Skip to content

fix(agent): wire additionalContext into review and recap prompts - #2050

Merged
gfargo-horizon-agent[bot] merged 2 commits into
mainfrom
agent/coco-1218-coco-1837-fix-agent-additionalcontext-is
Aug 3, 2026
Merged

fix(agent): wire additionalContext into review and recap prompts#2050
gfargo-horizon-agent[bot] merged 2 commits into
mainfrom
agent/coco-1218-coco-1837-fix-agent-additionalcontext-is

Conversation

@gfargo-horizon-agent

@gfargo-horizon-agent gfargo-horizon-agent Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What

additionalContext was accepted and validated by AgentOptionsSchema for all four operations but only forwarded to the model by commit-draft and changelog. review and recap accepted the field and silently discarded it — the caller had no way to detect this as the request validated, the call succeeded, and the output looked plausible.

This fix threads additionalContext through both prompt templates and agent generation functions, matching the shape already used by changelog.

Why

Closes #1837
Plane: OSS-1218

How

  • src/commands/review/prompt.ts: add additional_context to inputVariables and insert {{additional_context}} before the {{changes}} block, so caller guidance is read before the diff
  • src/commands/recap/prompt.ts: same treatment
  • src/operations/agent/generate.ts: pass additional_context: options.additionalContext ? '## Additional Context\n...' : '' in both generateAgentReview and generateAgentRecap, matching the existing generateAgentChangelog site verbatim so the three cannot drift; additionalContext stays outside asUntrustedChangeContext (caller-trusted), consistent with changelog
  • src/commands/review/handler.ts: pass additional_context: '' on the CLI path so the rendered prompt is valid when no additional context is supplied
  • src/commands/recap/handler.ts: same
  • src/operations/agent/schemas.ts: update additionalContext.describe() to 'Honored by: all operations.' (the Honored by: phrase is preserved for the existing test guard)
  • src/operations/agent/additionalContextPromptWiring.test.ts: new test file asserting inputVariables membership, prompt rendering with supplied context, CLI empty-context path, and agent variable forwarding for both review and recap

author for recap is deliberately kept changelog-only — code and schema already agree; no functional change needed.

Testing

  • build passes
  • tests pass / added (new additionalContextPromptWiring.test.ts, 69 tests pass)
  • lint clean (0 errors)
  • CI: pending

🤖 Generated by the harbor agent loop. Reviewed by a human before merge.

additionalContext was accepted and validated by AgentOptionsSchema for all
four operations but only forwarded to the model by commit-draft and changelog.
review and recap accepted the field and silently discarded it — the caller had
no way to detect this as the request validated, the call succeeded, and the
output looked plausible.

Changes:
- src/commands/review/prompt.ts: add additional_context to inputVariables and
  insert {{additional_context}} before the changes block, so caller guidance
  (e.g. ticket description, suppress-finding notes) is read before the diff.
- src/commands/recap/prompt.ts: same treatment.
- src/operations/agent/generate.ts: pass
  additional_context: options.additionalContext ? '## Additional Context\n...' : ''
  in both generateAgentReview and generateAgentRecap, matching the existing
  generateAgentChangelog site verbatim so the three cannot drift.
  additionalContext stays outside asUntrustedChangeContext (caller-trusted),
  consistent with changelog.
- src/commands/review/handler.ts: pass additional_context: '' on the CLI path
  so the rendered prompt is valid when no additional context is supplied.
- src/commands/recap/handler.ts: same.
- src/operations/agent/schemas.ts: update additionalContext.describe() from
  'Honored by: commit-draft, changelog. Ignored by review and recap.' to
  'Honored by: all operations.' (Honored by: phrase preserved for test guard).
- src/operations/agent/additionalContextPromptWiring.test.ts: new test file
  asserting inputVariables, rendering, and agent variable forwarding for both
  review and recap, modelled on conventionsContextPromptWiring.test.ts.

author for recap is deliberately kept changelog-only — code and schema already
agree on this; no change needed.

@gfargo-horizon-agent gfargo-horizon-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 Agent review (kiro · sonnet) — CONCERNS

REVIEW: CONCERNS
RESOLVES: full

The fix correctly threads additionalContext into both review and recap across all four surfaces (prompt templates, generate.ts, CLI handlers, and schema descriptions), with solid test coverage. One concern: both CLI handlers now declare conventions_context in inputVariables (added by #2004) but supply neither it nor — previously — additional_context; this PR fixes the additional_context gap but leaves the conventions_context gap unaddressed, meaning the CLI path silently renders conventions_context as an empty string rather than reading project convention files.

2 concerns · 1 nit — 3 inline on the diff

@@ -315,6 +315,7 @@ export const handler: CommandHandler<ReviewArgv> = async (argv, logger) => {
changes: context,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ conventions_context missing from CLI handler variables

REVIEW_PROMPT.inputVariables now contains ['format_instructions', 'changes', 'language_context', 'conventions_context', 'additional_context'], but the variables object in the CLI handler only supplies changes, format_instructions, language_context, and additional_context. conventions_context was added to the prompt in #2004 (d5b1815) without updating the handler, and this PR correctly adds additional_context but leaves the pre-existing conventions_context gap in place. Mustache silently renders the missing variable as an empty string, so there is no runtime crash, but project convention files (AGENTS.md, CLAUDE.md, .kiro/steering/) are never applied on the interactive CLI path for review. This PR is a natural place to fix it since it is touching exactly this block.

Suggested change
changes: context,
additional_context: '',
conventions_context: '',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

↩️ Not addressed in this revise — needs a follow-up / out of scope

format_instructions: formatInstructions,
timeframe,
language_context: getLanguageContext(argv.language || config.language, { taskDescription: 'summary' }),
additional_context: '',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ conventions_context missing from CLI handler variables

Same gap as review/handler.ts: RECAP_PROMPT.inputVariables declares conventions_context but the CLI handler's variables object omits it. Added by #2004 without updating the handler; this PR adds additional_context correctly but leaves conventions_context silently empty on the interactive CLI recap path. Not a crash, but project convention files have no effect during interactive coco recap.

Suggested change
additional_context: '',
additional_context: '',
conventions_context: '',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

↩️ Not addressed in this revise — needs a follow-up / out of scope

mockGetApiKeyForModel.mockReturnValue('test-key')
mockGetModelAndProviderFromConfig.mockReturnValue({ provider: 'test-provider' } as never)
mockResolveDynamicService.mockReturnValue({ model: 'test-model' } as never)
// eslint-disable-next-line @typescript-eslint/no-explicit-any

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Duplicate beforeEach setup across two describe blocks

The beforeEach bodies in the generateAgentReview and generateAgentRecap describe blocks are identical apart from the mockExecuteChain/mockExecuteChainStreaming return values. Extracting the shared setup into a top-level beforeEach and overriding only the mock return values in each block would halve the setup boilerplate. Low priority since test clarity is good, but the duplication will accumulate if a third operation is added.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

↩️ Not addressed in this revise — needs a follow-up / out of scope

Both handlers declared conventions_context in their prompt inputVariables
(added in #2004) but omitted the key from the variables object passed to
the template, so project convention files (AGENTS.md, CLAUDE.md,
.kiro/steering/) had no effect on the interactive CLI path for review/recap.

Also extract shared beforeEach setup to top-level in
additionalContextPromptWiring.test.ts, overriding only the operation-
specific mock return values per describe block.

@gfargo-horizon-agent gfargo-horizon-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 Agent review (kiro · sonnet) — CONCERNS

REVIEW: CONCERNS
RESOLVES: partial

The PR correctly wires additionalContext into review and recap prompts and handler call sites, with solid test coverage. However, the work item explicitly requires a deliberate decision on the author option for recap — the PR leaves it silently ignored and the schema description still says 'Ignored by other operations', meaning the code and documentation remain inconsistent as called out in the acceptance criteria.

  • ⚠️ author recap decision not made, schema still ambiguoussrc/operations/agent/schemas.ts:111 — The work item's acceptance criterion states: 'author for recap is either implemented or removed from the documented applicability, not left ambiguous.' The schema description still reads 'Honored by: changelog. Ignored by other operations.' — unchanged from before this PR. generateAgentRecap still does not forward author in any form. The issue explicitly flags this as a required decision, not an optional cleanup, because the existing documentation (issue #1827) listed recap as honoring author. The PR neither wires it nor updates the description to explicitly note recap ignores it with a reason, leaving the pre-existing ambiguity intact.
  • ⚠️ Test only asserts executeChain call, misses streaming pathsrc/operations/agent/additionalContextPromptWiring.test.ts:163 — The agent-level tests assert on mockExecuteChain exclusively but executeStructured can also route through executeChainStreaming when streaming is enabled. The mock for executeChainStreaming is set up but never asserted against. If executeStructured is invoked with a streaming config, the additional_context variable forwarding would be exercised through a different code path that these tests never verify. Adding a parallel test case with streaming: { enabled: true } in the mock config would close this gap.
  • 🧹 Empty string for conventions_context added unnecessarilysrc/commands/recap/handler.ts:249 — The diff adds both additional_context: '' and conventions_context: '' to the CLI handler's variables object, but conventions_context was already present in the template's inputVariables before this PR — meaning the handler must have been supplying it already (or the prompt would have been throwing before). Worth verifying this isn't masking a pre-existing missing-variable bug rather than being a deliberate defensive addition; if it was already supplied upstream it is redundant, if it was genuinely missing it should be a separate fix with its own mention in the PR description.

@gfargo-horizon-agent gfargo-horizon-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 Agent re-review (sonnet, delta) — CONCERNS

structured payload failed to parse — see the run transcript for the full review

@gfargo-horizon-agent
gfargo-horizon-agent Bot merged commit 1cce8b2 into main Aug 3, 2026
11 checks passed
@gfargo-horizon-agent
gfargo-horizon-agent Bot deleted the agent/coco-1218-coco-1837-fix-agent-additionalcontext-is branch August 3, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(agent): additionalContext is accepted but silently ignored by review and recap

0 participants