# Generated from Microi.Code/codex/src/microi-dsh-profile-bootstrap.js.
# Installed by: dsh plugin --profile <name> add @microi.net/cli
- insert:
    - id: microi-mcp
      name: '@deepseek-ai/dsh-mcp-client'
      config:
        serverName: microi
        transport: stdio
        command: !!js process.execPath
        args: ["-e","/*\n * DeepSeek Harness 通过 profile bundle 加载此 `node -e` 引导脚本。\n * DSH 不保证 MCP 子进程 cwd 位于 npm 包根，因此按 DSH_HOME/profile 定位\n * 当前版本的 @microi.net/cli，再复用 Codex 同源适配器与多连接路由器。\n */\nconst fs = require('node:fs');\nconst os = require('node:os');\nconst path = require('node:path');\nconst packageName = '@microi.net/cli';\nconst expectedVersion = '5.6.8';\n\nfunction readJson(filePath) {\n  try { return JSON.parse(fs.readFileSync(filePath, 'utf8')); }\n  catch { return undefined; }\n}\n\nfunction expandHome(value) {\n  if (value === '~') return os.homedir();\n  if (value.startsWith('~/') || value.startsWith('~\\\\')) return path.join(os.homedir(), value.slice(2));\n  return value;\n}\n\nfunction validRoot(value) {\n  const root = path.resolve(value);\n  const pkg = readJson(path.join(root, 'package.json'));\n  const patch = path.join(root, 'cordis.patch.yml');\n  const adapter = path.join(root, 'scripts', 'mcp-codex-stdio-adapter.js');\n  const router = path.join(root, 'scripts', 'microi-codex-router.js');\n  if (pkg?.name !== packageName || pkg?.version !== expectedVersion) return undefined;\n  if (pkg?.dsh?.bundle?.patch !== './cordis.patch.yml') return undefined;\n  if (![patch, adapter, router].every(filePath => fs.existsSync(filePath))) return undefined;\n  return { root: fs.realpathSync(root), adapter, router, modifiedAt: fs.statSync(router).mtimeMs };\n}\n\nfunction findPlugin() {\n  const explicit = String(process.env.MICROI_DSH_PLUGIN_ROOT || '').trim();\n  if (explicit) {\n    const plugin = validRoot(explicit);\n    if (!plugin) throw new Error(`MICROI_DSH_PLUGIN_ROOT 不是版本 ${expectedVersion} 的有效 Microi DSH bundle：${explicit}`);\n    return plugin;\n  }\n  const configuredHome = String(process.env.DSH_HOME || '').trim();\n  const dshHome = path.resolve(expandHome(configuredHome || path.join(os.homedir(), '.dsh')));\n  const profilesRoot = path.join(dshHome, 'profiles');\n  const candidates = [];\n  if (fs.existsSync(profilesRoot)) {\n    for (const entry of fs.readdirSync(profilesRoot, { withFileTypes: true })) {\n      if (!entry.isDirectory() || entry.name === 'node_modules') continue;\n      const root = path.join(profilesRoot, entry.name, 'node_modules', '@microi.net', 'cli');\n      const plugin = validRoot(root);\n      if (plugin) candidates.push(plugin);\n    }\n  }\n  candidates.sort((left, right) => right.modifiedAt - left.modifiedAt);\n  if (!candidates[0]) throw new Error(`未在 ${profilesRoot} 找到版本 ${expectedVersion} 的 ${packageName}`);\n  return candidates[0];\n}\n\ntry {\n  const plugin = findPlugin();\n  process.env.MICROI_DSH_PLUGIN_ROOT = plugin.root;\n  process.env.MICROI_CODEX_PLUGIN_ROOT = plugin.root;\n  process.env.MICROI_TOOL_SOURCE = 'dsh';\n  process.env.MICROI_TOOL_VERSION = expectedVersion;\n  process.env.MICROI_WORKSPACE_ROOT = process.env.MICROI_WORKSPACE_ROOT || process.cwd();\n  process.argv[2] = plugin.router;\n  require(plugin.adapter);\n} catch (error) {\n  console.error(`[microi-dsh-bootstrap] ${error instanceof Error ? error.message : String(error)}`);\n  process.exit(1);\n}\n"]
        env:
          MICROI_TOOL_SOURCE: dsh
        cwd: !!js process.cwd()
        failOnStartupError: false
        reconnect:
          enabled: true
          initialDelayMs: 500
          maxDelayMs: 30000
          maxAttempts: 10
