pi-subagent-manager 0.23.0 → 0.24.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.
package/README.md CHANGED
@@ -65,14 +65,16 @@ They inherit your current model until you set preferences. Details: [docs/defaul
65
65
 
66
66
  ## Commands
67
67
 
68
- | Command | Opens |
69
- | ---------------- | ------------------------------------------------------ |
70
- | `/agents` | Settings (mode, limits, model picking, tool filtering) |
71
- | `/agents types` | Agent-type browser and editor |
72
- | `/agents tree` | Fullscreen tree and live viewer with manual steering |
73
- | `/agents import` | Import agents from other subagent extensions |
74
- | `/agents reload` | Reload definitions and settings |
75
- | `/agents reap` | Confirm the eligible count, then forget completed agents and free retained-thread slots (cannot be resumed); preserves active parents and ancestors of retained threads. Session files remain on disk. |
68
+ | Command | Opens |
69
+ | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
70
+ | `/agents` | Settings (mode, limits, model picking, tool filtering) |
71
+ | `/agents types` | Agent-type browser and editor |
72
+ | `/agents tree` | Fullscreen tree and live viewer with manual steering |
73
+ | `/agents import` | Import agents from other subagent extensions |
74
+ | `/agents fork:<agent> <task>` | Start a detached agent that inherits your current conversation (autocompletes every available agent) |
75
+ | `/agents fresh:<agent> <task>` | Start a detached agent with no inherited context (autocompletes every available agent) |
76
+ | `/agents reload` | Reload definitions and settings |
77
+ | `/agents reap` | Confirm the eligible count, then forget completed agents and free retained-thread slots (cannot be resumed); preserves active parents and ancestors of retained threads. Session files remain on disk. |
76
78
 
77
79
  A live **Agents** widget sits above the input box. Choose **Full** (the existing tree) or **Minimal** (colored status counts and running-agent token totals, plus the browser hint) under **Status Widget** in `/agents` settings. In the fullscreen tree, **Enter** opens an agent's live view. Type in the bottom **Steer** input and press **Enter** to send it a steering message, including nested agents. **Tab** switches between input and transcript controls, **Escape** returns, and **i** in the tree opens existing thread actions. A status strip below the previews shows how many agents are running and **Press ← to open subagent browser**. Once the main turn ends and all subagents are idle, the preview collapses to a single status-count line. A fresh prompt hides previously settled agents from the widget; they reappear only when resumed, and `/agents tree` always keeps them available. While subagents are starting or running, press **Left** at the start of the main draft to open it; otherwise Left stays native. Press **Right** at the end of the draft (or in an empty input) to collapse the widget to one line for this session only, without changing saved settings. `/agents tree` remains available regardless of agent activity. See [live navigation](docs/tools-and-ui.md#live-agent-navigation) for controls and compatibility.
78
80
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-subagent-manager",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "Hierarchical, steerable subagent threads for pi",
5
5
  "type": "module",
6
6
  "engines": {
package/src/index.ts CHANGED
@@ -649,8 +649,44 @@ export default function piSubagent(pi: ExtensionAPI): void {
649
649
  context = undefined;
650
650
  });
651
651
  const agentSubcommands = ["tree", "settings", "types", "import", "reload", "reap"] as const;
652
+ const spawnModes = ["fork", "fresh"] as const;
653
+ /** `/agents fork:<type> <task>` inherits the main conversation; `fresh:` starts with no context. */
654
+ const spawnFromCommand = async (
655
+ ctx: ExtensionContext,
656
+ mode: (typeof spawnModes)[number],
657
+ typeName: string,
658
+ task: string,
659
+ ) => {
660
+ if (limits.subagentMode === "off") {
661
+ ctx.ui.notify("Subagent Mode is off. Change it in /agents settings.", "warning");
662
+ return;
663
+ }
664
+ const current = requireManager();
665
+ if (!store.list().some((type) => type.name === typeName)) {
666
+ ctx.ui.notify(`Unknown agent type: ${typeName}`, "error");
667
+ return;
668
+ }
669
+ const base = typeName.replace(/[^A-Za-z0-9_-]/g, "-").replace(/^[^A-Za-z0-9]+/, "") || "agent";
670
+ const taken = new Set(current.list().map((thread) => thread.path));
671
+ const prefix = mode === "fork" ? "/root/" : "/";
672
+ let n = 1;
673
+ while (taken.has(`${prefix}${base}-${n}`)) n++;
674
+ const path = `${prefix}${base}-${n}`;
675
+ try {
676
+ await current.scope("/root").spawn({ path, type: typeName, task, wait: false });
677
+ persist();
678
+ refreshWidget(ctx);
679
+ ctx.ui.notify(
680
+ `Started ${typeName} (${mode === "fork" ? "forked context" : "fresh context"}) at ${path}`,
681
+ "info",
682
+ );
683
+ } catch (error) {
684
+ ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
685
+ }
686
+ };
652
687
  pi.registerCommand("agents", {
653
- description: "Configure agent settings, import/edit definitions, or show the live tree",
688
+ description:
689
+ "Configure agent settings, show the live tree, or run /agents fork:<agent> | fresh:<agent> <task>",
654
690
  getArgumentCompletions: (argumentText) => {
655
691
  const text = argumentText.trimStart();
656
692
  const completed = text.match(/^(\S+)(\s+)([\s\S]*)$/);
@@ -662,9 +698,33 @@ export default function piSubagent(pi: ExtensionAPI): void {
662
698
  .filter((path) => path !== "/root");
663
699
  const matched = fuzzyFilter(paths, completed[3]!.trimStart(), (path) => path);
664
700
  if (matched.length === 0) return null;
665
- return matched.map((path) => ({ value: `tree ${path}`, label: path }));
701
+ return matched.map((path) => ({
702
+ value: `tree ${path}`,
703
+ label: path,
704
+ }));
666
705
  }
667
706
  if ((agentSubcommands as readonly string[]).includes(command)) return null;
707
+ if (/^(fork|fresh):/.test(command)) return null;
708
+ }
709
+ const lower = text.toLowerCase();
710
+ const colon = lower.indexOf(":");
711
+ // "fo", "fork", "fork:", "fork:wo" -> every matching `fork:<agent>` / `fresh:<agent>`.
712
+ if (lower === "f")
713
+ return spawnModes.map((mode) => ({ value: `${mode}:`, label: `${mode}:` }));
714
+ const modes = spawnModes.filter((mode) =>
715
+ colon >= 0 ? lower.slice(0, colon) === mode : lower.length >= 2 && mode.startsWith(lower),
716
+ );
717
+ if (modes.length) {
718
+ const names = store.list().map((type) => type.name);
719
+ const filter = colon >= 0 ? lower.slice(colon + 1) : "";
720
+ const matched = filter ? fuzzyFilter(names, filter, (name) => name) : names;
721
+ const out = modes.flatMap((mode) =>
722
+ matched.map((name) => ({
723
+ value: `${mode}:${name}`,
724
+ label: `${mode}:${name}`,
725
+ })),
726
+ );
727
+ if (out.length) return out;
668
728
  }
669
729
  const matched = fuzzyFilter([...agentSubcommands], text, (name) => name);
670
730
  if (matched.length === 0) return null;
@@ -672,7 +732,13 @@ export default function piSubagent(pi: ExtensionAPI): void {
672
732
  },
673
733
  handler: async (args, ctx) => {
674
734
  const [command, ...rest] = args.trim().split(/\s+/);
675
- if (command === "import") {
735
+ const spawnMatch = args.trim().match(/^(fork|fresh):(\S+)(?:\s+([\s\S]*))?$/);
736
+ if (spawnMatch) {
737
+ const task = spawnMatch[3]?.trim();
738
+ if (!task)
739
+ ctx.ui.notify(`Usage: /agents ${spawnMatch[1]}:${spawnMatch[2]} <task>`, "warning");
740
+ else await spawnFromCommand(ctx, spawnMatch[1] as "fork" | "fresh", spawnMatch[2]!, task);
741
+ } else if (command === "import") {
676
742
  await importAgents(ctx, false);
677
743
  } else if (command === "types") {
678
744
  await editAgentTypes(ctx, store, limits.nerdFontIcons, {
@@ -747,7 +813,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
747
813
  );
748
814
  } else
749
815
  ctx.ui.notify(
750
- "Usage: /agents [tree [path] | settings | types | import | reload | reap]",
816
+ "Usage: /agents [tree [path] | settings | types | import | reload | reap | fork:<agent> <task> | fresh:<agent> <task>]",
751
817
  "warning",
752
818
  );
753
819
  },
package/src/ui/dialog.ts CHANGED
@@ -191,6 +191,7 @@ export class DialogMenu {
191
191
  selectedId?: string,
192
192
  readonly footer = "↑↓ navigate · Enter select · Esc close",
193
193
  private saveId?: string,
194
+ private renderLegend?: (theme: Theme) => string,
194
195
  ) {
195
196
  const index = rows.findIndex((row) => row.id === selectedId);
196
197
  if (index >= 0) this.selected = index;
@@ -224,11 +225,16 @@ export class DialogMenu {
224
225
  render(width: number): string[] {
225
226
  const height = dialogHeight(this.host);
226
227
  const inner = Math.max(0, width - 4);
228
+ const legend = this.renderLegend
229
+ ? wrapTextWithAnsi(this.renderLegend(this.theme), Math.max(1, inner - 1))
230
+ .slice(0, Math.max(0, height - 8))
231
+ .map((line) => ` ${line}`)
232
+ : [];
227
233
  const help = (this.rows[this.selected]?.help ?? "")
228
234
  .split(/\r\n?|\n/)
229
235
  .flatMap((line) => wrapTextWithAnsi(dialogText(line), Math.max(1, inner - 1)))
230
- .slice(0, Math.max(1, height - 7));
231
- this.viewport = Math.max(1, height - 6 - help.length);
236
+ .slice(0, Math.max(1, height - 7 - legend.length));
237
+ this.viewport = Math.max(1, height - 6 - help.length - legend.length);
232
238
  const start = Math.max(
233
239
  0,
234
240
  Math.min(
@@ -262,6 +268,12 @@ export class DialogMenu {
262
268
  "",
263
269
  ...help.map((line) => this.theme.fg("muted", ` ${line}`)),
264
270
  ];
271
+ if (legend.length) {
272
+ const budget = Math.max(0, height - 4 - legend.length);
273
+ body.length = Math.min(body.length, budget);
274
+ while (body.length < budget) body.push("");
275
+ body.push(...legend);
276
+ }
265
277
  return frameDialog(
266
278
  this.theme,
267
279
  width,
@@ -286,7 +298,7 @@ export async function dialogMenu(
286
298
  ctx: ExtensionContext,
287
299
  title: string,
288
300
  rows: DialogRow[],
289
- options: { selectedId?: string; footer?: string; saveId?: string } = {},
301
+ options: { selectedId?: string; footer?: string; saveId?: string; renderLegend?: (theme: Theme) => string } = {},
290
302
  ): Promise<string | undefined> {
291
303
  return ctx.ui.custom(
292
304
  (host, theme, _keys, done) =>
@@ -299,6 +311,7 @@ export async function dialogMenu(
299
311
  options.selectedId,
300
312
  options.footer,
301
313
  options.saveId,
314
+ options.renderLegend,
302
315
  ),
303
316
  DIALOG_OPTIONS,
304
317
  );
@@ -1,4 +1,4 @@
1
- import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
1
+ import type { ExtensionCommandContext, Theme } from "@earendil-works/pi-coding-agent";
2
2
  import type { ConfigStore } from "../prefs/config.ts";
3
3
  import {
4
4
  canOpenDialog,
@@ -163,10 +163,16 @@ function withProvenance(row: DialogRow, keys: (keyof ManagerSettings)[], layers:
163
163
  renderLabel: (label, theme) =>
164
164
  (globalChanged ? theme.fg("accent", "●") + " " : "") +
165
165
  (projectChanged ? theme.fg("warning", "●") + " " : "") + label.replace(/^\[labs\] /, ""),
166
- help: `${row.label}\n${row.help ?? ""}\nDots (saved): accent ● Global; warning ● Current Project; both ● ● changed in both.`,
166
+ help: `${row.label}\n${row.help ?? ""}`,
167
167
  };
168
168
  }
169
169
 
170
+ function provenanceLegend(theme: Theme): string {
171
+ const global = theme.fg("accent", "●");
172
+ const project = theme.fg("warning", "●");
173
+ return theme.fg("muted", "Saved: ") + `${global} Global · ${project} Current Project · ${global} ${project} Both`;
174
+ }
175
+
170
176
  /** Edits the shared draft; only the outer settings screen saves or applies it. */
171
177
  async function configureFooterDisplay(ctx: ExtensionCommandContext, draft: ManagerSettings, layers: SettingsLayers): Promise<void> {
172
178
  let selectedId: string | undefined;
@@ -194,7 +200,7 @@ async function configureFooterDisplay(ctx: ExtensionCommandContext, draft: Manag
194
200
  ] as DialogRow[]).map((row) => {
195
201
  const key = ({ location: "costDisplay", value: "costValue", icon: "costIcon" } as Record<string, keyof ManagerSettings>)[row.id];
196
202
  return key ? withProvenance(row, [key], layers) : row;
197
- }), { selectedId, footer: "↑↓/Tab navigate · Enter edit · Esc back" });
203
+ }), { selectedId, renderLegend: provenanceLegend, footer: "↑↓/Tab navigate · Enter edit · Esc back" });
198
204
  if (!action || action === "back") return;
199
205
  selectedId = action;
200
206
  if (action === "location") {
@@ -381,6 +387,7 @@ async function configureAgentsDialog(
381
387
  {
382
388
  selectedId,
383
389
  saveId: "save",
390
+ renderLegend: provenanceLegend,
384
391
  footer: "↑↓/Tab navigate · Enter edit · Ctrl+S save · Esc cancel",
385
392
  },
386
393
  );