pi-straw-boss 0.96.1 → 0.97.0
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 +35 -16
- package/package.json +1 -1
- package/src/herdr.ts +2 -2
- package/src/server/runs.ts +2 -0
- package/src/server/standin.ts +63 -0
- package/src/server/standing.ts +18 -27
- package/src/server/towers.ts +2 -2
package/dist/server/main.mjs
CHANGED
|
@@ -8411,6 +8411,26 @@ ${answerId}`, { block } = answer.ref, doc2 = found.doc;
|
|
|
8411
8411
|
// src/operateseam.ts
|
|
8412
8412
|
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
8413
8413
|
|
|
8414
|
+
// src/server/standin.ts
|
|
8415
|
+
function standinState(f) {
|
|
8416
|
+
if (f.verdict !== "prompt" && f.verdict !== "run" || f.leaving || !f.prompt || f.agent === "other") return void 0;
|
|
8417
|
+
if (f.cards > 0 && f.attended) return "blocked";
|
|
8418
|
+
return f.working ? "working" : "idle";
|
|
8419
|
+
}
|
|
8420
|
+
var WORDS2 = {
|
|
8421
|
+
en: { standing: "standing by", working: "working", held: "held", queued: (n) => `${n} queued`, cards: (n) => n === 1 ? "1 card waits" : `${n} cards wait`, elsewhere: (n) => n === 1 ? "1 card waits at another tower" : `${n} cards wait at other towers` },
|
|
8422
|
+
"zh-TW": { standing: "\u5F85\u547D\u4E2D", working: "\u8655\u7406\u4E2D", held: "\u5DF2\u64F1\u7F6E", queued: (n) => `${n} \u5247\u5F85\u8655\u7406`, cards: (n) => `${n} \u5F35\u5361\u7247\u7B49\u4F60`, elsewhere: (n) => `\u5176\u4ED6\u5854\u53F0\u6709 ${n} \u5F35\u5361\u7247\u7B49\u4F60` }
|
|
8423
|
+
};
|
|
8424
|
+
function standinMessage(status, { cards = 0, working = false, elsewhere = 0, locale = "en" } = {}) {
|
|
8425
|
+
const w = WORDS2[locale], tail = status?.state === "held" ? w.held : status && status.queued > 0 ? w.queued(status.queued) : void 0;
|
|
8426
|
+
const lead = working ? w.working : cards === 0 && !tail ? w.standing : void 0;
|
|
8427
|
+
return [...cards > 0 ? [w.cards(cards)] : [], ...lead ? [lead] : [], ...elsewhere > 0 ? [w.elsewhere(elsewhere)] : [], ...tail ? [tail] : []].join(" \xB7 ");
|
|
8428
|
+
}
|
|
8429
|
+
function standinReport(f) {
|
|
8430
|
+
const state = standinState(f);
|
|
8431
|
+
return state && { state, message: standinMessage(f.status, { cards: f.cards, working: f.working, elsewhere: f.elsewhere ?? 0, locale: f.locale ?? "en" }) };
|
|
8432
|
+
}
|
|
8433
|
+
|
|
8414
8434
|
// src/server/typegate.ts
|
|
8415
8435
|
var SHELLS2 = /* @__PURE__ */ new Set(["zsh", "bash", "fish", "sh", "dash", "ksh", "tcsh", "csh", "nu", "login", "pwsh", "powershell", "cmd"]);
|
|
8416
8436
|
var nameOf2 = (p) => String(p.argv0 ?? p.name ?? "").replace(/^-/, "").split(/[\\/]/).pop().toLowerCase().replace(/\.exe$/, "");
|
|
@@ -8506,15 +8526,6 @@ var MISSES = 3;
|
|
|
8506
8526
|
var NO_START = 3;
|
|
8507
8527
|
var RUN_SOON_MS = 5e3;
|
|
8508
8528
|
var TYPED_KEEP_MS = 15 * 6e4;
|
|
8509
|
-
var STANDIN_WORDS = {
|
|
8510
|
-
en: { standing: "standing by", held: "held", queued: (n) => `${n} queued`, cards: (n) => n === 1 ? "1 card waits" : `${n} cards wait`, elsewhere: (n) => n === 1 ? "1 card waits at another tower" : `${n} cards wait at other towers` },
|
|
8511
|
-
"zh-TW": { standing: "\u5F85\u547D\u4E2D", held: "\u5DF2\u64F1\u7F6E", queued: (n) => `${n} \u5247\u5F85\u8655\u7406`, cards: (n) => `${n} \u5F35\u5361\u7247\u7B49\u4F60`, elsewhere: (n) => `\u5176\u4ED6\u5854\u53F0\u6709 ${n} \u5F35\u5361\u7247\u7B49\u4F60` }
|
|
8512
|
-
};
|
|
8513
|
-
function standinReport(status, cards = 0, locale = "en", attended = true, elsewhere = 0) {
|
|
8514
|
-
const w = STANDIN_WORDS[locale], tail = status?.state === "held" ? w.held : status && status.queued > 0 ? w.queued(status.queued) : void 0;
|
|
8515
|
-
const parts = [...cards > 0 ? [w.cards(cards)] : [], ...elsewhere > 0 ? [w.elsewhere(elsewhere)] : [], ...tail ? [tail] : []];
|
|
8516
|
-
return { state: cards > 0 && attended ? "blocked" : "idle", message: parts.length ? cards > 0 || tail || !elsewhere ? parts.join(" \xB7 ") : `${w.standing} \xB7 ${parts.join(" \xB7 ")}` : w.standing };
|
|
8517
|
-
}
|
|
8518
8529
|
function programProcs(info) {
|
|
8519
8530
|
const procs = Array.isArray(info?.foreground_processes) ? info.foreground_processes : [];
|
|
8520
8531
|
return procs.filter((p) => !SHELLS2.has(nameOf2(p)) && !/\bprompt --workspace\b/.test(p.cmdline ?? ""));
|
|
@@ -8592,6 +8603,7 @@ function createStanding(o) {
|
|
|
8592
8603
|
const status = attached ? target2.status() : void 0;
|
|
8593
8604
|
let command = "";
|
|
8594
8605
|
let seat = pane;
|
|
8606
|
+
const agent = !pane?.agent ? "none" : isStandin(pane) ? "stand-in" : "other";
|
|
8595
8607
|
const verdict = await typeGate({
|
|
8596
8608
|
attached,
|
|
8597
8609
|
// A service that was detached while this look waited (lost, retired) is no seat: it types nothing from a look it had in flight.
|
|
@@ -8600,7 +8612,7 @@ function createStanding(o) {
|
|
|
8600
8612
|
busy: attached && Boolean(target2.paneBusy?.()),
|
|
8601
8613
|
held: status?.state === "held",
|
|
8602
8614
|
run: m.leaving || status !== void 0 && ["waking", "running", "closing"].includes(status.state),
|
|
8603
|
-
agent
|
|
8615
|
+
agent,
|
|
8604
8616
|
prompt: () => present3(m),
|
|
8605
8617
|
// The prompt is not there. Herdr clears its label itself a moment after; a release makes it at once.
|
|
8606
8618
|
gone: () => unreport(m),
|
|
@@ -8626,16 +8638,18 @@ function createStanding(o) {
|
|
|
8626
8638
|
switch (verdict.reason) {
|
|
8627
8639
|
case "busy":
|
|
8628
8640
|
return await lookHeld(m, paneId);
|
|
8629
|
-
case "run":
|
|
8630
|
-
if (m.reported && !isStandin(pane)) m.reported = void 0;
|
|
8631
|
-
return;
|
|
8632
8641
|
case "agent":
|
|
8633
8642
|
m.reported = void 0;
|
|
8634
8643
|
return;
|
|
8644
|
+
case "run":
|
|
8635
8645
|
case "prompt": {
|
|
8636
|
-
m.parked = false;
|
|
8646
|
+
if (verdict.reason === "prompt") m.parked = false;
|
|
8647
|
+
const next2 = standinReport({ verdict: verdict.reason, leaving: m.leaving, prompt: present3(m), agent, working: Boolean(target2.working?.()), cards: target2.cards?.() ?? 0, attended: o.attended?.() ?? true, status, elsewhere: target2.elsewhere?.() ?? 0, locale: o.locale?.() ?? "en" });
|
|
8648
|
+
if (!next2) {
|
|
8649
|
+
if (m.reported && !isStandin(pane)) m.reported = void 0;
|
|
8650
|
+
return;
|
|
8651
|
+
}
|
|
8637
8652
|
if (isStandin(pane)) m.misses = 0;
|
|
8638
|
-
const next2 = standinReport(status, target2.cards?.() ?? 0, o.locale?.() ?? "en", o.attended?.() ?? true, target2.elsewhere?.() ?? 0);
|
|
8639
8653
|
if (!isStandin(pane) || !m.reported || m.reported.message !== next2.message || m.reported.state !== next2.state || now() - m.reported.at >= t.refreshMs) await report4(m, pane, next2);
|
|
8640
8654
|
return;
|
|
8641
8655
|
}
|
|
@@ -28146,6 +28160,11 @@ Its .pi settings, extensions, skills, and prompts load only if you trust it. Yes
|
|
|
28146
28160
|
const s2 = services.get(workspace);
|
|
28147
28161
|
return Boolean(s2 && !s2.run && s2.wake && s2.wakeAt !== void 0 && s2.wakeAt - now() <= ms3);
|
|
28148
28162
|
},
|
|
28163
|
+
/** Whether a local run of this workspace handles something now (the stand-in's `working`, standin.ts): it is waking, or live and not idle at its last poll; a boss conversation between his turns is idle. */
|
|
28164
|
+
working: (workspace) => {
|
|
28165
|
+
const a = services.get(workspace)?.run;
|
|
28166
|
+
return Boolean(a && !a.ended && a.rec.kind === "local" && a.idleSince === void 0);
|
|
28167
|
+
},
|
|
28149
28168
|
/**
|
|
28150
28169
|
* The tower prompt's poll says whether the boss is answering wait cards in the standing pane. While they are, the service's wake is held (`heldUntil`); a poll that says they are done ends the hold at once, and the
|
|
28151
28170
|
* events that waited wake one run. A stretch of answering is the polls that follow each other within `answer`. Returns whether a wake is held now: events wait, and no run begins for them yet.
|
|
@@ -29241,7 +29260,7 @@ function createTowers(o) {
|
|
|
29241
29260
|
services.set(record2.workspace, l);
|
|
29242
29261
|
if (isHeadL(l)) bindDir(slot, record2.workspace, headDir(slot));
|
|
29243
29262
|
runs2.attach(refOf2(l));
|
|
29244
|
-
standing2.attach({ workspace: record2.workspace, label: () => l.record.label, ...isHeadL(l) ? { agent: STANDIN_HEAD } : {}, pane: () => l.record.pane, live: () => l.state === "live" && !l.stopped && Boolean(l.client?.isConnected()), seated: (pane) => holds(l, pane), status: () => runs2.status(record2.workspace), cards: () => cardsFor(l), ...isHeadL(l) ? { elsewhere: () => cardsElsewhere() } : {}, runWithin: (ms3) => runs2.startsWithin(record2.workspace, ms3), paneBusy: () => runs2.paneBusy(record2.workspace), busyPids: () => runs2.busyPids(record2.workspace), paneFree: () => runs2.retry(record2.workspace) }, fresh);
|
|
29263
|
+
standing2.attach({ workspace: record2.workspace, label: () => l.record.label, ...isHeadL(l) ? { agent: STANDIN_HEAD } : {}, pane: () => l.record.pane, live: () => l.state === "live" && !l.stopped && Boolean(l.client?.isConnected()), seated: (pane) => holds(l, pane), status: () => runs2.status(record2.workspace), cards: () => cardsFor(l), working: () => runs2.working(record2.workspace), ...isHeadL(l) ? { elsewhere: () => cardsElsewhere() } : {}, runWithin: (ms3) => runs2.startsWithin(record2.workspace, ms3), paneBusy: () => runs2.paneBusy(record2.workspace), busyPids: () => runs2.busyPids(record2.workspace), paneFree: () => runs2.retry(record2.workspace) }, fresh);
|
|
29245
29264
|
l.starting = (async () => {
|
|
29246
29265
|
let waited = false;
|
|
29247
29266
|
for (let resident = await residentOf(l); resident && !l.stopped && !stopped; resident = await residentOf(l)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-straw-boss",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.97.0",
|
|
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/herdr.ts
CHANGED
|
@@ -91,8 +91,8 @@ export const isStandin = (pane: Pick<Pane, "agent">) => pane.agent === STANDIN_A
|
|
|
91
91
|
let lastSeq = 0;
|
|
92
92
|
/** A `seq` Herdr takes: above the last one this process sent and in the space of Herdr's own pi integration (the clock in microseconds), since Herdr ignores a report or release whose seq is not above the last one it took. */
|
|
93
93
|
export const nextSeq = (now = Date.now()) => (lastSeq = Math.max(lastSeq + 1, now * 1000));
|
|
94
|
-
/** Reports the stand-in:
|
|
95
|
-
export const reportStandin = (api: HerdrApi, paneId: string, message: string, agent: string = STANDIN_AGENT, state: "
|
|
94
|
+
/** Reports the stand-in: working, blocked, or idle as server/standin.ts decides (never `done`, which Herdr shows by itself), with a short state as the message. No resume command and no session, so a restart of Herdr never relaunches it. */
|
|
95
|
+
export const reportStandin = (api: HerdrApi, paneId: string, message: string, agent: string = STANDIN_AGENT, state: "working" | "blocked" | "idle" = "idle") =>
|
|
96
96
|
api("pane.report_agent", { pane_id: paneId, source: STANDIN_SOURCE, agent, state, message, seq: nextSeq() });
|
|
97
97
|
export const releaseStandin = (api: HerdrApi, paneId: string, agent: string = STANDIN_AGENT) => api("pane.release_agent", { pane_id: paneId, source: STANDIN_SOURCE, agent, seq: nextSeq() });
|
|
98
98
|
|
package/src/server/runs.ts
CHANGED
|
@@ -1643,6 +1643,8 @@ export function createRuns(o: RunsOptions) {
|
|
|
1643
1643
|
attach, detach, poke: (workspace: string) => { const s = services.get(workspace); if (s) poke(s); },
|
|
1644
1644
|
/** Whether a run of this workspace starts within `ms`: its wake is due by then (the standing pane types no prompt that run would have to wait for, B6 VM F6). */
|
|
1645
1645
|
startsWithin: (workspace: string, ms: number) => { const s = services.get(workspace); return Boolean(s && !s.run && s.wake && s.wakeAt !== undefined && s.wakeAt - now() <= ms); },
|
|
1646
|
+
/** Whether a local run of this workspace handles something now (the stand-in's `working`, standin.ts): it is waking, or live and not idle at its last poll; a boss conversation between his turns is idle. */
|
|
1647
|
+
working: (workspace: string) => { const a = services.get(workspace)?.run; return Boolean(a && !a.ended && a.rec.kind === "local" && a.idleSince === undefined); },
|
|
1646
1648
|
/**
|
|
1647
1649
|
* The tower prompt's poll says whether the boss is answering wait cards in the standing pane. While they are, the service's wake is held (`heldUntil`); a poll that says they are done ends the hold at once, and the
|
|
1648
1650
|
* events that waited wake one run. A stretch of answering is the polls that follow each other within `answer`. Returns whether a wake is held now: events wait, and no run begins for them yet.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// The stand-in's Herdr state and message (docs/how-it-works.md, The standing pane): what the server reports on a standing pane is decided here, at every look, and nowhere else.
|
|
2
|
+
//
|
|
3
|
+
// The order the boss set (2026-11-26): `working` while the tower handles something (a run of its workspace is waking, or live and not idle at its last poll: an event run at work, a boss conversation's turn),
|
|
4
|
+
// `blocked` only while wait cards wait for him, and `idle` otherwise. A card that waits outranks the run's work, as Herdr's pi integration ranks a dialog above a turn. The stand-in never reports `done`: Herdr 0.9.5
|
|
5
|
+
// shows `done` by itself after working → idle or blocked → idle on a pane the boss is not looking at, and `idle` once he focuses it, so `idle` after the handling reads "finished" until he has seen it.
|
|
6
|
+
//
|
|
7
|
+
// Who reports: the stand-in stands only while the tower prompt is in the pane: between runs, and under headless runs during one too, since the run is the server's child and the prompt (the viewer) stays. While a
|
|
8
|
+
// run's pi holds the pane (pane runs), Herdr's pi integration reports that pi (source `herdr:pi`, agent `pi`: working, idle, or blocked on a dialog), Herdr keeps no report of another label over it, and the server
|
|
9
|
+
// reports nothing: one source on a pane at a time, so the two never flap.
|
|
10
|
+
|
|
11
|
+
import type { Locale } from "../locale.ts";
|
|
12
|
+
import type { ServiceStatus } from "./runs.ts";
|
|
13
|
+
import type { NoReason } from "./typegate.ts";
|
|
14
|
+
|
|
15
|
+
export type StandinState = "working" | "blocked" | "idle";
|
|
16
|
+
/** What the stand-in is reported as: its Herdr state and the short message. */
|
|
17
|
+
export interface Standin { state: StandinState; message: string }
|
|
18
|
+
|
|
19
|
+
/** What a look knows that decides the stand-in's state. */
|
|
20
|
+
export interface StandinFacts {
|
|
21
|
+
/** The rule of the typing gate (typegate.ts) that said no at this look. Only `prompt` (the prompt polls, no run) and `run` (a run holds the pane or is about to) can leave the pane to the stand-in. */
|
|
22
|
+
verdict: NoReason;
|
|
23
|
+
/** A run is about to start pi in the pane: the stand-in was released and the prompt told to leave (standing.ts `yieldPane`). */
|
|
24
|
+
leaving: boolean;
|
|
25
|
+
/** The prompt polled lately: it is in the pane. */
|
|
26
|
+
prompt: boolean;
|
|
27
|
+
/** The agent Herdr shows on the pane: none, the stand-in, or another (a run's pi, a pi of the boss's own). */
|
|
28
|
+
agent: "none" | "stand-in" | "other";
|
|
29
|
+
/** A local run of the workspace handles something: it is waking, or live and not idle at its last poll (runs.ts `working`). */
|
|
30
|
+
working: boolean;
|
|
31
|
+
/** The wait cards that wait for the boss here (a tower's own; the head's own at the head), parked ones under auto mode included. */
|
|
32
|
+
cards: number;
|
|
33
|
+
/** A person is at this device: an unattended one has nobody to answer a card. */
|
|
34
|
+
attended: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The stand-in's state at a look, or undefined when the server reports none: the prompt is not in the pane, a run is taking it, or another agent holds it. */
|
|
38
|
+
export function standinState(f: StandinFacts): StandinState | undefined {
|
|
39
|
+
if ((f.verdict !== "prompt" && f.verdict !== "run") || f.leaving || !f.prompt || f.agent === "other") return undefined;
|
|
40
|
+
if (f.cards > 0 && f.attended) return "blocked";
|
|
41
|
+
return f.working ? "working" : "idle";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const WORDS = {
|
|
45
|
+
en: { standing: "standing by", working: "working", held: "held", queued: (n: number) => `${n} queued`, cards: (n: number) => (n === 1 ? "1 card waits" : `${n} cards wait`), elsewhere: (n: number) => (n === 1 ? "1 card waits at another tower" : `${n} cards wait at other towers`) },
|
|
46
|
+
"zh-TW": { standing: "待命中", working: "處理中", held: "已擱置", queued: (n: number) => `${n} 則待處理`, cards: (n: number) => `${n} 張卡片等你`, elsewhere: (n: number) => `其他塔台有 ${n} 張卡片等你` },
|
|
47
|
+
};
|
|
48
|
+
export interface StandinWords { cards?: number; working?: boolean; elsewhere?: number; locale?: Locale }
|
|
49
|
+
/**
|
|
50
|
+
* The message, in sb's language: the cards first, then what the tower does (`working`; `standing by` when nothing but the other towers' cards would be said), then at the head the cards of the other towers (a note
|
|
51
|
+
* that never blocks: a tower's wait is not the head's, AR-D2), then `held` or the queue: `2 cards wait · working · 1 queued`, `standing by · 3 cards wait at other towers`, `standing by`.
|
|
52
|
+
*/
|
|
53
|
+
export function standinMessage(status: Pick<ServiceStatus, "state" | "queued"> | undefined, { cards = 0, working = false, elsewhere = 0, locale = "en" }: StandinWords = {}): string {
|
|
54
|
+
const w = WORDS[locale], tail = status?.state === "held" ? w.held : status && status.queued > 0 ? w.queued(status.queued) : undefined;
|
|
55
|
+
const lead = working ? w.working : cards === 0 && !tail ? w.standing : undefined;
|
|
56
|
+
return [...(cards > 0 ? [w.cards(cards)] : []), ...(lead ? [lead] : []), ...(elsewhere > 0 ? [w.elsewhere(elsewhere)] : []), ...(tail ? [tail] : [])].join(" · ");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The stand-in at a look: its state (`standinState`) and its message, or undefined when the server reports none. */
|
|
60
|
+
export function standinReport(f: StandinFacts & { status: Pick<ServiceStatus, "state" | "queued"> | undefined; elsewhere?: number; locale?: Locale }): Standin | undefined {
|
|
61
|
+
const state = standinState(f);
|
|
62
|
+
return state && { state, message: standinMessage(f.status, { cards: f.cards, working: f.working, elsewhere: f.elsewhere ?? 0, locale: f.locale ?? "en" }) };
|
|
63
|
+
}
|
package/src/server/standing.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Locale } from "../locale.ts";
|
|
|
3
3
|
import { alive as pidAlive } from "../remote.ts";
|
|
4
4
|
import type { Log } from "./log.ts";
|
|
5
5
|
import type { ServiceStatus } from "./runs.ts";
|
|
6
|
+
import { type Standin, standinReport } from "./standin.ts";
|
|
6
7
|
import { giveBackGate, handGate, holdGate, idleShell, nameOf, refusedGate, SHELLS, settleGate, typeGate } from "./typegate.ts";
|
|
7
8
|
|
|
8
9
|
/** Headless runs: how long after a viewer call made its pane the one typing may still happen (Herdr's lost Enter), and the command as typed there, so the viewer takes the shell's place (`exec`) and no shell is left behind it. */
|
|
@@ -63,6 +64,8 @@ export interface StandingTarget {
|
|
|
63
64
|
status(): ServiceStatus | undefined;
|
|
64
65
|
/** How many wait cards wait for the boss here (a tower's own; the head's own): the stand-in is `blocked` while there are any. */
|
|
65
66
|
cards?(): number;
|
|
67
|
+
/** Whether a local run of the workspace handles something now (runs.ts `working`): the stand-in is `working` while it does and no card waits (standin.ts). */
|
|
68
|
+
working?(): boolean;
|
|
66
69
|
/** The head only: how many cards wait at the other towers. Named on the stand-in, never `blocked` (docs/specs/2026-11-21-auto-return.md, AR-D2). */
|
|
67
70
|
elsewhere?(): number;
|
|
68
71
|
/** Whether a run starts in the pane within `ms`: a prompt typed now would only have to start, poll, and leave before the run's pi can. */
|
|
@@ -138,25 +141,6 @@ interface Mine {
|
|
|
138
141
|
unsupported?: number;
|
|
139
142
|
}
|
|
140
143
|
|
|
141
|
-
/** What the stand-in is reported as: its Herdr state and the short message. */
|
|
142
|
-
export interface Standin { state: "idle" | "blocked"; message: string }
|
|
143
|
-
const STANDIN_WORDS = {
|
|
144
|
-
en: { standing: "standing by", held: "held", queued: (n: number) => `${n} queued`, cards: (n: number) => (n === 1 ? "1 card waits" : `${n} cards wait`), elsewhere: (n: number) => (n === 1 ? "1 card waits at another tower" : `${n} cards wait at other towers`) },
|
|
145
|
-
"zh-TW": { standing: "待命中", held: "已擱置", queued: (n: number) => `${n} 則待處理`, cards: (n: number) => `${n} 張卡片等你`, elsewhere: (n: number) => `其他塔台有 ${n} 張卡片等你` },
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* The stand-in (docs/how-it-works.md, The standing pane): `blocked` while wait cards wait for the boss (`cards`: a tower's own, and the head's own at the head), so Herdr's Agents list and its rollups show the tower as
|
|
149
|
-
* waiting on him; `idle` with none, and always on an unattended device, where nobody answers. Auto mode does not change it: the cards still wait, parked, and the page shows them. The message names the cards first, then
|
|
150
|
-
* at the head the cards of the other towers (`elsewhere`, a note that never blocks: a tower's wait is not the head's, AR-D2), then `held` or the queue: `2 cards wait · 1 queued`, `standing by`, in sb's language.
|
|
151
|
-
*/
|
|
152
|
-
export function standinReport(status: Pick<ServiceStatus, "state" | "queued"> | undefined, cards = 0, locale: Locale = "en", attended = true, elsewhere = 0): Standin {
|
|
153
|
-
const w = STANDIN_WORDS[locale], tail = status?.state === "held" ? w.held : status && status.queued > 0 ? w.queued(status.queued) : undefined;
|
|
154
|
-
const parts = [...(cards > 0 ? [w.cards(cards)] : []), ...(elsewhere > 0 ? [w.elsewhere(elsewhere)] : []), ...(tail ? [tail] : [])];
|
|
155
|
-
return { state: cards > 0 && attended ? "blocked" : "idle", message: parts.length ? (cards > 0 || tail || !elsewhere ? parts.join(" · ") : `${w.standing} · ${parts.join(" · ")}`) : w.standing };
|
|
156
|
-
}
|
|
157
|
-
/** The stand-in's message alone, in English with no card: `standing by`, `3 queued`, or `held`. */
|
|
158
|
-
export const standinMessage = (status: Pick<ServiceStatus, "state" | "queued"> | undefined): string => standinReport(status).message;
|
|
159
|
-
|
|
160
144
|
/** The programs in the pane's foreground that are no shell and not the tower prompt: what the boss runs there. Empty when none is listed or all are shells. */
|
|
161
145
|
export function programProcs(info: { foreground_processes?: unknown } | undefined): { pid?: number; name?: string; argv0?: string; cmdline?: string }[] {
|
|
162
146
|
const procs = Array.isArray(info?.foreground_processes) ? (info!.foreground_processes as { pid?: number; name?: string; argv0?: string; cmdline?: string }[]) : [];
|
|
@@ -262,6 +246,7 @@ export function createStanding(o: StandingOptions) {
|
|
|
262
246
|
let command = "";
|
|
263
247
|
// The pane as Herdr lists it at the latest reading: the tick's, and then (just before the typing) a reading of its own, since the tick's may be old by the time an earlier look of the same tick is done.
|
|
264
248
|
let seat = pane;
|
|
249
|
+
const agent = !pane?.agent ? "none" : isStandin(pane) ? "stand-in" : "other";
|
|
265
250
|
const verdict = await typeGate({
|
|
266
251
|
attached,
|
|
267
252
|
// A service that was detached while this look waited (lost, retired) is no seat: it types nothing from a look it had in flight.
|
|
@@ -270,7 +255,7 @@ export function createStanding(o: StandingOptions) {
|
|
|
270
255
|
busy: attached && Boolean(target.paneBusy?.()),
|
|
271
256
|
held: status?.state === "held",
|
|
272
257
|
run: m.leaving || (status !== undefined && ["waking", "running", "closing"].includes(status.state)),
|
|
273
|
-
agent
|
|
258
|
+
agent,
|
|
274
259
|
prompt: () => present(m),
|
|
275
260
|
// The prompt is not there. Herdr clears its label itself a moment after; a release makes it at once.
|
|
276
261
|
gone: () => unreport(m),
|
|
@@ -297,19 +282,25 @@ export function createStanding(o: StandingOptions) {
|
|
|
297
282
|
switch (verdict.reason) {
|
|
298
283
|
case "busy":
|
|
299
284
|
return await lookHeld(m, paneId);
|
|
300
|
-
case "run":
|
|
301
|
-
// A run holds the pane (or is about to): the prompt has left or is leaving, and no stand-in stands over the run's pi.
|
|
302
|
-
if (m.reported && !isStandin(pane)) m.reported = undefined;
|
|
303
|
-
return;
|
|
304
285
|
case "agent":
|
|
305
286
|
// Another agent holds the pane (a pi of the boss's own): the stand-in is not reported over it, and Herdr would not take it.
|
|
306
287
|
m.reported = undefined;
|
|
307
288
|
return;
|
|
289
|
+
case "run":
|
|
308
290
|
case "prompt": {
|
|
309
|
-
|
|
291
|
+
// A prompt that polls with no run ends the boss's Ctrl+D (one he started by hand).
|
|
292
|
+
if (verdict.reason === "prompt") m.parked = false;
|
|
293
|
+
// The state is standin.ts's at every look, a run's included: under headless runs the prompt stays in the pane while the run works, and the state follows the run (working, then idle) and the cards.
|
|
294
|
+
// `leaving` is read here, after the gate's await, and nothing is awaited from here until the report takes its seq: a run's start that released the stand-in meanwhile is seen, and one that releases it after
|
|
295
|
+
// sends a higher seq, which Herdr keeps over this report.
|
|
296
|
+
const next = standinReport({ verdict: verdict.reason, leaving: m.leaving, prompt: present(m), agent, working: Boolean(target.working?.()), cards: target.cards?.() ?? 0, attended: o.attended?.() ?? true, status, elsewhere: target.elsewhere?.() ?? 0, locale: o.locale?.() ?? "en" });
|
|
297
|
+
if (!next) {
|
|
298
|
+
// A run takes the pane, or its pi holds it: the prompt has left or is leaving, and the run's pi is Herdr's pi integration's to report.
|
|
299
|
+
if (m.reported && !isStandin(pane)) m.reported = undefined;
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
310
302
|
if (isStandin(pane)) m.misses = 0;
|
|
311
|
-
|
|
312
|
-
// Reported again when the message or the state changed (a card opened or was answered), and every `refreshMs`.
|
|
303
|
+
// Reported again when the message or the state changed (a card opened or was answered, the run went to work or came to rest), and every `refreshMs`.
|
|
313
304
|
if (!isStandin(pane) || !m.reported || m.reported.message !== next.message || m.reported.state !== next.state || now() - m.reported.at >= t.refreshMs) await report(m, pane, next);
|
|
314
305
|
return;
|
|
315
306
|
}
|
package/src/server/towers.ts
CHANGED
|
@@ -846,7 +846,7 @@ export function createTowers(o: TowersOptions): Towers {
|
|
|
846
846
|
// The head's files are in `head/`, whatever the id of its workspace is. Its runs are the hub's too (runs.ts): they resume one conversation and have the head's tools.
|
|
847
847
|
if (isHeadL(l)) bindDir(slot, record.workspace, headDir(slot));
|
|
848
848
|
runs.attach(refOf(l));
|
|
849
|
-
standing.attach({ workspace: record.workspace, label: () => l.record.label, ...(isHeadL(l) ? { agent: STANDIN_HEAD } : {}), pane: () => l.record.pane, live: () => l.state === "live" && !l.stopped && Boolean(l.client?.isConnected()), seated: (pane) => holds(l, pane), status: () => runs.status(record.workspace), cards: () => cardsFor(l), ...(isHeadL(l) ? { elsewhere: () => cardsElsewhere() } : {}), runWithin: (ms) => runs.startsWithin(record.workspace, ms), paneBusy: () => runs.paneBusy(record.workspace), busyPids: () => runs.busyPids(record.workspace), paneFree: () => runs.retry(record.workspace) }, fresh);
|
|
849
|
+
standing.attach({ workspace: record.workspace, label: () => l.record.label, ...(isHeadL(l) ? { agent: STANDIN_HEAD } : {}), pane: () => l.record.pane, live: () => l.state === "live" && !l.stopped && Boolean(l.client?.isConnected()), seated: (pane) => holds(l, pane), status: () => runs.status(record.workspace), cards: () => cardsFor(l), working: () => runs.working(record.workspace), ...(isHeadL(l) ? { elsewhere: () => cardsElsewhere() } : {}), runWithin: (ms) => runs.startsWithin(record.workspace, ms), paneBusy: () => runs.paneBusy(record.workspace), busyPids: () => runs.busyPids(record.workspace), paneFree: () => runs.retry(record.workspace) }, fresh);
|
|
850
850
|
l.starting = (async () => {
|
|
851
851
|
// A resident tower keeps its workspace; the service registers its identity once that session leaves. Two towers never hold one workspace.
|
|
852
852
|
let waited = false;
|
|
@@ -1356,7 +1356,7 @@ export function createTowers(o: TowersOptions): Towers {
|
|
|
1356
1356
|
// The boss's waits for the list and the polls' digests (waitlist.ts): the head's memory is read under its constant key, a workspace's under its id.
|
|
1357
1357
|
const autoView = () => ((v) => ({ on: v?.on === true, ...(v?.since ? { since: v.since } : {}) }))(o.auto?.view());
|
|
1358
1358
|
const listed = (): Target[] => [...services.values()].filter((l) => !l.stopped && !isHeadL(l)).map((l) => ({ workspace: l.record.workspace, label: l.record.label }));
|
|
1359
|
-
/** The cards that make a stand-in wait (
|
|
1359
|
+
/** The cards that make a stand-in wait (standin.ts `standinState`): a tower's own, the head's own at the head; the other towers' are only named on the head's (`cardsElsewhere`, AR-D2). An unreadable memory counts none. */
|
|
1360
1360
|
const cardsFor = (l: Live): number => openCards(waitRows(slot, isHeadL(l) ? HEAD_KEY : l.record.workspace, now(), isHeadL(l)).rows);
|
|
1361
1361
|
const cardsElsewhere = (): number => listed().reduce((n, t) => n + openCards(waitRows(slot, t.workspace, now(), false).rows), 0);
|
|
1362
1362
|
const api: Towers = {
|