summaryrefslogtreecommitdiff
path: root/packages/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/server/src')
-rw-r--r--packages/server/src/config/config.ts13
-rw-r--r--packages/server/src/tools/shell.json18
-rw-r--r--packages/server/src/tools/shell.md1
-rw-r--r--packages/server/src/tools/shell.ts44
4 files changed, 74 insertions, 2 deletions
diff --git a/packages/server/src/config/config.ts b/packages/server/src/config/config.ts
index 06092b84..8a49380c 100644
--- a/packages/server/src/config/config.ts
+++ b/packages/server/src/config/config.ts
@@ -15,9 +15,11 @@ import { GrepTool } from '../tools/grep.js';
import { GlobTool } from '../tools/glob.js';
import { EditTool } from '../tools/edit.js';
import { TerminalTool } from '../tools/terminal.js';
+import { ShellTool } from '../tools/shell.js';
import { WriteFileTool } from '../tools/write-file.js';
import { WebFetchTool } from '../tools/web-fetch.js';
import { ReadManyFilesTool } from '../tools/read-many-files.js';
+import { BaseTool, ToolResult } from '../tools/tools.js';
const DEFAULT_PASSTHROUGH_COMMANDS = ['ls', 'git', 'npm'];
@@ -132,17 +134,24 @@ function createToolRegistry(config: Config): ToolRegistry {
const registry = new ToolRegistry();
const targetDir = config.getTargetDir();
- const tools = [
+ const tools: Array<BaseTool<unknown, ToolResult>> = [
new LSTool(targetDir),
new ReadFileTool(targetDir),
new GrepTool(targetDir),
new GlobTool(targetDir),
new EditTool(targetDir),
- new TerminalTool(targetDir, config),
new WriteFileTool(targetDir),
new WebFetchTool(), // Note: WebFetchTool takes no arguments
new ReadManyFilesTool(targetDir),
];
+
+ // use ShellTool (next-gen TerminalTool) if environment variable is set
+ if (process.env.SHELL_TOOL) {
+ tools.push(new ShellTool(targetDir, config));
+ } else {
+ tools.push(new TerminalTool(targetDir, config));
+ }
+
for (const tool of tools) {
registry.registerTool(tool);
}
diff --git a/packages/server/src/tools/shell.json b/packages/server/src/tools/shell.json
new file mode 100644
index 00000000..f1ba372e
--- /dev/null
+++ b/packages/server/src/tools/shell.json
@@ -0,0 +1,18 @@
+{
+ "type": "object",
+ "properties": {
+ "command": {
+ "description": "The exact bash command or sequence of commands (using ';' or '&&') to execute. Must adhere to usage guidelines. Example: 'npm install && npm run build'",
+ "type": "string"
+ },
+ "description": {
+ "description": "Optional: A brief, user-centric explanation of what the command does and why it's being run. Used for logging and confirmation prompts. Example: 'Install project dependencies'",
+ "type": "string"
+ },
+ "runInBackground": {
+ "description": "If true, execute the command in the background using '&'. Defaults to false. Use for servers or long tasks.",
+ "type": "boolean"
+ }
+ },
+ "required": ["command"]
+}
diff --git a/packages/server/src/tools/shell.md b/packages/server/src/tools/shell.md
new file mode 100644
index 00000000..ce71e42c
--- /dev/null
+++ b/packages/server/src/tools/shell.md
@@ -0,0 +1 @@
+This is a minimal shell tool.
diff --git a/packages/server/src/tools/shell.ts b/packages/server/src/tools/shell.ts
new file mode 100644
index 00000000..658293b0
--- /dev/null
+++ b/packages/server/src/tools/shell.ts
@@ -0,0 +1,44 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import path from 'path';
+import fs from 'fs';
+import { Config } from '../config/config.js';
+import { BaseTool, ToolResult } from './tools.js';
+
+export interface ShellToolParams {
+ command: string;
+ description?: string;
+}
+
+export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
+ static Name: string = 'execute_bash_command';
+ private readonly rootDirectory: string;
+ private readonly config: Config;
+
+ constructor(rootDirectory: string, config: Config) {
+ const toolDisplayName = 'Shell';
+ const descriptionUrl = new URL('shell.md', import.meta.url);
+ const toolDescription = fs.readFileSync(descriptionUrl, 'utf-8');
+ const schemaUrl = new URL('shell.json', import.meta.url);
+ const toolParameterSchema = JSON.parse(fs.readFileSync(schemaUrl, 'utf-8'));
+ super(
+ ShellTool.Name,
+ toolDisplayName,
+ toolDescription,
+ toolParameterSchema,
+ );
+ this.config = config;
+ this.rootDirectory = path.resolve(rootDirectory);
+ }
+
+ async execute(_params: ShellToolParams): Promise<ToolResult> {
+ return {
+ llmContent: 'hello',
+ returnDisplay: 'hello',
+ };
+ }
+}