pi-straw-boss 0.79.0 → 0.79.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.
@@ -221,13 +221,14 @@ async function panes(run4, workspace) {
221
221
  var READS = /* @__PURE__ */ new Set(["workspace.list", "pane.list", "tab.list", "pane.current", "pane.get", "pane.read", "pane.process_info", "pane.layout", "session.snapshot"]);
222
222
  var RETRY_MS = 250;
223
223
  var RETRIED = /* @__PURE__ */ new Set(["timeout", "closed"]);
224
+ var retried = (error) => RETRIED.has(error.code) || error.code === "socket_error" && /\b(?:ECONNRESET|EPIPE|ECONNREFUSED)\b/.test(error.message);
224
225
  var herdrCall = (socketPath = herdrSocket()) => {
225
226
  const once = callOnce(socketPath);
226
227
  return async (method, params, timeoutMs) => {
227
228
  try {
228
229
  return await once(method, params, timeoutMs);
229
230
  } catch (error) {
230
- if (!READS.has(method) || !(error instanceof HerdrError) || !RETRIED.has(error.code)) throw error;
231
+ if (!READS.has(method) || !(error instanceof HerdrError) || !retried(error)) throw error;
231
232
  await new Promise((resolve4) => setTimeout(resolve4, RETRY_MS));
232
233
  return once(method, params, timeoutMs);
233
234
  }
@@ -88,7 +88,7 @@ import {
88
88
  writeBoard,
89
89
  writeJson,
90
90
  writerAlive
91
- } from "./chunk-YPEYIVLF.mjs";
91
+ } from "./chunk-VOBPJZPJ.mjs";
92
92
 
93
93
  // src/server/cli.ts
94
94
  import { existsSync as existsSync2, realpathSync as realpathSync3 } from "node:fs";
@@ -211,7 +211,7 @@ import {
211
211
  writeStartError,
212
212
  writerAlive,
213
213
  yardPath
214
- } from "./chunk-YPEYIVLF.mjs";
214
+ } from "./chunk-VOBPJZPJ.mjs";
215
215
 
216
216
  // src/server/main.ts
217
217
  import { homedir as homedir14 } from "node:os";
@@ -3450,11 +3450,15 @@ function subagents(parent, all, now, limit = MAX_CHILDREN) {
3450
3450
  const folder = scriptsOf(scriptDir, launched), read4 = (f) => scriptRead(folder, join14(scriptDir, f));
3451
3451
  const resumeOf = (id) => {
3452
3452
  if (!folder.resumes) {
3453
- folder.resumes = /* @__PURE__ */ new Map();
3453
+ const index2 = /* @__PURE__ */ new Map();
3454
+ let whole = true;
3454
3455
  for (const f of launched) if (/-resume-[^-]*\.sh$/.test(f)) {
3455
3456
  const launch = read4(f);
3456
- if (launch?.id && !folder.resumes.has(launch.id)) folder.resumes.set(launch.id, { script: f, launch });
3457
+ if (launch?.id) index2.has(launch.id) || index2.set(launch.id, { script: f, launch });
3458
+ else whole = false;
3457
3459
  }
3460
+ if (whole) folder.resumes = index2;
3461
+ else return index2.get(id);
3458
3462
  }
3459
3463
  return folder.resumes.get(id);
3460
3464
  };
@@ -8850,7 +8854,7 @@ function createLanListener(options) {
8850
8854
  conn.kill();
8851
8855
  return false;
8852
8856
  }
8853
- function hostOf2(entry, header2) {
8857
+ function hostOf3(entry, header2) {
8854
8858
  if (!header2 || entry.port === void 0) return void 0;
8855
8859
  const value = header2.toLowerCase(), name2 = ca.name ? `${ca.name}.local` : void 0;
8856
8860
  return [name2, entry.served.address].find((h) => h !== void 0 && value === `${h}:${entry.port}`);
@@ -8906,7 +8910,7 @@ function createLanListener(options) {
8906
8910
  function plainRequest(entry, req, res) {
8907
8911
  const conn = connOf.get(req.socket);
8908
8912
  if (conn) conn.requests++;
8909
- const host = hostOf2(entry, req.headers.host), bad2 = () => send(res, 400, "text/plain; charset=utf-8", "bad request");
8913
+ const host = hostOf3(entry, req.headers.host), bad2 = () => send(res, 400, "text/plain; charset=utf-8", "bad request");
8910
8914
  if (!host || req.method !== "GET") return bad2();
8911
8915
  const url = new URL(req.url ?? "/", "http://x"), csp = `default-src 'none'; style-src 'unsafe-inline'; img-src https://${host}:${entry.port}; form-action 'none'; base-uri 'none'; frame-ancestors 'none'`;
8912
8916
  const html = (body2) => send(res, 200, "text/html; charset=utf-8", body2, { "content-security-policy": csp });
@@ -8925,7 +8929,7 @@ function createLanListener(options) {
8925
8929
  }
8926
8930
  }
8927
8931
  function httpsRequest(entry, req, res) {
8928
- const host = hostOf2(entry, req.headers.host), conn = connOf.get(req.socket);
8932
+ const host = hostOf3(entry, req.headers.host), conn = connOf.get(req.socket);
8929
8933
  if (!host) {
8930
8934
  if (conn) {
8931
8935
  conn.requests++;
@@ -17265,8 +17269,15 @@ var safeUrl = (url) => {
17265
17269
  }
17266
17270
  return void 0;
17267
17271
  };
17272
+ var hostOf2 = (url) => {
17273
+ for (const re of URL_OK) {
17274
+ const host = re.exec(url)?.groups?.host;
17275
+ if (host !== void 0) return host.toLowerCase();
17276
+ }
17277
+ return void 0;
17278
+ };
17268
17279
  function openingFacts(request) {
17269
- const head = request.split(/\r?\n(?=\s*car:)/i)[0] ?? request;
17280
+ const head = request.split(/\r?\n(?=\s*(?:car:|app:[^|\n]*\|\s*(?:car|tickets):))/i)[0] ?? request;
17270
17281
  const base = /(?:^|\n)[ \t>*-]*["']?base["']?[ \t]*[:=][ \t]*["']?([A-Za-z0-9][A-Za-z0-9._/-]{0,199})/i.exec(head)?.[1];
17271
17282
  return { ...base ? { base } : {}, heads: headsIn(request).slice(0, 64) };
17272
17283
  }
@@ -17773,7 +17784,7 @@ var CarBook = class {
17773
17784
  const reach = error.reach;
17774
17785
  if (reach) {
17775
17786
  this.d.log?.("cars-received-unchecked", { project, car: label.slice(0, 40), reason: reach });
17776
- return { unchecked: `the server could not reach the project's remote (${reach}: ${error.message.replace(/^sb: /, "").slice(0, 200)}), so whether head ${head.slice(0, 12)} is on ${base} already was not checked` };
17787
+ return { unchecked: `the server could not reach the project's remote${hostOf2(url) ? ` at ${hostOf2(url)}` : ""} (${reach}: ${error.message.replace(/^sb: /, "").slice(0, 200)}), so whether head ${head.slice(0, 12)} is on ${base} already was not checked` };
17777
17788
  }
17778
17789
  const word2 = `sb: car ${label} is not received: whether its head ${head.slice(0, 12)} is on ${base} of the project's remote already could not be checked (${error.message.replace(/^sb: /, "").slice(0, 300)}). A car that is on the base is never received again, so the check has to run: try again`;
17779
17790
  this.d.log?.("cars-received-refused", { project, car: label.slice(0, 40), reason: word2.slice(0, 200) });
@@ -21294,7 +21305,7 @@ function opener(env) {
21294
21305
  const slips = slipsInText(request);
21295
21306
  if (!slips.length) throw new OpenLimitError("An integrator is opened on a car slip: the request carries none (car: <app> | tickets: \u2026 | branch: \u2026 | head: <40 hex>)");
21296
21307
  const unread = slips.flatMap((s2) => s2.problems ?? []);
21297
- if (unread.length) throw new OpenLimitError(`The car slip cannot be taken as written: ${unread.join("; ")}. The slip's car: names the car's app (app: is the same field), and its tickets go in tickets:.`);
21308
+ if (unread.length) throw new OpenLimitError(`The car slip cannot be taken as written: ${unread.join("; ")}. The slip's car: names the car's app (app: is the same field), and its tickets go in tickets:. A slip ends at a blank line: words of your own (\`Note: \u2026\`) go after one, never on the line below the slip.`);
21298
21309
  const apps = [...new Set(slips.map((s2) => s2.app))], config = noTrainRefusal(dir, apps);
21299
21310
  if (config) throw new OpenLimitError(config);
21300
21311
  const own = checkoutProject(dir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-straw-boss",
3
- "version": "0.79.0",
3
+ "version": "0.79.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",
package/src/bridge.ts CHANGED
@@ -230,7 +230,7 @@ export function startBridge(pi: ExtensionAPI, { env, dir, local, close, platform
230
230
  closed(id: string, by?: string, allow?: true) {
231
231
  const r = recs.get(id);
232
232
  if (!r || r.state === "closed") return;
233
- [r.state, r.at, r.by] = ["closed", Date.now(), by ?? (r.accepted ? "remote" : "local")];
233
+ [r.state, r.at, r.by] = ["closed", Date.now(), by === "cancel" && r.accepted ? "remote" : (by ?? (r.accepted ? "remote" : "local"))]; // A close by "cancel" after the owner accepted this bridge's own answer is that answer winning (sb's close path carries no answerId): a resend gets "accepted" (RC-F002).
234
234
  if (allow) r.allow = true;
235
235
  changed();
236
236
  },
package/src/herdr.ts CHANGED
@@ -123,15 +123,17 @@ export async function panes(run: HerdrRun, workspace?: string): Promise<Pane[]>
123
123
  const READS = new Set(["workspace.list", "pane.list", "tab.list", "pane.current", "pane.get", "pane.read", "pane.process_info", "pane.layout", "session.snapshot"]);
124
124
  const RETRY_MS = 250;
125
125
  const RETRIED = new Set(["timeout", "closed"]);
126
+ /** A reset, a broken pipe, or a refusal arrives as `error` before `close`, so it fails first as a socket_error: the same loss as a closed connection (R0773-F002). */
127
+ const retried = (error: HerdrError) => RETRIED.has(error.code) || (error.code === "socket_error" && /\b(?:ECONNRESET|EPIPE|ECONNREFUSED)\b/.test(error.message));
126
128
 
127
- /** Herdr's socket API: one request on a connection of its own, and for a read (`READS`) one more try after a timeout or a closed connection. */
129
+ /** Herdr's socket API: one request on a connection of its own, and for a read (`READS`) one more try after a timeout, a closed connection, or a reset. */
128
130
  export const herdrCall = (socketPath = herdrSocket()): HerdrCall => {
129
131
  const once = callOnce(socketPath);
130
132
  return async (method, params, timeoutMs) => {
131
133
  try {
132
134
  return await once(method, params, timeoutMs);
133
135
  } catch (error) {
134
- if (!READS.has(method) || !(error instanceof HerdrError) || !RETRIED.has(error.code)) throw error;
136
+ if (!READS.has(method) || !(error instanceof HerdrError) || !retried(error)) throw error;
135
137
  await new Promise((resolve) => setTimeout(resolve, RETRY_MS));
136
138
  return once(method, params, timeoutMs);
137
139
  }
package/src/netdata.ts CHANGED
@@ -174,8 +174,12 @@ export function subagents(parent: Pane | undefined, all: Pane[], now: number, li
174
174
  // Only the resumes are read for that, once while the folder lists the same names.
175
175
  const resumeOf = (id: string) => {
176
176
  if (!folder.resumes) {
177
- folder.resumes = new Map();
178
- for (const f of launched) if (/-resume-[^-]*\.sh$/.test(f)) { const launch = read(f); if (launch?.id && !folder.resumes.has(launch.id)) folder.resumes.set(launch.id, { script: f, launch }); }
177
+ const index = new Map<string, { script: string; launch: Launch }>();
178
+ let whole = true;
179
+ for (const f of launched) if (/-resume-[^-]*\.sh$/.test(f)) { const launch = read(f); if (launch?.id) index.has(launch.id) || index.set(launch.id, { script: f, launch }); else whole = false; }
180
+ // A script that names no id yet is still being written (R0790-D001): the index is not kept, so the next read looks again.
181
+ if (whole) folder.resumes = index;
182
+ else return index.get(id);
179
183
  }
180
184
  return folder.resumes.get(id);
181
185
  };
package/src/opener.ts CHANGED
@@ -163,7 +163,7 @@ export function opener(env: OpenerEnv) {
163
163
  if (!slips.length) throw new OpenLimitError("An integrator is opened on a car slip: the request carries none (car: <app> | tickets: … | branch: … | head: <40 hex>)");
164
164
  // A field the parse could not take (a key that is no slip field, `app:` and `car:` naming two apps) is refused here with the parse's words, not dropped: the slip goes back to its sender as written (0.77.3).
165
165
  const unread = slips.flatMap((s) => s.problems ?? []);
166
- if (unread.length) throw new OpenLimitError(`The car slip cannot be taken as written: ${unread.join("; ")}. The slip's car: names the car's app (app: is the same field), and its tickets go in tickets:.`);
166
+ if (unread.length) throw new OpenLimitError(`The car slip cannot be taken as written: ${unread.join("; ")}. The slip's car: names the car's app (app: is the same field), and its tickets go in tickets:. A slip ends at a blank line: words of your own (\`Note: …\`) go after one, never on the line below the slip.`);
167
167
  const apps = [...new Set(slips.map((s) => s.app))], config = noTrainRefusal(dir, apps);
168
168
  if (config) throw new OpenLimitError(config);
169
169
  const own = checkoutProject(dir);
@@ -53,9 +53,14 @@ export const safeUrl = (url: string): string | undefined => {
53
53
  }
54
54
  return undefined;
55
55
  };
56
+ /** The host of a remote `safeUrl` accepts, and nothing else of it: no userinfo, port, or path (the unchecked notice names it, U1). */
57
+ export const hostOf = (url: string): string | undefined => {
58
+ for (const re of URL_OK) { const host = re.exec(url)?.groups?.host; if (host !== undefined) return host.toLowerCase(); }
59
+ return undefined;
60
+ };
56
61
  /** What the server reads from the manifest text the tower opens a train on: the base it names and the heads of its cars. */
57
62
  export function openingFacts(request: string): { base?: string; heads: string[] } {
58
- const head = request.split(/\r?\n(?=\s*car:)/i)[0] ?? request;
63
+ const head = request.split(/\r?\n(?=\s*(?:car:|app:[^|\n]*\|\s*(?:car|tickets):))/i)[0] ?? request;
59
64
  const base = /(?:^|\n)[ \t>*-]*["']?base["']?[ \t]*[:=][ \t]*["']?([A-Za-z0-9][A-Za-z0-9._/-]{0,199})/i.exec(head)?.[1];
60
65
  return { ...(base ? { base } : {}), heads: headsIn(request).slice(0, 64) };
61
66
  }
@@ -588,7 +593,7 @@ export class CarBook {
588
593
  const reach = (error as { reach?: string }).reach;
589
594
  if (reach) {
590
595
  this.d.log?.("cars-received-unchecked", { project, car: label.slice(0, 40), reason: reach });
591
- return { unchecked: `the server could not reach the project's remote (${reach}: ${(error as Error).message.replace(/^sb: /, "").slice(0, 200)}), so whether head ${head.slice(0, 12)} is on ${base} already was not checked` };
596
+ return { unchecked: `the server could not reach the project's remote${hostOf(url) ? ` at ${hostOf(url)}` : ""} (${reach}: ${(error as Error).message.replace(/^sb: /, "").slice(0, 200)}), so whether head ${head.slice(0, 12)} is on ${base} already was not checked` };
592
597
  }
593
598
  const word = `sb: car ${label} is not received: whether its head ${head.slice(0, 12)} is on ${base} of the project's remote already could not be checked (${(error as Error).message.replace(/^sb: /, "").slice(0, 300)}). A car that is on the base is never received again, so the check has to run: try again`;
594
599
  this.d.log?.("cars-received-refused", { project, car: label.slice(0, 40), reason: word.slice(0, 200) });
package/src/session.ts CHANGED
@@ -100,7 +100,7 @@ export function registerSession(kit: Kit, { mainDuty, runMode, briefing, roles,
100
100
  pi.appendEntry(ENTRY, { openedBy: s.openedBy ?? null, openedPane: s.at.paneId }); // null, not undefined: a later claim (a pop) overrides an earlier opener
101
101
  // The kind the tower opened it with (docs/specs/2026-11-09-agent-kinds.md §6) is consumed with the claim: the entry, `s.duty`, and, at the promotion below, the role record, which a restore before the first message reads.
102
102
  const duty = mine.tokens.sb_open_duty;
103
- if (isCoordinatorDuty(duty) && s.duty !== duty) {
103
+ if (isCoordinatorDuty(duty) && s.duty !== duty && (duty !== "integrator" || mainDuty.integrationOn())) { // `integrator` only while integration is on, as the door (opener.ts) requires: a token written by anything else gets no hidden integrator entry (R0790-F003).
104
104
  const tower = (await workspaces(run).catch(() => [])).find((w) => w.workspace_id === s.at.workspaceId)?.tokens?.tower;
105
105
  mainDuty.write(duty, `opened by tower ${tower ?? `of workspace ${s.at.workspaceId}`} as ${duty}`);
106
106
  }
@@ -1,5 +1,4 @@
1
1
  import { readFileSync } from "node:fs";
2
- import { legacyContract } from "./contract-legacy.ts";
3
2
 
4
3
  // The merge-train contract (docs/specs/2026-11-07-train-workers.md §14.1, TB-F008). The train's and the integrator's prompts follow two skills by name, `integrating` and `deploying`, and assume what version 1 of the contract
5
4
  // holds (the seven seams read from one `## Seam bindings` block, the Project skill headings with `## Acceptance`, the car slip); a model cannot tell a stale procedure from a current one by reading the skill. So a skill declares
@@ -41,7 +40,7 @@ export function checkContract(commands: readonly SkillCommand[] | undefined, nee
41
40
  if (!file) return refuse(`pi loaded no skill named \`${name}\`; install a package that provides it and /reload`);
42
41
  let text: string;
43
42
  try { text = readFileSync(file, "utf8"); } catch (error) { return refuse(`${file} cannot be read (${(error as Error).message}); fix it and /reload`); }
44
- const said = declaredContract(text) ?? legacyContract(file);
43
+ const said = declaredContract(text);
45
44
  if (said === undefined) return refuse(`${file} declares none (its frontmatter needs \`metadata:\` with \`merge-train-contract: "${need}"\` under it); update the package that ships it and /reload`);
46
45
  const versions = said.split(/[\s,]+/).filter(Boolean);
47
46
  if (!versions.length || versions.some((v) => !/^\d+$/.test(v))) return refuse(`${file} declares ${JSON.stringify(said)}; its value lists the contract versions the skill implements, such as "${need}"`);
@@ -1,19 +0,0 @@
1
- import { readFileSync, realpathSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
-
4
- // The transition of the merge-train contract (contract.ts), and the only place Straw Boss names a skills package. pi-anchorloop implemented contract 1 from 2.11.0 on, before there was a declaration to carry: a skill with no
5
- // declaration that sits in that package (`<package>/skills/<name>/SKILL.md`), at that version or newer, counts as declaring "1". A declaration always wins over this. Remove this file, its one call in contract.ts and its test
6
- // once the pi-anchorloop that declares the contract is the oldest in use.
7
-
8
- const PACKAGE = "pi-anchorloop", SINCE = [2, 11, 0];
9
-
10
- export function legacyContract(skillFile: string): string | undefined {
11
- try {
12
- const pkg = JSON.parse(readFileSync(join(dirname(realpathSync(skillFile)), "..", "..", "package.json"), "utf8")) as { name?: unknown; version?: unknown };
13
- const found = pkg.name === PACKAGE && typeof pkg.version === "string" ? /^(\d+)\.(\d+)\.(\d+)(-.*)?$/.exec(pkg.version) : null;
14
- if (!found) return undefined;
15
- const at = [1, 2, 3].map((i) => Number(found[i])), differs = at.findIndex((n, i) => n !== SINCE[i]);
16
- // A pre-release of the first version is older than it.
17
- return (differs < 0 ? found[4] === undefined : at[differs]! > SINCE[differs]!) ? "1" : undefined;
18
- } catch { return undefined; }
19
- }