"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Module: tools/builtins
 *
 * Registers built-in tools, toolsets, and reminder owners.
 *
 * Entry points (server/cli) must import this module once to populate registries.
 */
const apply_patch_1 = require("./apply-patch");
const ctrl_1 = require("./ctrl");
const env_1 = require("./env");
const fs_1 = require("./fs");
const spec_1 = require("./manual/spec");
const mcp_1 = require("./mcp");
const mem_1 = require("./mem");
const os_1 = require("./os");
const pending_tellask_reminder_1 = require("./pending-tellask-reminder");
const picture_1 = require("./picture");
const registry_1 = require("./registry");
const resources_1 = require("./resources");
const ripgrep_1 = require("./ripgrep");
const skills_1 = require("./skills");
const team_mgmt_1 = require("./team_mgmt");
const txt_1 = require("./txt");
function promptFilesFor(toolsetId) {
    if (toolsetId === 'ws_mod') {
        // ws_mod uses flat single-file format, not subdirectory structure.
        return {
            en: 'prompts/ws_mod.en.md',
            zh: 'prompts/ws_mod.zh.md',
        };
    }
    return {
        en: `prompts/${toolsetId}/en/index.md`,
        zh: `prompts/${toolsetId}/zh/index.md`,
    };
}
function manualSpecFor(toolsetId) {
    if (toolsetId === 'ws_mod') {
        return (0, spec_1.buildBuiltinManualSpec)({
            toolsetId: 'ws_mod',
            warnOnMissing: false,
        });
    }
    return (0, spec_1.buildBuiltinManualSpec)({ toolsetId });
}
(0, registry_1.registerTool)(fs_1.listDirTool);
(0, registry_1.registerTool)(fs_1.rmDirTool);
(0, registry_1.registerTool)(fs_1.rmFileTool);
(0, registry_1.registerTool)(fs_1.rmSymlinkTool);
(0, registry_1.registerTool)(fs_1.mkDirTool);
(0, registry_1.registerTool)(fs_1.moveFileTool);
(0, registry_1.registerTool)(fs_1.moveDirTool);
(0, registry_1.registerTool)(fs_1.readSymlinkTool);
(0, registry_1.registerTool)(fs_1.createSymlinkTool);
(0, registry_1.registerTool)(fs_1.fsListDirTool);
(0, registry_1.registerTool)(fs_1.fsReadSymlinkTool);
(0, registry_1.registerTool)(txt_1.readFileTool);
(0, registry_1.registerTool)(txt_1.fsReadFileTool);
(0, registry_1.registerTool)(picture_1.readPictureTool);
(0, registry_1.registerTool)(picture_1.fsReadPictureTool);
(0, registry_1.registerTool)(picture_1.writePictureTool);
(0, registry_1.registerTool)(txt_1.createNewFileTool);
(0, registry_1.registerTool)(txt_1.overwriteEntireFileTool);
(0, registry_1.registerTool)(txt_1.fileRangeEditTool);
(0, registry_1.registerTool)(txt_1.padWriteTool);
(0, registry_1.registerTool)(txt_1.padLoadFileRangeTool);
(0, registry_1.registerTool)(txt_1.padEditTool);
(0, registry_1.registerTool)(txt_1.padInsertTool);
(0, registry_1.registerTool)(txt_1.padDeleteRangeTool);
(0, registry_1.registerTool)(txt_1.padCopyTool);
(0, registry_1.registerTool)(txt_1.padMoveTool);
(0, registry_1.registerTool)(txt_1.padDeleteTool);
(0, registry_1.registerTool)(txt_1.fileAppendTool);
(0, registry_1.registerTool)(txt_1.fileInsertAfterTool);
(0, registry_1.registerTool)(txt_1.fileInsertBeforeTool);
(0, registry_1.registerTool)(txt_1.fileBlockReplaceTool);
(0, registry_1.registerTool)(txt_1.prepareOccurrenceReplaceTool);
(0, registry_1.registerTool)(txt_1.applyOccurrenceReplaceTool);
// Ripgrep tools
(0, registry_1.registerTool)(ripgrep_1.ripgrepFilesTool);
(0, registry_1.registerTool)(ripgrep_1.ripgrepSnippetsTool);
(0, registry_1.registerTool)(ripgrep_1.ripgrepCountTool);
(0, registry_1.registerTool)(ripgrep_1.ripgrepFixedTool);
(0, registry_1.registerTool)(ripgrep_1.ripgrepSearchTool);
(0, registry_1.registerTool)(ripgrep_1.fsRipgrepFilesTool);
(0, registry_1.registerTool)(ripgrep_1.fsRipgrepSnippetsTool);
(0, registry_1.registerTool)(ripgrep_1.fsRipgrepCountTool);
(0, registry_1.registerTool)(ripgrep_1.fsRipgrepFixedTool);
(0, registry_1.registerTool)(ripgrep_1.fsRipgrepSearchTool);
// OS tools
(0, registry_1.registerTool)(os_1.shellCmdTool);
(0, registry_1.registerTool)(os_1.readonlyShellTool);
(0, registry_1.registerTool)(os_1.stopDaemonTool);
(0, registry_1.registerTool)(os_1.getDaemonOutputTool);
// Inspect-and-patch helpers
(0, registry_1.registerTool)(apply_patch_1.applyPatchTool);
// Env tools (local testing)
(0, registry_1.registerTool)(env_1.envGetTool);
(0, registry_1.registerTool)(env_1.envSetTool);
(0, registry_1.registerTool)(env_1.envUnsetTool);
// MCP tools (local testing/ops)
(0, registry_1.registerTool)(mcp_1.mcpRestartTool);
(0, registry_1.registerTool)(mcp_1.mcpReleaseTool);
(0, registry_1.registerTool)(mcp_1.mcpDisableTool);
// Memory tools
(0, registry_1.registerTool)(mem_1.addPersonalMemoryTool);
(0, registry_1.registerTool)(mem_1.dropPersonalMemoryTool);
(0, registry_1.registerTool)(mem_1.replacePersonalMemoryTool);
(0, registry_1.registerTool)(mem_1.clearPersonalMemoryTool);
(0, registry_1.registerTool)(mem_1.addSharedMemoryTool);
(0, registry_1.registerTool)(mem_1.dropSharedMemoryTool);
(0, registry_1.registerTool)(mem_1.replaceSharedMemoryTool);
(0, registry_1.registerTool)(mem_1.clearSharedMemoryTool);
// Skill tools
(0, registry_1.registerTool)(skills_1.addPersonalSkillTool);
(0, registry_1.registerTool)(skills_1.importPersonalSkillFromFileTool);
(0, registry_1.registerTool)(skills_1.replacePersonalSkillTool);
(0, registry_1.registerTool)(skills_1.movePersonalSkillTool);
(0, registry_1.registerTool)(skills_1.dropPersonalSkillTool);
(0, registry_1.registerTool)(skills_1.readSkillTool);
// Resource tools
(0, registry_1.registerTool)(resources_1.listResourcesTool);
(0, registry_1.registerTool)(resources_1.fetchResourceTool);
// Control tools
(0, registry_1.registerTool)(ctrl_1.addReminderTool);
(0, registry_1.registerTool)(ctrl_1.deleteReminderTool);
(0, registry_1.registerTool)(ctrl_1.updateReminderTool);
(0, registry_1.registerTool)(ctrl_1.migrateReminderTool);
(0, registry_1.registerTool)(ctrl_1.clearMindTool);
(0, registry_1.registerTool)(ctrl_1.doMindTool);
(0, registry_1.registerTool)(ctrl_1.changeMindTool);
(0, registry_1.registerTool)(ctrl_1.mindMoreTool);
(0, registry_1.registerTool)(ctrl_1.neverMindTool);
(0, registry_1.registerTool)(ctrl_1.recallTaskdocTool);
// Team management tools (scoped to `.minds/**`)
for (const tool of team_mgmt_1.teamMgmtTools) {
    (0, registry_1.registerTool)(tool);
}
// Register well-known toolsets
(0, registry_1.registerToolset)('personal_memory', [
    mem_1.addPersonalMemoryTool,
    mem_1.dropPersonalMemoryTool,
    mem_1.replacePersonalMemoryTool,
    mem_1.clearPersonalMemoryTool,
]);
(0, registry_1.setToolsetMeta)('personal_memory', {
    source: 'dominds',
    descriptionI18n: {
        en: 'Private memory for this agent: keep stable preferences, responsibility-scope paths, and durable facts accurate.',
        zh: '仅当前智能体可见的个人记忆：维护稳定偏好、职责域路径索引与长期事实。',
    },
    promptFilesI18n: promptFilesFor('personal_memory'),
    manualSpec: manualSpecFor('personal_memory'),
});
(0, registry_1.registerToolset)('team_memory', [
    mem_1.addSharedMemoryTool,
    mem_1.dropSharedMemoryTool,
    mem_1.replaceSharedMemoryTool,
    mem_1.clearSharedMemoryTool,
]);
(0, registry_1.setToolsetMeta)('team_memory', {
    source: 'dominds',
    descriptionI18n: {
        en: 'Shared team memory: record reusable conventions, invariants, and cross-task collaboration rules.',
        zh: '团队共享记忆：沉淀可复用的约定、不变量与跨任务协作规则。',
    },
    promptFilesI18n: promptFilesFor('team_memory'),
    manualSpec: manualSpecFor('team_memory'),
});
(0, registry_1.registerToolset)('skills', [
    skills_1.readSkillTool,
    skills_1.addPersonalSkillTool,
    skills_1.importPersonalSkillFromFileTool,
    skills_1.replacePersonalSkillTool,
    skills_1.movePersonalSkillTool,
    skills_1.dropPersonalSkillTool,
]);
(0, registry_1.setToolsetMeta)('skills', {
    source: 'dominds',
    descriptionI18n: {
        en: 'Personal skills for this agent: create, update, move, and delete reusable prompt skills under your own skill store.',
        zh: '当前智能体的个人 skills：在自己的 skill 仓库中创建、更新、移动、删除可复用提示技能。',
    },
    promptFilesI18n: promptFilesFor('skills'),
    manualSpec: manualSpecFor('skills'),
});
(0, registry_1.registerToolset)('resources', [resources_1.listResourcesTool, resources_1.fetchResourceTool]);
(0, registry_1.setToolsetMeta)('resources', {
    source: 'dominds',
    descriptionI18n: {
        en: 'Read-only Dominds resources: list and fetch MCP resources and resource templates.',
        zh: '只读 Dominds resources：列出并读取 MCP resources 与 resource templates。',
    },
    promptFilesI18n: promptFilesFor('resources'),
    manualSpec: manualSpecFor('resources'),
});
(0, registry_1.registerToolset)('control', [
    ctrl_1.addReminderTool,
    ctrl_1.deleteReminderTool,
    ctrl_1.updateReminderTool,
    ctrl_1.migrateReminderTool,
    ctrl_1.clearMindTool,
    ctrl_1.doMindTool,
    ctrl_1.changeMindTool,
    ctrl_1.mindMoreTool,
    ctrl_1.neverMindTool,
    ctrl_1.recallTaskdocTool,
]);
(0, registry_1.setToolsetMeta)('control', {
    source: 'dominds',
    assignable: false,
    descriptionI18n: {
        en: 'Dialog control: manage reminders, Taskdoc sections, and course resets.',
        zh: '对话控制：维护提醒项、差遣牒分段，并管理对话进程重置。',
    },
    promptFilesI18n: promptFilesFor('control'),
    manualSpec: manualSpecFor('control'),
});
(0, registry_1.registerToolset)('os', [
    os_1.shellCmdTool,
    os_1.stopDaemonTool,
    os_1.getDaemonOutputTool,
    env_1.envGetTool,
    env_1.envSetTool,
    env_1.envUnsetTool,
]);
(0, registry_1.setToolsetMeta)('os', {
    source: 'dominds',
    descriptionI18n: {
        en: 'Shell and process operations: run commands, manage daemons, inspect output, and adjust local env vars.',
        zh: '命令行与进程操作：执行命令、管理后台进程、查看输出，并调整本地环境变量。',
    },
    promptFilesI18n: promptFilesFor('os'),
    manualSpec: manualSpecFor('os'),
});
(0, registry_1.registerToolset)('mcp_admin', [
    mcp_1.mcpRestartTool,
    mcp_1.mcpReleaseTool,
    mcp_1.mcpDisableTool,
    env_1.envGetTool,
    env_1.envSetTool,
    env_1.envUnsetTool,
]);
(0, registry_1.setToolsetMeta)('mcp_admin', {
    source: 'dominds',
    descriptionI18n: {
        en: 'MCP administration: restart/release MCP servers and manage related local environment configuration.',
        zh: 'MCP 管理：重启/释放 MCP 服务器，并维护相关本地环境配置。',
    },
    promptFilesI18n: promptFilesFor('mcp_admin'),
    manualSpec: manualSpecFor('mcp_admin'),
});
(0, registry_1.registerToolset)('ws_read', [
    fs_1.listDirTool,
    fs_1.readSymlinkTool,
    txt_1.readFileTool,
    picture_1.readPictureTool,
    ripgrep_1.ripgrepFilesTool,
    ripgrep_1.ripgrepSnippetsTool,
    ripgrep_1.ripgrepCountTool,
    ripgrep_1.ripgrepFixedTool,
    ripgrep_1.ripgrepSearchTool,
]);
(0, registry_1.setToolsetMeta)('ws_read', {
    source: 'dominds',
    descriptionI18n: {
        en: 'rtws read-only access: list directories, read text/images, and search code/content to gather facts safely.',
        zh: '运行时工作区只读访问：列目录、读文本/图片、检索代码与文本，用于安全获取事实。',
    },
    promptFilesI18n: promptFilesFor('ws_read'),
    manualSpec: manualSpecFor('ws_read'),
});
(0, registry_1.registerToolset)('fs_read', [
    fs_1.fsListDirTool,
    fs_1.fsReadSymlinkTool,
    txt_1.fsReadFileTool,
    picture_1.fsReadPictureTool,
    ripgrep_1.fsRipgrepFilesTool,
    ripgrep_1.fsRipgrepSnippetsTool,
    ripgrep_1.fsRipgrepCountTool,
    ripgrep_1.fsRipgrepFixedTool,
    ripgrep_1.fsRipgrepSearchTool,
]);
(0, registry_1.setToolsetMeta)('fs_read', {
    source: 'dominds',
    wildcardAssignable: false,
    descriptionI18n: {
        en: 'Local filesystem read-only access without rtws path restriction: list directories, read text/images, and search files.',
        zh: '本机文件系统只读访问，不限制路径必须位于 rtws 内：列目录、读文本/图片、检索文件。',
    },
    promptFilesI18n: promptFilesFor('fs_read'),
    manualSpec: manualSpecFor('fs_read'),
});
(0, registry_1.registerToolset)('ws_mod', [
    fs_1.listDirTool,
    fs_1.rmDirTool,
    fs_1.rmFileTool,
    fs_1.rmSymlinkTool,
    fs_1.mkDirTool,
    fs_1.moveFileTool,
    fs_1.moveDirTool,
    fs_1.readSymlinkTool,
    fs_1.createSymlinkTool,
    txt_1.readFileTool,
    picture_1.readPictureTool,
    picture_1.writePictureTool,
    txt_1.createNewFileTool,
    txt_1.overwriteEntireFileTool,
    txt_1.fileRangeEditTool,
    txt_1.padWriteTool,
    txt_1.padLoadFileRangeTool,
    txt_1.padEditTool,
    txt_1.padInsertTool,
    txt_1.padDeleteRangeTool,
    txt_1.padCopyTool,
    txt_1.padMoveTool,
    txt_1.padDeleteTool,
    txt_1.fileAppendTool,
    txt_1.fileInsertAfterTool,
    txt_1.fileInsertBeforeTool,
    txt_1.fileBlockReplaceTool,
    txt_1.prepareOccurrenceReplaceTool,
    txt_1.applyOccurrenceReplaceTool,
    ripgrep_1.ripgrepFilesTool,
    ripgrep_1.ripgrepSnippetsTool,
    ripgrep_1.ripgrepCountTool,
    ripgrep_1.ripgrepFixedTool,
    ripgrep_1.ripgrepSearchTool,
]);
(0, registry_1.setToolsetMeta)('ws_mod', {
    source: 'dominds',
    descriptionI18n: {
        en: 'rtws read/write access: inspect, create, move, delete, precisely edit text files, and read/write workspace images.',
        zh: '运行时工作区读写访问：检查、创建、移动、删除、精确编辑文本文件，并读写工作区图片。',
    },
    promptFilesI18n: promptFilesFor('ws_mod'),
    manualSpec: manualSpecFor('ws_mod'),
});
// Inspect-and-patch helpers (function tools only; useful for GPT-5.x coding agents)
(0, registry_1.registerToolset)('codex_inspect_and_patch_tools', [os_1.readonlyShellTool, apply_patch_1.applyPatchTool]);
(0, registry_1.setToolsetMeta)('codex_inspect_and_patch_tools', {
    source: 'dominds',
    descriptionI18n: {
        en: 'Inspect-and-patch helpers: use readonly_shell for lightweight inspection and apply_patch for reviewable edits.',
        zh: '检查与补丁工具：用 readonly_shell 做轻量检查，用 apply_patch 做可审查修改。',
    },
    promptI18n: {
        en: 'Use `apply_patch` (apply_patch patch format) to modify files. Use `readonly_shell` for simple rtws (runtime workspace) inspection via its small allowlist; commands outside the allowlist are rejected. On Windows, `readonly_shell` runs through `cmd.exe`; use allowlisted commands available in that shell/PATH such as `rg`, `git`, `dir`, `type`, or `where`. For node/python, only exact version probes are allowed (no scripts). Chains via |/&&/|| are validated segment-by-segment. You are explicitly authorized to call `readonly_shell` yourself; do not delegate it to a shell specialist. Avoid multi-line script-style commands; single-line is preferred (|, &&, || are ok). Paths must be relative to the rtws (runtime workspace). Hard denies: `readonly_shell` refuses rtws-root `.minds/` and `.dialogs/`; `apply_patch` is subject to the same access-control (including hard denies for `*.tsk/`, `.minds/`, and rtws-root `.dialogs/`).',
        zh: '使用 `apply_patch`（apply_patch patch 格式）修改文件；使用 `readonly_shell` 做少量只读命令行检查，仅允许白名单命令前缀，白名单之外的命令会被拒绝。Windows 上 `readonly_shell` 通过 `cmd.exe` 执行；请使用该 shell/PATH 中可用的白名单命令，例如 `rg`、`git`、`dir`、`type` 或 `where`。对 node/python 仅允许版本探针（不允许脚本执行）。通过 |/&&/|| 串联命令时会按子命令逐段校验。你已被明确授权自行调用 `readonly_shell`，不要把它委派给 shell 专员。不建议多行脚本式命令，优先单行（允许 |、&&、||）。路径必须相对 rtws（运行时工作区）根目录。硬拒绝点：`readonly_shell` 无条件拒绝访问 rtws root 的 `.minds/` 与 `.dialogs/`；`apply_patch` 也受相同的访问控制约束（包含对 `*.tsk/`、`.minds/`、rtws root `.dialogs/` 的硬拒绝）。',
    },
    promptFilesI18n: promptFilesFor('codex_inspect_and_patch_tools'),
    manualSpec: manualSpecFor('codex_inspect_and_patch_tools'),
});
(0, registry_1.registerToolset)('team_mgmt', [...team_mgmt_1.teamMgmtTools]);
(0, registry_1.setToolsetMeta)('team_mgmt', {
    source: 'dominds',
    descriptionI18n: {
        en: 'Team management under `.minds/`: maintain team config, members, manuals, memory, and governed file changes.',
        zh: '`.minds/` 下的团队管理：维护团队配置、成员、手册、记忆与受控文件修改。',
    },
});
// Register ReminderOwners
(0, registry_1.registerReminderOwner)(os_1.shellCmdReminderOwner);
(0, registry_1.registerReminderOwner)(mcp_1.mcpLeaseReminderOwner);
(0, registry_1.registerReminderOwner)(pending_tellask_reminder_1.pendingTellaskReminderOwner);
(0, registry_1.registerReminderOwner)(txt_1.wsModPadReminderOwner);
