pi-task-dispatcher 2.0.0 → 3.0.1
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 +176 -76
- package/extensions/task-dispatcher.ts +1281 -552
- package/package.json +50 -42
- package/tests/fake-rpc-check.mjs +237 -0
- package/tests/fake-rpc-worker.mjs +133 -0
- package/tests/gate-probe.mjs +155 -0
- package/tests/static-check.mjs +43 -0
package/README.md
CHANGED
|
@@ -1,124 +1,224 @@
|
|
|
1
1
|
# pi-task-dispatcher
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Supervised mechanical, assistant, engineering, and media-design delegations for Pi.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
- **Two focused worker roles:** route precise execution work to a mechanic model and broader implementation work to an engineer model.
|
|
8
|
-
- **Least-privilege delegation:** every call supplies an exact tool allowlist selected from tools active for the main agent. Workers cannot invoke the delegation tools recursively.
|
|
9
|
-
- **Live progress:** streamed worker text, tool activity, and an elapsed-time heartbeat keep long-running tasks visible.
|
|
10
|
-
- **Recoverable interruption:** approaching time and turn limits request a worker-authored checkpoint. A hard timeout returns a synthetic fallback checkpoint.
|
|
11
|
-
- **Explicit continuation:** a checkpoint never starts another worker automatically. The main agent reviews current state and decides what happens next.
|
|
12
|
-
|
|
13
|
-
## Worker tools
|
|
14
|
-
|
|
15
|
-
The package adds two model-only tools to Pi:
|
|
5
|
+
Each delegation runs in an isolated, in-memory Pi RPC session. After every cohesive tool batch, a worker-side gate stops execution at a safe boundary and returns a bounded state report. The manager can then inspect the result and explicitly continue, revise, compact, checkpoint, cancel, or take over.
|
|
16
6
|
|
|
17
|
-
|
|
18
|
-
| --- | --- |
|
|
19
|
-
| `delegate_mechanical` | Bounded multi-step inspection, exact edits, repetitive transformations, commands, retrieval, or verification with precise acceptance conditions. |
|
|
20
|
-
| `delegate_engineering` | Self-contained investigation, implementation, debugging, refactoring, testing, review, research, or analysis. |
|
|
21
|
-
|
|
22
|
-
The main model remains the **orchestrator**. It defines the delegated task, selects the smallest sufficient tool allowlist, evaluates the report, reviews material changes, performs required verification, and owns the final answer.
|
|
7
|
+
## Features
|
|
23
8
|
|
|
24
|
-
|
|
9
|
+
- **Four worker roles:** prescribed mechanical execution, bounded assistant work, broader engineering, and media design.
|
|
10
|
+
- **Enforced supervision:** a private parent-child IPC gate calls `ctx.abort()` after persisted tool results; pausing does not depend on the worker following a prompt.
|
|
11
|
+
- **Explicit control:** continue, revise, recalculate, compact, checkpoint, cancel, or take over.
|
|
12
|
+
- **Resumable context:** continuation uses the same in-memory worker session and completed tool results.
|
|
13
|
+
- **Least privilege:** every start selects an exact isolated-worker tool allowlist; delegation tools and unrelated discovered extensions are unavailable to the worker. Pi's built-in `codemode` extension loads only when explicitly selected.
|
|
14
|
+
- **Model agnostic:** every role inherits Pi's active model and thinking level unless an explicit role override is configured.
|
|
15
|
+
- **Formula-owned budgets:** the manager supplies semantic workload units, while the dispatcher calculates turn and time ceilings from workload, role, and delegated-model limits.
|
|
16
|
+
- **Context insight:** boundary reports include worker context usage, compactions, turns, elapsed time, action counts, and recommendations.
|
|
17
|
+
- **Recoverable reports:** the complete action ledger and worker text remain in structured tool details; bounded model-facing text retains recent actions plus both the beginning and ending of long reports.
|
|
18
|
+
- **Deterministic UI:** tool renderers display task, current activity, elapsed time, context pressure, and terminal success/failure colors. Pi's footer retains the latest state of every role invoked in the session.
|
|
25
19
|
|
|
26
20
|
## Requirements
|
|
27
21
|
|
|
28
|
-
- Pi 1.0.
|
|
22
|
+
- Pi 1.0.4 or later
|
|
29
23
|
- Node.js 22.19.0 or later
|
|
30
|
-
-
|
|
24
|
+
- One active, authenticated Pi model; optional role-specific models must also be available and authenticated
|
|
25
|
+
|
|
26
|
+
The supervision gate requires the parent Pi process and child Pi CLI to run under Node.js with an inherited IPC channel. The dispatcher fails closed when that boundary cannot be established; it does not fall back to prompt-only supervision. Worker processes disable ordinary extension discovery and load the generated supervision gate plus Pi's built-in `codemode` extension only when that tool was explicitly selected.
|
|
31
27
|
|
|
32
28
|
## Installation
|
|
33
29
|
|
|
34
|
-
Install the package for
|
|
30
|
+
Install the published package for the current Pi user:
|
|
35
31
|
|
|
36
32
|
```sh
|
|
37
33
|
pi install npm:pi-task-dispatcher
|
|
38
34
|
```
|
|
39
35
|
|
|
40
|
-
|
|
36
|
+
## Tools
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
| Tool | Responsibility |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `delegate_mechanical` | Execute prescribed work whose method and expected result are already known. |
|
|
41
|
+
| `delegate_assistant` | Perform bounded, low-complexity interpretation, synthesis, or routine updates. |
|
|
42
|
+
| `delegate_engineering` | Investigate or implement uncertain, cross-component, or technically intensive work. |
|
|
43
|
+
| `delegate_designer` | Create or edit image assets and process image, video, or audio files with available tools. |
|
|
44
|
+
| `delegate_control` | Apply one explicit manager decision to a paused delegation. |
|
|
45
|
+
| `delegate_status` | Recover the current or most recent state without changing it. |
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
Only one live delegation is currently permitted. A terminal delegation may be inspected until a new one replaces it.
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
/reload
|
|
50
|
-
```
|
|
49
|
+
## Choosing a role
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
| Role | Selection rule |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| Mechanic | The method and expected result are known; execute exact steps. |
|
|
54
|
+
| Assistant | The task needs limited judgment but remains bounded, low-risk, and locally verifiable. It does not assume manager authority or make architectural decisions. |
|
|
55
|
+
| Engineer | The cause, design, or implementation path is uncertain or spans components. |
|
|
56
|
+
| Designer | The requested result is an image, video, audio, or related media asset or transformation. |
|
|
57
|
+
|
|
58
|
+
The designer can inspect images with `read`, use image models through `codemode`, and run explicitly selected command-line media programs through `bash` or `powershell`. Generated codemode images are runtime-temporary until the worker deliberately copies a selected output to the requested workspace destination and verifies it. Video and audio generation depends on explicitly available command-line programs or services; editing workflows can use programs such as `ffmpeg` when installed.
|
|
53
59
|
|
|
54
|
-
|
|
60
|
+
## Starting a delegation
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
| --- | --- | --- | ---: | ---: | ---: |
|
|
58
|
-
| Mechanic | `openai-codex/gpt-5.6-luna` | `max` | 300 seconds | 30 seconds | 20 |
|
|
59
|
-
| Engineer | `openai-codex/gpt-5.6-terra` | `max` | 900 seconds | 45 seconds | 30 |
|
|
62
|
+
Every role tool requires:
|
|
60
63
|
|
|
61
|
-
|
|
64
|
+
- `task`: a self-contained objective, scope, constraints, and acceptance checks;
|
|
65
|
+
- `tools`: the smallest exact allowlist selected from Pi's built-in tools and active for the main agent;
|
|
66
|
+
- `workload`: semantic estimates used by the deterministic budget formula.
|
|
62
67
|
|
|
63
68
|
```json
|
|
64
69
|
{
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
"engineer": {
|
|
73
|
-
"model": "openai-codex/gpt-5.6-terra",
|
|
74
|
-
"thinking": "max",
|
|
75
|
-
"timeoutSeconds": 900,
|
|
76
|
-
"checkpointGraceSeconds": 45,
|
|
77
|
-
"maxTurns": 30
|
|
70
|
+
"task": "Inspect the parser cache, correct its invalidation, and run the focused tests.",
|
|
71
|
+
"tools": ["read", "edit", "bash"],
|
|
72
|
+
"workload": {
|
|
73
|
+
"investigationUnits": 3,
|
|
74
|
+
"changeUnits": 2,
|
|
75
|
+
"verificationUnits": 2,
|
|
76
|
+
"expectedLongRunningSeconds": 60
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
```
|
|
81
80
|
|
|
82
|
-
|
|
81
|
+
A workload unit is intentionally semantic:
|
|
82
|
+
|
|
83
|
+
- `investigationUnits`: cohesive components or evidence groups to inspect;
|
|
84
|
+
- `changeUnits`: related edit groups;
|
|
85
|
+
- `verificationUnits`: focused check or test groups;
|
|
86
|
+
- `expectedLongRunningSeconds`: additional expected command time.
|
|
87
|
+
|
|
88
|
+
At least one investigation, change, or verification unit is required.
|
|
89
|
+
|
|
90
|
+
Isolated workers accept `read`, `bash`, `powershell`, `edit`, `write`, `grep`, `find`, `ls`, and `codemode` when the selected tools are also active in the main Pi session. `codemode` is loaded as an explicit Pi built-in while ordinary extension discovery remains disabled. Its scripts can call only the worker's callable tools and non-LLM model catalog; unrelated manager extensions and delegation tools remain unavailable.
|
|
91
|
+
|
|
92
|
+
The current formula derives planned work turns from those units, applies a role factor and a bounded scale based on the selected delegated model's own context window, reserves two additional turns for synthesis or recovery, then derives active execution time from calculated turns plus expected long-running time. Administrative ceilings always win. Formula inputs and results are returned in every state report so they can be reviewed and recalculated. Time spent paused for manager deliberation does not consume the active execution budget.
|
|
93
|
+
|
|
94
|
+
## Safe action boundaries
|
|
95
|
+
|
|
96
|
+
A worker run proceeds as follows:
|
|
97
|
+
|
|
98
|
+
1. Pi produces one assistant response.
|
|
99
|
+
2. Its complete tool-call batch runs and tool results are persisted.
|
|
100
|
+
3. The worker-only gate reports the boundary through private IPC.
|
|
101
|
+
4. The gate aborts the automatic next worker turn.
|
|
102
|
+
5. The RPC run settles while the child process and in-memory context remain alive.
|
|
103
|
+
6. The delegation tool returns the new state to the manager.
|
|
104
|
+
|
|
105
|
+
An action batch can contain parallel tool calls from one worker response. Already-running tools are allowed to finish. The boundary prevents another productive model turn from starting without a manager decision.
|
|
106
|
+
|
|
107
|
+
A tool-free response that reaches the model's output limit is retained as a recoverable paused state. Continuing resumes the same in-memory session so the worker can finish its truncated report; the dispatcher does not misreport that response as completed.
|
|
108
|
+
|
|
109
|
+
## Controlling a paused delegation
|
|
110
|
+
|
|
111
|
+
`delegate_control` accepts these actions:
|
|
112
|
+
|
|
113
|
+
| Action | Effect |
|
|
83
114
|
| --- | --- |
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
115
|
+
| `continue` | Resume from completed results. `actionBatches` may lease 1–10 batches before returning. |
|
|
116
|
+
| `revise` | Add controlling instructions, then resume. |
|
|
117
|
+
| `recalculate` | Supply remaining semantic workload and extend the current ceilings from observed turns and active execution time without running the worker. |
|
|
118
|
+
| `compact` | Compact the idle worker's own context and return refreshed state. |
|
|
119
|
+
| `take_over` | Stop the delegation externally and transfer remaining work to the manager. |
|
|
120
|
+
| `checkpoint` | Stop externally and preserve a synthetic checkpoint from observed state. |
|
|
121
|
+
| `cancel` | Stop externally and close the job. |
|
|
122
|
+
|
|
123
|
+
Example:
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"jobId": "engineer-2",
|
|
128
|
+
"action": "continue",
|
|
129
|
+
"actionBatches": 2
|
|
130
|
+
}
|
|
131
|
+
```
|
|
90
132
|
|
|
91
|
-
|
|
133
|
+
The dispatcher enforces takeover, cancellation, budget exhaustion, no-progress policy, and process cleanup. These actions do not depend on worker cooperation.
|
|
92
134
|
|
|
93
|
-
|
|
135
|
+
## State reports and screen output
|
|
94
136
|
|
|
95
|
-
|
|
137
|
+
A paused result contains:
|
|
96
138
|
|
|
97
|
-
|
|
139
|
+
- a session-local sequential identity such as `engineer-2`, plus role, model, and status;
|
|
140
|
+
- the delegated task and live command or tool activity while execution is running;
|
|
141
|
+
- boundary sequence and current phase;
|
|
142
|
+
- completed, failed, and potentially mutating action counts;
|
|
143
|
+
- recent bounded activity labels in completion order and image-output MIME/size metadata without retained base64 payloads;
|
|
144
|
+
- active elapsed time and turns against calculated budgets;
|
|
145
|
+
- context tokens, context window, percentage, and compaction counts;
|
|
146
|
+
- a recommended next decision;
|
|
147
|
+
- bounded worker text, if any.
|
|
98
148
|
|
|
99
|
-
|
|
149
|
+
The TUI renders the same structured state as a compact block. Expanding the tool result reveals bounded worker text. The complete action ledger and worker text remain in result details for state reconstruction rather than being discarded by display truncation.
|
|
100
150
|
|
|
101
|
-
|
|
151
|
+
After the first worker state, one unindented, dim footer status remains below Pi's primary report and updates across worker lifecycle states. It retains the newest state observed for every invoked role, with the most recently updated role first and each entry ordered as identity, context, model, and thinking—for example, `engineer-2 · 10.3%/32k • model-name • medium | mechanic-1 · 8.1%/128k • smaller-model • low`. Each percentage and window comes from that delegation's own fresh worker session; a continuation accumulates context in the same job, while a new delegation starts a new context. Current or latest action details appear in the delegation or manager block rather than the footer.
|
|
102
152
|
|
|
103
|
-
|
|
153
|
+
## Worker compaction
|
|
104
154
|
|
|
105
|
-
|
|
155
|
+
The dispatcher explicitly enables automatic compaction in every worker session. Pi's automatic compaction remains the overflow safety mechanism.
|
|
106
156
|
|
|
107
|
-
|
|
157
|
+
The dispatcher also:
|
|
108
158
|
|
|
109
|
-
|
|
159
|
+
- observes compaction lifecycle events;
|
|
160
|
+
- accounts for reported compaction usage;
|
|
161
|
+
- queries `get_session_stats` at safe boundaries;
|
|
162
|
+
- recommends proactive compaction when context usage reaches the current policy threshold;
|
|
163
|
+
- permits explicit worker compaction only while paused.
|
|
110
164
|
|
|
111
|
-
|
|
165
|
+
Worker compaction is independent from compaction of the main Pi conversation.
|
|
112
166
|
|
|
113
|
-
|
|
167
|
+
## Configuration
|
|
114
168
|
|
|
115
|
-
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
169
|
+
The optional configuration file is `task-dispatcher.json` in Pi's agent directory.
|
|
170
|
+
|
|
171
|
+
```json
|
|
172
|
+
{
|
|
173
|
+
"mechanic": {
|
|
174
|
+
"model": "provider/mechanic-model",
|
|
175
|
+
"thinking": "high"
|
|
176
|
+
},
|
|
177
|
+
"assistant": {
|
|
178
|
+
"model": "provider/assistant-model",
|
|
179
|
+
"thinking": "low"
|
|
180
|
+
},
|
|
181
|
+
"engineer": {
|
|
182
|
+
"model": "provider/engineer-model",
|
|
183
|
+
"thinking": "high"
|
|
184
|
+
},
|
|
185
|
+
"designer": {
|
|
186
|
+
"model": "provider/vision-model",
|
|
187
|
+
"thinking": "medium"
|
|
188
|
+
},
|
|
189
|
+
"policy": {
|
|
190
|
+
"absoluteMaxTurns": 96,
|
|
191
|
+
"absoluteMaxSeconds": 7200,
|
|
192
|
+
"pausedLeaseSeconds": 1800,
|
|
193
|
+
"noProgressSeconds": 600
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Configuration is read for every new delegation. By default, all roles inherit the manager's active model and thinking level, so installation assumes no particular provider or model access. Each role may optionally override `model` with `"provider/model"`, `thinking`, or both. Policy values are administrative failsafes, not ordinary task budgets.
|
|
199
|
+
|
|
200
|
+
Version 3 intentionally ignores the version 2 fields `maxTurns`, `timeoutSeconds`, and `checkpointGraceSeconds`. Remove them from local configuration after migration.
|
|
201
|
+
|
|
202
|
+
## Lifecycle and cleanup
|
|
203
|
+
|
|
204
|
+
- A parent-operation abort stops the active worker stage.
|
|
205
|
+
- A paused lease eventually closes an abandoned worker.
|
|
206
|
+
- Session shutdown or extension reload disposes the child and runtime-controlled temporary files.
|
|
207
|
+
- Worker process failures reject pending RPC operations and produce a failed state.
|
|
208
|
+
- Worker role instructions and the supervision gate exist only in a runtime-controlled temporary directory.
|
|
209
|
+
- The selected built-in `codemode` extension may create runtime-temporary image outputs; the designer must persist requested outputs explicitly before completion.
|
|
210
|
+
- The worker uses `--no-session`; no worker session file is persisted.
|
|
211
|
+
|
|
212
|
+
Process separation is not a security sandbox. Worker tools execute with the Pi host's operating-system permissions. Tool availability does not establish task scope or authorization.
|
|
213
|
+
|
|
214
|
+
## Development checks
|
|
215
|
+
|
|
216
|
+
```sh
|
|
217
|
+
npm run check
|
|
218
|
+
npm run test:gate
|
|
219
|
+
```
|
|
119
220
|
|
|
120
|
-
|
|
221
|
+
`check` runs static release invariants and deterministic fake-RPC lifecycle and renderer scenarios. The fake child verifies all role registrations, pause/resume, output-limit recovery, usage deltas, nested codemode usage accounting, media metadata without base64 retention, persistent per-role footer state, full action-ledger retention, intercepted prompts, missing-boundary failure, fail-closed timeouts, pre-aborted operations, partial argument rendering, stable repeated rendering, and manager-state transitions without a model request.
|
|
121
222
|
|
|
122
|
-
|
|
223
|
+
`test:gate` performs a small live model integration check with the active parent model exported by Pi through `PI_PROVIDER`, `PI_MODEL`, and `PI_REASONING_LEVEL`, falling back to Pi's configured default when those values are unavailable; it contains no provider or model assumption. Optional `PI_TASK_DISPATCHER_GATE_MODEL` and `PI_TASK_DISPATCHER_GATE_THINKING` overrides are available for explicit test matrices. The probe verifies selective built-in `codemode` loading, a private pause after its completed tool batch, and subsequent completion in the same in-memory child. It requires configured credentials and therefore is not a hermetic unit test.
|
|
123
224
|
|
|
124
|
-
Worker process separation is **not** a security sandbox. A worker uses its selected tools with the Pi host's permissions in the current environment. Tool availability does not establish task scope, authorization, or safety. Use the smallest practical allowlist and delegate only work you are prepared to authorize and review.
|