@hheei/pi-subagents 0.6.0 → 0.8.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/LICENSES/Apache-2.0.txt +202 -0
- package/NOTICE +10 -0
- package/README.md +14 -12
- package/dist/child-control.d.ts +0 -8
- package/dist/child-control.js +66 -3
- package/dist/commands.js +1 -1
- package/dist/controller-ipc.d.ts +38 -0
- package/dist/controller-ipc.js +292 -0
- package/dist/controller-main.d.ts +1 -0
- package/dist/controller-main.js +26 -0
- package/dist/controller-role.d.ts +40 -0
- package/dist/controller-role.js +37 -0
- package/dist/controller-socket.d.ts +6 -0
- package/dist/controller-socket.js +43 -0
- package/dist/controller.d.ts +25 -0
- package/dist/controller.js +217 -0
- package/dist/delegation.d.ts +73 -0
- package/dist/delegation.js +71 -0
- package/dist/domain.d.ts +20 -18
- package/dist/domain.js +6 -1
- package/dist/extension.js +43 -26
- package/dist/host-adapter.js +1 -1
- package/dist/launch-spec.d.ts +1 -3
- package/dist/launch-spec.js +39 -15
- package/dist/lease.d.ts +0 -1
- package/dist/lease.js +8 -11
- package/dist/mailbox.js +110 -34
- package/dist/manager.d.ts +52 -6
- package/dist/manager.js +585 -48
- package/dist/mcp/app.html +948 -0
- package/dist/mcp/delegate.d.ts +30 -0
- package/dist/mcp/delegate.js +44 -0
- package/dist/mcp/views.d.ts +5 -0
- package/dist/mcp/views.js +12 -0
- package/dist/mcp-server.d.ts +6 -0
- package/dist/mcp-server.js +287 -0
- package/dist/mcp-stdio.d.ts +2 -0
- package/dist/mcp-stdio.js +111 -0
- package/dist/process-lock.d.ts +1 -1
- package/dist/process-lock.js +4 -2
- package/dist/protocol.d.ts +5 -5
- package/dist/protocol.js +3 -4
- package/dist/receipts.d.ts +80 -0
- package/dist/receipts.js +326 -0
- package/dist/runtime.d.ts +5 -26
- package/dist/runtime.js +15 -57
- package/dist/session-bootstrap.js +2 -6
- package/dist/state-db.d.ts +11 -4
- package/dist/state-db.js +102 -24
- package/dist/state.d.ts +1 -0
- package/dist/state.js +29 -3
- package/dist/tool-activation.d.ts +2 -2
- package/dist/tool-activation.js +5 -5
- package/dist/tool-presentation.d.ts +2 -6
- package/dist/tool-presentation.js +75 -122
- package/dist/tools.d.ts +0 -3
- package/dist/tools.js +104 -132
- package/package.json +12 -5
- package/dist/json-lines.d.ts +0 -14
- package/dist/json-lines.js +0 -95
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
This package includes a compact CSS shell adapted from AgentDock.
|
|
2
|
+
|
|
3
|
+
AgentDock mcpapps/app.html
|
|
4
|
+
https://github.com/uvwt/agentdock-protocol/blob/a0ffc5114507a498013dc8a5bbd572114e23bf5d/mcpapps/app.html
|
|
5
|
+
Copyright AgentDock contributors
|
|
6
|
+
Licensed under the Apache License, Version 2.0
|
|
7
|
+
The license text is LICENSES/Apache-2.0.txt.
|
|
8
|
+
|
|
9
|
+
The adapted lines live in src/mcp/app.html and are marked there.
|
|
10
|
+
The rest of @hheei/pi-subagents is MIT licensed; see LICENSE.
|
package/README.md
CHANGED
|
@@ -15,20 +15,20 @@ children and `/subagents stop [id]` to stop one without conflicting with other e
|
|
|
15
15
|
|
|
16
16
|
| Tool | Purpose |
|
|
17
17
|
| --- | --- |
|
|
18
|
-
| `
|
|
19
|
-
| `
|
|
20
|
-
| `
|
|
21
|
-
| `
|
|
18
|
+
| `agents_delegate({ task, agent?, id?, cwd?, wait? })` | Delegate work to a new agent (`agent`) or continue an existing one (`id`, which wins over `agent`). A new child runs in a new Herdr tab (or cmux surface) targeting the parent's workspace when a host is available, and headless in the background otherwise. **Prefer reusing existing agents** via `id` for related/follow-up work to keep context and maximize prompt-cache and memory efficiency. The tool description lists available agent names and roles, excluding disabled or hidden definitions. Deferred by default; discover via `tool_search({ query: "agent" })`. `wait:true` (default) returns the settled delegation, `wait:false` returns it as soon as it is accepted; either way the result arrives automatically, so do not poll. |
|
|
19
|
+
| `agents_get({ id, revision?, includeOutput? })` | Read one delegation of an agent: the newest by default, `revision` for one specific delegation, and the result body only with `includeOutput: true` (bounded by the shared output limit). The view carries the delegation `status` and the runtime `progress.runtimeState` separately, so a new delegation never overwrites a historical result. From the second successful inspection of the same agent in this parent runtime, the result adds a short reminder that results return automatically and must not be polled. Deferred by default; discover via `tool_search({ query: "agent" })`. |
|
|
20
|
+
| `agents_stop({ id })` | Stop one agent's runtime by id. Open delegations end as failed; finished results and the session are kept, so a later `agents_delegate` with this id resumes it. Deferred by default; discover via `tool_search({ query: "agent" })`. |
|
|
21
|
+
| `agents_dashboard({})` | Summarise this session's agents: runtime counts plus each agent's latest delegation status and activity, never result bodies. Deferred by default; discover via `tool_search({ query: "agent" })`. |
|
|
22
22
|
|
|
23
23
|
### Unified Task Management
|
|
24
24
|
|
|
25
|
-
`
|
|
26
|
-
|
|
27
|
-
`
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
`agents_delegate` returns `{ id, revision, status, task, hasOutput }`: `revision` identifies that
|
|
26
|
+
delegation of the agent, and a settled delegation carries its result when `wait` is true.
|
|
27
|
+
`agents_stop` returns the same projection for the agent it stopped. Failures return only their
|
|
28
|
+
reason. There is no public `title` or `mode`: the child session title is derived from the agent name
|
|
29
|
+
and id, and continuing an agent always steers.
|
|
30
30
|
|
|
31
|
-
SubagentManager and its SQLite ledger own child conversation state, runtime leases, recovery, and reports. No pi-ext-tools task service is required. Only delivery batching is shared through ext-core BackgroundDelivery. Child reports arrive automatically; do not poll status to detect completion. Bash uses separate `bg_bash_*` tools. Deferred
|
|
31
|
+
SubagentManager and its SQLite ledger own child conversation state, runtime leases, recovery, and reports. No pi-ext-tools task service is required. Only delivery batching is shared through ext-core BackgroundDelivery. Child reports arrive automatically; do not poll status to detect completion. Bash uses separate `bg_bash_*` tools. Deferred agent tools are loaded via `tool_search`; `before_agent_start` writes the `subagents` bullet into the structured prompt's `optional_tools` section. Diagnostics describe blockers, failed turns, or uncertain runtime state.
|
|
32
32
|
|
|
33
33
|
## Child execution and reporting
|
|
34
34
|
|
|
@@ -37,6 +37,8 @@ Subagents communicate with the parent through the `commands` table in `state.sql
|
|
|
37
37
|
- **Completion by Direct Output**: Subagents do **not** need to call any reporting tool upon successful completion. The subagent simply outputs its final answer as normal assistant text.
|
|
38
38
|
- **Settlement Batching**: When a subagent settles, the harness captures the trailing assistant text and delivers it to the parent conversation as a `subagent-report`. Reports flush within 500ms when no other child is working, and are batched for up to 10 seconds while another child is still running.
|
|
39
39
|
- **Blockers & Decisions**: The child registers `contact_parent({ message, reason? })` strictly for reporting when it is blocked or urgently requires a parent decision midway (`reason` defaults to `'blocked'`). Blocked reports wake the parent immediately.
|
|
40
|
+
- **Direct `/compact` Command**: Sending `"/compact"` (or `"/compact [instructions]"`) via `agents_delegate` intercepts the command on the child side without passing it as prompt text to the LLM. The child executes native context compaction and reports completion status back to the parent via `contact_parent`. Duplicate `/compact` requests while a compaction is already in flight are safely acknowledged and ignored.
|
|
41
|
+
- **Context Trim Hint**: When a subagent completes a task with context usage exceeding 100,000 tokens, its report includes a hint advising the parent to trim memory via `agents_delegate({ id, task: "/compact" })` if the child session will be retained for future work.
|
|
40
42
|
- **Automatic Retry**: Pi's own auto-retry is observed, not invented: reports are suppressed while a retry is in flight, and a retry that succeeds clears the previous error instead of reporting it.
|
|
41
43
|
- **Panel Failure Auto-Close**: When a subagent running in a panel encounters a fatal error or reports a blocker, the manager starts a 15-second countdown after notifying the parent, automatically closing the panel tab to avoid workspace clutter unless new instructions are dispatched.
|
|
42
44
|
## Compact status and reports
|
|
@@ -45,12 +47,12 @@ Running children use the native Pi status line: `🤖 #21 #22 #23`. With pi-
|
|
|
45
47
|
|
|
46
48
|
Confirmed done, error, and blocked reports appear once as `subagent-info` transcript entries. Collapsed entries show the outcome, child ID, and agent name; expand to read the complete report. They survive resume and do not enter model context. The original automatic `subagent-report` still reaches the model, with its duplicate transcript display hidden. Transient errors remain subject to settlement and retry checks before reporting.
|
|
47
49
|
|
|
48
|
-
Use `/subagents` for complete status and management. `
|
|
50
|
+
Use `/subagents` for complete status and management. `agents_delegate` with an existing `id` can resume a done, blocked, errored, or stopped child with its session context intact; retrying does not guarantee the underlying failure is resolved.
|
|
49
51
|
|
|
50
52
|
## Host Integration and Isolation
|
|
51
53
|
|
|
52
54
|
- **Herdr Workspace Affinity**: When spawning in Herdr, tabs are explicitly created in the parent process's current workspace (`--workspace <WORKSPACE_ID>`), preventing child tabs from jumping to whichever workspace happens to have user focus.
|
|
53
|
-
- **
|
|
55
|
+
- **Memory Isolation**: Both `PI_HINDSIGHT_DISABLE=1` and `PI_OBSERVATIONAL_MEMORY_DISABLE=1` are injected into child processes. Hindsight memory auto-registration, recall, and writeback are disabled, and the child bridge blocks all `mcp__hindsight__*` calls. Background Observational Memory workers (observation, reflection, compaction triggers) are suppressed in passive mode.
|
|
54
56
|
|
|
55
57
|
## Agent definitions
|
|
56
58
|
|
package/dist/child-control.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Child-side control plane.
|
|
3
|
-
*
|
|
4
|
-
* The parent drives a child, and the child reports back, over one bridge connection. Every parent
|
|
5
|
-
* request is executed with this process's own Pi primitives, so a child presented in a host panel
|
|
6
|
-
* and a child running headless are controlled identically and no second transport (an RPC writer,
|
|
7
|
-
* a pause handshake) has to be kept in sync with the child's real state.
|
|
8
|
-
*/
|
|
9
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
10
2
|
import type { ChildIdentity } from "./domain.js";
|
|
11
3
|
import { type ChildInputSource } from "./protocol.js";
|
package/dist/child-control.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Child-side control plane.
|
|
3
|
+
*
|
|
4
|
+
* The parent drives a child, and the child reports back, over one bridge connection. Every parent
|
|
5
|
+
* request is executed with this process's own Pi primitives, so a child presented in a host panel
|
|
6
|
+
* and a child running headless are controlled identically and no second transport (an RPC writer,
|
|
7
|
+
* a pause handshake) has to be kept in sync with the child's real state.
|
|
8
|
+
*/
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
1
10
|
import { errorMessage, isRecord } from "@hheei/pi-ext-core";
|
|
2
11
|
import { attachChildMailbox } from "./mailbox.js";
|
|
3
12
|
import { BridgeError, CHILD_INPUT_EVENT } from "./protocol.js";
|
|
@@ -198,6 +207,26 @@ export function registerChildControl(pi, options) {
|
|
|
198
207
|
}
|
|
199
208
|
return ctx;
|
|
200
209
|
};
|
|
210
|
+
const reportCompaction = (controlId, reason, message) => {
|
|
211
|
+
void client
|
|
212
|
+
.report("contact_parent", {
|
|
213
|
+
type: "pi_subagent_report",
|
|
214
|
+
parentSessionId: options.identity.parentSessionId,
|
|
215
|
+
childId: options.identity.subagentId,
|
|
216
|
+
runtimeIdentity: options.identity.runtimeIdentity,
|
|
217
|
+
reason,
|
|
218
|
+
message,
|
|
219
|
+
controlId,
|
|
220
|
+
})
|
|
221
|
+
.catch((err) => {
|
|
222
|
+
options.diagnose?.(`failed to report compaction ${reason}: ${errorMessage(err)}`);
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* The compaction this child is running for a delegation. A second /compact joins it instead of
|
|
227
|
+
* queueing another one, so both delegations settle with the same operation.
|
|
228
|
+
*/
|
|
229
|
+
let compactOperation;
|
|
201
230
|
const deliverPrompt = (payload, deliverAs) => {
|
|
202
231
|
const message = promptMessage(payload);
|
|
203
232
|
// A message needs a session to land in: while the process is between sessions the parent
|
|
@@ -206,6 +235,32 @@ export function registerChildControl(pi, options) {
|
|
|
206
235
|
if (path === undefined) {
|
|
207
236
|
throw new BridgeError("session_not_ready", "This child has no session file path");
|
|
208
237
|
}
|
|
238
|
+
const trimmed = message.trim();
|
|
239
|
+
if (trimmed === "/compact" || trimmed.startsWith("/compact ")) {
|
|
240
|
+
// A compaction this child already runs for a delegation is the operation a new request
|
|
241
|
+
// joins, whatever the event state says yet.
|
|
242
|
+
if (compactOperation !== undefined) {
|
|
243
|
+
return { accepted: true, path, compacting: true, controlId: compactOperation };
|
|
244
|
+
}
|
|
245
|
+
if (isCompacting) {
|
|
246
|
+
throw new BridgeError("compaction_unbound", "A compaction started outside a delegation is already running");
|
|
247
|
+
}
|
|
248
|
+
const controlId = randomUUID();
|
|
249
|
+
compactOperation = controlId;
|
|
250
|
+
const customInstructions = trimmed.slice(8).trim() || undefined;
|
|
251
|
+
requireContext().compact({
|
|
252
|
+
...(customInstructions ? { customInstructions } : {}),
|
|
253
|
+
onComplete: (result) => {
|
|
254
|
+
compactOperation = undefined;
|
|
255
|
+
reportCompaction(controlId, "success", `Context compacted (${result.tokensBefore} -> ${result.estimatedTokensAfter} tokens).`);
|
|
256
|
+
},
|
|
257
|
+
onError: (err) => {
|
|
258
|
+
compactOperation = undefined;
|
|
259
|
+
reportCompaction(controlId, "blocked", `Compaction failed: ${err.message}`);
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
return { accepted: true, path, compacting: true, controlId };
|
|
263
|
+
}
|
|
209
264
|
if (isCompacting) {
|
|
210
265
|
pendingCompactionDeliveries.push({ message, deliverAs });
|
|
211
266
|
return { accepted: true, path, queuedForCompaction: true };
|
|
@@ -248,12 +303,20 @@ export function registerChildControl(pi, options) {
|
|
|
248
303
|
return deliverPrompt(request.payload, undefined);
|
|
249
304
|
case "steer":
|
|
250
305
|
return deliverPrompt(request.payload, "steer");
|
|
251
|
-
case "follow_up":
|
|
252
|
-
return deliverPrompt(request.payload, "followUp");
|
|
253
306
|
case "get_state":
|
|
254
307
|
return childState(requireContext(), isCompacting);
|
|
255
308
|
case "get_entries": {
|
|
256
|
-
|
|
309
|
+
const payload = isRecord(request.payload) ? request.payload : undefined;
|
|
310
|
+
const cursor = typeof payload?.cursor === "number" && payload.cursor >= 0
|
|
311
|
+
? Math.floor(payload.cursor)
|
|
312
|
+
: 0;
|
|
313
|
+
const limit = typeof payload?.limit === "number" && payload.limit > 0
|
|
314
|
+
? Math.min(Math.floor(payload.limit), 100)
|
|
315
|
+
: 20;
|
|
316
|
+
const all = currentEntries();
|
|
317
|
+
const entries = all.slice(cursor, cursor + limit);
|
|
318
|
+
const nextCursor = cursor + entries.length < all.length ? cursor + entries.length : undefined;
|
|
319
|
+
return { entries, ...(nextCursor === undefined ? {} : { nextCursor }) };
|
|
257
320
|
}
|
|
258
321
|
case "session_facts": {
|
|
259
322
|
const expected = isRecord(request.payload) ? request.payload.expectedInput : undefined;
|
package/dist/commands.js
CHANGED
|
@@ -46,7 +46,7 @@ export function registerParentCommands(pi, manager) {
|
|
|
46
46
|
getArgumentCompletions: subcommandCompletions(SUBAGENT_SUBCOMMANDS),
|
|
47
47
|
handler: async (args, ctx) => {
|
|
48
48
|
if (ctx.mode !== "tui") {
|
|
49
|
-
ctx.ui.notify("Use
|
|
49
|
+
ctx.ui.notify("Use agents_delegate / agents_get / agents_stop in this mode");
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
const { verb, rest: target } = splitSubcommand(args);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Server } from "node:net";
|
|
2
|
+
import type { ControllerManager } from "./controller-role.js";
|
|
3
|
+
/** Bumped whenever this call surface changes: a client never talks to a controller from another build. */
|
|
4
|
+
export declare const CONTROLLER_PROTOCOL = 2;
|
|
5
|
+
export type ControllerOp = "protocol" | "delegate" | "receipts" | "get" | "list" | "stop" | "transcript";
|
|
6
|
+
export interface ControllerCall {
|
|
7
|
+
readonly op: ControllerOp;
|
|
8
|
+
readonly input: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface ControllerReply {
|
|
11
|
+
readonly ok: boolean;
|
|
12
|
+
readonly result?: unknown;
|
|
13
|
+
readonly error?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function serveControllerIpc(options: {
|
|
16
|
+
readonly socketPath: string;
|
|
17
|
+
readonly parentSessionId: string;
|
|
18
|
+
readonly manager: ControllerManager;
|
|
19
|
+
/** Ledger this controller records delegations in; defaults to this parent's state database. */
|
|
20
|
+
readonly statePath?: string;
|
|
21
|
+
}): Promise<Server>;
|
|
22
|
+
/** Stops listening and drops open calls. `server.close()` alone waits until every wait:true socket ends. */
|
|
23
|
+
export declare function closeControllerIpc(server: Server): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* What answered on this socket. `silent` is not a protocol: a slow or dead peer must not be treated
|
|
26
|
+
* as an older build.
|
|
27
|
+
*/
|
|
28
|
+
export type ControllerProbe = {
|
|
29
|
+
readonly state: "ready";
|
|
30
|
+
readonly protocol: number;
|
|
31
|
+
} | {
|
|
32
|
+
readonly state: "foreign";
|
|
33
|
+
} | {
|
|
34
|
+
readonly state: "silent";
|
|
35
|
+
};
|
|
36
|
+
/** The call surface of the controller listening here. Only an actual answer can be foreign. */
|
|
37
|
+
export declare function controllerProtocol(socketPath: string): Promise<ControllerProbe>;
|
|
38
|
+
export declare function callController(socketPath: string, call: ControllerCall, signal?: AbortSignal): Promise<ControllerReply>;
|