@descent-vtt/spec-harness 0.14.0 → 0.16.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +106 -0
- package/README.md +15 -2
- package/dist/answers.js +2 -1
- package/dist/answers.js.map +1 -1
- package/dist/branch.js +12 -0
- package/dist/branch.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +36 -54
- package/dist/cli.js.map +1 -1
- package/dist/configure.d.ts +97 -9
- package/dist/configure.js +310 -14
- package/dist/configure.js.map +1 -1
- package/dist/context.js +2 -1
- package/dist/context.js.map +1 -1
- package/dist/fs.js +1 -0
- package/dist/fs.js.map +1 -1
- package/dist/git.js +2 -1
- package/dist/git.js.map +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/host.js.map +1 -1
- package/dist/literal.d.ts +18 -0
- package/dist/literal.js +21 -0
- package/dist/literal.js.map +1 -0
- package/dist/probe.js +1 -1
- package/dist/probe.js.map +1 -1
- package/dist/reader.js +7 -1
- package/dist/reader.js.map +1 -1
- package/dist/round.d.ts +28 -3
- package/dist/round.js +90 -9
- package/dist/round.js.map +1 -1
- package/dist/rulings.js +6 -0
- package/dist/rulings.js.map +1 -1
- package/dist/sandbox.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/setup.d.ts +1 -1
- package/dist/setup.js +36 -14
- package/dist/setup.js.map +1 -1
- package/dist/siblings.js +2 -1
- package/dist/siblings.js.map +1 -1
- package/dist/signers.js +10 -1
- package/dist/signers.js.map +1 -1
- package/dist/usage.d.ts +98 -27
- package/dist/usage.js +67 -7
- package/dist/usage.js.map +1 -1
- package/dist/vendor/spec-core/jsonrpc/mcp.js.map +1 -1
- package/dist/vendor/spec-core/markdown/frontmatter.js.map +1 -1
- package/dist/vendor/spec-core/markdown/headings.js.map +1 -1
- package/dist/vendor/spec-core/markdown/links.js.map +1 -1
- package/dist/vendor/spec-core/markdown/scan.js.map +1 -1
- package/dist/vendor/spec-core/pattern/automaton.js.map +1 -1
- package/dist/vendor/spec-core/pattern/charset.js.map +1 -1
- package/dist/vendor/spec-core/pattern/regex.js.map +1 -1
- package/dist/vendor/spec-core/text/lines.js.map +1 -1
- package/dist/vendor/spec-core/text/width.js.map +1 -1
- package/dist/versions.js +3 -0
- package/dist/versions.js.map +1 -1
- package/dist/workspace.d.ts +3 -3
- package/dist/workspace.js +3 -1
- package/dist/workspace.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spec-harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Rounds of agent work under a brief: context, a guard on every write, escalations a person signs, an audit at the end. Needs Claude Code 2.1.139 or later, and @descent-vtt/spec-harness and @descent-vtt/spec-brief 0.2.0 or later installed in the project.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "DescentVTT",
|
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,112 @@ only fixes, reports less or documents, so `^0.7.0` takes only releases that
|
|
|
9
9
|
cannot turn a run red. The family's policy is
|
|
10
10
|
[spec-core's ADR-0009](https://github.com/DescentVTT/spec-core/blob/main/docs/adr/0009-versions-before-1-0.md).
|
|
11
11
|
|
|
12
|
+
## 0.16.0
|
|
13
|
+
|
|
14
|
+
`doctor` and `init` see the rest of Claude Code's hook. A line that names
|
|
15
|
+
a brief which is not one holds every write, and `doctor` says so, exit 1,
|
|
16
|
+
where it said the line guards. An entry is read with the event it stands
|
|
17
|
+
under and its matcher, so a line Claude Code never starts before a write
|
|
18
|
+
is no longer reported as the guard. And `init` writes no second line
|
|
19
|
+
beside a line of the hook a person changed, and says of each file what
|
|
20
|
+
`doctor` says of it.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- **`doctor` says a hook's line that names a brief which is not one, and
|
|
25
|
+
exits 1.** `hook claude --brief 404` on the line in Claude Code's settings
|
|
26
|
+
has the hook hold every write, exit 2, where spec-brief knows no brief 404
|
|
27
|
+
or has archived it, and `doctor` said of that line that it guards. It now
|
|
28
|
+
asks spec-brief about the name as the hook does, in the work tree the
|
|
29
|
+
line's root is in, and says the line in the words the hook holds the write
|
|
30
|
+
with: `"hook claude --brief 404" in .claude/settings.json: the flag names
|
|
31
|
+
brief 404, and spec-brief knows no such brief, so the hook holds every
|
|
32
|
+
write until the line is mended`. `--format json` has the line's `state` as
|
|
33
|
+
`held`. The hook answers as it did
|
|
34
|
+
([ADR-0005](https://github.com/DescentVTT/spec-harness/blob/main/docs/adr/0005-a-guard-is-a-guardrail.md)).
|
|
35
|
+
Upgrading: `doctor` exits 1 for such a line, where it exited 0 while every
|
|
36
|
+
write was held: name a brief spec-brief lists on the line, or take
|
|
37
|
+
`--brief` off it.
|
|
38
|
+
- **`doctor` reads the event and the matcher of the hook's entries.** It
|
|
39
|
+
read neither, so a line under `PostToolUse` alone, or under a matcher such
|
|
40
|
+
as `Bash`, which Claude Code never starts before a write, was reported as
|
|
41
|
+
the guard. An entry is now read as Claude Code's hooks reference has it:
|
|
42
|
+
waited on before a tool call under `PreToolUse` alone, for the tools its
|
|
43
|
+
matcher lets through, and for none where it runs in the background
|
|
44
|
+
(`async`, `asyncRewake`). A line waited on before no write is said as not
|
|
45
|
+
the guard, with what it stands under; one waited on before some of `Edit`,
|
|
46
|
+
`Write`, `MultiEdit` and `NotebookEdit` guards those, and the rest are
|
|
47
|
+
named as unchecked; an entry with an `if`, whose rule is not read, or with
|
|
48
|
+
a matcher that is not text, is no pattern, or is a pattern that takes more
|
|
49
|
+
than a tenth of a second to test against the four names, is *cannot
|
|
50
|
+
tell*. `--format
|
|
51
|
+
json` has `before`, `after` and `cover` on each of `claudeCode.lines`, and
|
|
52
|
+
the states `unstarted` and `held` beside `guards`, `off` and `unknown`.
|
|
53
|
+
Upgrading: a settings file whose only line of the hook is started for no
|
|
54
|
+
write, before one or after, is no longer one of `init`'s entries, so
|
|
55
|
+
beside the plugin it is no double install, exit 0 where it was 1, and
|
|
56
|
+
alone `doctor` reports no guard and does not ask Claude Code its release.
|
|
57
|
+
`doctor --strict` exits 1 for a line whose entry has an `if`, or a matcher
|
|
58
|
+
it cannot read. A script that reads `claudeCode.lines[].state` meets the
|
|
59
|
+
two new states.
|
|
60
|
+
- **`init` writes no hook beside a line of the hook that is there.** It knew
|
|
61
|
+
only the line it writes and the one 0.1 wrote, so beside a line a person
|
|
62
|
+
had changed, such as `hook claude --root ${CLAUDE_PROJECT_DIR}`, `init
|
|
63
|
+
--write` added its own, and both ran for every write; and with the Claude
|
|
64
|
+
Code plugin on beside such a line it said `skip` where `doctor` exits 1
|
|
65
|
+
for the double install. It now knows the hook as `doctor` knows it, by its
|
|
66
|
+
command and the words `hook claude`, with the event and the matcher its
|
|
67
|
+
entry stands under. Where the file holds such a line that Claude Code
|
|
68
|
+
starts for a write, `init` writes no hook into it, and says which line it
|
|
69
|
+
left in `doctor`'s words for it: `keep`, or `advise` where the line turns
|
|
70
|
+
the guard off, holds every write or is waited on before none. Beside the
|
|
71
|
+
plugin the file is `advise`, the double install, and so where the line
|
|
72
|
+
stands in a settings file of your own. It rewrites no line but the one 0.1
|
|
73
|
+
wrote
|
|
74
|
+
([ADR-0012](https://github.com/DescentVTT/spec-harness/blob/main/docs/adr/0012-one-way-into-claude-code.md)).
|
|
75
|
+
Upgrading: `init --write` leaves `.claude/settings.json` as it is where it
|
|
76
|
+
added a second line; a file that holds two since an earlier `init` keeps
|
|
77
|
+
both, and one of them is yours to take out. A line Claude Code starts for
|
|
78
|
+
no write, under a matcher that names no writing tool or in the background
|
|
79
|
+
before a write, no longer counts as installed: `init` writes its hooks
|
|
80
|
+
beside it. In the programmatic API, `mergeClaudeSettings` takes the
|
|
81
|
+
hook's reading as an optional second argument; without it, it knows
|
|
82
|
+
`init`'s own line alone, read with its event and matcher as above.
|
|
83
|
+
|
|
84
|
+
## 0.15.0
|
|
85
|
+
|
|
86
|
+
`doctor` reads the line of Claude Code's hook as the hook itself reads it:
|
|
87
|
+
a line with more on it than `init` writes is said to guard where it does,
|
|
88
|
+
and a line the hook cannot read, or whose `--root` is no directory, is said
|
|
89
|
+
as a guard that is off, exit 1, where each was reported as no guard at all
|
|
90
|
+
or not reported.
|
|
91
|
+
|
|
92
|
+
### Changed
|
|
93
|
+
|
|
94
|
+
- **`doctor` reads the line of Claude Code's hook as the hook reads it.** It
|
|
95
|
+
knew the hook only where its command and arguments were exactly what
|
|
96
|
+
`init` writes, or what 0.1 wrote: a line with `--root
|
|
97
|
+
${CLAUDE_PROJECT_DIR}` added by hand, which guards, was reported as
|
|
98
|
+
`neither the spec-harness plugin nor the hooks init writes, so Claude Code
|
|
99
|
+
guards no write`, and a line that turns the guard off was reported the
|
|
100
|
+
same way, with exit 0. It now knows the hook by its command and the words
|
|
101
|
+
`hook claude`, whatever else is on the line, and reads the rest through
|
|
102
|
+
the code the hook reads it with. A line that guards with more on it than
|
|
103
|
+
`init` writes is said as it is and fails nothing. A line the hook cannot
|
|
104
|
+
read, and a `--root` that is not a directory, are said in the hook's own
|
|
105
|
+
words, as a guard that is off, and `doctor` exits 1. A line with no
|
|
106
|
+
`args`, which a shell reads first, is *cannot tell* where the shell would
|
|
107
|
+
change what follows the command: said, and a failure under `--strict`.
|
|
108
|
+
`"onFailure": "block"` on the entry is said in a note, with what it
|
|
109
|
+
changes. `--format json` has each line as `claudeCode.lines`
|
|
110
|
+
([ADR-0005](https://github.com/DescentVTT/spec-harness/blob/main/docs/adr/0005-a-guard-is-a-guardrail.md)).
|
|
111
|
+
Upgrading: a hook's line changed by hand is now the guard to `doctor`, so
|
|
112
|
+
it asks Claude Code its release for it, and beside the plugin it is the
|
|
113
|
+
double install it always was, exit 1. Where `doctor` now exits 1 for a
|
|
114
|
+
line, the guard was off already: mend the line it names, or write
|
|
115
|
+
`hook claude` and nothing after it, as `init` does. The lines `init` and
|
|
116
|
+
the plugin wrote are reported as before.
|
|
117
|
+
|
|
12
118
|
## 0.14.0
|
|
13
119
|
|
|
14
120
|
`hook claude` says a line of its own that it cannot read with exit 1 and
|
package/README.md
CHANGED
|
@@ -342,7 +342,8 @@ Configures the family to agree. It prints the plan, merges into files that exist
|
|
|
342
342
|
- **Claude Code**: the guard hooks in `.claude/settings.json` and the MCP server in `.mcp.json`, each run with `node` from the project's `node_modules`. The `npx` entries 0.1 wrote are replaced.
|
|
343
343
|
- These are the ones the [Claude Code plugin](#as-a-claude-code-plugin) brings, so while that plugin is on - `"spec-harness@<marketplace>": true` under `enabledPlugins` in your user, project or local Claude Code settings - `init` writes neither and says why (`skip`).
|
|
344
344
|
- To have its entries instead, which every clone reads, turn the Claude Code plugin off for the project, `claude plugin disable spec-harness@spec-tools --scope local`, and run `init` again.
|
|
345
|
-
- It removes nothing: where the Claude Code plugin is on and a file already holds its entry, it says so (`advise`) and leaves the file alone.
|
|
345
|
+
- It removes nothing: where the Claude Code plugin is on and a file already holds its entry, it says so (`advise`) and leaves the file alone. So where the hook stands in a settings file of your own, which `init` does not write.
|
|
346
|
+
- A line of the hook that is there already is known as [`doctor`](#doctor) knows it: by its command and the words `hook claude`, however a person changed it, with the event and the matcher its entry stands under. Where the file holds such a line that Claude Code starts for a write, `init` writes no hook into it, since a second line would run beside the first, and says which line it left, in `doctor`'s words for it (`keep`, or `advise` where the line is no guard: it turns the guard off, holds every write, or is waited on before none). It rewrites no line but the one 0.1 wrote, and completes only its own line where that stands under one event alone. A line Claude Code starts for no write is left as it is, and `init` writes its own beside it.
|
|
346
347
|
- **git's pre-commit hook**, where git runs it from: `core.hooksPath`, relative, absolute or under `~`, and the shared hooks of a linked worktree.
|
|
347
348
|
- It refuses a commit that changes what the active brief protects, for any agent or none, a shell's writes included.
|
|
348
349
|
- With `--git-hook` it is written; without, the plan advises it (`advise`).
|
|
@@ -374,6 +375,18 @@ The first thing to run when a hook refuses something unexpectedly. It reports:
|
|
|
374
375
|
- A `cert-authority` line is a certificate authority's key, not a person's, and is left out.
|
|
375
376
|
- A line OpenSSH refuses is named as no signer, with why. Its quotes are read as OpenSSH reads them: in the principals, the first double quote, wherever it opens, is taken out with the next, which ends the field; an option's value is always in double quotes, `\"` a quote inside it. And its options are OpenSSH's: `cert-authority`, `namespaces`, `valid-after` and `valid-before`, separated by commas.
|
|
376
377
|
- **How Claude Code runs the guard**: the Claude Code plugin, with the settings file that turns it on; `init`'s hooks and server; both, which guards every write twice and exits 1, with how to keep one; or neither.
|
|
378
|
+
- A hook in Claude Code's settings is the guard by its command, `spec-harness` or its script, and the words `hook claude`, whatever else is on its line. `doctor` reads the line as the hook reads it, through the same code, with the project in place of `${CLAUDE_PROJECT_DIR}`, and says what the hook does with it.
|
|
379
|
+
- A line that holds more than `init` writes, such as `--root ${CLAUDE_PROJECT_DIR}` or `--brief 012`, is said as it is and fails nothing: `"hook claude --root ${CLAUDE_PROJECT_DIR}" in .claude/settings.json is more than init writes, and guards: the hook reads the line, and its root, /work/app, is a directory`.
|
|
380
|
+
- A line the hook cannot read, and a `--root` that is a file or is not there, are a guard that is off. Each is said in the words the hook itself says before a write, and exits 1.
|
|
381
|
+
- A line that names a brief which is not one, as `--brief 404` does where spec-brief knows no brief 404 or has archived it, holds every write: the hook exits 2 before each until the line is mended. `doctor` asks spec-brief about the name as the hook does, in the work tree the line's root is in, says it in the words the hook holds the write with, and exits 1: `"hook claude --brief 404" in .claude/settings.json: the flag names brief 404, and spec-brief knows no such brief, so the hook holds every write until the line is mended: name a brief spec-brief lists, or take --brief off the line`.
|
|
382
|
+
- An entry is read with the event it stands under and its matcher, as [Claude Code's hooks reference](https://code.claude.com/docs/en/hooks) has them: Claude Code waits on a hook before a tool call under `PreToolUse` alone, and starts an entry for the tools its matcher lets through - every tool where the matcher is left out, empty or `*`, the tools it names where it is a list of names, and the names a pattern matches otherwise. An entry that runs in the background (`async`, `asyncRewake`) is waited on for none.
|
|
383
|
+
- A line Claude Code waits on before no write is not the guard, whatever the hook would do with it. `doctor` says so with what the line stands under, `"hook claude" in .claude/settings.json: Claude Code waits on it before no write, so it is not the guard and refuses none (under PreToolUse it has the matcher "Bash")`, and a file whose only line is started for no write, before one or after, is not counted among `init`'s entries. It fails nothing: no guard is a choice.
|
|
384
|
+
- A line waited on before some of `Edit`, `Write`, `MultiEdit` and `NotebookEdit` guards those, and `doctor` names the rest, whose writes go unchecked. A line started after no write warns of none, which is said too. Neither fails anything.
|
|
385
|
+
- An `if` on the entry has Claude Code start it only for the tool calls its rule matches. The rule is not read, so which writes the line is asked on is *cannot tell*, never fine; `--strict` fails it. So is a matcher that is not text, or is no pattern, or is a pattern that takes more than a tenth of a second to test against the four names: one can be written that never finishes, and `doctor` and `init` come back all the same.
|
|
386
|
+
- A line with no `args` is one Claude Code hands to a shell. Where it holds a quote, a variable or anything else a shell rewrites after its command, what the hook is handed is *cannot tell*, never fine; `--strict` fails it. Written with `args`, each word reaches the hook as it stands, and `doctor` reads it.
|
|
387
|
+
- `"onFailure": "block"` on the hook's entry is said in a note. Claude Code 2.1.295 or later then holds a write when the hook fails, where without the field the write goes ahead: by the hook's exit 1 for a question it cannot read, by a hook that does not start, or by one that runs past its timeout. With a line that turns the guard off, that is every write, the one that mends the line among them.
|
|
388
|
+
- `--format json` has each line under `claudeCode.lines`: its `file`, `events`, the `line` as written, its `state` (`guards`, `off`, `held`, `unstarted` or `unknown`), `onFailure`, the writing tools Claude Code waits on it `before` a write by and starts it `after` one by (`null` where that cannot be told), and what is said of it as `detail`, `cover` and `note`, `null` where there is nothing to say.
|
|
389
|
+
- The plugin's own hooks are not read: they are a release's files, and every release wrote `hook claude` and no more on the line, under the matcher `init` writes. Nor is whether the plugin a settings file turns on is installed on this machine.
|
|
377
390
|
- **Which Claude Code**, when Claude Code runs the guard: `claude --version`, found on `PATH` and run without a shell.
|
|
378
391
|
- Older than 2.1.139 exits 1. An older release ignores a hook's `args` and runs a bare `node`, which reads the hook's input as a script and fails, and a PreToolUse hook that fails with anything but exit 2 blocks nothing: every write passes unguarded.
|
|
379
392
|
- On Windows, npm installs Claude Code as a `claude.cmd` shim, which cannot be run without a shell, so it is read instead: the `node_modules\@anthropic-ai\claude-code` it runs, as npm's shim or pnpm's names it, and that package.json's `version`, which doctor says it read. Nothing is run.
|
|
@@ -417,7 +430,7 @@ An option, an argument or a value that is given and names nothing is refused: ex
|
|
|
417
430
|
- **A `--root` that is a file, or is not there.** It read as a session outside a git work tree, exit 0 and no word, and the guard was off. It is `--root is "nowhere", which is not a directory, so the guard is off and this write is not checked`, with what to do. An empty `--root` is the directory the hook was started in, and guards there, as before.
|
|
418
431
|
- **A line the parser cannot read**: an option no command has, as in `hook claude --nope`; an option left without its value, as `--root $DIR` is in a shell where the variable is not set; a `--format` or an `--at` that is none. Each was exit 2, as it is from every other command, and Claude Code blocks the tool call on a PreToolUse hook's exit 2: every write of the session waited on a line only a write can mend. It is `the hook's line cannot be read (Option '--root <value>' argument missing), so the guard is off and this write is not checked`, with what to do. The parser's own words stand between the brackets, on one line.
|
|
419
432
|
|
|
420
|
-
Exit 2 from `hook claude` is kept for a write it could not check: a configuration that does not load, briefs that cannot be read, a brief that is named and is not one, an error nothing expected. `hook git` is not read this way. It stops one commit, exit 2, on a line a person reads, who can then mend the hook. Nor is a line that does not say `hook claude`, such as `hook` alone: the harness cannot tell whose it is. A hook entry that sets `"onFailure": "block"`, which Claude Code 2.1.295 and later read, has Claude Code hold the action when the hook fails, and exit 1 is a failure to it; neither `init` nor the plugin writes that field.
|
|
433
|
+
Exit 2 from `hook claude` is kept for a write it could not check: a configuration that does not load, briefs that cannot be read, a brief that is named and is not one, an error nothing expected. `hook git` is not read this way. It stops one commit, exit 2, on a line a person reads, who can then mend the hook. Nor is a line that does not say `hook claude`, such as `hook` alone: the harness cannot tell whose it is. A hook entry that sets `"onFailure": "block"`, which Claude Code 2.1.295 and later read, has Claude Code hold the action when the hook fails, and exit 1 is a failure to it; neither `init` nor the plugin writes that field. [`doctor`](#doctor) says each of these of a line it finds in Claude Code's settings, before any write meets it.
|
|
421
434
|
- **`doctor` says an empty `--brief` or `--base` in its report**, as it says a brief spec-brief does not know: a diagnosis is what a person runs when something is wrong, and it reports what is wrong with what it was given.
|
|
422
435
|
- **`SPEC_BRIEF` set and empty is as unset**, since what sets it sets it whether or not there is a round ([Which brief](#which-brief)).
|
|
423
436
|
|
package/dist/answers.js
CHANGED
|
@@ -134,7 +134,7 @@ export function readArchivePlan(document) {
|
|
|
134
134
|
const file = read.optionalText(reason['file'], `${where}.file`);
|
|
135
135
|
const line = read.optionalNumber(reason['line'], `${where}.line`);
|
|
136
136
|
const path = read.optionalText(reason['path'], `${where}.path`);
|
|
137
|
-
|
|
137
|
+
const carried = {
|
|
138
138
|
rule: read.text(reason['rule'], `${where}.rule`),
|
|
139
139
|
severity: severity,
|
|
140
140
|
message: read.text(reason['message'], `${where}.message`),
|
|
@@ -143,6 +143,7 @@ export function readArchivePlan(document) {
|
|
|
143
143
|
line,
|
|
144
144
|
path,
|
|
145
145
|
};
|
|
146
|
+
return carried;
|
|
146
147
|
});
|
|
147
148
|
return { blocking: reasons('blocking'), warnings: reasons('warnings') };
|
|
148
149
|
}
|
package/dist/answers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"answers.js","sourceRoot":"","sources":["../src/answers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAIjD,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,iGAAiG;AACjG,SAAS,MAAM,CAAC,OAAe;IAC7B,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,QAAgB,EAAS,EAAE;QACxD,MAAM,IAAI,kBAAkB,CAAC,GAAG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O,EAAE,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["/**\n * What spec-guard and spec-brief answer in JSON, besides the brief list\n * briefs.ts reads: a query's rules, a run's results and errors, and an\n * archive's plan. Each is checked for the fields the harness reads, with the\n * types it reads them as, and a document of another shape is an error that\n * names the tool and the field (ADR-0002): the command that asked stops with\n * exit 2, as for any sibling that printed something it cannot read, rather\n * than crash halfway through the document or count what it could not read as\n * clean. Fields the harness does not read are not checked, so a sibling may\n * add to its documents freely.\n */\n\nimport type { ArchiveReason } from './audit.js';\nimport { SiblingOutputError } from './briefs.js';\n\ntype Json = Record<string, unknown>;\n\nfunction isObject(value: unknown): value is Json {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** Reads fields of one document, naming the tool, its command and the field in every refusal. */\nfunction reader(printer: string) {\n const refuse = (where: string, expected: string): never => {\n throw new SiblingOutputError(`${printer} printed ${where} that is not ${expected}`);\n };\n return {\n object(value: unknown, where: string): Json {\n return isObject(value) ? value : refuse(where, 'an object');\n },\n /** A list that is absent is an empty one. */\n list(value: unknown, where: string): unknown[] {\n if (value === undefined) return [];\n return Array.isArray(value) ? (value as unknown[]) : refuse(where, 'a list');\n },\n text(value: unknown, where: string): string {\n return typeof value === 'string' ? value : refuse(where, 'text');\n },\n optionalText(value: unknown, where: string): string | undefined {\n return value === undefined ? undefined : typeof value === 'string' ? value : refuse(where, 'text');\n },\n number(value: unknown, where: string): number {\n return typeof value === 'number' ? value : refuse(where, 'a number');\n },\n optionalNumber(value: unknown, where: string): number | undefined {\n return value === undefined ? undefined : typeof value === 'number' ? value : refuse(where, 'a number');\n },\n flag(value: unknown, where: string): boolean {\n return typeof value === 'boolean' ? value : refuse(where, 'true or false');\n },\n refuse,\n };\n}\n\n/** Where spec-guard places a directive. */\nexport interface Spec {\n readonly file: string;\n readonly line: number;\n}\n\nexport interface QueryRule {\n readonly document: string;\n readonly line: number;\n readonly kind: string;\n readonly description: string;\n readonly reason: string | null;\n /** Absent from a document that says nothing of it, which is in force. */\n readonly inForce: boolean;\n}\n\n/** The rules in each of the results of `spec-guard query --json`, in order. */\nexport function readQueryRules(document: unknown): QueryRule[][] {\n const read = reader('spec-guard query');\n const top = read.object(document, 'a document');\n return read.list(top['results'], 'results').map((value, index) => {\n const result = read.object(value, `results[${index}]`);\n return read.list(result['rules'], `results[${index}].rules`).map((ruleValue, at) => {\n const where = `results[${index}].rules[${at}]`;\n const rule = read.object(ruleValue, where);\n const reason = rule['reason'];\n if (reason !== undefined && reason !== null && typeof reason !== 'string') read.refuse(`${where}.reason`, 'text or null');\n const inForce = rule['inForce'];\n return {\n document: read.text(rule['document'], `${where}.document`),\n line: read.number(rule['line'], `${where}.line`),\n kind: read.text(rule['kind'], `${where}.kind`),\n description: read.text(rule['description'], `${where}.description`),\n reason: typeof reason === 'string' ? reason : null,\n inForce: inForce === undefined ? true : read.flag(inForce, `${where}.inForce`),\n };\n });\n });\n}\n\n/**\n * The spec patterns `spec-guard query --json` says matched no file, as\n * written. A document that says nothing of them names none: spec-guard has\n * written the field since 0.22.0, and only where there is such a pattern.\n */\nexport function readQueryUnmatched(document: unknown): string[] {\n const read = reader('spec-guard query');\n const top = read.object(document, 'a document');\n return read.list(top['unmatchedSpecs'], 'unmatchedSpecs').map((value, index) => read.text(value, `unmatchedSpecs[${index}]`));\n}\n\nexport interface GuardResult {\n readonly ok: boolean;\n readonly description: string;\n readonly message: string;\n readonly spec?: Spec | undefined;\n}\n\nexport interface GuardError {\n readonly message: string;\n readonly raw: string;\n readonly spec?: Spec | undefined;\n}\n\n/** The results and the unreadable directives of a spec-guard run over briefs, `--json`. */\nexport function readGuardRun(document: unknown): { results: GuardResult[]; errors: GuardError[] } {\n const read = reader('spec-guard');\n const top = read.object(document, 'a document');\n const spec = (value: unknown, where: string): Spec | undefined => {\n if (value === undefined) return undefined;\n const placed = read.object(value, where);\n return { file: read.text(placed['file'], `${where}.file`), line: read.number(placed['line'], `${where}.line`) };\n };\n const results = read.list(top['results'], 'results').map((value, index) => {\n const where = `results[${index}]`;\n const result = read.object(value, where);\n return {\n ok: read.flag(result['ok'], `${where}.ok`),\n description: read.text(result['description'], `${where}.description`),\n message: read.text(result['message'], `${where}.message`),\n spec: spec(result['spec'], `${where}.spec`),\n };\n });\n const errors = read.list(top['errors'], 'errors').map((value, index) => {\n const where = `errors[${index}]`;\n const error = read.object(value, where);\n return {\n message: read.text(error['message'], `${where}.message`),\n raw: read.optionalText(error['raw'], `${where}.raw`) ?? '',\n spec: spec(error['spec'], `${where}.spec`),\n };\n });\n return { results, errors };\n}\n\nconst SEVERITIES: readonly string[] = ['error', 'warning', 'note'];\n\n/**\n * What `spec-brief archive --dry-run --format json` would refuse and warn\n * about. A document with no plan plans nothing to refuse. spec-brief gives a\n * reason without a hint where it has no next step, and the reason is carried\n * as it gave it: a field it left out is undefined, which JSON leaves out too.\n */\nexport function readArchivePlan(document: unknown): { blocking: ArchiveReason[]; warnings: ArchiveReason[] } {\n const read = reader('spec-brief archive');\n const top = read.object(document, 'a document');\n if (top['plan'] === undefined) return { blocking: [], warnings: [] };\n const plan = read.object(top['plan'], 'plan');\n const reasons = (key: 'blocking' | 'warnings'): ArchiveReason[] =>\n read.list(plan[key], `plan.${key}`).map((value, index) => {\n const where = `plan.${key}[${index}]`;\n const reason = read.object(value, where);\n const severity = read.text(reason['severity'], `${where}.severity`);\n if (!SEVERITIES.includes(severity)) read.refuse(`${where}.severity`, 'error, warning or note');\n const hint = read.optionalText(reason['hint'], `${where}.hint`);\n const file = read.optionalText(reason['file'], `${where}.file`);\n const line = read.optionalNumber(reason['line'], `${where}.line`);\n const path = read.optionalText(reason['path'], `${where}.path`);\n return {\n rule: read.text(reason['rule'], `${where}.rule`),\n severity: severity as ArchiveReason['severity'],\n message: read.text(reason['message'], `${where}.message`),\n hint,\n file,\n line,\n path,\n } as ArchiveReason;\n });\n return { blocking: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M,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC;QAClE,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC;QAChE,MAAM,OAAO,GAAG;YACd,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC;YAChD,QAAQ,EAAE,QAAqC;YAC/C,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,GAAG,KAAK,UAAU,CAAC;YACzD,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,IAAI;SACL,CAAC;QACF,OAAO,OAAwB,CAAC;IAClC,CAAC,CAAC,CAAC;IACL,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["/**\n * What spec-guard and spec-brief answer in JSON, besides the brief list\n * briefs.ts reads: a query's rules, a run's results and errors, and an\n * archive's plan. Each is checked for the fields the harness reads, with the\n * types it reads them as, and a document of another shape is an error that\n * names the tool and the field (ADR-0002): the command that asked stops with\n * exit 2, as for any sibling that printed something it cannot read, rather\n * than crash halfway through the document or count what it could not read as\n * clean. Fields the harness does not read are not checked, so a sibling may\n * add to its documents freely.\n */\n\nimport type { ArchiveReason } from './audit.js';\nimport { SiblingOutputError } from './briefs.js';\n\ntype Json = Record<string, unknown>;\n\nfunction isObject(value: unknown): value is Json {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** Reads fields of one document, naming the tool, its command and the field in every refusal. */\nfunction reader(printer: string) {\n const refuse = (where: string, expected: string): never => {\n throw new SiblingOutputError(`${printer} printed ${where} that is not ${expected}`);\n };\n return {\n object(value: unknown, where: string): Json {\n return isObject(value) ? value : refuse(where, 'an object');\n },\n /** A list that is absent is an empty one. */\n list(value: unknown, where: string): unknown[] {\n if (value === undefined) return [];\n return Array.isArray(value) ? (value as unknown[]) : refuse(where, 'a list');\n },\n text(value: unknown, where: string): string {\n return typeof value === 'string' ? value : refuse(where, 'text');\n },\n optionalText(value: unknown, where: string): string | undefined {\n return value === undefined ? undefined : typeof value === 'string' ? value : refuse(where, 'text');\n },\n number(value: unknown, where: string): number {\n return typeof value === 'number' ? value : refuse(where, 'a number');\n },\n optionalNumber(value: unknown, where: string): number | undefined {\n return value === undefined ? undefined : typeof value === 'number' ? value : refuse(where, 'a number');\n },\n flag(value: unknown, where: string): boolean {\n return typeof value === 'boolean' ? value : refuse(where, 'true or false');\n },\n refuse,\n };\n}\n\n/** Where spec-guard places a directive. */\nexport interface Spec {\n readonly file: string;\n readonly line: number;\n}\n\nexport interface QueryRule {\n readonly document: string;\n readonly line: number;\n readonly kind: string;\n readonly description: string;\n readonly reason: string | null;\n /** Absent from a document that says nothing of it, which is in force. */\n readonly inForce: boolean;\n}\n\n/** The rules in each of the results of `spec-guard query --json`, in order. */\nexport function readQueryRules(document: unknown): QueryRule[][] {\n const read = reader('spec-guard query');\n const top = read.object(document, 'a document');\n return read.list(top['results'], 'results').map((value, index) => {\n const result = read.object(value, `results[${index}]`);\n return read.list(result['rules'], `results[${index}].rules`).map((ruleValue, at) => {\n const where = `results[${index}].rules[${at}]`;\n const rule = read.object(ruleValue, where);\n const reason = rule['reason'];\n if (reason !== undefined && reason !== null && typeof reason !== 'string') read.refuse(`${where}.reason`, 'text or null');\n const inForce = rule['inForce'];\n return {\n document: read.text(rule['document'], `${where}.document`),\n line: read.number(rule['line'], `${where}.line`),\n kind: read.text(rule['kind'], `${where}.kind`),\n description: read.text(rule['description'], `${where}.description`),\n reason: typeof reason === 'string' ? reason : null,\n inForce: inForce === undefined ? true : read.flag(inForce, `${where}.inForce`),\n };\n });\n });\n}\n\n/**\n * The spec patterns `spec-guard query --json` says matched no file, as\n * written. A document that says nothing of them names none: spec-guard has\n * written the field since 0.22.0, and only where there is such a pattern.\n */\nexport function readQueryUnmatched(document: unknown): string[] {\n const read = reader('spec-guard query');\n const top = read.object(document, 'a document');\n return read.list(top['unmatchedSpecs'], 'unmatchedSpecs').map((value, index) => read.text(value, `unmatchedSpecs[${index}]`));\n}\n\nexport interface GuardResult {\n readonly ok: boolean;\n readonly description: string;\n readonly message: string;\n readonly spec?: Spec | undefined;\n}\n\nexport interface GuardError {\n readonly message: string;\n readonly raw: string;\n readonly spec?: Spec | undefined;\n}\n\n/** The results and the unreadable directives of a spec-guard run over briefs, `--json`. */\nexport function readGuardRun(document: unknown): { results: GuardResult[]; errors: GuardError[] } {\n const read = reader('spec-guard');\n const top = read.object(document, 'a document');\n const spec = (value: unknown, where: string): Spec | undefined => {\n if (value === undefined) return undefined;\n const placed = read.object(value, where);\n return { file: read.text(placed['file'], `${where}.file`), line: read.number(placed['line'], `${where}.line`) };\n };\n const results = read.list(top['results'], 'results').map((value, index) => {\n const where = `results[${index}]`;\n const result = read.object(value, where);\n return {\n ok: read.flag(result['ok'], `${where}.ok`),\n description: read.text(result['description'], `${where}.description`),\n message: read.text(result['message'], `${where}.message`),\n spec: spec(result['spec'], `${where}.spec`),\n };\n });\n const errors = read.list(top['errors'], 'errors').map((value, index) => {\n const where = `errors[${index}]`;\n const error = read.object(value, where);\n return {\n message: read.text(error['message'], `${where}.message`),\n raw: read.optionalText(error['raw'], `${where}.raw`) ?? '',\n spec: spec(error['spec'], `${where}.spec`),\n };\n });\n return { results, errors };\n}\n\nconst SEVERITIES: readonly string[] = ['error', 'warning', 'note'];\n\n/**\n * What `spec-brief archive --dry-run --format json` would refuse and warn\n * about. A document with no plan plans nothing to refuse. spec-brief gives a\n * reason without a hint where it has no next step, and the reason is carried\n * as it gave it: a field it left out is undefined, which JSON leaves out too.\n */\nexport function readArchivePlan(document: unknown): { blocking: ArchiveReason[]; warnings: ArchiveReason[] } {\n const read = reader('spec-brief archive');\n const top = read.object(document, 'a document');\n if (top['plan'] === undefined) return { blocking: [], warnings: [] };\n const plan = read.object(top['plan'], 'plan');\n const reasons = (key: 'blocking' | 'warnings'): ArchiveReason[] =>\n read.list(plan[key], `plan.${key}`).map((value, index) => {\n const where = `plan.${key}[${index}]`;\n const reason = read.object(value, where);\n const severity = read.text(reason['severity'], `${where}.severity`);\n if (!SEVERITIES.includes(severity)) read.refuse(`${where}.severity`, 'error, warning or note');\n const hint = read.optionalText(reason['hint'], `${where}.hint`);\n const file = read.optionalText(reason['file'], `${where}.file`);\n const line = read.optionalNumber(reason['line'], `${where}.line`);\n const path = read.optionalText(reason['path'], `${where}.path`);\n const carried = {\n rule: read.text(reason['rule'], `${where}.rule`),\n severity: severity as ArchiveReason['severity'],\n message: read.text(reason['message'], `${where}.message`),\n hint,\n file,\n line,\n path,\n };\n return carried as ArchiveReason;\n });\n return { blocking: reasons('blocking'), warnings: reasons('warnings') };\n}\n"]}
|
package/dist/branch.js
CHANGED
|
@@ -25,6 +25,11 @@ function isIdChar(ch) {
|
|
|
25
25
|
*/
|
|
26
26
|
function prefixEnds(prefix, name) {
|
|
27
27
|
// reach[j]: the prefix read so far can end at name offset j.
|
|
28
|
+
// An offset nothing was written at reads as one that cannot be reached,
|
|
29
|
+
// and `forEach` passes over it. So a list made with no places, here and
|
|
30
|
+
// for `next`, is equivalent to its mutant, and so is one made two places
|
|
31
|
+
// short, for every name but the empty one, whose list would have fewer
|
|
32
|
+
// places than none: a test holds that name.
|
|
28
33
|
let reach = new Array(name.length + 1).fill(false);
|
|
29
34
|
reach[0] = true;
|
|
30
35
|
for (const token of prefix) {
|
|
@@ -41,12 +46,17 @@ function prefixEnds(prefix, name) {
|
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
48
|
else {
|
|
49
|
+
// One place past the end `charAt` gives the empty string, which is no
|
|
50
|
+
// token, so `<=` for `<` is equivalent.
|
|
44
51
|
for (let j = 0; j < name.length; j += 1)
|
|
45
52
|
if (reach[j] && name.charAt(j) === token)
|
|
46
53
|
next[j + 1] = true;
|
|
47
54
|
}
|
|
48
55
|
reach = next;
|
|
49
56
|
}
|
|
57
|
+
// `idFromBranch` reads an id from each offset and passes over one where
|
|
58
|
+
// none starts, which a text among them is: a list that starts with one is
|
|
59
|
+
// equivalent.
|
|
50
60
|
const ends = [];
|
|
51
61
|
reach.forEach((ok, j) => {
|
|
52
62
|
if (ok)
|
|
@@ -70,6 +80,8 @@ export function idFromBranch(template, name) {
|
|
|
70
80
|
const prefix = template.slice(0, -'{id}'.length);
|
|
71
81
|
for (const start of prefixEnds(prefix, name)) {
|
|
72
82
|
let end = start;
|
|
83
|
+
// Past the end `charAt` gives the empty string, which is no character of
|
|
84
|
+
// an id, so the bound is equivalent to its mutants.
|
|
73
85
|
while (end < name.length && isIdChar(name.charAt(end)))
|
|
74
86
|
end += 1;
|
|
75
87
|
if (end === start)
|
package/dist/branch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch.js","sourceRoot":"","sources":["../src/branch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAEjD,SAAS,QAAQ,CAAC,EAAU;IAC1B,2EAA2E;IAC3E,kBAAkB;IAClB,OAAO,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,SAAS,UAAU,CAAC,MAAc,EAAE,IAAY;IAC9C,6DAA6D;IAC7D,IAAI,KAAK,GAAc,IAAI,KAAK,CAAU,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvE,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAChB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,IAAI,KAAK,CA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AAM,EAAE,IAAI,EAAE,CAAC;IAC/D,CAAC,CAAC;IACF,OAAO,CACL,KAAK,CAAC,iBAAiB,CAAC;QACxB,CAAC,GAAG,CAAC,iBAAiB,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACvE,KAAK,CAAC,qCAAqC,CAAC;QAC5C,KAAK,CAAC,kBAAkB,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED,4GAA4G;AAC5G,MAAM,UAAU,iBAAiB,CAAC,SAA4B,EAAE,IAAmB;IACjF,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,EAAE,GAAG,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACxC,IAAI,EAAE,KAAK,IAAI;YAAE,OAAO,EAAE,CAAC;IAC7B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,CAAS;IACzC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC","sourcesContent":["/**\n * Which brief a branch is working on, read from its name.\n *\n * A round runs on a branch, and naming the branch after the brief is the one\n * convention every repository that runs agents on briefs already has. Reading\n * it from there keeps the harness stateless: no file says which brief is\n * active, so no file can say it wrongly (ADR-0004).\n *\n * A template is a branch name with `{id}` where the id goes and `*` for any\n * run of characters other than `/`: `brief/{id}`, `*\\/brief-{id}`. The id is\n * the longest run of letters and digits at that point, and must be followed\n * by the end of the name or a separator - so `brief/012-rotate-tokens` names\n * 012, and `brief/012x` names 012x, never 012.\n */\n\nconst SEPARATORS = new Set(['-', '_', '/', '.']);\n\nfunction isIdChar(ch: string): boolean {\n // Asked of one character at a time, so the mutants that drop either anchor\n // are equivalent.\n return /^[A-Za-z0-9]$/.test(ch);\n}\n\n/**\n * The offsets in `name` at which a template prefix can end, by dynamic\n * programming over prefix and name, so a template of many stars costs their\n * product and never an exponent.\n */\nfunction prefixEnds(prefix: string, name: string): number[] {\n // reach[j]: the prefix read so far can end at name offset j.\n let reach: boolean[] = new Array<boolean>(name.length + 1).fill(false);\n reach[0] = true;\n for (const token of prefix) {\n const next = new Array<boolean>(name.length + 1).fill(false);\n if (token === '*') {\n let open = false;\n for (let j = 0; j <= name.length; j += 1) {\n if (reach[j]) open = true;\n if (open) next[j] = true;\n if (name.charAt(j) === '/') open = false;\n }\n } else {\n for (let j = 0; j < name.length; j += 1) if (reach[j] && name.charAt(j) === token) next[j + 1] = true;\n }\n reach = next;\n }\n const ends: number[] = [];\n reach.forEach((ok, j) => {\n if (ok) ends.push(j);\n });\n return ends;\n}\n\n/** Why a template cannot be used, or `null`. */\nexport function templateError(template: string): string | null {\n const count = template.split('{id}').length - 1;\n if (count !== 1) return `\"${template}\" must contain {id} exactly once`;\n if (!template.endsWith('{id}')) return `\"${template}\" must end with {id}; whatever follows the id is the branch's own`;\n return null;\n}\n\n/** The brief id a branch name carries under one template, or `null`. */\nexport function idFromBranch(template: string, name: string): string | null {\n if (templateError(template) !== null) return null;\n const prefix = template.slice(0, -'{id}'.length);\n for (const start of prefixEnds(prefix, name)) {\n let end = start;\n while (end < name.length && isIdChar(name.charAt(end))) end += 1;\n if (end === start) continue;\n if (end < name.length && !SEPARATORS.has(name.charAt(end))) continue;\n return name.slice(start, end);\n }\n return null;\n}\n\n/**\n * The branch a CI run is building, as the forge names it, for a checkout on\n * no branch: CI checks out a commit, and without the branch a round's own\n * run would name no brief. In order: a GitHub pull request's head branch; the\n * branch a GitHub push built; a GitLab merge request's source branch; the\n * branch a GitLab pipeline built. Each is set only where it names a branch -\n * GitHub's `GITHUB_REF_NAME` names a tag too, so only when `GITHUB_REF_TYPE`\n * says `branch` - and an empty one is not set. `null` outside CI.\n */\nexport function ciBranch(env: Readonly<Record<string, string | undefined>>): { readonly branch: string; readonly source: string } | null {\n const named = (name: string): { branch: string; source: string } | null => {\n const value = env[name]?.trim() ?? '';\n return value === '' ? null : { branch: value, source: name };\n };\n return (\n named('GITHUB_HEAD_REF') ??\n (env['GITHUB_REF_TYPE'] === 'branch' ? named('GITHUB_REF_NAME') : null) ??\n named('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME') ??\n named('CI_COMMIT_BRANCH')\n );\n}\n\n/** The first template that yields an id, in order; `null` for a head on no branch, which names no brief. */\nexport function briefIdFromBranch(templates: readonly string[], name: string | null): string | null {\n if (name === null) return null;\n for (const template of templates) {\n const id = idFromBranch(template, name);\n if (id !== null) return id;\n }\n return null;\n}\n\n/**\n * Whether two ids name the same brief: equal as written, or equal as numbers\n * when both are all digits, since a branch says `brief/12` of a brief whose\n * file says `012`.\n */\nexport function sameId(a: string, b: string): boolean {\n if (a === b) return true;\n return /^\\d+$/.test(a) && /^\\d+$/.test(b) && BigInt(a) === BigInt(b);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"branch.js","sourceRoot":"","sources":["../src/branch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAEjD,SAAS,QAAQ,CAAC,EAAU;IAC1B,2EAA2E;IAC3E,kBAAkB;IAClB,OAAO,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,SAAS,UAAU,CAAC,MAAc,EAAE,IAAY;IAC9C,6DAA6D;IAC7D,wEAAwE;IACxE,wEAAwE;IACxE,yEAAyE;IACzE,uEAAuE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CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC","sourcesContent":["/**\n * Which brief a branch is working on, read from its name.\n *\n * A round runs on a branch, and naming the branch after the brief is the one\n * convention every repository that runs agents on briefs already has. Reading\n * it from there keeps the harness stateless: no file says which brief is\n * active, so no file can say it wrongly (ADR-0004).\n *\n * A template is a branch name with `{id}` where the id goes and `*` for any\n * run of characters other than `/`: `brief/{id}`, `*\\/brief-{id}`. The id is\n * the longest run of letters and digits at that point, and must be followed\n * by the end of the name or a separator - so `brief/012-rotate-tokens` names\n * 012, and `brief/012x` names 012x, never 012.\n */\n\nconst SEPARATORS = new Set(['-', '_', '/', '.']);\n\nfunction isIdChar(ch: string): boolean {\n // Asked of one character at a time, so the mutants that drop either anchor\n // are equivalent.\n return /^[A-Za-z0-9]$/.test(ch);\n}\n\n/**\n * The offsets in `name` at which a template prefix can end, by dynamic\n * programming over prefix and name, so a template of many stars costs their\n * product and never an exponent.\n */\nfunction prefixEnds(prefix: string, name: string): number[] {\n // reach[j]: the prefix read so far can end at name offset j.\n // An offset nothing was written at reads as one that cannot be reached,\n // and `forEach` passes over it. So a list made with no places, here and\n // for `next`, is equivalent to its mutant, and so is one made two places\n // short, for every name but the empty one, whose list would have fewer\n // places than none: a test holds that name.\n let reach: boolean[] = new Array<boolean>(name.length + 1).fill(false);\n reach[0] = true;\n for (const token of prefix) {\n const next = new Array<boolean>(name.length + 1).fill(false);\n if (token === '*') {\n let open = false;\n for (let j = 0; j <= name.length; j += 1) {\n if (reach[j]) open = true;\n if (open) next[j] = true;\n if (name.charAt(j) === '/') open = false;\n }\n } else {\n // One place past the end `charAt` gives the empty string, which is no\n // token, so `<=` for `<` is equivalent.\n for (let j = 0; j < name.length; j += 1) if (reach[j] && name.charAt(j) === token) next[j + 1] = true;\n }\n reach = next;\n }\n // `idFromBranch` reads an id from each offset and passes over one where\n // none starts, which a text among them is: a list that starts with one is\n // equivalent.\n const ends: number[] = [];\n reach.forEach((ok, j) => {\n if (ok) ends.push(j);\n });\n return ends;\n}\n\n/** Why a template cannot be used, or `null`. */\nexport function templateError(template: string): string | null {\n const count = template.split('{id}').length - 1;\n if (count !== 1) return `\"${template}\" must contain {id} exactly once`;\n if (!template.endsWith('{id}')) return `\"${template}\" must end with {id}; whatever follows the id is the branch's own`;\n return null;\n}\n\n/** The brief id a branch name carries under one template, or `null`. */\nexport function idFromBranch(template: string, name: string): string | null {\n if (templateError(template) !== null) return null;\n const prefix = template.slice(0, -'{id}'.length);\n for (const start of prefixEnds(prefix, name)) {\n let end = start;\n // Past the end `charAt` gives the empty string, which is no character of\n // an id, so the bound is equivalent to its mutants.\n while (end < name.length && isIdChar(name.charAt(end))) end += 1;\n if (end === start) continue;\n if (end < name.length && !SEPARATORS.has(name.charAt(end))) continue;\n return name.slice(start, end);\n }\n return null;\n}\n\n/**\n * The branch a CI run is building, as the forge names it, for a checkout on\n * no branch: CI checks out a commit, and without the branch a round's own\n * run would name no brief. In order: a GitHub pull request's head branch; the\n * branch a GitHub push built; a GitLab merge request's source branch; the\n * branch a GitLab pipeline built. Each is set only where it names a branch -\n * GitHub's `GITHUB_REF_NAME` names a tag too, so only when `GITHUB_REF_TYPE`\n * says `branch` - and an empty one is not set. `null` outside CI.\n */\nexport function ciBranch(env: Readonly<Record<string, string | undefined>>): { readonly branch: string; readonly source: string } | null {\n const named = (name: string): { branch: string; source: string } | null => {\n const value = env[name]?.trim() ?? '';\n return value === '' ? null : { branch: value, source: name };\n };\n return (\n named('GITHUB_HEAD_REF') ??\n (env['GITHUB_REF_TYPE'] === 'branch' ? named('GITHUB_REF_NAME') : null) ??\n named('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME') ??\n named('CI_COMMIT_BRANCH')\n );\n}\n\n/** The first template that yields an id, in order; `null` for a head on no branch, which names no brief. */\nexport function briefIdFromBranch(templates: readonly string[], name: string | null): string | null {\n if (name === null) return null;\n for (const template of templates) {\n const id = idFromBranch(template, name);\n if (id !== null) return id;\n }\n return null;\n}\n\n/**\n * Whether two ids name the same brief: equal as written, or equal as numbers\n * when both are all digits, since a branch says `brief/12` of a brief whose\n * file says `012`.\n */\nexport function sameId(a: string, b: string): boolean {\n if (a === b) return true;\n return /^\\d+$/.test(a) && /^\\d+$/.test(b) && BigInt(a) === BigInt(b);\n}\n"]}
|
package/dist/cli.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { type CliIO } from './workspace.js';
|
|
13
13
|
export { EXIT_ERROR, EXIT_FAILED, EXIT_OK, UsageError, version, type CliIO } from './workspace.js';
|
|
14
|
-
export declare const HELP = "spec-harness - context, guards, audits and rulings for rounds of agent work\n\nUsage:\n spec-harness <command> [options]\n\nCommands:\n context [brief] What an agent needs to start a round: the brief, its scope,\n rulings, dependencies, the rules in force, the cited documents.\n guard <path...> May the round write these paths? Exit 1 if one is refused.\n hook claude Answer a Claude Code PreToolUse or PostToolUse hook (stdin).\n hook git Answer git's pre-commit hook for the staged files.\n escalate Ask a person to rule: --path <file> (repeatable) --reason <why>\n [--option \"<label>: <cost>\"]... [--recommend <text>].\n --list shows what waits; --show <id> prints one memo. Neither\n raises a request: beside one, only --root and --format are read.\n rule <id> Record a person's ruling in the brief: --allow or --deny, with\n --note <text>. It counts once committed signed.\n rulings [brief] The brief's rulings, and whether each one's signature verifies.\n audit [brief] Did the round stay inside the lines: what the archive would say,\n the brief's assertions, unverified rulings, new dependencies\n and the install scripts it allowed.\n probe [brief] Run the brief's probes: red at the base, green at the head.\n --at <base|head|both>, --id <probe>.\n premises Do the live briefs' premises still hold? For CI: exit 1 when one\n is stale, or, with --strict, when spec-guard cannot read one.\n init Configure the spec-* tools to agree. Prints the plan; --write\n applies it; --git-hook adds a pre-commit hook.\n mcp Serve start_round, check_path, request_escalation, audit_round,\n list_rounds and the workflow prompts over MCP on stdio.\n doctor Which siblings are installed, at which versions, which brief is\n named, how Claude Code runs the guard, and git's hook. Exit 1\n when a sibling is older than this release needs, the guard is\n installed twice, or Claude Code is too old to run its hooks.\n\nOptions:\n --brief <id> The brief the round works on. Otherwise SPEC_BRIEF, then the branch.\n For context, guard, hook, escalate, rulings, audit, probe, premises\n and doctor.\n --base <ref> What the round is measured from. Otherwise \"base\" in\n .spec-harness.json, then the remote's default branch. For context,\n guard, hook, rulings, audit, probe and doctor.\n --root <dir> Run from another directory, which must exist. For every command.\n --format <fmt> pretty or json; audit and premises also gitlab, sarif or github.\n For every command but hook and mcp.\n --strict Warnings fail the run. For guard, audit, premises and doctor.\n --help, --version\n\nAn option a command does not read, an argument it does not take, an option or an\nargument given an empty value, and a brief given both as the argument and as --brief\nare refused, exit 2, not read as if they were not there. doctor says an empty --brief\nor --base in its report. hook claude reads its line as every release has, and says a\nline it cannot read, and a --root that is not a directory, with exit 1: it refuses\nnothing for either.\n\nExit codes: 0 clean, 1 refused or found something, 2 the answer cannot be trusted.\n";
|
|
14
|
+
export declare const HELP = "spec-harness - context, guards, audits and rulings for rounds of agent work\n\nUsage:\n spec-harness <command> [options]\n\nCommands:\n context [brief] What an agent needs to start a round: the brief, its scope,\n rulings, dependencies, the rules in force, the cited documents.\n guard <path...> May the round write these paths? Exit 1 if one is refused.\n hook claude Answer a Claude Code PreToolUse or PostToolUse hook (stdin).\n hook git Answer git's pre-commit hook for the staged files.\n escalate Ask a person to rule: --path <file> (repeatable) --reason <why>\n [--option \"<label>: <cost>\"]... [--recommend <text>].\n --list shows what waits; --show <id> prints one memo. Neither\n raises a request: beside one, only --root and --format are read.\n rule <id> Record a person's ruling in the brief: --allow or --deny, with\n --note <text>. It counts once committed signed.\n rulings [brief] The brief's rulings, and whether each one's signature verifies.\n audit [brief] Did the round stay inside the lines: what the archive would say,\n the brief's assertions, unverified rulings, new dependencies\n and the install scripts it allowed.\n probe [brief] Run the brief's probes: red at the base, green at the head.\n --at <base|head|both>, --id <probe>.\n premises Do the live briefs' premises still hold? For CI: exit 1 when one\n is stale, or, with --strict, when spec-guard cannot read one.\n init Configure the spec-* tools to agree. Prints the plan; --write\n applies it; --git-hook adds a pre-commit hook.\n mcp Serve start_round, check_path, request_escalation, audit_round,\n list_rounds and the workflow prompts over MCP on stdio.\n doctor Which siblings are installed, at which versions, which brief is\n named, how Claude Code runs the guard, and git's hook. Exit 1\n when a sibling is older than this release needs, the guard is\n installed twice, its hook's line turns it off or holds every\n write, or Claude Code is too old to run its hooks.\n\nOptions:\n --brief <id> The brief the round works on. Otherwise SPEC_BRIEF, then the branch.\n For context, guard, hook, escalate, rulings, audit, probe, premises\n and doctor.\n --base <ref> What the round is measured from. Otherwise \"base\" in\n .spec-harness.json, then the remote's default branch. For context,\n guard, hook, rulings, audit, probe and doctor.\n --root <dir> Run from another directory, which must exist. For every command.\n --format <fmt> pretty or json; audit and premises also gitlab, sarif or github.\n For every command but hook and mcp.\n --strict Warnings fail the run. For guard, audit, premises and doctor.\n --help, --version\n\nAn option a command does not read, an argument it does not take, an option or an\nargument given an empty value, and a brief given both as the argument and as --brief\nare refused, exit 2, not read as if they were not there. doctor says an empty --brief\nor --base in its report. hook claude reads its line as every release has, and says a\nline it cannot read, and a --root that is not a directory, with exit 1: it refuses\nnothing for either.\n\nExit codes: 0 clean, 1 refused or found something, 2 the answer cannot be trusted.\n";
|
|
15
15
|
/**
|
|
16
16
|
* Runs the command line and resolves to the exit code, for an error nothing
|
|
17
17
|
* below expected too.
|
package/dist/cli.js
CHANGED
|
@@ -19,14 +19,14 @@ import { claudeResponse, gitResponse, parseClaudeHook } from './hooks.js';
|
|
|
19
19
|
import { claudeVersion } from './host.js';
|
|
20
20
|
import { premisesCommand } from './premises.js';
|
|
21
21
|
import { createReader } from './reader.js';
|
|
22
|
-
import { checkPaths, claudeCodeWiring, resolveBase, specBriefPlugin } from './round.js';
|
|
22
|
+
import { checkPaths, claudeCodeWiring, diagnoseBrief, resolveBase, specBriefPlugin } from './round.js';
|
|
23
23
|
import { mcpCommand } from './server.js';
|
|
24
24
|
import { gitHook, initCommand } from './setup.js';
|
|
25
25
|
import { notFido2, readAllowedSigners } from './signers.js';
|
|
26
26
|
import { SiblingError } from './siblings.js';
|
|
27
|
-
import { emptyValue, isBlank, isClaudeHook,
|
|
27
|
+
import { emptyValue, heldHookLine, isBlank, isClaudeHook, readHookLine, refusal, unreadHookLine } from './usage.js';
|
|
28
28
|
import { checkClaudeCode, CLAUDE_CODE_MINIMUM, MINIMUM_VERSIONS } from './versions.js';
|
|
29
|
-
import { activeBrief, describeActive, EXIT_ERROR, EXIT_FAILED, EXIT_OK, json,
|
|
29
|
+
import { activeBrief, describeActive, EXIT_ERROR, EXIT_FAILED, EXIT_OK, json, openWorkspace, parseOptions, UsageError, version, } from './workspace.js';
|
|
30
30
|
export { EXIT_ERROR, EXIT_FAILED, EXIT_OK, UsageError, version } from './workspace.js';
|
|
31
31
|
export const HELP = `spec-harness - context, guards, audits and rulings for rounds of agent work
|
|
32
32
|
|
|
@@ -60,7 +60,8 @@ Commands:
|
|
|
60
60
|
doctor Which siblings are installed, at which versions, which brief is
|
|
61
61
|
named, how Claude Code runs the guard, and git's hook. Exit 1
|
|
62
62
|
when a sibling is older than this release needs, the guard is
|
|
63
|
-
installed twice,
|
|
63
|
+
installed twice, its hook's line turns it off or holds every
|
|
64
|
+
write, or Claude Code is too old to run its hooks.
|
|
64
65
|
|
|
65
66
|
Options:
|
|
66
67
|
--brief <id> The brief the round works on. Otherwise SPEC_BRIEF, then the branch.
|
|
@@ -162,7 +163,7 @@ async function writeAsked(io) {
|
|
|
162
163
|
* that exits 1 and goes on with the write, where exit 2 would hold every
|
|
163
164
|
* write of the session, the one that mends the line among them (ADR-0005).
|
|
164
165
|
*/
|
|
165
|
-
function guardOff(io, wrong, mend) {
|
|
166
|
+
function guardOff(io, { wrong, mend }) {
|
|
166
167
|
io.stderr.write(`spec-harness: ${wrong}, so the guard is off and this write is not checked; ${mend}\n`);
|
|
167
168
|
return EXIT_FAILED;
|
|
168
169
|
}
|
|
@@ -170,14 +171,14 @@ function guardOff(io, wrong, mend) {
|
|
|
170
171
|
* Claude Code's hook on a line the parser refused: an option no command has,
|
|
171
172
|
* an option left without its value, a --format or an --at that is none. It
|
|
172
173
|
* was exit 2 before the question was read, for the line a settings file
|
|
173
|
-
* holds as for one typed at a terminal.
|
|
174
|
-
*
|
|
174
|
+
* holds as for one typed at a terminal. What is said of it is `doctor`'s
|
|
175
|
+
* to say as well, of a line it finds in a settings file (usage.ts).
|
|
175
176
|
*/
|
|
176
|
-
async function
|
|
177
|
+
async function unreadLine(said, io) {
|
|
177
178
|
const request = await writeAsked(io);
|
|
178
179
|
if (typeof request === 'number')
|
|
179
180
|
return request;
|
|
180
|
-
return guardOff(io,
|
|
181
|
+
return guardOff(io, unreadHookLine(said).fault);
|
|
181
182
|
}
|
|
182
183
|
async function hookCommand(options, io) {
|
|
183
184
|
const kind = options.positionals[0];
|
|
@@ -185,20 +186,15 @@ async function hookCommand(options, io) {
|
|
|
185
186
|
const request = await writeAsked(io);
|
|
186
187
|
if (typeof request === 'number')
|
|
187
188
|
return request;
|
|
188
|
-
//
|
|
189
|
-
//
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
// starts in neither, which read as a session outside a work tree, exit 0
|
|
194
|
-
// and no word, and the guard someone had configured was off.
|
|
195
|
-
if (root !== undefined && !isDirectory(root)) {
|
|
196
|
-
return guardOff(io, noDirectory(root), "give the hook's line a directory that exists, or leave --root out for the project Claude Code names");
|
|
197
|
-
}
|
|
189
|
+
// The root the line gives, or what is wrong with it: read as `doctor`
|
|
190
|
+
// reads the line where it finds it in a settings file (usage.ts).
|
|
191
|
+
const line = readHookLine(options.root, io.cwd, isDirectory);
|
|
192
|
+
if (line.state === 'off')
|
|
193
|
+
return guardOff(io, line.fault);
|
|
198
194
|
const cwd = request.cwd ?? io.cwd;
|
|
199
195
|
let workspace;
|
|
200
196
|
try {
|
|
201
|
-
workspace = await openWorkspace({ ...options, root: root ?? io.env['CLAUDE_PROJECT_DIR'] ?? cwd }, io);
|
|
197
|
+
workspace = await openWorkspace({ ...options, root: line.root ?? io.env['CLAUDE_PROJECT_DIR'] ?? cwd }, io);
|
|
202
198
|
}
|
|
203
199
|
catch (error) {
|
|
204
200
|
if (error instanceof UsageError)
|
|
@@ -208,8 +204,10 @@ async function hookCommand(options, io) {
|
|
|
208
204
|
try {
|
|
209
205
|
const decided = await decisionsFor(workspace, options, io, request.paths, cwd);
|
|
210
206
|
if ('problem' in decided) {
|
|
211
|
-
// Exit 2 blocks the tool call, and its stderr reaches the model.
|
|
212
|
-
|
|
207
|
+
// Exit 2 blocks the tool call, and its stderr reaches the model. Where
|
|
208
|
+
// the name stands on the hook's own line, what is wrong with it is
|
|
209
|
+
// `doctor`'s to say as well, in the same words (usage.ts).
|
|
210
|
+
io.stderr.write(`spec-harness: ${heldHookLine(decided.problem).wrong}. Fix the brief or the branch before writing.\n`);
|
|
213
211
|
return EXIT_ERROR;
|
|
214
212
|
}
|
|
215
213
|
const response = claudeResponse(request.event, decided.decisions);
|
|
@@ -243,32 +241,6 @@ async function hookCommand(options, io) {
|
|
|
243
241
|
throw new UsageError('hook takes "claude" or "git"');
|
|
244
242
|
}
|
|
245
243
|
/* ------------------------------------------------------------------ doctor */
|
|
246
|
-
/**
|
|
247
|
-
* The brief a round here works on, as doctor reports it: its id, and what is
|
|
248
|
-
* wrong with the name when no round can work under it. Every other command
|
|
249
|
-
* stops there. A diagnosis says it, being what a person runs when the guard
|
|
250
|
-
* holds a write they expected it to pass.
|
|
251
|
-
*/
|
|
252
|
-
async function diagnoseBrief(workspace, options, env) {
|
|
253
|
-
if (options.brief !== undefined && isBlank(options.brief))
|
|
254
|
-
return { id: null, problem: emptyValue('--brief', 'brief', options.brief) };
|
|
255
|
-
const id = namedId(workspace, options, env);
|
|
256
|
-
// A spec-brief that cannot be run is a row of the report, with the reason.
|
|
257
|
-
if (workspace.siblings.locate('spec-brief').kind !== 'found')
|
|
258
|
-
return { id, problem: null };
|
|
259
|
-
try {
|
|
260
|
-
// Where nothing names a brief, spec-brief is not asked (ADR-0004), and
|
|
261
|
-
// there is no problem to state.
|
|
262
|
-
return { id, problem: describeActive(await activeBrief(workspace, options, env)).problem };
|
|
263
|
-
}
|
|
264
|
-
catch (error) {
|
|
265
|
-
// Asking spec-brief throws nothing but this, so the check is equivalent
|
|
266
|
-
// to its mutant; it keeps any other error the stack it needs.
|
|
267
|
-
if (!(error instanceof SiblingError))
|
|
268
|
-
throw error;
|
|
269
|
-
return { id, problem: `spec-brief could not say whether it knows brief ${id}: ${error.message}` };
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
244
|
async function doctorCommand(options, io) {
|
|
273
245
|
const workspace = await openWorkspace(options, io);
|
|
274
246
|
const rows = SIBLINGS.map((name) => {
|
|
@@ -305,8 +277,14 @@ async function doctorCommand(options, io) {
|
|
|
305
277
|
const plugin = await specBriefPlugin(workspace.root);
|
|
306
278
|
// The plugin and init's entries both on: Claude Code runs every guard twice
|
|
307
279
|
// and registers the server twice (ADR-0012).
|
|
308
|
-
const wiring = await claudeCodeWiring(workspace.root, io
|
|
280
|
+
const wiring = await claudeCodeWiring(workspace.root, io);
|
|
309
281
|
const claude = wiringState(wiring);
|
|
282
|
+
// What the hook does with each line the settings hold for it, where there
|
|
283
|
+
// is something to say: more on it than init writes, a line that turns the
|
|
284
|
+
// guard off or holds every write, one only a shell can read, the writes
|
|
285
|
+
// Claude Code starts it for where they are not all of them, and what
|
|
286
|
+
// onFailure changes.
|
|
287
|
+
const lineNotes = wiring.lines.flatMap((line) => [line.detail, line.cover, line.note]).filter((note) => note !== null);
|
|
310
288
|
// Only a Claude Code that runs the guard is asked its release: one older
|
|
311
289
|
// than the hooks need lets every write through unguarded.
|
|
312
290
|
const release = claude === 'none' ? null : checkClaudeCode(await claudeVersion(io.env));
|
|
@@ -353,6 +331,7 @@ async function doctorCommand(options, io) {
|
|
|
353
331
|
...more(signerNotes),
|
|
354
332
|
`plugin ${describePlugin(plugin)}`,
|
|
355
333
|
`claude ${describeClaudeCode(wiring)}`,
|
|
334
|
+
...more(lineNotes),
|
|
356
335
|
...more(release === null ? [] : [describeClaudeRelease(release)]),
|
|
357
336
|
`git ${describeGitHook(hook)}`,
|
|
358
337
|
...more(hookNote === null ? [] : [hookNote]),
|
|
@@ -365,13 +344,16 @@ async function doctorCommand(options, io) {
|
|
|
365
344
|
// An outdated sibling is a problem to fix, where a missing optional one is
|
|
366
345
|
// a choice; with none installed, the harness can check nothing. A double
|
|
367
346
|
// install is a problem too, where no Claude Code wiring at all is a choice,
|
|
368
|
-
// and so
|
|
369
|
-
//
|
|
347
|
+
// and so are a hook whose own line turns the guard off or holds every
|
|
348
|
+
// write, and a Claude Code too old to run the hooks. A release that cannot
|
|
349
|
+
// be told is not fine either, nor a line whose reading cannot be: --strict
|
|
350
|
+
// fails both.
|
|
370
351
|
const outdated = rows.some((row) => row.state === 'outdated');
|
|
371
352
|
const usable = rows.some((row) => row.state === 'found');
|
|
353
|
+
const off = wiring.lines.some((line) => line.state === 'off' || line.state === 'held');
|
|
372
354
|
const tooOld = release?.state === 'outdated';
|
|
373
|
-
const untold = options.strict && release?.state === 'unknown';
|
|
374
|
-
return outdated || !usable || claude === 'both' || tooOld || untold ? EXIT_FAILED : EXIT_OK;
|
|
355
|
+
const untold = options.strict && (release?.state === 'unknown' || wiring.lines.some((line) => line.state === 'unknown'));
|
|
356
|
+
return outdated || !usable || claude === 'both' || off || tooOld || untold ? EXIT_FAILED : EXIT_OK;
|
|
375
357
|
}
|
|
376
358
|
/* ---------------------------------------------------------------- dispatch */
|
|
377
359
|
/**
|
|
@@ -407,7 +389,7 @@ async function dispatch(argv, io) {
|
|
|
407
389
|
// write for it.
|
|
408
390
|
const refused = error;
|
|
409
391
|
if (isClaudeHook(refused.words[0], refused.words[1]))
|
|
410
|
-
return
|
|
392
|
+
return unreadLine(refused.message, io);
|
|
411
393
|
io.stderr.write(`spec-harness: ${refused.message}\n`);
|
|
412
394
|
return EXIT_ERROR;
|
|
413
395
|
}
|