Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(subagents): explain empty model override authorization
xjxcd9629a7c2b3
diff --git a/docs/spec/03-runtime/02-agent-runtime.md b/docs/spec/03-runtime/02-agent-runtime.mdindex 4d0ffdc15..cd596d524 100644--- a/docs/spec/03-runtime/02-agent-runtime.md+++ b/docs/spec/03-runtime/02-agent-runtime.md@@ -862,7 +862,11 @@ core set rather than the on-demand catalog of §7.1:(`"provider/modelId"`) that overrides the delegate's model for that run.Resolution priority: Task.model parameter → definition frontmatter pin →session model. The parent agent sees a model summary in the system prompt- listing all models marked `availableForSubagents` in provider settings. If+ listing all models marked `availableForSubagents` in provider settings. The+ empty-catalog system summary, Task description and rejected-override error+ point to Settings → Models → edit service/account → model Advanced →+ "Available for AI delegation" → save, and require an exact catalog key+ rather than guessed provider/model keys. Ifthe delegation catalog is empty, the prompt tells the model to omit `model`and use the definition pin, or inherit the session model when unpinned; anexplicit key that exactly names the current session provider/model is treated as the same inheritance case. Otherdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex b404aecf6..e217b0f94 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -12129,7 +12129,11 @@ are withdrawn with ADR 0165.specified model, not the session model; its delegation node shows theeffective model id immediately after the subagent name.4. If the model is not configured or not enabled for delegation, the Task- returns a tool error listing available models.+ returns a tool error listing available models. With an empty override+ catalog, the error, system summary and Task description name the Settings+ → Models / model Advanced / "Available for AI delegation" / save path.+ A denied guessed override sends no child request; retrying with `model`+ omitted still uses the definition default or inherits the parent model.5. Resolution priority is Task.model parameter → definition frontmatter pin →session model.6. On-demand resolution succeeds for models enabled in provider settings via@@ -12151,6 +12155,7 @@ are withdrawn with ADR 0165.- **Milestone**: M6+- **Status**: Partially automated. `pnpm test:e2e:subagent-models` drives thebuilt sidecar over real NDJSON and a local deterministic SSE model fixture:+ empty-catalog guidance and inheritance after a denied override,private cross-definition rejection, own-pin echo, normal pin use, allowed override priority,on-demand authorization without runtime rebuild, exact-session inheritance, and revocation across twoprompts all pass. Runtime unit tests cover the same selection gates and thediff --git a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md b/docs/zh-CN/spec/03-runtime/02-agent-runtime.mdindex 9b52cdda6..91e214f9f 100644--- a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md+++ b/docs/zh-CN/spec/03-runtime/02-agent-runtime.md@@ -638,7 +638,10 @@ Frontmatter 新增 `permission: inherit | ask | accept-edits | auto`(默认`Task` 工具接受一个可选的 `model` 参数(`"provider/modelId"`),用于在本次运行中覆盖该委托的模型。解析优先级:Task.model 参数 → 定义 frontmatter 的引脚 → 会话模型。父 agent 会在系统提示中看到一份模型摘要,列出提供商设置里- 所有标记为 `availableForSubagents` 的模型。若委托目录为空,提示会告诉模型+ 所有标记为 `availableForSubagents` 的模型。空目录下的系统摘要、Task 说明和+ 覆盖请求错误均指向「设置 → 模型 → 编辑服务或账号 → 模型高级设置 →+ 可供 AI 自动调度 → 保存」,要求使用目录中的准确键,避免猜测 provider/model。+ 若委托目录为空,提示会告诉模型省略 `model`,使用定义的固定模型,无固定模型时继承会话模型;显式给出的键如果正好就是当前会话的provider/model,同样按继承处理。其他显式模型键必须已配置并已为委托启用。Electron 单独传递 `subagentModelKeys` 与 `subagentProviders`:后者可含仅供定义diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex e2d60e875..971a6ca8d 100644--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@ -6955,7 +6955,9 @@ eleven-tool-round desktop paths are verified by- **预期**:自动调度许可持久化。系统模型摘要只列出成功解析且已勾选的模型,不包含仅供定义固定使用的模型;Task 定义目录展示默认模型并提示省略或重复该键保留默认。优先级保持 Task.model → 定义固定模型 → 会话模型;未配置或未授权的显式覆盖返回- 工具错误,且不向子模型发送请求。省略参数,或重复该定义自己的固定模型键,仍能使用定义自己的未勾选固定模型。+ 工具错误,且不向子模型发送请求。覆盖目录为空时,错误、系统摘要与 Task 说明+ 指明「设置 → 模型 → 模型高级设置 → 可供 AI 自动调度 → 保存」的操作路径。+ 猜测键被拒绝后,省略 `model` 重试仍可使用定义默认模型或继承主会话模型。省略参数,或重复该定义自己的固定模型键,仍能使用定义自己的未勾选固定模型。当前会话模型的既有继承例外不变,按需解析仍需 main 检查许可,且不得覆盖固定模型或替换空闲运行时。许可变化会在下一回合替换空闲运行时,旧缓存不再授予选择权。- **链接规格**:`03-runtime/02-agent-runtime.md` §5f;@@ -6964,7 +6966,7 @@ eleven-tool-round desktop paths are verified by- **验收**:C(对话/流)+ B(模型配置)+ E(工具)- **里程碑**:M6+- **状态**:部分自动化。`pnpm test:e2e:subagent-models` 通过真实 NDJSON 驱动构建后- 的 sidecar,并使用本地确定性 SSE 模型夹具,已验证跨定义拒绝、自身固定模型回显、固定模型、合法覆盖+ 的 sidecar,并使用本地确定性 SSE 模型夹具,已验证空目录指引与拒绝后继承、跨定义拒绝、自身固定模型回显、固定模型、合法覆盖优先级、按需授权且不重建运行时、会话继承与跨回合撤销。运行时单测覆盖选择校验,桌面启动测试验证独立许可、撤销和多账号别名冲突,连接测试检查按需唯一匹配。设置复选框 UI/持久化旅程及外部真实提供商执行仍需手动验证;此夹具不代表完整原生 UI 旅程已通过。diff --git a/packages/agent-runtime/src/runtime.test.ts b/packages/agent-runtime/src/runtime.test.tsindex ab5949882..36a27d146 100644--- a/packages/agent-runtime/src/runtime.test.ts+++ b/packages/agent-runtime/src/runtime.test.ts@@ -7143,6 +7143,49 @@ describe("DesktopAgentRuntime subagents", () => {expect(host.call).toHaveBeenCalledTimes(1);});+ it("guides empty override catalogs to model opt-in without blocking default delegation (#1043)", async () => {+ const host = { call: vi.fn().mockRejectedValue(new Error("not enabled for delegation")) };+ const runtime = createRuntime({ subagents: [explorer], subagentModelKeys: [], host });+ subagentRuns.calls.length = 0;+ subagentRuns.deferred = false;+ subagentRuns.result = undefined;+ const tool = taskTool(runtime);+ const denied = await tool.execute("empty-override", {+ agent: "explorer", task: "Search.", model: "guessed/model",+ });+ for (const guidance of [+ denied.details.error, tool.description, (runtime as any).agent.state.systemPrompt,+ ]) {+ expect(guidance).toContain("Settings → Models");+ expect(guidance).toContain("Advanced");+ expect(guidance).toContain("Available for AI delegation");+ expect(guidance).toContain("save");+ expect(guidance).toContain("Omit");+ }+ expect(denied.details.error).toContain("not available for delegation");+ expect(subagentRuns.calls).toHaveLength(0);+ const inherited = await tool.execute("inherit-after-denial", { agent: "explorer", task: "Search." });+ expect(inherited.details.error).toBeUndefined();+ expect(subagentRuns.calls).toHaveLength(1);+ expect(subagentRuns.calls[0].provider).toBe(provider);+ await runtime.dispose();+ });++ it("lists exact authorized keys instead of empty-catalog guidance for an invalid override (#1043)", async () => {+ const runtime = createRuntime({+ subagents: [explorer],+ subagentProviders: { "allowed/selected-model": provider },+ subagentModelKeys: ["allowed/selected-model"],+ host: { call: vi.fn().mockRejectedValue(new Error("not enabled for delegation")) },+ });+ const denied = await taskTool(runtime).execute("unknown-override", {+ agent: "explorer", task: "Search.", model: "guessed/model",+ });+ expect(denied.details.error).toContain("Available: allowed/selected-model.");+ expect(denied.details.error).not.toContain("Settings → Models");+ await runtime.dispose();+ });+it("allows an opted-in model to override a definition pin without changing D278", async () => {const pinnedProvider = { ...provider, modelId: "remote-model", modelConfig: undefined };const selected = { ...provider, modelId: "selected-model", modelConfig: undefined };diff --git a/packages/agent-runtime/src/runtime.ts b/packages/agent-runtime/src/runtime.tsindex 7fcf036af..debb767e0 100644--- a/packages/agent-runtime/src/runtime.ts+++ b/packages/agent-runtime/src/runtime.ts@@ -492,6 +492,10 @@ export const ASK_TOOL_NAME = "asktool";* be re-read by id without re-running it.*/const MAX_RETAINED_DELEGATIONS = 100;+const DELEGATION_MODEL_OPT_IN_GUIDANCE =+ 'To authorize a model override, open Settings → Models, edit the service or account, expand its model Advanced settings, enable "Available for AI delegation", and save. Use an exact key from the delegation catalog; never guess a provider/model key.';+const DELEGATION_DEFAULT_MODEL_GUIDANCE =+ "Omit the `model` parameter on Task to use the definition's default model, or inherit the parent conversation's selected model when no default is pinned. Repeating the definition's own Default model key is the same as omitting `model`.";/*** `TaskWait` blocks the turn, and the model picks the timeout, so the ceiling* is what bounds how long a session can look hung with no way to intervene.@@ -4139,8 +4143,8 @@ Do not invent objections or turn speculative risks into blockers. Stop when theif (keys.length === 0) {return ["No delegation model overrides are configured.",- "Omit the `model` parameter on Task to use the definition's default model, or inherit the parent conversation's selected model when no default is pinned.",- "Repeating a definition's own Default model key is the same as omitting `model`. Never invent a provider/model key.",+ DELEGATION_DEFAULT_MODEL_GUIDANCE,+ DELEGATION_MODEL_OPT_IN_GUIDANCE,].join(" ");}const lines: string[] = [@@ -4402,7 +4406,7 @@ Do not invent objections or turn speculative risks into blockers. Stop when the"Only pass `model` when deliberately overriding the definition default with a listed delegation model; otherwise omit it. Repeating the definition's own Default model key, or the exact parent provider/model, is the same as omitting `model`.",]: [- "No delegation model overrides are configured. Omit `model` to use the definition's default, or the parent model when no default is pinned. Repeating a definition's own Default model key is the same as omitting `model`; never invent a provider/model key.",+ `No delegation model overrides are configured. ${DELEGATION_DEFAULT_MODEL_GUIDANCE} ${DELEGATION_MODEL_OPT_IN_GUIDANCE}`,]),"`task` is the delegate's only instruction. It cannot see this conversation, and you cannot correct it while it runs, so state the goal, the paths and facts it cannot infer, and exactly what to report back.","To run delegates concurrently, emit several Task calls in one assistant message. A message that mixes Task with any other tool runs one call at a time. You may keep working or talk to the user while they run; the runtime delivers their reports when they finish. Call TaskStop only to cancel.",@@ -4504,7 +4508,7 @@ Do not invent objections or turn speculative risks into blockers. Stop when theconst available = this.availableSubagentModelKeys();const hint = available.length? ` Available: ${available.join(", ")}.`- : " No models are configured for delegation.";+ : ` No delegation model overrides are configured. ${DELEGATION_DEFAULT_MODEL_GUIDANCE} ${DELEGATION_MODEL_OPT_IN_GUIDANCE}`;return this.subagentToolError(toolCallId,`Model "${modelOverride}" is not available for delegation.${hint}`,diff --git a/scripts/e2e-subagent-models.mjs b/scripts/e2e-subagent-models.mjsindex 6bb00954c..b6c1e38c5 100644--- a/scripts/e2e-subagent-models.mjs+++ b/scripts/e2e-subagent-models.mjs@@ -180,6 +180,16 @@ async function run(id, args, expectedModel, keys = ["fixture/allowed"], sessionIassert.equal(delegates.length, 0, "forbidden override must not issue a provider request");assert.ok(captured.some((p) => p.messages.some((m) => m.role === "tool" && JSON.stringify(m.content).includes("not available for delegation"))));}+ if (id === "empty-override-guidance") {+ const task = parent.tools.find((tool) => tool.function?.name === "Task");+ const toolResult = captured.flatMap((request) => request.messages)+ .find((message) => message.role === "tool" && JSON.stringify(message.content).includes("not available for delegation"));+ for (const text of [system, task.function.description, JSON.stringify(toolResult?.content)]) {+ assert.ok(text.includes("Settings → Models"), "empty overrides must point to model settings");+ assert.ok(text.includes("Advanced") && text.includes("Available for AI delegation") && text.includes("save"), "guidance must name the opt-in control and save action");+ assert.ok(text.includes("Omit"), "empty overrides must not imply delegation is unavailable");+ }+ }if (fallbackModels) {for (const pin of fallbackModels) {assert.ok(!system.includes(`\`fixture/${pin}\``), "fallback pin stays out of the override catalog");@@ -322,6 +332,8 @@ try {expectedAttempts: unavailable,expectedStatus: "failed",});+ await run("empty-override-guidance", { agent: "explorer", model: "guessed/model" }, undefined, [], "empty-catalog");+ await run("empty-override-inheritance", { agent: "explorer" }, "parent", [], "empty-catalog");console.log("PASS E2E-166 changed opt-in rebuilds the sidecar runtime");} finally {child.kill();