pi-straw-boss 0.116.2 → 0.116.3
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 +30 -13
- package/package.json +1 -1
- package/src/link/store.ts +20 -7
- package/src/server/towers.ts +7 -7
- package/src/server/towerstow.ts +10 -0
package/dist/server/main.mjs
CHANGED
|
@@ -1379,7 +1379,7 @@ var LinkElection = class {
|
|
|
1379
1379
|
// src/link/store.ts
|
|
1380
1380
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1381
1381
|
import { randomBytes as randomBytes2, randomUUID } from "node:crypto";
|
|
1382
|
-
import { appendFileSync, chmodSync as chmodSync2, closeSync, existsSync as existsSync2, fsyncSync, mkdirSync as mkdirSync2, openSync, readdirSync, readFileSync as readFileSync3, renameSync as renameSync2, rmSync, statSync as statSync2, utimesSync, writeFileSync as writeFileSync2, writeSync } from "node:fs";
|
|
1382
|
+
import { appendFileSync, chmodSync as chmodSync2, closeSync, existsSync as existsSync2, fsyncSync, linkSync, mkdirSync as mkdirSync2, openSync, readdirSync, readFileSync as readFileSync3, renameSync as renameSync2, rmSync, statSync as statSync2, utimesSync, writeFileSync as writeFileSync2, writeSync } from "node:fs";
|
|
1383
1383
|
import { hostname } from "node:os";
|
|
1384
1384
|
import { dirname as dirname3, join as join5 } from "node:path";
|
|
1385
1385
|
var LOCK_STALE_MS = 1e4;
|
|
@@ -1562,12 +1562,7 @@ var LinkStore = class {
|
|
|
1562
1562
|
this.ensure();
|
|
1563
1563
|
const token = randomUUID(), end = Date.now() + waitMs;
|
|
1564
1564
|
for (; ; ) {
|
|
1565
|
-
|
|
1566
|
-
writeFileSync2(this.lock, JSON.stringify({ pid: process.pid, ...this.started() ? { started: this.started() } : {}, token, t: this.now() }), { flag: "wx", mode: 384 });
|
|
1567
|
-
return token;
|
|
1568
|
-
} catch (error) {
|
|
1569
|
-
if (error.code !== "EEXIST") throw error;
|
|
1570
|
-
}
|
|
1565
|
+
if (this.create(JSON.stringify({ pid: process.pid, ...this.started() ? { started: this.started() } : {}, token, t: this.now() }), token)) return token;
|
|
1571
1566
|
const stale = this.stale();
|
|
1572
1567
|
if (stale !== void 0) {
|
|
1573
1568
|
this.breakStale(stale);
|
|
@@ -1577,6 +1572,24 @@ var LinkStore = class {
|
|
|
1577
1572
|
await new Promise((r) => setTimeout(r, 10 + Math.floor(Math.random() * 20)));
|
|
1578
1573
|
}
|
|
1579
1574
|
}
|
|
1575
|
+
/**
|
|
1576
|
+
* Makes the lock file whole or not at all: the text goes into a file of this call's own, which is then linked under the lock's name (a link fails when the name is taken). Created with `wx` and written after, a lock
|
|
1577
|
+
* whose process was killed in between (SIGKILL, or pi ended) was an empty file, which stands as one being written until it is `staleMs` old: the next holder waited 10 s (link-holder-live under load). A kill here
|
|
1578
|
+
* leaves at most the temp file, as `write` does.
|
|
1579
|
+
*/
|
|
1580
|
+
create(text14, token) {
|
|
1581
|
+
const temp = `${this.lock}.${process.pid}.${token.slice(0, 8)}.tmp`;
|
|
1582
|
+
writeFileSync2(temp, text14, { flag: "wx", mode: 384 });
|
|
1583
|
+
try {
|
|
1584
|
+
linkSync(temp, this.lock);
|
|
1585
|
+
return true;
|
|
1586
|
+
} catch (error) {
|
|
1587
|
+
if (error.code !== "EEXIST") throw error;
|
|
1588
|
+
return false;
|
|
1589
|
+
} finally {
|
|
1590
|
+
rmSync(temp, { force: true });
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1580
1593
|
started() {
|
|
1581
1594
|
return this.ownStart ??= this.start(process.pid);
|
|
1582
1595
|
}
|
|
@@ -5866,7 +5879,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5866
5879
|
|
|
5867
5880
|
// src/stash.ts
|
|
5868
5881
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
5869
|
-
import { existsSync as existsSync4, linkSync, mkdirSync as mkdirSync6, readdirSync as readdirSync5, readFileSync as readFileSync14, renameSync as renameSync5, rmSync as rmSync4, statSync as statSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
5882
|
+
import { existsSync as existsSync4, linkSync as linkSync2, mkdirSync as mkdirSync6, readdirSync as readdirSync5, readFileSync as readFileSync14, renameSync as renameSync5, rmSync as rmSync4, statSync as statSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
5870
5883
|
import { dirname as dirname6, join as join21 } from "node:path";
|
|
5871
5884
|
var ROLES2 = /* @__PURE__ */ new Set(["tower", "main", "member"]);
|
|
5872
5885
|
var SETTLED = /* @__PURE__ */ new Set(["idle", "done"]);
|
|
@@ -6070,7 +6083,7 @@ async function popBase(d, name2) {
|
|
|
6070
6083
|
return r;
|
|
6071
6084
|
} catch (error) {
|
|
6072
6085
|
const back = existsSync4(stashFile(d.stateDir, name2)) ? nameFor(name2, d.stateDir) : name2;
|
|
6073
|
-
|
|
6086
|
+
linkSync2(claimed2, stashFile(d.stateDir, back));
|
|
6074
6087
|
rmSync4(claimed2, { force: true });
|
|
6075
6088
|
throw back === name2 ? error : new Error(`${error.message}; it is stashed again as "${back}", since "${name2}" was taken meanwhile`);
|
|
6076
6089
|
}
|
|
@@ -26999,6 +27012,10 @@ function foregroundOf(info, workspace, promptPid) {
|
|
|
26999
27012
|
function reopenGate(f) {
|
|
27000
27013
|
return !f.headless || f.stowed && f.attended;
|
|
27001
27014
|
}
|
|
27015
|
+
function viewerGate(f) {
|
|
27016
|
+
if (f.service === "tab" || f.asked === false) return false;
|
|
27017
|
+
return f.asked === true || f.attended && f.service === "none";
|
|
27018
|
+
}
|
|
27002
27019
|
function seatOpen(f) {
|
|
27003
27020
|
if (f.label === void 0) return "gone";
|
|
27004
27021
|
return f.seated || f.label === f.record ? "open" : "stranger";
|
|
@@ -30491,9 +30508,9 @@ function createTowers(o) {
|
|
|
30491
30508
|
await Promise.race([l.starting, sleep2(o.registerMs ?? REGISTER_WAIT_MS)]);
|
|
30492
30509
|
return answer(l, true);
|
|
30493
30510
|
};
|
|
30494
|
-
const openHeadless = async (target2, existing, cwd,
|
|
30495
|
-
const ws = target2.workspace_id;
|
|
30496
|
-
if (existing &&
|
|
30511
|
+
const openHeadless = async (target2, existing, cwd, asked3) => {
|
|
30512
|
+
const ws = target2.workspace_id, view = viewerGate({ asked: asked3, attended: !o.unattended?.(), service: !existing ? "none" : tabless(existing) ? "tabless" : "tab" });
|
|
30513
|
+
if (existing && !view) {
|
|
30497
30514
|
if (existing.state !== "waiting") await Promise.race([existing.starting, sleep2(o.registerMs ?? REGISTER_WAIT_MS)]);
|
|
30498
30515
|
return answer(existing, false);
|
|
30499
30516
|
}
|
|
@@ -30522,7 +30539,7 @@ function createTowers(o) {
|
|
|
30522
30539
|
const target2 = isSub(asked3) ? parentOf(all, asked3) : asked3;
|
|
30523
30540
|
if (!target2) throw new Error(`${asked3.label} is a sub workspace with no open parent workspace, so it has no tower; open the parent workspace first`);
|
|
30524
30541
|
if (isHead(target2) || headLive()?.record.workspace === target2.workspace_id) throw new Error(`${target2.label} is the head tower's workspace: it has no workspace tower, the head tower is its own`);
|
|
30525
|
-
const pending = opening3.get(target2.workspace_id) ?? openFor(target2, target2 === asked3 ? pane : void 0, cwd, pid, target2 === asked3 ? made : void 0, view
|
|
30542
|
+
const pending = opening3.get(target2.workspace_id) ?? openFor(target2, target2 === asked3 ? pane : void 0, cwd, pid, target2 === asked3 ? made : void 0, view ?? false).finally(() => opening3.delete(target2.workspace_id));
|
|
30526
30543
|
opening3.set(target2.workspace_id, pending);
|
|
30527
30544
|
return pending;
|
|
30528
30545
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-straw-boss",
|
|
3
|
-
"version": "0.116.
|
|
3
|
+
"version": "0.116.3",
|
|
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/link/store.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
2
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
3
|
-
import { appendFileSync, chmodSync, closeSync, existsSync, fsyncSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, statSync, utimesSync, writeFileSync, writeSync } from "node:fs";
|
|
3
|
+
import { appendFileSync, chmodSync, closeSync, existsSync, fsyncSync, linkSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, statSync, utimesSync, writeFileSync, writeSync } from "node:fs";
|
|
4
4
|
import { hostname } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
import { startOf } from "../startof.ts";
|
|
@@ -298,12 +298,7 @@ export class LinkStore {
|
|
|
298
298
|
this.ensure();
|
|
299
299
|
const token = randomUUID(), end = Date.now() + waitMs;
|
|
300
300
|
for (;;) {
|
|
301
|
-
|
|
302
|
-
writeFileSync(this.lock, JSON.stringify({ pid: process.pid, ...(this.started() ? { started: this.started() } : {}), token, t: this.now() }), { flag: "wx", mode: 0o600 });
|
|
303
|
-
return token;
|
|
304
|
-
} catch (error) {
|
|
305
|
-
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
306
|
-
}
|
|
301
|
+
if (this.create(JSON.stringify({ pid: process.pid, ...(this.started() ? { started: this.started() } : {}), token, t: this.now() }), token)) return token;
|
|
307
302
|
const stale = this.stale();
|
|
308
303
|
if (stale !== undefined) {
|
|
309
304
|
this.breakStale(stale);
|
|
@@ -313,6 +308,24 @@ export class LinkStore {
|
|
|
313
308
|
await new Promise((r) => setTimeout(r, 10 + Math.floor(Math.random() * 20)));
|
|
314
309
|
}
|
|
315
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Makes the lock file whole or not at all: the text goes into a file of this call's own, which is then linked under the lock's name (a link fails when the name is taken). Created with `wx` and written after, a lock
|
|
313
|
+
* whose process was killed in between (SIGKILL, or pi ended) was an empty file, which stands as one being written until it is `staleMs` old: the next holder waited 10 s (link-holder-live under load). A kill here
|
|
314
|
+
* leaves at most the temp file, as `write` does.
|
|
315
|
+
*/
|
|
316
|
+
private create(text: string, token: string): boolean {
|
|
317
|
+
const temp = `${this.lock}.${process.pid}.${token.slice(0, 8)}.tmp`;
|
|
318
|
+
writeFileSync(temp, text, { flag: "wx", mode: 0o600 });
|
|
319
|
+
try {
|
|
320
|
+
linkSync(temp, this.lock);
|
|
321
|
+
return true;
|
|
322
|
+
} catch (error) {
|
|
323
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
324
|
+
return false;
|
|
325
|
+
} finally {
|
|
326
|
+
rmSync(temp, { force: true });
|
|
327
|
+
}
|
|
328
|
+
}
|
|
316
329
|
private started(): string | undefined {
|
|
317
330
|
return (this.ownStart ??= this.start(process.pid)); // not kept while unknown: on Windows it arrives from a background read
|
|
318
331
|
}
|
package/src/server/towers.ts
CHANGED
|
@@ -32,7 +32,7 @@ import { runApprover } from "./runapprove.ts";
|
|
|
32
32
|
import type { Asks } from "./asks.ts";
|
|
33
33
|
import { ageOf, allyTools, briefOf, buildAllyBrief, gatherMains, heldFlag, localTools } from "./towerbrief.ts";
|
|
34
34
|
import { createStanding, type PromptReply, type StandingTimers } from "./standing.ts";
|
|
35
|
-
import { createStow, type StowTimers } from "./towerstow.ts";
|
|
35
|
+
import { createStow, type StowTimers, viewerGate } from "./towerstow.ts";
|
|
36
36
|
import { createKids, type KidsPort } from "./runkids.ts";
|
|
37
37
|
import { resolvePi } from "./runchild.ts";
|
|
38
38
|
import { digestOf, headLabel, openCards, type WaitDigest, type WaitList, waitList, waitRows } from "./waitlist.ts";
|
|
@@ -1048,7 +1048,7 @@ export function createTowers(o: TowersOptions): Towers {
|
|
|
1048
1048
|
return { base, bare: base && here[0]!.tokens?.sb_role === "tower" && !here[0]!.agent, terminal: base ? here[0]!.terminal_id : undefined };
|
|
1049
1049
|
};
|
|
1050
1050
|
|
|
1051
|
-
const openFor = async (target: Workspace, hint: string | undefined, cwd: string | undefined, handedBy?: number, claim?: { pane: string; at: number }, view = false): Promise<Ensured> => {
|
|
1051
|
+
const openFor = async (target: Workspace, hint: string | undefined, cwd: string | undefined, handedBy?: number, claim?: { pane: string; at: number }, view: boolean | "attended" = false): Promise<Ensured> => {
|
|
1052
1052
|
const ws = target.workspace_id;
|
|
1053
1053
|
let existing = services.get(ws);
|
|
1054
1054
|
// Headless runs (docs/specs/2026-11-23-f-entry.md §2.2): the service needs no tab. A tab is made only when a viewer is asked for, and only where none stands; nothing else here types into or marks a pane.
|
|
@@ -1127,10 +1127,10 @@ export function createTowers(o: TowersOptions): Towers {
|
|
|
1127
1127
|
return answer(l, true);
|
|
1128
1128
|
};
|
|
1129
1129
|
|
|
1130
|
-
/** The headless `ensure`: a service with no tab, and a viewer tab
|
|
1131
|
-
const openHeadless = async (target: Workspace, existing: Live | undefined, cwd: string | undefined,
|
|
1132
|
-
const ws = target.workspace_id;
|
|
1133
|
-
if (existing &&
|
|
1130
|
+
/** The headless `ensure`: a service with no tab, and a viewer tab when towerstow.ts `viewerGate` says so. The tab this call makes is typed into once (standing.ts, typegate.ts `onceGate`). */
|
|
1131
|
+
const openHeadless = async (target: Workspace, existing: Live | undefined, cwd: string | undefined, asked: boolean | "attended"): Promise<Ensured> => {
|
|
1132
|
+
const ws = target.workspace_id, view = viewerGate({ asked, attended: !o.unattended?.(), service: !existing ? "none" : tabless(existing) ? "tabless" : "tab" });
|
|
1133
|
+
if (existing && !view) {
|
|
1134
1134
|
if (existing.state !== "waiting") await Promise.race([existing.starting, sleep(o.registerMs ?? REGISTER_WAIT_MS)]);
|
|
1135
1135
|
return answer(existing, false);
|
|
1136
1136
|
}
|
|
@@ -1160,7 +1160,7 @@ export function createTowers(o: TowersOptions): Towers {
|
|
|
1160
1160
|
const target = isSub(asked) ? parentOf(all, asked) : asked;
|
|
1161
1161
|
if (!target) throw new Error(`${asked.label} is a sub workspace with no open parent workspace, so it has no tower; open the parent workspace first`);
|
|
1162
1162
|
if (isHead(target) || headLive()?.record.workspace === target.workspace_id) throw new Error(`${target.label} is the head tower's workspace: it has no workspace tower, the head tower is its own`);
|
|
1163
|
-
const pending = opening.get(target.workspace_id) ?? openFor(target, target === asked ? pane : undefined, cwd, pid, target === asked ? made : undefined, view
|
|
1163
|
+
const pending = opening.get(target.workspace_id) ?? openFor(target, target === asked ? pane : undefined, cwd, pid, target === asked ? made : undefined, view ?? false).finally(() => opening.delete(target.workspace_id));
|
|
1164
1164
|
opening.set(target.workspace_id, pending);
|
|
1165
1165
|
return pending;
|
|
1166
1166
|
};
|
package/src/server/towerstow.ts
CHANGED
|
@@ -93,6 +93,16 @@ export function reopenGate(f: { headless: boolean; stowed: boolean; attended: bo
|
|
|
93
93
|
return !f.headless || (f.stowed && f.attended);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Whether a headless `ensure-tower` makes a viewer tab. The boss's own Open viewer (`view: true`) makes one wherever the service has none; an attended session's plain ensure (`"attended"`: a promotion, a main's call)
|
|
98
|
+
* makes one only with the service it makes. A service that stands with no tab (a viewer the idle close took, or one the boss ended) gets a viewer back by `reopenGate` alone: a plain ensure that came while the identity
|
|
99
|
+
* registered again after the idle close (seen 2026-11-28 06:41:36) would make a viewer the idle close takes again half a minute later.
|
|
100
|
+
*/
|
|
101
|
+
export function viewerGate(f: { asked: boolean | "attended"; attended: boolean; service: "none" | "tabless" | "tab" }): boolean {
|
|
102
|
+
if (f.service === "tab" || f.asked === false) return false;
|
|
103
|
+
return f.asked === true || (f.attended && f.service === "none");
|
|
104
|
+
}
|
|
105
|
+
|
|
96
106
|
/** 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). */
|
|
97
107
|
export function seatOpen(f: { seated: boolean; label: string | undefined; record: string }): "open" | "stranger" | "gone" {
|
|
98
108
|
if (f.label === undefined) return "gone";
|