@vibe-agent-toolkit/utils 0.1.39-rc.7 → 0.1.39-rc.8
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.
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export interface ClaudeSpawnArgs {
|
|
2
|
-
promptFile: string;
|
|
3
2
|
pluginDirs: string[];
|
|
4
3
|
sandboxDir: string;
|
|
5
4
|
model?: string;
|
|
@@ -7,10 +6,11 @@ export interface ClaudeSpawnArgs {
|
|
|
7
6
|
maxBudgetUsd?: number;
|
|
8
7
|
}
|
|
9
8
|
/**
|
|
10
|
-
* Pure assembly of the headless `claude -p` argv (spec §9). The prompt is
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
9
|
+
* Pure assembly of the headless `claude -p` argv (spec §9). The prompt is never
|
|
10
|
+
* inlined as an argv string (Windows cmd-quoting safety) and claude 2.x has no
|
|
11
|
+
* `--prompt-file` flag — the prompt is fed to the child's stdin by
|
|
12
|
+
* {@link spawnHeadlessClaude} instead. `--setting-sources ""` suppresses
|
|
13
|
+
* user/project settings; built-in skills remain (§5).
|
|
14
14
|
*/
|
|
15
15
|
export declare function assembleClaudeArgs(opts: ClaudeSpawnArgs): string[];
|
|
16
16
|
export interface SpawnResult {
|
|
@@ -19,6 +19,13 @@ export interface SpawnResult {
|
|
|
19
19
|
stalled: boolean;
|
|
20
20
|
}
|
|
21
21
|
export interface SpawnHeadlessOptions extends ClaudeSpawnArgs {
|
|
22
|
+
/**
|
|
23
|
+
* Path to the experimenter-prompt file. Its contents are streamed to the
|
|
24
|
+
* child's stdin (claude 2.x reads the `-p` prompt from stdin; there is no
|
|
25
|
+
* `--prompt-file` flag). Kept off argv so the prompt is never inlined
|
|
26
|
+
* (Windows cmd-quoting safety).
|
|
27
|
+
*/
|
|
28
|
+
promptFile: string;
|
|
22
29
|
cwd: string;
|
|
23
30
|
env: NodeJS.ProcessEnv;
|
|
24
31
|
timeoutMs: number;
|
|
@@ -28,10 +35,11 @@ export interface SpawnHeadlessOptions extends ClaudeSpawnArgs {
|
|
|
28
35
|
onStderr?: (chunk: string) => void;
|
|
29
36
|
}
|
|
30
37
|
/**
|
|
31
|
-
* Spawn the headless `claude`.
|
|
32
|
-
* the session
|
|
33
|
-
* If `stallMs` is set, a resettable stall
|
|
34
|
-
* output is received for that duration
|
|
38
|
+
* Spawn the headless `claude`. The prompt file is streamed to the child's stdin
|
|
39
|
+
* so the session reads its prompt and then sees EOF (it cannot block on input,
|
|
40
|
+
* §16). Wall-clock kill on timeout. If `stallMs` is set, a resettable stall
|
|
41
|
+
* watchdog kills the child when no output is received for that duration
|
|
42
|
+
* (stalled: true in result).
|
|
35
43
|
*/
|
|
36
44
|
export declare function spawnHeadlessClaude(opts: SpawnHeadlessOptions): Promise<SpawnResult>;
|
|
37
45
|
//# sourceMappingURL=spawn-claude.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn-claude.d.ts","sourceRoot":"","sources":["../../src/skill-test/spawn-claude.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"spawn-claude.d.ts","sourceRoot":"","sources":["../../src/skill-test/spawn-claude.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,EAAE,CAmBlE;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D;;;;;OAKG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,yFAAyF;IACzF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,CAAC,CAsD1F"}
|
|
@@ -2,19 +2,23 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { createReadStream } from 'node:fs';
|
|
3
3
|
import which from 'which';
|
|
4
4
|
/**
|
|
5
|
-
* Pure assembly of the headless `claude -p` argv (spec §9). The prompt is
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Pure assembly of the headless `claude -p` argv (spec §9). The prompt is never
|
|
6
|
+
* inlined as an argv string (Windows cmd-quoting safety) and claude 2.x has no
|
|
7
|
+
* `--prompt-file` flag — the prompt is fed to the child's stdin by
|
|
8
|
+
* {@link spawnHeadlessClaude} instead. `--setting-sources ""` suppresses
|
|
9
|
+
* user/project settings; built-in skills remain (§5).
|
|
9
10
|
*/
|
|
10
11
|
export function assembleClaudeArgs(opts) {
|
|
11
12
|
const args = [
|
|
12
13
|
'-p',
|
|
14
|
+
// claude 2.x rejects `-p --output-format stream-json` unless --verbose is
|
|
15
|
+
// also passed ("--output-format=stream-json requires --verbose"). The
|
|
16
|
+
// streamed JSON is piped to stderr for progress visibility.
|
|
13
17
|
'--output-format', 'stream-json',
|
|
18
|
+
'--verbose',
|
|
14
19
|
'--setting-sources', '',
|
|
15
20
|
'--permission-mode', 'bypassPermissions',
|
|
16
21
|
'--add-dir', opts.sandboxDir,
|
|
17
|
-
'--prompt-file', opts.promptFile,
|
|
18
22
|
];
|
|
19
23
|
for (const dir of opts.pluginDirs) {
|
|
20
24
|
args.push('--plugin-dir', dir);
|
|
@@ -28,15 +32,15 @@ export function assembleClaudeArgs(opts) {
|
|
|
28
32
|
return args;
|
|
29
33
|
}
|
|
30
34
|
/**
|
|
31
|
-
* Spawn the headless `claude`.
|
|
32
|
-
* the session
|
|
33
|
-
* If `stallMs` is set, a resettable stall
|
|
34
|
-
* output is received for that duration
|
|
35
|
+
* Spawn the headless `claude`. The prompt file is streamed to the child's stdin
|
|
36
|
+
* so the session reads its prompt and then sees EOF (it cannot block on input,
|
|
37
|
+
* §16). Wall-clock kill on timeout. If `stallMs` is set, a resettable stall
|
|
38
|
+
* watchdog kills the child when no output is received for that duration
|
|
39
|
+
* (stalled: true in result).
|
|
35
40
|
*/
|
|
36
41
|
export async function spawnHeadlessClaude(opts) {
|
|
37
42
|
const bin = which.sync('claude');
|
|
38
43
|
const args = assembleClaudeArgs(opts);
|
|
39
|
-
const nullDevice = process.platform === 'win32' ? 'NUL' : '/dev/null';
|
|
40
44
|
return await new Promise((resolve, reject) => {
|
|
41
45
|
const child = spawn(bin, args, { cwd: opts.cwd, env: opts.env, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
42
46
|
let timedOut = false;
|
|
@@ -66,8 +70,19 @@ export async function spawnHeadlessClaude(opts) {
|
|
|
66
70
|
if (stallTimer !== undefined)
|
|
67
71
|
clearTimeout(stallTimer);
|
|
68
72
|
};
|
|
69
|
-
//
|
|
70
|
-
|
|
73
|
+
// Feed the prompt to the child via stdin (claude 2.x has no --prompt-file).
|
|
74
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- our own derived prompt path
|
|
75
|
+
const promptStream = createReadStream(opts.promptFile);
|
|
76
|
+
promptStream.on('error', err => {
|
|
77
|
+
clearAllTimers();
|
|
78
|
+
child.kill('SIGKILL');
|
|
79
|
+
reject(err);
|
|
80
|
+
});
|
|
81
|
+
// Swallow EPIPE: if the child exits before consuming all stdin, the write
|
|
82
|
+
// end errors — that is not a harness failure (the close handler reports the
|
|
83
|
+
// child's real exit status).
|
|
84
|
+
child.stdin.on('error', () => { });
|
|
85
|
+
promptStream.pipe(child.stdin);
|
|
71
86
|
child.stdout.on('data', (d) => { opts.onStdout?.(d.toString()); });
|
|
72
87
|
child.stderr.on('data', (d) => { opts.onStderr?.(d.toString()); });
|
|
73
88
|
child.on('error', err => { clearAllTimers(); reject(err); });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn-claude.js","sourceRoot":"","sources":["../../src/skill-test/spawn-claude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"spawn-claude.js","sourceRoot":"","sources":["../../src/skill-test/spawn-claude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,KAAK,MAAM,OAAO,CAAC;AAU1B;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAqB;IACtD,MAAM,IAAI,GAAa;QACrB,IAAI;QACJ,0EAA0E;QAC1E,sEAAsE;QACtE,4DAA4D;QAC5D,iBAAiB,EAAE,aAAa;QAChC,WAAW;QACX,mBAAmB,EAAE,EAAE;QACvB,mBAAmB,EAAE,mBAAmB;QACxC,WAAW,EAAE,IAAI,CAAC,UAAU;KAC7B,CAAC;IACF,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,CAAC,CA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