neurastream 0.1.16 → 0.1.18
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 +2 -2
- package/package.json +1 -1
- package/src/adapters/omp/index.ts +82 -24
- package/src/adapters/omp/launch.ts +1 -1
- package/src/core/queue-close.ts +71 -15
- package/src/core/rollover.ts +4 -4
package/README.md
CHANGED
|
@@ -103,9 +103,9 @@ In both modes:
|
|
|
103
103
|
|
|
104
104
|
- A note counts only if it was written after the threshold was crossed and is at most one hour old.
|
|
105
105
|
- The running plugin going stale counts as over the threshold too: at every check the adapter re-reads the `package.json` it was loaded from, and a different (or unreadable) version asks for the handoff note even below `rollover.max_session_mb`, naming both versions (`NEURASTREAM_PACKAGE_JSON` overrides the path it watches).
|
|
106
|
-
- While a rollover is pending (no fresh note,
|
|
106
|
+
- While a rollover is pending (no fresh note, own jobs still running, or the handoff is ready and waiting for idle), Main cannot start new subagents: a `task` call is refused until the running jobs finish and the session rolls over.
|
|
107
107
|
- While own jobs (subagents included) are still running, the switch waits: a rollover would cancel them.
|
|
108
|
-
- `/main-rollover <message>` does the same by hand. It refuses below the threshold, without a fresh note, or while jobs run.
|
|
108
|
+
- `/main-rollover <message>` does the same by hand. It refuses below the threshold, without a fresh note, or while jobs run. Under neurastream main it is refused and the owner's next message starts the rollover; in plain omp a second call while one waits adds its text to the same handoff.
|
|
109
109
|
- `/main-rollover` shows a notice at once and gathers `main-start` in the background, so omp keeps repainting and reading keys until the new session opens.
|
|
110
110
|
- The previous session file stays where it is.
|
|
111
111
|
- `rollover.enabled: false` turns the feature off.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "neurastream",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Guardrails for running many AI coding agents at once: plan queue, blockers, call budgets, provider caps, scoring, merge-verified close.",
|
|
5
5
|
"keywords": ["ai-agents", "coding-agents", "orchestration", "guardrails", "omp", "bun", "cli"],
|
|
6
6
|
"homepage": "https://github.com/umiddey/neurastream#readme",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// Harness payloads are untyped at the boundary: every field read goes through a runtime check.
|
|
17
17
|
|
|
18
18
|
import { execFileSync, spawn } from "node:child_process";
|
|
19
|
-
import { appendFileSync, mkdirSync, openSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { appendFileSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
20
20
|
import { dirname, join, resolve } from "node:path";
|
|
21
21
|
import { fileURLToPath } from "node:url";
|
|
22
22
|
import type { Decision } from "../../core/adapter.ts";
|
|
@@ -412,6 +412,8 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
412
412
|
pi.on("session_stop", (_e, ctx) => {
|
|
413
413
|
const c = asCtx(ctx);
|
|
414
414
|
if (c.hasAgent && c.kind !== "main") return;
|
|
415
|
+
// A relaunch is requested: omp shuts down at the next idle, so the stop must not be continued.
|
|
416
|
+
if (relaunched) return undefined;
|
|
415
417
|
const d = checkStop({ agent: "main", callsSinceStop, idleStops, ledgerText: ledgerText(cfg) }, cfg);
|
|
416
418
|
callsSinceStop = d.state?.callsSinceStop ?? 0;
|
|
417
419
|
idleStops = d.state?.idleStops ?? idleStops;
|
|
@@ -464,20 +466,35 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
464
466
|
let relaunched = false;
|
|
465
467
|
// The launcher restarts omp: the request file carries the note and the editor draft, and omp
|
|
466
468
|
// shuts down only after the file is written. A failed write keeps the session running.
|
|
467
|
-
|
|
469
|
+
// Returns whether the request was written.
|
|
470
|
+
const requestRelaunch = (c: RolloverCtx, note: string, draft = c.draft()): boolean => {
|
|
468
471
|
try {
|
|
469
472
|
mkdirSync(dirname(relaunchPath()), { recursive: true });
|
|
470
|
-
writeFileSync(
|
|
471
|
-
relaunchPath(),
|
|
472
|
-
`${JSON.stringify({ previousSessionFile: c.sessionFile, notePath: note, draft: c.draft() })}\n`,
|
|
473
|
-
);
|
|
473
|
+
writeFileSync(relaunchPath(), `${JSON.stringify({ previousSessionFile: c.sessionFile, notePath: note, draft })}\n`);
|
|
474
474
|
} catch (err) {
|
|
475
475
|
adapterLog(cfg, `rollover: relaunch request not written: ${String(err)}`);
|
|
476
|
-
return;
|
|
476
|
+
return false;
|
|
477
477
|
}
|
|
478
478
|
relaunched = true;
|
|
479
479
|
adapterLog(cfg, `rollover: relaunch requested from ${c.sessionFile}`);
|
|
480
480
|
c.shutdown();
|
|
481
|
+
return true;
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
// An owner message typed while the relaunch is pending joins the request's draft, in order; the
|
|
485
|
+
// launcher's handoff carries it. The rewrite is atomic, so the launcher never reads a partial file.
|
|
486
|
+
const appendToRelaunch = (text: string): boolean => {
|
|
487
|
+
try {
|
|
488
|
+
const req = asRecord(JSON.parse(readFileSync(relaunchPath(), "utf8")));
|
|
489
|
+
const draft = [asString(req.draft), text].filter(s => s !== "").join("\n");
|
|
490
|
+
const tmp = `${relaunchPath()}.tmp`;
|
|
491
|
+
writeFileSync(tmp, `${JSON.stringify({ ...req, draft })}\n`);
|
|
492
|
+
renameSync(tmp, relaunchPath());
|
|
493
|
+
return true;
|
|
494
|
+
} catch (err) {
|
|
495
|
+
adapterLog(cfg, `rollover: owner message not added to the relaunch request: ${String(err)}`);
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
481
498
|
};
|
|
482
499
|
|
|
483
500
|
const onSizeCheck = (_e: unknown, ctx: unknown): void => {
|
|
@@ -527,22 +544,46 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
527
544
|
return null;
|
|
528
545
|
};
|
|
529
546
|
|
|
530
|
-
//
|
|
547
|
+
// Under the launcher the relaunch is the only rollover path: a plain interactive message in the ready
|
|
548
|
+
// state requests it, and every such message joins the pending request's draft, in order. Plain omp keeps
|
|
549
|
+
// `/main-rollover <text>`: the message becomes the owner's first message of the new session.
|
|
531
550
|
pi.on("input", (event, ctx) => {
|
|
532
551
|
const e = asRecord(event);
|
|
533
552
|
const c = asRolloverCtx(ctx);
|
|
534
553
|
const text = asString(e.text);
|
|
535
554
|
if (!cfg.rollover.enabled || !c || !isMain(ctx)) return undefined;
|
|
536
555
|
if (asString(e.source) !== "interactive" || text === "" || text.startsWith("/")) return undefined;
|
|
556
|
+
if (process.env.NEURASTREAM_MAIN_LAUNCHER === "1") {
|
|
557
|
+
if (!relaunched) {
|
|
558
|
+
if (rolloverSnapshot(c).state !== "ready") return undefined;
|
|
559
|
+
// The message is the request's first owner text, so the editor draft is not carried.
|
|
560
|
+
if (!requestRelaunch(c, notePath(c.sessionId), "")) return undefined;
|
|
561
|
+
}
|
|
562
|
+
if (appendToRelaunch(text)) c.notify("rollover in progress: your message goes to the new session");
|
|
563
|
+
else c.notify("rollover in progress: your message could not be saved and was not sent; send it again after the rollover");
|
|
564
|
+
return { handled: true };
|
|
565
|
+
}
|
|
537
566
|
if (rolloverSnapshot(c).state !== "ready") return undefined;
|
|
538
567
|
return { text: `/main-rollover ${text}` };
|
|
539
568
|
});
|
|
540
569
|
|
|
570
|
+
// One /main-rollover at a time: while one waits for idle, a second call adds its text to the owner message.
|
|
571
|
+
let flight: string[] | null = null;
|
|
541
572
|
pi.registerCommand("main-rollover", {
|
|
542
573
|
description: "Start a fresh session from Main's handoff note; the rest of the message is the owner's first message",
|
|
543
574
|
handler: async (args: unknown, ctx: unknown) => {
|
|
544
575
|
const c = asRolloverCtx(ctx);
|
|
545
576
|
if (!c) return;
|
|
577
|
+
const text = asString(args);
|
|
578
|
+
if (process.env.NEURASTREAM_MAIN_LAUNCHER === "1") {
|
|
579
|
+
c.notify("main-rollover: under neurastream main the rollover starts from your next message, not from this command.");
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
if (flight) {
|
|
583
|
+
flight.push(text);
|
|
584
|
+
c.notify("main-rollover: a rollover is already in progress; your message is added to its handoff.");
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
546
587
|
const path = notePath(c.sessionId);
|
|
547
588
|
const state = rolloverSnapshot(c).state;
|
|
548
589
|
if (state === "below") {
|
|
@@ -557,22 +598,39 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
557
598
|
c.notify(`main-rollover: own jobs are still running (${c.runningJobs().join(", ")}); a rollover would cancel them.`);
|
|
558
599
|
return;
|
|
559
600
|
}
|
|
560
|
-
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
601
|
+
const previous = c.sessionFile;
|
|
602
|
+
const owner = [text];
|
|
603
|
+
flight = owner;
|
|
604
|
+
try {
|
|
605
|
+
c.notify("main-rollover: collecting main-start state for the handoff (this can take a minute)…");
|
|
606
|
+
const generated = [
|
|
607
|
+
await mainStartText([], cfg, { inheritStdin: false }, { source: defaultRunSource(cfg), results: defaultCompletedResults(cfg) }),
|
|
608
|
+
holdsBlock(q.ownerHolds()),
|
|
609
|
+
].join("\n");
|
|
610
|
+
const note = readFileSync(path, "utf8");
|
|
611
|
+
adapterLog(cfg, `rollover: new session from ${previous}; note ${path}`);
|
|
612
|
+
await c.waitForIdle();
|
|
613
|
+
const again = rolloverSnapshot(c).state;
|
|
614
|
+
if (relaunched || again !== "ready") {
|
|
615
|
+
c.notify(`main-rollover: the state changed while waiting for idle (${relaunched ? "relaunch requested" : again}); no new session.`);
|
|
616
|
+
// The owner's text is not lost: it goes to this session as an ordinary message.
|
|
617
|
+
const pending = owner.filter(s => s !== "").join("\n");
|
|
618
|
+
if (pending !== "") pi.sendUserMessage(pending);
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
const r = asRecord(await c.newSession({ parentSession: previous }));
|
|
622
|
+
if (r.cancelled === true) return;
|
|
623
|
+
// Read after the await: owner messages that arrived during newSession are part of the handoff.
|
|
624
|
+
const handoff = buildHandoff({
|
|
625
|
+
generated,
|
|
626
|
+
note,
|
|
627
|
+
previousSessionFile: previous,
|
|
628
|
+
ownerMessage: owner.filter(s => s !== "").join("\n"),
|
|
629
|
+
});
|
|
630
|
+
pi.sendUserMessage(handoff);
|
|
631
|
+
} finally {
|
|
632
|
+
flight = null;
|
|
633
|
+
}
|
|
576
634
|
},
|
|
577
635
|
});
|
|
578
636
|
}
|
|
@@ -149,7 +149,7 @@ async function nextMessage(req: RelaunchRequest, cfg: Config): Promise<string |
|
|
|
149
149
|
await mainStartText([], cfg, { inheritStdin: false }, { source: defaultRunSource(cfg), results: defaultCompletedResults(cfg) }),
|
|
150
150
|
holdsBlock(q.ownerHolds()),
|
|
151
151
|
].join("\n");
|
|
152
|
-
const draft = req.draft.trim() === "" ? "" : `\nOwner's unsent draft: ${req.draft}`;
|
|
152
|
+
const draft = req.draft.trim() === "" ? "" : `\nOwner's messages during the rollover (and any unsent draft): ${req.draft}`;
|
|
153
153
|
const handoff = buildHandoff({
|
|
154
154
|
generated,
|
|
155
155
|
note,
|
package/src/core/queue-close.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { appendFileSync, existsSync, fstatSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { appendFileSync, existsSync, fstatSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import type { Config } from "./config.ts";
|
|
@@ -65,6 +65,25 @@ export function queueClose(args: string[], cfg: Config): number {
|
|
|
65
65
|
if (lines.length) writeFileSync(file, `${lines.join("\n")}\n`);
|
|
66
66
|
else rmSync(file, { force: true });
|
|
67
67
|
}
|
|
68
|
+
// A clone of a clone judges "landed" against the middle copy's default branch, which can be
|
|
69
|
+
// stale. Follow local-path origins (at most 3 hops) to the upstream repo and fetch its default
|
|
70
|
+
// branch: that commit is the base. No local origin: the existing base, unchanged.
|
|
71
|
+
function upstreamBase(repo: string, localBase: string): string {
|
|
72
|
+
let cur = repo;
|
|
73
|
+
let hops = 0;
|
|
74
|
+
while (hops < 3) {
|
|
75
|
+
const url = git(cur, "config", "--get", "remote.origin.url").out;
|
|
76
|
+
if (!url || !path.isAbsolute(url) || !existsSync(url) || !git(url, "rev-parse", "--git-dir").ok) break;
|
|
77
|
+
cur = url;
|
|
78
|
+
hops++;
|
|
79
|
+
}
|
|
80
|
+
if (hops === 0) return localBase;
|
|
81
|
+
const named = git(cur, "symbolic-ref", "-q", "--short", "refs/remotes/origin/HEAD").out.replace(/^origin\//, "");
|
|
82
|
+
const def = named || git(cur, "symbolic-ref", "-q", "--short", "HEAD").out;
|
|
83
|
+
const fetched = git(repo, "fetch", "-q", cur, def);
|
|
84
|
+
if (!fetched.ok) die(`could not fetch ${def} from ${cur}: ${fetched.out}`);
|
|
85
|
+
return git(repo, "rev-parse", "FETCH_HEAD").out;
|
|
86
|
+
}
|
|
68
87
|
const today = new Date().toISOString().slice(0, 10);
|
|
69
88
|
|
|
70
89
|
const arg = args[0];
|
|
@@ -95,10 +114,26 @@ export function queueClose(args: string[], cfg: Config): number {
|
|
|
95
114
|
|
|
96
115
|
git(plan.repo, "fetch", "-q", "origin");
|
|
97
116
|
const head = git(plan.repo, "symbolic-ref", "-q", "refs/remotes/origin/HEAD");
|
|
98
|
-
const base = head.ok ? head.out : "refs/remotes/origin/main";
|
|
117
|
+
const base = upstreamBase(plan.repo, head.ok ? head.out : "refs/remotes/origin/main");
|
|
118
|
+
const worktrees = (): { path: string; branch: string | null; head: string }[] => {
|
|
119
|
+
const list: { path: string; branch: string | null; head: string }[] = [];
|
|
120
|
+
for (const line of git(plan.repo, "worktree", "list", "--porcelain").out.split("\n")) {
|
|
121
|
+
if (line.startsWith("worktree ")) list.push({ path: path.resolve(line.slice(9)), branch: null, head: "" });
|
|
122
|
+
const cur = list.at(-1);
|
|
123
|
+
if (!cur) continue;
|
|
124
|
+
if (line.startsWith("HEAD ")) cur.head = line.slice(5);
|
|
125
|
+
else if (line.startsWith("branch refs/heads/")) cur.branch = line.slice(18);
|
|
126
|
+
}
|
|
127
|
+
return list;
|
|
128
|
+
};
|
|
129
|
+
const wtEntry = plan.worktree ? worktrees().find(w => w.path === path.resolve(plan.worktree!)) : undefined;
|
|
99
130
|
const wtExists = !!plan.worktree && existsSync(plan.worktree);
|
|
100
|
-
|
|
101
|
-
|
|
131
|
+
// A plan worktree is the plan's only while it sits on the plan's branch (or a detached HEAD already merged into it).
|
|
132
|
+
const owned = wtExists && !!plan.branch && !!wtEntry && (wtEntry.branch !== null
|
|
133
|
+
? wtEntry.branch === plan.branch
|
|
134
|
+
: git(plan.repo, "merge-base", "--is-ancestor", wtEntry.head, `refs/heads/${plan.branch}`).ok);
|
|
135
|
+
if (wtExists && !owned) console.log(`queue-close: worktree ${plan.worktree} kept: it is on ${wtEntry?.branch ?? (wtEntry ? "a detached HEAD" : "no branch of this repo")}`);
|
|
136
|
+
const branch = plan.branch;
|
|
102
137
|
const branchExists = !!branch && git(plan.repo, "rev-parse", "--verify", "-q", `refs/heads/${branch}`).ok;
|
|
103
138
|
const merged = branchExists && (
|
|
104
139
|
git(plan.repo, "merge-base", "--is-ancestor", `refs/heads/${branch}`, base).ok ||
|
|
@@ -106,17 +141,33 @@ export function queueClose(args: string[], cfg: Config): number {
|
|
|
106
141
|
declaredLanded(plan.repo, `refs/heads/${branch}`, base, readFileSync(file, "utf8"))
|
|
107
142
|
);
|
|
108
143
|
|
|
109
|
-
|
|
144
|
+
// A plan whose worktree is missing or kept is checked against the upstream base, never a foreign checkout.
|
|
145
|
+
const detached = !!plan.worktree && !owned;
|
|
146
|
+
const runIn = owned ? plan.worktree! : plan.repo;
|
|
110
147
|
if (!cancelling) {
|
|
111
148
|
const tip = branchExists ? git(plan.repo, "rev-parse", `refs/heads/${branch}`).out : "";
|
|
112
|
-
const dirty = git(runIn, "status", "--porcelain").out;
|
|
149
|
+
const dirty = detached ? `base:${base}` : git(runIn, "status", "--porcelain").out;
|
|
113
150
|
const doneKey = sha(`${plan.doneCheck}\n${tip}\n${dirty}`);
|
|
114
151
|
const doneCache = path.join(STATE_DIR, `done-ok-${sha(file)}`);
|
|
115
152
|
const cached = existsSync(doneCache) && readFileSync(doneCache, "utf8").trim() === doneKey;
|
|
116
153
|
if (cached) console.log(`queue-close: done check passed before for this state (cached ${doneKey})`);
|
|
117
154
|
else {
|
|
118
|
-
|
|
119
|
-
|
|
155
|
+
let scratch: string | undefined;
|
|
156
|
+
if (detached) {
|
|
157
|
+
scratch = mkdtempSync(path.join(STATE_DIR, "done-base-"));
|
|
158
|
+
const add = git(plan.repo, "worktree", "add", "--detach", scratch, base);
|
|
159
|
+
if (!add.ok) {
|
|
160
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
161
|
+
die(`could not check out ${base} for the done check: ${add.out}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
console.log(`queue-close: done check in ${detached ? `${base} (temporary worktree)` : runIn}: ${plan.doneCheck}`);
|
|
165
|
+
const dc = spawnSync("bash", ["-lc", plan.doneCheck!], { cwd: scratch ?? runIn, stdio: "inherit", timeout: 3600_000 });
|
|
166
|
+
if (scratch) {
|
|
167
|
+
git(plan.repo, "worktree", "remove", "--force", scratch);
|
|
168
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
169
|
+
git(plan.repo, "worktree", "prune");
|
|
170
|
+
}
|
|
120
171
|
if (dc.status !== 0) {
|
|
121
172
|
rmSync(doneCache, { force: true });
|
|
122
173
|
const text = readFileSync(file, "utf8")
|
|
@@ -139,8 +190,9 @@ export function queueClose(args: string[], cfg: Config): number {
|
|
|
139
190
|
const [ref, t] = line.split(" ");
|
|
140
191
|
if (ref && Number(t) < cutoff) git(plan.repo, "update-ref", "-d", ref);
|
|
141
192
|
}
|
|
142
|
-
if (
|
|
143
|
-
const
|
|
193
|
+
if (owned) {
|
|
194
|
+
const stash = git(plan.worktree!, "stash", "create", `queue-close: uncommitted work of ${path.basename(file)}`);
|
|
195
|
+
const saved = stash.ok ? stash.out : "";
|
|
144
196
|
if (saved) {
|
|
145
197
|
const ref = `refs/queue-archive/${path.basename(file, ".md")}-${today}`;
|
|
146
198
|
if (!git(plan.repo, "update-ref", ref, saved).ok || !git(plan.repo, "stash", "show", "-p", ref).out)
|
|
@@ -155,9 +207,9 @@ export function queueClose(args: string[], cfg: Config): number {
|
|
|
155
207
|
if (!keep.ok || !git(plan.repo, "update-ref", ref, keep.out).ok) die(`could not save branch ${branch} to ${ref}; nothing removed`);
|
|
156
208
|
console.log(`queue-close: branch ${branch} saved as ${ref} (restore: git -C ${plan.repo} branch ${branch} ${ref}^; pruned after ${ARCHIVE_DAYS} days)`);
|
|
157
209
|
}
|
|
158
|
-
if (
|
|
210
|
+
if (owned) {
|
|
159
211
|
let rm = git(plan.repo, "worktree", "remove", "--force", plan.worktree!);
|
|
160
|
-
if (!rm.ok &&
|
|
212
|
+
if (!rm.ok && existsSync(plan.worktree!)) {
|
|
161
213
|
spawnSync("docker", ["run", "--rm", "-v", `${plan.worktree}:/w`, "alpine", "chown", "-R", `${os.userInfo().uid}:${os.userInfo().gid}`, "/w"], { stdio: "ignore" });
|
|
162
214
|
rm = git(plan.repo, "worktree", "remove", "--force", plan.worktree!);
|
|
163
215
|
if (!rm.ok && existsSync(plan.worktree!)) {
|
|
@@ -170,9 +222,13 @@ export function queueClose(args: string[], cfg: Config): number {
|
|
|
170
222
|
console.log(`queue-close: worktree ${plan.worktree} removed`);
|
|
171
223
|
}
|
|
172
224
|
if (branchExists) {
|
|
173
|
-
const
|
|
174
|
-
if (
|
|
175
|
-
|
|
225
|
+
const holder = worktrees().find(w => w.branch === branch);
|
|
226
|
+
if (holder) console.log(`queue-close: branch ${branch} kept: checked out in ${holder.path}`);
|
|
227
|
+
else {
|
|
228
|
+
const d = git(plan.repo, "branch", "-D", branch!);
|
|
229
|
+
if (!d.ok) die(`could not delete branch ${branch}: ${d.out}`);
|
|
230
|
+
console.log(`queue-close: branch ${branch} deleted`);
|
|
231
|
+
}
|
|
176
232
|
}
|
|
177
233
|
|
|
178
234
|
const month = today.slice(0, 7).replace("-", "");
|
package/src/core/rollover.ts
CHANGED
|
@@ -45,12 +45,12 @@ export function rolloverState(p: RolloverInput): RolloverState {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* Drain: while a rollover is pending (need-note
|
|
49
|
-
* a rollover would cancel them, or they would outlive the handoff.
|
|
50
|
-
* null when the spawn may proceed
|
|
48
|
+
* Drain: while a rollover is pending (need-note, wait-jobs or ready) Main must not start new subagents —
|
|
49
|
+
* a rollover would cancel them, or they would outlive the handoff. Ready counts: the rollover follows the
|
|
50
|
+
* next idle, so a spawn now would be aborted. Returns the refusal text, or null when the spawn may proceed.
|
|
51
51
|
*/
|
|
52
52
|
export function spawnRefusal(state: RolloverState, runningJobs: readonly string[]): string | null {
|
|
53
|
-
if (state !== "need-note" && state !== "wait-jobs") return null;
|
|
53
|
+
if (state !== "need-note" && state !== "wait-jobs" && state !== "ready") return null;
|
|
54
54
|
return `main-guard: rollover pending (${state}); no new subagents until the session rolls over. Running: ${runningJobs.join(", ")}.`;
|
|
55
55
|
}
|
|
56
56
|
|