@narumitw/pi-subagents 2.1.4 → 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 +187 -1228
- 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 -1614
- 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 -139
- package/docs/pi-subagents-diagrams.md +0 -183
- package/src/adaptive-scheduler.ts +0 -224
- 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/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 -372
- 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,305 +0,0 @@
|
|
|
1
|
-
import { redactPrivateText } from "./context.js";
|
|
2
|
-
import { DEFAULT_MAX_CONTEXT_BYTES, truncateUtf8 } from "./limits.js";
|
|
3
|
-
|
|
4
|
-
export const TIMEOUT_CHECKPOINT_VERSION = "pi-subagents:checkpoint:v1" as const;
|
|
5
|
-
export const TURN_TERMINATION_VERSION = "pi-subagents:termination:v1" as const;
|
|
6
|
-
|
|
7
|
-
const DEFAULT_CHECKPOINT_BYTES = 16 * 1024;
|
|
8
|
-
const MAX_ITEMS = 10;
|
|
9
|
-
const MAX_ITEM_BYTES = 2 * 1024;
|
|
10
|
-
const MAX_PENDING_TOOLS = 50;
|
|
11
|
-
const MUTATING_TOOLS = new Set(["bash", "edit", "write"]);
|
|
12
|
-
const FILE_TOOLS = new Set(["edit", "write"]);
|
|
13
|
-
|
|
14
|
-
export type TurnTerminationReason =
|
|
15
|
-
| "work_timeout"
|
|
16
|
-
| "idle_timeout"
|
|
17
|
-
| "turn_limit"
|
|
18
|
-
| "tool_call_limit"
|
|
19
|
-
| "orchestration_timeout";
|
|
20
|
-
|
|
21
|
-
export interface CompletedToolEvidence {
|
|
22
|
-
toolName: string;
|
|
23
|
-
output: string;
|
|
24
|
-
isError: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface TimeoutCheckpoint {
|
|
28
|
-
version: typeof TIMEOUT_CHECKPOINT_VERSION;
|
|
29
|
-
task: string;
|
|
30
|
-
partialOutput?: string;
|
|
31
|
-
assistantNotes: string[];
|
|
32
|
-
completedTools: CompletedToolEvidence[];
|
|
33
|
-
changedFiles: string[];
|
|
34
|
-
sideEffectsMayHaveOccurred: boolean;
|
|
35
|
-
truncated: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface TurnFinalizationReport {
|
|
39
|
-
attempted: boolean;
|
|
40
|
-
status: "completed" | "failed" | "timed_out" | "skipped";
|
|
41
|
-
durationMs: number;
|
|
42
|
-
error?: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface TurnTerminationReport {
|
|
46
|
-
version: typeof TURN_TERMINATION_VERSION;
|
|
47
|
-
reason: TurnTerminationReason;
|
|
48
|
-
limit: number;
|
|
49
|
-
checkpoint: TimeoutCheckpoint;
|
|
50
|
-
finalization: TurnFinalizationReport;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface TimeoutProgressJournalOptions {
|
|
54
|
-
maxBytes?: number;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
interface PendingToolCall {
|
|
58
|
-
name: string;
|
|
59
|
-
path?: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export class TimeoutProgressJournal {
|
|
63
|
-
private readonly assistantNotes: string[] = [];
|
|
64
|
-
private readonly completedTools: CompletedToolEvidence[] = [];
|
|
65
|
-
private readonly changedFiles = new Set<string>();
|
|
66
|
-
private readonly pendingTools = new Map<string, PendingToolCall>();
|
|
67
|
-
private readonly maxBytes: number;
|
|
68
|
-
private sideEffectsMayHaveOccurred = false;
|
|
69
|
-
private truncated = false;
|
|
70
|
-
|
|
71
|
-
constructor(options: TimeoutProgressJournalOptions = {}) {
|
|
72
|
-
const requested = options.maxBytes ?? DEFAULT_CHECKPOINT_BYTES;
|
|
73
|
-
if (
|
|
74
|
-
!Number.isSafeInteger(requested) ||
|
|
75
|
-
requested < 512 ||
|
|
76
|
-
requested > DEFAULT_MAX_CONTEXT_BYTES
|
|
77
|
-
) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
`Timeout checkpoint limit must be an integer between 512 and ${DEFAULT_MAX_CONTEXT_BYTES}`,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
this.maxBytes = requested;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
recordAssistantText(text: string): void {
|
|
86
|
-
const bounded = boundedPrivate(text, MAX_ITEM_BYTES);
|
|
87
|
-
if (!bounded) return;
|
|
88
|
-
this.assistantNotes.push(bounded);
|
|
89
|
-
this.trimItems(this.assistantNotes);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
recordToolCall(id: string, name: string, args: Record<string, unknown> = {}): void {
|
|
93
|
-
const toolName = boundedPrivate(name, 256);
|
|
94
|
-
if (!toolName) return;
|
|
95
|
-
const path = toolPath(args);
|
|
96
|
-
this.pendingTools.set(id, { name: toolName, path });
|
|
97
|
-
while (this.pendingTools.size > MAX_PENDING_TOOLS) {
|
|
98
|
-
const oldest = this.pendingTools.keys().next().value;
|
|
99
|
-
if (typeof oldest !== "string") break;
|
|
100
|
-
this.pendingTools.delete(oldest);
|
|
101
|
-
this.truncated = true;
|
|
102
|
-
}
|
|
103
|
-
if (MUTATING_TOOLS.has(toolName)) this.sideEffectsMayHaveOccurred = true;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
recordToolResult(
|
|
107
|
-
id: string,
|
|
108
|
-
name: string,
|
|
109
|
-
result: { content?: unknown; isError?: unknown },
|
|
110
|
-
): void {
|
|
111
|
-
const pending = this.pendingTools.get(id);
|
|
112
|
-
this.pendingTools.delete(id);
|
|
113
|
-
const toolName = boundedPrivate(pending?.name || name, 256);
|
|
114
|
-
if (!toolName) return;
|
|
115
|
-
if (pending?.path && FILE_TOOLS.has(toolName)) this.changedFiles.add(pending.path);
|
|
116
|
-
const output = boundedPrivate(textContent(result.content), MAX_ITEM_BYTES);
|
|
117
|
-
this.completedTools.push({
|
|
118
|
-
toolName,
|
|
119
|
-
output: output || "(no text output)",
|
|
120
|
-
isError: result.isError === true,
|
|
121
|
-
});
|
|
122
|
-
this.trimItems(this.completedTools);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
checkpoint(task: string, partialOutput?: string): TimeoutCheckpoint {
|
|
126
|
-
const checkpoint: TimeoutCheckpoint = {
|
|
127
|
-
version: TIMEOUT_CHECKPOINT_VERSION,
|
|
128
|
-
task: boundedPrivate(task, 4 * 1024),
|
|
129
|
-
partialOutput: partialOutput ? boundedPrivate(partialOutput, 4 * 1024) : undefined,
|
|
130
|
-
assistantNotes: [...this.assistantNotes],
|
|
131
|
-
completedTools: this.completedTools.map((item) => ({ ...item })),
|
|
132
|
-
changedFiles: [...this.changedFiles].slice(-MAX_ITEMS),
|
|
133
|
-
sideEffectsMayHaveOccurred: this.sideEffectsMayHaveOccurred,
|
|
134
|
-
truncated: this.truncated || this.changedFiles.size > MAX_ITEMS,
|
|
135
|
-
};
|
|
136
|
-
return fitCheckpoint(checkpoint, this.maxBytes);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
private trimItems(items: unknown[]): void {
|
|
140
|
-
if (items.length <= MAX_ITEMS) return;
|
|
141
|
-
items.splice(0, items.length - MAX_ITEMS);
|
|
142
|
-
this.truncated = true;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function formatTurnTerminationMessage(
|
|
147
|
-
reason: TurnTerminationReason,
|
|
148
|
-
limit: number,
|
|
149
|
-
prefix = "Subagent",
|
|
150
|
-
): string {
|
|
151
|
-
switch (reason) {
|
|
152
|
-
case "work_timeout":
|
|
153
|
-
return `${prefix} timed out after ${limit}ms`;
|
|
154
|
-
case "orchestration_timeout":
|
|
155
|
-
return `${prefix} orchestration deadline expired after ${limit}ms`;
|
|
156
|
-
case "idle_timeout":
|
|
157
|
-
return `${prefix} made no completed progress for ${limit}ms`;
|
|
158
|
-
case "turn_limit":
|
|
159
|
-
return `${prefix} reached the ${limit}-turn limit before producing a final answer`;
|
|
160
|
-
case "tool_call_limit":
|
|
161
|
-
return `${prefix} exceeded the ${limit}-tool-call limit`;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function copyTurnTerminationReport(report: TurnTerminationReport): TurnTerminationReport {
|
|
166
|
-
return {
|
|
167
|
-
...report,
|
|
168
|
-
checkpoint: {
|
|
169
|
-
...report.checkpoint,
|
|
170
|
-
assistantNotes: [...report.checkpoint.assistantNotes],
|
|
171
|
-
completedTools: report.checkpoint.completedTools.map((item) => ({ ...item })),
|
|
172
|
-
changedFiles: [...report.checkpoint.changedFiles],
|
|
173
|
-
},
|
|
174
|
-
finalization: { ...report.finalization },
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export function formatTimeoutCheckpoint(checkpoint: TimeoutCheckpoint): string {
|
|
179
|
-
const sections = [
|
|
180
|
-
checkpoint.partialOutput ? `Partial output:\n${checkpoint.partialOutput}` : undefined,
|
|
181
|
-
checkpoint.assistantNotes.length > 0
|
|
182
|
-
? `Assistant checkpoints:\n${checkpoint.assistantNotes.map((note) => `- ${note}`).join("\n")}`
|
|
183
|
-
: undefined,
|
|
184
|
-
checkpoint.completedTools.length > 0
|
|
185
|
-
? `Completed tool evidence:\n${checkpoint.completedTools
|
|
186
|
-
.map((item) => `- ${item.toolName}${item.isError ? " (error)" : ""}: ${item.output}`)
|
|
187
|
-
.join("\n")}`
|
|
188
|
-
: undefined,
|
|
189
|
-
checkpoint.changedFiles.length > 0
|
|
190
|
-
? `Changed files: ${checkpoint.changedFiles.join(", ")}`
|
|
191
|
-
: undefined,
|
|
192
|
-
checkpoint.sideEffectsMayHaveOccurred
|
|
193
|
-
? "Side effects may have occurred before termination."
|
|
194
|
-
: undefined,
|
|
195
|
-
checkpoint.truncated ? "Checkpoint evidence was truncated." : undefined,
|
|
196
|
-
].filter((value): value is string => Boolean(value));
|
|
197
|
-
return truncateUtf8(
|
|
198
|
-
sections.join("\n\n") || "No completed evidence was captured.",
|
|
199
|
-
DEFAULT_MAX_CONTEXT_BYTES,
|
|
200
|
-
).text;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export function journalMessages(
|
|
204
|
-
journal: TimeoutProgressJournal,
|
|
205
|
-
messages: readonly unknown[],
|
|
206
|
-
): void {
|
|
207
|
-
for (const message of messages) {
|
|
208
|
-
if (!message || typeof message !== "object" || Array.isArray(message)) continue;
|
|
209
|
-
const value = message as Record<string, unknown>;
|
|
210
|
-
if (value.role === "assistant" && Array.isArray(value.content)) {
|
|
211
|
-
for (const part of value.content) {
|
|
212
|
-
if (!part || typeof part !== "object" || Array.isArray(part)) continue;
|
|
213
|
-
const item = part as Record<string, unknown>;
|
|
214
|
-
if (item.type === "text" && typeof item.text === "string") {
|
|
215
|
-
journal.recordAssistantText(item.text);
|
|
216
|
-
} else if (
|
|
217
|
-
item.type === "toolCall" &&
|
|
218
|
-
typeof item.id === "string" &&
|
|
219
|
-
typeof item.name === "string"
|
|
220
|
-
) {
|
|
221
|
-
journal.recordToolCall(
|
|
222
|
-
item.id,
|
|
223
|
-
item.name,
|
|
224
|
-
isRecord(item.arguments) ? item.arguments : {},
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
} else if (value.role === "toolResult") {
|
|
229
|
-
journal.recordToolResult(
|
|
230
|
-
typeof value.toolCallId === "string" ? value.toolCallId : "",
|
|
231
|
-
typeof value.toolName === "string" ? value.toolName : "tool",
|
|
232
|
-
{ content: value.content, isError: value.isError },
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function fitCheckpoint(checkpoint: TimeoutCheckpoint, maxBytes: number): TimeoutCheckpoint {
|
|
239
|
-
const copy: TimeoutCheckpoint = {
|
|
240
|
-
...checkpoint,
|
|
241
|
-
assistantNotes: [...checkpoint.assistantNotes],
|
|
242
|
-
completedTools: checkpoint.completedTools.map((item) => ({ ...item })),
|
|
243
|
-
changedFiles: [...checkpoint.changedFiles],
|
|
244
|
-
};
|
|
245
|
-
while (serializedBytes(copy) > maxBytes) {
|
|
246
|
-
copy.truncated = true;
|
|
247
|
-
if (copy.assistantNotes.length > 0) copy.assistantNotes.shift();
|
|
248
|
-
else if (copy.completedTools.length > 0) copy.completedTools.shift();
|
|
249
|
-
else if (copy.changedFiles.length > 0) copy.changedFiles.shift();
|
|
250
|
-
else if (copy.partialOutput) {
|
|
251
|
-
copy.partialOutput =
|
|
252
|
-
shrinkCheckpointText(copy.partialOutput, Math.floor(maxBytes / 4), 128) || undefined;
|
|
253
|
-
} else if (copy.task) {
|
|
254
|
-
copy.task = shrinkCheckpointText(copy.task, Math.floor(maxBytes / 8), 64);
|
|
255
|
-
} else break;
|
|
256
|
-
}
|
|
257
|
-
return copy;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function shrinkCheckpointText(
|
|
261
|
-
value: string,
|
|
262
|
-
preferredMaxBytes: number,
|
|
263
|
-
minimumBytes: number,
|
|
264
|
-
): string {
|
|
265
|
-
const currentBytes = Buffer.byteLength(value, "utf8");
|
|
266
|
-
if (currentBytes <= minimumBytes) return "";
|
|
267
|
-
const nextMaxBytes = Math.min(
|
|
268
|
-
currentBytes - 1,
|
|
269
|
-
preferredMaxBytes,
|
|
270
|
-
Math.max(minimumBytes, Math.floor(currentBytes / 2)),
|
|
271
|
-
);
|
|
272
|
-
return truncateUtf8(value, nextMaxBytes).text;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function serializedBytes(value: unknown): number {
|
|
276
|
-
return Buffer.byteLength(JSON.stringify(value), "utf8");
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
function boundedPrivate(value: string, maxBytes: number): string {
|
|
280
|
-
return truncateUtf8(redactPrivateText(value).trim(), maxBytes).text;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
function textContent(value: unknown): string {
|
|
284
|
-
if (typeof value === "string") return value;
|
|
285
|
-
if (!Array.isArray(value)) return "";
|
|
286
|
-
return value
|
|
287
|
-
.flatMap((part) => {
|
|
288
|
-
if (!part || typeof part !== "object" || Array.isArray(part)) return [];
|
|
289
|
-
const item = part as Record<string, unknown>;
|
|
290
|
-
return item.type === "text" && typeof item.text === "string" ? [item.text] : [];
|
|
291
|
-
})
|
|
292
|
-
.join("\n");
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function toolPath(args: Record<string, unknown>): string | undefined {
|
|
296
|
-
for (const key of ["path", "file_path"]) {
|
|
297
|
-
const value = args[key];
|
|
298
|
-
if (typeof value === "string" && value.trim()) return boundedPrivate(value, 1024);
|
|
299
|
-
}
|
|
300
|
-
return undefined;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
304
|
-
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
305
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { redactPrivateText } from "./context.js";
|
|
2
|
-
import { DEFAULT_MAX_CONTEXT_BYTES, truncateUtf8 } from "./limits.js";
|
|
3
|
-
import { appendResultInstruction, type SubagentResultFormat } from "./result-contract.js";
|
|
4
|
-
import type { RecentActivityItem } from "./runner-types.js";
|
|
5
|
-
import {
|
|
6
|
-
formatTimeoutCheckpoint,
|
|
7
|
-
type TimeoutCheckpoint,
|
|
8
|
-
type TurnTerminationReason,
|
|
9
|
-
} from "./timeout-checkpoint.js";
|
|
10
|
-
|
|
11
|
-
export const DEFAULT_TIMEOUT_FINALIZATION_MS = 45_000;
|
|
12
|
-
|
|
13
|
-
export interface TimeoutFinalizationEvidence {
|
|
14
|
-
task: string;
|
|
15
|
-
partialOutput?: string;
|
|
16
|
-
recentActivity?: readonly RecentActivityItem[];
|
|
17
|
-
checkpoint?: TimeoutCheckpoint;
|
|
18
|
-
terminationReason?: TurnTerminationReason;
|
|
19
|
-
resultFormat?: SubagentResultFormat;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function resolveTimeoutFinalizationMs(workTimeoutMs: number, override?: number): number {
|
|
23
|
-
const requested = override ?? Math.min(workTimeoutMs, DEFAULT_TIMEOUT_FINALIZATION_MS);
|
|
24
|
-
if (!Number.isFinite(requested) || requested < 1) {
|
|
25
|
-
throw new Error("Timeout finalization deadline must be a positive finite number");
|
|
26
|
-
}
|
|
27
|
-
return Math.min(Math.floor(requested), DEFAULT_TIMEOUT_FINALIZATION_MS);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function buildTimeoutFinalizationPrompt(
|
|
31
|
-
evidence: TimeoutFinalizationEvidence,
|
|
32
|
-
maxBytes = DEFAULT_MAX_CONTEXT_BYTES,
|
|
33
|
-
): string {
|
|
34
|
-
const activity = (evidence.recentActivity ?? [])
|
|
35
|
-
.slice(-10)
|
|
36
|
-
.map((item) =>
|
|
37
|
-
item.type === "text"
|
|
38
|
-
? `- Assistant note: ${redactPrivateText(item.text)}`
|
|
39
|
-
: `- Tool activity: ${redactPrivateText(item.name)}`,
|
|
40
|
-
)
|
|
41
|
-
.join("\n");
|
|
42
|
-
const prompt = [
|
|
43
|
-
terminationHeading(evidence.terminationReason),
|
|
44
|
-
"Do not continue investigating, call tools, modify files, or retry the original task.",
|
|
45
|
-
"Return a concise summary of only verified findings and completed evidence already available.",
|
|
46
|
-
"Explicitly label unfinished or unverified areas.",
|
|
47
|
-
`Original task:\n${redactPrivateText(evidence.task)}`,
|
|
48
|
-
evidence.partialOutput
|
|
49
|
-
? `Partial assistant output:\n${redactPrivateText(evidence.partialOutput)}`
|
|
50
|
-
: "Partial assistant output: (none)",
|
|
51
|
-
evidence.checkpoint
|
|
52
|
-
? `Deterministic progress checkpoint:\n${formatTimeoutCheckpoint(evidence.checkpoint)}`
|
|
53
|
-
: undefined,
|
|
54
|
-
activity ? `Recent bounded activity:\n${activity}` : "Recent bounded activity: (none)",
|
|
55
|
-
]
|
|
56
|
-
.filter((value): value is string => Boolean(value))
|
|
57
|
-
.join("\n\n");
|
|
58
|
-
return truncateUtf8(appendResultInstruction(prompt, evidence.resultFormat, maxBytes), maxBytes)
|
|
59
|
-
.text;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function terminationHeading(reason: TurnTerminationReason | undefined): string {
|
|
63
|
-
switch (reason) {
|
|
64
|
-
case "idle_timeout":
|
|
65
|
-
return "The idle deadline expired and the active work was aborted.";
|
|
66
|
-
case "turn_limit":
|
|
67
|
-
return "The assistant-turn budget was exhausted and the active work was aborted.";
|
|
68
|
-
case "tool_call_limit":
|
|
69
|
-
return "The tool-call budget was exhausted and the active work was aborted.";
|
|
70
|
-
case "orchestration_timeout":
|
|
71
|
-
return "The orchestration deadline expired and the active work was aborted.";
|
|
72
|
-
default:
|
|
73
|
-
return "Work deadline expired and the active work was aborted.";
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { type TObject, type TObjectOptions, type TProperties, type TSchema, Type } from "typebox";
|
|
2
|
-
|
|
3
|
-
const LLAMA_CPP_MAX_REPETITION_THRESHOLD = 2_000;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Remove large nested string repetitions that llama.cpp cannot compile into GBNF.
|
|
7
|
-
*
|
|
8
|
-
* Runtime normalization and validation continue to bound these inputs.
|
|
9
|
-
* See https://github.com/ggml-org/llama.cpp/issues/25746.
|
|
10
|
-
*/
|
|
11
|
-
export function grammarSafeToolObject<Properties extends TProperties>(
|
|
12
|
-
properties: Properties,
|
|
13
|
-
options?: TObjectOptions,
|
|
14
|
-
): TObject<Properties> {
|
|
15
|
-
return makeGrammarSafeToolSchema(Type.Object(properties, options));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function makeGrammarSafeToolSchema<Schema extends TSchema>(schema: Schema): Schema {
|
|
19
|
-
return cloneSchema(schema, 0) as Schema;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function cloneSchema(schema: unknown, depth: number): unknown {
|
|
23
|
-
if (!isRecord(schema)) return schema;
|
|
24
|
-
const clone = cloneWithDescriptors(schema);
|
|
25
|
-
if (
|
|
26
|
-
depth > 1 &&
|
|
27
|
-
clone.type === "string" &&
|
|
28
|
-
typeof clone.maxLength === "number" &&
|
|
29
|
-
clone.maxLength >= LLAMA_CPP_MAX_REPETITION_THRESHOLD
|
|
30
|
-
) {
|
|
31
|
-
delete clone.maxLength;
|
|
32
|
-
}
|
|
33
|
-
if (isRecord(clone.properties)) {
|
|
34
|
-
clone.properties = mapSchemas(clone.properties, depth + 1);
|
|
35
|
-
}
|
|
36
|
-
if (clone.items !== undefined) {
|
|
37
|
-
clone.items = Array.isArray(clone.items)
|
|
38
|
-
? clone.items.map((item) => cloneSchema(item, depth + 1))
|
|
39
|
-
: cloneSchema(clone.items, depth + 1);
|
|
40
|
-
}
|
|
41
|
-
if (Array.isArray(clone.prefixItems)) {
|
|
42
|
-
clone.prefixItems = clone.prefixItems.map((item) => cloneSchema(item, depth + 1));
|
|
43
|
-
}
|
|
44
|
-
for (const keyword of ["allOf", "anyOf", "oneOf"] as const) {
|
|
45
|
-
if (Array.isArray(clone[keyword])) {
|
|
46
|
-
clone[keyword] = clone[keyword].map((item) => cloneSchema(item, depth));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (isRecord(clone.patternProperties)) {
|
|
50
|
-
clone.patternProperties = mapSchemas(clone.patternProperties, depth + 1);
|
|
51
|
-
}
|
|
52
|
-
if (isRecord(clone.additionalProperties)) {
|
|
53
|
-
clone.additionalProperties = cloneSchema(clone.additionalProperties, depth + 1);
|
|
54
|
-
}
|
|
55
|
-
return clone;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function mapSchemas(schemas: Record<string, unknown>, depth: number): Record<string, unknown> {
|
|
59
|
-
return Object.fromEntries(
|
|
60
|
-
Object.entries(schemas).map(([name, schema]) => [name, cloneSchema(schema, depth)]),
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function cloneWithDescriptors(value: Record<string, unknown>): Record<string, unknown> {
|
|
65
|
-
return Object.defineProperties(
|
|
66
|
-
Object.create(Object.getPrototypeOf(value)),
|
|
67
|
-
Object.getOwnPropertyDescriptors(value),
|
|
68
|
-
) as Record<string, unknown>;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
72
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
73
|
-
}
|
package/src/transport-types.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { SubagentThinkingLevel } from "./agents/types.js";
|
|
2
|
-
|
|
3
|
-
export const PI_SUBAGENTS_RPC_PROTOCOL = "pi-subagents:v1" as const;
|
|
4
|
-
|
|
5
|
-
export type EffectiveSubagentTransportKind = "subprocess" | "in-process" | "rpc";
|
|
6
|
-
|
|
7
|
-
export type TransportProgressPhase =
|
|
8
|
-
| "queued"
|
|
9
|
-
| "starting"
|
|
10
|
-
| "ready"
|
|
11
|
-
| "accepted"
|
|
12
|
-
| "running"
|
|
13
|
-
| "finalizing"
|
|
14
|
-
| "retrying"
|
|
15
|
-
| "compacting"
|
|
16
|
-
| "settled"
|
|
17
|
-
| "failed"
|
|
18
|
-
| "interrupted";
|
|
19
|
-
|
|
20
|
-
export interface TransportUsage {
|
|
21
|
-
input: number;
|
|
22
|
-
output: number;
|
|
23
|
-
cacheRead: number;
|
|
24
|
-
cacheWrite: number;
|
|
25
|
-
totalTokens: number;
|
|
26
|
-
cost: number;
|
|
27
|
-
turns: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface TransportTiming {
|
|
31
|
-
queuedAt?: number;
|
|
32
|
-
startedAt?: number;
|
|
33
|
-
transportStartedAt?: number;
|
|
34
|
-
readyAt?: number;
|
|
35
|
-
promptAcceptedAt?: number;
|
|
36
|
-
firstActivityAt?: number;
|
|
37
|
-
settledAt?: number;
|
|
38
|
-
completionDeliveredAt?: number;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface TransportTelemetry {
|
|
42
|
-
transport?: EffectiveSubagentTransportKind;
|
|
43
|
-
selectionReason?: string;
|
|
44
|
-
protocol?: typeof PI_SUBAGENTS_RPC_PROTOCOL;
|
|
45
|
-
phase: TransportProgressPhase;
|
|
46
|
-
queuePosition?: number;
|
|
47
|
-
updatedAt: number;
|
|
48
|
-
timing: TransportTiming;
|
|
49
|
-
provider?: string;
|
|
50
|
-
model?: string;
|
|
51
|
-
thinkingLevel?: SubagentThinkingLevel;
|
|
52
|
-
usage?: TransportUsage;
|
|
53
|
-
budgetSource?: {
|
|
54
|
-
timeout: "runtime" | "explicit";
|
|
55
|
-
idleTimeout: "runtime" | "explicit";
|
|
56
|
-
turnLimit: "runtime" | "explicit";
|
|
57
|
-
toolCallLimit: "runtime" | "explicit";
|
|
58
|
-
};
|
|
59
|
-
failurePhase?: TransportProgressPhase;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export type TransportProgressCallback = (progress: TransportTelemetry) => void;
|
|
63
|
-
|
|
64
|
-
export function emptyTransportUsage(): TransportUsage {
|
|
65
|
-
return {
|
|
66
|
-
input: 0,
|
|
67
|
-
output: 0,
|
|
68
|
-
cacheRead: 0,
|
|
69
|
-
cacheWrite: 0,
|
|
70
|
-
totalTokens: 0,
|
|
71
|
-
cost: 0,
|
|
72
|
-
turns: 0,
|
|
73
|
-
};
|
|
74
|
-
}
|
package/src/transport-ui.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { SubagentTransportKind } from "./agents/types.js";
|
|
3
|
-
import { safeTerminalLine as safeTerminalText } from "./safe-text.js";
|
|
4
|
-
import { inspectStatefulTransportSettings, updateStatefulTransportSetting } from "./settings.js";
|
|
5
|
-
import type { StatefulSubagentRuntimeStatus } from "./stateful.js";
|
|
6
|
-
|
|
7
|
-
const TRANSPORT_OPTIONS: Array<{
|
|
8
|
-
value: SubagentTransportKind;
|
|
9
|
-
label: string;
|
|
10
|
-
description: string;
|
|
11
|
-
}> = [
|
|
12
|
-
{
|
|
13
|
-
value: "subprocess",
|
|
14
|
-
label: "Fresh process",
|
|
15
|
-
description:
|
|
16
|
-
"Start a separate Pi process for every turn. Most compatible, but slower for follow-ups.",
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
value: "in-process",
|
|
20
|
-
label: "Inside Pi",
|
|
21
|
-
description:
|
|
22
|
-
"Run built-in tools inside Pi for faster follow-ups. Shares Pi's memory and crash boundary.",
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
value: "rpc",
|
|
26
|
-
label: "Persistent process (RPC)",
|
|
27
|
-
description:
|
|
28
|
-
"Keep one separate Pi process per background subagent so follow-ups preserve history.",
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
value: "auto",
|
|
32
|
-
label: "Automatic · Recommended",
|
|
33
|
-
description: "Let Pi choose a compatible method for each subagent and its tools.",
|
|
34
|
-
},
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
export interface TransportUiRuntime {
|
|
38
|
-
getRuntimeStatus(): StatefulSubagentRuntimeStatus;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function transportSettingsScreen(runtime: TransportUiRuntime) {
|
|
42
|
-
const configured = inspectStatefulTransportSettings();
|
|
43
|
-
const current = runtime.getRuntimeStatus();
|
|
44
|
-
return {
|
|
45
|
-
kind: "actions" as const,
|
|
46
|
-
title: configured.error
|
|
47
|
-
? "Background Agent Transport · Read only"
|
|
48
|
-
: "Background Agent Transport",
|
|
49
|
-
lines: [
|
|
50
|
-
"Advanced: choose how Pi hosts background subagents.",
|
|
51
|
-
`Current session: ${transportLabel(current.transport)}`,
|
|
52
|
-
`Configured after reload: ${transportLabel(configured.value)} (${configured.source})`,
|
|
53
|
-
"Separate processes do not restrict filesystem or network access.",
|
|
54
|
-
"Persistent process (RPC) supports built-in Pi tools and does not load child extensions.",
|
|
55
|
-
...(configured.error
|
|
56
|
-
? [
|
|
57
|
-
`Settings cannot be edited: ${safeTerminalText(configured.error)}`,
|
|
58
|
-
`Repair ${safeTerminalText(configured.path)} and retry.`,
|
|
59
|
-
]
|
|
60
|
-
: []),
|
|
61
|
-
],
|
|
62
|
-
items: [
|
|
63
|
-
...(configured.error
|
|
64
|
-
? []
|
|
65
|
-
: TRANSPORT_OPTIONS.map((option) => ({
|
|
66
|
-
id: option.value,
|
|
67
|
-
label: option.label,
|
|
68
|
-
description: option.description,
|
|
69
|
-
action: "set-transport" as const,
|
|
70
|
-
}))),
|
|
71
|
-
{ id: "back", label: "Back", action: "back" as const },
|
|
72
|
-
],
|
|
73
|
-
hint: "back" as const,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export async function applyTransportSetting(
|
|
78
|
-
value: string,
|
|
79
|
-
ctx: ExtensionCommandContext,
|
|
80
|
-
runtime: TransportUiRuntime,
|
|
81
|
-
signal: AbortSignal,
|
|
82
|
-
isCurrent: () => boolean,
|
|
83
|
-
) {
|
|
84
|
-
if (!isTransport(value)) return { kind: "rejected" as const };
|
|
85
|
-
const before = inspectStatefulTransportSettings();
|
|
86
|
-
if (before.error) return { kind: "rejected" as const };
|
|
87
|
-
if (value === before.value) return { kind: "stay" as const };
|
|
88
|
-
const status = runtime.getRuntimeStatus();
|
|
89
|
-
if (status.retainedAgents > 0) {
|
|
90
|
-
ctx.ui.notify(
|
|
91
|
-
`Cannot change transport while ${status.retainedAgents} subagent${status.retainedAgents === 1 ? " is" : "s are"} saved for follow-up. Clear Current subagents first.`,
|
|
92
|
-
"warning",
|
|
93
|
-
);
|
|
94
|
-
return { kind: "rejected" as const };
|
|
95
|
-
}
|
|
96
|
-
const option = TRANSPORT_OPTIONS.find((candidate) => candidate.value === value);
|
|
97
|
-
const confirmed = await ctx.ui.confirm(
|
|
98
|
-
`Use ${transportLabel(value)} after reload?`,
|
|
99
|
-
`${option?.description ?? ""}\n\nThis saves the setting but does not reload Pi automatically.`,
|
|
100
|
-
{ signal },
|
|
101
|
-
);
|
|
102
|
-
if (signal.aborted || !isCurrent()) return { kind: "close" as const };
|
|
103
|
-
if (!confirmed) return { kind: "rejected" as const };
|
|
104
|
-
const after = inspectStatefulTransportSettings();
|
|
105
|
-
if (after.error || after.value !== before.value || after.source !== before.source) {
|
|
106
|
-
ctx.ui.notify("Transport settings changed while confirming; review again.", "warning");
|
|
107
|
-
return { kind: "rejected" as const };
|
|
108
|
-
}
|
|
109
|
-
if (runtime.getRuntimeStatus().retainedAgents > 0) {
|
|
110
|
-
ctx.ui.notify(
|
|
111
|
-
"New subagents were saved for follow-up while confirming. Clear them before changing transport.",
|
|
112
|
-
"warning",
|
|
113
|
-
);
|
|
114
|
-
return { kind: "rejected" as const };
|
|
115
|
-
}
|
|
116
|
-
try {
|
|
117
|
-
updateStatefulTransportSetting(value);
|
|
118
|
-
ctx.ui.notify(`Saved ${transportLabel(value)}. Run /reload when ready.`, "info");
|
|
119
|
-
return { kind: "stay" as const };
|
|
120
|
-
} catch (error) {
|
|
121
|
-
ctx.ui.notify(
|
|
122
|
-
`Transport was not saved; the previous setting remains: ${safeTerminalText(error instanceof Error ? error.message : String(error))}`,
|
|
123
|
-
"error",
|
|
124
|
-
);
|
|
125
|
-
return { kind: "rejected" as const };
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function transportLabel(value: SubagentTransportKind): string {
|
|
130
|
-
return TRANSPORT_OPTIONS.find((option) => option.value === value)?.label ?? value;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function isTransport(value: string): value is SubagentTransportKind {
|
|
134
|
-
return ["subprocess", "in-process", "rpc", "auto"].includes(value);
|
|
135
|
-
}
|