@ferris1225/pi-subagents 6.0.5 → 7.0.1
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 +56 -0
- package/README.md +233 -266
- package/index.ts +13 -12
- package/package.json +11 -10
- package/src/configuration/config.ts +76 -158
- package/src/configuration/models.ts +15 -85
- package/src/configuration/setup.ts +82 -165
- package/src/configuration/ui.ts +97 -178
- package/src/delegation/agents.ts +7 -7
- package/src/delegation/builtin-agents.ts +11 -30
- package/src/delegation/dispatch.ts +18 -28
- package/src/delegation/orchestration.ts +26 -0
- package/src/delegation/prompt.ts +13 -19
- package/src/execution/cli-run.ts +9 -7
- package/src/execution/run-control.ts +5 -7
- package/src/execution/spawn.ts +36 -160
- package/src/isolation/git-command.ts +2 -2
- package/src/isolation/recovery.ts +8 -24
- package/src/isolation/temp-hygiene.ts +1 -1
- package/src/lifecycle/completion.ts +2 -13
- package/src/lifecycle/durable.ts +17 -34
- package/src/lifecycle/stop.ts +2 -2
- package/src/lifecycle/thread-lifecycle.ts +7 -7
- package/src/lifecycle/thread-restore.ts +4 -6
- package/src/lifecycle/thread-shared.ts +12 -20
- package/src/lifecycle/tools.ts +2 -4
- package/src/presentation/announcements.ts +17 -23
- package/src/presentation/format.ts +5 -6
- package/src/presentation/monitor.ts +2 -7
- package/src/configuration/role-migration.ts +0 -39
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
readThreadRecords,
|
|
12
12
|
removeThreadRecord,
|
|
13
13
|
restoredResultFromSummary,
|
|
14
|
-
threadRecordIdentity,
|
|
15
14
|
type ThreadRecord,
|
|
16
15
|
} from "./durable.ts";
|
|
17
16
|
import { monitor } from "../presentation/monitor.ts";
|
|
@@ -38,7 +37,7 @@ import { installThreadLifecycle } from "./thread-lifecycle.ts";
|
|
|
38
37
|
async function discardRestoredRecord(runtime: SubagentRuntime, record: ThreadRecord): Promise<void> {
|
|
39
38
|
await discardRecordArtifacts(record);
|
|
40
39
|
if (record.sessionDir) runtime.sessionDirs.delete(record.sessionDir);
|
|
41
|
-
await removeThreadRecord(runtime.configPath,
|
|
40
|
+
await removeThreadRecord(runtime.configPath, record.durableId, record.cwd).catch(() => undefined);
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
function createRestoredThread(
|
|
@@ -48,7 +47,7 @@ function createRestoredThread(
|
|
|
48
47
|
state: ThreadState,
|
|
49
48
|
): SubagentThread {
|
|
50
49
|
const thread: SubagentThread = {
|
|
51
|
-
durableId:
|
|
50
|
+
durableId: record.durableId,
|
|
52
51
|
id: record.runId,
|
|
53
52
|
generation: record.generation,
|
|
54
53
|
agentName: record.agentName,
|
|
@@ -80,15 +79,14 @@ function belongsToSessionProject(configPath: string, cwd: string, record: Thread
|
|
|
80
79
|
* Other projects' parked threads stay on disk for their own window; this process
|
|
81
80
|
* must not restore them or kill their children. Records with a live owner or
|
|
82
81
|
* child are left alone; missing session files do not discard isolated
|
|
83
|
-
* edits.
|
|
84
|
-
* managed artifacts. */
|
|
82
|
+
* edits. Settled records are removed with their managed artifacts. */
|
|
85
83
|
export async function restoreDurableThreads(runtime: SubagentRuntime, cwd: string): Promise<number[]> {
|
|
86
84
|
const records = await readThreadRecords(runtime.configPath);
|
|
87
85
|
const restoredIds: number[] = [];
|
|
88
86
|
const localRecords = records.filter((record) => belongsToSessionProject(runtime.configPath, cwd, record));
|
|
89
87
|
for (const record of localRecords) monitor.ensureNextIdAbove(record.runId);
|
|
90
88
|
for (let record of localRecords) {
|
|
91
|
-
const identity =
|
|
89
|
+
const identity = record.durableId;
|
|
92
90
|
if ([...runtime.threads.values()].some((thread) => thread.durableId === identity)) continue;
|
|
93
91
|
// Another Pi window may own this checkpoint, and PID reuse means a live
|
|
94
92
|
// recorded child is not proof of ownership. Never kill either on restore.
|
|
@@ -5,8 +5,8 @@ import { realpath } from "node:fs/promises";
|
|
|
5
5
|
import { join, resolve } from "node:path";
|
|
6
6
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import type { AgentConfig } from "../delegation/agents.ts";
|
|
8
|
-
import {
|
|
9
|
-
import { removeThreadRecord, threadRecordFromThread,
|
|
8
|
+
import { BUILTIN_AGENT_NAMES, type AgentName, type SubagentsConfig, type ThinkingLevel } from "../configuration/config.ts";
|
|
9
|
+
import { removeThreadRecord, threadRecordFromThread, upsertThreadRecord } from "./durable.ts";
|
|
10
10
|
import {
|
|
11
11
|
availableModelsInScope,
|
|
12
12
|
currentModelRef,
|
|
@@ -32,7 +32,7 @@ export function quiesced(promise: Promise<unknown>, timeoutMs: number = CONTROL_
|
|
|
32
32
|
promise.then(() => true, () => true),
|
|
33
33
|
new Promise<boolean>((resolve) => {
|
|
34
34
|
const timer = setTimeout(() => resolve(false), timeoutMs);
|
|
35
|
-
|
|
35
|
+
timer.unref();
|
|
36
36
|
}),
|
|
37
37
|
]);
|
|
38
38
|
}
|
|
@@ -98,7 +98,7 @@ export function persistThreadCheckpoint(
|
|
|
98
98
|
const record = threadRecordFromThread(thread, state);
|
|
99
99
|
const write = state === "parked"
|
|
100
100
|
? upsertThreadRecord(runtime.configPath, record)
|
|
101
|
-
: removeThreadRecord(runtime.configPath,
|
|
101
|
+
: removeThreadRecord(runtime.configPath, record.durableId, thread.cwd);
|
|
102
102
|
void write.catch(() => undefined);
|
|
103
103
|
}
|
|
104
104
|
|
|
@@ -143,9 +143,8 @@ export interface ThreadLifecycleDeps {
|
|
|
143
143
|
|
|
144
144
|
interface DispatchModelRoute {
|
|
145
145
|
agent: AgentConfig;
|
|
146
|
-
|
|
146
|
+
error?: string;
|
|
147
147
|
thinkingLevel: ThinkingLevel;
|
|
148
|
-
thinkingLevelForModel: (ref?: string) => ThinkingLevel;
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
export function resolveDispatchModelRoute(
|
|
@@ -153,28 +152,21 @@ export function resolveDispatchModelRoute(
|
|
|
153
152
|
config: SubagentsConfig,
|
|
154
153
|
ctx: ExtensionContext,
|
|
155
154
|
): DispatchModelRoute {
|
|
155
|
+
if (!(BUILTIN_AGENT_NAMES as readonly string[]).includes(agent.name)) throw new Error(`Unknown subagent role: ${agent.name}`);
|
|
156
|
+
const settings = config[agent.name as AgentName];
|
|
156
157
|
const availableModels = availableModelsInScope(ctx);
|
|
157
158
|
const mainRef = currentModelRef(ctx);
|
|
158
159
|
const route = resolveAgentModelRoute({
|
|
159
|
-
selectedRef:
|
|
160
|
+
selectedRef: settings.model,
|
|
160
161
|
mainRef,
|
|
161
162
|
availableRefs: availableModels.map(modelRef),
|
|
162
163
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const preferred =
|
|
166
|
-
config.agentThinkingLevels[agent.name] ?? roleThinkingLevel(agent.name);
|
|
167
|
-
const thinkingLevelForModel = (ref?: string): ThinkingLevel => {
|
|
168
|
-
const model = ref === mainRef && ctx.model
|
|
169
|
-
? ctx.model
|
|
170
|
-
: findModelByRef(availableModels, ref);
|
|
171
|
-
return resolveThinkingLevel(model, preferred);
|
|
172
|
-
};
|
|
164
|
+
const model = route.primaryRef === mainRef && ctx.model
|
|
165
|
+
? ctx.model : findModelByRef(availableModels, route.primaryRef);
|
|
173
166
|
return {
|
|
174
167
|
agent: { ...agent, model: route.primaryRef },
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
thinkingLevelForModel,
|
|
168
|
+
thinkingLevel: resolveThinkingLevel(model, settings.thinking),
|
|
169
|
+
...(route.unavailableSelectedRef ? { error: `${agent.name} model ${route.unavailableSelectedRef} is unavailable in this session. Dispatch paused; restore availability or choose another model with /subagents-setup. No main-model worker was started.` } : {}),
|
|
178
170
|
};
|
|
179
171
|
}
|
|
180
172
|
|
package/src/lifecycle/tools.ts
CHANGED
|
@@ -189,7 +189,7 @@ export function registerLookupTools(pi: ExtensionAPI, runtime: SubagentRuntime,
|
|
|
189
189
|
pi.registerTool({
|
|
190
190
|
name: "subagent_message",
|
|
191
191
|
label: "Subagent Message",
|
|
192
|
-
description: "Steer a running subagent, or continue a successfully completed run with a new bounded step in the same role and workspace. Steering waits for the child's RPC acknowledgement and reports queued
|
|
192
|
+
description: "Steer a running subagent, or continue a successfully completed run with a new bounded step in the same role and workspace. Steering waits for the child's RPC acknowledgement and reports queued or handled by an input hook; receipt is not proof of model execution, and status retains the latest acknowledgement. A continuation chooses its history with the context parameter. Use wait:true to receive its result in this call; one-shot print/JSON sessions wait by default.",
|
|
193
193
|
exposure: "model-only",
|
|
194
194
|
executionMode: "parallel",
|
|
195
195
|
parameters: Type.Object({
|
|
@@ -210,9 +210,7 @@ export function registerLookupTools(pi: ExtensionAPI, runtime: SubagentRuntime,
|
|
|
210
210
|
thread.lastSteering = { ...receipt, message: formatTaskSummary(params.message, 160, false) };
|
|
211
211
|
const status = receipt.disposition === "queued"
|
|
212
212
|
? `Received by #${thread.id} · queued for the next steering boundary. Model execution is not yet confirmed.`
|
|
213
|
-
:
|
|
214
|
-
? `Received by #${thread.id} · handled by an input hook. Delivery to the model is not confirmed.`
|
|
215
|
-
: `Accepted by #${thread.id} · queue state unconfirmed. Model execution is not yet confirmed.`;
|
|
213
|
+
: `Received by #${thread.id} · handled by an input hook. Delivery to the model is not confirmed.`;
|
|
216
214
|
monitor.setActivity(thread.id, `steering ${receipt.disposition}`);
|
|
217
215
|
return {
|
|
218
216
|
content: [{ type: "text" as const, text: `${status}${receipt.requestId ? `\nChild RPC acknowledgement: ${receipt.requestId}` : ""}` }],
|
|
@@ -1,36 +1,31 @@
|
|
|
1
|
-
/** Session-start recovery,
|
|
1
|
+
/** Session-start recovery, worker availability, and progress-surface installation. */
|
|
2
2
|
|
|
3
3
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { BUILTIN_AGENT_NAMES, loadConfig } from "../configuration/config.ts";
|
|
5
|
+
import { findModelByRef } from "../configuration/models.ts";
|
|
6
6
|
import { ensureDefaultConfig } from "../configuration/setup.ts";
|
|
7
|
-
import { announceRecoveryRecords
|
|
7
|
+
import { announceRecoveryRecords } from "../isolation/recovery.ts";
|
|
8
8
|
import type { SubagentRuntime } from "../lifecycle/runtime.ts";
|
|
9
9
|
import { installActiveRunsWidget } from "./widget.ts";
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
* routing, so it never deletes a persisted override. */
|
|
14
|
-
async function removeUnavailableAgentModels(
|
|
11
|
+
/** Preserve the worker choice during outages instead of spending main-model quota. */
|
|
12
|
+
async function checkWorkerModel(
|
|
15
13
|
ctx: Pick<ExtensionContext, "ui" | "modelRegistry">,
|
|
16
14
|
runtime: SubagentRuntime,
|
|
17
15
|
): Promise<void> {
|
|
18
16
|
try {
|
|
19
17
|
const config = await loadConfig(runtime.configPath);
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
`pi-subagents: removed model overrides that are no longer available (${list}). Those roles now follow the main model; run /subagents-setup to choose another.`,
|
|
30
|
-
"warning",
|
|
31
|
-
);
|
|
18
|
+
const models = ctx.modelRegistry.getAvailable();
|
|
19
|
+
for (const role of BUILTIN_AGENT_NAMES) {
|
|
20
|
+
const ref = config[role].model;
|
|
21
|
+
if (!ref || findModelByRef(models, ref)) continue;
|
|
22
|
+
ctx.ui.notify(
|
|
23
|
+
`pi-subagents: ${role} model ${ref} is unavailable. Its setting is preserved and dispatch is paused for this role. Restore availability or run /subagents-setup to choose another.`,
|
|
24
|
+
"warning",
|
|
25
|
+
);
|
|
26
|
+
}
|
|
32
27
|
} catch {
|
|
33
|
-
/*
|
|
28
|
+
/* availability notices are non-fatal */
|
|
34
29
|
}
|
|
35
30
|
}
|
|
36
31
|
|
|
@@ -38,14 +33,13 @@ export function registerAnnouncements(pi: ExtensionAPI, runtime: SubagentRuntime
|
|
|
38
33
|
pi.on("session_start", async (_event, ctx) => {
|
|
39
34
|
await ensureDefaultConfig(ctx, runtime.configPath);
|
|
40
35
|
try {
|
|
41
|
-
await relocateRecoveryManifest(runtime.configPath);
|
|
42
36
|
await announceRecoveryRecords(runtime.configPath, ctx);
|
|
43
37
|
} catch (error) {
|
|
44
38
|
// Recovery readers must fail closed for cleanup, but a failed notice
|
|
45
39
|
// must not prevent the rest of the session UI from being installed.
|
|
46
40
|
ctx.ui.notify(`pi-subagents: recovery inspection failed; continuing startup: ${error instanceof Error ? error.message : String(error)}`, "warning");
|
|
47
41
|
}
|
|
48
|
-
await
|
|
42
|
+
await checkWorkerModel(ctx, runtime);
|
|
49
43
|
// Bootstrap also runs on session_start; wait so this notice sees restored
|
|
50
44
|
// threads instead of racing an empty list.
|
|
51
45
|
await runtime.durableRestore;
|
|
@@ -112,16 +112,13 @@ export function formatCompletionBlock(
|
|
|
112
112
|
const usage = formatUsage(result.usage);
|
|
113
113
|
const output = getResultOutput(result);
|
|
114
114
|
const overflow = inlineOverflow(output, maxResultLines);
|
|
115
|
-
const fallbackNote = result.modelFallbackFrom
|
|
116
|
-
? ` (selected model ${result.modelFallbackFrom} failed → main ${result.model ?? "dynamic default"})`
|
|
117
|
-
: "";
|
|
118
115
|
const runNote = result.runId !== undefined ? ` · run #${result.runId}` : "";
|
|
119
116
|
// A short task-derived label, not the task itself: the parent authored the
|
|
120
117
|
// task and still has it in context, but a wide fan-out of same-agent runs
|
|
121
118
|
// needs more than a run id to tell completions apart.
|
|
122
119
|
const label = shrinkRunLabel(runLabel(result.task), COMPLETION_LABEL_MAX);
|
|
123
120
|
const lines = [
|
|
124
|
-
`### [${result.agent}${label ? `·${label}` : ""}] ${status}${usage ? ` (${usage})` : ""}${
|
|
121
|
+
`### [${result.agent}${label ? `·${label}` : ""}] ${status}${usage ? ` (${usage})` : ""}${runNote}`,
|
|
125
122
|
"",
|
|
126
123
|
];
|
|
127
124
|
if (result.isolation === "worktree") {
|
|
@@ -167,14 +164,16 @@ export function formatCompletionBlock(
|
|
|
167
164
|
);
|
|
168
165
|
}
|
|
169
166
|
if (failed && isModelLevelFailure(result)) lines.push("", modelLevelTakeoverNote(result));
|
|
167
|
+
if (!failed && result.agent === "worker") {
|
|
168
|
+
lines.push("", "Review handoff: main. Worker completion is not review approval. Inspect the actual diff, affected callers, acceptance criteria, and check evidence. Send confirmed corrections to the owning worker with subagent_message; main owns acceptance and release.");
|
|
169
|
+
}
|
|
170
170
|
return lines.join("\n");
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
/** A terminal model failure hands the unfinished task to main, not another run. */
|
|
174
174
|
function modelLevelTakeoverNote(result: SingleResult): string {
|
|
175
|
-
const retry = result.modelFallbackFrom ? ", and the current main model also failed" : "";
|
|
176
175
|
const cause = getResultError(result) ?? "its model was unavailable or failed";
|
|
177
|
-
return `The
|
|
176
|
+
return `The worker could not complete this task: ${cause}. No automatic model upgrade was attempted. Earlier edits and retained result/session artifacts remain available. Main must inspect that work and decide how to proceed; do not repeat this failed phase automatically.`;
|
|
178
177
|
}
|
|
179
178
|
|
|
180
179
|
/** Resolve a run-id request to actual ids: an exact numeric match always wins
|
|
@@ -161,7 +161,7 @@ function tailGraphemes(segments: string[], maxWidth: number): string {
|
|
|
161
161
|
* One-line task preview, capped by `maxWidth` display columns (default 80).
|
|
162
162
|
* `keysOnly` (default): extracted key fragments (paths, quoted phrases,
|
|
163
163
|
* symbols) are shown bare — the agent name is already displayed next to the
|
|
164
|
-
* task line, so templated prose ("
|
|
164
|
+
* task line, so templated prose ("researcher: trace how ...") adds nothing.
|
|
165
165
|
* `keysOnly: false` keeps the prose as `head…tail` (used for completion
|
|
166
166
|
* messages, where the Task line is the reader's only context).
|
|
167
167
|
* Grapheme-safe — CJK, ZWJ emoji and combining sequences are never split.
|
|
@@ -303,13 +303,8 @@ export function formatDuration(ms: number): string {
|
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
function elapsedMilliseconds(run: RunView, now: number = Date.now()): number {
|
|
306
|
-
let elapsed = run.elapsedMs
|
|
306
|
+
let elapsed = run.elapsedMs;
|
|
307
307
|
if (run.activeSince !== undefined) elapsed += Math.max(0, now - run.activeSince);
|
|
308
|
-
// Keep formatting tolerant of older/synthetic RunView values that predate
|
|
309
|
-
// segmented timing and carry only startedAt/endedAt.
|
|
310
|
-
if (elapsed === 0 && run.startedAt !== undefined && run.activeSince === undefined) {
|
|
311
|
-
elapsed = Math.max(0, (run.endedAt ?? now) - run.startedAt);
|
|
312
|
-
}
|
|
313
308
|
return elapsed;
|
|
314
309
|
}
|
|
315
310
|
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/** One-time data migration for the role rename. Runtime dispatch accepts only
|
|
2
|
-
* current catalog names; these helpers are used only at storage boundaries. */
|
|
3
|
-
|
|
4
|
-
export function migrateStoredAgentName(name: string): string {
|
|
5
|
-
if (name === "reviewer" || name === "critic" || name === "skeptic") return "sentinel";
|
|
6
|
-
return name;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** Valid explicit new settings win; old keys disappear after persistence. */
|
|
10
|
-
export function migrateStoredRoleKeys<T>(settings: Record<string, T>): Record<string, T> {
|
|
11
|
-
const migrated = { ...settings };
|
|
12
|
-
for (const [name, value] of Object.entries(settings)) {
|
|
13
|
-
const current = migrateStoredAgentName(name);
|
|
14
|
-
if (current === name) continue;
|
|
15
|
-
if (!Object.hasOwn(migrated, current)) migrated[current] = value;
|
|
16
|
-
delete migrated[name];
|
|
17
|
-
}
|
|
18
|
-
return migrated;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function migrateField(value: unknown, key: string): boolean {
|
|
22
|
-
if (!value || typeof value !== "object") return false;
|
|
23
|
-
const record = value as Record<string, unknown>;
|
|
24
|
-
if (typeof record[key] !== "string") return false;
|
|
25
|
-
const name = record[key].trim();
|
|
26
|
-
const current = migrateStoredAgentName(name);
|
|
27
|
-
if (current === name) return false;
|
|
28
|
-
record[key] = current;
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Thread manifests retain their ids, leases, and recovery paths. */
|
|
33
|
-
export function migrateStoredRecordRoles(value: unknown): boolean {
|
|
34
|
-
if (!value || typeof value !== "object") return false;
|
|
35
|
-
const summary = (value as { resultSummary?: unknown }).resultSummary;
|
|
36
|
-
const threadChanged = migrateField(value, "agentName");
|
|
37
|
-
const summaryChanged = migrateField(summary, "agent");
|
|
38
|
-
return threadChanged || summaryChanged;
|
|
39
|
-
}
|