neurastream 0.3.17 → 0.3.20
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 +88 -490
- package/package.json +1 -1
- package/src/adapters/omp/index.ts +66 -54
- package/src/adapters/omp/launch.ts +4 -6
- package/src/cli/claim.ts +1 -3
- package/src/cli/dispatch.ts +25 -21
- package/src/cli/guard.ts +0 -3
- package/src/cli/incident.ts +2 -2
- package/src/cli/metrics.ts +1 -1
- package/src/cli/recall.ts +3 -6
- package/src/cli/results-build.ts +1 -3
- package/src/cli/workspace.ts +0 -3
- package/src/core/autonomy.ts +24 -21
- package/src/core/guards.ts +192 -195
- package/src/core/incidents.ts +13 -12
- package/src/core/main-start.ts +1 -1
- package/src/core/mr-sweep.ts +4 -2
- package/src/core/notify.ts +15 -15
- package/src/core/owner-log.ts +19 -17
- package/src/core/owner-topics.ts +36 -35
- package/src/core/owner-ui.ts +54 -51
- package/src/core/pages.ts +3 -4
- package/src/core/plan-approval.ts +18 -18
- package/src/core/queue/lib.ts +89 -105
- package/src/core/queue-cancel.ts +20 -10
- package/src/core/queue-check.ts +5 -7
- package/src/core/queue-close.ts +8 -8
- package/src/core/queue-finished.ts +9 -10
- package/src/core/queue-migrate.ts +1 -3
- package/src/core/queue-trim.ts +2 -4
- package/src/core/results.ts +0 -2
- package/src/core/rollover.ts +2 -3
- package/src/core/team-client.ts +5 -4
- package/src/core/watch.ts +3 -2
- package/src/core/queue/env.ts +0 -14
package/package.json
CHANGED
|
@@ -42,7 +42,6 @@ import { inboxPath } from "../../core/owner-ui.ts";
|
|
|
42
42
|
import { realTailscale } from "../../core/tailscale.ts";
|
|
43
43
|
import { briefPaths } from "../../core/brief-lint.ts";
|
|
44
44
|
import { actionsRules, ownedRepoOf, suspiciousActions, unreportedFindings } from "../../core/trace-actions.ts";
|
|
45
|
-
import { applyQueueEnv } from "../../core/queue/env.ts";
|
|
46
45
|
import { mainDetectors, mainStartText } from "../../core/main-start.ts";
|
|
47
46
|
|
|
48
47
|
import { buildHandoff, holdsBlock, notePath, noteRequest, OWNER_AWAY, ownerText, relaunchPath, rolloverState, spawnRefusal, unansweredOwnerMessages, type RolloverState } from "../../core/rollover.ts";
|
|
@@ -261,20 +260,31 @@ export function autoClose(cfg: Config): string[] {
|
|
|
261
260
|
try {
|
|
262
261
|
// P4: landed open plans auto-close too (q.autoCloseCandidate) — the child runs queue-close
|
|
263
262
|
// --auto and writes "Status: complete" itself when the done check passes.
|
|
264
|
-
plans = q.activePlans().filter(p => (p.status === "complete" || p.status === "cancelled" || q.autoCloseCandidate(p)) && !p.errors.length);
|
|
263
|
+
plans = q.activePlans(cfg.paths).filter(p => (p.status === "complete" || p.status === "cancelled" || q.autoCloseCandidate(p)) && !p.errors.length);
|
|
265
264
|
} catch {
|
|
266
265
|
return started;
|
|
267
266
|
}
|
|
268
267
|
try {
|
|
269
|
-
mkdirSync(
|
|
268
|
+
mkdirSync(cfg.paths.queue_state, { recursive: true });
|
|
270
269
|
} catch {}
|
|
271
270
|
for (const p of plans) {
|
|
272
271
|
try {
|
|
273
|
-
const outFile = q.closeLog(p.file);
|
|
272
|
+
const outFile = q.closeLog(p.file, cfg.paths);
|
|
274
273
|
appendFileSync(outFile, `--- ${new Date().toISOString()} auto-close attempt\n`);
|
|
275
274
|
const out = openSync(outFile, "a");
|
|
276
275
|
const [bin, args] = closeChildArgs(p.file, p.status === "open");
|
|
277
|
-
const
|
|
276
|
+
const childEnv: NodeJS.ProcessEnv = {
|
|
277
|
+
...process.env,
|
|
278
|
+
HOME: cfg.paths.home,
|
|
279
|
+
QUEUE_AGENT: cfg.paths.agent_dir,
|
|
280
|
+
QUEUE_INDEX: cfg.paths.queue_index,
|
|
281
|
+
QUEUE_BLOCKERS: cfg.paths.blockers,
|
|
282
|
+
QUEUE_STATE: cfg.paths.queue_state,
|
|
283
|
+
QUEUE_SUBAGENTS: cfg.paths.subagents,
|
|
284
|
+
QUEUE_CANCELLED: cfg.paths.cancelled,
|
|
285
|
+
QUEUE_UNLOCK: cfg.paths.unlock,
|
|
286
|
+
};
|
|
287
|
+
const child = spawn(bin, args, { detached: true, stdio: ["ignore", out, out], env: childEnv });
|
|
278
288
|
child.unref();
|
|
279
289
|
closeSync(out);
|
|
280
290
|
started.push(p.file);
|
|
@@ -299,10 +309,10 @@ function ledgerText(cfg: Config): string {
|
|
|
299
309
|
|
|
300
310
|
// Write-time checks (plan 20261028_1228): the text of each file a call names that a configured linter
|
|
301
311
|
// covers, read before the call runs; null when the file does not exist yet.
|
|
302
|
-
function writeCheckSnapshot(tool: string, input: Record<string, unknown>, cwd: string, wc: WriteCheckConfig): Map<string, string | null> {
|
|
312
|
+
function writeCheckSnapshot(tool: string, input: Record<string, unknown>, cwd: string, wc: WriteCheckConfig, cfg: Config): Map<string, string | null> {
|
|
303
313
|
const exts = wc.linters.flatMap((l) => l.ext);
|
|
304
314
|
const snap = new Map<string, string | null>();
|
|
305
|
-
for (const file of q.writeTargets(tool, input, cwd)) {
|
|
315
|
+
for (const file of q.writeTargets(tool, input, cwd, cfg.paths)) {
|
|
306
316
|
if (!exts.includes(extname(file))) continue;
|
|
307
317
|
try {
|
|
308
318
|
snap.set(file, readFileSync(file, "utf8"));
|
|
@@ -318,8 +328,8 @@ function writeCheckSnapshot(tool: string, input: Record<string, unknown>, cwd: s
|
|
|
318
328
|
function snapshotPlans(tool: string, input: Record<string, unknown>, cwd: string, snap: Map<string, string>, main: boolean, plannerPlan: string | null, cfg: Config): void {
|
|
319
329
|
if (tool !== "write" && tool !== "edit") return;
|
|
320
330
|
const delegated = currentPlanner(cfg) === "delegated";
|
|
321
|
-
const plans = q.activePlans();
|
|
322
|
-
for (const p of q.writeTargets(tool, input, cwd)) {
|
|
331
|
+
const plans = q.activePlans(cfg.paths);
|
|
332
|
+
for (const p of q.writeTargets(tool, input, cwd, cfg.paths)) {
|
|
323
333
|
if (snap.has(p)) continue;
|
|
324
334
|
if (main) {
|
|
325
335
|
// Main's own plan text is checked too; a plan that did not exist yet snapshots as "".
|
|
@@ -331,7 +341,7 @@ function snapshotPlans(tool: string, input: Record<string, unknown>, cwd: string
|
|
|
331
341
|
}
|
|
332
342
|
continue;
|
|
333
343
|
}
|
|
334
|
-
if (!q.isOrchestrationPath(p, plans) || !q.planAt(p, plans)) {
|
|
344
|
+
if (!q.isOrchestrationPath(p, plans, cfg.paths.queue_index) || !q.planAt(p, plans)) {
|
|
335
345
|
// planner mode P2 (b): the brief's named plan snapshots before its create/edit so
|
|
336
346
|
// checkPlanEdit judges it (Planner header, Main-only lines) — a new plan file is not
|
|
337
347
|
// an indexed path yet, and every other plan write is refused pre-tool while delegated.
|
|
@@ -469,8 +479,8 @@ function spawnTopics(cfg: Config, ctx: unknown, args: string[]): void {
|
|
|
469
479
|
}
|
|
470
480
|
let out: number | undefined;
|
|
471
481
|
try {
|
|
472
|
-
mkdirSync(ownerLogDir(), { recursive: true, mode: 0o700 });
|
|
473
|
-
out = openSync(topicsLogFile(), "a", 0o600);
|
|
482
|
+
mkdirSync(ownerLogDir(cfg.paths), { recursive: true, mode: 0o700 });
|
|
483
|
+
out = openSync(topicsLogFile(cfg.paths), "a", 0o600);
|
|
474
484
|
const child = spawn("nice", ["-n", "19", "bun", join(import.meta.dir, "../../cli/main.ts"), ...args], { detached: true, stdio: ["ignore", out, out], env });
|
|
475
485
|
child.on("error", err => adapterLog(cfg, `OWNER-TOPICS: could not start: ${err.message}`));
|
|
476
486
|
child.unref();
|
|
@@ -510,7 +520,7 @@ export const OWNER_INBOX_POLL_MS = 15_000;
|
|
|
510
520
|
export const CLAIM_BEAT_MS = 60_000;
|
|
511
521
|
|
|
512
522
|
/** The delivered cursor: how many owner-inbox rows this Main's session has consumed (P5: one file per Main, under its mainStateDir). */
|
|
513
|
-
export function ownerInboxCursorPath(cfg
|
|
523
|
+
export function ownerInboxCursorPath(cfg: Config | Pick<q.QueuePaths, "queue_state">): string {
|
|
514
524
|
return `${mainStateDir(cfg)}/inbox-cursor`;
|
|
515
525
|
}
|
|
516
526
|
|
|
@@ -535,7 +545,7 @@ function writeOwnerInboxCursor(cfg: Config, n: number): void {
|
|
|
535
545
|
|
|
536
546
|
/** The user message one inbox record becomes, or null when the record is not one Main can act on.
|
|
537
547
|
* Records without `kind` are page answers (the original shape). */
|
|
538
|
-
export function ownerInboxMessage(rec: Record<string, unknown>): string | ({ type: "text"; text: string } | { type: "image"; data: string; mimeType: string })[] | null {
|
|
548
|
+
export function ownerInboxMessage(rec: Record<string, unknown>, queuePaths?: Pick<q.QueuePaths, "queue_state">): string | ({ type: "text"; text: string } | { type: "image"; data: string; mimeType: string })[] | null {
|
|
539
549
|
const kind = rec.kind === undefined ? "answer" : asString(rec.kind);
|
|
540
550
|
const num = (v: unknown): number | null => (typeof v === "number" && Number.isFinite(v) ? v : null);
|
|
541
551
|
switch (kind) {
|
|
@@ -572,7 +582,8 @@ export function ownerInboxMessage(rec: Record<string, unknown>): string | ({ typ
|
|
|
572
582
|
const id = asString(rec.id);
|
|
573
583
|
if (ts === null || !/^[0-9]+-[0-9a-f]{6}$/.test(id)) return null;
|
|
574
584
|
const at = strftime(ts, "%H:%M");
|
|
575
|
-
|
|
585
|
+
if (!queuePaths) return null;
|
|
586
|
+
const dir = join(queuePaths.queue_state, "owner-messages", id);
|
|
576
587
|
let message: Record<string, unknown>;
|
|
577
588
|
try {
|
|
578
589
|
message = JSON.parse(readFileSync(join(dir, "message.json"), "utf8")) as Record<string, unknown>;
|
|
@@ -639,7 +650,7 @@ export function pendingInboxRecords(text: string, cursor: number): { records: Re
|
|
|
639
650
|
export function deliverOwnerInbox(pi: ExtensionHost, cfg: Config): void {
|
|
640
651
|
let text: string;
|
|
641
652
|
try {
|
|
642
|
-
text = readFileSync(inboxPath(), "utf8");
|
|
653
|
+
text = readFileSync(inboxPath(cfg.paths), "utf8");
|
|
643
654
|
} catch {
|
|
644
655
|
return; // no inbox yet: nothing to deliver
|
|
645
656
|
}
|
|
@@ -650,7 +661,7 @@ export function deliverOwnerInbox(pi: ExtensionHost, cfg: Config): void {
|
|
|
650
661
|
for (const rec of records) {
|
|
651
662
|
// P5: a row addressed to another Main (`to` set and not this Main's id) is consumed but not delivered here.
|
|
652
663
|
if (typeof rec.to === "string" && rec.to !== "" && rec.to !== mainId()) continue;
|
|
653
|
-
const msg = ownerInboxMessage(rec);
|
|
664
|
+
const msg = ownerInboxMessage(rec, cfg.paths);
|
|
654
665
|
if (msg === null) continue;
|
|
655
666
|
pi.sendUserMessage(msg);
|
|
656
667
|
delivered++;
|
|
@@ -709,8 +720,6 @@ function spawnLimitProbeChild(cfg: Config): void {
|
|
|
709
720
|
export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig: () => Config = () => initial): void {
|
|
710
721
|
// Guarded handlers take `cfg = freshConfig()` first, so an edited config.yml reaches the next call (P4e).
|
|
711
722
|
let cfg = initial;
|
|
712
|
-
// The queue library resolves its paths from env snapshots; point them at this config first.
|
|
713
|
-
applyQueueEnv(cfg);
|
|
714
723
|
// P2 d: the first seam — a mode fact another writer left behind is reverted before any handler runs.
|
|
715
724
|
cfg = freshPlannerConfig(freshConfig);
|
|
716
725
|
// P5: seed the per-Main inbox floor once — a Main that has never delivered starts past rows
|
|
@@ -721,12 +730,12 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
721
730
|
mkdirSync(mainStateDir(cfg), { recursive: true });
|
|
722
731
|
if (mainId() === "main") {
|
|
723
732
|
try {
|
|
724
|
-
renameSync(`${
|
|
733
|
+
renameSync(`${cfg.paths.queue_state}/owner-inbox.cursor`, ownerInboxCursorPath(cfg));
|
|
725
734
|
} catch {}
|
|
726
735
|
}
|
|
727
736
|
if (!existsSync(ownerInboxCursorPath(cfg))) {
|
|
728
737
|
try {
|
|
729
|
-
inboxFloor = pendingInboxRecords(readFileSync(inboxPath(), "utf8"), 0).next;
|
|
738
|
+
inboxFloor = pendingInboxRecords(readFileSync(inboxPath(cfg.paths), "utf8"), 0).next;
|
|
730
739
|
} catch {
|
|
731
740
|
inboxFloor = 0;
|
|
732
741
|
}
|
|
@@ -786,7 +795,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
786
795
|
adapterLog(cfg, `RECALL-LOG record failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
787
796
|
}
|
|
788
797
|
try {
|
|
789
|
-
appendOwnerAnswer(reply.text);
|
|
798
|
+
appendOwnerAnswer(reply.text, cfg.paths);
|
|
790
799
|
} catch (err) {
|
|
791
800
|
adapterLog(cfg, `OWNER-ANSWER record failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
792
801
|
}
|
|
@@ -901,9 +910,9 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
901
910
|
// source the owner page lists). Keys are `plan file|waiting line`, remembered in
|
|
902
911
|
// <queue_state>/notify-waiting.json; a key whose line is gone is dropped, so the same question
|
|
903
912
|
// asked again later posts again. No waiting plans: no decision, no log line.
|
|
904
|
-
const waitingKeysFile = join(cfg.paths.queue_state, "notify-waiting.json");
|
|
905
913
|
const notifyWaitingPlans = (): void => {
|
|
906
|
-
const
|
|
914
|
+
const waitingKeysFile = join(cfg.paths.queue_state, "notify-waiting.json");
|
|
915
|
+
const waiting = q.activePlans(cfg.paths).filter(p => p.waiting && p.status === "open" && p.waitingLine);
|
|
907
916
|
let stored: string[] = [];
|
|
908
917
|
try {
|
|
909
918
|
const parsed: unknown = JSON.parse(readFileSync(waitingKeysFile, "utf8"));
|
|
@@ -1038,9 +1047,9 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1038
1047
|
};
|
|
1039
1048
|
add(cwd);
|
|
1040
1049
|
if (cfg.guards.read_tools.includes(tool) && typeof input.path === "string") add(resolve(cwd, q.expandHome(input.path)));
|
|
1041
|
-
for (const p of q.writeTargets(tool, input, cwd)) add(p);
|
|
1050
|
+
for (const p of q.writeTargets(tool, input, cwd, cfg.paths)) add(p);
|
|
1042
1051
|
if (tool === "task") {
|
|
1043
|
-
const plans = q.readIndex();
|
|
1052
|
+
const plans = q.readIndex(cfg.paths.queue_index);
|
|
1044
1053
|
for (const t of Array.isArray(input.tasks) ? input.tasks : []) {
|
|
1045
1054
|
const plan = plans.find(file => String(asRecord(t).task ?? "").includes(file));
|
|
1046
1055
|
if (plan) add(plan);
|
|
@@ -1057,7 +1066,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1057
1066
|
if (c.kind !== "sub") return undefined;
|
|
1058
1067
|
// A subagent's first turn is the only one carrying its brief, and the plan the brief
|
|
1059
1068
|
// names is the repo whose rules it needs — the same index match the plan gate makes.
|
|
1060
|
-
const plans = q.readIndex();
|
|
1069
|
+
const plans = q.readIndex(cfg.paths.queue_index);
|
|
1061
1070
|
const content = unhanded(asString(c.id) || "sub", plans.find(file => prompt.includes(file)) ?? null);
|
|
1062
1071
|
return content ? { message: { customType: "main-guard.rules", content, display: false } } : undefined;
|
|
1063
1072
|
}
|
|
@@ -1099,8 +1108,8 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1099
1108
|
cfg = freshPlannerConfig(freshConfig);
|
|
1100
1109
|
const agent = asString(asRecord(event).agent);
|
|
1101
1110
|
const kind = asString(asRecord(event).invocationKind);
|
|
1102
|
-
if (!q.allowedAgents().has(agent))
|
|
1103
|
-
return { block: true, reason: `main-guard: agent "${agent}" is not in "## Allowed" of ${
|
|
1111
|
+
if (!q.allowedAgents(cfg.paths.subagents).has(agent))
|
|
1112
|
+
return { block: true, reason: `main-guard: agent "${agent}" is not in "## Allowed" of ${cfg.paths.subagents}.` };
|
|
1104
1113
|
if (kind !== "task")
|
|
1105
1114
|
return { block: true, reason: "main-guard: spawn implementers with the task tool (the plan gate checks its brief)." };
|
|
1106
1115
|
return undefined;
|
|
@@ -1124,7 +1133,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1124
1133
|
const cwd = c.cwd ?? process.cwd();
|
|
1125
1134
|
// planner mode P2 (plan 20261102_1515): the plan a sub's approved spawn bound to it (the
|
|
1126
1135
|
// brief's `Planner role for <plan path>` line) — the gates check it against plan-path writes.
|
|
1127
|
-
const plannerPlan = isSub ? plannerSpawnPlan(id) : null;
|
|
1136
|
+
const plannerPlan = isSub ? plannerSpawnPlan(id, cfg.paths) : null;
|
|
1128
1137
|
const snap = new Map<string, string>();
|
|
1129
1138
|
snapshotPlans(tool, input, cwd, snap, !isSub, plannerPlan, cfg);
|
|
1130
1139
|
// Drain (src/core/rollover.ts): while a rollover is pending no new subagent starts; the
|
|
@@ -1168,7 +1177,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1168
1177
|
if (snap.size) pending.set(asString(e.toolCallId), snap);
|
|
1169
1178
|
const wc = cfg.write_check;
|
|
1170
1179
|
if (wc.enabled && (wc.applies_to === "all" || isSub)) {
|
|
1171
|
-
const ws = writeCheckSnapshot(tool, input, cwd, wc);
|
|
1180
|
+
const ws = writeCheckSnapshot(tool, input, cwd, wc, cfg);
|
|
1172
1181
|
if (ws.size) pendingWrite.set(asString(e.toolCallId), ws);
|
|
1173
1182
|
}
|
|
1174
1183
|
// An allowed Main call inside a repo queues that repo's rules for the next prompt (P3).
|
|
@@ -1182,7 +1191,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1182
1191
|
const trimProgress = (file: string): string | undefined => {
|
|
1183
1192
|
const t = q.trimPlanProgress(file, cfg.queue.progress_keep);
|
|
1184
1193
|
if (!t) return undefined;
|
|
1185
|
-
rekeySpawnFile(file, t.before, t.after);
|
|
1194
|
+
rekeySpawnFile(file, t.before, t.after, cfg.paths);
|
|
1186
1195
|
return `plan-guard: moved ${t.count} older Progress entries to ${t.archive}; re-read the plan before editing it again.`;
|
|
1187
1196
|
};
|
|
1188
1197
|
|
|
@@ -1240,7 +1249,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1240
1249
|
} catch {}
|
|
1241
1250
|
if (d.note) notes.push(d.note);
|
|
1242
1251
|
}
|
|
1243
|
-
if (d.allow && (!c.hasAgent || c.kind === "main") && q.doneCount(after) > q.doneCount(before) && q.planAt(file, q.activePlans())) {
|
|
1252
|
+
if (d.allow && (!c.hasAgent || c.kind === "main") && q.doneCount(after) > q.doneCount(before) && q.planAt(file, q.activePlans(cfg.paths))) {
|
|
1244
1253
|
const note = trimProgress(file);
|
|
1245
1254
|
if (note) notes.push(note);
|
|
1246
1255
|
}
|
|
@@ -1287,7 +1296,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1287
1296
|
}
|
|
1288
1297
|
if ((!c.hasAgent || c.kind === "main") && !e.isError) {
|
|
1289
1298
|
const text = content.map(p => asString(asRecord(p).text)).join("\n");
|
|
1290
|
-
recordMainResult(asString(e.toolName), asRecord(e.input), c.cwd ?? process.cwd(), text);
|
|
1299
|
+
recordMainResult(asString(e.toolName), asRecord(e.input), c.cwd ?? process.cwd(), text, cfg.paths);
|
|
1291
1300
|
// After the reads are recorded: a fresh hit clears its own warning, a stale list warns
|
|
1292
1301
|
// before Main drafts an edit the plan-read guard would refuse (I-20261025-208 P3).
|
|
1293
1302
|
const readNote = planReadNote(asString(e.toolName), asRecord(e.input), c.cwd ?? process.cwd(), text, cfg);
|
|
@@ -1355,7 +1364,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1355
1364
|
adapterLog(cfg, `ALLOW stop: rollover ${snap.state}`);
|
|
1356
1365
|
recordTurnAnswer(reply);
|
|
1357
1366
|
// Under the launcher a ready rollover starts now (not a hand-back to the owner).
|
|
1358
|
-
const handsToOwner = !(snap.state === "ready" && requestRelaunch(rc, notePath(rc.sessionId)));
|
|
1367
|
+
const handsToOwner = !(snap.state === "ready" && requestRelaunch(rc, notePath(rc.sessionId, mainStateDir(cfg))));
|
|
1359
1368
|
if (handsToOwner) notifyHandback(reply, "allowed session_stop");
|
|
1360
1369
|
else adapterLog(cfg, "notify: skipped (relaunch requested)");
|
|
1361
1370
|
return undefined;
|
|
@@ -1392,7 +1401,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1392
1401
|
const nowMs = Date.now();
|
|
1393
1402
|
const bytes = sizeOf(c.sessionFile);
|
|
1394
1403
|
const maxMb = cfg.rollover.max_session_mb;
|
|
1395
|
-
const noteMtimeMs = mtimeOf(notePath(c.sessionId));
|
|
1404
|
+
const noteMtimeMs = mtimeOf(notePath(c.sessionId, mainStateDir(cfg)));
|
|
1396
1405
|
const liveVersion = packageVersion(packageJsonPath());
|
|
1397
1406
|
const stale = liveVersion === null || loadedVersion === null || liveVersion !== loadedVersion;
|
|
1398
1407
|
if (stale) {
|
|
@@ -1420,7 +1429,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1420
1429
|
// The note request for a state. A stale install names both versions in place of the size line.
|
|
1421
1430
|
const noteRequestFor = (c: RolloverCtx, snap: { stale: boolean; liveVersion: string | null }): string => {
|
|
1422
1431
|
const reason = snap.stale ? `neurastream on disk is ${snap.liveVersion ?? "unknown"}, this session runs ${loadedVersion ?? "unknown"}` : undefined;
|
|
1423
|
-
return noteRequest(notePath(c.sessionId), reason);
|
|
1432
|
+
return noteRequest(notePath(c.sessionId, mainStateDir(cfg)), reason);
|
|
1424
1433
|
};
|
|
1425
1434
|
|
|
1426
1435
|
let relaunched = false;
|
|
@@ -1452,13 +1461,13 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1452
1461
|
// the wait sends the owner's text to this session as an ordinary message.
|
|
1453
1462
|
const rolloverInProcess = async (c: RolloverCtx, owner: string[], notice: string): Promise<void> => {
|
|
1454
1463
|
const previous = c.sessionFile;
|
|
1455
|
-
const path = notePath(c.sessionId);
|
|
1464
|
+
const path = notePath(c.sessionId, mainStateDir(cfg));
|
|
1456
1465
|
flight = owner;
|
|
1457
1466
|
try {
|
|
1458
1467
|
c.notify(notice);
|
|
1459
1468
|
const generated = [
|
|
1460
1469
|
await mainStartText([], cfg, { inheritStdin: false }, { source: defaultRunSource(cfg), results: defaultCompletedResults(cfg), providers: ompProviders(cfg) }),
|
|
1461
|
-
holdsBlock(q.ownerHolds()),
|
|
1470
|
+
holdsBlock(q.ownerHolds(cfg.paths)),
|
|
1462
1471
|
].join("\n");
|
|
1463
1472
|
const note = readFileSync(path, "utf8");
|
|
1464
1473
|
adapterLog(cfg, `rollover: new session from ${previous}; note ${path}`);
|
|
@@ -1479,7 +1488,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1479
1488
|
note,
|
|
1480
1489
|
previousSessionFile: previous,
|
|
1481
1490
|
ownerMessage: owner.filter(s => s !== "").join("\n"),
|
|
1482
|
-
unanswered: unansweredOwnerMessages(readOwnerMessages(), readOwnerAnswers()),
|
|
1491
|
+
unanswered: unansweredOwnerMessages(readOwnerMessages(cfg.paths), readOwnerAnswers(cfg.paths)),
|
|
1483
1492
|
});
|
|
1484
1493
|
pi.sendUserMessage(handoff);
|
|
1485
1494
|
} finally {
|
|
@@ -1507,9 +1516,10 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1507
1516
|
// shuts down only after the file is written. A failed write keeps the session running.
|
|
1508
1517
|
// Returns whether the request was written.
|
|
1509
1518
|
const requestRelaunch = (c: RolloverCtx, note: string, draft = c.draft()): boolean => {
|
|
1519
|
+
const reqFile = relaunchPath(mainStateDir(cfg));
|
|
1510
1520
|
try {
|
|
1511
|
-
mkdirSync(dirname(
|
|
1512
|
-
writeFileSync(
|
|
1521
|
+
mkdirSync(dirname(reqFile), { recursive: true });
|
|
1522
|
+
writeFileSync(reqFile, `${JSON.stringify({ previousSessionFile: c.sessionFile, notePath: note, draft })}\n`);
|
|
1513
1523
|
} catch (err) {
|
|
1514
1524
|
adapterLog(cfg, `rollover: relaunch request not written: ${String(err)}`);
|
|
1515
1525
|
return false;
|
|
@@ -1524,12 +1534,13 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1524
1534
|
// An owner message typed while the relaunch is pending joins the request's draft, in order; the
|
|
1525
1535
|
// launcher's handoff carries it. The rewrite is atomic, so the launcher never reads a partial file.
|
|
1526
1536
|
const appendToRelaunch = (text: string): boolean => {
|
|
1537
|
+
const reqFile = relaunchPath(mainStateDir(cfg));
|
|
1527
1538
|
try {
|
|
1528
|
-
const req = asRecord(JSON.parse(readFileSync(
|
|
1539
|
+
const req = asRecord(JSON.parse(readFileSync(reqFile, "utf8")));
|
|
1529
1540
|
const draft = [asString(req.draft), text].filter(s => s !== "").join("\n");
|
|
1530
|
-
const tmp = `${
|
|
1541
|
+
const tmp = `${reqFile}.tmp`;
|
|
1531
1542
|
writeFileSync(tmp, `${JSON.stringify({ ...req, draft })}\n`);
|
|
1532
|
-
renameSync(tmp,
|
|
1543
|
+
renameSync(tmp, reqFile);
|
|
1533
1544
|
return true;
|
|
1534
1545
|
} catch (err) {
|
|
1535
1546
|
adapterLog(cfg, `rollover: owner message not added to the relaunch request: ${String(err)}`);
|
|
@@ -1542,11 +1553,12 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1542
1553
|
// dead UI. The owner-away text stands in when nothing was typed.
|
|
1543
1554
|
const exitGraceElapsed = (c: RolloverCtx): void => {
|
|
1544
1555
|
adapterLog(cfg, `rollover: omp did not exit within ${cfg.rollover.exit_grace_s}s; rolling over in-process`);
|
|
1556
|
+
const reqFile = relaunchPath(mainStateDir(cfg));
|
|
1545
1557
|
let draft = "";
|
|
1546
1558
|
try {
|
|
1547
|
-
draft = asString(asRecord(JSON.parse(readFileSync(
|
|
1559
|
+
draft = asString(asRecord(JSON.parse(readFileSync(reqFile, "utf8"))).draft);
|
|
1548
1560
|
} catch {}
|
|
1549
|
-
rmSync(
|
|
1561
|
+
rmSync(reqFile, { force: true });
|
|
1550
1562
|
relaunched = false;
|
|
1551
1563
|
rolloverInProcess(c, [draft.trim() === "" ? OWNER_AWAY : draft], "rollover: omp did not restart; continuing in a new session here").catch((err: unknown) => {
|
|
1552
1564
|
adapterLog(cfg, `rollover: in-process rollover failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -1568,7 +1580,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1568
1580
|
);
|
|
1569
1581
|
} else if (terminal && snap.state === "ready" && !relaunched && flight === null) {
|
|
1570
1582
|
// flight !== null: an in-process rollover (the fallback) owns this session's end.
|
|
1571
|
-
requestRelaunch(c, notePath(c.sessionId));
|
|
1583
|
+
requestRelaunch(c, notePath(c.sessionId, mainStateDir(cfg)));
|
|
1572
1584
|
} else if (terminal && relaunched) {
|
|
1573
1585
|
// A tool result mid-run never restarts the session (I-20261024-4), and omp's interactive
|
|
1574
1586
|
// mode re-runs its deferred exit check only when shutdown() is called again: re-arm at
|
|
@@ -1635,8 +1647,8 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1635
1647
|
// A deferred hand-back fires no session_stop: reset the per-turn cap here (I-20261030-24),
|
|
1636
1648
|
// record the hand-back for the owner-answer wait (P9), and steer a promise like checkStop
|
|
1637
1649
|
// refuses it (I-20261030-32).
|
|
1638
|
-
resetMainCalls();
|
|
1639
|
-
ownerAnswerHandback(nowSec());
|
|
1650
|
+
resetMainCalls(cfg.paths);
|
|
1651
|
+
ownerAnswerHandback(nowSec(), cfg.paths);
|
|
1640
1652
|
if (new RegExp(cfg.guards.plan_offer, "i").test(reply.text)) {
|
|
1641
1653
|
pi.sendUserMessage(STOP_PLAN_OFFER_REFUSAL);
|
|
1642
1654
|
}
|
|
@@ -1679,8 +1691,8 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1679
1691
|
pi.on("agent_end", (e, ctx) => {
|
|
1680
1692
|
if (!isMain(ctx)) return;
|
|
1681
1693
|
if (asRecord(e).willContinue === true) return;
|
|
1682
|
-
resetMainCalls();
|
|
1683
|
-
ownerAnswerHandback(nowSec());
|
|
1694
|
+
resetMainCalls(cfg.paths);
|
|
1695
|
+
ownerAnswerHandback(nowSec(), cfg.paths);
|
|
1684
1696
|
});
|
|
1685
1697
|
// P4k backstop (plan 20261028_1600): a named review spawn that ends with no verdict recorded at its edit is judged here, from its own plan file; the note tells Main at its next prompt.
|
|
1686
1698
|
pi.on("agent_end", (_e, ctx) => {
|
|
@@ -1711,7 +1723,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1711
1723
|
// Compaction keeps the owner's holds true: a summary may state a hold only as a plans' WAITING on owner line says it.
|
|
1712
1724
|
pi.on("session.compacting", (_e, ctx) => {
|
|
1713
1725
|
if (!isMain(ctx)) return undefined;
|
|
1714
|
-
const holds = q.ownerHolds();
|
|
1726
|
+
const holds = q.ownerHolds(cfg.paths);
|
|
1715
1727
|
return {
|
|
1716
1728
|
context: [
|
|
1717
1729
|
"Owner holds/blockers: only plans' WAITING on owner lines are real:",
|
|
@@ -1880,7 +1892,7 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
1880
1892
|
if (!relaunched) {
|
|
1881
1893
|
if (rolloverSnapshot(c).state !== "ready") return undefined;
|
|
1882
1894
|
// The message is the request's first owner text, so the editor draft is not carried.
|
|
1883
|
-
if (!requestRelaunch(c, notePath(c.sessionId), "")) return undefined;
|
|
1895
|
+
if (!requestRelaunch(c, notePath(c.sessionId, mainStateDir(cfg)), "")) return undefined;
|
|
1884
1896
|
}
|
|
1885
1897
|
if (appendToRelaunch(text)) c.notify("rollover in progress: your message goes to the new session");
|
|
1886
1898
|
else c.notify("rollover in progress: your message could not be saved and was not sent; send it again after the rollover");
|
|
@@ -13,7 +13,6 @@ import { readOwnerAnswers, readOwnerMessages } from "../../core/incidents.ts";
|
|
|
13
13
|
import { mainStartText } from "../../core/main-start.ts";
|
|
14
14
|
import { appendMetric } from "../../core/metrics.ts";
|
|
15
15
|
import type { CompleteRequest, CompleteResult } from "../../core/owner-topics.ts";
|
|
16
|
-
import { applyQueueEnv } from "../../core/queue/env.ts";
|
|
17
16
|
import { tryLock } from "../../core/file-lock.ts";
|
|
18
17
|
import { MAIN_ID_RE, mainId, mainStateDir } from "../../core/guards.ts";
|
|
19
18
|
import * as q from "../../core/queue/lib.ts";
|
|
@@ -172,7 +171,6 @@ interface RelaunchRequest {
|
|
|
172
171
|
* from the package on disk: the handoff is then built with the installed code, not the old code.
|
|
173
172
|
*/
|
|
174
173
|
export async function runMainLauncher(args: string[], cfg: Config, opts: LaunchOptions = {}): Promise<number> {
|
|
175
|
-
applyQueueEnv(cfg);
|
|
176
174
|
// --name names this launcher's Main and never reaches the harness: stripped before the first
|
|
177
175
|
// run's args and a relaunch's carriedArgs are built.
|
|
178
176
|
const { args: harnessArgs, name } = stripNameFlag(args);
|
|
@@ -391,7 +389,7 @@ function legacyRelaunchPath(cfg: Config): string {
|
|
|
391
389
|
|
|
392
390
|
/** After a successful consume, drop the request on the new path and any legacy copy for id main. */
|
|
393
391
|
function clearRelaunchFiles(cfg: Config): void {
|
|
394
|
-
rmSync(relaunchPath(), { force: true });
|
|
392
|
+
rmSync(relaunchPath(mainStateDir(cfg)), { force: true });
|
|
395
393
|
if (mainId() === "main") rmSync(legacyRelaunchPath(cfg), { force: true });
|
|
396
394
|
}
|
|
397
395
|
|
|
@@ -417,7 +415,7 @@ function parseRelaunchFile(path: string, cfg: Config): RelaunchRequest | null {
|
|
|
417
415
|
* required fields is removed and logged; an unreadable one is logged and left in place.
|
|
418
416
|
*/
|
|
419
417
|
function readRequest(since: number, cfg: Config): RelaunchRequest | null {
|
|
420
|
-
const newPath = relaunchPath();
|
|
418
|
+
const newPath = relaunchPath(mainStateDir(cfg));
|
|
421
419
|
let newMtime: number | undefined;
|
|
422
420
|
try {
|
|
423
421
|
newMtime = statSync(newPath).mtimeMs;
|
|
@@ -463,7 +461,7 @@ async function nextMessage(req: RelaunchRequest, cfg: Config, mainStart: typeof
|
|
|
463
461
|
try {
|
|
464
462
|
generated = [
|
|
465
463
|
await mainStart([], cfg, { inheritStdin: false }, { source: defaultRunSource(cfg), results: defaultCompletedResults(cfg), providers: ompProviders(cfg), episodesFor: cutoff => ompEpisodes(cfg, cutoff) }),
|
|
466
|
-
holdsBlock(q.ownerHolds()),
|
|
464
|
+
holdsBlock(q.ownerHolds(cfg.paths)),
|
|
467
465
|
].join("\n");
|
|
468
466
|
} catch (err) {
|
|
469
467
|
// A failing main-start must not cost the owner the note: the handoff says it failed.
|
|
@@ -477,7 +475,7 @@ async function nextMessage(req: RelaunchRequest, cfg: Config, mainStart: typeof
|
|
|
477
475
|
note,
|
|
478
476
|
previousSessionFile: req.previousSessionFile,
|
|
479
477
|
ownerMessage: `${OWNER_AWAY}${draft}`,
|
|
480
|
-
unanswered: unansweredOwnerMessages(readOwnerMessages(), readOwnerAnswers()),
|
|
478
|
+
unanswered: unansweredOwnerMessages(readOwnerMessages(cfg.paths), readOwnerAnswers(cfg.paths)),
|
|
481
479
|
});
|
|
482
480
|
const bytes = Buffer.byteLength(handoff);
|
|
483
481
|
if (bytes <= MAX_INLINE_HANDOFF) {
|
package/src/cli/claim.ts
CHANGED
|
@@ -9,7 +9,6 @@ import path from "node:path";
|
|
|
9
9
|
import { fileClaimStore, heldByOther, type Claim, type ClaimStore } from "../core/claims.ts";
|
|
10
10
|
import { nowSec, strftime } from "../core/clock.ts";
|
|
11
11
|
import { mainId } from "../core/guards.ts";
|
|
12
|
-
import { applyQueueEnv } from "../core/queue/env.ts";
|
|
13
12
|
import { activePlans, openWaits } from "../core/queue/lib.ts";
|
|
14
13
|
import { claimStoreFor, remoteStoreFor, type TeamEntry } from "../core/team-client.ts";
|
|
15
14
|
import type { Config } from "../core/config.ts";
|
|
@@ -21,13 +20,12 @@ const USAGE = [
|
|
|
21
20
|
].join("\n");
|
|
22
21
|
|
|
23
22
|
export function claimCli(args: string[], cfg: Config): number {
|
|
24
|
-
applyQueueEnv(cfg);
|
|
25
23
|
const me = mainId();
|
|
26
24
|
|
|
27
25
|
if (args[0] === "next") {
|
|
28
26
|
// Index order IS priority; the skips are queueSummary's flags minus plans another live
|
|
29
27
|
// Main holds. A claim that races away mid-loop just moves the pick to the next plan.
|
|
30
|
-
const plans = activePlans();
|
|
28
|
+
const plans = activePlans(cfg.paths);
|
|
31
29
|
const rank = new Map(plans.map((p, i) => [p.file, i + 1] as const));
|
|
32
30
|
for (const p of plans) {
|
|
33
31
|
if (p.status !== "open" || p.waiting || openWaits(p, plans, rank).length) continue;
|
package/src/cli/dispatch.ts
CHANGED
|
@@ -12,7 +12,6 @@ import { nowSec } from "../core/clock.ts";
|
|
|
12
12
|
import { postReply } from "../core/notify.ts";
|
|
13
13
|
import { log } from "../core/guards.ts";
|
|
14
14
|
import { loadKnownSecrets, redactSecrets, redactSummary } from "../core/secret-redact.ts";
|
|
15
|
-
import { applyQueueEnv } from "../core/queue/env.ts";
|
|
16
15
|
import { getAdapter } from "../adapters/index.ts";
|
|
17
16
|
import { GUARD_USAGE, runGuard } from "./guard.ts";
|
|
18
17
|
import { runInit } from "./init.ts";
|
|
@@ -32,7 +31,7 @@ import { watchOn, watchOff } from "./watch-setup.ts";
|
|
|
32
31
|
import { runWip } from "./wip.ts";
|
|
33
32
|
import { runUninstall } from "../core/uninstall.ts";
|
|
34
33
|
import { queueMigrate } from "../core/queue-migrate.ts";
|
|
35
|
-
import { activePlans, allowedAgents, enforceReadOnlyIndex, gitTop,
|
|
34
|
+
import { activePlans, allowedAgents, enforceReadOnlyIndex, gitTop, readIndex, writeIndex } from "../core/queue/lib.ts";
|
|
36
35
|
import { defaultRunner } from "../core/mr-sweep.ts";
|
|
37
36
|
import { allowAgents, denyAgents, invalidSlugs } from "../core/subagents.ts";
|
|
38
37
|
import { runLabels } from "./labels.ts";
|
|
@@ -206,9 +205,10 @@ export async function run(cmd: string, args: string[]): Promise<number> {
|
|
|
206
205
|
if (cmd === "doctor") {
|
|
207
206
|
for (const warning of pagesDoctor()) console.warn(`warning: ${warning}`);
|
|
208
207
|
try {
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
console.
|
|
208
|
+
const cfg = loadConfig();
|
|
209
|
+
const was = enforceReadOnlyIndex(cfg.paths.queue_index);
|
|
210
|
+
if (was) console.warn(`warning: ${cfg.paths.queue_index} — was ${was}, set 0444 (the plan index is read-only on disk)`);
|
|
211
|
+
console.log(watchDoctorLine(watchHealth(cfg, Date.now())));
|
|
212
212
|
} catch {} // a broken config is doctor's own report; the adapter doctor names it
|
|
213
213
|
return getAdapter().doctor();
|
|
214
214
|
}
|
|
@@ -266,9 +266,9 @@ export async function run(cmd: string, args: string[]): Promise<number> {
|
|
|
266
266
|
);
|
|
267
267
|
},
|
|
268
268
|
runner: defaultRunner,
|
|
269
|
-
plans: () => activePlans(),
|
|
269
|
+
plans: () => activePlans(cfg.paths),
|
|
270
270
|
// Plans whose newest spawn (staffing.json) is inside the watch.ci_red_hours window: a timer run has no live job list to ask.
|
|
271
|
-
staffed: now => timerStaffedPlans(now, cfg.watch.ci_red_hours),
|
|
271
|
+
staffed: now => timerStaffedPlans(now, cfg.watch.ci_red_hours, cfg.paths),
|
|
272
272
|
});
|
|
273
273
|
console.log(`watch: ${report.opened.length} opened, ${report.deduped.length} deduped, ${report.closed.length} recovered, ${report.detectors.length} detector findings`);
|
|
274
274
|
return 0;
|
|
@@ -290,13 +290,14 @@ export async function run(cmd: string, args: string[]): Promise<number> {
|
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
if (cmd === "queue" && (args[0] === "add" || args[0] === "move")) {
|
|
293
|
+
let cfg: Config;
|
|
293
294
|
try {
|
|
294
|
-
|
|
295
|
+
cfg = loadConfig();
|
|
295
296
|
} catch (err) {
|
|
296
297
|
console.error(err instanceof ConfigError ? err.message : String(err));
|
|
297
298
|
return 1;
|
|
298
299
|
}
|
|
299
|
-
return args[0] === "add" ? runQueueAdd(args.slice(1)) : runQueueMove(args.slice(1));
|
|
300
|
+
return args[0] === "add" ? runQueueAdd(args.slice(1), cfg) : runQueueMove(args.slice(1), cfg);
|
|
300
301
|
}
|
|
301
302
|
if (cmd === "guard") {
|
|
302
303
|
return runGuard(args[0] ?? "");
|
|
@@ -304,7 +305,7 @@ export async function run(cmd: string, args: string[]): Promise<number> {
|
|
|
304
305
|
if (cmd === "agents") return runAgents(args);
|
|
305
306
|
if ((PORTED as readonly string[]).includes(cmd)) {
|
|
306
307
|
try {
|
|
307
|
-
|
|
308
|
+
loadConfig();
|
|
308
309
|
} catch (err) {
|
|
309
310
|
console.error(err instanceof ConfigError ? err.message : String(err));
|
|
310
311
|
return 1;
|
|
@@ -322,7 +323,7 @@ const QUEUE_EDIT_USAGE =
|
|
|
322
323
|
// The index file is 0444 and guard-protected (plan 20261031_0911 P2), so these two commands are the
|
|
323
324
|
// only way an agent adds a plan or reorders it. Both write through writeIndex: the set of plans can
|
|
324
325
|
// only grow, and the file stays read-only on disk after every write.
|
|
325
|
-
function runQueueAdd(args: string[]): number {
|
|
326
|
+
function runQueueAdd(args: string[], cfg: Config): number {
|
|
326
327
|
const ri = args.indexOf("--rank");
|
|
327
328
|
const rest = args.filter((a, i) => a !== "--rank" && args[i - 1] !== "--rank");
|
|
328
329
|
const rankArg = ri >= 0 ? args[ri + 1] : undefined;
|
|
@@ -337,19 +338,20 @@ function runQueueAdd(args: string[]): number {
|
|
|
337
338
|
console.error(`queue add: ${abs} does not exist`);
|
|
338
339
|
return 1;
|
|
339
340
|
}
|
|
340
|
-
const
|
|
341
|
+
const index = cfg.paths.queue_index;
|
|
342
|
+
const lines = readIndex(index);
|
|
341
343
|
if (lines.includes(abs)) {
|
|
342
344
|
console.error(`queue add: ${abs} is already listed at rank ${lines.indexOf(abs) + 1} (queue move reorders it)`);
|
|
343
345
|
return 1;
|
|
344
346
|
}
|
|
345
347
|
const at = rank === null ? lines.length : Math.min(rank - 1, lines.length);
|
|
346
348
|
lines.splice(at, 0, abs);
|
|
347
|
-
writeIndex(lines);
|
|
348
|
-
console.log(`queue add: ${abs} at rank ${at + 1} of ${lines.length} in ${
|
|
349
|
+
writeIndex(lines, undefined, index);
|
|
350
|
+
console.log(`queue add: ${abs} at rank ${at + 1} of ${lines.length} in ${index}`);
|
|
349
351
|
return 0;
|
|
350
352
|
}
|
|
351
353
|
|
|
352
|
-
function runQueueMove(args: string[]): number {
|
|
354
|
+
function runQueueMove(args: string[], cfg: Config): number {
|
|
353
355
|
const [fileArg, rankArg] = args;
|
|
354
356
|
const n = Number(rankArg);
|
|
355
357
|
const rank = rankArg !== undefined && rankArg !== "" && Number.isInteger(n) && n >= 1 ? n : null;
|
|
@@ -358,17 +360,18 @@ function runQueueMove(args: string[]): number {
|
|
|
358
360
|
return 2;
|
|
359
361
|
}
|
|
360
362
|
const abs = path.resolve(fileArg!);
|
|
361
|
-
const
|
|
363
|
+
const index = cfg.paths.queue_index;
|
|
364
|
+
const lines = readIndex(index);
|
|
362
365
|
const from = lines.indexOf(abs);
|
|
363
366
|
if (from === -1) {
|
|
364
|
-
console.error(`queue move: ${abs} is not in ${
|
|
367
|
+
console.error(`queue move: ${abs} is not in ${index}`);
|
|
365
368
|
return 1;
|
|
366
369
|
}
|
|
367
370
|
lines.splice(from, 1);
|
|
368
371
|
const to = Math.min(rank - 1, lines.length);
|
|
369
372
|
lines.splice(to, 0, abs);
|
|
370
|
-
writeIndex(lines);
|
|
371
|
-
console.log(`queue move: ${abs} rank ${from + 1} → ${to + 1} of ${lines.length} in ${
|
|
373
|
+
writeIndex(lines, undefined, index);
|
|
374
|
+
console.log(`queue move: ${abs} rank ${from + 1} → ${to + 1} of ${lines.length} in ${index}`);
|
|
372
375
|
return 0;
|
|
373
376
|
}
|
|
374
377
|
|
|
@@ -442,13 +445,14 @@ function runAgents(args: string[]): number {
|
|
|
442
445
|
console.error(`invalid slug: ${bad.join(", ")} (allowed: a-z, 0-9, -)`);
|
|
443
446
|
return 2;
|
|
444
447
|
}
|
|
448
|
+
let cfg: Config;
|
|
445
449
|
try {
|
|
446
|
-
|
|
450
|
+
cfg = loadConfig();
|
|
447
451
|
} catch (err) {
|
|
448
452
|
console.error(err instanceof ConfigError ? err.message : String(err));
|
|
449
453
|
return 1;
|
|
450
454
|
}
|
|
451
|
-
const file =
|
|
455
|
+
const file = cfg.paths.subagents;
|
|
452
456
|
if (action === "list") {
|
|
453
457
|
for (const slug of allowedAgents(file)) console.log(slug);
|
|
454
458
|
console.log(`file: ${file}`);
|
package/src/cli/guard.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type { Decision, InjectEvent, PlanEditEvent, SpawnEvent, StopEvent, ToolE
|
|
|
6
6
|
import { plannerPin, verifyPlannerMode } from "../core/autonomy.ts";
|
|
7
7
|
import { ConfigError, loadConfig } from "../core/config.ts";
|
|
8
8
|
import { checkPlanEdit, checkSpawn, checkStop, checkTool, checkInject } from "../core/guards.ts";
|
|
9
|
-
import { applyQueueEnv } from "../core/queue/env.ts";
|
|
10
9
|
import type { Config } from "../core/config.ts";
|
|
11
10
|
|
|
12
11
|
export const GUARD_EVENTS = ["pre-tool", "prompt", "inject", "spawn", "plan-edit", "stop"] as const;
|
|
@@ -105,14 +104,12 @@ export async function runGuard(event: string): Promise<number> {
|
|
|
105
104
|
let cfg: Config;
|
|
106
105
|
try {
|
|
107
106
|
cfg = loadConfig();
|
|
108
|
-
applyQueueEnv(cfg);
|
|
109
107
|
// P2 d: hold the mode facts to the owner's baseline before any decision reads them; a
|
|
110
108
|
// reverted config is re-read so this guard sees the restored values.
|
|
111
109
|
const held = verifyPlannerMode(plannerPin(cfg));
|
|
112
110
|
if (held.reverted) {
|
|
113
111
|
if (held.hint !== null) console.error(held.hint);
|
|
114
112
|
cfg = loadConfig();
|
|
115
|
-
applyQueueEnv(cfg);
|
|
116
113
|
}
|
|
117
114
|
} catch (err) {
|
|
118
115
|
console.error(err instanceof ConfigError ? err.message : String(err));
|