@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
package/src/settings.ts
DELETED
|
@@ -1,452 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
|
-
import * as path from "node:path";
|
|
5
|
-
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
6
|
-
import type {
|
|
7
|
-
AgentConfig,
|
|
8
|
-
CompletionDelivery,
|
|
9
|
-
ConsultationCwdPolicy,
|
|
10
|
-
ConsultResourcePolicy,
|
|
11
|
-
DelegationCwdPolicy,
|
|
12
|
-
SubagentAgentConfig,
|
|
13
|
-
SubagentSettings,
|
|
14
|
-
SubagentThinkingLevel,
|
|
15
|
-
SubagentTransportKind,
|
|
16
|
-
} from "./agents/types.js";
|
|
17
|
-
import { MAX_CONFIGURABLE_PARALLEL_TASKS } from "./limits.js";
|
|
18
|
-
import type { DelegationWorkflow } from "./settings/inspection.js";
|
|
19
|
-
import {
|
|
20
|
-
hasOwn,
|
|
21
|
-
isPlainObject,
|
|
22
|
-
isPositiveInteger,
|
|
23
|
-
normalizeSubagentSettings,
|
|
24
|
-
} from "./settings/schema.js";
|
|
25
|
-
import {
|
|
26
|
-
pathEntryExists,
|
|
27
|
-
resolveSubagentSettingsPaths,
|
|
28
|
-
SUBAGENT_SETTINGS_FILE,
|
|
29
|
-
} from "./settings-reader.js";
|
|
30
|
-
import {
|
|
31
|
-
isValidStatefulLimit,
|
|
32
|
-
resolveStatefulLimits,
|
|
33
|
-
STATEFUL_LIMIT_FIELDS,
|
|
34
|
-
type StatefulLimitField,
|
|
35
|
-
type StatefulLimits,
|
|
36
|
-
statefulLimitDefinition,
|
|
37
|
-
} from "./stateful-limits.js";
|
|
38
|
-
|
|
39
|
-
export {
|
|
40
|
-
type BlockingParallelLimitSettingsSnapshot,
|
|
41
|
-
type CompletionDeliverySettingsSnapshot,
|
|
42
|
-
type ConsultResourceSettingsSnapshot,
|
|
43
|
-
type CwdPolicyFieldSnapshot,
|
|
44
|
-
type CwdPolicySettingsSnapshot,
|
|
45
|
-
consumeSubagentSettingsNotice,
|
|
46
|
-
DEFAULT_CONSULT_RESOURCE_POLICY,
|
|
47
|
-
DEFAULT_CONSULTATION_CWD_POLICY,
|
|
48
|
-
DEFAULT_DELEGATION_CWD_POLICY,
|
|
49
|
-
type DelegationWorkflow,
|
|
50
|
-
type DelegationWorkflowSettingsSnapshot,
|
|
51
|
-
hasOwn,
|
|
52
|
-
inspectBlockingParallelLimitSettings,
|
|
53
|
-
inspectCompletionDeliverySettings,
|
|
54
|
-
inspectConsultResourceSettings,
|
|
55
|
-
inspectCwdPolicySettings,
|
|
56
|
-
inspectDelegationWorkflowSettings,
|
|
57
|
-
inspectStatefulLimitSettings,
|
|
58
|
-
inspectStatefulTransportSettings,
|
|
59
|
-
inspectSubagentSettings,
|
|
60
|
-
inspectUsageRecordingSettings,
|
|
61
|
-
normalizeAgentSettings,
|
|
62
|
-
normalizeSubagentSettings,
|
|
63
|
-
readSubagentSettings,
|
|
64
|
-
resolveBlockingMaxParallelTasks,
|
|
65
|
-
resolveDelegationWorkflow,
|
|
66
|
-
type StatefulLimitFieldSnapshot,
|
|
67
|
-
type StatefulLimitSettingsSnapshot,
|
|
68
|
-
type StatefulTransportSettingsSnapshot,
|
|
69
|
-
type SubagentSettingsSnapshot,
|
|
70
|
-
subagentSettingsFilePath,
|
|
71
|
-
type UsageRecordingSettingsSnapshot,
|
|
72
|
-
} from "./settings-reader.js";
|
|
73
|
-
|
|
74
|
-
const SETTINGS_FILE = SUBAGENT_SETTINGS_FILE;
|
|
75
|
-
const require = createRequire(import.meta.url);
|
|
76
|
-
|
|
77
|
-
const SETTINGS_LOCK_FS_ADAPTER = {
|
|
78
|
-
mkdir: fs.mkdir,
|
|
79
|
-
mkdirSync: fs.mkdirSync,
|
|
80
|
-
realpath: fs.realpath,
|
|
81
|
-
realpathSync: fs.realpathSync,
|
|
82
|
-
rmdir: fs.rmdir,
|
|
83
|
-
rmdirSync: fs.rmdirSync,
|
|
84
|
-
stat: fs.stat,
|
|
85
|
-
statSync: fs.statSync,
|
|
86
|
-
utimes: fs.utimes,
|
|
87
|
-
utimesSync: fs.utimesSync,
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export function saveSubagentConfig(settings: SubagentSettings): void {
|
|
91
|
-
writeSettingsObject(settings);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function updateDelegationWorkflowSetting(
|
|
95
|
-
value: Exclude<DelegationWorkflow, "disabled">,
|
|
96
|
-
): void {
|
|
97
|
-
withSettingsMutationLock(() => {
|
|
98
|
-
const update = readSettingsObjectForUpdate();
|
|
99
|
-
const raw = update.document;
|
|
100
|
-
const blocking = raw.blocking;
|
|
101
|
-
if (blocking !== undefined && !isPlainObject(blocking)) {
|
|
102
|
-
throw new Error(`Cannot update invalid ${SETTINGS_FILE} blocking settings`);
|
|
103
|
-
}
|
|
104
|
-
const stateful = raw.stateful;
|
|
105
|
-
if (stateful !== undefined && !isPlainObject(stateful)) {
|
|
106
|
-
throw new Error(`Cannot update invalid ${SETTINGS_FILE} stateful settings`);
|
|
107
|
-
}
|
|
108
|
-
writeSettingsObjectUnlocked(
|
|
109
|
-
{
|
|
110
|
-
...raw,
|
|
111
|
-
blocking: {
|
|
112
|
-
...(blocking ?? {}),
|
|
113
|
-
enabled: value !== "async-only",
|
|
114
|
-
},
|
|
115
|
-
stateful: {
|
|
116
|
-
...(stateful ?? {}),
|
|
117
|
-
enabled: value !== "blocking-only",
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
update.replaceCanonical,
|
|
121
|
-
);
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function updateStatefulTransportSetting(value: SubagentTransportKind): void {
|
|
126
|
-
if (!["subprocess", "in-process", "rpc", "auto"].includes(value)) {
|
|
127
|
-
throw new Error(`Unsupported stateful transport: ${value}`);
|
|
128
|
-
}
|
|
129
|
-
withSettingsMutationLock(() => {
|
|
130
|
-
const update = readSettingsObjectForUpdate();
|
|
131
|
-
const raw = update.document;
|
|
132
|
-
const stateful = raw.stateful;
|
|
133
|
-
if (stateful !== undefined && !isPlainObject(stateful)) {
|
|
134
|
-
throw new Error(`Cannot update invalid ${SETTINGS_FILE} stateful settings`);
|
|
135
|
-
}
|
|
136
|
-
writeSettingsObjectUnlocked(
|
|
137
|
-
{
|
|
138
|
-
...raw,
|
|
139
|
-
stateful: { ...(stateful ?? {}), transport: value },
|
|
140
|
-
},
|
|
141
|
-
update.replaceCanonical,
|
|
142
|
-
);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function updateCompletionDeliverySetting(value: CompletionDelivery): void {
|
|
147
|
-
withSettingsMutationLock(() => {
|
|
148
|
-
const update = readSettingsObjectForUpdate();
|
|
149
|
-
const raw = update.document;
|
|
150
|
-
const stateful = raw.stateful;
|
|
151
|
-
if (stateful !== undefined && !isPlainObject(stateful)) {
|
|
152
|
-
throw new Error(`Cannot update invalid ${SETTINGS_FILE} stateful settings`);
|
|
153
|
-
}
|
|
154
|
-
writeSettingsObjectUnlocked(
|
|
155
|
-
{
|
|
156
|
-
...raw,
|
|
157
|
-
stateful: {
|
|
158
|
-
...(stateful ?? {}),
|
|
159
|
-
completionDelivery: value,
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
update.replaceCanonical,
|
|
163
|
-
);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export function updateUsageRecordingSetting(enabled: boolean): void {
|
|
168
|
-
withSettingsMutationLock(() => {
|
|
169
|
-
const update = readSettingsObjectForUpdate();
|
|
170
|
-
const raw = update.document;
|
|
171
|
-
const usageRecording = raw.usageRecording;
|
|
172
|
-
if (usageRecording !== undefined && !isPlainObject(usageRecording)) {
|
|
173
|
-
throw new Error(`Cannot update invalid ${SETTINGS_FILE} usageRecording settings`);
|
|
174
|
-
}
|
|
175
|
-
writeSettingsObjectUnlocked(
|
|
176
|
-
{
|
|
177
|
-
...raw,
|
|
178
|
-
usageRecording: { ...(usageRecording ?? {}), enabled },
|
|
179
|
-
},
|
|
180
|
-
update.replaceCanonical,
|
|
181
|
-
);
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export function updateBlockingMaxParallelTasksSetting(value: number): void {
|
|
186
|
-
if (!isPositiveInteger(value) || value > MAX_CONFIGURABLE_PARALLEL_TASKS) {
|
|
187
|
-
throw new Error(
|
|
188
|
-
`Maximum parallel tasks must be an integer between 1 and ${MAX_CONFIGURABLE_PARALLEL_TASKS}`,
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
withSettingsMutationLock(() => {
|
|
192
|
-
const update = readSettingsObjectForUpdate();
|
|
193
|
-
const raw = update.document;
|
|
194
|
-
const blocking = raw.blocking;
|
|
195
|
-
if (blocking !== undefined && !isPlainObject(blocking)) {
|
|
196
|
-
throw new Error(`Cannot update invalid ${SETTINGS_FILE} blocking settings`);
|
|
197
|
-
}
|
|
198
|
-
writeSettingsObjectUnlocked(
|
|
199
|
-
{
|
|
200
|
-
...raw,
|
|
201
|
-
blocking: {
|
|
202
|
-
...(blocking ?? {}),
|
|
203
|
-
maxParallelTasks: value,
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
update.replaceCanonical,
|
|
207
|
-
);
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export function updateStatefulLimitSetting(
|
|
212
|
-
field: StatefulLimitField,
|
|
213
|
-
value: number,
|
|
214
|
-
expected?: StatefulLimits,
|
|
215
|
-
): void {
|
|
216
|
-
if (!isValidStatefulLimit(field, value)) {
|
|
217
|
-
throw new Error(
|
|
218
|
-
`${field} must be a safe integer greater than or equal to ${statefulLimitDefinition(field).minimum}`,
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
withSettingsMutationLock(() => {
|
|
222
|
-
const update = readSettingsObjectForUpdate();
|
|
223
|
-
const raw = update.document;
|
|
224
|
-
const stateful = raw.stateful;
|
|
225
|
-
if (stateful !== undefined && !isPlainObject(stateful)) {
|
|
226
|
-
throw new Error(`Cannot update invalid ${SETTINGS_FILE} stateful settings`);
|
|
227
|
-
}
|
|
228
|
-
const normalized = normalizeSubagentSettings(raw);
|
|
229
|
-
if (!normalized) throw new Error(`Cannot update invalid ${SETTINGS_FILE}`);
|
|
230
|
-
if (expected && !sameStatefulLimits(resolveStatefulLimits(normalized.stateful), expected)) {
|
|
231
|
-
throw new Error("Detached limit settings changed; reopen settings and retry");
|
|
232
|
-
}
|
|
233
|
-
writeSettingsObjectUnlocked(
|
|
234
|
-
{
|
|
235
|
-
...raw,
|
|
236
|
-
stateful: { ...(stateful ?? {}), [field]: value },
|
|
237
|
-
},
|
|
238
|
-
update.replaceCanonical,
|
|
239
|
-
);
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export function updateConsultResourceSetting(value: ConsultResourcePolicy): void {
|
|
244
|
-
withSettingsMutationLock(() => {
|
|
245
|
-
const update = readSettingsObjectForUpdate();
|
|
246
|
-
const raw = update.document;
|
|
247
|
-
const consult = raw.consult;
|
|
248
|
-
if (consult !== undefined && !isPlainObject(consult)) {
|
|
249
|
-
throw new Error(`Cannot update invalid ${SETTINGS_FILE} consult settings`);
|
|
250
|
-
}
|
|
251
|
-
writeSettingsObjectUnlocked(
|
|
252
|
-
{
|
|
253
|
-
...raw,
|
|
254
|
-
consult: {
|
|
255
|
-
...(consult ?? {}),
|
|
256
|
-
resources: value,
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
update.replaceCanonical,
|
|
260
|
-
);
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
export function updateCwdPolicySetting(field: "consultation", value: ConsultationCwdPolicy): void;
|
|
265
|
-
export function updateCwdPolicySetting(field: "delegation", value: DelegationCwdPolicy): void;
|
|
266
|
-
export function updateCwdPolicySetting(
|
|
267
|
-
field: "consultation" | "delegation",
|
|
268
|
-
value: ConsultationCwdPolicy | DelegationCwdPolicy,
|
|
269
|
-
): void {
|
|
270
|
-
withSettingsMutationLock(() => {
|
|
271
|
-
const update = readSettingsObjectForUpdate();
|
|
272
|
-
const raw = update.document;
|
|
273
|
-
const cwdPolicy = raw.cwdPolicy;
|
|
274
|
-
if (cwdPolicy !== undefined && !isPlainObject(cwdPolicy)) {
|
|
275
|
-
throw new Error(`Cannot update invalid ${SETTINGS_FILE} cwdPolicy settings`);
|
|
276
|
-
}
|
|
277
|
-
writeSettingsObjectUnlocked(
|
|
278
|
-
{
|
|
279
|
-
...raw,
|
|
280
|
-
cwdPolicy: { ...(cwdPolicy ?? {}), [field]: value },
|
|
281
|
-
},
|
|
282
|
-
update.replaceCanonical,
|
|
283
|
-
);
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
export type AgentSettingsPatch = {
|
|
288
|
-
tools?: string[] | undefined;
|
|
289
|
-
model?: string | null | undefined;
|
|
290
|
-
thinkingLevel?: SubagentThinkingLevel | null | undefined;
|
|
291
|
-
timeoutMs?: number | null | undefined;
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
export function updateAgentToolsSetting(name: string, tools: string[] | undefined): void {
|
|
295
|
-
updateAgentSettingsPatch({ [name]: { tools } });
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
export function updateAgentSettingsPatch(patches: Record<string, AgentSettingsPatch>): void {
|
|
299
|
-
withSettingsMutationLock(() => {
|
|
300
|
-
const update = readSettingsObjectForUpdate();
|
|
301
|
-
const raw = update.document;
|
|
302
|
-
const rawAgents = raw.agents;
|
|
303
|
-
if (rawAgents !== undefined && !isPlainObject(rawAgents)) {
|
|
304
|
-
throw new Error(`Cannot update invalid ${SETTINGS_FILE} agent settings`);
|
|
305
|
-
}
|
|
306
|
-
const agents = { ...(rawAgents ?? {}) };
|
|
307
|
-
for (const [name, patch] of Object.entries(patches)) {
|
|
308
|
-
const rawAgent = hasOwn(agents, name) ? agents[name] : undefined;
|
|
309
|
-
if (rawAgent !== undefined && !isPlainObject(rawAgent)) {
|
|
310
|
-
throw new Error(`Cannot update invalid ${SETTINGS_FILE} settings for ${name}`);
|
|
311
|
-
}
|
|
312
|
-
const agent = { ...(rawAgent ?? {}) };
|
|
313
|
-
for (const field of ["tools", "model", "thinkingLevel", "timeoutMs"] as const) {
|
|
314
|
-
if (!hasOwn(patch, field)) continue;
|
|
315
|
-
const value = patch[field];
|
|
316
|
-
if (value === undefined) delete agent[field];
|
|
317
|
-
else
|
|
318
|
-
Object.defineProperty(agent, field, {
|
|
319
|
-
value,
|
|
320
|
-
enumerable: true,
|
|
321
|
-
configurable: true,
|
|
322
|
-
writable: true,
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
if (Object.keys(agent).length > 0) {
|
|
326
|
-
Object.defineProperty(agents, name, {
|
|
327
|
-
value: agent,
|
|
328
|
-
enumerable: true,
|
|
329
|
-
configurable: true,
|
|
330
|
-
writable: true,
|
|
331
|
-
});
|
|
332
|
-
} else {
|
|
333
|
-
delete agents[name];
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const normalized = normalizeSubagentSettings({
|
|
338
|
-
...raw,
|
|
339
|
-
...(Object.keys(agents).length > 0 ? { agents } : {}),
|
|
340
|
-
});
|
|
341
|
-
if (!normalized) throw new Error(`Cannot update invalid ${SETTINGS_FILE} agent settings`);
|
|
342
|
-
const updated = { ...raw };
|
|
343
|
-
if (Object.keys(agents).length > 0) updated.agents = agents;
|
|
344
|
-
else delete updated.agents;
|
|
345
|
-
writeSettingsObjectUnlocked(updated, update.replaceCanonical);
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
interface SettingsObjectForUpdate {
|
|
350
|
-
document: Record<string, unknown>;
|
|
351
|
-
replaceCanonical: boolean;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
function readSettingsObjectForUpdate(): SettingsObjectForUpdate {
|
|
355
|
-
const { canonicalPath, activePath } = resolveSubagentSettingsPaths();
|
|
356
|
-
if (activePath === undefined) return { document: {}, replaceCanonical: false };
|
|
357
|
-
const activeFile = path.basename(activePath);
|
|
358
|
-
let parsed: unknown;
|
|
359
|
-
try {
|
|
360
|
-
parsed = JSON.parse(fs.readFileSync(activePath, "utf8"));
|
|
361
|
-
} catch {
|
|
362
|
-
throw new Error(`Cannot update malformed ${activeFile}`);
|
|
363
|
-
}
|
|
364
|
-
if (!isPlainObject(parsed) || !normalizeSubagentSettings(parsed)) {
|
|
365
|
-
throw new Error(`Cannot update invalid ${activeFile}`);
|
|
366
|
-
}
|
|
367
|
-
return { document: parsed, replaceCanonical: activePath === canonicalPath };
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
function writeSettingsObject(settings: object, replaceCanonical?: boolean): void {
|
|
371
|
-
withSettingsMutationLock(() => writeSettingsObjectUnlocked(settings, replaceCanonical));
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
function writeSettingsObjectUnlocked(settings: object, replaceCanonical?: boolean): void {
|
|
375
|
-
const agentDir = getAgentDir();
|
|
376
|
-
fs.mkdirSync(agentDir, { recursive: true });
|
|
377
|
-
const configPath = path.join(agentDir, SETTINGS_FILE);
|
|
378
|
-
const tempFile = path.join(agentDir, `.${SETTINGS_FILE}.${randomUUID()}.tmp`);
|
|
379
|
-
// Updates seeded from a missing or legacy document must remain exclusive even if the
|
|
380
|
-
// canonical path appears after the read and before publication.
|
|
381
|
-
const firstCanonicalPublication = !(replaceCanonical ?? pathEntryExists(configPath));
|
|
382
|
-
try {
|
|
383
|
-
fs.writeFileSync(tempFile, `${JSON.stringify(settings, null, "\t")}\n`, {
|
|
384
|
-
encoding: "utf8",
|
|
385
|
-
flag: "wx",
|
|
386
|
-
});
|
|
387
|
-
if (firstCanonicalPublication && pathEntryExists(configPath)) {
|
|
388
|
-
throw new Error(`${SETTINGS_FILE} was created concurrently; reopen settings and retry`);
|
|
389
|
-
}
|
|
390
|
-
fs.renameSync(tempFile, configPath);
|
|
391
|
-
} finally {
|
|
392
|
-
try {
|
|
393
|
-
fs.rmSync(tempFile, { force: true });
|
|
394
|
-
} catch {
|
|
395
|
-
// Preserve the save result if best-effort temp cleanup fails.
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
function withSettingsMutationLock<T>(mutate: () => T): T {
|
|
401
|
-
const lockfile = require("proper-lockfile") as typeof import("proper-lockfile");
|
|
402
|
-
const agentDir = getAgentDir();
|
|
403
|
-
fs.mkdirSync(agentDir, { recursive: true });
|
|
404
|
-
const configPath = path.join(agentDir, SETTINGS_FILE);
|
|
405
|
-
const release = lockfile.lockSync(configPath, {
|
|
406
|
-
fs: SETTINGS_LOCK_FS_ADAPTER,
|
|
407
|
-
lockfilePath: `${configPath}.mutation-lock`,
|
|
408
|
-
realpath: false,
|
|
409
|
-
});
|
|
410
|
-
try {
|
|
411
|
-
return mutate();
|
|
412
|
-
} finally {
|
|
413
|
-
release();
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
function sameStatefulLimits(left: StatefulLimits, right: StatefulLimits): boolean {
|
|
418
|
-
return STATEFUL_LIMIT_FIELDS.every((field) => left[field] === right[field]);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
export function uniqueToolNames(tools: string[]): string[] {
|
|
422
|
-
return [...new Set(tools)];
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
export function sameToolSet(left: string[], right: string[]): boolean {
|
|
426
|
-
const leftSet = new Set(left);
|
|
427
|
-
const rightSet = new Set(right);
|
|
428
|
-
if (leftSet.size !== rightSet.size) return false;
|
|
429
|
-
return [...leftSet].every((tool) => rightSet.has(tool));
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
export function resolveSubagentThinkingLevel(
|
|
433
|
-
agents: readonly Pick<AgentConfig, "name" | "thinkingLevel">[],
|
|
434
|
-
agentName: string,
|
|
435
|
-
topLevelThinkingLevel?: SubagentThinkingLevel,
|
|
436
|
-
localThinkingLevel?: SubagentThinkingLevel,
|
|
437
|
-
): SubagentThinkingLevel | undefined {
|
|
438
|
-
return (
|
|
439
|
-
localThinkingLevel ??
|
|
440
|
-
topLevelThinkingLevel ??
|
|
441
|
-
agents.find((agent) => agent.name === agentName)?.thinkingLevel
|
|
442
|
-
);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
export function hasAnyAgentOverride(config: SubagentAgentConfig): boolean {
|
|
446
|
-
return (
|
|
447
|
-
hasOwn(config, "tools") ||
|
|
448
|
-
hasOwn(config, "model") ||
|
|
449
|
-
hasOwn(config, "thinkingLevel") ||
|
|
450
|
-
hasOwn(config, "timeoutMs")
|
|
451
|
-
);
|
|
452
|
-
}
|
package/src/spawn-idempotency.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import type { AgentScope, SubagentThinkingLevel } from "./agents/types.js";
|
|
3
|
-
import type { CompletionRequirementMode } from "./completion-requirement.js";
|
|
4
|
-
import type { DelegationContract } from "./delegation-contract.js";
|
|
5
|
-
import type { SubagentResultFormat } from "./result-contract.js";
|
|
6
|
-
|
|
7
|
-
export const MAX_SPAWN_IDEMPOTENCY_KEY_LENGTH = 256;
|
|
8
|
-
|
|
9
|
-
export interface CanonicalSpawnRequest {
|
|
10
|
-
agent: string;
|
|
11
|
-
taskName?: string;
|
|
12
|
-
task: string;
|
|
13
|
-
cwd: string;
|
|
14
|
-
agentScope: AgentScope;
|
|
15
|
-
thinkingLevel?: SubagentThinkingLevel;
|
|
16
|
-
timeoutMs?: number;
|
|
17
|
-
idleTimeoutMs?: number;
|
|
18
|
-
maxTurns?: number;
|
|
19
|
-
maxToolCalls?: number;
|
|
20
|
-
parentId?: string;
|
|
21
|
-
context?: string;
|
|
22
|
-
contextSourceIds: readonly string[];
|
|
23
|
-
workspaceMode: "shared" | "worktree";
|
|
24
|
-
allowConcurrentWrites: boolean;
|
|
25
|
-
contract?: DelegationContract;
|
|
26
|
-
resultFormat: SubagentResultFormat;
|
|
27
|
-
completionRequirement?: CompletionRequirementMode;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function hashSpawnRequest(request: CanonicalSpawnRequest): string {
|
|
31
|
-
return createHash("sha256")
|
|
32
|
-
.update(
|
|
33
|
-
JSON.stringify({
|
|
34
|
-
agent: request.agent,
|
|
35
|
-
...(request.taskName === undefined ? {} : { taskName: request.taskName }),
|
|
36
|
-
task: request.task,
|
|
37
|
-
cwd: request.cwd,
|
|
38
|
-
agentScope: request.agentScope,
|
|
39
|
-
thinkingLevel: request.thinkingLevel ?? null,
|
|
40
|
-
...(request.timeoutMs === undefined ? {} : { timeoutMs: request.timeoutMs }),
|
|
41
|
-
...(request.idleTimeoutMs === undefined ? {} : { idleTimeoutMs: request.idleTimeoutMs }),
|
|
42
|
-
...(request.maxTurns === undefined ? {} : { maxTurns: request.maxTurns }),
|
|
43
|
-
...(request.maxToolCalls === undefined ? {} : { maxToolCalls: request.maxToolCalls }),
|
|
44
|
-
parentId: request.parentId ?? null,
|
|
45
|
-
contextHash: request.context
|
|
46
|
-
? createHash("sha256").update(request.context).digest("hex")
|
|
47
|
-
: null,
|
|
48
|
-
contextSourceIds: [...request.contextSourceIds],
|
|
49
|
-
workspaceMode: request.workspaceMode,
|
|
50
|
-
allowConcurrentWrites: request.allowConcurrentWrites,
|
|
51
|
-
...(request.contract === undefined ? {} : { contract: request.contract }),
|
|
52
|
-
resultFormat: request.resultFormat,
|
|
53
|
-
...(request.completionRequirement === "required"
|
|
54
|
-
? { completionRequirement: "required" }
|
|
55
|
-
: {}),
|
|
56
|
-
}),
|
|
57
|
-
)
|
|
58
|
-
.digest("hex");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function assertSpawnIdempotencyKey(value: string | undefined): void {
|
|
62
|
-
if (value === undefined) return;
|
|
63
|
-
if (!value || value.length > MAX_SPAWN_IDEMPOTENCY_KEY_LENGTH) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`subagent_spawn idempotencyKey must contain 1-${MAX_SPAWN_IDEMPOTENCY_KEY_LENGTH} characters`,
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { MAX_TOOL_MESSAGE_BYTES, truncateUtf8 } from "./limits.js";
|
|
2
|
-
import type { ManagedAgent } from "./registry.js";
|
|
3
|
-
|
|
4
|
-
export function formatStatefulAgentLine(agent: ManagedAgent, now = Date.now()): string {
|
|
5
|
-
const elapsedSeconds = Math.max(0, Math.floor((now - agent.updatedAt) / 1000));
|
|
6
|
-
const task = agent.currentTask ? ` — ${sanitizeStatusLine(agent.currentTask, 80)}` : "";
|
|
7
|
-
const unread = agent.mailbox.filter((message) => !message.readAt).length;
|
|
8
|
-
const indent = " ".repeat(agent.depth);
|
|
9
|
-
return `${indent}${sanitizeStatusLine(agent.taskPath ?? agent.id, 256)} · ${sanitizeStatusLine(agent.agent, 128)} · ${agentStateLabel(agent.state)} · updated ${elapsedSeconds}s ago · ${unread} unread${task}`;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function summarizeStatefulAgent(agent: ManagedAgent) {
|
|
13
|
-
return {
|
|
14
|
-
id: agent.id,
|
|
15
|
-
taskName: agent.taskName,
|
|
16
|
-
taskPath: agent.taskPath,
|
|
17
|
-
agent: agent.agent,
|
|
18
|
-
parentId: agent.parentId,
|
|
19
|
-
rootId: agent.rootId,
|
|
20
|
-
depth: agent.depth,
|
|
21
|
-
children: [...agent.children],
|
|
22
|
-
state: agent.state,
|
|
23
|
-
createdAt: agent.createdAt,
|
|
24
|
-
updatedAt: agent.updatedAt,
|
|
25
|
-
cwd: agent.cwd,
|
|
26
|
-
workspaceMode: agent.workspaceMode ?? "shared",
|
|
27
|
-
thinkingLevel: agent.thinkingLevel,
|
|
28
|
-
timeoutMs: agent.timeoutMs,
|
|
29
|
-
currentTimeoutMs: agent.currentTimeoutMs,
|
|
30
|
-
idleTimeoutMs: agent.idleTimeoutMs,
|
|
31
|
-
currentIdleTimeoutMs: agent.currentIdleTimeoutMs,
|
|
32
|
-
maxTurns: agent.maxTurns,
|
|
33
|
-
currentMaxTurns: agent.currentMaxTurns,
|
|
34
|
-
maxToolCalls: agent.maxToolCalls,
|
|
35
|
-
currentMaxToolCalls: agent.currentMaxToolCalls,
|
|
36
|
-
currentTask: agent.currentTask
|
|
37
|
-
? truncateUtf8(agent.currentTask, MAX_TOOL_MESSAGE_BYTES).text
|
|
38
|
-
: undefined,
|
|
39
|
-
historyCount: agent.history.length,
|
|
40
|
-
unreadMessages: agent.mailbox.filter((message) => !message.readAt).length,
|
|
41
|
-
context: {
|
|
42
|
-
turns: agent.contextTurns ?? 0,
|
|
43
|
-
sources: agent.contextSourceIds?.length ?? 0,
|
|
44
|
-
bytes: agent.contextBytes ?? 0,
|
|
45
|
-
truncated: agent.contextTruncated === true,
|
|
46
|
-
},
|
|
47
|
-
resultFormat: agent.resultFormat ?? "text",
|
|
48
|
-
completionRequirements: (agent.completionRequirements ?? []).map((record) => ({
|
|
49
|
-
...record,
|
|
50
|
-
})),
|
|
51
|
-
structuredResult: agent.structuredResult,
|
|
52
|
-
termination: agent.termination,
|
|
53
|
-
outcome: agent.outcome,
|
|
54
|
-
executionPlan: agent.executionPlan,
|
|
55
|
-
capabilityGrant: agent.capabilityGrant,
|
|
56
|
-
semanticCompatibility: agent.semanticCompatibility,
|
|
57
|
-
semanticSnapshotDigest: agent.semanticSnapshot?.digest,
|
|
58
|
-
telemetry: agent.telemetry,
|
|
59
|
-
error: agent.error ? truncateUtf8(agent.error, MAX_TOOL_MESSAGE_BYTES).text : undefined,
|
|
60
|
-
target: agent.target,
|
|
61
|
-
policy: agent.policy,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function agentStateLabel(state: ManagedAgent["state"]): string {
|
|
66
|
-
switch (state) {
|
|
67
|
-
case "running":
|
|
68
|
-
return "working";
|
|
69
|
-
case "completed":
|
|
70
|
-
return "finished";
|
|
71
|
-
default:
|
|
72
|
-
return state;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function sanitizeStatusLine(value: string, maxLength: number): string {
|
|
77
|
-
return (
|
|
78
|
-
value
|
|
79
|
-
.slice(0, maxLength)
|
|
80
|
-
// biome-ignore lint/suspicious/noControlCharactersInRegex: Escape untrusted terminal controls.
|
|
81
|
-
.replace(/[\u0000-\u001f\u007f-\u009f]/gu, " ")
|
|
82
|
-
.replace(/\s+/gu, " ")
|
|
83
|
-
.trim()
|
|
84
|
-
);
|
|
85
|
-
}
|
package/src/stateful-config.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { CompletionDelivery, SubagentTransportKind } from "./agents/types.js";
|
|
2
|
-
|
|
3
|
-
export function resolveStatefulTransportKind(
|
|
4
|
-
value: SubagentTransportKind | undefined,
|
|
5
|
-
): SubagentTransportKind {
|
|
6
|
-
return value ?? "subprocess";
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function resolveCompletionDelivery(
|
|
10
|
-
value: CompletionDelivery | undefined,
|
|
11
|
-
): CompletionDelivery {
|
|
12
|
-
return value ?? "next-turn";
|
|
13
|
-
}
|
package/src/stateful-guidance.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export function createSpawnPromptGuidelines(blockingEnabled = true): string[] {
|
|
2
|
-
return [
|
|
3
|
-
"Do not use subagent_spawn for simple or critical-path work that the main agent can perform directly. The main agent retains overall planning, immediate critical-path work, integration, final verification, and the final answer.",
|
|
4
|
-
"Before one ordinary subagent_spawn, identify concrete useful non-overlapping main-agent work you can start immediately and a supported completion integration path. If none exists, perform the task directly instead of calling subagent_spawn.",
|
|
5
|
-
"Give subagent_spawn a concise unique taskName using lowercase letters, digits, and underscores so the retained agent has a stable canonical task path.",
|
|
6
|
-
"Set subagent_spawn thinkingLevel to the lowest sufficient thinking level for the delegated task: use off or minimal for extraction, formatting, or mechanical work; low for straightforward bounded work; medium for ordinary multi-step research or implementation; high for complex debugging, design, review, or cross-file analysis; xhigh for highly ambiguous, cross-system, or high-risk analysis; and max only for the hardest tasks when quality clearly outweighs latency and cost. Omit subagent_spawn thinkingLevel only to preserve the agent or child default.",
|
|
7
|
-
"Set subagent_spawn timeoutMs to the shortest realistic work deadline for the task difficulty; use idleTimeoutMs for stalled work and maxTurns or maxToolCalls to stop repeated work without progress. Scope the task to the smallest named files or questions. When setting subagent_spawn maxTurns or maxToolCalls, leave sufficient headroom for discovery, evidence reads, and final synthesis; otherwise omit them instead of guessing speculative tight values. Split oversized tasks instead of extending budgets merely to compensate for broad scope.",
|
|
8
|
-
"For an ordinary subagent_spawn, omit contract; use a delegation contract only when explicit acceptance, authority, evidence, or admission semantics are required.",
|
|
9
|
-
"Do not set subagent_spawn contract enforcement to enforce with requestedAuthority readPaths, writePaths, network, or secrets; those guarantees are unsupported and reject before child launch, while capabilities and tools remain enforceable.",
|
|
10
|
-
"If subagent_spawn rejects an unsupported guarantee, retry once with those fields removed or enforcement set to audit only when they were advisory; when any field is a required security boundary, stop instead of weakening it.",
|
|
11
|
-
"Read the current pi-subagents session-guidance message before choosing detached completion behavior. With next-turn delivery, use subagent_spawn only when the current response does not depend on its result unless useful overlap ends with an intentional subagent_await. With auto-resume delivery, final-answer-dependent detached work may continue asynchronously.",
|
|
12
|
-
'Track every final-answer-dependent subagent_spawn by setting completionRequirement to "required" and retaining its returned agentId or taskPath; treat interim output as progress, and synthesize only after every corresponding completion message is visible or terminal.',
|
|
13
|
-
"Keep ordinary review in the main agent with a review skill and deterministic checks; use subagent_spawn for detached review only when consequential independent verification has concrete parallel value.",
|
|
14
|
-
"Use a single subagent_spawn for a bounded implementation slice with clear ownership only when it can run beside the identified main-agent work.",
|
|
15
|
-
"Use a single subagent_spawn without concurrent main-agent work only for an explicit user-requested specialist model, tool profile, or isolation boundary.",
|
|
16
|
-
...(blockingEnabled
|
|
17
|
-
? [
|
|
18
|
-
"The subagent tool is deprecated; do not select it merely because synchronous output is required. Prefer subagent_spawn with supported completion delivery, and use subagent_await only after useful overlapping main-agent work is complete and an intentional join is required.",
|
|
19
|
-
"Use deprecated subagent instead of subagent_spawn only for an existing caller or an explicit user request whose blocking chain, fan-in, panel, or workflow semantics do not yet have a detached replacement; queued steering cannot be processed until it returns.",
|
|
20
|
-
]
|
|
21
|
-
: []),
|
|
22
|
-
"Add another subagent_spawn only for truly independent work with safe workspace concurrency and disjoint write ownership; shared workspaces permit concurrent writes by default, so use workspaceMode worktree when repository isolation is required. The main agent still owns integration.",
|
|
23
|
-
"After subagent_spawn returns, immediately continue the identified local task; do not merely announce the spawn, wait, poll, or end the response while useful local work remains.",
|
|
24
|
-
"When completionRequirement required subagent_spawn work remains active after local work is exhausted, emit at most one brief progress sentence and end the turn; do not repeat waiting updates or use the requested final format, verdict, or conclusion until every required completion is visible or terminal. Current Pi versions do not enforce a hard pre-display barrier.",
|
|
25
|
-
"Do not duplicate assigned work from subagent_spawn while its retained agent is running; use a bounded parent fallback only after its completion reports failure or insufficient evidence.",
|
|
26
|
-
'Consume and synthesize available subagent_spawn completion messages; use subagent_manage with action "interrupt" or "close" for agents that are no longer needed.',
|
|
27
|
-
'Completion from subagent_spawn is delivered automatically. Do not poll with subagent_inspect or subagent_mailbox action "read", repeatedly check progress, or duplicate the delegated work.',
|
|
28
|
-
];
|
|
29
|
-
}
|