@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,302 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CompletionDelivery,
|
|
3
|
-
ConsultationCwdPolicy,
|
|
4
|
-
ConsultResourcePolicy,
|
|
5
|
-
DelegationCwdPolicy,
|
|
6
|
-
SubagentSettings,
|
|
7
|
-
SubagentTransportKind,
|
|
8
|
-
} from "../agents/types.js";
|
|
9
|
-
import { DEFAULT_MAX_PARALLEL_TASKS } from "../limits.js";
|
|
10
|
-
import {
|
|
11
|
-
resolveStatefulLimits,
|
|
12
|
-
STATEFUL_LIMIT_FIELDS,
|
|
13
|
-
type StatefulLimitField,
|
|
14
|
-
} from "../stateful-limits.js";
|
|
15
|
-
import { hasOwn, isPlainObject } from "./schema.js";
|
|
16
|
-
|
|
17
|
-
const DEFAULT_COMPLETION_DELIVERY: CompletionDelivery = "next-turn";
|
|
18
|
-
export const DEFAULT_CONSULT_RESOURCE_POLICY: ConsultResourcePolicy = "project-context";
|
|
19
|
-
export const DEFAULT_CONSULTATION_CWD_POLICY: ConsultationCwdPolicy = "anywhere";
|
|
20
|
-
export const DEFAULT_DELEGATION_CWD_POLICY: DelegationCwdPolicy = "trusted-targets";
|
|
21
|
-
|
|
22
|
-
export type DelegationWorkflow = "all" | "async-only" | "blocking-only" | "disabled";
|
|
23
|
-
|
|
24
|
-
type SettingsSource = "default" | "user settings";
|
|
25
|
-
|
|
26
|
-
export interface InspectedSubagentSettingsDocument {
|
|
27
|
-
path: string;
|
|
28
|
-
raw?: Record<string, unknown>;
|
|
29
|
-
settings?: SubagentSettings;
|
|
30
|
-
error?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface DelegationWorkflowSettingsSnapshot {
|
|
34
|
-
path: string;
|
|
35
|
-
value: DelegationWorkflow;
|
|
36
|
-
source: SettingsSource;
|
|
37
|
-
error?: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface CompletionDeliverySettingsSnapshot {
|
|
41
|
-
path: string;
|
|
42
|
-
value: CompletionDelivery;
|
|
43
|
-
source: SettingsSource;
|
|
44
|
-
error?: string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface StatefulTransportSettingsSnapshot {
|
|
48
|
-
path: string;
|
|
49
|
-
value: SubagentTransportKind;
|
|
50
|
-
source: SettingsSource;
|
|
51
|
-
error?: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface BlockingParallelLimitSettingsSnapshot {
|
|
55
|
-
path: string;
|
|
56
|
-
value: number;
|
|
57
|
-
source: SettingsSource;
|
|
58
|
-
error?: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface StatefulLimitFieldSnapshot {
|
|
62
|
-
value: number;
|
|
63
|
-
source: SettingsSource;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface StatefulLimitSettingsSnapshot {
|
|
67
|
-
path: string;
|
|
68
|
-
writePath: string;
|
|
69
|
-
values?: Record<StatefulLimitField, StatefulLimitFieldSnapshot>;
|
|
70
|
-
error?: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface ConsultResourceSettingsSnapshot {
|
|
74
|
-
path: string;
|
|
75
|
-
value: ConsultResourcePolicy;
|
|
76
|
-
source: SettingsSource;
|
|
77
|
-
error?: string;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export interface CwdPolicyFieldSnapshot<T> {
|
|
81
|
-
value: T;
|
|
82
|
-
source: SettingsSource;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface CwdPolicySettingsSnapshot {
|
|
86
|
-
path: string;
|
|
87
|
-
consultation: CwdPolicyFieldSnapshot<ConsultationCwdPolicy>;
|
|
88
|
-
delegation: CwdPolicyFieldSnapshot<DelegationCwdPolicy>;
|
|
89
|
-
error?: string;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface SubagentSettingsSnapshot {
|
|
93
|
-
path: string;
|
|
94
|
-
settings?: SubagentSettings;
|
|
95
|
-
source: SettingsSource;
|
|
96
|
-
error?: string;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface UsageRecordingSettingsSnapshot {
|
|
100
|
-
path: string;
|
|
101
|
-
enabled: boolean;
|
|
102
|
-
source: SettingsSource;
|
|
103
|
-
error?: string;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function resolveDelegationWorkflow(
|
|
107
|
-
blockingEnabled: boolean,
|
|
108
|
-
statefulEnabled: boolean,
|
|
109
|
-
): DelegationWorkflow {
|
|
110
|
-
if (blockingEnabled && statefulEnabled) return "all";
|
|
111
|
-
if (statefulEnabled) return "async-only";
|
|
112
|
-
if (blockingEnabled) return "blocking-only";
|
|
113
|
-
return "disabled";
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function resolveBlockingMaxParallelTasks(settings?: SubagentSettings): number {
|
|
117
|
-
return settings?.blocking?.maxParallelTasks ?? DEFAULT_MAX_PARALLEL_TASKS;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function buildSubagentSettingsSnapshot(
|
|
121
|
-
inspected: InspectedSubagentSettingsDocument,
|
|
122
|
-
): SubagentSettingsSnapshot {
|
|
123
|
-
return {
|
|
124
|
-
path: inspected.path,
|
|
125
|
-
settings: inspected.settings,
|
|
126
|
-
source: inspected.settings ? "user settings" : "default",
|
|
127
|
-
...(inspected.error ? { error: inspected.error } : {}),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function buildUsageRecordingSettingsSnapshot(
|
|
132
|
-
inspected: InspectedSubagentSettingsDocument,
|
|
133
|
-
): UsageRecordingSettingsSnapshot {
|
|
134
|
-
if (!inspected.raw || !inspected.settings) {
|
|
135
|
-
return {
|
|
136
|
-
path: inspected.path,
|
|
137
|
-
enabled: false,
|
|
138
|
-
source: "default",
|
|
139
|
-
...(inspected.error ? { error: inspected.error } : {}),
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
const explicit =
|
|
143
|
-
isPlainObject(inspected.raw.usageRecording) && hasOwn(inspected.raw.usageRecording, "enabled");
|
|
144
|
-
return {
|
|
145
|
-
path: inspected.path,
|
|
146
|
-
enabled: inspected.settings.usageRecording?.enabled === true,
|
|
147
|
-
source: explicit ? "user settings" : "default",
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function buildConsultResourceSettingsSnapshot(
|
|
152
|
-
inspected: InspectedSubagentSettingsDocument,
|
|
153
|
-
): ConsultResourceSettingsSnapshot {
|
|
154
|
-
if (!inspected.raw || !inspected.settings) {
|
|
155
|
-
return {
|
|
156
|
-
path: inspected.path,
|
|
157
|
-
value: DEFAULT_CONSULT_RESOURCE_POLICY,
|
|
158
|
-
source: "default",
|
|
159
|
-
...(inspected.error ? { error: inspected.error } : {}),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
const explicit =
|
|
163
|
-
isPlainObject(inspected.raw.consult) && hasOwn(inspected.raw.consult, "resources");
|
|
164
|
-
return {
|
|
165
|
-
path: inspected.path,
|
|
166
|
-
value: inspected.settings.consult?.resources ?? DEFAULT_CONSULT_RESOURCE_POLICY,
|
|
167
|
-
source: explicit ? "user settings" : "default",
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export function buildCwdPolicySettingsSnapshot(
|
|
172
|
-
inspected: InspectedSubagentSettingsDocument,
|
|
173
|
-
): CwdPolicySettingsSnapshot {
|
|
174
|
-
if (!inspected.raw || !inspected.settings) {
|
|
175
|
-
return {
|
|
176
|
-
path: inspected.path,
|
|
177
|
-
consultation: { value: DEFAULT_CONSULTATION_CWD_POLICY, source: "default" },
|
|
178
|
-
delegation: { value: DEFAULT_DELEGATION_CWD_POLICY, source: "default" },
|
|
179
|
-
...(inspected.error ? { error: inspected.error } : {}),
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
const rawPolicy = isPlainObject(inspected.raw.cwdPolicy) ? inspected.raw.cwdPolicy : undefined;
|
|
183
|
-
return {
|
|
184
|
-
path: inspected.path,
|
|
185
|
-
consultation: {
|
|
186
|
-
value: inspected.settings.cwdPolicy?.consultation ?? DEFAULT_CONSULTATION_CWD_POLICY,
|
|
187
|
-
source: rawPolicy && hasOwn(rawPolicy, "consultation") ? "user settings" : "default",
|
|
188
|
-
},
|
|
189
|
-
delegation: {
|
|
190
|
-
value: inspected.settings.cwdPolicy?.delegation ?? DEFAULT_DELEGATION_CWD_POLICY,
|
|
191
|
-
source: rawPolicy && hasOwn(rawPolicy, "delegation") ? "user settings" : "default",
|
|
192
|
-
},
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export function buildDelegationWorkflowSettingsSnapshot(
|
|
197
|
-
inspected: InspectedSubagentSettingsDocument,
|
|
198
|
-
): DelegationWorkflowSettingsSnapshot {
|
|
199
|
-
if (!inspected.raw || !inspected.settings) {
|
|
200
|
-
return {
|
|
201
|
-
path: inspected.path,
|
|
202
|
-
value: "all",
|
|
203
|
-
source: "default",
|
|
204
|
-
...(inspected.error ? { error: inspected.error } : {}),
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
const explicit =
|
|
208
|
-
(isPlainObject(inspected.raw.blocking) && hasOwn(inspected.raw.blocking, "enabled")) ||
|
|
209
|
-
(isPlainObject(inspected.raw.stateful) && hasOwn(inspected.raw.stateful, "enabled"));
|
|
210
|
-
return {
|
|
211
|
-
path: inspected.path,
|
|
212
|
-
value: resolveDelegationWorkflow(
|
|
213
|
-
inspected.settings.blocking?.enabled !== false,
|
|
214
|
-
inspected.settings.stateful?.enabled !== false,
|
|
215
|
-
),
|
|
216
|
-
source: explicit ? "user settings" : "default",
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export function buildCompletionDeliverySettingsSnapshot(
|
|
221
|
-
inspected: InspectedSubagentSettingsDocument,
|
|
222
|
-
): CompletionDeliverySettingsSnapshot {
|
|
223
|
-
if (!inspected.raw || !inspected.settings) {
|
|
224
|
-
return {
|
|
225
|
-
path: inspected.path,
|
|
226
|
-
value: DEFAULT_COMPLETION_DELIVERY,
|
|
227
|
-
source: "default",
|
|
228
|
-
...(inspected.error ? { error: inspected.error } : {}),
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
const explicit =
|
|
232
|
-
isPlainObject(inspected.raw.stateful) && hasOwn(inspected.raw.stateful, "completionDelivery");
|
|
233
|
-
return {
|
|
234
|
-
path: inspected.path,
|
|
235
|
-
value: inspected.settings.stateful?.completionDelivery ?? DEFAULT_COMPLETION_DELIVERY,
|
|
236
|
-
source: explicit ? "user settings" : "default",
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export function buildStatefulTransportSettingsSnapshot(
|
|
241
|
-
inspected: InspectedSubagentSettingsDocument,
|
|
242
|
-
): StatefulTransportSettingsSnapshot {
|
|
243
|
-
if (!inspected.raw || !inspected.settings) {
|
|
244
|
-
return {
|
|
245
|
-
path: inspected.path,
|
|
246
|
-
value: "subprocess",
|
|
247
|
-
source: "default",
|
|
248
|
-
...(inspected.error ? { error: inspected.error } : {}),
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
const explicit =
|
|
252
|
-
isPlainObject(inspected.raw.stateful) && hasOwn(inspected.raw.stateful, "transport");
|
|
253
|
-
return {
|
|
254
|
-
path: inspected.path,
|
|
255
|
-
value: inspected.settings.stateful?.transport ?? "subprocess",
|
|
256
|
-
source: explicit ? "user settings" : "default",
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export function buildBlockingParallelLimitSettingsSnapshot(
|
|
261
|
-
inspected: InspectedSubagentSettingsDocument,
|
|
262
|
-
): BlockingParallelLimitSettingsSnapshot {
|
|
263
|
-
if (!inspected.raw || !inspected.settings) {
|
|
264
|
-
return {
|
|
265
|
-
path: inspected.path,
|
|
266
|
-
value: DEFAULT_MAX_PARALLEL_TASKS,
|
|
267
|
-
source: "default",
|
|
268
|
-
...(inspected.error ? { error: inspected.error } : {}),
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
const explicit =
|
|
272
|
-
isPlainObject(inspected.raw.blocking) && hasOwn(inspected.raw.blocking, "maxParallelTasks");
|
|
273
|
-
return {
|
|
274
|
-
path: inspected.path,
|
|
275
|
-
value: resolveBlockingMaxParallelTasks(inspected.settings),
|
|
276
|
-
source: explicit ? "user settings" : "default",
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
export function buildStatefulLimitSettingsSnapshot(
|
|
281
|
-
inspected: InspectedSubagentSettingsDocument,
|
|
282
|
-
writePath: string,
|
|
283
|
-
): StatefulLimitSettingsSnapshot {
|
|
284
|
-
if (inspected.error) {
|
|
285
|
-
return { path: inspected.path, writePath, error: inspected.error };
|
|
286
|
-
}
|
|
287
|
-
const resolved = resolveStatefulLimits(inspected.settings?.stateful);
|
|
288
|
-
const rawStateful = isPlainObject(inspected.raw?.stateful) ? inspected.raw.stateful : undefined;
|
|
289
|
-
return {
|
|
290
|
-
path: inspected.path,
|
|
291
|
-
writePath,
|
|
292
|
-
values: Object.fromEntries(
|
|
293
|
-
STATEFUL_LIMIT_FIELDS.map((field) => [
|
|
294
|
-
field,
|
|
295
|
-
{
|
|
296
|
-
value: resolved[field],
|
|
297
|
-
source: rawStateful && hasOwn(rawStateful, field) ? "user settings" : "default",
|
|
298
|
-
},
|
|
299
|
-
]),
|
|
300
|
-
) as unknown as Record<StatefulLimitField, StatefulLimitFieldSnapshot>,
|
|
301
|
-
};
|
|
302
|
-
}
|
package/src/settings/schema.ts
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CONSULT_RESOURCE_POLICIES,
|
|
3
|
-
CONSULTATION_CWD_POLICIES,
|
|
4
|
-
type ConsultationCwdPolicy,
|
|
5
|
-
type ConsultResourcePolicy,
|
|
6
|
-
DELEGATION_CWD_POLICIES,
|
|
7
|
-
type DelegationCwdPolicy,
|
|
8
|
-
isThinkingLevel,
|
|
9
|
-
type SubagentAgentConfig,
|
|
10
|
-
type SubagentSettings,
|
|
11
|
-
} from "../agents/types.js";
|
|
12
|
-
import { MAX_CONFIGURABLE_PARALLEL_TASKS, MAX_SUBAGENT_TIMEOUT_MS } from "../limits.js";
|
|
13
|
-
import { isValidStatefulLimit, STATEFUL_LIMIT_FIELDS } from "../stateful-limits.js";
|
|
14
|
-
|
|
15
|
-
export function hasOwn(obj: object, key: PropertyKey): boolean {
|
|
16
|
-
return Object.hasOwn(obj, key);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
20
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function isStringArray(value: unknown): value is string[] {
|
|
24
|
-
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function isPositiveNumber(value: unknown): value is number {
|
|
28
|
-
return typeof value === "number" && Number.isFinite(value) && value >= 1;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function isPositiveInteger(value: unknown): value is number {
|
|
32
|
-
return isPositiveNumber(value) && Number.isSafeInteger(value);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function normalizeAgentSettings(value: unknown): SubagentAgentConfig | undefined {
|
|
36
|
-
if (!isPlainObject(value)) return undefined;
|
|
37
|
-
|
|
38
|
-
const config: SubagentAgentConfig = {};
|
|
39
|
-
let hasKnownField = false;
|
|
40
|
-
|
|
41
|
-
if (hasOwn(value, "tools")) {
|
|
42
|
-
if (!isStringArray(value.tools)) return undefined;
|
|
43
|
-
config.tools = value.tools;
|
|
44
|
-
hasKnownField = true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (hasOwn(value, "model")) {
|
|
48
|
-
if (value.model !== null && typeof value.model !== "string") return undefined;
|
|
49
|
-
config.model = value.model;
|
|
50
|
-
hasKnownField = true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (hasOwn(value, "thinkingLevel")) {
|
|
54
|
-
if (value.thinkingLevel !== null && !isThinkingLevel(value.thinkingLevel)) return undefined;
|
|
55
|
-
config.thinkingLevel = value.thinkingLevel;
|
|
56
|
-
hasKnownField = true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (hasOwn(value, "timeoutMs")) {
|
|
60
|
-
if (
|
|
61
|
-
value.timeoutMs !== null &&
|
|
62
|
-
(!isPositiveNumber(value.timeoutMs) || value.timeoutMs > MAX_SUBAGENT_TIMEOUT_MS)
|
|
63
|
-
) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
config.timeoutMs = value.timeoutMs;
|
|
67
|
-
hasKnownField = true;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return hasKnownField ? config : undefined;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function normalizeSubagentSettings(value: unknown): SubagentSettings | undefined {
|
|
74
|
-
if (!isPlainObject(value)) return undefined;
|
|
75
|
-
const settings: SubagentSettings = {};
|
|
76
|
-
if (hasOwn(value, "agents")) {
|
|
77
|
-
if (!isPlainObject(value.agents)) return undefined;
|
|
78
|
-
const agents: Record<string, SubagentAgentConfig> = {};
|
|
79
|
-
for (const [name, rawConfig] of Object.entries(value.agents)) {
|
|
80
|
-
const config = normalizeAgentSettings(rawConfig);
|
|
81
|
-
if (config) agents[name] = config;
|
|
82
|
-
}
|
|
83
|
-
if (Object.keys(agents).length > 0) settings.agents = agents;
|
|
84
|
-
}
|
|
85
|
-
if (hasOwn(value, "blocking")) {
|
|
86
|
-
if (!isPlainObject(value.blocking)) return undefined;
|
|
87
|
-
const blocking: NonNullable<SubagentSettings["blocking"]> = {};
|
|
88
|
-
if (hasOwn(value.blocking, "enabled")) {
|
|
89
|
-
if (typeof value.blocking.enabled !== "boolean") return undefined;
|
|
90
|
-
blocking.enabled = value.blocking.enabled;
|
|
91
|
-
}
|
|
92
|
-
if (hasOwn(value.blocking, "maxParallelTasks")) {
|
|
93
|
-
if (
|
|
94
|
-
!isPositiveInteger(value.blocking.maxParallelTasks) ||
|
|
95
|
-
value.blocking.maxParallelTasks > MAX_CONFIGURABLE_PARALLEL_TASKS
|
|
96
|
-
) {
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
blocking.maxParallelTasks = value.blocking.maxParallelTasks;
|
|
100
|
-
}
|
|
101
|
-
settings.blocking = blocking;
|
|
102
|
-
}
|
|
103
|
-
if (hasOwn(value, "stateful")) {
|
|
104
|
-
if (!isPlainObject(value.stateful)) return undefined;
|
|
105
|
-
const runtime: NonNullable<SubagentSettings["stateful"]> = {};
|
|
106
|
-
if (hasOwn(value.stateful, "transport")) {
|
|
107
|
-
if (
|
|
108
|
-
value.stateful.transport !== "subprocess" &&
|
|
109
|
-
value.stateful.transport !== "in-process" &&
|
|
110
|
-
value.stateful.transport !== "rpc" &&
|
|
111
|
-
value.stateful.transport !== "auto"
|
|
112
|
-
) {
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
runtime.transport = value.stateful.transport;
|
|
116
|
-
}
|
|
117
|
-
if (hasOwn(value.stateful, "completionDelivery")) {
|
|
118
|
-
if (
|
|
119
|
-
value.stateful.completionDelivery !== "next-turn" &&
|
|
120
|
-
value.stateful.completionDelivery !== "auto-resume"
|
|
121
|
-
) {
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
runtime.completionDelivery = value.stateful.completionDelivery;
|
|
125
|
-
}
|
|
126
|
-
for (const key of STATEFUL_LIMIT_FIELDS) {
|
|
127
|
-
if (hasOwn(value.stateful, key)) {
|
|
128
|
-
if (!isValidStatefulLimit(key, value.stateful[key])) return undefined;
|
|
129
|
-
runtime[key] = value.stateful[key];
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
for (const key of ["maxMailboxMessages", "maxMailboxMessageBytes", "idleTtlMs"] as const) {
|
|
133
|
-
if (hasOwn(value.stateful, key)) {
|
|
134
|
-
if (!isPositiveInteger(value.stateful[key])) return undefined;
|
|
135
|
-
runtime[key] = value.stateful[key];
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (hasOwn(value.stateful, "retentionDays")) {
|
|
139
|
-
if (!isPositiveNumber(value.stateful.retentionDays)) return undefined;
|
|
140
|
-
runtime.retentionDays = value.stateful.retentionDays;
|
|
141
|
-
}
|
|
142
|
-
if (hasOwn(value.stateful, "enabled")) {
|
|
143
|
-
if (typeof value.stateful.enabled !== "boolean") return undefined;
|
|
144
|
-
runtime.enabled = value.stateful.enabled;
|
|
145
|
-
}
|
|
146
|
-
settings.stateful = runtime;
|
|
147
|
-
}
|
|
148
|
-
if (hasOwn(value, "consult")) {
|
|
149
|
-
if (!isPlainObject(value.consult)) return undefined;
|
|
150
|
-
const consult: NonNullable<SubagentSettings["consult"]> = {};
|
|
151
|
-
if (hasOwn(value.consult, "resources")) {
|
|
152
|
-
if (
|
|
153
|
-
typeof value.consult.resources !== "string" ||
|
|
154
|
-
!CONSULT_RESOURCE_POLICIES.includes(value.consult.resources as ConsultResourcePolicy)
|
|
155
|
-
) {
|
|
156
|
-
return undefined;
|
|
157
|
-
}
|
|
158
|
-
consult.resources = value.consult.resources as ConsultResourcePolicy;
|
|
159
|
-
}
|
|
160
|
-
settings.consult = consult;
|
|
161
|
-
}
|
|
162
|
-
if (hasOwn(value, "cwdPolicy")) {
|
|
163
|
-
if (!isPlainObject(value.cwdPolicy)) return undefined;
|
|
164
|
-
const cwdPolicy: NonNullable<SubagentSettings["cwdPolicy"]> = {};
|
|
165
|
-
if (hasOwn(value.cwdPolicy, "consultation")) {
|
|
166
|
-
if (
|
|
167
|
-
typeof value.cwdPolicy.consultation !== "string" ||
|
|
168
|
-
!CONSULTATION_CWD_POLICIES.includes(value.cwdPolicy.consultation as ConsultationCwdPolicy)
|
|
169
|
-
) {
|
|
170
|
-
return undefined;
|
|
171
|
-
}
|
|
172
|
-
cwdPolicy.consultation = value.cwdPolicy.consultation as ConsultationCwdPolicy;
|
|
173
|
-
}
|
|
174
|
-
if (hasOwn(value.cwdPolicy, "delegation")) {
|
|
175
|
-
if (
|
|
176
|
-
typeof value.cwdPolicy.delegation !== "string" ||
|
|
177
|
-
!DELEGATION_CWD_POLICIES.includes(value.cwdPolicy.delegation as DelegationCwdPolicy)
|
|
178
|
-
) {
|
|
179
|
-
return undefined;
|
|
180
|
-
}
|
|
181
|
-
cwdPolicy.delegation = value.cwdPolicy.delegation as DelegationCwdPolicy;
|
|
182
|
-
}
|
|
183
|
-
settings.cwdPolicy = cwdPolicy;
|
|
184
|
-
}
|
|
185
|
-
if (hasOwn(value, "usageRecording")) {
|
|
186
|
-
if (!isPlainObject(value.usageRecording)) return undefined;
|
|
187
|
-
const usageRecording: NonNullable<SubagentSettings["usageRecording"]> = {};
|
|
188
|
-
if (hasOwn(value.usageRecording, "enabled")) {
|
|
189
|
-
if (typeof value.usageRecording.enabled !== "boolean") return undefined;
|
|
190
|
-
usageRecording.enabled = value.usageRecording.enabled;
|
|
191
|
-
}
|
|
192
|
-
settings.usageRecording = usageRecording;
|
|
193
|
-
}
|
|
194
|
-
return settings;
|
|
195
|
-
}
|
package/src/settings-reader.ts
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import type { SubagentSettings } from "./agents/types.js";
|
|
5
|
-
import {
|
|
6
|
-
type BlockingParallelLimitSettingsSnapshot,
|
|
7
|
-
buildBlockingParallelLimitSettingsSnapshot,
|
|
8
|
-
buildCompletionDeliverySettingsSnapshot,
|
|
9
|
-
buildConsultResourceSettingsSnapshot,
|
|
10
|
-
buildCwdPolicySettingsSnapshot,
|
|
11
|
-
buildDelegationWorkflowSettingsSnapshot,
|
|
12
|
-
buildStatefulLimitSettingsSnapshot,
|
|
13
|
-
buildStatefulTransportSettingsSnapshot,
|
|
14
|
-
buildSubagentSettingsSnapshot,
|
|
15
|
-
buildUsageRecordingSettingsSnapshot,
|
|
16
|
-
type CompletionDeliverySettingsSnapshot,
|
|
17
|
-
type ConsultResourceSettingsSnapshot,
|
|
18
|
-
type CwdPolicySettingsSnapshot,
|
|
19
|
-
type DelegationWorkflowSettingsSnapshot,
|
|
20
|
-
type InspectedSubagentSettingsDocument,
|
|
21
|
-
type StatefulLimitSettingsSnapshot,
|
|
22
|
-
type StatefulTransportSettingsSnapshot,
|
|
23
|
-
type SubagentSettingsSnapshot,
|
|
24
|
-
type UsageRecordingSettingsSnapshot,
|
|
25
|
-
} from "./settings/inspection.js";
|
|
26
|
-
import { isPlainObject, normalizeSubagentSettings } from "./settings/schema.js";
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
type BlockingParallelLimitSettingsSnapshot,
|
|
30
|
-
type CompletionDeliverySettingsSnapshot,
|
|
31
|
-
type ConsultResourceSettingsSnapshot,
|
|
32
|
-
type CwdPolicyFieldSnapshot,
|
|
33
|
-
type CwdPolicySettingsSnapshot,
|
|
34
|
-
DEFAULT_CONSULT_RESOURCE_POLICY,
|
|
35
|
-
DEFAULT_CONSULTATION_CWD_POLICY,
|
|
36
|
-
DEFAULT_DELEGATION_CWD_POLICY,
|
|
37
|
-
type DelegationWorkflow,
|
|
38
|
-
type DelegationWorkflowSettingsSnapshot,
|
|
39
|
-
resolveBlockingMaxParallelTasks,
|
|
40
|
-
resolveDelegationWorkflow,
|
|
41
|
-
type StatefulLimitFieldSnapshot,
|
|
42
|
-
type StatefulLimitSettingsSnapshot,
|
|
43
|
-
type StatefulTransportSettingsSnapshot,
|
|
44
|
-
type SubagentSettingsSnapshot,
|
|
45
|
-
type UsageRecordingSettingsSnapshot,
|
|
46
|
-
} from "./settings/inspection.js";
|
|
47
|
-
export { hasOwn, normalizeAgentSettings, normalizeSubagentSettings } from "./settings/schema.js";
|
|
48
|
-
|
|
49
|
-
export const SUBAGENT_SETTINGS_FILE = "pi-subagents.json";
|
|
50
|
-
const LEGACY_SETTINGS_FILE = "pi-subagents-config.json";
|
|
51
|
-
let pendingSettingsNotice: string | undefined;
|
|
52
|
-
|
|
53
|
-
export function resolveSubagentSettingsPaths(): {
|
|
54
|
-
canonicalPath: string;
|
|
55
|
-
legacyPath: string;
|
|
56
|
-
activePath?: string;
|
|
57
|
-
} {
|
|
58
|
-
const canonicalPath = path.join(getAgentDir(), SUBAGENT_SETTINGS_FILE);
|
|
59
|
-
const legacyPath = path.join(getAgentDir(), LEGACY_SETTINGS_FILE);
|
|
60
|
-
return {
|
|
61
|
-
canonicalPath,
|
|
62
|
-
legacyPath,
|
|
63
|
-
activePath: fs.existsSync(canonicalPath)
|
|
64
|
-
? canonicalPath
|
|
65
|
-
: fs.existsSync(legacyPath)
|
|
66
|
-
? legacyPath
|
|
67
|
-
: undefined,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function readSubagentSettings(): SubagentSettings | undefined {
|
|
72
|
-
pendingSettingsNotice = undefined;
|
|
73
|
-
const { canonicalPath, legacyPath, activePath } = resolveSubagentSettingsPaths();
|
|
74
|
-
if (activePath === canonicalPath) {
|
|
75
|
-
const canonical = readSettingsFile(canonicalPath);
|
|
76
|
-
const notices: string[] = [];
|
|
77
|
-
if (!canonical) notices.push(`${SUBAGENT_SETTINGS_FILE} is invalid and was ignored.`);
|
|
78
|
-
if (fs.existsSync(legacyPath)) {
|
|
79
|
-
notices.push(
|
|
80
|
-
`${LEGACY_SETTINGS_FILE} ignored because ${SUBAGENT_SETTINGS_FILE} takes precedence.`,
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
if (notices.length > 0) pendingSettingsNotice = notices.join("\n");
|
|
84
|
-
return canonical;
|
|
85
|
-
}
|
|
86
|
-
if (activePath === undefined) return undefined;
|
|
87
|
-
const legacy = readSettingsFile(legacyPath);
|
|
88
|
-
if (fs.existsSync(canonicalPath)) {
|
|
89
|
-
const canonical = readSettingsFile(canonicalPath);
|
|
90
|
-
pendingSettingsNotice = [
|
|
91
|
-
...(!canonical ? [`${SUBAGENT_SETTINGS_FILE} is invalid and was ignored.`] : []),
|
|
92
|
-
`${LEGACY_SETTINGS_FILE} ignored because ${SUBAGENT_SETTINGS_FILE} was created concurrently.`,
|
|
93
|
-
].join("\n");
|
|
94
|
-
return canonical;
|
|
95
|
-
}
|
|
96
|
-
if (!legacy) {
|
|
97
|
-
pendingSettingsNotice = `${LEGACY_SETTINGS_FILE} is invalid and was ignored.`;
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
pendingSettingsNotice = `Using legacy ${LEGACY_SETTINGS_FILE}; rename it to ${SUBAGENT_SETTINGS_FILE}. Future saves write ${SUBAGENT_SETTINGS_FILE} without modifying the legacy file.`;
|
|
101
|
-
return legacy;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function consumeSubagentSettingsNotice() {
|
|
105
|
-
const notice = pendingSettingsNotice;
|
|
106
|
-
pendingSettingsNotice = undefined;
|
|
107
|
-
return notice;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function subagentSettingsFilePath(): string {
|
|
111
|
-
return path.join(getAgentDir(), SUBAGENT_SETTINGS_FILE);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function inspectSubagentSettingsDocument(): InspectedSubagentSettingsDocument {
|
|
115
|
-
const { canonicalPath, activePath } = resolveSubagentSettingsPaths();
|
|
116
|
-
if (activePath === undefined) return { path: canonicalPath };
|
|
117
|
-
const inspected = inspectSubagentSettingsPath(activePath);
|
|
118
|
-
return activePath !== canonicalPath && fs.existsSync(canonicalPath)
|
|
119
|
-
? inspectSubagentSettingsPath(canonicalPath)
|
|
120
|
-
: inspected;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function inspectSubagentSettingsPath(configPath: string): InspectedSubagentSettingsDocument {
|
|
124
|
-
const fileName = path.basename(configPath);
|
|
125
|
-
let contents: string;
|
|
126
|
-
try {
|
|
127
|
-
contents = fs.readFileSync(configPath, "utf8");
|
|
128
|
-
} catch (error) {
|
|
129
|
-
const code = (error as NodeJS.ErrnoException).code;
|
|
130
|
-
return {
|
|
131
|
-
path: configPath,
|
|
132
|
-
error: `${fileName} could not be read${code ? ` (${safeErrorCode(code)})` : ""}`,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
let raw: unknown;
|
|
136
|
-
try {
|
|
137
|
-
raw = JSON.parse(contents);
|
|
138
|
-
} catch {
|
|
139
|
-
return { path: configPath, error: `${fileName} contains malformed JSON` };
|
|
140
|
-
}
|
|
141
|
-
const settings = normalizeSubagentSettings(raw);
|
|
142
|
-
if (!isPlainObject(raw) || !settings) {
|
|
143
|
-
return { path: configPath, error: `${fileName} is not a valid settings object` };
|
|
144
|
-
}
|
|
145
|
-
return { path: configPath, raw, settings };
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function inspectSubagentSettings(): SubagentSettingsSnapshot {
|
|
149
|
-
return buildSubagentSettingsSnapshot(inspectSubagentSettingsDocument());
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function inspectConsultResourceSettings(): ConsultResourceSettingsSnapshot {
|
|
153
|
-
return buildConsultResourceSettingsSnapshot(inspectSubagentSettingsDocument());
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export function inspectCwdPolicySettings(): CwdPolicySettingsSnapshot {
|
|
157
|
-
return buildCwdPolicySettingsSnapshot(inspectSubagentSettingsDocument());
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function inspectDelegationWorkflowSettings(): DelegationWorkflowSettingsSnapshot {
|
|
161
|
-
return buildDelegationWorkflowSettingsSnapshot(inspectSubagentSettingsDocument());
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function inspectCompletionDeliverySettings(): CompletionDeliverySettingsSnapshot {
|
|
165
|
-
return buildCompletionDeliverySettingsSnapshot(inspectSubagentSettingsDocument());
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export function inspectUsageRecordingSettings(): UsageRecordingSettingsSnapshot {
|
|
169
|
-
return buildUsageRecordingSettingsSnapshot(inspectSubagentSettingsDocument());
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function inspectStatefulTransportSettings(): StatefulTransportSettingsSnapshot {
|
|
173
|
-
return buildStatefulTransportSettingsSnapshot(inspectSubagentSettingsDocument());
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function inspectBlockingParallelLimitSettings(): BlockingParallelLimitSettingsSnapshot {
|
|
177
|
-
return buildBlockingParallelLimitSettingsSnapshot(inspectSubagentSettingsDocument());
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export function inspectStatefulLimitSettings(): StatefulLimitSettingsSnapshot {
|
|
181
|
-
return buildStatefulLimitSettingsSnapshot(
|
|
182
|
-
inspectSubagentSettingsDocument(),
|
|
183
|
-
subagentSettingsFilePath(),
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function pathEntryExists(filePath: string): boolean {
|
|
188
|
-
try {
|
|
189
|
-
fs.lstatSync(filePath);
|
|
190
|
-
return true;
|
|
191
|
-
} catch (error) {
|
|
192
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
|
|
193
|
-
throw error;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function readSettingsFile(configPath: string): SubagentSettings | undefined {
|
|
198
|
-
return readSettingsSnapshot(configPath).settings;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export function readSettingsSnapshot(configPath: string): {
|
|
202
|
-
settings?: SubagentSettings;
|
|
203
|
-
contents?: string;
|
|
204
|
-
} {
|
|
205
|
-
try {
|
|
206
|
-
const contents = fs.readFileSync(configPath, "utf8");
|
|
207
|
-
return { settings: normalizeSubagentSettings(JSON.parse(contents)), contents };
|
|
208
|
-
} catch {
|
|
209
|
-
return {};
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function safeErrorCode(value: string): string {
|
|
214
|
-
return value.replace(/[^A-Z0-9_-]/giu, "?").slice(0, 64);
|
|
215
|
-
}
|