Skip to main content

Module prompt

Module prompt 

Source
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):

  1. Scan the workspace for files the task references (or every source file in small workspaces — see workspace_scan).
  2. Inject each file’s verbatim contents into the user message under FILE: <path> / END-FILE separators.
  3. Ask the model to emit the complete updated file contents, not a diff — the S5 strategy that won the bake-off (golden_match=true on 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§

CoderPrompt
A built prompt — system + user strings ready for ChatRequest, 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 task against workspace. The workspace is scanned for relevant source files (see scan_workspace_for_files) and their contents are injected verbatim into the user message under FILE:/END-FILE separators.
build_reprompt
Build a re-prompt for the single-retry whole-file fallback.