@ferris1225/pi-subagents 4.2.5 → 4.2.8

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,78 +1,81 @@
1
- /** Session-start recovery, stale-config migration, and widget installation. */
2
-
3
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
- import { existsSync } from "node:fs";
5
- import { loadConfig, saveConfig } from "./config.ts";
6
- import { availableModelsInScope, filterUnavailableModelOverrides } from "./models.ts";
7
- import { announceRecoveryRecords } from "./recovery.ts";
8
- import type { SubagentRuntime } from "./runtime.ts";
9
- import { installActiveRunsWidget } from "./widget.ts";
10
-
11
- /**
12
- * One-time-per-stale-override migration: keep agent model selections Pi still
13
- * reports as available, drop the rest back to dynamic main-model routing, and
14
- * tell the user what was removed. Saving the cleaned config is what makes it
15
- * one-time the dropped refs no longer exist to re-trigger the notice.
16
- */
17
- async function migrateUnavailableAgentModels(
18
- ctx: { ui: { notify: (message: string, kind: "info" | "warning" | "error") => void } } & Parameters<typeof availableModelsInScope>[0],
19
- runtime: SubagentRuntime,
20
- ): Promise<void> {
21
- try {
22
- const config = await loadConfig(runtime.configPath);
23
- const overrides = Object.entries(config.agentModels);
24
- if (overrides.length === 0) return;
25
- const { kept, dropped } = filterUnavailableModelOverrides(config.agentModels, availableModelsInScope(ctx));
26
- if (dropped.length === 0) return;
27
- await saveConfig({ ...config, agentModels: kept }, runtime.configPath);
28
- const list = dropped.map(({ agent, ref }) => `${agent}: ${ref}`).join(", ");
29
- ctx.ui.notify(
30
- `pi-subagents: removed stale agent model overrides that are no longer available (${list}). Those agents now follow the current main model; run /subagents-setup to re-pick.`,
31
- "warning",
32
- );
33
- } catch {
34
- /* migration failures are non-fatal */
35
- }
36
- }
37
-
38
- export function registerAnnouncements(pi: ExtensionAPI, runtime: SubagentRuntime): void {
39
- pi.on("session_start", async (_event, ctx) => {
40
- if (!existsSync(runtime.configPath)) {
41
- ctx.ui.notify(
42
- "pi-subagents: no configuration yet — run /subagents-setup to pick agents, models, and thinking strengths. Defaults (all built-in agents on the main model) apply until then.",
43
- "info",
44
- );
45
- }
46
- await announceRecoveryRecords(runtime.configPath, ctx);
47
- await migrateUnavailableAgentModels(ctx, runtime);
48
- // Restore starts at extension load and session_start fires right behind
49
- // it, so without this the notice reports whatever the race left behind.
50
- await runtime.durableRestore;
51
- if (!runtime.restoredNotified && runtime.restoredRunIds.length > 0) {
52
- runtime.restoredNotified = true;
53
- const ids = runtime.restoredRunIds.map((id) => `#${id}`).join(", ");
54
- ctx.ui.notify(
55
- `pi-subagents: restored ${runtime.restoredRunIds.length} interrupted thread${runtime.restoredRunIds.length === 1 ? "" : "s"} (${ids}) with retained context. subagent_control resume continues one.`,
56
- "info",
57
- );
58
- }
59
- if (ctx.mode !== "tui") return;
60
- installActiveRunsWidget(ctx);
61
- });
62
-
63
- // Compaction failures are otherwise silent in long orchestration sessions
64
- // where subagent results accumulate; aborted (user-cancelled) compactions
65
- // are deliberate and not worth a notice.
66
- pi.on("session_compact_failed", async (event, ctx) => {
67
- if (event.aborted && !event.errorMessage) return;
68
- const detail = event.errorMessage ? `: ${event.errorMessage}` : "";
69
- if (event.willRetry) {
70
- ctx.ui.notify(`pi-subagents: session compaction failed${detail} — retrying automatically.`, "warning");
71
- return;
72
- }
73
- ctx.ui.notify(
74
- `pi-subagents: session compaction failed${detail}. Long threads may hit context limits soon; run /compact to retry or trim old results.`,
75
- "error",
76
- );
77
- });
78
- }
1
+ /** Session-start recovery, stale-config migration, and progress-surface installation. */
2
+
3
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
+ import { existsSync } from "node:fs";
5
+ import { loadConfig, saveConfig } from "./config.ts";
6
+ import { availableModelsInScope, filterUnavailableModelOverrides } from "./models.ts";
7
+ import { announceRecoveryRecords } from "./recovery.ts";
8
+ import type { SubagentRuntime } from "./runtime.ts";
9
+ import { installActiveRunsStatus } from "./status.ts";
10
+ import { installActiveRunsWidget } from "./widget.ts";
11
+
12
+ /**
13
+ * One-time-per-stale-override migration: keep agent model selections Pi still
14
+ * reports as available, drop the rest back to dynamic main-model routing, and
15
+ * tell the user what was removed. Saving the cleaned config is what makes it
16
+ * one-time — the dropped refs no longer exist to re-trigger the notice.
17
+ */
18
+ async function migrateUnavailableAgentModels(
19
+ ctx: { ui: { notify: (message: string, kind: "info" | "warning" | "error") => void } } & Parameters<typeof availableModelsInScope>[0],
20
+ runtime: SubagentRuntime,
21
+ ): Promise<void> {
22
+ try {
23
+ const config = await loadConfig(runtime.configPath);
24
+ const overrides = Object.entries(config.agentModels);
25
+ if (overrides.length === 0) return;
26
+ const { kept, dropped } = filterUnavailableModelOverrides(config.agentModels, availableModelsInScope(ctx));
27
+ if (dropped.length === 0) return;
28
+ await saveConfig({ ...config, agentModels: kept }, runtime.configPath);
29
+ const list = dropped.map(({ agent, ref }) => `${agent}: ${ref}`).join(", ");
30
+ ctx.ui.notify(
31
+ `pi-subagents: removed stale agent model overrides that are no longer available (${list}). Those agents now follow the current main model; run /subagents-setup to re-pick.`,
32
+ "warning",
33
+ );
34
+ } catch {
35
+ /* migration failures are non-fatal */
36
+ }
37
+ }
38
+
39
+ export function registerAnnouncements(pi: ExtensionAPI, runtime: SubagentRuntime): void {
40
+ pi.on("session_start", async (_event, ctx) => {
41
+ if (!existsSync(runtime.configPath)) {
42
+ ctx.ui.notify(
43
+ "pi-subagents: no configuration yet — run /subagents-setup to pick agents, models, and thinking strengths. Defaults (all built-in agents on the main model) apply until then.",
44
+ "info",
45
+ );
46
+ }
47
+ await announceRecoveryRecords(runtime.configPath, ctx);
48
+ await migrateUnavailableAgentModels(ctx, runtime);
49
+ // Restore starts at extension load and session_start fires right behind
50
+ // it, so without this the notice reports whatever the race left behind.
51
+ await runtime.durableRestore;
52
+ if (!runtime.restoredNotified && runtime.restoredRunIds.length > 0) {
53
+ runtime.restoredNotified = true;
54
+ const ids = runtime.restoredRunIds.map((id) => `#${id}`).join(", ");
55
+ ctx.ui.notify(
56
+ `pi-subagents: restored ${runtime.restoredRunIds.length} interrupted thread${runtime.restoredRunIds.length === 1 ? "" : "s"} (${ids}) with retained context. subagent_control resume continues one.`,
57
+ "info",
58
+ );
59
+ }
60
+ // The footer status works in every UI host (TUI and RPC); the widget is TUI-only.
61
+ installActiveRunsStatus(ctx);
62
+ if (ctx.mode !== "tui") return;
63
+ installActiveRunsWidget(ctx);
64
+ });
65
+
66
+ // Compaction failures are otherwise silent in long orchestration sessions
67
+ // where subagent results accumulate; aborted (user-cancelled) compactions
68
+ // are deliberate and not worth a notice.
69
+ pi.on("session_compact_failed", async (event, ctx) => {
70
+ if (event.aborted && !event.errorMessage) return;
71
+ const detail = event.errorMessage ? `: ${event.errorMessage}` : "";
72
+ if (event.willRetry) {
73
+ ctx.ui.notify(`pi-subagents: session compaction failed${detail} — retrying automatically.`, "warning");
74
+ return;
75
+ }
76
+ ctx.ui.notify(
77
+ `pi-subagents: session compaction failed${detail}. Long threads may hit context limits soon; run /compact to retry or trim old results.`,
78
+ "error",
79
+ );
80
+ });
81
+ }