@dadado/agent-kit-cli 6.23.0 → 6.26.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/README.md +1 -0
- package/dashboard/dashboard-data.mjs +126 -5
- package/dashboard/dashboard.html +48 -7
- package/dashboard/lib/guards.mjs +1 -0
- package/dashboard/lib/live-refresh.mjs +1 -0
- package/dist/{add-RKZQX6ZK.js → add-G7KEZLWP.js} +17 -8
- package/dist/{chunk-7HDQEK6T.js → chunk-2G4K4ZI5.js} +7 -3
- package/dist/{chunk-5PSV76CQ.js → chunk-2GXN7HVG.js} +26 -7
- package/dist/chunk-2QYWMSI5.js +193 -0
- package/dist/{chunk-B3VR5YBQ.js → chunk-2TW7ENWC.js} +12 -11
- package/dist/{chunk-IESSMKOV.js → chunk-5A72LTR3.js} +7 -7
- package/dist/{chunk-R4DUO5DA.js → chunk-AXQMVQ6O.js} +61 -237
- package/dist/{chunk-6WUKLS4D.js → chunk-BIFTTL2O.js} +1 -1
- package/dist/{chunk-AWQ6KRFV.js → chunk-BVZDPVUL.js} +1 -1
- package/dist/{chunk-QNISTPPZ.js → chunk-ENRXS5O6.js} +19 -12
- package/dist/chunk-FB6G6OD6.js +519 -0
- package/dist/{chunk-MFKHIWEL.js → chunk-FOVHFMSH.js} +1 -1
- package/dist/{chunk-6BEFGKCU.js → chunk-FUSNEYGU.js} +29 -3
- package/dist/chunk-H7KAXI5R.js +357 -0
- package/dist/chunk-HGB4DHXV.js +138 -0
- package/dist/{chunk-W3ZJVBNY.js → chunk-HXV6VQD4.js} +2374 -983
- package/dist/{chunk-BGL5DRK2.js → chunk-I3FGWNU5.js} +4 -4
- package/dist/chunk-IHVJTGYR.js +144 -0
- package/dist/{chunk-5LNHRL5E.js → chunk-IUY24WPE.js} +93 -263
- package/dist/chunk-JG5MKMOM.js +248 -0
- package/dist/{chunk-SGTTC2JP.js → chunk-JWIJHO67.js} +17 -2
- package/dist/chunk-KMK4T4ZM.js +34 -0
- package/dist/{chunk-ZMYV6PRE.js → chunk-LEVNLHH3.js} +2 -1
- package/dist/{chunk-2IP4OO6R.js → chunk-MGVV6YC4.js} +1 -1
- package/dist/{chunk-7TYA3GMI.js → chunk-MWRYQLEG.js} +7 -4
- package/dist/chunk-NHJ4IAVN.js +435 -0
- package/dist/{chunk-C4Q77GGJ.js → chunk-O7VMHCNN.js} +6 -0
- package/dist/{chunk-5EBT3V7G.js → chunk-OVRGTHZD.js} +1 -1
- package/dist/{chunk-F7YAAKYP.js → chunk-PCIYXGB3.js} +7 -5
- package/dist/{chunk-UJCATSYO.js → chunk-PLLXFSN2.js} +46 -17
- package/dist/{chunk-OYFCBYMP.js → chunk-RJP47EGS.js} +18 -1
- package/dist/{chunk-KDJ4ML7I.js → chunk-RRJVC35Y.js} +4 -4
- package/dist/{chunk-DRZFWIBN.js → chunk-SWJJW624.js} +1 -1
- package/dist/{chunk-MJJBIOSY.js → chunk-SYRJ5TTK.js} +34 -12
- package/dist/{chunk-L5V3W3DY.js → chunk-TTUFIE26.js} +60 -14
- package/dist/{chunk-JFS4GKP7.js → chunk-XXPI4H4D.js} +2 -2
- package/dist/{chunk-CVZNSRXV.js → chunk-Y5526WCN.js} +84 -19
- package/dist/{chunk-CQHD6UKB.js → chunk-Y575INEC.js} +2 -1
- package/dist/{chunk-V2H57TFD.js → chunk-ZNZHDPS3.js} +80 -170
- package/dist/{commands-SAQEEE6V.js → commands-K4HSDML5.js} +8 -6
- package/dist/{conflicts-5JOP4GX2.js → conflicts-4SUWIPWP.js} +9 -10
- package/dist/{contribute-BQKRT5GN.js → contribute-HE4WCBRY.js} +7 -5
- package/dist/{countdown-25E5C7AR.js → countdown-TYQHVAIX.js} +305 -32
- package/dist/{dashboard-P65XHYCU.js → dashboard-6V6PCNYF.js} +1 -1
- package/dist/{dashboard-broadcast-GYK34QYL.js → dashboard-broadcast-PMVQ7PXU.js} +1 -1
- package/dist/{diff-6JSXBVSX.js → diff-3XUZM7ZT.js} +15 -6
- package/dist/{doctor-I3MTHS7F.js → doctor-KGUWU5SN.js} +106 -19
- package/dist/{engine-info-BBI5QO5Y.js → engine-info-VM4VPGQM.js} +2 -2
- package/dist/{ground-control-IDCXN5FK.js → ground-control-ZIDHEOPW.js} +7 -4
- package/dist/{guard-RJZEEKSL.js → guard-ZO4Z3LLB.js} +47 -9
- package/dist/{handoff-5AGE2D3T.js → handoff-LLT4CI6H.js} +4 -3
- package/dist/{hook-WNA42CXE.js → hook-UPZ3CPYS.js} +22 -20
- package/dist/index.js +51 -33
- package/dist/{init-FZ2UFPO7.js → init-ZHLVXEVT.js} +25 -18
- package/dist/install-XWOG64W3.js +42 -0
- package/dist/installs-2ROXPO6M.js +223 -0
- package/dist/{mission-control-CRMCRZUU.js → mission-control-IGOI3WHS.js} +2 -2
- package/dist/models-5BDXREWM.js +45 -0
- package/dist/paths-JTPV6SXH.js +107 -0
- package/dist/pi-DCMDOY65.js +248 -0
- package/dist/{plan-index-BNLUU6T5.js → plan-index-5QZJK4AG.js} +2 -3
- package/dist/{queue-JW4VR33H.js → queue-Z5VNNHM6.js} +10 -12
- package/dist/{run-X2WOONTB.js → run-QURAXAR2.js} +27 -33
- package/dist/{run-plan-4MOLLIES.js → run-plan-4MMHVCTS.js} +35 -23
- package/dist/{scan-K3T5RQLC.js → scan-7D3RMO34.js} +2 -1
- package/dist/{session-start-MV7A4263.js → session-start-NC2HE5X5.js} +20 -14
- package/dist/{sessions-UPFDWDMB.js → sessions-WWWLYPW6.js} +4 -4
- package/dist/{setup-global-VNADNTQ2.js → setup-global-WDMARD4Z.js} +12 -10
- package/dist/{status-SXA3OK5E.js → status-2WNJL7PP.js} +17 -13
- package/dist/update-YSVOYYK5.js +32 -0
- package/dist/update-all-5XLTCHPX.js +697 -0
- package/package.json +14 -4
- package/pi/agent-kit.ts +224 -0
- package/dist/chunk-4MR4QXMF.js +0 -52
- package/dist/chunk-7ABY6DYH.js +0 -89
- package/dist/chunk-C4LCOOL4.js +0 -71
- package/dist/chunk-DZCLMIAS.js +0 -391
- package/dist/chunk-HAFRAXGV.js +0 -17
- package/dist/chunk-MUTTNRX4.js +0 -53
- package/dist/install-CTLT3TSI.js +0 -38
- package/dist/update-RMAWXMCV.js +0 -304
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ensurePathIgnored
|
|
3
|
-
} from "./chunk-MUTTNRX4.js";
|
|
4
1
|
import {
|
|
5
2
|
claudeRedactions,
|
|
6
3
|
redactSecrets
|
|
7
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HXV6VQD4.js";
|
|
8
5
|
import {
|
|
9
6
|
findHitlGateInText
|
|
10
7
|
} from "./chunk-P7732A25.js";
|
|
8
|
+
import {
|
|
9
|
+
ensurePathIgnored
|
|
10
|
+
} from "./chunk-TTUFIE26.js";
|
|
11
11
|
import {
|
|
12
12
|
findOnPath
|
|
13
13
|
} from "./chunk-WGLPZXNU.js";
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// src/utils/dir-lock.ts
|
|
2
|
+
import { randomUUID } from "crypto";
|
|
3
|
+
import { mkdir, readFile, rename, rm, stat, writeFile } from "fs/promises";
|
|
4
|
+
import path from "path";
|
|
5
|
+
var DEFAULT_LOCK_TIMEOUT_MS = 6e4;
|
|
6
|
+
var LOCK_RETRY_MS = 200;
|
|
7
|
+
var LOCK_STALE_MS = 5 * 6e4;
|
|
8
|
+
var LOCK_REFRESH_MS = 1e4;
|
|
9
|
+
function lockOwnerPath(lockDir) {
|
|
10
|
+
return path.join(lockDir, "owner.json");
|
|
11
|
+
}
|
|
12
|
+
function isProcessAlive(pid) {
|
|
13
|
+
try {
|
|
14
|
+
process.kill(pid, 0);
|
|
15
|
+
return true;
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function readLockOwner(lockDir) {
|
|
21
|
+
try {
|
|
22
|
+
const raw = await readFile(lockOwnerPath(lockDir), "utf8");
|
|
23
|
+
const parsed = JSON.parse(raw);
|
|
24
|
+
if (typeof parsed.pid === "number" && typeof parsed.uuid === "string") {
|
|
25
|
+
return parsed;
|
|
26
|
+
}
|
|
27
|
+
} catch {
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
async function writeLockOwner(lockDir, owner) {
|
|
32
|
+
const finalPath = lockOwnerPath(lockDir);
|
|
33
|
+
const tmpPath = path.join(lockDir, `owner.${owner.uuid}.${randomUUID()}.tmp`);
|
|
34
|
+
await writeFile(tmpPath, JSON.stringify(owner), "utf8");
|
|
35
|
+
await rename(tmpPath, finalPath);
|
|
36
|
+
}
|
|
37
|
+
async function refreshLockOwner(lockDir, uuid) {
|
|
38
|
+
const owner = await readLockOwner(lockDir);
|
|
39
|
+
if (owner && owner.uuid !== uuid) return;
|
|
40
|
+
await writeLockOwner(lockDir, { pid: process.pid, uuid, updatedAt: Date.now() });
|
|
41
|
+
}
|
|
42
|
+
async function releaseDirLock(lockDir, uuid) {
|
|
43
|
+
const claimPath = path.join(lockDir, `releasing.${uuid}`);
|
|
44
|
+
try {
|
|
45
|
+
await rename(lockOwnerPath(lockDir), claimPath);
|
|
46
|
+
} catch {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
let claimed = null;
|
|
50
|
+
try {
|
|
51
|
+
const raw = await readFile(claimPath, "utf8");
|
|
52
|
+
const parsed = JSON.parse(raw);
|
|
53
|
+
if (typeof parsed.pid === "number" && typeof parsed.uuid === "string") {
|
|
54
|
+
claimed = parsed;
|
|
55
|
+
}
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
if (!claimed || claimed.uuid !== uuid) {
|
|
59
|
+
try {
|
|
60
|
+
await rename(claimPath, lockOwnerPath(lockDir));
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
await rm(lockDir, { recursive: true, force: true });
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function tryReclaimStaleLock(lockDir) {
|
|
71
|
+
let owner;
|
|
72
|
+
let lockStat;
|
|
73
|
+
try {
|
|
74
|
+
lockStat = await stat(lockDir);
|
|
75
|
+
owner = await readLockOwner(lockDir);
|
|
76
|
+
} catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const now = Date.now();
|
|
80
|
+
if (owner) {
|
|
81
|
+
const ownerFresh = now - owner.updatedAt < LOCK_STALE_MS;
|
|
82
|
+
if (isProcessAlive(owner.pid) && ownerFresh) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (now - lockStat.mtimeMs > LOCK_STALE_MS) {
|
|
87
|
+
try {
|
|
88
|
+
await rm(lockDir, { recursive: true, force: true });
|
|
89
|
+
return true;
|
|
90
|
+
} catch {
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
async function acquireDirLock(target, options = {}) {
|
|
96
|
+
const lockDir = `${target}.lock`;
|
|
97
|
+
const deadline = Date.now() + (options.timeoutMs ?? DEFAULT_LOCK_TIMEOUT_MS);
|
|
98
|
+
const uuid = randomUUID();
|
|
99
|
+
const owner = { pid: process.pid, uuid, updatedAt: Date.now() };
|
|
100
|
+
await mkdir(path.dirname(lockDir), { recursive: true });
|
|
101
|
+
let lastErrorCode;
|
|
102
|
+
while (Date.now() < deadline) {
|
|
103
|
+
try {
|
|
104
|
+
await mkdir(lockDir, { recursive: false });
|
|
105
|
+
await writeLockOwner(lockDir, owner);
|
|
106
|
+
let refreshing = false;
|
|
107
|
+
const refreshInterval = setInterval(() => {
|
|
108
|
+
if (refreshing) return;
|
|
109
|
+
refreshing = true;
|
|
110
|
+
refreshLockOwner(lockDir, uuid).catch(() => {
|
|
111
|
+
}).finally(() => {
|
|
112
|
+
refreshing = false;
|
|
113
|
+
});
|
|
114
|
+
}, LOCK_REFRESH_MS);
|
|
115
|
+
return async () => {
|
|
116
|
+
clearInterval(refreshInterval);
|
|
117
|
+
await releaseDirLock(lockDir, uuid);
|
|
118
|
+
};
|
|
119
|
+
} catch (err) {
|
|
120
|
+
const code = err.code;
|
|
121
|
+
lastErrorCode = code;
|
|
122
|
+
if (code === "EEXIST") {
|
|
123
|
+
if (await tryReclaimStaleLock(lockDir)) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
await new Promise((r) => setTimeout(r, LOCK_RETRY_MS + Math.random() * 100));
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (code === "ENOENT") {
|
|
130
|
+
await mkdir(path.dirname(lockDir), { recursive: true });
|
|
131
|
+
await new Promise((r) => setTimeout(r, LOCK_RETRY_MS + Math.random() * 100));
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
throw err;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
throw new Error(
|
|
138
|
+
lastErrorCode === "ENOENT" ? options.vanishedMessage?.(target) ?? `Timed out acquiring lock on ${target}: the lock parent directory kept vanishing.` : options.timeoutMessage?.(target) ?? `Timed out waiting for lock on ${target}.`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export {
|
|
143
|
+
acquireDirLock
|
|
144
|
+
};
|
|
@@ -1,9 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NO_PROGRESS_REASON,
|
|
3
|
+
armExternalPlanReview,
|
|
4
|
+
formatAgentStopLine,
|
|
5
|
+
formatNoProgressLine,
|
|
6
|
+
formatSentinelLine,
|
|
7
|
+
isPlanExhaustedReason,
|
|
8
|
+
resolveTickResultStatus,
|
|
9
|
+
resolveTickSentinel,
|
|
10
|
+
shouldArmExternalPlanReview
|
|
11
|
+
} from "./chunk-JG5MKMOM.js";
|
|
12
|
+
import {
|
|
13
|
+
REVIEW_BACKENDS,
|
|
14
|
+
runReviewJob
|
|
15
|
+
} from "./chunk-5A72LTR3.js";
|
|
1
16
|
import {
|
|
2
17
|
InputLine,
|
|
3
18
|
ScrollRegion,
|
|
4
19
|
renderMcLive,
|
|
5
20
|
runMcTuiLoop
|
|
6
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-Y575INEC.js";
|
|
7
22
|
import {
|
|
8
23
|
DRIVER_PROTOCOL_VERSION,
|
|
9
24
|
DriverAgentSink,
|
|
@@ -12,35 +27,11 @@ import {
|
|
|
12
27
|
createDriverEmitter,
|
|
13
28
|
driverReplies,
|
|
14
29
|
driverStop
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import {
|
|
17
|
-
CLAUDE_SUBAGENT_MODEL_ENV,
|
|
18
|
-
describeIdenticalReviewModel,
|
|
19
|
-
describeResolvedRoles,
|
|
20
|
-
describeSameFamilyReviewModel,
|
|
21
|
-
readPlanRoleOverrides,
|
|
22
|
-
resolveSubworkerModel,
|
|
23
|
-
reviewModelRelation
|
|
24
|
-
} from "./chunk-DZCLMIAS.js";
|
|
25
|
-
import {
|
|
26
|
-
REVIEW_BACKENDS,
|
|
27
|
-
runReviewJob
|
|
28
|
-
} from "./chunk-IESSMKOV.js";
|
|
29
|
-
import {
|
|
30
|
-
countPendingTodos,
|
|
31
|
-
findActivePlanFile,
|
|
32
|
-
readPlan,
|
|
33
|
-
readRunQueueState,
|
|
34
|
-
resolveActivePlanFromHandoff,
|
|
35
|
-
resolveActivePlanPath
|
|
36
|
-
} from "./chunk-7ABY6DYH.js";
|
|
37
|
-
import {
|
|
38
|
-
detectAgentBackend
|
|
39
|
-
} from "./chunk-C4LCOOL4.js";
|
|
30
|
+
} from "./chunk-BIFTTL2O.js";
|
|
40
31
|
import {
|
|
41
32
|
classifyGateExit,
|
|
42
33
|
landGateExit
|
|
43
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-I3FGWNU5.js";
|
|
44
35
|
import {
|
|
45
36
|
QUEUE_LEASE_INTERRUPT_WAIT_MS,
|
|
46
37
|
QUEUE_LEASE_SESSION_ENV,
|
|
@@ -49,23 +40,35 @@ import {
|
|
|
49
40
|
gateCheckIn,
|
|
50
41
|
holdQueueStatus,
|
|
51
42
|
procStart
|
|
52
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-FOVHFMSH.js";
|
|
53
44
|
import {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
CLAUDE_SUBAGENT_MODEL_ENV,
|
|
46
|
+
INSTALL_HINTS,
|
|
47
|
+
countPendingTodos,
|
|
48
|
+
describeIdenticalReviewModel,
|
|
49
|
+
describeResolvedRoles,
|
|
50
|
+
describeSameFamilyReviewModel,
|
|
51
|
+
detectAgentBackend,
|
|
52
|
+
findActivePlanFile,
|
|
59
53
|
parseStreamLine,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
readPlan,
|
|
55
|
+
readPlanRoleOverrides,
|
|
56
|
+
readRunQueueState,
|
|
57
|
+
renderStreamEvent,
|
|
58
|
+
resolveActivePlanFromHandoff,
|
|
59
|
+
resolveActivePlanPath,
|
|
60
|
+
resolveSubworkerModel,
|
|
61
|
+
reviewModelRelation
|
|
62
|
+
} from "./chunk-HXV6VQD4.js";
|
|
63
63
|
import {
|
|
64
64
|
LineSplitter,
|
|
65
65
|
formatHitlSummary,
|
|
66
66
|
operatorQuitStop,
|
|
67
67
|
sumUsage
|
|
68
68
|
} from "./chunk-P7732A25.js";
|
|
69
|
+
import {
|
|
70
|
+
parsePlanFrontmatter
|
|
71
|
+
} from "./chunk-TTUFIE26.js";
|
|
69
72
|
import {
|
|
70
73
|
TtySpinner,
|
|
71
74
|
shouldUseVisualMotion,
|
|
@@ -80,7 +83,7 @@ import {
|
|
|
80
83
|
STATE_ROOT_ENV,
|
|
81
84
|
ensureLoopLogsDir,
|
|
82
85
|
runnerStatePaths
|
|
83
|
-
} from "./chunk-
|
|
86
|
+
} from "./chunk-O7VMHCNN.js";
|
|
84
87
|
import {
|
|
85
88
|
fileExists,
|
|
86
89
|
readJson
|
|
@@ -465,106 +468,12 @@ async function withLiveTui(opts, run) {
|
|
|
465
468
|
}
|
|
466
469
|
|
|
467
470
|
// src/plan-loop/run-loop.ts
|
|
468
|
-
import {
|
|
469
|
-
import
|
|
470
|
-
|
|
471
|
-
// src/plan-loop/external-review.ts
|
|
472
|
-
import { spawn } from "child_process";
|
|
473
|
-
import path2 from "path";
|
|
474
|
-
var CANONICAL_REL = path2.join(".cursor", "scripts", "plan-external-review.sh");
|
|
475
|
-
var FALLBACK_REL = path2.join("scripts", "plan-external-review.sh");
|
|
476
|
-
function isPlanExhaustedReason(reason) {
|
|
477
|
-
const r = reason.trim().toLowerCase();
|
|
478
|
-
if (!r) return false;
|
|
479
|
-
if (r.includes("plan exhausted")) return true;
|
|
480
|
-
if (r.includes("nothing to do")) return true;
|
|
481
|
-
if (r.includes("no implementable")) return true;
|
|
482
|
-
if (/\ball\s+(implementable\s+)?to-?dos?\b/.test(r) && (r.includes("completed") || r.includes("done") || r.includes("exhausted"))) {
|
|
483
|
-
return true;
|
|
484
|
-
}
|
|
485
|
-
return false;
|
|
486
|
-
}
|
|
487
|
-
function shouldArmExternalPlanReview(input) {
|
|
488
|
-
if (input.pending === 0) return true;
|
|
489
|
-
if (input.stopReason && isPlanExhaustedReason(input.stopReason)) return true;
|
|
490
|
-
return false;
|
|
491
|
-
}
|
|
492
|
-
async function armExternalPlanReview(root, options = {}) {
|
|
493
|
-
const spawnFn = options.spawnFn ?? spawn;
|
|
494
|
-
const existsFn = options.existsFn ?? fileExists;
|
|
495
|
-
const log = options.log ?? ((line) => console.log(line));
|
|
496
|
-
const force = options.force === true;
|
|
497
|
-
const canonicalPath = path2.join(root, CANONICAL_REL);
|
|
498
|
-
const fallbackPath = path2.join(root, FALLBACK_REL);
|
|
499
|
-
let scriptPath = null;
|
|
500
|
-
let scriptRel = CANONICAL_REL;
|
|
501
|
-
if (await existsFn(canonicalPath)) {
|
|
502
|
-
scriptPath = canonicalPath;
|
|
503
|
-
scriptRel = CANONICAL_REL;
|
|
504
|
-
} else if (await existsFn(fallbackPath)) {
|
|
505
|
-
scriptPath = fallbackPath;
|
|
506
|
-
scriptRel = FALLBACK_REL;
|
|
507
|
-
}
|
|
508
|
-
if (!scriptPath) {
|
|
509
|
-
log(
|
|
510
|
-
`tip: ${CANONICAL_REL} missing (optional wrapper: ${FALLBACK_REL}). Manual: /plan-external-review (enable externalPlanReview in .cursor/context/config.json).`
|
|
511
|
-
);
|
|
512
|
-
return { invoked: false, exitCode: null, output: "" };
|
|
513
|
-
}
|
|
514
|
-
log("Plan exhausted: arming optional external plan review (opt-in handled by script)...");
|
|
515
|
-
const args = force ? [scriptPath, "--force", "--print"] : [scriptPath, "--print"];
|
|
516
|
-
const implementerModel = options.implementerModel?.trim();
|
|
517
|
-
if (implementerModel) args.push("--implementer-model", implementerModel);
|
|
518
|
-
return new Promise((resolve) => {
|
|
519
|
-
const child = spawnFn("bash", args, {
|
|
520
|
-
cwd: root,
|
|
521
|
-
env: { ...process.env, AGENT_KIT_HEADLESS: "1" }
|
|
522
|
-
});
|
|
523
|
-
const redact = claudeRedactions(process.env);
|
|
524
|
-
const outBuffer = new RedactingStreamBuffer(redact);
|
|
525
|
-
const errBuffer = new RedactingStreamBuffer(redact);
|
|
526
|
-
let output = "";
|
|
527
|
-
const emitOut = (s) => {
|
|
528
|
-
if (!s) return;
|
|
529
|
-
output += s;
|
|
530
|
-
if (options.writeOut) options.writeOut(s);
|
|
531
|
-
else process.stdout.write(s);
|
|
532
|
-
};
|
|
533
|
-
const emitErr = (s) => {
|
|
534
|
-
if (!s) return;
|
|
535
|
-
output += s;
|
|
536
|
-
process.stderr.write(s);
|
|
537
|
-
};
|
|
538
|
-
let flushed = false;
|
|
539
|
-
const flush = () => {
|
|
540
|
-
if (flushed) return;
|
|
541
|
-
flushed = true;
|
|
542
|
-
emitOut(outBuffer.flush());
|
|
543
|
-
emitErr(errBuffer.flush());
|
|
544
|
-
};
|
|
545
|
-
child.stdout?.on("data", (chunk) => emitOut(outBuffer.push(chunk)));
|
|
546
|
-
child.stderr?.on("data", (chunk) => emitErr(errBuffer.push(chunk)));
|
|
547
|
-
child.on("error", (err) => {
|
|
548
|
-
flush();
|
|
549
|
-
log(
|
|
550
|
-
`tip: external plan review launcher failed (${redactSecrets(err.message, redact)}). Manual: ${scriptRel} or /plan-external-review`
|
|
551
|
-
);
|
|
552
|
-
resolve({ invoked: true, exitCode: null, output });
|
|
553
|
-
});
|
|
554
|
-
child.on("close", (code) => {
|
|
555
|
-
flush();
|
|
556
|
-
if (code !== 0 && code !== null) {
|
|
557
|
-
log(
|
|
558
|
-
`tip: external plan review exited ${code} (ignored; does not fail the loop). Manual: ${scriptRel} or /plan-external-review`
|
|
559
|
-
);
|
|
560
|
-
}
|
|
561
|
-
resolve({ invoked: true, exitCode: code, output });
|
|
562
|
-
});
|
|
563
|
-
});
|
|
564
|
-
}
|
|
471
|
+
import { createHash } from "crypto";
|
|
472
|
+
import { readFile as readFile2, rm, unlink } from "fs/promises";
|
|
473
|
+
import path3 from "path";
|
|
565
474
|
|
|
566
475
|
// src/plan-loop/persona-banners.ts
|
|
567
|
-
import
|
|
476
|
+
import path2 from "path";
|
|
568
477
|
import {
|
|
569
478
|
blue,
|
|
570
479
|
cyan,
|
|
@@ -600,7 +509,7 @@ function resolveColor(name, fallback) {
|
|
|
600
509
|
async function resolveCliPersonaId(root) {
|
|
601
510
|
try {
|
|
602
511
|
const cfg = await readJson(
|
|
603
|
-
|
|
512
|
+
path2.join(root, ".cursor", "context", "config.json")
|
|
604
513
|
);
|
|
605
514
|
const modes = cfg?.agentPersona?.modes ?? cfg?.workspaceSkin?.modes;
|
|
606
515
|
const id = modes?.[CLI_RUN_PLAN_MODE];
|
|
@@ -611,7 +520,7 @@ async function resolveCliPersonaId(root) {
|
|
|
611
520
|
}
|
|
612
521
|
async function loadPersonaPack(root, personaId) {
|
|
613
522
|
try {
|
|
614
|
-
const personaPath =
|
|
523
|
+
const personaPath = path2.join(root, "registry", "personas", "core", personaId, "persona.json");
|
|
615
524
|
const pack = await readJson(personaPath);
|
|
616
525
|
if (!pack || typeof pack.id !== "string") return null;
|
|
617
526
|
return pack;
|
|
@@ -659,119 +568,6 @@ function createPersonaBannerPrinter(persona) {
|
|
|
659
568
|
};
|
|
660
569
|
}
|
|
661
570
|
|
|
662
|
-
// src/plan-loop/sentinel.ts
|
|
663
|
-
import { readFile as readFile2 } from "fs/promises";
|
|
664
|
-
var SENTINEL_RE = /LOOP_TICK_RESULT:\s*(continue|stop(?:\s*[—-].*)?)/i;
|
|
665
|
-
function takeFromText(text) {
|
|
666
|
-
if (!text) return null;
|
|
667
|
-
const m = SENTINEL_RE.exec(text);
|
|
668
|
-
if (!m?.[1]) return null;
|
|
669
|
-
const raw = m[1].trim();
|
|
670
|
-
if (raw.toLowerCase().startsWith("stop")) {
|
|
671
|
-
const reason = raw.slice(4).replace(/^[—\-\s]+/, "").trim() || "requested by agent";
|
|
672
|
-
return { kind: "stop", reason };
|
|
673
|
-
}
|
|
674
|
-
return { kind: "continue" };
|
|
675
|
-
}
|
|
676
|
-
function parseSentinelFromLog(content) {
|
|
677
|
-
let lastJson = null;
|
|
678
|
-
let lastText = null;
|
|
679
|
-
let sawJson = false;
|
|
680
|
-
for (const line of content.split(/\r?\n/)) {
|
|
681
|
-
const trimmed = line.trim();
|
|
682
|
-
if (!trimmed) continue;
|
|
683
|
-
if (!trimmed.startsWith("{")) {
|
|
684
|
-
const hit = takeFromText(trimmed);
|
|
685
|
-
if (hit) lastText = hit;
|
|
686
|
-
continue;
|
|
687
|
-
}
|
|
688
|
-
try {
|
|
689
|
-
const ev = JSON.parse(trimmed);
|
|
690
|
-
sawJson = true;
|
|
691
|
-
if (ev.type === "result" && typeof ev.result === "string") {
|
|
692
|
-
const hit = takeFromText(ev.result);
|
|
693
|
-
if (hit) lastJson = hit;
|
|
694
|
-
}
|
|
695
|
-
const parts = ev.type === "assistant" ? ev.message?.content : void 0;
|
|
696
|
-
if (Array.isArray(parts)) {
|
|
697
|
-
for (const part of parts) {
|
|
698
|
-
if (part && typeof part === "object" && part.type === "text" && typeof part.text === "string") {
|
|
699
|
-
const hit = takeFromText(part.text);
|
|
700
|
-
if (hit) lastJson = hit;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
} catch {
|
|
705
|
-
const hit = takeFromText(trimmed);
|
|
706
|
-
if (hit) lastText = hit;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
return (sawJson ? lastJson : lastText) ?? { kind: "missing" };
|
|
710
|
-
}
|
|
711
|
-
function parseTickResultStatus(content) {
|
|
712
|
-
let last = null;
|
|
713
|
-
for (const line of content.split(/\r?\n/)) {
|
|
714
|
-
const trimmed = line.trim();
|
|
715
|
-
if (!trimmed.startsWith("{")) continue;
|
|
716
|
-
try {
|
|
717
|
-
const ev = JSON.parse(trimmed);
|
|
718
|
-
if (ev.type !== "result") continue;
|
|
719
|
-
const errors = Array.isArray(ev.errors) ? ev.errors.filter((e) => typeof e === "string") : [];
|
|
720
|
-
last = {
|
|
721
|
-
isError: ev.is_error === true,
|
|
722
|
-
...typeof ev.subtype === "string" ? { subtype: ev.subtype } : {},
|
|
723
|
-
errors
|
|
724
|
-
};
|
|
725
|
-
} catch {
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
return last;
|
|
729
|
-
}
|
|
730
|
-
async function parseTickResultStatusFromLogFile(logPath) {
|
|
731
|
-
try {
|
|
732
|
-
return parseTickResultStatus(await readFile2(logPath, "utf8"));
|
|
733
|
-
} catch {
|
|
734
|
-
return null;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
async function parseSentinelFromLogFile(logPath) {
|
|
738
|
-
try {
|
|
739
|
-
const content = await readFile2(logPath, "utf8");
|
|
740
|
-
return parseSentinelFromLog(content);
|
|
741
|
-
} catch {
|
|
742
|
-
return { kind: "missing" };
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
function formatSentinelLine(sentinel) {
|
|
746
|
-
if (sentinel.kind === "continue") return "LOOP_TICK_RESULT: continue";
|
|
747
|
-
if (sentinel.kind === "stop") return `LOOP_TICK_RESULT: stop - ${sentinel.reason}`;
|
|
748
|
-
return "";
|
|
749
|
-
}
|
|
750
|
-
function sentinelFromTurn(turn) {
|
|
751
|
-
const fromResult = takeFromText(turn.resultText);
|
|
752
|
-
if (fromResult) return fromResult;
|
|
753
|
-
for (let i = turn.assistantTexts.length - 1; i >= 0; i--) {
|
|
754
|
-
const hit = takeFromText(turn.assistantTexts[i] ?? "");
|
|
755
|
-
if (hit) return hit;
|
|
756
|
-
}
|
|
757
|
-
return null;
|
|
758
|
-
}
|
|
759
|
-
function tickResultStatusFromTurn(turn) {
|
|
760
|
-
return {
|
|
761
|
-
isError: turn.isError,
|
|
762
|
-
...turn.subtype !== null ? { subtype: turn.subtype } : {},
|
|
763
|
-
errors: turn.errors
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
async function resolveTickResultStatus(lastResult, logPath, fromFile = parseTickResultStatusFromLogFile) {
|
|
767
|
-
if (lastResult) return tickResultStatusFromTurn(lastResult);
|
|
768
|
-
return fromFile(logPath);
|
|
769
|
-
}
|
|
770
|
-
async function resolveTickSentinel(lastResult, logPath, fromFile = parseSentinelFromLogFile) {
|
|
771
|
-
const fromTurn = lastResult ? sentinelFromTurn(lastResult) : null;
|
|
772
|
-
return fromTurn ?? fromFile(logPath);
|
|
773
|
-
}
|
|
774
|
-
|
|
775
571
|
// src/plan-loop/usage-limit.ts
|
|
776
572
|
var LIMIT_TEXT_RE = /\b(?:usage|rate)[ _-]?limit|\blimit (?:reached|exceeded)|\bquota (?:exceeded|reached)|\btoo many requests\b|\bout of (?:extra )?usage\b/i;
|
|
777
573
|
var NON_LIMIT_STATUSES = /* @__PURE__ */ new Set(["allowed", "allowed_warning"]);
|
|
@@ -898,6 +694,13 @@ function stamp() {
|
|
|
898
694
|
function sleep(ms) {
|
|
899
695
|
return new Promise((r) => setTimeout(r, ms));
|
|
900
696
|
}
|
|
697
|
+
async function contentHash(file) {
|
|
698
|
+
try {
|
|
699
|
+
return createHash("sha256").update(await readFile2(file)).digest("hex");
|
|
700
|
+
} catch {
|
|
701
|
+
return "absent";
|
|
702
|
+
}
|
|
703
|
+
}
|
|
901
704
|
async function runPlanLoop(opts) {
|
|
902
705
|
const statePaths = runnerStatePaths(opts.root);
|
|
903
706
|
const stopFile = statePaths.stopFile;
|
|
@@ -980,7 +783,9 @@ async function runPlanLoop(opts) {
|
|
|
980
783
|
return finishRun(1, "no active plan", null);
|
|
981
784
|
}
|
|
982
785
|
const pending = async () => countPendingTodos(await readPlan(planPath));
|
|
983
|
-
|
|
786
|
+
const handoffPath = path3.join(opts.root, HANDOFF_REL);
|
|
787
|
+
const fingerprint = async () => `${await contentHash(planPath)}:${await contentHash(handoffPath)}`;
|
|
788
|
+
landPlan = path3.basename(planPath);
|
|
984
789
|
if (statePaths.invalid !== void 0) {
|
|
985
790
|
say(
|
|
986
791
|
`${STATE_ROOT_ENV}=${statePaths.invalid} is not supported (use .cursor or .agent-kit); using .cursor.`,
|
|
@@ -1055,12 +860,12 @@ async function runPlanLoop(opts) {
|
|
|
1055
860
|
protocol: DRIVER_PROTOCOL_VERSION,
|
|
1056
861
|
command: "run-plan",
|
|
1057
862
|
backend: opts.backend.id,
|
|
1058
|
-
plan:
|
|
863
|
+
plan: path3.basename(planPath),
|
|
1059
864
|
pending: pendingAtStart,
|
|
1060
865
|
maxTicks: opts.maxTicks,
|
|
1061
866
|
hitl: opts.noHitl ? "off" : "driver"
|
|
1062
867
|
});
|
|
1063
|
-
say(`Active plan: ${
|
|
868
|
+
say(`Active plan: ${path3.basename(planPath)}`);
|
|
1064
869
|
say(`Pending to-dos: ${pendingAtStart} | max ticks: ${opts.maxTicks}`);
|
|
1065
870
|
say(`Backend: ${opts.backend.id}`);
|
|
1066
871
|
if (persona) {
|
|
@@ -1073,8 +878,9 @@ async function runPlanLoop(opts) {
|
|
|
1073
878
|
}
|
|
1074
879
|
const binary = await opts.backend.resolve();
|
|
1075
880
|
if (!binary) {
|
|
1076
|
-
|
|
1077
|
-
|
|
881
|
+
const missing = opts.backend.id === "local" ? `local backend: pi not found on PATH. ${INSTALL_HINTS.local}` : `${opts.backend.id} not found on PATH`;
|
|
882
|
+
say(missing, "error");
|
|
883
|
+
return finishRun(1, missing, pendingAtStart);
|
|
1078
884
|
}
|
|
1079
885
|
const writer = acquirePlanWriterLease(opts.root, "agent-kit run-plan", {
|
|
1080
886
|
...opts.lease,
|
|
@@ -1104,7 +910,7 @@ async function runPlanLoop(opts) {
|
|
|
1104
910
|
process.env[QUEUE_LEASE_SESSION_ENV] = lease.session;
|
|
1105
911
|
leaseSessionSet = true;
|
|
1106
912
|
restoreQueue = holdQueueStatus(opts.root, {
|
|
1107
|
-
plan:
|
|
913
|
+
plan: path3.basename(planPath),
|
|
1108
914
|
who: `agent-kit run-plan session ${lease.session}`,
|
|
1109
915
|
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1110
916
|
});
|
|
@@ -1131,6 +937,12 @@ async function runPlanLoop(opts) {
|
|
|
1131
937
|
rolesWarned.add(line);
|
|
1132
938
|
say(`roles: ${line}`, "warn");
|
|
1133
939
|
};
|
|
940
|
+
if (tickBackend === "local" && (!reviewer.backend || reviewer.backend === "auto")) {
|
|
941
|
+
warnOnce(
|
|
942
|
+
"post-tick review skipped: the tick ran on the local backend and roles.reviewer.backend is not set (set it to claude or cursor-agent to review local ticks on that engine)"
|
|
943
|
+
);
|
|
944
|
+
return proceed;
|
|
945
|
+
}
|
|
1134
946
|
const relation = reviewModelRelation(tickModel, reviewer.model);
|
|
1135
947
|
if (relation === "identical") {
|
|
1136
948
|
warnOnce(
|
|
@@ -1218,10 +1030,11 @@ async function runPlanLoop(opts) {
|
|
|
1218
1030
|
endReason = "plan exhausted";
|
|
1219
1031
|
break;
|
|
1220
1032
|
}
|
|
1221
|
-
const
|
|
1033
|
+
const beforeFingerprint = await fingerprint();
|
|
1034
|
+
const logPath = path3.join(logDir, `tick-${stamp()}.log`);
|
|
1222
1035
|
landLogPath = logPath;
|
|
1223
1036
|
landBackend = backend.id;
|
|
1224
|
-
const relLog =
|
|
1037
|
+
const relLog = path3.relative(opts.root, logPath);
|
|
1225
1038
|
if (!driver) console.log("");
|
|
1226
1039
|
const tickLine = `=== tick ${tick}/${opts.maxTicks} - pending: ${before} - log: ${relLog} ===`;
|
|
1227
1040
|
if (banners) banners.tickStart(tickLine);
|
|
@@ -1309,7 +1122,16 @@ async function runPlanLoop(opts) {
|
|
|
1309
1122
|
onSpawn: (info) => {
|
|
1310
1123
|
lease?.setAgent(info.pid);
|
|
1311
1124
|
tickAgent = info.pid === void 0 ? null : { pid: info.pid, start: procStart(info.pid) };
|
|
1312
|
-
}
|
|
1125
|
+
},
|
|
1126
|
+
onProgress: (p) => emit({
|
|
1127
|
+
type: "model_loading",
|
|
1128
|
+
tick,
|
|
1129
|
+
backend: backend.id,
|
|
1130
|
+
model: p.model,
|
|
1131
|
+
phase: p.phase,
|
|
1132
|
+
elapsedMs: p.elapsedMs,
|
|
1133
|
+
...p.detail ? { detail: p.detail } : {}
|
|
1134
|
+
})
|
|
1313
1135
|
}) : await runTickWithSpinner(`tick ${tick}`, backend, runOpts, opts.plain === true);
|
|
1314
1136
|
tickAgent = null;
|
|
1315
1137
|
agentExit = result.exitCode;
|
|
@@ -1347,10 +1169,10 @@ async function runPlanLoop(opts) {
|
|
|
1347
1169
|
}
|
|
1348
1170
|
let logText = "";
|
|
1349
1171
|
try {
|
|
1350
|
-
logText = await
|
|
1172
|
+
logText = await readFile2(logPath, "utf8");
|
|
1351
1173
|
} catch {
|
|
1352
1174
|
}
|
|
1353
|
-
limit = detectUsageLimit(logText);
|
|
1175
|
+
limit = backend.id === "local" ? null : detectUsageLimit(logText);
|
|
1354
1176
|
if (limit) {
|
|
1355
1177
|
const hit = limit;
|
|
1356
1178
|
const fallback = opts.onLimit && !limitSwitched && opts.onLimit.id !== backend.id ? opts.onLimit : null;
|
|
@@ -1418,6 +1240,14 @@ async function runPlanLoop(opts) {
|
|
|
1418
1240
|
banners.tickEnd(`pending: ${after}`);
|
|
1419
1241
|
}
|
|
1420
1242
|
endTick(after, sentinel);
|
|
1243
|
+
if (sentinel.kind === "continue" && after >= before && await fingerprint() === beforeFingerprint) {
|
|
1244
|
+
if (banners) banners.stop(NO_PROGRESS_REASON);
|
|
1245
|
+
say(formatNoProgressLine({ before, after, log: relLog }));
|
|
1246
|
+
exitCode = 1;
|
|
1247
|
+
endReason = NO_PROGRESS_REASON;
|
|
1248
|
+
landFailed = true;
|
|
1249
|
+
break;
|
|
1250
|
+
}
|
|
1421
1251
|
const review = await reviewAfterTick(backend.id, implementerModel);
|
|
1422
1252
|
if (review.stop) {
|
|
1423
1253
|
const msg = `Post-tick review landed a gate exit after tick ${tick} - stopping. Read the ticket before the next tick.`;
|
|
@@ -1431,7 +1261,7 @@ async function runPlanLoop(opts) {
|
|
|
1431
1261
|
}
|
|
1432
1262
|
if (sentinel.kind === "continue") {
|
|
1433
1263
|
} else if (sentinel.kind === "stop") {
|
|
1434
|
-
say(
|
|
1264
|
+
say(formatAgentStopLine(sentinel));
|
|
1435
1265
|
stopReason = sentinel.reason;
|
|
1436
1266
|
endReason = `agent requested stop: ${sentinel.reason}`;
|
|
1437
1267
|
if (after === 0 || isPlanExhaustedReason(sentinel.reason)) {
|
|
@@ -1473,7 +1303,7 @@ async function runPlanLoop(opts) {
|
|
|
1473
1303
|
const finishDetail = `after ${tick} tick(s); pending: ${pendingNow}`;
|
|
1474
1304
|
if (banners) banners.phaseComplete(finishDetail);
|
|
1475
1305
|
say(
|
|
1476
|
-
`Loop finished after ${tick} tick(s). Pending now: ${pendingNow}. Logs in ${
|
|
1306
|
+
`Loop finished after ${tick} tick(s). Pending now: ${pendingNow}. Logs in ${path3.relative(opts.root, logDir)}/`
|
|
1477
1307
|
);
|
|
1478
1308
|
if (planExhausted || shouldArmExternalPlanReview({ pending: pendingNow, stopReason })) {
|
|
1479
1309
|
await armExternalPlanReview(opts.root, {
|