@bamptee/aia-code 2.0.7 → 2.0.9
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 +1 -1
- package/src/providers/anthropic.js +24 -1
- package/src/providers/cli-runner.js +17 -33
package/package.json
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
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';
|
|
5
|
+
import chalk from 'chalk';
|
|
1
6
|
import { runCli } from './cli-runner.js';
|
|
2
7
|
|
|
3
8
|
export async function generate(prompt, model, { verbose = false, apply = false, onData } = {}) {
|
|
@@ -11,7 +16,25 @@ export async function generate(prompt, model, { verbose = false, apply = false,
|
|
|
11
16
|
if (verbose || apply) {
|
|
12
17
|
args.push('--verbose');
|
|
13
18
|
}
|
|
14
|
-
args.push('-');
|
|
15
19
|
|
|
20
|
+
// In agent mode, large prompts via stdin can hang Claude CLI.
|
|
21
|
+
// Write context to a temp file and give a short prompt to read it.
|
|
22
|
+
if (apply) {
|
|
23
|
+
const tmpFile = path.join(tmpdir(), `aia-prompt-${randomBytes(6).toString('hex')}.md`);
|
|
24
|
+
writeFileSync(tmpFile, prompt, 'utf-8');
|
|
25
|
+
console.error(chalk.gray(`[AI] Prompt written to temp file (${(prompt.length / 1024).toFixed(1)}KB): ${tmpFile}`));
|
|
26
|
+
const shortPrompt = `Read the file at ${tmpFile} — it contains your full instructions and context. Follow them exactly.`;
|
|
27
|
+
args.push('-');
|
|
28
|
+
console.error(chalk.gray(`[AI] Spawning: claude ${args.join(' ')}`));
|
|
29
|
+
console.error(chalk.gray(`[AI] Waiting for Claude agent response...`));
|
|
30
|
+
try {
|
|
31
|
+
return await runCli('claude', args, { stdin: shortPrompt, verbose: verbose || apply, apply, onData });
|
|
32
|
+
} finally {
|
|
33
|
+
try { unlinkSync(tmpFile); } catch {}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
args.push('-');
|
|
38
|
+
console.error(chalk.gray(`[AI] Spawning: claude ${args.join(' ')} (${(prompt.length / 1024).toFixed(1)}KB prompt)`));
|
|
16
39
|
return runCli('claude', args, { stdin: prompt, verbose: verbose || apply, apply, onData });
|
|
17
40
|
}
|
|
@@ -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,42 +8,17 @@ 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
|
|
|
42
18
|
const chunks = [];
|
|
43
19
|
let stderr = '';
|
|
44
20
|
let settled = false;
|
|
45
|
-
|
|
46
|
-
function cleanup() {
|
|
47
|
-
if (tmpFile) {
|
|
48
|
-
try { unlinkSync(tmpFile); } catch {}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
21
|
+
let gotFirstOutput = false;
|
|
51
22
|
|
|
52
23
|
function resetTimer() {
|
|
53
24
|
clearTimeout(timer);
|
|
@@ -61,7 +32,6 @@ export function runCli(command, args, { stdin: stdinData, verbose = false, apply
|
|
|
61
32
|
if (settled) return;
|
|
62
33
|
settled = true;
|
|
63
34
|
clearTimeout(timer);
|
|
64
|
-
cleanup();
|
|
65
35
|
if (err) reject(err);
|
|
66
36
|
else resolve(result);
|
|
67
37
|
}
|
|
@@ -70,6 +40,10 @@ export function runCli(command, args, { stdin: stdinData, verbose = false, apply
|
|
|
70
40
|
resetTimer();
|
|
71
41
|
|
|
72
42
|
child.stdout.on('data', (data) => {
|
|
43
|
+
if (!gotFirstOutput) {
|
|
44
|
+
gotFirstOutput = true;
|
|
45
|
+
console.error(chalk.gray('[AI] First stdout received — agent is running'));
|
|
46
|
+
}
|
|
73
47
|
const text = data.toString();
|
|
74
48
|
process.stdout.write(text);
|
|
75
49
|
chunks.push(text);
|
|
@@ -78,6 +52,10 @@ export function runCli(command, args, { stdin: stdinData, verbose = false, apply
|
|
|
78
52
|
});
|
|
79
53
|
|
|
80
54
|
child.stderr.on('data', (data) => {
|
|
55
|
+
if (!gotFirstOutput) {
|
|
56
|
+
gotFirstOutput = true;
|
|
57
|
+
console.error(chalk.gray('[AI] First stderr received — agent is running'));
|
|
58
|
+
}
|
|
81
59
|
const text = data.toString();
|
|
82
60
|
stderr += text;
|
|
83
61
|
if (verbose) {
|
|
@@ -102,5 +80,11 @@ export function runCli(command, args, { stdin: stdinData, verbose = false, apply
|
|
|
102
80
|
finish(null, chunks.join(''));
|
|
103
81
|
}
|
|
104
82
|
});
|
|
83
|
+
|
|
84
|
+
if (stdinData) {
|
|
85
|
+
child.stdin.on('error', () => {}); // Ignore EPIPE if child exits early
|
|
86
|
+
child.stdin.write(stdinData);
|
|
87
|
+
child.stdin.end();
|
|
88
|
+
}
|
|
105
89
|
});
|
|
106
90
|
}
|