@descent-vtt/spec-harness 0.18.0 → 0.20.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 +372 -0
- package/README.md +78 -11
- package/dist/briefs.d.ts +45 -0
- package/dist/briefs.js +73 -0
- package/dist/briefs.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +384 -84
- package/dist/cli.js.map +1 -1
- package/dist/commands.js +7 -2
- package/dist/commands.js.map +1 -1
- package/dist/config.d.ts +15 -1
- package/dist/config.js +16 -3
- package/dist/config.js.map +1 -1
- package/dist/configure.d.ts +142 -32
- package/dist/configure.js +316 -89
- package/dist/configure.js.map +1 -1
- package/dist/fs.d.ts +150 -3
- package/dist/fs.js +459 -17
- package/dist/fs.js.map +1 -1
- package/dist/git.d.ts +85 -9
- package/dist/git.js +140 -16
- package/dist/git.js.map +1 -1
- package/dist/hooks.d.ts +111 -0
- package/dist/hooks.js +172 -16
- package/dist/hooks.js.map +1 -1
- package/dist/round.d.ts +8 -0
- package/dist/round.js +32 -9
- package/dist/round.js.map +1 -1
- package/dist/sandbox.js +4 -3
- package/dist/sandbox.js.map +1 -1
- package/dist/server.d.ts +25 -1
- package/dist/server.js +194 -27
- package/dist/server.js.map +1 -1
- package/dist/setup.d.ts +6 -3
- package/dist/setup.js +74 -23
- package/dist/setup.js.map +1 -1
- package/dist/siblings.d.ts +42 -7
- package/dist/siblings.js +135 -30
- package/dist/siblings.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.js.map +1 -1
- package/dist/usage.d.ts +66 -12
- package/dist/usage.js +134 -21
- package/dist/usage.js.map +1 -1
- package/dist/workspace.d.ts +80 -1
- package/dist/workspace.js +188 -8
- package/dist/workspace.js.map +1 -1
- package/hooks/hooks.json +16 -0
- package/package.json +2 -2
package/dist/usage.js
CHANGED
|
@@ -13,14 +13,20 @@
|
|
|
13
13
|
* `null`. The one thing only the disk knows, whether `--root` is a
|
|
14
14
|
* directory, is asked of the caller.
|
|
15
15
|
*/
|
|
16
|
+
import { resolve } from 'node:path';
|
|
17
|
+
import { sameId } from './branch.js';
|
|
16
18
|
import { literal } from './literal.js';
|
|
17
19
|
/** Whether a value names nothing: empty, or only space. */
|
|
18
20
|
export function isBlank(value) {
|
|
19
21
|
return value.trim() === '';
|
|
20
22
|
}
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
|
|
23
|
+
// Every value an option that takes one was given, so that an empty one is
|
|
24
|
+
// refused wherever it stands: `--root "" --root .` names one directory twice
|
|
25
|
+
// as the root is read, and the empty value is still the unset variable it
|
|
26
|
+
// most often is. An option left out has no value to refuse, and a value that
|
|
27
|
+
// names something is passed over as none is: the empty list is equivalent
|
|
28
|
+
// to its mutant.
|
|
29
|
+
const every = (option) => (line) => line.written[option] ?? [];
|
|
24
30
|
/**
|
|
25
31
|
* The options that take a value, and what an empty one fails to name.
|
|
26
32
|
* `--format` and `--at` are not here: each takes one of a few words, and the
|
|
@@ -28,16 +34,64 @@ const one = (value) => (value === undefined ? [] : [value]);
|
|
|
28
34
|
* `rule` refuses by name itself.
|
|
29
35
|
*/
|
|
30
36
|
const VALUED = literal({
|
|
31
|
-
brief: { of: (
|
|
32
|
-
base: { of: (
|
|
33
|
-
root: { of: (
|
|
37
|
+
brief: { of: every('brief'), says: "names no brief; give it a brief's id, or leave it out for the one SPEC_BRIEF or the branch names" },
|
|
38
|
+
base: { of: every('base'), says: 'names no commit; give it a branch or a commit, or leave it out for the configured base' },
|
|
39
|
+
root: { of: every('root'), says: 'names no directory; give it one, or leave it out to run in the current directory' },
|
|
34
40
|
path: { of: (line) => line.paths, says: 'names no file; give it the path of a file' },
|
|
35
|
-
reason: { of: (
|
|
41
|
+
reason: { of: every('reason'), says: 'gives no reason; say why the round cannot be done without the file' },
|
|
36
42
|
option: { of: (line) => line.options, says: 'names no choice; give it "<label>: <cost>", or leave it out' },
|
|
37
|
-
recommend: { of: (
|
|
38
|
-
show: { of: (
|
|
39
|
-
id: { of: (
|
|
43
|
+
recommend: { of: every('recommend'), says: 'recommends nothing; say which option and why, or leave it out' },
|
|
44
|
+
show: { of: every('show'), says: 'names no escalation; give it an id, as spec-harness escalate --list prints them' },
|
|
45
|
+
id: { of: every('id'), says: "names no probe; give it a probe's id, or leave it out to run every probe" },
|
|
40
46
|
});
|
|
47
|
+
/**
|
|
48
|
+
* A resolved path with its drive letter in one case. On Windows a drive
|
|
49
|
+
* letter names its volume in either case, `D:\` and `d:\` alike (Microsoft's
|
|
50
|
+
* Naming Files, Paths, and Namespaces, Naming Conventions, read 2026-10-19),
|
|
51
|
+
* where Node's `resolve` keeps the case it was written in (spec-core
|
|
52
|
+
* ADR-0005, amended 2026-10-19). The rest of the path is left as it is: NTFS
|
|
53
|
+
* can be made to tell names apart by case, so whether two names are one
|
|
54
|
+
* directory is the disk's to say. A path resolved elsewhere starts with `/`,
|
|
55
|
+
* and has no drive letter to fold.
|
|
56
|
+
*/
|
|
57
|
+
export function foldDrive(path) {
|
|
58
|
+
return /^[a-z]:/.test(path) ? `${path[0].toUpperCase()}${path.slice(1)}` : path;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Whether two values of an option that takes one ask for one thing, as the
|
|
62
|
+
* option reads them: a brief by its id as spec-brief's names are matched,
|
|
63
|
+
* space around it dropped and `12` the brief `012` (ADR-0004); a root by the
|
|
64
|
+
* directory it names from `cwd`, the one an empty root names on the hook's
|
|
65
|
+
* line among them, with a drive letter in either case; any other as it is
|
|
66
|
+
* written, since each is read so, a format, a probe's position, an id or
|
|
67
|
+
* text.
|
|
68
|
+
*/
|
|
69
|
+
function asksOne(option, first, other, cwd) {
|
|
70
|
+
if (option === 'brief')
|
|
71
|
+
return sameId(first.trim(), other.trim());
|
|
72
|
+
if (option === 'root')
|
|
73
|
+
return foldDrive(resolve(cwd, first)) === foldDrive(resolve(cwd, other));
|
|
74
|
+
return first === other;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The first option that takes one value and was given two that read as two,
|
|
78
|
+
* named with both as they were written; `null` where none was. The parser
|
|
79
|
+
* keeps the last, and the earlier went unread with no word of it:
|
|
80
|
+
* `doctor --root nowhere --root .` ran in `.`, and `--brief 404 --brief 001`
|
|
81
|
+
* was brief 001 (spec-core ADR-0005). The same value given twice, however it
|
|
82
|
+
* is spelled, is the option once, and the last is the one read. `cwd` is
|
|
83
|
+
* where a relative root is read from. A list, `--path` and `--option`, has
|
|
84
|
+
* every value it is given.
|
|
85
|
+
*/
|
|
86
|
+
export function twoValues(line, cwd) {
|
|
87
|
+
for (const [option, values] of Object.entries(line.written)) {
|
|
88
|
+
const first = values[0];
|
|
89
|
+
const other = values.find((value) => !asksOne(option, first, value, cwd));
|
|
90
|
+
if (other !== undefined)
|
|
91
|
+
return `--${option} is given twice, as ${JSON.stringify(first)} and as ${JSON.stringify(other)}, and one of the two would go unread`;
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
41
95
|
/**
|
|
42
96
|
* The line for a value that names nothing. `subject` is the input as its
|
|
43
97
|
* caller knows it: `--brief` on a command line, `"brief"` in a tool call. The
|
|
@@ -85,13 +139,15 @@ const SHAPE = literal({
|
|
|
85
139
|
audit: { options: ['brief', 'base', 'root', 'format', 'strict'], ...ONE_BRIEF },
|
|
86
140
|
probe: { options: ['brief', 'base', 'root', 'format', 'id', 'at'], ...ONE_BRIEF },
|
|
87
141
|
premises: { options: ['brief', 'root', 'format', 'strict'], ...NO_ARGUMENT },
|
|
88
|
-
init: { options: ['root', 'format', 'write', 'git-hook'], ...NO_ARGUMENT },
|
|
142
|
+
init: { options: ['root', 'format', 'write', 'git-hook', 'block-on-failure'], ...NO_ARGUMENT },
|
|
89
143
|
mcp: { options: ['root'], ...NO_ARGUMENT },
|
|
90
144
|
// A diagnosis says what is wrong with what it was given, where a command
|
|
91
145
|
// that acts on it stops: a brief or a base that names nothing is a line of
|
|
92
146
|
// doctor's report.
|
|
93
147
|
doctor: { options: ['brief', 'base', 'root', 'format', 'strict'], ...NO_ARGUMENT, reports: ['brief', 'base'] },
|
|
94
148
|
});
|
|
149
|
+
/** The options every command answers instead of running, which no shape lists. */
|
|
150
|
+
const ANSWERS = ['help', 'version'];
|
|
95
151
|
// A map, since a command is a word a person types and an object answers to
|
|
96
152
|
// more names than it was given: `constructor` has no shape.
|
|
97
153
|
const SHAPES = new Map(Object.entries(SHAPE));
|
|
@@ -109,7 +165,7 @@ function listed(options) {
|
|
|
109
165
|
* every release, which this one cannot rewrite, and exit 2 from it holds
|
|
110
166
|
* every write of a session, the write that would fix the line among them.
|
|
111
167
|
* A line the parser cannot read is asked the same, and the hook says it
|
|
112
|
-
* with exit
|
|
168
|
+
* to the person with exit 0 (cli.ts).
|
|
113
169
|
*/
|
|
114
170
|
export function isClaudeHook(command, argument) {
|
|
115
171
|
return command === 'hook' && argument === 'claude';
|
|
@@ -133,9 +189,11 @@ export function heldHookLine(wrong) {
|
|
|
133
189
|
}
|
|
134
190
|
/**
|
|
135
191
|
* A line the parser refused: an option no command has, an option left
|
|
136
|
-
* without its value, a `--format` or an `--at` that is none
|
|
137
|
-
*
|
|
138
|
-
*
|
|
192
|
+
* without its value, a `--format` or an `--at` that is none, `--help` beside
|
|
193
|
+
* `--version`; or a line it read with two values for an option that takes
|
|
194
|
+
* one, of which it cannot tell the one meant ({@link twoValues}). The
|
|
195
|
+
* parser's words are kept, on one line: what node says of an option that may
|
|
196
|
+
* have lost its value is three.
|
|
139
197
|
*/
|
|
140
198
|
export function unreadHookLine(said) {
|
|
141
199
|
return { state: 'off', fault: { wrong: `the hook's line cannot be read (${said.split('\n').join(' ')})`, mend: 'mend it in Claude Code\'s settings, where init writes "hook claude" and nothing after it' } };
|
|
@@ -155,6 +213,42 @@ export function readHookLine(root, cwd, isDirectory) {
|
|
|
155
213
|
}
|
|
156
214
|
return { state: 'guards', root: given };
|
|
157
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* What `--help` or `--version` on the hook's line stands beside that the
|
|
218
|
+
* hook would say as it runs, in the words for a line it cannot read; `null`
|
|
219
|
+
* where the line asks for neither, or stands beside nothing the line itself
|
|
220
|
+
* shows to be wrong. Every command answers either before it runs, so the
|
|
221
|
+
* hook printed the help over a root that is not a directory, exit 0, and
|
|
222
|
+
* said nothing of it (ADR-0005). A fault only git or spec-brief can tell
|
|
223
|
+
* stays unsaid: neither is asked before an answer that runs nothing.
|
|
224
|
+
*/
|
|
225
|
+
export function answerBeside(line, cwd, isDirectory) {
|
|
226
|
+
if (!line.help && !line.version)
|
|
227
|
+
return null;
|
|
228
|
+
const read = readHookLine(line.root, cwd, isDirectory);
|
|
229
|
+
if (read.state === 'guards')
|
|
230
|
+
return null;
|
|
231
|
+
const asked = line.help ? 'help' : 'version';
|
|
232
|
+
return `--${asked} is given beside a fault, ${read.fault.wrong}, and the ${asked} would be printed in its place`;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* A line of the hook's that asks for the help or the version, which the hook
|
|
236
|
+
* prints, exit 0, in place of reading its question: no write is checked
|
|
237
|
+
* under it, and Claude Code, by its hooks reference, writes what a hook
|
|
238
|
+
* that exits 0 prints to its debug log, so nothing says the guard is off
|
|
239
|
+
* (ADR-0005). The hook says nothing of it, since a person who asks the hook
|
|
240
|
+
* for its help at a terminal is answered the same way.
|
|
241
|
+
*/
|
|
242
|
+
export function answeringHookLine(asked) {
|
|
243
|
+
return {
|
|
244
|
+
state: 'off',
|
|
245
|
+
silent: true,
|
|
246
|
+
fault: {
|
|
247
|
+
wrong: `the line asks for the ${asked}, which the hook prints, exit 0, in place of checking the write`,
|
|
248
|
+
mend: 'take that option off the line, where init writes "hook claude" and nothing after it',
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
}
|
|
158
252
|
/**
|
|
159
253
|
* A line whose root is a directory outside any git work tree. The hook
|
|
160
254
|
* reads that as a session outside one, where it has nothing to guard: it
|
|
@@ -215,6 +309,11 @@ export function holderHookLine(line, tree, path) {
|
|
|
215
309
|
* A line that guards says which brief it names, where it names one: the hook
|
|
216
310
|
* passes over a `--brief` that is empty, as every release has, and holds
|
|
217
311
|
* every write under one that names no brief, which only spec-brief can tell.
|
|
312
|
+
* A line with two values for an option that takes one is a line the hook
|
|
313
|
+
* cannot read, whichever option it is, read from `cwd` as the hook reads it
|
|
314
|
+
* from where it is started (cli.ts). So is one with the help or the version
|
|
315
|
+
* beside a root that is not a directory; and with either beside nothing it
|
|
316
|
+
* can see is wrong, the line checks no write, whatever else it holds.
|
|
218
317
|
*/
|
|
219
318
|
export function claudeHookLine(words, parse, cwd, isDirectory) {
|
|
220
319
|
let line;
|
|
@@ -227,6 +326,16 @@ export function claudeHookLine(words, parse, cwd, isDirectory) {
|
|
|
227
326
|
}
|
|
228
327
|
if (!isClaudeHook(line.command, line.positionals[0]))
|
|
229
328
|
return null;
|
|
329
|
+
const twice = twoValues(line, cwd);
|
|
330
|
+
if (twice !== null)
|
|
331
|
+
return unreadHookLine(twice);
|
|
332
|
+
const beside = answerBeside(line, cwd, isDirectory);
|
|
333
|
+
if (beside !== null)
|
|
334
|
+
return unreadHookLine(beside);
|
|
335
|
+
if (line.help)
|
|
336
|
+
return answeringHookLine('help');
|
|
337
|
+
if (line.version)
|
|
338
|
+
return answeringHookLine('version');
|
|
230
339
|
const read = readHookLine(line.root, cwd, isDirectory);
|
|
231
340
|
return read.state === 'guards' && line.brief !== undefined && !isBlank(line.brief) ? { ...read, brief: line.brief } : read;
|
|
232
341
|
}
|
|
@@ -234,9 +343,10 @@ export function claudeHookLine(words, parse, cwd, isDirectory) {
|
|
|
234
343
|
* Why the command line is refused, or `null` when the command can run:
|
|
235
344
|
* an option it does not read, alone or beside another, an argument it does
|
|
236
345
|
* not take, a brief named twice, a value or an argument that names nothing,
|
|
237
|
-
* a `--root` that is no directory. Asked once a command is known and
|
|
238
|
-
* `--help`
|
|
239
|
-
*
|
|
346
|
+
* a `--root` that is no directory. Asked once a command is known, and before
|
|
347
|
+
* `--help` or `--version` answers: a line that is wrong is refused with
|
|
348
|
+
* either on it, as one the parser refuses always was (spec-core ADR-0005).
|
|
349
|
+
* A command with no shape is none, which its caller says.
|
|
240
350
|
*/
|
|
241
351
|
export function refusal(line, isDirectory) {
|
|
242
352
|
const { command, positionals } = line;
|
|
@@ -247,15 +357,18 @@ export function refusal(line, isDirectory) {
|
|
|
247
357
|
const shape = SHAPES.get(command);
|
|
248
358
|
if (shape === undefined || isClaudeHook(command, positionals[0]))
|
|
249
359
|
return null;
|
|
250
|
-
|
|
360
|
+
// What the line asks the command, beside the help or the version it may
|
|
361
|
+
// ask for instead, which every command answers.
|
|
362
|
+
const asked = line.given.filter((option) => !ANSWERS.includes(option));
|
|
363
|
+
const stray = asked.find((option) => !shape.options.includes(option));
|
|
251
364
|
if (stray !== undefined)
|
|
252
365
|
return `${command} does not take --${stray}; ${listed(shape.options)}`;
|
|
253
366
|
// An option the command reads, beside one that leaves it unread:
|
|
254
367
|
// `escalate --list --path src/a.ts` printed the list, exit 0, and the
|
|
255
368
|
// request it also spelled out was never raised.
|
|
256
|
-
const mode = shape.modes?.find((candidate) =>
|
|
369
|
+
const mode = shape.modes?.find((candidate) => asked.includes(candidate.option));
|
|
257
370
|
if (mode !== undefined) {
|
|
258
|
-
const unread =
|
|
371
|
+
const unread = asked.find((option) => option !== mode.option && !mode.beside.includes(option));
|
|
259
372
|
if (unread !== undefined)
|
|
260
373
|
return `${command} --${mode.option} does not take --${unread}; beside --${mode.option} ${listed(mode.beside)}`;
|
|
261
374
|
}
|
package/dist/usage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAmBvC,2DAA2D;AAC3D,MAAM,UAAU,OAAO,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ACjM,CAAC;IACD,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAA6B,EAAE,CAAC;QAClF,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC;YAAE,SAAS;QAC9C,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,UAAU,CAAC,KAAK,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3E,CAAC;IACD,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxD,OAAO,GAAG,OAAO,cAAc,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,uBAAuB,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAChI,CAAC;IACD,4EAA4E;IAC5E,uEAAuE;IACvE,yEAAyE;IACzE,oDAAoD;IACpD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACvD,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,4EAA4E,CAAC;IAC/G,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * What a command line that parsed has still to be before it runs.\n *\n * The parser says what was typed. Whether it names anything was left to each\n * command, and most never asked: an option another command reads was taken\n * and did nothing, an argument no command asked for was dropped, and an\n * option given an empty value, as `--root \"$DIR\"` is where the variable is\n * not set, was read as the option left out. Each run then answered a\n * question nobody had put, exit 0, where a tool never falls back to its\n * defaults and reports clean (spec-core ADR-0005).\n *\n * Pure: the command line as it was read, and the line that refuses it, or\n * `null`. The one thing only the disk knows, whether `--root` is a\n * directory, is asked of the caller.\n */\n\nimport { literal } from './literal.js';\n\n/** A command line as the parser read it; what `parseOptions` returns is one. */\nexport interface CommandLine {\n readonly command: string | undefined;\n readonly positionals: readonly string[];\n /** The long name of every option on it, in the order given. */\n readonly given: readonly string[];\n readonly brief: string | undefined;\n readonly base: string | undefined;\n readonly root: string | undefined;\n readonly paths: readonly string[];\n readonly reason: string | undefined;\n readonly options: readonly string[];\n readonly recommend: string | undefined;\n readonly show: string | undefined;\n readonly id: string | undefined;\n}\n\n/** Whether a value names nothing: empty, or only space. */\nexport function isBlank(value: string): boolean {\n return value.trim() === '';\n}\n\ninterface Valued {\n readonly of: (line: CommandLine) => readonly string[];\n /** What is said of a value that names nothing, and what to do instead. */\n readonly says: string;\n}\n\n// An option left out has no value to refuse, and a value that names something\n// is passed over as none is: the empty list is equivalent to its mutant.\nconst one = (value: string | undefined): readonly string[] => (value === undefined ? [] : [value]);\n\n/**\n * The options that take a value, and what an empty one fails to name.\n * `--format` and `--at` are not here: each takes one of a few words, and the\n * parser refuses any other, the empty one with them. Nor is `--note`, which\n * `rule` refuses by name itself.\n */\nconst VALUED = literal({\n brief: { of: (line) => one(line.brief), says: \"names no brief; give it a brief's id, or leave it out for the one SPEC_BRIEF or the branch names\" },\n base: { of: (line) => one(line.base), says: 'names no commit; give it a branch or a commit, or leave it out for the configured base' },\n root: { of: (line) => one(line.root), says: 'names no directory; give it one, or leave it out to run in the current directory' },\n path: { of: (line) => line.paths, says: 'names no file; give it the path of a file' },\n reason: { of: (line) => one(line.reason), says: 'gives no reason; say why the round cannot be done without the file' },\n option: { of: (line) => line.options, says: 'names no choice; give it \"<label>: <cost>\", or leave it out' },\n recommend: { of: (line) => one(line.recommend), says: 'recommends nothing; say which option and why, or leave it out' },\n show: { of: (line) => one(line.show), says: 'names no escalation; give it an id, as spec-harness escalate --list prints them' },\n id: { of: (line) => one(line.id), says: \"names no probe; give it a probe's id, or leave it out to run every probe\" },\n}) satisfies Record<string, Valued>;\n\nexport type ValuedOption = keyof typeof VALUED;\n\n/**\n * The line for a value that names nothing. `subject` is the input as its\n * caller knows it: `--brief` on a command line, `\"brief\"` in a tool call. The\n * value is shown as JSON, where a tab or a line break in it can be seen.\n */\nexport function emptyValue(subject: string, option: ValuedOption, value: string): string {\n return `${subject} is ${JSON.stringify(value)}, which ${VALUED[option].says}`;\n}\n\ninterface Shape {\n /** The options the command reads, by their long names. */\n readonly options: readonly string[];\n /** The most arguments it takes, with that said for the refusal of one more; `null` where it takes any number. */\n readonly limit: { readonly most: number; readonly takes: string } | null;\n /**\n * What an argument of it is, and what to do about an empty one; absent\n * where it takes none, or says so itself. `option` is the option that\n * names the same thing, where there is one: the two together are refused.\n * Only a brief is named both ways.\n */\n readonly argument?: { readonly role: string; readonly instead: string; readonly option?: 'brief' };\n /** The options whose empty value the command says in its own report. */\n readonly reports?: readonly string[];\n /**\n * The options that make the command another one, each with the only\n * options it reads beside it. The first on the list that is given decides,\n * as the command itself decides.\n */\n readonly modes?: readonly { readonly option: string; readonly beside: readonly string[] }[];\n}\n\nconst NO_ARGUMENT = literal({ limit: { most: 0, takes: 'no argument' } });\nconst ONE_BRIEF = literal({\n limit: { most: 1, takes: \"one argument at most, a brief's id\" },\n argument: { role: 'the brief', instead: \"give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names\", option: 'brief' },\n});\n\n/**\n * Every command, with what it reads of a command line. An option is listed\n * for a command only where the command's answer depends on it: `init`\n * chooses the base itself and the server is told the brief by each call, so\n * neither takes `--base` or `--brief`, and taking them would tell someone\n * the base or the brief had been set.\n */\nconst SHAPE = literal({\n context: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },\n guard: {\n options: ['brief', 'base', 'root', 'format', 'strict'],\n limit: null,\n argument: { role: 'a path', instead: 'give it the paths the round would write' },\n },\n hook: { options: ['brief', 'base', 'root'], limit: { most: 1, takes: 'one argument, \"claude\" or \"git\"' } },\n // `--list` and `--show` print what waits and raise nothing: neither reads\n // the parts of a request, nor a brief, since what waits is every round's.\n escalate: {\n options: ['brief', 'root', 'format', 'path', 'reason', 'option', 'recommend', 'list', 'show'],\n ...NO_ARGUMENT,\n modes: [\n { option: 'list', beside: ['root', 'format'] },\n { option: 'show', beside: ['root', 'format'] },\n ],\n },\n rule: {\n options: ['root', 'format', 'allow', 'deny', 'note'],\n limit: { most: 1, takes: \"one argument, the escalation's id\" },\n argument: { role: 'the escalation', instead: 'give it an id, as spec-harness escalate --list prints them' },\n },\n rulings: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },\n audit: { options: ['brief', 'base', 'root', 'format', 'strict'], ...ONE_BRIEF },\n probe: { options: ['brief', 'base', 'root', 'format', 'id', 'at'], ...ONE_BRIEF },\n premises: { options: ['brief', 'root', 'format', 'strict'], ...NO_ARGUMENT },\n init: { options: ['root', 'format', 'write', 'git-hook'], ...NO_ARGUMENT },\n mcp: { options: ['root'], ...NO_ARGUMENT },\n // A diagnosis says what is wrong with what it was given, where a command\n // that acts on it stops: a brief or a base that names nothing is a line of\n // doctor's report.\n doctor: { options: ['brief', 'base', 'root', 'format', 'strict'], ...NO_ARGUMENT, reports: ['brief', 'base'] },\n}) satisfies Record<string, Shape>;\n\n/** Every command there is: the command line dispatches on these names and no other. */\nexport type Command = keyof typeof SHAPE;\n\n// A map, since a command is a word a person types and an object answers to\n// more names than it was given: `constructor` has no shape.\nconst SHAPES: ReadonlyMap<string, Shape> = new Map(Object.entries(SHAPE));\n\nfunction listed(options: readonly string[]): string {\n const names = options.map((option) => `--${option}`);\n // Every command reads at least `--root`, so a list is never empty.\n if (names.length === 1) return `its only option is ${names[0] as string}`;\n return `its options are ${names.slice(0, -1).join(', ')} and ${names.at(-1)!}`;\n}\n\n/**\n * Whether a line is Claude Code's hook, by its command and the argument\n * after it. It is exempt from every refusal here, and read as each release\n * since 0.1.0 read it: the line lives in settings files and in the plugin of\n * every release, which this one cannot rewrite, and exit 2 from it holds\n * every write of a session, the write that would fix the line among them.\n * A line the parser cannot read is asked the same, and the hook says it\n * with exit 1 (cli.ts).\n */\nexport function isClaudeHook(command: string | undefined, argument: string | undefined): boolean {\n return command === 'hook' && argument === 'claude';\n}\n\n/** The words for a `--root` that is a file, or is not there, wherever it is said. */\nexport function noDirectory(root: string): string {\n return `--root is \"${root}\", which is not a directory`;\n}\n\n/** What is wrong with the line of Claude Code's hook, and what mends it. */\nexport interface LineFault {\n readonly wrong: string;\n readonly mend: string;\n}\n\n/**\n * What Claude Code's hook does with its own line, as far as the line decides\n * it: it guards, in the root the line gives it where it gives one and under\n * the brief it names where it names one; or the guard is off, for a fault\n * the hook says with exit 1 and holds no write for; or every write is held,\n * exit 2, for a brief the line names that is not one (ADR-0005). The hook\n * reads its line through the functions below, and `doctor` reads a line it\n * finds in Claude Code's settings through the same ones, so what it says of\n * a line is what the hook does with it.\n */\nexport type HookLine = Guards | GuardOff | WritesHeld;\n\nexport interface Guards {\n readonly state: 'guards';\n readonly root: string | undefined;\n /**\n * The brief the line names with `--brief`, as written. Whether it is a\n * brief is spec-brief's to say, which the caller asks. Absent where the\n * line names none.\n */\n readonly brief?: string;\n /**\n * The work tree the root is in, where that is not the project's own and\n * holds it: the hook opens the work tree its root is in, so a write to a\n * file of the project is checked there, by that work tree's briefs, under\n * the path the file has in it. Only git can tell, so the caller asks it.\n * Absent where the line gives no root, or one in the project's work tree.\n */\n readonly holder?: OtherTree & { readonly path: string };\n}\n\n/** A work tree the root on the hook's line is in that is not the project's own. */\nexport interface OtherTree {\n /** Its top, as git names it. */\n readonly top: string;\n /** Whether it is a work tree of the project's own repository, linked or main, where it is otherwise another repository's. */\n readonly ours: boolean;\n}\n\n/** How such a work tree is named: by its top, and whose it is. */\nexport function namedTree({ top, ours }: OtherTree): string {\n return `${top}, ${ours ? 'another work tree of this repository' : 'the work tree of another repository'}`;\n}\n\nexport interface GuardOff {\n readonly state: 'off';\n readonly fault: LineFault;\n /**\n * Set where the hook says nothing of the fault and exits 0, so that no\n * run of it fails: a root outside any work tree, or in a work tree that\n * does not hold the project. Every other fault it says, with exit 1.\n */\n readonly silent?: true;\n /**\n * What goes unchecked, where that is not every write: under a root in a\n * work tree that does not hold the project, the hook checks a write to a\n * file of that work tree, and none to a file of the project.\n */\n readonly unchecked?: string;\n}\n\nexport interface WritesHeld {\n readonly state: 'held';\n /** What is said of the name, by what named the brief (workspace.ts). */\n readonly wrong: string;\n}\n\n/**\n * A line under which the round has no brief to be checked against, since\n * what names one names a brief spec-brief does not know, or one it has\n * archived: the hook holds the write, exit 2, and every write after it until\n * the name is mended (ADR-0004). `wrong` is what is said of the name.\n */\nexport function heldHookLine(wrong: string): WritesHeld {\n return { state: 'held', wrong };\n}\n\n/**\n * A line the parser refused: an option no command has, an option left\n * without its value, a `--format` or an `--at` that is none. The parser's\n * words are kept, on one line: what node says of an option that may have\n * lost its value is three.\n */\nexport function unreadHookLine(said: string): GuardOff {\n return { state: 'off', fault: { wrong: `the hook's line cannot be read (${said.split('\\n').join(' ')})`, mend: 'mend it in Claude Code\\'s settings, where init writes \"hook claude\" and nothing after it' } };\n}\n\n/**\n * A line that parsed, by the root it gives. An empty root is the directory\n * the hook was started in: git starts there when it is handed no directory,\n * so the hook has guarded there for an empty root in every release. A root\n * that is a file, or is not there, is one git starts in neither of, which\n * read as a session outside a work tree, exit 0 and no word, and the guard\n * someone had configured was off.\n */\nexport function readHookLine(root: string | undefined, cwd: string, isDirectory: (path: string) => boolean): Guards | GuardOff {\n const given = root === '' ? cwd : root;\n if (given !== undefined && !isDirectory(given)) {\n return { state: 'off', fault: { wrong: noDirectory(given), mend: \"give the hook's line a directory that exists, or leave --root out for the project Claude Code names\" } };\n }\n return { state: 'guards', root: given };\n}\n\n/**\n * A line whose root is a directory outside any git work tree. The hook\n * reads that as a session outside one, where it has nothing to guard: it\n * checks no write and says nothing, exit 0 (ADR-0005), and that stays. Only\n * git can tell such a root, so the caller asks it. A line that carries one\n * is a guard someone set up that checks nothing, and `doctor` says it as\n * off.\n */\nexport function outsideHookLine(root: string): GuardOff {\n return {\n state: 'off',\n silent: true,\n fault: {\n wrong: `--root is \"${root}\", a directory outside any git work tree, which the hook reads as a session outside one, exit 0 and no word`,\n mend: \"give the hook's line a directory in the work tree, or leave --root out for the project Claude Code names\",\n },\n };\n}\n\n/**\n * A line whose root is in a git work tree that does not hold the project:\n * another repository beside it, or a work tree inside it, a repository of\n * its own, a submodule or a linked worktree. The hook opens the work tree\n * its root is in and decides by that work tree's briefs. A file of the\n * project is outside it, which the hook reads as a file outside the\n * repository: it says nothing, exit 0, as it has in every release, and that\n * stays. So no write to a file of the project is checked under the line,\n * and `doctor` says it as a guard that is off. Only git can tell such a\n * root, so the caller asks it.\n */\nexport function elsewhereHookLine(root: string, tree: OtherTree): GuardOff {\n return {\n state: 'off',\n silent: true,\n unchecked: 'no write to a file of this project is checked',\n fault: {\n wrong: `--root is \"${root}\", a directory in ${namedTree(tree)}, which does not hold this project: the hook checks a write to a file of that work tree, by its briefs, and passes any other with no word, exit 0`,\n mend: \"give the hook's line a directory in this work tree, or leave --root out for the project Claude Code names\",\n },\n };\n}\n\n/**\n * A line that guards under a root in a work tree which holds the project\n * and is not its own: a repository the project is nested in, or the main\n * work tree around a linked one. `path` is the project's top as that work\n * tree names it.\n */\nexport function holderHookLine(line: Guards, tree: OtherTree, path: string): Guards {\n return { ...line, holder: { ...tree, path } };\n}\n\n/**\n * What Claude Code's hook does with the words it is handed, or `null` for\n * words that are not its line: read by the parser the command line reads\n * every line with, and known by its command and the argument after it on a\n * line that parsed and on one that did not, as the command line knows it\n * (cli.ts). `parse` is that parser, which throws its refusal with the words\n * it could still read.\n *\n * A line that guards says which brief it names, where it names one: the hook\n * passes over a `--brief` that is empty, as every release has, and holds\n * every write under one that names no brief, which only spec-brief can tell.\n */\nexport function claudeHookLine(\n words: readonly string[],\n parse: (argv: readonly string[]) => CommandLine,\n cwd: string,\n isDirectory: (path: string) => boolean,\n): HookLine | null {\n let line: CommandLine;\n try {\n line = parse(words);\n } catch (error) {\n const refused = error as { readonly message: string; readonly words: readonly string[] };\n return isClaudeHook(refused.words[0], refused.words[1]) ? unreadHookLine(refused.message) : null;\n }\n if (!isClaudeHook(line.command, line.positionals[0])) return null;\n const read = readHookLine(line.root, cwd, isDirectory);\n return read.state === 'guards' && line.brief !== undefined && !isBlank(line.brief) ? { ...read, brief: line.brief } : read;\n}\n\n/**\n * Why the command line is refused, or `null` when the command can run:\n * an option it does not read, alone or beside another, an argument it does\n * not take, a brief named twice, a value or an argument that names nothing,\n * a `--root` that is no directory. Asked once a command is known and neither\n * `--help` nor `--version` answers instead; a command with no shape is none,\n * which its caller says.\n */\nexport function refusal(line: CommandLine, isDirectory: (path: string) => boolean): string | null {\n const { command, positionals } = line;\n // No shape is kept under `undefined`, so the first check is the compiler's,\n // and its mutant is equivalent.\n if (command === undefined) return null;\n const shape = SHAPES.get(command);\n if (shape === undefined || isClaudeHook(command, positionals[0])) return null;\n const stray = line.given.find((option) => !shape.options.includes(option));\n if (stray !== undefined) return `${command} does not take --${stray}; ${listed(shape.options)}`;\n // An option the command reads, beside one that leaves it unread:\n // `escalate --list --path src/a.ts` printed the list, exit 0, and the\n // request it also spelled out was never raised.\n const mode = shape.modes?.find((candidate) => line.given.includes(candidate.option));\n if (mode !== undefined) {\n const unread = line.given.find((option) => option !== mode.option && !mode.beside.includes(option));\n if (unread !== undefined) return `${command} --${mode.option} does not take --${unread}; beside --${mode.option} ${listed(mode.beside)}`;\n }\n if (shape.limit !== null && positionals.length > shape.limit.most) {\n return `${command} takes ${shape.limit.takes}, not ${positionals.map((argument) => JSON.stringify(argument)).join(', ')}`;\n }\n // One thing named two ways, whatever the two hold: the argument won with\n // no word, so `audit 012 --brief 013` audited 012 for someone who had\n // also typed 013.\n const { argument } = shape;\n if (argument?.option !== undefined && positionals.length > 0 && line.given.includes(argument.option)) {\n return `${command} was given ${argument.role} twice, as its argument ${JSON.stringify(positionals[0])} and as --${argument.option} ${JSON.stringify(line[argument.option])}; give one of them`;\n }\n for (const [option, valued] of Object.entries(VALUED) as [ValuedOption, Valued][]) {\n if (shape.reports?.includes(option)) continue;\n const empty = valued.of(line).find(isBlank);\n if (empty !== undefined) return emptyValue(`--${option}`, option, empty);\n }\n const empty = positionals.find(isBlank);\n if (shape.argument !== undefined && empty !== undefined) {\n return `${command} was given ${JSON.stringify(empty)} as ${shape.argument.role}, which names none; ${shape.argument.instead}`;\n }\n // An empty one was refused above, so this is a path that was meant: a file,\n // or a directory that is not there. git starts in neither, and the run\n // ended saying the path was outside a work tree, which named neither the\n // option nor what was wrong with what it was given.\n if (line.root !== undefined && !isDirectory(line.root)) {\n return `${noDirectory(line.root)}; give it one that exists, or leave it out to run in the current directory`;\n }\n return null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAwBvC,2DAA2D;AAC3D,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAQD,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,iBAAiB;AACjB,MAAM,KAAK,GACT,CAAC,MAAc,EAAE,EAAE,CACnB,CAAC,IAAiB,EAAqB,EAAE,CACvC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,MAAM,GAAG,OAAO,CAAC;IACrB,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,kGA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,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxD,OAAO,GAAG,OAAO,cAAc,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,uBAAuB,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAChI,CAAC;IACD,4EAA4E;IAC5E,uEAAuE;IACvE,yEAAyE;IACzE,oDAAoD;IACpD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACvD,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,4EAA4E,CAAC;IAC/G,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * What a command line that parsed has still to be before it runs.\n *\n * The parser says what was typed. Whether it names anything was left to each\n * command, and most never asked: an option another command reads was taken\n * and did nothing, an argument no command asked for was dropped, and an\n * option given an empty value, as `--root \"$DIR\"` is where the variable is\n * not set, was read as the option left out. Each run then answered a\n * question nobody had put, exit 0, where a tool never falls back to its\n * defaults and reports clean (spec-core ADR-0005).\n *\n * Pure: the command line as it was read, and the line that refuses it, or\n * `null`. The one thing only the disk knows, whether `--root` is a\n * directory, is asked of the caller.\n */\n\nimport { resolve } from 'node:path';\n\nimport { sameId } from './branch.js';\nimport { literal } from './literal.js';\n\n/** A command line as the parser read it; what `parseOptions` returns is one. */\nexport interface CommandLine {\n readonly command: string | undefined;\n readonly positionals: readonly string[];\n /** The long name of every option on it, in the order given. */\n readonly given: readonly string[];\n /** Every value of each option that takes one, by its long name, in the order given; the fields below hold the last. */\n readonly written: Readonly<Record<string, readonly string[]>>;\n readonly brief: string | undefined;\n readonly base: string | undefined;\n readonly root: string | undefined;\n readonly paths: readonly string[];\n readonly reason: string | undefined;\n readonly options: readonly string[];\n readonly recommend: string | undefined;\n readonly show: string | undefined;\n readonly id: string | undefined;\n /** Whether the line asks for the help, or for the version, which every command answers in place of running. */\n readonly help: boolean;\n readonly version: boolean;\n}\n\n/** Whether a value names nothing: empty, or only space. */\nexport function isBlank(value: string): boolean {\n return value.trim() === '';\n}\n\ninterface Valued {\n readonly of: (line: CommandLine) => readonly string[];\n /** What is said of a value that names nothing, and what to do instead. */\n readonly says: string;\n}\n\n// Every value an option that takes one was given, so that an empty one is\n// refused wherever it stands: `--root \"\" --root .` names one directory twice\n// as the root is read, and the empty value is still the unset variable it\n// most often is. An option left out has no value to refuse, and a value that\n// names something is passed over as none is: the empty list is equivalent\n// to its mutant.\nconst every =\n (option: string) =>\n (line: CommandLine): readonly string[] =>\n line.written[option] ?? [];\n\n/**\n * The options that take a value, and what an empty one fails to name.\n * `--format` and `--at` are not here: each takes one of a few words, and the\n * parser refuses any other, the empty one with them. Nor is `--note`, which\n * `rule` refuses by name itself.\n */\nconst VALUED = literal({\n brief: { of: every('brief'), says: \"names no brief; give it a brief's id, or leave it out for the one SPEC_BRIEF or the branch names\" },\n base: { of: every('base'), says: 'names no commit; give it a branch or a commit, or leave it out for the configured base' },\n root: { of: every('root'), says: 'names no directory; give it one, or leave it out to run in the current directory' },\n path: { of: (line) => line.paths, says: 'names no file; give it the path of a file' },\n reason: { of: every('reason'), says: 'gives no reason; say why the round cannot be done without the file' },\n option: { of: (line) => line.options, says: 'names no choice; give it \"<label>: <cost>\", or leave it out' },\n recommend: { of: every('recommend'), says: 'recommends nothing; say which option and why, or leave it out' },\n show: { of: every('show'), says: 'names no escalation; give it an id, as spec-harness escalate --list prints them' },\n id: { of: every('id'), says: \"names no probe; give it a probe's id, or leave it out to run every probe\" },\n}) satisfies Record<string, Valued>;\n\n/**\n * A resolved path with its drive letter in one case. On Windows a drive\n * letter names its volume in either case, `D:\\` and `d:\\` alike (Microsoft's\n * Naming Files, Paths, and Namespaces, Naming Conventions, read 2026-10-19),\n * where Node's `resolve` keeps the case it was written in (spec-core\n * ADR-0005, amended 2026-10-19). The rest of the path is left as it is: NTFS\n * can be made to tell names apart by case, so whether two names are one\n * directory is the disk's to say. A path resolved elsewhere starts with `/`,\n * and has no drive letter to fold.\n */\nexport function foldDrive(path: string): string {\n return /^[a-z]:/.test(path) ? `${path[0]!.toUpperCase()}${path.slice(1)}` : path;\n}\n\n/**\n * Whether two values of an option that takes one ask for one thing, as the\n * option reads them: a brief by its id as spec-brief's names are matched,\n * space around it dropped and `12` the brief `012` (ADR-0004); a root by the\n * directory it names from `cwd`, the one an empty root names on the hook's\n * line among them, with a drive letter in either case; any other as it is\n * written, since each is read so, a format, a probe's position, an id or\n * text.\n */\nfunction asksOne(option: string, first: string, other: string, cwd: string): boolean {\n if (option === 'brief') return sameId(first.trim(), other.trim());\n if (option === 'root') return foldDrive(resolve(cwd, first)) === foldDrive(resolve(cwd, other));\n return first === other;\n}\n\n/**\n * The first option that takes one value and was given two that read as two,\n * named with both as they were written; `null` where none was. The parser\n * keeps the last, and the earlier went unread with no word of it:\n * `doctor --root nowhere --root .` ran in `.`, and `--brief 404 --brief 001`\n * was brief 001 (spec-core ADR-0005). The same value given twice, however it\n * is spelled, is the option once, and the last is the one read. `cwd` is\n * where a relative root is read from. A list, `--path` and `--option`, has\n * every value it is given.\n */\nexport function twoValues(line: Pick<CommandLine, 'written'>, cwd: string): string | null {\n for (const [option, values] of Object.entries(line.written)) {\n const first = values[0]!;\n const other = values.find((value) => !asksOne(option, first, value, cwd));\n if (other !== undefined) return `--${option} is given twice, as ${JSON.stringify(first)} and as ${JSON.stringify(other)}, and one of the two would go unread`;\n }\n return null;\n}\n\nexport type ValuedOption = keyof typeof VALUED;\n\n/**\n * The line for a value that names nothing. `subject` is the input as its\n * caller knows it: `--brief` on a command line, `\"brief\"` in a tool call. The\n * value is shown as JSON, where a tab or a line break in it can be seen.\n */\nexport function emptyValue(subject: string, option: ValuedOption, value: string): string {\n return `${subject} is ${JSON.stringify(value)}, which ${VALUED[option].says}`;\n}\n\ninterface Shape {\n /** The options the command reads, by their long names. */\n readonly options: readonly string[];\n /** The most arguments it takes, with that said for the refusal of one more; `null` where it takes any number. */\n readonly limit: { readonly most: number; readonly takes: string } | null;\n /**\n * What an argument of it is, and what to do about an empty one; absent\n * where it takes none, or says so itself. `option` is the option that\n * names the same thing, where there is one: the two together are refused.\n * Only a brief is named both ways.\n */\n readonly argument?: { readonly role: string; readonly instead: string; readonly option?: 'brief' };\n /** The options whose empty value the command says in its own report. */\n readonly reports?: readonly string[];\n /**\n * The options that make the command another one, each with the only\n * options it reads beside it. The first on the list that is given decides,\n * as the command itself decides.\n */\n readonly modes?: readonly { readonly option: string; readonly beside: readonly string[] }[];\n}\n\nconst NO_ARGUMENT = literal({ limit: { most: 0, takes: 'no argument' } });\nconst ONE_BRIEF = literal({\n limit: { most: 1, takes: \"one argument at most, a brief's id\" },\n argument: { role: 'the brief', instead: \"give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names\", option: 'brief' },\n});\n\n/**\n * Every command, with what it reads of a command line. An option is listed\n * for a command only where the command's answer depends on it: `init`\n * chooses the base itself and the server is told the brief by each call, so\n * neither takes `--base` or `--brief`, and taking them would tell someone\n * the base or the brief had been set.\n */\nconst SHAPE = literal({\n context: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },\n guard: {\n options: ['brief', 'base', 'root', 'format', 'strict'],\n limit: null,\n argument: { role: 'a path', instead: 'give it the paths the round would write' },\n },\n hook: { options: ['brief', 'base', 'root'], limit: { most: 1, takes: 'one argument, \"claude\" or \"git\"' } },\n // `--list` and `--show` print what waits and raise nothing: neither reads\n // the parts of a request, nor a brief, since what waits is every round's.\n escalate: {\n options: ['brief', 'root', 'format', 'path', 'reason', 'option', 'recommend', 'list', 'show'],\n ...NO_ARGUMENT,\n modes: [\n { option: 'list', beside: ['root', 'format'] },\n { option: 'show', beside: ['root', 'format'] },\n ],\n },\n rule: {\n options: ['root', 'format', 'allow', 'deny', 'note'],\n limit: { most: 1, takes: \"one argument, the escalation's id\" },\n argument: { role: 'the escalation', instead: 'give it an id, as spec-harness escalate --list prints them' },\n },\n rulings: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },\n audit: { options: ['brief', 'base', 'root', 'format', 'strict'], ...ONE_BRIEF },\n probe: { options: ['brief', 'base', 'root', 'format', 'id', 'at'], ...ONE_BRIEF },\n premises: { options: ['brief', 'root', 'format', 'strict'], ...NO_ARGUMENT },\n init: { options: ['root', 'format', 'write', 'git-hook', 'block-on-failure'], ...NO_ARGUMENT },\n mcp: { options: ['root'], ...NO_ARGUMENT },\n // A diagnosis says what is wrong with what it was given, where a command\n // that acts on it stops: a brief or a base that names nothing is a line of\n // doctor's report.\n doctor: { options: ['brief', 'base', 'root', 'format', 'strict'], ...NO_ARGUMENT, reports: ['brief', 'base'] },\n}) satisfies Record<string, Shape>;\n\n/** The options every command answers instead of running, which no shape lists. */\nconst ANSWERS: readonly string[] = ['help', 'version'];\n\n/** Every command there is: the command line dispatches on these names and no other. */\nexport type Command = keyof typeof SHAPE;\n\n// A map, since a command is a word a person types and an object answers to\n// more names than it was given: `constructor` has no shape.\nconst SHAPES: ReadonlyMap<string, Shape> = new Map(Object.entries(SHAPE));\n\nfunction listed(options: readonly string[]): string {\n const names = options.map((option) => `--${option}`);\n // Every command reads at least `--root`, so a list is never empty.\n if (names.length === 1) return `its only option is ${names[0] as string}`;\n return `its options are ${names.slice(0, -1).join(', ')} and ${names.at(-1)!}`;\n}\n\n/**\n * Whether a line is Claude Code's hook, by its command and the argument\n * after it. It is exempt from every refusal here, and read as each release\n * since 0.1.0 read it: the line lives in settings files and in the plugin of\n * every release, which this one cannot rewrite, and exit 2 from it holds\n * every write of a session, the write that would fix the line among them.\n * A line the parser cannot read is asked the same, and the hook says it\n * to the person with exit 0 (cli.ts).\n */\nexport function isClaudeHook(command: string | undefined, argument: string | undefined): boolean {\n return command === 'hook' && argument === 'claude';\n}\n\n/** The words for a `--root` that is a file, or is not there, wherever it is said. */\nexport function noDirectory(root: string): string {\n return `--root is \"${root}\", which is not a directory`;\n}\n\n/** What is wrong with the line of Claude Code's hook, and what mends it. */\nexport interface LineFault {\n readonly wrong: string;\n readonly mend: string;\n}\n\n/**\n * What Claude Code's hook does with its own line, as far as the line decides\n * it: it guards, in the root the line gives it where it gives one and under\n * the brief it names where it names one; or the guard is off, for a fault\n * the hook says with exit 0 and holds no write for; or every write is held,\n * exit 2, for a brief the line names that is not one (ADR-0005). The hook\n * reads its line through the functions below, and `doctor` reads a line it\n * finds in Claude Code's settings through the same ones, so what it says of\n * a line is what the hook does with it.\n */\nexport type HookLine = Guards | GuardOff | WritesHeld;\n\nexport interface Guards {\n readonly state: 'guards';\n readonly root: string | undefined;\n /**\n * The brief the line names with `--brief`, as written. Whether it is a\n * brief is spec-brief's to say, which the caller asks. Absent where the\n * line names none.\n */\n readonly brief?: string;\n /**\n * The work tree the root is in, where that is not the project's own and\n * holds it: the hook opens the work tree its root is in, so a write to a\n * file of the project is checked there, by that work tree's briefs, under\n * the path the file has in it. Only git can tell, so the caller asks it.\n * Absent where the line gives no root, or one in the project's work tree.\n */\n readonly holder?: OtherTree & { readonly path: string };\n}\n\n/** A work tree the root on the hook's line is in that is not the project's own. */\nexport interface OtherTree {\n /** Its top, as git names it. */\n readonly top: string;\n /** Whether it is a work tree of the project's own repository, linked or main, where it is otherwise another repository's. */\n readonly ours: boolean;\n}\n\n/** How such a work tree is named: by its top, and whose it is. */\nexport function namedTree({ top, ours }: OtherTree): string {\n return `${top}, ${ours ? 'another work tree of this repository' : 'the work tree of another repository'}`;\n}\n\nexport interface GuardOff {\n readonly state: 'off';\n readonly fault: LineFault;\n /**\n * Set where the hook says nothing of the fault: a root outside any work\n * tree, or in a work tree that does not hold the project. Every other\n * fault it says, to the person, and every one with exit 0.\n */\n readonly silent?: true;\n /**\n * What goes unchecked, where that is not every write: under a root in a\n * work tree that does not hold the project, the hook checks a write to a\n * file of that work tree, and none to a file of the project.\n */\n readonly unchecked?: string;\n}\n\nexport interface WritesHeld {\n readonly state: 'held';\n /** What is said of the name, by what named the brief (workspace.ts). */\n readonly wrong: string;\n}\n\n/**\n * A line under which the round has no brief to be checked against, since\n * what names one names a brief spec-brief does not know, or one it has\n * archived: the hook holds the write, exit 2, and every write after it until\n * the name is mended (ADR-0004). `wrong` is what is said of the name.\n */\nexport function heldHookLine(wrong: string): WritesHeld {\n return { state: 'held', wrong };\n}\n\n/**\n * A line the parser refused: an option no command has, an option left\n * without its value, a `--format` or an `--at` that is none, `--help` beside\n * `--version`; or a line it read with two values for an option that takes\n * one, of which it cannot tell the one meant ({@link twoValues}). The\n * parser's words are kept, on one line: what node says of an option that may\n * have lost its value is three.\n */\nexport function unreadHookLine(said: string): GuardOff {\n return { state: 'off', fault: { wrong: `the hook's line cannot be read (${said.split('\\n').join(' ')})`, mend: 'mend it in Claude Code\\'s settings, where init writes \"hook claude\" and nothing after it' } };\n}\n\n/**\n * A line that parsed, by the root it gives. An empty root is the directory\n * the hook was started in: git starts there when it is handed no directory,\n * so the hook has guarded there for an empty root in every release. A root\n * that is a file, or is not there, is one git starts in neither of, which\n * read as a session outside a work tree, exit 0 and no word, and the guard\n * someone had configured was off.\n */\nexport function readHookLine(root: string | undefined, cwd: string, isDirectory: (path: string) => boolean): Guards | GuardOff {\n const given = root === '' ? cwd : root;\n if (given !== undefined && !isDirectory(given)) {\n return { state: 'off', fault: { wrong: noDirectory(given), mend: \"give the hook's line a directory that exists, or leave --root out for the project Claude Code names\" } };\n }\n return { state: 'guards', root: given };\n}\n\n/**\n * What `--help` or `--version` on the hook's line stands beside that the\n * hook would say as it runs, in the words for a line it cannot read; `null`\n * where the line asks for neither, or stands beside nothing the line itself\n * shows to be wrong. Every command answers either before it runs, so the\n * hook printed the help over a root that is not a directory, exit 0, and\n * said nothing of it (ADR-0005). A fault only git or spec-brief can tell\n * stays unsaid: neither is asked before an answer that runs nothing.\n */\nexport function answerBeside(line: Pick<CommandLine, 'help' | 'version' | 'root'>, cwd: string, isDirectory: (path: string) => boolean): string | null {\n if (!line.help && !line.version) return null;\n const read = readHookLine(line.root, cwd, isDirectory);\n if (read.state === 'guards') return null;\n const asked = line.help ? 'help' : 'version';\n return `--${asked} is given beside a fault, ${read.fault.wrong}, and the ${asked} would be printed in its place`;\n}\n\n/**\n * A line of the hook's that asks for the help or the version, which the hook\n * prints, exit 0, in place of reading its question: no write is checked\n * under it, and Claude Code, by its hooks reference, writes what a hook\n * that exits 0 prints to its debug log, so nothing says the guard is off\n * (ADR-0005). The hook says nothing of it, since a person who asks the hook\n * for its help at a terminal is answered the same way.\n */\nexport function answeringHookLine(asked: 'help' | 'version'): GuardOff {\n return {\n state: 'off',\n silent: true,\n fault: {\n wrong: `the line asks for the ${asked}, which the hook prints, exit 0, in place of checking the write`,\n mend: 'take that option off the line, where init writes \"hook claude\" and nothing after it',\n },\n };\n}\n\n/**\n * A line whose root is a directory outside any git work tree. The hook\n * reads that as a session outside one, where it has nothing to guard: it\n * checks no write and says nothing, exit 0 (ADR-0005), and that stays. Only\n * git can tell such a root, so the caller asks it. A line that carries one\n * is a guard someone set up that checks nothing, and `doctor` says it as\n * off.\n */\nexport function outsideHookLine(root: string): GuardOff {\n return {\n state: 'off',\n silent: true,\n fault: {\n wrong: `--root is \"${root}\", a directory outside any git work tree, which the hook reads as a session outside one, exit 0 and no word`,\n mend: \"give the hook's line a directory in the work tree, or leave --root out for the project Claude Code names\",\n },\n };\n}\n\n/**\n * A line whose root is in a git work tree that does not hold the project:\n * another repository beside it, or a work tree inside it, a repository of\n * its own, a submodule or a linked worktree. The hook opens the work tree\n * its root is in and decides by that work tree's briefs. A file of the\n * project is outside it, which the hook reads as a file outside the\n * repository: it says nothing, exit 0, as it has in every release, and that\n * stays. So no write to a file of the project is checked under the line,\n * and `doctor` says it as a guard that is off. Only git can tell such a\n * root, so the caller asks it.\n */\nexport function elsewhereHookLine(root: string, tree: OtherTree): GuardOff {\n return {\n state: 'off',\n silent: true,\n unchecked: 'no write to a file of this project is checked',\n fault: {\n wrong: `--root is \"${root}\", a directory in ${namedTree(tree)}, which does not hold this project: the hook checks a write to a file of that work tree, by its briefs, and passes any other with no word, exit 0`,\n mend: \"give the hook's line a directory in this work tree, or leave --root out for the project Claude Code names\",\n },\n };\n}\n\n/**\n * A line that guards under a root in a work tree which holds the project\n * and is not its own: a repository the project is nested in, or the main\n * work tree around a linked one. `path` is the project's top as that work\n * tree names it.\n */\nexport function holderHookLine(line: Guards, tree: OtherTree, path: string): Guards {\n return { ...line, holder: { ...tree, path } };\n}\n\n/**\n * What Claude Code's hook does with the words it is handed, or `null` for\n * words that are not its line: read by the parser the command line reads\n * every line with, and known by its command and the argument after it on a\n * line that parsed and on one that did not, as the command line knows it\n * (cli.ts). `parse` is that parser, which throws its refusal with the words\n * it could still read.\n *\n * A line that guards says which brief it names, where it names one: the hook\n * passes over a `--brief` that is empty, as every release has, and holds\n * every write under one that names no brief, which only spec-brief can tell.\n * A line with two values for an option that takes one is a line the hook\n * cannot read, whichever option it is, read from `cwd` as the hook reads it\n * from where it is started (cli.ts). So is one with the help or the version\n * beside a root that is not a directory; and with either beside nothing it\n * can see is wrong, the line checks no write, whatever else it holds.\n */\nexport function claudeHookLine(\n words: readonly string[],\n parse: (argv: readonly string[]) => CommandLine,\n cwd: string,\n isDirectory: (path: string) => boolean,\n): HookLine | null {\n let line: CommandLine;\n try {\n line = parse(words);\n } catch (error) {\n const refused = error as { readonly message: string; readonly words: readonly string[] };\n return isClaudeHook(refused.words[0], refused.words[1]) ? unreadHookLine(refused.message) : null;\n }\n if (!isClaudeHook(line.command, line.positionals[0])) return null;\n const twice = twoValues(line, cwd);\n if (twice !== null) return unreadHookLine(twice);\n const beside = answerBeside(line, cwd, isDirectory);\n if (beside !== null) return unreadHookLine(beside);\n if (line.help) return answeringHookLine('help');\n if (line.version) return answeringHookLine('version');\n const read = readHookLine(line.root, cwd, isDirectory);\n return read.state === 'guards' && line.brief !== undefined && !isBlank(line.brief) ? { ...read, brief: line.brief } : read;\n}\n\n/**\n * Why the command line is refused, or `null` when the command can run:\n * an option it does not read, alone or beside another, an argument it does\n * not take, a brief named twice, a value or an argument that names nothing,\n * a `--root` that is no directory. Asked once a command is known, and before\n * `--help` or `--version` answers: a line that is wrong is refused with\n * either on it, as one the parser refuses always was (spec-core ADR-0005).\n * A command with no shape is none, which its caller says.\n */\nexport function refusal(line: CommandLine, isDirectory: (path: string) => boolean): string | null {\n const { command, positionals } = line;\n // No shape is kept under `undefined`, so the first check is the compiler's,\n // and its mutant is equivalent.\n if (command === undefined) return null;\n const shape = SHAPES.get(command);\n if (shape === undefined || isClaudeHook(command, positionals[0])) return null;\n // What the line asks the command, beside the help or the version it may\n // ask for instead, which every command answers.\n const asked = line.given.filter((option) => !ANSWERS.includes(option));\n const stray = asked.find((option) => !shape.options.includes(option));\n if (stray !== undefined) return `${command} does not take --${stray}; ${listed(shape.options)}`;\n // An option the command reads, beside one that leaves it unread:\n // `escalate --list --path src/a.ts` printed the list, exit 0, and the\n // request it also spelled out was never raised.\n const mode = shape.modes?.find((candidate) => asked.includes(candidate.option));\n if (mode !== undefined) {\n const unread = asked.find((option) => option !== mode.option && !mode.beside.includes(option));\n if (unread !== undefined) return `${command} --${mode.option} does not take --${unread}; beside --${mode.option} ${listed(mode.beside)}`;\n }\n if (shape.limit !== null && positionals.length > shape.limit.most) {\n return `${command} takes ${shape.limit.takes}, not ${positionals.map((argument) => JSON.stringify(argument)).join(', ')}`;\n }\n // One thing named two ways, whatever the two hold: the argument won with\n // no word, so `audit 012 --brief 013` audited 012 for someone who had\n // also typed 013.\n const { argument } = shape;\n if (argument?.option !== undefined && positionals.length > 0 && line.given.includes(argument.option)) {\n return `${command} was given ${argument.role} twice, as its argument ${JSON.stringify(positionals[0])} and as --${argument.option} ${JSON.stringify(line[argument.option])}; give one of them`;\n }\n for (const [option, valued] of Object.entries(VALUED) as [ValuedOption, Valued][]) {\n if (shape.reports?.includes(option)) continue;\n const empty = valued.of(line).find(isBlank);\n if (empty !== undefined) return emptyValue(`--${option}`, option, empty);\n }\n const empty = positionals.find(isBlank);\n if (shape.argument !== undefined && empty !== undefined) {\n return `${command} was given ${JSON.stringify(empty)} as ${shape.argument.role}, which names none; ${shape.argument.instead}`;\n }\n // An empty one was refused above, so this is a path that was meant: a file,\n // or a directory that is not there. git starts in neither, and the run\n // ended saying the path was outside a work tree, which named neither the\n // option nor what was wrong with what it was given.\n if (line.root !== undefined && !isDirectory(line.root)) {\n return `${noDirectory(line.root)}; give it one that exists, or leave it out to run in the current directory`;\n }\n return null;\n}\n"]}
|
package/dist/workspace.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { type ActiveBrief } from './briefs.js';
|
|
6
6
|
import type { HarnessConfig } from './config.js';
|
|
7
|
+
import { type WorkTree } from './git.js';
|
|
7
8
|
import type { FindingFormat } from './formats.js';
|
|
8
9
|
import { type Siblings } from './siblings.js';
|
|
9
10
|
import type { BriefRow } from './types.js';
|
|
@@ -41,6 +42,12 @@ export interface Options {
|
|
|
41
42
|
readonly positionals: readonly string[];
|
|
42
43
|
/** The long name of every option given, in the order given: what tells an option left out from one a command does not read. */
|
|
43
44
|
readonly given: readonly string[];
|
|
45
|
+
/**
|
|
46
|
+
* Every value given to each option that takes one value, by its long name,
|
|
47
|
+
* in the order given. The fields below hold the last of them, which is
|
|
48
|
+
* what the parser keeps.
|
|
49
|
+
*/
|
|
50
|
+
readonly written: Readonly<Record<string, readonly string[]>>;
|
|
44
51
|
readonly brief: string | undefined;
|
|
45
52
|
readonly base: string | undefined;
|
|
46
53
|
readonly root: string | undefined;
|
|
@@ -53,6 +60,8 @@ export interface Options {
|
|
|
53
60
|
readonly write: boolean;
|
|
54
61
|
/** init: also install git's pre-commit hook. */
|
|
55
62
|
readonly gitHook: boolean;
|
|
63
|
+
/** init: `onFailure: "block"` on the hook entries it writes (ADR-0012). */
|
|
64
|
+
readonly blockOnFailure: boolean;
|
|
56
65
|
/** escalate: the files the round needs, the reason, the options and the recommendation. */
|
|
57
66
|
readonly paths: readonly string[];
|
|
58
67
|
readonly reason: string | undefined;
|
|
@@ -81,7 +90,38 @@ export interface Workspace {
|
|
|
81
90
|
readonly branchSource?: string | undefined;
|
|
82
91
|
readonly cwd: string;
|
|
83
92
|
}
|
|
84
|
-
|
|
93
|
+
/**
|
|
94
|
+
* A work tree as the first wave of opening it found it: the directory it
|
|
95
|
+
* was asked from, its top, what one start of git said from there, and the
|
|
96
|
+
* branch where it was asked beside them.
|
|
97
|
+
*/
|
|
98
|
+
export interface FoundTree {
|
|
99
|
+
readonly cwd: string;
|
|
100
|
+
readonly root: string;
|
|
101
|
+
readonly tree: WorkTree | 'unread';
|
|
102
|
+
readonly early: string | null | undefined;
|
|
103
|
+
}
|
|
104
|
+
/** The work tree that holds `cwd`, or `null` where none does. */
|
|
105
|
+
export declare function findTree(cwd: string): Promise<FoundTree | null>;
|
|
106
|
+
/**
|
|
107
|
+
* The git directory a found work tree's repository keeps, as git names it
|
|
108
|
+
* from the directory it was found from: one repository's work trees, linked
|
|
109
|
+
* and main, share it, and no two repositories do. Asked again only where
|
|
110
|
+
* the one start of git could not be read.
|
|
111
|
+
*/
|
|
112
|
+
export declare function foundCommonDir(found: FoundTree): Promise<string | null>;
|
|
113
|
+
export declare function openWorkspace(options: Pick<Options, 'root'>, io: CliIO, installs?: Installs): Promise<Workspace>;
|
|
114
|
+
/** The installs a work tree's siblings are looked for in after its own, given its top and its common directory (siblings.ts). */
|
|
115
|
+
export type Installs = (root: string, commonDir: string) => readonly string[];
|
|
116
|
+
/**
|
|
117
|
+
* Every command: a linked worktree with no install of its own is checked
|
|
118
|
+
* with the main work tree's, where `git worktree add` leaves the project's
|
|
119
|
+
* `node_modules`, as git's hook and doctor were, and as the hook is with the
|
|
120
|
+
* project's (ADR-0005).
|
|
121
|
+
*/
|
|
122
|
+
export declare const MAIN_INSTALL: Installs;
|
|
123
|
+
/** The rest of opening a work tree, once it is found: its common directory, its configuration and its branch. */
|
|
124
|
+
export declare function openFound(found: FoundTree, io: CliIO, installs?: Installs): Promise<Workspace>;
|
|
85
125
|
/**
|
|
86
126
|
* What one of several things asked at once answered, or what it threw,
|
|
87
127
|
* thrown from here: the things are asked through `Promise.allSettled`, and
|
|
@@ -118,3 +158,42 @@ export declare function describeActive(active: ActiveBrief, argument?: string):
|
|
|
118
158
|
problem: string;
|
|
119
159
|
};
|
|
120
160
|
export declare function json(command: string, body: Record<string, unknown>): string;
|
|
161
|
+
/**
|
|
162
|
+
* Whether a work tree other than the one whose top is `top` may hold `cwd`:
|
|
163
|
+
* `cwd` is outside it, or a `.git` stands in a directory between the two,
|
|
164
|
+
* where a linked worktree, a submodule or a repository of its own starts.
|
|
165
|
+
* Where neither is so, `cwd` is in that work tree, and git is asked nothing
|
|
166
|
+
* more: a session works at its project's top, or below it, for nearly every
|
|
167
|
+
* write. Answering that one may is what git is then asked, so the mutant
|
|
168
|
+
* that always answers so is equivalent, at the cost of a process, and so
|
|
169
|
+
* is each that only answers so more often: a slice one short reaches the
|
|
170
|
+
* top itself, which holds a `.git`, and a part named in place of none is
|
|
171
|
+
* a directory no top holds.
|
|
172
|
+
*/
|
|
173
|
+
export declare function mayBeElsewhere(cwd: string, top: string): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* The work tree that holds `cwd`, where it is another work tree of the
|
|
176
|
+
* repository the work tree `named` is one of, as the hook's root names it, by the git directory the two share;
|
|
177
|
+
* `null` where `cwd` is in the root's own, in another repository, or in
|
|
178
|
+
* none (ADR-0005).
|
|
179
|
+
*/
|
|
180
|
+
export declare function otherTree(named: Workspace, cwd: string): Promise<FoundTree | null>;
|
|
181
|
+
/**
|
|
182
|
+
* The work trees a write is decided in, each with the paths it decides, for
|
|
183
|
+
* the hook and for the server's `check_path` (ADR-0005). The repository is
|
|
184
|
+
* the one the hook's root names, as before. Each path is decided by the
|
|
185
|
+
* innermost work tree of that repository that holds it, by its branch, its
|
|
186
|
+
* briefs and its configuration, read from its top, with its siblings looked
|
|
187
|
+
* for in its install and then the project's: there a session works in a
|
|
188
|
+
* worktree while Claude Code names the project it started in, or writes from
|
|
189
|
+
* one into another, and the hook decided by the project's branch, which
|
|
190
|
+
* named no brief, so a protected write passed with no word. A path in no
|
|
191
|
+
* other work tree of the repository is decided by the work tree the root
|
|
192
|
+
* names, as before: a write to the project's own file from a worktree is
|
|
193
|
+
* refused where it was, and a path in another repository, or in none, is
|
|
194
|
+
* read as it was. `cwd` is what a relative path is read from.
|
|
195
|
+
*/
|
|
196
|
+
export declare function writesBy(named: Workspace, cwd: string | null, paths: readonly string[], io: CliIO): Promise<{
|
|
197
|
+
readonly workspace: Workspace;
|
|
198
|
+
readonly paths: readonly string[];
|
|
199
|
+
}[]>;
|