fix(coding-agent): use tool-name allowlists and remove cwd-bound singletons
- treat tools as a global allowlist across built-in, extension, and SDK tools - remove process-cwd singleton tool usage from SDK and CLI paths - add regression coverage for extension tool filtering closes #3452 closes #2835
This commit is contained in:
@@ -6,7 +6,6 @@ import type { ThinkingLevel } from "@mariozechner/pi-agent-core";
|
||||
import chalk from "chalk";
|
||||
import { APP_NAME, CONFIG_DIR_NAME, ENV_AGENT_DIR } from "../config.js";
|
||||
import type { ExtensionFlag } from "../core/extensions/types.js";
|
||||
import { allTools, type ToolName } from "../core/tools/index.js";
|
||||
|
||||
export type Mode = "text" | "json" | "rpc";
|
||||
|
||||
@@ -27,7 +26,7 @@ export interface Args {
|
||||
fork?: string;
|
||||
sessionDir?: string;
|
||||
models?: string[];
|
||||
tools?: ToolName[];
|
||||
tools?: string[];
|
||||
noTools?: boolean;
|
||||
extensions?: string[];
|
||||
noExtensions?: boolean;
|
||||
@@ -104,19 +103,10 @@ export function parseArgs(args: string[]): Args {
|
||||
} else if (arg === "--no-tools") {
|
||||
result.noTools = true;
|
||||
} else if (arg === "--tools" && i + 1 < args.length) {
|
||||
const toolNames = args[++i].split(",").map((s) => s.trim());
|
||||
const validTools: ToolName[] = [];
|
||||
for (const name of toolNames) {
|
||||
if (name in allTools) {
|
||||
validTools.push(name as ToolName);
|
||||
} else {
|
||||
result.diagnostics.push({
|
||||
type: "warning",
|
||||
message: `Unknown tool "${name}". Valid tools: ${Object.keys(allTools).join(", ")}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
result.tools = validTools;
|
||||
result.tools = args[++i]
|
||||
.split(",")
|
||||
.map((s) => s.trim())
|
||||
.filter((name) => name.length > 0);
|
||||
} else if (arg === "--thinking" && i + 1 < args.length) {
|
||||
const level = args[++i];
|
||||
if (isValidThinkingLevel(level)) {
|
||||
@@ -231,9 +221,9 @@ ${chalk.bold("Options:")}
|
||||
--no-session Don't save session (ephemeral)
|
||||
--models <patterns> Comma-separated model patterns for Ctrl+P cycling
|
||||
Supports globs (anthropic/*, *sonnet*) and fuzzy matching
|
||||
--no-tools Disable all built-in tools
|
||||
--tools <tools> Comma-separated list of tools to enable (default: read,bash,edit,write)
|
||||
Available: read, bash, edit, write, grep, find, ls
|
||||
--no-tools Disable all tools by default (built-in and extension)
|
||||
--tools <tools> Comma-separated allowlist of tool names to enable
|
||||
Applies to built-in and extension tools
|
||||
--thinking <level> Set thinking level: off, minimal, low, medium, high, xhigh
|
||||
--extension, -e <path> Load an extension file (can be used multiple times)
|
||||
--no-extensions, -ne Disable extension discovery (explicit -e paths still work)
|
||||
@@ -332,7 +322,7 @@ ${chalk.bold("Environment Variables:")}
|
||||
PI_SHARE_VIEWER_URL - Base URL for /share command (default: https://pi.dev/session/)
|
||||
PI_AI_ANTIGRAVITY_VERSION - Override Antigravity User-Agent version (e.g., 1.23.0)
|
||||
|
||||
${chalk.bold("Available Tools (default: read, bash, edit, write):")}
|
||||
${chalk.bold("Built-in Tool Names:")}
|
||||
read - Read file contents
|
||||
bash - Execute bash commands
|
||||
edit - Edit files with find/replace
|
||||
|
||||
@@ -9,7 +9,6 @@ import { DefaultResourceLoader, type DefaultResourceLoaderOptions, type Resource
|
||||
import { type CreateAgentSessionResult, createAgentSession } from "./sdk.js";
|
||||
import type { SessionManager } from "./session-manager.js";
|
||||
import { SettingsManager } from "./settings-manager.js";
|
||||
import type { Tool } from "./tools/index.js";
|
||||
|
||||
/**
|
||||
* Non-fatal issues collected while creating services or sessions.
|
||||
@@ -53,7 +52,7 @@ export interface CreateAgentSessionFromServicesOptions {
|
||||
model?: Model<any>;
|
||||
thinkingLevel?: ThinkingLevel;
|
||||
scopedModels?: Array<{ model: Model<any>; thinkingLevel?: ThinkingLevel }>;
|
||||
tools?: Tool[];
|
||||
tools?: string[];
|
||||
customTools?: ToolDefinition[];
|
||||
}
|
||||
|
||||
|
||||
@@ -150,6 +150,8 @@ export interface AgentSessionConfig {
|
||||
modelRegistry: ModelRegistry;
|
||||
/** Initial active built-in tool names. Default: [read, bash, edit, write] */
|
||||
initialActiveToolNames?: string[];
|
||||
/** Optional allowlist of tool names. When provided, only these tool names are exposed. */
|
||||
allowedToolNames?: string[];
|
||||
/**
|
||||
* Override base tools (useful for custom runtimes).
|
||||
*
|
||||
@@ -278,6 +280,7 @@ export class AgentSession {
|
||||
private _cwd: string;
|
||||
private _extensionRunnerRef?: { current?: ExtensionRunner };
|
||||
private _initialActiveToolNames?: string[];
|
||||
private _allowedToolNames?: Set<string>;
|
||||
private _baseToolsOverride?: Record<string, AgentTool>;
|
||||
private _sessionStartEvent: SessionStartEvent;
|
||||
private _extensionUIContext?: ExtensionUIContext;
|
||||
@@ -309,6 +312,7 @@ export class AgentSession {
|
||||
this._modelRegistry = config.modelRegistry;
|
||||
this._extensionRunnerRef = config.extensionRunnerRef;
|
||||
this._initialActiveToolNames = config.initialActiveToolNames;
|
||||
this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;
|
||||
this._baseToolsOverride = config.baseToolsOverride;
|
||||
this._sessionStartEvent = config.sessionStartEvent ?? { type: "session_start", reason: "startup" };
|
||||
|
||||
@@ -2221,6 +2225,8 @@ export class AgentSession {
|
||||
private _refreshToolRegistry(options?: { activeToolNames?: string[]; includeAllExtensionTools?: boolean }): void {
|
||||
const previousRegistryNames = new Set(this._toolRegistry.keys());
|
||||
const previousActiveToolNames = this.getActiveToolNames();
|
||||
const allowedToolNames = this._allowedToolNames;
|
||||
const isAllowedTool = (name: string): boolean => !allowedToolNames || allowedToolNames.has(name);
|
||||
|
||||
const registeredTools = this._extensionRunner.getAllRegisteredTools();
|
||||
const allCustomTools = [
|
||||
@@ -2229,15 +2235,17 @@ export class AgentSession {
|
||||
definition,
|
||||
sourceInfo: createSyntheticSourceInfo(`<sdk:${definition.name}>`, { source: "sdk" }),
|
||||
})),
|
||||
];
|
||||
].filter((tool) => isAllowedTool(tool.definition.name));
|
||||
const definitionRegistry = new Map<string, ToolDefinitionEntry>(
|
||||
Array.from(this._baseToolDefinitions.entries()).map(([name, definition]) => [
|
||||
name,
|
||||
{
|
||||
definition,
|
||||
sourceInfo: createSyntheticSourceInfo(`<builtin:${name}>`, { source: "builtin" }),
|
||||
},
|
||||
]),
|
||||
Array.from(this._baseToolDefinitions.entries())
|
||||
.filter(([name]) => isAllowedTool(name))
|
||||
.map(([name, definition]) => [
|
||||
name,
|
||||
{
|
||||
definition,
|
||||
sourceInfo: createSyntheticSourceInfo(`<builtin:${name}>`, { source: "builtin" }),
|
||||
},
|
||||
]),
|
||||
);
|
||||
for (const tool of allCustomTools) {
|
||||
definitionRegistry.set(tool.definition.name, {
|
||||
@@ -2265,10 +2273,12 @@ export class AgentSession {
|
||||
const runner = this._extensionRunner;
|
||||
const wrappedExtensionTools = wrapRegisteredTools(allCustomTools, runner);
|
||||
const wrappedBuiltInTools = wrapRegisteredTools(
|
||||
Array.from(this._baseToolDefinitions.values()).map((definition) => ({
|
||||
definition,
|
||||
sourceInfo: createSyntheticSourceInfo(`<builtin:${definition.name}>`, { source: "builtin" }),
|
||||
})),
|
||||
Array.from(this._baseToolDefinitions.values())
|
||||
.filter((definition) => isAllowedTool(definition.name))
|
||||
.map((definition) => ({
|
||||
definition,
|
||||
sourceInfo: createSyntheticSourceInfo(`<builtin:${definition.name}>`, { source: "builtin" }),
|
||||
})),
|
||||
runner,
|
||||
);
|
||||
|
||||
@@ -2278,11 +2288,17 @@ export class AgentSession {
|
||||
}
|
||||
this._toolRegistry = toolRegistry;
|
||||
|
||||
const nextActiveToolNames = options?.activeToolNames
|
||||
? [...options.activeToolNames]
|
||||
: [...previousActiveToolNames];
|
||||
const nextActiveToolNames = (
|
||||
options?.activeToolNames ? [...options.activeToolNames] : [...previousActiveToolNames]
|
||||
).filter((name) => isAllowedTool(name));
|
||||
|
||||
if (options?.includeAllExtensionTools) {
|
||||
if (allowedToolNames) {
|
||||
for (const toolName of this._toolRegistry.keys()) {
|
||||
if (allowedToolNames.has(toolName)) {
|
||||
nextActiveToolNames.push(toolName);
|
||||
}
|
||||
}
|
||||
} else if (options?.includeAllExtensionTools) {
|
||||
for (const tool of wrappedExtensionTools) {
|
||||
nextActiveToolNames.push(tool.name);
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@ import { SettingsManager } from "./settings-manager.js";
|
||||
import { isInstallTelemetryEnabled } from "./telemetry.js";
|
||||
import { time } from "./timings.js";
|
||||
import {
|
||||
allTools,
|
||||
bashTool,
|
||||
codingTools,
|
||||
createBashTool,
|
||||
createCodingTools,
|
||||
createEditTool,
|
||||
@@ -28,16 +25,8 @@ import {
|
||||
createReadOnlyTools,
|
||||
createReadTool,
|
||||
createWriteTool,
|
||||
editTool,
|
||||
findTool,
|
||||
grepTool,
|
||||
lsTool,
|
||||
readOnlyTools,
|
||||
readTool,
|
||||
type Tool,
|
||||
type ToolName,
|
||||
withFileMutationQueue,
|
||||
writeTool,
|
||||
} from "./tools/index.js";
|
||||
|
||||
export interface CreateAgentSessionOptions {
|
||||
@@ -58,8 +47,14 @@ export interface CreateAgentSessionOptions {
|
||||
/** Models available for cycling (Ctrl+P in interactive mode) */
|
||||
scopedModels?: Array<{ model: Model<any>; thinkingLevel?: ThinkingLevel }>;
|
||||
|
||||
/** Built-in tools to use. Default: codingTools [read, bash, edit, write] */
|
||||
tools?: Tool[];
|
||||
/**
|
||||
* Optional allowlist of tool names.
|
||||
*
|
||||
* When omitted, pi enables the default built-in tools (read, bash, edit, write)
|
||||
* and leaves extension/custom tools enabled.
|
||||
* When provided, only the listed tool names are enabled.
|
||||
*/
|
||||
tools?: string[];
|
||||
/** Custom tools to register (in addition to built-in tools). */
|
||||
customTools?: ToolDefinition[];
|
||||
|
||||
@@ -102,17 +97,6 @@ export type { Skill } from "./skills.js";
|
||||
export type { Tool } from "./tools/index.js";
|
||||
|
||||
export {
|
||||
// Pre-built tools (use process.cwd())
|
||||
readTool,
|
||||
bashTool,
|
||||
editTool,
|
||||
writeTool,
|
||||
grepTool,
|
||||
findTool,
|
||||
lsTool,
|
||||
codingTools,
|
||||
readOnlyTools,
|
||||
allTools as allBuiltInTools,
|
||||
withFileMutationQueue,
|
||||
// Tool factories (for custom cwd)
|
||||
createCodingTools,
|
||||
@@ -185,7 +169,7 @@ function getOpenRouterAttributionHeaders(
|
||||
* ```
|
||||
*/
|
||||
export async function createAgentSession(options: CreateAgentSessionOptions = {}): Promise<CreateAgentSessionResult> {
|
||||
const cwd = options.cwd ?? process.cwd();
|
||||
const cwd = options.cwd ?? options.sessionManager?.getCwd() ?? process.cwd();
|
||||
const agentDir = options.agentDir ?? getDefaultAgentDir();
|
||||
let resourceLoader = options.resourceLoader;
|
||||
|
||||
@@ -261,9 +245,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
||||
}
|
||||
|
||||
const defaultActiveToolNames: ToolName[] = ["read", "bash", "edit", "write"];
|
||||
const initialActiveToolNames: ToolName[] = options.tools
|
||||
? options.tools.map((t) => t.name).filter((n): n is ToolName => n in allTools)
|
||||
: defaultActiveToolNames;
|
||||
const initialActiveToolNames: string[] = options.tools ? [...options.tools] : defaultActiveToolNames;
|
||||
|
||||
let agent: Agent;
|
||||
|
||||
@@ -384,6 +366,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
||||
customTools: options.customTools,
|
||||
modelRegistry,
|
||||
initialActiveToolNames,
|
||||
allowedToolNames: options.tools,
|
||||
extensionRunnerRef,
|
||||
sessionStartEvent: options.sessionStartEvent,
|
||||
});
|
||||
|
||||
@@ -5,8 +5,6 @@ export {
|
||||
type BashToolDetails,
|
||||
type BashToolInput,
|
||||
type BashToolOptions,
|
||||
bashTool,
|
||||
bashToolDefinition,
|
||||
createBashTool,
|
||||
createBashToolDefinition,
|
||||
createLocalBashOperations,
|
||||
@@ -18,8 +16,6 @@ export {
|
||||
type EditToolDetails,
|
||||
type EditToolInput,
|
||||
type EditToolOptions,
|
||||
editTool,
|
||||
editToolDefinition,
|
||||
} from "./edit.js";
|
||||
export { withFileMutationQueue } from "./file-mutation-queue.js";
|
||||
export {
|
||||
@@ -29,8 +25,6 @@ export {
|
||||
type FindToolDetails,
|
||||
type FindToolInput,
|
||||
type FindToolOptions,
|
||||
findTool,
|
||||
findToolDefinition,
|
||||
} from "./find.js";
|
||||
export {
|
||||
createGrepTool,
|
||||
@@ -39,8 +33,6 @@ export {
|
||||
type GrepToolDetails,
|
||||
type GrepToolInput,
|
||||
type GrepToolOptions,
|
||||
grepTool,
|
||||
grepToolDefinition,
|
||||
} from "./grep.js";
|
||||
export {
|
||||
createLsTool,
|
||||
@@ -49,8 +41,6 @@ export {
|
||||
type LsToolDetails,
|
||||
type LsToolInput,
|
||||
type LsToolOptions,
|
||||
lsTool,
|
||||
lsToolDefinition,
|
||||
} from "./ls.js";
|
||||
export {
|
||||
createReadTool,
|
||||
@@ -59,8 +49,6 @@ export {
|
||||
type ReadToolDetails,
|
||||
type ReadToolInput,
|
||||
type ReadToolOptions,
|
||||
readTool,
|
||||
readToolDefinition,
|
||||
} from "./read.js";
|
||||
export {
|
||||
DEFAULT_MAX_BYTES,
|
||||
@@ -78,80 +66,90 @@ export {
|
||||
type WriteOperations,
|
||||
type WriteToolInput,
|
||||
type WriteToolOptions,
|
||||
writeTool,
|
||||
writeToolDefinition,
|
||||
} from "./write.js";
|
||||
|
||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||
import type { ToolDefinition } from "../extensions/types.js";
|
||||
import {
|
||||
type BashToolOptions,
|
||||
bashTool,
|
||||
bashToolDefinition,
|
||||
createBashTool,
|
||||
createBashToolDefinition,
|
||||
} from "./bash.js";
|
||||
import { createEditTool, createEditToolDefinition, editTool, editToolDefinition } from "./edit.js";
|
||||
import { createFindTool, createFindToolDefinition, findTool, findToolDefinition } from "./find.js";
|
||||
import { createGrepTool, createGrepToolDefinition, grepTool, grepToolDefinition } from "./grep.js";
|
||||
import { createLsTool, createLsToolDefinition, lsTool, lsToolDefinition } from "./ls.js";
|
||||
import {
|
||||
createReadTool,
|
||||
createReadToolDefinition,
|
||||
type ReadToolOptions,
|
||||
readTool,
|
||||
readToolDefinition,
|
||||
} from "./read.js";
|
||||
import { createWriteTool, createWriteToolDefinition, writeTool, writeToolDefinition } from "./write.js";
|
||||
import { type BashToolOptions, createBashTool, createBashToolDefinition } from "./bash.js";
|
||||
import { createEditTool, createEditToolDefinition, type EditToolOptions } from "./edit.js";
|
||||
import { createFindTool, createFindToolDefinition, type FindToolOptions } from "./find.js";
|
||||
import { createGrepTool, createGrepToolDefinition, type GrepToolOptions } from "./grep.js";
|
||||
import { createLsTool, createLsToolDefinition, type LsToolOptions } from "./ls.js";
|
||||
import { createReadTool, createReadToolDefinition, type ReadToolOptions } from "./read.js";
|
||||
import { createWriteTool, createWriteToolDefinition, type WriteToolOptions } from "./write.js";
|
||||
|
||||
export type Tool = AgentTool<any>;
|
||||
export type ToolDef = ToolDefinition<any, any>;
|
||||
|
||||
export const codingTools: Tool[] = [readTool, bashTool, editTool, writeTool];
|
||||
export const readOnlyTools: Tool[] = [readTool, grepTool, findTool, lsTool];
|
||||
|
||||
export const allTools = {
|
||||
read: readTool,
|
||||
bash: bashTool,
|
||||
edit: editTool,
|
||||
write: writeTool,
|
||||
grep: grepTool,
|
||||
find: findTool,
|
||||
ls: lsTool,
|
||||
};
|
||||
|
||||
export const allToolDefinitions = {
|
||||
read: readToolDefinition,
|
||||
bash: bashToolDefinition,
|
||||
edit: editToolDefinition,
|
||||
write: writeToolDefinition,
|
||||
grep: grepToolDefinition,
|
||||
find: findToolDefinition,
|
||||
ls: lsToolDefinition,
|
||||
};
|
||||
|
||||
export type ToolName = keyof typeof allTools;
|
||||
export type ToolName = "read" | "bash" | "edit" | "write" | "grep" | "find" | "ls";
|
||||
export const allToolNames: Set<ToolName> = new Set(["read", "bash", "edit", "write", "grep", "find", "ls"]);
|
||||
|
||||
export interface ToolsOptions {
|
||||
read?: ReadToolOptions;
|
||||
bash?: BashToolOptions;
|
||||
write?: WriteToolOptions;
|
||||
edit?: EditToolOptions;
|
||||
grep?: GrepToolOptions;
|
||||
find?: FindToolOptions;
|
||||
ls?: LsToolOptions;
|
||||
}
|
||||
|
||||
export function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef {
|
||||
switch (toolName) {
|
||||
case "read":
|
||||
return createReadToolDefinition(cwd, options?.read);
|
||||
case "bash":
|
||||
return createBashToolDefinition(cwd, options?.bash);
|
||||
case "edit":
|
||||
return createEditToolDefinition(cwd, options?.edit);
|
||||
case "write":
|
||||
return createWriteToolDefinition(cwd, options?.write);
|
||||
case "grep":
|
||||
return createGrepToolDefinition(cwd, options?.grep);
|
||||
case "find":
|
||||
return createFindToolDefinition(cwd, options?.find);
|
||||
case "ls":
|
||||
return createLsToolDefinition(cwd, options?.ls);
|
||||
default:
|
||||
throw new Error(`Unknown tool name: ${toolName}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function createTool(toolName: ToolName, cwd: string, options?: ToolsOptions): Tool {
|
||||
switch (toolName) {
|
||||
case "read":
|
||||
return createReadTool(cwd, options?.read);
|
||||
case "bash":
|
||||
return createBashTool(cwd, options?.bash);
|
||||
case "edit":
|
||||
return createEditTool(cwd, options?.edit);
|
||||
case "write":
|
||||
return createWriteTool(cwd, options?.write);
|
||||
case "grep":
|
||||
return createGrepTool(cwd, options?.grep);
|
||||
case "find":
|
||||
return createFindTool(cwd, options?.find);
|
||||
case "ls":
|
||||
return createLsTool(cwd, options?.ls);
|
||||
default:
|
||||
throw new Error(`Unknown tool name: ${toolName}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function createCodingToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {
|
||||
return [
|
||||
createReadToolDefinition(cwd, options?.read),
|
||||
createBashToolDefinition(cwd, options?.bash),
|
||||
createEditToolDefinition(cwd),
|
||||
createWriteToolDefinition(cwd),
|
||||
createEditToolDefinition(cwd, options?.edit),
|
||||
createWriteToolDefinition(cwd, options?.write),
|
||||
];
|
||||
}
|
||||
|
||||
export function createReadOnlyToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[] {
|
||||
return [
|
||||
createReadToolDefinition(cwd, options?.read),
|
||||
createGrepToolDefinition(cwd),
|
||||
createFindToolDefinition(cwd),
|
||||
createLsToolDefinition(cwd),
|
||||
createGrepToolDefinition(cwd, options?.grep),
|
||||
createFindToolDefinition(cwd, options?.find),
|
||||
createLsToolDefinition(cwd, options?.ls),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -159,11 +157,11 @@ export function createAllToolDefinitions(cwd: string, options?: ToolsOptions): R
|
||||
return {
|
||||
read: createReadToolDefinition(cwd, options?.read),
|
||||
bash: createBashToolDefinition(cwd, options?.bash),
|
||||
edit: createEditToolDefinition(cwd),
|
||||
write: createWriteToolDefinition(cwd),
|
||||
grep: createGrepToolDefinition(cwd),
|
||||
find: createFindToolDefinition(cwd),
|
||||
ls: createLsToolDefinition(cwd),
|
||||
edit: createEditToolDefinition(cwd, options?.edit),
|
||||
write: createWriteToolDefinition(cwd, options?.write),
|
||||
grep: createGrepToolDefinition(cwd, options?.grep),
|
||||
find: createFindToolDefinition(cwd, options?.find),
|
||||
ls: createLsToolDefinition(cwd, options?.ls),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -171,23 +169,28 @@ export function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {
|
||||
return [
|
||||
createReadTool(cwd, options?.read),
|
||||
createBashTool(cwd, options?.bash),
|
||||
createEditTool(cwd),
|
||||
createWriteTool(cwd),
|
||||
createEditTool(cwd, options?.edit),
|
||||
createWriteTool(cwd, options?.write),
|
||||
];
|
||||
}
|
||||
|
||||
export function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {
|
||||
return [createReadTool(cwd, options?.read), createGrepTool(cwd), createFindTool(cwd), createLsTool(cwd)];
|
||||
return [
|
||||
createReadTool(cwd, options?.read),
|
||||
createGrepTool(cwd, options?.grep),
|
||||
createFindTool(cwd, options?.find),
|
||||
createLsTool(cwd, options?.ls),
|
||||
];
|
||||
}
|
||||
|
||||
export function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool> {
|
||||
return {
|
||||
read: createReadTool(cwd, options?.read),
|
||||
bash: createBashTool(cwd, options?.bash),
|
||||
edit: createEditTool(cwd),
|
||||
write: createWriteTool(cwd),
|
||||
grep: createGrepTool(cwd),
|
||||
find: createFindTool(cwd),
|
||||
ls: createLsTool(cwd),
|
||||
edit: createEditTool(cwd, options?.edit),
|
||||
write: createWriteTool(cwd, options?.write),
|
||||
grep: createGrepTool(cwd, options?.grep),
|
||||
find: createFindTool(cwd, options?.find),
|
||||
ls: createLsTool(cwd, options?.ls),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import {
|
||||
import { SessionManager } from "./core/session-manager.js";
|
||||
import { SettingsManager } from "./core/settings-manager.js";
|
||||
import { printTimings, resetTimings, time } from "./core/timings.js";
|
||||
import { allTools } from "./core/tools/index.js";
|
||||
import { runMigrations, showDeprecationWarnings } from "./migrations.js";
|
||||
import { InteractiveMode, runPrintMode, runRpcMode } from "./modes/index.js";
|
||||
import { ExtensionSelectorComponent } from "./modes/interactive/components/extension-selector.js";
|
||||
@@ -368,14 +367,10 @@ function buildSessionOptions(
|
||||
// Tools
|
||||
if (parsed.noTools) {
|
||||
// --no-tools: start with no built-in tools
|
||||
// --tools can still add specific ones back
|
||||
if (parsed.tools && parsed.tools.length > 0) {
|
||||
options.tools = parsed.tools.map((name) => allTools[name]);
|
||||
} else {
|
||||
options.tools = [];
|
||||
}
|
||||
// --tools can still add specific ones back, including extension tools.
|
||||
options.tools = parsed.tools && parsed.tools.length > 0 ? [...parsed.tools] : [];
|
||||
} else if (parsed.tools) {
|
||||
options.tools = parsed.tools.map((name) => allTools[name]);
|
||||
options.tools = [...parsed.tools];
|
||||
}
|
||||
|
||||
return { options, cliThinkingFromModel, diagnostics };
|
||||
|
||||
Reference in New Issue
Block a user