fix(commands): scope self-fix + simplify to the PR diff#1952
Conversation
Both archon-self-fix-all and archon-simplify-changes could edit files outside the PR diff (scope-bleed): self-fix never computed the diff and its "fix EVERYTHING / add tests for existing code" framing pushed edits outward; simplify computed the diff but never enforced it. Both nodes now compute an allow-list (git diff $BASE...HEAD --name-only) and run a hard pre-commit gate (comm -23 of changed files vs the allow-list) that reverts anything out of scope before staging. self-fix's framing is re-toned to "aggressive within the diff; out-of-scope findings become follow-up issues, never edits". Prompt-only; bundled-defaults.generated.ts regenerated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR updates three workflow documentation and configuration files to enforce hard in-scope boundaries for the aggressive self-fix workflow. The PR computes an allow-list of already-modified files, tags findings as in-scope or out-of-scope, and adds a mandatory scope gate that prevents committing any out-of-scope edits unless they are new test or doc files paired 1:1 with in-scope sources. ChangesIn-scope editing boundary enforcement
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/workflows/src/defaults/bundled-defaults.generated.ts`:
- Line 42: The allow-list generation uses a local base ref ("git diff
$BASE_BRANCH...HEAD --name-only") which can be stale; update the logic that
builds the simplify allow-list (the string containing "git diff
$BASE_BRANCH...HEAD --name-only") to reference the remote base ref by fetching
and diffing against origin/$BASE_BRANCH (e.g., run "git fetch origin
$BASE_BRANCH" then "git diff origin/$BASE_BRANCH...HEAD --name-only" or resolve
origin/$BASE_BRANCH via git rev-parse before diffing) so the allow-list is
derived from the up-to-date remote base rather than a potentially stale local
branch.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3cdf2026-00f3-4701-91ce-7e4b6fcc16cb
📒 Files selected for processing (3)
.archon/commands/defaults/archon-self-fix-all.md.archon/commands/defaults/archon-simplify-changes.mdpackages/workflows/src/defaults/bundled-defaults.generated.ts
| "archon-self-fix-all": "---\ndescription: Aggressively fix all review findings - lean towards fixing unless clearly a new concern\nargument-hint: (none - reads all review artifacts from $ARTIFACTS_DIR/review/)\n---\n\n# Self-Fix All Review Findings\n\n---\n\n## IMPORTANT: Output Behavior\n\n**Your output will be posted as a GitHub comment.** Keep working output minimal:\n- Do NOT narrate each step\n- Do NOT output verbose progress updates\n- Only output the final structured report at the end\n\n---\n\n## Your Mission\n\nRead all review artifacts and fix EVERYTHING surfaced. Unlike conservative auto-fix, you lean aggressively towards fixing. LLMs are fast at generating code — use that advantage to add tests, fix docs, improve error handling, and address all findings.\n\n**Philosophy**: Fix it unless it's clearly a NEW unrelated concern that deserves its own issue. Adding tests for existing code? Fix it. Updating docs? Fix it. Adding missing error handling? Fix it. The bar for skipping is HIGH — only skip when the fix would introduce a genuinely new feature or concern outside the PR's scope.\n\n**Output artifact**: `$ARTIFACTS_DIR/review/fix-report.md`\n**Git action**: Commit AND push fixes to the PR branch\n**GitHub action**: Post fix report as a comment on the PR\n\n---\n\n## Phase 1: LOAD — Get Context\n\n### 1.1 Get PR Number and Branch\n\n```bash\nPR_NUMBER=$(cat $ARTIFACTS_DIR/.pr-number)\nHEAD_BRANCH=$(gh pr view $PR_NUMBER --json headRefName --jq '.headRefName')\necho \"PR: $PR_NUMBER, Branch: $HEAD_BRANCH\"\n```\n\n### 1.2 Checkout PR Branch\n\n```bash\ngit fetch origin $HEAD_BRANCH\ngit checkout $HEAD_BRANCH\ngit pull origin $HEAD_BRANCH\n```\n\nVerify:\n\n```bash\ngit branch --show-current\ngit status --porcelain\n```\n\n### 1.3 Read All Review Artifacts\n\n```bash\nls $ARTIFACTS_DIR/review/\n```\n\nRead each `.md` file that contains findings (e.g. `code-review-findings.md`, `error-handling-findings.md`, `test-coverage-findings.md`, `comment-quality-findings.md`, `docs-impact-findings.md`, `consolidated-review.md`). Skip `scope.md` and `fix-report.md`.\n\n```bash\nfor f in $ARTIFACTS_DIR/review/*.md; do\n echo \"=== $f ===\"; cat \"$f\"; echo\ndone\n```\n\n### 1.4 Extract All Findings\n\nCompile a unified list of ALL findings with severity, location, and suggested fix.\n\n**PHASE_1_CHECKPOINT:**\n\n- [ ] PR number and branch identified\n- [ ] On correct PR branch\n- [ ] All review artifacts read\n- [ ] All findings extracted\n\n---\n\n## Phase 2: TRIAGE — Decide What to Fix\n\nFor each finding, decide: **FIX** or **SKIP**.\n\n### FIX (default — lean towards fixing):\n\n- Real bugs, type errors, silent failures, code quality issues\n- Missing tests for changed or existing code touched by the PR\n- Missing or outdated documentation\n- Error handling gaps\n- Comment quality issues\n- Import organization\n- Naming improvements\n- Any finding where the fix is concrete and the code is within the PR's touched area\n\n### SKIP only if:\n\n- The fix introduces a **genuinely new feature** not related to the PR\n- The fix requires **architectural changes** that affect untouched subsystems\n- The fix is about code **completely unrelated** to the PR's changes\n- The finding is factually wrong or based on a misunderstanding\n\n**Key principle**: If the review agent found it while reviewing THIS PR, it's fair game to fix. Tests, docs, simplification, error handling — all fixable. The only skip reason is \"this is a new concern that deserves its own issue.\"\n\nFor each skipped finding, write down **the specific reason**.\n\n**PHASE_2_CHECKPOINT:**\n\n- [ ] Every finding marked FIX or SKIP\n- [ ] Skip reasons documented (should be very few)\n\n---\n\n## Phase 3: IMPLEMENT — Apply Fixes\n\n### 3.1 For Each Finding Marked FIX\n\n1. Read the relevant file(s)\n2. Apply the fix following the suggested approach\n3. Run type-check after each fix: `bun run type-check`\n4. Note exactly what was changed\n\n### 3.2 Add Tests\n\nFor ANY finding about missing tests:\n\n1. Create or update the test file\n2. Write meaningful tests (not just stubs)\n3. Run them: `bun test {file}`\n\n### 3.3 Fix Documentation\n\nFor ANY finding about docs:\n\n1. Update the relevant documentation\n2. Ensure accuracy with the current code\n\n### 3.4 Handle Blocked Fixes\n\nIf a fix cannot be applied (code changed since review, fix would break other things), mark as **BLOCKED** with reason. Do not force a broken fix.\n\n**PHASE_3_CHECKPOINT:**\n\n- [ ] All FIX findings attempted\n- [ ] Tests added where flagged\n- [ ] Docs updated where flagged\n- [ ] BLOCKED findings documented\n\n---\n\n## Phase 4: VALIDATE — Full Check\n\n```bash\nbun run type-check\nbun run lint\nbun test\n```\n\nAll must pass. If something fails after a fix:\n\n1. Review the error\n2. Adjust the fix or revert it and mark BLOCKED\n3. Re-run until clean\n\n**PHASE_4_CHECKPOINT:**\n\n- [ ] Type check passes\n- [ ] Lint passes\n- [ ] Tests pass\n\n---\n\n## Phase 5: COMMIT AND PUSH\n\n### 5.1 Stage and Commit\n\nOnly stage files you actually changed:\n\n```bash\ngit add {specific files}\ngit status\ngit commit -m \"$(cat <<'EOF'\nfix: address review findings\n\nFixed:\n- {brief list of fixes}\n\nTests added:\n- {brief list if any}\n\nSkipped:\n- {brief list if any, with reasons}\nEOF\n)\"\n```\n\n### 5.2 Push\n\n```bash\ngit push origin $HEAD_BRANCH\n```\n\nIf push fails due to divergence:\n\n```bash\ngit pull --rebase origin $HEAD_BRANCH\ngit push origin $HEAD_BRANCH\n```\n\n**PHASE_5_CHECKPOINT:**\n\n- [ ] Changes committed\n- [ ] Pushed to PR branch\n\n---\n\n## Phase 6: GENERATE — Write Fix Report\n\nWrite to `$ARTIFACTS_DIR/review/fix-report.md`:\n\n```markdown\n# Fix Report: PR #{number}\n\n**Date**: {ISO timestamp}\n**Status**: COMPLETE | PARTIAL\n**Branch**: {HEAD_BRANCH}\n**Commit**: {commit hash}\n**Philosophy**: Aggressive fix — lean towards fixing everything\n\n---\n\n## Summary\n\n{2-3 sentences: what was found, what was fixed, what was skipped and why}\n\n---\n\n## Fixes Applied\n\n| Severity | Finding | Location | What Was Done |\n|----------|---------|----------|---------------|\n| CRITICAL | {title} | `file:line` | {description} |\n| HIGH | {title} | `file:line` | {description} |\n| MEDIUM | {title} | `file:line` | {description} |\n| LOW | {title} | `file:line` | {description} |\n\n---\n\n## Tests Added\n\n| File | Test Cases |\n|------|------------|\n| `{file}.test.ts` | `{test description}` |\n\n*(none)* if no tests were added\n\n---\n\n## Docs Updated\n\n| File | Changes |\n|------|---------|\n| `{file}` | {what was updated} |\n\n*(none)* if no docs were updated\n\n---\n\n## Skipped Findings\n\n| Severity | Finding | Location | Reason Skipped |\n|----------|---------|----------|----------------|\n| {sev} | {title} | `file:line` | New concern: {specific reason} |\n\n*(none)* if nothing was skipped — ideal outcome\n\n---\n\n## Blocked (Could Not Fix)\n\n| Severity | Finding | Reason |\n|----------|---------|--------|\n| {sev} | {title} | {why it could not be applied} |\n\n*(none)* if nothing was blocked\n\n---\n\n## Suggested Follow-up Issues\n\n{For any skipped or blocked findings that warrant their own issue:}\n\n| Issue Title | Priority | Reason |\n|-------------|----------|--------|\n| \"{title}\" | {P1/P2/P3} | {why this deserves a separate issue} |\n\n*(none)* if everything was addressed\n\n---\n\n## Validation\n\n| Check | Status |\n|-------|--------|\n| Type check | ✅ / ❌ |\n| Lint | ✅ / ❌ |\n| Tests | ✅ {n} passed / ❌ |\n```\n\n**PHASE_6_CHECKPOINT:**\n\n- [ ] Fix report written\n\n---\n\n## Phase 7: POST — GitHub Comment\n\nPost the fix report as a PR comment:\n\n```bash\ngh pr comment $PR_NUMBER --body \"$(cat <<'EOF'\n## ⚡ Self-Fix Report (Aggressive)\n\n**Status**: {COMPLETE | PARTIAL}\n**Pushed**: ✅ Changes pushed to `{HEAD_BRANCH}`\n**Philosophy**: Fix everything unless clearly a new concern\n\n---\n\n### Fixes Applied ({n} total)\n\n| Severity | Count |\n|----------|-------|\n| 🔴 CRITICAL | {n} |\n| 🟠 HIGH | {n} |\n| 🟡 MEDIUM | {n} |\n| 🟢 LOW | {n} |\n\n<details>\n<summary>View all fixes</summary>\n\n{For each fix:}\n- ✅ **{title}** (`{file}:{line}`) — {brief description}\n\n</details>\n\n---\n\n### Tests Added\n\n{List or \"(none)\"}\n\n---\n\n### Skipped ({n})\n\n{If any:}\n| Finding | Reason |\n|---------|--------|\n| {title} | New concern: {reason} |\n\n*(none — all findings addressed)*\n\n---\n\n### Suggested Follow-up Issues\n\n{If any skipped/blocked items warrant issues:}\n1. **{Issue Title}** — {brief description}\n\n*(none)*\n\n---\n\n### Validation\n\n✅ Type check | ✅ Lint | ✅ Tests ({n} passed)\n\n---\n\n*Self-fix by Archon · aggressive mode · fixes pushed to `{HEAD_BRANCH}`*\nEOF\n)\"\n```\n\n**PHASE_7_CHECKPOINT:**\n\n- [ ] GitHub comment posted\n\n---\n\n## Phase 8: OUTPUT — Final Summary\n\n```\n## ⚡ Self-Fix Complete\n\n**PR**: #{number}\n**Branch**: {HEAD_BRANCH}\n**Status**: COMPLETE | PARTIAL\n\nFixed: {n} (across all severities)\nTests added: {n}\nDocs updated: {n}\nSkipped: {n} (new concerns only)\nBlocked: {n}\n\nValidation: ✅ All checks pass\nPushed: ✅\n\nFix report: $ARTIFACTS_DIR/review/fix-report.md\n```\n\n---\n\n## Success Criteria\n\n- **ON_CORRECT_BRANCH**: Working on PR's head branch\n- **ALL_FINDINGS_ADDRESSED**: Every finding is fixed, skipped (with reason), or blocked (with reason)\n- **AGGRESSIVE_FIXING**: Most findings fixed — skip rate should be very low\n- **TESTS_ADDED**: Missing test coverage addressed\n- **DOCS_UPDATED**: Documentation gaps filled\n- **VALIDATION_PASSED**: Type check, lint, and tests all pass\n- **COMMITTED_AND_PUSHED**: Changes committed and pushed to PR branch\n- **REPORTED**: Fix report artifact written and GitHub comment posted\n", | ||
| "archon-simplify-changes": "---\ndescription: Simplify code changed in this PR — implements fixes directly, commits, and pushes\nargument-hint: (none - operates on the current branch diff against $BASE_BRANCH)\n---\n\n# Simplify Changed Code\n\n---\n\n## IMPORTANT: Output Behavior\n\n**Your output will be posted as a GitHub comment.** Keep working output minimal:\n- Do NOT narrate each step\n- Do NOT output verbose progress updates\n- Only output the final structured report at the end\n\n---\n\n## Your Mission\n\nReview ALL code changed on this branch and implement simplifications directly. You are not advisory — you edit files, validate, commit, and push.\n\n## Scope\n\n**Only code changed in this PR** — run `git diff $BASE_BRANCH...HEAD --name-only` to get the file list. Do not touch unrelated files.\n\n## What to Simplify\n\n| Opportunity | What to Look For |\n|-------------|------------------|\n| **Unnecessary complexity** | Deep nesting, convoluted logic paths |\n| **Redundant code** | Duplicated logic, unused variables/imports |\n| **Over-abstraction** | Abstractions that obscure rather than clarify |\n| **Poor naming** | Unclear variable/function names |\n| **Nested ternaries** | Multiple conditions in ternary chains — use if/else |\n| **Dense one-liners** | Compact code that sacrifices readability |\n| **Obvious comments** | Comments that describe what code clearly shows |\n| **Inconsistent patterns** | Code that doesn't follow project conventions (read CLAUDE.md) |\n\n## Rules\n\n- **Preserve exact functionality** — simplification must not change behavior\n- **Clarity over brevity** — readable beats compact\n- **No speculative refactors** — only simplify what's obviously improvable\n- **Follow project conventions** — read CLAUDE.md before making changes\n- **Small, obvious changes** — each simplification should be self-evidently correct\n\n## Process\n\n### Phase 1: ANALYZE\n\n1. Read CLAUDE.md for project conventions\n2. Get changed files: `git diff $BASE_BRANCH...HEAD --name-only`\n3. Read each changed file\n4. Identify simplification opportunities per file\n\n### Phase 2: IMPLEMENT\n\nFor each simplification:\n1. Edit the file\n2. Run `bun run type-check` — if it fails, revert that change\n3. Run `bun run lint` — if it fails, fix or revert\n\n**Track every path you edit.** You will need this list in Phase 3 to stage only the files you touched.\n\n### Phase 3: VALIDATE & COMMIT\n\n1. Run full validation: `bun run type-check && bun run lint`\n2. If simplifications were applied, stage **only** the files you edited in Phase 2 — never `git add -A`, `git add .`, or `git add -u`:\n ```bash\n # Stage by name, using the list you tracked in Phase 2\n git add path/to/file1.ts path/to/file2.ts\n # Verify nothing else snuck in\n git status --porcelain\n ```\n3. **Never stage** report, scratch, or PR-body artifacts, even if they show up as untracked or modified in the worktree:\n - Anything under `$ARTIFACTS_DIR` (the artifacts directory normally lives outside the worktree, but copies/symlinks may exist)\n - `review/`, `simplify-report.md`, `*-report.md` at the repo root\n - `.pr-body.md`, `pr-body.md`, `*.scratch.md`, `*.tmp.md`\n - If `git status --porcelain` shows files you don't recognize as part of your simplifications, leave them unstaged\n4. Commit and push only the staged source edits:\n ```bash\n git commit -m \"simplify: reduce complexity in changed files\"\n git push\n ```\n5. If no simplifications were applied, skip the commit entirely\n\n### Phase 4: REPORT\n\nWrite report to `$ARTIFACTS_DIR/review/simplify-report.md` and output:\n\n```markdown\n## Code Simplification Report\n\n### Changes Made\n\n#### 1. [Brief Title]\n**File**: `path/to/file.ts:45-60`\n**Type**: Reduced nesting / Improved naming / Removed redundancy / etc.\n**Before**: [snippet]\n**After**: [snippet]\n\n---\n\n### Summary\n\n| Metric | Value |\n|--------|-------|\n| Files analyzed | X |\n| Simplifications applied | Y |\n| Net line change | -N lines |\n| Validation | PASS / FAIL |\n\n### No Changes Needed\n(If nothing to simplify, say so — \"Code is already clean. No simplifications applied.\")\n```\n", | ||
| "archon-self-fix-all": "---\ndescription: Aggressively fix all review findings - lean towards fixing unless clearly a new concern\nargument-hint: (none - reads all review artifacts from $ARTIFACTS_DIR/review/)\n---\n\n# Self-Fix All Review Findings\n\n---\n\n## IMPORTANT: Output Behavior\n\n**Your output will be posted as a GitHub comment.** Keep working output minimal:\n- Do NOT narrate each step\n- Do NOT output verbose progress updates\n- Only output the final structured report at the end\n\n---\n\n## Your Mission\n\nRead all review artifacts and fix everything surfaced **that falls within this PR's diff**. Within that boundary you lean aggressively towards fixing — LLMs are fast at generating code, so use that to add tests for the PR's own code, fix docs, improve error handling, and address all in-scope findings.\n\n**Scope is a hard boundary, not a judgment call (see Phase 1.3).** You may only edit files this PR already changed (`git diff $BASE_BRANCH...HEAD`), plus a **new** test/doc file that pairs 1:1 with one of those files. A finding about any **other** file — even a real, valid one — is **not yours to fix in this PR**: record it under \"Suggested Follow-up Issues\" instead. Aggressive *inside* the diff; never *outside* it. This is enforced by a hard gate in Phase 5 before commit.\n\n**Philosophy**: Within the PR's diff scope, fix it — real bugs, missing tests for the PR's own changed code, docs, error handling, naming. You skip a finding for exactly two reasons: (a) it targets a file **outside the diff scope** → record a follow-up issue (this is the most common skip and it is correct), or (b) it would introduce a **genuinely new feature / architectural change**. The bar for editing outside the diff is absolute: you don't.\n\n**Output artifact**: `$ARTIFACTS_DIR/review/fix-report.md`\n**Git action**: Commit AND push fixes to the PR branch\n**GitHub action**: Post fix report as a comment on the PR\n\n---\n\n## Phase 1: LOAD — Get Context\n\n### 1.1 Get PR Number and Branch\n\n```bash\nPR_NUMBER=$(cat $ARTIFACTS_DIR/.pr-number)\nHEAD_BRANCH=$(gh pr view $PR_NUMBER --json headRefName --jq '.headRefName')\nBASE_BRANCH=$(gh pr view $PR_NUMBER --json baseRefName --jq '.baseRefName')\necho \"PR: $PR_NUMBER, Head: $HEAD_BRANCH, Base: $BASE_BRANCH\"\n```\n\n### 1.2 Checkout PR Branch\n\n```bash\ngit fetch origin $HEAD_BRANCH\ngit checkout $HEAD_BRANCH\ngit pull origin $HEAD_BRANCH\n```\n\nVerify:\n\n```bash\ngit branch --show-current\ngit status --porcelain\n```\n\n### 1.3 Compute the PR Diff Scope (allow-list)\n\nThis PR's scope is the set of files it already changed. Compute it now — every fix you make must stay inside it. This is the guard that prevents the self-fix step from editing unrelated files.\n\n```bash\ngit fetch origin $BASE_BRANCH\n# The allow-list: files this PR touched, measured from the merge-base.\ngit diff origin/$BASE_BRANCH...HEAD --name-only | sort -u > /tmp/scope-allowlist.txt\necho \"In-scope files (this is the ONLY set you may edit):\"; cat /tmp/scope-allowlist.txt\n```\n\n**The rule (enforced by the hard gate in Phase 5):**\n\n- You MAY edit any file in the allow-list.\n- You MAY create a **new** test or doc file that pairs 1:1 with an in-scope source file (e.g. `foo.test.ts` for an in-scope `foo.ts`, or that file's doc page).\n- You MAY NOT touch any other file. A finding about an out-of-scope file is real but **not yours to fix here** — record it under \"Suggested Follow-up Issues,\" do not edit it.\n\n### 1.4 Read All Review Artifacts\n\n```bash\nls $ARTIFACTS_DIR/review/\n```\n\nRead each `.md` file that contains findings (e.g. `code-review-findings.md`, `error-handling-findings.md`, `test-coverage-findings.md`, `comment-quality-findings.md`, `docs-impact-findings.md`, `consolidated-review.md`). Skip `scope.md` and `fix-report.md`.\n\n```bash\nfor f in $ARTIFACTS_DIR/review/*.md; do\n echo \"=== $f ===\"; cat \"$f\"; echo\ndone\n```\n\n### 1.5 Extract All Findings\n\nCompile a unified list of ALL findings with severity, location, and suggested fix. Tag each finding **in-scope** or **out-of-scope** by checking its file against the allow-list from 1.3.\n\n**PHASE_1_CHECKPOINT:**\n\n- [ ] PR number, head, and base branch identified\n- [ ] On correct PR branch\n- [ ] Scope allow-list computed (1.3)\n- [ ] All review artifacts read\n- [ ] All findings extracted and tagged in-scope / out-of-scope\n\n---\n\n## Phase 2: TRIAGE — Decide What to Fix\n\nFor each finding, decide: **FIX** or **SKIP**.\n\n**Gate every finding on scope first.** If the finding's file is **not** in the 1.3 allow-list (and the fix isn't a new test/doc paired 1:1 with an in-scope source file), it is **SKIP → follow-up issue**, full stop — no matter how real or easy it is. Only findings that pass this scope gate proceed to the FIX/SKIP judgment below.\n\n### FIX (for in-scope findings, lean towards fixing):\n\n- Real bugs, type errors, silent failures, code quality issues\n- Missing tests for the **PR's own changed code** (an in-scope file)\n- Missing or outdated documentation **for an in-scope file**\n- Error handling gaps\n- Comment quality issues\n- Import organization\n- Naming improvements\n- Any finding where the fix is concrete and the file is in the scope allow-list (1.3)\n\n### SKIP if:\n\n- **The finding targets a file NOT in the scope allow-list (1.3)** → record it as a follow-up issue. This is the most common skip, and it is correct — do not edit out-of-scope files.\n- The fix introduces a **genuinely new feature** not related to the PR\n- The fix requires **architectural changes** that affect untouched subsystems\n- The finding is factually wrong or based on a misunderstanding\n\n**Key principle**: In-scope (a file the PR already changed, or a new test/doc paired to one) → fair game to fix aggressively. Out-of-scope → a follow-up issue, never an edit. \"The reviewer mentioned it\" does **not** make an out-of-scope file fixable here.\n\nFor each skipped finding, write down **the specific reason** (for out-of-scope skips: name the file and that it's not in the allow-list).\n\n**PHASE_2_CHECKPOINT:**\n\n- [ ] Every finding marked FIX or SKIP\n- [ ] Every out-of-scope finding routed to a follow-up issue, not an edit\n- [ ] Skip reasons documented\n\n---\n\n## Phase 3: IMPLEMENT — Apply Fixes\n\n### 3.1 For Each Finding Marked FIX\n\n1. Read the relevant file(s)\n2. Apply the fix following the suggested approach\n3. Run type-check after each fix: `bun run type-check`\n4. Note exactly what was changed\n\n### 3.2 Add Tests\n\nFor ANY finding about missing tests:\n\n1. Create or update the test file\n2. Write meaningful tests (not just stubs)\n3. Run them: `bun test {file}`\n\n### 3.3 Fix Documentation\n\nFor ANY finding about docs:\n\n1. Update the relevant documentation\n2. Ensure accuracy with the current code\n\n### 3.4 Handle Blocked Fixes\n\nIf a fix cannot be applied (code changed since review, fix would break other things), mark as **BLOCKED** with reason. Do not force a broken fix.\n\n**PHASE_3_CHECKPOINT:**\n\n- [ ] All FIX findings attempted\n- [ ] Tests added where flagged\n- [ ] Docs updated where flagged\n- [ ] BLOCKED findings documented\n\n---\n\n## Phase 4: VALIDATE — Full Check\n\n```bash\nbun run type-check\nbun run lint\nbun test\n```\n\nAll must pass. If something fails after a fix:\n\n1. Review the error\n2. Adjust the fix or revert it and mark BLOCKED\n3. Re-run until clean\n\n**PHASE_4_CHECKPOINT:**\n\n- [ ] Type check passes\n- [ ] Lint passes\n- [ ] Tests pass\n\n---\n\n## Phase 5: COMMIT AND PUSH\n\n### 5.1 Enforce scope (hard gate), then stage and commit\n\n**Scope gate — run this BEFORE staging.** Every file you changed must be in the allow-list (1.3), or a new test/doc paired 1:1 with an in-scope source file. Anything else is a scope leak and must not be committed:\n\n```bash\ngit diff --name-only | sort -u > /tmp/changed.txt\n# Files you changed that are NOT in the allow-list:\ncomm -23 /tmp/changed.txt /tmp/scope-allowlist.txt\n```\n\nFor each path that prints: if it is **not** a new test/doc paired 1:1 with an in-scope source file, it is **out of scope** — revert it (`git checkout -- <path>` for an edit, or `rm <path>` for a stray new file) and move the finding to \"Suggested Follow-up Issues.\" Re-run the check until it prints only justified paired new files (ideally nothing).\n\nThen stage **only** the in-scope files you changed — never `git add -A`, `git add .`, or `git add -u`:\n\n```bash\ngit add {specific in-scope files}\ngit status\ngit commit -m \"$(cat <<'EOF'\nfix: address review findings\n\nFixed:\n- {brief list of fixes}\n\nTests added:\n- {brief list if any}\n\nSkipped:\n- {brief list if any, with reasons}\nEOF\n)\"\n```\n\n### 5.2 Push\n\n```bash\ngit push origin $HEAD_BRANCH\n```\n\nIf push fails due to divergence:\n\n```bash\ngit pull --rebase origin $HEAD_BRANCH\ngit push origin $HEAD_BRANCH\n```\n\n**PHASE_5_CHECKPOINT:**\n\n- [ ] Scope gate passed — no out-of-scope files staged\n- [ ] Changes committed\n- [ ] Pushed to PR branch\n\n---\n\n## Phase 6: GENERATE — Write Fix Report\n\nWrite to `$ARTIFACTS_DIR/review/fix-report.md`:\n\n```markdown\n# Fix Report: PR #{number}\n\n**Date**: {ISO timestamp}\n**Status**: COMPLETE | PARTIAL\n**Branch**: {HEAD_BRANCH}\n**Commit**: {commit hash}\n**Philosophy**: Aggressive fix — lean towards fixing everything\n\n---\n\n## Summary\n\n{2-3 sentences: what was found, what was fixed, what was skipped and why}\n\n---\n\n## Fixes Applied\n\n| Severity | Finding | Location | What Was Done |\n|----------|---------|----------|---------------|\n| CRITICAL | {title} | `file:line` | {description} |\n| HIGH | {title} | `file:line` | {description} |\n| MEDIUM | {title} | `file:line` | {description} |\n| LOW | {title} | `file:line` | {description} |\n\n---\n\n## Tests Added\n\n| File | Test Cases |\n|------|------------|\n| `{file}.test.ts` | `{test description}` |\n\n*(none)* if no tests were added\n\n---\n\n## Docs Updated\n\n| File | Changes |\n|------|---------|\n| `{file}` | {what was updated} |\n\n*(none)* if no docs were updated\n\n---\n\n## Skipped Findings\n\n| Severity | Finding | Location | Reason Skipped |\n|----------|---------|----------|----------------|\n| {sev} | {title} | `file:line` | New concern: {specific reason} |\n\n*(none)* if nothing was skipped — ideal outcome\n\n---\n\n## Blocked (Could Not Fix)\n\n| Severity | Finding | Reason |\n|----------|---------|--------|\n| {sev} | {title} | {why it could not be applied} |\n\n*(none)* if nothing was blocked\n\n---\n\n## Suggested Follow-up Issues\n\n{For any skipped or blocked findings that warrant their own issue:}\n\n| Issue Title | Priority | Reason |\n|-------------|----------|--------|\n| \"{title}\" | {P1/P2/P3} | {why this deserves a separate issue} |\n\n*(none)* if everything was addressed\n\n---\n\n## Validation\n\n| Check | Status |\n|-------|--------|\n| Type check | ✅ / ❌ |\n| Lint | ✅ / ❌ |\n| Tests | ✅ {n} passed / ❌ |\n```\n\n**PHASE_6_CHECKPOINT:**\n\n- [ ] Fix report written\n\n---\n\n## Phase 7: POST — GitHub Comment\n\nPost the fix report as a PR comment:\n\n```bash\ngh pr comment $PR_NUMBER --body \"$(cat <<'EOF'\n## ⚡ Self-Fix Report (Aggressive)\n\n**Status**: {COMPLETE | PARTIAL}\n**Pushed**: ✅ Changes pushed to `{HEAD_BRANCH}`\n**Philosophy**: Fix everything unless clearly a new concern\n\n---\n\n### Fixes Applied ({n} total)\n\n| Severity | Count |\n|----------|-------|\n| 🔴 CRITICAL | {n} |\n| 🟠 HIGH | {n} |\n| 🟡 MEDIUM | {n} |\n| 🟢 LOW | {n} |\n\n<details>\n<summary>View all fixes</summary>\n\n{For each fix:}\n- ✅ **{title}** (`{file}:{line}`) — {brief description}\n\n</details>\n\n---\n\n### Tests Added\n\n{List or \"(none)\"}\n\n---\n\n### Skipped ({n})\n\n{If any:}\n| Finding | Reason |\n|---------|--------|\n| {title} | New concern: {reason} |\n\n*(none — all findings addressed)*\n\n---\n\n### Suggested Follow-up Issues\n\n{If any skipped/blocked items warrant issues:}\n1. **{Issue Title}** — {brief description}\n\n*(none)*\n\n---\n\n### Validation\n\n✅ Type check | ✅ Lint | ✅ Tests ({n} passed)\n\n---\n\n*Self-fix by Archon · aggressive mode · fixes pushed to `{HEAD_BRANCH}`*\nEOF\n)\"\n```\n\n**PHASE_7_CHECKPOINT:**\n\n- [ ] GitHub comment posted\n\n---\n\n## Phase 8: OUTPUT — Final Summary\n\n```\n## ⚡ Self-Fix Complete\n\n**PR**: #{number}\n**Branch**: {HEAD_BRANCH}\n**Status**: COMPLETE | PARTIAL\n\nFixed: {n} (across all severities)\nTests added: {n}\nDocs updated: {n}\nSkipped: {n} (new concerns only)\nBlocked: {n}\n\nValidation: ✅ All checks pass\nPushed: ✅\n\nFix report: $ARTIFACTS_DIR/review/fix-report.md\n```\n\n---\n\n## Success Criteria\n\n- **ON_CORRECT_BRANCH**: Working on PR's head branch\n- **SCOPE_RESPECTED**: Every change is inside the 1.3 allow-list (or a new test/doc paired 1:1 with an in-scope source file); out-of-scope findings are routed to follow-up issues, never edited\n- **ALL_FINDINGS_ADDRESSED**: Every finding is fixed (in-scope), skipped (with reason), or blocked (with reason)\n- **AGGRESSIVE_WITHIN_SCOPE**: In-scope findings fixed thoroughly; out-of-scope skips are expected and correct, not a failure\n- **TESTS_ADDED**: Missing test coverage for the PR's own code addressed\n- **DOCS_UPDATED**: Documentation gaps for in-scope files filled\n- **VALIDATION_PASSED**: Type check, lint, and tests all pass\n- **COMMITTED_AND_PUSHED**: Changes committed and pushed to PR branch\n- **REPORTED**: Fix report artifact written and GitHub comment posted\n", | ||
| "archon-simplify-changes": "---\ndescription: Simplify code changed in this PR — implements fixes directly, commits, and pushes\nargument-hint: (none - operates on the current branch diff against $BASE_BRANCH)\n---\n\n# Simplify Changed Code\n\n---\n\n## IMPORTANT: Output Behavior\n\n**Your output will be posted as a GitHub comment.** Keep working output minimal:\n- Do NOT narrate each step\n- Do NOT output verbose progress updates\n- Only output the final structured report at the end\n\n---\n\n## Your Mission\n\nReview ALL code changed on this branch and implement simplifications directly. You are not advisory — you edit files, validate, commit, and push.\n\n## Scope\n\n**Only code changed in this PR** — run `git diff $BASE_BRANCH...HEAD --name-only` to get the file list. Do not touch unrelated files.\n\n## What to Simplify\n\n| Opportunity | What to Look For |\n|-------------|------------------|\n| **Unnecessary complexity** | Deep nesting, convoluted logic paths |\n| **Redundant code** | Duplicated logic, unused variables/imports |\n| **Over-abstraction** | Abstractions that obscure rather than clarify |\n| **Poor naming** | Unclear variable/function names |\n| **Nested ternaries** | Multiple conditions in ternary chains — use if/else |\n| **Dense one-liners** | Compact code that sacrifices readability |\n| **Obvious comments** | Comments that describe what code clearly shows |\n| **Inconsistent patterns** | Code that doesn't follow project conventions (read CLAUDE.md) |\n\n## Rules\n\n- **Preserve exact functionality** — simplification must not change behavior\n- **Clarity over brevity** — readable beats compact\n- **No speculative refactors** — only simplify what's obviously improvable\n- **Follow project conventions** — read CLAUDE.md before making changes\n- **Small, obvious changes** — each simplification should be self-evidently correct\n\n## Process\n\n### Phase 1: ANALYZE\n\n1. Read CLAUDE.md for project conventions\n2. Get changed files — this is your **scope allow-list**; you may edit nothing outside it:\n ```bash\n git diff $BASE_BRANCH...HEAD --name-only | sort -u > /tmp/simplify-allowlist.txt\n cat /tmp/simplify-allowlist.txt\n ```\n3. Read each changed file\n4. Identify simplification opportunities per file\n\n### Phase 2: IMPLEMENT\n\nFor each simplification:\n1. Edit the file\n2. Run `bun run type-check` — if it fails, revert that change\n3. Run `bun run lint` — if it fails, fix or revert\n\n**Track every path you edit.** You will need this list in Phase 3 to stage only the files you touched.\n\n### Phase 3: VALIDATE & COMMIT\n\n1. Run full validation: `bun run type-check && bun run lint`\n2. **Scope gate (hard).** Confirm you edited nothing outside the allow-list — simplify never adds files and never touches anything outside the PR diff:\n ```bash\n comm -23 <(git diff --name-only | sort -u) /tmp/simplify-allowlist.txt\n ```\n This must print **nothing**. For any path it prints, revert it (`git checkout -- <path>`, or `rm` a stray new file) before continuing — a simplification that touched an out-of-scope file is a scope leak, not a simplification.\n3. If simplifications were applied, stage **only** the files you edited in Phase 2 — never `git add -A`, `git add .`, or `git add -u`:\n ```bash\n # Stage by name, using the list you tracked in Phase 2\n git add path/to/file1.ts path/to/file2.ts\n # Verify nothing else snuck in\n git status --porcelain\n ```\n4. **Never stage** report, scratch, or PR-body artifacts, even if they show up as untracked or modified in the worktree:\n - Anything under `$ARTIFACTS_DIR` (the artifacts directory normally lives outside the worktree, but copies/symlinks may exist)\n - `review/`, `simplify-report.md`, `*-report.md` at the repo root\n - `.pr-body.md`, `pr-body.md`, `*.scratch.md`, `*.tmp.md`\n - If `git status --porcelain` shows files you don't recognize as part of your simplifications, leave them unstaged\n5. Commit and push only the staged source edits:\n ```bash\n git commit -m \"simplify: reduce complexity in changed files\"\n git push\n ```\n6. If no simplifications were applied, skip the commit entirely\n\n### Phase 4: REPORT\n\nWrite report to `$ARTIFACTS_DIR/review/simplify-report.md` and output:\n\n```markdown\n## Code Simplification Report\n\n### Changes Made\n\n#### 1. [Brief Title]\n**File**: `path/to/file.ts:45-60`\n**Type**: Reduced nesting / Improved naming / Removed redundancy / etc.\n**Before**: [snippet]\n**After**: [snippet]\n\n---\n\n### Summary\n\n| Metric | Value |\n|--------|-------|\n| Files analyzed | X |\n| Simplifications applied | Y |\n| Net line change | -N lines |\n| Validation | PASS / FAIL |\n\n### No Changes Needed\n(If nothing to simplify, say so — \"Code is already clean. No simplifications applied.\")\n```\n", |
There was a problem hiding this comment.
Use the remote base ref for simplify allow-list derivation.
Line 42 builds the simplify allow-list from git diff $BASE_BRANCH...HEAD without first fetching or anchoring to origin/$BASE_BRANCH. In worktree/stale-local-base scenarios this can produce an incorrect in-scope set and weaken the hard scope gate.
🔧 Proposed fix
- git diff $BASE_BRANCH...HEAD --name-only | sort -u > /tmp/simplify-allowlist.txt
+ git fetch origin $BASE_BRANCH
+ git diff origin/$BASE_BRANCH...HEAD --name-only | sort -u > /tmp/simplify-allowlist.txt📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "archon-simplify-changes": "---\ndescription: Simplify code changed in this PR — implements fixes directly, commits, and pushes\nargument-hint: (none - operates on the current branch diff against $BASE_BRANCH)\n---\n\n# Simplify Changed Code\n\n---\n\n## IMPORTANT: Output Behavior\n\n**Your output will be posted as a GitHub comment.** Keep working output minimal:\n- Do NOT narrate each step\n- Do NOT output verbose progress updates\n- Only output the final structured report at the end\n\n---\n\n## Your Mission\n\nReview ALL code changed on this branch and implement simplifications directly. You are not advisory — you edit files, validate, commit, and push.\n\n## Scope\n\n**Only code changed in this PR** — run `git diff $BASE_BRANCH...HEAD --name-only` to get the file list. Do not touch unrelated files.\n\n## What to Simplify\n\n| Opportunity | What to Look For |\n|-------------|------------------|\n| **Unnecessary complexity** | Deep nesting, convoluted logic paths |\n| **Redundant code** | Duplicated logic, unused variables/imports |\n| **Over-abstraction** | Abstractions that obscure rather than clarify |\n| **Poor naming** | Unclear variable/function names |\n| **Nested ternaries** | Multiple conditions in ternary chains — use if/else |\n| **Dense one-liners** | Compact code that sacrifices readability |\n| **Obvious comments** | Comments that describe what code clearly shows |\n| **Inconsistent patterns** | Code that doesn't follow project conventions (read CLAUDE.md) |\n\n## Rules\n\n- **Preserve exact functionality** — simplification must not change behavior\n- **Clarity over brevity** — readable beats compact\n- **No speculative refactors** — only simplify what's obviously improvable\n- **Follow project conventions** — read CLAUDE.md before making changes\n- **Small, obvious changes** — each simplification should be self-evidently correct\n\n## Process\n\n### Phase 1: ANALYZE\n\n1. Read CLAUDE.md for project conventions\n2. Get changed files — this is your **scope allow-list**; you may edit nothing outside it:\n ```bash\n git diff $BASE_BRANCH...HEAD --name-only | sort -u > /tmp/simplify-allowlist.txt\n cat /tmp/simplify-allowlist.txt\n ```\n3. Read each changed file\n4. Identify simplification opportunities per file\n\n### Phase 2: IMPLEMENT\n\nFor each simplification:\n1. Edit the file\n2. Run `bun run type-check` — if it fails, revert that change\n3. Run `bun run lint` — if it fails, fix or revert\n\n**Track every path you edit.** You will need this list in Phase 3 to stage only the files you touched.\n\n### Phase 3: VALIDATE & COMMIT\n\n1. Run full validation: `bun run type-check && bun run lint`\n2. **Scope gate (hard).** Confirm you edited nothing outside the allow-list — simplify never adds files and never touches anything outside the PR diff:\n ```bash\n comm -23 <(git diff --name-only | sort -u) /tmp/simplify-allowlist.txt\n ```\n This must print **nothing**. For any path it prints, revert it (`git checkout -- <path>`, or `rm` a stray new file) before continuing — a simplification that touched an out-of-scope file is a scope leak, not a simplification.\n3. If simplifications were applied, stage **only** the files you edited in Phase 2 — never `git add -A`, `git add .`, or `git add -u`:\n ```bash\n # Stage by name, using the list you tracked in Phase 2\n git add path/to/file1.ts path/to/file2.ts\n # Verify nothing else snuck in\n git status --porcelain\n ```\n4. **Never stage** report, scratch, or PR-body artifacts, even if they show up as untracked or modified in the worktree:\n - Anything under `$ARTIFACTS_DIR` (the artifacts directory normally lives outside the worktree, but copies/symlinks may exist)\n - `review/`, `simplify-report.md`, `*-report.md` at the repo root\n - `.pr-body.md`, `pr-body.md`, `*.scratch.md`, `*.tmp.md`\n - If `git status --porcelain` shows files you don't recognize as part of your simplifications, leave them unstaged\n5. Commit and push only the staged source edits:\n ```bash\n git commit -m \"simplify: reduce complexity in changed files\"\n git push\n ```\n6. If no simplifications were applied, skip the commit entirely\n\n### Phase 4: REPORT\n\nWrite report to `$ARTIFACTS_DIR/review/simplify-report.md` and output:\n\n```markdown\n## Code Simplification Report\n\n### Changes Made\n\n#### 1. [Brief Title]\n**File**: `path/to/file.ts:45-60`\n**Type**: Reduced nesting / Improved naming / Removed redundancy / etc.\n**Before**: [snippet]\n**After**: [snippet]\n\n---\n\n### Summary\n\n| Metric | Value |\n|--------|-------|\n| Files analyzed | X |\n| Simplifications applied | Y |\n| Net line change | -N lines |\n| Validation | PASS / FAIL |\n\n### No Changes Needed\n(If nothing to simplify, say so — \"Code is already clean. No simplifications applied.\")\n```\n", | |
| "archon-simplify-changes": "---\ndescription: Simplify code changed in this PR — implements fixes directly, commits, and pushes\nargument-hint: (none - operates on the current branch diff against $BASE_BRANCH)\n---\n\n# Simplify Changed Code\n\n---\n\n## IMPORTANT: Output Behavior\n\n**Your output will be posted as a GitHub comment.** Keep working output minimal:\n- Do NOT narrate each step\n- Do NOT output verbose progress updates\n- Only output the final structured report at the end\n\n---\n\n## Your Mission\n\nReview ALL code changed on this branch and implement simplifications directly. You are not advisory — you edit files, validate, commit, and push.\n\n## Scope\n\n**Only code changed in this PR** — run `git diff $BASE_BRANCH...HEAD --name-only` to get the file list. Do not touch unrelated files.\n\n## What to Simplify\n\n| Opportunity | What to Look For |\n|-------------|------------------|\n| **Unnecessary complexity** | Deep nesting, convoluted logic paths |\n| **Redundant code** | Duplicated logic, unused variables/imports |\n| **Over-abstraction** | Abstractions that obscure rather than clarify |\n| **Poor naming** | Unclear variable/function names |\n| **Nested ternaries** | Multiple conditions in ternary chains — use if/else |\n| **Dense one-liners** | Compact code that sacrifices readability |\n| **Obvious comments** | Comments that describe what code clearly shows |\n| **Inconsistent patterns** | Code that doesn't follow project conventions (read CLAUDE.md) |\n\n## Rules\n\n- **Preserve exact functionality** — simplification must not change behavior\n- **Clarity over brevity** — readable beats compact\n- **No speculative refactors** — only simplify what's obviously improvable\n- **Follow project conventions** — read CLAUDE.md before making changes\n- **Small, obvious changes** — each simplification should be self-evidently correct\n\n## Process\n\n### Phase 1: ANALYZE\n\n1. Read CLAUDE.md for project conventions\n2. Get changed files — this is your **scope allow-list**; you may edit nothing outside it:\n |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/workflows/src/defaults/bundled-defaults.generated.ts` at line 42,
The allow-list generation uses a local base ref ("git diff $BASE_BRANCH...HEAD
--name-only") which can be stale; update the logic that builds the simplify
allow-list (the string containing "git diff $BASE_BRANCH...HEAD --name-only") to
reference the remote base ref by fetching and diffing against
origin/$BASE_BRANCH (e.g., run "git fetch origin $BASE_BRANCH" then "git diff
origin/$BASE_BRANCH...HEAD --name-only" or resolve origin/$BASE_BRANCH via git
rev-parse before diffing) so the allow-list is derived from the up-to-date
remote base rather than a potentially stale local branch.
Both archon-self-fix-all and archon-simplify-changes could edit files outside the PR diff (scope-bleed): self-fix never computed the diff and its "fix EVERYTHING / add tests for existing code" framing pushed edits outward; simplify computed the diff but never enforced it.
Both nodes now compute an allow-list (git diff $BASE...HEAD --name-only) and run a hard pre-commit gate (comm -23 of changed files vs the allow-list) that reverts anything out of scope before staging. self-fix's framing is re-toned to "aggressive within the diff; out-of-scope findings become follow-up issues, never edits". Prompt-only; bundled-defaults.generated.ts regenerated.
Summary
Describe this PR in 2-5 bullets:
UX Journey
Before
After
Architecture Diagram
Before
After
Connection inventory (list every module-to-module edge, mark changes):
Label Snapshot
risk: low|medium|highsize: XS|S|M|L|XLcore|workflows|isolation|git|adapters|server|web|cli|paths|config|docs|dependencies|ci|tests|skills<scope>:<component>(e.g.workflows:executor,adapters:slack,core:orchestrator)Change Metadata
bug|feature|refactor|docs|security|chorecore|workflows|isolation|git|adapters|server|web|cli|paths|multiLinked Issue
Validation Evidence (required)
Commands and result summary:
Security Impact (required)
Yes/No)Yes/No)Yes/No)Yes/No)Yes, describe risk and mitigation:Compatibility / Migration
Yes/No)Yes/No)Yes/No)Human Verification (required)
What was personally validated beyond CI:
Side Effects / Blast Radius (required)
Rollback Plan (required)
Risks and Mitigations
List real risks in this PR (or write
None).Summary by CodeRabbit