Fix CLI completion bootstrap tool imports

This commit is contained in:
Ogrodev
2026-06-01 22:37:01 -03:00
parent 069479e039
commit b4707629bf
5 changed files with 46 additions and 12 deletions
+3 -3
View File
@@ -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<string, { type: "boolean" | "string" }>): Args {
@@ -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" };
+5 -5
View File
@@ -47,8 +47,8 @@ import type { Args } from "./args";
export interface ParseDeps {
logger: { warn: (message: string, meta?: Record<string, unknown>) => void };
parseEffort: (value: string | null | undefined) => Effort | undefined;
BUILTIN_TOOLS: Record<string, unknown>;
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<string, StringSetter> = {
.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<string, StringSetter> = {
} else {
deps.logger.warn("Invalid thinking level passed to --thinking", {
level: value,
validThinkingLevels: deps.THINKING_EFFORTS,
validThinkingLevels: deps.thinkingEfforts,
});
}
},
@@ -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];
+3 -2
View File
@@ -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<string, ToolFactory> = {
export const BUILTIN_TOOLS: Record<BuiltinToolName, ToolFactory> = {
read: s => new ReadTool(s),
bash: s => new BashTool(s),
edit: s => new EditTool(s),
@@ -335,7 +336,7 @@ export const HIDDEN_TOOLS: Record<string, ToolFactory> = {
goal: s => new GoalTool(s),
};
export type ToolName = keyof typeof BUILTIN_TOOLS;
export type ToolName = BuiltinToolName;
/**
* Create tools from BUILTIN_TOOLS registry.