@dadado/agent-kit-cli 6.10.1 → 6.12.0
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/{add-7GH3K44T.js → add-CLRIMPN4.js} +3 -3
- package/dist/{chunk-52WYZFP5.js → chunk-2R4HYPQH.js} +2 -2
- package/dist/{chunk-26KXYR5T.js → chunk-2TKPKRHO.js} +2 -2
- package/dist/{chunk-CXDAT76O.js → chunk-4WHPZGF4.js} +17 -6
- package/dist/{chunk-6LRY2CYU.js → chunk-5RWTDCJ7.js} +5 -1
- package/dist/{chunk-75ELVLBY.js → chunk-5T4CHRRR.js} +1 -1
- package/dist/chunk-7ABY6DYH.js +89 -0
- package/dist/{chunk-BZI5G3OZ.js → chunk-7TEEGAED.js} +35 -5
- package/dist/{chunk-BSYQJ5WF.js → chunk-CRLMS2JX.js} +1 -1
- package/dist/{chunk-O5FKTKOW.js → chunk-DVCNJNCF.js} +3 -3
- package/dist/{chunk-BB22FGQ4.js → chunk-EE3LTOBZ.js} +1 -1
- package/dist/{chunk-LPZ2KXVE.js → chunk-FX6BIH4C.js} +1 -1
- package/dist/{chunk-6UKI4CAN.js → chunk-GDKTTV2A.js} +13 -2
- package/dist/{chunk-HIJTNHJE.js → chunk-HWYVLEET.js} +3 -3
- package/dist/{chunk-TZA7MT4I.js → chunk-I2SG2VPJ.js} +2 -2
- package/dist/{chunk-LGSNC4OI.js → chunk-IBE2EJZS.js} +1 -1
- package/dist/{chunk-ZF4YBL7F.js → chunk-LAYMAMPL.js} +1 -1
- package/dist/{chunk-GQ6Q3P7C.js → chunk-ODI2N2BN.js} +2 -2
- package/dist/{chunk-BIFWN6BJ.js → chunk-OKQ3SAHK.js} +1 -1
- package/dist/{chunk-K5OCGZWA.js → chunk-PGCRP5A6.js} +8 -8
- package/dist/chunk-TFKEHC2D.js +273 -0
- package/dist/{chunk-S7XAV6JK.js → chunk-UX6FHSO7.js} +5 -5
- package/dist/{chunk-TUZVOPKY.js → chunk-WAWCS5PJ.js} +75 -122
- package/dist/{chunk-MTLQN57O.js → chunk-WRCXRV2U.js} +114 -6
- package/dist/{chunk-HVH24VRL.js → chunk-XJWCL4PO.js} +1 -1
- package/dist/{commands-EQHK3ZEP.js → commands-DVEZOEEO.js} +5 -5
- package/dist/{contribute-VSVPRHQ7.js → contribute-E3COXKH4.js} +4 -4
- package/dist/{countdown-XYRE4GZU.js → countdown-F6EIHGDR.js} +7 -7
- package/dist/{diff-4P7LMQK5.js → diff-SCGNC4SF.js} +5 -5
- package/dist/{doctor-E6LOBJYK.js → doctor-QGO4QB7R.js} +9 -9
- package/dist/{engine-info-3MQML5I2.js → engine-info-MNCKB55Y.js} +2 -2
- package/dist/{ground-control-726LRB6Q.js → ground-control-DB5RSYAT.js} +4 -4
- package/dist/{hook-HJW5SXQG.js → hook-R7V4NG3C.js} +5 -5
- package/dist/index.js +22 -20
- package/dist/{init-KKVT2RW4.js → init-ONPKZS63.js} +12 -12
- package/dist/{install-BPZTP5KT.js → install-NHTYTVSG.js} +12 -12
- package/dist/queue-XI4HUFLJ.js +172 -0
- package/dist/{run-326EEQYY.js → run-EO5P2YZG.js} +50 -271
- package/dist/{run-plan-2IFO4G4Y.js → run-plan-VMW34QY6.js} +8 -7
- package/dist/{setup-global-BFBSR2RZ.js → setup-global-PMKGHX2S.js} +6 -6
- package/dist/{status-LNXVLDMP.js → status-P2I6LE6Y.js} +7 -7
- package/dist/{update-PX5XFCSG.js → update-K6L24JDP.js} +10 -10
- package/package.json +20 -13
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readRunQueueState
|
|
3
|
+
} from "./chunk-7ABY6DYH.js";
|
|
4
|
+
import {
|
|
5
|
+
DRIVER_PROTOCOL_VERSION,
|
|
6
|
+
DriverAgentSink,
|
|
7
|
+
createDriverAnswerReader,
|
|
8
|
+
createDriverEmitter,
|
|
9
|
+
driverReplies,
|
|
10
|
+
driverStop
|
|
11
|
+
} from "./chunk-4WHPZGF4.js";
|
|
12
|
+
import {
|
|
13
|
+
detectAgentBackend
|
|
14
|
+
} from "./chunk-EE3LTOBZ.js";
|
|
15
|
+
import {
|
|
16
|
+
classifyGateExit,
|
|
17
|
+
landGateExit
|
|
18
|
+
} from "./chunk-2TKPKRHO.js";
|
|
19
|
+
import {
|
|
20
|
+
buildDispatchPrompt,
|
|
21
|
+
ensureDispatchLogPath,
|
|
22
|
+
readCommandFile,
|
|
23
|
+
runHeadlessDispatch
|
|
24
|
+
} from "./chunk-7TEEGAED.js";
|
|
25
|
+
import {
|
|
26
|
+
formatHitlSummary,
|
|
27
|
+
hitlExitCode
|
|
28
|
+
} from "./chunk-WRCXRV2U.js";
|
|
29
|
+
import {
|
|
30
|
+
HANDOFF_REL
|
|
31
|
+
} from "./chunk-C4Q77GGJ.js";
|
|
32
|
+
|
|
33
|
+
// src/plan-loop/dispatch-driver.ts
|
|
34
|
+
import { readFile } from "fs/promises";
|
|
35
|
+
import path from "path";
|
|
36
|
+
var DISPATCH_DRIVER_TICK = 1;
|
|
37
|
+
var QUEUE_STATE_POLL_MS = 1e3;
|
|
38
|
+
function projectQueueState(handoff) {
|
|
39
|
+
const { queue, cursor, current, status } = readRunQueueState(handoff);
|
|
40
|
+
if (queue.length === 0) return { cursor: null, total: 0, current: null, status: null };
|
|
41
|
+
return { cursor, total: queue.length, current, status };
|
|
42
|
+
}
|
|
43
|
+
async function readHandoffText(root) {
|
|
44
|
+
try {
|
|
45
|
+
return await readFile(path.join(root, HANDOFF_REL), "utf8");
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function readQueueState(root) {
|
|
51
|
+
return projectQueueState(await readHandoffText(root) ?? "");
|
|
52
|
+
}
|
|
53
|
+
function createQueueStateWatcher(opts) {
|
|
54
|
+
const read = opts.read ?? (() => readHandoffText(opts.root));
|
|
55
|
+
let last = JSON.stringify(opts.initial);
|
|
56
|
+
let pending = null;
|
|
57
|
+
let busy = null;
|
|
58
|
+
let stopped = false;
|
|
59
|
+
const emit = (next, key) => {
|
|
60
|
+
last = key;
|
|
61
|
+
pending = null;
|
|
62
|
+
opts.emitter.emit({ type: "queue_state", ...next });
|
|
63
|
+
};
|
|
64
|
+
const sample = async () => {
|
|
65
|
+
const text = await read();
|
|
66
|
+
if (text !== null && text.trim() === "") return null;
|
|
67
|
+
const next = projectQueueState(text ?? "");
|
|
68
|
+
return { next, key: JSON.stringify(next) };
|
|
69
|
+
};
|
|
70
|
+
const check = async () => {
|
|
71
|
+
const got = await sample();
|
|
72
|
+
if (!got || stopped) return;
|
|
73
|
+
if (got.key === last) {
|
|
74
|
+
pending = null;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (got.key !== pending) {
|
|
78
|
+
pending = got.key;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
emit(got.next, got.key);
|
|
82
|
+
};
|
|
83
|
+
const tick = () => {
|
|
84
|
+
if (busy) return busy;
|
|
85
|
+
busy = check().finally(() => {
|
|
86
|
+
busy = null;
|
|
87
|
+
});
|
|
88
|
+
return busy;
|
|
89
|
+
};
|
|
90
|
+
opts.emitter.emit({ type: "queue_state", ...opts.initial });
|
|
91
|
+
const timer = setInterval(() => {
|
|
92
|
+
void tick();
|
|
93
|
+
}, opts.pollMs ?? QUEUE_STATE_POLL_MS);
|
|
94
|
+
timer.unref?.();
|
|
95
|
+
return {
|
|
96
|
+
flush: async () => {
|
|
97
|
+
if (busy) await busy;
|
|
98
|
+
const got = await sample();
|
|
99
|
+
if (!got || stopped || got.key === last) return;
|
|
100
|
+
emit(got.next, got.key);
|
|
101
|
+
},
|
|
102
|
+
stop: () => {
|
|
103
|
+
stopped = true;
|
|
104
|
+
clearInterval(timer);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async function landDispatchOutcome(opts) {
|
|
109
|
+
const { result } = opts;
|
|
110
|
+
const stop = result.hitl?.stop;
|
|
111
|
+
const trigger = classifyGateExit({ stop, failed: opts.exitCode !== 0 });
|
|
112
|
+
if (!trigger) return;
|
|
113
|
+
const summary = result.lastResult?.resultText.trim() || result.lastResult?.assistantTexts.at(-1)?.trim() || void 0;
|
|
114
|
+
try {
|
|
115
|
+
await landGateExit({
|
|
116
|
+
root: opts.root,
|
|
117
|
+
outcome: {
|
|
118
|
+
trigger,
|
|
119
|
+
exitCode: opts.exitCode,
|
|
120
|
+
reason: stop?.message ?? `${opts.backendId} exited with code ${opts.exitCode}`,
|
|
121
|
+
command: `run ${opts.slash}`,
|
|
122
|
+
backend: opts.backendId,
|
|
123
|
+
logPath: opts.logPath,
|
|
124
|
+
...stop ? { askId: stop.askId } : {},
|
|
125
|
+
...summary ? { summary } : {},
|
|
126
|
+
...result.lastResult ? {
|
|
127
|
+
gateText: [result.lastResult.resultText, ...result.lastResult.assistantTexts].join(
|
|
128
|
+
"\n"
|
|
129
|
+
)
|
|
130
|
+
} : {}
|
|
131
|
+
},
|
|
132
|
+
log: opts.log
|
|
133
|
+
});
|
|
134
|
+
} catch (err) {
|
|
135
|
+
opts.log(`gate-exit: landing failed: ${String(err)}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async function runDispatchDriver(opts) {
|
|
139
|
+
const root = path.resolve(opts.root);
|
|
140
|
+
const emitter = createDriverEmitter(opts.events.write, opts.events.now);
|
|
141
|
+
const reader = createDriverAnswerReader({
|
|
142
|
+
input: opts.events.input,
|
|
143
|
+
emitter,
|
|
144
|
+
tick: () => DISPATCH_DRIVER_TICK
|
|
145
|
+
});
|
|
146
|
+
const writeErr = opts.events.writeErr ?? ((text) => {
|
|
147
|
+
process.stderr.write(text);
|
|
148
|
+
});
|
|
149
|
+
const say = (message, level = "info") => emitter.emit({ type: "log", level, message });
|
|
150
|
+
let ticks = 0;
|
|
151
|
+
let queue = null;
|
|
152
|
+
const finish = async (exitCode, reason, result) => {
|
|
153
|
+
if (queue) {
|
|
154
|
+
await queue.flush();
|
|
155
|
+
queue.stop();
|
|
156
|
+
}
|
|
157
|
+
emitter.emit({
|
|
158
|
+
type: "run_end",
|
|
159
|
+
exitCode,
|
|
160
|
+
ticks,
|
|
161
|
+
pending: null,
|
|
162
|
+
reason,
|
|
163
|
+
planExhausted: false,
|
|
164
|
+
replies: driverReplies(result?.hitl?.replies),
|
|
165
|
+
stop: driverStop(result?.hitl?.stop),
|
|
166
|
+
usage: result?.usage?.total() ?? null
|
|
167
|
+
});
|
|
168
|
+
reader.close();
|
|
169
|
+
return exitCode;
|
|
170
|
+
};
|
|
171
|
+
const detected = await detectAgentBackend(opts.backend, opts.whichFn);
|
|
172
|
+
if (!detected.ok) {
|
|
173
|
+
say(detected.message, "error");
|
|
174
|
+
return finish(1, detected.message);
|
|
175
|
+
}
|
|
176
|
+
const file = await readCommandFile(root, opts.slash);
|
|
177
|
+
if (!file.ok) {
|
|
178
|
+
say(file.message, "error");
|
|
179
|
+
return finish(1, file.message);
|
|
180
|
+
}
|
|
181
|
+
const prompt = buildDispatchPrompt(file.body, opts.note);
|
|
182
|
+
const initialQueue = await readQueueState(root);
|
|
183
|
+
emitter.emit({
|
|
184
|
+
type: "run_start",
|
|
185
|
+
protocol: DRIVER_PROTOCOL_VERSION,
|
|
186
|
+
command: opts.slash,
|
|
187
|
+
backend: detected.id,
|
|
188
|
+
plan: null,
|
|
189
|
+
pending: null,
|
|
190
|
+
maxTicks: null,
|
|
191
|
+
hitl: opts.noHitl ? "off" : "driver",
|
|
192
|
+
queue: initialQueue
|
|
193
|
+
});
|
|
194
|
+
queue = createQueueStateWatcher({
|
|
195
|
+
root,
|
|
196
|
+
emitter,
|
|
197
|
+
initial: initialQueue,
|
|
198
|
+
pollMs: opts.queuePollMs
|
|
199
|
+
});
|
|
200
|
+
say(`Dispatch: ${opts.slash} via ${detected.id}`);
|
|
201
|
+
say(`Command file: ${path.relative(root, file.path)}`);
|
|
202
|
+
if (opts.dryRun) {
|
|
203
|
+
say("--dry-run: no agent will be started. Prompt:");
|
|
204
|
+
say(prompt);
|
|
205
|
+
return finish(0, "dry-run");
|
|
206
|
+
}
|
|
207
|
+
const logPath = await ensureDispatchLogPath(root);
|
|
208
|
+
say(`Log: ${path.relative(root, logPath)}`);
|
|
209
|
+
const onSigInt = () => {
|
|
210
|
+
queue?.stop();
|
|
211
|
+
emitter.emit({
|
|
212
|
+
type: "run_end",
|
|
213
|
+
exitCode: 130,
|
|
214
|
+
ticks,
|
|
215
|
+
pending: null,
|
|
216
|
+
reason: "interrupted (SIGINT)",
|
|
217
|
+
planExhausted: false,
|
|
218
|
+
usage: null
|
|
219
|
+
});
|
|
220
|
+
process.exit(130);
|
|
221
|
+
};
|
|
222
|
+
process.on("SIGINT", onSigInt);
|
|
223
|
+
try {
|
|
224
|
+
ticks = DISPATCH_DRIVER_TICK;
|
|
225
|
+
let result;
|
|
226
|
+
try {
|
|
227
|
+
result = await runHeadlessDispatch({
|
|
228
|
+
backendId: detected.id,
|
|
229
|
+
bin: detected.bin,
|
|
230
|
+
workspace: root,
|
|
231
|
+
prompt,
|
|
232
|
+
model: opts.model,
|
|
233
|
+
logPath,
|
|
234
|
+
spawnFn: opts.spawnFn,
|
|
235
|
+
versionFn: opts.versionFn,
|
|
236
|
+
log: (line) => say(line),
|
|
237
|
+
render: new DriverAgentSink(emitter, DISPATCH_DRIVER_TICK),
|
|
238
|
+
hitl: {
|
|
239
|
+
policy: opts.noHitl ? "off" : "driver",
|
|
240
|
+
readAnswer: reader.read,
|
|
241
|
+
write: writeErr
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
} catch (err) {
|
|
245
|
+
say(String(err), "error");
|
|
246
|
+
return finish(1, `${opts.slash} failed to start: ${String(err)}`);
|
|
247
|
+
}
|
|
248
|
+
for (const line of formatHitlSummary(result.hitl)) say(line);
|
|
249
|
+
const exitCode = hitlExitCode(result.exitCode, result.hitl);
|
|
250
|
+
if (opts.landOnGate) {
|
|
251
|
+
await landDispatchOutcome({
|
|
252
|
+
root,
|
|
253
|
+
slash: opts.slash,
|
|
254
|
+
backendId: detected.id,
|
|
255
|
+
logPath,
|
|
256
|
+
exitCode,
|
|
257
|
+
result,
|
|
258
|
+
log: (line) => say(line, "warn")
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
const stop = result.hitl?.stop;
|
|
262
|
+
const reason = stop ? stop.message : exitCode === 0 ? "session ended" : `${detected.id} exited with code ${exitCode}`;
|
|
263
|
+
return finish(exitCode, reason, result);
|
|
264
|
+
} finally {
|
|
265
|
+
process.off("SIGINT", onSigInt);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export {
|
|
270
|
+
readHandoffText,
|
|
271
|
+
landDispatchOutcome,
|
|
272
|
+
runDispatchDriver
|
|
273
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isBranchInBase
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CRLMS2JX.js";
|
|
4
4
|
import {
|
|
5
5
|
GATE_EXIT_BRANCH_PREFIX,
|
|
6
6
|
GATE_EXIT_NOTE_DIR,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
isSafeBaseRef,
|
|
12
12
|
landGateExit,
|
|
13
13
|
resolveGateExitRefs
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-2TKPKRHO.js";
|
|
15
15
|
import {
|
|
16
16
|
ensurePathIgnored
|
|
17
17
|
} from "./chunk-MUTTNRX4.js";
|
|
@@ -19,14 +19,14 @@ import {
|
|
|
19
19
|
ensureDispatchLogPath,
|
|
20
20
|
readCommandFile,
|
|
21
21
|
runHeadlessDispatch
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-7TEEGAED.js";
|
|
23
23
|
import {
|
|
24
24
|
redactSecrets
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-GDKTTV2A.js";
|
|
26
26
|
import {
|
|
27
27
|
formatHitlSummary,
|
|
28
28
|
hitlExitCode
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-WRCXRV2U.js";
|
|
30
30
|
|
|
31
31
|
// src/plan-loop/review-job.ts
|
|
32
32
|
import { randomBytes } from "crypto";
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InputLine,
|
|
3
|
+
ScrollRegion,
|
|
4
|
+
renderMcLive,
|
|
5
|
+
runMcTuiLoop
|
|
6
|
+
} from "./chunk-LFWPB2JR.js";
|
|
7
|
+
import {
|
|
8
|
+
countPendingTodos,
|
|
9
|
+
findActivePlanFile,
|
|
10
|
+
readPlan,
|
|
11
|
+
readRunQueueState,
|
|
12
|
+
resolveActivePlanFromHandoff,
|
|
13
|
+
resolveActivePlanPath
|
|
14
|
+
} from "./chunk-7ABY6DYH.js";
|
|
1
15
|
import {
|
|
2
16
|
DRIVER_PROTOCOL_VERSION,
|
|
3
17
|
DriverAgentSink,
|
|
@@ -5,20 +19,12 @@ import {
|
|
|
5
19
|
createDriverEmitter,
|
|
6
20
|
driverReplies,
|
|
7
21
|
driverStop
|
|
8
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-4WHPZGF4.js";
|
|
9
23
|
import {
|
|
10
24
|
classifyGateExit,
|
|
11
25
|
landGateExit
|
|
12
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-2TKPKRHO.js";
|
|
13
27
|
import {
|
|
14
|
-
InputLine,
|
|
15
|
-
ScrollRegion,
|
|
16
|
-
renderMcLive,
|
|
17
|
-
runMcTuiLoop
|
|
18
|
-
} from "./chunk-LFWPB2JR.js";
|
|
19
|
-
import {
|
|
20
|
-
extractHandoffNamedPlans,
|
|
21
|
-
namedPlanCandidatePaths,
|
|
22
28
|
parsePlanFrontmatter
|
|
23
29
|
} from "./chunk-L5V3W3DY.js";
|
|
24
30
|
import {
|
|
@@ -27,12 +33,13 @@ import {
|
|
|
27
33
|
parseStreamLine,
|
|
28
34
|
redactSecrets,
|
|
29
35
|
renderStreamEvent
|
|
30
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-GDKTTV2A.js";
|
|
31
37
|
import {
|
|
32
38
|
LineSplitter,
|
|
33
39
|
formatHitlSummary,
|
|
34
|
-
operatorQuitStop
|
|
35
|
-
|
|
40
|
+
operatorQuitStop,
|
|
41
|
+
sumUsage
|
|
42
|
+
} from "./chunk-WRCXRV2U.js";
|
|
36
43
|
import {
|
|
37
44
|
TtySpinner,
|
|
38
45
|
shouldUseVisualMotion,
|
|
@@ -54,77 +61,8 @@ import {
|
|
|
54
61
|
} from "./chunk-5B4DVO6C.js";
|
|
55
62
|
|
|
56
63
|
// src/mission-control/live-run.ts
|
|
57
|
-
import { readFile
|
|
58
|
-
import path2 from "path";
|
|
59
|
-
|
|
60
|
-
// src/plan-loop/plan-state.ts
|
|
61
|
-
import { readdir, readFile } from "fs/promises";
|
|
64
|
+
import { readFile } from "fs/promises";
|
|
62
65
|
import path from "path";
|
|
63
|
-
function countPendingTodos(raw) {
|
|
64
|
-
return parsePlanFrontmatter(raw).todos.filter(
|
|
65
|
-
(t) => (t.status === "pending" || t.status === "in_progress") && t.id !== "dogfood-poc"
|
|
66
|
-
).length;
|
|
67
|
-
}
|
|
68
|
-
async function findActivePlanFile(plansDir) {
|
|
69
|
-
if (!await fileExists(plansDir)) return null;
|
|
70
|
-
const files = (await readdir(plansDir)).filter((f) => f.endsWith(".plan.md")).sort();
|
|
71
|
-
return files[0] ? path.join(plansDir, files[0]) : null;
|
|
72
|
-
}
|
|
73
|
-
async function readPlan(planPath) {
|
|
74
|
-
return readFile(planPath, "utf8");
|
|
75
|
-
}
|
|
76
|
-
var QUEUE_CURSOR_RE = /^- \*\*Queue cursor:\*\*\s*(.+)$/m;
|
|
77
|
-
var QUEUE_STATUS_RE = /^- \*\*Queue status:\*\*\s*(.+)$/m;
|
|
78
|
-
var QUEUE_DONE_STATUSES = /* @__PURE__ */ new Set(["exhausted", "completed", "done"]);
|
|
79
|
-
function readRunQueueState(handoff) {
|
|
80
|
-
const queue = extractHandoffNamedPlans(handoff).runQueue;
|
|
81
|
-
let cursorIndex = null;
|
|
82
|
-
let cursorPlan = null;
|
|
83
|
-
const cursorRaw = QUEUE_CURSOR_RE.exec(handoff)?.[1]?.trim() ?? "";
|
|
84
|
-
const indexMatch = /^(\d+)\b/.exec(cursorRaw);
|
|
85
|
-
if (indexMatch?.[1]) cursorIndex = Number(indexMatch[1]);
|
|
86
|
-
const currentMatch = /current:\s*`?([^`()]+?)`?\s*\)/i.exec(cursorRaw);
|
|
87
|
-
if (currentMatch?.[1]) {
|
|
88
|
-
const base = currentMatch[1].trim().split("/").pop() ?? "";
|
|
89
|
-
if (/\.plan\.md$/i.test(base)) cursorPlan = base;
|
|
90
|
-
}
|
|
91
|
-
const status = QUEUE_STATUS_RE.exec(handoff)?.[1]?.trim().split(/\s+/)[0]?.replace(/[`*]/g, "");
|
|
92
|
-
const queueStatus = status ? status : null;
|
|
93
|
-
const finished = queueStatus !== null && QUEUE_DONE_STATUSES.has(queueStatus.toLowerCase());
|
|
94
|
-
let cursor = null;
|
|
95
|
-
if (cursorIndex !== null && cursorIndex >= 0 && cursorIndex < queue.length) {
|
|
96
|
-
cursor = cursorIndex;
|
|
97
|
-
} else if (cursorPlan && queue.includes(cursorPlan)) {
|
|
98
|
-
cursor = queue.indexOf(cursorPlan);
|
|
99
|
-
}
|
|
100
|
-
const current = cursor !== null ? queue[cursor] ?? null : cursorPlan;
|
|
101
|
-
return { queue, cursor, current, status: queueStatus, finished };
|
|
102
|
-
}
|
|
103
|
-
function defaultPlanStateIo() {
|
|
104
|
-
return {
|
|
105
|
-
readFile: async (file) => {
|
|
106
|
-
try {
|
|
107
|
-
return await readFile(file, "utf8");
|
|
108
|
-
} catch {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
findActivePlan: findActivePlanFile
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
async function resolveActivePlanFromHandoff(root, handoff, io = defaultPlanStateIo()) {
|
|
116
|
-
const queue = readRunQueueState(handoff);
|
|
117
|
-
const base = (queue.queue.length > 0 && !queue.finished ? queue.current : null) ?? extractHandoffNamedPlans(handoff).active;
|
|
118
|
-
if (!base) return io.findActivePlan(path.join(root, ".cursor", "plans"));
|
|
119
|
-
for (const candidate of namedPlanCandidatePaths(root, base)) {
|
|
120
|
-
if (await io.readFile(candidate) !== null) return candidate;
|
|
121
|
-
}
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
async function resolveActivePlanPath(root, io = defaultPlanStateIo()) {
|
|
125
|
-
const handoff = await io.readFile(path.join(root, HANDOFF_REL)) ?? "";
|
|
126
|
-
return resolveActivePlanFromHandoff(root, handoff, io);
|
|
127
|
-
}
|
|
128
66
|
|
|
129
67
|
// src/mission-control/live-feed.ts
|
|
130
68
|
import { StringDecoder } from "string_decoder";
|
|
@@ -274,7 +212,7 @@ function defaultMissionIo() {
|
|
|
274
212
|
return {
|
|
275
213
|
readFile: async (file) => {
|
|
276
214
|
try {
|
|
277
|
-
return await
|
|
215
|
+
return await readFile(file, "utf8");
|
|
278
216
|
} catch {
|
|
279
217
|
return null;
|
|
280
218
|
}
|
|
@@ -289,7 +227,7 @@ function firstWord(raw) {
|
|
|
289
227
|
}
|
|
290
228
|
async function readLiveMission(root, io = defaultMissionIo()) {
|
|
291
229
|
const mission = emptyLiveMission();
|
|
292
|
-
const handoff = await io.readFile(
|
|
230
|
+
const handoff = await io.readFile(path.join(root, HANDOFF_REL)) ?? "";
|
|
293
231
|
mission.mode = firstWord(MODE_RE.exec(handoff)?.[1]);
|
|
294
232
|
const { queue, cursor, current, status: queueStatus, finished } = readRunQueueState(handoff);
|
|
295
233
|
let checklist = [];
|
|
@@ -310,7 +248,7 @@ async function readLiveMission(root, io = defaultMissionIo()) {
|
|
|
310
248
|
if (planPath) {
|
|
311
249
|
const raw = await io.readFile(planPath);
|
|
312
250
|
if (raw !== null) {
|
|
313
|
-
mission.planFile =
|
|
251
|
+
mission.planFile = path.basename(planPath);
|
|
314
252
|
const { todos } = parsePlanFrontmatter(raw);
|
|
315
253
|
const open = todos.filter((t) => t.status !== "cancelled");
|
|
316
254
|
mission.todos = {
|
|
@@ -365,7 +303,7 @@ async function withLiveTui(opts, run) {
|
|
|
365
303
|
columns,
|
|
366
304
|
now,
|
|
367
305
|
backend: opts.backend,
|
|
368
|
-
logPath:
|
|
306
|
+
logPath: path.relative(opts.root, opts.logPath) || opts.logPath
|
|
369
307
|
});
|
|
370
308
|
opts.onFeed?.(feed);
|
|
371
309
|
const missionLoader = opts.missionLoader ?? createLiveMissionLoader(opts.root, { now });
|
|
@@ -501,14 +439,14 @@ async function withLiveTui(opts, run) {
|
|
|
501
439
|
}
|
|
502
440
|
|
|
503
441
|
// src/plan-loop/run-loop.ts
|
|
504
|
-
import { readFile as
|
|
505
|
-
import
|
|
442
|
+
import { readFile as readFile3, rm, unlink } from "fs/promises";
|
|
443
|
+
import path4 from "path";
|
|
506
444
|
|
|
507
445
|
// src/plan-loop/external-review.ts
|
|
508
446
|
import { spawn } from "child_process";
|
|
509
|
-
import
|
|
510
|
-
var CANONICAL_REL =
|
|
511
|
-
var FALLBACK_REL =
|
|
447
|
+
import path2 from "path";
|
|
448
|
+
var CANONICAL_REL = path2.join(".cursor", "scripts", "plan-external-review.sh");
|
|
449
|
+
var FALLBACK_REL = path2.join("scripts", "plan-external-review.sh");
|
|
512
450
|
function isPlanExhaustedReason(reason) {
|
|
513
451
|
const r = reason.trim().toLowerCase();
|
|
514
452
|
if (!r) return false;
|
|
@@ -530,8 +468,8 @@ async function armExternalPlanReview(root, options = {}) {
|
|
|
530
468
|
const existsFn = options.existsFn ?? fileExists;
|
|
531
469
|
const log = options.log ?? ((line) => console.log(line));
|
|
532
470
|
const force = options.force === true;
|
|
533
|
-
const canonicalPath =
|
|
534
|
-
const fallbackPath =
|
|
471
|
+
const canonicalPath = path2.join(root, CANONICAL_REL);
|
|
472
|
+
const fallbackPath = path2.join(root, FALLBACK_REL);
|
|
535
473
|
let scriptPath = null;
|
|
536
474
|
let scriptRel = CANONICAL_REL;
|
|
537
475
|
if (await existsFn(canonicalPath)) {
|
|
@@ -598,7 +536,7 @@ async function armExternalPlanReview(root, options = {}) {
|
|
|
598
536
|
}
|
|
599
537
|
|
|
600
538
|
// src/plan-loop/persona-banners.ts
|
|
601
|
-
import
|
|
539
|
+
import path3 from "path";
|
|
602
540
|
import {
|
|
603
541
|
blue,
|
|
604
542
|
cyan,
|
|
@@ -634,7 +572,7 @@ function resolveColor(name, fallback) {
|
|
|
634
572
|
async function resolveCliPersonaId(root) {
|
|
635
573
|
try {
|
|
636
574
|
const cfg = await readJson(
|
|
637
|
-
|
|
575
|
+
path3.join(root, ".cursor", "context", "config.json")
|
|
638
576
|
);
|
|
639
577
|
const modes = cfg?.agentPersona?.modes ?? cfg?.workspaceSkin?.modes;
|
|
640
578
|
const id = modes?.[CLI_RUN_PLAN_MODE];
|
|
@@ -645,7 +583,7 @@ async function resolveCliPersonaId(root) {
|
|
|
645
583
|
}
|
|
646
584
|
async function loadPersonaPack(root, personaId) {
|
|
647
585
|
try {
|
|
648
|
-
const personaPath =
|
|
586
|
+
const personaPath = path3.join(root, "registry", "personas", "core", personaId, "persona.json");
|
|
649
587
|
const pack = await readJson(personaPath);
|
|
650
588
|
if (!pack || typeof pack.id !== "string") return null;
|
|
651
589
|
return pack;
|
|
@@ -694,7 +632,7 @@ function createPersonaBannerPrinter(persona) {
|
|
|
694
632
|
}
|
|
695
633
|
|
|
696
634
|
// src/plan-loop/sentinel.ts
|
|
697
|
-
import { readFile as
|
|
635
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
698
636
|
var SENTINEL_RE = /LOOP_TICK_RESULT:\s*(continue|stop(?:\s*[—-].*)?)/i;
|
|
699
637
|
function takeFromText(text) {
|
|
700
638
|
if (!text) return null;
|
|
@@ -763,14 +701,14 @@ function parseTickResultStatus(content) {
|
|
|
763
701
|
}
|
|
764
702
|
async function parseTickResultStatusFromLogFile(logPath) {
|
|
765
703
|
try {
|
|
766
|
-
return parseTickResultStatus(await
|
|
704
|
+
return parseTickResultStatus(await readFile2(logPath, "utf8"));
|
|
767
705
|
} catch {
|
|
768
706
|
return null;
|
|
769
707
|
}
|
|
770
708
|
}
|
|
771
709
|
async function parseSentinelFromLogFile(logPath) {
|
|
772
710
|
try {
|
|
773
|
-
const content = await
|
|
711
|
+
const content = await readFile2(logPath, "utf8");
|
|
774
712
|
return parseSentinelFromLog(content);
|
|
775
713
|
} catch {
|
|
776
714
|
return { kind: "missing" };
|
|
@@ -935,6 +873,7 @@ async function runPlanLoop(opts) {
|
|
|
935
873
|
const logDir = statePaths.loopLogsDir;
|
|
936
874
|
let tick = 0;
|
|
937
875
|
let ticksRun = 0;
|
|
876
|
+
let runUsage = null;
|
|
938
877
|
const driver = opts.events ? (() => {
|
|
939
878
|
const emitter = createDriverEmitter(opts.events.write, opts.events.now);
|
|
940
879
|
return {
|
|
@@ -992,7 +931,15 @@ async function runPlanLoop(opts) {
|
|
|
992
931
|
}
|
|
993
932
|
};
|
|
994
933
|
const finishRun = (exitCode, reason, pending2, planExhausted = false) => {
|
|
995
|
-
emit({
|
|
934
|
+
emit({
|
|
935
|
+
type: "run_end",
|
|
936
|
+
exitCode,
|
|
937
|
+
ticks: ticksRun,
|
|
938
|
+
pending: pending2,
|
|
939
|
+
reason,
|
|
940
|
+
planExhausted,
|
|
941
|
+
usage: runUsage
|
|
942
|
+
});
|
|
996
943
|
driver?.reader.close();
|
|
997
944
|
return exitCode;
|
|
998
945
|
};
|
|
@@ -1002,7 +949,7 @@ async function runPlanLoop(opts) {
|
|
|
1002
949
|
return finishRun(1, "no active plan", null);
|
|
1003
950
|
}
|
|
1004
951
|
const pending = async () => countPendingTodos(await readPlan(planPath));
|
|
1005
|
-
landPlan =
|
|
952
|
+
landPlan = path4.basename(planPath);
|
|
1006
953
|
if (statePaths.invalid !== void 0) {
|
|
1007
954
|
say(
|
|
1008
955
|
`${STATE_ROOT_ENV}=${statePaths.invalid} is not supported (use .cursor or .agent-kit); using .cursor.`,
|
|
@@ -1022,7 +969,8 @@ async function runPlanLoop(opts) {
|
|
|
1022
969
|
ticks: ticksRun,
|
|
1023
970
|
pending: null,
|
|
1024
971
|
reason: "interrupted (SIGINT)",
|
|
1025
|
-
planExhausted: false
|
|
972
|
+
planExhausted: false,
|
|
973
|
+
usage: runUsage
|
|
1026
974
|
});
|
|
1027
975
|
} else {
|
|
1028
976
|
console.log("");
|
|
@@ -1040,12 +988,12 @@ async function runPlanLoop(opts) {
|
|
|
1040
988
|
protocol: DRIVER_PROTOCOL_VERSION,
|
|
1041
989
|
command: "run-plan",
|
|
1042
990
|
backend: opts.backend.id,
|
|
1043
|
-
plan:
|
|
991
|
+
plan: path4.basename(planPath),
|
|
1044
992
|
pending: pendingAtStart,
|
|
1045
993
|
maxTicks: opts.maxTicks,
|
|
1046
994
|
hitl: opts.noHitl ? "off" : "driver"
|
|
1047
995
|
});
|
|
1048
|
-
say(`Active plan: ${
|
|
996
|
+
say(`Active plan: ${path4.basename(planPath)}`);
|
|
1049
997
|
say(`Pending to-dos: ${pendingAtStart} | max ticks: ${opts.maxTicks}`);
|
|
1050
998
|
say(`Backend: ${opts.backend.id}`);
|
|
1051
999
|
if (persona) {
|
|
@@ -1094,10 +1042,10 @@ async function runPlanLoop(opts) {
|
|
|
1094
1042
|
endReason = "plan exhausted";
|
|
1095
1043
|
break;
|
|
1096
1044
|
}
|
|
1097
|
-
const logPath =
|
|
1045
|
+
const logPath = path4.join(logDir, `tick-${stamp()}.log`);
|
|
1098
1046
|
landLogPath = logPath;
|
|
1099
1047
|
landBackend = backend.id;
|
|
1100
|
-
const relLog =
|
|
1048
|
+
const relLog = path4.relative(opts.root, logPath);
|
|
1101
1049
|
if (!driver) console.log("");
|
|
1102
1050
|
const tickLine = `=== tick ${tick}/${opts.maxTicks} - pending: ${before} - log: ${relLog} ===`;
|
|
1103
1051
|
if (banners) banners.tickStart(tickLine);
|
|
@@ -1117,18 +1065,23 @@ async function runPlanLoop(opts) {
|
|
|
1117
1065
|
let lastResult;
|
|
1118
1066
|
let replies = [];
|
|
1119
1067
|
let limit = null;
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1068
|
+
let tickUsage = null;
|
|
1069
|
+
const endTick = (pendingAfter, sentinel2) => {
|
|
1070
|
+
runUsage = sumUsage(runUsage, tickUsage);
|
|
1071
|
+
emit({
|
|
1072
|
+
type: "tick_end",
|
|
1073
|
+
tick,
|
|
1074
|
+
backend: backend.id,
|
|
1075
|
+
limit,
|
|
1076
|
+
exitCode: agentExit,
|
|
1077
|
+
pendingBefore: before,
|
|
1078
|
+
pendingAfter,
|
|
1079
|
+
result: driverSentinel(sentinel2),
|
|
1080
|
+
replies: driverReplies(replies),
|
|
1081
|
+
stop: driverStop(hitlStop),
|
|
1082
|
+
usage: tickUsage
|
|
1083
|
+
});
|
|
1084
|
+
};
|
|
1132
1085
|
try {
|
|
1133
1086
|
const runOpts = {
|
|
1134
1087
|
workspace: opts.root,
|
|
@@ -1148,6 +1101,7 @@ async function runPlanLoop(opts) {
|
|
|
1148
1101
|
}
|
|
1149
1102
|
}) : await runTickWithSpinner(`tick ${tick}`, backend, runOpts, opts.plain === true);
|
|
1150
1103
|
agentExit = result.exitCode;
|
|
1104
|
+
tickUsage = result.usage?.total() ?? null;
|
|
1151
1105
|
for (const line of formatHitlSummary(result.hitl)) say(line);
|
|
1152
1106
|
hitlStop = result.hitl?.stop;
|
|
1153
1107
|
replies = result.hitl?.replies ?? [];
|
|
@@ -1180,7 +1134,7 @@ async function runPlanLoop(opts) {
|
|
|
1180
1134
|
}
|
|
1181
1135
|
let logText = "";
|
|
1182
1136
|
try {
|
|
1183
|
-
logText = await
|
|
1137
|
+
logText = await readFile3(logPath, "utf8");
|
|
1184
1138
|
} catch {
|
|
1185
1139
|
}
|
|
1186
1140
|
limit = detectUsageLimit(logText);
|
|
@@ -1294,7 +1248,7 @@ async function runPlanLoop(opts) {
|
|
|
1294
1248
|
const finishDetail = `after ${tick} tick(s); pending: ${pendingNow}`;
|
|
1295
1249
|
if (banners) banners.phaseComplete(finishDetail);
|
|
1296
1250
|
say(
|
|
1297
|
-
`Loop finished after ${tick} tick(s). Pending now: ${pendingNow}. Logs in ${
|
|
1251
|
+
`Loop finished after ${tick} tick(s). Pending now: ${pendingNow}. Logs in ${path4.relative(opts.root, logDir)}/`
|
|
1298
1252
|
);
|
|
1299
1253
|
if (planExhausted || shouldArmExternalPlanReview({ pending: pendingNow, stopReason })) {
|
|
1300
1254
|
await armExternalPlanReview(
|
|
@@ -1310,7 +1264,6 @@ async function runPlanLoop(opts) {
|
|
|
1310
1264
|
}
|
|
1311
1265
|
|
|
1312
1266
|
export {
|
|
1313
|
-
readRunQueueState,
|
|
1314
1267
|
shouldUseLiveTui,
|
|
1315
1268
|
withLiveTui,
|
|
1316
1269
|
runPlanLoop
|