Use parameter properties where possible. (#242)

This commit is contained in:
Jacob Richman 2025-05-02 09:31:18 -07:00 committed by GitHub
parent a7679db6e9
commit 539ab947a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 18 additions and 53 deletions

View File

@ -65,18 +65,11 @@ export const ansiTheme: ColorsTheme = {
};
export class Theme {
/**
* The user-facing name of the theme.
*/
readonly name: string;
/**
* The default foreground color for text when no specific highlight rule applies.
* This is an Ink-compatible color string (hex or name).
*/
readonly defaultColor: string;
readonly colors: ColorsTheme;
/**
* Stores the mapping from highlight.js class names (e.g., 'hljs-keyword')
* to Ink-compatible color strings (hex or name).
@ -256,13 +249,11 @@ export class Theme {
* @param rawMappings The raw CSSProperties mappings from a react-syntax-highlighter theme object.
*/
constructor(
name: string,
readonly name: string,
rawMappings: Record<string, CSSProperties>,
colors: ColorsTheme,
readonly colors: ColorsTheme,
) {
this.name = name;
this._colorMap = Object.freeze(this._buildColorMap(rawMappings)); // Build and freeze the map
this.colors = colors;
// Determine the default foreground color
const rawDefaultColor = rawMappings['hljs']?.color;

View File

@ -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();
}

View File

@ -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 = [];

View File

@ -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(

View File

@ -32,16 +32,11 @@ export interface GlobToolParams {
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

View File

@ -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',

View File

@ -61,17 +61,11 @@ export interface FileEntry {
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',

View File

@ -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',

View File

@ -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: {

View File

@ -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 {

View File

@ -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;

View File

@ -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',