@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
package/src/agents.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compatibility facade for the former mixed agent module.
|
|
3
|
-
*
|
|
4
|
-
* New source modules should import from the cohesive agent boundaries directly.
|
|
5
|
-
* Keep this facade while tests and supported internal entrypoints still depend on the old path.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export { getBuiltInAgent } from "./agents/built-ins.js";
|
|
9
|
-
export {
|
|
10
|
-
type AgentCatalog,
|
|
11
|
-
type AgentCatalogFormatOptions,
|
|
12
|
-
type AgentCatalogFormatResult,
|
|
13
|
-
DEFAULT_AGENT_CATALOG_MAX_CHARACTERS,
|
|
14
|
-
DEFAULT_AGENT_CATALOG_MAX_DESCRIPTION_LENGTH,
|
|
15
|
-
DEFAULT_AGENT_CATALOG_MAX_FILE_BYTES,
|
|
16
|
-
DEFAULT_AGENT_CATALOG_MAX_FILES_PER_SCOPE,
|
|
17
|
-
DEFAULT_AGENT_CATALOG_MAX_ITEMS,
|
|
18
|
-
DEFAULT_AGENT_CATALOG_MAX_TOTAL_BYTES_PER_SCOPE,
|
|
19
|
-
discoverAgentCatalog,
|
|
20
|
-
formatAgentCatalog,
|
|
21
|
-
formatAgentList,
|
|
22
|
-
} from "./agents/catalog.js";
|
|
23
|
-
export {
|
|
24
|
-
type AgentDiscoveryOptions,
|
|
25
|
-
type AgentDiscoveryResult,
|
|
26
|
-
discoverAgents,
|
|
27
|
-
} from "./agents/discovery.js";
|
|
28
|
-
export {
|
|
29
|
-
type AgentConfig,
|
|
30
|
-
type AgentScope,
|
|
31
|
-
type AgentSource,
|
|
32
|
-
CONSULT_RESOURCE_POLICIES,
|
|
33
|
-
CONSULTATION_CWD_POLICIES,
|
|
34
|
-
type CompletionDelivery,
|
|
35
|
-
type ConsultationCwdPolicy,
|
|
36
|
-
type ConsultResourcePolicy,
|
|
37
|
-
DEFAULT_PI_TOOL_NAMES,
|
|
38
|
-
DELEGATION_CWD_POLICIES,
|
|
39
|
-
type DelegationCwdPolicy,
|
|
40
|
-
isThinkingLevel,
|
|
41
|
-
resolveAgentToolNames,
|
|
42
|
-
type SubagentAgentConfig,
|
|
43
|
-
type SubagentBlockingSettings,
|
|
44
|
-
type SubagentConsultSettings,
|
|
45
|
-
type SubagentCwdPolicySettings,
|
|
46
|
-
type SubagentRuntimeSettings,
|
|
47
|
-
type SubagentSettings,
|
|
48
|
-
type SubagentThinkingLevel,
|
|
49
|
-
type SubagentTransportKind,
|
|
50
|
-
THINKING_LEVELS,
|
|
51
|
-
} from "./agents/types.js";
|
|
@@ -1,532 +0,0 @@
|
|
|
1
|
-
export const ASYNC_SUBAGENT_BENCHMARK_VERSION = "pi-subagents:async-surface-benchmark:v1" as const;
|
|
2
|
-
|
|
3
|
-
export const BENCHMARK_RESULT_PREFIX = "BENCHMARK_RESULT_JSON:";
|
|
4
|
-
export const BENCHMARK_MODES = ["quick", "extended"] as const;
|
|
5
|
-
export const BENCHMARK_ARMS = ["sync", "async"] as const;
|
|
6
|
-
export const BENCHMARK_THINKING_LEVELS = [
|
|
7
|
-
"off",
|
|
8
|
-
"minimal",
|
|
9
|
-
"low",
|
|
10
|
-
"medium",
|
|
11
|
-
"high",
|
|
12
|
-
"xhigh",
|
|
13
|
-
"max",
|
|
14
|
-
] as const;
|
|
15
|
-
|
|
16
|
-
export type AsyncSubagentBenchmarkMode = (typeof BENCHMARK_MODES)[number];
|
|
17
|
-
export type AsyncSubagentBenchmarkArm = (typeof BENCHMARK_ARMS)[number];
|
|
18
|
-
export type AsyncSubagentBenchmarkThinkingLevel = (typeof BENCHMARK_THINKING_LEVELS)[number];
|
|
19
|
-
export type AsyncSubagentTerminalOutcome =
|
|
20
|
-
| "completed"
|
|
21
|
-
| "invalid-output"
|
|
22
|
-
| "timed-out"
|
|
23
|
-
| "readiness-timeout"
|
|
24
|
-
| "process-error"
|
|
25
|
-
| "protocol-error";
|
|
26
|
-
|
|
27
|
-
export const FIXED_BENCHMARK_TASK = [
|
|
28
|
-
"Inspect only packages/pi-subagents/src/registry.ts, packages/pi-subagents/src/completion-delivery.ts, and packages/pi-subagents/src/stateful-registration.ts.",
|
|
29
|
-
"Report what AgentRegistry.wait races, how completion IDs prevent duplicate delivery, and which session hook closes retained completion delivery state.",
|
|
30
|
-
"Cite each finding with its repository-relative source path and exact symbol or operation.",
|
|
31
|
-
"Do not modify files.",
|
|
32
|
-
].join("\n");
|
|
33
|
-
|
|
34
|
-
export const FIXED_EVIDENCE_RUBRIC = [
|
|
35
|
-
{
|
|
36
|
-
id: "registry-wait-race",
|
|
37
|
-
terms: ["packages/pi-subagents/src/registry.ts", "promise.race"],
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
id: "completion-id-deduplication",
|
|
41
|
-
terms: ["packages/pi-subagents/src/completion-delivery.ts", "completionid"],
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
id: "session-shutdown-cleanup",
|
|
45
|
-
terms: ["packages/pi-subagents/src/stateful-registration.ts", "session_shutdown"],
|
|
46
|
-
},
|
|
47
|
-
] as const;
|
|
48
|
-
|
|
49
|
-
export interface AsyncSubagentBenchmarkOptions {
|
|
50
|
-
mode: AsyncSubagentBenchmarkMode;
|
|
51
|
-
model: string;
|
|
52
|
-
thinkingLevel: AsyncSubagentBenchmarkThinkingLevel;
|
|
53
|
-
timeoutMs: number;
|
|
54
|
-
readinessTimeoutMs: number;
|
|
55
|
-
outputPath?: string;
|
|
56
|
-
run: boolean;
|
|
57
|
-
piCommand: string;
|
|
58
|
-
workspace?: string;
|
|
59
|
-
extension?: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface AsyncSubagentBenchmarkTrialPlan {
|
|
63
|
-
pairIndex: number;
|
|
64
|
-
orderIndex: number;
|
|
65
|
-
arm: AsyncSubagentBenchmarkArm;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface AsyncSubagentEventAnalysis {
|
|
69
|
-
completionObserved: boolean;
|
|
70
|
-
evidenceScore: number;
|
|
71
|
-
matchedEvidence: string[];
|
|
72
|
-
prematureFinalCount: number;
|
|
73
|
-
finalAnswer?: string;
|
|
74
|
-
resultMarker?: Record<string, unknown>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface AsyncSubagentBenchmarkTrialRecord extends AsyncSubagentEventAnalysis {
|
|
78
|
-
version: typeof ASYNC_SUBAGENT_BENCHMARK_VERSION;
|
|
79
|
-
pairIndex: number;
|
|
80
|
-
orderIndex: number;
|
|
81
|
-
arm: AsyncSubagentBenchmarkArm;
|
|
82
|
-
outcome: AsyncSubagentTerminalOutcome;
|
|
83
|
-
readinessMs: number;
|
|
84
|
-
elapsedMs: number;
|
|
85
|
-
cost: number | null;
|
|
86
|
-
startedAt: string;
|
|
87
|
-
completedAt: string;
|
|
88
|
-
events: unknown[];
|
|
89
|
-
stderr?: string;
|
|
90
|
-
error?: string;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface DistributionSummary {
|
|
94
|
-
median: number;
|
|
95
|
-
p95: number;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export interface AsyncSubagentArmSummary {
|
|
99
|
-
trials: number;
|
|
100
|
-
completionCoverage: number;
|
|
101
|
-
evidenceScore: number;
|
|
102
|
-
prematureFinalCount: number;
|
|
103
|
-
terminalOutcomes: Record<AsyncSubagentTerminalOutcome, number>;
|
|
104
|
-
latencyMs: DistributionSummary | null;
|
|
105
|
-
cost: {
|
|
106
|
-
available: number;
|
|
107
|
-
total: number;
|
|
108
|
-
median: number;
|
|
109
|
-
p95: number;
|
|
110
|
-
} | null;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface AsyncSubagentBenchmarkSummary {
|
|
114
|
-
version: typeof ASYNC_SUBAGENT_BENCHMARK_VERSION;
|
|
115
|
-
pairs: number;
|
|
116
|
-
arms: Record<AsyncSubagentBenchmarkArm, AsyncSubagentArmSummary>;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export class BenchmarkDeadlineError extends Error {
|
|
120
|
-
constructor(message: string) {
|
|
121
|
-
super(message);
|
|
122
|
-
this.name = "BenchmarkDeadlineError";
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function parseAsyncSubagentBenchmarkArgs(
|
|
127
|
-
args: readonly string[],
|
|
128
|
-
): AsyncSubagentBenchmarkOptions {
|
|
129
|
-
let mode: AsyncSubagentBenchmarkMode = "quick";
|
|
130
|
-
let model = "";
|
|
131
|
-
let thinkingLevel: AsyncSubagentBenchmarkThinkingLevel = "medium";
|
|
132
|
-
let timeoutMs = 120_000;
|
|
133
|
-
let readinessTimeoutMs = 15_000;
|
|
134
|
-
let outputPath: string | undefined;
|
|
135
|
-
let run = false;
|
|
136
|
-
let piCommand = "pi";
|
|
137
|
-
let workspace: string | undefined;
|
|
138
|
-
let extension: string | undefined;
|
|
139
|
-
|
|
140
|
-
for (let index = 0; index < args.length; index++) {
|
|
141
|
-
const argument = args[index];
|
|
142
|
-
if (argument === "--run") {
|
|
143
|
-
run = true;
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
const value = args[index + 1];
|
|
147
|
-
if (!value || value.startsWith("--")) throw new Error(`${argument} requires a value`);
|
|
148
|
-
index++;
|
|
149
|
-
switch (argument) {
|
|
150
|
-
case "--mode":
|
|
151
|
-
if (!isOneOf(value, BENCHMARK_MODES)) throw new Error("--mode must be quick or extended");
|
|
152
|
-
mode = value;
|
|
153
|
-
break;
|
|
154
|
-
case "--model":
|
|
155
|
-
model = value.trim();
|
|
156
|
-
break;
|
|
157
|
-
case "--thinking":
|
|
158
|
-
if (!isOneOf(value, BENCHMARK_THINKING_LEVELS)) {
|
|
159
|
-
throw new Error(`Unsupported thinking level: ${value}`);
|
|
160
|
-
}
|
|
161
|
-
thinkingLevel = value;
|
|
162
|
-
break;
|
|
163
|
-
case "--timeout-ms":
|
|
164
|
-
timeoutMs = positiveInteger(value, "--timeout-ms");
|
|
165
|
-
break;
|
|
166
|
-
case "--readiness-timeout-ms":
|
|
167
|
-
readinessTimeoutMs = positiveInteger(value, "--readiness-timeout-ms");
|
|
168
|
-
break;
|
|
169
|
-
case "--output":
|
|
170
|
-
outputPath = value;
|
|
171
|
-
break;
|
|
172
|
-
case "--pi":
|
|
173
|
-
piCommand = value;
|
|
174
|
-
break;
|
|
175
|
-
case "--workspace":
|
|
176
|
-
workspace = value;
|
|
177
|
-
break;
|
|
178
|
-
case "--extension":
|
|
179
|
-
extension = value;
|
|
180
|
-
break;
|
|
181
|
-
default:
|
|
182
|
-
throw new Error(`Unknown benchmark argument: ${argument}`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (!model) throw new Error("--model is required so every paired trial uses one fixed model");
|
|
186
|
-
if (run && !outputPath) throw new Error("--output is required with --run");
|
|
187
|
-
return {
|
|
188
|
-
mode,
|
|
189
|
-
model,
|
|
190
|
-
thinkingLevel,
|
|
191
|
-
timeoutMs,
|
|
192
|
-
readinessTimeoutMs,
|
|
193
|
-
outputPath,
|
|
194
|
-
run,
|
|
195
|
-
piCommand,
|
|
196
|
-
...(workspace ? { workspace } : {}),
|
|
197
|
-
...(extension ? { extension } : {}),
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export function benchmarkPairCount(mode: AsyncSubagentBenchmarkMode): number {
|
|
202
|
-
return mode === "quick" ? 3 : 10;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export function createAlternatingTrialPlan(
|
|
206
|
-
mode: AsyncSubagentBenchmarkMode,
|
|
207
|
-
): AsyncSubagentBenchmarkTrialPlan[] {
|
|
208
|
-
const trials: AsyncSubagentBenchmarkTrialPlan[] = [];
|
|
209
|
-
for (let pairIndex = 0; pairIndex < benchmarkPairCount(mode); pairIndex++) {
|
|
210
|
-
const order: readonly AsyncSubagentBenchmarkArm[] =
|
|
211
|
-
pairIndex % 2 === 0 ? ["sync", "async"] : ["async", "sync"];
|
|
212
|
-
for (const [orderIndex, arm] of order.entries()) {
|
|
213
|
-
trials.push({ pairIndex, orderIndex, arm });
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
return trials;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export function buildAsyncSubagentBenchmarkPrompt(
|
|
220
|
-
arm: AsyncSubagentBenchmarkArm,
|
|
221
|
-
thinkingLevel: AsyncSubagentBenchmarkThinkingLevel = "medium",
|
|
222
|
-
): string {
|
|
223
|
-
const orchestration =
|
|
224
|
-
arm === "sync"
|
|
225
|
-
? [
|
|
226
|
-
"Use the deprecated subagent tool in single mode exactly once with agent explorer.",
|
|
227
|
-
`Set thinkingLevel to ${thinkingLevel}, pass the fixed task below, and wait for the blocking result.`,
|
|
228
|
-
]
|
|
229
|
-
: [
|
|
230
|
-
"Use subagent_spawn exactly once with agent explorer, context none, and completionRequirement required.",
|
|
231
|
-
`Set thinkingLevel to ${thinkingLevel}, continue only useful non-overlapping local work, and rely on automatic completion delivery without calling any blocking or inspection tool.`,
|
|
232
|
-
"Do not provide the benchmark result before the retained completion is visible or terminal.",
|
|
233
|
-
];
|
|
234
|
-
return [
|
|
235
|
-
"This is a non-interactive paired benchmark.",
|
|
236
|
-
...orchestration,
|
|
237
|
-
"Use the configured model without changing it.",
|
|
238
|
-
"Fixed child task:",
|
|
239
|
-
FIXED_BENCHMARK_TASK,
|
|
240
|
-
"After observing the child result, answer concisely with all three requested findings.",
|
|
241
|
-
`End with one single-line marker in this exact form: ${BENCHMARK_RESULT_PREFIX} {"complete":true}`,
|
|
242
|
-
].join("\n\n");
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export function parseBenchmarkJsonLines(source: string): unknown[] {
|
|
246
|
-
const values: unknown[] = [];
|
|
247
|
-
for (const [index, rawLine] of source.split("\n").entries()) {
|
|
248
|
-
const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
|
|
249
|
-
if (!line) continue;
|
|
250
|
-
try {
|
|
251
|
-
values.push(JSON.parse(line));
|
|
252
|
-
} catch {
|
|
253
|
-
throw new Error(`Invalid benchmark JSONL at line ${index + 1}`);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return values;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export function analyzeBenchmarkEvents(
|
|
260
|
-
arm: AsyncSubagentBenchmarkArm,
|
|
261
|
-
events: readonly unknown[],
|
|
262
|
-
): AsyncSubagentEventAnalysis {
|
|
263
|
-
let completionIndex = -1;
|
|
264
|
-
let spawnObserved = false;
|
|
265
|
-
let prematureFinalCount = 0;
|
|
266
|
-
let finalAnswer: string | undefined;
|
|
267
|
-
let resultMarker: Record<string, unknown> | undefined;
|
|
268
|
-
let finalIndex = -1;
|
|
269
|
-
|
|
270
|
-
for (const [index, value] of events.entries()) {
|
|
271
|
-
if (!isRecord(value)) continue;
|
|
272
|
-
const message =
|
|
273
|
-
value.type === "message_end" && isRecord(value.message) ? value.message : undefined;
|
|
274
|
-
if (!message) continue;
|
|
275
|
-
if (message.role === "custom" && message.customType === "pi-subagent-completion") {
|
|
276
|
-
if (completionIndex < 0) completionIndex = index;
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
if (message.role === "toolResult") {
|
|
280
|
-
const toolName = typeof message.toolName === "string" ? message.toolName : "";
|
|
281
|
-
const details = isRecord(message.details) ? message.details : undefined;
|
|
282
|
-
if (toolName === "subagent_spawn" && message.isError !== true) spawnObserved = true;
|
|
283
|
-
if (
|
|
284
|
-
message.isError !== true &&
|
|
285
|
-
details?.timedOut !== true &&
|
|
286
|
-
((arm === "sync" && toolName === "subagent") ||
|
|
287
|
-
(arm === "async" && toolName === "subagent_await"))
|
|
288
|
-
) {
|
|
289
|
-
if (completionIndex < 0) completionIndex = index;
|
|
290
|
-
}
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
if (message.role !== "assistant") continue;
|
|
294
|
-
const content = Array.isArray(message.content) ? message.content : [];
|
|
295
|
-
const hasToolCall = content.some(
|
|
296
|
-
(item) => isRecord(item) && item.type === "toolCall" && typeof item.name === "string",
|
|
297
|
-
);
|
|
298
|
-
if (
|
|
299
|
-
content.some(
|
|
300
|
-
(item) => isRecord(item) && item.type === "toolCall" && item.name === "subagent_spawn",
|
|
301
|
-
)
|
|
302
|
-
) {
|
|
303
|
-
spawnObserved = true;
|
|
304
|
-
}
|
|
305
|
-
const text = messageText(message);
|
|
306
|
-
const marker = extractResultMarker(text);
|
|
307
|
-
if (marker) {
|
|
308
|
-
if (arm === "async" && spawnObserved && completionIndex < 0) prematureFinalCount++;
|
|
309
|
-
finalAnswer = text;
|
|
310
|
-
resultMarker = marker;
|
|
311
|
-
finalIndex = index;
|
|
312
|
-
} else if (
|
|
313
|
-
arm === "async" &&
|
|
314
|
-
spawnObserved &&
|
|
315
|
-
completionIndex < 0 &&
|
|
316
|
-
text.trim() &&
|
|
317
|
-
!hasToolCall &&
|
|
318
|
-
scoreBenchmarkEvidence(text).score > 0
|
|
319
|
-
) {
|
|
320
|
-
prematureFinalCount++;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const score = scoreBenchmarkEvidence(finalAnswer ?? "");
|
|
325
|
-
return {
|
|
326
|
-
completionObserved: completionIndex >= 0 && (finalIndex < 0 || completionIndex < finalIndex),
|
|
327
|
-
evidenceScore: score.score,
|
|
328
|
-
matchedEvidence: score.matched,
|
|
329
|
-
prematureFinalCount,
|
|
330
|
-
...(finalAnswer ? { finalAnswer } : {}),
|
|
331
|
-
...(resultMarker ? { resultMarker } : {}),
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export function scoreBenchmarkEvidence(text: string): { score: number; matched: string[] } {
|
|
336
|
-
const normalized = text.toLowerCase().replaceAll("`", "");
|
|
337
|
-
const matched = FIXED_EVIDENCE_RUBRIC.filter((item) =>
|
|
338
|
-
item.terms.every((term) => normalized.includes(term.toLowerCase())),
|
|
339
|
-
).map((item) => item.id);
|
|
340
|
-
return {
|
|
341
|
-
score: round(matched.length / FIXED_EVIDENCE_RUBRIC.length),
|
|
342
|
-
matched,
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
export function percentile(values: readonly number[], quantile: number): number {
|
|
347
|
-
if (values.length === 0) throw new Error("Cannot calculate a percentile without values");
|
|
348
|
-
if (!Number.isFinite(quantile) || quantile < 0 || quantile > 1) {
|
|
349
|
-
throw new Error("Percentile quantile must be between zero and one");
|
|
350
|
-
}
|
|
351
|
-
const sorted = [...values].sort((left, right) => left - right);
|
|
352
|
-
const position = (sorted.length - 1) * quantile;
|
|
353
|
-
const lower = Math.floor(position);
|
|
354
|
-
const upper = Math.ceil(position);
|
|
355
|
-
if (lower === upper) return round(sorted[lower]);
|
|
356
|
-
return round(sorted[lower] + (sorted[upper] - sorted[lower]) * (position - lower));
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
export function summarizeAsyncSubagentBenchmark(
|
|
360
|
-
records: readonly AsyncSubagentBenchmarkTrialRecord[],
|
|
361
|
-
): AsyncSubagentBenchmarkSummary {
|
|
362
|
-
const summarizeArm = (arm: AsyncSubagentBenchmarkArm): AsyncSubagentArmSummary => {
|
|
363
|
-
const selected = records.filter((record) => record.arm === arm);
|
|
364
|
-
const completed = selected.filter((record) => record.outcome === "completed");
|
|
365
|
-
const costs = selected.flatMap((record) => (record.cost === null ? [] : [record.cost]));
|
|
366
|
-
const terminalOutcomes = emptyTerminalOutcomes();
|
|
367
|
-
for (const record of selected) terminalOutcomes[record.outcome]++;
|
|
368
|
-
return {
|
|
369
|
-
trials: selected.length,
|
|
370
|
-
completionCoverage:
|
|
371
|
-
selected.length === 0
|
|
372
|
-
? 0
|
|
373
|
-
: round(selected.filter((record) => record.completionObserved).length / selected.length),
|
|
374
|
-
evidenceScore:
|
|
375
|
-
selected.length === 0
|
|
376
|
-
? 0
|
|
377
|
-
: round(
|
|
378
|
-
selected.reduce((sum, record) => sum + record.evidenceScore, 0) / selected.length,
|
|
379
|
-
),
|
|
380
|
-
prematureFinalCount: selected.reduce((sum, record) => sum + record.prematureFinalCount, 0),
|
|
381
|
-
terminalOutcomes,
|
|
382
|
-
latencyMs:
|
|
383
|
-
completed.length === 0
|
|
384
|
-
? null
|
|
385
|
-
: {
|
|
386
|
-
median: percentile(
|
|
387
|
-
completed.map((record) => record.elapsedMs),
|
|
388
|
-
0.5,
|
|
389
|
-
),
|
|
390
|
-
p95: percentile(
|
|
391
|
-
completed.map((record) => record.elapsedMs),
|
|
392
|
-
0.95,
|
|
393
|
-
),
|
|
394
|
-
},
|
|
395
|
-
cost:
|
|
396
|
-
costs.length === 0
|
|
397
|
-
? null
|
|
398
|
-
: {
|
|
399
|
-
available: costs.length,
|
|
400
|
-
total: round(costs.reduce((sum, value) => sum + value, 0)),
|
|
401
|
-
median: percentile(costs, 0.5),
|
|
402
|
-
p95: percentile(costs, 0.95),
|
|
403
|
-
},
|
|
404
|
-
};
|
|
405
|
-
};
|
|
406
|
-
return {
|
|
407
|
-
version: ASYNC_SUBAGENT_BENCHMARK_VERSION,
|
|
408
|
-
pairs: new Set(records.map((record) => record.pairIndex)).size,
|
|
409
|
-
arms: { sync: summarizeArm("sync"), async: summarizeArm("async") },
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
export async function runAfterReadinessWithDeadline<T>(
|
|
414
|
-
readiness: Promise<unknown>,
|
|
415
|
-
run: () => Promise<T>,
|
|
416
|
-
timeoutMs: number,
|
|
417
|
-
): Promise<T> {
|
|
418
|
-
await readiness;
|
|
419
|
-
return await withDeadline(run(), timeoutMs, "Benchmark trial timed out");
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
export async function withDeadline<T>(
|
|
423
|
-
operation: Promise<T>,
|
|
424
|
-
timeoutMs: number,
|
|
425
|
-
message: string,
|
|
426
|
-
): Promise<T> {
|
|
427
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs < 1) throw new Error("Deadline must be positive");
|
|
428
|
-
let timer: NodeJS.Timeout | undefined;
|
|
429
|
-
try {
|
|
430
|
-
return await Promise.race([
|
|
431
|
-
operation,
|
|
432
|
-
new Promise<never>((_resolve, reject) => {
|
|
433
|
-
timer = setTimeout(() => reject(new BenchmarkDeadlineError(message)), timeoutMs);
|
|
434
|
-
}),
|
|
435
|
-
]);
|
|
436
|
-
} finally {
|
|
437
|
-
if (timer) clearTimeout(timer);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
export function redactBenchmarkValue(value: unknown): unknown {
|
|
442
|
-
return redactValue(value, new WeakSet<object>());
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
function extractResultMarker(text: string): Record<string, unknown> | undefined {
|
|
446
|
-
for (const line of text.split("\n").reverse()) {
|
|
447
|
-
const markerIndex = line.indexOf(BENCHMARK_RESULT_PREFIX);
|
|
448
|
-
if (markerIndex < 0) continue;
|
|
449
|
-
const source = line.slice(markerIndex + BENCHMARK_RESULT_PREFIX.length).trim();
|
|
450
|
-
try {
|
|
451
|
-
const parsed: unknown = JSON.parse(source);
|
|
452
|
-
if (isRecord(parsed) && parsed.complete === true) return parsed;
|
|
453
|
-
} catch {
|
|
454
|
-
return undefined;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
return undefined;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
function messageText(message: Record<string, unknown>): string {
|
|
461
|
-
if (typeof message.content === "string") return message.content;
|
|
462
|
-
if (!Array.isArray(message.content)) return "";
|
|
463
|
-
return message.content
|
|
464
|
-
.flatMap((item) =>
|
|
465
|
-
isRecord(item) && item.type === "text" && typeof item.text === "string" ? [item.text] : [],
|
|
466
|
-
)
|
|
467
|
-
.join("\n");
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
function emptyTerminalOutcomes(): Record<AsyncSubagentTerminalOutcome, number> {
|
|
471
|
-
return {
|
|
472
|
-
completed: 0,
|
|
473
|
-
"invalid-output": 0,
|
|
474
|
-
"timed-out": 0,
|
|
475
|
-
"readiness-timeout": 0,
|
|
476
|
-
"process-error": 0,
|
|
477
|
-
"protocol-error": 0,
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
function redactValue(value: unknown, seen: WeakSet<object>): unknown {
|
|
482
|
-
if (typeof value === "string") return redactString(value);
|
|
483
|
-
if (Array.isArray(value)) return value.map((item) => redactValue(item, seen));
|
|
484
|
-
if (!isRecord(value)) return value;
|
|
485
|
-
if (seen.has(value)) return "[circular]";
|
|
486
|
-
seen.add(value);
|
|
487
|
-
const redacted: Record<string, unknown> = {};
|
|
488
|
-
for (const [key, item] of Object.entries(value)) {
|
|
489
|
-
redacted[key] = sensitiveKey(key) ? "[redacted]" : redactValue(item, seen);
|
|
490
|
-
}
|
|
491
|
-
return redacted;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
function redactString(value: string): string {
|
|
495
|
-
const home = process.env.HOME;
|
|
496
|
-
let redacted = value.replace(/<private>[\s\S]*?<\/private>/giu, "[private content omitted]");
|
|
497
|
-
redacted = redacted.replace(/\bBearer\s+[A-Za-z0-9._~+/-]+=*/giu, "Bearer [redacted]");
|
|
498
|
-
redacted = redacted.replace(/\b(sk-[A-Za-z0-9_-]{12,})\b/gu, "[redacted-key]");
|
|
499
|
-
redacted = redacted.replace(
|
|
500
|
-
/\b([A-Z][A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|API_KEY))=([^\s]+)/gu,
|
|
501
|
-
"$1=[redacted]",
|
|
502
|
-
);
|
|
503
|
-
if (home) redacted = redacted.split(home).join("$HOME");
|
|
504
|
-
const limit = 16 * 1024;
|
|
505
|
-
return redacted.length <= limit ? redacted : `${redacted.slice(0, limit)}\n[truncated]`;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
function sensitiveKey(key: string): boolean {
|
|
509
|
-
return /^(?:authorization|api[-_]?key|token|secret|password|headers|environment|env)$/iu.test(
|
|
510
|
-
key,
|
|
511
|
-
);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
function positiveInteger(value: string, name: string): number {
|
|
515
|
-
const parsed = Number(value);
|
|
516
|
-
if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > 2_147_483_647) {
|
|
517
|
-
throw new Error(`${name} must be a positive integer`);
|
|
518
|
-
}
|
|
519
|
-
return parsed;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
523
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
function isOneOf<const T extends readonly string[]>(value: string, values: T): value is T[number] {
|
|
527
|
-
return values.includes(value);
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
function round(value: number): number {
|
|
531
|
-
return Number(value.toFixed(3));
|
|
532
|
-
}
|
package/src/auto-transport.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { discoverAgents } from "./agents/discovery.js";
|
|
2
|
-
import type { SubagentSettings } from "./agents/types.js";
|
|
3
|
-
import type { AgentMailboxMessage, ManagedAgent, TurnOutcome } from "./registry.js";
|
|
4
|
-
import { isWriteCapable } from "./stateful-safety.js";
|
|
5
|
-
import type { SubagentTransport } from "./transport.js";
|
|
6
|
-
import type {
|
|
7
|
-
EffectiveSubagentTransportKind,
|
|
8
|
-
TransportProgressCallback,
|
|
9
|
-
} from "./transport-types.js";
|
|
10
|
-
|
|
11
|
-
const BUILT_IN_TOOL_NAMES = new Set(["read", "bash", "edit", "write", "grep", "find", "ls"]);
|
|
12
|
-
|
|
13
|
-
export interface AutoTransportOptions {
|
|
14
|
-
subprocess: SubagentTransport;
|
|
15
|
-
inProcess: SubagentTransport;
|
|
16
|
-
rpc: SubagentTransport;
|
|
17
|
-
getSettings?: () => SubagentSettings | undefined;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface AutoTransportSelection {
|
|
21
|
-
kind: EffectiveSubagentTransportKind;
|
|
22
|
-
reason: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class AutoTransport implements SubagentTransport {
|
|
26
|
-
readonly kind = "auto" as const;
|
|
27
|
-
private readonly selections = new Map<string, AutoTransportSelection>();
|
|
28
|
-
|
|
29
|
-
constructor(private readonly options: AutoTransportOptions) {}
|
|
30
|
-
|
|
31
|
-
async runTurn(
|
|
32
|
-
agent: ManagedAgent,
|
|
33
|
-
task: string,
|
|
34
|
-
signal: AbortSignal,
|
|
35
|
-
onProgress?: TransportProgressCallback,
|
|
36
|
-
): Promise<TurnOutcome> {
|
|
37
|
-
const selection = this.selections.get(agent.id) ?? this.select(agent);
|
|
38
|
-
this.selections.set(agent.id, selection);
|
|
39
|
-
const transport = this.transport(selection.kind);
|
|
40
|
-
const outcome = await transport.runTurn(agent, task, signal, (progress) =>
|
|
41
|
-
onProgress?.({ ...progress, selectionReason: selection.reason }),
|
|
42
|
-
);
|
|
43
|
-
return {
|
|
44
|
-
...outcome,
|
|
45
|
-
telemetry: outcome.telemetry
|
|
46
|
-
? { ...outcome.telemetry, selectionReason: selection.reason }
|
|
47
|
-
: outcome.telemetry,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async deliverMessage(agent: ManagedAgent, message: AgentMailboxMessage): Promise<boolean> {
|
|
52
|
-
const selection = this.selections.get(agent.id);
|
|
53
|
-
if (!selection) return false;
|
|
54
|
-
return this.transport(selection.kind).deliverMessage?.(agent, message) ?? false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async release(agent: ManagedAgent): Promise<void> {
|
|
58
|
-
const selection = this.selections.get(agent.id);
|
|
59
|
-
this.selections.delete(agent.id);
|
|
60
|
-
if (selection) await this.transport(selection.kind).release?.(agent);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async shutdown(): Promise<void> {
|
|
64
|
-
this.selections.clear();
|
|
65
|
-
const transports = [this.options.subprocess, this.options.inProcess, this.options.rpc];
|
|
66
|
-
const results = await Promise.allSettled(transports.map((transport) => transport.shutdown?.()));
|
|
67
|
-
const failures = results.flatMap((result) =>
|
|
68
|
-
result.status === "rejected" ? [result.reason] : [],
|
|
69
|
-
);
|
|
70
|
-
if (failures.length > 0) {
|
|
71
|
-
throw new AggregateError(
|
|
72
|
-
failures,
|
|
73
|
-
`Failed to shut down ${failures.length} auto transport(s)`,
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
selectionFor(agentId: string): AutoTransportSelection | undefined {
|
|
79
|
-
const selection = this.selections.get(agentId);
|
|
80
|
-
return selection ? { ...selection } : undefined;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private select(agent: ManagedAgent): AutoTransportSelection {
|
|
84
|
-
const settings = this.options.getSettings?.();
|
|
85
|
-
const config = discoverAgents(agent.cwd, agent.agentScope ?? "user", settings).agents.find(
|
|
86
|
-
(candidate) => candidate.name === agent.agent,
|
|
87
|
-
);
|
|
88
|
-
if (!config) {
|
|
89
|
-
throw new Error(`Automatic transport cannot resolve subagent ${agent.agent}`);
|
|
90
|
-
}
|
|
91
|
-
const effectiveTools = agent.executionPlan?.effectiveTools ?? config.tools;
|
|
92
|
-
const unsupported = (effectiveTools ?? []).filter((tool) => !BUILT_IN_TOOL_NAMES.has(tool));
|
|
93
|
-
if (unsupported.length > 0) {
|
|
94
|
-
return {
|
|
95
|
-
kind: "subprocess",
|
|
96
|
-
reason: `extension/custom tools require subprocess: ${unsupported.join(", ")}`,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
if (isWriteCapable(effectiveTools)) {
|
|
100
|
-
return {
|
|
101
|
-
kind: "rpc",
|
|
102
|
-
reason: "write-capable built-in tools use a persistent isolated process",
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
kind: "in-process",
|
|
107
|
-
reason: "read-only built-in tools use the lowest-overhead public SDK session",
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private transport(kind: EffectiveSubagentTransportKind): SubagentTransport {
|
|
112
|
-
switch (kind) {
|
|
113
|
-
case "subprocess":
|
|
114
|
-
return this.options.subprocess;
|
|
115
|
-
case "in-process":
|
|
116
|
-
return this.options.inProcess;
|
|
117
|
-
case "rpc":
|
|
118
|
-
return this.options.rpc;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|