pi-better-goal 0.13.0 → 0.13.1
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
|
@@ -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 =
|
|
63
|
-
let current = meta;
|
|
66
|
+
const attempts = [];
|
|
64
67
|
try {
|
|
65
|
-
for (const id of
|
|
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
|
|
69
|
-
|
|
70
|
-
|
|
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]]);
|
package/src/subagents.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 =
|
|
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
|
+
}
|