pi-straw-boss 0.113.1 → 0.113.2
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/dist/server/main.mjs +27 -9
- package/package.json +1 -1
- package/src/server/runs.ts +4 -2
- package/src/server/towers.ts +14 -3
- package/src/server/towerstore.ts +2 -0
- package/src/server/towerstow.ts +19 -8
package/dist/server/main.mjs
CHANGED
|
@@ -26750,7 +26750,6 @@ var STOW = { intervalMs: 3e3, idleMs: 3e4 };
|
|
|
26750
26750
|
var keep2 = (why2) => ({ stow: false, why: why2 });
|
|
26751
26751
|
function idleGate(f) {
|
|
26752
26752
|
if (f.head) return keep2("head");
|
|
26753
|
-
if (f.headless) return keep2("headless");
|
|
26754
26753
|
if (!f.ready) return keep2("unready");
|
|
26755
26754
|
if (f.cards > 0) return keep2("cards");
|
|
26756
26755
|
if (f.run || f.state === "waking" || f.state === "running" || f.state === "closing") return keep2("run");
|
|
@@ -26777,6 +26776,9 @@ function foregroundOf(info, workspace, promptPid) {
|
|
|
26777
26776
|
const shell2 = typeof info?.shell_pid === "number" ? info.shell_pid : void 0, prompt = new RegExp(`\\bprompt --workspace ${workspace.replace(/[^\w.:-]/g, "")}(\\s|$)`);
|
|
26778
26777
|
return list2.every((p) => (shell2 !== void 0 ? p.pid === shell2 : list2.length === 1 && SHELLS2.has(nameOf2(p))) || promptPid !== void 0 && p.pid === promptPid || prompt.test(p.cmdline ?? "")) ? "clean" : "program";
|
|
26779
26778
|
}
|
|
26779
|
+
function reopenGate(f) {
|
|
26780
|
+
return !f.headless || f.stowed && f.attended;
|
|
26781
|
+
}
|
|
26780
26782
|
function seatOpen(f) {
|
|
26781
26783
|
if (f.label === void 0) return "gone";
|
|
26782
26784
|
return f.seated || f.label === f.record ? "open" : "stranger";
|
|
@@ -26791,8 +26793,9 @@ function createStow(o) {
|
|
|
26791
26793
|
const processInfo = (pane) => run2(["pane", "process-info", "--pane", pane]).then((x) => JSON.parse(x).result?.process_info, () => void 0);
|
|
26792
26794
|
const idleOf = (l, at) => {
|
|
26793
26795
|
const ws = o.record(l).workspace, status = o.status(ws), from = since.get(ws);
|
|
26794
|
-
return idleGate({ head: o.head(l),
|
|
26796
|
+
return idleGate({ head: o.head(l), ready: o.ready(l), cards: o.cards(l), state: status?.state, run: Boolean(status?.run) || (status?.allyRuns.length ?? 0) > 0, queued: o.queued(ws), soon: o.soon(ws, t.idleMs), idleFor: from ? at - from.at : 0, idleMs: t.idleMs });
|
|
26795
26797
|
};
|
|
26798
|
+
const wants = (l) => reopenGate({ headless: o.headless(), stowed: o.record(l).stowed === true, attended: o.attended() });
|
|
26796
26799
|
const said1 = (ws, why2) => {
|
|
26797
26800
|
if (said2.get(ws) === why2) return;
|
|
26798
26801
|
said2.set(ws, why2);
|
|
@@ -26800,7 +26803,7 @@ function createStow(o) {
|
|
|
26800
26803
|
};
|
|
26801
26804
|
const close = async (l, record2) => {
|
|
26802
26805
|
const ws = record2.workspace, undo = o.hold(l);
|
|
26803
|
-
const bare2 = { ...record2, pane: "", tab: "" };
|
|
26806
|
+
const bare2 = { ...record2, pane: "", tab: "", stowed: true };
|
|
26804
26807
|
o.place(l, bare2);
|
|
26805
26808
|
try {
|
|
26806
26809
|
await run2(["pane", "close", record2.pane]);
|
|
@@ -26816,8 +26819,9 @@ function createStow(o) {
|
|
|
26816
26819
|
};
|
|
26817
26820
|
const lookAt = async (l) => {
|
|
26818
26821
|
const record2 = o.record(l), ws = record2.workspace;
|
|
26819
|
-
if (o.head(l) ||
|
|
26822
|
+
if (o.head(l) || opening3.has(ws)) return;
|
|
26820
26823
|
if (!record2.pane) {
|
|
26824
|
+
if (!wants(l)) return;
|
|
26821
26825
|
if (!o.seated(l)) {
|
|
26822
26826
|
const listed = await workspaces(run2).catch(() => void 0), seat = listed && seatOpen({ seated: false, label: listed.find((w) => w.workspace_id === ws)?.label, record: record2.label });
|
|
26823
26827
|
if (seat === "open") await o.seat(l);
|
|
@@ -26867,7 +26871,8 @@ function createStow(o) {
|
|
|
26867
26871
|
await report(run2, "pane", made.paneId, { sb_role: "tower" });
|
|
26868
26872
|
await o.api("tab.move", { tab_id: made.tabId, insert_index: 0 }).catch((cause) => error("tab-move", cause.message));
|
|
26869
26873
|
log.line("tower-unstowed", { workspace, pane: made.paneId, why: why2 });
|
|
26870
|
-
|
|
26874
|
+
const { stowed: _, ...kept } = record2;
|
|
26875
|
+
return await o.reseat(l, { ...kept, pane: made.paneId, tab: made.tabId, cwd: dir }, true);
|
|
26871
26876
|
} catch (cause) {
|
|
26872
26877
|
undo();
|
|
26873
26878
|
if (made) await run2(["pane", "close", made.paneId]).catch(() => {
|
|
@@ -26881,6 +26886,8 @@ function createStow(o) {
|
|
|
26881
26886
|
return {
|
|
26882
26887
|
look: look2,
|
|
26883
26888
|
open: open9,
|
|
26889
|
+
/** Whether the tower with no pane gets its tab again before a run starts (`reopenGate`). */
|
|
26890
|
+
wants,
|
|
26884
26891
|
start() {
|
|
26885
26892
|
timer ??= setInterval(() => void look2(), t.intervalMs);
|
|
26886
26893
|
timer.unref();
|
|
@@ -27669,7 +27676,7 @@ function createRuns2(o) {
|
|
|
27669
27676
|
const begin = async (svc) => {
|
|
27670
27677
|
if (stopped || svc.run || svc.state !== "standing" || !o.enabled() || !waitingOf(svc).some((e) => !e.quiet)) return;
|
|
27671
27678
|
if (!svc.ref.live()) return;
|
|
27672
|
-
if (!
|
|
27679
|
+
if (!svc.ref.record().pane && (!headlessOn() || svc.ref.viewer?.())) return void svc.ref.seat?.("run");
|
|
27673
27680
|
if (slots >= o.max()) return void blocked.add(svc);
|
|
27674
27681
|
slots++;
|
|
27675
27682
|
svc.state = "waking";
|
|
@@ -27877,7 +27884,7 @@ function createRuns2(o) {
|
|
|
27877
27884
|
for (const { device, items } of devicesWaiting(svc)) {
|
|
27878
27885
|
if (stopped || !o.enabled() || svc.refusedAt !== void 0 && now() - svc.refusedAt < t.refuse) return;
|
|
27879
27886
|
if (!svc.ref.live()) return;
|
|
27880
|
-
if (!
|
|
27887
|
+
if (!svc.ref.record().pane && (!headlessOn() || svc.ref.viewer?.())) return void svc.ref.seat?.("ally");
|
|
27881
27888
|
if (slots >= o.max()) return void blocked.add(svc);
|
|
27882
27889
|
await beginAlly(svc, device, items).catch((cause) => error("ally-begin", cause.message));
|
|
27883
27890
|
}
|
|
@@ -29480,7 +29487,8 @@ function createTowers(o) {
|
|
|
29480
29487
|
},
|
|
29481
29488
|
renewPane: (runId) => renew(l, runId),
|
|
29482
29489
|
renewing: () => l.renewing === true,
|
|
29483
|
-
seat: (why2) => void stow.open(l.record.workspace, why2).catch((cause) => error("tower-seat", cause.message)),
|
|
29490
|
+
seat: (why2) => void stow.open(l.record.workspace, why2).catch((cause) => (error("tower-seat", cause.message), unstow(l))),
|
|
29491
|
+
viewer: () => headless() && tabless(l) && stow.wants(l),
|
|
29484
29492
|
// The run that was shown an expired wait has polled: it will not be shown again (towermemory.ts).
|
|
29485
29493
|
shown: (ids) => {
|
|
29486
29494
|
try {
|
|
@@ -29972,6 +29980,14 @@ function createTowers(o) {
|
|
|
29972
29980
|
else if (l.state === "live") await publish(l);
|
|
29973
29981
|
}
|
|
29974
29982
|
};
|
|
29983
|
+
const unstow = (l) => {
|
|
29984
|
+
if (!headless() || l.stopped || services.get(l.record.workspace) !== l || !l.record.stowed) return;
|
|
29985
|
+
const { stowed: _, ...kept } = l.record;
|
|
29986
|
+
l.record = kept;
|
|
29987
|
+
writeService(slot, kept);
|
|
29988
|
+
log.line("tower-unstow-failed", { workspace: kept.workspace });
|
|
29989
|
+
runs2.poke(kept.workspace);
|
|
29990
|
+
};
|
|
29975
29991
|
const untab = async (l) => {
|
|
29976
29992
|
if (l.stopped || services.get(l.record.workspace) !== l) return;
|
|
29977
29993
|
l.record = { ...l.record, pane: "", tab: "" };
|
|
@@ -30006,6 +30022,7 @@ function createTowers(o) {
|
|
|
30006
30022
|
seat: async (l) => void (l.seated = true, await publish(l)),
|
|
30007
30023
|
hold: (l) => ((was) => (l.state = "registering", l.renewing = true, () => void (l.state = was, l.renewing = false)))(l.state),
|
|
30008
30024
|
headless,
|
|
30025
|
+
attended: () => !o.unattended?.(),
|
|
30009
30026
|
status: (ws) => runs2.status(ws),
|
|
30010
30027
|
queued: (ws) => runs2.queue(ws).filter((e) => !e.quiet).length,
|
|
30011
30028
|
soon: (ws, ms4) => runs2.startsWithin(ws, ms4),
|
|
@@ -30267,7 +30284,8 @@ function createTowers(o) {
|
|
|
30267
30284
|
await report(run2, "pane", tab.paneId, { sb_role: "tower" }).catch(() => {
|
|
30268
30285
|
});
|
|
30269
30286
|
await cfg.api("tab.move", { tab_id: tab.tabId, insert_index: 0 }).catch((cause) => error("tab-move", cause.message));
|
|
30270
|
-
|
|
30287
|
+
const { stowed: _, ...kept } = record2;
|
|
30288
|
+
record2 = { ...kept, pane: tab.paneId, tab: tab.tabId };
|
|
30271
30289
|
}
|
|
30272
30290
|
const l = existing ? await reseat(existing, record2, view) : (writeService(slot, record2), adopt(record2, view, true));
|
|
30273
30291
|
log.line(existing ? "tower-viewer" : "tower-opened", { workspace: ws, id: record2.id, ...view ? { pane: record2.pane, tab: record2.tab } : { tab: "none" } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-straw-boss",
|
|
3
|
-
"version": "0.113.
|
|
3
|
+
"version": "0.113.2",
|
|
4
4
|
"description": "Straw Boss coordination for pi in Herdr: sessions join a tab's net by choice, the first joiner is its main agent, a workspace tower opens on demand with a live monitoring dashboard, and boss_broadcast reaches the rest",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/server/runs.ts
CHANGED
|
@@ -203,6 +203,8 @@ export interface ServiceRef {
|
|
|
203
203
|
renewing?(): boolean;
|
|
204
204
|
/** A service whose pane closed between runs (towerstow.ts) gets it made again before a run starts: once its identity has registered with the new pane, it pokes again. */
|
|
205
205
|
seat?(why: "run" | "ally"): void;
|
|
206
|
+
/** Under headless runs: whether a run waits for the service's viewer to be made again first (a viewer the idle close took, on an attended device; towerstow.ts `reopenGate`). */
|
|
207
|
+
viewer?(): boolean;
|
|
206
208
|
/** The tower's memory in counts for the GUI's snapshot (towermemory.ts). */
|
|
207
209
|
memory?(): MemorySummary;
|
|
208
210
|
}
|
|
@@ -479,7 +481,7 @@ export function createRuns(o: RunsOptions) {
|
|
|
479
481
|
const begin = async (svc: Svc) => {
|
|
480
482
|
if (stopped || svc.run || svc.state !== "standing" || !o.enabled() || !waitingOf(svc).some((e) => !e.quiet)) return;
|
|
481
483
|
if (!svc.ref.live()) return; // the identity registers first: runs reply under it. The service pokes again when it is live.
|
|
482
|
-
if (!
|
|
484
|
+
if (!svc.ref.record().pane && (!headlessOn() || svc.ref.viewer?.())) return void svc.ref.seat?.("run"); // its pane (a headless viewer) closed between runs: made first
|
|
483
485
|
if (slots >= o.max()) return void blocked.add(svc);
|
|
484
486
|
slots++;
|
|
485
487
|
svc.state = "waking";
|
|
@@ -729,7 +731,7 @@ export function createRuns(o: RunsOptions) {
|
|
|
729
731
|
for (const { device, items } of devicesWaiting(svc)) {
|
|
730
732
|
if (stopped || !o.enabled() || svc.refusedAt !== undefined && now() - svc.refusedAt < t.refuse) return;
|
|
731
733
|
if (!svc.ref.live()) return; // the identity registers first; the service pokes again when it is live
|
|
732
|
-
if (!
|
|
734
|
+
if (!svc.ref.record().pane && (!headlessOn() || svc.ref.viewer?.())) return void svc.ref.seat?.("ally"); // the ally pane is split off the standing pane (or the headless viewer comes back), which is made first
|
|
733
735
|
if (slots >= o.max()) return void blocked.add(svc);
|
|
734
736
|
await beginAlly(svc, device, items).catch((cause: Error) => error("ally-begin", cause.message));
|
|
735
737
|
}
|
package/src/server/towers.ts
CHANGED
|
@@ -309,7 +309,8 @@ export function createTowers(o: TowersOptions): Towers {
|
|
|
309
309
|
// The logbook's read mark rides on the digest's keys (`book:<seq>`, this slot's book): a run that ended well read the rows its brief carried.
|
|
310
310
|
clearDigest: async (keys) => { for (const k of keys) if (k.startsWith(BOOK_KEY)) markRead(slot.dir, l.record.workspace, Number(k.slice(BOOK_KEY.length)), now()); await digest.drop(l.record.workspace, keys.filter((k) => !k.startsWith(BOOK_KEY))); },
|
|
311
311
|
renewPane: (runId) => renew(l, runId),
|
|
312
|
-
renewing: () => l.renewing === true, seat: (why) => void stow.open(l.record.workspace, why).catch((cause: Error) => error("tower-seat", cause.message)),
|
|
312
|
+
renewing: () => l.renewing === true, seat: (why) => void stow.open(l.record.workspace, why).catch((cause: Error) => (error("tower-seat", cause.message), unstow(l))),
|
|
313
|
+
viewer: () => headless() && tabless(l) && stow.wants(l),
|
|
313
314
|
// The run that was shown an expired wait has polled: it will not be shown again (towermemory.ts).
|
|
314
315
|
shown: (ids) => { try { markShown(slot, l.record.workspace, now(), ids); } catch (cause) { error("memory", (cause as Error).message); } },
|
|
315
316
|
memory: () => {
|
|
@@ -820,6 +821,15 @@ export function createTowers(o: TowersOptions): Towers {
|
|
|
820
821
|
else if (l.state === "live") await publish(l);
|
|
821
822
|
}
|
|
822
823
|
};
|
|
824
|
+
/** Headless runs: a viewer the idle close took could not be made again; the service stops waiting for one, so its runs start with no tab, and the next look pokes them. */
|
|
825
|
+
const unstow = (l: Live) => {
|
|
826
|
+
if (!headless() || l.stopped || services.get(l.record.workspace) !== l || !l.record.stowed) return;
|
|
827
|
+
const { stowed: _, ...kept } = l.record;
|
|
828
|
+
l.record = kept;
|
|
829
|
+
writeService(slot, kept);
|
|
830
|
+
log.line("tower-unstow-failed", { workspace: kept.workspace });
|
|
831
|
+
runs.poke(kept.workspace);
|
|
832
|
+
};
|
|
823
833
|
/** Headless runs: the service's viewer pane is gone, and the service goes on with no tab. The identity registers again with no pane, as after a move (`tower-found`). */
|
|
824
834
|
const untab = async (l: Live) => {
|
|
825
835
|
if (l.stopped || services.get(l.record.workspace) !== l) return;
|
|
@@ -833,7 +843,7 @@ export function createTowers(o: TowersOptions): Towers {
|
|
|
833
843
|
const reseat = async (l: Live, record: ServiceRecord, fresh: boolean): Promise<Live> => { l.record = record; writeService(slot, record); await release(l); await standing.detach(record.workspace); if (services.get(record.workspace) === l) services.delete(record.workspace); return adopt(record, fresh, true); };
|
|
834
844
|
const stow = createStow<Live>({ run, api: cfg.api, log, now, stateDir: slot.stateDir, ...(o.stow ? { timers: o.stow } : {}), list: () => [...services.values()].filter((l) => !l.stopped), current: (ws) => ((l) => (l && !l.stopped ? l : undefined))(services.get(ws)), record: (l) => l.record, place: (l, record) => void (l.record = record), head: isHeadL, seated: (l) => l.seated, recovering: () => now() < recoverUntil,
|
|
835
845
|
ready: (l) => l.state === "live" && l.seated && !l.stopped && !l.renewing && Boolean(l.client?.isConnected()), seat: async (l) => void ((l.seated = true), await publish(l)), hold: (l) => ((was) => ((l.state = "registering"), (l.renewing = true), () => void ((l.state = was), (l.renewing = false))))(l.state),
|
|
836
|
-
headless, status: (ws) => runs.status(ws), queued: (ws) => runs.queue(ws).filter((e) => !e.quiet).length, soon: (ws, ms) => runs.startsWithin(ws, ms), cards: (l) => cardsFor(l), prompt: (ws) => standing.here(ws), reseat, lose });
|
|
846
|
+
headless, attended: () => !o.unattended?.(), status: (ws) => runs.status(ws), queued: (ws) => runs.queue(ws).filter((e) => !e.quiet).length, soon: (ws, ms) => runs.startsWithin(ws, ms), cards: (l) => cardsFor(l), prompt: (ws) => standing.here(ws), reseat, lose });
|
|
837
847
|
|
|
838
848
|
// --- the start ------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
839
849
|
|
|
@@ -1130,7 +1140,8 @@ export function createTowers(o: TowersOptions): Towers {
|
|
|
1130
1140
|
const tab = await createTab(run, ws, record.cwd ?? slot.stateDir, [], TOWER_LABEL);
|
|
1131
1141
|
await report(run, "pane", tab.paneId, { sb_role: "tower" }).catch(() => {});
|
|
1132
1142
|
await cfg.api("tab.move", { tab_id: tab.tabId, insert_index: 0 }).catch((cause: Error) => error("tab-move", cause.message));
|
|
1133
|
-
|
|
1143
|
+
const { stowed: _, ...kept } = record;
|
|
1144
|
+
record = { ...kept, pane: tab.paneId, tab: tab.tabId };
|
|
1134
1145
|
}
|
|
1135
1146
|
const l = existing ? await reseat(existing, record, view) : (writeService(slot, record), adopt(record, view, true));
|
|
1136
1147
|
log.line(existing ? "tower-viewer" : "tower-opened", { workspace: ws, id: record.id, ...(view ? { pane: record.pane, tab: record.tab } : { tab: "none" }) });
|
package/src/server/towerstore.ts
CHANGED
|
@@ -34,6 +34,8 @@ export interface ServiceRecord {
|
|
|
34
34
|
waiting?: true;
|
|
35
35
|
/** `head` for the head tower's service (its workspace is the head workspace, its folder `head/`); absent for a workspace tower. */
|
|
36
36
|
kind?: "head";
|
|
37
|
+
/** The idle close took the pane (towerstow.ts): under headless runs only such a viewer comes back, as a fresh one. Dropped when a pane is made again. */
|
|
38
|
+
stowed?: true;
|
|
37
39
|
}
|
|
38
40
|
/** What wakes a run (the spec, Wake triggers): an intercom message, the boss typing into the tower, a notice the server raises, a follow-up the last run asked for. */
|
|
39
41
|
/** `link` is a teammate's message an ally run was given: it lives in the link inbox, never in this queue. */
|
package/src/server/towerstow.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { nameOf, SHELLS } from "./typegate.ts";
|
|
|
8
8
|
// is live, nothing waits to wake one, no card of the tower waits, and that has held for `idleMs`, the pane closes (only the pane: Herdr drops the emptied tab itself) and the service goes on with no pane, as a headless
|
|
9
9
|
// service does: its identity stays registered and its token written, so mains still reach it. The next run, ally run, card, or ensure-tower makes the tab again, as the first open made it.
|
|
10
10
|
// What keeps the pane is decided here alone (`idleGate`, `paneGate`, `seatOpen`; their table test is tests/towerstow.test.ts); the look gathers the facts and acts on the answer.
|
|
11
|
+
// Under headless runs (`towerRuns.headless`) the pane is the service's viewer and the same rules close it; it comes back as a fresh viewer only when the idle close took it (`stowed` on the record), and only on an attended
|
|
12
|
+
// device (`reopenGate`): a service of headless runs needs no tab, and a viewer the boss ended himself stays ended.
|
|
11
13
|
// The head tower's pane is never closed: it is its workspace's only pane, so closing it would close the head workspace and take the head's record with it (`lose`). A pane that is the last of its workspace is kept for the
|
|
12
14
|
// same reason: the queue, the memory, and the ledgers are kept under the workspace's id, which a workspace made again does not get.
|
|
13
15
|
|
|
@@ -20,14 +22,12 @@ export interface StowTimers {
|
|
|
20
22
|
export const STOW: StowTimers = { intervalMs: 3000, idleMs: 30_000 };
|
|
21
23
|
|
|
22
24
|
/** Why a standing pane stays. */
|
|
23
|
-
export type Keep = "head" | "
|
|
25
|
+
export type Keep = "head" | "unready" | "cards" | "run" | "held" | "queued" | "soon" | "recent" | "gone" | "agent" | "tab" | "last" | "parked" | "prompt" | "draft" | "program" | "unknown";
|
|
24
26
|
export type StowVerdict = { stow: true } | { stow: false; why: Keep };
|
|
25
27
|
const keep = (why: Keep): StowVerdict => ({ stow: false, why });
|
|
26
28
|
|
|
27
29
|
export interface IdleFacts {
|
|
28
30
|
head: boolean;
|
|
29
|
-
/** `towerRuns.headless`: a viewer has its own life (it ends by itself). */
|
|
30
|
-
headless: boolean;
|
|
31
31
|
/** The identity is registered, the seat proven, and no pane change is under way. */
|
|
32
32
|
ready: boolean;
|
|
33
33
|
/** The tower's own wait cards that wait for the boss. */
|
|
@@ -45,7 +45,6 @@ export interface IdleFacts {
|
|
|
45
45
|
/** The facts of the service, cheap to read: asked before the pane's facts, which cost Herdr calls. */
|
|
46
46
|
export function idleGate(f: IdleFacts): StowVerdict {
|
|
47
47
|
if (f.head) return keep("head");
|
|
48
|
-
if (f.headless) return keep("headless");
|
|
49
48
|
if (!f.ready) return keep("unready");
|
|
50
49
|
if (f.cards > 0) return keep("cards");
|
|
51
50
|
if (f.run || f.state === "waking" || f.state === "running" || f.state === "closing") return keep("run");
|
|
@@ -89,6 +88,11 @@ export function foregroundOf(info: { shell_pid?: unknown; foreground_processes?:
|
|
|
89
88
|
return list.every((p) => (shell !== undefined ? p.pid === shell : list.length === 1 && SHELLS.has(nameOf(p))) || (promptPid !== undefined && p.pid === promptPid) || prompt.test(p.cmdline ?? "")) ? "clean" : "program";
|
|
90
89
|
}
|
|
91
90
|
|
|
91
|
+
/** Whether a tower with no pane gets its tab again (before a run or an ally run, for a card): a standing pane always does; under headless runs only a viewer the idle close took (`stowed`), and only where the boss is. */
|
|
92
|
+
export function reopenGate(f: { headless: boolean; stowed: boolean; attended: boolean }): boolean {
|
|
93
|
+
return !f.headless || (f.stowed && f.attended);
|
|
94
|
+
}
|
|
95
|
+
|
|
92
96
|
/** Whether a tower with no pane may make its tab in the workspace under its id: after a Herdr restart (`seated` false) only one that still carries the label it had is its own (ids repeat across Herdr servers). */
|
|
93
97
|
export function seatOpen(f: { seated: boolean; label: string | undefined; record: string }): "open" | "stranger" | "gone" {
|
|
94
98
|
if (f.label === undefined) return "gone";
|
|
@@ -118,6 +122,8 @@ export interface StowPort<L> {
|
|
|
118
122
|
/** The service is not live while its pane changes (no run begins, no pi is admitted); returns the undo. */
|
|
119
123
|
hold(l: L): () => void;
|
|
120
124
|
headless(): boolean;
|
|
125
|
+
/** A boss is at this device (no `unattended` box): only there does a headless viewer come back. */
|
|
126
|
+
attended(): boolean;
|
|
121
127
|
status(workspace: string): ServiceStatus | undefined;
|
|
122
128
|
queued(workspace: string): number;
|
|
123
129
|
soon(workspace: string, ms: number): boolean;
|
|
@@ -139,8 +145,9 @@ export function createStow<L>(o: StowPort<L>) {
|
|
|
139
145
|
const processInfo = (pane: string) => run(["pane", "process-info", "--pane", pane]).then((x) => JSON.parse(x).result?.process_info, () => undefined);
|
|
140
146
|
const idleOf = (l: L, at: number) => {
|
|
141
147
|
const ws = o.record(l).workspace, status = o.status(ws), from = since.get(ws);
|
|
142
|
-
return idleGate({ head: o.head(l),
|
|
148
|
+
return idleGate({ head: o.head(l), ready: o.ready(l), cards: o.cards(l), state: status?.state, run: Boolean(status?.run) || (status?.allyRuns.length ?? 0) > 0, queued: o.queued(ws), soon: o.soon(ws, t.idleMs), idleFor: from ? at - from.at : 0, idleMs: t.idleMs });
|
|
143
149
|
};
|
|
150
|
+
const wants = (l: L) => reopenGate({ headless: o.headless(), stowed: o.record(l).stowed === true, attended: o.attended() });
|
|
144
151
|
const said1 = (ws: string, why: Keep) => {
|
|
145
152
|
if (said.get(ws) === why) return;
|
|
146
153
|
said.set(ws, why);
|
|
@@ -150,7 +157,7 @@ export function createStow<L>(o: StowPort<L>) {
|
|
|
150
157
|
/** The pane closes and the service goes on with no pane. Every fact is asked again after the last await; a close Herdr refuses leaves everything as it was. */
|
|
151
158
|
const close = async (l: L, record: ServiceRecord) => {
|
|
152
159
|
const ws = record.workspace, undo = o.hold(l);
|
|
153
|
-
const bare: ServiceRecord = { ...record, pane: "", tab: "" };
|
|
160
|
+
const bare: ServiceRecord = { ...record, pane: "", tab: "", stowed: true };
|
|
154
161
|
o.place(l, bare);
|
|
155
162
|
try {
|
|
156
163
|
await run(["pane", "close", record.pane]);
|
|
@@ -166,8 +173,9 @@ export function createStow<L>(o: StowPort<L>) {
|
|
|
166
173
|
};
|
|
167
174
|
const lookAt = async (l: L) => {
|
|
168
175
|
const record = o.record(l), ws = record.workspace;
|
|
169
|
-
if (o.head(l) ||
|
|
176
|
+
if (o.head(l) || opening.has(ws)) return;
|
|
170
177
|
if (!record.pane) {
|
|
178
|
+
if (!wants(l)) return; // a service of headless runs with no viewer, or one the boss ended: nothing to bring back
|
|
171
179
|
// A service seated before a Herdr restart is seated again by its workspace's label: its token is written again, and a card or a run makes its tab. A workspace under its id with another label is a stranger's, once the minute is over.
|
|
172
180
|
if (!o.seated(l)) {
|
|
173
181
|
const listed = await workspaces(run).catch(() => undefined), seat = listed && seatOpen({ seated: false, label: listed.find((w) => w.workspace_id === ws)?.label, record: record.label });
|
|
@@ -221,7 +229,8 @@ export function createStow<L>(o: StowPort<L>) {
|
|
|
221
229
|
await report(run, "pane", made.paneId, { sb_role: "tower" });
|
|
222
230
|
await o.api("tab.move", { tab_id: made.tabId, insert_index: 0 }).catch((cause: Error) => error("tab-move", cause.message));
|
|
223
231
|
log.line("tower-unstowed", { workspace, pane: made.paneId, why });
|
|
224
|
-
|
|
232
|
+
const { stowed: _, ...kept } = record;
|
|
233
|
+
return await o.reseat(l, { ...kept, pane: made.paneId, tab: made.tabId, cwd: dir }, true);
|
|
225
234
|
} catch (cause) {
|
|
226
235
|
undo();
|
|
227
236
|
if (made) await run(["pane", "close", made.paneId]).catch(() => {}); // the pane it made, never the tab
|
|
@@ -235,6 +244,8 @@ export function createStow<L>(o: StowPort<L>) {
|
|
|
235
244
|
return {
|
|
236
245
|
look,
|
|
237
246
|
open,
|
|
247
|
+
/** Whether the tower with no pane gets its tab again before a run starts (`reopenGate`). */
|
|
248
|
+
wants,
|
|
238
249
|
start() {
|
|
239
250
|
timer ??= setInterval(() => void look(), t.intervalMs);
|
|
240
251
|
timer.unref();
|