pi-straw-boss 0.81.0 → 0.81.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-straw-boss",
3
- "version": "0.81.0",
3
+ "version": "0.81.1",
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
@@ -1,3 +1,4 @@
1
+ import type { SessionEntry } from "@earendil-works/pi-coding-agent";
1
2
  import type { Graph } from "./duty.ts";
2
3
  import type { MainDuty } from "./mainduty.ts";
3
4
  import { cliCommand } from "./server/version.ts";
@@ -28,15 +29,16 @@ export function createBriefing({ pi, cfg, s, role, guiDir, tell }: Kit, mainDuty
28
29
  const current = role(), duty = current === "main" ? mainDuty.now() : "";
29
30
  return { name: current === "member" && !s.mainId ? "member-no-main" : current, duty, graph: duty === "coordinator" ? (mainDuty.graph() ?? "") : "" };
30
31
  };
31
- // A rewritten section invalidates the system prompt cache. Pin the rendered bytes at the first run, except for an explicit boss_duty change.
32
+ // A rewritten section invalidates the system prompt cache. Pin the rendered bytes at the first run with a role, except for an explicit boss_duty change.
32
33
  // The section never contains a coordinator's graph. Role and graph changes, including ones on a different branch, reach the agent as messages.
33
34
  // `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).
34
35
  // 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
35
36
  // own was written against the older state: `told` is unknown (`undefined`) then, and the next steer is the whole prompt.
36
37
  let idle = () => false, told: Briefed | undefined, flight: Told | undefined, running = false, rewriteKind = false;
37
- let section: { base: Briefed; text: string | undefined } | undefined, labels: typeof s.info | undefined;
38
- // Keep the first labels for custom templates as well as the shipped ones. Live labels come from boss_status.
39
- const compose = ({ name, duty, graph }: Briefed, parts = name ? partsOf(name, duty, graph) : []) => parts.map((part) => prompts[part]).join("\n\n").replace(/\{\{(\w+)\}\}/g, (_, key: string) => ({ dir: files ? files.dir : cfg.promptDir, state: guiDir, cli: cliCommand(), ...labels, duty } as Record<string, string | undefined>)[key] || "none yet");
38
+ let section: { base: Briefed; text: string } | undefined, labels: typeof s.info | undefined;
39
+ // Keep the first role's labels for custom templates too. A steer before pinning uses the same fields, read live.
40
+ const labelsOf = () => ({ tab: s.info.tab, workspace: s.info.workspace, head: s.info.head });
41
+ const compose = ({ name, duty, graph }: Briefed, parts = name ? partsOf(name, duty, graph) : []) => parts.map((part) => prompts[part]).join("\n\n").replace(/\{\{(\w+)\}\}/g, (_, key: string) => ({ dir: files ? files.dir : cfg.promptDir, state: guiDir, cli: cliCommand(), ...(labels ?? labelsOf()), duty } as Record<string, string | undefined>)[key] || "none yet");
40
42
  // 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).
41
43
  let quiet = false;
42
44
  // 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
@@ -90,16 +92,17 @@ export function createBriefing({ pi, cfg, s, role, guiDir, tell }: Kit, mainDuty
90
92
  rebrief();
91
93
  quiet = false;
92
94
  },
93
- begin(sections: Record<string, string>) {
95
+ begin(sections: Record<string, string>, branch: () => readonly SessionEntry[]) {
94
96
  const now = stateOf();
95
- if (!section || (rewriteKind && now.name === "main" && section.base.duty !== now.duty)) {
96
- labels ??= { tab: s.info.tab, workspace: s.info.workspace, head: s.info.head };
97
+ if (now.name && (!section || (rewriteKind && now.name === "main" && section.base.duty !== now.duty))) {
98
+ labels ??= labelsOf();
97
99
  const base: Briefed = { ...now, graph: "" };
98
- if (told === section?.base && !flight) told = base; // no earlier steer to supersede the new section
99
- section = { base, text: base.name ? compose(base) : undefined };
100
+ // On the first pin, an earlier instance's steer may still override the section. Leave `told` unknown so we replace it in a message.
101
+ if (told === section?.base && !flight && (section || !branch().some((e) => e.type === "custom_message" && e.customType === ENTRY && (e.details as Partial<Told> | undefined)?.briefed))) told = base;
102
+ section = { base, text: compose(base) };
100
103
  }
101
- if (section.text === undefined) delete sections[ENTRY];
102
- else sections[ENTRY] = section.text;
104
+ if (section) sections[ENTRY] = section.text;
105
+ else delete sections[ENTRY];
103
106
  // An undelivered steer was dropped or waits for this run's start: if it arrives, `delivered` weighs it against what the agent holds.
104
107
  [running, flight, rewriteKind] = [true, undefined, false];
105
108
  rebrief();
package/src/runmode.ts CHANGED
@@ -505,7 +505,7 @@ export function createRunMode(kit: Kit, look: ServerLook | undefined, deps: RunS
505
505
  });
506
506
  // A compaction folds the brief into its summary with the rest: the session is given it again, behind the summary (stored without a turn of its own; steered into the turn only when the compaction retries one).
507
507
  pi.on("session_compact", (event) => { const brief = currentBrief(); if (brief) pi.sendMessage(liveBrief(brief), event.willRetry ? { deliverAs: "steer" } : { triggerTurn: false }); });
508
- pi.on("session_tree", () => void (briefSent = undefined));
508
+ pi.on("session_tree", () => { briefSent = undefined; keep(); });
509
509
  /** A pane the server owns: this pi quits with the server's reason. */
510
510
  const quitPane = (context: ExtensionContext, reason?: string) => {
511
511
  mode = "run";
package/src/session.ts CHANGED
@@ -281,11 +281,11 @@ export function registerSession(kit: Kit, { mainDuty, runMode, briefing, roles,
281
281
  });
282
282
 
283
283
  // The tower's run starts with what happened in its workspace since its last run, and the digest is cleared as it is read.
284
- pi.on("before_agent_start", async (event) => {
284
+ pi.on("before_agent_start", async (event, ctx) => {
285
285
  if (runMode.active()) return;
286
286
  const sections = event.systemPromptOptions.sections;
287
287
  mainDuty.migrate(pi.getSessionName()); // a main's signs: its name and its train todos, read before the prompt is built
288
- briefing.begin(sections);
288
+ briefing.begin(sections, () => ctx.sessionManager.getBranch());
289
289
  if (!s.holdsTower || !sections[ENTRY]) return;
290
290
  const lines = await digest.take(s.at.workspaceId).catch(() => []);
291
291
  if (lines.length) return { message: { customType: ENTRY, content: `Since your last run:\n${lines.map((line) => `- ${line}`).join("\n")}`, display: false } };