@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/execution-plan.ts
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import {
|
|
3
|
-
type DelegationAdmissionDecision,
|
|
4
|
-
evaluateDelegationAdmission,
|
|
5
|
-
} from "./admission-policy.js";
|
|
6
|
-
import {
|
|
7
|
-
type AgentConfig,
|
|
8
|
-
type AgentSource,
|
|
9
|
-
resolveAgentToolNames,
|
|
10
|
-
type SubagentThinkingLevel,
|
|
11
|
-
} from "./agents/types.js";
|
|
12
|
-
import type { TargetPolicyAudit } from "./cwd-policy.js";
|
|
13
|
-
import type { DelegationContract } from "./delegation-contract.js";
|
|
14
|
-
import type { SubagentResultFormat } from "./result-contract.js";
|
|
15
|
-
|
|
16
|
-
export const EXECUTION_PLAN_VERSION = "pi-subagents:execution-plan:v1" as const;
|
|
17
|
-
export const EXECUTION_ACKNOWLEDGEMENT_VERSION = "pi-subagents:acknowledgement:v1" as const;
|
|
18
|
-
|
|
19
|
-
export type CapabilityFit = "match" | "mismatch" | "unknown";
|
|
20
|
-
export type ExecutionPlanTransport = "subprocess" | "in-process" | "rpc" | "auto";
|
|
21
|
-
|
|
22
|
-
export interface ExecutionPlanAgentProjection {
|
|
23
|
-
name: string;
|
|
24
|
-
source: AgentSource;
|
|
25
|
-
capabilitiesKnown: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface ExecutionPlan {
|
|
29
|
-
version: typeof EXECUTION_PLAN_VERSION;
|
|
30
|
-
id: string;
|
|
31
|
-
mode: "audit" | "enforce";
|
|
32
|
-
taskId?: string;
|
|
33
|
-
taskGeneration: number;
|
|
34
|
-
cancellationLineage: string[];
|
|
35
|
-
admission: DelegationAdmissionDecision;
|
|
36
|
-
agent: ExecutionPlanAgentProjection;
|
|
37
|
-
capabilityFit: CapabilityFit;
|
|
38
|
-
missingCapabilities: string[];
|
|
39
|
-
requestedCapabilities: string[];
|
|
40
|
-
declaredCapabilities: string[];
|
|
41
|
-
requestedTools: string[];
|
|
42
|
-
effectiveTools?: string[];
|
|
43
|
-
missingTools: string[];
|
|
44
|
-
overgrantedTools: string[];
|
|
45
|
-
resultFormat: SubagentResultFormat;
|
|
46
|
-
sideEffectPolicy: "read-only" | "idempotent" | "mutating";
|
|
47
|
-
resultFormatSupported: boolean | "unknown";
|
|
48
|
-
target: TargetPolicyAudit;
|
|
49
|
-
workspaceMode: "shared" | "worktree";
|
|
50
|
-
transport: ExecutionPlanTransport;
|
|
51
|
-
model?: string;
|
|
52
|
-
thinkingLevel?: SubagentThinkingLevel;
|
|
53
|
-
timeoutMs?: number;
|
|
54
|
-
unsupportedGuarantees: string[];
|
|
55
|
-
warnings: string[];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface ExecutionAcknowledgement {
|
|
59
|
-
version: typeof EXECUTION_ACKNOWLEDGEMENT_VERSION;
|
|
60
|
-
status: "accepted" | "rejected";
|
|
61
|
-
reasonCodes: string[];
|
|
62
|
-
recoveryActions: string[];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface CreateExecutionPlanInput {
|
|
66
|
-
contract?: DelegationContract;
|
|
67
|
-
agent: AgentConfig;
|
|
68
|
-
effectiveTools?: string[];
|
|
69
|
-
target: TargetPolicyAudit;
|
|
70
|
-
workspaceMode: "shared" | "worktree";
|
|
71
|
-
transport: ExecutionPlanTransport;
|
|
72
|
-
resultFormat: SubagentResultFormat;
|
|
73
|
-
model?: string;
|
|
74
|
-
thinkingLevel?: SubagentThinkingLevel;
|
|
75
|
-
timeoutMs?: number;
|
|
76
|
-
taskGeneration?: number;
|
|
77
|
-
cancellationLineage?: string[];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function createExecutionPlan(input: CreateExecutionPlanInput): ExecutionPlan {
|
|
81
|
-
const manifest = input.agent.capabilityManifest;
|
|
82
|
-
const requestedCapabilities = unique(input.contract?.requestedAuthority?.capabilities ?? []);
|
|
83
|
-
const declaredCapabilities = unique(manifest?.capabilities ?? []);
|
|
84
|
-
const missingCapabilities = requestedCapabilities.filter(
|
|
85
|
-
(capability) => !declaredCapabilities.includes(capability),
|
|
86
|
-
);
|
|
87
|
-
const capabilityFit: CapabilityFit = manifest
|
|
88
|
-
? missingCapabilities.length > 0
|
|
89
|
-
? "mismatch"
|
|
90
|
-
: "match"
|
|
91
|
-
: "unknown";
|
|
92
|
-
const requestedTools = unique(input.contract?.requestedAuthority?.tools ?? []);
|
|
93
|
-
const effectiveTools = input.effectiveTools ? unique(input.effectiveTools) : undefined;
|
|
94
|
-
const missingTools = requestedTools.filter((tool) => !(effectiveTools ?? []).includes(tool));
|
|
95
|
-
const overgrantedTools =
|
|
96
|
-
requestedTools.length === 0
|
|
97
|
-
? []
|
|
98
|
-
: (effectiveTools ?? []).filter((tool) => !requestedTools.includes(tool));
|
|
99
|
-
const resultFormatSupported = manifest
|
|
100
|
-
? manifest.resultFormats.includes(input.resultFormat)
|
|
101
|
-
: "unknown";
|
|
102
|
-
const unsupportedGuarantees = unsupported(input.contract);
|
|
103
|
-
const taskGeneration = input.taskGeneration ?? 0;
|
|
104
|
-
const cancellationLineage = [...(input.cancellationLineage ?? [])];
|
|
105
|
-
const admissionRequest = input.contract?.admission;
|
|
106
|
-
const admission = evaluateDelegationAdmission({
|
|
107
|
-
contextPressure: admissionRequest?.contextPressure ?? "low",
|
|
108
|
-
independentWorkItems: admissionRequest?.independentWorkItems ?? 1,
|
|
109
|
-
coupling: admissionRequest?.coupling ?? "dense",
|
|
110
|
-
verificationRequired: admissionRequest?.verificationRequired ?? false,
|
|
111
|
-
verificationAvailable: admissionRequest?.verificationAvailable ?? false,
|
|
112
|
-
capabilitiesSupported: capabilityFit === "match" && missingTools.length === 0,
|
|
113
|
-
budgetAllowsChildren: admissionRequest?.budgetAllowsChildren ?? true,
|
|
114
|
-
generationCurrent: true,
|
|
115
|
-
requirementsComplete: admissionRequest?.requirementsComplete ?? false,
|
|
116
|
-
});
|
|
117
|
-
const warnings: string[] = [];
|
|
118
|
-
if (!manifest) warnings.push("agent-capabilities-unknown");
|
|
119
|
-
if (missingCapabilities.length > 0) warnings.push("capability-mismatch");
|
|
120
|
-
if (missingTools.length > 0) warnings.push("requested-tools-missing");
|
|
121
|
-
if (overgrantedTools.length > 0) warnings.push("tools-overgranted");
|
|
122
|
-
if (resultFormatSupported === false) warnings.push("result-format-unsupported");
|
|
123
|
-
if (unsupportedGuarantees.length > 0) warnings.push("unsupported-guarantees");
|
|
124
|
-
const planWithoutId: Omit<ExecutionPlan, "id"> = {
|
|
125
|
-
version: EXECUTION_PLAN_VERSION,
|
|
126
|
-
mode: input.contract?.enforcement ?? "audit",
|
|
127
|
-
...(input.contract?.taskId ? { taskId: input.contract.taskId } : {}),
|
|
128
|
-
agent: {
|
|
129
|
-
name: input.agent.name,
|
|
130
|
-
source: input.agent.source,
|
|
131
|
-
capabilitiesKnown: manifest !== undefined,
|
|
132
|
-
},
|
|
133
|
-
capabilityFit,
|
|
134
|
-
missingCapabilities,
|
|
135
|
-
requestedCapabilities,
|
|
136
|
-
declaredCapabilities,
|
|
137
|
-
requestedTools,
|
|
138
|
-
...(effectiveTools === undefined ? {} : { effectiveTools }),
|
|
139
|
-
missingTools,
|
|
140
|
-
overgrantedTools,
|
|
141
|
-
resultFormat: input.resultFormat,
|
|
142
|
-
sideEffectPolicy: input.contract?.sideEffectPolicy ?? "mutating",
|
|
143
|
-
resultFormatSupported,
|
|
144
|
-
target: structuredClone(input.target),
|
|
145
|
-
workspaceMode: input.workspaceMode,
|
|
146
|
-
transport: input.transport,
|
|
147
|
-
...(input.model === undefined ? {} : { model: input.model }),
|
|
148
|
-
...(input.thinkingLevel === undefined ? {} : { thinkingLevel: input.thinkingLevel }),
|
|
149
|
-
...(input.timeoutMs === undefined ? {} : { timeoutMs: input.timeoutMs }),
|
|
150
|
-
unsupportedGuarantees,
|
|
151
|
-
warnings,
|
|
152
|
-
taskGeneration,
|
|
153
|
-
cancellationLineage,
|
|
154
|
-
admission,
|
|
155
|
-
};
|
|
156
|
-
return { ...planWithoutId, id: executionPlanId(planWithoutId) };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export function resolveContractTools(
|
|
160
|
-
configuredTools: string[] | undefined,
|
|
161
|
-
contract: DelegationContract | undefined,
|
|
162
|
-
): string[] | undefined {
|
|
163
|
-
const requested = contract?.requestedAuthority?.tools;
|
|
164
|
-
if (contract?.enforcement !== "enforce" || requested === undefined) {
|
|
165
|
-
return configuredTools ? unique(configuredTools) : undefined;
|
|
166
|
-
}
|
|
167
|
-
const availableTools = resolveAgentToolNames(configuredTools);
|
|
168
|
-
return unique(requested.filter((tool) => availableTools.includes(tool)));
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export function acknowledgeExecutionPlan(plan: ExecutionPlan): ExecutionAcknowledgement {
|
|
172
|
-
if (plan.mode === "audit") {
|
|
173
|
-
return {
|
|
174
|
-
version: EXECUTION_ACKNOWLEDGEMENT_VERSION,
|
|
175
|
-
status: "accepted",
|
|
176
|
-
reasonCodes: [],
|
|
177
|
-
recoveryActions: [],
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
const reasonCodes: string[] = [];
|
|
181
|
-
const recoveryActions: string[] = [];
|
|
182
|
-
if (plan.capabilityFit === "unknown") {
|
|
183
|
-
reasonCodes.push("capabilities-unknown");
|
|
184
|
-
recoveryActions.push("declare-capabilities", "reroute");
|
|
185
|
-
}
|
|
186
|
-
if (plan.missingCapabilities.length > 0) {
|
|
187
|
-
reasonCodes.push("capability-mismatch");
|
|
188
|
-
recoveryActions.push("reroute");
|
|
189
|
-
}
|
|
190
|
-
if (plan.missingTools.length > 0) {
|
|
191
|
-
reasonCodes.push("authority-missing");
|
|
192
|
-
recoveryActions.push("grant-authority", "reroute");
|
|
193
|
-
}
|
|
194
|
-
if (plan.overgrantedTools.length > 0) {
|
|
195
|
-
reasonCodes.push("authority-overgranted");
|
|
196
|
-
recoveryActions.push("narrow-authority");
|
|
197
|
-
}
|
|
198
|
-
if (plan.resultFormatSupported !== true) {
|
|
199
|
-
reasonCodes.push("result-format-unsupported");
|
|
200
|
-
recoveryActions.push("reroute", "change-result-format");
|
|
201
|
-
}
|
|
202
|
-
if (plan.unsupportedGuarantees.length > 0) {
|
|
203
|
-
reasonCodes.push("unsupported-guarantee");
|
|
204
|
-
recoveryActions.push("repair-contract", "stop");
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
version: EXECUTION_ACKNOWLEDGEMENT_VERSION,
|
|
208
|
-
status: reasonCodes.length === 0 ? "accepted" : "rejected",
|
|
209
|
-
reasonCodes: unique(reasonCodes),
|
|
210
|
-
recoveryActions: unique(recoveryActions),
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export function copyExecutionPlan(plan: ExecutionPlan): ExecutionPlan {
|
|
215
|
-
const { id: _storedId, ...cloned } = structuredClone(plan);
|
|
216
|
-
const legacyAdmission = evaluateDelegationAdmission({
|
|
217
|
-
contextPressure: "low",
|
|
218
|
-
independentWorkItems: 1,
|
|
219
|
-
coupling: "dense",
|
|
220
|
-
verificationRequired: false,
|
|
221
|
-
verificationAvailable: false,
|
|
222
|
-
capabilitiesSupported: false,
|
|
223
|
-
budgetAllowsChildren: true,
|
|
224
|
-
generationCurrent: true,
|
|
225
|
-
requirementsComplete: false,
|
|
226
|
-
});
|
|
227
|
-
const normalized = {
|
|
228
|
-
...cloned,
|
|
229
|
-
sideEffectPolicy: plan.sideEffectPolicy ?? "mutating",
|
|
230
|
-
taskGeneration: plan.taskGeneration ?? 0,
|
|
231
|
-
cancellationLineage: plan.cancellationLineage ?? [],
|
|
232
|
-
admission: plan.admission ?? legacyAdmission,
|
|
233
|
-
};
|
|
234
|
-
return { ...normalized, id: executionPlanId(normalized) };
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export function rotateExecutionPlanGeneration(plan: ExecutionPlan): ExecutionPlan {
|
|
238
|
-
const normalized = copyExecutionPlan(plan);
|
|
239
|
-
const { id: previousId, ...withoutId } = normalized;
|
|
240
|
-
const rotated = {
|
|
241
|
-
...withoutId,
|
|
242
|
-
taskGeneration: normalized.taskGeneration + 1,
|
|
243
|
-
cancellationLineage: [...normalized.cancellationLineage, previousId],
|
|
244
|
-
};
|
|
245
|
-
return { ...rotated, id: executionPlanId(rotated) };
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export function isExecutionPlan(value: unknown): value is ExecutionPlan {
|
|
249
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
250
|
-
const plan = value as Partial<ExecutionPlan>;
|
|
251
|
-
return (
|
|
252
|
-
plan.version === EXECUTION_PLAN_VERSION &&
|
|
253
|
-
(plan.mode === "audit" || plan.mode === "enforce") &&
|
|
254
|
-
Boolean(plan.agent) &&
|
|
255
|
-
typeof plan.agent?.name === "string" &&
|
|
256
|
-
["built-in", "user", "project"].includes(String(plan.agent?.source)) &&
|
|
257
|
-
["match", "mismatch", "unknown"].includes(String(plan.capabilityFit)) &&
|
|
258
|
-
Array.isArray(plan.missingCapabilities) &&
|
|
259
|
-
plan.missingCapabilities.every((item) => typeof item === "string") &&
|
|
260
|
-
Array.isArray(plan.requestedCapabilities) &&
|
|
261
|
-
plan.requestedCapabilities.every((item) => typeof item === "string") &&
|
|
262
|
-
Array.isArray(plan.declaredCapabilities) &&
|
|
263
|
-
plan.declaredCapabilities.every((item) => typeof item === "string") &&
|
|
264
|
-
Array.isArray(plan.missingTools) &&
|
|
265
|
-
plan.missingTools.every((item) => typeof item === "string") &&
|
|
266
|
-
Array.isArray(plan.requestedTools) &&
|
|
267
|
-
plan.requestedTools.every((item) => typeof item === "string") &&
|
|
268
|
-
(plan.effectiveTools === undefined ||
|
|
269
|
-
(Array.isArray(plan.effectiveTools) &&
|
|
270
|
-
plan.effectiveTools.every((item) => typeof item === "string"))) &&
|
|
271
|
-
Array.isArray(plan.overgrantedTools) &&
|
|
272
|
-
plan.overgrantedTools.every((item) => typeof item === "string") &&
|
|
273
|
-
["text", "structured-v1", "structured-v2"].includes(String(plan.resultFormat)) &&
|
|
274
|
-
(typeof plan.resultFormatSupported === "boolean" || plan.resultFormatSupported === "unknown") &&
|
|
275
|
-
Boolean(plan.target) &&
|
|
276
|
-
typeof plan.target?.cwd === "string" &&
|
|
277
|
-
["current-workspace", "external"].includes(String(plan.target?.boundary)) &&
|
|
278
|
-
(plan.workspaceMode === "shared" || plan.workspaceMode === "worktree") &&
|
|
279
|
-
["subprocess", "in-process", "rpc", "auto"].includes(String(plan.transport)) &&
|
|
280
|
-
typeof plan.id === "string" &&
|
|
281
|
-
/^[a-f0-9]{64}$/u.test(plan.id) &&
|
|
282
|
-
(plan.taskGeneration === undefined ||
|
|
283
|
-
(Number.isSafeInteger(plan.taskGeneration) && Number(plan.taskGeneration) >= 0)) &&
|
|
284
|
-
(plan.cancellationLineage === undefined ||
|
|
285
|
-
(Array.isArray(plan.cancellationLineage) &&
|
|
286
|
-
plan.cancellationLineage.every((item) => typeof item === "string"))) &&
|
|
287
|
-
(plan.admission === undefined ||
|
|
288
|
-
(typeof plan.admission === "object" &&
|
|
289
|
-
plan.admission.auditOnly === true &&
|
|
290
|
-
typeof plan.admission.recommendation === "string" &&
|
|
291
|
-
Array.isArray(plan.admission.reasonCodes) &&
|
|
292
|
-
plan.admission.reasonCodes.every((item) => typeof item === "string"))) &&
|
|
293
|
-
(plan.sideEffectPolicy === undefined ||
|
|
294
|
-
["read-only", "idempotent", "mutating"].includes(String(plan.sideEffectPolicy))) &&
|
|
295
|
-
Array.isArray(plan.unsupportedGuarantees) &&
|
|
296
|
-
plan.unsupportedGuarantees.every((item) => typeof item === "string") &&
|
|
297
|
-
Array.isArray(plan.warnings) &&
|
|
298
|
-
plan.warnings.every((item) => typeof item === "string") &&
|
|
299
|
-
copyExecutionPlan(plan as ExecutionPlan).id === plan.id
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function executionPlanId(plan: Omit<ExecutionPlan, "id"> | Record<string, unknown>): string {
|
|
304
|
-
return createHash("sha256").update(JSON.stringify(plan)).digest("hex");
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function unsupported(contract: DelegationContract | undefined): string[] {
|
|
308
|
-
if (!contract?.requestedAuthority) return [];
|
|
309
|
-
const authority = contract.requestedAuthority;
|
|
310
|
-
const result: string[] = [];
|
|
311
|
-
if (authority.readPaths && authority.readPaths.length > 0) result.push("read-path-scope");
|
|
312
|
-
if (authority.writePaths && authority.writePaths.length > 0) result.push("write-path-scope");
|
|
313
|
-
if (authority.network === "denied") result.push("network-denial");
|
|
314
|
-
if (authority.network === "required") result.push("network-availability");
|
|
315
|
-
if (authority.secrets === "denied") result.push("secret-denial");
|
|
316
|
-
if (authority.secrets === "required") result.push("secret-availability");
|
|
317
|
-
return result;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function unique(values: readonly string[]): string[] {
|
|
321
|
-
return [...new Set(values)];
|
|
322
|
-
}
|
package/src/execution-ui.ts
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { AgentConfig, SubagentThinkingLevel } from "./agents/types.js";
|
|
3
|
-
import { MAX_SUBAGENT_TIMEOUT_MS } from "./limits.js";
|
|
4
|
-
import { safeTerminalLine as safeTerminalText } from "./safe-text.js";
|
|
5
|
-
import { readSubagentSettings, updateAgentSettingsPatch } from "./settings.js";
|
|
6
|
-
|
|
7
|
-
export function executionAgentPickerScreen(agents: readonly AgentConfig[]) {
|
|
8
|
-
const configured = readSubagentSettings()?.agents ?? {};
|
|
9
|
-
return {
|
|
10
|
-
kind: "actions" as const,
|
|
11
|
-
title: "Model, Thinking, and Time Limit",
|
|
12
|
-
lines: ["Choose a subagent. A specific request can override these starting values."],
|
|
13
|
-
items: [
|
|
14
|
-
...agents.map((agent) => {
|
|
15
|
-
const value = configured[agent.name];
|
|
16
|
-
return {
|
|
17
|
-
id: agent.name,
|
|
18
|
-
label: safeTerminalText(agent.name),
|
|
19
|
-
description: safeTerminalText(
|
|
20
|
-
`${agent.source} · model ${value?.model ?? agent.model ?? "default"} · thinking ${value?.thinkingLevel ?? agent.thinkingLevel ?? "default"} · time limit ${value?.timeoutMs ?? agent.timeoutMs ?? "default"}`,
|
|
21
|
-
),
|
|
22
|
-
action: "pick-execution-agent" as const,
|
|
23
|
-
};
|
|
24
|
-
}),
|
|
25
|
-
{ id: "back", label: "Back", action: "back" as const },
|
|
26
|
-
],
|
|
27
|
-
hint: "back" as const,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function executionAgentScreen(agent: AgentConfig | undefined) {
|
|
32
|
-
if (!agent) {
|
|
33
|
-
return {
|
|
34
|
-
kind: "actions" as const,
|
|
35
|
-
title: "Model, Thinking, and Time Limit",
|
|
36
|
-
lines: ["No subagent selected."],
|
|
37
|
-
items: [{ id: "back", label: "Back", action: "back" as const }],
|
|
38
|
-
hint: "back" as const,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const configured = readSubagentSettings()?.agents?.[agent.name];
|
|
42
|
-
return {
|
|
43
|
-
kind: "actions" as const,
|
|
44
|
-
title: `${safeTerminalText(agent.name)} defaults`,
|
|
45
|
-
lines: [
|
|
46
|
-
`Model: ${safeTerminalText(configured?.model ?? agent.model ?? "agent or Pi default")}`,
|
|
47
|
-
`Thinking: ${configured?.thinkingLevel ?? agent.thinkingLevel ?? "agent or Pi default"}`,
|
|
48
|
-
`Time limit: ${configured?.timeoutMs ?? agent.timeoutMs ?? "agent or Pi default"}`,
|
|
49
|
-
"A specific subagent request can override these defaults.",
|
|
50
|
-
],
|
|
51
|
-
items: [
|
|
52
|
-
{ id: "thinking", label: "Thinking level", to: "execution-thinking" as const },
|
|
53
|
-
{ id: "model", label: "Model", to: "execution-model" as const },
|
|
54
|
-
{ id: "timeout", label: "Time limit", to: "execution-timeout" as const },
|
|
55
|
-
{
|
|
56
|
-
id: "reset",
|
|
57
|
-
label: "Use agent or Pi defaults",
|
|
58
|
-
description: "Remove custom model, thinking, and time limit without changing tools",
|
|
59
|
-
action: "reset-agent-execution" as const,
|
|
60
|
-
},
|
|
61
|
-
{ id: "back", label: "Back", action: "back" as const },
|
|
62
|
-
],
|
|
63
|
-
hint: "back" as const,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function executionThinkingScreen(agent: AgentConfig | undefined) {
|
|
68
|
-
const configured = agent ? readSubagentSettings()?.agents?.[agent.name] : undefined;
|
|
69
|
-
return {
|
|
70
|
-
kind: "settings" as const,
|
|
71
|
-
title: agent ? `${safeTerminalText(agent.name)} thinking` : "Agent thinking",
|
|
72
|
-
items: agent
|
|
73
|
-
? [
|
|
74
|
-
{
|
|
75
|
-
id: "thinking",
|
|
76
|
-
label: "Default thinking level",
|
|
77
|
-
description: "A specific subagent request can override this value.",
|
|
78
|
-
currentValue:
|
|
79
|
-
configured?.thinkingLevel ?? agent.thinkingLevel ?? "Use agent or Pi default",
|
|
80
|
-
values: [
|
|
81
|
-
"Use agent or Pi default",
|
|
82
|
-
"off",
|
|
83
|
-
"minimal",
|
|
84
|
-
"low",
|
|
85
|
-
"medium",
|
|
86
|
-
"high",
|
|
87
|
-
"xhigh",
|
|
88
|
-
"max",
|
|
89
|
-
],
|
|
90
|
-
action: "set-agent-thinking" as const,
|
|
91
|
-
},
|
|
92
|
-
]
|
|
93
|
-
: [],
|
|
94
|
-
hint: "back" as const,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function executionModelScreen(agent: AgentConfig | undefined, ctx: ExtensionCommandContext) {
|
|
99
|
-
const configured = agent ? readSubagentSettings()?.agents?.[agent.name] : undefined;
|
|
100
|
-
const models = ctx.modelRegistry
|
|
101
|
-
.getAvailable()
|
|
102
|
-
.map((model) => `${model.provider}/${model.id}`)
|
|
103
|
-
.sort((left, right) => left.localeCompare(right))
|
|
104
|
-
.slice(0, 100);
|
|
105
|
-
return {
|
|
106
|
-
kind: "actions" as const,
|
|
107
|
-
title: agent ? `${safeTerminalText(agent.name)} model` : "Agent model",
|
|
108
|
-
lines: [
|
|
109
|
-
`Current: ${safeTerminalText(configured?.model ?? agent?.model ?? "agent or Pi default")}`,
|
|
110
|
-
"Choose an available model or enter a custom Pi model pattern.",
|
|
111
|
-
],
|
|
112
|
-
items: agent
|
|
113
|
-
? [
|
|
114
|
-
{
|
|
115
|
-
id: "model:__inherited__",
|
|
116
|
-
label: "Use agent or Pi default",
|
|
117
|
-
description: "Remove the custom model setting",
|
|
118
|
-
action: "set-agent-model" as const,
|
|
119
|
-
},
|
|
120
|
-
...models.map((model) => ({
|
|
121
|
-
id: `model:${model}`,
|
|
122
|
-
label: safeTerminalText(model),
|
|
123
|
-
action: "set-agent-model" as const,
|
|
124
|
-
})),
|
|
125
|
-
{
|
|
126
|
-
id: "custom",
|
|
127
|
-
label: "Custom model pattern",
|
|
128
|
-
description: "Enter provider/model, a model pattern, or an optional :thinking suffix",
|
|
129
|
-
to: "execution-model-input" as const,
|
|
130
|
-
},
|
|
131
|
-
{ id: "back", label: "Back", action: "back" as const },
|
|
132
|
-
]
|
|
133
|
-
: [],
|
|
134
|
-
hint: "back" as const,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function executionModelInputScreen(agent: AgentConfig | undefined) {
|
|
139
|
-
const configured = agent ? readSubagentSettings()?.agents?.[agent.name] : undefined;
|
|
140
|
-
return {
|
|
141
|
-
kind: "input" as const,
|
|
142
|
-
title: agent ? `${safeTerminalText(agent.name)} model` : "Agent model",
|
|
143
|
-
lines: [
|
|
144
|
-
`Current: ${safeTerminalText(configured?.model ?? agent?.model ?? "agent or Pi default")}`,
|
|
145
|
-
"Enter a Pi CLI model pattern, including an optional :thinking suffix.",
|
|
146
|
-
"Use agent or Pi defaults to remove this custom value.",
|
|
147
|
-
],
|
|
148
|
-
placeholder: "provider/model or model pattern",
|
|
149
|
-
action: "set-agent-model" as const,
|
|
150
|
-
hint: "back" as const,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function executionTimeoutInputScreen(agent: AgentConfig | undefined) {
|
|
155
|
-
const configured = agent ? readSubagentSettings()?.agents?.[agent.name] : undefined;
|
|
156
|
-
return {
|
|
157
|
-
kind: "input" as const,
|
|
158
|
-
title: agent ? `${safeTerminalText(agent.name)} time limit` : "Agent time limit",
|
|
159
|
-
lines: [
|
|
160
|
-
`Current: ${configured?.timeoutMs ?? agent?.timeoutMs ?? "agent or Pi default"}`,
|
|
161
|
-
`Allowed: 1-${MAX_SUBAGENT_TIMEOUT_MS} milliseconds.`,
|
|
162
|
-
"Use agent or Pi defaults to remove this custom value.",
|
|
163
|
-
],
|
|
164
|
-
placeholder: "Time limit in milliseconds",
|
|
165
|
-
action: "set-agent-timeout" as const,
|
|
166
|
-
hint: "back" as const,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function applyAgentThinking(
|
|
171
|
-
agent: AgentConfig | undefined,
|
|
172
|
-
value: string | undefined,
|
|
173
|
-
ctx: ExtensionCommandContext,
|
|
174
|
-
) {
|
|
175
|
-
if (!agent) return { kind: "rejected" as const };
|
|
176
|
-
const thinkingLevel =
|
|
177
|
-
value === "Use agent or Pi default" ? undefined : (value as SubagentThinkingLevel);
|
|
178
|
-
if (
|
|
179
|
-
thinkingLevel !== undefined &&
|
|
180
|
-
!["off", "minimal", "low", "medium", "high", "xhigh", "max"].includes(thinkingLevel)
|
|
181
|
-
) {
|
|
182
|
-
return { kind: "rejected" as const };
|
|
183
|
-
}
|
|
184
|
-
return saveAgentPatch(agent.name, { thinkingLevel }, ctx, "thinking level");
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function applyAgentModel(
|
|
188
|
-
agent: AgentConfig | undefined,
|
|
189
|
-
value: string | undefined,
|
|
190
|
-
ctx: ExtensionCommandContext,
|
|
191
|
-
) {
|
|
192
|
-
if (!agent) return { kind: "rejected" as const };
|
|
193
|
-
if (value === undefined) return saveAgentPatch(agent.name, { model: undefined }, ctx, "model");
|
|
194
|
-
const model = value.trim();
|
|
195
|
-
if (!model || Buffer.byteLength(model, "utf8") > 1_024 || hasTerminalControl(model)) {
|
|
196
|
-
ctx.ui.notify("Model must contain 1-1024 UTF-8 bytes on one line.", "warning");
|
|
197
|
-
return { kind: "rejected" as const };
|
|
198
|
-
}
|
|
199
|
-
return saveAgentPatch(agent.name, { model }, ctx, "model");
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export function applyAgentTimeout(
|
|
203
|
-
agent: AgentConfig | undefined,
|
|
204
|
-
value: string | undefined,
|
|
205
|
-
ctx: ExtensionCommandContext,
|
|
206
|
-
) {
|
|
207
|
-
if (!agent) return { kind: "rejected" as const };
|
|
208
|
-
const normalized = value?.trim() ?? "";
|
|
209
|
-
if (!/^\d+$/u.test(normalized)) {
|
|
210
|
-
ctx.ui.notify("Time limit must be a whole number of milliseconds.", "warning");
|
|
211
|
-
return { kind: "rejected" as const };
|
|
212
|
-
}
|
|
213
|
-
const timeoutMs = Number(normalized);
|
|
214
|
-
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > MAX_SUBAGENT_TIMEOUT_MS) {
|
|
215
|
-
ctx.ui.notify(`Time limit must be between 1 and ${MAX_SUBAGENT_TIMEOUT_MS}.`, "warning");
|
|
216
|
-
return { kind: "rejected" as const };
|
|
217
|
-
}
|
|
218
|
-
return saveAgentPatch(agent.name, { timeoutMs }, ctx, "timeout");
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export function resetAgentExecution(agent: AgentConfig | undefined, ctx: ExtensionCommandContext) {
|
|
222
|
-
if (!agent) return { kind: "rejected" as const };
|
|
223
|
-
return saveAgentPatch(
|
|
224
|
-
agent.name,
|
|
225
|
-
{ model: undefined, thinkingLevel: undefined, timeoutMs: undefined },
|
|
226
|
-
ctx,
|
|
227
|
-
"execution defaults",
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function saveAgentPatch(
|
|
232
|
-
name: string,
|
|
233
|
-
patch: Parameters<typeof updateAgentSettingsPatch>[0][string],
|
|
234
|
-
ctx: ExtensionCommandContext,
|
|
235
|
-
label: string,
|
|
236
|
-
) {
|
|
237
|
-
try {
|
|
238
|
-
updateAgentSettingsPatch({ [name]: patch });
|
|
239
|
-
ctx.ui.notify(`${safeTerminalText(name)} ${label} saved.`, "info");
|
|
240
|
-
return { kind: "back" as const };
|
|
241
|
-
} catch (error) {
|
|
242
|
-
ctx.ui.notify(
|
|
243
|
-
`${safeTerminalText(name)} ${label} was not saved: ${formatError(error)}`,
|
|
244
|
-
"error",
|
|
245
|
-
);
|
|
246
|
-
return { kind: "rejected" as const };
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function hasTerminalControl(value: string): boolean {
|
|
251
|
-
return [...value].some((character) => {
|
|
252
|
-
const code = character.codePointAt(0) ?? 0;
|
|
253
|
-
return code <= 0x1f || (code >= 0x7f && code <= 0x9f);
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function formatError(error: unknown): string {
|
|
258
|
-
return safeTerminalText(error instanceof Error ? error.message : String(error));
|
|
259
|
-
}
|