@groupchatai/claude-runner 0.2.0 → 0.2.1
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/index.js +28 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -125,6 +125,7 @@ var C = {
|
|
|
125
125
|
dim: "\x1B[2m",
|
|
126
126
|
white: "\x1B[97m",
|
|
127
127
|
grey: "\x1B[90m",
|
|
128
|
+
lightGrey: "\x1B[37m",
|
|
128
129
|
green: "\x1B[32m",
|
|
129
130
|
red: "\x1B[31m",
|
|
130
131
|
pid: "\x1B[38;2;193;95;60m"
|
|
@@ -132,8 +133,21 @@ var C = {
|
|
|
132
133
|
function pidTag(pid) {
|
|
133
134
|
return ` ${C.pid}[pid ${pid}]${C.reset}`;
|
|
134
135
|
}
|
|
136
|
+
function padForTag(pid) {
|
|
137
|
+
const tagLen = ` [pid ${pid}] `.length;
|
|
138
|
+
return " ".repeat(tagLen);
|
|
139
|
+
}
|
|
140
|
+
function wrapLines(tag, pad, text, color) {
|
|
141
|
+
const lines = text.split("\n").filter((l) => l.trim());
|
|
142
|
+
if (lines.length === 0) return "";
|
|
143
|
+
const first = `${tag} ${color}${lines[0]}${C.reset}`;
|
|
144
|
+
if (lines.length === 1) return first;
|
|
145
|
+
const rest = lines.slice(1).map((l) => `${pad}${color}${l}${C.reset}`);
|
|
146
|
+
return [first, ...rest].join("\n");
|
|
147
|
+
}
|
|
135
148
|
function formatStreamEvent(event, pid) {
|
|
136
149
|
const tag = pidTag(pid);
|
|
150
|
+
const pad = padForTag(pid);
|
|
137
151
|
switch (event.type) {
|
|
138
152
|
case "system":
|
|
139
153
|
if (event.subtype === "init") {
|
|
@@ -149,18 +163,17 @@ function formatStreamEvent(event, pid) {
|
|
|
149
163
|
const parts = [];
|
|
150
164
|
for (const block of blocks) {
|
|
151
165
|
if (block.type === "text" && block.text) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
166
|
+
const wrapped = wrapLines(tag, pad, block.text, C.white);
|
|
167
|
+
if (wrapped) parts.push(wrapped);
|
|
155
168
|
} else if (block.type === "tool_use" && block.name) {
|
|
156
169
|
let detail = block.name;
|
|
157
170
|
const input = block.input;
|
|
158
171
|
if (input) {
|
|
159
172
|
if (typeof input.file_path === "string") {
|
|
160
|
-
detail += ` ${C.
|
|
173
|
+
detail += ` ${C.grey}\u2192${C.lightGrey} ${input.file_path}`;
|
|
161
174
|
} else if (typeof input.command === "string") {
|
|
162
175
|
const cmd = input.command.length > 80 ? input.command.slice(0, 77) + "\u2026" : input.command;
|
|
163
|
-
detail += ` ${C.
|
|
176
|
+
detail += ` ${C.grey}\u2192${C.lightGrey} ${cmd}`;
|
|
164
177
|
}
|
|
165
178
|
}
|
|
166
179
|
parts.push(`${tag} ${C.grey}${detail}${C.reset}`);
|
|
@@ -177,8 +190,8 @@ function formatStreamEvent(event, pid) {
|
|
|
177
190
|
lines.push(`${tag} ${C.dim}cost: $${cost?.toFixed(4)}${C.reset}`);
|
|
178
191
|
}
|
|
179
192
|
if (event.result) {
|
|
180
|
-
const
|
|
181
|
-
lines.push(
|
|
193
|
+
const wrapped = wrapLines(tag, pad, `\u2713 ${event.result}`, C.green);
|
|
194
|
+
if (wrapped) lines.push(wrapped);
|
|
182
195
|
}
|
|
183
196
|
return lines.length > 0 ? lines.join("\n") : null;
|
|
184
197
|
}
|
|
@@ -362,7 +375,9 @@ function extractPullRequestUrl(stdout) {
|
|
|
362
375
|
return void 0;
|
|
363
376
|
}
|
|
364
377
|
async function processRun(client, run, config) {
|
|
365
|
-
const
|
|
378
|
+
const runTag = ` ${C.pid}[${run.id.slice(-8)}]${C.reset}`;
|
|
379
|
+
const log = (msg) => console.log(`${runTag} ${msg}`);
|
|
380
|
+
const logGreen = (msg) => console.log(`${runTag} ${C.green}${msg}${C.reset}`);
|
|
366
381
|
const detail = await client.getRunDetail(run.id);
|
|
367
382
|
const ownerName = run.owner?.name ?? detail.owner?.name ?? "unknown";
|
|
368
383
|
log(`\u{1F4CB} "${run.taskTitle}" \u2014 delegated by ${ownerName}`);
|
|
@@ -415,15 +430,15 @@ async function processRun(client, run, config) {
|
|
|
415
430
|
${stdout.slice(0, 2e3)}
|
|
416
431
|
\`\`\``;
|
|
417
432
|
await client.errorRun(run.id, errorMsg, { pullRequestUrl });
|
|
418
|
-
log(
|
|
433
|
+
log(`${C.red}\u274C Run errored (exit code ${exitCode})${C.reset}`);
|
|
419
434
|
return;
|
|
420
435
|
}
|
|
421
436
|
const resultText = extractResultText(stdout);
|
|
422
437
|
const cost = extractCost(stdout);
|
|
423
438
|
const summary = resultText;
|
|
424
439
|
await client.completeRun(run.id, summary, { ...cost, pullRequestUrl });
|
|
425
|
-
if (pullRequestUrl)
|
|
426
|
-
|
|
440
|
+
if (pullRequestUrl) logGreen(`\u{1F517} PR: ${pullRequestUrl}`);
|
|
441
|
+
logGreen(`\u2705 Run completed`);
|
|
427
442
|
} catch (err) {
|
|
428
443
|
const message = err instanceof Error ? err.message : String(err);
|
|
429
444
|
const errorBody = `Claude Code runner error:
|
|
@@ -433,9 +448,9 @@ ${message.slice(0, 2e3)}
|
|
|
433
448
|
try {
|
|
434
449
|
await client.errorRun(run.id, errorBody);
|
|
435
450
|
} catch {
|
|
436
|
-
log(
|
|
451
|
+
log(`${C.dim}\u26A0 Failed to report error to API${C.reset}`);
|
|
437
452
|
}
|
|
438
|
-
log(
|
|
453
|
+
log(`${C.red}\u274C Error: ${message}${C.reset}`);
|
|
439
454
|
}
|
|
440
455
|
}
|
|
441
456
|
function loadEnvFile() {
|