@dadado/agent-kit-cli 6.25.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.
Files changed (75) hide show
  1. package/dashboard/dashboard.html +3 -3
  2. package/dashboard/lib/guards.mjs +1 -0
  3. package/dist/{add-OYLOMCM6.js → add-G7KEZLWP.js} +7 -6
  4. package/dist/{chunk-7HDQEK6T.js → chunk-2G4K4ZI5.js} +7 -3
  5. package/dist/{chunk-QLTGHJB3.js → chunk-2GXN7HVG.js} +5 -5
  6. package/dist/{chunk-HSIHZWFF.js → chunk-5A72LTR3.js} +7 -7
  7. package/dist/{chunk-6WUKLS4D.js → chunk-BIFTTL2O.js} +1 -1
  8. package/dist/{chunk-NJ2SUSWX.js → chunk-BVZDPVUL.js} +1 -1
  9. package/dist/{chunk-QACMV46U.js → chunk-ENRXS5O6.js} +19 -12
  10. package/dist/{chunk-2F6NMQOA.js → chunk-FB6G6OD6.js} +3 -3
  11. package/dist/{chunk-MFKHIWEL.js → chunk-FOVHFMSH.js} +1 -1
  12. package/dist/{chunk-EO5NGAYV.js → chunk-FUSNEYGU.js} +29 -3
  13. package/dist/{chunk-GMG7ZH4E.js → chunk-H7KAXI5R.js} +13 -13
  14. package/dist/{chunk-SAQ3EE5R.js → chunk-HGB4DHXV.js} +3 -3
  15. package/dist/{chunk-IFBIO7VT.js → chunk-HXV6VQD4.js} +1402 -42
  16. package/dist/{chunk-XGZOU4DS.js → chunk-I3FGWNU5.js} +4 -4
  17. package/dist/{chunk-6M6UKECW.js → chunk-IHVJTGYR.js} +0 -32
  18. package/dist/{chunk-H7RAFRRZ.js → chunk-IUY24WPE.js} +68 -34
  19. package/dist/chunk-JG5MKMOM.js +248 -0
  20. package/dist/{chunk-KWYF7QNH.js → chunk-JWIJHO67.js} +17 -2
  21. package/dist/chunk-KMK4T4ZM.js +34 -0
  22. package/dist/{chunk-ZMYV6PRE.js → chunk-LEVNLHH3.js} +2 -1
  23. package/dist/{chunk-2XLI7XEY.js → chunk-MGVV6YC4.js} +1 -1
  24. package/dist/{chunk-C7SV7UP5.js → chunk-MWRYQLEG.js} +3 -3
  25. package/dist/{chunk-WKFE3RUC.js → chunk-NHJ4IAVN.js} +5 -3
  26. package/dist/{chunk-C4Q77GGJ.js → chunk-O7VMHCNN.js} +6 -0
  27. package/dist/{chunk-GQSSXDDK.js → chunk-OVRGTHZD.js} +1 -1
  28. package/dist/{chunk-CIV42JGT.js → chunk-PCIYXGB3.js} +2 -2
  29. package/dist/{chunk-7Y74KO7U.js → chunk-PLLXFSN2.js} +12 -12
  30. package/dist/{chunk-QX55T4UX.js → chunk-RJP47EGS.js} +6 -1
  31. package/dist/{chunk-JGG574RK.js → chunk-RRJVC35Y.js} +3 -3
  32. package/dist/{chunk-PIMGV3E5.js → chunk-SWJJW624.js} +1 -1
  33. package/dist/{chunk-G5MQRP6M.js → chunk-SYRJ5TTK.js} +13 -9
  34. package/dist/{chunk-L5V3W3DY.js → chunk-TTUFIE26.js} +60 -14
  35. package/dist/{chunk-JFS4GKP7.js → chunk-XXPI4H4D.js} +2 -2
  36. package/dist/{chunk-M4UL422I.js → chunk-Y5526WCN.js} +6 -6
  37. package/dist/{chunk-CXE6ASSX.js → chunk-Y575INEC.js} +1 -1
  38. package/dist/{chunk-JG3CNGQM.js → chunk-ZNZHDPS3.js} +6 -4
  39. package/dist/{commands-UW2C2ZN4.js → commands-K4HSDML5.js} +8 -6
  40. package/dist/{conflicts-RING6AHV.js → conflicts-4SUWIPWP.js} +9 -10
  41. package/dist/{contribute-LSY75JZH.js → contribute-HE4WCBRY.js} +7 -6
  42. package/dist/{countdown-SZ2P4XHB.js → countdown-TYQHVAIX.js} +74 -45
  43. package/dist/{dashboard-P65XHYCU.js → dashboard-6V6PCNYF.js} +1 -1
  44. package/dist/{dashboard-broadcast-GYK34QYL.js → dashboard-broadcast-PMVQ7PXU.js} +1 -1
  45. package/dist/{diff-NZVBVQSK.js → diff-3XUZM7ZT.js} +8 -7
  46. package/dist/{doctor-TJSXBVGV.js → doctor-KGUWU5SN.js} +16 -15
  47. package/dist/{engine-info-BBI5QO5Y.js → engine-info-VM4VPGQM.js} +2 -2
  48. package/dist/{ground-control-ZJXPUIQN.js → ground-control-ZIDHEOPW.js} +7 -4
  49. package/dist/{handoff-2OZSWGTE.js → handoff-LLT4CI6H.js} +2 -3
  50. package/dist/{hook-3VPKNSOO.js → hook-UPZ3CPYS.js} +22 -22
  51. package/dist/index.js +49 -32
  52. package/dist/{init-UW2BJBO2.js → init-ZHLVXEVT.js} +19 -18
  53. package/dist/{install-RQSI4CHG.js → install-XWOG64W3.js} +19 -18
  54. package/dist/{installs-7TR4H4QH.js → installs-2ROXPO6M.js} +5 -4
  55. package/dist/{mission-control-VSU6NT43.js → mission-control-IGOI3WHS.js} +2 -2
  56. package/dist/models-5BDXREWM.js +45 -0
  57. package/dist/paths-JTPV6SXH.js +107 -0
  58. package/dist/pi-DCMDOY65.js +248 -0
  59. package/dist/{plan-index-BNLUU6T5.js → plan-index-5QZJK4AG.js} +2 -3
  60. package/dist/{queue-JHYILLMX.js → queue-Z5VNNHM6.js} +11 -13
  61. package/dist/{run-CQF5RM5X.js → run-QURAXAR2.js} +24 -30
  62. package/dist/{run-plan-BEOCOJCF.js → run-plan-4MMHVCTS.js} +35 -23
  63. package/dist/{session-start-QV7CEFRX.js → session-start-NC2HE5X5.js} +16 -16
  64. package/dist/{sessions-AWAAO3DU.js → sessions-WWWLYPW6.js} +4 -4
  65. package/dist/{setup-global-ST4TT427.js → setup-global-WDMARD4Z.js} +11 -10
  66. package/dist/{status-HUBPBGUU.js → status-2WNJL7PP.js} +12 -11
  67. package/dist/update-YSVOYYK5.js +32 -0
  68. package/dist/{update-all-YYUTXHGR.js → update-all-5XLTCHPX.js} +20 -18
  69. package/package.json +14 -4
  70. package/pi/agent-kit.ts +224 -0
  71. package/dist/chunk-7ABY6DYH.js +0 -89
  72. package/dist/chunk-AQLBEEPD.js +0 -625
  73. package/dist/chunk-MUTTNRX4.js +0 -53
  74. package/dist/chunk-TOSAAQ5A.js +0 -71
  75. package/dist/update-DD5UZPGG.js +0 -31
@@ -1,625 +0,0 @@
1
- import {
2
- readPlan,
3
- resolveActivePlanPath
4
- } from "./chunk-7ABY6DYH.js";
5
- import {
6
- isBackendId,
7
- isRequestedBackend
8
- } from "./chunk-TOSAAQ5A.js";
9
- import {
10
- RedactingStreamBuffer,
11
- claudeRedactions,
12
- redactSecrets
13
- } from "./chunk-IFBIO7VT.js";
14
- import {
15
- loadContextConfig
16
- } from "./chunk-PFEUZXVT.js";
17
- import {
18
- fileExists
19
- } from "./chunk-5B4DVO6C.js";
20
-
21
- // src/plan-loop/model-roles.ts
22
- var ROLE_CAPABILITIES = Object.freeze({
23
- claude: { workerModel: true, subworkerModel: true, reviewer: true },
24
- "cursor-agent": { workerModel: true, subworkerModel: false, reviewer: true },
25
- codex: { workerModel: true, subworkerModel: false, reviewer: false },
26
- openrouter: { workerModel: true, subworkerModel: false, reviewer: false },
27
- "cursor-acp": { workerModel: false, subworkerModel: false, reviewer: false }
28
- });
29
- var ROLE_MODEL_ID = /^[A-Za-z0-9._:/+=,[\]-]{1,128}$/;
30
- var ROLE_WORKER_TYPE_KEY = /^[a-z0-9][a-z0-9_-]{0,63}$/;
31
- var SUBWORKER_AUTO = "auto";
32
- var REVIEWER_SCOPES = ["off", "tick", "plan"];
33
- var REVIEWER_BACKENDS = ["auto", "claude", "cursor-agent"];
34
- var CLAUDE_SUBAGENT_MODEL_ENV = "CLAUDE_CODE_SUBAGENT_MODEL";
35
- function isPlainObject(v) {
36
- return v !== null && typeof v === "object" && !Array.isArray(v);
37
- }
38
- function modelField(v, where) {
39
- if (v === void 0 || v === null || v === "") return {};
40
- if (typeof v !== "string" || !ROLE_MODEL_ID.test(v.trim())) {
41
- return { error: `${where} must be a model id (letters, digits, . _ : / + = , [ ] -)` };
42
- }
43
- return { value: v.trim() };
44
- }
45
- function parseModelRoles(raw) {
46
- if (raw === void 0 || raw === null) return { ok: true, roles: {} };
47
- if (!isPlainObject(raw)) return { ok: false, error: "roles must be an object" };
48
- const roles = {};
49
- for (const key of Object.keys(raw)) {
50
- if (key !== "worker" && key !== "subworker" && key !== "reviewer") {
51
- return { ok: false, error: `unknown roles key: ${key}` };
52
- }
53
- }
54
- if (raw.worker !== void 0 && raw.worker !== null) {
55
- const w = raw.worker;
56
- if (!isPlainObject(w)) return { ok: false, error: "roles.worker must be an object" };
57
- for (const key of Object.keys(w)) {
58
- if (key !== "backend" && key !== "model") {
59
- return { ok: false, error: `unknown roles.worker key: ${key}` };
60
- }
61
- }
62
- const worker = {};
63
- if (w.backend !== void 0 && w.backend !== null && w.backend !== "") {
64
- const b = typeof w.backend === "string" ? w.backend.trim().toLowerCase() : "";
65
- if (!isRequestedBackend(b)) {
66
- return {
67
- ok: false,
68
- error: `roles.worker.backend must be auto or a kit backend id (got ${JSON.stringify(w.backend)})`
69
- };
70
- }
71
- worker.backend = b;
72
- }
73
- const m = modelField(w.model, "roles.worker.model");
74
- if (m.error) return { ok: false, error: m.error };
75
- if (m.value) worker.model = m.value;
76
- roles.worker = worker;
77
- }
78
- if (raw.subworker !== void 0 && raw.subworker !== null) {
79
- const s = raw.subworker;
80
- if (!isPlainObject(s)) return { ok: false, error: "roles.subworker must be an object" };
81
- for (const key of Object.keys(s)) {
82
- if (key !== "model" && key !== "byWorkerType") {
83
- return { ok: false, error: `unknown roles.subworker key: ${key}` };
84
- }
85
- }
86
- const sub = {};
87
- const m = modelField(s.model, "roles.subworker.model");
88
- if (m.error) return { ok: false, error: m.error };
89
- if (m.value) sub.model = m.value;
90
- if (s.byWorkerType !== void 0 && s.byWorkerType !== null) {
91
- if (!isPlainObject(s.byWorkerType)) {
92
- return { ok: false, error: "roles.subworker.byWorkerType must be an object" };
93
- }
94
- const map = {};
95
- for (const [type, value] of Object.entries(s.byWorkerType)) {
96
- if (!ROLE_WORKER_TYPE_KEY.test(type)) {
97
- return {
98
- ok: false,
99
- error: `roles.subworker.byWorkerType key ${type} is not a worker_type`
100
- };
101
- }
102
- const mv = modelField(value, `roles.subworker.byWorkerType.${type}`);
103
- if (mv.error) return { ok: false, error: mv.error };
104
- if (mv.value) map[type] = mv.value;
105
- }
106
- sub.byWorkerType = map;
107
- }
108
- roles.subworker = sub;
109
- }
110
- if (raw.reviewer !== void 0 && raw.reviewer !== null) {
111
- const r = raw.reviewer;
112
- if (!isPlainObject(r)) return { ok: false, error: "roles.reviewer must be an object" };
113
- const reviewer = {};
114
- for (const key of Object.keys(r)) {
115
- if (!["enabled", "scope", "backend", "model", "advisorModel"].includes(key)) {
116
- return { ok: false, error: `unknown roles.reviewer key: ${key}` };
117
- }
118
- }
119
- if (r.enabled !== void 0 && r.enabled !== null) {
120
- if (typeof r.enabled !== "boolean") {
121
- return { ok: false, error: "roles.reviewer.enabled must be boolean" };
122
- }
123
- reviewer.enabled = r.enabled;
124
- }
125
- if (r.scope !== void 0 && r.scope !== null) {
126
- if (typeof r.scope !== "string" || !REVIEWER_SCOPES.includes(r.scope)) {
127
- return { ok: false, error: "roles.reviewer.scope must be off, tick, or plan" };
128
- }
129
- reviewer.scope = r.scope;
130
- }
131
- if (r.backend !== void 0 && r.backend !== null) {
132
- if (typeof r.backend !== "string" || !REVIEWER_BACKENDS.includes(r.backend)) {
133
- return { ok: false, error: "roles.reviewer.backend must be auto, claude, or cursor-agent" };
134
- }
135
- reviewer.backend = r.backend;
136
- }
137
- for (const key of ["model", "advisorModel"]) {
138
- const mv = modelField(r[key], `roles.reviewer.${key}`);
139
- if (mv.error) return { ok: false, error: mv.error };
140
- if (mv.value) reviewer[key] = mv.value;
141
- }
142
- roles.reviewer = reviewer;
143
- }
144
- return { ok: true, roles };
145
- }
146
- function frontmatterBlock(planText) {
147
- const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(planText);
148
- return m?.[1] ?? null;
149
- }
150
- function unquote(v) {
151
- const t = v.trim();
152
- if (t.length >= 2 && (t[0] === '"' || t[0] === "'") && t[t.length - 1] === t[0]) {
153
- return t.slice(1, -1).trim();
154
- }
155
- return t;
156
- }
157
- function readPlanRoleOverrides(planText) {
158
- const block = frontmatterBlock(planText);
159
- if (!block) return {};
160
- const out = {};
161
- const top = (key) => {
162
- const m = new RegExp(`^${key}:[ \\t]*(.+)$`, "m").exec(block);
163
- const v = m?.[1] ? unquote(m[1]) : "";
164
- return v ? v : void 0;
165
- };
166
- const wb = top("worker_backend");
167
- if (wb) out.workerBackend = wb;
168
- const wm = top("worker_model");
169
- if (wm) out.workerModel = wm;
170
- const sm = top("subworker_model");
171
- if (sm) out.subworkerModel = sm;
172
- const items = block.split(/^\s*- id:/m).slice(1);
173
- for (const item of items) {
174
- const status = /^\s*status:\s*(\S+)/m.exec(item)?.[1];
175
- if (status !== "pending" && status !== "in_progress") continue;
176
- if (unquote(item.split("\n")[0] ?? "") === "dogfood-poc") continue;
177
- const type = /^\s*worker_type:\s*(.+)$/m.exec(item)?.[1];
178
- if (type) out.nextWorkerType = unquote(type);
179
- break;
180
- }
181
- return out;
182
- }
183
- var RANK = { flag: 3, plan: 2, config: 1, default: 0 };
184
- function resolveWorkerRole(input) {
185
- const warnings = [];
186
- const layers = [
187
- {
188
- source: "flag",
189
- backend: input.flagBackend?.trim() || void 0,
190
- model: input.flagModel?.trim() || void 0
191
- },
192
- { source: "plan", backend: input.plan?.workerBackend, model: input.plan?.workerModel },
193
- { source: "config", backend: input.roles?.worker?.backend, model: input.roles?.worker?.model },
194
- { source: "default", backend: input.defaultBackend }
195
- ];
196
- const bLayer = layers.find((l) => l.backend) ?? {
197
- source: "default",
198
- backend: input.defaultBackend
199
- };
200
- const backend = bLayer.backend.trim().toLowerCase();
201
- let model;
202
- let modelSource;
203
- for (const l of layers) {
204
- if (!l.model) continue;
205
- if (RANK[l.source] < RANK[bLayer.source]) {
206
- warnings.push(
207
- `${l.source} model ${l.model} ignored: the backend ${backend} came from the ${bLayer.source} layer, and a model only applies to its own backend or a lower layer's`
208
- );
209
- break;
210
- }
211
- model = l.model;
212
- modelSource = l.source;
213
- break;
214
- }
215
- if (model && modelSource !== "flag" && isBackendId(backend) && !ROLE_CAPABILITIES[backend].workerModel) {
216
- warnings.push(
217
- `${modelSource} model ${model} ignored: ${backend} cannot select a model (docs/model-roles-capability-matrix.md)`
218
- );
219
- model = void 0;
220
- modelSource = void 0;
221
- }
222
- return {
223
- backend,
224
- ...model ? { model, modelSource } : {},
225
- backendSource: bLayer.source,
226
- warnings
227
- };
228
- }
229
- function resolveSubworkerModel(input) {
230
- const sub = input.roles?.subworker;
231
- const type = input.plan?.nextWorkerType;
232
- let model;
233
- let source;
234
- if (input.plan?.subworkerModel) {
235
- model = input.plan.subworkerModel;
236
- source = "plan";
237
- } else if (type && sub?.byWorkerType?.[type]) {
238
- model = sub.byWorkerType[type];
239
- source = "worker_type";
240
- } else if (sub?.model) {
241
- model = sub.model;
242
- source = "config";
243
- }
244
- if (!model) return {};
245
- if (model === SUBWORKER_AUTO) {
246
- return {
247
- warning: "subworker model auto is reserved and not implemented yet (auto tier routing); no subworker model set"
248
- };
249
- }
250
- if (!ROLE_MODEL_ID.test(model)) {
251
- return {
252
- warning: `subworker model ${JSON.stringify(model)} is not a model id; no subworker model set`
253
- };
254
- }
255
- if (!ROLE_CAPABILITIES[input.backend].subworkerModel) {
256
- const how = input.backend === "cursor-agent" ? "Cursor subagents follow the worker model (model: inherit)" : "subagents keep the backend default";
257
- return {
258
- warning: `subworker model ${model} is not supported on ${input.backend}; ${how} (docs/model-roles-capability-matrix.md)`
259
- };
260
- }
261
- return { model, source };
262
- }
263
- function describeResolvedRoles(input) {
264
- const model = input.model ? `${input.model} (${input.modelSource ?? "flag"})` : "backend default";
265
- const sub = input.subworker?.model ? `, subworker ${input.subworker.model} (${input.subworker.source})` : "";
266
- return `roles: worker ${input.backendId} (${input.backendSource}), model ${model}${sub}`;
267
- }
268
- function resolveReviewerRole(roles, externalPlanReview) {
269
- const r = roles?.reviewer;
270
- const legacyOn = isPlainObject(externalPlanReview) && externalPlanReview.enabled === true;
271
- const fields = {
272
- ...r?.backend ? { backend: r.backend } : {},
273
- ...r?.model ? { model: r.model } : {},
274
- ...r?.advisorModel ? { advisorModel: r.advisorModel } : {}
275
- };
276
- if (r?.enabled === false || r?.scope === "off") {
277
- return { scope: "off", source: "roles", ...fields };
278
- }
279
- const on = r?.enabled === true || legacyOn;
280
- const source = r?.enabled === true ? "roles" : legacyOn ? "externalPlanReview" : "default";
281
- if (!on) return { scope: "off", source, ...fields };
282
- return { scope: r?.scope ?? "plan", source, ...fields };
283
- }
284
- function normalizeReviewModelId(raw) {
285
- const id = (raw ?? "").toLowerCase().replace(/\s+/g, "").replace(/\[.*$/, "");
286
- if (id === "" || id === "auto" || id === "cursor-auto" || id === "cursorauto" || id === "default")
287
- return "auto";
288
- return id;
289
- }
290
- var FAMILY_PATTERNS = [
291
- [
292
- "haiku",
293
- /^(haiku|claude-haiku|claude-3-haiku.*|claude-3\.5-haiku.*|claude-3-5-haiku.*|claude-haiku-.*|claude-4-haiku.*|claude-4\.5-haiku.*)$/
294
- ],
295
- [
296
- "opus",
297
- /^(opus|claude-opus|claude-3-opus.*|claude-opus-.*|claude-4-opus.*|claude-4\.5-opus.*)$/
298
- ],
299
- [
300
- "sonnet",
301
- /^(sonnet|claude-sonnet|claude-3-sonnet.*|claude-3\.5-sonnet.*|claude-3-5-sonnet.*|claude-3-7-sonnet.*|claude-sonnet-.*|claude-4-sonnet.*|claude-4\.5-sonnet.*)$/
302
- ],
303
- ["fable", /^(fable|claude-fable|claude-fable-.*)$/],
304
- ["composer", /^(composer|composer-.*|cursor-composer.*)$/],
305
- ["grok", /^(grok|grok-.*)$/]
306
- ];
307
- function reviewModelFamily(raw) {
308
- const id = normalizeReviewModelId(raw);
309
- for (const [family, pattern] of FAMILY_PATTERNS) if (pattern.test(id)) return family;
310
- return id;
311
- }
312
- function isFamilyAlias(id, family) {
313
- return id === family || id === `claude-${family}` || id === `cursor-${family}`;
314
- }
315
- function reviewModelRelation(implementer, reviewer) {
316
- const a = normalizeReviewModelId(implementer);
317
- const b = normalizeReviewModelId(reviewer);
318
- if (a === b) return "identical";
319
- const fa = reviewModelFamily(a);
320
- const fb = reviewModelFamily(b);
321
- if (fa !== fb) return "different";
322
- if (isFamilyAlias(a, fa) || isFamilyAlias(b, fb)) return "identical";
323
- return "same-family";
324
- }
325
- function describeIdenticalReviewModel(implementer, reviewer) {
326
- return `reviewer model ${reviewer} is the implementer model (${implementer}): identical-model review is refused, Auto/Auto and a family alias against an id of that family included. This is not a silent self-review; set roles.reviewer.model to a different model`;
327
- }
328
- function describeSameFamilyReviewModel(implementer, reviewer) {
329
- return `reviewer model ${reviewer} and implementer model ${implementer} are the same family (${reviewModelFamily(reviewer)}): the review runs, as a second read by a different model of one family`;
330
- }
331
- function resolveReviewJobRole(input) {
332
- const flagBackend = input.flagBackend?.trim() ?? "";
333
- const flagModel = input.flagModel?.trim() ?? "";
334
- const reviewer = input.roles?.reviewer;
335
- const backend = flagBackend || reviewer?.backend || "auto";
336
- const backendSource = flagBackend ? "flag" : reviewer?.backend ? "config" : "default";
337
- const model = flagModel || (flagBackend ? "" : reviewer?.model ?? "");
338
- const out = {
339
- backend,
340
- backendSource,
341
- ...model ? { model, modelSource: flagModel ? "flag" : "config" } : {}
342
- };
343
- const implementer = input.roles?.worker?.model;
344
- if (model && implementer) {
345
- const relation = reviewModelRelation(implementer, model);
346
- if (relation === "identical") out.refusal = describeIdenticalReviewModel(implementer, model);
347
- else if (relation === "same-family") {
348
- out.warning = describeSameFamilyReviewModel(implementer, model);
349
- }
350
- }
351
- return out;
352
- }
353
- function checkPlanRoleOverrides(plan) {
354
- if (plan.workerBackend && !isRequestedBackend(plan.workerBackend.toLowerCase())) {
355
- return `plan frontmatter worker_backend must be auto or a kit backend id (got ${JSON.stringify(plan.workerBackend)})`;
356
- }
357
- for (const [key, value] of [
358
- ["worker_model", plan.workerModel],
359
- ["subworker_model", plan.subworkerModel]
360
- ]) {
361
- if (value && !ROLE_MODEL_ID.test(value)) {
362
- return `plan frontmatter ${key} must be a model id (got ${JSON.stringify(value)})`;
363
- }
364
- }
365
- return null;
366
- }
367
- async function loadRolesContext(root, usePlan) {
368
- const config = await loadContextConfig(root);
369
- const parsed = parseModelRoles(config?.roles);
370
- if (!parsed.ok) return { ok: false, error: `.cursor/context/config.json: ${parsed.error}` };
371
- let plan = {};
372
- if (usePlan) {
373
- const planPath = await resolveActivePlanPath(root);
374
- if (planPath) {
375
- plan = readPlanRoleOverrides(await readPlan(planPath).catch(() => ""));
376
- const problem = checkPlanRoleOverrides(plan);
377
- if (problem) return { ok: false, error: `${planPath}: ${problem}` };
378
- }
379
- }
380
- return {
381
- ok: true,
382
- roles: parsed.roles,
383
- plan,
384
- reviewer: resolveReviewerRole(parsed.roles, config?.externalPlanReview)
385
- };
386
- }
387
-
388
- // src/plan-loop/external-review.ts
389
- import { spawn } from "child_process";
390
- import path from "path";
391
- var CANONICAL_REL = path.join(".cursor", "scripts", "plan-external-review.sh");
392
- var FALLBACK_REL = path.join("scripts", "plan-external-review.sh");
393
- function isPlanExhaustedReason(reason) {
394
- const r = reason.trim().toLowerCase();
395
- if (!r) return false;
396
- if (r.includes("plan exhausted")) return true;
397
- if (r.includes("nothing to do")) return true;
398
- if (r.includes("no implementable")) return true;
399
- if (/\ball\s+(implementable\s+)?to-?dos?\b/.test(r) && (r.includes("completed") || r.includes("done") || r.includes("exhausted"))) {
400
- return true;
401
- }
402
- return false;
403
- }
404
- function shouldArmExternalPlanReview(input) {
405
- if (input.pending === 0) return true;
406
- if (input.stopReason && isPlanExhaustedReason(input.stopReason)) return true;
407
- return false;
408
- }
409
- async function armExternalPlanReview(root, options = {}) {
410
- const spawnFn = options.spawnFn ?? spawn;
411
- const existsFn = options.existsFn ?? fileExists;
412
- const log = options.log ?? ((line) => console.log(line));
413
- const force = options.force === true;
414
- const canonicalPath = path.join(root, CANONICAL_REL);
415
- const fallbackPath = path.join(root, FALLBACK_REL);
416
- let scriptPath = null;
417
- let scriptRel = CANONICAL_REL;
418
- if (await existsFn(canonicalPath)) {
419
- scriptPath = canonicalPath;
420
- scriptRel = CANONICAL_REL;
421
- } else if (await existsFn(fallbackPath)) {
422
- scriptPath = fallbackPath;
423
- scriptRel = FALLBACK_REL;
424
- }
425
- if (!scriptPath) {
426
- log(
427
- `tip: ${CANONICAL_REL} missing (optional wrapper: ${FALLBACK_REL}). Manual: /plan-external-review (enable externalPlanReview in .cursor/context/config.json).`
428
- );
429
- return { invoked: false, exitCode: null, output: "" };
430
- }
431
- log("Plan exhausted: arming optional external plan review (opt-in handled by script)...");
432
- const args = force ? [scriptPath, "--force", "--print"] : [scriptPath, "--print"];
433
- const implementerModel = options.implementerModel?.trim();
434
- if (implementerModel) args.push("--implementer-model", implementerModel);
435
- return new Promise((resolve) => {
436
- const child = spawnFn("bash", args, {
437
- cwd: root,
438
- env: { ...process.env, AGENT_KIT_HEADLESS: "1" }
439
- });
440
- const redact = claudeRedactions(process.env);
441
- const outBuffer = new RedactingStreamBuffer(redact);
442
- const errBuffer = new RedactingStreamBuffer(redact);
443
- let output = "";
444
- const emitOut = (s) => {
445
- if (!s) return;
446
- output += s;
447
- if (options.writeOut) options.writeOut(s);
448
- else process.stdout.write(s);
449
- };
450
- const emitErr = (s) => {
451
- if (!s) return;
452
- output += s;
453
- process.stderr.write(s);
454
- };
455
- let flushed = false;
456
- const flush = () => {
457
- if (flushed) return;
458
- flushed = true;
459
- emitOut(outBuffer.flush());
460
- emitErr(errBuffer.flush());
461
- };
462
- child.stdout?.on("data", (chunk) => emitOut(outBuffer.push(chunk)));
463
- child.stderr?.on("data", (chunk) => emitErr(errBuffer.push(chunk)));
464
- child.on("error", (err) => {
465
- flush();
466
- log(
467
- `tip: external plan review launcher failed (${redactSecrets(err.message, redact)}). Manual: ${scriptRel} or /plan-external-review`
468
- );
469
- resolve({ invoked: true, exitCode: null, output });
470
- });
471
- child.on("close", (code) => {
472
- flush();
473
- if (code !== 0 && code !== null) {
474
- log(
475
- `tip: external plan review exited ${code} (ignored; does not fail the loop). Manual: ${scriptRel} or /plan-external-review`
476
- );
477
- }
478
- resolve({ invoked: true, exitCode: code, output });
479
- });
480
- });
481
- }
482
-
483
- // src/plan-loop/sentinel.ts
484
- import { readFile } from "fs/promises";
485
- var SENTINEL_RE = /LOOP_TICK_RESULT:\s*(continue|stop(?:\s*[—-].*)?)/i;
486
- function takeFromText(text) {
487
- if (!text) return null;
488
- const m = SENTINEL_RE.exec(text);
489
- if (!m?.[1]) return null;
490
- const raw = m[1].trim();
491
- if (raw.toLowerCase().startsWith("stop")) {
492
- const reason = raw.slice(4).replace(/^[—\-\s]+/, "").trim() || "requested by agent";
493
- return { kind: "stop", reason };
494
- }
495
- return { kind: "continue" };
496
- }
497
- function parseSentinelFromLog(content) {
498
- let lastJson = null;
499
- let lastText = null;
500
- let sawJson = false;
501
- for (const line of content.split(/\r?\n/)) {
502
- const trimmed = line.trim();
503
- if (!trimmed) continue;
504
- if (!trimmed.startsWith("{")) {
505
- const hit = takeFromText(trimmed);
506
- if (hit) lastText = hit;
507
- continue;
508
- }
509
- try {
510
- const ev = JSON.parse(trimmed);
511
- sawJson = true;
512
- if (ev.type === "result" && typeof ev.result === "string") {
513
- const hit = takeFromText(ev.result);
514
- if (hit) lastJson = hit;
515
- }
516
- const parts = ev.type === "assistant" ? ev.message?.content : void 0;
517
- if (Array.isArray(parts)) {
518
- for (const part of parts) {
519
- if (part && typeof part === "object" && part.type === "text" && typeof part.text === "string") {
520
- const hit = takeFromText(part.text);
521
- if (hit) lastJson = hit;
522
- }
523
- }
524
- }
525
- } catch {
526
- const hit = takeFromText(trimmed);
527
- if (hit) lastText = hit;
528
- }
529
- }
530
- return (sawJson ? lastJson : lastText) ?? { kind: "missing" };
531
- }
532
- function parseTickResultStatus(content) {
533
- let last = null;
534
- for (const line of content.split(/\r?\n/)) {
535
- const trimmed = line.trim();
536
- if (!trimmed.startsWith("{")) continue;
537
- try {
538
- const ev = JSON.parse(trimmed);
539
- if (ev.type !== "result") continue;
540
- const errors = Array.isArray(ev.errors) ? ev.errors.filter((e) => typeof e === "string") : [];
541
- last = {
542
- isError: ev.is_error === true,
543
- ...typeof ev.subtype === "string" ? { subtype: ev.subtype } : {},
544
- errors
545
- };
546
- } catch {
547
- }
548
- }
549
- return last;
550
- }
551
- async function parseTickResultStatusFromLogFile(logPath) {
552
- try {
553
- return parseTickResultStatus(await readFile(logPath, "utf8"));
554
- } catch {
555
- return null;
556
- }
557
- }
558
- async function parseSentinelFromLogFile(logPath) {
559
- try {
560
- const content = await readFile(logPath, "utf8");
561
- return parseSentinelFromLog(content);
562
- } catch {
563
- return { kind: "missing" };
564
- }
565
- }
566
- function formatSentinelLine(sentinel) {
567
- if (sentinel.kind === "continue") return "LOOP_TICK_RESULT: continue";
568
- if (sentinel.kind === "stop") return `LOOP_TICK_RESULT: stop - ${sentinel.reason}`;
569
- return "";
570
- }
571
- var AGENT_STOP_LINE_PREFIX = "Agent requested stop: ";
572
- function formatAgentStopLine(sentinel) {
573
- return `${AGENT_STOP_LINE_PREFIX}${formatSentinelLine(sentinel)}`;
574
- }
575
- var AGENT_STOP_LINE_RE = /^Agent requested stop: LOOP_TICK_RESULT: stop - (.*)$/;
576
- function parseAgentStopLine(line) {
577
- const m = AGENT_STOP_LINE_RE.exec(line.replace(/\r$/, ""));
578
- if (!m) return null;
579
- return m[1]?.trim() || "requested by agent";
580
- }
581
- function sentinelFromTurn(turn) {
582
- const fromResult = takeFromText(turn.resultText);
583
- if (fromResult) return fromResult;
584
- for (let i = turn.assistantTexts.length - 1; i >= 0; i--) {
585
- const hit = takeFromText(turn.assistantTexts[i] ?? "");
586
- if (hit) return hit;
587
- }
588
- return null;
589
- }
590
- function tickResultStatusFromTurn(turn) {
591
- return {
592
- isError: turn.isError,
593
- ...turn.subtype !== null ? { subtype: turn.subtype } : {},
594
- errors: turn.errors
595
- };
596
- }
597
- async function resolveTickResultStatus(lastResult, logPath, fromFile = parseTickResultStatusFromLogFile) {
598
- if (lastResult) return tickResultStatusFromTurn(lastResult);
599
- return fromFile(logPath);
600
- }
601
- async function resolveTickSentinel(lastResult, logPath, fromFile = parseSentinelFromLogFile) {
602
- const fromTurn = lastResult ? sentinelFromTurn(lastResult) : null;
603
- return fromTurn ?? fromFile(logPath);
604
- }
605
-
606
- export {
607
- CLAUDE_SUBAGENT_MODEL_ENV,
608
- readPlanRoleOverrides,
609
- resolveWorkerRole,
610
- resolveSubworkerModel,
611
- describeResolvedRoles,
612
- reviewModelRelation,
613
- describeIdenticalReviewModel,
614
- describeSameFamilyReviewModel,
615
- resolveReviewJobRole,
616
- loadRolesContext,
617
- isPlanExhaustedReason,
618
- shouldArmExternalPlanReview,
619
- armExternalPlanReview,
620
- formatSentinelLine,
621
- formatAgentStopLine,
622
- parseAgentStopLine,
623
- resolveTickResultStatus,
624
- resolveTickSentinel
625
- };
@@ -1,53 +0,0 @@
1
- // src/utils/git-local-exclude.ts
2
- import { execFile } from "child_process";
3
- import { appendFile, mkdir, readFile } from "fs/promises";
4
- import path from "path";
5
- function gitAt(cwd) {
6
- return (args) => new Promise((resolve) => {
7
- execFile(
8
- "git",
9
- [...args],
10
- {
11
- cwd,
12
- env: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
13
- encoding: "utf8",
14
- timeout: 3e4
15
- },
16
- (err, stdout, stderr) => {
17
- resolve({
18
- code: err ? typeof err.code === "number" ? err.code : 1 : 0,
19
- stdout: String(stdout ?? ""),
20
- stderr: String(stderr ?? err?.message ?? "")
21
- });
22
- }
23
- );
24
- });
25
- }
26
- async function ensurePathIgnored(git, root, relPath) {
27
- try {
28
- const check = () => git(["check-ignore", "-q", "--", relPath]);
29
- const first = await check();
30
- if (first.code === 0) return true;
31
- if (first.code !== 1) return false;
32
- const prefix = await git(["rev-parse", "--show-prefix"]);
33
- const where = await git(["rev-parse", "--git-path", "info/exclude"]);
34
- if (prefix.code !== 0 || where.code !== 0 || !where.stdout.trim()) return false;
35
- const line = `/${prefix.stdout.trim()}${relPath}`;
36
- const exclude = path.resolve(root, where.stdout.trim());
37
- const current = await readFile(exclude, "utf8").catch(() => "");
38
- if (!current.split("\n").some((l) => l.trim() === line)) {
39
- await mkdir(path.dirname(exclude), { recursive: true });
40
- const sep = current && !current.endsWith("\n") ? "\n" : "";
41
- await appendFile(exclude, `${sep}${line}
42
- `, "utf8");
43
- }
44
- return (await check()).code === 0;
45
- } catch {
46
- return false;
47
- }
48
- }
49
-
50
- export {
51
- gitAt,
52
- ensurePathIgnored
53
- };