pi-straw-boss 0.116.1 → 0.116.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 +9 -7
- 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/server/askmirror.ts +4 -3
- package/src/server/askops.ts +3 -2
- package/src/todo.ts +7 -6
package/dist/server/main.mjs
CHANGED
|
@@ -6309,8 +6309,8 @@ var FULL = 1 << 20;
|
|
|
6309
6309
|
var TEXT = 1e5;
|
|
6310
6310
|
var LAST_BYTES = 65536;
|
|
6311
6311
|
var FULL_LIMIT = FULL;
|
|
6312
|
-
var STATUSES2 = /* @__PURE__ */ new Set(["pending", "in_progress", "completed"]);
|
|
6313
6312
|
var UID = /^t_[a-z2-7]{10}$/;
|
|
6313
|
+
var STATUSES2 = /* @__PURE__ */ new Set(["pending", "in_progress", "completed"]);
|
|
6314
6314
|
var AGENT = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/;
|
|
6315
6315
|
var obj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
6316
6316
|
var cut3 = (v, n) => typeof v === "string" && v ? v.slice(0, n) : void 0;
|
|
@@ -7164,12 +7164,13 @@ var RUNS_MAX = 64;
|
|
|
7164
7164
|
var todoOk = (v) => {
|
|
7165
7165
|
const t = v;
|
|
7166
7166
|
const count4 = (n) => Number.isSafeInteger(n) && n >= 0 && n <= 200;
|
|
7167
|
+
const uid2 = (s2) => typeof s2 === "string" && UID.test(s2);
|
|
7167
7168
|
const plain5 = (s2, max) => typeof s2 === "string" && s2.length > 0 && s2.length <= max && !/[\p{Cc}\p{Cf}]/u.test(s2);
|
|
7168
7169
|
const step = (r) => {
|
|
7169
7170
|
const x = r;
|
|
7170
7171
|
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
7172
|
};
|
|
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)));
|
|
7173
|
+
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
7174
|
};
|
|
7174
7175
|
|
|
7175
7176
|
// src/dialogs.ts
|
|
@@ -7278,7 +7279,7 @@ function createHub(pi, me, local, onAllow) {
|
|
|
7278
7279
|
const docs = msg.type === "dialogs" && (msg.documents === void 0 ? [] : docsOf({ version: 1, documents: msg.documents }));
|
|
7279
7280
|
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
7281
|
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;
|
|
7282
|
+
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
7283
|
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
7284
|
if (msg.type === "ack") waiting.get([from, msg.bridgeId, msg.id, msg.answerId].join("\n"))?.(msg);
|
|
7284
7285
|
if (msg.type === "probe-result") probes.get([from, msg.bridgeId, msg.probeId].join("\n"))?.(checkProbe({ ...msg }));
|
|
@@ -21375,10 +21376,11 @@ function places(net) {
|
|
|
21375
21376
|
}
|
|
21376
21377
|
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
21378
|
function itemOf(p, explicit) {
|
|
21378
|
-
|
|
21379
|
+
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);
|
|
21380
|
+
if (explicit) return own(explicit);
|
|
21379
21381
|
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 ?
|
|
21382
|
+
if (bound && p.launcher) return { session: p.launcher.key, id: bound.id, ...bound.uid && { uid: bound.uid } };
|
|
21383
|
+
return p.u.todo?.doing !== void 0 ? own(p.u.todo.doing) : void 0;
|
|
21382
21384
|
}
|
|
21383
21385
|
var subjectOf2 = (u) => {
|
|
21384
21386
|
const p = u.pending, qs = p.asks ?? (p.ask ? [p.ask] : (p.answer?.questions ?? []).map((q2) => ({ question: q2.question })));
|
|
@@ -21513,7 +21515,7 @@ function startAsks(d) {
|
|
|
21513
21515
|
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
21516
|
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
21517
|
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 } } : {} });
|
|
21518
|
+
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
21519
|
d.log("ask-open", { n: rec.n, kind: rec.kind });
|
|
21518
21520
|
return Promise.resolve({ ok: true, ask: rec });
|
|
21519
21521
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-straw-boss",
|
|
3
|
-
"version": "0.116.
|
|
3
|
+
"version": "0.116.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/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/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/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
|
};
|