@henryqw/pi-subagent 27.14.3 → 27.15.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/README.md +7 -1
- package/dist/composition.js +1 -0
- package/dist/herdr-runtime.js +2 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +21 -9
- package/dist/launch-runtime.d.ts +2 -0
- package/dist/launch-runtime.js +11 -1
- package/dist/runner.d.ts +2 -0
- package/dist/runner.js +1 -0
- package/extensions/isolated.ts +11 -1
- package/extensions/subagent.ts +8 -1
- package/extensions/task-model-fallback.ts +29 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -190,6 +190,12 @@ The built-in reviewer answers exactly `PASS` or gives prioritized findings in th
|
|
|
190
190
|
|
|
191
191
|
The built-in reviewer and scout include `git_read`; existing user reviewers and scouts must add it to `tools`. No additional extension or Bash access is necessary. See [Reviewer Git inspection](./docs/orchestration.md#reviewer-git-inspection) for operations, parameters, limits, and Git requirements.
|
|
192
192
|
|
|
193
|
+
When a direct or isolated worker starts with a configured fallback, Pi Subagent warns in the parent session that created it. The warning names the profile, selected `provider/model`, and thinking level. It uses the user interface (UI) when available. Without a UI, it adds a displayed parent-session message that does not start a turn.
|
|
194
|
+
|
|
195
|
+
The same profile and fallback route warn once in the active parent session. A session change resets these warnings. A different fallback model or thinking level gets a new warning. Dry runs, preflight, unused launch preparation, and cancelled or replaced sessions do not consume warnings. Isolated text and judgment workers report fallback use on their first child activity.
|
|
196
|
+
|
|
197
|
+
Route selection does not change. An available primary produces no fallback warning. A direct `model` override produces no fallback warning because it replaces the configured model. It still keeps the resolved thinking level.
|
|
198
|
+
|
|
193
199
|
Children load only declared resources and required adapters. Roles must list their model provider extension. `codemode` requires both `builtin:codemode` in `extensions` and `codemode` in `tools`. Missing Skills, tools, MCP servers, Roles, or routes fail before productive work. Main-only delegation/recovery tools and `ask_question` stay unavailable to children.
|
|
194
200
|
|
|
195
201
|
Read [Role and resource policy](./docs/orchestration.md#role-and-resource-policy) for extension exposure, MCP validation, OAuth constraints, and child budgets. Project MCP overrides cannot change a Role's global allowlist or exposure.
|
|
@@ -200,7 +206,7 @@ Read [Role and resource policy](./docs/orchestration.md#role-and-resource-policy
|
|
|
200
206
|
| --- | --- | --- |
|
|
201
207
|
| `loadRoleCatalog`, `findRole`, `parseRoleName`, `parseRoleDefaults` | functions | Load, validate, and select Roles with shared defaults and per-file errors. |
|
|
202
208
|
| `registerRoleDefaultsReporting(pi, agentDir?)` | function | Report problems at session start, once per session. Returns `report(ctx)`; call before a lazy `loadRoleCatalog`. |
|
|
203
|
-
| `resolveRoleSkills`, `resolveRoleLaunch`, `resolveConfiguredRoleLaunch` | functions | Resolve effective Pi resources and model routes. |
|
|
209
|
+
| `resolveRoleSkills`, `resolveRoleLaunch`, `resolveConfiguredRoleLaunch` | functions | Resolve effective Pi resources and model routes. Role launch results include optional `fallback` identity without a notification. |
|
|
204
210
|
| `prepareRoleLaunch`, `finalizeRoleLaunch` | functions | Prepare Role prompts, arguments, and tool policy. |
|
|
205
211
|
| `createEphemeralSubagentExecutor` | function | Run bounded no-session Pi children through a FIFO pool. |
|
|
206
212
|
| `createChildWorktree`, `finalizeChildWorktree` | functions | Create and conservatively finalize child worktrees. |
|
package/dist/composition.js
CHANGED
|
@@ -88,6 +88,7 @@ export function createExactJudgmentExecutor(executor) {
|
|
|
88
88
|
};
|
|
89
89
|
const result = await executor.run({
|
|
90
90
|
signal: context.signal,
|
|
91
|
+
onActivity: input.launch.onFallbackUse,
|
|
91
92
|
prepare: async () => ({ launch, task, cwd: input.cwd }),
|
|
92
93
|
});
|
|
93
94
|
context.signal.throwIfAborted();
|
package/dist/herdr-runtime.js
CHANGED
|
@@ -882,11 +882,12 @@ export class HerdrHostRuntime {
|
|
|
882
882
|
const agent = parseAgent(parseJsonObject(response.stdout, "Herdr agent start response"), allocation, ["agent_started"]);
|
|
883
883
|
if (!agent.interactiveReady || agent.status !== "idle")
|
|
884
884
|
throw new Error("Started Herdr agent is not exactly ready and idle.");
|
|
885
|
-
return { kind: "agent", outcome: "owned" };
|
|
886
885
|
}
|
|
887
886
|
catch (error) {
|
|
888
887
|
return { kind: "agent", outcome: "unknown", failure: safeText(error), possibleResources: [allocation.agentName, allocation.paneId] };
|
|
889
888
|
}
|
|
889
|
+
launch.onFallbackUse?.();
|
|
890
|
+
return { kind: "agent", outcome: "owned" };
|
|
890
891
|
});
|
|
891
892
|
}
|
|
892
893
|
async reconcileDeliveredPrompt(input, allocation, context, prompt, promptMayBeInFlight = true) {
|
package/dist/index.d.ts
CHANGED
|
@@ -59,10 +59,16 @@ export interface PiLaunch {
|
|
|
59
59
|
env: Record<string, string>;
|
|
60
60
|
args: string[];
|
|
61
61
|
}
|
|
62
|
+
export type TaskModelFallback = Readonly<{
|
|
63
|
+
profileName: ProfileName;
|
|
64
|
+
model: string;
|
|
65
|
+
thinkingLevel: ThinkingLevel;
|
|
66
|
+
}>;
|
|
62
67
|
export interface ResolvedRoleLaunch extends PiLaunch {
|
|
63
68
|
model: AvailableModel;
|
|
64
69
|
thinkingLevel: ThinkingLevel;
|
|
65
70
|
missingSkills: string[];
|
|
71
|
+
fallback?: TaskModelFallback;
|
|
66
72
|
}
|
|
67
73
|
export interface PreparedRoleLaunch extends ResolvedRoleLaunch {
|
|
68
74
|
role: RoleName;
|
|
@@ -143,7 +149,7 @@ export declare function loadRoleCatalog(agentDir?: string): RoleCatalog;
|
|
|
143
149
|
export declare function findRole(catalog: RoleCatalog, name: RoleName): Role;
|
|
144
150
|
type TaskRouteContext = Parameters<typeof resolveTaskModelRoute>[0];
|
|
145
151
|
type RoleLaunchContext = TaskRouteContext & Pick<ExtensionContext, "isProjectTrusted">;
|
|
146
|
-
export declare function resolveTaskRoute(ctx: TaskRouteContext, profileName: ProfileName, agentDir?: string): ResolvedTaskRoute;
|
|
152
|
+
export declare function resolveTaskRoute(ctx: TaskRouteContext, profileName: ProfileName, agentDir?: string, onFallback?: (profileName: ProfileName, route: ResolvedTaskRoute) => void): ResolvedTaskRoute;
|
|
147
153
|
export declare function resolveRoleSkills(pi: Pick<ExtensionAPI, "getCommands">, role: Role): ResolvedRoleSkills;
|
|
148
154
|
/** Resolve all enabled package resources selected by one Role's extension sources. */
|
|
149
155
|
export declare function resolveRolePackageResources(role: Role, ctx: Pick<ExtensionContext, "cwd" | "isProjectTrusted">): Promise<{
|
package/dist/index.js
CHANGED
|
@@ -397,18 +397,21 @@ export function findRole(catalog, name) {
|
|
|
397
397
|
throw new Error(`Subagent role ${name} is unavailable: ${invalid.map(({ message }) => message).join("; ")}`);
|
|
398
398
|
throw new Error(`Unknown Subagent role: ${name}. Available roles: ${catalog.roles.map((candidate) => candidate.name).join(", ") || "none"}.${catalog.errors.length ? ` ${catalog.errors.length} invalid Role file(s); run /subagent roles.` : ""}`);
|
|
399
399
|
}
|
|
400
|
-
export function resolveTaskRoute(ctx, profileName, agentDir = getAgentDir()) {
|
|
400
|
+
export function resolveTaskRoute(ctx, profileName, agentDir = getAgentDir(), onFallback) {
|
|
401
401
|
// A disabled config throws with the path and the problems.
|
|
402
402
|
const config = loadTaskModelsConfig(agentDir).value;
|
|
403
|
-
return resolveConfiguredRoute(ctx, profileName, config.profiles[profileName]);
|
|
403
|
+
return resolveConfiguredRoute(ctx, profileName, config.profiles[profileName], onFallback);
|
|
404
404
|
}
|
|
405
|
-
function resolveConfiguredRoute(ctx, profileName, profile) {
|
|
405
|
+
function resolveConfiguredRoute(ctx, profileName, profile, onFallback) {
|
|
406
406
|
if (!profile)
|
|
407
407
|
throw new Error(`No ${profileName} task model profile is configured. Run /task-models.`);
|
|
408
408
|
for (const route of orderedProfileRoutes(profile)) {
|
|
409
409
|
const resolved = resolveTaskModelRoute(ctx, route);
|
|
410
|
-
if (resolved)
|
|
410
|
+
if (resolved) {
|
|
411
|
+
if (route === profile.fallback)
|
|
412
|
+
onFallback?.(profileName, resolved);
|
|
411
413
|
return resolved;
|
|
414
|
+
}
|
|
412
415
|
}
|
|
413
416
|
throw new Error(`No usable ${profileName} task model route. Run /task-models.`);
|
|
414
417
|
}
|
|
@@ -509,12 +512,17 @@ function prepareRoleLaunchFromSkills(ctx, input, skills) {
|
|
|
509
512
|
function prepareResolvedRoleLaunch(pi, ctx, input) {
|
|
510
513
|
const { task, modelClass, agentDir, ...launchInput } = input;
|
|
511
514
|
const selectedClass = modelClass ?? input.role.modelClass;
|
|
512
|
-
|
|
515
|
+
let fallback;
|
|
516
|
+
const onFallback = (profileName, route) => {
|
|
517
|
+
fallback = { profileName, model: modelReference(route.model), thinkingLevel: route.thinkingLevel };
|
|
518
|
+
};
|
|
519
|
+
const prepared = prepareRoleLaunchFromSkills(ctx, {
|
|
513
520
|
...launchInput,
|
|
514
521
|
route: selectedClass === undefined
|
|
515
|
-
? resolveConfiguredTaskRoute(ctx, task, agentDir)
|
|
516
|
-
: resolveTaskRoute(ctx, selectedClass, agentDir),
|
|
522
|
+
? resolveConfiguredTaskRoute(ctx, task, agentDir, undefined, onFallback)
|
|
523
|
+
: resolveTaskRoute(ctx, selectedClass, agentDir, onFallback),
|
|
517
524
|
}, resolveRoleSkills(pi, input.role));
|
|
525
|
+
return { ...prepared, ...(fallback ? { fallback } : {}) };
|
|
518
526
|
}
|
|
519
527
|
export function resolveRoleLaunch(pi, ctx, input) {
|
|
520
528
|
return finalizeRoleLaunch(prepareResolvedRoleLaunch(pi, ctx, input));
|
|
@@ -552,9 +560,12 @@ export async function resolveConfiguredRoleLaunch(pi, ctx, input) {
|
|
|
552
560
|
...namedSkills,
|
|
553
561
|
paths: [...new Set([...namedSkills.paths, ...resources.skills])],
|
|
554
562
|
};
|
|
563
|
+
let fallback;
|
|
555
564
|
const prepared = prepareRoleLaunchFromSkills(ctx, {
|
|
556
565
|
role: effectiveRole,
|
|
557
|
-
route: resolveTaskRoute(ctx, input.modelClass)
|
|
566
|
+
route: resolveTaskRoute(ctx, input.modelClass, undefined, (profileName, route) => {
|
|
567
|
+
fallback = { profileName, model: modelReference(route.model), thinkingLevel: route.thinkingLevel };
|
|
568
|
+
}),
|
|
558
569
|
}, skills);
|
|
559
570
|
assertNoMissingRoleSkills(effectiveRole, prepared);
|
|
560
571
|
const args = [
|
|
@@ -564,7 +575,7 @@ export async function resolveConfiguredRoleLaunch(pi, ctx, input) {
|
|
|
564
575
|
...resources.prompts.flatMap((path) => ["--prompt-template", path]),
|
|
565
576
|
...resources.themes.flatMap((path) => ["--theme", path]),
|
|
566
577
|
];
|
|
567
|
-
return { ...prepared, args, promptArgIndex: args.length };
|
|
578
|
+
return { ...prepared, args, promptArgIndex: args.length, ...(fallback ? { fallback } : {}) };
|
|
568
579
|
}
|
|
569
580
|
/** Insert the system prompt pair after a caller has prepared its launch argv. */
|
|
570
581
|
export function finalizeRoleLaunch(prepared) {
|
|
@@ -576,6 +587,7 @@ export function finalizeRoleLaunch(prepared) {
|
|
|
576
587
|
model: prepared.model,
|
|
577
588
|
thinkingLevel: prepared.thinkingLevel,
|
|
578
589
|
missingSkills: prepared.missingSkills,
|
|
590
|
+
...(prepared.fallback ? { fallback: prepared.fallback } : {}),
|
|
579
591
|
};
|
|
580
592
|
}
|
|
581
593
|
export * from "./composition.js";
|
package/dist/launch-runtime.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type TaskModelFallback } from "./index.ts";
|
|
2
3
|
import type { CoordinatorRuntime, OperationContext, ResolvedRoute, TransientLaunchHandle, VerifiedLaunch } from "./runner.ts";
|
|
3
4
|
import { type ExecuteRequest, type ModelClass, type WorkspaceIdentity } from "./schema.ts";
|
|
4
5
|
export declare const ISOLATED_MODEL_TASK: {
|
|
@@ -11,6 +12,7 @@ type LaunchPi = Pick<ExtensionAPI, "events" | "getCommands">;
|
|
|
11
12
|
export interface LaunchRuntimeOptions {
|
|
12
13
|
pi: LaunchPi;
|
|
13
14
|
context(): ExtensionContext;
|
|
15
|
+
captureFallbackWarning?(signal: AbortSignal): (fallback: TaskModelFallback) => void;
|
|
14
16
|
resolveRoot(cwd: string, context: OperationContext): Promise<string>;
|
|
15
17
|
preflightHost?(input: {
|
|
16
18
|
request: ExecuteRequest;
|
package/dist/launch-runtime.js
CHANGED
|
@@ -117,6 +117,7 @@ export class RoleLaunchRuntime {
|
|
|
117
117
|
async prepareLaunch(role, modelClass, context) {
|
|
118
118
|
context.signal?.throwIfAborted();
|
|
119
119
|
const prepared = await resolveConfiguredRoleLaunch(this.options.pi, this.options.context(), { role, modelClass });
|
|
120
|
+
context.signal.throwIfAborted();
|
|
120
121
|
return Object.freeze({
|
|
121
122
|
launch: Object.freeze({
|
|
122
123
|
role: prepared.role,
|
|
@@ -129,6 +130,7 @@ export class RoleLaunchRuntime {
|
|
|
129
130
|
}),
|
|
130
131
|
prompt: prepared.systemPrompt,
|
|
131
132
|
promptArgIndex: prepared.promptArgIndex,
|
|
133
|
+
...(prepared.fallback ? { fallback: prepared.fallback } : {}),
|
|
132
134
|
});
|
|
133
135
|
}
|
|
134
136
|
async preflight(input, context) {
|
|
@@ -172,7 +174,15 @@ export class RoleLaunchRuntime {
|
|
|
172
174
|
return { root, main, routes };
|
|
173
175
|
}
|
|
174
176
|
async acquireLaunch(role, modelClass, context) {
|
|
177
|
+
context.signal.throwIfAborted();
|
|
178
|
+
const reportFallback = this.options.captureFallbackWarning?.(context.signal);
|
|
175
179
|
const prepared = await this.prepareLaunch(role, modelClass, context);
|
|
176
|
-
|
|
180
|
+
const fallback = prepared.fallback;
|
|
181
|
+
const launch = fallback && reportFallback ? Object.freeze({
|
|
182
|
+
...prepared.launch,
|
|
183
|
+
onFallbackUse: () => { if (!context.signal.aborted)
|
|
184
|
+
reportFallback(fallback); },
|
|
185
|
+
}) : prepared.launch;
|
|
186
|
+
return await materializeTransientLaunch({ ...prepared, launch }, context.signal);
|
|
177
187
|
}
|
|
178
188
|
}
|
package/dist/runner.d.ts
CHANGED
|
@@ -95,6 +95,8 @@ export interface VerifiedLaunch {
|
|
|
95
95
|
readonly args: readonly string[];
|
|
96
96
|
readonly env: Readonly<Record<string, string>>;
|
|
97
97
|
readonly tools: readonly string[];
|
|
98
|
+
/** Parent-owned notice; call only after the child starts productive work. */
|
|
99
|
+
readonly onFallbackUse?: () => void;
|
|
98
100
|
}
|
|
99
101
|
export type ResolvedRoute = Pick<VerifiedLaunch, "role" | "modelClass" | "model" | "thinkingLevel">;
|
|
100
102
|
/** A dry-run result: the normalized request and the resolved routes; no state exists for it. */
|
package/dist/runner.js
CHANGED
|
@@ -2473,6 +2473,7 @@ export class IsolatedRunner {
|
|
|
2473
2473
|
const launch = { args: [...verifiedLaunch.args], env: { ...verifiedLaunch.env } };
|
|
2474
2474
|
return await this.textExecutor.run({
|
|
2475
2475
|
signal: context.signal,
|
|
2476
|
+
onActivity: verifiedLaunch.onFallbackUse,
|
|
2476
2477
|
prepare: async () => ({ launch, task: prompt, cwd: isolated.cwd }),
|
|
2477
2478
|
});
|
|
2478
2479
|
});
|
package/extensions/isolated.ts
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
} from "../dist/schema.js";
|
|
40
40
|
import { FileRunStore } from "../dist/store.js";
|
|
41
41
|
import { workerOutputForMain } from "./result-transport.ts";
|
|
42
|
+
import { captureFallbackWarning } from "./task-model-fallback.ts";
|
|
42
43
|
import type { CleanupReport, IsolatedInventory, IsolatedRequest, PrunePlan } from "./subagent-command.ts";
|
|
43
44
|
import type { DiscardPlan } from "../dist/discard.js";
|
|
44
45
|
|
|
@@ -58,6 +59,7 @@ export interface IsolatedExtensionComponents {
|
|
|
58
59
|
export type CreateIsolatedComponents = (options: {
|
|
59
60
|
pi: ExtensionAPI;
|
|
60
61
|
context(): ExtensionContext;
|
|
62
|
+
captureFallbackWarning?: LaunchRuntimeOptions["captureFallbackWarning"];
|
|
61
63
|
executor: EphemeralSubagentExecutor;
|
|
62
64
|
policy: ExecutionPolicySnapshot;
|
|
63
65
|
currentPolicy(): ExecutionPolicySnapshot;
|
|
@@ -66,7 +68,7 @@ export type CreateIsolatedComponents = (options: {
|
|
|
66
68
|
|
|
67
69
|
/** Construct the checked runtime while reusing the unified productive-assignment executor. */
|
|
68
70
|
export const createIsolatedComponents: CreateIsolatedComponents = ({
|
|
69
|
-
pi, context, executor, policy, currentPolicy, onStateSaved,
|
|
71
|
+
pi, context, captureFallbackWarning, executor, policy, currentPolicy, onStateSaved,
|
|
70
72
|
}) => {
|
|
71
73
|
const runProcess: DirectProcessRunner = async (command, args, options) => options.stdin === undefined
|
|
72
74
|
? await pi.exec(command, args, { cwd: options.cwd, signal: options.signal, timeout: options.timeoutMs })
|
|
@@ -82,6 +84,7 @@ export const createIsolatedComponents: CreateIsolatedComponents = ({
|
|
|
82
84
|
const coordinator = new RoleLaunchRuntime({
|
|
83
85
|
pi,
|
|
84
86
|
context,
|
|
87
|
+
captureFallbackWarning,
|
|
85
88
|
resolveRoot,
|
|
86
89
|
preflightHost: async ({ root }, operation) => await host.preflightHost({ root }, operation),
|
|
87
90
|
inspectMainBase: async (input, operation) => await git.inspectMainBase(input, operation),
|
|
@@ -568,6 +571,13 @@ export function registerIsolatedExtension(pi: ExtensionAPI, options: RegisterIso
|
|
|
568
571
|
options.beforeRoleLaunch?.(ctx);
|
|
569
572
|
return ctx;
|
|
570
573
|
},
|
|
574
|
+
captureFallbackWarning: (signal) => {
|
|
575
|
+
const ctx = latestContext();
|
|
576
|
+
const epoch = sessionEpoch;
|
|
577
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
578
|
+
return captureFallbackWarning(pi, ctx, () => !sessionClosed && sessionEpoch === epoch
|
|
579
|
+
&& latestCtx?.sessionManager.getSessionId() === sessionId, signal);
|
|
580
|
+
},
|
|
571
581
|
executor: options.executor,
|
|
572
582
|
policy: options.policy,
|
|
573
583
|
currentPolicy: options.currentPolicy,
|
package/extensions/subagent.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { availableTaskModels, loadTaskModelsConfig, modelReference, type Profile
|
|
|
5
5
|
import { registerConfigReporting } from "@henryqw/pi-config-store";
|
|
6
6
|
import { capEphemeralSubagentOutput as capOutput, createEphemeralSubagentExecutor, createSubagentConfigStore, DEFAULT_SUBAGENT_CONFIG, DELEGATE_TASK, findRole, formatDuration, loadRoleCatalog, prepareRoleLaunch, resolveRolePackageResources, resolveTaskRoute, ROLE_TOOL_POLICY_FLAG, type ExecutionPolicySnapshot, type Role } from "@henryqw/pi-subagent";
|
|
7
7
|
import { resolveExecutionPolicy } from "./config.ts";
|
|
8
|
+
import { captureFallbackWarning } from "./task-model-fallback.ts";
|
|
8
9
|
import { registerCheckoutAdmission } from "./admission.ts";
|
|
9
10
|
import { registerIsolatedExtension } from "./isolated.ts";
|
|
10
11
|
import { directRef, registerSubagentCommand, type DirectDisplay, type DirectTask } from "./subagent-command.ts";
|
|
@@ -433,9 +434,10 @@ export default function subagentExtension(pi: ExtensionAPI): void {
|
|
|
433
434
|
if (Buffer.byteLength(snapshot, "utf8") > 32_000) throw new Error("Status exceeds the 32 KiB inspection limit; use subagent_status for exact evidence.");
|
|
434
435
|
reportConfig(ctx);
|
|
435
436
|
const role = findRole(loadRoleCatalog(), "scout");
|
|
437
|
+
const controller = new AbortController();
|
|
438
|
+
const reportFallback = captureFallbackWarning(pi, ctx, current, controller.signal);
|
|
436
439
|
const prepared = await prepareDirectLaunch(role, ctx, { modelClass: "fast" });
|
|
437
440
|
const herdr = createDirectHerdr(pi, ctx.cwd, currentPolicy().childIdleMs);
|
|
438
|
-
const controller = new AbortController();
|
|
439
441
|
const taskId = `inspect-${id}-${randomUUID()}`;
|
|
440
442
|
const display: DirectDisplay = { workflow: nextWorkflow(ctx), worker: 1, workers: 1, title: `Inspect ${id}`, role: role.name };
|
|
441
443
|
const recordEpoch = directRecordEpoch;
|
|
@@ -466,6 +468,7 @@ export default function subagentExtension(pi: ExtensionAPI): void {
|
|
|
466
468
|
await handle.cancel();
|
|
467
469
|
throw new Error(`Session changed during inspection launch; inspect Herdr tab ${handle.tabId}.`);
|
|
468
470
|
}
|
|
471
|
+
if (prepared.fallback) reportFallback(prepared.fallback);
|
|
469
472
|
return { ref: directRef(display), tabId: handle.tabId, name: handle.name, sessionFile: handle.sessionFile };
|
|
470
473
|
} finally {
|
|
471
474
|
directTasks.delete(taskId);
|
|
@@ -898,12 +901,15 @@ export default function subagentExtension(pi: ExtensionAPI): void {
|
|
|
898
901
|
const answerBytes = Math.floor(40 * 1024 / entries.length);
|
|
899
902
|
const launch = async (entry: WorkflowEntry, activeSignal: AbortSignal) => {
|
|
900
903
|
activeSignal.throwIfAborted();
|
|
904
|
+
const reportFallback = captureFallbackWarning(pi, ctx, () => launchEpoch === sessionEpoch
|
|
905
|
+
&& (latestCtx ?? ctx).sessionManager.getSessionId() === launchSessionId, activeSignal);
|
|
901
906
|
// A later worker launches after earlier ones finish; report and revalidate config edits made meanwhile.
|
|
902
907
|
beforeRoleLaunch(latestCtx ?? ctx);
|
|
903
908
|
const role = findRole(loadRoleCatalog(), entry.delegation.role);
|
|
904
909
|
const { modelClass, model } = entry.delegation;
|
|
905
910
|
const prepared = await prepareDirectLaunch(role, latestCtx ?? ctx, {
|
|
906
911
|
...(modelClass === undefined ? {} : { modelClass }), ...(model === undefined ? {} : { model }) });
|
|
912
|
+
activeSignal.throwIfAborted();
|
|
907
913
|
states.set(entry.id, { ...states.get(entry.id)!, model: modelReference(prepared.model), thinkingLevel: prepared.thinkingLevel, status: "running", assistantOutput: "" });
|
|
908
914
|
startedAt.set(entry.id, Date.now());
|
|
909
915
|
const display = displayOf(entry);
|
|
@@ -934,6 +940,7 @@ export default function subagentExtension(pi: ExtensionAPI): void {
|
|
|
934
940
|
handles.push(handle);
|
|
935
941
|
handleByEntry.set(entry.id, handle);
|
|
936
942
|
if (widgetItems.has(entry.id)) tokenHandles.set(entry.id, handle);
|
|
943
|
+
if (prepared.fallback) reportFallback(prepared.fallback);
|
|
937
944
|
if (launchEpoch === sessionEpoch) automaticCollection(ctx);
|
|
938
945
|
return handle;
|
|
939
946
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { TaskModelFallback } from "../dist/index.js";
|
|
3
|
+
|
|
4
|
+
// Keep one warning per parent session and route, including after extension reloads.
|
|
5
|
+
const FALLBACK_WARNINGS = Symbol.for("pi-subagent/task-model-fallback-warnings");
|
|
6
|
+
|
|
7
|
+
export function captureFallbackWarning(
|
|
8
|
+
pi: Pick<ExtensionAPI, "sendMessage">,
|
|
9
|
+
ctx: ExtensionContext,
|
|
10
|
+
current: () => boolean,
|
|
11
|
+
signal: AbortSignal,
|
|
12
|
+
): (fallback: TaskModelFallback) => void {
|
|
13
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
14
|
+
return ({ profileName, model, thinkingLevel }) => {
|
|
15
|
+
if (signal.aborted || !current() || ctx.sessionManager.getSessionId() !== sessionId) return;
|
|
16
|
+
const message = `Task model profile ${profileName}: primary route is unavailable; selected fallback ${JSON.stringify(model)} (thinking ${thinkingLevel}).`;
|
|
17
|
+
const state = globalThis as { [FALLBACK_WARNINGS]?: WeakMap<object, { sessionId: string; shown: Set<string> }> };
|
|
18
|
+
const sessions = state[FALLBACK_WARNINGS] ??= new WeakMap();
|
|
19
|
+
let warnings = sessions.get(ctx.sessionManager);
|
|
20
|
+
if (warnings?.sessionId !== sessionId) {
|
|
21
|
+
warnings = { sessionId, shown: new Set() };
|
|
22
|
+
sessions.set(ctx.sessionManager, warnings);
|
|
23
|
+
}
|
|
24
|
+
if (warnings.shown.has(message)) return;
|
|
25
|
+
if (ctx.hasUI) ctx.ui.notify(message, "warning");
|
|
26
|
+
else pi.sendMessage({ customType: "pi-subagent-model-fallback", content: message, display: true }, { triggerTurn: false, deliverAs: "followUp" });
|
|
27
|
+
warnings.shown.add(message);
|
|
28
|
+
};
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@henryqw/pi-subagent",
|
|
3
|
-
"version": "27.
|
|
3
|
+
"version": "27.15.0",
|
|
4
4
|
"description": "Delegate bounded direct work or durable checked isolated task graphs to Pi roles.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@henryqw/pi-herdr": "^0.6.0",
|
|
75
75
|
"@henryqw/pi-multi-codex": "^3.0.0",
|
|
76
76
|
"@henryqw/pi-process": "^0.2.0",
|
|
77
|
-
"@henryqw/pi-task-models": "^9.
|
|
77
|
+
"@henryqw/pi-task-models": "^9.2.0",
|
|
78
78
|
"proper-lockfile": "^4.1.2"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|