@bonesofspring/ai-rules 0.2.87 → 0.2.90
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 +50 -0
- package/README.md +9 -1
- package/bin/lib/engine-scripts.js +7 -0
- package/bin/lib/seed-ai-local-team.js +40 -0
- package/bin/opencode-install.js +11 -10
- package/docs/OPENCODE.md +8 -4
- package/docs/openapi/team-db.v1.json +2 -2
- package/package.json +1 -1
- package/presets/_shared/ai-local/env.example +54 -0
- package/presets/_shared/ai-local/scripts/aggregate-agent-task-metrics.mjs +34 -5
- package/presets/_shared/ai-local/scripts/check-task-repositories.mjs +25 -22
- package/presets/_shared/ai-local/scripts/process-lease.mjs +3 -2
- package/presets/_shared/ai-local/scripts/processes.mjs +52 -20
- package/presets/_shared/ai-local/scripts/run.mjs +38 -6
- package/presets/_shared/ai-local/scripts/settings.mjs +246 -0
- package/presets/_shared/ai-local/scripts/task-worktree.mjs +364 -0
- package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +2 -2
- package/presets/_shared/ai-local/scripts/team-db-project.mjs +87 -14
- package/presets/_shared/ai-local/scripts/team-db-schema.mjs +102 -12
- package/presets/_shared/ai-local/scripts/team-db-tracker.mjs +35 -0
- package/presets/_shared/ai-local/scripts/tracker-planned-drain.mjs +10 -1
- package/presets/_shared/ai-local/scripts/verification.mjs +106 -11
- package/presets/_shared/core/agent-team/agent-task-metrics.md +10 -2
- package/presets/_shared/core/agent-team/agent-team-intake.md +2 -0
- package/presets/_shared/core/agent-team/agent-team-orchestrator.md +2 -2
- package/presets/_shared/core/meta/preset-writing-style.md +8 -0
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +541 -61
- package/presets/_shared/hooks/guard-shell-command.mjs.tmpl +733 -9
- package/presets/_shared/hooks/prompt-autoroute.mjs.tmpl +153 -0
- package/presets/claude/android-kotlin/CLAUDE.md +2 -4
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/android-kotlin/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/android-kotlin/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/android-kotlin/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/android-kotlin/settings.json +15 -5
- package/presets/claude/go/CLAUDE.md +2 -4
- package/presets/claude/go/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/go/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/go/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/go/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/go/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/go/settings.json +15 -5
- package/presets/claude/ios-swift/CLAUDE.md +2 -4
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/ios-swift/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/ios-swift/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/ios-swift/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/ios-swift/settings.json +15 -5
- package/presets/claude/java/CLAUDE.md +2 -4
- package/presets/claude/java/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/java/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/java/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/java/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/java/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/java/settings.json +15 -5
- package/presets/claude/mcp-ts/CLAUDE.md +2 -4
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/mcp-ts/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/mcp-ts/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/mcp-ts/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/mcp-ts/settings.json +15 -5
- package/presets/claude/mol/CLAUDE.md +2 -4
- package/presets/claude/mol/agents/feature-developer.md +1 -1
- package/presets/claude/mol/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/claude/mol/commands/task-evil.md +8 -0
- package/presets/claude/mol/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/mol/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/mol/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/mol/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/mol/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/mol/settings.json +15 -4
- package/presets/claude/next/CLAUDE.md +2 -4
- package/presets/claude/next/REPO_AGENTS.md +2 -0
- package/presets/claude/next/agents/feature-developer.md +1 -1
- package/presets/claude/next/agents/task-analyst.md +1 -7
- package/presets/claude/next/agents/task-router.md +1 -1
- package/presets/claude/next/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/claude/next/commands/spec-start.md +3 -4
- package/presets/claude/next/commands/task-continue.md +9 -8
- package/presets/claude/next/commands/task-evil.md +8 -0
- package/presets/claude/next/commands/task.md +1 -1
- package/presets/claude/next/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/next/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/next/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/next/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/next/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/next/settings.json +15 -4
- package/presets/claude/next/team/README.md +1 -1
- package/presets/claude/nuxt/CLAUDE.md +2 -4
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/nuxt/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/nuxt/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/nuxt/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/nuxt/settings.json +15 -4
- package/presets/claude/php-hexagonal/CLAUDE.md +2 -4
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/php-hexagonal/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/php-hexagonal/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/php-hexagonal/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/php-hexagonal/settings.json +15 -5
- package/presets/claude/php-laravel/CLAUDE.md +2 -4
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/php-laravel/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/php-laravel/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/php-laravel/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/php-laravel/settings.json +15 -5
- package/presets/claude/svelte/CLAUDE.md +2 -4
- package/presets/claude/svelte/hooks/chain-team-phases.sh +541 -61
- package/presets/claude/svelte/hooks/guard-shell-command.mjs +733 -9
- package/presets/claude/svelte/hooks/prompt-autoroute.mjs +153 -0
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-intake.md +2 -0
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
- package/presets/claude/svelte/rules/tooling-and-review/preset-writing-style.md +8 -0
- package/presets/claude/svelte/settings.json +15 -4
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/android-kotlin/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/android-kotlin/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/android-kotlin/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/go/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/go/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/go/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/go/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/go/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/ios-swift/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/ios-swift/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/ios-swift/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/java/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/java/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/java/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/java/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/java/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/mcp-ts/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/mcp-ts/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/mcp-ts/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/mol/agents/feature-developer.md +1 -1
- package/presets/cursor/mol/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/cursor/mol/commands/task-evil.md +8 -0
- package/presets/cursor/mol/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/mol/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/mol/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/mol/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/next/REPO_AGENTS.md +2 -0
- package/presets/cursor/next/agents/feature-developer.md +1 -1
- package/presets/cursor/next/agents/task-analyst.md +1 -7
- package/presets/cursor/next/agents/task-router.md +1 -1
- package/presets/cursor/next/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/cursor/next/commands/spec-start.md +3 -4
- package/presets/cursor/next/commands/task-continue.md +9 -8
- package/presets/cursor/next/commands/task-evil.md +8 -0
- package/presets/cursor/next/commands/task.md +1 -1
- package/presets/cursor/next/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/next/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/next/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/next/rules/agent-team-orchestrator.mdc +2 -2
- package/presets/cursor/next/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/next/team/README.md +1 -1
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/nuxt/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/nuxt/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/nuxt/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/php-hexagonal/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/php-hexagonal/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/php-hexagonal/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/php-laravel/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/php-laravel/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/php-laravel/rules/preset-writing-style.mdc +8 -0
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +541 -61
- package/presets/cursor/svelte/hooks/guard-shell-command.mjs +733 -9
- package/presets/cursor/svelte/rules/agent-team-intake.mdc +2 -0
- package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/svelte/rules/preset-writing-style.mdc +8 -0
- package/presets/mavis/android-kotlin/MAVIS.md +1 -1
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/android-kotlin/rules/agent-team-intake.md +2 -0
- package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/android-kotlin/rules/preset-writing-style.md +8 -0
- package/presets/mavis/go/MAVIS.md +1 -1
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/go/rules/agent-team-intake.md +2 -0
- package/presets/mavis/go/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/go/rules/preset-writing-style.md +8 -0
- package/presets/mavis/ios-swift/MAVIS.md +1 -1
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/ios-swift/rules/agent-team-intake.md +2 -0
- package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/ios-swift/rules/preset-writing-style.md +8 -0
- package/presets/mavis/java/MAVIS.md +1 -1
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/java/rules/agent-team-intake.md +2 -0
- package/presets/mavis/java/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/java/rules/preset-writing-style.md +8 -0
- package/presets/mavis/mcp-ts/MAVIS.md +1 -1
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/mcp-ts/rules/agent-team-intake.md +2 -0
- package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/mcp-ts/rules/preset-writing-style.md +8 -0
- package/presets/mavis/mol/MAVIS.md +1 -1
- package/presets/mavis/mol/adapter-map.json +1 -1
- package/presets/mavis/mol/agents/feature-developer.md +1 -1
- package/presets/mavis/mol/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/mavis/mol/commands/task-evil.md +8 -0
- package/presets/mavis/mol/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/mol/native-skills/task-evil/SKILL.md +8 -0
- package/presets/mavis/mol/rules/agent-team-intake.md +2 -0
- package/presets/mavis/mol/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/mol/rules/preset-writing-style.md +8 -0
- package/presets/mavis/next/MAVIS.md +1 -1
- package/presets/mavis/next/REPO_AGENTS.md +2 -0
- package/presets/mavis/next/adapter-map.json +1 -1
- package/presets/mavis/next/agents/feature-developer.md +1 -1
- package/presets/mavis/next/agents/task-analyst.md +1 -7
- package/presets/mavis/next/agents/task-router.md +1 -1
- package/presets/mavis/next/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/mavis/next/commands/spec-start.md +3 -4
- package/presets/mavis/next/commands/task-continue.md +9 -8
- package/presets/mavis/next/commands/task-evil.md +8 -0
- package/presets/mavis/next/commands/task.md +1 -1
- package/presets/mavis/next/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/next/native-skills/spec-start/SKILL.md +3 -4
- package/presets/mavis/next/native-skills/task/SKILL.md +1 -1
- package/presets/mavis/next/native-skills/task-continue/SKILL.md +9 -8
- package/presets/mavis/next/native-skills/task-evil/SKILL.md +8 -0
- package/presets/mavis/next/rules/agent-team-intake.md +2 -0
- package/presets/mavis/next/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/next/rules/preset-writing-style.md +8 -0
- package/presets/mavis/next/team/README.md +1 -1
- package/presets/mavis/nuxt/MAVIS.md +1 -1
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/nuxt/rules/agent-team-intake.md +2 -0
- package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/nuxt/rules/preset-writing-style.md +8 -0
- package/presets/mavis/php-hexagonal/MAVIS.md +1 -1
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/php-hexagonal/rules/agent-team-intake.md +2 -0
- package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/php-hexagonal/rules/preset-writing-style.md +8 -0
- package/presets/mavis/php-laravel/MAVIS.md +1 -1
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/php-laravel/rules/agent-team-intake.md +2 -0
- package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/php-laravel/rules/preset-writing-style.md +8 -0
- package/presets/mavis/svelte/MAVIS.md +1 -1
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +541 -61
- package/presets/mavis/svelte/rules/agent-team-intake.md +2 -0
- package/presets/mavis/svelte/rules/agent-team-orchestrator.md +2 -2
- package/presets/mavis/svelte/rules/preset-writing-style.md +8 -0
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/hooks/README.md +6 -5
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/android-kotlin/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/android-kotlin/opencode.json +4 -4
- package/presets/opencode/android-kotlin/rules/agent-team-intake.md +2 -0
- package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/android-kotlin/rules/preset-writing-style.md +8 -0
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/hooks/README.md +6 -5
- package/presets/opencode/go/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/go/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/go/opencode.json +4 -4
- package/presets/opencode/go/rules/agent-team-intake.md +2 -0
- package/presets/opencode/go/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/go/rules/preset-writing-style.md +8 -0
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/hooks/README.md +6 -5
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/ios-swift/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/ios-swift/opencode.json +4 -4
- package/presets/opencode/ios-swift/rules/agent-team-intake.md +2 -0
- package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/ios-swift/rules/preset-writing-style.md +8 -0
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/hooks/README.md +6 -5
- package/presets/opencode/java/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/java/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/java/opencode.json +4 -4
- package/presets/opencode/java/rules/agent-team-intake.md +2 -0
- package/presets/opencode/java/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/java/rules/preset-writing-style.md +8 -0
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/hooks/README.md +6 -5
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/mcp-ts/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/mcp-ts/opencode.json +4 -4
- package/presets/opencode/mcp-ts/rules/agent-team-intake.md +2 -0
- package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/mcp-ts/rules/preset-writing-style.md +8 -0
- package/presets/opencode/mol/adapter-map.json +1 -1
- package/presets/opencode/mol/agents/feature-developer.md +1 -1
- package/presets/opencode/mol/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/opencode/mol/commands/task-evil.md +8 -0
- package/presets/opencode/mol/hooks/README.md +6 -5
- package/presets/opencode/mol/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/mol/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/mol/opencode.json +4 -4
- package/presets/opencode/mol/rules/agent-team-intake.md +2 -0
- package/presets/opencode/mol/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/mol/rules/preset-writing-style.md +8 -0
- package/presets/opencode/next/REPO_AGENTS.md +2 -0
- package/presets/opencode/next/adapter-map.json +1 -1
- package/presets/opencode/next/agents/feature-developer.md +1 -1
- package/presets/opencode/next/agents/task-analyst.md +1 -7
- package/presets/opencode/next/agents/task-router.md +1 -1
- package/presets/opencode/next/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/opencode/next/commands/spec-start.md +3 -4
- package/presets/opencode/next/commands/task-continue.md +9 -8
- package/presets/opencode/next/commands/task-evil.md +8 -0
- package/presets/opencode/next/commands/task.md +1 -1
- package/presets/opencode/next/hooks/README.md +6 -5
- package/presets/opencode/next/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/next/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/next/opencode.json +4 -4
- package/presets/opencode/next/rules/agent-team-intake.md +2 -0
- package/presets/opencode/next/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/next/rules/preset-writing-style.md +8 -0
- package/presets/opencode/next/team/README.md +1 -1
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/hooks/README.md +6 -5
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/nuxt/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/nuxt/opencode.json +4 -4
- package/presets/opencode/nuxt/rules/agent-team-intake.md +2 -0
- package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/nuxt/rules/preset-writing-style.md +8 -0
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/hooks/README.md +6 -5
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/php-hexagonal/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/php-hexagonal/opencode.json +4 -4
- package/presets/opencode/php-hexagonal/rules/agent-team-intake.md +2 -0
- package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/php-hexagonal/rules/preset-writing-style.md +8 -0
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/hooks/README.md +6 -5
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/php-laravel/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/php-laravel/opencode.json +4 -4
- package/presets/opencode/php-laravel/rules/agent-team-intake.md +2 -0
- package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/php-laravel/rules/preset-writing-style.md +8 -0
- package/presets/opencode/plugins/settings-guard/README.md +25 -0
- package/presets/opencode/plugins/settings-guard/index.ts +114 -0
- package/presets/opencode/plugins/settings-guard/package.json +9 -0
- package/presets/opencode/plugins/settings-guard/policy.mjs +85 -0
- package/presets/opencode/plugins/settings-guard/prompt-face.mjs +153 -0
- package/presets/opencode/plugins/task-status/README.md +9 -4
- package/presets/opencode/plugins/task-status/eta.ts +20 -7
- package/presets/opencode/plugins/task-status/index.ts +14 -1
- package/presets/opencode/plugins/task-status/task-view.ts +160 -5
- package/presets/opencode/plugins/task-status/timing.ts +244 -0
- package/presets/opencode/plugins/task-status/types.ts +6 -0
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/hooks/README.md +6 -5
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +541 -61
- package/presets/opencode/svelte/hooks/guard-shell-command.mjs +733 -9
- package/presets/opencode/svelte/opencode.json +4 -4
- package/presets/opencode/svelte/rules/agent-team-intake.md +2 -0
- package/presets/opencode/svelte/rules/agent-team-orchestrator.md +2 -2
- package/presets/opencode/svelte/rules/preset-writing-style.md +8 -0
- package/presets/zcode/android-kotlin/adapter-map.json +1 -1
- package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/android-kotlin/rules/agent-team-intake.md +2 -0
- package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/android-kotlin/rules/preset-writing-style.md +8 -0
- package/presets/zcode/go/adapter-map.json +1 -1
- package/presets/zcode/go/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/go/rules/agent-team-intake.md +2 -0
- package/presets/zcode/go/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/go/rules/preset-writing-style.md +8 -0
- package/presets/zcode/ios-swift/adapter-map.json +1 -1
- package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/ios-swift/rules/agent-team-intake.md +2 -0
- package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/ios-swift/rules/preset-writing-style.md +8 -0
- package/presets/zcode/java/adapter-map.json +1 -1
- package/presets/zcode/java/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/java/rules/agent-team-intake.md +2 -0
- package/presets/zcode/java/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/java/rules/preset-writing-style.md +8 -0
- package/presets/zcode/mcp-ts/adapter-map.json +1 -1
- package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/mcp-ts/rules/agent-team-intake.md +2 -0
- package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/mcp-ts/rules/preset-writing-style.md +8 -0
- package/presets/zcode/mol/adapter-map.json +1 -1
- package/presets/zcode/mol/agents/feature-developer.md +1 -1
- package/presets/zcode/mol/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/zcode/mol/commands/task-evil.md +8 -0
- package/presets/zcode/mol/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/mol/rules/agent-team-intake.md +2 -0
- package/presets/zcode/mol/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/mol/rules/preset-writing-style.md +8 -0
- package/presets/zcode/next/REPO_AGENTS.md +2 -0
- package/presets/zcode/next/adapter-map.json +1 -1
- package/presets/zcode/next/agents/feature-developer.md +1 -1
- package/presets/zcode/next/agents/task-analyst.md +1 -7
- package/presets/zcode/next/agents/task-router.md +1 -1
- package/presets/zcode/next/ai-local/rules-library/commit-hygiene.md +1 -1
- package/presets/zcode/next/commands/spec-start.md +3 -4
- package/presets/zcode/next/commands/task-continue.md +9 -8
- package/presets/zcode/next/commands/task-evil.md +8 -0
- package/presets/zcode/next/commands/task.md +1 -1
- package/presets/zcode/next/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/next/rules/agent-team-intake.md +2 -0
- package/presets/zcode/next/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/next/rules/preset-writing-style.md +8 -0
- package/presets/zcode/next/team/README.md +1 -1
- package/presets/zcode/nuxt/adapter-map.json +1 -1
- package/presets/zcode/nuxt/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/nuxt/rules/agent-team-intake.md +2 -0
- package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/nuxt/rules/preset-writing-style.md +8 -0
- package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
- package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/php-hexagonal/rules/agent-team-intake.md +2 -0
- package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/php-hexagonal/rules/preset-writing-style.md +8 -0
- package/presets/zcode/php-laravel/adapter-map.json +1 -1
- package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/php-laravel/rules/agent-team-intake.md +2 -0
- package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/php-laravel/rules/preset-writing-style.md +8 -0
- package/presets/zcode/svelte/adapter-map.json +1 -1
- package/presets/zcode/svelte/hooks/chain-team-phases.sh +541 -61
- package/presets/zcode/svelte/rules/agent-team-intake.md +2 -0
- package/presets/zcode/svelte/rules/agent-team-orchestrator.md +2 -2
- package/presets/zcode/svelte/rules/preset-writing-style.md +8 -0
|
@@ -11,7 +11,10 @@ const fs = require('fs');
|
|
|
11
11
|
const path = require('path');
|
|
12
12
|
const crypto = require('crypto');
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
// Worktree hooks set AI_RULES_TEAM_ROOT so cwd does not open a second store.
|
|
15
|
+
const TEAM_ROOT = process.env.AI_RULES_TEAM_ROOT
|
|
16
|
+
? path.resolve(process.env.AI_RULES_TEAM_ROOT)
|
|
17
|
+
: path.join(process.cwd(), '.ai.local', 'team');
|
|
15
18
|
|
|
16
19
|
const inputRaw = process.env.INPUT || '';
|
|
17
20
|
let hookInput;
|
|
@@ -52,11 +55,15 @@ if (hookInput.status !== 'completed') {
|
|
|
52
55
|
// Slug resolution, strongest first:
|
|
53
56
|
// 1. TEAM_TASK_SLUG — the orchestrator's explicit binding for this call.
|
|
54
57
|
// 2. the per-session lease `.ai.local/team/.session-leases/<session>.json`,
|
|
55
|
-
// written by an earlier call that carried (1)
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
58
|
+
// written by an earlier call that carried (1), or by the OpenCode
|
|
59
|
+
// task-status plugin when it pinned this tab.
|
|
60
|
+
// 3. active-task.json — a UI projection of the live slugs (rebuilt by
|
|
61
|
+
// `team-db sync`), read only as a fallback for older hosts; when more
|
|
62
|
+
// than one slug is live the resolution is ambiguous and refused below.
|
|
63
|
+
// Only (1) writes the lease from this hook. The OpenCode task-status plugin
|
|
64
|
+
// writes the same file when it pins a tab, and `shell.env` injects the session
|
|
65
|
+
// id so this lookup sees that pin. A pointer fallback never writes a lease:
|
|
66
|
+
// that would let one session inherit another's task.
|
|
60
67
|
const SESSION_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
61
68
|
const LEASE_ROOT = path.join(TEAM_ROOT, '.session-leases');
|
|
62
69
|
const LEASE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
@@ -120,21 +127,24 @@ if (!slug && sessionId) {
|
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
129
|
if (!slug) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (!fs.existsSync(activePath)) {
|
|
126
|
-
process.stdout.write('{}');
|
|
127
|
-
process.exit(0);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
let active;
|
|
130
|
+
let active = null;
|
|
131
131
|
try {
|
|
132
|
-
active = JSON.parse(fs.readFileSync(
|
|
132
|
+
active = JSON.parse(fs.readFileSync(path.join(TEAM_ROOT, 'active-task.json'), 'utf8'));
|
|
133
133
|
} catch {
|
|
134
|
+
active = null;
|
|
135
|
+
}
|
|
136
|
+
// Back-compat reader: the projection shape `{"slugs": [...]}` (rebuilt by
|
|
137
|
+
// `team-db sync`) and the legacy single-slot `{"slug"}` shape are accepted
|
|
138
|
+
// forever. An empty or unreadable projection is identical to a missing
|
|
139
|
+
// file: a `{}` no-op.
|
|
140
|
+
const pointerSlugs = active && Array.isArray(active.slugs)
|
|
141
|
+
? active.slugs
|
|
142
|
+
: (active && typeof active.slug === 'string' && active.slug ? [active.slug] : []);
|
|
143
|
+
if (pointerSlugs.length === 0) {
|
|
134
144
|
process.stdout.write('{}');
|
|
135
145
|
process.exit(0);
|
|
136
146
|
}
|
|
137
|
-
slug =
|
|
147
|
+
slug = pointerSlugs[0];
|
|
138
148
|
slugSource = 'active-task.json';
|
|
139
149
|
}
|
|
140
150
|
// Reject non-kebab / traversal slugs: the runtime writes status.json and
|
|
@@ -144,6 +154,44 @@ if (typeof slug !== 'string' || slug.length > 48 || !SLUG_RE.test(slug)) {
|
|
|
144
154
|
process.stdout.write('{}');
|
|
145
155
|
process.exit(0);
|
|
146
156
|
}
|
|
157
|
+
// Canonical live-slug scan over the task store, never the pointer: a slug is
|
|
158
|
+
// live when `tasks/<name>/status.json` parses and its state is not terminal.
|
|
159
|
+
const TERMINAL_STATES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
|
|
160
|
+
function liveSlugs() {
|
|
161
|
+
const tasksDir = path.join(TEAM_ROOT, 'tasks');
|
|
162
|
+
let entries;
|
|
163
|
+
try {
|
|
164
|
+
entries = fs.readdirSync(tasksDir, { withFileTypes: true });
|
|
165
|
+
} catch {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
const live = [];
|
|
169
|
+
for (const entry of entries) {
|
|
170
|
+
if (!entry.isDirectory()) continue;
|
|
171
|
+
try {
|
|
172
|
+
const status = JSON.parse(fs.readFileSync(path.join(tasksDir, entry.name, 'status.json'), 'utf8'));
|
|
173
|
+
if (status && typeof status.state === 'string' && !TERMINAL_STATES.has(status.state)) live.push(entry.name);
|
|
174
|
+
} catch {}
|
|
175
|
+
}
|
|
176
|
+
return live.sort();
|
|
177
|
+
}
|
|
178
|
+
// Level-3 (pointer) resolution guard: when the slug came from
|
|
179
|
+
// active-task.json and any other live slug exists, the pointer cannot say
|
|
180
|
+
// which task this call belongs to. Refuse loudly — `ok:false` with exit 0,
|
|
181
|
+
// the hook's refusal convention (a non-zero exit would be read as a blocking
|
|
182
|
+
// platform error by Stop-class hook consumers) — so the caller re-runs with
|
|
183
|
+
// `TEAM_TASK_SLUG=<slug>` instead of silently acting on the wrong task.
|
|
184
|
+
// Exactly one live slug keeps today's warning-only behaviour, so older hosts
|
|
185
|
+
// keep working until they pass the env.
|
|
186
|
+
if (slugSource === 'active-task.json') {
|
|
187
|
+
const live = liveSlugs();
|
|
188
|
+
if (live.some((name) => name !== slug)) {
|
|
189
|
+
const shown = live.slice(0, 5).join(', ');
|
|
190
|
+
process.stderr.write(`ERROR: ${slug}: active-task.json is ambiguous — ${live.length} live slugs (${shown}${live.length > 5 ? ', max 5 shown' : ''}); pass TEAM_TASK_SLUG=<slug> on every hook call.\n`);
|
|
191
|
+
process.stdout.write(JSON.stringify({ ok: false, reason: 'active-task-pointer-ambiguous', slug, liveSlugs: live }));
|
|
192
|
+
process.exit(0);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
147
195
|
if (slugSource !== 'TEAM_TASK_SLUG') {
|
|
148
196
|
process.stderr.write(`WARNING: ${slug}: chain hook resolved the slug from ${slugSource}; pass TEAM_TASK_SLUG=<slug> on every hook call so parallel sessions cannot no-op each other.\n`);
|
|
149
197
|
}
|
|
@@ -334,6 +382,86 @@ function attemptStaleMs() {
|
|
|
334
382
|
const value = Number(raw);
|
|
335
383
|
return Number.isFinite(value) && value >= MIN_ATTEMPT_STALE_MS ? value : DEFAULT_ATTEMPT_STALE_MS;
|
|
336
384
|
}
|
|
385
|
+
// Work a single attempt may claim. Wall time beyond it is suspension, a hang, or
|
|
386
|
+
// a stop that arrived days after the agent died, and it is recorded as idle.
|
|
387
|
+
const DEFAULT_ATTEMPT_MAX_MS = 4 * 60 * 60 * 1000;
|
|
388
|
+
const MIN_ATTEMPT_MAX_MS = 10 * 60 * 1000;
|
|
389
|
+
function attemptMaxMs() {
|
|
390
|
+
const raw = process.env.AI_RULES_ATTEMPT_MAX_MS;
|
|
391
|
+
if (typeof raw !== 'string' || raw.trim() === '') return DEFAULT_ATTEMPT_MAX_MS;
|
|
392
|
+
const value = Number(raw);
|
|
393
|
+
return Number.isFinite(value) && value >= MIN_ATTEMPT_MAX_MS ? value : DEFAULT_ATTEMPT_MAX_MS;
|
|
394
|
+
}
|
|
395
|
+
// Intervals appended by the sidebar's suspend detector: the host did not run, so
|
|
396
|
+
// the attempt did not work. Written as JSONL, one { from, to } per line.
|
|
397
|
+
function readSuspendIntervals() {
|
|
398
|
+
const file = path.join(taskDir, '.suspend.jsonl');
|
|
399
|
+
let raw;
|
|
400
|
+
try { raw = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
401
|
+
const intervals = [];
|
|
402
|
+
for (const line of raw.split('\n')) {
|
|
403
|
+
const trimmed = line.trim();
|
|
404
|
+
if (trimmed === '') continue;
|
|
405
|
+
try {
|
|
406
|
+
const row = JSON.parse(trimmed);
|
|
407
|
+
const from = Date.parse(row && row.from);
|
|
408
|
+
const to = Date.parse(row && row.to);
|
|
409
|
+
if (Number.isFinite(from) && Number.isFinite(to) && to > from) intervals.push([from, to]);
|
|
410
|
+
} catch { /* a torn last line is re-read when the file grows */ }
|
|
411
|
+
}
|
|
412
|
+
return intervals;
|
|
413
|
+
}
|
|
414
|
+
function unionOverlapMs(intervals, from, to) {
|
|
415
|
+
if (!Number.isFinite(from) || !Number.isFinite(to) || to <= from) return 0;
|
|
416
|
+
const sorted = intervals
|
|
417
|
+
.filter((pair) => Array.isArray(pair) && Number.isFinite(pair[0]) && Number.isFinite(pair[1]) && pair[1] > pair[0])
|
|
418
|
+
.sort((left, right) => left[0] - right[0]);
|
|
419
|
+
let total = 0;
|
|
420
|
+
let cursor = from;
|
|
421
|
+
for (const [start, end] of sorted) {
|
|
422
|
+
const overlapStart = Math.max(start, from, cursor);
|
|
423
|
+
const overlapEnd = Math.min(end, to);
|
|
424
|
+
if (overlapEnd <= overlapStart) continue;
|
|
425
|
+
total += overlapEnd - overlapStart;
|
|
426
|
+
cursor = overlapEnd;
|
|
427
|
+
}
|
|
428
|
+
return total;
|
|
429
|
+
}
|
|
430
|
+
// Everything the ledger can prove was not work: a gate, an operator pause, a
|
|
431
|
+
// host suspension. Attempt wall time minus this is the attempt's active time.
|
|
432
|
+
function attemptIdleMs(startedAtMs, endedAtMs, events) {
|
|
433
|
+
const intervals = readSuspendIntervals();
|
|
434
|
+
// The sentinel is the control plane: it is engaged before `task_paused` is
|
|
435
|
+
// written, so a stop that notices it must still charge the wait as idle.
|
|
436
|
+
const livePause = readPauseSentinel();
|
|
437
|
+
if (livePause.engaged && livePause.at) {
|
|
438
|
+
intervals.push([Date.parse(livePause.at), endedAtMs]);
|
|
439
|
+
}
|
|
440
|
+
const gates = new Map();
|
|
441
|
+
for (const event of events) {
|
|
442
|
+
if (event && event.type === 'human_gate_started' && event.eventId) gates.set(event.eventId, Date.parse(event.at));
|
|
443
|
+
}
|
|
444
|
+
for (const event of events) {
|
|
445
|
+
if (!event) continue;
|
|
446
|
+
if (event.type === 'human_gate_ended' && event.gateStartedEventId) {
|
|
447
|
+
const start = gates.get(event.gateStartedEventId);
|
|
448
|
+
const end = Date.parse(event.at);
|
|
449
|
+
if (Number.isFinite(start) && Number.isFinite(end)) intervals.push([start, end]);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
let openPause = null;
|
|
453
|
+
for (const event of events) {
|
|
454
|
+
if (!event) continue;
|
|
455
|
+
if (event.type === 'task_paused') openPause = Date.parse(event.at);
|
|
456
|
+
if (event.type === 'task_resumed' && openPause !== null) {
|
|
457
|
+
const end = Date.parse(event.at);
|
|
458
|
+
if (Number.isFinite(end) && end > openPause) intervals.push([openPause, end]);
|
|
459
|
+
openPause = null;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (openPause !== null && Number.isFinite(openPause)) intervals.push([openPause, endedAtMs]);
|
|
463
|
+
return unionOverlapMs(intervals, startedAtMs, endedAtMs);
|
|
464
|
+
}
|
|
337
465
|
function hasTerminalReceipt(attemptId, entry) {
|
|
338
466
|
const manifestPath = path.join(taskDir, 'artifact-manifest.json');
|
|
339
467
|
if (!fs.existsSync(manifestPath)) return false;
|
|
@@ -391,6 +519,9 @@ function reclaimStaleAttempts(scope) {
|
|
|
391
519
|
role: roleFor(entry.agent),
|
|
392
520
|
outcome: 'stale',
|
|
393
521
|
durationMs: ageMs,
|
|
522
|
+
wallMs: ageMs,
|
|
523
|
+
activeMs: Math.min(ageMs, attemptMaxMs()),
|
|
524
|
+
idleMs: Math.max(0, ageMs - Math.min(ageMs, attemptMaxMs())),
|
|
394
525
|
retryAfterFix: status.retryAfterFix || null,
|
|
395
526
|
source: 'hook',
|
|
396
527
|
attributionConfidence: 'high',
|
|
@@ -1239,7 +1370,33 @@ function sanitizeUsage(value) {
|
|
|
1239
1370
|
/**
|
|
1240
1371
|
* Freshness of a persisted verification snapshot against the current worktree.
|
|
1241
1372
|
* Read-only: closure warns, it never blocks on a stale snapshot.
|
|
1373
|
+
*
|
|
1374
|
+
* Task scoping: with the slug's write-scope step baselines
|
|
1375
|
+
* (`.write-scope/<slug>/*.json`) the evidence hash covers the union of the
|
|
1376
|
+
* baselines' recorded paths only, so another live slug's uncommitted work
|
|
1377
|
+
* cannot stale this task's evidence. Known limit: a file created after baseline
|
|
1378
|
+
* activation outside the claimed path set is invisible to `scopeHash`; the
|
|
1379
|
+
* write-scope audit and `check:task` still attribute such files at gate time
|
|
1380
|
+
* (content-hash delta). The scoped hash is a change detector, not an
|
|
1381
|
+
* attribution tool. `environmentHash` (renamed from `worktreeHash`) keeps the
|
|
1382
|
+
* whole-tree capture as diagnostics only.
|
|
1242
1383
|
*/
|
|
1384
|
+
function writeScopeBaselinePaths(dir) {
|
|
1385
|
+
let entries;
|
|
1386
|
+
try { entries = fs.readdirSync(dir); } catch { return null; }
|
|
1387
|
+
const paths = new Set();
|
|
1388
|
+
for (const entry of entries) {
|
|
1389
|
+
if (!entry.endsWith('.json')) continue;
|
|
1390
|
+
let parsed = null;
|
|
1391
|
+
try { parsed = JSON.parse(fs.readFileSync(path.join(dir, entry), 'utf8')); } catch { parsed = null; }
|
|
1392
|
+
const record = parsed && typeof parsed === 'object' && parsed.paths && typeof parsed.paths === 'object' && !Array.isArray(parsed.paths) ? parsed.paths : null;
|
|
1393
|
+
if (!record) continue;
|
|
1394
|
+
for (const key of Object.keys(record)) {
|
|
1395
|
+
if (typeof key === 'string' && key !== '') paths.add(key.split(path.sep).join('/'));
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
return paths.size > 0 ? [...paths].sort() : null;
|
|
1399
|
+
}
|
|
1243
1400
|
function gitSnapshot() {
|
|
1244
1401
|
const { spawnSync } = require('child_process');
|
|
1245
1402
|
const git = (args) => {
|
|
@@ -1253,11 +1410,30 @@ function gitSnapshot() {
|
|
|
1253
1410
|
const statusText = git(['status', '--porcelain=v1', ...exclude]) || '';
|
|
1254
1411
|
const diffText = git(['diff', '--binary', 'HEAD', ...exclude]) || '';
|
|
1255
1412
|
const untracked = git(['ls-files', '--others', '--exclude-standard', ...exclude]) || '';
|
|
1413
|
+
const baselinePaths = typeof slug === 'string' && slug !== '' && SLUG_RE.test(slug)
|
|
1414
|
+
? writeScopeBaselinePaths(path.join(TEAM_ROOT, '.write-scope', slug))
|
|
1415
|
+
: null;
|
|
1416
|
+
const liveCount = liveSlugs().length;
|
|
1417
|
+
let scopeBasis = 'none';
|
|
1418
|
+
let scopeHash = null;
|
|
1419
|
+
if (baselinePaths !== null) {
|
|
1420
|
+
scopeBasis = 'write-scope';
|
|
1421
|
+
const spec = ['--', ...baselinePaths];
|
|
1422
|
+
const scopedStatus = git(['status', '--porcelain=v1', ...spec]) || '';
|
|
1423
|
+
const scopedDiff = git(['diff', '--binary', 'HEAD', ...spec]) || '';
|
|
1424
|
+
const scopedUntracked = git(['ls-files', '--others', '--exclude-standard', ...spec]) || '';
|
|
1425
|
+
scopeHash = crypto.createHash('sha256').update(`${scopedStatus}\u0000${scopedDiff}\u0000${scopedUntracked}`).digest('hex');
|
|
1426
|
+
} else if (liveCount <= 1) {
|
|
1427
|
+
scopeBasis = 'whole-tree';
|
|
1428
|
+
}
|
|
1256
1429
|
return {
|
|
1257
1430
|
head: head.trim(),
|
|
1258
1431
|
branch: branch === null ? null : branch.trim(),
|
|
1259
1432
|
dirtyFiles: statusText === '' ? 0 : statusText.split('\n').filter((line) => line !== '').length,
|
|
1260
|
-
|
|
1433
|
+
environmentHash: crypto.createHash('sha256').update(`${statusText}\u0000${diffText}\u0000${untracked}`).digest('hex'),
|
|
1434
|
+
scopeBasis,
|
|
1435
|
+
scopePaths: baselinePaths === null ? 0 : baselinePaths.length,
|
|
1436
|
+
scopeHash,
|
|
1261
1437
|
capturedAt: now,
|
|
1262
1438
|
};
|
|
1263
1439
|
}
|
|
@@ -1346,7 +1522,7 @@ function ensureVerificationSnapshot(dir, agent) {
|
|
|
1346
1522
|
fs.writeFileSync(temporary, JSON.stringify(verification, null, 2) + '\n');
|
|
1347
1523
|
fs.renameSync(temporary, file);
|
|
1348
1524
|
});
|
|
1349
|
-
appendMetric({ type: 'verification_recorded', at: now, kind: 'snapshot-only', agent: agent || null, head: snapshot.head,
|
|
1525
|
+
appendMetric({ type: 'verification_recorded', at: now, kind: 'snapshot-only', agent: agent || null, head: snapshot.head, environmentHash: snapshot.environmentHash, source: 'hook', attributionConfidence: 'high' });
|
|
1350
1526
|
}
|
|
1351
1527
|
|
|
1352
1528
|
function verificationFreshness(dir) {
|
|
@@ -1361,15 +1537,34 @@ function verificationFreshness(dir) {
|
|
|
1361
1537
|
// Judge the report the gate judges: its `tree:` header, not the wider worktree
|
|
1362
1538
|
// hash. A later edit inside the same report generation moved the hash while the
|
|
1363
1539
|
// gate still accepted the report, so the same fresh evidence warned twice.
|
|
1540
|
+
// The head comparison stays global (HEAD is shared across live slugs); the
|
|
1541
|
+
// dirty/hash dimension binds to the task's `scopeHash` when the evidence was
|
|
1542
|
+
// captured on a `write-scope` basis — the header's dirty count is a whole-tree
|
|
1543
|
+
// number and is not comparable to a scoped one, so the scoped hash is the
|
|
1544
|
+
// binding check for that basis, and a scope that can no longer be recomputed
|
|
1545
|
+
// reports `scope-unbound` (loud not-fresh, never a false fresh). Legacy
|
|
1546
|
+
// snapshots (no `scopeBasis`) and `whole-tree` snapshots keep today's
|
|
1547
|
+
// whole-tree comparison, reading the renamed field as
|
|
1548
|
+
// `environmentHash ?? worktreeHash`.
|
|
1364
1549
|
const found = evidenceReportText(dir);
|
|
1365
1550
|
const header = found === null ? null : found.text.match(REPORT_TREE_RE);
|
|
1366
1551
|
const reasons = [];
|
|
1367
1552
|
if (header) {
|
|
1368
1553
|
if (!current.head.startsWith(header[1])) reasons.push('head-changed');
|
|
1369
|
-
if (Number(header[2]) !== current.dirtyFiles) reasons.push('worktree-changed');
|
|
1370
1554
|
} else {
|
|
1371
1555
|
if (current.head !== snapshot.head) reasons.push('head-changed');
|
|
1372
|
-
|
|
1556
|
+
}
|
|
1557
|
+
const basis = typeof snapshot.scopeBasis === 'string' ? snapshot.scopeBasis : 'legacy';
|
|
1558
|
+
if (basis === 'write-scope') {
|
|
1559
|
+
if (current.scopeBasis !== 'write-scope') reasons.push('scope-unbound');
|
|
1560
|
+
else if (current.scopeHash !== snapshot.scopeHash) reasons.push('worktree-changed');
|
|
1561
|
+
} else if (basis === 'none') {
|
|
1562
|
+
reasons.push('scope-unbound');
|
|
1563
|
+
} else if (header) {
|
|
1564
|
+
if (Number(header[2]) !== current.dirtyFiles) reasons.push('worktree-changed');
|
|
1565
|
+
} else {
|
|
1566
|
+
const recorded = typeof snapshot.environmentHash === 'string' ? snapshot.environmentHash : snapshot.worktreeHash;
|
|
1567
|
+
if (current.environmentHash !== recorded) reasons.push('worktree-changed');
|
|
1373
1568
|
}
|
|
1374
1569
|
return { present: true, fresh: reasons.length === 0, reasons };
|
|
1375
1570
|
}
|
|
@@ -1388,10 +1583,32 @@ function noteVerificationFreshness(dir, agent) {
|
|
|
1388
1583
|
|
|
1389
1584
|
function finishActiveAttempt(forced) {
|
|
1390
1585
|
const resolved = forced || resolvedAttempt(); if (!resolved) return null;
|
|
1391
|
-
const
|
|
1586
|
+
const startedAtMs = Date.parse(resolved.entry.startedAt);
|
|
1587
|
+
const endedAtMs = Date.parse(now);
|
|
1588
|
+
const wallMs = Number.isFinite(startedAtMs) && Number.isFinite(endedAtMs) ? Math.max(0, endedAtMs - startedAtMs) : null;
|
|
1589
|
+
// Suspension, a gate or an operator pause inside the attempt is not work.
|
|
1590
|
+
const nonWorkMs = wallMs === null ? null : attemptIdleMs(startedAtMs, endedAtMs, readMetricsEvents());
|
|
1591
|
+
// `idleMs` is the remainder, not only the proven intervals: wall = active + idle.
|
|
1592
|
+
const activeMs = wallMs === null ? null : Math.min(Math.max(0, wallMs - nonWorkMs), attemptMaxMs());
|
|
1593
|
+
const idleMs = wallMs === null ? null : Math.max(0, wallMs - (activeMs ?? 0));
|
|
1392
1594
|
const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
|
|
1393
1595
|
const usage = sanitizeUsage(hookInput.usage);
|
|
1394
|
-
appendMetric({
|
|
1596
|
+
appendMetric({
|
|
1597
|
+
type: 'attempt_finished',
|
|
1598
|
+
at: now,
|
|
1599
|
+
attemptId: resolved.attemptId,
|
|
1600
|
+
stepIndex: typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : null,
|
|
1601
|
+
agent: resolved.entry.agent || null,
|
|
1602
|
+
outcome,
|
|
1603
|
+
durationMs: wallMs,
|
|
1604
|
+
wallMs,
|
|
1605
|
+
activeMs,
|
|
1606
|
+
idleMs,
|
|
1607
|
+
retryAfterFix: status.retryAfterFix || null,
|
|
1608
|
+
source: resolved.source || 'hook',
|
|
1609
|
+
attributionConfidence: resolved.confidence,
|
|
1610
|
+
...(usage ? { usage } : {}),
|
|
1611
|
+
});
|
|
1395
1612
|
if (resolved.entry && resolved.entry.agent === 'build-verifier') { ensureVerificationSnapshot(taskDir, resolved.entry.agent); noteVerificationFreshness(taskDir, resolved.entry.agent); }
|
|
1396
1613
|
const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
|
|
1397
1614
|
}
|
|
@@ -1468,10 +1685,38 @@ function completePipeline(statusPatch) {
|
|
|
1468
1685
|
out(`Pipeline complete for "${slug}". Run /technical-retro ${slug}.`);
|
|
1469
1686
|
process.exit(0);
|
|
1470
1687
|
}
|
|
1471
|
-
function beginHumanGate() {
|
|
1688
|
+
function beginHumanGate() {
|
|
1689
|
+
// A second stop for the same gate must not open a parallel one: the wait
|
|
1690
|
+
// would be counted twice and the pairing lost.
|
|
1691
|
+
if (status.activeHumanGateEventId && status.awaitingHumanGate) return;
|
|
1692
|
+
const eventId = `${status.metricsRunId || slug}:gate:${Date.now()}`;
|
|
1693
|
+
appendMetric({
|
|
1694
|
+
eventId,
|
|
1695
|
+
type: 'human_gate_started',
|
|
1696
|
+
at: now,
|
|
1697
|
+
stepIndex: typeof status.pipelineIndex === 'number' ? status.pipelineIndex : null,
|
|
1698
|
+
agent: status.currentAgent || null,
|
|
1699
|
+
source: 'hook',
|
|
1700
|
+
attributionConfidence: 'high',
|
|
1701
|
+
});
|
|
1702
|
+
status.activeHumanGateEventId = eventId;
|
|
1703
|
+
}
|
|
1472
1704
|
function endHumanGateIfResumed() {
|
|
1473
1705
|
if (!status.activeHumanGateEventId || status.awaitingHumanGate || status.state === 'awaiting_approval') return;
|
|
1474
|
-
|
|
1706
|
+
const events = readMetricsEvents();
|
|
1707
|
+
const started = events.find((event) => event && event.type === 'human_gate_started' && event.eventId === status.activeHumanGateEventId);
|
|
1708
|
+
const startedAt = started ? Date.parse(started.at) : NaN;
|
|
1709
|
+
// The gate ends when work resumed, not when a later stop noticed it.
|
|
1710
|
+
const resumed = Number.isFinite(startedAt)
|
|
1711
|
+
? events.find((event) => event && event.type === 'attempt_started' && Date.parse(event.at) > startedAt)
|
|
1712
|
+
: null;
|
|
1713
|
+
appendMetric({
|
|
1714
|
+
type: 'human_gate_ended',
|
|
1715
|
+
at: resumed ? resumed.at : now,
|
|
1716
|
+
gateStartedEventId: status.activeHumanGateEventId,
|
|
1717
|
+
source: 'hook',
|
|
1718
|
+
attributionConfidence: 'high',
|
|
1719
|
+
});
|
|
1475
1720
|
delete status.activeHumanGateEventId;
|
|
1476
1721
|
}
|
|
1477
1722
|
function completeTaskMetrics() {
|
|
@@ -1836,21 +2081,22 @@ function writeStatus(next) {
|
|
|
1836
2081
|
// attempt is finished before this check runs. An empty or unreadable file still
|
|
1837
2082
|
// counts as engaged (fail safe).
|
|
1838
2083
|
const PAUSE_SENTINELS = [
|
|
1839
|
-
path.join(process.cwd(), '.ai.local', 'STOP'),
|
|
1840
|
-
path.join(process.cwd(), '.ai.local', 'ESTOP'),
|
|
2084
|
+
{ file: path.join(process.cwd(), '.ai.local', 'STOP'), scope: 'repo' },
|
|
2085
|
+
{ file: path.join(process.cwd(), '.ai.local', 'ESTOP'), scope: 'repo-emergency' },
|
|
1841
2086
|
];
|
|
1842
2087
|
function readPauseSentinel() {
|
|
1843
2088
|
const sentinels = [...PAUSE_SENTINELS];
|
|
1844
2089
|
if (typeof slug === 'string' && slug !== '') {
|
|
1845
|
-
sentinels.push(path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug, 'STOP'));
|
|
2090
|
+
sentinels.push({ file: path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug, 'STOP'), scope: 'task' });
|
|
1846
2091
|
}
|
|
1847
|
-
for (const
|
|
2092
|
+
for (const sentinel of sentinels) {
|
|
2093
|
+
const file = sentinel.file;
|
|
1848
2094
|
let stat = null;
|
|
1849
2095
|
try { stat = fs.statSync(file); } catch (error) {
|
|
1850
2096
|
if (error && error.code === 'ENOENT') continue;
|
|
1851
2097
|
// A permission or I/O error is not proof of absence: fail safe and say so.
|
|
1852
2098
|
process.stderr.write(`WARNING: ${slug}: cannot stat pause sentinel ${path.relative(process.cwd(), file).split(path.sep).join('/')} (${error && error.message ? error.message : String(error)}); treating it as engaged.\n`);
|
|
1853
|
-
return { engaged: true, file: path.relative(process.cwd(), file).split(path.sep).join('/'), reason: 'sentinel stat failed' };
|
|
2099
|
+
return { engaged: true, file: path.relative(process.cwd(), file).split(path.sep).join('/'), scope: sentinel.scope, at: null, reason: 'sentinel stat failed' };
|
|
1854
2100
|
}
|
|
1855
2101
|
if (!stat || !stat.isFile()) continue;
|
|
1856
2102
|
let reason = '';
|
|
@@ -1868,19 +2114,52 @@ function readPauseSentinel() {
|
|
|
1868
2114
|
return {
|
|
1869
2115
|
engaged: true,
|
|
1870
2116
|
file: path.relative(process.cwd(), file).split(path.sep).join('/'),
|
|
2117
|
+
scope: sentinel.scope,
|
|
2118
|
+
// The pause started when the sentinel was written, not when a hook noticed it.
|
|
2119
|
+
at: new Date(stat.mtimeMs).toISOString(),
|
|
1871
2120
|
reason: reason.replace(/\s+/g, ' ').slice(0, 160),
|
|
1872
2121
|
};
|
|
1873
2122
|
}
|
|
1874
|
-
return { engaged: false, file: null, reason: '' };
|
|
2123
|
+
return { engaged: false, file: null, scope: null, at: null, reason: '' };
|
|
1875
2124
|
}
|
|
1876
2125
|
function pausedNotice(pause) {
|
|
1877
2126
|
const where = pause && pause.file ? pause.file : '.ai.local/STOP';
|
|
1878
2127
|
const because = pause && pause.reason ? ` (${pause.reason})` : '';
|
|
1879
2128
|
return `[chain-team-phases] ${slug}: paused — operator sentinel ${where} is engaged${because}. No step advanced and no handoff was emitted. Remove the sentinel and run /task-continue ${slug}.`;
|
|
1880
2129
|
}
|
|
2130
|
+
// A pause is a duration in the ledger, not only a file. One `task_paused` per
|
|
2131
|
+
// engagement and one `task_resumed` when the sentinel is gone.
|
|
2132
|
+
function recordPauseEngaged(pause) {
|
|
2133
|
+
if (openPauseIndex(readMetricsEvents()) !== -1) return;
|
|
2134
|
+
appendMetric({
|
|
2135
|
+
type: 'task_paused',
|
|
2136
|
+
at: pause.at || now,
|
|
2137
|
+
scope: pause.scope || 'repo',
|
|
2138
|
+
file: pause.file || null,
|
|
2139
|
+
reason: pause.reason || null,
|
|
2140
|
+
source: 'hook',
|
|
2141
|
+
attributionConfidence: 'high',
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2144
|
+
function recordPauseResumed() {
|
|
2145
|
+
const events = readMetricsEvents();
|
|
2146
|
+
const index = openPauseIndex(events);
|
|
2147
|
+
if (index === -1) return;
|
|
2148
|
+
appendMetric({
|
|
2149
|
+
type: 'task_resumed',
|
|
2150
|
+
at: now,
|
|
2151
|
+
pausedSince: events[index].at || null,
|
|
2152
|
+
source: 'hook',
|
|
2153
|
+
attributionConfidence: 'high',
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
1881
2156
|
function pauseBlocksAdvance() {
|
|
1882
2157
|
const pause = readPauseSentinel();
|
|
1883
|
-
if (!pause.engaged)
|
|
2158
|
+
if (!pause.engaged) {
|
|
2159
|
+
recordPauseResumed();
|
|
2160
|
+
return null;
|
|
2161
|
+
}
|
|
2162
|
+
recordPauseEngaged(pause);
|
|
1884
2163
|
writeStatus({ state: 'paused', phase: 'paused' });
|
|
1885
2164
|
out(pausedNotice(pause));
|
|
1886
2165
|
return pause;
|
|
@@ -2319,6 +2598,96 @@ function countDebugImplementationRetries() {
|
|
|
2319
2598
|
return 0;
|
|
2320
2599
|
}
|
|
2321
2600
|
}
|
|
2601
|
+
function replanDecisionCount() {
|
|
2602
|
+
try {
|
|
2603
|
+
const text = fs.readFileSync(path.join(taskDir, '.memlog.md'), 'utf8');
|
|
2604
|
+
const matches = text.match(/replan rev\s+\d+\s*(?:→|->)\s*\d+/g);
|
|
2605
|
+
return matches ? matches.length : 0;
|
|
2606
|
+
} catch {
|
|
2607
|
+
return 0;
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
function changesRequestedCount(agent) {
|
|
2611
|
+
if (typeof agent !== 'string' || agent === '') return 0;
|
|
2612
|
+
try {
|
|
2613
|
+
const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
|
|
2614
|
+
const events = Array.isArray(metrics.events) ? metrics.events : [];
|
|
2615
|
+
const needle = `:${agent}:`;
|
|
2616
|
+
return events.filter((event) => event && event.type === 'attempt_finished' && event.outcome === 'changes_requested' && typeof event.attemptId === 'string' && event.attemptId.includes(needle)).length;
|
|
2617
|
+
} catch {
|
|
2618
|
+
return 0;
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
function holdDesignEscalation(agent, mode, reviewerStepIndex) {
|
|
2622
|
+
if (changesRequestedCount(agent) < 2) return false;
|
|
2623
|
+
beginHumanGate();
|
|
2624
|
+
writeStatus({
|
|
2625
|
+
awaitingHumanGate: true,
|
|
2626
|
+
state: 'awaiting_approval',
|
|
2627
|
+
currentAgent: agent,
|
|
2628
|
+
phase: 'human_gate',
|
|
2629
|
+
designEscalation: {
|
|
2630
|
+
agent,
|
|
2631
|
+
mode,
|
|
2632
|
+
reviewerStepIndex: Number.isInteger(reviewerStepIndex) ? reviewerStepIndex : null,
|
|
2633
|
+
priorReplanCount: replanDecisionCount(),
|
|
2634
|
+
},
|
|
2635
|
+
parallelCompleted: [],
|
|
2636
|
+
parallelOutcomes: {},
|
|
2637
|
+
waveSteps: [],
|
|
2638
|
+
waveId: null,
|
|
2639
|
+
retryAfterFix: null,
|
|
2640
|
+
retryAfterFixStepIndex: null,
|
|
2641
|
+
});
|
|
2642
|
+
out(`${agent} requested changes for slug "${slug}" a second time in this task. Append a \`.memlog.md\` line \`decision: replan rev N → N+1\` that changes the model, then resume via /task-continue. The next attempt is not dispatched until that line exists.`);
|
|
2643
|
+
process.exit(0);
|
|
2644
|
+
}
|
|
2645
|
+
function resumeDesignEscalation(escalation, resumeSteps) {
|
|
2646
|
+
steps = resumeSteps;
|
|
2647
|
+
const reviewer = escalation.agent;
|
|
2648
|
+
const reviewerStepIndex = Number.isInteger(escalation.reviewerStepIndex)
|
|
2649
|
+
? escalation.reviewerStepIndex
|
|
2650
|
+
: (typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0);
|
|
2651
|
+
status.pipelineIndex = reviewerStepIndex;
|
|
2652
|
+
delete status.designEscalation;
|
|
2653
|
+
if (escalation.mode === 'graph') {
|
|
2654
|
+
const producerIndex = resolveProducerStepIndex('feature-developer', reviewerStepIndex);
|
|
2655
|
+
if (producerIndex < 0) {
|
|
2656
|
+
out(`${reviewer} requested changes for slug "${slug}" but no graph ancestor authors fixes. Read the review artifact. Resume only via /task-continue.`);
|
|
2657
|
+
process.exit(0);
|
|
2658
|
+
}
|
|
2659
|
+
appendMetric({ type: 'retry_scheduled', at: now, attemptId: status.lastCompletedAttempt?.attemptId || null, nextAgent: 'feature-developer', retryAfterFix: reviewer, source: 'hook', attributionConfidence: 'high' });
|
|
2660
|
+
invalidateFrom(producerIndex, reviewerStepIndex);
|
|
2661
|
+
writeStatus({ state: 'in_progress', phase: 'executing', awaitingHumanGate: false, waveSteps: [], waveId: null, retryAfterFix: null, retryAfterFixStepIndex: null, parallelCompleted: [], parallelOutcomes: {} });
|
|
2662
|
+
if (!dispatchReadyWave(`Design escalation for ${reviewer} accepted; re-dispatching unsatisfied steps.`)) out(noProgressNotice());
|
|
2663
|
+
process.exit(0);
|
|
2664
|
+
}
|
|
2665
|
+
let verifierStepIndex = -1;
|
|
2666
|
+
for (let index = reviewerStepIndex - 1; index >= 0; index -= 1) {
|
|
2667
|
+
if (getStepAgents(steps[index]).includes('build-verifier')) {
|
|
2668
|
+
verifierStepIndex = index;
|
|
2669
|
+
break;
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
const retryGate = verifierStepIndex >= 0 ? 'build-verifier' : reviewer;
|
|
2673
|
+
const retryAfterFixStepIndex = verifierStepIndex >= 0 ? verifierStepIndex : reviewerStepIndex;
|
|
2674
|
+
const developerIndex = scheduleRetry('feature-developer', reviewer, status.lastCompletedAttempt);
|
|
2675
|
+
if (developerIndex < 0) {
|
|
2676
|
+
out(`${reviewer} requested changes for slug "${slug}" but this pipeline has no feature-developer step. Read the review artifact. Resume only via /task-continue.`);
|
|
2677
|
+
process.exit(0);
|
|
2678
|
+
}
|
|
2679
|
+
writeStatus({
|
|
2680
|
+
pipelineIndex: developerIndex,
|
|
2681
|
+
currentAgent: 'feature-developer',
|
|
2682
|
+
state: 'in_progress',
|
|
2683
|
+
phase: 'executing',
|
|
2684
|
+
awaitingHumanGate: false,
|
|
2685
|
+
retryAfterFix: retryGate,
|
|
2686
|
+
retryAfterFixStepIndex,
|
|
2687
|
+
});
|
|
2688
|
+
out(handoffForAgent('feature-developer', steps[developerIndex]?.scope, steps[developerIndex]) + ` After fixes, re-run ${retryGate}.`);
|
|
2689
|
+
process.exit(0);
|
|
2690
|
+
}
|
|
2322
2691
|
function featureDeveloperAlreadyStarted() {
|
|
2323
2692
|
try {
|
|
2324
2693
|
const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
|
|
@@ -2751,6 +3120,19 @@ if (hookInput.action === 'bootstrap') {
|
|
|
2751
3120
|
function readMetricsLedger() {
|
|
2752
3121
|
try { return JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8')); } catch { return null; }
|
|
2753
3122
|
}
|
|
3123
|
+
function readMetricsEvents() {
|
|
3124
|
+
const ledger = readMetricsLedger();
|
|
3125
|
+
return ledger && Array.isArray(ledger.events) ? ledger.events : [];
|
|
3126
|
+
}
|
|
3127
|
+
/** Index of the `task_paused` that no `task_resumed` closed, or -1. */
|
|
3128
|
+
function openPauseIndex(events) {
|
|
3129
|
+
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
3130
|
+
const type = events[index] && events[index].type;
|
|
3131
|
+
if (type === 'task_resumed') return -1;
|
|
3132
|
+
if (type === 'task_paused') return index;
|
|
3133
|
+
}
|
|
3134
|
+
return -1;
|
|
3135
|
+
}
|
|
2754
3136
|
|
|
2755
3137
|
if (hookInput.action === 'out_of_band_start') {
|
|
2756
3138
|
if (pauseBlocksAdvance()) process.exit(0);
|
|
@@ -2817,6 +3199,11 @@ if (hookInput.action === 'out_of_band_end') {
|
|
|
2817
3199
|
|
|
2818
3200
|
if (hookInput.action === 'end_human_gate') {
|
|
2819
3201
|
if (pauseBlocksAdvance()) process.exit(0);
|
|
3202
|
+
const designEscalation = status.designEscalation && typeof status.designEscalation === 'object' ? status.designEscalation : null;
|
|
3203
|
+
if (designEscalation && replanDecisionCount() <= (Number(designEscalation.priorReplanCount) || 0)) {
|
|
3204
|
+
out(`Design escalation for slug "${slug}" is still open. Append a \`.memlog.md\` line \`decision: replan rev N → N+1\` that changes the model, then resume via /task-continue.`);
|
|
3205
|
+
process.exit(0);
|
|
3206
|
+
}
|
|
2820
3207
|
// Only advance when a gate was actually open. A duplicate or retried
|
|
2821
3208
|
// end_human_gate must be a no-op, not a silent pipeline skip.
|
|
2822
3209
|
const gateWasOpen = Boolean(status.activeHumanGateEventId) || status.awaitingHumanGate === true;
|
|
@@ -2848,6 +3235,12 @@ if (hookInput.action === 'end_human_gate') {
|
|
|
2848
3235
|
});
|
|
2849
3236
|
delete status.activeHumanGateEventId;
|
|
2850
3237
|
}
|
|
3238
|
+
if (designEscalation && hookInput.activateNext && fs.existsSync(pipelinePath)) {
|
|
3239
|
+
let designPipeline = null;
|
|
3240
|
+
try { designPipeline = JSON.parse(fs.readFileSync(pipelinePath, 'utf8')); } catch {}
|
|
3241
|
+
const designSteps = designPipeline && Array.isArray(designPipeline.steps) ? designPipeline.steps : [];
|
|
3242
|
+
resumeDesignEscalation(designEscalation, designSteps);
|
|
3243
|
+
}
|
|
2851
3244
|
if (gateWasOpen && hookInput.activateNext && fs.existsSync(pipelinePath)) {
|
|
2852
3245
|
let resumePipeline = null;
|
|
2853
3246
|
try { resumePipeline = JSON.parse(fs.readFileSync(pipelinePath, 'utf8')); } catch {}
|
|
@@ -2987,10 +3380,12 @@ if (status.state === 'awaiting_artifact_receipt') {
|
|
|
2987
3380
|
const pause = readPauseSentinel();
|
|
2988
3381
|
if (pause.engaged) {
|
|
2989
3382
|
if (artifactStallMessage) process.stderr.write(artifactStallMessage + '\n');
|
|
3383
|
+
recordPauseEngaged(pause);
|
|
2990
3384
|
writeStatus({ state: 'paused', phase: 'paused' });
|
|
2991
3385
|
out(pausedNotice(pause));
|
|
2992
3386
|
process.exit(0);
|
|
2993
3387
|
}
|
|
3388
|
+
recordPauseResumed();
|
|
2994
3389
|
writeStatus({});
|
|
2995
3390
|
emitArtifactStall(artifactStallMessage, !wasWaitingForReceipt);
|
|
2996
3391
|
process.exit(0);
|
|
@@ -3214,6 +3609,7 @@ if (waveIndexes) {
|
|
|
3214
3609
|
out(`${retryReviewer} requested changes for slug "${slug}" but no graph ancestor authors fixes. Read the review artifact. Resume only via /task-continue.`);
|
|
3215
3610
|
process.exit(0);
|
|
3216
3611
|
}
|
|
3612
|
+
holdDesignEscalation(retryReviewer, 'graph', reviewerStepIndex);
|
|
3217
3613
|
const graphPredecessor = outcomes[retryReviewer]
|
|
3218
3614
|
? { attemptId: outcomes[retryReviewer].attemptId, confidence: outcomes[retryReviewer].confidence }
|
|
3219
3615
|
: finishedAttempt;
|
|
@@ -3226,6 +3622,7 @@ if (waveIndexes) {
|
|
|
3226
3622
|
if (!dispatchReadyWave(`Step ${reviewerStepIndex} (${retryReviewer}) requested changes; re-dispatching unsatisfied steps.`)) out(noProgressNotice());
|
|
3227
3623
|
process.exit(0);
|
|
3228
3624
|
}
|
|
3625
|
+
holdDesignEscalation(retryReviewer, 'linear', idx);
|
|
3229
3626
|
const retryAfterFixStepIndex = idx;
|
|
3230
3627
|
const predecessor = outcomes[retryReviewer]
|
|
3231
3628
|
? {
|
|
@@ -3325,6 +3722,7 @@ if (status.state === 'changes_requested') {
|
|
|
3325
3722
|
process.exit(0);
|
|
3326
3723
|
}
|
|
3327
3724
|
const reviewerStepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
|
|
3725
|
+
holdDesignEscalation(reviewer, 'linear', reviewerStepIndex);
|
|
3328
3726
|
let verifierStepIndex = -1;
|
|
3329
3727
|
for (let index = reviewerStepIndex - 1; index >= 0; index -= 1) {
|
|
3330
3728
|
if (getStepAgents(steps[index]).includes('build-verifier')) {
|
|
@@ -3458,26 +3856,21 @@ const fs = require('fs');
|
|
|
3458
3856
|
const path = require('path');
|
|
3459
3857
|
const { spawnSync } = require('child_process');
|
|
3460
3858
|
|
|
3859
|
+
// Slug binding for the seams below is inside the projection markers. The
|
|
3860
|
+
// dualwrite harness executes that region alone, so the resolver has to live
|
|
3861
|
+
// there or a fresh store is never created.
|
|
3862
|
+
|
|
3461
3863
|
// Dev-server cleanup: terminal task state only. `processes.mjs` proves
|
|
3462
3864
|
// ownership from `.ai.local/.processes/leases/<name>.json` before any signal,
|
|
3463
3865
|
// so a foreign process is never touched. A refusal or timeout is a warning,
|
|
3464
|
-
// never a hook failure.
|
|
3866
|
+
// never a hook failure. The slug is the env binding only — no pointer
|
|
3867
|
+
// fallback: cleanup matters only on terminal state, and the main hook always
|
|
3868
|
+
// knows the slug it resolved.
|
|
3465
3869
|
function stopOwnedDevServers() {
|
|
3466
3870
|
const processes = path.join(process.cwd(), '.ai.local', 'scripts', 'processes.mjs');
|
|
3467
3871
|
if (!fs.existsSync(processes)) return;
|
|
3468
|
-
const
|
|
3469
|
-
|
|
3470
|
-
if (!slug) {
|
|
3471
|
-
try {
|
|
3472
|
-
const active = JSON.parse(
|
|
3473
|
-
fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'active-task.json'), 'utf8'),
|
|
3474
|
-
);
|
|
3475
|
-
slug = typeof active.slug === 'string' ? active.slug : '';
|
|
3476
|
-
} catch {
|
|
3477
|
-
return;
|
|
3478
|
-
}
|
|
3479
|
-
}
|
|
3480
|
-
if (slug.length === 0 || slug.length > 48 || !SLUG_RE.test(slug)) return;
|
|
3872
|
+
const slug = typeof process.env.TEAM_TASK_SLUG === 'string' ? process.env.TEAM_TASK_SLUG : '';
|
|
3873
|
+
if (slug.length === 0 || slug.length > 48 || !POSTFLIGHT_SLUG_RE.test(slug)) return;
|
|
3481
3874
|
let state = '';
|
|
3482
3875
|
try {
|
|
3483
3876
|
const status = JSON.parse(
|
|
@@ -3705,6 +4098,95 @@ if (!input || input.status !== 'completed') {
|
|
|
3705
4098
|
// This is a plain region marker, not a `hook-slot`: the block is identical in
|
|
3706
4099
|
// all 40 rendered bodies and needs no per-stack fragment.
|
|
3707
4100
|
// <<<team-db-projection>>>
|
|
4101
|
+
// Postflight slug binding, shared by the seams below: the env slug first,
|
|
4102
|
+
// then the per-session lease (the same file the main hook and the OpenCode
|
|
4103
|
+
// task-status plugin write), and the active-task.json projection only as a
|
|
4104
|
+
// last resort. Containment comes from validating every derivation point with
|
|
4105
|
+
// the slug grammar (the same pattern as the hook's SLUG_RE), so `tasks/<slug>`
|
|
4106
|
+
// cannot escape the tree on any postflight path. This region is extracted and
|
|
4107
|
+
// executed alone by the dualwrite harness, so the resolver stays inside the
|
|
4108
|
+
// markers.
|
|
4109
|
+
const TERMINAL_STATES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
|
|
4110
|
+
const POSTFLIGHT_SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
4111
|
+
function postflightLiveSlugs() {
|
|
4112
|
+
const tasksDir = path.join(process.cwd(), '.ai.local', 'team', 'tasks');
|
|
4113
|
+
let entries;
|
|
4114
|
+
try {
|
|
4115
|
+
entries = fs.readdirSync(tasksDir, { withFileTypes: true });
|
|
4116
|
+
} catch (error) {
|
|
4117
|
+
return [];
|
|
4118
|
+
}
|
|
4119
|
+
const live = [];
|
|
4120
|
+
for (const entry of entries) {
|
|
4121
|
+
if (!entry.isDirectory()) continue;
|
|
4122
|
+
try {
|
|
4123
|
+
const status = JSON.parse(fs.readFileSync(path.join(tasksDir, entry.name, 'status.json'), 'utf8'));
|
|
4124
|
+
if (status && typeof status.state === 'string' && !TERMINAL_STATES.has(status.state)) live.push(entry.name);
|
|
4125
|
+
} catch (error) {
|
|
4126
|
+
/* an unreadable status is not a live slug */
|
|
4127
|
+
}
|
|
4128
|
+
}
|
|
4129
|
+
return live.sort();
|
|
4130
|
+
}
|
|
4131
|
+
function postflightPointerSlug() {
|
|
4132
|
+
// Last-resort read of the UI projection; both the projection shape
|
|
4133
|
+
// `{"slugs": [...]}` and the legacy single-slot `{"slug"}` are accepted
|
|
4134
|
+
// forever. A multi-slug projection resolves to its first entry; the
|
|
4135
|
+
// live-scan guard in postflightResolveSlug decides whether that
|
|
4136
|
+
// resolution is safe to act on.
|
|
4137
|
+
try {
|
|
4138
|
+
const active = JSON.parse(
|
|
4139
|
+
fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'active-task.json'), 'utf8'),
|
|
4140
|
+
);
|
|
4141
|
+
const slugs = Array.isArray(active.slugs)
|
|
4142
|
+
? active.slugs
|
|
4143
|
+
: (typeof active.slug === 'string' && active.slug ? [active.slug] : []);
|
|
4144
|
+
const candidate = typeof slugs[0] === 'string' ? slugs[0] : '';
|
|
4145
|
+
if (candidate.length > 48 || !POSTFLIGHT_SLUG_RE.test(candidate)) return '';
|
|
4146
|
+
return candidate;
|
|
4147
|
+
} catch (error) {
|
|
4148
|
+
return '';
|
|
4149
|
+
}
|
|
4150
|
+
}
|
|
4151
|
+
function postflightSessionId() {
|
|
4152
|
+
const raw = process.env.OPENCODE_SESSION_ID || process.env.AI_RULES_SESSION_ID || '';
|
|
4153
|
+
return /^[A-Za-z0-9_-]{1,128}$/.test(raw) ? raw : '';
|
|
4154
|
+
}
|
|
4155
|
+
function postflightLeaseSlug() {
|
|
4156
|
+
// Same file and TTL as the main hook. A pointer fallback must not win while
|
|
4157
|
+
// this session already has a pin.
|
|
4158
|
+
const id = postflightSessionId();
|
|
4159
|
+
if (!id) return '';
|
|
4160
|
+
try {
|
|
4161
|
+
const file = path.join(process.cwd(), '.ai.local', 'team', '.session-leases', `${id}.json`);
|
|
4162
|
+
if (Date.now() - fs.statSync(file).mtimeMs > 7 * 24 * 60 * 60 * 1000) return '';
|
|
4163
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
4164
|
+
const slug = parsed && typeof parsed.slug === 'string' ? parsed.slug : '';
|
|
4165
|
+
if (slug.length > 48 || !POSTFLIGHT_SLUG_RE.test(slug)) return '';
|
|
4166
|
+
return slug;
|
|
4167
|
+
} catch (error) {
|
|
4168
|
+
return '';
|
|
4169
|
+
}
|
|
4170
|
+
}
|
|
4171
|
+
function postflightResolveSlug() {
|
|
4172
|
+
// An env slug present but invalid is a stop, not a fallback: the projection
|
|
4173
|
+
// must never route around a bad explicit binding.
|
|
4174
|
+
const envSlug = typeof process.env.TEAM_TASK_SLUG === 'string' ? process.env.TEAM_TASK_SLUG : '';
|
|
4175
|
+
if (envSlug !== '') {
|
|
4176
|
+
if (envSlug.length <= 48 && POSTFLIGHT_SLUG_RE.test(envSlug)) return { slug: envSlug };
|
|
4177
|
+
return { slug: '' };
|
|
4178
|
+
}
|
|
4179
|
+
const leaseSlug = postflightLeaseSlug();
|
|
4180
|
+
if (leaseSlug) return { slug: leaseSlug };
|
|
4181
|
+
const pointerSlug = postflightPointerSlug();
|
|
4182
|
+
if (!pointerSlug) return { slug: '' };
|
|
4183
|
+
const live = postflightLiveSlugs();
|
|
4184
|
+
for (let index = 0; index < live.length; index += 1) {
|
|
4185
|
+
if (live[index] !== pointerSlug) return { slug: '', pointerLiveSlugs: live.length };
|
|
4186
|
+
}
|
|
4187
|
+
return { slug: pointerSlug };
|
|
4188
|
+
}
|
|
4189
|
+
|
|
3708
4190
|
function teamDbTruthy(value) {
|
|
3709
4191
|
if (typeof value !== 'string') return false;
|
|
3710
4192
|
const normalized = value.trim().toLowerCase();
|
|
@@ -3761,17 +4243,17 @@ function teamDbProject() {
|
|
|
3761
4243
|
try {
|
|
3762
4244
|
const env = process.env;
|
|
3763
4245
|
if (teamDbTruthy(env.AI_RULES_TEAM_DB_DISABLE)) return;
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
} catch (error) {
|
|
4246
|
+
const resolved = postflightResolveSlug();
|
|
4247
|
+
if (resolved.pointerLiveSlugs) {
|
|
4248
|
+
// A pointer-resolved projection under other live slugs cannot say
|
|
4249
|
+
// which task this stop belongs to. Skipping is safe: the projection
|
|
4250
|
+
// converges on the next `team-db sync`, and the files stay
|
|
4251
|
+
// authoritative.
|
|
4252
|
+
process.stderr.write(`WARNING: pointer-resolved projection skipped; ${resolved.pointerLiveSlugs} live slugs\n`);
|
|
3772
4253
|
return;
|
|
3773
4254
|
}
|
|
3774
|
-
|
|
4255
|
+
const slug = resolved.slug;
|
|
4256
|
+
if (!slug) return;
|
|
3775
4257
|
const taskDir = path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug);
|
|
3776
4258
|
if (!fs.existsSync(path.join(taskDir, 'status.json'))) return;
|
|
3777
4259
|
const script = path.join(process.cwd(), '.ai.local', 'scripts', 'team-db.mjs');
|
|
@@ -3917,13 +4399,11 @@ teamDbTrackerDrain();
|
|
|
3917
4399
|
let pipeline = null;
|
|
3918
4400
|
try {
|
|
3919
4401
|
const teamRoot = path.join(process.cwd(), '.ai.local', 'team');
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
//
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
const POSTFLIGHT_SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
3926
|
-
if (pipelineSlug.length <= 48 && POSTFLIGHT_SLUG_RE.test(pipelineSlug)) {
|
|
4402
|
+
// Same binding as the seams above: env slug first, projection last resort.
|
|
4403
|
+
// A pointer resolution refused by the live-scan guard is a silent policy
|
|
4404
|
+
// skip here — the ratchet is already silent-by-design for light/spike.
|
|
4405
|
+
const pipelineSlug = postflightResolveSlug().slug;
|
|
4406
|
+
if (pipelineSlug) {
|
|
3927
4407
|
pipeline = JSON.parse(fs.readFileSync(path.join(teamRoot, 'tasks', pipelineSlug, 'pipeline.json'), 'utf8'));
|
|
3928
4408
|
}
|
|
3929
4409
|
} catch {
|