@ken-jo/agent-connector 0.1.0
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/LICENSE +202 -0
- package/NOTICE +6 -0
- package/README.md +348 -0
- package/dist/amp-QSFH2V7Y.js +217 -0
- package/dist/amp-QSFH2V7Y.js.map +1 -0
- package/dist/amp-TULUPXXL.js +237 -0
- package/dist/amp-TULUPXXL.js.map +1 -0
- package/dist/antigravity-CX2YLSY7.js +17 -0
- package/dist/antigravity-CX2YLSY7.js.map +1 -0
- package/dist/antigravity-STHZWMP3.js +171 -0
- package/dist/antigravity-STHZWMP3.js.map +1 -0
- package/dist/antigravity-cli-P6HADOAO.js +121 -0
- package/dist/antigravity-cli-P6HADOAO.js.map +1 -0
- package/dist/antigravity-cli-YQDFVV4U.js +86 -0
- package/dist/antigravity-cli-YQDFVV4U.js.map +1 -0
- package/dist/chunk-54EMKTTX.js +191 -0
- package/dist/chunk-54EMKTTX.js.map +1 -0
- package/dist/chunk-7L6ITC4T.js +54 -0
- package/dist/chunk-7L6ITC4T.js.map +1 -0
- package/dist/chunk-7MSDGHJW.js +316 -0
- package/dist/chunk-7MSDGHJW.js.map +1 -0
- package/dist/chunk-BCHWFTV4.js +196 -0
- package/dist/chunk-BCHWFTV4.js.map +1 -0
- package/dist/chunk-DBQMX75U.js +36 -0
- package/dist/chunk-DBQMX75U.js.map +1 -0
- package/dist/chunk-EXLS7BSI.js +29 -0
- package/dist/chunk-EXLS7BSI.js.map +1 -0
- package/dist/chunk-JNM3TPLX.js +593 -0
- package/dist/chunk-JNM3TPLX.js.map +1 -0
- package/dist/chunk-JWNT5KW7.js +197 -0
- package/dist/chunk-JWNT5KW7.js.map +1 -0
- package/dist/chunk-KHO5WNTP.js +30 -0
- package/dist/chunk-KHO5WNTP.js.map +1 -0
- package/dist/chunk-LTT56GI3.js +155 -0
- package/dist/chunk-LTT56GI3.js.map +1 -0
- package/dist/chunk-MEH7GC7R.js +111 -0
- package/dist/chunk-MEH7GC7R.js.map +1 -0
- package/dist/chunk-MQPNU2CY.js +64 -0
- package/dist/chunk-MQPNU2CY.js.map +1 -0
- package/dist/chunk-OPXAP3AC.js +12 -0
- package/dist/chunk-OPXAP3AC.js.map +1 -0
- package/dist/chunk-RK6VBLXP.js +50 -0
- package/dist/chunk-RK6VBLXP.js.map +1 -0
- package/dist/chunk-TIIP3RG2.js +420 -0
- package/dist/chunk-TIIP3RG2.js.map +1 -0
- package/dist/chunk-TRKWUNO4.js +702 -0
- package/dist/chunk-TRKWUNO4.js.map +1 -0
- package/dist/chunk-TRQKHP7D.js +93 -0
- package/dist/chunk-TRQKHP7D.js.map +1 -0
- package/dist/chunk-WCETQWWK.js +59 -0
- package/dist/chunk-WCETQWWK.js.map +1 -0
- package/dist/chunk-WV63X7IK.js +357 -0
- package/dist/chunk-WV63X7IK.js.map +1 -0
- package/dist/chunk-XD7MY6HB.js +343 -0
- package/dist/chunk-XD7MY6HB.js.map +1 -0
- package/dist/chunk-XNAM7F35.js +276 -0
- package/dist/chunk-XNAM7F35.js.map +1 -0
- package/dist/chunk-XUCWLJY5.js +238 -0
- package/dist/chunk-XUCWLJY5.js.map +1 -0
- package/dist/chunk-YNZU6PAV.js +800 -0
- package/dist/chunk-YNZU6PAV.js.map +1 -0
- package/dist/chunk-YT43MUSJ.js +146 -0
- package/dist/chunk-YT43MUSJ.js.map +1 -0
- package/dist/claude-code-HKDV7T32.js +637 -0
- package/dist/claude-code-HKDV7T32.js.map +1 -0
- package/dist/claude-code-W74MNTAC.js +652 -0
- package/dist/claude-code-W74MNTAC.js.map +1 -0
- package/dist/cli/sdk.d.ts +54 -0
- package/dist/cli/sdk.js +82 -0
- package/dist/cli/sdk.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +15 -0
- package/dist/cli.js.map +1 -0
- package/dist/codebuff-3PMZJJHP.js +307 -0
- package/dist/codebuff-3PMZJJHP.js.map +1 -0
- package/dist/codebuff-QX57FJDN.js +220 -0
- package/dist/codebuff-QX57FJDN.js.map +1 -0
- package/dist/codex-JFQTS6LU.js +593 -0
- package/dist/codex-JFQTS6LU.js.map +1 -0
- package/dist/codex-Q3ATRRX3.js +364 -0
- package/dist/codex-Q3ATRRX3.js.map +1 -0
- package/dist/copilot-cli-MTCGHZ2T.js +622 -0
- package/dist/copilot-cli-MTCGHZ2T.js.map +1 -0
- package/dist/copilot-cli-SJGIXVSD.js +369 -0
- package/dist/copilot-cli-SJGIXVSD.js.map +1 -0
- package/dist/crush-I7PK3FGI.js +360 -0
- package/dist/crush-I7PK3FGI.js.map +1 -0
- package/dist/crush-LN5QFFR2.js +183 -0
- package/dist/crush-LN5QFFR2.js.map +1 -0
- package/dist/cursor-4TMXKJOZ.js +603 -0
- package/dist/cursor-4TMXKJOZ.js.map +1 -0
- package/dist/cursor-QZ6MTO74.js +194 -0
- package/dist/cursor-QZ6MTO74.js.map +1 -0
- package/dist/detect-WIAGVYS4.js +68 -0
- package/dist/detect-WIAGVYS4.js.map +1 -0
- package/dist/doctor-EZW2K4NI.js +372 -0
- package/dist/doctor-EZW2K4NI.js.map +1 -0
- package/dist/droid-KN6VRMMT.js +424 -0
- package/dist/droid-KN6VRMMT.js.map +1 -0
- package/dist/droid-W5WF5XEX.js +224 -0
- package/dist/droid-W5WF5XEX.js.map +1 -0
- package/dist/gemini-cli-CIRW37TU.js +369 -0
- package/dist/gemini-cli-CIRW37TU.js.map +1 -0
- package/dist/gemini-cli-Y35FFK4M.js +705 -0
- package/dist/gemini-cli-Y35FFK4M.js.map +1 -0
- package/dist/goose-A3M5GODH.js +212 -0
- package/dist/goose-A3M5GODH.js.map +1 -0
- package/dist/goose-ZTGTSUFJ.js +480 -0
- package/dist/goose-ZTGTSUFJ.js.map +1 -0
- package/dist/hermes-H2KV44GK.js +470 -0
- package/dist/hermes-H2KV44GK.js.map +1 -0
- package/dist/hermes-ZYLMOFLZ.js +196 -0
- package/dist/hermes-ZYLMOFLZ.js.map +1 -0
- package/dist/hook-YVDILAMZ.js +75 -0
- package/dist/hook-YVDILAMZ.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/install-HQRYZOQ2.js +60 -0
- package/dist/install-HQRYZOQ2.js.map +1 -0
- package/dist/jetbrains-copilot-HWA3DMH7.js +633 -0
- package/dist/jetbrains-copilot-HWA3DMH7.js.map +1 -0
- package/dist/kilo-NSWAVP6P.js +235 -0
- package/dist/kilo-NSWAVP6P.js.map +1 -0
- package/dist/kilo-QXJRCSLT.js +384 -0
- package/dist/kilo-QXJRCSLT.js.map +1 -0
- package/dist/kilo-cli-EAQTHXUW.js +587 -0
- package/dist/kilo-cli-EAQTHXUW.js.map +1 -0
- package/dist/kilo-cli-EVBKUODA.js +160 -0
- package/dist/kilo-cli-EVBKUODA.js.map +1 -0
- package/dist/kimi-EI3UM3ZV.js +155 -0
- package/dist/kimi-EI3UM3ZV.js.map +1 -0
- package/dist/kimi-GQ7VXNYT.js +423 -0
- package/dist/kimi-GQ7VXNYT.js.map +1 -0
- package/dist/kiro-UCLSLBW2.js +217 -0
- package/dist/kiro-UCLSLBW2.js.map +1 -0
- package/dist/kiro-VQTT6LO2.js +451 -0
- package/dist/kiro-VQTT6LO2.js.map +1 -0
- package/dist/leaderboard-K6ON3SWW.js +137 -0
- package/dist/leaderboard-K6ON3SWW.js.map +1 -0
- package/dist/mux-T2TV4CIQ.js +211 -0
- package/dist/mux-T2TV4CIQ.js.map +1 -0
- package/dist/mux-ZMLVAXOO.js +96 -0
- package/dist/mux-ZMLVAXOO.js.map +1 -0
- package/dist/omp-PB4VDKS6.js +586 -0
- package/dist/omp-PB4VDKS6.js.map +1 -0
- package/dist/openclaw-ETN2M63O.js +751 -0
- package/dist/openclaw-ETN2M63O.js.map +1 -0
- package/dist/openclaw-IYA7ASL6.js +150 -0
- package/dist/openclaw-IYA7ASL6.js.map +1 -0
- package/dist/opencode-FZ33JKUZ.js +734 -0
- package/dist/opencode-FZ33JKUZ.js.map +1 -0
- package/dist/opencode-HWT3RSMN.js +216 -0
- package/dist/opencode-HWT3RSMN.js.map +1 -0
- package/dist/package-DLOVE2E4.js +1132 -0
- package/dist/package-DLOVE2E4.js.map +1 -0
- package/dist/pi-CIU2QHT4.js +208 -0
- package/dist/pi-CIU2QHT4.js.map +1 -0
- package/dist/pi-UFX2OYFV.js +139 -0
- package/dist/pi-UFX2OYFV.js.map +1 -0
- package/dist/qwen-code-5POCNU6P.js +573 -0
- package/dist/qwen-code-5POCNU6P.js.map +1 -0
- package/dist/qwen-code-W7NUCDEN.js +134 -0
- package/dist/qwen-code-W7NUCDEN.js.map +1 -0
- package/dist/roo-code-IOIUXRDE.js +242 -0
- package/dist/roo-code-IOIUXRDE.js.map +1 -0
- package/dist/roo-code-ZLKH4A7N.js +229 -0
- package/dist/roo-code-ZLKH4A7N.js.map +1 -0
- package/dist/runtime/index.d.ts +157 -0
- package/dist/runtime/index.js +20 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/serve-HVWWY4B6.js +65 -0
- package/dist/serve-HVWWY4B6.js.map +1 -0
- package/dist/status-FE7TECZD.js +128 -0
- package/dist/status-FE7TECZD.js.map +1 -0
- package/dist/synthetic-UKR6SMGS.js +178 -0
- package/dist/synthetic-UKR6SMGS.js.map +1 -0
- package/dist/telemetry-36GESKQQ.js +349 -0
- package/dist/telemetry-36GESKQQ.js.map +1 -0
- package/dist/trae-JSNDZFKL.js +204 -0
- package/dist/trae-JSNDZFKL.js.map +1 -0
- package/dist/trae-PA26DPBW.js +157 -0
- package/dist/trae-PA26DPBW.js.map +1 -0
- package/dist/types-CYUB1OTr.d.ts +427 -0
- package/dist/uninstall-IGCKNOSF.js +72 -0
- package/dist/uninstall-IGCKNOSF.js.map +1 -0
- package/dist/upgrade-JV2VK242.js +104 -0
- package/dist/upgrade-JV2VK242.js.map +1 -0
- package/dist/usage-6ER6EMEY.js +324 -0
- package/dist/usage-6ER6EMEY.js.map +1 -0
- package/dist/usage-event-JKBI6XCF.js +48 -0
- package/dist/usage-event-JKBI6XCF.js.map +1 -0
- package/dist/vscode-copilot-CK3NO54M.js +715 -0
- package/dist/vscode-copilot-CK3NO54M.js.map +1 -0
- package/dist/warp-JNQA7PBU.js +126 -0
- package/dist/warp-JNQA7PBU.js.map +1 -0
- package/dist/warp-QNVDXOG4.js +199 -0
- package/dist/warp-QNVDXOG4.js.map +1 -0
- package/dist/zed-NNNX5MNT.js +272 -0
- package/dist/zed-NNNX5MNT.js.map +1 -0
- package/dist/zed-VRJKWYUR.js +209 -0
- package/dist/zed-VRJKWYUR.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapters/antigravity/index.ts"],"sourcesContent":["/**\n * adapters/antigravity — Google Antigravity (IDE) platform adapter.\n *\n * Antigravity is a Gemini-family host that, as of the 2.0 line, exposes a real\n * lifecycle-hook system on top of MCP — so this adapter is `json-stdio` (not the\n * old `mcp-only` framing): the host pipes a JSON payload to a hook command on\n * stdin and reads a JSON control object back, the same paradigm as Claude Code /\n * Gemini CLI. It installs the MCP server, lifecycle hooks, slash-command\n * Workflows, and Agent Skills.\n *\n * CONFIRMED-BY-INSTALL (2026-06-03, docs/research/antigravity-paths-confirmed.md):\n * a real machine with Antigravity IDE + `agy` CLI v1.0.0 shows the canonical user\n * customization root is `~/.gemini/antigravity/` — `~/.gemini/antigravity/mcp_config.json`\n * EXISTS and `~/.gemini/config/mcp_config.json` does NOT. So the fresh-install\n * default user MCP path is `~/.gemini/antigravity/mcp_config.json` (candidate[0]);\n * the `config/` and `antigravity-cli/` paths remain probed fallbacks only (honored\n * when a pre-existing config is found there, never the fresh default).\n *\n * STILL MEDIUM-CONFIDENCE / PATH-PROBING: hooks.json and the global skills dir were\n * NOT present on the observed install, so those locations stay corroborated-but-not-\n * byte-verified. Every user-scope path is PROBED at runtime — prefer a candidate\n * that already exists on disk, else fall back to the canonical path — and the doctor\n * flags each probed path with \"verify for your Antigravity version.\" We NEVER\n * hard-code a single guessed path, and any unsupported event or surface warn-skips\n * (never throws) at install time.\n *\n * Native config formats:\n * - MCP config (JSONC; we WRITE plain JSON), root key \"mcpServers\". stdio is\n * `{ command, args, env }`; a remote server is `{ serverUrl, headers }`\n * (NOTE: the key is `serverUrl`, NOT `url` and NOT Gemini CLI's `httpUrl`).\n * user scope → prefer existing of:\n * ~/.gemini/antigravity/mcp_config.json (CONFIRMED canonical)\n * ~/.gemini/config/mcp_config.json (probed fallback)\n * ~/.gemini/antigravity-cli/mcp_config.json (probed fallback)\n * else default to candidate[0] (antigravity/).\n * project scope → <projectDir>/.agents/mcp_config.json\n * - Hooks: a SEPARATE hooks.json in the customization dir (NOT the mcp_config),\n * project → <projectDir>/.agents/hooks.json\n * user → <resolvedUserConfigDir>/hooks.json\n * Shape: { hooks: { <Event>: [ { matcher, hooks:[{ type:\"command\", command }] } ] } }.\n * Supported events: PreToolUse, PostToolUse, SessionStart, Stop. All other\n * normalized events warn-skip. I/O fields are camelCase (see parse/format).\n * - Commands = \"Workflows\": markdown `.md` (body = the prompt; an optional\n * leading description line). Project prefer existing <proj>/.agent/workflows\n * or <proj>/.agents/workflows (default .agent/workflows per launch docs);\n * user ~/.gemini/antigravity/global_workflows.\n * - Skills = Agent Skills (uniform SKILL.md). Project\n * <proj>/.agents/skills/<name>/SKILL.md; user PROBE\n * ~/.gemini/antigravity-cli/skills then ~/.gemini/skills (NEVER\n * ~/.gemini/antigravity/skills — reportedly broken). NOTE: the global skills\n * dir was NOT present on the confirmed install, so it stays medium-confidence\n * + doctor \"verify for your version.\"\n * - Subagents: declarative subagents exist only inside a plugin bundle, which\n * agent-connector does not emit; supportsSubagents is false and the\n * BaseAdapter skip/warn default applies.\n *\n * Env handling: Antigravity (Gemini family) documents no `${env:VAR}` token of\n * the framework's syntax, so env/header/url refs are resolved to literals at\n * install time via resolveEnvRefsDeep — the safe default matching the Gemini CLI\n * adapter.\n */\n\nimport { existsSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nimport { BaseAdapter } from \"../base.js\";\nimport type { Adapter, HookReply, InstallContext, NormalizedEvent } 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 StopEvent,\n Transport,\n} from \"../../core/types.js\";\nimport { resolveEnvRefsDeep } from \"../../core/interpolate.js\";\nimport {\n buildHomeBinHookCommand,\n buildServeWrapperCommand,\n buildUsageEventCommand,\n isHomeBinHookCommand,\n isHostNativeUsageEnabled,\n isUsageEventCommand,\n shouldWrapForTelemetry,\n} from \"../../core/spawn.js\";\n\nconst HOST: PlatformId = \"antigravity\";\nconst MCP_ROOT_KEY = \"mcpServers\";\n\n/**\n * Known user-scope MCP config candidates, in preference order. We pick the first\n * that already exists on disk; otherwise we default to candidate[0]\n * (~/.gemini/antigravity/mcp_config.json — CONFIRMED canonical on a real install:\n * docs/research/antigravity-paths-confirmed.md). The `config/` and CLI-only\n * `antigravity-cli/` paths are kept ONLY as probed fallbacks so a pre-existing\n * config in either is still honored, but neither is ever the fresh-install default.\n */\nconst USER_CONFIG_CANDIDATES = [\n [\".gemini\", \"antigravity\", \"mcp_config.json\"],\n [\".gemini\", \"config\", \"mcp_config.json\"],\n [\".gemini\", \"antigravity-cli\", \"mcp_config.json\"],\n] as const;\n\n/**\n * Antigravity's supported lifecycle hook events. These happen to share the\n * normalized PascalCase names 1:1; everything else has no Antigravity equivalent\n * and is reported as a warn/skip at install time.\n */\nconst SUPPORTED_EVENTS: ReadonlySet<HookEventName> = new Set<HookEventName>([\n \"PreToolUse\",\n \"PostToolUse\",\n \"SessionStart\",\n \"Stop\",\n]);\n\n/**\n * Native hooks.json key for the OPT-IN host-native turn-usage hook (enricher 4a).\n * Antigravity shares the Gemini-family `AfterModel` model-turn hook, whose payload\n * carries `usageMetadata`. This is a host-native-only sink (no connector handler);\n * it is installed ONLY when host-native capture is enabled and records a DISTINCT\n * `model_turn` telemetry row that is never summed with the per-MCP `serve` rows.\n */\nconst USAGE_HOOK_EVENT = \"AfterModel\";\n\n/** A single Antigravity native hook registration entry (nested, Claude-shaped). */\ninterface AntigravityHookEntry {\n matcher: string;\n hooks: Array<{ type: \"command\"; command: string }>;\n}\n\n/** The shape of Antigravity's hooks.json (only the parts we touch). */\ninterface AntigravityHooksFile {\n hooks?: Record<string, AntigravityHookEntry[]>;\n [key: string]: unknown;\n}\n\n/**\n * Native MCP server entry shapes Antigravity accepts under `mcpServers`.\n * A stdio server is `{ command, args, env }`; a remote server is\n * `{ serverUrl, headers }` — the key is `serverUrl` (NOT `url`).\n */\ninterface AntigravityStdioServer {\n command: string;\n args?: string[];\n env?: Record<string, string>;\n}\ninterface AntigravityHttpServer {\n serverUrl: string;\n headers?: Record<string, string>;\n}\n\n/** Raw Antigravity hook stdin payload (camelCase wire fields). */\ninterface AntigravityWireInput {\n connector?: unknown;\n toolName?: string;\n toolInput?: Record<string, unknown>;\n toolOutput?: string;\n isError?: boolean;\n sessionId?: string;\n cwd?: string;\n source?: string;\n reason?: string;\n stopHookActive?: boolean;\n}\n\nexport class AntigravityAdapter extends BaseAdapter implements Adapter {\n readonly id: PlatformId = HOST;\n readonly name: string = \"Google Antigravity\";\n readonly paradigm: HookParadigm = \"json-stdio\";\n\n readonly capabilities: PlatformCapabilities = {\n // Antigravity 2.0 fires PreToolUse / PostToolUse / SessionStart / Stop.\n preToolUse: true,\n postToolUse: true,\n sessionStart: true,\n stop: true,\n // No documented equivalents — kept false; the corresponding normalized\n // events warn-skip at install time.\n preCompact: false,\n sessionEnd: false,\n userPromptSubmit: false,\n notification: false,\n // Transform-category hooks can rewrite tool input and tool output; the\n // SessionStart hook can inject additional context.\n canModifyArgs: true,\n canModifyOutput: true,\n canInjectSessionContext: true,\n // Antigravity registers stdio, SSE, and Streamable HTTP MCP servers.\n transports: [\"stdio\", \"sse\", \"http\"],\n // Content surfaces: Workflows (markdown commands) + Agent Skills (SKILL.md).\n // Declarative subagents exist only inside a plugin bundle (not emitted), so\n // subagents are unsupported and inherit the BaseAdapter skip/warn default.\n supportsCommands: true,\n supportsSkills: true,\n supportsSubagents: false,\n };\n\n // ── Detection ────────────────────────────────────────────────────────────\n\n detectInstalled(projectDir: string): DetectedPlatform {\n const userConfig = this.resolveUserConfigPath();\n const userDir = join(homedir(), \".gemini\");\n const projectConfig = join(projectDir, \".agents\", \"mcp_config.json\");\n\n const userInstalled =\n existsSync(userDir) ||\n this.userConfigCandidates().some((parts) => existsSync(join(homedir(), ...parts)));\n const projInstalled = existsSync(projectConfig);\n const installed = userInstalled || projInstalled;\n\n // Report the scope/path that actually matched, so a project-only install\n // isn't 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 Antigravity config at ${projectConfig}`\n : `found Antigravity config under ${userDir}`\n : `no Antigravity config at ${userDir} or ${projectConfig}`,\n confidence: installed ? \"high\" : \"low\",\n };\n }\n\n // ── Native paths ─────────────────────────────────────────────────────────\n\n getConfigDir(ctx: InstallContext): string {\n if (ctx.scope === \"project\") return join(ctx.projectDir, \".agents\");\n // User scope: parent dir of the resolved user mcp_config.json.\n return dirname(this.resolveUserConfigPath());\n }\n\n getServerConfigPath(ctx: InstallContext): string {\n return ctx.scope === \"project\"\n ? join(ctx.projectDir, \".agents\", \"mcp_config.json\")\n : this.resolveUserConfigPath();\n }\n\n /**\n * Hooks live in a SEPARATE hooks.json in the customization dir — NOT the\n * mcp_config.json. Project → <proj>/.agents/hooks.json; user →\n * <resolvedUserConfigDir>/hooks.json (the dir holding the resolved user MCP\n * config). Path is medium-confidence and surfaced by the doctor.\n */\n getHookConfigPath(ctx: InstallContext): string {\n return join(this.getConfigDir(ctx), \"hooks.json\");\n }\n\n /**\n * The user-scope MCP config candidates, in preference order. Overridable by\n * forks (e.g. the Antigravity CLI) that resolve a different user-scope root\n * while reusing resolveUserConfigPath's prefer-existing-else-candidate[0] logic.\n */\n protected userConfigCandidates(): ReadonlyArray<readonly string[]> {\n return USER_CONFIG_CANDIDATES;\n }\n\n /**\n * Pick the user-scope mcp_config.json: prefer a candidate that already exists,\n * else default to candidate[0] (the CONFIRMED canonical ~/.gemini/antigravity path).\n */\n protected resolveUserConfigPath(): string {\n const home = homedir();\n const candidates = this.userConfigCandidates();\n for (const parts of candidates) {\n const p = join(home, ...parts);\n if (existsSync(p)) return p;\n }\n const fallback = candidates[0];\n if (fallback === undefined) {\n // Defensive: a non-empty candidate list is an invariant, but never throw.\n return join(home, \".gemini\", \"antigravity\", \"mcp_config.json\");\n }\n return join(home, ...fallback);\n }\n\n /**\n * Resolve the Workflows (slash-command) dir, prefer-existing-else-canonical.\n * project → prefer existing <proj>/.agent/workflows or <proj>/.agents/workflows;\n * default .agent/workflows (launch-era singular `.agent`).\n * user → ~/.gemini/antigravity/global_workflows.\n */\n protected resolveWorkflowsDir(ctx: InstallContext): string {\n if (ctx.scope === \"project\") {\n const singular = join(ctx.projectDir, \".agent\", \"workflows\");\n const plural = join(ctx.projectDir, \".agents\", \"workflows\");\n if (existsSync(singular)) return singular;\n if (existsSync(plural)) return plural;\n return singular;\n }\n return join(homedir(), \".gemini\", \"antigravity\", \"global_workflows\");\n }\n\n /**\n * Resolve the Agent Skills dir, prefer-existing-else-canonical.\n * project → <proj>/.agents/skills (plural — matches mcp/skills convention).\n * user → prefer existing ~/.gemini/antigravity-cli/skills, else\n * ~/.gemini/skills. NEVER ~/.gemini/antigravity/skills\n * (reportedly broken), so it is not a candidate.\n */\n protected resolveSkillsDir(ctx: InstallContext): string {\n if (ctx.scope === \"project\") {\n return join(ctx.projectDir, \".agents\", \"skills\");\n }\n const home = homedir();\n const cliSkills = join(home, \".gemini\", \"antigravity-cli\", \"skills\");\n const sharedSkills = join(home, \".gemini\", \"skills\");\n if (existsSync(cliSkills)) return cliSkills;\n if (existsSync(sharedSkills)) return sharedSkills;\n return cliSkills;\n }\n\n // ── MCP server install / uninstall ───────────────────────────────────────\n\n installServer(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n const override = connector.platforms[this.id]?.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 ${this.id}`\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 /** Render a normalized ServerDef into Antigravity's native mcpServers entry. */\n private renderServerEntry(\n ctx: InstallContext,\n server: ServerDef,\n ): AntigravityStdioServer | AntigravityHttpServer {\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> --scope <scope> -- <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 // Antigravity (Gemini family) has no documented native interpolation token,\n // so resolve every ${env:VAR} to a literal at install time.\n const entry: AntigravityStdioServer = { command: resolveEnvRefsDeep(command) };\n if (args.length > 0) entry.args = resolveEnvRefsDeep(args);\n const env = this.renderEnv(server.env);\n if (env) entry.env = env;\n return entry;\n }\n\n // sse / http (and any other remote transport) — Antigravity registers a URL\n // under the `serverUrl` key (NOT `url`).\n const entry: AntigravityHttpServer = { serverUrl: resolveEnvRefsDeep(server.url ?? \"\") };\n const headers = this.renderEnv(server.headers);\n if (headers) entry.headers = headers;\n return entry;\n }\n\n /**\n * Render env/header values. Antigravity documents no native interpolation\n * token, so resolve `${env:VAR}` references to literals at install time.\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 ─────────────────────────────────────────────\n\n installHooks(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.platforms[this.id]?.hooks === false) {\n return [{ platform: this.id, action: \"skip\", detail: `hooks disabled for ${this.id}` }];\n }\n // The opt-in host-native usage hook (4a) needs no connector handler, so it may\n // be installed even when the connector declares no normalized hook events.\n const hostNative = isHostNativeUsageEnabled(connector.telemetry);\n if (connector.hookEvents.length === 0 && !hostNative) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no hooks\" }];\n }\n\n const hooksPath = this.getHookConfigPath(ctx);\n // OVERWRITE GUARD: never clobber a present-but-unparseable hooks.json.\n if (this.isPresentButUnparseable(hooksPath)) {\n return [\n {\n platform: this.id,\n action: \"warn\",\n path: hooksPath,\n detail: `existing ${hooksPath} is not parseable; left untouched (back it up / fix it, then re-run)`,\n },\n ];\n }\n\n const file = this.readJson<AntigravityHooksFile>(hooksPath) ?? {};\n const hooks = (file.hooks ??= {});\n\n const changes: ChangeRecord[] = [];\n let mutated = false;\n\n for (const event of connector.hookEvents) {\n if (!SUPPORTED_EVENTS.has(event)) {\n // No Antigravity equivalent for this normalized event — report.\n changes.push({\n platform: this.id,\n action: \"warn\",\n path: hooksPath,\n detail: `${event} has no Antigravity hook equivalent — skipped`,\n });\n continue;\n }\n\n const command = buildHomeBinHookCommand(ctx.homeBinPath, this.id, event, connector.id);\n const matcher = connector.hooks[event]?.matcher ?? \"\";\n const entry: AntigravityHookEntry = {\n matcher,\n hooks: [{ type: \"command\", command }],\n };\n\n const bucket = (hooks[event] ??= []);\n const existingIdx = bucket.findIndex((e) => this.entryHasOurCommand(e, ctx));\n\n if (existingIdx >= 0) {\n if (JSON.stringify(bucket[existingIdx]) === JSON.stringify(entry)) {\n changes.push({\n platform: this.id,\n action: \"skip\",\n path: hooksPath,\n detail: `hooks.${event} already registered`,\n });\n continue;\n }\n bucket[existingIdx] = entry;\n changes.push({\n platform: this.id,\n action: \"update\",\n path: hooksPath,\n detail: `hooks.${event}`,\n });\n } else {\n bucket.push(entry);\n changes.push({\n platform: this.id,\n action: \"create\",\n path: hooksPath,\n detail: `hooks.${event}`,\n });\n }\n mutated = true;\n }\n\n // OPT-IN host-native usage hook (4a): register the AfterModel `usage-event`\n // sink when enabled. Records a DISTINCT `model_turn` row (whole-conversation),\n // never summed with the per-MCP `serve`-proxy rows.\n if (hostNative) {\n if (this.installUsageHook(hooks, ctx, hooksPath, changes)) mutated = true;\n }\n\n if (mutated) this.writeJson(hooksPath, file, ctx.dryRun);\n return changes;\n }\n\n /**\n * Register the opt-in AfterModel host-native usage hook (4a) into `hooks`.\n * Idempotent (byte-identical → skip, drift → update); returns true on mutation.\n * The command is the hidden `usage-event` entrypoint (NOT a connector hook), so\n * it carries an empty matcher. Reads `this.id` so the CLI fork installs its own\n * `usage-event antigravity-cli …` variant.\n */\n private installUsageHook(\n hooks: Record<string, AntigravityHookEntry[]>,\n ctx: InstallContext,\n hooksPath: string,\n changes: ChangeRecord[],\n ): boolean {\n const command = buildUsageEventCommand(ctx.homeBinPath, this.id, ctx.connector.id);\n const entry: AntigravityHookEntry = {\n matcher: \"\",\n hooks: [{ type: \"command\", command }],\n };\n const bucket = (hooks[USAGE_HOOK_EVENT] ??= []);\n const existingIdx = bucket.findIndex((e) =>\n (e.hooks ?? []).some((h) => isUsageEventCommand(h.command, ctx.homeBinPath, ctx.connector.id)),\n );\n\n if (existingIdx >= 0) {\n if (JSON.stringify(bucket[existingIdx]) === JSON.stringify(entry)) {\n changes.push({\n platform: this.id,\n action: \"skip\",\n path: hooksPath,\n detail: `hooks.${USAGE_HOOK_EVENT} (host-native usage) already registered`,\n });\n return false;\n }\n bucket[existingIdx] = entry;\n changes.push({\n platform: this.id,\n action: \"update\",\n path: hooksPath,\n detail: `hooks.${USAGE_HOOK_EVENT} (host-native usage)`,\n });\n } else {\n bucket.push(entry);\n changes.push({\n platform: this.id,\n action: \"create\",\n path: hooksPath,\n detail: `hooks.${USAGE_HOOK_EVENT} (host-native usage)`,\n });\n }\n return true;\n }\n\n uninstallHooks(ctx: InstallContext): ChangeRecord[] {\n const hooksPath = this.getHookConfigPath(ctx);\n const file = this.readJson<AntigravityHooksFile>(hooksPath);\n const hooks = file?.hooks;\n if (!file || !hooks) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n path: hooksPath,\n detail: \"no hooks section present\",\n },\n ];\n }\n\n const changes: ChangeRecord[] = [];\n let mutated = false;\n\n for (const event of Object.keys(hooks)) {\n const bucket = hooks[event];\n if (!Array.isArray(bucket)) continue;\n\n // Strip our hook command from each entry; drop entries left empty so we\n // never remove another connector's (or the user's own) hook commands.\n const next: AntigravityHookEntry[] = [];\n let removed = 0;\n for (const e of bucket) {\n const innerBefore = e.hooks?.length ?? 0;\n const inner = (e.hooks ?? []).filter((h) => !this.isOurCommand(h.command, ctx));\n removed += innerBefore - inner.length;\n if (inner.length > 0) next.push({ matcher: e.matcher ?? \"\", hooks: inner });\n }\n\n if (removed > 0) {\n if (next.length > 0) hooks[event] = next;\n else delete hooks[event];\n changes.push({\n platform: this.id,\n action: \"remove\",\n path: hooksPath,\n detail: `hooks.${event} (${removed})`,\n });\n mutated = true;\n }\n }\n\n if (mutated) this.writeJson(hooksPath, file, ctx.dryRun);\n if (changes.length === 0) {\n changes.push({\n platform: this.id,\n action: \"skip\",\n path: hooksPath,\n detail: \"no matching hook entries\",\n });\n }\n return changes;\n }\n\n private entryHasOurCommand(entry: AntigravityHookEntry, ctx: InstallContext): boolean {\n return (entry.hooks ?? []).some((h) => this.isOurCommand(h.command, ctx));\n }\n\n /**\n * True when a hook command is ONE OF OURS for this connector — the universal\n * `hook` dispatcher OR the opt-in `usage-event` sink. Both are anchored on the\n * connector id (see isHomeBinHookCommand) so a shared-prefix id can't collide,\n * and so uninstall reverses the AfterModel usage hook too.\n */\n private isOurCommand(command: string | undefined, ctx: InstallContext): boolean {\n return (\n isHomeBinHookCommand(command, ctx.homeBinPath, ctx.connector.id) ||\n isUsageEventCommand(command, ctx.homeBinPath, ctx.connector.id)\n );\n }\n\n // ── Content surfaces: commands (Workflows) / skills ───────────────────────\n // CONTENT-ONLY: pure native-file writers under the probed workflows / skills\n // dirs. No runtime dispatch, no home-bin pointer, no telemetry wrap. Each\n // method is idempotent (byte-identical → skip) via BaseAdapter.writeContentFile\n // and reversible via removeContentFile. Honors platforms[\"antigravity\"]\n // per-surface false to skip. Commands are markdown Workflows (NOT TOML, unlike\n // gemini-cli); skills are the uniform Claude-compatible SKILL.md. Subagents are\n // unsupported (plugin-bundle-only) and inherit the BaseAdapter skip/warn.\n\n /** Native Workflow file path: <workflowsDir>/<name>.md. */\n private commandPath(ctx: InstallContext, name: string): string {\n return join(this.resolveWorkflowsDir(ctx), `${name}.md`);\n }\n /** Native skill dir: <skillsDir>/<name>. */\n private skillDir(ctx: InstallContext, name: string): string {\n return join(this.resolveSkillsDir(ctx), name);\n }\n\n // ── Commands (Workflows) ──────────────────────────────────────────────────\n\n override installCommands(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.platforms[this.id]?.commands === false) {\n return [{ platform: this.id, action: \"skip\", detail: `commands disabled for ${this.id}` }];\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(this.commandPath(ctx, cmd.name), this.renderCommand(cmd), ctx.dryRun),\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 /**\n * Render a command to an Antigravity Workflow: a plain markdown `.md` whose\n * body is the command prompt, optionally preceded by a leading description\n * line. No frontmatter / TOML (unlike gemini-cli).\n */\n private renderCommand(cmd: CommandDef): string {\n const body = cmd.prompt.endsWith(\"\\n\") ? cmd.prompt : `${cmd.prompt}\\n`;\n if (cmd.description !== undefined && cmd.description !== \"\") {\n return `${cmd.description}\\n\\n${body}`;\n }\n return body;\n }\n\n // ── Skills ────────────────────────────────────────────────────────────────\n\n override installSkills(ctx: InstallContext): ChangeRecord[] {\n const { connector } = ctx;\n if (connector.platforms[this.id]?.skills === false) {\n return [{ platform: this.id, action: \"skip\", detail: `skills disabled for ${this.id}` }];\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 // Defense-in-depth: skip+warn on any key that escapes the skill dir.\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 // Remove only the files we wrote (SKILL.md + declared resources), then the\n // skill dir itself when we own its full contents.\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; // never delete outside the skill dir\n changes.push(this.removeContentFile(target, ctx.dryRun));\n }\n // Only remove the skill dir when WE own its full contents — never rm -rf a\n // dir that still holds user-added / sibling-tool / shared files.\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) + body. Uniform across platforms.\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 // ── Diagnostics ──────────────────────────────────────────────────────────\n\n override getHealthChecks(ctx: InstallContext): readonly HealthCheck[] {\n const mcpPath = this.getServerConfigPath(ctx);\n const hooksPath = this.getHookConfigPath(ctx);\n const connectorId = ctx.connector.id;\n const homeBin = ctx.homeBinPath;\n const hookEvents = ctx.connector.hookEvents;\n const workflowsDir = this.resolveWorkflowsDir(ctx);\n const skillsDir = this.resolveSkillsDir(ctx);\n\n const checks: HealthCheck[] = [\n {\n name: `${this.name}: mcp_config.json present`,\n check: () =>\n existsSync(mcpPath)\n ? { status: \"OK\", detail: `${mcpPath} (path probed; verify for your Antigravity version)` }\n : { status: \"FAIL\", detail: `not found: ${mcpPath} (path probed; verify for your Antigravity version)` },\n },\n {\n name: `${this.name}: server entry registered`,\n check: () => {\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}: hooks.json hook command registered`,\n check: () => {\n if (hookEvents.length === 0) {\n return { status: \"OK\", detail: \"no hooks declared\" };\n }\n const file = this.readJson<AntigravityHooksFile>(hooksPath);\n if (!file) {\n return {\n status: \"FAIL\",\n detail: `not found: ${hooksPath} (path probed; verify for your Antigravity version)`,\n };\n }\n const hooks = file.hooks ?? {};\n const registered = Object.values(hooks).some((entries) =>\n (entries ?? []).some((e) =>\n (e.hooks ?? []).some((h) =>\n isHomeBinHookCommand(h.command, homeBin, connectorId),\n ),\n ),\n );\n return registered\n ? { status: \"OK\", detail: `hook command present in ${hooksPath}` }\n : { status: \"FAIL\", detail: `no hook for ${connectorId} in ${hooksPath}` };\n },\n },\n ];\n\n // Content-surface checks: only assert presence of the files this connector\n // declares (skip silently for surfaces it never asked for). The probed dirs\n // are noted so doctor output makes the medium-confidence path explicit.\n for (const cmd of ctx.connector.commands) {\n const p = join(workflowsDir, `${cmd.name}.md`);\n checks.push({\n name: `${this.name}: workflow ${cmd.name} present`,\n check: () =>\n existsSync(p)\n ? { status: \"OK\", detail: `${p} (workflows dir probed; verify for your version)` }\n : { status: \"FAIL\", detail: `not found: ${p} (workflows dir probed; verify for your version)` },\n });\n }\n for (const skill of ctx.connector.skills) {\n const p = join(skillsDir, skill.name, \"SKILL.md\");\n checks.push({\n name: `${this.name}: skill ${skill.name} present`,\n check: () =>\n existsSync(p)\n ? { status: \"OK\", detail: `${p} (skills dir probed; verify for your version)` }\n : { status: \"FAIL\", detail: `not found: ${p} (skills dir probed; verify for your version)` },\n });\n }\n return checks;\n }\n\n // ── Runtime: parse Antigravity stdin JSON → normalized event ──────────────\n\n parseEvent(event: HookEventName, raw: unknown): NormalizedEvent {\n const input = (raw ?? {}) as AntigravityWireInput;\n const connectorId = typeof input.connector === \"string\" ? input.connector : \"\";\n const sessionId = typeof input.sessionId === \"string\" ? input.sessionId : \"\";\n const projectDir = typeof input.cwd === \"string\" ? input.cwd : undefined;\n\n const base = {\n hostPlatform: this.id,\n connectorId,\n sessionId,\n raw,\n ...(projectDir !== undefined ? { 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 ...(input.toolOutput !== undefined ? { toolOutput: input.toolOutput } : {}),\n ...(input.isError === true ? { isError: true } : {}),\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 \"Stop\": {\n const ev: StopEvent = {\n ...base,\n ...(typeof input.stopHookActive === \"boolean\"\n ? { stopHookActive: input.stopHookActive }\n : {}),\n };\n return ev;\n }\n default: {\n // Antigravity only delivers the four SUPPORTED_EVENTS. If the runtime\n // dispatches anything else, surface it loudly rather than mis-parse.\n throw new Error(`unsupported ${this.id} hook event: ${String(event)}`);\n }\n }\n }\n\n // ── Runtime: normalized response → Antigravity native hook reply ──────────\n\n formatReply(event: HookEventName, response: HookResponse): HookReply {\n const decision = response.decision ?? \"allow\";\n\n // deny → Antigravity blocks the action via a top-level `decision:\"deny\"` +\n // reason (the Decide category).\n if (decision === \"deny\") {\n return this.stdout({\n decision: \"deny\",\n reason: response.reason ?? \"Blocked by hook\",\n });\n }\n\n // ask → Antigravity has no native \"ask\"; degrade to deny to stay fail-safe.\n if (decision === \"ask\") {\n return this.stdout({\n decision: \"deny\",\n reason: response.reason ?? \"Action requires user confirmation (security policy)\",\n });\n }\n\n // modify → Transform category. camelCase: rewrite PreToolUse input via\n // updatedInput; rewrite PostToolUse output via updatedOutput.\n if (decision === \"modify\") {\n if (event === \"PreToolUse\" && response.updatedInput) {\n return this.stdout({ updatedInput: response.updatedInput });\n }\n if (event === \"PostToolUse\" && response.updatedOutput !== undefined) {\n return this.stdout({ updatedOutput: response.updatedOutput });\n }\n // Nothing to apply; fall through to allow.\n }\n\n // context → inject soft guidance via additionalContext (the SessionStart\n // context-injection path).\n if (decision === \"context\" && response.additionalContext) {\n return this.stdout({ additionalContext: response.additionalContext });\n }\n\n // allow / void / unsupported-degradation → pass through with exit 0.\n return { exitCode: 0 };\n }\n\n private stdout(payload: unknown): HookReply {\n return { exitCode: 0, stdout: JSON.stringify(payload) };\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 AntigravityAdapter();\nexport default adapter;\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8DA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AACxB,SAAS,SAAS,YAAY;AAiC9B,IAAM,OAAmB;AACzB,IAAM,eAAe;AAUrB,IAAM,yBAAyB;AAAA,EAC7B,CAAC,WAAW,eAAe,iBAAiB;AAAA,EAC5C,CAAC,WAAW,UAAU,iBAAiB;AAAA,EACvC,CAAC,WAAW,mBAAmB,iBAAiB;AAClD;AAOA,IAAM,m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UAAU,GAAG,QAAQ,KAAK,UAAU,OAAO,EAAE;AAAA,EACxD;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,mBAAmB;AAC9C,IAAO,sBAAQ;","names":["entry"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/core/paths.ts
|
|
4
|
+
import { createHash } from "crypto";
|
|
5
|
+
import {
|
|
6
|
+
chmodSync,
|
|
7
|
+
existsSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
readFileSync,
|
|
10
|
+
writeFileSync
|
|
11
|
+
} from "fs";
|
|
12
|
+
import { homedir } from "os";
|
|
13
|
+
import { basename, join, resolve } from "path";
|
|
14
|
+
function dataRoot() {
|
|
15
|
+
const override = process.env.AGENT_CONNECTOR_DATA_DIR;
|
|
16
|
+
if (override && override.trim() !== "") return resolve(override);
|
|
17
|
+
return join(homedir(), ".agent-connector");
|
|
18
|
+
}
|
|
19
|
+
function connectorsDir() {
|
|
20
|
+
return join(dataRoot(), "connectors");
|
|
21
|
+
}
|
|
22
|
+
function connectorDir(id) {
|
|
23
|
+
return join(connectorsDir(), id);
|
|
24
|
+
}
|
|
25
|
+
function backupsDir() {
|
|
26
|
+
return join(dataRoot(), "backups");
|
|
27
|
+
}
|
|
28
|
+
function telemetryPath(store = "ndjson") {
|
|
29
|
+
return join(dataRoot(), store === "sqlite" ? "telemetry.db" : "telemetry.ndjson");
|
|
30
|
+
}
|
|
31
|
+
function homeBinPath() {
|
|
32
|
+
const name = process.platform === "win32" ? "agent-connector.cmd" : "agent-connector";
|
|
33
|
+
return join(dataRoot(), "bin", name);
|
|
34
|
+
}
|
|
35
|
+
function ensureDir(dir) {
|
|
36
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
function ensureHomeBin(cliEntry, nodePath = process.execPath) {
|
|
39
|
+
const binPath = homeBinPath();
|
|
40
|
+
ensureDir(join(dataRoot(), "bin"));
|
|
41
|
+
const node = nodePath.replace(/\\/g, "/");
|
|
42
|
+
const cli = cliEntry.replace(/\\/g, "/");
|
|
43
|
+
if (process.platform === "win32") {
|
|
44
|
+
writeFileSync(binPath, `@echo off\r
|
|
45
|
+
"${node}" "${cli}" %*\r
|
|
46
|
+
`, "utf8");
|
|
47
|
+
} else {
|
|
48
|
+
writeFileSync(binPath, `#!/bin/sh
|
|
49
|
+
exec "${node}" "${cli}" "$@"
|
|
50
|
+
`, "utf8");
|
|
51
|
+
chmodSync(binPath, 493);
|
|
52
|
+
}
|
|
53
|
+
return binPath;
|
|
54
|
+
}
|
|
55
|
+
function gitRemoteUrl(projectDir) {
|
|
56
|
+
const cfg = join(projectDir, ".git", "config");
|
|
57
|
+
if (!existsSync(cfg)) return null;
|
|
58
|
+
try {
|
|
59
|
+
const text = readFileSync(cfg, "utf8");
|
|
60
|
+
const lines = text.split(/\r?\n/);
|
|
61
|
+
let inOrigin = false;
|
|
62
|
+
for (const line of lines) {
|
|
63
|
+
const s = line.trim();
|
|
64
|
+
if (s.startsWith("[")) inOrigin = /^\[remote\s+"origin"\]$/.test(s);
|
|
65
|
+
else if (inOrigin) {
|
|
66
|
+
const m = s.match(/^url\s*=\s*(.+)$/);
|
|
67
|
+
if (m && m[1]) return m[1].trim();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
function projectIdentity(projectDir) {
|
|
75
|
+
const dir = resolve(projectDir);
|
|
76
|
+
const remote = gitRemoteUrl(dir);
|
|
77
|
+
const basis = remote ?? dir;
|
|
78
|
+
const key = createHash("sha256").update(basis).digest("hex").slice(0, 16);
|
|
79
|
+
return { key, label: remote ?? basename(dir), dir };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
dataRoot,
|
|
84
|
+
connectorsDir,
|
|
85
|
+
connectorDir,
|
|
86
|
+
backupsDir,
|
|
87
|
+
telemetryPath,
|
|
88
|
+
homeBinPath,
|
|
89
|
+
ensureDir,
|
|
90
|
+
ensureHomeBin,
|
|
91
|
+
projectIdentity
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=chunk-TRQKHP7D.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/paths.ts"],"sourcesContent":["/**\n * core/paths — home data-root, stable home binary, and project identity.\n *\n * Operating model (docs/ARCHITECTURE.md §3):\n * • One home data-root holds the single binary + shared telemetry + state.\n * Override with AGENT_CONNECTOR_DATA_DIR (the cross-agent shared-DB key).\n * This relocates FRAMEWORK state only — never platform-native config files.\n * • The home binary lives at a STABLE path so every host's pointer config\n * keeps working across updates (no versioned cache dir → no cache-heal bug).\n * • Per-project data is keyed by a stable project identity (git remote ||\n * normalized absolute path), hashed — not by code location.\n */\n\nimport { createHash } from \"node:crypto\";\nimport {\n chmodSync,\n existsSync,\n mkdirSync,\n readFileSync,\n writeFileSync,\n} from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { basename, join, resolve } from \"node:path\";\n\n/** Framework data-root: AGENT_CONNECTOR_DATA_DIR || ~/.agent-connector. */\nexport function dataRoot(): string {\n const override = process.env.AGENT_CONNECTOR_DATA_DIR;\n if (override && override.trim() !== \"\") return resolve(override);\n return join(homedir(), \".agent-connector\");\n}\n\nexport function connectorsDir(): string {\n return join(dataRoot(), \"connectors\");\n}\nexport function connectorDir(id: string): string {\n return join(connectorsDir(), id);\n}\nexport function backupsDir(): string {\n return join(dataRoot(), \"backups\");\n}\nexport function logsDir(): string {\n return join(dataRoot(), \"logs\");\n}\n\n/** Telemetry store path for the selected backend. */\nexport function telemetryPath(store: \"ndjson\" | \"sqlite\" = \"ndjson\"): string {\n return join(dataRoot(), store === \"sqlite\" ? \"telemetry.db\" : \"telemetry.ndjson\");\n}\n\n/** Stable, OS-correct path to the single home binary pointer. */\nexport function homeBinPath(): string {\n const name = process.platform === \"win32\" ? \"agent-connector.cmd\" : \"agent-connector\";\n return join(dataRoot(), \"bin\", name);\n}\n\nexport function ensureDir(dir: string): void {\n if (!existsSync(dir)) mkdirSync(dir, { recursive: true });\n}\n\n/**\n * Write a stable launcher at homeBinPath() that execs the real CLI entry.\n * Avoids symlinks (Windows constraint) and versioned paths. Idempotent.\n *\n * @param cliEntry absolute path to the installed cli.js\n * @param nodePath node runtime to exec with (defaults to current process.execPath)\n * @returns the stable launcher path\n */\nexport function ensureHomeBin(cliEntry: string, nodePath: string = process.execPath): string {\n const binPath = homeBinPath();\n ensureDir(join(dataRoot(), \"bin\"));\n const node = nodePath.replace(/\\\\/g, \"/\");\n const cli = cliEntry.replace(/\\\\/g, \"/\");\n if (process.platform === \"win32\") {\n writeFileSync(binPath, `@echo off\\r\\n\"${node}\" \"${cli}\" %*\\r\\n`, \"utf8\");\n } else {\n writeFileSync(binPath, `#!/bin/sh\\nexec \"${node}\" \"${cli}\" \"$@\"\\n`, \"utf8\");\n chmodSync(binPath, 0o755);\n }\n return binPath;\n}\n\n/** Read remote.origin.url from a project's .git/config without spawning git. */\nfunction gitRemoteUrl(projectDir: string): string | null {\n const cfg = join(projectDir, \".git\", \"config\");\n if (!existsSync(cfg)) return null;\n try {\n const text = readFileSync(cfg, \"utf8\");\n // Find [remote \"origin\"] ... url = X\n const lines = text.split(/\\r?\\n/);\n let inOrigin = false;\n for (const line of lines) {\n const s = line.trim();\n if (s.startsWith(\"[\")) inOrigin = /^\\[remote\\s+\"origin\"\\]$/.test(s);\n else if (inOrigin) {\n const m = s.match(/^url\\s*=\\s*(.+)$/);\n if (m && m[1]) return m[1].trim();\n }\n }\n } catch {\n /* ignore */\n }\n return null;\n}\n\nexport interface ProjectIdentity {\n /** Hashed stable key used to partition telemetry/state. */\n key: string;\n /** Human-readable label (git remote or directory name). */\n label: string;\n /** Absolute project directory. */\n dir: string;\n}\n\n/**\n * Derive a stable project identity. Prefers the git origin URL (stable across\n * clones/locations); falls back to the normalized absolute path.\n */\nexport function projectIdentity(projectDir: string): ProjectIdentity {\n const dir = resolve(projectDir);\n const remote = gitRemoteUrl(dir);\n const basis = remote ?? dir;\n const key = createHash(\"sha256\").update(basis).digest(\"hex\").slice(0, 16);\n return { key, label: remote ?? basename(dir), dir };\n}\n"],"mappings":";;;AAaA,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe;AACxB,SAAS,UAAU,MAAM,eAAe;AAGjC,SAAS,WAAmB;AACjC,QAAM,WAAW,QAAQ,IAAI;AAC7B,MAAI,YAAY,SAAS,KAAK,MAAM,GAAI,QAAO,QAAQ,QAAQ;AAC/D,SAAO,KAAK,QAAQ,GAAG,kBAAkB;AAC3C;AAEO,SAAS,gBAAwB;AACtC,SAAO,KAAK,SAAS,GAAG,YAAY;AACtC;AACO,SAAS,aAAa,IAAoB;AAC/C,SAAO,KAAK,cAAc,GAAG,EAAE;AACjC;AACO,SAAS,aAAqB;AACnC,SAAO,KAAK,SAAS,GAAG,SAAS;AACnC;AAMO,SAAS,cAAc,QAA6B,UAAkB;AAC3E,SAAO,KAAK,SAAS,GAAG,UAAU,WAAW,iBAAiB,kBAAkB;AAClF;AAGO,SAAS,cAAsB;AACpC,QAAM,OAAO,QAAQ,aAAa,UAAU,wBAAwB;AACpE,SAAO,KAAK,SAAS,GAAG,OAAO,IAAI;AACrC;AAEO,SAAS,UAAU,KAAmB;AAC3C,MAAI,CAAC,WAAW,GAAG,EAAG,WAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAC1D;AAUO,SAAS,cAAc,UAAkB,WAAmB,QAAQ,UAAkB;AAC3F,QAAM,UAAU,YAAY;AAC5B,YAAU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|
|
3
|
+
resolveSpawnCommand
|
|
4
|
+
} from "./chunk-MEH7GC7R.js";
|
|
5
|
+
|
|
6
|
+
// src/core/spawn-child.ts
|
|
7
|
+
import { spawn } from "child_process";
|
|
8
|
+
function winQuoteArg(s) {
|
|
9
|
+
return `"${s.replace(/"/g, '""')}"`;
|
|
10
|
+
}
|
|
11
|
+
function spawnChild(command, args, options) {
|
|
12
|
+
const resolved = resolveSpawnCommand(command);
|
|
13
|
+
if (!resolved.needsShell) return spawn(resolved.file, args, options);
|
|
14
|
+
const line = [resolved.file, ...args].map(winQuoteArg).join(" ");
|
|
15
|
+
return spawn(line, { ...options, shell: true });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/telemetry/jsonrpc.ts
|
|
19
|
+
import { StringDecoder } from "string_decoder";
|
|
20
|
+
function isObject(v) {
|
|
21
|
+
return typeof v === "object" && v !== null;
|
|
22
|
+
}
|
|
23
|
+
function idKey(id) {
|
|
24
|
+
if (typeof id === "string") return `s:${id}`;
|
|
25
|
+
if (typeof id === "number") return `n:${id}`;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
var LineBuffer = class {
|
|
29
|
+
buf = "";
|
|
30
|
+
onLine;
|
|
31
|
+
// Incremental UTF-8 decoder: `data` events split on arbitrary byte
|
|
32
|
+
// boundaries, so a multi-byte sequence (emoji/CJK in a tool arg or result)
|
|
33
|
+
// can straddle two chunks. StringDecoder holds back a trailing partial
|
|
34
|
+
// sequence until it completes, keeping the measured copy byte-accurate.
|
|
35
|
+
// (The forwarded stream is untouched — this is only the tee copy.)
|
|
36
|
+
decoder = new StringDecoder("utf8");
|
|
37
|
+
constructor(onLine) {
|
|
38
|
+
this.onLine = onLine;
|
|
39
|
+
}
|
|
40
|
+
push(chunk) {
|
|
41
|
+
this.buf += this.decoder.write(chunk);
|
|
42
|
+
let nl = this.buf.indexOf("\n");
|
|
43
|
+
while (nl !== -1) {
|
|
44
|
+
let line = this.buf.slice(0, nl);
|
|
45
|
+
if (line.endsWith("\r")) line = line.slice(0, -1);
|
|
46
|
+
if (line.length > 0) this.onLine(line);
|
|
47
|
+
this.buf = this.buf.slice(nl + 1);
|
|
48
|
+
nl = this.buf.indexOf("\n");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
spawnChild,
|
|
55
|
+
isObject,
|
|
56
|
+
idKey,
|
|
57
|
+
LineBuffer
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=chunk-WCETQWWK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/spawn-child.ts","../src/telemetry/jsonrpc.ts"],"sourcesContent":["/**\n * core/spawn-child — the cross-platform child_process.spawn wrapper.\n *\n * Kept SEPARATE from core/spawn.ts (pure string/path helpers, imported widely\n * and early) so that pulling in `node:child_process` here does not perturb the\n * module-eval order of test suites that vi.mock(\"node:child_process\").\n */\n\nimport { type ChildProcess, type SpawnOptions, spawn } from \"node:child_process\";\n\nimport { resolveSpawnCommand } from \"./spawn.js\";\n\n/**\n * Quote one token for a cmd.exe command line: wrap in double quotes, doubling any\n * embedded double quote. Sufficient for the paths / package names / flags we\n * spawn (connector config, not untrusted end-user input) — we intentionally do\n * not escape cmd metacharacters (& | ^ %), which never appear in those tokens.\n */\nfunction winQuoteArg(s: string): string {\n return `\"${s.replace(/\"/g, '\"\"')}\"`;\n}\n\n/**\n * Cross-platform child spawn that fixes native-Windows package-runner launches.\n * Direct spawn on macOS/Linux. On win32 it routes through\n * {@link resolveSpawnCommand}; an `.exe` runs directly, while a `.cmd`/`.bat`\n * (npx.cmd, the agent-connector.cmd launcher) is launched via a SINGLE quoted\n * command line with `shell: true` — a string rather than an args array, which\n * Node requires for a batch file AND which avoids the DEP0190 deprecation that\n * `shell: true` + an args array triggers on Node ≥ 24.\n */\nexport function spawnChild(\n command: string,\n args: string[],\n options: SpawnOptions,\n): ChildProcess {\n const resolved = resolveSpawnCommand(command);\n if (!resolved.needsShell) return spawn(resolved.file, args, options);\n const line = [resolved.file, ...args].map(winQuoteArg).join(\" \");\n return spawn(line, { ...options, shell: true });\n}\n","/**\n * telemetry/jsonrpc — shared MCP stdio wire primitives.\n *\n * The MCP stdio transport is NEWLINE-DELIMITED JSON-RPC: one single-line JSON\n * object per message, terminated by `\\n` (no Content-Length framing). These\n * primitives — the message shape, the id key, the line buffer — are used by BOTH\n * the telemetry proxy (which tees + measures) and `doctor --probe` (which sends\n * a real initialize/ping/tools-list handshake), so framing + id-correlation are\n * byte-identical across the two paths. Extracted here rather than duplicated.\n */\n\nimport { StringDecoder } from \"node:string_decoder\";\n\n/** Any newline-delimited JSON-RPC message — request, response, or notification. */\nexport interface JsonRpcMessage {\n jsonrpc?: unknown;\n id?: unknown;\n method?: unknown;\n params?: unknown;\n result?: unknown;\n error?: unknown;\n}\n\nexport function isObject(v: unknown): v is Record<string, unknown> {\n return typeof v === \"object\" && v !== null;\n}\n\n/** JSON-RPC ids are number | string; normalize to a Map key. `null` → no key. */\nexport function idKey(id: unknown): string | null {\n if (typeof id === \"string\") return `s:${id}`;\n if (typeof id === \"number\") return `n:${id}`;\n return null;\n}\n\n/**\n * Buffer a byte stream into complete `\\n`-terminated lines and invoke `onLine`\n * for each. Carriage returns are tolerated (some hosts emit CRLF). This is a\n * pure side-channel: it never owns or mutates the bytes being forwarded — the\n * caller has already written the original chunk downstream verbatim.\n */\nexport class LineBuffer {\n private buf = \"\";\n private readonly onLine: (line: string) => void;\n // Incremental UTF-8 decoder: `data` events split on arbitrary byte\n // boundaries, so a multi-byte sequence (emoji/CJK in a tool arg or result)\n // can straddle two chunks. StringDecoder holds back a trailing partial\n // sequence until it completes, keeping the measured copy byte-accurate.\n // (The forwarded stream is untouched — this is only the tee copy.)\n private readonly decoder = new StringDecoder(\"utf8\");\n\n constructor(onLine: (line: string) => void) {\n this.onLine = onLine;\n }\n\n push(chunk: Buffer): void {\n this.buf += this.decoder.write(chunk);\n let nl = this.buf.indexOf(\"\\n\");\n while (nl !== -1) {\n // Slice off one line (without the newline), tolerate a trailing CR.\n let line = this.buf.slice(0, nl);\n if (line.endsWith(\"\\r\")) line = line.slice(0, -1);\n if (line.length > 0) this.onLine(line);\n this.buf = this.buf.slice(nl + 1);\n nl = this.buf.indexOf(\"\\n\");\n }\n }\n}\n"],"mappings":";;;;;;AAQA,SAA+C,aAAa;AAU5D,SAAS,YAAY,GAAmB;AACtC,SAAO,IAAI,EAAE,QAAQ,MAAM,IAAI,CAAC;AAClC;AAWO,SAAS,WACd,SACA,MACA,SACc;AACd,QAAM,WAAW,oBAAoB,OAAO;AAC5C,MAAI,CAAC,SAAS,WAAY,QAAO,MAAM,SAAS,MAAM,MAAM,OAAO;AACnE,QAAM,OAAO,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,IAAI,WAAW,EAAE,KAAK,GAAG;AAC/D,SAAO,MAAM,MAAM,EAAE,GAAG,SAAS,OAAO,KAAK,CAAC;AAChD;;;AC7BA,SAAS,qBAAqB;AAYvB,SAAS,SAAS,GAA0C;AACjE,SAAO,OAAO,MAAM,YAAY,MAAM;AACxC;AAGO,SAAS,MAAM,IAA4B;AAChD,MAAI,OAAO,OAAO,SAAU,QAAO,KAAK,EAAE;AAC1C,MAAI,OAAO,OAAO,SAAU,QAAO,KAAK,EAAE;AAC1C,SAAO;AACT;AAQO,IAAM,aAAN,MAAiB;AAAA,EACd,MAAM;AAAA,EACG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU,IAAI,cAAc,MAAM;AAAA,EAEnD,YAAY,QAAgC;AAC1C,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,KAAK,OAAqB;AACxB,SAAK,OAAO,KAAK,QAAQ,MAAM,KAAK;AACpC,QAAI,KAAK,KAAK,IAAI,QAAQ,IAAI;AAC9B,WAAO,OAAO,IAAI;AAEhB,UAAI,OAAO,KAAK,IAAI,MAAM,GAAG,EAAE;AAC/B,UAAI,KAAK,SA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