@ferris1225/pi-subagents 6.0.4 → 7.0.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.
@@ -19,10 +19,8 @@ import type { IsolationMode, WorktreeFinalizationStatus } from "../isolation/wor
19
19
  // Types
20
20
  // ---------------------------------------------------------------------------
21
21
 
22
- export type RunStatus = "queued" | "running" | "interrupting" | "parked" | "done" | "failed";
23
-
24
22
  /** A queued run is preparing its child process; execution has no capacity wait. */
25
- export type RunWaitReason = "starting";
23
+ export type RunStatus = "queued" | "running" | "interrupting" | "parked" | "done" | "failed";
26
24
 
27
25
  export function isRunActiveStatus(status: RunStatus): boolean {
28
26
  return status === "queued" || status === "running" || status === "interrupting";
@@ -42,16 +40,12 @@ export interface RunView {
42
40
  * are doing, not just by their run id. */
43
41
  label?: string;
44
42
  model?: string;
45
- /** Selected model ref when the run handed off to current main. */
46
- modelFallbackFrom?: string;
47
43
  /** Effective thinking strength this run was launched with (setup override or role default). */
48
44
  thinking?: string;
49
45
  isolation?: IsolationMode;
50
46
  integrationStatus?: RunIntegrationStatus;
51
47
  worktreeId?: string;
52
48
  status: RunStatus;
53
- /** What a queued run is actually waiting for; see RunWaitReason. */
54
- waitReason?: RunWaitReason;
55
49
  usage: UsageStats;
56
50
  /** Concise current activity ("thinking", "read src/index.ts"); last writer wins. */
57
51
  activity?: string;
@@ -68,13 +62,6 @@ export interface RunView {
68
62
  endedAt?: number;
69
63
  }
70
64
 
71
- export interface RunChainMeta {
72
- isolation?: IsolationMode;
73
- worktreeId?: string;
74
- /** Initial startup state before the child emits activity. */
75
- waitReason?: RunWaitReason;
76
- }
77
-
78
65
  // ---------------------------------------------------------------------------
79
66
  // Formatting helpers
80
67
  // ---------------------------------------------------------------------------
@@ -288,7 +275,7 @@ function usageCostPart(usage: UsageStats | undefined): string | undefined {
288
275
  return usage?.cost ? `$${usage.cost.toFixed(4)}` : undefined;
289
276
  }
290
277
 
291
- /** Aggregate usage across several runs (chain steps or a completion group). */
278
+ /** Aggregate usage across the runs of a completion group. */
292
279
  export function sumUsage(parts: readonly UsageStats[]): UsageStats {
293
280
  const total: UsageStats = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, contextTokens: 0, turns: 0 };
294
281
  for (const part of parts) {
@@ -308,7 +295,7 @@ export function formatDuration(ms: number): string {
308
295
  if (totalSeconds < 60) return `${totalSeconds}s`;
309
296
  const minutes = Math.floor(totalSeconds / 60);
310
297
  const seconds = totalSeconds % 60;
311
- // Seconds stay visible at every magnitude: a long-running chain is judged
298
+ // Seconds stay visible at every magnitude: a long-running run is judged
312
299
  // by whether it is still moving, and "5s ago" is exactly that signal.
313
300
  if (minutes < 60) return `${minutes}m${String(seconds).padStart(2, "0")}s`;
314
301
  const hours = Math.floor(minutes / 60);
@@ -481,7 +468,7 @@ export class MonitorStore {
481
468
  this.notify();
482
469
  }
483
470
 
484
- addRun(agent: string, task: string, model?: string, thinking?: string, meta?: RunChainMeta): number {
471
+ addRun(agent: string, task: string, model?: string, thinking?: string, isolation?: IsolationMode): number {
485
472
  const id = this.reserveRunId();
486
473
  this.runs.push({
487
474
  id,
@@ -491,10 +478,9 @@ export class MonitorStore {
491
478
  model,
492
479
  thinking,
493
480
  status: "queued",
494
- waitReason: meta?.waitReason ?? "starting",
495
481
  usage: emptyUsage(),
496
482
  elapsedMs: 0,
497
- ...(meta?.isolation ? { isolation: meta.isolation, integrationStatus: meta.isolation === "worktree" ? "pending" : undefined, ...(meta.worktreeId ? { worktreeId: meta.worktreeId } : {}) } : {}),
483
+ ...(isolation ? { isolation, integrationStatus: isolation === "worktree" ? "pending" : undefined } : {}),
498
484
  });
499
485
  this.notify();
500
486
  return id;
@@ -508,7 +494,6 @@ export class MonitorStore {
508
494
  const isExecuting = status === "running" || status === "interrupting";
509
495
  const now = Date.now();
510
496
  run.status = status;
511
- if (status !== "queued") run.waitReason = undefined;
512
497
  if (isExecuting && !wasExecuting) {
513
498
  run.startedAt ??= now;
514
499
  run.activeSince = now;
@@ -522,15 +507,6 @@ export class MonitorStore {
522
507
  }
523
508
  this.notify();
524
509
  }
525
- /** Record what a still-queued run is actually waiting for, at the exact
526
- * transition owned by the caller (lane wait begins, child process starts). */
527
- setWaitReason(id: number, waitReason: RunWaitReason): void {
528
- const run = this.find(id);
529
- if (!run || run.status !== "queued" || run.waitReason === waitReason) return;
530
- run.waitReason = waitReason;
531
- this.notify();
532
- }
533
-
534
510
  setUsage(id: number, usage: UsageStats, model?: string): void {
535
511
  const run = this.find(id);
536
512
  if (!run) return;
@@ -539,12 +515,11 @@ export class MonitorStore {
539
515
  this.notify();
540
516
  }
541
517
 
542
- /** Record the final actual model and selected-to-main transition. */
543
- setModel(id: number, model?: string, fallbackFrom?: string): void {
518
+ /** Record the model of the current attempt. */
519
+ setModel(id: number, model?: string): void {
544
520
  const run = this.find(id);
545
- if (!run) return;
546
- if (model) run.model = model;
547
- run.modelFallbackFrom = fallbackFrom;
521
+ if (!run || !model) return;
522
+ run.model = model;
548
523
  this.notify();
549
524
  }
550
525
 
@@ -707,21 +682,16 @@ export function statusIcon(status: RunStatus, theme: Theme): string {
707
682
  export function statusLabel(status: RunStatus): string {
708
683
  switch (status) {
709
684
  case "queued":
710
- return "queued";
685
+ return "starting";
711
686
  case "running":
712
687
  return "running";
713
688
  case "interrupting":
714
689
  return "interrupting";
715
690
  case "parked":
716
- return "parked";
691
+ return "interrupted";
717
692
  case "done":
718
693
  return "done";
719
694
  case "failed":
720
695
  return "stopped";
721
696
  }
722
697
  }
723
-
724
- /** Startup label for runs that have not emitted activity yet. */
725
- export function runWaitLabel(run: Pick<RunView, "status" | "waitReason">): string | undefined {
726
- return run.status === "queued" ? "starting" : undefined;
727
- }
@@ -11,10 +11,6 @@ const SUBAGENTS_WIDGET_ID = "pi-subagents";
11
11
  const MAX_WIDGET_LINES = 10;
12
12
  const SEPARATOR = " · ";
13
13
 
14
- function waitWord(run: Pick<RunView, "waitReason">): string {
15
- return run.waitReason === "starting" ? "starting" : "queued";
16
- }
17
-
18
14
  function worktreeBadge(run: RunView): string | undefined {
19
15
  if (run.isolation !== "worktree") return undefined;
20
16
  const state = run.integrationStatus;
@@ -55,7 +51,7 @@ function detailLine(activity: string | undefined, run: RunView | undefined, them
55
51
  }
56
52
 
57
53
  function runRow(run: RunView, theme: Theme, width: number, now: number): TaskRow {
58
- const state = run.status === "queued" ? waitWord(run) : run.integrationStatus === "finalizing" ? "applying" : run.status;
54
+ const state = run.status === "queued" ? "starting" : run.integrationStatus === "finalizing" ? "applying" : run.status;
59
55
  const label = run.label ?? formatTaskSummary(run.task, Math.max(1, width - 18));
60
56
  const narrowState = width < 60 && (run.status === "queued" || run.integrationStatus === "finalizing") ? " · " + state : "";
61
57
  const identity = statusIcon(run.status, theme) + " " + theme.fg("dim", "#" + run.id) + " " + run.agent + narrowState + " · " + label;
@@ -72,10 +68,9 @@ function runRow(run: RunView, theme: Theme, width: number, now: number): TaskRow
72
68
  function rowCost(row: TaskRow): number { return 1 + Number(Boolean(row.requiredDetail && row.detail)); }
73
69
 
74
70
  /** Select identities before optional details. Overflow describes only hidden work. */
75
- function renderBoard(rows: TaskRow[], theme: Theme, width: number, overview?: string): string[] {
76
- if (width <= 0 || !rows.length) return [];
71
+ function renderBoard(rows: TaskRow[], theme: Theme, width: number, overview: string): string[] {
77
72
  const totalCost = rows.reduce((cost, row) => cost + rowCost(row), 0);
78
- const lines = overview ? [overview] : [];
73
+ const lines = [overview];
79
74
  const capacity = MAX_WIDGET_LINES - lines.length - Number(totalCost + lines.length > MAX_WIDGET_LINES);
80
75
  const selected = new Set<TaskRow>();
81
76
  let used = 0;
@@ -102,11 +97,6 @@ function renderBoard(rows: TaskRow[], theme: Theme, width: number, overview?: st
102
97
  return lines.map((line) => truncateToWidth(line, width, "…"));
103
98
  }
104
99
 
105
- export function formatActiveRunLines(runs: readonly RunView[], theme: Theme, width: number, now = Date.now()): string[] {
106
- const rows = runs.filter((run) => isRunActiveStatus(run.status)).map((run) => runRow(run, theme, width, now));
107
- return rows.length ? renderBoard(rows, theme, width) : [];
108
- }
109
-
110
100
  export function formatSubagentWidgetLines(
111
101
  runs: readonly RunView[], theme: Theme, width: number, now = Date.now(),
112
102
  ): string[] {
@@ -117,7 +107,7 @@ export function formatSubagentWidgetLines(
117
107
  const states = new Map<string, number>();
118
108
  for (const row of rows) states.set(row.state, (states.get(row.state) ?? 0) + 1);
119
109
  const counts = ["failed", "interrupting", "running", "queued"]
120
- .filter((state) => states.has(state)).map((state) => states.get(state) + " " + state);
110
+ .filter((state) => states.has(state)).map((state) => states.get(state) + " " + (state === "queued" ? "starting" : state));
121
111
  const overview = theme.bold("Subagents") + theme.fg("dim", " " + counts.join(SEPARATOR));
122
112
  return renderBoard(rows, theme, width, overview);
123
113
  }
@@ -1,39 +0,0 @@
1
- /** One-time data migration for the role rename. Runtime dispatch accepts only
2
- * current catalog names; these helpers are used only at storage boundaries. */
3
-
4
- export function migrateStoredAgentName(name: string): string {
5
- if (name === "reviewer" || name === "critic" || name === "skeptic") return "sentinel";
6
- return name;
7
- }
8
-
9
- /** Valid explicit new settings win; old keys disappear after persistence. */
10
- export function migrateStoredRoleKeys<T>(settings: Record<string, T>): Record<string, T> {
11
- const migrated = { ...settings };
12
- for (const [name, value] of Object.entries(settings)) {
13
- const current = migrateStoredAgentName(name);
14
- if (current === name) continue;
15
- if (!Object.hasOwn(migrated, current)) migrated[current] = value;
16
- delete migrated[name];
17
- }
18
- return migrated;
19
- }
20
-
21
- function migrateField(value: unknown, key: string): boolean {
22
- if (!value || typeof value !== "object") return false;
23
- const record = value as Record<string, unknown>;
24
- if (typeof record[key] !== "string") return false;
25
- const name = record[key].trim();
26
- const current = migrateStoredAgentName(name);
27
- if (current === name) return false;
28
- record[key] = current;
29
- return true;
30
- }
31
-
32
- /** Thread manifests retain their ids, leases, and recovery paths. */
33
- export function migrateStoredRecordRoles(value: unknown): boolean {
34
- if (!value || typeof value !== "object") return false;
35
- const summary = (value as { resultSummary?: unknown }).resultSummary;
36
- const threadChanged = migrateField(value, "agentName");
37
- const summaryChanged = migrateField(summary, "agent");
38
- return threadChanged || summaryChanged;
39
- }