diff --git a/src/cli/doctor/checks/dependencies.ts b/src/cli/doctor/checks/dependencies.ts index 7e273c96b..42876c4a3 100644 --- a/src/cli/doctor/checks/dependencies.ts +++ b/src/cli/doctor/checks/dependencies.ts @@ -6,7 +6,11 @@ import type { DependencyInfo } from "../types" import { spawnWithTimeout } from "../spawn-with-timeout" import { getCachedBinaryPath } from "../../../hooks/comment-checker/downloader" -async function checkBinaryExists(binary: string): Promise<{ exists: boolean; path: string | null }> { +type BinaryCheck = + | { exists: true; path: string } + | { exists: false; path: null } + +async function checkBinaryExists(binary: string): Promise { try { const path = Bun.which(binary) if (path) { @@ -44,7 +48,7 @@ export async function checkAstGrepCli(): Promise { } } - const version = await getBinaryVersion(binary.path!) + const version = await getBinaryVersion(binary.path) return { name: "AST-Grep CLI", diff --git a/src/tools/background-task/create-background-cancel.ts b/src/tools/background-task/create-background-cancel.ts index 30f73837f..2347ebcfc 100644 --- a/src/tools/background-task/create-background-cancel.ts +++ b/src/tools/background-task/create-background-cancel.ts @@ -15,10 +15,6 @@ export function createBackgroundCancel(manager: BackgroundManager, _client: Back try { const cancelAll = args.all === true - if (!cancelAll && !args.taskId) { - return `[ERROR] Invalid arguments: Either provide a taskId or set all=true to cancel all running tasks.` - } - if (cancelAll) { const tasks = manager.getAllDescendantTasks(toolContext.sessionID) const cancellableTasks = tasks.filter((t: { status: string }) => t.status === "running" || t.status === "pending") @@ -74,9 +70,14 @@ ${tableRows} ${resumeSection}` } - const task = manager.getTask(args.taskId!) + const taskId = args.taskId + if (!taskId) { + return `[ERROR] Invalid arguments: Either provide a taskId or set all=true to cancel all running tasks.` + } + + const task = manager.getTask(taskId) if (!task) { - return `[ERROR] Task not found: ${args.taskId}` + return `[ERROR] Task not found: ${taskId}` } if (task.status !== "running" && task.status !== "pending") { diff --git a/src/tools/look-at/look-at-arguments.ts b/src/tools/look-at/look-at-arguments.ts index 4a2d978fb..a62241b2f 100644 --- a/src/tools/look-at/look-at-arguments.ts +++ b/src/tools/look-at/look-at-arguments.ts @@ -13,10 +13,11 @@ export function normalizeArgs(args: LookAtArgsWithAlias): LookAtArgs { } export function validateArgs(args: LookAtArgs): string | null { - const hasFilePath = Boolean(args.file_path && args.file_path.length > 0) + const filePath = args.file_path + const hasFilePath = Boolean(filePath && filePath.length > 0) const hasImageData = Boolean(args.image_data && args.image_data.length > 0) - if (hasFilePath && /^https?:\/\//i.test(args.file_path!)) { + if (filePath && /^https?:\/\//i.test(filePath)) { return "Error: Remote URLs are not supported for file_path. Download the file first or use a local path." } if (!hasFilePath && !hasImageData) { diff --git a/src/tools/lsp/lsp-client-transport.ts b/src/tools/lsp/lsp-client-transport.ts index e8b34e706..05d1d0f18 100644 --- a/src/tools/lsp/lsp-client-transport.ts +++ b/src/tools/lsp/lsp-client-transport.ts @@ -136,22 +136,27 @@ export class LSPClientTransport { throw new Error(`LSP server already exited (code: ${this.proc?.exitCode})` + (stderr ? `\nstderr: ${stderr}` : "")) } - let timeoutId: ReturnType + let timeoutId: ReturnType | undefined const timeoutPromise = new Promise((_, reject) => { timeoutId = setTimeout(() => { const stderr = this.stderrBuffer.slice(-5).join("\n") reject(new Error(`LSP request timeout (method: ${method})` + (stderr ? `\nrecent stderr: ${stderr}` : ""))) }, this.REQUEST_TIMEOUT) }) + const clearRequestTimeout = (): void => { + if (timeoutId !== undefined) { + clearTimeout(timeoutId) + } + } const requestPromise = this.connection.sendRequest(method, ...args) as Promise try { const result = await Promise.race([requestPromise, timeoutPromise]) - clearTimeout(timeoutId!) + clearRequestTimeout() return result } catch (error) { - clearTimeout(timeoutId!) + clearRequestTimeout() throw error } } diff --git a/src/tools/lsp/symbols-tool.ts b/src/tools/lsp/symbols-tool.ts index 0c4ca130b..3af960731 100644 --- a/src/tools/lsp/symbols-tool.ts +++ b/src/tools/lsp/symbols-tool.ts @@ -22,12 +22,13 @@ export const lsp_symbols: ToolDefinition = tool({ const scope = args.scope ?? "document" if (scope === "workspace") { - if (!args.query) { + const query = args.query + if (!query) { return "Error: 'query' is required for workspace scope" } const result = await withLspClient(args.filePath, async (client) => { - return (await client.workspaceSymbols(args.query!)) as SymbolInfo[] | null + return (await client.workspaceSymbols(query)) as SymbolInfo[] | null }) if (!result || result.length === 0) {