pi-better-subagents 0.33.0 → 0.35.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/agent-catalog.mjs +24 -0
- package/agent-commands.ts +71 -4
- package/agent-inspection.ts +2 -1
- package/agents-catalog-tool.ts +8 -1
- package/assignment-outcomes.ts +44 -6
- package/capacity.mjs +13 -0
- package/catalog-host-admission.ts +69 -0
- package/catalog-overlay.ts +10 -0
- package/catalog-runtime.ts +10 -2
- package/catalog-store.ts +23 -0
- package/catalog-ui.ts +26 -10
- package/continuation-authority.ts +29 -0
- package/continuation.ts +21 -0
- package/docs/agent-catalog-operations.md +38 -0
- package/failures.ts +7 -1
- package/health.ts +0 -1
- package/index.ts +282 -113
- package/launch-abort.ts +21 -0
- package/managed-background-capability.ts +9 -0
- package/managed-failure-worker.mjs +27 -0
- package/managed-launch-bootstrap.mjs +35 -0
- package/managed-launch-client.ts +56 -0
- package/managed-launch-host.ts +351 -0
- package/managed-launch-journal.mjs +18 -0
- package/managed-launch-ownership.ts +22 -0
- package/managed-launch-port.ts +21 -0
- package/managed-launch-recovery.ts +45 -0
- package/managed-worker-bridge.ts +48 -0
- package/managed-worker.mjs +11 -0
- package/package.json +1 -1
- package/permission-policy.ts +12 -0
- package/registry.ts +2 -0
- package/runtime-client/artifacts/darwin-arm64.gz +0 -0
- package/runtime-client/artifacts/darwin-arm64.json +1 -1
- package/runtime-client/artifacts/darwin-x64.gz +0 -0
- package/runtime-client/artifacts/darwin-x64.json +1 -1
- package/runtime-client/artifacts/linux-arm64.gz +0 -0
- package/runtime-client/artifacts/linux-arm64.json +1 -1
- package/runtime-client/artifacts/linux-x64.gz +0 -0
- package/runtime-client/artifacts/linux-x64.json +1 -1
- package/runtime-client/src/daemon-owner.mjs +2 -1
- package/runtime-client/src/runtime/work-client.mjs +16 -2
- package/shared-callback-batcher.ts +4 -1
- package/shared-catalog.ts +69 -0
- package/shared-failure-observations.ts +3 -0
- package/shared-navigator.ts +23 -5
- package/shared-operation-coordinator/assignment-observation.mjs +48 -1
- package/shared-operation-coordinator/index.ts +2 -0
- package/shared-operation-coordinator/src/background-parent-callbacks.ts +68 -0
- package/shared-operation-coordinator/src/background-requests.ts +79 -0
- package/shared-operation-coordinator/src/discovery.ts +9 -0
- package/shared-operation-coordinator/src/operations.ts +6 -4
- package/shared-operation-coordinator/src/result-supervision.ts +128 -0
- package/shared-operation-coordinator/src/schema.ts +50 -1
- package/shared-operation-coordinator/src/store.ts +38 -0
- package/shared-operation-coordinator/src/subagent-launch.ts +119 -0
- package/shared-operation-coordinator/src/types.ts +6 -0
- package/shared-operation-coordinator/src/upgrade.ts +22 -0
- package/shared-work-client.d.mts +4 -1
- package/shared-work-client.mjs +16 -2
- package/skill-picker.ts +6 -2
- package/task-runtime.mjs +1 -0
- package/timing-notifications.ts +37 -0
- package/timing.ts +1 -0
- package/tools.ts +10 -3
- package/work-observation.ts +18 -2
- package/worker-waits.ts +46 -14
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { parseSubagentTools } from "./shared-task-tools.ts";
|
|
2
|
+
/** Intersect captured permissions with the current mandatory profile. */
|
|
3
|
+
export function intersectContinuationPermissions(captured: any, current: any): any {
|
|
4
|
+
if (!captured || !current) throw new Error("Continuation permission authority unavailable");
|
|
5
|
+
const currentTools = parseSubagentTools(current.subagentTools);
|
|
6
|
+
const capturedTools = captured.subagentTools ? parseSubagentTools(captured.subagentTools) : currentTools;
|
|
7
|
+
const allowed = new Set(currentTools.trusted.map(tool => JSON.stringify([tool.name, tool.package])));
|
|
8
|
+
const tools = { applyPatch: capturedTools.applyPatch && currentTools.applyPatch,
|
|
9
|
+
trusted: capturedTools.trusted.filter(tool => allowed.has(JSON.stringify([tool.name, tool.package])))
|
|
10
|
+
.sort((a, b) => a.name.localeCompare(b.name) || a.package.localeCompare(b.package)) };
|
|
11
|
+
const intersect = (old: any, fresh: any) => {
|
|
12
|
+
if (!old || !fresh) throw new Error("Continuation permission profile unavailable");
|
|
13
|
+
const access = ["off", "read", "write", "read-write"];
|
|
14
|
+
const value = { ...fresh, enabled: old.enabled || fresh.enabled };
|
|
15
|
+
for (const key of ["projectFiles", "outsideProject", "storedCredentials"]) {
|
|
16
|
+
if (!access.includes(old[key]) || !access.includes(fresh[key])) throw new Error("Invalid continuation permission profile");
|
|
17
|
+
value[key] = access[Math.min(access.indexOf(old[key]), access.indexOf(fresh[key]))];
|
|
18
|
+
}
|
|
19
|
+
for (const key of ["commands", "network"]) value[key] = old[key] && fresh[key];
|
|
20
|
+
value.shell = old.shell !== false && fresh.shell !== false;
|
|
21
|
+
value.processAccess = old.processAccess === "read" && fresh.processAccess === "read" ? "read" : "off";
|
|
22
|
+
const caps = [old.commandTimeoutSeconds, fresh.commandTimeoutSeconds].filter((n) => typeof n === "number" && n > 0);
|
|
23
|
+
value.commandTimeoutSeconds = caps.length ? Math.min(...caps) : null;
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
return { permissions: captured.permissions ? intersect(captured.permissions, current.main) : current.main,
|
|
27
|
+
subagentPermissions: captured.subagentPermissions ? intersect(captured.subagentPermissions, current.subagents) : current.subagents,
|
|
28
|
+
subagentTools: tools };
|
|
29
|
+
}
|
package/continuation.ts
CHANGED
|
@@ -1028,3 +1028,24 @@ export function readConversationLease(sessionId: string): (LeasePayload & { raw:
|
|
|
1028
1028
|
return undefined;
|
|
1029
1029
|
}
|
|
1030
1030
|
}
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
/** Release exact undispatched server ownership under the ordinary conversation lock. */
|
|
1034
|
+
export function releaseUnspawnedConversationLease(input: {
|
|
1035
|
+
sessionId: string; attemptId: string; managerPid: number; managerStart: string;
|
|
1036
|
+
canProveUnspawned(): boolean;
|
|
1037
|
+
}): boolean {
|
|
1038
|
+
return withConversationMutation(input.sessionId, () => {
|
|
1039
|
+
const lease = readConversationLease(input.sessionId);
|
|
1040
|
+
if (!lease) return true;
|
|
1041
|
+
if (lease.attemptId !== input.attemptId || lease.pid !== input.managerPid || !lease.start
|
|
1042
|
+
|| Buffer.from(lease.start).toString("base64url") !== input.managerStart) return false;
|
|
1043
|
+
if (processExists(lease.pid)) {
|
|
1044
|
+
const start = processStartToken(lease.pid);
|
|
1045
|
+
if (!start || start === lease.start) return false;
|
|
1046
|
+
}
|
|
1047
|
+
if (!input.canProveUnspawned()) return false;
|
|
1048
|
+
releaseLeaseUnlocked(leasePathFor(input.sessionId), lease.raw);
|
|
1049
|
+
return readConversationLease(input.sessionId) === undefined;
|
|
1050
|
+
}, { waitMs: RELEASE_LOCK_WAIT_MS });
|
|
1051
|
+
}
|
|
@@ -4,6 +4,44 @@ Commands, the read-only discovery tool, and the Codex importer for `pi-agent/v1`
|
|
|
4
4
|
|
|
5
5
|
## Commands
|
|
6
6
|
|
|
7
|
+
### Shared runtime writes
|
|
8
|
+
|
|
9
|
+
Production catalog reads and persistent edits use the canonical agent directory's
|
|
10
|
+
server. Each edit submits the content revision read by that invocation. If another
|
|
11
|
+
client changed the catalog, the server returns `catalog-conflict`; reopen the view
|
|
12
|
+
before trying again. A conflict does not overwrite the newer definition or discard
|
|
13
|
+
the current session branch's temporary choices. Model/effort still use the existing
|
|
14
|
+
`agents/settings.json`; skill changes still use the original Markdown definition.
|
|
15
|
+
|
|
16
|
+
The server serializes cooperating clients' comparison and atomic writes. A direct
|
|
17
|
+
external editor does not participate in this transaction and can race the revision
|
|
18
|
+
comparison and rename. This is not a filesystem-wide compare-and-swap guarantee.
|
|
19
|
+
Open catalog views subscribe to source revisions. The server shares filesystem
|
|
20
|
+
watches and reconciles at most 64 subscribed scopes once per second, including
|
|
21
|
+
paths created after subscription. Revoked subscriptions discard project data;
|
|
22
|
+
the fixed host revalidates its current context before resubscribing. A disconnected
|
|
23
|
+
or missing host requires reopening the view. External changes are
|
|
24
|
+
also visible on the next explicit catalog request. An admitted launch or
|
|
25
|
+
batch retains its frozen snapshot; later changes affect future admission only,
|
|
26
|
+
not an existing attempt, continuation recipe, tools, or sandbox permissions.
|
|
27
|
+
|
|
28
|
+
The fixed Pi host adapter reads the actual workspace, session, branch, overlay
|
|
29
|
+
revision, and `ctx.isProjectTrusted()` decision. It creates an unguessable grant
|
|
30
|
+
in the canonical agent directory's private `catalog-host-admission` directory
|
|
31
|
+
(0700; records 0600). The server checks the record, secret hash, generation,
|
|
32
|
+
exact scope, and live host connection on every request using that grant.
|
|
33
|
+
Issuance is not a socket operation or a tool. Session strings and wire trust
|
|
34
|
+
booleans cannot issue a grant. The CLI's fixed adapter uses the existing SDK
|
|
35
|
+
trust store rather than accepting a project trust argument.
|
|
36
|
+
|
|
37
|
+
The host revalidates its context before catalog operations and at a bounded
|
|
38
|
+
interval while connected. Trust or branch changes invalidate the old grant.
|
|
39
|
+
Host shutdown and connection loss revoke it; reconnect requires current host
|
|
40
|
+
validation and a new grant. Session-only trust does not update the user's trust
|
|
41
|
+
store. Grants remain control metadata, never definition fields, index rows,
|
|
42
|
+
protocol logs, or launch recipes. As in the server's existing security model,
|
|
43
|
+
a process fully controlling the same UID is outside this boundary.
|
|
44
|
+
|
|
7
45
|
`/agents` is one Pi command. Dialogs use `ctx.ui.select`, `confirm`, `input`, and `editor`. `ctx.hasUI` is false in print and JSON mode. When a choice or confirmation is required there, the command returns `clarification-needed` and writes nothing.
|
|
8
46
|
|
|
9
47
|
In an interactive TUI, `/agents`, `/agents list`, and `/agents show` open a focused catalog view instead of leaving the listing in a persistent widget. Rows align name, effective model, source, and launch state; narrow terminals retain name and model. The model is the resolved actual model when available, otherwise the requested or inherited preference, or `not resolved`. Type to filter by id, name, description, or base role; use Up/Down and Enter to inspect. The detail view opens **Settings**, with Model, Effort, Skills, launch resolution, and diagnostics. **Instructions** contains the complete effective prompt (role plus agent in add mode, agent text in replace mode); this is not the task-specific launch prompt. **Files** shows definition and saved-config sources plus current session edits. Tab and Shift+Tab cycle between these pages; `p` opens Instructions. Up/Down selects settings or scrolls the current page. Left or Escape returns to Settings, then list, clears the filter, then closes. `/agents show <id>` opens that definition directly. Print/JSON callers still receive the complete text and structured result; bare `/agents` still returns help outside the custom TUI.
|
package/failures.ts
CHANGED
|
@@ -160,7 +160,8 @@ function exactRuleLeftovers(path: string, prior: FailureState): Set<string> {
|
|
|
160
160
|
.filter((x) => x.category === "tool" && x.status === "unresolved" && leftover(x.id)).map((x) => x.id));
|
|
161
161
|
}
|
|
162
162
|
/** Scan complete source records, independent of the finite progress/transcript tail. */
|
|
163
|
-
export function collectRunFailures(id: string, cwd: string, terminal = false): FailureState {
|
|
163
|
+
export function collectRunFailures(id: string, cwd: string, terminal = false, assertCurrent: () => void = () => {}): FailureState {
|
|
164
|
+
assertCurrent();
|
|
164
165
|
const path = failurePath(id);
|
|
165
166
|
let fd: number;
|
|
166
167
|
try { fd = openSync(logPathFor(id), "r"); }
|
|
@@ -229,6 +230,7 @@ export function collectRunFailures(id: string, cwd: string, terminal = false): F
|
|
|
229
230
|
let oversized = false;
|
|
230
231
|
const buffer = Buffer.alloc(CHUNK);
|
|
231
232
|
while (position < size) {
|
|
233
|
+
assertCurrent();
|
|
232
234
|
const count = readSync(fd, buffer, 0, Math.min(CHUNK, size - position), position);
|
|
233
235
|
if (!count) break;
|
|
234
236
|
let from = 0;
|
|
@@ -251,9 +253,11 @@ export function collectRunFailures(id: string, cwd: string, terminal = false): F
|
|
|
251
253
|
(row.type === "tool_execution_end" && typeof row.isError !== "boolean" && typeof row.result?.isError !== "boolean" && typeof row.result?.exitCode !== "number") ||
|
|
252
254
|
(row.type === "message_end" && (!row.message || typeof row.message.role !== "string")) ||
|
|
253
255
|
(row.type === "auto_retry_end" && typeof row.success !== "boolean")) throw new Error("invalid structured event");
|
|
256
|
+
assertCurrent();
|
|
254
257
|
fold(id, scan, row, start, cwd);
|
|
255
258
|
}
|
|
256
259
|
} catch {
|
|
260
|
+
assertCurrent();
|
|
257
261
|
observeFailures(path, [{ id: `malformed:${start}`, operation: "child-log", kind: "incomplete", summary: "Child log contains malformed structured events; observations may be incomplete" }]);
|
|
258
262
|
}
|
|
259
263
|
}
|
|
@@ -270,6 +274,7 @@ export function collectRunFailures(id: string, cwd: string, terminal = false): F
|
|
|
270
274
|
if (!oversized && rest.length) fragments.push(Buffer.from(rest));
|
|
271
275
|
position += count;
|
|
272
276
|
}
|
|
277
|
+
assertCurrent();
|
|
273
278
|
scan.offset = start;
|
|
274
279
|
if (scan.gap) settleMetadataGap(id, scan);
|
|
275
280
|
scans.delete(id);
|
|
@@ -280,6 +285,7 @@ export function collectRunFailures(id: string, cwd: string, terminal = false): F
|
|
|
280
285
|
operation: "child-log-access", kind: "recovered", incidents: [access.id] }]);
|
|
281
286
|
if (terminal && position > start) observeFailures(path, [{ id: `partial:${start}`, operation: "child-log", kind: "incomplete", summary: "Child log ends with a partial event; observations may be incomplete" }]);
|
|
282
287
|
} catch {
|
|
288
|
+
assertCurrent();
|
|
283
289
|
observeFailures(path, [{ id: "log-read-error", operation: "child-log", kind: "incomplete", summary: "Child log could not be fully scanned; observations may be incomplete" }]);
|
|
284
290
|
} finally { closeSync(fd); }
|
|
285
291
|
return readRunFailures(id);
|
package/health.ts
CHANGED
|
@@ -244,7 +244,6 @@ export function needsMonitoring(
|
|
|
244
244
|
(m) => ownedByThisParent(m, parentPid) && (
|
|
245
245
|
m.status === "running"
|
|
246
246
|
|| m.status === "orphaned"
|
|
247
|
-
|| (m.status === "lost" && m.lostCallbackSentAt === undefined && m.lostCallbackSuppressedAt === undefined)
|
|
248
247
|
),
|
|
249
248
|
);
|
|
250
249
|
}
|