@microi.net/cli 5.8.6 → 5.8.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/.codebuddy-plugin/marketplace.json +2 -2
  2. package/.codebuddy-plugin/plugin.json +1 -1
  3. package/.codex-plugin/plugin.json +1 -1
  4. package/.mcp.json +1 -1
  5. package/.workbuddy-plugin/marketplace.json +2 -2
  6. package/.workbuddy-plugin/plugin.json +1 -1
  7. package/assets/build-meta.json +4 -4
  8. package/cordis.patch.yml +1 -1
  9. package/package.json +1 -1
  10. package/scripts/codex-marketplace.json +20 -20
  11. package/scripts/mcp-codex-stdio-adapter.js +189 -189
  12. package/scripts/mcp-server.js +1 -1
  13. package/scripts/mcp-trae-windows-launcher.cmd +21 -21
  14. package/scripts/microi-cli-mcp.js +7 -7
  15. package/scripts/microi-skills.meta.json +206 -206
  16. package/skills/.microi-skills-version.json +2 -2
  17. package/skills/.progressive-disclosure-manifest.json +3566 -3566
  18. package/skills/dos-orm/SKILL.md +4 -2
  19. package/skills/microi-client-frontend/SKILL.md +10 -7
  20. package/skills/microi-client-frontend/references/progressive-01-3-/345/212/250/346/200/201/346/214/211/351/222/256/347/263/273/347/273/237.md +3 -3
  21. package/skills/microi-client-frontend/references/progressive-02-8-/350/277/220/350/241/214/346/227/266/351/253/230/351/242/221/345/235/221/345/244/215/347/233/230.md +3 -3
  22. package/skills/microi-client-frontend/references/progressive-03-vue3-/345/211/215/347/253/257/345/276/256/346/234/215/345/212/241/345/256/277/344/270/273/350/247/204/345/210/231.md +3 -3
  23. package/skills/microi-codex/SKILL.md +3 -1
  24. package/skills/microi-deployment/SKILL.md +3 -1
  25. package/skills/microi-microservice/SKILL.md +2 -2
  26. package/skills/microi-sso/SKILL.md +7 -1
  27. package/skills/system-observability/SKILL.md +5 -2
@@ -5,13 +5,13 @@
5
5
  "url": "https://microi.net"
6
6
  },
7
7
  "description": "Microi吾码官方 AI 插件市场",
8
- "version": "5.8.6",
8
+ "version": "5.8.8",
9
9
  "plugins": [
10
10
  {
11
11
  "name": "microi",
12
12
  "source": ".",
13
13
  "description": "Microi吾码 AI 开发插件:服务器连接、Skills、MCP、V8 全量同步与低代码交付",
14
- "version": "5.8.6",
14
+ "version": "5.8.8",
15
15
  "strict": true
16
16
  }
17
17
  ]
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microi",
3
- "version": "5.8.6",
3
+ "version": "5.8.8",
4
4
  "description": "Microi吾码 AI 开发插件:服务器连接、Skills、MCP、V8 全量同步与低代码交付",
5
5
  "author": {
6
6
  "name": "Microi.Net",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microi",
3
- "version": "5.8.6",
3
+ "version": "5.8.8",
4
4
  "description": "Microi吾码低代码平台的 Codex 开发插件,共享 VS Code/CLI 的连接、同步、MCP、V8 与交付能力。",
5
5
  "author": {
6
6
  "name": "Microi.Net",
package/.mcp.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "command": "node",
5
5
  "args": [
6
6
  "-e",
7
- "/*\r\n * Codex CLI 仍不会把 plugin .mcp.json 的相对路径定位到插件根。\r\n * 本脚本作为 `node -e` 内容运行:CodeBuddy/WorkBuddy 优先使用宿主注入的\r\n * plugin root;Codex 则回退到官方 plugin cache,并统一执行双清单校验。\r\n */\r\nconst fs = require('node:fs');\r\nconst os = require('node:os');\r\nconst path = require('node:path');\r\nconst primaryPackageName = '@microi.net/cli';\r\nconst legacyPackageName = '@microi.net/codex-plugin';\r\n\r\nfunction readJson(filePath) {\r\n try { return JSON.parse(fs.readFileSync(filePath, 'utf8')); }\r\n catch { return undefined; }\r\n}\r\nfunction validPluginRoot(root) {\r\n const manifest = readJson(path.join(root, '.codex-plugin', 'plugin.json'));\r\n const pkg = readJson(path.join(root, 'package.json'));\r\n const adapter = path.join(root, 'scripts', 'mcp-codex-stdio-adapter.js');\r\n const router = path.join(root, 'scripts', 'microi-codex-router.js');\r\n if (manifest?.name !== 'microi' || ![primaryPackageName, legacyPackageName].includes(pkg?.name)) return undefined;\r\n if (!manifest.version || manifest.version !== pkg.version) return undefined;\r\n if (!fs.existsSync(adapter) || !fs.existsSync(router)) return undefined;\r\n return {\r\n root,\r\n adapter,\r\n router,\r\n packagePriority: pkg.name === primaryPackageName ? 1 : 0,\r\n modifiedAt: Math.max(fs.statSync(adapter).mtimeMs, fs.statSync(router).mtimeMs),\r\n };\r\n}\r\n\r\nfunction findPluginRoot() {\r\n const explicitRoots = [\r\n ['MICROI_CODEX_PLUGIN_ROOT', process.env.MICROI_CODEX_PLUGIN_ROOT],\r\n ['CODEBUDDY_PLUGIN_ROOT', process.env.CODEBUDDY_PLUGIN_ROOT],\r\n ['WORKBUDDY_PLUGIN_ROOT', process.env.WORKBUDDY_PLUGIN_ROOT],\r\n ['CLAUDE_PLUGIN_ROOT', process.env.CLAUDE_PLUGIN_ROOT],\r\n ];\r\n for (const [source, value] of explicitRoots) {\r\n const explicit = String(value || '').trim();\r\n if (!explicit) continue;\r\n const validated = validPluginRoot(path.resolve(explicit));\r\n if (!validated) throw new Error(`${source} 不是有效的 Microi Plugin:${explicit}`);\r\n return validated;\r\n }\r\n\r\n const codexHome = path.resolve(process.env.CODEX_HOME || path.join(os.homedir(), '.codex'));\r\n const cacheRoot = path.join(codexHome, 'plugins', 'cache');\r\n const candidates = [];\r\n if (fs.existsSync(cacheRoot)) {\r\n for (const marketplace of fs.readdirSync(cacheRoot, { withFileTypes: true }).filter(entry => entry.isDirectory())) {\r\n const pluginDir = path.join(cacheRoot, marketplace.name, 'microi');\r\n if (!fs.existsSync(pluginDir)) continue;\r\n for (const version of fs.readdirSync(pluginDir, { withFileTypes: true }).filter(entry => entry.isDirectory())) {\r\n const candidateRoot = path.resolve(pluginDir, version.name);\r\n const relative = path.relative(cacheRoot, candidateRoot);\r\n if (relative.startsWith('..') || path.isAbsolute(relative)) continue;\r\n const validated = validPluginRoot(candidateRoot);\r\n if (validated) candidates.push(validated);\r\n }\r\n }\r\n }\r\n candidates.sort((left, right) => right.packagePriority - left.packagePriority || right.modifiedAt - left.modifiedAt);\r\n if (!candidates[0]) {\r\n throw new Error(`未在 Codex plugin cache 找到有效的 Microi Agentx Plugin:${cacheRoot}`);\r\n }\r\n return candidates[0];\r\n}\r\n\r\ntry {\r\n const plugin = findPluginRoot();\r\n process.env.MICROI_CODEX_PLUGIN_ROOT = plugin.root;\r\n process.argv[2] = plugin.router;\r\n require(plugin.adapter);\r\n} catch (error) {\r\n console.error(`[microi-codex-bootstrap] ${error instanceof Error ? error.message : String(error)}`);\r\n process.exit(1);\r\n}\r\n"
7
+ "/*\n * Codex CLI 仍不会把 plugin .mcp.json 的相对路径定位到插件根。\n * 本脚本作为 `node -e` 内容运行:CodeBuddy/WorkBuddy 优先使用宿主注入的\n * plugin root;Codex 则回退到官方 plugin cache,并统一执行双清单校验。\n */\nconst fs = require('node:fs');\nconst os = require('node:os');\nconst path = require('node:path');\nconst primaryPackageName = '@microi.net/cli';\nconst legacyPackageName = '@microi.net/codex-plugin';\n\nfunction readJson(filePath) {\n try { return JSON.parse(fs.readFileSync(filePath, 'utf8')); }\n catch { return undefined; }\n}\nfunction validPluginRoot(root) {\n const manifest = readJson(path.join(root, '.codex-plugin', 'plugin.json'));\n const pkg = readJson(path.join(root, 'package.json'));\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 (manifest?.name !== 'microi' || ![primaryPackageName, legacyPackageName].includes(pkg?.name)) return undefined;\n if (!manifest.version || manifest.version !== pkg.version) return undefined;\n if (!fs.existsSync(adapter) || !fs.existsSync(router)) return undefined;\n return {\n root,\n adapter,\n router,\n packagePriority: pkg.name === primaryPackageName ? 1 : 0,\n modifiedAt: Math.max(fs.statSync(adapter).mtimeMs, fs.statSync(router).mtimeMs),\n };\n}\n\nfunction findPluginRoot() {\n const explicitRoots = [\n ['MICROI_CODEX_PLUGIN_ROOT', process.env.MICROI_CODEX_PLUGIN_ROOT],\n ['CODEBUDDY_PLUGIN_ROOT', process.env.CODEBUDDY_PLUGIN_ROOT],\n ['WORKBUDDY_PLUGIN_ROOT', process.env.WORKBUDDY_PLUGIN_ROOT],\n ['CLAUDE_PLUGIN_ROOT', process.env.CLAUDE_PLUGIN_ROOT],\n ];\n for (const [source, value] of explicitRoots) {\n const explicit = String(value || '').trim();\n if (!explicit) continue;\n const validated = validPluginRoot(path.resolve(explicit));\n if (!validated) throw new Error(`${source} 不是有效的 Microi Plugin:${explicit}`);\n return validated;\n }\n\n const codexHome = path.resolve(process.env.CODEX_HOME || path.join(os.homedir(), '.codex'));\n const cacheRoot = path.join(codexHome, 'plugins', 'cache');\n const candidates = [];\n if (fs.existsSync(cacheRoot)) {\n for (const marketplace of fs.readdirSync(cacheRoot, { withFileTypes: true }).filter(entry => entry.isDirectory())) {\n const pluginDir = path.join(cacheRoot, marketplace.name, 'microi');\n if (!fs.existsSync(pluginDir)) continue;\n for (const version of fs.readdirSync(pluginDir, { withFileTypes: true }).filter(entry => entry.isDirectory())) {\n const candidateRoot = path.resolve(pluginDir, version.name);\n const relative = path.relative(cacheRoot, candidateRoot);\n if (relative.startsWith('..') || path.isAbsolute(relative)) continue;\n const validated = validPluginRoot(candidateRoot);\n if (validated) candidates.push(validated);\n }\n }\n }\n candidates.sort((left, right) => right.packagePriority - left.packagePriority || right.modifiedAt - left.modifiedAt);\n if (!candidates[0]) {\n throw new Error(`未在 Codex plugin cache 找到有效的 Microi Agentx Plugin:${cacheRoot}`);\n }\n return candidates[0];\n}\n\ntry {\n const plugin = findPluginRoot();\n process.env.MICROI_CODEX_PLUGIN_ROOT = plugin.root;\n process.argv[2] = plugin.router;\n require(plugin.adapter);\n} catch (error) {\n console.error(`[microi-codex-bootstrap] ${error instanceof Error ? error.message : String(error)}`);\n process.exit(1);\n}\n"
8
8
  ]
9
9
  }
10
10
  }
@@ -5,13 +5,13 @@
5
5
  "url": "https://microi.net"
6
6
  },
7
7
  "description": "Microi吾码官方 AI 插件市场",
8
- "version": "5.8.6",
8
+ "version": "5.8.8",
9
9
  "plugins": [
10
10
  {
11
11
  "name": "microi",
12
12
  "source": ".",
13
13
  "description": "Microi吾码 AI 开发插件:服务器连接、Skills、MCP、V8 全量同步与低代码交付",
14
- "version": "5.8.6",
14
+ "version": "5.8.8",
15
15
  "strict": true
16
16
  }
17
17
  ]
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microi",
3
- "version": "5.8.6",
3
+ "version": "5.8.8",
4
4
  "description": "Microi吾码 AI 开发插件:服务器连接、Skills、MCP、V8 全量同步与低代码交付",
5
5
  "author": {
6
6
  "name": "Microi.Net",
@@ -1,6 +1,6 @@
1
1
  {
2
- "builtAt": "2026-10-09T08:18:06.823Z",
3
- "version": "5.8.6",
2
+ "builtAt": "2026-10-09T17:52:05.032Z",
3
+ "version": "5.8.8",
4
4
  "sourceProducts": [
5
5
  "vscode-extension",
6
6
  "microi-cli",
@@ -10,10 +10,10 @@
10
10
  "commands": 55,
11
11
  "skills": 68,
12
12
  "hashes": {
13
- "mcpServer": "ccc7697b5032db3ceb2851066cb5871515fae5d22348891f3f1d65dfd9d4eab1",
13
+ "mcpServer": "daf65060b88bc1a52bc0333e0f2a4c7aba2b0c97aa6c53c3d6c5189d40c15950",
14
14
  "cli": "622493d51fe81db1aae5e823384c79b663b889b3dd7028f5753a43d3f02d68f1",
15
15
  "router": "761b54007451348da5f6491245635c15c33663cae6c1811005839bc2312886e2",
16
16
  "broker": "fffe3a7bbbc0c842d69c2eda09a0490ce0055a060f56d6a6d6230046e8952749",
17
- "dshBundle": "44e789c25d59d362b9ecb21ee2cd079189b4714c10c4fdbde6e41313ab1fc3b8"
17
+ "dshBundle": "6dd03a134e1c1963629e4c157c46e00b6ce04e4bfaf8db295b3e8a8b7f37ef0e"
18
18
  }
19
19
  }
package/cordis.patch.yml CHANGED
@@ -7,7 +7,7 @@
7
7
  serverName: microi
8
8
  transport: stdio
9
9
  command: !!js process.execPath
10
- args: ["-e","/*\r\n * DeepSeek Harness 通过 profile bundle 加载此 `node -e` 引导脚本。\r\n * DSH 不保证 MCP 子进程 cwd 位于 npm 包根,因此按 DSH_HOME/profile 定位\r\n * 当前版本的 @microi.net/cli,再复用 Codex 同源适配器与多连接路由器。\r\n */\r\nconst fs = require('node:fs');\r\nconst os = require('node:os');\r\nconst path = require('node:path');\r\nconst packageName = '@microi.net/cli';\r\nconst expectedVersion = '5.8.6';\r\n\r\nfunction readJson(filePath) {\r\n try { return JSON.parse(fs.readFileSync(filePath, 'utf8')); }\r\n catch { return undefined; }\r\n}\r\n\r\nfunction expandHome(value) {\r\n if (value === '~') return os.homedir();\r\n if (value.startsWith('~/') || value.startsWith('~\\\\')) return path.join(os.homedir(), value.slice(2));\r\n return value;\r\n}\r\n\r\nfunction validRoot(value) {\r\n const root = path.resolve(value);\r\n const pkg = readJson(path.join(root, 'package.json'));\r\n const patch = path.join(root, 'cordis.patch.yml');\r\n const adapter = path.join(root, 'scripts', 'mcp-codex-stdio-adapter.js');\r\n const router = path.join(root, 'scripts', 'microi-codex-router.js');\r\n if (pkg?.name !== packageName || pkg?.version !== expectedVersion) return undefined;\r\n if (pkg?.dsh?.bundle?.patch !== './cordis.patch.yml') return undefined;\r\n if (![patch, adapter, router].every(filePath => fs.existsSync(filePath))) return undefined;\r\n return { root: fs.realpathSync(root), adapter, router, modifiedAt: fs.statSync(router).mtimeMs };\r\n}\r\n\r\nfunction findPlugin() {\r\n const explicit = String(process.env.MICROI_DSH_PLUGIN_ROOT || '').trim();\r\n if (explicit) {\r\n const plugin = validRoot(explicit);\r\n if (!plugin) throw new Error(`MICROI_DSH_PLUGIN_ROOT 不是版本 ${expectedVersion} 的有效 Microi DSH bundle:${explicit}`);\r\n return plugin;\r\n }\r\n const configuredHome = String(process.env.DSH_HOME || '').trim();\r\n const dshHome = path.resolve(expandHome(configuredHome || path.join(os.homedir(), '.dsh')));\r\n const profilesRoot = path.join(dshHome, 'profiles');\r\n const candidates = [];\r\n if (fs.existsSync(profilesRoot)) {\r\n for (const entry of fs.readdirSync(profilesRoot, { withFileTypes: true })) {\r\n if (!entry.isDirectory() || entry.name === 'node_modules') continue;\r\n const root = path.join(profilesRoot, entry.name, 'node_modules', '@microi.net', 'cli');\r\n const plugin = validRoot(root);\r\n if (plugin) candidates.push(plugin);\r\n }\r\n }\r\n candidates.sort((left, right) => right.modifiedAt - left.modifiedAt);\r\n if (!candidates[0]) throw new Error(`未在 ${profilesRoot} 找到版本 ${expectedVersion} 的 ${packageName}`);\r\n return candidates[0];\r\n}\r\n\r\ntry {\r\n const plugin = findPlugin();\r\n process.env.MICROI_DSH_PLUGIN_ROOT = plugin.root;\r\n process.env.MICROI_CODEX_PLUGIN_ROOT = plugin.root;\r\n process.env.MICROI_TOOL_SOURCE = 'dsh';\r\n process.env.MICROI_TOOL_VERSION = expectedVersion;\r\n process.env.MICROI_WORKSPACE_ROOT = process.env.MICROI_WORKSPACE_ROOT || process.cwd();\r\n process.argv[2] = plugin.router;\r\n require(plugin.adapter);\r\n} catch (error) {\r\n console.error(`[microi-dsh-bootstrap] ${error instanceof Error ? error.message : String(error)}`);\r\n process.exit(1);\r\n}\r\n"]
10
+ 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.8.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"]
11
11
  env:
12
12
  MICROI_TOOL_SOURCE: dsh
13
13
  cwd: !!js process.cwd()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microi.net/cli",
3
- "version": "5.8.6",
3
+ "version": "5.8.8",
4
4
  "description": "Microi吾码 AI 开发 CLI 与多宿主 Plugin:服务器连接、Skills、MCP、V8 同步和低代码交付",
5
5
  "license": "MIT",
6
6
  "homepage": "https://microi.net/doc/v8-engine/vs-code-plugin.html",
@@ -1,20 +1,20 @@
1
- {
2
- "name": "microi-net",
3
- "interface": {
4
- "displayName": "Microi.Net"
5
- },
6
- "plugins": [
7
- {
8
- "name": "microi",
9
- "source": {
10
- "source": "local",
11
- "path": "./plugins/microi"
12
- },
13
- "policy": {
14
- "installation": "AVAILABLE",
15
- "authentication": "ON_USE"
16
- },
17
- "category": "developer-tools"
18
- }
19
- ]
20
- }
1
+ {
2
+ "name": "microi-net",
3
+ "interface": {
4
+ "displayName": "Microi.Net"
5
+ },
6
+ "plugins": [
7
+ {
8
+ "name": "microi",
9
+ "source": {
10
+ "source": "local",
11
+ "path": "./plugins/microi"
12
+ },
13
+ "policy": {
14
+ "installation": "AVAILABLE",
15
+ "authentication": "ON_USE"
16
+ },
17
+ "category": "developer-tools"
18
+ }
19
+ ]
20
+ }
@@ -1,189 +1,189 @@
1
- #!/usr/bin/env node
2
- /*
3
- * Codex MCP stdio adapter for the bundled Microi MCP server.
4
- *
5
- * The MCP SDK version used by Microi currently speaks newline-delimited
6
- * JSON-RPC over stdio. Some Codex runtimes send and expect Content-Length
7
- * framed JSON-RPC. This adapter bridges both formats without changing the
8
- * normal VS Code/Cursor/Trae/Claude MCP configuration.
9
- */
10
-
11
- const childProcess = require('node:child_process');
12
- const path = require('node:path');
13
-
14
- const target = process.argv[2];
15
- if (!target) {
16
- console.error('[microi-mcp-adapter] Missing target MCP server path.');
17
- process.exit(1);
18
- }
19
-
20
- const child = childProcess.spawn(process.execPath, [target, ...process.argv.slice(3)], {
21
- cwd: process.cwd(),
22
- env: process.env,
23
- stdio: ['pipe', 'pipe', 'pipe'],
24
- windowsHide: true,
25
- });
26
-
27
- let inputBuffer = Buffer.alloc(0);
28
- let outputBuffer = Buffer.alloc(0);
29
- let clientFraming = null; // 'content-length' | 'line'
30
- let shutdownRequested = false;
31
- let requestedExitCode = 0;
32
- let forceExitTimer = null;
33
-
34
- function stopChildAndExit(exitCode = 0) {
35
- if (shutdownRequested) return;
36
- shutdownRequested = true;
37
- requestedExitCode = exitCode;
38
-
39
- if (!child.stdin.destroyed) {
40
- child.stdin.end();
41
- }
42
-
43
- if (child.exitCode !== null) {
44
- process.exit(requestedExitCode);
45
- }
46
-
47
- try {
48
- child.kill('SIGTERM');
49
- } catch {
50
- process.exit(requestedExitCode);
51
- }
52
-
53
- forceExitTimer = setTimeout(() => {
54
- try {
55
- child.kill('SIGKILL');
56
- } catch {
57
- // 子进程可能已在超时边界退出。
58
- }
59
- process.exit(requestedExitCode);
60
- }, 2000);
61
- }
62
-
63
- // Codex 会为每个 MCP 连接启动一个适配器。客户端退出、重载或异常断开时,
64
- // 必须同步终止其子 MCP 服务,否则孤儿进程会持续累积并挤占前端构建内存。
65
- process.stdin.on('end', () => stopChildAndExit(0));
66
- process.stdin.on('error', () => stopChildAndExit(1));
67
- process.stdout.on('error', error => {
68
- stopChildAndExit(error && error.code === 'EPIPE' ? 0 : 1);
69
- });
70
- process.on('disconnect', () => stopChildAndExit(0));
71
- for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
72
- process.on(signal, () => stopChildAndExit(0));
73
- }
74
-
75
- const parentPid = process.ppid;
76
- if (parentPid > 1) {
77
- const parentWatchTimer = setInterval(() => {
78
- try {
79
- process.kill(parentPid, 0);
80
- } catch (error) {
81
- if (error && error.code === 'ESRCH') {
82
- stopChildAndExit(0);
83
- }
84
- }
85
- }, 5000);
86
- parentWatchTimer.unref();
87
- }
88
-
89
- process.on('exit', () => {
90
- if (child.exitCode === null) {
91
- try {
92
- child.kill('SIGKILL');
93
- } catch {
94
- // 退出阶段只做尽力清理。
95
- }
96
- }
97
- });
98
-
99
- function writeLineToChild(jsonText) {
100
- if (!child.stdin.destroyed) {
101
- child.stdin.write(jsonText.trimEnd() + '\n');
102
- }
103
- }
104
-
105
- function writeToClient(jsonText) {
106
- const text = jsonText.trim();
107
- if (!text) return;
108
-
109
- if (clientFraming === 'line') {
110
- process.stdout.write(text + '\n');
111
- return;
112
- }
113
-
114
- const bytes = Buffer.byteLength(text, 'utf8');
115
- process.stdout.write(`Content-Length: ${bytes}\r\n\r\n${text}`);
116
- }
117
-
118
- function processInputBuffer() {
119
- while (inputBuffer.length > 0) {
120
- const asText = inputBuffer.toString('utf8');
121
-
122
- if (/^Content-Length:/i.test(asText)) {
123
- clientFraming = 'content-length';
124
- const headerEnd = asText.indexOf('\r\n\r\n');
125
- if (headerEnd < 0) return;
126
-
127
- const header = asText.slice(0, headerEnd);
128
- const match = header.match(/Content-Length:\s*(\d+)/i);
129
- if (!match) {
130
- console.error('[microi-mcp-adapter] Invalid Content-Length header.');
131
- stopChildAndExit(1);
132
- return;
133
- }
134
-
135
- const length = Number(match[1]);
136
- const bodyStart = Buffer.byteLength(asText.slice(0, headerEnd + 4), 'utf8');
137
- if (inputBuffer.length < bodyStart + length) return;
138
-
139
- const body = inputBuffer.slice(bodyStart, bodyStart + length).toString('utf8');
140
- writeLineToChild(body);
141
- inputBuffer = inputBuffer.slice(bodyStart + length);
142
- continue;
143
- }
144
-
145
- clientFraming = clientFraming || 'line';
146
- const newline = inputBuffer.indexOf(0x0a);
147
- if (newline < 0) return;
148
-
149
- const line = inputBuffer.slice(0, newline + 1).toString('utf8').trim();
150
- inputBuffer = inputBuffer.slice(newline + 1);
151
- if (line) {
152
- writeLineToChild(line);
153
- }
154
- }
155
- }
156
-
157
- process.stdin.on('data', chunk => {
158
- inputBuffer = Buffer.concat([inputBuffer, chunk]);
159
- processInputBuffer();
160
- });
161
-
162
- child.stdout.on('data', chunk => {
163
- outputBuffer = Buffer.concat([outputBuffer, chunk]);
164
- let newlineIndex;
165
- while ((newlineIndex = outputBuffer.indexOf(0x0a)) >= 0) {
166
- const line = outputBuffer.slice(0, newlineIndex).toString('utf8').trim();
167
- outputBuffer = outputBuffer.slice(newlineIndex + 1);
168
- if (line) writeToClient(line);
169
- }
170
- });
171
-
172
- child.stderr.on('data', chunk => {
173
- process.stderr.write(chunk);
174
- });
175
-
176
- child.on('exit', code => {
177
- if (forceExitTimer) {
178
- clearTimeout(forceExitTimer);
179
- }
180
- if (outputBuffer.length > 0) {
181
- writeToClient(outputBuffer.toString('utf8'));
182
- }
183
- process.exit(shutdownRequested ? requestedExitCode : (code || 0));
184
- });
185
-
186
- child.on('error', err => {
187
- console.error(`[microi-mcp-adapter] Failed to start ${path.basename(target)}: ${err.message}`);
188
- stopChildAndExit(1);
189
- });
1
+ #!/usr/bin/env node
2
+ /*
3
+ * Codex MCP stdio adapter for the bundled Microi MCP server.
4
+ *
5
+ * The MCP SDK version used by Microi currently speaks newline-delimited
6
+ * JSON-RPC over stdio. Some Codex runtimes send and expect Content-Length
7
+ * framed JSON-RPC. This adapter bridges both formats without changing the
8
+ * normal VS Code/Cursor/Trae/Claude MCP configuration.
9
+ */
10
+
11
+ const childProcess = require('node:child_process');
12
+ const path = require('node:path');
13
+
14
+ const target = process.argv[2];
15
+ if (!target) {
16
+ console.error('[microi-mcp-adapter] Missing target MCP server path.');
17
+ process.exit(1);
18
+ }
19
+
20
+ const child = childProcess.spawn(process.execPath, [target, ...process.argv.slice(3)], {
21
+ cwd: process.cwd(),
22
+ env: process.env,
23
+ stdio: ['pipe', 'pipe', 'pipe'],
24
+ windowsHide: true,
25
+ });
26
+
27
+ let inputBuffer = Buffer.alloc(0);
28
+ let outputBuffer = Buffer.alloc(0);
29
+ let clientFraming = null; // 'content-length' | 'line'
30
+ let shutdownRequested = false;
31
+ let requestedExitCode = 0;
32
+ let forceExitTimer = null;
33
+
34
+ function stopChildAndExit(exitCode = 0) {
35
+ if (shutdownRequested) return;
36
+ shutdownRequested = true;
37
+ requestedExitCode = exitCode;
38
+
39
+ if (!child.stdin.destroyed) {
40
+ child.stdin.end();
41
+ }
42
+
43
+ if (child.exitCode !== null) {
44
+ process.exit(requestedExitCode);
45
+ }
46
+
47
+ try {
48
+ child.kill('SIGTERM');
49
+ } catch {
50
+ process.exit(requestedExitCode);
51
+ }
52
+
53
+ forceExitTimer = setTimeout(() => {
54
+ try {
55
+ child.kill('SIGKILL');
56
+ } catch {
57
+ // 子进程可能已在超时边界退出。
58
+ }
59
+ process.exit(requestedExitCode);
60
+ }, 2000);
61
+ }
62
+
63
+ // Codex 会为每个 MCP 连接启动一个适配器。客户端退出、重载或异常断开时,
64
+ // 必须同步终止其子 MCP 服务,否则孤儿进程会持续累积并挤占前端构建内存。
65
+ process.stdin.on('end', () => stopChildAndExit(0));
66
+ process.stdin.on('error', () => stopChildAndExit(1));
67
+ process.stdout.on('error', error => {
68
+ stopChildAndExit(error && error.code === 'EPIPE' ? 0 : 1);
69
+ });
70
+ process.on('disconnect', () => stopChildAndExit(0));
71
+ for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
72
+ process.on(signal, () => stopChildAndExit(0));
73
+ }
74
+
75
+ const parentPid = process.ppid;
76
+ if (parentPid > 1) {
77
+ const parentWatchTimer = setInterval(() => {
78
+ try {
79
+ process.kill(parentPid, 0);
80
+ } catch (error) {
81
+ if (error && error.code === 'ESRCH') {
82
+ stopChildAndExit(0);
83
+ }
84
+ }
85
+ }, 5000);
86
+ parentWatchTimer.unref();
87
+ }
88
+
89
+ process.on('exit', () => {
90
+ if (child.exitCode === null) {
91
+ try {
92
+ child.kill('SIGKILL');
93
+ } catch {
94
+ // 退出阶段只做尽力清理。
95
+ }
96
+ }
97
+ });
98
+
99
+ function writeLineToChild(jsonText) {
100
+ if (!child.stdin.destroyed) {
101
+ child.stdin.write(jsonText.trimEnd() + '\n');
102
+ }
103
+ }
104
+
105
+ function writeToClient(jsonText) {
106
+ const text = jsonText.trim();
107
+ if (!text) return;
108
+
109
+ if (clientFraming === 'line') {
110
+ process.stdout.write(text + '\n');
111
+ return;
112
+ }
113
+
114
+ const bytes = Buffer.byteLength(text, 'utf8');
115
+ process.stdout.write(`Content-Length: ${bytes}\r\n\r\n${text}`);
116
+ }
117
+
118
+ function processInputBuffer() {
119
+ while (inputBuffer.length > 0) {
120
+ const asText = inputBuffer.toString('utf8');
121
+
122
+ if (/^Content-Length:/i.test(asText)) {
123
+ clientFraming = 'content-length';
124
+ const headerEnd = asText.indexOf('\r\n\r\n');
125
+ if (headerEnd < 0) return;
126
+
127
+ const header = asText.slice(0, headerEnd);
128
+ const match = header.match(/Content-Length:\s*(\d+)/i);
129
+ if (!match) {
130
+ console.error('[microi-mcp-adapter] Invalid Content-Length header.');
131
+ stopChildAndExit(1);
132
+ return;
133
+ }
134
+
135
+ const length = Number(match[1]);
136
+ const bodyStart = Buffer.byteLength(asText.slice(0, headerEnd + 4), 'utf8');
137
+ if (inputBuffer.length < bodyStart + length) return;
138
+
139
+ const body = inputBuffer.slice(bodyStart, bodyStart + length).toString('utf8');
140
+ writeLineToChild(body);
141
+ inputBuffer = inputBuffer.slice(bodyStart + length);
142
+ continue;
143
+ }
144
+
145
+ clientFraming = clientFraming || 'line';
146
+ const newline = inputBuffer.indexOf(0x0a);
147
+ if (newline < 0) return;
148
+
149
+ const line = inputBuffer.slice(0, newline + 1).toString('utf8').trim();
150
+ inputBuffer = inputBuffer.slice(newline + 1);
151
+ if (line) {
152
+ writeLineToChild(line);
153
+ }
154
+ }
155
+ }
156
+
157
+ process.stdin.on('data', chunk => {
158
+ inputBuffer = Buffer.concat([inputBuffer, chunk]);
159
+ processInputBuffer();
160
+ });
161
+
162
+ child.stdout.on('data', chunk => {
163
+ outputBuffer = Buffer.concat([outputBuffer, chunk]);
164
+ let newlineIndex;
165
+ while ((newlineIndex = outputBuffer.indexOf(0x0a)) >= 0) {
166
+ const line = outputBuffer.slice(0, newlineIndex).toString('utf8').trim();
167
+ outputBuffer = outputBuffer.slice(newlineIndex + 1);
168
+ if (line) writeToClient(line);
169
+ }
170
+ });
171
+
172
+ child.stderr.on('data', chunk => {
173
+ process.stderr.write(chunk);
174
+ });
175
+
176
+ child.on('exit', code => {
177
+ if (forceExitTimer) {
178
+ clearTimeout(forceExitTimer);
179
+ }
180
+ if (outputBuffer.length > 0) {
181
+ writeToClient(outputBuffer.toString('utf8'));
182
+ }
183
+ process.exit(shutdownRequested ? requestedExitCode : (code || 0));
184
+ });
185
+
186
+ child.on('error', err => {
187
+ console.error(`[microi-mcp-adapter] Failed to start ${path.basename(target)}: ${err.message}`);
188
+ stopChildAndExit(1);
189
+ });