@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.
Files changed (203) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +6 -0
  3. package/README.md +348 -0
  4. package/dist/amp-QSFH2V7Y.js +217 -0
  5. package/dist/amp-QSFH2V7Y.js.map +1 -0
  6. package/dist/amp-TULUPXXL.js +237 -0
  7. package/dist/amp-TULUPXXL.js.map +1 -0
  8. package/dist/antigravity-CX2YLSY7.js +17 -0
  9. package/dist/antigravity-CX2YLSY7.js.map +1 -0
  10. package/dist/antigravity-STHZWMP3.js +171 -0
  11. package/dist/antigravity-STHZWMP3.js.map +1 -0
  12. package/dist/antigravity-cli-P6HADOAO.js +121 -0
  13. package/dist/antigravity-cli-P6HADOAO.js.map +1 -0
  14. package/dist/antigravity-cli-YQDFVV4U.js +86 -0
  15. package/dist/antigravity-cli-YQDFVV4U.js.map +1 -0
  16. package/dist/chunk-54EMKTTX.js +191 -0
  17. package/dist/chunk-54EMKTTX.js.map +1 -0
  18. package/dist/chunk-7L6ITC4T.js +54 -0
  19. package/dist/chunk-7L6ITC4T.js.map +1 -0
  20. package/dist/chunk-7MSDGHJW.js +316 -0
  21. package/dist/chunk-7MSDGHJW.js.map +1 -0
  22. package/dist/chunk-BCHWFTV4.js +196 -0
  23. package/dist/chunk-BCHWFTV4.js.map +1 -0
  24. package/dist/chunk-DBQMX75U.js +36 -0
  25. package/dist/chunk-DBQMX75U.js.map +1 -0
  26. package/dist/chunk-EXLS7BSI.js +29 -0
  27. package/dist/chunk-EXLS7BSI.js.map +1 -0
  28. package/dist/chunk-JNM3TPLX.js +593 -0
  29. package/dist/chunk-JNM3TPLX.js.map +1 -0
  30. package/dist/chunk-JWNT5KW7.js +197 -0
  31. package/dist/chunk-JWNT5KW7.js.map +1 -0
  32. package/dist/chunk-KHO5WNTP.js +30 -0
  33. package/dist/chunk-KHO5WNTP.js.map +1 -0
  34. package/dist/chunk-LTT56GI3.js +155 -0
  35. package/dist/chunk-LTT56GI3.js.map +1 -0
  36. package/dist/chunk-MEH7GC7R.js +111 -0
  37. package/dist/chunk-MEH7GC7R.js.map +1 -0
  38. package/dist/chunk-MQPNU2CY.js +64 -0
  39. package/dist/chunk-MQPNU2CY.js.map +1 -0
  40. package/dist/chunk-OPXAP3AC.js +12 -0
  41. package/dist/chunk-OPXAP3AC.js.map +1 -0
  42. package/dist/chunk-RK6VBLXP.js +50 -0
  43. package/dist/chunk-RK6VBLXP.js.map +1 -0
  44. package/dist/chunk-TIIP3RG2.js +420 -0
  45. package/dist/chunk-TIIP3RG2.js.map +1 -0
  46. package/dist/chunk-TRKWUNO4.js +702 -0
  47. package/dist/chunk-TRKWUNO4.js.map +1 -0
  48. package/dist/chunk-TRQKHP7D.js +93 -0
  49. package/dist/chunk-TRQKHP7D.js.map +1 -0
  50. package/dist/chunk-WCETQWWK.js +59 -0
  51. package/dist/chunk-WCETQWWK.js.map +1 -0
  52. package/dist/chunk-WV63X7IK.js +357 -0
  53. package/dist/chunk-WV63X7IK.js.map +1 -0
  54. package/dist/chunk-XD7MY6HB.js +343 -0
  55. package/dist/chunk-XD7MY6HB.js.map +1 -0
  56. package/dist/chunk-XNAM7F35.js +276 -0
  57. package/dist/chunk-XNAM7F35.js.map +1 -0
  58. package/dist/chunk-XUCWLJY5.js +238 -0
  59. package/dist/chunk-XUCWLJY5.js.map +1 -0
  60. package/dist/chunk-YNZU6PAV.js +800 -0
  61. package/dist/chunk-YNZU6PAV.js.map +1 -0
  62. package/dist/chunk-YT43MUSJ.js +146 -0
  63. package/dist/chunk-YT43MUSJ.js.map +1 -0
  64. package/dist/claude-code-HKDV7T32.js +637 -0
  65. package/dist/claude-code-HKDV7T32.js.map +1 -0
  66. package/dist/claude-code-W74MNTAC.js +652 -0
  67. package/dist/claude-code-W74MNTAC.js.map +1 -0
  68. package/dist/cli/sdk.d.ts +54 -0
  69. package/dist/cli/sdk.js +82 -0
  70. package/dist/cli/sdk.js.map +1 -0
  71. package/dist/cli.d.ts +2 -0
  72. package/dist/cli.js +15 -0
  73. package/dist/cli.js.map +1 -0
  74. package/dist/codebuff-3PMZJJHP.js +307 -0
  75. package/dist/codebuff-3PMZJJHP.js.map +1 -0
  76. package/dist/codebuff-QX57FJDN.js +220 -0
  77. package/dist/codebuff-QX57FJDN.js.map +1 -0
  78. package/dist/codex-JFQTS6LU.js +593 -0
  79. package/dist/codex-JFQTS6LU.js.map +1 -0
  80. package/dist/codex-Q3ATRRX3.js +364 -0
  81. package/dist/codex-Q3ATRRX3.js.map +1 -0
  82. package/dist/copilot-cli-MTCGHZ2T.js +622 -0
  83. package/dist/copilot-cli-MTCGHZ2T.js.map +1 -0
  84. package/dist/copilot-cli-SJGIXVSD.js +369 -0
  85. package/dist/copilot-cli-SJGIXVSD.js.map +1 -0
  86. package/dist/crush-I7PK3FGI.js +360 -0
  87. package/dist/crush-I7PK3FGI.js.map +1 -0
  88. package/dist/crush-LN5QFFR2.js +183 -0
  89. package/dist/crush-LN5QFFR2.js.map +1 -0
  90. package/dist/cursor-4TMXKJOZ.js +603 -0
  91. package/dist/cursor-4TMXKJOZ.js.map +1 -0
  92. package/dist/cursor-QZ6MTO74.js +194 -0
  93. package/dist/cursor-QZ6MTO74.js.map +1 -0
  94. package/dist/detect-WIAGVYS4.js +68 -0
  95. package/dist/detect-WIAGVYS4.js.map +1 -0
  96. package/dist/doctor-EZW2K4NI.js +372 -0
  97. package/dist/doctor-EZW2K4NI.js.map +1 -0
  98. package/dist/droid-KN6VRMMT.js +424 -0
  99. package/dist/droid-KN6VRMMT.js.map +1 -0
  100. package/dist/droid-W5WF5XEX.js +224 -0
  101. package/dist/droid-W5WF5XEX.js.map +1 -0
  102. package/dist/gemini-cli-CIRW37TU.js +369 -0
  103. package/dist/gemini-cli-CIRW37TU.js.map +1 -0
  104. package/dist/gemini-cli-Y35FFK4M.js +705 -0
  105. package/dist/gemini-cli-Y35FFK4M.js.map +1 -0
  106. package/dist/goose-A3M5GODH.js +212 -0
  107. package/dist/goose-A3M5GODH.js.map +1 -0
  108. package/dist/goose-ZTGTSUFJ.js +480 -0
  109. package/dist/goose-ZTGTSUFJ.js.map +1 -0
  110. package/dist/hermes-H2KV44GK.js +470 -0
  111. package/dist/hermes-H2KV44GK.js.map +1 -0
  112. package/dist/hermes-ZYLMOFLZ.js +196 -0
  113. package/dist/hermes-ZYLMOFLZ.js.map +1 -0
  114. package/dist/hook-YVDILAMZ.js +75 -0
  115. package/dist/hook-YVDILAMZ.js.map +1 -0
  116. package/dist/index.d.ts +22 -0
  117. package/dist/index.js +10 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/install-HQRYZOQ2.js +60 -0
  120. package/dist/install-HQRYZOQ2.js.map +1 -0
  121. package/dist/jetbrains-copilot-HWA3DMH7.js +633 -0
  122. package/dist/jetbrains-copilot-HWA3DMH7.js.map +1 -0
  123. package/dist/kilo-NSWAVP6P.js +235 -0
  124. package/dist/kilo-NSWAVP6P.js.map +1 -0
  125. package/dist/kilo-QXJRCSLT.js +384 -0
  126. package/dist/kilo-QXJRCSLT.js.map +1 -0
  127. package/dist/kilo-cli-EAQTHXUW.js +587 -0
  128. package/dist/kilo-cli-EAQTHXUW.js.map +1 -0
  129. package/dist/kilo-cli-EVBKUODA.js +160 -0
  130. package/dist/kilo-cli-EVBKUODA.js.map +1 -0
  131. package/dist/kimi-EI3UM3ZV.js +155 -0
  132. package/dist/kimi-EI3UM3ZV.js.map +1 -0
  133. package/dist/kimi-GQ7VXNYT.js +423 -0
  134. package/dist/kimi-GQ7VXNYT.js.map +1 -0
  135. package/dist/kiro-UCLSLBW2.js +217 -0
  136. package/dist/kiro-UCLSLBW2.js.map +1 -0
  137. package/dist/kiro-VQTT6LO2.js +451 -0
  138. package/dist/kiro-VQTT6LO2.js.map +1 -0
  139. package/dist/leaderboard-K6ON3SWW.js +137 -0
  140. package/dist/leaderboard-K6ON3SWW.js.map +1 -0
  141. package/dist/mux-T2TV4CIQ.js +211 -0
  142. package/dist/mux-T2TV4CIQ.js.map +1 -0
  143. package/dist/mux-ZMLVAXOO.js +96 -0
  144. package/dist/mux-ZMLVAXOO.js.map +1 -0
  145. package/dist/omp-PB4VDKS6.js +586 -0
  146. package/dist/omp-PB4VDKS6.js.map +1 -0
  147. package/dist/openclaw-ETN2M63O.js +751 -0
  148. package/dist/openclaw-ETN2M63O.js.map +1 -0
  149. package/dist/openclaw-IYA7ASL6.js +150 -0
  150. package/dist/openclaw-IYA7ASL6.js.map +1 -0
  151. package/dist/opencode-FZ33JKUZ.js +734 -0
  152. package/dist/opencode-FZ33JKUZ.js.map +1 -0
  153. package/dist/opencode-HWT3RSMN.js +216 -0
  154. package/dist/opencode-HWT3RSMN.js.map +1 -0
  155. package/dist/package-DLOVE2E4.js +1132 -0
  156. package/dist/package-DLOVE2E4.js.map +1 -0
  157. package/dist/pi-CIU2QHT4.js +208 -0
  158. package/dist/pi-CIU2QHT4.js.map +1 -0
  159. package/dist/pi-UFX2OYFV.js +139 -0
  160. package/dist/pi-UFX2OYFV.js.map +1 -0
  161. package/dist/qwen-code-5POCNU6P.js +573 -0
  162. package/dist/qwen-code-5POCNU6P.js.map +1 -0
  163. package/dist/qwen-code-W7NUCDEN.js +134 -0
  164. package/dist/qwen-code-W7NUCDEN.js.map +1 -0
  165. package/dist/roo-code-IOIUXRDE.js +242 -0
  166. package/dist/roo-code-IOIUXRDE.js.map +1 -0
  167. package/dist/roo-code-ZLKH4A7N.js +229 -0
  168. package/dist/roo-code-ZLKH4A7N.js.map +1 -0
  169. package/dist/runtime/index.d.ts +157 -0
  170. package/dist/runtime/index.js +20 -0
  171. package/dist/runtime/index.js.map +1 -0
  172. package/dist/serve-HVWWY4B6.js +65 -0
  173. package/dist/serve-HVWWY4B6.js.map +1 -0
  174. package/dist/status-FE7TECZD.js +128 -0
  175. package/dist/status-FE7TECZD.js.map +1 -0
  176. package/dist/synthetic-UKR6SMGS.js +178 -0
  177. package/dist/synthetic-UKR6SMGS.js.map +1 -0
  178. package/dist/telemetry-36GESKQQ.js +349 -0
  179. package/dist/telemetry-36GESKQQ.js.map +1 -0
  180. package/dist/trae-JSNDZFKL.js +204 -0
  181. package/dist/trae-JSNDZFKL.js.map +1 -0
  182. package/dist/trae-PA26DPBW.js +157 -0
  183. package/dist/trae-PA26DPBW.js.map +1 -0
  184. package/dist/types-CYUB1OTr.d.ts +427 -0
  185. package/dist/uninstall-IGCKNOSF.js +72 -0
  186. package/dist/uninstall-IGCKNOSF.js.map +1 -0
  187. package/dist/upgrade-JV2VK242.js +104 -0
  188. package/dist/upgrade-JV2VK242.js.map +1 -0
  189. package/dist/usage-6ER6EMEY.js +324 -0
  190. package/dist/usage-6ER6EMEY.js.map +1 -0
  191. package/dist/usage-event-JKBI6XCF.js +48 -0
  192. package/dist/usage-event-JKBI6XCF.js.map +1 -0
  193. package/dist/vscode-copilot-CK3NO54M.js +715 -0
  194. package/dist/vscode-copilot-CK3NO54M.js.map +1 -0
  195. package/dist/warp-JNQA7PBU.js +126 -0
  196. package/dist/warp-JNQA7PBU.js.map +1 -0
  197. package/dist/warp-QNVDXOG4.js +199 -0
  198. package/dist/warp-QNVDXOG4.js.map +1 -0
  199. package/dist/zed-NNNX5MNT.js +272 -0
  200. package/dist/zed-NNNX5MNT.js.map +1 -0
  201. package/dist/zed-VRJKWYUR.js +209 -0
  202. package/dist/zed-VRJKWYUR.js.map +1 -0
  203. package/package.json +79 -0
@@ -0,0 +1,424 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ resolveEnvRefsDeep
4
+ } from "./chunk-DBQMX75U.js";
5
+ import {
6
+ BaseAdapter
7
+ } from "./chunk-TIIP3RG2.js";
8
+ import "./chunk-7L6ITC4T.js";
9
+ import {
10
+ buildHomeBinHookCommand,
11
+ buildServeWrapperCommand,
12
+ isHomeBinHookCommand,
13
+ shouldWrapForTelemetry
14
+ } from "./chunk-MEH7GC7R.js";
15
+ import "./chunk-TRQKHP7D.js";
16
+
17
+ // src/adapters/droid/index.ts
18
+ import { existsSync } from "fs";
19
+ import { homedir } from "os";
20
+ import { join } from "path";
21
+ var HOST = "droid";
22
+ var MCP_ROOT_KEY = "mcpServers";
23
+ var SUPPORTED_EVENTS = /* @__PURE__ */ new Set([
24
+ "PreToolUse",
25
+ "PostToolUse",
26
+ "UserPromptSubmit",
27
+ "Stop"
28
+ ]);
29
+ var DroidAdapter = class extends BaseAdapter {
30
+ id = HOST;
31
+ name = "Droid (Factory)";
32
+ paradigm = "json-stdio";
33
+ capabilities = {
34
+ preToolUse: true,
35
+ postToolUse: true,
36
+ preCompact: false,
37
+ sessionStart: false,
38
+ sessionEnd: false,
39
+ userPromptSubmit: true,
40
+ stop: true,
41
+ notification: false,
42
+ // Droid's PreToolUse can deny/ask (Claude-shaped), but it cannot rewrite
43
+ // already-emitted tool output. canModifyArgs left false until confirmed.
44
+ canModifyArgs: false,
45
+ canModifyOutput: false,
46
+ // Droid honors additionalContext on the stdout reply.
47
+ canInjectSessionContext: true,
48
+ // Droid registers stdio and Streamable HTTP MCP servers.
49
+ transports: ["stdio", "http"]
50
+ };
51
+ // ── Detection ────────────────────────────────────────────────────────────
52
+ detectInstalled(projectDir) {
53
+ const userDir = join(homedir(), ".factory");
54
+ const userMcp = join(userDir, "mcp.json");
55
+ const projDir = join(projectDir, ".factory");
56
+ const projMcp = join(projDir, "mcp.json");
57
+ const userInstalled = existsSync(userDir) || existsSync(userMcp);
58
+ const projInstalled = existsSync(projDir) || existsSync(projMcp);
59
+ const installed = userInstalled || projInstalled;
60
+ const scope = projInstalled && !userInstalled ? "project" : "user";
61
+ const configPath = scope === "project" ? projMcp : userMcp;
62
+ return {
63
+ id: this.id,
64
+ name: this.name,
65
+ installed,
66
+ paradigm: this.paradigm,
67
+ capabilities: this.capabilities,
68
+ configPath,
69
+ scope,
70
+ reason: installed ? `found Droid config (${scope}) at ${configPath}` : `no .factory config at ${userDir} or ${projDir}`,
71
+ confidence: installed ? "high" : "low"
72
+ };
73
+ }
74
+ // ── Native paths ─────────────────────────────────────────────────────────
75
+ getConfigDir(ctx) {
76
+ return ctx.scope === "project" ? join(ctx.projectDir, ".factory") : join(homedir(), ".factory");
77
+ }
78
+ getServerConfigPath(ctx) {
79
+ return join(this.getConfigDir(ctx), "mcp.json");
80
+ }
81
+ /** Hooks live in a SEPARATE hooks.json under the same `.factory` dir. */
82
+ getHookConfigPath(ctx) {
83
+ return join(this.getConfigDir(ctx), "hooks.json");
84
+ }
85
+ // ── MCP server install / uninstall ───────────────────────────────────────
86
+ installServer(ctx) {
87
+ const { connector } = ctx;
88
+ const override = connector.platforms[HOST]?.server;
89
+ if (!connector.server || override === false) {
90
+ return [
91
+ {
92
+ platform: this.id,
93
+ action: "skip",
94
+ detail: connector.server ? "server registration disabled for droid" : "connector declares no MCP server"
95
+ }
96
+ ];
97
+ }
98
+ const server = override && typeof override === "object" ? { ...connector.server, ...override } : connector.server;
99
+ const serverPath = this.getServerConfigPath(ctx);
100
+ const entry = this.renderServerEntry(ctx, server);
101
+ return [
102
+ this.upsertServerInJson(serverPath, MCP_ROOT_KEY, connector.id, entry, ctx.dryRun)
103
+ ];
104
+ }
105
+ uninstallServer(ctx) {
106
+ const serverPath = this.getServerConfigPath(ctx);
107
+ return [
108
+ this.removeServerFromJson(serverPath, MCP_ROOT_KEY, ctx.connector.id, ctx.dryRun)
109
+ ];
110
+ }
111
+ /** Render a normalized ServerDef into Droid's native mcpServers entry. */
112
+ renderServerEntry(ctx, server) {
113
+ const transport = server.transport;
114
+ const disabled = server.enabled === false;
115
+ if (transport === "stdio") {
116
+ let command = server.command ?? "";
117
+ let args = [...server.args ?? []];
118
+ if (shouldWrapForTelemetry(server, ctx.connector.telemetry)) {
119
+ const wrapped = buildServeWrapperCommand(
120
+ ctx.homeBinPath,
121
+ ctx.connector.id,
122
+ command,
123
+ args,
124
+ ctx.scope,
125
+ this.id
126
+ );
127
+ command = wrapped.command;
128
+ args = wrapped.args;
129
+ }
130
+ const entry2 = {
131
+ type: "stdio",
132
+ command: resolveEnvRefsDeep(command),
133
+ disabled
134
+ };
135
+ if (args.length > 0) entry2.args = resolveEnvRefsDeep(args);
136
+ const env = this.renderEnv(server.env);
137
+ if (env) entry2.env = env;
138
+ return entry2;
139
+ }
140
+ const entry = {
141
+ type: "http",
142
+ url: resolveEnvRefsDeep(server.url ?? ""),
143
+ disabled
144
+ };
145
+ const headers = this.renderEnv(server.headers);
146
+ if (headers) entry.headers = headers;
147
+ return entry;
148
+ }
149
+ /**
150
+ * Render env/header values. Resolve `${env:VAR}` references to literals at
151
+ * install time (the safe path; Droid would also accept native ${VAR}).
152
+ */
153
+ renderEnv(env) {
154
+ if (!env || Object.keys(env).length === 0) return void 0;
155
+ return resolveEnvRefsDeep({ ...env });
156
+ }
157
+ // ── Hook install / uninstall (separate hooks.json, nested-rule shape) ─────
158
+ installHooks(ctx) {
159
+ const { connector } = ctx;
160
+ if (connector.platforms[HOST]?.hooks === false) {
161
+ return [{ platform: this.id, action: "skip", detail: "hooks disabled for droid" }];
162
+ }
163
+ if (connector.hookEvents.length === 0) {
164
+ return [{ platform: this.id, action: "skip", detail: "connector declares no hooks" }];
165
+ }
166
+ const hookPath = this.getHookConfigPath(ctx);
167
+ const file = this.readJson(hookPath) ?? {};
168
+ const hooks = file.hooks ??= {};
169
+ const changes = [];
170
+ let mutated = false;
171
+ for (const event of connector.hookEvents) {
172
+ if (!SUPPORTED_EVENTS.has(event)) {
173
+ changes.push({
174
+ platform: this.id,
175
+ action: "warn",
176
+ path: hookPath,
177
+ detail: `${event} has no Droid hook equivalent \u2014 skipped`
178
+ });
179
+ continue;
180
+ }
181
+ const command = buildHomeBinHookCommand(ctx.homeBinPath, HOST, event, connector.id);
182
+ const matcher = connector.hooks[event]?.matcher ?? "";
183
+ const entry = {
184
+ matcher,
185
+ hooks: [{ type: "command", command }]
186
+ };
187
+ const bucket = hooks[event] ??= [];
188
+ const existingIdx = bucket.findIndex((e) => this.entryHasOurCommand(e, ctx));
189
+ if (existingIdx >= 0) {
190
+ if (JSON.stringify(bucket[existingIdx]) === JSON.stringify(entry)) {
191
+ changes.push({
192
+ platform: this.id,
193
+ action: "skip",
194
+ path: hookPath,
195
+ detail: `hooks.${event} already registered`
196
+ });
197
+ continue;
198
+ }
199
+ bucket[existingIdx] = entry;
200
+ changes.push({
201
+ platform: this.id,
202
+ action: "update",
203
+ path: hookPath,
204
+ detail: `hooks.${event}`
205
+ });
206
+ } else {
207
+ bucket.push(entry);
208
+ changes.push({
209
+ platform: this.id,
210
+ action: "create",
211
+ path: hookPath,
212
+ detail: `hooks.${event}`
213
+ });
214
+ }
215
+ mutated = true;
216
+ }
217
+ if (mutated) this.writeJson(hookPath, file, ctx.dryRun);
218
+ return changes;
219
+ }
220
+ uninstallHooks(ctx) {
221
+ const hookPath = this.getHookConfigPath(ctx);
222
+ const file = this.readJson(hookPath);
223
+ const hooks = file?.hooks;
224
+ if (!file || !hooks) {
225
+ return [
226
+ {
227
+ platform: this.id,
228
+ action: "skip",
229
+ path: hookPath,
230
+ detail: "no hooks section present"
231
+ }
232
+ ];
233
+ }
234
+ const changes = [];
235
+ let mutated = false;
236
+ for (const event of Object.keys(hooks)) {
237
+ const bucket = hooks[event];
238
+ if (!Array.isArray(bucket)) continue;
239
+ const next = [];
240
+ let removed = 0;
241
+ for (const e of bucket) {
242
+ const innerBefore = e.hooks?.length ?? 0;
243
+ const inner = (e.hooks ?? []).filter((h) => !this.isOurCommand(h.command, ctx));
244
+ removed += innerBefore - inner.length;
245
+ if (inner.length > 0) next.push({ matcher: e.matcher ?? "", hooks: inner });
246
+ }
247
+ if (removed > 0) {
248
+ if (next.length > 0) hooks[event] = next;
249
+ else delete hooks[event];
250
+ changes.push({
251
+ platform: this.id,
252
+ action: "remove",
253
+ path: hookPath,
254
+ detail: `hooks.${event} (${removed})`
255
+ });
256
+ mutated = true;
257
+ }
258
+ }
259
+ if (mutated) this.writeJson(hookPath, file, ctx.dryRun);
260
+ if (changes.length === 0) {
261
+ changes.push({
262
+ platform: this.id,
263
+ action: "skip",
264
+ path: hookPath,
265
+ detail: "no matching hook entries"
266
+ });
267
+ }
268
+ return changes;
269
+ }
270
+ entryHasOurCommand(entry, ctx) {
271
+ return (entry.hooks ?? []).some((h) => this.isOurCommand(h.command, ctx));
272
+ }
273
+ /** True when a hook command references our home binary AND this connector id
274
+ * (anchored so a shared-prefix id can't collide — see isHomeBinHookCommand). */
275
+ isOurCommand(command, ctx) {
276
+ return isHomeBinHookCommand(command, ctx.homeBinPath, ctx.connector.id);
277
+ }
278
+ // ── Diagnostics ──────────────────────────────────────────────────────────
279
+ getHealthChecks(ctx) {
280
+ const mcpPath = this.getServerConfigPath(ctx);
281
+ const hookPath = this.getHookConfigPath(ctx);
282
+ const connectorId = ctx.connector.id;
283
+ const homeBin = ctx.homeBinPath;
284
+ const hookEvents = ctx.connector.hookEvents;
285
+ return [
286
+ {
287
+ name: `${this.name}: mcp.json present`,
288
+ check: () => existsSync(mcpPath) ? { status: "OK", detail: mcpPath } : { status: "FAIL", detail: `not found: ${mcpPath}` }
289
+ },
290
+ {
291
+ name: `${this.name}: server entry registered`,
292
+ check: () => {
293
+ const cfg = this.readJson(mcpPath);
294
+ const bucket = cfg?.[MCP_ROOT_KEY];
295
+ if (!cfg || !bucket) {
296
+ return { status: "FAIL", detail: `no ${MCP_ROOT_KEY} in ${mcpPath}` };
297
+ }
298
+ return connectorId in bucket ? { status: "OK", detail: `${MCP_ROOT_KEY}.${connectorId} present` } : {
299
+ status: "FAIL",
300
+ detail: `no ${MCP_ROOT_KEY}.${connectorId} in ${mcpPath}`
301
+ };
302
+ }
303
+ },
304
+ {
305
+ name: `${this.name}: hook command registered`,
306
+ check: () => {
307
+ if (hookEvents.length === 0) {
308
+ return { status: "OK", detail: "no hooks declared" };
309
+ }
310
+ const file = this.readJson(hookPath);
311
+ if (!file) return { status: "FAIL", detail: `cannot read ${hookPath}` };
312
+ const hooks = file.hooks ?? {};
313
+ const registered = Object.values(hooks).some(
314
+ (entries) => (entries ?? []).some(
315
+ (e) => (e.hooks ?? []).some(
316
+ (h) => isHomeBinHookCommand(h.command, homeBin, connectorId)
317
+ )
318
+ )
319
+ );
320
+ return registered ? { status: "OK", detail: "hook command present" } : { status: "FAIL", detail: `no hook for ${connectorId} in ${hookPath}` };
321
+ }
322
+ }
323
+ ];
324
+ }
325
+ // ── Runtime: parse Droid stdin JSON → normalized event ────────────────────
326
+ parseEvent(event, raw) {
327
+ const input = raw ?? {};
328
+ const connectorId = typeof input.connector === "string" ? input.connector : "";
329
+ const sessionId = typeof input.session_id === "string" ? input.session_id : "";
330
+ const projectDir = typeof input.cwd === "string" ? input.cwd : void 0;
331
+ const base = {
332
+ hostPlatform: HOST,
333
+ connectorId,
334
+ sessionId,
335
+ raw,
336
+ ...projectDir !== void 0 ? { projectDir } : {}
337
+ };
338
+ switch (event) {
339
+ case "PreToolUse": {
340
+ const ev = {
341
+ ...base,
342
+ toolName: input.tool_name ?? "",
343
+ toolInput: input.tool_input ?? {}
344
+ };
345
+ return ev;
346
+ }
347
+ case "PostToolUse": {
348
+ const ev = {
349
+ ...base,
350
+ toolName: input.tool_name ?? "",
351
+ toolInput: input.tool_input ?? {},
352
+ ...toolResponseToString(input.tool_response) !== void 0 ? { toolOutput: toolResponseToString(input.tool_response) } : {}
353
+ };
354
+ return ev;
355
+ }
356
+ case "UserPromptSubmit": {
357
+ const ev = {
358
+ ...base,
359
+ prompt: typeof input.prompt === "string" ? input.prompt : ""
360
+ };
361
+ return ev;
362
+ }
363
+ case "Stop": {
364
+ const ev = {
365
+ ...base,
366
+ ...typeof input.stop_hook_active === "boolean" ? { stopHookActive: input.stop_hook_active } : {}
367
+ };
368
+ return ev;
369
+ }
370
+ default: {
371
+ throw new Error(`unsupported droid hook event: ${String(event)}`);
372
+ }
373
+ }
374
+ }
375
+ // ── Runtime: normalized response → Droid native (Claude-shaped) hook reply ─
376
+ formatReply(event, response) {
377
+ const hookEventName = event;
378
+ const decision = response.decision ?? "allow";
379
+ if (decision === "deny") {
380
+ return this.stdout({
381
+ hookSpecificOutput: {
382
+ hookEventName,
383
+ permissionDecision: "deny",
384
+ permissionDecisionReason: response.reason ?? "Blocked by hook"
385
+ }
386
+ });
387
+ }
388
+ if (decision === "ask") {
389
+ return this.stdout({
390
+ hookSpecificOutput: {
391
+ hookEventName,
392
+ permissionDecision: "ask",
393
+ permissionDecisionReason: response.reason ?? "Confirmation required by hook"
394
+ }
395
+ });
396
+ }
397
+ if (decision === "context" && response.additionalContext) {
398
+ return this.stdout({
399
+ hookSpecificOutput: { hookEventName, additionalContext: response.additionalContext }
400
+ });
401
+ }
402
+ return { exitCode: 0 };
403
+ }
404
+ stdout(payload) {
405
+ return { exitCode: 0, stdout: JSON.stringify(payload) };
406
+ }
407
+ };
408
+ function toolResponseToString(value) {
409
+ if (value == null) return void 0;
410
+ if (typeof value === "string") return value;
411
+ try {
412
+ return JSON.stringify(value);
413
+ } catch {
414
+ return String(value);
415
+ }
416
+ }
417
+ var adapter = new DroidAdapter();
418
+ var droid_default = adapter;
419
+ export {
420
+ DroidAdapter,
421
+ adapter,
422
+ droid_default as default
423
+ };
424
+ //# sourceMappingURL=droid-KN6VRMMT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/adapters/droid/index.ts"],"sourcesContent":["/**\n * adapters/droid — Droid (Factory AI) platform adapter for agent-connector.\n *\n * Droid is a **json-stdio** host with TWO native config surfaces that live in\n * DIFFERENT files (so getServerConfigPath ≠ getHookConfigPath):\n *\n * 1. MCP servers — `mcp.json` (root key `mcpServers`):\n * - user scope → ~/.factory/mcp.json\n * - project scope → <projectDir>/.factory/mcp.json\n * Native stdio entry shape: { type:\"stdio\", command, args, env, disabled };\n * a remote server registers a URL ({ type:\"http\", url, headers, disabled }).\n *\n * 2. Hooks — a SEPARATE `hooks.json` (root key `hooks`) under the same\n * `.factory` dir. Droid ships a FULL Claude-compatible lifecycle hook\n * system (live-confirmed): PascalCase event names, Claude snake_case stdin\n * wire fields, and a Claude-shaped `hookSpecificOutput` reply. Hook\n * registrations use the Claude NESTED-rule shape:\n * { hooks: { <Event>: [ { matcher?, hooks:[{ type:\"command\", command }] } ] } }\n *\n * Supported events (Claude-compatible): PreToolUse, PostToolUse,\n * UserPromptSubmit, Stop. Droid exposes no PreCompact / SessionStart /\n * SessionEnd / Notification, so those degrade to a warn/skip at install time.\n *\n * Reply protocol is Claude-shaped JSON on stdout (exit 0 + `hookSpecificOutput`\n * with permissionDecision allow|deny|ask, plus additionalContext). Droid cannot\n * rewrite already-emitted tool output, so canModifyOutput is false; it CAN\n * inject session context (additionalContext) so canInjectSessionContext is true.\n *\n * Env handling: env/header/url refs are resolved to literals at install time via\n * resolveEnvRefsDeep — the safe default matching the Kiro/Qwen adapters. Droid\n * also accepts native ${VAR}, but resolve-to-literal avoids surprises.\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, HookReply, InstallContext, NormalizedEvent } from \"../spi.js\";\nimport type {\n ChangeRecord,\n DetectedPlatform,\n HealthCheck,\n HookEventName,\n HookParadigm,\n HookResponse,\n PlatformCapabilities,\n PlatformId,\n PostToolUseEvent,\n PreToolUseEvent,\n ServerDef,\n StopEvent,\n Transport,\n UserPromptSubmitEvent,\n} from \"../../core/types.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 = \"droid\";\nconst MCP_ROOT_KEY = \"mcpServers\";\n\n/**\n * Canonical events Droid actually fires. Droid's hook event names are\n * Claude-identical (PascalCase), so the canonical name is registered directly.\n * PreCompact / SessionStart / SessionEnd / Notification have no Droid equivalent\n * and are reported as a warn/skip at install time.\n */\nconst SUPPORTED_EVENTS: ReadonlySet<HookEventName> = new Set<HookEventName>([\n \"PreToolUse\",\n \"PostToolUse\",\n \"UserPromptSubmit\",\n \"Stop\",\n]);\n\n/**\n * Native MCP server entry shapes Droid accepts under `mcpServers`.\n * A stdio entry carries an explicit `type: \"stdio\"` discriminator and a\n * `disabled` flag; remote transports register a URL.\n */\ninterface DroidStdioServer {\n type: \"stdio\";\n command: string;\n args?: string[];\n env?: Record<string, string>;\n disabled: boolean;\n}\ninterface DroidHttpServer {\n type: \"http\";\n url: string;\n headers?: Record<string, string>;\n disabled: boolean;\n}\n\n/** A single Droid native hook registration entry (Claude-shaped, nested). */\ninterface DroidHookEntry {\n matcher: string;\n hooks: Array<{ type: \"command\"; command: string }>;\n}\n\n/** The shape of Droid's hooks.json (only the parts we touch). */\ninterface DroidHooksFile {\n hooks?: Record<string, DroidHookEntry[]>;\n [key: string]: unknown;\n}\n\n/** Raw Droid CLI hook stdin payload (Claude-compatible snake_case wire fields). */\ninterface DroidWireInput {\n session_id?: string;\n transcript_path?: string;\n cwd?: string;\n hook_event_name?: string;\n tool_name?: string;\n tool_input?: Record<string, unknown>;\n tool_response?: unknown;\n prompt?: string;\n stop_hook_active?: boolean;\n /** Injected by the entrypoint so the runtime knows which connector to dispatch. */\n connector?: unknown;\n}\n\nexport class DroidAdapter extends BaseAdapter implements Adapter {\n readonly id: PlatformId = HOST;\n readonly name = \"Droid (Factory)\";\n readonly paradigm: HookParadigm = \"json-stdio\";\n\n readonly capabilities: PlatformCapabilities = {\n preToolUse: true,\n postToolUse: true,\n preCompact: false,\n sessionStart: false,\n sessionEnd: false,\n userPromptSubmit: true,\n stop: true,\n notification: false,\n // Droid's PreToolUse can deny/ask (Claude-shaped), but it cannot rewrite\n // already-emitted tool output. canModifyArgs left false until confirmed.\n canModifyArgs: false,\n canModifyOutput: false,\n // Droid honors additionalContext on the stdout reply.\n canInjectSessionContext: true,\n // Droid registers stdio and Streamable HTTP MCP servers.\n transports: [\"stdio\", \"http\"],\n };\n\n // ── Detection ────────────────────────────────────────────────────────────\n\n detectInstalled(projectDir: string): DetectedPlatform {\n const userDir = join(homedir(), \".factory\");\n const userMcp = join(userDir, \"mcp.json\");\n const projDir = join(projectDir, \".factory\");\n const projMcp = join(projDir, \"mcp.json\");\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 Droid config (${scope}) at ${configPath}`\n : `no .factory 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, \".factory\")\n : join(homedir(), \".factory\");\n }\n\n getServerConfigPath(ctx: InstallContext): string {\n return join(this.getConfigDir(ctx), \"mcp.json\");\n }\n\n /** Hooks live in a SEPARATE hooks.json under the same `.factory` dir. */\n getHookConfigPath(ctx: InstallContext): string {\n return join(this.getConfigDir(ctx), \"hooks.json\");\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 droid\"\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 Droid's native mcpServers entry. */\n private renderServerEntry(\n ctx: InstallContext,\n server: ServerDef,\n ): DroidStdioServer | DroidHttpServer {\n const transport: Transport = server.transport;\n const disabled = server.enabled === false;\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 every ${env:VAR} to a literal at install time (safe path).\n const entry: DroidStdioServer = {\n type: \"stdio\",\n command: resolveEnvRefsDeep(command),\n disabled,\n };\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 // http (and any other remote transport) — Droid registers a URL.\n const entry: DroidHttpServer = {\n type: \"http\",\n url: resolveEnvRefsDeep(server.url ?? \"\"),\n disabled,\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 (the safe path; Droid would also accept native ${VAR}).\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 (separate hooks.json, nested-rule shape) ─────\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 droid\" }];\n }\n if (connector.hookEvents.length === 0) {\n return [{ platform: this.id, action: \"skip\", detail: \"connector declares no hooks\" }];\n }\n\n const hookPath = this.getHookConfigPath(ctx);\n // Merge into any existing hooks.json so the user's own hooks survive.\n const file = this.readJson<DroidHooksFile>(hookPath) ?? {};\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 changes.push({\n platform: this.id,\n action: \"warn\",\n path: hookPath,\n detail: `${event} has no Droid hook equivalent — skipped`,\n });\n continue;\n }\n\n // Droid's event names are Claude-identical (PascalCase) — register the\n // canonical event name directly.\n const command = buildHomeBinHookCommand(ctx.homeBinPath, HOST, event, connector.id);\n const matcher = connector.hooks[event]?.matcher ?? \"\";\n const entry: DroidHookEntry = {\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: hookPath,\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: hookPath,\n detail: `hooks.${event}`,\n });\n } else {\n bucket.push(entry);\n changes.push({\n platform: this.id,\n action: \"create\",\n path: hookPath,\n detail: `hooks.${event}`,\n });\n }\n mutated = true;\n }\n\n if (mutated) this.writeJson(hookPath, file, ctx.dryRun);\n return changes;\n }\n\n uninstallHooks(ctx: InstallContext): ChangeRecord[] {\n const hookPath = this.getHookConfigPath(ctx);\n const file = this.readJson<DroidHooksFile>(hookPath);\n const hooks = file?.hooks;\n if (!file || !hooks) {\n return [\n {\n platform: this.id,\n action: \"skip\",\n path: hookPath,\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. The\n // id token is anchored (isHomeBinHookCommand) so a shared-prefix connector\n // id is never affected.\n const next: DroidHookEntry[] = [];\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: hookPath,\n detail: `hooks.${event} (${removed})`,\n });\n mutated = true;\n }\n }\n\n if (mutated) this.writeJson(hookPath, file, ctx.dryRun);\n if (changes.length === 0) {\n changes.push({\n platform: this.id,\n action: \"skip\",\n path: hookPath,\n detail: \"no matching hook entries\",\n });\n }\n return changes;\n }\n\n private entryHasOurCommand(entry: DroidHookEntry, ctx: InstallContext): boolean {\n return (entry.hooks ?? []).some((h) => this.isOurCommand(h.command, ctx));\n }\n\n /** True when a hook command references our home binary AND this connector id\n * (anchored so a shared-prefix id can't collide — see isHomeBinHookCommand). */\n private isOurCommand(command: string | undefined, ctx: InstallContext): boolean {\n return isHomeBinHookCommand(command, ctx.homeBinPath, ctx.connector.id);\n }\n\n // ── Diagnostics ──────────────────────────────────────────────────────────\n\n override getHealthChecks(ctx: InstallContext): readonly HealthCheck[] {\n const mcpPath = this.getServerConfigPath(ctx);\n const hookPath = this.getHookConfigPath(ctx);\n const connectorId = ctx.connector.id;\n const homeBin = ctx.homeBinPath;\n const hookEvents = ctx.connector.hookEvents;\n return [\n {\n name: `${this.name}: mcp.json 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 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}: hook command registered`,\n check: () => {\n if (hookEvents.length === 0) {\n return { status: \"OK\", detail: \"no hooks declared\" };\n }\n const file = this.readJson<DroidHooksFile>(hookPath);\n if (!file) return { status: \"FAIL\", detail: `cannot read ${hookPath}` };\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\" }\n : { status: \"FAIL\", detail: `no hook for ${connectorId} in ${hookPath}` };\n },\n },\n ];\n }\n\n // ── Runtime: parse Droid stdin JSON → normalized event ────────────────────\n\n parseEvent(event: HookEventName, raw: unknown): NormalizedEvent {\n const input = (raw ?? {}) as DroidWireInput;\n const connectorId = typeof input.connector === \"string\" ? input.connector : \"\";\n const sessionId = typeof input.session_id === \"string\" ? input.session_id : \"\";\n const projectDir = typeof input.cwd === \"string\" ? input.cwd : undefined;\n\n const base = {\n hostPlatform: HOST,\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.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 };\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 \"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 default: {\n // Droid never delivers PreCompact / SessionStart / SessionEnd /\n // Notification (no native equivalent). If the runtime dispatches one\n // anyway, surface it loudly rather than silently mis-parse.\n throw new Error(`unsupported droid hook event: ${String(event)}`);\n }\n }\n }\n\n // ── Runtime: normalized response → Droid native (Claude-shaped) hook reply ─\n\n formatReply(event: HookEventName, response: HookResponse): HookReply {\n const hookEventName = event;\n const decision = response.decision ?? \"allow\";\n\n // deny → block the action with a reason (exit 0; JSON carries the decision).\n if (decision === \"deny\") {\n return this.stdout({\n hookSpecificOutput: {\n hookEventName,\n permissionDecision: \"deny\",\n permissionDecisionReason: response.reason ?? \"Blocked by hook\",\n },\n });\n }\n\n // ask → prompt the user to confirm.\n if (decision === \"ask\") {\n return this.stdout({\n hookSpecificOutput: {\n hookEventName,\n permissionDecision: \"ask\",\n permissionDecisionReason: response.reason ?? \"Confirmation required by hook\",\n },\n });\n }\n\n // context → inject soft guidance (Droid honors additionalContext).\n if (decision === \"context\" && response.additionalContext) {\n return this.stdout({\n hookSpecificOutput: { hookEventName, additionalContext: response.additionalContext },\n });\n }\n\n // allow / modify (unsupported — exit-code/decision protocol only) / void →\n // 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\n/** Coerce a Droid PostToolUse `tool_response` into a string for the normalized event. */\nfunction toolResponseToString(value: unknown): string | undefined {\n if (value == null) return undefined;\n if (typeof value === \"string\") return value;\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n}\n\nexport const adapter = new DroidAdapter();\nexport default adapter;\n"],"mappings":";;;;;;;;;;;;;;;;;AAiCA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AACxB,SAAS,YAAY;AA4BrB,IAAM,OAAmB;AACzB,IAAM,eAAe;AAQrB,IAAM,mBAA+C,oBAAI,IAAmB;AAAA,EAC1E;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAgDM,IAAM,eAAN,cAA2B,YAA+B;AAAA,EACtD,KAAiB;AAAA,EACjB,OAAO;AAAA,EACP,WAAyB;AAAA,EAEzB,eAAqC;AAAA,IAC5C,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,eAAe;AAAA,IACf,iBAAiB;AAAA;AAAA,IAEjB,yBAAyB;AAAA;AAAA,IAEzB,YAAY,CAAC,SAAS,MAAM;AAAA,EAC9B;AAAA;AAAA,EAIA,gBAAgB,YAAsC;AACpD,UAAM,UAAU,KAAK,QAAQ,GAAG,UAAU;AAC1C,UAAM,UAAU,KAAK,SAAS,UAAU;AACxC,UAAM,UAAU,KAAK,YAAY,UAAU;AAC3C,UAAM,UAAU,KAAK,SAAS,UAAU;AAExC,UAAM,gBAAgB,WAAW,OAAO,KAAK,WAAW,OAAO;AAC/D,UAAM,gBAAgB,WAAW,OAAO,KAAK,WAAW,OAAO;AAC/D,UAAM,YAAY,iBAAiB;AACnC,UAAM,QAAQ,iBAAiB,CAAC,gBAAgB,YAAY;AAC5D,UAAM,aAAa,UAAU,YAAY,UAAU;AAEnD,WAAO;AAAA,MACL,IAAI,KAAK;AAAA,MACT,MAAM,KAAK;AAAA,MACX;AAAA,MACA,UAAU,KAAK;AAAA,MACf,cAAc,KAAK;AAAA,MACnB;AAAA,MACA;AAAA,MACA,QA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