summaryrefslogtreecommitdiff
path: root/packages/server/src
diff options
context:
space:
mode:
authorJacob Richman <[email protected]>2025-05-02 09:31:18 -0700
committerGitHub <[email protected]>2025-05-02 09:31:18 -0700
commit539ab947a49b0351759df5192ed44f17d217b2f1 (patch)
treeeb45ee25f24077745456215cb7e9578d79983404 /packages/server/src
parenta7679db6e99f971306bc4b27c603e93bc67ac254 (diff)
Use parameter properties where possible. (#242)
Diffstat (limited to 'packages/server/src')
-rw-r--r--packages/server/src/core/client.ts4
-rw-r--r--packages/server/src/core/turn.ts7
-rw-r--r--packages/server/src/tools/edit.ts4
-rw-r--r--packages/server/src/tools/glob.ts7
-rw-r--r--packages/server/src/tools/grep.ts4
-rw-r--r--packages/server/src/tools/ls.ts8
-rw-r--r--packages/server/src/tools/read-file.ts3
-rw-r--r--packages/server/src/tools/read-many-files.ts3
-rw-r--r--packages/server/src/tools/shell.ts4
-rw-r--r--packages/server/src/tools/terminal.ts10
-rw-r--r--packages/server/src/tools/write-file.ts4
11 files changed, 16 insertions, 42 deletions
diff --git a/packages/server/src/core/client.ts b/packages/server/src/core/client.ts
index a1cec704..d4bcdeca 100644
--- a/packages/server/src/core/client.ts
+++ b/packages/server/src/core/client.ts
@@ -23,7 +23,6 @@ import { ReadManyFilesTool } from '../tools/read-many-files.js'; // Import ReadM
import { getResponseText } from '../utils/generateContentResponseUtilities.js';
export class GeminiClient {
- private config: Config;
private client: GoogleGenAI;
private model: string;
private generateContentConfig: GenerateContentConfig = {
@@ -32,9 +31,8 @@ export class GeminiClient {
};
private readonly MAX_TURNS = 100;
- constructor(config: Config) {
+ constructor(private config: Config) {
this.client = new GoogleGenAI({ apiKey: config.getApiKey() });
- this.config = config;
this.model = config.getModel();
}
diff --git a/packages/server/src/core/turn.ts b/packages/server/src/core/turn.ts
index 25601164..47ca051b 100644
--- a/packages/server/src/core/turn.ts
+++ b/packages/server/src/core/turn.ts
@@ -84,7 +84,6 @@ export type ServerGeminiStreamEvent =
// A turn manages the agentic loop turn within the server context.
export class Turn {
- private readonly chat: Chat;
private readonly availableTools: Map<string, ServerTool>; // Use passed-in tools
private pendingToolCalls: Array<{
callId: string;
@@ -95,8 +94,10 @@ export class Turn {
private confirmationDetails: ToolCallConfirmationDetails[];
private debugResponses: GenerateContentResponse[];
- constructor(chat: Chat, availableTools: ServerTool[]) {
- this.chat = chat;
+ constructor(
+ private readonly chat: Chat,
+ availableTools: ServerTool[],
+ ) {
this.availableTools = new Map(availableTools.map((t) => [t.name, t]));
this.pendingToolCalls = [];
this.fnResponses = [];
diff --git a/packages/server/src/tools/edit.ts b/packages/server/src/tools/edit.ts
index 5dbeaf41..3b317a08 100644
--- a/packages/server/src/tools/edit.ts
+++ b/packages/server/src/tools/edit.ts
@@ -59,13 +59,11 @@ export class EditTool extends BaseTool<EditToolParams, ToolResult> {
static readonly Name = 'replace'; // Keep static name
private shouldAlwaysEdit = false;
- private readonly rootDirectory: string;
-
/**
* Creates a new instance of the EditLogic
* @param rootDirectory Root directory to ground this tool in.
*/
- constructor(rootDirectory: string) {
+ constructor(private readonly rootDirectory: string) {
// Note: The description here mentions other tools like ReadFileTool/WriteFileTool
// by name. This might need updating if those tool names change.
super(
diff --git a/packages/server/src/tools/glob.ts b/packages/server/src/tools/glob.ts
index f51456c3..d9d91c7a 100644
--- a/packages/server/src/tools/glob.ts
+++ b/packages/server/src/tools/glob.ts
@@ -33,15 +33,10 @@ export class GlobTool extends BaseTool<GlobToolParams, ToolResult> {
static readonly Name = 'glob'; // Keep static name
/**
- * The root directory that this tool is grounded in.
- */
- private rootDirectory: string;
-
- /**
* Creates a new instance of the GlobLogic
* @param rootDirectory Root directory to ground this tool in.
*/
- constructor(rootDirectory: string) {
+ constructor(private rootDirectory: string) {
super(
GlobTool.Name,
'FindFiles', // Display name handled by CLI wrapper
diff --git a/packages/server/src/tools/grep.ts b/packages/server/src/tools/grep.ts
index 1873a794..e3253ecf 100644
--- a/packages/server/src/tools/grep.ts
+++ b/packages/server/src/tools/grep.ts
@@ -54,13 +54,11 @@ interface GrepMatch {
export class GrepTool extends BaseTool<GrepToolParams, ToolResult> {
static readonly Name = 'search_file_content'; // Keep static name
- private rootDirectory: string;
-
/**
* Creates a new instance of the GrepLogic
* @param rootDirectory Root directory to ground this tool in. All operations will be restricted to this directory.
*/
- constructor(rootDirectory: string) {
+ constructor(private rootDirectory: string) {
super(
GrepTool.Name,
'SearchText',
diff --git a/packages/server/src/tools/ls.ts b/packages/server/src/tools/ls.ts
index 628daad5..01da5121 100644
--- a/packages/server/src/tools/ls.ts
+++ b/packages/server/src/tools/ls.ts
@@ -62,16 +62,10 @@ export class LSTool extends BaseTool<LSToolParams, ToolResult> {
static readonly Name = 'list_directory';
/**
- * The root directory that this tool is grounded in.
- * All path operations will be restricted to this directory.
- */
- private rootDirectory: string;
-
- /**
* Creates a new instance of the LSLogic
* @param rootDirectory Root directory to ground this tool in. All operations will be restricted to this directory.
*/
- constructor(rootDirectory: string) {
+ constructor(private rootDirectory: string) {
super(
LSTool.Name,
'ReadFolder',
diff --git a/packages/server/src/tools/read-file.ts b/packages/server/src/tools/read-file.ts
index 6cd70302..598b4691 100644
--- a/packages/server/src/tools/read-file.ts
+++ b/packages/server/src/tools/read-file.ts
@@ -37,9 +37,8 @@ export class ReadFileTool extends BaseTool<ReadFileToolParams, ToolResult> {
static readonly Name: string = 'read_file';
private static readonly DEFAULT_MAX_LINES = 2000;
private static readonly MAX_LINE_LENGTH = 2000;
- private rootDirectory: string;
- constructor(rootDirectory: string) {
+ constructor(private rootDirectory: string) {
super(
ReadFileTool.Name,
'ReadFile',
diff --git a/packages/server/src/tools/read-many-files.ts b/packages/server/src/tools/read-many-files.ts
index fad05759..0b4b090d 100644
--- a/packages/server/src/tools/read-many-files.ts
+++ b/packages/server/src/tools/read-many-files.ts
@@ -116,14 +116,13 @@ export class ReadManyFilesTool extends BaseTool<
ToolResult
> {
static readonly Name: string = 'read_many_files';
- readonly targetDir: string;
/**
* Creates an instance of ReadManyFilesTool.
* @param targetDir The absolute root directory within which this tool is allowed to operate.
* All paths provided in `params` will be resolved relative to this directory.
*/
- constructor(targetDir: string) {
+ constructor(readonly targetDir: string) {
const parameterSchema: Record<string, unknown> = {
type: 'object',
properties: {
diff --git a/packages/server/src/tools/shell.ts b/packages/server/src/tools/shell.ts
index 1224dc8f..592acc2b 100644
--- a/packages/server/src/tools/shell.ts
+++ b/packages/server/src/tools/shell.ts
@@ -25,10 +25,9 @@ import { spawn } from 'child_process';
export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
static Name: string = 'execute_bash_command';
- private readonly config: Config;
private whitelist: Set<string> = new Set();
- constructor(config: Config) {
+ constructor(private readonly config: Config) {
const toolDisplayName = 'Shell';
const descriptionUrl = new URL('shell.md', import.meta.url);
const toolDescription = fs.readFileSync(descriptionUrl, 'utf-8');
@@ -38,7 +37,6 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
toolDescription,
toolParameterSchema,
);
- this.config = config;
}
getDescription(params: ShellToolParams): string {
diff --git a/packages/server/src/tools/terminal.ts b/packages/server/src/tools/terminal.ts
index 514ad682..7320cfb2 100644
--- a/packages/server/src/tools/terminal.ts
+++ b/packages/server/src/tools/terminal.ts
@@ -46,8 +46,6 @@ interface QueuedCommand {
export class TerminalTool extends BaseTool<TerminalToolParams, ToolResult> {
static Name: string = 'execute_bash_command';
- private readonly rootDirectory: string;
- private readonly outputLimit: number;
private bashProcess: ChildProcessWithoutNullStreams | null = null;
private currentCwd: string;
private isExecuting: boolean = false;
@@ -58,12 +56,11 @@ export class TerminalTool extends BaseTool<TerminalToolParams, ToolResult> {
private resolveShellReady: (() => void) | undefined;
private rejectShellReady: ((reason?: unknown) => void) | undefined;
private readonly backgroundTerminalAnalyzer: BackgroundTerminalAnalyzer;
- private readonly config: Config;
constructor(
- rootDirectory: string,
- config: Config,
- outputLimit: number = MAX_OUTPUT_LENGTH,
+ private readonly rootDirectory: string,
+ private readonly config: Config,
+ private readonly outputLimit: number = MAX_OUTPUT_LENGTH,
) {
const toolDisplayName = 'Terminal';
const toolDescription = `Executes one or more bash commands sequentially in a secure and persistent interactive shell session. Can run commands in the foreground (waiting for completion) or background (returning after launch, with subsequent status polling).
@@ -131,7 +128,6 @@ Use this tool for running build steps (\`npm install\`, \`make\`), linters (\`es
toolDescription,
toolParameterSchema,
);
- this.config = config;
this.rootDirectory = path.resolve(rootDirectory);
this.currentCwd = this.rootDirectory;
this.outputLimit = outputLimit;
diff --git a/packages/server/src/tools/write-file.ts b/packages/server/src/tools/write-file.ts
index 814efa86..d24080d2 100644
--- a/packages/server/src/tools/write-file.ts
+++ b/packages/server/src/tools/write-file.ts
@@ -41,9 +41,7 @@ export class WriteFileTool extends BaseTool<WriteFileToolParams, ToolResult> {
static readonly Name: string = 'write_file';
private shouldAlwaysWrite = false;
- private readonly rootDirectory: string;
-
- constructor(rootDirectory: string) {
+ constructor(private readonly rootDirectory: string) {
super(
WriteFileTool.Name,
'WriteFile',