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.
- package/CHANGELOG.md +35 -0
- package/README.md +2 -2
- package/agents/simt-agent.md +84 -0
- package/docs/decisions/ADR-009-skill-layout.md +1 -1
- package/docs/decisions/ADR-086-the-stable-prefix-comes-first-and-the-lock-records-both-digests.md +1 -1
- package/docs/decisions/ADR-106-the-harness-hook-runs-through-a-repo-shim.md +46 -0
- package/docs/decisions/ADR-107-an-install-can-name-one-harness-and-the-skipped-ones-are-named.md +51 -0
- package/docs/decisions/ADR-108-an-adoption-builds-the-index-and-a-command-refreshes-it-on-read.md +59 -0
- 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
- 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
- package/docs/decisions/ADR-111-the-tool-ships-one-agent-rendered-per-harness-and-installs-it-with-init-and-a-command.md +75 -0
- package/docs/decisions/ADR-112-the-registry-is-what-simt-dev-ships-and-a-repo-owns-its-own-skills.md +81 -0
- package/docs/decisions/ADR-113-a-pre-push-that-carries-only-documentation-skips-the-test-gate-and-says-so.md +87 -0
- 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
- 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
- package/docs/decisions/ADR-116-rust-support-reaches-the-example-path-the-indent-and-the-bench-runner.md +100 -0
- package/docs/decisions/README.md +9 -0
- package/package.json +4 -2
- package/rules/core.md +2 -2
- package/rules/mdc/test-gate.mdc +2 -0
- package/rules/stacks/android.md +3 -3
- package/rules/stacks/connectiq.md +2 -2
- package/rules/stacks/dart.md +1 -1
- package/rules/stacks/deno.md +1 -1
- package/rules/stacks/dotnet.md +1 -1
- package/rules/stacks/elixir.md +1 -1
- package/rules/stacks/go.md +1 -1
- package/rules/stacks/jvm.md +3 -2
- package/rules/stacks/node.md +2 -2
- package/rules/stacks/python.md +7 -6
- package/rules/stacks/ruby.md +1 -1
- package/rules/stacks/rust.md +1 -1
- package/rules/stacks/swift.md +1 -1
- package/rules/stacks/typescript.md +2 -2
- package/rules/stacks/uv.md +3 -2
- package/skills/simt-commands/SKILL.md +70 -0
- package/src/advice/advice.mjs +7 -3
- package/src/agenthooks/decide.mjs +141 -9
- package/src/agenthooks/opencode.mjs +72 -0
- package/src/agenthooks/prompt.mjs +6 -2
- package/src/agenthooks/render.mjs +186 -19
- package/src/agenthooks/shim.mjs +55 -0
- package/src/agents/render.mjs +277 -0
- package/src/argv.mjs +8 -0
- package/src/bench/ablate.mjs +31 -14
- package/src/bench/mine.mjs +48 -1
- package/src/bench/probes.mjs +5 -6
- package/src/bench/report.mjs +243 -80
- package/src/bench/run.mjs +12 -11
- package/src/bench/variants.mjs +112 -40
- package/src/brief/assemble.mjs +6 -0
- package/src/ci/workflow.mjs +16 -7
- package/src/commands/agent.mjs +206 -0
- package/src/commands/agenthook.mjs +109 -15
- package/src/commands/bench.mjs +2 -1
- package/src/commands/compare.mjs +8 -7
- package/src/commands/decide.mjs +6 -5
- package/src/commands/evidence.mjs +13 -3
- package/src/commands/gate.mjs +85 -19
- package/src/commands/graph.mjs +18 -5
- package/src/commands/help.mjs +35 -14
- package/src/commands/hooks.mjs +68 -25
- package/src/commands/impact.mjs +4 -2
- package/src/commands/index.mjs +17 -4
- package/src/commands/init.mjs +169 -37
- package/src/commands/lease.mjs +203 -35
- package/src/commands/lessons.mjs +65 -9
- package/src/commands/map.mjs +33 -18
- package/src/commands/plugin.mjs +1 -1
- package/src/commands/repoindex.mjs +1 -0
- package/src/commands/rules.mjs +92 -18
- package/src/commands/skills.mjs +60 -25
- package/src/commands/skillscompile.mjs +8 -7
- package/src/commands/skillsinstall.mjs +12 -0
- package/src/commands/slice.mjs +377 -18
- package/src/commands/sync.mjs +37 -22
- package/src/commands/tests.mjs +5 -2
- package/src/commands/undo.mjs +24 -16
- package/src/commands/upgrade.mjs +33 -1
- package/src/commands/why.mjs +10 -4
- package/src/compare/hooksstate.mjs +23 -1
- package/src/compare/learn.mjs +82 -57
- package/src/compare/parallel.mjs +50 -0
- package/src/compare/row.mjs +26 -1
- package/src/completions.mjs +5 -0
- package/src/decisions/dir.mjs +84 -0
- package/src/decisions/index.mjs +109 -11
- package/src/distill/distill.mjs +3 -1
- package/src/ecosystem/node-runner.mjs +144 -0
- package/src/explain.mjs +18 -6
- package/src/graph/load.mjs +38 -19
- package/src/hooks/capability.mjs +14 -1
- package/src/hooks/dispatcher.mjs +335 -13
- package/src/hooks/resolve.mjs +9 -3
- package/src/hooks/shim.mjs +12 -7
- package/src/identity.mjs +67 -14
- package/src/index/extract.mjs +192 -11
- package/src/index/persist.mjs +307 -47
- package/src/index/store.mjs +263 -60
- package/src/index/tests.mjs +6 -35
- package/src/journal.mjs +296 -77
- package/src/kernel/card.mjs +37 -12
- package/src/kernel/checks.mjs +44 -9
- package/src/kernel/variants.mjs +27 -16
- package/src/lease.mjs +97 -15
- package/src/ledger/index.mjs +91 -25
- package/src/mcp/resources.mjs +5 -3
- package/src/mcp/server.mjs +81 -22
- package/src/mcp/tools.mjs +45 -9
- package/src/memory/decide.mjs +98 -43
- package/src/memory/lessons.mjs +168 -33
- package/src/name.mjs +9 -0
- package/src/plan/index.mjs +31 -8
- package/src/plan/template.mjs +27 -5
- package/src/plugins.mjs +6 -2
- package/src/prbody.mjs +7 -5
- package/src/projection/baselines.mjs +1 -1
- package/src/projection/disclosure.mjs +2 -2
- package/src/projection/loaders.mjs +41 -1
- package/src/projection/lock.mjs +21 -14
- package/src/projection/manifest.mjs +69 -19
- package/src/projection/markers.mjs +43 -3
- package/src/projection/mdc.mjs +34 -7
- package/src/projection/project.mjs +162 -18
- package/src/projection/rules.mjs +54 -3
- package/src/projection/surfaces.mjs +9 -1
- package/src/repo-root.mjs +69 -0
- package/src/resolve/body.mjs +4 -0
- package/src/resolve/fingerprint.mjs +5 -0
- package/src/resolve/local.mjs +58 -0
- package/src/review/critic.mjs +4 -2
- package/src/secrets.mjs +165 -22
- package/src/state.mjs +76 -0
- package/src/status.mjs +9 -4
- package/src/toolwords.mjs +5 -0
- package/src/tsconfig.mjs +39 -99
- package/templates/plan/tracker.json +1 -1
package/src/commands/lease.mjs
CHANGED
|
@@ -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 {
|
|
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 =
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
const
|
|
61
|
-
|
|
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
|
-
//
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
const
|
|
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 });
|
package/src/commands/lessons.mjs
CHANGED
|
@@ -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
|
-
|
|
26
|
-
|
|
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:
|
|
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 ${
|
|
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 (
|
|
69
|
+
if (live.length > 0) {
|
|
66
70
|
lines.push('', 'LESSONS');
|
|
67
|
-
for (const l of
|
|
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`);
|
package/src/commands/map.mjs
CHANGED
|
@@ -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
|
|
3
|
-
//
|
|
4
|
-
// the
|
|
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
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/commands/plugin.mjs
CHANGED
|
@@ -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
|