@rasensio/aidlc 1.87.0 → 1.88.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/dist/change/types.d.ts +1 -1
- package/dist/change/types.d.ts.map +1 -1
- package/dist/commands/amend.d.ts.map +1 -1
- package/dist/commands/amend.js +12 -2
- package/dist/commands/amend.js.map +1 -1
- package/dist/commands/autopilot.d.ts.map +1 -1
- package/dist/commands/autopilot.js +9 -0
- package/dist/commands/autopilot.js.map +1 -1
- package/dist/commands/hook.d.ts.map +1 -1
- package/dist/commands/hook.js +5 -0
- package/dist/commands/hook.js.map +1 -1
- package/dist/commands/transition.d.ts.map +1 -1
- package/dist/commands/transition.js +84 -28
- package/dist/commands/transition.js.map +1 -1
- package/dist/core/lifecycle.d.ts.map +1 -1
- package/dist/core/lifecycle.js +3 -2
- package/dist/core/lifecycle.js.map +1 -1
- package/dist/core/next-steps.d.ts.map +1 -1
- package/dist/core/next-steps.js +8 -0
- package/dist/core/next-steps.js.map +1 -1
- package/dist/core/types.d.ts +5 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/doctor/migrations/instance-completion.d.ts +5 -0
- package/dist/doctor/migrations/instance-completion.d.ts.map +1 -1
- package/dist/doctor/migrations/instance-completion.js +13 -4
- package/dist/doctor/migrations/instance-completion.js.map +1 -1
- package/dist/events/event-bus.d.ts +2 -1
- package/dist/events/event-bus.d.ts.map +1 -1
- package/dist/events/event-bus.js +25 -11
- package/dist/events/event-bus.js.map +1 -1
- package/dist/hooks/approval-guard.d.ts +51 -0
- package/dist/hooks/approval-guard.d.ts.map +1 -0
- package/dist/hooks/approval-guard.js +293 -0
- package/dist/hooks/approval-guard.js.map +1 -0
- package/dist/hooks/human-only.d.ts +61 -0
- package/dist/hooks/human-only.d.ts.map +1 -0
- package/dist/hooks/human-only.js +82 -0
- package/dist/hooks/human-only.js.map +1 -0
- package/dist/hooks/install.d.ts +1 -1
- package/dist/hooks/install.d.ts.map +1 -1
- package/dist/hooks/install.js +56 -9
- package/dist/hooks/install.js.map +1 -1
- package/dist/roadmap/promote.d.ts +32 -0
- package/dist/roadmap/promote.d.ts.map +1 -1
- package/dist/roadmap/promote.js +49 -1
- package/dist/roadmap/promote.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The approval guard: a Claude Code `PreToolUse` hook that blocks an agent from
|
|
3
|
+
* running the commands only a person may run, or writing the autopilot
|
|
4
|
+
* approval record (agent-cannot-approve-itself/AC-8..AC-13).
|
|
5
|
+
*
|
|
6
|
+
* The opposite contract to the phase guard (`guard.ts`), on purpose, and the
|
|
7
|
+
* same one as the reviewer guard (`compile/reviewer-guard.ts`): this is a
|
|
8
|
+
* boundary, so every way it can fail is a block. The script exits 2 on anything
|
|
9
|
+
* it cannot read, and the hook command turns any other exit — a missing script,
|
|
10
|
+
* a missing `node`, a crash — into 2 as well.
|
|
11
|
+
*
|
|
12
|
+
* It is a standalone script rather than an `aidlc hook` subcommand because it
|
|
13
|
+
* runs before every agent shell and file-write call: starting the CLI each time
|
|
14
|
+
* is slow, and a broken build would block every call (design D1). The logic is
|
|
15
|
+
* written once, here, as `guardVerdict`, and embedded in the script with
|
|
16
|
+
* `Function.prototype.toString` — so it must stay self-contained.
|
|
17
|
+
*
|
|
18
|
+
* It is a denylist, and a shell denylist can be talked around (`sh -c`, a
|
|
19
|
+
* variable, a script file). The CLI's terminal check (`human-only.ts`) is the
|
|
20
|
+
* line; this is the early, logged layer (design D2).
|
|
21
|
+
*
|
|
22
|
+
* Design: design.md C3
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import { type HumanOnlyCommand } from './human-only.js';
|
|
27
|
+
export declare const APPROVAL_GUARD_PATH = ".claude/hooks/aidlc-approval-guard.mjs";
|
|
28
|
+
export declare const APPROVAL_GUARD_MATCHER = "Bash|Edit|Write|MultiEdit|NotebookEdit";
|
|
29
|
+
export type Verdict = {
|
|
30
|
+
block: false;
|
|
31
|
+
} | {
|
|
32
|
+
block: true;
|
|
33
|
+
rule: string;
|
|
34
|
+
reason: string;
|
|
35
|
+
subject: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The settings.json command. Exit 0 allows and 2 blocks with the script's own
|
|
39
|
+
* reason; any other status means the guard did not run, which blocks too, with a
|
|
40
|
+
* line saying so (AC-12). `$CLAUDE_PROJECT_DIR` because a hook runs in the
|
|
41
|
+
* session's working directory, which need not be the root.
|
|
42
|
+
*/
|
|
43
|
+
export declare function approvalGuardCommand(): string;
|
|
44
|
+
/**
|
|
45
|
+
* Block or pass one `PreToolUse` payload. Self-contained: no imports and no
|
|
46
|
+
* outer references, because the rendered script carries its source text.
|
|
47
|
+
*/
|
|
48
|
+
export declare function guardVerdict(input: unknown, rules: readonly HumanOnlyCommand[]): Verdict;
|
|
49
|
+
/** The script `aidlc hook install` writes to `APPROVAL_GUARD_PATH`. */
|
|
50
|
+
export declare function renderApprovalGuard(): string;
|
|
51
|
+
//# sourceMappingURL=approval-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval-guard.d.ts","sourceRoot":"","sources":["../../src/hooks/approval-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAA6B,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGnF,eAAO,MAAM,mBAAmB,2CAA2C,CAAC;AAC5E,eAAO,MAAM,sBAAsB,2CAA2C,CAAC;AAE/E,MAAM,MAAM,OAAO,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAExG;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAM7C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,gBAAgB,EAAE,GAAG,OAAO,CAwJxF;AAED,uEAAuE;AACvE,wBAAgB,mBAAmB,IAAI,MAAM,CAwE5C"}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The approval guard: a Claude Code `PreToolUse` hook that blocks an agent from
|
|
3
|
+
* running the commands only a person may run, or writing the autopilot
|
|
4
|
+
* approval record (agent-cannot-approve-itself/AC-8..AC-13).
|
|
5
|
+
*
|
|
6
|
+
* The opposite contract to the phase guard (`guard.ts`), on purpose, and the
|
|
7
|
+
* same one as the reviewer guard (`compile/reviewer-guard.ts`): this is a
|
|
8
|
+
* boundary, so every way it can fail is a block. The script exits 2 on anything
|
|
9
|
+
* it cannot read, and the hook command turns any other exit — a missing script,
|
|
10
|
+
* a missing `node`, a crash — into 2 as well.
|
|
11
|
+
*
|
|
12
|
+
* It is a standalone script rather than an `aidlc hook` subcommand because it
|
|
13
|
+
* runs before every agent shell and file-write call: starting the CLI each time
|
|
14
|
+
* is slow, and a broken build would block every call (design D1). The logic is
|
|
15
|
+
* written once, here, as `guardVerdict`, and embedded in the script with
|
|
16
|
+
* `Function.prototype.toString` — so it must stay self-contained.
|
|
17
|
+
*
|
|
18
|
+
* It is a denylist, and a shell denylist can be talked around (`sh -c`, a
|
|
19
|
+
* variable, a script file). The CLI's terminal check (`human-only.ts`) is the
|
|
20
|
+
* line; this is the early, logged layer (design D2).
|
|
21
|
+
*
|
|
22
|
+
* Design: design.md C3
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import { HUMAN_ONLY, SUBJECT_LIMIT } from './human-only.js';
|
|
27
|
+
import { LIFECYCLE_HOOK_MARKER } from './install.js';
|
|
28
|
+
export const APPROVAL_GUARD_PATH = '.claude/hooks/aidlc-approval-guard.mjs';
|
|
29
|
+
export const APPROVAL_GUARD_MATCHER = 'Bash|Edit|Write|MultiEdit|NotebookEdit';
|
|
30
|
+
/**
|
|
31
|
+
* The settings.json command. Exit 0 allows and 2 blocks with the script's own
|
|
32
|
+
* reason; any other status means the guard did not run, which blocks too, with a
|
|
33
|
+
* line saying so (AC-12). `$CLAUDE_PROJECT_DIR` because a hook runs in the
|
|
34
|
+
* session's working directory, which need not be the root.
|
|
35
|
+
*/
|
|
36
|
+
export function approvalGuardCommand() {
|
|
37
|
+
return (`node "$CLAUDE_PROJECT_DIR/${APPROVAL_GUARD_PATH}"; s=$?; [ "$s" = 0 ] && exit 0; ` +
|
|
38
|
+
`[ "$s" = 2 ] || echo 'AIDLC approval guard could not run, so the call is blocked; reinstall it with: aidlc hook install' >&2; ` +
|
|
39
|
+
`exit 2 ${LIFECYCLE_HOOK_MARKER}`);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Block or pass one `PreToolUse` payload. Self-contained: no imports and no
|
|
43
|
+
* outer references, because the rendered script carries its source text.
|
|
44
|
+
*/
|
|
45
|
+
export function guardVerdict(input, rules) {
|
|
46
|
+
const STATE_FILE = 'aidlc/autopilot/state.json';
|
|
47
|
+
const FILE_TOOLS = ['Edit', 'Write', 'MultiEdit', 'NotebookEdit'];
|
|
48
|
+
const unreadable = {
|
|
49
|
+
block: true,
|
|
50
|
+
rule: 'unreadable-input',
|
|
51
|
+
reason: 'the hook input could not be read as a tool call, so the approval guard blocks it',
|
|
52
|
+
subject: '',
|
|
53
|
+
};
|
|
54
|
+
if (typeof input !== 'object' || input === null)
|
|
55
|
+
return unreadable;
|
|
56
|
+
const toolName = input.tool_name;
|
|
57
|
+
const toolInput = input.tool_input;
|
|
58
|
+
if (typeof toolName !== 'string' || typeof toolInput !== 'object' || toolInput === null)
|
|
59
|
+
return unreadable;
|
|
60
|
+
if (FILE_TOOLS.includes(toolName)) {
|
|
61
|
+
const target = toolInput.file_path ?? toolInput.notebook_path;
|
|
62
|
+
if (typeof target !== 'string')
|
|
63
|
+
return unreadable;
|
|
64
|
+
if (!target.replace(/\\/g, '/').endsWith(STATE_FILE))
|
|
65
|
+
return { block: false };
|
|
66
|
+
return {
|
|
67
|
+
block: true,
|
|
68
|
+
rule: 'approval-record',
|
|
69
|
+
reason: 'autopilot approvals are recorded only by `aidlc autopilot approve`, run by a person in their own terminal',
|
|
70
|
+
subject: target,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (toolName !== 'Bash')
|
|
74
|
+
return { block: false };
|
|
75
|
+
const command = toolInput.command;
|
|
76
|
+
if (typeof command !== 'string')
|
|
77
|
+
return unreadable;
|
|
78
|
+
// Words as a POSIX shell would split them, for this purpose only: quotes and
|
|
79
|
+
// backslashes join, so a quoted mention is one word that names no program
|
|
80
|
+
// (AC-9). Operators end a segment. A `$(…)` or backtick body inside double
|
|
81
|
+
// quotes still runs, so it is scanned as a command of its own.
|
|
82
|
+
function split(text) {
|
|
83
|
+
const segments = [];
|
|
84
|
+
const nested = [];
|
|
85
|
+
let words = [];
|
|
86
|
+
let word = '';
|
|
87
|
+
let inWord = false;
|
|
88
|
+
const endWord = () => {
|
|
89
|
+
if (inWord)
|
|
90
|
+
words.push(word);
|
|
91
|
+
word = '';
|
|
92
|
+
inWord = false;
|
|
93
|
+
};
|
|
94
|
+
const endSegment = () => {
|
|
95
|
+
endWord();
|
|
96
|
+
if (words.length > 0)
|
|
97
|
+
segments.push(words);
|
|
98
|
+
words = [];
|
|
99
|
+
};
|
|
100
|
+
const closingParen = (from) => {
|
|
101
|
+
let depth = 1;
|
|
102
|
+
for (let j = from; j < text.length; j++) {
|
|
103
|
+
if (text[j] === '(')
|
|
104
|
+
depth++;
|
|
105
|
+
else if (text[j] === ')' && --depth === 0)
|
|
106
|
+
return j;
|
|
107
|
+
}
|
|
108
|
+
return text.length;
|
|
109
|
+
};
|
|
110
|
+
for (let i = 0; i < text.length; i++) {
|
|
111
|
+
const c = text[i];
|
|
112
|
+
if (c === "'") {
|
|
113
|
+
const end = text.indexOf("'", i + 1);
|
|
114
|
+
const stop = end === -1 ? text.length : end;
|
|
115
|
+
word += text.slice(i + 1, stop);
|
|
116
|
+
inWord = true;
|
|
117
|
+
i = stop;
|
|
118
|
+
}
|
|
119
|
+
else if (c === '"') {
|
|
120
|
+
inWord = true;
|
|
121
|
+
let j = i + 1;
|
|
122
|
+
for (; j < text.length && text[j] !== '"'; j++) {
|
|
123
|
+
const d = text[j];
|
|
124
|
+
if (d === '\\' && j + 1 < text.length) {
|
|
125
|
+
word += text[++j];
|
|
126
|
+
}
|
|
127
|
+
else if (d === '$' && text[j + 1] === '(') {
|
|
128
|
+
const end = closingParen(j + 2);
|
|
129
|
+
nested.push(text.slice(j + 2, end));
|
|
130
|
+
word += text.slice(j, end + 1);
|
|
131
|
+
j = end;
|
|
132
|
+
}
|
|
133
|
+
else if (d === '`') {
|
|
134
|
+
const end = text.indexOf('`', j + 1);
|
|
135
|
+
const stop = end === -1 ? text.length : end;
|
|
136
|
+
nested.push(text.slice(j + 1, stop));
|
|
137
|
+
word += text.slice(j, stop + 1);
|
|
138
|
+
j = stop;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
word += d;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
i = j;
|
|
145
|
+
}
|
|
146
|
+
else if (c === '\\') {
|
|
147
|
+
if (i + 1 < text.length && text[i + 1] !== '\n') {
|
|
148
|
+
word += text[i + 1];
|
|
149
|
+
inWord = true;
|
|
150
|
+
}
|
|
151
|
+
i++;
|
|
152
|
+
}
|
|
153
|
+
else if (c === ' ' || c === '\t' || c === '\r') {
|
|
154
|
+
endWord();
|
|
155
|
+
}
|
|
156
|
+
else if (c === '#' && !inWord) {
|
|
157
|
+
const nl = text.indexOf('\n', i);
|
|
158
|
+
i = nl === -1 ? text.length : nl - 1;
|
|
159
|
+
}
|
|
160
|
+
else if (';&|()\n`'.includes(c) || (c === '$' && text[i + 1] === '(')) {
|
|
161
|
+
endSegment();
|
|
162
|
+
if (c === '$')
|
|
163
|
+
i++;
|
|
164
|
+
}
|
|
165
|
+
else if (c === '<' || c === '>') {
|
|
166
|
+
endWord();
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
word += c;
|
|
170
|
+
inWord = true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
endSegment();
|
|
174
|
+
return { segments, nested };
|
|
175
|
+
}
|
|
176
|
+
function matchSegment(words) {
|
|
177
|
+
const at = words.findIndex((w) => w.split('/').pop() === 'aidlc' || w.endsWith('dist/cli.js'));
|
|
178
|
+
if (at === -1)
|
|
179
|
+
return null;
|
|
180
|
+
const args = words.slice(at + 1);
|
|
181
|
+
const positionals = args.filter((a) => !a.startsWith('-'));
|
|
182
|
+
for (const rule of rules) {
|
|
183
|
+
if (!rule.words.every((w, k) => positionals[k] === w))
|
|
184
|
+
continue;
|
|
185
|
+
const flag = rule.flag;
|
|
186
|
+
if (flag !== null && !args.some((a) => a === flag || a.startsWith(`${flag}=`)))
|
|
187
|
+
continue;
|
|
188
|
+
return rule;
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
function scan(text, depth) {
|
|
193
|
+
const { segments, nested } = split(text);
|
|
194
|
+
for (const words of segments) {
|
|
195
|
+
const hit = matchSegment(words);
|
|
196
|
+
if (hit !== null)
|
|
197
|
+
return hit;
|
|
198
|
+
}
|
|
199
|
+
if (depth >= 4)
|
|
200
|
+
return null;
|
|
201
|
+
for (const inner of nested) {
|
|
202
|
+
const hit = scan(inner, depth + 1);
|
|
203
|
+
if (hit !== null)
|
|
204
|
+
return hit;
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
const hit = scan(command, 0);
|
|
209
|
+
if (hit === null)
|
|
210
|
+
return { block: false };
|
|
211
|
+
return {
|
|
212
|
+
block: true,
|
|
213
|
+
rule: hit.rule,
|
|
214
|
+
reason: `${hit.label} needs a person: an agent may not approve, override or confirm its own gates. ` +
|
|
215
|
+
'Ask the person to run it in their own terminal',
|
|
216
|
+
subject: command,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/** The script `aidlc hook install` writes to `APPROVAL_GUARD_PATH`. */
|
|
220
|
+
export function renderApprovalGuard() {
|
|
221
|
+
return `#!/usr/bin/env node
|
|
222
|
+
// Generated by \`aidlc hook install\` — do not edit by hand; the next install overwrites it.
|
|
223
|
+
//
|
|
224
|
+
// AIDLC approval guard. Claude Code runs it before every Bash, Edit, Write,
|
|
225
|
+
// MultiEdit and NotebookEdit call: exit 0 lets the call run, exit 2 blocks it and
|
|
226
|
+
// shows stderr to the agent. The hook command blocks on any other exit as well.
|
|
227
|
+
|
|
228
|
+
import { appendFileSync, mkdirSync, readFileSync, statSync } from 'node:fs';
|
|
229
|
+
import { dirname, join, resolve } from 'node:path';
|
|
230
|
+
|
|
231
|
+
const RULES = ${JSON.stringify(HUMAN_ONLY)};
|
|
232
|
+
const SUBJECT_LIMIT = ${SUBJECT_LIMIT};
|
|
233
|
+
|
|
234
|
+
${guardVerdict.toString()}
|
|
235
|
+
|
|
236
|
+
// The refusal log: <git-common-dir>/aidlc/refusals.ndjson, found by reading
|
|
237
|
+
// files rather than spawning git; .aidlc/refusals.ndjson outside a repository.
|
|
238
|
+
function logPath(root) {
|
|
239
|
+
for (let dir = resolve(root); ; dir = dirname(dir)) {
|
|
240
|
+
const dotgit = join(dir, '.git');
|
|
241
|
+
try {
|
|
242
|
+
let gitdir = dotgit;
|
|
243
|
+
if (!statSync(dotgit).isDirectory()) {
|
|
244
|
+
const m = /^gitdir:\\s*(.+)$/m.exec(readFileSync(dotgit, 'utf8'));
|
|
245
|
+
if (m === null) break;
|
|
246
|
+
gitdir = resolve(dir, m[1].trim());
|
|
247
|
+
}
|
|
248
|
+
let common = gitdir;
|
|
249
|
+
try {
|
|
250
|
+
common = resolve(gitdir, readFileSync(join(gitdir, 'commondir'), 'utf8').trim());
|
|
251
|
+
} catch {
|
|
252
|
+
// a primary checkout has no commondir file
|
|
253
|
+
}
|
|
254
|
+
return join(common, 'aidlc', 'refusals.ndjson');
|
|
255
|
+
} catch {
|
|
256
|
+
// no .git here
|
|
257
|
+
}
|
|
258
|
+
if (dirname(dir) === dir) break;
|
|
259
|
+
}
|
|
260
|
+
return join(resolve(root), '.aidlc', 'refusals.ndjson');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
let verdict;
|
|
264
|
+
let session;
|
|
265
|
+
try {
|
|
266
|
+
const input = JSON.parse(readFileSync(0, 'utf8'));
|
|
267
|
+
session = input?.session_id;
|
|
268
|
+
verdict = guardVerdict(input, RULES);
|
|
269
|
+
} catch {
|
|
270
|
+
verdict = guardVerdict(null, RULES);
|
|
271
|
+
}
|
|
272
|
+
if (!verdict.block) process.exit(0);
|
|
273
|
+
|
|
274
|
+
try {
|
|
275
|
+
const path = logPath(process.env.CLAUDE_PROJECT_DIR || process.cwd());
|
|
276
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
277
|
+
const entry = {
|
|
278
|
+
at: new Date().toISOString(),
|
|
279
|
+
where: 'guard',
|
|
280
|
+
rule: verdict.rule,
|
|
281
|
+
reason: verdict.reason,
|
|
282
|
+
subject: String(verdict.subject).slice(0, SUBJECT_LIMIT),
|
|
283
|
+
};
|
|
284
|
+
if (typeof session === 'string') entry.session = session;
|
|
285
|
+
appendFileSync(path, JSON.stringify(entry) + '\\n');
|
|
286
|
+
} catch {
|
|
287
|
+
// a refusal that cannot be logged is still a refusal
|
|
288
|
+
}
|
|
289
|
+
process.stderr.write('AIDLC: ' + verdict.reason + '.\\n');
|
|
290
|
+
process.exit(2);
|
|
291
|
+
`;
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=approval-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval-guard.js","sourceRoot":"","sources":["../../src/hooks/approval-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OA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C;YAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YACnC,IAAI,GAAG,KAAK,IAAI;gBAAE,OAAO,GAAG,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC7B,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC1C,OAAO;QACL,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,MAAM,EACJ,GAAG,GAAG,CAAC,KAAK,gFAAgF;YAC5F,gDAAgD;QAClD,OAAO,EAAE,OAAO;KACjB,CAAC;AACJ,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,mBAAmB;IACjC,OAAO;;;;;;;;;;gBAUO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;wBAClB,aAAa;;EAEnC,YAAY,CAAC,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyDxB,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The commands only a person may run, and the check that refuses them to an
|
|
3
|
+
* agent (agent-cannot-approve-itself/AC-1..AC-6, AC-14, AC-15).
|
|
4
|
+
*
|
|
5
|
+
* Each command exists so that a person can say yes: carry a paused item on,
|
|
6
|
+
* pass the ownership gate, reopen from testing. An agent that runs one approves
|
|
7
|
+
* its own work, which empties "approved" of meaning.
|
|
8
|
+
*
|
|
9
|
+
* This check is the line; the approval guard (`approval-guard.ts`) is the early,
|
|
10
|
+
* logged layer in Claude Code (design D2). A shell denylist can always be talked
|
|
11
|
+
* around, but no agent harness gives its shell a terminal on stdin, so the
|
|
12
|
+
* terminal test catches every route the guard misses, in every harness.
|
|
13
|
+
*
|
|
14
|
+
* Design: design.md C1
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
export type HumanRule = 'autopilot-approve' | 'transition-override' | 'amend-confirm';
|
|
19
|
+
export interface HumanOnlyCommand {
|
|
20
|
+
rule: HumanRule;
|
|
21
|
+
/** How the command is named to whoever is refused. */
|
|
22
|
+
label: string;
|
|
23
|
+
/** The positional words after `aidlc` that name the command. */
|
|
24
|
+
words: string[];
|
|
25
|
+
/** The flag that makes it need a person, or null when the command always does. */
|
|
26
|
+
flag: string | null;
|
|
27
|
+
}
|
|
28
|
+
/** The one table. The approval guard embeds it, so both layers refuse the same set. */
|
|
29
|
+
export declare const HUMAN_ONLY: readonly HumanOnlyCommand[];
|
|
30
|
+
/** The longest command or path a log line keeps. */
|
|
31
|
+
export declare const SUBJECT_LIMIT = 500;
|
|
32
|
+
export interface RefusalEntry {
|
|
33
|
+
at: string;
|
|
34
|
+
where: 'cli' | 'guard';
|
|
35
|
+
rule: string;
|
|
36
|
+
reason: string;
|
|
37
|
+
subject: string;
|
|
38
|
+
session?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Why no person is present, or null when one is. `AIDLC_UNATTENDED` comes first
|
|
42
|
+
* so the reason names it even at a terminal (AC-4). Only stdin is read: a person
|
|
43
|
+
* piping the output through `tee` is still a person.
|
|
44
|
+
*/
|
|
45
|
+
export declare function absenceReason(env: NodeJS.ProcessEnv, stdinIsTTY: boolean | undefined): string | null;
|
|
46
|
+
export declare function refusalMessage(cmd: HumanOnlyCommand, why: string): string;
|
|
47
|
+
/** Shared by every worktree, and never committed: it records what happened here. */
|
|
48
|
+
export declare function refusalsPath(projectRoot: string): string;
|
|
49
|
+
/** Append one line. Never throws: a refusal that cannot be logged is still a refusal (AC-15). */
|
|
50
|
+
export declare function logRefusal(projectRoot: string, entry: RefusalEntry): void;
|
|
51
|
+
/**
|
|
52
|
+
* Null when a person is present. Otherwise logs the refusal and returns the
|
|
53
|
+
* message, for the caller to print in its own way (`amend --json` wraps it).
|
|
54
|
+
*/
|
|
55
|
+
export declare function requireHuman(rule: HumanRule, opts: {
|
|
56
|
+
root: string;
|
|
57
|
+
env?: NodeJS.ProcessEnv;
|
|
58
|
+
stdinIsTTY?: boolean;
|
|
59
|
+
subject?: string;
|
|
60
|
+
}): string | null;
|
|
61
|
+
//# sourceMappingURL=human-only.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"human-only.d.ts","sourceRoot":"","sources":["../../src/hooks/human-only.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAOH,MAAM,MAAM,SAAS,GAAG,mBAAmB,GAAG,qBAAqB,GAAG,eAAe,CAAC;AAEtF,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,SAAS,CAAC;IAChB,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,kFAAkF;IAClF,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED,uFAAuF;AACvF,eAAO,MAAM,UAAU,EAAE,SAAS,gBAAgB,EAIjD,CAAC;AAEF,oDAAoD;AACpD,eAAO,MAAM,aAAa,MAAM,CAAC;AAEjC,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAIpG;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,CASzE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACtF,MAAM,GAAG,IAAI,CAaf"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The commands only a person may run, and the check that refuses them to an
|
|
3
|
+
* agent (agent-cannot-approve-itself/AC-1..AC-6, AC-14, AC-15).
|
|
4
|
+
*
|
|
5
|
+
* Each command exists so that a person can say yes: carry a paused item on,
|
|
6
|
+
* pass the ownership gate, reopen from testing. An agent that runs one approves
|
|
7
|
+
* its own work, which empties "approved" of meaning.
|
|
8
|
+
*
|
|
9
|
+
* This check is the line; the approval guard (`approval-guard.ts`) is the early,
|
|
10
|
+
* logged layer in Claude Code (design D2). A shell denylist can always be talked
|
|
11
|
+
* around, but no agent harness gives its shell a terminal on stdin, so the
|
|
12
|
+
* terminal test catches every route the guard misses, in every harness.
|
|
13
|
+
*
|
|
14
|
+
* Design: design.md C1
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
import { appendFileSync, mkdirSync } from 'node:fs';
|
|
19
|
+
import { dirname, join } from 'node:path';
|
|
20
|
+
import { gitCommonDir } from '../concurrency/common-dir.js';
|
|
21
|
+
/** The one table. The approval guard embeds it, so both layers refuse the same set. */
|
|
22
|
+
export const HUMAN_ONLY = [
|
|
23
|
+
{ rule: 'autopilot-approve', label: 'aidlc autopilot approve', words: ['autopilot', 'approve'], flag: null },
|
|
24
|
+
{ rule: 'transition-override', label: 'aidlc transition --override', words: ['transition'], flag: '--override' },
|
|
25
|
+
{ rule: 'amend-confirm', label: 'aidlc amend --confirm', words: ['amend'], flag: '--confirm' },
|
|
26
|
+
];
|
|
27
|
+
/** The longest command or path a log line keeps. */
|
|
28
|
+
export const SUBJECT_LIMIT = 500;
|
|
29
|
+
/**
|
|
30
|
+
* Why no person is present, or null when one is. `AIDLC_UNATTENDED` comes first
|
|
31
|
+
* so the reason names it even at a terminal (AC-4). Only stdin is read: a person
|
|
32
|
+
* piping the output through `tee` is still a person.
|
|
33
|
+
*/
|
|
34
|
+
export function absenceReason(env, stdinIsTTY) {
|
|
35
|
+
if (env.AIDLC_UNATTENDED === '1')
|
|
36
|
+
return 'AIDLC_UNATTENDED=1 says no person is attending this run';
|
|
37
|
+
if (stdinIsTTY !== true)
|
|
38
|
+
return 'stdin is not a terminal, so no person is at the keyboard';
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
export function refusalMessage(cmd, why) {
|
|
42
|
+
return `${cmd.label} needs a person: ${why}. Run it yourself in your own terminal.`;
|
|
43
|
+
}
|
|
44
|
+
/** Shared by every worktree, and never committed: it records what happened here. */
|
|
45
|
+
export function refusalsPath(projectRoot) {
|
|
46
|
+
const common = gitCommonDir(projectRoot);
|
|
47
|
+
return common === null
|
|
48
|
+
? join(projectRoot, '.aidlc', 'refusals.ndjson')
|
|
49
|
+
: join(common, 'aidlc', 'refusals.ndjson');
|
|
50
|
+
}
|
|
51
|
+
/** Append one line. Never throws: a refusal that cannot be logged is still a refusal (AC-15). */
|
|
52
|
+
export function logRefusal(projectRoot, entry) {
|
|
53
|
+
try {
|
|
54
|
+
const path = refusalsPath(projectRoot);
|
|
55
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
56
|
+
const line = { ...entry, subject: entry.subject.slice(0, SUBJECT_LIMIT) };
|
|
57
|
+
appendFileSync(path, `${JSON.stringify(line)}\n`);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// nothing to do: the caller refuses either way
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Null when a person is present. Otherwise logs the refusal and returns the
|
|
65
|
+
* message, for the caller to print in its own way (`amend --json` wraps it).
|
|
66
|
+
*/
|
|
67
|
+
export function requireHuman(rule, opts) {
|
|
68
|
+
const why = absenceReason(opts.env ?? process.env, 'stdinIsTTY' in opts ? opts.stdinIsTTY : process.stdin.isTTY);
|
|
69
|
+
if (why === null)
|
|
70
|
+
return null;
|
|
71
|
+
const cmd = HUMAN_ONLY.find((c) => c.rule === rule);
|
|
72
|
+
const message = refusalMessage(cmd, why);
|
|
73
|
+
logRefusal(opts.root, {
|
|
74
|
+
at: new Date().toISOString(),
|
|
75
|
+
where: 'cli',
|
|
76
|
+
rule,
|
|
77
|
+
reason: why,
|
|
78
|
+
subject: opts.subject ?? process.argv.slice(2).join(' '),
|
|
79
|
+
});
|
|
80
|
+
return message;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=human-only.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"human-only.js","sourceRoot":"","sources":["../../src/hooks/human-only.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAc5D,uFAAuF;AACvF,MAAM,CAAC,MAAM,UAAU,GAAgC;IACrD,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,yBAAyB,EAAE,KAAK,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE;IAC5G,EAAE,IAAI,EAAE,qBAAqB,EA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AAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC;QAC1E,cAAc,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,+CAA+C;IACjD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAe,EACf,IAAuF;IAEvF,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,YAAY,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjH,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC9B,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAE,CAAC;IACrD,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACzC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE;QACpB,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAC5B,KAAK,EAAE,KAAK;QACZ,IAAI;QACJ,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;KACzD,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/hooks/install.d.ts
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* @module
|
|
24
24
|
*/
|
|
25
25
|
export type LifecyclePlatform = 'claude-code' | 'codex';
|
|
26
|
-
export type LifecycleHook = 'session-start' | 'guard';
|
|
26
|
+
export type LifecycleHook = 'session-start' | 'guard' | 'approval-guard';
|
|
27
27
|
export declare const LIFECYCLE_PLATFORMS: readonly LifecyclePlatform[];
|
|
28
28
|
export declare const LIFECYCLE_HOOK_MARKER = "#aidlc-lifecycle-hook";
|
|
29
29
|
export declare const GUARD_MATCHER = "Edit|Write|MultiEdit|NotebookEdit";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/hooks/install.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/hooks/install.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AASH,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG,OAAO,CAAC;AACxD,MAAM,MAAM,aAAa,GAAG,eAAe,GAAG,OAAO,GAAG,gBAAgB,CAAC;AAEzE,eAAO,MAAM,mBAAmB,EAAE,SAAS,iBAAiB,EAA6B,CAAC;AAC1F,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAC7D,eAAO,MAAM,aAAa,sCAAsC,CAAC;AA2BjE;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,GAAE,iBAAiC,GAAG,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAO5G;AAkCD,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAErF;AAED,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAElE;AAED,+EAA+E;AAC/E,wBAAgB,SAAS,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAEpE;AAED,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAEjE;AAED,6FAA6F;AAC7F,wB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