pi-better-subagents 0.32.7 → 0.34.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/README.md +13 -0
- 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 +14 -3
- package/assignment-projection.mjs +12 -4
- package/assignment-report.ts +92 -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/child-operations.ts +2 -0
- package/child-ownership.ts +1 -1
- package/docs/agent-catalog-operations.md +38 -0
- package/health-observation.ts +9 -4
- package/index.ts +154 -84
- package/launch-abort.ts +21 -0
- package/list.mjs +1 -1
- package/navigator.mjs +2 -1
- package/operation-bridge-types.ts +18 -1
- package/output-payload.ts +2 -0
- package/package.json +4 -2
- package/parse.ts +7 -6
- package/registry.ts +4 -2
- package/runtime-client/artifacts/darwin-arm64.gz +0 -0
- package/runtime-client/artifacts/darwin-arm64.json +1 -0
- package/runtime-client/artifacts/darwin-x64.gz +0 -0
- package/runtime-client/artifacts/darwin-x64.json +1 -0
- package/runtime-client/artifacts/linux-arm64.gz +0 -0
- package/runtime-client/artifacts/linux-arm64.json +1 -0
- package/runtime-client/artifacts/linux-x64.gz +0 -0
- package/runtime-client/artifacts/linux-x64.json +1 -0
- package/runtime-client/scripts/private-runtime/format.mjs +90 -0
- package/runtime-client/src/daemon-owner.mjs +218 -0
- package/runtime-client/src/runtime/client.mjs +130 -0
- package/runtime-client/src/runtime/root.mjs +41 -0
- package/runtime-client/src/runtime/socket.mjs +9 -0
- package/runtime-client/src/runtime/status-cli.mjs +14 -0
- package/runtime-client/src/runtime/work-client.mjs +102 -0
- package/runtime-client/src/startup/artifact.mjs +76 -0
- package/runtime-client/src/startup/install.mjs +184 -0
- package/runtime-client/src/startup/managed-types.mjs +1 -0
- package/runtime-client/src/startup/runtime.mjs +120 -0
- package/session-store.ts +85 -30
- package/shared-catalog.ts +69 -0
- package/shared-harness-settings.ts +4 -2
- package/shared-log-utils.ts +18 -7
- package/shared-navigator.ts +16 -4
- package/shared-operation-coordinator/assignment-observation.mjs +80 -3
- package/shared-operation-coordinator/index.ts +2 -0
- package/shared-operation-coordinator/src/discovery.ts +9 -0
- package/shared-operation-coordinator/src/errors.ts +2 -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 +39 -1
- package/shared-operation-coordinator/src/store.ts +55 -0
- package/shared-operation-coordinator/src/task-cancellation.ts +224 -0
- package/shared-operation-coordinator/src/types.ts +6 -0
- package/shared-work-client.d.mts +12 -0
- package/shared-work-client.mjs +102 -0
- package/skill-picker.ts +6 -2
- package/tools.ts +39 -2
- package/work-observation.ts +177 -0
- package/worker-operations-host.ts +3 -0
- package/worker-waits.ts +50 -13
package/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ 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";
|
|
18
|
+
import { createToolDescriptor } from "./operation-bridge-types.ts";
|
|
18
19
|
import { requestResumeAdmission } from "./worker-waits.ts";
|
|
19
20
|
import { execSync } from "node:child_process";
|
|
20
21
|
import { writeFileSync, mkdirSync, renameSync, statSync } from "node:fs";
|
|
@@ -23,6 +24,9 @@ import * as PiCodingAgent from "@earendil-works/pi-coding-agent";
|
|
|
23
24
|
import * as PiTui from "@earendil-works/pi-tui";
|
|
24
25
|
import { CustomEditor } from "@earendil-works/pi-coding-agent";
|
|
25
26
|
import { initializeNavigatorPanels } from "./shared-navigator-panels.ts";
|
|
27
|
+
import { workObservation, workObservationFailure, startWorkObservation, stopWorkObservation, observedAssignment, observedList, requestWorkDetail, TERMINAL_NAVIGATOR_RETENTION_MS } from "./work-observation.ts";
|
|
28
|
+
import { withAssignmentObservations } from "./assignment-projection.mjs";
|
|
29
|
+
import { formatNavigatorHealthFacts } from "./health-surface.mjs";
|
|
26
30
|
import { matchesKey, Key, truncateToWidth, type AutocompleteItem } from "@earendil-works/pi-tui";
|
|
27
31
|
import { Type } from "@earendil-works/pi-ai";
|
|
28
32
|
import {
|
|
@@ -37,6 +41,7 @@ import {
|
|
|
37
41
|
type BackgroundWorkRow,
|
|
38
42
|
} from "./shared-navigator.ts";
|
|
39
43
|
import { spawnDetached, killProcessTree, type SpawnResult } from "./spawn.ts";
|
|
44
|
+
import { abortUncommittedLaunch } from "./launch-abort.ts";
|
|
40
45
|
import { parseRun, parseRunForLifecycle, readRunTranscript, resetParseRunCursor, type Usage } from "./parse.ts";
|
|
41
46
|
import { finalizeRun as finalizeRunCore } from "./finalization.ts";
|
|
42
47
|
import { selectSessionByName } from "./session-selection.ts";
|
|
@@ -88,7 +93,6 @@ import {
|
|
|
88
93
|
sessionsDir,
|
|
89
94
|
runDir,
|
|
90
95
|
recordTaskRuntimeProvenance,
|
|
91
|
-
discardFailedLaunch,
|
|
92
96
|
recordLaunchAttempt,
|
|
93
97
|
clearLaunchAttempt,
|
|
94
98
|
logPathFor,
|
|
@@ -162,7 +166,6 @@ import {
|
|
|
162
166
|
} from "./widget.ts";
|
|
163
167
|
import {
|
|
164
168
|
executeNavigatorClose,
|
|
165
|
-
buildNavigatorRows,
|
|
166
169
|
pendingNavigatorPark,
|
|
167
170
|
buildNavigatorDetail,
|
|
168
171
|
} from "./navigator.ts";
|
|
@@ -195,7 +198,7 @@ import {
|
|
|
195
198
|
createLaunchEnricher,
|
|
196
199
|
blankCatalogSelector,
|
|
197
200
|
hasCatalogSelector,
|
|
198
|
-
|
|
201
|
+
loadSharedLaunchSnapshot,
|
|
199
202
|
noteCatalogHost,
|
|
200
203
|
prepareCatalogJob,
|
|
201
204
|
catalogDefaultNote,
|
|
@@ -237,6 +240,7 @@ import {
|
|
|
237
240
|
} from "./worker-waits.ts";
|
|
238
241
|
import { defaultUserRoot, type CatalogSnapshot } from "./catalog-store.ts";
|
|
239
242
|
import { restrictContextFilesToWorktree } from "./shared-worktree-context.ts";
|
|
243
|
+
import { noteCatalogHostContext, closeCatalogHost } from "./catalog-host-admission.ts";
|
|
240
244
|
|
|
241
245
|
const SUBAGENT_MODE_ACTIONS: readonly AutocompleteItem[] = [
|
|
242
246
|
{ value: "history", label: "history", description: "Inspect or cancel waits from other sessions" },
|
|
@@ -482,6 +486,8 @@ function warnInterruptedSubagents(ctx: ExtensionContext, interrupted: RunMeta[],
|
|
|
482
486
|
let sessionTornDown = false;
|
|
483
487
|
let outcomeHost = createOutcomeHost();
|
|
484
488
|
const outcomeAdmission = new Map<string, () => boolean>();
|
|
489
|
+
const outcomeEnqueuing = new Set<string>();
|
|
490
|
+
let outcomeTicker: ReturnType<typeof setInterval> | undefined;
|
|
485
491
|
|
|
486
492
|
/**
|
|
487
493
|
* "The rightful conversation is not the active one", not "this notification is
|
|
@@ -572,31 +578,69 @@ function enqueueCompletionCallback(pi: ExtensionAPI, id: string): void {
|
|
|
572
578
|
}
|
|
573
579
|
|
|
574
580
|
async function enqueueAssignmentOutcome(pi: ExtensionAPI, meta: RunMeta): Promise<void> {
|
|
581
|
+
if (outcomeEnqueuing.has(meta.id)) return;
|
|
582
|
+
outcomeEnqueuing.add(meta.id);
|
|
583
|
+
try { await tryEnqueueAssignmentOutcome(pi, meta); }
|
|
584
|
+
catch (error) {
|
|
585
|
+
try { deferOutcome(meta, `Outcome reconciliation failed: ${String(error)}`); } catch { /* storage remains unavailable; next reconciliation retries */ }
|
|
586
|
+
}
|
|
587
|
+
finally { outcomeEnqueuing.delete(meta.id); }
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function deferOutcome(meta: RunMeta, reason?: string): void {
|
|
591
|
+
const current = readMeta(meta.id);
|
|
592
|
+
if (!current || current.outcomeDeliveryDeferredReason === reason) return;
|
|
593
|
+
current.outcomeDeliveryDeferredReason = reason;
|
|
594
|
+
writeMeta(current);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
async function tryEnqueueAssignmentOutcome(pi: ExtensionAPI, meta: RunMeta): Promise<void> {
|
|
575
598
|
const outcome = readOutcome(meta);
|
|
576
599
|
const ctx = uiCtx;
|
|
577
|
-
if (!outcome || outcome.deliveryReceipt || outcome.disposition
|
|
578
|
-
|
|
600
|
+
if (!outcome || outcome.deliveryReceipt || outcome.disposition) return;
|
|
601
|
+
if (!ctx || meta.callback === false || typeof ctx.sessionManager?.getBranch !== "function") {
|
|
602
|
+
deferOutcome(meta, meta.callback === false ? "Assignment callbacks are disabled."
|
|
603
|
+
: "Recorded parent transcript is unavailable; automatic reconciliation will retry.");
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
579
606
|
const active = ownerBindingFromContext(ctx);
|
|
580
607
|
if (active.sessionId !== outcome.recipient.sessionId || active.workspace !== outcome.recipient.workspace
|
|
581
|
-
|| (outcome.recipient.branchId && !ctx.sessionManager.getBranch().some((entry) => entry.id === outcome.recipient.branchId)))
|
|
608
|
+
|| (outcome.recipient.branchId && !ctx.sessionManager.getBranch().some((entry) => entry.id === outcome.recipient.branchId))) {
|
|
609
|
+
deferOutcome(meta, "Recorded parent session, workspace or branch is inactive; automatic reconciliation will retry.");
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
582
612
|
const prior = outcomeTranscriptReceipt(ctx.sessionManager.getBranch(), outcome.eventId);
|
|
583
613
|
if (prior) { receiptOutcome(meta, prior); return; }
|
|
614
|
+
const deliveryHost = outcomeHost;
|
|
584
615
|
const gate = await requestResumeAdmission(pi, active, { timeoutMs: 50 });
|
|
585
616
|
outcomeAdmission.set(outcome.eventId, () => gate.allowed ? gate.isCurrent?.() !== false : !active.goalId && !outcome.recipient.goalId && gate.revision === -1);
|
|
586
|
-
if (!gate.allowed && (active.goalId || outcome.recipient.goalId || gate.revision !== -1))
|
|
587
|
-
|
|
617
|
+
if (!gate.allowed && (active.goalId || outcome.recipient.goalId || gate.revision !== -1)) {
|
|
618
|
+
deferOutcome(meta, gate.reason ?? "Parent admission refused; automatic reconciliation will retry.");
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
// Admission may yield across a session switch or Goal/workflow change.
|
|
622
|
+
if (sessionTornDown || outcomeHost !== deliveryHost || !uiCtx || callbackSuppressionReason(meta)
|
|
623
|
+
|| !outcomeAdmission.get(outcome.eventId)?.()) {
|
|
624
|
+
deferOutcome(meta, "Parent delivery authority changed; automatic reconciliation will retry.");
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
if (!claimOutcome(meta, outcomeHost)) {
|
|
628
|
+
deferOutcome(meta, "Outcome dispatch is owned by another host; automatic reconciliation will retry.");
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
deferOutcome(meta);
|
|
588
632
|
getCallbackBatcher(pi).enqueue({
|
|
589
633
|
source: "subagent", id: outcome.eventId, inspectId: meta.id, receiptId: outcome.eventId,
|
|
590
634
|
label: meta.name ?? meta.id,
|
|
591
635
|
status: outcome.outcome, outcome: outcome.reason, detailTool: "subagent_result", callback: true,
|
|
592
636
|
isDelivered: () => Boolean(readOutcome(meta)?.deliveryReceipt),
|
|
593
637
|
getSuppressionReason: () => {
|
|
594
|
-
if (!uiCtx || callbackSuppressionReason(meta)) throw new Error("Recorded parent is inactive; retain outcome.");
|
|
638
|
+
if (outcomeHost !== deliveryHost || !uiCtx || callbackSuppressionReason(meta)) throw new Error("Recorded parent is inactive; retain outcome.");
|
|
595
639
|
if ((outcome.recipient.branchId && !uiCtx.sessionManager.getBranch().some((entry) => entry.id === outcome.recipient.branchId)) || !outcomeAdmission.get(outcome.eventId)?.()) throw new Error("Parent delivery authority changed; retain outcome.");
|
|
596
640
|
return undefined;
|
|
597
641
|
},
|
|
598
642
|
onDelivered: (at) => {
|
|
599
|
-
const entry = outcomeTranscriptReceipt(
|
|
643
|
+
const entry = uiCtx && outcomeTranscriptReceipt(uiCtx.sessionManager.getBranch(), outcome.eventId);
|
|
600
644
|
if (!entry) throw new Error("Awaiting durable recipient transcript receipt.");
|
|
601
645
|
receiptOutcome(meta, entry);
|
|
602
646
|
markCompletionCallbackSent(meta.id, at);
|
|
@@ -1201,7 +1245,7 @@ function reconcileHealth(): void {
|
|
|
1201
1245
|
// is the human's own interrupted work, not another session's live run, and
|
|
1202
1246
|
// `finalizeInterruptedRunFromLog` still requires all process evidence to be
|
|
1203
1247
|
// absent, so a live writer is never touched.
|
|
1204
|
-
for (const summary of listMetas()) {
|
|
1248
|
+
for (const summary of listMetas({ includeArchived: false })) {
|
|
1205
1249
|
if (summary.status !== "running" && summary.status !== "orphaned") continue;
|
|
1206
1250
|
if (ownedByThisParent(summary) || !ownsInterruptedSupervision(summary)) continue;
|
|
1207
1251
|
const meta = readMeta(summary.id);
|
|
@@ -1353,7 +1397,6 @@ let unregisterSubagentProvider: (() => void) | undefined;
|
|
|
1353
1397
|
let acceptanceProviderRef: BackgroundWorkProvider | undefined;
|
|
1354
1398
|
let acceptanceSpawnToolRef: Parameters<ExtensionAPI["registerTool"]>[0] | undefined;
|
|
1355
1399
|
let acceptanceStopToolRef: Parameters<ExtensionAPI["registerTool"]>[0] | undefined;
|
|
1356
|
-
const TERMINAL_NAVIGATOR_RETENTION_MS = 30_000;
|
|
1357
1400
|
let mainAgentStartedAt: number | undefined;
|
|
1358
1401
|
const mainAgentTools = new Map<string, string>();
|
|
1359
1402
|
|
|
@@ -1368,25 +1411,14 @@ function observeNavigatorHealth(meta: RunMeta, now: number = Date.now()): Health
|
|
|
1368
1411
|
return observeWidgetHealth(meta, now, effectiveStatus(meta));
|
|
1369
1412
|
}
|
|
1370
1413
|
|
|
1371
|
-
/**
|
|
1372
|
-
function
|
|
1373
|
-
const
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
spendFor: (m: RunMeta) => {
|
|
1380
|
-
const snap = spendFor(m.id, now);
|
|
1381
|
-
return fmtSpend(snap.usage);
|
|
1382
|
-
},
|
|
1383
|
-
toolFor: (m: RunMeta) => {
|
|
1384
|
-
const snap = spendFor(m.id, now);
|
|
1385
|
-
return snap.tool ?? "";
|
|
1386
|
-
},
|
|
1387
|
-
effortFor: (m: RunMeta) => m.effort,
|
|
1388
|
-
healthFor: (m: RunMeta) => observeNavigatorHealth(m, now),
|
|
1389
|
-
});
|
|
1414
|
+
/** Keep expiry and formatting on one observation, only for this refresh. */
|
|
1415
|
+
function createNavigatorProjector() {
|
|
1416
|
+
const project = createAssignmentProjector();
|
|
1417
|
+
const results = new Map<string, ReturnType<typeof project>>();
|
|
1418
|
+
return (meta: RunMeta, status: string = meta.status) => {
|
|
1419
|
+
if (!results.has(meta.id)) results.set(meta.id, project(meta, status));
|
|
1420
|
+
return results.get(meta.id)!;
|
|
1421
|
+
};
|
|
1390
1422
|
}
|
|
1391
1423
|
|
|
1392
1424
|
/** Runs that should advertise/open the left-arrow navigator affordance. */
|
|
@@ -1395,8 +1427,12 @@ function navigatorRunningRuns(): RunMeta[] {
|
|
|
1395
1427
|
return sessionVisibleNavigatorRuns(Date.now(), project).filter((m) => ["running", "waiting"].includes(project(m, effectiveStatus(m)).state));
|
|
1396
1428
|
}
|
|
1397
1429
|
|
|
1430
|
+
const pendingNavigatorDismissals = new Set<string>();
|
|
1431
|
+
|
|
1398
1432
|
function navigatorRunningCount(): number {
|
|
1399
|
-
|
|
1433
|
+
const snapshot = workObservation();
|
|
1434
|
+
return (snapshot?.rows.filter((row: any) => !pendingNavigatorDismissals.has(row.meta.id) && !row.meta.dismissedAt && ["running", "waiting"].includes(row.assignment.state)).length ?? 0) +
|
|
1435
|
+
(!snapshot || snapshot.status !== "ready" ? 1 : 0);
|
|
1400
1436
|
}
|
|
1401
1437
|
|
|
1402
1438
|
/**
|
|
@@ -1453,6 +1489,8 @@ function navigatorCloseRun(id: string) {
|
|
|
1453
1489
|
.then((cancelled) => {
|
|
1454
1490
|
if (!cancelled) throw new Error("The pending wait changed; inspect it again.");
|
|
1455
1491
|
dismissRun(id);
|
|
1492
|
+
pendingNavigatorDismissals.add(id);
|
|
1493
|
+
refreshBackgroundWorkNavigator(uiCtx);
|
|
1456
1494
|
uiCtx?.ui.notify(`Cancelled the pending wait of ${id}. Writer termination may remain unproven.`, "info");
|
|
1457
1495
|
})
|
|
1458
1496
|
.catch((error) => uiCtx?.ui.notify(`Cancellation failed for ${id}: ${String(error)}. The wait remains available for inspection and retry.`, "warning"));
|
|
@@ -1465,6 +1503,7 @@ function navigatorCloseRun(id: string) {
|
|
|
1465
1503
|
stopRun,
|
|
1466
1504
|
dismissRun,
|
|
1467
1505
|
});
|
|
1506
|
+
if (outcome.action === "dismissed" || outcome.action === "stopped-and-dismissed") pendingNavigatorDismissals.add(id);
|
|
1468
1507
|
// A closed row is off the hot path: release its caches and retained events.
|
|
1469
1508
|
spendCache.delete(id);
|
|
1470
1509
|
healthLogCache.delete(id);
|
|
@@ -1494,39 +1533,29 @@ function statusTone(status: string): BackgroundWorkRow["statusTone"] {
|
|
|
1494
1533
|
}
|
|
1495
1534
|
|
|
1496
1535
|
function subagentWorkRows(now: number): BackgroundWorkRow[] {
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
const
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
effort:
|
|
1512
|
-
tool: row.tool,
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
kind: "subagent",
|
|
1517
|
-
elapsed: row.elapsed,
|
|
1518
|
-
primary: bits.join(" · ") || "subagent run",
|
|
1519
|
-
facts: row.healthFacts,
|
|
1520
|
-
sortStartedAt: metaById.get(row.id)?.startedAt ?? now,
|
|
1521
|
-
expiresAt: (() => {
|
|
1522
|
-
const meta = metaById.get(row.id);
|
|
1523
|
-
const endedAt = meta?.endedAt ?? meta?.lostAt;
|
|
1524
|
-
return meta && isTerminalNavigatorStatus(row.status) && typeof endedAt === "number"
|
|
1525
|
-
? endedAt + TERMINAL_NAVIGATOR_RETENTION_MS
|
|
1526
|
-
: undefined;
|
|
1527
|
-
})(),
|
|
1528
|
-
};
|
|
1536
|
+
const snapshot = workObservation();
|
|
1537
|
+
const sourceRows = snapshot?.rows ?? [];
|
|
1538
|
+
if (snapshot?.status === "ready" && pendingNavigatorDismissals.size) {
|
|
1539
|
+
// A successful local dismissal is already durable; hide its old observation until acknowledged.
|
|
1540
|
+
const undismissed = new Set(sourceRows.filter((row: any) => !row.meta.dismissedAt).map((row: any) => row.meta.id));
|
|
1541
|
+
for (const id of pendingNavigatorDismissals) if (!undismissed.has(id)) pendingNavigatorDismissals.delete(id);
|
|
1542
|
+
}
|
|
1543
|
+
const rows: BackgroundWorkRow[] = sourceRows.filter((row: any) => !pendingNavigatorDismissals.has(row.meta.id) && !row.meta.dismissedAt &&
|
|
1544
|
+
(["running", "waiting"].includes(row.assignment.state) || typeof (row.meta.endedAt ?? row.meta.lostAt) !== "number" ||
|
|
1545
|
+
now - (row.meta.endedAt ?? row.meta.lostAt) < TERMINAL_NAVIGATOR_RETENTION_MS)).map((row: any) => {
|
|
1546
|
+
const meta = row.meta;
|
|
1547
|
+
const health = row.health ? observeRunHealth({ ...row.health, status: row.assignment.processStatus === "exited" ? meta.status : row.assignment.processStatus, now, startedAt: meta.startedAt }) : undefined;
|
|
1548
|
+
const terminal = !["running", "waiting"].includes(row.assignment.state);
|
|
1549
|
+
return { providerId: "subagents", id: meta.id, name: meta.name || meta.id,
|
|
1550
|
+
model: shortModel(meta.model), effort: meta.effort, status: row.assignment.state,
|
|
1551
|
+
tool: row.display?.tool, tokens: row.display?.spend,
|
|
1552
|
+
statusTone: statusTone(row.assignment.state), kind: "subagent", elapsed: fmtElapsed((meta.endedAt ?? now) - meta.startedAt),
|
|
1553
|
+
primary: [shortModel(meta.model), meta.effort, row.display?.tool, row.display?.spend].filter(Boolean).join(" ") || "subagent run", facts: formatNavigatorHealthFacts(health), sortStartedAt: meta.startedAt,
|
|
1554
|
+
expiresAt: terminal && typeof meta.endedAt === "number" ? meta.endedAt + TERMINAL_NAVIGATOR_RETENTION_MS : undefined };
|
|
1529
1555
|
});
|
|
1556
|
+
if (!snapshot || snapshot.status !== "ready") rows.unshift({ providerId: "subagents", id: "runtime-observation", name: "Subagents",
|
|
1557
|
+
status: snapshot?.status ?? "degraded", statusTone: "warning", kind: "observation", elapsed: "", primary: workObservationFailure(), sortStartedAt: now });
|
|
1558
|
+
return rows;
|
|
1530
1559
|
}
|
|
1531
1560
|
|
|
1532
1561
|
const DELEGATION_BLURB: Record<DelegationMode, string> = {
|
|
@@ -1603,12 +1632,19 @@ function mainAgentWorkDetail(now: number): BackgroundWorkDetail {
|
|
|
1603
1632
|
|
|
1604
1633
|
function subagentWorkDetail(id: string, now: number, options?: { logTailLines?: number }): BackgroundWorkDetail | null {
|
|
1605
1634
|
if (id === "main") return mainAgentWorkDetail(now);
|
|
1606
|
-
const
|
|
1635
|
+
const row = requestWorkDetail(id);
|
|
1636
|
+
if (!row?.detail) return { providerId: "subagents", id, title: id, status: row?.observationError ? "degraded" : "rebuilding", statusTone: "warning", metadata: [], evidence: { label: "observation", text: row?.observationError ?? workObservationFailure() } };
|
|
1637
|
+
const health = row.health ? observeRunHealth({ ...row.health, status: row.assignment.processStatus === "exited" ? row.meta.status : row.assignment.processStatus, now, startedAt: row.meta.startedAt }) : undefined;
|
|
1638
|
+
const detail = withAssignmentObservations([row], () => buildNavigatorDetail(id, {
|
|
1639
|
+
readMeta: () => row.meta, effectiveStatus: () => row.assignment.processStatus, parseRun: () => row.detail.parsed,
|
|
1640
|
+
shortModel, fmtElapsed, fmtSpend, now, effortFor: (meta: RunMeta) => meta.effort, healthFor: () => health,
|
|
1641
|
+
}));
|
|
1607
1642
|
if (!detail) return null;
|
|
1608
1643
|
void options;
|
|
1609
|
-
const transcript =
|
|
1644
|
+
const transcript = row.detail.transcript;
|
|
1610
1645
|
const metadata = [
|
|
1611
1646
|
{ label: "provider", value: "Subagents" },
|
|
1647
|
+
...(row.observationError ? [{ label: "observation", value: row.observationError }] : []),
|
|
1612
1648
|
{ label: "id", value: detail.id },
|
|
1613
1649
|
...(detail.role ? [{ label: "role", value: String(detail.role) }] : []),
|
|
1614
1650
|
{ label: "model", value: detail.effort ? `${detail.model} · effort ${detail.effort}` : detail.model },
|
|
@@ -1701,7 +1737,7 @@ function ensureSubagentProvider(): void {
|
|
|
1701
1737
|
label: "Subagents",
|
|
1702
1738
|
priority: 10,
|
|
1703
1739
|
visibleCount: () => navigatorRunningCount(),
|
|
1704
|
-
showSection: (rows) => rows.some((row) => row.status === "running" || ["parking", "waiting", "ready", "resuming", "held"].includes(row.status)),
|
|
1740
|
+
showSection: (rows) => rows.some((row) => row.status === "running" || ["parking", "waiting", "ready", "resuming", "held", "degraded", "rebuilding"].includes(row.status)),
|
|
1705
1741
|
parentRow: (now) => mainAgentWorkRow(now),
|
|
1706
1742
|
listRows: (now) => subagentWorkRows(now),
|
|
1707
1743
|
detail: (id, now, options) => subagentWorkDetail(id, now, options),
|
|
@@ -1890,7 +1926,7 @@ function ownsInterruptedSupervision(summary: Pick<RunMeta, "spawnPid" | "spawnPi
|
|
|
1890
1926
|
/** True while an interrupted record still needs this process's supervision loop. */
|
|
1891
1927
|
function needsInterruptedSupervision(): boolean {
|
|
1892
1928
|
try {
|
|
1893
|
-
for (const summary of listMetas()) {
|
|
1929
|
+
for (const summary of listMetas({ includeArchived: false })) {
|
|
1894
1930
|
if (summary.status !== "running" && summary.status !== "orphaned") continue;
|
|
1895
1931
|
if (ownsInterruptedSupervision(summary)) return true;
|
|
1896
1932
|
}
|
|
@@ -1977,8 +2013,14 @@ function sameLaunchPath(left: unknown, right: string | undefined): boolean {
|
|
|
1977
2013
|
try { return canonicalizePath(left) === canonicalizePath(right); } catch { return false; }
|
|
1978
2014
|
}
|
|
1979
2015
|
|
|
2016
|
+
/** Reporting is injected by the supervisor, not part of the caller's tool intent.
|
|
2017
|
+
* Older recipes included it; remove only this internal name when reading them. */
|
|
2018
|
+
function callerLaunchTools(tools: string): string {
|
|
2019
|
+
return normalizeTools(tools).split(",").filter((name) => name !== "report_assignment_result").join(",");
|
|
2020
|
+
}
|
|
2021
|
+
|
|
1980
2022
|
function sameLaunchTools(left: unknown, right: string): boolean {
|
|
1981
|
-
return typeof left === "string" &&
|
|
2023
|
+
return typeof left === "string" && callerLaunchTools(left) === callerLaunchTools(right);
|
|
1982
2024
|
}
|
|
1983
2025
|
|
|
1984
2026
|
/**
|
|
@@ -2505,6 +2547,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
2505
2547
|
}
|
|
2506
2548
|
|
|
2507
2549
|
function catalogHostFrom(ctx: ExtensionContext): CatalogHost {
|
|
2550
|
+
noteCatalogHostContext(ctx, () => agentSessionSettings.snapshot());
|
|
2508
2551
|
if (typeof ctx.sessionManager?.getBranch === "function") agentSessionSettings.restore(ctx);
|
|
2509
2552
|
catalogModelRegistry = ctx.modelRegistry;
|
|
2510
2553
|
const cfg = loadConfig();
|
|
@@ -2547,7 +2590,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
2547
2590
|
if (!jobs.some((job) => hasCatalogSelector(job))) {
|
|
2548
2591
|
return { status: "ready", jobs: jobs as SpawnParams[] };
|
|
2549
2592
|
}
|
|
2550
|
-
const snapshot =
|
|
2593
|
+
const snapshot = await loadSharedLaunchSnapshot(host);
|
|
2551
2594
|
const clarified = await clarifyCatalogRequest(jobs, { hasUI: host.hasUI === true, select: host.select });
|
|
2552
2595
|
if (clarified.status === "clarification-needed") return clarified;
|
|
2553
2596
|
const prepared: SpawnParams[] = [];
|
|
@@ -2787,7 +2830,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
2787
2830
|
|
|
2788
2831
|
// A continuation keeps the recipe's launch intent; only current
|
|
2789
2832
|
// permission-driven adjustments are re-derived from it.
|
|
2790
|
-
const requestedTools = resume ? resume.recipe.tools : p.tools;
|
|
2833
|
+
const requestedTools = resume ? callerLaunchTools(resume.recipe.tools) : p.tools;
|
|
2791
2834
|
const requestedExcludeTools = resume ? resume.recipe.excludeTools ?? "" : p.exclude_tools ?? "";
|
|
2792
2835
|
const clean = resume ? resume.recipe.clean : p.clean === true;
|
|
2793
2836
|
const allowNested = resume ? resume.recipe.allowNested : p.allow_nested === true;
|
|
@@ -2829,7 +2872,22 @@ export default function (pi: ExtensionAPI) {
|
|
|
2829
2872
|
explicitTools: requestedTools !== undefined,
|
|
2830
2873
|
productionSchemas: new Set(productionBridgeSchemas.schemas.keys()),
|
|
2831
2874
|
});
|
|
2832
|
-
const
|
|
2875
|
+
const parent = ownerBindingFromContext(ctx);
|
|
2876
|
+
const assignment: AssignmentBinding | undefined = internal?.resumeWait && resume?.prior.assignment
|
|
2877
|
+
? resume.prior.assignment
|
|
2878
|
+
: parent.sessionId && typeof ctx.sessionManager?.getBranch === "function" ? { version: 1, assignmentId: id,
|
|
2879
|
+
owner: { kind: "worker-conversation", sessionId, workspace: cwd, branchId: parent.branchId, goalId: parent.goalId },
|
|
2880
|
+
recipient: { kind: "parent-session", ...parent } } : undefined;
|
|
2881
|
+
if (!workerOperations.available) {
|
|
2882
|
+
bridgePlan.tools = [];
|
|
2883
|
+
bridgePlan.capabilities = { background: { spawn: false, watch: false, status: false, log: false }, wait: false, acknowledge: false, parking: false };
|
|
2884
|
+
}
|
|
2885
|
+
if (assignment && !requestedExcludes.has("report_assignment_result")) {
|
|
2886
|
+
bridgePlan.tools = [...bridgePlan.tools, "report_assignment_result"];
|
|
2887
|
+
bridgePlan.capabilities = { ...bridgePlan.capabilities, reportAssignment: true };
|
|
2888
|
+
productionBridgeSchemas.schemas.set("report_assignment_result", createToolDescriptor("report_assignment_result"));
|
|
2889
|
+
}
|
|
2890
|
+
const bridgeEnabled = bridgePlan.tools.length > 0;
|
|
2833
2891
|
if (bridgeEnabled) {
|
|
2834
2892
|
allow = [...new Set([...allow.split(",").filter(Boolean), ...bridgePlan.tools])].join(",");
|
|
2835
2893
|
}
|
|
@@ -3057,6 +3115,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
3057
3115
|
// already captured. A resume requires the bridge: without it the
|
|
3058
3116
|
// attempt could not read evidence or acknowledge its wait.
|
|
3059
3117
|
let workerBridge: { env: Record<string, string>; policy: ReturnType<typeof captureWorkerPolicy>; authorityReference: string } | undefined;
|
|
3118
|
+
if (assignment) registerAssignmentAttempt(assignment, id);
|
|
3060
3119
|
if (bridgeEnabled) {
|
|
3061
3120
|
const workerPolicy = captureWorkerPolicy({
|
|
3062
3121
|
sandbox: sandboxEnabled,
|
|
@@ -3079,6 +3138,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
3079
3138
|
const owner = internal?.parkOwner ?? ownerBindingFromContext(ctx);
|
|
3080
3139
|
try {
|
|
3081
3140
|
const handle = await workerOperations.register({
|
|
3141
|
+
assignment,
|
|
3082
3142
|
runId: id,
|
|
3083
3143
|
conversationId: sessionId,
|
|
3084
3144
|
workspace: cwd,
|
|
@@ -3116,14 +3176,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
3116
3176
|
// await between it and the spawn, so a cancellation or parent change
|
|
3117
3177
|
// cannot hide inside a final asynchronous window.
|
|
3118
3178
|
if (internal?.resumeWait && !resume?.prior.assignment) throw new PreSpawnResumeError("This legacy park has no verified assignment outcome recipient; refusing continuation on an unsupported binding.");
|
|
3119
|
-
const parent = ownerBindingFromContext(ctx);
|
|
3120
|
-
const assignment: AssignmentBinding | undefined = internal?.resumeWait && resume?.prior.assignment
|
|
3121
|
-
? resume.prior.assignment
|
|
3122
|
-
: parent.sessionId && typeof ctx.sessionManager?.getBranch === "function" ? { version: 1, assignmentId: id,
|
|
3123
|
-
owner: { kind: "worker-conversation", sessionId, workspace: cwd, branchId: parent.branchId, goalId: parent.goalId },
|
|
3124
|
-
recipient: { kind: "parent-session", ...parent } } : undefined;
|
|
3125
3179
|
if (!assignment && bridgeEnabled) throw new Error("Durable assignment outcomes require a recorded parent session and transcript capability.");
|
|
3126
|
-
if (assignment) registerAssignmentAttempt(assignment, id);
|
|
3127
3180
|
if (internal?.resumeWait) {
|
|
3128
3181
|
const captured = resume?.prior.operations?.policy;
|
|
3129
3182
|
const currentSandbox = taskRuntime ? {
|
|
@@ -3158,7 +3211,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
3158
3211
|
cwd,
|
|
3159
3212
|
model,
|
|
3160
3213
|
effort: thinking,
|
|
3161
|
-
tools: allow,
|
|
3214
|
+
tools: callerLaunchTools(allow),
|
|
3162
3215
|
excludeTools: requestedExcludes.size ? [...requestedExcludes].join(",") : undefined,
|
|
3163
3216
|
skills: skills.mode === "inherit" ? undefined : [...skills.paths],
|
|
3164
3217
|
clean,
|
|
@@ -3300,9 +3353,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
3300
3353
|
// must not keep running unsupervised; its log goes with the
|
|
3301
3354
|
// attempt, because a record without metadata can never be read.
|
|
3302
3355
|
if (!committed) {
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3356
|
+
await abortUncommittedLaunch(id, {
|
|
3357
|
+
child: spawned, lease,
|
|
3358
|
+
artifacts: { sessionDir: childSessionDir, workspaceDir: ownedCloneWorkspace, scratch: launchScratch },
|
|
3359
|
+
});
|
|
3306
3360
|
}
|
|
3307
3361
|
throw error;
|
|
3308
3362
|
}
|
|
@@ -3820,7 +3874,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
3820
3874
|
if (needsCatalog) {
|
|
3821
3875
|
catalogHost = catalogHostFrom(ctx);
|
|
3822
3876
|
noteCatalogHost(catalogHost);
|
|
3823
|
-
catalogSnapshot =
|
|
3877
|
+
catalogSnapshot = await loadSharedLaunchSnapshot(catalogHost);
|
|
3824
3878
|
const clarified = await clarifyCatalogRequest(
|
|
3825
3879
|
p.jobs.map((job) => mergeJobOptions(p.shared, job) as CatalogJobFields),
|
|
3826
3880
|
{ hasUI: catalogHost.hasUI === true, select: catalogHost.select },
|
|
@@ -3974,6 +4028,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
3974
4028
|
// The foreground origin from session_start; otherwise the calling context's
|
|
3975
4029
|
// own session. An unreadable session id stays unavailable (never cwd-wide).
|
|
3976
4030
|
const toolSession = {
|
|
4031
|
+
observeAssignment: observedAssignment,
|
|
4032
|
+
observeList: observedList,
|
|
3977
4033
|
inspectOutcome: (meta: RunMeta, params: Record<string, unknown>, callCtx?: unknown) => {
|
|
3978
4034
|
if (params.disposition !== undefined && params.disposition !== "consumed" && params.disposition !== "dismissed") throw new Error("Outcome disposition must be consumed or dismissed.");
|
|
3979
4035
|
if (!readOutcome(meta)) {
|
|
@@ -4273,6 +4329,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
4273
4329
|
// switch), so the previous session's teardown no longer applies: the
|
|
4274
4330
|
// replacing session owns this instance's supervision loops (#625).
|
|
4275
4331
|
sessionTornDown = false;
|
|
4332
|
+
pendingNavigatorDismissals.clear();
|
|
4276
4333
|
outcomeHost = createOutcomeHost();
|
|
4277
4334
|
setCallbackBatchContext(pi, ctx);
|
|
4278
4335
|
agentSessionSettings.restore(ctx);
|
|
@@ -4283,7 +4340,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
4283
4340
|
catch { mainAgentStartedAt = undefined; }
|
|
4284
4341
|
mainAgentTools.clear();
|
|
4285
4342
|
activeCallbackOrigin = callbackOriginFromContext(ctx);
|
|
4343
|
+
if (activeCallbackOrigin) await startWorkObservation(PiCodingAgent.getAgentDir(), activeCallbackOrigin, () => refreshBackgroundWorkNavigator(ctx));
|
|
4286
4344
|
recoverCompletionCallbacks(pi);
|
|
4345
|
+
// Admission can defer before batcher enqueue, even after the last child
|
|
4346
|
+
// exits. Keep reconciliation independent of the live-run health ticker.
|
|
4347
|
+
if (outcomeTicker) clearInterval(outcomeTicker);
|
|
4348
|
+
outcomeTicker = setInterval(() => recoverAssignmentOutcomes(pi), 1000);
|
|
4349
|
+
outcomeTicker.unref?.();
|
|
4287
4350
|
// Reload / session switch hardening (#48):
|
|
4288
4351
|
// - Drop any leftover overlay timers/confirm state from a prior session
|
|
4289
4352
|
// (defensive if the host skipped session_shutdown before re-start).
|
|
@@ -4319,6 +4382,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
4319
4382
|
});
|
|
4320
4383
|
|
|
4321
4384
|
pi.on("session_before_switch", () => {
|
|
4385
|
+
closeCatalogHost();
|
|
4322
4386
|
agentSessionSettings.clear();
|
|
4323
4387
|
catalogModelRegistry = undefined;
|
|
4324
4388
|
activeCallbackOrigin = undefined;
|
|
@@ -4332,6 +4396,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
4332
4396
|
|
|
4333
4397
|
// Tear down the timer and clear the widget when the session ends.
|
|
4334
4398
|
pi.on("session_shutdown", async (event, ctx) => {
|
|
4399
|
+
closeCatalogHost();
|
|
4400
|
+
stopWorkObservation();
|
|
4401
|
+
pendingNavigatorDismissals.clear();
|
|
4402
|
+
if (outcomeTicker) clearInterval(outcomeTicker);
|
|
4403
|
+
outcomeTicker = undefined;
|
|
4404
|
+
outcomeAdmission.clear();
|
|
4335
4405
|
closeOutcomeHost(outcomeHost);
|
|
4336
4406
|
if (typeof unsubscribeOutcomeWorkflow === "function") unsubscribeOutcomeWorkflow();
|
|
4337
4407
|
if (typeof unsubscribeSettingsRequest === "function") unsubscribeSettingsRequest();
|
package/launch-abort.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ConversationLease } from "./continuation.ts";
|
|
2
|
+
import { discardFailedLaunch } from "./registry.ts";
|
|
3
|
+
import { killProcessTree, type SpawnResult } from "./spawn.ts";
|
|
4
|
+
|
|
5
|
+
/** A signal request is not writer-exit proof. Retain ownership until close. */
|
|
6
|
+
export async function abortUncommittedLaunch(
|
|
7
|
+
id: string,
|
|
8
|
+
options: {
|
|
9
|
+
child?: SpawnResult;
|
|
10
|
+
lease?: ConversationLease;
|
|
11
|
+
artifacts: Parameters<typeof discardFailedLaunch>[1];
|
|
12
|
+
},
|
|
13
|
+
): Promise<void> {
|
|
14
|
+
if (options.child) {
|
|
15
|
+
killProcessTree(options.child.pid, "SIGKILL");
|
|
16
|
+
// If exit cannot be established, neither the lease nor its evidence is removed.
|
|
17
|
+
await options.child.exit;
|
|
18
|
+
}
|
|
19
|
+
options.lease?.release();
|
|
20
|
+
discardFailedLaunch(id, options.artifacts);
|
|
21
|
+
}
|
package/list.mjs
CHANGED
|
@@ -106,7 +106,7 @@ export function formatSubagentListRow(meta, p) {
|
|
|
106
106
|
: "";
|
|
107
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
|
-
? `\n ${assignmentDiagnostic(assignment)}` : "";
|
|
109
|
+
? `\n ${assignmentDiagnostic(assignment, { includeEvidence: !p.compact })}` : "";
|
|
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}`;
|
|
111
111
|
}
|
|
112
112
|
|
package/navigator.mjs
CHANGED
|
@@ -181,6 +181,7 @@ export function isNavigatorUiAvailable(ctx) {
|
|
|
181
181
|
* @param {(m: object) => string} [deps.toolFor] - current/used tool label or ""
|
|
182
182
|
* @param {(m: object) => string|undefined} [deps.effortFor] - model effort when available
|
|
183
183
|
* @param {(m: object) => object|undefined} [deps.healthFor] - #66 HealthObservation
|
|
184
|
+
* @param {(m: object, status: string) => object} [deps.project] - refresh-local assignment results shared with expiry filtering
|
|
184
185
|
* @param {number} [deps.now]
|
|
185
186
|
*/
|
|
186
187
|
export function pendingNavigatorPark(meta) {
|
|
@@ -190,7 +191,7 @@ export function pendingNavigatorPark(meta) {
|
|
|
190
191
|
|
|
191
192
|
export function buildNavigatorRows(metas, deps) {
|
|
192
193
|
const now = deps.now ?? Date.now();
|
|
193
|
-
const project = createAssignmentProjector();
|
|
194
|
+
const project = deps.project ?? createAssignmentProjector();
|
|
194
195
|
return metas.map((m) => {
|
|
195
196
|
const assignment = project(m, deps.effectiveStatus(m));
|
|
196
197
|
const status = assignment.state;
|
|
@@ -72,6 +72,7 @@ export const OPERATION_BRIDGE_TOOL_NAMES = [
|
|
|
72
72
|
"bg_task_log",
|
|
73
73
|
"wait_for_operations",
|
|
74
74
|
"acknowledge_operation_result",
|
|
75
|
+
"report_assignment_result",
|
|
75
76
|
] as const;
|
|
76
77
|
|
|
77
78
|
export type OperationBridgeToolName = (typeof OPERATION_BRIDGE_TOOL_NAMES)[number];
|
|
@@ -102,6 +103,7 @@ export const OPERATION_BRIDGE_METHODS: readonly OperationBridgeMethod[] = [
|
|
|
102
103
|
export type JsonRecord = Record<string, unknown>;
|
|
103
104
|
|
|
104
105
|
export interface OperationBridgeCapabilities {
|
|
106
|
+
reportAssignment?: boolean;
|
|
105
107
|
background: {
|
|
106
108
|
spawn: boolean;
|
|
107
109
|
watch: boolean;
|
|
@@ -628,6 +630,17 @@ const HANDSHAKE_SCHEMA: JsonRecord = object({
|
|
|
628
630
|
|
|
629
631
|
export function canonicalToolSchema(name: OperationBridgeToolName): JsonRecord {
|
|
630
632
|
switch (name) {
|
|
633
|
+
case "report_assignment_result": return {
|
|
634
|
+
type: "object", additionalProperties: false, required: ["status", "reason", "evidence"],
|
|
635
|
+
properties: {
|
|
636
|
+
status: { type: "string", enum: ["complete", "incomplete"] },
|
|
637
|
+
reason: { type: "string", minLength: 1, maxLength: 2048 },
|
|
638
|
+
evidence: { type: "array", minItems: 1, maxItems: 4, items: {
|
|
639
|
+
type: "object", additionalProperties: false, required: ["path", "explanation"],
|
|
640
|
+
properties: { path: { type: "string", minLength: 1, maxLength: 1024 }, explanation: { type: "string", minLength: 1, maxLength: 1024 } },
|
|
641
|
+
} },
|
|
642
|
+
},
|
|
643
|
+
};
|
|
631
644
|
case "wait_for_operations": return WAIT_FOR_OPERATIONS_SCHEMA;
|
|
632
645
|
case "acknowledge_operation_result": return ACKNOWLEDGE_OPERATION_RESULT_SCHEMA;
|
|
633
646
|
default: return LOOSE_BACKGROUND_SCHEMA;
|
|
@@ -635,6 +648,7 @@ export function canonicalToolSchema(name: OperationBridgeToolName): JsonRecord {
|
|
|
635
648
|
}
|
|
636
649
|
|
|
637
650
|
const TOOL_LABELS: Record<OperationBridgeToolName, string> = {
|
|
651
|
+
report_assignment_result: "Report Assignment Result",
|
|
638
652
|
bg_task_spawn: "BG Spawn",
|
|
639
653
|
bg_task_watch: "BG Watch",
|
|
640
654
|
bg_task_status: "BG Status",
|
|
@@ -644,6 +658,7 @@ const TOOL_LABELS: Record<OperationBridgeToolName, string> = {
|
|
|
644
658
|
};
|
|
645
659
|
|
|
646
660
|
const TOOL_DESCRIPTIONS: Record<OperationBridgeToolName, string> = {
|
|
661
|
+
report_assignment_result: "Record your complete or incomplete assignment judgment with retained workspace artifact evidence before your final answer. Does not terminalize the assignment, interpret waits or record parent acceptance. Report once; identical retries are allowed, conflicting reports are refused.",
|
|
647
662
|
bg_task_spawn: "Start one long-running background operation through the trusted parent supervisor. Returns immediately. The operation is owned by the parent, not by this worker process.",
|
|
648
663
|
bg_task_watch: "Start one background command watch through the trusted parent supervisor. Returns immediately. The operation is owned by the parent, not by this worker process.",
|
|
649
664
|
bg_task_status: "Inspect one operation owned by this worker conversation. Only task ids accepted by the parent ownership check are readable.",
|
|
@@ -664,7 +679,7 @@ export function createToolDescriptor(
|
|
|
664
679
|
): OperationToolDescriptor {
|
|
665
680
|
// The wait/acknowledge schemas are fixed here; a parent descriptor may not
|
|
666
681
|
// loosen the contract that decides when a worker parks or consumes evidence.
|
|
667
|
-
const parameters = name === WAIT_OPERATIONS_TOOL || name === ACKNOWLEDGE_OPERATION_TOOL
|
|
682
|
+
const parameters = name === WAIT_OPERATIONS_TOOL || name === ACKNOWLEDGE_OPERATION_TOOL || name === "report_assignment_result"
|
|
668
683
|
? canonicalToolSchema(name)
|
|
669
684
|
: (overrides.parameters ?? canonicalToolSchema(name));
|
|
670
685
|
return deepFreeze({
|
|
@@ -679,6 +694,7 @@ export function createToolDescriptor(
|
|
|
679
694
|
|
|
680
695
|
export function descriptorsForCapabilities(capabilities: OperationBridgeCapabilities): OperationToolDescriptor[] {
|
|
681
696
|
return deepFreeze([
|
|
697
|
+
...(capabilities.reportAssignment === true ? [createToolDescriptor("report_assignment_result")] : []),
|
|
682
698
|
...(capabilities.background.spawn ? [createToolDescriptor("bg_task_spawn")] : []),
|
|
683
699
|
...(capabilities.background.watch ? [createToolDescriptor("bg_task_watch")] : []),
|
|
684
700
|
...(capabilities.background.status ? [createToolDescriptor("bg_task_status")] : []),
|
|
@@ -720,6 +736,7 @@ export function normalizeToolDescriptors(
|
|
|
720
736
|
|
|
721
737
|
export function capabilityForTool(name: OperationBridgeToolName, capabilities: OperationBridgeCapabilities): boolean {
|
|
722
738
|
switch (name) {
|
|
739
|
+
case "report_assignment_result": return capabilities.reportAssignment === true;
|
|
723
740
|
case "bg_task_spawn": return capabilities.background.spawn;
|
|
724
741
|
case "bg_task_watch": return capabilities.background.watch;
|
|
725
742
|
case "bg_task_status": return capabilities.background.status;
|
package/output-payload.ts
CHANGED
|
@@ -98,6 +98,8 @@ export type LoadedRun =
|
|
|
98
98
|
| { kind: "unreadable"; detail: string };
|
|
99
99
|
|
|
100
100
|
export type SubagentToolSession = {
|
|
101
|
+
observeAssignment?: (id: string) => Promise<{ assignment: ReturnType<typeof assignmentFor>; snapshot: unknown }>;
|
|
102
|
+
observeList?: (scope: object) => Promise<any>;
|
|
101
103
|
inspectOutcome?: (meta: RunMeta, params: Record<string, unknown>, ctx?: unknown) => unknown;
|
|
102
104
|
/** Current session origin; `ctx` is the tool call's host context when available. */
|
|
103
105
|
getActiveOrigin?: (ctx?: unknown) => RunCallbackOrigin | undefined;
|