{
  // ============================================================
  // ★ 自定义工具包使用说明（示例文件）
  // ============================================================
  // 1. 本文件是一个"工具包"（Tool Package），由 export_custom_tools 导出，
  //    也可在"自定义工具管理"面板中上传导入（支持 // 与 /* */ 注释，
  //    导入时前端会自动剥离注释后解析）。
  // 2. 导入后自动执行安全审计：
  //      通过    → 工具升级为 host，可被 AI 正常调用
  //      可疑    → 保持 sandbox 受限，需在管理面板手动"审核/强制放行"
  // 3. 顶层结构固定为 { "version": 1, "tools": [...] }，tools 可含多个工具对象。
  // 4. 每个工具对象的字段（★ 为必填，其余可选，可省略或留空）：
  //      ★ name         工具名称（唯一标识，见下方命名规则）
  //      ★ description  工具描述，AI 据此决定何时调用
  //      ★ parameters   JSON Schema 参数定义，AI 按 description 自动填参
  //      ★ handler      async 函数字符串，签名 (args, ctx)
  //         handlerFiles 多文件 handler：{ main: "主函数字符串", files: { "lib.js": "..." } }
  //         imports      npm 依赖包名列表（导入时自动安装）
  //         permissions  权限标签数组；仅 "sandbox" 真正生效（强制 LXC 沙箱执行），
  //                      其余标签仅作审计记录，不产生强制限制
  //         timeout      单次调用超时毫秒数，范围 1000 ~ 7200000（2 小时），默认 60000
  //         hooks        生命周期钩子：{ pre, post, on_error }，值为函数字符串
  //                      pre 在调用前执行（可拦截/改参），post 在成功后执行，
  //                      on_error 在失败后执行
  //         schedule     定时任务：[{ cron: "分 时 日 月 周", args? }]，cron 为 5 字段表达式
  //         deps         依赖的其他工具名列表（声明后 AI 可先调依赖工具）
  //         tags         标签数组（用于检索/分类）
  //         examples     示例数组：["描述" 或 { description, args }]
  //         version      工具版本号（整数，默认 1）
// 5. 工具命名规则：正则 ^[A-Za-z0-9_]{1,32}$ —— 允许英文字母、数字、下划线（不区分大小写），
//    总长度 1~32，不能含连字符/点号/中文/空格；
//    同作用域重名将被拒绝注册（提示"不允许存在相同名称的工具，请修改名称"）。
  // 6. handler 签名 (args, ctx)：
  //      args → 按 parameters 定义的入参对象（AI 自动填参）
  //      ctx  → 运行上下文（host 状态下可用，sandbox 下部分受限）：
  //             ctx.run(cmd, timeout?, maxBuf?)     执行 shell 命令 → { stdout, stderr, code }
  //             ctx.exec(file, args?, opts?)        启动子进程 → { stdout, stderr, code }
  //             ctx.execWithStdin(file, args?, opts) 子进程 + 写 stdin
  //             ctx.execInteractive(cmd, opts?)     交互式子进程 { stdin, stdout, stderr, kill, wait }
  //             ctx.fs / ctx.path / ctx.os / ctx.util / ctx.crypto / ctx.url / ctx.zlib / ctx.Buffer
  //                  Node 内置模块直通（sandbox 下 fs 为 null）
  //             ctx.http                         安全 HTTP 客户端（sandbox 下为 null）
  //             ctx.callTool(name, args)         调用其他工具（受限，防递归）
  //             ctx.state / ctx.global            工具级 / 用户级 KV 存储
  //             ctx.progress(msg)                 上报进度
  //             ctx.logger.info/error(...)        日志
  //             ctx.userId / ctx.sessionId / ctx.workspace / ctx._envMode
  //      返回值   → 推荐 { content: "给 AI 的文本", data?: {结构化数据} }
  //            出错时返回 { content: "错误：..." } 即可
  // 7. 安全建议：不要写读取 /etc/passwd、rm -rf 等危险操作；确需系统能力
  //    请在 permissions 中声明 sandbox，否则滥用会被审计拦截/标记。
// 8. 变更后如需重新导入：先在管理面板"删除"旧工具，再上传新版本；
//    导入同名校验会拒绝注册（不会静默跳过），请改用其他名称。
  // ============================================================

  // 工具包格式版本（目前固定为 1）
  "version": 1,

  // 工具列表：可包含多个工具对象（本示例只演示 1 个）
  "tools": [
    {
      // [必填] 工具名称：AI 调用时使用的唯一标识，遵循命名规则
      "name": "randomPassword",

      // [必填] 工具描述：说明工具用途与参数，AI 据此决定何时调用
      "description": "生成随机安全密码：可指定长度（6-64）与字符集（小写/大写/数字/符号），默认全部启用、长度 16，可一次生成多个",

      // [必填] 参数定义：JSON Schema 格式，AI 按 description 自动填参
      "parameters": {
        "type": "object",
        "properties": {
          "length": {
            "type": "number",
            "description": "密码长度，6-64，默认 16"
          },
          "count": {
            "type": "number",
            "description": "生成几个密码，1-10，默认 1"
          },
          "lowercase": {
            "type": "boolean",
            "description": "包含小写字母，默认 true"
          },
          "uppercase": {
            "type": "boolean",
            "description": "包含大写字母，默认 true"
          },
          "digits": {
            "type": "boolean",
            "description": "包含数字，默认 true"
          },
          "symbols": {
            "type": "boolean",
            "description": "包含特殊符号，默认 true"
          }
        }
      },

      // [必填] 工具实现：async 函数字符串，参数 (args, ctx)，返回给 AI 的文本放在 content 中
      "handler": "async (args, ctx) => {\n  const length = Math.min(Math.max(parseInt(args.length) || 16, 6), 64);\n  const count = Math.min(Math.max(parseInt(args.count) || 1, 1), 10);\n  const useLower = args.lowercase !== false;\n  const useUpper = args.uppercase !== false;\n  const useDigits = args.digits !== false;\n  const useSymbols = args.symbols !== false;\n  let pool = '';\n  if (useLower) pool += 'abcdefghijklmnopqrstuvwxyz';\n  if (useUpper) pool += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\n  if (useDigits) pool += '0123456789';\n  if (useSymbols) pool += '!@#$%^&*()-_=+[]{};:,.<>?';\n  if (!pool) return { content: '错误：至少启用一种字符集' };\n  const rand = (n) => Math.floor(Math.random() * n);\n  const passwords = [];\n  for (let i = 0; i < count; i++) {\n    let p = '';\n    for (let j = 0; j < length; j++) p += pool[rand(pool.length)];\n    passwords.push(p);\n  }\n  return { content: passwords.join('\\n'), data: { count, length, charset: (useLower ? 'a-z ' : '') + (useUpper ? 'A-Z ' : '') + (useDigits ? '0-9 ' : '') + (useSymbols ? 'symbols' : '') } };\n}",

      // [可选] 多文件 handler：主函数在 handler，辅助文件放这里
      // 示例：{ "main": "async (args, ctx) => { const { helper } = require('./lib.js'); ... }", "files": { "lib.js": "module.exports = { helper: () => 1 };" } }
      "handlerFiles": {},

      // [可选] 需要安装的 npm 依赖包名列表（留空表示无第三方依赖）
      "imports": [],

      // [可选] 权限标签：仅 "sandbox" 真正生效（强制 LXC 沙箱），其余仅审计记录
      "permissions": [],

      // [可选] 单次调用超时（毫秒），范围 1000~7200000，默认 60000（60 秒）
      "timeout": 60000,

      // [可选] 生命周期钩子：{ pre, post, on_error }，值为 async 函数字符串
      // 示例：{ "pre": "async (args, ctx) => { if (!args.length) args.length = 16; return args; }" }
      "hooks": {},

      // [可选] 定时任务：{ cron: "分 时 日 月 周", args? } 数组
      // 示例：[{ "cron": "0 9 * * *", "args": { "length": 20 } }]（每天 9 点执行）
      "schedule": null,

      // [可选] 依赖的其他工具名列表
      "deps": [],

      // [可选] 标签数组
      "tags": ["password", "random"],

      // [可选] 示例数组：字符串 或 { description, args }
      "examples": [
        { "description": "生成一个 20 位默认字符集密码", "args": { "length": 20 } }
      ],

      // [可选] 工具版本号（整数）
      "version": 1
    }
  ]
}
