pi-durable-subagents 1.4.3 → 1.5.0
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 +6 -0
- package/README.md +10 -6
- package/dist/agent/main.js +7 -3
- package/dist/orchestrator/executor/effects/prepare.js +8 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
- The `durable-subagents:activity` event includes `costUsd`, the sum of recorded costs for the session's retained workflows, including finished runs. Status bars receive a new event when spend changes (#6).
|
|
6
|
+
- Parallel and chained calls with `isolation: "worktree"` can create a Git branch for generated keys such as `tasks:0`. Each key gets a distinct branch, including when the workflow also has a key named `tasks-0` (#8).
|
|
7
|
+
- The CLI guide explains how to start a run whose completion wakes the main pi session (#9).
|
|
8
|
+
|
|
3
9
|
## 1.4.3
|
|
4
10
|
|
|
5
11
|
- Startup: agent discovery no longer starts `npm root -g` every time (issue #5). Each pi start, run admission and CLI
|
package/README.md
CHANGED
|
@@ -597,17 +597,19 @@ tell that work goes on after the main agent settles:
|
|
|
597
597
|
|
|
598
598
|
```ts
|
|
599
599
|
pi.events.on("durable-subagents:activity", data => {
|
|
600
|
-
const { sessionId, busy, working, asking, queued, paused } = data as {
|
|
601
|
-
sessionId: string; busy: boolean; working: number; asking: number; queued: number; paused: number;
|
|
600
|
+
const { sessionId, busy, working, asking, queued, paused, costUsd } = data as {
|
|
601
|
+
sessionId: string; busy: boolean; working: number; asking: number; queued: number; paused: number; costUsd: number;
|
|
602
602
|
};
|
|
603
603
|
});
|
|
604
604
|
```
|
|
605
605
|
|
|
606
606
|
The counts are this session's live calls by state, the same as the summary
|
|
607
607
|
line above the editor. `busy` is true while any call works, asks or waits
|
|
608
|
-
for a slot; paused work alone is not busy.
|
|
609
|
-
|
|
610
|
-
|
|
608
|
+
for a slot; paused work alone is not busy. `costUsd` is what this session's
|
|
609
|
+
workflows have spent so far, finished ones included, so a status bar can show
|
|
610
|
+
subagent spend next to pi's own cost; a pruned workflow no longer counts. The
|
|
611
|
+
first state is sent when the session starts, then only changes, and every
|
|
612
|
+
count at zero (the spend kept) when the session ends with work still counted.
|
|
611
613
|
|
|
612
614
|
## Your pi-subagents scripts, unchanged
|
|
613
615
|
|
|
@@ -950,7 +952,9 @@ any row; the run still belongs to its sender: that session's main agent gets
|
|
|
950
952
|
no completion notices for it, quitting that pi does not pause it, and the
|
|
951
953
|
session is not part of the content, so a retry from another session gets the
|
|
952
954
|
first outcome. An invalid `--session` exits 1; an invalid inherited value
|
|
953
|
-
is ignored.
|
|
955
|
+
is ignored. To have the main agent receive a completion notice, start the run
|
|
956
|
+
with the `subagents` tool in that pi session. `--wake caller` delivers to the
|
|
957
|
+
subagent call that launched a CLI run (see above).
|
|
954
958
|
|
|
955
959
|
When an unsealed call does not move, its `waiting` in `describe` adds
|
|
956
960
|
`reason`, `detail` (the status line for that cause, e.g. `waiting for a slot:
|
package/dist/agent/main.js
CHANGED
|
@@ -70,7 +70,7 @@ export function registerMain(pi, ui) {
|
|
|
70
70
|
let ctx, sender = "", outbox;
|
|
71
71
|
let queue = Promise.resolve(), timer;
|
|
72
72
|
let reserved = [], notes = [], stopped = true, lastStarter = 0;
|
|
73
|
-
let polling = false, lastActivity = "", activityAt = 0;
|
|
73
|
+
let polling = false, lastActivity = "", lastCostUsd = 0, activityAt = 0;
|
|
74
74
|
const failures = new BackgroundFailures();
|
|
75
75
|
const pendingReader = new PendingOutboxReader();
|
|
76
76
|
const sink = (text) => { notes.push(text); };
|
|
@@ -107,12 +107,15 @@ export function registerMain(pi, ui) {
|
|
|
107
107
|
const events = pi.events;
|
|
108
108
|
if (typeof events?.emit !== "function" || !sender)
|
|
109
109
|
return;
|
|
110
|
-
const
|
|
111
|
-
const
|
|
110
|
+
const workflows = sessionEnds ? [] : ownWorkflows(home, sender);
|
|
111
|
+
const counts = sessionEnds ? { working: 0, asking: 0, queued: 0, paused: 0 } : activityCounts(workflows);
|
|
112
|
+
const costUsd = sessionEnds ? lastCostUsd : workflows.reduce((sum, w) => sum + (w.usage?.costUsd ?? 0), 0);
|
|
113
|
+
const activity = { sessionId: sender.slice("main:".length), busy: counts.working + counts.asking + counts.queued > 0, ...counts, costUsd };
|
|
112
114
|
const key = JSON.stringify(activity);
|
|
113
115
|
if (key === lastActivity || (sessionEnds && !lastActivity))
|
|
114
116
|
return;
|
|
115
117
|
lastActivity = key;
|
|
118
|
+
lastCostUsd = costUsd;
|
|
116
119
|
try {
|
|
117
120
|
events.emit(ACTIVITY_CHANNEL, activity);
|
|
118
121
|
}
|
|
@@ -199,6 +202,7 @@ export function registerMain(pi, ui) {
|
|
|
199
202
|
notes = [];
|
|
200
203
|
ctx = undefined;
|
|
201
204
|
lastActivity = "";
|
|
205
|
+
lastCostUsd = 0;
|
|
202
206
|
failures.ok();
|
|
203
207
|
}
|
|
204
208
|
async function start(context) {
|
|
@@ -62,7 +62,14 @@ export async function prepareWorktree(t) {
|
|
|
62
62
|
return t.cwd;
|
|
63
63
|
let intent = records(t, "wt-intent")[0];
|
|
64
64
|
if (!intent) {
|
|
65
|
-
const root = resolve(t.cwd, ".dsa", t.wid), path = resolve(root, t.key)
|
|
65
|
+
const root = resolve(t.cwd, ".dsa", t.wid), path = resolve(root, t.key);
|
|
66
|
+
// Colon keys could never create a branch in the original namespace. Give them their own namespace so
|
|
67
|
+
// existing literal keys (including percent-encoded spellings) retain their branches across upgrades.
|
|
68
|
+
const branch = t.key.includes(":")
|
|
69
|
+
? `dsa-colon/${t.wid}/${contentHash(t.key)}`
|
|
70
|
+
: `dsa/${t.wid}/${t.key}`;
|
|
71
|
+
if (t.key.split("/").some(part => !part || part === "." || part === ".."))
|
|
72
|
+
throw new Error("Invalid worktree key");
|
|
66
73
|
if (!path.startsWith(root + sep))
|
|
67
74
|
throw new Error("Invalid worktree key");
|
|
68
75
|
await git(t.cwd, "check-ref-format", "--branch", branch);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-durable-subagents",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
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",
|