@matthugh1/conductor-cli 0.2.0 → 0.2.3
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/agent-spawner-BNOGEYDK.js +232 -0
- package/dist/agent.js +227 -89
- package/dist/{chunk-IHARLSA6.js → branch-overview-RRHX3XGY.js} +116 -10
- package/dist/chunk-6AA726KG.js +238 -0
- package/dist/{chunk-FAZ7FCZQ.js → chunk-N2KKNG4C.js} +15 -3
- package/dist/{chunk-MJKFQIYA.js → cli-config-LEERSU5N.js} +23 -25
- package/dist/daemon-ZJDZIP3R.js +607 -0
- package/dist/daemon-client-CTYOJMJP.js +435 -0
- package/dist/{git-hooks-UZJ6AER4.js → git-hooks-RQ6WJQS4.js} +1 -2
- package/dist/{git-wrapper-DVJ46TMA.js → git-wrapper-QRZYTYCZ.js} +1 -2
- package/dist/runner-prompt-MOOPKA5P.js +9 -0
- package/package.json +1 -1
- package/dist/branch-overview-XVHTGFCJ.js +0 -18
- package/dist/chunk-4YEHSYVN.js +0 -17
- package/dist/chunk-JZT526HU.js +0 -536
- package/dist/chunk-PANC6BTV.js +0 -151
- package/dist/chunk-VYINBHPQ.js +0 -22
- package/dist/cli-config-TDSTAXIA.js +0 -17
- package/dist/cli-tasks-NW3BONXC.js +0 -179
- package/dist/db-U6Y3QJDD.js +0 -16
- package/dist/git-snapshots-N3FBS7T3.js +0 -90
- package/dist/health-CTND2ANA.js +0 -147
- package/dist/health-snapshots-6MUVHE3G.js +0 -39
- package/dist/runner-prompt-2B6EXGN6.js +0 -139
- package/dist/work-queue-YE5P4S7R.js +0 -764
- package/dist/worktree-manager-QKRBTPVC.js +0 -30
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
assembleAutonomousPrompt
|
|
4
|
+
} from "./chunk-6AA726KG.js";
|
|
5
|
+
|
|
6
|
+
// ../../src/core/agent-spawner.ts
|
|
7
|
+
import { spawn } from "child_process";
|
|
8
|
+
import { readFile } from "fs/promises";
|
|
9
|
+
import { join } from "path";
|
|
10
|
+
import { createInterface } from "readline";
|
|
11
|
+
async function readClaudeMd(projectRoot) {
|
|
12
|
+
try {
|
|
13
|
+
return await readFile(join(projectRoot, "CLAUDE.md"), "utf8");
|
|
14
|
+
} catch {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function parseStreamJsonLine(raw) {
|
|
19
|
+
let event;
|
|
20
|
+
try {
|
|
21
|
+
event = JSON.parse(raw);
|
|
22
|
+
} catch {
|
|
23
|
+
return raw;
|
|
24
|
+
}
|
|
25
|
+
const type = event.type;
|
|
26
|
+
if (type === "assistant") {
|
|
27
|
+
const msg = event.message;
|
|
28
|
+
const content = msg?.content;
|
|
29
|
+
if (!content) return null;
|
|
30
|
+
const parts = [];
|
|
31
|
+
for (const block of content) {
|
|
32
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
33
|
+
parts.push(block.text);
|
|
34
|
+
} else if (block.type === "tool_use") {
|
|
35
|
+
const name = block.name;
|
|
36
|
+
parts.push(`[tool] ${name}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return parts.length > 0 ? parts.join("\n") : null;
|
|
40
|
+
}
|
|
41
|
+
if (type === "tool_result") {
|
|
42
|
+
const name = event.tool_name ?? "tool";
|
|
43
|
+
const content = event.content;
|
|
44
|
+
if (content && content.length > 200) {
|
|
45
|
+
return `[${name}] ${content.slice(0, 200)}...`;
|
|
46
|
+
}
|
|
47
|
+
return content ? `[${name}] ${content}` : `[${name}] done`;
|
|
48
|
+
}
|
|
49
|
+
if (type === "result") {
|
|
50
|
+
const subtype = event.subtype;
|
|
51
|
+
const result = event.result;
|
|
52
|
+
if (subtype === "success" && result) {
|
|
53
|
+
return `[result] ${result.slice(0, 500)}`;
|
|
54
|
+
}
|
|
55
|
+
if (subtype === "error") {
|
|
56
|
+
return `[error] ${event.error ?? "unknown error"}`;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
if (type === "system" || type === "rate_limit_event") {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
function spawnAgent(opts) {
|
|
66
|
+
let child = null;
|
|
67
|
+
let cancelled = false;
|
|
68
|
+
let pid = null;
|
|
69
|
+
const cancel = () => {
|
|
70
|
+
cancelled = true;
|
|
71
|
+
if (child !== null && child.exitCode === null) {
|
|
72
|
+
child.kill("SIGTERM");
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const done = runAgent(opts, (c) => {
|
|
76
|
+
child = c;
|
|
77
|
+
pid = c.pid ?? null;
|
|
78
|
+
}, () => cancelled);
|
|
79
|
+
return { done, cancel, get pid() {
|
|
80
|
+
return pid;
|
|
81
|
+
} };
|
|
82
|
+
}
|
|
83
|
+
async function runAgent(opts, onChild, isCancelled) {
|
|
84
|
+
const startTime = Date.now();
|
|
85
|
+
let lineCount = 0;
|
|
86
|
+
let prompt;
|
|
87
|
+
if (opts.assembledPrompt) {
|
|
88
|
+
prompt = opts.assembledPrompt;
|
|
89
|
+
} else {
|
|
90
|
+
const claudeMd = await readClaudeMd(opts.projectRoot);
|
|
91
|
+
prompt = assembleAutonomousPrompt({
|
|
92
|
+
claudeMd,
|
|
93
|
+
projectName: opts.projectRoot,
|
|
94
|
+
item: opts.item
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const args = ["-p", prompt, "--output-format", "stream-json", "--verbose"];
|
|
98
|
+
if (opts.modelOverride) {
|
|
99
|
+
args.push("--model", opts.modelOverride);
|
|
100
|
+
}
|
|
101
|
+
if (opts.skipPermissions !== false) {
|
|
102
|
+
args.push("--dangerously-skip-permissions");
|
|
103
|
+
}
|
|
104
|
+
const child = spawn("claude", args, {
|
|
105
|
+
cwd: opts.projectRoot,
|
|
106
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
107
|
+
env: { ...process.env }
|
|
108
|
+
});
|
|
109
|
+
onChild(child);
|
|
110
|
+
if (child.pid === void 0) {
|
|
111
|
+
return {
|
|
112
|
+
outcome: "failed",
|
|
113
|
+
exitCode: null,
|
|
114
|
+
lineCount: 0,
|
|
115
|
+
durationMs: Date.now() - startTime,
|
|
116
|
+
errorMessage: "Failed to spawn claude process"
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (child.stdout !== null) {
|
|
120
|
+
const rl = createInterface({ input: child.stdout });
|
|
121
|
+
rl.on("line", (raw) => {
|
|
122
|
+
const text = parseStreamJsonLine(raw);
|
|
123
|
+
if (text === null) return;
|
|
124
|
+
lineCount++;
|
|
125
|
+
const currentLine = lineCount;
|
|
126
|
+
opts.onLine?.("stdout", text);
|
|
127
|
+
opts.client.appendOutputLine(opts.runId, {
|
|
128
|
+
lineNumber: currentLine,
|
|
129
|
+
stream: "stdout",
|
|
130
|
+
content: text
|
|
131
|
+
}).catch(() => {
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (child.stderr !== null) {
|
|
136
|
+
const rl = createInterface({ input: child.stderr });
|
|
137
|
+
rl.on("line", (line) => {
|
|
138
|
+
lineCount++;
|
|
139
|
+
const currentLine = lineCount;
|
|
140
|
+
opts.onLine?.("stderr", line);
|
|
141
|
+
opts.client.appendOutputLine(opts.runId, {
|
|
142
|
+
lineNumber: currentLine,
|
|
143
|
+
stream: "stderr",
|
|
144
|
+
content: line
|
|
145
|
+
}).catch(() => {
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const exitCode = await waitWithTimeout(
|
|
150
|
+
child,
|
|
151
|
+
opts.timeoutMs,
|
|
152
|
+
opts.client,
|
|
153
|
+
opts.projectId,
|
|
154
|
+
opts.deliverableId,
|
|
155
|
+
isCancelled
|
|
156
|
+
);
|
|
157
|
+
const durationMs = Date.now() - startTime;
|
|
158
|
+
if (isCancelled()) {
|
|
159
|
+
return { outcome: "cancelled", exitCode, lineCount, durationMs };
|
|
160
|
+
}
|
|
161
|
+
if (exitCode === null) {
|
|
162
|
+
child.kill("SIGTERM");
|
|
163
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
164
|
+
if (child.exitCode === null) {
|
|
165
|
+
child.kill("SIGKILL");
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
outcome: "timeout",
|
|
169
|
+
exitCode: null,
|
|
170
|
+
lineCount,
|
|
171
|
+
durationMs,
|
|
172
|
+
errorMessage: `Task timed out after ${Math.round(opts.timeoutMs / 1e3)}s`
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
if (exitCode === 0) {
|
|
176
|
+
return { outcome: "completed", exitCode, lineCount, durationMs };
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
outcome: "failed",
|
|
180
|
+
exitCode,
|
|
181
|
+
lineCount,
|
|
182
|
+
durationMs,
|
|
183
|
+
errorMessage: `Agent exited with code ${exitCode}`
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
async function waitWithTimeout(child, timeoutMs, client, projectId, deliverableId, isCancelled) {
|
|
187
|
+
return new Promise((resolve) => {
|
|
188
|
+
let resolved = false;
|
|
189
|
+
let elapsedMs = 0;
|
|
190
|
+
const TICK_MS = 3e3;
|
|
191
|
+
const finish = (code) => {
|
|
192
|
+
if (!resolved) {
|
|
193
|
+
resolved = true;
|
|
194
|
+
clearInterval(timer);
|
|
195
|
+
resolve(code);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
child.on("close", (code) => {
|
|
199
|
+
finish(code ?? 1);
|
|
200
|
+
});
|
|
201
|
+
child.on("error", () => {
|
|
202
|
+
finish(1);
|
|
203
|
+
});
|
|
204
|
+
const timer = setInterval(async () => {
|
|
205
|
+
if (resolved || isCancelled()) {
|
|
206
|
+
clearInterval(timer);
|
|
207
|
+
if (isCancelled() && !resolved) {
|
|
208
|
+
finish(null);
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (deliverableId) {
|
|
213
|
+
try {
|
|
214
|
+
const paused = await client.hasPendingDecisions(projectId, deliverableId);
|
|
215
|
+
if (!paused) {
|
|
216
|
+
elapsedMs += TICK_MS;
|
|
217
|
+
}
|
|
218
|
+
} catch {
|
|
219
|
+
elapsedMs += TICK_MS;
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
elapsedMs += TICK_MS;
|
|
223
|
+
}
|
|
224
|
+
if (elapsedMs >= timeoutMs) {
|
|
225
|
+
finish(null);
|
|
226
|
+
}
|
|
227
|
+
}, TICK_MS);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
export {
|
|
231
|
+
spawnAgent
|
|
232
|
+
};
|