import { ProcessManager } from "../core/process-manager.js";
import { LspManager } from "../core/lsp/manager.js";
import { createReadTool } from "./read.js";
import { getVideoByteLimit } from "../core/model-registry.js";
import { createWriteTool } from "./write.js";
import { createEditTool } from "./edit.js";
import { createBashTool } from "./bash.js";
import { createFindTool } from "./find.js";
import { createGrepTool } from "./grep.js";
import { createSearchCodeTool } from "./search-code.js";
import { createLsTool } from "./ls.js";
import { createSubAgentTool } from "./subagent.js";
import { createWebFetchTool } from "./web-fetch.js";
import { createWebSearchTool } from "./web-search.js";
import { createSourcePathTool } from "./source-path.js";
import { createTaskOutputTool } from "./task-output.js";
import { createTaskStopTool } from "./task-stop.js";
import { createTaskSendTool } from "./task-send.js";
import { createTasksTool } from "./tasks.js";
import { createSkillTool } from "./skill.js";
import { createScreenshotTool } from "./screenshot.js";
import { createGenerateImageTool } from "./generate-image.js";
import { createEnterPlanTool } from "./enter-plan.js";
import { createExitPlanTool } from "./exit-plan.js";
import { localOperations } from "./operations.js";
export async function createTools(cwd, opts) {
    const readFiles = new Map();
    const processManager = new ProcessManager();
    const ops = opts?.operations ?? localOperations;
    const planModeRef = opts?.planModeRef;
    // LSP diagnostics only make sense against the local filesystem — remote
    // operations (SSH/Docker) would point local language servers at paths that
    // don't exist here. Lazy: no server spawns until the first matching edit.
    const lspEnabled = (opts?.lspDiagnostics ?? true) && ops === localOperations;
    const lspManager = lspEnabled ? new LspManager(cwd) : undefined;
    const getDiagnostics = lspManager
        ? (filePath, content) => lspManager.diagnosticsAfterWrite(filePath, content)
        : undefined;
    // Enable native video returns from the read tool for any video-capable model
    // (Kimi/Moonshot, Gemini, MiniMax), each with its own per-model byte cap that
    // drives auto-compression. Non-video models get `undefined` — video falls back
    // to the plain binary-file notice, never offered to models that can't watch it.
    const videoByteLimit = opts?.model ? getVideoByteLimit(opts.model) : undefined;
    const tools = [
        createReadTool(cwd, readFiles, ops, opts?.onFileRead, videoByteLimit),
        createWriteTool(cwd, readFiles, ops, planModeRef, opts?.onFileMutated, opts?.onPreFileMutation, getDiagnostics),
        createEditTool(cwd, readFiles, ops, planModeRef, opts?.onFileMutated, opts?.onPreFileMutation, getDiagnostics),
        createBashTool(cwd, processManager, ops, planModeRef),
        createFindTool(cwd),
        createGrepTool(cwd, ops),
        createSearchCodeTool(cwd, ops),
        createLsTool(cwd, ops),
        createSourcePathTool(cwd),
        createWebFetchTool(),
        createTaskOutputTool(processManager),
        createTaskSendTool(processManager),
        createTaskStopTool(processManager),
        createTasksTool(cwd),
        createScreenshotTool(cwd),
    ];
    // Add web search tool for providers without reliable native web search
    if (opts?.provider && opts.provider !== "anthropic") {
        tools.push(createWebSearchTool());
    }
    if (opts?.agents && opts.agents.length > 0 && opts.provider && opts.model) {
        tools.push(createSubAgentTool(cwd, opts.agents, () => opts.getProvider?.() ?? opts.provider, () => opts.getModel?.() ?? opts.model, opts.getCacheKey, planModeRef));
    }
    if (opts?.skills && opts.skills.length > 0) {
        tools.push(createSkillTool(opts.skills));
    }
    if (opts?.onEnterPlan) {
        tools.push(createEnterPlanTool(opts.onEnterPlan));
    }
    if (opts?.onExitPlan) {
        tools.push(createExitPlanTool(cwd, opts.onExitPlan));
    }
    // Conditionally register the image generation tool — only when OpenAI auth
    // is connected. The tool always uses OpenAI's Image API regardless of the
    // active chat provider, so it's purely gated on OpenAI being logged in.
    if (opts?.authStorage) {
        try {
            if (await opts.authStorage.hasProviderAuth("openai")) {
                tools.push(createGenerateImageTool(cwd, opts.authStorage));
            }
        }
        catch {
            // Auth not loaded yet or check failed — skip the tool silently.
        }
    }
    const rebuildReadTool = (model) => createReadTool(cwd, readFiles, ops, opts?.onFileRead, getVideoByteLimit(model));
    return { tools, processManager, rebuildReadTool, lspManager };
}
export { createReadTool } from "./read.js";
export { createWriteTool } from "./write.js";
export { createEditTool } from "./edit.js";
export { createBashTool } from "./bash.js";
export { createFindTool } from "./find.js";
export { createGrepTool } from "./grep.js";
export { createSearchCodeTool } from "./search-code.js";
export { createLsTool } from "./ls.js";
export { createWebFetchTool } from "./web-fetch.js";
export { createWebSearchTool } from "./web-search.js";
export { createSourcePathTool } from "./source-path.js";
export { createTaskOutputTool } from "./task-output.js";
export { createTaskSendTool } from "./task-send.js";
export { createTaskStopTool } from "./task-stop.js";
export { createTasksTool } from "./tasks.js";
export { createSkillTool } from "./skill.js";
export { createScreenshotTool } from "./screenshot.js";
export { createGenerateImageTool } from "./generate-image.js";
export { createEnterPlanTool } from "./enter-plan.js";
export { createExitPlanTool } from "./exit-plan.js";
export { ProcessManager } from "../core/process-manager.js";
export { LspManager } from "../core/lsp/manager.js";
export { localOperations } from "./operations.js";
//# sourceMappingURL=index.js.map