diff --git a/packages/coding-agent/src/cli/args.ts b/packages/coding-agent/src/cli/args.ts index af0414068..a52f1530b 100644 --- a/packages/coding-agent/src/cli/args.ts +++ b/packages/coding-agent/src/cli/args.ts @@ -5,7 +5,7 @@ import { type Effort, THINKING_EFFORTS } from "@oh-my-pi/pi-ai"; import { APP_NAME, CONFIG_DIR_NAME, logger } from "@oh-my-pi/pi-utils"; import chalk from "chalk"; import { parseEffort } from "../thinking"; -import { BUILTIN_TOOLS } from "../tools"; +import { BUILTIN_TOOL_NAMES } from "../tools/builtin-names"; import { OPTIONAL_FLAGS, OPTIONAL_VALUE_FLAGS, @@ -72,8 +72,8 @@ export interface Args { const PARSE_DEPS: ParseDeps = { logger, parseEffort, - BUILTIN_TOOLS, - THINKING_EFFORTS, + builtinToolNames: BUILTIN_TOOL_NAMES, + thinkingEfforts: THINKING_EFFORTS, }; export function parseArgs(inputArgs: string[], extensionFlags?: Map): Args { diff --git a/packages/coding-agent/src/cli/completion-gen.ts b/packages/coding-agent/src/cli/completion-gen.ts index 33e8b0458..60aecbc17 100644 --- a/packages/coding-agent/src/cli/completion-gen.ts +++ b/packages/coding-agent/src/cli/completion-gen.ts @@ -15,7 +15,7 @@ * knob and is keyed by flag name so it stays stable as flags are added. */ import type { ArgDescriptor, CliConfig, CommandCtor, FlagDescriptor } from "@oh-my-pi/pi-utils/cli"; -import { BUILTIN_TOOLS } from "../tools"; +import { BUILTIN_TOOL_NAMES } from "../tools/builtin-names"; export type Shell = "bash" | "zsh" | "fish"; @@ -77,7 +77,7 @@ function flagValue(name: string, desc: FlagDescriptor): ValueSource { if (MODEL_FLAGS[name]) return { kind: "models", multiple: false }; if (name === "models") return { kind: "models", multiple: true }; if (SESSION_FLAGS[name]) return { kind: "sessions" }; - if (name === "tools") return { kind: "list", values: Object.keys(BUILTIN_TOOLS) }; + if (name === "tools") return { kind: "list", values: BUILTIN_TOOL_NAMES }; if (DIR_FLAGS[name]) return { kind: "dir" }; if (desc.kind === "integer") return { kind: "value" }; return { kind: "file" }; diff --git a/packages/coding-agent/src/cli/flag-tables.ts b/packages/coding-agent/src/cli/flag-tables.ts index 0be7b2717..c078b5e04 100644 --- a/packages/coding-agent/src/cli/flag-tables.ts +++ b/packages/coding-agent/src/cli/flag-tables.ts @@ -47,8 +47,8 @@ import type { Args } from "./args"; export interface ParseDeps { logger: { warn: (message: string, meta?: Record) => void }; parseEffort: (value: string | null | undefined) => Effort | undefined; - BUILTIN_TOOLS: Record; - THINKING_EFFORTS: readonly string[]; + builtinToolNames: readonly string[]; + thinkingEfforts: readonly string[]; } export type StringSetter = (result: Args, value: string, deps: ParseDeps) => void; @@ -146,12 +146,12 @@ export const STRING_SETTERS: Record = { .filter(Boolean); const valid: string[] = []; for (const name of names) { - if (name in deps.BUILTIN_TOOLS) { + if (deps.builtinToolNames.includes(name)) { valid.push(name); } else { deps.logger.warn("Unknown tool passed to --tools", { tool: name, - validTools: Object.keys(deps.BUILTIN_TOOLS), + validTools: deps.builtinToolNames, }); } } @@ -164,7 +164,7 @@ export const STRING_SETTERS: Record = { } else { deps.logger.warn("Invalid thinking level passed to --thinking", { level: value, - validThinkingLevels: deps.THINKING_EFFORTS, + validThinkingLevels: deps.thinkingEfforts, }); } }, diff --git a/packages/coding-agent/src/tools/builtin-names.ts b/packages/coding-agent/src/tools/builtin-names.ts new file mode 100644 index 000000000..853c24ec0 --- /dev/null +++ b/packages/coding-agent/src/tools/builtin-names.ts @@ -0,0 +1,33 @@ +export const BUILTIN_TOOL_NAMES = [ + "read", + "bash", + "edit", + "ast_grep", + "ast_edit", + "render_mermaid", + "ask", + "debug", + "eval", + "ssh", + "github", + "find", + "search", + "lsp", + "inspect_image", + "browser", + "checkpoint", + "rewind", + "task", + "job", + "irc", + "todo_write", + "web_search", + "search_tool_bm25", + "write", + "memory_edit", + "retain", + "recall", + "reflect", +] as const; + +export type BuiltinToolName = (typeof BUILTIN_TOOL_NAMES)[number]; diff --git a/packages/coding-agent/src/tools/index.ts b/packages/coding-agent/src/tools/index.ts index 973823980..a8bb4ec8f 100644 --- a/packages/coding-agent/src/tools/index.ts +++ b/packages/coding-agent/src/tools/index.ts @@ -31,6 +31,7 @@ import { AstEditTool } from "./ast-edit"; import { AstGrepTool } from "./ast-grep"; import { BashTool } from "./bash"; import { BrowserTool } from "./browser"; +import type { BuiltinToolName } from "./builtin-names"; import { type CheckpointState, CheckpointTool, RewindTool } from "./checkpoint"; import { DebugTool } from "./debug"; import { EvalTool } from "./eval"; @@ -295,7 +296,7 @@ export function computeEssentialBuiltinNames(settings: Settings): string[] { * Public callable factory map. External callers may invoke `BUILTIN_TOOLS.read(session)` or * `BUILTIN_TOOLS[name](session)` to construct a tool directly. */ -export const BUILTIN_TOOLS: Record = { +export const BUILTIN_TOOLS: Record = { read: s => new ReadTool(s), bash: s => new BashTool(s), edit: s => new EditTool(s), @@ -335,7 +336,7 @@ export const HIDDEN_TOOLS: Record = { goal: s => new GoalTool(s), }; -export type ToolName = keyof typeof BUILTIN_TOOLS; +export type ToolName = BuiltinToolName; /** * Create tools from BUILTIN_TOOLS registry.