Skip to content

feat(feedback): add context anchoring instructions to plan denial#432

Open
aviadshiber wants to merge 4 commits intobacknotprop:mainfrom
aviadshiber:feat/context-anchoring-adr
Open

feat(feedback): add context anchoring instructions to plan denial#432
aviadshiber wants to merge 4 commits intobacknotprop:mainfrom
aviadshiber:feat/context-anchoring-adr

Conversation

@aviadshiber
Copy link
Copy Markdown
Contributor

@aviadshiber aviadshiber commented Mar 30, 2026

Summary

Implements the context anchoring pattern from Martin Fowler's article on context anchoring, applied to both the plan denial and approval flows.

The problem: when an agent gets a plan denied and revises, it only receives the current round's feedback — not what was rejected in prior rounds. It can re-propose the same approaches without knowing they were already rejected, creating iteration loops. And on approval, nothing reminds the agent to carry forward the decision history into implementation.

Changes

packages/shared/feedback-templates.ts

planDenyFeedback() — adds a ## Context Anchoring section instructing the agent to maintain a ## Decisions Log in the plan itself:

## Context Anchoring

Before revising your plan:
1. Add (or update) a `## Decisions Log` section at the bottom of the plan.
2. For each rejected approach from this feedback, add an entry:
   - **Rejected:** [brief description]  **Why:** [reason from this feedback]
3. Do NOT re-propose approaches already listed in the Decisions Log — it is your cross-session memory.

planApproveFeedback() — new function used on plan approval, reminding the agent to reference the Decisions Log during implementation:

Plan approved!

If your plan contains a `## Decisions Log`, keep it as a reference during
implementation — it documents the rejected alternatives that shaped this design.

apps/opencode-plugin/index.ts

Uses planApproveFeedback() for both approval paths (with notes and without), replacing the previous inline strings.

packages/shared/feedback-templates.test.ts

Adds 4 tests covering the context anchoring behavior (all passing):

  • Deny includes Decisions Log instructions, Rejected: entry format, and cross-session memory note
  • Approve includes Decisions Log reminder
  • Approve with notes includes both implementation notes and Decisions Log reminder
  • Approve with saved path surfaces the file path

Why this approach

The plan is already the persistent artifact (saved to version history on every submission). By embedding rejected alternatives and their reasoning directly in the plan markdown, the ADR pattern works at zero infrastructure cost. The Decisions Log:

  • Travels with every revision
  • Is visible in the plan diff view (shows what was added/changed between iterations)
  • Is archived with the final approved/denied decision
  • Survives context window resets — it's in the document, not just the conversation

Test plan

  • Deny → agent instructed to build ## Decisions Log with rejected approaches
  • Deny again → Decisions Log grows ("add or update" instruction)
  • Approve → agent reminded to reference Decisions Log during implementation
  • Approve with notes → notes + Decisions Log reminder both appear

Part of #431

🤖 Generated with Claude Code

aviadsTaboola and others added 4 commits March 30, 2026 11:58
When a plan is denied, instruct the agent to maintain a `## Decisions Log`
section in the plan tracking rejected approaches and their reasons. This
implements the context anchoring pattern from Martin Fowler's article:
the plan itself becomes the persistent ADR, visible in diffs and archived
with every decision — at zero infrastructure cost.

Closes backnotprop#431

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds planApproveFeedback() to shared feedback templates and uses it
in the OpenCode plugin approval paths. On approval, the agent is
reminded to reference the Decisions Log (built up during denial
iterations) during implementation — completing the context anchoring
loop for both deny and approve flows.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests that planDenyFeedback includes Decisions Log instructions and
planApproveFeedback includes the Decisions Log reminder — for both
plain approval and approval-with-notes paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- planApproveFeedback: header now reads "Plan approved with notes!" when
  notes are present, so the agent knows content follows
- Extract DECISIONS_LOG_NOTE as a named export so Pi (and other
  integrations with custom approval messages) can append it without
  duplicating the string
- Pi approval paths now include DECISIONS_LOG_NOTE in both the
  with-notes and plain-approval messages
- planDenyFeedback: soften "Do NOT re-propose" to "Once added, do NOT
  re-propose" — accurate on first denial when the log doesn't exist yet
- Add tests: "with notes" header, "without notes" header, DECISIONS_LOG_NOTE export

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

2 participants