@ferris1225/pi-subagents 7.0.2 → 7.0.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 +15 -0
- package/README.md +6 -2
- package/package.json +1 -1
- package/src/lifecycle/cancellation.ts +21 -4
- package/src/lifecycle/runtime.ts +27 -0
- package/src/lifecycle/stop.ts +11 -3
- package/src/lifecycle/tools.ts +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 7.0.3
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
|
|
7
|
+
- Escape no longer cancels a run whose child already finished and is only
|
|
8
|
+
integrating its worktree. It settles normally, and its real result is
|
|
9
|
+
delivered on the next turn without waking main, instead of being reported as
|
|
10
|
+
aborted partial work while its changes were applied anyway.
|
|
11
|
+
- Escape hands successes already queued for delivery to the next turn instead
|
|
12
|
+
of discarding them. Branch navigation still stops everything and discards
|
|
13
|
+
results for the abandoned branch.
|
|
14
|
+
- `subagent_stop({ all: true })` skips settling runs and runs that are already
|
|
15
|
+
stopping. An explicit stop of a settling run retires it but keeps its real
|
|
16
|
+
result and integration status.
|
|
17
|
+
|
|
3
18
|
## 7.0.2
|
|
4
19
|
|
|
5
20
|
### Orchestration prompts
|
package/README.md
CHANGED
|
@@ -185,8 +185,12 @@ and preserves the caller's index, branch, and HEAD. Failures retain recovery
|
|
|
185
185
|
artifacts. Worktrees isolate Git changes, not permissions.
|
|
186
186
|
|
|
187
187
|
Escape cancels unfinished workers without waking main. Main receives a cancellation
|
|
188
|
-
receipt on the next user turn.
|
|
189
|
-
|
|
188
|
+
receipt on the next user turn. A worker whose child already finished and is only
|
|
189
|
+
integrating its worktree is not cancelled: it settles normally, and its real
|
|
190
|
+
result, like any result already queued for delivery, arrives on the next user
|
|
191
|
+
turn. `subagent_stop({ all: true })` also leaves such runs alone. Tree navigation,
|
|
192
|
+
new/resume/fork/reload, and shutdown stop old work; interrupted evidence remains
|
|
193
|
+
available for recovery.
|
|
190
194
|
|
|
191
195
|
The task widget shows status, elapsed time, model, thinking, tokens, and worktree
|
|
192
196
|
state in at most ten lines. Independent workers can start together; only
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ferris1225/pi-subagents",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.3",
|
|
4
4
|
"description": "Lead/worker orchestration for Pi: main plans and reviews, configurable workers execute with retained sessions and Git worktree isolation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1,18 +1,35 @@
|
|
|
1
|
-
/** Cancel work owned by a cancelled parent turn or an abandoned conversation branch.
|
|
1
|
+
/** Cancel work owned by a cancelled parent turn or an abandoned conversation branch.
|
|
2
|
+
*
|
|
3
|
+
* A run whose child already finished and is only integrating its worktree has
|
|
4
|
+
* nothing left to cancel. On a parent cancellation it settles normally and its
|
|
5
|
+
* real result, like any completion already held for delivery, reaches the next
|
|
6
|
+
* user turn without waking the parent. Branch navigation abandons the
|
|
7
|
+
* conversation, so it stops everything and discards results. */
|
|
2
8
|
|
|
3
9
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import type { SubagentRuntime } from "./runtime.ts";
|
|
10
|
+
import type { SubagentRuntime, SubagentThread } from "./runtime.ts";
|
|
5
11
|
import { stopThreads } from "./stop.ts";
|
|
6
12
|
|
|
7
13
|
const cancellations = new WeakMap<SubagentRuntime, Promise<void>>();
|
|
8
14
|
|
|
15
|
+
/** The child has settled and only Git integration and delivery remain. */
|
|
16
|
+
export function isSettlingThread(thread: SubagentThread): boolean {
|
|
17
|
+
return !thread.retired && thread.lifecycleOperation === "settle";
|
|
18
|
+
}
|
|
19
|
+
|
|
9
20
|
export function cancelActiveWork(runtime: SubagentRuntime, reason: string, notifyParent = true): Promise<void> {
|
|
10
21
|
const existing = cancellations.get(runtime);
|
|
11
22
|
if (existing) return existing;
|
|
12
23
|
runtime.suppressCompletions = true;
|
|
24
|
+
if (notifyParent) runtime.deferPendingCompletions();
|
|
13
25
|
runtime.discardCompletions();
|
|
14
|
-
const
|
|
15
|
-
|
|
26
|
+
const threads = [...runtime.threads.values()];
|
|
27
|
+
// Only a parent cancellation keeps finished work; an abandoned branch stops it.
|
|
28
|
+
const keepSettling = notifyParent;
|
|
29
|
+
if (keepSettling) for (const thread of threads.filter(isSettlingThread)) runtime.deferRunDelivery(thread.id);
|
|
30
|
+
const activeThreads = threads
|
|
31
|
+
.filter((thread) => !thread.retired && !(keepSettling && isSettlingThread(thread))
|
|
32
|
+
&& (thread.lifecycleOperation !== undefined || ["queued", "running", "interrupting"].includes(thread.state)));
|
|
16
33
|
const threadIds = activeThreads.map((thread) => thread.id);
|
|
17
34
|
const done = stopThreads(runtime, threadIds, reason).then(() => {
|
|
18
35
|
if (notifyParent && runtime.sessionActive && threadIds.length > 0) {
|
package/src/lifecycle/runtime.ts
CHANGED
|
@@ -86,6 +86,11 @@ export interface SubagentRuntime {
|
|
|
86
86
|
/** Cancelling a parent must not wake it again with old child results. */
|
|
87
87
|
suppressCompletions: boolean;
|
|
88
88
|
discardCompletions: () => void;
|
|
89
|
+
/** Hand held completions to the next user turn without waking the parent. */
|
|
90
|
+
deferPendingCompletions: () => void;
|
|
91
|
+
/** Route a run that already finished its child to the next user turn, even
|
|
92
|
+
* while completions are suppressed: its result is real and must not be lost. */
|
|
93
|
+
deferRunDelivery: (runId: number) => void;
|
|
89
94
|
/** Record cancellation for the next user turn without waking the parent. */
|
|
90
95
|
recordCancellation: (runIds: number[]) => void;
|
|
91
96
|
/** Resolves when the load-time durable restore pass has finished. Everything
|
|
@@ -139,6 +144,15 @@ export function createRuntime(pi: ExtensionAPI, configPath: string): SubagentRun
|
|
|
139
144
|
let heldCompletions: CompletionMessageItem[] = [];
|
|
140
145
|
|
|
141
146
|
const runDeliveries = new Map<number, "background" | "await">();
|
|
147
|
+
const deferredRuns = new Set<number>();
|
|
148
|
+
const sendNextTurn = (items: CompletionMessageItem[]): void => {
|
|
149
|
+
if (!runtime.sessionActive || items.length === 0) return;
|
|
150
|
+
pi.sendMessage({
|
|
151
|
+
customType: "subagent-result",
|
|
152
|
+
content: formatCompletionMessage(items),
|
|
153
|
+
display: true,
|
|
154
|
+
}, { deliverAs: "nextTurn", triggerTurn: false });
|
|
155
|
+
};
|
|
142
156
|
const runtime: SubagentRuntime = {
|
|
143
157
|
configPath,
|
|
144
158
|
backgroundQueue,
|
|
@@ -161,6 +175,14 @@ export function createRuntime(pi: ExtensionAPI, configPath: string): SubagentRun
|
|
|
161
175
|
heldCompletions = [];
|
|
162
176
|
runDeliveries.clear();
|
|
163
177
|
},
|
|
178
|
+
deferPendingCompletions: () => {
|
|
179
|
+
const pending = [...runtime.completionBatcher.dispose(), ...heldCompletions];
|
|
180
|
+
heldCompletions = [];
|
|
181
|
+
sendNextTurn(pending);
|
|
182
|
+
},
|
|
183
|
+
deferRunDelivery: (runId) => {
|
|
184
|
+
deferredRuns.add(runId);
|
|
185
|
+
},
|
|
164
186
|
durableRestore: Promise.resolve(),
|
|
165
187
|
restoredRunIds: [],
|
|
166
188
|
restoredNotified: false,
|
|
@@ -200,6 +222,11 @@ export function createRuntime(pi: ExtensionAPI, configPath: string): SubagentRun
|
|
|
200
222
|
runDeliveries.set(runId, route);
|
|
201
223
|
},
|
|
202
224
|
publishRunCompletion: (runId, item, immediate) => {
|
|
225
|
+
if (deferredRuns.delete(runId)) {
|
|
226
|
+
runDeliveries.delete(runId);
|
|
227
|
+
sendNextTurn([item]);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
203
230
|
if (runtime.suppressCompletions) { runDeliveries.delete(runId); return; }
|
|
204
231
|
if (runDeliveries.get(runId) === "await") return;
|
|
205
232
|
runDeliveries.delete(runId);
|
package/src/lifecycle/stop.ts
CHANGED
|
@@ -19,6 +19,7 @@ export async function stopThreads(runtime: SubagentRuntime, targets: readonly nu
|
|
|
19
19
|
previousState: SubagentThread["state"];
|
|
20
20
|
wasQueued: boolean;
|
|
21
21
|
wasActive: boolean;
|
|
22
|
+
wasSettling: boolean;
|
|
22
23
|
generation: number;
|
|
23
24
|
controller: AbortController | undefined;
|
|
24
25
|
completion: Promise<void>;
|
|
@@ -32,6 +33,8 @@ export async function stopThreads(runtime: SubagentRuntime, targets: readonly nu
|
|
|
32
33
|
const previousState = thread.state;
|
|
33
34
|
const wasQueued = previousState === "queued";
|
|
34
35
|
const wasActive = thread.lifecycleOperation !== undefined || ["queued", "running", "interrupting"].includes(previousState);
|
|
36
|
+
// The child already settled; only integration and delivery remained.
|
|
37
|
+
const wasSettling = thread.lifecycleOperation === "settle" && !thread.retired;
|
|
35
38
|
const stopVersion = ++thread.lifecycleVersion;
|
|
36
39
|
thread.lifecycleOperation = "stop";
|
|
37
40
|
thread.retired = true;
|
|
@@ -48,7 +51,7 @@ export async function stopThreads(runtime: SubagentRuntime, targets: readonly nu
|
|
|
48
51
|
: previousState === "parked" ? "Stopped by subagent_stop from an interrupted checkpoint."
|
|
49
52
|
: "Retired by subagent_stop.");
|
|
50
53
|
claimed.push({
|
|
51
|
-
runId, thread, run: monitor.findRun(runId), previousState, wasQueued, wasActive,
|
|
54
|
+
runId, thread, run: monitor.findRun(runId), previousState, wasQueued, wasActive, wasSettling,
|
|
52
55
|
generation: thread.generation,
|
|
53
56
|
controller: thread.queueController,
|
|
54
57
|
completion, releaseQuiescence,
|
|
@@ -77,6 +80,7 @@ export async function stopThreads(runtime: SubagentRuntime, targets: readonly nu
|
|
|
77
80
|
previousState,
|
|
78
81
|
wasQueued,
|
|
79
82
|
wasActive,
|
|
83
|
+
wasSettling,
|
|
80
84
|
generation,
|
|
81
85
|
controller,
|
|
82
86
|
completion,
|
|
@@ -105,7 +109,11 @@ export async function stopThreads(runtime: SubagentRuntime, targets: readonly nu
|
|
|
105
109
|
!runtime.settledRuns.has(runId)
|
|
106
110
|
) {
|
|
107
111
|
const prior = thread.lastResult;
|
|
108
|
-
|
|
112
|
+
// A settled child already produced its real result; stopping during
|
|
113
|
+
// integration retires the run but must not relabel finished work.
|
|
114
|
+
stoppedResult = wasSettling && prior
|
|
115
|
+
? { ...prior, runId }
|
|
116
|
+
: prior
|
|
109
117
|
? {
|
|
110
118
|
...prior,
|
|
111
119
|
exitCode: 1,
|
|
@@ -184,7 +192,7 @@ export async function stopThreads(runtime: SubagentRuntime, targets: readonly nu
|
|
|
184
192
|
}
|
|
185
193
|
releaseQuiescence();
|
|
186
194
|
});
|
|
187
|
-
stopped.push(`#${runId} ${thread.agentName}${wasQueued ? " (queued)" : wasActive ? "" : ` (${previousState})`}`);
|
|
195
|
+
stopped.push(`#${runId} ${thread.agentName}${wasQueued ? " (queued)" : wasSettling ? " (already finished; result kept)" : wasActive ? "" : ` (${previousState})`}`);
|
|
188
196
|
}
|
|
189
197
|
return { stopped, retainedIntegration, pendingIntegration, completionResults };
|
|
190
198
|
}
|
package/src/lifecycle/tools.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { findSessionFile, getProjectRoot, getResultOutput, isFailedResult, sessi
|
|
|
12
12
|
import { writeTempOwnerMarker } from "../isolation/temp-hygiene.ts";
|
|
13
13
|
import type { DispatchCore } from "./dispatch-core.ts";
|
|
14
14
|
import { awaitRunResults, WaitSchema } from "./await-results.ts";
|
|
15
|
-
import { cancelActiveWork } from "./cancellation.ts";
|
|
15
|
+
import { cancelActiveWork, isSettlingThread } from "./cancellation.ts";
|
|
16
16
|
import { stopThreads } from "./stop.ts";
|
|
17
17
|
import { formatCompletionBlock } from "../presentation/format.ts";
|
|
18
18
|
import { emptyUsage } from "../execution/run-control.ts";
|
|
@@ -337,7 +337,12 @@ export function registerLookupTools(pi: ExtensionAPI, runtime: SubagentRuntime,
|
|
|
337
337
|
...[...runtime.threads.values()]
|
|
338
338
|
.filter((thread) => thread.lifecycleOperation !== undefined || ["queued", "running", "interrupting"].includes(thread.state))
|
|
339
339
|
.map((thread) => thread.id),
|
|
340
|
-
])]
|
|
340
|
+
])].filter((id) => {
|
|
341
|
+
// A settling run's child is already done, so stop-all leaves its
|
|
342
|
+
// integration and real result alone; a retired run is already stopping.
|
|
343
|
+
const thread = runtime.threads.get(id);
|
|
344
|
+
return !thread || (!thread.retired && !isSettlingThread(thread));
|
|
345
|
+
})
|
|
341
346
|
: [...runtime.threads.keys()];
|
|
342
347
|
const requestedId = params.all === true ? undefined : parseExactRunId(params.id);
|
|
343
348
|
const targets = params.all === true
|