@bonesofspring/ai-rules 0.2.65 → 0.2.67
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 +56 -0
- package/README.md +21 -11
- package/bin/cli.js +9 -1
- package/bin/lib/engine-scripts.js +34 -7
- package/bin/lib/engine-upgrade.js +5 -2
- package/bin/lib/seed-ai-local-team.js +32 -3
- package/docs/OPENCODE-COMPATIBILITY.md +1 -0
- package/docs/OPENCODE.md +31 -10
- package/docs/TEAM-DB.md +54 -14
- package/docs/TOKEN-ECONOMY.md +110 -0
- package/docs/openapi/team-db.v1.json +5 -5
- package/package.json +16 -3
- package/presets/_shared/ai-local/scripts/dump-output.mjs +422 -0
- package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +3 -3
- package/presets/_shared/ai-local/scripts/team-db-tracker.mjs +2 -0
- package/presets/_shared/ai-local/scripts/team-db.mjs +82 -2
- package/presets/_shared/core/agent-team/agent-team-orchestrator.md +3 -1
- package/presets/_shared/core/architecture/feature-delivery-workflow.md +4 -0
- package/presets/_shared/core/quality/context-and-iteration.md +1 -0
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +9 -2
- package/presets/_shared/hooks/list-ai-local.mjs +17 -0
- package/presets/claude/android-kotlin/agents/task-analyst.md +1 -1
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +9 -2
- package/presets/claude/android-kotlin/hooks/list-ai-local.mjs +17 -0
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
- package/presets/claude/go/agents/task-analyst.md +1 -1
- package/presets/claude/go/hooks/chain-team-phases.sh +9 -2
- package/presets/claude/go/hooks/list-ai-local.mjs +17 -0
- package/presets/claude/go/rules/architecture/feature-delivery.md +4 -0
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
- package/presets/claude/ios-swift/agents/task-analyst.md +1 -1
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +9 -2
- package/presets/claude/ios-swift/hooks/list-ai-local.mjs +17 -0
- package/presets/claude/ios-swift/rules/architecture/feature-delivery.md +4 -0
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
- package/presets/claude/java/agents/task-analyst.md +1 -1
- package/presets/claude/java/hooks/chain-team-phases.sh +9 -2
- package/presets/claude/java/hooks/list-ai-local.mjs +17 -0
- package/presets/claude/java/rules/architecture/feature-delivery.md +4 -0
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
- package/presets/claude/mcp-ts/agents/task-analyst.md +1 -1
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +9 -2
- package/presets/claude/mcp-ts/hooks/list-ai-local.mjs +17 -0
- package/presets/claude/mcp-ts/rules/architecture/feature-delivery.md +4 -0
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
- package/presets/claude/mol/agents/task-analyst.md +1 -1
- package/presets/claude/mol/hooks/chain-team-phases.sh +9 -2
- package/presets/claude/mol/hooks/list-ai-local.mjs +17 -0
- package/presets/claude/mol/rules/architecture/feature-delivery-workflow.md +4 -0
- package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
- package/presets/claude/next/agents/ci-investigator.md +5 -2
- package/presets/claude/next/agents/debugger.md +5 -2
- package/presets/claude/next/agents/feature-developer.md +5 -2
- package/presets/claude/next/agents/task-analyst.md +1 -1
- package/presets/claude/next/commands/README.md +1 -1
- package/presets/claude/next/commands/task.md +1 -1
- package/presets/claude/next/hooks/chain-team-phases.sh +9 -2
- package/presets/claude/next/hooks/list-ai-local.mjs +17 -0
- package/presets/claude/next/rules/architecture/feature-delivery-workflow.md +8 -0
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
- package/presets/claude/next/team/README.md +7 -3
- package/presets/claude/nuxt/agents/task-analyst.md +1 -1
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +9 -2
- package/presets/claude/nuxt/hooks/list-ai-local.mjs +17 -0
- package/presets/claude/nuxt/rules/architecture/feature-delivery-workflow.md +4 -0
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
- package/presets/claude/php-hexagonal/agents/task-analyst.md +1 -1
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +9 -2
- package/presets/claude/php-hexagonal/hooks/list-ai-local.mjs +17 -0
- package/presets/claude/php-hexagonal/rules/architecture/feature-delivery.md +4 -0
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
- package/presets/claude/php-laravel/agents/task-analyst.md +1 -1
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +9 -2
- package/presets/claude/php-laravel/hooks/list-ai-local.mjs +17 -0
- package/presets/claude/php-laravel/rules/architecture/feature-delivery.md +4 -0
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
- package/presets/claude/svelte/agents/task-analyst.md +1 -1
- package/presets/claude/svelte/hooks/chain-team-phases.sh +9 -2
- package/presets/claude/svelte/hooks/list-ai-local.mjs +17 -0
- package/presets/claude/svelte/rules/architecture/feature-delivery-workflow.md +4 -0
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
- package/presets/cursor/android-kotlin/agents/task-analyst.md +1 -1
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +9 -2
- package/presets/cursor/android-kotlin/hooks/list-ai-local.mjs +17 -0
- package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/go/agents/task-analyst.md +1 -1
- package/presets/cursor/go/hooks/chain-team-phases.sh +9 -2
- package/presets/cursor/go/hooks/list-ai-local.mjs +17 -0
- package/presets/cursor/go/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/ios-swift/agents/task-analyst.md +1 -1
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +9 -2
- package/presets/cursor/ios-swift/hooks/list-ai-local.mjs +17 -0
- package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/java/agents/task-analyst.md +1 -1
- package/presets/cursor/java/hooks/chain-team-phases.sh +9 -2
- package/presets/cursor/java/hooks/list-ai-local.mjs +17 -0
- package/presets/cursor/java/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/mcp-ts/agents/task-analyst.md +1 -1
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +9 -2
- package/presets/cursor/mcp-ts/hooks/list-ai-local.mjs +17 -0
- package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/mol/agents/task-analyst.md +1 -1
- package/presets/cursor/mol/hooks/chain-team-phases.sh +9 -2
- package/presets/cursor/mol/hooks/list-ai-local.mjs +17 -0
- package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/next/agents/task-analyst.md +1 -1
- package/presets/cursor/next/commands/README.md +1 -1
- package/presets/cursor/next/commands/task.md +1 -1
- package/presets/cursor/next/hooks/chain-team-phases.sh +9 -2
- package/presets/cursor/next/hooks/list-ai-local.mjs +17 -0
- package/presets/cursor/next/rules/agent-team-orchestrator.mdc +3 -1
- package/presets/cursor/next/rules/feature-delivery-workflow.mdc +4 -0
- package/presets/cursor/next/team/README.md +7 -3
- package/presets/cursor/nuxt/agents/task-analyst.md +1 -1
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +9 -2
- package/presets/cursor/nuxt/hooks/list-ai-local.mjs +17 -0
- package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/php-hexagonal/agents/task-analyst.md +1 -1
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +9 -2
- package/presets/cursor/php-hexagonal/hooks/list-ai-local.mjs +17 -0
- package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/php-laravel/agents/task-analyst.md +1 -1
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +9 -2
- package/presets/cursor/php-laravel/hooks/list-ai-local.mjs +17 -0
- package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/svelte/agents/task-analyst.md +1 -1
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +9 -2
- package/presets/cursor/svelte/hooks/list-ai-local.mjs +17 -0
- package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/agents/task-analyst.md +1 -1
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +9 -2
- package/presets/mavis/android-kotlin/hooks/list-ai-local.mjs +17 -0
- package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +3 -1
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/agents/task-analyst.md +1 -1
- package/presets/mavis/go/hooks/chain-team-phases.sh +9 -2
- package/presets/mavis/go/hooks/list-ai-local.mjs +17 -0
- package/presets/mavis/go/rules/agent-team-orchestrator.md +3 -1
- package/presets/mavis/go/rules/feature-delivery-workflow.md +4 -0
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/agents/task-analyst.md +1 -1
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +9 -2
- package/presets/mavis/ios-swift/hooks/list-ai-local.mjs +17 -0
- package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +3 -1
- package/presets/mavis/ios-swift/rules/feature-delivery-workflow.md +4 -0
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/agents/task-analyst.md +1 -1
- package/presets/mavis/java/hooks/chain-team-phases.sh +9 -2
- package/presets/mavis/java/hooks/list-ai-local.mjs +17 -0
- package/presets/mavis/java/rules/agent-team-orchestrator.md +3 -1
- package/presets/mavis/java/rules/feature-delivery-workflow.md +4 -0
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/agents/task-analyst.md +1 -1
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +9 -2
- package/presets/mavis/mcp-ts/hooks/list-ai-local.mjs +17 -0
- package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +3 -1
- package/presets/mavis/mcp-ts/rules/feature-delivery-workflow.md +4 -0
- package/presets/mavis/mol/adapter-map.json +1 -1
- package/presets/mavis/mol/agents/task-analyst.md +1 -1
- package/presets/mavis/mol/hooks/chain-team-phases.sh +9 -2
- package/presets/mavis/mol/hooks/list-ai-local.mjs +17 -0
- package/presets/mavis/mol/rules/agent-team-orchestrator.md +3 -1
- package/presets/mavis/mol/rules/feature-delivery-workflow.md +4 -0
- package/presets/mavis/next/adapter-map.json +9 -1
- package/presets/mavis/next/agents/ci-investigator.md +5 -2
- package/presets/mavis/next/agents/debugger.md +5 -2
- package/presets/mavis/next/agents/feature-developer.md +5 -2
- package/presets/mavis/next/agents/task-analyst.md +1 -1
- package/presets/mavis/next/commands/README.md +1 -1
- package/presets/mavis/next/commands/task.md +1 -1
- package/presets/mavis/next/hooks/chain-team-phases.sh +9 -2
- package/presets/mavis/next/hooks/list-ai-local.mjs +17 -0
- package/presets/mavis/next/rules/agent-team-orchestrator.md +3 -1
- package/presets/mavis/next/rules/feature-delivery-workflow.md +8 -0
- package/presets/mavis/next/team/README.md +7 -3
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/agents/task-analyst.md +1 -1
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +9 -2
- package/presets/mavis/nuxt/hooks/list-ai-local.mjs +17 -0
- package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +3 -1
- package/presets/mavis/nuxt/rules/feature-delivery-workflow.md +4 -0
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/agents/task-analyst.md +1 -1
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +9 -2
- package/presets/mavis/php-hexagonal/hooks/list-ai-local.mjs +17 -0
- package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +3 -1
- package/presets/mavis/php-hexagonal/rules/feature-delivery-workflow.md +4 -0
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/agents/task-analyst.md +1 -1
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +9 -2
- package/presets/mavis/php-laravel/hooks/list-ai-local.mjs +17 -0
- package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +3 -1
- package/presets/mavis/php-laravel/rules/feature-delivery-workflow.md +4 -0
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/agents/task-analyst.md +1 -1
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +9 -2
- package/presets/mavis/svelte/hooks/list-ai-local.mjs +17 -0
- package/presets/mavis/svelte/rules/agent-team-orchestrator.md +3 -1
- package/presets/mavis/svelte/rules/feature-delivery-workflow.md +4 -0
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/agents/task-analyst.md +1 -1
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +9 -2
- package/presets/opencode/android-kotlin/hooks/list-ai-local.mjs +17 -0
- package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +3 -1
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/agents/task-analyst.md +1 -1
- package/presets/opencode/go/hooks/chain-team-phases.sh +9 -2
- package/presets/opencode/go/hooks/list-ai-local.mjs +17 -0
- package/presets/opencode/go/rules/agent-team-orchestrator.md +3 -1
- package/presets/opencode/go/rules/feature-delivery-workflow.md +4 -0
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/agents/task-analyst.md +1 -1
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +9 -2
- package/presets/opencode/ios-swift/hooks/list-ai-local.mjs +17 -0
- package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +3 -1
- package/presets/opencode/ios-swift/rules/feature-delivery-workflow.md +4 -0
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/agents/task-analyst.md +1 -1
- package/presets/opencode/java/hooks/chain-team-phases.sh +9 -2
- package/presets/opencode/java/hooks/list-ai-local.mjs +17 -0
- package/presets/opencode/java/rules/agent-team-orchestrator.md +3 -1
- package/presets/opencode/java/rules/feature-delivery-workflow.md +4 -0
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/agents/task-analyst.md +1 -1
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +9 -2
- package/presets/opencode/mcp-ts/hooks/list-ai-local.mjs +17 -0
- package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +3 -1
- package/presets/opencode/mcp-ts/rules/feature-delivery-workflow.md +4 -0
- package/presets/opencode/mol/adapter-map.json +1 -1
- package/presets/opencode/mol/agents/task-analyst.md +1 -1
- package/presets/opencode/mol/hooks/chain-team-phases.sh +9 -2
- package/presets/opencode/mol/hooks/list-ai-local.mjs +17 -0
- package/presets/opencode/mol/rules/agent-team-orchestrator.md +3 -1
- package/presets/opencode/mol/rules/feature-delivery-workflow.md +4 -0
- package/presets/opencode/next/adapter-map.json +9 -1
- package/presets/opencode/next/agents/ci-investigator.md +5 -2
- package/presets/opencode/next/agents/debugger.md +5 -2
- package/presets/opencode/next/agents/feature-developer.md +5 -2
- package/presets/opencode/next/agents/task-analyst.md +1 -1
- package/presets/opencode/next/commands/README.md +1 -1
- package/presets/opencode/next/commands/task.md +1 -1
- package/presets/opencode/next/hooks/chain-team-phases.sh +9 -2
- package/presets/opencode/next/hooks/list-ai-local.mjs +17 -0
- package/presets/opencode/next/rules/agent-team-orchestrator.md +3 -1
- package/presets/opencode/next/rules/feature-delivery-workflow.md +8 -0
- package/presets/opencode/next/team/README.md +7 -3
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/agents/task-analyst.md +1 -1
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +9 -2
- package/presets/opencode/nuxt/hooks/list-ai-local.mjs +17 -0
- package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +3 -1
- package/presets/opencode/nuxt/rules/feature-delivery-workflow.md +4 -0
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/agents/task-analyst.md +1 -1
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +9 -2
- package/presets/opencode/php-hexagonal/hooks/list-ai-local.mjs +17 -0
- package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +3 -1
- package/presets/opencode/php-hexagonal/rules/feature-delivery-workflow.md +4 -0
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/agents/task-analyst.md +1 -1
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +9 -2
- package/presets/opencode/php-laravel/hooks/list-ai-local.mjs +17 -0
- package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +3 -1
- package/presets/opencode/php-laravel/rules/feature-delivery-workflow.md +4 -0
- package/presets/opencode/plugins/output-guard/README.md +43 -0
- package/presets/opencode/plugins/output-guard/index.ts +300 -0
- package/presets/opencode/plugins/output-guard/package.json +9 -0
- package/presets/opencode/plugins/output-guard/rewrite.ts +149 -0
- package/presets/opencode/plugins/task-status/README.md +23 -11
- package/presets/opencode/plugins/task-status/details-data.ts +64 -46
- package/presets/opencode/plugins/task-status/details.tsx +12 -2
- package/presets/opencode/plugins/task-status/format.ts +16 -0
- package/presets/opencode/plugins/task-status/prompt-text.ts +37 -0
- package/presets/opencode/plugins/task-status/task-view.ts +281 -179
- package/presets/opencode/plugins/task-status/tui.tsx +60 -16
- package/presets/opencode/plugins/task-status/types.ts +74 -0
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/agents/task-analyst.md +1 -1
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +9 -2
- package/presets/opencode/svelte/hooks/list-ai-local.mjs +17 -0
- package/presets/opencode/svelte/rules/agent-team-orchestrator.md +3 -1
- package/presets/opencode/svelte/rules/feature-delivery-workflow.md +4 -0
- package/presets/zcode/android-kotlin/adapter-map.json +1 -1
- package/presets/zcode/android-kotlin/agents/task-analyst.md +1 -1
- package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +9 -2
- package/presets/zcode/android-kotlin/hooks/list-ai-local.mjs +17 -0
- package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +3 -1
- package/presets/zcode/go/adapter-map.json +1 -1
- package/presets/zcode/go/agents/task-analyst.md +1 -1
- package/presets/zcode/go/hooks/chain-team-phases.sh +9 -2
- package/presets/zcode/go/hooks/list-ai-local.mjs +17 -0
- package/presets/zcode/go/rules/agent-team-orchestrator.md +3 -1
- package/presets/zcode/go/rules/feature-delivery-workflow.md +4 -0
- package/presets/zcode/ios-swift/adapter-map.json +1 -1
- package/presets/zcode/ios-swift/agents/task-analyst.md +1 -1
- package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +9 -2
- package/presets/zcode/ios-swift/hooks/list-ai-local.mjs +17 -0
- package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +3 -1
- package/presets/zcode/ios-swift/rules/feature-delivery-workflow.md +4 -0
- package/presets/zcode/java/adapter-map.json +1 -1
- package/presets/zcode/java/agents/task-analyst.md +1 -1
- package/presets/zcode/java/hooks/chain-team-phases.sh +9 -2
- package/presets/zcode/java/hooks/list-ai-local.mjs +17 -0
- package/presets/zcode/java/rules/agent-team-orchestrator.md +3 -1
- package/presets/zcode/java/rules/feature-delivery-workflow.md +4 -0
- package/presets/zcode/mcp-ts/adapter-map.json +1 -1
- package/presets/zcode/mcp-ts/agents/task-analyst.md +1 -1
- package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +9 -2
- package/presets/zcode/mcp-ts/hooks/list-ai-local.mjs +17 -0
- package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +3 -1
- package/presets/zcode/mcp-ts/rules/feature-delivery-workflow.md +4 -0
- package/presets/zcode/mol/adapter-map.json +1 -1
- package/presets/zcode/mol/agents/task-analyst.md +1 -1
- package/presets/zcode/mol/hooks/chain-team-phases.sh +9 -2
- package/presets/zcode/mol/hooks/list-ai-local.mjs +17 -0
- package/presets/zcode/mol/rules/agent-team-orchestrator.md +3 -1
- package/presets/zcode/mol/rules/feature-delivery-workflow.md +4 -0
- package/presets/zcode/next/adapter-map.json +9 -1
- package/presets/zcode/next/agents/ci-investigator.md +5 -2
- package/presets/zcode/next/agents/debugger.md +5 -2
- package/presets/zcode/next/agents/feature-developer.md +5 -2
- package/presets/zcode/next/agents/task-analyst.md +1 -1
- package/presets/zcode/next/commands/README.md +1 -1
- package/presets/zcode/next/commands/task.md +1 -1
- package/presets/zcode/next/hooks/chain-team-phases.sh +9 -2
- package/presets/zcode/next/hooks/list-ai-local.mjs +17 -0
- package/presets/zcode/next/rules/agent-team-orchestrator.md +3 -1
- package/presets/zcode/next/rules/feature-delivery-workflow.md +8 -0
- package/presets/zcode/next/team/README.md +7 -3
- package/presets/zcode/nuxt/adapter-map.json +1 -1
- package/presets/zcode/nuxt/agents/task-analyst.md +1 -1
- package/presets/zcode/nuxt/hooks/chain-team-phases.sh +9 -2
- package/presets/zcode/nuxt/hooks/list-ai-local.mjs +17 -0
- package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +3 -1
- package/presets/zcode/nuxt/rules/feature-delivery-workflow.md +4 -0
- package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
- package/presets/zcode/php-hexagonal/agents/task-analyst.md +1 -1
- package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +9 -2
- package/presets/zcode/php-hexagonal/hooks/list-ai-local.mjs +17 -0
- package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +3 -1
- package/presets/zcode/php-hexagonal/rules/feature-delivery-workflow.md +4 -0
- package/presets/zcode/php-laravel/adapter-map.json +1 -1
- package/presets/zcode/php-laravel/agents/task-analyst.md +1 -1
- package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +9 -2
- package/presets/zcode/php-laravel/hooks/list-ai-local.mjs +17 -0
- package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +3 -1
- package/presets/zcode/php-laravel/rules/feature-delivery-workflow.md +4 -0
- package/presets/zcode/svelte/adapter-map.json +1 -1
- package/presets/zcode/svelte/agents/task-analyst.md +1 -1
- package/presets/zcode/svelte/hooks/chain-team-phases.sh +9 -2
- package/presets/zcode/svelte/hooks/list-ai-local.mjs +17 -0
- package/presets/zcode/svelte/rules/agent-team-orchestrator.md +3 -1
- package/presets/zcode/svelte/rules/feature-delivery-workflow.md +4 -0
- package/scripts/report-context-cost.mjs +432 -0
- package/presets/_shared/ai-local/scripts/upstream-research.mjs +0 -2964
- package/presets/claude/next/commands/upstream-research.md +0 -23
- package/presets/claude/next/team/upstream/config.json +0 -31
- package/presets/claude/next/team/upstream/digest-template.md +0 -55
- package/presets/claude/next/team/upstream/jobs.json +0 -34
- package/presets/claude/next/team/upstream/opencode.json +0 -34
- package/presets/claude/next/team/upstream/projects.json +0 -4
- package/presets/claude/next/team/upstream/prompt.md +0 -77
- package/presets/claude/next/team/upstream/signatures.json +0 -9
- package/presets/cursor/next/commands/upstream-research.md +0 -23
- package/presets/cursor/next/team/upstream/config.json +0 -31
- package/presets/cursor/next/team/upstream/digest-template.md +0 -55
- package/presets/cursor/next/team/upstream/jobs.json +0 -34
- package/presets/cursor/next/team/upstream/opencode.json +0 -34
- package/presets/cursor/next/team/upstream/projects.json +0 -4
- package/presets/cursor/next/team/upstream/prompt.md +0 -77
- package/presets/cursor/next/team/upstream/signatures.json +0 -9
- package/presets/mavis/next/commands/upstream-research.md +0 -18
- package/presets/mavis/next/team/upstream/config.json +0 -31
- package/presets/mavis/next/team/upstream/digest-template.md +0 -55
- package/presets/mavis/next/team/upstream/jobs.json +0 -34
- package/presets/mavis/next/team/upstream/opencode.json +0 -34
- package/presets/mavis/next/team/upstream/projects.json +0 -4
- package/presets/mavis/next/team/upstream/prompt.md +0 -77
- package/presets/mavis/next/team/upstream/signatures.json +0 -9
- package/presets/opencode/next/commands/upstream-research.md +0 -26
- package/presets/opencode/next/team/upstream/config.json +0 -31
- package/presets/opencode/next/team/upstream/digest-template.md +0 -55
- package/presets/opencode/next/team/upstream/jobs.json +0 -34
- package/presets/opencode/next/team/upstream/opencode.json +0 -34
- package/presets/opencode/next/team/upstream/projects.json +0 -4
- package/presets/opencode/next/team/upstream/prompt.md +0 -77
- package/presets/opencode/next/team/upstream/signatures.json +0 -9
- package/presets/zcode/next/commands/upstream-research.md +0 -26
- package/presets/zcode/next/team/upstream/config.json +0 -31
- package/presets/zcode/next/team/upstream/digest-template.md +0 -55
- package/presets/zcode/next/team/upstream/jobs.json +0 -34
- package/presets/zcode/next/team/upstream/opencode.json +0 -34
- package/presets/zcode/next/team/upstream/projects.json +0 -4
- package/presets/zcode/next/team/upstream/prompt.md +0 -77
- package/presets/zcode/next/team/upstream/signatures.json +0 -9
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import fs from "node:fs"
|
|
2
2
|
import type { Dirent } from "node:fs"
|
|
3
|
+
import os from "node:os"
|
|
3
4
|
import path from "node:path"
|
|
4
|
-
import { createEtaStats, estimateEta } from "./eta"
|
|
5
|
-
import type { EtaStats } from "./eta"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export type TaskStore = { view: TaskView | null | undefined }
|
|
5
|
+
import { createEtaStats, estimateEta } from "./eta.ts"
|
|
6
|
+
import type { EtaStats } from "./eta.ts"
|
|
7
|
+
import { formatAge, formatDuration, formatEta } from "./format.ts"
|
|
8
|
+
import { logTexts, normalize, verbatimPrompt } from "./prompt-text.ts"
|
|
9
|
+
import type {
|
|
10
|
+
Metrics,
|
|
11
|
+
MetricEvent,
|
|
12
|
+
PauseScope,
|
|
13
|
+
Pipeline,
|
|
14
|
+
Status,
|
|
15
|
+
TaskStore,
|
|
16
|
+
TaskTone,
|
|
17
|
+
TaskView,
|
|
18
|
+
} from "./types.ts"
|
|
19
|
+
|
|
20
|
+
export type { TaskStore, TaskTone, TaskView, TaskField } from "./types.ts"
|
|
21
21
|
|
|
22
22
|
export type MemoryStorage = {
|
|
23
23
|
memory: <T>(key: string, options: { initial: T }) => [T, (mutate: (draft: T) => void) => void]
|
|
@@ -30,52 +30,33 @@ export type TaskWatcherOptions = {
|
|
|
30
30
|
userTexts: (sessionID: string) => Promise<string[]>
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
type Attempt = {
|
|
34
|
-
agent?: string
|
|
35
|
-
stepIndex?: number
|
|
36
|
-
attempt?: number
|
|
37
|
-
startedAt?: string
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type Status = {
|
|
41
|
-
state?: string
|
|
42
|
-
pipelineIndex?: number
|
|
43
|
-
currentAgent?: string | null
|
|
44
|
-
awaitingHumanGate?: boolean
|
|
45
|
-
activeHumanGateEventId?: string | null
|
|
46
|
-
activeAttempts?: Record<string, Attempt>
|
|
47
|
-
lastCompletedAttempt?: { attemptId?: string; completedAt?: string }
|
|
48
|
-
updatedAt?: string
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
type Pipeline = {
|
|
52
|
-
steps?: { agent?: string | string[]; label?: string; parallel?: boolean }[]
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
type MetricEvent = {
|
|
56
|
-
type?: string
|
|
57
|
-
at?: string
|
|
58
|
-
eventId?: string
|
|
59
|
-
attemptId?: string
|
|
60
|
-
agent?: string
|
|
61
|
-
role?: string
|
|
62
|
-
durationMs?: number
|
|
63
|
-
stepIndex?: number
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
type Metrics = { events?: MetricEvent[] }
|
|
67
|
-
|
|
68
33
|
type PromptEntry = { slug: string; texts: string[]; updatedAt: number }
|
|
69
34
|
|
|
70
35
|
const TEAM_REL = path.join(".ai.local", "team")
|
|
71
36
|
const TICK_MS = 1000
|
|
72
37
|
const SYNC_MS = 5000
|
|
73
38
|
const INDEX_MS = 30000
|
|
39
|
+
const ROOT_MS = 30000
|
|
40
|
+
const OFFLINE_MS = 60000
|
|
41
|
+
const SESSION_CACHE = 4
|
|
74
42
|
const STALE_ATTEMPT_MS = 6 * 60 * 60 * 1000
|
|
75
43
|
const STALE_GATE_MS = 24 * 60 * 60 * 1000
|
|
44
|
+
const STALE_P90_FACTOR = 2
|
|
76
45
|
const MIN_PARTIAL = 24
|
|
77
46
|
const TERMINAL = new Set(["completed"])
|
|
78
47
|
|
|
48
|
+
const DEBUG = process.env.OPENCODE_TASK_STATUS_DEBUG === "1"
|
|
49
|
+
const DEBUG_FILE = path.join(os.tmpdir(), "ai-rules-task-status-debug.log")
|
|
50
|
+
|
|
51
|
+
export const logTaskDebug = (line: string): void => {
|
|
52
|
+
if (!DEBUG) return
|
|
53
|
+
try {
|
|
54
|
+
fs.appendFileSync(DEBUG_FILE, `${new Date().toISOString()} ${line}\n`)
|
|
55
|
+
} catch {
|
|
56
|
+
// Debug output must never affect the sidebar.
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
79
60
|
const MARKER: Record<string, string> = {
|
|
80
61
|
in_progress: "●",
|
|
81
62
|
awaiting_approval: "⏸",
|
|
@@ -125,6 +106,15 @@ const findTeamRoot = (start: string): string | null => {
|
|
|
125
106
|
}
|
|
126
107
|
}
|
|
127
108
|
|
|
109
|
+
let rootCache: { start: string; root: string | null; at: number } | undefined
|
|
110
|
+
|
|
111
|
+
const cachedTeamRoot = (start: string, now: number): string | null => {
|
|
112
|
+
if (rootCache && rootCache.start === start && now - rootCache.at < ROOT_MS) return rootCache.root
|
|
113
|
+
const root = findTeamRoot(start)
|
|
114
|
+
rootCache = { start, root, at: now }
|
|
115
|
+
return root
|
|
116
|
+
}
|
|
117
|
+
|
|
128
118
|
const statusFile = (root: string, slug: string) => path.join(root, "tasks", slug, "status.json")
|
|
129
119
|
|
|
130
120
|
const overlayDir = (root: string): string | null => {
|
|
@@ -132,45 +122,84 @@ const overlayDir = (root: string): string | null => {
|
|
|
132
122
|
return path.basename(overlay) === ".ai.local" ? overlay : null
|
|
133
123
|
}
|
|
134
124
|
|
|
135
|
-
const
|
|
125
|
+
const isPresent = (file: string): boolean => {
|
|
126
|
+
try {
|
|
127
|
+
return fs.statSync(file).isFile()
|
|
128
|
+
} catch (error) {
|
|
129
|
+
return (error as { code?: string }).code !== "ENOENT"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const taskSentinel = (root: string, slug: string) => path.join(root, "tasks", slug, "STOP")
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A task-scoped STOP wins over the overlay sentinel: the tracker writes the
|
|
137
|
+
* first, the operator pause writes the second.
|
|
138
|
+
*/
|
|
139
|
+
export const pauseState = (root: string, slug?: string): PauseScope | null => {
|
|
140
|
+
if (slug && isPresent(taskSentinel(root, slug))) return "task"
|
|
136
141
|
const overlay = overlayDir(root)
|
|
137
|
-
if (!overlay) return
|
|
138
|
-
return ["STOP", "ESTOP"].some((name) =>
|
|
139
|
-
try {
|
|
140
|
-
return fs.statSync(path.join(overlay, name)).isFile()
|
|
141
|
-
} catch (error) {
|
|
142
|
-
return (error as { code?: string }).code !== "ENOENT"
|
|
143
|
-
}
|
|
144
|
-
})
|
|
142
|
+
if (!overlay) return null
|
|
143
|
+
return ["STOP", "ESTOP"].some((name) => isPresent(path.join(overlay, name))) ? "repo" : null
|
|
145
144
|
}
|
|
146
145
|
|
|
147
|
-
|
|
146
|
+
const pausePayload = (scope: PauseScope) =>
|
|
147
|
+
JSON.stringify({ reason: "soft stop requested from the task sidebar", scope })
|
|
148
|
+
|
|
149
|
+
/** The scope actually written, or `null` when no sentinel could be written. */
|
|
150
|
+
export const engagePause = (root: string, slug?: string): PauseScope | null => {
|
|
151
|
+
if (slug) {
|
|
152
|
+
try {
|
|
153
|
+
fs.writeFileSync(taskSentinel(root, slug), pausePayload("task"), "utf8")
|
|
154
|
+
return "task"
|
|
155
|
+
} catch {
|
|
156
|
+
// A task directory can disappear under a stale view; fall back to the repo sentinel.
|
|
157
|
+
}
|
|
158
|
+
}
|
|
148
159
|
const overlay = overlayDir(root)
|
|
149
|
-
if (!overlay) return
|
|
160
|
+
if (!overlay) return null
|
|
150
161
|
try {
|
|
151
|
-
fs.writeFileSync(
|
|
152
|
-
|
|
153
|
-
JSON.stringify({ reason: "soft stop requested from the task sidebar" }),
|
|
154
|
-
"utf8",
|
|
155
|
-
)
|
|
156
|
-
return true
|
|
162
|
+
fs.writeFileSync(path.join(overlay, "STOP"), pausePayload("repo"), "utf8")
|
|
163
|
+
return "repo"
|
|
157
164
|
} catch {
|
|
158
|
-
return
|
|
165
|
+
return null
|
|
159
166
|
}
|
|
160
167
|
}
|
|
161
168
|
|
|
162
|
-
|
|
169
|
+
/**
|
|
170
|
+
* What a sidebar affordance or a resume word may lift: a task sentinel or a
|
|
171
|
+
* repo `STOP`. A repo `ESTOP` alone is emergency-stop semantics — it is
|
|
172
|
+
* displayed as a repo pause, but nothing automatic clears it.
|
|
173
|
+
*/
|
|
174
|
+
export const resumableScope = (root: string, slug?: string): PauseScope | null => {
|
|
175
|
+
if (slug && isPresent(taskSentinel(root, slug))) return "task"
|
|
163
176
|
const overlay = overlayDir(root)
|
|
164
|
-
if (!overlay) return
|
|
177
|
+
if (!overlay) return null
|
|
178
|
+
return isPresent(path.join(overlay, "STOP")) ? "repo" : null
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Clear exactly the named scope's sentinel. A repo resume lifts the operator
|
|
183
|
+
* `STOP` only: an `ESTOP` is removed by hand alone, never by a resume word or
|
|
184
|
+
* a sidebar button.
|
|
185
|
+
*/
|
|
186
|
+
export const clearPause = (root: string, slug: string | undefined, scope: PauseScope): boolean => {
|
|
165
187
|
let cleared = false
|
|
166
|
-
|
|
167
|
-
|
|
188
|
+
const targets: string[] = []
|
|
189
|
+
if (scope === "task") {
|
|
190
|
+
if (!slug) return false
|
|
191
|
+
targets.push(taskSentinel(root, slug))
|
|
192
|
+
} else {
|
|
193
|
+
const overlay = overlayDir(root)
|
|
194
|
+
if (overlay) targets.push(path.join(overlay, "STOP"))
|
|
195
|
+
}
|
|
196
|
+
for (const file of targets) {
|
|
168
197
|
if (!fs.existsSync(file)) continue
|
|
169
198
|
try {
|
|
170
199
|
fs.rmSync(file, { force: true })
|
|
171
200
|
cleared = true
|
|
172
201
|
} catch {
|
|
173
|
-
//
|
|
202
|
+
// Leave an undeletable sentinel for the hook to report.
|
|
174
203
|
}
|
|
175
204
|
}
|
|
176
205
|
return cleared
|
|
@@ -188,22 +217,8 @@ const toMs = (value?: string): number | undefined => {
|
|
|
188
217
|
return Number.isFinite(parsed) ? parsed : undefined
|
|
189
218
|
}
|
|
190
219
|
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
if (seconds < 60) return `${seconds}s`
|
|
194
|
-
const minutes = Math.floor(seconds / 60)
|
|
195
|
-
if (minutes < 60) return `${minutes}m`
|
|
196
|
-
const hours = Math.floor(minutes / 60)
|
|
197
|
-
if (hours < 48) return `${hours}h ${String(minutes % 60).padStart(2, "0")}m`
|
|
198
|
-
return `${Math.floor(hours / 24)}d ${hours % 24}h`
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const formatAge = (ms: number): string => `${formatDuration(ms)} ago`
|
|
202
|
-
|
|
203
|
-
const formatEta = (eta: { p50Ms: number; p90Ms: number }): string =>
|
|
204
|
-
eta.p90Ms > eta.p50Ms * 1.5
|
|
205
|
-
? `~${formatDuration(eta.p50Ms)} · p90 ${formatDuration(eta.p90Ms)}`
|
|
206
|
-
: `~${formatDuration(eta.p50Ms)}`
|
|
220
|
+
const truncate = (value: string, max: number): string =>
|
|
221
|
+
value.length > max ? `${value.slice(0, max - 1)}…` : value
|
|
207
222
|
|
|
208
223
|
const progressBar = (value: number, total: number, width = 8): string => {
|
|
209
224
|
if (total <= 0) return ""
|
|
@@ -211,35 +226,6 @@ const progressBar = (value: number, total: number, width = 8): string => {
|
|
|
211
226
|
return `${"█".repeat(filled)}${"░".repeat(width - filled)}`
|
|
212
227
|
}
|
|
213
228
|
|
|
214
|
-
const truncate = (value: string, max: number): string =>
|
|
215
|
-
value.length > max ? `${value.slice(0, max - 1)}…` : value
|
|
216
|
-
|
|
217
|
-
const normalize = (text: string): string => text.toLowerCase().replace(/\s+/g, " ").trim()
|
|
218
|
-
|
|
219
|
-
const stripFrontmatter = (text: string): string =>
|
|
220
|
-
text.startsWith("---") ? text.replace(/^---[\s\S]*?\n---\s*/, "") : text
|
|
221
|
-
|
|
222
|
-
const promptText = (raw: string): string => {
|
|
223
|
-
const lines = stripFrontmatter(raw).split("\n")
|
|
224
|
-
const start = lines.findIndex((line) => /^#+\s*Verbatim prompt\s*$/i.test(line.trim()))
|
|
225
|
-
const slice = start >= 0 ? lines.slice(start + 1) : lines
|
|
226
|
-
const kept: string[] = []
|
|
227
|
-
for (const line of slice) {
|
|
228
|
-
if (/^#+\s/.test(line)) {
|
|
229
|
-
if (start >= 0) break
|
|
230
|
-
continue
|
|
231
|
-
}
|
|
232
|
-
const trimmed = line.trim()
|
|
233
|
-
const meta = /^(language|slug|created|source|command|capturedAt):/i.test(trimmed)
|
|
234
|
-
if (trimmed === "" || trimmed.startsWith("```") || meta) continue
|
|
235
|
-
kept.push(trimmed)
|
|
236
|
-
}
|
|
237
|
-
return kept.join("\n")
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const logTexts = (raw: string): string[] =>
|
|
241
|
-
[...raw.matchAll(/```(?:text)?\n([\s\S]*?)```/g)].map((match) => match[1])
|
|
242
|
-
|
|
243
229
|
const buildPromptIndex = (root: string): PromptEntry[] => {
|
|
244
230
|
const dir = path.join(root, "tasks")
|
|
245
231
|
let entries: Dirent[]
|
|
@@ -260,7 +246,7 @@ const buildPromptIndex = (root: string): PromptEntry[] => {
|
|
|
260
246
|
const stat = fs.statSync(filePath)
|
|
261
247
|
updatedAt = Math.max(updatedAt, stat.mtimeMs)
|
|
262
248
|
const raw = fs.readFileSync(filePath, "utf8")
|
|
263
|
-
const parts = file === "prompt.md" ? [
|
|
249
|
+
const parts = file === "prompt.md" ? [verbatimPrompt(raw)] : logTexts(raw)
|
|
264
250
|
for (const part of parts) {
|
|
265
251
|
const text = normalize(part)
|
|
266
252
|
if (text.length > 0) texts.push(text)
|
|
@@ -277,35 +263,53 @@ const buildPromptIndex = (root: string): PromptEntry[] => {
|
|
|
277
263
|
return index
|
|
278
264
|
}
|
|
279
265
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
266
|
+
/**
|
|
267
|
+
* Tier-monotonic: a stronger tier always outscores a weaker one, so a longer
|
|
268
|
+
* substring can never outrank a shorter match from a better tier, and an
|
|
269
|
+
* exact match (handled outright in `computeMatch`) always wins.
|
|
270
|
+
*/
|
|
271
|
+
const scoreFor = (message: string, prompt: string): number => {
|
|
272
|
+
if (message === prompt) return 3000 + prompt.length
|
|
273
|
+
if (prompt.length >= MIN_PARTIAL && message.includes(prompt)) {
|
|
274
|
+
return 2000 + Math.min(prompt.length, 999)
|
|
275
|
+
}
|
|
276
|
+
if (message.length >= MIN_PARTIAL && prompt.includes(message)) {
|
|
277
|
+
return 1000 + Math.min(message.length, 999)
|
|
278
|
+
}
|
|
279
|
+
return 0
|
|
285
280
|
}
|
|
286
281
|
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
if (normalized.length === 0) return undefined
|
|
282
|
+
const computeMatch = (index: PromptEntry[], messages: string[]): string | undefined => {
|
|
283
|
+
if (messages.length === 0) return undefined
|
|
290
284
|
|
|
291
285
|
let continued: string | undefined
|
|
292
|
-
for (const message of
|
|
286
|
+
for (const message of messages) {
|
|
293
287
|
const match = /(?:^|\s)\/task-continue\s+([a-z0-9][a-z0-9-]*)/i.exec(message)
|
|
294
288
|
if (match) continued = match[1]
|
|
295
289
|
}
|
|
296
290
|
if (continued) return continued
|
|
297
291
|
|
|
292
|
+
// An exact prompt match wins outright whatever the lengths involved; the
|
|
293
|
+
// substring tiers only rank the remaining candidates. Newest exact wins.
|
|
294
|
+
let exact: PromptEntry | undefined
|
|
295
|
+
for (const entry of index) {
|
|
296
|
+
if (!entry.texts.some((prompt) => messages.includes(prompt))) continue
|
|
297
|
+
if (!exact || entry.updatedAt > exact.updatedAt) exact = entry
|
|
298
|
+
}
|
|
299
|
+
if (exact) return exact.slug
|
|
300
|
+
|
|
298
301
|
let best: PromptEntry | undefined
|
|
299
302
|
let bestScore = 0
|
|
300
303
|
for (const entry of index) {
|
|
301
304
|
let score = 0
|
|
302
|
-
for (const message of
|
|
305
|
+
for (const message of messages) {
|
|
303
306
|
for (const prompt of entry.texts) {
|
|
304
|
-
|
|
307
|
+
score = Math.max(score, scoreFor(message, prompt))
|
|
305
308
|
}
|
|
306
309
|
}
|
|
307
310
|
if (score === 0) continue
|
|
308
|
-
|
|
311
|
+
// Recency breaks ties inside a tier; `scoreFor` keeps the tiers monotonic.
|
|
312
|
+
if (!best || score > bestScore || (score === bestScore && entry.updatedAt > best.updatedAt)) {
|
|
309
313
|
best = entry
|
|
310
314
|
bestScore = score
|
|
311
315
|
}
|
|
@@ -313,25 +317,43 @@ const matchTask = (index: PromptEntry[], messages: string[]): string | undefined
|
|
|
313
317
|
return best?.slug
|
|
314
318
|
}
|
|
315
319
|
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
320
|
+
const matchCache = new WeakMap<PromptEntry[], { key: string; slug: string | undefined }>()
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* The sidebar re-renders every second, so matching is memoized on the index
|
|
324
|
+
* generation and the message fingerprint; a rebuilt index (every 30s) drops it.
|
|
325
|
+
*/
|
|
326
|
+
const matchTask = (index: PromptEntry[], messages: string[]): string | undefined => {
|
|
327
|
+
const key = `${messages.length}:${messages[0] ?? ""}:${messages[messages.length - 1] ?? ""}`
|
|
328
|
+
const hit = matchCache.get(index)
|
|
329
|
+
if (hit && hit.key === key) return hit.slug
|
|
330
|
+
const slug = computeMatch(index, messages)
|
|
331
|
+
matchCache.set(index, { key, slug })
|
|
332
|
+
return slug
|
|
323
333
|
}
|
|
324
334
|
|
|
335
|
+
const ROLE_RULES: [RegExp, string][] = [
|
|
336
|
+
[/analyst|architect|router|migration|openspec/, "planning"],
|
|
337
|
+
[/verifier/, "validation"],
|
|
338
|
+
[/reviewer|auditor/, "review"],
|
|
339
|
+
[/test|qa|playwright/, "testing"],
|
|
340
|
+
[/writer/, "docs"],
|
|
341
|
+
[/developer|debugger|investigator|analyzer/, "implementation"],
|
|
342
|
+
]
|
|
343
|
+
|
|
344
|
+
const roleForAgent = (agent: string): string | undefined =>
|
|
345
|
+
ROLE_RULES.find(([pattern]) => pattern.test(agent))?.[1]
|
|
346
|
+
|
|
325
347
|
const actorOf = (
|
|
326
348
|
events: MetricEvent[],
|
|
327
349
|
attemptId: string | undefined,
|
|
328
350
|
fallbackAgent: string | undefined,
|
|
329
|
-
): { agent: string | undefined; role: string |
|
|
351
|
+
): { agent: string | undefined; role: string | undefined } => {
|
|
330
352
|
const event = attemptId
|
|
331
353
|
? events.findLast((item) => item.type === "attempt_started" && item.attemptId === attemptId)
|
|
332
354
|
: undefined
|
|
333
355
|
const agent = event?.agent ?? fallbackAgent
|
|
334
|
-
return { agent, role: event?.role ?? (agent ? roleForAgent(agent) :
|
|
356
|
+
return { agent, role: event?.role ?? (agent ? roleForAgent(agent) : undefined) }
|
|
335
357
|
}
|
|
336
358
|
|
|
337
359
|
// Agent-written metrics can carry a `task_started` in the future; a future clock would freeze elapsed at 0s.
|
|
@@ -358,6 +380,7 @@ const buildTaskView = (
|
|
|
358
380
|
status: Status,
|
|
359
381
|
now: number,
|
|
360
382
|
etaStats?: EtaStats,
|
|
383
|
+
offline = false,
|
|
361
384
|
): TaskView => {
|
|
362
385
|
const taskDir = path.join(root, "tasks", slug)
|
|
363
386
|
const pipeline = readJson<Pipeline>(path.join(taskDir, "pipeline.json"))
|
|
@@ -365,8 +388,10 @@ const buildTaskView = (
|
|
|
365
388
|
|
|
366
389
|
const state = status.state ?? "in_progress"
|
|
367
390
|
const done = TERMINAL.has(state)
|
|
368
|
-
const
|
|
369
|
-
const paused = state === "paused" ||
|
|
391
|
+
const pauseScope = done ? null : pauseState(root, slug)
|
|
392
|
+
const paused = state === "paused" || pauseScope !== null
|
|
393
|
+
const blocked = state === "blocked"
|
|
394
|
+
const awaitingReceipt = state === "awaiting_artifact_receipt"
|
|
370
395
|
|
|
371
396
|
const attempts = Object.entries(status.activeAttempts ?? {})
|
|
372
397
|
.map(([id, attempt]) => ({ id, ...attempt }))
|
|
@@ -389,12 +414,21 @@ const buildTaskView = (
|
|
|
389
414
|
const elapsed = startedAt === undefined ? undefined : Math.max(0, finishedAt - startedAt)
|
|
390
415
|
|
|
391
416
|
const freshness = currentStart ?? gateStart ?? updatedAt
|
|
392
|
-
|
|
417
|
+
// A long real step must not be called stale: the agent's own p90 raises the floor.
|
|
418
|
+
const agentP90 = current?.agent ? etaStats?.byAgent.get(current.agent)?.p90Ms : undefined
|
|
419
|
+
const staleAfter = Math.max(
|
|
420
|
+
status.awaitingHumanGate ? STALE_GATE_MS : STALE_ATTEMPT_MS,
|
|
421
|
+
(agentP90 ?? 0) * STALE_P90_FACTOR,
|
|
422
|
+
)
|
|
423
|
+
const stale = !done && !paused && now - freshness > staleAfter
|
|
424
|
+
|
|
425
|
+
const plannedStep = status.pipelineIndex === undefined ? undefined : pipeline?.steps?.[status.pipelineIndex]
|
|
426
|
+
const plannedAgent = Array.isArray(plannedStep?.agent) ? plannedStep?.agent[0] : plannedStep?.agent
|
|
393
427
|
|
|
394
428
|
const actor = actorOf(
|
|
395
429
|
events,
|
|
396
430
|
current?.id ?? status.lastCompletedAttempt?.attemptId,
|
|
397
|
-
current?.agent ?? status.currentAgent ??
|
|
431
|
+
current?.agent ?? status.currentAgent ?? plannedAgent,
|
|
398
432
|
)
|
|
399
433
|
const totalSteps = pipeline?.steps?.length
|
|
400
434
|
const stepNumber = done
|
|
@@ -407,10 +441,10 @@ const buildTaskView = (
|
|
|
407
441
|
|
|
408
442
|
const staleFor = now - freshness
|
|
409
443
|
|
|
410
|
-
const
|
|
444
|
+
const baseState =
|
|
411
445
|
state === "paused"
|
|
412
446
|
? `⏸ paused${elapsed === undefined ? "" : ` · ${formatDuration(elapsed)}`}`
|
|
413
|
-
:
|
|
447
|
+
: pauseScope !== null
|
|
414
448
|
? "⏸ stopping · in-flight attempt finishes"
|
|
415
449
|
: stale
|
|
416
450
|
? `◌ stale · ${formatAge(staleFor)}`
|
|
@@ -421,6 +455,8 @@ const buildTaskView = (
|
|
|
421
455
|
.filter(Boolean)
|
|
422
456
|
.join(" · ")
|
|
423
457
|
|
|
458
|
+
const statusLine = offline ? `${baseState} · offline` : baseState
|
|
459
|
+
|
|
424
460
|
const agents = attempts.map((attempt) => attempt.agent).filter((agent): agent is string => Boolean(agent))
|
|
425
461
|
const agentText = agents.length > 1 ? `${agents[0]} +${agents.length - 1}` : agents[0] ?? actor.agent
|
|
426
462
|
|
|
@@ -442,20 +478,20 @@ const buildTaskView = (
|
|
|
442
478
|
]
|
|
443
479
|
.filter(Boolean)
|
|
444
480
|
.join(" · ")
|
|
481
|
+
} else if (state === "in_progress") {
|
|
482
|
+
stepLine = `${stepNumber ? `${stepNumber}/${totalSteps ?? "?"}` : "?"} · no attempt started`
|
|
445
483
|
} else {
|
|
446
484
|
stepLine = `updated ${formatAge(now - updatedAt)}`
|
|
447
485
|
}
|
|
448
486
|
|
|
449
|
-
const tone = paused ? "warning" : toneFor(state, stale)
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
? estimateEta(pipeline?.steps ?? [], status, events, etaStats, now)
|
|
453
|
-
: null
|
|
487
|
+
const tone = paused ? "warning" : blocked ? "error" : toneFor(state, stale)
|
|
488
|
+
const showEta = !done && !paused && !blocked && !awaitingReceipt && !status.awaitingHumanGate && (totalSteps ?? 0) > 0
|
|
489
|
+
const eta = showEta && etaStats ? estimateEta(pipeline?.steps ?? [], status, events, etaStats, now) : null
|
|
454
490
|
const progressLabel = !done && totalSteps && stepNumber ? `${stepNumber}/${totalSteps}` : null
|
|
455
491
|
const summary =
|
|
456
492
|
state === "paused"
|
|
457
493
|
? ["paused", elapsed === undefined ? null : formatDuration(elapsed)].filter(Boolean).join(" · ")
|
|
458
|
-
:
|
|
494
|
+
: pauseScope !== null
|
|
459
495
|
? "stopping"
|
|
460
496
|
: stale
|
|
461
497
|
? `stale · ${formatAge(staleFor)}`
|
|
@@ -466,17 +502,22 @@ const buildTaskView = (
|
|
|
466
502
|
return {
|
|
467
503
|
fields: [
|
|
468
504
|
{ label: "task", value: truncate(slug, 34) },
|
|
469
|
-
{ label: "state", value: statusLine, tone },
|
|
505
|
+
{ label: "state", value: statusLine, tone: offline ? "muted" : tone },
|
|
470
506
|
{ label: "role", value: actor.role ?? "—" },
|
|
471
507
|
{ label: "agent", value: agentText ?? "—" },
|
|
472
508
|
{ label: "step", value: stepLine },
|
|
473
|
-
...(
|
|
509
|
+
...(showEta
|
|
510
|
+
? [{ label: "eta", value: eta ? formatEta(eta) : "—", tone: eta ? undefined : ("muted" as const) }]
|
|
511
|
+
: []),
|
|
474
512
|
],
|
|
475
|
-
summary,
|
|
476
|
-
tone,
|
|
513
|
+
summary: offline ? `offline · ${summary}` : summary,
|
|
514
|
+
tone: offline ? "muted" : tone,
|
|
477
515
|
slug,
|
|
478
516
|
root,
|
|
479
|
-
stoppable: !done && !paused,
|
|
517
|
+
stoppable: !done && !paused && !blocked && !status.awaitingHumanGate && state !== "awaiting_approval",
|
|
518
|
+
resumable: resumableScope(root, slug) !== null,
|
|
519
|
+
pausedScope: pauseScope ?? undefined,
|
|
520
|
+
offline,
|
|
480
521
|
}
|
|
481
522
|
}
|
|
482
523
|
|
|
@@ -519,32 +560,75 @@ const buildSessionView = (
|
|
|
519
560
|
sessionID: string,
|
|
520
561
|
texts: string[],
|
|
521
562
|
now: number,
|
|
522
|
-
options: TaskWatcherOptions,
|
|
563
|
+
options: Pick<TaskWatcherOptions, "sessionTitle">,
|
|
523
564
|
index: PromptEntry[],
|
|
524
565
|
etaStats?: EtaStats,
|
|
566
|
+
offline = false,
|
|
567
|
+
normalized?: string[],
|
|
525
568
|
): TaskView => {
|
|
526
|
-
const slug = matchTask(index, texts)
|
|
569
|
+
const slug = matchTask(index, normalized ?? texts.map(normalize).filter(Boolean))
|
|
527
570
|
if (slug && fs.existsSync(path.join(root, "tasks", slug))) {
|
|
528
571
|
const status = readJson<Status>(statusFile(root, slug))
|
|
529
|
-
return status ? buildTaskView(root, slug, status, now, etaStats) : buildNoteView(root, slug, now)
|
|
572
|
+
return status ? buildTaskView(root, slug, status, now, etaStats, offline) : buildNoteView(root, slug, now)
|
|
530
573
|
}
|
|
531
574
|
return buildPromptView(options.sessionTitle(sessionID) ?? "", texts)
|
|
532
575
|
}
|
|
533
576
|
|
|
577
|
+
export const resolveTaskView = (
|
|
578
|
+
root: string,
|
|
579
|
+
sessionID: string,
|
|
580
|
+
texts: string[],
|
|
581
|
+
now: number,
|
|
582
|
+
sessionTitle: (sessionID: string) => string | undefined,
|
|
583
|
+
offline = false,
|
|
584
|
+
): TaskView =>
|
|
585
|
+
buildSessionView(
|
|
586
|
+
root,
|
|
587
|
+
sessionID,
|
|
588
|
+
texts,
|
|
589
|
+
now,
|
|
590
|
+
{ sessionTitle },
|
|
591
|
+
buildPromptIndex(root),
|
|
592
|
+
createEtaStats(root, readJson),
|
|
593
|
+
offline,
|
|
594
|
+
)
|
|
595
|
+
|
|
596
|
+
type SessionState = {
|
|
597
|
+
id: string
|
|
598
|
+
texts: string[]
|
|
599
|
+
textsNorm: string[]
|
|
600
|
+
fetchedAt: number
|
|
601
|
+
loading: boolean
|
|
602
|
+
errorAt?: number
|
|
603
|
+
resumeFor?: string
|
|
604
|
+
}
|
|
605
|
+
|
|
534
606
|
export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOptions) => {
|
|
535
607
|
const [state, update] = storage.memory<TaskStore>("view", { initial: { view: undefined } })
|
|
536
608
|
let index: PromptEntry[] = []
|
|
537
609
|
let indexAt = 0
|
|
538
610
|
let etaStats: EtaStats | undefined
|
|
539
611
|
let etaAt = 0
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
const sessionState = (id: string) => {
|
|
543
|
-
|
|
544
|
-
|
|
612
|
+
const sessions = new Map<string, SessionState>()
|
|
613
|
+
|
|
614
|
+
const sessionState = (id: string): SessionState => {
|
|
615
|
+
const existing = sessions.get(id)
|
|
616
|
+
if (existing) {
|
|
617
|
+
sessions.delete(id)
|
|
618
|
+
sessions.set(id, existing)
|
|
619
|
+
return existing
|
|
620
|
+
}
|
|
621
|
+
const created: SessionState = { id, texts: [], textsNorm: [], fetchedAt: 0, loading: false }
|
|
622
|
+
sessions.set(id, created)
|
|
623
|
+
while (sessions.size > SESSION_CACHE) {
|
|
624
|
+
const oldest = sessions.keys().next().value
|
|
625
|
+
if (oldest === undefined) break
|
|
626
|
+
sessions.delete(oldest)
|
|
627
|
+
}
|
|
628
|
+
return created
|
|
545
629
|
}
|
|
546
630
|
|
|
547
|
-
const syncSession = (
|
|
631
|
+
const syncSession = (id: string) => {
|
|
548
632
|
const current = sessionState(id)
|
|
549
633
|
if (current.loading || Date.now() - current.fetchedAt < SYNC_MS) return
|
|
550
634
|
current.loading = true
|
|
@@ -552,32 +636,43 @@ export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOp
|
|
|
552
636
|
.userTexts(id)
|
|
553
637
|
.then((texts) => {
|
|
554
638
|
current.texts = texts
|
|
639
|
+
current.textsNorm = texts.map(normalize).filter(Boolean)
|
|
555
640
|
current.fetchedAt = Date.now()
|
|
556
|
-
|
|
557
|
-
const key = `${texts.length}:${latest}`
|
|
558
|
-
if (latest && current.resumeFor !== key && resumeIntent(latest)) {
|
|
559
|
-
current.resumeFor = key
|
|
560
|
-
if (pauseSentinel(root)) clearPause(root)
|
|
561
|
-
}
|
|
641
|
+
current.errorAt = undefined
|
|
562
642
|
})
|
|
563
|
-
.catch(() => {
|
|
643
|
+
.catch((error: unknown) => {
|
|
644
|
+
current.errorAt = Date.now()
|
|
564
645
|
current.fetchedAt = Date.now() - SYNC_MS + 1000
|
|
646
|
+
logTaskDebug(`message.list failed for ${id}: ${error instanceof Error ? error.message : String(error)}`)
|
|
565
647
|
})
|
|
566
648
|
.finally(() => {
|
|
567
649
|
current.loading = false
|
|
568
650
|
})
|
|
569
651
|
}
|
|
570
652
|
|
|
653
|
+
const resume = (root: string, current: SessionState, slug: string | undefined) => {
|
|
654
|
+
if (!slug) return
|
|
655
|
+
const latest = current.texts.at(-1)?.trim() ?? ""
|
|
656
|
+
const key = `${current.texts.length}:${latest}`
|
|
657
|
+
if (!latest || current.resumeFor === key || !resumeIntent(latest)) return
|
|
658
|
+
current.resumeFor = key
|
|
659
|
+
const scope = resumableScope(root, slug)
|
|
660
|
+
if (scope && clearPause(root, slug, scope)) {
|
|
661
|
+
logTaskDebug(`resume intent cleared ${scope} pause for ${slug}`)
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
571
665
|
const refresh = () => {
|
|
572
666
|
const start = options.directory()
|
|
573
|
-
const
|
|
667
|
+
const now = Date.now()
|
|
668
|
+
const root = start ? cachedTeamRoot(start, now) : null
|
|
574
669
|
if (!root) {
|
|
670
|
+
logTaskDebug(`no team root from ${start ?? "unknown directory"}`)
|
|
575
671
|
update((draft) => {
|
|
576
672
|
draft.view = undefined
|
|
577
673
|
})
|
|
578
674
|
return
|
|
579
675
|
}
|
|
580
|
-
const now = Date.now()
|
|
581
676
|
if (now - indexAt > INDEX_MS) {
|
|
582
677
|
index = buildPromptIndex(root)
|
|
583
678
|
indexAt = now
|
|
@@ -588,16 +683,23 @@ export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOp
|
|
|
588
683
|
}
|
|
589
684
|
const sessionID = options.sessionID()
|
|
590
685
|
if (!sessionID) {
|
|
686
|
+
logTaskDebug("no session id")
|
|
591
687
|
update((draft) => {
|
|
592
688
|
draft.view = undefined
|
|
593
689
|
})
|
|
594
690
|
return
|
|
595
691
|
}
|
|
596
692
|
const current = sessionState(sessionID)
|
|
597
|
-
syncSession(
|
|
693
|
+
syncSession(sessionID)
|
|
694
|
+
const offline = current.errorAt !== undefined && now - current.errorAt < OFFLINE_MS
|
|
695
|
+
const view = buildSessionView(root, sessionID, current.texts, now, options, index, etaStats, offline, current.textsNorm)
|
|
696
|
+
resume(root, current, view.slug)
|
|
598
697
|
update((draft) => {
|
|
599
|
-
draft.view =
|
|
698
|
+
draft.view = view
|
|
600
699
|
})
|
|
700
|
+
logTaskDebug(
|
|
701
|
+
`session=${sessionID} messages=${current.texts.length} matched=${view.slug ?? "-"} view=${view.summary}`,
|
|
702
|
+
)
|
|
601
703
|
}
|
|
602
704
|
|
|
603
705
|
refresh()
|