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(agent-runtime): reject differing spellings of one tool argument
vastsa5bd40d81e445
diff --git a/docs/spec/03-runtime/03-tools-and-permissions.md b/docs/spec/03-runtime/03-tools-and-permissions.mdindex 79351932f..91fe0c490 100644--- a/docs/spec/03-runtime/03-tools-and-permissions.md+++ b/docs/spec/03-runtime/03-tools-and-permissions.md@@ -302,8 +302,10 @@ before the host sees the call (D273):| `Glob` / `Grep` | `pattern` | `query` |Both spellings are optional in the schema and the runtime requires exactly one;-a call naming neither fails with `INVALID_ARGUMENT`. When a call carries both,-the canonical name wins. `Bash.timeout` accepts up to 100000000 in the schema so a+a call naming neither fails with `INVALID_ARGUMENT`. Several spellings with the+same value count as one argument. Spellings with different values fail with+`INVALID_ARGUMENT` before execution, and the message quotes every value, so+the runtime never silently picks one (D690). `Bash.timeout` accepts up to 100000000 in the schema so amillisecond value validates: a value above the honoured 21,600-second ceilingis read as milliseconds and converted to seconds, then clamped to 21,600seconds (D273 / D329). In-range values, including 600 and 1800, are seconds.diff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.mdindex dda655edf..80cf89db4 100644--- a/docs/spec/08-meta/decisions-log.md+++ b/docs/spec/08-meta/decisions-log.md@@ -466,6 +466,7 @@ section mirrors only marketplace/catalog items still blocking nothing.| D166 | Settings directory split into AI and Shortcuts destinations | **The Settings rail grows from five to seven destinations in order: Basics (`SlidersHorizontal`), 全局 AI/AI (`Sparkles`, new), Shortcuts (`Keyboard`, new), Model configuration (`Bot`), Import (`Download`), Project archive (`Archive`), Info (`Info`). Permissions and Context management move from Basics to the new AI destination; Keyboard shortcuts moves from Basics to the new Shortcuts destination; Developer moves from Basics to Info. Basics keeps only Appearance and Defaults. This supersedes the five-destination count/order of D133 and the five-icon set of D143 (adding `Sparkles` and `Keyboard`) without changing any setting's semantics, the full-page shell, or rail metrics.** | Basics accumulated six unrelated cards, burying global AI behavior (permission mode, context compaction) and shortcut configuration alongside look-and-feel; splitting them gives each concern a scannable home while keeping provider/connection config separate in Model configuration. || D684 | One settings destination owns one subject | **Amend D143 / D166 / D678: the Settings rail is fifteen single-subject destinations in four clusters, retiring `general` and `ai` into Appearance, Conversation, Behavior, and System.** | Two destinations had become mixed landing places. See ADR 0345. || D685 | Composer model picker: text rail and segmented reasoning | **Amend D458: the reasoning control in the combined Composer model menu is a segmented track with a raised pill under the selected level, placed in the menu footer, instead of a rail with track dots. The native range input, its column geometry, latest-wins commits and keyboard ownership are unchanged. The model list uses a text-only source rail with one sliding marker; Escape clears a typed search before closing the menu. Renderer only. See `04-ux/08-component-spec.md` and E2E-050.** | The dot rail and colored source tiles read heavy next to compact model rows; a segmented pill and a text rail match the rest of the menu chrome. |+| D690 | Differing spellings of one tool argument are rejected | **Amend D273: when a `Read`/`Write`/`Edit`/`BrowserPreview`/`Glob`/`Grep` call names one argument under several accepted spellings with different values, the runtime fails it with `INVALID_ARGUMENT` before execution and quotes every value; identical values still fold to one. The canonical name no longer silently wins. Runtime only: no IPC, storage, host-protocol, or schema change.** | Issue #2552: calls stored `path` with conversational junk (`Wizard.tsx here?`, `Wizard.tsx:{`) beside a clean `file_path`. Canonical-wins ran the junk path every time, and host-core never saw the clean value. Picking either spelling is a guess; naming both lets the next call send one. |## R. Decision rules going forward@@ -5447,3 +5448,15 @@ See ADR 0344.the same pairing. Keep only device metadata and cookie verifiers on Desktop.Explicit disable or revocation persists; first launch still starts off. Seethe [code pairing amendment](../../adr/lan-webui-code-pairing.md#amendment-remember-pairing-across-desktop-launches-d688).++## 2026-11-28 — Differing spellings of one tool argument are rejected (D690)++- D273 let the canonical name win when a call carried both `path` and an+ alias. Issue #2552 showed the cost: stored calls had junk in `path`+ (`Wizard.tsx here?`, `Wizard.tsx:{`) and the clean value in `file_path`,+ so every retry ran the junk path.+- The runtime now rejects differing values for one argument before the+ write lock and the host call, with an `INVALID_ARGUMENT` message that quotes+ every spelling and asks for `path` alone. Identical values still fold.+- Transcripts recorded earlier keep their meaning: the compaction file-op+ collector still reads `path` first, which is how those calls ran.diff --git a/packages/agent-runtime/src/pi-runtime-compaction-plan.ts b/packages/agent-runtime/src/pi-runtime-compaction-plan.tsindex 86e982953..9dd1394cc 100644--- a/packages/agent-runtime/src/pi-runtime-compaction-plan.ts+++ b/packages/agent-runtime/src/pi-runtime-compaction-plan.ts@@ -116,9 +116,10 @@ function createFileOperations(): FileOperations {/*** Spellings of `path` kept on a stored `Read` / `Write` / `Edit` call.*- * `path` plus `PATH_ARG_ALIASES` from runtime.ts, in that map's order (D273 /- * issue #454). This module cannot import the map: runtime.ts already imports- * the planner. `normalizeToolParams` folds an alias only when the call+ * `path` plus `PATH_ARG_ALIASES` from tool-param-aliases.ts, in that map's+ * order (D273 / issue #454). Transcripts recorded before #2552 may carry+ * differing spellings that ran with `path`; current calls with differing+ * spellings fail before execution. `normalizeToolParams` folds an alias only when the call* executes, and the runtime defines no `prepareArguments`, so the assistant* message still carries the spelling the model sent.*/diff --git a/packages/agent-runtime/src/runtime.test.ts b/packages/agent-runtime/src/runtime.test.tsindex 2174a058e..4f65b851e 100644--- a/packages/agent-runtime/src/runtime.test.ts+++ b/packages/agent-runtime/src/runtime.test.ts@@ -3126,12 +3126,55 @@ describe("DesktopAgentRuntime configuration matching", () => {args: { pattern: "foo", path: "src" },});- // The canonical name wins when a call somehow carries both.- await tool("Read").execute("read-both", {- path: "src/canonical.ts",- file_path: "src/alias.ts",+ // Both spellings with the same value are one argument.+ await tool("Read").execute("read-both-same", {+ path: "src/same.ts",+ file_path: "src/same.ts",+ });+ expect(lastExecute()).toMatchObject({ args: { path: "src/same.ts" } });+ const executesBeforeConflicts = host.call.mock.calls.filter(+ (call: unknown[]) => call[0] === "tools.execute",+ ).length;++ // Differing spellings are rejected instead of silently running one of+ // them (#2552): the stored calls carried junk in `path` and the clean+ // value in `file_path`.+ await expect(+ tool("Read").execute("read-conflict", {+ path: "src/pages/Wizard.tsx here?",+ file_path: "src/pages/Wizard.tsx",+ }),+ ).rejects.toMatchObject({+ errorCode: "INVALID_ARGUMENT",+ message: expect.stringContaining(+ '`path` = "src/pages/Wizard.tsx here?", `file_path` = "src/pages/Wizard.tsx"',+ ),});- expect(lastExecute()).toMatchObject({ args: { path: "src/canonical.ts" } });+ await expect(+ tool("Edit").execute("edit-conflict", {+ path: "src/pages/Wizard.tsx:{",+ file_path: "src/pages/Wizard.tsx",+ tag: "9DA2",+ ops: "PUT 1.=1:\n+x",+ }),+ ).rejects.toMatchObject({ errorCode: "INVALID_ARGUMENT" });+ // Two aliases without the canonical spelling conflict the same way.+ await expect(+ tool("Write").execute("write-alias-conflict", {+ file_path: "a.ts",+ filePath: "b.ts",+ content: "x",+ }),+ ).rejects.toMatchObject({+ errorCode: "INVALID_ARGUMENT",+ message: expect.stringContaining("Send only `path`"),+ });+ await expect(+ tool("Grep").execute("grep-conflict", { pattern: "foo", query: "bar" }),+ ).rejects.toMatchObject({ errorCode: "INVALID_ARGUMENT" });+ expect(+ host.call.mock.calls.filter((call: unknown[]) => call[0] === "tools.execute"),+ ).toHaveLength(executesBeforeConflicts);// Extra path spellings weaker models reach for (issue #454): every one of// these folds onto `path` so the model does not silently fall back to Bashdiff --git a/packages/agent-runtime/src/runtime.ts b/packages/agent-runtime/src/runtime.tsindex 6eee512a2..eab1b602d 100644--- a/packages/agent-runtime/src/runtime.ts+++ b/packages/agent-runtime/src/runtime.ts@@ -344,6 +344,11 @@ import {} from "./context-calibration.js";import { rebuildNodeNetworkTransport } from "./node-proxy.js";+import {+ rejectConflictingAliasedParams,+ requireAliasedParams,+ TOOL_PARAM_ALIASES,+} from "./tool-param-aliases.js";import {createProviderTransportHealth,explainsProviderFetchFailure,@@ -1400,32 +1405,6 @@ const MAX_COMMAND_TIMEOUT_SECONDS = 21_600;* clamps to {@link MAX_COMMAND_TIMEOUT_SECONDS} (D273 / D329).*/const MAX_ACCEPTED_COMMAND_TIMEOUT = 100_000_000;-/**- * Argument names models reach for instead of ours, mapped to the canonical- * name. Every strong model has `file_path`/`query` burned in from pretraining- * and sends them regardless of what the schema says, so the schema accepts both- * spellings and {@link normalizeToolParams} folds the alias away before the- * host sees the call (D273). Weaker models — issue #454 pinned longcat 2.0 —- * reach for `filepath` / `filename` / `filePath` / `file` instead; folding- * those the same way rescues the turn before the model gives up on the tool- * and silently falls back to Bash.- */-const PATH_ARG_ALIASES = {- file_path: "path",- filepath: "path",- filePath: "path",- filename: "path",- fileName: "path",- file: "path",-} as const;-const TOOL_PARAM_ALIASES: Record<string, Record<string, string>> = {- Read: { ...PATH_ARG_ALIASES },- Write: { ...PATH_ARG_ALIASES },- Edit: { ...PATH_ARG_ALIASES },- BrowserPreview: { ...PATH_ARG_ALIASES },- Glob: { query: "pattern" },- Grep: { query: "pattern" },-};const TOOL_OUTPUT_UPDATE_THROTTLE_MS = 100;const READ_ONLY_CORE_TOOLS = new Set(["Read", "Glob", "Grep"]);/**@@ -1521,38 +1500,6 @@ function aliasParam(canonical: string) {);}-/**- * Fails a call that named neither the canonical argument nor its alias. Without- * this the now-optional canonical argument would reach the host as `undefined`- * and surface as a confusing host-side error instead of a schema one.- */-function requireAliasedParams(toolName: string, params: unknown): void {- const aliases = TOOL_PARAM_ALIASES[toolName];- if (!aliases || !isRecord(params)) return;- for (const canonical of new Set(Object.values(aliases))) {- if (params[canonical] !== undefined) continue;- // A weaker model that keeps hitting this error gives up on the tool and- // silently switches to Bash (issue #454). Naming the accepted spellings and- // showing a minimal example lets the next call self-correct instead of the- // whole turn falling back to shell.- const acceptedAliases = Object.keys(aliases).filter(- (alias) => aliases[alias] === canonical,- );- const aliasHint =- acceptedAliases.length > 0- ? ` (the alias${acceptedAliases.length > 1 ? "es" : ""} ${acceptedAliases- .map((name) => `\`${name}\``)- .join(", ")} ${acceptedAliases.length > 1 ? "are" : "is"} also accepted)`- : "";- throw Object.assign(- new Error(- `Invalid arguments for ${toolName}: \`${canonical}\` is required${aliasHint}. Example: {"${canonical}": "..."}.`,- ),- { errorCode: "INVALID_ARGUMENT" },- );- }-}-/*** Folds aliased argument names onto the canonical ones and reads a Bash* `timeout` that arrived in milliseconds as seconds (D273). Both rewrites are@@ -1577,8 +1524,9 @@ function normalizeToolParams(toolName: string, params: unknown): unknown {const next = { ...params };for (const alias of aliased) {const canonical = aliases![alias];- // The canonical spelling wins if a call carries both; either way the alias- // is dropped so the host and the transcript never see it.+ // Differing spellings were rejected by rejectConflictingAliasedParams+ // before execution; either way the alias is dropped so the host and the+ // transcript never see it.if (next[canonical] === undefined) next[canonical] = next[alias];delete next[alias];}@@ -4188,6 +4136,8 @@ Do not invent objections or turn speculative risks into blockers. Stop when theexecute: async (toolCallId, rawParams, signal, onUpdate) => {const prepared = typeof rawParams === "object" && rawParams !== null&& this.preparedPathToolArgs.has(rawParams);+ // A prepared call was already checked by preparePathToolCall.+ if (!prepared) rejectConflictingAliasedParams(toolName, rawParams);const params = prepared? this.preparedPathToolArgs.get(rawParams as object): normalizeToolParams(toolName, rawParams);@@ -6897,6 +6847,7 @@ Do not invent objections or turn speculative risks into blockers. Stop when theawait this.waitForBatchWritableDelegations(context.toolCall.id);}if (!PATH_SCOPED_INSTRUCTION_TOOLS.has(name)) return;+ rejectConflictingAliasedParams(name, context.args);const params = normalizeToolParams(name, context.args);requireAliasedParams(name, params);await this.loadPathInstructions(name, params, apply);diff --git a/packages/agent-runtime/src/tool-param-aliases.ts b/packages/agent-runtime/src/tool-param-aliases.tsnew file mode 100644index 000000000..5c561cf66--- /dev/null+++ b/packages/agent-runtime/src/tool-param-aliases.ts@@ -0,0 +1,108 @@+/**+ * Argument names models reach for instead of ours, mapped to the canonical+ * name. Every strong model has `file_path`/`query` burned in from pretraining+ * and sends them regardless of what the schema says, so the schema accepts both+ * spellings and `normalizeToolParams` folds the alias away before the host sees+ * the call (D273). Weaker models — issue #454 pinned longcat 2.0 — reach for+ * `filepath` / `filename` / `filePath` / `file` instead; folding those the same+ * way rescues the turn before the model gives up on the tool and silently falls+ * back to Bash.+ */+const PATH_ARG_ALIASES = {+ file_path: "path",+ filepath: "path",+ filePath: "path",+ filename: "path",+ fileName: "path",+ file: "path",+} as const;++export const TOOL_PARAM_ALIASES: Record<string, Record<string, string>> = {+ Read: { ...PATH_ARG_ALIASES },+ Write: { ...PATH_ARG_ALIASES },+ Edit: { ...PATH_ARG_ALIASES },+ BrowserPreview: { ...PATH_ARG_ALIASES },+ Glob: { query: "pattern" },+ Grep: { query: "pattern" },+};++/** Longest argument value quoted back in a diagnostic. */+const MAX_QUOTED_VALUE_CHARS = 200;++function isRecord(value: unknown): value is Record<string, unknown> {+ return typeof value === "object" && value !== null && !Array.isArray(value);+}++function invalidArgument(message: string): Error {+ return Object.assign(new Error(message), { errorCode: "INVALID_ARGUMENT" });+}++function quoted(value: unknown): string {+ let text: string;+ try {+ text = JSON.stringify(value) ?? String(value);+ } catch {+ text = String(value);+ }+ return text.length > MAX_QUOTED_VALUE_CHARS+ ? `${text.slice(0, MAX_QUOTED_VALUE_CHARS)}…`+ : text;+}++/**+ * Fails a call that names one argument under several spellings with different+ * values, e.g. `{"path": "src/a.tsx here?", "file_path": "src/a.tsx"}` (#2552).+ * Folding would have to pick one and silently drop the other, and either guess+ * can run the operation on a path the model did not mean; naming both values+ * lets the next call send exactly one. Identical values are one argument and+ * pass. Runs on the raw arguments, before `normalizeToolParams` drops aliases.+ */+export function rejectConflictingAliasedParams(toolName: string, params: unknown): void {+ const aliases = TOOL_PARAM_ALIASES[toolName];+ if (!aliases || !isRecord(params)) return;+ for (const canonical of new Set(Object.values(aliases))) {+ const spellings = [+ canonical,+ ...Object.keys(aliases).filter((alias) => aliases[alias] === canonical),+ ].filter((name) => params[name] !== undefined);+ const first = spellings[0];+ if (first === undefined) continue;+ const differing = spellings.filter((name) => !Object.is(params[name], params[first]));+ if (differing.length === 0) continue;+ const named = [first, ...differing]+ .map((name) => `\`${name}\` = ${quoted(params[name])}`)+ .join(", ");+ throw invalidArgument(+ `Invalid arguments for ${toolName}: ${named} name the same argument with different values. Send only \`${canonical}\`, with the exact intended value. Example: {"${canonical}": "..."}.`,+ );+ }+}++/**+ * Fails a call that named neither the canonical argument nor its alias. Without+ * this the now-optional canonical argument would reach the host as `undefined`+ * and surface as a confusing host-side error instead of a schema one.+ */+export function requireAliasedParams(toolName: string, params: unknown): void {+ const aliases = TOOL_PARAM_ALIASES[toolName];+ if (!aliases || !isRecord(params)) return;+ for (const canonical of new Set(Object.values(aliases))) {+ if (params[canonical] !== undefined) continue;+ // A weaker model that keeps hitting this error gives up on the tool and+ // silently switches to Bash (issue #454). Naming the accepted spellings and+ // showing a minimal example lets the next call self-correct instead of the+ // whole turn falling back to shell.+ const acceptedAliases = Object.keys(aliases).filter(+ (alias) => aliases[alias] === canonical,+ );+ const aliasHint =+ acceptedAliases.length > 0+ ? ` (the alias${acceptedAliases.length > 1 ? "es" : ""} ${acceptedAliases+ .map((name) => `\`${name}\``)+ .join(", ")} ${acceptedAliases.length > 1 ? "are" : "is"} also accepted)`+ : "";+ throw invalidArgument(+ `Invalid arguments for ${toolName}: \`${canonical}\` is required${aliasHint}. Example: {"${canonical}": "..."}.`,+ );+ }+}