pi-straw-boss 0.80.11 → 0.80.12
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/package.json +1 -1
- package/src/briefing.ts +67 -23
- package/src/closemain.ts +1 -1
- package/src/session.ts +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-straw-boss",
|
|
3
|
-
"version": "0.80.
|
|
3
|
+
"version": "0.80.12",
|
|
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/briefing.ts
CHANGED
|
@@ -10,6 +10,9 @@ const GRAPH_ADDENDUM: Partial<Record<Graph, string>> = { "fan-out/fan-in": "grap
|
|
|
10
10
|
|
|
11
11
|
/** What a run was briefed with: the role, a main's kind, and the graph a coordinator's plan named (an integrator and a standing main carry `dispatch.md` whatever their plan says, so they have none here). */
|
|
12
12
|
interface Briefed { role: Role | undefined; duty: string; graph: Graph | "" }
|
|
13
|
+
/** A steer's `details`: what it tells, and what it was written against (`null`: it replaces the whole role prompt, whatever the model held). */
|
|
14
|
+
interface Told { briefed: Briefed; base: Briefed | null }
|
|
15
|
+
const same = (a: Briefed, b: Briefed) => a.role === b.role && a.duty === b.duty && a.graph === b.graph;
|
|
13
16
|
|
|
14
17
|
/** The role prompt: a system prompt section, set when a run starts, and a steer when the role, the kind, or a coordinator's plan changes during one. */
|
|
15
18
|
export function createBriefing({ pi, cfg, s, role, guiDir, tell }: Kit, mainDuty: MainDuty) {
|
|
@@ -27,43 +30,84 @@ export function createBriefing({ pi, cfg, s, role, guiDir, tell }: Kit, mainDuty
|
|
|
27
30
|
const duty = role() === "main" ? mainDuty.now() : "";
|
|
28
31
|
return { role: role(), duty, graph: duty === "coordinator" ? (mainDuty.graph() ?? "") : "" };
|
|
29
32
|
};
|
|
30
|
-
// The role's prompt is a system prompt section, set when a run starts. A role that changes during a run (a member promoted as it
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
+
// The role's prompt is a system prompt section, set when a run starts. A role that changes during a run (a member promoted as it dispatches a subagent, mains demoted as their tower quits),
|
|
34
|
+
// a kind that switches, or a plan that names a graph reaches the agent at its next step as a steer; an idle session gets it with its next run.
|
|
35
|
+
// A section that changes is read with the whole context uncached, so a run start keeps it while only the graph moved, and steers the change instead (docs/how-it-works.md, The role section stays put);
|
|
36
|
+
// it is rendered anew (`stale`) where the cache or the steers are gone anyway. `sectioned` is what the section was rendered with, which pi keeps for the whole run, through its compactions.
|
|
37
|
+
// `told` is what the agent holds: the section, then each steer pi delivered (its `message_end`), never one only sent, since pi's queue can drop it first (Esc, the dequeue key, the sb GUI's Edit).
|
|
38
|
+
// One steer waits in the queue at a time (`flight`), and a change meanwhile is written once it arrived, against what it told. A steer an abort left queued arrives at the next run's start, after that run's
|
|
39
|
+
// own was written against the older state: `told` is unknown (`undefined`) then, and the next steer is the whole prompt.
|
|
40
|
+
let idle = () => false, told: Briefed | undefined, sectioned: Briefed | undefined, flight: Told | undefined, running = false, stale = false;
|
|
33
41
|
// `dir` is the folder of the files the prompt points to (the switch of trainswitch.ts may give a copy), `state` the state folder, whose `trains` folder holds an integrator's ledgers, `cli` the command that runs cli.mjs (`train check`). What a prompt may name is this session's own (its tab's label, its workspace's label, its kind) or fixed for the process, never another session's name or state: the tower's or the main's name in the section rewrote it whenever that session left, came back, or renamed itself, and a rewritten section is read with the whole context uncached; `boss_status` has the live values (docs/how-it-works.md, The role section stays put).
|
|
34
42
|
const render = (text = "", duty = "") => text.replace(/\{\{(\w+)\}\}/g, (_, key: string) => ({ dir: files ? files.dir : cfg.promptDir, state: guiDir, cli: cliCommand(), tab: s.info.tab, workspace: s.info.workspace, head: s.info.head, duty } as Record<string, string | undefined>)[key] || "none yet");
|
|
35
43
|
const compose = (parts: string[], duty: string) => render(parts.map((part) => prompts[part]).join("\n\n"), duty);
|
|
36
|
-
|
|
44
|
+
// A compaction that retries no turn gets the message stored, not steered: a steer queued then would make pi continue a run that had ended (runmode.ts does the same with a run's brief).
|
|
45
|
+
let quiet = false;
|
|
46
|
+
// A stored message is in the transcript at the turn's end, and pi reports it to no extension: it is told as it is sent. So is a steer sent while pi is idle (awaiting `agent_settled` handlers, or after a run
|
|
47
|
+
// that failed to start past `before_agent_start`): pi stores it at once (`_appendCustomMessage`), with no `message_end`.
|
|
48
|
+
const steer = (text: string, base: Briefed | null, briefed: Briefed) => {
|
|
49
|
+
const details: Told = { briefed, base };
|
|
50
|
+
pi.sendMessage({ customType: ENTRY, content: `<straw-boss>\n${text}\n</straw-boss>`, display: true, details }, quiet ? { triggerTurn: false } : { deliverAs: "steer" });
|
|
51
|
+
if (quiet || idle()) told = briefed;
|
|
52
|
+
else flight = details;
|
|
53
|
+
};
|
|
54
|
+
/** Steers what changed from `was` to `now`, if anything: a role or a kind gets its whole prompt, which replaces the section's, as does an unknown `was`; a coordinator's graph only what it adds, replaces, or drops (§2a). */
|
|
55
|
+
const steerChange = (was: Briefed | undefined, now: Briefed) => {
|
|
56
|
+
const name = nameOf(now.role);
|
|
57
|
+
if (!name || (was && same(was, now))) return;
|
|
58
|
+
const whole = (lead: string) => steer(`${lead} This replaces the role instructions in your system prompt:\n\n${compose(partsOf(name, now.duty, now.graph), now.duty)}`, null, now);
|
|
59
|
+
if (!was) return whole("Some of your Straw Boss role updates were lost or reached you out of order.");
|
|
60
|
+
if (now.role !== was.role) return whole("Your Straw Boss role changed during this run.");
|
|
61
|
+
if (now.duty !== was.duty) return whole(`Your kind is now ${now.duty}.`);
|
|
62
|
+
const addendum = now.graph ? GRAPH_ADDENDUM[now.graph] : undefined, graph = (text: string) => steer(text, was, now);
|
|
63
|
+
if (!now.graph) return graph(`Your plan has no open graph: drop your "## Dispatch" and "## Graph:" sections.`);
|
|
64
|
+
if (!was.graph) return graph(`Your plan's graph is now ${now.graph}. Add to your instructions:\n\n${compose(["dispatch", ...(addendum ? [addendum] : [])], now.duty)}`);
|
|
65
|
+
if (!addendum) return graph(`Your plan's graph is now ${now.graph}. Drop your "## Graph:" section.`);
|
|
66
|
+
graph(`Your plan's graph is now ${now.graph}. ${GRAPH_ADDENDUM[was.graph] ? 'Replace your "## Graph:" section with' : "Add to your instructions"}:\n\n${compose([addendum], now.duty)}`);
|
|
67
|
+
};
|
|
68
|
+
/** Tells a running agent what changed since what it holds, unless a steer still waits in pi's queue. */
|
|
69
|
+
const rebrief = () => void (running && !flight && steerChange(told, stateOf()));
|
|
37
70
|
return {
|
|
38
|
-
|
|
71
|
+
/** `isIdle` is pi's idle signal (`ctx.isIdle`) of the session that started. */
|
|
72
|
+
load(isIdle: () => boolean = () => false) {
|
|
73
|
+
idle = isIdle;
|
|
39
74
|
files = promptSet({ promptDir: cfg.promptDir, stateDir: guiDir, env: cfg.env, warn: (text) => tell(text, "warning") });
|
|
40
75
|
prompts = Object.fromEntries(PROMPTS.map((name) => [name, files!.read(name)]));
|
|
76
|
+
[told, sectioned, flight, running, stale] = [undefined, undefined, undefined, false, false]; // a session start: the next run renders the section anew
|
|
41
77
|
},
|
|
42
78
|
/** Whether the loaded prompts have integration off; before they are loaded, the switch is read as `promptSet` will read it. */
|
|
43
79
|
off: () => files?.off,
|
|
44
80
|
/** The folder of the files the prompts point to. */
|
|
45
81
|
dir: () => (files ? files.dir : cfg.promptDir),
|
|
46
|
-
rebrief
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
82
|
+
rebrief,
|
|
83
|
+
/** pi delivered a message. A steer of this briefing moves what the agent holds to what it tells, when it was written against what the agent held, or tells what it holds already; else what it holds is unknown. */
|
|
84
|
+
delivered(message: { role?: string; customType?: string; details?: unknown }) {
|
|
85
|
+
const d = message.details as Told | undefined;
|
|
86
|
+
if (message.role !== "custom" || message.customType !== ENTRY || !d?.briefed) return;
|
|
87
|
+
const fits = d.base === null || (told !== undefined && (same(d.base, told) || same(d.briefed, told)));
|
|
88
|
+
[told, flight] = [fits ? d.briefed : undefined, flight === d ? undefined : flight];
|
|
89
|
+
rebrief();
|
|
90
|
+
},
|
|
91
|
+
/** The section is rendered anew at the next run start: a compaction or a tree move, as a session start (`load`), left no cache for it, or no steers after it.
|
|
92
|
+
* A run that goes on after a compaction keeps its section, and is told again, at each compaction, what changed since that section was rendered: the steers that said it may be summarized away. */
|
|
93
|
+
fresh(retries = true) {
|
|
94
|
+
stale = true;
|
|
95
|
+
if (!running || !sectioned) return;
|
|
96
|
+
[told, quiet] = [sectioned, !retries];
|
|
97
|
+
rebrief();
|
|
98
|
+
quiet = false;
|
|
60
99
|
},
|
|
61
|
-
/** A run starts: the role's prompt becomes the session's section. */
|
|
100
|
+
/** A run starts: the role's prompt becomes the session's section, or stays it while only the plan's graph moved since it was rendered, and the move is steered once. */
|
|
62
101
|
begin(sections: Record<string, string>) {
|
|
63
102
|
const now = stateOf(), name = nameOf(now.role);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
103
|
+
const kept = (b: Briefed | undefined) => b !== undefined && b.role === now.role && b.duty === now.duty;
|
|
104
|
+
const keep = Boolean(name) && !stale && kept(sectioned) && kept(told);
|
|
105
|
+
if (!name) delete sections[ENTRY];
|
|
106
|
+
else sections[ENTRY] = compose(partsOf(name, now.duty, keep ? sectioned!.graph : now.graph), now.duty);
|
|
107
|
+
if (!keep) [sectioned, told, stale] = [name ? now : undefined, now, false];
|
|
108
|
+
// A steer the last run left undelivered was dropped from pi's queue or waits for this run's start: it is not told, and if it arrives, `delivered` weighs it.
|
|
109
|
+
[running, flight] = [true, undefined];
|
|
110
|
+
rebrief();
|
|
67
111
|
},
|
|
68
112
|
settled: () => void (running = false),
|
|
69
113
|
};
|
package/src/closemain.ts
CHANGED
|
@@ -47,7 +47,7 @@ export function createCloseMain({ pi, cfg, s, me }: Kit, { closeSelf, check, tur
|
|
|
47
47
|
if (!workspace?.tokens?.tower || workspace.tokens.tower !== from) return no("the request is not from the tower of this workspace");
|
|
48
48
|
const running = subagents(mine, all, cfg.now()).filter((row) => !row.ended).length;
|
|
49
49
|
const subs = running && `${running} subagent${running > 1 ? "s are" : " is"} running`;
|
|
50
|
-
// An interrupt aborts the turn in flight, and only that: a dialog, a monitor or a subagent is work the abort does not end, so they still refuse. A queue that survives the abort is another busy answer at the next ask.
|
|
50
|
+
// An interrupt aborts the turn in flight, and only that: a dialog, a monitor or a subagent is work the abort does not end, so they still refuse. A queue that survives the abort (pi's TUI clears it; an RPC or SDK abort does not) is another busy answer at the next ask.
|
|
51
51
|
if (interrupt && turn?.running()) {
|
|
52
52
|
const others = [turn.blockers(), subs].filter(Boolean).join(", ");
|
|
53
53
|
if (others) return { reason: others, busy: true };
|
package/src/session.ts
CHANGED
|
@@ -116,7 +116,7 @@ export function registerSession(kit: Kit, { mainDuty, runMode, briefing, roles,
|
|
|
116
116
|
s.ui = ctx.ui;
|
|
117
117
|
s.hasUI = ctx.hasUI;
|
|
118
118
|
s.quit = () => ctx.shutdown();
|
|
119
|
-
briefing.load();
|
|
119
|
+
briefing.load(() => { try { return ctx.isIdle(); } catch { return false; } }); // a replaced session's context throws
|
|
120
120
|
s.saved = Object.assign({}, ...ctx.sessionManager.getBranch().flatMap((e) => (e.type === "custom" && e.customType === ENTRY ? [e.data] : [])));
|
|
121
121
|
s.duty = isCoordinatorDuty(s.saved.duty) ? s.saved.duty : undefined; // the migration's guard is this live value (docs/specs/2026-11-09-agent-kinds.md §2)
|
|
122
122
|
s.branch = () => ctx.sessionManager.getBranch();
|
|
@@ -292,6 +292,10 @@ export function registerSession(kit: Kit, { mainDuty, runMode, briefing, roles,
|
|
|
292
292
|
// A rename from any source (boss_rename, /name, another extension) can make this main an integrator (§2); its todos are read again after each todo call.
|
|
293
293
|
pi.on("session_info_changed", (event) => void (!runMode.active() && mainDuty.migrate((event as { name?: string }).name)));
|
|
294
294
|
pi.on("agent_settled", () => void (!runMode.active() && briefing.settled()));
|
|
295
|
+
pi.on("message_end", (event) => void (!runMode.active() && briefing.delivered(event.message))); // a role steer counts as told once pi delivers it (briefing.ts `told`)
|
|
296
|
+
// A compaction drops the cache and may summarize the steers away, and a tree move may leave them on another branch: the next run renders the role section anew (briefing.ts `fresh`).
|
|
297
|
+
pi.on("session_compact", (event) => void (!runMode.active() && briefing.fresh(event.willRetry)));
|
|
298
|
+
pi.on("session_tree", () => void (!runMode.active() && briefing.fresh()));
|
|
295
299
|
|
|
296
300
|
// A member that dispatches or resumes a subagent without promoting is promoted here, before the subagent starts, unless the tab already has a main.
|
|
297
301
|
// A tower only coordinates: it dispatches no subagent (one would outlive it with no one to take its result), and opens a main for the work instead.
|