@caupulican/pi-adaptative 0.81.41 → 0.81.42
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 +16 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +5 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +3 -3
- package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +8 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +26 -3
- package/dist/bundled-resources/runtimes/pi-shell-engine/expand.py +3 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +4 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +2 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +2 -0
- package/dist/core/agent-paths.d.ts +32 -0
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +65 -0
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-contracts.d.ts +19 -1
- package/dist/core/agent-session-contracts.d.ts.map +1 -1
- package/dist/core/agent-session-contracts.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +4 -9
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +2 -0
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.js +4 -9
- package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts +3 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +17 -4
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/path-scope.d.ts +14 -0
- package/dist/core/autonomy/path-scope.d.ts.map +1 -1
- package/dist/core/autonomy/path-scope.js +37 -6
- package/dist/core/autonomy/path-scope.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +27 -1
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +32 -1
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.d.ts +11 -1
- package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
- package/dist/core/delegation/managed-lane-controller.js +84 -41
- package/dist/core/delegation/managed-lane-controller.js.map +1 -1
- package/dist/core/delegation/session-worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/session-worker-claim.js +4 -3
- package/dist/core/delegation/session-worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-action-journal.d.ts +73 -0
- package/dist/core/delegation/worker-action-journal.d.ts.map +1 -0
- package/dist/core/delegation/worker-action-journal.js +297 -0
- package/dist/core/delegation/worker-action-journal.js.map +1 -0
- package/dist/core/delegation/worker-actions.d.ts +36 -1
- package/dist/core/delegation/worker-actions.d.ts.map +1 -1
- package/dist/core/delegation/worker-actions.js +171 -46
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +75 -0
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-agent-control-coordinator.js +218 -0
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-agent-control.d.ts +66 -0
- package/dist/core/delegation/worker-agent-control.d.ts.map +1 -0
- package/dist/core/delegation/worker-agent-control.js +163 -0
- package/dist/core/delegation/worker-agent-control.js.map +1 -0
- package/dist/core/delegation/worker-attempt-executor.d.ts +80 -0
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -0
- package/dist/core/delegation/worker-attempt-executor.js +343 -0
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -0
- package/dist/core/delegation/worker-claim.d.ts +30 -0
- package/dist/core/delegation/worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/worker-claim.js +205 -53
- package/dist/core/delegation/worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-conversation-store.d.ts +116 -0
- package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -0
- package/dist/core/delegation/worker-conversation-store.js +442 -0
- package/dist/core/delegation/worker-conversation-store.js.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts +21 -5
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +386 -251
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-delegation-request.d.ts +14 -0
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-request.js.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts +4 -2
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.js +16 -6
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
- package/dist/core/delegation/worker-execution-policy.d.ts +2 -1
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
- package/dist/core/delegation/worker-execution-policy.js +5 -7
- package/dist/core/delegation/worker-execution-policy.js.map +1 -1
- package/dist/core/delegation/worker-lifecycle.d.ts +44 -1
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js +120 -0
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-process-owner.d.ts +18 -0
- package/dist/core/delegation/worker-process-owner.d.ts.map +1 -0
- package/dist/core/delegation/worker-process-owner.js +54 -0
- package/dist/core/delegation/worker-process-owner.js.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts +5 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.js +8 -0
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
- package/dist/core/delegation/worker-recovery-coordinator.d.ts +54 -0
- package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-recovery-coordinator.js +181 -0
- package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-resource-catalog.d.ts +32 -0
- package/dist/core/delegation/worker-resource-catalog.d.ts.map +1 -0
- package/dist/core/delegation/worker-resource-catalog.js +116 -0
- package/dist/core/delegation/worker-resource-catalog.js.map +1 -0
- package/dist/core/delegation/worker-resource-materializer.d.ts +47 -0
- package/dist/core/delegation/worker-resource-materializer.d.ts.map +1 -0
- package/dist/core/delegation/worker-resource-materializer.js +137 -0
- package/dist/core/delegation/worker-resource-materializer.js.map +1 -0
- package/dist/core/delegation/worker-runner.d.ts +3 -1
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +189 -54
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-terminal-finalizer.d.ts +23 -0
- package/dist/core/delegation/worker-terminal-finalizer.d.ts.map +1 -0
- package/dist/core/delegation/worker-terminal-finalizer.js +12 -0
- package/dist/core/delegation/worker-terminal-finalizer.js.map +1 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +38 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.js +107 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-write-reservation.d.ts +90 -0
- package/dist/core/delegation/worker-write-reservation.d.ts.map +1 -0
- package/dist/core/delegation/worker-write-reservation.js +348 -0
- package/dist/core/delegation/worker-write-reservation.js.map +1 -0
- package/dist/core/models/model-endpoint.d.ts +3 -0
- package/dist/core/models/model-endpoint.d.ts.map +1 -0
- package/dist/core/models/model-endpoint.js +11 -0
- package/dist/core/models/model-endpoint.js.map +1 -0
- package/dist/core/orchestration/agent-resume.d.ts +2 -0
- package/dist/core/orchestration/agent-resume.d.ts.map +1 -1
- package/dist/core/orchestration/agent-resume.js +7 -0
- package/dist/core/orchestration/agent-resume.js.map +1 -1
- package/dist/core/orchestration/attempt-usage.d.ts +28 -0
- package/dist/core/orchestration/attempt-usage.d.ts.map +1 -0
- package/dist/core/orchestration/attempt-usage.js +168 -0
- package/dist/core/orchestration/attempt-usage.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +19 -1
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +128 -28
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/contracts.d.ts +35 -0
- package/dist/core/orchestration/contracts.d.ts.map +1 -1
- package/dist/core/orchestration/contracts.js +17 -0
- package/dist/core/orchestration/contracts.js.map +1 -1
- package/dist/core/orchestration/delegation-ledger.d.ts +17 -2
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
- package/dist/core/orchestration/delegation-ledger.js +78 -3
- package/dist/core/orchestration/delegation-ledger.js.map +1 -1
- package/dist/core/orchestration/event-store.d.ts +1 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -1
- package/dist/core/orchestration/event-store.js +78 -38
- package/dist/core/orchestration/event-store.js.map +1 -1
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
- package/dist/core/orchestration/profile-registry.js +81 -41
- package/dist/core/orchestration/profile-registry.js.map +1 -1
- package/dist/core/orchestration/profile-store.d.ts.map +1 -1
- package/dist/core/orchestration/profile-store.js +18 -4
- package/dist/core/orchestration/profile-store.js.map +1 -1
- package/dist/core/orchestration/risk-budget.d.ts +2 -0
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
- package/dist/core/orchestration/risk-budget.js +26 -0
- package/dist/core/orchestration/risk-budget.js.map +1 -1
- package/dist/core/orchestration/task-runtime.d.ts +13 -1
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
- package/dist/core/orchestration/task-runtime.js +127 -16
- package/dist/core/orchestration/task-runtime.js.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.d.ts +3 -1
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.js +75 -23
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
- package/dist/core/orchestration/worker-result-adapter.d.ts +9 -3
- package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
- package/dist/core/orchestration/worker-result-adapter.js +167 -14
- package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +1 -1
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +90 -54
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/research/evidence-bundle.d.ts +20 -0
- package/dist/core/research/evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/evidence-bundle.js +173 -69
- package/dist/core/research/evidence-bundle.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +7 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +15 -1
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/session-artifact-bundle.d.ts +35 -0
- package/dist/core/session-artifact-bundle.d.ts.map +1 -0
- package/dist/core/session-artifact-bundle.js +61 -0
- package/dist/core/session-artifact-bundle.js.map +1 -0
- package/dist/core/tools/delegate-status.d.ts +6 -1
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +100 -18
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +9 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +323 -61
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/run-process.d.ts +1 -1
- package/dist/core/tools/run-process.d.ts.map +1 -1
- package/dist/core/tools/run-process.js +69 -9
- package/dist/core/tools/run-process.js.map +1 -1
- package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
- package/dist/core/tools/shell-contract-router.js +12 -5
- package/dist/core/tools/shell-contract-router.js.map +1 -1
- package/dist/core/util/bounded-file.d.ts +15 -0
- package/dist/core/util/bounded-file.d.ts.map +1 -0
- package/dist/core/util/bounded-file.js +120 -0
- package/dist/core/util/bounded-file.js.map +1 -0
- package/dist/core/util/bounded-jsonl.d.ts.map +1 -1
- package/dist/core/util/bounded-jsonl.js +119 -9
- package/dist/core/util/bounded-jsonl.js.map +1 -1
- package/dist/core/util/bounded-value.d.ts +3 -0
- package/dist/core/util/bounded-value.d.ts.map +1 -0
- package/dist/core/util/bounded-value.js +12 -0
- package/dist/core/util/bounded-value.js.map +1 -0
- package/dist/core/util/value-guards.d.ts +2 -0
- package/dist/core/util/value-guards.d.ts.map +1 -1
- package/dist/core/util/value-guards.js +5 -0
- package/dist/core/util/value-guards.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +27 -44
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/docs/tool-repair.md +3 -0
- package/docs/windows.md +4 -2
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type SessionArtifactDeletionMethod = "trash" | "unlink";
|
|
2
|
+
export interface SessionArtifactPathDeletion {
|
|
3
|
+
ok: boolean;
|
|
4
|
+
method: SessionArtifactDeletionMethod;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ForegroundSessionBundleDeletion {
|
|
8
|
+
foreground: SessionArtifactPathDeletion;
|
|
9
|
+
workerArtifacts: SessionArtifactPathDeletion | {
|
|
10
|
+
ok: true;
|
|
11
|
+
method: "absent";
|
|
12
|
+
} | {
|
|
13
|
+
ok: false;
|
|
14
|
+
method: "preserved";
|
|
15
|
+
};
|
|
16
|
+
complete: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface DeleteForegroundSessionBundleOptions {
|
|
19
|
+
agentDir: string;
|
|
20
|
+
parentSessionId: string;
|
|
21
|
+
sessionPath: string;
|
|
22
|
+
removePath?: (path: string) => Promise<SessionArtifactPathDeletion>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Move a managed path to the platform trash when available. Permanent removal is a documented
|
|
26
|
+
* fallback only when trash cannot complete the individual path.
|
|
27
|
+
*/
|
|
28
|
+
export declare function removePathWithTrashFallback(path: string): Promise<SessionArtifactPathDeletion>;
|
|
29
|
+
/**
|
|
30
|
+
* Explicitly delete one foreground session together with its exact session-owned control-plane
|
|
31
|
+
* namespace. No age-based cleanup is performed. If the foreground file moves first but its worker
|
|
32
|
+
* bundle cannot, the result reports that partial state rather than claiming a full deletion.
|
|
33
|
+
*/
|
|
34
|
+
export declare function deleteForegroundSessionBundle(options: DeleteForegroundSessionBundleOptions): Promise<ForegroundSessionBundleDeletion>;
|
|
35
|
+
//# sourceMappingURL=session-artifact-bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-artifact-bundle.d.ts","sourceRoot":"","sources":["../../src/core/session-artifact-bundle.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,6BAA6B,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE/D,MAAM,WAAW,2BAA2B;IAC3C,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,6BAA6B,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,+BAA+B;IAC/C,UAAU,EAAE,2BAA2B,CAAC;IACxC,eAAe,EAAE,2BAA2B,GAAG;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,MAAM,EAAE,QAAQ,CAAA;KAAE,GAAG;QAAE,EAAE,EAAE,KAAK,CAAC;QAAC,MAAM,EAAE,WAAW,CAAA;KAAE,CAAC;IACnH,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,oCAAoC;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,2BAA2B,CAAC,CAAC;CACpE;AAUD;;;GAGG;AACH,wBAAsB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAsBpG;AAED;;;;GAIG;AACH,wBAAsB,6BAA6B,CAClD,OAAO,EAAE,oCAAoC,GAC3C,OAAO,CAAC,+BAA+B,CAAC,CAa1C","sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { lstat, rm, unlink } from \"node:fs/promises\";\nimport { orchestrationSessionDir } from \"./agent-paths.ts\";\n\nexport type SessionArtifactDeletionMethod = \"trash\" | \"unlink\";\n\nexport interface SessionArtifactPathDeletion {\n\tok: boolean;\n\tmethod: SessionArtifactDeletionMethod;\n\terror?: string;\n}\n\nexport interface ForegroundSessionBundleDeletion {\n\tforeground: SessionArtifactPathDeletion;\n\tworkerArtifacts: SessionArtifactPathDeletion | { ok: true; method: \"absent\" } | { ok: false; method: \"preserved\" };\n\tcomplete: boolean;\n}\n\nexport interface DeleteForegroundSessionBundleOptions {\n\tagentDir: string;\n\tparentSessionId: string;\n\tsessionPath: string;\n\tremovePath?: (path: string) => Promise<SessionArtifactPathDeletion>;\n}\n\nfunction describeTrashError(result: ReturnType<typeof spawnSync>): string | undefined {\n\tconst parts: string[] = [];\n\tif (result.error) parts.push(result.error.message);\n\tconst stderr = typeof result.stderr === \"string\" ? result.stderr.trim() : undefined;\n\tif (stderr) parts.push(stderr.split(\"\\n\")[0] ?? stderr);\n\treturn parts.length > 0 ? `trash: ${parts.join(\" · \").slice(0, 200)}` : undefined;\n}\n\n/**\n * Move a managed path to the platform trash when available. Permanent removal is a documented\n * fallback only when trash cannot complete the individual path.\n */\nexport async function removePathWithTrashFallback(path: string): Promise<SessionArtifactPathDeletion> {\n\tconst trashArgs = path.startsWith(\"-\") ? [\"--\", path] : [path];\n\tconst trashResult = spawnSync(\"trash\", trashArgs, { encoding: \"utf-8\", timeout: 10_000 });\n\tif (trashResult.status === 0 || !existsSync(path)) return { ok: true, method: \"trash\" };\n\n\ttry {\n\t\tconst stat = await lstat(path);\n\t\tif (stat.isDirectory()) {\n\t\t\tawait rm(path, { recursive: true, force: false });\n\t\t} else {\n\t\t\tawait unlink(path);\n\t\t}\n\t\treturn { ok: true, method: \"unlink\" };\n\t} catch (error) {\n\t\tconst fallbackError = error instanceof Error ? error.message : String(error);\n\t\tconst trashError = describeTrashError(trashResult);\n\t\treturn {\n\t\t\tok: false,\n\t\t\tmethod: \"unlink\",\n\t\t\terror: trashError ? `${fallbackError} (${trashError})` : fallbackError,\n\t\t};\n\t}\n}\n\n/**\n * Explicitly delete one foreground session together with its exact session-owned control-plane\n * namespace. No age-based cleanup is performed. If the foreground file moves first but its worker\n * bundle cannot, the result reports that partial state rather than claiming a full deletion.\n */\nexport async function deleteForegroundSessionBundle(\n\toptions: DeleteForegroundSessionBundleOptions,\n): Promise<ForegroundSessionBundleDeletion> {\n\tconst removePath = options.removePath ?? removePathWithTrashFallback;\n\tconst foreground = await removePath(options.sessionPath);\n\tif (!foreground.ok) {\n\t\treturn { foreground, workerArtifacts: { ok: false, method: \"preserved\" }, complete: false };\n\t}\n\n\tconst workerArtifactsPath = orchestrationSessionDir(options.agentDir, options.parentSessionId);\n\tif (!existsSync(workerArtifactsPath)) {\n\t\treturn { foreground, workerArtifacts: { ok: true, method: \"absent\" }, complete: true };\n\t}\n\tconst workerArtifacts = await removePath(workerArtifactsPath);\n\treturn { foreground, workerArtifacts, complete: workerArtifacts.ok };\n}\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { lstat, rm, unlink } from "node:fs/promises";
|
|
4
|
+
import { orchestrationSessionDir } from "./agent-paths.js";
|
|
5
|
+
function describeTrashError(result) {
|
|
6
|
+
const parts = [];
|
|
7
|
+
if (result.error)
|
|
8
|
+
parts.push(result.error.message);
|
|
9
|
+
const stderr = typeof result.stderr === "string" ? result.stderr.trim() : undefined;
|
|
10
|
+
if (stderr)
|
|
11
|
+
parts.push(stderr.split("\n")[0] ?? stderr);
|
|
12
|
+
return parts.length > 0 ? `trash: ${parts.join(" · ").slice(0, 200)}` : undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Move a managed path to the platform trash when available. Permanent removal is a documented
|
|
16
|
+
* fallback only when trash cannot complete the individual path.
|
|
17
|
+
*/
|
|
18
|
+
export async function removePathWithTrashFallback(path) {
|
|
19
|
+
const trashArgs = path.startsWith("-") ? ["--", path] : [path];
|
|
20
|
+
const trashResult = spawnSync("trash", trashArgs, { encoding: "utf-8", timeout: 10_000 });
|
|
21
|
+
if (trashResult.status === 0 || !existsSync(path))
|
|
22
|
+
return { ok: true, method: "trash" };
|
|
23
|
+
try {
|
|
24
|
+
const stat = await lstat(path);
|
|
25
|
+
if (stat.isDirectory()) {
|
|
26
|
+
await rm(path, { recursive: true, force: false });
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
await unlink(path);
|
|
30
|
+
}
|
|
31
|
+
return { ok: true, method: "unlink" };
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const fallbackError = error instanceof Error ? error.message : String(error);
|
|
35
|
+
const trashError = describeTrashError(trashResult);
|
|
36
|
+
return {
|
|
37
|
+
ok: false,
|
|
38
|
+
method: "unlink",
|
|
39
|
+
error: trashError ? `${fallbackError} (${trashError})` : fallbackError,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Explicitly delete one foreground session together with its exact session-owned control-plane
|
|
45
|
+
* namespace. No age-based cleanup is performed. If the foreground file moves first but its worker
|
|
46
|
+
* bundle cannot, the result reports that partial state rather than claiming a full deletion.
|
|
47
|
+
*/
|
|
48
|
+
export async function deleteForegroundSessionBundle(options) {
|
|
49
|
+
const removePath = options.removePath ?? removePathWithTrashFallback;
|
|
50
|
+
const foreground = await removePath(options.sessionPath);
|
|
51
|
+
if (!foreground.ok) {
|
|
52
|
+
return { foreground, workerArtifacts: { ok: false, method: "preserved" }, complete: false };
|
|
53
|
+
}
|
|
54
|
+
const workerArtifactsPath = orchestrationSessionDir(options.agentDir, options.parentSessionId);
|
|
55
|
+
if (!existsSync(workerArtifactsPath)) {
|
|
56
|
+
return { foreground, workerArtifacts: { ok: true, method: "absent" }, complete: true };
|
|
57
|
+
}
|
|
58
|
+
const workerArtifacts = await removePath(workerArtifactsPath);
|
|
59
|
+
return { foreground, workerArtifacts, complete: workerArtifacts.ok };
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=session-artifact-bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-artifact-bundle.js","sourceRoot":"","sources":["../../src/core/session-artifact-bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAuB3D,SAAS,kBAAkB,CAAC,MAAoC,EAAsB;IACrF,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,MAAM,CAAC,KAAK;QAAE,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AAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACxF,CAAC;IACD,MAAM,eAAe,GAAG,MAAM,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAC9D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,eAAe,CAAC,EAAE,EAAE,CAAC;AAAA,CACrE","sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { lstat, rm, unlink } from \"node:fs/promises\";\nimport { orchestrationSessionDir } from \"./agent-paths.ts\";\n\nexport type SessionArtifactDeletionMethod = \"trash\" | \"unlink\";\n\nexport interface SessionArtifactPathDeletion {\n\tok: boolean;\n\tmethod: SessionArtifactDeletionMethod;\n\terror?: string;\n}\n\nexport interface ForegroundSessionBundleDeletion {\n\tforeground: SessionArtifactPathDeletion;\n\tworkerArtifacts: SessionArtifactPathDeletion | { ok: true; method: \"absent\" } | { ok: false; method: \"preserved\" };\n\tcomplete: boolean;\n}\n\nexport interface DeleteForegroundSessionBundleOptions {\n\tagentDir: string;\n\tparentSessionId: string;\n\tsessionPath: string;\n\tremovePath?: (path: string) => Promise<SessionArtifactPathDeletion>;\n}\n\nfunction describeTrashError(result: ReturnType<typeof spawnSync>): string | undefined {\n\tconst parts: string[] = [];\n\tif (result.error) parts.push(result.error.message);\n\tconst stderr = typeof result.stderr === \"string\" ? result.stderr.trim() : undefined;\n\tif (stderr) parts.push(stderr.split(\"\\n\")[0] ?? stderr);\n\treturn parts.length > 0 ? `trash: ${parts.join(\" · \").slice(0, 200)}` : undefined;\n}\n\n/**\n * Move a managed path to the platform trash when available. Permanent removal is a documented\n * fallback only when trash cannot complete the individual path.\n */\nexport async function removePathWithTrashFallback(path: string): Promise<SessionArtifactPathDeletion> {\n\tconst trashArgs = path.startsWith(\"-\") ? [\"--\", path] : [path];\n\tconst trashResult = spawnSync(\"trash\", trashArgs, { encoding: \"utf-8\", timeout: 10_000 });\n\tif (trashResult.status === 0 || !existsSync(path)) return { ok: true, method: \"trash\" };\n\n\ttry {\n\t\tconst stat = await lstat(path);\n\t\tif (stat.isDirectory()) {\n\t\t\tawait rm(path, { recursive: true, force: false });\n\t\t} else {\n\t\t\tawait unlink(path);\n\t\t}\n\t\treturn { ok: true, method: \"unlink\" };\n\t} catch (error) {\n\t\tconst fallbackError = error instanceof Error ? error.message : String(error);\n\t\tconst trashError = describeTrashError(trashResult);\n\t\treturn {\n\t\t\tok: false,\n\t\t\tmethod: \"unlink\",\n\t\t\terror: trashError ? `${fallbackError} (${trashError})` : fallbackError,\n\t\t};\n\t}\n}\n\n/**\n * Explicitly delete one foreground session together with its exact session-owned control-plane\n * namespace. No age-based cleanup is performed. If the foreground file moves first but its worker\n * bundle cannot, the result reports that partial state rather than claiming a full deletion.\n */\nexport async function deleteForegroundSessionBundle(\n\toptions: DeleteForegroundSessionBundleOptions,\n): Promise<ForegroundSessionBundleDeletion> {\n\tconst removePath = options.removePath ?? removePathWithTrashFallback;\n\tconst foreground = await removePath(options.sessionPath);\n\tif (!foreground.ok) {\n\t\treturn { foreground, workerArtifacts: { ok: false, method: \"preserved\" }, complete: false };\n\t}\n\n\tconst workerArtifactsPath = orchestrationSessionDir(options.agentDir, options.parentSessionId);\n\tif (!existsSync(workerArtifactsPath)) {\n\t\treturn { foreground, workerArtifacts: { ok: true, method: \"absent\" }, complete: true };\n\t}\n\tconst workerArtifacts = await removePath(workerArtifactsPath);\n\treturn { foreground, workerArtifacts, complete: workerArtifacts.ok };\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { WorkerClaim } from "../autonomy/contracts.ts";
|
|
2
2
|
import type { LaneRecord } from "../autonomy/lane-tracker.ts";
|
|
3
|
+
import type { WorkerAgentControlPort } from "../delegation/worker-agent-control.ts";
|
|
3
4
|
import type { ToolDefinition } from "../extensions/types.ts";
|
|
4
5
|
export interface DelegateStatusLaneView {
|
|
5
6
|
laneId: string;
|
|
@@ -11,7 +12,7 @@ export interface DelegateStatusLaneView {
|
|
|
11
12
|
unreviewed: boolean;
|
|
12
13
|
}
|
|
13
14
|
export interface DelegateStatusToolDetails {
|
|
14
|
-
kind: "overview" | "lane" | "review" | "error";
|
|
15
|
+
kind: "overview" | "lane" | "review" | "wait" | "error";
|
|
15
16
|
count?: number;
|
|
16
17
|
queued?: number;
|
|
17
18
|
running?: number;
|
|
@@ -28,6 +29,8 @@ export interface DelegateStatusToolDetails {
|
|
|
28
29
|
claimSummary?: string;
|
|
29
30
|
changedFiles?: readonly string[];
|
|
30
31
|
blockers?: readonly string[];
|
|
32
|
+
agentId?: string;
|
|
33
|
+
agentStatus?: "active" | "suspended" | "idle" | "unknown";
|
|
31
34
|
}
|
|
32
35
|
export type AcknowledgeWorkerReviewResult = {
|
|
33
36
|
ok: true;
|
|
@@ -46,6 +49,8 @@ export interface DelegateStatusDependencies {
|
|
|
46
49
|
* it the "review" action reports itself unsupported instead of silently no-op'ing.
|
|
47
50
|
*/
|
|
48
51
|
acknowledgeWorkerReview?(requestId: string): AcknowledgeWorkerReviewResult;
|
|
52
|
+
/** Event-driven logical-worker controls; callers must not poll. */
|
|
53
|
+
workerAgentControl?: Pick<WorkerAgentControlPort, "waitForWorkerAgent">;
|
|
49
54
|
}
|
|
50
55
|
export declare function createDelegateStatusToolDefinition(deps: DelegateStatusDependencies): ToolDefinition;
|
|
51
56
|
//# sourceMappingURL=delegate-status.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate-status.d.ts","sourceRoot":"","sources":["../../../src/core/tools/delegate-status.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAwB7D,MAAM,WAAW,sBAAsB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EA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BAA0B;IAC1C,cAAc,IAAI,UAAU,EAAE,CAAC;IAC/B,uBAAuB,IAAI,WAAW,EAAE,CAAC;IACzC;;;;OAIG;IACH,uBAAuB,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,6BAA6B,CAAC;CAC3E;AA+HD,wBAAgB,kCAAkC,CAAC,IAAI,EAAE,0BAA0B,GAAG,cAAc,CAuInG","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { WorkerClaim } from \"../autonomy/contracts.ts\";\nimport type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\temptyOrchestrationCall,\n\tOrchestrationPanelComponent,\n\ttype OrchestrationPanelModel,\n\ttype OrchestrationPanelRow,\n} from \"./orchestration-panel.ts\";\n\nconst schema = Type.Object(\n\t{\n\t\tlaneId: Type.Optional(\n\t\t\tType.String({ description: \"Worker lane id to inspect. Omit it for a recent-session status overview.\" }),\n\t\t),\n\t\taction: Type.Optional(\n\t\t\tType.Literal(\"review\", {\n\t\t\t\tdescription:\n\t\t\t\t\t'Pass \"review\" together with laneId to durably acknowledge that worker\\'s unreviewed mutation, clearing its sticky notice. Not required to read a status.',\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\ntype Input = Static<typeof schema>;\n\nexport interface DelegateStatusLaneView {\n\tlaneId: string;\n\tlabel?: string;\n\tprofileId?: string;\n\ttype: LaneRecord[\"type\"];\n\tstatus: LaneRecord[\"status\"];\n\treasonCode?: string;\n\tunreviewed: boolean;\n}\n\nexport interface DelegateStatusToolDetails {\n\tkind: \"overview\" | \"lane\" | \"review\" | \"error\";\n\tcount?: number;\n\tqueued?: number;\n\trunning?: number;\n\tterminal?: number;\n\tunreviewedCount?: number;\n\tunreviewedLaneIds?: readonly string[];\n\tlanes?: readonly DelegateStatusLaneView[];\n\tlaneId?: string;\n\tstatus?: LaneRecord[\"status\"];\n\tunreviewed?: boolean;\n\treviewed?: boolean;\n\treviewedAt?: string;\n\treason?: string;\n\tclaimSummary?: string;\n\tchangedFiles?: readonly string[];\n\tblockers?: readonly string[];\n}\n\nexport type AcknowledgeWorkerReviewResult =\n\t| { ok: true; requestId: string; reviewedAt: string }\n\t| { ok: false; reason: \"unknown_worker_claim\" | \"not_flagged\" | \"already_reviewed\" };\n\nexport interface DelegateStatusDependencies {\n\tgetLaneRecords(): LaneRecord[];\n\tgetWorkerClaimSnapshots(): WorkerClaim[];\n\t/**\n\t * Durably acknowledge an unreviewed worker mutation (parentReviewRequired), clearing its\n\t * sticky notice. Optional so callers without durable persistence wired still type-check; without\n\t * it the \"review\" action reports itself unsupported instead of silently no-op'ing.\n\t */\n\tacknowledgeWorkerReview?(requestId: string): AcknowledgeWorkerReviewResult;\n}\n\n/** A worker claim flagged parent_review_required whose mutation has not yet been acked. */\nfunction isUnreviewed(claim: WorkerClaim | undefined): boolean {\n\treturn claim?.parentReviewRequired === true && claim.parentReviewedAt === undefined;\n}\n\n/** In-process `worker` lanes and out-of-process `tmux-worker` lanes are both delegated work whose\n * output is an untrusted claim under the same review machinery — surfaced together here. */\nfunction isDelegatedWorkerLane(record: LaneRecord): boolean {\n\treturn record.type === \"worker\" || record.type === \"tmux-worker\";\n}\n\nfunction formatRecord(record: LaneRecord, claim: WorkerClaim | undefined): string {\n\tconst lines = [`${record.laneId}: ${record.status}${record.reasonCode ? ` (${record.reasonCode})` : \"\"}`];\n\tif (!claim) return lines.join(\"\\n\");\n\tlines.push(`usageReportId: ${claim.usageReportId ?? \"none\"}`);\n\tif (isUnreviewed(claim)) {\n\t\tlines.push(\n\t\t\t`UNREVIEWED MUTATION - this worker's claim requires explicit parent review. Acknowledge with delegate_status { laneId: \"${record.laneId}\", action: \"review\" }.`,\n\t\t);\n\t} else if (claim.parentReviewRequired && claim.parentReviewedAt) {\n\t\tlines.push(`reviewed at ${claim.parentReviewedAt}`);\n\t}\n\tlines.push(\"UNTRUSTED worker output — verify before acting on it:\");\n\tlines.push(claim.summary.slice(0, 8000));\n\tif (claim.changedFiles.length > 0) lines.push(`changed files: ${claim.changedFiles.join(\", \")}`);\n\tif (claim.blockers?.length) lines.push(`blockers: ${claim.blockers.join(\"; \")}`);\n\treturn lines.join(\"\\n\").slice(0, 16 * 1024);\n}\n\nfunction laneView(record: LaneRecord, claim: WorkerClaim | undefined): DelegateStatusLaneView {\n\treturn {\n\t\tlaneId: record.laneId,\n\t\t...(record.label ? { label: record.label } : {}),\n\t\t...(record.profileId ? { profileId: record.profileId } : {}),\n\t\ttype: record.type,\n\t\tstatus: record.status,\n\t\t...(record.reasonCode ? { reasonCode: record.reasonCode } : {}),\n\t\tunreviewed: isUnreviewed(claim),\n\t};\n}\n\nfunction lanePanelRow(view: DelegateStatusLaneView, details?: DelegateStatusToolDetails): OrchestrationPanelRow {\n\tconst meta = [\n\t\tview.label ? view.laneId : undefined,\n\t\tview.profileId ? `profile ${view.profileId}` : undefined,\n\t\tview.type === \"tmux-worker\" ? \"tmux\" : undefined,\n\t\tview.reasonCode,\n\t\tview.unreviewed ? \"review required\" : undefined,\n\t].filter((value): value is string => value !== undefined);\n\tconst expandedDetails = [\n\t\tdetails?.claimSummary ? `untrusted claim: ${details.claimSummary}` : undefined,\n\t\tdetails?.changedFiles?.length ? `changed: ${details.changedFiles.join(\", \")}` : undefined,\n\t\t...(details?.blockers ?? []).map((blocker) => `blocker: ${blocker}`),\n\t].filter((value): value is string => value !== undefined);\n\treturn {\n\t\tstatus: view.status,\n\t\tlabel: view.label ?? view.laneId,\n\t\tmeta,\n\t\tdetails: expandedDetails,\n\t};\n}\n\nfunction delegateStatusPanelModel(details: DelegateStatusToolDetails | undefined): OrchestrationPanelModel {\n\tif (!details) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"status\",\n\t\t\tstatus: \"idle\",\n\t\t\temptyText: \"No structured worker status was retained.\",\n\t\t};\n\t}\n\tif (details.kind === \"error\") {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"status\",\n\t\t\tstatus: \"error\",\n\t\t\temptyText: details.reason ?? \"Worker status is unavailable.\",\n\t\t};\n\t}\n\tif (details.kind === \"review\") {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: details.reviewed ? \"reviewed\" : \"review required\",\n\t\t\tstatus: details.reviewed ? \"success\" : \"warning\",\n\t\t\trows: details.laneId\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: details.reviewed ? \"reviewed\" : \"blocked\",\n\t\t\t\t\t\t\tlabel: details.laneId,\n\t\t\t\t\t\t\tmeta: details.reviewedAt ? [`reviewed ${details.reviewedAt}`] : undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: undefined,\n\t\t\temptyText: details.reason,\n\t\t};\n\t}\n\tconst lanes = details.lanes ?? [];\n\tconst rows = lanes.map((view) => lanePanelRow(view, details.kind === \"lane\" ? details : undefined));\n\tconst running = details.running ?? lanes.filter((lane) => lane.status === \"running\").length;\n\tconst queued = details.queued ?? lanes.filter((lane) => lane.status === \"queued\").length;\n\tconst terminal = details.terminal ?? lanes.length - running - queued;\n\tconst unreviewed = details.unreviewedCount ?? lanes.filter((lane) => lane.unreviewed).length;\n\treturn {\n\t\tlabel: \"workers\",\n\t\taction: details.kind === \"lane\" ? \"lane\" : \"status\",\n\t\tstatus: unreviewed > 0 ? \"warning\" : running + queued > 0 ? \"running\" : lanes.length > 0 ? \"success\" : \"idle\",\n\t\tsummary: [\n\t\t\trunning ? `${running} running` : undefined,\n\t\t\tqueued ? `${queued} queued` : undefined,\n\t\t\tterminal ? `${terminal} terminal` : undefined,\n\t\t].filter((value): value is string => value !== undefined),\n\t\trows,\n\t\temptyText: \"No worker lanes.\",\n\t\tnotices:\n\t\t\tunreviewed > 0\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: \"warning\",\n\t\t\t\t\t\t\ttext: `${unreviewed} worker mutation${unreviewed === 1 ? \"\" : \"s\"} awaiting parent review.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: undefined,\n\t};\n}\n\nexport function createDelegateStatusToolDefinition(deps: DelegateStatusDependencies): ToolDefinition {\n\treturn {\n\t\tname: \"delegate_status\",\n\t\tlabel: \"delegate_status\",\n\t\tdescription:\n\t\t\t'Inspect queued, running, and terminal workers in this session, retrieve one worker\\'s bounded, explicitly untrusted claim, or acknowledge (action: \"review\") an unreviewed worker mutation.',\n\t\tpromptSnippet:\n\t\t\t\"Inspect delegated workers after a terminal handoff without receiving a late transcript injection; acknowledge unreviewed mutations.\",\n\t\tparameters: schema,\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) return emptyOrchestrationCall();\n\t\t\tconst details = result.details as DelegateStatusToolDetails | undefined;\n\t\t\tif (!expanded && details && details.kind !== \"error\" && !(details.kind === \"review\" && !details.reviewed)) {\n\t\t\t\treturn emptyOrchestrationCall();\n\t\t\t}\n\t\t\treturn new OrchestrationPanelComponent(theme, delegateStatusPanelModel(details), expanded);\n\t\t},\n\t\tasync execute(_toolCallId, input: Input) {\n\t\t\tif (input.action === \"review\") {\n\t\t\t\tif (!input.laneId) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"review action requires laneId\" }],\n\t\t\t\t\t\tdetails: { kind: \"review\", reviewed: false, reason: \"missing_lane_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (!deps.acknowledgeWorkerReview) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"review acknowledgement is not available in this session\" }],\n\t\t\t\t\t\tdetails: { kind: \"review\", reviewed: false, reason: \"review_unsupported\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst outcome = deps.acknowledgeWorkerReview(input.laneId);\n\t\t\t\tif (!outcome.ok) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: `review not acknowledged (${input.laneId}): ${outcome.reason}` },\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { kind: \"review\", laneId: input.laneId, reviewed: false, reason: outcome.reason },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `reviewed ${input.laneId} at ${outcome.reviewedAt} — unreviewed-mutation notice cleared`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tkind: \"review\",\n\t\t\t\t\t\tlaneId: input.laneId,\n\t\t\t\t\t\treviewed: true,\n\t\t\t\t\t\treviewedAt: outcome.reviewedAt,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst records = deps.getLaneRecords().filter(isDelegatedWorkerLane);\n\t\t\tconst claims = new Map(deps.getWorkerClaimSnapshots().map((claim) => [claim.requestId, claim]));\n\t\t\t// Sticky: computed over ALL worker records, not just the recent window below — an\n\t\t\t// unreviewed mutation must stay visible no matter how much later lane churn buries it.\n\t\t\tconst unreviewedRecords = records.filter((record) => isUnreviewed(claims.get(record.laneId)));\n\n\t\t\tif (input.laneId) {\n\t\t\t\tconst record = records.find((candidate) => candidate.laneId === input.laneId);\n\t\t\t\tif (!record) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"unknown_worker_lane\" }],\n\t\t\t\t\t\tdetails: { kind: \"error\", reason: \"unknown_worker_lane\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: formatRecord(record, claims.get(record.laneId)) }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tkind: \"lane\",\n\t\t\t\t\t\tlaneId: record.laneId,\n\t\t\t\t\t\tstatus: record.status,\n\t\t\t\t\t\tunreviewed: isUnreviewed(claims.get(record.laneId)),\n\t\t\t\t\t\tlanes: [laneView(record, claims.get(record.laneId))],\n\t\t\t\t\t\tclaimSummary: claims.get(record.laneId)?.summary.slice(0, 8_000),\n\t\t\t\t\t\tchangedFiles: claims.get(record.laneId)?.changedFiles.slice(0, 64),\n\t\t\t\t\t\tblockers: claims.get(record.laneId)?.blockers?.slice(0, 16),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst recentRecords = records.slice(-10);\n\t\t\tconst recentLaneIds = new Set(recentRecords.map((record) => record.laneId));\n\t\t\tconst queued = records.filter((record) => record.status === \"queued\").length;\n\t\t\tconst running = records.filter((record) => record.status === \"running\").length;\n\t\t\tconst terminal = records.length - queued - running;\n\t\t\tconst recent = recentRecords.map((record) => formatRecord(record, claims.get(record.laneId)));\n\t\t\tconst olderUnreviewed = unreviewedRecords.filter((record) => !recentLaneIds.has(record.laneId));\n\t\t\tconst displayedRecords = [...recentRecords, ...olderUnreviewed.slice(0, 10)].filter(\n\t\t\t\t(record, index, all) => all.findIndex((candidate) => candidate.laneId === record.laneId) === index,\n\t\t\t);\n\t\t\tconst olderUnreviewedText =\n\t\t\t\tolderUnreviewed.length > 0\n\t\t\t\t\t? `\\n\\nOlder unreviewed workers (outside the recent list):\\n${olderUnreviewed\n\t\t\t\t\t\t\t.map((record) => formatRecord(record, claims.get(record.laneId)))\n\t\t\t\t\t\t\t.join(\"\\n\\n\")}`\n\t\t\t\t\t: \"\";\n\t\t\tconst overviewLines = [`workers: ${running} running, ${queued} queued, ${terminal} terminal`];\n\t\t\tif (unreviewedRecords.length > 0) {\n\t\t\t\toverviewLines.push(\n\t\t\t\t\t`${unreviewedRecords.length} unreviewed worker mutation${unreviewedRecords.length === 1 ? \"\" : \"s\"} pending review: ${unreviewedRecords.map((record) => record.laneId).join(\", \")}. Acknowledge each with delegate_status { laneId, action: \"review\" }.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst overview = overviewLines.join(\"\\n\");\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\trecent.length > 0\n\t\t\t\t\t\t\t\t? `${overview}\\n\\n${recent.join(\"\\n\\n\")}${olderUnreviewedText}`.slice(0, 16 * 1024)\n\t\t\t\t\t\t\t\t: \"No worker lanes.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: {\n\t\t\t\t\tkind: \"overview\",\n\t\t\t\t\tcount: recent.length,\n\t\t\t\t\tqueued,\n\t\t\t\t\trunning,\n\t\t\t\t\tterminal,\n\t\t\t\t\tunreviewedCount: unreviewedRecords.length,\n\t\t\t\t\tunreviewedLaneIds: unreviewedRecords.map((record) => record.laneId),\n\t\t\t\t\tlanes: displayedRecords.map((record) => laneView(record, claims.get(record.laneId))),\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"delegate-status.d.ts","sourceRoot":"","sources":["../../../src/core/tools/delegate-status.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AA2C7D,MAAM,WAAW,sBAAsB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACzB,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC7B,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AAE,CAAC;IAC/B,uBAAuB,IAAI,WAAW,EAAE,CAAC;IACzC;;;;OAIG;IACH,uBAAuB,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,6BAA6B,CAAC;IAC3E,mEAAmE;IACnE,kBAAkB,CAAC,EAAE,IAAI,CAAC,sBAAsB,EAAE,oBAAoB,CAAC,CAAC;CACxE;AA+HD,wBAAgB,kCAAkC,CAAC,IAAI,EAAE,0BAA0B,GAAG,cAAc,CA6MnG","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { WorkerClaim } from \"../autonomy/contracts.ts\";\nimport type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { WorkerAgentControlPort } from \"../delegation/worker-agent-control.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\temptyOrchestrationCall,\n\tOrchestrationPanelComponent,\n\ttype OrchestrationPanelModel,\n\ttype OrchestrationPanelRow,\n} from \"./orchestration-panel.ts\";\n\nconst MAX_WORKER_CONTROL_ID_CHARS = 512;\n\nconst schema = Type.Object(\n\t{\n\t\tagentId: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tmaxLength: MAX_WORKER_CONTROL_ID_CHARS,\n\t\t\t\tdescription: \"Stable logical worker id returned by delegate start; required only for action wait.\",\n\t\t\t}),\n\t\t),\n\t\tlaneId: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tmaxLength: MAX_WORKER_CONTROL_ID_CHARS,\n\t\t\t\tdescription: \"Worker lane id to inspect. Omit it for a recent-session status overview.\",\n\t\t\t}),\n\t\t),\n\t\taction: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tenum: [\"review\", \"wait\"],\n\t\t\t\tdescription:\n\t\t\t\t\t'Pass \"review\" together with laneId to durably acknowledge that worker\\'s unreviewed mutation, clearing its sticky notice. Pass \"wait\" with agentId for one event-driven state change; do not poll.',\n\t\t\t}),\n\t\t),\n\t\ttimeoutMs: Type.Optional(\n\t\t\tType.Integer({\n\t\t\t\tminimum: 0,\n\t\t\t\tmaximum: 300_000,\n\t\t\t\tdescription: \"Optional bounded event-driven wait timeout in milliseconds.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\ntype Input = Static<typeof schema>;\n\nexport interface DelegateStatusLaneView {\n\tlaneId: string;\n\tlabel?: string;\n\tprofileId?: string;\n\ttype: LaneRecord[\"type\"];\n\tstatus: LaneRecord[\"status\"];\n\treasonCode?: string;\n\tunreviewed: boolean;\n}\n\nexport interface DelegateStatusToolDetails {\n\tkind: \"overview\" | \"lane\" | \"review\" | \"wait\" | \"error\";\n\tcount?: number;\n\tqueued?: number;\n\trunning?: number;\n\tterminal?: number;\n\tunreviewedCount?: number;\n\tunreviewedLaneIds?: readonly string[];\n\tlanes?: readonly DelegateStatusLaneView[];\n\tlaneId?: string;\n\tstatus?: LaneRecord[\"status\"];\n\tunreviewed?: boolean;\n\treviewed?: boolean;\n\treviewedAt?: string;\n\treason?: string;\n\tclaimSummary?: string;\n\tchangedFiles?: readonly string[];\n\tblockers?: readonly string[];\n\tagentId?: string;\n\tagentStatus?: \"active\" | \"suspended\" | \"idle\" | \"unknown\";\n}\n\nexport type AcknowledgeWorkerReviewResult =\n\t| { ok: true; requestId: string; reviewedAt: string }\n\t| { ok: false; reason: \"unknown_worker_claim\" | \"not_flagged\" | \"already_reviewed\" };\n\nexport interface DelegateStatusDependencies {\n\tgetLaneRecords(): LaneRecord[];\n\tgetWorkerClaimSnapshots(): WorkerClaim[];\n\t/**\n\t * Durably acknowledge an unreviewed worker mutation (parentReviewRequired), clearing its\n\t * sticky notice. Optional so callers without durable persistence wired still type-check; without\n\t * it the \"review\" action reports itself unsupported instead of silently no-op'ing.\n\t */\n\tacknowledgeWorkerReview?(requestId: string): AcknowledgeWorkerReviewResult;\n\t/** Event-driven logical-worker controls; callers must not poll. */\n\tworkerAgentControl?: Pick<WorkerAgentControlPort, \"waitForWorkerAgent\">;\n}\n\n/** A worker claim flagged parent_review_required whose mutation has not yet been acked. */\nfunction isUnreviewed(claim: WorkerClaim | undefined): boolean {\n\treturn claim?.parentReviewRequired === true && claim.parentReviewedAt === undefined;\n}\n\n/** In-process `worker` lanes and out-of-process `tmux-worker` lanes are both delegated work whose\n * output is an untrusted claim under the same review machinery — surfaced together here. */\nfunction isDelegatedWorkerLane(record: LaneRecord): boolean {\n\treturn record.type === \"worker\" || record.type === \"tmux-worker\";\n}\n\nfunction formatRecord(record: LaneRecord, claim: WorkerClaim | undefined): string {\n\tconst lines = [`${record.laneId}: ${record.status}${record.reasonCode ? ` (${record.reasonCode})` : \"\"}`];\n\tif (!claim) return lines.join(\"\\n\");\n\tlines.push(`usageReportId: ${claim.usageReportId ?? \"none\"}`);\n\tif (isUnreviewed(claim)) {\n\t\tlines.push(\n\t\t\t`UNREVIEWED MUTATION - this worker's claim requires explicit parent review. Acknowledge with delegate_status { laneId: \"${record.laneId}\", action: \"review\" }.`,\n\t\t);\n\t} else if (claim.parentReviewRequired && claim.parentReviewedAt) {\n\t\tlines.push(`reviewed at ${claim.parentReviewedAt}`);\n\t}\n\tlines.push(\"UNTRUSTED worker output — verify before acting on it:\");\n\tlines.push(claim.summary.slice(0, 8000));\n\tif (claim.changedFiles.length > 0) lines.push(`changed files: ${claim.changedFiles.join(\", \")}`);\n\tif (claim.blockers?.length) lines.push(`blockers: ${claim.blockers.join(\"; \")}`);\n\treturn lines.join(\"\\n\").slice(0, 16 * 1024);\n}\n\nfunction laneView(record: LaneRecord, claim: WorkerClaim | undefined): DelegateStatusLaneView {\n\treturn {\n\t\tlaneId: record.laneId,\n\t\t...(record.label ? { label: record.label } : {}),\n\t\t...(record.profileId ? { profileId: record.profileId } : {}),\n\t\ttype: record.type,\n\t\tstatus: record.status,\n\t\t...(record.reasonCode ? { reasonCode: record.reasonCode } : {}),\n\t\tunreviewed: isUnreviewed(claim),\n\t};\n}\n\nfunction lanePanelRow(view: DelegateStatusLaneView, details?: DelegateStatusToolDetails): OrchestrationPanelRow {\n\tconst meta = [\n\t\tview.label ? view.laneId : undefined,\n\t\tview.profileId ? `profile ${view.profileId}` : undefined,\n\t\tview.type === \"tmux-worker\" ? \"tmux\" : undefined,\n\t\tview.reasonCode,\n\t\tview.unreviewed ? \"review required\" : undefined,\n\t].filter((value): value is string => value !== undefined);\n\tconst expandedDetails = [\n\t\tdetails?.claimSummary ? `untrusted claim: ${details.claimSummary}` : undefined,\n\t\tdetails?.changedFiles?.length ? `changed: ${details.changedFiles.join(\", \")}` : undefined,\n\t\t...(details?.blockers ?? []).map((blocker) => `blocker: ${blocker}`),\n\t].filter((value): value is string => value !== undefined);\n\treturn {\n\t\tstatus: view.status,\n\t\tlabel: view.label ?? view.laneId,\n\t\tmeta,\n\t\tdetails: expandedDetails,\n\t};\n}\n\nfunction delegateStatusPanelModel(details: DelegateStatusToolDetails | undefined): OrchestrationPanelModel {\n\tif (!details) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"status\",\n\t\t\tstatus: \"idle\",\n\t\t\temptyText: \"No structured worker status was retained.\",\n\t\t};\n\t}\n\tif (details.kind === \"error\") {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"status\",\n\t\t\tstatus: \"error\",\n\t\t\temptyText: details.reason ?? \"Worker status is unavailable.\",\n\t\t};\n\t}\n\tif (details.kind === \"review\") {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: details.reviewed ? \"reviewed\" : \"review required\",\n\t\t\tstatus: details.reviewed ? \"success\" : \"warning\",\n\t\t\trows: details.laneId\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: details.reviewed ? \"reviewed\" : \"blocked\",\n\t\t\t\t\t\t\tlabel: details.laneId,\n\t\t\t\t\t\t\tmeta: details.reviewedAt ? [`reviewed ${details.reviewedAt}`] : undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: undefined,\n\t\t\temptyText: details.reason,\n\t\t};\n\t}\n\tconst lanes = details.lanes ?? [];\n\tconst rows = lanes.map((view) => lanePanelRow(view, details.kind === \"lane\" ? details : undefined));\n\tconst running = details.running ?? lanes.filter((lane) => lane.status === \"running\").length;\n\tconst queued = details.queued ?? lanes.filter((lane) => lane.status === \"queued\").length;\n\tconst terminal = details.terminal ?? lanes.length - running - queued;\n\tconst unreviewed = details.unreviewedCount ?? lanes.filter((lane) => lane.unreviewed).length;\n\treturn {\n\t\tlabel: \"workers\",\n\t\taction: details.kind === \"lane\" ? \"lane\" : \"status\",\n\t\tstatus: unreviewed > 0 ? \"warning\" : running + queued > 0 ? \"running\" : lanes.length > 0 ? \"success\" : \"idle\",\n\t\tsummary: [\n\t\t\trunning ? `${running} running` : undefined,\n\t\t\tqueued ? `${queued} queued` : undefined,\n\t\t\tterminal ? `${terminal} terminal` : undefined,\n\t\t].filter((value): value is string => value !== undefined),\n\t\trows,\n\t\temptyText: \"No worker lanes.\",\n\t\tnotices:\n\t\t\tunreviewed > 0\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: \"warning\",\n\t\t\t\t\t\t\ttext: `${unreviewed} worker mutation${unreviewed === 1 ? \"\" : \"s\"} awaiting parent review.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: undefined,\n\t};\n}\n\nexport function createDelegateStatusToolDefinition(deps: DelegateStatusDependencies): ToolDefinition {\n\treturn {\n\t\tname: \"delegate_status\",\n\t\tlabel: \"delegate_status\",\n\t\tdescription:\n\t\t\t'Inspect queued, running, and terminal workers in this session, retrieve one worker\\'s bounded, explicitly untrusted claim, acknowledge (action: \"review\") an unreviewed worker mutation, or use action: \"wait\" with agentId for one event-driven update. Do not poll.',\n\t\tpromptSnippet:\n\t\t\t\"Inspect delegated workers after a terminal handoff without receiving a late transcript injection; acknowledge unreviewed mutations.\",\n\t\tparameters: schema,\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) return emptyOrchestrationCall();\n\t\t\tconst details = result.details as DelegateStatusToolDetails | undefined;\n\t\t\tif (!expanded && details && details.kind !== \"error\" && !(details.kind === \"review\" && !details.reviewed)) {\n\t\t\t\treturn emptyOrchestrationCall();\n\t\t\t}\n\t\t\treturn new OrchestrationPanelComponent(theme, delegateStatusPanelModel(details), expanded);\n\t\t},\n\t\tasync execute(_toolCallId, input: Input) {\n\t\t\tif (input.action !== undefined && input.action.length > 16) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"delegate_status action is invalid\" }],\n\t\t\t\t\tdetails: { kind: \"error\", reason: \"invalid_action\" },\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (input.action !== undefined && input.action !== \"review\" && input.action !== \"wait\") {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate_status action is invalid: ${input.action}` }],\n\t\t\t\t\tdetails: { kind: \"error\", reason: \"invalid_action\" },\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (input.action === \"wait\") {\n\t\t\t\tif (input.agentId !== undefined && input.agentId.length > MAX_WORKER_CONTROL_ID_CHARS) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"wait action agentId is invalid\" }],\n\t\t\t\t\t\tdetails: { kind: \"wait\" as const, reason: \"invalid_agent_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst agentId = input.agentId?.trim();\n\t\t\t\tif (!agentId) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"wait action requires agentId\" }],\n\t\t\t\t\t\tdetails: { kind: \"wait\", reason: \"missing_agent_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\tinput.timeoutMs !== undefined &&\n\t\t\t\t\t(!Number.isSafeInteger(input.timeoutMs) || input.timeoutMs < 0 || input.timeoutMs > 300_000)\n\t\t\t\t) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"wait action timeoutMs is invalid\" }],\n\t\t\t\t\t\tdetails: { kind: \"wait\", agentId, reason: \"invalid_timeout_ms\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (!deps.workerAgentControl) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: \"event-driven worker wait is not available in this session\" },\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { kind: \"wait\", agentId, reason: \"wait_unsupported\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst outcome = await deps.workerAgentControl.waitForWorkerAgent(agentId, input.timeoutMs);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `worker ${agentId} wait completed: ${outcome.status}` }],\n\t\t\t\t\tdetails: { kind: \"wait\", agentId, agentStatus: outcome.status },\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (input.action === \"review\") {\n\t\t\t\tif (!input.laneId?.trim()) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"review action requires laneId\" }],\n\t\t\t\t\t\tdetails: { kind: \"review\", reviewed: false, reason: \"missing_lane_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (input.laneId.length > MAX_WORKER_CONTROL_ID_CHARS) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"review action laneId is invalid\" }],\n\t\t\t\t\t\tdetails: { kind: \"review\" as const, reviewed: false, reason: \"invalid_lane_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst laneId = input.laneId.trim();\n\t\t\t\tif (!deps.acknowledgeWorkerReview) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"review acknowledgement is not available in this session\" }],\n\t\t\t\t\t\tdetails: { kind: \"review\", reviewed: false, reason: \"review_unsupported\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst outcome = deps.acknowledgeWorkerReview(laneId);\n\t\t\t\tif (!outcome.ok) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `review not acknowledged (${laneId}): ${outcome.reason}` }],\n\t\t\t\t\t\tdetails: { kind: \"review\", laneId, reviewed: false, reason: outcome.reason },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `reviewed ${laneId} at ${outcome.reviewedAt} — unreviewed-mutation notice cleared`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tkind: \"review\",\n\t\t\t\t\t\tlaneId,\n\t\t\t\t\t\treviewed: true,\n\t\t\t\t\t\treviewedAt: outcome.reviewedAt,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst records = deps.getLaneRecords().filter(isDelegatedWorkerLane);\n\t\t\tconst claims = new Map(deps.getWorkerClaimSnapshots().map((claim) => [claim.requestId, claim]));\n\t\t\t// Sticky: computed over ALL worker records, not just the recent window below — an\n\t\t\t// unreviewed mutation must stay visible no matter how much later lane churn buries it.\n\t\t\tconst unreviewedRecords = records.filter((record) => isUnreviewed(claims.get(record.laneId)));\n\n\t\t\tif (input.laneId !== undefined) {\n\t\t\t\tif (input.laneId.length > MAX_WORKER_CONTROL_ID_CHARS) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"worker lane id is invalid\" }],\n\t\t\t\t\t\tdetails: { kind: \"error\" as const, reason: \"invalid_lane_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst laneId = input.laneId.trim();\n\t\t\t\tif (!laneId) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"worker lane id is invalid\" }],\n\t\t\t\t\t\tdetails: { kind: \"error\" as const, reason: \"invalid_lane_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst record = records.find((candidate) => candidate.laneId === laneId);\n\t\t\t\tif (!record) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"unknown_worker_lane\" }],\n\t\t\t\t\t\tdetails: { kind: \"error\", reason: \"unknown_worker_lane\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: formatRecord(record, claims.get(record.laneId)) }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tkind: \"lane\",\n\t\t\t\t\t\tlaneId: record.laneId,\n\t\t\t\t\t\tstatus: record.status,\n\t\t\t\t\t\tunreviewed: isUnreviewed(claims.get(record.laneId)),\n\t\t\t\t\t\tlanes: [laneView(record, claims.get(record.laneId))],\n\t\t\t\t\t\tclaimSummary: claims.get(record.laneId)?.summary.slice(0, 8_000),\n\t\t\t\t\t\tchangedFiles: claims.get(record.laneId)?.changedFiles.slice(0, 64),\n\t\t\t\t\t\tblockers: claims.get(record.laneId)?.blockers?.slice(0, 16),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst recentRecords = records.slice(-10);\n\t\t\tconst recentLaneIds = new Set(recentRecords.map((record) => record.laneId));\n\t\t\tconst queued = records.filter((record) => record.status === \"queued\").length;\n\t\t\tconst running = records.filter((record) => record.status === \"running\").length;\n\t\t\tconst terminal = records.length - queued - running;\n\t\t\tconst recent = recentRecords.map((record) => formatRecord(record, claims.get(record.laneId)).slice(0, 2_048));\n\t\t\tconst olderUnreviewed = unreviewedRecords.filter((record) => !recentLaneIds.has(record.laneId));\n\t\t\tconst displayedRecords = [...recentRecords, ...olderUnreviewed.slice(0, 10)].filter(\n\t\t\t\t(record, index, all) => all.findIndex((candidate) => candidate.laneId === record.laneId) === index,\n\t\t\t);\n\t\t\tconst olderUnreviewedText =\n\t\t\t\tolderUnreviewed.length > 0\n\t\t\t\t\t? `\\n\\nOlder unreviewed workers (outside the recent list):\\n${olderUnreviewed\n\t\t\t\t\t\t\t.slice(0, 10)\n\t\t\t\t\t\t\t.map((record) => formatRecord(record, claims.get(record.laneId)).slice(0, 2_048))\n\t\t\t\t\t\t\t.join(\"\\n\\n\")}`\n\t\t\t\t\t: \"\";\n\t\t\tconst overviewLines = [`workers: ${running} running, ${queued} queued, ${terminal} terminal`];\n\t\t\tif (unreviewedRecords.length > 0) {\n\t\t\t\tconst visibleUnreviewedIds = unreviewedRecords.slice(0, 64).map((record) => record.laneId);\n\t\t\t\tconst omitted = unreviewedRecords.length - visibleUnreviewedIds.length;\n\t\t\t\toverviewLines.push(\n\t\t\t\t\t`${unreviewedRecords.length} unreviewed worker mutation${unreviewedRecords.length === 1 ? \"\" : \"s\"} pending review: ${visibleUnreviewedIds.join(\", \")}${omitted > 0 ? `, and ${omitted} more` : \"\"}. Acknowledge each with delegate_status { laneId, action: \"review\" }.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst overview = overviewLines.join(\"\\n\");\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\trecent.length > 0\n\t\t\t\t\t\t\t\t? `${overview}\\n\\n${recent.join(\"\\n\\n\")}${olderUnreviewedText}`.slice(0, 16 * 1024)\n\t\t\t\t\t\t\t\t: \"No worker lanes.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: {\n\t\t\t\t\tkind: \"overview\",\n\t\t\t\t\tcount: recent.length,\n\t\t\t\t\tqueued,\n\t\t\t\t\trunning,\n\t\t\t\t\tterminal,\n\t\t\t\t\tunreviewedCount: unreviewedRecords.length,\n\t\t\t\t\tunreviewedLaneIds: unreviewedRecords.slice(0, 64).map((record) => record.laneId),\n\t\t\t\t\tlanes: displayedRecords.map((record) => laneView(record, claims.get(record.laneId))),\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { emptyOrchestrationCall, OrchestrationPanelComponent, } from "./orchestration-panel.js";
|
|
3
|
+
const MAX_WORKER_CONTROL_ID_CHARS = 512;
|
|
3
4
|
const schema = Type.Object({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
description:
|
|
5
|
+
agentId: Type.Optional(Type.String({
|
|
6
|
+
maxLength: MAX_WORKER_CONTROL_ID_CHARS,
|
|
7
|
+
description: "Stable logical worker id returned by delegate start; required only for action wait.",
|
|
8
|
+
})),
|
|
9
|
+
laneId: Type.Optional(Type.String({
|
|
10
|
+
maxLength: MAX_WORKER_CONTROL_ID_CHARS,
|
|
11
|
+
description: "Worker lane id to inspect. Omit it for a recent-session status overview.",
|
|
12
|
+
})),
|
|
13
|
+
action: Type.Optional(Type.String({
|
|
14
|
+
enum: ["review", "wait"],
|
|
15
|
+
description: 'Pass "review" together with laneId to durably acknowledge that worker\'s unreviewed mutation, clearing its sticky notice. Pass "wait" with agentId for one event-driven state change; do not poll.',
|
|
16
|
+
})),
|
|
17
|
+
timeoutMs: Type.Optional(Type.Integer({
|
|
18
|
+
minimum: 0,
|
|
19
|
+
maximum: 300_000,
|
|
20
|
+
description: "Optional bounded event-driven wait timeout in milliseconds.",
|
|
7
21
|
})),
|
|
8
22
|
}, { additionalProperties: false });
|
|
9
23
|
/** A worker claim flagged parent_review_required whose mutation has not yet been acked. */
|
|
@@ -130,7 +144,7 @@ export function createDelegateStatusToolDefinition(deps) {
|
|
|
130
144
|
return {
|
|
131
145
|
name: "delegate_status",
|
|
132
146
|
label: "delegate_status",
|
|
133
|
-
description: 'Inspect queued, running, and terminal workers in this session, retrieve one worker\'s bounded, explicitly untrusted claim,
|
|
147
|
+
description: 'Inspect queued, running, and terminal workers in this session, retrieve one worker\'s bounded, explicitly untrusted claim, acknowledge (action: "review") an unreviewed worker mutation, or use action: "wait" with agentId for one event-driven update. Do not poll.',
|
|
134
148
|
promptSnippet: "Inspect delegated workers after a terminal handoff without receiving a late transcript injection; acknowledge unreviewed mutations.",
|
|
135
149
|
parameters: schema,
|
|
136
150
|
renderShell: "self",
|
|
@@ -147,38 +161,90 @@ export function createDelegateStatusToolDefinition(deps) {
|
|
|
147
161
|
return new OrchestrationPanelComponent(theme, delegateStatusPanelModel(details), expanded);
|
|
148
162
|
},
|
|
149
163
|
async execute(_toolCallId, input) {
|
|
164
|
+
if (input.action !== undefined && input.action.length > 16) {
|
|
165
|
+
return {
|
|
166
|
+
content: [{ type: "text", text: "delegate_status action is invalid" }],
|
|
167
|
+
details: { kind: "error", reason: "invalid_action" },
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
if (input.action !== undefined && input.action !== "review" && input.action !== "wait") {
|
|
171
|
+
return {
|
|
172
|
+
content: [{ type: "text", text: `delegate_status action is invalid: ${input.action}` }],
|
|
173
|
+
details: { kind: "error", reason: "invalid_action" },
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
if (input.action === "wait") {
|
|
177
|
+
if (input.agentId !== undefined && input.agentId.length > MAX_WORKER_CONTROL_ID_CHARS) {
|
|
178
|
+
return {
|
|
179
|
+
content: [{ type: "text", text: "wait action agentId is invalid" }],
|
|
180
|
+
details: { kind: "wait", reason: "invalid_agent_id" },
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const agentId = input.agentId?.trim();
|
|
184
|
+
if (!agentId) {
|
|
185
|
+
return {
|
|
186
|
+
content: [{ type: "text", text: "wait action requires agentId" }],
|
|
187
|
+
details: { kind: "wait", reason: "missing_agent_id" },
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (input.timeoutMs !== undefined &&
|
|
191
|
+
(!Number.isSafeInteger(input.timeoutMs) || input.timeoutMs < 0 || input.timeoutMs > 300_000)) {
|
|
192
|
+
return {
|
|
193
|
+
content: [{ type: "text", text: "wait action timeoutMs is invalid" }],
|
|
194
|
+
details: { kind: "wait", agentId, reason: "invalid_timeout_ms" },
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
if (!deps.workerAgentControl) {
|
|
198
|
+
return {
|
|
199
|
+
content: [
|
|
200
|
+
{ type: "text", text: "event-driven worker wait is not available in this session" },
|
|
201
|
+
],
|
|
202
|
+
details: { kind: "wait", agentId, reason: "wait_unsupported" },
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const outcome = await deps.workerAgentControl.waitForWorkerAgent(agentId, input.timeoutMs);
|
|
206
|
+
return {
|
|
207
|
+
content: [{ type: "text", text: `worker ${agentId} wait completed: ${outcome.status}` }],
|
|
208
|
+
details: { kind: "wait", agentId, agentStatus: outcome.status },
|
|
209
|
+
};
|
|
210
|
+
}
|
|
150
211
|
if (input.action === "review") {
|
|
151
|
-
if (!input.laneId) {
|
|
212
|
+
if (!input.laneId?.trim()) {
|
|
152
213
|
return {
|
|
153
214
|
content: [{ type: "text", text: "review action requires laneId" }],
|
|
154
215
|
details: { kind: "review", reviewed: false, reason: "missing_lane_id" },
|
|
155
216
|
};
|
|
156
217
|
}
|
|
218
|
+
if (input.laneId.length > MAX_WORKER_CONTROL_ID_CHARS) {
|
|
219
|
+
return {
|
|
220
|
+
content: [{ type: "text", text: "review action laneId is invalid" }],
|
|
221
|
+
details: { kind: "review", reviewed: false, reason: "invalid_lane_id" },
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
const laneId = input.laneId.trim();
|
|
157
225
|
if (!deps.acknowledgeWorkerReview) {
|
|
158
226
|
return {
|
|
159
227
|
content: [{ type: "text", text: "review acknowledgement is not available in this session" }],
|
|
160
228
|
details: { kind: "review", reviewed: false, reason: "review_unsupported" },
|
|
161
229
|
};
|
|
162
230
|
}
|
|
163
|
-
const outcome = deps.acknowledgeWorkerReview(
|
|
231
|
+
const outcome = deps.acknowledgeWorkerReview(laneId);
|
|
164
232
|
if (!outcome.ok) {
|
|
165
233
|
return {
|
|
166
|
-
content: [
|
|
167
|
-
|
|
168
|
-
],
|
|
169
|
-
details: { kind: "review", laneId: input.laneId, reviewed: false, reason: outcome.reason },
|
|
234
|
+
content: [{ type: "text", text: `review not acknowledged (${laneId}): ${outcome.reason}` }],
|
|
235
|
+
details: { kind: "review", laneId, reviewed: false, reason: outcome.reason },
|
|
170
236
|
};
|
|
171
237
|
}
|
|
172
238
|
return {
|
|
173
239
|
content: [
|
|
174
240
|
{
|
|
175
241
|
type: "text",
|
|
176
|
-
text: `reviewed ${
|
|
242
|
+
text: `reviewed ${laneId} at ${outcome.reviewedAt} — unreviewed-mutation notice cleared`,
|
|
177
243
|
},
|
|
178
244
|
],
|
|
179
245
|
details: {
|
|
180
246
|
kind: "review",
|
|
181
|
-
laneId
|
|
247
|
+
laneId,
|
|
182
248
|
reviewed: true,
|
|
183
249
|
reviewedAt: outcome.reviewedAt,
|
|
184
250
|
},
|
|
@@ -189,8 +255,21 @@ export function createDelegateStatusToolDefinition(deps) {
|
|
|
189
255
|
// Sticky: computed over ALL worker records, not just the recent window below — an
|
|
190
256
|
// unreviewed mutation must stay visible no matter how much later lane churn buries it.
|
|
191
257
|
const unreviewedRecords = records.filter((record) => isUnreviewed(claims.get(record.laneId)));
|
|
192
|
-
if (input.laneId) {
|
|
193
|
-
|
|
258
|
+
if (input.laneId !== undefined) {
|
|
259
|
+
if (input.laneId.length > MAX_WORKER_CONTROL_ID_CHARS) {
|
|
260
|
+
return {
|
|
261
|
+
content: [{ type: "text", text: "worker lane id is invalid" }],
|
|
262
|
+
details: { kind: "error", reason: "invalid_lane_id" },
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
const laneId = input.laneId.trim();
|
|
266
|
+
if (!laneId) {
|
|
267
|
+
return {
|
|
268
|
+
content: [{ type: "text", text: "worker lane id is invalid" }],
|
|
269
|
+
details: { kind: "error", reason: "invalid_lane_id" },
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
const record = records.find((candidate) => candidate.laneId === laneId);
|
|
194
273
|
if (!record) {
|
|
195
274
|
return {
|
|
196
275
|
content: [{ type: "text", text: "unknown_worker_lane" }],
|
|
@@ -216,17 +295,20 @@ export function createDelegateStatusToolDefinition(deps) {
|
|
|
216
295
|
const queued = records.filter((record) => record.status === "queued").length;
|
|
217
296
|
const running = records.filter((record) => record.status === "running").length;
|
|
218
297
|
const terminal = records.length - queued - running;
|
|
219
|
-
const recent = recentRecords.map((record) => formatRecord(record, claims.get(record.laneId)));
|
|
298
|
+
const recent = recentRecords.map((record) => formatRecord(record, claims.get(record.laneId)).slice(0, 2_048));
|
|
220
299
|
const olderUnreviewed = unreviewedRecords.filter((record) => !recentLaneIds.has(record.laneId));
|
|
221
300
|
const displayedRecords = [...recentRecords, ...olderUnreviewed.slice(0, 10)].filter((record, index, all) => all.findIndex((candidate) => candidate.laneId === record.laneId) === index);
|
|
222
301
|
const olderUnreviewedText = olderUnreviewed.length > 0
|
|
223
302
|
? `\n\nOlder unreviewed workers (outside the recent list):\n${olderUnreviewed
|
|
224
|
-
.
|
|
303
|
+
.slice(0, 10)
|
|
304
|
+
.map((record) => formatRecord(record, claims.get(record.laneId)).slice(0, 2_048))
|
|
225
305
|
.join("\n\n")}`
|
|
226
306
|
: "";
|
|
227
307
|
const overviewLines = [`workers: ${running} running, ${queued} queued, ${terminal} terminal`];
|
|
228
308
|
if (unreviewedRecords.length > 0) {
|
|
229
|
-
|
|
309
|
+
const visibleUnreviewedIds = unreviewedRecords.slice(0, 64).map((record) => record.laneId);
|
|
310
|
+
const omitted = unreviewedRecords.length - visibleUnreviewedIds.length;
|
|
311
|
+
overviewLines.push(`${unreviewedRecords.length} unreviewed worker mutation${unreviewedRecords.length === 1 ? "" : "s"} pending review: ${visibleUnreviewedIds.join(", ")}${omitted > 0 ? `, and ${omitted} more` : ""}. Acknowledge each with delegate_status { laneId, action: "review" }.`);
|
|
230
312
|
}
|
|
231
313
|
const overview = overviewLines.join("\n");
|
|
232
314
|
return {
|
|
@@ -245,7 +327,7 @@ export function createDelegateStatusToolDefinition(deps) {
|
|
|
245
327
|
running,
|
|
246
328
|
terminal,
|
|
247
329
|
unreviewedCount: unreviewedRecords.length,
|
|
248
|
-
unreviewedLaneIds: unreviewedRecords.map((record) => record.laneId),
|
|
330
|
+
unreviewedLaneIds: unreviewedRecords.slice(0, 64).map((record) => record.laneId),
|
|
249
331
|
lanes: displayedRecords.map((record) => laneView(record, claims.get(record.laneId))),
|
|
250
332
|
},
|
|
251
333
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate-status.js","sourceRoot":"","sources":["../../../src/core/tools/delegate-status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EACN,sBAAsB,EACtB,2BAA2B,GAG3B,MAAM,0BAA0B,CAAC;AAElC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CACzB;IACC,MAAM,EAAE,IAAI,CAAC,QAAQ,CACpB,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,0EAA0E,EAAE,CAAC,CACxG;IACD,MAAM,EAAE,IAAI,CAAC,QAAQ,CACpB,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;QACtB,WAAW,EACV,0JAA0J;KAC3J,CAAC,CACF;CACD,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B,CAAC;AAgDF,2FAA2F;AAC3F,SAAS,YAAY,CAAC,KAA8B,EAAW;IAC9D,OAAO,KAAK,EAAE,oBAAoB,KAAK,IAAI,IAAI,KAAK,CAAC,gBAAgB,KAAK,SAAS,CAAC;AAAA,CACpF;AAED;8FAC4F;AAC5F,SAAS,qBAAqB,CAAC,MAAkB,EAAW;IAC3D,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ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M;oBACpB,MAAM;oBACN,OAAO;oBACP,QAAQ;oBACR,eAAe,EAAE,iBAAiB,CAAC,MAAM;oBACzC,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;oBACnE,KAAK,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;iBACpF;aACD,CAAC;QAAA,CACF;KACD,CAAC;AAAA,CACF","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { WorkerClaim } from \"../autonomy/contracts.ts\";\nimport type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\temptyOrchestrationCall,\n\tOrchestrationPanelComponent,\n\ttype OrchestrationPanelModel,\n\ttype OrchestrationPanelRow,\n} from \"./orchestration-panel.ts\";\n\nconst schema = Type.Object(\n\t{\n\t\tlaneId: Type.Optional(\n\t\t\tType.String({ description: \"Worker lane id to inspect. Omit it for a recent-session status overview.\" }),\n\t\t),\n\t\taction: Type.Optional(\n\t\t\tType.Literal(\"review\", {\n\t\t\t\tdescription:\n\t\t\t\t\t'Pass \"review\" together with laneId to durably acknowledge that worker\\'s unreviewed mutation, clearing its sticky notice. Not required to read a status.',\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\ntype Input = Static<typeof schema>;\n\nexport interface DelegateStatusLaneView {\n\tlaneId: string;\n\tlabel?: string;\n\tprofileId?: string;\n\ttype: LaneRecord[\"type\"];\n\tstatus: LaneRecord[\"status\"];\n\treasonCode?: string;\n\tunreviewed: boolean;\n}\n\nexport interface DelegateStatusToolDetails {\n\tkind: \"overview\" | \"lane\" | \"review\" | \"error\";\n\tcount?: number;\n\tqueued?: number;\n\trunning?: number;\n\tterminal?: number;\n\tunreviewedCount?: number;\n\tunreviewedLaneIds?: readonly string[];\n\tlanes?: readonly DelegateStatusLaneView[];\n\tlaneId?: string;\n\tstatus?: LaneRecord[\"status\"];\n\tunreviewed?: boolean;\n\treviewed?: boolean;\n\treviewedAt?: string;\n\treason?: string;\n\tclaimSummary?: string;\n\tchangedFiles?: readonly string[];\n\tblockers?: readonly string[];\n}\n\nexport type AcknowledgeWorkerReviewResult =\n\t| { ok: true; requestId: string; reviewedAt: string }\n\t| { ok: false; reason: \"unknown_worker_claim\" | \"not_flagged\" | \"already_reviewed\" };\n\nexport interface DelegateStatusDependencies {\n\tgetLaneRecords(): LaneRecord[];\n\tgetWorkerClaimSnapshots(): WorkerClaim[];\n\t/**\n\t * Durably acknowledge an unreviewed worker mutation (parentReviewRequired), clearing its\n\t * sticky notice. Optional so callers without durable persistence wired still type-check; without\n\t * it the \"review\" action reports itself unsupported instead of silently no-op'ing.\n\t */\n\tacknowledgeWorkerReview?(requestId: string): AcknowledgeWorkerReviewResult;\n}\n\n/** A worker claim flagged parent_review_required whose mutation has not yet been acked. */\nfunction isUnreviewed(claim: WorkerClaim | undefined): boolean {\n\treturn claim?.parentReviewRequired === true && claim.parentReviewedAt === undefined;\n}\n\n/** In-process `worker` lanes and out-of-process `tmux-worker` lanes are both delegated work whose\n * output is an untrusted claim under the same review machinery — surfaced together here. */\nfunction isDelegatedWorkerLane(record: LaneRecord): boolean {\n\treturn record.type === \"worker\" || record.type === \"tmux-worker\";\n}\n\nfunction formatRecord(record: LaneRecord, claim: WorkerClaim | undefined): string {\n\tconst lines = [`${record.laneId}: ${record.status}${record.reasonCode ? ` (${record.reasonCode})` : \"\"}`];\n\tif (!claim) return lines.join(\"\\n\");\n\tlines.push(`usageReportId: ${claim.usageReportId ?? \"none\"}`);\n\tif (isUnreviewed(claim)) {\n\t\tlines.push(\n\t\t\t`UNREVIEWED MUTATION - this worker's claim requires explicit parent review. Acknowledge with delegate_status { laneId: \"${record.laneId}\", action: \"review\" }.`,\n\t\t);\n\t} else if (claim.parentReviewRequired && claim.parentReviewedAt) {\n\t\tlines.push(`reviewed at ${claim.parentReviewedAt}`);\n\t}\n\tlines.push(\"UNTRUSTED worker output — verify before acting on it:\");\n\tlines.push(claim.summary.slice(0, 8000));\n\tif (claim.changedFiles.length > 0) lines.push(`changed files: ${claim.changedFiles.join(\", \")}`);\n\tif (claim.blockers?.length) lines.push(`blockers: ${claim.blockers.join(\"; \")}`);\n\treturn lines.join(\"\\n\").slice(0, 16 * 1024);\n}\n\nfunction laneView(record: LaneRecord, claim: WorkerClaim | undefined): DelegateStatusLaneView {\n\treturn {\n\t\tlaneId: record.laneId,\n\t\t...(record.label ? { label: record.label } : {}),\n\t\t...(record.profileId ? { profileId: record.profileId } : {}),\n\t\ttype: record.type,\n\t\tstatus: record.status,\n\t\t...(record.reasonCode ? { reasonCode: record.reasonCode } : {}),\n\t\tunreviewed: isUnreviewed(claim),\n\t};\n}\n\nfunction lanePanelRow(view: DelegateStatusLaneView, details?: DelegateStatusToolDetails): OrchestrationPanelRow {\n\tconst meta = [\n\t\tview.label ? view.laneId : undefined,\n\t\tview.profileId ? `profile ${view.profileId}` : undefined,\n\t\tview.type === \"tmux-worker\" ? \"tmux\" : undefined,\n\t\tview.reasonCode,\n\t\tview.unreviewed ? \"review required\" : undefined,\n\t].filter((value): value is string => value !== undefined);\n\tconst expandedDetails = [\n\t\tdetails?.claimSummary ? `untrusted claim: ${details.claimSummary}` : undefined,\n\t\tdetails?.changedFiles?.length ? `changed: ${details.changedFiles.join(\", \")}` : undefined,\n\t\t...(details?.blockers ?? []).map((blocker) => `blocker: ${blocker}`),\n\t].filter((value): value is string => value !== undefined);\n\treturn {\n\t\tstatus: view.status,\n\t\tlabel: view.label ?? view.laneId,\n\t\tmeta,\n\t\tdetails: expandedDetails,\n\t};\n}\n\nfunction delegateStatusPanelModel(details: DelegateStatusToolDetails | undefined): OrchestrationPanelModel {\n\tif (!details) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"status\",\n\t\t\tstatus: \"idle\",\n\t\t\temptyText: \"No structured worker status was retained.\",\n\t\t};\n\t}\n\tif (details.kind === \"error\") {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"status\",\n\t\t\tstatus: \"error\",\n\t\t\temptyText: details.reason ?? \"Worker status is unavailable.\",\n\t\t};\n\t}\n\tif (details.kind === \"review\") {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: details.reviewed ? \"reviewed\" : \"review required\",\n\t\t\tstatus: details.reviewed ? \"success\" : \"warning\",\n\t\t\trows: details.laneId\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: details.reviewed ? \"reviewed\" : \"blocked\",\n\t\t\t\t\t\t\tlabel: details.laneId,\n\t\t\t\t\t\t\tmeta: details.reviewedAt ? [`reviewed ${details.reviewedAt}`] : undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: undefined,\n\t\t\temptyText: details.reason,\n\t\t};\n\t}\n\tconst lanes = details.lanes ?? [];\n\tconst rows = lanes.map((view) => lanePanelRow(view, details.kind === \"lane\" ? details : undefined));\n\tconst running = details.running ?? lanes.filter((lane) => lane.status === \"running\").length;\n\tconst queued = details.queued ?? lanes.filter((lane) => lane.status === \"queued\").length;\n\tconst terminal = details.terminal ?? lanes.length - running - queued;\n\tconst unreviewed = details.unreviewedCount ?? lanes.filter((lane) => lane.unreviewed).length;\n\treturn {\n\t\tlabel: \"workers\",\n\t\taction: details.kind === \"lane\" ? \"lane\" : \"status\",\n\t\tstatus: unreviewed > 0 ? \"warning\" : running + queued > 0 ? \"running\" : lanes.length > 0 ? \"success\" : \"idle\",\n\t\tsummary: [\n\t\t\trunning ? `${running} running` : undefined,\n\t\t\tqueued ? `${queued} queued` : undefined,\n\t\t\tterminal ? `${terminal} terminal` : undefined,\n\t\t].filter((value): value is string => value !== undefined),\n\t\trows,\n\t\temptyText: \"No worker lanes.\",\n\t\tnotices:\n\t\t\tunreviewed > 0\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: \"warning\",\n\t\t\t\t\t\t\ttext: `${unreviewed} worker mutation${unreviewed === 1 ? \"\" : \"s\"} awaiting parent review.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: undefined,\n\t};\n}\n\nexport function createDelegateStatusToolDefinition(deps: DelegateStatusDependencies): ToolDefinition {\n\treturn {\n\t\tname: \"delegate_status\",\n\t\tlabel: \"delegate_status\",\n\t\tdescription:\n\t\t\t'Inspect queued, running, and terminal workers in this session, retrieve one worker\\'s bounded, explicitly untrusted claim, or acknowledge (action: \"review\") an unreviewed worker mutation.',\n\t\tpromptSnippet:\n\t\t\t\"Inspect delegated workers after a terminal handoff without receiving a late transcript injection; acknowledge unreviewed mutations.\",\n\t\tparameters: schema,\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) return emptyOrchestrationCall();\n\t\t\tconst details = result.details as DelegateStatusToolDetails | undefined;\n\t\t\tif (!expanded && details && details.kind !== \"error\" && !(details.kind === \"review\" && !details.reviewed)) {\n\t\t\t\treturn emptyOrchestrationCall();\n\t\t\t}\n\t\t\treturn new OrchestrationPanelComponent(theme, delegateStatusPanelModel(details), expanded);\n\t\t},\n\t\tasync execute(_toolCallId, input: Input) {\n\t\t\tif (input.action === \"review\") {\n\t\t\t\tif (!input.laneId) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"review action requires laneId\" }],\n\t\t\t\t\t\tdetails: { kind: \"review\", reviewed: false, reason: \"missing_lane_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (!deps.acknowledgeWorkerReview) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"review acknowledgement is not available in this session\" }],\n\t\t\t\t\t\tdetails: { kind: \"review\", reviewed: false, reason: \"review_unsupported\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst outcome = deps.acknowledgeWorkerReview(input.laneId);\n\t\t\t\tif (!outcome.ok) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: `review not acknowledged (${input.laneId}): ${outcome.reason}` },\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { kind: \"review\", laneId: input.laneId, reviewed: false, reason: outcome.reason },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `reviewed ${input.laneId} at ${outcome.reviewedAt} — unreviewed-mutation notice cleared`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tkind: \"review\",\n\t\t\t\t\t\tlaneId: input.laneId,\n\t\t\t\t\t\treviewed: true,\n\t\t\t\t\t\treviewedAt: outcome.reviewedAt,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst records = deps.getLaneRecords().filter(isDelegatedWorkerLane);\n\t\t\tconst claims = new Map(deps.getWorkerClaimSnapshots().map((claim) => [claim.requestId, claim]));\n\t\t\t// Sticky: computed over ALL worker records, not just the recent window below — an\n\t\t\t// unreviewed mutation must stay visible no matter how much later lane churn buries it.\n\t\t\tconst unreviewedRecords = records.filter((record) => isUnreviewed(claims.get(record.laneId)));\n\n\t\t\tif (input.laneId) {\n\t\t\t\tconst record = records.find((candidate) => candidate.laneId === input.laneId);\n\t\t\t\tif (!record) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"unknown_worker_lane\" }],\n\t\t\t\t\t\tdetails: { kind: \"error\", reason: \"unknown_worker_lane\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: formatRecord(record, claims.get(record.laneId)) }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tkind: \"lane\",\n\t\t\t\t\t\tlaneId: record.laneId,\n\t\t\t\t\t\tstatus: record.status,\n\t\t\t\t\t\tunreviewed: isUnreviewed(claims.get(record.laneId)),\n\t\t\t\t\t\tlanes: [laneView(record, claims.get(record.laneId))],\n\t\t\t\t\t\tclaimSummary: claims.get(record.laneId)?.summary.slice(0, 8_000),\n\t\t\t\t\t\tchangedFiles: claims.get(record.laneId)?.changedFiles.slice(0, 64),\n\t\t\t\t\t\tblockers: claims.get(record.laneId)?.blockers?.slice(0, 16),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst recentRecords = records.slice(-10);\n\t\t\tconst recentLaneIds = new Set(recentRecords.map((record) => record.laneId));\n\t\t\tconst queued = records.filter((record) => record.status === \"queued\").length;\n\t\t\tconst running = records.filter((record) => record.status === \"running\").length;\n\t\t\tconst terminal = records.length - queued - running;\n\t\t\tconst recent = recentRecords.map((record) => formatRecord(record, claims.get(record.laneId)));\n\t\t\tconst olderUnreviewed = unreviewedRecords.filter((record) => !recentLaneIds.has(record.laneId));\n\t\t\tconst displayedRecords = [...recentRecords, ...olderUnreviewed.slice(0, 10)].filter(\n\t\t\t\t(record, index, all) => all.findIndex((candidate) => candidate.laneId === record.laneId) === index,\n\t\t\t);\n\t\t\tconst olderUnreviewedText =\n\t\t\t\tolderUnreviewed.length > 0\n\t\t\t\t\t? `\\n\\nOlder unreviewed workers (outside the recent list):\\n${olderUnreviewed\n\t\t\t\t\t\t\t.map((record) => formatRecord(record, claims.get(record.laneId)))\n\t\t\t\t\t\t\t.join(\"\\n\\n\")}`\n\t\t\t\t\t: \"\";\n\t\t\tconst overviewLines = [`workers: ${running} running, ${queued} queued, ${terminal} terminal`];\n\t\t\tif (unreviewedRecords.length > 0) {\n\t\t\t\toverviewLines.push(\n\t\t\t\t\t`${unreviewedRecords.length} unreviewed worker mutation${unreviewedRecords.length === 1 ? \"\" : \"s\"} pending review: ${unreviewedRecords.map((record) => record.laneId).join(\", \")}. Acknowledge each with delegate_status { laneId, action: \"review\" }.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst overview = overviewLines.join(\"\\n\");\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\trecent.length > 0\n\t\t\t\t\t\t\t\t? `${overview}\\n\\n${recent.join(\"\\n\\n\")}${olderUnreviewedText}`.slice(0, 16 * 1024)\n\t\t\t\t\t\t\t\t: \"No worker lanes.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: {\n\t\t\t\t\tkind: \"overview\",\n\t\t\t\t\tcount: recent.length,\n\t\t\t\t\tqueued,\n\t\t\t\t\trunning,\n\t\t\t\t\tterminal,\n\t\t\t\t\tunreviewedCount: unreviewedRecords.length,\n\t\t\t\t\tunreviewedLaneIds: unreviewedRecords.map((record) => record.laneId),\n\t\t\t\t\tlanes: displayedRecords.map((record) => laneView(record, claims.get(record.laneId))),\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"delegate-status.js","sourceRoot":"","sources":["../../../src/core/tools/delegate-status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAK5C,OAAO,EACN,sBAAsB,EACtB,2BAA2B,GAG3B,MAAM,0BAA0B,CAAC;AAElC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAExC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CACzB;IACC,OAAO,EAAE,IAAI,CAAC,QAAQ,CACrB,IAAI,CAAC,MAAM,CAAC;QACX,SAAS,EAAE,2BAA2B;QACtC,WAAW,EAAE,q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,CAAC,MAAM,8BAA8B,iBAAiB,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,oBAAoB,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,uEAAuE,CACzQ,CAAC;YACH,CAAC;YACD,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1C,OAAO;gBACN,OAAO,EAAE;oBACR;wBACC,IAAI,EAAE,MAAe;wBACrB,IAAI,EACH,MAAM,CAAC,MAAM,GAAG,CAAC;4BAChB,CAAC,CAAC,GAAG,QAAQ,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,mBAAmB,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC;4BACnF,CAAC,CAAC,kBAAkB;qBACtB;iBACD;gBACD,OAAO,EAAE;oBACR,IAAI,EAAE,UAAU;oBAChB,KAAK,EAAE,MAAM,CAAC,MAAM;oBACpB,MAAM;oBACN,OAAO;oBACP,QAAQ;oBACR,eAAe,EAAE,iBAAiB,CAAC,MAAM;oBACzC,iBAAiB,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;oBAChF,KAAK,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;iBACpF;aACD,CAAC;QAAA,CACF;KACD,CAAC;AAAA,CACF","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { WorkerClaim } from \"../autonomy/contracts.ts\";\nimport type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { WorkerAgentControlPort } from \"../delegation/worker-agent-control.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\temptyOrchestrationCall,\n\tOrchestrationPanelComponent,\n\ttype OrchestrationPanelModel,\n\ttype OrchestrationPanelRow,\n} from \"./orchestration-panel.ts\";\n\nconst MAX_WORKER_CONTROL_ID_CHARS = 512;\n\nconst schema = Type.Object(\n\t{\n\t\tagentId: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tmaxLength: MAX_WORKER_CONTROL_ID_CHARS,\n\t\t\t\tdescription: \"Stable logical worker id returned by delegate start; required only for action wait.\",\n\t\t\t}),\n\t\t),\n\t\tlaneId: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tmaxLength: MAX_WORKER_CONTROL_ID_CHARS,\n\t\t\t\tdescription: \"Worker lane id to inspect. Omit it for a recent-session status overview.\",\n\t\t\t}),\n\t\t),\n\t\taction: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tenum: [\"review\", \"wait\"],\n\t\t\t\tdescription:\n\t\t\t\t\t'Pass \"review\" together with laneId to durably acknowledge that worker\\'s unreviewed mutation, clearing its sticky notice. Pass \"wait\" with agentId for one event-driven state change; do not poll.',\n\t\t\t}),\n\t\t),\n\t\ttimeoutMs: Type.Optional(\n\t\t\tType.Integer({\n\t\t\t\tminimum: 0,\n\t\t\t\tmaximum: 300_000,\n\t\t\t\tdescription: \"Optional bounded event-driven wait timeout in milliseconds.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\ntype Input = Static<typeof schema>;\n\nexport interface DelegateStatusLaneView {\n\tlaneId: string;\n\tlabel?: string;\n\tprofileId?: string;\n\ttype: LaneRecord[\"type\"];\n\tstatus: LaneRecord[\"status\"];\n\treasonCode?: string;\n\tunreviewed: boolean;\n}\n\nexport interface DelegateStatusToolDetails {\n\tkind: \"overview\" | \"lane\" | \"review\" | \"wait\" | \"error\";\n\tcount?: number;\n\tqueued?: number;\n\trunning?: number;\n\tterminal?: number;\n\tunreviewedCount?: number;\n\tunreviewedLaneIds?: readonly string[];\n\tlanes?: readonly DelegateStatusLaneView[];\n\tlaneId?: string;\n\tstatus?: LaneRecord[\"status\"];\n\tunreviewed?: boolean;\n\treviewed?: boolean;\n\treviewedAt?: string;\n\treason?: string;\n\tclaimSummary?: string;\n\tchangedFiles?: readonly string[];\n\tblockers?: readonly string[];\n\tagentId?: string;\n\tagentStatus?: \"active\" | \"suspended\" | \"idle\" | \"unknown\";\n}\n\nexport type AcknowledgeWorkerReviewResult =\n\t| { ok: true; requestId: string; reviewedAt: string }\n\t| { ok: false; reason: \"unknown_worker_claim\" | \"not_flagged\" | \"already_reviewed\" };\n\nexport interface DelegateStatusDependencies {\n\tgetLaneRecords(): LaneRecord[];\n\tgetWorkerClaimSnapshots(): WorkerClaim[];\n\t/**\n\t * Durably acknowledge an unreviewed worker mutation (parentReviewRequired), clearing its\n\t * sticky notice. Optional so callers without durable persistence wired still type-check; without\n\t * it the \"review\" action reports itself unsupported instead of silently no-op'ing.\n\t */\n\tacknowledgeWorkerReview?(requestId: string): AcknowledgeWorkerReviewResult;\n\t/** Event-driven logical-worker controls; callers must not poll. */\n\tworkerAgentControl?: Pick<WorkerAgentControlPort, \"waitForWorkerAgent\">;\n}\n\n/** A worker claim flagged parent_review_required whose mutation has not yet been acked. */\nfunction isUnreviewed(claim: WorkerClaim | undefined): boolean {\n\treturn claim?.parentReviewRequired === true && claim.parentReviewedAt === undefined;\n}\n\n/** In-process `worker` lanes and out-of-process `tmux-worker` lanes are both delegated work whose\n * output is an untrusted claim under the same review machinery — surfaced together here. */\nfunction isDelegatedWorkerLane(record: LaneRecord): boolean {\n\treturn record.type === \"worker\" || record.type === \"tmux-worker\";\n}\n\nfunction formatRecord(record: LaneRecord, claim: WorkerClaim | undefined): string {\n\tconst lines = [`${record.laneId}: ${record.status}${record.reasonCode ? ` (${record.reasonCode})` : \"\"}`];\n\tif (!claim) return lines.join(\"\\n\");\n\tlines.push(`usageReportId: ${claim.usageReportId ?? \"none\"}`);\n\tif (isUnreviewed(claim)) {\n\t\tlines.push(\n\t\t\t`UNREVIEWED MUTATION - this worker's claim requires explicit parent review. Acknowledge with delegate_status { laneId: \"${record.laneId}\", action: \"review\" }.`,\n\t\t);\n\t} else if (claim.parentReviewRequired && claim.parentReviewedAt) {\n\t\tlines.push(`reviewed at ${claim.parentReviewedAt}`);\n\t}\n\tlines.push(\"UNTRUSTED worker output — verify before acting on it:\");\n\tlines.push(claim.summary.slice(0, 8000));\n\tif (claim.changedFiles.length > 0) lines.push(`changed files: ${claim.changedFiles.join(\", \")}`);\n\tif (claim.blockers?.length) lines.push(`blockers: ${claim.blockers.join(\"; \")}`);\n\treturn lines.join(\"\\n\").slice(0, 16 * 1024);\n}\n\nfunction laneView(record: LaneRecord, claim: WorkerClaim | undefined): DelegateStatusLaneView {\n\treturn {\n\t\tlaneId: record.laneId,\n\t\t...(record.label ? { label: record.label } : {}),\n\t\t...(record.profileId ? { profileId: record.profileId } : {}),\n\t\ttype: record.type,\n\t\tstatus: record.status,\n\t\t...(record.reasonCode ? { reasonCode: record.reasonCode } : {}),\n\t\tunreviewed: isUnreviewed(claim),\n\t};\n}\n\nfunction lanePanelRow(view: DelegateStatusLaneView, details?: DelegateStatusToolDetails): OrchestrationPanelRow {\n\tconst meta = [\n\t\tview.label ? view.laneId : undefined,\n\t\tview.profileId ? `profile ${view.profileId}` : undefined,\n\t\tview.type === \"tmux-worker\" ? \"tmux\" : undefined,\n\t\tview.reasonCode,\n\t\tview.unreviewed ? \"review required\" : undefined,\n\t].filter((value): value is string => value !== undefined);\n\tconst expandedDetails = [\n\t\tdetails?.claimSummary ? `untrusted claim: ${details.claimSummary}` : undefined,\n\t\tdetails?.changedFiles?.length ? `changed: ${details.changedFiles.join(\", \")}` : undefined,\n\t\t...(details?.blockers ?? []).map((blocker) => `blocker: ${blocker}`),\n\t].filter((value): value is string => value !== undefined);\n\treturn {\n\t\tstatus: view.status,\n\t\tlabel: view.label ?? view.laneId,\n\t\tmeta,\n\t\tdetails: expandedDetails,\n\t};\n}\n\nfunction delegateStatusPanelModel(details: DelegateStatusToolDetails | undefined): OrchestrationPanelModel {\n\tif (!details) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"status\",\n\t\t\tstatus: \"idle\",\n\t\t\temptyText: \"No structured worker status was retained.\",\n\t\t};\n\t}\n\tif (details.kind === \"error\") {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"status\",\n\t\t\tstatus: \"error\",\n\t\t\temptyText: details.reason ?? \"Worker status is unavailable.\",\n\t\t};\n\t}\n\tif (details.kind === \"review\") {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: details.reviewed ? \"reviewed\" : \"review required\",\n\t\t\tstatus: details.reviewed ? \"success\" : \"warning\",\n\t\t\trows: details.laneId\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: details.reviewed ? \"reviewed\" : \"blocked\",\n\t\t\t\t\t\t\tlabel: details.laneId,\n\t\t\t\t\t\t\tmeta: details.reviewedAt ? [`reviewed ${details.reviewedAt}`] : undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: undefined,\n\t\t\temptyText: details.reason,\n\t\t};\n\t}\n\tconst lanes = details.lanes ?? [];\n\tconst rows = lanes.map((view) => lanePanelRow(view, details.kind === \"lane\" ? details : undefined));\n\tconst running = details.running ?? lanes.filter((lane) => lane.status === \"running\").length;\n\tconst queued = details.queued ?? lanes.filter((lane) => lane.status === \"queued\").length;\n\tconst terminal = details.terminal ?? lanes.length - running - queued;\n\tconst unreviewed = details.unreviewedCount ?? lanes.filter((lane) => lane.unreviewed).length;\n\treturn {\n\t\tlabel: \"workers\",\n\t\taction: details.kind === \"lane\" ? \"lane\" : \"status\",\n\t\tstatus: unreviewed > 0 ? \"warning\" : running + queued > 0 ? \"running\" : lanes.length > 0 ? \"success\" : \"idle\",\n\t\tsummary: [\n\t\t\trunning ? `${running} running` : undefined,\n\t\t\tqueued ? `${queued} queued` : undefined,\n\t\t\tterminal ? `${terminal} terminal` : undefined,\n\t\t].filter((value): value is string => value !== undefined),\n\t\trows,\n\t\temptyText: \"No worker lanes.\",\n\t\tnotices:\n\t\t\tunreviewed > 0\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: \"warning\",\n\t\t\t\t\t\t\ttext: `${unreviewed} worker mutation${unreviewed === 1 ? \"\" : \"s\"} awaiting parent review.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: undefined,\n\t};\n}\n\nexport function createDelegateStatusToolDefinition(deps: DelegateStatusDependencies): ToolDefinition {\n\treturn {\n\t\tname: \"delegate_status\",\n\t\tlabel: \"delegate_status\",\n\t\tdescription:\n\t\t\t'Inspect queued, running, and terminal workers in this session, retrieve one worker\\'s bounded, explicitly untrusted claim, acknowledge (action: \"review\") an unreviewed worker mutation, or use action: \"wait\" with agentId for one event-driven update. Do not poll.',\n\t\tpromptSnippet:\n\t\t\t\"Inspect delegated workers after a terminal handoff without receiving a late transcript injection; acknowledge unreviewed mutations.\",\n\t\tparameters: schema,\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) return emptyOrchestrationCall();\n\t\t\tconst details = result.details as DelegateStatusToolDetails | undefined;\n\t\t\tif (!expanded && details && details.kind !== \"error\" && !(details.kind === \"review\" && !details.reviewed)) {\n\t\t\t\treturn emptyOrchestrationCall();\n\t\t\t}\n\t\t\treturn new OrchestrationPanelComponent(theme, delegateStatusPanelModel(details), expanded);\n\t\t},\n\t\tasync execute(_toolCallId, input: Input) {\n\t\t\tif (input.action !== undefined && input.action.length > 16) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"delegate_status action is invalid\" }],\n\t\t\t\t\tdetails: { kind: \"error\", reason: \"invalid_action\" },\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (input.action !== undefined && input.action !== \"review\" && input.action !== \"wait\") {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate_status action is invalid: ${input.action}` }],\n\t\t\t\t\tdetails: { kind: \"error\", reason: \"invalid_action\" },\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (input.action === \"wait\") {\n\t\t\t\tif (input.agentId !== undefined && input.agentId.length > MAX_WORKER_CONTROL_ID_CHARS) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"wait action agentId is invalid\" }],\n\t\t\t\t\t\tdetails: { kind: \"wait\" as const, reason: \"invalid_agent_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst agentId = input.agentId?.trim();\n\t\t\t\tif (!agentId) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"wait action requires agentId\" }],\n\t\t\t\t\t\tdetails: { kind: \"wait\", reason: \"missing_agent_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\tinput.timeoutMs !== undefined &&\n\t\t\t\t\t(!Number.isSafeInteger(input.timeoutMs) || input.timeoutMs < 0 || input.timeoutMs > 300_000)\n\t\t\t\t) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"wait action timeoutMs is invalid\" }],\n\t\t\t\t\t\tdetails: { kind: \"wait\", agentId, reason: \"invalid_timeout_ms\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (!deps.workerAgentControl) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: \"event-driven worker wait is not available in this session\" },\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { kind: \"wait\", agentId, reason: \"wait_unsupported\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst outcome = await deps.workerAgentControl.waitForWorkerAgent(agentId, input.timeoutMs);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `worker ${agentId} wait completed: ${outcome.status}` }],\n\t\t\t\t\tdetails: { kind: \"wait\", agentId, agentStatus: outcome.status },\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (input.action === \"review\") {\n\t\t\t\tif (!input.laneId?.trim()) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"review action requires laneId\" }],\n\t\t\t\t\t\tdetails: { kind: \"review\", reviewed: false, reason: \"missing_lane_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (input.laneId.length > MAX_WORKER_CONTROL_ID_CHARS) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"review action laneId is invalid\" }],\n\t\t\t\t\t\tdetails: { kind: \"review\" as const, reviewed: false, reason: \"invalid_lane_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst laneId = input.laneId.trim();\n\t\t\t\tif (!deps.acknowledgeWorkerReview) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"review acknowledgement is not available in this session\" }],\n\t\t\t\t\t\tdetails: { kind: \"review\", reviewed: false, reason: \"review_unsupported\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst outcome = deps.acknowledgeWorkerReview(laneId);\n\t\t\t\tif (!outcome.ok) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `review not acknowledged (${laneId}): ${outcome.reason}` }],\n\t\t\t\t\t\tdetails: { kind: \"review\", laneId, reviewed: false, reason: outcome.reason },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `reviewed ${laneId} at ${outcome.reviewedAt} — unreviewed-mutation notice cleared`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tkind: \"review\",\n\t\t\t\t\t\tlaneId,\n\t\t\t\t\t\treviewed: true,\n\t\t\t\t\t\treviewedAt: outcome.reviewedAt,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst records = deps.getLaneRecords().filter(isDelegatedWorkerLane);\n\t\t\tconst claims = new Map(deps.getWorkerClaimSnapshots().map((claim) => [claim.requestId, claim]));\n\t\t\t// Sticky: computed over ALL worker records, not just the recent window below — an\n\t\t\t// unreviewed mutation must stay visible no matter how much later lane churn buries it.\n\t\t\tconst unreviewedRecords = records.filter((record) => isUnreviewed(claims.get(record.laneId)));\n\n\t\t\tif (input.laneId !== undefined) {\n\t\t\t\tif (input.laneId.length > MAX_WORKER_CONTROL_ID_CHARS) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"worker lane id is invalid\" }],\n\t\t\t\t\t\tdetails: { kind: \"error\" as const, reason: \"invalid_lane_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst laneId = input.laneId.trim();\n\t\t\t\tif (!laneId) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"worker lane id is invalid\" }],\n\t\t\t\t\t\tdetails: { kind: \"error\" as const, reason: \"invalid_lane_id\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst record = records.find((candidate) => candidate.laneId === laneId);\n\t\t\t\tif (!record) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"unknown_worker_lane\" }],\n\t\t\t\t\t\tdetails: { kind: \"error\", reason: \"unknown_worker_lane\" },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: formatRecord(record, claims.get(record.laneId)) }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tkind: \"lane\",\n\t\t\t\t\t\tlaneId: record.laneId,\n\t\t\t\t\t\tstatus: record.status,\n\t\t\t\t\t\tunreviewed: isUnreviewed(claims.get(record.laneId)),\n\t\t\t\t\t\tlanes: [laneView(record, claims.get(record.laneId))],\n\t\t\t\t\t\tclaimSummary: claims.get(record.laneId)?.summary.slice(0, 8_000),\n\t\t\t\t\t\tchangedFiles: claims.get(record.laneId)?.changedFiles.slice(0, 64),\n\t\t\t\t\t\tblockers: claims.get(record.laneId)?.blockers?.slice(0, 16),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst recentRecords = records.slice(-10);\n\t\t\tconst recentLaneIds = new Set(recentRecords.map((record) => record.laneId));\n\t\t\tconst queued = records.filter((record) => record.status === \"queued\").length;\n\t\t\tconst running = records.filter((record) => record.status === \"running\").length;\n\t\t\tconst terminal = records.length - queued - running;\n\t\t\tconst recent = recentRecords.map((record) => formatRecord(record, claims.get(record.laneId)).slice(0, 2_048));\n\t\t\tconst olderUnreviewed = unreviewedRecords.filter((record) => !recentLaneIds.has(record.laneId));\n\t\t\tconst displayedRecords = [...recentRecords, ...olderUnreviewed.slice(0, 10)].filter(\n\t\t\t\t(record, index, all) => all.findIndex((candidate) => candidate.laneId === record.laneId) === index,\n\t\t\t);\n\t\t\tconst olderUnreviewedText =\n\t\t\t\tolderUnreviewed.length > 0\n\t\t\t\t\t? `\\n\\nOlder unreviewed workers (outside the recent list):\\n${olderUnreviewed\n\t\t\t\t\t\t\t.slice(0, 10)\n\t\t\t\t\t\t\t.map((record) => formatRecord(record, claims.get(record.laneId)).slice(0, 2_048))\n\t\t\t\t\t\t\t.join(\"\\n\\n\")}`\n\t\t\t\t\t: \"\";\n\t\t\tconst overviewLines = [`workers: ${running} running, ${queued} queued, ${terminal} terminal`];\n\t\t\tif (unreviewedRecords.length > 0) {\n\t\t\t\tconst visibleUnreviewedIds = unreviewedRecords.slice(0, 64).map((record) => record.laneId);\n\t\t\t\tconst omitted = unreviewedRecords.length - visibleUnreviewedIds.length;\n\t\t\t\toverviewLines.push(\n\t\t\t\t\t`${unreviewedRecords.length} unreviewed worker mutation${unreviewedRecords.length === 1 ? \"\" : \"s\"} pending review: ${visibleUnreviewedIds.join(\", \")}${omitted > 0 ? `, and ${omitted} more` : \"\"}. Acknowledge each with delegate_status { laneId, action: \"review\" }.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst overview = overviewLines.join(\"\\n\");\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\trecent.length > 0\n\t\t\t\t\t\t\t\t? `${overview}\\n\\n${recent.join(\"\\n\\n\")}${olderUnreviewedText}`.slice(0, 16 * 1024)\n\t\t\t\t\t\t\t\t: \"No worker lanes.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: {\n\t\t\t\t\tkind: \"overview\",\n\t\t\t\t\tcount: recent.length,\n\t\t\t\t\tqueued,\n\t\t\t\t\trunning,\n\t\t\t\t\tterminal,\n\t\t\t\t\tunreviewedCount: unreviewedRecords.length,\n\t\t\t\t\tunreviewedLaneIds: unreviewedRecords.slice(0, 64).map((record) => record.laneId),\n\t\t\t\t\tlanes: displayedRecords.map((record) => laneView(record, claims.get(record.laneId))),\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|