@descent-vtt/spec-harness 0.11.1 → 0.13.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 +159 -0
- package/README.md +68 -10
- package/dist/briefs.d.ts +10 -5
- package/dist/briefs.js +5 -3
- package/dist/briefs.js.map +1 -1
- package/dist/cli.d.ts +7 -6
- package/dist/cli.js +99 -30
- package/dist/cli.js.map +1 -1
- package/dist/commands.d.ts +5 -1
- package/dist/commands.js +32 -11
- package/dist/commands.js.map +1 -1
- package/dist/context.js +4 -1
- package/dist/context.js.map +1 -1
- package/dist/fs.d.ts +2 -0
- package/dist/fs.js +16 -1
- package/dist/fs.js.map +1 -1
- package/dist/premises.js +11 -1
- package/dist/premises.js.map +1 -1
- package/dist/round.js +3 -1
- package/dist/round.js.map +1 -1
- package/dist/rulings.js +3 -1
- package/dist/rulings.js.map +1 -1
- package/dist/sandbox.d.ts +24 -13
- package/dist/sandbox.js +88 -16
- package/dist/sandbox.js.map +1 -1
- package/dist/server.js +85 -24
- package/dist/server.js.map +1 -1
- package/dist/usage.d.ts +224 -0
- package/dist/usage.js +178 -0
- package/dist/usage.js.map +1 -0
- package/dist/workspace.d.ts +9 -2
- package/dist/workspace.js +18 -4
- package/dist/workspace.js.map +1 -1
- package/package.json +3 -3
package/dist/usage.d.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a command line that parsed has still to be before it runs.
|
|
3
|
+
*
|
|
4
|
+
* The parser says what was typed. Whether it names anything was left to each
|
|
5
|
+
* command, and most never asked: an option another command reads was taken
|
|
6
|
+
* and did nothing, an argument no command asked for was dropped, and an
|
|
7
|
+
* option given an empty value, as `--root "$DIR"` is where the variable is
|
|
8
|
+
* not set, was read as the option left out. Each run then answered a
|
|
9
|
+
* question nobody had put, exit 0, where a tool never falls back to its
|
|
10
|
+
* defaults and reports clean (spec-core ADR-0005).
|
|
11
|
+
*
|
|
12
|
+
* Pure: the command line as it was read, and the line that refuses it, or
|
|
13
|
+
* `null`. The one thing only the disk knows, whether `--root` is a
|
|
14
|
+
* directory, is asked of the caller.
|
|
15
|
+
*/
|
|
16
|
+
/** A command line as the parser read it; what `parseOptions` returns is one. */
|
|
17
|
+
export interface CommandLine {
|
|
18
|
+
readonly command: string | undefined;
|
|
19
|
+
readonly positionals: readonly string[];
|
|
20
|
+
/** The long name of every option on it, in the order given. */
|
|
21
|
+
readonly given: readonly string[];
|
|
22
|
+
readonly brief: string | undefined;
|
|
23
|
+
readonly base: string | undefined;
|
|
24
|
+
readonly root: string | undefined;
|
|
25
|
+
readonly paths: readonly string[];
|
|
26
|
+
readonly reason: string | undefined;
|
|
27
|
+
readonly options: readonly string[];
|
|
28
|
+
readonly recommend: string | undefined;
|
|
29
|
+
readonly show: string | undefined;
|
|
30
|
+
readonly id: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** Whether a value names nothing: empty, or only space. */
|
|
33
|
+
export declare function isBlank(value: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The options that take a value, and what an empty one fails to name.
|
|
36
|
+
* `--format` and `--at` are not here: each takes one of a few words, and the
|
|
37
|
+
* parser refuses any other, the empty one with them. Nor is `--note`, which
|
|
38
|
+
* `rule` refuses by name itself.
|
|
39
|
+
*/
|
|
40
|
+
declare const VALUED: {
|
|
41
|
+
readonly brief: {
|
|
42
|
+
readonly of: (line: CommandLine) => readonly string[];
|
|
43
|
+
readonly says: "names no brief; give it a brief's id, or leave it out for the one SPEC_BRIEF or the branch names";
|
|
44
|
+
};
|
|
45
|
+
readonly base: {
|
|
46
|
+
readonly of: (line: CommandLine) => readonly string[];
|
|
47
|
+
readonly says: 'names no commit; give it a branch or a commit, or leave it out for the configured base';
|
|
48
|
+
};
|
|
49
|
+
readonly root: {
|
|
50
|
+
readonly of: (line: CommandLine) => readonly string[];
|
|
51
|
+
readonly says: 'names no directory; give it one, or leave it out to run in the current directory';
|
|
52
|
+
};
|
|
53
|
+
readonly path: {
|
|
54
|
+
readonly of: (line: CommandLine) => readonly string[];
|
|
55
|
+
readonly says: 'names no file; give it the path of a file';
|
|
56
|
+
};
|
|
57
|
+
readonly reason: {
|
|
58
|
+
readonly of: (line: CommandLine) => readonly string[];
|
|
59
|
+
readonly says: 'gives no reason; say why the round cannot be done without the file';
|
|
60
|
+
};
|
|
61
|
+
readonly option: {
|
|
62
|
+
readonly of: (line: CommandLine) => readonly string[];
|
|
63
|
+
readonly says: 'names no choice; give it "<label>: <cost>", or leave it out';
|
|
64
|
+
};
|
|
65
|
+
readonly recommend: {
|
|
66
|
+
readonly of: (line: CommandLine) => readonly string[];
|
|
67
|
+
readonly says: 'recommends nothing; say which option and why, or leave it out';
|
|
68
|
+
};
|
|
69
|
+
readonly show: {
|
|
70
|
+
readonly of: (line: CommandLine) => readonly string[];
|
|
71
|
+
readonly says: 'names no escalation; give it an id, as spec-harness escalate --list prints them';
|
|
72
|
+
};
|
|
73
|
+
readonly id: {
|
|
74
|
+
readonly of: (line: CommandLine) => readonly string[];
|
|
75
|
+
readonly says: "names no probe; give it a probe's id, or leave it out to run every probe";
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export type ValuedOption = keyof typeof VALUED;
|
|
79
|
+
/**
|
|
80
|
+
* The line for a value that names nothing. `subject` is the input as its
|
|
81
|
+
* caller knows it: `--brief` on a command line, `"brief"` in a tool call. The
|
|
82
|
+
* value is shown as JSON, where a tab or a line break in it can be seen.
|
|
83
|
+
*/
|
|
84
|
+
export declare function emptyValue(subject: string, option: ValuedOption, value: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Every command, with what it reads of a command line. An option is listed
|
|
87
|
+
* for a command only where the command's answer depends on it: `init`
|
|
88
|
+
* chooses the base itself and the server is told the brief by each call, so
|
|
89
|
+
* neither takes `--base` or `--brief`, and taking them would tell someone
|
|
90
|
+
* the base or the brief had been set.
|
|
91
|
+
*/
|
|
92
|
+
declare const SHAPE: {
|
|
93
|
+
readonly context: {
|
|
94
|
+
readonly limit: {
|
|
95
|
+
readonly most: 1;
|
|
96
|
+
readonly takes: "one argument at most, a brief's id";
|
|
97
|
+
};
|
|
98
|
+
readonly argument: {
|
|
99
|
+
readonly role: 'the brief';
|
|
100
|
+
readonly instead: "give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names";
|
|
101
|
+
readonly option: 'brief';
|
|
102
|
+
};
|
|
103
|
+
readonly options: readonly ["brief", "base", "root", "format"];
|
|
104
|
+
};
|
|
105
|
+
readonly guard: {
|
|
106
|
+
readonly options: readonly ["brief", "base", "root", "format", "strict"];
|
|
107
|
+
readonly limit: null;
|
|
108
|
+
readonly argument: {
|
|
109
|
+
readonly role: 'a path';
|
|
110
|
+
readonly instead: 'give it the paths the round would write';
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
readonly hook: {
|
|
114
|
+
readonly options: readonly ["brief", "base", "root"];
|
|
115
|
+
readonly limit: {
|
|
116
|
+
readonly most: 1;
|
|
117
|
+
readonly takes: 'one argument, "claude" or "git"';
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
readonly escalate: {
|
|
121
|
+
readonly limit: {
|
|
122
|
+
readonly most: 0;
|
|
123
|
+
readonly takes: 'no argument';
|
|
124
|
+
};
|
|
125
|
+
readonly options: readonly ["brief", "root", "format", "path", "reason", "option", "recommend", "list", "show"];
|
|
126
|
+
readonly modes: readonly [{
|
|
127
|
+
readonly option: 'list';
|
|
128
|
+
readonly beside: readonly ["root", "format"];
|
|
129
|
+
}, {
|
|
130
|
+
readonly option: 'show';
|
|
131
|
+
readonly beside: readonly ["root", "format"];
|
|
132
|
+
}];
|
|
133
|
+
};
|
|
134
|
+
readonly rule: {
|
|
135
|
+
readonly options: readonly ["root", "format", "allow", "deny", "note"];
|
|
136
|
+
readonly limit: {
|
|
137
|
+
readonly most: 1;
|
|
138
|
+
readonly takes: "one argument, the escalation's id";
|
|
139
|
+
};
|
|
140
|
+
readonly argument: {
|
|
141
|
+
readonly role: 'the escalation';
|
|
142
|
+
readonly instead: 'give it an id, as spec-harness escalate --list prints them';
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
readonly rulings: {
|
|
146
|
+
readonly limit: {
|
|
147
|
+
readonly most: 1;
|
|
148
|
+
readonly takes: "one argument at most, a brief's id";
|
|
149
|
+
};
|
|
150
|
+
readonly argument: {
|
|
151
|
+
readonly role: 'the brief';
|
|
152
|
+
readonly instead: "give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names";
|
|
153
|
+
readonly option: 'brief';
|
|
154
|
+
};
|
|
155
|
+
readonly options: readonly ["brief", "base", "root", "format"];
|
|
156
|
+
};
|
|
157
|
+
readonly audit: {
|
|
158
|
+
readonly limit: {
|
|
159
|
+
readonly most: 1;
|
|
160
|
+
readonly takes: "one argument at most, a brief's id";
|
|
161
|
+
};
|
|
162
|
+
readonly argument: {
|
|
163
|
+
readonly role: 'the brief';
|
|
164
|
+
readonly instead: "give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names";
|
|
165
|
+
readonly option: 'brief';
|
|
166
|
+
};
|
|
167
|
+
readonly options: readonly ["brief", "base", "root", "format", "strict"];
|
|
168
|
+
};
|
|
169
|
+
readonly probe: {
|
|
170
|
+
readonly limit: {
|
|
171
|
+
readonly most: 1;
|
|
172
|
+
readonly takes: "one argument at most, a brief's id";
|
|
173
|
+
};
|
|
174
|
+
readonly argument: {
|
|
175
|
+
readonly role: 'the brief';
|
|
176
|
+
readonly instead: "give it a brief's id, or leave it out for the one --brief, SPEC_BRIEF or the branch names";
|
|
177
|
+
readonly option: 'brief';
|
|
178
|
+
};
|
|
179
|
+
readonly options: readonly ["brief", "base", "root", "format", "id", "at"];
|
|
180
|
+
};
|
|
181
|
+
readonly premises: {
|
|
182
|
+
readonly limit: {
|
|
183
|
+
readonly most: 0;
|
|
184
|
+
readonly takes: 'no argument';
|
|
185
|
+
};
|
|
186
|
+
readonly options: readonly ["brief", "root", "format", "strict"];
|
|
187
|
+
};
|
|
188
|
+
readonly init: {
|
|
189
|
+
readonly limit: {
|
|
190
|
+
readonly most: 0;
|
|
191
|
+
readonly takes: 'no argument';
|
|
192
|
+
};
|
|
193
|
+
readonly options: readonly ["root", "format", "write", "git-hook"];
|
|
194
|
+
};
|
|
195
|
+
readonly mcp: {
|
|
196
|
+
readonly limit: {
|
|
197
|
+
readonly most: 0;
|
|
198
|
+
readonly takes: 'no argument';
|
|
199
|
+
};
|
|
200
|
+
readonly options: readonly ["root"];
|
|
201
|
+
};
|
|
202
|
+
readonly doctor: {
|
|
203
|
+
readonly limit: {
|
|
204
|
+
readonly most: 0;
|
|
205
|
+
readonly takes: 'no argument';
|
|
206
|
+
};
|
|
207
|
+
readonly options: readonly ["brief", "base", "root", "format", "strict"];
|
|
208
|
+
readonly reports: readonly ["brief", "base"];
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
/** Every command there is: the command line dispatches on these names and no other. */
|
|
212
|
+
export type Command = keyof typeof SHAPE;
|
|
213
|
+
/** The words for a `--root` that is a file, or is not there, wherever it is said. */
|
|
214
|
+
export declare function noDirectory(root: string): string;
|
|
215
|
+
/**
|
|
216
|
+
* Why the command line is refused, or `null` when the command can run:
|
|
217
|
+
* an option it does not read, alone or beside another, an argument it does
|
|
218
|
+
* not take, a brief named twice, a value or an argument that names nothing,
|
|
219
|
+
* a `--root` that is no directory. Asked once a command is known and neither
|
|
220
|
+
* `--help` nor `--version` answers instead; a command with no shape is none,
|
|
221
|
+
* which its caller says.
|
|
222
|
+
*/
|
|
223
|
+
export declare function refusal(line: CommandLine, isDirectory: (path: string) => boolean): string | null;
|
|
224
|
+
export {};
|
package/dist/usage.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a command line that parsed has still to be before it runs.
|
|
3
|
+
*
|
|
4
|
+
* The parser says what was typed. Whether it names anything was left to each
|
|
5
|
+
* command, and most never asked: an option another command reads was taken
|
|
6
|
+
* and did nothing, an argument no command asked for was dropped, and an
|
|
7
|
+
* option given an empty value, as `--root "$DIR"` is where the variable is
|
|
8
|
+
* not set, was read as the option left out. Each run then answered a
|
|
9
|
+
* question nobody had put, exit 0, where a tool never falls back to its
|
|
10
|
+
* defaults and reports clean (spec-core ADR-0005).
|
|
11
|
+
*
|
|
12
|
+
* Pure: the command line as it was read, and the line that refuses it, or
|
|
13
|
+
* `null`. The one thing only the disk knows, whether `--root` is a
|
|
14
|
+
* directory, is asked of the caller.
|
|
15
|
+
*/
|
|
16
|
+
/** Whether a value names nothing: empty, or only space. */
|
|
17
|
+
export function isBlank(value) {
|
|
18
|
+
return value.trim() === '';
|
|
19
|
+
}
|
|
20
|
+
// An option left out has no value to refuse, and a value that names something
|
|
21
|
+
// is passed over as none is: the empty list is equivalent to its mutant.
|
|
22
|
+
const one = (value) => (value === undefined ? [] : [value]);
|
|
23
|
+
/**
|
|
24
|
+
* The options that take a value, and what an empty one fails to name.
|
|
25
|
+
* `--format` and `--at` are not here: each takes one of a few words, and the
|
|
26
|
+
* parser refuses any other, the empty one with them. Nor is `--note`, which
|
|
27
|
+
* `rule` refuses by name itself.
|
|
28
|
+
*/
|
|
29
|
+
const VALUED = {
|
|
30
|
+
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" },
|
|
31
|
+
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' },
|
|
32
|
+
root: { of: (line) => one(line.root), says: 'names no directory; give it one, or leave it out to run in the current directory' },
|
|
33
|
+
path: { of: (line) => line.paths, says: 'names no file; give it the path of a file' },
|
|
34
|
+
reason: { of: (line) => one(line.reason), says: 'gives no reason; say why the round cannot be done without the file' },
|
|
35
|
+
option: { of: (line) => line.options, says: 'names no choice; give it "<label>: <cost>", or leave it out' },
|
|
36
|
+
recommend: { of: (line) => one(line.recommend), says: 'recommends nothing; say which option and why, or leave it out' },
|
|
37
|
+
show: { of: (line) => one(line.show), says: 'names no escalation; give it an id, as spec-harness escalate --list prints them' },
|
|
38
|
+
id: { of: (line) => one(line.id), says: "names no probe; give it a probe's id, or leave it out to run every probe" },
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The line for a value that names nothing. `subject` is the input as its
|
|
42
|
+
* caller knows it: `--brief` on a command line, `"brief"` in a tool call. The
|
|
43
|
+
* value is shown as JSON, where a tab or a line break in it can be seen.
|
|
44
|
+
*/
|
|
45
|
+
export function emptyValue(subject, option, value) {
|
|
46
|
+
return `${subject} is ${JSON.stringify(value)}, which ${VALUED[option].says}`;
|
|
47
|
+
}
|
|
48
|
+
const NO_ARGUMENT = { limit: { most: 0, takes: 'no argument' } };
|
|
49
|
+
const ONE_BRIEF = {
|
|
50
|
+
limit: { most: 1, takes: "one argument at most, a brief's id" },
|
|
51
|
+
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' },
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Every command, with what it reads of a command line. An option is listed
|
|
55
|
+
* for a command only where the command's answer depends on it: `init`
|
|
56
|
+
* chooses the base itself and the server is told the brief by each call, so
|
|
57
|
+
* neither takes `--base` or `--brief`, and taking them would tell someone
|
|
58
|
+
* the base or the brief had been set.
|
|
59
|
+
*/
|
|
60
|
+
const SHAPE = {
|
|
61
|
+
context: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },
|
|
62
|
+
guard: {
|
|
63
|
+
options: ['brief', 'base', 'root', 'format', 'strict'],
|
|
64
|
+
limit: null,
|
|
65
|
+
argument: { role: 'a path', instead: 'give it the paths the round would write' },
|
|
66
|
+
},
|
|
67
|
+
hook: { options: ['brief', 'base', 'root'], limit: { most: 1, takes: 'one argument, "claude" or "git"' } },
|
|
68
|
+
// `--list` and `--show` print what waits and raise nothing: neither reads
|
|
69
|
+
// the parts of a request, nor a brief, since what waits is every round's.
|
|
70
|
+
escalate: {
|
|
71
|
+
options: ['brief', 'root', 'format', 'path', 'reason', 'option', 'recommend', 'list', 'show'],
|
|
72
|
+
...NO_ARGUMENT,
|
|
73
|
+
modes: [
|
|
74
|
+
{ option: 'list', beside: ['root', 'format'] },
|
|
75
|
+
{ option: 'show', beside: ['root', 'format'] },
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
rule: {
|
|
79
|
+
options: ['root', 'format', 'allow', 'deny', 'note'],
|
|
80
|
+
limit: { most: 1, takes: "one argument, the escalation's id" },
|
|
81
|
+
argument: { role: 'the escalation', instead: 'give it an id, as spec-harness escalate --list prints them' },
|
|
82
|
+
},
|
|
83
|
+
rulings: { options: ['brief', 'base', 'root', 'format'], ...ONE_BRIEF },
|
|
84
|
+
audit: { options: ['brief', 'base', 'root', 'format', 'strict'], ...ONE_BRIEF },
|
|
85
|
+
probe: { options: ['brief', 'base', 'root', 'format', 'id', 'at'], ...ONE_BRIEF },
|
|
86
|
+
premises: { options: ['brief', 'root', 'format', 'strict'], ...NO_ARGUMENT },
|
|
87
|
+
init: { options: ['root', 'format', 'write', 'git-hook'], ...NO_ARGUMENT },
|
|
88
|
+
mcp: { options: ['root'], ...NO_ARGUMENT },
|
|
89
|
+
// A diagnosis says what is wrong with what it was given, where a command
|
|
90
|
+
// that acts on it stops: a brief or a base that names nothing is a line of
|
|
91
|
+
// doctor's report.
|
|
92
|
+
doctor: { options: ['brief', 'base', 'root', 'format', 'strict'], ...NO_ARGUMENT, reports: ['brief', 'base'] },
|
|
93
|
+
};
|
|
94
|
+
// A map, since a command is a word a person types and an object answers to
|
|
95
|
+
// more names than it was given: `constructor` has no shape.
|
|
96
|
+
const SHAPES = new Map(Object.entries(SHAPE));
|
|
97
|
+
function listed(options) {
|
|
98
|
+
const names = options.map((option) => `--${option}`);
|
|
99
|
+
// Every command reads at least `--root`, so a list is never empty.
|
|
100
|
+
if (names.length === 1)
|
|
101
|
+
return `its only option is ${names[0]}`;
|
|
102
|
+
return `its options are ${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Whether the line is Claude Code's hook. It is exempt from every refusal
|
|
106
|
+
* here, and read as each release since 0.1.0 read it: the line lives in
|
|
107
|
+
* settings files and in the plugin of every release, which this one cannot
|
|
108
|
+
* rewrite, and exit 2 from it holds every write of a session, the write that
|
|
109
|
+
* would fix the line among them. An option the parser itself does not know
|
|
110
|
+
* is exit 2 there, as it always was.
|
|
111
|
+
*/
|
|
112
|
+
function isClaudeHook(line) {
|
|
113
|
+
return line.command === 'hook' && line.positionals[0] === 'claude';
|
|
114
|
+
}
|
|
115
|
+
/** The words for a `--root` that is a file, or is not there, wherever it is said. */
|
|
116
|
+
export function noDirectory(root) {
|
|
117
|
+
return `--root is "${root}", which is not a directory`;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Why the command line is refused, or `null` when the command can run:
|
|
121
|
+
* an option it does not read, alone or beside another, an argument it does
|
|
122
|
+
* not take, a brief named twice, a value or an argument that names nothing,
|
|
123
|
+
* a `--root` that is no directory. Asked once a command is known and neither
|
|
124
|
+
* `--help` nor `--version` answers instead; a command with no shape is none,
|
|
125
|
+
* which its caller says.
|
|
126
|
+
*/
|
|
127
|
+
export function refusal(line, isDirectory) {
|
|
128
|
+
const { command, positionals } = line;
|
|
129
|
+
// No shape is kept under `undefined`, so the first check is the compiler's,
|
|
130
|
+
// and its mutant is equivalent.
|
|
131
|
+
if (command === undefined)
|
|
132
|
+
return null;
|
|
133
|
+
const shape = SHAPES.get(command);
|
|
134
|
+
if (shape === undefined || isClaudeHook(line))
|
|
135
|
+
return null;
|
|
136
|
+
const stray = line.given.find((option) => !shape.options.includes(option));
|
|
137
|
+
if (stray !== undefined)
|
|
138
|
+
return `${command} does not take --${stray}; ${listed(shape.options)}`;
|
|
139
|
+
// An option the command reads, beside one that leaves it unread:
|
|
140
|
+
// `escalate --list --path src/a.ts` printed the list, exit 0, and the
|
|
141
|
+
// request it also spelled out was never raised.
|
|
142
|
+
const mode = shape.modes?.find((candidate) => line.given.includes(candidate.option));
|
|
143
|
+
if (mode !== undefined) {
|
|
144
|
+
const unread = line.given.find((option) => option !== mode.option && !mode.beside.includes(option));
|
|
145
|
+
if (unread !== undefined)
|
|
146
|
+
return `${command} --${mode.option} does not take --${unread}; beside --${mode.option} ${listed(mode.beside)}`;
|
|
147
|
+
}
|
|
148
|
+
if (shape.limit !== null && positionals.length > shape.limit.most) {
|
|
149
|
+
return `${command} takes ${shape.limit.takes}, not ${positionals.map((argument) => JSON.stringify(argument)).join(', ')}`;
|
|
150
|
+
}
|
|
151
|
+
// One thing named two ways, whatever the two hold: the argument won with
|
|
152
|
+
// no word, so `audit 012 --brief 013` audited 012 for someone who had
|
|
153
|
+
// also typed 013.
|
|
154
|
+
const { argument } = shape;
|
|
155
|
+
if (argument?.option !== undefined && positionals.length > 0 && line.given.includes(argument.option)) {
|
|
156
|
+
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`;
|
|
157
|
+
}
|
|
158
|
+
for (const [option, valued] of Object.entries(VALUED)) {
|
|
159
|
+
if (shape.reports?.includes(option))
|
|
160
|
+
continue;
|
|
161
|
+
const empty = valued.of(line).find(isBlank);
|
|
162
|
+
if (empty !== undefined)
|
|
163
|
+
return emptyValue(`--${option}`, option, empty);
|
|
164
|
+
}
|
|
165
|
+
const empty = positionals.find(isBlank);
|
|
166
|
+
if (shape.argument !== undefined && empty !== undefined) {
|
|
167
|
+
return `${command} was given ${JSON.stringify(empty)} as ${shape.argument.role}, which names none; ${shape.argument.instead}`;
|
|
168
|
+
}
|
|
169
|
+
// An empty one was refused above, so this is a path that was meant: a file,
|
|
170
|
+
// or a directory that is not there. git starts in neither, and the run
|
|
171
|
+
// ended saying the path was outside a work tree, which named neither the
|
|
172
|
+
// option nor what was wrong with what it was given.
|
|
173
|
+
if (line.root !== undefined && !isDirectory(line.root)) {
|
|
174
|
+
return `${noDirectory(line.root)}; give it one that exists, or leave it out to run in the current directory`;
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAmBH,2DAA2D;AAC3D,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAQD,8EAA8E;AAC9E,yEAAyE;AACzE,MAAM,GAAG,GAAG,CAAC,KAAyB,EAAqB,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAEnG;;;;;GAKG;AACH,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,kGAAkG,EAAE;IAClJ,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,wFAAwF,EAAE;IACtI,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,kFAAkF,EAAE;IAChI,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,2CAA2C,EAAE;IACrF,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,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oB,CAAC;IACjM,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\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 = {\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} as const 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 = { limit: { most: 0, takes: 'no argument' } } as const;\nconst ONE_BRIEF = {\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} as const;\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 = {\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} as const 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) as string}`;\n}\n\n/**\n * Whether the line is Claude Code's hook. It is exempt from every refusal\n * here, and read as each release since 0.1.0 read it: the line lives in\n * settings files and in the plugin of every release, which this one cannot\n * rewrite, and exit 2 from it holds every write of a session, the write that\n * would fix the line among them. An option the parser itself does not know\n * is exit 2 there, as it always was.\n */\nfunction isClaudeHook(line: CommandLine): boolean {\n return line.command === 'hook' && line.positionals[0] === '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/**\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(line)) 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"]}
|
package/dist/workspace.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export declare function version(): string;
|
|
|
30
30
|
export interface Options {
|
|
31
31
|
readonly command: string | undefined;
|
|
32
32
|
readonly positionals: readonly string[];
|
|
33
|
+
/** The long name of every option given, in the order given: what tells an option left out from one a command does not read. */
|
|
34
|
+
readonly given: readonly string[];
|
|
33
35
|
readonly brief: string | undefined;
|
|
34
36
|
readonly base: string | undefined;
|
|
35
37
|
readonly root: string | undefined;
|
|
@@ -74,12 +76,17 @@ export declare function openWorkspace(options: Options, io: CliIO): Promise<Work
|
|
|
74
76
|
/** The id the flag, the environment or the branch names, without asking spec-brief anything. */
|
|
75
77
|
export declare function namedId(workspace: Workspace, options: Options, env: CliIO['env']): string | null;
|
|
76
78
|
export declare function activeBrief(workspace: Workspace, options: Options, env: CliIO['env']): Promise<ActiveBrief>;
|
|
79
|
+
/** What is said of a name that names no brief spec-brief knows, by what named it. */
|
|
80
|
+
export declare function namesNoBrief(active: Extract<ActiveBrief, {
|
|
81
|
+
kind: 'unknown';
|
|
82
|
+
}>, argument?: string): string;
|
|
77
83
|
/**
|
|
78
84
|
* The brief a command acts on, or why there is none: a note when nothing names
|
|
79
85
|
* one, which a command that needs a brief refuses with, or a problem when what
|
|
80
|
-
* names one is wrong.
|
|
86
|
+
* names one is wrong. `argument` is what the caller calls an argument that
|
|
87
|
+
* named it.
|
|
81
88
|
*/
|
|
82
|
-
export declare function describeActive(active: ActiveBrief): {
|
|
89
|
+
export declare function describeActive(active: ActiveBrief, argument?: string): {
|
|
83
90
|
brief: BriefRow;
|
|
84
91
|
note: undefined;
|
|
85
92
|
problem: null;
|
package/dist/workspace.js
CHANGED
|
@@ -74,6 +74,7 @@ export function parseOptions(argv) {
|
|
|
74
74
|
return {
|
|
75
75
|
command,
|
|
76
76
|
positionals: positionals.slice(1),
|
|
77
|
+
given: Object.keys(values),
|
|
77
78
|
brief: values.brief,
|
|
78
79
|
base: values.base,
|
|
79
80
|
root: values.root,
|
|
@@ -132,24 +133,37 @@ export async function activeBrief(workspace, options, env) {
|
|
|
132
133
|
const fromBranch = briefIdFromBranch(workspace.config.branches, workspace.branch);
|
|
133
134
|
return findActive(briefs, { flag: options.brief, environment: env['SPEC_BRIEF'], branch: fromBranch });
|
|
134
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* What named a brief, as its caller knows it. An argument is the command
|
|
138
|
+
* line's by default, the id after the command; a tool call's is its `brief`,
|
|
139
|
+
* which the server says as it says every argument, by its name in quotes.
|
|
140
|
+
*/
|
|
141
|
+
function namedBy(source, argument) {
|
|
142
|
+
return source === 'argument' ? argument : `the ${source}`;
|
|
143
|
+
}
|
|
144
|
+
/** What is said of a name that names no brief spec-brief knows, by what named it. */
|
|
145
|
+
export function namesNoBrief(active, argument = 'the argument') {
|
|
146
|
+
return `${namedBy(active.source, argument)} names brief ${active.id}, and spec-brief knows no such brief`;
|
|
147
|
+
}
|
|
135
148
|
/**
|
|
136
149
|
* The brief a command acts on, or why there is none: a note when nothing names
|
|
137
150
|
* one, which a command that needs a brief refuses with, or a problem when what
|
|
138
|
-
* names one is wrong.
|
|
151
|
+
* names one is wrong. `argument` is what the caller calls an argument that
|
|
152
|
+
* named it.
|
|
139
153
|
*/
|
|
140
|
-
export function describeActive(active) {
|
|
154
|
+
export function describeActive(active, argument = 'the argument') {
|
|
141
155
|
switch (active.kind) {
|
|
142
156
|
case 'found':
|
|
143
157
|
return { brief: active.brief, note: undefined, problem: null };
|
|
144
158
|
case 'none':
|
|
145
159
|
return { brief: null, note: active.reason, problem: null };
|
|
146
160
|
case 'unknown':
|
|
147
|
-
return { brief: null, note: undefined, problem:
|
|
161
|
+
return { brief: null, note: undefined, problem: namesNoBrief(active, argument) };
|
|
148
162
|
case 'archived':
|
|
149
163
|
return {
|
|
150
164
|
brief: null,
|
|
151
165
|
note: undefined,
|
|
152
|
-
problem:
|
|
166
|
+
problem: `${namedBy(active.source, argument)} names brief ${active.brief.id}, which is archived; a closed round writes nothing`,
|
|
153
167
|
};
|
|
154
168
|
}
|
|
155
169
|
}
|
package/dist/workspace.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAoB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExE,OAAO,EAAE,cAAc,EAAiB,MAAM,eAAe,CAAC;AAG9D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC;AACzB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAE5B,+FAA+F;AAC/F,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC,MAAM,OAAO,UAAW,SAA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O,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,MAAM,CAAC,MAAM,gBAAgB,MAAM,CAAC,EAAE,sCAAsC,EAAE,CAAC;QACxI,KAAK,UAAU;YACb,OAAO;gBACL,KAAK,EAAE,IAAI;gBACX,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,OAAO,MAAM,CAAC,MAAM,gBAAgB,MAAM,CAAC,KAAK,CAAC,EAAE,oDAAoD;aACjH,CAAC;IACN,CAAC;AACH,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,OAAe,EAAE,IAA6B;IACjE,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,mBAAmB,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AAC5I,CAAC","sourcesContent":["/**\n * What every command shares: exit codes, options, the repository a command\n * runs in, and which brief the round is working on.\n */\n\nimport { readFileSync } from 'node:fs';\nimport { parseArgs } from 'node:util';\n\nimport { findActive, type ActiveBrief } from './briefs.js';\nimport { briefIdFromBranch, ciBranch } from './branch.js';\nimport type { HarnessConfig } from './config.js';\nimport { loadConfig } from './fs.js';\nimport { commonDirectory, currentBranch, workTreeRoot } from './git.js';\nimport type { FindingFormat } from './formats.js';\nimport { createSiblings, type Siblings } from './siblings.js';\nimport type { BriefRow } from './types.js';\n\nexport const EXIT_OK = 0;\nexport const EXIT_FAILED = 1;\nexport const EXIT_ERROR = 2;\n\n/** The version of the JSON documents this tool prints. Bumped when a field changes meaning. */\nexport const JSON_SCHEMA_VERSION = 1;\n\nexport class UsageError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'UsageError';\n }\n}\n\nexport interface CliIO {\n readonly stdout: { write(text: string): unknown };\n readonly stderr: { write(text: string): unknown };\n readonly stdin?: () => Promise<string>;\n readonly cwd: string;\n readonly env: Readonly<Record<string, string | undefined>>;\n}\n\nexport function version(): string {\n const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')) as { version: string };\n return manifest.version;\n}\n\nexport interface Options {\n readonly command: string | undefined;\n readonly positionals: readonly string[];\n readonly brief: string | undefined;\n readonly base: string | undefined;\n readonly root: string | undefined;\n /** `gitlab`, `sarif` and `github` only for `audit` and `premises`, whose findings have places. */\n readonly format: 'pretty' | 'json' | FindingFormat;\n readonly strict: boolean;\n readonly help: boolean;\n readonly version: boolean;\n /** init: apply the plan instead of printing it. */\n readonly write: boolean;\n /** init: also install git's pre-commit hook. */\n readonly gitHook: boolean;\n /** escalate: the files the round needs, the reason, the options and the recommendation. */\n readonly paths: readonly string[];\n readonly reason: string | undefined;\n readonly options: readonly string[];\n readonly recommend: string | undefined;\n readonly list: boolean;\n readonly show: string | undefined;\n /** rule: the decision and what it allows. */\n readonly allow: boolean;\n readonly deny: boolean;\n readonly note: string | undefined;\n /** probe: which probe, and at which commit. */\n readonly id: string | undefined;\n readonly at: 'base' | 'head' | 'both' | undefined;\n}\n\nexport function parseOptions(argv: readonly string[]): Options {\n let parsed;\n try {\n parsed = parseArgs({\n args: [...argv],\n allowPositionals: true,\n strict: true,\n options: {\n brief: { type: 'string' },\n base: { type: 'string' },\n root: { type: 'string' },\n format: { type: 'string' },\n strict: { type: 'boolean' },\n write: { type: 'boolean' },\n 'git-hook': { type: 'boolean' },\n path: { type: 'string', multiple: true },\n reason: { type: 'string' },\n option: { type: 'string', multiple: true },\n recommend: { type: 'string' },\n list: { type: 'boolean' },\n show: { type: 'string' },\n allow: { type: 'boolean' },\n deny: { type: 'boolean' },\n note: { type: 'string' },\n id: { type: 'string' },\n at: { type: 'string' },\n help: { type: 'boolean', short: 'h' },\n version: { type: 'boolean', short: 'v' },\n },\n });\n } catch (error) {\n throw new UsageError((error as Error).message);\n }\n const { values, positionals } = parsed;\n const format = (values.format ?? 'pretty') as Options['format'];\n const formats: readonly Options['format'][] = ['pretty', 'json', 'gitlab', 'sarif', 'github'];\n if (!formats.includes(format)) throw new UsageError(`--format must be pretty, json, gitlab, sarif or github, not \"${format}\"`);\n const command = positionals[0];\n // Only the commands whose findings have places print them for a forge.\n if (command !== undefined && command !== 'audit' && command !== 'premises' && format !== 'pretty' && format !== 'json') {\n throw new UsageError(`--format ${format} is for audit and premises; ${command} prints pretty or json`);\n }\n const at = values.at;\n if (at !== undefined && at !== 'base' && at !== 'head' && at !== 'both') throw new UsageError(`--at must be base, head or both, not \"${at}\"`);\n return {\n command,\n positionals: positionals.slice(1),\n brief: values.brief,\n base: values.base,\n root: values.root,\n format,\n strict: values.strict === true,\n help: values.help === true,\n version: values.version === true,\n write: values.write === true,\n gitHook: values['git-hook'] === true,\n paths: values.path ?? [],\n reason: values.reason,\n options: values.option ?? [],\n recommend: values.recommend,\n list: values.list === true,\n show: values.show,\n allow: values.allow === true,\n deny: values.deny === true,\n note: values.note,\n id: values.id,\n at,\n };\n}\n\n/** Everything a command needs about the repository it runs in. */\nexport interface Workspace {\n readonly root: string;\n readonly commonDir: string;\n readonly config: HarnessConfig;\n readonly siblings: Siblings;\n /** The branch checked out, or on a detached head the one the forge's CI names; `null` when neither names one. */\n readonly branch: string | null;\n /** The CI variable that named the branch, on a detached head; absent when git named it. */\n readonly branchSource?: string | undefined;\n readonly cwd: string;\n}\n\nexport async function openWorkspace(options: Options, io: CliIO): Promise<Workspace> {\n const cwd = options.root ?? io.cwd;\n const root = await workTreeRoot(cwd);\n if (root === null) throw new UsageError(`${cwd} is not inside a git work tree; spec-harness measures rounds by their commits`);\n // Inside a work tree git always names the common directory; the fallback\n // is there for the type.\n const commonDir = (await commonDirectory(root)) ?? `${root}/.git`;\n const { config } = await loadConfig(root);\n // A branch checked out is the branch; only a head on none, as CI checks\n // out, asks the forge which branch the run builds.\n const checkedOut = await currentBranch(root);\n const ci = checkedOut === null ? ciBranch(io.env) : null;\n const named = ci === null ? { branch: checkedOut } : { branch: ci.branch, branchSource: ci.source };\n return { root, commonDir, config, siblings: createSiblings(root, config), ...named, cwd: io.cwd };\n}\n\n/** The id the flag, the environment or the branch names, without asking spec-brief anything. */\nexport function namedId(workspace: Workspace, options: Options, env: CliIO['env']): string | null {\n if (options.brief !== undefined && options.brief.trim() !== '') return options.brief.trim();\n const environment = env['SPEC_BRIEF'];\n if (environment !== undefined && environment.trim() !== '') return environment.trim();\n return briefIdFromBranch(workspace.config.branches, workspace.branch);\n}\n\nexport async function activeBrief(workspace: Workspace, options: Options, env: CliIO['env']): Promise<ActiveBrief> {\n // Nothing names a brief, so spec-brief is not asked (ADR-0004): the answer\n // is none whatever the briefs are, and so the empty list is equivalent to\n // its mutant.\n if (namedId(workspace, options, env) === null) {\n return findActive([], {});\n }\n const briefs = await workspace.siblings.briefs();\n const fromBranch = briefIdFromBranch(workspace.config.branches, workspace.branch);\n return findActive(briefs, { flag: options.brief, environment: env['SPEC_BRIEF'], branch: fromBranch });\n}\n\n/**\n * The brief a command acts on, or why there is none: a note when nothing names\n * one, which a command that needs a brief refuses with, or a problem when what\n * names one is wrong.\n */\nexport function describeActive(\n active: ActiveBrief,\n): { brief: BriefRow; note: undefined; problem: null } | { brief: null; note: string; problem: null } | { brief: null; note: undefined; problem: string } {\n switch (active.kind) {\n case 'found':\n return { brief: active.brief, note: undefined, problem: null };\n case 'none':\n return { brief: null, note: active.reason, problem: null };\n case 'unknown':\n return { brief: null, note: undefined, problem: `the ${active.source} names brief ${active.id}, and spec-brief knows no such brief` };\n case 'archived':\n return {\n brief: null,\n note: undefined,\n problem: `the ${active.source} names brief ${active.brief.id}, which is archived; a closed round writes nothing`,\n };\n }\n}\n\nexport function json(command: string, body: Record<string, unknown>): string {\n return `${JSON.stringify({ tool: 'spec-harness', version: version(), schemaVersion: JSON_SCHEMA_VERSION, command, ...body }, null, 2)}\\n`;\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AA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BACL,KAAK,EAAE,IAAI;gBACX,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,gBAAgB,MAAM,CAAC,KAAK,CAAC,EAAE,oDAAoD;aAChI,CAAC;IACN,CAAC;AACH,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,OAAe,EAAE,IAA6B;IACjE,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,mBAAmB,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AAC5I,CAAC","sourcesContent":["/**\n * What every command shares: exit codes, options, the repository a command\n * runs in, and which brief the round is working on.\n */\n\nimport { readFileSync } from 'node:fs';\nimport { parseArgs } from 'node:util';\n\nimport { findActive, type ActiveBrief, type ActiveSource } from './briefs.js';\nimport { briefIdFromBranch, ciBranch } from './branch.js';\nimport type { HarnessConfig } from './config.js';\nimport { loadConfig } from './fs.js';\nimport { commonDirectory, currentBranch, workTreeRoot } from './git.js';\nimport type { FindingFormat } from './formats.js';\nimport { createSiblings, type Siblings } from './siblings.js';\nimport type { BriefRow } from './types.js';\n\nexport const EXIT_OK = 0;\nexport const EXIT_FAILED = 1;\nexport const EXIT_ERROR = 2;\n\n/** The version of the JSON documents this tool prints. Bumped when a field changes meaning. */\nexport const JSON_SCHEMA_VERSION = 1;\n\nexport class UsageError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'UsageError';\n }\n}\n\nexport interface CliIO {\n readonly stdout: { write(text: string): unknown };\n readonly stderr: { write(text: string): unknown };\n readonly stdin?: () => Promise<string>;\n readonly cwd: string;\n readonly env: Readonly<Record<string, string | undefined>>;\n}\n\nexport function version(): string {\n const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')) as { version: string };\n return manifest.version;\n}\n\nexport interface Options {\n readonly command: string | undefined;\n readonly positionals: readonly string[];\n /** The long name of every option given, in the order given: what tells an option left out from one a command does not read. */\n readonly given: readonly string[];\n readonly brief: string | undefined;\n readonly base: string | undefined;\n readonly root: string | undefined;\n /** `gitlab`, `sarif` and `github` only for `audit` and `premises`, whose findings have places. */\n readonly format: 'pretty' | 'json' | FindingFormat;\n readonly strict: boolean;\n readonly help: boolean;\n readonly version: boolean;\n /** init: apply the plan instead of printing it. */\n readonly write: boolean;\n /** init: also install git's pre-commit hook. */\n readonly gitHook: boolean;\n /** escalate: the files the round needs, the reason, the options and the recommendation. */\n readonly paths: readonly string[];\n readonly reason: string | undefined;\n readonly options: readonly string[];\n readonly recommend: string | undefined;\n readonly list: boolean;\n readonly show: string | undefined;\n /** rule: the decision and what it allows. */\n readonly allow: boolean;\n readonly deny: boolean;\n readonly note: string | undefined;\n /** probe: which probe, and at which commit. */\n readonly id: string | undefined;\n readonly at: 'base' | 'head' | 'both' | undefined;\n}\n\nexport function parseOptions(argv: readonly string[]): Options {\n let parsed;\n try {\n parsed = parseArgs({\n args: [...argv],\n allowPositionals: true,\n strict: true,\n options: {\n brief: { type: 'string' },\n base: { type: 'string' },\n root: { type: 'string' },\n format: { type: 'string' },\n strict: { type: 'boolean' },\n write: { type: 'boolean' },\n 'git-hook': { type: 'boolean' },\n path: { type: 'string', multiple: true },\n reason: { type: 'string' },\n option: { type: 'string', multiple: true },\n recommend: { type: 'string' },\n list: { type: 'boolean' },\n show: { type: 'string' },\n allow: { type: 'boolean' },\n deny: { type: 'boolean' },\n note: { type: 'string' },\n id: { type: 'string' },\n at: { type: 'string' },\n help: { type: 'boolean', short: 'h' },\n version: { type: 'boolean', short: 'v' },\n },\n });\n } catch (error) {\n throw new UsageError((error as Error).message);\n }\n const { values, positionals } = parsed;\n const format = (values.format ?? 'pretty') as Options['format'];\n const formats: readonly Options['format'][] = ['pretty', 'json', 'gitlab', 'sarif', 'github'];\n if (!formats.includes(format)) throw new UsageError(`--format must be pretty, json, gitlab, sarif or github, not \"${format}\"`);\n const command = positionals[0];\n // Only the commands whose findings have places print them for a forge.\n if (command !== undefined && command !== 'audit' && command !== 'premises' && format !== 'pretty' && format !== 'json') {\n throw new UsageError(`--format ${format} is for audit and premises; ${command} prints pretty or json`);\n }\n const at = values.at;\n if (at !== undefined && at !== 'base' && at !== 'head' && at !== 'both') throw new UsageError(`--at must be base, head or both, not \"${at}\"`);\n return {\n command,\n positionals: positionals.slice(1),\n given: Object.keys(values),\n brief: values.brief,\n base: values.base,\n root: values.root,\n format,\n strict: values.strict === true,\n help: values.help === true,\n version: values.version === true,\n write: values.write === true,\n gitHook: values['git-hook'] === true,\n paths: values.path ?? [],\n reason: values.reason,\n options: values.option ?? [],\n recommend: values.recommend,\n list: values.list === true,\n show: values.show,\n allow: values.allow === true,\n deny: values.deny === true,\n note: values.note,\n id: values.id,\n at,\n };\n}\n\n/** Everything a command needs about the repository it runs in. */\nexport interface Workspace {\n readonly root: string;\n readonly commonDir: string;\n readonly config: HarnessConfig;\n readonly siblings: Siblings;\n /** The branch checked out, or on a detached head the one the forge's CI names; `null` when neither names one. */\n readonly branch: string | null;\n /** The CI variable that named the branch, on a detached head; absent when git named it. */\n readonly branchSource?: string | undefined;\n readonly cwd: string;\n}\n\nexport async function openWorkspace(options: Options, io: CliIO): Promise<Workspace> {\n const cwd = options.root ?? io.cwd;\n const root = await workTreeRoot(cwd);\n if (root === null) throw new UsageError(`${cwd} is not inside a git work tree; spec-harness measures rounds by their commits`);\n // Inside a work tree git always names the common directory; the fallback\n // is there for the type.\n const commonDir = (await commonDirectory(root)) ?? `${root}/.git`;\n const { config } = await loadConfig(root);\n // A branch checked out is the branch; only a head on none, as CI checks\n // out, asks the forge which branch the run builds.\n const checkedOut = await currentBranch(root);\n const ci = checkedOut === null ? ciBranch(io.env) : null;\n const named = ci === null ? { branch: checkedOut } : { branch: ci.branch, branchSource: ci.source };\n return { root, commonDir, config, siblings: createSiblings(root, config), ...named, cwd: io.cwd };\n}\n\n/** The id the flag, the environment or the branch names, without asking spec-brief anything. */\nexport function namedId(workspace: Workspace, options: Options, env: CliIO['env']): string | null {\n if (options.brief !== undefined && options.brief.trim() !== '') return options.brief.trim();\n const environment = env['SPEC_BRIEF'];\n if (environment !== undefined && environment.trim() !== '') return environment.trim();\n return briefIdFromBranch(workspace.config.branches, workspace.branch);\n}\n\nexport async function activeBrief(workspace: Workspace, options: Options, env: CliIO['env']): Promise<ActiveBrief> {\n // Nothing names a brief, so spec-brief is not asked (ADR-0004): the answer\n // is none whatever the briefs are, and so the empty list is equivalent to\n // its mutant.\n if (namedId(workspace, options, env) === null) {\n return findActive([], {});\n }\n const briefs = await workspace.siblings.briefs();\n const fromBranch = briefIdFromBranch(workspace.config.branches, workspace.branch);\n return findActive(briefs, { flag: options.brief, environment: env['SPEC_BRIEF'], branch: fromBranch });\n}\n\n/**\n * What named a brief, as its caller knows it. An argument is the command\n * line's by default, the id after the command; a tool call's is its `brief`,\n * which the server says as it says every argument, by its name in quotes.\n */\nfunction namedBy(source: ActiveSource, argument: string): string {\n return source === 'argument' ? argument : `the ${source}`;\n}\n\n/** What is said of a name that names no brief spec-brief knows, by what named it. */\nexport function namesNoBrief(active: Extract<ActiveBrief, { kind: 'unknown' }>, argument = 'the argument'): string {\n return `${namedBy(active.source, argument)} names brief ${active.id}, and spec-brief knows no such brief`;\n}\n\n/**\n * The brief a command acts on, or why there is none: a note when nothing names\n * one, which a command that needs a brief refuses with, or a problem when what\n * names one is wrong. `argument` is what the caller calls an argument that\n * named it.\n */\nexport function describeActive(\n active: ActiveBrief,\n argument = 'the argument',\n): { brief: BriefRow; note: undefined; problem: null } | { brief: null; note: string; problem: null } | { brief: null; note: undefined; problem: string } {\n switch (active.kind) {\n case 'found':\n return { brief: active.brief, note: undefined, problem: null };\n case 'none':\n return { brief: null, note: active.reason, problem: null };\n case 'unknown':\n return { brief: null, note: undefined, problem: namesNoBrief(active, argument) };\n case 'archived':\n return {\n brief: null,\n note: undefined,\n problem: `${namedBy(active.source, argument)} names brief ${active.brief.id}, which is archived; a closed round writes nothing`,\n };\n }\n}\n\nexport function json(command: string, body: Record<string, unknown>): string {\n return `${JSON.stringify({ tool: 'spec-harness', version: version(), schemaVersion: JSON_SCHEMA_VERSION, command, ...body }, null, 2)}\\n`;\n}\n\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@descent-vtt/spec-harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "The agent-facing member of the spec-* tools: context for a round, a guard on every write, an audit when it ends, probes that prove a defect before it is filed, and rulings a person signs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@descent-vtt/spec-brief": "^0.
|
|
77
|
-
"@descent-vtt/spec-guard": "^0.
|
|
76
|
+
"@descent-vtt/spec-brief": "^0.7.0",
|
|
77
|
+
"@descent-vtt/spec-guard": "^0.21.0",
|
|
78
78
|
"@stryker-mutator/core": "^10.0.0",
|
|
79
79
|
"@stryker-mutator/vitest-runner": "^10.0.0",
|
|
80
80
|
"@types/node": "^22.20.4",
|