@zgeoff/skill-gate 0.2.1 → 0.2.2
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/dist/index.js +1118 -0
- package/package.json +5 -9
- package/src/build-bash-skill-gate-output.ts +0 -41
- package/src/build-skill-gate-output.ts +0 -54
- package/src/collect-gate-skills.ts +0 -19
- package/src/collect-loaded-skills.ts +0 -98
- package/src/collect-written-paths.ts +0 -450
- package/src/format-skill-list.ts +0 -10
- package/src/index.ts +0 -1
- package/src/parse-shell-commands.ts +0 -429
- package/src/parse-skill-gate-rules.ts +0 -72
- package/src/plan-bash-skill-gate.ts +0 -21
- package/src/plan-skill-gate.ts +0 -21
- package/src/run-skill-gate.ts +0 -235
- package/src/types.ts +0 -96
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
import { match } from 'ts-pattern';
|
|
2
|
-
import type { ShellCommand, ShellRedirect, ShellWord } from './types.ts';
|
|
3
|
-
|
|
4
|
-
// Parses a Bash command line into its simple commands, or null on an unclosed quote. A word with a
|
|
5
|
-
// parameter, a substitution or an unquoted glob is not literal, so no caller reads it as a path. A
|
|
6
|
-
// here document's body becomes the command's stdin.
|
|
7
|
-
export function parseShellCommands(text: string): readonly ShellCommand[] | null {
|
|
8
|
-
const tokens = splitShellTokens(text);
|
|
9
|
-
|
|
10
|
-
return tokens === null ? null : buildShellCommands(tokens);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type ShellToken =
|
|
14
|
-
| { readonly kind: 'word'; readonly word: ShellWord }
|
|
15
|
-
| { readonly kind: 'separator'; readonly operator: string }
|
|
16
|
-
| { readonly kind: 'subshell'; readonly opens: boolean }
|
|
17
|
-
| { readonly kind: 'redirect'; readonly operator: string }
|
|
18
|
-
| { readonly kind: 'heredoc'; readonly body: string };
|
|
19
|
-
|
|
20
|
-
interface PendingHeredoc {
|
|
21
|
-
readonly delimiter: string;
|
|
22
|
-
readonly stripTabs: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function splitShellTokens(text: string): ShellToken[] | null {
|
|
26
|
-
const tokens: ShellToken[] = [];
|
|
27
|
-
const heredocs: PendingHeredoc[] = [];
|
|
28
|
-
let heredocOperator: string | null = null;
|
|
29
|
-
let index = 0;
|
|
30
|
-
|
|
31
|
-
while (index < text.length) {
|
|
32
|
-
const char = text.charAt(index);
|
|
33
|
-
|
|
34
|
-
if (char === ' ' || char === '\t') {
|
|
35
|
-
index += 1;
|
|
36
|
-
} else if (char === '\\' && text.charAt(index + 1) === '\n') {
|
|
37
|
-
index += 2;
|
|
38
|
-
} else if (char === '\n') {
|
|
39
|
-
index += 1;
|
|
40
|
-
|
|
41
|
-
for (const heredoc of heredocs.splice(0)) {
|
|
42
|
-
const end = getHeredocEndOrTextEnd(text, index, heredoc);
|
|
43
|
-
|
|
44
|
-
tokens.push({ kind: 'heredoc', body: text.slice(index, end.bodyEnd) });
|
|
45
|
-
|
|
46
|
-
index = end.next;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
tokens.push({ kind: 'separator', operator: '\n' });
|
|
50
|
-
} else if (char === '#') {
|
|
51
|
-
const lineEnd = text.indexOf('\n', index);
|
|
52
|
-
|
|
53
|
-
index = lineEnd === -1 ? text.length : lineEnd;
|
|
54
|
-
} else {
|
|
55
|
-
const operator = findOperator(text, index);
|
|
56
|
-
|
|
57
|
-
if (operator === null) {
|
|
58
|
-
const parsed = parseShellWord(text, index);
|
|
59
|
-
|
|
60
|
-
if (parsed === null) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
index = parsed.end;
|
|
65
|
-
|
|
66
|
-
if (heredocOperator !== null) {
|
|
67
|
-
heredocs.push({ delimiter: parsed.word.text, stripTabs: heredocOperator === '<<-' });
|
|
68
|
-
|
|
69
|
-
heredocOperator = null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// A file descriptor number such as the 2 in `2>err.log` belongs to the redirect after it.
|
|
73
|
-
if (!(isFileDescriptor(parsed.word) && isRedirectStart(text.charAt(index)))) {
|
|
74
|
-
tokens.push({ kind: 'word', word: parsed.word });
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
index += operator.length;
|
|
78
|
-
heredocOperator = operator === '<<' || operator === '<<-' ? operator : null;
|
|
79
|
-
|
|
80
|
-
tokens.push(buildOperatorToken(operator));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return tokens;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function getHeredocEndOrTextEnd(
|
|
89
|
-
text: string,
|
|
90
|
-
start: number,
|
|
91
|
-
heredoc: PendingHeredoc,
|
|
92
|
-
): { readonly bodyEnd: number; readonly next: number } {
|
|
93
|
-
let lineStart = start;
|
|
94
|
-
|
|
95
|
-
while (lineStart < text.length) {
|
|
96
|
-
const newline = text.indexOf('\n', lineStart);
|
|
97
|
-
const lineEnd = newline === -1 ? text.length : newline;
|
|
98
|
-
const line = text.slice(lineStart, lineEnd);
|
|
99
|
-
|
|
100
|
-
if ((heredoc.stripTabs ? line.replace(/^\t+/u, '') : line) === heredoc.delimiter) {
|
|
101
|
-
return { bodyEnd: lineStart, next: lineEnd };
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
lineStart = lineEnd + 1;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return { bodyEnd: text.length, next: text.length };
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Longest first, so `>>` wins over `>` and `&&` over `&`.
|
|
111
|
-
const OPERATORS = [
|
|
112
|
-
'&>>',
|
|
113
|
-
'<<-',
|
|
114
|
-
'<<<',
|
|
115
|
-
'>>',
|
|
116
|
-
'>|',
|
|
117
|
-
'&>',
|
|
118
|
-
'>&',
|
|
119
|
-
'<&',
|
|
120
|
-
'<>',
|
|
121
|
-
'<<',
|
|
122
|
-
'&&',
|
|
123
|
-
'||',
|
|
124
|
-
'|&',
|
|
125
|
-
';;',
|
|
126
|
-
'>',
|
|
127
|
-
'<',
|
|
128
|
-
'|',
|
|
129
|
-
'&',
|
|
130
|
-
';',
|
|
131
|
-
'(',
|
|
132
|
-
')',
|
|
133
|
-
];
|
|
134
|
-
|
|
135
|
-
function findOperator(text: string, index: number): string | null {
|
|
136
|
-
return OPERATORS.find((operator) => text.startsWith(operator, index)) ?? null;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const GLOB_CHARS = '*?[{';
|
|
140
|
-
|
|
141
|
-
function parseShellWord(
|
|
142
|
-
text: string,
|
|
143
|
-
start: number,
|
|
144
|
-
): { readonly word: ShellWord; readonly end: number } | null {
|
|
145
|
-
let value = '';
|
|
146
|
-
let literal = true;
|
|
147
|
-
let index = start;
|
|
148
|
-
|
|
149
|
-
while (index < text.length && !isWordEnd(text.charAt(index))) {
|
|
150
|
-
const char = text.charAt(index);
|
|
151
|
-
|
|
152
|
-
if (char === '\\') {
|
|
153
|
-
value += text.charAt(index + 1);
|
|
154
|
-
index += 2;
|
|
155
|
-
} else if (char === "'") {
|
|
156
|
-
const close = text.indexOf("'", index + 1);
|
|
157
|
-
|
|
158
|
-
if (close === -1) {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
value += text.slice(index + 1, close);
|
|
163
|
-
index = close + 1;
|
|
164
|
-
} else if (char === '"') {
|
|
165
|
-
const quoted = parseDoubleQuoted(text, index + 1);
|
|
166
|
-
|
|
167
|
-
if (quoted === null) {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
value += quoted.value;
|
|
172
|
-
literal &&= quoted.literal;
|
|
173
|
-
index = quoted.end;
|
|
174
|
-
} else if (char === '$' || char === '`') {
|
|
175
|
-
const end = findExpansionEnd(text, index);
|
|
176
|
-
|
|
177
|
-
if (end === null) {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
literal = false;
|
|
182
|
-
index = end;
|
|
183
|
-
} else {
|
|
184
|
-
if (GLOB_CHARS.includes(char) || (char === '~' && index === start)) {
|
|
185
|
-
literal = false;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
value += char;
|
|
189
|
-
index += 1;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return { word: { text: value, literal }, end: index };
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function isWordEnd(char: string): boolean {
|
|
197
|
-
return ' \t\n;&|<>()'.includes(char);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function parseDoubleQuoted(
|
|
201
|
-
text: string,
|
|
202
|
-
start: number,
|
|
203
|
-
): { readonly value: string; readonly literal: boolean; readonly end: number } | null {
|
|
204
|
-
let value = '';
|
|
205
|
-
let literal = true;
|
|
206
|
-
let index = start;
|
|
207
|
-
|
|
208
|
-
while (index < text.length) {
|
|
209
|
-
const char = text.charAt(index);
|
|
210
|
-
|
|
211
|
-
if (char === '"') {
|
|
212
|
-
return { value, literal, end: index + 1 };
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (char === '\\' && '"\\$`\n'.includes(text.charAt(index + 1))) {
|
|
216
|
-
value += text.charAt(index + 1);
|
|
217
|
-
index += 2;
|
|
218
|
-
} else if (char === '$' || char === '`') {
|
|
219
|
-
const end = findExpansionEnd(text, index);
|
|
220
|
-
|
|
221
|
-
if (end === null) {
|
|
222
|
-
return null;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
literal = false;
|
|
226
|
-
index = end;
|
|
227
|
-
} else {
|
|
228
|
-
value += char;
|
|
229
|
-
index += 1;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Finds where a `$name`, `${…}`, `$(…)` or backtick expansion that starts at `index` ends.
|
|
237
|
-
function findExpansionEnd(text: string, index: number): number | null {
|
|
238
|
-
if (text.charAt(index) === '`') {
|
|
239
|
-
const close = text.indexOf('`', index + 1);
|
|
240
|
-
|
|
241
|
-
return close === -1 ? null : close + 1;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const next = text.charAt(index + 1);
|
|
245
|
-
|
|
246
|
-
if (next === '(' || next === '{') {
|
|
247
|
-
return findGroupEnd(text, index + 1);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const name = /^(?:[A-Za-z_]\w*|[0-9?#@*$!-])/u.exec(text.slice(index + 1));
|
|
251
|
-
|
|
252
|
-
return index + 1 + (name?.[0].length ?? 0);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Finds the end of the bracket group that opens at `index`, past nested groups and quoted text.
|
|
256
|
-
function findGroupEnd(text: string, index: number): number | null {
|
|
257
|
-
let depth = 0;
|
|
258
|
-
let cursor = index;
|
|
259
|
-
|
|
260
|
-
while (cursor < text.length) {
|
|
261
|
-
const char = text.charAt(cursor);
|
|
262
|
-
|
|
263
|
-
if (char === "'") {
|
|
264
|
-
const close = text.indexOf("'", cursor + 1);
|
|
265
|
-
|
|
266
|
-
if (close === -1) {
|
|
267
|
-
return null;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
cursor = close + 1;
|
|
271
|
-
} else {
|
|
272
|
-
depth += getDepthChange(char);
|
|
273
|
-
cursor += char === '\\' ? 2 : 1;
|
|
274
|
-
|
|
275
|
-
if (depth === 0) {
|
|
276
|
-
return cursor;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
function getDepthChange(char: string): number {
|
|
285
|
-
if ('({'.includes(char)) {
|
|
286
|
-
return 1;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return ')}'.includes(char) ? -1 : 0;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function isFileDescriptor(word: ShellWord): boolean {
|
|
293
|
-
return word.literal && /^\d+$/u.test(word.text);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
function isRedirectStart(char: string): boolean {
|
|
297
|
-
return char === '<' || char === '>';
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const SEPARATORS = new Set(['&&', '||', '|&', ';;', '|', '&', ';']);
|
|
301
|
-
|
|
302
|
-
function buildOperatorToken(operator: string): ShellToken {
|
|
303
|
-
if (operator === '(' || operator === ')') {
|
|
304
|
-
return { kind: 'subshell', opens: operator === '(' };
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return SEPARATORS.has(operator)
|
|
308
|
-
? { kind: 'separator', operator }
|
|
309
|
-
: { kind: 'redirect', operator };
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
interface CommandDraft {
|
|
313
|
-
words: ShellWord[];
|
|
314
|
-
redirects: ShellRedirect[];
|
|
315
|
-
stdin: string | null;
|
|
316
|
-
enters: number;
|
|
317
|
-
leaves: number;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const LIST_ENDS = new Set(['&', ';', ';;', '\n']);
|
|
321
|
-
|
|
322
|
-
// A subshell's opening counts toward the next command's `enters`, and its closing toward the last
|
|
323
|
-
// command's `leaves`. A pipe side and a list sent to the background run in their own subshell too,
|
|
324
|
-
// so a caller can restore the state they changed, such as the directory.
|
|
325
|
-
function buildShellCommands(tokens: readonly ShellToken[]): readonly ShellCommand[] {
|
|
326
|
-
const commands: CommandDraft[] = [];
|
|
327
|
-
const heredocOwners: CommandDraft[] = [];
|
|
328
|
-
let draft = buildCommandDraft();
|
|
329
|
-
let operator: string | null = null;
|
|
330
|
-
let pipedIn = false;
|
|
331
|
-
|
|
332
|
-
// The index of the first command in the current list, one entry for each open subshell.
|
|
333
|
-
const listStarts = [0];
|
|
334
|
-
|
|
335
|
-
// Closes the draft at a separator. A command on either side of a pipe enters and leaves one more
|
|
336
|
-
// subshell, and so does the whole list before `&`, such as `cd docs && make &`.
|
|
337
|
-
const collectDraft = (separator: string | null): void => {
|
|
338
|
-
const pipedOut = separator === '|' || separator === '|&';
|
|
339
|
-
|
|
340
|
-
if (draft.words.length > 0 || draft.redirects.length > 0) {
|
|
341
|
-
const piped = pipedIn || pipedOut;
|
|
342
|
-
|
|
343
|
-
draft.enters += piped ? 1 : 0;
|
|
344
|
-
draft.leaves += piped ? 1 : 0;
|
|
345
|
-
|
|
346
|
-
commands.push(draft);
|
|
347
|
-
|
|
348
|
-
draft = buildCommandDraft();
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
operator = null;
|
|
352
|
-
pipedIn = pipedOut;
|
|
353
|
-
|
|
354
|
-
const listStart = listStarts.at(-1) ?? 0;
|
|
355
|
-
const first = commands[listStart];
|
|
356
|
-
const last = commands.at(-1);
|
|
357
|
-
|
|
358
|
-
if (separator === '&' && first !== undefined && last !== undefined) {
|
|
359
|
-
first.enters += 1;
|
|
360
|
-
last.leaves += 1;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
if (separator !== null && LIST_ENDS.has(separator)) {
|
|
364
|
-
listStarts[listStarts.length - 1] = commands.length;
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
const collectToken = (token: ShellToken): void => {
|
|
369
|
-
match(token)
|
|
370
|
-
.with({ kind: 'separator' }, (separator) => {
|
|
371
|
-
collectDraft(separator.operator);
|
|
372
|
-
})
|
|
373
|
-
.with({ kind: 'subshell' }, (subshell) => {
|
|
374
|
-
collectDraft(null);
|
|
375
|
-
|
|
376
|
-
const last = commands.at(-1);
|
|
377
|
-
|
|
378
|
-
if (subshell.opens) {
|
|
379
|
-
draft.enters += 1;
|
|
380
|
-
|
|
381
|
-
listStarts.push(commands.length);
|
|
382
|
-
} else {
|
|
383
|
-
listStarts.pop();
|
|
384
|
-
|
|
385
|
-
if (last !== undefined) {
|
|
386
|
-
last.leaves += 1;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
})
|
|
390
|
-
.with({ kind: 'heredoc' }, (heredoc) => {
|
|
391
|
-
// A here document's body belongs to the command whose `<<` asked for it, which a pipe may
|
|
392
|
-
// already have closed.
|
|
393
|
-
const owner = heredocOwners.shift();
|
|
394
|
-
|
|
395
|
-
if (owner !== undefined) {
|
|
396
|
-
owner.stdin = heredoc.body;
|
|
397
|
-
}
|
|
398
|
-
})
|
|
399
|
-
.with({ kind: 'redirect' }, (redirect) => {
|
|
400
|
-
operator = redirect.operator;
|
|
401
|
-
|
|
402
|
-
if (operator === '<<' || operator === '<<-') {
|
|
403
|
-
heredocOwners.push(draft);
|
|
404
|
-
}
|
|
405
|
-
})
|
|
406
|
-
.with({ kind: 'word' }, (word) => {
|
|
407
|
-
if (operator === null) {
|
|
408
|
-
draft.words.push(word.word);
|
|
409
|
-
} else {
|
|
410
|
-
draft.redirects.push({ operator, target: word.word });
|
|
411
|
-
|
|
412
|
-
operator = null;
|
|
413
|
-
}
|
|
414
|
-
})
|
|
415
|
-
.exhaustive();
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
for (const token of tokens) {
|
|
419
|
-
collectToken(token);
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
collectDraft(null);
|
|
423
|
-
|
|
424
|
-
return commands;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
function buildCommandDraft(): CommandDraft {
|
|
428
|
-
return { words: [], redirects: [], stdin: null, enters: 0, leaves: 0 };
|
|
429
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { isRecord } from '@zgeoff/std';
|
|
2
|
-
import type { SkillGate, SkillGateRulesResult } from './types.ts';
|
|
3
|
-
|
|
4
|
-
// Parses a repo's .claude/skill-gate.json: an optional `ignore` list of path segments and a `gates`
|
|
5
|
-
// list of `{ match, skills }`, where `match` globs the path relative to the project root.
|
|
6
|
-
export function parseSkillGateRules(text: string): SkillGateRulesResult {
|
|
7
|
-
const value = parseJSON(text);
|
|
8
|
-
|
|
9
|
-
if (value instanceof Error) {
|
|
10
|
-
return { ok: false, error: `is not valid JSON: ${value.message}` };
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (!isRecord(value)) {
|
|
14
|
-
return { ok: false, error: 'must hold a JSON object' };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return parseRulesRecord(value);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function parseJSON(text: string): unknown {
|
|
21
|
-
try {
|
|
22
|
-
return JSON.parse(text);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
return error instanceof Error ? error : new Error(String(error));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function parseRulesRecord(value: Readonly<Record<string, unknown>>): SkillGateRulesResult {
|
|
29
|
-
const ignore = value['ignore'] ?? [];
|
|
30
|
-
|
|
31
|
-
if (!isStringArray(ignore)) {
|
|
32
|
-
return { ok: false, error: '`ignore` must be an array of non-empty strings' };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const gates = value['gates'];
|
|
36
|
-
|
|
37
|
-
if (!Array.isArray(gates)) {
|
|
38
|
-
return { ok: false, error: '`gates` must be an array' };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return parseGates(ignore, gates);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// An empty string would match every path as an ignore segment, and no session can load it as a skill.
|
|
45
|
-
function isStringArray(value: unknown): value is string[] {
|
|
46
|
-
return Array.isArray(value) && value.every((item) => typeof item === 'string' && item !== '');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function parseGates(ignore: readonly string[], gates: readonly unknown[]): SkillGateRulesResult {
|
|
50
|
-
const parsed = gates.map((gate, index) => parseGate(gate, index));
|
|
51
|
-
const error = parsed.find((gate) => typeof gate === 'string');
|
|
52
|
-
|
|
53
|
-
if (typeof error === 'string') {
|
|
54
|
-
return { ok: false, error };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return { ok: true, rules: { ignore, gates: parsed.filter((gate) => typeof gate !== 'string') } };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function parseGate(gate: unknown, index: number): SkillGate | string {
|
|
61
|
-
if (!isRecord(gate) || typeof gate['match'] !== 'string' || gate['match'] === '') {
|
|
62
|
-
return `gate ${index} needs a non-empty string \`match\``;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const skills = gate['skills'];
|
|
66
|
-
|
|
67
|
-
if (!isStringArray(skills) || skills.length === 0) {
|
|
68
|
-
return `gate "${gate['match']}" needs a non-empty \`skills\` array of non-empty strings`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return { match: gate['match'], skills };
|
|
72
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { collectGateSkills } from './collect-gate-skills.ts';
|
|
2
|
-
import { planSkillGate } from './plan-skill-gate.ts';
|
|
3
|
-
import type { BashSkillGateInput, BashSkillGatePlan } from './types.ts';
|
|
4
|
-
|
|
5
|
-
export function planBashSkillGate(input: BashSkillGateInput): BashSkillGatePlan {
|
|
6
|
-
const gated = input.paths.filter(
|
|
7
|
-
(entry) => collectGateSkills(input.rules, entry.relativePath).length > 0,
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
const missing = gated.flatMap(
|
|
11
|
-
(entry) =>
|
|
12
|
-
planSkillGate({
|
|
13
|
-
rules: input.rules,
|
|
14
|
-
relativePath: entry.relativePath,
|
|
15
|
-
loadedSkills: input.loadedSkills,
|
|
16
|
-
availableSkills: input.availableSkills,
|
|
17
|
-
}).missing,
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
return { gatedPaths: gated.map((entry) => entry.path), missing: [...new Set(missing)] };
|
|
21
|
-
}
|
package/src/plan-skill-gate.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { collectGateSkills } from './collect-gate-skills.ts';
|
|
2
|
-
import type { SkillGateInput, SkillGatePlan, UnknownSkill } from './types.ts';
|
|
3
|
-
|
|
4
|
-
// Plans the gate for one edit: the skills the path needs that the session has not loaded, in gate
|
|
5
|
-
// order without repeats, and each rule that names a skill the repo does not have. Such a skill never
|
|
6
|
-
// counts as missing, since no session could load it.
|
|
7
|
-
export function planSkillGate(input: SkillGateInput): SkillGatePlan {
|
|
8
|
-
const unknown: UnknownSkill[] = input.rules.gates.flatMap((gate) =>
|
|
9
|
-
gate.skills
|
|
10
|
-
.filter((skill) => !input.availableSkills.includes(skill))
|
|
11
|
-
.map((skill) => ({ match: gate.match, skill })),
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
const needed = collectGateSkills(input.rules, input.relativePath);
|
|
15
|
-
|
|
16
|
-
const missing = needed.filter(
|
|
17
|
-
(skill) => input.availableSkills.includes(skill) && !input.loadedSkills.includes(skill),
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
return { missing: [...new Set(missing)], unknown };
|
|
21
|
-
}
|