Expand description
Build the LLM prompt for a coder task.
Strategy (per the failure-mode taxonomy in
~/workspaces/knowledge/board/drake/2026-05-29_newt-coder-failure-mode-taxonomy.md):
- Scan the workspace for files the task references (or every
source file in small workspaces — see
workspace_scan). - Inject each file’s verbatim contents into the user message
under
FILE: <path>/END-FILEseparators. - Ask the model to emit the complete updated file contents,
not a diff — the S5 strategy that won the bake-off
(
golden_match=trueon qwen3-coder:30b, 224 tokens, 5.6 s).
Total file context is capped at DEFAULT_CONTEXT_CAP_CHARS
(~8K tokens) to keep prompts within local-model context budgets.
When the cap is reached we drop the remaining files and emit a
tracing::warn! — the operator should see this and either narrow
the task or split it.
Structs§
- Coder
Prompt - A built prompt —
system+userstrings ready forChatRequest, plus the list of files actually injected (useful for audit logs and the foreman’s scorecard).
Constants§
- DEFAULT_
CONTEXT_ CAP_ CHARS - Maximum total chars of file context to inject into a single prompt. ~8K tokens at ~4 chars/token (English-ish average). Bake-off case 001-rename-function used 224 tokens of context; this leaves a wide margin for multi-file refactors before the prompt becomes prohibitively expensive on local hardware.
- WHOLE_
FILE_ SYSTEM_ PROMPT - The S5 system prompt — whole-file emit, no diffs, no fences.
Functions§
- build_
prompt - Build a prompt for
taskagainstworkspace. The workspace is scanned for relevant source files (seescan_workspace_for_files) and their contents are injected verbatim into the user message underFILE:/END-FILEseparators. - build_
reprompt - Build a re-prompt for the single-retry whole-file fallback.