pi-better-harness 0.45.1 → 0.45.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.45.2] - 2026-11-13
4
+
5
+ ### Fixed
6
+
7
+ - Bundle Subagents 0.32.1 and Goal 0.13.1 to share assignment lineage discovery within each Navigator or Goal activity refresh, reducing repeated metadata reads and JSON parsing. (#726, #727)
8
+
3
9
  ## [0.45.1] - 2026-11-12
4
10
 
5
11
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-goal",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "Pi extension for goal tracking with background-aware continuation.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -10,6 +10,7 @@ export interface AssignmentProjection {
10
10
  verified: boolean;
11
11
  }
12
12
  export function assignmentFor(meta: object, processStatus?: string, options?: { baseDir?: string | undefined; coordinatorPath?: string; observation?: object }): AssignmentProjection;
13
+ export function createAssignmentProjector(options?: { baseDir?: string | undefined; coordinatorPath?: string; observation?: object }): (meta: object, processStatus?: string) => AssignmentProjection;
13
14
  export function projectAssignment(meta: object, processStatus: string, observation?: object): AssignmentProjection;
14
15
  export function assignmentDiagnostic(assignment: AssignmentProjection): string;
15
16
  export const ASSIGNMENT_STATES: string[];
@@ -58,18 +58,53 @@ export function projectAssignment(meta, processStatus, observation = { verified:
58
58
 
59
59
  /** All consumers use the same lineage and authoritative wait read. Park caches are hints only. */
60
60
  export function assignmentFor(meta, processStatus = meta.status, options = {}) {
61
+ return assignmentFromSnapshot(meta, processStatus, options, () => readAttempts(options));
62
+ }
63
+
64
+ function readAttempts(options) {
61
65
  const base = options.baseDir ?? join(tmpdir(), "pi-better-subagents");
62
- const attempts = new Map([[meta.id, meta]]);
63
- let current = meta;
66
+ const attempts = [];
64
67
  try {
65
- for (const id of (meta.operations || meta.park ? readdirSync(join(base, "runs")) : [])) {
68
+ for (const id of readdirSync(join(base, "runs"))) {
66
69
  try {
67
70
  const candidate = JSON.parse(readFileSync(join(base, "runs", id, "meta.json"), "utf8"));
68
- if (candidate.sessionId === meta.sessionId && candidate.cwd === meta.cwd
69
- && (!meta.assignment || candidate.assignment?.assignmentId === meta.assignment.assignmentId)) attempts.set(candidate.id, candidate);
70
- } catch { /* A partial unrelated record must not hide a continuation. */ }
71
+ if (candidate && typeof candidate === "object") attempts.push(candidate);
72
+ }
73
+ catch { /* A partial unrelated record must not hide a continuation. */ }
71
74
  }
72
75
  } catch { /* Registry gaps cannot establish a newer attempt. */ }
76
+ return attempts;
77
+ }
78
+
79
+ /** One synchronous UI refresh shares a snapshot; the next refresh reads disk again. */
80
+ export function createAssignmentProjector(options = {}) {
81
+ let snapshot;
82
+ const readSnapshot = (meta) => {
83
+ if (!snapshot) {
84
+ snapshot = new Map();
85
+ for (const candidate of readAttempts(options)) {
86
+ let workspaces = snapshot.get(candidate.sessionId);
87
+ if (!workspaces) snapshot.set(candidate.sessionId, workspaces = new Map());
88
+ let attempts = workspaces.get(candidate.cwd);
89
+ if (!attempts) workspaces.set(candidate.cwd, attempts = []);
90
+ attempts.push(candidate);
91
+ }
92
+ }
93
+ return snapshot.get(meta.sessionId)?.get(meta.cwd) ?? [];
94
+ };
95
+ return (meta, processStatus = meta.status) => assignmentFromSnapshot(meta, processStatus, options,
96
+ () => readSnapshot(meta));
97
+ }
98
+
99
+ function assignmentFromSnapshot(meta, processStatus, options, readSnapshot) {
100
+ const attempts = new Map([[meta.id, meta]]);
101
+ let current = meta;
102
+ if (meta.operations || meta.park) {
103
+ for (const candidate of readSnapshot()) {
104
+ if (candidate.sessionId === meta.sessionId && candidate.cwd === meta.cwd
105
+ && (!meta.assignment || candidate.assignment?.assignmentId === meta.assignment.assignmentId)) attempts.set(candidate.id, candidate);
106
+ }
107
+ }
73
108
  // Conversation roots survive explicit follow-ups. Only automatic resume edges
74
109
  // join attempts into one assignment; manual continuation starts a new one.
75
110
  const lineage = new Map([[meta.id, meta]]);
@@ -1,4 +1,4 @@
1
- import { assignmentFor } from "./shared-assignment-projection.mjs";
1
+ import { createAssignmentProjector } from "./shared-assignment-projection.mjs";
2
2
  import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
@@ -127,8 +127,9 @@ export function subagentStatusToItem(
127
127
  meta: SubagentRunMeta,
128
128
  status: SubagentEffectiveStatus,
129
129
  baseDir?: string,
130
+ project = createAssignmentProjector({ baseDir }),
130
131
  ): BackgroundWorkItem {
131
- const assignment = assignmentFor(meta, status, { baseDir });
132
+ const assignment = project(meta, status);
132
133
  const active = assignment.state === "running" || assignment.state === "waiting";
133
134
  const unhealthy = status === "orphaned";
134
135
  const terminal = !active;
@@ -167,10 +168,11 @@ export function collectSubagentActivity(
167
168
  const parentPid = options.parentPid ?? process.pid;
168
169
  const processExists = options.processExists ?? defaultProcessExists;
169
170
  const metas = readParentSubagentMetas(options.baseDir, parentPid);
171
+ const project = createAssignmentProjector({ baseDir: options.baseDir });
170
172
 
171
173
  return {
172
174
  providerId: "subagents",
173
175
  label: "Subagents",
174
- items: metas.map((meta) => subagentStatusToItem(meta, effectiveSubagentStatus(meta, processExists), options.baseDir)),
176
+ items: metas.map((meta) => subagentStatusToItem(meta, effectiveSubagentStatus(meta, processExists), options.baseDir, project)),
175
177
  };
176
- }
178
+ }
@@ -9,6 +9,7 @@ export interface AssignmentProjection {
9
9
  verified: boolean;
10
10
  }
11
11
  export function assignmentFor(meta: object, processStatus?: string, options?: { baseDir?: string | undefined; coordinatorPath?: string; observation?: object }): AssignmentProjection;
12
+ export function createAssignmentProjector(options?: { baseDir?: string | undefined; coordinatorPath?: string; observation?: object }): (meta: object, processStatus?: string) => AssignmentProjection;
12
13
  export function projectAssignment(meta: object, processStatus: string, observation?: object): AssignmentProjection;
13
14
  export function assignmentDiagnostic(assignment: AssignmentProjection): string;
14
15
  export const ASSIGNMENT_STATES: string[];
@@ -57,18 +57,53 @@ 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) {
60
64
  const base = options.baseDir ?? join(tmpdir(), "pi-better-subagents");
61
- const attempts = new Map([[meta.id, meta]]);
62
- let current = meta;
65
+ const attempts = [];
63
66
  try {
64
- for (const id of (meta.operations || meta.park ? readdirSync(join(base, "runs")) : [])) {
67
+ for (const id of readdirSync(join(base, "runs"))) {
65
68
  try {
66
69
  const candidate = JSON.parse(readFileSync(join(base, "runs", id, "meta.json"), "utf8"));
67
- if (candidate.sessionId === meta.sessionId && candidate.cwd === meta.cwd
68
- && (!meta.assignment || candidate.assignment?.assignmentId === meta.assignment.assignmentId)) attempts.set(candidate.id, candidate);
69
- } catch { /* A partial unrelated record must not hide a continuation. */ }
70
+ if (candidate && typeof candidate === "object") attempts.push(candidate);
71
+ }
72
+ catch { /* A partial unrelated record must not hide a continuation. */ }
70
73
  }
71
74
  } catch { /* Registry gaps cannot establish a newer attempt. */ }
75
+ return attempts;
76
+ }
77
+
78
+ /** One synchronous UI refresh shares a snapshot; the next refresh reads disk again. */
79
+ export function createAssignmentProjector(options = {}) {
80
+ let snapshot;
81
+ const readSnapshot = (meta) => {
82
+ if (!snapshot) {
83
+ snapshot = new Map();
84
+ for (const candidate of readAttempts(options)) {
85
+ let workspaces = snapshot.get(candidate.sessionId);
86
+ if (!workspaces) snapshot.set(candidate.sessionId, workspaces = new Map());
87
+ let attempts = workspaces.get(candidate.cwd);
88
+ if (!attempts) workspaces.set(candidate.cwd, attempts = []);
89
+ attempts.push(candidate);
90
+ }
91
+ }
92
+ return snapshot.get(meta.sessionId)?.get(meta.cwd) ?? [];
93
+ };
94
+ return (meta, processStatus = meta.status) => assignmentFromSnapshot(meta, processStatus, options,
95
+ () => readSnapshot(meta));
96
+ }
97
+
98
+ function assignmentFromSnapshot(meta, processStatus, options, readSnapshot) {
99
+ const attempts = new Map([[meta.id, meta]]);
100
+ let current = meta;
101
+ if (meta.operations || meta.park) {
102
+ for (const candidate of readSnapshot()) {
103
+ if (candidate.sessionId === meta.sessionId && candidate.cwd === meta.cwd
104
+ && (!meta.assignment || candidate.assignment?.assignmentId === meta.assignment.assignmentId)) attempts.set(candidate.id, candidate);
105
+ }
106
+ }
72
107
  // Conversation roots survive explicit follow-ups. Only automatic resume edges
73
108
  // join attempts into one assignment; manual continuation starts a new one.
74
109
  const lineage = new Map([[meta.id, meta]]);
@@ -11,7 +11,7 @@
11
11
  * launch is the result · completion posts back · the foreground never blocks
12
12
  */
13
13
 
14
- import { assignmentFor } from "./assignment-projection.mjs";
14
+ import { createAssignmentProjector } from "./assignment-projection.mjs";
15
15
  import { historicalWaits, attentionRevision, attentionDismissed, dismissAttention } from "./historical-attention.ts";
16
16
  import { registerAssignmentAttempt, commitAssignmentTerminal, readOutcome, receiptOutcome, outcomeTranscriptReceipt, inspectOutcome, createOutcomeHost, closeOutcomeHost, claimOutcome, type AssignmentBinding } from "./assignment-outcomes.ts";
17
17
  import { currentSandboxPermissions } from "./permission-policy.ts";
@@ -1391,7 +1391,8 @@ function navigatorRows(visible?: RunMeta[], at?: number) {
1391
1391
 
1392
1392
  /** Runs that should advertise/open the left-arrow navigator affordance. */
1393
1393
  function navigatorRunningRuns(): RunMeta[] {
1394
- return sessionVisibleNavigatorRuns().filter((m) => ["running", "waiting"].includes(assignmentFor(m, effectiveStatus(m)).state));
1394
+ const project = createAssignmentProjector();
1395
+ return sessionVisibleNavigatorRuns(Date.now(), project).filter((m) => ["running", "waiting"].includes(project(m, effectiveStatus(m)).state));
1395
1396
  }
1396
1397
 
1397
1398
  function navigatorRunningCount(): number {
@@ -1403,16 +1404,16 @@ function navigatorRunningCount(): number {
1403
1404
  * each rebuild still reads owned non-terminal metadata so external status
1404
1405
  * changes are visible immediately without a time-based memo.
1405
1406
  */
1406
- function sessionVisibleNavigatorRuns(now: number = Date.now()): RunMeta[] {
1407
+ function sessionVisibleNavigatorRuns(now: number = Date.now(), project = createAssignmentProjector()): RunMeta[] {
1407
1408
  const origin = activeCallbackOrigin;
1408
1409
  if (!origin) return [];
1409
1410
  return navigatorVisibleRuns(listMetasForOrigin(origin))
1410
1411
  .filter(belongsToActiveNavigatorSession)
1411
- .filter((m) => !isExpiredTerminalNavigatorRun(m, now));
1412
+ .filter((m) => !isExpiredTerminalNavigatorRun(m, now, project));
1412
1413
  }
1413
1414
 
1414
- function isExpiredTerminalNavigatorRun(meta: RunMeta, now: number): boolean {
1415
- const status = assignmentFor(meta, effectiveStatus(meta)).state;
1415
+ function isExpiredTerminalNavigatorRun(meta: RunMeta, now: number, project = createAssignmentProjector()): boolean {
1416
+ const status = project(meta, effectiveStatus(meta)).state;
1416
1417
  if (!isTerminalNavigatorStatus(status)) return false;
1417
1418
  const endedAt = meta.endedAt ?? meta.lostAt;
1418
1419
  return typeof endedAt === "number" && now - endedAt >= TERMINAL_NAVIGATOR_RETENTION_MS;
@@ -24,7 +24,7 @@
24
24
  * with visible-width-aware truncation.
25
25
  */
26
26
 
27
- import { assignmentFor } from "./assignment-projection.mjs";
27
+ import { assignmentFor, createAssignmentProjector } from "./assignment-projection.mjs";
28
28
  import {
29
29
  formatNavigatorHealthFacts,
30
30
  statusThemeColor,
@@ -190,8 +190,9 @@ export function pendingNavigatorPark(meta) {
190
190
 
191
191
  export function buildNavigatorRows(metas, deps) {
192
192
  const now = deps.now ?? Date.now();
193
+ const project = createAssignmentProjector();
193
194
  return metas.map((m) => {
194
- const assignment = assignmentFor(m, deps.effectiveStatus(m));
195
+ const assignment = project(m, deps.effectiveStatus(m));
195
196
  const status = assignment.state;
196
197
  const health = typeof deps.healthFor === "function" ? deps.healthFor(m) : undefined;
197
198
  const effort = typeof deps.effortFor === "function" ? deps.effortFor(m) : (m.effort ?? m.modelEffort);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-subagents",
3
- "version": "0.32.0",
3
+ "version": "0.32.1",
4
4
  "description": "Pi extension for detached, sandboxed subagent runs that keep the foreground session free.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-harness",
3
- "version": "0.45.1",
3
+ "version": "0.45.2",
4
4
  "description": "Pi extension bundle for a write sandbox, subagents, background tasks, SSH, goals, model routing, and Outcome & Todo.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -59,12 +59,12 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "pi-better-background-tasks": "0.15.1",
62
- "pi-better-goal": "0.13.0",
62
+ "pi-better-goal": "0.13.1",
63
63
  "pi-better-model-router": "0.1.4",
64
64
  "pi-ollama-cloud": "0.13.1",
65
65
  "pi-better-sandbox": "0.14.1",
66
66
  "pi-better-ssh": "0.1.5",
67
- "pi-better-subagents": "0.32.0",
67
+ "pi-better-subagents": "0.32.1",
68
68
  "proper-lockfile": "^4.1.2",
69
69
  "shell-quote": "1.12.0",
70
70
  "smol-toml": "1.9.0",