@bonesofspring/ai-rules 0.2.87 → 0.2.91
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 +83 -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-COMPATIBILITY.md +2 -1
- package/docs/OPENCODE.md +27 -5
- 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/output-guard/README.md +4 -3
- package/presets/opencode/plugins/output-guard/index.ts +4 -3
- package/presets/opencode/plugins/output-guard/rewrite.ts +1 -2
- package/presets/opencode/plugins/rule-attach/README.md +1 -1
- package/presets/opencode/plugins/rule-attach/index.ts +23 -4
- package/presets/opencode/plugins/settings-guard/README.md +28 -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 +13 -8
- package/presets/opencode/plugins/task-status/deepseek.ts +23 -8
- 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 +168 -9
- package/presets/opencode/plugins/task-status/timing.ts +244 -0
- package/presets/opencode/plugins/task-status/tui.tsx +12 -3
- 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
|
@@ -14,7 +14,10 @@ const fs = require('fs');
|
|
|
14
14
|
const path = require('path');
|
|
15
15
|
const crypto = require('crypto');
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// Worktree hooks set AI_RULES_TEAM_ROOT so cwd does not open a second store.
|
|
18
|
+
const TEAM_ROOT = process.env.AI_RULES_TEAM_ROOT
|
|
19
|
+
? path.resolve(process.env.AI_RULES_TEAM_ROOT)
|
|
20
|
+
: path.join(process.cwd(), '.ai.local', 'team');
|
|
18
21
|
|
|
19
22
|
const inputRaw = process.env.INPUT || '';
|
|
20
23
|
let hookInput;
|
|
@@ -37,11 +40,15 @@ if (hookInput.status !== 'completed') {
|
|
|
37
40
|
// Slug resolution, strongest first:
|
|
38
41
|
// 1. TEAM_TASK_SLUG — the orchestrator's explicit binding for this call.
|
|
39
42
|
// 2. the per-session lease `.ai.local/team/.session-leases/<session>.json`,
|
|
40
|
-
// written by an earlier call that carried (1)
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
43
|
+
// written by an earlier call that carried (1), or by the OpenCode
|
|
44
|
+
// task-status plugin when it pinned this tab.
|
|
45
|
+
// 3. active-task.json — a UI projection of the live slugs (rebuilt by
|
|
46
|
+
// `team-db sync`), read only as a fallback for older hosts; when more
|
|
47
|
+
// than one slug is live the resolution is ambiguous and refused below.
|
|
48
|
+
// Only (1) writes the lease from this hook. The OpenCode task-status plugin
|
|
49
|
+
// writes the same file when it pins a tab, and `shell.env` injects the session
|
|
50
|
+
// id so this lookup sees that pin. A pointer fallback never writes a lease:
|
|
51
|
+
// that would let one session inherit another's task.
|
|
45
52
|
const SESSION_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
46
53
|
const LEASE_ROOT = path.join(TEAM_ROOT, '.session-leases');
|
|
47
54
|
const LEASE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
@@ -105,21 +112,24 @@ if (!slug && sessionId) {
|
|
|
105
112
|
}
|
|
106
113
|
}
|
|
107
114
|
if (!slug) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (!fs.existsSync(activePath)) {
|
|
111
|
-
process.stdout.write('{}');
|
|
112
|
-
process.exit(0);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
let active;
|
|
115
|
+
let active = null;
|
|
116
116
|
try {
|
|
117
|
-
active = JSON.parse(fs.readFileSync(
|
|
117
|
+
active = JSON.parse(fs.readFileSync(path.join(TEAM_ROOT, 'active-task.json'), 'utf8'));
|
|
118
118
|
} catch {
|
|
119
|
+
active = null;
|
|
120
|
+
}
|
|
121
|
+
// Back-compat reader: the projection shape `{"slugs": [...]}` (rebuilt by
|
|
122
|
+
// `team-db sync`) and the legacy single-slot `{"slug"}` shape are accepted
|
|
123
|
+
// forever. An empty or unreadable projection is identical to a missing
|
|
124
|
+
// file: a `{}` no-op.
|
|
125
|
+
const pointerSlugs = active && Array.isArray(active.slugs)
|
|
126
|
+
? active.slugs
|
|
127
|
+
: (active && typeof active.slug === 'string' && active.slug ? [active.slug] : []);
|
|
128
|
+
if (pointerSlugs.length === 0) {
|
|
119
129
|
process.stdout.write('{}');
|
|
120
130
|
process.exit(0);
|
|
121
131
|
}
|
|
122
|
-
slug =
|
|
132
|
+
slug = pointerSlugs[0];
|
|
123
133
|
slugSource = 'active-task.json';
|
|
124
134
|
}
|
|
125
135
|
// Reject non-kebab / traversal slugs: the runtime writes status.json and
|
|
@@ -129,6 +139,44 @@ if (typeof slug !== 'string' || slug.length > 48 || !SLUG_RE.test(slug)) {
|
|
|
129
139
|
process.stdout.write('{}');
|
|
130
140
|
process.exit(0);
|
|
131
141
|
}
|
|
142
|
+
// Canonical live-slug scan over the task store, never the pointer: a slug is
|
|
143
|
+
// live when `tasks/<name>/status.json` parses and its state is not terminal.
|
|
144
|
+
const TERMINAL_STATES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
|
|
145
|
+
function liveSlugs() {
|
|
146
|
+
const tasksDir = path.join(TEAM_ROOT, 'tasks');
|
|
147
|
+
let entries;
|
|
148
|
+
try {
|
|
149
|
+
entries = fs.readdirSync(tasksDir, { withFileTypes: true });
|
|
150
|
+
} catch {
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
const live = [];
|
|
154
|
+
for (const entry of entries) {
|
|
155
|
+
if (!entry.isDirectory()) continue;
|
|
156
|
+
try {
|
|
157
|
+
const status = JSON.parse(fs.readFileSync(path.join(tasksDir, entry.name, 'status.json'), 'utf8'));
|
|
158
|
+
if (status && typeof status.state === 'string' && !TERMINAL_STATES.has(status.state)) live.push(entry.name);
|
|
159
|
+
} catch {}
|
|
160
|
+
}
|
|
161
|
+
return live.sort();
|
|
162
|
+
}
|
|
163
|
+
// Level-3 (pointer) resolution guard: when the slug came from
|
|
164
|
+
// active-task.json and any other live slug exists, the pointer cannot say
|
|
165
|
+
// which task this call belongs to. Refuse loudly — `ok:false` with exit 0,
|
|
166
|
+
// the hook's refusal convention (a non-zero exit would be read as a blocking
|
|
167
|
+
// platform error by Stop-class hook consumers) — so the caller re-runs with
|
|
168
|
+
// `TEAM_TASK_SLUG=<slug>` instead of silently acting on the wrong task.
|
|
169
|
+
// Exactly one live slug keeps today's warning-only behaviour, so older hosts
|
|
170
|
+
// keep working until they pass the env.
|
|
171
|
+
if (slugSource === 'active-task.json') {
|
|
172
|
+
const live = liveSlugs();
|
|
173
|
+
if (live.some((name) => name !== slug)) {
|
|
174
|
+
const shown = live.slice(0, 5).join(', ');
|
|
175
|
+
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`);
|
|
176
|
+
process.stdout.write(JSON.stringify({ ok: false, reason: 'active-task-pointer-ambiguous', slug, liveSlugs: live }));
|
|
177
|
+
process.exit(0);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
132
180
|
if (slugSource !== 'TEAM_TASK_SLUG') {
|
|
133
181
|
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`);
|
|
134
182
|
}
|
|
@@ -303,6 +351,86 @@ function attemptStaleMs() {
|
|
|
303
351
|
const value = Number(raw);
|
|
304
352
|
return Number.isFinite(value) && value >= MIN_ATTEMPT_STALE_MS ? value : DEFAULT_ATTEMPT_STALE_MS;
|
|
305
353
|
}
|
|
354
|
+
// Work a single attempt may claim. Wall time beyond it is suspension, a hang, or
|
|
355
|
+
// a stop that arrived days after the agent died, and it is recorded as idle.
|
|
356
|
+
const DEFAULT_ATTEMPT_MAX_MS = 4 * 60 * 60 * 1000;
|
|
357
|
+
const MIN_ATTEMPT_MAX_MS = 10 * 60 * 1000;
|
|
358
|
+
function attemptMaxMs() {
|
|
359
|
+
const raw = process.env.AI_RULES_ATTEMPT_MAX_MS;
|
|
360
|
+
if (typeof raw !== 'string' || raw.trim() === '') return DEFAULT_ATTEMPT_MAX_MS;
|
|
361
|
+
const value = Number(raw);
|
|
362
|
+
return Number.isFinite(value) && value >= MIN_ATTEMPT_MAX_MS ? value : DEFAULT_ATTEMPT_MAX_MS;
|
|
363
|
+
}
|
|
364
|
+
// Intervals appended by the sidebar's suspend detector: the host did not run, so
|
|
365
|
+
// the attempt did not work. Written as JSONL, one { from, to } per line.
|
|
366
|
+
function readSuspendIntervals() {
|
|
367
|
+
const file = path.join(taskDir, '.suspend.jsonl');
|
|
368
|
+
let raw;
|
|
369
|
+
try { raw = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
370
|
+
const intervals = [];
|
|
371
|
+
for (const line of raw.split('\n')) {
|
|
372
|
+
const trimmed = line.trim();
|
|
373
|
+
if (trimmed === '') continue;
|
|
374
|
+
try {
|
|
375
|
+
const row = JSON.parse(trimmed);
|
|
376
|
+
const from = Date.parse(row && row.from);
|
|
377
|
+
const to = Date.parse(row && row.to);
|
|
378
|
+
if (Number.isFinite(from) && Number.isFinite(to) && to > from) intervals.push([from, to]);
|
|
379
|
+
} catch { /* a torn last line is re-read when the file grows */ }
|
|
380
|
+
}
|
|
381
|
+
return intervals;
|
|
382
|
+
}
|
|
383
|
+
function unionOverlapMs(intervals, from, to) {
|
|
384
|
+
if (!Number.isFinite(from) || !Number.isFinite(to) || to <= from) return 0;
|
|
385
|
+
const sorted = intervals
|
|
386
|
+
.filter((pair) => Array.isArray(pair) && Number.isFinite(pair[0]) && Number.isFinite(pair[1]) && pair[1] > pair[0])
|
|
387
|
+
.sort((left, right) => left[0] - right[0]);
|
|
388
|
+
let total = 0;
|
|
389
|
+
let cursor = from;
|
|
390
|
+
for (const [start, end] of sorted) {
|
|
391
|
+
const overlapStart = Math.max(start, from, cursor);
|
|
392
|
+
const overlapEnd = Math.min(end, to);
|
|
393
|
+
if (overlapEnd <= overlapStart) continue;
|
|
394
|
+
total += overlapEnd - overlapStart;
|
|
395
|
+
cursor = overlapEnd;
|
|
396
|
+
}
|
|
397
|
+
return total;
|
|
398
|
+
}
|
|
399
|
+
// Everything the ledger can prove was not work: a gate, an operator pause, a
|
|
400
|
+
// host suspension. Attempt wall time minus this is the attempt's active time.
|
|
401
|
+
function attemptIdleMs(startedAtMs, endedAtMs, events) {
|
|
402
|
+
const intervals = readSuspendIntervals();
|
|
403
|
+
// The sentinel is the control plane: it is engaged before `task_paused` is
|
|
404
|
+
// written, so a stop that notices it must still charge the wait as idle.
|
|
405
|
+
const livePause = readPauseSentinel();
|
|
406
|
+
if (livePause.engaged && livePause.at) {
|
|
407
|
+
intervals.push([Date.parse(livePause.at), endedAtMs]);
|
|
408
|
+
}
|
|
409
|
+
const gates = new Map();
|
|
410
|
+
for (const event of events) {
|
|
411
|
+
if (event && event.type === 'human_gate_started' && event.eventId) gates.set(event.eventId, Date.parse(event.at));
|
|
412
|
+
}
|
|
413
|
+
for (const event of events) {
|
|
414
|
+
if (!event) continue;
|
|
415
|
+
if (event.type === 'human_gate_ended' && event.gateStartedEventId) {
|
|
416
|
+
const start = gates.get(event.gateStartedEventId);
|
|
417
|
+
const end = Date.parse(event.at);
|
|
418
|
+
if (Number.isFinite(start) && Number.isFinite(end)) intervals.push([start, end]);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
let openPause = null;
|
|
422
|
+
for (const event of events) {
|
|
423
|
+
if (!event) continue;
|
|
424
|
+
if (event.type === 'task_paused') openPause = Date.parse(event.at);
|
|
425
|
+
if (event.type === 'task_resumed' && openPause !== null) {
|
|
426
|
+
const end = Date.parse(event.at);
|
|
427
|
+
if (Number.isFinite(end) && end > openPause) intervals.push([openPause, end]);
|
|
428
|
+
openPause = null;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (openPause !== null && Number.isFinite(openPause)) intervals.push([openPause, endedAtMs]);
|
|
432
|
+
return unionOverlapMs(intervals, startedAtMs, endedAtMs);
|
|
433
|
+
}
|
|
306
434
|
function hasTerminalReceipt(attemptId, entry) {
|
|
307
435
|
const manifestPath = path.join(taskDir, 'artifact-manifest.json');
|
|
308
436
|
if (!fs.existsSync(manifestPath)) return false;
|
|
@@ -360,6 +488,9 @@ function reclaimStaleAttempts(scope) {
|
|
|
360
488
|
role: roleFor(entry.agent),
|
|
361
489
|
outcome: 'stale',
|
|
362
490
|
durationMs: ageMs,
|
|
491
|
+
wallMs: ageMs,
|
|
492
|
+
activeMs: Math.min(ageMs, attemptMaxMs()),
|
|
493
|
+
idleMs: Math.max(0, ageMs - Math.min(ageMs, attemptMaxMs())),
|
|
363
494
|
retryAfterFix: status.retryAfterFix || null,
|
|
364
495
|
source: 'hook',
|
|
365
496
|
attributionConfidence: 'high',
|
|
@@ -1208,7 +1339,33 @@ function sanitizeUsage(value) {
|
|
|
1208
1339
|
/**
|
|
1209
1340
|
* Freshness of a persisted verification snapshot against the current worktree.
|
|
1210
1341
|
* Read-only: closure warns, it never blocks on a stale snapshot.
|
|
1342
|
+
*
|
|
1343
|
+
* Task scoping: with the slug's write-scope step baselines
|
|
1344
|
+
* (`.write-scope/<slug>/*.json`) the evidence hash covers the union of the
|
|
1345
|
+
* baselines' recorded paths only, so another live slug's uncommitted work
|
|
1346
|
+
* cannot stale this task's evidence. Known limit: a file created after baseline
|
|
1347
|
+
* activation outside the claimed path set is invisible to `scopeHash`; the
|
|
1348
|
+
* write-scope audit and `check:task` still attribute such files at gate time
|
|
1349
|
+
* (content-hash delta). The scoped hash is a change detector, not an
|
|
1350
|
+
* attribution tool. `environmentHash` (renamed from `worktreeHash`) keeps the
|
|
1351
|
+
* whole-tree capture as diagnostics only.
|
|
1211
1352
|
*/
|
|
1353
|
+
function writeScopeBaselinePaths(dir) {
|
|
1354
|
+
let entries;
|
|
1355
|
+
try { entries = fs.readdirSync(dir); } catch { return null; }
|
|
1356
|
+
const paths = new Set();
|
|
1357
|
+
for (const entry of entries) {
|
|
1358
|
+
if (!entry.endsWith('.json')) continue;
|
|
1359
|
+
let parsed = null;
|
|
1360
|
+
try { parsed = JSON.parse(fs.readFileSync(path.join(dir, entry), 'utf8')); } catch { parsed = null; }
|
|
1361
|
+
const record = parsed && typeof parsed === 'object' && parsed.paths && typeof parsed.paths === 'object' && !Array.isArray(parsed.paths) ? parsed.paths : null;
|
|
1362
|
+
if (!record) continue;
|
|
1363
|
+
for (const key of Object.keys(record)) {
|
|
1364
|
+
if (typeof key === 'string' && key !== '') paths.add(key.split(path.sep).join('/'));
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
return paths.size > 0 ? [...paths].sort() : null;
|
|
1368
|
+
}
|
|
1212
1369
|
function gitSnapshot() {
|
|
1213
1370
|
const { spawnSync } = require('child_process');
|
|
1214
1371
|
const git = (args) => {
|
|
@@ -1222,11 +1379,30 @@ function gitSnapshot() {
|
|
|
1222
1379
|
const statusText = git(['status', '--porcelain=v1', ...exclude]) || '';
|
|
1223
1380
|
const diffText = git(['diff', '--binary', 'HEAD', ...exclude]) || '';
|
|
1224
1381
|
const untracked = git(['ls-files', '--others', '--exclude-standard', ...exclude]) || '';
|
|
1382
|
+
const baselinePaths = typeof slug === 'string' && slug !== '' && SLUG_RE.test(slug)
|
|
1383
|
+
? writeScopeBaselinePaths(path.join(TEAM_ROOT, '.write-scope', slug))
|
|
1384
|
+
: null;
|
|
1385
|
+
const liveCount = liveSlugs().length;
|
|
1386
|
+
let scopeBasis = 'none';
|
|
1387
|
+
let scopeHash = null;
|
|
1388
|
+
if (baselinePaths !== null) {
|
|
1389
|
+
scopeBasis = 'write-scope';
|
|
1390
|
+
const spec = ['--', ...baselinePaths];
|
|
1391
|
+
const scopedStatus = git(['status', '--porcelain=v1', ...spec]) || '';
|
|
1392
|
+
const scopedDiff = git(['diff', '--binary', 'HEAD', ...spec]) || '';
|
|
1393
|
+
const scopedUntracked = git(['ls-files', '--others', '--exclude-standard', ...spec]) || '';
|
|
1394
|
+
scopeHash = crypto.createHash('sha256').update(`${scopedStatus}\u0000${scopedDiff}\u0000${scopedUntracked}`).digest('hex');
|
|
1395
|
+
} else if (liveCount <= 1) {
|
|
1396
|
+
scopeBasis = 'whole-tree';
|
|
1397
|
+
}
|
|
1225
1398
|
return {
|
|
1226
1399
|
head: head.trim(),
|
|
1227
1400
|
branch: branch === null ? null : branch.trim(),
|
|
1228
1401
|
dirtyFiles: statusText === '' ? 0 : statusText.split('\n').filter((line) => line !== '').length,
|
|
1229
|
-
|
|
1402
|
+
environmentHash: crypto.createHash('sha256').update(`${statusText}\u0000${diffText}\u0000${untracked}`).digest('hex'),
|
|
1403
|
+
scopeBasis,
|
|
1404
|
+
scopePaths: baselinePaths === null ? 0 : baselinePaths.length,
|
|
1405
|
+
scopeHash,
|
|
1230
1406
|
capturedAt: now,
|
|
1231
1407
|
};
|
|
1232
1408
|
}
|
|
@@ -1315,7 +1491,7 @@ function ensureVerificationSnapshot(dir, agent) {
|
|
|
1315
1491
|
fs.writeFileSync(temporary, JSON.stringify(verification, null, 2) + '\n');
|
|
1316
1492
|
fs.renameSync(temporary, file);
|
|
1317
1493
|
});
|
|
1318
|
-
appendMetric({ type: 'verification_recorded', at: now, kind: 'snapshot-only', agent: agent || null, head: snapshot.head,
|
|
1494
|
+
appendMetric({ type: 'verification_recorded', at: now, kind: 'snapshot-only', agent: agent || null, head: snapshot.head, environmentHash: snapshot.environmentHash, source: 'hook', attributionConfidence: 'high' });
|
|
1319
1495
|
}
|
|
1320
1496
|
|
|
1321
1497
|
function verificationFreshness(dir) {
|
|
@@ -1330,15 +1506,34 @@ function verificationFreshness(dir) {
|
|
|
1330
1506
|
// Judge the report the gate judges: its `tree:` header, not the wider worktree
|
|
1331
1507
|
// hash. A later edit inside the same report generation moved the hash while the
|
|
1332
1508
|
// gate still accepted the report, so the same fresh evidence warned twice.
|
|
1509
|
+
// The head comparison stays global (HEAD is shared across live slugs); the
|
|
1510
|
+
// dirty/hash dimension binds to the task's `scopeHash` when the evidence was
|
|
1511
|
+
// captured on a `write-scope` basis — the header's dirty count is a whole-tree
|
|
1512
|
+
// number and is not comparable to a scoped one, so the scoped hash is the
|
|
1513
|
+
// binding check for that basis, and a scope that can no longer be recomputed
|
|
1514
|
+
// reports `scope-unbound` (loud not-fresh, never a false fresh). Legacy
|
|
1515
|
+
// snapshots (no `scopeBasis`) and `whole-tree` snapshots keep today's
|
|
1516
|
+
// whole-tree comparison, reading the renamed field as
|
|
1517
|
+
// `environmentHash ?? worktreeHash`.
|
|
1333
1518
|
const found = evidenceReportText(dir);
|
|
1334
1519
|
const header = found === null ? null : found.text.match(REPORT_TREE_RE);
|
|
1335
1520
|
const reasons = [];
|
|
1336
1521
|
if (header) {
|
|
1337
1522
|
if (!current.head.startsWith(header[1])) reasons.push('head-changed');
|
|
1338
|
-
if (Number(header[2]) !== current.dirtyFiles) reasons.push('worktree-changed');
|
|
1339
1523
|
} else {
|
|
1340
1524
|
if (current.head !== snapshot.head) reasons.push('head-changed');
|
|
1341
|
-
|
|
1525
|
+
}
|
|
1526
|
+
const basis = typeof snapshot.scopeBasis === 'string' ? snapshot.scopeBasis : 'legacy';
|
|
1527
|
+
if (basis === 'write-scope') {
|
|
1528
|
+
if (current.scopeBasis !== 'write-scope') reasons.push('scope-unbound');
|
|
1529
|
+
else if (current.scopeHash !== snapshot.scopeHash) reasons.push('worktree-changed');
|
|
1530
|
+
} else if (basis === 'none') {
|
|
1531
|
+
reasons.push('scope-unbound');
|
|
1532
|
+
} else if (header) {
|
|
1533
|
+
if (Number(header[2]) !== current.dirtyFiles) reasons.push('worktree-changed');
|
|
1534
|
+
} else {
|
|
1535
|
+
const recorded = typeof snapshot.environmentHash === 'string' ? snapshot.environmentHash : snapshot.worktreeHash;
|
|
1536
|
+
if (current.environmentHash !== recorded) reasons.push('worktree-changed');
|
|
1342
1537
|
}
|
|
1343
1538
|
return { present: true, fresh: reasons.length === 0, reasons };
|
|
1344
1539
|
}
|
|
@@ -1357,10 +1552,32 @@ function noteVerificationFreshness(dir, agent) {
|
|
|
1357
1552
|
|
|
1358
1553
|
function finishActiveAttempt(forced) {
|
|
1359
1554
|
const resolved = forced || resolvedAttempt(); if (!resolved) return null;
|
|
1360
|
-
const
|
|
1555
|
+
const startedAtMs = Date.parse(resolved.entry.startedAt);
|
|
1556
|
+
const endedAtMs = Date.parse(now);
|
|
1557
|
+
const wallMs = Number.isFinite(startedAtMs) && Number.isFinite(endedAtMs) ? Math.max(0, endedAtMs - startedAtMs) : null;
|
|
1558
|
+
// Suspension, a gate or an operator pause inside the attempt is not work.
|
|
1559
|
+
const nonWorkMs = wallMs === null ? null : attemptIdleMs(startedAtMs, endedAtMs, readMetricsEvents());
|
|
1560
|
+
// `idleMs` is the remainder, not only the proven intervals: wall = active + idle.
|
|
1561
|
+
const activeMs = wallMs === null ? null : Math.min(Math.max(0, wallMs - nonWorkMs), attemptMaxMs());
|
|
1562
|
+
const idleMs = wallMs === null ? null : Math.max(0, wallMs - (activeMs ?? 0));
|
|
1361
1563
|
const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
|
|
1362
1564
|
const usage = sanitizeUsage(hookInput.usage);
|
|
1363
|
-
appendMetric({
|
|
1565
|
+
appendMetric({
|
|
1566
|
+
type: 'attempt_finished',
|
|
1567
|
+
at: now,
|
|
1568
|
+
attemptId: resolved.attemptId,
|
|
1569
|
+
stepIndex: typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : null,
|
|
1570
|
+
agent: resolved.entry.agent || null,
|
|
1571
|
+
outcome,
|
|
1572
|
+
durationMs: wallMs,
|
|
1573
|
+
wallMs,
|
|
1574
|
+
activeMs,
|
|
1575
|
+
idleMs,
|
|
1576
|
+
retryAfterFix: status.retryAfterFix || null,
|
|
1577
|
+
source: resolved.source || 'hook',
|
|
1578
|
+
attributionConfidence: resolved.confidence,
|
|
1579
|
+
...(usage ? { usage } : {}),
|
|
1580
|
+
});
|
|
1364
1581
|
if (resolved.entry && resolved.entry.agent === 'build-verifier') { ensureVerificationSnapshot(taskDir, resolved.entry.agent); noteVerificationFreshness(taskDir, resolved.entry.agent); }
|
|
1365
1582
|
const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
|
|
1366
1583
|
}
|
|
@@ -1437,10 +1654,38 @@ function completePipeline(statusPatch) {
|
|
|
1437
1654
|
out(`Pipeline complete for "${slug}". Run /technical-retro ${slug}.`);
|
|
1438
1655
|
process.exit(0);
|
|
1439
1656
|
}
|
|
1440
|
-
function beginHumanGate() {
|
|
1657
|
+
function beginHumanGate() {
|
|
1658
|
+
// A second stop for the same gate must not open a parallel one: the wait
|
|
1659
|
+
// would be counted twice and the pairing lost.
|
|
1660
|
+
if (status.activeHumanGateEventId && status.awaitingHumanGate) return;
|
|
1661
|
+
const eventId = `${status.metricsRunId || slug}:gate:${Date.now()}`;
|
|
1662
|
+
appendMetric({
|
|
1663
|
+
eventId,
|
|
1664
|
+
type: 'human_gate_started',
|
|
1665
|
+
at: now,
|
|
1666
|
+
stepIndex: typeof status.pipelineIndex === 'number' ? status.pipelineIndex : null,
|
|
1667
|
+
agent: status.currentAgent || null,
|
|
1668
|
+
source: 'hook',
|
|
1669
|
+
attributionConfidence: 'high',
|
|
1670
|
+
});
|
|
1671
|
+
status.activeHumanGateEventId = eventId;
|
|
1672
|
+
}
|
|
1441
1673
|
function endHumanGateIfResumed() {
|
|
1442
1674
|
if (!status.activeHumanGateEventId || status.awaitingHumanGate || status.state === 'awaiting_approval') return;
|
|
1443
|
-
|
|
1675
|
+
const events = readMetricsEvents();
|
|
1676
|
+
const started = events.find((event) => event && event.type === 'human_gate_started' && event.eventId === status.activeHumanGateEventId);
|
|
1677
|
+
const startedAt = started ? Date.parse(started.at) : NaN;
|
|
1678
|
+
// The gate ends when work resumed, not when a later stop noticed it.
|
|
1679
|
+
const resumed = Number.isFinite(startedAt)
|
|
1680
|
+
? events.find((event) => event && event.type === 'attempt_started' && Date.parse(event.at) > startedAt)
|
|
1681
|
+
: null;
|
|
1682
|
+
appendMetric({
|
|
1683
|
+
type: 'human_gate_ended',
|
|
1684
|
+
at: resumed ? resumed.at : now,
|
|
1685
|
+
gateStartedEventId: status.activeHumanGateEventId,
|
|
1686
|
+
source: 'hook',
|
|
1687
|
+
attributionConfidence: 'high',
|
|
1688
|
+
});
|
|
1444
1689
|
delete status.activeHumanGateEventId;
|
|
1445
1690
|
}
|
|
1446
1691
|
function completeTaskMetrics() {
|
|
@@ -1805,21 +2050,22 @@ function writeStatus(next) {
|
|
|
1805
2050
|
// attempt is finished before this check runs. An empty or unreadable file still
|
|
1806
2051
|
// counts as engaged (fail safe).
|
|
1807
2052
|
const PAUSE_SENTINELS = [
|
|
1808
|
-
path.join(process.cwd(), '.ai.local', 'STOP'),
|
|
1809
|
-
path.join(process.cwd(), '.ai.local', 'ESTOP'),
|
|
2053
|
+
{ file: path.join(process.cwd(), '.ai.local', 'STOP'), scope: 'repo' },
|
|
2054
|
+
{ file: path.join(process.cwd(), '.ai.local', 'ESTOP'), scope: 'repo-emergency' },
|
|
1810
2055
|
];
|
|
1811
2056
|
function readPauseSentinel() {
|
|
1812
2057
|
const sentinels = [...PAUSE_SENTINELS];
|
|
1813
2058
|
if (typeof slug === 'string' && slug !== '') {
|
|
1814
|
-
sentinels.push(path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug, 'STOP'));
|
|
2059
|
+
sentinels.push({ file: path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug, 'STOP'), scope: 'task' });
|
|
1815
2060
|
}
|
|
1816
|
-
for (const
|
|
2061
|
+
for (const sentinel of sentinels) {
|
|
2062
|
+
const file = sentinel.file;
|
|
1817
2063
|
let stat = null;
|
|
1818
2064
|
try { stat = fs.statSync(file); } catch (error) {
|
|
1819
2065
|
if (error && error.code === 'ENOENT') continue;
|
|
1820
2066
|
// A permission or I/O error is not proof of absence: fail safe and say so.
|
|
1821
2067
|
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`);
|
|
1822
|
-
return { engaged: true, file: path.relative(process.cwd(), file).split(path.sep).join('/'), reason: 'sentinel stat failed' };
|
|
2068
|
+
return { engaged: true, file: path.relative(process.cwd(), file).split(path.sep).join('/'), scope: sentinel.scope, at: null, reason: 'sentinel stat failed' };
|
|
1823
2069
|
}
|
|
1824
2070
|
if (!stat || !stat.isFile()) continue;
|
|
1825
2071
|
let reason = '';
|
|
@@ -1837,19 +2083,52 @@ function readPauseSentinel() {
|
|
|
1837
2083
|
return {
|
|
1838
2084
|
engaged: true,
|
|
1839
2085
|
file: path.relative(process.cwd(), file).split(path.sep).join('/'),
|
|
2086
|
+
scope: sentinel.scope,
|
|
2087
|
+
// The pause started when the sentinel was written, not when a hook noticed it.
|
|
2088
|
+
at: new Date(stat.mtimeMs).toISOString(),
|
|
1840
2089
|
reason: reason.replace(/\s+/g, ' ').slice(0, 160),
|
|
1841
2090
|
};
|
|
1842
2091
|
}
|
|
1843
|
-
return { engaged: false, file: null, reason: '' };
|
|
2092
|
+
return { engaged: false, file: null, scope: null, at: null, reason: '' };
|
|
1844
2093
|
}
|
|
1845
2094
|
function pausedNotice(pause) {
|
|
1846
2095
|
const where = pause && pause.file ? pause.file : '.ai.local/STOP';
|
|
1847
2096
|
const because = pause && pause.reason ? ` (${pause.reason})` : '';
|
|
1848
2097
|
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}.`;
|
|
1849
2098
|
}
|
|
2099
|
+
// A pause is a duration in the ledger, not only a file. One `task_paused` per
|
|
2100
|
+
// engagement and one `task_resumed` when the sentinel is gone.
|
|
2101
|
+
function recordPauseEngaged(pause) {
|
|
2102
|
+
if (openPauseIndex(readMetricsEvents()) !== -1) return;
|
|
2103
|
+
appendMetric({
|
|
2104
|
+
type: 'task_paused',
|
|
2105
|
+
at: pause.at || now,
|
|
2106
|
+
scope: pause.scope || 'repo',
|
|
2107
|
+
file: pause.file || null,
|
|
2108
|
+
reason: pause.reason || null,
|
|
2109
|
+
source: 'hook',
|
|
2110
|
+
attributionConfidence: 'high',
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
function recordPauseResumed() {
|
|
2114
|
+
const events = readMetricsEvents();
|
|
2115
|
+
const index = openPauseIndex(events);
|
|
2116
|
+
if (index === -1) return;
|
|
2117
|
+
appendMetric({
|
|
2118
|
+
type: 'task_resumed',
|
|
2119
|
+
at: now,
|
|
2120
|
+
pausedSince: events[index].at || null,
|
|
2121
|
+
source: 'hook',
|
|
2122
|
+
attributionConfidence: 'high',
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
1850
2125
|
function pauseBlocksAdvance() {
|
|
1851
2126
|
const pause = readPauseSentinel();
|
|
1852
|
-
if (!pause.engaged)
|
|
2127
|
+
if (!pause.engaged) {
|
|
2128
|
+
recordPauseResumed();
|
|
2129
|
+
return null;
|
|
2130
|
+
}
|
|
2131
|
+
recordPauseEngaged(pause);
|
|
1853
2132
|
writeStatus({ state: 'paused', phase: 'paused' });
|
|
1854
2133
|
out(pausedNotice(pause));
|
|
1855
2134
|
return pause;
|
|
@@ -2243,6 +2522,96 @@ function countDebugImplementationRetries() {
|
|
|
2243
2522
|
return 0;
|
|
2244
2523
|
}
|
|
2245
2524
|
}
|
|
2525
|
+
function replanDecisionCount() {
|
|
2526
|
+
try {
|
|
2527
|
+
const text = fs.readFileSync(path.join(taskDir, '.memlog.md'), 'utf8');
|
|
2528
|
+
const matches = text.match(/replan rev\s+\d+\s*(?:→|->)\s*\d+/g);
|
|
2529
|
+
return matches ? matches.length : 0;
|
|
2530
|
+
} catch {
|
|
2531
|
+
return 0;
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
function changesRequestedCount(agent) {
|
|
2535
|
+
if (typeof agent !== 'string' || agent === '') return 0;
|
|
2536
|
+
try {
|
|
2537
|
+
const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
|
|
2538
|
+
const events = Array.isArray(metrics.events) ? metrics.events : [];
|
|
2539
|
+
const needle = `:${agent}:`;
|
|
2540
|
+
return events.filter((event) => event && event.type === 'attempt_finished' && event.outcome === 'changes_requested' && typeof event.attemptId === 'string' && event.attemptId.includes(needle)).length;
|
|
2541
|
+
} catch {
|
|
2542
|
+
return 0;
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
function holdDesignEscalation(agent, mode, reviewerStepIndex) {
|
|
2546
|
+
if (changesRequestedCount(agent) < 2) return false;
|
|
2547
|
+
beginHumanGate();
|
|
2548
|
+
writeStatus({
|
|
2549
|
+
awaitingHumanGate: true,
|
|
2550
|
+
state: 'awaiting_approval',
|
|
2551
|
+
currentAgent: agent,
|
|
2552
|
+
phase: 'human_gate',
|
|
2553
|
+
designEscalation: {
|
|
2554
|
+
agent,
|
|
2555
|
+
mode,
|
|
2556
|
+
reviewerStepIndex: Number.isInteger(reviewerStepIndex) ? reviewerStepIndex : null,
|
|
2557
|
+
priorReplanCount: replanDecisionCount(),
|
|
2558
|
+
},
|
|
2559
|
+
parallelCompleted: [],
|
|
2560
|
+
parallelOutcomes: {},
|
|
2561
|
+
waveSteps: [],
|
|
2562
|
+
waveId: null,
|
|
2563
|
+
retryAfterFix: null,
|
|
2564
|
+
retryAfterFixStepIndex: null,
|
|
2565
|
+
});
|
|
2566
|
+
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.`);
|
|
2567
|
+
process.exit(0);
|
|
2568
|
+
}
|
|
2569
|
+
function resumeDesignEscalation(escalation, resumeSteps) {
|
|
2570
|
+
steps = resumeSteps;
|
|
2571
|
+
const reviewer = escalation.agent;
|
|
2572
|
+
const reviewerStepIndex = Number.isInteger(escalation.reviewerStepIndex)
|
|
2573
|
+
? escalation.reviewerStepIndex
|
|
2574
|
+
: (typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0);
|
|
2575
|
+
status.pipelineIndex = reviewerStepIndex;
|
|
2576
|
+
delete status.designEscalation;
|
|
2577
|
+
if (escalation.mode === 'graph') {
|
|
2578
|
+
const producerIndex = resolveProducerStepIndex('feature-developer', reviewerStepIndex);
|
|
2579
|
+
if (producerIndex < 0) {
|
|
2580
|
+
out(`${reviewer} requested changes for slug "${slug}" but no graph ancestor authors fixes. Read the review artifact. Resume only via /task-continue.`);
|
|
2581
|
+
process.exit(0);
|
|
2582
|
+
}
|
|
2583
|
+
appendMetric({ type: 'retry_scheduled', at: now, attemptId: status.lastCompletedAttempt?.attemptId || null, nextAgent: 'feature-developer', retryAfterFix: reviewer, source: 'hook', attributionConfidence: 'high' });
|
|
2584
|
+
invalidateFrom(producerIndex, reviewerStepIndex);
|
|
2585
|
+
writeStatus({ state: 'in_progress', phase: 'executing', awaitingHumanGate: false, waveSteps: [], waveId: null, retryAfterFix: null, retryAfterFixStepIndex: null, parallelCompleted: [], parallelOutcomes: {} });
|
|
2586
|
+
if (!dispatchReadyWave(`Design escalation for ${reviewer} accepted; re-dispatching unsatisfied steps.`)) out(noProgressNotice());
|
|
2587
|
+
process.exit(0);
|
|
2588
|
+
}
|
|
2589
|
+
let verifierStepIndex = -1;
|
|
2590
|
+
for (let index = reviewerStepIndex - 1; index >= 0; index -= 1) {
|
|
2591
|
+
if (getStepAgents(steps[index]).includes('build-verifier')) {
|
|
2592
|
+
verifierStepIndex = index;
|
|
2593
|
+
break;
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
const retryGate = verifierStepIndex >= 0 ? 'build-verifier' : reviewer;
|
|
2597
|
+
const retryAfterFixStepIndex = verifierStepIndex >= 0 ? verifierStepIndex : reviewerStepIndex;
|
|
2598
|
+
const developerIndex = scheduleRetry('feature-developer', reviewer, status.lastCompletedAttempt);
|
|
2599
|
+
if (developerIndex < 0) {
|
|
2600
|
+
out(`${reviewer} requested changes for slug "${slug}" but this pipeline has no feature-developer step. Read the review artifact. Resume only via /task-continue.`);
|
|
2601
|
+
process.exit(0);
|
|
2602
|
+
}
|
|
2603
|
+
writeStatus({
|
|
2604
|
+
pipelineIndex: developerIndex,
|
|
2605
|
+
currentAgent: 'feature-developer',
|
|
2606
|
+
state: 'in_progress',
|
|
2607
|
+
phase: 'executing',
|
|
2608
|
+
awaitingHumanGate: false,
|
|
2609
|
+
retryAfterFix: retryGate,
|
|
2610
|
+
retryAfterFixStepIndex,
|
|
2611
|
+
});
|
|
2612
|
+
out(handoffForAgent('feature-developer', steps[developerIndex]?.scope, steps[developerIndex]) + ` After fixes, re-run ${retryGate}.`);
|
|
2613
|
+
process.exit(0);
|
|
2614
|
+
}
|
|
2246
2615
|
function featureDeveloperAlreadyStarted() {
|
|
2247
2616
|
try {
|
|
2248
2617
|
const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
|
|
@@ -2675,6 +3044,19 @@ if (hookInput.action === 'bootstrap') {
|
|
|
2675
3044
|
function readMetricsLedger() {
|
|
2676
3045
|
try { return JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8')); } catch { return null; }
|
|
2677
3046
|
}
|
|
3047
|
+
function readMetricsEvents() {
|
|
3048
|
+
const ledger = readMetricsLedger();
|
|
3049
|
+
return ledger && Array.isArray(ledger.events) ? ledger.events : [];
|
|
3050
|
+
}
|
|
3051
|
+
/** Index of the `task_paused` that no `task_resumed` closed, or -1. */
|
|
3052
|
+
function openPauseIndex(events) {
|
|
3053
|
+
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
3054
|
+
const type = events[index] && events[index].type;
|
|
3055
|
+
if (type === 'task_resumed') return -1;
|
|
3056
|
+
if (type === 'task_paused') return index;
|
|
3057
|
+
}
|
|
3058
|
+
return -1;
|
|
3059
|
+
}
|
|
2678
3060
|
|
|
2679
3061
|
if (hookInput.action === 'out_of_band_start') {
|
|
2680
3062
|
if (pauseBlocksAdvance()) process.exit(0);
|
|
@@ -2741,6 +3123,11 @@ if (hookInput.action === 'out_of_band_end') {
|
|
|
2741
3123
|
|
|
2742
3124
|
if (hookInput.action === 'end_human_gate') {
|
|
2743
3125
|
if (pauseBlocksAdvance()) process.exit(0);
|
|
3126
|
+
const designEscalation = status.designEscalation && typeof status.designEscalation === 'object' ? status.designEscalation : null;
|
|
3127
|
+
if (designEscalation && replanDecisionCount() <= (Number(designEscalation.priorReplanCount) || 0)) {
|
|
3128
|
+
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.`);
|
|
3129
|
+
process.exit(0);
|
|
3130
|
+
}
|
|
2744
3131
|
// Only advance when a gate was actually open. A duplicate or retried
|
|
2745
3132
|
// end_human_gate must be a no-op, not a silent pipeline skip.
|
|
2746
3133
|
const gateWasOpen = Boolean(status.activeHumanGateEventId) || status.awaitingHumanGate === true;
|
|
@@ -2772,6 +3159,12 @@ if (hookInput.action === 'end_human_gate') {
|
|
|
2772
3159
|
});
|
|
2773
3160
|
delete status.activeHumanGateEventId;
|
|
2774
3161
|
}
|
|
3162
|
+
if (designEscalation && hookInput.activateNext && fs.existsSync(pipelinePath)) {
|
|
3163
|
+
let designPipeline = null;
|
|
3164
|
+
try { designPipeline = JSON.parse(fs.readFileSync(pipelinePath, 'utf8')); } catch {}
|
|
3165
|
+
const designSteps = designPipeline && Array.isArray(designPipeline.steps) ? designPipeline.steps : [];
|
|
3166
|
+
resumeDesignEscalation(designEscalation, designSteps);
|
|
3167
|
+
}
|
|
2775
3168
|
if (gateWasOpen && hookInput.activateNext && fs.existsSync(pipelinePath)) {
|
|
2776
3169
|
let resumePipeline = null;
|
|
2777
3170
|
try { resumePipeline = JSON.parse(fs.readFileSync(pipelinePath, 'utf8')); } catch {}
|
|
@@ -2911,10 +3304,12 @@ if (status.state === 'awaiting_artifact_receipt') {
|
|
|
2911
3304
|
const pause = readPauseSentinel();
|
|
2912
3305
|
if (pause.engaged) {
|
|
2913
3306
|
if (artifactStallMessage) process.stderr.write(artifactStallMessage + '\n');
|
|
3307
|
+
recordPauseEngaged(pause);
|
|
2914
3308
|
writeStatus({ state: 'paused', phase: 'paused' });
|
|
2915
3309
|
out(pausedNotice(pause));
|
|
2916
3310
|
process.exit(0);
|
|
2917
3311
|
}
|
|
3312
|
+
recordPauseResumed();
|
|
2918
3313
|
writeStatus({});
|
|
2919
3314
|
emitArtifactStall(artifactStallMessage, !wasWaitingForReceipt);
|
|
2920
3315
|
process.exit(0);
|
|
@@ -3138,6 +3533,7 @@ if (waveIndexes) {
|
|
|
3138
3533
|
out(`${retryReviewer} requested changes for slug "${slug}" but no graph ancestor authors fixes. Read the review artifact. Resume only via /task-continue.`);
|
|
3139
3534
|
process.exit(0);
|
|
3140
3535
|
}
|
|
3536
|
+
holdDesignEscalation(retryReviewer, 'graph', reviewerStepIndex);
|
|
3141
3537
|
const graphPredecessor = outcomes[retryReviewer]
|
|
3142
3538
|
? { attemptId: outcomes[retryReviewer].attemptId, confidence: outcomes[retryReviewer].confidence }
|
|
3143
3539
|
: finishedAttempt;
|
|
@@ -3150,6 +3546,7 @@ if (waveIndexes) {
|
|
|
3150
3546
|
if (!dispatchReadyWave(`Step ${reviewerStepIndex} (${retryReviewer}) requested changes; re-dispatching unsatisfied steps.`)) out(noProgressNotice());
|
|
3151
3547
|
process.exit(0);
|
|
3152
3548
|
}
|
|
3549
|
+
holdDesignEscalation(retryReviewer, 'linear', idx);
|
|
3153
3550
|
const retryAfterFixStepIndex = idx;
|
|
3154
3551
|
const predecessor = outcomes[retryReviewer]
|
|
3155
3552
|
? {
|
|
@@ -3249,6 +3646,7 @@ if (status.state === 'changes_requested') {
|
|
|
3249
3646
|
process.exit(0);
|
|
3250
3647
|
}
|
|
3251
3648
|
const reviewerStepIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
|
|
3649
|
+
holdDesignEscalation(reviewer, 'linear', reviewerStepIndex);
|
|
3252
3650
|
let verifierStepIndex = -1;
|
|
3253
3651
|
for (let index = reviewerStepIndex - 1; index >= 0; index -= 1) {
|
|
3254
3652
|
if (getStepAgents(steps[index]).includes('build-verifier')) {
|
|
@@ -3382,26 +3780,21 @@ const fs = require('fs');
|
|
|
3382
3780
|
const path = require('path');
|
|
3383
3781
|
const { spawnSync } = require('child_process');
|
|
3384
3782
|
|
|
3783
|
+
// Slug binding for the seams below is inside the projection markers. The
|
|
3784
|
+
// dualwrite harness executes that region alone, so the resolver has to live
|
|
3785
|
+
// there or a fresh store is never created.
|
|
3786
|
+
|
|
3385
3787
|
// Dev-server cleanup: terminal task state only. `processes.mjs` proves
|
|
3386
3788
|
// ownership from `.ai.local/.processes/leases/<name>.json` before any signal,
|
|
3387
3789
|
// so a foreign process is never touched. A refusal or timeout is a warning,
|
|
3388
|
-
// never a hook failure.
|
|
3790
|
+
// never a hook failure. The slug is the env binding only — no pointer
|
|
3791
|
+
// fallback: cleanup matters only on terminal state, and the main hook always
|
|
3792
|
+
// knows the slug it resolved.
|
|
3389
3793
|
function stopOwnedDevServers() {
|
|
3390
3794
|
const processes = path.join(process.cwd(), '.ai.local', 'scripts', 'processes.mjs');
|
|
3391
3795
|
if (!fs.existsSync(processes)) return;
|
|
3392
|
-
const
|
|
3393
|
-
|
|
3394
|
-
if (!slug) {
|
|
3395
|
-
try {
|
|
3396
|
-
const active = JSON.parse(
|
|
3397
|
-
fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'active-task.json'), 'utf8'),
|
|
3398
|
-
);
|
|
3399
|
-
slug = typeof active.slug === 'string' ? active.slug : '';
|
|
3400
|
-
} catch {
|
|
3401
|
-
return;
|
|
3402
|
-
}
|
|
3403
|
-
}
|
|
3404
|
-
if (slug.length === 0 || slug.length > 48 || !SLUG_RE.test(slug)) return;
|
|
3796
|
+
const slug = typeof process.env.TEAM_TASK_SLUG === 'string' ? process.env.TEAM_TASK_SLUG : '';
|
|
3797
|
+
if (slug.length === 0 || slug.length > 48 || !POSTFLIGHT_SLUG_RE.test(slug)) return;
|
|
3405
3798
|
let state = '';
|
|
3406
3799
|
try {
|
|
3407
3800
|
const status = JSON.parse(
|
|
@@ -3629,6 +4022,95 @@ if (!input || input.status !== 'completed') {
|
|
|
3629
4022
|
// This is a plain region marker, not a `hook-slot`: the block is identical in
|
|
3630
4023
|
// all 40 rendered bodies and needs no per-stack fragment.
|
|
3631
4024
|
// <<<team-db-projection>>>
|
|
4025
|
+
// Postflight slug binding, shared by the seams below: the env slug first,
|
|
4026
|
+
// then the per-session lease (the same file the main hook and the OpenCode
|
|
4027
|
+
// task-status plugin write), and the active-task.json projection only as a
|
|
4028
|
+
// last resort. Containment comes from validating every derivation point with
|
|
4029
|
+
// the slug grammar (the same pattern as the hook's SLUG_RE), so `tasks/<slug>`
|
|
4030
|
+
// cannot escape the tree on any postflight path. This region is extracted and
|
|
4031
|
+
// executed alone by the dualwrite harness, so the resolver stays inside the
|
|
4032
|
+
// markers.
|
|
4033
|
+
const TERMINAL_STATES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
|
|
4034
|
+
const POSTFLIGHT_SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
4035
|
+
function postflightLiveSlugs() {
|
|
4036
|
+
const tasksDir = path.join(process.cwd(), '.ai.local', 'team', 'tasks');
|
|
4037
|
+
let entries;
|
|
4038
|
+
try {
|
|
4039
|
+
entries = fs.readdirSync(tasksDir, { withFileTypes: true });
|
|
4040
|
+
} catch (error) {
|
|
4041
|
+
return [];
|
|
4042
|
+
}
|
|
4043
|
+
const live = [];
|
|
4044
|
+
for (const entry of entries) {
|
|
4045
|
+
if (!entry.isDirectory()) continue;
|
|
4046
|
+
try {
|
|
4047
|
+
const status = JSON.parse(fs.readFileSync(path.join(tasksDir, entry.name, 'status.json'), 'utf8'));
|
|
4048
|
+
if (status && typeof status.state === 'string' && !TERMINAL_STATES.has(status.state)) live.push(entry.name);
|
|
4049
|
+
} catch (error) {
|
|
4050
|
+
/* an unreadable status is not a live slug */
|
|
4051
|
+
}
|
|
4052
|
+
}
|
|
4053
|
+
return live.sort();
|
|
4054
|
+
}
|
|
4055
|
+
function postflightPointerSlug() {
|
|
4056
|
+
// Last-resort read of the UI projection; both the projection shape
|
|
4057
|
+
// `{"slugs": [...]}` and the legacy single-slot `{"slug"}` are accepted
|
|
4058
|
+
// forever. A multi-slug projection resolves to its first entry; the
|
|
4059
|
+
// live-scan guard in postflightResolveSlug decides whether that
|
|
4060
|
+
// resolution is safe to act on.
|
|
4061
|
+
try {
|
|
4062
|
+
const active = JSON.parse(
|
|
4063
|
+
fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'active-task.json'), 'utf8'),
|
|
4064
|
+
);
|
|
4065
|
+
const slugs = Array.isArray(active.slugs)
|
|
4066
|
+
? active.slugs
|
|
4067
|
+
: (typeof active.slug === 'string' && active.slug ? [active.slug] : []);
|
|
4068
|
+
const candidate = typeof slugs[0] === 'string' ? slugs[0] : '';
|
|
4069
|
+
if (candidate.length > 48 || !POSTFLIGHT_SLUG_RE.test(candidate)) return '';
|
|
4070
|
+
return candidate;
|
|
4071
|
+
} catch (error) {
|
|
4072
|
+
return '';
|
|
4073
|
+
}
|
|
4074
|
+
}
|
|
4075
|
+
function postflightSessionId() {
|
|
4076
|
+
const raw = process.env.OPENCODE_SESSION_ID || process.env.AI_RULES_SESSION_ID || '';
|
|
4077
|
+
return /^[A-Za-z0-9_-]{1,128}$/.test(raw) ? raw : '';
|
|
4078
|
+
}
|
|
4079
|
+
function postflightLeaseSlug() {
|
|
4080
|
+
// Same file and TTL as the main hook. A pointer fallback must not win while
|
|
4081
|
+
// this session already has a pin.
|
|
4082
|
+
const id = postflightSessionId();
|
|
4083
|
+
if (!id) return '';
|
|
4084
|
+
try {
|
|
4085
|
+
const file = path.join(process.cwd(), '.ai.local', 'team', '.session-leases', `${id}.json`);
|
|
4086
|
+
if (Date.now() - fs.statSync(file).mtimeMs > 7 * 24 * 60 * 60 * 1000) return '';
|
|
4087
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
4088
|
+
const slug = parsed && typeof parsed.slug === 'string' ? parsed.slug : '';
|
|
4089
|
+
if (slug.length > 48 || !POSTFLIGHT_SLUG_RE.test(slug)) return '';
|
|
4090
|
+
return slug;
|
|
4091
|
+
} catch (error) {
|
|
4092
|
+
return '';
|
|
4093
|
+
}
|
|
4094
|
+
}
|
|
4095
|
+
function postflightResolveSlug() {
|
|
4096
|
+
// An env slug present but invalid is a stop, not a fallback: the projection
|
|
4097
|
+
// must never route around a bad explicit binding.
|
|
4098
|
+
const envSlug = typeof process.env.TEAM_TASK_SLUG === 'string' ? process.env.TEAM_TASK_SLUG : '';
|
|
4099
|
+
if (envSlug !== '') {
|
|
4100
|
+
if (envSlug.length <= 48 && POSTFLIGHT_SLUG_RE.test(envSlug)) return { slug: envSlug };
|
|
4101
|
+
return { slug: '' };
|
|
4102
|
+
}
|
|
4103
|
+
const leaseSlug = postflightLeaseSlug();
|
|
4104
|
+
if (leaseSlug) return { slug: leaseSlug };
|
|
4105
|
+
const pointerSlug = postflightPointerSlug();
|
|
4106
|
+
if (!pointerSlug) return { slug: '' };
|
|
4107
|
+
const live = postflightLiveSlugs();
|
|
4108
|
+
for (let index = 0; index < live.length; index += 1) {
|
|
4109
|
+
if (live[index] !== pointerSlug) return { slug: '', pointerLiveSlugs: live.length };
|
|
4110
|
+
}
|
|
4111
|
+
return { slug: pointerSlug };
|
|
4112
|
+
}
|
|
4113
|
+
|
|
3632
4114
|
function teamDbTruthy(value) {
|
|
3633
4115
|
if (typeof value !== 'string') return false;
|
|
3634
4116
|
const normalized = value.trim().toLowerCase();
|
|
@@ -3685,17 +4167,17 @@ function teamDbProject() {
|
|
|
3685
4167
|
try {
|
|
3686
4168
|
const env = process.env;
|
|
3687
4169
|
if (teamDbTruthy(env.AI_RULES_TEAM_DB_DISABLE)) return;
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
} catch (error) {
|
|
4170
|
+
const resolved = postflightResolveSlug();
|
|
4171
|
+
if (resolved.pointerLiveSlugs) {
|
|
4172
|
+
// A pointer-resolved projection under other live slugs cannot say
|
|
4173
|
+
// which task this stop belongs to. Skipping is safe: the projection
|
|
4174
|
+
// converges on the next `team-db sync`, and the files stay
|
|
4175
|
+
// authoritative.
|
|
4176
|
+
process.stderr.write(`WARNING: pointer-resolved projection skipped; ${resolved.pointerLiveSlugs} live slugs\n`);
|
|
3696
4177
|
return;
|
|
3697
4178
|
}
|
|
3698
|
-
|
|
4179
|
+
const slug = resolved.slug;
|
|
4180
|
+
if (!slug) return;
|
|
3699
4181
|
const taskDir = path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug);
|
|
3700
4182
|
if (!fs.existsSync(path.join(taskDir, 'status.json'))) return;
|
|
3701
4183
|
const script = path.join(process.cwd(), '.ai.local', 'scripts', 'team-db.mjs');
|
|
@@ -3841,13 +4323,11 @@ teamDbTrackerDrain();
|
|
|
3841
4323
|
let pipeline = null;
|
|
3842
4324
|
try {
|
|
3843
4325
|
const teamRoot = path.join(process.cwd(), '.ai.local', 'team');
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
//
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
const POSTFLIGHT_SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
3850
|
-
if (pipelineSlug.length <= 48 && POSTFLIGHT_SLUG_RE.test(pipelineSlug)) {
|
|
4326
|
+
// Same binding as the seams above: env slug first, projection last resort.
|
|
4327
|
+
// A pointer resolution refused by the live-scan guard is a silent policy
|
|
4328
|
+
// skip here — the ratchet is already silent-by-design for light/spike.
|
|
4329
|
+
const pipelineSlug = postflightResolveSlug().slug;
|
|
4330
|
+
if (pipelineSlug) {
|
|
3851
4331
|
pipeline = JSON.parse(fs.readFileSync(path.join(teamRoot, 'tasks', pipelineSlug, 'pipeline.json'), 'utf8'));
|
|
3852
4332
|
}
|
|
3853
4333
|
} catch {
|