pi-durable-subagents 1.0.28 → 1.0.31
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 +31 -0
- package/README.md +17 -2
- package/dist/agent/main.js +6 -1
- package/dist/cli/control.js +3 -1
- package/dist/cli/main.js +1 -1
- package/dist/cli/requests.js +18 -4
- package/dist/orchestrator/engine.js +4 -1
- package/dist/orchestrator/main.js +2 -0
- package/dist/orchestrator/snapshot.js +30 -13
- package/dist/requests.js +5 -2
- package/dist/ui/view.js +5 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.31
|
|
4
|
+
|
|
5
|
+
- A run can be shown in the pi session it was started for, not only the one
|
|
6
|
+
that sent it. pi exports `DSA_SESSION=<session id>` to the processes it
|
|
7
|
+
starts, and `run` takes `--session <id>` (default: an inherited
|
|
8
|
+
`$DSA_SESSION`, ignored inside a subagent). A tool or script started from a
|
|
9
|
+
pi session therefore has its runs listed in that session's dock and
|
|
10
|
+
`/subagents`, sorted first in `status`. Display and ownership only:
|
|
11
|
+
completion notices and attention still go to the sender, quitting pi does not
|
|
12
|
+
pause these runs, and `session` is not part of a request's digest. An invalid
|
|
13
|
+
`--session` exits 1; the engine rejects an invalid id with `invalid-session`.
|
|
14
|
+
|
|
15
|
+
## 1.0.30
|
|
16
|
+
|
|
17
|
+
- The pi UI shows only the subagents this pi session started again: the
|
|
18
|
+
dock's `elsewhere: ...` count and the `Other sessions` group from 1.0.29 are
|
|
19
|
+
removed, and the `ui.otherSessions` setting is ignored. Other sessions' and
|
|
20
|
+
the CLI's work remains visible through `status` and the CLI.
|
|
21
|
+
|
|
22
|
+
## 1.0.29
|
|
23
|
+
|
|
24
|
+
- The pi UI shows subagents that other sessions or the CLI started, kept apart
|
|
25
|
+
from this session's: the dock's summary line adds
|
|
26
|
+
`elsewhere: 4 running (cli 2, 1 session 2)` (dropped first when the line is
|
|
27
|
+
narrow; shown alone when this session runs nothing), and `/subagents` ends
|
|
28
|
+
with a folded `Other sessions` group listing their running workflows with
|
|
29
|
+
name, origin and labels. They can be watched but not changed from here: the
|
|
30
|
+
list's change keys and the watch view's input, model and stop controls
|
|
31
|
+
refuse them, decided by the workflow's origin. `ui.otherSessions: false`
|
|
32
|
+
turns this off.
|
|
33
|
+
|
|
3
34
|
## 1.0.28
|
|
4
35
|
|
|
5
36
|
- Lower orchestrator cost. A finished workflow's journal is closed about a
|
package/README.md
CHANGED
|
@@ -209,7 +209,11 @@ Press `↓` on an empty editor, or type `/subagents`, to open the list, a floati
|
|
|
209
209
|
session's workflows (sessions are independent), newest first, every
|
|
210
210
|
subagent with its model, what it is doing and for how long, and its latest
|
|
211
211
|
line. Finished ones stay there,
|
|
212
|
-
dimmed, with their conclusion.
|
|
212
|
+
dimmed, with their conclusion. A session's workflows include runs started
|
|
213
|
+
through the CLI by a process this session launched (a background driver, a
|
|
214
|
+
script run from its bash tool): pi exports `DSA_SESSION`, and `run` names that
|
|
215
|
+
session (see `--session` below). Other sessions' and a terminal's runs are
|
|
216
|
+
not shown.
|
|
213
217
|
|
|
214
218
|
The list is also where you act. The footer shows the keys for the selected
|
|
215
219
|
row: `Enter` watch, `s` steer, `f` follow-up, `x` stop (asks `y` first),
|
|
@@ -299,7 +303,7 @@ pi-durable-subagents start start the orchestrator if work is pendin
|
|
|
299
303
|
pi-durable-subagents resume [wid] continue unfinished or parked work (undoes drain / stop-all)
|
|
300
304
|
pi-durable-subagents drain hold existing workflows: running calls finish, nothing new starts in them
|
|
301
305
|
pi-durable-subagents stop <wid|call>
|
|
302
|
-
pi-durable-subagents run --request <id> --spec <file|-> [--labels <json>] [--cwd <dir>] [--json] [--wait-ms <n>]
|
|
306
|
+
pi-durable-subagents run --request <id> --spec <file|-> [--labels <json>] [--session <id>] [--cwd <dir>] [--json] [--wait-ms <n>]
|
|
303
307
|
start a run under a caller-chosen id; safe to retry (see below)
|
|
304
308
|
pi-durable-subagents send --request <id> --to <run-id|wid/key> [--to ...] --kind follow-up|answer|steer|notify|model
|
|
305
309
|
[--call <key>] [--qid <qid> --rev <n>] --message <text|@file> [--model <m>] [--json]
|
|
@@ -482,6 +486,17 @@ request that carries invalid ones (`invalid-labels: …`). `describe` returns
|
|
|
482
486
|
them as `labels` (also after `prune`), and every event of the run carries
|
|
483
487
|
them.
|
|
484
488
|
|
|
489
|
+
`--session <pi session id>` shows the run in that pi session's dock and
|
|
490
|
+
`/subagents` list as one of its own; without it, `run` takes `$DSA_SESSION`,
|
|
491
|
+
which a pi session exports to every process it starts (a subagent's
|
|
492
|
+
processes never pass it on). It decides where the run is listed (the dock,
|
|
493
|
+
`/subagents` and that session's `status`), and you act on it there like on
|
|
494
|
+
any row; the run still belongs to its sender: that session's main agent gets
|
|
495
|
+
no completion notices for it, quitting that pi does not pause it, and the
|
|
496
|
+
session is not part of the content, so a retry from another session gets the
|
|
497
|
+
first outcome. An invalid `--session` exits 1; an invalid inherited value
|
|
498
|
+
is ignored.
|
|
499
|
+
|
|
485
500
|
When an unsealed call does not move, its `waiting` in `describe` adds
|
|
486
501
|
`reason`, `detail` (the status line for that cause, e.g. `waiting for a slot:
|
|
487
502
|
probe 1/1`) and `since` (ms: when that cause started). The event log has the
|
package/dist/agent/main.js
CHANGED
|
@@ -91,7 +91,8 @@ export function registerMain(pi, ui) {
|
|
|
91
91
|
return;
|
|
92
92
|
await lock.release();
|
|
93
93
|
const entry = process.env.DSA_ORCHESTRATOR_ENTRY ?? fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "../orchestrator/main.ts" : "../orchestrator/main.js", import.meta.url));
|
|
94
|
-
const
|
|
94
|
+
const { DSA_SESSION: _session, ...env } = process.env;
|
|
95
|
+
const child = spawn(process.execPath, [entry], { detached: true, stdio: "ignore", env: { ...env, DSA_HOME: home } });
|
|
95
96
|
await new Promise((resolve, reject) => { child.once("spawn", resolve); child.once("error", reject); });
|
|
96
97
|
child.unref();
|
|
97
98
|
}
|
|
@@ -156,6 +157,10 @@ export function registerMain(pi, ui) {
|
|
|
156
157
|
ctx = context;
|
|
157
158
|
sender = `main:${context.sessionManager.getSessionId()}`;
|
|
158
159
|
stopped = false;
|
|
160
|
+
// Processes this session starts (bash, a detached CLI driver) inherit it: their CLI runs name this session, which
|
|
161
|
+
// then shows them as its own. A subagent's pi is not a user's session and exports nothing.
|
|
162
|
+
if (!process.env.DSA_EXEC)
|
|
163
|
+
process.env.DSA_SESSION = context.sessionManager.getSessionId();
|
|
159
164
|
outbox = await Outbox.open(outboxRoot(home), sender, () => orchInbox(home));
|
|
160
165
|
noteSink = sink;
|
|
161
166
|
await reconcile();
|
package/dist/cli/control.js
CHANGED
|
@@ -21,7 +21,9 @@ export async function startOrchestrator(home, env) {
|
|
|
21
21
|
return;
|
|
22
22
|
await lock.release();
|
|
23
23
|
const entry = env.DSA_ORCHESTRATOR_ENTRY ?? fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "../orchestrator/main.ts" : "../orchestrator/main.js", import.meta.url));
|
|
24
|
-
|
|
24
|
+
// The orchestrator serves every session: it never carries the starting pi session's $DSA_SESSION to its children.
|
|
25
|
+
const { DSA_SESSION: _session, ...rest } = env;
|
|
26
|
+
const child = spawn(process.execPath, [entry], { detached: true, stdio: "ignore", env: { ...rest, DSA_HOME: home } });
|
|
25
27
|
await new Promise((resolve, reject) => { child.once("spawn", resolve); child.once("error", reject); });
|
|
26
28
|
child.unref();
|
|
27
29
|
}
|
package/dist/cli/main.js
CHANGED
|
@@ -164,7 +164,7 @@ export function serviceEntryError(entry) {
|
|
|
164
164
|
return `install-service refuses to run from an npx cache (${entry}); the cache can be pruned and the service would break. Install the CLI with \`npm i -g pi-durable-subagents\` and run \`pi-durable-subagents install-service\` again.`;
|
|
165
165
|
return undefined;
|
|
166
166
|
}
|
|
167
|
-
export const HELP = "pi-durable-subagents: smoke | status [wid] [--json] | status <wid> [--tail <n>] [--grep <regex>] [--json] | events <wid> [--json] | events --all [--since <cursor>] [--limit <n>] [--json] [--wait-ms <n>] | tail [wid] [--json] | start | resume [wid] | drain | stop <wid|callId> | stop-all | run --request <id> --spec <file|-> [--labels <json>] [--cwd <dir>] [--json] [--wait-ms <n>] | send --request <id> --to <run-id|wid/key> [--to ...] [--call <key>] --kind follow-up|answer|steer|notify|model [--qid <qid> --rev <n>] [--message <text|@file>] [--model <m>] [--json] [--wait-ms <n>] | stop --request <id> <run-id|wid|wid/key> [--json] [--wait-ms <n>] | describe --key <id> | describe <wid> [--json] | prune [wid] [--older-than <days>] | restart [--force <token> --reason <text>] | hold <resource> [--shared | --slots <n>] [--max-wait <s> | --no-wait] [--note <text>] -- <command…> | leases [--json] | doctor [--json] | install-service [--dry-run] | uninstall-service [--dry-run] | chaos [--scenario <1-9>] [--keep] [--json] | drill failover [--keep] [--json]";
|
|
167
|
+
export const HELP = "pi-durable-subagents: smoke | status [wid] [--json] | status <wid> [--tail <n>] [--grep <regex>] [--json] | events <wid> [--json] | events --all [--since <cursor>] [--limit <n>] [--json] [--wait-ms <n>] | tail [wid] [--json] | start | resume [wid] | drain | stop <wid|callId> | stop-all | run --request <id> --spec <file|-> [--labels <json>] [--session <id>] [--cwd <dir>] [--json] [--wait-ms <n>] | send --request <id> --to <run-id|wid/key> [--to ...] [--call <key>] --kind follow-up|answer|steer|notify|model [--qid <qid> --rev <n>] [--message <text|@file>] [--model <m>] [--json] [--wait-ms <n>] | stop --request <id> <run-id|wid|wid/key> [--json] [--wait-ms <n>] | describe --key <id> | describe <wid> [--json] | prune [wid] [--older-than <days>] | restart [--force <token> --reason <text>] | hold <resource> [--shared | --slots <n>] [--max-wait <s> | --no-wait] [--note <text>] -- <command…> | leases [--json] | doctor [--json] | install-service [--dry-run] | uninstall-service [--dry-run] | chaos [--scenario <1-9>] [--keep] [--json] | drill failover [--keep] [--json]";
|
|
168
168
|
/** Restart: the orchestrator exits when no execution runs (or `force`) and the installed version takes over. */
|
|
169
169
|
async function restartCommand(home, env, write, options) {
|
|
170
170
|
const body = { ...(typeof options.force === "string" ? { token: options.force } : options.force === true ? { force: true } : {}), ...(options.reason !== undefined ? { reason: options.reason } : {}), initiator: cliInitiator(env) };
|
package/dist/cli/requests.js
CHANGED
|
@@ -7,7 +7,7 @@ import { setTimeout as delay } from "node:timers/promises";
|
|
|
7
7
|
import { readJournalSnapshot } from "../kernel/journal.js";
|
|
8
8
|
import { reduceLifecycle } from "../kernel/lifecycle.js";
|
|
9
9
|
import { journalPath, orchLedger, pinnedDir } from "../paths.js";
|
|
10
|
-
import { batchConflict, batchDigest, findRequest, manyIds, namesMany, REQUEST_ID, requestId, requestRid, RequestsBusy, specDigest } from "../requests.js";
|
|
10
|
+
import { batchConflict, batchDigest, findRequest, manyIds, namesMany, REQUEST_ID, requestId, requestRid, RequestsBusy, SESSION_ID, specDigest } from "../requests.js";
|
|
11
11
|
import { NOTIFY_SINCE, isLive, orchestratorTooOld, slotsView, workflowSnapshot, writerWaits, writerWaitLine, WRITER_WAIT_HINT } from "../orchestrator/snapshot.js";
|
|
12
12
|
import { leaseCalls, leaseState } from "../platform/lease.js";
|
|
13
13
|
import { BATCH, checkAgents, outcomeLine, request, sendReceipt } from "../agent/main/tool.js";
|
|
@@ -265,16 +265,27 @@ async function refusable(args, ctx, run) {
|
|
|
265
265
|
}
|
|
266
266
|
const forks = (spec) => [spec, ...["tasks", "chain"].flatMap(k => Array.isArray(spec[k]) ? spec[k] : [])]
|
|
267
267
|
.some(s => s && typeof s === "object" && s.context === "fork");
|
|
268
|
-
/**
|
|
268
|
+
/** The pi session a CLI run is shown in: --session, else $DSA_SESSION (exported by a pi session to what it starts)
|
|
269
|
+
* unless this process runs inside a subagent call. An unusable inherited value is ignored; a bad flag is an error. */
|
|
270
|
+
export function runSession(flag, env) {
|
|
271
|
+
if (flag !== undefined) {
|
|
272
|
+
if (!SESSION_ID.test(flag))
|
|
273
|
+
throw new Error("--session must be a pi session id ([A-Za-z0-9._:-], at most 128 characters)");
|
|
274
|
+
return flag;
|
|
275
|
+
}
|
|
276
|
+
const inherited = env.DSA_CALL || env.DSA_EXEC ? undefined : env.DSA_SESSION;
|
|
277
|
+
return inherited && SESSION_ID.test(inherited) ? inherited : undefined;
|
|
278
|
+
}
|
|
279
|
+
/** `run --request <id> --spec <file|-> [--session <id>] [--cwd <dir>] [--json] [--wait-ms <n>]`. The spec is the `subagents` run
|
|
269
280
|
* form ({agent,task,…} or {tasks|chain:[…],…}); it is validated by the tool's own normalizer and agent check. */
|
|
270
281
|
export const runCommand = (args, ctx) => refusable(args, ctx, runRequest);
|
|
271
282
|
async function runRequest(args, ctx, seen) {
|
|
272
|
-
const { values, positionals } = flags(args, { request: "value", spec: "value", cwd: "value", labels: "value", json: "flag", "wait-ms": "value" });
|
|
283
|
+
const { values, positionals } = flags(args, { request: "value", spec: "value", cwd: "value", labels: "value", session: "value", json: "flag", "wait-ms": "value" });
|
|
273
284
|
const id = text(values, "request"), file = text(values, "spec"), json = values.json === true, wait = waitMs(values, ctx);
|
|
274
285
|
seen.id = id;
|
|
275
286
|
seen.json = json;
|
|
276
287
|
if (!id || !file || positionals.length)
|
|
277
|
-
throw new Error("usage: run --request <id> --spec <file|-> [--labels <json>] [--cwd <dir>] [--json] [--wait-ms <n>]");
|
|
288
|
+
throw new Error("usage: run --request <id> --spec <file|-> [--labels <json>] [--session <pi session id>] [--cwd <dir>] [--json] [--wait-ms <n>]");
|
|
278
289
|
requestRid(id);
|
|
279
290
|
const raw = text(values, "labels"), labels = raw !== undefined ? parseLabels(raw) : undefined;
|
|
280
291
|
const bytes = file === "-" ? await (ctx.stdin ?? stdin)() : readFileSync(resolve(ctx.cwd ?? process.cwd(), file), "utf8");
|
|
@@ -299,6 +310,9 @@ async function runRequest(args, ctx, seen) {
|
|
|
299
310
|
const base = resolve(ctx.cwd ?? process.cwd(), text(values, "cwd") ?? "."), dir = typeof spec.cwd === "string" && spec.cwd ? resolve(base, spec.cwd) : base;
|
|
300
311
|
const normalized = request({ ...spec, action: "run", ...(typeof spec.cwd === "string" && spec.cwd ? { cwd: dir } : {}), ...(labels ? { labels } : {}) }, dir);
|
|
301
312
|
const body = normalized.body;
|
|
313
|
+
const session = runSession(text(values, "session"), ctx.env);
|
|
314
|
+
if (session)
|
|
315
|
+
body.session = session;
|
|
302
316
|
seen.digest = specDigest({ kind: "run", body });
|
|
303
317
|
// An id already recorded is decided by that record: the same content gets its first outcome (the agents it named may
|
|
304
318
|
// have changed since), other content is a request-conflict. Only a new id is checked here.
|
|
@@ -20,7 +20,7 @@ import { contentHash } from "../kernel/ids.js";
|
|
|
20
20
|
import { planDecisions, reduceLifecycle } from "../kernel/lifecycle.js";
|
|
21
21
|
import { scanInbox } from "../kernel/mailbox.js";
|
|
22
22
|
import { orchInbox, pinnedDir } from "../paths.js";
|
|
23
|
-
import { requestId, specDigest } from "../requests.js";
|
|
23
|
+
import { SESSION_ID, requestId, specDigest } from "../requests.js";
|
|
24
24
|
import { JT, attentionEntries, isEntry } from "../types.js";
|
|
25
25
|
import { isForceRestart, restartRefusal } from "./restart.js";
|
|
26
26
|
import { EvaluatorClient } from "./evaluator-client.js";
|
|
@@ -409,6 +409,9 @@ export class Engine {
|
|
|
409
409
|
const labels = req.body?.labels, invalid = !created && labels !== undefined ? labelsProblem(labels) : undefined;
|
|
410
410
|
if (invalid)
|
|
411
411
|
return { action: 'reject', reason: `invalid-labels: ${invalid}` };
|
|
412
|
+
const session = req.body?.session;
|
|
413
|
+
if (!created && session !== undefined && (typeof session !== 'string' || !SESSION_ID.test(session)))
|
|
414
|
+
return { action: 'reject', reason: 'invalid-session: a pi session id' };
|
|
412
415
|
if (created && this.store.pruned().has(String(created.wid)))
|
|
413
416
|
return { action: 'apply' }; // Never resurrect a pruned run.
|
|
414
417
|
let wf = created ? this.store.workflows.get(created.wid) : undefined;
|
|
@@ -22,6 +22,8 @@ import { packageVersion } from "../version.js";
|
|
|
22
22
|
/** P2, C4, K6: Acquire the single authority before opening ledgers, recover, and idle-exit. Resolves `restart` when an
|
|
23
23
|
* applied restart request ended it (the caller starts the successor once the lock is released). */
|
|
24
24
|
export async function main(options = {}) {
|
|
25
|
+
// Serves every session: whichever pi session started it, its children and their CLI runs must not name that session.
|
|
26
|
+
delete process.env.DSA_SESSION;
|
|
25
27
|
const home = options.home ?? dsaHome();
|
|
26
28
|
await mkdir(home, { recursive: true });
|
|
27
29
|
const lock = await new OsLock().tryAcquire(orchLock(home));
|
|
@@ -377,7 +377,7 @@ const ledgerIndexes = new WeakMap();
|
|
|
377
377
|
export function ledgerIndex(ledger) {
|
|
378
378
|
let ix = ledgerIndexes.get(ledger);
|
|
379
379
|
if (!ix || ix.length > ledger.length || (ix.length && ledger[ix.length - 1] !== ix.last)) {
|
|
380
|
-
ix = { length: 0, created: new Map(), pruned: new Set(), labels: new Map(), runLabels: new Map(), byWid: new Map(), byOrigin: new Map() };
|
|
380
|
+
ix = { length: 0, created: new Map(), pruned: new Set(), labels: new Map(), runLabels: new Map(), sessions: new Map(), runSessions: new Map(), byWid: new Map(), byOrigin: new Map() };
|
|
381
381
|
ledgerIndexes.set(ledger, ix);
|
|
382
382
|
}
|
|
383
383
|
for (let i = ix.length; i < ledger.length; i++) {
|
|
@@ -391,17 +391,29 @@ export function ledgerIndex(ledger) {
|
|
|
391
391
|
ix.labels.set(String(e.wid), labels);
|
|
392
392
|
ix.runLabels.delete(String(e.rid));
|
|
393
393
|
}
|
|
394
|
+
const session = ix.runSessions.get(String(e.rid));
|
|
395
|
+
if (session) {
|
|
396
|
+
if (!ix.sessions.has(String(e.wid)))
|
|
397
|
+
ix.sessions.set(String(e.wid), session);
|
|
398
|
+
ix.runSessions.delete(String(e.rid));
|
|
399
|
+
}
|
|
394
400
|
}
|
|
395
401
|
else if (e.type === "request") {
|
|
396
402
|
const r = e.request, labels = r?.kind === "run" ? labelsOf(r.body) : undefined;
|
|
397
403
|
if (labels && typeof r?.rid === "string")
|
|
398
404
|
ix.runLabels.set(r.rid, labels);
|
|
405
|
+
const session = r?.kind === "run" ? r.body?.session : undefined;
|
|
406
|
+
if (typeof session === "string" && session && typeof r?.rid === "string")
|
|
407
|
+
ix.runSessions.set(r.rid, session);
|
|
399
408
|
}
|
|
400
|
-
else if (e.type === JT.rejected)
|
|
409
|
+
else if (e.type === JT.rejected) {
|
|
401
410
|
ix.runLabels.delete(String(e.rid));
|
|
411
|
+
ix.runSessions.delete(String(e.rid));
|
|
412
|
+
}
|
|
402
413
|
else if (e.type === "pruned") {
|
|
403
414
|
ix.pruned.add(String(e.wid));
|
|
404
415
|
ix.labels.delete(String(e.wid));
|
|
416
|
+
ix.sessions.delete(String(e.wid));
|
|
405
417
|
}
|
|
406
418
|
else if (e.type === "drain" || e.type === "undrain") {
|
|
407
419
|
if (e.type === "drain")
|
|
@@ -448,11 +460,16 @@ export function heldWorkflows(home) {
|
|
|
448
460
|
const origin = (wid) => ix.created.get(wid)?.origin;
|
|
449
461
|
const hold = (wid) => holdOf(ledger, wid, origin(wid));
|
|
450
462
|
const since = ix.lastDrain !== undefined ? ledger[ix.lastDrain].ts : undefined;
|
|
451
|
-
return { ...(since !== undefined ? { since } : {}), held: wid => hold(wid) !== undefined, labels: wid => ix.labels.get(wid) };
|
|
463
|
+
return { ...(since !== undefined ? { since } : {}), held: wid => hold(wid) !== undefined, labels: wid => ix.labels.get(wid), session: wid => ix.sessions.get(wid) };
|
|
464
|
+
}
|
|
465
|
+
/** The workflow with its run's labels and session, when it has them. */
|
|
466
|
+
function labelled(wf, labels, session) {
|
|
467
|
+
return labels || session ? { ...wf, ...(labels ? { labels } : {}), ...(session ? { session } : {}) } : wf;
|
|
452
468
|
}
|
|
453
|
-
/**
|
|
454
|
-
|
|
455
|
-
|
|
469
|
+
/** Whether `origin` ("main:<pi session id>") shows the workflow as its own: it started it, or the run named that pi
|
|
470
|
+
* session (RunBody.session, e.g. a CLI driver started from that session). */
|
|
471
|
+
export function ownedBy(w, origin) {
|
|
472
|
+
return w.origin === origin || (w.session !== undefined && `main:${w.session}` === origin);
|
|
456
473
|
}
|
|
457
474
|
/** Labels clipped for one status line: "[k=v k2=v2]", at most `width` characters (empty without labels). */
|
|
458
475
|
export function labelsText(labels, width = 60) {
|
|
@@ -463,8 +480,8 @@ export function labelsText(labels, width = 60) {
|
|
|
463
480
|
}
|
|
464
481
|
/** P25: Snapshot every workflow under DSA_HOME (newest first by wid, which is a ULID); `paused` marks work a drain holds. */
|
|
465
482
|
export function allWorkflows(home) {
|
|
466
|
-
const { held, labels } = heldWorkflows(home);
|
|
467
|
-
return workflowIds(home).sort().reverse().map(wid => { const wf = labelled(workflowSnapshot(home, wid), labels(wid)); return isLive(wf) && held(wid) ? { ...wf, paused: true } : wf; });
|
|
483
|
+
const { held, labels, session } = heldWorkflows(home);
|
|
484
|
+
return workflowIds(home).sort().reverse().map(wid => { const wf = labelled(workflowSnapshot(home, wid), labels(wid), session(wid)); return isLive(wf) && held(wid) ? { ...wf, paused: true } : wf; });
|
|
468
485
|
}
|
|
469
486
|
/** P10/P11: Per-workflow script console log written by the orchestrator (bounded, human-readable). */
|
|
470
487
|
export function scriptLogPath(home, wid) { return join(workflowDir(home, wid), "script.log"); }
|
|
@@ -507,10 +524,10 @@ function origins(home) {
|
|
|
507
524
|
}
|
|
508
525
|
/** Every workflow with its origin and hold, own session first, then newest first. */
|
|
509
526
|
function snapshots(home, origin) {
|
|
510
|
-
const own = (w) => Number(!!origin && w
|
|
511
|
-
const { since, held, labels } = heldWorkflows(home);
|
|
527
|
+
const own = (w) => Number(!!origin && ownedBy(w, origin));
|
|
528
|
+
const { since, held, labels, session } = heldWorkflows(home);
|
|
512
529
|
const all = [...origins(home)].sort(([a], [b]) => a < b ? 1 : a > b ? -1 : 0).map(([wid, origin]) => {
|
|
513
|
-
const wf = labelled(workflowSnapshot(home, wid), labels(wid)), withOrigin = wf.origin === undefined && origin !== undefined ? { ...wf, origin } : wf;
|
|
530
|
+
const wf = labelled(workflowSnapshot(home, wid), labels(wid), session(wid)), withOrigin = wf.origin === undefined && origin !== undefined ? { ...wf, origin } : wf;
|
|
514
531
|
return isLive(withOrigin) && held(wid) ? { ...withOrigin, paused: true } : withOrigin;
|
|
515
532
|
}).sort((a, b) => own(b) - own(a));
|
|
516
533
|
return { all, ...(since !== undefined ? { since } : {}) };
|
|
@@ -641,7 +658,7 @@ export function slotsView(home, now = Date.now()) {
|
|
|
641
658
|
export function statusBrief(home, options = {}) {
|
|
642
659
|
const keep = options.keep ?? 5, now = options.now ?? Date.now(), origin = options.origin;
|
|
643
660
|
const { all } = snapshots(home, origin), leases = leaseState(home), byCall = leaseCalls(leases, now);
|
|
644
|
-
const mine = (w) => !origin || w
|
|
661
|
+
const mine = (w) => !origin || ownedBy(w, origin);
|
|
645
662
|
const line = (w) => {
|
|
646
663
|
const p = progressOf(w), notOk = latestCalls(w).filter(c => c.result && !c.result.ok).length;
|
|
647
664
|
const notes = latestCalls(w).reduce((n, c) => n + (c.notesPending ?? 0), 0);
|
|
@@ -775,7 +792,7 @@ export function statusDetail(home, wid) {
|
|
|
775
792
|
const origin = origins(home);
|
|
776
793
|
if (!origin.has(wid))
|
|
777
794
|
throw new Error(prunedIds(home).has(wid) ? `Workflow ${wid} was pruned` : `Unknown workflow: ${wid}`);
|
|
778
|
-
const wf = labelled(workflowSnapshot(home, wid),
|
|
795
|
+
const held = heldWorkflows(home), wf = labelled(workflowSnapshot(home, wid), held.labels(wid), held.session(wid)), log = scriptLogPath(home, wid);
|
|
779
796
|
return { ...wf, ...(wf.origin === undefined && origin.get(wid) !== undefined ? { origin: origin.get(wid) } : {}), ...(existsSync(log) ? { scriptLog: log } : {}) };
|
|
780
797
|
}
|
|
781
798
|
/** P25, T10: Project a workflow journal into meaningful events (no observations, time or tracking). */
|
package/dist/requests.js
CHANGED
|
@@ -48,12 +48,15 @@ export async function namesMany(home, id) {
|
|
|
48
48
|
const first = `${id}:1`;
|
|
49
49
|
return REQUEST_ID.test(first) && await findRequest(home, requestRid(first)) !== undefined;
|
|
50
50
|
}
|
|
51
|
+
/** A pi session id as a run's `session`: what a pi session exports as $DSA_SESSION. */
|
|
52
|
+
export const SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
51
53
|
/** Spec_digest = contentHash({kind, body, cond}) (cond omitted when absent). A run's body.origin (the pi session
|
|
52
|
-
* branch offered for context:"fork") is delivery metadata, not spec: it differs on every turn, so it is not hashed
|
|
54
|
+
* branch offered for context:"fork") is delivery metadata, not spec: it differs on every turn, so it is not hashed;
|
|
55
|
+
* nor is body.session (which pi session shows the run): a retry from another session is the same request. */
|
|
53
56
|
export function specDigest(req) {
|
|
54
57
|
let body = req.body;
|
|
55
58
|
if (req.kind === 'run' && body && typeof body === 'object' && !Array.isArray(body)) {
|
|
56
|
-
const { origin: _, ...rest } = body;
|
|
59
|
+
const { origin: _, session: _s, ...rest } = body;
|
|
57
60
|
body = rest;
|
|
58
61
|
}
|
|
59
62
|
if (req.kind === 'send' && body && typeof body === 'object' && !Array.isArray(body)) {
|
package/dist/ui/view.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
-
import { isLive, labelsText, liveCalls, progressOf } from "../orchestrator/snapshot.js";
|
|
2
|
+
import { isLive, labelsText, liveCalls, ownedBy, progressOf } from "../orchestrator/snapshot.js";
|
|
3
3
|
import { oneLine } from "./frame.js";
|
|
4
4
|
/** UI §2: Render compact wall-clock durations; never present these as charged active time. */
|
|
5
5
|
export function duration(ms) {
|
|
@@ -28,10 +28,11 @@ export const toolCount = (n) => n ? `${n} tool${n === 1 ? "" : "s"}` : "";
|
|
|
28
28
|
export const pendingText = (n) => n ? `${n} message${n === 1 ? "" : "s"} pending` : "";
|
|
29
29
|
/** UI §2, P7: The list row's small pending marker (the watch header spells it out). */
|
|
30
30
|
export const pendingMarker = (n) => n ? `${n} pending` : "";
|
|
31
|
-
/** UI §2: Sessions are independent: only this session's workflows,
|
|
32
|
-
*
|
|
31
|
+
/** UI §2: Sessions are independent: only this session's workflows (it started them, or a run started from it named it
|
|
32
|
+
* as its session, e.g. a CLI driver launched from this pi), newest first by start time. Start times never change, so
|
|
33
|
+
* the order is stable while you read, also when a workflow finishes. */
|
|
33
34
|
export function orderWorkflows(workflows, own) {
|
|
34
|
-
return workflows.filter(w => own === undefined || w
|
|
35
|
+
return workflows.filter(w => own === undefined || ownedBy(w, own))
|
|
35
36
|
.sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0) || (a.wid < b.wid ? 1 : a.wid > b.wid ? -1 : 0));
|
|
36
37
|
}
|
|
37
38
|
/** UI §2: Done rows newest result first by immutable end time; ties keep snapshot order, so rows never reshuffle. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-durable-subagents",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.31",
|
|
4
4
|
"description": "Subagents for pi that never lose work and never do it twice. Crash-safe workflows, automatic recovery, and a live view just like the main agent.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|