pi-durable-subagents 1.0.27 → 1.0.28
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/CHANGELOG.md +41 -0
- package/README.md +121 -10
- package/dist/agent/child.js +7 -2
- package/dist/agent/main/schema.js +4 -1
- package/dist/agent/main/tool.js +42 -8
- package/dist/agent/main.js +62 -12
- package/dist/cli/doctor.js +4 -3
- package/dist/cli/drill/index.js +287 -0
- package/dist/cli/drill/provider.js +25 -0
- package/dist/cli/hold.js +28 -14
- package/dist/cli/main.js +50 -11
- package/dist/cli/requests.js +102 -18
- package/dist/kernel/journal.js +99 -15
- package/dist/kernel/mailbox.js +1 -1
- package/dist/orchestrator/engine.js +157 -12
- package/dist/orchestrator/evaluator-client.js +18 -3
- package/dist/orchestrator/executor/digest.js +80 -0
- package/dist/orchestrator/executor/index.js +47 -37
- package/dist/orchestrator/executor/observe.js +21 -7
- package/dist/orchestrator/notes.js +20 -0
- package/dist/orchestrator/restart.js +5 -3
- package/dist/orchestrator/snapshot.js +144 -21
- package/dist/orchestrator/stats.js +49 -0
- package/dist/platform/containment.js +35 -11
- package/dist/platform/lease.js +37 -11
- package/dist/platform/proctable.js +16 -3
- package/dist/requests.js +27 -0
- package/dist/ui/view.js +5 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.28
|
|
4
|
+
|
|
5
|
+
- Lower orchestrator cost. A finished workflow's journal is closed about a
|
|
6
|
+
second after its last write and reopened on demand, so finished workflows
|
|
7
|
+
cost nothing while nothing touches them (before: one open file and periodic
|
|
8
|
+
work per workflow ever run). Live calls now look only at session entries
|
|
9
|
+
appended since the last check instead of rescanning the whole session every
|
|
10
|
+
second, and the process scan indexes the process table once per pass.
|
|
11
|
+
Measured in an isolated home: idle with 300 finished workflows about 0.006
|
|
12
|
+
core (was 0.03); 3 live calls with 20 MB sessions about 0.03 core (was 0.07,
|
|
13
|
+
growing with session size).
|
|
14
|
+
- `status --json` and `doctor --json` include `orchestratorStats` (workflows,
|
|
15
|
+
live workflows, open journals, intake passes per second, bytes read); text
|
|
16
|
+
`status` shows it on one line.
|
|
17
|
+
- `send kind:"notify"` tells a call a decision without disturbing it: a
|
|
18
|
+
running call gets it at its next safe point (`steered`), a call waiting on
|
|
19
|
+
its question gets it after the answer (`held-until-answer`), and a call that
|
|
20
|
+
is not running starts nothing: the note is recorded (`noted`) and its next
|
|
21
|
+
follow-up opens with every pending note, once. Restart the orchestrator after
|
|
22
|
+
upgrading before using it; an older orchestrator makes the client refuse it.
|
|
23
|
+
- `to` may list several calls for `steer`, `notify`, `follow-up` and `model`
|
|
24
|
+
(CLI: repeated `--to`); each target is decided on its own and the reply has
|
|
25
|
+
one entry per target. A retry with the same request id and list is
|
|
26
|
+
idempotent; another list under that id is a `request-conflict`.
|
|
27
|
+
- `hold <name> --slots N -- <cmd>` is a counted lease: at most N holders at a
|
|
28
|
+
time, FIFO, with the same release and visibility as other leases;
|
|
29
|
+
`leases`, `status` and restart refusals show `held k/N`. A granted ticket is
|
|
30
|
+
never treated as blocked afterwards.
|
|
31
|
+
- `pi-durable-subagents drill failover` rehearses pool failover in an isolated
|
|
32
|
+
home with a scripted provider (about 30 s, offline): a call moves from a
|
|
33
|
+
used-up provider to the next candidate, new calls avoid the provider, and it
|
|
34
|
+
is used again after a probe. Interrupting it cleans up.
|
|
35
|
+
- `events <wid>` names the target model of a model switch, and `failover:` the
|
|
36
|
+
provider it left when the switch was a failover.
|
|
37
|
+
- `run`: with `tasks`/`chain`, a top-level `agent` is the default agent of
|
|
38
|
+
every step. A run reply names calls that start queued behind another call's
|
|
39
|
+
writer lock (`writerWait`).
|
|
40
|
+
- `status`: run labels show on each workflow line and in the list.
|
|
41
|
+
`status <wid>` takes `tail: N` and `grep: "<regex>"` (CLI `--tail`,
|
|
42
|
+
`--grep`) to return just the last or matching lines of each call's result.
|
|
43
|
+
|
|
3
44
|
## 1.0.27
|
|
4
45
|
|
|
5
46
|
- `hold --no-wait` (or `--max-wait 0`) takes the lease at once or exits 75
|
package/README.md
CHANGED
|
@@ -73,13 +73,24 @@ subagents({ tasks: [{ agent: "scout", task: "…" }, { agent: "reviewer", task:
|
|
|
73
73
|
subagents({ chain: [{ agent: "worker", task: "…" }, { agent: "reviewer", task: "Review: {previous}" }] })
|
|
74
74
|
subagents({ workflow: "./batch.js", args: { … }, usageBudget: { costUsd: 20 } })
|
|
75
75
|
subagents({ action: "send", to: "<wid>/<key>", kind: "steer", message: "Don't touch the tests yet" })
|
|
76
|
+
subagents({ action: "send", to: ["<wid>/a", "<wid>/b"], kind: "notify", message: "Config is TOML from now on" })
|
|
76
77
|
subagents({ action: "status" })
|
|
77
78
|
```
|
|
78
79
|
|
|
79
80
|
`status` without a wid is brief: what runs, what asks (with the address to
|
|
80
|
-
answer) or failed, and one line per finished workflow
|
|
81
|
+
answer) or failed, and one line per finished workflow, each with its run
|
|
82
|
+
`labels` clipped to 60 characters (the `/subagents` list shows them on a
|
|
83
|
+
workflow's row when they fit). `status` with a wid
|
|
81
84
|
shows one workflow with outputs clipped; add `key` for one call's full result,
|
|
82
|
-
or `full: true` for everything.
|
|
85
|
+
or `full: true` for everything. `tail: N` gives the last N lines of each call's
|
|
86
|
+
result instead, and `grep: "<regex>"` only its lines matching a case-sensitive
|
|
87
|
+
JavaScript regular expression (both: grep first, then the last N); either is
|
|
88
|
+
unclipped up to 4000 characters per call, which suits a receipt on the last
|
|
89
|
+
line of each output. An invalid regex is an error. The regex runs in the
|
|
90
|
+
process that asks (the pi session or the CLI), so avoid nested quantifiers
|
|
91
|
+
such as `(a+)+`, which can take seconds on one line; to bound its cost it
|
|
92
|
+
tests only the first 2000 characters of a line and the last 5000 lines of an
|
|
93
|
+
output (the reply then starts with `[n earlier lines not searched]`). When a run replies `{submitted: {rid}}`
|
|
83
94
|
(its workflow was not created within 10 s), the rid works wherever a wid does.
|
|
84
95
|
A call's `model` in `status` is the model its last provider request used; a
|
|
85
96
|
requested switch not used yet shows as `switching`, a refused one as
|
|
@@ -87,10 +98,17 @@ requested switch not used yet shows as `switching`, a refused one as
|
|
|
87
98
|
(`next-request`, `next-execution` or `next-generation`).
|
|
88
99
|
A provider's refusal of the content (terms of service, usage policy) fails the
|
|
89
100
|
call at once with that error instead of retrying it.
|
|
90
|
-
With `tasks` or `chain`, top-level `model`, `timeoutMs`, `budget`,
|
|
91
|
-
`context`, `tools`, `skills` and `
|
|
92
|
-
|
|
93
|
-
|
|
101
|
+
With `tasks` or `chain`, top-level `agent`, `model`, `timeoutMs`, `budget`,
|
|
102
|
+
`isolation`, `context`, `tools`, `skills`, `once` and `writer` apply to every
|
|
103
|
+
step that does not set its own, e.g.
|
|
104
|
+
`{ tasks: [{ task: "…" }, { task: "…" }], agent: "reviewer" }`. A top-level
|
|
105
|
+
`task` beside a list is refused (agent + task is a single call); other call
|
|
106
|
+
fields there, and any of them beside a workflow script, are refused rather
|
|
107
|
+
than ignored.
|
|
108
|
+
When a call of a new run already waits for its worktree's writer lock as the
|
|
109
|
+
run reply is written, the reply names it: `writerWait: ["<wid>/<key> held by
|
|
110
|
+
<wid>/<key> (<root>)"]` with a hint that `writer: false` or
|
|
111
|
+
`isolation: "worktree"` opts out. The reply does not wait for this.
|
|
94
112
|
|
|
95
113
|
Every run is asynchronous. The agent is woken once, when the workflow
|
|
96
114
|
finishes (the notice carries each subagent's result) or when a subagent asks
|
|
@@ -100,12 +118,47 @@ it something. Each verb means one thing, and a refusal says what would work:
|
|
|
100
118
|
|---|---|---|
|
|
101
119
|
| `run` | — | Start one subagent, `tasks` in parallel, a `chain`, or a workflow script. An unknown agent name is refused before anything starts, with the list of agents. |
|
|
102
120
|
| `send steer` | a running subagent | Reaches it at its next safe point. To a finished one: refused, use `follow-up`; To one waiting on its question: it interrupts the question, and the subagent usually asks again; `answer` answers it. |
|
|
121
|
+
| `send notify` | any subagent | Tells it a decision without disturbing it. The reply's `delivery` says how: `steered` (running: it gets the note at its next safe point, like a steer), `held-until-answer` (waiting on its question: never interrupts it; it gets the note at the first safe point after the answer) or `noted` (not running: nothing starts; the note is recorded, and the call's next follow-up opens with it). |
|
|
103
122
|
| `send follow-up` | a finished subagent | Continues the same session as a new generation (`key@2`). With `model` (a model or a pool's name), that generation runs on it. |
|
|
104
123
|
| `send answer` | an open question | Answers it once. |
|
|
105
124
|
| `send model` | any subagent | A running one switches at its next request; one asking, hibernated or waiting for a slot launches on it when it runs again. A pool's name picks its first model that is not used up (and, for a running call, has a free slot); the reply names the model picked, and a call from that pool stays in it. |
|
|
106
125
|
| `stop` | a subagent or a workflow | Final: `stopped`, usage kept, edits left as they are. |
|
|
107
126
|
| `drain` / `resume` | existing workflows | A reversible hold; runs started later are not held. |
|
|
108
127
|
|
|
128
|
+
Notes recorded for a call that is not running are durable and pending until
|
|
129
|
+
its next follow-up, whose opening message carries all of them, in order, before
|
|
130
|
+
its own message:
|
|
131
|
+
|
|
132
|
+
```text
|
|
133
|
+
Notes recorded after your last turn:
|
|
134
|
+
- Config is TOML from now on
|
|
135
|
+
- Keep the old parser for one release
|
|
136
|
+
|
|
137
|
+
<the follow-up's message>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Each note is delivered once, also across orchestrator restarts and retried
|
|
141
|
+
requests. A notify accepted for a running call that seals before it gets the
|
|
142
|
+
note becomes a pending note too. `status` shows them on the call
|
|
143
|
+
(`b@1 ok "..." · 2 notes pending`; JSON `notesPending`).
|
|
144
|
+
|
|
145
|
+
`to` may list several calls for `steer`, `notify`, `follow-up` and `model`
|
|
146
|
+
(`answer` takes one). Each call gets its own request and is decided on its
|
|
147
|
+
own: an unknown or refused target does not affect the others, and the reply
|
|
148
|
+
has one entry per target (`targets`, plus a `summary` line each). With
|
|
149
|
+
`request: "<id>"`, the target at position i (1-based, in the order given) is
|
|
150
|
+
sent as `<id>:<i>`, so a retry with the same list gets the same outcomes and
|
|
151
|
+
sends nothing twice. Each of those requests records the whole list, so another
|
|
152
|
+
message, another list (longer, shorter or reordered) or a single send under
|
|
153
|
+
that id is a `request-conflict`, and nothing of it is sent. The list is compared
|
|
154
|
+
as written: retry with the same addresses (the same run id or `wid/key` form),
|
|
155
|
+
or the retry is a conflict too.
|
|
156
|
+
|
|
157
|
+
`notify` is new in 1.0.28: after upgrading, restart the orchestrator
|
|
158
|
+
(`pi-durable-subagents restart` or the tool's restart action) before using it.
|
|
159
|
+
While an older orchestrator runs, a notify is refused with that advice and
|
|
160
|
+
nothing is sent (an older orchestrator would accept it and drop it).
|
|
161
|
+
|
|
109
162
|
### Workflow scripts
|
|
110
163
|
|
|
111
164
|
A workflow is a plain script. These are the globals it can use:
|
|
@@ -233,7 +286,11 @@ unchanged, with zero edited lines.
|
|
|
233
286
|
```text
|
|
234
287
|
pi-durable-subagents smoke check this machine and this pi (offline, < 60 s)
|
|
235
288
|
pi-durable-subagents chaos run the fault suite (offline, about 2 minutes)
|
|
289
|
+
pi-durable-subagents drill failover [--keep] [--json]
|
|
290
|
+
rehearse pool failover in a temporary home (offline, about 30 s)
|
|
236
291
|
pi-durable-subagents status [wid] [--json]
|
|
292
|
+
pi-durable-subagents status <wid> [--tail <n>] [--grep <regex>] [--json]
|
|
293
|
+
each call's last n lines and/or its lines matching regex
|
|
237
294
|
pi-durable-subagents events <wid> [--json] the meaningful timeline of one workflow
|
|
238
295
|
pi-durable-subagents events --all [--since <cursor>] [--limit <n>] [--json]
|
|
239
296
|
milestones of every workflow, read with a cursor (see below)
|
|
@@ -244,7 +301,7 @@ pi-durable-subagents drain hold existing workflows: running calls f
|
|
|
244
301
|
pi-durable-subagents stop <wid|call>
|
|
245
302
|
pi-durable-subagents run --request <id> --spec <file|-> [--labels <json>] [--cwd <dir>] [--json] [--wait-ms <n>]
|
|
246
303
|
start a run under a caller-chosen id; safe to retry (see below)
|
|
247
|
-
pi-durable-subagents send --request <id> --to <run-id|wid/key> --kind follow-up|answer|steer|model
|
|
304
|
+
pi-durable-subagents send --request <id> --to <run-id|wid/key> [--to ...] --kind follow-up|answer|steer|notify|model
|
|
248
305
|
[--call <key>] [--qid <qid> --rev <n>] --message <text|@file> [--model <m>] [--json]
|
|
249
306
|
pi-durable-subagents stop --request <id> <run-id|wid|wid/key|call> [--json]
|
|
250
307
|
pi-durable-subagents describe --key <run-id> | <wid> [--json]
|
|
@@ -254,7 +311,7 @@ pi-durable-subagents stop-all pause every existing workflow now; journ
|
|
|
254
311
|
pi-durable-subagents prune [wid] [--older-than <days>]
|
|
255
312
|
delete finished workflows (done, failed, stopped); prints count and bytes freed
|
|
256
313
|
pi-durable-subagents restart [--force <token> --reason <text>] switch to the installed version (see "Updating Durable Subagents")
|
|
257
|
-
pi-durable-subagents hold <resource> [--shared] [--max-wait <s> | --no-wait] [--note <text>] -- <command…>
|
|
314
|
+
pi-durable-subagents hold <resource> [--shared | --slots <n>] [--max-wait <s> | --no-wait] [--note <text>] -- <command…>
|
|
258
315
|
run one command while holding a resource lease (see below)
|
|
259
316
|
pi-durable-subagents leases [--json] who holds and who waits for each resource
|
|
260
317
|
pi-durable-subagents doctor [--json] read-only health check; exits 1 when something needs you
|
|
@@ -287,7 +344,7 @@ session and is rejected.
|
|
|
287
344
|
|
|
288
345
|
| exit | meaning | `--json` reply |
|
|
289
346
|
| --- | --- | --- |
|
|
290
|
-
| 0 | decided and applied (a retry gets the same answer) | run: `{request, wid, created, spec_digest}
|
|
347
|
+
| 0 | decided and applied (a retry gets the same answer) | run: `{request, wid, created, spec_digest, writerWait?, hint?}` (`writerWait: [{call, heldBy, cwd}]`: calls already queued behind a writer lock); send/stop: `{request, applied, generation?, call?, spec_digest}` |
|
|
291
348
|
| 1 | decided and rejected (`reason`), or refused before submission (usage error, invalid spec, unknown agent: this invocation submitted nothing) | `{request, applied: false, reason, spec_digest?}` (`spec_digest` once the content could be hashed) |
|
|
292
349
|
| 3 | `request-conflict`: the id already names other content; nothing was sent | `{request, error, wid?, spec_digest, state}` (the original's digest and state) |
|
|
293
350
|
| 75 | not decided yet: submitted but undecided in `--wait-ms` (default 60 s), submitted and then a later step failed (`reason` says which), or a lock was busy (`reason: "busy"`); an id already recorded is never refused again (the same content gets its first outcome, its agents are not rechecked; other content is a conflict); retry with the same id | `{request, pending: true, reason?}` |
|
|
@@ -298,6 +355,14 @@ tombstone keeps the final status, the id and the digest. Any sender's retry
|
|
|
298
355
|
completes a submission another one recorded but did not publish (it died in
|
|
299
356
|
between), so a retry with the same content always converges.
|
|
300
357
|
|
|
358
|
+
A send with several `--to` (not for `answer`) sends `<id>:1` ... `<id>:n`, one
|
|
359
|
+
per target in the order given, and prints one line per target (`--json`:
|
|
360
|
+
`{request, targets: [{to, request, applied, ...}]}`). The same id with another
|
|
361
|
+
message or list (also a longer one) is a conflict and sends nothing. Its exit code is 3 when the
|
|
362
|
+
id or one target names other content, else 75 when one target is not decided
|
|
363
|
+
yet, else 1 when one was rejected, else 0. A notify's reply adds `delivery`
|
|
364
|
+
(`steered`, `held-until-answer` or `noted`) and a `note` that says what it means.
|
|
365
|
+
|
|
301
366
|
From the `subagents` tool, `request` works the same, with one difference: a
|
|
302
367
|
run's origin session (what `context: "fork"` copies, and where notices go) is
|
|
303
368
|
not part of the digest. A retry of the same id from another session therefore
|
|
@@ -455,6 +520,25 @@ never comes back. `doctor` shows disk use, workflows by status, the largest
|
|
|
455
520
|
journals, parked work, old open questions, and leftovers; each finding
|
|
456
521
|
comes with one command to fix it.
|
|
457
522
|
|
|
523
|
+
Finished workflows cost the orchestrator nothing while nobody touches them:
|
|
524
|
+
once a workflow has ended (or parked) with no follow-up or execution open,
|
|
525
|
+
its journal file is closed and nothing reads it periodically. A follow-up,
|
|
526
|
+
resume, revise, stop or prune reopens it as needed. `status` and `doctor`
|
|
527
|
+
show what the running orchestrator costs on one line,
|
|
528
|
+
|
|
529
|
+
```text
|
|
530
|
+
orchestrator: 1.0.28 (pid 4242) · 3 live / 190 workflows, 3 journals open, 0.4 passes/s, read 12 MB
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
and `status --json` / `doctor --json` carry it as `orchestratorStats`:
|
|
534
|
+
`workflows` (not pruned), `liveWorkflows` (with work still open),
|
|
535
|
+
`openJournals` (journal files held open), `passesPerSecond` (intake passes
|
|
536
|
+
that ran, averaged over the last minute; an idle orchestrator runs almost
|
|
537
|
+
none), `readBytes` (bytes the process read since it started, from
|
|
538
|
+
`/proc/self/io`; absent where there is none), `pid` and `at` (when it was
|
|
539
|
+
written). The orchestrator writes these to `orchestrator-stats.json` every
|
|
540
|
+
10 s; they are shown only while that process runs.
|
|
541
|
+
|
|
458
542
|
### Resource leases
|
|
459
543
|
|
|
460
544
|
Benchmarks, timing measurements and big builds need the machine to
|
|
@@ -465,6 +549,7 @@ command:
|
|
|
465
549
|
pi-durable-subagents hold machine -- make bench # exclusive
|
|
466
550
|
pi-durable-subagents hold machine --shared -- npm test # with other shared holders, never with an exclusive one
|
|
467
551
|
pi-durable-subagents hold machine --max-wait 600 --note "profile" -- ./measure.sh
|
|
552
|
+
pi-durable-subagents hold build --slots 4 -- cargo test # at most 4 at a time
|
|
468
553
|
```
|
|
469
554
|
|
|
470
555
|
- The lease covers one command, not a whole call: a subagent that thinks
|
|
@@ -473,6 +558,16 @@ pi-durable-subagents hold machine --max-wait 600 --note "profile" -- ./measure.s
|
|
|
473
558
|
everything before it, and keeps later shared requests out (no starvation).
|
|
474
559
|
A waiting `hold` prints who holds the resource; `--max-wait` gives up with
|
|
475
560
|
exit 75 without running the command.
|
|
561
|
+
- `--slots N` (an integer of at least 1; not with `--shared`) makes the
|
|
562
|
+
resource a counting semaphore: a request runs once fewer than N holders
|
|
563
|
+
(slot or shared) hold it, no exclusive request is ahead of it, and no
|
|
564
|
+
earlier request of any kind still waits, so it never overtakes a waiter.
|
|
565
|
+
Shared requests are not limited by slots but occupy them, and they do not
|
|
566
|
+
queue behind a slot waiter, so a stream of shared requests can keep it
|
|
567
|
+
waiting; use one mode and one N per resource name. `leases` shows
|
|
568
|
+
``build 3/4 held: pid 123 `cargo test` (slot, 2m), ...; waiting: 2 (first: pid 456, 30s)``,
|
|
569
|
+
`leases --json` adds `slots` and `held` to the resource,
|
|
570
|
+
and a waiting `hold` prints its position and `held k/N`.
|
|
476
571
|
- `--no-wait` (same as `--max-wait 0`) takes the lease now or not at all.
|
|
477
572
|
It decides under the resource's lock. If it can run now, its request is
|
|
478
573
|
written already granted. Otherwise nothing is written, and it exits 75
|
|
@@ -531,7 +626,23 @@ State lives in `~/.pi/durable-subagents`; set `DSA_HOME` to move it.
|
|
|
531
626
|
time goes to it, so finding out costs no extra request. A call that moved to
|
|
532
627
|
another provider stays there for the rest of its generation (switching back
|
|
533
628
|
mid-task would lose the prompt cache); a follow-up starts on the first
|
|
534
|
-
candidate again. `status` lists each used-up provider with its next try
|
|
629
|
+
candidate again. `status` lists each used-up provider with its next try,
|
|
630
|
+
and `events <wid>` shows the move as a model `forward` naming the target
|
|
631
|
+
(`model=<provider>/<id>`) and the provider it left (`failover=<provider>`);
|
|
632
|
+
a model you send shows only its target.
|
|
633
|
+
- **Rehearsing failover:** `pi-durable-subagents drill failover` runs the
|
|
634
|
+
real CLI, orchestrator and subagent pi processes in a temporary home, with
|
|
635
|
+
two offline providers in a pool: the first refuses with a used-up window
|
|
636
|
+
(`503 ... No available accounts`), the second answers. It checks, step by
|
|
637
|
+
step, that a call moves to the second provider, that `status` lists the
|
|
638
|
+
first with its next try, that a second call starts on the second provider,
|
|
639
|
+
that after the probe interval (25 s here) the next call probes the first
|
|
640
|
+
provider and finds it available, and that this call ends on it. Each step
|
|
641
|
+
prints pass/fail and its time; the exit code is 0 only when all pass. Your
|
|
642
|
+
home, providers and credentials are not used. `--json` prints the result as
|
|
643
|
+
one object; `--keep` keeps the temporary directory and prints its path.
|
|
644
|
+
Interrupted (Ctrl-C), it stops what it started and cleans up the same way
|
|
645
|
+
(exit 130, or 143 for SIGTERM).
|
|
535
646
|
- **Provider slots:** never exceeded, including while a model switch is in
|
|
536
647
|
progress.
|
|
537
648
|
- **Memory:** new subagents wait while memory is short. Running ones are
|
package/dist/agent/child.js
CHANGED
|
@@ -10,7 +10,7 @@ import { openness } from "../kernel/guards.js";
|
|
|
10
10
|
import { recover } from "./child/history.js";
|
|
11
11
|
import { validate } from "./child/schema.js";
|
|
12
12
|
import { registerLive } from "./child/live.js";
|
|
13
|
-
const MESSAGES = ['task', 'steer', 'follow-up', 'continue'];
|
|
13
|
+
const MESSAGES = ['task', 'steer', 'notify', 'follow-up', 'continue'];
|
|
14
14
|
/** P31, P33, P37: Usage of this call only — assistant messages in segments opened by this call's executions,
|
|
15
15
|
* deduplicated by entry id. Context inherited from an earlier generation or a forked origin is not charged. */
|
|
16
16
|
export function usage(entries, call) {
|
|
@@ -78,7 +78,7 @@ export function registerChild(pi) {
|
|
|
78
78
|
if (!active || (mode === 'idle' && !ctx.isIdle()))
|
|
79
79
|
return [];
|
|
80
80
|
let delivered = false;
|
|
81
|
-
const plans = planDecisions(state.records, candidates, req => {
|
|
81
|
+
const plans = planDecisions(state.records, candidates, (req, view) => {
|
|
82
82
|
if (req.to !== call)
|
|
83
83
|
return { action: 'reject', reason: 'wrong-recipient' };
|
|
84
84
|
if ([...MESSAGES, 'answer'].includes(req.kind) && typeof req.body?.message !== 'string')
|
|
@@ -105,6 +105,11 @@ export function registerChild(pi) {
|
|
|
105
105
|
if (MESSAGES.includes(req.kind)) {
|
|
106
106
|
if ((mode === 'idle' && delivered) || (req.kind === 'follow-up' && mode === 'boundary'))
|
|
107
107
|
return { action: 'defer' };
|
|
108
|
+
// A notify never interrupts a question: while an answer waits to be delivered (a hibernated asker resumes with
|
|
109
|
+
// its answer as a continue) it goes after it, at the next safe point. In ask mode it was deferred above.
|
|
110
|
+
if (req.kind === 'notify' && candidates.some(other => !view.resolved.has(other.rid) && !view.tombstones.has(other.rid) &&
|
|
111
|
+
(other.kind === 'answer' && !state.answered.has(`${other.cond?.qid}@${other.cond?.rev}`) || other.kind === 'continue' && other.cond?.qid !== undefined)))
|
|
112
|
+
return { action: 'defer' };
|
|
108
113
|
delivered = true;
|
|
109
114
|
return { action: 'apply' };
|
|
110
115
|
}
|
|
@@ -10,7 +10,8 @@ export const parameters = Type.Object({
|
|
|
10
10
|
chain: Type.Optional(Type.Array(Type.Any(), { description: `Sequential calls ({previous} = previous output). ${stepsDoc}` })),
|
|
11
11
|
agent: Type.Optional(Type.String()), task: Type.Optional(Type.String()), model: Type.Optional(Type.String()),
|
|
12
12
|
cwd: Type.Optional(Type.String({ description: "Run directory (default: this session's). Relative workflow, inputs and call cwd paths resolve against it." })),
|
|
13
|
-
to: Type.Optional(Type.String()
|
|
13
|
+
to: Type.Optional(Type.Union([Type.String(), Type.Array(Type.String())], { description: "send: '<wid>/<key>', or a list of them for steer, notify, follow-up and model (one request per call; answer takes one)." })),
|
|
14
|
+
kind: Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("notify"), Type.Literal("follow-up"), Type.Literal("answer"), Type.Literal("model")])),
|
|
14
15
|
message: Type.Optional(Type.String()), qid: Type.Optional(Type.String()), rev: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
15
16
|
replaces: Type.Optional(Type.Array(Type.String())), target: Type.Optional(Type.String()), wid: Type.Optional(Type.String()),
|
|
16
17
|
usageBudget: Type.Optional(Type.Object({ tokens: Type.Optional(Type.Number()), costUsd: Type.Optional(Type.Number()) })),
|
|
@@ -19,6 +20,8 @@ export const parameters = Type.Object({
|
|
|
19
20
|
labels: Type.Optional(Type.Record(Type.String(), Type.String(), { description: "run: your labels, e.g. {node, attempt}: at most 32 keys [A-Za-z0-9_.:-]{1,64}, string values of at most 256 characters, 4096 bytes of JSON; part of the request's content (spec_digest), shown by describe and on its events." })),
|
|
20
21
|
timeoutMs: Type.Optional(Type.Number({ description: "Per-call limit on active time in milliseconds (a number). Omit unless a hard limit is needed; prefer budgets." })),
|
|
21
22
|
key: Type.Optional(Type.String({ description: "A single agent/task run: the call's key. status with wid: that call's full result." })),
|
|
23
|
+
tail: Type.Optional(Type.Integer({ minimum: 1, description: "status with wid: the last N lines of each call's result (unclipped, at most 4000 characters per call)." })),
|
|
24
|
+
grep: Type.Optional(Type.String({ description: "status with wid: only the lines of each call's result matching this case-sensitive JS regular expression, run in-process: avoid nested quantifiers such as (a+)+; it tests the first 2000 characters of a line and the last 5000 lines (with tail: grep first, then the last N)." })),
|
|
22
25
|
full: Type.Optional(Type.Boolean({ description: "status: with wid, the complete workflow detail including every output." })),
|
|
23
26
|
force: Type.Optional(Type.Union([Type.String(), Type.Boolean()], { description: "restart: the token shown by a refusal. Show the user the list and obtain explicit approval first; boolean true is refused. Subagents cannot force a restart (an environment-based rail against accidents, not a security boundary)." })),
|
|
24
27
|
reason: Type.Optional(Type.String({ description: "restart: non-empty reason, at most 500 characters; required with force." })),
|
package/dist/agent/main/tool.js
CHANGED
|
@@ -4,7 +4,7 @@ import { validateCallSpec } from "../../compat/spec.js";
|
|
|
4
4
|
import { compileFanout } from "../../compat/fanout.js";
|
|
5
5
|
import { checkLabels } from "../../events/labels.js";
|
|
6
6
|
/** Call fields a tasks/chain run applies to every step that does not set its own. */
|
|
7
|
-
export const stepDefaults = ["model", "timeoutMs", "budget", "isolation", "context", "tools", "skills", "once", "writer"];
|
|
7
|
+
export const stepDefaults = ["agent", "model", "timeoutMs", "budget", "isolation", "context", "tools", "skills", "once", "writer"];
|
|
8
8
|
function string(args, name) {
|
|
9
9
|
if (typeof args[name] !== "string" || !args[name])
|
|
10
10
|
throw new Error(`${name} is required`);
|
|
@@ -35,21 +35,51 @@ export function checkAgents(body, available) {
|
|
|
35
35
|
* at its next provider request), `next-execution` (a call with no live execution launches on it) or `next-generation`
|
|
36
36
|
* (a follow-up's new generation runs on it). From the orchestrator ledger's `send-note`. */
|
|
37
37
|
export function sendReceipt(ledger, rid) {
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
// The latest one counts: a replayed notify corrects what an interrupted first decision recorded.
|
|
39
|
+
const note = ledger.findLast(e => e.type === "send-note" && e.rid === rid);
|
|
40
|
+
if (!note)
|
|
41
|
+
return {};
|
|
42
|
+
if (typeof note.delivery === "string")
|
|
43
|
+
return { delivery: note.delivery, note: DELIVERY_NOTE[note.delivery] ?? note.delivery };
|
|
44
|
+
return { model: String(note.model), effect: String(note.effect), ...(note.pool ? { pool: String(note.pool) } : {}) };
|
|
40
45
|
}
|
|
46
|
+
/** The internal argument through which a send to several calls passes its `batch` (not a tool parameter). */
|
|
47
|
+
export const BATCH = Symbol("batch");
|
|
48
|
+
/** One line of a reply per target: applied (with how a notify went), rejected with its reason, or not decided yet. */
|
|
49
|
+
export function outcomeLine(r) {
|
|
50
|
+
if (r.applied === true)
|
|
51
|
+
return `applied${r.delivery ? ` (${String(r.delivery)}: ${String(r.note)})` : r.effect ? ` (model ${String(r.model)}, ${String(r.effect)})` : ""}`;
|
|
52
|
+
if (r.applied === false)
|
|
53
|
+
return `rejected ${String(r.reason)}`;
|
|
54
|
+
if (r.submitted)
|
|
55
|
+
return `submitted, not decided yet (${String(r.submitted.rid)})`;
|
|
56
|
+
return JSON.stringify(r);
|
|
57
|
+
}
|
|
58
|
+
export const DELIVERY_NOTE = {
|
|
59
|
+
steered: "the call is running; it gets the note at its next safe point",
|
|
60
|
+
"held-until-answer": "the call waits on its question; it gets the note after the answer",
|
|
61
|
+
noted: "the call is not running: recorded as a pending note for its next follow-up (nothing was started)",
|
|
62
|
+
};
|
|
41
63
|
export function request(args, cwd) {
|
|
42
64
|
// v12 §2: Infer run only when one launch form is present; never guess a control verb.
|
|
43
|
-
|
|
65
|
+
// A top-level agent without a task beside tasks/chain is the steps' default agent, not a launch form of its own.
|
|
66
|
+
const listRun = args.tasks !== undefined || args.chain !== undefined;
|
|
67
|
+
// A task beside tasks/chain is refused with what to do, before the launch form is inferred (with or without action).
|
|
68
|
+
if ((args.action === undefined || args.action === "run") && listRun && args.task !== undefined)
|
|
69
|
+
throw new Error(`task cannot be set beside ${args.tasks !== undefined ? "tasks" : "chain"}: agent+task is a single call; give each step its own task (a top-level agent alone is the default agent of every step)`);
|
|
70
|
+
const launchForms = [args.task !== undefined || args.agent !== undefined && !listRun, args.tasks !== undefined,
|
|
44
71
|
args.chain !== undefined, args.workflow !== undefined, args.source !== undefined];
|
|
45
72
|
const action = args.action === undefined && launchForms.filter(Boolean).length === 1 ? "run" : args.action;
|
|
46
73
|
if (typeof action !== "string" || !action)
|
|
47
74
|
throw new Error("action is required: run, agents, send, stop, revise, status, resume, drain, restart");
|
|
48
75
|
if (action === "run") {
|
|
49
76
|
const { action: _, workflow, source, tasks, chain, args: inputs, name, usageBudget, maxCalls, inputs: files, labels, by: _by, request: _request, ...spec } = args;
|
|
50
|
-
const
|
|
77
|
+
const steps = tasks !== undefined || chain !== undefined;
|
|
78
|
+
// With tasks/chain a top-level agent (no task) is the default agent of every step, like model or timeoutMs.
|
|
79
|
+
const single = spec.task !== undefined || spec.agent !== undefined && !steps;
|
|
80
|
+
const choices = [workflow, source, tasks, chain, single ? spec : undefined];
|
|
51
81
|
if (choices.filter(v => v !== undefined).length !== 1)
|
|
52
|
-
throw new Error("run requires exactly one of workflow, source, tasks, chain, or agent/task");
|
|
82
|
+
throw new Error("run requires exactly one of workflow, source, tasks, chain, or agent/task (with tasks/chain, a top-level agent without task is the steps' default agent)");
|
|
53
83
|
// A top-level cwd on a workflow/tasks/chain/source run is the run's directory: relative paths (the workflow file,
|
|
54
84
|
// inputs, per-call cwd) resolve against it and calls default to it. It used to be ignored, so a relative
|
|
55
85
|
// workflow path was looked up in the session's directory instead.
|
|
@@ -110,11 +140,15 @@ export function request(args, cwd) {
|
|
|
110
140
|
}
|
|
111
141
|
if (action === "send") {
|
|
112
142
|
const kind = string(args, "kind");
|
|
113
|
-
if (!["steer", "follow-up", "answer", "model"].includes(kind))
|
|
143
|
+
if (!["steer", "notify", "follow-up", "answer", "model"].includes(kind))
|
|
114
144
|
throw new Error("Unsupported send kind");
|
|
145
|
+
if (Array.isArray(args.to))
|
|
146
|
+
throw new Error("to names one call here; several targets are sent one request each");
|
|
115
147
|
// follow-up may name the model its continuation runs on (P37); other kinds ignore one.
|
|
116
148
|
const model = kind === "model" || kind === "follow-up" && args.model !== undefined ? { model: string(args, "model") } : {};
|
|
117
|
-
|
|
149
|
+
// `batch` is set by a send to several calls (see manyIds in src/requests.ts), never by a caller.
|
|
150
|
+
const body = { to: string(args, "to"), kind, ...model, ...(kind === "model" ? {} : { message: string(args, "message") }), ...(args.by === "user" ? { by: "user" } : {}),
|
|
151
|
+
...(typeof args[BATCH] === "string" ? { batch: args[BATCH] } : {}) };
|
|
118
152
|
const cond = {};
|
|
119
153
|
if (kind === "answer") {
|
|
120
154
|
cond.qid = string(args, "qid");
|
package/dist/agent/main.js
CHANGED
|
@@ -12,10 +12,10 @@ import { OsLock } from "../platform/lock.js";
|
|
|
12
12
|
import { dsaHome, orchInbox, orchLedger, orchLock, outboxRoot } from "../paths.js";
|
|
13
13
|
import { CT, JT } from "../types.js";
|
|
14
14
|
import { attention, presentText, presented, resolved, unfinishedWorkflow } from "./main/snapshots.js";
|
|
15
|
-
import { isLive, pausedElsewhere, runningOrchestrator, statusBrief, statusCallDetail, statusCompactDetail, statusDetail, statusView, widOfRid } from "../orchestrator/snapshot.js";
|
|
16
|
-
import { checkAgents, request, sendReceipt } from "./main/tool.js";
|
|
15
|
+
import { NOTIFY_SINCE, isLive, orchestratorTooOld, pausedElsewhere, runningOrchestrator, statusBrief, statusCallDetail, statusCompactDetail, statusDetail, statusView, widOfRid, outputSelect, writerWaits, writerWaitLine, WRITER_WAIT_HINT } from "../orchestrator/snapshot.js";
|
|
16
|
+
import { BATCH, checkAgents, outcomeLine, request, sendReceipt } from "./main/tool.js";
|
|
17
17
|
import { parameters } from "./main/schema.js";
|
|
18
|
-
import { findRequest, requestRid, sendIdentified } from "../requests.js";
|
|
18
|
+
import { batchConflict, batchDigest, findRequest, manyIds, namesMany, requestRid, sendIdentified } from "../requests.js";
|
|
19
19
|
import { discoverAgents } from "../compat/agents.js";
|
|
20
20
|
import { restartInputError } from "../orchestrator/restart.js";
|
|
21
21
|
import { currentOrchestrator, legacyRestart, waitExit } from "../cli/restart.js";
|
|
@@ -236,9 +236,9 @@ export function registerMain(pi, ui) {
|
|
|
236
236
|
return { ...args, to: to ?? q.call, qid: q.qid, rev: args.rev ?? q.rev };
|
|
237
237
|
}
|
|
238
238
|
if (typeof args.to !== "string" || !args.to) {
|
|
239
|
-
const want = args.kind === "follow-up" ? (c) => c.phase === "sealed" : (c) => c.phase !== "sealed";
|
|
239
|
+
const want = args.kind === "follow-up" ? (c) => c.phase === "sealed" : args.kind === "notify" ? () => true : (c) => c.phase !== "sealed";
|
|
240
240
|
const targets = own.flatMap(w => w.calls.filter(want).map(c => `${w.wid}/${c.key}`));
|
|
241
|
-
throw new Error(`to is required: '<wid>/<key>'${targets.length ? `; ${args.kind === "follow-up" ? "finished" : "running"}: ${targets.slice(0, 12).join(", ")}` : ""}`);
|
|
241
|
+
throw new Error(`to is required: '<wid>/<key>'${targets.length ? `; ${args.kind === "follow-up" ? "finished" : args.kind === "notify" ? "calls" : "running"}: ${targets.slice(0, 12).join(", ")}` : ""}`);
|
|
242
242
|
}
|
|
243
243
|
return args;
|
|
244
244
|
}
|
|
@@ -260,7 +260,39 @@ export function registerMain(pi, ui) {
|
|
|
260
260
|
const others = pausedElsewhere(home, sender);
|
|
261
261
|
return others.length ? `nothing-to-resume: nothing of this session is paused; paused in other sessions: ${others.slice(0, 8).join(", ")} — resume wid=<wid> continues one` : reason;
|
|
262
262
|
}
|
|
263
|
+
/** A send to several calls: one request per target (the same kind, message and model), each decided on its own; the
|
|
264
|
+
* reply lists every target's outcome. With a request id <id>, target i (1-based, in the order given) is sent as
|
|
265
|
+
* <id>:<i>, so a retry with the same list gets the same outcomes; another list under that id is a request-conflict. */
|
|
266
|
+
async function sendMany(args, cwd, signal, wait = true) {
|
|
267
|
+
const targets = args.to;
|
|
268
|
+
if (!targets.length || !targets.every(t => typeof t === "string" && t))
|
|
269
|
+
throw new Error("to must name a call '<wid>/<key>' or a nonempty list of them");
|
|
270
|
+
if (args.kind === "answer")
|
|
271
|
+
throw new Error("answer goes to one call: give to as a single address");
|
|
272
|
+
if (targets.length === 1)
|
|
273
|
+
return submit({ ...args, to: targets[0] }, cwd, signal, wait);
|
|
274
|
+
if (args.replaces !== undefined)
|
|
275
|
+
throw new Error("replaces supersedes one earlier send: use it with a single target");
|
|
276
|
+
const id = args.request, ids = typeof id === "string" ? manyIds(id, targets.length) : undefined;
|
|
277
|
+
if (id !== undefined && !ids)
|
|
278
|
+
throw new Error(REQUEST_USE);
|
|
279
|
+
const batch = batchDigest(targets);
|
|
280
|
+
if (ids && typeof id === "string" && await batchConflict(home, id, batch))
|
|
281
|
+
return { applied: false, reason: "request-conflict", request: id, note: "this request id was used for different content (another message or list of calls); use a new id" };
|
|
282
|
+
const results = await Promise.all(targets.map(async (to, i) => {
|
|
283
|
+
const request = ids ? { request: ids[i] } : {};
|
|
284
|
+
try {
|
|
285
|
+
return { to, ...request, ...await submit({ ...args, to, ...request, ...(ids ? { [BATCH]: batch } : {}) }, cwd, signal, wait) };
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
return { to, ...request, applied: false, reason: error instanceof Error ? error.message : String(error) };
|
|
289
|
+
}
|
|
290
|
+
}));
|
|
291
|
+
return { targets: results, summary: results.map(r => `${String(r.to)}: ${outcomeLine(r)}`).join("\n") };
|
|
292
|
+
}
|
|
263
293
|
async function submit(args, cwd, signal, wait = true) {
|
|
294
|
+
if (args.action === "send" && Array.isArray(args.to))
|
|
295
|
+
return sendMany(args, cwd, signal, wait);
|
|
264
296
|
// A run answers {submitted:{rid}} when its workflow is not created within 10 s; that rid then stands for the wid.
|
|
265
297
|
for (const field of ["wid", "to", "target"])
|
|
266
298
|
if (typeof args[field] === "string")
|
|
@@ -268,14 +300,20 @@ export function registerMain(pi, ui) {
|
|
|
268
300
|
if (args.request !== undefined && (args.action === "status" || args.action === "agents"))
|
|
269
301
|
throw new Error(REQUEST_USE);
|
|
270
302
|
if (args.action === "status") {
|
|
271
|
-
|
|
303
|
+
const select = outputSelect(args.tail, args.grep);
|
|
304
|
+
if (typeof args.wid !== "string" || !args.wid) {
|
|
305
|
+
if (select)
|
|
306
|
+
throw new Error("tail and grep select lines of one workflow's outputs: give a wid");
|
|
272
307
|
return statusBrief(home, { origin: sender });
|
|
308
|
+
}
|
|
273
309
|
const pending = pendingRun(args.wid);
|
|
274
310
|
if (pending)
|
|
275
311
|
return pending;
|
|
312
|
+
if (select && (args.full === true || typeof args.key === "string" && args.key))
|
|
313
|
+
throw new Error("tail and grep apply to status wid=<wid> without key or full");
|
|
276
314
|
if (typeof args.key === "string" && args.key)
|
|
277
315
|
return statusCallDetail(home, args.wid, args.key);
|
|
278
|
-
return args.full === true ? statusDetail(home, args.wid) : statusCompactDetail(home, args.wid);
|
|
316
|
+
return args.full === true ? statusDetail(home, args.wid) : statusCompactDetail(home, args.wid, select);
|
|
279
317
|
}
|
|
280
318
|
if (args.action === "agents")
|
|
281
319
|
return agentsAt(cwd).map(({ name, description, model, source }) => ({ name, description, ...(model === undefined ? {} : { model }), source }));
|
|
@@ -301,6 +339,15 @@ export function registerMain(pi, ui) {
|
|
|
301
339
|
if (args.request !== undefined && (typeof args.request !== "string" || !["run", "send", "stop"].includes(normalized.kind) || normalized.replaces?.length))
|
|
302
340
|
throw new Error(REQUEST_USE);
|
|
303
341
|
const rid = typeof args.request === "string" ? requestRid(args.request) : undefined;
|
|
342
|
+
// A single send under an id that already names a send to several calls (<id>:1 ...) is other content.
|
|
343
|
+
if (rid && normalized.kind === "send" && !await findRequest(home, rid) && await namesMany(home, String(args.request)))
|
|
344
|
+
return { applied: false, reason: "request-conflict", request: args.request, note: "this request id was used for a send to several calls; use a new id" };
|
|
345
|
+
// A retry of a recorded request gets its first outcome; a new notify is refused while an orchestrator too old for it runs.
|
|
346
|
+
if (normalized.kind === "send" && normalized.body.kind === "notify" && !(rid && await findRequest(home, rid))) {
|
|
347
|
+
const old = orchestratorTooOld(home, 'send kind "notify"', NOTIFY_SINCE);
|
|
348
|
+
if (old)
|
|
349
|
+
throw new Error(old);
|
|
350
|
+
}
|
|
304
351
|
if (normalized.kind === "run")
|
|
305
352
|
checkAgents(normalized.body, () => agentsAt(cwd).map(agent => agent.name));
|
|
306
353
|
// P33: any call of the run may fork the origin context, so the origin branch is always offered for pinning.
|
|
@@ -352,8 +399,11 @@ export function registerMain(pi, ui) {
|
|
|
352
399
|
const decision = receipt ? undefined : decisions().get(sent.rid);
|
|
353
400
|
if (receipt || decision) {
|
|
354
401
|
await serial(async () => { await outbox?.markResolved(sent.rid); });
|
|
355
|
-
if (receipt)
|
|
356
|
-
|
|
402
|
+
if (receipt) {
|
|
403
|
+
// A call already queued behind a worktree's writer lock is named at once (read once; nothing waits for it).
|
|
404
|
+
const waits = writerWaits(home, String(receipt.wid));
|
|
405
|
+
return { wid: receipt.wid, ...(waits.length ? { writerWait: waits.map(writerWaitLine), hint: WRITER_WAIT_HINT } : {}) };
|
|
406
|
+
}
|
|
357
407
|
// The rid is returned so a later send can supersede this one (replaces: [rid]).
|
|
358
408
|
if (decision.type === "rejected")
|
|
359
409
|
return { applied: false, reason: sent.kind === "resume" && args.wid === undefined ? resumeElsewhere(String(decision.reason)) : decision.reason, rid: sent.rid };
|
|
@@ -378,10 +428,10 @@ export function registerMain(pi, ui) {
|
|
|
378
428
|
pi.registerTool(defineTool({
|
|
379
429
|
name: "subagents", label: "Subagents", description: [
|
|
380
430
|
"Durable asynchronous subagents; run returns {wid} when created (or {submitted:{rid}} while pending). A finished workflow (its notice carries every agent's result) or a question wakes you, so after starting work end your turn: never poll with sleep or repeated status. Crash recovery resumes sessions, not external side effects. Background helper processes (orchestrator, evaluator) exit by themselves about 10 s after all work ends: never kill processes or delete files to 'clean up'. When the user quits pi, this session's running workflows pause (nothing is spent); resume continues them.",
|
|
381
|
-
"run (action optional for exactly one launch form): agent+task; tasks:[call specs] parallel; chain:[call specs] sequential ({previous}); workflow:'./script.js' or source (runs.run(key,spec), runs.all([...]), emit(value), args, runs.input(name)). Optional name, cwd, usageBudget, maxCalls, inputs, labels. With tasks/chain, top-level model, timeoutMs, budget, isolation, context, tools, skills, once are defaults for every step (a step's own value wins); a workflow/source script sets them per runs.run call. timeoutMs is milliseconds of active time (a number); omit it unless a hard limit is needed. Explicit unknown agents are rejected BEFORE creation, with available names; unknown script agents fail only their call.",
|
|
431
|
+
"run (action optional for exactly one launch form): agent+task; tasks:[call specs] parallel; chain:[call specs] sequential ({previous}); workflow:'./script.js' or source (runs.run(key,spec), runs.all([...]), emit(value), args, runs.input(name)). Optional name, cwd, usageBudget, maxCalls, inputs, labels. With tasks/chain, top-level agent (without task), model, timeoutMs, budget, isolation, context, tools, skills, once, writer are defaults for every step (a step's own value wins); a workflow/source script sets them per runs.run call. timeoutMs is milliseconds of active time (a number); omit it unless a hard limit is needed. Explicit unknown agents are rejected BEFORE creation, with available names; unknown script agents fail only their call.",
|
|
382
432
|
"agents: list names, descriptions, default models and source for this cwd; use these names for run.",
|
|
383
|
-
"send to:'<wid>/<key>' (bare '<wid>' only for a single-call workflow): steer on a running call delivers at the next safe point (receipt in status/UI); a steer to a call waiting on its question interrupts the question and the subagent usually asks again — use answer to answer it; sealed → finished:<status> — use kind 'follow-up'. follow-up continues a sealed call as generation g+1 or queues after a running turn; follow-up model:'provider/id' or a pool name runs that generation on it. answer: give the qid (or just the call, or nothing when one question is open); to and rev are filled in. A question that needs the user's decision goes to the user; if you answer one yourself, tell the user what you chose. model ('provider/id' or a pool name — its first model not used up): a running call switches at its next provider request; an asking, hibernated or queued call launches on it when it runs again; the reply's model/effect (next-request|next-execution|next-generation) says which. status model = model actually used by the last request; switching = requested, not used yet; switchFailed = refused. A provider content refusal (ToS/usage policy) fails the call at once, not retried. Unknown targets list valid addresses. replaces:[rid] supersedes an earlier send.",
|
|
384
|
-
"stop target:<wid|<wid>/<key>> is terminal stopped (usage and partial edits kept); a sealed call → already-sealed:<status>, a finished workflow → terminal:<status>. drain holds existing workflows reversibly (new runs unaffected); resume [wid] releases held workflows. restart (after an update) replaces the orchestrator with the installed version: refused with busy:<running executions> while any runs. Never force without the user's explicit approval: show the user the refusal's list first, then supply force:'<token>' and reason. Subagents cannot force; hibernated askers and queued calls do not block it. Never kill the orchestrator process. Commands that need the machine (benchmarks, timing) take a lease: tell the subagent to run them as `pi-durable-subagents hold machine [--shared] -- <command>` (FIFO; status lists lease holders and waiters). status: without wid, what runs, asks (with its answer address; hibernated:true holds no slot) or failed, writerWait: a call queued for its git worktree's writer lock (one call whose tools include edit/write runs per worktree; spec writer:false or isolation:'worktree' opts out), sharedWorktree names calls sharing observed edit/write roots (reminder), lease: a call holding or waiting for a resource lease, finished workflows one line each, provider slots held/limit, the config in effect and providers whose usage window is used up (avoided until a probe finds them answering again), and the orchestrator version (versionNote when it differs from the loaded one); wid: one workflow, outputs clipped; wid+key: one call's full result; full:true: everything. A run's rid from {submitted:{rid}} works wherever a wid is expected. revise wid + workflow/source/args starts a revision.",
|
|
433
|
+
"send to:'<wid>/<key>' (bare '<wid>' only for a single-call workflow): steer on a running call delivers at the next safe point (receipt in status/UI); a steer to a call waiting on its question interrupts the question and the subagent usually asks again — use answer to answer it; sealed → finished:<status> — use kind 'follow-up'. notify tells a call a decision without disturbing it; the reply's delivery says how: steered (running: it gets the note at its next safe point), held-until-answer (waiting on its question: never interrupts it, delivered after the answer) or noted (not running: nothing starts; the note is recorded and the call's next follow-up opens with every pending note; status shows notesPending). to may list several calls for steer, notify, follow-up and model: one request per call, each decided on its own, one result line per target (request:<id> sends <id>:1...<id>:n; a retry with the same list is safe). follow-up continues a sealed call as generation g+1 or queues after a running turn; follow-up model:'provider/id' or a pool name runs that generation on it. answer: give the qid (or just the call, or nothing when one question is open); to and rev are filled in. A question that needs the user's decision goes to the user; if you answer one yourself, tell the user what you chose. model ('provider/id' or a pool name — its first model not used up): a running call switches at its next provider request; an asking, hibernated or queued call launches on it when it runs again; the reply's model/effect (next-request|next-execution|next-generation) says which. status model = model actually used by the last request; switching = requested, not used yet; switchFailed = refused. A provider content refusal (ToS/usage policy) fails the call at once, not retried. Unknown targets list valid addresses. replaces:[rid] supersedes an earlier send.",
|
|
434
|
+
"stop target:<wid|<wid>/<key>> is terminal stopped (usage and partial edits kept); a sealed call → already-sealed:<status>, a finished workflow → terminal:<status>. drain holds existing workflows reversibly (new runs unaffected); resume [wid] releases held workflows. restart (after an update) replaces the orchestrator with the installed version: refused with busy:<running executions> while any runs. Never force without the user's explicit approval: show the user the refusal's list first, then supply force:'<token>' and reason. Subagents cannot force; hibernated askers and queued calls do not block it. Never kill the orchestrator process. Commands that need the machine (benchmarks, timing) take a lease: tell the subagent to run them as `pi-durable-subagents hold machine [--shared] -- <command>` (FIFO; `hold <name> --slots N` admits N at a time; status lists lease holders and waiters). status: without wid, what runs (with its run labels, clipped), asks (with its answer address; hibernated:true holds no slot) or failed, writerWait: a call queued for its git worktree's writer lock (one call whose tools include edit/write runs per worktree; spec writer:false or isolation:'worktree' opts out), sharedWorktree names calls sharing observed edit/write roots (reminder), lease: a call holding or waiting for a resource lease, finished workflows one line each, provider slots held/limit, the config in effect and providers whose usage window is used up (avoided until a probe finds them answering again), and the orchestrator version (versionNote when it differs from the loaded one); wid: one workflow, outputs clipped; wid+tail:N: the last N lines of each call's result, wid+grep:'<regex>': only its matching lines (a JS regex run in-process: avoid nested quantifiers like (a+)+; first 2000 chars of a line, last 5000 lines; both: grep, then tail; at most 4000 chars per call); wid+key: one call's full result; full:true: everything. A run reply names calls already queued behind a writer lock (writerWait). A run's rid from {submitted:{rid}} works wherever a wid is expected. revise wid + workflow/source/args starts a revision.",
|
|
385
435
|
"Control replies are {applied:true,rid} or {applied:false,reason,rid} when decided; otherwise {submitted:{rid}} after 10s.",
|
|
386
436
|
...(agents ? [`Available agents: ${agents}.`] : []),
|
|
387
437
|
"User sees a summary line above the editor; ↓ on an empty editor (or /subagents) opens the list, Enter watches live OR finished calls (finished transcripts remain on disk) and expands finished workflows. List keys: s steer (paste-capable input), x stop (confirm y), m model, a answer when asked, f follow-up on finished calls; action feedback appears in footer.",
|
package/dist/cli/doctor.js
CHANGED
|
@@ -9,7 +9,8 @@ import { reduceLifecycle } from "../kernel/lifecycle.js";
|
|
|
9
9
|
import { scanInbox } from "../kernel/mailbox.js";
|
|
10
10
|
import { OsLock } from "../platform/lock.js";
|
|
11
11
|
import { journalPath, orchInbox, orchLedger, orchLock } from "../paths.js";
|
|
12
|
-
import { snapshotFromEntries } from "../orchestrator/snapshot.js";
|
|
12
|
+
import { runningStats, snapshotFromEntries } from "../orchestrator/snapshot.js";
|
|
13
|
+
import { statsLine } from "../orchestrator/stats.js";
|
|
13
14
|
import { diskUsage } from "../orchestrator/store.js";
|
|
14
15
|
import { JT, isEntry } from "../types.js";
|
|
15
16
|
import { serviceFiles } from "./service.js";
|
|
@@ -48,7 +49,7 @@ export async function doctor(home, env = process.env, now = Date.now()) {
|
|
|
48
49
|
const ledger = readJournalSnapshot(orchLedger(home));
|
|
49
50
|
const pruned = new Set(ledger.filter(e => e.type === "pruned").map(e => String(e.wid)));
|
|
50
51
|
const report = { home, bytes: await diskUsage(home), workflows: {}, ledger: { entries: ledger.length, bytes: await diskUsage(orchLedger(home)) },
|
|
51
|
-
largestJournals: [], parked: [], attention: [], fenceFailed: [], orphanStaging: [], tmpFiles: [], orchestrator: await lockHeld(home), service: "unavailable", findings: [] };
|
|
52
|
+
largestJournals: [], parked: [], attention: [], fenceFailed: [], orphanStaging: [], tmpFiles: [], orchestrator: await lockHeld(home), service: "unavailable", findings: [], ...runningStats(home) };
|
|
52
53
|
const journals = [];
|
|
53
54
|
for (const wid of (await names(join(home, "w"))).filter(n => !n.startsWith(".") && !pruned.has(n)).sort()) {
|
|
54
55
|
const entries = readJournalSnapshot(journalPath(home, wid)), snap = snapshotFromEntries(wid, entries);
|
|
@@ -140,7 +141,7 @@ export function renderDoctor(r) {
|
|
|
140
141
|
...list("unresolved fence failures", r.fenceFailed, f => `${f.wid} ${f.exec} ${age(f.ageMs)}`),
|
|
141
142
|
...list("orphan staging", r.orphanStaging, s => s),
|
|
142
143
|
...list("leftover tmp files", r.tmpFiles, s => s),
|
|
143
|
-
`orchestrator: ${r.orchestrator === "running" ? "running (holds the lock)" : r.orchestrator}`,
|
|
144
|
+
`orchestrator: ${r.orchestrator === "running" ? "running (holds the lock)" : r.orchestrator}${r.orchestratorStats ? `; ${statsLine(r.orchestratorStats)}` : ""}`,
|
|
144
145
|
`service: ${r.service}`,
|
|
145
146
|
...(r.findings.length ? [`${r.findings.length} actionable finding(s):`, ...r.findings.flatMap(f => [` ${f.kind}: ${f.detail}`, ` ${f.command}`])] : ["nothing actionable"]),
|
|
146
147
|
].join("\n");
|