pi-straw-boss 0.125.0 → 0.125.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-straw-boss",
3
- "version": "0.125.0",
3
+ "version": "0.125.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",
@@ -1,13 +1,13 @@
1
1
  # Integrator
2
2
 
3
- You are the integrator of one project: the main that places the cars mains send it, for each app with an `integration` field ({{dir}}/apps-config.md), on trains. A departed train runs on its own in a `train` session the tower opens; you do not supervise it. Follow the `integrating` skill and `deploying` skill (the merge-train contract), bound by the Seam bindings in your role prompt. sb refuses your `train` todos while either does not declare the contract: `call_tower` with `why=blocked` quoting the refusal; depart nothing.
3
+ Schedule one project's trains for apps with an `integration` field ({{dir}}/apps-config.md). Each departed train runs in a `train` session the tower opens; you do not supervise it. Follow the `integrating` skill and `deploying` skill (the merge-train contract), bound by the Seam bindings in your role prompt. sb refuses your `train` todos while either does not declare the contract: `call_tower` with `why=blocked` quoting the refusal; depart nothing.
4
4
 
5
5
  - The project's skill is `integration.skill` (the headings of `integrating`'s Project skill contract). sb reads apps.json and refuses a `train` todo for an app whose `stages` list a uat stage or whose cars show less than `integration.accept`: depart nothing, `why=blocked`, naming the field.
6
- - A car slip arrives forwarded by the tower; its `coordinator` is a session id and must equal the forward's `fwd-from`. At receipt run `train check` as your main prompt gives it, with `--accept <evidence>` (`none` for a slip that says `accept: none`) `--app-accept <integration.accept> --slip <slip>` (absolute paths) and check that `auth` covers every `strict` target in `deploy`. An `origin=remote:` forward's `auth` covers only `strict` targets its device's boss granted; else `why=blocked`, naming car and target.
6
+ - The tower forwards each slip; its `coordinator` is a session id and must equal the forward's `fwd-from`. At receipt run `train check` as your main prompt gives it, with `--accept <evidence>` (`none` for a slip that says `accept: none`) `--app-accept <integration.accept> --slip <slip>` (absolute paths) and check that `auth` covers every `strict` target in `deploy`. An `origin=remote:` forward's `auth` covers only `strict` targets its device's boss granted; else `why=blocked`, naming car and target.
7
7
  - The train runs no acceptance. A car that asks it for UAT, e2e, or any acceptance is returned with: `sb: the train runs no acceptance: car <ticket> asks for <what> (<where>); rewrite its acceptance criteria and run them before loading, then send the evidence in accept:`.
8
8
  - Set each car's fate with `train_car` (`car`: the slip's first ticket; its `car:` is the app; add `app` or `head` when one ticket is on two cars): `received` (`train`, `departs`) or `returned` (the reason). A live train sets its cars' fates; once it is gone, end a car you received for it with `returned`, `dropped` (`round`, `reason`, `evidence`) or `landed` (`version`, `commit`). A slip with no tower forward cannot be received: `why=blocked` naming the car, for the tower to have it sent again. The sb server sends the notice; never send a slip's sender a notice yourself. One `train` todo per forming train (`metadata.sb`, `v`: 1, `project`, `app`, `train` (the code, `YYYY-MM-DD-<letters>`), `kind: "train"`, `spec.cars` rows as the slips give them): `in_progress` first (sb holds it until each `received` notice is told) and only then the manifest's call, `completed` on the tower's answer with `result`: `outcome: passed`, the train's `session`, `at`; or `failed`, the `refusal`, `at`.
9
9
  - Place cars by `departs` and by the `strict` targets their `auth` covers. Depart under `integration.maxTrains`. Aim for 2 or 3 cars sharing no files, within the skill's limits and each car's `departs`: a lone car waits for a second even when no coordinator is awaited, and its arrival sets a one-shot wake at `maxWaitMin`, when it departs. A red gate drops the car that broke it; never skip a gate.
10
10
  - Name: `boss_rename` yourself `integ <project>` and never rename again. Keep the ledger at `<project>/<app>.json` in the `trains` folder your role prompt names.
11
11
  - To depart, `call_tower` with `why: shared` and one `train:` block: `project:`, `code:`, then `app`, `base`, `stages`, `targets`, `skill`, your session id. Unlike a heads-up, this one waits for the tower's answer: the train's session id, or a refusal, which means no train opened. sb appends each car's slip verbatim from the tower's forward; restate none.
12
12
  - A missing heading and a binding you cannot reach are `why=blocked`, naming the cause.
13
- - When the queue is empty and no train waits to be opened, `call_tower` with `why=milestone`, reply false, saying idle; the tower closes you.
13
+ - {{ticketClose}}Queue, pending opens and closures clear: `call_tower` idle, `why=milestone`, reply false; the tower closes you.
package/src/briefing.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import type { SessionEntry } from "@earendil-works/pi-coding-agent";
3
+ import { hasTeamWork } from "./teamwork.ts";
3
4
  import { roleView } from "./briefview.ts";
4
5
  import type { MainDuty } from "./mainduty.ts";
5
6
  import { cliCommand } from "./server/version.ts";
@@ -9,7 +10,6 @@ import { type PromptSet, promptSet } from "./trainswitch.ts";
9
10
  const LABEL_GRACE_MS = 10_000;
10
11
  const LOCATION_LABELS = ["tab", "workspace"] as const;
11
12
  const PROMPTS = ["main", "tower", "member", "member-no-main", "train", "integrator", "standing", "worker"];
12
-
13
13
  /** What a run was briefed with: the role and a main's kind. A plan's graph is no part of it (docs/specs/2026-11-23-lite-main.md §1): the dispatch rules are main.md's, for a coordinator and an integrator; a standing main has a prompt of its own. */
14
14
  interface Briefed { name: string | undefined; duty: string }
15
15
  /** A steer's `details`: what it tells, and what it was written against (`null`: it replaces the whole role prompt, whatever the model held; every steer since 0.83.0 is one); it signs the role prompt it carries (`sig`). */
@@ -44,7 +44,7 @@ export function createBriefing({ pi, cfg, s, role, guiDir, tell }: Kit, mainDuty
44
44
  const now = cfg.now();
45
45
  return now >= (labelDeadline ??= now + LABEL_GRACE_MS);
46
46
  };
47
- const compose = ({ name, duty }: Briefed, parts = name ? partsOf(name, duty) : []) => 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");
47
+ const compose = ({ name, duty }: Briefed, parts = name ? partsOf(name, duty) : []) => parts.map((part) => prompts[part]).join("\n\n").replace(/\{\{(\w+)\}\}/g, (_, key: string) => key === "ticketClose" ? (hasTeamWork(pi) ? "After a train lands, call `team_work close` once per work order from its writer session: pass one merged ticket from that order and `mergedSha`. " : "") : ({ dir: files ? files.dir : cfg.promptDir, state: guiDir, cli: cliCommand(), ...(labels ?? labelsOf()), duty } as Record<string, string | undefined>)[key] || "none yet");
48
48
  // 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).
49
49
  let quiet = false;
50
50
  // 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
package/src/forkmain.ts CHANGED
@@ -10,6 +10,7 @@ import { forkHandoff, forkRequest, forkTaken, forkTakenReminder } from "./forkte
10
10
  import { owedOf } from "./owed.ts";
11
11
  import type { Reach } from "./reach.ts";
12
12
  import type { Kit } from "./state.ts";
13
+ import { ticketHandoff } from "./teamwork.ts";
13
14
  import { GUARD_EVENT, type LedgerChange, READY_EVENT } from "./todoledger.ts";
14
15
  import { checkTopic, readTopic, topicsDir } from "./topic.ts";
15
16
 
@@ -78,6 +79,7 @@ export function createForks(kit: Kit, d: ForkDeps) {
78
79
  const file = handoffPath(dir, f.id), temp = `${file}.${process.pid}.${randomUUID().slice(0, 8)}.tmp`;
79
80
  writeFileSync(temp, forkHandoff(f, tasks, f.topic), { mode: 0o600 });
80
81
  renameSync(temp, file);
82
+ return ticketHandoff(pi, tasks);
81
83
  };
82
84
  /** Asks the tower to open the fork's main (`why=fork fork=<id>`); the record counts the ask. */
83
85
  const ask = async (f: Fork): Promise<{ fork: Fork; refusal?: string }> => {
@@ -105,7 +107,7 @@ export function createForks(kit: Kit, d: ForkDeps) {
105
107
  };
106
108
  /** Fork `f` of this main, which stopped after its move committed: rebuild what is missing (the move file, the handoff, the mark of the replies) and ask the tower again unless its main is live. */
107
109
  /** Makes fork `f` whole on this main's side: the mark of the replies it handed away, its move file (the ledger rebuilds it from the tombstones, with no second move) and `moved` step, and its handoff file. */
108
- async function restore(ctx: Nested, f: Fork, ids: number[], tombs: Json[]): Promise<{ fork: Fork; lost: boolean }> {
110
+ async function restore(ctx: Nested, f: Fork, ids: number[], tombs: Json[]) {
109
111
  const to = f.id, moveId = (tombs[0]?.moved as Json | undefined)?.moveId;
110
112
  forkMark(kit, f, "fork", () => ({ owed: f.replies.map((r) => r.id) })); // a stop after the move and before this mark left them owed here (fork-review-F003)
111
113
  const lost = !f.movePath || !existsSync(f.movePath);
@@ -116,19 +118,18 @@ export function createForks(kit: Kit, d: ForkDeps) {
116
118
  if ("refusal" in out) throw new Error(`Fork ${short(to)}: its move file could not be rebuilt (${clean(out.refusal, 300)}); nothing changed`);
117
119
  f = advanceFork(dir, to, "moved", { movePath: out.path, ...(typeof moveId === "string" ? { moveId } : {}) }) ?? f;
118
120
  }
119
- writeHandoff(f); // again from the move file, whatever an earlier stop left
120
- return { fork: f, lost };
121
+ return { fork: f, lost, reminder: writeHandoff(f) }; // again from the move file, whatever an earlier stop left
121
122
  }
122
123
  async function resume(ctx: Nested, given: Fork, ids: number[], tombs: Json[]) {
123
124
  const to = given.id;
124
125
  if (given.step === "imported") return { text: `Fork ${short(to)} is done: main ${to} holds the todos as ${(given.imported?.ids ?? []).map((m) => `#${m.to}`).join(", ")}.`, details: given };
125
- const { fork: f, lost } = await restore(ctx, given, ids, tombs);
126
+ const { fork: f, lost, reminder } = await restore(ctx, given, ids, tombs);
126
127
  const live = (await d.read()).sessions.some((x) => x.id === to);
127
- if (stepAt(f.step) >= stepAt("opened") && live) return { text: `Fork ${short(to)}: its main (session ${to}) is live and imports the todos; nothing more to do here.`, details: f };
128
+ if (stepAt(f.step) >= stepAt("opened") && live) return { text: `Fork ${short(to)}: its main (session ${to}) is live and imports the todos${reminder ? `.${reminder}` : "; nothing more to do here."}`, details: f };
128
129
  const what = lost ? "its move committed and its result was lost" : stepAt(f.step) >= stepAt("opened") ? "its main is not live" : "the tower has not opened its main yet";
129
130
  const asked = await ask(f);
130
131
  d.refresh();
131
- return { text: `Picked up fork ${short(to)}: ${what}; ${asked.refusal ? askWords(asked) : "asked the tower again"}. The todos wait in ${asked.fork.movePath}.`, details: asked.fork };
132
+ return { text: `Picked up fork ${short(to)}: ${what}; ${asked.refusal ? askWords(asked) : "asked the tower again"}. The todos wait in ${asked.fork.movePath}.${reminder}`, details: asked.fork };
132
133
  }
133
134
 
134
135
  pi.on("before_agent_start", () => {
@@ -225,11 +226,11 @@ export function createForks(kit: Kit, d: ForkDeps) {
225
226
  const moveId = ledgerList(s.branch())?.tasks.find((t) => t.id === ids[0] && isObject(t.moved))?.moved as Json | undefined;
226
227
  forkMark(kit, f, "fork", () => ({ owed: replies.map((r) => r.id) })); // the replies that moved leave this main's owed list, with the move
227
228
  f = advanceFork(dir, id, "moved", { movePath: out.path, ...(typeof moveId?.moveId === "string" ? { moveId: moveId.moveId } : {}) }) ?? f;
228
- writeHandoff(f);
229
+ const reminder = writeHandoff(f);
229
230
  d.refresh();
230
231
  const asked = await ask(f);
231
232
  const list2 = f.tasks.map((t) => `#${t.id}`).join(", ");
232
- return { content: [{ type: "text" as const, text: `Moved ${list2} to fork ${short(id)} (session id ${id}, move file ${out.path}); ${askWords(asked)}. They are off your list and board now: do not work on them.${replies.length ? ` The replies ${replies.map((r) => r.id).join(", ")} went with them.` : ""}` }], details: asked.fork };
233
+ return { content: [{ type: "text" as const, text: `Moved ${list2} to fork ${short(id)} (session id ${id}, move file ${out.path}); ${askWords(asked)}. They are off your list and board now: do not work on them.${replies.length ? ` The replies ${replies.map((r) => r.id).join(", ")} went with them.` : ""}${reminder}` }], details: asked.fork };
233
234
  } finally {
234
235
  busy.delete(id);
235
236
  }
@@ -0,0 +1,11 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ type Registry = Pick<ExtensionAPI, "getAllTools">;
3
+ export const hasTeamWork = (pi: Registry): boolean => pi.getAllTools().some(({ name }) => name === "team_work");
4
+ export function ticketHandoff(pi: Registry, tasks: readonly Record<string, unknown>[] = []): string {
5
+ const ids = new Set<string>();
6
+ for (const { status, metadata } of hasTeamWork(pi) ? tasks : []) {
7
+ if (status !== "pending" && status !== "in_progress") continue;
8
+ if (metadata && typeof metadata === "object" && "ticket" in metadata && typeof metadata.ticket === "string" && metadata.ticket.trim()) ids.add(metadata.ticket.trim());
9
+ }
10
+ return ids.size ? ` Call team_work handoff for each ticket not yet handed off: ${[...ids].join(", ")}. Posting requires confirmation.` : "";
11
+ }
package/src/tools.ts CHANGED
@@ -24,7 +24,8 @@ import type { Reach } from "./reach.ts";
24
24
  import type { ServerLook } from "./server-look.ts";
25
25
  import { ENTRY, type Kit } from "./state.ts";
26
26
  import { snapshotOfBranch } from "./todo.ts";
27
- import { writeHandoverTodos } from "./handovertodo.ts";
27
+ import { handoverSnapshot, writeHandoverTodos } from "./handovertodo.ts";
28
+ import { ticketHandoff } from "./teamwork.ts";
28
29
  import { todosOf } from "./items.ts";
29
30
  import { integrationOff } from "./trainswitch.ts";
30
31
  import { isRoleLabel, ownsBoard, trainLabel } from "./trainrole.ts";
@@ -244,9 +245,9 @@ export function createTools({ pi, cfg, s, guiDir, me, role, tell }: Kit, { mainD
244
245
  },
245
246
  // A main's own session rotation (docs/specs/2026-11-23-tower-revive.md §8): it opens its successor itself, with the handoff file as the new pi's first prompt; no /new, no boss.
246
247
  addHandover() {
247
- tool("boss_handover", "Main only, outside teammate turns. When the rotation rule says rotate, write a handoff and open your successor in a new tab with your name and kind. On its intercom takeover, relinquish your role per that rule.",
248
+ tool("boss_handover", "Main rotation, outside teammate turns: call with reason alone before writing the handoff. Then give its path to open your successor under your name and kind. On takeover relinquish your role.",
248
249
  Type.Object({
249
- handoff: Type.String({ description: "Existing handoff path (absolute or cwd-relative)." }),
250
+ handoff: Type.Optional(Type.String({ description: "Existing handoff path (absolute or cwd-relative)." })),
250
251
  reason: Type.String({ description: "One line of at most 200 characters." }),
251
252
  }),
252
253
  async ({ handoff, reason }, _signal, ctx) => {
@@ -258,6 +259,8 @@ export function createTools({ pi, cfg, s, guiDir, me, role, tell }: Kit, { mainD
258
259
  if (s.openedBy?.startsWith("link:")) throw new Error(`A main opened for a teammate's device (${s.openedBy.slice(0, 40)}) does not hand over: its successor would run outside the device's revoke and signed stop. Finish or report what you can; the device asks again`);
259
260
  const why = reason.replace(/\s+/g, " ").trim();
260
261
  if (!why || why.length > 200) throw new Error("reason is required: one line of 1 to 200 characters");
262
+ const advice = (snapshot: unknown) => ticketHandoff(pi, handoverSnapshot(snapshot).data?.tasks);
263
+ if (handoff === undefined) return { text: `No successor opened.${advice(snapshotOfBranch(s.branch()))} Write the handoff and call boss_handover with its path and reason.`, details: { prepared: true } };
261
264
  const cwd = process.cwd(), path = isAbsolute(handoff) ? handoff : resolve(cwd, handoff);
262
265
  let regular = false;
263
266
  try { regular = lstatSync(path).isFile(); } catch { /* missing */ }
@@ -272,9 +275,12 @@ export function createTools({ pi, cfg, s, guiDir, me, role, tell }: Kit, { mainD
272
275
  if (net.ps.some((p) => p.pane_id === held.pane && p.agent)) throw new Error(`Your successor in pane ${held.pane} (tab ${held.tab}) is still live: one at a time. Tell it by intercom, or wait until it took over.`);
273
276
  }
274
277
  const name = pi.getSessionName() || s.ownName || me().slice(0, 8);
275
- let todos: ReturnType<typeof writeHandoverTodos>;
276
- try { todos = writeHandoverTodos(path, snapshotOfBranch(s.branch())); }
277
- catch (error) { todos = { written: false, path: null, count: 0, reason: String(error) }; }
278
+ let reminder = "", todos: ReturnType<typeof writeHandoverTodos>;
279
+ try {
280
+ const snapshot = snapshotOfBranch(s.branch());
281
+ reminder = advice(snapshot);
282
+ todos = writeHandoverTodos(path, snapshot);
283
+ } catch (error) { todos = { written: false, path: null, count: 0, reason: String(error) }; }
278
284
  const next = await openSuccessor({ run: cfg.run, sleep: cfg.sleep, workspaceId: s.at.workspaceId, cwd, sessions: () => s.c.listSessions(), send: (to, message) => post(to, message, "handoff", "main", true), trustDir: trustDir(guiDir), inherit: (next) => void topics?.inherit(next) }, { from: { id: me(), name }, handoff: path, ...(todos.written ? { todosPath: todos.path } : {}), reason: why, ...(s.duty ? { duty: s.duty } : {}), ...(s.openedBy ? { openedBy: s.openedBy } : {}) });
279
285
  const forked = (await forks?.inherit(next.main, ctx)) || ""; // the handoff was delivered: the forks change owner at the handover's commit point, never before (fork-review-F008)
280
286
  pi.appendEntry(ENTRY, { successor: (s.saved.successor = { pane: next.pane, tab: next.tab, at: cfg.now(), main: next.main }) });
@@ -285,7 +291,7 @@ export function createTools({ pi, cfg, s, guiDir, me, role, tell }: Kit, { mainD
285
291
  try { listen(); } catch { /* no pi-intercom channel: the tower's ask goes unanswered and says so; the handover itself stands */ }
286
292
  const told = await openTower(undefined, false).then((tower) => post(tower.id, handedNotice(name, me(), next), "call_tower", "tower", false, undefined, "milestone", { handedTo: next.main })).then((r) => r.status === "sent", () => false);
287
293
  const closer = told ? "your workspace's tower was told too" : "no tower of this workspace took the notice";
288
- return { text: `Opened your successor in tab ${next.tab} (session ${next.main}) and handed it ${path}. ${todos.written ? `Wrote ${todos.count} tasks to ${todos.path}.` : `No todos file written (0 tasks exported): ${todos.reason}.`} When it tells you it took over, give up your role as your rule says: boss_duty coordinator (if you are standing or integrator), boss_rename to "old ${name} (handed over to ${next.main.slice(0, 8)})", stop your monitors and loops, clear your board, and end your turn. Its takeover reaches sb too: sb then closes this session and its pane once nothing of yours runs (no subagent, monitor, loop, watch, dialog, or queued message), under auto mode too, and sends a subagent result that reaches you meanwhile to your successor itself; do not ask the boss to close you (${closer}).${forked && ` ${forked}`}`, details: { ...next, towerTold: told, todos } };
294
+ return { text: `Opened your successor in tab ${next.tab} (session ${next.main}) and handed it ${path}. ${todos.written ? `Wrote ${todos.count} tasks to ${todos.path}.` : `No todos file written (0 tasks exported): ${todos.reason}.`} When it tells you it took over, give up your role as your rule says: boss_duty coordinator (if you are standing or integrator), boss_rename to "old ${name} (handed over to ${next.main.slice(0, 8)})", stop your monitors and loops, clear your board, and end your turn. Its takeover reaches sb too: sb then closes this session and its pane once nothing of yours runs (no subagent, monitor, loop, watch, dialog, or queued message), under auto mode too, and sends a subagent result that reaches you meanwhile to your successor itself; do not ask the boss to close you (${closer}).${forked && ` ${forked}`}${reminder}`, details: { ...next, towerTold: told, todos } };
289
295
  } finally {
290
296
  handing = false;
291
297
  }