pi-straw-boss 0.111.1 → 0.111.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.111.1",
3
+ "version": "0.111.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/host/index.ts CHANGED
@@ -13,6 +13,8 @@ import { join } from "node:path";
13
13
  import { fileURLToPath } from "node:url";
14
14
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
15
15
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
16
+ import { localeOf } from "../locale.ts";
17
+ import { retiredWarning } from "./retired.ts";
16
18
  import { lateApi } from "./late.ts";
17
19
  import { rivalsOf, rivalText } from "./rivals.ts";
18
20
  import { setHostState } from "./state.ts";
@@ -65,14 +67,29 @@ export function createHost(deps: HostDeps = {}) {
65
67
  setHostState({ state: "pending", from });
66
68
  const late = lateApi(pi);
67
69
  let decided: "active" | "down" | undefined;
70
+ let retired: ReturnType<typeof rivalsOf> = [];
71
+ const warned = new Set<string>();
68
72
  pi.on("session_start", async (event, ctx) => {
73
+ const tell = (text: string) => {
74
+ if (ctx.hasUI && ctx.ui?.notify) ctx.ui.notify(text, "warning");
75
+ else console.error(text);
76
+ };
77
+ const warnRetired = () => {
78
+ const session = ctx.sessionManager.getSessionId();
79
+ if (warned.has(session)) return;
80
+ warned.add(session);
81
+ tell(retiredWarning(retired, localeOf(process.env, join(getAgentDir(), "straw-boss"))));
82
+ };
83
+ if (retired.length) return warnRetired();
69
84
  if (!decided) {
70
85
  const rivals = rivalsOf(pi.getCommands(), pi.getAllTools(), deps.root ?? ROOT);
71
86
  if (rivals.length) {
72
87
  decided = "down";
73
88
  const why = `${rivalText(rivals)}, so sb's subagent host registered nothing in this pi`;
74
89
  setHostState({ state: "stood-down", from, why, others: rivals.map((r) => r.path) });
75
- ctx.ui.notify(`Straw Boss: ${why}. Remove one of the two hosts (see /boss doctor).`, "warning");
90
+ retired = rivals.filter(r => r.pkg === "pi-herdr-agents");
91
+ if (retired.length) warnRetired();
92
+ else tell(`Straw Boss: ${why}. Remove one of the two hosts (see /boss doctor).`);
76
93
  return;
77
94
  }
78
95
  try {
@@ -0,0 +1,12 @@
1
+ import type { Locale } from "../locale.ts";
2
+ import type { Rival } from "./rivals.ts";
3
+
4
+ const arg = (s: string) => /^[a-zA-Z0-9@%_+=:,./-]+$/.test(s) ? s : `'${s.replaceAll("'", "'\\''")}'`;
5
+
6
+ export function retiredWarning(rivals: readonly Rival[], locale: Locale): string {
7
+ const paths = rivals.map(r => r.path).join(", ");
8
+ const commands = [...new Set(rivals.map(r => `pi remove ${arg(r.configured?.source ?? r.path)}${r.configured?.local ? " --local" : ""}`))].join("; ");
9
+ return locale === "zh-TW"
10
+ ? `Straw Boss 現在負責執行子代理,但 pi 已從 ${paths} 載入 pi-herdr-agents,因此這個工作階段仍由舊套件接手。請執行 ${commands},再執行 /reload`
11
+ : `Straw Boss now hosts subagents, but pi loaded pi-herdr-agents from ${paths}, so the old host is still in use. Run ${commands}, then /reload`;
12
+ }
@@ -9,8 +9,8 @@ import { dirname, join, sep } from "node:path";
9
9
  // A path resolves to its package by the nearest package.json above it (symlinks resolved), so a checkout, an npm install and a `-e` path all name
10
10
  // pi-herdr-agents the same way. Load order, the shared load stamp and the runtime slot a previous load left are never read.
11
11
 
12
- export interface Registered { name: string; source?: string; sourceInfo?: { path?: string } }
13
- export interface Rival { /** The registering extension's resolved path. */ path: string; /** Its package's name, when a package.json above it has one. */ pkg?: string; via: ("tool" | "command")[] }
12
+ export interface Registered { name: string; source?: string; sourceInfo?: { path?: string; source?: string; scope?: string; origin?: string } }
13
+ export interface Rival { /** The registering extension's resolved path. */ path: string; /** Its package's name, when a package.json above it has one. */ pkg?: string; configured?: { source: string; local: boolean }; via: ("tool" | "command")[] }
14
14
 
15
15
  const real = (path: string) => {
16
16
  try {
@@ -41,15 +41,18 @@ const COMMAND = /^subagent(:\d+)?$/;
41
41
  export function rivalsOf(commands: readonly Registered[], tools: readonly Registered[], selfRoot: string): Rival[] {
42
42
  const self = real(selfRoot), mine = (path: string) => real(path) === self || real(path).startsWith(self + sep);
43
43
  const found = new Map<string, Rival>();
44
- const add = (path: string | undefined, via: "tool" | "command") => {
44
+ const add = (info: Registered["sourceInfo"], via: "tool" | "command") => {
45
+ const path = info?.path;
45
46
  if (!path || path.startsWith("builtin:") || path.startsWith("<") || mine(path)) return;
46
47
  const key = real(path), was = found.get(key);
47
48
  if (was) return void (was.via.includes(via) || was.via.push(via));
48
49
  const pkg = packageOf(path);
49
- found.set(key, { path: key, ...(pkg ? { pkg } : {}), via: [via] });
50
+ // Pi's package resolver records the verbatim settings entry (including version/ref) and its scope.
51
+ const configured = info.origin === "package" && info.source && (info.scope === "user" || info.scope === "project") ? { source: info.source, local: info.scope === "project" } : undefined;
52
+ found.set(key, { path: key, ...(configured ? { configured } : {}), ...(pkg ? { pkg } : {}), via: [via] });
50
53
  };
51
- for (const c of commands) if (c.source === "extension" && COMMAND.test(c.name)) add(c.sourceInfo?.path, "command");
52
- for (const t of tools) if (t.name === "subagent") add(t.sourceInfo?.path, "tool");
54
+ for (const c of commands) if (c.source === "extension" && COMMAND.test(c.name)) add(c.sourceInfo, "command");
55
+ for (const t of tools) if (t.name === "subagent") add(t.sourceInfo, "tool");
53
56
  return [...found.values()];
54
57
  }
55
58