@narumitw/pi-subagents 2.1.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -1250
- package/dist/child-communication-bridge.ts +136 -0
- package/dist/child-communication-bridge.ts.map +7 -0
- package/dist/chunks/chunk-UKTWUQRM.js +667 -0
- package/dist/chunks/chunk-UKTWUQRM.js.map +7 -0
- package/dist/index.ts +1448 -1598
- package/dist/index.ts.map +4 -4
- package/docs/design-principles.md +31 -0
- package/docs/ipc-transport-idea.md +103 -0
- package/docs/tools.md +109 -0
- package/package.json +11 -19
- package/src/broker-credentials.ts +71 -0
- package/src/child-communication-bridge.ts +153 -0
- package/src/child-communication-tools.ts +147 -0
- package/src/completion-renderer.ts +60 -0
- package/src/index.ts +1 -1
- package/src/message-broker.ts +628 -0
- package/src/model-output.ts +42 -0
- package/src/process.ts +688 -0
- package/src/runtime.ts +538 -0
- package/src/subagents.ts +33 -34
- package/src/tools.ts +416 -0
- package/src/types.ts +85 -0
- package/src/widget.ts +130 -0
- package/dist/chunks/auto-transport-FUUKFDIG.ts +0 -109
- package/dist/chunks/auto-transport-FUUKFDIG.ts.map +0 -7
- package/dist/chunks/capability-grant-PR72SWWS.ts +0 -19
- package/dist/chunks/capability-grant-PR72SWWS.ts.map +0 -7
- package/dist/chunks/child-peer-bridge.ts +0 -108
- package/dist/chunks/child-peer-bridge.ts.map +0 -7
- package/dist/chunks/chunk-2LMJU25E.ts +0 -1641
- package/dist/chunks/chunk-2LMJU25E.ts.map +0 -7
- package/dist/chunks/chunk-47SK2QYC.ts +0 -56
- package/dist/chunks/chunk-47SK2QYC.ts.map +0 -7
- package/dist/chunks/chunk-4AQSF7AS.ts +0 -29
- package/dist/chunks/chunk-4AQSF7AS.ts.map +0 -7
- package/dist/chunks/chunk-5DGRMKNV.ts +0 -126
- package/dist/chunks/chunk-5DGRMKNV.ts.map +0 -7
- package/dist/chunks/chunk-6H6TBBED.ts +0 -108
- package/dist/chunks/chunk-6H6TBBED.ts.map +0 -7
- package/dist/chunks/chunk-6KJ34M6S.ts +0 -159
- package/dist/chunks/chunk-6KJ34M6S.ts.map +0 -7
- package/dist/chunks/chunk-6NSJVPXX.ts +0 -480
- package/dist/chunks/chunk-6NSJVPXX.ts.map +0 -7
- package/dist/chunks/chunk-7AAJEUSL.ts +0 -238
- package/dist/chunks/chunk-7AAJEUSL.ts.map +0 -7
- package/dist/chunks/chunk-BFK2Z4ZF.ts +0 -189
- package/dist/chunks/chunk-BFK2Z4ZF.ts.map +0 -7
- package/dist/chunks/chunk-BOAXY55Y.ts +0 -153
- package/dist/chunks/chunk-BOAXY55Y.ts.map +0 -7
- package/dist/chunks/chunk-D4CR7T73.ts +0 -353
- package/dist/chunks/chunk-D4CR7T73.ts.map +0 -7
- package/dist/chunks/chunk-FEVPWRMU.ts +0 -300
- package/dist/chunks/chunk-FEVPWRMU.ts.map +0 -7
- package/dist/chunks/chunk-G6VZTCFH.ts +0 -70
- package/dist/chunks/chunk-G6VZTCFH.ts.map +0 -7
- package/dist/chunks/chunk-H3FP6DLR.ts +0 -160
- package/dist/chunks/chunk-H3FP6DLR.ts.map +0 -7
- package/dist/chunks/chunk-HA36LPCO.ts +0 -130
- package/dist/chunks/chunk-HA36LPCO.ts.map +0 -7
- package/dist/chunks/chunk-HOP5FXDT.ts +0 -27
- package/dist/chunks/chunk-HOP5FXDT.ts.map +0 -7
- package/dist/chunks/chunk-IGAMVWFN.ts +0 -139
- package/dist/chunks/chunk-IGAMVWFN.ts.map +0 -7
- package/dist/chunks/chunk-ILEQ27AL.ts +0 -45
- package/dist/chunks/chunk-ILEQ27AL.ts.map +0 -7
- package/dist/chunks/chunk-ITVWPNU4.ts +0 -819
- package/dist/chunks/chunk-ITVWPNU4.ts.map +0 -7
- package/dist/chunks/chunk-IWC32VPY.ts +0 -172
- package/dist/chunks/chunk-IWC32VPY.ts.map +0 -7
- package/dist/chunks/chunk-JSZIP73U.ts +0 -362
- package/dist/chunks/chunk-JSZIP73U.ts.map +0 -7
- package/dist/chunks/chunk-JU6LUNLP.ts +0 -380
- package/dist/chunks/chunk-JU6LUNLP.ts.map +0 -7
- package/dist/chunks/chunk-KMGKCEO4.ts +0 -38
- package/dist/chunks/chunk-KMGKCEO4.ts.map +0 -7
- package/dist/chunks/chunk-LASD73CM.ts +0 -339
- package/dist/chunks/chunk-LASD73CM.ts.map +0 -7
- package/dist/chunks/chunk-LEOYDZI3.ts +0 -22
- package/dist/chunks/chunk-LEOYDZI3.ts.map +0 -7
- package/dist/chunks/chunk-LL4LP2T7.ts +0 -737
- package/dist/chunks/chunk-LL4LP2T7.ts.map +0 -7
- package/dist/chunks/chunk-N2T5IN4X.ts +0 -18
- package/dist/chunks/chunk-N2T5IN4X.ts.map +0 -7
- package/dist/chunks/chunk-N7BLVXKK.ts +0 -73
- package/dist/chunks/chunk-N7BLVXKK.ts.map +0 -7
- package/dist/chunks/chunk-NLT67IZS.ts +0 -322
- package/dist/chunks/chunk-NLT67IZS.ts.map +0 -7
- package/dist/chunks/chunk-NTRPLF46.ts +0 -63
- package/dist/chunks/chunk-NTRPLF46.ts.map +0 -7
- package/dist/chunks/chunk-ONDTY4EL.ts +0 -91
- package/dist/chunks/chunk-ONDTY4EL.ts.map +0 -7
- package/dist/chunks/chunk-OVPHFGKO.ts +0 -1769
- package/dist/chunks/chunk-OVPHFGKO.ts.map +0 -7
- package/dist/chunks/chunk-P7OH4XMF.ts +0 -60
- package/dist/chunks/chunk-P7OH4XMF.ts.map +0 -7
- package/dist/chunks/chunk-PBZMBTNJ.ts +0 -422
- package/dist/chunks/chunk-PBZMBTNJ.ts.map +0 -7
- package/dist/chunks/chunk-PGLSFLYW.ts +0 -52
- package/dist/chunks/chunk-PGLSFLYW.ts.map +0 -7
- package/dist/chunks/chunk-RRR66UWR.ts +0 -28
- package/dist/chunks/chunk-RRR66UWR.ts.map +0 -7
- package/dist/chunks/chunk-RSUXZD6S.ts +0 -275
- package/dist/chunks/chunk-RSUXZD6S.ts.map +0 -7
- package/dist/chunks/chunk-RTCVYIZA.ts +0 -221
- package/dist/chunks/chunk-RTCVYIZA.ts.map +0 -7
- package/dist/chunks/chunk-RY2AEGMZ.ts +0 -34
- package/dist/chunks/chunk-RY2AEGMZ.ts.map +0 -7
- package/dist/chunks/chunk-SWGQLFSD.ts +0 -60
- package/dist/chunks/chunk-SWGQLFSD.ts.map +0 -7
- package/dist/chunks/chunk-TM2R67J3.ts +0 -52
- package/dist/chunks/chunk-TM2R67J3.ts.map +0 -7
- package/dist/chunks/chunk-TMZRHIIK.ts +0 -497
- package/dist/chunks/chunk-TMZRHIIK.ts.map +0 -7
- package/dist/chunks/chunk-TZ34IQ3M.ts +0 -59
- package/dist/chunks/chunk-TZ34IQ3M.ts.map +0 -7
- package/dist/chunks/chunk-UMBPMVJW.ts +0 -22
- package/dist/chunks/chunk-UMBPMVJW.ts.map +0 -7
- package/dist/chunks/chunk-VDG7LTYE.ts +0 -80
- package/dist/chunks/chunk-VDG7LTYE.ts.map +0 -7
- package/dist/chunks/chunk-X4NMONPE.ts +0 -73
- package/dist/chunks/chunk-X4NMONPE.ts.map +0 -7
- package/dist/chunks/chunk-YPJEN6NU.ts +0 -65
- package/dist/chunks/chunk-YPJEN6NU.ts.map +0 -7
- package/dist/chunks/chunk-YU53SHA7.ts +0 -328
- package/dist/chunks/chunk-YU53SHA7.ts.map +0 -7
- package/dist/chunks/completion-delivery-RSJU6BXL.ts +0 -17
- package/dist/chunks/completion-delivery-RSJU6BXL.ts.map +0 -7
- package/dist/chunks/config-status-FKGDECZ3.ts +0 -35
- package/dist/chunks/config-status-FKGDECZ3.ts.map +0 -7
- package/dist/chunks/config-ui-ABHYNGQ7.ts +0 -1212
- package/dist/chunks/config-ui-ABHYNGQ7.ts.map +0 -7
- package/dist/chunks/consult-LJU3IQY5.ts +0 -519
- package/dist/chunks/consult-LJU3IQY5.ts.map +0 -7
- package/dist/chunks/context-QDKLVQXE.ts +0 -11
- package/dist/chunks/context-QDKLVQXE.ts.map +0 -7
- package/dist/chunks/create-stateful-transport-JWC2EFYL.ts +0 -130
- package/dist/chunks/create-stateful-transport-JWC2EFYL.ts.map +0 -7
- package/dist/chunks/cwd-policy-NB6XZ5GF.ts +0 -17
- package/dist/chunks/cwd-policy-NB6XZ5GF.ts.map +0 -7
- package/dist/chunks/delegation-contract-LA56I5DT.ts +0 -24
- package/dist/chunks/delegation-contract-LA56I5DT.ts.map +0 -7
- package/dist/chunks/discovery-MIFB2U4Y.ts +0 -12
- package/dist/chunks/discovery-MIFB2U4Y.ts.map +0 -7
- package/dist/chunks/execution-Q2JZLKJA.ts +0 -4037
- package/dist/chunks/execution-Q2JZLKJA.ts.map +0 -7
- package/dist/chunks/in-process-transport-HJ6TZXC3.ts +0 -39
- package/dist/chunks/in-process-transport-HJ6TZXC3.ts.map +0 -7
- package/dist/chunks/inspect-UH2TKH6E.ts +0 -634
- package/dist/chunks/inspect-UH2TKH6E.ts.map +0 -7
- package/dist/chunks/peer-communication-KL36Z6CO.ts +0 -294
- package/dist/chunks/peer-communication-KL36Z6CO.ts.map +0 -7
- package/dist/chunks/persistence-UY3PY6E5.ts +0 -348
- package/dist/chunks/persistence-UY3PY6E5.ts.map +0 -7
- package/dist/chunks/registry-BT54L6CY.ts +0 -1445
- package/dist/chunks/registry-BT54L6CY.ts.map +0 -7
- package/dist/chunks/retained-semantic-state-GM75FZGE.ts +0 -81
- package/dist/chunks/retained-semantic-state-GM75FZGE.ts.map +0 -7
- package/dist/chunks/rpc-transport-7R7DVCEB.ts +0 -1222
- package/dist/chunks/rpc-transport-7R7DVCEB.ts.map +0 -7
- package/dist/chunks/runtime-policy-5YELCOVC.ts +0 -15
- package/dist/chunks/runtime-policy-5YELCOVC.ts.map +0 -7
- package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts +0 -19
- package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts.map +0 -7
- package/dist/chunks/spawn-idempotency-BNHOSMZW.ts +0 -13
- package/dist/chunks/spawn-idempotency-BNHOSMZW.ts.map +0 -7
- package/dist/chunks/stateful-lifecycle-JAR6K55H.ts +0 -15
- package/dist/chunks/stateful-lifecycle-JAR6K55H.ts.map +0 -7
- package/dist/chunks/subprocess-transport-VHZJRBTW.ts +0 -160
- package/dist/chunks/subprocess-transport-VHZJRBTW.ts.map +0 -7
- package/dist/chunks/usage-recording-store-CW3EH2SZ.ts +0 -164
- package/dist/chunks/usage-recording-store-CW3EH2SZ.ts.map +0 -7
- package/dist/chunks/workspace-WDKLN72J.ts +0 -11
- package/dist/chunks/workspace-WDKLN72J.ts.map +0 -7
- package/docs/async-runtime-protocol.md +0 -84
- package/docs/implementation-notes/pi-subagents-capability-matrix.md +0 -62
- package/docs/implementation-notes/pi-subagents-current-direction.md +0 -99
- package/docs/implementation-notes/pi-subagents-rpc-v1.md +0 -153
- package/docs/pi-subagents-diagrams.md +0 -183
- package/src/adaptive-scheduler.ts +0 -224
- package/src/admission-benchmark.ts +0 -95
- package/src/admission-policy.ts +0 -78
- package/src/agent-projection.ts +0 -53
- package/src/agents/built-ins.ts +0 -71
- package/src/agents/catalog.ts +0 -241
- package/src/agents/discovery.ts +0 -265
- package/src/agents/types.ts +0 -100
- package/src/agents.ts +0 -51
- package/src/async-subagent-benchmark.ts +0 -532
- package/src/auto-transport.ts +0 -121
- package/src/blocking-status.ts +0 -63
- package/src/cached-module-loader.ts +0 -18
- package/src/capabilities.ts +0 -145
- package/src/capability-grant.ts +0 -115
- package/src/capability-router.ts +0 -107
- package/src/child-peer-bridge.ts +0 -124
- package/src/child-peer-tools.ts +0 -132
- package/src/completion-delivery.ts +0 -409
- package/src/completion-render.ts +0 -190
- package/src/completion-requirement.ts +0 -479
- package/src/completion-routing.ts +0 -24
- package/src/config-registration.ts +0 -114
- package/src/config-status.ts +0 -217
- package/src/config-ui.ts +0 -983
- package/src/consult-policy.ts +0 -15
- package/src/consult-registration.ts +0 -125
- package/src/consult-render.ts +0 -194
- package/src/consult-resources.ts +0 -51
- package/src/consult-tool.ts +0 -95
- package/src/consult.ts +0 -566
- package/src/context.ts +0 -126
- package/src/create-stateful-transport.ts +0 -157
- package/src/cwd-policy.ts +0 -183
- package/src/delegation-contract.ts +0 -463
- package/src/execution/budget.ts +0 -56
- package/src/execution/runtime-policy.ts +0 -19
- package/src/execution-plan.ts +0 -322
- package/src/execution-ui.ts +0 -259
- package/src/execution.ts +0 -1679
- package/src/in-process-transport.ts +0 -941
- package/src/inspect-registration.ts +0 -64
- package/src/inspect-render.ts +0 -334
- package/src/inspect-tool.ts +0 -45
- package/src/inspect.ts +0 -769
- package/src/integration-controller.ts +0 -98
- package/src/limits.ts +0 -75
- package/src/orchestration-metrics.ts +0 -116
- package/src/outcome.ts +0 -61
- package/src/panel-child-group.ts +0 -35
- package/src/panel-contract.ts +0 -343
- package/src/panel-evidence.ts +0 -59
- package/src/panel-execution.ts +0 -769
- package/src/panel-failure.ts +0 -56
- package/src/panel-planning.ts +0 -175
- package/src/panel-presets.ts +0 -3
- package/src/panel-prompts.ts +0 -132
- package/src/panel-reconciliation.ts +0 -57
- package/src/panel-render.ts +0 -103
- package/src/parallel-limit-ui.ts +0 -113
- package/src/params.ts +0 -278
- package/src/peer-communication.ts +0 -352
- package/src/peer-transport.ts +0 -49
- package/src/persistence.ts +0 -522
- package/src/pi-args.ts +0 -43
- package/src/pi-invocation.ts +0 -168
- package/src/process-control.ts +0 -43
- package/src/prompt-resources.ts +0 -38
- package/src/prompt-source-safety.ts +0 -48
- package/src/protocol.ts +0 -76
- package/src/registry-types.ts +0 -204
- package/src/registry.ts +0 -1698
- package/src/render-common.ts +0 -252
- package/src/render.ts +0 -704
- package/src/result-contract.ts +0 -431
- package/src/retained-semantic-state.ts +0 -100
- package/src/rpc-timeout-finalization.ts +0 -207
- package/src/rpc-transport-metadata.ts +0 -65
- package/src/rpc-transport.ts +0 -1035
- package/src/rpc-turn-capture.ts +0 -217
- package/src/runner-outcome.ts +0 -31
- package/src/runner-result.ts +0 -55
- package/src/runner-types.ts +0 -102
- package/src/runner-usage.ts +0 -48
- package/src/runner.ts +0 -866
- package/src/safe-text.ts +0 -67
- package/src/semantic-snapshot.ts +0 -214
- package/src/session-guidance-contract.ts +0 -399
- package/src/settings/inspection.ts +0 -302
- package/src/settings/schema.ts +0 -195
- package/src/settings-reader.ts +0 -215
- package/src/settings.ts +0 -452
- package/src/spawn-idempotency.ts +0 -68
- package/src/stateful-agent-view.ts +0 -85
- package/src/stateful-config.ts +0 -13
- package/src/stateful-guidance.ts +0 -29
- package/src/stateful-lifecycle.ts +0 -74
- package/src/stateful-limit-ui.ts +0 -249
- package/src/stateful-limits.ts +0 -96
- package/src/stateful-prompt.ts +0 -49
- package/src/stateful-registration.ts +0 -1320
- package/src/stateful-render.ts +0 -318
- package/src/stateful-safety.ts +0 -47
- package/src/stateful-tool-params.ts +0 -215
- package/src/stateful.ts +0 -12
- package/src/subagent-details.ts +0 -43
- package/src/subagents-extension.ts +0 -355
- package/src/subprocess-transport.ts +0 -145
- package/src/supervision.ts +0 -104
- package/src/task-path.ts +0 -65
- package/src/timeout-checkpoint.ts +0 -305
- package/src/timeout-finalization.ts +0 -75
- package/src/tool-schema-compatibility.ts +0 -73
- package/src/transport-types.ts +0 -74
- package/src/transport-ui.ts +0 -135
- package/src/transport.ts +0 -43
- package/src/turn-budget.ts +0 -109
- package/src/usage-format.ts +0 -42
- package/src/usage-recording-config.ts +0 -13
- package/src/usage-recording-store.ts +0 -183
- package/src/usage-recording.ts +0 -478
- package/src/verification-harness.ts +0 -516
- package/src/verification-policy.ts +0 -67
- package/src/verification-receipt.ts +0 -275
- package/src/verified-execution-benchmark.ts +0 -86
- package/src/verified-execution-contract.ts +0 -191
- package/src/verified-execution-schema.ts +0 -32
- package/src/work-item-ledger.ts +0 -1404
- package/src/work-item-persistence.ts +0 -254
- package/src/workflow-completion-controller.ts +0 -397
- package/src/workflow-planning.ts +0 -172
- package/src/workflow-tree-identity.ts +0 -289
- package/src/workflow-ui.ts +0 -69
- package/src/workflow-verification.ts +0 -296
- package/src/workspace.ts +0 -174
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_MAX_OUTPUT_BYTES, truncateUtf8 } from "./limits.js";
|
|
2
|
-
import type { SubagentResultFormat } from "./result-contract.js";
|
|
3
|
-
import type { TimeoutCheckpoint, TurnTerminationReason } from "./timeout-checkpoint.js";
|
|
4
|
-
import {
|
|
5
|
-
buildTimeoutFinalizationPrompt,
|
|
6
|
-
resolveTimeoutFinalizationMs,
|
|
7
|
-
} from "./timeout-finalization.js";
|
|
8
|
-
|
|
9
|
-
interface RpcTimeoutFinalizationClient {
|
|
10
|
-
prompt(message: string, timeoutMs?: number): Promise<void>;
|
|
11
|
-
abort(): Promise<void>;
|
|
12
|
-
onEvent(listener: (event: unknown) => void): () => void;
|
|
13
|
-
onClose(listener: (error: Error) => void): () => void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface RpcSummaryCapture {
|
|
17
|
-
output: string;
|
|
18
|
-
partial: string;
|
|
19
|
-
stopReason?: string;
|
|
20
|
-
error?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface RpcTimeoutFinalizationOptions {
|
|
24
|
-
client: RpcTimeoutFinalizationClient;
|
|
25
|
-
task: string;
|
|
26
|
-
partialOutput: string;
|
|
27
|
-
checkpoint?: TimeoutCheckpoint;
|
|
28
|
-
terminationReason?: TurnTerminationReason;
|
|
29
|
-
resultFormat?: SubagentResultFormat;
|
|
30
|
-
signal: AbortSignal;
|
|
31
|
-
workTimeoutMs: number;
|
|
32
|
-
finalizationTimeoutMs?: number;
|
|
33
|
-
abortGraceMs: number;
|
|
34
|
-
resetCapture(): void;
|
|
35
|
-
getCapture(): RpcSummaryCapture;
|
|
36
|
-
release(): Promise<void>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface RpcTimeoutFinalizationResult {
|
|
40
|
-
output: string;
|
|
41
|
-
truncated: boolean;
|
|
42
|
-
status: "completed" | "failed" | "timed_out";
|
|
43
|
-
error?: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function finalizeTimedOutRpcTurn(
|
|
47
|
-
options: RpcTimeoutFinalizationOptions,
|
|
48
|
-
): Promise<RpcTimeoutFinalizationResult> {
|
|
49
|
-
options.resetCapture();
|
|
50
|
-
let settleResolve!: () => void;
|
|
51
|
-
let settleReject!: (error: Error) => void;
|
|
52
|
-
const settled = new Promise<void>((resolve, reject) => {
|
|
53
|
-
settleResolve = resolve;
|
|
54
|
-
settleReject = reject;
|
|
55
|
-
});
|
|
56
|
-
void settled.catch(() => undefined);
|
|
57
|
-
const unsubscribeEvent = options.client.onEvent((event) => {
|
|
58
|
-
if (eventType(event) === "agent_settled") settleResolve();
|
|
59
|
-
});
|
|
60
|
-
const unsubscribeClose = options.client.onClose(settleReject);
|
|
61
|
-
let error: string | undefined;
|
|
62
|
-
try {
|
|
63
|
-
const finalizationMs = resolveTimeoutFinalizationMs(
|
|
64
|
-
options.workTimeoutMs,
|
|
65
|
-
options.finalizationTimeoutMs,
|
|
66
|
-
);
|
|
67
|
-
const deadline = Date.now() + finalizationMs;
|
|
68
|
-
await raceWithAbort(
|
|
69
|
-
() =>
|
|
70
|
-
options.client.prompt(
|
|
71
|
-
buildTimeoutFinalizationPrompt({
|
|
72
|
-
task: options.task,
|
|
73
|
-
partialOutput: options.partialOutput,
|
|
74
|
-
checkpoint: options.checkpoint,
|
|
75
|
-
terminationReason: options.terminationReason,
|
|
76
|
-
resultFormat: options.resultFormat,
|
|
77
|
-
}),
|
|
78
|
-
remainingMs(deadline),
|
|
79
|
-
),
|
|
80
|
-
options.signal,
|
|
81
|
-
remainingMs(deadline),
|
|
82
|
-
);
|
|
83
|
-
const settlement = await waitForSettlement(settled, options.signal, remainingMs(deadline));
|
|
84
|
-
if (settlement !== "settled") {
|
|
85
|
-
const [abortCompleted, stopped] = await Promise.all([
|
|
86
|
-
settlesWithin(options.client.abort(), options.abortGraceMs),
|
|
87
|
-
settlesWithin(settled, options.abortGraceMs),
|
|
88
|
-
]);
|
|
89
|
-
if (!stopped) await boundedRelease(options);
|
|
90
|
-
error = [
|
|
91
|
-
`timeout summary ${settlement}`,
|
|
92
|
-
abortCompleted ? undefined : "summary abort command did not settle",
|
|
93
|
-
]
|
|
94
|
-
.filter(Boolean)
|
|
95
|
-
.join("; ");
|
|
96
|
-
}
|
|
97
|
-
} catch (caught) {
|
|
98
|
-
error = boundedError(caught);
|
|
99
|
-
await boundedRelease(options);
|
|
100
|
-
} finally {
|
|
101
|
-
unsubscribeEvent();
|
|
102
|
-
unsubscribeClose();
|
|
103
|
-
}
|
|
104
|
-
const capture = options.getCapture();
|
|
105
|
-
const output = truncateUtf8(capture.output || capture.partial, DEFAULT_MAX_OUTPUT_BYTES);
|
|
106
|
-
if (!error && (capture.stopReason === "error" || !output.text.trim())) {
|
|
107
|
-
error = capture.error || "Timeout summary produced no final text";
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
output: output.text,
|
|
111
|
-
truncated: output.truncated,
|
|
112
|
-
status: error ? (/timed out|timeout/iu.test(error) ? "timed_out" : "failed") : "completed",
|
|
113
|
-
error,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function eventType(value: unknown): string | undefined {
|
|
118
|
-
return value &&
|
|
119
|
-
typeof value === "object" &&
|
|
120
|
-
typeof (value as { type?: unknown }).type === "string"
|
|
121
|
-
? ((value as { type: string }).type ?? undefined)
|
|
122
|
-
: undefined;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function remainingMs(deadline: number): number {
|
|
126
|
-
return Math.max(1, deadline - Date.now());
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async function raceWithAbort<T>(
|
|
130
|
-
start: () => Promise<T>,
|
|
131
|
-
signal: AbortSignal,
|
|
132
|
-
timeoutMs: number,
|
|
133
|
-
): Promise<T> {
|
|
134
|
-
if (signal.aborted) throw abortError();
|
|
135
|
-
let onAbort: (() => void) | undefined;
|
|
136
|
-
let timer: NodeJS.Timeout | undefined;
|
|
137
|
-
const aborted = new Promise<never>((_resolve, reject) => {
|
|
138
|
-
onAbort = () => reject(abortError());
|
|
139
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
140
|
-
if (signal.aborted) onAbort();
|
|
141
|
-
});
|
|
142
|
-
const timedOut = new Promise<never>((_resolve, reject) => {
|
|
143
|
-
timer = setTimeout(() => reject(new Error("RPC timeout summary prompt timed out")), timeoutMs);
|
|
144
|
-
});
|
|
145
|
-
try {
|
|
146
|
-
return await Promise.race([start(), aborted, timedOut]);
|
|
147
|
-
} finally {
|
|
148
|
-
if (timer) clearTimeout(timer);
|
|
149
|
-
if (onAbort) signal.removeEventListener("abort", onAbort);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async function waitForSettlement(
|
|
154
|
-
settled: Promise<void>,
|
|
155
|
-
signal: AbortSignal,
|
|
156
|
-
timeoutMs: number,
|
|
157
|
-
): Promise<"settled" | "aborted" | "timeout"> {
|
|
158
|
-
if (signal.aborted) return "aborted";
|
|
159
|
-
let timer: NodeJS.Timeout | undefined;
|
|
160
|
-
let onAbort: (() => void) | undefined;
|
|
161
|
-
try {
|
|
162
|
-
return await Promise.race([
|
|
163
|
-
settled.then(() => "settled" as const),
|
|
164
|
-
new Promise<"aborted">((resolve) => {
|
|
165
|
-
onAbort = () => resolve("aborted");
|
|
166
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
167
|
-
}),
|
|
168
|
-
new Promise<"timeout">((resolve) => {
|
|
169
|
-
timer = setTimeout(() => resolve("timeout"), timeoutMs);
|
|
170
|
-
}),
|
|
171
|
-
]);
|
|
172
|
-
} finally {
|
|
173
|
-
if (timer) clearTimeout(timer);
|
|
174
|
-
if (onAbort) signal.removeEventListener("abort", onAbort);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
async function boundedRelease(options: RpcTimeoutFinalizationOptions): Promise<boolean> {
|
|
179
|
-
return settlesWithin(options.release(), options.abortGraceMs + 1_000);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async function settlesWithin(settled: Promise<void>, timeoutMs: number): Promise<boolean> {
|
|
183
|
-
let timer: NodeJS.Timeout | undefined;
|
|
184
|
-
try {
|
|
185
|
-
return await Promise.race([
|
|
186
|
-
settled.then(
|
|
187
|
-
() => true,
|
|
188
|
-
() => true,
|
|
189
|
-
),
|
|
190
|
-
new Promise<boolean>((resolve) => {
|
|
191
|
-
timer = setTimeout(() => resolve(false), timeoutMs);
|
|
192
|
-
}),
|
|
193
|
-
]);
|
|
194
|
-
} finally {
|
|
195
|
-
if (timer) clearTimeout(timer);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function abortError(): Error {
|
|
200
|
-
const error = new Error("RPC timeout summary aborted");
|
|
201
|
-
error.name = "AbortError";
|
|
202
|
-
return error;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function boundedError(error: unknown): string {
|
|
206
|
-
return truncateUtf8(error instanceof Error ? error.message : String(error), 16 * 1024).text;
|
|
207
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { AgentConfig, SubagentThinkingLevel } from "./agents/types.js";
|
|
2
|
-
import { DEFAULT_MAX_OUTPUT_BYTES } from "./limits.js";
|
|
3
|
-
import type { ManagedAgent, TurnOutcome } from "./registry.js";
|
|
4
|
-
import { boundedPrivateText } from "./safe-text.js";
|
|
5
|
-
import type { TransportTelemetry } from "./transport-types.js";
|
|
6
|
-
|
|
7
|
-
export function modelIdentity(value: unknown): { provider?: string; model?: string } {
|
|
8
|
-
if (!value || typeof value !== "object") return {};
|
|
9
|
-
const model = value as Record<string, unknown>;
|
|
10
|
-
return {
|
|
11
|
-
provider:
|
|
12
|
-
typeof model.provider === "string" ? boundedPrivateText(model.provider, 256) : undefined,
|
|
13
|
-
model: typeof model.id === "string" ? boundedPrivateText(model.id, 256) : undefined,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function normalizeThinking(value: unknown): SubagentThinkingLevel | undefined {
|
|
18
|
-
return typeof value === "string" &&
|
|
19
|
-
["off", "minimal", "low", "medium", "high", "xhigh", "max"].includes(value)
|
|
20
|
-
? (value as SubagentThinkingLevel)
|
|
21
|
-
: undefined;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function rpcPolicy(
|
|
25
|
-
config: AgentConfig,
|
|
26
|
-
agent: ManagedAgent,
|
|
27
|
-
): NonNullable<TurnOutcome["policy"]> {
|
|
28
|
-
return {
|
|
29
|
-
inherited: ["environment", "cwdResources"],
|
|
30
|
-
overridden: [
|
|
31
|
-
"cwd",
|
|
32
|
-
"extensions",
|
|
33
|
-
...(config.model ? ["model"] : []),
|
|
34
|
-
...(agent.thinkingLevel || config.thinkingLevel ? ["thinkingLevel"] : []),
|
|
35
|
-
...(config.tools ? ["tools"] : []),
|
|
36
|
-
],
|
|
37
|
-
unsupported: ["approvalPolicy", "sandboxProfile", "providerHeaders", "extensionState"],
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function interruptedRpcOutcome(
|
|
42
|
-
output: string,
|
|
43
|
-
telemetry: TransportTelemetry,
|
|
44
|
-
failurePhase: TransportTelemetry["phase"],
|
|
45
|
-
): TurnOutcome {
|
|
46
|
-
return {
|
|
47
|
-
output,
|
|
48
|
-
exitCode: 130,
|
|
49
|
-
aborted: true,
|
|
50
|
-
error: "RPC subagent was aborted",
|
|
51
|
-
telemetry: {
|
|
52
|
-
...telemetry,
|
|
53
|
-
phase: "interrupted",
|
|
54
|
-
failurePhase,
|
|
55
|
-
updatedAt: Date.now(),
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function boundedError(error: unknown): string {
|
|
61
|
-
return boundedPrivateText(
|
|
62
|
-
error instanceof Error ? error.message : String(error),
|
|
63
|
-
DEFAULT_MAX_OUTPUT_BYTES,
|
|
64
|
-
);
|
|
65
|
-
}
|