@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
|
@@ -278,10 +278,429 @@ function writeSkeletonManifest(manifestPath) {
|
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
+
function normalizeRepoPath(value) {
|
|
282
|
+
let text = typeof value === 'string' ? value.trim() : '';
|
|
283
|
+
text = text.replace(/\\/g, '/');
|
|
284
|
+
while (text.startsWith('./')) text = text.slice(2);
|
|
285
|
+
if (!text || text === '—' || text === '-' || text === '–') return '';
|
|
286
|
+
if (/[\s()]/.test(text)) return '';
|
|
287
|
+
return text;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function isAppPath(file) {
|
|
291
|
+
const normalized = normalizeRepoPath(file);
|
|
292
|
+
return normalized === 'app' || normalized.startsWith('app/') || normalized.startsWith('app/**') || normalized.startsWith('app/*');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function isSpecFolderPath(file) {
|
|
296
|
+
const normalized = normalizeRepoPath(file);
|
|
297
|
+
return normalized.startsWith('docs/specs/') || normalized.startsWith('docs/specs/**') || normalized.startsWith('openspec/') || normalized.startsWith('openspec/**');
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function listsBothSpecAndApp(files) {
|
|
301
|
+
let app = false;
|
|
302
|
+
let spec = false;
|
|
303
|
+
for (const file of files || []) {
|
|
304
|
+
if (isAppPath(file)) app = true;
|
|
305
|
+
if (isSpecFolderPath(file)) spec = true;
|
|
306
|
+
}
|
|
307
|
+
return app && spec;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function pathInWriteScopes(file, writeScopes) {
|
|
311
|
+
const target = normalizeRepoPath(file);
|
|
312
|
+
if (!target) return false;
|
|
313
|
+
const scopes = Array.isArray(writeScopes) ? writeScopes : [];
|
|
314
|
+
for (const scope of scopes) {
|
|
315
|
+
const normalized = normalizeRepoPath(scope);
|
|
316
|
+
if (!normalized) continue;
|
|
317
|
+
if (normalized === target) return true;
|
|
318
|
+
if (normalized.endsWith('/**')) {
|
|
319
|
+
const prefix = normalized.slice(0, -3);
|
|
320
|
+
if (target === prefix || target.startsWith(prefix + '/')) return true;
|
|
321
|
+
} else if (normalized.endsWith('/*')) {
|
|
322
|
+
const prefix = normalized.slice(0, -2);
|
|
323
|
+
const rest = target.startsWith(prefix + '/') ? target.slice(prefix.length + 1) : '';
|
|
324
|
+
if (rest && !rest.includes('/')) return true;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function taskFileSet(task) {
|
|
331
|
+
const all = []
|
|
332
|
+
.concat((task && task.files) || [], (task && task.specFiles) || [], (task && task.appFiles) || [])
|
|
333
|
+
.map((file) => normalizeRepoPath(file))
|
|
334
|
+
.filter(Boolean);
|
|
335
|
+
return new Set(all);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function taskReaches(tasks, startId, targetId) {
|
|
339
|
+
const byId = new Map(tasks.map((task) => [String(task.id), task]));
|
|
340
|
+
const seen = new Set();
|
|
341
|
+
const stack = [String(startId)];
|
|
342
|
+
while (stack.length > 0) {
|
|
343
|
+
const id = stack.pop();
|
|
344
|
+
if (seen.has(id)) continue;
|
|
345
|
+
seen.add(id);
|
|
346
|
+
const task = byId.get(id);
|
|
347
|
+
const deps = task && Array.isArray(task.dependsOn) ? task.dependsOn : [];
|
|
348
|
+
for (const dep of deps) {
|
|
349
|
+
if (String(dep) === String(targetId)) return true;
|
|
350
|
+
stack.push(String(dep));
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function tasksAreOrdered(tasks, left, right) {
|
|
357
|
+
return taskReaches(tasks, left.id, right.id) || taskReaches(tasks, right.id, left.id);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function validateTaskFileLists(tasks, writeScopes) {
|
|
361
|
+
const list = Array.isArray(tasks) ? tasks : [];
|
|
362
|
+
const scopes = Array.isArray(writeScopes) ? writeScopes : [];
|
|
363
|
+
for (const task of list) {
|
|
364
|
+
const id = task && task.id ? task.id : '(unnamed)';
|
|
365
|
+
const files = (task && task.files) || [];
|
|
366
|
+
if (listsBothSpecAndApp(files)) {
|
|
367
|
+
return 'task "' + id + '" lists spec-folder paths and app/** paths in one file list; they are different lists';
|
|
368
|
+
}
|
|
369
|
+
if (scopes.length === 0) continue;
|
|
370
|
+
const combined = files.concat((task && task.specFiles) || [], (task && task.appFiles) || []);
|
|
371
|
+
for (const file of combined) {
|
|
372
|
+
if (!pathInWriteScopes(file, scopes)) {
|
|
373
|
+
const label = normalizeRepoPath(file) || file;
|
|
374
|
+
return 'task "' + id + '" file "' + label + '" is outside the implementing step writeScopes';
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
for (let i = 0; i < list.length; i += 1) {
|
|
379
|
+
for (let j = i + 1; j < list.length; j += 1) {
|
|
380
|
+
if (tasksAreOrdered(list, list[i], list[j])) continue;
|
|
381
|
+
const left = taskFileSet(list[i]);
|
|
382
|
+
let shared = '';
|
|
383
|
+
for (const file of taskFileSet(list[j])) {
|
|
384
|
+
if (left.has(file)) {
|
|
385
|
+
shared = file;
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (shared) return 'parallel tasks "' + list[i].id + '" and "' + list[j].id + '" share "' + shared + '"';
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function productionPathsOutsideTaskList(paths, tasks) {
|
|
396
|
+
const allowed = new Set();
|
|
397
|
+
for (const task of tasks || []) {
|
|
398
|
+
for (const file of taskFileSet(task)) allowed.add(file);
|
|
399
|
+
}
|
|
400
|
+
const outside = [];
|
|
401
|
+
for (const cited of paths || []) {
|
|
402
|
+
const normalized = normalizeRepoPath(cited);
|
|
403
|
+
if (normalized && !allowed.has(normalized)) outside.push(normalized);
|
|
404
|
+
}
|
|
405
|
+
return outside;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function splitMarkdownCells(line) {
|
|
409
|
+
const trimmed = String(line || '').trim();
|
|
410
|
+
if (!trimmed.startsWith('|')) return [];
|
|
411
|
+
const cells = trimmed.split('|').map((cell) => cell.trim());
|
|
412
|
+
if (cells.length && cells[0] === '') cells.shift();
|
|
413
|
+
if (cells.length && cells[cells.length - 1] === '') cells.pop();
|
|
414
|
+
return cells;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function isSeparatorRow(cells) {
|
|
418
|
+
return cells.length > 0 && cells.every((cell) => /^:?-{3,}:?$/.test(cell));
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function pathsFromCell(cell) {
|
|
422
|
+
const text = String(cell || '');
|
|
423
|
+
const found = [];
|
|
424
|
+
const pattern = /`([^`]+)`/g;
|
|
425
|
+
let match = pattern.exec(text);
|
|
426
|
+
while (match) {
|
|
427
|
+
const normalized = normalizeRepoPath(match[1]);
|
|
428
|
+
if (normalized && normalized.includes('/')) found.push(normalized);
|
|
429
|
+
match = pattern.exec(text);
|
|
430
|
+
}
|
|
431
|
+
if (found.length > 0) return found;
|
|
432
|
+
return text.split(',').map((part) => normalizeRepoPath(part)).filter((part) => part.includes('/'));
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function dependsFromCell(cell) {
|
|
436
|
+
const cleaned = String(cell || '').replace(/[`*]/g, '').trim();
|
|
437
|
+
if (!cleaned || cleaned === '—' || cleaned === '-' || cleaned === '–') return [];
|
|
438
|
+
return cleaned.split(/[,|/]/).map((part) => part.trim()).filter((part) => /^[A-Za-z][A-Za-z0-9._-]*$/.test(part));
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function cellIsComplete(cell) {
|
|
442
|
+
const cleaned = String(cell || '').replace(/[`*[\]]/g, '').trim().toLowerCase();
|
|
443
|
+
return cleaned === 'complete' || cleaned === 'completed' || cleaned === 'done' || cleaned === 'x';
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function absorbMarkdownTable(block, byId) {
|
|
447
|
+
const rows = [];
|
|
448
|
+
for (const line of block) {
|
|
449
|
+
const cells = splitMarkdownCells(line);
|
|
450
|
+
if (cells.length === 0 || isSeparatorRow(cells)) continue;
|
|
451
|
+
rows.push(cells);
|
|
452
|
+
}
|
|
453
|
+
if (rows.length < 2) return false;
|
|
454
|
+
const headers = rows[0].map((cell) => cell.replace(/[`*]/g, '').trim());
|
|
455
|
+
const idIndex = headers.findIndex((header) => /^id$/i.test(header));
|
|
456
|
+
if (idIndex < 0) return false;
|
|
457
|
+
const dependsIndex = headers.findIndex((header) => /dependson/i.test(header));
|
|
458
|
+
const specIndex = headers.findIndex((header) => /spec files/i.test(header));
|
|
459
|
+
const appIndex = headers.findIndex((header) => /^app files$/i.test(header));
|
|
460
|
+
const filesIndex = headers.findIndex((header, index) => index !== specIndex && index !== appIndex && /files|paths/i.test(header));
|
|
461
|
+
const statusIndex = headers.findIndex((header) => /^(status|done|state)$/i.test(header));
|
|
462
|
+
const sawFiles = specIndex >= 0 || appIndex >= 0 || filesIndex >= 0;
|
|
463
|
+
for (const cells of rows.slice(1)) {
|
|
464
|
+
const id = String(cells[idIndex] || '').replace(/[`*]/g, '').trim();
|
|
465
|
+
if (!id || /^id$/i.test(id)) continue;
|
|
466
|
+
const task = byId.get(id) || { id, dependsOn: [], files: [], specFiles: [], appFiles: [], tracked: false, rowComplete: false };
|
|
467
|
+
if (dependsIndex >= 0) {
|
|
468
|
+
task.dependsOn = dependsFromCell(cells[dependsIndex] || '');
|
|
469
|
+
task.tracked = true;
|
|
470
|
+
}
|
|
471
|
+
if (statusIndex >= 0) task.rowComplete = cellIsComplete(cells[statusIndex] || '');
|
|
472
|
+
if (filesIndex >= 0) {
|
|
473
|
+
const parsed = pathsFromCell(cells[filesIndex] || '');
|
|
474
|
+
if (parsed.length > 0) task.files = parsed;
|
|
475
|
+
}
|
|
476
|
+
if (specIndex >= 0) {
|
|
477
|
+
const parsed = pathsFromCell(cells[specIndex] || '');
|
|
478
|
+
if (parsed.length > 0) task.specFiles = parsed;
|
|
479
|
+
}
|
|
480
|
+
if (appIndex >= 0) {
|
|
481
|
+
const parsed = pathsFromCell(cells[appIndex] || '');
|
|
482
|
+
if (parsed.length > 0) task.appFiles = parsed;
|
|
483
|
+
}
|
|
484
|
+
byId.set(id, task);
|
|
485
|
+
}
|
|
486
|
+
return sawFiles;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function parseDecompositionTaskFileLists(markdown) {
|
|
490
|
+
const lines = String(markdown || '').split(/\r?\n/);
|
|
491
|
+
const byId = new Map();
|
|
492
|
+
let hasFileColumn = false;
|
|
493
|
+
let index = 0;
|
|
494
|
+
while (index < lines.length) {
|
|
495
|
+
if (!String(lines[index] || '').trim().startsWith('|')) {
|
|
496
|
+
index += 1;
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
const block = [];
|
|
500
|
+
while (index < lines.length && String(lines[index] || '').trim().startsWith('|')) {
|
|
501
|
+
block.push(lines[index]);
|
|
502
|
+
index += 1;
|
|
503
|
+
}
|
|
504
|
+
if (absorbMarkdownTable(block, byId)) hasFileColumn = true;
|
|
505
|
+
}
|
|
506
|
+
return { tasks: [...byId.values()], hasFileColumn };
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function parseDecompositionTasks(markdown) {
|
|
510
|
+
const lines = String(markdown || '').split(/\r?\n/);
|
|
511
|
+
const byId = new Map();
|
|
512
|
+
let index = 0;
|
|
513
|
+
while (index < lines.length) {
|
|
514
|
+
if (!String(lines[index] || '').trim().startsWith('|')) {
|
|
515
|
+
index += 1;
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
const block = [];
|
|
519
|
+
while (index < lines.length && String(lines[index] || '').trim().startsWith('|')) {
|
|
520
|
+
block.push(lines[index]);
|
|
521
|
+
index += 1;
|
|
522
|
+
}
|
|
523
|
+
absorbMarkdownTable(block, byId);
|
|
524
|
+
}
|
|
525
|
+
return [...byId.values()].filter((task) => task.tracked === true);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
function taskCoveredByCompletedArtifact(taskId, artifacts) {
|
|
529
|
+
const id = String(taskId);
|
|
530
|
+
const list = Array.isArray(artifacts) ? artifacts : [];
|
|
531
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
532
|
+
const artifact = list[index];
|
|
533
|
+
if (!artifact || artifact.status !== 'completed') continue;
|
|
534
|
+
if (String(artifact.id) === id) return true;
|
|
535
|
+
const taskIds = Array.isArray(artifact.taskIds) ? artifact.taskIds : [];
|
|
536
|
+
for (let taskIndex = 0; taskIndex < taskIds.length; taskIndex += 1) {
|
|
537
|
+
if (String(taskIds[taskIndex]) === id) return true;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return false;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function computeDecompositionReadySet(tasks, artifacts) {
|
|
544
|
+
const list = (Array.isArray(tasks) ? tasks : []).filter((task) => task && task.id && task.tracked !== false);
|
|
545
|
+
const complete = new Set();
|
|
546
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
547
|
+
const task = list[index];
|
|
548
|
+
if (task.rowComplete === true || taskCoveredByCompletedArtifact(task.id, artifacts)) complete.add(String(task.id));
|
|
549
|
+
}
|
|
550
|
+
const ready = [];
|
|
551
|
+
const blocked = [];
|
|
552
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
553
|
+
const task = list[index];
|
|
554
|
+
const id = String(task.id);
|
|
555
|
+
if (complete.has(id)) continue;
|
|
556
|
+
const deps = Array.isArray(task.dependsOn) ? task.dependsOn.map((dep) => String(dep)) : [];
|
|
557
|
+
const waiting = [];
|
|
558
|
+
const seen = new Set();
|
|
559
|
+
for (let depIndex = 0; depIndex < deps.length; depIndex += 1) {
|
|
560
|
+
const dep = deps[depIndex];
|
|
561
|
+
if (!dep || seen.has(dep) || complete.has(dep)) continue;
|
|
562
|
+
seen.add(dep);
|
|
563
|
+
waiting.push(dep);
|
|
564
|
+
}
|
|
565
|
+
if (waiting.length === 0) ready.push(id);
|
|
566
|
+
else blocked.push({ id, waiting_on: waiting });
|
|
567
|
+
}
|
|
568
|
+
return { ready, blocked };
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
function readManifestArtifacts(dir) {
|
|
572
|
+
try {
|
|
573
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'artifact-manifest.json'), 'utf8'));
|
|
574
|
+
return Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
575
|
+
} catch {
|
|
576
|
+
return [];
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function readDecompositionReadySet(dir) {
|
|
581
|
+
let markdown = '';
|
|
582
|
+
try {
|
|
583
|
+
markdown = fs.readFileSync(path.join(dir, 'decomposition.md'), 'utf8');
|
|
584
|
+
} catch {
|
|
585
|
+
markdown = '';
|
|
586
|
+
}
|
|
587
|
+
return computeDecompositionReadySet(parseDecompositionTasks(markdown), readManifestArtifacts(dir));
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function formatDecompositionReadyClause(report, stepsForRows) {
|
|
591
|
+
const source = report && typeof report === 'object' ? report : { ready: [], blocked: [] };
|
|
592
|
+
const stepList = Array.isArray(stepsForRows) ? stepsForRows : [];
|
|
593
|
+
const allow = [];
|
|
594
|
+
for (let index = 0; index < stepList.length; index += 1) {
|
|
595
|
+
const taskIds = stepList[index] && stepList[index].taskIds;
|
|
596
|
+
if (!Array.isArray(taskIds)) continue;
|
|
597
|
+
for (let idIndex = 0; idIndex < taskIds.length; idIndex += 1) {
|
|
598
|
+
if (taskIds[idIndex] != null && String(taskIds[idIndex])) allow.push(String(taskIds[idIndex]));
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
const gate = allow.length > 0 ? new Set(allow) : null;
|
|
602
|
+
const ready = (Array.isArray(source.ready) ? source.ready : []).filter((id) => !gate || gate.has(String(id)));
|
|
603
|
+
const blocked = (Array.isArray(source.blocked) ? source.blocked : []).filter((row) => row && (!gate || gate.has(String(row.id))));
|
|
604
|
+
const readyText = ready.length > 0 ? ready.join(', ') : '(none)';
|
|
605
|
+
let text = ' Decomposition ready set: ' + readyText + '.';
|
|
606
|
+
if (blocked.length > 0) {
|
|
607
|
+
const parts = [];
|
|
608
|
+
for (let index = 0; index < blocked.length; index += 1) {
|
|
609
|
+
const row = blocked[index];
|
|
610
|
+
const waiting = Array.isArray(row.waiting_on) ? row.waiting_on.join(', ') : '';
|
|
611
|
+
parts.push(String(row.id) + ' waiting_on ' + waiting);
|
|
612
|
+
}
|
|
613
|
+
text += ' Blocked: ' + parts.join('; ') + '.';
|
|
614
|
+
}
|
|
615
|
+
return text;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function decompositionReadyClause(stepsForRows) {
|
|
619
|
+
try {
|
|
620
|
+
return formatDecompositionReadyClause(readDecompositionReadySet(taskDir), stepsForRows);
|
|
621
|
+
} catch {
|
|
622
|
+
return ' Decomposition ready set: (none).';
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
function productionCitationRepoPath(cited) {
|
|
627
|
+
const value = typeof cited === 'string' ? cited.trim() : '';
|
|
628
|
+
if (!value) return null;
|
|
629
|
+
const normalized = value.replace(/\\/g, '/');
|
|
630
|
+
if (path.isAbsolute(normalized)) {
|
|
631
|
+
const fromCwd = path.relative(process.cwd(), normalized);
|
|
632
|
+
if (fromCwd && !fromCwd.startsWith('..') && !path.isAbsolute(fromCwd)) return normalizeRepoPath(fromCwd);
|
|
633
|
+
return normalizeRepoPath(normalized) || normalized;
|
|
634
|
+
}
|
|
635
|
+
const taskResolved = path.resolve(taskDir, normalized);
|
|
636
|
+
const taskRelative = path.relative(taskDir, taskResolved);
|
|
637
|
+
const insideTask = taskRelative !== '' && taskRelative !== '..' && !taskRelative.startsWith('..' + path.sep) && !path.isAbsolute(taskRelative);
|
|
638
|
+
if (insideTask) {
|
|
639
|
+
try {
|
|
640
|
+
if (fs.statSync(taskResolved).isFile()) return null;
|
|
641
|
+
} catch {}
|
|
642
|
+
}
|
|
643
|
+
return normalizeRepoPath(normalized);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function implementingStepForTaskIds(taskIds) {
|
|
647
|
+
if (!Array.isArray(steps) || taskIds.length === 0) return null;
|
|
648
|
+
return steps.find((step) => Array.isArray(step && step.taskIds) && taskIds.some((id) => step.taskIds.map((item) => String(item)).includes(String(id)))) || null;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
function productionWriteListError(entry) {
|
|
652
|
+
const artifactId = entry && entry.id ? entry.id : '(unnamed)';
|
|
653
|
+
const resume = 'Then resume with: /task-continue ' + slug;
|
|
654
|
+
const fail = (detail) => '[chain-team-phases] ' + slug + ': receipt "' + artifactId + '" ' + detail + ' ' + resume;
|
|
655
|
+
try {
|
|
656
|
+
const evidence = entry && Array.isArray(entry.evidencePaths) ? entry.evidencePaths : [];
|
|
657
|
+
const production = [];
|
|
658
|
+
for (const cited of evidence) {
|
|
659
|
+
const repoPath = productionCitationRepoPath(cited);
|
|
660
|
+
if (repoPath) production.push(repoPath);
|
|
661
|
+
}
|
|
662
|
+
if (production.length === 0) return null;
|
|
663
|
+
let markdown = '';
|
|
664
|
+
try {
|
|
665
|
+
markdown = fs.readFileSync(path.join(taskDir, 'decomposition.md'), 'utf8');
|
|
666
|
+
} catch {
|
|
667
|
+
markdown = '';
|
|
668
|
+
}
|
|
669
|
+
const parsed = parseDecompositionTaskFileLists(markdown);
|
|
670
|
+
if (!parsed.hasFileColumn) return null;
|
|
671
|
+
const tasks = parsed.tasks;
|
|
672
|
+
const taskIds = Array.isArray(entry && entry.taskIds) ? entry.taskIds.map((id) => String(id)) : [];
|
|
673
|
+
const step = implementingStepForTaskIds(taskIds);
|
|
674
|
+
const selectedIds = new Set(taskIds);
|
|
675
|
+
if (step && Array.isArray(step.taskIds)) {
|
|
676
|
+
for (const id of step.taskIds) selectedIds.add(String(id));
|
|
677
|
+
}
|
|
678
|
+
const selected = tasks.filter((task) => selectedIds.has(String(task.id)));
|
|
679
|
+
if (selected.length === 0) {
|
|
680
|
+
return fail('cites production paths but decomposition.md has no file list for ' + (taskIds.join(', ') || '(none)') + '. Record the task file list.');
|
|
681
|
+
}
|
|
682
|
+
const writeScopes = step && Array.isArray(step.writeScopes) ? step.writeScopes : [];
|
|
683
|
+
const listError = validateTaskFileLists(selected, writeScopes);
|
|
684
|
+
if (listError) return fail(listError + '.');
|
|
685
|
+
const owned = selected.filter((task) => taskIds.includes(String(task.id)));
|
|
686
|
+
const citedAgainst = owned.length > 0 ? owned : selected;
|
|
687
|
+
const outside = productionPathsOutsideTaskList(production, citedAgainst);
|
|
688
|
+
if (outside.length > 0) {
|
|
689
|
+
const ids = taskIds.length > 0 ? taskIds.join(', ') : citedAgainst.map((task) => task.id).join(', ');
|
|
690
|
+
return fail('cites production path "' + outside[0] + '", which is not on the decomposition file list for ' + ids + '.');
|
|
691
|
+
}
|
|
692
|
+
return null;
|
|
693
|
+
} catch (error) {
|
|
694
|
+
return fail('production file-list check failed (' + (error && error.message ? error.message : error) + ').');
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
281
698
|
// A2: a `completed` receipt must cite evidence the harness can inspect. Order is
|
|
282
699
|
// the message order — the first failing predicate wins, so the operator sees one
|
|
283
700
|
// actionable line. `authoritativePaths[]` stays task-dir-relative; external
|
|
284
|
-
// references belong in `evidencePaths[]`.
|
|
701
|
+
// references belong in `evidencePaths[]`. The task-folder checks below stay in
|
|
702
|
+
// place. A later production evidencePaths check uses the decomposition file list
|
|
703
|
+
// only when that list column exists.
|
|
285
704
|
function validateCompletedArtifact(entry) {
|
|
286
705
|
const artifactId = entry && entry.id ? entry.id : '(unnamed)';
|
|
287
706
|
const entryStatus = entry && entry.status;
|
|
@@ -313,6 +732,8 @@ function validateCompletedArtifact(entry) {
|
|
|
313
732
|
}
|
|
314
733
|
}
|
|
315
734
|
}
|
|
735
|
+
const productionListError = productionWriteListError(entry);
|
|
736
|
+
if (productionListError) return productionListError;
|
|
316
737
|
return null;
|
|
317
738
|
}
|
|
318
739
|
|
|
@@ -458,7 +879,21 @@ function endHumanGateIfResumed() {
|
|
|
458
879
|
appendMetric({ type: 'human_gate_ended', at: now, gateStartedEventId: status.activeHumanGateEventId, source: 'hook', attributionConfidence: 'high' });
|
|
459
880
|
delete status.activeHumanGateEventId;
|
|
460
881
|
}
|
|
461
|
-
function completeTaskMetrics() {
|
|
882
|
+
function completeTaskMetrics() {
|
|
883
|
+
// Two hook processes can both enter completion before either writes the
|
|
884
|
+
// event. The metrics lock serializes them; the second sees the first write.
|
|
885
|
+
mutateMetrics((metrics) => {
|
|
886
|
+
if (metrics.events.some((event) => event && event.type === 'task_completed')) return;
|
|
887
|
+
metrics.events.push({
|
|
888
|
+
eventId: `${metrics.task.runId}:${Date.now()}:${Math.random().toString(16).slice(2)}`,
|
|
889
|
+
type: 'task_completed',
|
|
890
|
+
at: now,
|
|
891
|
+
outcome: status.state === 'completed' ? 'completed' : 'unknown',
|
|
892
|
+
source: 'hook',
|
|
893
|
+
attributionConfidence: 'high',
|
|
894
|
+
});
|
|
895
|
+
});
|
|
896
|
+
}
|
|
462
897
|
function recordSkippedStep(step, stepIndex) {
|
|
463
898
|
for (const agent of getStepAgents(step)) {
|
|
464
899
|
const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
@@ -468,6 +903,309 @@ function recordSkippedStep(step, stepIndex) {
|
|
|
468
903
|
}
|
|
469
904
|
}
|
|
470
905
|
|
|
906
|
+
// Living task files and the hook ledger stay put. A completed entry's other markdown is the body that leaves the default read.
|
|
907
|
+
const CLOSED_BODY_KEEP = new Set([
|
|
908
|
+
'brief.md',
|
|
909
|
+
'decomposition.md',
|
|
910
|
+
'goal.md',
|
|
911
|
+
'prompt.md',
|
|
912
|
+
'prompt-log.md',
|
|
913
|
+
'pipeline.json',
|
|
914
|
+
'implementation.md',
|
|
915
|
+
'.memlog.md',
|
|
916
|
+
'focus.md',
|
|
917
|
+
'status.json',
|
|
918
|
+
'metrics.json',
|
|
919
|
+
'artifact-manifest.json',
|
|
920
|
+
'overlay-scope.json',
|
|
921
|
+
]);
|
|
922
|
+
|
|
923
|
+
function closedMarkdownBody(dir, cited) {
|
|
924
|
+
if (typeof cited !== 'string') return null;
|
|
925
|
+
const value = cited.trim();
|
|
926
|
+
if (!value || path.isAbsolute(value)) return null;
|
|
927
|
+
const resolved = path.resolve(dir, value);
|
|
928
|
+
const relative = path.relative(dir, resolved);
|
|
929
|
+
if (!relative || relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)) return null;
|
|
930
|
+
const normalized = relative.split(path.sep).join('/');
|
|
931
|
+
if (!/\.md$/i.test(normalized) || normalized.startsWith('archive/')) return null;
|
|
932
|
+
const base = normalized.slice(normalized.lastIndexOf('/') + 1);
|
|
933
|
+
if (CLOSED_BODY_KEEP.has(base) || CLOSED_BODY_KEEP.has(normalized)) return null;
|
|
934
|
+
return { resolved, base };
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
function archiveClosedBody(dir, date, id, body) {
|
|
938
|
+
const archiveDir = path.join(dir, 'archive', date);
|
|
939
|
+
fs.mkdirSync(archiveDir, { recursive: true });
|
|
940
|
+
let name = body.base;
|
|
941
|
+
let destination = path.join(archiveDir, name);
|
|
942
|
+
if (fs.existsSync(destination)) {
|
|
943
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(id)) return null;
|
|
944
|
+
name = id + '--' + body.base;
|
|
945
|
+
destination = path.join(archiveDir, name);
|
|
946
|
+
}
|
|
947
|
+
if (fs.existsSync(destination)) return null;
|
|
948
|
+
fs.renameSync(body.resolved, destination);
|
|
949
|
+
return 'archive/' + date + '/' + name;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function appendMemlogEvent(dir, text) {
|
|
953
|
+
const memlogPath = path.join(dir, '.memlog.md');
|
|
954
|
+
const line = '- `event`: ' + text + '\n';
|
|
955
|
+
let existing = '';
|
|
956
|
+
try { existing = fs.readFileSync(memlogPath, 'utf8'); } catch { existing = ''; }
|
|
957
|
+
if (existing.includes(text)) return existing;
|
|
958
|
+
const prefix = existing.length > 0 && !existing.endsWith('\n') ? '\n' : '';
|
|
959
|
+
fs.appendFileSync(memlogPath, prefix + line);
|
|
960
|
+
return existing + prefix + line;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
function writeJsonFile(filePath, value) {
|
|
964
|
+
const temporary = filePath + '.' + String(process.pid) + '.tmp';
|
|
965
|
+
const fd = fs.openSync(temporary, 'w');
|
|
966
|
+
try {
|
|
967
|
+
fs.writeSync(fd, JSON.stringify(value, null, 2) + '\n');
|
|
968
|
+
} finally {
|
|
969
|
+
fs.closeSync(fd);
|
|
970
|
+
}
|
|
971
|
+
fs.renameSync(temporary, filePath);
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
function compactClosedManifestBodies(dir, closedOn) {
|
|
975
|
+
const date = typeof closedOn === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(closedOn)
|
|
976
|
+
? closedOn
|
|
977
|
+
: new Date().toISOString().slice(0, 10);
|
|
978
|
+
const manifestPath = path.join(dir, 'artifact-manifest.json');
|
|
979
|
+
let manifest;
|
|
980
|
+
try {
|
|
981
|
+
manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
982
|
+
} catch {
|
|
983
|
+
return { moved: [] };
|
|
984
|
+
}
|
|
985
|
+
const slugBefore = manifest.slug;
|
|
986
|
+
const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
987
|
+
let memlog = '';
|
|
988
|
+
try { memlog = fs.readFileSync(path.join(dir, '.memlog.md'), 'utf8'); } catch { memlog = ''; }
|
|
989
|
+
let manifestChanged = false;
|
|
990
|
+
const moved = [];
|
|
991
|
+
for (let index = 0; index < artifacts.length; index += 1) {
|
|
992
|
+
const entry = artifacts[index];
|
|
993
|
+
if (!entry || entry.status !== 'completed' || typeof entry.id !== 'string' || !entry.id) continue;
|
|
994
|
+
const marker = 'closed manifest artifact ' + entry.id + ';';
|
|
995
|
+
if (memlog.includes(marker)) continue;
|
|
996
|
+
const cited = Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths.slice() : [];
|
|
997
|
+
const relocated = [];
|
|
998
|
+
for (let pathIndex = 0; pathIndex < cited.length; pathIndex += 1) {
|
|
999
|
+
const body = closedMarkdownBody(dir, cited[pathIndex]);
|
|
1000
|
+
if (!body) continue;
|
|
1001
|
+
let stat = null;
|
|
1002
|
+
try { stat = fs.statSync(body.resolved); } catch { stat = null; }
|
|
1003
|
+
if (!stat || !stat.isFile()) continue;
|
|
1004
|
+
let content = '';
|
|
1005
|
+
try { content = fs.readFileSync(body.resolved, 'utf8'); } catch { content = ''; }
|
|
1006
|
+
if (!/\S/.test(content)) continue;
|
|
1007
|
+
const archived = archiveClosedBody(dir, date, entry.id, body);
|
|
1008
|
+
if (!archived) continue;
|
|
1009
|
+
cited[pathIndex] = archived;
|
|
1010
|
+
relocated.push(archived);
|
|
1011
|
+
moved.push(archived);
|
|
1012
|
+
manifestChanged = true;
|
|
1013
|
+
}
|
|
1014
|
+
if (relocated.length > 0) entry.authoritativePaths = cited;
|
|
1015
|
+
let archiveHint = relocated.length > 0 ? 'archive/' + date + '/' : '';
|
|
1016
|
+
if (!archiveHint) {
|
|
1017
|
+
for (let pathIndex = 0; pathIndex < cited.length; pathIndex += 1) {
|
|
1018
|
+
const value = typeof cited[pathIndex] === 'string' ? cited[pathIndex].trim() : '';
|
|
1019
|
+
const match = /^archive\/\d{4}-\d{2}-\d{2}\//.exec(value);
|
|
1020
|
+
if (match) {
|
|
1021
|
+
archiveHint = match[0];
|
|
1022
|
+
break;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
const text = archiveHint
|
|
1027
|
+
? 'closed manifest artifact ' + entry.id + '; body archived under ' + archiveHint
|
|
1028
|
+
: 'closed manifest artifact ' + entry.id + '; no bulky markdown body moved';
|
|
1029
|
+
memlog = appendMemlogEvent(dir, text);
|
|
1030
|
+
}
|
|
1031
|
+
if (manifest.slug !== slugBefore) manifest.slug = slugBefore;
|
|
1032
|
+
if (manifestChanged) writeJsonFile(manifestPath, manifest);
|
|
1033
|
+
return { moved };
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
function projectResumeArtifact(entry) {
|
|
1037
|
+
if (!entry || typeof entry !== 'object') return entry;
|
|
1038
|
+
if (entry.status !== 'completed') return entry;
|
|
1039
|
+
return {
|
|
1040
|
+
id: entry.id,
|
|
1041
|
+
status: entry.status,
|
|
1042
|
+
authoritativePaths: Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths : [],
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
function defaultResumeRead(dir) {
|
|
1047
|
+
const chunks = [];
|
|
1048
|
+
try { chunks.push(fs.readFileSync(path.join(dir, 'focus.md'), 'utf8')); } catch {}
|
|
1049
|
+
try {
|
|
1050
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'artifact-manifest.json'), 'utf8'));
|
|
1051
|
+
const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
1052
|
+
const projected = [];
|
|
1053
|
+
for (let index = 0; index < artifacts.length; index += 1) {
|
|
1054
|
+
projected.push(projectResumeArtifact(artifacts[index]));
|
|
1055
|
+
}
|
|
1056
|
+
chunks.push(JSON.stringify({ slug: manifest.slug, artifacts: projected }));
|
|
1057
|
+
} catch {}
|
|
1058
|
+
try { chunks.push(fs.readFileSync(path.join(dir, '.memlog.md'), 'utf8')); } catch {}
|
|
1059
|
+
return chunks.join('\n');
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
function archiveIndexLine(dir) {
|
|
1063
|
+
const root = path.join(dir, 'archive');
|
|
1064
|
+
let names = [];
|
|
1065
|
+
try { names = fs.readdirSync(root); } catch { names = []; }
|
|
1066
|
+
const dates = [];
|
|
1067
|
+
for (let index = 0; index < names.length; index += 1) {
|
|
1068
|
+
const name = names[index];
|
|
1069
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(name)) continue;
|
|
1070
|
+
let stat = null;
|
|
1071
|
+
try { stat = fs.statSync(path.join(root, name)); } catch { stat = null; }
|
|
1072
|
+
if (stat && stat.isDirectory()) dates.push(name);
|
|
1073
|
+
}
|
|
1074
|
+
dates.sort();
|
|
1075
|
+
if (dates.length === 0) return '- archive index: (none)';
|
|
1076
|
+
const parts = [];
|
|
1077
|
+
for (let index = 0; index < dates.length; index += 1) parts.push('archive/' + dates[index] + '/');
|
|
1078
|
+
return '- archive index: ' + parts.join(', ');
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
function focusDigestMarkdown(dir, statusSnapshot) {
|
|
1082
|
+
const snapshot = statusSnapshot && typeof statusSnapshot === 'object' ? statusSnapshot : {};
|
|
1083
|
+
const slugValue = typeof snapshot.slug === 'string' ? snapshot.slug : '';
|
|
1084
|
+
const stepIndex = Number.isInteger(snapshot.pipelineIndex) ? snapshot.pipelineIndex : 0;
|
|
1085
|
+
const incomplete = [];
|
|
1086
|
+
try {
|
|
1087
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'artifact-manifest.json'), 'utf8'));
|
|
1088
|
+
const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
1089
|
+
for (let index = 0; index < artifacts.length; index += 1) {
|
|
1090
|
+
const artifact = artifacts[index];
|
|
1091
|
+
if (!artifact || artifact.status === 'completed') continue;
|
|
1092
|
+
const id = typeof artifact.id === 'string' ? artifact.id : '(no id)';
|
|
1093
|
+
const cited = Array.isArray(artifact.authoritativePaths) ? artifact.authoritativePaths : [];
|
|
1094
|
+
const paths = [];
|
|
1095
|
+
for (let pathIndex = 0; pathIndex < cited.length; pathIndex += 1) {
|
|
1096
|
+
if (typeof cited[pathIndex] === 'string') paths.push(cited[pathIndex]);
|
|
1097
|
+
}
|
|
1098
|
+
incomplete.push({ id, paths });
|
|
1099
|
+
}
|
|
1100
|
+
} catch {}
|
|
1101
|
+
let lastEvent = '(none)';
|
|
1102
|
+
try {
|
|
1103
|
+
const raw = fs.readFileSync(path.join(dir, '.memlog.md'), 'utf8');
|
|
1104
|
+
const lines = raw.split(/\r?\n/);
|
|
1105
|
+
const tickEvent = /`event`:\s*(.*)$/;
|
|
1106
|
+
const bareEvent = /(?:^|\s)event:\s*(.*)$/;
|
|
1107
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
1108
|
+
const line = lines[index];
|
|
1109
|
+
let matched = tickEvent.exec(line);
|
|
1110
|
+
if (!matched) matched = bareEvent.exec(line);
|
|
1111
|
+
if (matched && matched[1].trim()) {
|
|
1112
|
+
lastEvent = matched[1].trim();
|
|
1113
|
+
break;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
} catch {}
|
|
1117
|
+
let nextGate = 'none';
|
|
1118
|
+
if (snapshot.awaitingHumanGate === true || snapshot.state === 'awaiting_approval') {
|
|
1119
|
+
nextGate = 'human gate — /task-continue ' + slugValue;
|
|
1120
|
+
} else {
|
|
1121
|
+
try {
|
|
1122
|
+
const pipeline = JSON.parse(fs.readFileSync(path.join(dir, 'pipeline.json'), 'utf8'));
|
|
1123
|
+
const steps = Array.isArray(pipeline.steps) ? pipeline.steps : [];
|
|
1124
|
+
const gates = Array.isArray(pipeline.humanGates) ? pipeline.humanGates : [];
|
|
1125
|
+
for (let index = stepIndex; index < steps.length; index += 1) {
|
|
1126
|
+
const step = steps[index];
|
|
1127
|
+
const agents = !step ? [] : (Array.isArray(step.agent) ? step.agent : [step.agent]);
|
|
1128
|
+
let hit = '';
|
|
1129
|
+
for (let agentIndex = 0; agentIndex < agents.length; agentIndex += 1) {
|
|
1130
|
+
const agent = agents[agentIndex];
|
|
1131
|
+
if (typeof agent === 'string' && gates.indexOf('after:' + agent) !== -1) {
|
|
1132
|
+
hit = agent;
|
|
1133
|
+
break;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
if (hit) {
|
|
1137
|
+
const stepId = step && typeof step.id === 'string' ? step.id : 'step-' + String(index);
|
|
1138
|
+
nextGate = 'after:' + hit + ' (step ' + stepId + ', index ' + String(index) + ')';
|
|
1139
|
+
break;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
} catch {}
|
|
1143
|
+
}
|
|
1144
|
+
const pathLines = [];
|
|
1145
|
+
if (incomplete.length === 0) pathLines.push(' - (none)');
|
|
1146
|
+
else {
|
|
1147
|
+
for (let index = 0; index < incomplete.length; index += 1) {
|
|
1148
|
+
const item = incomplete[index];
|
|
1149
|
+
if (item.paths.length === 0) pathLines.push(' - ' + item.id + ': (none)');
|
|
1150
|
+
else {
|
|
1151
|
+
for (let pathIndex = 0; pathIndex < item.paths.length; pathIndex += 1) {
|
|
1152
|
+
pathLines.push(' - ' + item.id + ': ' + item.paths[pathIndex]);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
let readyLine = '- decomposition ready set: (none)';
|
|
1158
|
+
try {
|
|
1159
|
+
const report = readDecompositionReadySet(dir);
|
|
1160
|
+
const ids = Array.isArray(report.ready) ? report.ready : [];
|
|
1161
|
+
readyLine = '- decomposition ready set: ' + (ids.length > 0 ? ids.join(', ') : '(none)');
|
|
1162
|
+
} catch {
|
|
1163
|
+
readyLine = '- decomposition ready set: (none)';
|
|
1164
|
+
}
|
|
1165
|
+
const head = [
|
|
1166
|
+
'# focus.md',
|
|
1167
|
+
'',
|
|
1168
|
+
'View only. `status.json`, `metrics.json`, `artifact-manifest.json`, and `.memlog.md` stay the system of record.',
|
|
1169
|
+
'',
|
|
1170
|
+
'- slug: ' + slugValue,
|
|
1171
|
+
'- pipeline step index: ' + String(stepIndex),
|
|
1172
|
+
readyLine,
|
|
1173
|
+
archiveIndexLine(dir),
|
|
1174
|
+
'- incomplete authoritative paths:',
|
|
1175
|
+
];
|
|
1176
|
+
const tail = [
|
|
1177
|
+
'- last memlog event: ' + lastEvent,
|
|
1178
|
+
'- next gate: ' + nextGate,
|
|
1179
|
+
];
|
|
1180
|
+
let pathBudget = 99 - head.length - tail.length;
|
|
1181
|
+
if (pathBudget < 1) pathBudget = 1;
|
|
1182
|
+
let kept = pathLines;
|
|
1183
|
+
if (pathLines.length > pathBudget) {
|
|
1184
|
+
const room = pathBudget - 1;
|
|
1185
|
+
kept = pathLines.slice(0, room);
|
|
1186
|
+
const omitted = pathLines.length - kept.length;
|
|
1187
|
+
kept.push(' - (' + String(omitted) + ' lines omitted to stay under 100)');
|
|
1188
|
+
}
|
|
1189
|
+
return head.concat(kept, tail).join('\n') + '\n';
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
function writeFocusDigest() {
|
|
1193
|
+
const focusPath = path.join(taskDir, 'focus.md');
|
|
1194
|
+
const temporary = focusPath + '.' + String(process.pid) + '.' + String(Date.now()) + '.tmp';
|
|
1195
|
+
try {
|
|
1196
|
+
const markdown = focusDigestMarkdown(taskDir, status);
|
|
1197
|
+
const fd = fs.openSync(temporary, 'w');
|
|
1198
|
+
try {
|
|
1199
|
+
fs.writeSync(fd, markdown);
|
|
1200
|
+
try { fs.fsyncSync(fd); } catch {}
|
|
1201
|
+
} finally {
|
|
1202
|
+
fs.closeSync(fd);
|
|
1203
|
+
}
|
|
1204
|
+
fs.renameSync(temporary, focusPath);
|
|
1205
|
+
} catch {
|
|
1206
|
+
try { fs.unlinkSync(temporary); } catch {}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
471
1209
|
|
|
472
1210
|
function writeStatus(next) {
|
|
473
1211
|
status = { ...status, ...next, slug, updatedAt: now };
|
|
@@ -484,6 +1222,11 @@ function writeStatus(next) {
|
|
|
484
1222
|
fs.closeSync(fd);
|
|
485
1223
|
}
|
|
486
1224
|
fs.renameSync(temporary, statusPath);
|
|
1225
|
+
// Closed bodies move after the checkpoint lands. A compaction miss must not roll status.json back.
|
|
1226
|
+
try { compactClosedManifestBodies(taskDir, now.slice(0, 10)); } catch {}
|
|
1227
|
+
// focus.md is a view of this checkpoint. It is written after status.json
|
|
1228
|
+
// lands so a digest failure cannot roll the checkpoint back.
|
|
1229
|
+
writeFocusDigest();
|
|
487
1230
|
}
|
|
488
1231
|
|
|
489
1232
|
function out(message) {
|
|
@@ -646,7 +1389,8 @@ function handoffForWave(units, waveId) {
|
|
|
646
1389
|
`Invoke IN PARALLEL (one message, multiple Task calls): ${labels.join(' AND ')} for slug "${slug}"${waveId ? ` (waveId=${waveId})` : ''}. ` +
|
|
647
1390
|
`Each agent writes its artifact and owned receipt; the hook records slot joins from stops. Do not mutate status.json lifecycle fields. ` +
|
|
648
1391
|
`Artifact inputs: ${inputIds.length > 0 ? inputIds.join(', ') : 'manifest defaults'}; owned output IDs: ${outputIds.join('; ')}. ` +
|
|
649
|
-
`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
|
|
1392
|
+
`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()}` +
|
|
1393
|
+
decompositionReadyClause(units.map((unit) => steps[unit.stepIndex]))
|
|
650
1394
|
);
|
|
651
1395
|
}
|
|
652
1396
|
function blockedNotice(blockedIndex, agent) {
|
|
@@ -662,16 +1406,29 @@ function noProgressNotice() {
|
|
|
662
1406
|
const pending = pendingStepIndexes().map((index) => steps[index].id || `step-${index}`);
|
|
663
1407
|
return `No schedulable step remains for slug "${slug}" (unsatisfied: ${pending.join(', ')}). Resume only via /task-continue ${slug}.`;
|
|
664
1408
|
}
|
|
1409
|
+
function deferReason(wave, deferred) {
|
|
1410
|
+
const sameAgent = deferred.some((index) => wave.some((chosen) => {
|
|
1411
|
+
const left = getStepAgents(steps[chosen]);
|
|
1412
|
+
return getStepAgents(steps[index]).some((agent) => left.includes(agent));
|
|
1413
|
+
}));
|
|
1414
|
+
if (sameAgent) return 'same agent already in the wave';
|
|
1415
|
+
const missingScope = [...wave, ...deferred].some((index) => declaredScopes(steps[index]).length === 0);
|
|
1416
|
+
if (missingScope) return 'writeScopes undeclared';
|
|
1417
|
+
return 'writeScopes overlap';
|
|
1418
|
+
}
|
|
665
1419
|
function dispatchReadyWave(prefixMessage) {
|
|
666
1420
|
const ready = computeReadySteps();
|
|
667
1421
|
if (ready.length === 0) return false;
|
|
668
1422
|
const { wave, deferred } = selectWave(ready);
|
|
669
1423
|
if (deferred.length > 0) {
|
|
670
|
-
appendMetric({ type: 'parallel_conflict_deferred', at: now, stepIndex: wave[0], deferredStepIndexes: deferred, reason:
|
|
1424
|
+
appendMetric({ type: 'parallel_conflict_deferred', at: now, stepIndex: wave[0], deferredStepIndexes: deferred, reason: deferReason(wave, deferred), source: 'hook', attributionConfidence: 'fallback' });
|
|
671
1425
|
}
|
|
672
1426
|
// Slot-filtered dispatch: only unsatisfied (stepIndex, agent) slots are invoked.
|
|
673
1427
|
const units = wave.flatMap((stepIndex) => unsatisfiedAgents(stepIndex).map((agent) => ({ stepIndex, agent })));
|
|
674
1428
|
if (units.length === 0) return false;
|
|
1429
|
+
const unitAgents = units.map((unit) => unit.agent);
|
|
1430
|
+
refuseImplementationStart(unitAgents, (agent) => implementationDebugRetry(agent));
|
|
1431
|
+
recordAllowedDebugRetries(unitAgents);
|
|
675
1432
|
const first = units[0].stepIndex;
|
|
676
1433
|
const waveId = `${status.metricsRunId || slug}:wave-${first}`;
|
|
677
1434
|
for (const unit of units) activateAttempts(steps[unit.stepIndex], unit.stepIndex, units.length > 1 ? waveId : null, [unit.agent]);
|
|
@@ -770,15 +1527,173 @@ function metricsHandoff(agent) {
|
|
|
770
1527
|
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.';
|
|
771
1528
|
}
|
|
772
1529
|
|
|
1530
|
+
function receiptPathClause() {
|
|
1531
|
+
return 'authoritativePaths are relative to the task folder (brief.md), not the repo root; put external files in evidencePaths.';
|
|
1532
|
+
}
|
|
773
1533
|
function artifactHandoff(step, agent) {
|
|
774
1534
|
const inputIds = Array.isArray(step?.artifactInputIds) ? step.artifactInputIds.join(', ') : 'manifest defaults';
|
|
775
|
-
return ` Artifact inputs: ${inputIds}; owned output ID: ${artifactOutputIdFor(step, agent)}. Bind the terminal receipt to the supplied attemptId
|
|
1535
|
+
return ` Artifact inputs: ${inputIds}; owned output ID: ${artifactOutputIdFor(step, agent)}. Bind the terminal receipt to the supplied attemptId. ${receiptPathClause()}`;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
// <<<implementation-rail>>>
|
|
1539
|
+
// Opt-in. Omitted, "off", and non-production intents stay off. Only "on" applies.
|
|
1540
|
+
function testBeforeHandoffRule() {
|
|
1541
|
+
return 'Include unit tests for mappers/logic before handoff.';
|
|
1542
|
+
}
|
|
1543
|
+
function railOnHandoffClause() {
|
|
1544
|
+
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.';
|
|
1545
|
+
}
|
|
1546
|
+
function implementationRailApplies(pipeline) {
|
|
1547
|
+
if (!pipeline || typeof pipeline !== 'object') return false;
|
|
1548
|
+
const intent = typeof pipeline.intent === 'string' ? pipeline.intent : '';
|
|
1549
|
+
const level = pipeline.taskLevel;
|
|
1550
|
+
if (level === 'L0' || level === 0 || level === '0') return false;
|
|
1551
|
+
if (intent === 'docs-only' || intent === 'research' || intent === 'preset-only' || intent === 'spike') return false;
|
|
1552
|
+
if (pipeline.presetOnly === true) return false;
|
|
1553
|
+
return pipeline.implementationRail === 'on';
|
|
1554
|
+
}
|
|
1555
|
+
function briefHasOpenClarificationMarker(text) {
|
|
1556
|
+
if (typeof text !== 'string' || text.length === 0) return false;
|
|
1557
|
+
const lines = text.split(/\r?\n/);
|
|
1558
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
1559
|
+
let body = lines[index].trim().replace(/^(?:>\s*)+/, '');
|
|
1560
|
+
body = body.replace(/^(?:[-*+]|\d+[.)])\s+/, '');
|
|
1561
|
+
if (body.startsWith('[NEEDS CLARIFICATION]')) return true;
|
|
1562
|
+
}
|
|
1563
|
+
return false;
|
|
1564
|
+
}
|
|
1565
|
+
function implementationHandoffDecision(input) {
|
|
1566
|
+
const agent = input && input.agent;
|
|
1567
|
+
const applies = agent === 'feature-developer' && implementationRailApplies(input && input.pipeline);
|
|
1568
|
+
if (!applies) {
|
|
1569
|
+
return {
|
|
1570
|
+
start: true,
|
|
1571
|
+
rail: 'off',
|
|
1572
|
+
handoffRule: agent === 'feature-developer' ? testBeforeHandoffRule() : null,
|
|
1573
|
+
constraints: [],
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
if (briefHasOpenClarificationMarker(input && input.briefText)) {
|
|
1577
|
+
return { start: false, rail: 'on', reason: 'open-marker', handoffRule: testBeforeHandoffRule(), constraints: [] };
|
|
1578
|
+
}
|
|
1579
|
+
const debugRetries = Number(input && input.debugRetryCount) || 0;
|
|
1580
|
+
if (input && input.debugRetry === true && debugRetries >= 2) {
|
|
1581
|
+
return { start: false, rail: 'on', reason: 'debug-retry-cap', handoffRule: testBeforeHandoffRule(), constraints: [] };
|
|
1582
|
+
}
|
|
1583
|
+
return {
|
|
1584
|
+
start: true,
|
|
1585
|
+
rail: 'on',
|
|
1586
|
+
handoffRule: testBeforeHandoffRule(),
|
|
1587
|
+
constraints: [
|
|
1588
|
+
'failing test before production edits',
|
|
1589
|
+
'branch or worktree before the first implementation task',
|
|
1590
|
+
'code-reviewer between decomposition tasks',
|
|
1591
|
+
'debug retries capped at two',
|
|
1592
|
+
],
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
// <<<implementation-rail-end>>>
|
|
1596
|
+
|
|
1597
|
+
function readPipelineRecord() {
|
|
1598
|
+
try {
|
|
1599
|
+
return JSON.parse(fs.readFileSync(pipelinePath, 'utf8'));
|
|
1600
|
+
} catch {
|
|
1601
|
+
return null;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
function readBriefText() {
|
|
1605
|
+
try {
|
|
1606
|
+
return fs.readFileSync(path.join(taskDir, 'brief.md'), 'utf8');
|
|
1607
|
+
} catch {
|
|
1608
|
+
return '';
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
function countDebugImplementationRetries() {
|
|
1612
|
+
try {
|
|
1613
|
+
const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
|
|
1614
|
+
const events = Array.isArray(metrics.events) ? metrics.events : [];
|
|
1615
|
+
return events.filter((event) => event && event.type === 'retry_scheduled' && event.nextAgent === 'feature-developer' && event.retryAfterFix === 'debugger').length;
|
|
1616
|
+
} catch {
|
|
1617
|
+
return 0;
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
function featureDeveloperAlreadyStarted() {
|
|
1621
|
+
try {
|
|
1622
|
+
const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
|
|
1623
|
+
const events = Array.isArray(metrics.events) ? metrics.events : [];
|
|
1624
|
+
return events.some((event) => event && event.type === 'attempt_started' && event.agent === 'feature-developer');
|
|
1625
|
+
} catch {
|
|
1626
|
+
return false;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
function implementationDebugRetry(agent) {
|
|
1630
|
+
return agent === 'feature-developer' && status.currentAgent === 'debugger' && featureDeveloperAlreadyStarted();
|
|
1631
|
+
}
|
|
1632
|
+
function blockImplementationStart(agent, debugRetry) {
|
|
1633
|
+
const decision = implementationHandoffDecision({
|
|
1634
|
+
agent,
|
|
1635
|
+
pipeline: readPipelineRecord(),
|
|
1636
|
+
briefText: readBriefText(),
|
|
1637
|
+
debugRetry: Boolean(debugRetry),
|
|
1638
|
+
debugRetryCount: countDebugImplementationRetries(),
|
|
1639
|
+
});
|
|
1640
|
+
if (decision.start) return null;
|
|
1641
|
+
if (decision.reason === 'debug-retry-cap') {
|
|
1642
|
+
return `Strict implementation rail is on for slug "${slug}". Debug retries for the implementation handoff are capped at two. Do not start implementation.`;
|
|
1643
|
+
}
|
|
1644
|
+
return `Strict implementation rail is on for slug "${slug}" and a [NEEDS CLARIFICATION] marker is open. Do not start implementation.`;
|
|
1645
|
+
}
|
|
1646
|
+
function refuseImplementationStart(agents, debugRetryFor) {
|
|
1647
|
+
const list = Array.isArray(agents) ? agents : [agents];
|
|
1648
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
1649
|
+
const block = blockImplementationStart(list[index], debugRetryFor(list[index]));
|
|
1650
|
+
if (!block) continue;
|
|
1651
|
+
beginHumanGate();
|
|
1652
|
+
writeStatus({
|
|
1653
|
+
state: 'awaiting_approval',
|
|
1654
|
+
phase: 'human_gate',
|
|
1655
|
+
awaitingHumanGate: true,
|
|
1656
|
+
waveSteps: [],
|
|
1657
|
+
waveId: null,
|
|
1658
|
+
retryAfterFix: null,
|
|
1659
|
+
retryAfterFixStepIndex: null,
|
|
1660
|
+
});
|
|
1661
|
+
out(block);
|
|
1662
|
+
process.exit(0);
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
function recordAllowedDebugRetries(agents) {
|
|
1666
|
+
if (!implementationRailApplies(readPipelineRecord())) return;
|
|
1667
|
+
const list = Array.isArray(agents) ? agents : [agents];
|
|
1668
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
1669
|
+
if (!implementationDebugRetry(list[index])) continue;
|
|
1670
|
+
appendMetric({
|
|
1671
|
+
type: 'retry_scheduled',
|
|
1672
|
+
at: now,
|
|
1673
|
+
attemptId: null,
|
|
1674
|
+
nextAgent: 'feature-developer',
|
|
1675
|
+
retryAfterFix: 'debugger',
|
|
1676
|
+
source: 'hook',
|
|
1677
|
+
attributionConfidence: 'high',
|
|
1678
|
+
});
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
function railInstructionClause(agent) {
|
|
1682
|
+
const decision = implementationHandoffDecision({
|
|
1683
|
+
agent,
|
|
1684
|
+
pipeline: readPipelineRecord(),
|
|
1685
|
+
briefText: readBriefText(),
|
|
1686
|
+
debugRetry: false,
|
|
1687
|
+
debugRetryCount: 0,
|
|
1688
|
+
});
|
|
1689
|
+
if (decision.rail !== 'on' || !decision.start) return '';
|
|
1690
|
+
return railOnHandoffClause();
|
|
776
1691
|
}
|
|
777
1692
|
|
|
778
1693
|
function handoffForAgent(agent, scope, step = null) {
|
|
779
1694
|
const fn = AGENT_HANDOFF[agent];
|
|
780
1695
|
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.`;
|
|
781
|
-
return handoff + artifactHandoff(step, agent) + metricsHandoff(agent);
|
|
1696
|
+
return handoff + railInstructionClause(agent) + artifactHandoff(step, agent) + metricsHandoff(agent) + decompositionReadyClause(step ? [step] : []);
|
|
782
1697
|
}
|
|
783
1698
|
|
|
784
1699
|
function handoffForParallelStep(step) {
|
|
@@ -790,7 +1705,8 @@ function handoffForParallelStep(step) {
|
|
|
790
1705
|
`Invoke IN PARALLEL (one message, multiple Task calls): ${agents.join(' AND ')} for slug "${slug}". ` +
|
|
791
1706
|
`Each agent writes its artifact and owned receipt; the hook records parallelCompleted from stops. Do not mutate status.json lifecycle fields. ` +
|
|
792
1707
|
`Artifact inputs: ${Array.isArray(step.artifactInputIds) ? step.artifactInputIds.join(', ') : 'manifest defaults'}; owned output IDs: ${agents.map((agent) => `${agent}=${artifactOutputIdFor(step, agent)}`).join('; ')}. ` +
|
|
793
|
-
`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
|
|
1708
|
+
`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()}` +
|
|
1709
|
+
decompositionReadyClause([step])
|
|
794
1710
|
);
|
|
795
1711
|
}
|
|
796
1712
|
|
|
@@ -799,9 +1715,35 @@ function hasGateAfter(agent, humanGates) {
|
|
|
799
1715
|
}
|
|
800
1716
|
|
|
801
1717
|
function hasGateAfterStep(step, humanGates) {
|
|
1718
|
+
if (!Array.isArray(humanGates) || !step) return false;
|
|
1719
|
+
if (typeof step.id === 'string' && step.id.length > 0 && humanGates.includes(`after:${step.id}`)) return true;
|
|
802
1720
|
return getStepAgents(step).some((a) => hasGateAfter(a, humanGates));
|
|
803
1721
|
}
|
|
804
1722
|
|
|
1723
|
+
// A followup loop of the subagent that just finished arrives with no attemptId
|
|
1724
|
+
// and no receipt for the attempt this same transition opened. That stop is not
|
|
1725
|
+
// the next agent. A stop more than 15s later, still without a receipt, is a
|
|
1726
|
+
// real missing receipt and must stall.
|
|
1727
|
+
function isSchedulingEcho() {
|
|
1728
|
+
if (typeof hookInput.attemptId === 'string' && hookInput.attemptId.length > 0) return false;
|
|
1729
|
+
const entries = Object.entries(status.activeAttempts || {});
|
|
1730
|
+
if (entries.length !== 1) return false;
|
|
1731
|
+
const [attemptId, entry] = entries[0];
|
|
1732
|
+
const previous = status.lastCompletedAttempt;
|
|
1733
|
+
if (!previous || previous.completedAt !== entry.startedAt) return false;
|
|
1734
|
+
const ageMs = Date.parse(now) - Date.parse(entry.startedAt);
|
|
1735
|
+
if (!Number.isFinite(ageMs) || ageMs < 0 || ageMs > 15000) return false;
|
|
1736
|
+
const previousJoined = Object.values(status.joinedSlots || {}).some((slot) => slot && slot.attemptId === previous.attemptId);
|
|
1737
|
+
const linearAdvance = !isGraphMode() && typeof entry.stepIndex === 'number' && entry.stepIndex > 0;
|
|
1738
|
+
if (!previousJoined && !linearAdvance) return false;
|
|
1739
|
+
try {
|
|
1740
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(taskDir, 'artifact-manifest.json'), 'utf8'));
|
|
1741
|
+
const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
1742
|
+
if (artifacts.some((item) => item && item.receipt && item.receipt.attemptId === attemptId)) return false;
|
|
1743
|
+
} catch {}
|
|
1744
|
+
return true;
|
|
1745
|
+
}
|
|
1746
|
+
|
|
805
1747
|
function legacyFlow() {
|
|
806
1748
|
if (status.phase === 'analysis') {
|
|
807
1749
|
process.stdout.write('{}');
|
|
@@ -927,6 +1869,8 @@ if (hookInput.action === 'end_human_gate') {
|
|
|
927
1869
|
const resumeNext = findNextExecutableStep(resumeSteps, resumeStart, taskDir);
|
|
928
1870
|
if (resumeNext) {
|
|
929
1871
|
const resumeAgents = getStepAgents(resumeNext.step);
|
|
1872
|
+
refuseImplementationStart(resumeAgents, (agent) => implementationDebugRetry(agent));
|
|
1873
|
+
recordAllowedDebugRetries(resumeAgents);
|
|
930
1874
|
activateAttempts(resumeNext.step, resumeNext.index);
|
|
931
1875
|
writeStatus({
|
|
932
1876
|
pipelineIndex: resumeNext.index,
|
|
@@ -1019,6 +1963,10 @@ if (pipelineParseError) {
|
|
|
1019
1963
|
}
|
|
1020
1964
|
|
|
1021
1965
|
steps = pipeline.steps || [];
|
|
1966
|
+
if (isSchedulingEcho()) {
|
|
1967
|
+
process.stdout.write('{}');
|
|
1968
|
+
process.exit(0);
|
|
1969
|
+
}
|
|
1022
1970
|
const initialIdx = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
|
|
1023
1971
|
const initialStep = steps[initialIdx];
|
|
1024
1972
|
const activeAttemptCountBeforeFinish = Object.keys(status.activeAttempts || {}).length;
|
|
@@ -1079,6 +2027,9 @@ function nearestPrecedingStepIndex(agent, fromIndex, fallback) {
|
|
|
1079
2027
|
return match >= 0 ? match : fallback;
|
|
1080
2028
|
}
|
|
1081
2029
|
function scheduleRetry(agent, retryAfterFix, predecessor, explicitStepIndex = null) {
|
|
2030
|
+
if (agent === 'feature-developer') {
|
|
2031
|
+
refuseImplementationStart([agent], () => retryAfterFix === 'debugger');
|
|
2032
|
+
}
|
|
1082
2033
|
const currentIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
|
|
1083
2034
|
const explicitOk = Number.isInteger(explicitStepIndex) && getStepAgents(steps[explicitStepIndex]).includes(agent);
|
|
1084
2035
|
const stepIndex = explicitOk ? explicitStepIndex : nearestPrecedingStepIndex(agent, currentIndex, -1);
|
|
@@ -1386,6 +2337,8 @@ if (!next) {
|
|
|
1386
2337
|
const { step: nextStep, index: nextIdx } = next;
|
|
1387
2338
|
const nextAgents = getStepAgents(nextStep);
|
|
1388
2339
|
|
|
2340
|
+
refuseImplementationStart(nextAgents, (agent) => implementationDebugRetry(agent));
|
|
2341
|
+
recordAllowedDebugRetries(nextAgents);
|
|
1389
2342
|
activateAttempts(nextStep, nextIdx);
|
|
1390
2343
|
writeStatus({
|
|
1391
2344
|
pipelineIndex: nextIdx,
|
|
@@ -1414,6 +2367,180 @@ const fs = require('fs');
|
|
|
1414
2367
|
const path = require('path');
|
|
1415
2368
|
const { spawnSync } = require('child_process');
|
|
1416
2369
|
|
|
2370
|
+
// <<<standards-draft>>>
|
|
2371
|
+
// Explicit payload only. This postflight never walks the repo and never
|
|
2372
|
+
// creates `.ai.local/rules/`. The same provenance tag does not rewrite an
|
|
2373
|
+
// accepted Gotchas, Patterns, or Decisions line.
|
|
2374
|
+
function standardsDraftTag(provenance) {
|
|
2375
|
+
return '(`' + provenance + '`)';
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
function standardsDraftLineIndex(content, header) {
|
|
2379
|
+
if (content.startsWith(header) && (content.length === header.length || content.charAt(header.length) === '\n')) return 0;
|
|
2380
|
+
const at = content.indexOf('\n' + header + '\n');
|
|
2381
|
+
if (at !== -1) return at + 1;
|
|
2382
|
+
if (content.endsWith('\n' + header)) return content.length - header.length;
|
|
2383
|
+
return -1;
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
function standardsDraftSection(content, name) {
|
|
2387
|
+
const header = '## ' + name;
|
|
2388
|
+
const start = standardsDraftLineIndex(content, header);
|
|
2389
|
+
if (start === -1) return null;
|
|
2390
|
+
const from = start + header.length;
|
|
2391
|
+
const next = content.indexOf('\n## ', from);
|
|
2392
|
+
const end = next === -1 ? content.length : next;
|
|
2393
|
+
return content.slice(start, end);
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
function standardsDraftProtected(content) {
|
|
2397
|
+
const names = ['Language', 'Gotchas', 'Patterns', 'Decisions', 'Advisory index'];
|
|
2398
|
+
let snapshot = '';
|
|
2399
|
+
for (let index = 0; index < names.length; index += 1) {
|
|
2400
|
+
const body = standardsDraftSection(content, names[index]);
|
|
2401
|
+
snapshot += names[index] + '\n' + (body === null ? '' : body) + '\n';
|
|
2402
|
+
}
|
|
2403
|
+
return snapshot;
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
function standardsDraftNormalize(line) {
|
|
2407
|
+
return line.trim().replace(/\s+/g, ' ').replace(/^-\s+/, '').replace(/\s+\(`[^`]*`\)$/, '').toLowerCase();
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
function standardsDraftAccepted(content, text) {
|
|
2411
|
+
const pending = standardsDraftSection(content, 'Pending');
|
|
2412
|
+
let rest = content;
|
|
2413
|
+
if (pending !== null) {
|
|
2414
|
+
const start = content.indexOf(pending);
|
|
2415
|
+
rest = content.slice(0, start) + content.slice(start + pending.length);
|
|
2416
|
+
}
|
|
2417
|
+
const needle = standardsDraftNormalize(text);
|
|
2418
|
+
if (!needle) return false;
|
|
2419
|
+
const lines = rest.split('\n');
|
|
2420
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
2421
|
+
const line = lines[index];
|
|
2422
|
+
if (!/^-\s+\S/.test(line)) continue;
|
|
2423
|
+
if (standardsDraftNormalize(line) === needle) return true;
|
|
2424
|
+
}
|
|
2425
|
+
return false;
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
function standardsDraftAppendPending(content, line) {
|
|
2429
|
+
const header = '## Pending';
|
|
2430
|
+
const start = standardsDraftLineIndex(content, header);
|
|
2431
|
+
if (start === -1) {
|
|
2432
|
+
const sep = content.endsWith('\n') ? '\n' : '\n\n';
|
|
2433
|
+
return content + sep + header + '\n\n' + line + '\n';
|
|
2434
|
+
}
|
|
2435
|
+
const from = start + header.length;
|
|
2436
|
+
const next = content.indexOf('\n## ', from);
|
|
2437
|
+
const end = next === -1 ? content.length : next;
|
|
2438
|
+
let body = content.slice(from, end);
|
|
2439
|
+
const hasBullet = /(^|\n)-\s+\S/.test(body);
|
|
2440
|
+
if (!hasBullet && /(^|\n)-[ \t]*(?=\n|$)/.test(body)) {
|
|
2441
|
+
body = body.replace(/(^|\n)-[ \t]*(?=\n|$)/, '$1' + line);
|
|
2442
|
+
} else if (body.endsWith('\n\n')) {
|
|
2443
|
+
body = body.slice(0, -1) + line + '\n\n';
|
|
2444
|
+
} else if (body.endsWith('\n')) {
|
|
2445
|
+
body = body + line + '\n';
|
|
2446
|
+
} else {
|
|
2447
|
+
body = body + '\n' + line + '\n';
|
|
2448
|
+
}
|
|
2449
|
+
return content.slice(0, from) + body + content.slice(end);
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2452
|
+
function standardsDraftProvenance(draft) {
|
|
2453
|
+
if (!draft || typeof draft.provenance !== 'string') return '';
|
|
2454
|
+
const provenance = draft.provenance.trim();
|
|
2455
|
+
if (/^incident: [A-Za-z0-9][A-Za-z0-9._:-]{0,80}$/.test(provenance)) return provenance;
|
|
2456
|
+
const read = /^read: ([A-Za-z0-9][A-Za-z0-9._/-]{0,160})$/.exec(provenance);
|
|
2457
|
+
if (!read) return '';
|
|
2458
|
+
const parts = read[1].split('/');
|
|
2459
|
+
if (parts.indexOf('..') !== -1 || parts.indexOf('.') !== -1) return '';
|
|
2460
|
+
if (read[1] === '.ai.local/rules' || read[1].indexOf('.ai.local/rules/') === 0) return '';
|
|
2461
|
+
return provenance;
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
function standardsDraftWrite(target, content) {
|
|
2465
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
2466
|
+
const temporary = target + '.' + String(process.pid) + '.tmp';
|
|
2467
|
+
fs.writeFileSync(temporary, content);
|
|
2468
|
+
fs.renameSync(temporary, target);
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
function appendOptionalStandardsDraft(root, draft) {
|
|
2472
|
+
const provenance = standardsDraftProvenance(draft);
|
|
2473
|
+
if (!provenance) return { wrote: false, reason: 'provenance' };
|
|
2474
|
+
const text = draft && typeof draft.text === 'string' ? draft.text.trim() : '';
|
|
2475
|
+
if (!text || text.length > 400 || text.indexOf('\n') !== -1 || text.indexOf('\r') !== -1 || text.indexOf('## ') !== -1) {
|
|
2476
|
+
return { wrote: false, reason: 'text' };
|
|
2477
|
+
}
|
|
2478
|
+
let destination = 'conventions';
|
|
2479
|
+
if (draft.destination != null) {
|
|
2480
|
+
if (draft.destination === 'conventions' || draft.destination === 'rules-library') destination = draft.destination;
|
|
2481
|
+
else return { wrote: false, reason: 'destination' };
|
|
2482
|
+
}
|
|
2483
|
+
const line = '- ' + text + ' ' + standardsDraftTag(provenance);
|
|
2484
|
+
const overlay = path.join(root, '.ai.local');
|
|
2485
|
+
const rulesDir = path.join(overlay, 'rules');
|
|
2486
|
+
const rulesPrefix = rulesDir + path.sep;
|
|
2487
|
+
|
|
2488
|
+
if (destination === 'rules-library') {
|
|
2489
|
+
const stem = draft && typeof draft.stem === 'string' ? draft.stem : '';
|
|
2490
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+){0,8}$/.test(stem) || stem.length > 48) {
|
|
2491
|
+
return { wrote: false, reason: 'stem' };
|
|
2492
|
+
}
|
|
2493
|
+
const libraryDir = path.join(overlay, 'rules-library');
|
|
2494
|
+
const target = path.join(libraryDir, stem + '.md');
|
|
2495
|
+
const libraryPrefix = libraryDir + path.sep;
|
|
2496
|
+
if (!target.startsWith(libraryPrefix)) return { wrote: false, reason: 'path' };
|
|
2497
|
+
if (target === rulesDir || target.startsWith(rulesPrefix)) return { wrote: false, reason: 'rules' };
|
|
2498
|
+
let existing = null;
|
|
2499
|
+
try {
|
|
2500
|
+
existing = fs.readFileSync(target, 'utf8');
|
|
2501
|
+
} catch (error) {
|
|
2502
|
+
if (!error || error.code !== 'ENOENT') throw error;
|
|
2503
|
+
}
|
|
2504
|
+
if (existing !== null) {
|
|
2505
|
+
if (existing.indexOf(standardsDraftTag(provenance)) !== -1) {
|
|
2506
|
+
return { wrote: false, reason: 'same-provenance', target: target };
|
|
2507
|
+
}
|
|
2508
|
+
const prefix = existing.endsWith('\n') ? '' : '\n';
|
|
2509
|
+
fs.appendFileSync(target, prefix + line + '\n');
|
|
2510
|
+
return { wrote: true, target: target, mode: 'append-provenance' };
|
|
2511
|
+
}
|
|
2512
|
+
standardsDraftWrite(target, '# ' + stem + '\n\nPending draft. Inactive until a human moves this file into `.ai.local/rules/`.\n\n' + line + '\n');
|
|
2513
|
+
return { wrote: true, target: target, mode: 'create' };
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
const conventionsPath = path.join(overlay, 'conventions.md');
|
|
2517
|
+
if (conventionsPath === rulesDir || conventionsPath.startsWith(rulesPrefix)) {
|
|
2518
|
+
return { wrote: false, reason: 'rules' };
|
|
2519
|
+
}
|
|
2520
|
+
let content = null;
|
|
2521
|
+
try {
|
|
2522
|
+
content = fs.readFileSync(conventionsPath, 'utf8');
|
|
2523
|
+
} catch (error) {
|
|
2524
|
+
if (!error || error.code !== 'ENOENT') throw error;
|
|
2525
|
+
}
|
|
2526
|
+
if (content === null) content = '# Living conventions\n';
|
|
2527
|
+
if (content.indexOf(standardsDraftTag(provenance)) !== -1) {
|
|
2528
|
+
return { wrote: false, reason: 'same-provenance', target: conventionsPath };
|
|
2529
|
+
}
|
|
2530
|
+
const before = standardsDraftProtected(content);
|
|
2531
|
+
const next = standardsDraftAppendPending(content, line);
|
|
2532
|
+
if (standardsDraftProtected(next) !== before) {
|
|
2533
|
+
return { wrote: false, reason: 'protected', target: conventionsPath };
|
|
2534
|
+
}
|
|
2535
|
+
standardsDraftWrite(conventionsPath, next);
|
|
2536
|
+
return {
|
|
2537
|
+
wrote: true,
|
|
2538
|
+
target: conventionsPath,
|
|
2539
|
+
mode: standardsDraftAccepted(content, text) ? 'provenance-only' : 'pending',
|
|
2540
|
+
};
|
|
2541
|
+
}
|
|
2542
|
+
// <<<standards-draft-end>>>
|
|
2543
|
+
|
|
1417
2544
|
let input;
|
|
1418
2545
|
try {
|
|
1419
2546
|
input = JSON.parse(process.env.INPUT || '');
|
|
@@ -1446,6 +2573,12 @@ if (pipeline && (pipeline.profile === 'light' || pipeline.intent === 'spike')) {
|
|
|
1446
2573
|
process.exit(0);
|
|
1447
2574
|
}
|
|
1448
2575
|
|
|
2576
|
+
try {
|
|
2577
|
+
appendOptionalStandardsDraft(process.cwd(), input.standardsDraft);
|
|
2578
|
+
} catch {
|
|
2579
|
+
// A draft failure must not fail the stop, and must not add a WARNING.
|
|
2580
|
+
}
|
|
2581
|
+
|
|
1449
2582
|
if (!fs.existsSync(path.join(process.cwd(), '.ai.local', 'scripts', 'run.mjs'))) {
|
|
1450
2583
|
process.stderr.write(
|
|
1451
2584
|
'WARNING: self-learning loop skipped: .ai.local/scripts/run.mjs is missing (install it with `npx @bonesofspring/ai-rules init <tool> --preset <stack>`)\n',
|