Files
cleveragents-core/tools/controller/worker
drew 1b09a2054f feat(controller): Phase 1i — per-role prompt templates
Replace the JSON-dump prompt stub with structured per-role builders
that render the V1 input contract fields in human-friendly sections.
The agent's system prompt (.opencode/agents/{name}.md) provides the
HOW (tool calls, response shape); this module provides the WHAT (the
per-attempt context drawn from input_payload).

Per-role builders in tools/controller/worker/prompts.py:
- build_implementer_prompt   — branch coords, CI summary (highlights
  failing gates), active reviewer state, new comments, prior attempts,
  optional allowed_files scope, output contract reminder
- build_reviewer_prompt      — PR coords, CI summary, full diff (with
  code fence), implementer's latest claim, prior reviewer outputs
- build_estimator_prompt     — PR/issue context (title, body, diff
  summary, head_sha), tier-pick guidance
- build_conflict_resolver_prompt — coords, conflicted files (or
  porcelain fallback), prior implementer outputs
- build_summarizer_prompt    — aged-out attempt + prior running
  summary; instructs terse condensation
- build_prompt(role, tier, input_payload) — dispatcher

Truncation budgets (in chars):
- full_diff:           12,000
- pr_body / summaries: 4,000
- prior-attempt JSON:  2,000
- comment one-liner:   200

Wired as the default prompt builder in opencode_session via
``_default_prompt_for``. wire_opencode_session() callers that pass
prompt_builder=... override per-test.

Tests (+35 in test_worker_prompts.py, 1 updated adapter test, 0
regressions):
- Per-role: section headers present, required fields rendered,
  missing fields fall back to (unavailable), oversize fields
  truncated
- Dispatcher: routes by role; raises ValueError for missing tier on
  tiered roles + unknown role
- Adapter integration: _default_prompt_for delegates to build_prompt

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 14:36:14 -04:00
..