@bonesofspring/ai-rules 0.2.66 → 0.2.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +2 -0
  3. package/bin/cli.js +9 -1
  4. package/bin/lib/engine-scripts.js +0 -4
  5. package/bin/lib/seed-ai-local-team.js +26 -0
  6. package/docs/OPENCODE-COMPATIBILITY.md +1 -0
  7. package/docs/OPENCODE.md +14 -1
  8. package/docs/TEAM-DB.md +2 -1
  9. package/docs/TOKEN-ECONOMY.md +32 -1
  10. package/docs/openapi/team-db.v1.json +5 -5
  11. package/package.json +10 -2
  12. package/presets/_shared/ai-local/scripts/dump-output.mjs +63 -12
  13. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +3 -3
  14. package/presets/_shared/ai-local/scripts/team-db-tracker.mjs +2 -0
  15. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +9 -2
  16. package/presets/_shared/hooks/list-ai-local.mjs +17 -0
  17. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +9 -2
  18. package/presets/claude/android-kotlin/hooks/list-ai-local.mjs +17 -0
  19. package/presets/claude/go/hooks/chain-team-phases.sh +9 -2
  20. package/presets/claude/go/hooks/list-ai-local.mjs +17 -0
  21. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +9 -2
  22. package/presets/claude/ios-swift/hooks/list-ai-local.mjs +17 -0
  23. package/presets/claude/java/hooks/chain-team-phases.sh +9 -2
  24. package/presets/claude/java/hooks/list-ai-local.mjs +17 -0
  25. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +9 -2
  26. package/presets/claude/mcp-ts/hooks/list-ai-local.mjs +17 -0
  27. package/presets/claude/mol/hooks/chain-team-phases.sh +9 -2
  28. package/presets/claude/mol/hooks/list-ai-local.mjs +17 -0
  29. package/presets/claude/next/agents/ci-investigator.md +5 -2
  30. package/presets/claude/next/agents/debugger.md +5 -2
  31. package/presets/claude/next/agents/feature-developer.md +5 -2
  32. package/presets/claude/next/hooks/chain-team-phases.sh +9 -2
  33. package/presets/claude/next/hooks/list-ai-local.mjs +17 -0
  34. package/presets/claude/next/rules/architecture/feature-delivery-workflow.md +4 -0
  35. package/presets/claude/nuxt/hooks/chain-team-phases.sh +9 -2
  36. package/presets/claude/nuxt/hooks/list-ai-local.mjs +17 -0
  37. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +9 -2
  38. package/presets/claude/php-hexagonal/hooks/list-ai-local.mjs +17 -0
  39. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +9 -2
  40. package/presets/claude/php-laravel/hooks/list-ai-local.mjs +17 -0
  41. package/presets/claude/svelte/hooks/chain-team-phases.sh +9 -2
  42. package/presets/claude/svelte/hooks/list-ai-local.mjs +17 -0
  43. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +9 -2
  44. package/presets/cursor/android-kotlin/hooks/list-ai-local.mjs +17 -0
  45. package/presets/cursor/go/hooks/chain-team-phases.sh +9 -2
  46. package/presets/cursor/go/hooks/list-ai-local.mjs +17 -0
  47. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +9 -2
  48. package/presets/cursor/ios-swift/hooks/list-ai-local.mjs +17 -0
  49. package/presets/cursor/java/hooks/chain-team-phases.sh +9 -2
  50. package/presets/cursor/java/hooks/list-ai-local.mjs +17 -0
  51. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +9 -2
  52. package/presets/cursor/mcp-ts/hooks/list-ai-local.mjs +17 -0
  53. package/presets/cursor/mol/hooks/chain-team-phases.sh +9 -2
  54. package/presets/cursor/mol/hooks/list-ai-local.mjs +17 -0
  55. package/presets/cursor/next/hooks/chain-team-phases.sh +9 -2
  56. package/presets/cursor/next/hooks/list-ai-local.mjs +17 -0
  57. package/presets/cursor/next/rules/feature-delivery-workflow.mdc +4 -0
  58. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +9 -2
  59. package/presets/cursor/nuxt/hooks/list-ai-local.mjs +17 -0
  60. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +9 -2
  61. package/presets/cursor/php-hexagonal/hooks/list-ai-local.mjs +17 -0
  62. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +9 -2
  63. package/presets/cursor/php-laravel/hooks/list-ai-local.mjs +17 -0
  64. package/presets/cursor/svelte/hooks/chain-team-phases.sh +9 -2
  65. package/presets/cursor/svelte/hooks/list-ai-local.mjs +17 -0
  66. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  67. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +9 -2
  68. package/presets/mavis/android-kotlin/hooks/list-ai-local.mjs +17 -0
  69. package/presets/mavis/go/adapter-map.json +1 -1
  70. package/presets/mavis/go/hooks/chain-team-phases.sh +9 -2
  71. package/presets/mavis/go/hooks/list-ai-local.mjs +17 -0
  72. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  73. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +9 -2
  74. package/presets/mavis/ios-swift/hooks/list-ai-local.mjs +17 -0
  75. package/presets/mavis/java/adapter-map.json +1 -1
  76. package/presets/mavis/java/hooks/chain-team-phases.sh +9 -2
  77. package/presets/mavis/java/hooks/list-ai-local.mjs +17 -0
  78. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  79. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +9 -2
  80. package/presets/mavis/mcp-ts/hooks/list-ai-local.mjs +17 -0
  81. package/presets/mavis/mol/adapter-map.json +1 -1
  82. package/presets/mavis/mol/hooks/chain-team-phases.sh +9 -2
  83. package/presets/mavis/mol/hooks/list-ai-local.mjs +17 -0
  84. package/presets/mavis/next/adapter-map.json +1 -1
  85. package/presets/mavis/next/agents/ci-investigator.md +5 -2
  86. package/presets/mavis/next/agents/debugger.md +5 -2
  87. package/presets/mavis/next/agents/feature-developer.md +5 -2
  88. package/presets/mavis/next/hooks/chain-team-phases.sh +9 -2
  89. package/presets/mavis/next/hooks/list-ai-local.mjs +17 -0
  90. package/presets/mavis/next/rules/feature-delivery-workflow.md +4 -0
  91. package/presets/mavis/nuxt/adapter-map.json +1 -1
  92. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +9 -2
  93. package/presets/mavis/nuxt/hooks/list-ai-local.mjs +17 -0
  94. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  95. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +9 -2
  96. package/presets/mavis/php-hexagonal/hooks/list-ai-local.mjs +17 -0
  97. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  98. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +9 -2
  99. package/presets/mavis/php-laravel/hooks/list-ai-local.mjs +17 -0
  100. package/presets/mavis/svelte/adapter-map.json +1 -1
  101. package/presets/mavis/svelte/hooks/chain-team-phases.sh +9 -2
  102. package/presets/mavis/svelte/hooks/list-ai-local.mjs +17 -0
  103. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  104. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +9 -2
  105. package/presets/opencode/android-kotlin/hooks/list-ai-local.mjs +17 -0
  106. package/presets/opencode/go/adapter-map.json +1 -1
  107. package/presets/opencode/go/hooks/chain-team-phases.sh +9 -2
  108. package/presets/opencode/go/hooks/list-ai-local.mjs +17 -0
  109. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  110. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +9 -2
  111. package/presets/opencode/ios-swift/hooks/list-ai-local.mjs +17 -0
  112. package/presets/opencode/java/adapter-map.json +1 -1
  113. package/presets/opencode/java/hooks/chain-team-phases.sh +9 -2
  114. package/presets/opencode/java/hooks/list-ai-local.mjs +17 -0
  115. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  116. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +9 -2
  117. package/presets/opencode/mcp-ts/hooks/list-ai-local.mjs +17 -0
  118. package/presets/opencode/mol/adapter-map.json +1 -1
  119. package/presets/opencode/mol/hooks/chain-team-phases.sh +9 -2
  120. package/presets/opencode/mol/hooks/list-ai-local.mjs +17 -0
  121. package/presets/opencode/next/adapter-map.json +1 -1
  122. package/presets/opencode/next/agents/ci-investigator.md +5 -2
  123. package/presets/opencode/next/agents/debugger.md +5 -2
  124. package/presets/opencode/next/agents/feature-developer.md +5 -2
  125. package/presets/opencode/next/hooks/chain-team-phases.sh +9 -2
  126. package/presets/opencode/next/hooks/list-ai-local.mjs +17 -0
  127. package/presets/opencode/next/rules/feature-delivery-workflow.md +4 -0
  128. package/presets/opencode/nuxt/adapter-map.json +1 -1
  129. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +9 -2
  130. package/presets/opencode/nuxt/hooks/list-ai-local.mjs +17 -0
  131. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  132. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +9 -2
  133. package/presets/opencode/php-hexagonal/hooks/list-ai-local.mjs +17 -0
  134. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  135. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +9 -2
  136. package/presets/opencode/php-laravel/hooks/list-ai-local.mjs +17 -0
  137. package/presets/opencode/plugins/output-guard/README.md +43 -0
  138. package/presets/opencode/plugins/output-guard/index.ts +300 -0
  139. package/presets/opencode/plugins/output-guard/package.json +9 -0
  140. package/presets/opencode/plugins/output-guard/rewrite.ts +149 -0
  141. package/presets/opencode/plugins/task-status/task-view.ts +58 -20
  142. package/presets/opencode/plugins/task-status/tui.tsx +5 -3
  143. package/presets/opencode/svelte/adapter-map.json +1 -1
  144. package/presets/opencode/svelte/hooks/chain-team-phases.sh +9 -2
  145. package/presets/opencode/svelte/hooks/list-ai-local.mjs +17 -0
  146. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  147. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +9 -2
  148. package/presets/zcode/android-kotlin/hooks/list-ai-local.mjs +17 -0
  149. package/presets/zcode/go/adapter-map.json +1 -1
  150. package/presets/zcode/go/hooks/chain-team-phases.sh +9 -2
  151. package/presets/zcode/go/hooks/list-ai-local.mjs +17 -0
  152. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  153. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +9 -2
  154. package/presets/zcode/ios-swift/hooks/list-ai-local.mjs +17 -0
  155. package/presets/zcode/java/adapter-map.json +1 -1
  156. package/presets/zcode/java/hooks/chain-team-phases.sh +9 -2
  157. package/presets/zcode/java/hooks/list-ai-local.mjs +17 -0
  158. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  159. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +9 -2
  160. package/presets/zcode/mcp-ts/hooks/list-ai-local.mjs +17 -0
  161. package/presets/zcode/mol/adapter-map.json +1 -1
  162. package/presets/zcode/mol/hooks/chain-team-phases.sh +9 -2
  163. package/presets/zcode/mol/hooks/list-ai-local.mjs +17 -0
  164. package/presets/zcode/next/adapter-map.json +1 -1
  165. package/presets/zcode/next/agents/ci-investigator.md +5 -2
  166. package/presets/zcode/next/agents/debugger.md +5 -2
  167. package/presets/zcode/next/agents/feature-developer.md +5 -2
  168. package/presets/zcode/next/hooks/chain-team-phases.sh +9 -2
  169. package/presets/zcode/next/hooks/list-ai-local.mjs +17 -0
  170. package/presets/zcode/next/rules/feature-delivery-workflow.md +4 -0
  171. package/presets/zcode/nuxt/adapter-map.json +1 -1
  172. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +9 -2
  173. package/presets/zcode/nuxt/hooks/list-ai-local.mjs +17 -0
  174. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  175. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +9 -2
  176. package/presets/zcode/php-hexagonal/hooks/list-ai-local.mjs +17 -0
  177. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  178. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +9 -2
  179. package/presets/zcode/php-laravel/hooks/list-ai-local.mjs +17 -0
  180. package/presets/zcode/svelte/adapter-map.json +1 -1
  181. package/presets/zcode/svelte/hooks/chain-team-phases.sh +9 -2
  182. package/presets/zcode/svelte/hooks/list-ai-local.mjs +17 -0
  183. package/scripts/report-context-cost.mjs +432 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.67
4
+
5
+ ### Added
6
+
7
+ - **OpenCode output guard.** `init opencode` and `update` copy `presets/opencode/plugins/output-guard/` to `.opencode/plugins/output-guard/`. The server plugin registers `ctx.session.hook("context")` and replaces a `tool-result` over 8 KB with a bounded head + tail, the path under `.ai.local/team/output-guard/`, and one `grep` / `sed` hint. `AI_RULES_OUTPUT_GUARD_BYTES` changes the threshold and the seeded `.ai.local/.gitignore` ignores `team/output-guard/`. It works for a prompt without `/task`; a host without the hook no-ops and `AI_RULES_OUTPUT_GUARD=0` disables it.
8
+ - **Output-guard totals in the context report.** `report-context-cost.mjs` reads `output-guard/stats.jsonl`, dedupes by path, and prints before/after/saved bytes plus the session count; `--json` adds `outputGuard`.
9
+ - **Efficiency report and A/B harness.** `report:efficiency` reads `results.jsonl` (every tool result) and `usage.jsonl` (per-step tokens/cost), prints measured bytes, tokens, cost, turns, and quality, and writes a static dashboard with `--html`. `bench:efficiency` runs the guard off/on through `opencode run --standalone` with a deterministic oracle and writes `efficiency.json`; the verdict requires `--runs 5`. The report never turns a byte saving into a token saving.
10
+ - **Next implementer reads 8 rules at startup.** The other 21 stems move to a `Read when the task reaches the matching zone` section of the generated `## Rules to load` block (Next only), so `feature-developer` no longer reads ~100 KB of rules before its first action.
11
+ - **`focus.md` lists at most 5 incomplete entries** plus a count; the existing 100-line cap still bounds a single entry with many paths.
12
+ - **`list-ai-local.mjs` prints an 8-hex body hash per file**, so a session can skip a re-read whose content did not change.
13
+ - **`tracker list --json` rows carry `labels` and `sourceRefs`.** Both arrays join the summary row, so the repository-only upstream importer can recognize an item it already created without fetching every item back.
14
+
15
+ ### Fixed
16
+
17
+ - **`dump-output.mjs` resolves the team root above the current directory.** A run from `packages/ai-rules` no longer creates a nested `.ai.local/team`; `--root` still wins and a missing root is a usage error.
18
+ - **The Cursor `next` feature-delivery rule carries the Context hygiene paragraph**, matching the OpenCode and Claude carriers.
19
+ - **A consumer seeded by ≤0.2.65 is told its weekly `upstream-research` job is dead.** `update` now prints a warning when the operator-owned `scheduler/jobs.json` references the runner that became repository-only, instead of silently leaving a job that fails every fire; the file itself is never rewritten. `test-pack-repo-only.mjs` covers the upgrade cohort.
20
+ - **The task-status sidebar can no longer lift a repo-wide stop by accident.** A resume word or the sidebar Resume clears only the pause it detected — a task sentinel or the operator `STOP`; a repo `ESTOP` is emergency semantics and is removed by hand alone. A prompt match is exact-first, so a longer substring prompt can no longer outrank the exact one.
21
+ - **Tracker UI refusals and affordances match the engine.** `E_TRACKER_TRANSITION` explains itself and closes instead of offering a dead Reload loop; the tracker form and the linked-task form gate the submit while invalid and cannot double-fire mid-flight; enqueue is hidden on terminal items; the mock upstream mirrors the contract (integer delete id, 202 on continue, the idempotent enqueue 200, query-grammar 422s).
22
+ - **A crash between a tracker create and its map write no longer duplicates an upstream item.** The repository-only importer adopts the row whose `sourceRefs` carry this run's `run:<id>` instead of creating a second one; if the lookup fails, the previous create path runs unchanged.
23
+ - **`doctor` gives an engine module with no recorded base its own `no-base` finding.** Its bytes were never attributed to the package, so the finding no longer says `modified` and reads as a consumer edit.
24
+
3
25
  ## 0.2.66
4
26
 
5
27
  ### Repository-only upstream research payload
package/README.md CHANGED
@@ -30,6 +30,8 @@ Run `init` from the **app root** (`--cwd` if needed). Default `--preset` is `nex
30
30
 
31
31
  OpenCode also ships **`.opencode/plugins/task-status/`**, a TUI sidebar for the active `/task` run (slug, state, elapsed time, step, remaining-time estimate, soft-stop). OpenCode auto-loads it; it needs no `opencode.json` entry, is refreshed by `update`, and is a viewer only — the chain hook stays manual.
32
32
 
33
+ **`.opencode/plugins/output-guard/`** is the server counterpart: a `tool-result` over 8 KB is stored under `.ai.local/team/output-guard/` and replaced with a bounded head + tail, the path, and one `grep` hint. It registers `ctx.session.hook("context")`, so it works for a prompt without `/task`; `AI_RULES_OUTPUT_GUARD=0` disables it and a host without the hook no-ops. It is a token-economy mechanism, not a security boundary. Measure it with `yarn report:efficiency` (text/JSON/HTML) and `yarn bench:efficiency --model <provider/model> --runs 5` (A/B with a deterministic oracle); a byte saving is never reported as a token saving.
34
+
33
35
  ### Project MCP catalog
34
36
 
35
37
  `init mcp` writes the third-party servers this package ships plus Storybook, DefectDojo, and the packaged GitLab / GitHub / Yandex runtime entries into every installed client; `--tools` narrows the list to the clients you name. Entries render in each client's native shape and merge like `init`: extra servers, the consumer's `env` / `headers`, and other top-level keys stay. Names: `context7`, `playwright` (Claude's id is `playwright-test`), `chrome-devtools`, `next-devtools`, `semgrep`, `sentry`, `figma-desktop` (alias `figma`, the local `http://127.0.0.1:3845/mcp` server), `figma-cloud` (the remote `https://mcp.figma.com/mcp` server), `storybook` (`http://localhost:6200/mcp`), `defectdojo`, `gitlab`, `github`, `yandex-tracker`, and `yandex-wiki`; `--all` selects every one. The last five are packaged runtime entries: they are registered without credentials and need `mcp setup <provider>` once (DefectDojo reads `.env.defectdojo`). Next.js DevTools needs a running `next dev` on Next.js 16+; Semgrep needs the `semgrep` CLI; Sentry uses OAuth.
package/bin/cli.js CHANGED
@@ -1057,7 +1057,15 @@ function collectDoctorState(cwd, packageRoot) {
1057
1057
  continue;
1058
1058
  }
1059
1059
  engineFindings.push({
1060
- code: entry.state === 'stale' ? 'stale-engine' : 'modified',
1060
+ // A `no-base` module is not a consumer edit: its bytes were never
1061
+ // attributed, so it carries its own finding code instead of folding
1062
+ // into `modified`.
1063
+ code:
1064
+ entry.state === 'stale'
1065
+ ? 'stale-engine'
1066
+ : entry.state === 'no-base'
1067
+ ? 'no-base'
1068
+ : 'modified',
1061
1069
  path: entry.rel,
1062
1070
  detail: entry.detail,
1063
1071
  fixable: entry.state === 'stale',
@@ -73,9 +73,6 @@ const ENGINE_SCRIPTS = [
73
73
  /** Package `presets/`-relative directory holding the engine source of truth. */
74
74
  const ENGINE_SOURCE_RELATIVE = '_shared/ai-local/scripts';
75
75
 
76
- /** The `ENGINE_SCRIPTS` subset whose sources ship in the published tarball. */
77
- const SHIPPED_ENGINE_SCRIPTS = ENGINE_SCRIPTS.filter((name) => !isRepoOnlyEngineScript(name));
78
-
79
76
  /**
80
77
  * Absolute shipped engine directory for a package.
81
78
  *
@@ -93,7 +90,6 @@ function isRepoOnlyEngineScript(name) {
93
90
 
94
91
  module.exports = {
95
92
  ENGINE_SCRIPTS,
96
- SHIPPED_ENGINE_SCRIPTS,
97
93
  REPO_ONLY_ENGINE_SCRIPTS,
98
94
  ENGINE_SOURCE_RELATIVE,
99
95
  engineSourceDir,
@@ -43,6 +43,8 @@ const AI_LOCAL_GITIGNORE = [
43
43
  '# Per-step write-scope baselines; derived from git, never a project input.',
44
44
  'team/.write-scope/',
45
45
  'team/upstream/cursor.json',
46
+ '# Output-guard spill files; runtime state, never commit.',
47
+ 'team/output-guard/',
46
48
  '# Dashboard lifecycle marker (`.ai.local/.ui/api.json`); local runtime state, never commit.',
47
49
  '.ui/',
48
50
  '# Dev-server lifecycle markers (`.ai.local/.dev/<name>.json`); local runtime state, never commit.',
@@ -378,6 +380,30 @@ function copyTemplates(presetTeamSrc, dest) {
378
380
  if (fs.existsSync(jobsSource) && !fs.existsSync(jobsTarget)) {
379
381
  copyFile(jobsSource, jobsTarget);
380
382
  written.push('.ai.local/team/scheduler/jobs.json');
383
+ } else if (!fs.existsSync(jobsSource) && fs.existsSync(jobsTarget)) {
384
+ // The upgrade cohort: a consumer seeded by a pre-repository-only release
385
+ // keeps the weekly job whose runner no longer ships. The operator file
386
+ // is never rewritten, so the dead job is named, not silently left behind.
387
+ try {
388
+ const jobs = JSON.parse(fs.readFileSync(jobsTarget, 'utf8'));
389
+ const dead = Array.isArray(jobs?.jobs)
390
+ ? jobs.jobs.filter(
391
+ (job) =>
392
+ String(job?.id ?? '').includes('upstream-research') ||
393
+ (Array.isArray(job?.payload?.runner) &&
394
+ job.payload.runner.some((element) =>
395
+ String(element).includes('upstream-research'),
396
+ )),
397
+ )
398
+ : [];
399
+ for (const job of dead) {
400
+ warn(
401
+ `scheduler/jobs.json keeps job "${job?.id ?? '?'}", whose runner (upstream-research.mjs) is repository-only in this version: the weekly run will fail until the job is removed or a repository checkout provides the runner`,
402
+ );
403
+ }
404
+ } catch {
405
+ // An unreadable jobs file is the scheduler's refusal to explain.
406
+ }
381
407
  }
382
408
  }
383
409
  const gitkeepSrc = path.join(presetTeamSrc, 'tasks', '.gitkeep');
@@ -36,6 +36,7 @@ Allowed status values are `confirmed`, `partial`, `unknown`, `manual`, and `no-e
36
36
  | Workspace Skill discovery | `confirmed` | opencode.ai/docs/skills | `.opencode/skills/<name>/SKILL.md` | Native `skill` tool |
37
37
  | Project MCP | `confirmed` | opencode.ai/docs/mcp-servers | `opencode.json` `mcp` | Merge on init |
38
38
  | TUI plugin discovery | `confirmed` | opencode.ai/docs/plugins | `.opencode/plugins/<name>/` loads automatically | Ships `task-status` TUI sidebar |
39
+ | Tool-output guard (server plugin) | `confirmed` | opencode.ai/docs/build/plugins/server + live probe 2026-11-13 | `ctx.session.hook("context")` mutates assembled messages before dispatch | Ships `output-guard`; a host without the hook no-ops |
39
40
  | Project hooks (`hooks.json`) | `manual` | plugins exist; this preset ships a TUI viewer, not a hook plugin | No confirmed `subagentStop` analog was opened | Manual `chain-team-phases.sh` |
40
41
  | Slash commands | `confirmed` | opencode.ai/docs/commands | `.opencode/commands/<name>.md` | Native `/task` |
41
42
  | Plugin / skill / MCP combo | `confirmed` | skills + mcp docs | MCP inflates context | Gate unused servers in operator config |
package/docs/OPENCODE.md CHANGED
@@ -78,10 +78,23 @@ printf '%s\n' '{"status":"completed","attemptId":"<from-status.json>"}' \
78
78
  | TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh
79
79
  ```
80
80
 
81
- Human gates pause with `awaitingHumanGate: true`. Resume with `/task-continue`. There is **no** shipped `hooks.json` or hook plugin in v1.
81
+ Human gates pause with `awaitingHumanGate: true`. Resume with `/task-continue`. There is **no** shipped `hooks.json`; the shipped OpenCode plugins are the TUI viewer and the output guard.
82
82
 
83
83
  Full team layout: `.ai.local/team/README.md`.
84
84
 
85
+ ## Output guard (server plugin)
86
+
87
+ `.opencode/plugins/output-guard/` ships with every OpenCode preset. It registers
88
+ `ctx.session.hook("context")`, which receives the assembled model messages before
89
+ dispatch. A `tool-result` over 8 KB is written to
90
+ `.ai.local/team/output-guard/<sessionID>/outputs/` and replaced with a bounded
91
+ head + tail, the path, and one `grep` / `sed` hint. It works for every prompt,
92
+ including one without `/task`.
93
+
94
+ - `AI_RULES_OUTPUT_GUARD=0` disables it; `AI_RULES_OUTPUT_GUARD_BYTES` changes the threshold.
95
+ - The change affects only the outgoing model call; persisted history is untouched.
96
+ - Hosts without `ctx.session.hook` no-op. It is a token-economy mechanism, not a security boundary.
97
+
85
98
  ## Task status sidebar (TUI plugin)
86
99
 
87
100
  `.opencode/plugins/task-status/` ships with every OpenCode preset. `init` and
package/docs/TEAM-DB.md CHANGED
@@ -66,9 +66,10 @@ team.db-shm
66
66
  team-db-errors.log
67
67
  team/scheduler/runs/
68
68
  team/scheduler/state.json
69
+ team/output-guard/
69
70
  ```
70
71
 
71
- `team/scheduler/jobs.json` stays tracked: definitions are code, run output is not. The
72
+ `team/scheduler/jobs.json` stays tracked: definitions are code, run output is not. `team/output-guard/` holds the OpenCode output-guard spill files; runtime state, never commit. The
72
73
  consumer root `.gitignore` is never created or edited. Never commit the database even
73
74
  for a demo: it contains copies of prompts and task documents.
74
75
 
@@ -49,7 +49,19 @@ Example run, 2026-11-13; file lists elided; task bytes move as a task grows.
49
49
  { "key": "UI", "file": "app/src/ui/pages/Example/Example.tsx", "cap": 420, "attachedLines": 415, "headroom": 5 }
50
50
  ],
51
51
  "tasks": [{ "slug": "context-cost-report", "files": 8, "bytes": 18257 }],
52
- "usage": { "events": 0, "input": 0, "output": 0, "cached": 0 }
52
+ "usage": { "events": 0, "input": 0, "output": 0, "cached": 0 },
53
+ "outputGuard": {
54
+ "present": true,
55
+ "file": ".ai.local/team/output-guard/stats.jsonl",
56
+ "events": 10,
57
+ "invalid": 0,
58
+ "beforeBytes": 113996,
59
+ "afterBytes": 34189,
60
+ "savedBytes": 79807,
61
+ "savedRatio": 0.7,
62
+ "sessions": 1,
63
+ "tools": ["read", "shell"]
64
+ }
53
65
  }
54
66
  ```
55
67
 
@@ -57,6 +69,25 @@ Example run, 2026-11-13; file lists elided; task bytes move as a task grows.
57
69
 
58
70
  `tasks` sums every file under `.ai.local/team/tasks/<slug>`, `archive/` included. A missing team directory returns `tasks: []`.
59
71
 
72
+ `outputGuard` reads `.ai.local/team/output-guard/stats.jsonl`, written by the OpenCode output guard. Rows are deduped by `path` because a plugin reload re-records a historical result. `savedRatio` is the byte saving on the replaced tool results, not a session-token claim; `invalid` counts unreadable rows. A missing file returns `present: false` and zeros.
73
+
74
+ ## Effectiveness (separate report)
75
+
76
+ This report measures **fixed inputs**. It does not measure a session. The output guard writes two more ledgers under `.ai.local/team/output-guard/`:
77
+
78
+ - `results.jsonl` — every tool result, replaced or not (the denominator);
79
+ - `usage.jsonl` — one row per assistant step, from the OpenCode `ctx.session.context` tokens and cost.
80
+
81
+ `report-efficiency.mjs` reads both and prints measured tool bytes, input/output/reasoning/cache tokens, cost, turns, and quality. `bench-efficiency.mjs` runs an A/B (guard off/on) through `opencode run --standalone` with a deterministic oracle and writes `efficiency.json`; `report-efficiency --bench <file>` merges it. The byte percentage is always labelled as tool-result bytes, never as a token saving.
82
+
83
+ ```bash
84
+ yarn report:efficiency
85
+ yarn report:efficiency --html /tmp/efficiency.html
86
+ yarn bench:efficiency --model <provider/model> --runs 3
87
+ ```
88
+
89
+ The A/B needs `--runs 5` for a verdict; `--runs 1` is a smoke. Each run starts a private server, so the arm env (`AI_RULES_OUTPUT_GUARD=0|1`) applies without touching the shared server.
90
+
60
91
  `usage` sums `input`, `output`, and `cached` over `metrics.json` events with `type: "usage_recorded"`. Zero events is a valid result and prints as zero. A usage record that was never written stays missing; the report does not infer one.
61
92
 
62
93
  ## Baseline
@@ -9287,7 +9287,7 @@
9287
9287
  "dependsOn": [
9288
9288
  2
9289
9289
  ],
9290
- "sourceTask": "task-tracker-tracker-impl",
9290
+ "sourceTask": "task-tracker-impl",
9291
9291
  "sourceRefs": [
9292
9292
  "AC-5",
9293
9293
  "WP7"
@@ -9465,7 +9465,7 @@
9465
9465
  ],
9466
9466
  "waitingOn": [],
9467
9467
  "ready": true,
9468
- "sourceTask": "task-tracker-tracker-impl",
9468
+ "sourceTask": "task-tracker-impl",
9469
9469
  "sourceRefs": [
9470
9470
  "AC-5",
9471
9471
  "WP7"
@@ -9734,7 +9734,7 @@
9734
9734
  "dependsOn": [
9735
9735
  2
9736
9736
  ],
9737
- "sourceTask": "task-tracker-tracker-impl",
9737
+ "sourceTask": "task-tracker-impl",
9738
9738
  "sourceRefs": [
9739
9739
  "AC-5",
9740
9740
  "WP7"
@@ -9911,7 +9911,7 @@
9911
9911
  ],
9912
9912
  "waitingOn": [],
9913
9913
  "ready": true,
9914
- "sourceTask": "task-tracker-tracker-impl",
9914
+ "sourceTask": "task-tracker-impl",
9915
9915
  "sourceRefs": [
9916
9916
  "AC-5",
9917
9917
  "WP7"
@@ -10014,7 +10014,7 @@
10014
10014
  2
10015
10015
  ],
10016
10016
  "priority": 2,
10017
- "sourceTask": "task-tracker-tracker-impl",
10017
+ "sourceTask": "task-tracker-impl",
10018
10018
  "sourceRefs": [
10019
10019
  "AC-5",
10020
10020
  "WP7"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonesofspring/ai-rules",
3
- "version": "0.2.66",
3
+ "version": "0.2.67",
4
4
  "description": "Presets of Cursor, Claude, Mavis, OpenCode, and ZCode rules/commands for Revy Ross personal use",
5
5
  "license": "MIT",
6
6
  "author": "Revy Ross",
@@ -35,7 +35,8 @@
35
35
  "presets/_shared/ai-local/scripts/check-write-scope.mjs",
36
36
  "scripts/check-product-specs.sh",
37
37
  "scripts/aggregate-agent-task-metrics.mjs",
38
- "scripts/close-agent-task-human-gate.mjs"
38
+ "scripts/close-agent-task-human-gate.mjs",
39
+ "scripts/report-context-cost.mjs"
39
40
  ],
40
41
  "scripts": {
41
42
  "check:fast": "bash scripts/check-preset-fast.sh",
@@ -81,6 +82,13 @@
81
82
  "test:generated-drift-claude-fixtures": "node scripts/test-generated-drift-claude-fixtures.mjs",
82
83
  "test:rule-improver": "node scripts/test-rule-improver-ledger.mjs",
83
84
  "test:guard-shell-command": "node scripts/test-guard-shell-command.mjs",
85
+ "test:dump-output": "node scripts/test-dump-output.mjs",
86
+ "test:output-guard": "node scripts/test-output-guard.mjs",
87
+ "test:context-cost-report": "node scripts/test-context-cost-report.mjs",
88
+ "test:report-efficiency": "node scripts/test-report-efficiency.mjs",
89
+ "test:bench-efficiency": "node scripts/test-bench-efficiency.mjs",
90
+ "report:efficiency": "node scripts/report-efficiency.mjs",
91
+ "bench:efficiency": "node scripts/bench-efficiency.mjs",
84
92
  "check:processes": "node scripts/test-process-lease.mjs && node scripts/test-process-adapters.mjs && node scripts/test-process-scan.mjs",
85
93
  "test:cli-mcp-merge": "node scripts/test-cli-mcp-merge.mjs",
86
94
  "test:cli-init-clean": "node scripts/run-locked.mjs --label test:cli-init-clean -- node scripts/test-cli-init-clean.mjs",
@@ -16,6 +16,9 @@
16
16
  *
17
17
  * Exit codes: 0 ok (including empty or truncated input), 2 usage or containment
18
18
  * refusal, 1 write failure. The task comes from `--task`, else TEAM_TASK_SLUG.
19
+ * Without `--root`, the team root is the nearest `.ai.local/team` above the
20
+ * current directory, so a run from a nested package does not create a second
21
+ * overlay.
19
22
  */
20
23
 
21
24
  import fs from 'node:fs';
@@ -47,7 +50,7 @@ at most ${HEAD_LINES} head lines, the byte count, the path, and one grep hint.
47
50
  --task <slug> task slug; defaults to TEAM_TASK_SLUG
48
51
  --label <text> suffix in the output name (lowercased, [^a-z0-9]+ -> -)
49
52
  --input <file> read this file instead of stdin
50
- --root <dir> team root; defaults to .ai.local/team under the current directory
53
+ --root <dir> team root; defaults to the nearest .ai.local/team above the current directory
51
54
 
52
55
  Exit codes: 0 ok (including empty or truncated input), 2 usage or containment
53
56
  refusal, 1 write failure.`;
@@ -120,17 +123,39 @@ const parseArgs = (argv) => {
120
123
  return { help: false, flags };
121
124
  };
122
125
 
123
- const assertNotSymlink = (target, label) => {
124
- let stats;
126
+ const assertNotSymlink = (target, label, boundary) => {
127
+ // Walk from the team root down, not from `/`: a system alias above the
128
+ // project (`/var` → `/private/var` on macOS) is not a write-through dead end
129
+ // for the projection. A symlink at any depth **inside** the team tree still
130
+ // is, including the root itself.
131
+ const absolute = path.resolve(target);
132
+ const start = path.resolve(boundary ?? path.parse(absolute).root);
125
133
  try {
126
- stats = fs.lstatSync(target);
134
+ if (fs.lstatSync(start).isSymbolicLink()) {
135
+ usageFail(`refusing a symlinked ${label}: ${target}`);
136
+ }
127
137
  } catch (error) {
128
- if (error.code === 'ENOENT') return;
129
- throw error;
138
+ if (error.code !== 'ENOENT') throw error;
139
+ return;
140
+ }
141
+ const relative = path.relative(start, absolute);
142
+ if (relative.startsWith('..') || path.isAbsolute(relative)) {
143
+ usageFail(`refusing to write ${label} outside ${start}: ${target}`);
144
+ }
145
+ let walked = start;
146
+ for (const part of relative.split(path.sep).filter((part) => part !== '')) {
147
+ walked = path.join(walked, part);
148
+ let stats;
149
+ try {
150
+ stats = fs.lstatSync(walked);
151
+ } catch (error) {
152
+ if (error.code === 'ENOENT') return;
153
+ throw error;
154
+ }
155
+ // The projection walk skips symlinks, so anything written through one is
156
+ // invisible to `team-db search` — refuse instead of dumping into a dead end.
157
+ if (stats.isSymbolicLink()) usageFail(`refusing a symlinked ${label}: ${target}`);
130
158
  }
131
- // The projection walk skips symlinks, so anything written through one is
132
- // invisible to `team-db search` — refuse instead of dumping into a dead end.
133
- if (stats.isSymbolicLink()) usageFail(`refusing a symlinked ${label}: ${target}`);
134
159
  };
135
160
 
136
161
  const assertReadableFile = (file) => {
@@ -291,6 +316,27 @@ const displayPath = (file) => {
291
316
  return (inside ? relative : target).split(path.sep).join('/');
292
317
  };
293
318
 
319
+ /**
320
+ * Nearest `.ai.local/team` at or above `start`. A nested package in a monorepo
321
+ * owns its overlay when it has one; otherwise the repo-root overlay wins. Null
322
+ * means the caller must pass `--root` — never create a second overlay by
323
+ * guessing the current directory.
324
+ */
325
+ export function resolveTeamRoot(start = process.cwd()) {
326
+ let dir = path.resolve(start);
327
+ for (;;) {
328
+ const candidate = path.join(dir, '.ai.local', 'team');
329
+ try {
330
+ if (fs.statSync(candidate).isDirectory()) return candidate;
331
+ } catch {
332
+ /* keep walking up */
333
+ }
334
+ const parent = path.dirname(dir);
335
+ if (parent === dir) return null;
336
+ dir = parent;
337
+ }
338
+ }
339
+
294
340
  async function main(argv) {
295
341
  const { help, flags } = parseArgs(argv);
296
342
  if (help) {
@@ -302,15 +348,20 @@ async function main(argv) {
302
348
  if (slug === '') {
303
349
  usageFail('a task slug is required: --task <slug> or TEAM_TASK_SLUG (letters, digits, "-", max 48 chars)');
304
350
  }
305
- const root = flags.root ? path.resolve(flags.root) : path.join(process.cwd(), '.ai.local', 'team');
351
+ const root = flags.root ? path.resolve(flags.root) : resolveTeamRoot(process.cwd());
352
+ if (!root) {
353
+ usageFail(
354
+ 'no .ai.local/team found above the current directory; pass --root <team-dir>',
355
+ );
356
+ }
306
357
  const inputPath = typeof flags.input === 'string' && flags.input !== '' ? path.resolve(flags.input) : null;
307
358
  // Validate before touching the tree, so a usage refusal writes nothing.
308
359
  if (inputPath) assertReadableFile(inputPath);
309
360
 
310
361
  const taskDir = path.join(root, 'tasks', slug);
311
362
  const outputsDir = path.join(taskDir, 'outputs');
312
- assertNotSymlink(taskDir, 'task directory');
313
- assertNotSymlink(outputsDir, 'outputs directory');
363
+ assertNotSymlink(taskDir, 'task directory', root);
364
+ assertNotSymlink(outputsDir, 'outputs directory', root);
314
365
  fs.mkdirSync(outputsDir, { recursive: true });
315
366
 
316
367
  const baseId = [utcStamp(), sanitizeLabel(flags.label)].filter(Boolean).join('-');
@@ -1526,7 +1526,7 @@ const trackerItemExample = {
1526
1526
  labels: ['tracker', 'ui'],
1527
1527
  history: [trackerHistoryExample],
1528
1528
  dependsOn: [2],
1529
- sourceTask: 'task-tracker-tracker-impl',
1529
+ sourceTask: 'task-tracker-impl',
1530
1530
  sourceRefs: ['AC-5', 'WP7'],
1531
1531
  createdAt: '2026-11-10T09:00:00.000Z',
1532
1532
  updatedAt: '2026-11-12T10:00:00.000Z',
@@ -1554,7 +1554,7 @@ const trackerItemSummaryExample = {
1554
1554
  dependsOn: [2],
1555
1555
  waitingOn: [],
1556
1556
  ready: true,
1557
- sourceTask: 'task-tracker-tracker-impl',
1557
+ sourceTask: 'task-tracker-impl',
1558
1558
  sourceRefs: ['AC-5', 'WP7'],
1559
1559
  taskState: null,
1560
1560
  createdAt: '2026-11-10T09:00:00.000Z',
@@ -1568,7 +1568,7 @@ const trackerCreateRequestExample = {
1568
1568
  title: 'Ship the tracker operator UI',
1569
1569
  dependsOn: [2],
1570
1570
  priority: 2,
1571
- sourceTask: 'task-tracker-tracker-impl',
1571
+ sourceTask: 'task-tracker-impl',
1572
1572
  sourceRefs: ['AC-5', 'WP7'],
1573
1573
  type: 'feature',
1574
1574
  description: 'The /tracker list and the /tracker/[id] detail over the existing proxy.',
@@ -1953,6 +1953,8 @@ export function runTrackerCommand(subcommand, positionalId, options = {}) {
1953
1953
  status: annotated.item.status,
1954
1954
  effectiveStatus: annotated.effectiveStatus,
1955
1955
  priority: annotated.item.priority,
1956
+ labels: annotated.item.labels,
1957
+ sourceRefs: annotated.item.sourceRefs,
1956
1958
  ready: annotated.ready,
1957
1959
  waitingOn: annotated.waitingOn,
1958
1960
  createdAt: annotated.item.createdAt,
@@ -1264,11 +1264,15 @@ function focusDigestMarkdown(dir, statusSnapshot) {
1264
1264
  }
1265
1265
  } catch {}
1266
1266
  }
1267
+ // Five entries is enough to resume; a longer list is a status dump, not a
1268
+ // pointer. The line budget below still bounds a single entry with many paths.
1269
+ const MAX_FOCUS_ENTRIES = 5;
1270
+ const shownIncomplete = incomplete.slice(0, MAX_FOCUS_ENTRIES);
1267
1271
  const pathLines = [];
1268
1272
  if (incomplete.length === 0) pathLines.push(' - (none)');
1269
1273
  else {
1270
- for (let index = 0; index < incomplete.length; index += 1) {
1271
- const item = incomplete[index];
1274
+ for (let index = 0; index < shownIncomplete.length; index += 1) {
1275
+ const item = shownIncomplete[index];
1272
1276
  if (item.paths.length === 0) pathLines.push(' - ' + item.id + ': (none)');
1273
1277
  else {
1274
1278
  for (let pathIndex = 0; pathIndex < item.paths.length; pathIndex += 1) {
@@ -1276,6 +1280,9 @@ function focusDigestMarkdown(dir, statusSnapshot) {
1276
1280
  }
1277
1281
  }
1278
1282
  }
1283
+ if (incomplete.length > shownIncomplete.length) {
1284
+ pathLines.push(' - (+' + String(incomplete.length - shownIncomplete.length) + ' more incomplete entries)');
1285
+ }
1279
1286
  }
1280
1287
  let readyLine = '- decomposition ready set: (none)';
1281
1288
  try {
@@ -14,6 +14,7 @@
14
14
  */
15
15
  import fs from 'node:fs';
16
16
  import path from 'node:path';
17
+ import crypto from 'node:crypto';
17
18
  import { fileURLToPath } from 'node:url';
18
19
 
19
20
  export const OUTPUT_CAP = 4096;
@@ -29,6 +30,15 @@ const isRealDirectory = (target) => {
29
30
  }
30
31
  };
31
32
 
33
+ /** First 8 hex of the file body; a session-local re-read gate, not a security hash. */
34
+ const shortHash = (file) => {
35
+ try {
36
+ return crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex').slice(0, 8);
37
+ } catch {
38
+ return '????????';
39
+ }
40
+ };
41
+
32
42
  const insideRoot = (root, abs) => {
33
43
  const relative = path.relative(root, abs);
34
44
  return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
@@ -168,6 +178,13 @@ export const renderReport = (root, inputs) => {
168
178
  }
169
179
  if (blocks.length === 0) return { text: 'overlays=0', chains: [], read: [] };
170
180
  const lines = [`overlays=${overlaySet.size}`, ...blocks.flatMap((block) => block.lines)];
181
+ const readSet = new Set(read);
182
+ if (readSet.size > 0) {
183
+ lines.push('hashes:');
184
+ for (const file of [...readSet].sort()) {
185
+ lines.push(`${file} ${shortHash(path.join(root, file))}`);
186
+ }
187
+ }
171
188
  return {
172
189
  text: lines.join('\n'),
173
190
  chains: blocks.map((block) => ({ for: block.for, overlays: block.overlays })),
@@ -1301,11 +1301,15 @@ function focusDigestMarkdown(dir, statusSnapshot) {
1301
1301
  }
1302
1302
  } catch {}
1303
1303
  }
1304
+ // Five entries is enough to resume; a longer list is a status dump, not a
1305
+ // pointer. The line budget below still bounds a single entry with many paths.
1306
+ const MAX_FOCUS_ENTRIES = 5;
1307
+ const shownIncomplete = incomplete.slice(0, MAX_FOCUS_ENTRIES);
1304
1308
  const pathLines = [];
1305
1309
  if (incomplete.length === 0) pathLines.push(' - (none)');
1306
1310
  else {
1307
- for (let index = 0; index < incomplete.length; index += 1) {
1308
- const item = incomplete[index];
1311
+ for (let index = 0; index < shownIncomplete.length; index += 1) {
1312
+ const item = shownIncomplete[index];
1309
1313
  if (item.paths.length === 0) pathLines.push(' - ' + item.id + ': (none)');
1310
1314
  else {
1311
1315
  for (let pathIndex = 0; pathIndex < item.paths.length; pathIndex += 1) {
@@ -1313,6 +1317,9 @@ function focusDigestMarkdown(dir, statusSnapshot) {
1313
1317
  }
1314
1318
  }
1315
1319
  }
1320
+ if (incomplete.length > shownIncomplete.length) {
1321
+ pathLines.push(' - (+' + String(incomplete.length - shownIncomplete.length) + ' more incomplete entries)');
1322
+ }
1316
1323
  }
1317
1324
  let readyLine = '- decomposition ready set: (none)';
1318
1325
  try {
@@ -14,6 +14,7 @@
14
14
  */
15
15
  import fs from 'node:fs';
16
16
  import path from 'node:path';
17
+ import crypto from 'node:crypto';
17
18
  import { fileURLToPath } from 'node:url';
18
19
 
19
20
  export const OUTPUT_CAP = 4096;
@@ -29,6 +30,15 @@ const isRealDirectory = (target) => {
29
30
  }
30
31
  };
31
32
 
33
+ /** First 8 hex of the file body; a session-local re-read gate, not a security hash. */
34
+ const shortHash = (file) => {
35
+ try {
36
+ return crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex').slice(0, 8);
37
+ } catch {
38
+ return '????????';
39
+ }
40
+ };
41
+
32
42
  const insideRoot = (root, abs) => {
33
43
  const relative = path.relative(root, abs);
34
44
  return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
@@ -168,6 +178,13 @@ export const renderReport = (root, inputs) => {
168
178
  }
169
179
  if (blocks.length === 0) return { text: 'overlays=0', chains: [], read: [] };
170
180
  const lines = [`overlays=${overlaySet.size}`, ...blocks.flatMap((block) => block.lines)];
181
+ const readSet = new Set(read);
182
+ if (readSet.size > 0) {
183
+ lines.push('hashes:');
184
+ for (const file of [...readSet].sort()) {
185
+ lines.push(`${file} ${shortHash(path.join(root, file))}`);
186
+ }
187
+ }
171
188
  return {
172
189
  text: lines.join('\n'),
173
190
  chains: blocks.map((block) => ({ for: block.for, overlays: block.overlays })),
@@ -1300,11 +1300,15 @@ function focusDigestMarkdown(dir, statusSnapshot) {
1300
1300
  }
1301
1301
  } catch {}
1302
1302
  }
1303
+ // Five entries is enough to resume; a longer list is a status dump, not a
1304
+ // pointer. The line budget below still bounds a single entry with many paths.
1305
+ const MAX_FOCUS_ENTRIES = 5;
1306
+ const shownIncomplete = incomplete.slice(0, MAX_FOCUS_ENTRIES);
1303
1307
  const pathLines = [];
1304
1308
  if (incomplete.length === 0) pathLines.push(' - (none)');
1305
1309
  else {
1306
- for (let index = 0; index < incomplete.length; index += 1) {
1307
- const item = incomplete[index];
1310
+ for (let index = 0; index < shownIncomplete.length; index += 1) {
1311
+ const item = shownIncomplete[index];
1308
1312
  if (item.paths.length === 0) pathLines.push(' - ' + item.id + ': (none)');
1309
1313
  else {
1310
1314
  for (let pathIndex = 0; pathIndex < item.paths.length; pathIndex += 1) {
@@ -1312,6 +1316,9 @@ function focusDigestMarkdown(dir, statusSnapshot) {
1312
1316
  }
1313
1317
  }
1314
1318
  }
1319
+ if (incomplete.length > shownIncomplete.length) {
1320
+ pathLines.push(' - (+' + String(incomplete.length - shownIncomplete.length) + ' more incomplete entries)');
1321
+ }
1315
1322
  }
1316
1323
  let readyLine = '- decomposition ready set: (none)';
1317
1324
  try {
@@ -14,6 +14,7 @@
14
14
  */
15
15
  import fs from 'node:fs';
16
16
  import path from 'node:path';
17
+ import crypto from 'node:crypto';
17
18
  import { fileURLToPath } from 'node:url';
18
19
 
19
20
  export const OUTPUT_CAP = 4096;
@@ -29,6 +30,15 @@ const isRealDirectory = (target) => {
29
30
  }
30
31
  };
31
32
 
33
+ /** First 8 hex of the file body; a session-local re-read gate, not a security hash. */
34
+ const shortHash = (file) => {
35
+ try {
36
+ return crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex').slice(0, 8);
37
+ } catch {
38
+ return '????????';
39
+ }
40
+ };
41
+
32
42
  const insideRoot = (root, abs) => {
33
43
  const relative = path.relative(root, abs);
34
44
  return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
@@ -168,6 +178,13 @@ export const renderReport = (root, inputs) => {
168
178
  }
169
179
  if (blocks.length === 0) return { text: 'overlays=0', chains: [], read: [] };
170
180
  const lines = [`overlays=${overlaySet.size}`, ...blocks.flatMap((block) => block.lines)];
181
+ const readSet = new Set(read);
182
+ if (readSet.size > 0) {
183
+ lines.push('hashes:');
184
+ for (const file of [...readSet].sort()) {
185
+ lines.push(`${file} ${shortHash(path.join(root, file))}`);
186
+ }
187
+ }
171
188
  return {
172
189
  text: lines.join('\n'),
173
190
  chains: blocks.map((block) => ({ for: block.for, overlays: block.overlays })),