pi-straw-boss 0.121.0 → 0.122.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 +1 -1
- package/package.json +1 -1
- package/src/idlewake.ts +1 -3
- package/src/moments.ts +2 -2
- package/src/rotclose.ts +1 -1
- package/src/server/ledger.ts +1 -1
- package/src/wrapup.ts +17 -18
package/dist/server/main.mjs
CHANGED
|
@@ -3384,7 +3384,7 @@ function createHeadReach({ read: read4, deliver }) {
|
|
|
3384
3384
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
3385
3385
|
import { dirname as dirname4, join as join11 } from "node:path";
|
|
3386
3386
|
var KINDS2 = ["wait_raised", "wait_answered", "wait_closed", "wait_returned", "wait_parked", "link_wait_open", "link_wait_done", "thread_open", "thread_close", "call_tower", "wrap", "handover"];
|
|
3387
|
-
var WHYS2 = { wait_closed: ["resolved", "dropped"], thread_close: ["done", "blocked", "abandoned"], call_tower: ["milestone", "shared", "blocked"], wrap: ["wrapped", "refused", "auto"] };
|
|
3387
|
+
var WHYS2 = { wait_closed: ["resolved", "dropped"], thread_close: ["done", "blocked", "abandoned"], call_tower: ["milestone", "shared", "blocked"], wrap: ["wrapped", "auto-wrapped", "refused", "auto"] };
|
|
3388
3388
|
var BYS = ["terminal", "gui", "phone", "box", "tower"];
|
|
3389
3389
|
var ID = /^[A-Za-z0-9_.:#@+=|-]{1,160}$/;
|
|
3390
3390
|
var ledgerId = (v) => typeof v === "string" && ID.test(v) ? v : null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-straw-boss",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.122.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/idlewake.ts
CHANGED
|
@@ -3,9 +3,7 @@ import { ARM_TEXT, HELD_ARM_TEXT } from "./moments.ts";
|
|
|
3
3
|
import type { Kit } from "./state.ts";
|
|
4
4
|
import type { Probe } from "./stillruns.ts";
|
|
5
5
|
|
|
6
|
-
// An idle wake: a main idle `idleMs` gets one message per idle period, once nothing of it runs.
|
|
7
|
-
// auto mode stops (the boss is away; its clock starts again when he is back), and the standing main's wake when nothing is armed (`armWake`, docs/specs/2026-11-26-standing-prompt.md; boss 2026-11-26
|
|
8
|
-
// 「閒置喚醒的條件也應該不同」), which runs under auto mode too, since a standing main runs unattended. The clock is the session's own: it sees each turn start and end, so the turn a wake starts is not counted as
|
|
6
|
+
// An idle wake: a main idle `idleMs` gets one message per idle period, once nothing of it runs. Coordinator, integrator, worker, and standing wakes run under auto mode too. The clock is the session's own: it sees each turn start and end, so the turn a wake starts is not counted as
|
|
9
7
|
// new work (the server's minute look could not tell them apart).
|
|
10
8
|
|
|
11
9
|
const LOOK_MS = 60_000;
|
package/src/moments.ts
CHANGED
|
@@ -4,11 +4,11 @@ import type { CarState } from "./train/cars.ts";
|
|
|
4
4
|
// the code that chooses one stays where the moment happens. Each names its moment and who reads it. Imports nothing at run time, so the sb server (src/server/) takes its own from here too.
|
|
5
5
|
|
|
6
6
|
/** The idle nudge (idlewake.ts, wired in wrapup.ts): a coordinator or integrator main idle 30 minutes with nothing running. */
|
|
7
|
-
export const NUDGE_TEXT = "sb: you have been idle 30 minutes. Is your work done? If work remains: dispatch your ready todos now; none ready, take your next eligible work; or clean up stale todos. If you wait on someone other than the boss, set that todo's `metadata.waitsOn` (who) and stop. If it is done: answer the intercom asks you owe, remove the worktrees you made, complete or delete every todo, stop your monitors and loops, write a daily memory entry if you have a memory tool, then call boss_wrap with a summary: it asks the boss before this pane closes.";
|
|
7
|
+
export const NUDGE_TEXT = "sb: you have been idle 30 minutes. Is your work done? If work remains: dispatch your ready todos now; none ready, take your next eligible work; or clean up stale todos. If you wait on someone other than the boss, set that todo's `metadata.waitsOn` (who) and stop. If it is done: answer the intercom asks you owe, remove the worktrees you made, complete or delete every todo, stop your monitors and loops, write a daily memory entry if you have a memory tool, then call boss_wrap with a summary: auto mode approves; otherwise it asks the boss before this pane closes.";
|
|
8
8
|
/** The worker's nudge (wrapup.ts): a worker opened for a teammate's device, idle 15 minutes with nothing running and no final report (docs/specs/2026-11-26-ally-workers.md). */
|
|
9
9
|
export const WORKER_NUDGE = "sb: you have been idle 15 minutes. Finish the brief now, or send your final report with call_tower why: milestone (blocked or done): it is your only one, and your pane closes after it. At 60 minutes idle without it the box stops you and keeps your worktree.";
|
|
10
10
|
/** `boss_wrap`'s description (wrapup.ts): every main that has the tool, on every turn. */
|
|
11
|
-
export const WRAP_DESCRIPTION = "
|
|
11
|
+
export const WRAP_DESCRIPTION = "Wrap up a finished main: auto mode approves; otherwise ask the boss here. Send summary as a tower milestone and to your requester, clear your board, close session and pane. Refused with open todos, queued messages, monitors, loops, watches or subagents running, standing duty or teammate turns.";
|
|
12
12
|
/** The standing main's wake (idlewake.ts `armWake`): a standing main idle 2 hours with nothing armed. */
|
|
13
13
|
export const ARM_TEXT = "sb: you have nothing armed (no watch, monitor, or loop). Re-arm what you mind from your handoff or board, or say on your board why nothing needs watching.";
|
|
14
14
|
/** A standing main's lines in every text that brings it back (revive.ts: a revive, a handover; session.ts: a Herdr restart that resumed it): it minds by what it arms, and nothing it armed survived
|
package/src/rotclose.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Reach } from "./reach.ts";
|
|
|
6
6
|
import { ENTRY, type Kit } from "./state.ts";
|
|
7
7
|
import { moveHolds } from "./link/holds.ts";
|
|
8
8
|
|
|
9
|
-
// A main that handed over closes itself (docs/specs/2026-11-26-rotation-close.md). Field, 2026-11-26: after a rotation the old skald main could not close itself (boss_wrap
|
|
9
|
+
// A main that handed over closes itself (docs/specs/2026-11-26-rotation-close.md). Field, 2026-11-26: after a rotation the old skald main could not close itself (boss_wrap was then refused under auto mode, /new is
|
|
10
10
|
// forbidden, no other tool closes a session) and stayed open to forward a child's result. The rotation is the consent: once the successor's own extension says it took over (its call_peer to its caller, the old main, or an intercom send to it,
|
|
11
11
|
// the step successorPrompt asks for, seen as a tool result of a `send` in a local turn, not read from its words) and nothing of the old main runs (no turn, queued message, dialog, monitor, loop, watch, or subagent), sb clears its board
|
|
12
12
|
// and closes it and its pane as /boss close does, under auto mode too. While something runs it looks again each minute (wrapup.ts's look); a child's result that reaches it meanwhile goes to the successor, quoted
|
package/src/server/ledger.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type LedgerKind = (typeof KINDS)[number];
|
|
|
11
11
|
/** Where a boss wait's answer came in: a terminal (pi's `/boss wait` or `/boss memory`, the tower prompt, a run's pane, the dialog of `boss_wait_ask`), this computer's page, a paired phone, a box's controller, or a message the tower took that names it. */
|
|
12
12
|
export type AnsweredBy = "terminal" | "gui" | "phone" | "box" | "tower";
|
|
13
13
|
/** The `why` each kind may carry; the others carry none. */
|
|
14
|
-
const WHYS: Partial<Record<LedgerKind, readonly string[]>> = { wait_closed: ["resolved", "dropped"], thread_close: ["done", "blocked", "abandoned"], call_tower: ["milestone", "shared", "blocked"], wrap: ["wrapped", "refused", "auto"] };
|
|
14
|
+
const WHYS: Partial<Record<LedgerKind, readonly string[]>> = { wait_closed: ["resolved", "dropped"], thread_close: ["done", "blocked", "abandoned"], call_tower: ["milestone", "shared", "blocked"], wrap: ["wrapped", "auto-wrapped", "refused", "auto"] };
|
|
15
15
|
const BYS: readonly string[] = ["terminal", "gui", "phone", "box", "tower"];
|
|
16
16
|
export interface LedgerEvent { kind: LedgerKind; id: string; session?: string | null; workspace?: string | null; why?: string; item?: string; by?: AnsweredBy }
|
|
17
17
|
export interface LedgerRow { v: 1; at: number; kind: LedgerKind; id: string; session: string | null; workspace: string | null; why?: string; item?: string; by?: AnsweredBy }
|
package/src/wrapup.ts
CHANGED
|
@@ -12,8 +12,8 @@ import { createProbe, type ProbeDeps } from "./stillruns.ts";
|
|
|
12
12
|
import { snapshotOfBranch } from "./todo.ts";
|
|
13
13
|
|
|
14
14
|
// Idle wrap-up (docs/specs/2026-11-25-idle-wrap-up.md, part 1; boss 2026-11-25): a coordinator or integrator main idle 30 minutes is asked once whether its work is done (the nudge, an idle wake of idlewake.ts),
|
|
15
|
-
// and `boss_wrap` asks the boss in this pane before it reports, clears the board, and closes the session as /boss close does.
|
|
16
|
-
// A standing main has no end, so no nudge and no boss_wrap: its own wake (idlewake.ts `armWake`) tells it to re-arm what it minds. Each call is a `wrap` event of the ledger (server/ledger.ts)
|
|
15
|
+
// and `boss_wrap` asks the boss in this pane before it reports, clears the board, and closes the session as /boss close does. Auto mode keeps the nudge and approves wrap without a dialog.
|
|
16
|
+
// A standing main has no end, so no nudge and no boss_wrap: its own wake (idlewake.ts `armWake`) tells it to re-arm what it minds. Each call is a `wrap` event of the ledger (server/ledger.ts).
|
|
17
17
|
|
|
18
18
|
export const IDLE_MS = 30 * 60_000, WORKER_IDLE_MS = 15 * 60_000, SUMMARY_MAX = 800, WRAP_MESSAGE = "straw-boss-wrap";
|
|
19
19
|
|
|
@@ -33,15 +33,15 @@ export interface WrapDeps extends ProbeDeps {
|
|
|
33
33
|
export function createWrapUp(kit: Kit, d: WrapDeps) {
|
|
34
34
|
const { pi, cfg, s, me, role, guiDir } = kit, name = () => pi.getSessionName() || s.ownName || me().slice(0, 8), held = () => heldHere(guiDir, cfg.now()) !== undefined; // a held box words the nudge and the wake apart (docs/specs/2026-11-26-device-hold.md)
|
|
35
35
|
const note = (why: string) => noteLedger(guiDir, { kind: "wrap", id: me(), session: me(), workspace: s.at?.workspaceId, why }, cfg.now(), (text) => kit.tell(text, "warning"));
|
|
36
|
-
const noted = <T extends { details: unknown }>(how: Promise<T>) => how.then((r) => { const o = r.details as { wrapped?: boolean; auto?: boolean }; note(o.wrapped ?
|
|
36
|
+
const noted = <T extends { details: unknown }>(how: Promise<T>) => how.then((r) => { const o = r.details as { wrapped?: boolean; auto?: boolean }; note(o.wrapped ? (o.auto ? "auto-wrapped" : "wrapped") : "refused"); return r; }, (error: unknown) => { note("refused"); throw error; });
|
|
37
37
|
const probe = createProbe({ cfg, s, me }, d); // what still runs for this session (stillruns.ts)
|
|
38
|
-
const nudge = idleWake(cfg.now, { idleMs: IDLE_MS, eligible: () => d.duty() === "coordinator" || d.duty() === "integrator", ready: async () => !(await probe.nudge()).length, customType: WRAP_MESSAGE, text: () => (held() ? HELD_NUDGE : NUDGE_TEXT), underAuto:
|
|
38
|
+
const nudge = idleWake(cfg.now, { idleMs: IDLE_MS, eligible: () => d.duty() === "coordinator" || d.duty() === "integrator", ready: async () => !(await probe.nudge()).length, customType: WRAP_MESSAGE, text: () => (held() ? HELD_NUDGE : NUDGE_TEXT), underAuto: true });
|
|
39
39
|
const worker = idleWake(cfg.now, { idleMs: WORKER_IDLE_MS, eligible: () => d.duty() === "worker", ready: async () => !(await probe.strict()).length, customType: WRAP_MESSAGE, text: WORKER_NUDGE, underAuto: true, forLink: true });
|
|
40
40
|
const look = idleWakes(kit, [nudge, armWake(cfg.now, d.duty, probe, held), worker], d.first);
|
|
41
41
|
|
|
42
42
|
type Ctx = Pick<ExtensionContext, "hasUI" | "hasPendingMessages">;
|
|
43
43
|
/** Why this call may not wrap up at all, in the order the checks run; `text` is the summary as one line. */
|
|
44
|
-
const refusal = (text: string
|
|
44
|
+
const refusal = (text: string): string | undefined => {
|
|
45
45
|
if (s.isTower || role() === "tower") return "A tower does not wrap up: it ends with its runs";
|
|
46
46
|
if (role() === "train") return "A train does not wrap up: it ends with its milestone report and the tower closes it";
|
|
47
47
|
if (role() !== "main") return "Only a tab's main agent wraps up; a member's work ends with its main's";
|
|
@@ -50,26 +50,24 @@ export function createWrapUp(kit: Kit, d: WrapDeps) {
|
|
|
50
50
|
if (d.duty() === "worker") return "A worker ends with its one call_tower why: milestone, its final report: the tower closes it then";
|
|
51
51
|
if (s.openedBy?.startsWith("link:")) return `A main opened for a teammate's device (${s.openedBy.slice(0, 40)}) is closed by that device's stop or the tower, not by boss_wrap`;
|
|
52
52
|
if (!text || text.length > SUMMARY_MAX) return `summary is required: one paragraph of 1 to ${SUMMARY_MAX} characters`;
|
|
53
|
-
if (s.autoOn()) return "auto mode: the boss is away; wrap up when he is back";
|
|
54
|
-
if (!c.hasUI) return "This session has no terminal to ask the boss in";
|
|
55
53
|
};
|
|
56
54
|
/** What would be lost by closing: asked before the boss is, and again after his yes, since the dialog may stand for hours (a message queued, a monitor a parallel call started; RV-F001). */
|
|
57
55
|
const notReady = async (c: Ctx) => {
|
|
58
56
|
const open = (todosOf(snapshotOfBranch(s.branch())) ?? []).filter((t) => t.status !== "completed");
|
|
59
57
|
return [...(open.length ? [`open todos ${open.map((t) => `#${t.id}`).join(", ")}: complete or delete each (a task you reported blocked to its owner: delete it)`] : []), ...(c.hasPendingMessages() ? ["messages wait in your queue: read them first"] : []), ...(await probe.wrap())];
|
|
60
58
|
};
|
|
61
|
-
/**
|
|
62
|
-
const finish = async (text: string) => {
|
|
63
|
-
const line = `${name()} (session ${me()}) wrapped up, the boss agreeing: ${text}`;
|
|
59
|
+
/** Approved and nothing runs: the milestone, the opener, the board, the close. */
|
|
60
|
+
const finish = async (text: string, auto: boolean) => {
|
|
61
|
+
const line = `${name()} (session ${me()}) wrapped up, ${auto ? "auto mode approving" : "the boss agreeing"}: ${text}`;
|
|
64
62
|
try { await d.reach.callTower(line, undefined, false, "milestone"); } catch (error) {
|
|
65
|
-
return reply(`The tower did not take the wrap-up milestone (${(error as Error).message}): nothing closed. Try boss_wrap again later
|
|
63
|
+
return reply(`The tower did not take the wrap-up milestone (${(error as Error).message}): nothing closed. Try boss_wrap again later.`, { wrapped: false });
|
|
66
64
|
}
|
|
67
65
|
const opener = s.openedBy && !s.openedBy.includes(":") ? s.openedBy : undefined;
|
|
68
66
|
const told = opener ? (await d.reach.send(opener, line).catch(() => ({ status: "failed" }))).status === "sent" : undefined;
|
|
69
67
|
try { d.boardFill.clear(); } catch { /* no board to clear */ }
|
|
70
68
|
const refused = d.closeSelf(false);
|
|
71
69
|
if (refused) return reply(`Told the tower and cleared the board, but the session did not close: ${refused}`, { wrapped: false });
|
|
72
|
-
return reply(`Wrapped up: the tower has your summary${opener ? (told ? ", and so does the session that asked for this main" : `; the session that asked for this main (${opener}) did not take it`) : ""}, and your board is cleared. This session quits when this turn ends and its pane closes: end your turn now.`, { wrapped: true });
|
|
70
|
+
return reply(`Wrapped up: the tower has your summary${opener ? (told ? ", and so does the session that asked for this main" : `; the session that asked for this main (${opener}) did not take it`) : ""}, and your board is cleared. This session quits when this turn ends and its pane closes: end your turn now.`, { wrapped: true, ...(auto && { auto }) });
|
|
73
71
|
};
|
|
74
72
|
|
|
75
73
|
return {
|
|
@@ -82,16 +80,17 @@ export function createWrapUp(kit: Kit, d: WrapDeps) {
|
|
|
82
80
|
name: "boss_wrap", label: "boss_wrap", description: WRAP_DESCRIPTION,
|
|
83
81
|
parameters: Type.Object({ summary: Type.String({ description: `What this session finished: one paragraph, at most ${SUMMARY_MAX} characters.` }) }),
|
|
84
82
|
execute: (_id, { summary }, _signal, _update, c) => noted((async () => {
|
|
85
|
-
const text = summary.replace(/\s+/g, " ").trim(), refused = refusal(text
|
|
83
|
+
const text = summary.replace(/\s+/g, " ").trim(), refused = refusal(text);
|
|
86
84
|
if (refused) throw new Error(refused);
|
|
87
85
|
const why = await notReady(c);
|
|
88
86
|
if (why.length) throw new Error(`Not ready to wrap up: ${why.join("; ")}.`);
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
87
|
+
if (s.autoOn()) return finish(text, true);
|
|
88
|
+
if (!c.hasUI) throw new Error("This session has no terminal to ask the boss in");
|
|
89
|
+
const yes = await c.ui.confirm(`Wrap up ${name()}?`, text), auto = s.autoOn();
|
|
90
|
+
if (!yes && !auto) return (nudge.clock.hold(), reply("The boss said not now: nothing closed. Keep this session open and do nothing more about wrapping up; sb does not ask again until you have worked again.", { wrapped: false }));
|
|
92
91
|
const since = await notReady(c);
|
|
93
|
-
if (since.length) return reply(
|
|
94
|
-
return finish(text);
|
|
92
|
+
if (since.length) return reply(`${auto ? "Auto mode approved" : "The boss said yes"}, but while he was asked: ${since.join("; ")}. Nothing closed and nothing was sent: handle them, then call boss_wrap again.`, { wrapped: false });
|
|
93
|
+
return finish(text, auto);
|
|
95
94
|
})()),
|
|
96
95
|
});
|
|
97
96
|
},
|