@bonesofspring/ai-rules 0.2.63 → 0.2.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +60 -0
- package/README.md +10 -3
- package/bin/cli.js +7 -5
- package/bin/lib/ai-local-drift.js +7 -6
- package/bin/lib/engine-scripts.js +4 -0
- package/bin/lib/engine-upgrade.js +10 -2
- package/bin/lib/manifest-schema.js +12 -0
- package/bin/lib/seed-ai-local-team.js +13 -0
- package/bin/mavis-install.js +4 -3
- package/bin/opencode-install.js +22 -6
- package/bin/zcode-install.js +4 -3
- package/docs/MCP-CATALOG.md +1 -1
- package/docs/OPENCODE-COMPATIBILITY.md +3 -2
- package/docs/OPENCODE.md +22 -2
- package/docs/PRESET-CONTRIBUTION.md +2 -2
- package/docs/TEAM-DB.md +71 -4
- package/docs/openapi/team-db.v1.json +4817 -2795
- package/mcp/defectdojo-mcp.mjs +41 -11
- package/mcp/lib/defectdojo.mjs +45 -2
- package/package.json +8 -2
- package/presets/_shared/ai-local/scripts/aggregate-agent-task-metrics.mjs +279 -0
- package/presets/_shared/ai-local/scripts/team-db-api.mjs +471 -7
- package/presets/_shared/ai-local/scripts/team-db-backlog.mjs +1366 -0
- package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +573 -7
- package/presets/_shared/ai-local/scripts/team-db-project.mjs +288 -4
- package/presets/_shared/ai-local/scripts/team-db-scheduler.mjs +82 -10
- package/presets/_shared/ai-local/scripts/team-db-schema.mjs +83 -0
- package/presets/_shared/ai-local/scripts/team-db.mjs +69 -6
- package/presets/_shared/ai-local/scripts/upstream-research.mjs +3 -0
- package/presets/_shared/core/agent-team/agent-task-metrics.md +7 -2
- package/presets/_shared/core/agent-team/agent-team-orchestrator.md +1 -0
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +225 -0
- package/presets/_shared/hooks/run-hook.mjs +2 -1
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +225 -0
- package/presets/claude/android-kotlin/hooks/run-hook.mjs +2 -1
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
- package/presets/claude/go/hooks/chain-team-phases.sh +225 -0
- package/presets/claude/go/hooks/run-hook.mjs +2 -1
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +225 -0
- package/presets/claude/ios-swift/hooks/run-hook.mjs +2 -1
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
- package/presets/claude/java/hooks/chain-team-phases.sh +225 -0
- package/presets/claude/java/hooks/run-hook.mjs +2 -1
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +225 -0
- package/presets/claude/mcp-ts/hooks/run-hook.mjs +2 -1
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
- package/presets/claude/mol/hooks/chain-team-phases.sh +225 -0
- package/presets/claude/mol/hooks/run-hook.mjs +2 -1
- package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
- package/presets/claude/next/agents/code-reviewer.md +1 -0
- package/presets/claude/next/agents/mockup-reviewer.md +2 -1
- package/presets/claude/next/agents/task-analyst.md +2 -0
- package/presets/claude/next/commands/task.md +7 -1
- package/presets/claude/next/commands/technical-retro.md +7 -1
- package/presets/claude/next/commands/upstream-research.md +1 -1
- package/presets/claude/next/hooks/chain-team-phases.sh +225 -0
- package/presets/claude/next/hooks/run-hook.mjs +2 -1
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
- package/presets/claude/next/skills/figma-fidelity/SKILL.md +4 -1
- package/presets/claude/next/skills/mockup-review/SKILL.md +4 -0
- package/presets/claude/next/team/README.md +5 -1
- package/presets/claude/next/team/upstream/jobs.json +34 -0
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +225 -0
- package/presets/claude/nuxt/hooks/run-hook.mjs +2 -1
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +225 -0
- package/presets/claude/php-hexagonal/hooks/run-hook.mjs +2 -1
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +225 -0
- package/presets/claude/php-laravel/hooks/run-hook.mjs +2 -1
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
- package/presets/claude/svelte/hooks/chain-team-phases.sh +225 -0
- package/presets/claude/svelte/hooks/run-hook.mjs +2 -1
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +1 -0
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +225 -0
- package/presets/cursor/android-kotlin/hooks/run-hook.mjs +2 -1
- package/presets/cursor/go/hooks/chain-team-phases.sh +225 -0
- package/presets/cursor/go/hooks/run-hook.mjs +2 -1
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +225 -0
- package/presets/cursor/ios-swift/hooks/run-hook.mjs +2 -1
- package/presets/cursor/java/hooks/chain-team-phases.sh +225 -0
- package/presets/cursor/java/hooks/run-hook.mjs +2 -1
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +225 -0
- package/presets/cursor/mcp-ts/hooks/run-hook.mjs +2 -1
- package/presets/cursor/mol/hooks/chain-team-phases.sh +225 -0
- package/presets/cursor/mol/hooks/run-hook.mjs +2 -1
- package/presets/cursor/next/agents/code-reviewer.md +1 -0
- package/presets/cursor/next/agents/mockup-reviewer.md +2 -1
- package/presets/cursor/next/agents/task-analyst.md +2 -0
- package/presets/cursor/next/ai-local/rules-library/storybook-dev-compare-figma.md +1 -0
- package/presets/cursor/next/ai-local/rules-library/ui-change-review-gate.md +1 -0
- package/presets/cursor/next/commands/task.md +7 -1
- package/presets/cursor/next/commands/technical-retro.md +7 -1
- package/presets/cursor/next/commands/upstream-research.md +1 -1
- package/presets/cursor/next/hooks/chain-team-phases.sh +225 -0
- package/presets/cursor/next/hooks/run-hook.mjs +2 -1
- package/presets/cursor/next/skills/figma-fidelity/SKILL.md +4 -1
- package/presets/cursor/next/skills/mockup-review/SKILL.md +4 -0
- package/presets/cursor/next/team/README.md +5 -1
- package/presets/cursor/next/team/upstream/jobs.json +34 -0
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +225 -0
- package/presets/cursor/nuxt/hooks/run-hook.mjs +2 -1
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +225 -0
- package/presets/cursor/php-hexagonal/hooks/run-hook.mjs +2 -1
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +225 -0
- package/presets/cursor/php-laravel/hooks/run-hook.mjs +2 -1
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +225 -0
- package/presets/cursor/svelte/hooks/run-hook.mjs +2 -1
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +225 -0
- package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +1 -0
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/hooks/chain-team-phases.sh +225 -0
- package/presets/mavis/go/rules/agent-team-orchestrator.md +1 -0
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +225 -0
- package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +1 -0
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/hooks/chain-team-phases.sh +225 -0
- package/presets/mavis/java/rules/agent-team-orchestrator.md +1 -0
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +225 -0
- package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +1 -0
- package/presets/mavis/mol/adapter-map.json +1 -1
- package/presets/mavis/mol/hooks/chain-team-phases.sh +225 -0
- package/presets/mavis/mol/rules/agent-team-orchestrator.md +1 -0
- package/presets/mavis/next/adapter-map.json +9 -1
- package/presets/mavis/next/agents/code-reviewer.md +1 -0
- package/presets/mavis/next/agents/mockup-reviewer.md +2 -1
- package/presets/mavis/next/agents/task-analyst.md +2 -0
- package/presets/mavis/next/ai-local/rules-library/storybook-dev-compare-figma.md +1 -0
- package/presets/mavis/next/ai-local/rules-library/ui-change-review-gate.md +1 -0
- package/presets/mavis/next/commands/task.md +7 -1
- package/presets/mavis/next/commands/technical-retro.md +7 -1
- package/presets/mavis/next/commands/upstream-research.md +1 -1
- package/presets/mavis/next/hooks/chain-team-phases.sh +225 -0
- package/presets/mavis/next/rules/agent-team-orchestrator.md +1 -0
- package/presets/mavis/next/skills/figma-fidelity/SKILL.md +4 -1
- package/presets/mavis/next/skills/mockup-review/SKILL.md +4 -0
- package/presets/mavis/next/team/README.md +5 -1
- package/presets/mavis/next/team/upstream/jobs.json +34 -0
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +225 -0
- package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +1 -0
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +225 -0
- package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +1 -0
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +225 -0
- package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +1 -0
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +225 -0
- package/presets/mavis/svelte/rules/agent-team-orchestrator.md +1 -0
- package/presets/opencode/android-kotlin/OPENCODE.md +4 -1
- package/presets/opencode/android-kotlin/README.md +1 -0
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/hooks/README.md +4 -2
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +225 -0
- package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +1 -0
- package/presets/opencode/go/OPENCODE.md +4 -1
- package/presets/opencode/go/README.md +1 -0
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/hooks/README.md +4 -2
- package/presets/opencode/go/hooks/chain-team-phases.sh +225 -0
- package/presets/opencode/go/rules/agent-team-orchestrator.md +1 -0
- package/presets/opencode/ios-swift/OPENCODE.md +4 -1
- package/presets/opencode/ios-swift/README.md +1 -0
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/hooks/README.md +4 -2
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +225 -0
- package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +1 -0
- package/presets/opencode/java/OPENCODE.md +4 -1
- package/presets/opencode/java/README.md +1 -0
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/hooks/README.md +4 -2
- package/presets/opencode/java/hooks/chain-team-phases.sh +225 -0
- package/presets/opencode/java/rules/agent-team-orchestrator.md +1 -0
- package/presets/opencode/mcp-ts/OPENCODE.md +4 -1
- package/presets/opencode/mcp-ts/README.md +1 -0
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/hooks/README.md +4 -2
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +225 -0
- package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +1 -0
- package/presets/opencode/mol/OPENCODE.md +4 -1
- package/presets/opencode/mol/README.md +1 -0
- package/presets/opencode/mol/adapter-map.json +1 -1
- package/presets/opencode/mol/hooks/README.md +4 -2
- package/presets/opencode/mol/hooks/chain-team-phases.sh +225 -0
- package/presets/opencode/mol/rules/agent-team-orchestrator.md +1 -0
- package/presets/opencode/next/OPENCODE.md +4 -1
- package/presets/opencode/next/README.md +1 -0
- package/presets/opencode/next/adapter-map.json +9 -1
- package/presets/opencode/next/agents/code-reviewer.md +1 -0
- package/presets/opencode/next/agents/mockup-reviewer.md +2 -1
- package/presets/opencode/next/agents/task-analyst.md +2 -0
- package/presets/opencode/next/ai-local/rules-library/storybook-dev-compare-figma.md +1 -0
- package/presets/opencode/next/ai-local/rules-library/ui-change-review-gate.md +1 -0
- package/presets/opencode/next/commands/task.md +7 -1
- package/presets/opencode/next/commands/technical-retro.md +7 -1
- package/presets/opencode/next/commands/upstream-research.md +1 -1
- package/presets/opencode/next/hooks/README.md +4 -2
- package/presets/opencode/next/hooks/chain-team-phases.sh +225 -0
- package/presets/opencode/next/rules/agent-team-orchestrator.md +1 -0
- package/presets/opencode/next/skills/figma-fidelity/SKILL.md +4 -1
- package/presets/opencode/next/skills/mockup-review/SKILL.md +4 -0
- package/presets/opencode/next/team/README.md +5 -1
- package/presets/opencode/next/team/upstream/jobs.json +34 -0
- package/presets/opencode/nuxt/OPENCODE.md +4 -1
- package/presets/opencode/nuxt/README.md +1 -0
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/hooks/README.md +4 -2
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +225 -0
- package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +1 -0
- package/presets/opencode/php-hexagonal/OPENCODE.md +4 -1
- package/presets/opencode/php-hexagonal/README.md +1 -0
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/hooks/README.md +4 -2
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +225 -0
- package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +1 -0
- package/presets/opencode/php-laravel/OPENCODE.md +4 -1
- package/presets/opencode/php-laravel/README.md +1 -0
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/hooks/README.md +4 -2
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +225 -0
- package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +1 -0
- package/presets/opencode/platform-contract.json +6 -0
- package/presets/opencode/plugins/task-status/README.md +92 -0
- package/presets/opencode/plugins/task-status/details-data.ts +130 -0
- package/presets/opencode/plugins/task-status/details.tsx +84 -0
- package/presets/opencode/plugins/task-status/eta.ts +230 -0
- package/presets/opencode/plugins/task-status/index.ts +6 -0
- package/presets/opencode/plugins/task-status/package.json +10 -0
- package/presets/opencode/plugins/task-status/task-view.ts +606 -0
- package/presets/opencode/plugins/task-status/tui.tsx +139 -0
- package/presets/opencode/svelte/OPENCODE.md +4 -1
- package/presets/opencode/svelte/README.md +1 -0
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/hooks/README.md +4 -2
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +225 -0
- package/presets/opencode/svelte/rules/agent-team-orchestrator.md +1 -0
- package/presets/zcode/android-kotlin/adapter-map.json +1 -1
- package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +225 -0
- package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +1 -0
- package/presets/zcode/go/adapter-map.json +1 -1
- package/presets/zcode/go/hooks/chain-team-phases.sh +225 -0
- package/presets/zcode/go/rules/agent-team-orchestrator.md +1 -0
- package/presets/zcode/ios-swift/adapter-map.json +1 -1
- package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +225 -0
- package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +1 -0
- package/presets/zcode/java/adapter-map.json +1 -1
- package/presets/zcode/java/hooks/chain-team-phases.sh +225 -0
- package/presets/zcode/java/rules/agent-team-orchestrator.md +1 -0
- package/presets/zcode/mcp-ts/adapter-map.json +1 -1
- package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +225 -0
- package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +1 -0
- package/presets/zcode/mol/adapter-map.json +1 -1
- package/presets/zcode/mol/hooks/chain-team-phases.sh +225 -0
- package/presets/zcode/mol/rules/agent-team-orchestrator.md +1 -0
- package/presets/zcode/next/adapter-map.json +9 -1
- package/presets/zcode/next/agents/code-reviewer.md +1 -0
- package/presets/zcode/next/agents/mockup-reviewer.md +2 -1
- package/presets/zcode/next/agents/task-analyst.md +2 -0
- package/presets/zcode/next/ai-local/rules-library/storybook-dev-compare-figma.md +1 -0
- package/presets/zcode/next/ai-local/rules-library/ui-change-review-gate.md +1 -0
- package/presets/zcode/next/commands/task.md +7 -1
- package/presets/zcode/next/commands/technical-retro.md +7 -1
- package/presets/zcode/next/commands/upstream-research.md +1 -1
- package/presets/zcode/next/hooks/chain-team-phases.sh +225 -0
- package/presets/zcode/next/rules/agent-team-orchestrator.md +1 -0
- package/presets/zcode/next/skills/figma-fidelity/SKILL.md +4 -1
- package/presets/zcode/next/skills/mockup-review/SKILL.md +4 -0
- package/presets/zcode/next/team/README.md +5 -1
- package/presets/zcode/next/team/upstream/jobs.json +34 -0
- package/presets/zcode/nuxt/adapter-map.json +1 -1
- package/presets/zcode/nuxt/hooks/chain-team-phases.sh +225 -0
- package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +1 -0
- package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
- package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +225 -0
- package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +1 -0
- package/presets/zcode/php-laravel/adapter-map.json +1 -1
- package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +225 -0
- package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +1 -0
- package/presets/zcode/svelte/adapter-map.json +1 -1
- package/presets/zcode/svelte/hooks/chain-team-phases.sh +225 -0
- package/presets/zcode/svelte/rules/agent-team-orchestrator.md +1 -0
- package/scripts/aggregate-agent-task-metrics.mjs +48 -4
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Task status sidebar (OpenCode TUI plugin)
|
|
2
|
+
|
|
3
|
+
Shows the `/task` run of the active session in the TUI `sidebar.content` slot: slug, state, elapsed time, executor role and agent, current step. Each session tab maps to its own task; a tab without a task shows its prompt title instead.
|
|
4
|
+
|
|
5
|
+
## Layout
|
|
6
|
+
|
|
7
|
+
Modelled on the built-in MCP sidebar plugin (`packages/tui/src/feature-plugins/sidebar/mcp.tsx` in the OpenCode repo):
|
|
8
|
+
|
|
9
|
+
- header `▼ Task` toggles on click; collapsed it reads `▶ Task (running · 3/7 · 16h 05m)`
|
|
10
|
+
- each row is a flex row of a bold label and a value; the state value is colored by tone (success, warning, error, muted)
|
|
11
|
+
- the step row carries a progress bar, e.g. `3/7 ███░░░░░ · attempt 1 · 3h 35m`
|
|
12
|
+
- the `eta` row reads `~52m · p90 3h 32m`: estimated time to finish the remaining plan steps. It is hidden while the run waits on a human gate, is paused, stale or done — those states are already in the `state`/`step` rows
|
|
13
|
+
- clicking any row opens a details dialog with 3-cell side padding: `goal.md`, pipeline steps with the current one marked, present artifacts, the last manifest entries and the prompt. The body scrolls with ↑/↓, PgUp/PgDn, Home/End or the mouse wheel; `esc` closes it.
|
|
14
|
+
- a live task shows `■ stop` in the header; click → confirm → writes `.ai.local/STOP`, the hook's operator pause. The in-flight attempt finishes, no next step starts. Resume by saying `/task-continue <slug>`, `продолжай`, or `continue`: the plugin clears the sentinel on that intent and the local `task-resume` rule runs the resume procedure. The button disappears once the pause is engaged. <!-- i18n-keep: E4 -->
|
|
15
|
+
- a stale task reads `◌ stale · 8d 17h ago` with a muted tone instead of pretending to run
|
|
16
|
+
- the open flag lives in `context.storage.store("panel", { initial: { open: true } })`, so it survives restarts; the live view stays in `context.storage.memory`
|
|
17
|
+
- values use `wrapMode="none" truncate` and `minWidth={0}`, so a narrow sidebar truncates instead of wrapping
|
|
18
|
+
|
|
19
|
+
## Data
|
|
20
|
+
|
|
21
|
+
Reads the nearest `.ai.local/team/` above the session directory:
|
|
22
|
+
|
|
23
|
+
- `tasks/<slug>/prompt.md`, `prompt-log.md` — prompt text used for session matching
|
|
24
|
+
- `tasks/<slug>/status.json` — state, attempts, gate, timestamps
|
|
25
|
+
- `tasks/<slug>/pipeline.json` — step count and the agent for each remaining step
|
|
26
|
+
- `tasks/<slug>/metrics.json` — task start, role per attempt, attempt durations
|
|
27
|
+
- every `tasks/*/metrics.json` — historical attempt durations that feed the ETA medians
|
|
28
|
+
|
|
29
|
+
## ETA
|
|
30
|
+
|
|
31
|
+
`eta.ts` estimates the remaining agent work, not wall-clock time:
|
|
32
|
+
|
|
33
|
+
- per-agent median attempt duration and a per-step retry factor (attempts ÷ distinct steps, capped at 1.5) come from every `metrics.json` under the team root; the index is rebuilt with the prompt index, every 30s, through the same mtime cache
|
|
34
|
+
- remaining plan steps are summed, then scaled by 0.65: adding right-skewed per-step medians overestimates the median of the total
|
|
35
|
+
- a running step subtracts what it already spent (finished attempts plus the current attempt's elapsed), floored at 15% of its estimate
|
|
36
|
+
- `p90` is `max(4 × p50, 1.5 × √Σ p90²)` — the quadrature keeps the range from growing linearly with the step count
|
|
37
|
+
- a parallel step (`agent: [...]` or `parallel: true`) takes the slowest agent, not the sum
|
|
38
|
+
- fewer than 3 ledgers with finished attempts → no estimate
|
|
39
|
+
|
|
40
|
+
Calibrated on this repository's 66 ledgers: 52% of tasks finish below the p50 and 89% below the p90 when estimated before the first step; after half the steps, 47% and 87%.
|
|
41
|
+
|
|
42
|
+
The number excludes human gates and ignores parallelism between steps, so the actual wait is often 20–25% shorter than the p50. The tail is real: 16% of runs exceed 8h of work, which is why the row shows a p90 instead of a single number.
|
|
43
|
+
|
|
44
|
+
## Session mapping
|
|
45
|
+
|
|
46
|
+
Every tick the plugin reads the active route's session and its user messages (`client.message.list`, `type=user`, oldest first) and matches them against the prompt index:
|
|
47
|
+
|
|
48
|
+
- an exact or substring match of at least 24 characters maps the tab to that task, most recently updated match first
|
|
49
|
+
- a `/task-continue <slug>` message maps the tab directly to that slug
|
|
50
|
+
- a subagent session maps through `data.session.root(sessionID)`, so its sidebar shows the parent task
|
|
51
|
+
- no match → `prompt <session title>` and `state no task`; an `Untitled session` title falls back to the first user message
|
|
52
|
+
- a task with `prompt.md` but no `status.json` renders as a note (`note · 33m`)
|
|
53
|
+
|
|
54
|
+
Session messages refresh every 5s and the prompt index every 30s, so a `/task` tab picks up its task as soon as the agent writes `prompt.md`. The old global `active-task.json` pointer is no longer used for selection; it only helps locate the team root.
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
Shipped with `@bonesofspring/ai-rules` for every OpenCode preset. `ai-rules init opencode`
|
|
59
|
+
and `ai-rules update` copy this directory to `.opencode/plugins/task-status/`; OpenCode
|
|
60
|
+
auto-loads every plugin under `.opencode/plugins/`, so no `opencode.json` `plugins`
|
|
61
|
+
entry is needed.
|
|
62
|
+
|
|
63
|
+
The files are managed by the install manifest: `ai-rules update` refreshes them and
|
|
64
|
+
`ai-rules clean opencode` removes unchanged copies. Do not edit the installed copy in
|
|
65
|
+
place; keep local changes in a separate plugin directory.
|
|
66
|
+
|
|
67
|
+
No build, no dependencies:
|
|
68
|
+
|
|
69
|
+
- `index.ts` — no-op server part. The TUI part loads with the plugin package; a TUI-only
|
|
70
|
+
package would belong in the global `cli.json` instead.
|
|
71
|
+
- `tui.tsx` — slot registration, rows, expand/collapse and the details dialog trigger.
|
|
72
|
+
- `task-view.ts` — session mapping, file polling, view model.
|
|
73
|
+
- `details.tsx`, `details-data.ts` — the row-click dialog and its file readers.
|
|
74
|
+
|
|
75
|
+
Do not import `solid-js` here. A local plugin resolves its own copy, and signals created by that copy are not tracked by the host renderer, so the UI renders once and never updates. Reactive state goes through `context.storage.memory`, refreshed once per second.
|
|
76
|
+
|
|
77
|
+
## Update
|
|
78
|
+
|
|
79
|
+
`ai-rules update` refreshes the installed copy. In a development checkout, edit the
|
|
80
|
+
preset source and re-run the installer, or copy the changed files into
|
|
81
|
+
`.opencode/plugins/task-status/`. The loader watches the server entrypoint (`index.ts`),
|
|
82
|
+
so an edit to `eta.ts`, `task-view.ts`, or `tui.tsx` needs `/reload` (or `opencode reload`)
|
|
83
|
+
to be picked up. The sidebar is session-scoped and follows `session.sidebar.toggle` (`ctrl+x b`).
|
|
84
|
+
|
|
85
|
+
## Limits
|
|
86
|
+
|
|
87
|
+
- The stop sentinel is repo-wide: it is the hook's operator pause, so it blocks new steps for every task, not only the one in the tab.
|
|
88
|
+
- Mapping relies on prompt text: a task without `prompt.md` and `prompt-log.md` cannot be matched, so its tab falls back to the prompt view.
|
|
89
|
+
- With a remote server, messages come from the server but the prompt files are read from the client filesystem.
|
|
90
|
+
- `status.json` timestamps are the only clock: a task paused for days shows total wall time plus a `stale` marker.
|
|
91
|
+
- A timestamp later than the host clock is ignored; a future `task_started` in agent-written metrics would otherwise freeze the elapsed value at `0s`.
|
|
92
|
+
- The ETA has no per-repository model: the medians are shared by every task under the team root, so a run that differs in size from the history is only as good as the step composition and the profile. It also needs finished attempts — a first run in a fresh repository shows no estimate.
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import fs from "node:fs"
|
|
2
|
+
import path from "node:path"
|
|
3
|
+
|
|
4
|
+
type Status = {
|
|
5
|
+
state?: string
|
|
6
|
+
phase?: string
|
|
7
|
+
pipelineIndex?: number
|
|
8
|
+
awaitingHumanGate?: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type Pipeline = {
|
|
12
|
+
steps?: { agent?: string; label?: string }[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type Manifest = {
|
|
16
|
+
artifacts?: { producer?: string; status?: string; receipt?: { outcome?: string } }[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type Details = {
|
|
20
|
+
slug: string
|
|
21
|
+
stateLine: string
|
|
22
|
+
goal?: string
|
|
23
|
+
prompt?: string
|
|
24
|
+
steps: { index: number; agent: string; marker: string }[]
|
|
25
|
+
artifacts: string[]
|
|
26
|
+
manifest: { producer: string; outcome: string }[]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const ARTIFACT_FILES = [
|
|
30
|
+
"goal.md",
|
|
31
|
+
"brief.md",
|
|
32
|
+
"decomposition.md",
|
|
33
|
+
"implementation.md",
|
|
34
|
+
"validation-report.md",
|
|
35
|
+
"review.md",
|
|
36
|
+
"outcome.md",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
const readJson = <T>(file: string): T | null => {
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(fs.readFileSync(file, "utf8")) as T
|
|
42
|
+
} catch {
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const section = (raw: string, heading: string, limit: number): string | undefined => {
|
|
48
|
+
const lines = raw.split("\n")
|
|
49
|
+
const start = lines.findIndex((line) => new RegExp(`^#+\\s*${heading}\\s*$`, "i").test(line.trim()))
|
|
50
|
+
if (start < 0) return undefined
|
|
51
|
+
const body: string[] = []
|
|
52
|
+
for (const line of lines.slice(start + 1)) {
|
|
53
|
+
if (/^#+\s/.test(line)) break
|
|
54
|
+
if (line.trim() !== "") body.push(line.trim())
|
|
55
|
+
}
|
|
56
|
+
if (body.length === 0) return undefined
|
|
57
|
+
const text = body.join(" ")
|
|
58
|
+
return text.length > limit ? `${text.slice(0, limit - 1)}…` : text
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const promptExcerpt = (raw: string): string | undefined => {
|
|
62
|
+
const body = raw.startsWith("---") ? raw.replace(/^---[\s\S]*?\n---\s*/, "") : raw
|
|
63
|
+
const lines = body.split("\n")
|
|
64
|
+
const start = lines.findIndex((line) => /^#+\s*Verbatim prompt\s*$/i.test(line.trim()))
|
|
65
|
+
const slice = start >= 0 ? lines.slice(start + 1) : lines
|
|
66
|
+
const kept: string[] = []
|
|
67
|
+
for (const line of slice) {
|
|
68
|
+
if (/^#+\s/.test(line)) {
|
|
69
|
+
if (start >= 0) break
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
const trimmed = line.trim()
|
|
73
|
+
if (
|
|
74
|
+
trimmed === "" ||
|
|
75
|
+
trimmed.startsWith("```") ||
|
|
76
|
+
/^(language|slug|created|source|command|capturedAt):/i.test(trimmed)
|
|
77
|
+
) {
|
|
78
|
+
continue
|
|
79
|
+
}
|
|
80
|
+
kept.push(trimmed)
|
|
81
|
+
}
|
|
82
|
+
if (kept.length === 0) return undefined
|
|
83
|
+
const text = kept.join(" ")
|
|
84
|
+
return text.length > 200 ? `${text.slice(0, 199)}…` : text
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const buildDetails = (root: string, slug: string): Details => {
|
|
88
|
+
const taskDir = path.join(root, "tasks", slug)
|
|
89
|
+
const status = readJson<Status>(path.join(taskDir, "status.json"))
|
|
90
|
+
const pipeline = readJson<Pipeline>(path.join(taskDir, "pipeline.json"))
|
|
91
|
+
const manifest = readJson<Manifest>(path.join(taskDir, "artifact-manifest.json"))
|
|
92
|
+
|
|
93
|
+
let goal: string | undefined
|
|
94
|
+
try {
|
|
95
|
+
goal = section(fs.readFileSync(path.join(taskDir, "goal.md"), "utf8"), "Goal", 300)
|
|
96
|
+
} catch {
|
|
97
|
+
// goal.md is optional
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let prompt: string | undefined
|
|
101
|
+
try {
|
|
102
|
+
prompt = promptExcerpt(fs.readFileSync(path.join(taskDir, "prompt.md"), "utf8"))
|
|
103
|
+
} catch {
|
|
104
|
+
// prompt.md is optional
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const current = status?.pipelineIndex ?? 0
|
|
108
|
+
const finished = status?.state === "completed" || status?.phase === "done"
|
|
109
|
+
const steps = (pipeline?.steps ?? []).map((step, position) => {
|
|
110
|
+
const marker = finished ? "✓" : position < current ? "✓" : position === current ? "●" : "·"
|
|
111
|
+
return { index: position + 1, agent: step.agent ?? "?", marker }
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const artifacts = ARTIFACT_FILES.filter((file) => fs.existsSync(path.join(taskDir, file)))
|
|
115
|
+
|
|
116
|
+
const manifestRows = (manifest?.artifacts ?? []).slice(-4).map((entry) => ({
|
|
117
|
+
producer: entry.producer ?? "?",
|
|
118
|
+
outcome: entry.receipt?.outcome ?? entry.status ?? "?",
|
|
119
|
+
}))
|
|
120
|
+
|
|
121
|
+
const stateLine = [
|
|
122
|
+
status?.state ?? (status ? "no state" : "no status"),
|
|
123
|
+
steps.length > 0 && status ? `step ${Math.min(current + 1, steps.length)}/${steps.length}` : null,
|
|
124
|
+
status?.awaitingHumanGate ? "gate" : null,
|
|
125
|
+
]
|
|
126
|
+
.filter(Boolean)
|
|
127
|
+
.join(" · ")
|
|
128
|
+
|
|
129
|
+
return { slug, stateLine, goal, prompt, steps, artifacts, manifest: manifestRows }
|
|
130
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { usePlugin } from "@opencode/plugin/tui"
|
|
2
|
+
import { buildDetails } from "./details-data"
|
|
3
|
+
|
|
4
|
+
type Scroll = {
|
|
5
|
+
scrollBy: (value: number) => void
|
|
6
|
+
scrollTo: (value: number) => void
|
|
7
|
+
scrollHeight: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const DetailsRow = (props: { label: string; value: string; base: string; muted: string }) => (
|
|
11
|
+
<box flexDirection="column">
|
|
12
|
+
<text fg={props.base}>
|
|
13
|
+
<b>{props.label}</b>
|
|
14
|
+
</text>
|
|
15
|
+
<text fg={props.muted} wrapMode="word">
|
|
16
|
+
{props.value}
|
|
17
|
+
</text>
|
|
18
|
+
</box>
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
export const TaskDetails = (props: { slug: string; root: string; base: string; muted: string }) => {
|
|
22
|
+
const context = usePlugin()
|
|
23
|
+
const data = buildDetails(props.root, props.slug)
|
|
24
|
+
let scroll: Scroll | undefined
|
|
25
|
+
|
|
26
|
+
context.keymap.layer(() => ({
|
|
27
|
+
mode: "modal",
|
|
28
|
+
commands: [
|
|
29
|
+
{ bind: "up", run: () => scroll?.scrollBy(-1) },
|
|
30
|
+
{ bind: "down", run: () => scroll?.scrollBy(1) },
|
|
31
|
+
{ bind: "pageup", run: () => scroll?.scrollBy(-20) },
|
|
32
|
+
{ bind: "pagedown", run: () => scroll?.scrollBy(20) },
|
|
33
|
+
{ bind: "home", run: () => scroll?.scrollTo(0) },
|
|
34
|
+
{ bind: "end", run: () => scroll && scroll.scrollTo(scroll.scrollHeight) },
|
|
35
|
+
],
|
|
36
|
+
}))
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<box flexDirection="column" paddingLeft={3} paddingRight={3} paddingBottom={1} gap={1}>
|
|
40
|
+
<text fg={props.base}>
|
|
41
|
+
<b>{data.slug}</b>
|
|
42
|
+
</text>
|
|
43
|
+
<text fg={props.muted}>{data.stateLine}</text>
|
|
44
|
+
<scrollbox
|
|
45
|
+
ref={(element: Scroll) => (scroll = element)}
|
|
46
|
+
maxHeight={20}
|
|
47
|
+
focused
|
|
48
|
+
contentOptions={{ minHeight: 0 }}
|
|
49
|
+
scrollbarOptions={{ visible: false }}
|
|
50
|
+
>
|
|
51
|
+
<box flexDirection="column" gap={1}>
|
|
52
|
+
{data.goal ? <DetailsRow label="Goal" value={data.goal} base={props.base} muted={props.muted} /> : null}
|
|
53
|
+
{data.steps.length > 0 ? (
|
|
54
|
+
<box flexDirection="column">
|
|
55
|
+
<text fg={props.base}>
|
|
56
|
+
<b>Steps</b>
|
|
57
|
+
</text>
|
|
58
|
+
{data.steps.map((step) => (
|
|
59
|
+
<text fg={props.muted}>{`${step.marker} ${step.index}. ${step.agent}`}</text>
|
|
60
|
+
))}
|
|
61
|
+
</box>
|
|
62
|
+
) : null}
|
|
63
|
+
{data.artifacts.length > 0 ? (
|
|
64
|
+
<DetailsRow label="Artifacts" value={data.artifacts.join(" ")} base={props.base} muted={props.muted} />
|
|
65
|
+
) : null}
|
|
66
|
+
{data.manifest.length > 0 ? (
|
|
67
|
+
<box flexDirection="column">
|
|
68
|
+
<text fg={props.base}>
|
|
69
|
+
<b>Manifest</b>
|
|
70
|
+
</text>
|
|
71
|
+
{data.manifest.map((row) => (
|
|
72
|
+
<text fg={props.muted}>{`${row.producer} · ${row.outcome}`}</text>
|
|
73
|
+
))}
|
|
74
|
+
</box>
|
|
75
|
+
) : null}
|
|
76
|
+
{data.prompt ? (
|
|
77
|
+
<DetailsRow label="Prompt" value={data.prompt} base={props.base} muted={props.muted} />
|
|
78
|
+
) : null}
|
|
79
|
+
</box>
|
|
80
|
+
</scrollbox>
|
|
81
|
+
<text fg={props.muted}>↑/↓ scroll · esc close</text>
|
|
82
|
+
</box>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import fs from "node:fs"
|
|
2
|
+
import path from "node:path"
|
|
3
|
+
|
|
4
|
+
export type EtaStat = {
|
|
5
|
+
medianMs: number
|
|
6
|
+
p90Ms: number
|
|
7
|
+
attempts: number
|
|
8
|
+
perStep: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type EtaStats = {
|
|
12
|
+
byAgent: Map<string, EtaStat>
|
|
13
|
+
fallback: EtaStat
|
|
14
|
+
tasks: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type EtaStep = {
|
|
18
|
+
agent?: string | string[]
|
|
19
|
+
parallel?: boolean
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type EtaStatus = {
|
|
23
|
+
pipelineIndex?: number
|
|
24
|
+
activeAttempts?: Record<string, { agent?: string; stepIndex?: number; startedAt?: string }>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type EtaView = {
|
|
28
|
+
p50Ms: number
|
|
29
|
+
p90Ms: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type MetricEvent = {
|
|
33
|
+
type?: string
|
|
34
|
+
attemptId?: string
|
|
35
|
+
durationMs?: number
|
|
36
|
+
agent?: string
|
|
37
|
+
stepIndex?: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type Reader = <T>(file: string) => T | null
|
|
41
|
+
|
|
42
|
+
const MIN_SAMPLE = 3
|
|
43
|
+
const MIN_STEP_SHARE = 0.15
|
|
44
|
+
const MAX_RETRY = 1.5
|
|
45
|
+
// Per-step medians come from right-skewed samples; adding them overestimates the
|
|
46
|
+
// median of the total. 0.65 is calibrated on the ledger history (66 tasks): it puts
|
|
47
|
+
// the median prediction at ~1.1x actual and keeps ~half of tasks below the p50.
|
|
48
|
+
const BIAS = 0.65
|
|
49
|
+
|
|
50
|
+
const percentile = (sorted: number[], value: number): number => {
|
|
51
|
+
if (sorted.length === 0) return 0
|
|
52
|
+
const index = (sorted.length - 1) * value
|
|
53
|
+
const low = Math.floor(index)
|
|
54
|
+
const high = Math.ceil(index)
|
|
55
|
+
return sorted[low] + (sorted[high] - sorted[low]) * (index - low)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const parseAttempt = (attemptId: string | undefined): { agent?: string; step?: number } => {
|
|
59
|
+
if (!attemptId) return {}
|
|
60
|
+
const parts = attemptId.split(":")
|
|
61
|
+
const attemptAt = parts.findIndex((part) => part.startsWith("attempt-"))
|
|
62
|
+
const step = /(?:^|:)step-(\d+)(?::|$)/.exec(attemptId)
|
|
63
|
+
return {
|
|
64
|
+
agent: attemptAt > 0 ? parts[attemptAt - 1] : undefined,
|
|
65
|
+
step: step ? Number(step[1]) : undefined,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const makeStat = (durations: number[], steps: number): EtaStat => {
|
|
70
|
+
const sorted = [...durations].sort((left, right) => left - right)
|
|
71
|
+
const attempts = sorted.length
|
|
72
|
+
const perStep = steps > 0 ? Math.min(MAX_RETRY, Math.max(1, attempts / steps)) : 1
|
|
73
|
+
return {
|
|
74
|
+
medianMs: percentile(sorted, 0.5),
|
|
75
|
+
p90Ms: percentile(sorted, 0.9),
|
|
76
|
+
attempts,
|
|
77
|
+
perStep,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Median and p90 attempt duration per agent, from every `metrics.json` under
|
|
83
|
+
* `<team root>/tasks`. Reads through the caller's mtime cache, so unchanged
|
|
84
|
+
* ledgers are not re-parsed.
|
|
85
|
+
*/
|
|
86
|
+
export const createEtaStats = (root: string, readJson: Reader): EtaStats => {
|
|
87
|
+
const durations = new Map<string, number[]>()
|
|
88
|
+
const stepKeys = new Map<string, Set<string>>()
|
|
89
|
+
const all: number[] = []
|
|
90
|
+
let tasks = 0
|
|
91
|
+
|
|
92
|
+
let entries: fs.Dirent[]
|
|
93
|
+
try {
|
|
94
|
+
entries = fs.readdirSync(path.join(root, "tasks"), { withFileTypes: true })
|
|
95
|
+
} catch {
|
|
96
|
+
entries = []
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for (const entry of entries) {
|
|
100
|
+
if (!entry.isDirectory()) continue
|
|
101
|
+
const events = readJson<{ events?: MetricEvent[] }>(
|
|
102
|
+
path.join(root, "tasks", entry.name, "metrics.json"),
|
|
103
|
+
)?.events
|
|
104
|
+
if (!events || events.length === 0) continue
|
|
105
|
+
tasks += 1
|
|
106
|
+
|
|
107
|
+
const started = new Map<string, { agent?: string; step?: number }>()
|
|
108
|
+
for (const event of events) {
|
|
109
|
+
if (event.type === "attempt_started" && event.attemptId) {
|
|
110
|
+
started.set(event.attemptId, { agent: event.agent, step: event.stepIndex })
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (const event of events) {
|
|
115
|
+
if (event.type !== "attempt_finished" || event.durationMs === undefined) continue
|
|
116
|
+
const parsed = parseAttempt(event.attemptId)
|
|
117
|
+
const ref = (event.attemptId && started.get(event.attemptId)) ?? parsed
|
|
118
|
+
const agent = ref.agent ?? event.agent ?? "unknown"
|
|
119
|
+
const step = ref.step ?? parsed.step
|
|
120
|
+
if (!durations.has(agent)) durations.set(agent, [])
|
|
121
|
+
durations.get(agent)!.push(event.durationMs)
|
|
122
|
+
all.push(event.durationMs)
|
|
123
|
+
if (!stepKeys.has(agent)) stepKeys.set(agent, new Set())
|
|
124
|
+
stepKeys.get(agent)!.add(`${entry.name}:${step ?? event.attemptId}`)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const byAgent = new Map<string, EtaStat>()
|
|
129
|
+
for (const [agent, list] of durations) {
|
|
130
|
+
byAgent.set(agent, makeStat(list, stepKeys.get(agent)?.size ?? list.length))
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
byAgent,
|
|
135
|
+
fallback: makeStat(all, all.length),
|
|
136
|
+
tasks,
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const agentStat = (stats: EtaStats, agent: string | undefined): EtaStat =>
|
|
141
|
+
(agent ? stats.byAgent.get(agent) : undefined) ?? stats.fallback
|
|
142
|
+
|
|
143
|
+
const stepEstimate = (step: EtaStep, stats: EtaStats): { p50: number; p90: number } => {
|
|
144
|
+
const agents = Array.isArray(step.agent) ? step.agent : step.agent ? [step.agent] : []
|
|
145
|
+
if (agents.length === 0) return { p50: stats.fallback.medianMs, p90: stats.fallback.p90Ms }
|
|
146
|
+
const timed = agents.map((agent) => {
|
|
147
|
+
const stat = agentStat(stats, agent)
|
|
148
|
+
return { p50: stat.medianMs * stat.perStep, p90: stat.p90Ms }
|
|
149
|
+
})
|
|
150
|
+
if (step.parallel || agents.length > 1) {
|
|
151
|
+
return {
|
|
152
|
+
p50: Math.max(...timed.map((item) => item.p50)),
|
|
153
|
+
p90: Math.max(...timed.map((item) => item.p90)),
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return timed[0]
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const stepSpent = (
|
|
160
|
+
step: number,
|
|
161
|
+
running: { agent?: string; startedAt?: number }[],
|
|
162
|
+
events: MetricEvent[],
|
|
163
|
+
now: number,
|
|
164
|
+
): number => {
|
|
165
|
+
const agents = new Set(running.map((attempt) => attempt.agent).filter(Boolean))
|
|
166
|
+
let spent = 0
|
|
167
|
+
for (const event of events) {
|
|
168
|
+
if (event.type !== "attempt_finished" || event.durationMs === undefined) continue
|
|
169
|
+
const parsed = parseAttempt(event.attemptId)
|
|
170
|
+
if (parsed.step !== step) continue
|
|
171
|
+
if (agents.size > 0 && parsed.agent && !agents.has(parsed.agent)) continue
|
|
172
|
+
spent += event.durationMs
|
|
173
|
+
}
|
|
174
|
+
for (const attempt of running) {
|
|
175
|
+
if (attempt.startedAt === undefined) continue
|
|
176
|
+
spent += Math.max(0, now - attempt.startedAt)
|
|
177
|
+
}
|
|
178
|
+
return spent
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export const estimateEta = (
|
|
182
|
+
steps: EtaStep[],
|
|
183
|
+
status: EtaStatus,
|
|
184
|
+
events: MetricEvent[],
|
|
185
|
+
stats: EtaStats,
|
|
186
|
+
now: number,
|
|
187
|
+
): EtaView | null => {
|
|
188
|
+
if (steps.length === 0 || stats.tasks < MIN_SAMPLE) return null
|
|
189
|
+
|
|
190
|
+
const active = Object.entries(status.activeAttempts ?? {})
|
|
191
|
+
.map(([id, attempt]) => ({ id, ...attempt }))
|
|
192
|
+
.filter((attempt) => attempt.stepIndex !== undefined)
|
|
193
|
+
.sort((left, right) => (left.stepIndex ?? 0) - (right.stepIndex ?? 0))
|
|
194
|
+
|
|
195
|
+
const currentIndex = active.length > 0 ? active[0].stepIndex : status.pipelineIndex
|
|
196
|
+
const first = currentIndex === undefined ? 0 : Math.min(currentIndex, steps.length - 1)
|
|
197
|
+
|
|
198
|
+
const inFlight = new Map<number, { agent?: string; startedAt?: number }[]>()
|
|
199
|
+
for (const attempt of active) {
|
|
200
|
+
const index = attempt.stepIndex ?? 0
|
|
201
|
+
if (!inFlight.has(index)) inFlight.set(index, [])
|
|
202
|
+
inFlight.get(index)!.push({
|
|
203
|
+
agent: attempt.agent,
|
|
204
|
+
startedAt: attempt.startedAt === undefined ? undefined : Date.parse(attempt.startedAt),
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
let p50 = 0
|
|
209
|
+
let variance = 0
|
|
210
|
+
const add = (estimate: { p50: number; p90: number }, spent: number, started: boolean) => {
|
|
211
|
+
const expected = estimate.p50 * BIAS
|
|
212
|
+
const remP50 = started ? Math.max(expected - spent, expected * MIN_STEP_SHARE) : expected
|
|
213
|
+
const remP90 = started
|
|
214
|
+
? Math.max(estimate.p90 - spent, remP50, estimate.p90 * MIN_STEP_SHARE)
|
|
215
|
+
: estimate.p90
|
|
216
|
+
p50 += remP50
|
|
217
|
+
variance += remP90 * remP90
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
for (let index = first; index < steps.length; index += 1) {
|
|
221
|
+
const estimate = stepEstimate(steps[index], stats)
|
|
222
|
+
const running = inFlight.get(index) ?? []
|
|
223
|
+
const spent = stepSpent(index, running, events, now)
|
|
224
|
+
add(estimate, spent, spent > 0)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (p50 <= 0) return null
|
|
228
|
+
const p90 = Math.max(p50 * 4, Math.sqrt(variance) * 1.5)
|
|
229
|
+
return { p50Ms: p50, p90Ms: p90 }
|
|
230
|
+
}
|