@dadado/agent-kit-cli 6.3.0 → 6.5.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/dashboard-data.mjs +14 -2
- package/dashboard/dashboard.html +190 -32
- package/dashboard/lib/chat-sessions.d.mts +63 -0
- package/dashboard/lib/chat-sessions.mjs +430 -0
- package/dashboard/{logo-cursor.svg → logo-bare-metal.svg} +1 -1
- package/dashboard/logo-marketplace.svg +1 -1
- package/dashboard/serve.mjs +5 -1
- package/dashboard/social-preview.svg +2 -2
- package/dist/{add-VA2W7I6P.js → add-IT6XFPKT.js} +2 -2
- package/dist/{chunk-NNKOWUWM.js → chunk-236IYK6L.js} +64 -28
- package/dist/{chunk-YRFSTHR5.js → chunk-2OIPMQHA.js} +13 -219
- package/dist/{chunk-JEI6HACW.js → chunk-2TCRKQHD.js} +35 -379
- package/dist/{chunk-U26MRIWN.js → chunk-34BBPQKI.js} +1 -1
- package/dist/{chunk-GUQYNUV4.js → chunk-4XZXM2ZA.js} +1 -1
- package/dist/{chunk-Z7RYIHHX.js → chunk-5LQP4JGH.js} +3 -3
- package/dist/{chunk-6KUSG7BJ.js → chunk-5WSFO35Y.js} +4 -1
- package/dist/{chunk-MAPOQEA2.js → chunk-6RRG3WOE.js} +8 -1
- package/dist/{chunk-OWWFKGKS.js → chunk-EI3VQ7FU.js} +2 -2
- package/dist/{chunk-QTBTKEXK.js → chunk-FM32XR7A.js} +1 -1
- package/dist/{chunk-KVY425NM.js → chunk-GIZNM73K.js} +4 -2
- package/dist/{chunk-MO63KZBP.js → chunk-HKYJG2FJ.js} +8 -6
- package/dist/{chunk-SV2BR2LZ.js → chunk-I2D75F4I.js} +7 -7
- package/dist/{chunk-25J2SMJQ.js → chunk-IN4MQ3P3.js} +1 -1
- package/dist/{chunk-OVOXRH5W.js → chunk-MEZUW3LL.js} +1 -1
- package/dist/chunk-MTLQN57O.js +380 -0
- package/dist/chunk-R6WH5P7R.js +223 -0
- package/dist/{chunk-VQBI3JVS.js → chunk-TNO7GTAJ.js} +2 -2
- package/dist/{chunk-Z7ABX5QI.js → chunk-U7XOLYDG.js} +4 -2
- package/dist/{chunk-WMVMBPCR.js → chunk-WOGBBJCX.js} +1 -1
- package/dist/{chunk-6GYKOHIL.js → chunk-YIOTJQHL.js} +2 -2
- package/dist/{contribute-NLM2BN6Z.js → contribute-V7PV5UMK.js} +3 -3
- package/dist/{countdown-QXJD6TDB.js → countdown-YONBTSJ2.js} +10 -8
- package/dist/{diff-HHG4JEDE.js → diff-GWIHGH65.js} +4 -4
- package/dist/{doctor-TWF2M3S3.js → doctor-FLIQCVFN.js} +8 -8
- package/dist/engine-info-UQNVNOA2.js +89 -0
- package/dist/{ground-control-NMYYIVCV.js → ground-control-6W2AKTKI.js} +5 -4
- package/dist/{guard-EHXF76ID.js → guard-ZZRQW3DJ.js} +107 -8
- package/dist/{hook-VP7FHRSZ.js → hook-2SX2V2T6.js} +10 -4
- package/dist/index.js +26 -22
- package/dist/{init-UOTV4ASJ.js → init-4B2IRH27.js} +11 -11
- package/dist/{install-VCHPXQV3.js → install-3JVTG35O.js} +11 -11
- package/dist/{run-R66G276Q.js → run-AYT6CRHI.js} +12 -9
- package/dist/{run-plan-24Z5K4P3.js → run-plan-5XIISG3W.js} +11 -7
- package/dist/sessions-O7MYEMCT.js +343 -0
- package/dist/{setup-global-M6LKGJHQ.js → setup-global-6JM5XTAT.js} +5 -5
- package/dist/{status-5UKVIKOI.js → status-PMAI7NH3.js} +6 -6
- package/dist/{update-VQBGEUWS.js → update-3PLY4FZA.js} +9 -9
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
INTERACTIVE_ALLOW_RULES,
|
|
2
3
|
INTERACTIVE_DENY_RULES
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6RRG3WOE.js";
|
|
4
5
|
import {
|
|
5
6
|
assertRealContained,
|
|
6
7
|
assertRealParentContained,
|
|
@@ -10,7 +11,7 @@ import {
|
|
|
10
11
|
resolveContained,
|
|
11
12
|
saveManagedHashLedger,
|
|
12
13
|
shouldPreserveCustomizedOverlay
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-5WSFO35Y.js";
|
|
14
15
|
import {
|
|
15
16
|
ensureDir,
|
|
16
17
|
fileExists
|
|
@@ -149,17 +150,18 @@ var ClaudeSettingsLedgerInvalidError = class extends Error {
|
|
|
149
150
|
path;
|
|
150
151
|
};
|
|
151
152
|
function emptyLedger() {
|
|
152
|
-
return { schemaVersion: 1, denyRowsWritten: [], hookEntriesWritten: [] };
|
|
153
|
+
return { schemaVersion: 1, denyRowsWritten: [], allowRowsWritten: [], hookEntriesWritten: [] };
|
|
153
154
|
}
|
|
154
155
|
function hookKey(r) {
|
|
155
156
|
return `${r.event}\0${r.marker}`;
|
|
156
157
|
}
|
|
157
|
-
function normalize(denyRows, hooks) {
|
|
158
|
+
function normalize(denyRows, allowRows, hooks) {
|
|
158
159
|
const seen = /* @__PURE__ */ new Map();
|
|
159
160
|
for (const h of hooks) seen.set(hookKey(h), { event: h.event, marker: h.marker });
|
|
160
161
|
return {
|
|
161
162
|
schemaVersion: 1,
|
|
162
163
|
denyRowsWritten: [...new Set(denyRows)].sort(),
|
|
164
|
+
allowRowsWritten: [...new Set(allowRows)].sort(),
|
|
163
165
|
hookEntriesWritten: [...seen.values()].sort(
|
|
164
166
|
(a, b) => a.event.localeCompare(b.event) || a.marker.localeCompare(b.marker)
|
|
165
167
|
)
|
|
@@ -178,6 +180,8 @@ function parseLedger(raw) {
|
|
|
178
180
|
if (!Array.isArray(o.denyRowsWritten) || !o.denyRowsWritten.every((r) => typeof r === "string")) {
|
|
179
181
|
return null;
|
|
180
182
|
}
|
|
183
|
+
const allowRows = o.allowRowsWritten ?? [];
|
|
184
|
+
if (!Array.isArray(allowRows) || !allowRows.every((r) => typeof r === "string")) return null;
|
|
181
185
|
if (!Array.isArray(o.hookEntriesWritten)) return null;
|
|
182
186
|
const hooks = [];
|
|
183
187
|
for (const h of o.hookEntriesWritten) {
|
|
@@ -189,7 +193,7 @@ function parseLedger(raw) {
|
|
|
189
193
|
marker: h.marker
|
|
190
194
|
});
|
|
191
195
|
}
|
|
192
|
-
return normalize(o.denyRowsWritten, hooks);
|
|
196
|
+
return normalize(o.denyRowsWritten, allowRows, hooks);
|
|
193
197
|
}
|
|
194
198
|
async function readState(root) {
|
|
195
199
|
const abs = resolveContained(root, CLAUDE_SETTINGS_LEDGER_REL);
|
|
@@ -224,6 +228,7 @@ async function saveClaudeSettingsLedger(root, additions, opts = {}) {
|
|
|
224
228
|
const base = state.kind === "ok" ? state.ledger : emptyLedger();
|
|
225
229
|
const merged = normalize(
|
|
226
230
|
[...base.denyRowsWritten, ...additions.denyRowsWritten ?? []],
|
|
231
|
+
[...base.allowRowsWritten, ...additions.allowRowsWritten ?? []],
|
|
227
232
|
[...base.hookEntriesWritten, ...additions.hookEntriesWritten ?? []]
|
|
228
233
|
);
|
|
229
234
|
await mkdir(path2.dirname(abs), { recursive: true });
|
|
@@ -300,8 +305,12 @@ function mergeSessionStartHookIntoSettings(existingRaw, opts = {}) {
|
|
|
300
305
|
};
|
|
301
306
|
}
|
|
302
307
|
}
|
|
303
|
-
const pending = { denyRows: [], hookEntries: [] };
|
|
304
|
-
const additions = {
|
|
308
|
+
const pending = { denyRows: [], allowRows: [], hookEntries: [] };
|
|
309
|
+
const additions = {
|
|
310
|
+
denyRowsWritten: [],
|
|
311
|
+
allowRowsWritten: [],
|
|
312
|
+
hookEntriesWritten: []
|
|
313
|
+
};
|
|
305
314
|
const hooks = isPlainObject(root.hooks) ? { ...root.hooks } : {};
|
|
306
315
|
const sessionStart = Array.isArray(hooks.SessionStart) ? [...hooks.SessionStart] : [];
|
|
307
316
|
const preToolUse = Array.isArray(hooks.PreToolUse) ? [...hooks.PreToolUse] : [];
|
|
@@ -342,8 +351,17 @@ function mergeSessionStartHookIntoSettings(existingRaw, opts = {}) {
|
|
|
342
351
|
(acc, next, i) => i === 0 ? next : combineStatus(acc, next),
|
|
343
352
|
"unchanged"
|
|
344
353
|
);
|
|
345
|
-
const
|
|
346
|
-
const
|
|
354
|
+
const ctx = { ledger, authorized };
|
|
355
|
+
const denyAdded = mergeKitRuleRows(root, "deny", INTERACTIVE_DENY_RULES, ctx, pending, additions);
|
|
356
|
+
const allowAdded = mergeKitRuleRows(
|
|
357
|
+
root,
|
|
358
|
+
"allow",
|
|
359
|
+
INTERACTIVE_ALLOW_RULES,
|
|
360
|
+
ctx,
|
|
361
|
+
pending,
|
|
362
|
+
additions
|
|
363
|
+
);
|
|
364
|
+
const finalStatus = (denyAdded || allowAdded) && status === "unchanged" ? "refreshed" : status;
|
|
347
365
|
return {
|
|
348
366
|
content: `${JSON.stringify(root, null, 2)}
|
|
349
367
|
`,
|
|
@@ -355,23 +373,25 @@ function mergeSessionStartHookIntoSettings(existingRaw, opts = {}) {
|
|
|
355
373
|
function combineStatus(a, b) {
|
|
356
374
|
return a === "unchanged" && b !== "unchanged" ? "refreshed" : a;
|
|
357
375
|
}
|
|
358
|
-
function
|
|
376
|
+
function mergeKitRuleRows(root, kind, rules, ctx, pending, additions) {
|
|
359
377
|
if (root.permissions !== void 0 && !isPlainObject(root.permissions)) return false;
|
|
360
378
|
const permissions = isPlainObject(root.permissions) ? { ...root.permissions } : {};
|
|
361
|
-
if (permissions
|
|
362
|
-
const
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
const missing = INTERACTIVE_DENY_RULES.filter(
|
|
368
|
-
(rule) => !deny.includes(rule) && !written.has(rule)
|
|
379
|
+
if (permissions[kind] !== void 0 && !Array.isArray(permissions[kind])) return false;
|
|
380
|
+
const list = Array.isArray(permissions[kind]) ? [...permissions[kind]] : [];
|
|
381
|
+
const pendingRows = kind === "deny" ? pending.denyRows : pending.allowRows;
|
|
382
|
+
const written = kind === "deny" ? additions.denyRowsWritten : additions.allowRowsWritten;
|
|
383
|
+
const ledgerRows = new Set(
|
|
384
|
+
(kind === "deny" ? ctx.ledger?.denyRowsWritten : ctx.ledger?.allowRowsWritten) ?? []
|
|
369
385
|
);
|
|
386
|
+
for (const rule of rules) {
|
|
387
|
+
if (list.includes(rule)) written.push(rule);
|
|
388
|
+
}
|
|
389
|
+
const missing = rules.filter((rule) => !list.includes(rule) && !ledgerRows.has(rule));
|
|
370
390
|
const toAdd = ctx.ledger === null && !ctx.authorized ? [] : missing;
|
|
371
|
-
if (ctx.ledger === null && !ctx.authorized)
|
|
391
|
+
if (ctx.ledger === null && !ctx.authorized) pendingRows.push(...missing);
|
|
372
392
|
if (toAdd.length === 0) return false;
|
|
373
|
-
|
|
374
|
-
permissions
|
|
393
|
+
written.push(...toAdd);
|
|
394
|
+
permissions[kind] = [...list, ...toAdd];
|
|
375
395
|
root.permissions = permissions;
|
|
376
396
|
return true;
|
|
377
397
|
}
|
|
@@ -425,7 +445,7 @@ async function writeClaudeSessionStartHook(rootDir, opts = {}) {
|
|
|
425
445
|
relativePath: CLAUDE_SETTINGS_REL,
|
|
426
446
|
status: merged.status
|
|
427
447
|
};
|
|
428
|
-
if (merged.pending && (merged.pending.denyRows.length || merged.pending.hookEntries.length)) {
|
|
448
|
+
if (merged.pending && (merged.pending.denyRows.length || merged.pending.allowRows.length || merged.pending.hookEntries.length)) {
|
|
429
449
|
result.pending = merged.pending;
|
|
430
450
|
}
|
|
431
451
|
if (authorized && merged.ledgerAdditions && ledgerGrows(ledger, merged.ledgerAdditions)) {
|
|
@@ -437,8 +457,9 @@ async function writeClaudeSessionStartHook(rootDir, opts = {}) {
|
|
|
437
457
|
function ledgerGrows(ledger, add) {
|
|
438
458
|
if (ledger === null) return true;
|
|
439
459
|
const rows = new Set(ledger.denyRowsWritten);
|
|
460
|
+
const allowRows = new Set(ledger.allowRowsWritten);
|
|
440
461
|
const hooks = new Set(ledger.hookEntriesWritten.map((h) => `${h.event}\0${h.marker}`));
|
|
441
|
-
return add.denyRowsWritten.some((r) => !rows.has(r)) || add.hookEntriesWritten.some((h) => !hooks.has(`${h.event}\0${h.marker}`));
|
|
462
|
+
return add.denyRowsWritten.some((r) => !rows.has(r)) || add.allowRowsWritten.some((r) => !allowRows.has(r)) || add.hookEntriesWritten.some((h) => !hooks.has(`${h.event}\0${h.marker}`));
|
|
442
463
|
}
|
|
443
464
|
async function planClaudeSettingsDrift(rootDir) {
|
|
444
465
|
const abs = resolveContained(rootDir, CLAUDE_SETTINGS_REL);
|
|
@@ -477,17 +498,23 @@ async function planClaudeSettingsDrift(rootDir) {
|
|
|
477
498
|
const merged = mergeSessionStartHookIntoSettings(raw, { ledger, authorized: false });
|
|
478
499
|
if (merged.content === null) return null;
|
|
479
500
|
const next = JSON.parse(merged.content);
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
501
|
+
const rowsOf = (r, kind) => {
|
|
502
|
+
const list = isPlainObject(r.permissions) ? r.permissions[kind] : void 0;
|
|
503
|
+
return Array.isArray(list) ? list.filter((x) => typeof x === "string") : [];
|
|
504
|
+
};
|
|
505
|
+
const hadDeny = new Set(rowsOf(existing, "deny"));
|
|
506
|
+
const hadAllow = new Set(rowsOf(existing, "allow"));
|
|
507
|
+
const denyRows = rowsOf(next, "deny").filter((r) => !hadDeny.has(r));
|
|
508
|
+
const allowRows = rowsOf(next, "allow").filter((r) => !hadAllow.has(r));
|
|
483
509
|
const ambiguousDenyRows = merged.pending?.denyRows ?? [];
|
|
510
|
+
const ambiguousAllowRows = merged.pending?.allowRows ?? [];
|
|
484
511
|
const missingEntries = kitEntries.filter((e) => !present.includes(e));
|
|
485
512
|
const ledgerHas = (e) => Boolean(ledger?.hookEntriesWritten.some((h) => h.event === e.event && h.marker === e.marker));
|
|
486
513
|
const hookEntries = missingEntries.filter((e) => !ledgerHas(e));
|
|
487
|
-
if (denyRows.length === 0 && ambiguousDenyRows.length === 0 && hookEntries.length === 0) {
|
|
514
|
+
if (denyRows.length === 0 && ambiguousDenyRows.length === 0 && allowRows.length === 0 && ambiguousAllowRows.length === 0 && hookEntries.length === 0) {
|
|
488
515
|
return null;
|
|
489
516
|
}
|
|
490
|
-
return { denyRows, ambiguousDenyRows, hookEntries };
|
|
517
|
+
return { denyRows, ambiguousDenyRows, allowRows, ambiguousAllowRows, hookEntries };
|
|
491
518
|
}
|
|
492
519
|
function formatClaudeSettingsDrift(report, opts) {
|
|
493
520
|
const rows = [...report.denyRows, ...report.ambiguousDenyRows];
|
|
@@ -502,6 +529,15 @@ function formatClaudeSettingsDrift(report, opts) {
|
|
|
502
529
|
);
|
|
503
530
|
}
|
|
504
531
|
}
|
|
532
|
+
const allowRows = [...report.allowRows, ...report.ambiguousAllowRows];
|
|
533
|
+
if (allowRows.length > 0) {
|
|
534
|
+
lines.push("Add to permissions.allow:", JSON.stringify(allowRows, null, 2));
|
|
535
|
+
if (report.ambiguousAllowRows.length > 0) {
|
|
536
|
+
lines.push(
|
|
537
|
+
`(${report.ambiguousAllowRows.length} row(s) ambiguous: no ${CLAUDE_SETTINGS_LEDGER_REL} ledger, so a deliberate deletion cannot be told apart.)`
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
505
541
|
if (report.hookEntries.length > 0) {
|
|
506
542
|
lines.push("Missing hook entries (add by hand or use the command below):");
|
|
507
543
|
for (const e of report.hookEntries) lines.push(` ${e.event}: ${e.marker}`);
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DRIVER_PROTOCOL_VERSION,
|
|
3
|
+
DriverAgentSink,
|
|
4
|
+
createDriverAnswerReader,
|
|
5
|
+
createDriverEmitter
|
|
6
|
+
} from "./chunk-R6WH5P7R.js";
|
|
1
7
|
import {
|
|
2
8
|
classifyGateExit,
|
|
3
9
|
landGateExit
|
|
4
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-GIZNM73K.js";
|
|
5
11
|
import {
|
|
6
12
|
InputLine,
|
|
7
13
|
ScrollRegion,
|
|
@@ -14,16 +20,17 @@ import {
|
|
|
14
20
|
parsePlanFrontmatter
|
|
15
21
|
} from "./chunk-L5V3W3DY.js";
|
|
16
22
|
import {
|
|
17
|
-
LineSplitter,
|
|
18
23
|
RedactingStreamBuffer,
|
|
19
24
|
claudeRedactions,
|
|
20
|
-
formatHitlGateLine,
|
|
21
|
-
formatHitlSummary,
|
|
22
|
-
operatorQuitStop,
|
|
23
25
|
parseStreamLine,
|
|
24
26
|
redactSecrets,
|
|
25
27
|
renderStreamEvent
|
|
26
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-2TCRKQHD.js";
|
|
29
|
+
import {
|
|
30
|
+
LineSplitter,
|
|
31
|
+
formatHitlSummary,
|
|
32
|
+
operatorQuitStop
|
|
33
|
+
} from "./chunk-MTLQN57O.js";
|
|
27
34
|
import {
|
|
28
35
|
TtySpinner,
|
|
29
36
|
shouldUseVisualMotion,
|
|
@@ -491,218 +498,6 @@ async function withLiveTui(opts, run) {
|
|
|
491
498
|
}
|
|
492
499
|
}
|
|
493
500
|
|
|
494
|
-
// src/plan-loop/driver-events.ts
|
|
495
|
-
import { createInterface } from "readline";
|
|
496
|
-
import { StringDecoder as StringDecoder2 } from "string_decoder";
|
|
497
|
-
var DRIVER_PROTOCOL_MAJOR = 1;
|
|
498
|
-
var DRIVER_PROTOCOL_VERSION = "1.1.0";
|
|
499
|
-
var DRIVER_EVENTS_FORMATS = ["ndjson"];
|
|
500
|
-
var INBOUND_MAX_CHARS = 64 * 1024;
|
|
501
|
-
var AGENT_PENDING_MAX_CHARS = 4 * 1024 * 1024;
|
|
502
|
-
function formatDriverEvent(event, now = () => /* @__PURE__ */ new Date()) {
|
|
503
|
-
return `${JSON.stringify({ v: DRIVER_PROTOCOL_MAJOR, ts: now().toISOString(), ...event })}
|
|
504
|
-
`;
|
|
505
|
-
}
|
|
506
|
-
function createDriverEmitter(write = (text) => {
|
|
507
|
-
process.stdout.write(text);
|
|
508
|
-
}, now) {
|
|
509
|
-
return {
|
|
510
|
-
emit(event) {
|
|
511
|
-
try {
|
|
512
|
-
write(formatDriverEvent(event, now));
|
|
513
|
-
} catch {
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
function parseDriverInbound(line) {
|
|
519
|
-
const text = line.trim();
|
|
520
|
-
if (text.length > INBOUND_MAX_CHARS) return { ok: false, error: "line too long" };
|
|
521
|
-
let value;
|
|
522
|
-
try {
|
|
523
|
-
value = JSON.parse(text);
|
|
524
|
-
} catch {
|
|
525
|
-
return { ok: false, error: "not JSON" };
|
|
526
|
-
}
|
|
527
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
528
|
-
return { ok: false, error: "not a JSON object" };
|
|
529
|
-
}
|
|
530
|
-
const msg = value;
|
|
531
|
-
if (msg.v !== void 0 && msg.v !== DRIVER_PROTOCOL_MAJOR) {
|
|
532
|
-
return { ok: false, error: `unsupported protocol v${String(msg.v)}` };
|
|
533
|
-
}
|
|
534
|
-
if (msg.type === "stop") {
|
|
535
|
-
return {
|
|
536
|
-
ok: true,
|
|
537
|
-
message: { type: "stop", ...typeof msg.reason === "string" ? { reason: msg.reason } : {} }
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
if (msg.type !== "hitl_reply")
|
|
541
|
-
return { ok: false, error: `unknown type ${JSON.stringify(msg.type)}` };
|
|
542
|
-
if (typeof msg.askId !== "string" || !/^[a-z0-9-]+$/.test(msg.askId)) {
|
|
543
|
-
return { ok: false, error: "hitl_reply.askId must be a kebab-case string" };
|
|
544
|
-
}
|
|
545
|
-
if (typeof msg.reply === "number") {
|
|
546
|
-
if (!Number.isInteger(msg.reply) || msg.reply < 1) {
|
|
547
|
-
return { ok: false, error: "hitl_reply.reply number must be a positive integer" };
|
|
548
|
-
}
|
|
549
|
-
return { ok: true, message: { type: "hitl_reply", askId: msg.askId, reply: msg.reply } };
|
|
550
|
-
}
|
|
551
|
-
if (typeof msg.reply === "string" && msg.reply.trim() && !/[\r\n]/.test(msg.reply)) {
|
|
552
|
-
return { ok: true, message: { type: "hitl_reply", askId: msg.askId, reply: msg.reply.trim() } };
|
|
553
|
-
}
|
|
554
|
-
return { ok: false, error: "hitl_reply.reply must be a number or a one-line non-empty string" };
|
|
555
|
-
}
|
|
556
|
-
function inboundToRawAnswer(gate, parsed) {
|
|
557
|
-
if (!parsed.ok) return { kind: "stop", cause: "protocol error", detail: parsed.error };
|
|
558
|
-
const message = parsed.message;
|
|
559
|
-
if (message.type === "stop") return { kind: "stop", cause: "driver stop" };
|
|
560
|
-
if (message.askId !== gate.askId) {
|
|
561
|
-
return {
|
|
562
|
-
kind: "stop",
|
|
563
|
-
cause: "protocol error",
|
|
564
|
-
detail: `reply for ${message.askId} while gate ${gate.askId} is open`
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
return { kind: "line", text: String(message.reply) };
|
|
568
|
-
}
|
|
569
|
-
function createDriverAnswerReader(opts) {
|
|
570
|
-
const input = opts.input ?? process.stdin;
|
|
571
|
-
const queue = [];
|
|
572
|
-
let ended = false;
|
|
573
|
-
let waiter = null;
|
|
574
|
-
let rl = null;
|
|
575
|
-
const ensure = () => {
|
|
576
|
-
if (rl) return;
|
|
577
|
-
rl = createInterface({ input, terminal: false, crlfDelay: Number.POSITIVE_INFINITY });
|
|
578
|
-
rl.on("line", (line) => {
|
|
579
|
-
if (!line.trim()) return;
|
|
580
|
-
if (waiter) {
|
|
581
|
-
const w = waiter;
|
|
582
|
-
waiter = null;
|
|
583
|
-
w(line);
|
|
584
|
-
} else queue.push(line);
|
|
585
|
-
});
|
|
586
|
-
rl.on("close", () => {
|
|
587
|
-
ended = true;
|
|
588
|
-
if (waiter) {
|
|
589
|
-
const w = waiter;
|
|
590
|
-
waiter = null;
|
|
591
|
-
w(null);
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
};
|
|
595
|
-
const nextLine = (signal) => new Promise((resolve) => {
|
|
596
|
-
const queued = queue.shift();
|
|
597
|
-
if (queued !== void 0) {
|
|
598
|
-
resolve(queued);
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
if (ended) {
|
|
602
|
-
resolve(null);
|
|
603
|
-
return;
|
|
604
|
-
}
|
|
605
|
-
const onAbort = () => {
|
|
606
|
-
if (waiter === settle) waiter = null;
|
|
607
|
-
resolve(null);
|
|
608
|
-
};
|
|
609
|
-
const settle = (line) => {
|
|
610
|
-
signal?.removeEventListener("abort", onAbort);
|
|
611
|
-
resolve(line);
|
|
612
|
-
};
|
|
613
|
-
if (signal?.aborted) {
|
|
614
|
-
resolve(null);
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
618
|
-
waiter = settle;
|
|
619
|
-
});
|
|
620
|
-
return {
|
|
621
|
-
read: async (gate, readOpts) => {
|
|
622
|
-
ensure();
|
|
623
|
-
opts.emitter.emit({
|
|
624
|
-
type: "hitl_gate",
|
|
625
|
-
tick: opts.tick(),
|
|
626
|
-
askId: gate.askId,
|
|
627
|
-
labels: [...gate.labels],
|
|
628
|
-
detection: gate.detection,
|
|
629
|
-
line: formatHitlGateLine(gate)
|
|
630
|
-
});
|
|
631
|
-
const line = await nextLine(readOpts.signal);
|
|
632
|
-
if (line === null) return { kind: "eof" };
|
|
633
|
-
return inboundToRawAnswer(gate, parseDriverInbound(line));
|
|
634
|
-
},
|
|
635
|
-
close: () => {
|
|
636
|
-
const r = rl;
|
|
637
|
-
rl = null;
|
|
638
|
-
r?.close();
|
|
639
|
-
if (typeof input.pause === "function") {
|
|
640
|
-
input.pause();
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
var DriverAgentSink = class {
|
|
646
|
-
constructor(emitter, tick) {
|
|
647
|
-
this.emitter = emitter;
|
|
648
|
-
this.tick = tick;
|
|
649
|
-
}
|
|
650
|
-
emitter;
|
|
651
|
-
tick;
|
|
652
|
-
pending = "";
|
|
653
|
-
dropped = false;
|
|
654
|
-
decoder = new StringDecoder2("utf8");
|
|
655
|
-
feed(chunk) {
|
|
656
|
-
try {
|
|
657
|
-
const text = typeof chunk === "string" ? chunk : this.decoder.write(chunk);
|
|
658
|
-
if (!text) return;
|
|
659
|
-
const lines = (this.pending + text).split("\n");
|
|
660
|
-
this.pending = lines.pop() ?? "";
|
|
661
|
-
for (const line of lines) {
|
|
662
|
-
if (this.dropped) {
|
|
663
|
-
this.dropped = false;
|
|
664
|
-
continue;
|
|
665
|
-
}
|
|
666
|
-
this.take(line);
|
|
667
|
-
}
|
|
668
|
-
if (this.pending.length > AGENT_PENDING_MAX_CHARS) {
|
|
669
|
-
this.pending = "";
|
|
670
|
-
this.dropped = true;
|
|
671
|
-
}
|
|
672
|
-
} catch {
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
end() {
|
|
676
|
-
try {
|
|
677
|
-
const rest = this.pending + this.decoder.end();
|
|
678
|
-
this.pending = "";
|
|
679
|
-
if (rest && !this.dropped) this.take(rest);
|
|
680
|
-
this.dropped = false;
|
|
681
|
-
} catch {
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
take(raw) {
|
|
685
|
-
const line = raw.replace(/\r$/, "");
|
|
686
|
-
if (!line.trim()) return;
|
|
687
|
-
const trimmed = line.trim();
|
|
688
|
-
if (trimmed.startsWith("{")) {
|
|
689
|
-
try {
|
|
690
|
-
const event = JSON.parse(trimmed);
|
|
691
|
-
if (typeof event === "object" && event !== null && !Array.isArray(event)) {
|
|
692
|
-
this.emitter.emit({
|
|
693
|
-
type: "agent_event",
|
|
694
|
-
tick: this.tick,
|
|
695
|
-
event
|
|
696
|
-
});
|
|
697
|
-
return;
|
|
698
|
-
}
|
|
699
|
-
} catch {
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
this.emitter.emit({ type: "agent_text", tick: this.tick, text: line });
|
|
703
|
-
}
|
|
704
|
-
};
|
|
705
|
-
|
|
706
501
|
// src/plan-loop/run-loop.ts
|
|
707
502
|
import { readFile as readFile4, rm, unlink } from "fs/promises";
|
|
708
503
|
import path5 from "path";
|
|
@@ -1525,6 +1320,5 @@ async function runPlanLoop(opts) {
|
|
|
1525
1320
|
export {
|
|
1526
1321
|
shouldUseLiveTui,
|
|
1527
1322
|
withLiveTui,
|
|
1528
|
-
DRIVER_EVENTS_FORMATS,
|
|
1529
1323
|
runPlanLoop
|
|
1530
1324
|
};
|