pi-better-subagents 0.32.6 → 0.32.7

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.
@@ -57,19 +57,7 @@ export function projectAssignment(meta, processStatus, observation = { verified:
57
57
 
58
58
  /** All consumers use the same lineage and authoritative wait read. Park caches are hints only. */
59
59
  export function assignmentFor(meta, processStatus = meta.status, options = {}) {
60
- return assignmentFromSnapshot(meta, processStatus, options, () => readAttempts(options));
61
- }
62
-
63
- function readAttempts(options) {
64
- const base = options.baseDir ?? join(tmpdir(), "pi-better-subagents");
65
- const attempts = [];
66
- try {
67
- for (const id of readdirSync(join(base, "runs"))) {
68
- const candidate = readAttempt(base, id);
69
- if (candidate) attempts.push(candidate);
70
- }
71
- } catch { /* Registry gaps cannot establish a newer attempt. */ }
72
- return attempts;
60
+ return createAssignmentProjector(options)(meta, processStatus);
73
61
  }
74
62
 
75
63
  function readAttempt(base, id) {
package/list.mjs CHANGED
@@ -104,7 +104,7 @@ export function formatSubagentListRow(meta, p) {
104
104
  const batch = meta.batchId
105
105
  ? ` [batch: ${meta.batchName ? `${bounded(meta.batchName, 40)} ` : ""}${bounded(meta.batchId, 60)}]`
106
106
  : "";
107
- const assignment = assignmentFor(meta, p.processStatus ?? meta.status);
107
+ const assignment = p.assignment ?? assignmentFor(meta, p.processStatus ?? meta.status);
108
108
  const diagnostic = meta.operations || meta.park || status !== assignment.processStatus || status === "failed"
109
109
  ? `\n ${assignmentDiagnostic(assignment)}` : "";
110
110
  return `• ${name}${meta.id} [${status}] session_id=${meta.sessionId ?? "unavailable"} ${bounded(meta.model ?? "?", 60)} ${elapsed}${health}${timing}${batch}${failure}\n ${promptPreview(meta)} · r${assignment.revision}${diagnostic}`;
@@ -133,6 +133,7 @@ export function collectSubagentList(p) {
133
133
 
134
134
  const displayed = items.slice(offset, offset + options.limit);
135
135
  const rows = displayed.map((row) => formatSubagentListRow(row.meta, {
136
+ assignment: p.assignmentOf?.(row.meta),
136
137
  status: row.status,
137
138
  now,
138
139
  health: healthById(row.meta.id),
package/output-payload.ts CHANGED
@@ -862,12 +862,13 @@ export function listIncidentLabel(id: string, cwd: string, terminal: boolean): s
862
862
  export function listRevisions(
863
863
  items: Array<{ id: string; status: string; meta?: RunMeta }>,
864
864
  failureSignatures: string[],
865
+ assignmentOf = (meta: RunMeta) => assignmentFor(meta, effectiveStatus(meta)),
865
866
  ): { contentRevision: string; failureRevision: string } {
866
867
  return {
867
868
  contentRevision: revisionOf(items.map((item) => [
868
869
  item.id,
869
870
  item.status,
870
- item.meta ? assignmentFor(item.meta, effectiveStatus(item.meta)).revision : null,
871
+ item.meta ? assignmentOf(item.meta).revision : null,
871
872
  item.meta?.status ?? null,
872
873
  item.meta?.exitCode ?? null,
873
874
  item.meta?.endedAt ?? null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-subagents",
3
- "version": "0.32.6",
3
+ "version": "0.32.7",
4
4
  "description": "Pi extension for detached, sandboxed subagent runs that keep the foreground session free.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -90,6 +90,7 @@ type NavigatorState = {
90
90
  lastHint?: string | null;
91
91
  lastMainListLines?: string[];
92
92
  lastMainListSignature?: string;
93
+ mainListRows?: InternalRow[];
93
94
  mainListWidgetInstalled?: boolean;
94
95
  mainListRequestRender?: () => void;
95
96
  mainListSelectedId?: string;
@@ -121,6 +122,7 @@ export const NAVIGATOR_STATUS_KEY = "background-work-nav";
121
122
  export const CLOSE_CONFIRM_STATUS_KEY = "background-work-close";
122
123
  export const MAIN_LIST_WIDGET_KEY = "background-work-list";
123
124
  export const DETAIL_TICK_MS = 10_000;
125
+ export const MAIN_LIST_REFRESH_MS = 1_000;
124
126
  export const CLOSE_ARM_MS = 3000;
125
127
  export const DEFAULT_LOG_TAIL_ROWS = 25;
126
128
  export const LOG_TAIL_ROW_CHOICES = [10, 25] as const;
@@ -208,6 +210,7 @@ export function ensureBackgroundWorkNavigator(ctx: ExtensionContext, deps: HostD
208
210
  try { setNavigatorPanel(ctx, MAIN_LIST_WIDGET_KEY, undefined); } catch { /* ignore */ }
209
211
  s.mainListWidgetInstalled = false;
210
212
  s.mainListRequestRender = undefined;
213
+ s.mainListRows = undefined;
211
214
  s.mainListDeadlineScheduler?.dispose();
212
215
  s.mainListDeadlineScheduler = createRenderScheduler(() => refreshMainListWidget());
213
216
  installNavigatorEditor(ctx.ui as any, deps);
@@ -242,6 +245,7 @@ export function disposeBackgroundWorkNavigator(ctx?: ExtensionContext, owner?: s
242
245
  s.lastHint = undefined;
243
246
  s.lastMainListLines = undefined;
244
247
  s.lastMainListSignature = undefined;
248
+ s.mainListRows = undefined;
245
249
  s.mainListDeadlineScheduler?.dispose();
246
250
  s.mainListDeadlineScheduler = undefined;
247
251
  s.mainListWidgetInstalled = false;
@@ -290,13 +294,15 @@ function refreshMainListWidget(): void {
290
294
  if (!ctx || !deps || !isNavigatorUiAvailable(ctx)) return;
291
295
  const now = Date.now();
292
296
  const rows = listRows(now);
297
+ s.mainListRows = rows;
293
298
  s.mainListDeadlineScheduler?.cancel();
294
299
  const nextExpiry = rows.reduce<number | undefined>((next, row) => {
295
300
  if (row.expiresAt === undefined || row.expiresAt <= now) return next;
296
301
  return next === undefined ? row.expiresAt : Math.min(next, row.expiresAt);
297
302
  }, undefined);
298
- if (nextExpiry !== undefined) {
299
- s.mainListDeadlineScheduler?.schedule(nextExpiry - now);
303
+ if (rows.length) {
304
+ // External writers cannot notify this host. Refresh independently of paint frequency.
305
+ s.mainListDeadlineScheduler?.schedule(Math.min(MAIN_LIST_REFRESH_MS, nextExpiry === undefined ? Infinity : nextExpiry - now));
300
306
  }
301
307
  syncMainListSelection(rows);
302
308
  const nextSignature = rows.length ? mainListSignature(rows, {
@@ -409,12 +415,12 @@ function createMainListWidget(tui: { requestRender?(): void }, theme: unknown, d
409
415
  if (!Number.isFinite(event.x) || event.x < 0 || event.x >= width) return undefined;
410
416
  if (!Number.isInteger(event.y) || event.y < 0 || event.y >= lineOwners.length) return undefined;
411
417
  const id = lineOwners[event.y];
412
- return id && listRows().some((row) => row.navigatorId === id) ? id : undefined;
418
+ return id && state().mainListRows?.some((row) => row.navigatorId === id) ? id : undefined;
413
419
  };
414
420
  const pointer = createPointerNavigation(rowAt, openNavigatorRow);
415
421
  return {
416
422
  render(width: number): string[] {
417
- const rows = listRows();
423
+ const rows = state().mainListRows ?? [];
418
424
  syncMainListSelection(rows);
419
425
  if (!rows.length) {
420
426
  state().lastMainListLines = undefined;
package/tools.ts CHANGED
@@ -14,7 +14,7 @@
14
14
  * far as `execute` is concerned).
15
15
  */
16
16
 
17
- import { assignmentFor } from "./assignment-projection.mjs";
17
+ import { assignmentFor, createAssignmentProjector } from "./assignment-projection.mjs";
18
18
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
19
19
  import { readMeta, listRunRecords, effectiveStatus, isFinalResultStatus, type RunCallbackOrigin, type RunMeta, type RunStatus } from "./registry.ts";
20
20
  import { buildSubagentResultPayload } from "./finalization.ts";
@@ -337,6 +337,16 @@ export function subagentListTool(Type: TypeModule, baseSession: SubagentToolSess
337
337
  // are listed even when they were spawned by another foreground.
338
338
  const cwd = listCwd(ctx, resolved.origin);
339
339
  const scopeKey = listFolderScopeKey(p.all === true, cwd);
340
+ const project = createAssignmentProjector();
341
+ const assignments = new Map<string, ReturnType<typeof assignmentFor>>();
342
+ const assignmentOf = (meta: RunMeta) => {
343
+ let assignment = assignments.get(meta.id);
344
+ if (!assignment) {
345
+ assignment = project(meta, effectiveStatus(meta));
346
+ assignments.set(meta.id, assignment);
347
+ }
348
+ return assignment;
349
+ };
340
350
  const healthCache = new Map<string, HealthObservation>();
341
351
  const healthById = (id: string) => {
342
352
  const hit = healthCache.get(id);
@@ -352,7 +362,8 @@ export function subagentListTool(Type: TypeModule, baseSession: SubagentToolSess
352
362
  params: p,
353
363
  cwd,
354
364
  now,
355
- statusOf: (meta: RunMeta) => assignmentFor(meta, effectiveStatus(meta)).state,
365
+ statusOf: (meta: RunMeta) => assignmentOf(meta).state,
366
+ assignmentOf,
356
367
  healthById,
357
368
  });
358
369
  const items = collected.items as Array<{ meta: RunMeta; status: string }>;
@@ -364,6 +375,7 @@ export function subagentListTool(Type: TypeModule, baseSession: SubagentToolSess
364
375
  const revisions = listRevisions(
365
376
  items.map((row) => ({ id: row.meta.id, status: String(row.status), meta: row.meta })),
366
377
  items.map((row) => incidents.get(row.meta.id)?.revision ?? ""),
378
+ assignmentOf,
367
379
  );
368
380
  const statusesKey = Array.isArray(p.status) ? [...p.status].map(String).sort().join(",") : String(p.status ?? "");
369
381
  const incidentRuns = items.filter((row) => (incidents.get(row.meta.id)?.count ?? 0) > 0).length;
@@ -373,6 +385,7 @@ export function subagentListTool(Type: TypeModule, baseSession: SubagentToolSess
373
385
  render: (row) => {
374
386
  const incident = incidents.get(row.meta.id);
375
387
  return formatSubagentListRow(row.meta, {
388
+ assignment: assignmentOf(row.meta),
376
389
  processStatus: effectiveStatus(row.meta),
377
390
  status: row.status,
378
391
  now,