pi-durable-subagents 1.0.27 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/README.md +121 -10
- package/dist/agent/child.js +7 -2
- package/dist/agent/main/schema.js +4 -1
- package/dist/agent/main/tool.js +42 -8
- package/dist/agent/main.js +62 -12
- package/dist/cli/doctor.js +4 -3
- package/dist/cli/drill/index.js +287 -0
- package/dist/cli/drill/provider.js +25 -0
- package/dist/cli/hold.js +28 -14
- package/dist/cli/main.js +50 -11
- package/dist/cli/requests.js +102 -18
- package/dist/kernel/journal.js +99 -15
- package/dist/kernel/mailbox.js +1 -1
- package/dist/orchestrator/engine.js +157 -12
- package/dist/orchestrator/evaluator-client.js +18 -3
- package/dist/orchestrator/executor/digest.js +80 -0
- package/dist/orchestrator/executor/index.js +47 -37
- package/dist/orchestrator/executor/observe.js +21 -7
- package/dist/orchestrator/notes.js +20 -0
- package/dist/orchestrator/restart.js +5 -3
- package/dist/orchestrator/snapshot.js +144 -21
- package/dist/orchestrator/stats.js +49 -0
- package/dist/platform/containment.js +35 -11
- package/dist/platform/lease.js +37 -11
- package/dist/platform/proctable.js +16 -3
- package/dist/requests.js +27 -0
- package/dist/ui/view.js +5 -2
- package/package.json +1 -1
|
@@ -2,11 +2,24 @@
|
|
|
2
2
|
// Known-id filtering assumes argv/other values do not impersonate the sole known
|
|
3
3
|
// execution id. Multiple known ids are ambiguous; macOS verification awaits CI.
|
|
4
4
|
import { readFile, readdir } from "node:fs/promises";
|
|
5
|
-
import { readFileSync } from "node:fs";
|
|
5
|
+
import { closeSync, openSync, readFileSync, readSync } from "node:fs";
|
|
6
6
|
import { execFile } from "node:child_process";
|
|
7
7
|
import { promisify } from "node:util";
|
|
8
8
|
const exec = promisify(execFile);
|
|
9
9
|
const vanished = (error) => ["ENOENT", "ESRCH", "EACCES", "EPERM"].includes(error.code ?? "");
|
|
10
|
+
// /proc/<pid>/stat is one short line: one open/read/close into a reused buffer, not readFileSync's fstat, sized read
|
|
11
|
+
// and EOF read (a scan reads it for every process of the machine every second).
|
|
12
|
+
const statBuffer = Buffer.alloc(4096);
|
|
13
|
+
function readStat(pid) {
|
|
14
|
+
const fd = openSync(`/proc/${pid}/stat`, "r");
|
|
15
|
+
try {
|
|
16
|
+
const n = readSync(fd, statBuffer, 0, statBuffer.length, 0);
|
|
17
|
+
return n < statBuffer.length ? statBuffer.toString("latin1", 0, n) : readFileSync(`/proc/${pid}/stat`, "latin1");
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
closeSync(fd);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
10
23
|
/** C2, C3: Capture only the newly spawned pid; an absent or dead process has no token. */
|
|
11
24
|
export async function captureStart(pid) {
|
|
12
25
|
if (process.platform === "linux") {
|
|
@@ -94,7 +107,7 @@ export class ProcessTable {
|
|
|
94
107
|
continue;
|
|
95
108
|
try {
|
|
96
109
|
// /proc stat is a tiny kernel snapshot; avoid four libuv round trips per cached identity.
|
|
97
|
-
const stat =
|
|
110
|
+
const stat = readStat(name);
|
|
98
111
|
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
99
112
|
// Zombies cannot act and may remain indefinitely under a non-reaping init.
|
|
100
113
|
if (fields[0] === "Z" || fields[0] === "X")
|
|
@@ -112,7 +125,7 @@ export class ProcessTable {
|
|
|
112
125
|
throw error;
|
|
113
126
|
}
|
|
114
127
|
// Do not attach an old environment to a reused pid; cached identities already include the start token.
|
|
115
|
-
const check =
|
|
128
|
+
const check = readStat(name);
|
|
116
129
|
if (check.slice(check.lastIndexOf(")") + 2).split(" ")[19] !== start)
|
|
117
130
|
continue;
|
|
118
131
|
}
|
package/dist/requests.js
CHANGED
|
@@ -21,6 +21,33 @@ export function requestRid(id) {
|
|
|
21
21
|
}
|
|
22
22
|
/** The request id of a `req:<id>` rid; undefined for any other rid (ULIDs never contain ':'). */
|
|
23
23
|
export function requestId(rid) { return rid.startsWith(PREFIX) ? rid.slice(PREFIX.length) : undefined; }
|
|
24
|
+
/** The request ids of one send to `n` calls under `<id>`: `<id>:1` ... `<id>:n`, one per target in the order given
|
|
25
|
+
* (each is an ordinary request id, so a retry with the same list gets the same outcomes). Each body carries the list's
|
|
26
|
+
* digest (`batch`, see batchDigest), so another list under the id is a request-conflict (checked by batchConflict
|
|
27
|
+
* before anything is sent). */
|
|
28
|
+
export function manyIds(id, n) {
|
|
29
|
+
const ids = Array.from({ length: n }, (_, i) => `${id}:${i + 1}`);
|
|
30
|
+
for (const derived of ids)
|
|
31
|
+
if (!REQUEST_ID.test(derived))
|
|
32
|
+
throw new Error(`request id ${JSON.stringify(id)} is too long for a send to ${n} calls (${derived} exceeds 124 characters)`);
|
|
33
|
+
requestRid(id);
|
|
34
|
+
return ids;
|
|
35
|
+
}
|
|
36
|
+
/** The `batch` of every request of a send to the calls `targets` (in the order given). */
|
|
37
|
+
export function batchDigest(targets) { return contentHash({ to: targets }); }
|
|
38
|
+
/** Whether `<id>` names other content than a send to several calls with this `batch`: a single request under `<id>`, or
|
|
39
|
+
* a send to several calls with another list (its first request `<id>:1` has another batch). */
|
|
40
|
+
export async function batchConflict(home, id, batch) {
|
|
41
|
+
if (await findRequest(home, requestRid(id)))
|
|
42
|
+
return true;
|
|
43
|
+
const first = `${id}:1`, prior = REQUEST_ID.test(first) ? await findRequest(home, requestRid(first)) : undefined;
|
|
44
|
+
return prior !== undefined && prior.request.body?.batch !== batch;
|
|
45
|
+
}
|
|
46
|
+
/** Whether `<id>` already names a send to several calls (its first derived id `<id>:1` is recorded). */
|
|
47
|
+
export async function namesMany(home, id) {
|
|
48
|
+
const first = `${id}:1`;
|
|
49
|
+
return REQUEST_ID.test(first) && await findRequest(home, requestRid(first)) !== undefined;
|
|
50
|
+
}
|
|
24
51
|
/** Spec_digest = contentHash({kind, body, cond}) (cond omitted when absent). A run's body.origin (the pi session
|
|
25
52
|
* branch offered for context:"fork") is delivery metadata, not spec: it differs on every turn, so it is not hashed. */
|
|
26
53
|
export function specDigest(req) {
|
package/dist/ui/view.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
-
import { isLive, liveCalls, progressOf } from "../orchestrator/snapshot.js";
|
|
2
|
+
import { isLive, labelsText, liveCalls, 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) {
|
|
@@ -276,7 +276,10 @@ export function listRows(workflows, state, facts, name, width, now = Date.now())
|
|
|
276
276
|
// Stable order (UI §2): active rows keep proposal (snapshot) order; done rows by immutable end time.
|
|
277
277
|
const done = doneOrder(w.calls), active = liveCalls(w), folded = !isOpen(w, state);
|
|
278
278
|
const progress = progressOf(w); // v12 §4: done/planned, `n+` while a script workflow keeps proposing
|
|
279
|
-
|
|
279
|
+
const head = `${folded ? "▸" : "▾"} ${w.name ?? w.wid} · ${progress.done}/${progress.total}${progress.plus ? "+" : ""} · ${duration((w.endedAt ?? now) - (w.startedAt ?? now))}`;
|
|
280
|
+
// The run's labels follow when the row has room for a useful part of them (clipped to at most 60 characters).
|
|
281
|
+
const room = Math.min(60, width - visibleWidth(head) - 3);
|
|
282
|
+
rows.push({ id: w.wid, kind: "workflow", workflow: w, dim, text: w.labels && room >= 12 ? `${head} · ${labelsText(w.labels, room)}` : head });
|
|
280
283
|
if (folded)
|
|
281
284
|
continue;
|
|
282
285
|
if (dim) { // a finished workflow lists its agents directly (no nested "done" node)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-durable-subagents",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.28",
|
|
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",
|