pi-durable-subagents 1.0.40 → 1.0.42
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 +51 -0
- package/README.md +52 -2
- package/dist/agent/child.js +65 -22
- package/dist/agent/main.js +1 -1
- package/dist/cli/main.js +18 -5
- package/dist/compat/model.js +12 -0
- package/dist/events/pump.js +6 -2
- package/dist/events/waiting.js +3 -0
- package/dist/kernel/journal.js +189 -36
- package/dist/kernel/mailbox.js +2 -0
- package/dist/orchestrator/config.js +6 -1
- package/dist/orchestrator/engine.js +154 -18
- package/dist/orchestrator/executor/effects/gate.js +10 -3
- package/dist/orchestrator/executor/effects/index.js +2 -1
- package/dist/orchestrator/executor/hibernate.js +11 -0
- package/dist/orchestrator/executor/index.js +316 -62
- package/dist/orchestrator/executor/indexes.js +34 -0
- package/dist/orchestrator/executor/observe.js +25 -4
- package/dist/orchestrator/executor/pool.js +39 -0
- package/dist/orchestrator/executor/recovered.js +85 -0
- package/dist/orchestrator/executor/session.js +8 -0
- package/dist/orchestrator/executor/sweep.js +17 -1
- package/dist/orchestrator/ledger.js +8 -3
- package/dist/orchestrator/main.js +5 -2
- package/dist/orchestrator/settled.js +134 -0
- package/dist/orchestrator/snapshot.js +191 -15
- package/dist/orchestrator/store.js +131 -22
- package/dist/types.js +2 -0
- package/dist/ui/tool.js +5 -3
- package/dist/ui/view.js +22 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.42
|
|
4
|
+
|
|
5
|
+
- The orchestrator starts in seconds on a large home. Measured on a copy of a real home (2084 workflows, 432 MB of
|
|
6
|
+
journals): a restart reached the evaluator after 82 s in 1.0.41 and after 3.5 s now; peak memory fell from 1.5 GiB
|
|
7
|
+
to about 710 MiB. Recovery records a receipt per recovered call and skips calls whose receipt is still current;
|
|
8
|
+
lookups that scanned every journal per call are indexed; pinned files of terminal workflows are checked when a
|
|
9
|
+
request needs them rather than at every start.
|
|
10
|
+
- Settled workflows open without decoding their journals. A rebuildable record under `cache/settled/` (validated
|
|
11
|
+
against the journal's inode, size, entry count and last line; any mismatch takes the full path and rewrites it)
|
|
12
|
+
stands in until something reads or appends to the journal, which then decodes it in full. Only terminal workflows
|
|
13
|
+
with nothing left for recovery to do are eligible.
|
|
14
|
+
- The first start after upgrading does a one-time pass that writes the receipts and records (about 40 s on the home
|
|
15
|
+
above).
|
|
16
|
+
- A pinned file that changed no longer stops the orchestrator or leaves a generation hanging: the generation's call
|
|
17
|
+
is sealed `failed` with `pin-failed: <file>` without starting a child, and a follow-up runs again once the file is
|
|
18
|
+
restored. Resume, revise and follow-up of such a workflow are refused with `pin-failed`.
|
|
19
|
+
- `status` says why a queued call does not move: `orchestrator starting (<age>)` while the orchestrator recovers
|
|
20
|
+
(also on the orchestrator line), the writer lock, a full provider (`waiting for a free slot (<provider> n/n)`) or a
|
|
21
|
+
used-up usage window. Without evidence it says only `queued`; an answered asker shows `queued (answered)`.
|
|
22
|
+
- The orchestrator ledger records `recovery: true` on its start entry and a `recovered` entry with the recovery time
|
|
23
|
+
and counts.
|
|
24
|
+
|
|
25
|
+
## 1.0.41
|
|
26
|
+
|
|
27
|
+
- An answer that races the planned hibernation no longer strands its call. In 1.0.40 the parent forwarded an answer,
|
|
28
|
+
the call hibernated two seconds later, the child had already read the answer and was fenced, and the call showed
|
|
29
|
+
`asking` for 49 minutes until a second answer arrived. Hibernation is now decided on the current journal inside the
|
|
30
|
+
serial section and is refused while an answer forward to the call is pending or in flight. A call fenced while
|
|
31
|
+
stopped on that `ask` (hibernated on the question, or the answer receipt is the last thing it did) is treated as
|
|
32
|
+
answered and continues its session at once, live and after recovery; a call that kept working after the answer is
|
|
33
|
+
judged by its own evidence as before (report, `once` with a dangling tool, losses). `status` flags an answer that
|
|
34
|
+
was forwarded but not delivered within 30 seconds.
|
|
35
|
+
- A bound answer excuses losses only for the execution it was bound to and for the first launch that never started a
|
|
36
|
+
child. A child that keeps dying before its first marker now stops at `lossBound` instead of relaunching without
|
|
37
|
+
limit (a defect since before 1.0.40).
|
|
38
|
+
- A resumed pool call no longer waits a whole turn on its session's full provider. After `k.resumeSpillMs` (default
|
|
39
|
+
120000; `0` at once; `null` or negative never) it continues the same session on another entry of its pool that has a
|
|
40
|
+
free slot, preferring the same model id (compared by its last path segment, case-insensitively, without thinking
|
|
41
|
+
suffix). Explicit models and models requested by the parent never spill. `status` shows the wait, the free pool
|
|
42
|
+
providers and the spill. The wait timer restarts after recovery.
|
|
43
|
+
- A child never answers with a model dsa did not select. The child extension checks the active model at session
|
|
44
|
+
start and before every turn; a mismatch (for example pi falling back to its default model because the selected
|
|
45
|
+
provider has no credentials) stops the execution before its first request and records `model-unavailable` with
|
|
46
|
+
the reason. A pool call fails over to the next entry and skips the failed one for ten minutes; a call with an
|
|
47
|
+
explicit model fails naming both models. Virtual (routed) models must activate at launch; their answers name the
|
|
48
|
+
routed physical model, shown as `routed Y`. Any other answer from an unselected model shows `used Y, selected X`.
|
|
49
|
+
A refusal is rechecked once against fresh credentials of that provider first: pi can answer `setModel` from an
|
|
50
|
+
availability snapshot that a startup refresh briefly replaced (seen after resumes on CI), which is not a missing
|
|
51
|
+
credential.
|
|
52
|
+
- Slot waits are journaled once per wait episode; free providers are computed live for `status`.
|
|
53
|
+
|
|
3
54
|
## 1.0.40
|
|
4
55
|
|
|
5
56
|
- Readers keep rebuildable digests of settled workflows and facts of final calls in `DSA_HOME/cache`, keyed by
|
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ the npx cache, so `install-service` refuses to run from there.
|
|
|
57
57
|
| A step is refused, or a dependency fails | The workflow stops that branch cleanly. Nothing is retried in vain. |
|
|
58
58
|
| A provider's usage window runs out (`No available accounts`, usage limit, quota exceeded, a daily quota at 0) | Found at the second refusal in a row, while pi is still retrying. A call in a pool continues **in the same session** on the pool's next model (within pi's next retry or two); new calls skip that provider. After 15 minutes the next call that wants it tries it once; when it answers, new calls and new generations use it again. A call with a single model waits for it instead of failing. Billing errors (402, insufficient balance) still fail at once. |
|
|
59
59
|
| Two subagents would write in the same worktree | Only one runs there at a time. A call that can write (its tools include `edit` or `write`, which pi's default tools do) holds its git worktree's writer lock from its launch until it ends, also while it waits for an answer. Another writer for that worktree waits in order, and status shows `waiting for writer lock: <root> held by <wid>/<key>`. `writer: false` (a call that does not write there), `isolation: "worktree"` and `"writerLock": "off"` opt out. |
|
|
60
|
-
| A subagent waits for an answer for a long time | It releases its model slot and memory, then resumes exactly once when you answer. The question survives orchestrator restarts (also forced ones) and crashes, including one that hits before the subagent released its slot. |
|
|
60
|
+
| A subagent waits for an answer for a long time | It releases its model slot and memory, then resumes exactly once when you answer. A forwarded answer prevents planned hibernation. If an execution was stopped after consuming the answer, recovery continues the same session without another answer. The question survives orchestrator restarts (also forced ones) and crashes, including one that hits before the subagent released its slot. |
|
|
61
61
|
| A subagent's work ends (finished, stopped, or cut off) | Every process its tools started ends with that execution, also ones started with `nohup`, `setsid` or `&`: they carry the execution's tag (see the limit below). Anything that must outlive the subagent has to be started by you or the parent session. A command run under `hold` is no exception: a forced restart stops it and its lease is released. |
|
|
62
62
|
| A subagent runs in a worktree you made (`isolation: "none"`, the default, with `cwd`) | Durable Subagents never creates, cleans, moves or deletes that directory or its branch, also not on `prune`; `prune` deletes only its own state and the worktrees it created for `isolation: "worktree"`. |
|
|
63
63
|
|
|
@@ -228,6 +228,20 @@ script run from its bash tool): pi exports `DSA_SESSION`, and `run` names that
|
|
|
228
228
|
session (see `--session` below). Other sessions' and a terminal's runs are
|
|
229
229
|
not shown.
|
|
230
230
|
|
|
231
|
+
A queued subagent says why it does not start, as far as the orchestrator has
|
|
232
|
+
recorded it, and `queued` alone when nothing is known:
|
|
233
|
+
|
|
234
|
+
| phrase | meaning |
|
|
235
|
+
| --- | --- |
|
|
236
|
+
| `queued: orchestrator starting (12s)` | the orchestrator is still recovering workflows after a start; nothing is dispatched yet (`status` shows `orchestrator: <version> (pid N, starting 12s)`, the summary line `3 queued: orchestrator starting (12s)`) |
|
|
237
|
+
| `queued: <provider> usage window used up` | every provider it can start on is used up |
|
|
238
|
+
| `queued: waiting for the writer lock of <root>` | another call writes in the same worktree |
|
|
239
|
+
| `queued: waiting for a free slot (<provider> 4/4)` | every provider it can start on is full |
|
|
240
|
+
| `queued (answered)` / `queued (answered): <reason>` | an answered asker waiting to run again, with the reason when one is recorded (as above) |
|
|
241
|
+
| `paused · r resumes` | a drained workflow |
|
|
242
|
+
|
|
243
|
+
The CLI and the tool's status (`queued` per call) say the same.
|
|
244
|
+
|
|
231
245
|
The list is also where you act. The footer shows the keys for the selected
|
|
232
246
|
row: `Enter` watch, `s` steer, `f` follow-up, `x` stop (asks `y` first),
|
|
233
247
|
`m` model, `a` answer. A one-line input opens at the bottom (paste works),
|
|
@@ -544,6 +558,10 @@ answer is bound. A drained call
|
|
|
544
558
|
(no execution running) is never `silent`; a sealed call never waits. `provider-exhausted`, `writer-lock`, `lease` and `slot` are queues
|
|
545
559
|
that clear by themselves; `silent` and `unconfirmed-stop` may need a look.
|
|
546
560
|
|
|
561
|
+
An open question with an unconfirmed answer forward carries
|
|
562
|
+
`answerForwarded: {rid, qid, rev, at}` in JSON status. After 30 seconds, text status
|
|
563
|
+
says `asking: answer forwarded <age> ago, not delivered` instead of plain `asking`.
|
|
564
|
+
|
|
547
565
|
### Housekeeping
|
|
548
566
|
|
|
549
567
|
Journals are never compacted, so state only grows. `prune` removes finished
|
|
@@ -745,6 +763,24 @@ State lives in `~/.pi/durable-subagents`; set `DSA_HOME` to move it.
|
|
|
745
763
|
session's model or was asked for a model, and a running call that moves off
|
|
746
764
|
a used-up provider skips such entries, as does a model send that names the
|
|
747
765
|
pool.
|
|
766
|
+
- **Resumed pool calls:** keep their session's model for its prompt cache, but
|
|
767
|
+
after 2 minutes queued on its full provider try another free provider in the
|
|
768
|
+
same pool. Set `"k": { "resumeSpillMs": 120000 }` to change the wait;
|
|
769
|
+
`0` spills immediately, `null` or a negative number keeps waiting indefinitely.
|
|
770
|
+
The same model id on another provider is preferred, then pool order; the new
|
|
771
|
+
entry's thinking level and `afterMs` apply. This continues the same session
|
|
772
|
+
but gives up the old provider's prompt cache. Explicit models and models
|
|
773
|
+
requested by the parent do not spill. The timer restarts for each execution,
|
|
774
|
+
including recovery after an orchestrator restart, like `afterMs`.
|
|
775
|
+
`status` shows the queued provider, elapsed wait and free pool providers,
|
|
776
|
+
then the recorded spill and how long it waited (`poolWait` / `spill` in JSON).
|
|
777
|
+
- **Selected model unavailable:** before delivering work, the child verifies
|
|
778
|
+
that pi activated the selected model (including catalog aliases and display
|
|
779
|
+
names). Missing auth or a different model stops that execution; a pool call
|
|
780
|
+
tries another entry and skips the unavailable entry for that call for 10
|
|
781
|
+
minutes. A single-model call fails with the selected model, pi's fallback
|
|
782
|
+
and the reason. `status` retains `modelUnavailable`; an unexpected answering
|
|
783
|
+
model also shows `used Y, selected X` (`modelMismatch` in JSON).
|
|
748
784
|
- **A used-up provider** is not sent new calls until its next try, 15 minutes
|
|
749
785
|
after it last refused (`"k": { "probeMs": 900000 }`). Then one call at a
|
|
750
786
|
time goes to it, so finding out costs no extra request. A call that moved to
|
|
@@ -879,7 +915,21 @@ subagent only watching it.
|
|
|
879
915
|
The restart ledger records the reason and initiator; after the next start,
|
|
880
916
|
`status` shows who forced it and why for 24 hours.
|
|
881
917
|
|
|
882
|
-
An orchestrator reads requests only after it has recovered its workflows
|
|
918
|
+
An orchestrator reads requests only after it has recovered its workflows. Its
|
|
919
|
+
start costs the unfinished work plus a small check per finished workflow, not
|
|
920
|
+
the size of finished history: a call whose recovery completed is recorded in its
|
|
921
|
+
journal and not read again until something concerns it, and a settled workflow
|
|
922
|
+
(ended, nothing open) opens without decoding its journal, from a rebuildable
|
|
923
|
+
record in `DSA_HOME/cache/settled`; the journal is read when a request needs it.
|
|
924
|
+
Pinned files of a finished workflow are verified when a resume, revise or
|
|
925
|
+
follow-up uses them; a changed file refuses that request (`pin-failed`). A
|
|
926
|
+
follow-up generation that is already open when its files no longer verify (at a
|
|
927
|
+
restart, say) is sealed `failed` without starting a subagent, with an error
|
|
928
|
+
starting `pin-failed: ` that names the file; the workflow ends again, and once
|
|
929
|
+
the file is restored a later follow-up runs. The first start after upgrading
|
|
930
|
+
makes a one-time pass that writes these records and receipts (tens of seconds
|
|
931
|
+
on a large home). The ledger's `orchestrator` entry has `recovery: true`, and a
|
|
932
|
+
`recovered` entry with the time taken follows when recovery ends. So
|
|
883
933
|
a `restart` sent to one that just started waits for it (and says so); if no
|
|
884
934
|
orchestrator reaches the request in time, `restart` exits 75 and the request
|
|
885
935
|
stays pending — it is decided later, so do not send another.
|
package/dist/agent/child.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { watch } from 'node:fs';
|
|
1
|
+
import fs, { watch } from 'node:fs';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { Type } from '@earendil-works/pi-ai';
|
|
4
4
|
import { ASK_CUT, CT, ENV, JT } from "../types.js";
|
|
@@ -9,6 +9,7 @@ import { planDecisions } from "../kernel/lifecycle.js";
|
|
|
9
9
|
import { openness } from "../kernel/guards.js";
|
|
10
10
|
import { recover } from "./child/history.js";
|
|
11
11
|
import { validate } from "./child/schema.js";
|
|
12
|
+
import { catalogModel, parseModel, sameModel } from "../compat/model.js";
|
|
12
13
|
import { registerLive } from "./child/live.js";
|
|
13
14
|
const MESSAGES = ['task', 'steer', 'notify', 'follow-up', 'continue'];
|
|
14
15
|
/** D2: the questions a bound continue supersedes: the hibernated asker's own question when it resumes with the answer
|
|
@@ -65,25 +66,69 @@ export function registerChild(pi) {
|
|
|
65
66
|
* pi captures a turn's model when the turn begins, so a correction in the `context` hook comes too late for that
|
|
66
67
|
* turn: seen on CI as one "Unknown provider: unknown" reply (pi's placeholder model) after a resume. The registry
|
|
67
68
|
* can briefly lack an extension provider at startup, so wait for it up to 5 s. */
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
return;
|
|
72
|
-
|
|
69
|
+
let verified, modelFailed = false;
|
|
70
|
+
async function ensureModel(ctx, correct = true) {
|
|
71
|
+
if (modelFailed)
|
|
72
|
+
return false;
|
|
73
|
+
if (!target)
|
|
74
|
+
return true;
|
|
75
|
+
const selected = parseModel(target), actual = ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : { id: 'none' };
|
|
76
|
+
let model = ctx.modelRegistry.find(selected.provider, selected.id) ?? catalogModel(selected, ctx.modelRegistry.getAll());
|
|
73
77
|
for (let waited = 0; !model && waited < 5000; waited += 50) {
|
|
74
78
|
await new Promise(resolve => setTimeout(resolve, 50));
|
|
75
|
-
model = ctx.modelRegistry.find(
|
|
79
|
+
model = ctx.modelRegistry.find(selected.provider, selected.id) ?? catalogModel(selected, ctx.modelRegistry.getAll());
|
|
76
80
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
let reason;
|
|
82
|
+
if (!model)
|
|
83
|
+
reason = `model is not registered for provider ${selected.provider}`;
|
|
84
|
+
else if (!sameModel(ctx.model, model)) {
|
|
85
|
+
if (!correct)
|
|
86
|
+
reason = 'active model changed after turn selection';
|
|
87
|
+
else
|
|
88
|
+
try {
|
|
89
|
+
// pi 1.0.2 answers setModel from an availability snapshot that a startup refresh can briefly replace with
|
|
90
|
+
// one taken before an extension provider registered (seen on CI after a resume: provider found, setModel
|
|
91
|
+
// refused). Recheck that provider's credentials once, authoritatively, before calling the model unavailable.
|
|
92
|
+
if (!await pi.setModel(model)) {
|
|
93
|
+
try {
|
|
94
|
+
await ctx.modelRegistry.refresh({ providers: [model.provider], allowNetwork: false });
|
|
95
|
+
}
|
|
96
|
+
catch { /* recheck below */ }
|
|
97
|
+
if (!await pi.setModel(model))
|
|
98
|
+
reason = `no auth for provider ${model.provider} (setModel refused)`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
reason = String(error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (!reason && model && !sameModel(ctx.model, model))
|
|
106
|
+
reason = 'pi did not activate the selected model';
|
|
107
|
+
if (reason) {
|
|
108
|
+
modelFailed = true;
|
|
109
|
+
active = false;
|
|
110
|
+
watcher?.close();
|
|
111
|
+
const data = { exec, selected, actual, reason };
|
|
112
|
+
pi.appendEntry(CT.modelUnavailable, data);
|
|
113
|
+
// Native state survives a crash; RPC wakes the observer even before a first answer exists.
|
|
114
|
+
fs.writeSync(process.stdout.fd, JSON.stringify({ type: CT.modelUnavailable, ...data }) + '\n');
|
|
115
|
+
console.error(`durable-subagents: model-unavailable: selected ${target}, pi would use ${actual.provider ? `${actual.provider}/` : ''}${actual.id}: ${reason}`);
|
|
116
|
+
ctx.shutdown();
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (verified !== target) {
|
|
120
|
+
const data = { exec, selected, model: { provider: model.provider, id: model.id }, virtual: model.api === 'pi-virtual' };
|
|
121
|
+
pi.appendEntry(CT.modelReady, data);
|
|
122
|
+
fs.writeSync(process.stdout.fd, JSON.stringify({ type: CT.modelReady, ...data }) + '\n');
|
|
123
|
+
verified = target;
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
81
126
|
}
|
|
82
127
|
async function consume(ctx, mode) {
|
|
83
128
|
if (!active || (mode === 'idle' && !ctx.isIdle()))
|
|
84
129
|
return [];
|
|
85
|
-
if (mode === 'idle')
|
|
86
|
-
|
|
130
|
+
if (mode === 'idle' && !await ensureModel(ctx))
|
|
131
|
+
return []; // an idle delivery starts a turn
|
|
87
132
|
const candidates = await scanInbox(inbox), byRid = new Map(candidates.map(req => [req.rid, req]));
|
|
88
133
|
// Scan is asynchronous: recheck before using the idle delivery API.
|
|
89
134
|
if (!active || (mode === 'idle' && !ctx.isIdle()))
|
|
@@ -257,7 +302,8 @@ export function registerChild(pi) {
|
|
|
257
302
|
// The executor names the model it holds a slot for; apply it before any provider request if pi did not.
|
|
258
303
|
// Observed with pi 1.0.2 on resumed sessions: the registry briefly lacks an extension provider at startup.
|
|
259
304
|
// Nothing is delivered (so no provider request starts) until the held model is resolvable, for up to 5 s.
|
|
260
|
-
await ensureModel(ctx)
|
|
305
|
+
if (!await ensureModel(ctx))
|
|
306
|
+
return;
|
|
261
307
|
watcher = watch(inbox, () => { void serial(async () => { await consume(ctx, blocked ? 'ask' : 'idle'); }).catch(error => fail(ctx, error)); });
|
|
262
308
|
watcher.on('error', error => fail(ctx, error));
|
|
263
309
|
await consume(ctx, 'idle');
|
|
@@ -282,14 +328,11 @@ export function registerChild(pi) {
|
|
|
282
328
|
// turn_start runs before the request is prepared (pi reads the model then); `context` runs after it, too late for
|
|
283
329
|
// that request (seen on CI: model_change after the delivered message, then "Unknown provider: unknown"). Keep both.
|
|
284
330
|
const guard = async (_event, ctx) => {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
await pi.setModel(model);
|
|
291
|
-
else
|
|
292
|
-
console.error(`durable-subagents: model ${target} is not registered before a provider request`);
|
|
331
|
+
if (!await ensureModel(ctx, _event?.type !== 'context')) {
|
|
332
|
+
// Hook errors are swallowed by pi. Exit this owned child synchronously so a captured fallback model
|
|
333
|
+
// cannot make a request, even when a provider ignores abort. The receipt was appended synchronously.
|
|
334
|
+
process.exit(1);
|
|
335
|
+
}
|
|
293
336
|
};
|
|
294
337
|
pi.on('turn_start', guard);
|
|
295
338
|
pi.on('context', guard);
|
package/dist/agent/main.js
CHANGED
|
@@ -439,7 +439,7 @@ export function registerMain(pi, ui) {
|
|
|
439
439
|
"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.",
|
|
440
440
|
"agents: list names, descriptions, default models and source for this cwd; use these names for run.",
|
|
441
441
|
"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 (reply generation) or queues after a running turn (reply delivery forwarded; if that turn ends without taking it, it opens g+1); 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.",
|
|
442
|
-
"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.",
|
|
442
|
+
"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, queued: why a queued call does not start (orchestrator starting while it recovers after a start, a used-up provider, a writer lock, full providers; absent when not known), 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 (with ', starting <age>' while it recovers; 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.",
|
|
443
443
|
"Control replies are {applied:true,rid} or {applied:false,reason,rid} when decided; otherwise {submitted:{rid}} after 10s.",
|
|
444
444
|
...(agents ? [`Available agents: ${agents}.`] : []),
|
|
445
445
|
"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/main.js
CHANGED
|
@@ -7,7 +7,7 @@ import { setTimeout as delay } from "node:timers/promises";
|
|
|
7
7
|
import { dsaHome } from "../paths.js";
|
|
8
8
|
import { readJournalSnapshot } from "../kernel/journal.js";
|
|
9
9
|
import { journalPath, orchLedger } from "../paths.js";
|
|
10
|
-
import { allWorkflows, eventsFromEntries, heldWorkflows, isLive, formatUsage, renderEvent, statusDetail, statusView, workflowSnapshot, compactWorkflow, labelsText, outputSelect, statusCompactDetail } from "../orchestrator/snapshot.js";
|
|
10
|
+
import { answerForwardedNote, modelStatusText, queuedText, allWorkflows, eventsFromEntries, heldWorkflows, isLive, formatUsage, renderEvent, statusDetail, statusView, workflowSnapshot, compactWorkflow, labelsText, outputSelect, statusCompactDetail } from "../orchestrator/snapshot.js";
|
|
11
11
|
import { statsLine } from "../orchestrator/stats.js";
|
|
12
12
|
import { resolution, start, startOrchestrator, submit } from "./control.js";
|
|
13
13
|
import { doctor, renderDoctor, size } from "./doctor.js";
|
|
@@ -101,15 +101,28 @@ export function parseArgs(args) {
|
|
|
101
101
|
const clip = (text, n) => text.length > n ? `${text.slice(0, n)}…` : text;
|
|
102
102
|
/** Notes recorded for a call that is not running (send kind "notify"); its next follow-up carries them. */
|
|
103
103
|
const notesLine = (n) => n ? ` · ${n} note${n > 1 ? "s" : ""} pending` : "";
|
|
104
|
-
/**
|
|
105
|
-
|
|
104
|
+
/** Why a queued call does not start, when the orchestrator ledger says so (an answered asker: "(answered)" first); nothing
|
|
105
|
+
* while a drain holds its workflow (it waits for resume, as the UI says). A writer-lock wait has its own suffix. */
|
|
106
|
+
const answeredNote = (c, paused) => {
|
|
107
|
+
const forwarded = answerForwardedNote(c);
|
|
108
|
+
if (forwarded)
|
|
109
|
+
return `: ${forwarded}`;
|
|
110
|
+
if (c.phase !== "queued" || paused)
|
|
111
|
+
return "";
|
|
112
|
+
const why = c.queued ?? (c.queuedFor ? queuedText(c.queuedFor) : undefined);
|
|
113
|
+
if (c.writerWait && why === `waiting for the writer lock of ${c.writerWait.root}`)
|
|
114
|
+
return c.answered ? " (answered)" : ""; // its own suffix says it
|
|
115
|
+
if (c.answered)
|
|
116
|
+
return why ? ` (answered): ${why}` : " (answered)"; // no slot claim without a full provider
|
|
117
|
+
return why ? `: ${why}` : "";
|
|
118
|
+
};
|
|
106
119
|
/** P25, T10: Render journal-derived status (one line per call, last output line only) without live orchestrator memory. */
|
|
107
120
|
export function renderStatus(wf) {
|
|
108
121
|
const sealed = wf.counts.sealed, total = wf.calls.length, used = wf.usage && (wf.usage.input || wf.usage.output || wf.usage.costUsd);
|
|
109
122
|
return [`${wf.wid}@${wf.rev}${wf.labels ? ` ${labelsText(wf.labels)}` : ""}${wf.name ? ` ${wf.name}` : ""}: ${wf.followUps ? `follow-up running (run ${wf.status})` : wf.status}${wf.error ? ` (${clip(wf.error, 300)})` : ""} · ${sealed}/${total} sealed${used ? ` · ${formatUsage(wf.usage)}` : ""}`,
|
|
110
123
|
...wf.calls.map(c => {
|
|
111
124
|
const last = c.result?.output?.split("\n").map(l => l.trim()).filter(Boolean).at(-1), err = c.result?.error;
|
|
112
|
-
return ` ${c.key}@${c.gen} ${c.result?.status ?? c.phase}${answeredNote(c, wf.paused)}${c.model ? ` ${c.model}` : ""}${c.tools ? ` tools:${c.tools}` : ""}${c.usage && (c.usage.input || c.usage.output) ? ` ${formatUsage(c.usage)}` : ""}${last ? ` ${JSON.stringify(clip(last, 160))}` : err ? ` (${clip(err, 160)})` : ""}${c.sharedWorktree ? ` (shares worktree with ${c.sharedWorktree.join(", ")})` : ""}${c.writerWait && !c.result && c.phase !== "sealed" ? ` (waiting for writer lock: ${c.writerWait.root} held by ${c.writerWait.holder})` : ""}${notesLine(c.notesPending)}`;
|
|
125
|
+
return ` ${c.key}@${c.gen} ${c.result?.status ?? c.phase}${answeredNote(c, wf.paused)}${c.model ? ` ${c.model}` : ""}${c.tools ? ` tools:${c.tools}` : ""}${c.usage && (c.usage.input || c.usage.output) ? ` ${formatUsage(c.usage)}` : ""}${last ? ` ${JSON.stringify(clip(last, 160))}` : err ? ` (${clip(err, 160)})` : ""}${c.sharedWorktree ? ` (shares worktree with ${c.sharedWorktree.join(", ")})` : ""}${c.writerWait && !c.result && c.phase !== "sealed" ? ` (waiting for writer lock: ${c.writerWait.root} held by ${c.writerWait.holder})` : ""}${notesLine(c.notesPending)}${modelStatusText(c)}`;
|
|
113
126
|
}),
|
|
114
127
|
...wf.attention.map(a => ` ${a.kind}: ${JSON.stringify(clip(a.text, 300))}`),
|
|
115
128
|
...(wf.scriptLog ? [` script log: ${wf.scriptLog}`] : [])].join("\n");
|
|
@@ -122,7 +135,7 @@ export function renderSelected(wf) {
|
|
|
122
135
|
/** P25, T10: Render the compact status projection shared with the `subagents` tool. */
|
|
123
136
|
export function renderView(view) {
|
|
124
137
|
const lines = view.workflows.map(w => [`${w.wid}@${w.rev}${w.labels ? ` ${labelsText(w.labels)}` : ""}${w.name ? ` ${w.name}` : ""}: ${w.followUps ? `follow-up running (run ${w.status})` : w.status}${w.error ? ` (${clip(w.error, 200)})` : ""} · ${w.done}/${w.planned ?? w.calls.length}${w.planned === undefined && w.status === "running" ? "+" : ""} done${w.usage.input || w.usage.output || w.usage.costUsd ? ` · ${formatUsage(w.usage)}` : ""}`,
|
|
125
|
-
...w.calls.map(c => ` ${c.key}@${c.gen} ${c.status ?? c.phase}${answeredNote(c, w.paused)}${c.hibernated ? " (hibernated, no slot)" : ""}${c.model ? ` ${c.model}` : ""}${c.switching ? `
|
|
138
|
+
...w.calls.map(c => ` ${c.key}@${c.gen} ${c.status ?? c.phase}${answeredNote(c, w.paused)}${c.hibernated ? " (hibernated, no slot)" : ""}${c.model ? ` ${c.model}` : ""}${c.switching ? ` \u2192 ${c.switching} (requested)` : ""}${c.switchFailed ? ` (switch refused: ${c.switchFailed})` : ""}${c.tools ? ` tools:${c.tools}` : ""}${c.usage ? ` ${formatUsage(c.usage)}` : ""}${c.lastLine ? ` ${JSON.stringify(c.lastLine)}` : c.error ? ` (${c.error})` : ""}${c.sharedWorktree ? ` (shares worktree with ${c.sharedWorktree.join(", ")})` : ""}${c.writerWait && c.phase !== "sealed" ? ` (waiting for writer lock: ${c.writerWait.root} held by ${c.writerWait.holder})` : ""}${c.lease && c.phase !== "sealed" ? ` (${c.lease})` : ""}${notesLine(c.notesPending)}${modelStatusText(c)}`),
|
|
126
139
|
...w.attention.map(a => ` ${a.kind}: ${JSON.stringify(a.text.split("\n")[0])}`)].join("\n"));
|
|
127
140
|
if (view.paused)
|
|
128
141
|
lines.unshift(`${view.paused} (pi-durable-subagents resume)`);
|
package/dist/compat/model.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
export const thinkingLevels = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
2
2
|
/** The model without scheduling fields, as recorded and launched. */
|
|
3
3
|
export const plainModel = (m) => ({ ...(m.provider !== undefined ? { provider: m.provider } : {}), id: m.id, ...(m.thinking ? { thinking: m.thinking } : {}) });
|
|
4
|
+
export const sameModel = (a, b) => !!a && !!b && a.provider?.toLowerCase() === b.provider?.toLowerCase() && a.id.toLowerCase() === b.id.toLowerCase();
|
|
5
|
+
/** Resolve CLI spelling within the selected provider, using pi's alias-before-dated ordering. */
|
|
6
|
+
export function catalogModel(selected, catalog) {
|
|
7
|
+
const models = catalog.filter(m => m.provider.toLowerCase() === selected.provider?.toLowerCase());
|
|
8
|
+
const exact = models.find(m => sameModel(m, selected));
|
|
9
|
+
if (exact)
|
|
10
|
+
return exact;
|
|
11
|
+
const name = selected.id.toLowerCase();
|
|
12
|
+
const matches = models.filter(m => m.id.toLowerCase().includes(name) || m.name?.toLowerCase().includes(name));
|
|
13
|
+
const aliases = matches.filter(m => !/-\d{8}$/.test(m.id));
|
|
14
|
+
return (aliases.length ? aliases : matches).sort((a, b) => b.id.localeCompare(a.id))[0];
|
|
15
|
+
}
|
|
4
16
|
/** P35: Parse Pi model identifiers, preserving colons that are not thinking suffixes. */
|
|
5
17
|
export function parseModel(value) {
|
|
6
18
|
let id = value.trim();
|
package/dist/events/pump.js
CHANGED
|
@@ -290,7 +290,11 @@ export class EventPump {
|
|
|
290
290
|
const wf = this.options.store.workflows.get(wid);
|
|
291
291
|
if (!wf)
|
|
292
292
|
continue;
|
|
293
|
-
const
|
|
293
|
+
const start = this.marks.get(wid) ?? 0;
|
|
294
|
+
// A journal not decoded (a settled workflow) is decoded only when it has entries not derived yet.
|
|
295
|
+
if (wf.journal.loaded === false && (wf.journal.count?.() ?? Infinity) <= start)
|
|
296
|
+
continue;
|
|
297
|
+
const entries = committed(wf.journal);
|
|
294
298
|
if (entries.length <= start)
|
|
295
299
|
continue;
|
|
296
300
|
const id = this.identity(wid);
|
|
@@ -332,7 +336,7 @@ export class EventPump {
|
|
|
332
336
|
let v = verdicts.get(wid);
|
|
333
337
|
if (v === undefined) {
|
|
334
338
|
const wf = this.options.store.workflows.get(wid);
|
|
335
|
-
v = wf ? quiet(wid, committed(wf.journal)) : pruned.has(wid);
|
|
339
|
+
v = wf ? (wf.journal.loaded === false && wf.settled ? wf.settled.quiet : quiet(wid, committed(wf.journal))) : pruned.has(wid);
|
|
336
340
|
verdicts.set(wid, v);
|
|
337
341
|
}
|
|
338
342
|
return v;
|
package/dist/events/waiting.js
CHANGED
|
@@ -419,6 +419,9 @@ export function waitCollector(src) {
|
|
|
419
419
|
const current = new Map(), meta = new Map(), present = new Set();
|
|
420
420
|
for (const wf of src.workflows()) {
|
|
421
421
|
present.add(wf.wid);
|
|
422
|
+
// A journal not decoded is a settled workflow's (orchestrator/settled.ts): it has no live call, so no wait.
|
|
423
|
+
if (wf.journal.loaded === false)
|
|
424
|
+
continue;
|
|
422
425
|
const entries = wf.journal.entries();
|
|
423
426
|
let hit = folds.get(wf.wid);
|
|
424
427
|
if (hit?.entries !== entries) {
|