@bonesofspring/ai-rules 0.2.41 → 0.2.43
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/CHANGELOG.md +60 -0
- package/bin/lib/seed-ai-local-team.js +41 -4
- package/docs/LOCAL-OVERLAY.md +3 -1
- package/docs/specs/INDEX.md +3 -1
- package/docs/specs/_templates/feature.md +6 -0
- package/package.json +1 -1
- package/presets/_shared/ai-local/scripts/derive-gate-signals.mjs +7 -0
- package/presets/_shared/assets/docs-specs/_templates/feature.md +6 -0
- package/presets/_shared/core/agent-team/agent-artifact-contracts.md +1 -0
- package/presets/_shared/core/agent-team/agent-team-orchestrator.md +21 -5
- package/presets/_shared/core/agent-team/plan-graph.md +9 -1
- package/presets/_shared/core/quality/anti-hallucination-contract.md +2 -0
- package/presets/_shared/core/quality/context-and-iteration.md +2 -1
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +1140 -7
- package/presets/claude/android-kotlin/agents/ci-investigator.md +1 -1
- package/presets/claude/android-kotlin/agents/debugger.md +1 -1
- package/presets/claude/android-kotlin/agents/feature-developer.md +1 -1
- package/presets/claude/android-kotlin/agents/migration-specialist.md +1 -1
- package/presets/claude/android-kotlin/agents/performance-auditor.md +1 -1
- package/presets/claude/android-kotlin/agents/qa-tester.md +1 -1
- package/presets/claude/android-kotlin/agents/task-analyst.md +1 -1
- package/presets/claude/android-kotlin/agents/task-router.md +1 -1
- package/presets/claude/android-kotlin/agents/tech-writer.md +1 -1
- package/presets/claude/android-kotlin/agents/unit-test-generator.md +1 -1
- package/presets/claude/android-kotlin/agents/unit-test-healer.md +1 -1
- package/presets/claude/android-kotlin/agents/unit-test-planner.md +1 -1
- package/presets/claude/android-kotlin/commands/task-continue.md +1 -1
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +1140 -7
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +21 -5
- package/presets/claude/android-kotlin/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
- package/presets/claude/android-kotlin/team/README.md +1 -1
- package/presets/claude/go/agents/feature-developer.md +1 -1
- package/presets/claude/go/agents/task-analyst.md +1 -1
- package/presets/claude/go/agents/task-router.md +1 -1
- package/presets/claude/go/commands/task-continue.md +1 -1
- package/presets/claude/go/hooks/chain-team-phases.sh +1140 -7
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +21 -5
- package/presets/claude/go/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
- package/presets/claude/go/team/README.md +1 -1
- package/presets/claude/ios-swift/agents/feature-developer.md +1 -1
- package/presets/claude/ios-swift/agents/task-analyst.md +1 -1
- package/presets/claude/ios-swift/agents/task-router.md +1 -1
- package/presets/claude/ios-swift/commands/task-continue.md +1 -1
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +1140 -7
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +21 -5
- package/presets/claude/ios-swift/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
- package/presets/claude/ios-swift/team/README.md +1 -1
- package/presets/claude/java/agents/feature-developer.md +1 -1
- package/presets/claude/java/agents/task-analyst.md +1 -1
- package/presets/claude/java/agents/task-router.md +1 -1
- package/presets/claude/java/commands/task-continue.md +1 -1
- package/presets/claude/java/hooks/chain-team-phases.sh +1140 -7
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +21 -5
- package/presets/claude/java/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
- package/presets/claude/java/team/README.md +1 -1
- package/presets/claude/mcp-ts/agents/feature-developer.md +1 -1
- package/presets/claude/mcp-ts/agents/task-analyst.md +1 -1
- package/presets/claude/mcp-ts/agents/task-router.md +1 -1
- package/presets/claude/mcp-ts/commands/task-continue.md +1 -1
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +1140 -7
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +21 -5
- package/presets/claude/mcp-ts/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
- package/presets/claude/mcp-ts/team/README.md +1 -1
- package/presets/claude/next/REPO_AGENTS.md +1 -1
- package/presets/claude/next/agents/ci-investigator.md +1 -1
- package/presets/claude/next/agents/debugger.md +1 -1
- package/presets/claude/next/agents/feature-developer.md +1 -1
- package/presets/claude/next/agents/migration-specialist.md +1 -1
- package/presets/claude/next/agents/openspec-author.md +26 -2
- package/presets/claude/next/agents/performance-auditor.md +1 -1
- package/presets/claude/next/agents/qa-tester.md +1 -1
- package/presets/claude/next/agents/solution-architect.md +1 -1
- package/presets/claude/next/agents/task-analyst.md +16 -7
- package/presets/claude/next/agents/task-router.md +21 -3
- package/presets/claude/next/agents/tech-writer.md +1 -1
- package/presets/claude/next/agents/unit-test-generator.md +1 -1
- package/presets/claude/next/agents/unit-test-healer.md +1 -1
- package/presets/claude/next/agents/unit-test-planner.md +1 -1
- package/presets/{cursor/next/ai-local/rules-library → claude/next/ai-local/rules}/task-levels.md +2 -0
- package/presets/claude/next/commands/task-continue.md +1 -1
- package/presets/claude/next/hooks/chain-team-phases.sh +1140 -7
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +21 -5
- package/presets/claude/next/rules/tooling-and-review/ai-local-overlay.md +1 -1
- package/presets/claude/next/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
- package/presets/claude/next/team/README.md +1 -1
- package/presets/claude/nuxt/agents/README.md +1 -1
- package/presets/claude/nuxt/agents/ci-investigator.md +1 -1
- package/presets/claude/nuxt/agents/debugger.md +1 -1
- package/presets/claude/nuxt/agents/feature-developer.md +1 -1
- package/presets/claude/nuxt/agents/migration-specialist.md +1 -1
- package/presets/claude/nuxt/agents/performance-auditor.md +1 -1
- package/presets/claude/nuxt/agents/qa-tester.md +1 -1
- package/presets/claude/nuxt/agents/solution-architect.md +1 -1
- package/presets/claude/nuxt/agents/task-analyst.md +1 -1
- package/presets/claude/nuxt/agents/task-router.md +1 -1
- package/presets/claude/nuxt/agents/tech-writer.md +1 -1
- package/presets/claude/nuxt/agents/unit-test-generator.md +1 -1
- package/presets/claude/nuxt/agents/unit-test-healer.md +1 -1
- package/presets/claude/nuxt/agents/unit-test-planner.md +1 -1
- package/presets/claude/nuxt/commands/task-continue.md +1 -1
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +1140 -7
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +21 -5
- package/presets/claude/nuxt/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
- package/presets/claude/nuxt/team/README.md +1 -1
- package/presets/claude/php-hexagonal/agents/feature-developer.md +1 -1
- package/presets/claude/php-hexagonal/agents/task-analyst.md +1 -1
- package/presets/claude/php-hexagonal/agents/task-router.md +1 -1
- package/presets/claude/php-hexagonal/commands/task-continue.md +1 -1
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +1140 -7
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +21 -5
- package/presets/claude/php-hexagonal/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
- package/presets/claude/php-hexagonal/team/README.md +1 -1
- package/presets/claude/php-laravel/agents/feature-developer.md +1 -1
- package/presets/claude/php-laravel/agents/task-analyst.md +1 -1
- package/presets/claude/php-laravel/agents/task-router.md +1 -1
- package/presets/claude/php-laravel/commands/task-continue.md +1 -1
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +1140 -7
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +21 -5
- package/presets/claude/php-laravel/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
- package/presets/claude/php-laravel/team/README.md +1 -1
- package/presets/claude/svelte/agents/README.md +1 -1
- package/presets/claude/svelte/agents/ci-investigator.md +1 -1
- package/presets/claude/svelte/agents/debugger.md +1 -1
- package/presets/claude/svelte/agents/feature-developer.md +1 -1
- package/presets/claude/svelte/agents/migration-specialist.md +1 -1
- package/presets/claude/svelte/agents/performance-auditor.md +1 -1
- package/presets/claude/svelte/agents/qa-tester.md +1 -1
- package/presets/claude/svelte/agents/solution-architect.md +1 -1
- package/presets/claude/svelte/agents/task-analyst.md +1 -1
- package/presets/claude/svelte/agents/task-router.md +1 -1
- package/presets/claude/svelte/agents/tech-writer.md +1 -1
- package/presets/claude/svelte/agents/unit-test-generator.md +1 -1
- package/presets/claude/svelte/agents/unit-test-healer.md +1 -1
- package/presets/claude/svelte/agents/unit-test-planner.md +1 -1
- package/presets/claude/svelte/commands/task-continue.md +1 -1
- package/presets/claude/svelte/hooks/chain-team-phases.sh +1140 -7
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +21 -5
- package/presets/claude/svelte/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
- package/presets/claude/svelte/team/README.md +1 -1
- package/presets/cursor/android-kotlin/agents/ci-investigator.md +1 -1
- package/presets/cursor/android-kotlin/agents/debugger.md +1 -1
- package/presets/cursor/android-kotlin/agents/feature-developer.md +1 -1
- package/presets/cursor/android-kotlin/agents/migration-specialist.md +1 -1
- package/presets/cursor/android-kotlin/agents/performance-auditor.md +1 -1
- package/presets/cursor/android-kotlin/agents/qa-tester.md +1 -1
- package/presets/cursor/android-kotlin/agents/task-analyst.md +1 -1
- package/presets/cursor/android-kotlin/agents/task-router.md +1 -1
- package/presets/cursor/android-kotlin/agents/tech-writer.md +1 -1
- package/presets/cursor/android-kotlin/agents/unit-test-generator.md +1 -1
- package/presets/cursor/android-kotlin/agents/unit-test-healer.md +1 -1
- package/presets/cursor/android-kotlin/agents/unit-test-planner.md +1 -1
- package/presets/cursor/android-kotlin/commands/task-continue.md +1 -1
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +1140 -7
- package/presets/cursor/android-kotlin/rules/anti-hallucination-contract.mdc +2 -0
- package/presets/cursor/android-kotlin/team/README.md +1 -1
- package/presets/cursor/go/agents/feature-developer.md +1 -1
- package/presets/cursor/go/agents/task-analyst.md +1 -1
- package/presets/cursor/go/agents/task-router.md +1 -1
- package/presets/cursor/go/commands/task-continue.md +1 -1
- package/presets/cursor/go/hooks/chain-team-phases.sh +1140 -7
- package/presets/cursor/go/rules/anti-hallucination-contract.mdc +2 -0
- package/presets/cursor/go/team/README.md +1 -1
- package/presets/cursor/ios-swift/agents/feature-developer.md +1 -1
- package/presets/cursor/ios-swift/agents/task-analyst.md +1 -1
- package/presets/cursor/ios-swift/agents/task-router.md +1 -1
- package/presets/cursor/ios-swift/commands/task-continue.md +1 -1
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +1140 -7
- package/presets/cursor/ios-swift/rules/anti-hallucination-contract.mdc +2 -0
- package/presets/cursor/ios-swift/team/README.md +1 -1
- package/presets/cursor/java/agents/feature-developer.md +1 -1
- package/presets/cursor/java/agents/task-analyst.md +1 -1
- package/presets/cursor/java/agents/task-router.md +1 -1
- package/presets/cursor/java/commands/task-continue.md +1 -1
- package/presets/cursor/java/hooks/chain-team-phases.sh +1140 -7
- package/presets/cursor/java/rules/anti-hallucination-contract.mdc +2 -0
- package/presets/cursor/java/team/README.md +1 -1
- package/presets/cursor/mcp-ts/agents/feature-developer.md +1 -1
- package/presets/cursor/mcp-ts/agents/task-analyst.md +1 -1
- package/presets/cursor/mcp-ts/agents/task-router.md +1 -1
- package/presets/cursor/mcp-ts/commands/task-continue.md +1 -1
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +1140 -7
- package/presets/cursor/mcp-ts/rules/anti-hallucination-contract.mdc +2 -0
- package/presets/cursor/mcp-ts/team/README.md +1 -1
- package/presets/cursor/next/REPO_AGENTS.md +1 -1
- package/presets/cursor/next/agents/README.md +1 -1
- package/presets/cursor/next/agents/build-verifier.md +2 -0
- package/presets/cursor/next/agents/ci-investigator.md +1 -1
- package/presets/cursor/next/agents/debugger.md +1 -1
- package/presets/cursor/next/agents/feature-developer.md +10 -1
- package/presets/cursor/next/agents/migration-specialist.md +1 -1
- package/presets/cursor/next/agents/openspec-author.md +26 -2
- package/presets/cursor/next/agents/performance-auditor.md +1 -1
- package/presets/cursor/next/agents/qa-tester.md +1 -1
- package/presets/cursor/next/agents/solution-architect.md +1 -1
- package/presets/cursor/next/agents/task-analyst.md +21 -7
- package/presets/cursor/next/agents/task-router.md +32 -3
- package/presets/cursor/next/agents/tech-writer.md +1 -1
- package/presets/cursor/next/agents/unit-test-generator.md +1 -1
- package/presets/cursor/next/agents/unit-test-healer.md +1 -1
- package/presets/cursor/next/agents/unit-test-planner.md +1 -1
- package/presets/cursor/next/ai-local/conventions.md +20 -0
- package/presets/{mavis/next/ai-local/rules-library → cursor/next/ai-local/rules}/task-levels.md +12 -0
- package/presets/cursor/next/commands/task-continue.md +1 -1
- package/presets/cursor/next/hooks/chain-team-phases.sh +1140 -7
- package/presets/cursor/next/rules/agent-team-orchestrator.mdc +18 -2
- package/presets/cursor/next/rules/ai-local-overlay.mdc +1 -1
- package/presets/cursor/next/rules/anti-hallucination-contract.mdc +2 -0
- package/presets/cursor/next/team/README.md +1 -1
- package/presets/cursor/nuxt/agents/README.md +1 -1
- package/presets/cursor/nuxt/agents/ci-investigator.md +1 -1
- package/presets/cursor/nuxt/agents/debugger.md +1 -1
- package/presets/cursor/nuxt/agents/feature-developer.md +1 -1
- package/presets/cursor/nuxt/agents/migration-specialist.md +1 -1
- package/presets/cursor/nuxt/agents/performance-auditor.md +1 -1
- package/presets/cursor/nuxt/agents/qa-tester.md +1 -1
- package/presets/cursor/nuxt/agents/solution-architect.md +1 -1
- package/presets/cursor/nuxt/agents/task-analyst.md +1 -1
- package/presets/cursor/nuxt/agents/task-router.md +1 -1
- package/presets/cursor/nuxt/agents/tech-writer.md +1 -1
- package/presets/cursor/nuxt/agents/unit-test-generator.md +1 -1
- package/presets/cursor/nuxt/agents/unit-test-healer.md +1 -1
- package/presets/cursor/nuxt/agents/unit-test-planner.md +1 -1
- package/presets/cursor/nuxt/commands/task-continue.md +1 -1
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +1140 -7
- package/presets/cursor/nuxt/rules/anti-hallucination-contract.mdc +2 -0
- package/presets/cursor/nuxt/team/README.md +1 -1
- package/presets/cursor/php-hexagonal/agents/feature-developer.md +1 -1
- package/presets/cursor/php-hexagonal/agents/task-analyst.md +1 -1
- package/presets/cursor/php-hexagonal/agents/task-router.md +1 -1
- package/presets/cursor/php-hexagonal/commands/task-continue.md +1 -1
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +1140 -7
- package/presets/cursor/php-hexagonal/rules/anti-hallucination-contract.mdc +2 -0
- package/presets/cursor/php-hexagonal/team/README.md +1 -1
- package/presets/cursor/php-laravel/agents/feature-developer.md +1 -1
- package/presets/cursor/php-laravel/agents/task-analyst.md +1 -1
- package/presets/cursor/php-laravel/agents/task-router.md +1 -1
- package/presets/cursor/php-laravel/commands/task-continue.md +1 -1
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +1140 -7
- package/presets/cursor/php-laravel/rules/anti-hallucination-contract.mdc +2 -0
- package/presets/cursor/php-laravel/team/README.md +1 -1
- package/presets/cursor/svelte/agents/README.md +1 -1
- package/presets/cursor/svelte/agents/ci-investigator.md +1 -1
- package/presets/cursor/svelte/agents/debugger.md +1 -1
- package/presets/cursor/svelte/agents/feature-developer.md +1 -1
- package/presets/cursor/svelte/agents/migration-specialist.md +1 -1
- package/presets/cursor/svelte/agents/performance-auditor.md +1 -1
- package/presets/cursor/svelte/agents/qa-tester.md +1 -1
- package/presets/cursor/svelte/agents/solution-architect.md +1 -1
- package/presets/cursor/svelte/agents/task-analyst.md +1 -1
- package/presets/cursor/svelte/agents/task-router.md +1 -1
- package/presets/cursor/svelte/agents/tech-writer.md +1 -1
- package/presets/cursor/svelte/agents/unit-test-generator.md +1 -1
- package/presets/cursor/svelte/agents/unit-test-healer.md +1 -1
- package/presets/cursor/svelte/agents/unit-test-planner.md +1 -1
- package/presets/cursor/svelte/commands/task-continue.md +1 -1
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +1140 -7
- package/presets/cursor/svelte/rules/anti-hallucination-contract.mdc +2 -0
- package/presets/cursor/svelte/team/README.md +1 -1
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/agents/ci-investigator.md +1 -1
- package/presets/mavis/android-kotlin/agents/debugger.md +1 -1
- package/presets/mavis/android-kotlin/agents/feature-developer.md +1 -1
- package/presets/mavis/android-kotlin/agents/migration-specialist.md +1 -1
- package/presets/mavis/android-kotlin/agents/performance-auditor.md +1 -1
- package/presets/mavis/android-kotlin/agents/qa-tester.md +1 -1
- package/presets/mavis/android-kotlin/agents/task-analyst.md +1 -1
- package/presets/mavis/android-kotlin/agents/task-router.md +1 -1
- package/presets/mavis/android-kotlin/agents/tech-writer.md +1 -1
- package/presets/mavis/android-kotlin/agents/unit-test-generator.md +1 -1
- package/presets/mavis/android-kotlin/agents/unit-test-healer.md +1 -1
- package/presets/mavis/android-kotlin/agents/unit-test-planner.md +1 -1
- package/presets/mavis/android-kotlin/commands/task-continue.md +1 -1
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +1140 -7
- package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +21 -5
- package/presets/mavis/android-kotlin/rules/anti-hallucination-contract.md +2 -0
- package/presets/mavis/android-kotlin/team/README.md +1 -1
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/agents/feature-developer.md +1 -1
- package/presets/mavis/go/agents/task-analyst.md +1 -1
- package/presets/mavis/go/agents/task-router.md +1 -1
- package/presets/mavis/go/commands/task-continue.md +1 -1
- package/presets/mavis/go/hooks/chain-team-phases.sh +1140 -7
- package/presets/mavis/go/rules/agent-team-orchestrator.md +21 -5
- package/presets/mavis/go/rules/anti-hallucination-contract.md +2 -0
- package/presets/mavis/go/team/README.md +1 -1
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/agents/feature-developer.md +1 -1
- package/presets/mavis/ios-swift/agents/task-analyst.md +1 -1
- package/presets/mavis/ios-swift/agents/task-router.md +1 -1
- package/presets/mavis/ios-swift/commands/task-continue.md +1 -1
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +1140 -7
- package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +21 -5
- package/presets/mavis/ios-swift/rules/anti-hallucination-contract.md +2 -0
- package/presets/mavis/ios-swift/team/README.md +1 -1
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/agents/feature-developer.md +1 -1
- package/presets/mavis/java/agents/task-analyst.md +1 -1
- package/presets/mavis/java/agents/task-router.md +1 -1
- package/presets/mavis/java/commands/task-continue.md +1 -1
- package/presets/mavis/java/hooks/chain-team-phases.sh +1140 -7
- package/presets/mavis/java/rules/agent-team-orchestrator.md +21 -5
- package/presets/mavis/java/rules/anti-hallucination-contract.md +2 -0
- package/presets/mavis/java/team/README.md +1 -1
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/agents/feature-developer.md +1 -1
- package/presets/mavis/mcp-ts/agents/task-analyst.md +1 -1
- package/presets/mavis/mcp-ts/agents/task-router.md +1 -1
- package/presets/mavis/mcp-ts/commands/task-continue.md +1 -1
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +1140 -7
- package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +21 -5
- package/presets/mavis/mcp-ts/rules/anti-hallucination-contract.md +2 -0
- package/presets/mavis/mcp-ts/team/README.md +1 -1
- package/presets/mavis/next/REPO_AGENTS.md +1 -1
- package/presets/mavis/next/adapter-map.json +5 -5
- package/presets/mavis/next/agents/build-verifier.md +2 -0
- package/presets/mavis/next/agents/ci-investigator.md +1 -1
- package/presets/mavis/next/agents/debugger.md +1 -1
- package/presets/mavis/next/agents/feature-developer.md +10 -1
- package/presets/mavis/next/agents/migration-specialist.md +1 -1
- package/presets/mavis/next/agents/openspec-author.md +26 -2
- package/presets/mavis/next/agents/performance-auditor.md +1 -1
- package/presets/mavis/next/agents/qa-tester.md +1 -1
- package/presets/mavis/next/agents/solution-architect.md +1 -1
- package/presets/mavis/next/agents/task-analyst.md +21 -7
- package/presets/mavis/next/agents/task-router.md +32 -3
- package/presets/mavis/next/agents/tech-writer.md +1 -1
- package/presets/mavis/next/agents/unit-test-generator.md +1 -1
- package/presets/mavis/next/agents/unit-test-healer.md +1 -1
- package/presets/mavis/next/agents/unit-test-planner.md +1 -1
- package/presets/mavis/next/ai-local/conventions.md +20 -0
- package/presets/{opencode/next/ai-local/rules-library → mavis/next/ai-local/rules}/task-levels.md +12 -0
- package/presets/mavis/next/commands/task-continue.md +1 -1
- package/presets/mavis/next/hooks/chain-team-phases.sh +1140 -7
- package/presets/mavis/next/rules/agent-team-orchestrator.md +21 -5
- package/presets/mavis/next/rules/ai-local-overlay.md +1 -1
- package/presets/mavis/next/rules/anti-hallucination-contract.md +2 -0
- package/presets/mavis/next/team/README.md +1 -1
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/agents/ci-investigator.md +1 -1
- package/presets/mavis/nuxt/agents/debugger.md +1 -1
- package/presets/mavis/nuxt/agents/feature-developer.md +1 -1
- package/presets/mavis/nuxt/agents/migration-specialist.md +1 -1
- package/presets/mavis/nuxt/agents/performance-auditor.md +1 -1
- package/presets/mavis/nuxt/agents/qa-tester.md +1 -1
- package/presets/mavis/nuxt/agents/solution-architect.md +1 -1
- package/presets/mavis/nuxt/agents/task-analyst.md +1 -1
- package/presets/mavis/nuxt/agents/task-router.md +1 -1
- package/presets/mavis/nuxt/agents/tech-writer.md +1 -1
- package/presets/mavis/nuxt/agents/unit-test-generator.md +1 -1
- package/presets/mavis/nuxt/agents/unit-test-healer.md +1 -1
- package/presets/mavis/nuxt/agents/unit-test-planner.md +1 -1
- package/presets/mavis/nuxt/commands/task-continue.md +1 -1
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +1140 -7
- package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +21 -5
- package/presets/mavis/nuxt/rules/anti-hallucination-contract.md +2 -0
- package/presets/mavis/nuxt/team/README.md +1 -1
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/agents/feature-developer.md +1 -1
- package/presets/mavis/php-hexagonal/agents/task-analyst.md +1 -1
- package/presets/mavis/php-hexagonal/agents/task-router.md +1 -1
- package/presets/mavis/php-hexagonal/commands/task-continue.md +1 -1
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +1140 -7
- package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +21 -5
- package/presets/mavis/php-hexagonal/rules/anti-hallucination-contract.md +2 -0
- package/presets/mavis/php-hexagonal/team/README.md +1 -1
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/agents/feature-developer.md +1 -1
- package/presets/mavis/php-laravel/agents/task-analyst.md +1 -1
- package/presets/mavis/php-laravel/agents/task-router.md +1 -1
- package/presets/mavis/php-laravel/commands/task-continue.md +1 -1
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +1140 -7
- package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +21 -5
- package/presets/mavis/php-laravel/rules/anti-hallucination-contract.md +2 -0
- package/presets/mavis/php-laravel/team/README.md +1 -1
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/agents/ci-investigator.md +1 -1
- package/presets/mavis/svelte/agents/debugger.md +1 -1
- package/presets/mavis/svelte/agents/feature-developer.md +1 -1
- package/presets/mavis/svelte/agents/migration-specialist.md +1 -1
- package/presets/mavis/svelte/agents/performance-auditor.md +1 -1
- package/presets/mavis/svelte/agents/qa-tester.md +1 -1
- package/presets/mavis/svelte/agents/solution-architect.md +1 -1
- package/presets/mavis/svelte/agents/task-analyst.md +1 -1
- package/presets/mavis/svelte/agents/task-router.md +1 -1
- package/presets/mavis/svelte/agents/tech-writer.md +1 -1
- package/presets/mavis/svelte/agents/unit-test-generator.md +1 -1
- package/presets/mavis/svelte/agents/unit-test-healer.md +1 -1
- package/presets/mavis/svelte/agents/unit-test-planner.md +1 -1
- package/presets/mavis/svelte/commands/task-continue.md +1 -1
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +1140 -7
- package/presets/mavis/svelte/rules/agent-team-orchestrator.md +21 -5
- package/presets/mavis/svelte/rules/anti-hallucination-contract.md +2 -0
- package/presets/mavis/svelte/team/README.md +1 -1
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/agents/ci-investigator.md +1 -1
- package/presets/opencode/android-kotlin/agents/debugger.md +1 -1
- package/presets/opencode/android-kotlin/agents/feature-developer.md +1 -1
- package/presets/opencode/android-kotlin/agents/migration-specialist.md +1 -1
- package/presets/opencode/android-kotlin/agents/performance-auditor.md +1 -1
- package/presets/opencode/android-kotlin/agents/qa-tester.md +1 -1
- package/presets/opencode/android-kotlin/agents/task-analyst.md +1 -1
- package/presets/opencode/android-kotlin/agents/task-router.md +1 -1
- package/presets/opencode/android-kotlin/agents/tech-writer.md +1 -1
- package/presets/opencode/android-kotlin/agents/unit-test-generator.md +1 -1
- package/presets/opencode/android-kotlin/agents/unit-test-healer.md +1 -1
- package/presets/opencode/android-kotlin/agents/unit-test-planner.md +1 -1
- package/presets/opencode/android-kotlin/commands/task-continue.md +1 -1
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +1140 -7
- package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +21 -5
- package/presets/opencode/android-kotlin/rules/anti-hallucination-contract.md +2 -0
- package/presets/opencode/android-kotlin/team/README.md +1 -1
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/agents/feature-developer.md +1 -1
- package/presets/opencode/go/agents/task-analyst.md +1 -1
- package/presets/opencode/go/agents/task-router.md +1 -1
- package/presets/opencode/go/commands/task-continue.md +1 -1
- package/presets/opencode/go/hooks/chain-team-phases.sh +1140 -7
- package/presets/opencode/go/rules/agent-team-orchestrator.md +21 -5
- package/presets/opencode/go/rules/anti-hallucination-contract.md +2 -0
- package/presets/opencode/go/team/README.md +1 -1
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/agents/feature-developer.md +1 -1
- package/presets/opencode/ios-swift/agents/task-analyst.md +1 -1
- package/presets/opencode/ios-swift/agents/task-router.md +1 -1
- package/presets/opencode/ios-swift/commands/task-continue.md +1 -1
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +1140 -7
- package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +21 -5
- package/presets/opencode/ios-swift/rules/anti-hallucination-contract.md +2 -0
- package/presets/opencode/ios-swift/team/README.md +1 -1
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/agents/feature-developer.md +1 -1
- package/presets/opencode/java/agents/task-analyst.md +1 -1
- package/presets/opencode/java/agents/task-router.md +1 -1
- package/presets/opencode/java/commands/task-continue.md +1 -1
- package/presets/opencode/java/hooks/chain-team-phases.sh +1140 -7
- package/presets/opencode/java/rules/agent-team-orchestrator.md +21 -5
- package/presets/opencode/java/rules/anti-hallucination-contract.md +2 -0
- package/presets/opencode/java/team/README.md +1 -1
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/agents/feature-developer.md +1 -1
- package/presets/opencode/mcp-ts/agents/task-analyst.md +1 -1
- package/presets/opencode/mcp-ts/agents/task-router.md +1 -1
- package/presets/opencode/mcp-ts/commands/task-continue.md +1 -1
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +1140 -7
- package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +21 -5
- package/presets/opencode/mcp-ts/rules/anti-hallucination-contract.md +2 -0
- package/presets/opencode/mcp-ts/team/README.md +1 -1
- package/presets/opencode/next/REPO_AGENTS.md +1 -1
- package/presets/opencode/next/adapter-map.json +5 -5
- package/presets/opencode/next/agents/build-verifier.md +2 -0
- package/presets/opencode/next/agents/ci-investigator.md +1 -1
- package/presets/opencode/next/agents/debugger.md +1 -1
- package/presets/opencode/next/agents/feature-developer.md +10 -1
- package/presets/opencode/next/agents/migration-specialist.md +1 -1
- package/presets/opencode/next/agents/openspec-author.md +26 -2
- package/presets/opencode/next/agents/performance-auditor.md +1 -1
- package/presets/opencode/next/agents/qa-tester.md +1 -1
- package/presets/opencode/next/agents/solution-architect.md +1 -1
- package/presets/opencode/next/agents/task-analyst.md +21 -7
- package/presets/opencode/next/agents/task-router.md +32 -3
- package/presets/opencode/next/agents/tech-writer.md +1 -1
- package/presets/opencode/next/agents/unit-test-generator.md +1 -1
- package/presets/opencode/next/agents/unit-test-healer.md +1 -1
- package/presets/opencode/next/agents/unit-test-planner.md +1 -1
- package/presets/opencode/next/ai-local/conventions.md +20 -0
- package/presets/opencode/next/ai-local/rules/task-levels.md +40 -0
- package/presets/opencode/next/commands/task-continue.md +1 -1
- package/presets/opencode/next/hooks/chain-team-phases.sh +1140 -7
- package/presets/opencode/next/rules/agent-team-orchestrator.md +21 -5
- package/presets/opencode/next/rules/ai-local-overlay.md +1 -1
- package/presets/opencode/next/rules/anti-hallucination-contract.md +2 -0
- package/presets/opencode/next/team/README.md +1 -1
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/agents/ci-investigator.md +1 -1
- package/presets/opencode/nuxt/agents/debugger.md +1 -1
- package/presets/opencode/nuxt/agents/feature-developer.md +1 -1
- package/presets/opencode/nuxt/agents/migration-specialist.md +1 -1
- package/presets/opencode/nuxt/agents/performance-auditor.md +1 -1
- package/presets/opencode/nuxt/agents/qa-tester.md +1 -1
- package/presets/opencode/nuxt/agents/solution-architect.md +1 -1
- package/presets/opencode/nuxt/agents/task-analyst.md +1 -1
- package/presets/opencode/nuxt/agents/task-router.md +1 -1
- package/presets/opencode/nuxt/agents/tech-writer.md +1 -1
- package/presets/opencode/nuxt/agents/unit-test-generator.md +1 -1
- package/presets/opencode/nuxt/agents/unit-test-healer.md +1 -1
- package/presets/opencode/nuxt/agents/unit-test-planner.md +1 -1
- package/presets/opencode/nuxt/commands/task-continue.md +1 -1
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +1140 -7
- package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +21 -5
- package/presets/opencode/nuxt/rules/anti-hallucination-contract.md +2 -0
- package/presets/opencode/nuxt/team/README.md +1 -1
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/agents/feature-developer.md +1 -1
- package/presets/opencode/php-hexagonal/agents/task-analyst.md +1 -1
- package/presets/opencode/php-hexagonal/agents/task-router.md +1 -1
- package/presets/opencode/php-hexagonal/commands/task-continue.md +1 -1
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +1140 -7
- package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +21 -5
- package/presets/opencode/php-hexagonal/rules/anti-hallucination-contract.md +2 -0
- package/presets/opencode/php-hexagonal/team/README.md +1 -1
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/agents/feature-developer.md +1 -1
- package/presets/opencode/php-laravel/agents/task-analyst.md +1 -1
- package/presets/opencode/php-laravel/agents/task-router.md +1 -1
- package/presets/opencode/php-laravel/commands/task-continue.md +1 -1
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +1140 -7
- package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +21 -5
- package/presets/opencode/php-laravel/rules/anti-hallucination-contract.md +2 -0
- package/presets/opencode/php-laravel/team/README.md +1 -1
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/agents/ci-investigator.md +1 -1
- package/presets/opencode/svelte/agents/debugger.md +1 -1
- package/presets/opencode/svelte/agents/feature-developer.md +1 -1
- package/presets/opencode/svelte/agents/migration-specialist.md +1 -1
- package/presets/opencode/svelte/agents/performance-auditor.md +1 -1
- package/presets/opencode/svelte/agents/qa-tester.md +1 -1
- package/presets/opencode/svelte/agents/solution-architect.md +1 -1
- package/presets/opencode/svelte/agents/task-analyst.md +1 -1
- package/presets/opencode/svelte/agents/task-router.md +1 -1
- package/presets/opencode/svelte/agents/tech-writer.md +1 -1
- package/presets/opencode/svelte/agents/unit-test-generator.md +1 -1
- package/presets/opencode/svelte/agents/unit-test-healer.md +1 -1
- package/presets/opencode/svelte/agents/unit-test-planner.md +1 -1
- package/presets/opencode/svelte/commands/task-continue.md +1 -1
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +1140 -7
- package/presets/opencode/svelte/rules/agent-team-orchestrator.md +21 -5
- package/presets/opencode/svelte/rules/anti-hallucination-contract.md +2 -0
- package/presets/opencode/svelte/team/README.md +1 -1
|
@@ -254,10 +254,429 @@ function writeSkeletonManifest(manifestPath) {
|
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
+
function normalizeRepoPath(value) {
|
|
258
|
+
let text = typeof value === 'string' ? value.trim() : '';
|
|
259
|
+
text = text.replace(/\\/g, '/');
|
|
260
|
+
while (text.startsWith('./')) text = text.slice(2);
|
|
261
|
+
if (!text || text === '—' || text === '-' || text === '–') return '';
|
|
262
|
+
if (/[\s()]/.test(text)) return '';
|
|
263
|
+
return text;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function isAppPath(file) {
|
|
267
|
+
const normalized = normalizeRepoPath(file);
|
|
268
|
+
return normalized === 'app' || normalized.startsWith('app/') || normalized.startsWith('app/**') || normalized.startsWith('app/*');
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function isSpecFolderPath(file) {
|
|
272
|
+
const normalized = normalizeRepoPath(file);
|
|
273
|
+
return normalized.startsWith('docs/specs/') || normalized.startsWith('docs/specs/**') || normalized.startsWith('openspec/') || normalized.startsWith('openspec/**');
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function listsBothSpecAndApp(files) {
|
|
277
|
+
let app = false;
|
|
278
|
+
let spec = false;
|
|
279
|
+
for (const file of files || []) {
|
|
280
|
+
if (isAppPath(file)) app = true;
|
|
281
|
+
if (isSpecFolderPath(file)) spec = true;
|
|
282
|
+
}
|
|
283
|
+
return app && spec;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function pathInWriteScopes(file, writeScopes) {
|
|
287
|
+
const target = normalizeRepoPath(file);
|
|
288
|
+
if (!target) return false;
|
|
289
|
+
const scopes = Array.isArray(writeScopes) ? writeScopes : [];
|
|
290
|
+
for (const scope of scopes) {
|
|
291
|
+
const normalized = normalizeRepoPath(scope);
|
|
292
|
+
if (!normalized) continue;
|
|
293
|
+
if (normalized === target) return true;
|
|
294
|
+
if (normalized.endsWith('/**')) {
|
|
295
|
+
const prefix = normalized.slice(0, -3);
|
|
296
|
+
if (target === prefix || target.startsWith(prefix + '/')) return true;
|
|
297
|
+
} else if (normalized.endsWith('/*')) {
|
|
298
|
+
const prefix = normalized.slice(0, -2);
|
|
299
|
+
const rest = target.startsWith(prefix + '/') ? target.slice(prefix.length + 1) : '';
|
|
300
|
+
if (rest && !rest.includes('/')) return true;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function taskFileSet(task) {
|
|
307
|
+
const all = []
|
|
308
|
+
.concat((task && task.files) || [], (task && task.specFiles) || [], (task && task.appFiles) || [])
|
|
309
|
+
.map((file) => normalizeRepoPath(file))
|
|
310
|
+
.filter(Boolean);
|
|
311
|
+
return new Set(all);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function taskReaches(tasks, startId, targetId) {
|
|
315
|
+
const byId = new Map(tasks.map((task) => [String(task.id), task]));
|
|
316
|
+
const seen = new Set();
|
|
317
|
+
const stack = [String(startId)];
|
|
318
|
+
while (stack.length > 0) {
|
|
319
|
+
const id = stack.pop();
|
|
320
|
+
if (seen.has(id)) continue;
|
|
321
|
+
seen.add(id);
|
|
322
|
+
const task = byId.get(id);
|
|
323
|
+
const deps = task && Array.isArray(task.dependsOn) ? task.dependsOn : [];
|
|
324
|
+
for (const dep of deps) {
|
|
325
|
+
if (String(dep) === String(targetId)) return true;
|
|
326
|
+
stack.push(String(dep));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function tasksAreOrdered(tasks, left, right) {
|
|
333
|
+
return taskReaches(tasks, left.id, right.id) || taskReaches(tasks, right.id, left.id);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function validateTaskFileLists(tasks, writeScopes) {
|
|
337
|
+
const list = Array.isArray(tasks) ? tasks : [];
|
|
338
|
+
const scopes = Array.isArray(writeScopes) ? writeScopes : [];
|
|
339
|
+
for (const task of list) {
|
|
340
|
+
const id = task && task.id ? task.id : '(unnamed)';
|
|
341
|
+
const files = (task && task.files) || [];
|
|
342
|
+
if (listsBothSpecAndApp(files)) {
|
|
343
|
+
return 'task "' + id + '" lists spec-folder paths and app/** paths in one file list; they are different lists';
|
|
344
|
+
}
|
|
345
|
+
if (scopes.length === 0) continue;
|
|
346
|
+
const combined = files.concat((task && task.specFiles) || [], (task && task.appFiles) || []);
|
|
347
|
+
for (const file of combined) {
|
|
348
|
+
if (!pathInWriteScopes(file, scopes)) {
|
|
349
|
+
const label = normalizeRepoPath(file) || file;
|
|
350
|
+
return 'task "' + id + '" file "' + label + '" is outside the implementing step writeScopes';
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
for (let i = 0; i < list.length; i += 1) {
|
|
355
|
+
for (let j = i + 1; j < list.length; j += 1) {
|
|
356
|
+
if (tasksAreOrdered(list, list[i], list[j])) continue;
|
|
357
|
+
const left = taskFileSet(list[i]);
|
|
358
|
+
let shared = '';
|
|
359
|
+
for (const file of taskFileSet(list[j])) {
|
|
360
|
+
if (left.has(file)) {
|
|
361
|
+
shared = file;
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (shared) return 'parallel tasks "' + list[i].id + '" and "' + list[j].id + '" share "' + shared + '"';
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function productionPathsOutsideTaskList(paths, tasks) {
|
|
372
|
+
const allowed = new Set();
|
|
373
|
+
for (const task of tasks || []) {
|
|
374
|
+
for (const file of taskFileSet(task)) allowed.add(file);
|
|
375
|
+
}
|
|
376
|
+
const outside = [];
|
|
377
|
+
for (const cited of paths || []) {
|
|
378
|
+
const normalized = normalizeRepoPath(cited);
|
|
379
|
+
if (normalized && !allowed.has(normalized)) outside.push(normalized);
|
|
380
|
+
}
|
|
381
|
+
return outside;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function splitMarkdownCells(line) {
|
|
385
|
+
const trimmed = String(line || '').trim();
|
|
386
|
+
if (!trimmed.startsWith('|')) return [];
|
|
387
|
+
const cells = trimmed.split('|').map((cell) => cell.trim());
|
|
388
|
+
if (cells.length && cells[0] === '') cells.shift();
|
|
389
|
+
if (cells.length && cells[cells.length - 1] === '') cells.pop();
|
|
390
|
+
return cells;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function isSeparatorRow(cells) {
|
|
394
|
+
return cells.length > 0 && cells.every((cell) => /^:?-{3,}:?$/.test(cell));
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function pathsFromCell(cell) {
|
|
398
|
+
const text = String(cell || '');
|
|
399
|
+
const found = [];
|
|
400
|
+
const pattern = /`([^`]+)`/g;
|
|
401
|
+
let match = pattern.exec(text);
|
|
402
|
+
while (match) {
|
|
403
|
+
const normalized = normalizeRepoPath(match[1]);
|
|
404
|
+
if (normalized && normalized.includes('/')) found.push(normalized);
|
|
405
|
+
match = pattern.exec(text);
|
|
406
|
+
}
|
|
407
|
+
if (found.length > 0) return found;
|
|
408
|
+
return text.split(',').map((part) => normalizeRepoPath(part)).filter((part) => part.includes('/'));
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function dependsFromCell(cell) {
|
|
412
|
+
const cleaned = String(cell || '').replace(/[`*]/g, '').trim();
|
|
413
|
+
if (!cleaned || cleaned === '—' || cleaned === '-' || cleaned === '–') return [];
|
|
414
|
+
return cleaned.split(/[,|/]/).map((part) => part.trim()).filter((part) => /^[A-Za-z][A-Za-z0-9._-]*$/.test(part));
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function cellIsComplete(cell) {
|
|
418
|
+
const cleaned = String(cell || '').replace(/[`*[\]]/g, '').trim().toLowerCase();
|
|
419
|
+
return cleaned === 'complete' || cleaned === 'completed' || cleaned === 'done' || cleaned === 'x';
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function absorbMarkdownTable(block, byId) {
|
|
423
|
+
const rows = [];
|
|
424
|
+
for (const line of block) {
|
|
425
|
+
const cells = splitMarkdownCells(line);
|
|
426
|
+
if (cells.length === 0 || isSeparatorRow(cells)) continue;
|
|
427
|
+
rows.push(cells);
|
|
428
|
+
}
|
|
429
|
+
if (rows.length < 2) return false;
|
|
430
|
+
const headers = rows[0].map((cell) => cell.replace(/[`*]/g, '').trim());
|
|
431
|
+
const idIndex = headers.findIndex((header) => /^id$/i.test(header));
|
|
432
|
+
if (idIndex < 0) return false;
|
|
433
|
+
const dependsIndex = headers.findIndex((header) => /dependson/i.test(header));
|
|
434
|
+
const specIndex = headers.findIndex((header) => /spec files/i.test(header));
|
|
435
|
+
const appIndex = headers.findIndex((header) => /^app files$/i.test(header));
|
|
436
|
+
const filesIndex = headers.findIndex((header, index) => index !== specIndex && index !== appIndex && /files|paths/i.test(header));
|
|
437
|
+
const statusIndex = headers.findIndex((header) => /^(status|done|state)$/i.test(header));
|
|
438
|
+
const sawFiles = specIndex >= 0 || appIndex >= 0 || filesIndex >= 0;
|
|
439
|
+
for (const cells of rows.slice(1)) {
|
|
440
|
+
const id = String(cells[idIndex] || '').replace(/[`*]/g, '').trim();
|
|
441
|
+
if (!id || /^id$/i.test(id)) continue;
|
|
442
|
+
const task = byId.get(id) || { id, dependsOn: [], files: [], specFiles: [], appFiles: [], tracked: false, rowComplete: false };
|
|
443
|
+
if (dependsIndex >= 0) {
|
|
444
|
+
task.dependsOn = dependsFromCell(cells[dependsIndex] || '');
|
|
445
|
+
task.tracked = true;
|
|
446
|
+
}
|
|
447
|
+
if (statusIndex >= 0) task.rowComplete = cellIsComplete(cells[statusIndex] || '');
|
|
448
|
+
if (filesIndex >= 0) {
|
|
449
|
+
const parsed = pathsFromCell(cells[filesIndex] || '');
|
|
450
|
+
if (parsed.length > 0) task.files = parsed;
|
|
451
|
+
}
|
|
452
|
+
if (specIndex >= 0) {
|
|
453
|
+
const parsed = pathsFromCell(cells[specIndex] || '');
|
|
454
|
+
if (parsed.length > 0) task.specFiles = parsed;
|
|
455
|
+
}
|
|
456
|
+
if (appIndex >= 0) {
|
|
457
|
+
const parsed = pathsFromCell(cells[appIndex] || '');
|
|
458
|
+
if (parsed.length > 0) task.appFiles = parsed;
|
|
459
|
+
}
|
|
460
|
+
byId.set(id, task);
|
|
461
|
+
}
|
|
462
|
+
return sawFiles;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function parseDecompositionTaskFileLists(markdown) {
|
|
466
|
+
const lines = String(markdown || '').split(/\r?\n/);
|
|
467
|
+
const byId = new Map();
|
|
468
|
+
let hasFileColumn = false;
|
|
469
|
+
let index = 0;
|
|
470
|
+
while (index < lines.length) {
|
|
471
|
+
if (!String(lines[index] || '').trim().startsWith('|')) {
|
|
472
|
+
index += 1;
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const block = [];
|
|
476
|
+
while (index < lines.length && String(lines[index] || '').trim().startsWith('|')) {
|
|
477
|
+
block.push(lines[index]);
|
|
478
|
+
index += 1;
|
|
479
|
+
}
|
|
480
|
+
if (absorbMarkdownTable(block, byId)) hasFileColumn = true;
|
|
481
|
+
}
|
|
482
|
+
return { tasks: [...byId.values()], hasFileColumn };
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function parseDecompositionTasks(markdown) {
|
|
486
|
+
const lines = String(markdown || '').split(/\r?\n/);
|
|
487
|
+
const byId = new Map();
|
|
488
|
+
let index = 0;
|
|
489
|
+
while (index < lines.length) {
|
|
490
|
+
if (!String(lines[index] || '').trim().startsWith('|')) {
|
|
491
|
+
index += 1;
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
const block = [];
|
|
495
|
+
while (index < lines.length && String(lines[index] || '').trim().startsWith('|')) {
|
|
496
|
+
block.push(lines[index]);
|
|
497
|
+
index += 1;
|
|
498
|
+
}
|
|
499
|
+
absorbMarkdownTable(block, byId);
|
|
500
|
+
}
|
|
501
|
+
return [...byId.values()].filter((task) => task.tracked === true);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function taskCoveredByCompletedArtifact(taskId, artifacts) {
|
|
505
|
+
const id = String(taskId);
|
|
506
|
+
const list = Array.isArray(artifacts) ? artifacts : [];
|
|
507
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
508
|
+
const artifact = list[index];
|
|
509
|
+
if (!artifact || artifact.status !== 'completed') continue;
|
|
510
|
+
if (String(artifact.id) === id) return true;
|
|
511
|
+
const taskIds = Array.isArray(artifact.taskIds) ? artifact.taskIds : [];
|
|
512
|
+
for (let taskIndex = 0; taskIndex < taskIds.length; taskIndex += 1) {
|
|
513
|
+
if (String(taskIds[taskIndex]) === id) return true;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function computeDecompositionReadySet(tasks, artifacts) {
|
|
520
|
+
const list = (Array.isArray(tasks) ? tasks : []).filter((task) => task && task.id && task.tracked !== false);
|
|
521
|
+
const complete = new Set();
|
|
522
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
523
|
+
const task = list[index];
|
|
524
|
+
if (task.rowComplete === true || taskCoveredByCompletedArtifact(task.id, artifacts)) complete.add(String(task.id));
|
|
525
|
+
}
|
|
526
|
+
const ready = [];
|
|
527
|
+
const blocked = [];
|
|
528
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
529
|
+
const task = list[index];
|
|
530
|
+
const id = String(task.id);
|
|
531
|
+
if (complete.has(id)) continue;
|
|
532
|
+
const deps = Array.isArray(task.dependsOn) ? task.dependsOn.map((dep) => String(dep)) : [];
|
|
533
|
+
const waiting = [];
|
|
534
|
+
const seen = new Set();
|
|
535
|
+
for (let depIndex = 0; depIndex < deps.length; depIndex += 1) {
|
|
536
|
+
const dep = deps[depIndex];
|
|
537
|
+
if (!dep || seen.has(dep) || complete.has(dep)) continue;
|
|
538
|
+
seen.add(dep);
|
|
539
|
+
waiting.push(dep);
|
|
540
|
+
}
|
|
541
|
+
if (waiting.length === 0) ready.push(id);
|
|
542
|
+
else blocked.push({ id, waiting_on: waiting });
|
|
543
|
+
}
|
|
544
|
+
return { ready, blocked };
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function readManifestArtifacts(dir) {
|
|
548
|
+
try {
|
|
549
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'artifact-manifest.json'), 'utf8'));
|
|
550
|
+
return Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
551
|
+
} catch {
|
|
552
|
+
return [];
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function readDecompositionReadySet(dir) {
|
|
557
|
+
let markdown = '';
|
|
558
|
+
try {
|
|
559
|
+
markdown = fs.readFileSync(path.join(dir, 'decomposition.md'), 'utf8');
|
|
560
|
+
} catch {
|
|
561
|
+
markdown = '';
|
|
562
|
+
}
|
|
563
|
+
return computeDecompositionReadySet(parseDecompositionTasks(markdown), readManifestArtifacts(dir));
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function formatDecompositionReadyClause(report, stepsForRows) {
|
|
567
|
+
const source = report && typeof report === 'object' ? report : { ready: [], blocked: [] };
|
|
568
|
+
const stepList = Array.isArray(stepsForRows) ? stepsForRows : [];
|
|
569
|
+
const allow = [];
|
|
570
|
+
for (let index = 0; index < stepList.length; index += 1) {
|
|
571
|
+
const taskIds = stepList[index] && stepList[index].taskIds;
|
|
572
|
+
if (!Array.isArray(taskIds)) continue;
|
|
573
|
+
for (let idIndex = 0; idIndex < taskIds.length; idIndex += 1) {
|
|
574
|
+
if (taskIds[idIndex] != null && String(taskIds[idIndex])) allow.push(String(taskIds[idIndex]));
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
const gate = allow.length > 0 ? new Set(allow) : null;
|
|
578
|
+
const ready = (Array.isArray(source.ready) ? source.ready : []).filter((id) => !gate || gate.has(String(id)));
|
|
579
|
+
const blocked = (Array.isArray(source.blocked) ? source.blocked : []).filter((row) => row && (!gate || gate.has(String(row.id))));
|
|
580
|
+
const readyText = ready.length > 0 ? ready.join(', ') : '(none)';
|
|
581
|
+
let text = ' Decomposition ready set: ' + readyText + '.';
|
|
582
|
+
if (blocked.length > 0) {
|
|
583
|
+
const parts = [];
|
|
584
|
+
for (let index = 0; index < blocked.length; index += 1) {
|
|
585
|
+
const row = blocked[index];
|
|
586
|
+
const waiting = Array.isArray(row.waiting_on) ? row.waiting_on.join(', ') : '';
|
|
587
|
+
parts.push(String(row.id) + ' waiting_on ' + waiting);
|
|
588
|
+
}
|
|
589
|
+
text += ' Blocked: ' + parts.join('; ') + '.';
|
|
590
|
+
}
|
|
591
|
+
return text;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function decompositionReadyClause(stepsForRows) {
|
|
595
|
+
try {
|
|
596
|
+
return formatDecompositionReadyClause(readDecompositionReadySet(taskDir), stepsForRows);
|
|
597
|
+
} catch {
|
|
598
|
+
return ' Decomposition ready set: (none).';
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function productionCitationRepoPath(cited) {
|
|
603
|
+
const value = typeof cited === 'string' ? cited.trim() : '';
|
|
604
|
+
if (!value) return null;
|
|
605
|
+
const normalized = value.replace(/\\/g, '/');
|
|
606
|
+
if (path.isAbsolute(normalized)) {
|
|
607
|
+
const fromCwd = path.relative(process.cwd(), normalized);
|
|
608
|
+
if (fromCwd && !fromCwd.startsWith('..') && !path.isAbsolute(fromCwd)) return normalizeRepoPath(fromCwd);
|
|
609
|
+
return normalizeRepoPath(normalized) || normalized;
|
|
610
|
+
}
|
|
611
|
+
const taskResolved = path.resolve(taskDir, normalized);
|
|
612
|
+
const taskRelative = path.relative(taskDir, taskResolved);
|
|
613
|
+
const insideTask = taskRelative !== '' && taskRelative !== '..' && !taskRelative.startsWith('..' + path.sep) && !path.isAbsolute(taskRelative);
|
|
614
|
+
if (insideTask) {
|
|
615
|
+
try {
|
|
616
|
+
if (fs.statSync(taskResolved).isFile()) return null;
|
|
617
|
+
} catch {}
|
|
618
|
+
}
|
|
619
|
+
return normalizeRepoPath(normalized);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
function implementingStepForTaskIds(taskIds) {
|
|
623
|
+
if (!Array.isArray(steps) || taskIds.length === 0) return null;
|
|
624
|
+
return steps.find((step) => Array.isArray(step && step.taskIds) && taskIds.some((id) => step.taskIds.map((item) => String(item)).includes(String(id)))) || null;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function productionWriteListError(entry) {
|
|
628
|
+
const artifactId = entry && entry.id ? entry.id : '(unnamed)';
|
|
629
|
+
const resume = 'Then resume with: /task-continue ' + slug;
|
|
630
|
+
const fail = (detail) => '[chain-team-phases] ' + slug + ': receipt "' + artifactId + '" ' + detail + ' ' + resume;
|
|
631
|
+
try {
|
|
632
|
+
const evidence = entry && Array.isArray(entry.evidencePaths) ? entry.evidencePaths : [];
|
|
633
|
+
const production = [];
|
|
634
|
+
for (const cited of evidence) {
|
|
635
|
+
const repoPath = productionCitationRepoPath(cited);
|
|
636
|
+
if (repoPath) production.push(repoPath);
|
|
637
|
+
}
|
|
638
|
+
if (production.length === 0) return null;
|
|
639
|
+
let markdown = '';
|
|
640
|
+
try {
|
|
641
|
+
markdown = fs.readFileSync(path.join(taskDir, 'decomposition.md'), 'utf8');
|
|
642
|
+
} catch {
|
|
643
|
+
markdown = '';
|
|
644
|
+
}
|
|
645
|
+
const parsed = parseDecompositionTaskFileLists(markdown);
|
|
646
|
+
if (!parsed.hasFileColumn) return null;
|
|
647
|
+
const tasks = parsed.tasks;
|
|
648
|
+
const taskIds = Array.isArray(entry && entry.taskIds) ? entry.taskIds.map((id) => String(id)) : [];
|
|
649
|
+
const step = implementingStepForTaskIds(taskIds);
|
|
650
|
+
const selectedIds = new Set(taskIds);
|
|
651
|
+
if (step && Array.isArray(step.taskIds)) {
|
|
652
|
+
for (const id of step.taskIds) selectedIds.add(String(id));
|
|
653
|
+
}
|
|
654
|
+
const selected = tasks.filter((task) => selectedIds.has(String(task.id)));
|
|
655
|
+
if (selected.length === 0) {
|
|
656
|
+
return fail('cites production paths but decomposition.md has no file list for ' + (taskIds.join(', ') || '(none)') + '. Record the task file list.');
|
|
657
|
+
}
|
|
658
|
+
const writeScopes = step && Array.isArray(step.writeScopes) ? step.writeScopes : [];
|
|
659
|
+
const listError = validateTaskFileLists(selected, writeScopes);
|
|
660
|
+
if (listError) return fail(listError + '.');
|
|
661
|
+
const owned = selected.filter((task) => taskIds.includes(String(task.id)));
|
|
662
|
+
const citedAgainst = owned.length > 0 ? owned : selected;
|
|
663
|
+
const outside = productionPathsOutsideTaskList(production, citedAgainst);
|
|
664
|
+
if (outside.length > 0) {
|
|
665
|
+
const ids = taskIds.length > 0 ? taskIds.join(', ') : citedAgainst.map((task) => task.id).join(', ');
|
|
666
|
+
return fail('cites production path "' + outside[0] + '", which is not on the decomposition file list for ' + ids + '.');
|
|
667
|
+
}
|
|
668
|
+
return null;
|
|
669
|
+
} catch (error) {
|
|
670
|
+
return fail('production file-list check failed (' + (error && error.message ? error.message : error) + ').');
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
257
674
|
// A2: a `completed` receipt must cite evidence the harness can inspect. Order is
|
|
258
675
|
// the message order — the first failing predicate wins, so the operator sees one
|
|
259
676
|
// actionable line. `authoritativePaths[]` stays task-dir-relative; external
|
|
260
|
-
// references belong in `evidencePaths[]`.
|
|
677
|
+
// references belong in `evidencePaths[]`. The task-folder checks below stay in
|
|
678
|
+
// place. A later production evidencePaths check uses the decomposition file list
|
|
679
|
+
// only when that list column exists.
|
|
261
680
|
function validateCompletedArtifact(entry) {
|
|
262
681
|
const artifactId = entry && entry.id ? entry.id : '(unnamed)';
|
|
263
682
|
const entryStatus = entry && entry.status;
|
|
@@ -289,6 +708,8 @@ function validateCompletedArtifact(entry) {
|
|
|
289
708
|
}
|
|
290
709
|
}
|
|
291
710
|
}
|
|
711
|
+
const productionListError = productionWriteListError(entry);
|
|
712
|
+
if (productionListError) return productionListError;
|
|
292
713
|
return null;
|
|
293
714
|
}
|
|
294
715
|
|
|
@@ -434,7 +855,21 @@ function endHumanGateIfResumed() {
|
|
|
434
855
|
appendMetric({ type: 'human_gate_ended', at: now, gateStartedEventId: status.activeHumanGateEventId, source: 'hook', attributionConfidence: 'high' });
|
|
435
856
|
delete status.activeHumanGateEventId;
|
|
436
857
|
}
|
|
437
|
-
function completeTaskMetrics() {
|
|
858
|
+
function completeTaskMetrics() {
|
|
859
|
+
// Two hook processes can both enter completion before either writes the
|
|
860
|
+
// event. The metrics lock serializes them; the second sees the first write.
|
|
861
|
+
mutateMetrics((metrics) => {
|
|
862
|
+
if (metrics.events.some((event) => event && event.type === 'task_completed')) return;
|
|
863
|
+
metrics.events.push({
|
|
864
|
+
eventId: `${metrics.task.runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
|
|
865
|
+
type: 'task_completed',
|
|
866
|
+
at: now,
|
|
867
|
+
outcome: status.state === 'completed' ? 'completed' : 'unknown',
|
|
868
|
+
source: 'hook',
|
|
869
|
+
attributionConfidence: 'high',
|
|
870
|
+
});
|
|
871
|
+
});
|
|
872
|
+
}
|
|
438
873
|
function recordSkippedStep(step, stepIndex) {
|
|
439
874
|
for (const agent of getStepAgents(step)) {
|
|
440
875
|
const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
@@ -444,6 +879,309 @@ function recordSkippedStep(step, stepIndex) {
|
|
|
444
879
|
}
|
|
445
880
|
}
|
|
446
881
|
|
|
882
|
+
// Living task files and the hook ledger stay put. A completed entry's other markdown is the body that leaves the default read.
|
|
883
|
+
const CLOSED_BODY_KEEP = new Set([
|
|
884
|
+
'brief.md',
|
|
885
|
+
'decomposition.md',
|
|
886
|
+
'goal.md',
|
|
887
|
+
'prompt.md',
|
|
888
|
+
'prompt-log.md',
|
|
889
|
+
'pipeline.json',
|
|
890
|
+
'implementation.md',
|
|
891
|
+
'.memlog.md',
|
|
892
|
+
'focus.md',
|
|
893
|
+
'status.json',
|
|
894
|
+
'metrics.json',
|
|
895
|
+
'artifact-manifest.json',
|
|
896
|
+
'overlay-scope.json',
|
|
897
|
+
]);
|
|
898
|
+
|
|
899
|
+
function closedMarkdownBody(dir, cited) {
|
|
900
|
+
if (typeof cited !== 'string') return null;
|
|
901
|
+
const value = cited.trim();
|
|
902
|
+
if (!value || path.isAbsolute(value)) return null;
|
|
903
|
+
const resolved = path.resolve(dir, value);
|
|
904
|
+
const relative = path.relative(dir, resolved);
|
|
905
|
+
if (!relative || relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)) return null;
|
|
906
|
+
const normalized = relative.split(path.sep).join('/');
|
|
907
|
+
if (!/\.md$/i.test(normalized) || normalized.startsWith('archive/')) return null;
|
|
908
|
+
const base = normalized.slice(normalized.lastIndexOf('/') + 1);
|
|
909
|
+
if (CLOSED_BODY_KEEP.has(base) || CLOSED_BODY_KEEP.has(normalized)) return null;
|
|
910
|
+
return { resolved, base };
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
function archiveClosedBody(dir, date, id, body) {
|
|
914
|
+
const archiveDir = path.join(dir, 'archive', date);
|
|
915
|
+
fs.mkdirSync(archiveDir, { recursive: true });
|
|
916
|
+
let name = body.base;
|
|
917
|
+
let destination = path.join(archiveDir, name);
|
|
918
|
+
if (fs.existsSync(destination)) {
|
|
919
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(id)) return null;
|
|
920
|
+
name = id + '--' + body.base;
|
|
921
|
+
destination = path.join(archiveDir, name);
|
|
922
|
+
}
|
|
923
|
+
if (fs.existsSync(destination)) return null;
|
|
924
|
+
fs.renameSync(body.resolved, destination);
|
|
925
|
+
return 'archive/' + date + '/' + name;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
function appendMemlogEvent(dir, text) {
|
|
929
|
+
const memlogPath = path.join(dir, '.memlog.md');
|
|
930
|
+
const line = '- `event`: ' + text + '\n';
|
|
931
|
+
let existing = '';
|
|
932
|
+
try { existing = fs.readFileSync(memlogPath, 'utf8'); } catch { existing = ''; }
|
|
933
|
+
if (existing.includes(text)) return existing;
|
|
934
|
+
const prefix = existing.length > 0 && !existing.endsWith('\n') ? '\n' : '';
|
|
935
|
+
fs.appendFileSync(memlogPath, prefix + line);
|
|
936
|
+
return existing + prefix + line;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
function writeJsonFile(filePath, value) {
|
|
940
|
+
const temporary = filePath + '.' + String(process.pid) + '.tmp';
|
|
941
|
+
const fd = fs.openSync(temporary, 'w');
|
|
942
|
+
try {
|
|
943
|
+
fs.writeSync(fd, JSON.stringify(value, null, 2) + '\n');
|
|
944
|
+
} finally {
|
|
945
|
+
fs.closeSync(fd);
|
|
946
|
+
}
|
|
947
|
+
fs.renameSync(temporary, filePath);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
function compactClosedManifestBodies(dir, closedOn) {
|
|
951
|
+
const date = typeof closedOn === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(closedOn)
|
|
952
|
+
? closedOn
|
|
953
|
+
: new Date().toISOString().slice(0, 10);
|
|
954
|
+
const manifestPath = path.join(dir, 'artifact-manifest.json');
|
|
955
|
+
let manifest;
|
|
956
|
+
try {
|
|
957
|
+
manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
958
|
+
} catch {
|
|
959
|
+
return { moved: [] };
|
|
960
|
+
}
|
|
961
|
+
const slugBefore = manifest.slug;
|
|
962
|
+
const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
963
|
+
let memlog = '';
|
|
964
|
+
try { memlog = fs.readFileSync(path.join(dir, '.memlog.md'), 'utf8'); } catch { memlog = ''; }
|
|
965
|
+
let manifestChanged = false;
|
|
966
|
+
const moved = [];
|
|
967
|
+
for (let index = 0; index < artifacts.length; index += 1) {
|
|
968
|
+
const entry = artifacts[index];
|
|
969
|
+
if (!entry || entry.status !== 'completed' || typeof entry.id !== 'string' || !entry.id) continue;
|
|
970
|
+
const marker = 'closed manifest artifact ' + entry.id + ';';
|
|
971
|
+
if (memlog.includes(marker)) continue;
|
|
972
|
+
const cited = Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths.slice() : [];
|
|
973
|
+
const relocated = [];
|
|
974
|
+
for (let pathIndex = 0; pathIndex < cited.length; pathIndex += 1) {
|
|
975
|
+
const body = closedMarkdownBody(dir, cited[pathIndex]);
|
|
976
|
+
if (!body) continue;
|
|
977
|
+
let stat = null;
|
|
978
|
+
try { stat = fs.statSync(body.resolved); } catch { stat = null; }
|
|
979
|
+
if (!stat || !stat.isFile()) continue;
|
|
980
|
+
let content = '';
|
|
981
|
+
try { content = fs.readFileSync(body.resolved, 'utf8'); } catch { content = ''; }
|
|
982
|
+
if (!/\S/.test(content)) continue;
|
|
983
|
+
const archived = archiveClosedBody(dir, date, entry.id, body);
|
|
984
|
+
if (!archived) continue;
|
|
985
|
+
cited[pathIndex] = archived;
|
|
986
|
+
relocated.push(archived);
|
|
987
|
+
moved.push(archived);
|
|
988
|
+
manifestChanged = true;
|
|
989
|
+
}
|
|
990
|
+
if (relocated.length > 0) entry.authoritativePaths = cited;
|
|
991
|
+
let archiveHint = relocated.length > 0 ? 'archive/' + date + '/' : '';
|
|
992
|
+
if (!archiveHint) {
|
|
993
|
+
for (let pathIndex = 0; pathIndex < cited.length; pathIndex += 1) {
|
|
994
|
+
const value = typeof cited[pathIndex] === 'string' ? cited[pathIndex].trim() : '';
|
|
995
|
+
const match = /^archive\/\d{4}-\d{2}-\d{2}\//.exec(value);
|
|
996
|
+
if (match) {
|
|
997
|
+
archiveHint = match[0];
|
|
998
|
+
break;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
const text = archiveHint
|
|
1003
|
+
? 'closed manifest artifact ' + entry.id + '; body archived under ' + archiveHint
|
|
1004
|
+
: 'closed manifest artifact ' + entry.id + '; no bulky markdown body moved';
|
|
1005
|
+
memlog = appendMemlogEvent(dir, text);
|
|
1006
|
+
}
|
|
1007
|
+
if (manifest.slug !== slugBefore) manifest.slug = slugBefore;
|
|
1008
|
+
if (manifestChanged) writeJsonFile(manifestPath, manifest);
|
|
1009
|
+
return { moved };
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
function projectResumeArtifact(entry) {
|
|
1013
|
+
if (!entry || typeof entry !== 'object') return entry;
|
|
1014
|
+
if (entry.status !== 'completed') return entry;
|
|
1015
|
+
return {
|
|
1016
|
+
id: entry.id,
|
|
1017
|
+
status: entry.status,
|
|
1018
|
+
authoritativePaths: Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths : [],
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
function defaultResumeRead(dir) {
|
|
1023
|
+
const chunks = [];
|
|
1024
|
+
try { chunks.push(fs.readFileSync(path.join(dir, 'focus.md'), 'utf8')); } catch {}
|
|
1025
|
+
try {
|
|
1026
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'artifact-manifest.json'), 'utf8'));
|
|
1027
|
+
const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
1028
|
+
const projected = [];
|
|
1029
|
+
for (let index = 0; index < artifacts.length; index += 1) {
|
|
1030
|
+
projected.push(projectResumeArtifact(artifacts[index]));
|
|
1031
|
+
}
|
|
1032
|
+
chunks.push(JSON.stringify({ slug: manifest.slug, artifacts: projected }));
|
|
1033
|
+
} catch {}
|
|
1034
|
+
try { chunks.push(fs.readFileSync(path.join(dir, '.memlog.md'), 'utf8')); } catch {}
|
|
1035
|
+
return chunks.join('\n');
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
function archiveIndexLine(dir) {
|
|
1039
|
+
const root = path.join(dir, 'archive');
|
|
1040
|
+
let names = [];
|
|
1041
|
+
try { names = fs.readdirSync(root); } catch { names = []; }
|
|
1042
|
+
const dates = [];
|
|
1043
|
+
for (let index = 0; index < names.length; index += 1) {
|
|
1044
|
+
const name = names[index];
|
|
1045
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(name)) continue;
|
|
1046
|
+
let stat = null;
|
|
1047
|
+
try { stat = fs.statSync(path.join(root, name)); } catch { stat = null; }
|
|
1048
|
+
if (stat && stat.isDirectory()) dates.push(name);
|
|
1049
|
+
}
|
|
1050
|
+
dates.sort();
|
|
1051
|
+
if (dates.length === 0) return '- archive index: (none)';
|
|
1052
|
+
const parts = [];
|
|
1053
|
+
for (let index = 0; index < dates.length; index += 1) parts.push('archive/' + dates[index] + '/');
|
|
1054
|
+
return '- archive index: ' + parts.join(', ');
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
function focusDigestMarkdown(dir, statusSnapshot) {
|
|
1058
|
+
const snapshot = statusSnapshot && typeof statusSnapshot === 'object' ? statusSnapshot : {};
|
|
1059
|
+
const slugValue = typeof snapshot.slug === 'string' ? snapshot.slug : '';
|
|
1060
|
+
const stepIndex = Number.isInteger(snapshot.pipelineIndex) ? snapshot.pipelineIndex : 0;
|
|
1061
|
+
const incomplete = [];
|
|
1062
|
+
try {
|
|
1063
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'artifact-manifest.json'), 'utf8'));
|
|
1064
|
+
const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
1065
|
+
for (let index = 0; index < artifacts.length; index += 1) {
|
|
1066
|
+
const artifact = artifacts[index];
|
|
1067
|
+
if (!artifact || artifact.status === 'completed') continue;
|
|
1068
|
+
const id = typeof artifact.id === 'string' ? artifact.id : '(no id)';
|
|
1069
|
+
const cited = Array.isArray(artifact.authoritativePaths) ? artifact.authoritativePaths : [];
|
|
1070
|
+
const paths = [];
|
|
1071
|
+
for (let pathIndex = 0; pathIndex < cited.length; pathIndex += 1) {
|
|
1072
|
+
if (typeof cited[pathIndex] === 'string') paths.push(cited[pathIndex]);
|
|
1073
|
+
}
|
|
1074
|
+
incomplete.push({ id, paths });
|
|
1075
|
+
}
|
|
1076
|
+
} catch {}
|
|
1077
|
+
let lastEvent = '(none)';
|
|
1078
|
+
try {
|
|
1079
|
+
const raw = fs.readFileSync(path.join(dir, '.memlog.md'), 'utf8');
|
|
1080
|
+
const lines = raw.split(/\r?\n/);
|
|
1081
|
+
const tickEvent = /`event`:\s*(.*)$/;
|
|
1082
|
+
const bareEvent = /(?:^|\s)event:\s*(.*)$/;
|
|
1083
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
1084
|
+
const line = lines[index];
|
|
1085
|
+
let matched = tickEvent.exec(line);
|
|
1086
|
+
if (!matched) matched = bareEvent.exec(line);
|
|
1087
|
+
if (matched && matched[1].trim()) {
|
|
1088
|
+
lastEvent = matched[1].trim();
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
} catch {}
|
|
1093
|
+
let nextGate = 'none';
|
|
1094
|
+
if (snapshot.awaitingHumanGate === true || snapshot.state === 'awaiting_approval') {
|
|
1095
|
+
nextGate = 'human gate — /task-continue ' + slugValue;
|
|
1096
|
+
} else {
|
|
1097
|
+
try {
|
|
1098
|
+
const pipeline = JSON.parse(fs.readFileSync(path.join(dir, 'pipeline.json'), 'utf8'));
|
|
1099
|
+
const steps = Array.isArray(pipeline.steps) ? pipeline.steps : [];
|
|
1100
|
+
const gates = Array.isArray(pipeline.humanGates) ? pipeline.humanGates : [];
|
|
1101
|
+
for (let index = stepIndex; index < steps.length; index += 1) {
|
|
1102
|
+
const step = steps[index];
|
|
1103
|
+
const agents = !step ? [] : (Array.isArray(step.agent) ? step.agent : [step.agent]);
|
|
1104
|
+
let hit = '';
|
|
1105
|
+
for (let agentIndex = 0; agentIndex < agents.length; agentIndex += 1) {
|
|
1106
|
+
const agent = agents[agentIndex];
|
|
1107
|
+
if (typeof agent === 'string' && gates.indexOf('after:' + agent) !== -1) {
|
|
1108
|
+
hit = agent;
|
|
1109
|
+
break;
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
if (hit) {
|
|
1113
|
+
const stepId = step && typeof step.id === 'string' ? step.id : 'step-' + String(index);
|
|
1114
|
+
nextGate = 'after:' + hit + ' (step ' + stepId + ', index ' + String(index) + ')';
|
|
1115
|
+
break;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
} catch {}
|
|
1119
|
+
}
|
|
1120
|
+
const pathLines = [];
|
|
1121
|
+
if (incomplete.length === 0) pathLines.push(' - (none)');
|
|
1122
|
+
else {
|
|
1123
|
+
for (let index = 0; index < incomplete.length; index += 1) {
|
|
1124
|
+
const item = incomplete[index];
|
|
1125
|
+
if (item.paths.length === 0) pathLines.push(' - ' + item.id + ': (none)');
|
|
1126
|
+
else {
|
|
1127
|
+
for (let pathIndex = 0; pathIndex < item.paths.length; pathIndex += 1) {
|
|
1128
|
+
pathLines.push(' - ' + item.id + ': ' + item.paths[pathIndex]);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
let readyLine = '- decomposition ready set: (none)';
|
|
1134
|
+
try {
|
|
1135
|
+
const report = readDecompositionReadySet(dir);
|
|
1136
|
+
const ids = Array.isArray(report.ready) ? report.ready : [];
|
|
1137
|
+
readyLine = '- decomposition ready set: ' + (ids.length > 0 ? ids.join(', ') : '(none)');
|
|
1138
|
+
} catch {
|
|
1139
|
+
readyLine = '- decomposition ready set: (none)';
|
|
1140
|
+
}
|
|
1141
|
+
const head = [
|
|
1142
|
+
'# focus.md',
|
|
1143
|
+
'',
|
|
1144
|
+
'View only. `status.json`, `metrics.json`, `artifact-manifest.json`, and `.memlog.md` stay the system of record.',
|
|
1145
|
+
'',
|
|
1146
|
+
'- slug: ' + slugValue,
|
|
1147
|
+
'- pipeline step index: ' + String(stepIndex),
|
|
1148
|
+
readyLine,
|
|
1149
|
+
archiveIndexLine(dir),
|
|
1150
|
+
'- incomplete authoritative paths:',
|
|
1151
|
+
];
|
|
1152
|
+
const tail = [
|
|
1153
|
+
'- last memlog event: ' + lastEvent,
|
|
1154
|
+
'- next gate: ' + nextGate,
|
|
1155
|
+
];
|
|
1156
|
+
let pathBudget = 99 - head.length - tail.length;
|
|
1157
|
+
if (pathBudget < 1) pathBudget = 1;
|
|
1158
|
+
let kept = pathLines;
|
|
1159
|
+
if (pathLines.length > pathBudget) {
|
|
1160
|
+
const room = pathBudget - 1;
|
|
1161
|
+
kept = pathLines.slice(0, room);
|
|
1162
|
+
const omitted = pathLines.length - kept.length;
|
|
1163
|
+
kept.push(' - (' + String(omitted) + ' lines omitted to stay under 100)');
|
|
1164
|
+
}
|
|
1165
|
+
return head.concat(kept, tail).join('\n') + '\n';
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
function writeFocusDigest() {
|
|
1169
|
+
const focusPath = path.join(taskDir, 'focus.md');
|
|
1170
|
+
const temporary = focusPath + '.' + String(process.pid) + '.' + String(Date.now()) + '.tmp';
|
|
1171
|
+
try {
|
|
1172
|
+
const markdown = focusDigestMarkdown(taskDir, status);
|
|
1173
|
+
const fd = fs.openSync(temporary, 'w');
|
|
1174
|
+
try {
|
|
1175
|
+
fs.writeSync(fd, markdown);
|
|
1176
|
+
try { fs.fsyncSync(fd); } catch {}
|
|
1177
|
+
} finally {
|
|
1178
|
+
fs.closeSync(fd);
|
|
1179
|
+
}
|
|
1180
|
+
fs.renameSync(temporary, focusPath);
|
|
1181
|
+
} catch {
|
|
1182
|
+
try { fs.unlinkSync(temporary); } catch {}
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
447
1185
|
|
|
448
1186
|
function writeStatus(next) {
|
|
449
1187
|
status = { ...status, ...next, slug, updatedAt: now };
|
|
@@ -460,6 +1198,11 @@ function writeStatus(next) {
|
|
|
460
1198
|
fs.closeSync(fd);
|
|
461
1199
|
}
|
|
462
1200
|
fs.renameSync(temporary, statusPath);
|
|
1201
|
+
// Closed bodies move after the checkpoint lands. A compaction miss must not roll status.json back.
|
|
1202
|
+
try { compactClosedManifestBodies(taskDir, now.slice(0, 10)); } catch {}
|
|
1203
|
+
// focus.md is a view of this checkpoint. It is written after status.json
|
|
1204
|
+
// lands so a digest failure cannot roll the checkpoint back.
|
|
1205
|
+
writeFocusDigest();
|
|
463
1206
|
}
|
|
464
1207
|
|
|
465
1208
|
function out(message) {
|
|
@@ -622,7 +1365,8 @@ function handoffForWave(units, waveId) {
|
|
|
622
1365
|
`Invoke IN PARALLEL (one message, multiple Task calls): ${labels.join(' AND ')} for slug "${slug}"${waveId ? ` (waveId=${waveId})` : ''}. ` +
|
|
623
1366
|
`Each agent writes its artifact and owned receipt; the hook records slot joins from stops. Do not mutate status.json lifecycle fields. ` +
|
|
624
1367
|
`Artifact inputs: ${inputIds.length > 0 ? inputIds.join(', ') : 'manifest defaults'}; owned output IDs: ${outputIds.join('; ')}. ` +
|
|
625
|
-
`Metrics attemptIds: ${attemptIds.join('; ')}. If the hook cannot identify a parallel stop, append a minimal { attemptId, outcome } receipt to .metrics-receipts.json; do not calculate duration
|
|
1368
|
+
`Metrics attemptIds: ${attemptIds.join('; ')}. If the hook cannot identify a parallel stop, append a minimal { attemptId, outcome } receipt to .metrics-receipts.json; do not calculate duration. ${receiptPathClause()}` +
|
|
1369
|
+
decompositionReadyClause(units.map((unit) => steps[unit.stepIndex]))
|
|
626
1370
|
);
|
|
627
1371
|
}
|
|
628
1372
|
function blockedNotice(blockedIndex, agent) {
|
|
@@ -638,16 +1382,29 @@ function noProgressNotice() {
|
|
|
638
1382
|
const pending = pendingStepIndexes().map((index) => steps[index].id || `step-${index}`);
|
|
639
1383
|
return `No schedulable step remains for slug "${slug}" (unsatisfied: ${pending.join(', ')}). Resume only via /task-continue ${slug}.`;
|
|
640
1384
|
}
|
|
1385
|
+
function deferReason(wave, deferred) {
|
|
1386
|
+
const sameAgent = deferred.some((index) => wave.some((chosen) => {
|
|
1387
|
+
const left = getStepAgents(steps[chosen]);
|
|
1388
|
+
return getStepAgents(steps[index]).some((agent) => left.includes(agent));
|
|
1389
|
+
}));
|
|
1390
|
+
if (sameAgent) return 'same agent already in the wave';
|
|
1391
|
+
const missingScope = [...wave, ...deferred].some((index) => declaredScopes(steps[index]).length === 0);
|
|
1392
|
+
if (missingScope) return 'writeScopes undeclared';
|
|
1393
|
+
return 'writeScopes overlap';
|
|
1394
|
+
}
|
|
641
1395
|
function dispatchReadyWave(prefixMessage) {
|
|
642
1396
|
const ready = computeReadySteps();
|
|
643
1397
|
if (ready.length === 0) return false;
|
|
644
1398
|
const { wave, deferred } = selectWave(ready);
|
|
645
1399
|
if (deferred.length > 0) {
|
|
646
|
-
appendMetric({ type: 'parallel_conflict_deferred', at: now, stepIndex: wave[0], deferredStepIndexes: deferred, reason:
|
|
1400
|
+
appendMetric({ type: 'parallel_conflict_deferred', at: now, stepIndex: wave[0], deferredStepIndexes: deferred, reason: deferReason(wave, deferred), source: 'hook', attributionConfidence: 'fallback' });
|
|
647
1401
|
}
|
|
648
1402
|
// Slot-filtered dispatch: only unsatisfied (stepIndex, agent) slots are invoked.
|
|
649
1403
|
const units = wave.flatMap((stepIndex) => unsatisfiedAgents(stepIndex).map((agent) => ({ stepIndex, agent })));
|
|
650
1404
|
if (units.length === 0) return false;
|
|
1405
|
+
const unitAgents = units.map((unit) => unit.agent);
|
|
1406
|
+
refuseImplementationStart(unitAgents, (agent) => implementationDebugRetry(agent));
|
|
1407
|
+
recordAllowedDebugRetries(unitAgents);
|
|
651
1408
|
const first = units[0].stepIndex;
|
|
652
1409
|
const waveId = `${status.metricsRunId || slug}:wave-${first}`;
|
|
653
1410
|
for (const unit of units) activateAttempts(steps[unit.stepIndex], unit.stepIndex, units.length > 1 ? waveId : null, [unit.agent]);
|
|
@@ -733,15 +1490,173 @@ function metricsHandoff(agent) {
|
|
|
733
1490
|
return ' Metrics: use the supplied attemptId when available; for a parallel completion, write a minimal { attemptId, outcome } receipt to .metrics-receipts.json rather than relying on currentAgent. Do not calculate duration.';
|
|
734
1491
|
}
|
|
735
1492
|
|
|
1493
|
+
function receiptPathClause() {
|
|
1494
|
+
return 'authoritativePaths are relative to the task folder (brief.md), not the repo root; put external files in evidencePaths.';
|
|
1495
|
+
}
|
|
736
1496
|
function artifactHandoff(step, agent) {
|
|
737
1497
|
const inputIds = Array.isArray(step?.artifactInputIds) ? step.artifactInputIds.join(', ') : 'manifest defaults';
|
|
738
|
-
return ` Artifact inputs: ${inputIds}; owned output ID: ${artifactOutputIdFor(step, agent)}. Bind the terminal receipt to the supplied attemptId
|
|
1498
|
+
return ` Artifact inputs: ${inputIds}; owned output ID: ${artifactOutputIdFor(step, agent)}. Bind the terminal receipt to the supplied attemptId. ${receiptPathClause()}`;
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
// <<<implementation-rail>>>
|
|
1502
|
+
// Opt-in. Omitted, "off", and non-production intents stay off. Only "on" applies.
|
|
1503
|
+
function testBeforeHandoffRule() {
|
|
1504
|
+
return 'Include unit tests for mappers/logic before handoff.';
|
|
1505
|
+
}
|
|
1506
|
+
function railOnHandoffClause() {
|
|
1507
|
+
return ' Strict implementation rail: write a failing test before production edits; use a branch or worktree before the first implementation task; run code-reviewer between decomposition tasks; debug retries for this handoff are capped at two.';
|
|
1508
|
+
}
|
|
1509
|
+
function implementationRailApplies(pipeline) {
|
|
1510
|
+
if (!pipeline || typeof pipeline !== 'object') return false;
|
|
1511
|
+
const intent = typeof pipeline.intent === 'string' ? pipeline.intent : '';
|
|
1512
|
+
const level = pipeline.taskLevel;
|
|
1513
|
+
if (level === 'L0' || level === 0 || level === '0') return false;
|
|
1514
|
+
if (intent === 'docs-only' || intent === 'research' || intent === 'preset-only' || intent === 'spike') return false;
|
|
1515
|
+
if (pipeline.presetOnly === true) return false;
|
|
1516
|
+
return pipeline.implementationRail === 'on';
|
|
1517
|
+
}
|
|
1518
|
+
function briefHasOpenClarificationMarker(text) {
|
|
1519
|
+
if (typeof text !== 'string' || text.length === 0) return false;
|
|
1520
|
+
const lines = text.split(/\r?\n/);
|
|
1521
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
1522
|
+
let body = lines[index].trim().replace(/^(?:>\s*)+/, '');
|
|
1523
|
+
body = body.replace(/^(?:[-*+]|\d+[.)])\s+/, '');
|
|
1524
|
+
if (body.startsWith('[NEEDS CLARIFICATION]')) return true;
|
|
1525
|
+
}
|
|
1526
|
+
return false;
|
|
1527
|
+
}
|
|
1528
|
+
function implementationHandoffDecision(input) {
|
|
1529
|
+
const agent = input && input.agent;
|
|
1530
|
+
const applies = agent === 'feature-developer' && implementationRailApplies(input && input.pipeline);
|
|
1531
|
+
if (!applies) {
|
|
1532
|
+
return {
|
|
1533
|
+
start: true,
|
|
1534
|
+
rail: 'off',
|
|
1535
|
+
handoffRule: agent === 'feature-developer' ? testBeforeHandoffRule() : null,
|
|
1536
|
+
constraints: [],
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
if (briefHasOpenClarificationMarker(input && input.briefText)) {
|
|
1540
|
+
return { start: false, rail: 'on', reason: 'open-marker', handoffRule: testBeforeHandoffRule(), constraints: [] };
|
|
1541
|
+
}
|
|
1542
|
+
const debugRetries = Number(input && input.debugRetryCount) || 0;
|
|
1543
|
+
if (input && input.debugRetry === true && debugRetries >= 2) {
|
|
1544
|
+
return { start: false, rail: 'on', reason: 'debug-retry-cap', handoffRule: testBeforeHandoffRule(), constraints: [] };
|
|
1545
|
+
}
|
|
1546
|
+
return {
|
|
1547
|
+
start: true,
|
|
1548
|
+
rail: 'on',
|
|
1549
|
+
handoffRule: testBeforeHandoffRule(),
|
|
1550
|
+
constraints: [
|
|
1551
|
+
'failing test before production edits',
|
|
1552
|
+
'branch or worktree before the first implementation task',
|
|
1553
|
+
'code-reviewer between decomposition tasks',
|
|
1554
|
+
'debug retries capped at two',
|
|
1555
|
+
],
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
// <<<implementation-rail-end>>>
|
|
1559
|
+
|
|
1560
|
+
function readPipelineRecord() {
|
|
1561
|
+
try {
|
|
1562
|
+
return JSON.parse(fs.readFileSync(pipelinePath, 'utf8'));
|
|
1563
|
+
} catch {
|
|
1564
|
+
return null;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
function readBriefText() {
|
|
1568
|
+
try {
|
|
1569
|
+
return fs.readFileSync(path.join(taskDir, 'brief.md'), 'utf8');
|
|
1570
|
+
} catch {
|
|
1571
|
+
return '';
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
function countDebugImplementationRetries() {
|
|
1575
|
+
try {
|
|
1576
|
+
const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
|
|
1577
|
+
const events = Array.isArray(metrics.events) ? metrics.events : [];
|
|
1578
|
+
return events.filter((event) => event && event.type === 'retry_scheduled' && event.nextAgent === 'feature-developer' && event.retryAfterFix === 'debugger').length;
|
|
1579
|
+
} catch {
|
|
1580
|
+
return 0;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
function featureDeveloperAlreadyStarted() {
|
|
1584
|
+
try {
|
|
1585
|
+
const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
|
|
1586
|
+
const events = Array.isArray(metrics.events) ? metrics.events : [];
|
|
1587
|
+
return events.some((event) => event && event.type === 'attempt_started' && event.agent === 'feature-developer');
|
|
1588
|
+
} catch {
|
|
1589
|
+
return false;
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
function implementationDebugRetry(agent) {
|
|
1593
|
+
return agent === 'feature-developer' && status.currentAgent === 'debugger' && featureDeveloperAlreadyStarted();
|
|
1594
|
+
}
|
|
1595
|
+
function blockImplementationStart(agent, debugRetry) {
|
|
1596
|
+
const decision = implementationHandoffDecision({
|
|
1597
|
+
agent,
|
|
1598
|
+
pipeline: readPipelineRecord(),
|
|
1599
|
+
briefText: readBriefText(),
|
|
1600
|
+
debugRetry: Boolean(debugRetry),
|
|
1601
|
+
debugRetryCount: countDebugImplementationRetries(),
|
|
1602
|
+
});
|
|
1603
|
+
if (decision.start) return null;
|
|
1604
|
+
if (decision.reason === 'debug-retry-cap') {
|
|
1605
|
+
return `Strict implementation rail is on for slug "${slug}". Debug retries for the implementation handoff are capped at two. Do not start implementation.`;
|
|
1606
|
+
}
|
|
1607
|
+
return `Strict implementation rail is on for slug "${slug}" and a [NEEDS CLARIFICATION] marker is open. Do not start implementation.`;
|
|
1608
|
+
}
|
|
1609
|
+
function refuseImplementationStart(agents, debugRetryFor) {
|
|
1610
|
+
const list = Array.isArray(agents) ? agents : [agents];
|
|
1611
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
1612
|
+
const block = blockImplementationStart(list[index], debugRetryFor(list[index]));
|
|
1613
|
+
if (!block) continue;
|
|
1614
|
+
beginHumanGate();
|
|
1615
|
+
writeStatus({
|
|
1616
|
+
state: 'awaiting_approval',
|
|
1617
|
+
phase: 'human_gate',
|
|
1618
|
+
awaitingHumanGate: true,
|
|
1619
|
+
waveSteps: [],
|
|
1620
|
+
waveId: null,
|
|
1621
|
+
retryAfterFix: null,
|
|
1622
|
+
retryAfterFixStepIndex: null,
|
|
1623
|
+
});
|
|
1624
|
+
out(block);
|
|
1625
|
+
process.exit(0);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
function recordAllowedDebugRetries(agents) {
|
|
1629
|
+
if (!implementationRailApplies(readPipelineRecord())) return;
|
|
1630
|
+
const list = Array.isArray(agents) ? agents : [agents];
|
|
1631
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
1632
|
+
if (!implementationDebugRetry(list[index])) continue;
|
|
1633
|
+
appendMetric({
|
|
1634
|
+
type: 'retry_scheduled',
|
|
1635
|
+
at: now,
|
|
1636
|
+
attemptId: null,
|
|
1637
|
+
nextAgent: 'feature-developer',
|
|
1638
|
+
retryAfterFix: 'debugger',
|
|
1639
|
+
source: 'hook',
|
|
1640
|
+
attributionConfidence: 'high',
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
function railInstructionClause(agent) {
|
|
1645
|
+
const decision = implementationHandoffDecision({
|
|
1646
|
+
agent,
|
|
1647
|
+
pipeline: readPipelineRecord(),
|
|
1648
|
+
briefText: readBriefText(),
|
|
1649
|
+
debugRetry: false,
|
|
1650
|
+
debugRetryCount: 0,
|
|
1651
|
+
});
|
|
1652
|
+
if (decision.rail !== 'on' || !decision.start) return '';
|
|
1653
|
+
return railOnHandoffClause();
|
|
739
1654
|
}
|
|
740
1655
|
|
|
741
1656
|
function handoffForAgent(agent, scope, step = null) {
|
|
742
1657
|
const fn = AGENT_HANDOFF[agent];
|
|
743
1658
|
const handoff = fn ? fn(slug, scope) : `Invoke ${agent} subagent for slug "${slug}". Upsert the owned terminal receipt in artifact-manifest.json; do not mutate status.json lifecycle fields.`;
|
|
744
|
-
return handoff + artifactHandoff(step, agent) + metricsHandoff(agent);
|
|
1659
|
+
return handoff + railInstructionClause(agent) + artifactHandoff(step, agent) + metricsHandoff(agent) + decompositionReadyClause(step ? [step] : []);
|
|
745
1660
|
}
|
|
746
1661
|
|
|
747
1662
|
function handoffForParallelStep(step) {
|
|
@@ -753,7 +1668,8 @@ function handoffForParallelStep(step) {
|
|
|
753
1668
|
`Invoke IN PARALLEL (one message, multiple Task calls): ${agents.join(' AND ')} for slug "${slug}". ` +
|
|
754
1669
|
`Each agent writes its artifact and owned receipt; the hook records parallelCompleted from stops. Do not mutate status.json lifecycle fields. ` +
|
|
755
1670
|
`Artifact inputs: ${Array.isArray(step.artifactInputIds) ? step.artifactInputIds.join(', ') : 'manifest defaults'}; owned output IDs: ${agents.map((agent) => `${agent}=${artifactOutputIdFor(step, agent)}`).join('; ')}. ` +
|
|
756
|
-
`Metrics attemptIds: ${attemptIds.join('; ')}. If the hook cannot identify a parallel stop, append a minimal { attemptId, outcome } receipt to .metrics-receipts.json; do not calculate duration
|
|
1671
|
+
`Metrics attemptIds: ${attemptIds.join('; ')}. If the hook cannot identify a parallel stop, append a minimal { attemptId, outcome } receipt to .metrics-receipts.json; do not calculate duration. ${receiptPathClause()}` +
|
|
1672
|
+
decompositionReadyClause([step])
|
|
757
1673
|
);
|
|
758
1674
|
}
|
|
759
1675
|
|
|
@@ -762,9 +1678,35 @@ function hasGateAfter(agent, humanGates) {
|
|
|
762
1678
|
}
|
|
763
1679
|
|
|
764
1680
|
function hasGateAfterStep(step, humanGates) {
|
|
1681
|
+
if (!Array.isArray(humanGates) || !step) return false;
|
|
1682
|
+
if (typeof step.id === 'string' && step.id.length > 0 && humanGates.includes(`after:${step.id}`)) return true;
|
|
765
1683
|
return getStepAgents(step).some((a) => hasGateAfter(a, humanGates));
|
|
766
1684
|
}
|
|
767
1685
|
|
|
1686
|
+
// A followup loop of the subagent that just finished arrives with no attemptId
|
|
1687
|
+
// and no receipt for the attempt this same transition opened. That stop is not
|
|
1688
|
+
// the next agent. A stop more than 15s later, still without a receipt, is a
|
|
1689
|
+
// real missing receipt and must stall.
|
|
1690
|
+
function isSchedulingEcho() {
|
|
1691
|
+
if (typeof hookInput.attemptId === 'string' && hookInput.attemptId.length > 0) return false;
|
|
1692
|
+
const entries = Object.entries(status.activeAttempts || {});
|
|
1693
|
+
if (entries.length !== 1) return false;
|
|
1694
|
+
const [attemptId, entry] = entries[0];
|
|
1695
|
+
const previous = status.lastCompletedAttempt;
|
|
1696
|
+
if (!previous || previous.completedAt !== entry.startedAt) return false;
|
|
1697
|
+
const ageMs = Date.parse(now) - Date.parse(entry.startedAt);
|
|
1698
|
+
if (!Number.isFinite(ageMs) || ageMs < 0 || ageMs > 15000) return false;
|
|
1699
|
+
const previousJoined = Object.values(status.joinedSlots || {}).some((slot) => slot && slot.attemptId === previous.attemptId);
|
|
1700
|
+
const linearAdvance = !isGraphMode() && typeof entry.stepIndex === 'number' && entry.stepIndex > 0;
|
|
1701
|
+
if (!previousJoined && !linearAdvance) return false;
|
|
1702
|
+
try {
|
|
1703
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(taskDir, 'artifact-manifest.json'), 'utf8'));
|
|
1704
|
+
const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
1705
|
+
if (artifacts.some((item) => item && item.receipt && item.receipt.attemptId === attemptId)) return false;
|
|
1706
|
+
} catch {}
|
|
1707
|
+
return true;
|
|
1708
|
+
}
|
|
1709
|
+
|
|
768
1710
|
function legacyFlow() {
|
|
769
1711
|
// <<<hook-slot:LEGACY_FLOW>>>
|
|
770
1712
|
// <<<hook-slot:/LEGACY_FLOW>>>
|
|
@@ -826,6 +1768,8 @@ if (hookInput.action === 'end_human_gate') {
|
|
|
826
1768
|
const resumeNext = findNextExecutableStep(resumeSteps, resumeStart, taskDir);
|
|
827
1769
|
if (resumeNext) {
|
|
828
1770
|
const resumeAgents = getStepAgents(resumeNext.step);
|
|
1771
|
+
refuseImplementationStart(resumeAgents, (agent) => implementationDebugRetry(agent));
|
|
1772
|
+
recordAllowedDebugRetries(resumeAgents);
|
|
829
1773
|
activateAttempts(resumeNext.step, resumeNext.index);
|
|
830
1774
|
writeStatus({
|
|
831
1775
|
pipelineIndex: resumeNext.index,
|
|
@@ -918,6 +1862,10 @@ if (pipelineParseError) {
|
|
|
918
1862
|
}
|
|
919
1863
|
|
|
920
1864
|
steps = pipeline.steps || [];
|
|
1865
|
+
if (isSchedulingEcho()) {
|
|
1866
|
+
process.stdout.write('{}');
|
|
1867
|
+
process.exit(0);
|
|
1868
|
+
}
|
|
921
1869
|
const initialIdx = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
|
|
922
1870
|
const initialStep = steps[initialIdx];
|
|
923
1871
|
const activeAttemptCountBeforeFinish = Object.keys(status.activeAttempts || {}).length;
|
|
@@ -978,6 +1926,9 @@ function nearestPrecedingStepIndex(agent, fromIndex, fallback) {
|
|
|
978
1926
|
return match >= 0 ? match : fallback;
|
|
979
1927
|
}
|
|
980
1928
|
function scheduleRetry(agent, retryAfterFix, predecessor, explicitStepIndex = null) {
|
|
1929
|
+
if (agent === 'feature-developer') {
|
|
1930
|
+
refuseImplementationStart([agent], () => retryAfterFix === 'debugger');
|
|
1931
|
+
}
|
|
981
1932
|
const currentIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
|
|
982
1933
|
const explicitOk = Number.isInteger(explicitStepIndex) && getStepAgents(steps[explicitStepIndex]).includes(agent);
|
|
983
1934
|
const stepIndex = explicitOk ? explicitStepIndex : nearestPrecedingStepIndex(agent, currentIndex, -1);
|
|
@@ -1285,6 +2236,8 @@ if (!next) {
|
|
|
1285
2236
|
const { step: nextStep, index: nextIdx } = next;
|
|
1286
2237
|
const nextAgents = getStepAgents(nextStep);
|
|
1287
2238
|
|
|
2239
|
+
refuseImplementationStart(nextAgents, (agent) => implementationDebugRetry(agent));
|
|
2240
|
+
recordAllowedDebugRetries(nextAgents);
|
|
1288
2241
|
activateAttempts(nextStep, nextIdx);
|
|
1289
2242
|
writeStatus({
|
|
1290
2243
|
pipelineIndex: nextIdx,
|
|
@@ -1313,6 +2266,180 @@ const fs = require('fs');
|
|
|
1313
2266
|
const path = require('path');
|
|
1314
2267
|
const { spawnSync } = require('child_process');
|
|
1315
2268
|
|
|
2269
|
+
// <<<standards-draft>>>
|
|
2270
|
+
// Explicit payload only. This postflight never walks the repo and never
|
|
2271
|
+
// creates `.ai.local/rules/`. The same provenance tag does not rewrite an
|
|
2272
|
+
// accepted Gotchas, Patterns, or Decisions line.
|
|
2273
|
+
function standardsDraftTag(provenance) {
|
|
2274
|
+
return '(`' + provenance + '`)';
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
function standardsDraftLineIndex(content, header) {
|
|
2278
|
+
if (content.startsWith(header) && (content.length === header.length || content.charAt(header.length) === '\n')) return 0;
|
|
2279
|
+
const at = content.indexOf('\n' + header + '\n');
|
|
2280
|
+
if (at !== -1) return at + 1;
|
|
2281
|
+
if (content.endsWith('\n' + header)) return content.length - header.length;
|
|
2282
|
+
return -1;
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
function standardsDraftSection(content, name) {
|
|
2286
|
+
const header = '## ' + name;
|
|
2287
|
+
const start = standardsDraftLineIndex(content, header);
|
|
2288
|
+
if (start === -1) return null;
|
|
2289
|
+
const from = start + header.length;
|
|
2290
|
+
const next = content.indexOf('\n## ', from);
|
|
2291
|
+
const end = next === -1 ? content.length : next;
|
|
2292
|
+
return content.slice(start, end);
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
function standardsDraftProtected(content) {
|
|
2296
|
+
const names = ['Language', 'Gotchas', 'Patterns', 'Decisions', 'Advisory index'];
|
|
2297
|
+
let snapshot = '';
|
|
2298
|
+
for (let index = 0; index < names.length; index += 1) {
|
|
2299
|
+
const body = standardsDraftSection(content, names[index]);
|
|
2300
|
+
snapshot += names[index] + '\n' + (body === null ? '' : body) + '\n';
|
|
2301
|
+
}
|
|
2302
|
+
return snapshot;
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
function standardsDraftNormalize(line) {
|
|
2306
|
+
return line.trim().replace(/\s+/g, ' ').replace(/^-\s+/, '').replace(/\s+\(`[^`]*`\)$/, '').toLowerCase();
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
function standardsDraftAccepted(content, text) {
|
|
2310
|
+
const pending = standardsDraftSection(content, 'Pending');
|
|
2311
|
+
let rest = content;
|
|
2312
|
+
if (pending !== null) {
|
|
2313
|
+
const start = content.indexOf(pending);
|
|
2314
|
+
rest = content.slice(0, start) + content.slice(start + pending.length);
|
|
2315
|
+
}
|
|
2316
|
+
const needle = standardsDraftNormalize(text);
|
|
2317
|
+
if (!needle) return false;
|
|
2318
|
+
const lines = rest.split('\n');
|
|
2319
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
2320
|
+
const line = lines[index];
|
|
2321
|
+
if (!/^-\s+\S/.test(line)) continue;
|
|
2322
|
+
if (standardsDraftNormalize(line) === needle) return true;
|
|
2323
|
+
}
|
|
2324
|
+
return false;
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
function standardsDraftAppendPending(content, line) {
|
|
2328
|
+
const header = '## Pending';
|
|
2329
|
+
const start = standardsDraftLineIndex(content, header);
|
|
2330
|
+
if (start === -1) {
|
|
2331
|
+
const sep = content.endsWith('\n') ? '\n' : '\n\n';
|
|
2332
|
+
return content + sep + header + '\n\n' + line + '\n';
|
|
2333
|
+
}
|
|
2334
|
+
const from = start + header.length;
|
|
2335
|
+
const next = content.indexOf('\n## ', from);
|
|
2336
|
+
const end = next === -1 ? content.length : next;
|
|
2337
|
+
let body = content.slice(from, end);
|
|
2338
|
+
const hasBullet = /(^|\n)-\s+\S/.test(body);
|
|
2339
|
+
if (!hasBullet && /(^|\n)-[ \t]*(?=\n|$)/.test(body)) {
|
|
2340
|
+
body = body.replace(/(^|\n)-[ \t]*(?=\n|$)/, '$1' + line);
|
|
2341
|
+
} else if (body.endsWith('\n\n')) {
|
|
2342
|
+
body = body.slice(0, -1) + line + '\n\n';
|
|
2343
|
+
} else if (body.endsWith('\n')) {
|
|
2344
|
+
body = body + line + '\n';
|
|
2345
|
+
} else {
|
|
2346
|
+
body = body + '\n' + line + '\n';
|
|
2347
|
+
}
|
|
2348
|
+
return content.slice(0, from) + body + content.slice(end);
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
function standardsDraftProvenance(draft) {
|
|
2352
|
+
if (!draft || typeof draft.provenance !== 'string') return '';
|
|
2353
|
+
const provenance = draft.provenance.trim();
|
|
2354
|
+
if (/^incident: [A-Za-z0-9][A-Za-z0-9._:-]{0,80}$/.test(provenance)) return provenance;
|
|
2355
|
+
const read = /^read: ([A-Za-z0-9][A-Za-z0-9._/-]{0,160})$/.exec(provenance);
|
|
2356
|
+
if (!read) return '';
|
|
2357
|
+
const parts = read[1].split('/');
|
|
2358
|
+
if (parts.indexOf('..') !== -1 || parts.indexOf('.') !== -1) return '';
|
|
2359
|
+
if (read[1] === '.ai.local/rules' || read[1].indexOf('.ai.local/rules/') === 0) return '';
|
|
2360
|
+
return provenance;
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
function standardsDraftWrite(target, content) {
|
|
2364
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
2365
|
+
const temporary = target + '.' + String(process.pid) + '.tmp';
|
|
2366
|
+
fs.writeFileSync(temporary, content);
|
|
2367
|
+
fs.renameSync(temporary, target);
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
function appendOptionalStandardsDraft(root, draft) {
|
|
2371
|
+
const provenance = standardsDraftProvenance(draft);
|
|
2372
|
+
if (!provenance) return { wrote: false, reason: 'provenance' };
|
|
2373
|
+
const text = draft && typeof draft.text === 'string' ? draft.text.trim() : '';
|
|
2374
|
+
if (!text || text.length > 400 || text.indexOf('\n') !== -1 || text.indexOf('\r') !== -1 || text.indexOf('## ') !== -1) {
|
|
2375
|
+
return { wrote: false, reason: 'text' };
|
|
2376
|
+
}
|
|
2377
|
+
let destination = 'conventions';
|
|
2378
|
+
if (draft.destination != null) {
|
|
2379
|
+
if (draft.destination === 'conventions' || draft.destination === 'rules-library') destination = draft.destination;
|
|
2380
|
+
else return { wrote: false, reason: 'destination' };
|
|
2381
|
+
}
|
|
2382
|
+
const line = '- ' + text + ' ' + standardsDraftTag(provenance);
|
|
2383
|
+
const overlay = path.join(root, '.ai.local');
|
|
2384
|
+
const rulesDir = path.join(overlay, 'rules');
|
|
2385
|
+
const rulesPrefix = rulesDir + path.sep;
|
|
2386
|
+
|
|
2387
|
+
if (destination === 'rules-library') {
|
|
2388
|
+
const stem = draft && typeof draft.stem === 'string' ? draft.stem : '';
|
|
2389
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+){0,8}$/.test(stem) || stem.length > 48) {
|
|
2390
|
+
return { wrote: false, reason: 'stem' };
|
|
2391
|
+
}
|
|
2392
|
+
const libraryDir = path.join(overlay, 'rules-library');
|
|
2393
|
+
const target = path.join(libraryDir, stem + '.md');
|
|
2394
|
+
const libraryPrefix = libraryDir + path.sep;
|
|
2395
|
+
if (!target.startsWith(libraryPrefix)) return { wrote: false, reason: 'path' };
|
|
2396
|
+
if (target === rulesDir || target.startsWith(rulesPrefix)) return { wrote: false, reason: 'rules' };
|
|
2397
|
+
let existing = null;
|
|
2398
|
+
try {
|
|
2399
|
+
existing = fs.readFileSync(target, 'utf8');
|
|
2400
|
+
} catch (error) {
|
|
2401
|
+
if (!error || error.code !== 'ENOENT') throw error;
|
|
2402
|
+
}
|
|
2403
|
+
if (existing !== null) {
|
|
2404
|
+
if (existing.indexOf(standardsDraftTag(provenance)) !== -1) {
|
|
2405
|
+
return { wrote: false, reason: 'same-provenance', target: target };
|
|
2406
|
+
}
|
|
2407
|
+
const prefix = existing.endsWith('\n') ? '' : '\n';
|
|
2408
|
+
fs.appendFileSync(target, prefix + line + '\n');
|
|
2409
|
+
return { wrote: true, target: target, mode: 'append-provenance' };
|
|
2410
|
+
}
|
|
2411
|
+
standardsDraftWrite(target, '# ' + stem + '\n\nPending draft. Inactive until a human moves this file into `.ai.local/rules/`.\n\n' + line + '\n');
|
|
2412
|
+
return { wrote: true, target: target, mode: 'create' };
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
const conventionsPath = path.join(overlay, 'conventions.md');
|
|
2416
|
+
if (conventionsPath === rulesDir || conventionsPath.startsWith(rulesPrefix)) {
|
|
2417
|
+
return { wrote: false, reason: 'rules' };
|
|
2418
|
+
}
|
|
2419
|
+
let content = null;
|
|
2420
|
+
try {
|
|
2421
|
+
content = fs.readFileSync(conventionsPath, 'utf8');
|
|
2422
|
+
} catch (error) {
|
|
2423
|
+
if (!error || error.code !== 'ENOENT') throw error;
|
|
2424
|
+
}
|
|
2425
|
+
if (content === null) content = '# Living conventions\n';
|
|
2426
|
+
if (content.indexOf(standardsDraftTag(provenance)) !== -1) {
|
|
2427
|
+
return { wrote: false, reason: 'same-provenance', target: conventionsPath };
|
|
2428
|
+
}
|
|
2429
|
+
const before = standardsDraftProtected(content);
|
|
2430
|
+
const next = standardsDraftAppendPending(content, line);
|
|
2431
|
+
if (standardsDraftProtected(next) !== before) {
|
|
2432
|
+
return { wrote: false, reason: 'protected', target: conventionsPath };
|
|
2433
|
+
}
|
|
2434
|
+
standardsDraftWrite(conventionsPath, next);
|
|
2435
|
+
return {
|
|
2436
|
+
wrote: true,
|
|
2437
|
+
target: conventionsPath,
|
|
2438
|
+
mode: standardsDraftAccepted(content, text) ? 'provenance-only' : 'pending',
|
|
2439
|
+
};
|
|
2440
|
+
}
|
|
2441
|
+
// <<<standards-draft-end>>>
|
|
2442
|
+
|
|
1316
2443
|
let input;
|
|
1317
2444
|
try {
|
|
1318
2445
|
input = JSON.parse(process.env.INPUT || '');
|
|
@@ -1345,6 +2472,12 @@ if (pipeline && (pipeline.profile === 'light' || pipeline.intent === 'spike')) {
|
|
|
1345
2472
|
process.exit(0);
|
|
1346
2473
|
}
|
|
1347
2474
|
|
|
2475
|
+
try {
|
|
2476
|
+
appendOptionalStandardsDraft(process.cwd(), input.standardsDraft);
|
|
2477
|
+
} catch {
|
|
2478
|
+
// A draft failure must not fail the stop, and must not add a WARNING.
|
|
2479
|
+
}
|
|
2480
|
+
|
|
1348
2481
|
if (!fs.existsSync(path.join(process.cwd(), '.ai.local', 'scripts', 'run.mjs'))) {
|
|
1349
2482
|
process.stderr.write(
|
|
1350
2483
|
'WARNING: self-learning loop skipped: .ai.local/scripts/run.mjs is missing (install it with `npx @bonesofspring/ai-rules init <tool> --preset <stack>`)\n',
|