simt-dev 0.6.3 → 0.7.0

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 (137) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +2 -2
  3. package/agents/simt-agent.md +84 -0
  4. package/docs/decisions/ADR-009-skill-layout.md +1 -1
  5. package/docs/decisions/ADR-086-the-stable-prefix-comes-first-and-the-lock-records-both-digests.md +1 -1
  6. package/docs/decisions/ADR-106-the-harness-hook-runs-through-a-repo-shim.md +46 -0
  7. package/docs/decisions/ADR-107-an-install-can-name-one-harness-and-the-skipped-ones-are-named.md +51 -0
  8. package/docs/decisions/ADR-108-an-adoption-builds-the-index-and-a-command-refreshes-it-on-read.md +59 -0
  9. package/docs/decisions/ADR-109-simt-dev-is-its-own-consumer-and-the-guards-that-kept-it-from-being-one-are-retired.md +47 -0
  10. package/docs/decisions/ADR-110-the-lock-file-follows-the-manifest-name-and-the-old-name-is-read-until-the-next-write.md +43 -0
  11. package/docs/decisions/ADR-111-the-tool-ships-one-agent-rendered-per-harness-and-installs-it-with-init-and-a-command.md +75 -0
  12. package/docs/decisions/ADR-112-the-registry-is-what-simt-dev-ships-and-a-repo-owns-its-own-skills.md +81 -0
  13. package/docs/decisions/ADR-113-a-pre-push-that-carries-only-documentation-skips-the-test-gate-and-says-so.md +87 -0
  14. package/docs/decisions/ADR-114-the-bench-pairs-at-the-task-level-a-missing-cost-is-not-zero-and-an-unasked-cross-group-compare-is-refused.md +74 -0
  15. package/docs/decisions/ADR-115-the-index-stamps-its-schema-version-migrates-older-databases-in-place-and-serves-newer-ones-from-a-sidecar.md +69 -0
  16. package/docs/decisions/ADR-116-rust-support-reaches-the-example-path-the-indent-and-the-bench-runner.md +100 -0
  17. package/docs/decisions/README.md +9 -0
  18. package/package.json +4 -2
  19. package/rules/core.md +2 -2
  20. package/rules/mdc/test-gate.mdc +2 -0
  21. package/rules/stacks/android.md +3 -3
  22. package/rules/stacks/connectiq.md +2 -2
  23. package/rules/stacks/dart.md +1 -1
  24. package/rules/stacks/deno.md +1 -1
  25. package/rules/stacks/dotnet.md +1 -1
  26. package/rules/stacks/elixir.md +1 -1
  27. package/rules/stacks/go.md +1 -1
  28. package/rules/stacks/jvm.md +3 -2
  29. package/rules/stacks/node.md +2 -2
  30. package/rules/stacks/python.md +7 -6
  31. package/rules/stacks/ruby.md +1 -1
  32. package/rules/stacks/rust.md +1 -1
  33. package/rules/stacks/swift.md +1 -1
  34. package/rules/stacks/typescript.md +2 -2
  35. package/rules/stacks/uv.md +3 -2
  36. package/skills/simt-commands/SKILL.md +70 -0
  37. package/src/advice/advice.mjs +7 -3
  38. package/src/agenthooks/decide.mjs +141 -9
  39. package/src/agenthooks/opencode.mjs +72 -0
  40. package/src/agenthooks/prompt.mjs +6 -2
  41. package/src/agenthooks/render.mjs +186 -19
  42. package/src/agenthooks/shim.mjs +55 -0
  43. package/src/agents/render.mjs +277 -0
  44. package/src/argv.mjs +8 -0
  45. package/src/bench/ablate.mjs +31 -14
  46. package/src/bench/mine.mjs +48 -1
  47. package/src/bench/probes.mjs +5 -6
  48. package/src/bench/report.mjs +243 -80
  49. package/src/bench/run.mjs +12 -11
  50. package/src/bench/variants.mjs +112 -40
  51. package/src/brief/assemble.mjs +6 -0
  52. package/src/ci/workflow.mjs +16 -7
  53. package/src/commands/agent.mjs +206 -0
  54. package/src/commands/agenthook.mjs +109 -15
  55. package/src/commands/bench.mjs +2 -1
  56. package/src/commands/compare.mjs +8 -7
  57. package/src/commands/decide.mjs +6 -5
  58. package/src/commands/evidence.mjs +13 -3
  59. package/src/commands/gate.mjs +85 -19
  60. package/src/commands/graph.mjs +18 -5
  61. package/src/commands/help.mjs +35 -14
  62. package/src/commands/hooks.mjs +68 -25
  63. package/src/commands/impact.mjs +4 -2
  64. package/src/commands/index.mjs +17 -4
  65. package/src/commands/init.mjs +169 -37
  66. package/src/commands/lease.mjs +203 -35
  67. package/src/commands/lessons.mjs +65 -9
  68. package/src/commands/map.mjs +33 -18
  69. package/src/commands/plugin.mjs +1 -1
  70. package/src/commands/repoindex.mjs +1 -0
  71. package/src/commands/rules.mjs +92 -18
  72. package/src/commands/skills.mjs +60 -25
  73. package/src/commands/skillscompile.mjs +8 -7
  74. package/src/commands/skillsinstall.mjs +12 -0
  75. package/src/commands/slice.mjs +377 -18
  76. package/src/commands/sync.mjs +37 -22
  77. package/src/commands/tests.mjs +5 -2
  78. package/src/commands/undo.mjs +24 -16
  79. package/src/commands/upgrade.mjs +33 -1
  80. package/src/commands/why.mjs +10 -4
  81. package/src/compare/hooksstate.mjs +23 -1
  82. package/src/compare/learn.mjs +82 -57
  83. package/src/compare/parallel.mjs +50 -0
  84. package/src/compare/row.mjs +26 -1
  85. package/src/completions.mjs +5 -0
  86. package/src/decisions/dir.mjs +84 -0
  87. package/src/decisions/index.mjs +109 -11
  88. package/src/distill/distill.mjs +3 -1
  89. package/src/ecosystem/node-runner.mjs +144 -0
  90. package/src/explain.mjs +18 -6
  91. package/src/graph/load.mjs +38 -19
  92. package/src/hooks/capability.mjs +14 -1
  93. package/src/hooks/dispatcher.mjs +335 -13
  94. package/src/hooks/resolve.mjs +9 -3
  95. package/src/hooks/shim.mjs +12 -7
  96. package/src/identity.mjs +67 -14
  97. package/src/index/extract.mjs +192 -11
  98. package/src/index/persist.mjs +307 -47
  99. package/src/index/store.mjs +263 -60
  100. package/src/index/tests.mjs +6 -35
  101. package/src/journal.mjs +296 -77
  102. package/src/kernel/card.mjs +37 -12
  103. package/src/kernel/checks.mjs +44 -9
  104. package/src/kernel/variants.mjs +27 -16
  105. package/src/lease.mjs +97 -15
  106. package/src/ledger/index.mjs +91 -25
  107. package/src/mcp/resources.mjs +5 -3
  108. package/src/mcp/server.mjs +81 -22
  109. package/src/mcp/tools.mjs +45 -9
  110. package/src/memory/decide.mjs +98 -43
  111. package/src/memory/lessons.mjs +168 -33
  112. package/src/name.mjs +9 -0
  113. package/src/plan/index.mjs +31 -8
  114. package/src/plan/template.mjs +27 -5
  115. package/src/plugins.mjs +6 -2
  116. package/src/prbody.mjs +7 -5
  117. package/src/projection/baselines.mjs +1 -1
  118. package/src/projection/disclosure.mjs +2 -2
  119. package/src/projection/loaders.mjs +41 -1
  120. package/src/projection/lock.mjs +21 -14
  121. package/src/projection/manifest.mjs +69 -19
  122. package/src/projection/markers.mjs +43 -3
  123. package/src/projection/mdc.mjs +34 -7
  124. package/src/projection/project.mjs +162 -18
  125. package/src/projection/rules.mjs +54 -3
  126. package/src/projection/surfaces.mjs +9 -1
  127. package/src/repo-root.mjs +69 -0
  128. package/src/resolve/body.mjs +4 -0
  129. package/src/resolve/fingerprint.mjs +5 -0
  130. package/src/resolve/local.mjs +58 -0
  131. package/src/review/critic.mjs +4 -2
  132. package/src/secrets.mjs +165 -22
  133. package/src/state.mjs +76 -0
  134. package/src/status.mjs +9 -4
  135. package/src/toolwords.mjs +5 -0
  136. package/src/tsconfig.mjs +39 -99
  137. package/templates/plan/tracker.json +1 -1
@@ -1,4 +1,7 @@
1
1
  // `simt lease [<paths>...]`: claim files for one session, or read the claims (R54).
2
+ // `lease release` and `lease renew` end and extend the holder's own claims: the
3
+ // denial tells a blocked session to ask the holder to release the path, so the
4
+ // holder needs a command that does it (review 0003 Q20).
2
5
  //
3
6
  // The claim is the half of ADR-101 a session does by hand: `lease src/a.mjs --session
4
7
  // alpha` records that alpha is working on the path until a TTL expires, the pre-edit
@@ -12,8 +15,16 @@
12
15
  // (the hook fails closed on that same file, so writing over it would erase the very
13
16
  // claims the hook is about to enforce while telling the author it fixed something).
14
17
 
15
- import { EXIT, emit, emitJson, fail, isJson, writeMode } from '../output/index.mjs';
16
- import { DEFAULT_TTL_SECONDS, activeLeases, leasePathFor, readLeases, writeLeases } from '../lease.mjs';
18
+ import { EXIT, emit, emitJson, fail, isJson, note, writeMode } from '../output/index.mjs';
19
+ import {
20
+ DEFAULT_TTL_SECONDS,
21
+ activeLeases,
22
+ canonicalLeasePath,
23
+ readLeases,
24
+ withLeaseLock,
25
+ writeLeases,
26
+ } from '../lease.mjs';
27
+ import { coreIgnoreCase } from '../repo-root.mjs';
17
28
  import { SESSION_ENV } from '../agenthooks/policy.mjs';
18
29
  import { CLI } from '../name.mjs';
19
30
 
@@ -21,6 +32,11 @@ const ISO = (ms) => new Date(ms).toISOString();
21
32
 
22
33
  export async function leaseCommand(args, flags) {
23
34
  const root = flags.root ?? process.cwd();
35
+ const [sub, ...rest] = args;
36
+ // The denial tells a blocked session to ask the holder to release the path,
37
+ // so releasing is a subcommand, not a missing flag (review 0003 Q20).
38
+ if (sub === 'release') return releaseLeases(root, rest, flags);
39
+ if (sub === 'renew') return renewLeases(root, rest, flags);
24
40
 
25
41
  // A session or a TTL with no paths is a claim about nothing; the parser would
26
42
  // otherwise hand back a list the caller never asked to see.
@@ -39,11 +55,17 @@ export async function leaseCommand(args, flags) {
39
55
  if (!Number.isInteger(ttl) || ttl < 1) {
40
56
  return fail(`--ttl must be a positive number of seconds, received ${flags.ttl}`, EXIT.USAGE, `example: run: ${CLI} lease <paths> --ttl 900`);
41
57
  }
58
+ const harness = typeof flags.harness === 'string' && flags.harness !== '' ? flags.harness : null;
42
59
 
43
60
  const wanted = [];
44
61
  const seen = new Set();
62
+ // The claim is stored in the one spelling the hook's comparison will produce:
63
+ // a claim taken as `src/Keep.mjs` and an edit that spells `src/keep.mjs` must
64
+ // be the same claim on a case-insensitive volume, so the stored path is
65
+ // canonical at write time, not at read time.
66
+ const ignoreCase = coreIgnoreCase(root);
45
67
  for (const arg of args) {
46
- const rel = leasePathFor(root, arg);
68
+ const rel = canonicalLeasePath(root, arg, { ignoreCase });
47
69
  if (rel === null) {
48
70
  return fail(`${arg} is not a path inside the repository`, EXIT.USAGE, `leases are repository-relative: run: ${CLI} lease <path> --session ${session}`);
49
71
  }
@@ -53,37 +75,19 @@ export async function leaseCommand(args, flags) {
53
75
  }
54
76
  }
55
77
 
56
- const read = await readLeases(root);
57
- if (read.error !== null) {
58
- return fail(`${read.error}`, EXIT.FAIL, `fix or remove ${read.path}; the pre-edit hook fails closed on it too`);
59
- }
60
- const held = activeLeases(read);
61
- const conflicts = held.filter((l) => seen.has(l.path) && l.session !== session);
62
- if (conflicts.length > 0) {
63
- return fail(
64
- `${conflicts.map((c) => `${c.path} is leased by ${c.session} until ${ISO(c.expiresAt)}`).join('; ')}`,
65
- EXIT.FAIL,
66
- `wait for the TTL or ask the holder to release it; run: ${CLI} lease to see every claim`,
67
- );
68
- }
78
+ // Older claim files hold the pre-canonical spelling, so a stored path is
79
+ // canonicalised before it is compared: a claim written before the resolver
80
+ // existed must still conflict with a claim taken for the same file.
81
+ const keyOf = (l) => canonicalLeasePath(root, l.path, { ignoreCase }) ?? l.path;
82
+ const newClaim = (expiresAt) =>
83
+ wanted.map((path) => ({ path, session, expiresAt, ...(harness === null ? {} : { harness }) }));
69
84
 
70
- const expiresAt = Date.now() + ttl * 1000;
71
- const apply = `run: ${CLI} lease ${wanted.map((p) => JSON.stringify(p)).join(' ')} --session ${session} --yes`;
72
85
  const mode = writeMode(flags);
73
- const mine = wanted.map((path) => ({ path, session, expiresAt }));
74
-
75
86
  if (!mode.apply) {
87
+ const mine = newClaim(Date.now() + ttl * 1000);
88
+ const apply = `run: ${CLI} lease ${wanted.map((p) => JSON.stringify(p)).join(' ')} --session ${session} --yes`;
76
89
  if (isJson(flags)) {
77
- emitJson({
78
- ok: true,
79
- command: 'lease',
80
- root,
81
- dryRun: true,
82
- session,
83
- ttl,
84
- leases: mine,
85
- remedy: apply,
86
- });
90
+ emitJson({ ok: true, command: 'lease', root, dryRun: true, session, ttl, leases: mine, remedy: apply });
87
91
  return EXIT.OK;
88
92
  }
89
93
  const lines = [
@@ -97,10 +101,33 @@ export async function leaseCommand(args, flags) {
97
101
  return EXIT.OK;
98
102
  }
99
103
 
100
- // Keep every other live claim, refresh ours, and let an expired one fall out: the
101
- // write is also the only sweep the file ever gets.
102
- const others = held.filter((l) => !seen.has(l.path));
103
- const path = await writeLeases(root, [...others, ...mine]);
104
+ // The read-modify-write happens under the lock: twelve concurrent claims
105
+ // stored seven before this, because every claimant read the same file and
106
+ // each wrote back only what it had seen (review 0003 Q20).
107
+ const claimed = await withLeaseLock(root, async () => {
108
+ const read = await readLeases(root);
109
+ if (read.error !== null) return { error: read.error, path: read.path };
110
+ const held = activeLeases(read);
111
+ const conflicts = held.filter((l) => seen.has(keyOf(l)) && l.session !== session);
112
+ if (conflicts.length > 0) return { conflicts };
113
+ // Keep every other live claim, refresh ours, and let an expired one fall out:
114
+ // the write is also the only sweep the file ever gets.
115
+ const others = held.filter((l) => !seen.has(keyOf(l)));
116
+ const mine = newClaim(Date.now() + ttl * 1000);
117
+ const path = await writeLeases(root, [...others, ...mine]);
118
+ return { mine, path };
119
+ });
120
+ if (claimed.error) {
121
+ return fail(`${claimed.error}`, EXIT.FAIL, `fix or remove ${claimed.path}; the pre-edit hook fails closed on it too`);
122
+ }
123
+ if (claimed.conflicts) {
124
+ return fail(
125
+ `${claimed.conflicts.map((c) => `${c.path} is leased by ${c.session} until ${ISO(c.expiresAt)}`).join('; ')}`,
126
+ EXIT.FAIL,
127
+ `wait for the TTL or ask the holder to release it (${CLI} lease release <paths> --session ${session}); run: ${CLI} lease to see every claim`,
128
+ );
129
+ }
130
+ const { mine, path } = claimed;
104
131
 
105
132
  if (isJson(flags)) {
106
133
  emitJson({ ok: true, command: 'lease', root, session, ttl, dryRun: false, leases: mine, file: path });
@@ -116,6 +143,147 @@ export async function leaseCommand(args, flags) {
116
143
  return EXIT.OK;
117
144
  }
118
145
 
146
+ /** Resolve release/renew targets to canonical paths, or the usage failure. */
147
+ function resolveTargets(root, args, session, verb) {
148
+ if (args.length === 0) {
149
+ return { error: fail(`lease ${verb} needs paths`, EXIT.USAGE, `run: ${CLI} lease ${verb} <paths> --session <id>`) };
150
+ }
151
+ const ignoreCase = coreIgnoreCase(root);
152
+ const wanted = [];
153
+ const seen = new Set();
154
+ for (const arg of args) {
155
+ const rel = canonicalLeasePath(root, arg, { ignoreCase });
156
+ if (rel === null) {
157
+ return { error: fail(`${arg} is not a path inside the repository`, EXIT.USAGE, `leases are repository-relative`) };
158
+ }
159
+ if (!seen.has(rel)) {
160
+ seen.add(rel);
161
+ wanted.push(rel);
162
+ }
163
+ }
164
+ return { wanted, seen, ignoreCase };
165
+ }
166
+
167
+ function claimSession(flags) {
168
+ const session = String(flags.session ?? process.env[SESSION_ENV] ?? '');
169
+ if (session === '') {
170
+ return { error: fail(`lease needs a session to hold the claim`, EXIT.USAGE, `run: ${CLI} lease <paths> --session <id> (or set ${SESSION_ENV})`) };
171
+ }
172
+ return { session };
173
+ }
174
+
175
+ async function releaseLeases(root, args, flags) {
176
+ const { session, error: sessionError } = claimSession(flags);
177
+ if (sessionError !== undefined) return sessionError;
178
+ const resolved = resolveTargets(root, args, session, 'release');
179
+ if (resolved.error !== undefined) return resolved.error;
180
+ const { wanted, seen, ignoreCase } = resolved;
181
+ const keyOf = (l) => canonicalLeasePath(root, l.path, { ignoreCase }) ?? l.path;
182
+ const mode = writeMode(flags);
183
+
184
+ const released = await withLeaseLock(root, async () => {
185
+ const read = await readLeases(root);
186
+ if (read.error !== null) return { error: read.error, path: read.path };
187
+ const held = activeLeases(read);
188
+ const foreign = held.filter((l) => seen.has(keyOf(l)) && l.session !== session);
189
+ if (foreign.length > 0) {
190
+ return {
191
+ conflicts: foreign.map((c) => `${c.path} is leased by ${c.session} until ${ISO(c.expiresAt)}`).join('; '),
192
+ };
193
+ }
194
+ const dropped = held.filter((l) => seen.has(keyOf(l)));
195
+ if (!mode.apply) return { preview: dropped };
196
+ const kept = held.filter((l) => !seen.has(keyOf(l)));
197
+ const path = await writeLeases(root, kept);
198
+ return { dropped, path };
199
+ });
200
+ if (released.error) {
201
+ return fail(`${released.error}`, EXIT.FAIL, `fix or remove ${released.path}`);
202
+ }
203
+ if (released.conflicts) {
204
+ return fail(`${released.conflicts}`, EXIT.FAIL, `only the holder releases a claim; wait for the TTL or ask ${session} to run: ${CLI} lease release`);
205
+ }
206
+ if (!mode.apply) {
207
+ const lines = [
208
+ `repo ${root}`,
209
+ `session ${session}`,
210
+ ...released.preview.map((l) => `would release ${l.path} (held by ${l.session})`),
211
+ ...(released.preview.length === 0 ? ['(no active claims on those paths)'] : []),
212
+ `apply run: ${CLI} lease release ${wanted.map((p) => JSON.stringify(p)).join(' ')} --session ${session} --yes`,
213
+ ];
214
+ if (isJson(flags)) emitJson({ ok: true, command: 'lease release', root, dryRun: true, session, leases: released.preview });
215
+ else emit(lines.join('\n'), { maxBytes: flags.maxBytes ?? 0 });
216
+ return EXIT.OK;
217
+ }
218
+ for (const l of released.dropped) note(`note released ${l.path} (was held by ${l.session})`);
219
+ if (isJson(flags)) emitJson({ ok: true, command: 'lease release', root, dryRun: false, session, leases: released.dropped });
220
+ else {
221
+ emit(
222
+ [
223
+ `repo ${root}`,
224
+ `session ${session}`,
225
+ ...released.dropped.map((l) => `RELEASED ${l.path}`),
226
+ ...(released.dropped.length === 0 ? ['(no active claims on those paths)'] : []),
227
+ ].join('\n'),
228
+ { maxBytes: flags.maxBytes ?? 0 },
229
+ );
230
+ }
231
+ return EXIT.OK;
232
+ }
233
+
234
+ async function renewLeases(root, args, flags) {
235
+ const { session, error: sessionError } = claimSession(flags);
236
+ if (sessionError !== undefined) return sessionError;
237
+ const resolved = resolveTargets(root, args, session, 'renew');
238
+ if (resolved.error !== undefined) return resolved.error;
239
+ const { wanted, seen, ignoreCase } = resolved;
240
+ const ttl = flags.ttl === undefined ? DEFAULT_TTL_SECONDS : Number(flags.ttl);
241
+ if (!Number.isInteger(ttl) || ttl < 1) {
242
+ return fail(`--ttl must be a positive number of seconds, received ${flags.ttl}`, EXIT.USAGE, `example: run: ${CLI} lease renew <paths> --ttl 900`);
243
+ }
244
+ const keyOf = (l) => canonicalLeasePath(root, l.path, { ignoreCase }) ?? l.path;
245
+ const mode = writeMode(flags);
246
+
247
+ const renewed = await withLeaseLock(root, async () => {
248
+ const read = await readLeases(root);
249
+ if (read.error !== null) return { error: read.error, path: read.path };
250
+ const held = activeLeases(read);
251
+ const foreign = held.filter((l) => seen.has(keyOf(l)) && l.session !== session);
252
+ if (foreign.length > 0) {
253
+ return {
254
+ conflicts: foreign.map((c) => `${c.path} is leased by ${c.session} until ${ISO(c.expiresAt)}`).join('; '),
255
+ };
256
+ }
257
+ const expiresAt = Date.now() + ttl * 1000;
258
+ const mine = held.map((l) => (seen.has(keyOf(l)) ? { ...l, expiresAt } : l));
259
+ const touched = held.filter((l) => seen.has(keyOf(l)));
260
+ if (!mode.apply) return { preview: touched.map((l) => ({ ...l, expiresAt })) };
261
+ const path = await writeLeases(root, mine);
262
+ return { touched: touched.map((l) => ({ ...l, expiresAt })), path };
263
+ });
264
+ if (renewed.error) {
265
+ return fail(`${renewed.error}`, EXIT.FAIL, `fix or remove ${renewed.path}`);
266
+ }
267
+ if (renewed.conflicts) {
268
+ return fail(`${renewed.conflicts}`, EXIT.FAIL, `only the holder renews a claim; run: ${CLI} lease to see every claim`);
269
+ }
270
+ const rows = mode.apply ? renewed.touched : renewed.preview;
271
+ if (isJson(flags)) emitJson({ ok: true, command: 'lease renew', root, dryRun: !mode.apply, session, ttl, leases: rows });
272
+ else {
273
+ emit(
274
+ [
275
+ `repo ${root}`,
276
+ `session ${session}`,
277
+ `ttl ${ttl}s`,
278
+ ...rows.map((l) => `${mode.apply ? 'RENEWED ' : 'would renew '} ${l.path} until ${ISO(l.expiresAt)}`),
279
+ ...(rows.length === 0 ? ['(no active claims on those paths)'] : []),
280
+ ].join('\n'),
281
+ { maxBytes: flags.maxBytes ?? 0 },
282
+ );
283
+ }
284
+ return EXIT.OK;
285
+ }
286
+
119
287
  async function listLeases(root, flags) {
120
288
  const read = await readLeases(root);
121
289
  if (read.error !== null) {
@@ -128,7 +296,7 @@ async function listLeases(root, flags) {
128
296
  }
129
297
  const lines = [
130
298
  `repo ${root}`,
131
- ...held.map((l) => `LEASED ${l.path} ${l.session} until ${ISO(l.expiresAt)}`),
299
+ ...held.map((l) => `LEASED ${l.path} ${l.session}${l.harness ? `/${l.harness}` : ''} until ${ISO(l.expiresAt)}`),
132
300
  ];
133
301
  if (held.length === 0) lines.push(`(no active leases)`);
134
302
  emit(lines.join('\n'), { maxBytes: flags.maxBytes ?? 0 });
@@ -5,6 +5,7 @@ import { resolve } from 'node:path';
5
5
 
6
6
  import { EXIT, emit, emitJson, fail, isJson, note, writeMode } from '../output/index.mjs';
7
7
  import { diffField, emitDiffs } from '../diff.mjs';
8
+ import { commitJournal } from '../journal.mjs';
8
9
  import { CLI } from '../name.mjs';
9
10
  import { parsePathList } from '../argv.mjs';
10
11
  import {
@@ -22,13 +23,15 @@ export async function lessonsListCommand(args, flags) {
22
23
  return fail(`unknown lessons argument ${args[0]}`, EXIT.USAGE, `run: ${CLI} lessons`);
23
24
  }
24
25
  const root = resolve(flags.root ?? process.cwd());
25
- await captureFromLedger(root);
26
- await captureRevertedCommits(root);
27
-
26
+ // Pure: listing must not capture. Capture used to run here, so `list` wrote
27
+ // to the store it was reading and a read-only question had write side
28
+ // effects. Capturing is `lessons capture` now (review 0003 Q36).
28
29
  const [{ candidates, errors }, promoted] = await Promise.all([
29
30
  readLessonCandidates(root),
30
- listPromotedLessons(root),
31
+ listPromotedLessons(root, { includeExpired: true }),
31
32
  ]);
33
+ const live = promoted.filter((l) => !l.expired);
34
+ const expiredCount = promoted.length - live.length;
32
35
 
33
36
  const payload = {
34
37
  ok: errors.length === 0,
@@ -37,9 +40,10 @@ export async function lessonsListCommand(args, flags) {
37
40
  ledgerFile: LESSONS_FILE,
38
41
  lessonsDir: LESSONS_DIR,
39
42
  candidateCount: candidates.length,
40
- promotedCount: promoted.length,
43
+ promotedCount: live.length,
44
+ expiredCount,
41
45
  candidates,
42
- promoted,
46
+ promoted: live,
43
47
  errors,
44
48
  };
45
49
 
@@ -50,7 +54,7 @@ export async function lessonsListCommand(args, flags) {
50
54
 
51
55
  const lines = [
52
56
  `candidates ${candidates.length} (${LESSONS_FILE})`,
53
- `promoted ${promoted.length} (${LESSONS_DIR})`,
57
+ `promoted ${live.length} (${LESSONS_DIR})${expiredCount > 0 ? `, ${expiredCount} expired` : ''}`,
54
58
  ];
55
59
 
56
60
  if (candidates.length > 0) {
@@ -62,12 +66,18 @@ export async function lessonsListCommand(args, flags) {
62
66
  }
63
67
  }
64
68
 
65
- if (promoted.length > 0) {
69
+ if (live.length > 0) {
66
70
  lines.push('', 'LESSONS');
67
- for (const l of promoted) {
71
+ for (const l of live) {
68
72
  lines.push(` ${l.id.padEnd(28)} ${(l.signature ?? 'no-signature').slice(0, 19)} ${l.title}`);
69
73
  }
70
74
  }
75
+ if (expiredCount > 0) {
76
+ lines.push('', `EXPIRED ${expiredCount}`);
77
+ for (const l of promoted.filter((l) => l.expired)) {
78
+ lines.push(` ${l.id.padEnd(28)} expired ${l.expires ?? 'no date'} ${l.title}`);
79
+ }
80
+ }
71
81
 
72
82
  for (const err of errors) lines.push(`error ${err}`);
73
83
 
@@ -75,6 +85,45 @@ export async function lessonsListCommand(args, flags) {
75
85
  return errors.length === 0 ? EXIT.OK : EXIT.FAIL;
76
86
  }
77
87
 
88
+ /**
89
+ * `simt lessons capture` — the explicit write half of the old `list`.
90
+ *
91
+ * Scans the ledger for fail-then-fix sequences and git history for reverts,
92
+ * and appends any new candidates. A command that writes says so in its name;
93
+ * `list` and `review` previews do not (review 0003 Q36).
94
+ */
95
+ export async function lessonsCaptureCommand(args, flags) {
96
+ if (args.length > 0) {
97
+ return fail(`unknown lessons capture argument ${args[0]}`, EXIT.USAGE, `run: ${CLI} lessons capture`);
98
+ }
99
+ const root = resolve(flags.root ?? process.cwd());
100
+ const fromLedger = await captureFromLedger(root);
101
+ const reverts = await captureRevertedCommits(root);
102
+
103
+ const payload = {
104
+ ok: true,
105
+ command: 'lessons capture',
106
+ root,
107
+ failThenFix: fromLedger.length,
108
+ reverts: reverts.length,
109
+ captured: [...fromLedger, ...reverts],
110
+ };
111
+ if (isJson(flags)) {
112
+ emitJson(payload, { pretty: flags.pretty === true, maxBytes: flags.maxBytes ?? 0 });
113
+ return EXIT.OK;
114
+ }
115
+ const lines = [
116
+ `captured ${payload.captured.length} candidates (${LESSONS_FILE})`,
117
+ ` fail-then-fix ${fromLedger.length}`,
118
+ ` reverts ${reverts.length}`,
119
+ ];
120
+ for (const c of payload.captured) {
121
+ lines.push(` ${c.id} ${c.kind} ${c.summary}`);
122
+ }
123
+ emit(lines.join('\n'), { maxBytes: flags.maxBytes ?? 0 });
124
+ return EXIT.OK;
125
+ }
126
+
78
127
  export async function lessonsReviewCommand(args, flags) {
79
128
  if (args.length > 1) {
80
129
  return fail(`unknown lessons review argument ${args[1]}`, EXIT.USAGE, `run: ${CLI} lessons review [<id>] [--yes]`);
@@ -84,13 +133,20 @@ export async function lessonsReviewCommand(args, flags) {
84
133
  const parsedPaths = parsePathList(flags.paths);
85
134
  const paths = parsedPaths.length > 0 ? parsedPaths : undefined;
86
135
  const title = flags.task ? String(flags.task) : undefined;
136
+ const expires = typeof flags.expires === 'string' && flags.expires.trim() !== '' ? flags.expires.trim() : undefined;
87
137
 
138
+ // Journaled so `undo` restores the promoted file (R49); committed only when
139
+ // the run actually wrote, which commitJournal already guarantees.
140
+ const journal = [];
88
141
  const result = await promoteLesson(root, {
89
142
  id: args[0],
90
143
  apply: mode.apply,
91
144
  paths,
92
145
  title,
146
+ expires,
147
+ journal: mode.apply ? journal : undefined,
93
148
  });
149
+ if (mode.apply && result.ok) await commitJournal(root, 'lessons review', journal);
94
150
 
95
151
  if (!result.ok) {
96
152
  return fail(result.error, EXIT.FAIL, `record a session failure-then-fix or run: ${CLI} lessons`);
@@ -1,11 +1,13 @@
1
1
  // `simt map` ranks the files a task is most likely to touch (R22, ADR-091).
2
- // The cache is read, and rebuilt once when it is empty, because a map of no
3
- // files is not an answer. The rebuild writes the gitignored index, which is
4
- // the same cache `simt index` writes.
2
+ // The cache is refreshed from the git index on every read: `reindex` skips unchanged
3
+ // blobs, so a current repository pays for one `git ls-files -s`, not a walk of the
4
+ // tree. A map of stale files is a wrong answer, and the commands that read with
5
+ // `build` on are ones a person typed at a terminal, where a few hundred
6
+ // milliseconds is not a bar to meet.
5
7
 
6
8
  import { EXIT, emit, emitJson, fail, isJson } from '../output/index.mjs';
7
9
  import { CLI } from '../name.mjs';
8
- import { readEdges, readEmbeddings, readFiles, readFts, readSymbols, reindex, searchFtsBm25 } from '../index/store.mjs';
10
+ import { isIndexStale, readEdges, readEmbeddings, readFiles, readFts, readSymbols, reindex, searchFtsBm25 } from '../index/store.mjs';
9
11
  import {
10
12
  DEFAULT_BUDGET,
11
13
  embedTaskQuery,
@@ -89,20 +91,22 @@ async function recall(root, flags) {
89
91
  }
90
92
 
91
93
  /**
92
- * The files, symbols, edges, FTS rows and stored vector embeddings the index holds,
93
- * building the index once when it is empty.
94
+ * The files, symbols, edges, FTS rows and stored vector embeddings the index holds.
94
95
  *
95
- * `build: false` refuses that rebuild and answers with `cold: true` instead. The one
96
- * caller that passes it is the prompt-submit hook (R29), and the reason is the bar that
97
- * hook has to meet: a delivered packet that built an index would make a person's first
98
- * prompt in a fresh clone wait on a walk of the whole repository, and a prompt that takes
99
- * a minute to appear is how a hook gets uninstalled. The next prompt gets the packet, and
100
- * a command a person typed at a terminal always builds what it needs.
96
+ * With `build` (the default) the index is refreshed from the git index before it is
97
+ * read. The refresh is incremental — a blob that has not changed is not re-read — so
98
+ * the cost of a current repository is one `git ls-files -s`, not a walk of the tree.
99
+ * The callers that build are commands a person typed: `map`, `brief`, `slice`.
100
+ *
101
+ * `build: false` refuses the refresh and answers with `cold: true` when the index is
102
+ * empty. The callers that pass it are the prompt-submit hook (R29) and the MCP
103
+ * surface: a delivered packet that walked the whole repository would make a person's
104
+ * first prompt in a fresh clone wait, and a prompt that takes a minute to appear is
105
+ * how a hook gets uninstalled. The next prompt gets the packet, and a command a
106
+ * person typed at a terminal always builds what it needs.
101
107
  */
102
108
  export async function loadGraph(root, { build = true } = {}) {
103
- let files = await readFiles(root);
104
- if (files.length === 0) {
105
- if (!build) return { files: [], symbols: [], edges: [], fts: [], embeddings: [], cold: true };
109
+ if (build) {
106
110
  try {
107
111
  await reindex(root);
108
112
  } catch (error) {
@@ -114,13 +118,24 @@ export async function loadGraph(root, { build = true } = {}) {
114
118
  ),
115
119
  };
116
120
  }
117
- files = await readFiles(root);
118
121
  }
119
- const [symbols, edges, fts, embeddings] = await Promise.all([
122
+ const [files, symbols, edges, fts, embeddings] = await Promise.all([
123
+ readFiles(root),
120
124
  readSymbols(root),
121
125
  readEdges(root),
122
126
  readFts(root),
123
127
  readEmbeddings(root),
124
128
  ]);
125
- return { files, symbols, edges, fts, embeddings };
129
+ // A present index that cannot be read is named, not served as empty
130
+ // (review 0003 Q44): `cold` is "nothing here", `broken` is "something is
131
+ // here and the read failed".
132
+ const broken = !build && Boolean(files.error);
133
+ if (!build && files.length === 0) {
134
+ return { files: [], symbols: [], edges: [], fts: [], embeddings: [], cold: true, broken, stale: false };
135
+ }
136
+ // A caller that may not build still learns the index is old (review 0003
137
+ // Q42): the digest compare costs one `git ls-files -s`, and the freshness
138
+ // signal is what lets a UI distrust the packet instead of quoting it.
139
+ const stale = !build && files.length > 0 && (await isIndexStale(root));
140
+ return { files, symbols, edges, fts, embeddings, stale, broken };
126
141
  }
@@ -1,4 +1,4 @@
1
- // simt plugin <claude|gemini|cursor> --out <dir> [--yes]
1
+ // simt plugin <claude|gemini|cursor|opencode> --out <dir> [--yes]
2
2
  //
3
3
  // Build one harness package from the same tables `agent-hooks install` writes into a
4
4
  // repository, so a package and a repository install cannot drift apart. A dry run prints
@@ -39,6 +39,7 @@ export async function indexCommand(args, flags) {
39
39
  `files ${result.files}`,
40
40
  `updated ${result.updated}`,
41
41
  `removed ${result.removed}`,
42
+ `skipped ${result.skipped ?? 0}`,
42
43
  `symbols ${result.symbols}`,
43
44
  `edges ${result.edges}`,
44
45
  `ms ${result.ms}`,