@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,183 +0,0 @@
|
|
|
1
|
-
# pi-subagents Architecture Diagrams
|
|
2
|
-
|
|
3
|
-
These diagrams describe the main `pi-subagents` components, detached-agent lifecycle, transport selection, and verified workflow.
|
|
4
|
-
|
|
5
|
-
## Overall architecture
|
|
6
|
-
|
|
7
|
-
```mermaid
|
|
8
|
-
flowchart TB
|
|
9
|
-
Root["Main Pi Agent<br/>Planning, integration, verification, and final answer"]
|
|
10
|
-
Extension["pi-subagents Extension"]
|
|
11
|
-
Settings["User Settings<br/>pi-subagents.json"]
|
|
12
|
-
Catalog["Agent Catalog<br/>built-in / user / project"]
|
|
13
|
-
UI["/subagents Manager<br/>pi-tui-kit"]
|
|
14
|
-
|
|
15
|
-
Root --> Extension
|
|
16
|
-
Settings --> Extension
|
|
17
|
-
Catalog --> Extension
|
|
18
|
-
UI <--> Extension
|
|
19
|
-
|
|
20
|
-
subgraph Surfaces["Tool Surfaces"]
|
|
21
|
-
Blocking["subagent<br/>Blocking workflows"]
|
|
22
|
-
Consult["subagent_consult<br/>Synchronous read-only consultation"]
|
|
23
|
-
Stateful["Detached lifecycle<br/>spawn / send / manage / mailbox"]
|
|
24
|
-
Inspect["subagent_inspect<br/>Read-only diagnostics"]
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
Extension --> Blocking
|
|
28
|
-
Extension --> Consult
|
|
29
|
-
Extension --> Stateful
|
|
30
|
-
Extension --> Inspect
|
|
31
|
-
|
|
32
|
-
Blocking --> BlockingExecution["Blocking Execution<br/>single / parallel / chain / workflow / panel"]
|
|
33
|
-
Consult --> ConsultPolicy["Read-only tool intersection<br/>read / grep / find / ls"]
|
|
34
|
-
Stateful --> Registry["Agent Registry<br/>queue / generations / hierarchy"]
|
|
35
|
-
Inspect --> Snapshots["Safe projections<br/>runs / workflows / models / status"]
|
|
36
|
-
|
|
37
|
-
Registry --> Persistence["Persistent State and Completion Outbox"]
|
|
38
|
-
Registry --> TransportSelector["Transport Selector"]
|
|
39
|
-
BlockingExecution --> Runner["Subprocess Runner"]
|
|
40
|
-
ConsultPolicy --> Runner
|
|
41
|
-
|
|
42
|
-
TransportSelector --> InProcess["In-process<br/>Low startup overhead"]
|
|
43
|
-
TransportSelector --> RPC["Retained RPC process<br/>Process isolation and retained history"]
|
|
44
|
-
TransportSelector --> Subprocess["Fresh subprocess<br/>Custom-tool compatibility"]
|
|
45
|
-
|
|
46
|
-
Registry --> Delivery["Completion Routing"]
|
|
47
|
-
Delivery --> Root
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## Detached-agent execution and completion delivery
|
|
51
|
-
|
|
52
|
-
```mermaid
|
|
53
|
-
sequenceDiagram
|
|
54
|
-
participant R as Root Agent
|
|
55
|
-
participant E as Extension
|
|
56
|
-
participant P as Policy / Preflight
|
|
57
|
-
participant G as Agent Registry
|
|
58
|
-
participant T as Transport
|
|
59
|
-
participant S as Persistent State
|
|
60
|
-
participant D as Completion Broker
|
|
61
|
-
|
|
62
|
-
R->>E: subagent_spawn(task, contract, budgets)
|
|
63
|
-
E->>P: Check cwd, trust, agent scope, and capacity
|
|
64
|
-
P-->>E: Approved execution plan
|
|
65
|
-
E->>G: Create agent, generation, and runId
|
|
66
|
-
G->>S: Persist starting / queued state
|
|
67
|
-
E-->>R: Immediately return agentId and taskPath
|
|
68
|
-
|
|
69
|
-
Note over R: Root continues non-overlapping local work
|
|
70
|
-
|
|
71
|
-
G->>T: runTurn() when capacity is available
|
|
72
|
-
T-->>G: Bounded progress / telemetry
|
|
73
|
-
T-->>G: Terminal outcome
|
|
74
|
-
|
|
75
|
-
G->>G: Classify completed / failed / blocked / interrupted
|
|
76
|
-
G->>G: Create completionId and outbox record
|
|
77
|
-
G->>S: Persist terminal state and completion first
|
|
78
|
-
S-->>G: Durable
|
|
79
|
-
|
|
80
|
-
G->>D: Route to the direct parent or nearest live ancestor
|
|
81
|
-
|
|
82
|
-
alt next-turn
|
|
83
|
-
D-->>R: Steer without waking an idle root
|
|
84
|
-
else auto-resume
|
|
85
|
-
D-->>R: Trigger a synthesis turn after the root settles
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
R->>E: subagent_send(agentId, follow-up)
|
|
89
|
-
E->>G: Start a new generation while retaining agent history
|
|
90
|
-
G->>T: Execute the follow-up
|
|
91
|
-
|
|
92
|
-
R->>E: subagent_manage(close)
|
|
93
|
-
E->>G: Release descendants child-first
|
|
94
|
-
G->>T: Shutdown / release
|
|
95
|
-
G->>S: Update or remove retained state
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
The system persists each completion before notifying its parent so that a process interruption does not permanently lose the result.
|
|
99
|
-
|
|
100
|
-
## Automatic transport selection
|
|
101
|
-
|
|
102
|
-
```mermaid
|
|
103
|
-
flowchart TD
|
|
104
|
-
Start["Create a detached agent"]
|
|
105
|
-
Explicit{"Was transport explicitly selected?"}
|
|
106
|
-
UseExplicit["Use the selected transport"]
|
|
107
|
-
BuiltIn{"Are all effective tools<br/>Pi built-in tools?"}
|
|
108
|
-
ReadOnly{"Is the tool set read-only?"}
|
|
109
|
-
InProcess["in-process<br/>Retained SDK session"]
|
|
110
|
-
RPC["rpc<br/>Retained independent Pi process"]
|
|
111
|
-
Subprocess["subprocess<br/>Fresh process for each turn"]
|
|
112
|
-
Run["Create the child and accept the prompt"]
|
|
113
|
-
Failure["Startup or execution failure<br/>Report failure without switching transport"]
|
|
114
|
-
Note["After a child is created or may have accepted work,<br/>automatic fallback is forbidden to prevent duplicate side effects"]
|
|
115
|
-
|
|
116
|
-
Start --> Explicit
|
|
117
|
-
Explicit -- "Yes" --> UseExplicit
|
|
118
|
-
Explicit -- "No, use auto" --> BuiltIn
|
|
119
|
-
|
|
120
|
-
BuiltIn -- "No, includes extension/custom tools" --> Subprocess
|
|
121
|
-
BuiltIn -- "Yes" --> ReadOnly
|
|
122
|
-
|
|
123
|
-
ReadOnly -- "Yes" --> InProcess
|
|
124
|
-
ReadOnly -- "No, includes bash/edit/write" --> RPC
|
|
125
|
-
|
|
126
|
-
UseExplicit --> Run
|
|
127
|
-
InProcess --> Run
|
|
128
|
-
RPC --> Run
|
|
129
|
-
Subprocess --> Run
|
|
130
|
-
Run --> Failure
|
|
131
|
-
Failure -.-> Note
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Read-only classification is based on effective tool permissions rather than promises written in the task prompt.
|
|
135
|
-
|
|
136
|
-
## Verified workflow and acceptance barrier
|
|
137
|
-
|
|
138
|
-
```mermaid
|
|
139
|
-
flowchart TD
|
|
140
|
-
Request["Caller-authored workflow"]
|
|
141
|
-
Validate["Validate DAG, contracts, dependencies, and budgets"]
|
|
142
|
-
Preflight["Preflight every cwd, agent, scope, and authority"]
|
|
143
|
-
Ledger["Create the WorkItem Ledger"]
|
|
144
|
-
Scheduler["Adaptive Scheduler<br/>dependency / capacity / budget / conflict"]
|
|
145
|
-
Worker["Execute Worker"]
|
|
146
|
-
Result["Parse structured-v2<br/>Record artifacts and tree identity"]
|
|
147
|
-
NeedsVerify{"Is independent verification required?"}
|
|
148
|
-
OrdinaryDone["Complete the ordinary workflow item"]
|
|
149
|
-
|
|
150
|
-
Checks["Run executor-owned checks<br/>in a disposable worktree"]
|
|
151
|
-
ChecksPass{"Did every check pass?"}
|
|
152
|
-
Verifier["Independent read-only Verifier<br/>Different agent and generation"]
|
|
153
|
-
Receipt["Create verification receipt<br/>Bind patch, tree, plan, and evidence"]
|
|
154
|
-
Decision{"Verifier decision"}
|
|
155
|
-
|
|
156
|
-
Accept["Acceptance Controller<br/>Mark accepted"]
|
|
157
|
-
Rework{"Is rework capacity available?"}
|
|
158
|
-
Rotate["Revoke old grants<br/>Rotate worker/verifier generations"]
|
|
159
|
-
Reject["rejected / non-success"]
|
|
160
|
-
Finish["Workflow terminal result"]
|
|
161
|
-
|
|
162
|
-
Request --> Validate --> Preflight --> Ledger --> Scheduler
|
|
163
|
-
Scheduler --> Worker --> Result --> NeedsVerify
|
|
164
|
-
|
|
165
|
-
NeedsVerify -- "No" --> OrdinaryDone --> Finish
|
|
166
|
-
NeedsVerify -- "Yes" --> Checks
|
|
167
|
-
Checks --> ChecksPass
|
|
168
|
-
ChecksPass -- "No" --> Reject
|
|
169
|
-
ChecksPass -- "Yes" --> Verifier
|
|
170
|
-
Verifier --> Receipt --> Decision
|
|
171
|
-
|
|
172
|
-
Decision -- "accepted" --> Accept --> Finish
|
|
173
|
-
Decision -- "rework" --> Rework
|
|
174
|
-
Decision -- "rejected" --> Reject
|
|
175
|
-
|
|
176
|
-
Rework -- "Yes, at most once" --> Rotate --> Scheduler
|
|
177
|
-
Rework -- "No" --> Reject
|
|
178
|
-
Reject --> Finish
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
A worker's own claim that verification passed cannot move acceptance from `pending` to `accepted`.
|
|
182
|
-
|
|
183
|
-
Only executor-owned checks, an independent verifier, and the acceptance controller can complete acceptance.
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
|
-
import type { WorkItemLedgerSnapshot, WorkItemRecord } from "./work-item-ledger.js";
|
|
3
|
-
|
|
4
|
-
export const ADAPTIVE_SCHEDULER_POLICY = "dependency-aware-v1" as const;
|
|
5
|
-
|
|
6
|
-
export type SchedulingReason =
|
|
7
|
-
| "selected"
|
|
8
|
-
| "dependency-not-ready"
|
|
9
|
-
| "state-not-ready"
|
|
10
|
-
| "budget-exhausted"
|
|
11
|
-
| "capacity-exhausted"
|
|
12
|
-
| "scope-conflict"
|
|
13
|
-
| "verification-barrier";
|
|
14
|
-
|
|
15
|
-
export interface SchedulingDecisionItem {
|
|
16
|
-
id: string;
|
|
17
|
-
reason: SchedulingReason;
|
|
18
|
-
criticalPathDepth: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface SchedulingDecision {
|
|
22
|
-
policy: typeof ADAPTIVE_SCHEDULER_POLICY;
|
|
23
|
-
workflowId: string;
|
|
24
|
-
workflowGeneration: number;
|
|
25
|
-
effectiveConcurrency: number;
|
|
26
|
-
selected: string[];
|
|
27
|
-
decisions: SchedulingDecisionItem[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface AdaptiveSchedulerOptions {
|
|
31
|
-
maxConcurrency: number;
|
|
32
|
-
activeCount: number;
|
|
33
|
-
transportCapacity: number;
|
|
34
|
-
remainingBudgetMs: number;
|
|
35
|
-
activeReadPaths?: string[];
|
|
36
|
-
activeWritePaths?: string[];
|
|
37
|
-
activeOwnershipKeys?: string[];
|
|
38
|
-
activeMutatingCount?: number;
|
|
39
|
-
maxMutatingConcurrency?: number;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class AdaptiveScheduler {
|
|
43
|
-
decide(snapshot: WorkItemLedgerSnapshot, options: AdaptiveSchedulerOptions): SchedulingDecision {
|
|
44
|
-
validateOptions(options);
|
|
45
|
-
const depth = criticalPathDepths(snapshot.items);
|
|
46
|
-
const ready = snapshot.items
|
|
47
|
-
.filter((item) => item.state === "ready")
|
|
48
|
-
.sort(
|
|
49
|
-
(left, right) =>
|
|
50
|
-
(depth.get(right.id) ?? 0) - (depth.get(left.id) ?? 0) || left.id.localeCompare(right.id),
|
|
51
|
-
);
|
|
52
|
-
const availableSlots = Math.max(
|
|
53
|
-
0,
|
|
54
|
-
Math.min(
|
|
55
|
-
options.maxConcurrency - options.activeCount,
|
|
56
|
-
options.transportCapacity - options.activeCount,
|
|
57
|
-
ready.length,
|
|
58
|
-
),
|
|
59
|
-
);
|
|
60
|
-
const effectiveConcurrency = options.remainingBudgetMs > 0 ? availableSlots : 0;
|
|
61
|
-
const readyVerifier = ready.find((item) => item.verifierFor !== undefined);
|
|
62
|
-
if (readyVerifier) {
|
|
63
|
-
const verifierMayStart = effectiveConcurrency > 0 && options.activeCount === 0;
|
|
64
|
-
return {
|
|
65
|
-
policy: ADAPTIVE_SCHEDULER_POLICY,
|
|
66
|
-
workflowId: snapshot.workflowId,
|
|
67
|
-
workflowGeneration: snapshot.generation,
|
|
68
|
-
effectiveConcurrency: verifierMayStart ? 1 : 0,
|
|
69
|
-
selected: verifierMayStart ? [readyVerifier.id] : [],
|
|
70
|
-
decisions: snapshot.items
|
|
71
|
-
.map((item) => ({
|
|
72
|
-
id: item.id,
|
|
73
|
-
reason:
|
|
74
|
-
item.id === readyVerifier.id
|
|
75
|
-
? verifierMayStart
|
|
76
|
-
? ("selected" as const)
|
|
77
|
-
: ("capacity-exhausted" as const)
|
|
78
|
-
: item.state === "ready"
|
|
79
|
-
? ("verification-barrier" as const)
|
|
80
|
-
: item.state === "pending"
|
|
81
|
-
? ("dependency-not-ready" as const)
|
|
82
|
-
: ("state-not-ready" as const),
|
|
83
|
-
criticalPathDepth: depth.get(item.id) ?? 0,
|
|
84
|
-
}))
|
|
85
|
-
.sort((left, right) => left.id.localeCompare(right.id)),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
const selected: string[] = [];
|
|
89
|
-
let mutatingCount = options.activeMutatingCount ?? 0;
|
|
90
|
-
const maxMutatingConcurrency = options.maxMutatingConcurrency ?? 2;
|
|
91
|
-
const selectedReadPaths = normalizedScopes(options.activeReadPaths ?? []);
|
|
92
|
-
const selectedWritePaths = normalizedScopes(options.activeWritePaths ?? []);
|
|
93
|
-
const selectedOwnership = new Set(options.activeOwnershipKeys ?? []);
|
|
94
|
-
const reasons = new Map<string, SchedulingReason>();
|
|
95
|
-
for (const item of ready) {
|
|
96
|
-
if (options.remainingBudgetMs <= 0) {
|
|
97
|
-
reasons.set(item.id, "budget-exhausted");
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
if (
|
|
101
|
-
selected.length >= effectiveConcurrency ||
|
|
102
|
-
(item.sideEffectPolicy !== "read-only" && mutatingCount >= maxMutatingConcurrency)
|
|
103
|
-
) {
|
|
104
|
-
reasons.set(item.id, "capacity-exhausted");
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (hasConflict(item, selectedReadPaths, selectedWritePaths, selectedOwnership)) {
|
|
108
|
-
reasons.set(item.id, "scope-conflict");
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
selected.push(item.id);
|
|
112
|
-
if (item.sideEffectPolicy !== "read-only") mutatingCount++;
|
|
113
|
-
reasons.set(item.id, "selected");
|
|
114
|
-
for (const scope of normalizedScopes(item.readPaths)) selectedReadPaths.add(scope);
|
|
115
|
-
for (const scope of normalizedScopes(item.writePaths)) selectedWritePaths.add(scope);
|
|
116
|
-
for (const key of item.ownershipKeys) selectedOwnership.add(key);
|
|
117
|
-
}
|
|
118
|
-
const decisions = snapshot.items
|
|
119
|
-
.map((item) => ({
|
|
120
|
-
id: item.id,
|
|
121
|
-
reason:
|
|
122
|
-
reasons.get(item.id) ??
|
|
123
|
-
(item.state === "pending" ? "dependency-not-ready" : "state-not-ready"),
|
|
124
|
-
criticalPathDepth: depth.get(item.id) ?? 0,
|
|
125
|
-
}))
|
|
126
|
-
.sort((left, right) => left.id.localeCompare(right.id));
|
|
127
|
-
return {
|
|
128
|
-
policy: ADAPTIVE_SCHEDULER_POLICY,
|
|
129
|
-
workflowId: snapshot.workflowId,
|
|
130
|
-
workflowGeneration: snapshot.generation,
|
|
131
|
-
effectiveConcurrency,
|
|
132
|
-
selected,
|
|
133
|
-
decisions,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function hasConflict(
|
|
139
|
-
item: WorkItemRecord,
|
|
140
|
-
readPaths: ReadonlySet<string>,
|
|
141
|
-
writePaths: ReadonlySet<string>,
|
|
142
|
-
ownership: ReadonlySet<string>,
|
|
143
|
-
): boolean {
|
|
144
|
-
const candidateReads = normalizedScopes(item.readPaths);
|
|
145
|
-
const candidateWrites = normalizedScopes(item.writePaths);
|
|
146
|
-
return (
|
|
147
|
-
[...candidateWrites].some(
|
|
148
|
-
(scope) => overlapsAny(scope, readPaths) || overlapsAny(scope, writePaths),
|
|
149
|
-
) ||
|
|
150
|
-
[...candidateReads].some((scope) => overlapsAny(scope, writePaths)) ||
|
|
151
|
-
item.ownershipKeys.some((key) => ownership.has(key))
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function normalizedScopes(values: readonly string[]): Set<string> {
|
|
156
|
-
return new Set(values.map(normalizeScope));
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function normalizeScope(value: string): string {
|
|
160
|
-
const normalized = path.posix.normalize(value.trim().replace(/\\+/gu, "/"));
|
|
161
|
-
if (
|
|
162
|
-
normalized === "." ||
|
|
163
|
-
normalized === ".." ||
|
|
164
|
-
normalized.startsWith("../") ||
|
|
165
|
-
normalized.startsWith("/") ||
|
|
166
|
-
/^[A-Za-z]:\//u.test(normalized)
|
|
167
|
-
) {
|
|
168
|
-
return "";
|
|
169
|
-
}
|
|
170
|
-
return normalized.replace(/^\.\//u, "").replace(/\/$/u, "");
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function overlapsAny(scope: string, candidates: ReadonlySet<string>): boolean {
|
|
174
|
-
return [...candidates].some((candidate) => scopesOverlap(scope, candidate));
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function scopesOverlap(left: string, right: string): boolean {
|
|
178
|
-
if (!left || !right || left === right) return true;
|
|
179
|
-
return left.startsWith(`${right}/`) || right.startsWith(`${left}/`);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function criticalPathDepths(items: WorkItemRecord[]): Map<string, number> {
|
|
183
|
-
const byId = new Map(items.map((item) => [item.id, item]));
|
|
184
|
-
const memo = new Map<string, number>();
|
|
185
|
-
const visit = (id: string): number => {
|
|
186
|
-
const cached = memo.get(id);
|
|
187
|
-
if (cached !== undefined) return cached;
|
|
188
|
-
const item = byId.get(id);
|
|
189
|
-
if (!item || item.dependents.length === 0) {
|
|
190
|
-
memo.set(id, 0);
|
|
191
|
-
return 0;
|
|
192
|
-
}
|
|
193
|
-
const value = 1 + Math.max(...item.dependents.map(visit));
|
|
194
|
-
memo.set(id, value);
|
|
195
|
-
return value;
|
|
196
|
-
};
|
|
197
|
-
for (const item of items) visit(item.id);
|
|
198
|
-
return memo;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function validateOptions(options: AdaptiveSchedulerOptions): void {
|
|
202
|
-
for (const [name, value] of [
|
|
203
|
-
["maxConcurrency", options.maxConcurrency],
|
|
204
|
-
["activeCount", options.activeCount],
|
|
205
|
-
["transportCapacity", options.transportCapacity],
|
|
206
|
-
] as const) {
|
|
207
|
-
if (!Number.isSafeInteger(value) || value < (name === "activeCount" ? 0 : 1)) {
|
|
208
|
-
throw new Error(
|
|
209
|
-
`${name} must be a ${name === "activeCount" ? "non-negative" : "positive"} safe integer`,
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
for (const [name, value] of [
|
|
214
|
-
["activeMutatingCount", options.activeMutatingCount ?? 0],
|
|
215
|
-
["maxMutatingConcurrency", options.maxMutatingConcurrency ?? 2],
|
|
216
|
-
] as const) {
|
|
217
|
-
if (!Number.isSafeInteger(value) || value < (name === "activeMutatingCount" ? 0 : 1)) {
|
|
218
|
-
throw new Error(`${name} has an invalid bound`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (!Number.isFinite(options.remainingBudgetMs) || options.remainingBudgetMs < 0) {
|
|
222
|
-
throw new Error("remainingBudgetMs must be a non-negative finite number");
|
|
223
|
-
}
|
|
224
|
-
}
|
package/src/admission-policy.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export const DELEGATION_ADMISSION_VERSION = "pi-subagents:admission:v1" as const;
|
|
2
|
-
|
|
3
|
-
export type DelegationAdmissionRecommendation =
|
|
4
|
-
| "parent-owned-direct"
|
|
5
|
-
| "one-child"
|
|
6
|
-
| "one-child-plus-verification"
|
|
7
|
-
| "bounded-two-child"
|
|
8
|
-
| "abstain-insufficient-evidence";
|
|
9
|
-
|
|
10
|
-
export interface DelegationAdmissionInput {
|
|
11
|
-
contextPressure: "low" | "medium" | "high";
|
|
12
|
-
independentWorkItems: number;
|
|
13
|
-
coupling: "dense" | "sparse";
|
|
14
|
-
verificationRequired: boolean;
|
|
15
|
-
verificationAvailable: boolean;
|
|
16
|
-
capabilitiesSupported: boolean;
|
|
17
|
-
budgetAllowsChildren: boolean;
|
|
18
|
-
generationCurrent: boolean;
|
|
19
|
-
requirementsComplete: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface DelegationAdmissionDecision {
|
|
23
|
-
version: typeof DELEGATION_ADMISSION_VERSION;
|
|
24
|
-
recommendation: DelegationAdmissionRecommendation;
|
|
25
|
-
reasonCodes: string[];
|
|
26
|
-
benefitHypothesis: string;
|
|
27
|
-
auditOnly: true;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function evaluateDelegationAdmission(
|
|
31
|
-
input: DelegationAdmissionInput,
|
|
32
|
-
): DelegationAdmissionDecision {
|
|
33
|
-
if (!input.generationCurrent)
|
|
34
|
-
return decision("abstain-insufficient-evidence", ["stale-generation"]);
|
|
35
|
-
if (!input.requirementsComplete) {
|
|
36
|
-
return decision("abstain-insufficient-evidence", ["requirements-incomplete"]);
|
|
37
|
-
}
|
|
38
|
-
if (!input.capabilitiesSupported) {
|
|
39
|
-
return decision("abstain-insufficient-evidence", ["capability-unsupported"]);
|
|
40
|
-
}
|
|
41
|
-
if (!input.budgetAllowsChildren) {
|
|
42
|
-
return decision("parent-owned-direct", ["child-budget-insufficient"]);
|
|
43
|
-
}
|
|
44
|
-
if (input.independentWorkItems >= 2 && input.coupling === "sparse") {
|
|
45
|
-
return decision(
|
|
46
|
-
"bounded-two-child",
|
|
47
|
-
["declared-independent-work"],
|
|
48
|
-
"parallel-critical-path-reduction",
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
if (input.verificationRequired) {
|
|
52
|
-
return input.verificationAvailable
|
|
53
|
-
? decision(
|
|
54
|
-
"one-child-plus-verification",
|
|
55
|
-
["independent-verification-required"],
|
|
56
|
-
"independent-error-detection",
|
|
57
|
-
)
|
|
58
|
-
: decision("abstain-insufficient-evidence", ["verification-unavailable"]);
|
|
59
|
-
}
|
|
60
|
-
if (input.contextPressure === "high") {
|
|
61
|
-
return decision("one-child", ["declared-context-pressure"], "context-isolation");
|
|
62
|
-
}
|
|
63
|
-
return decision("parent-owned-direct", ["delegation-benefit-not-established"]);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function decision(
|
|
67
|
-
recommendation: DelegationAdmissionRecommendation,
|
|
68
|
-
reasonCodes: string[],
|
|
69
|
-
benefitHypothesis = "none",
|
|
70
|
-
): DelegationAdmissionDecision {
|
|
71
|
-
return {
|
|
72
|
-
version: DELEGATION_ADMISSION_VERSION,
|
|
73
|
-
recommendation,
|
|
74
|
-
reasonCodes,
|
|
75
|
-
benefitHypothesis,
|
|
76
|
-
auditOnly: true,
|
|
77
|
-
};
|
|
78
|
-
}
|
package/src/agent-projection.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { ManagedAgent } from "./registry.js";
|
|
2
|
-
|
|
3
|
-
export interface AgentProjectionLimits {
|
|
4
|
-
maxAgents: number;
|
|
5
|
-
maxDepth?: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Select the newest restorable agent trees without orphaning child records.
|
|
10
|
-
*
|
|
11
|
-
* Complete ancestor chains are selected together, then returned in their original
|
|
12
|
-
* order so persistence and restore behavior stay deterministic.
|
|
13
|
-
*/
|
|
14
|
-
export function projectAgentRecords(
|
|
15
|
-
agents: readonly ManagedAgent[],
|
|
16
|
-
limits: AgentProjectionLimits,
|
|
17
|
-
): ManagedAgent[] {
|
|
18
|
-
const byId = new Map(agents.map((agent) => [agent.id, agent]));
|
|
19
|
-
const selected = new Set<string>();
|
|
20
|
-
const maxDepth = limits.maxDepth ?? Number.MAX_SAFE_INTEGER;
|
|
21
|
-
const newestFirst = agents
|
|
22
|
-
.map((agent, index) => ({ agent, index }))
|
|
23
|
-
.sort(
|
|
24
|
-
(left, right) => right.agent.updatedAt - left.agent.updatedAt || right.index - left.index,
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
for (const { agent } of newestFirst) {
|
|
28
|
-
const chain = ancestorChain(agent, byId);
|
|
29
|
-
if (!chain || chain.length - 1 > maxDepth) continue;
|
|
30
|
-
const missing = chain.filter((candidate) => !selected.has(candidate.id));
|
|
31
|
-
if (selected.size + missing.length > limits.maxAgents) continue;
|
|
32
|
-
for (const candidate of missing) selected.add(candidate.id);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return agents.filter((agent) => selected.has(agent.id));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function ancestorChain(
|
|
39
|
-
agent: ManagedAgent,
|
|
40
|
-
byId: ReadonlyMap<string, ManagedAgent>,
|
|
41
|
-
): ManagedAgent[] | undefined {
|
|
42
|
-
const chain: ManagedAgent[] = [];
|
|
43
|
-
const seen = new Set<string>();
|
|
44
|
-
let current: ManagedAgent | undefined = agent;
|
|
45
|
-
while (current) {
|
|
46
|
-
if (seen.has(current.id)) return undefined;
|
|
47
|
-
seen.add(current.id);
|
|
48
|
-
chain.unshift(current);
|
|
49
|
-
if (!current.parentId) return chain;
|
|
50
|
-
current = byId.get(current.parentId);
|
|
51
|
-
}
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
package/src/agents/built-ins.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Built-in agent definitions and prompt construction.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { type AgentCapabilityManifest, CAPABILITY_MANIFEST_VERSION } from "../capabilities.js";
|
|
6
|
-
import type { AgentConfig } from "./types.js";
|
|
7
|
-
|
|
8
|
-
export const BUILT_IN_AGENTS: AgentConfig[] = [
|
|
9
|
-
{
|
|
10
|
-
name: "explorer",
|
|
11
|
-
description:
|
|
12
|
-
"Read-only codebase exploration for specific questions; returns concise findings with paths and evidence.",
|
|
13
|
-
tools: ["read", "grep", "find", "ls"],
|
|
14
|
-
capabilityManifest: builtInManifest(["repository-search", "code-evidence"], "read", [
|
|
15
|
-
"evidence-gathering",
|
|
16
|
-
]),
|
|
17
|
-
thinkingLevel: "low",
|
|
18
|
-
source: "built-in",
|
|
19
|
-
filePath: "built-in:explorer",
|
|
20
|
-
systemPrompt: [
|
|
21
|
-
"You are an explorer subagent. Explore the codebase for specific, well-scoped questions and report grounded findings.",
|
|
22
|
-
"Do not edit files, run shell commands, or use any tool outside the read-only inspection set.",
|
|
23
|
-
"Do not install dependencies, run formatters, start servers, run tests, or execute long-running commands.",
|
|
24
|
-
"Return concise bullets with exact file paths, symbols, and open questions.",
|
|
25
|
-
].join("\n"),
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
name: "worker",
|
|
29
|
-
description: "Bounded implementation and command-execution worker with clear ownership.",
|
|
30
|
-
capabilityManifest: builtInManifest(
|
|
31
|
-
["implementation", "command-execution", "repository-modification"],
|
|
32
|
-
"write",
|
|
33
|
-
),
|
|
34
|
-
source: "built-in",
|
|
35
|
-
filePath: "built-in:worker",
|
|
36
|
-
systemPrompt: workerSystemPrompt(),
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
export function getBuiltInAgent(name: string): AgentConfig | undefined {
|
|
41
|
-
const agent = BUILT_IN_AGENTS.find((candidate) => candidate.name === name);
|
|
42
|
-
return agent ? structuredClone(agent) : undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function builtInManifest(
|
|
46
|
-
capabilities: string[],
|
|
47
|
-
filesystem: "read" | "write",
|
|
48
|
-
verificationRoles: string[] = [],
|
|
49
|
-
): AgentCapabilityManifest {
|
|
50
|
-
return {
|
|
51
|
-
version: CAPABILITY_MANIFEST_VERSION,
|
|
52
|
-
capabilities,
|
|
53
|
-
modalities: ["text"],
|
|
54
|
-
resultFormats: ["text", "structured-v1", "structured-v2"],
|
|
55
|
-
authority: { filesystem },
|
|
56
|
-
verificationRoles,
|
|
57
|
-
contextStrengths: ["repository"],
|
|
58
|
-
costHint: filesystem === "read" ? "low" : "medium",
|
|
59
|
-
latencyHint: filesystem === "read" ? "low" : "medium",
|
|
60
|
-
limitations: [],
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function workerSystemPrompt(): string {
|
|
65
|
-
return [
|
|
66
|
-
"You are a focused worker subagent running in an isolated Pi child context.",
|
|
67
|
-
"Complete only the bounded delegated implementation slice and respect its assigned file or responsibility ownership.",
|
|
68
|
-
"Keep scope tight, avoid unrelated changes, and do not overwrite concurrent work outside your ownership.",
|
|
69
|
-
"The main agent owns integration and final verification; report changed files, commands run, and remaining risks for that handoff.",
|
|
70
|
-
].join("\n");
|
|
71
|
-
}
|