@ferris1225/pi-subagents 6.0.5 → 7.0.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.
@@ -1,36 +1,34 @@
1
- /** Session-start recovery, stale-model cleanup, and progress-surface installation. */
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
4
  import { loadConfig, saveConfig } from "../configuration/config.ts";
5
- import { filterUnavailableModelOverrides } from "../configuration/models.ts";
5
+ import { findModelByRef, modelRef } from "../configuration/models.ts";
6
6
  import { ensureDefaultConfig } from "../configuration/setup.ts";
7
7
  import { announceRecoveryRecords, relocateRecoveryManifest } from "../isolation/recovery.ts";
8
8
  import type { SubagentRuntime } from "../lifecycle/runtime.ts";
9
9
  import { installActiveRunsWidget } from "./widget.ts";
10
10
 
11
- /** Drop overrides that no authenticated model serves back to dynamic
12
- * main-model routing. A session model scope only narrows this session's
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 overrides = Object.entries(config.agentModels);
21
- if (overrides.length === 0) return;
22
- const { kept, dropped } = filterUnavailableModelOverrides(config.agentModels, ctx.modelRegistry.getAvailable());
23
- const rewritten = JSON.stringify(kept) !== JSON.stringify(config.agentModels);
24
- if (!rewritten && dropped.length === 0) return;
25
- await saveConfig({ ...config, agentModels: kept }, runtime.configPath);
26
- if (dropped.length === 0) return;
27
- const list = dropped.map(({ agent, ref }) => `${agent}: ${ref}`).join(", ");
18
+ if (!config.model) return;
19
+ const selected = findModelByRef(ctx.modelRegistry.getAvailable(), config.model);
20
+ const liveRef = selected ? modelRef(selected) : undefined;
21
+ if (liveRef === config.model) return;
22
+ if (liveRef) {
23
+ await saveConfig({ ...config, model: liveRef }, runtime.configPath);
24
+ return;
25
+ }
28
26
  ctx.ui.notify(
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.`,
27
+ `pi-subagents: worker model ${config.model} is unavailable. Its setting is preserved and dispatch is paused. Restore availability or run /subagents-setup to choose another.`,
30
28
  "warning",
31
29
  );
32
30
  } catch {
33
- /* stale-model cleanup is non-fatal */
31
+ /* availability notices are non-fatal */
34
32
  }
35
33
  }
36
34
 
@@ -45,7 +43,7 @@ export function registerAnnouncements(pi: ExtensionAPI, runtime: SubagentRuntime
45
43
  // must not prevent the rest of the session UI from being installed.
46
44
  ctx.ui.notify(`pi-subagents: recovery inspection failed; continuing startup: ${error instanceof Error ? error.message : String(error)}`, "warning");
47
45
  }
48
- await removeUnavailableAgentModels(ctx, runtime);
46
+ await checkWorkerModel(ctx, runtime);
49
47
  // Bootstrap also runs on session_start; wait so this notice sees restored
50
48
  // threads instead of racing an empty list.
51
49
  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})` : ""}${fallbackNote}${runNote}`,
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 === "artisan") {
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 sub-agent could not complete this task: ${cause}${retry}. Earlier edits and any retained result/session artifacts remain available. Main must inspect that work and finish with its own tools; do not re-dispatch this phase.`;
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
@@ -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
- }