@dadado/agent-kit-cli 6.10.0 → 6.11.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/dashboard/lib/semantic-model.d.mts +14 -0
- package/dashboard/lib/semantic-model.mjs +3 -0
- package/dist/{add-7GH3K44T.js → add-P4DIZKC2.js} +3 -3
- package/dist/{chunk-O5FKTKOW.js → chunk-2B3HHQ3L.js} +3 -3
- package/dist/{chunk-6LRY2CYU.js → chunk-47ZJ3S7M.js} +4 -1
- package/dist/{chunk-TUZVOPKY.js → chunk-5D5BJZW5.js} +75 -122
- package/dist/{chunk-BB22FGQ4.js → chunk-5KDMATUR.js} +1 -1
- package/dist/{chunk-6UKI4CAN.js → chunk-5TEXYAGP.js} +10 -1
- package/dist/{chunk-LPZ2KXVE.js → chunk-6GM5YUWR.js} +1 -1
- package/dist/chunk-7ABY6DYH.js +89 -0
- package/dist/{chunk-HVH24VRL.js → chunk-7T4MDNV3.js} +1 -1
- package/dist/{chunk-BSYQJ5WF.js → chunk-AOSXKF3M.js} +1 -1
- package/dist/{chunk-26KXYR5T.js → chunk-BOZUBCQA.js} +2 -2
- package/dist/{chunk-GQ6Q3P7C.js → chunk-CAOQBBP5.js} +2 -2
- package/dist/{chunk-LGSNC4OI.js → chunk-FQNAEFTW.js} +1 -1
- package/dist/{chunk-BIFWN6BJ.js → chunk-FTLMWPQY.js} +1 -1
- package/dist/{chunk-52WYZFP5.js → chunk-H3PQYVFT.js} +2 -2
- package/dist/{chunk-MTLQN57O.js → chunk-JPAQOESJ.js} +85 -1
- package/dist/{chunk-BZI5G3OZ.js → chunk-KHFPPQJ5.js} +35 -5
- package/dist/{chunk-75ELVLBY.js → chunk-MAXEVJCP.js} +1 -1
- package/dist/{chunk-ZF4YBL7F.js → chunk-Q4J5UXVQ.js} +1 -1
- package/dist/{chunk-CXDAT76O.js → chunk-S4T6KYYA.js} +2 -2
- package/dist/{chunk-TZA7MT4I.js → chunk-SZ5REXPD.js} +2 -2
- package/dist/chunk-UGJ3YAT2.js +273 -0
- package/dist/{chunk-HIJTNHJE.js → chunk-UQSFGLY5.js} +3 -3
- package/dist/{chunk-S7XAV6JK.js → chunk-VWDFMXFK.js} +5 -5
- package/dist/{chunk-K5OCGZWA.js → chunk-YN5NBMQT.js} +8 -8
- package/dist/{commands-EQHK3ZEP.js → commands-F437QCGQ.js} +5 -5
- package/dist/{contribute-VSVPRHQ7.js → contribute-G5DFZCH6.js} +4 -4
- package/dist/{countdown-XYRE4GZU.js → countdown-6SP7IEJ3.js} +7 -7
- package/dist/{diff-4P7LMQK5.js → diff-VCVSR4OV.js} +5 -5
- package/dist/{doctor-E6LOBJYK.js → doctor-5LPPWRPI.js} +9 -9
- package/dist/{engine-info-3MQML5I2.js → engine-info-LEE37RRK.js} +2 -2
- package/dist/{ground-control-726LRB6Q.js → ground-control-IJ5NQVLP.js} +4 -4
- package/dist/{guard-M3W3QE62.js → guard-X6FNFZ27.js} +13 -3
- package/dist/{hook-HJW5SXQG.js → hook-A22PNYY2.js} +5 -5
- package/dist/index.js +23 -21
- package/dist/{init-KKVT2RW4.js → init-VCOMQ32C.js} +12 -12
- package/dist/{install-BPZTP5KT.js → install-YXOE2U6T.js} +12 -12
- package/dist/queue-Q2LEPXSY.js +172 -0
- package/dist/{run-326EEQYY.js → run-BOWCPU56.js} +50 -271
- package/dist/{run-plan-2IFO4G4Y.js → run-plan-P65QMVCS.js} +8 -7
- package/dist/{setup-global-BFBSR2RZ.js → setup-global-QEEW7ASU.js} +6 -6
- package/dist/{status-LNXVLDMP.js → status-WGO2O7TR.js} +7 -7
- package/dist/{update-PX5XFCSG.js → update-LV335HJU.js} +10 -10
- package/package.json +20 -13
|
@@ -53,3 +53,17 @@ export function buildFlightLogTickets(
|
|
|
53
53
|
tickets: Record<string, unknown>[] | null | undefined,
|
|
54
54
|
opts?: { cap?: number },
|
|
55
55
|
): FlightLogTicket[];
|
|
56
|
+
|
|
57
|
+
/** Mission Control snapshot slice (`missionControl`); typed loosely for the TUI tests. */
|
|
58
|
+
export type MissionControlView = {
|
|
59
|
+
now: Record<string, unknown> & { status: string; gaps: string | null };
|
|
60
|
+
flightLog: Record<string, unknown> & { current: string | null };
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export function buildMissionControlView(input: {
|
|
65
|
+
plans?: unknown[];
|
|
66
|
+
handoff?: HandoffMarkdown | null;
|
|
67
|
+
nowMs?: number;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
}): MissionControlView;
|
|
@@ -2044,6 +2044,9 @@ export function buildCurrentExecution(plans, handoff) {
|
|
|
2044
2044
|
planFile: null,
|
|
2045
2045
|
planPath: null,
|
|
2046
2046
|
mode: null,
|
|
2047
|
+
// Gaps outlive the plan: with `Plan: none` they still feed the Flight Log NOW
|
|
2048
|
+
// residual, so the cockpit never reads All clear over open Gaps.
|
|
2049
|
+
gaps: handoff?.gaps || null,
|
|
2047
2050
|
progress: { completed: 0, total: 0 },
|
|
2048
2051
|
previousTodo: null,
|
|
2049
2052
|
currentTodo: null,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
REGISTRY_CLI_ARGS,
|
|
7
7
|
resolveRegistryFromCli
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-MAXEVJCP.js";
|
|
9
9
|
import {
|
|
10
10
|
logger
|
|
11
11
|
} from "./chunk-ZB43YMHW.js";
|
|
@@ -22,8 +22,8 @@ import {
|
|
|
22
22
|
resolveProtectedGlobs,
|
|
23
23
|
saveManifest,
|
|
24
24
|
upsertIdList
|
|
25
|
-
} from "./chunk-
|
|
26
|
-
import "./chunk-
|
|
25
|
+
} from "./chunk-7T4MDNV3.js";
|
|
26
|
+
import "./chunk-47ZJ3S7M.js";
|
|
27
27
|
import {
|
|
28
28
|
KIT_VERSION
|
|
29
29
|
} from "./chunk-7HDQEK6T.js";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
managedPairs
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6GM5YUWR.js";
|
|
4
4
|
import {
|
|
5
5
|
isProtectedPath,
|
|
6
6
|
resolveProtectedGlobs
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-7T4MDNV3.js";
|
|
8
8
|
import {
|
|
9
9
|
resolveContained
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-47ZJ3S7M.js";
|
|
11
11
|
|
|
12
12
|
// src/lifecycle/diff.ts
|
|
13
13
|
import { readFile } from "fs/promises";
|
|
@@ -370,7 +370,10 @@ var KNOWN_SHIPPED_OVERLAY_HASHES = /* @__PURE__ */ new Set([
|
|
|
370
370
|
"f95f94170f26beb4e03d4e24b22139e1aaa6bbb3d4b43d524ea9f12ed296beb4",
|
|
371
371
|
"23e690d5c97eb1f739115b8977a862332fe44da3a4b0888de078cf437cf478b9",
|
|
372
372
|
"f8d95774ad51e1c7cddc93be8115fa2b7ba75d45c60b71c6228b59e8a50c839d",
|
|
373
|
-
"5b8f11be3c7f3af65ea6947cecc199f1acd5cf1fc2b2805ed3496257dd8605b5"
|
|
373
|
+
"5b8f11be3c7f3af65ea6947cecc199f1acd5cf1fc2b2805ed3496257dd8605b5",
|
|
374
|
+
"2bd11cdf44d1fd536d9a52206b79b78ecb7e0276efdf0e598d3cec5f831c35b6",
|
|
375
|
+
"88fa5ebe0d0fc29f8dac3de140797a85fbc8dc00e9b9c461b0e9e10bb9ef4e64",
|
|
376
|
+
"c746b0424dfc3a9e36c588e48526b1f14e9c2c3032397f2ba721fa7f50390230"
|
|
374
377
|
]);
|
|
375
378
|
|
|
376
379
|
// src/lifecycle/paths.ts
|
|
@@ -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-S4T6KYYA.js";
|
|
9
23
|
import {
|
|
10
24
|
classifyGateExit,
|
|
11
25
|
landGateExit
|
|
12
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-BOZUBCQA.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-5TEXYAGP.js";
|
|
31
37
|
import {
|
|
32
38
|
LineSplitter,
|
|
33
39
|
formatHitlSummary,
|
|
34
|
-
operatorQuitStop
|
|
35
|
-
|
|
40
|
+
operatorQuitStop,
|
|
41
|
+
sumUsage
|
|
42
|
+
} from "./chunk-JPAQOESJ.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
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LineSplitter,
|
|
3
3
|
TurnWatcher,
|
|
4
|
+
UsageTally,
|
|
4
5
|
askOperator,
|
|
5
6
|
createTerminalAnswerReader,
|
|
6
7
|
detectHitlGate,
|
|
@@ -8,7 +9,7 @@ import {
|
|
|
8
9
|
noRelayStop,
|
|
9
10
|
unansweredStop,
|
|
10
11
|
userEventLine
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-JPAQOESJ.js";
|
|
12
13
|
import {
|
|
13
14
|
findOnPath
|
|
14
15
|
} from "./chunk-WGLPZXNU.js";
|
|
@@ -314,6 +315,7 @@ var codexBackend = {
|
|
|
314
315
|
translate
|
|
315
316
|
};
|
|
316
317
|
const records = [];
|
|
318
|
+
const usage = new UsageTally();
|
|
317
319
|
let result;
|
|
318
320
|
try {
|
|
319
321
|
result = await spawnLogged(
|
|
@@ -323,6 +325,7 @@ var codexBackend = {
|
|
|
323
325
|
{ ...common, stdinText: prepared.prompt }
|
|
324
326
|
);
|
|
325
327
|
if (result.hitl) records.push(result.hitl);
|
|
328
|
+
if (result.usage) usage.merge(result.usage);
|
|
326
329
|
for (let i = 0; result.resumeWith && i < CODEX_MAX_RESUMES; i += 1) {
|
|
327
330
|
const reply = result.resumeWith;
|
|
328
331
|
const thread = threadId;
|
|
@@ -342,6 +345,7 @@ var codexBackend = {
|
|
|
342
345
|
{ ...common, stdinText: reply, appendLog: true }
|
|
343
346
|
);
|
|
344
347
|
if (result.hitl) records.push(result.hitl);
|
|
348
|
+
if (result.usage) usage.merge(result.usage);
|
|
345
349
|
}
|
|
346
350
|
} catch (err) {
|
|
347
351
|
throw new Error(`codex backend failed to start: ${redactSecrets(String(err), redact)}`);
|
|
@@ -349,6 +353,7 @@ var codexBackend = {
|
|
|
349
353
|
return {
|
|
350
354
|
exitCode: result.exitCode,
|
|
351
355
|
hitl: mergeRecords(records),
|
|
356
|
+
usage,
|
|
352
357
|
...result.lastResult ? { lastResult: result.lastResult } : {}
|
|
353
358
|
};
|
|
354
359
|
}
|
|
@@ -1404,6 +1409,7 @@ function spawnLogged(command, args, logPath, options = {}) {
|
|
|
1404
1409
|
resolve({
|
|
1405
1410
|
exitCode: code ?? 1,
|
|
1406
1411
|
hitl: relay.record,
|
|
1412
|
+
usage: relay.usage,
|
|
1407
1413
|
...lastResult ? { lastResult } : {},
|
|
1408
1414
|
...resumeWith ? { resumeWith } : {}
|
|
1409
1415
|
});
|
|
@@ -1469,8 +1475,10 @@ function createRelay(hitl, child, redactedError) {
|
|
|
1469
1475
|
timers.push(term);
|
|
1470
1476
|
};
|
|
1471
1477
|
let lastResult;
|
|
1478
|
+
const usage = new UsageTally();
|
|
1472
1479
|
const watcher = new TurnWatcher((turn) => {
|
|
1473
1480
|
lastResult = turn;
|
|
1481
|
+
usage.note(turn.sessionId, turn.usage);
|
|
1474
1482
|
const { resultText, assistantTexts } = turn;
|
|
1475
1483
|
if (record.stop || closed) return;
|
|
1476
1484
|
const gate = detectHitlGate(resultText, assistantTexts);
|
|
@@ -1536,6 +1544,7 @@ function createRelay(hitl, child, redactedError) {
|
|
|
1536
1544
|
startError,
|
|
1537
1545
|
record,
|
|
1538
1546
|
lastResult: () => lastResult,
|
|
1547
|
+
usage,
|
|
1539
1548
|
resumeWith: () => resumeWith,
|
|
1540
1549
|
feed: (text) => watcher.feed(text),
|
|
1541
1550
|
finish: () => watcher.end(),
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
extractHandoffNamedPlans,
|
|
3
|
+
namedPlanCandidatePaths,
|
|
4
|
+
parsePlanFrontmatter
|
|
5
|
+
} from "./chunk-L5V3W3DY.js";
|
|
6
|
+
import {
|
|
7
|
+
HANDOFF_REL
|
|
8
|
+
} from "./chunk-C4Q77GGJ.js";
|
|
9
|
+
import {
|
|
10
|
+
fileExists
|
|
11
|
+
} from "./chunk-5B4DVO6C.js";
|
|
12
|
+
|
|
13
|
+
// src/plan-loop/plan-state.ts
|
|
14
|
+
import { readdir, readFile } from "fs/promises";
|
|
15
|
+
import path from "path";
|
|
16
|
+
function countPendingTodos(raw) {
|
|
17
|
+
return parsePlanFrontmatter(raw).todos.filter(
|
|
18
|
+
(t) => (t.status === "pending" || t.status === "in_progress") && t.id !== "dogfood-poc"
|
|
19
|
+
).length;
|
|
20
|
+
}
|
|
21
|
+
async function findActivePlanFile(plansDir) {
|
|
22
|
+
if (!await fileExists(plansDir)) return null;
|
|
23
|
+
const files = (await readdir(plansDir)).filter((f) => f.endsWith(".plan.md")).sort();
|
|
24
|
+
return files[0] ? path.join(plansDir, files[0]) : null;
|
|
25
|
+
}
|
|
26
|
+
async function readPlan(planPath) {
|
|
27
|
+
return readFile(planPath, "utf8");
|
|
28
|
+
}
|
|
29
|
+
var QUEUE_CURSOR_RE = /^- \*\*Queue cursor:\*\*\s*(.+)$/m;
|
|
30
|
+
var QUEUE_STATUS_RE = /^- \*\*Queue status:\*\*\s*(.+)$/m;
|
|
31
|
+
var QUEUE_DONE_STATUSES = /* @__PURE__ */ new Set(["exhausted", "completed", "done"]);
|
|
32
|
+
function readRunQueueState(handoff) {
|
|
33
|
+
const queue = extractHandoffNamedPlans(handoff).runQueue;
|
|
34
|
+
let cursorIndex = null;
|
|
35
|
+
let cursorPlan = null;
|
|
36
|
+
const cursorRaw = QUEUE_CURSOR_RE.exec(handoff)?.[1]?.trim() ?? "";
|
|
37
|
+
const indexMatch = /^(\d+)\b/.exec(cursorRaw);
|
|
38
|
+
if (indexMatch?.[1]) cursorIndex = Number(indexMatch[1]);
|
|
39
|
+
const currentMatch = /current:\s*`?([^`()]+?)`?\s*\)/i.exec(cursorRaw);
|
|
40
|
+
if (currentMatch?.[1]) {
|
|
41
|
+
const base = currentMatch[1].trim().split("/").pop() ?? "";
|
|
42
|
+
if (/\.plan\.md$/i.test(base)) cursorPlan = base;
|
|
43
|
+
}
|
|
44
|
+
const status = QUEUE_STATUS_RE.exec(handoff)?.[1]?.trim().split(/\s+/)[0]?.replace(/[`*]/g, "");
|
|
45
|
+
const queueStatus = status ? status : null;
|
|
46
|
+
const finished = queueStatus !== null && QUEUE_DONE_STATUSES.has(queueStatus.toLowerCase());
|
|
47
|
+
let cursor = null;
|
|
48
|
+
if (cursorIndex !== null && cursorIndex >= 0 && cursorIndex < queue.length) {
|
|
49
|
+
cursor = cursorIndex;
|
|
50
|
+
} else if (cursorPlan && queue.includes(cursorPlan)) {
|
|
51
|
+
cursor = queue.indexOf(cursorPlan);
|
|
52
|
+
}
|
|
53
|
+
const current = cursor !== null ? queue[cursor] ?? null : cursorPlan;
|
|
54
|
+
return { queue, cursor, current, status: queueStatus, finished };
|
|
55
|
+
}
|
|
56
|
+
function defaultPlanStateIo() {
|
|
57
|
+
return {
|
|
58
|
+
readFile: async (file) => {
|
|
59
|
+
try {
|
|
60
|
+
return await readFile(file, "utf8");
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
findActivePlan: findActivePlanFile
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async function resolveActivePlanFromHandoff(root, handoff, io = defaultPlanStateIo()) {
|
|
69
|
+
const queue = readRunQueueState(handoff);
|
|
70
|
+
const base = (queue.queue.length > 0 && !queue.finished ? queue.current : null) ?? extractHandoffNamedPlans(handoff).active;
|
|
71
|
+
if (!base) return io.findActivePlan(path.join(root, ".cursor", "plans"));
|
|
72
|
+
for (const candidate of namedPlanCandidatePaths(root, base)) {
|
|
73
|
+
if (await io.readFile(candidate) !== null) return candidate;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
async function resolveActivePlanPath(root, io = defaultPlanStateIo()) {
|
|
78
|
+
const handoff = await io.readFile(path.join(root, HANDOFF_REL)) ?? "";
|
|
79
|
+
return resolveActivePlanFromHandoff(root, handoff, io);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
countPendingTodos,
|
|
84
|
+
findActivePlanFile,
|
|
85
|
+
readPlan,
|
|
86
|
+
readRunQueueState,
|
|
87
|
+
resolveActivePlanFromHandoff,
|
|
88
|
+
resolveActivePlanPath
|
|
89
|
+
};
|