@bamptee/aia-code 2.0.7 → 2.0.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.
package/package.json
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { writeFileSync, unlinkSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { randomBytes } from 'node:crypto';
|
|
4
|
+
import path from 'node:path';
|
|
1
5
|
import { runCli } from './cli-runner.js';
|
|
2
6
|
|
|
3
7
|
export async function generate(prompt, model, { verbose = false, apply = false, onData } = {}) {
|
|
@@ -11,7 +15,21 @@ export async function generate(prompt, model, { verbose = false, apply = false,
|
|
|
11
15
|
if (verbose || apply) {
|
|
12
16
|
args.push('--verbose');
|
|
13
17
|
}
|
|
14
|
-
args.push('-');
|
|
15
18
|
|
|
19
|
+
// In agent mode, large prompts via stdin can hang Claude CLI.
|
|
20
|
+
// Write context to a temp file and give a short prompt to read it.
|
|
21
|
+
if (apply) {
|
|
22
|
+
const tmpFile = path.join(tmpdir(), `aia-prompt-${randomBytes(6).toString('hex')}.md`);
|
|
23
|
+
writeFileSync(tmpFile, prompt, 'utf-8');
|
|
24
|
+
const shortPrompt = `Read the file at ${tmpFile} — it contains your full instructions and context. Follow them exactly.`;
|
|
25
|
+
args.push('-');
|
|
26
|
+
try {
|
|
27
|
+
return await runCli('claude', args, { stdin: shortPrompt, verbose: verbose || apply, apply, onData });
|
|
28
|
+
} finally {
|
|
29
|
+
try { unlinkSync(tmpFile); } catch {}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
args.push('-');
|
|
16
34
|
return runCli('claude', args, { stdin: prompt, verbose: verbose || apply, apply, onData });
|
|
17
35
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
import { writeFileSync, unlinkSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { randomBytes } from 'node:crypto';
|
|
6
2
|
import chalk from 'chalk';
|
|
7
3
|
|
|
8
4
|
const DEFAULT_IDLE_TIMEOUT_MS = 180_000;
|
|
@@ -12,30 +8,10 @@ export function runCli(command, args, { stdin: stdinData, verbose = false, apply
|
|
|
12
8
|
if (!idleTimeoutMs) {
|
|
13
9
|
idleTimeoutMs = apply ? AGENT_IDLE_TIMEOUT_MS : DEFAULT_IDLE_TIMEOUT_MS;
|
|
14
10
|
}
|
|
15
|
-
|
|
16
|
-
// Write prompt to a temp file to avoid stdin piping issues
|
|
17
|
-
let tmpFile;
|
|
18
|
-
if (stdinData) {
|
|
19
|
-
tmpFile = path.join(tmpdir(), `aia-prompt-${randomBytes(6).toString('hex')}.txt`);
|
|
20
|
-
writeFileSync(tmpFile, stdinData, 'utf-8');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
11
|
return new Promise((resolve, reject) => {
|
|
24
12
|
const { CLAUDECODE, ...cleanEnv } = process.env;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const finalArgs = tmpFile
|
|
28
|
-
? args.filter(a => a !== '-')
|
|
29
|
-
: args;
|
|
30
|
-
|
|
31
|
-
const spawnCommand = tmpFile
|
|
32
|
-
? `${command} ${finalArgs.map(a => `'${a}'`).join(' ')} < '${tmpFile}'`
|
|
33
|
-
: `${command} ${args.map(a => `'${a}'`).join(' ')}`;
|
|
34
|
-
|
|
35
|
-
console.error(`[DEBUG] ${spawnCommand}`);
|
|
36
|
-
|
|
37
|
-
const child = spawn('sh', ['-c', spawnCommand], {
|
|
38
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
13
|
+
const child = spawn(command, args, {
|
|
14
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
39
15
|
env: { ...cleanEnv, FORCE_COLOR: '0' },
|
|
40
16
|
});
|
|
41
17
|
|
|
@@ -43,12 +19,6 @@ export function runCli(command, args, { stdin: stdinData, verbose = false, apply
|
|
|
43
19
|
let stderr = '';
|
|
44
20
|
let settled = false;
|
|
45
21
|
|
|
46
|
-
function cleanup() {
|
|
47
|
-
if (tmpFile) {
|
|
48
|
-
try { unlinkSync(tmpFile); } catch {}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
22
|
function resetTimer() {
|
|
53
23
|
clearTimeout(timer);
|
|
54
24
|
timer = setTimeout(() => {
|
|
@@ -61,7 +31,6 @@ export function runCli(command, args, { stdin: stdinData, verbose = false, apply
|
|
|
61
31
|
if (settled) return;
|
|
62
32
|
settled = true;
|
|
63
33
|
clearTimeout(timer);
|
|
64
|
-
cleanup();
|
|
65
34
|
if (err) reject(err);
|
|
66
35
|
else resolve(result);
|
|
67
36
|
}
|
|
@@ -102,5 +71,11 @@ export function runCli(command, args, { stdin: stdinData, verbose = false, apply
|
|
|
102
71
|
finish(null, chunks.join(''));
|
|
103
72
|
}
|
|
104
73
|
});
|
|
74
|
+
|
|
75
|
+
if (stdinData) {
|
|
76
|
+
child.stdin.on('error', () => {}); // Ignore EPIPE if child exits early
|
|
77
|
+
child.stdin.write(stdinData);
|
|
78
|
+
child.stdin.end();
|
|
79
|
+
}
|
|
105
80
|
});
|
|
106
81
|
}
|