pi-straw-boss 0.100.2 → 0.101.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.
|
@@ -5472,6 +5472,7 @@ var AGENT_DUTY = { worker: "worker", scout: "scout", planner: "planner", reviewe
|
|
|
5472
5472
|
var GRAPHS = ["single-loop", "fan-out/fan-in", "orchestrator-worker"];
|
|
5473
5473
|
var isCoordinatorDuty = (v) => typeof v === "string" && COORDINATOR_DUTIES.includes(v);
|
|
5474
5474
|
var isMainKind = (v) => isCoordinatorDuty(v) || v === "worker";
|
|
5475
|
+
var isGraph = (v) => typeof v === "string" && GRAPHS.includes(v);
|
|
5475
5476
|
var graphOf = (v) => v === "orchestrator-worker" ? v : v === "fan-out/fan-in" || v === "fan-out" ? "fan-out/fan-in" : v === "single" || typeof v === "string" && v.startsWith("single-loop") ? "single-loop" : void 0;
|
|
5476
5477
|
var dutyOfAgent = (name) => name !== void 0 && Object.hasOwn(AGENT_DUTY, name) ? AGENT_DUTY[name] : void 0;
|
|
5477
5478
|
|
|
@@ -8291,6 +8292,7 @@ export {
|
|
|
8291
8292
|
GRAPHS,
|
|
8292
8293
|
isCoordinatorDuty,
|
|
8293
8294
|
isMainKind,
|
|
8295
|
+
isGraph,
|
|
8294
8296
|
graphOf,
|
|
8295
8297
|
markOf,
|
|
8296
8298
|
sessionMark,
|
package/dist/server/cli.mjs
CHANGED
package/dist/server/main.mjs
CHANGED
|
@@ -139,6 +139,7 @@ import {
|
|
|
139
139
|
intercomOf,
|
|
140
140
|
isCode,
|
|
141
141
|
isCoordinatorDuty,
|
|
142
|
+
isGraph,
|
|
142
143
|
isHead,
|
|
143
144
|
isHeadKey,
|
|
144
145
|
isMainKind,
|
|
@@ -307,7 +308,7 @@ import {
|
|
|
307
308
|
writeStartError,
|
|
308
309
|
writerAlive,
|
|
309
310
|
yardPath
|
|
310
|
-
} from "./chunk-
|
|
311
|
+
} from "./chunk-WTEFOEUM.mjs";
|
|
311
312
|
|
|
312
313
|
// src/server/main.ts
|
|
313
314
|
import { homedir as homedir18 } from "node:os";
|
|
@@ -6224,7 +6225,7 @@ function todosOf(snapshot) {
|
|
|
6224
6225
|
if (!s2 || !Array.isArray(s2.tasks) || typeof s2.nextId !== "number") return void 0;
|
|
6225
6226
|
return s2.tasks.slice(0, 200).flatMap((t) => {
|
|
6226
6227
|
if (!(typeof t?.id === "number" && typeof t.subject === "string" && STATUSES2.has(t.status))) return [];
|
|
6227
|
-
const sb = stepInfo(t.metadata), graph = obj(t.metadata) ? graphOf(t.metadata.graph) : void 0, points = pointsOf(obj(t.metadata) ? t.metadata.points : void 0) ?? pointsOf(t.points);
|
|
6228
|
+
const sb = stepInfo(t.metadata), graph = isGraph(t.graph) ? t.graph : obj(t.metadata) ? graphOf(t.metadata.graph) : void 0, points = pointsOf(obj(t.metadata) ? t.metadata.points : void 0) ?? pointsOf(t.points);
|
|
6228
6229
|
const e = Array.isArray(t.evidence) ? t.evidence.at(-1) : void 0;
|
|
6229
6230
|
const evidence2 = e && typeof e.command === "string" && (e.result === "pass" || e.result === "fail") && typeof e.at === "string" && Number.isFinite(Date.parse(e.at)) ? { command: e.command.slice(0, 500), result: e.result, at: e.at, ...typeof e.sha === "string" && { sha: e.sha.slice(0, 7) } } : void 0;
|
|
6230
6231
|
return [{ ...typeof t.anchor === "string" && t.anchor && { anchor: t.anchor.slice(0, 500) }, ...evidence2 && { evidence: evidence2 }, id: t.id, subject: t.subject.slice(0, 300), status: t.status, ...typeof t.activeForm === "string" && { activeForm: t.activeForm.slice(0, 120) }, ...sb && { sb }, ...graph && { graph }, ...typeof t.owner === "string" && t.owner.trim() && { owner: t.owner.trim().slice(0, 64) }, ...Array.isArray(t.blockedBy) && { blockedBy: t.blockedBy.filter(Number.isSafeInteger).slice(0, 50) }, ...points !== void 0 && { points } }];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-straw-boss",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.101.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/prompts/planning.md
CHANGED
|
@@ -20,7 +20,8 @@ For fan-out and orchestrator-worker, one todo per task:
|
|
|
20
20
|
- `owner`: the subagent's name, or `self`.
|
|
21
21
|
- `description`: the app, the worktree branch for a parallel writer, the anchor and who exercises it, and the exact artifact path a dependent will read.
|
|
22
22
|
- `blockedBy`: the tasks whose output or landed change this one needs; the rest run in parallel, on an unattended device within its capacity budget. Serialize only on a real dependency or shared files.
|
|
23
|
-
- `
|
|
23
|
+
- `graph`: a graph name from section 1, exactly.
|
|
24
|
+
- `metadata`: `{ "anchor": "...", "checkpoint": "own" | "<checkpoint todo id>", "points": <n> }`: its weight against the budget, as the boss or project weighs it (default 1; 0.25 for a light, API-bound worker).
|
|
24
25
|
- Defer: `metadata.until` (ISO) or `metadata.waitsOn` (person). Your monitor, loop or `boss_watch` prevents stale notices.
|
|
25
26
|
|
|
26
27
|
## 3. Name the anchors
|
package/src/items.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FileHandle, open } from "node:fs/promises";
|
|
2
2
|
import { basename } from "node:path";
|
|
3
|
-
import { type Graph, graphOf } from "./duty.ts";
|
|
3
|
+
import { type Graph, graphOf, isGraph } from "./duty.ts";
|
|
4
4
|
import { cleanLabel } from "./eventmarks.ts";
|
|
5
5
|
import { MAX_SB_BYTES, tooDeep } from "./train/spec.ts";
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@ export const FULL_LIMIT = FULL;
|
|
|
12
12
|
|
|
13
13
|
export interface Tool { id: string; name: string; summary: string; args?: string; cut?: true }
|
|
14
14
|
/** One task of a session's todo list, as pi-todo-ledger (its `todo/v1` entries) or @juicesharp/rpiv-todo (its snapshot entries and todo results) keeps it; deleted ones are left out. */
|
|
15
|
-
export interface Todo { id: number; subject: string; status: "pending" | "in_progress" | "completed"; activeForm?: string; /** A train's step (`metadata.sb`), bounded: see `stepInfo`. */ sb?: StepInfo; /** The plan's graph (`metadata.graph` through `graphOf
|
|
15
|
+
export interface Todo { id: number; subject: string; status: "pending" | "in_progress" | "completed"; activeForm?: string; /** A train's step (`metadata.sb`), bounded: see `stepInfo`. */ sb?: StepInfo; /** The plan's graph: the todo's own `graph` (pi-todo-ledger 0.4.0, a name of `GRAPHS` exactly), else a legacy `metadata.graph` through `graphOf`, when the todo names one. */ graph?: Graph; /** Who works on it (rpiv-todo's `owner`), the ids it waits on, and its capacity points (`metadata.points`, else the ledger's own `points`, 0 to 10; capacity.ts). */ owner?: string; blockedBy?: number[]; points?: number; anchor?: string; evidence?: { command: string; result: "pass" | "fail"; sha?: string; at: string } }
|
|
16
16
|
/** What the page keeps of a step's `metadata.sb` (docs/specs/2026-11-07-train-workers.md §11.1): its kind and name, whose it is, the check's type, what it holds and needs, and how it ended; never a command, a path, or evidence text. */
|
|
17
17
|
export interface StepInfo {
|
|
18
18
|
kind: string; name?: string; project?: string; app?: string; train?: string; round?: number; check?: string;
|
|
@@ -52,7 +52,7 @@ export function todosOf(snapshot: unknown): Todo[] | undefined {
|
|
|
52
52
|
if (!s || !Array.isArray(s.tasks) || typeof s.nextId !== "number") return undefined;
|
|
53
53
|
return s.tasks.slice(0, 200).flatMap((t: Json) => {
|
|
54
54
|
if (!(typeof t?.id === "number" && typeof t.subject === "string" && STATUSES.has(t.status))) return [];
|
|
55
|
-
const sb = stepInfo(t.metadata), graph = obj(t.metadata) ? graphOf(t.metadata.graph) : undefined, points = pointsOf(obj(t.metadata) ? t.metadata.points : undefined) ?? pointsOf(t.points);
|
|
55
|
+
const sb = stepInfo(t.metadata), graph = isGraph(t.graph) ? t.graph : obj(t.metadata) ? graphOf(t.metadata.graph) : undefined, points = pointsOf(obj(t.metadata) ? t.metadata.points : undefined) ?? pointsOf(t.points);
|
|
56
56
|
const e = Array.isArray(t.evidence) ? t.evidence.at(-1) : undefined;
|
|
57
57
|
const evidence = e && typeof e.command === "string" && (e.result === "pass" || e.result === "fail") && typeof e.at === "string" && Number.isFinite(Date.parse(e.at)) ? { command: e.command.slice(0, 500), result: e.result, at: e.at, ...(typeof e.sha === "string" && { sha: e.sha.slice(0, 7) }) } : undefined;
|
|
58
58
|
return [{ ...(typeof t.anchor === "string" && t.anchor && { anchor: t.anchor.slice(0, 500) }), ...(evidence && { evidence }), id: t.id, subject: t.subject.slice(0, 300), status: t.status, ...(typeof t.activeForm === "string" && { activeForm: t.activeForm.slice(0, 120) }), ...(sb && { sb }), ...(graph && { graph }), ...(typeof t.owner === "string" && t.owner.trim() && { owner: t.owner.trim().slice(0, 64) }), ...(Array.isArray(t.blockedBy) && { blockedBy: t.blockedBy.filter(Number.isSafeInteger).slice(0, 50) }), ...(points !== undefined && { points }) }];
|
package/src/planhint.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { type Todo, todosOf } from "./items.ts";
|
|
5
|
+
import { todosOfBranch } from "./todo.ts";
|
|
6
|
+
|
|
7
|
+
// The planning rule at the moment it is missed (docs/specs/2026-11-26-plan-graph-jit.md; boss 2026-11-26 「sb 在派工當下送規則」): a coordinator or standing main whose `todo` create leaves it with open
|
|
8
|
+
// todos and none names a graph gets planning.md §1 and §2 on that result, condensed from the file itself, so the wording has one source. Once, and once more only after its open todos named a graph
|
|
9
|
+
// (or it had none open) and then again named none. main.md keeps only its pointer; nothing here reaches a member, a worker, a train, or a tower.
|
|
10
|
+
|
|
11
|
+
/** The block's last line: what the main does with it. */
|
|
12
|
+
export const PLAN_HINT_END = "Set the `graph` field on these todos.";
|
|
13
|
+
const OPENING = "sb: your open todos name no graph. From planning.md:";
|
|
14
|
+
/** The text of planning.md §1 and §2 the block leaves out, to stay near 1.2 KB: what the page shows, the capacity details (capacity notices carry them), and deferring. Each must be there: a cut that no longer matches is a file error. */
|
|
15
|
+
const DROPPED = ["The page shows it beside your kind. ", ", on an unattended device within its capacity budget", " (default 1; 0.25 for a light, API-bound worker)", /^- Defer: .*\n?/m, /\*\*/g];
|
|
16
|
+
|
|
17
|
+
/** One `## <n>.` section of planning.md, without its heading; a missing one is a file error. */
|
|
18
|
+
function section(text: string, n: number): string {
|
|
19
|
+
const found = new RegExp(`^## ${n}\\. ([^\\n]+)\\n([\\s\\S]*?)(?=^## |(?![\\s\\S]))`, "m").exec(text);
|
|
20
|
+
if (!found) throw new Error(`planning.md has no section ${n}`);
|
|
21
|
+
return `${found[1]}: ${found[2].trim()}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The block from planning.md's text: §1 and §2, condensed, then its end line. */
|
|
25
|
+
export function planHint(planning: string): string {
|
|
26
|
+
let body = [1, 2].map((n) => section(planning, n)).join("\n");
|
|
27
|
+
for (const cut of DROPPED) {
|
|
28
|
+
const next = body.replace(cut, "");
|
|
29
|
+
if (next === body) throw new Error(`planning.md §1-§2 no longer hold ${String(cut)}`);
|
|
30
|
+
body = next;
|
|
31
|
+
}
|
|
32
|
+
body = body.replace(/\n{2,}/g, "\n").trim();
|
|
33
|
+
return `${OPENING}\n${body}\n${PLAN_HINT_END}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Whether a `todo` call creates a todo: a single create or a batch. */
|
|
37
|
+
const creates = (input: unknown) => typeof input === "object" && input !== null && (input as { action?: unknown }).action === "create";
|
|
38
|
+
/** The open todos of a plan: not completed, and not a train's step. */
|
|
39
|
+
const openOf = (list: readonly Todo[]) => list.filter((t) => t.status !== "completed" && !t.sb);
|
|
40
|
+
|
|
41
|
+
/** `kind`: this session's main kind now (none while it is no main or runs a tower run); `planning`: the folder of planning.md (its §1-§2 hold no integration blocks), or its text for a test, read at the moment the block is sent. */
|
|
42
|
+
export function registerPlanHint(pi: ExtensionAPI, kind: () => string | undefined, planning: string | (() => string)): void {
|
|
43
|
+
let armed = true; // false after the block was shown, until the open todos name a graph or none is open
|
|
44
|
+
pi.on("session_start", () => void (armed = true));
|
|
45
|
+
pi.on("tool_result", (event, ctx) => {
|
|
46
|
+
const k = kind();
|
|
47
|
+
if (event.toolName !== "todo" || event.isError || (k !== "coordinator" && k !== "standing")) return;
|
|
48
|
+
const list = todosOf(event.details) ?? (ctx ? todosOfBranch(ctx.sessionManager.getBranch()) : undefined);
|
|
49
|
+
if (!list) return;
|
|
50
|
+
const open = openOf(list), missing = open.length > 0 && !open.some((t) => t.graph);
|
|
51
|
+
if (!missing) return void (armed = true);
|
|
52
|
+
if (!armed || !creates(event.input)) return;
|
|
53
|
+
const text = planHint(typeof planning === "string" ? readFileSync(join(planning, "planning.md"), "utf8") : planning()); // a planning.md without its sections throws: pi passes the result through and reports the hook's error; tests/plan-hint.test.ts holds the file to them
|
|
54
|
+
armed = false;
|
|
55
|
+
return { content: [...event.content, { type: "text" as const, text }] };
|
|
56
|
+
});
|
|
57
|
+
}
|
package/src/session.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type { Presence } from "./presence.ts";
|
|
|
23
23
|
import { registerCarOff } from "./carslip.ts";
|
|
24
24
|
import type { Reach } from "./reach.ts";
|
|
25
25
|
import type { Roles } from "./roles.ts";
|
|
26
|
+
import { registerPlanHint } from "./planhint.ts";
|
|
26
27
|
import { registerStandingHint } from "./standinghint.ts";
|
|
27
28
|
import { ENTRY, type Kit } from "./state.ts";
|
|
28
29
|
import { ARM_MESSAGE } from "./idlewake.ts";
|
|
@@ -371,6 +372,7 @@ export function registerSession(kit: Kit, { mainDuty, runMode, briefing, roles,
|
|
|
371
372
|
});
|
|
372
373
|
|
|
373
374
|
registerStandingHint(pi, () => (role() === "main" && !runMode.active() ? mainDuty.now() : undefined)); // a coordinator that starts a watch is told of `standing` once (D8)
|
|
375
|
+
registerPlanHint(pi, () => (role() === "main" && !runMode.active() ? mainDuty.now() : undefined), cfg.promptDir); // a plan with no graph: planning.md §1-§2 on that todo result (planhint.ts)
|
|
374
376
|
registerCarOff(pi, () => role() === "main" && !runMode.active() && !mainDuty.integrationOn()); // a car slip that reaches a main with integration off: how to answer it (carslip.ts)
|
|
375
377
|
pi.on("session_shutdown", async (event) => {
|
|
376
378
|
// A run's own shutdown is runmode.ts's: it joined nothing and holds no pane, tokens, or board entry. So is that of a pi that never became a normal session (undecided, or plain after no answer from the server):
|