kernelbot 1.0.17 → 1.0.19
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/coder.js +29 -20
- package/src/tools/coding.js +25 -2
package/package.json
CHANGED
package/src/coder.js
CHANGED
|
@@ -146,23 +146,25 @@ export class ClaudeCodeSpawner {
|
|
|
146
146
|
|
|
147
147
|
ensureClaudeCodeSetup();
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
const args = [
|
|
150
|
+
'-p', prompt,
|
|
151
|
+
'--max-turns', String(turns),
|
|
152
|
+
'--output-format', 'stream-json',
|
|
153
|
+
'--dangerously-skip-permissions',
|
|
154
|
+
];
|
|
155
|
+
if (this.model) {
|
|
156
|
+
args.push('--model', this.model);
|
|
157
|
+
}
|
|
151
158
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
'--output-format', 'stream-json',
|
|
157
|
-
'--dangerously-skip-permissions',
|
|
158
|
-
];
|
|
159
|
-
if (this.model) {
|
|
160
|
-
args.push('--model', this.model);
|
|
161
|
-
}
|
|
159
|
+
const cmd = `claude ${args.map((a) => a.includes(' ') ? `"${a}"` : a).join(' ')}`;
|
|
160
|
+
logger.info(`Spawning: ${cmd.slice(0, 300)}`);
|
|
161
|
+
logger.info(`CWD: ${workingDirectory}`);
|
|
162
|
+
if (onOutput) onOutput(`⏳ Starting Claude Code...\n\`${cmd.slice(0, 200)}\``).catch(() => {});
|
|
162
163
|
|
|
164
|
+
return new Promise((resolve, reject) => {
|
|
163
165
|
const child = spawn('claude', args, {
|
|
164
166
|
cwd: workingDirectory,
|
|
165
|
-
env: { ...process.env },
|
|
167
|
+
env: { ...process.env, IS_SANDBOX: '1' },
|
|
166
168
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
167
169
|
});
|
|
168
170
|
|
|
@@ -183,7 +185,6 @@ export class ClaudeCodeSpawner {
|
|
|
183
185
|
|
|
184
186
|
fullOutput += trimmed + '\n';
|
|
185
187
|
|
|
186
|
-
// Try to extract result text
|
|
187
188
|
try {
|
|
188
189
|
const event = JSON.parse(trimmed);
|
|
189
190
|
if (event.type === 'result') {
|
|
@@ -196,10 +197,13 @@ export class ClaudeCodeSpawner {
|
|
|
196
197
|
});
|
|
197
198
|
|
|
198
199
|
child.stderr.on('data', (data) => {
|
|
199
|
-
const chunk = data.toString();
|
|
200
|
-
stderr += chunk;
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
const chunk = data.toString().trim();
|
|
201
|
+
stderr += chunk + '\n';
|
|
202
|
+
logger.warn(`Claude Code stderr: ${chunk.slice(0, 300)}`);
|
|
203
|
+
// Forward ALL stderr to Telegram immediately
|
|
204
|
+
if (onOutput && chunk) {
|
|
205
|
+
onOutput(`⚠️ Claude Code: ${chunk.slice(0, 400)}`).catch(() => {});
|
|
206
|
+
}
|
|
203
207
|
});
|
|
204
208
|
|
|
205
209
|
const timer = setTimeout(() => {
|
|
@@ -222,8 +226,13 @@ export class ClaudeCodeSpawner {
|
|
|
222
226
|
processEvent(buffer.trim(), onOutput, logger);
|
|
223
227
|
}
|
|
224
228
|
|
|
225
|
-
|
|
226
|
-
|
|
229
|
+
logger.info(`Claude Code exited with code ${code} | stdout: ${fullOutput.length} chars | stderr: ${stderr.length} chars`);
|
|
230
|
+
|
|
231
|
+
if (code !== 0) {
|
|
232
|
+
const errMsg = stderr.trim() || fullOutput.trim() || `exited with code ${code}`;
|
|
233
|
+
logger.error(`Claude Code failed: ${errMsg.slice(0, 500)}`);
|
|
234
|
+
if (onOutput) onOutput(`❌ Claude Code failed (exit ${code}):\n\`\`\`\n${errMsg.slice(0, 400)}\n\`\`\``).catch(() => {});
|
|
235
|
+
reject(new Error(`Claude Code exited with code ${code}: ${errMsg.slice(0, 500)}`));
|
|
227
236
|
} else {
|
|
228
237
|
resolve({
|
|
229
238
|
output: resultText || fullOutput.trim(),
|
package/src/tools/coding.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { resolve } from 'path';
|
|
1
3
|
import { ClaudeCodeSpawner } from '../coder.js';
|
|
4
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
5
|
|
|
3
6
|
let spawner = null;
|
|
4
7
|
|
|
@@ -35,16 +38,36 @@ export const definitions = [
|
|
|
35
38
|
|
|
36
39
|
export const handlers = {
|
|
37
40
|
spawn_claude_code: async (params, context) => {
|
|
41
|
+
const logger = getLogger();
|
|
42
|
+
const onUpdate = context.onUpdate || null;
|
|
43
|
+
const dir = resolve(params.working_directory);
|
|
44
|
+
|
|
45
|
+
// Validate directory exists
|
|
46
|
+
if (!existsSync(dir)) {
|
|
47
|
+
const msg = `Directory not found: ${dir}`;
|
|
48
|
+
logger.error(`spawn_claude_code: ${msg}`);
|
|
49
|
+
if (onUpdate) onUpdate(`❌ ${msg}`).catch(() => {});
|
|
50
|
+
return { error: msg };
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
try {
|
|
39
54
|
const coder = getSpawner(context.config);
|
|
40
55
|
const result = await coder.run({
|
|
41
|
-
workingDirectory:
|
|
56
|
+
workingDirectory: dir,
|
|
42
57
|
prompt: params.prompt,
|
|
43
58
|
maxTurns: params.max_turns,
|
|
44
|
-
onOutput:
|
|
59
|
+
onOutput: onUpdate,
|
|
45
60
|
});
|
|
61
|
+
|
|
62
|
+
// Show stderr if any
|
|
63
|
+
if (result.stderr && onUpdate) {
|
|
64
|
+
onUpdate(`⚠️ Claude Code stderr:\n\`\`\`\n${result.stderr.slice(0, 500)}\n\`\`\``).catch(() => {});
|
|
65
|
+
}
|
|
66
|
+
|
|
46
67
|
return { success: true, output: result.output };
|
|
47
68
|
} catch (err) {
|
|
69
|
+
logger.error(`spawn_claude_code failed: ${err.message}`);
|
|
70
|
+
if (onUpdate) onUpdate(`❌ Claude Code error: ${err.message}`).catch(() => {});
|
|
48
71
|
return { error: err.message };
|
|
49
72
|
}
|
|
50
73
|
},
|