@ken-jo/agent-connector 0.4.0 → 0.4.1
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.
- package/README.md +8 -8
- package/dist/{action-PLZW5BGX.js → action-WT7GVRCC.js} +11 -10
- package/dist/{action-PLZW5BGX.js.map → action-WT7GVRCC.js.map} +1 -1
- package/dist/amazon-q-COAL3764.js +276 -0
- package/dist/amazon-q-COAL3764.js.map +1 -0
- package/dist/{amp-B524U6LO.js → amp-4U33CU7E.js} +3 -3
- package/dist/{antigravity-ANDKF3K7.js → antigravity-AMKKKHS4.js} +4 -4
- package/dist/{antigravity-cli-LLRPDDOT.js → antigravity-cli-XERXEH5W.js} +4 -4
- package/dist/{chunk-KGJWE6A2.js → chunk-24IDL5RW.js} +2 -2
- package/dist/{chunk-CIRDOY2V.js → chunk-2AVLX7GH.js} +3 -3
- package/dist/{chunk-ADTHT2FN.js → chunk-4ENJK5S2.js} +10 -173
- package/dist/chunk-4ENJK5S2.js.map +1 -0
- package/dist/{chunk-BHUCB6LY.js → chunk-5OWS5CMA.js} +8 -7
- package/dist/{chunk-BHUCB6LY.js.map → chunk-5OWS5CMA.js.map} +1 -1
- package/dist/{chunk-IW77FFNX.js → chunk-CPLK7GTE.js} +41 -5
- package/dist/chunk-CPLK7GTE.js.map +1 -0
- package/dist/chunk-DCKFYWGM.js +237 -0
- package/dist/chunk-DCKFYWGM.js.map +1 -0
- package/dist/{chunk-J3D5W5T2.js → chunk-EGCBZ2DC.js} +2 -2
- package/dist/{chunk-22Y24V7O.js → chunk-F5RX62T7.js} +2 -2
- package/dist/chunk-FAHIMJRU.js +177 -0
- package/dist/chunk-FAHIMJRU.js.map +1 -0
- package/dist/{chunk-BXGFUENQ.js → chunk-I5MLE6S7.js} +14 -1
- package/dist/{chunk-BXGFUENQ.js.map → chunk-I5MLE6S7.js.map} +1 -1
- package/dist/{chunk-LL4OBGRU.js → chunk-LQRAPXS4.js} +3 -3
- package/dist/{chunk-KGXDYGNJ.js → chunk-O5TWCIJN.js} +19 -19
- package/dist/{chunk-KGXDYGNJ.js.map → chunk-O5TWCIJN.js.map} +1 -1
- package/dist/{chunk-MAH6QQTO.js → chunk-QREL7LZJ.js} +5 -4
- package/dist/chunk-QREL7LZJ.js.map +1 -0
- package/dist/{chunk-G3ER4SY5.js → chunk-RIMVWCZY.js} +9 -9
- package/dist/{chunk-6XHB6BE3.js → chunk-SCVBYSF7.js} +1 -1
- package/dist/{chunk-KGGBNKI4.js → chunk-URHQMFB3.js} +90 -13
- package/dist/chunk-URHQMFB3.js.map +1 -0
- package/dist/chunk-WZA4CSGJ.js +28 -0
- package/dist/chunk-WZA4CSGJ.js.map +1 -0
- package/dist/{chunk-76FUSVIA.js → chunk-XJ4S47CT.js} +6 -5
- package/dist/chunk-XJ4S47CT.js.map +1 -0
- package/dist/{claude-code-MLWS7CW6.js → claude-code-W4PUFZL5.js} +20 -30
- package/dist/claude-code-W4PUFZL5.js.map +1 -0
- package/dist/cli/sdk.js +5 -4
- package/dist/cli/sdk.js.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/cline-WRYMNS7Z.js +442 -0
- package/dist/cline-WRYMNS7Z.js.map +1 -0
- package/dist/{codebuff-SH2S3QAN.js → codebuff-DH5Y7GAT.js} +8 -4
- package/dist/codebuff-DH5Y7GAT.js.map +1 -0
- package/dist/{codex-BXA4FIF4.js → codex-DDHIV767.js} +43 -11
- package/dist/codex-DDHIV767.js.map +1 -0
- package/dist/continue-K43SUHLQ.js +790 -0
- package/dist/continue-K43SUHLQ.js.map +1 -0
- package/dist/{copilot-cli-ROIBTTDT.js → copilot-cli-Q3SSPT4V.js} +70 -12
- package/dist/copilot-cli-Q3SSPT4V.js.map +1 -0
- package/dist/{crush-QLEFLHUC.js → crush-MBEH2R3I.js} +130 -6
- package/dist/crush-MBEH2R3I.js.map +1 -0
- package/dist/{cursor-ASJPWZ4R.js → cursor-TMBXDYR4.js} +119 -19
- package/dist/cursor-TMBXDYR4.js.map +1 -0
- package/dist/{detect-ZIIS55LD.js → detect-KG5FG3EV.js} +5 -4
- package/dist/{detect-ZIIS55LD.js.map → detect-KG5FG3EV.js.map} +1 -1
- package/dist/{doctor-TJUGSQ5C.js → doctor-FLZF34Y3.js} +221 -95
- package/dist/doctor-FLZF34Y3.js.map +1 -0
- package/dist/{droid-NCSS3B5Y.js → droid-JC2NT6S4.js} +135 -13
- package/dist/droid-JC2NT6S4.js.map +1 -0
- package/dist/{gemini-cli-SLVWLXJW.js → gemini-cli-ILR7M5X3.js} +62 -10
- package/dist/gemini-cli-ILR7M5X3.js.map +1 -0
- package/dist/{goose-PBA7KTE5.js → goose-SFO5BBGW.js} +15 -8
- package/dist/goose-SFO5BBGW.js.map +1 -0
- package/dist/{hermes-ONDCECP2.js → hermes-3N7WN4WS.js} +329 -15
- package/dist/hermes-3N7WN4WS.js.map +1 -0
- package/dist/{hook-OU522ABV.js → hook-XR3Z45FB.js} +14 -11
- package/dist/hook-XR3Z45FB.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -2
- package/dist/{install-UDCBL7HP.js → install-BSR62UHJ.js} +11 -10
- package/dist/{install-UDCBL7HP.js.map → install-BSR62UHJ.js.map} +1 -1
- package/dist/{introspect-DuZSPSHB.d.ts → introspect-Nw8hTReX.d.ts} +1 -1
- package/dist/{jetbrains-copilot-YABZ3HFA.js → jetbrains-copilot-NRZHI5PC.js} +85 -18
- package/dist/jetbrains-copilot-NRZHI5PC.js.map +1 -0
- package/dist/{kilo-F3ZDZKCT.js → kilo-5NWOXVSD.js} +16 -16
- package/dist/kilo-5NWOXVSD.js.map +1 -0
- package/dist/{kilo-cli-3HWPWBY4.js → kilo-cli-UZ7R5UOP.js} +3 -3
- package/dist/{kimi-NV72FVAO.js → kimi-2YFK2GBA.js} +87 -25
- package/dist/kimi-2YFK2GBA.js.map +1 -0
- package/dist/{kiro-C5W6AGDR.js → kiro-YL6AWUYG.js} +3 -3
- package/dist/{leaderboard-TIBVONVT.js → leaderboard-MJG24O35.js} +3 -3
- package/dist/{mimo-code-IMM5YM3M.js → mimo-code-FTMGSKMQ.js} +41 -5
- package/dist/mimo-code-FTMGSKMQ.js.map +1 -0
- package/dist/{mux-DSSH4AFS.js → mux-5XZFB44C.js} +156 -6
- package/dist/mux-5XZFB44C.js.map +1 -0
- package/dist/{nemoclaw-3EVNKD3I.js → nemoclaw-W5KEJ3WX.js} +4 -4
- package/dist/{omp-Z6FRNDPN.js → omp-2QMEY6HD.js} +138 -18
- package/dist/omp-2QMEY6HD.js.map +1 -0
- package/dist/{openclaw-7G437NT7.js → openclaw-EXJEFNZI.js} +4 -4
- package/dist/{opencode-Q6KBSAKW.js → opencode-WNXYJR4X.js} +84 -27
- package/dist/opencode-WNXYJR4X.js.map +1 -0
- package/dist/{package-RMPN57YZ.js → package-ACZXJHWB.js} +8 -7
- package/dist/{package-RMPN57YZ.js.map → package-ACZXJHWB.js.map} +1 -1
- package/dist/{pi-LZT6WWAZ.js → pi-PVVPVWKG.js} +3 -2
- package/dist/{pi-LZT6WWAZ.js.map → pi-PVVPVWKG.js.map} +1 -1
- package/dist/{qwen-code-WQBKRPWJ.js → qwen-code-G4CXKUHR.js} +426 -10
- package/dist/qwen-code-G4CXKUHR.js.map +1 -0
- package/dist/{roo-code-GWSNU3OW.js → roo-code-67TYJIQR.js} +3 -3
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +9 -8
- package/dist/sdk/index.d.ts +3 -3
- package/dist/sdk/index.js +4 -3
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/test.d.ts +2 -2
- package/dist/sdk/test.js +6 -5
- package/dist/sdk/test.js.map +1 -1
- package/dist/{serve-D3GO36UT.js → serve-GER7URPR.js} +11 -10
- package/dist/{serve-D3GO36UT.js.map → serve-GER7URPR.js.map} +1 -1
- package/dist/{status-KOSKCETC.js → status-LAJE3BM5.js} +7 -6
- package/dist/{status-KOSKCETC.js.map → status-LAJE3BM5.js.map} +1 -1
- package/dist/{statusline-ZNTCL5YC.js → statusline-L376ZPZU.js} +10 -9
- package/dist/{statusline-ZNTCL5YC.js.map → statusline-L376ZPZU.js.map} +1 -1
- package/dist/{telemetry-XIKUUGTQ.js → telemetry-B3DX3PWU.js} +6 -5
- package/dist/{telemetry-XIKUUGTQ.js.map → telemetry-B3DX3PWU.js.map} +1 -1
- package/dist/{trae-NWT3TMSZ.js → trae-7CZZGOGI.js} +3 -3
- package/dist/{types-BEKsAium.d.ts → types-CRVrFWeU.d.ts} +64 -22
- package/dist/{uninstall-2LBLQVFA.js → uninstall-ZYTW7YMZ.js} +11 -10
- package/dist/{uninstall-2LBLQVFA.js.map → uninstall-ZYTW7YMZ.js.map} +1 -1
- package/dist/{upgrade-ZC2S7VRN.js → upgrade-4LUEEOZW.js} +11 -10
- package/dist/{upgrade-ZC2S7VRN.js.map → upgrade-4LUEEOZW.js.map} +1 -1
- package/dist/{usage-E2A4O2CY.js → usage-ZFBVQF3H.js} +3 -3
- package/dist/{usage-event-JKMC4QC4.js → usage-event-GZ32AGEB.js} +10 -9
- package/dist/{usage-event-JKMC4QC4.js.map → usage-event-GZ32AGEB.js.map} +1 -1
- package/dist/{vscode-copilot-ALV45XF6.js → vscode-copilot-MF2CDNMT.js} +23 -10
- package/dist/vscode-copilot-MF2CDNMT.js.map +1 -0
- package/dist/{warp-H6IX4U3J.js → warp-VKG55TAT.js} +55 -4
- package/dist/warp-VKG55TAT.js.map +1 -0
- package/dist/windsurf-FU5G4SHF.js +443 -0
- package/dist/windsurf-FU5G4SHF.js.map +1 -0
- package/dist/{zed-RH34TNSW.js → zed-SFUHL3GS.js} +3 -3
- package/package.json +2 -2
- package/dist/chunk-3PFFTFCU.js +0 -190
- package/dist/chunk-3PFFTFCU.js.map +0 -1
- package/dist/chunk-76FUSVIA.js.map +0 -1
- package/dist/chunk-ADTHT2FN.js.map +0 -1
- package/dist/chunk-IW77FFNX.js.map +0 -1
- package/dist/chunk-KGGBNKI4.js.map +0 -1
- package/dist/chunk-MAH6QQTO.js.map +0 -1
- package/dist/claude-code-MLWS7CW6.js.map +0 -1
- package/dist/codebuff-SH2S3QAN.js.map +0 -1
- package/dist/codex-BXA4FIF4.js.map +0 -1
- package/dist/copilot-cli-ROIBTTDT.js.map +0 -1
- package/dist/crush-QLEFLHUC.js.map +0 -1
- package/dist/cursor-ASJPWZ4R.js.map +0 -1
- package/dist/doctor-TJUGSQ5C.js.map +0 -1
- package/dist/droid-NCSS3B5Y.js.map +0 -1
- package/dist/gemini-cli-SLVWLXJW.js.map +0 -1
- package/dist/goose-PBA7KTE5.js.map +0 -1
- package/dist/hermes-ONDCECP2.js.map +0 -1
- package/dist/hook-OU522ABV.js.map +0 -1
- package/dist/jetbrains-copilot-YABZ3HFA.js.map +0 -1
- package/dist/kilo-F3ZDZKCT.js.map +0 -1
- package/dist/kimi-NV72FVAO.js.map +0 -1
- package/dist/mimo-code-IMM5YM3M.js.map +0 -1
- package/dist/mux-DSSH4AFS.js.map +0 -1
- package/dist/omp-Z6FRNDPN.js.map +0 -1
- package/dist/opencode-Q6KBSAKW.js.map +0 -1
- package/dist/qwen-code-WQBKRPWJ.js.map +0 -1
- package/dist/vscode-copilot-ALV45XF6.js.map +0 -1
- package/dist/warp-H6IX4U3J.js.map +0 -1
- /package/dist/{amp-B524U6LO.js.map → amp-4U33CU7E.js.map} +0 -0
- /package/dist/{antigravity-ANDKF3K7.js.map → antigravity-AMKKKHS4.js.map} +0 -0
- /package/dist/{antigravity-cli-LLRPDDOT.js.map → antigravity-cli-XERXEH5W.js.map} +0 -0
- /package/dist/{chunk-KGJWE6A2.js.map → chunk-24IDL5RW.js.map} +0 -0
- /package/dist/{chunk-CIRDOY2V.js.map → chunk-2AVLX7GH.js.map} +0 -0
- /package/dist/{chunk-J3D5W5T2.js.map → chunk-EGCBZ2DC.js.map} +0 -0
- /package/dist/{chunk-22Y24V7O.js.map → chunk-F5RX62T7.js.map} +0 -0
- /package/dist/{chunk-LL4OBGRU.js.map → chunk-LQRAPXS4.js.map} +0 -0
- /package/dist/{chunk-G3ER4SY5.js.map → chunk-RIMVWCZY.js.map} +0 -0
- /package/dist/{chunk-6XHB6BE3.js.map → chunk-SCVBYSF7.js.map} +0 -0
- /package/dist/{kilo-cli-3HWPWBY4.js.map → kilo-cli-UZ7R5UOP.js.map} +0 -0
- /package/dist/{kiro-C5W6AGDR.js.map → kiro-YL6AWUYG.js.map} +0 -0
- /package/dist/{leaderboard-TIBVONVT.js.map → leaderboard-MJG24O35.js.map} +0 -0
- /package/dist/{nemoclaw-3EVNKD3I.js.map → nemoclaw-W5KEJ3WX.js.map} +0 -0
- /package/dist/{openclaw-7G437NT7.js.map → openclaw-EXJEFNZI.js.map} +0 -0
- /package/dist/{roo-code-GWSNU3OW.js.map → roo-code-67TYJIQR.js.map} +0 -0
- /package/dist/{trae-NWT3TMSZ.js.map → trae-7CZZGOGI.js.map} +0 -0
- /package/dist/{usage-E2A4O2CY.js.map → usage-ZFBVQF3H.js.map} +0 -0
- /package/dist/{zed-RH34TNSW.js.map → zed-SFUHL3GS.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapters/kilo/index.ts"],"sourcesContent":["/**\n * adapters/kilo — Kilo Code (VS Code extension) platform adapter.\n *\n * Kilo Code (`kilocode.kilo-code`) is a Roo/Cline-fork VS Code extension that\n * as of vsix 7.x was REBUILT on the Kilo CLI server and shares ONE backend with\n * the Kilo CLI (adapter id \"kilo-cli\"). Paradigm: **ts-plugin** (same plugin\n * layer the CLI uses).\n *\n * MCP config (vsix 7.3.28 — delegated to the kilo backend):\n * - user scope → ~/.config/kilo/kilo.json (XDG: $XDG_CONFIG_HOME/kilo)\n * - project scope → <projectDir>/.kilo/kilo.json\n * Both are JSON, root key **\"mcp\"**, entry shape\n * { type:\"local\", command:[exe,...args], environment:{} } (array command).\n * The legacy globalStorage `<vscodeUserDir>/globalStorage/kilocode.kilo-code/\n * settings/mcp_settings.json` (root \"mcpServers\") is MIGRATION-ONLY in 7.3.28\n * and is no longer the live write target — detectInstalled() still probes it so\n * an older install is recognized, but we install into kilo.json.\n *\n * SHARED BACKEND NOTE: kilo.json (VS Code ext) AND kilo.jsonc (CLI) are MERGED\n * by the ONE shared backend at user / project-root / .kilo/ levels — 3-way merge\n * verified live. The two platform IDs remain distinct for collision tracking, but\n * they share the same config dir and the backend dedupes across both files.\n *\n * Env interpolation: {env:VARIABLE_NAME} is documented by the pi/kilo backend.\n * We still resolve env refs to literals at install time (the conservative path,\n * consistent with kilo-cli) to avoid any version dependency on the interpolation\n * feature being present at runtime.\n *\n * Hooks (ts-plugin — same layer as kilo-cli):\n * The plugins doc banner reads \"applies to current VSCode extension & CLI\".\n * Plugin dirs: project → <projectDir>/.kilo/plugin/, user → ~/.config/kilo/plugin/.\n * Auto-discovery applies (as in the CLI ≥ 7.3.16), and we ALSO register the\n * module path in kilo.json's `plugin` array for explicit load (both loaded).\n * Event names: same as kilo-cli (\"tool.execute.before\", \"tool.execute.after\",\n * \"experimental.chat.system.transform\"). Bridge shims to \"kilo\" (not \"kilo-cli\").\n *\n * Content surfaces:\n * Commands → .kilocode/commands (project) / ~/.kilocode/commands (user)\n * Skills → .kilo/skills/<name>/SKILL.md (project) / ~/.kilo/skills (user)\n * Subagents → .kilocode/agents (project) / ~/.kilocode/agents (user)\n */\n\nimport {\n chmodSync,\n existsSync,\n mkdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from \"node:fs\";\nimport { homedir, platform as osPlatform } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nimport { BaseAdapter } from \"../base.js\";\nimport type {\n Adapter,\n GeneratedPluginFile,\n HookReply,\n InstallContext,\n MemoryTarget,\n NormalizedEvent,\n} from \"../spi.js\";\nimport type {\n ChangeRecord,\n CommandDef,\n DetectedPlatform,\n HealthCheck,\n HookEventName,\n HookParadigm,\n HookResponse,\n PlatformCapabilities,\n PlatformId,\n PostToolUseEvent,\n PreToolUseEvent,\n ServerDef,\n SessionStartEvent,\n SkillDef,\n SubagentDef,\n Transport,\n} from \"../../core/types.js\";\nimport { resolveEnvRefsDeep } from \"../../core/interpolate.js\";\nimport {\n buildServeWrapperCommand,\n shouldWrapForTelemetry,\n} from \"../../core/spawn.js\";\n\nconst HOST: PlatformId = \"kilo\";\n/** vsix 7.3.28 root key in kilo.json (delegated kilo backend). */\nconst MCP_ROOT_KEY = \"mcp\";\n/** kilo.json array of plugin module paths (also supports auto-discovery). */\nconst PLUGIN_ARRAY_KEY = \"plugin\";\n/** Live config filename for the VS Code ext (DISTINCT from the CLI's kilo.jsonc). */\nconst CONFIG_FILE = \"kilo.json\";\n\n/** Kilo Code extension id → its (legacy, migration-only) VS Code globalStorage folder. */\nconst KILO_EXTENSION_ID = \"kilocode.kilo-code\";\n/**\n * Legacy globalStorage MCP settings filenames (MIGRATION-ONLY in 7.3.28). The\n * Cline-family alternative is probed during detection so an older install is\n * still recognized; we no longer WRITE there.\n */\nconst LEGACY_MCP_SETTINGS_FILE = \"mcp_settings.json\";\nconst LEGACY_CLINE_SETTINGS_FILE = \"cline_mcp_settings.json\";\n\n/**\n * Canonical → Kilo (shared ts-plugin layer) event name map. Identical to the\n * kilo-cli mapping: the extension and CLI share the same plugin event model.\n */\nconst EVENT_TO_KILO: Partial<Record<HookEventName, string>> = {\n PreToolUse: \"tool.execute.before\",\n PostToolUse: \"tool.execute.after\",\n SessionStart: \"experimental.chat.system.transform\",\n};\n\n/** Raw payload the generated plugin posts to the universal hook entrypoint. */\ninterface KiloBridgePayload {\n toolName?: string;\n toolInput?: Record<string, unknown>;\n toolOutput?: string;\n isError?: boolean;\n sessionId?: string;\n projectDir?: string;\n}\n\n/**\n * Native MCP server entry shapes kilo.json accepts under `mcp` (the delegated\n * kilo backend). Local (stdio) servers use a SINGLE array command that folds the\n * executable and its args together; env lives under `environment`.\n */\ninterface KiloLocalServer {\n type: \"local\";\n command: string[];\n environment: Record<string, string>;\n}\ninterface KiloRemoteServer {\n type: \"remote\";\n url: string;\n headers?: Record<string, string>;\n}\n\n/**\n * Resolve the kilo backend user config dir: `$XDG_CONFIG_HOME/kilo` when set,\n * else `~/.config/kilo`. This is the SAME backend dir kilo-cli uses (the two\n * differ only by filename — kilo.json here vs kilo.jsonc for the CLI).\n */\nfunction kiloConfigDir(): string {\n const xdg = process.env.XDG_CONFIG_HOME;\n const base =\n xdg && xdg.trim() !== \"\" ? xdg : join(homedir(), \".config\");\n return join(base, \"kilo\");\n}\n\n/**\n * Resolve the cross-OS VS Code per-user data directory (the \"User\" folder that\n * contains `globalStorage`) — used ONLY to probe the legacy migration-only MCP\n * settings file during detection. See module header for the per-platform mapping.\n */\nfunction vscodeUserDir(): string {\n const home = homedir();\n switch (osPlatform()) {\n case \"darwin\":\n return join(home, \"Library\", \"Application Support\", \"Code\", \"User\");\n case \"win32\": {\n const appData = process.env.APPDATA ?? join(home, \"AppData\", \"Roaming\");\n return join(appData, \"Code\", \"User\");\n }\n default:\n // Linux / other POSIX: XDG-style config dir.\n return join(home, \".config\", \"Code\", \"User\");\n }\n}\n\nexport class KiloAdapter extends BaseAdapter implements Adapter {\n readonly id: PlatformId = HOST;\n readonly name = \"Kilo Code\";\n readonly paradigm: HookParadigm = \"ts-plugin\";\n\n readonly capabilities: PlatformCapabilities = {\n // Memory surface: AGENTS.md-first managed block (project <projectDir>/AGENTS.md\n // via the base default; user scope → ~/.kilocode/rules/agent-connector.md below).\n supportsMemory: true,\n // Kilo Code 7.x shares the ts-plugin layer with the Kilo CLI — same events.\n preToolUse: true,\n postToolUse: true,\n preCompact: false,\n sessionStart: true,\n sessionEnd: false,\n userPromptSubmit: false,\n stop: false,\n notification: false,\n canModifyArgs: true,\n canModifyOutput: true,\n canInjectSessionContext: true,\n // Kilo Code registers stdio, SSE, and Streamable HTTP MCP servers.\n transports: [\"stdio\", \"sse\", \"http\"],\n // Content surfaces: commands, skills (since 7.x rebuild), and subagents.\n supportsCommands: true,\n supportsSkills: true,\n supportsSubagents: true,\n };\n\n // ── Detection ────────────────────────────────────────────────────────────\n\n detectInstalled(projectDir: string): DetectedPlatform {\n const userConfig = this.userConfigPath();\n const userBackendDir = kiloConfigDir();\n // Probe the legacy (migration-only) globalStorage MCP settings too so an\n // older install is still recognized; we never WRITE there anymore.\n const legacyExtDir = join(vscodeUserDir(), \"globalStorage\", KILO_EXTENSION_ID);\n const legacySettings = join(legacyExtDir, \"settings\", LEGACY_MCP_SETTINGS_FILE);\n const legacyClineSettings = join(\n legacyExtDir,\n \"settings\",\n LEGACY_CLINE_SETTINGS_FILE,\n );\n const projectConfig = join(projectDir, \".kilo\", CONFIG_FILE);\n\n const userMatch =\n existsSync(userConfig) ||\n existsSync(userBackendDir) ||\n existsSync(legacySettings) ||\n existsSync(legacyClineSettings) ||\n existsSync(legacyExtDir);\n const projectMatch = existsSync(projectConfig);\n const installed = userMatch || projectMatch;\n\n // Prefer the user scope/path when present; otherwise surface the project one.\n const scope = userMatch || !projectMatch ? \"user\" : \"project\";\n const configPath = scope === \"user\" ? userConfig : projectConfig;\n const reason = installed\n ? userMatch\n ? `found Kilo Code config under ${userBackendDir}`\n : `found Kilo Code project config at ${projectConfig}`\n : `no Kilo Code config at ${userBackendDir} or ${projectConfig}`;\n\n return {\n id: this.id,\n name: this.name,\n installed,\n paradigm: this.paradigm,\n capabilities: this.capabilities,\n configPath,\n scope,\n reason,\n confidence: installed ? \"high\" : \"low\",\n };\n }\n\n // ── Native paths ─────────────────────────────────────────────────────────\n\n /** Absolute path to the user-scope kilo.json (kilo backend, XDG dir). */\n private userConfigPath(): string {\n return join(kiloConfigDir(), CONFIG_FILE);\n }\n\n // ── Memory surface: global rules dir at user scope ──────────────────────\n // Project scope stays on the AGENTS.md base default. User scope targets a\n // dedicated agent-connector.md in the legacy-compatible ~/.kilocode/rules/\n // dir (always loaded; avoids JSONC `instructions` edits in kilo.jsonc; the\n // AC-created file is cleanly deletable on uninstall). Shared backend with\n // kilo-cli — the convergent write dedupes via the content hash.\n protected override memoryTargets(ctx: InstallContext): MemoryTarget[] {\n if (this.memoryOverride(ctx)?.path || ctx.scope !== \"user\") {\n return super.memoryTargets(ctx);\n }\n return [\n {\n path: join(homedir(), \".kilocode\", \"rules\", \"agent-connector.md\"),\n reason: \"kilo global rules dir (~/.kilocode/rules; agent-connector-owned file)\",\n },\n ];\n }\n\n /**\n * MCP config dir. Note the project surface is `.kilo/` (kilo backend), NOT the\n * extension's `.kilocode/` content tree (which still hosts commands/subagents).\n */\n getConfigDir(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? join(ctx.projectDir, \".kilo\")\n : kiloConfigDir();\n }\n\n getServerConfigPath(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? join(ctx.projectDir, \".kilo\", CONFIG_FILE)\n : this.userConfigPath();\n }\n\n /**\n * For ts-plugin hosts the \"hook config path\" is the generated plugin FILE.\n * The backend also supports auto-discovery from the plugin dir, but we ALSO\n * register the path in kilo.json's `plugin` array for explicit load (idempotent).\n */\n getHookConfigPath(ctx: InstallContext): string {\n return join(this.pluginDir(ctx), this.pluginFileName(ctx));\n }\n\n /** Plugin directory the synthesized module is written into, per scope. */\n private pluginDir(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? join(ctx.projectDir, \".kilo\", \"plugin\")\n : join(kiloConfigDir(), \"plugin\");\n }\n\n /** Plugin module file name (one per connector, kebab-case id). */\n private pluginFileName(ctx: InstallContext): string {\n return `${ctx.connector.id}.js`;\n }\n\n // ── MCP server install / uninstall ───────────────────────────────────────\n\n installServer(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n const override = connector.platforms[HOST]?.server;\n if (!connector.server || override === false) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n detail: connector.server\n ? \"server registration disabled for kilo\"\n : \"connector declares no MCP server\",\n },\n ];\n }\n\n // Shallow-merge any per-platform server override into the base ServerDef.\n const server: ServerDef =\n override && typeof override === \"object\"\n ? { ...connector.server, ...override }\n : connector.server;\n\n const serverPath = this.getServerConfigPath(ctx);\n const entry = this.renderServerEntry(ctx, server);\n\n return [\n this.upsertServerInJson(serverPath, MCP_ROOT_KEY, connector.id, entry, ctx.dryRun),\n ];\n }\n\n uninstallServer(ctx: InstallContext): ChangeRecord[] {\n const serverPath = this.getServerConfigPath(ctx);\n return [\n this.removeServerFromJson(serverPath, MCP_ROOT_KEY, ctx.connector.id, ctx.dryRun),\n ];\n }\n\n /**\n * Render a normalized ServerDef into kilo.json's native `mcp` entry. Local\n * (stdio) servers fold the executable + args into a SINGLE `command` array and\n * carry env under `environment`; remote servers use a `type:\"remote\"` URL entry.\n */\n private renderServerEntry(\n ctx: InstallContext,\n server: ServerDef,\n ): KiloLocalServer | KiloRemoteServer {\n const transport: Transport = server.transport;\n\n if (transport === \"stdio\") {\n let command = server.command ?? \"\";\n let args = [...(server.args ?? [])];\n\n // Transparent telemetry wrapping: route the real command through\n // `<homeBin> serve --connector <id> -- <command> <args...>`.\n if (shouldWrapForTelemetry(server, ctx.connector.telemetry)) {\n const wrapped = buildServeWrapperCommand(\n ctx.homeBinPath,\n ctx.connector.id,\n command,\n args,\n ctx.scope,\n this.id,\n );\n command = wrapped.command;\n args = wrapped.args;\n }\n\n // Resolve ${env:VAR} to literals at install time (conservative; consistent\n // with kilo-cli even though {env:VARIABLE_NAME} is documented).\n const argv: string[] = [\n resolveEnvRefsDeep(command),\n ...resolveEnvRefsDeep(args),\n ];\n const entry: KiloLocalServer = {\n type: \"local\",\n command: argv,\n environment: this.renderEnv(server.env) ?? {},\n };\n return entry;\n }\n\n // sse / http (and any other remote transport) — kilo registers a remote URL.\n const entry: KiloRemoteServer = {\n type: \"remote\",\n url: resolveEnvRefsDeep(server.url ?? \"\"),\n };\n const headers = this.renderEnv(server.headers);\n if (headers) entry.headers = headers;\n return entry;\n }\n\n /**\n * Render env/header values. Resolve `${env:VAR}` references to literals at\n * install time for consistency with kilo-cli.\n */\n private renderEnv(\n env: Record<string, string> | undefined,\n ): Record<string, string> | undefined {\n if (!env || Object.keys(env).length === 0) return undefined;\n return resolveEnvRefsDeep({ ...env });\n }\n\n // ── Hook install / uninstall (ts-plugin + explicit `plugin` array) ────────\n\n installHooks(ctx: InstallContext): ChangeRecord[] {\n const pluginPath = this.getHookConfigPath(ctx);\n const configPath = this.getServerConfigPath(ctx);\n\n if (ctx.connector.platforms[HOST]?.hooks === false) {\n return [\n { platform: this.id, action: \"skip\", path: pluginPath, detail: \"hooks disabled for kilo\" },\n ];\n }\n if (ctx.connector.hookEvents.length === 0) {\n return [\n { platform: this.id, action: \"skip\", path: pluginPath, detail: \"connector declares no hooks\" },\n ];\n }\n\n const changes: ChangeRecord[] = [];\n\n // 1. Write the synthesized plugin module.\n for (const file of this.synthesizePlugin(ctx)) {\n const before = existsSync(file.path) ? this.safeRead(file.path) : undefined;\n let action: ChangeRecord[\"action\"];\n if (before === undefined) action = \"create\";\n else if (before === file.contents) action = \"skip\";\n else action = \"update\";\n\n if (action !== \"skip\" && !ctx.dryRun) {\n ensureDir(dirname(file.path));\n writeFileSync(file.path, file.contents, \"utf8\");\n chmodSync(file.path, file.executable ? 0o755 : 0o644);\n }\n changes.push({\n platform: this.id,\n action,\n path: file.path,\n detail: `kilo plugin module (${this.hookDetail(ctx)})`,\n });\n }\n\n // 2. Register the module path in kilo.json's `plugin` array. The backend also\n // auto-discovers from the plugin dir, but explicit registration is idempotent\n // and ensures loading even if auto-discovery is disabled.\n changes.push(this.upsertPluginInArray(configPath, pluginPath, ctx.dryRun));\n\n return changes;\n }\n\n /**\n * Human-facing summary of which declared events the synthesized module ACTUALLY\n * wires. Only events present in EVENT_TO_KILO are mapped/wired; any declared\n * event with no Kilo mapping is reported separately as \"unsupported here\".\n */\n private hookDetail(ctx: InstallContext): string {\n const declared = ctx.connector.hookEvents;\n const mapped = declared.filter((e) => EVENT_TO_KILO[e] !== undefined);\n const unsupported = declared.filter((e) => EVENT_TO_KILO[e] === undefined);\n const base = mapped.join(\",\");\n return unsupported.length > 0\n ? `${base}; unsupported here: ${unsupported.join(\",\")}`\n : base;\n }\n\n uninstallHooks(ctx: InstallContext): ChangeRecord[] {\n const pluginPath = this.getHookConfigPath(ctx);\n const configPath = this.getServerConfigPath(ctx);\n const changes: ChangeRecord[] = [];\n\n // 1. Deregister the module path from kilo.json's `plugin` array.\n changes.push(this.removePluginFromArray(configPath, pluginPath, ctx.dryRun));\n\n // 2. Remove the plugin module on disk.\n if (existsSync(pluginPath)) {\n if (!ctx.dryRun) rmSync(pluginPath, { force: true });\n changes.push({\n platform: this.id,\n action: \"remove\",\n path: pluginPath,\n detail: \"kilo plugin module\",\n });\n } else {\n changes.push({\n platform: this.id,\n action: \"skip\",\n path: pluginPath,\n detail: \"no kilo plugin module present\",\n });\n }\n\n // 3. Drop the now-empty plugin dir (only if WE own its full contents).\n changes.push(this.removeDirIfEmpty(this.pluginDir(ctx), ctx.dryRun));\n\n return changes;\n }\n\n /** Upsert the module path into kilo.json's top-level `plugin` array (idempotent). */\n private upsertPluginInArray(\n configPath: string,\n modulePath: string,\n dryRun: boolean,\n ): ChangeRecord {\n if (this.isPresentButUnparseable(configPath)) {\n return {\n platform: this.id,\n action: \"warn\",\n path: configPath,\n detail: `existing ${configPath} is not parseable; left untouched (back it up / fix it, then re-run)`,\n };\n }\n const cfg = this.readJson<Record<string, unknown>>(configPath) ?? {};\n const plugins = this.pluginArrayBucket(cfg);\n if (plugins.includes(modulePath)) {\n return {\n platform: this.id,\n action: \"skip\",\n path: configPath,\n detail: `${PLUGIN_ARRAY_KEY}[] already includes module`,\n };\n }\n plugins.push(modulePath);\n this.writeJson(configPath, cfg, dryRun);\n return {\n platform: this.id,\n action: \"create\",\n path: configPath,\n detail: `${PLUGIN_ARRAY_KEY}[] += module`,\n };\n }\n\n /** Remove the module path from kilo.json's `plugin` array. */\n private removePluginFromArray(\n configPath: string,\n modulePath: string,\n dryRun: boolean,\n ): ChangeRecord {\n if (this.isPresentButUnparseable(configPath)) {\n return {\n platform: this.id,\n action: \"warn\",\n path: configPath,\n detail: `existing ${configPath} is not parseable; left untouched (back it up / fix it, then re-run)`,\n };\n }\n const cfg = this.readJson<Record<string, unknown>>(configPath);\n const raw = cfg?.[PLUGIN_ARRAY_KEY];\n const plugins = Array.isArray(raw) ? (raw as unknown[]) : undefined;\n const idx = plugins ? plugins.indexOf(modulePath) : -1;\n if (!cfg || !plugins || idx < 0) {\n return {\n platform: this.id,\n action: \"skip\",\n path: configPath,\n detail: `${PLUGIN_ARRAY_KEY}[] does not include module`,\n };\n }\n plugins.splice(idx, 1);\n this.writeJson(configPath, cfg, dryRun);\n return {\n platform: this.id,\n action: \"remove\",\n path: configPath,\n detail: `${PLUGIN_ARRAY_KEY}[] -= module`,\n };\n }\n\n /** Get-or-create the top-level `plugin` array as a mutable string array. */\n private pluginArrayBucket(cfg: Record<string, unknown>): string[] {\n const existing = cfg[PLUGIN_ARRAY_KEY];\n const plugins = Array.isArray(existing)\n ? existing.filter((p): p is string => typeof p === \"string\")\n : [];\n cfg[PLUGIN_ARRAY_KEY] = plugins;\n return plugins;\n }\n\n // ── ts-plugin synthesis ────────────────────────────────────────────────\n\n /**\n * Build ONE self-contained ESM plugin module for Kilo Code (the VS Code\n * extension). Structurally identical to the kilo-cli plugin but bridges to\n * \"kilo\" (not \"kilo-cli\") so the dispatcher routes to the correct adapter.\n */\n synthesizePlugin(ctx: InstallContext): GeneratedPluginFile[] {\n const path = this.getHookConfigPath(ctx);\n const contents = this.buildPluginSource(ctx);\n return [{ path, contents, executable: false }];\n }\n\n /** Compose the generated plugin source with plain string concatenation. */\n private buildPluginSource(ctx: InstallContext): string {\n const homeBin = JSON.stringify(ctx.homeBinPath);\n const connectorId = JSON.stringify(ctx.connector.id);\n\n const events = ctx.connector.hookEvents.filter(\n (e): e is HookEventName => EVENT_TO_KILO[e] !== undefined,\n );\n const has = (e: HookEventName) => events.includes(e);\n\n const header = `/**\n * AUTO-GENERATED by agent-connector — DO NOT EDIT.\n *\n * Self-contained Kilo Code (VS Code extension) plugin bridge for connector ${ctx.connector.id}.\n * It imports nothing from agent-connector: every hook invocation shells out to\n * the stable home binary's universal entrypoint and JSON-parses the normalized\n * response. Fail-open: any bridge error degrades to \"allow\".\n *\n * Default export is the @kilocode/plugin PluginModule shape\n * ({ id, server: async (input) => Hooks }); the extension loads it via the\n * plugin dir auto-discovery and/or the \"plugin\" array in kilo.json.\n */\nimport { execFileSync, execSync } from \"node:child_process\";\n\nconst HOME_BIN = ${homeBin};\nconst CONNECTOR_ID = ${connectorId};\n\n/**\n * Invoke the universal hook entrypoint for one event.\n * @param {string} event canonical event name (PreToolUse|PostToolUse|SessionStart)\n * @param {object} payload Kilo-shaped payload posted on stdin\n * @returns {object|null} normalized HookResponse, or null on any failure\n */\nfunction bridge(event, payload) {\n try {\n // On Windows HOME_BIN is the agent-connector.cmd launcher: Node cannot\n // execFile a batch file, and shell+args is deprecated (DEP0190), so run one\n // quoted command line via a shell. POSIX keeps the direct execFile (no shell).\n const args = [\"hook\", \"kilo\", event, \"--connector\", CONNECTOR_ID];\n const opts = { input: JSON.stringify(payload), encoding: \"utf8\" };\n const stdout =\n process.platform === \"win32\"\n ? execSync([HOME_BIN, ...args].map((a) => '\"' + a + '\"').join(\" \"), opts)\n : execFileSync(HOME_BIN, args, opts);\n const text = (stdout || \"\").trim();\n if (text === \"\") return { decision: \"allow\" };\n return JSON.parse(text);\n } catch {\n // Fail-open — never wedge a tool call on a bridge error.\n return null;\n }\n}\n`;\n\n const handlers: string[] = [];\n\n if (has(\"PreToolUse\")) {\n handlers.push(` // PreToolUse → block (throw) / rewrite args (mutate output.args).\n \"tool.execute.before\": async (input, output) => {\n const payload = {\n toolName: input.tool ?? \"\",\n toolInput: (output && output.args) ?? {},\n sessionId: input.sessionID ?? \"\",\n projectDir: PROJECT_DIR,\n };\n const res = bridge(\"PreToolUse\", payload);\n if (!res) return;\n // Kilo has no \"ask\" gate — degrade \"ask\" to a block (safe direction).\n if (res.decision === \"deny\" || res.decision === \"ask\") {\n throw new Error(res.reason || \"Blocked by ${ctx.connector.id}\");\n }\n if (res.updatedInput && output && output.args) {\n Object.assign(output.args, res.updatedInput);\n }\n },`);\n }\n\n if (has(\"PostToolUse\")) {\n handlers.push(` // PostToolUse → observe / rewrite tool output (mutate output.output).\n \"tool.execute.after\": async (input, output) => {\n const payload = {\n toolName: input.tool ?? \"\",\n toolInput: input.args ?? {},\n toolOutput: output ? output.output : undefined,\n sessionId: input.sessionID ?? \"\",\n projectDir: PROJECT_DIR,\n };\n const res = bridge(\"PostToolUse\", payload);\n if (!res) return;\n if (typeof res.updatedOutput === \"string\" && output) {\n output.output = res.updatedOutput;\n }\n },`);\n }\n\n if (has(\"SessionStart\")) {\n handlers.push(` // SessionStart surrogate → inject context into the system prompt.\n // The extension has no real SessionStart hook; the system-prompt transform is\n // the verified injection point (mirrors OpenCode and kilo-cli).\n \"experimental.chat.system.transform\": async (input, output) => {\n const payload = {\n sessionId: (input && input.sessionID) ?? \"\",\n projectDir: PROJECT_DIR,\n };\n const res = bridge(\"SessionStart\", payload);\n if (!res) return;\n if (res.additionalContext && output && Array.isArray(output.system)) {\n // Insert at index 1 (after the header) to preserve the prompt-cache fold\n // (header must remain system[0]).\n output.system.splice(1, 0, res.additionalContext);\n }\n },`);\n }\n\n const definition = `\nconst plugin = {\n id: CONNECTOR_ID,\n // @kilocode/plugin PluginModule: server(input) returns the Hooks object keyed\n // by the fork's event names. ctx.directory is the project root; fall back to cwd.\n server: async (input) => {\n const PROJECT_DIR =\n (input && (input.directory || (input.worktree && input.worktree.path))) ||\n process.cwd();\n\n return {\n${handlers.join(\"\\n\")}\n };\n },\n};\n\nexport default plugin;\n`;\n\n return header + definition;\n }\n\n // ── Runtime: parse OUR bridge payload → normalized event ───────────────\n\n /**\n * `raw` is the payload OUR generated plugin posts (NOT a host-native shape):\n * { toolName, toolInput, toolOutput?, isError?, sessionId, projectDir }\n * so this maps straight through.\n */\n parseEvent(event: HookEventName, raw: unknown): NormalizedEvent {\n const input = (raw ?? {}) as KiloBridgePayload;\n const base = {\n hostPlatform: HOST,\n connectorId: \"\",\n sessionId: typeof input.sessionId === \"string\" ? input.sessionId : \"\",\n raw,\n ...(typeof input.projectDir === \"string\" ? { projectDir: input.projectDir } : {}),\n } as const;\n\n switch (event) {\n case \"PreToolUse\": {\n const ev: PreToolUseEvent = {\n ...base,\n toolName: input.toolName ?? \"\",\n toolInput: input.toolInput ?? {},\n };\n return ev;\n }\n case \"PostToolUse\": {\n const ev: PostToolUseEvent = {\n ...base,\n toolName: input.toolName ?? \"\",\n toolInput: input.toolInput ?? {},\n ...(typeof input.toolOutput === \"string\" ? { toolOutput: input.toolOutput } : {}),\n ...(typeof input.isError === \"boolean\" ? { isError: input.isError } : {}),\n };\n return ev;\n }\n case \"SessionStart\": {\n const ev: SessionStartEvent = { ...base, source: \"startup\" };\n return ev;\n }\n default:\n return { ...base, source: \"startup\" } satisfies SessionStartEvent;\n }\n }\n\n // ── Runtime: normalized response → reply the generated bridge parses ───\n\n /**\n * OUR generated bridge consumes this stdout directly. The reply body IS the\n * normalized HookResponse itself — the bridge JSON.parses it and reads\n * decision / updatedInput / updatedOutput / additionalContext.\n */\n formatReply(_event: HookEventName, response: HookResponse): HookReply {\n return {\n exitCode: 0,\n stdout: JSON.stringify(response ?? { decision: \"allow\" }),\n };\n }\n\n // ── Content surfaces: commands / skills / subagents ───────────────────\n // CONTENT-ONLY: pure native-file writers. No runtime dispatch, no home-bin\n // pointer, no telemetry wrap. Each method is idempotent (byte-identical →\n // skip) via BaseAdapter.writeContentFile and reversible via removeContentFile.\n // Honors platforms[\"kilo\"] per-surface false to skip.\n //\n // NOTE on dirs: the .kilocode/ tree is the EXTENSION's legacy content surface\n // — kept SEPARATE from the MCP/hooks backend dir (~/.config/kilo). Commands\n // live under .kilocode/commands (project) / ~/.kilocode/commands (user);\n // subagents live under .kilocode/agents (project) / ~/.kilocode/agents (user).\n // Skills use the newer .kilo/skills tree (project) / ~/.kilo/skills (user).\n\n /** The extension's user-scope legacy content home (~/.kilocode). */\n private userContentDir(): string {\n return join(homedir(), \".kilocode\");\n }\n\n /** Skills root: project → <projectDir>/.kilo/skills; user → ~/.kilo/skills. */\n private skillsRootDir(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? join(ctx.projectDir, \".kilo\", \"skills\")\n : join(homedir(), \".kilo\", \"skills\");\n }\n\n /** Commands root: project → <projectDir>/.kilocode/commands; user → ~/.kilocode/commands. */\n private commandsDir(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? join(ctx.projectDir, \".kilocode\", \"commands\")\n : join(this.userContentDir(), \"commands\");\n }\n\n /** Subagents root: project → <projectDir>/.kilocode/agents; user → ~/.kilocode/agents. */\n private agentsDir(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? join(ctx.projectDir, \".kilocode\", \"agents\")\n : join(this.userContentDir(), \"agents\");\n }\n\n /** Native command file path: <commandsDir>/<name>.md. */\n private commandPath(ctx: InstallContext, name: string): string {\n return join(this.commandsDir(ctx), `${name}.md`);\n }\n\n /** Native skill dir: <skillsRootDir>/<name>. */\n private skillDir(ctx: InstallContext, name: string): string {\n return join(this.skillsRootDir(ctx), name);\n }\n\n /** Native subagent file path: <agentsDir>/<name>.md. */\n private subagentPath(ctx: InstallContext, name: string): string {\n return join(this.agentsDir(ctx), `${name}.md`);\n }\n\n // ── Commands ──────────────────────────────────────────────────────────────\n\n override installCommands(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.platforms[HOST]?.commands === false) {\n return [{ platform: this.id, action: \"skip\", detail: \"commands disabled for kilo\" }];\n }\n if (connector.commands.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no commands\" }];\n }\n return connector.commands.map((cmd) =>\n this.writeContentFile(\n this.commandPath(ctx, cmd.name),\n this.renderCommand(cmd),\n ctx.dryRun,\n ),\n );\n }\n\n override uninstallCommands(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.commands.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no commands\" }];\n }\n return connector.commands.map((cmd) =>\n this.removeContentFile(this.commandPath(ctx, cmd.name), ctx.dryRun),\n );\n }\n\n /** Render a command to md+frontmatter (description, argument-hint, mode, model). */\n private renderCommand(cmd: CommandDef): string {\n const frontmatter: Record<string, unknown> = {};\n if (cmd.description !== undefined) frontmatter.description = cmd.description;\n if (cmd.argumentHint !== undefined) frontmatter[\"argument-hint\"] = cmd.argumentHint;\n if (cmd.model !== undefined) frontmatter.model = cmd.model;\n if (cmd.extra) Object.assign(frontmatter, cmd.extra);\n return this.renderFrontmatterMd(frontmatter, cmd.prompt);\n }\n\n // ── Skills ────────────────────────────────────────────────────────────────\n\n override installSkills(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.platforms[HOST]?.skills === false) {\n return [{ platform: this.id, action: \"skip\", detail: \"skills disabled for kilo\" }];\n }\n if (connector.skills.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no skills\" }];\n }\n const changes: ChangeRecord[] = [];\n for (const skill of connector.skills) {\n const dir = this.skillDir(ctx, skill.name);\n changes.push(\n this.writeContentFile(join(dir, \"SKILL.md\"), this.renderSkill(skill), ctx.dryRun),\n );\n // Bundle any resource files beside SKILL.md (relative path → contents).\n for (const [rel, contents] of Object.entries(skill.resources ?? {})) {\n const target = this.resolveWithin(dir, rel);\n if (target === null) {\n changes.push({\n platform: this.id,\n action: \"warn\",\n detail: `skill resource \"${rel}\" escapes the skill dir; skipped`,\n });\n continue;\n }\n changes.push(this.writeContentFile(target, contents, ctx.dryRun));\n }\n }\n return changes;\n }\n\n override uninstallSkills(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.skills.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no skills\" }];\n }\n const changes: ChangeRecord[] = [];\n for (const skill of connector.skills) {\n const dir = this.skillDir(ctx, skill.name);\n changes.push(this.removeContentFile(join(dir, \"SKILL.md\"), ctx.dryRun));\n for (const rel of Object.keys(skill.resources ?? {})) {\n const target = this.resolveWithin(dir, rel);\n if (target === null) continue;\n changes.push(this.removeContentFile(target, ctx.dryRun));\n }\n changes.push(this.removeDirIfEmpty(dir, ctx.dryRun));\n }\n return changes;\n }\n\n /**\n * Render a skill's SKILL.md: frontmatter (name, description + optional model,\n * allowed-tools, disable-model-invocation) + markdown body.\n */\n private renderSkill(skill: SkillDef): string {\n const frontmatter: Record<string, unknown> = {\n name: skill.name,\n description: skill.description,\n };\n if (skill.model !== undefined) frontmatter.model = skill.model;\n const allow = skill.tools?.allow;\n if (allow && allow.length > 0) frontmatter[\"allowed-tools\"] = allow.join(\", \");\n if (skill.disableModelInvocation !== undefined) {\n frontmatter[\"disable-model-invocation\"] = skill.disableModelInvocation;\n }\n if (skill.extra) Object.assign(frontmatter, skill.extra);\n return this.renderFrontmatterMd(frontmatter, skill.body);\n }\n\n // ── Subagents ───────────────────────────────────────────────────────────────\n\n override installSubagents(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.platforms[HOST]?.subagents === false) {\n return [{ platform: this.id, action: \"skip\", detail: \"subagents disabled for kilo\" }];\n }\n if (connector.subagents.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no subagents\" }];\n }\n return connector.subagents.map((agent) =>\n this.writeContentFile(\n this.subagentPath(ctx, agent.name),\n this.renderSubagent(agent),\n ctx.dryRun,\n ),\n );\n }\n\n override uninstallSubagents(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.subagents.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no subagents\" }];\n }\n return connector.subagents.map((agent) =>\n this.removeContentFile(this.subagentPath(ctx, agent.name), ctx.dryRun),\n );\n }\n\n /**\n * Render a subagent to md+frontmatter. Kilo Code's shape is\n * (description, mode:\"subagent\", model, permission) with the system prompt as\n * the body. `name` is NOT a frontmatter field — it comes from the filename.\n * `permission` is derived from the coarse `readonly` knob: a readonly agent\n * gets a per-tool deny map (edit/bash) so it cannot mutate the workspace.\n */\n private renderSubagent(agent: SubagentDef): string {\n const frontmatter: Record<string, unknown> = {\n description: agent.description,\n mode: \"subagent\",\n };\n if (agent.model !== undefined) frontmatter.model = agent.model;\n if (agent.readonly === true) {\n frontmatter.permission = { edit: \"deny\", bash: \"deny\" };\n }\n if (agent.extra) Object.assign(frontmatter, agent.extra);\n return this.renderFrontmatterMd(frontmatter, agent.prompt);\n }\n\n // ── Diagnostics ──────────────────────────────────────────────────────────\n\n override getHealthChecks(ctx: InstallContext): readonly HealthCheck[] {\n const mcpPath = this.getServerConfigPath(ctx);\n const pluginPath = this.getHookConfigPath(ctx);\n const connectorId = ctx.connector.id;\n const hasHooks = ctx.connector.hookEvents.length > 0;\n\n const checks: HealthCheck[] = [\n {\n name: `${this.name}: kilo.json present`,\n check: () =>\n existsSync(mcpPath)\n ? { status: \"OK\", detail: mcpPath }\n : { status: \"FAIL\", detail: `not found: ${mcpPath}` },\n },\n {\n // The backend merges kilo.json AND kilo.jsonc at user/project/.kilo/ levels.\n name: `${this.name}: MCP delegated to kilo backend`,\n check: () => ({\n status: \"OK\",\n detail:\n ctx.scope === \"user\"\n ? `using ${CONFIG_FILE} under ${kiloConfigDir()} (merged with kilo.jsonc by shared backend)`\n : `project scope uses .kilo/${CONFIG_FILE} (merged with kilo.jsonc by shared backend)`,\n }),\n },\n {\n name: `${this.name}: server entry registered`,\n check: () => {\n if (!ctx.connector.server) {\n return { status: \"OK\", detail: \"no MCP server declared\" };\n }\n const cfg = this.readJson<{ [k: string]: Record<string, unknown> }>(mcpPath);\n const bucket = cfg?.[MCP_ROOT_KEY];\n if (!cfg || !bucket) {\n return { status: \"FAIL\", detail: `no ${MCP_ROOT_KEY} in ${mcpPath}` };\n }\n return connectorId in bucket\n ? { status: \"OK\", detail: `${MCP_ROOT_KEY}.${connectorId} present` }\n : {\n status: \"FAIL\",\n detail: `no ${MCP_ROOT_KEY}.${connectorId} in ${mcpPath}`,\n };\n },\n },\n {\n name: `${this.name}: plugin module present`,\n check: () => {\n if (!hasHooks) return { status: \"OK\", detail: \"no hooks declared\" };\n return existsSync(pluginPath)\n ? { status: \"OK\", detail: pluginPath }\n : { status: \"FAIL\", detail: `not found: ${pluginPath}` };\n },\n },\n {\n name: `${this.name}: plugin registered in ${PLUGIN_ARRAY_KEY}[]`,\n check: () => {\n if (!hasHooks) return { status: \"OK\", detail: \"no hooks declared\" };\n const cfg = this.readJson<Record<string, unknown>>(mcpPath);\n const raw = cfg?.[PLUGIN_ARRAY_KEY];\n const plugins = Array.isArray(raw) ? (raw as unknown[]) : undefined;\n return plugins && plugins.includes(pluginPath)\n ? { status: \"OK\", detail: `${PLUGIN_ARRAY_KEY}[] includes module` }\n : {\n status: \"FAIL\",\n detail: `module not in ${PLUGIN_ARRAY_KEY}[] of ${mcpPath}`,\n };\n },\n },\n ];\n\n // Content-surface checks.\n for (const cmd of ctx.connector.commands) {\n const p = this.commandPath(ctx, cmd.name);\n checks.push({\n name: `${this.name}: command ${cmd.name} present`,\n check: () =>\n existsSync(p) ? { status: \"OK\", detail: p } : { status: \"FAIL\", detail: `not found: ${p}` },\n });\n }\n for (const skill of ctx.connector.skills) {\n const p = join(this.skillDir(ctx, skill.name), \"SKILL.md\");\n checks.push({\n name: `${this.name}: skill ${skill.name} present`,\n check: () =>\n existsSync(p) ? { status: \"OK\", detail: p } : { status: \"FAIL\", detail: `not found: ${p}` },\n });\n }\n for (const agent of ctx.connector.subagents) {\n const p = this.subagentPath(ctx, agent.name);\n checks.push({\n name: `${this.name}: subagent ${agent.name} present`,\n check: () =>\n existsSync(p) ? { status: \"OK\", detail: p } : { status: \"FAIL\", detail: `not found: ${p}` },\n });\n }\n return checks;\n }\n\n /** Read a file, returning undefined on any error (idempotency compare). */\n private safeRead(path: string): string | undefined {\n try {\n return readFileSync(path, \"utf8\");\n } catch {\n return undefined;\n }\n }\n}\n\n/** Create a directory (recursive) if it does not already exist. */\nfunction ensureDir(dir: string): void {\n if (!existsSync(dir)) mkd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AClC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAGA,SAAS,UAAU,KAAmB;AACpC,MAAI,CAAC,WAAW,GAAG,EAAG,WAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAC1D;AAEO,IAAM,UAAU,IAAI,YAAY;AACvC,IAAO,eAAQ;","names":["entry"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapters/kimi/index.ts"],"sourcesContent":["/**\n * adapters/kimi — Kimi CLI (Moonshot) platform adapter for agent-connector.\n *\n * Kimi CLI is a json-stdio host: the runner pipes a JSON payload to a command on\n * stdin and reads an exit code (and optional reason) back. Two native config\n * files live under the Kimi base dir (`$KIMI_HOME` || `$KIMI_CODE_HOME` || `~/.kimi`):\n * - mcp.json → `mcpServers.<id>` MCP registration (JSON, stdio shape:\n * {command,args,env}). Handled via BaseAdapter's JSON helpers.\n * - config.toml → `[[hooks]]` array-of-tables (TOML), each table\n * { event, matcher, command }. Parsed/serialized with @iarna/toml: every\n * config VALUE (unrelated sections, sibling hooks, scalars) is preserved,\n * but a parse→stringify round-trip does NOT preserve user COMMENTS or the\n * original key ordering/formatting in config.toml (values survive; comments\n * and layout do not).\n *\n * Hook surface is intentionally narrow: Kimi CLI only honors a PreToolUse DENY.\n * It cannot rewrite tool args, rewrite tool output, or inject session context —\n * so every other decision degrades to a silent allow (exit 0). Kimi Code uses\n * the Claude/Codex reply shape: a PreToolUse deny is signalled with EXIT 0 plus\n * a `hookSpecificOutput` JSON object on stdout carrying\n * permissionDecision:\"deny\" + permissionDecisionReason — that is how Kimi's\n * runner blocks the pending tool call. An allow is exit 0 with empty stdout.\n *\n * E1 extension events (verified against moonshotai.github.io/kimi-cli hooks):\n * - PostToolUseFailure — native (tool_name, tool_input, error; tool-name\n * matcher). Feedback-only: Kimi's exit-0 protocol adds non-empty stdout to\n * context, so \"context\" (and a degraded \"deny\") emit plain-text stdout.\n * - SubagentStart / SubagentStop — native, but with Kimi-specific wire\n * fields: agent_name (→ normalized agentType; there is no agent_id) plus\n * prompt (start) / response (stop → lastAssistantMessage). SubagentStop\n * deny uses Kimi's generic block protocol: EXIT 2 with the reason on\n * stderr (fed back to the model as correction).\n * - PermissionRequest — NO Kimi analog (the permission prompt is only\n * observable as a Notification); declared hooks for it warn-skip at\n * install and the capability flag stays unset.\n *\n * Path confidence: the `~/.kimi` base + mcp.json (`mcpServers`) layout is\n * LIVE-CONFIRMED against the real Moonshot Kimi CLI (v1.46.0, `pip install\n * kimi-cli`) via a `kimi mcp` probe. We still install + doctor-report presence\n * so a future path move surfaces as a FAIL rather than silently misbehaving.\n *\n * FUTURE COVERAGE (non-functional note — no behavior change here): beyond the\n * wired PreToolUse + PostToolUseFailure + SubagentStart/SubagentStop, Kimi CLI\n * supports a wider event surface — Stop, StopFailure, UserPromptSubmit,\n * PostToolUse, SessionStart, SessionEnd, PreCompact, PostCompact and\n * Notification. Kimi also has a PLUGIN system (plugins live at\n * `<base>/plugins/<name>/kimi.plugin.json`) and a SKILLS surface\n * (`~/.kimi/skills/`). None of these are covered yet; they are flagged here\n * as candidates for a future events/plugins/skills expansion of the adapter.\n */\n\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nimport TOML from \"@iarna/toml\";\n\nimport { BaseAdapter } from \"../base.js\";\nimport type { Adapter, HookReply, InstallContext, NormalizedEvent } from \"../spi.js\";\nimport type {\n ChangeRecord,\n DetectedPlatform,\n HealthCheck,\n HookEventName,\n HookParadigm,\n HookResponse,\n NotificationEvent,\n PermissionRequestEvent,\n PlatformCapabilities,\n PlatformId,\n PostToolUseEvent,\n PostToolUseFailureEvent,\n PreCompactEvent,\n PreToolUseEvent,\n SessionEndEvent,\n SessionStartEvent,\n ServerDef,\n SkillDef,\n StopEvent,\n SubagentStartEvent,\n SubagentStopEvent,\n Transport,\n UserPromptSubmitEvent,\n} from \"../../core/types.js\";\nimport { renderSkillMd } from \"../claude-code/render.js\";\nimport { ensureDir } from \"../../core/paths.js\";\nimport { resolveEnvRefsDeep } from \"../../core/interpolate.js\";\nimport {\n buildHomeBinHookCommand,\n buildServeWrapperCommand,\n isHomeBinHookCommand,\n shouldWrapForTelemetry,\n} from \"../../core/spawn.js\";\n\nconst HOST: PlatformId = \"kimi\";\nconst MCP_ROOT_KEY = \"mcpServers\";\n\n// ─────────────────────────────────────────────────────────────────────────\n// Native shapes\n// ─────────────────────────────────────────────────────────────────────────\n\n/** Raw Kimi CLI hook payload (Claude-style: PascalCase event, snake_case fields). */\ninterface KimiHookInput {\n tool_name?: string;\n tool_input?: Record<string, unknown>;\n tool_response?: unknown;\n session_id?: string;\n cwd?: string;\n hook_event_name?: string;\n source?: string;\n prompt?: string;\n is_error?: boolean;\n stop_hook_active?: boolean;\n trigger?: string;\n message?: string;\n reason?: string;\n // PostToolUseFailure — the failure message.\n error?: string;\n // SubagentStart / SubagentStop — Kimi sends agent_name (NOT agent_id /\n // agent_type) plus prompt (start) / response (stop).\n agent_name?: string;\n response?: string;\n connector?: string;\n}\n\n/** One `[[hooks]]` array-of-tables entry as Kimi stores it in config.toml. */\ninterface KimiTomlHook {\n event: string;\n matcher?: string;\n command: string;\n [key: string]: unknown;\n}\n\n/** Parsed config.toml shape we care about (rest preserved verbatim). */\ninterface KimiConfigToml {\n hooks?: KimiTomlHook[];\n [key: string]: unknown;\n}\n\n/** Native stdio MCP server entry under `mcpServers`. */\ninterface KimiStdioServer {\n command: string;\n args?: string[];\n env?: Record<string, string>;\n}\n\n/** Native remote MCP server entry under `mcpServers`. */\ninterface KimiHttpServer {\n url: string;\n headers?: Record<string, string>;\n}\n\n/**\n * Kimi CLI hook events agent-connector registers: the PreToolUse deny gate plus\n * the E1 extension events Kimi fires natively (PostToolUseFailure +\n * SubagentStart/SubagentStop). The matcher below is charset-clean (Rust-regex\n * safe: no look-around) so Kimi's matcher accepts it. Copied in spirit from the\n * Codex/context-mode matchers.\n */\nconst KIMI_HOOK_EVENTS = [\n \"PreToolUse\",\n \"PostToolUseFailure\",\n \"SubagentStart\",\n \"SubagentStop\",\n] as const;\ntype KimiHookEventName = (typeof KIMI_HOOK_EVENTS)[number];\n\n/**\n * Newer canonical events with NO Kimi analog: there is no permission-dialog\n * hook (the prompt is only observable via Notification). Declared hooks for\n * these warn-skip at install so the degradation is reported, never silent.\n * (The legacy silent drop of host-supported-but-unwired events — SessionStart,\n * Stop, … — predates this convention and is deliberately left untouched; see\n * the FUTURE COVERAGE header note.)\n */\nconst WARN_SKIP_EVENTS: ReadonlySet<HookEventName> = new Set([\"PermissionRequest\"]);\n\nconst PRE_TOOL_USE_MATCHER =\n \"Bash|Shell|shell|exec_command|Read|Edit|Write|WebFetch|Agent|mcp__\";\n\n// ─────────────────────────────────────────────────────────────────────────\n// Adapter\n// ─────────────────────────────────────────────────────────────────────────\n\nexport class KimiAdapter extends BaseAdapter implements Adapter {\n readonly id: PlatformId = HOST;\n readonly name = \"Kimi CLI\";\n readonly paradigm: HookParadigm = \"json-stdio\";\n\n readonly capabilities: PlatformCapabilities = {\n // Memory surface: AGENTS.md-first managed block via the BaseAdapter default\n // (memoryTargets: project <projectDir>/AGENTS.md; user scope where documented).\n supportsMemory: true,\n // PreToolUse deny is the only honored hook decision on Kimi CLI.\n preToolUse: true,\n postToolUse: false,\n preCompact: false,\n sessionStart: false,\n sessionEnd: false,\n userPromptSubmit: false,\n stop: false,\n notification: false,\n // E1 events Kimi fires natively. permissionRequest stays unset — Kimi has\n // no permission-dialog hook, so a declared hook for it warn-skips at install.\n postToolUseFailure: true,\n subagentStart: true,\n subagentStop: true,\n // Kimi cannot rewrite args/output nor inject session context — deny-only.\n canModifyArgs: false,\n canModifyOutput: false,\n canInjectSessionContext: false,\n transports: [\"stdio\", \"http\"],\n // Skills surface: Kimi reads SKILL.md from ~/.kimi/skills/<name>/SKILL.md\n // (user scope) and .kimi/skills/<name>/SKILL.md (project scope).\n // Confirmed: kilo-pi-ground-truth.md § \"Already-known skills gaps\".\n supportsSkills: true,\n };\n\n // ── Detection ────────────────────────────────────────────────────────────\n\n detectInstalled(_projectDir: string): DetectedPlatform {\n const baseDir = this.baseDir();\n const mcpPath = join(baseDir, \"mcp.json\");\n const configPath = join(baseDir, \"config.toml\");\n const installed = existsSync(baseDir) || existsSync(mcpPath) || existsSync(configPath);\n return {\n id: this.id,\n name: this.name,\n installed,\n paradigm: this.paradigm,\n capabilities: this.capabilities,\n configPath: mcpPath,\n scope: \"user\",\n reason: installed\n ? `found Kimi CLI config under ${baseDir}`\n : `no Kimi CLI config at ${baseDir}`,\n // Path confidence is medium even when present: the ~/.kimi-code layout is the\n // documented shape but less battle-tested than Claude/Codex.\n confidence: \"medium\",\n };\n }\n\n // ── Native paths ───────────────────────────────────────────────────────\n\n getConfigDir(_ctx: InstallContext): string {\n return this.baseDir();\n }\n\n /** MCP registration file (JSON). */\n getServerConfigPath(ctx: InstallContext): string {\n return join(this.getConfigDir(ctx), \"mcp.json\");\n }\n\n /** Hook registration file (TOML) — distinct from the MCP file. */\n getHookConfigPath(ctx: InstallContext): string {\n return join(this.getConfigDir(ctx), \"config.toml\");\n }\n\n /**\n * `$KIMI_HOME` || `$KIMI_CODE_HOME` (with `~` expansion) || `~/.kimi`.\n * The real Moonshot Kimi CLI (v1.46.0) keeps its config under `~/.kimi`\n * (mcp.json · mcpServers) — verified by a live `kimi mcp` probe; the legacy\n * `~/.kimi-code` guess was wrong. `$KIMI_CODE_HOME` is still honored as an\n * override for back-compat alongside the newer `$KIMI_HOME`.\n */\n private baseDir(): string {\n const env = process.env.KIMI_HOME ?? process.env.KIMI_CODE_HOME;\n if (env && env.trim() !== \"\") {\n if (env.startsWith(\"~\")) {\n return join(homedir(), env.replace(/^~[/\\\\]?/, \"\"));\n }\n return env;\n }\n return join(homedir(), \".kimi\");\n }\n\n // ── MCP server install / uninstall (mcp.json → mcpServers.<id>) ──────────\n\n installServer(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n const override = connector.platforms[HOST]?.server;\n if (!connector.server || override === false) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n detail: connector.server\n ? \"server registration disabled for kimi\"\n : \"connector declares no MCP server\",\n },\n ];\n }\n\n const server: ServerDef =\n override && typeof override === \"object\"\n ? { ...connector.server, ...override }\n : connector.server;\n\n const serverPath = this.getServerConfigPath(ctx);\n const entry = this.renderServerEntry(ctx, server);\n\n return [\n this.upsertServerInJson(serverPath, MCP_ROOT_KEY, connector.id, entry, ctx.dryRun),\n ];\n }\n\n uninstallServer(ctx: InstallContext): ChangeRecord[] {\n const serverPath = this.getServerConfigPath(ctx);\n return [\n this.removeServerFromJson(serverPath, MCP_ROOT_KEY, ctx.connector.id, ctx.dryRun),\n ];\n }\n\n /**\n * Render a normalized ServerDef into Kimi's native mcpServers entry. Kimi's\n * mcp.json has no documented native interpolation, so `${env:VAR}` refs are\n * resolved to literals at install time (same posture as the TOML hosts).\n */\n private renderServerEntry(\n ctx: InstallContext,\n server: ServerDef,\n ): KimiStdioServer | KimiHttpServer {\n const transport: Transport = server.transport;\n\n if (transport === \"stdio\") {\n let command = server.command ?? \"\";\n let args = [...(server.args ?? [])];\n\n // Transparent telemetry wrapping: route through\n // `<homeBin> serve --connector <id> -- <command> <args...>`.\n if (shouldWrapForTelemetry(server, ctx.connector.telemetry)) {\n const wrapped = buildServeWrapperCommand(\n ctx.homeBinPath,\n ctx.connector.id,\n command,\n args,\n ctx.scope,\n this.id,\n );\n command = wrapped.command;\n args = wrapped.args;\n }\n\n command = resolveEnvRefsDeep(command);\n args = resolveEnvRefsDeep(args);\n\n const entry: KimiStdioServer = { command };\n if (args.length > 0) entry.args = args;\n const env = this.renderEnv(server.env);\n if (env) entry.env = env;\n return entry;\n }\n\n // http (and any other remote transport) — Kimi registers a URL entry.\n const entry: KimiHttpServer = { url: resolveEnvRefsDeep(server.url ?? \"\") };\n const headers = this.renderEnv(server.headers);\n if (headers) entry.headers = headers;\n return entry;\n }\n\n /** Resolve env/header values to literals (no native interpolation on Kimi). */\n private renderEnv(\n env: Record<string, string> | undefined,\n ): Record<string, string> | undefined {\n if (!env || Object.keys(env).length === 0) return undefined;\n const out: Record<string, string> = {};\n for (const [k, v] of Object.entries(resolveEnvRefsDeep(env))) {\n out[k] = String(v);\n }\n return out;\n }\n\n // ── Skills surface ────────────────────────────────────────────────────────\n // Kimi reads SKILL.md from <baseDir>/skills/<name>/SKILL.md.\n // user scope: ~/.kimi/skills/<name>/SKILL.md\n // project scope: <projectDir>/.kimi/skills/<name>/SKILL.md\n // Confirmed: kilo-pi-ground-truth.md § \"Already-known skills gaps\".\n\n private skillsDir(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? join(ctx.projectDir, \".kimi\", \"skills\")\n : join(this.baseDir(), \"skills\");\n }\n\n private skillDir(ctx: InstallContext, name: string): string {\n return join(this.skillsDir(ctx), name);\n }\n\n override installSkills(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.platforms[HOST]?.skills === false) {\n return [{ platform: this.id, action: \"skip\", detail: \"skills disabled for kimi\" }];\n }\n if (connector.skills.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no skills\" }];\n }\n const changes: ChangeRecord[] = [];\n for (const skill of connector.skills) {\n const dir = this.skillDir(ctx, skill.name);\n changes.push(\n this.writeContentFile(join(dir, \"SKILL.md\"), this.renderSkill(skill), ctx.dryRun),\n );\n for (const [rel, contents] of Object.entries(skill.resources ?? {})) {\n const target = this.resolveWithin(dir, rel);\n if (target === null) {\n changes.push({\n platform: this.id,\n action: \"warn\",\n detail: `skill resource \"${rel}\" escapes the skill dir; skipped`,\n });\n continue;\n }\n changes.push(this.writeContentFile(target, contents, ctx.dryRun));\n }\n }\n return changes;\n }\n\n override uninstallSkills(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.skills.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no skills\" }];\n }\n const changes: ChangeRecord[] = [];\n for (const skill of connector.skills) {\n const dir = this.skillDir(ctx, skill.name);\n changes.push(this.removeContentFile(join(dir, \"SKILL.md\"), ctx.dryRun));\n for (const rel of Object.keys(skill.resources ?? {})) {\n const target = this.resolveWithin(dir, rel);\n if (target === null) continue;\n changes.push(this.removeContentFile(target, ctx.dryRun));\n }\n changes.push(this.removeDirIfEmpty(dir, ctx.dryRun));\n }\n return changes;\n }\n\n private renderSkill(skill: SkillDef): string {\n return renderSkillMd(skill);\n }\n\n // ── Hook install / uninstall (config.toml → [[hooks]]) ───────────────────\n\n installHooks(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.platforms[HOST]?.hooks === false) {\n return [{ platform: this.id, action: \"skip\", detail: \"hooks disabled for kimi\" }];\n }\n\n const events = this.effectiveHookEvents(ctx);\n const dropped = this.warnSkipHookEvents(ctx);\n const path = this.getHookConfigPath(ctx);\n\n if (events.length === 0 && dropped.length === 0) {\n return [{ platform: this.id, action: \"skip\", path, detail: \"no hooks declared\" }];\n }\n\n const cfg = this.readToml(path);\n const hooks = (cfg.hooks ??= []);\n const changes: ChangeRecord[] = [];\n let mutated = false;\n\n // Declared events Kimi cannot fire are reported, never silently dropped.\n for (const event of dropped) {\n changes.push({\n platform: this.id,\n action: \"warn\",\n path,\n detail: `${event} has no Kimi CLI hook equivalent — skipped`,\n });\n }\n\n for (const event of events) {\n const desired = this.renderHook(ctx, event);\n // Match our entry FOR THIS EVENT — isOurHook alone would find whichever\n // of our entries comes first and clobber a sibling event's registration.\n const idx = hooks.findIndex((h) => this.isOurHook(ctx, h) && h?.event === event);\n if (idx < 0) {\n hooks.push(desired);\n changes.push({ platform: this.id, action: \"create\", path, detail: `hooks.${event}` });\n mutated = true;\n } else if (JSON.stringify(hooks[idx]) !== JSON.stringify(desired)) {\n hooks[idx] = desired;\n changes.push({ platform: this.id, action: \"update\", path, detail: `hooks.${event}` });\n mutated = true;\n } else {\n changes.push({ platform: this.id, action: \"skip\", path, detail: `hooks.${event}` });\n }\n }\n\n if (mutated) this.writeToml(path, cfg, ctx.dryRun);\n return changes;\n }\n\n uninstallHooks(ctx: InstallContext): ChangeRecord[] {\n const path = this.getHookConfigPath(ctx);\n if (!existsSync(path)) {\n return [{ platform: this.id, action: \"skip\", path, detail: \"no config.toml\" }];\n }\n const cfg = this.readToml(path);\n const hooks = cfg.hooks;\n if (!Array.isArray(hooks) || hooks.length === 0) {\n return [{ platform: this.id, action: \"skip\", path, detail: \"no hooks present\" }];\n }\n\n const kept = hooks.filter((h) => !this.isOurHook(ctx, h));\n const removed = hooks.length - kept.length;\n if (removed === 0) {\n return [{ platform: this.id, action: \"skip\", path, detail: \"no agent-connector hooks present\" }];\n }\n\n if (kept.length > 0) cfg.hooks = kept;\n else delete cfg.hooks;\n this.writeToml(path, cfg, ctx.dryRun);\n return [{ platform: this.id, action: \"remove\", path, detail: `hooks (${removed})` }];\n }\n\n // ── Diagnostics ──────────────────────────────────────────────────────────\n\n override getHealthChecks(ctx: InstallContext): readonly HealthCheck[] {\n const serverPath = this.getServerConfigPath(ctx);\n const hookPath = this.getHookConfigPath(ctx);\n const connectorId = ctx.connector.id;\n const homeBin = ctx.homeBinPath;\n const hookEvents = this.effectiveHookEvents(ctx);\n const checks: HealthCheck[] = [\n {\n name: `${this.name}: mcp.json present`,\n check: () =>\n existsSync(serverPath)\n ? { status: \"OK\", detail: serverPath }\n : { status: \"FAIL\", detail: `not found: ${serverPath}` },\n },\n {\n name: `${this.name}: mcpServers.${connectorId} registered`,\n check: () => {\n if (!ctx.connector.server) {\n return { status: \"OK\", detail: \"no MCP server declared\" };\n }\n const cfg = this.readJson<Record<string, Record<string, unknown>>>(serverPath);\n const bucket = cfg?.[MCP_ROOT_KEY];\n const present =\n typeof bucket === \"object\" && bucket !== null && connectorId in bucket;\n return present\n ? { status: \"OK\", detail: `mcpServers.${connectorId}` }\n : { status: \"FAIL\", detail: `mcpServers.${connectorId} not found in ${serverPath}` };\n },\n },\n {\n name: `${this.name}: hook command registered`,\n check: () => {\n if (hookEvents.length === 0) {\n return { status: \"OK\", detail: \"no hooks declared\" };\n }\n if (!existsSync(hookPath)) {\n return { status: \"FAIL\", detail: `not found: ${hookPath}` };\n }\n const cfg = this.readToml(hookPath);\n const registered = (cfg.hooks ?? []).some((h) =>\n isHomeBinHookCommand(h?.command, homeBin, connectorId),\n );\n return registered\n ? { status: \"OK\", detail: \"hook command present\" }\n : { status: \"FAIL\", detail: `no hook for ${connectorId} in ${hookPath}` };\n },\n },\n ];\n for (const skill of ctx.connector.skills) {\n const p = join(this.skillDir(ctx, skill.name), \"SKILL.md\");\n checks.push({\n name: `${this.name}: skill ${skill.name} present`,\n check: () =>\n existsSync(p) ? { status: \"OK\", detail: p } : { status: \"FAIL\", detail: `not found: ${p}` },\n });\n }\n return checks;\n }\n\n // ── Runtime: parse Kimi stdin JSON → normalized event ────────────────────\n\n parseEvent(event: HookEventName, raw: unknown): NormalizedEvent {\n const input = (raw ?? {}) as KimiHookInput;\n const connectorId = typeof input.connector === \"string\" ? input.connector : \"\";\n const sessionId = input.session_id ?? `pid-${process.ppid}`;\n const projectDir = input.cwd ?? process.env.KIMI_PROJECT_DIR ?? process.cwd();\n\n const base = {\n hostPlatform: HOST,\n connectorId,\n sessionId,\n projectDir,\n raw,\n } as const;\n\n switch (event) {\n case \"PreToolUse\": {\n const ev: PreToolUseEvent = {\n ...base,\n toolName: input.tool_name ?? \"\",\n toolInput: input.tool_input ?? {},\n };\n return ev;\n }\n case \"PostToolUse\": {\n const ev: PostToolUseEvent = {\n ...base,\n toolName: input.tool_name ?? \"\",\n toolInput: input.tool_input ?? {},\n ...(toolResponseToString(input.tool_response) !== undefined\n ? { toolOutput: toolResponseToString(input.tool_response) }\n : {}),\n isError: input.is_error ?? false,\n };\n return ev;\n }\n case \"SessionStart\": {\n const ev: SessionStartEvent = {\n ...base,\n source: normalizeSessionSource(input.source),\n };\n return ev;\n }\n case \"SessionEnd\": {\n const ev: SessionEndEvent = {\n ...base,\n ...(typeof input.message === \"string\" ? { reason: input.message } : {}),\n };\n return ev;\n }\n case \"UserPromptSubmit\": {\n const ev: UserPromptSubmitEvent = {\n ...base,\n prompt: typeof input.prompt === \"string\" ? input.prompt : \"\",\n };\n return ev;\n }\n case \"PreCompact\": {\n const ev: PreCompactEvent = {\n ...base,\n ...(input.trigger === \"auto\" || input.trigger === \"manual\"\n ? { trigger: input.trigger }\n : {}),\n };\n return ev;\n }\n case \"Stop\": {\n const ev: StopEvent = {\n ...base,\n ...(typeof input.stop_hook_active === \"boolean\"\n ? { stopHookActive: input.stop_hook_active }\n : {}),\n };\n return ev;\n }\n case \"Notification\": {\n const ev: NotificationEvent = {\n ...base,\n message: typeof input.message === \"string\" ? input.message : \"\",\n };\n return ev;\n }\n case \"PermissionRequest\": {\n // No Kimi analog — never fired natively (install warn-skips it). Parsed\n // generically so a manual dispatch still normalizes instead of throwing.\n const ev: PermissionRequestEvent = {\n ...base,\n toolName: input.tool_name ?? \"\",\n toolInput: input.tool_input ?? {},\n };\n return ev;\n }\n case \"PostToolUseFailure\": {\n // Kimi documents tool_name/tool_input/error only (no tool_use_id /\n // is_interrupt / duration_ms) — the optionals stay unset.\n const ev: PostToolUseFailureEvent = {\n ...base,\n toolName: input.tool_name ?? \"\",\n toolInput: input.tool_input ?? {},\n error: typeof input.error === \"string\" ? input.error : \"\",\n };\n return ev;\n }\n case \"SubagentStart\": {\n // Kimi sends agent_name (the matcher subject) — normalize it as\n // agentType; there is no agent_id. The start prompt rides in `raw`.\n const ev: SubagentStartEvent = {\n ...base,\n ...(typeof input.agent_name === \"string\"\n ? { agentType: input.agent_name }\n : {}),\n };\n return ev;\n }\n case \"SubagentStop\": {\n const ev: SubagentStopEvent = {\n ...base,\n ...(typeof input.agent_name === \"string\"\n ? { agentType: input.agent_name }\n : {}),\n ...(typeof input.response === \"string\"\n ? { lastAssistantMessage: input.response }\n : {}),\n };\n return ev;\n }\n default: {\n const _never: never = event;\n throw new Error(`unsupported kimi hook event: ${String(_never)}`);\n }\n }\n }\n\n // ── Runtime: normalized response → Kimi native hook reply ────────────────\n\n formatReply(event: HookEventName, response: HookResponse): HookReply {\n const decision = response.decision ?? \"allow\";\n\n // deny → block the pending tool call. Kimi Code uses the Claude/Codex reply\n // shape: EXIT 0 + a `hookSpecificOutput` JSON object on stdout carrying\n // permissionDecision:\"deny\". Only PreToolUse deny is honored; every other\n // event (or decision) degrades to a silent allow.\n if (decision === \"deny\" && event === \"PreToolUse\") {\n return {\n exitCode: 0,\n stdout: JSON.stringify({\n hookSpecificOutput: {\n hookEventName: \"PreToolUse\",\n permissionDecision: \"deny\",\n permissionDecisionReason: response.reason ?? \"Blocked by hook\",\n },\n }),\n };\n }\n\n // PostToolUseFailure (feedback beside the error) and SubagentStart (context\n // for the subagent) are observe/context-only: Kimi's documented protocol\n // adds non-empty stdout on exit 0 to context, so \"context\" emits the text\n // PLAIN (no JSON envelope) and a \"deny\" DEGRADES to the same shape carrying\n // the reason (the tool already failed / the spawn is not blockable).\n if (event === \"PostToolUseFailure\" || event === \"SubagentStart\") {\n const context =\n decision === \"context\"\n ? response.additionalContext\n : decision === \"deny\"\n ? response.reason ?? response.additionalContext\n : undefined;\n if (context) return { exitCode: 0, stdout: context };\n return { exitCode: 0 };\n }\n\n // SubagentStop = Stop semantics via Kimi's generic block protocol: EXIT 2\n // with the reason on stderr keeps the subagent going (stderr is fed back to\n // the model as correction). \"context\" rides the exit-0 stdout channel.\n if (event === \"SubagentStop\") {\n if (decision === \"deny\") {\n return { exitCode: 2, stderr: response.reason ?? \"Blocked by hook\" };\n }\n if (decision === \"context\" && response.additionalContext) {\n return { exitCode: 0, stdout: response.additionalContext };\n }\n return { exitCode: 0 };\n }\n\n // allow / modify / context / ask / unsupported-event → passthrough (exit 0,\n // empty stdout). Kimi cannot rewrite args/output or inject context, so those\n // are dropped.\n return { exitCode: 0 };\n }\n\n // ── Internal helpers ───────────────────────────────────────────────────\n\n /** Which canonical hook events to register for Kimi, honoring overrides. */\n private effectiveHookEvents(ctx: InstallContext): KimiHookEventName[] {\n if (ctx.connector.platforms[HOST]?.hooks === false) return [];\n return KIMI_HOOK_EVENTS.filter((e) => ctx.connector.hookEvents.includes(e));\n }\n\n /** Declared events Kimi has no analog for — install reports a warn-skip. */\n private warnSkipHookEvents(ctx: InstallContext): HookEventName[] {\n if (ctx.connector.platforms[HOST]?.hooks === false) return [];\n return ctx.connector.hookEvents.filter((e) => WARN_SKIP_EVENTS.has(e));\n }\n\n /**\n * Render one `[[hooks]]` entry pointing at the stable home binary. Only the\n * PreToolUse deny gate carries the native tool matcher; the E1 events register\n * \"\" (match every tool failure / agent name) and the universal entrypoint\n * applies the connector's own matcher at runtime.\n */\n private renderHook(ctx: InstallContext, event: KimiHookEventName): KimiTomlHook {\n const command = buildHomeBinHookCommand(ctx.homeBinPath, HOST, event, ctx.connector.id);\n return {\n event,\n matcher: event === \"PreToolUse\" ? PRE_TOOL_USE_MATCHER : \"\",\n command,\n };\n }\n\n /**\n * Does this `[[hooks]]` entry belong to this connector? Anchored on the\n * home-bin + connector-id token (isHomeBinHookCommand) so uninstalling a\n * shared-prefix connector id never strips a sibling's hook.\n */\n private isOurHook(ctx: InstallContext, hook: KimiTomlHook | undefined): boolean {\n if (!hook || typeof hook !== \"object\") return false;\n return isHomeBinHookCommand(hook.command, ctx.homeBinPath, ctx.connector.id);\n }\n\n // ── TOML config IO (config.toml is TOML; MCP stays JSON via BaseAdapter) ──\n\n private readToml(path: string): KimiConfigToml {\n if (!existsSync(path)) return {};\n try {\n return TOML.parse(readFileSync(path, \"utf8\")) as unknown as KimiConfigToml;\n } catch {\n return {};\n }\n }\n\n private writeToml(path: string, data: KimiConfigToml, dryRun: boolean): void {\n if (dryRun) return;\n ensureDir(dirname(path));\n // NOTE: a @iarna/toml parse→stringify round-trip preserves config VALUES but\n // NOT user comments or the original key ordering/formatting in config.toml.\n // Values are safe; comments authored by the user are not preserved.\n writeFileSync(path, TOML.stringify(data as never), \"utf8\");\n }\n}\n\n/** Best-effort stringify of Kimi's tool_response into a normalized toolOutput. */\nfunction toolResponseToString(value: unknown): string | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value === \"string\") return value;\n try {\n return JSON.stringify(value);\n } catch {\n return undefined;\n }\n}\n\nfunction normalizeSessionSource(source: string | undefined): SessionStartEvent[\"source\"] {\n switch (source) {\n case \"compact\":\n return \"compact\";\n case \"resume\":\n return \"resume\";\n case \"clear\":\n return \"clear\";\n default:\n return \"startup\";\n }\n}\n\nexport const adapter = new KimiAdapter();\nexport default adapter;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmDA,SAAS,YAAY,cAAc,qBAAqB;AACxD,SAAS,eAAe;AACxB,SAAS,SAAS,YAAY;AAE9B,OAAO,UAAU;AAuCjB,IAAM,OAAmB;AACzB,IAAM,eAAe;AAgErB,IAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAWA,IAAM,mBAA+C,oBAAI,IAAI,CAAC,mBAAmB,CAAC;AAElF,IAAM,uBACJ;AAMK,IAAM,cAAN,cAA0B,YAA+B;AAAA,EACrD,KAAiB;AAAA,EACjB,OAAO;AAAA,EACP,WAAyB;AAAA,EAEzB,eAAqC;AAAA;AAAA;AAAA,IAG5C,gBAAgB;AAAA;AAAA,IAEhB,YAAY;AAAA,IACZ,aAAa;AAAA,IACb,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,YAAY;AAAA,IACZ,kBAAkB;AAAA,IAClB,MAAM;AAAA,IACN,cAAc;AAAA;AAAA;AAAA,IAGd,oBAAoB;AAAA,IACpB,eAAe;AAAA,IACf,cAAc;AAAA;AAAA,IAEd,eAAe;AAAA,IACf,iBAAiB;AAAA,IACjB,yBAAyB;AAAA,IACzB,YAAY,CAAC,SAAS,MAAM;AAAA;AAAA;AAAA;AAAA,IAI5B,gBAAgB;AAAA,EAClB;AAAA;AAAA,EAIA,gBAAgB,aAAuC;AACrD,UAAM,UAAU,KAAK,QAAQ;AAC7B,UAAM,UAAU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AAG,MAAM;AAAA,EAC3D;AACF;AAGA,SAAS,qBAAqB,OAAoC;AAChE,MAAI,UAAU,UAAa,UAAU,KAAM,QAAO;AAClD,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,MAAI;AACF,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,uBAAuB,QAAyD;AACvF,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAEO,IAAM,UAAU,IAAI,YAAY;AACvC,IAAO,eAAQ;","names":["entry"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapters/mimo-code/index.ts"],"sourcesContent":["/**\n * adapters/mimo-code — Xiaomi MiMoCode platform adapter for agent-connector.\n *\n * MiMoCode (github.com/XiaomiMiMo/MiMo-Code, MIT) is Xiaomi's open-source\n * terminal AI coding agent — a FORK OF OpenCode (anomalyco/opencode) that adds\n * cross-session memory, checkpoints, subagents, etc. Official npm `@mimo-ai/cli`\n * (bin: `mimo`). NOTE: `@xiaomi-mimo/cli` is an UNOFFICIAL squatter (GPL) — not\n * referenced here; the bin is `mimo`, NOT `mimo-code`.\n *\n * DESIGN — STANDALONE (mirrors OpenCode's render logic with mimocode paths),\n * NOT `extends OpenCodeAdapter`. The OpenCode adapter binds the host string in\n * several places that a subclass cannot cleanly override:\n * - a module-level `const HOST = \"opencode\"` used for the per-platform server/\n * hooks override lookup (`ctx.connector.platforms[HOST]`) and stamped as\n * `hostPlatform` on every parsed event — extending would read\n * `platforms[\"opencode\"]` overrides and mis-stamp events as opencode;\n * - the PRIVATE `buildPluginSource` hardcodes `[\"hook\", \"opencode\", event, …]`\n * in the GENERATED bridge, so an inherited plugin would dispatch the runtime\n * hook to the opencode adapter (`hook opencode`) instead of mimo-code;\n * - the config/plugin/content directory builders hardcode \"opencode\" /\n * \".opencode\" / \"opencode.json\".\n * Overriding all of that means re-implementing the private render core anyway,\n * so this adapter mirrors OpenCode's logic with a `HOST = \"mimo-code\"` constant\n * and the mimocode paths — a clean standalone that routes detection, the runtime\n * bridge, and per-platform overrides to its own id.\n *\n * MiMoCode IS OpenCode's config dialect, so the render shapes are IDENTICAL:\n * - config file `mimocode.json`\n * user scope → ~/.config/mimocode/mimocode.json\n * project scope → <projectDir>/mimocode.json\n * (the dir is `.mimocode` / `~/.config/mimocode` — NO hyphen; the committed\n * example is `.mimocode/mimocode.jsonc`).\n * - MCP root key \"mcp\" (the OpenCode shape, NOT \"mcpServers\"); each server\n * keyed by name; stdio → { type:\"local\", command:[exe,…args], environment },\n * remote → { type:\"remote\", url }.\n * - ts-plugin hooks: a self-contained ESM bridge module auto-loaded from the\n * user scope → ~/.config/mimocode/plugin/<id>.js\n * project scope → <projectDir>/.mimocode/plugin/<id>.js\n * plugin dir (writing the file IS the registration; no config array edit).\n * - content surfaces under <mcDir>/{commands,skills,agent} (singular `agent/`,\n * matching OpenCode).\n *\n * Event mapping (OpenCode's, unchanged):\n * PreToolUse → \"tool.execute.before\" (mutate output.args; throw to deny)\n * PostToolUse → \"tool.execute.after\" (mutate output.output)\n * SessionStart → \"experimental.chat.system.transform\" (inject into output.system)\n *\n * SOURCES: github.com/XiaomiMiMo/MiMo-Code (README, .mimocode/mimocode.jsonc,\n * packages/opencode/src/config/{config.ts,mcp.ts,plugin.ts}). npm @mimo-ai/cli.\n * mimo.xiaomi.com/en/mimocode.\n */\n\nimport {\n chmodSync,\n existsSync,\n mkdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nimport { BaseAdapter } from \"../base.js\";\nimport type {\n Adapter,\n GeneratedPluginFile,\n HookReply,\n InstallContext,\n MemoryTarget,\n NormalizedEvent,\n} from \"../spi.js\";\nimport type {\n ChangeRecord,\n CommandDef,\n DetectedPlatform,\n HealthCheck,\n HookEventName,\n HookParadigm,\n HookResponse,\n PlatformCapabilities,\n PlatformId,\n PostToolUseEvent,\n PreToolUseEvent,\n ServerDef,\n SessionStartEvent,\n SkillDef,\n SubagentDef,\n Transport,\n} from \"../../core/types.js\";\nimport { resolveEnvRefsDeep } from \"../../core/interpolate.js\";\nimport {\n buildServeWrapperCommand,\n shouldWrapForTelemetry,\n} from \"../../core/spawn.js\";\n\nconst HOST: PlatformId = \"mimo-code\";\nconst MCP_ROOT_KEY = \"mcp\";\n\n/** The config dir name (NO hyphen): `.mimocode` / `~/.config/mimocode`. */\nconst CONFIG_DIR_NAME = \"mimocode\";\n/** The config file name: `mimocode.json`. */\nconst CONFIG_FILE_NAME = \"mimocode.json\";\n\n/**\n * Canonical → MiMoCode (OpenCode-shaped) event name map. A connector hook event\n * is only emitted by the generated plugin when it appears here AND is declared\n * by the connector.\n */\nconst EVENT_TO_MIMOCODE: Partial<Record<HookEventName, string>> = {\n PreToolUse: \"tool.execute.before\",\n PostToolUse: \"tool.execute.after\",\n // No real SessionStart hook (inherited from OpenCode #14808 / #5409). The\n // verified surrogate is experimental.chat.system.transform.\n SessionStart: \"experimental.chat.system.transform\",\n};\n\n/** Raw payload the generated plugin posts to the universal hook entrypoint. */\ninterface MiMoCodeBridgePayload {\n toolName?: string;\n toolInput?: Record<string, unknown>;\n toolOutput?: string;\n isError?: boolean;\n sessionId?: string;\n projectDir?: string;\n}\n\n/** Native MCP server entry shapes MiMoCode accepts under the \"mcp\" key. */\ninterface MiMoCodeLocalServer {\n type: \"local\";\n command: string[];\n environment?: Record<string, string>;\n enabled?: boolean;\n}\ninterface MiMoCodeRemoteServer {\n type: \"remote\";\n url: string;\n enabled?: boolean;\n}\n\nexport class MiMoCodeAdapter extends BaseAdapter implements Adapter {\n readonly id: PlatformId = HOST;\n readonly name = \"MiMoCode\";\n readonly paradigm: HookParadigm = \"ts-plugin\";\n\n readonly capabilities: PlatformCapabilities = {\n // Memory surface: AGENTS.md-first managed block (CLAUDE.md fallback, like\n // OpenCode — MiMoCode keeps OpenCode's CLAUDE.md import + AGENTS.md reading).\n supportsMemory: true,\n preToolUse: true,\n postToolUse: true,\n preCompact: false,\n sessionStart: true,\n sessionEnd: false,\n userPromptSubmit: false,\n stop: false,\n notification: false,\n // tool.execute.before mutates output.args → input rewrite supported.\n canModifyArgs: true,\n // tool.execute.after mutates output.output → output rewrite supported.\n canModifyOutput: true,\n // injected via experimental.chat.system.transform at session start.\n canInjectSessionContext: true,\n transports: [\"stdio\", \"sse\", \"http\"],\n // Content surfaces: MiMoCode authors all three natively under <mcDir>\n // (inherited from OpenCode's commands/skills/agent layout).\n supportsCommands: true,\n supportsSkills: true,\n supportsSubagents: true,\n };\n\n // ── Detection ──────────────────────────────────────────────────────────\n\n detectInstalled(projectDir: string): DetectedPlatform {\n const userConfigDir = join(homedir(), \".config\", CONFIG_DIR_NAME);\n const userConfig = join(userConfigDir, CONFIG_FILE_NAME);\n const projectConfig = join(projectDir, CONFIG_FILE_NAME);\n\n const userInstalled = existsSync(userConfigDir) || existsSync(userConfig);\n const projInstalled = existsSync(projectConfig);\n const installed = userInstalled || projInstalled;\n\n // Report the marker that actually matched so a project-only install isn't\n // misreported as a (non-existent) user install.\n const scope = projInstalled && !userInstalled ? \"project\" : \"user\";\n const configPath = scope === \"project\" ? projectConfig : userConfig;\n\n return {\n id: this.id,\n name: this.name,\n installed,\n paradigm: this.paradigm,\n capabilities: this.capabilities,\n configPath,\n scope,\n reason: installed\n ? scope === \"project\"\n ? `found project MiMoCode config at ${projectConfig}`\n : `found MiMoCode config under ${userConfigDir}`\n : `no MiMoCode config at ${userConfigDir}`,\n confidence: installed ? \"high\" : \"low\",\n };\n }\n\n // ── Memory surface: AGENTS.md / CLAUDE.md-fallback probe (project) ──────\n // Mirrors OpenCode: project AGENTS.md, falling back to CLAUDE.md ONLY when no\n // AGENTS.md exists (creating AGENTS.md beside a relied-on CLAUDE.md would\n // shadow the user's rules). User scope stays on the BaseAdapter default.\n protected override memoryTargets(ctx: InstallContext): MemoryTarget[] {\n if (this.memoryOverride(ctx)?.path || ctx.scope !== \"project\") {\n return super.memoryTargets(ctx);\n }\n const agentsMd = join(ctx.projectDir, \"AGENTS.md\");\n if (existsSync(agentsMd)) {\n return [{ path: agentsMd, reason: \"AGENTS.md (mimocode's primary project rules file)\" }];\n }\n const claudeMd = join(ctx.projectDir, \"CLAUDE.md\");\n if (existsSync(claudeMd)) {\n return [\n {\n path: claudeMd,\n reason:\n \"CLAUDE.md (mimocode's fallback rules file — creating AGENTS.md would shadow it)\",\n },\n ];\n }\n return [{ path: agentsMd, reason: \"AGENTS.md standard (created; no mimocode rules file yet)\" }];\n }\n\n // ── Native paths ───────────────────────────────────────────────────────\n\n getConfigDir(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? ctx.projectDir\n : join(homedir(), \".config\", CONFIG_DIR_NAME);\n }\n\n getServerConfigPath(ctx: InstallContext): string {\n return join(this.getConfigDir(ctx), CONFIG_FILE_NAME);\n }\n\n /**\n * For ts-plugin hosts the \"hook config path\" is the generated plugin FILE.\n * MiMoCode (like OpenCode) auto-loads every file in the plugin dir; writing\n * this file IS the registration.\n */\n getHookConfigPath(ctx: InstallContext): string {\n return join(this.pluginDir(ctx), this.pluginFileName(ctx));\n }\n\n /** Plugin directory MiMoCode auto-loads modules from, per scope. */\n private pluginDir(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? join(ctx.projectDir, `.${CONFIG_DIR_NAME}`, \"plugin\")\n : join(homedir(), \".config\", CONFIG_DIR_NAME, \"plugin\");\n }\n\n /** Plugin module file name (one per connector, kebab-case id). */\n private pluginFileName(ctx: InstallContext): string {\n return `${ctx.connector.id}.js`;\n }\n\n // ── MCP server install / uninstall ─────────────────────────────────────\n\n installServer(ctx: InstallContext): ChangeRecord[] {\n const server = this.effectiveServer(ctx);\n const serverPath = this.getServerConfigPath(ctx);\n\n if (!server) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n path: serverPath,\n detail: ctx.connector.server\n ? \"server registration disabled for mimo-code\"\n : \"connector declares no MCP server\",\n },\n ];\n }\n\n const entry = this.renderServerEntry(ctx, server);\n return [\n this.upsertServerInJson(\n serverPath,\n MCP_ROOT_KEY,\n ctx.connector.id,\n entry,\n ctx.dryRun,\n ),\n ];\n }\n\n uninstallServer(ctx: InstallContext): ChangeRecord[] {\n const serverPath = this.getServerConfigPath(ctx);\n return [\n this.removeServerFromJson(\n serverPath,\n MCP_ROOT_KEY,\n ctx.connector.id,\n ctx.dryRun,\n ),\n ];\n }\n\n /** Resolve the per-platform server override into an effective ServerDef. */\n private effectiveServer(ctx: InstallContext): ServerDef | undefined {\n const override = ctx.connector.platforms[HOST]?.server;\n if (override === false) return undefined;\n const base = ctx.connector.server;\n if (!base) return undefined;\n return override && typeof override === \"object\" ? { ...base, ...override } : base;\n }\n\n /**\n * Render a normalized ServerDef into MiMoCode's native \"mcp\" entry (OpenCode\n * dialect).\n *\n * stdio → { type: \"local\", command: [exe, ...args], environment }\n * remote → { type: \"remote\", url }\n *\n * MiMoCode flattens command+args into a single ARRAY. When telemetry wrapping\n * applies, the wrapper's command+args (which already include the real command\n * tail after `--`) become the head of that array. No native interpolation\n * token → resolve every ${env:VAR} reference to a literal at install time.\n */\n private renderServerEntry(\n ctx: InstallContext,\n server: ServerDef,\n ): MiMoCodeLocalServer | MiMoCodeRemoteServer {\n const transport: Transport = server.transport;\n\n if (transport === \"stdio\") {\n let command = server.command ?? \"\";\n let args = [...(server.args ?? [])];\n\n if (shouldWrapForTelemetry(server, ctx.connector.telemetry)) {\n const wrapped = buildServeWrapperCommand(\n ctx.homeBinPath,\n ctx.connector.id,\n command,\n args,\n ctx.scope,\n this.id,\n );\n command = wrapped.command;\n args = wrapped.args;\n }\n\n const commandArray = resolveEnvRefsDeep([command, ...args]).filter(\n (s) => s !== \"\",\n );\n const entry: MiMoCodeLocalServer = {\n type: \"local\",\n command: commandArray,\n };\n const environment = this.renderEnv(server.env);\n if (environment) entry.environment = environment;\n if (server.enabled === false) entry.enabled = false;\n return entry;\n }\n\n // sse / http / ws (any remote transport) — MiMoCode registers a URL.\n const entry: MiMoCodeRemoteServer = {\n type: \"remote\",\n url: resolveEnvRefsDeep(server.url ?? \"\"),\n };\n if (server.enabled === false) entry.enabled = false;\n return entry;\n }\n\n /** Render env values, resolving every ${env:VAR} reference to a literal. */\n private renderEnv(\n env: Record<string, string> | undefined,\n ): Record<string, string> | undefined {\n if (!env || Object.keys(env).length === 0) return undefined;\n return resolveEnvRefsDeep({ ...env });\n }\n\n // ── Hook install / uninstall (ts-plugin) ───────────────────────────────\n\n installHooks(ctx: InstallContext): ChangeRecord[] {\n const pluginPath = this.getHookConfigPath(ctx);\n\n if (ctx.connector.platforms[HOST]?.hooks === false) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n path: pluginPath,\n detail: \"hooks disabled for mimo-code\",\n },\n ];\n }\n if (ctx.connector.hookEvents.length === 0) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n path: pluginPath,\n detail: \"connector declares no hooks\",\n },\n ];\n }\n\n const files = this.synthesizePlugin(ctx);\n const changes: ChangeRecord[] = [];\n\n for (const file of files) {\n const before = existsSync(file.path)\n ? this.safeRead(file.path)\n : undefined;\n let action: ChangeRecord[\"action\"];\n if (before === undefined) action = \"create\";\n else if (before === file.contents) action = \"skip\";\n else action = \"update\";\n\n if (action !== \"skip\" && !ctx.dryRun) {\n ensureDir(dirname(file.path));\n writeFileSync(file.path, file.contents, \"utf8\");\n chmodSync(file.path, file.executable ? 0o755 : 0o644);\n }\n\n changes.push({\n platform: this.id,\n action,\n path: file.path,\n detail: `mimo-code plugin module (${this.hookDetail(ctx)})`,\n });\n }\n\n return changes;\n }\n\n /**\n * Human-facing summary of which declared events the synthesized module\n * ACTUALLY wires. Only events present in EVENT_TO_MIMOCODE are mapped/wired;\n * any declared event with no mapping is reported separately as \"unsupported\n * here\" so the detail never overstates coverage.\n */\n private hookDetail(ctx: InstallContext): string {\n const declared = ctx.connector.hookEvents;\n const mapped = declared.filter((e) => EVENT_TO_MIMOCODE[e] !== undefined);\n const unsupported = declared.filter((e) => EVENT_TO_MIMOCODE[e] === undefined);\n const base = mapped.join(\",\");\n return unsupported.length > 0\n ? `${base}; unsupported here: ${unsupported.join(\",\")}`\n : base;\n }\n\n uninstallHooks(ctx: InstallContext): ChangeRecord[] {\n const pluginPath = this.getHookConfigPath(ctx);\n if (!existsSync(pluginPath)) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n path: pluginPath,\n detail: \"no mimo-code plugin module present\",\n },\n ];\n }\n if (!ctx.dryRun) rmSync(pluginPath, { force: true });\n return [\n {\n platform: this.id,\n action: \"remove\",\n path: pluginPath,\n detail: \"mimo-code plugin module\",\n },\n ];\n }\n\n // ── Content surfaces: commands / skills / subagents ──────────────────────\n // CONTENT-ONLY: pure native-file writers under <mcDir>/{commands,skills,\n // agent}. No runtime dispatch, no home-bin pointer, no telemetry wrap. Each\n // method is idempotent (byte-identical → skip) and reversible. Mirrors\n // OpenCode's layout: commands/<name>.md, skills/<name>/SKILL.md, and the\n // SINGULAR agent/<name>.md dir for subagents. For project scope the content\n // root is <projectDir>/.mimocode (NOT the project root where mimocode.json\n // lives).\n\n private contentRootDir(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? join(ctx.projectDir, `.${CONFIG_DIR_NAME}`)\n : this.getConfigDir(ctx);\n }\n private commandsDir(ctx: InstallContext): string {\n return join(this.contentRootDir(ctx), \"commands\");\n }\n private skillsDir(ctx: InstallContext): string {\n return join(this.contentRootDir(ctx), \"skills\");\n }\n private agentDir(ctx: InstallContext): string {\n return join(this.contentRootDir(ctx), \"agent\");\n }\n\n /** Native command file path: <mcDir>/commands/<name>.md. */\n private commandPath(ctx: InstallContext, name: string): string {\n return join(this.commandsDir(ctx), `${name}.md`);\n }\n /** Native skill dir: <mcDir>/skills/<name>. */\n private skillDir(ctx: InstallContext, name: string): string {\n return join(this.skillsDir(ctx), name);\n }\n /** Native subagent file path: <mcDir>/agent/<name>.md (SINGULAR dir). */\n private subagentPath(ctx: InstallContext, name: string): string {\n return join(this.agentDir(ctx), `${name}.md`);\n }\n\n // ── Commands ──────────────────────────────────────────────────────────────\n\n override installCommands(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.platforms[HOST]?.commands === false) {\n return [{ platform: this.id, action: \"skip\", detail: \"commands disabled for mimo-code\" }];\n }\n if (connector.commands.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no commands\" }];\n }\n return connector.commands.map((cmd) =>\n this.writeContentFile(\n this.commandPath(ctx, cmd.name),\n this.renderCommand(cmd),\n ctx.dryRun,\n ),\n );\n }\n\n override uninstallCommands(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.commands.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no commands\" }];\n }\n return connector.commands.map((cmd) =>\n this.removeContentFile(this.commandPath(ctx, cmd.name), ctx.dryRun),\n );\n }\n\n /** Render a command to md+frontmatter (description, model, subtask). */\n private renderCommand(cmd: CommandDef): string {\n const frontmatter: Record<string, unknown> = {};\n if (cmd.description !== undefined) frontmatter.description = cmd.description;\n if (cmd.model !== undefined) frontmatter.model = cmd.model;\n if (cmd.subtask !== undefined) frontmatter.subtask = cmd.subtask;\n if (cmd.extra) Object.assign(frontmatter, cmd.extra);\n return this.renderFrontmatterMd(frontmatter, cmd.prompt);\n }\n\n // ── Skills ────────────────────────────────────────────────────────────────\n\n override installSkills(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.platforms[HOST]?.skills === false) {\n return [{ platform: this.id, action: \"skip\", detail: \"skills disabled for mimo-code\" }];\n }\n if (connector.skills.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no skills\" }];\n }\n const changes: ChangeRecord[] = [];\n for (const skill of connector.skills) {\n const dir = this.skillDir(ctx, skill.name);\n changes.push(\n this.writeContentFile(join(dir, \"SKILL.md\"), this.renderSkill(skill), ctx.dryRun),\n );\n for (const [rel, contents] of Object.entries(skill.resources ?? {})) {\n const target = this.resolveWithin(dir, rel);\n if (target === null) {\n changes.push({\n platform: this.id,\n action: \"warn\",\n detail: `skill resource \"${rel}\" escapes the skill dir; skipped`,\n });\n continue;\n }\n changes.push(this.writeContentFile(target, contents, ctx.dryRun));\n }\n }\n return changes;\n }\n\n override uninstallSkills(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.skills.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no skills\" }];\n }\n const changes: ChangeRecord[] = [];\n for (const skill of connector.skills) {\n const dir = this.skillDir(ctx, skill.name);\n changes.push(this.removeContentFile(join(dir, \"SKILL.md\"), ctx.dryRun));\n for (const rel of Object.keys(skill.resources ?? {})) {\n const target = this.resolveWithin(dir, rel);\n if (target === null) continue;\n changes.push(this.removeContentFile(target, ctx.dryRun));\n }\n changes.push(this.removeDirIfEmpty(dir, ctx.dryRun));\n }\n return changes;\n }\n\n /**\n * Render a skill's SKILL.md (UNIFORM across platforms): frontmatter\n * (name, description + optional model, allowed-tools, disable-model-invocation)\n * + markdown body.\n */\n private renderSkill(skill: SkillDef): string {\n const frontmatter: Record<string, unknown> = {\n name: skill.name,\n description: skill.description,\n };\n if (skill.model !== undefined) frontmatter.model = skill.model;\n const allow = skill.tools?.allow;\n if (allow && allow.length > 0) frontmatter[\"allowed-tools\"] = allow.join(\", \");\n if (skill.disableModelInvocation !== undefined) {\n frontmatter[\"disable-model-invocation\"] = skill.disableModelInvocation;\n }\n if (skill.extra) Object.assign(frontmatter, skill.extra);\n return this.renderFrontmatterMd(frontmatter, skill.body);\n }\n\n // ── Subagents ───────────────────────────────────────────────────────────────\n\n override installSubagents(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.platforms[HOST]?.subagents === false) {\n return [{ platform: this.id, action: \"skip\", detail: \"subagents disabled for mimo-code\" }];\n }\n if (connector.subagents.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no subagents\" }];\n }\n return connector.subagents.map((agent) =>\n this.writeContentFile(\n this.subagentPath(ctx, agent.name),\n this.renderSubagent(agent),\n ctx.dryRun,\n ),\n );\n }\n\n override uninstallSubagents(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.subagents.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no subagents\" }];\n }\n return connector.subagents.map((agent) =>\n this.removeContentFile(this.subagentPath(ctx, agent.name), ctx.dryRun),\n );\n }\n\n /**\n * Render a subagent to md+frontmatter (OpenCode's shape, inherited by\n * MiMoCode): (description, mode:\"subagent\", model, permission) with the system\n * prompt as the body. `name` comes from the filename. A readonly agent gets a\n * per-tool deny map (edit/bash) so it cannot mutate the workspace.\n */\n private renderSubagent(agent: SubagentDef): string {\n const frontmatter: Record<string, unknown> = {\n description: agent.description,\n mode: \"subagent\",\n };\n if (agent.model !== undefined) frontmatter.model = agent.model;\n if (agent.readonly === true) {\n frontmatter.permission = { edit: \"deny\", bash: \"deny\" };\n }\n if (agent.extra) Object.assign(frontmatter, agent.extra);\n return this.renderFrontmatterMd(frontmatter, agent.prompt);\n }\n\n // ── ts-plugin synthesis ────────────────────────────────────────────────\n\n /**\n * Build ONE self-contained ESM bridge module for MiMoCode. The module imports\n * nothing from agent-connector; it embeds the home-bin path + connector id and\n * a `bridge()` helper that shells out to the universal hook entrypoint\n * (`<homeBin> hook mimo-code <event> --connector <id>`), feeding the payload on\n * stdin and JSON.parsing the normalized HookResponse from stdout (fail-open).\n */\n synthesizePlugin(ctx: InstallContext): GeneratedPluginFile[] {\n const path = this.getHookConfigPath(ctx);\n const contents = this.buildPluginSource(ctx);\n return [{ path, contents, executable: false }];\n }\n\n /** Compose the generated plugin source with plain string concatenation. */\n private buildPluginSource(ctx: InstallContext): string {\n const homeBin = JSON.stringify(ctx.homeBinPath);\n const connectorId = JSON.stringify(ctx.connector.id);\n\n const events = ctx.connector.hookEvents.filter(\n (e): e is HookEventName => EVENT_TO_MIMOCODE[e] !== undefined,\n );\n const has = (e: HookEventName) => events.includes(e);\n\n const header = `/**\n * AUTO-GENERATED by agent-connector — DO NOT EDIT.\n *\n * Self-contained MiMoCode plugin bridge for connector ${ctx.connector.id}.\n * It imports nothing from agent-connector: every hook invocation shells out to\n * the stable home binary's universal entrypoint and JSON-parses the normalized\n * response. Fail-open: any bridge error degrades to \"allow\".\n */\nimport { execFileSync, execSync } from \"node:child_process\";\n\nconst HOME_BIN = ${homeBin};\nconst CONNECTOR_ID = ${connectorId};\n\n/**\n * Invoke the universal hook entrypoint for one event.\n * @param {string} event canonical event name (PreToolUse|PostToolUse|SessionStart)\n * @param {object} payload MiMoCode-shaped payload posted on stdin\n * @returns {object|null} normalized HookResponse, or null on any failure\n */\nfunction bridge(event, payload) {\n try {\n // On Windows HOME_BIN is the agent-connector.cmd launcher: Node cannot\n // execFile a batch file, and shell+args is deprecated (DEP0190), so run one\n // quoted command line via a shell. POSIX keeps the direct execFile (no shell).\n const args = [\"hook\", \"mimo-code\", event, \"--connector\", CONNECTOR_ID];\n const opts = { input: JSON.stringify(payload), encoding: \"utf8\" };\n const stdout =\n process.platform === \"win32\"\n ? execSync([HOME_BIN, ...args].map((a) => '\"' + a + '\"').join(\" \"), opts)\n : execFileSync(HOME_BIN, args, opts);\n const text = (stdout || \"\").trim();\n if (text === \"\") return { decision: \"allow\" };\n return JSON.parse(text);\n } catch {\n // Fail-open — never wedge a tool call on a bridge error.\n return null;\n }\n}\n`;\n\n const handlers: string[] = [];\n\n if (has(\"PreToolUse\")) {\n handlers.push(` // PreToolUse → block (throw) / rewrite args (mutate output.args).\n \"tool.execute.before\": async (input, output) => {\n const payload = {\n toolName: input.tool ?? \"\",\n toolInput: (output && output.args) ?? {},\n sessionId: input.sessionID ?? \"\",\n projectDir: PROJECT_DIR,\n };\n const res = bridge(\"PreToolUse\", payload);\n if (!res) return;\n // MiMoCode has no \"ask\" gate — degrade \"ask\" to a block (safe direction).\n if (res.decision === \"deny\" || res.decision === \"ask\") {\n throw new Error(res.reason || \"Blocked by ${ctx.connector.id}\");\n }\n if (res.updatedInput && output && output.args) {\n Object.assign(output.args, res.updatedInput);\n }\n },`);\n }\n\n if (has(\"PostToolUse\")) {\n handlers.push(` // PostToolUse → observe / rewrite tool output (mutate output.output).\n \"tool.execute.after\": async (input, output) => {\n const payload = {\n toolName: input.tool ?? \"\",\n toolInput: input.args ?? {},\n toolOutput: output ? output.output : undefined,\n sessionId: input.sessionID ?? \"\",\n projectDir: PROJECT_DIR,\n };\n const res = bridge(\"PostToolUse\", payload);\n if (!res) return;\n if (typeof res.updatedOutput === \"string\" && output) {\n output.output = res.updatedOutput;\n }\n },`);\n }\n\n if (has(\"SessionStart\")) {\n handlers.push(` // SessionStart surrogate → inject context into the system prompt.\n // MiMoCode has no real SessionStart hook (inherited from OpenCode\n // #14808 / #5409); experimental.chat.system.transform is the injection point.\n \"experimental.chat.system.transform\": async (input, output) => {\n const payload = {\n sessionId: (input && input.sessionID) ?? \"\",\n projectDir: PROJECT_DIR,\n };\n const res = bridge(\"SessionStart\", payload);\n if (!res) return;\n if (res.additionalContext && output && Array.isArray(output.system)) {\n // Insert at index 1 (after the header) to preserve the prompt-cache\n // fold (header must remain system[0]).\n output.system.splice(1, 0, res.additionalContext);\n }\n },`);\n }\n\n const factory = `\nexport default async function (ctx) {\n // ctx.directory is the MiMoCode project root; fall back to cwd.\n const PROJECT_DIR =\n (ctx && (ctx.directory || (ctx.worktree && ctx.worktree.path))) ||\n process.cwd();\n\n return {\n${handlers.join(\"\\n\")}\n };\n}\n`;\n\n return header + factory;\n }\n\n // ── Runtime: parse OUR bridge payload → normalized event ───────────────\n\n /**\n * `raw` is the payload OUR generated plugin posts (NOT a host-native shape):\n * { toolName, toolInput, toolOutput?, isError?, sessionId, projectDir }\n * so this maps straight through.\n */\n parseEvent(event: HookEventName, raw: unknown): NormalizedEvent {\n const input = (raw ?? {}) as MiMoCodeBridgePayload;\n const base = {\n hostPlatform: HOST,\n connectorId: \"\",\n sessionId: typeof input.sessionId === \"string\" ? input.sessionId : \"\",\n raw,\n ...(typeof input.projectDir === \"string\"\n ? { projectDir: input.projectDir }\n : {}),\n } as const;\n\n switch (event) {\n case \"PreToolUse\": {\n const ev: PreToolUseEvent = {\n ...base,\n toolName: input.toolName ?? \"\",\n toolInput: input.toolInput ?? {},\n };\n return ev;\n }\n case \"PostToolUse\": {\n const ev: PostToolUseEvent = {\n ...base,\n toolName: input.toolName ?? \"\",\n toolInput: input.toolInput ?? {},\n ...(typeof input.toolOutput === \"string\"\n ? { toolOutput: input.toolOutput }\n : {}),\n ...(typeof input.isError === \"boolean\"\n ? { isError: input.isError }\n : {}),\n };\n return ev;\n }\n case \"SessionStart\": {\n const ev: SessionStartEvent = { ...base, source: \"startup\" };\n return ev;\n }\n default:\n // Other canonical events are not surfaced by MiMoCode; treat as a\n // session-start-shaped no-op so the dispatcher fails open gracefully.\n return { ...base, source: \"startup\" } satisfies SessionStartEvent;\n }\n }\n\n // ── Runtime: normalized response → reply the generated bridge parses ───\n\n /**\n * Our generated bridge consumes this stdout directly, so the reply body is the\n * NORMALIZED HookResponse itself — the bridge JSON.parses it and reads\n * decision / updatedInput / updatedOutput / additionalContext.\n */\n formatReply(_event: HookEventName, response: HookResponse): HookReply {\n return {\n exitCode: 0,\n stdout: JSON.stringify(response ?? { decision: \"allow\" }),\n };\n }\n\n // ── Diagnostics ────────────────────────────────────────────────────────\n\n override getHealthChecks(ctx: InstallContext): readonly HealthCheck[] {\n const serverPath = this.getServerConfigPath(ctx);\n const pluginPath = this.getHookConfigPath(ctx);\n const connectorId = ctx.connector.id;\n const hasHooks = ctx.connector.hookEvents.length > 0;\n\n const checks: HealthCheck[] = [\n {\n name: `${this.name}: mimocode.json present`,\n check: () =>\n existsSync(serverPath)\n ? { status: \"OK\", detail: serverPath }\n : { status: \"FAIL\", detail: `not found: ${serverPath}` },\n },\n {\n name: `${this.name}: mcp.${connectorId} registered`,\n check: () => {\n if (!ctx.connector.server) {\n return { status: \"OK\", detail: \"no MCP server declared\" };\n }\n const cfg = this.readJson<{ [k: string]: Record<string, unknown> }>(\n serverPath,\n );\n const bucket = cfg?.[MCP_ROOT_KEY];\n if (!cfg || !bucket) {\n return { status: \"FAIL\", detail: `no ${MCP_ROOT_KEY} in ${serverPath}` };\n }\n return connectorId in bucket\n ? { status: \"OK\", detail: `${MCP_ROOT_KEY}.${connectorId} present` }\n : {\n status: \"FAIL\",\n detail: `no ${MCP_ROOT_KEY}.${connectorId} in ${serverPath}`,\n };\n },\n },\n {\n name: `${this.name}: plugin module present`,\n check: () => {\n if (!hasHooks) return { status: \"OK\", detail: \"no hooks declared\" };\n return existsSync(pluginPath)\n ? { status: \"OK\", detail: pluginPath }\n : { status: \"FAIL\", detail: `not found: ${pluginPath}` };\n },\n },\n ];\n\n for (const cmd of ctx.connector.commands) {\n const p = this.commandPath(ctx, cmd.name);\n checks.push({\n name: `${this.name}: command ${cmd.name} present`,\n check: () =>\n existsSync(p) ? { status: \"OK\", detail: p } : { status: \"FAIL\", detail: `not found: ${p}` },\n });\n }\n for (const skill of ctx.connector.skills) {\n const p = join(this.skillDir(ctx, skill.name), \"SKILL.md\");\n checks.push({\n name: `${this.name}: skill ${skill.name} present`,\n check: () =>\n existsSync(p) ? { status: \"OK\", detail: p } : { status: \"FAIL\", detail: `not found: ${p}` },\n });\n }\n for (const agent of ctx.connector.subagents) {\n const p = this.subagentPath(ctx, agent.name);\n checks.push({\n name: `${this.name}: subagent ${agent.name} present`,\n check: () =>\n existsSync(p) ? { status: \"OK\", detail: p } : { status: \"FAIL\", detail: `not found: ${p}` },\n });\n }\n return checks;\n }\n\n /** Read a file, returning undefined on any error (idempotency compare). */\n private safeRead(path: string): string | undefined {\n try {\n return readFileSync(path, \"utf8\");\n } catch {\n return undefined;\n }\n }\n}\n\n/** Create a directory (recursive) if it does not already exist. */\nfunction ensureDir(dir: string): void {\n if (!existsSync(dir)) mkdirSync(dir, { recursive: true });\n}\n\nexport const adapter = new MiMoCodeAdapter();\nexport default adapter;\n"],"mappings":";;;;;;;;;;;;;;;;AAoDA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe;AACxB,SAAS,SAAS,YAAY;AAmC9B,IAAM,OAAmB;AACzB,IAAM,eAAe;AAGrB,IAAM,kBAAkB;AAExB,IAAM,mBAAmB;AAOzB,IAAM,oBAA4D;AAAA,EAChE,YAAY;AAAA,EACZ,aAAa;AAAA;AAAA;AAAA,EAGb,cAAc;AAChB;AAyBO,IAAM,kBAAN,cAA8B,YAA+B;AAAA,EACzD,KAAiB;AAAA,EACjB,OAAO;AAAA,EACP,WAAyB;AAAA,EAEzB,eAAqC;AAAA;AAAA;AAAA,IAG5C,gBAAgB;AAAA,IAChB,YAAY;AAAA,IACZ,aAAa;AAAA,IACb,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,YAAY;AAAA,IACZ,kBAAkB;AAAA,IAClB,MAAM;AAAA,IACN,cAAc;AAAA;AAAA,IAEd,eAAe;AAAA;AAAA,IAEf,iBAAiB;AAAA;AAAA,IAEjB,yBAAyB;AAAA,IACzB,YAAY,CAAC,SAAS,OAAO,MAAM;AAAA;AAAA;AAAA,IAGnC,kBAAkB;AAAA,IAClB,gBAAgB;AAAA,IAChB,mBAAmB;AAAA,EACrB;AAAA;AAAA,EAIA,gBAAgB,YAAsC;AACpD,UAAM,gBAAgB,KAAK,QAAQ,GAAG,WAAW,eAAe;AAChE,UAAM,aAAa,KAAK,eAAe,gBAAgB;AACvD,UAAM,gBAAgB,KAAK,YAAY,gBAAgB;AAEvD,UAAM,gBAAgB,WAAW,aAAa,KAAK,WAAW,UAAU;AACxE,UAAM,gBAAgB,WAAW,aAAa;AAC9C,UAAM,YAAY,iBAAiB;AAInC,UAAM,QAAQ,iBAAiB,CAAC,gBAAgB,YAAY;A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IAAI,GAAG,UAAU;AACzD,aAAO,KAAK;AAAA,QACV,MAAM,GAAG,KAAK,IAAI,WAAW,MAAM,IAAI;AAAA,QACvC,OAAO,MACL,WAAW,CAAC,IAAI,EAAE,QAAQ,MAAM,QAAQ,EAAE,IAAI,EAAE,QAAQ,QAAQ,QAAQ,cAAc,CAAC,GAAG;AAAA,MAC9F,CAAC;AAAA,IACH;AACA,eAAW,SAAS,IAAI,UAAU,WAAW;AAC3C,YAAM,IAAI,KAAK,aAAa,KAAK,MAAM,IAAI;AAC3C,aAAO,KAAK;AAAA,QACV,MAAM,GAAG,KAAK,IAAI,cAAc,MAAM,IAAI;AAAA,QAC1C,OAAO,MACL,WAAW,CAAC,IAAI,EAAE,QAAQ,MAAM,QAAQ,EAAE,IAAI,EAAE,QAAQ,QAAQ,QAAQ,cAAc,CAAC,GAAG;AAAA,MAC9F,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AAAA;AAAA,EAGQ,SAAS,MAAkC;AACjD,QAAI;AACF,aAAO,aAAa,MAAM,MAAM;AAAA,IAClC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAGA,SAAS,UAAU,KAAmB;AACpC,MAAI,CAAC,WAAW,GAAG,EAAG,WAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAC1D;AAEO,IAAM,UAAU,IAAI,gBAAgB;AAC3C,IAAO,oBAAQ;","names":["entry"]}
|
package/dist/mux-DSSH4AFS.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapters/mux/index.ts"],"sourcesContent":["/**\n * adapters/mux — Mux (Coder) platform adapter for agent-connector.\n *\n * Mux is an **mcp-only** host: it exposes no lifecycle hook system, and MCP is\n * its extensibility mechanism. This adapter therefore installs only the MCP\n * server and reports hooks as unavailable — the same shape as the Warp\n * reference adapter.\n *\n * MCP config:\n * - user scope → ~/.mux/mcp.jsonc\n * - project scope → <projectDir>/.mux/mcp.jsonc\n * Both are JSONC (comments allowed) but we write strict JSON. The root key is\n * \"servers\", and this file doubles as the (non-existent) hook config — there\n * is no separate hook file here.\n *\n * QUIRK: Mux models each server entry as a single shell-command STRING, not an\n * object. So `servers[id]` is `\"<exe> <arg1> <arg2> ...\"` — space-joined, with\n * any token containing whitespace double-quoted. We therefore build that string\n * ourselves and upsert it idempotently (the generic object upsert helper would\n * write the wrong shape). When telemetry-wrapping, the string is the home-bin\n * `serve` wrapper command followed by its args.\n *\n * Mux documents no native `${env:VAR}` interpolation token, so env-refs in the\n * command/args are resolved to literals at install time. The string form has no\n * place for an env map, so server.env is dropped with no native equivalent.\n */\n\nimport { existsSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\nimport { BaseAdapter } from \"../base.js\";\nimport type { Adapter, InstallContext } from \"../spi.js\";\nimport type {\n ChangeRecord,\n DetectedPlatform,\n HealthCheck,\n HookParadigm,\n PlatformCapabilities,\n PlatformId,\n ServerDef,\n} from \"../../core/types.js\";\nimport { resolveEnvRefs, resolveEnvRefsDeep } from \"../../core/interpolate.js\";\nimport {\n buildServeWrapperCommand,\n shouldWrapForTelemetry,\n} from \"../../core/spawn.js\";\n\nconst HOST: PlatformId = \"mux\";\nconst MCP_ROOT_KEY = \"servers\";\n\n/** Quote a token only when it contains whitespace (Mux command-string form). */\nfunction quoteToken(token: string): string {\n return /\\s/.test(token) ? `\"${token}\"` : token;\n}\n\n/** Join an executable + args into Mux's single shell-command string. */\nfunction buildCommandString(command: string, args: readonly string[]): string {\n return [command, ...args].map(quoteToken).join(\" \");\n}\n\nexport class MuxAdapter extends BaseAdapter implements Adapter {\n readonly id: PlatformId = HOST;\n readonly name = \"Mux\";\n readonly paradigm: HookParadigm = \"mcp-only\";\n\n readonly capabilities: PlatformCapabilities = {\n // Memory surface: AGENTS.md-first managed block via the BaseAdapter default\n // (memoryTargets: project <projectDir>/AGENTS.md; user scope where documented).\n supportsMemory: true,\n // Mux has no lifecycle hook system — every hook capability is false.\n preToolUse: false,\n postToolUse: false,\n preCompact: false,\n sessionStart: false,\n sessionEnd: false,\n userPromptSubmit: false,\n stop: false,\n notification: false,\n canModifyArgs: false,\n canModifyOutput: false,\n canInjectSessionContext: false,\n // Mux's command-string server entry is stdio-only.\n transports: [\"stdio\"],\n };\n\n // ── Detection ────────────────────────────────────────────────────────────\n\n detectInstalled(projectDir: string): DetectedPlatform {\n const userDir = join(homedir(), \".mux\");\n const userMcp = join(userDir, \"mcp.jsonc\");\n const projDir = join(projectDir, \".mux\");\n const projMcp = join(projDir, \"mcp.jsonc\");\n\n const userInstalled = existsSync(userDir) || existsSync(userMcp);\n const projInstalled = existsSync(projDir) || existsSync(projMcp);\n const installed = userInstalled || projInstalled;\n const scope = projInstalled && !userInstalled ? \"project\" : \"user\";\n const configPath = scope === \"project\" ? projMcp : userMcp;\n\n return {\n id: this.id,\n name: this.name,\n installed,\n paradigm: this.paradigm,\n capabilities: this.capabilities,\n configPath,\n scope,\n reason: installed\n ? `found Mux config (${scope})`\n : `no Mux config at ${userDir} or ${projDir}`,\n confidence: installed ? \"high\" : \"low\",\n };\n }\n\n // ── Native paths ─────────────────────────────────────────────────────────\n\n getConfigDir(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? join(ctx.projectDir, \".mux\")\n : join(homedir(), \".mux\");\n }\n\n getServerConfigPath(ctx: InstallContext): string {\n return join(this.getConfigDir(ctx), \"mcp.jsonc\");\n }\n\n /**\n * Mux has no hook file — hooks are not a thing here. The hook \"config path\"\n * is the same mcp.jsonc so the generic doctor/backup behave sensibly.\n */\n getHookConfigPath(ctx: InstallContext): string {\n return this.getServerConfigPath(ctx);\n }\n\n // ── MCP server install / uninstall ───────────────────────────────────────\n\n installServer(ctx: InstallContext): ChangeRecord[] {\n const { connector, dryRun } = ctx;\n const override = connector.platforms[HOST]?.server;\n if (!connector.server || override === false) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n detail: connector.server\n ? \"server registration disabled for mux\"\n : \"connector declares no MCP server\",\n },\n ];\n }\n\n // Shallow-merge any per-platform server override into the base ServerDef.\n const server: ServerDef =\n override && typeof override === \"object\"\n ? { ...connector.server, ...override }\n : connector.server;\n\n const path = this.getServerConfigPath(ctx);\n\n if (server.transport !== \"stdio\" || !server.command) {\n // Mux's command-string entry is stdio-only; remote transports skip.\n return [\n {\n platform: this.id,\n action: \"skip\",\n path,\n detail: `transport \"${server.transport}\" not registrable (mux expects a stdio command string)`,\n },\n ];\n }\n\n const entry = this.renderCommandString(ctx, server);\n\n // QUIRK: each server value is a STRING, not an object — so we cannot use the\n // generic object upsert helper. Build the string and upsert idempotently.\n const cfg =\n this.readJson<Record<string, Record<string, unknown>>>(path) ?? {};\n const bucket = (cfg[MCP_ROOT_KEY] ??= {});\n const before = JSON.stringify(bucket[connector.id]);\n const after = JSON.stringify(entry);\n\n let action: ChangeRecord[\"action\"];\n if (before === undefined) action = \"create\";\n else if (before === after) action = \"skip\";\n else action = \"update\";\n\n if (action !== \"skip\") {\n bucket[connector.id] = entry;\n this.writeJson(path, cfg, dryRun);\n }\n return [\n { platform: this.id, action, path, detail: `${MCP_ROOT_KEY}.${connector.id}` },\n ];\n }\n\n uninstallServer(ctx: InstallContext): ChangeRecord[] {\n const path = this.getServerConfigPath(ctx);\n return [\n this.removeServerFromJson(path, MCP_ROOT_KEY, ctx.connector.id, ctx.dryRun),\n ];\n }\n\n /**\n * Render a stdio ServerDef into Mux's single shell-command string. Honors the\n * telemetry serve-wrapper and resolves every `${env:VAR}` to a literal (Mux\n * documents no native interpolation token).\n */\n private renderCommandString(ctx: InstallContext, server: ServerDef): string {\n let command = server.command ?? \"\";\n let args = [...(server.args ?? [])];\n\n // Transparent telemetry wrapping: route the real command through\n // `<homeBin> serve --connector <id> -- <command> <args...>`.\n if (shouldWrapForTelemetry(server, ctx.connector.telemetry)) {\n const wrapped = buildServeWrapperCommand(\n ctx.homeBinPath,\n ctx.connector.id,\n command,\n args,\n ctx.scope,\n this.id,\n );\n command = wrapped.command;\n args = wrapped.args;\n }\n\n // Resolve env-refs to literals (Mux has no native interpolation token).\n command = resolveEnvRefs(command);\n args = resolveEnvRefsDeep(args);\n\n return buildCommandString(command, args);\n }\n\n // ── Hooks (unavailable — Mux is mcp-only) ─────────────────────────────────\n\n installHooks(_ctx: InstallContext): ChangeRecord[] {\n return [\n {\n platform: this.id,\n action: \"skip\",\n detail: \"hooks unavailable (Mux is mcp-only)\",\n },\n ];\n }\n\n uninstallHooks(_ctx: InstallContext): ChangeRecord[] {\n return [\n {\n platform: this.id,\n action: \"skip\",\n detail: \"hooks unavailable (Mux is mcp-only)\",\n },\n ];\n }\n\n // ── Diagnostics ──────────────────────────────────────────────────────────\n\n override getHealthChecks(ctx: InstallContext): readonly HealthCheck[] {\n const mcpPath = this.getServerConfigPath(ctx);\n const connectorId = ctx.connector.id;\n return [\n {\n name: `${this.name}: mcp.jsonc present`,\n check: () =>\n existsSync(mcpPath)\n ? { status: \"OK\", detail: mcpPath }\n : { status: \"FAIL\", detail: `not found: ${mcpPath}` },\n },\n {\n name: `${this.name}: server entry registered`,\n check: () => {\n // Only assert what the connector declares: a server-less connector\n // never writes an mcpServers entry, so its absence is healthy.\n if (!ctx.connector.server) {\n return { status: \"OK\", detail: \"no MCP server declared\" };\n }\n const cfg = this.readJson<{ [k: string]: Record<string, unknown> }>(\n mcpPath,\n );\n const bucket = cfg?.[MCP_ROOT_KEY];\n if (!cfg || !bucket) {\n return { status: \"FAIL\", detail: `no ${MCP_ROOT_KEY} in ${mcpPath}` };\n }\n return connectorId in bucket\n ? { status: \"OK\", detail: `${MCP_ROOT_KEY}.${connectorId} present` }\n : {\n status: \"FAIL\",\n detail: `no ${MCP_ROOT_KEY}.${connectorId} in ${mcpPath}`,\n };\n },\n },\n ];\n }\n}\n\nexport const adapter = new MuxAdapter();\nexport default adapter;\n"],"mappings":";;;;;;;;;;;;;;;;;AA2BA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AACxB,SAAS,YAAY;AAmBrB,IAAM,OA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;AAAA,EACF;AAAA;AAAA,EAIS,gBAAgB,KAA6C;AACpE,UAAM,UAAU,KAAK,oBAAoB,GAAG;AAC5C,UAAM,cAAc,IAAI,UAAU;AAClC,WAAO;AAAA,MACL;AAAA,QACE,MAAM,GAAG,KAAK,IAAI;AAAA,QAClB,OAAO,MACL,WAAW,OAAO,IACd,EAAE,QAAQ,MAAM,QAAQ,QAAQ,IAChC,EAAE,QAAQ,QAAQ,QAAQ,cAAc,OAAO,GAAG;AAAA,MAC1D;AAAA,MACA;AAAA,QACE,MAAM,GAAG,KAAK,IAAI;AAAA,QAClB,OAAO,MAAM;AAGX,cAAI,CAAC,IAAI,UAAU,QAAQ;AACzB,mBAAO,EAAE,QAAQ,MAAM,QAAQ,yBAAyB;AAAA,UAC1D;AACA,gBAAM,MAAM,KAAK;AAAA,YACf;AAAA,UACF;AACA,gBAAM,SAAS,MAAM,YAAY;AACjC,cAAI,CAAC,OAAO,CAAC,QAAQ;AACnB,mBAAO,EAAE,QAAQ,QAAQ,QAAQ,MAAM,YAAY,OAAO,OAAO,GAAG;AAAA,UACtE;AACA,iBAAO,eAAe,SAClB,EAAE,QAAQ,MAAM,QAAQ,GAAG,YAAY,IAAI,WAAW,WAAW,IACjE;AAAA,YACE,QAAQ;AAAA,YACR,QAAQ,MAAM,YAAY,IAAI,WAAW,OAAO,OAAO;AAAA,UACzD;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,UAAU,IAAI,WAAW;AACtC,IAAO,cAAQ;","names":[]}
|
package/dist/omp-Z6FRNDPN.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapters/omp/index.ts"],"sourcesContent":["/**\n * adapters/omp — Oh My Pi (OMP) platform adapter for agent-connector.\n *\n * OMP is a ts-plugin host with NATIVE MCP. The two surfaces are split:\n *\n * • MCP (native, real file) — OMP reads a real `mcp.json`:\n * user scope → <agentDir>/mcp.json (agentDir = ~/.omp/agent)\n * project scope → <projectDir>/.omp/mcp.json\n * JSON, root key \"mcpServers\", stdio entry { command, args, env } — the\n * portable field names. Verified against can1357/oh-my-pi\n * (packages/utils/src/dirs.ts getMCPConfigPath + docs/mcp-config.md). OMP\n * documents no native ${env:VAR} token, so env refs resolve to literals at\n * install time (resolveEnvRefsDeep).\n *\n * • Hooks (ts-plugin, in-process) — OMP loads EXTENSION PACKAGES. Its plugin\n * loader reads a package whose package.json carries an `omp` (or `pi`)\n * manifest field; the manifest's `extensions` array points at the plugin\n * module, whose DEFAULT export is a HookFactory `(pi) => void` that calls\n * `pi.on(event, handler)` (upstream loader.ts:75\n * `pluginPkg.omp || pluginPkg.pi`; hook factory types.ts:809). context-mode\n * proved this by dropping an extension under\n * `<agentDir>/extensions/<name>/{package.json,index.js}` whose index.js\n * default-exports the OMP plugin factory (src/setup.ts applyPlatformInstall\n * \"omp\"; src/adapters/omp/plugin.ts).\n *\n * Why we SYNTHESIZE instead of importing context-mode's plugin:\n * context-mode could load its own plugin module in-process because the handler\n * code shipped with the package. agent-connector cannot — the connector's hook\n * handlers are arbitrary developer code we must not import into OMP's runtime\n * (wrong cwd, wrong deps, version skew, the cache-heal bug class). So, exactly\n * like the OpenCode adapter, we generate a tiny self-contained ESM extension\n * that imports NOTHING from agent-connector: each `pi.on(...)` handler shells\n * out to the ONE stable home binary's universal entrypoint\n * (`<homeBin> hook omp <event> --connector <id>`) over child_process, feeds it\n * the OMP-shaped payload as JSON on stdin, and JSON.parses the normalized\n * HookResponse back from stdout. Fail-open: any bridge error → no-op. One\n * entrypoint, every paradigm.\n *\n * Event mapping (only events the connector declares are subscribed):\n * PreToolUse → pi.on(\"tool_call\", …) block via { block:true, reason }\n * (OMP tool_call cannot mutate args → canModifyArgs:false)\n * PostToolUse → pi.on(\"tool_result\", …) observe-only (no output rewrite hook)\n * SessionStart → pi.on(\"session_start\", …) (no context-injection surface)\n * PreCompact → pi.on(\"session_before_compact\", …) observe-only\n *\n * Distinct storage root from Pi: OMP lives under ~/.omp (NOT ~/.pi); the\n * PI_CODING_AGENT_DIR env var (the only OMP runtime dir override — OMP mirrors\n * any .env `OMP_*` keys to `PI_*` before process.env is read) takes precedence.\n */\n\nimport {\n chmodSync,\n existsSync,\n mkdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nimport { BaseAdapter } from \"../base.js\";\nimport type {\n Adapter,\n GeneratedPluginFile,\n HookReply,\n InstallContext,\n NormalizedEvent,\n} from \"../spi.js\";\nimport type {\n ChangeRecord,\n DetectedPlatform,\n HealthCheck,\n HookEventName,\n HookParadigm,\n HookResponse,\n PlatformCapabilities,\n PlatformId,\n PostToolUseEvent,\n PreCompactEvent,\n PreToolUseEvent,\n ServerDef,\n SessionStartEvent,\n Transport,\n} from \"../../core/types.js\";\nimport { resolveEnvRefsDeep } from \"../../core/interpolate.js\";\nimport {\n buildServeWrapperCommand,\n shouldWrapForTelemetry,\n} from \"../../core/spawn.js\";\n\nconst HOST: PlatformId = \"omp\";\nconst MCP_ROOT_KEY = \"mcpServers\";\n\n/**\n * Canonical → OMP event name map. A connector hook event is only subscribed by\n * the generated plugin when it appears here AND is declared by the connector.\n * Names verified against the proven context-mode OMP plugin (pi.on targets).\n */\nconst EVENT_TO_OMP: Partial<Record<HookEventName, string>> = {\n PreToolUse: \"tool_call\",\n PostToolUse: \"tool_result\",\n SessionStart: \"session_start\",\n PreCompact: \"session_before_compact\",\n};\n\n/** Raw payload the generated plugin posts to the universal hook entrypoint. */\ninterface OmpBridgePayload {\n toolName?: string;\n toolInput?: Record<string, unknown>;\n toolOutput?: string;\n isError?: boolean;\n sessionId?: string;\n projectDir?: string;\n}\n\n/** Native MCP server entry shapes OMP accepts under \"mcpServers\". */\ninterface OmpStdioServer {\n command: string;\n args?: string[];\n env?: Record<string, string>;\n}\ninterface OmpRemoteServer {\n url: string;\n headers?: Record<string, string>;\n}\n\nexport class OMPAdapter extends BaseAdapter implements Adapter {\n readonly id: PlatformId = HOST;\n readonly name = \"Oh My Pi (OMP)\";\n readonly paradigm: HookParadigm = \"ts-plugin\";\n\n readonly capabilities: PlatformCapabilities = {\n // Memory surface: AGENTS.md-first managed block via the BaseAdapter default\n // (memoryTargets: project <projectDir>/AGENTS.md; user scope where documented).\n supportsMemory: true,\n preToolUse: true,\n postToolUse: true,\n // session_before_compact is wired as an observe-only PreCompact surface.\n preCompact: true,\n sessionStart: true,\n sessionEnd: false,\n userPromptSubmit: false,\n stop: false,\n notification: false,\n // Newer events: OMP's agent_start/agent_end/turn_* hooks are the MAIN loop\n // (no subagent lifecycle events), there is no permission/approval surface,\n // and tool failure is merged into tool_result (isError) rather than a\n // dedicated event. None are wired, so permissionRequest /\n // postToolUseFailure / subagentStart / subagentStop stay unset — the\n // generated bridge never references them and install reports them as\n // \"unsupported here\".\n // OMP tool_call gates via { block, reason } only — it does not hand the\n // handler a mutable args object, so input rewrite is unsupported.\n canModifyArgs: false,\n // No tool_result output-rewrite surface upstream.\n canModifyOutput: false,\n // No session_start context-injection surface upstream.\n canInjectSessionContext: false,\n // OMP registers stdio and remote (http) MCP servers.\n transports: [\"stdio\", \"http\"],\n };\n\n // ── Native paths ───────────────────────────────────────────────────────\n\n /**\n * Resolve the OMP agent dir, honoring the PI_CODING_AGENT_DIR override (the\n * only OMP runtime dir env), else ~/.omp/agent. This is the user-scope root.\n */\n private agentDir(): string {\n const override = process.env.PI_CODING_AGENT_DIR;\n return override && override !== \"\"\n ? override\n : join(homedir(), \".omp\", \"agent\");\n }\n\n getConfigDir(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? join(ctx.projectDir, \".omp\")\n : this.agentDir();\n }\n\n /** Native MCP file: <agentDir>/mcp.json (user) or <projectDir>/.omp/mcp.json. */\n getServerConfigPath(ctx: InstallContext): string {\n return join(this.getConfigDir(ctx), \"mcp.json\");\n }\n\n /**\n * For this ts-plugin host the \"hook config path\" is the generated extension\n * entrypoint module (index.js). OMP loads the extension package by reading its\n * package.json manifest, so the package.json is written alongside (see\n * synthesizePlugin); this returns the entry module the manifest points at.\n */\n getHookConfigPath(ctx: InstallContext): string {\n return join(this.extensionDir(ctx), \"index.js\");\n }\n\n /** Extension package directory OMP loads the plugin from, per scope. */\n private extensionDir(ctx: InstallContext): string {\n const base =\n ctx.scope === \"project\"\n ? join(ctx.projectDir, \".omp\")\n : this.agentDir();\n return join(base, \"extensions\", ctx.connector.id);\n }\n\n // ── Detection ──────────────────────────────────────────────────────────\n\n detectInstalled(projectDir: string): DetectedPlatform {\n const userAgentDir = this.agentDir();\n const userConfig = join(userAgentDir, \"mcp.json\");\n const projectConfig = join(projectDir, \".omp\", \"mcp.json\");\n\n const userInstalled = existsSync(userAgentDir) || existsSync(userConfig);\n const projInstalled =\n existsSync(join(projectDir, \".omp\")) || existsSync(projectConfig);\n const installed = userInstalled || projInstalled;\n\n // Report the marker that actually matched.\n const scope = projInstalled && !userInstalled ? \"project\" : \"user\";\n const configPath = scope === \"project\" ? projectConfig : userConfig;\n\n return {\n id: this.id,\n name: this.name,\n installed,\n paradigm: this.paradigm,\n capabilities: this.capabilities,\n configPath,\n scope,\n reason: installed\n ? scope === \"project\"\n ? `found project OMP dir at ${join(projectDir, \".omp\")}`\n : `found OMP agent dir at ${userAgentDir}`\n : `no OMP agent dir at ${userAgentDir}`,\n confidence: installed ? \"high\" : \"low\",\n };\n }\n\n // ── MCP server install / uninstall (native mcp.json) ────────────────────\n\n installServer(ctx: InstallContext): ChangeRecord[] {\n const server = this.effectiveServer(ctx);\n const serverPath = this.getServerConfigPath(ctx);\n\n if (!server) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n path: serverPath,\n detail: ctx.connector.server\n ? \"server registration disabled for omp\"\n : \"connector declares no MCP server\",\n },\n ];\n }\n\n const entry = this.renderServerEntry(ctx, server);\n return [\n this.upsertServerInJson(\n serverPath,\n MCP_ROOT_KEY,\n ctx.connector.id,\n entry,\n ctx.dryRun,\n ),\n ];\n }\n\n uninstallServer(ctx: InstallContext): ChangeRecord[] {\n const serverPath = this.getServerConfigPath(ctx);\n return [\n this.removeServerFromJson(\n serverPath,\n MCP_ROOT_KEY,\n ctx.connector.id,\n ctx.dryRun,\n ),\n ];\n }\n\n /** Resolve the per-platform server override into an effective ServerDef. */\n private effectiveServer(ctx: InstallContext): ServerDef | undefined {\n const override = ctx.connector.platforms[HOST]?.server;\n if (override === false) return undefined;\n const base = ctx.connector.server;\n if (!base) return undefined;\n return override && typeof override === \"object\"\n ? { ...base, ...override }\n : base;\n }\n\n /**\n * Render a normalized ServerDef into OMP's native \"mcpServers\" entry.\n *\n * stdio → { command, args, env } (portable field names)\n * remote → { url, headers? }\n *\n * Telemetry wrapping routes the real command through\n * `<homeBin> serve --connector <id> -- <command> <args...>`. OMP has no native\n * env interpolation token, so every ${env:VAR} ref resolves to a literal.\n */\n private renderServerEntry(\n ctx: InstallContext,\n server: ServerDef,\n ): OmpStdioServer | OmpRemoteServer {\n const transport: Transport = server.transport;\n\n if (transport === \"stdio\") {\n let command = server.command ?? \"\";\n let args = [...(server.args ?? [])];\n\n if (shouldWrapForTelemetry(server, ctx.connector.telemetry)) {\n const wrapped = buildServeWrapperCommand(\n ctx.homeBinPath,\n ctx.connector.id,\n command,\n args,\n ctx.scope,\n this.id,\n );\n command = wrapped.command;\n args = wrapped.args;\n }\n\n const entry: OmpStdioServer = {\n command: resolveEnvRefsDeep(command),\n };\n const resolvedArgs = resolveEnvRefsDeep(args).filter((s) => s !== \"\");\n if (resolvedArgs.length > 0) entry.args = resolvedArgs;\n const env = this.renderEnv(server.env);\n if (env) entry.env = env;\n return entry;\n }\n\n // remote (http / sse / ws) — OMP registers a URL.\n const entry: OmpRemoteServer = {\n url: resolveEnvRefsDeep(server.url ?? \"\"),\n };\n const headers = this.renderEnv(server.headers);\n if (headers) entry.headers = headers;\n return entry;\n }\n\n /** Resolve every ${env:VAR} ref to a literal (OMP has no native token). */\n private renderEnv(\n env: Record<string, string> | undefined,\n ): Record<string, string> | undefined {\n if (!env || Object.keys(env).length === 0) return undefined;\n return resolveEnvRefsDeep({ ...env });\n }\n\n // ── Hook install / uninstall (ts-plugin extension package) ──────────────\n\n installHooks(ctx: InstallContext): ChangeRecord[] {\n const entryPath = this.getHookConfigPath(ctx);\n\n if (ctx.connector.platforms[HOST]?.hooks === false) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n path: entryPath,\n detail: \"hooks disabled for omp\",\n },\n ];\n }\n if (ctx.connector.hookEvents.length === 0) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n path: entryPath,\n detail: \"connector declares no hooks\",\n },\n ];\n }\n\n const files = this.synthesizePlugin(ctx);\n const changes: ChangeRecord[] = [];\n\n for (const file of files) {\n const before = existsSync(file.path)\n ? this.safeRead(file.path)\n : undefined;\n let action: ChangeRecord[\"action\"];\n if (before === undefined) action = \"create\";\n else if (before === file.contents) action = \"skip\";\n else action = \"update\";\n\n if (action !== \"skip\" && !ctx.dryRun) {\n ensureDir(dirname(file.path));\n writeFileSync(file.path, file.contents, \"utf8\");\n chmodSync(file.path, file.executable ? 0o755 : 0o644);\n }\n\n changes.push({\n platform: this.id,\n action,\n path: file.path,\n detail: file.path.endsWith(\"package.json\")\n ? \"omp extension manifest\"\n : `omp plugin module (${this.hookDetail(ctx)})`,\n });\n }\n\n return changes;\n }\n\n /**\n * Human-facing summary of which declared events the synthesized module ACTUALLY\n * wires. Only events present in EVENT_TO_OMP are mapped/wired; any declared\n * event with no OMP mapping (e.g. UserPromptSubmit) is reported separately as\n * \"unsupported here\" so the detail never overstates coverage.\n */\n private hookDetail(ctx: InstallContext): string {\n const declared = ctx.connector.hookEvents;\n const mapped = declared.filter((e) => EVENT_TO_OMP[e] !== undefined);\n const unsupported = declared.filter((e) => EVENT_TO_OMP[e] === undefined);\n const base = mapped.join(\",\");\n return unsupported.length > 0\n ? `${base}; unsupported here: ${unsupported.join(\",\")}`\n : base;\n }\n\n uninstallHooks(ctx: InstallContext): ChangeRecord[] {\n const entryPath = this.getHookConfigPath(ctx);\n const manifestPath = join(this.extensionDir(ctx), \"package.json\");\n const present = [entryPath, manifestPath].filter((p) => existsSync(p));\n\n if (present.length === 0) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n path: entryPath,\n detail: \"no omp extension present\",\n },\n ];\n }\n\n const changes: ChangeRecord[] = [];\n for (const p of present) {\n if (!ctx.dryRun) rmSync(p, { force: true });\n changes.push({\n platform: this.id,\n action: \"remove\",\n path: p,\n detail: p.endsWith(\"package.json\")\n ? \"omp extension manifest\"\n : \"omp plugin module\",\n });\n }\n return changes;\n }\n\n // ── ts-plugin synthesis ────────────────────────────────────────────────\n\n /**\n * Build the OMP extension package: TWO files.\n *\n * 1. package.json — the manifest OMP's loader reads. It carries the `omp`\n * field (`pluginPkg.omp || pluginPkg.pi`) whose `extensions` array points\n * at the entry module, plus `type:\"module\"` and `main:\"index.js\"`.\n * 2. index.js — a self-contained ESM plugin that imports nothing from\n * agent-connector. Its default export is the OMP HookFactory `(pi)=>void`;\n * each declared event registers a `pi.on(...)` handler that bridges to the\n * home binary via execFileSync (fail-open) and applies the normalized\n * response.\n */\n synthesizePlugin(ctx: InstallContext): GeneratedPluginFile[] {\n const dir = this.extensionDir(ctx);\n return [\n {\n path: join(dir, \"package.json\"),\n contents: this.buildManifest(ctx),\n executable: false,\n },\n {\n path: join(dir, \"index.js\"),\n contents: this.buildPluginSource(ctx),\n executable: false,\n },\n ];\n }\n\n /** The extension package.json manifest OMP's plugin loader reads. */\n private buildManifest(ctx: InstallContext): string {\n const manifest = {\n name: ctx.connector.id,\n version: ctx.connector.version || \"0.0.0\",\n description: `${ctx.connector.displayName} OMP extension (generated by agent-connector)`,\n type: \"module\",\n main: \"index.js\",\n // pluginPkg.omp || pluginPkg.pi → manifest. extensions points at the entry.\n omp: {\n extensions: [\"./index.js\"],\n },\n };\n return `${JSON.stringify(manifest, null, 2)}\\n`;\n }\n\n /** Compose the generated plugin source with plain string concatenation. */\n private buildPluginSource(ctx: InstallContext): string {\n const homeBin = JSON.stringify(ctx.homeBinPath);\n const connectorId = JSON.stringify(ctx.connector.id);\n\n const events = ctx.connector.hookEvents.filter(\n (e): e is HookEventName => EVENT_TO_OMP[e] !== undefined,\n );\n const has = (e: HookEventName) => events.includes(e);\n\n const header = `/**\n * AUTO-GENERATED by agent-connector — DO NOT EDIT.\n *\n * Self-contained Oh My Pi (OMP) plugin extension for connector ${ctx.connector.id}.\n * It imports nothing from agent-connector: every hook invocation shells out to\n * the stable home binary's universal entrypoint and JSON-parses the normalized\n * response. Fail-open: any bridge error degrades to a no-op (never wedges OMP).\n *\n * OMP loads this module via the sibling package.json \"omp\" manifest field; the\n * default export is the HookFactory (pi) => void called once at load time.\n */\nimport { execFileSync, execSync } from \"node:child_process\";\n\nconst HOME_BIN = ${homeBin};\nconst CONNECTOR_ID = ${connectorId};\n\n/**\n * Invoke the universal hook entrypoint for one event.\n * @param {string} event canonical event name\n * @param {object} payload OMP-shaped payload posted on stdin\n * @returns {object|null} normalized HookResponse, or null on any failure\n */\nfunction bridge(event, payload) {\n try {\n // On Windows HOME_BIN is the agent-connector.cmd launcher: Node cannot\n // execFile a batch file, and shell+args is deprecated (DEP0190), so run one\n // quoted command line via a shell. POSIX keeps the direct execFile (no shell).\n const args = [\"hook\", \"omp\", event, \"--connector\", CONNECTOR_ID];\n const opts = { input: JSON.stringify(payload), encoding: \"utf8\" };\n const stdout =\n process.platform === \"win32\"\n ? execSync([HOME_BIN, ...args].map((a) => '\"' + a + '\"').join(\" \"), opts)\n : execFileSync(HOME_BIN, args, opts);\n const text = (stdout || \"\").trim();\n if (text === \"\") return { decision: \"allow\" };\n return JSON.parse(text);\n } catch {\n // Fail-open — never break an OMP tool call / lifecycle event.\n return null;\n }\n}\n\n// OMP exposes the project dir via PI_PROJECT_DIR (PI_*-prefixed only); fall\n// through to cwd. The plugin process is long-lived, so resolve once at load.\nconst PROJECT_DIR = process.env.PI_PROJECT_DIR || process.cwd();\n\n// Derive a stable session id from OMP's session manager when available\n// (ctx.sessionManager.getSessionFile()), else a wall-clock token. The id is\n// rebound on each session_start so multi-session reuse stays attributed.\nlet SESSION_ID = \"\";\nfunction deriveSessionId(ctx) {\n try {\n const f = ctx && ctx.sessionManager && typeof ctx.sessionManager.getSessionFile === \"function\"\n ? ctx.sessionManager.getSessionFile()\n : \"\";\n if (f && typeof f === \"string\") return f;\n } catch {\n // best effort\n }\n return \"omp-\" + Date.now();\n}\n`;\n\n const handlers: string[] = [];\n\n if (has(\"SessionStart\")) {\n handlers.push(` // SessionStart → rebind the session id and notify the connector.\n pi.on(\"session_start\", (_event, ctx) => {\n SESSION_ID = deriveSessionId(ctx);\n bridge(\"SessionStart\", { sessionId: SESSION_ID, projectDir: PROJECT_DIR });\n return undefined;\n });`);\n }\n\n if (has(\"PreToolUse\")) {\n handlers.push(` // PreToolUse → block via { block, reason }. OMP tool_call cannot mutate\n // args, so \"ask\" degrades to a block (the safe direction); \"modify\" degrades\n // to ALLOW (no-block), matching opencode/claude-code — only deny/ask block.\n pi.on(\"tool_call\", (event) => {\n const payload = {\n toolName: (event && event.toolName) || \"\",\n toolInput: (event && event.input) || {},\n sessionId: SESSION_ID,\n projectDir: PROJECT_DIR,\n };\n const res = bridge(\"PreToolUse\", payload);\n if (!res) return undefined;\n if (res.decision === \"deny\" || res.decision === \"ask\") {\n return { block: true, reason: res.reason || \"Blocked by ${ctx.connector.id}\" };\n }\n return undefined;\n });`);\n }\n\n if (has(\"PostToolUse\")) {\n handlers.push(` // PostToolUse → observe tool results (no output-rewrite surface upstream).\n pi.on(\"tool_result\", (event) => {\n const content = (event && Array.isArray(event.content)) ? event.content : [];\n const toolOutput = content\n .filter((c) => c && c.type === \"text\" && typeof c.text === \"string\")\n .map((c) => c.text)\n .join(\"\\\\n\");\n const payload = {\n toolName: (event && event.toolName) || \"\",\n toolInput: (event && event.input) || {},\n toolOutput,\n isError: !!(event && event.isError),\n sessionId: SESSION_ID,\n projectDir: PROJECT_DIR,\n };\n bridge(\"PostToolUse\", payload);\n return undefined;\n });`);\n }\n\n if (has(\"PreCompact\")) {\n handlers.push(` // PreCompact → notify before OMP compacts the context window.\n pi.on(\"session_before_compact\", () => {\n bridge(\"PreCompact\", { sessionId: SESSION_ID, projectDir: PROJECT_DIR });\n return undefined;\n });`);\n }\n\n const factory = `\nexport default function plugin(pi) {\n${handlers.join(\"\\n\\n\")}\n}\n`;\n\n return header + factory;\n }\n\n // ── Runtime: parse OUR bridge payload → normalized event ───────────────\n\n /**\n * `raw` is the payload OUR generated plugin posts (NOT a host-native shape):\n * { toolName?, toolInput?, toolOutput?, isError?, sessionId?, projectDir? }\n * so this maps straight through.\n */\n parseEvent(event: HookEventName, raw: unknown): NormalizedEvent {\n const input = (raw ?? {}) as OmpBridgePayload;\n const base = {\n hostPlatform: HOST,\n connectorId: \"\",\n sessionId: typeof input.sessionId === \"string\" ? input.sessionId : \"\",\n raw,\n ...(typeof input.projectDir === \"string\"\n ? { projectDir: input.projectDir }\n : {}),\n } as const;\n\n switch (event) {\n case \"PreToolUse\": {\n const ev: PreToolUseEvent = {\n ...base,\n toolName: input.toolName ?? \"\",\n toolInput: input.toolInput ?? {},\n };\n return ev;\n }\n case \"PostToolUse\": {\n const ev: PostToolUseEvent = {\n ...base,\n toolName: input.toolName ?? \"\",\n toolInput: input.toolInput ?? {},\n ...(typeof input.toolOutput === \"string\"\n ? { toolOutput: input.toolOutput }\n : {}),\n ...(typeof input.isError === \"boolean\"\n ? { isError: input.isError }\n : {}),\n };\n return ev;\n }\n case \"PreCompact\": {\n const ev: PreCompactEvent = { ...base };\n return ev;\n }\n case \"SessionStart\": {\n const ev: SessionStartEvent = { ...base, source: \"startup\" };\n return ev;\n }\n default:\n // Other canonical events are not surfaced by OMP; treat as a\n // session-start-shaped no-op so the dispatcher fails open gracefully.\n return { ...base, source: \"startup\" } satisfies SessionStartEvent;\n }\n }\n\n // ── Runtime: normalized response → reply the generated bridge parses ───\n\n /**\n * Unlike json-stdio hosts (whose reply is the host's NATIVE control payload),\n * OUR generated bridge consumes this stdout directly. So the reply body is the\n * NORMALIZED HookResponse itself — the bridge JSON.parses it and maps decision\n * → OMP's { block, reason } for tool_call (and ignores it otherwise).\n */\n formatReply(_event: HookEventName, response: HookResponse): HookReply {\n return {\n exitCode: 0,\n stdout: JSON.stringify(response ?? { decision: \"allow\" }),\n };\n }\n\n // ── Diagnostics ────────────────────────────────────────────────────────\n\n override getHealthChecks(ctx: InstallContext): readonly HealthCheck[] {\n const serverPath = this.getServerConfigPath(ctx);\n const entryPath = this.getHookConfigPath(ctx);\n const manifestPath = join(this.extensionDir(ctx), \"package.json\");\n const connectorId = ctx.connector.id;\n const hasHooks = ctx.connector.hookEvents.length > 0;\n\n return [\n {\n name: `${this.name}: mcp.json present`,\n check: () =>\n existsSync(serverPath)\n ? { status: \"OK\", detail: serverPath }\n : { status: \"FAIL\", detail: `not found: ${serverPath}` },\n },\n {\n name: `${this.name}: ${MCP_ROOT_KEY}.${connectorId} registered`,\n check: () => {\n if (!ctx.connector.server) {\n return { status: \"OK\", detail: \"no MCP server declared\" };\n }\n const cfg = this.readJson<{ [k: string]: Record<string, unknown> }>(\n serverPath,\n );\n const bucket = cfg?.[MCP_ROOT_KEY];\n if (!cfg || !bucket) {\n return {\n status: \"FAIL\",\n detail: `no ${MCP_ROOT_KEY} in ${serverPath}`,\n };\n }\n return connectorId in bucket\n ? { status: \"OK\", detail: `${MCP_ROOT_KEY}.${connectorId} present` }\n : {\n status: \"FAIL\",\n detail: `no ${MCP_ROOT_KEY}.${connectorId} in ${serverPath}`,\n };\n },\n },\n {\n name: `${this.name}: extension package present`,\n check: () => {\n if (!hasHooks) return { status: \"OK\", detail: \"no hooks declared\" };\n if (!existsSync(manifestPath)) {\n return { status: \"FAIL\", detail: `not found: ${manifestPath}` };\n }\n return existsSync(entryPath)\n ? { status: \"OK\", detail: entryPath }\n : { status: \"FAIL\", detail: `not found: ${entryPath}` };\n },\n },\n ];\n }\n\n /** Read a file, returning undefined on any error (idempotency compare). */\n private safeRead(path: string): string | undefined {\n try {\n return readFileSync(path, \"utf8\");\n } catch {\n return undefined;\n }\n }\n}\n\n/** Create a directory (recursive) if it does not already exist. */\nfunction ensureDir(dir: string): void {\n if (!existsSync(dir)) mkdirSync(dir, { recursive: true });\n}\n\nexport const adapter = new OMPAdapter();\nexport default adapter;\n"],"mappings":";;;;;;;;;;;;;;;;AAkDA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe;AACxB,SAAS,SAAS,YAAY;AAgC9B,IAAM,OAAmB;AACzB,IAAM,eAAe;AAOrB,IAAM,eAAuD;AAAA,EAC3D,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AACd;AAuBO,IAAM,aAAN,cAAyB,YAA+B;AAAA,EACpD,KAAiB;AAAA,EACjB,OAAO;AAAA,EACP,WAAyB;AAAA,EAEzB,eAAqC;AAAA;AAAA;AAAA,IAG5C,gBAAgB;AAAA,IAChB,YAAY;AAAA,IACZ,aAAa;AAAA;AAAA,IAEb,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,YAAY;AAAA,IACZ,kBAAkB;AAAA,IAClB,MAAM;AAAA,IACN,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAUd,eAAe;AAAA;AAAA,IAEf,iBAAiB;AAAA;AAAA,IAEjB,yBAAyB;AAAA;AAAA,IAEzB,YAAY,CAAC,SAAS,MAAM;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,WAAmB;AACzB,UAAM,WAAW,QAAQ,IAAI;AAC7B,WAAO,YAAY,aAAa,KAC5B,WACA,KAAK,QAAQ,GAAG,QAAQ,OAAO;AAAA,EACrC;AAAA,EAEA,aAAa,KAA6B;AACxC,WAAO,IAAI,UAAU,YACjB,KAAK,IAAI,YAAY,MAAM,IA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