pi-durable-subagents 1.4.1 → 1.4.3
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 +23 -0
- package/README.md +9 -1
- package/dist/agent/main/snapshots.js +12 -6
- package/dist/agent/main.js +1 -1
- package/dist/compat/agents.js +93 -9
- package/dist/orchestrator/snapshot.js +87 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.4.3
|
|
4
|
+
|
|
5
|
+
- Startup: agent discovery no longer starts `npm root -g` every time (issue #5). Each pi start, run admission and CLI
|
|
6
|
+
request discovered agents, and npm took 100-300 ms to answer (seconds on a busy machine) before the TUI appeared.
|
|
7
|
+
The global root is now asked once and kept in this process and in `DSA_HOME/cache/npm-root.json`, keyed on the
|
|
8
|
+
`npm` and `node` executables found on `PATH`, the prefix environment and the user, global and builtin npmrc files;
|
|
9
|
+
a change asks npm again. A failed answer is not cached and is retried after a minute. When `npm` on `PATH` is a
|
|
10
|
+
version manager's shim (asdf, mise, Volta), which picks node per directory, its answer is kept only ten seconds in
|
|
11
|
+
the process. With a warm cache discovery takes about 10 ms; it took 100-140 ms here, and the reporter measured
|
|
12
|
+
170-225 ms inside the extension's 250-300 ms factory.
|
|
13
|
+
|
|
14
|
+
## 1.4.2
|
|
15
|
+
|
|
16
|
+
- Memory: a main session's polling no longer keeps every earlier pass alive. Each workflow entry's lazy `entries`
|
|
17
|
+
getter was created inside the polling function and closed over that call's context, which held the preceding pass;
|
|
18
|
+
so each pass kept the one before it, with its listing of the workflows directory, ledger state and digests. A
|
|
19
|
+
long-running pi grew by about 0.25 GB per hour while its subagents worked and ran out of heap after about 12 hours.
|
|
20
|
+
A pass now keeps only the latest result.
|
|
21
|
+
- Memory: `status`, every `send` and the resume check no longer keep a digest of every settled workflow on the
|
|
22
|
+
machine. They keep only each settled journal's identity and owner, and read the few finished workflows they show
|
|
23
|
+
from the cache. On a home with 7,800 workflows a pi process kept about 220 MB after its first `status`; it keeps
|
|
24
|
+
about 26 MB. The output is unchanged.
|
|
25
|
+
|
|
3
26
|
## 1.4.1
|
|
4
27
|
|
|
5
28
|
- Docs, tests and fixtures use neutral example names and paths; no behaviour change.
|
package/README.md
CHANGED
|
@@ -614,7 +614,12 @@ ends with work still counted.
|
|
|
614
614
|
Agent files, discovery and precedence follow `pi-subagents` 0.75.0. That
|
|
615
615
|
covers user, project and package agents, `model:thinking`, `tools` and
|
|
616
616
|
`skills`. The same builtin agents are included; an agent file of the same name
|
|
617
|
-
in your user or project agents overrides one.
|
|
617
|
+
in your user or project agents overrides one. Packages in npm's global root are
|
|
618
|
+
searched as well. Its location is asked from `npm root -g` once and kept in
|
|
619
|
+
`DSA_HOME/cache/npm-root.json`, until the `npm` or `node` found on `PATH`, the
|
|
620
|
+
`npm_config_prefix`/`PREFIX` environment or an npmrc file changes (a version
|
|
621
|
+
manager's `npm` shim is asked again after ten seconds); with `PI_OFFLINE=1` npm
|
|
622
|
+
is not asked.
|
|
618
623
|
|
|
619
624
|
| Agent | Use it when you want... |
|
|
620
625
|
|---|---|
|
|
@@ -1034,6 +1039,9 @@ for at most five seconds. Turn boundaries check immediately for late attention.
|
|
|
1034
1039
|
Ledger changes force a journal check;
|
|
1035
1040
|
final sessions are also rechecked within five seconds. Only an explicitly
|
|
1036
1041
|
opened final call keeps its transcript. Prune removes the workflow's caches.
|
|
1042
|
+
A `status` or `send` covers every workflow of the machine but keeps in memory
|
|
1043
|
+
only the identity of a settled journal that no poller holds; the few finished
|
|
1044
|
+
workflows it shows are read from the cache each time.
|
|
1037
1045
|
`DSA_CACHE_HOME=<directory>` places the derived cache under that directory
|
|
1038
1046
|
instead of `DSA_HOME`, without changing where authoritative data is read.
|
|
1039
1047
|
|
|
@@ -31,6 +31,17 @@ export class PendingOutboxReader {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
const passes = new Map();
|
|
34
|
+
/** One workflow of a pass. Built here, not inside workflows(): a getter created there closes over that call's whole
|
|
35
|
+
* context, which holds the preceding pass (`prior`, `old`), so every result entry kept the pass before it alive and,
|
|
36
|
+
* through that pass's own entries, every earlier one (each with its listing of w/, ledger state and digests). */
|
|
37
|
+
function mainWorkflow(wid, origin, digest, path) {
|
|
38
|
+
return { wid, origin, ...(digest.settled ? { settled: digest.settled } : {}), get entries() {
|
|
39
|
+
const entries = readJournalSnapshot(path);
|
|
40
|
+
if (digest.settled)
|
|
41
|
+
forgetJournalSnapshot(path);
|
|
42
|
+
return entries;
|
|
43
|
+
} };
|
|
44
|
+
}
|
|
34
45
|
export function workflows(home, origin, fresh = false) {
|
|
35
46
|
const { record, names, checked: listed } = readerWorkflowListing(home, fresh), ix = record.state, mark = readerLedgerIdentity(record), now = Date.now();
|
|
36
47
|
let byOrigin = passes.get(home);
|
|
@@ -59,12 +70,7 @@ export function workflows(home, origin, fresh = false) {
|
|
|
59
70
|
continue;
|
|
60
71
|
}
|
|
61
72
|
digests.set(wid, digest);
|
|
62
|
-
changes.set(wid,
|
|
63
|
-
const entries = readJournalSnapshot(path);
|
|
64
|
-
if (digest.settled)
|
|
65
|
-
forgetJournalSnapshot(path);
|
|
66
|
-
return entries;
|
|
67
|
-
} });
|
|
73
|
+
changes.set(wid, mainWorkflow(wid, from, digest, path));
|
|
68
74
|
}
|
|
69
75
|
const result = ids.map(wid => changes.get(wid) ?? old.get(wid)).filter((w) => !!w);
|
|
70
76
|
const same = prior && prior.result.length === result.length && result.every((w, i) => w === prior.result[i]);
|
package/dist/agent/main.js
CHANGED
|
@@ -23,7 +23,7 @@ let noteSink;
|
|
|
23
23
|
/** P16: Queue a UI note for the next boundary without waking the model. */
|
|
24
24
|
export function presentNote(text) { noteSink?.(text); }
|
|
25
25
|
/** P1, P15, P16, P25, P38: Register durable submission and serialized main-session presentation. */
|
|
26
|
-
/** v12 §6: Agent discovery per cwd, reused for a few seconds (
|
|
26
|
+
/** v12 §6: Agent discovery per cwd, reused for a few seconds (it reads every package's manifest). */
|
|
27
27
|
const discovered = new Map();
|
|
28
28
|
function agentsAt(cwd) {
|
|
29
29
|
const hit = discovered.get(cwd);
|
package/dist/compat/agents.js
CHANGED
|
@@ -4,6 +4,95 @@ import { homedir } from "node:os";
|
|
|
4
4
|
import { execFileSync } from "node:child_process";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { parseFrontmatter, parseFrontmatterList } from "./frontmatter.js";
|
|
7
|
+
import { cacheDir, dsaHome } from "../paths.js";
|
|
8
|
+
const stamp = (p) => { if (!p)
|
|
9
|
+
return null; try {
|
|
10
|
+
const s = fs.statSync(p);
|
|
11
|
+
return `${p}@${s.mtimeMs}:${s.size}`;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return `${p}@-`;
|
|
15
|
+
} };
|
|
16
|
+
/** The first `name` on PATH, resolved, with its stamp: what execFileSync would start. */
|
|
17
|
+
function onPath(name, env) {
|
|
18
|
+
const exts = process.platform === "win32" ? (env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";").filter(Boolean).concat("") : [""];
|
|
19
|
+
for (const dir of (env.PATH ?? env.Path ?? "").split(path.delimiter)) {
|
|
20
|
+
if (!dir)
|
|
21
|
+
continue;
|
|
22
|
+
for (const ext of exts) {
|
|
23
|
+
try {
|
|
24
|
+
const p = fs.realpathSync(path.join(dir, name + ext));
|
|
25
|
+
if (fs.statSync(p).isFile())
|
|
26
|
+
return p;
|
|
27
|
+
}
|
|
28
|
+
catch { /* next */ }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
/** Everything `npm root -g` reads to decide its answer, except npm's own code: which npm and node PATH selects, the
|
|
34
|
+
* prefix environment, and the user, global and builtin npmrc files. -g ignores the project's .npmrc, so cwd is not
|
|
35
|
+
* part of it, unless `npm` is a version manager's shim (asdf, mise, Volta) rather than npm itself: the shim picks a
|
|
36
|
+
* node per directory from files this key does not see, so its answer is only `fixed` for a few seconds. */
|
|
37
|
+
function npmRootKey(env) {
|
|
38
|
+
const npm = onPath("npm", env), node = onPath("node", env);
|
|
39
|
+
const vars = Object.keys(env).filter(k => /^(npm_config_(prefix|userconfig|globalconfig)|PREFIX|DESTDIR)$/i.test(k)).sort().map(k => `${k}=${env[k]}`);
|
|
40
|
+
const userconfig = Object.entries(env).find(([k]) => /^npm_config_userconfig$/i.test(k))?.[1] ?? path.join(env.HOME || env.USERPROFILE || homedir(), ".npmrc");
|
|
41
|
+
const prefix = env.PREFIX ?? (node ? (process.platform === "win32" ? path.dirname(node) : path.dirname(path.dirname(node))) : undefined);
|
|
42
|
+
const globalconfig = Object.entries(env).find(([k]) => /^npm_config_globalconfig$/i.test(k))?.[1] ?? (prefix && path.join(prefix, "etc", "npmrc"));
|
|
43
|
+
const builtin = npm ? path.join(path.dirname(path.dirname(npm)), "npmrc") : undefined;
|
|
44
|
+
const fixed = !!npm && /[\\/]npm[\\/]bin[\\/]npm(-cli\.js)?$/.test(npm);
|
|
45
|
+
return { npm, fixed, key: JSON.stringify([stamp(npm ?? undefined), stamp(node ?? undefined), vars, stamp(userconfig), stamp(globalconfig), stamp(builtin), process.platform === "win32" ? null : stamp("/etc/npmrc"), fixed ? null : process.cwd()]) };
|
|
46
|
+
}
|
|
47
|
+
const NPM_ROOT_ENTRIES = 8, NPM_ROOT_RETRY_MS = 60_000, NPM_ROOT_SHIM_MS = 10_000;
|
|
48
|
+
let npmRootMemo;
|
|
49
|
+
/** Issue #5: npm's global root without starting npm on every discovery. `npm root -g` takes 100-300 ms, and seconds on
|
|
50
|
+
* a busy machine, while every pi start, run admission and CLI request discovers agents. The answer is kept in this
|
|
51
|
+
* process and in a small rebuildable cache file, keyed on npmRootKey; a changed input asks npm again. A failed answer
|
|
52
|
+
* is null and is retried after a minute, never written to disk. A shim's answer stays in this process for ten seconds
|
|
53
|
+
* and is never written to disk. No npm on PATH is null without starting anything. */
|
|
54
|
+
export function globalNpmRoot(options = {}) {
|
|
55
|
+
const env = options.env ?? process.env;
|
|
56
|
+
const { key, npm, fixed } = npmRootKey(env);
|
|
57
|
+
if (!npm)
|
|
58
|
+
return null;
|
|
59
|
+
const now = Date.now();
|
|
60
|
+
if (npmRootMemo?.key === key && npmRootMemo.until > now)
|
|
61
|
+
return npmRootMemo.root;
|
|
62
|
+
const file = !fixed ? null : options.cacheFile === undefined ? path.join(cacheDir(dsaHome(env)), "npm-root.json") : options.cacheFile;
|
|
63
|
+
let entries = [];
|
|
64
|
+
if (file) {
|
|
65
|
+
try {
|
|
66
|
+
const v = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
67
|
+
if (Array.isArray(v))
|
|
68
|
+
entries = v.filter(e => typeof e?.key === "string" && typeof e?.root === "string");
|
|
69
|
+
}
|
|
70
|
+
catch { /* none yet */ }
|
|
71
|
+
const hit = entries.find(e => e.key === key);
|
|
72
|
+
if (hit) {
|
|
73
|
+
npmRootMemo = { key, root: hit.root, until: Infinity };
|
|
74
|
+
return hit.root;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
let root = null;
|
|
78
|
+
try {
|
|
79
|
+
root = (options.run ?? (() => execFileSync("npm", ["root", "-g"], { encoding: "utf8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"], env })))().trim() || null;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
root = null;
|
|
83
|
+
}
|
|
84
|
+
npmRootMemo = { key, root, until: !fixed ? now + NPM_ROOT_SHIM_MS : root === null ? now + NPM_ROOT_RETRY_MS : Infinity };
|
|
85
|
+
if (file && root !== null) {
|
|
86
|
+
try {
|
|
87
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
88
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
89
|
+
fs.writeFileSync(tmp, JSON.stringify([{ key, root }, ...entries.filter(e => e.key !== key)].slice(0, NPM_ROOT_ENTRIES)));
|
|
90
|
+
fs.renameSync(tmp, file);
|
|
91
|
+
}
|
|
92
|
+
catch { /* A cache failure only costs asking npm again. */ }
|
|
93
|
+
}
|
|
94
|
+
return root;
|
|
95
|
+
}
|
|
7
96
|
const directory = (p) => { try {
|
|
8
97
|
return fs.statSync(p).isDirectory();
|
|
9
98
|
}
|
|
@@ -171,7 +260,8 @@ function scans(values, cwd, home) {
|
|
|
171
260
|
return fs.readdirSync(base, { withFileTypes: true }).filter(e => e.isDirectory()).map(e => path.join(base, e.name, ...parts.slice(i + 1)));
|
|
172
261
|
});
|
|
173
262
|
}
|
|
174
|
-
/** P35, P11: Discover a fresh snapshot with upstream roots and scope precedence; never write
|
|
263
|
+
/** P35, P11: Discover a fresh snapshot with upstream roots and scope precedence; never write (beyond the rebuildable
|
|
264
|
+
* npm-root cache, globalNpmRoot). */
|
|
175
265
|
export function discoverAgents(cwd, options = {}) {
|
|
176
266
|
cwd = path.resolve(cwd);
|
|
177
267
|
const home = path.resolve(options.home ?? homedir());
|
|
@@ -213,14 +303,8 @@ export function discoverAgents(cwd, options = {}) {
|
|
|
213
303
|
}
|
|
214
304
|
}
|
|
215
305
|
let globalRoot = options.globalNpmRoot;
|
|
216
|
-
if (globalRoot === undefined && scope !== "project" && !/^(1|true|yes)$/i.test(process.env.PI_OFFLINE ?? ""))
|
|
217
|
-
|
|
218
|
-
globalRoot = execFileSync("npm", ["root", "-g"], { encoding: "utf8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
219
|
-
}
|
|
220
|
-
catch {
|
|
221
|
-
globalRoot = null;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
306
|
+
if (globalRoot === undefined && scope !== "project" && !/^(1|true|yes)$/i.test(process.env.PI_OFFLINE ?? ""))
|
|
307
|
+
globalRoot = globalNpmRoot();
|
|
224
308
|
if (globalRoot && scope !== "project")
|
|
225
309
|
roots.push(...packageRoots(globalRoot));
|
|
226
310
|
for (const packageRoot of new Set(roots)) {
|
|
@@ -766,6 +766,69 @@ export function workflowDigest(home, wid, ledger) {
|
|
|
766
766
|
}
|
|
767
767
|
return digest;
|
|
768
768
|
}
|
|
769
|
+
/** Settled journals a status listing checked without keeping their digest: the journal's identity and who owns the
|
|
770
|
+
* workflow. A listing covers every workflow of the machine (thousands) but shows only a few finished ones; keeping
|
|
771
|
+
* all their digests in `digests` cost each pi process hundreds of MB from its first `status` or `send`. */
|
|
772
|
+
const settledMarks = new Map();
|
|
773
|
+
/** Replace a settled digest that no poller held before (`held`) by its mark: the next reader takes it from disk. */
|
|
774
|
+
function markSettled(path) {
|
|
775
|
+
const memo = digests.get(path);
|
|
776
|
+
if (!memo?.digest.settled) {
|
|
777
|
+
settledMarks.delete(path);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
const { origin, session } = memo.digest.snapshot;
|
|
781
|
+
settledMarks.set(path, { dev: memo.dev, ino: memo.ino, size: memo.size, ...(origin !== undefined ? { origin } : {}), ...(session !== undefined ? { session } : {}) });
|
|
782
|
+
digests.delete(path);
|
|
783
|
+
folds.delete(path);
|
|
784
|
+
forgetJournalSnapshot(path);
|
|
785
|
+
releasable.delete(path);
|
|
786
|
+
}
|
|
787
|
+
/** Whether a workflow's journal is settled as it is now, with the origin and session of its snapshot; decided without
|
|
788
|
+
* keeping its digest in memory unless a poller already holds it. Undefined: not settled (or not readable). */
|
|
789
|
+
function settledFacts(home, wid) {
|
|
790
|
+
const path = pathsOf(home, wid).journal;
|
|
791
|
+
if (digests.has(path)) {
|
|
792
|
+
const digest = workflowDigest(home, wid);
|
|
793
|
+
settledMarks.delete(path);
|
|
794
|
+
return digest.settled ? { origin: digest.snapshot.origin, session: digest.snapshot.session } : undefined;
|
|
795
|
+
}
|
|
796
|
+
let dev, ino, size;
|
|
797
|
+
try {
|
|
798
|
+
({ dev, ino, size } = statSync(path));
|
|
799
|
+
}
|
|
800
|
+
catch (error) {
|
|
801
|
+
if (error.code !== "ENOENT")
|
|
802
|
+
throw error;
|
|
803
|
+
settledMarks.delete(path);
|
|
804
|
+
return undefined;
|
|
805
|
+
}
|
|
806
|
+
const mark = settledMarks.get(path);
|
|
807
|
+
if (mark && mark.dev === dev && mark.ino === ino && mark.size === size)
|
|
808
|
+
return mark;
|
|
809
|
+
const stored = storedDigest(home, wid, dev, ino, size);
|
|
810
|
+
if (stored) {
|
|
811
|
+
const { origin, session } = stored.snapshot;
|
|
812
|
+
const facts = { ...(origin !== undefined ? { origin } : {}), ...(session !== undefined ? { session } : {}) };
|
|
813
|
+
settledMarks.set(path, { dev, ino, size, ...facts });
|
|
814
|
+
return facts;
|
|
815
|
+
}
|
|
816
|
+
// No usable stored digest: fold the journal once (this also stores its digest when settled), then keep only the mark.
|
|
817
|
+
const digest = workflowDigest(home, wid);
|
|
818
|
+
markSettled(path);
|
|
819
|
+
return digest.settled ? { origin: digest.snapshot.origin, session: digest.snapshot.session } : undefined;
|
|
820
|
+
}
|
|
821
|
+
/** `read` (one snapshot of a settled workflow) without keeping its digest in memory unless a poller already held it. */
|
|
822
|
+
function unretained(home, wid, read) {
|
|
823
|
+
const path = pathsOf(home, wid).journal, held = digests.has(path);
|
|
824
|
+
try {
|
|
825
|
+
return read();
|
|
826
|
+
}
|
|
827
|
+
finally {
|
|
828
|
+
if (!held)
|
|
829
|
+
markSettled(path);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
769
832
|
/** Last journal identity check of the current digest. Reuse never renews this timestamp. */
|
|
770
833
|
export function workflowDigestChecked(home, wid) {
|
|
771
834
|
return digests.get(pathsOf(home, wid).journal)?.checked ?? -Infinity;
|
|
@@ -906,6 +969,7 @@ function forgetRemovedWorkflows(home, names, pruned) {
|
|
|
906
969
|
for (const [wid, p] of paths)
|
|
907
970
|
if (pruned.has(wid) || !present.has(wid)) {
|
|
908
971
|
digests.delete(p.journal);
|
|
972
|
+
settledMarks.delete(p.journal);
|
|
909
973
|
folds.delete(p.journal);
|
|
910
974
|
forgetJournalSnapshot(p.journal);
|
|
911
975
|
firstOrigins.delete(p.journal);
|
|
@@ -1291,12 +1355,22 @@ function origins(home) {
|
|
|
1291
1355
|
}
|
|
1292
1356
|
/** Every workflow with its origin and hold, own session first, then newest first. */
|
|
1293
1357
|
function snapshots(home, origin) {
|
|
1294
|
-
const
|
|
1358
|
+
const owned = (w) => !!origin && ownedBy(w, origin);
|
|
1295
1359
|
const { since, held, labels, session } = heldWorkflows(home);
|
|
1296
|
-
const
|
|
1297
|
-
const wf = labelled(workflowSnapshot(home, wid), labels(wid), session(wid)), withOrigin = wf.origin === undefined &&
|
|
1360
|
+
const full = (wid, ledgerOrigin) => {
|
|
1361
|
+
const wf = labelled(workflowSnapshot(home, wid), labels(wid), session(wid)), withOrigin = wf.origin === undefined && ledgerOrigin !== undefined ? { ...wf, origin: ledgerOrigin } : wf;
|
|
1298
1362
|
return isLive(withOrigin) && held(wid) ? { ...withOrigin, paused: true } : withOrigin;
|
|
1299
|
-
}
|
|
1363
|
+
};
|
|
1364
|
+
const all = [...origins(home)].sort(([a], [b]) => a < b ? 1 : a > b ? -1 : 0).map(([wid, ledgerOrigin]) => {
|
|
1365
|
+
const facts = settledFacts(home, wid);
|
|
1366
|
+
if (facts) {
|
|
1367
|
+
let wf;
|
|
1368
|
+
return { wid, settled: true, own: owned({ origin: facts.origin ?? ledgerOrigin, session: session(wid) || facts.session }),
|
|
1369
|
+
snapshot: () => wf ??= unretained(home, wid, () => full(wid, ledgerOrigin)) };
|
|
1370
|
+
}
|
|
1371
|
+
const wf = full(wid, ledgerOrigin);
|
|
1372
|
+
return { wid, settled: settled(wf), own: owned(wf), snapshot: () => wf };
|
|
1373
|
+
}).sort((a, b) => Number(b.own) - Number(a.own));
|
|
1300
1374
|
return { all, ...(since !== undefined ? { since } : {}) };
|
|
1301
1375
|
}
|
|
1302
1376
|
/** P25, T10: Compact status of all workflows: own session first, then newest first; finished ones beyond the first `keep` collapse into a count. */
|
|
@@ -1304,9 +1378,9 @@ export function statusView(home, options = {}) {
|
|
|
1304
1378
|
const keep = options.keep ?? 10;
|
|
1305
1379
|
const { all, since } = snapshots(home, options.origin), leases = leaseState(home), byCall = leaseCalls(leases);
|
|
1306
1380
|
let finished = 0;
|
|
1307
|
-
const shown = all.filter(w => !settled
|
|
1381
|
+
const shown = all.filter(w => !w.settled || ++finished <= keep).map(w => w.snapshot());
|
|
1308
1382
|
const hidden = all.length - shown.length;
|
|
1309
|
-
const paused = all.filter(w => w.paused).length;
|
|
1383
|
+
const paused = all.filter(w => !w.settled && w.snapshot().paused).length;
|
|
1310
1384
|
return { workflows: shown.map(w => compactWorkflow(w, byCall)), ...(hidden ? { olderFinished: hidden, hint: "status wid=<wid> shows any workflow in detail" } : {}),
|
|
1311
1385
|
...(paused ? { paused: `${paused} workflow${paused > 1 ? "s" : ""} paused (stop-all, drain or a quit pi) since ${new Date(since).toISOString()}; resume continues them (new runs are not affected)` } : {}),
|
|
1312
1386
|
...slotsView(home), ...(leases.length ? { leases: leaseLines(leases) } : {}), ...runningStats(home) };
|
|
@@ -1460,7 +1534,7 @@ export function slotsView(home, now = Date.now()) {
|
|
|
1460
1534
|
* The full view (every call's last line and usage) ran to tens of thousands of tokens on a busy home. */
|
|
1461
1535
|
export function statusBrief(home, options = {}) {
|
|
1462
1536
|
const keep = options.keep ?? 5, now = options.now ?? Date.now(), origin = options.origin;
|
|
1463
|
-
const { all } = snapshots(home, origin), leases = leaseState(home), byCall = leaseCalls(leases, now);
|
|
1537
|
+
const { all: listed } = snapshots(home, origin), leases = leaseState(home), byCall = leaseCalls(leases, now);
|
|
1464
1538
|
const mine = (w) => !origin || ownedBy(w, origin);
|
|
1465
1539
|
const line = (w) => {
|
|
1466
1540
|
const p = progressOf(w), notOk = latestCalls(w).filter(c => c.result && !c.result.ok).length;
|
|
@@ -1492,15 +1566,16 @@ export function statusBrief(home, options = {}) {
|
|
|
1492
1566
|
progress: `${p.done}/${p.total}${p.plus ? "+" : ""}`, tokens: tokens(w.usage), calls,
|
|
1493
1567
|
...(asking.length ? { asking } : {}), ...(alerts.length ? { alerts } : {}) };
|
|
1494
1568
|
};
|
|
1495
|
-
const active =
|
|
1496
|
-
|
|
1569
|
+
const active = listed.filter(w => !w.settled).map(w => w.snapshot());
|
|
1570
|
+
// Snapshotted for its line only when shown (the first `keep`); the rest is a count.
|
|
1571
|
+
const finished = listed.filter(w => w.settled && (!origin || w.own));
|
|
1497
1572
|
const others = active.filter(w => !mine(w));
|
|
1498
1573
|
const heldMine = active.filter(w => mine(w) && w.paused).length, heldOthers = others.filter(w => w.paused);
|
|
1499
1574
|
const paused = [heldMine ? `${heldMine} workflow${heldMine > 1 ? "s" : ""} of this session ${heldMine > 1 ? "are" : "is"} paused (stop-all, drain or a quit pi); resume continues ${heldMine > 1 ? "them" : "it"}` : "",
|
|
1500
1575
|
heldOthers.length ? `${heldOthers.length} workflow${heldOthers.length > 1 ? "s" : ""} of other sessions paused (${heldOthers.slice(0, 8).map(w => w.wid).join(", ")}); resume wid=<wid> continues one` : ""].filter(Boolean).join("; ");
|
|
1501
1576
|
return {
|
|
1502
1577
|
active: active.filter(mine).map(brief), ...(others.length ? { otherSessions: others.slice(0, 10).map(line) } : {}),
|
|
1503
|
-
finished: finished.slice(0, keep).map(line), ...(finished.length > keep ? { olderFinished: finished.length - keep } : {}),
|
|
1578
|
+
finished: finished.slice(0, keep).map(w => line(w.snapshot())), ...(finished.length > keep ? { olderFinished: finished.length - keep } : {}),
|
|
1504
1579
|
...(paused ? { paused } : {}), ...slotsView(home, now), ...(leases.length ? { leases: leaseLines(leases, now) } : {}),
|
|
1505
1580
|
hint: "status wid=<wid> shows one workflow (outputs clipped); add key=<key> for one call's full result, or full:true for everything",
|
|
1506
1581
|
};
|
|
@@ -1535,7 +1610,8 @@ export function statusText(home, value) {
|
|
|
1535
1610
|
}
|
|
1536
1611
|
/** Running workflows of other sessions that a pause holds, as "wid" or "wid (name)": a session's own resume skips them. */
|
|
1537
1612
|
export function pausedElsewhere(home, origin) {
|
|
1538
|
-
return snapshots(home, origin).all.filter(w => w.
|
|
1613
|
+
return snapshots(home, origin).all.filter(w => !w.settled).map(w => w.snapshot()).filter(w => w.paused && w.origin !== origin)
|
|
1614
|
+
.map(w => w.name ? `${w.wid} (${w.name})` : w.wid);
|
|
1539
1615
|
}
|
|
1540
1616
|
/** "<rid>" or "<rid>/<rest>" of a run request that created a workflow → the same address with its wid; else unchanged.
|
|
1541
1617
|
* A run replies {submitted:{rid}} when its workflow is not created within 10 s, so the rid is all the caller has. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-durable-subagents",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
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",
|