@bonesofspring/ai-rules 0.2.71 → 0.2.72
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 +24 -0
- package/bin/lib/engine-scripts.js +9 -0
- package/docs/OPENCODE.md +4 -2
- package/docs/TEAM-DB.md +10 -7
- package/package.json +1 -1
- package/presets/_shared/ai-local/scripts/aggregate-agent-task-metrics.mjs +201 -0
- package/presets/_shared/ai-local/scripts/incidents.mjs +452 -0
- package/presets/_shared/ai-local/scripts/record-usage.mjs +163 -0
- package/presets/_shared/ai-local/scripts/team-db-project.mjs +2 -0
- package/presets/_shared/ai-local/scripts/verification.mjs +374 -0
- package/presets/_shared/core/agent-team/agent-task-metrics.md +61 -1
- package/presets/_shared/core/agent-team/agent-team-orchestrator.md +5 -4
- package/presets/_shared/core/agent-team/incident-registry.md +47 -0
- package/presets/_shared/core/architecture/feature-delivery-workflow.md +1 -1
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +108 -1
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/go/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/go/rules/architecture/feature-delivery.md +1 -1
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/ios-swift/rules/architecture/feature-delivery.md +1 -1
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/java/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/java/rules/architecture/feature-delivery.md +1 -1
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/mcp-ts/rules/architecture/feature-delivery.md +1 -1
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/mol/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/mol/rules/architecture/feature-delivery-workflow.md +1 -1
- package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/next/agents/README.md +4 -3
- package/presets/claude/next/agents/api-contract-reviewer.md +1 -1
- package/presets/claude/next/agents/mockup-reviewer.md +1 -1
- package/presets/claude/next/agents/task-router.md +4 -4
- package/presets/claude/next/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/next/rules/architecture/feature-delivery-workflow.md +2 -2
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/nuxt/rules/architecture/feature-delivery-workflow.md +1 -1
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/php-hexagonal/rules/architecture/feature-delivery.md +1 -1
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/php-laravel/rules/architecture/feature-delivery.md +1 -1
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/svelte/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/svelte/rules/architecture/feature-delivery-workflow.md +1 -1
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/go/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/go/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/java/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/java/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/mol/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/next/agents/README.md +4 -3
- package/presets/cursor/next/agents/api-contract-reviewer.md +1 -1
- package/presets/cursor/next/agents/mockup-reviewer.md +1 -1
- package/presets/cursor/next/agents/task-router.md +4 -4
- package/presets/cursor/next/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/next/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/next/rules/feature-delivery-workflow.mdc +1 -1
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +108 -1
- 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/README.md +3 -3
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/agents/README.md +2 -2
- package/presets/mavis/go/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/go/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/go/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/agents/README.md +3 -3
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/ios-swift/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/agents/README.md +2 -2
- package/presets/mavis/java/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/java/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/java/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/agents/README.md +1 -1
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/mcp-ts/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/mol/adapter-map.json +1 -1
- package/presets/mavis/mol/agents/README.md +3 -3
- package/presets/mavis/mol/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/mol/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/mol/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/next/adapter-map.json +1 -1
- package/presets/mavis/next/agents/README.md +3 -3
- package/presets/mavis/next/agents/task-router.md +4 -4
- package/presets/mavis/next/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/next/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/next/rules/feature-delivery-workflow.md +2 -2
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/agents/README.md +3 -3
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/nuxt/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/agents/README.md +2 -2
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/php-hexagonal/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/agents/README.md +2 -2
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/php-laravel/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/agents/README.md +3 -3
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/svelte/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/svelte/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/agents/README.md +4 -4
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/agents/README.md +3 -3
- package/presets/opencode/go/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/go/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/go/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/agents/README.md +4 -4
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/ios-swift/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/agents/README.md +3 -3
- package/presets/opencode/java/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/java/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/java/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/agents/README.md +2 -2
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/mcp-ts/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/mol/adapter-map.json +1 -1
- package/presets/opencode/mol/agents/README.md +4 -4
- package/presets/opencode/mol/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/mol/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/mol/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/next/adapter-map.json +1 -1
- package/presets/opencode/next/agents/README.md +4 -4
- package/presets/opencode/next/agents/task-router.md +4 -4
- package/presets/opencode/next/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/next/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/next/rules/feature-delivery-workflow.md +2 -2
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/agents/README.md +4 -4
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/nuxt/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/agents/README.md +3 -3
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/php-hexagonal/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/agents/README.md +3 -3
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/php-laravel/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/plugins/output-guard/README.md +17 -4
- package/presets/opencode/plugins/output-guard/index.ts +27 -9
- package/presets/opencode/plugins/output-guard/rewrite.ts +104 -1
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/agents/README.md +4 -4
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/svelte/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/svelte/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/android-kotlin/adapter-map.json +1 -1
- package/presets/zcode/android-kotlin/agents/README.md +3 -3
- package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/go/adapter-map.json +1 -1
- package/presets/zcode/go/agents/README.md +2 -2
- package/presets/zcode/go/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/go/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/go/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/ios-swift/adapter-map.json +1 -1
- package/presets/zcode/ios-swift/agents/README.md +3 -3
- package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/ios-swift/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/java/adapter-map.json +1 -1
- package/presets/zcode/java/agents/README.md +2 -2
- package/presets/zcode/java/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/java/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/java/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/mcp-ts/adapter-map.json +1 -1
- package/presets/zcode/mcp-ts/agents/README.md +1 -1
- package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/mcp-ts/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/mol/adapter-map.json +1 -1
- package/presets/zcode/mol/agents/README.md +3 -3
- package/presets/zcode/mol/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/mol/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/mol/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/next/adapter-map.json +1 -1
- package/presets/zcode/next/agents/README.md +3 -3
- package/presets/zcode/next/agents/task-router.md +4 -4
- package/presets/zcode/next/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/next/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/next/rules/feature-delivery-workflow.md +2 -2
- package/presets/zcode/nuxt/adapter-map.json +1 -1
- package/presets/zcode/nuxt/agents/README.md +3 -3
- package/presets/zcode/nuxt/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/nuxt/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
- package/presets/zcode/php-hexagonal/agents/README.md +2 -2
- package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/php-hexagonal/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/php-laravel/adapter-map.json +1 -1
- package/presets/zcode/php-laravel/agents/README.md +2 -2
- package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/php-laravel/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/svelte/adapter-map.json +1 -1
- package/presets/zcode/svelte/agents/README.md +3 -3
- package/presets/zcode/svelte/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/svelte/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/svelte/rules/feature-delivery-workflow.md +1 -1
- package/scripts/aggregate-agent-task-metrics.mjs +201 -0
- package/scripts/report-context-cost.mjs +126 -0
|
@@ -16,7 +16,7 @@ Typical feature with data and UI. Concrete directories and rule stems — in the
|
|
|
16
16
|
|
|
17
17
|
## Context hygiene
|
|
18
18
|
|
|
19
|
-
A command whose output can exceed ~4 KB — a test run, a build/lint log, `git log`, a diff — is piped through `.ai.local/scripts/dump-output.mjs --task <slug>` instead of being read whole. Work from its ≤40-line head and the stored file (grep it or use `team-db.mjs search`), and when that output informed a decision, record the repo-relative `outputs/…` path in `implementation.md` or `validation-report.md`; a `code-reviewer` may ask for that path. Do not read the whole output into context.
|
|
19
|
+
A command whose output can exceed ~4 KB — a test run, a build/lint log, `git log`, a diff — is piped through `.ai.local/scripts/dump-output.mjs --task <slug>` instead of being read whole. Work from its ≤40-line head and the stored file (grep it or use `team-db.mjs search`), and when that output informed a decision, record the repo-relative `outputs/…` path in `implementation.md` or `validation-report.md`; a `code-reviewer` may ask for that path. Do not read the whole output into context. Artifact reads take the same slice: read the `artifact-manifest.json` entry, not the artifact body, and never re-read a completed entry's body. Read a large artifact with offset/limit ranges instead of a whole-file read.
|
|
20
20
|
|
|
21
21
|
## Iterative refinement loop
|
|
22
22
|
|
|
@@ -13,7 +13,9 @@ outgoing model call; persisted history is untouched.
|
|
|
13
13
|
|---|---|
|
|
14
14
|
| Trigger | `tool-result` text over **8192 B** (`AI_RULES_OUTPUT_GUARD_BYTES`) |
|
|
15
15
|
| Tools | `shell`, `bash`, `read`, `grep`, `glob`, `webfetch` |
|
|
16
|
-
| Replacement
|
|
16
|
+
| Replacement (8–20 KB band) | structured head + tail: named elision, top-level JSON keys that sit in the gap, a `sed -n 'A,Bp'` hint for a whole-line gap, or `tail -c` when a line is cut mid-way |
|
|
17
|
+
| Replacement (over 20 KB) | 40-line / 2 KB head + 15-line / 1 KB tail + path + hints |
|
|
18
|
+
| Shape override | `AI_RULES_OUTPUT_GUARD_SHAPE=flat` forces the legacy renderer in the band |
|
|
17
19
|
| Saved file | `.ai.local/team/output-guard/<sessionID>/outputs/<callID>-<tool>.txt`, 2 MiB cap |
|
|
18
20
|
| Stats | `.ai.local/team/output-guard/stats.jsonl` (one row per replacement) |
|
|
19
21
|
| Ledgers | `results.jsonl`, `usage.jsonl`, `context.jsonl` — see [Ledgers](#ledgers) |
|
|
@@ -22,8 +24,12 @@ outgoing model call; persisted history is untouched.
|
|
|
22
24
|
| Host | OpenCode V2 with `ctx.session.hook`; a host without it no-ops |
|
|
23
25
|
|
|
24
26
|
The replacement keeps the first and last lines because a test log often carries
|
|
25
|
-
the failure at the end.
|
|
26
|
-
|
|
27
|
+
the failure at the end. Results in the 8–20 KB band get the structured shape.
|
|
28
|
+
A whole-line gap is a `sed -n` range. A head or tail cut mid-line, including a
|
|
29
|
+
one-line payload, is a `tail -c` byte window: a line range would skip the rest
|
|
30
|
+
of the cut line. JSON keys are listed only when they sit in that gap. Larger
|
|
31
|
+
results keep the flat head+tail with a `[json: full document at the path]` note
|
|
32
|
+
so the agent can `jq` the file.
|
|
27
33
|
|
|
28
34
|
## Ledgers
|
|
29
35
|
|
|
@@ -33,7 +39,7 @@ and `usage.jsonl` rotate.
|
|
|
33
39
|
| File | Row | Written when |
|
|
34
40
|
|---|---|---|
|
|
35
41
|
| `stats.jsonl` | `sessionID`, `callID`, `tool`, `beforeBytes`, `afterBytes`, `path` | a result is replaced |
|
|
36
|
-
| `results.jsonl` | `sessionID`, `callID`, `tool`, `command`, `rawBytes`, `returnedBytes`, `replaced`, `path` | a tool result is seen |
|
|
42
|
+
| `results.jsonl` | `sessionID`, `callID`, `tool`, `command`, `rawBytes`, `returnedBytes`, `replaced`, `path`, `error?` | a tool result is seen |
|
|
37
43
|
| `usage.jsonl` | `sessionID`, `messageID`, `agent`, `model`, `input`, `output`, `reasoning`, `cacheRead`, `cacheWrite`, `cost`, `finish` | a message carries token counts |
|
|
38
44
|
| `context.jsonl` | `sessionID`, `toolset`, `tools`, `toolSchemaBytes`, `systemBytes`, `byTool[]`, `mcpServers[]` | a session's toolset changes |
|
|
39
45
|
|
|
@@ -65,6 +71,13 @@ for configured MCP servers whose name prefixes at least one tool
|
|
|
65
71
|
reader never mistakes a failed call for a measured zero. A session with no
|
|
66
72
|
tools writes no row.
|
|
67
73
|
|
|
74
|
+
A `results.jsonl` row records a text or error tool result (`command` is the
|
|
75
|
+
read target the host's `commandOf` slice found). An errored result adds
|
|
76
|
+
`error: true`; a non-error row, and every row written before the field
|
|
77
|
+
existed, has no such key — absence means non-error. The report reads the rows
|
|
78
|
+
back as `readCountPerPath` (per-path `read`-tool calls) and `mcpErrors`
|
|
79
|
+
(errored results on `<server>_<tool>` names).
|
|
80
|
+
|
|
68
81
|
## Why a hook, not a rule
|
|
69
82
|
|
|
70
83
|
A prose line asks the agent to pipe output; context-mode measured that path at
|
|
@@ -225,7 +225,7 @@ const commandOf = (input: unknown): string => {
|
|
|
225
225
|
*/
|
|
226
226
|
const collectToolActivity = (messages: unknown) => {
|
|
227
227
|
const calls = new Map<string, { tool: string; command: string }>()
|
|
228
|
-
const results: Array<{ id: string; tool: string; rawBytes: number }> = []
|
|
228
|
+
const results: Array<{ id: string; tool: string; rawBytes: number; error: boolean }> = []
|
|
229
229
|
if (!Array.isArray(messages)) return { calls, results }
|
|
230
230
|
for (const message of messages as Array<{ content?: unknown }>) {
|
|
231
231
|
const content = message?.content
|
|
@@ -240,15 +240,30 @@ const collectToolActivity = (messages: unknown) => {
|
|
|
240
240
|
if (
|
|
241
241
|
item?.type === "tool-result" &&
|
|
242
242
|
typeof item.id === "string" &&
|
|
243
|
-
item.result?.type === "text"
|
|
244
|
-
typeof item.result.value === "string"
|
|
243
|
+
(item.result?.type === "text" || item.result?.type === "error")
|
|
245
244
|
) {
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
245
|
+
const isError = item.result.type === "error"
|
|
246
|
+
// A text result keeps its string guard. An error value may be any JSON
|
|
247
|
+
// the host serialized. Stringify stays local: a BigInt or a cycle must
|
|
248
|
+
// skip this row, not abort the rewrite of the other results.
|
|
249
|
+
let text = ""
|
|
250
|
+
if (typeof item.result.value === "string") text = item.result.value
|
|
251
|
+
else if (isError) {
|
|
252
|
+
try {
|
|
253
|
+
text = JSON.stringify(item.result.value) ?? ""
|
|
254
|
+
} catch {
|
|
255
|
+
text = ""
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (text !== "") {
|
|
259
|
+
const call = calls.get(item.id)
|
|
260
|
+
results.push({
|
|
261
|
+
id: item.id,
|
|
262
|
+
tool: call?.tool ?? (typeof item.name === "string" ? item.name : ""),
|
|
263
|
+
rawBytes: Buffer.byteLength(text, "utf8"),
|
|
264
|
+
error: isError,
|
|
265
|
+
})
|
|
266
|
+
}
|
|
252
267
|
}
|
|
253
268
|
}
|
|
254
269
|
}
|
|
@@ -272,6 +287,7 @@ export default Plugin.define({
|
|
|
272
287
|
tailLines: TAIL_LINES,
|
|
273
288
|
allowlist: ALLOWLIST,
|
|
274
289
|
marker: MARKER,
|
|
290
|
+
shape: process.env.AI_RULES_OUTPUT_GUARD_SHAPE === "flat" ? ("flat" as const) : ("structured" as const),
|
|
275
291
|
}
|
|
276
292
|
const outputDir = process.env.AI_RULES_OUTPUT_GUARD_DIR
|
|
277
293
|
? path.resolve(process.env.AI_RULES_OUTPUT_GUARD_DIR)
|
|
@@ -522,6 +538,8 @@ export default Plugin.define({
|
|
|
522
538
|
returnedBytes: changed ? changed.afterBytes : item.rawBytes,
|
|
523
539
|
replaced: changed !== undefined,
|
|
524
540
|
path: changed?.path ?? "",
|
|
541
|
+
// Absence means non-error; only the host's error variant carries the key.
|
|
542
|
+
...(item.error ? { error: true } : {}),
|
|
525
543
|
})
|
|
526
544
|
}
|
|
527
545
|
// Detached after the rewrite: the tool result must never depend on
|
|
@@ -12,6 +12,8 @@ export type OutputGuardOptions = {
|
|
|
12
12
|
tailLines: number
|
|
13
13
|
allowlist: ReadonlySet<string>
|
|
14
14
|
marker: string
|
|
15
|
+
/** `"flat"` forces the legacy renderer inside the band; default is structured. */
|
|
16
|
+
shape?: "flat" | "structured"
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export type SaveOutputInput = { tool: string; id: string; text: string }
|
|
@@ -77,6 +79,104 @@ const searchTerm = (head: string, fallback: string): string => {
|
|
|
77
79
|
|
|
78
80
|
const looksJson = (value: string): boolean => /^[\s]*[{[]/.test(value)
|
|
79
81
|
|
|
82
|
+
export const BAND_MAX_BYTES = 20 * 1024
|
|
83
|
+
|
|
84
|
+
const BAND_LABEL = "structured head+tail (8-20 KB band)"
|
|
85
|
+
|
|
86
|
+
/** Top-level keys of a parseable JSON object; `[]` for anything else. */
|
|
87
|
+
const topLevelJsonKeys = (value: string): string[] => {
|
|
88
|
+
let parsed: unknown
|
|
89
|
+
try {
|
|
90
|
+
parsed = JSON.parse(value)
|
|
91
|
+
} catch {
|
|
92
|
+
return []
|
|
93
|
+
}
|
|
94
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return []
|
|
95
|
+
return Object.keys(parsed)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Smallest-indent match, so a nested key of the same name does not win. */
|
|
99
|
+
const lineOfKey = (lines: string[], key: string): number => {
|
|
100
|
+
const escaped = key.replace(/[\\^$.*+?()[\]{}|"]/g, "\\$&")
|
|
101
|
+
const pattern = new RegExp(`^(\\s*)"${escaped}"\\s*:`)
|
|
102
|
+
let bestLine = 0
|
|
103
|
+
let bestIndent = Number.POSITIVE_INFINITY
|
|
104
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
105
|
+
const match = pattern.exec(lines[index] ?? "")
|
|
106
|
+
if (!match || match[1] === undefined) continue
|
|
107
|
+
const indent = match[1].length
|
|
108
|
+
if (indent < bestIndent) {
|
|
109
|
+
bestIndent = indent
|
|
110
|
+
bestLine = index + 1
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return bestLine
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const joinedSlice = (lines: string[], start: number, count: number): string =>
|
|
117
|
+
lines.slice(start, start + count).join("\n")
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The 8–20 KB band names the gap. A whole-line gap keeps a `sed -n` range.
|
|
121
|
+
* A head or tail cut mid-line (or a one-line payload) names a byte window:
|
|
122
|
+
* a line range would skip the rest of the cut line, and `sed` past EOF is empty.
|
|
123
|
+
* JSON keys are listed only when they sit in that gap.
|
|
124
|
+
*/
|
|
125
|
+
export const renderStructured = (
|
|
126
|
+
value: string,
|
|
127
|
+
file: string,
|
|
128
|
+
options: OutputGuardOptions,
|
|
129
|
+
): string => {
|
|
130
|
+
const head = takeHead(value, options.headBytes, options.headLines)
|
|
131
|
+
const tail = takeTail(value, options.tailBytes, options.tailLines)
|
|
132
|
+
const term = searchTerm(head, "")
|
|
133
|
+
const total = bytes(value)
|
|
134
|
+
const lines = value.split("\n")
|
|
135
|
+
const headLinesUsed = head === "" ? 0 : head.split("\n").length
|
|
136
|
+
const tailLinesUsed = tail === "" ? 0 : tail.split("\n").length
|
|
137
|
+
const firstElided = headLinesUsed + 1
|
|
138
|
+
const lastElided = lines.length - tailLinesUsed
|
|
139
|
+
const headBytes = bytes(head)
|
|
140
|
+
const tailBytes = bytes(tail)
|
|
141
|
+
const elidedBytes = Math.max(0, total - headBytes - tailBytes)
|
|
142
|
+
const rangeForm = lastElided >= firstElided
|
|
143
|
+
const headSource = joinedSlice(lines, 0, Math.min(options.headLines, lines.length))
|
|
144
|
+
const tailStart = Math.max(0, lines.length - options.tailLines)
|
|
145
|
+
const tailSource = joinedSlice(lines, tailStart, lines.length - tailStart)
|
|
146
|
+
const cutMidLine = bytes(head) < bytes(headSource) || bytes(tail) < bytes(tailSource)
|
|
147
|
+
const lineRange = rangeForm && !cutMidLine
|
|
148
|
+
const keys = looksJson(value) ? topLevelJsonKeys(value) : []
|
|
149
|
+
const keyNotes = keys.flatMap((key) => {
|
|
150
|
+
const line = lineOfKey(lines, key)
|
|
151
|
+
if (lineRange) {
|
|
152
|
+
if (line < firstElided || line > lastElided) return []
|
|
153
|
+
return [`"${key}" (line ${line})`]
|
|
154
|
+
}
|
|
155
|
+
const at = value.indexOf(`"${key}"`)
|
|
156
|
+
if (at < headBytes || at >= total - tailBytes) return []
|
|
157
|
+
return [line > 0 ? `"${key}" (line ${line})` : `"${key}"`]
|
|
158
|
+
}).slice(0, 12)
|
|
159
|
+
const hints = [
|
|
160
|
+
term !== "" && value.includes(term) ? `${options.marker} search: grep -n '${term}' ${file}` : "",
|
|
161
|
+
lineRange
|
|
162
|
+
? `${options.marker} read more: sed -n '${firstElided},${lastElided}p' ${file}`
|
|
163
|
+
: elidedBytes > 0
|
|
164
|
+
? `${options.marker} read more: tail -c +${headBytes + 1} ${file} | head -c ${elidedBytes}`
|
|
165
|
+
: "",
|
|
166
|
+
].filter((line) => line !== "")
|
|
167
|
+
return [
|
|
168
|
+
`${options.marker} ${total} B -> ${BAND_LABEL}`,
|
|
169
|
+
head,
|
|
170
|
+
lineRange
|
|
171
|
+
? `${options.marker} elided lines ${firstElided}..${lastElided} of ${lines.length} (${elidedBytes} B)`
|
|
172
|
+
: `${options.marker} elided ${elidedBytes} B between head and tail`,
|
|
173
|
+
...(keyNotes.length > 0 ? [`${options.marker} json keys: ${keyNotes.join(", ")}`] : []),
|
|
174
|
+
tail,
|
|
175
|
+
`${options.marker} full output: ${file} (${total} B)`,
|
|
176
|
+
...hints,
|
|
177
|
+
].join("\n")
|
|
178
|
+
}
|
|
179
|
+
|
|
80
180
|
export const renderReplacement = (
|
|
81
181
|
value: string,
|
|
82
182
|
file: string,
|
|
@@ -133,7 +233,10 @@ export function rewriteMessages(
|
|
|
133
233
|
}
|
|
134
234
|
if (file === null || file === "") continue
|
|
135
235
|
|
|
136
|
-
const
|
|
236
|
+
const structured = options.shape !== "flat" && beforeBytes <= BAND_MAX_BYTES
|
|
237
|
+
const replacement = structured
|
|
238
|
+
? renderStructured(value, file, options)
|
|
239
|
+
: renderReplacement(value, file, options)
|
|
137
240
|
result.value = replacement
|
|
138
241
|
changed.push({
|
|
139
242
|
id: typeof item.id === "string" ? item.id : "",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"platform": "opencode",
|
|
4
4
|
"stack": "svelte",
|
|
5
5
|
"semanticSource": "cursor/svelte",
|
|
6
|
-
"sourceRevision": "
|
|
6
|
+
"sourceRevision": "034613cd2dce4fe89dcb9de2a0a5b7381f9c06d1bbe0fccb354bcdb8cb0fa074",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
9
9
|
"source": "AGENTS.md",
|
|
@@ -61,7 +61,7 @@ Copied to `.opencode/agents/` on `ai-rules init opencode --preset svelte`.
|
|
|
61
61
|
## OpenCode packaging
|
|
62
62
|
|
|
63
63
|
Agents ship with OpenCode YAML frontmatter: `description`, `mode: subagent`,
|
|
64
|
-
and `permission`.
|
|
64
|
+
and `permission`. No agent pins a provider model. A tier resolves through `.ai.local/team/model-tiers.json` when that file exists; otherwise the session model applies.
|
|
65
65
|
|
|
66
66
|
- Implementers (`feature-developer`, `debugger`, `ci-investigator`, test generators/healers): `permission.edit: allow`.
|
|
67
67
|
- Reviewer / planner roles: `edit` deny except `.ai.local/team/**`. `openspec-author` also allows `openspec/**`; `tech-writer` also allows `docs/**`. Prompt bodies still forbid production edits.
|
|
@@ -77,9 +77,9 @@ is advisory for the operator's OpenCode provider — see `task-router.md`.
|
|
|
77
77
|
|
|
78
78
|
| Tier | Agents |
|
|
79
79
|
|------|--------|
|
|
80
|
-
| **cheap** | `task-router`, `task-analyst`, `build-verifier`, `code-reviewer`, `tech-writer`, `codebase-analyzer` |
|
|
81
|
-
| **standard** | `feature-developer`, `debugger`, `ci-investigator`, `
|
|
82
|
-
| **strong** | `solution-architect`, `migration-specialist`, `security-reviewer`, `performance-auditor
|
|
80
|
+
| **cheap** | `task-router`, `task-analyst`, `build-verifier`, `code-reviewer`, `api-contract-reviewer`, `mockup-reviewer`, `tech-writer`, `codebase-analyzer` |
|
|
81
|
+
| **standard** | `feature-developer`, `debugger`, `ci-investigator`, `accessibility-reviewer`, `qa-tester`, `unit-test-*`, `playwright-test-*`, `openspec-author` |
|
|
82
|
+
| **strong** | `solution-architect`, `migration-specialist`, `security-reviewer`, `performance-auditor` |
|
|
83
83
|
|
|
84
84
|
## Orchestration
|
|
85
85
|
|
|
@@ -980,11 +980,117 @@ function reconcileStatusFromManifest(agent, step, resolved) {
|
|
|
980
980
|
return status.state;
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
+
/**
|
|
984
|
+
* Keep only the numeric usage fields and the two provenance fields. A host may
|
|
985
|
+
* forward richer objects; the ledger is allowlisted so nothing unbounded or
|
|
986
|
+
* secret-shaped reaches `metrics.json`.
|
|
987
|
+
*/
|
|
988
|
+
function sanitizeUsage(value) {
|
|
989
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
990
|
+
const num = (input) => (typeof input === 'number' && Number.isFinite(input) && input >= 0 ? input : null);
|
|
991
|
+
const usage = {
|
|
992
|
+
input: num(value.input), output: num(value.output), reasoning: num(value.reasoning),
|
|
993
|
+
cacheRead: num(value.cacheRead === undefined ? value.cached : value.cacheRead),
|
|
994
|
+
cacheWrite: num(value.cacheWrite), costUsd: num(value.costUsd),
|
|
995
|
+
model: typeof value.model === 'string' ? value.model.slice(0, 120) : null,
|
|
996
|
+
origin: value.origin === 'estimated' ? 'estimated' : 'measured',
|
|
997
|
+
};
|
|
998
|
+
const reported = usage.input !== null || usage.output !== null || usage.reasoning !== null ||
|
|
999
|
+
usage.cacheRead !== null || usage.cacheWrite !== null || usage.costUsd !== null;
|
|
1000
|
+
return reported ? usage : null;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Freshness of a persisted verification snapshot against the current worktree.
|
|
1005
|
+
* Read-only: closure warns, it never blocks on a stale snapshot.
|
|
1006
|
+
*/
|
|
1007
|
+
function gitSnapshot() {
|
|
1008
|
+
const { spawnSync } = require('child_process');
|
|
1009
|
+
const git = (args) => {
|
|
1010
|
+
const result = spawnSync('git', args, { cwd: process.cwd(), encoding: 'utf8', timeout: 10000, maxBuffer: 32 * 1024 * 1024 });
|
|
1011
|
+
return result && result.status === 0 ? String(result.stdout || '') : null;
|
|
1012
|
+
};
|
|
1013
|
+
const head = git(['rev-parse', 'HEAD']);
|
|
1014
|
+
if (head === null) return null;
|
|
1015
|
+
const branch = git(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
1016
|
+
const exclude = ['--', '.', ':(exclude).ai.local'];
|
|
1017
|
+
const statusText = git(['status', '--porcelain=v1', ...exclude]) || '';
|
|
1018
|
+
const diffText = git(['diff', '--binary', 'HEAD', ...exclude]) || '';
|
|
1019
|
+
const untracked = git(['ls-files', '--others', '--exclude-standard', ...exclude]) || '';
|
|
1020
|
+
return {
|
|
1021
|
+
head: head.trim(),
|
|
1022
|
+
branch: branch === null ? null : branch.trim(),
|
|
1023
|
+
dirtyFiles: statusText === '' ? 0 : statusText.split('\n').filter((line) => line !== '').length,
|
|
1024
|
+
worktreeHash: crypto.createHash('sha256').update(`${statusText}\u0000${diffText}\u0000${untracked}`).digest('hex'),
|
|
1025
|
+
capturedAt: now,
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* Seed the evidence file when the verifier finishes without an explicit
|
|
1031
|
+
* `verification.mjs record`: the snapshot plus a hash of `validation-report.md`.
|
|
1032
|
+
* An existing file is never refreshed — its binding must keep pointing at the
|
|
1033
|
+
* tree the commands actually ran on.
|
|
1034
|
+
*/
|
|
1035
|
+
function ensureVerificationSnapshot(dir, agent) {
|
|
1036
|
+
const file = path.join(dir, 'verification.json');
|
|
1037
|
+
if (fs.existsSync(file)) return;
|
|
1038
|
+
const snapshot = gitSnapshot();
|
|
1039
|
+
if (!snapshot) return;
|
|
1040
|
+
const reportPath = path.join(dir, 'validation-report.md');
|
|
1041
|
+
let report = null;
|
|
1042
|
+
try {
|
|
1043
|
+
const text = fs.readFileSync(reportPath);
|
|
1044
|
+
report = { path: 'validation-report.md', sha256: crypto.createHash('sha256').update(text).digest('hex') };
|
|
1045
|
+
} catch {}
|
|
1046
|
+
const verification = {
|
|
1047
|
+
schemaVersion: 1,
|
|
1048
|
+
task: path.basename(dir),
|
|
1049
|
+
snapshot,
|
|
1050
|
+
report,
|
|
1051
|
+
commands: [],
|
|
1052
|
+
gate: { status: 'snapshot-only', recordedBy: agent || null, checkedAt: now },
|
|
1053
|
+
};
|
|
1054
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
1055
|
+
fs.writeFileSync(temporary, JSON.stringify(verification, null, 2) + '\n');
|
|
1056
|
+
fs.renameSync(temporary, file);
|
|
1057
|
+
appendMetric({ type: 'verification_recorded', at: now, kind: 'snapshot-only', agent: agent || null, head: snapshot.head, worktreeHash: snapshot.worktreeHash, source: 'hook', attributionConfidence: 'high' });
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
function verificationFreshness(dir) {
|
|
1061
|
+
const file = path.join(dir, 'verification.json');
|
|
1062
|
+
if (!fs.existsSync(file)) return { present: false };
|
|
1063
|
+
let verification;
|
|
1064
|
+
try { verification = JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return { present: true, fresh: false, reasons: ['unreadable'] }; }
|
|
1065
|
+
const snapshot = verification && verification.snapshot;
|
|
1066
|
+
if (!snapshot || typeof snapshot.head !== 'string') return { present: true, fresh: false, reasons: ['no-snapshot'] };
|
|
1067
|
+
const current = gitSnapshot();
|
|
1068
|
+
if (!current) return { present: true, fresh: false, reasons: ['no-git'] };
|
|
1069
|
+
const reasons = [];
|
|
1070
|
+
if (current.head !== snapshot.head) reasons.push('head-changed');
|
|
1071
|
+
if (current.worktreeHash !== snapshot.worktreeHash) reasons.push('worktree-changed');
|
|
1072
|
+
return { present: true, fresh: reasons.length === 0, reasons };
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
let verificationStaleNoted = false;
|
|
1076
|
+
|
|
1077
|
+
function noteVerificationFreshness(dir, agent) {
|
|
1078
|
+
if (verificationStaleNoted) return;
|
|
1079
|
+
const freshness = verificationFreshness(dir);
|
|
1080
|
+
if (!freshness.present) return;
|
|
1081
|
+
if (freshness.fresh) return;
|
|
1082
|
+
verificationStaleNoted = true;
|
|
1083
|
+
appendMetric({ type: 'verification_stale', at: now, agent: agent || null, reasons: freshness.reasons, source: 'hook', attributionConfidence: 'high' });
|
|
1084
|
+
process.stderr.write(`verification evidence is stale (${freshness.reasons.join(', ')}); re-run the gate and record it before closure\n`);
|
|
1085
|
+
}
|
|
1086
|
+
|
|
983
1087
|
function finishActiveAttempt(forced) {
|
|
984
1088
|
const resolved = forced || resolvedAttempt(); if (!resolved) return null;
|
|
985
1089
|
const durationMs = Date.parse(now) - Date.parse(resolved.entry.startedAt);
|
|
986
1090
|
const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
|
|
987
|
-
|
|
1091
|
+
const usage = sanitizeUsage(hookInput.usage);
|
|
1092
|
+
appendMetric({ type: 'attempt_finished', at: now, attemptId: resolved.attemptId, outcome, durationMs: Number.isFinite(durationMs) && durationMs >= 0 ? durationMs : null, retryAfterFix: status.retryAfterFix || null, source: resolved.source || 'hook', attributionConfidence: resolved.confidence, ...(usage ? { usage } : {}) });
|
|
1093
|
+
if (resolved.entry && resolved.entry.agent === 'build-verifier') { ensureVerificationSnapshot(taskDir, resolved.entry.agent); noteVerificationFreshness(taskDir, resolved.entry.agent); }
|
|
988
1094
|
const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
|
|
989
1095
|
}
|
|
990
1096
|
function missingConsumerArtifacts() {
|
|
@@ -1014,6 +1120,7 @@ function completePipeline(statusPatch) {
|
|
|
1014
1120
|
// task_completed is written only on this branch. A missing receipt blocks
|
|
1015
1121
|
// above and must not be counted as a finished task.
|
|
1016
1122
|
status.state = 'completed';
|
|
1123
|
+
noteVerificationFreshness(taskDir, null);
|
|
1017
1124
|
completeTaskMetrics();
|
|
1018
1125
|
writeStatus(statusPatch);
|
|
1019
1126
|
out(`Pipeline complete for "${slug}". Run /technical-retro ${slug}.`);
|
|
@@ -151,7 +151,7 @@ Replanning is a **named, auditable operation** — never a silent reorder. Trigg
|
|
|
151
151
|
|
|
152
152
|
## Context budget & checkpoint/resume
|
|
153
153
|
|
|
154
|
-
Work in bounded waves (one artifact class across the target surface). **Checkpoint** each completed wave to `.memlog.md` (`## <date>` + an `event:` line) and record the produced paths on the `implementation` manifest entry (`authoritativePaths`). That checkpoint is the hook `writeStatus` path: it rewrites `.ai.local/team/tasks/<slug>/focus.md`. `focus.md` is a view, not the system of record. It lists slug, pipeline step index, authoritative paths for incomplete manifest ids, the last `.memlog.md` `event:` line, the next gate, one decomposition ready-set line, and one archive index line, and it stays under 100 lines. `status.json`, `metrics.json`, `artifact-manifest.json`, and `.memlog.md` stay the system of record. A resumed run (`/task-continue`) reads `focus.md` first, then `artifact-manifest.json` and `.memlog.md`, and continues at the first stage whose exit criteria are unmet — never re-derive state from the chat. A completed manifest entry keeps id, status, and `authoritativePaths`, and the default resume read omits that entry's markdown body; closing it appends one new `.memlog.md` event: line, moves the bulky body to `.ai.local/team/tasks/<slug>/archive/YYYY-MM-DD/`, and leaves earlier memlog lines, the human-readable slug and artifact ids, and the manifest entry in place, with no Beads hash ids and no Taskmaster tags. Mechanical waves (generation, embed sync) are delegated to repo scripts. A large command output (log, diff, test run, `git log`) is piped through `.ai.local/scripts/dump-output.mjs` instead of being read whole: take its ≤40-line head, then `grep -n` the stored file or find it with `team-db.mjs search "<term>"`. An **interrupted producer** (tool abort, killed session) is resumed, not restarted: run the stack's compile gate on the working tree first, and when it is red hand the failing output to the same producer with a `fix and finish` brief instead of starting a second parallel attempt. When the host runtime writes no `status.json` (manual-hook hosts such as OpenCode), the resume checkpoint is `artifact-manifest.json` + `.memlog.md`; never gate a resume on a file the runtime does not produce. See **context-and-iteration** for the budget, checkpoint, resume, and refinement loop.
|
|
154
|
+
Work in bounded waves (one artifact class across the target surface). **Checkpoint** each completed wave to `.memlog.md` (`## <date>` + an `event:` line) and record the produced paths on the `implementation` manifest entry (`authoritativePaths`). That checkpoint is the hook `writeStatus` path: it rewrites `.ai.local/team/tasks/<slug>/focus.md`. `focus.md` is a view, not the system of record. It lists slug, pipeline step index, authoritative paths for incomplete manifest ids, the last `.memlog.md` `event:` line, the next gate, one decomposition ready-set line, and one archive index line, and it stays under 100 lines. `status.json`, `metrics.json`, `artifact-manifest.json`, and `.memlog.md` stay the system of record. A resumed run (`/task-continue`) reads `focus.md` first, then `artifact-manifest.json` and `.memlog.md`, and continues at the first stage whose exit criteria are unmet — never re-derive state from the chat. A session approaching ~50 turns does not keep growing its history: the producer finishes the current wave, checkpoints it (`focus.md` + `artifact-manifest.json` + `.memlog.md`), and hands off to a fresh session. A wave that cannot finish before the cap checkpoints its partial state the same way. A completed manifest entry keeps id, status, and `authoritativePaths`, and the default resume read omits that entry's markdown body; closing it appends one new `.memlog.md` event: line, moves the bulky body to `.ai.local/team/tasks/<slug>/archive/YYYY-MM-DD/`, and leaves earlier memlog lines, the human-readable slug and artifact ids, and the manifest entry in place, with no Beads hash ids and no Taskmaster tags. Mechanical waves (generation, embed sync) are delegated to repo scripts. A large command output (log, diff, test run, `git log`) is piped through `.ai.local/scripts/dump-output.mjs` instead of being read whole: take its ≤40-line head, then `grep -n` the stored file or find it with `team-db.mjs search "<term>"`. An **interrupted producer** (tool abort, killed session) is resumed, not restarted: run the stack's compile gate on the working tree first, and when it is red hand the failing output to the same producer with a `fix and finish` brief instead of starting a second parallel attempt. When the host runtime writes no `status.json` (manual-hook hosts such as OpenCode), the resume checkpoint is `artifact-manifest.json` + `.memlog.md`; never gate a resume on a file the runtime does not produce. See **context-and-iteration** for the budget, checkpoint, resume, and refinement loop.
|
|
155
155
|
|
|
156
156
|
## Self-review & context hygiene
|
|
157
157
|
|
|
@@ -269,9 +269,10 @@ Use Task tool or `/agent-name`. Pass: slug, artifact paths, step `scope` if set.
|
|
|
269
269
|
|
|
270
270
|
1. Read `steps[i].model` if present; else use the agent’s frontmatter `model` (see `agents/README.md` matrix).
|
|
271
271
|
2. Resolve the tier through `.ai.local/team/model-tiers.json` → `tiers.<tier>` when that file exists. The user approved that map, so passing an explicit model is allowed. Pass the resolved `providerID/modelID` (or `providerID/modelID#variant`) to the Task/subagent tool.
|
|
272
|
-
- **`cheap`** →
|
|
273
|
-
- **`standard`** → implementation
|
|
274
|
-
- **`strong`** → architecture, security, migration, performance
|
|
272
|
+
- **`cheap`** → router, analyst, tech-writer, codebase-analyzer, and the review roles `code-reviewer`, `build-verifier`, `api-contract-reviewer`, `mockup-reviewer`. Resolve the provider through `.ai.local/team/model-tiers.json`. Do not write a provider id into the agent file. Pass the mapped id as written; do not append `#high`.
|
|
273
|
+
- **`standard`** → implementation and the other non-review specialists. `feature-developer` stays on this tier.
|
|
274
|
+
- **`strong`** → architecture, security, migration, performance. Never downgrade a `strong` step to the parent default, and do not put `mockup-reviewer` on `strong`.
|
|
275
|
+
- When `steps[i].model` is omitted and the agent file has no `model`, those four review roles stay `cheap` when `.ai.local/team/model-tiers.json` exists. Without that file, omit the model and the session model applies.
|
|
275
276
|
- If a tier is declared but the file has no mapping, **STOP** and report `model-tier-unmapped`; do not silently inherit the parent model.
|
|
276
277
|
3. If the tool does not accept a model (Cursor/Claude adapters), record the resolved tier in the handoff and let the platform pin apply.
|
|
277
278
|
4. Parallel steps: apply the step-level `model` to **each** agent in the array (or omit → each agent’s own frontmatter).
|
|
@@ -16,7 +16,7 @@ Typical feature with data and UI. Concrete directories and rule stems — in the
|
|
|
16
16
|
|
|
17
17
|
## Context hygiene
|
|
18
18
|
|
|
19
|
-
A command whose output can exceed ~4 KB — a test run, a build/lint log, `git log`, a diff — is piped through `.ai.local/scripts/dump-output.mjs --task <slug>` instead of being read whole. Work from its ≤40-line head and the stored file (grep it or use `team-db.mjs search`), and when that output informed a decision, record the repo-relative `outputs/…` path in `implementation.md` or `validation-report.md`; a `code-reviewer` may ask for that path. Do not read the whole output into context.
|
|
19
|
+
A command whose output can exceed ~4 KB — a test run, a build/lint log, `git log`, a diff — is piped through `.ai.local/scripts/dump-output.mjs --task <slug>` instead of being read whole. Work from its ≤40-line head and the stored file (grep it or use `team-db.mjs search`), and when that output informed a decision, record the repo-relative `outputs/…` path in `implementation.md` or `validation-report.md`; a `code-reviewer` may ask for that path. Do not read the whole output into context. Artifact reads take the same slice: read the `artifact-manifest.json` entry, not the artifact body, and never re-read a completed entry's body. Read a large artifact with offset/limit ranges instead of a whole-file read.
|
|
20
20
|
|
|
21
21
|
## Iterative refinement loop
|
|
22
22
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"platform": "zcode",
|
|
4
4
|
"stack": "android-kotlin",
|
|
5
5
|
"semanticSource": "cursor/android-kotlin",
|
|
6
|
-
"sourceRevision": "
|
|
6
|
+
"sourceRevision": "ee19e6c80f46af0a8307034142c742e07bdf8dd7c20c7488e1582a30ec82aada",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
9
9
|
"source": "AGENTS.md",
|
|
@@ -52,9 +52,9 @@ is advisory for the operator's ZCode session model — see `task-router.md`.
|
|
|
52
52
|
|
|
53
53
|
| Tier | Agents |
|
|
54
54
|
|------|--------|
|
|
55
|
-
| **cheap** | `task-router`, `task-analyst`, `build-verifier`, `code-reviewer`, `tech-writer`, `codebase-analyzer` |
|
|
56
|
-
| **standard** | `feature-developer`, `debugger`, `ci-investigator`, `
|
|
57
|
-
| **strong** | `solution-architect`, `migration-specialist`, `security-reviewer`, `performance-auditor
|
|
55
|
+
| **cheap** | `task-router`, `task-analyst`, `build-verifier`, `code-reviewer`, `api-contract-reviewer`, `mockup-reviewer`, `tech-writer`, `codebase-analyzer` |
|
|
56
|
+
| **standard** | `feature-developer`, `debugger`, `ci-investigator`, `accessibility-reviewer`, `qa-tester`, `unit-test-*`, `instrumentation-test-*`, `openspec-author` |
|
|
57
|
+
| **strong** | `solution-architect`, `migration-specialist`, `security-reviewer`, `performance-auditor` |
|
|
58
58
|
|
|
59
59
|
## Pipeline schema
|
|
60
60
|
|
|
@@ -980,11 +980,117 @@ function reconcileStatusFromManifest(agent, step, resolved) {
|
|
|
980
980
|
return status.state;
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
+
/**
|
|
984
|
+
* Keep only the numeric usage fields and the two provenance fields. A host may
|
|
985
|
+
* forward richer objects; the ledger is allowlisted so nothing unbounded or
|
|
986
|
+
* secret-shaped reaches `metrics.json`.
|
|
987
|
+
*/
|
|
988
|
+
function sanitizeUsage(value) {
|
|
989
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
990
|
+
const num = (input) => (typeof input === 'number' && Number.isFinite(input) && input >= 0 ? input : null);
|
|
991
|
+
const usage = {
|
|
992
|
+
input: num(value.input), output: num(value.output), reasoning: num(value.reasoning),
|
|
993
|
+
cacheRead: num(value.cacheRead === undefined ? value.cached : value.cacheRead),
|
|
994
|
+
cacheWrite: num(value.cacheWrite), costUsd: num(value.costUsd),
|
|
995
|
+
model: typeof value.model === 'string' ? value.model.slice(0, 120) : null,
|
|
996
|
+
origin: value.origin === 'estimated' ? 'estimated' : 'measured',
|
|
997
|
+
};
|
|
998
|
+
const reported = usage.input !== null || usage.output !== null || usage.reasoning !== null ||
|
|
999
|
+
usage.cacheRead !== null || usage.cacheWrite !== null || usage.costUsd !== null;
|
|
1000
|
+
return reported ? usage : null;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Freshness of a persisted verification snapshot against the current worktree.
|
|
1005
|
+
* Read-only: closure warns, it never blocks on a stale snapshot.
|
|
1006
|
+
*/
|
|
1007
|
+
function gitSnapshot() {
|
|
1008
|
+
const { spawnSync } = require('child_process');
|
|
1009
|
+
const git = (args) => {
|
|
1010
|
+
const result = spawnSync('git', args, { cwd: process.cwd(), encoding: 'utf8', timeout: 10000, maxBuffer: 32 * 1024 * 1024 });
|
|
1011
|
+
return result && result.status === 0 ? String(result.stdout || '') : null;
|
|
1012
|
+
};
|
|
1013
|
+
const head = git(['rev-parse', 'HEAD']);
|
|
1014
|
+
if (head === null) return null;
|
|
1015
|
+
const branch = git(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
1016
|
+
const exclude = ['--', '.', ':(exclude).ai.local'];
|
|
1017
|
+
const statusText = git(['status', '--porcelain=v1', ...exclude]) || '';
|
|
1018
|
+
const diffText = git(['diff', '--binary', 'HEAD', ...exclude]) || '';
|
|
1019
|
+
const untracked = git(['ls-files', '--others', '--exclude-standard', ...exclude]) || '';
|
|
1020
|
+
return {
|
|
1021
|
+
head: head.trim(),
|
|
1022
|
+
branch: branch === null ? null : branch.trim(),
|
|
1023
|
+
dirtyFiles: statusText === '' ? 0 : statusText.split('\n').filter((line) => line !== '').length,
|
|
1024
|
+
worktreeHash: crypto.createHash('sha256').update(`${statusText}\u0000${diffText}\u0000${untracked}`).digest('hex'),
|
|
1025
|
+
capturedAt: now,
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* Seed the evidence file when the verifier finishes without an explicit
|
|
1031
|
+
* `verification.mjs record`: the snapshot plus a hash of `validation-report.md`.
|
|
1032
|
+
* An existing file is never refreshed — its binding must keep pointing at the
|
|
1033
|
+
* tree the commands actually ran on.
|
|
1034
|
+
*/
|
|
1035
|
+
function ensureVerificationSnapshot(dir, agent) {
|
|
1036
|
+
const file = path.join(dir, 'verification.json');
|
|
1037
|
+
if (fs.existsSync(file)) return;
|
|
1038
|
+
const snapshot = gitSnapshot();
|
|
1039
|
+
if (!snapshot) return;
|
|
1040
|
+
const reportPath = path.join(dir, 'validation-report.md');
|
|
1041
|
+
let report = null;
|
|
1042
|
+
try {
|
|
1043
|
+
const text = fs.readFileSync(reportPath);
|
|
1044
|
+
report = { path: 'validation-report.md', sha256: crypto.createHash('sha256').update(text).digest('hex') };
|
|
1045
|
+
} catch {}
|
|
1046
|
+
const verification = {
|
|
1047
|
+
schemaVersion: 1,
|
|
1048
|
+
task: path.basename(dir),
|
|
1049
|
+
snapshot,
|
|
1050
|
+
report,
|
|
1051
|
+
commands: [],
|
|
1052
|
+
gate: { status: 'snapshot-only', recordedBy: agent || null, checkedAt: now },
|
|
1053
|
+
};
|
|
1054
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
1055
|
+
fs.writeFileSync(temporary, JSON.stringify(verification, null, 2) + '\n');
|
|
1056
|
+
fs.renameSync(temporary, file);
|
|
1057
|
+
appendMetric({ type: 'verification_recorded', at: now, kind: 'snapshot-only', agent: agent || null, head: snapshot.head, worktreeHash: snapshot.worktreeHash, source: 'hook', attributionConfidence: 'high' });
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
function verificationFreshness(dir) {
|
|
1061
|
+
const file = path.join(dir, 'verification.json');
|
|
1062
|
+
if (!fs.existsSync(file)) return { present: false };
|
|
1063
|
+
let verification;
|
|
1064
|
+
try { verification = JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return { present: true, fresh: false, reasons: ['unreadable'] }; }
|
|
1065
|
+
const snapshot = verification && verification.snapshot;
|
|
1066
|
+
if (!snapshot || typeof snapshot.head !== 'string') return { present: true, fresh: false, reasons: ['no-snapshot'] };
|
|
1067
|
+
const current = gitSnapshot();
|
|
1068
|
+
if (!current) return { present: true, fresh: false, reasons: ['no-git'] };
|
|
1069
|
+
const reasons = [];
|
|
1070
|
+
if (current.head !== snapshot.head) reasons.push('head-changed');
|
|
1071
|
+
if (current.worktreeHash !== snapshot.worktreeHash) reasons.push('worktree-changed');
|
|
1072
|
+
return { present: true, fresh: reasons.length === 0, reasons };
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
let verificationStaleNoted = false;
|
|
1076
|
+
|
|
1077
|
+
function noteVerificationFreshness(dir, agent) {
|
|
1078
|
+
if (verificationStaleNoted) return;
|
|
1079
|
+
const freshness = verificationFreshness(dir);
|
|
1080
|
+
if (!freshness.present) return;
|
|
1081
|
+
if (freshness.fresh) return;
|
|
1082
|
+
verificationStaleNoted = true;
|
|
1083
|
+
appendMetric({ type: 'verification_stale', at: now, agent: agent || null, reasons: freshness.reasons, source: 'hook', attributionConfidence: 'high' });
|
|
1084
|
+
process.stderr.write(`verification evidence is stale (${freshness.reasons.join(', ')}); re-run the gate and record it before closure\n`);
|
|
1085
|
+
}
|
|
1086
|
+
|
|
983
1087
|
function finishActiveAttempt(forced) {
|
|
984
1088
|
const resolved = forced || resolvedAttempt(); if (!resolved) return null;
|
|
985
1089
|
const durationMs = Date.parse(now) - Date.parse(resolved.entry.startedAt);
|
|
986
1090
|
const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
|
|
987
|
-
|
|
1091
|
+
const usage = sanitizeUsage(hookInput.usage);
|
|
1092
|
+
appendMetric({ type: 'attempt_finished', at: now, attemptId: resolved.attemptId, outcome, durationMs: Number.isFinite(durationMs) && durationMs >= 0 ? durationMs : null, retryAfterFix: status.retryAfterFix || null, source: resolved.source || 'hook', attributionConfidence: resolved.confidence, ...(usage ? { usage } : {}) });
|
|
1093
|
+
if (resolved.entry && resolved.entry.agent === 'build-verifier') { ensureVerificationSnapshot(taskDir, resolved.entry.agent); noteVerificationFreshness(taskDir, resolved.entry.agent); }
|
|
988
1094
|
const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
|
|
989
1095
|
}
|
|
990
1096
|
function missingConsumerArtifacts() {
|
|
@@ -1014,6 +1120,7 @@ function completePipeline(statusPatch) {
|
|
|
1014
1120
|
// task_completed is written only on this branch. A missing receipt blocks
|
|
1015
1121
|
// above and must not be counted as a finished task.
|
|
1016
1122
|
status.state = 'completed';
|
|
1123
|
+
noteVerificationFreshness(taskDir, null);
|
|
1017
1124
|
completeTaskMetrics();
|
|
1018
1125
|
writeStatus(statusPatch);
|
|
1019
1126
|
out(`Pipeline complete for "${slug}". Run /technical-retro ${slug}.`);
|