The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(tools): the retired names answer to their variants, and reads stop asking
Davidb77a1f1c910d
diff --git a/src/api/mcp/__tests__/tool-merge-redirect.test.ts b/src/api/mcp/__tests__/tool-merge-redirect.test.tsindex 70418ee6..36498f17 100644--- a/src/api/mcp/__tests__/tool-merge-redirect.test.ts+++ b/src/api/mcp/__tests__/tool-merge-redirect.test.ts@@ -34,6 +34,7 @@ vi.mock('../../../lib/workflow-engine', () => ({ WorkflowEngine: class {} }))import { runRetiredTool, RETIRED_TOOL_NAMES, registerBuiltinTools } from '../builtin-tools'import { ToolRegistry } from '../tool-registry'+import { DEFAULT_PERMISSIONS } from '../types'import { setReadOnlyShellTurn } from '../../agent-context'beforeEach(() => {@@ -174,3 +175,50 @@ describe('retired names survive the step executor (executeParallel)', () => {expect([...libNames].sort()).toEqual([...RETIRED_EXECUTOR_NAMES].sort())})})++// A9. The registry answers 'confirm' for every name it cannot find, and a+// retired name has no definition to look up. So Agent mode raised an approval+// dialog for `git_status`, a fixed `git status --porcelain=2 --branch`, and the+// user had to click it before the run could continue. The decision is made in+// getPermissionLevelWithOverrides (useAgentChat: needsApproval = permLevel !==+// 'auto'), which is why it is pinned HERE and not only on the pure helper.+describe('a retired name gets a permission, not a shrug', () => {+ const registry = new ToolRegistry()+ registerBuiltinTools(registry)+ const perms = DEFAULT_PERMISSIONS+ const level = (name: string) => registry.getPermissionLevelWithOverrides(name, perms, {})++ it('read-only retired names run without an approval dialog', () => {+ expect(perms.terminal).toBe('confirm')+ for (const n of ['git_status', 'git_log', 'git_diff', 'shell_task_status', 'shell_task_list',+ 'system_info', 'process_list', 'get_current_time']) {+ expect(level(n), n).toBe('auto')+ }+ })++ it('mutating retired names still stop for the user', () => {+ for (const n of ['git_commit', 'git_push', 'gh_pr_create', 'project_init', 'run_tests',+ 'code_execute', 'shell_execute_background', 'shell_task_kill']) {+ expect(level(n), n).toBe('confirm')+ }+ })++ it('negative control: a registered tool keeps its own category level', () => {+ expect(level('shell_execute')).toBe('confirm')+ expect(level('web_search')).toBe('auto')+ })++ it('negative control: a name that was never ours is still confirm', () => {+ expect(level('teleport')).toBe('confirm')+ expect(level('git_blame')).toBe('confirm')+ })++ it('a per-tool override still wins over the retired default', () => {+ // permissionStore's overrides are the user speaking; the A9 default must+ // not outrank them in either direction.+ expect(registry.getPermissionLevelWithOverrides('git_status', perms, { git_status: 'confirm' }))+ .toBe('confirm')+ expect(registry.getPermissionLevelWithOverrides('git_commit', perms, { git_commit: 'auto' }))+ .toBe('auto')+ })+})diff --git a/src/api/mcp/builtin-tools.ts b/src/api/mcp/builtin-tools.tsindex cad44ea2..97b9a1d5 100644--- a/src/api/mcp/builtin-tools.ts+++ b/src/api/mcp/builtin-tools.ts@@ -14,6 +14,7 @@ import { writeTodos, summarizeTodos } from '../../stores/todoStore'import { isMlxImageHost, generateMlxImageDataUrl, listMlxImageModels, type MlxImageModel } from '../mlx-image'import { getVideoStatus, listVideoModels, generateVideo as generateMlxVideo, getVideoProgress, cancelVideo, type VideoModel } from '../mlx-video'import { pathToFileUrl } from '../../lib/local-media-url'+import { RETIRED_MUTATING_NAMES } from '../../lib/retired-tools'/*** Helper: current chat id (+ folder workspace) as a fragment to spread into@@ -1399,10 +1400,9 @@ const RETIRED_EXECUTORS: Record<string, (args: Record<string, any>) => Promise<sshell_task_list: executeShellTaskList,}-const RETIRED_MUTATING = new Set([- 'git_commit', 'git_push', 'gh_pr_create', 'project_init', 'run_tests',- 'code_execute', 'shell_execute_background', 'shell_task_kill',-])+// The mutating half moved to lib/retired-tools.ts with A9: the registry's+// permission lookup needs the same split, and a second copy of a set that+// decides "may this run unattended" is exactly the copy that drifts./*** Names that still resolve through the redirect. The canonical list lives in@@ -1410,7 +1410,8 @@ const RETIRED_MUTATING = new Set([* re-exported here for the executors' callers. A test pins both to* RETIRED_EXECUTORS' keys.*/-export { RETIRED_TOOL_NAMES } from '../../lib/retired-tools'+export { RETIRED_TOOL_NAMES, RETIRED_MUTATING_NAMES } from '../../lib/retired-tools'+export const RETIRED_EXECUTOR_NAMES: ReadonlySet<string> = new Set(Object.keys(RETIRED_EXECUTORS))/**@@ -1426,7 +1427,7 @@ export async function runRetiredTool(if (!run) return null// The read-only gate lives on shell_execute's command classifier; a retired// mutating name would walk straight past it via this redirect.- if (isReadOnlyShellTurn() && RETIRED_MUTATING.has(name)) {+ if (isReadOnlyShellTurn() && RETIRED_MUTATING_NAMES.has(name)) {return `Refused: this turn is read-only (/review or Code-Review Mode); ${name} changes state.`}const result = await run(args)diff --git a/src/api/mcp/tool-registry.ts b/src/api/mcp/tool-registry.tsindex d6afe0f5..449f4167 100644--- a/src/api/mcp/tool-registry.ts+++ b/src/api/mcp/tool-registry.ts@@ -4,7 +4,7 @@ import type { MCPToolDefinition, PermissionMap, PermissionLevel } from './types'import type { OllamaTool } from '../../types/agent-mode'import type { ToolDefinition } from '../providers/types'import { MUTATING_TOOLS } from '../../lib/mutating-tools'-import { RETIRED_TOOL_NAMES } from '../../lib/retired-tools'+import { RETIRED_TOOL_NAMES, retiredPermissionLevel } from '../../lib/retired-tools'type ToolExecutor = (args: Record<string, any>) => Promise<string>/**@@ -95,8 +95,13 @@ export class ToolRegistry {getPermissionLevel(toolName: string, permissions: PermissionMap): PermissionLevel {const tool = this.tools.get(toolName)?.definition- if (!tool) return 'confirm'- return permissions[tool.category]+ if (tool) return permissions[tool.category]+ // A9: a retired name has no definition to read a category off, and the+ // 'confirm' below meant Agent mode opened an approval dialog for+ // `git_status`, whose executor is one fixed read. Read-only retired names+ // run unattended, mutating ones keep confirm, blocked stays blocked.+ // Anything else is genuinely unknown and confirm is the honest answer.+ return retiredPermissionLevel(toolName, permissions) ?? 'confirm'}/**diff --git a/src/lib/__tests__/retired-name-variants.test.ts b/src/lib/__tests__/retired-name-variants.test.tsnew file mode 100644index 00000000..274da1b2--- /dev/null+++ b/src/lib/__tests__/retired-name-variants.test.ts@@ -0,0 +1,205 @@+/**+ * A9, the rest of the retired names.+ *+ * The 2.6.6 merge kept the sixteen old names running: the registry redirects+ * them and the result carries a one-line note pointing at the new call form.+ * Two holes were left in that promise, and both cost a whole step each time+ * they were hit.+ *+ * 1. Only a SPOTLESS name reached the redirect. `functions.git_status` (the+ * harmony recipient namespace, captured live on gpt-oss via LU Cloud) and+ * `run_code` (a spelling models bring from elsewhere) went through+ * canonicalToolName, matched nothing in `known`, and arrived at the+ * executor unchanged, where they failed as "Unknown tool". The repair+ * ladder for decorated names existed; it just stopped at the registered+ * catalog.+ *+ * 2. The registry answers 'confirm' for anything it cannot find, so in Agent+ * mode every retired name raised an approval dialog. Including+ * `git_status`, whose entire executor is one fixed+ * `git status --porcelain=2 --branch`. A dialog for a read, on a name the+ * model only used because its own context taught it the old spelling.+ *+ * The negative controls matter more than usual here: the fix must not let a+ * name be rerouted AWAY from a live tool, and must not hand a mutating name an+ * unattended run.+ *+ * Run: npx vitest run src/lib/__tests__/retired-name-variants.test.ts+ */+import { describe, it, expect } from 'vitest'+import { canonicalToolName, parseLooseToolCalls } from '../loose-tool-parse'+import {+ RETIRED_TOOL_NAMES,+ RETIRED_MUTATING_NAMES,+ isRetiredReadOnly,+ retiredPermissionLevel,+} from '../retired-tools'+import { DEFAULT_PERMISSIONS } from '../../api/mcp/types'+import type { PermissionMap } from '../../api/mcp/types'++/** The coding catalog as it stands after the merge: no retired name in it. */+const KNOWN = [+ 'file_read', 'file_write', 'file_edit', 'file_list', 'file_search',+ 'shell_execute', 'web_search', 'web_fetch', 'todo_write', 'pr_resume',+ 'image_generate', 'video_generate', 'run_workflow', 'delegate_task', 'screenshot',+]++describe('canonicalToolName maps the variants onto the retired map', () => {+ it('the plain name, which the registry already redirected', () => {+ expect(canonicalToolName('git_status', KNOWN)).toBe('git_status')+ })++ it.each([+ ['functions.git_status', 'git_status'],+ ['functions.git_commit', 'git_commit'],+ ['functions.run_tests', 'run_tests'],+ ])('the harmony recipient namespace: %s', (sent, want) => {+ expect(canonicalToolName(sent, KNOWN)).toBe(want)+ })++ it.each([+ ['git_status<|channel|>commentary', 'git_status'],+ ['git_log<|constrain|>json', 'git_log'],+ ['functions.git_diff<|channel|>commentary', 'git_diff'],+ ])('a leaked control token welded onto the name: %s', (sent, want) => {+ expect(canonicalToolName(sent, KNOWN)).toBe(want)+ })++ it.each([+ ['run_code', 'code_execute'],+ ['execute_code', 'code_execute'],+ ['run_python', 'code_execute'],+ ['run_test', 'run_tests'],+ ['list_processes', 'process_list'],+ ['current_time', 'get_current_time'],+ ])('a near-miss spelling a model brought from elsewhere: %s', (sent, want) => {+ expect(canonicalToolName(sent, KNOWN)).toBe(want)+ })++ it.each([+ ['gitStatus', 'git_status'],+ ['git-status', 'git_status'],+ ['GIT_STATUS', 'git_status'],+ ['git status', 'git_status'],+ ['shell task list', 'shell_task_list'],+ ])('casing and punctuation: %s', (sent, want) => {+ expect(canonicalToolName(sent, KNOWN)).toBe(want)+ })++ it('every retired name survives its own namespace prefix', () => {+ for (const name of RETIRED_TOOL_NAMES) {+ expect(canonicalToolName(`functions.${name}`, KNOWN), name).toBe(name)+ }+ })++ // ── negative controls ──++ it('a registered tool always wins over a retired one', () => {+ // shell_execute is live and code_execute is retired. A catalog that still+ // had code_execute would be a different question; this one must never+ // reroute a live name.+ expect(canonicalToolName('shell_execute', KNOWN)).toBe('shell_execute')+ expect(canonicalToolName('functions.shell_execute', KNOWN)).toBe('shell_execute')+ expect(canonicalToolName('run_shell', KNOWN)).toBe('shell_execute')+ // And with code_execute BACK in the known list it resolves there, not+ // through the retired ladder, because known is walked first.+ expect(canonicalToolName('run_code', [...KNOWN, 'code_execute'])).toBe('code_execute')+ })++ it('a name that was never ours still comes back unchanged', () => {+ expect(canonicalToolName('teleport', KNOWN)).toBe('teleport')+ expect(canonicalToolName('functions.teleport', KNOWN)).toBe('functions.teleport')+ expect(canonicalToolName('git_blame', KNOWN)).toBe('git_blame')+ expect(canonicalToolName('', KNOWN)).toBe('')+ })++ it('an MCP tool whose real name carries dots is left alone', () => {+ const mcp = [...KNOWN, 'mcp.server.git_status']+ expect(canonicalToolName('mcp.server.git_status', mcp)).toBe('mcp.server.git_status')+ })+})++describe('the loose parse lifts a retired name out of prose', () => {+ it('function syntax, which is how the weak models write it', () => {+ const { calls } = parseLooseToolCalls('Let me check: git_log(limit=5)', KNOWN)+ expect(calls).toHaveLength(1)+ expect(calls[0].name).toBe('git_log')+ expect(calls[0].arguments).toEqual({ limit: 5 })+ })++ it('a JSON object naming a retired tool', () => {+ const { calls } = parseLooseToolCalls('{"name":"git_status","arguments":{"cwd":"."}}', KNOWN)+ expect(calls.map((c) => c.name)).toEqual(['git_status'])+ })++ it('the bare-name-plus-brace form', () => {+ const { calls } = parseLooseToolCalls('[run_tests {"path": "src"}]', KNOWN)+ expect(calls.map((c) => c.name)).toEqual(['run_tests'])+ })++ it('negative control: prose that only mentions a retired name is not a call', () => {+ const { calls } = parseLooseToolCalls('I would normally use git_status here.', KNOWN)+ expect(calls).toEqual([])+ })++ it('negative control: an unknown name in the same shape is still ignored', () => {+ const { calls } = parseLooseToolCalls('teleport(target="mars")', KNOWN)+ expect(calls).toEqual([])+ })+})++describe('the permission a retired name resolves to', () => {+ const perms = DEFAULT_PERMISSIONS++ it('the split covers every retired name exactly once', () => {+ for (const n of RETIRED_MUTATING_NAMES) expect(RETIRED_TOOL_NAMES.has(n), n).toBe(true)+ const readOnly = [...RETIRED_TOOL_NAMES].filter(isRetiredReadOnly)+ expect(readOnly.length + RETIRED_MUTATING_NAMES.size).toBe(RETIRED_TOOL_NAMES.size)+ expect(readOnly.sort()).toEqual([+ 'get_current_time', 'git_diff', 'git_log', 'git_status',+ 'process_list', 'shell_task_list', 'shell_task_status', 'system_info',+ ])+ })++ it('a read-only retired name runs unattended', () => {+ // DEFAULT_PERMISSIONS has terminal on 'confirm'; that is the dialog the+ // user had to click through for a `git status`.+ expect(perms.terminal).toBe('confirm')+ for (const n of ['git_status', 'git_log', 'git_diff', 'shell_task_status', 'shell_task_list']) {+ expect(retiredPermissionLevel(n, perms), n).toBe('auto')+ }+ })++ it('a mutating retired name still asks', () => {+ for (const n of ['git_commit', 'git_push', 'gh_pr_create', 'project_init', 'run_tests',+ 'code_execute', 'shell_execute_background', 'shell_task_kill']) {+ expect(retiredPermissionLevel(n, perms), n).toBe('confirm')+ }+ })++ it('a blocked category blocks the redirect too, on both halves', () => {+ const blocked: PermissionMap = { ...perms, terminal: 'blocked', system: 'blocked' }+ expect(retiredPermissionLevel('git_status', blocked)).toBe('blocked')+ expect(retiredPermissionLevel('git_commit', blocked)).toBe('blocked')+ expect(retiredPermissionLevel('system_info', blocked)).toBe('blocked')+ })++ it('the three system probes read the system category, not terminal', () => {+ // They redirect into a backend probe, not a shell, and that is the+ // category they always had. Blocking the terminal must not take the clock+ // with it, and blocking system must not leave them running.+ const noTerminal: PermissionMap = { ...perms, terminal: 'blocked' }+ for (const n of ['system_info', 'process_list', 'get_current_time']) {+ expect(retiredPermissionLevel(n, noTerminal), n).toBe('auto')+ }+ const noSystem: PermissionMap = { ...perms, system: 'blocked' }+ expect(retiredPermissionLevel('system_info', noSystem)).toBe('blocked')+ expect(retiredPermissionLevel('git_status', noSystem)).toBe('auto')+ })++ it('negative control: a name that was never ours gets no answer here', () => {+ expect(retiredPermissionLevel('teleport', perms)).toBeUndefined()+ expect(retiredPermissionLevel('shell_execute', perms)).toBeUndefined()+ expect(retiredPermissionLevel('', perms)).toBeUndefined()+ })+})diff --git a/src/lib/loose-tool-parse.ts b/src/lib/loose-tool-parse.tsindex 9bf3b43d..ea1cbc96 100644--- a/src/lib/loose-tool-parse.ts+++ b/src/lib/loose-tool-parse.ts@@ -22,6 +22,22 @@import { findBalancedObjects, balancedObjectAt } from './json-scan'import { repairJson } from './tool-call-repair'import { parseHermesToolCalls } from '../api/hermes-tool-calling'+import { RETIRED_TOOL_NAMES } from './retired-tools'++/**+ * A9. The sixteen names the 2.6.6 merge retired are not in any `known` list+ * any more, but they still EXECUTE: the registry redirects them and the result+ * carries a note naming the new call form. Every recogniser in this file was+ * gated on `known` alone, so the redirect only ever fired for a name that+ * arrived spotless through the native channel. `functions.git_status` (the+ * harmony recipient namespace, seen live on gpt-oss), `git_status` written+ * into prose, `run_code` from a model that learned that spelling elsewhere:+ * all three walked past the redirect and came back as "Unknown tool".+ *+ * A registered tool always wins; this list is only consulted after `known`+ * has had its full ladder, so nothing can be rerouted away from a live tool.+ */+const RETIRED_NAMES: string[] = [...RETIRED_TOOL_NAMES]export interface LooseToolCall {name: string@@ -119,7 +135,8 @@ function parseJsonObjectCalls(text: string, known: Set<string>): { call: LooseTo*/export function parseLooseToolCalls(text: string, known: string[]): LooseParseResult {if (!text || !text.trim()) return { calls: [], matched: [] }- const knownSet = new Set(known)+ // Retired names are recognisable AND runnable, so they belong in the net.+ const knownSet = new Set([...known, ...RETIRED_NAMES])const calls: LooseToolCall[] = []const matched: string[] = []const seen = new Set<string>()@@ -204,10 +221,17 @@ const TOOL_NAME_ALIASES: Record<string, string> = {text_to_video: 'video_generate', image_to_video: 'video_generate',web: 'web_search', search: 'web_search', fetch: 'web_fetch', read_file: 'file_read', write_file: 'file_write',list_files: 'file_list', search_files: 'file_search', run_shell: 'shell_execute', run_code: 'code_execute',+ // Retired targets (A9). These resolve only because the retired list is the+ // second ladder in canonicalToolName; while the name was registered they+ // were dead weight, and the moment it retired they became the difference+ // between a redirect and a wasted step.+ execute_code: 'code_execute', run_python: 'code_execute', python_exec: 'code_execute',+ run_test: 'run_tests', test_run: 'run_tests',+ list_processes: 'process_list', current_time: 'get_current_time',}/** Exact → lowercase → alias → punctuation-insensitive. Undefined if none hit. */-function matchKnown(name: string, known: string[]): string | undefined {+function matchKnown(name: string, known: readonly string[]): string | undefined {if (!name) return undefinedif (known.includes(name)) return nameconst lc = name.toLowerCase()@@ -253,12 +277,18 @@ function toolNameCandidates(name: string): string[] {*/export function canonicalToolName(name: string, known: string[]): string {if (!name) return name- const direct = matchKnown(name, known)- if (direct) return direct- for (const candidate of toolNameCandidates(name)) {- if (candidate === name) continue- const hit = matchKnown(candidate, known)- if (hit) return hit+ // Registered tools first, all the way down the ladder, THEN the retired+ // names (A9). Order is the safety property: a live tool can never lose a+ // call to a retired one, and a name that is neither still comes back+ // unchanged so the executor can say "Unknown tool" honestly.+ for (const list of [known, RETIRED_NAMES]) {+ const direct = matchKnown(name, list)+ if (direct) return direct+ for (const candidate of toolNameCandidates(name)) {+ if (candidate === name) continue+ const hit = matchKnown(candidate, list)+ if (hit) return hit+ }}return name}diff --git a/src/lib/retired-tools.ts b/src/lib/retired-tools.tsindex 3fc67281..29b71dea 100644--- a/src/lib/retired-tools.ts+++ b/src/lib/retired-tools.ts@@ -7,6 +7,8 @@* cycle tool-registry -> builtin-tools -> sub-agent -> tool-registry.* A unit test asserts this list equals the executor map's keys.*/+import type { PermissionLevel } from '../api/mcp/types'+export const RETIRED_TOOL_NAMES: ReadonlySet<string> = new Set(['git_status','git_log',@@ -25,3 +27,63 @@ export const RETIRED_TOOL_NAMES: ReadonlySet<string> = new Set(['shell_task_kill','shell_task_list',])++/**+ * The retired names that CHANGE something. The split used to live in+ * builtin-tools as RETIRED_MUTATING, where only the read-only-turn refusal+ * could see it; A9 needs the same answer in the registry's permission lookup,+ * and two copies of a security-relevant set drift. A drift test pins that this+ * set is a subset of the names above.+ */+export const RETIRED_MUTATING_NAMES: ReadonlySet<string> = new Set([+ 'git_commit',+ 'git_push',+ 'gh_pr_create',+ 'project_init',+ 'run_tests',+ 'code_execute',+ 'shell_execute_background',+ 'shell_task_kill',+])++/**+ * Which permission category a retired name borrows now that it has no+ * definition of its own. Everything that redirects into a shell command is+ * terminal; the three that redirect into a backend probe keep the system+ * category they always had, so blocking one does not silently block the other.+ */+const RETIRED_CATEGORY: Record<string, 'terminal' | 'system'> = {+ system_info: 'system',+ process_list: 'system',+ get_current_time: 'system',+}++/** True for a retired name that only looks at things. */+export function isRetiredReadOnly(name: string): boolean {+ return RETIRED_TOOL_NAMES.has(name) && !RETIRED_MUTATING_NAMES.has(name)+}++/**+ * The permission a retired name resolves to, or undefined when the name was+ * never ours.+ *+ * A9. The registry answers 'confirm' for anything it cannot find, so every+ * retired name asked for an approval dialog in Agent mode, including+ * `git_status`, whose whole executor is one fixed `git status --porcelain=2+ * --branch`. That is a dialog for a read, on a name the model only used+ * because its own context taught it the old spelling, and the user has to+ * click it to get anywhere.+ *+ * So: read-only retired names run unattended, mutating ones keep the confirm+ * they would have had as terminal tools, and a BLOCKED category still blocks+ * both, because the redirect is not a way around a switched-off permission.+ */+export function retiredPermissionLevel(+ name: string,+ permissions: Record<string, PermissionLevel>,+): PermissionLevel | undefined {+ if (!RETIRED_TOOL_NAMES.has(name)) return undefined+ const category = RETIRED_CATEGORY[name] ?? 'terminal'+ if (permissions[category] === 'blocked') return 'blocked'+ return RETIRED_MUTATING_NAMES.has(name) ? 'confirm' : 'auto'+}