simt-dev 0.3.0 → 0.4.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 +172 -0
- package/README.md +138 -74
- package/docs/decisions/ADR-073-a-kernel-is-a-smaller-projection-the-repository-asks-for.md +1 -1
- package/docs/decisions/ADR-077-the-command-card-leads-the-region-and-reads-committed-evidence.md +1 -1
- package/docs/decisions/ADR-083-a-budget-is-met-by-cutting-the-kernel-and-hard-is-the-floor.md +153 -0
- package/docs/decisions/ADR-084-a-workspace-carries-its-repeated-rules-once.md +100 -0
- package/docs/decisions/ADR-085-the-region-ends-with-the-names-it-kept-out.md +72 -0
- package/docs/decisions/ADR-086-the-stable-prefix-comes-first-and-the-lock-records-both-digests.md +69 -0
- package/docs/decisions/ADR-087-a-run-is-evidence-for-one-tree.md +67 -0
- package/docs/decisions/ADR-088-a-marked-line-is-enforced-by-a-checker.md +59 -0
- package/docs/decisions/ADR-089-the-local-index-is-a-cache-of-git-blobs.md +52 -0
- package/docs/decisions/ADR-090-an-optional-adapter-is-off-until-named.md +55 -0
- package/docs/decisions/ADR-091-the-map-ranks-files-a-task-mentions.md +60 -0
- package/docs/decisions/ADR-092-tests-are-imports-conventions-and-coverage.md +60 -0
- package/docs/decisions/ADR-093-why-names-what-governs-a-file.md +58 -0
- package/docs/decisions/ADR-094-a-change-runs-the-tests-that-import-it.md +44 -0
- package/docs/decisions/ADR-095-gate-output-keeps-the-failures.md +31 -0
- package/docs/decisions/ADR-096-impact-names-who-a-change-reaches.md +38 -0
- package/package.json +2 -2
- package/rules/core.md +2 -2
- package/src/agenthooks/policy.mjs +10 -2
- package/src/agenthooks/prompt.mjs +81 -0
- package/src/agenthooks/render.mjs +138 -17
- package/src/argv.mjs +34 -1
- package/src/bench/grade.mjs +3 -0
- package/src/bench/run.mjs +85 -39
- package/src/bench/variants.mjs +456 -0
- package/src/brief/assemble.mjs +346 -0
- package/src/brief/kind.mjs +134 -0
- package/src/brief/packet.mjs +197 -0
- package/src/ci/workflow.mjs +11 -1
- package/src/commands/agenthook.mjs +84 -5
- package/src/commands/bench.mjs +53 -16
- package/src/commands/brief.mjs +78 -0
- package/src/commands/compare.mjs +10 -2
- package/src/commands/decide.mjs +116 -0
- package/src/commands/evidence.mjs +96 -0
- package/src/commands/gate.mjs +165 -0
- package/src/commands/help.mjs +65 -3
- package/src/commands/hooks.mjs +45 -5
- package/src/commands/impact.mjs +205 -0
- package/src/commands/index.mjs +52 -1
- package/src/commands/lessons.mjs +127 -0
- package/src/commands/local.mjs +97 -0
- package/src/commands/map.mjs +126 -0
- package/src/commands/repoindex.mjs +55 -0
- package/src/commands/rules.mjs +17 -2
- package/src/commands/shared.mjs +398 -0
- package/src/commands/skills.mjs +3 -17
- package/src/commands/skillscompile.mjs +255 -0
- package/src/commands/sync.mjs +87 -3
- package/src/commands/tests.mjs +145 -0
- package/src/commands/tokens.mjs +30 -1
- package/src/commands/why.mjs +172 -0
- package/src/compare/learn.mjs +680 -0
- package/src/decisions/index.mjs +116 -65
- package/src/federation/client.mjs +188 -0
- package/src/federation/config.mjs +134 -0
- package/src/federation/query.mjs +48 -0
- package/src/graph/compile.mjs +475 -0
- package/src/graph/spec.mjs +1 -1
- package/src/hooks/dispatcher.mjs +15 -0
- package/src/hooks/shim.mjs +31 -0
- package/src/index/compact.mjs +228 -0
- package/src/index/extract.mjs +331 -0
- package/src/index/gate.mjs +89 -0
- package/src/index/govern.mjs +234 -0
- package/src/index/impact.mjs +186 -0
- package/src/index/map.mjs +627 -0
- package/src/index/persist.mjs +239 -0
- package/src/index/store.mjs +515 -0
- package/src/index/tests.mjs +294 -0
- package/src/kernel/budget.mjs +100 -0
- package/src/kernel/checks.mjs +378 -0
- package/src/kernel/variants.mjs +353 -0
- package/src/ledger/index.mjs +147 -0
- package/src/local/client.mjs +482 -0
- package/src/local/config.mjs +234 -0
- package/src/mcp/tools.mjs +138 -1
- package/src/measure/context.mjs +7 -5
- package/src/memory/decide.mjs +462 -0
- package/src/memory/lessons.mjs +858 -0
- package/src/projection/disclosure.mjs +92 -0
- package/src/projection/lock.mjs +125 -0
- package/src/projection/manifest.mjs +52 -0
- package/src/projection/markers.mjs +56 -17
- package/src/projection/project.mjs +24 -17
- package/src/projection/rules.mjs +407 -49
- package/src/projection/shared.mjs +428 -0
- package/src/projection/targets.mjs +2 -1
- package/src/toolwords.mjs +8 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# ADR-094 — a change runs the tests that import it
|
|
2
|
+
|
|
3
|
+
Status: **accepted** · 2026-10-18 · filed as R16 (plan 0003)
|
|
4
|
+
|
|
5
|
+
**Affects:** `src/index/gate.mjs`, `src/commands/gate.mjs`, `test/gate.test.mjs`
|
|
6
|
+
|
|
7
|
+
## Context
|
|
8
|
+
|
|
9
|
+
A gate that always runs the whole suite teaches people to skip it. The tests
|
|
10
|
+
that can see a change are the ones that import it, including through another
|
|
11
|
+
file. A name that looks like a test, and a commit that also touched a test,
|
|
12
|
+
are different facts. They are already answered by `simt tests`.
|
|
13
|
+
|
|
14
|
+
The pre-commit hook, the stop hook and an agent call this command. They do
|
|
15
|
+
not need the dispatcher rewritten to do it.
|
|
16
|
+
|
|
17
|
+
## Rulings
|
|
18
|
+
|
|
19
|
+
1. **Selection is the import closure.** A test file is selected when an import
|
|
20
|
+
reaches a changed file, at any depth. A changed file that is itself a test
|
|
21
|
+
is selected. A cycle is walked once. A conventional neighbour and a shared
|
|
22
|
+
commit are not imports, so they are not a selection. A file the test-path
|
|
23
|
+
rule already treats as a test counts, including a helper that lives beside
|
|
24
|
+
the tests and imports the change.
|
|
25
|
+
2. **The command is `simt gate`.** Paths name the change. `--changed` reads
|
|
26
|
+
the diff, staged, unstaged and untracked. No path and no `--changed` is a
|
|
27
|
+
usage error. A clean diff selects nothing and runs nothing. A repository
|
|
28
|
+
that is not git is unsupported.
|
|
29
|
+
3. **The run is the package's own runner, and only the selected files.** Tests
|
|
30
|
+
are grouped by the package that contains them. The runner is the one that
|
|
31
|
+
package already declares. A package with no runner is unsupported. The
|
|
32
|
+
child's test-runner environment is cleared, so a parent test process cannot
|
|
33
|
+
take the child's result and report a pass.
|
|
34
|
+
4. **The hand list for the plan's named file is 51 files, and the selection
|
|
35
|
+
finished in under 5 seconds.** Eight other test files do not import it, and
|
|
36
|
+
they are not selected. The set is wide because the shared fixture imports
|
|
37
|
+
the loader that imports that file. Measured at about 40 ms.
|
|
38
|
+
|
|
39
|
+
## Consequences
|
|
40
|
+
|
|
41
|
+
`simt tests` still answers "which tests exercise this file", including a
|
|
42
|
+
conventional name and, when asked, a shared commit. `simt gate` answers "run
|
|
43
|
+
the tests this change can reach". Compaction of the runner's text is a later
|
|
44
|
+
slice. The dispatcher is unchanged.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# ADR-095 — gate output keeps the failures
|
|
2
|
+
|
|
3
|
+
Status: **accepted** · 2026-10-18 · filed as R18 (plan 0003)
|
|
4
|
+
|
|
5
|
+
**Affects:** `src/index/compact.mjs`, `src/commands/gate.mjs`, `test/compact.test.mjs`
|
|
6
|
+
|
|
7
|
+
## Context
|
|
8
|
+
|
|
9
|
+
A gate that prints every passing test spends the reader's attention on the
|
|
10
|
+
lines that did not fail. A summary that drops a failure is worse: the run
|
|
11
|
+
looks cleaner than it was. The formats this tool's own runners emit are
|
|
12
|
+
known. An arbitrary shell log is not one of them, and guessing at it is how
|
|
13
|
+
a line gets lost.
|
|
14
|
+
|
|
15
|
+
## Rulings
|
|
16
|
+
|
|
17
|
+
1. **Compaction applies to a report this tool produced, and only to a format
|
|
18
|
+
it can read.** Those formats are TAP, JUnit XML, vitest or jest JSON, and
|
|
19
|
+
`go test -json`. Pytest's junit file is JUnit XML. A stream that is none
|
|
20
|
+
of these is printed unchanged.
|
|
21
|
+
2. **Failures come first, and each one is kept.** The name, the assertion
|
|
22
|
+
and the location stay in the printed block. Passing tests become a count.
|
|
23
|
+
A skip becomes a count when there is one.
|
|
24
|
+
3. **The raw log path is printed.** The log is gitignored. The command does
|
|
25
|
+
not wrap an arbitrary shell command. The gate is the caller.
|
|
26
|
+
|
|
27
|
+
## Consequences
|
|
28
|
+
|
|
29
|
+
`simt gate` is the command that compacts. Another command that wants the same
|
|
30
|
+
treatment calls the same function. A format that is not in the list stays
|
|
31
|
+
raw until it is added with a golden fixture.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# ADR-096 — impact names who a change reaches
|
|
2
|
+
|
|
3
|
+
Status: **accepted** · 2026-10-18 · filed as R23 (plan 0003)
|
|
4
|
+
|
|
5
|
+
**Affects:** `src/index/impact.mjs`, `src/commands/impact.mjs`, `test/impact.test.mjs`
|
|
6
|
+
|
|
7
|
+
## Context
|
|
8
|
+
|
|
9
|
+
A change has a neighbourhood: the files that import it, the tests of that
|
|
10
|
+
neighbourhood, the decisions and rules that govern the file, and the owner a
|
|
11
|
+
CODEOWNERS line names. In a workspace the neighbourhood crosses a repository
|
|
12
|
+
when another one references a contract this change touches. That is the check
|
|
13
|
+
behind "the producer ships before the consumer".
|
|
14
|
+
|
|
15
|
+
## Rulings
|
|
16
|
+
|
|
17
|
+
1. **The argument is a tracked path, or the name of one export.** A private
|
|
18
|
+
symbol is not an export. Several files exporting the same name is a usage
|
|
19
|
+
error that names those files. A name that is neither a path nor an export
|
|
20
|
+
is a usage error. A tree that is not git is unsupported.
|
|
21
|
+
2. **Importers are the non-test files that import the target, at any depth.**
|
|
22
|
+
The tests are the test files that import that closure. Both lists stop at
|
|
23
|
+
64. Past that, the report says it was truncated.
|
|
24
|
+
3. **Governance is what `why` would name for the file, limited to decisions
|
|
25
|
+
and rules.** Owners are the last matching pattern in the first CODEOWNERS
|
|
26
|
+
file that exists. A pattern with no slash matches the file name in any
|
|
27
|
+
directory.
|
|
28
|
+
4. **A cross-repo consumer is another repository whose text contains a
|
|
29
|
+
contract path this change touches.** A contract is an OpenAPI document or
|
|
30
|
+
a JSON Schema file. The path has to include a directory. No workspace
|
|
31
|
+
means no consumers, and that is not a failure. The scan stops at 64
|
|
32
|
+
references and 2000 files in a repository.
|
|
33
|
+
|
|
34
|
+
## Consequences
|
|
35
|
+
|
|
36
|
+
`simt impact` answers who is reached. `simt gate` still runs the tests.
|
|
37
|
+
`simt why` still answers governance on its own, including skills, gates and
|
|
38
|
+
lessons, which this report does not repeat.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simt-dev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Shared agent rules, skills and git hooks for a repository: one command adopts a repo, and every gate it declares is probed before it is written.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Said Elimam",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"skills"
|
|
38
38
|
],
|
|
39
39
|
"scripts": {
|
|
40
|
-
"test": "node --test test/*.test.mjs",
|
|
40
|
+
"test": "node --test --test-concurrency=4 test/*.test.mjs",
|
|
41
41
|
"lint": "node bin/simt-dev.mjs doctor"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/rules/core.md
CHANGED
|
@@ -7,7 +7,7 @@ simt-priority: hard
|
|
|
7
7
|
|
|
8
8
|
# Shared rules
|
|
9
9
|
|
|
10
|
-
Where a rule cites a decision, run `simt
|
|
10
|
+
Where a rule cites a decision, run `simt rules why ADR-NNN` to read it,
|
|
11
11
|
including whether it is still in force.
|
|
12
12
|
|
|
13
13
|
These rules are stack-agnostic. Whatever is specific to your stack, your product or your
|
|
@@ -60,7 +60,7 @@ commands belongs in this repository, not here.
|
|
|
60
60
|
|
|
61
61
|
- No type-system escapes, no unawaited async work, no debug printing in application code.
|
|
62
62
|
- 400 lines is a review trigger; 1000 lines is a hard ceiling. Generated files are exempt
|
|
63
|
-
when the hook names the generator. (ADR-005)
|
|
63
|
+
when the hook names the generator. (ADR-005) <!-- simt-check: max-file-lines -->
|
|
64
64
|
- Never weaken CSP, CORS, auth, audit, cache or validation controls to silence a test, warning
|
|
65
65
|
or alert.
|
|
66
66
|
- Review verdicts are exactly three: `BLOCK`, `APPROVE WITH RESIDUAL RISK` (must list what was
|
|
@@ -21,8 +21,16 @@
|
|
|
21
21
|
|
|
22
22
|
import { CLI } from '../name.mjs';
|
|
23
23
|
|
|
24
|
-
/**
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The events an agent-time hook can answer, normalised across harnesses.
|
|
26
|
+
*
|
|
27
|
+
* `pre-tool-use` is a decision: a payload in, a deny or nothing out, and exit 2 means
|
|
28
|
+
* block. `prompt-submit` is a delivery: the same payload shape in, context out, and it
|
|
29
|
+
* never denies anything — a hook that could stop a person's prompt would be a hook whose
|
|
30
|
+
* own bug is a person who cannot type (R29). `post-tool-use` recalls a lesson as one
|
|
31
|
+
* paragraph when a tool call fails with a signature matching `docs/lessons/*.md` (R33).
|
|
32
|
+
*/
|
|
33
|
+
export const EVENTS = ['pre-tool-use', 'prompt-submit', 'post-tool-use'];
|
|
26
34
|
|
|
27
35
|
/** The environment variable that lifts named policies for one session. */
|
|
28
36
|
export const ALLOW_ENV = 'SIMT_ALLOW';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// The prompt-submit surface: the packet delivered where the agent will read it.
|
|
2
|
+
//
|
|
3
|
+
// This module must stay off the tool-call path, and the code's shape is what keeps it
|
|
4
|
+
// there: `src/commands/agenthook.mjs` reaches it through a dynamic `import()` that only a
|
|
5
|
+
// prompt event takes. The pre-tool hook is a latency promise — it answers before every
|
|
6
|
+
// shell command an agent runs — so it imports the policy table, the decision and the
|
|
7
|
+
// renderer and nothing that walks the repository, and `test/agenthooks.test.mjs` asserts
|
|
8
|
+
// exactly that set. A delivery, by contrast, is the one thing here that must read the
|
|
9
|
+
// repository, so it lives behind a door the pre-tool path never opens.
|
|
10
|
+
//
|
|
11
|
+
// Three rules shape what gets delivered:
|
|
12
|
+
//
|
|
13
|
+
// * The repository opts in. The opt-in is a `brief` key in the repository's manifest,
|
|
14
|
+
// not the presence of a hook in a harness config: a repository that declared nothing
|
|
15
|
+
// is not spending its owner's context on a packet they did not ask for, and the
|
|
16
|
+
// manifest is the one file a person reviews before they commit the change.
|
|
17
|
+
// * The packet is capped, at PROMPT_CAP_BYTES. A packet is delivered into a prompt that
|
|
18
|
+
// already exists, and the ceiling is the measured bar of this slice rather than a
|
|
19
|
+
// value a repository is free to raise.
|
|
20
|
+
// * A delivery never blocks and never fails loudly. Everything that could go wrong —
|
|
21
|
+
// no index, no prompt in the payload, a registry that will not load — ends in no
|
|
22
|
+
// injection and a line on stderr. A hook that stopped a person's prompt because this
|
|
23
|
+
// tool could not answer would be worse than a hook that said nothing.
|
|
24
|
+
|
|
25
|
+
import { readManifest } from '../projection/manifest.mjs';
|
|
26
|
+
import { DEFAULT_BRIEF_BYTES, PROMPT_CAP_BYTES } from '../brief/packet.mjs';
|
|
27
|
+
import { assembleBrief } from '../brief/assemble.mjs';
|
|
28
|
+
import { deliveryJson, factsFrom, promptText } from './render.mjs';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Whether this repository asked for a delivered packet, and the ceiling it asked for.
|
|
32
|
+
*
|
|
33
|
+
* Presence is the opt-in and the value is a preference, so `"brief": {}` means "yes, at
|
|
34
|
+
* whatever you measured" and `"brief": { "bytes": 900 }` means "yes, and keep it small".
|
|
35
|
+
* A declared zero is not honoured as a ceiling: zero is this tool's word for "no ceiling"
|
|
36
|
+
* on the command line, and a delivered packet that meant "the whole repository" would be
|
|
37
|
+
* the one thing the cap exists to prevent. It is read from the manifest rather than from
|
|
38
|
+
* the harness config because the manifest is the file the repository reviews.
|
|
39
|
+
*/
|
|
40
|
+
export async function promptOptIn(root) {
|
|
41
|
+
const { manifest, exists, error } = await readManifest(root);
|
|
42
|
+
if (!exists || error) {
|
|
43
|
+
return { optedIn: false, bytes: DEFAULT_BRIEF_BYTES, why: `${exists ? error : 'no manifest'}` };
|
|
44
|
+
}
|
|
45
|
+
if (manifest?.brief === undefined || manifest.brief === null) {
|
|
46
|
+
return { optedIn: false, bytes: DEFAULT_BRIEF_BYTES, why: 'no `brief` key in the manifest' };
|
|
47
|
+
}
|
|
48
|
+
const declared = manifest.brief?.bytes;
|
|
49
|
+
const asked = Number.isFinite(declared) && declared > 0 ? declared : PROMPT_CAP_BYTES;
|
|
50
|
+
return { optedIn: true, bytes: Math.min(asked, PROMPT_CAP_BYTES) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The context one prompt-submit call should deliver, or the reason it delivers nothing.
|
|
55
|
+
*
|
|
56
|
+
* `build: false` is the latency promise in one argument: a delivery reports a cold index
|
|
57
|
+
* rather than building one, so the first prompt in a fresh clone gets nothing and the
|
|
58
|
+
* second gets the packet. The alternative — a person watching their first prompt sit for
|
|
59
|
+
* a minute while a repository is walked — is how the hook gets uninstalled, and the
|
|
60
|
+
* packet is not worth a prompt that cannot be typed.
|
|
61
|
+
*/
|
|
62
|
+
export async function deliverPrompt(row, payload) {
|
|
63
|
+
const task = promptText(row, payload);
|
|
64
|
+
if (task === null) return { skipped: 'the payload carries no prompt this harness documents' };
|
|
65
|
+
|
|
66
|
+
// The root is the same dialect fact for both events, so it is read the same way.
|
|
67
|
+
const root = factsFrom(row, payload).root;
|
|
68
|
+
const optIn = await promptOptIn(root);
|
|
69
|
+
if (!optIn.optedIn) return { skipped: optIn.why };
|
|
70
|
+
|
|
71
|
+
// Federation is off on this path and on no other: a delivery has 300 ms to answer, and
|
|
72
|
+
// starting a declared server is a wait a prompt submit must not take. The task is the
|
|
73
|
+
// question a federation would ask, and a person is not made to wait for it here.
|
|
74
|
+
const result = await assembleBrief({ root, task, budget: optIn.bytes, build: false, federate: false });
|
|
75
|
+
if (result.error) return { skipped: 'the packet could not be assembled' };
|
|
76
|
+
if (result.cold) return { skipped: 'the index is empty, and a delivered packet never builds one' };
|
|
77
|
+
|
|
78
|
+
const json = deliveryJson(row, result.packed.text);
|
|
79
|
+
if (json === null) return { skipped: `${row.id} has no prompt event that can inject` };
|
|
80
|
+
return { json, root, bytes: result.packed.after };
|
|
81
|
+
}
|
|
@@ -11,6 +11,26 @@
|
|
|
11
11
|
// cursor .cursor/hooks.json preToolUse {"version":1,"hooks":{E:[h]}}
|
|
12
12
|
// antigravity .agents/hooks.json PreToolUse {"<name>":{E:[{matcher,hooks:[h]}]}}
|
|
13
13
|
//
|
|
14
|
+
// The prompt-submit event (R29) is a second table, and it is shorter because the vendors
|
|
15
|
+
// are: two of the four document a prompt event that can put text into the model's context,
|
|
16
|
+
// and a delivery is the only thing this tool does there. Neither takes a matcher — both
|
|
17
|
+
// document that field for tool events, and a matcher a harness ignores is a matcher the
|
|
18
|
+
// next person believes is filtering something.
|
|
19
|
+
//
|
|
20
|
+
// claude .claude/settings.json UserPromptSubmit hookSpecificOutput.additionalContext
|
|
21
|
+
// codex .codex/hooks.json UserPromptSubmit hookSpecificOutput.additionalContext
|
|
22
|
+
// cursor .cursor/hooks.json beforeSubmitPrompt CANNOT INJECT: block-only
|
|
23
|
+
// antigravity .agents/hooks.json (no prompt event documented)
|
|
24
|
+
//
|
|
25
|
+
// Cursor is the one that would be a mistake to write anyway. Its `beforeSubmitPrompt` hook
|
|
26
|
+
// can only continue or block, so the entry would carry no packet and a broken one would
|
|
27
|
+
// stop a person from typing — and its only injection point, `sessionStart.additional_context`,
|
|
28
|
+
// fires once when the session is created, which is a different lifetime from the brief a
|
|
29
|
+
// task needs. Gemini CLI documents `BeforeAgent`, which does inject, but the product was
|
|
30
|
+
// replaced by Antigravity CLI on 2026-06-18 and its config is not in the reader table this
|
|
31
|
+
// module takes its paths from; a harness this tool did not verify is a harness it does not
|
|
32
|
+
// write to.
|
|
33
|
+
//
|
|
14
34
|
// The paths are not written here. They come from the reader table (R14) because that is
|
|
15
35
|
// where each one was verified against its vendor page, and a second copy of a verified
|
|
16
36
|
// fact is a copy that drifts the first time a vendor moves the file.
|
|
@@ -36,8 +56,8 @@ const TIMEOUT_SECONDS = 10;
|
|
|
36
56
|
* harness's dialect when a payload arrived in an unexpected shape, and the harness would
|
|
37
57
|
* read a decision it does not understand as no decision at all.
|
|
38
58
|
*/
|
|
39
|
-
export function hookCommand(id) {
|
|
40
|
-
return `${CLI} agent-hook ${
|
|
59
|
+
export function hookCommand(id, event = EVENTS[0]) {
|
|
60
|
+
return `${CLI} agent-hook ${event} --harness ${id}`;
|
|
41
61
|
}
|
|
42
62
|
|
|
43
63
|
/** The path a config file lives at, from the reader table rather than a second list. */
|
|
@@ -73,6 +93,20 @@ const ADAPTERS = {
|
|
|
73
93
|
deny: (message) => ({
|
|
74
94
|
hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: message },
|
|
75
95
|
}),
|
|
96
|
+
// The delivery door. `additionalContext` is documented for this event and is
|
|
97
|
+
// wrapped into the conversation at the point the hook fired, which is why the
|
|
98
|
+
// packet goes here rather than into a system prompt: the cached prefix survives.
|
|
99
|
+
prompt: {
|
|
100
|
+
event: 'UserPromptSubmit',
|
|
101
|
+
verified: 'code.claude.com/docs/en/hooks, read 2026-10-19',
|
|
102
|
+
context: (text) => ({ hookSpecificOutput: { hookEventName: 'UserPromptSubmit', additionalContext: text } }),
|
|
103
|
+
},
|
|
104
|
+
post: {
|
|
105
|
+
event: 'PostToolUse',
|
|
106
|
+
matcher: 'Bash',
|
|
107
|
+
verified: 'code.claude.com/docs/en/hooks, read 2026-10-19',
|
|
108
|
+
context: (text) => ({ hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext: text } }),
|
|
109
|
+
},
|
|
76
110
|
},
|
|
77
111
|
codex: {
|
|
78
112
|
id: 'codex',
|
|
@@ -96,6 +130,17 @@ const ADAPTERS = {
|
|
|
96
130
|
deny: (message) => ({
|
|
97
131
|
hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: message },
|
|
98
132
|
}),
|
|
133
|
+
prompt: {
|
|
134
|
+
event: 'UserPromptSubmit',
|
|
135
|
+
verified: 'developers.openai.com/codex/hooks, read 2026-10-19',
|
|
136
|
+
context: (text) => ({ hookSpecificOutput: { hookEventName: 'UserPromptSubmit', additionalContext: text } }),
|
|
137
|
+
},
|
|
138
|
+
post: {
|
|
139
|
+
event: 'PostToolUse',
|
|
140
|
+
matcher: 'Bash',
|
|
141
|
+
verified: 'developers.openai.com/codex/hooks, read 2026-10-19',
|
|
142
|
+
context: (text) => ({ hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext: text } }),
|
|
143
|
+
},
|
|
99
144
|
},
|
|
100
145
|
cursor: {
|
|
101
146
|
id: 'cursor',
|
|
@@ -111,6 +156,11 @@ const ADAPTERS = {
|
|
|
111
156
|
: [],
|
|
112
157
|
}),
|
|
113
158
|
deny: (message) => ({ permission: 'deny', user_message: message, agent_message: message }),
|
|
159
|
+
// beforeSubmitPrompt is documented as continue/block and nothing else, so there is no
|
|
160
|
+
// key to deliver a packet in. Writing the entry anyway would put a command that reads
|
|
161
|
+
// a repository on the path of every prompt a person types, to say nothing.
|
|
162
|
+
prompt: null,
|
|
163
|
+
post: null,
|
|
114
164
|
},
|
|
115
165
|
antigravity: {
|
|
116
166
|
id: 'antigravity',
|
|
@@ -133,6 +183,10 @@ const ADAPTERS = {
|
|
|
133
183
|
};
|
|
134
184
|
},
|
|
135
185
|
deny: (message) => ({ decision: 'deny', reason: message }),
|
|
186
|
+
// No prompt event is documented for this harness's hooks file, and a guessed event
|
|
187
|
+
// name is a hook that never fires while its config says it does.
|
|
188
|
+
prompt: null,
|
|
189
|
+
post: null,
|
|
136
190
|
},
|
|
137
191
|
};
|
|
138
192
|
|
|
@@ -160,6 +214,37 @@ export function decisionJson(row, decision) {
|
|
|
160
214
|
return row.deny(decision.messages.join('\n'));
|
|
161
215
|
}
|
|
162
216
|
|
|
217
|
+
/**
|
|
218
|
+
* The document to print for a delivery, or null when the harness takes none.
|
|
219
|
+
*
|
|
220
|
+
* A delivery is never a decision: nothing here can deny, and the caller exits 0 whatever
|
|
221
|
+
* this returns. That is the whole difference between the two events, and it is why the
|
|
222
|
+
* prompt event has no `denyExit` — there is no exit code that means "here is some context".
|
|
223
|
+
*/
|
|
224
|
+
export function deliveryJson(row, text) {
|
|
225
|
+
return row.prompt ? row.prompt.context(text) : null;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** The document to print for a post-tool lesson recall delivery, or null when the harness takes none. */
|
|
229
|
+
export function postDeliveryJson(row, text) {
|
|
230
|
+
return row.post ? row.post.context(text) : null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* The submitted text a prompt payload carries, or null when it carries none we recognise.
|
|
235
|
+
*
|
|
236
|
+
* Marked inferred rather than documented: both harnesses that take this event place the
|
|
237
|
+
* prompt at the top level, but only in the example on each page, not as a stated contract.
|
|
238
|
+
* An unrecognised payload therefore delivers nothing and says so on stderr. The failure
|
|
239
|
+
* this must not have is the opposite one — a packet delivered as though it answered a task
|
|
240
|
+
* it never saw, which reads as a confident answer about the wrong question.
|
|
241
|
+
*/
|
|
242
|
+
export function promptText(row, payload) {
|
|
243
|
+
if (!row.prompt) return null;
|
|
244
|
+
const text = payload?.prompt ?? payload?.user_prompt ?? payload?.message;
|
|
245
|
+
return typeof text === 'string' && text.trim().length > 0 ? text : null;
|
|
246
|
+
}
|
|
247
|
+
|
|
163
248
|
// ---------------------------------------------------------------------------
|
|
164
249
|
// The config file: reading ours out of somebody else's JSON, and putting it back.
|
|
165
250
|
// ---------------------------------------------------------------------------
|
|
@@ -180,9 +265,36 @@ function container(row, config, { create = false } = {}) {
|
|
|
180
265
|
return config.hooks ?? null;
|
|
181
266
|
}
|
|
182
267
|
|
|
268
|
+
/** The vendor's name for one of our events on this row, or null when it has none. */
|
|
269
|
+
function vendorEvent(row, event) {
|
|
270
|
+
if (event === EVENTS[0]) return row.event;
|
|
271
|
+
if (event === 'prompt-submit') return row.prompt?.event ?? null;
|
|
272
|
+
if (event === 'post-tool-use') return row.post?.event ?? null;
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** The events a row answers, and the name each one goes under in its config file. */
|
|
277
|
+
function eventsOf(row, { prompt = false, post = false } = {}) {
|
|
278
|
+
const pairs = [[EVENTS[0], row.event]];
|
|
279
|
+
if (prompt && row.prompt) pairs.push(['prompt-submit', row.prompt.event]);
|
|
280
|
+
if (post && row.post) pairs.push(['post-tool-use', row.post.event]);
|
|
281
|
+
return pairs;
|
|
282
|
+
}
|
|
283
|
+
|
|
183
284
|
/** The group this tool owns for one event, in that harness's shape. */
|
|
184
|
-
function group(row) {
|
|
185
|
-
const command = hookCommand(row.id);
|
|
285
|
+
function group(row, event = EVENTS[0]) {
|
|
286
|
+
const command = hookCommand(row.id, event);
|
|
287
|
+
if (event === 'prompt-submit') {
|
|
288
|
+
// No matcher: both vendors document that field for tool events, and a matcher a
|
|
289
|
+
// harness ignores is a matcher the next reader believes is filtering something.
|
|
290
|
+
return { hooks: [{ type: 'command', command, timeout: TIMEOUT_SECONDS }] };
|
|
291
|
+
}
|
|
292
|
+
if (event === 'post-tool-use') {
|
|
293
|
+
const matcher = row.post?.matcher;
|
|
294
|
+
return matcher
|
|
295
|
+
? { matcher, hooks: [{ type: 'command', command, timeout: TIMEOUT_SECONDS }] }
|
|
296
|
+
: { hooks: [{ type: 'command', command, timeout: TIMEOUT_SECONDS }] };
|
|
297
|
+
}
|
|
186
298
|
if (row.id === 'cursor') {
|
|
187
299
|
// failClosed is set because a hooks file this tool wrote should not silently
|
|
188
300
|
// degrade to fail-open on its own crash: the vendor's default turns a broken hook
|
|
@@ -197,35 +309,44 @@ function ours(entry) {
|
|
|
197
309
|
return JSON.stringify(entry).includes(`${CLI} agent-hook`);
|
|
198
310
|
}
|
|
199
311
|
|
|
200
|
-
function entries(row, config) {
|
|
201
|
-
const
|
|
202
|
-
|
|
312
|
+
function entries(row, config, event = EVENTS[0]) {
|
|
313
|
+
const name = vendorEvent(row, event);
|
|
314
|
+
if (name === null) return [];
|
|
315
|
+
const list = container(row, config)?.[name];
|
|
203
316
|
return Array.isArray(list) ? list : [];
|
|
204
317
|
}
|
|
205
318
|
|
|
206
|
-
/** Our entries in this document, for `status`; the document is not modified. */
|
|
207
|
-
export function installedIn(row, config) {
|
|
208
|
-
return entries(row, config).filter(ours);
|
|
319
|
+
/** Our entries in this document for one event, for `status`; the document is not modified. */
|
|
320
|
+
export function installedIn(row, config, event = EVENTS[0]) {
|
|
321
|
+
return entries(row, config, event).filter(ours);
|
|
209
322
|
}
|
|
210
323
|
|
|
211
324
|
/**
|
|
212
|
-
* The document with this tool's
|
|
325
|
+
* The document with this tool's hooks added, everything else left alone.
|
|
213
326
|
*
|
|
214
327
|
* Written as JSON with two spaces and a trailing newline because that is what a file in
|
|
215
328
|
* a repository reads like; a config that is rewritten with different indentation on
|
|
216
329
|
* every run is a diff nobody can review. Keys this tool does not own are preserved
|
|
217
330
|
* exactly, including their order, because the file belongs to the repository.
|
|
331
|
+
*
|
|
332
|
+
* One file can carry both events — Claude and Codex each hold a tool hook and a prompt
|
|
333
|
+
* hook in the same document — so this writes one group per event the row answers rather
|
|
334
|
+
* than one group per file. `prompt` is the caller's opt-in: a repository that has not
|
|
335
|
+
* asked for a delivered packet gets the tool hook and nothing extra, and the file it never
|
|
336
|
+
* asked to change is a file this tool does not touch.
|
|
218
337
|
*/
|
|
219
|
-
function withHook(row, config) {
|
|
338
|
+
function withHook(row, config, { prompt = false, post = false } = {}) {
|
|
220
339
|
const box = container(row, config, { create: true });
|
|
221
|
-
const
|
|
222
|
-
|
|
340
|
+
for (const [event, name] of eventsOf(row, { prompt, post })) {
|
|
341
|
+
const kept = entries(row, config, event).filter((e) => !ours(e));
|
|
342
|
+
box[name] = [...kept, group(row, event)];
|
|
343
|
+
}
|
|
223
344
|
return config;
|
|
224
345
|
}
|
|
225
346
|
|
|
226
347
|
/** The text `install` would write, or the reason the existing file cannot be read. */
|
|
227
|
-
export function rendered(row, existing) {
|
|
228
|
-
if (existing === null) return { text: `${JSON.stringify(withHook(row, {}), null, 2)}\n`, action: 'created' };
|
|
348
|
+
export function rendered(row, existing, options = {}) {
|
|
349
|
+
if (existing === null) return { text: `${JSON.stringify(withHook(row, {}, options), null, 2)}\n`, action: 'created' };
|
|
229
350
|
let config;
|
|
230
351
|
try {
|
|
231
352
|
config = JSON.parse(existing);
|
|
@@ -235,6 +356,6 @@ export function rendered(row, existing) {
|
|
|
235
356
|
if (config === null || typeof config !== 'object' || Array.isArray(config)) {
|
|
236
357
|
return { error: 'not a JSON object; left alone' };
|
|
237
358
|
}
|
|
238
|
-
const text = `${JSON.stringify(withHook(row, config), null, 2)}\n`;
|
|
359
|
+
const text = `${JSON.stringify(withHook(row, config, options), null, 2)}\n`;
|
|
239
360
|
return { text, action: text === existing ? 'unchanged' : 'updated' };
|
|
240
361
|
}
|
package/src/argv.mjs
CHANGED
|
@@ -59,6 +59,27 @@ export const BOOL_FLAGS = new Set([
|
|
|
59
59
|
// (plan 0003 R09). Off by default because a count is enough to act on; the per-line
|
|
60
60
|
// detail is what an author needs, and a reader is not an author.
|
|
61
61
|
'explain',
|
|
62
|
+
// check: the lock must match. Off by default because a repository that has not
|
|
63
|
+
// written one yet is not drift, and a gate that failed for the absence would be
|
|
64
|
+
// red on every repository this package already adopted.
|
|
65
|
+
'frozen',
|
|
66
|
+
// map: report gold-file recall@10 instead of rendering the ranking. Off by
|
|
67
|
+
// default because the ranking is the answer a task asked for, and the recall
|
|
68
|
+
// figure needs the hidden benchmark patches.
|
|
69
|
+
'recall',
|
|
70
|
+
// tests: also list files that only changed in the same commits as a test.
|
|
71
|
+
// Off by default because a shared commit is not a test.
|
|
72
|
+
'cochange',
|
|
73
|
+
// gate: read the working-tree diff instead of the paths named after the command.
|
|
74
|
+
// Off by default because a path is the change the caller named, and the diff
|
|
75
|
+
// is a different question.
|
|
76
|
+
'changed',
|
|
77
|
+
// local doctor: allow non-loopback model URLs. Off by default because nothing leaves
|
|
78
|
+
// the machine unless explicitly overridden (ADR-075, plan 0003 R37).
|
|
79
|
+
'allow-remote',
|
|
80
|
+
// index / map / brief: opt into local vector embeddings configured under local.embed
|
|
81
|
+
// (plan 0003 R28, R37). Off by default unless recall@10 gains at least 10 points.
|
|
82
|
+
'embed',
|
|
62
83
|
]);
|
|
63
84
|
|
|
64
85
|
export const VALUE_FLAGS = new Set([
|
|
@@ -100,6 +121,11 @@ export const VALUE_FLAGS = new Set([
|
|
|
100
121
|
// plan done: the test command that proves the slice. Plan 0003 R31.
|
|
101
122
|
'test',
|
|
102
123
|
'state',
|
|
124
|
+
// map: outline (paths), names (exported symbols) or signatures (the line).
|
|
125
|
+
// A boolean would not say which of the three the caller wanted.
|
|
126
|
+
'level',
|
|
127
|
+
// decide: structured supersession spec (ADR-NNN or ADR-NNN:<ruling>[:<kind>], repeatable).
|
|
128
|
+
'supersedes',
|
|
103
129
|
]);
|
|
104
130
|
|
|
105
131
|
/**
|
|
@@ -115,7 +141,7 @@ export const VALUE_FLAGS = new Set([
|
|
|
115
141
|
* is a superset of the old behaviour, not a replacement: `--skill a,b` parsed before it
|
|
116
142
|
* parses now.
|
|
117
143
|
*/
|
|
118
|
-
export const REPEATABLE_FLAGS = new Set(['skill', 'arm', 'compare']);
|
|
144
|
+
export const REPEATABLE_FLAGS = new Set(['skill', 'arm', 'compare', 'supersedes']);
|
|
119
145
|
|
|
120
146
|
/**
|
|
121
147
|
* @param {string[]} argv raw arguments, excluding node and the script path
|
|
@@ -189,6 +215,13 @@ export function parse(argv) {
|
|
|
189
215
|
return { ok: true, value: { flags, positional } };
|
|
190
216
|
}
|
|
191
217
|
|
|
218
|
+
export function parsePathList(value) {
|
|
219
|
+
return String(value ?? '')
|
|
220
|
+
.split(',')
|
|
221
|
+
.map((s) => s.trim())
|
|
222
|
+
.filter(Boolean);
|
|
223
|
+
}
|
|
224
|
+
|
|
192
225
|
/** `--max-bytes` -> `maxBytes`. Callers use camelCase; users type kebab-case. */
|
|
193
226
|
function camel(name) {
|
|
194
227
|
return name.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
package/src/bench/grade.mjs
CHANGED
|
@@ -173,6 +173,7 @@ export async function gradeWorkspace(workDir, task, { vaultRoot, initialHead, ti
|
|
|
173
173
|
resolved: false,
|
|
174
174
|
gatesPassed: false,
|
|
175
175
|
diff,
|
|
176
|
+
goldFiles: [...goldFiles],
|
|
176
177
|
agentPatch: diffPatchRes.stdout,
|
|
177
178
|
};
|
|
178
179
|
}
|
|
@@ -183,6 +184,7 @@ export async function gradeWorkspace(workDir, task, { vaultRoot, initialHead, ti
|
|
|
183
184
|
resolved: false,
|
|
184
185
|
gatesPassed: false,
|
|
185
186
|
diff,
|
|
187
|
+
goldFiles: [...goldFiles],
|
|
186
188
|
agentPatch: diffPatchRes.stdout,
|
|
187
189
|
};
|
|
188
190
|
}
|
|
@@ -224,6 +226,7 @@ export async function gradeWorkspace(workDir, task, { vaultRoot, initialHead, ti
|
|
|
224
226
|
resolved,
|
|
225
227
|
gatesPassed,
|
|
226
228
|
diff,
|
|
229
|
+
goldFiles: [...goldFiles],
|
|
227
230
|
agentPatch: diffPatchRes.stdout,
|
|
228
231
|
};
|
|
229
232
|
}
|