pi-straw-boss 0.116.1 → 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 +39 -20
- package/package.json +1 -1
- package/src/askclient.ts +1 -1
- package/src/askrows.ts +3 -3
- package/src/asktypes.ts +4 -2
- package/src/bossask.ts +4 -2
- package/src/carrows.ts +14 -4
- package/src/dialogs.ts +1 -1
- package/src/items.ts +2 -1
- package/src/link/store.ts +20 -7
- package/src/server/askmirror.ts +4 -3
- package/src/server/askops.ts +3 -2
- package/src/server/towers.ts +7 -7
- package/src/server/towerstow.ts +10 -0
- package/src/todo.ts +7 -6
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
|
}
|
|
@@ -6309,8 +6322,8 @@ var FULL = 1 << 20;
|
|
|
6309
6322
|
var TEXT = 1e5;
|
|
6310
6323
|
var LAST_BYTES = 65536;
|
|
6311
6324
|
var FULL_LIMIT = FULL;
|
|
6312
|
-
var STATUSES2 = /* @__PURE__ */ new Set(["pending", "in_progress", "completed"]);
|
|
6313
6325
|
var UID = /^t_[a-z2-7]{10}$/;
|
|
6326
|
+
var STATUSES2 = /* @__PURE__ */ new Set(["pending", "in_progress", "completed"]);
|
|
6314
6327
|
var AGENT = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/;
|
|
6315
6328
|
var obj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
6316
6329
|
var cut3 = (v, n) => typeof v === "string" && v ? v.slice(0, n) : void 0;
|
|
@@ -7164,12 +7177,13 @@ var RUNS_MAX = 64;
|
|
|
7164
7177
|
var todoOk = (v) => {
|
|
7165
7178
|
const t = v;
|
|
7166
7179
|
const count4 = (n) => Number.isSafeInteger(n) && n >= 0 && n <= 200;
|
|
7180
|
+
const uid2 = (s2) => typeof s2 === "string" && UID.test(s2);
|
|
7167
7181
|
const plain5 = (s2, max) => typeof s2 === "string" && s2.length > 0 && s2.length <= max && !/[\p{Cc}\p{Cf}]/u.test(s2);
|
|
7168
7182
|
const step = (r) => {
|
|
7169
7183
|
const x = r;
|
|
7170
7184
|
return x !== null && typeof x === "object" && Object.keys(x).every((k) => ["id", "kind", "status", "name", "round", "outcome"].includes(k)) && Number.isSafeInteger(x.id) && x.id >= 1 && plain5(x.kind, 32) && ["pending", "in_progress", "completed"].includes(x.status) && (x.name === void 0 || plain5(x.name, 64)) && (x.round === void 0 || Number.isSafeInteger(x.round) && x.round >= 1) && (x.outcome === void 0 || ["passed", "failed", "void"].includes(x.outcome));
|
|
7171
7185
|
};
|
|
7172
|
-
return t !== null && typeof t === "object" && count4(t.done) && count4(t.total) && t.done <= t.total && t.total > 0 && (t.now === void 0 || plain5(t.now, TODO_TEXT)) && (t.steps === void 0 || Array.isArray(t.steps) && t.steps.length <= 200 && t.steps.every(step)) && (t.graph === void 0 || GRAPHS.includes(t.graph)) && (t.doing === void 0 || Number.isSafeInteger(t.doing) && t.doing >= 0) && (t.runs === void 0 || Array.isArray(t.runs) && t.runs.length <= RUNS_MAX && t.runs.every((r) => Number.isSafeInteger(r?.id) && plain5(r.run, 64)));
|
|
7186
|
+
return t !== null && typeof t === "object" && count4(t.done) && count4(t.total) && t.done <= t.total && t.total > 0 && (t.now === void 0 || plain5(t.now, TODO_TEXT)) && (t.steps === void 0 || Array.isArray(t.steps) && t.steps.length <= 200 && t.steps.every(step)) && (t.graph === void 0 || GRAPHS.includes(t.graph)) && (t.doing === void 0 || Number.isSafeInteger(t.doing) && t.doing >= 0) && (t.doingUid === void 0 || uid2(t.doingUid)) && (t.runs === void 0 || Array.isArray(t.runs) && t.runs.length <= RUNS_MAX && t.runs.every((r) => Number.isSafeInteger(r?.id) && plain5(r.run, 64) && (r.uid === void 0 || uid2(r.uid))));
|
|
7173
7187
|
};
|
|
7174
7188
|
|
|
7175
7189
|
// src/dialogs.ts
|
|
@@ -7278,7 +7292,7 @@ function createHub(pi, me, local, onAllow) {
|
|
|
7278
7292
|
const docs = msg.type === "dialogs" && (msg.documents === void 0 ? [] : docsOf({ version: 1, documents: msg.documents }));
|
|
7279
7293
|
const queued = msg.type === "dialogs" && Array.isArray(msg.queued) && msg.queued.length <= MAX_QUEUED && msg.queued.every((q2) => typeof q2?.text === "string" && q2.text.length <= QUEUED_TEXT && (q2.as === "steer" || q2.as === "followUp")) ? msg.queued.map(({ text: text14, as }) => ({ text: text14, as })) : void 0;
|
|
7280
7294
|
const monitors = msg.type === "dialogs" && monitorsOk(msg.monitors) ? msg.monitors.map(({ id: id2, what, status, exit, last, load: load3, lines, at, ended }) => ({ id: id2, what, status, exit, last, load: load3, lines, at, ended })) : void 0;
|
|
7281
|
-
const todo = msg.type === "dialogs" && todoOk(msg.todo) ? { done: msg.todo.done, total: msg.todo.total, ...msg.todo.now && { now: msg.todo.now }, ...msg.todo.graph && { graph: msg.todo.graph }, ...msg.todo.doing !== void 0 && { doing: msg.todo.doing }, ...msg.todo.runs && { runs: msg.todo.runs.map(({ id: id2, run: run2 }) => ({ id: id2, run: run2 })) }, ...msg.todo.steps && { steps: msg.todo.steps.map(({ id: id2, kind, status, name: name2, round: round2, outcome }) => ({ id: id2, kind, status, ...name2 !== void 0 && { name: name2 }, ...round2 !== void 0 && { round: round2 }, ...outcome && { outcome } })) } } : void 0;
|
|
7295
|
+
const todo = msg.type === "dialogs" && todoOk(msg.todo) ? { done: msg.todo.done, total: msg.todo.total, ...msg.todo.now && { now: msg.todo.now }, ...msg.todo.graph && { graph: msg.todo.graph }, ...msg.todo.doing !== void 0 && { doing: msg.todo.doing }, ...msg.todo.doingUid && { doingUid: msg.todo.doingUid }, ...msg.todo.runs && { runs: msg.todo.runs.map(({ id: id2, run: run2, uid: uid2 }) => ({ id: id2, run: run2, ...uid2 && { uid: uid2 } })) }, ...msg.todo.steps && { steps: msg.todo.steps.map(({ id: id2, kind, status, name: name2, round: round2, outcome }) => ({ id: id2, kind, status, ...name2 !== void 0 && { name: name2 }, ...round2 !== void 0 && { round: round2 }, ...outcome && { outcome } })) } } : void 0;
|
|
7282
7296
|
if (closed && str7(msg.pane) && (msg.file === null || str7(msg.file)) && Array.isArray(msg.dialogs) && msg.dialogs.every(valid)) noteAllows(from, msg), bridges.set(from, { ...msg, ...docs ? { documents: docs } : { documents: [], docsCut: true }, queued, monitors, todo }), changed();
|
|
7283
7297
|
if (msg.type === "ack") waiting.get([from, msg.bridgeId, msg.id, msg.answerId].join("\n"))?.(msg);
|
|
7284
7298
|
if (msg.type === "probe-result") probes.get([from, msg.bridgeId, msg.probeId].join("\n"))?.(checkProbe({ ...msg }));
|
|
@@ -21375,10 +21389,11 @@ function places(net) {
|
|
|
21375
21389
|
}
|
|
21376
21390
|
var askerOf = (p, paneOf2) => ((pane) => ({ session: p.u.key, name: p.u.name, role: p.u.role, workspace: p.ws, workspaceLabel: p.wsLabel, ...p.tab ? { tab: p.tab, tabLabel: p.tabLabel } : {}, ...pane ? { pane } : {} }))(paneOf2?.(p.u.key));
|
|
21377
21391
|
function itemOf(p, explicit) {
|
|
21378
|
-
|
|
21392
|
+
const own = (id2) => ((uid2) => ({ session: p.u.key, id: id2, ...uid2 && { uid: uid2 } }))(id2 === p.u.todo?.doing ? p.u.todo.doingUid : p.u.todo?.runs?.find((r) => r.id === id2)?.uid);
|
|
21393
|
+
if (explicit) return own(explicit);
|
|
21379
21394
|
const bound = p.launcher?.todo?.runs?.find((r) => r.run === p.u.key);
|
|
21380
|
-
if (bound && p.launcher) return { session: p.launcher.key, id: bound.id };
|
|
21381
|
-
return p.u.todo?.doing !== void 0 ?
|
|
21395
|
+
if (bound && p.launcher) return { session: p.launcher.key, id: bound.id, ...bound.uid && { uid: bound.uid } };
|
|
21396
|
+
return p.u.todo?.doing !== void 0 ? own(p.u.todo.doing) : void 0;
|
|
21382
21397
|
}
|
|
21383
21398
|
var subjectOf2 = (u) => {
|
|
21384
21399
|
const p = u.pending, qs = p.asks ?? (p.ask ? [p.ask] : (p.answer?.questions ?? []).map((q2) => ({ question: q2.question })));
|
|
@@ -21513,7 +21528,7 @@ function startAsks(d) {
|
|
|
21513
21528
|
const ask = r.ask ?? {}, session = str10(r.session, 128), questions = questionsOf3(ask.questions), item = Number.isSafeInteger(ask.item) && ask.item > 0 ? ask.item : void 0;
|
|
21514
21529
|
if (!session || !questions) return Promise.resolve({ ok: false, error: "ask-open needs a session and one to four questions of up to eight options" });
|
|
21515
21530
|
const place = last ? seenIn(last.net).place(session) : void 0;
|
|
21516
|
-
const rec = store2.open({ kind: "boss", asker: { session, name: str10(r.name, 128) ?? session.slice(0, 8), ...place }, subject: str10(ask.subject, 2e3) ?? questions[0].question, questions, ...str10(ask.toolCallId, 128) ? { toolCallId: ask.toolCallId } : {}, ...item ? { item: { session, id: item } } : {} });
|
|
21531
|
+
const rec = store2.open({ kind: "boss", asker: { session, name: str10(r.name, 128) ?? session.slice(0, 8), ...place }, subject: str10(ask.subject, 2e3) ?? questions[0].question, questions, ...str10(ask.toolCallId, 128) ? { toolCallId: ask.toolCallId } : {}, ...item ? { item: { session, id: item, ...typeof ask.itemUid === "string" && UID.test(ask.itemUid) && { uid: ask.itemUid } } } : {} });
|
|
21517
21532
|
d.log("ask-open", { n: rec.n, kind: rec.kind });
|
|
21518
21533
|
return Promise.resolve({ ok: true, ask: rec });
|
|
21519
21534
|
}
|
|
@@ -26997,6 +27012,10 @@ function foregroundOf(info, workspace, promptPid) {
|
|
|
26997
27012
|
function reopenGate(f) {
|
|
26998
27013
|
return !f.headless || f.stowed && f.attended;
|
|
26999
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
|
+
}
|
|
27000
27019
|
function seatOpen(f) {
|
|
27001
27020
|
if (f.label === void 0) return "gone";
|
|
27002
27021
|
return f.seated || f.label === f.record ? "open" : "stranger";
|
|
@@ -30489,9 +30508,9 @@ function createTowers(o) {
|
|
|
30489
30508
|
await Promise.race([l.starting, sleep2(o.registerMs ?? REGISTER_WAIT_MS)]);
|
|
30490
30509
|
return answer(l, true);
|
|
30491
30510
|
};
|
|
30492
|
-
const openHeadless = async (target2, existing, cwd,
|
|
30493
|
-
const ws = target2.workspace_id;
|
|
30494
|
-
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) {
|
|
30495
30514
|
if (existing.state !== "waiting") await Promise.race([existing.starting, sleep2(o.registerMs ?? REGISTER_WAIT_MS)]);
|
|
30496
30515
|
return answer(existing, false);
|
|
30497
30516
|
}
|
|
@@ -30520,7 +30539,7 @@ function createTowers(o) {
|
|
|
30520
30539
|
const target2 = isSub(asked3) ? parentOf(all, asked3) : asked3;
|
|
30521
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`);
|
|
30522
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`);
|
|
30523
|
-
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));
|
|
30524
30543
|
opening3.set(target2.workspace_id, pending);
|
|
30525
30544
|
return pending;
|
|
30526
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/askclient.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { ServerCall } from "./traincar.ts";
|
|
|
10
10
|
* question is asked as before the store, and an Ask the server opened meanwhile is closed when its tool call ends (askops.ts).
|
|
11
11
|
*/
|
|
12
12
|
export interface AskClient {
|
|
13
|
-
open(a: { subject: string; questions: { question: string; options: string[] }[]; toolCallId?: string; item?: number }): Promise<{ id: string; digest: string } | undefined>;
|
|
13
|
+
open(a: { subject: string; questions: { question: string; options: string[] }[]; toolCallId?: string; item?: number; itemUid?: string }): Promise<{ id: string; digest: string } | undefined>;
|
|
14
14
|
answer(id: string, a: { answerId: string; digest: string; replies?: { choices?: number[]; text?: string; note?: string }[]; cancel?: true; by: "terminal" | "gui" | "phone" }): Promise<{ status: number; body: Record<string, unknown> } | undefined>;
|
|
15
15
|
get(id: string): Promise<AskState | undefined>;
|
|
16
16
|
close(id: string, why: "esc" | "abort" | "auto"): Promise<AskState | undefined>;
|
package/src/askrows.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { ASK_ROWS_EVENT, type AskRowV1 } from "./asktypes.ts";
|
|
2
|
+
import { ASK_ROWS_EVENT, type AskRowsAnswerV1, type AskRowV1 } from "./asktypes.ts";
|
|
3
3
|
import { localeOf, type Locale } from "./locale.ts";
|
|
4
4
|
import type { Kit } from "./state.ts";
|
|
5
5
|
import { todosOfBranch } from "./todo.ts";
|
|
6
6
|
import { callServer, type ServerCall } from "./traincar.ts";
|
|
7
7
|
|
|
8
8
|
// A session's rows of the open questions to the boss (docs/specs/2026-11-28-boss-asks.md, The probe): it asks the sb server every 15 s (`asks-rows`), answers `straw-boss:ask-rows:v1` from the last answer at once (the
|
|
9
|
-
// probe is synchronous), and prints the same rows for `/boss asks`. The rows are every open Ask of this computer; `mine` and `item`
|
|
9
|
+
// probe is synchronous), and prints the same rows for `/boss asks`. The rows are every open Ask of this computer; `mine`, `item` and the probe's `session` (which `item.session` is this one) place a row under its todo.
|
|
10
10
|
|
|
11
11
|
/** Between two asks of the server; the probe's rows stand for what waits now only this long after the server's last answer (three asks), then the probe answers none (asks-r2-F007). */
|
|
12
12
|
export const ASK_MS = 15_000, STALE_MS = 45_000;
|
|
@@ -47,7 +47,7 @@ export function registerAskRows(d: AskRowsDeps) {
|
|
|
47
47
|
const refresh = () => (running ??= look().finally(() => { running = undefined; }));
|
|
48
48
|
d.pi.events.on(ASK_ROWS_EVENT, (raw) => {
|
|
49
49
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return;
|
|
50
|
-
Object.assign(raw, { rows: { version: 1, rows: current().map((r) => ({ ...r })) } });
|
|
50
|
+
Object.assign(raw, { rows: { version: 1, session: d.me(), rows: current().map((r) => ({ ...r })) } satisfies AskRowsAnswerV1 });
|
|
51
51
|
});
|
|
52
52
|
if (every > 0) {
|
|
53
53
|
d.pi.on("session_start", () => {
|
package/src/asktypes.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// The shapes the Asks of docs/specs/2026-11-28-boss-asks.md show in: the probe's row (a contract: pi-todo-ledger reads it) and the page's view (the net's `asks`, this computer only). Free of Node, so the page imports it.
|
|
2
2
|
|
|
3
3
|
export type AskKind = "boss" | "dialog" | "wait" | "link";
|
|
4
|
-
/** The todo an Ask blocks: the session whose list holds it, and its id
|
|
5
|
-
export interface AskItem { session: string; id: number }
|
|
4
|
+
/** The todo an Ask blocks: the session whose list holds it, its id there, and its uid when the binding knew it (a reader checks it: `clear` lets a new todo take the id). */
|
|
5
|
+
export interface AskItem { session: string; id: number; uid?: string }
|
|
6
6
|
export const ASK_ROWS_EVENT = "straw-boss:ask-rows:v1";
|
|
7
7
|
/** One row of `straw-boss:ask-rows:v1`. */
|
|
8
8
|
export interface AskRowV1 { id: string; subject: string; asker: string; where: string; kind: AskKind; since: number; mine: boolean; item?: AskItem }
|
|
9
|
+
/** The probe's answer: `session` is the id `item.session` names this session by (an older sb leaves it out). */
|
|
10
|
+
export interface AskRowsAnswerV1 { version: 1; session: string; rows: AskRowV1[] }
|
|
9
11
|
/**
|
|
10
12
|
* An open Ask as the page draws it: `unit` is the unit on the net whose plate counts it (the asker, or the tower for a wait whose raiser is not on the net), `ws` its workspace, `wait` the W id of a wait card (its
|
|
11
13
|
* alert is the card), `pane` whether the asker has a pane the page can open.
|
package/src/bossask.ts
CHANGED
|
@@ -57,7 +57,7 @@ async function paneDialog(ui: ExtensionContext["ui"], q: BossQuestion, title: st
|
|
|
57
57
|
export function createBossAsk(kit: Kit, d: { attended(): boolean; remote(): boolean; asks?: AskClient }): BossAsk {
|
|
58
58
|
const { pi, cfg, s, role } = kit, watch = cfg.face?.every ?? every, bus = pi.events as unknown as Bus;
|
|
59
59
|
const asks = d.asks ?? askClient(cfg.server ? callServer(cfg.env, kit.guiDir) : async () => undefined, kit.me, () => (pi as { getSessionName?: () => string | undefined }).getSessionName?.());
|
|
60
|
-
const
|
|
60
|
+
const todos = () => { try { return todosOfBranch(s.branch()) ?? []; } catch { return []; } };
|
|
61
61
|
return async (q, signal, ctx, callId) => {
|
|
62
62
|
if (role() !== "main" || s.isTrain || s.isTower || s.remoteOrigin || d.remote() || !d.attended() || !ctx?.hasUI) return { kind: "tower" };
|
|
63
63
|
if (s.autoOn()) return { kind: "tower", note: AUTO_NOTE };
|
|
@@ -65,7 +65,9 @@ export function createBossAsk(kit: Kit, d: { attended(): boolean; remote(): bool
|
|
|
65
65
|
const opts = { signal: signal ? AbortSignal.any([signal, ac.signal]) : ac.signal };
|
|
66
66
|
// The first answer, here or there, wins: the store decides between the pane, the page and the phone; one from the page or a paired device ends the dialog here.
|
|
67
67
|
let got: Got | undefined, looking = false, unconfirmed = false, autoCancel = false, won: string | undefined; // `won`: the answerId the store (else the relay) took, which the close names (asks-r3-F001)
|
|
68
|
-
|
|
68
|
+
// The todo it blocks, by id and uid (carrows-review-F001): a reader tells it from a todo that takes the id after `clear`.
|
|
69
|
+
const list = todos(), item = q.item ?? list.find((t) => t.status === "in_progress")?.id, itemUid = item ? list.find((t) => t.id === item)?.uid : undefined;
|
|
70
|
+
const ask = await asks.open({ subject: q.question, questions: [{ question: title, options: q.options ?? [] }], ...(callId ? { toolCallId: callId } : {}), ...(item ? { item, ...(itemUid ? { itemUid } : {}) } : {}) }).catch(() => undefined);
|
|
69
71
|
const winner = (a: NonNullable<AskState["answer"]>) => void (!got && ((got = gotOf(q, a)), (won = a.answerId), ac.abort()));
|
|
70
72
|
const judged = (r: Awaited<ReturnType<AskClient["answer"]>>): Took | undefined => (!r ? undefined : r.status === 200 ? "won" : (r.status === 409 && (r.body.ask as AskState | undefined)?.answer && winner((r.body.ask as AskState).answer!), "lost"));
|
|
71
73
|
/**
|
package/src/carrows.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
|
2
2
|
import { CAR_ROWS_EVENT, carRows, carsText, type SentSlip, type TodoRef, UNRECEIVED_MS } from "./carline.ts";
|
|
3
3
|
import { localeOf, type Locale } from "./locale.ts";
|
|
4
4
|
import type { Kit } from "./state.ts";
|
|
5
|
-
import {
|
|
5
|
+
import { todosOf } from "./items.ts";
|
|
6
|
+
import { snapshotScan } from "./todo.ts";
|
|
6
7
|
import type { CarFact } from "./train/carfacts.ts";
|
|
7
8
|
import { slipsInText } from "./train/cars.ts";
|
|
8
9
|
import { callServer, type ServerCall } from "./traincar.ts";
|
|
@@ -38,8 +39,17 @@ export function registerCarRows(d: CarRowsDeps) {
|
|
|
38
39
|
const held = d.held ?? heldSlips(), every = d.every ?? ASK_MS;
|
|
39
40
|
let facts: CarFact[] = [], answered: number | undefined, timer: ReturnType<typeof setInterval> | undefined, running: Promise<void> | undefined;
|
|
40
41
|
const sent = () => held.get(d.me()) ?? [];
|
|
41
|
-
|
|
42
|
-
const
|
|
42
|
+
// The todo list is read again only when the branch's snapshot changed: the probe is asked at every draw (carrows-review-F004).
|
|
43
|
+
const scan = snapshotScan();
|
|
44
|
+
let list: { snapshot: unknown; refs: TodoRef[] } | undefined;
|
|
45
|
+
const todos = (): TodoRef[] => {
|
|
46
|
+
try {
|
|
47
|
+
const snapshot = scan(d.branch());
|
|
48
|
+
if (list && list.snapshot === snapshot) return list.refs;
|
|
49
|
+
return (list = { snapshot, refs: (todosOf(snapshot) ?? []).map((t) => ({ id: t.id, subject: t.subject, status: t.status, ...(t.uid ? { uid: t.uid } : {}) })) }).refs;
|
|
50
|
+
} catch { return []; }
|
|
51
|
+
};
|
|
52
|
+
const rows = () => (facts.length || sent().length ? carRows({ facts, sent: sent(), todos: todos(), me: d.me(), lang: d.lang(), now: d.now() }) : []);
|
|
43
53
|
|
|
44
54
|
// A slip the tower took: each car of the message whose coordinator is this session (a slip that names none is the sender's own).
|
|
45
55
|
d.pi.on("tool_result", (event) => {
|
|
@@ -71,7 +81,7 @@ export function registerCarRows(d: CarRowsDeps) {
|
|
|
71
81
|
|
|
72
82
|
d.pi.events.on(CAR_ROWS_EVENT, (raw) => {
|
|
73
83
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return;
|
|
74
|
-
Object.assign(raw, { rows: { version: 1, rows: rows() } });
|
|
84
|
+
Object.assign(raw, { rows: { version: 1, session: d.me(), rows: rows() } });
|
|
75
85
|
});
|
|
76
86
|
if (every > 0) {
|
|
77
87
|
d.pi.on("session_start", () => {
|
package/src/dialogs.ts
CHANGED
|
@@ -144,7 +144,7 @@ export function createHub(pi: ExtensionAPI, me: string, local: Bridge, onAllow?:
|
|
|
144
144
|
// A queue out of shape is left out; the dialogs and documents still go.
|
|
145
145
|
const queued = msg.type === "dialogs" && Array.isArray(msg.queued) && msg.queued.length <= MAX_QUEUED && msg.queued.every((q) => typeof q?.text === "string" && q.text.length <= QUEUED_TEXT && (q.as === "steer" || q.as === "followUp")) ? msg.queued.map(({ text, as }) => ({ text, as })) : undefined;
|
|
146
146
|
const monitors = msg.type === "dialogs" && monitorsOk(msg.monitors) ? msg.monitors.map(({ id, what, status, exit, last, load, lines, at, ended }) => ({ id, what, status, exit, last, load, lines, at, ended })) : undefined;
|
|
147
|
-
const todo = msg.type === "dialogs" && todoOk(msg.todo) ? { done: msg.todo.done, total: msg.todo.total, ...(msg.todo.now && { now: msg.todo.now }), ...(msg.todo.graph && { graph: msg.todo.graph }), ...(msg.todo.doing !== undefined && { doing: msg.todo.doing }), ...(msg.todo.runs && { runs: msg.todo.runs.map(({ id, run }) => ({ id, run })) }), ...(msg.todo.steps && { steps: msg.todo.steps.map(({ id, kind, status, name, round, outcome }) => ({ id, kind, status, ...(name !== undefined && { name }), ...(round !== undefined && { round }), ...(outcome && { outcome }) })) }) } : undefined;
|
|
147
|
+
const todo = msg.type === "dialogs" && todoOk(msg.todo) ? { done: msg.todo.done, total: msg.todo.total, ...(msg.todo.now && { now: msg.todo.now }), ...(msg.todo.graph && { graph: msg.todo.graph }), ...(msg.todo.doing !== undefined && { doing: msg.todo.doing }), ...(msg.todo.doingUid && { doingUid: msg.todo.doingUid }), ...(msg.todo.runs && { runs: msg.todo.runs.map(({ id, run, uid }) => ({ id, run, ...(uid && { uid }) })) }), ...(msg.todo.steps && { steps: msg.todo.steps.map(({ id, kind, status, name, round, outcome }) => ({ id, kind, status, ...(name !== undefined && { name }), ...(round !== undefined && { round }), ...(outcome && { outcome }) })) }) } : undefined;
|
|
148
148
|
if (closed && str(msg.pane) && (msg.file === null || str(msg.file)) && Array.isArray(msg.dialogs) && msg.dialogs.every(valid)) (noteAllows(from, msg), bridges.set(from, { ...msg, ...(docs ? { documents: docs } : { documents: [], docsCut: true as const }), queued, monitors, todo }), changed());
|
|
149
149
|
if (msg.type === "ack") waiting.get([from, msg.bridgeId, msg.id, msg.answerId].join("\n"))?.(msg);
|
|
150
150
|
if (msg.type === "probe-result") probes.get([from, msg.bridgeId, msg.probeId].join("\n"))?.(checkProbe({ ...msg }));
|
package/src/items.ts
CHANGED
|
@@ -19,7 +19,8 @@ export interface StepInfo {
|
|
|
19
19
|
kind: string; name?: string; project?: string; app?: string; train?: string; round?: number; check?: string;
|
|
20
20
|
holds?: { lane?: string; target?: string }; load?: { max?: number; perCore?: number; weight?: number }; lock?: string; outcome?: "passed" | "failed" | "void"; why?: "superseded" | "skipped";
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
/** The ledger's todo uid. */ export const UID = /^t_[a-z2-7]{10}$/;
|
|
23
|
+
const STATUSES = new Set(["pending", "in_progress", "completed"]), AGENT = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/;
|
|
23
24
|
const obj = (v: unknown): v is Json => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
24
25
|
const cut = (v: unknown, n: number) => (typeof v === "string" && v ? v.slice(0, n) : undefined);
|
|
25
26
|
const num = (v: unknown) => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
|
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/askmirror.ts
CHANGED
|
@@ -28,10 +28,11 @@ function places(net: Pick<Net, "bases">): Place[] {
|
|
|
28
28
|
const askerOf = (p: Place, paneOf?: (key: string) => string | undefined): Asker => ((pane) => ({ session: p.u.key, name: p.u.name, role: p.u.role, workspace: p.ws, workspaceLabel: p.wsLabel, ...(p.tab ? { tab: p.tab, tabLabel: p.tabLabel } : {}), ...(pane ? { pane } : {}) }))(paneOf?.(p.u.key));
|
|
29
29
|
/** The todo a question of this unit blocks: the call's own item, the launcher's todo bound to the subagent's run, else the unit's todo in progress. */
|
|
30
30
|
function itemOf(p: Place, explicit?: number): AskItem | undefined {
|
|
31
|
-
|
|
31
|
+
const own = (id: number): AskItem => ((uid) => ({ session: p.u.key, id, ...(uid && { uid }) }))(id === p.u.todo?.doing ? p.u.todo.doingUid : p.u.todo?.runs?.find((r) => r.id === id)?.uid);
|
|
32
|
+
if (explicit) return own(explicit);
|
|
32
33
|
const bound = p.launcher?.todo?.runs?.find((r) => r.run === p.u.key);
|
|
33
|
-
if (bound && p.launcher) return { session: p.launcher.key, id: bound.id };
|
|
34
|
-
return p.u.todo?.doing !== undefined ?
|
|
34
|
+
if (bound && p.launcher) return { session: p.launcher.key, id: bound.id, ...(bound.uid && { uid: bound.uid }) };
|
|
35
|
+
return p.u.todo?.doing !== undefined ? own(p.u.todo.doing) : undefined;
|
|
35
36
|
}
|
|
36
37
|
const subjectOf = (u: Place["u"]) => {
|
|
37
38
|
const p = u.pending!, qs = p.asks ?? (p.ask ? [p.ask] : (p.answer?.questions ?? []).map((q) => ({ question: q.question })));
|
package/src/server/askops.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { join } from "node:path";
|
|
|
2
2
|
import type { AskView } from "../asktypes.ts";
|
|
3
3
|
import type { Found, Net } from "../net.ts";
|
|
4
4
|
import { openCalls } from "../ask.ts";
|
|
5
|
+
import { UID } from "../items.ts";
|
|
5
6
|
import { asksOfNet, countOn, rowsFor, viewsOf } from "./askmirror.ts";
|
|
6
7
|
import { type AnswerBy, type AskQuestion, type AskRecord, type CloseWhy, createAskStore, GONE_MS, type Judged, oneLine } from "./askstore.ts";
|
|
7
8
|
import type { Slot } from "./record.ts";
|
|
@@ -10,7 +11,7 @@ import type { Reply, Request } from "./socket.ts";
|
|
|
10
11
|
// The server's side of the Asks (docs/specs/2026-11-28-boss-asks.md): the store under the slot's asks/, kept in step with every reading of the net (askmirror.ts), the control socket's commands, and the page's
|
|
11
12
|
// answer route. Kept out of main.ts, which carries a line budget.
|
|
12
13
|
//
|
|
13
|
-
// ask-open {session, name, ask: {subject, questions, toolCallId?, item?}}
|
|
14
|
+
// ask-open {session, name, ask: {subject, questions, toolCallId?, item?, itemUid?}} a blocking Ask of `call_tower`'s boss question; answers the record
|
|
14
15
|
// ask-answer {id, answerId, digest, replies | cancel, by} one answer (`by`: terminal, gui, phone); answers {status, body} as the page's route does
|
|
15
16
|
// ask-get {id} the record, which an asker looks at while its dialog is open
|
|
16
17
|
// ask-close {id, session, why} the asker ends its own question with no answer (esc, abort, auto)
|
|
@@ -87,7 +88,7 @@ export function startAsks(d: AskOpsDeps) {
|
|
|
87
88
|
const ask = (r.ask ?? {}) as Record<string, unknown>, session = str(r.session, 128), questions = questionsOf(ask.questions), item = Number.isSafeInteger(ask.item) && (ask.item as number) > 0 ? (ask.item as number) : undefined;
|
|
88
89
|
if (!session || !questions) return Promise.resolve({ ok: false, error: "ask-open needs a session and one to four questions of up to eight options" });
|
|
89
90
|
const place = last ? seenIn(last.net).place(session) : undefined; // the net's name and place of the session, when the last reading has it
|
|
90
|
-
const rec = store.open({ kind: "boss", asker: { session, name: str(r.name, 128) ?? session.slice(0, 8), ...place }, subject: str(ask.subject, 2000) ?? questions[0]!.question, questions, ...(str(ask.toolCallId, 128) ? { toolCallId: ask.toolCallId as string } : {}), ...(item ? { item: { session, id: item } } : {}) });
|
|
91
|
+
const rec = store.open({ kind: "boss", asker: { session, name: str(r.name, 128) ?? session.slice(0, 8), ...place }, subject: str(ask.subject, 2000) ?? questions[0]!.question, questions, ...(str(ask.toolCallId, 128) ? { toolCallId: ask.toolCallId as string } : {}), ...(item ? { item: { session, id: item, ...(typeof ask.itemUid === "string" && UID.test(ask.itemUid) && { uid: ask.itemUid }) } } : {}) });
|
|
91
92
|
d.log("ask-open", { n: rec.n, kind: rec.kind });
|
|
92
93
|
return Promise.resolve({ ok: true, ask: rec });
|
|
93
94
|
}
|
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";
|
package/src/todo.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GRAPHS, type Graph } from "./duty.ts";
|
|
2
2
|
import { newestOf } from "./branchscan.ts";
|
|
3
|
-
import { type Todo, todosOf } from "./items.ts";
|
|
3
|
+
import { type Todo, todosOf, UID } from "./items.ts";
|
|
4
4
|
import { v1Of } from "./todoledger.ts";
|
|
5
5
|
import { planGraph } from "./boardplan.ts";
|
|
6
6
|
|
|
@@ -8,8 +8,8 @@ import { planGraph } from "./boardplan.ts";
|
|
|
8
8
|
// checks it (dialogs.ts) before it goes to the unit. A snapshot is pi-todo-ledger's `todo/v1` entry (its public contract, todoledger.ts), else rpiv-todo's records (docs/specs/2026-11-24-todo-ledger.md).
|
|
9
9
|
|
|
10
10
|
/** Done of total, and the task in progress as rpiv-todo words it while it runs; `steps` are the train's (docs/specs/2026-11-07-train-workers.md §11.1), the todos that carry a `metadata.sb`. */
|
|
11
|
-
export interface TodoSum { done: number; total: number; now?: string; steps?: StepLine[]; /** The graph of the plan the main runs (`planGraph`); the page shows it beside the main's kind (docs/specs/2026-11-09-agent-kinds.md §2). */ graph?: Graph; /** The id of the todo in progress, and the open todos' Herdr runs (`Todo.runs`): the todo an Ask blocks (docs/specs/2026-11-28-boss-asks.md). */ doing?: number; runs?: TodoRun[] }
|
|
12
|
-
export interface TodoRun { id: number; run: string }
|
|
11
|
+
export interface TodoSum { done: number; total: number; now?: string; steps?: StepLine[]; /** The graph of the plan the main runs (`planGraph`); the page shows it beside the main's kind (docs/specs/2026-11-09-agent-kinds.md §2). */ graph?: Graph; /** The id of the todo in progress (and its uid), and the open todos' Herdr runs (`Todo.runs`): the todo an Ask blocks, bound by id and uid (docs/specs/2026-11-28-boss-asks.md). */ doing?: number; doingUid?: string; runs?: TodoRun[] }
|
|
12
|
+
export interface TodoRun { id: number; run: string; uid?: string }
|
|
13
13
|
export interface StepLine { id: number; kind: string; status: Todo["status"]; name?: string; round?: number; outcome?: "passed" | "failed" | "void" }
|
|
14
14
|
export const TODO_TEXT = 120, RUNS_MAX = 64;
|
|
15
15
|
|
|
@@ -41,14 +41,15 @@ export function todoOfBranch(entries: readonly unknown[]): TodoSum | undefined {
|
|
|
41
41
|
if (!list?.length) return undefined;
|
|
42
42
|
const now = doing && (doing.activeForm || doing.subject).replace(/[\p{Cc}\p{Cf}]+/gu, " ").trim().slice(0, TODO_TEXT);
|
|
43
43
|
const steps = list.flatMap((t): StepLine[] => (t.sb ? [{ id: t.id, kind: t.sb.kind, status: t.status, ...(t.sb.name && { name: t.sb.name }), ...(t.sb.round !== undefined && { round: t.sb.round }), ...(t.sb.outcome && { outcome: t.sb.outcome }) }] : []));
|
|
44
|
-
const graph = planGraph(list), runs = list.filter((t) => t.status !== "completed").flatMap((t) => (t.runs ?? []).map((run) => ({ id: t.id, run }))).slice(0, RUNS_MAX);
|
|
45
|
-
return { done: list.filter((t) => t.status === "completed").length, total: list.length, ...(now && { now }), ...(doing && { doing: doing.id }), ...(steps.length && { steps }), ...(graph && { graph }), ...(runs.length && { runs }) };
|
|
44
|
+
const graph = planGraph(list), runs = list.filter((t) => t.status !== "completed").flatMap((t) => (t.runs ?? []).map((run) => ({ id: t.id, run, ...(t.uid && { uid: t.uid }) }))).slice(0, RUNS_MAX);
|
|
45
|
+
return { done: list.filter((t) => t.status === "completed").length, total: list.length, ...(now && { now }), ...(doing && { doing: doing.id }), ...(doing?.uid && { doingUid: doing.uid }), ...(steps.length && { steps }), ...(graph && { graph }), ...(runs.length && { runs }) };
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/** What the hub accepts from a bridge. */
|
|
49
49
|
export const todoOk = (v: unknown): v is TodoSum => {
|
|
50
50
|
const t = v as Partial<TodoSum> | null;
|
|
51
51
|
const count = (n: unknown) => Number.isSafeInteger(n) && (n as number) >= 0 && (n as number) <= 200;
|
|
52
|
+
const uid = (s: unknown) => typeof s === "string" && UID.test(s);
|
|
52
53
|
const plain = (s: unknown, max: number) => typeof s === "string" && s.length > 0 && s.length <= max && !/[\p{Cc}\p{Cf}]/u.test(s);
|
|
53
54
|
const step = (r: unknown) => {
|
|
54
55
|
const x = r as Partial<StepLine> | null;
|
|
@@ -56,5 +57,5 @@ export const todoOk = (v: unknown): v is TodoSum => {
|
|
|
56
57
|
&& (x.name === undefined || plain(x.name, 64)) && (x.round === undefined || (Number.isSafeInteger(x.round) && x.round >= 1)) && (x.outcome === undefined || ["passed", "failed", "void"].includes(x.outcome));
|
|
57
58
|
};
|
|
58
59
|
return t !== null && typeof t === "object" && count(t.done) && count(t.total) && t.done! <= t.total! && t.total! > 0 && (t.now === undefined || plain(t.now, TODO_TEXT)) && (t.steps === undefined || (Array.isArray(t.steps) && t.steps.length <= 200 && t.steps.every(step))) && (t.graph === undefined || (GRAPHS as readonly string[]).includes(t.graph))
|
|
59
|
-
&& (t.doing === undefined || (Number.isSafeInteger(t.doing) && t.doing >= 0)) && (t.runs === undefined || (Array.isArray(t.runs) && t.runs.length <= RUNS_MAX && t.runs.every((r) => Number.isSafeInteger(r?.id) && plain(r.run, 64))));
|
|
60
|
+
&& (t.doing === undefined || (Number.isSafeInteger(t.doing) && t.doing >= 0)) && (t.doingUid === undefined || uid(t.doingUid)) && (t.runs === undefined || (Array.isArray(t.runs) && t.runs.length <= RUNS_MAX && t.runs.every((r) => Number.isSafeInteger(r?.id) && plain(r.run, 64) && (r.uid === undefined || uid(r.uid)))));
|
|
60
61
|
};
|