autonomous-coding-toolkit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +22 -0
- package/.claude-plugin/plugin.json +13 -0
- package/LICENSE +21 -0
- package/Makefile +21 -0
- package/README.md +140 -0
- package/SECURITY.md +28 -0
- package/agents/bash-expert.md +113 -0
- package/agents/dependency-auditor.md +138 -0
- package/agents/integration-tester.md +120 -0
- package/agents/lesson-scanner.md +149 -0
- package/agents/python-expert.md +179 -0
- package/agents/service-monitor.md +141 -0
- package/agents/shell-expert.md +147 -0
- package/benchmarks/runner.sh +147 -0
- package/benchmarks/tasks/01-rest-endpoint/rubric.sh +29 -0
- package/benchmarks/tasks/01-rest-endpoint/task.md +17 -0
- package/benchmarks/tasks/02-refactor-module/task.md +8 -0
- package/benchmarks/tasks/03-fix-integration-bug/task.md +8 -0
- package/benchmarks/tasks/04-add-test-coverage/task.md +8 -0
- package/benchmarks/tasks/05-multi-file-feature/task.md +8 -0
- package/bin/act.js +238 -0
- package/commands/autocode.md +6 -0
- package/commands/cancel-ralph.md +18 -0
- package/commands/code-factory.md +53 -0
- package/commands/create-prd.md +55 -0
- package/commands/ralph-loop.md +18 -0
- package/commands/run-plan.md +117 -0
- package/commands/submit-lesson.md +122 -0
- package/docs/ARCHITECTURE.md +630 -0
- package/docs/CONTRIBUTING.md +125 -0
- package/docs/lessons/0001-bare-exception-swallowing.md +34 -0
- package/docs/lessons/0002-async-def-without-await.md +28 -0
- package/docs/lessons/0003-create-task-without-callback.md +28 -0
- package/docs/lessons/0004-hardcoded-test-counts.md +28 -0
- package/docs/lessons/0005-sqlite-without-closing.md +33 -0
- package/docs/lessons/0006-venv-pip-path.md +27 -0
- package/docs/lessons/0007-runner-state-self-rejection.md +35 -0
- package/docs/lessons/0008-quality-gate-blind-spot.md +33 -0
- package/docs/lessons/0009-parser-overcount-empty-batches.md +36 -0
- package/docs/lessons/0010-local-outside-function-bash.md +33 -0
- package/docs/lessons/0011-batch-tests-for-unimplemented-code.md +36 -0
- package/docs/lessons/0012-api-markdown-unescaped-chars.md +33 -0
- package/docs/lessons/0013-export-prefix-env-parsing.md +33 -0
- package/docs/lessons/0014-decorator-registry-import-side-effect.md +43 -0
- package/docs/lessons/0015-frontend-backend-schema-drift.md +43 -0
- package/docs/lessons/0016-event-driven-cold-start-seeding.md +44 -0
- package/docs/lessons/0017-copy-paste-logic-diverges.md +43 -0
- package/docs/lessons/0018-layer-passes-pipeline-broken.md +45 -0
- package/docs/lessons/0019-systemd-envfile-ignores-export.md +41 -0
- package/docs/lessons/0020-persist-state-incrementally.md +44 -0
- package/docs/lessons/0021-dual-axis-testing.md +48 -0
- package/docs/lessons/0022-jsx-factory-shadowing.md +43 -0
- package/docs/lessons/0023-static-analysis-spiral.md +51 -0
- package/docs/lessons/0024-shared-pipeline-implementation.md +55 -0
- package/docs/lessons/0025-defense-in-depth-all-entry-points.md +65 -0
- package/docs/lessons/0026-linter-no-rules-false-enforcement.md +54 -0
- package/docs/lessons/0027-jsx-silent-prop-drop.md +64 -0
- package/docs/lessons/0028-no-infrastructure-in-client-code.md +49 -0
- package/docs/lessons/0029-never-write-secrets-to-files.md +61 -0
- package/docs/lessons/0030-cache-merge-not-replace.md +62 -0
- package/docs/lessons/0031-verify-units-at-boundaries.md +66 -0
- package/docs/lessons/0032-module-lifecycle-subscribe-unsubscribe.md +89 -0
- package/docs/lessons/0033-async-iteration-mutable-snapshot.md +72 -0
- package/docs/lessons/0034-caller-missing-await-silent-discard.md +65 -0
- package/docs/lessons/0035-duplicate-registration-silent-overwrite.md +85 -0
- package/docs/lessons/0036-websocket-dirty-disconnect.md +33 -0
- package/docs/lessons/0037-parallel-agents-worktree-corruption.md +31 -0
- package/docs/lessons/0038-subscribe-no-stored-ref.md +36 -0
- package/docs/lessons/0039-fallback-or-default-hides-bugs.md +34 -0
- package/docs/lessons/0040-event-firehose-filter-first.md +36 -0
- package/docs/lessons/0041-ambiguous-base-dir-path-nesting.md +32 -0
- package/docs/lessons/0042-spec-compliance-insufficient.md +36 -0
- package/docs/lessons/0043-exact-count-extensible-collections.md +32 -0
- package/docs/lessons/0044-relative-file-deps-worktree.md +39 -0
- package/docs/lessons/0045-iterative-design-improvement.md +33 -0
- package/docs/lessons/0046-plan-assertion-math-bugs.md +38 -0
- package/docs/lessons/0047-pytest-single-threaded-default.md +37 -0
- package/docs/lessons/0048-integration-wiring-batch.md +40 -0
- package/docs/lessons/0049-ab-verification.md +41 -0
- package/docs/lessons/0050-editing-sourced-files-during-execution.md +33 -0
- package/docs/lessons/0051-infrastructure-fixes-cant-self-heal.md +30 -0
- package/docs/lessons/0052-uncommitted-changes-poison-quality-gates.md +31 -0
- package/docs/lessons/0053-jq-compact-flag-inconsistency.md +31 -0
- package/docs/lessons/0054-parser-matches-inside-code-blocks.md +30 -0
- package/docs/lessons/0055-agents-compensate-for-garbled-prompts.md +31 -0
- package/docs/lessons/0056-grep-count-exit-code-on-zero.md +42 -0
- package/docs/lessons/0057-new-artifacts-break-git-clean-gates.md +42 -0
- package/docs/lessons/0058-dead-config-keys-never-consumed.md +49 -0
- package/docs/lessons/0059-contract-test-shared-structures.md +53 -0
- package/docs/lessons/0060-set-e-silent-death-in-runners.md +53 -0
- package/docs/lessons/0061-context-injection-dirty-state.md +50 -0
- package/docs/lessons/0062-sibling-bug-neighborhood-scan.md +29 -0
- package/docs/lessons/0063-one-flag-two-lifetimes.md +31 -0
- package/docs/lessons/0064-test-passes-wrong-reason.md +31 -0
- package/docs/lessons/0065-pipefail-grep-count-double-output.md +39 -0
- package/docs/lessons/0066-local-keyword-outside-function.md +37 -0
- package/docs/lessons/0067-stdin-hang-non-interactive-shell.md +36 -0
- package/docs/lessons/0068-agent-builds-wrong-thing-correctly.md +31 -0
- package/docs/lessons/0069-plan-quality-dominates-execution.md +30 -0
- package/docs/lessons/0070-spec-echo-back-prevents-drift.md +31 -0
- package/docs/lessons/0071-positive-instructions-outperform-negative.md +30 -0
- package/docs/lessons/0072-lost-in-the-middle-context-placement.md +30 -0
- package/docs/lessons/0073-unscoped-lessons-cause-false-positives.md +30 -0
- package/docs/lessons/0074-stale-context-injection-wrong-batch.md +32 -0
- package/docs/lessons/0075-research-artifacts-must-persist.md +32 -0
- package/docs/lessons/0076-wrong-decomposition-contaminates-downstream.md +30 -0
- package/docs/lessons/0077-cherry-pick-merges-need-manual-resolution.md +30 -0
- package/docs/lessons/0078-static-review-without-live-test.md +30 -0
- package/docs/lessons/0079-integration-wiring-batch-required.md +32 -0
- package/docs/lessons/FRAMEWORK.md +161 -0
- package/docs/lessons/SUMMARY.md +201 -0
- package/docs/lessons/TEMPLATE.md +85 -0
- package/docs/plans/2026-02-21-code-factory-v2-design.md +204 -0
- package/docs/plans/2026-02-21-code-factory-v2-implementation-plan.md +2189 -0
- package/docs/plans/2026-02-21-code-factory-v2-phase4-design.md +537 -0
- package/docs/plans/2026-02-21-code-factory-v2-phase4-implementation-plan.md +2012 -0
- package/docs/plans/2026-02-21-hardening-pass-design.md +108 -0
- package/docs/plans/2026-02-21-hardening-pass-plan.md +1378 -0
- package/docs/plans/2026-02-21-mab-research-report.md +406 -0
- package/docs/plans/2026-02-21-marketplace-restructure-design.md +240 -0
- package/docs/plans/2026-02-21-marketplace-restructure-plan.md +832 -0
- package/docs/plans/2026-02-21-phase4-completion-plan.md +697 -0
- package/docs/plans/2026-02-21-validator-suite-design.md +148 -0
- package/docs/plans/2026-02-21-validator-suite-plan.md +540 -0
- package/docs/plans/2026-02-22-mab-research-round2.md +556 -0
- package/docs/plans/2026-02-22-mab-run-design.md +462 -0
- package/docs/plans/2026-02-22-mab-run-plan.md +2046 -0
- package/docs/plans/2026-02-22-operations-design-methodology-research.md +681 -0
- package/docs/plans/2026-02-22-research-agent-failure-taxonomy.md +532 -0
- package/docs/plans/2026-02-22-research-code-guideline-policies.md +886 -0
- package/docs/plans/2026-02-22-research-codebase-audit-refactoring.md +908 -0
- package/docs/plans/2026-02-22-research-coding-standards-documentation.md +541 -0
- package/docs/plans/2026-02-22-research-competitive-landscape.md +687 -0
- package/docs/plans/2026-02-22-research-comprehensive-testing.md +1076 -0
- package/docs/plans/2026-02-22-research-context-utilization.md +459 -0
- package/docs/plans/2026-02-22-research-cost-quality-tradeoff.md +548 -0
- package/docs/plans/2026-02-22-research-lesson-transferability.md +508 -0
- package/docs/plans/2026-02-22-research-multi-agent-coordination.md +312 -0
- package/docs/plans/2026-02-22-research-phase-integration.md +602 -0
- package/docs/plans/2026-02-22-research-plan-quality.md +428 -0
- package/docs/plans/2026-02-22-research-prompt-engineering.md +558 -0
- package/docs/plans/2026-02-22-research-unconventional-perspectives.md +528 -0
- package/docs/plans/2026-02-22-research-user-adoption.md +638 -0
- package/docs/plans/2026-02-22-research-verification-effectiveness.md +433 -0
- package/docs/plans/2026-02-23-agent-suite-design.md +299 -0
- package/docs/plans/2026-02-23-agent-suite-plan.md +578 -0
- package/docs/plans/2026-02-23-phase3-cost-infrastructure-design.md +148 -0
- package/docs/plans/2026-02-23-phase3-cost-infrastructure-plan.md +1062 -0
- package/docs/plans/2026-02-23-research-bash-expert-agent.md +543 -0
- package/docs/plans/2026-02-23-research-dependency-auditor-agent.md +564 -0
- package/docs/plans/2026-02-23-research-improving-existing-agents.md +503 -0
- package/docs/plans/2026-02-23-research-integration-tester-agent.md +454 -0
- package/docs/plans/2026-02-23-research-python-expert-agent.md +429 -0
- package/docs/plans/2026-02-23-research-service-monitor-agent.md +425 -0
- package/docs/plans/2026-02-23-research-shell-expert-agent.md +533 -0
- package/docs/plans/2026-02-23-roadmap-to-completion.md +530 -0
- package/docs/plans/2026-02-24-headless-module-split-design.md +98 -0
- package/docs/plans/2026-02-24-headless-module-split.md +443 -0
- package/docs/plans/2026-02-24-lesson-scope-metadata-design.md +228 -0
- package/docs/plans/2026-02-24-lesson-scope-metadata-plan.md +968 -0
- package/docs/plans/2026-02-24-npm-packaging-design.md +841 -0
- package/docs/plans/2026-02-24-npm-packaging-plan.md +1965 -0
- package/docs/plans/audit-findings.md +186 -0
- package/docs/telegram-notification-format.md +98 -0
- package/examples/example-plan.md +51 -0
- package/examples/example-prd.json +72 -0
- package/examples/example-roadmap.md +33 -0
- package/examples/quickstart-plan.md +63 -0
- package/hooks/hooks.json +26 -0
- package/hooks/setup-symlinks.sh +48 -0
- package/hooks/stop-hook.sh +135 -0
- package/package.json +47 -0
- package/policies/bash.md +71 -0
- package/policies/python.md +71 -0
- package/policies/testing.md +61 -0
- package/policies/universal.md +60 -0
- package/scripts/analyze-report.sh +97 -0
- package/scripts/architecture-map.sh +145 -0
- package/scripts/auto-compound.sh +273 -0
- package/scripts/batch-audit.sh +42 -0
- package/scripts/batch-test.sh +101 -0
- package/scripts/entropy-audit.sh +221 -0
- package/scripts/failure-digest.sh +51 -0
- package/scripts/generate-ast-rules.sh +96 -0
- package/scripts/init.sh +112 -0
- package/scripts/lesson-check.sh +428 -0
- package/scripts/lib/common.sh +61 -0
- package/scripts/lib/cost-tracking.sh +153 -0
- package/scripts/lib/ollama.sh +60 -0
- package/scripts/lib/progress-writer.sh +128 -0
- package/scripts/lib/run-plan-context.sh +215 -0
- package/scripts/lib/run-plan-echo-back.sh +231 -0
- package/scripts/lib/run-plan-headless.sh +396 -0
- package/scripts/lib/run-plan-notify.sh +57 -0
- package/scripts/lib/run-plan-parser.sh +81 -0
- package/scripts/lib/run-plan-prompt.sh +215 -0
- package/scripts/lib/run-plan-quality-gate.sh +132 -0
- package/scripts/lib/run-plan-routing.sh +315 -0
- package/scripts/lib/run-plan-sampling.sh +170 -0
- package/scripts/lib/run-plan-scoring.sh +146 -0
- package/scripts/lib/run-plan-state.sh +142 -0
- package/scripts/lib/run-plan-team.sh +199 -0
- package/scripts/lib/telegram.sh +54 -0
- package/scripts/lib/thompson-sampling.sh +176 -0
- package/scripts/license-check.sh +74 -0
- package/scripts/mab-run.sh +575 -0
- package/scripts/module-size-check.sh +146 -0
- package/scripts/patterns/async-no-await.yml +5 -0
- package/scripts/patterns/bare-except.yml +6 -0
- package/scripts/patterns/empty-catch.yml +6 -0
- package/scripts/patterns/hardcoded-localhost.yml +9 -0
- package/scripts/patterns/retry-loop-no-backoff.yml +12 -0
- package/scripts/pipeline-status.sh +197 -0
- package/scripts/policy-check.sh +226 -0
- package/scripts/prior-art-search.sh +133 -0
- package/scripts/promote-mab-lessons.sh +126 -0
- package/scripts/prompts/agent-a-superpowers.md +29 -0
- package/scripts/prompts/agent-b-ralph.md +29 -0
- package/scripts/prompts/judge-agent.md +61 -0
- package/scripts/prompts/planner-agent.md +44 -0
- package/scripts/pull-community-lessons.sh +90 -0
- package/scripts/quality-gate.sh +266 -0
- package/scripts/research-gate.sh +90 -0
- package/scripts/run-plan.sh +329 -0
- package/scripts/scope-infer.sh +159 -0
- package/scripts/setup-ralph-loop.sh +155 -0
- package/scripts/telemetry.sh +230 -0
- package/scripts/tests/run-all-tests.sh +52 -0
- package/scripts/tests/test-act-cli.sh +46 -0
- package/scripts/tests/test-agents-md.sh +87 -0
- package/scripts/tests/test-analyze-report.sh +114 -0
- package/scripts/tests/test-architecture-map.sh +89 -0
- package/scripts/tests/test-auto-compound.sh +169 -0
- package/scripts/tests/test-batch-test.sh +65 -0
- package/scripts/tests/test-benchmark-runner.sh +25 -0
- package/scripts/tests/test-common.sh +168 -0
- package/scripts/tests/test-cost-tracking.sh +158 -0
- package/scripts/tests/test-echo-back.sh +180 -0
- package/scripts/tests/test-entropy-audit.sh +146 -0
- package/scripts/tests/test-failure-digest.sh +66 -0
- package/scripts/tests/test-generate-ast-rules.sh +145 -0
- package/scripts/tests/test-helpers.sh +82 -0
- package/scripts/tests/test-init.sh +47 -0
- package/scripts/tests/test-lesson-check.sh +278 -0
- package/scripts/tests/test-lesson-local.sh +55 -0
- package/scripts/tests/test-license-check.sh +109 -0
- package/scripts/tests/test-mab-run.sh +182 -0
- package/scripts/tests/test-ollama-lib.sh +49 -0
- package/scripts/tests/test-ollama.sh +60 -0
- package/scripts/tests/test-pipeline-status.sh +198 -0
- package/scripts/tests/test-policy-check.sh +124 -0
- package/scripts/tests/test-prior-art-search.sh +96 -0
- package/scripts/tests/test-progress-writer.sh +140 -0
- package/scripts/tests/test-promote-mab-lessons.sh +110 -0
- package/scripts/tests/test-pull-community-lessons.sh +149 -0
- package/scripts/tests/test-quality-gate.sh +241 -0
- package/scripts/tests/test-research-gate.sh +132 -0
- package/scripts/tests/test-run-plan-cli.sh +86 -0
- package/scripts/tests/test-run-plan-context.sh +305 -0
- package/scripts/tests/test-run-plan-e2e.sh +153 -0
- package/scripts/tests/test-run-plan-headless.sh +424 -0
- package/scripts/tests/test-run-plan-notify.sh +124 -0
- package/scripts/tests/test-run-plan-parser.sh +217 -0
- package/scripts/tests/test-run-plan-prompt.sh +254 -0
- package/scripts/tests/test-run-plan-quality-gate.sh +222 -0
- package/scripts/tests/test-run-plan-routing.sh +178 -0
- package/scripts/tests/test-run-plan-scoring.sh +148 -0
- package/scripts/tests/test-run-plan-state.sh +261 -0
- package/scripts/tests/test-run-plan-team.sh +157 -0
- package/scripts/tests/test-scope-infer.sh +150 -0
- package/scripts/tests/test-setup-ralph-loop.sh +63 -0
- package/scripts/tests/test-telegram-env.sh +38 -0
- package/scripts/tests/test-telegram.sh +121 -0
- package/scripts/tests/test-telemetry.sh +46 -0
- package/scripts/tests/test-thompson-sampling.sh +139 -0
- package/scripts/tests/test-validate-all.sh +60 -0
- package/scripts/tests/test-validate-commands.sh +89 -0
- package/scripts/tests/test-validate-hooks.sh +98 -0
- package/scripts/tests/test-validate-lessons.sh +150 -0
- package/scripts/tests/test-validate-plan-quality.sh +235 -0
- package/scripts/tests/test-validate-plans.sh +187 -0
- package/scripts/tests/test-validate-plugin.sh +106 -0
- package/scripts/tests/test-validate-prd.sh +184 -0
- package/scripts/tests/test-validate-skills.sh +134 -0
- package/scripts/validate-all.sh +57 -0
- package/scripts/validate-commands.sh +67 -0
- package/scripts/validate-hooks.sh +89 -0
- package/scripts/validate-lessons.sh +98 -0
- package/scripts/validate-plan-quality.sh +369 -0
- package/scripts/validate-plans.sh +120 -0
- package/scripts/validate-plugin.sh +86 -0
- package/scripts/validate-policies.sh +42 -0
- package/scripts/validate-prd.sh +118 -0
- package/scripts/validate-skills.sh +96 -0
- package/skills/autocode/SKILL.md +285 -0
- package/skills/autocode/ab-verification.md +51 -0
- package/skills/autocode/code-quality-standards.md +37 -0
- package/skills/autocode/competitive-mode.md +364 -0
- package/skills/brainstorming/SKILL.md +97 -0
- package/skills/capture-lesson/SKILL.md +187 -0
- package/skills/check-lessons/SKILL.md +116 -0
- package/skills/dispatching-parallel-agents/SKILL.md +110 -0
- package/skills/executing-plans/SKILL.md +85 -0
- package/skills/finishing-a-development-branch/SKILL.md +201 -0
- package/skills/receiving-code-review/SKILL.md +72 -0
- package/skills/requesting-code-review/SKILL.md +59 -0
- package/skills/requesting-code-review/code-reviewer.md +82 -0
- package/skills/research/SKILL.md +145 -0
- package/skills/roadmap/SKILL.md +115 -0
- package/skills/subagent-driven-development/SKILL.md +98 -0
- package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +18 -0
- package/skills/subagent-driven-development/implementer-prompt.md +73 -0
- package/skills/subagent-driven-development/spec-reviewer-prompt.md +57 -0
- package/skills/systematic-debugging/SKILL.md +134 -0
- package/skills/systematic-debugging/condition-based-waiting.md +64 -0
- package/skills/systematic-debugging/defense-in-depth.md +32 -0
- package/skills/systematic-debugging/root-cause-tracing.md +55 -0
- package/skills/test-driven-development/SKILL.md +167 -0
- package/skills/using-git-worktrees/SKILL.md +219 -0
- package/skills/using-superpowers/SKILL.md +54 -0
- package/skills/verification-before-completion/SKILL.md +140 -0
- package/skills/verify/SKILL.md +82 -0
- package/skills/writing-plans/SKILL.md +128 -0
- package/skills/writing-skills/SKILL.md +93 -0
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
# Phase 4 Completion Implementation Plan
|
|
2
|
+
|
|
3
|
+
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
|
|
4
|
+
|
|
5
|
+
**Goal:** Complete the remaining 15% of Phase 4 — batch-type-aware sampling, multi-armed bandit learning, AGENTS.md generation, and 2 missing ast-grep patterns.
|
|
6
|
+
|
|
7
|
+
**Architecture:** Extend existing sampling code in `run-plan-headless.sh` with batch-type classification and learned prompt allocation from `run-plan-scoring.sh`. Add `generate_agents_md()` to `run-plan-prompt.sh`. Add 2 pattern files to `scripts/patterns/`.
|
|
8
|
+
|
|
9
|
+
**Tech Stack:** Bash, jq, ast-grep YAML
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Quality Gates
|
|
14
|
+
|
|
15
|
+
Between each batch, run:
|
|
16
|
+
```bash
|
|
17
|
+
shellcheck -S warning scripts/*.sh scripts/lib/*.sh
|
|
18
|
+
bash scripts/tests/run-all-tests.sh
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Batch 1: Batch-Type Classification + Learned Prompt Allocation
|
|
24
|
+
|
|
25
|
+
### Task 1: Write tests for batch type classification
|
|
26
|
+
|
|
27
|
+
**Files:**
|
|
28
|
+
- Create: `scripts/tests/test-run-plan-sampling.sh`
|
|
29
|
+
|
|
30
|
+
**Step 1: Write the test file**
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
#!/usr/bin/env bash
|
|
34
|
+
set -euo pipefail
|
|
35
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
36
|
+
source "$SCRIPT_DIR/../lib/run-plan-scoring.sh"
|
|
37
|
+
source "$SCRIPT_DIR/helpers.sh"
|
|
38
|
+
|
|
39
|
+
WORK=$(mktemp -d)
|
|
40
|
+
trap 'rm -rf "$WORK"' EXIT
|
|
41
|
+
|
|
42
|
+
# === classify_batch_type ===
|
|
43
|
+
|
|
44
|
+
assert_exit "classify: Create files = new-file" 0 bash -c "
|
|
45
|
+
source $SCRIPT_DIR/../lib/run-plan-scoring.sh
|
|
46
|
+
source $SCRIPT_DIR/../lib/run-plan-parser.sh
|
|
47
|
+
mkdir -p $WORK/plans
|
|
48
|
+
cat > $WORK/plans/test.md << 'PLAN'
|
|
49
|
+
## Batch 1: Setup
|
|
50
|
+
**Files:**
|
|
51
|
+
- Create: src/lib.py
|
|
52
|
+
- Create: src/util.py
|
|
53
|
+
- Test: tests/test_lib.py
|
|
54
|
+
|
|
55
|
+
**Step 1:** Write files
|
|
56
|
+
PLAN
|
|
57
|
+
result=\$(classify_batch_type '$WORK/plans/test.md' 1)
|
|
58
|
+
[[ \$result == 'new-file' ]]
|
|
59
|
+
"
|
|
60
|
+
|
|
61
|
+
assert_exit "classify: Modify only = refactoring" 0 bash -c "
|
|
62
|
+
source $SCRIPT_DIR/../lib/run-plan-scoring.sh
|
|
63
|
+
source $SCRIPT_DIR/../lib/run-plan-parser.sh
|
|
64
|
+
cat > $WORK/plans/test2.md << 'PLAN'
|
|
65
|
+
## Batch 1: Refactor auth
|
|
66
|
+
**Files:**
|
|
67
|
+
- Modify: src/auth.py:20-50
|
|
68
|
+
- Modify: src/session.py:10-30
|
|
69
|
+
- Test: tests/test_auth.py
|
|
70
|
+
|
|
71
|
+
**Step 1:** Update auth
|
|
72
|
+
PLAN
|
|
73
|
+
result=\$(classify_batch_type '$WORK/plans/test2.md' 1)
|
|
74
|
+
[[ \$result == 'refactoring' ]]
|
|
75
|
+
"
|
|
76
|
+
|
|
77
|
+
assert_exit "classify: Run commands only = test-only" 0 bash -c "
|
|
78
|
+
source $SCRIPT_DIR/../lib/run-plan-scoring.sh
|
|
79
|
+
source $SCRIPT_DIR/../lib/run-plan-parser.sh
|
|
80
|
+
cat > $WORK/plans/test3.md << 'PLAN'
|
|
81
|
+
## Batch 1: Verify
|
|
82
|
+
Run: pytest tests/ -v
|
|
83
|
+
Run: bash scripts/quality-gate.sh --project-root .
|
|
84
|
+
|
|
85
|
+
**Step 1:** Run tests
|
|
86
|
+
PLAN
|
|
87
|
+
result=\$(classify_batch_type '$WORK/plans/test3.md' 1)
|
|
88
|
+
[[ \$result == 'test-only' ]]
|
|
89
|
+
"
|
|
90
|
+
|
|
91
|
+
assert_exit "classify: integration wiring title = integration" 0 bash -c "
|
|
92
|
+
source $SCRIPT_DIR/../lib/run-plan-scoring.sh
|
|
93
|
+
source $SCRIPT_DIR/../lib/run-plan-parser.sh
|
|
94
|
+
cat > $WORK/plans/test4.md << 'PLAN'
|
|
95
|
+
## Batch 1: Integration Wiring
|
|
96
|
+
**Files:**
|
|
97
|
+
- Modify: src/main.py
|
|
98
|
+
- Create: src/glue.py
|
|
99
|
+
|
|
100
|
+
**Step 1:** Wire components
|
|
101
|
+
PLAN
|
|
102
|
+
result=\$(classify_batch_type '$WORK/plans/test4.md' 1)
|
|
103
|
+
[[ \$result == 'integration' ]]
|
|
104
|
+
"
|
|
105
|
+
|
|
106
|
+
echo ""
|
|
107
|
+
echo "Results: tests completed"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Step 2: Write test for prompt variant allocation**
|
|
111
|
+
|
|
112
|
+
Append to the same test file:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# === get_prompt_variants ===
|
|
116
|
+
|
|
117
|
+
# Test: with no history, returns vanilla + random variants
|
|
118
|
+
assert_exit "variants: no history = vanilla + defaults" 0 bash -c "
|
|
119
|
+
source $SCRIPT_DIR/../lib/run-plan-scoring.sh
|
|
120
|
+
result=\$(get_prompt_variants 'new-file' '/nonexistent/outcomes.json' 3)
|
|
121
|
+
echo \"\$result\" | grep -q 'vanilla'
|
|
122
|
+
"
|
|
123
|
+
|
|
124
|
+
# Test: get_prompt_variants returns exactly N variants
|
|
125
|
+
assert_exit "variants: returns N lines" 0 bash -c "
|
|
126
|
+
source $SCRIPT_DIR/../lib/run-plan-scoring.sh
|
|
127
|
+
result=\$(get_prompt_variants 'refactoring' '/nonexistent/outcomes.json' 3)
|
|
128
|
+
count=\$(echo \"\$result\" | wc -l)
|
|
129
|
+
[[ \$count -eq 3 ]]
|
|
130
|
+
"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Step 3: Run tests to verify they fail**
|
|
134
|
+
|
|
135
|
+
Run: `bash scripts/tests/test-run-plan-sampling.sh`
|
|
136
|
+
Expected: FAIL — `classify_batch_type` and `get_prompt_variants` not defined
|
|
137
|
+
|
|
138
|
+
**Step 4: Commit test file**
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
git add scripts/tests/test-run-plan-sampling.sh
|
|
142
|
+
git commit -m "test: add sampling tests for batch-type classification and prompt variants"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
### Task 2: Implement batch-type classification
|
|
148
|
+
|
|
149
|
+
**Files:**
|
|
150
|
+
- Modify: `scripts/lib/run-plan-scoring.sh`
|
|
151
|
+
|
|
152
|
+
**Step 1: Add classify_batch_type function**
|
|
153
|
+
|
|
154
|
+
Append to `scripts/lib/run-plan-scoring.sh`:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# Classify a batch by its dominant action type.
|
|
158
|
+
# Returns: new-file | refactoring | integration | test-only | unknown
|
|
159
|
+
classify_batch_type() {
|
|
160
|
+
local plan_file="$1" batch_num="$2"
|
|
161
|
+
local batch_text title
|
|
162
|
+
|
|
163
|
+
# Source parser if not already loaded
|
|
164
|
+
type get_batch_text &>/dev/null || source "$(dirname "${BASH_SOURCE[0]}")/run-plan-parser.sh"
|
|
165
|
+
|
|
166
|
+
batch_text=$(get_batch_text "$plan_file" "$batch_num" 2>/dev/null || true)
|
|
167
|
+
title=$(get_batch_title "$plan_file" "$batch_num" 2>/dev/null || true)
|
|
168
|
+
|
|
169
|
+
# Check title for integration keywords
|
|
170
|
+
if echo "$title" | grep -qiE 'integrat|wir|connect|glue'; then
|
|
171
|
+
echo "integration"
|
|
172
|
+
return
|
|
173
|
+
fi
|
|
174
|
+
|
|
175
|
+
local creates modifies runs
|
|
176
|
+
creates=$(echo "$batch_text" | grep -cE '^\s*-\s*Create:' || true)
|
|
177
|
+
modifies=$(echo "$batch_text" | grep -cE '^\s*-\s*Modify:' || true)
|
|
178
|
+
runs=$(echo "$batch_text" | grep -cE '^Run:' || true)
|
|
179
|
+
|
|
180
|
+
# Test-only: only Run commands, no Create/Modify
|
|
181
|
+
if [[ "${creates:-0}" -eq 0 && "${modifies:-0}" -eq 0 && "${runs:-0}" -gt 0 ]]; then
|
|
182
|
+
echo "test-only"
|
|
183
|
+
return
|
|
184
|
+
fi
|
|
185
|
+
|
|
186
|
+
# New file creation dominant
|
|
187
|
+
if [[ "${creates:-0}" -gt "${modifies:-0}" ]]; then
|
|
188
|
+
echo "new-file"
|
|
189
|
+
return
|
|
190
|
+
fi
|
|
191
|
+
|
|
192
|
+
# Refactoring: modifications dominant
|
|
193
|
+
if [[ "${modifies:-0}" -gt 0 ]]; then
|
|
194
|
+
echo "refactoring"
|
|
195
|
+
return
|
|
196
|
+
fi
|
|
197
|
+
|
|
198
|
+
echo "unknown"
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Step 2: Add get_prompt_variants function**
|
|
203
|
+
|
|
204
|
+
Append to `scripts/lib/run-plan-scoring.sh`:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# Get prompt variant suffixes for a batch type.
|
|
208
|
+
# Uses learned outcomes if available, otherwise defaults.
|
|
209
|
+
# Args: <batch_type> <outcomes_file> <count>
|
|
210
|
+
# Output: N lines, each a prompt suffix string
|
|
211
|
+
get_prompt_variants() {
|
|
212
|
+
local batch_type="$1"
|
|
213
|
+
local outcomes_file="$2"
|
|
214
|
+
local count="${3:-3}"
|
|
215
|
+
|
|
216
|
+
# Default variants per batch type
|
|
217
|
+
local -A type_variants
|
|
218
|
+
type_variants[new-file]="check all imports before running tests|write tests first then implement"
|
|
219
|
+
type_variants[refactoring]="minimal change only|run tests after each edit"
|
|
220
|
+
type_variants[integration]="trace end-to-end before declaring done|check every import and export"
|
|
221
|
+
type_variants[test-only]="use real objects not mocks|focus on edge cases only"
|
|
222
|
+
type_variants[unknown]="try a different approach|make the minimum possible change"
|
|
223
|
+
|
|
224
|
+
local defaults="${type_variants[$batch_type]:-${type_variants[unknown]}}"
|
|
225
|
+
|
|
226
|
+
# Slot 1: always vanilla
|
|
227
|
+
echo "vanilla"
|
|
228
|
+
|
|
229
|
+
# Check for learned winners
|
|
230
|
+
local learned_variant=""
|
|
231
|
+
if [[ -f "$outcomes_file" ]]; then
|
|
232
|
+
learned_variant=$(jq -r --arg bt "$batch_type" \
|
|
233
|
+
'[.[] | select(.batch_type == $bt and .won == true)] | sort_by(.score) | reverse | .[0].prompt_variant // empty' \
|
|
234
|
+
"$outcomes_file" 2>/dev/null || true)
|
|
235
|
+
fi
|
|
236
|
+
|
|
237
|
+
# Slot 2: learned winner or first default
|
|
238
|
+
local variant2="${learned_variant:-$(echo "$defaults" | cut -d'|' -f1)}"
|
|
239
|
+
if [[ "$count" -ge 2 ]]; then
|
|
240
|
+
echo "$variant2"
|
|
241
|
+
fi
|
|
242
|
+
|
|
243
|
+
# Slot 3+: remaining defaults (exploration)
|
|
244
|
+
local slot=3
|
|
245
|
+
IFS='|' read -ra parts <<< "$defaults"
|
|
246
|
+
for part in "${parts[@]}"; do
|
|
247
|
+
[[ "$slot" -gt "$count" ]] && break
|
|
248
|
+
[[ "$part" == "$variant2" ]] && continue
|
|
249
|
+
echo "$part"
|
|
250
|
+
slot=$((slot + 1))
|
|
251
|
+
done
|
|
252
|
+
|
|
253
|
+
# Fill remaining slots with generic variants
|
|
254
|
+
while [[ "$slot" -le "$count" ]]; do
|
|
255
|
+
echo "try a fundamentally different approach"
|
|
256
|
+
slot=$((slot + 1))
|
|
257
|
+
done
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Step 3: Run tests**
|
|
262
|
+
|
|
263
|
+
Run: `bash scripts/tests/test-run-plan-sampling.sh`
|
|
264
|
+
Expected: ALL PASS
|
|
265
|
+
|
|
266
|
+
**Step 4: Run full suite**
|
|
267
|
+
|
|
268
|
+
Run: `bash scripts/tests/run-all-tests.sh`
|
|
269
|
+
Expected: 25 test files, ALL PASS
|
|
270
|
+
|
|
271
|
+
**Step 5: Commit**
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
git add scripts/lib/run-plan-scoring.sh
|
|
275
|
+
git commit -m "feat: add batch-type classification and learned prompt variant allocation"
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
### Task 3: Wire batch-type-aware variants into headless runner
|
|
281
|
+
|
|
282
|
+
**Files:**
|
|
283
|
+
- Modify: `scripts/lib/run-plan-headless.sh:96-102` (replace hardcoded variant suffixes)
|
|
284
|
+
|
|
285
|
+
**Step 1: Replace the hardcoded variant case statement**
|
|
286
|
+
|
|
287
|
+
In `scripts/lib/run-plan-headless.sh`, replace lines 96-102:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
for ((c = 0; c < SAMPLE_COUNT; c++)); do
|
|
291
|
+
local variant_suffix=""
|
|
292
|
+
case $c in
|
|
293
|
+
0) variant_suffix="" ;; # vanilla retry
|
|
294
|
+
1) variant_suffix=$'\nIMPORTANT: Take a fundamentally different approach than the previous attempt.' ;;
|
|
295
|
+
2) variant_suffix=$'\nIMPORTANT: Make the minimum possible change to pass the quality gate.' ;;
|
|
296
|
+
esac
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
With:
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
# Classify batch and get type-aware prompt variants
|
|
303
|
+
local batch_type
|
|
304
|
+
batch_type=$(classify_batch_type "$PLAN_FILE" "$batch")
|
|
305
|
+
local variants
|
|
306
|
+
variants=$(get_prompt_variants "$batch_type" "$WORKTREE/logs/sampling-outcomes.json" "$SAMPLE_COUNT")
|
|
307
|
+
|
|
308
|
+
local c=0
|
|
309
|
+
while IFS= read -r variant_name; do
|
|
310
|
+
local variant_suffix=""
|
|
311
|
+
if [[ "$variant_name" != "vanilla" ]]; then
|
|
312
|
+
variant_suffix=$'\nIMPORTANT: '"$variant_name"
|
|
313
|
+
fi
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Also update the closing of the for loop — change `done` (after line 140) to match the new `while` loop:
|
|
317
|
+
|
|
318
|
+
The existing `done` on the line after the stash/checkout block closes the for loop. It now closes the while loop instead. No line change needed since `done` closes both `for` and `while`.
|
|
319
|
+
|
|
320
|
+
**Step 2: Update variant name logging**
|
|
321
|
+
|
|
322
|
+
In the sampling outcome logging section (~line 156-158), replace the hardcoded variant name lookup:
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
local variant_name="vanilla"
|
|
326
|
+
[[ "$winner" -eq 1 ]] && variant_name="different-approach"
|
|
327
|
+
[[ "$winner" -eq 2 ]] && variant_name="minimal-change"
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
With:
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
# Get the winning variant name from the variants list
|
|
334
|
+
local variant_name
|
|
335
|
+
variant_name=$(echo "$variants" | sed -n "$((winner + 1))p")
|
|
336
|
+
variant_name="${variant_name:-vanilla}"
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
**Step 3: Run full test suite + shellcheck**
|
|
340
|
+
|
|
341
|
+
Run: `shellcheck -S warning scripts/lib/run-plan-headless.sh && bash scripts/tests/run-all-tests.sh`
|
|
342
|
+
Expected: Clean shellcheck, ALL PASS
|
|
343
|
+
|
|
344
|
+
**Step 4: Commit**
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
git add scripts/lib/run-plan-headless.sh
|
|
348
|
+
git commit -m "feat: wire batch-type-aware prompt variants into sampling runner"
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
### Task 4: Add sampling config constants to routing
|
|
354
|
+
|
|
355
|
+
**Files:**
|
|
356
|
+
- Modify: `scripts/lib/run-plan-routing.sh` (add config block near top)
|
|
357
|
+
|
|
358
|
+
**Step 1: Add sampling configuration**
|
|
359
|
+
|
|
360
|
+
After the existing parallelism config block (~line 18), add:
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
# --- Sampling configuration ---
|
|
364
|
+
SAMPLE_ON_RETRY=true # auto-sample when batch fails first attempt
|
|
365
|
+
SAMPLE_ON_CRITICAL=true # auto-sample for critical: true batches
|
|
366
|
+
# shellcheck disable=SC2034 # consumed by run-plan-headless.sh
|
|
367
|
+
SAMPLE_DEFAULT_COUNT=3 # default candidate count
|
|
368
|
+
SAMPLE_MAX_COUNT=5 # hard cap
|
|
369
|
+
SAMPLE_MIN_MEMORY_PER_GB=4 # per-candidate memory requirement
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
**Step 2: Shellcheck**
|
|
373
|
+
|
|
374
|
+
Run: `shellcheck -S warning scripts/lib/run-plan-routing.sh`
|
|
375
|
+
Expected: Clean
|
|
376
|
+
|
|
377
|
+
**Step 3: Commit**
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
git add scripts/lib/run-plan-routing.sh
|
|
381
|
+
git commit -m "feat: add sampling configuration constants to routing module"
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
386
|
+
## Batch 2: AGENTS.md Auto-Generation + ast-grep Patterns
|
|
387
|
+
|
|
388
|
+
### Task 5: Write test for AGENTS.md generation
|
|
389
|
+
|
|
390
|
+
**Files:**
|
|
391
|
+
- Create: `scripts/tests/test-agents-md.sh`
|
|
392
|
+
|
|
393
|
+
**Step 1: Write the test**
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
#!/usr/bin/env bash
|
|
397
|
+
set -euo pipefail
|
|
398
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
399
|
+
source "$SCRIPT_DIR/../lib/run-plan-prompt.sh"
|
|
400
|
+
source "$SCRIPT_DIR/../lib/run-plan-parser.sh"
|
|
401
|
+
source "$SCRIPT_DIR/../lib/run-plan-routing.sh"
|
|
402
|
+
source "$SCRIPT_DIR/helpers.sh"
|
|
403
|
+
|
|
404
|
+
WORK=$(mktemp -d)
|
|
405
|
+
trap 'rm -rf "$WORK"' EXIT
|
|
406
|
+
|
|
407
|
+
# Create a test plan
|
|
408
|
+
cat > "$WORK/plan.md" << 'PLAN'
|
|
409
|
+
## Batch 1: Setup
|
|
410
|
+
**Files:**
|
|
411
|
+
- Create: src/lib.py
|
|
412
|
+
- Test: tests/test_lib.py
|
|
413
|
+
|
|
414
|
+
**Step 1:** Create files
|
|
415
|
+
|
|
416
|
+
## Batch 2: Core Logic
|
|
417
|
+
**Files:**
|
|
418
|
+
- Create: src/core.py
|
|
419
|
+
- Modify: src/lib.py
|
|
420
|
+
|
|
421
|
+
**Step 1:** Add core
|
|
422
|
+
PLAN
|
|
423
|
+
|
|
424
|
+
# Generate AGENTS.md
|
|
425
|
+
generate_agents_md "$WORK/plan.md" "$WORK" "headless"
|
|
426
|
+
|
|
427
|
+
assert_exit "AGENTS.md created" 0 test -f "$WORK/AGENTS.md"
|
|
428
|
+
|
|
429
|
+
output=$(cat "$WORK/AGENTS.md")
|
|
430
|
+
assert_contains "has batch count" "2 batches" "$output"
|
|
431
|
+
assert_contains "has mode" "headless" "$output"
|
|
432
|
+
assert_contains "has tools" "Bash" "$output"
|
|
433
|
+
|
|
434
|
+
echo ""
|
|
435
|
+
echo "Results: tests completed"
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
**Step 2: Run to verify failure**
|
|
439
|
+
|
|
440
|
+
Run: `bash scripts/tests/test-agents-md.sh`
|
|
441
|
+
Expected: FAIL — `generate_agents_md` not defined
|
|
442
|
+
|
|
443
|
+
**Step 3: Commit**
|
|
444
|
+
|
|
445
|
+
```bash
|
|
446
|
+
git add scripts/tests/test-agents-md.sh
|
|
447
|
+
git commit -m "test: add AGENTS.md generation tests"
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
### Task 6: Implement generate_agents_md
|
|
453
|
+
|
|
454
|
+
**Files:**
|
|
455
|
+
- Modify: `scripts/lib/run-plan-prompt.sh`
|
|
456
|
+
|
|
457
|
+
**Step 1: Add generate_agents_md function**
|
|
458
|
+
|
|
459
|
+
Append to `scripts/lib/run-plan-prompt.sh`:
|
|
460
|
+
|
|
461
|
+
```bash
|
|
462
|
+
# Generate AGENTS.md in the worktree for agent team awareness.
|
|
463
|
+
# Args: <plan_file> <worktree> <mode>
|
|
464
|
+
generate_agents_md() {
|
|
465
|
+
local plan_file="$1" worktree="$2" mode="${3:-headless}"
|
|
466
|
+
|
|
467
|
+
# Source parser if needed
|
|
468
|
+
type count_batches &>/dev/null || source "$(dirname "${BASH_SOURCE[0]}")/run-plan-parser.sh"
|
|
469
|
+
|
|
470
|
+
local total_batches
|
|
471
|
+
total_batches=$(count_batches "$plan_file")
|
|
472
|
+
|
|
473
|
+
local batch_info=""
|
|
474
|
+
for ((b = 1; b <= total_batches; b++)); do
|
|
475
|
+
local title
|
|
476
|
+
title=$(get_batch_title "$plan_file" "$b")
|
|
477
|
+
[[ -z "$title" ]] && continue
|
|
478
|
+
batch_info+="| $b | $title |"$'\n'
|
|
479
|
+
done
|
|
480
|
+
|
|
481
|
+
cat > "$worktree/AGENTS.md" << EOF
|
|
482
|
+
# Agent Configuration
|
|
483
|
+
|
|
484
|
+
**Plan:** $(basename "$plan_file")
|
|
485
|
+
**Mode:** $mode
|
|
486
|
+
**Total:** $total_batches batches
|
|
487
|
+
|
|
488
|
+
## Tools Allowed
|
|
489
|
+
|
|
490
|
+
Bash, Read, Write, Edit, Grep, Glob
|
|
491
|
+
|
|
492
|
+
## Permission Mode
|
|
493
|
+
|
|
494
|
+
bypassPermissions
|
|
495
|
+
|
|
496
|
+
## Batches
|
|
497
|
+
|
|
498
|
+
| # | Title |
|
|
499
|
+
|---|-------|
|
|
500
|
+
${batch_info}
|
|
501
|
+
## Guidelines
|
|
502
|
+
|
|
503
|
+
- Run quality gate after each batch
|
|
504
|
+
- Commit after passing gate
|
|
505
|
+
- Append discoveries to progress.txt
|
|
506
|
+
- Do not modify files outside your batch scope
|
|
507
|
+
EOF
|
|
508
|
+
}
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
**Step 2: Run tests**
|
|
512
|
+
|
|
513
|
+
Run: `bash scripts/tests/test-agents-md.sh`
|
|
514
|
+
Expected: ALL PASS
|
|
515
|
+
|
|
516
|
+
**Step 3: Run full suite**
|
|
517
|
+
|
|
518
|
+
Run: `bash scripts/tests/run-all-tests.sh`
|
|
519
|
+
Expected: 26+ test files, ALL PASS
|
|
520
|
+
|
|
521
|
+
**Step 4: Commit**
|
|
522
|
+
|
|
523
|
+
```bash
|
|
524
|
+
git add scripts/lib/run-plan-prompt.sh
|
|
525
|
+
git commit -m "feat: add AGENTS.md auto-generation for worktree agent awareness"
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
---
|
|
529
|
+
|
|
530
|
+
### Task 7: Wire AGENTS.md into headless runner
|
|
531
|
+
|
|
532
|
+
**Files:**
|
|
533
|
+
- Modify: `scripts/lib/run-plan-headless.sh`
|
|
534
|
+
|
|
535
|
+
**Step 1: Add AGENTS.md generation at run start**
|
|
536
|
+
|
|
537
|
+
In `run_mode_headless()`, after the state initialization block (around line 30), add:
|
|
538
|
+
|
|
539
|
+
```bash
|
|
540
|
+
# Generate AGENTS.md for agent awareness
|
|
541
|
+
generate_agents_md "$PLAN_FILE" "$WORKTREE" "$MODE"
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
**Step 2: Run full suite + shellcheck**
|
|
545
|
+
|
|
546
|
+
Run: `shellcheck -S warning scripts/lib/run-plan-headless.sh && bash scripts/tests/run-all-tests.sh`
|
|
547
|
+
Expected: Clean
|
|
548
|
+
|
|
549
|
+
**Step 3: Commit**
|
|
550
|
+
|
|
551
|
+
```bash
|
|
552
|
+
git add scripts/lib/run-plan-headless.sh
|
|
553
|
+
git commit -m "feat: wire AGENTS.md generation into headless runner startup"
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
---
|
|
557
|
+
|
|
558
|
+
### Task 8: Add 2 missing ast-grep patterns
|
|
559
|
+
|
|
560
|
+
**Files:**
|
|
561
|
+
- Create: `scripts/patterns/retry-loop.yml`
|
|
562
|
+
- Create: `scripts/patterns/unused-import.yml`
|
|
563
|
+
|
|
564
|
+
**Step 1: Create retry-loop.yml**
|
|
565
|
+
|
|
566
|
+
```yaml
|
|
567
|
+
id: retry-loop-no-backoff
|
|
568
|
+
language: python
|
|
569
|
+
rule:
|
|
570
|
+
pattern: |
|
|
571
|
+
for $_ in range($RETRIES):
|
|
572
|
+
try:
|
|
573
|
+
$$$BODY
|
|
574
|
+
except $EXC:
|
|
575
|
+
$$$HANDLER
|
|
576
|
+
message: "Retry loop without backoff — add exponential backoff or sleep between retries"
|
|
577
|
+
severity: warning
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
**Step 2: Create unused-import.yml**
|
|
581
|
+
|
|
582
|
+
```yaml
|
|
583
|
+
id: unused-import
|
|
584
|
+
language: python
|
|
585
|
+
rule:
|
|
586
|
+
pattern: import $MODULE
|
|
587
|
+
message: "Verify this import is used — unused imports increase load time and confuse readers"
|
|
588
|
+
severity: hint
|
|
589
|
+
note: "Advisory only — ast-grep cannot track usage across the file. Review manually."
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
**Step 3: Verify pattern count**
|
|
593
|
+
|
|
594
|
+
Run: `ls scripts/patterns/*.yml | wc -l`
|
|
595
|
+
Expected: 5
|
|
596
|
+
|
|
597
|
+
**Step 4: Commit**
|
|
598
|
+
|
|
599
|
+
```bash
|
|
600
|
+
git add scripts/patterns/retry-loop.yml scripts/patterns/unused-import.yml
|
|
601
|
+
git commit -m "feat: add retry-loop and unused-import ast-grep patterns (5 total)"
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
---
|
|
605
|
+
|
|
606
|
+
## Batch 3: Integration Wiring + Verification
|
|
607
|
+
|
|
608
|
+
### Task 9: Wire sampling auto-trigger on retry and critical batches
|
|
609
|
+
|
|
610
|
+
**Files:**
|
|
611
|
+
- Modify: `scripts/lib/run-plan-headless.sh`
|
|
612
|
+
|
|
613
|
+
**Step 1: Add auto-sampling logic**
|
|
614
|
+
|
|
615
|
+
In the retry loop section of `run_mode_headless()`, before the existing `if [[ "${SAMPLE_COUNT:-0}" -gt 0 && $attempt -ge 2 ]]` check (~line 88), add:
|
|
616
|
+
|
|
617
|
+
```bash
|
|
618
|
+
# Auto-sample on retry if configured
|
|
619
|
+
if [[ "${SAMPLE_ON_RETRY:-true}" == "true" && "$SAMPLE_COUNT" -eq 0 && $attempt -ge 2 ]]; then
|
|
620
|
+
SAMPLE_COUNT="${SAMPLE_DEFAULT_COUNT:-3}"
|
|
621
|
+
echo " Auto-enabling sampling ($SAMPLE_COUNT candidates) for retry"
|
|
622
|
+
fi
|
|
623
|
+
|
|
624
|
+
# Auto-sample on critical batches
|
|
625
|
+
if [[ "${SAMPLE_ON_CRITICAL:-true}" == "true" && "$SAMPLE_COUNT" -eq 0 && $attempt -eq 1 ]]; then
|
|
626
|
+
if is_critical_batch "$PLAN_FILE" "$batch"; then
|
|
627
|
+
SAMPLE_COUNT="${SAMPLE_DEFAULT_COUNT:-3}"
|
|
628
|
+
echo " Auto-enabling sampling ($SAMPLE_COUNT candidates) for critical batch"
|
|
629
|
+
fi
|
|
630
|
+
fi
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
**Step 2: Add memory guard before sampling**
|
|
634
|
+
|
|
635
|
+
Right after the auto-trigger block, before entering the sampling path:
|
|
636
|
+
|
|
637
|
+
```bash
|
|
638
|
+
# Memory guard for sampling
|
|
639
|
+
if [[ "${SAMPLE_COUNT:-0}" -gt 0 ]]; then
|
|
640
|
+
local avail_gb
|
|
641
|
+
avail_gb=$(free -g 2>/dev/null | awk '/Mem:/{print $7}' || echo "0")
|
|
642
|
+
local needed=$((SAMPLE_COUNT * ${SAMPLE_MIN_MEMORY_PER_GB:-4}))
|
|
643
|
+
if [[ "$avail_gb" -lt "$needed" ]]; then
|
|
644
|
+
echo " WARNING: Not enough memory for sampling (${avail_gb}G < ${needed}G needed). Falling back to single attempt."
|
|
645
|
+
SAMPLE_COUNT=0
|
|
646
|
+
fi
|
|
647
|
+
fi
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
**Step 3: Shellcheck + full tests**
|
|
651
|
+
|
|
652
|
+
Run: `shellcheck -S warning scripts/lib/run-plan-headless.sh && bash scripts/tests/run-all-tests.sh`
|
|
653
|
+
Expected: Clean
|
|
654
|
+
|
|
655
|
+
**Step 4: Commit**
|
|
656
|
+
|
|
657
|
+
```bash
|
|
658
|
+
git add scripts/lib/run-plan-headless.sh
|
|
659
|
+
git commit -m "feat: auto-trigger sampling on retry and critical batches with memory guard"
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
---
|
|
663
|
+
|
|
664
|
+
### Task 10: Update CLAUDE.md and run final verification
|
|
665
|
+
|
|
666
|
+
**Files:**
|
|
667
|
+
- Modify: `CLAUDE.md` (update capability list)
|
|
668
|
+
|
|
669
|
+
**Step 1: Update CLAUDE.md**
|
|
670
|
+
|
|
671
|
+
In the Quality Gates section, add sampling info. In the State & Persistence section, confirm `logs/sampling-outcomes.json` is listed.
|
|
672
|
+
|
|
673
|
+
**Step 2: Run full verification**
|
|
674
|
+
|
|
675
|
+
Run all checks:
|
|
676
|
+
|
|
677
|
+
```bash
|
|
678
|
+
shellcheck -S warning scripts/*.sh scripts/lib/*.sh scripts/tests/test-*.sh
|
|
679
|
+
bash scripts/tests/run-all-tests.sh
|
|
680
|
+
bash scripts/quality-gate.sh --project-root .
|
|
681
|
+
bash scripts/pipeline-status.sh .
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
Expected: All clean, all pass.
|
|
685
|
+
|
|
686
|
+
**Step 3: Final commit**
|
|
687
|
+
|
|
688
|
+
```bash
|
|
689
|
+
git add CLAUDE.md
|
|
690
|
+
git commit -m "docs: update CLAUDE.md with Phase 4 completion — sampling, AGENTS.md, patterns"
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
**Step 4: Push**
|
|
694
|
+
|
|
695
|
+
```bash
|
|
696
|
+
git push
|
|
697
|
+
```
|