context-gatekeeper 0.3.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 (305) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +774 -0
  3. package/README.zh.md +765 -0
  4. package/bin/context-gatekeeper-cli.js +60 -0
  5. package/dist/api/gdpr.d.ts +104 -0
  6. package/dist/api/gdpr.d.ts.map +1 -0
  7. package/dist/api/gdpr.js +229 -0
  8. package/dist/api/gdpr.js.map +1 -0
  9. package/dist/api/health-check.d.ts +13 -0
  10. package/dist/api/health-check.d.ts.map +1 -0
  11. package/dist/api/health-check.js +2 -0
  12. package/dist/api/health-check.js.map +1 -0
  13. package/dist/api/index.d.ts +7 -0
  14. package/dist/api/index.d.ts.map +1 -0
  15. package/dist/api/index.js +8 -0
  16. package/dist/api/index.js.map +1 -0
  17. package/dist/api/observability.d.ts +39 -0
  18. package/dist/api/observability.d.ts.map +1 -0
  19. package/dist/api/observability.js +132 -0
  20. package/dist/api/observability.js.map +1 -0
  21. package/dist/api/session-manager.d.ts +41 -0
  22. package/dist/api/session-manager.d.ts.map +1 -0
  23. package/dist/api/session-manager.js +129 -0
  24. package/dist/api/session-manager.js.map +1 -0
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +7 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/mcp/server.d.ts +8 -0
  30. package/dist/mcp/server.d.ts.map +1 -0
  31. package/dist/mcp/server.js +613 -0
  32. package/dist/mcp/server.js.map +1 -0
  33. package/dist/mcp/tools/configure-llm.d.ts +26 -0
  34. package/dist/mcp/tools/configure-llm.d.ts.map +1 -0
  35. package/dist/mcp/tools/configure-llm.js +32 -0
  36. package/dist/mcp/tools/configure-llm.js.map +1 -0
  37. package/dist/mcp/tools/context-compress.d.ts +15 -0
  38. package/dist/mcp/tools/context-compress.d.ts.map +1 -0
  39. package/dist/mcp/tools/context-compress.js +15 -0
  40. package/dist/mcp/tools/context-compress.js.map +1 -0
  41. package/dist/mcp/tools/dual-mode-execute.d.ts +78 -0
  42. package/dist/mcp/tools/dual-mode-execute.d.ts.map +1 -0
  43. package/dist/mcp/tools/dual-mode-execute.js +299 -0
  44. package/dist/mcp/tools/dual-mode-execute.js.map +1 -0
  45. package/dist/mcp/tools/index.d.ts +19 -0
  46. package/dist/mcp/tools/index.d.ts.map +1 -0
  47. package/dist/mcp/tools/index.js +20 -0
  48. package/dist/mcp/tools/index.js.map +1 -0
  49. package/dist/mcp/tools/intelligent-recall.d.ts +67 -0
  50. package/dist/mcp/tools/intelligent-recall.d.ts.map +1 -0
  51. package/dist/mcp/tools/intelligent-recall.js +208 -0
  52. package/dist/mcp/tools/intelligent-recall.js.map +1 -0
  53. package/dist/mcp/tools/memory-anchor.d.ts +13 -0
  54. package/dist/mcp/tools/memory-anchor.d.ts.map +1 -0
  55. package/dist/mcp/tools/memory-anchor.js +16 -0
  56. package/dist/mcp/tools/memory-anchor.js.map +1 -0
  57. package/dist/mcp/tools/memory-delete-batch.d.ts +16 -0
  58. package/dist/mcp/tools/memory-delete-batch.d.ts.map +1 -0
  59. package/dist/mcp/tools/memory-delete-batch.js +26 -0
  60. package/dist/mcp/tools/memory-delete-batch.js.map +1 -0
  61. package/dist/mcp/tools/memory-extract.d.ts +68 -0
  62. package/dist/mcp/tools/memory-extract.d.ts.map +1 -0
  63. package/dist/mcp/tools/memory-extract.js +280 -0
  64. package/dist/mcp/tools/memory-extract.js.map +1 -0
  65. package/dist/mcp/tools/memory-recall.d.ts +42 -0
  66. package/dist/mcp/tools/memory-recall.d.ts.map +1 -0
  67. package/dist/mcp/tools/memory-recall.js +37 -0
  68. package/dist/mcp/tools/memory-recall.js.map +1 -0
  69. package/dist/mcp/tools/memory-report-usage.d.ts +17 -0
  70. package/dist/mcp/tools/memory-report-usage.d.ts.map +1 -0
  71. package/dist/mcp/tools/memory-report-usage.js +15 -0
  72. package/dist/mcp/tools/memory-report-usage.js.map +1 -0
  73. package/dist/mcp/tools/memory-search.d.ts +43 -0
  74. package/dist/mcp/tools/memory-search.d.ts.map +1 -0
  75. package/dist/mcp/tools/memory-search.js +38 -0
  76. package/dist/mcp/tools/memory-search.js.map +1 -0
  77. package/dist/mcp/tools/memory-session.d.ts +118 -0
  78. package/dist/mcp/tools/memory-session.d.ts.map +1 -0
  79. package/dist/mcp/tools/memory-session.js +113 -0
  80. package/dist/mcp/tools/memory-session.js.map +1 -0
  81. package/dist/mcp/tools/memory-stats.d.ts +10 -0
  82. package/dist/mcp/tools/memory-stats.d.ts.map +1 -0
  83. package/dist/mcp/tools/memory-stats.js +35 -0
  84. package/dist/mcp/tools/memory-stats.js.map +1 -0
  85. package/dist/mcp/tools/memory-store-batch.d.ts +49 -0
  86. package/dist/mcp/tools/memory-store-batch.d.ts.map +1 -0
  87. package/dist/mcp/tools/memory-store-batch.js +48 -0
  88. package/dist/mcp/tools/memory-store-batch.js.map +1 -0
  89. package/dist/mcp/tools/memory-store.d.ts +37 -0
  90. package/dist/mcp/tools/memory-store.d.ts.map +1 -0
  91. package/dist/mcp/tools/memory-store.js +34 -0
  92. package/dist/mcp/tools/memory-store.js.map +1 -0
  93. package/dist/mcp/tools/project-create.d.ts +16 -0
  94. package/dist/mcp/tools/project-create.d.ts.map +1 -0
  95. package/dist/mcp/tools/project-create.js +14 -0
  96. package/dist/mcp/tools/project-create.js.map +1 -0
  97. package/dist/models/types.d.ts +88 -0
  98. package/dist/models/types.d.ts.map +1 -0
  99. package/dist/models/types.js +19 -0
  100. package/dist/models/types.js.map +1 -0
  101. package/dist/schema/compression.d.ts +7 -0
  102. package/dist/schema/compression.d.ts.map +1 -0
  103. package/dist/schema/compression.js +66 -0
  104. package/dist/schema/compression.js.map +1 -0
  105. package/dist/schema/fulltext-search.d.ts +10 -0
  106. package/dist/schema/fulltext-search.d.ts.map +1 -0
  107. package/dist/schema/fulltext-search.js +73 -0
  108. package/dist/schema/fulltext-search.js.map +1 -0
  109. package/dist/schema/index.d.ts +9 -0
  110. package/dist/schema/index.d.ts.map +1 -0
  111. package/dist/schema/index.js +9 -0
  112. package/dist/schema/index.js.map +1 -0
  113. package/dist/schema/knowledge-graph.d.ts +108 -0
  114. package/dist/schema/knowledge-graph.d.ts.map +1 -0
  115. package/dist/schema/knowledge-graph.js +372 -0
  116. package/dist/schema/knowledge-graph.js.map +1 -0
  117. package/dist/schema/memory-session.d.ts +62 -0
  118. package/dist/schema/memory-session.d.ts.map +1 -0
  119. package/dist/schema/memory-session.js +258 -0
  120. package/dist/schema/memory-session.js.map +1 -0
  121. package/dist/schema/memory.d.ts +84 -0
  122. package/dist/schema/memory.d.ts.map +1 -0
  123. package/dist/schema/memory.js +622 -0
  124. package/dist/schema/memory.js.map +1 -0
  125. package/dist/schema/project.d.ts +8 -0
  126. package/dist/schema/project.d.ts.map +1 -0
  127. package/dist/schema/project.js +68 -0
  128. package/dist/schema/project.js.map +1 -0
  129. package/dist/schema/schema-init.d.ts +2 -0
  130. package/dist/schema/schema-init.d.ts.map +1 -0
  131. package/dist/schema/schema-init.js +199 -0
  132. package/dist/schema/schema-init.js.map +1 -0
  133. package/dist/schema/vector-index.d.ts +28 -0
  134. package/dist/schema/vector-index.d.ts.map +1 -0
  135. package/dist/schema/vector-index.js +179 -0
  136. package/dist/schema/vector-index.js.map +1 -0
  137. package/dist/scripts/agents/base.d.ts +89 -0
  138. package/dist/scripts/agents/base.d.ts.map +1 -0
  139. package/dist/scripts/agents/base.js +148 -0
  140. package/dist/scripts/agents/base.js.map +1 -0
  141. package/dist/scripts/agents/base.ts +193 -0
  142. package/dist/scripts/agents/claude-code.d.ts +21 -0
  143. package/dist/scripts/agents/claude-code.d.ts.map +1 -0
  144. package/dist/scripts/agents/claude-code.js +33 -0
  145. package/dist/scripts/agents/claude-code.js.map +1 -0
  146. package/dist/scripts/agents/claude-code.ts +36 -0
  147. package/dist/scripts/agents/claude-desktop.d.ts +25 -0
  148. package/dist/scripts/agents/claude-desktop.d.ts.map +1 -0
  149. package/dist/scripts/agents/claude-desktop.js +36 -0
  150. package/dist/scripts/agents/claude-desktop.js.map +1 -0
  151. package/dist/scripts/agents/claude-desktop.ts +39 -0
  152. package/dist/scripts/agents/cline.d.ts +22 -0
  153. package/dist/scripts/agents/cline.d.ts.map +1 -0
  154. package/dist/scripts/agents/cline.js +35 -0
  155. package/dist/scripts/agents/cline.js.map +1 -0
  156. package/dist/scripts/agents/cline.ts +38 -0
  157. package/dist/scripts/agents/continue.d.ts +20 -0
  158. package/dist/scripts/agents/continue.d.ts.map +1 -0
  159. package/dist/scripts/agents/continue.js +35 -0
  160. package/dist/scripts/agents/continue.js.map +1 -0
  161. package/dist/scripts/agents/continue.ts +38 -0
  162. package/dist/scripts/agents/cursor.d.ts +27 -0
  163. package/dist/scripts/agents/cursor.d.ts.map +1 -0
  164. package/dist/scripts/agents/cursor.js +38 -0
  165. package/dist/scripts/agents/cursor.js.map +1 -0
  166. package/dist/scripts/agents/cursor.ts +41 -0
  167. package/dist/scripts/cli/config-gen.d.ts +59 -0
  168. package/dist/scripts/cli/config-gen.d.ts.map +1 -0
  169. package/dist/scripts/cli/config-gen.js +156 -0
  170. package/dist/scripts/cli/config-gen.js.map +1 -0
  171. package/dist/scripts/cli/config-gen.ts +164 -0
  172. package/dist/scripts/cli/detect.d.ts +42 -0
  173. package/dist/scripts/cli/detect.d.ts.map +1 -0
  174. package/dist/scripts/cli/detect.js +131 -0
  175. package/dist/scripts/cli/detect.js.map +1 -0
  176. package/dist/scripts/cli/detect.ts +162 -0
  177. package/dist/scripts/cli/install.d.ts +31 -0
  178. package/dist/scripts/cli/install.d.ts.map +1 -0
  179. package/dist/scripts/cli/install.js +125 -0
  180. package/dist/scripts/cli/install.js.map +1 -0
  181. package/dist/scripts/cli/install.ts +157 -0
  182. package/dist/scripts/cli/status.d.ts +8 -0
  183. package/dist/scripts/cli/status.d.ts.map +1 -0
  184. package/dist/scripts/cli/status.js +39 -0
  185. package/dist/scripts/cli/status.js.map +1 -0
  186. package/dist/scripts/cli/status.ts +48 -0
  187. package/dist/scripts/cli/uninstall.d.ts +22 -0
  188. package/dist/scripts/cli/uninstall.d.ts.map +1 -0
  189. package/dist/scripts/cli/uninstall.js +141 -0
  190. package/dist/scripts/cli/uninstall.js.map +1 -0
  191. package/dist/scripts/cli/uninstall.ts +157 -0
  192. package/dist/scripts/cli.d.ts +23 -0
  193. package/dist/scripts/cli.d.ts.map +1 -0
  194. package/dist/scripts/cli.js +166 -0
  195. package/dist/scripts/cli.js.map +1 -0
  196. package/dist/scripts/cli.ts +173 -0
  197. package/dist/services/classifier/index.d.ts +36 -0
  198. package/dist/services/classifier/index.d.ts.map +1 -0
  199. package/dist/services/classifier/index.js +104 -0
  200. package/dist/services/classifier/index.js.map +1 -0
  201. package/dist/services/classifier/llm.d.ts +37 -0
  202. package/dist/services/classifier/llm.d.ts.map +1 -0
  203. package/dist/services/classifier/llm.js +119 -0
  204. package/dist/services/classifier/llm.js.map +1 -0
  205. package/dist/services/classifier/rules.d.ts +22 -0
  206. package/dist/services/classifier/rules.d.ts.map +1 -0
  207. package/dist/services/classifier/rules.js +98 -0
  208. package/dist/services/classifier/rules.js.map +1 -0
  209. package/dist/services/compressor/index.d.ts +3 -0
  210. package/dist/services/compressor/index.d.ts.map +1 -0
  211. package/dist/services/compressor/index.js +3 -0
  212. package/dist/services/compressor/index.js.map +1 -0
  213. package/dist/services/compressor/threshold.d.ts +35 -0
  214. package/dist/services/compressor/threshold.d.ts.map +1 -0
  215. package/dist/services/compressor/threshold.js +60 -0
  216. package/dist/services/compressor/threshold.js.map +1 -0
  217. package/dist/services/compressor/trigger.d.ts +24 -0
  218. package/dist/services/compressor/trigger.d.ts.map +1 -0
  219. package/dist/services/compressor/trigger.js +91 -0
  220. package/dist/services/compressor/trigger.js.map +1 -0
  221. package/dist/services/constraint-extractor.d.ts +25 -0
  222. package/dist/services/constraint-extractor.d.ts.map +1 -0
  223. package/dist/services/constraint-extractor.js +97 -0
  224. package/dist/services/constraint-extractor.js.map +1 -0
  225. package/dist/services/database-health.d.ts +22 -0
  226. package/dist/services/database-health.d.ts.map +1 -0
  227. package/dist/services/database-health.js +122 -0
  228. package/dist/services/database-health.js.map +1 -0
  229. package/dist/services/embedding-fixed.d.ts +9 -0
  230. package/dist/services/embedding-fixed.d.ts.map +1 -0
  231. package/dist/services/embedding-fixed.js +70 -0
  232. package/dist/services/embedding-fixed.js.map +1 -0
  233. package/dist/services/embedding-provider.d.ts +79 -0
  234. package/dist/services/embedding-provider.d.ts.map +1 -0
  235. package/dist/services/embedding-provider.js +229 -0
  236. package/dist/services/embedding-provider.js.map +1 -0
  237. package/dist/services/embedding.d.ts +17 -0
  238. package/dist/services/embedding.d.ts.map +1 -0
  239. package/dist/services/embedding.js +99 -0
  240. package/dist/services/embedding.js.map +1 -0
  241. package/dist/services/hnsw-index.d.ts +76 -0
  242. package/dist/services/hnsw-index.d.ts.map +1 -0
  243. package/dist/services/hnsw-index.js +301 -0
  244. package/dist/services/hnsw-index.js.map +1 -0
  245. package/dist/services/llm.d.ts +39 -0
  246. package/dist/services/llm.d.ts.map +1 -0
  247. package/dist/services/llm.js +207 -0
  248. package/dist/services/llm.js.map +1 -0
  249. package/dist/services/memory-tiers.d.ts +75 -0
  250. package/dist/services/memory-tiers.d.ts.map +1 -0
  251. package/dist/services/memory-tiers.js +275 -0
  252. package/dist/services/memory-tiers.js.map +1 -0
  253. package/dist/services/memory.d.ts +33 -0
  254. package/dist/services/memory.d.ts.map +1 -0
  255. package/dist/services/memory.js +209 -0
  256. package/dist/services/memory.js.map +1 -0
  257. package/dist/services/multi-agent-sharing.d.ts +83 -0
  258. package/dist/services/multi-agent-sharing.d.ts.map +1 -0
  259. package/dist/services/multi-agent-sharing.js +278 -0
  260. package/dist/services/multi-agent-sharing.js.map +1 -0
  261. package/dist/services/reranker.d.ts +88 -0
  262. package/dist/services/reranker.d.ts.map +1 -0
  263. package/dist/services/reranker.js +234 -0
  264. package/dist/services/reranker.js.map +1 -0
  265. package/dist/services/triple-extractor.d.ts +35 -0
  266. package/dist/services/triple-extractor.d.ts.map +1 -0
  267. package/dist/services/triple-extractor.js +293 -0
  268. package/dist/services/triple-extractor.js.map +1 -0
  269. package/dist/services/vector-provider.d.ts +40 -0
  270. package/dist/services/vector-provider.d.ts.map +1 -0
  271. package/dist/services/vector-provider.js +225 -0
  272. package/dist/services/vector-provider.js.map +1 -0
  273. package/dist/utils/after-chain-executor.d.ts +26 -0
  274. package/dist/utils/after-chain-executor.d.ts.map +1 -0
  275. package/dist/utils/after-chain-executor.js +135 -0
  276. package/dist/utils/after-chain-executor.js.map +1 -0
  277. package/dist/utils/after-chain.d.ts +94 -0
  278. package/dist/utils/after-chain.d.ts.map +1 -0
  279. package/dist/utils/after-chain.js +155 -0
  280. package/dist/utils/after-chain.js.map +1 -0
  281. package/dist/utils/db.d.ts +29 -0
  282. package/dist/utils/db.d.ts.map +1 -0
  283. package/dist/utils/db.js +201 -0
  284. package/dist/utils/db.js.map +1 -0
  285. package/dist/utils/encryption.d.ts +87 -0
  286. package/dist/utils/encryption.d.ts.map +1 -0
  287. package/dist/utils/encryption.js +175 -0
  288. package/dist/utils/encryption.js.map +1 -0
  289. package/dist/utils/errors.d.ts +35 -0
  290. package/dist/utils/errors.d.ts.map +1 -0
  291. package/dist/utils/errors.js +56 -0
  292. package/dist/utils/errors.js.map +1 -0
  293. package/dist/utils/logger.d.ts +27 -0
  294. package/dist/utils/logger.d.ts.map +1 -0
  295. package/dist/utils/logger.js +177 -0
  296. package/dist/utils/logger.js.map +1 -0
  297. package/dist/utils/priority.d.ts +26 -0
  298. package/dist/utils/priority.d.ts.map +1 -0
  299. package/dist/utils/priority.js +43 -0
  300. package/dist/utils/priority.js.map +1 -0
  301. package/dist/utils/watchdog.d.ts +57 -0
  302. package/dist/utils/watchdog.d.ts.map +1 -0
  303. package/dist/utils/watchdog.js +164 -0
  304. package/dist/utils/watchdog.js.map +1 -0
  305. package/package.json +78 -0
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Continue adapter.
3
+ *
4
+ * Continue.dev reads `.continue/config.json`. This adapter exercises the same
5
+ * MCP server configuration shape that Continue uses (`experimental.modelContextProtocolServers`).
6
+ */
7
+ import { BaseAgentAdapter, AgentConfig } from './base.ts';
8
+ export declare class ContinueAdapter extends BaseAgentAdapter {
9
+ get name(): string;
10
+ buildSpawnCommand(): {
11
+ command: string;
12
+ args: string[];
13
+ env: Record<string, string | undefined>;
14
+ };
15
+ static buildMcpConfig(mcpBin: {
16
+ command: string;
17
+ args: string[];
18
+ }): AgentConfig['mcpConfig'];
19
+ }
20
+ //# sourceMappingURL=continue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"continue.d.ts","sourceRoot":"","sources":["continue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE1D,qBAAa,eAAgB,SAAQ,gBAAgB;IACnD,IAAa,IAAI,IAAI,MAAM,CAE1B;IAEQ,iBAAiB,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;KAAE;IAS1G,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,WAAW,CAAC,WAAW,CAAC;CAc7F"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Continue adapter.
3
+ *
4
+ * Continue.dev reads `.continue/config.json`. This adapter exercises the same
5
+ * MCP server configuration shape that Continue uses (`experimental.modelContextProtocolServers`).
6
+ */
7
+ import { BaseAgentAdapter } from './base.ts';
8
+ export class ContinueAdapter extends BaseAgentAdapter {
9
+ get name() {
10
+ return 'continue';
11
+ }
12
+ buildSpawnCommand() {
13
+ const cliPath = this.config.cliPath ?? 'cn';
14
+ return {
15
+ command: cliPath,
16
+ args: ['--config', this.mcpConfigPath, 'test-mcp'],
17
+ env: this.buildMcpServerEnv(),
18
+ };
19
+ }
20
+ static buildMcpConfig(mcpBin) {
21
+ return {
22
+ experimental: {
23
+ modelContextProtocolServers: [
24
+ {
25
+ name: 'context-gatekeeper',
26
+ command: mcpBin.command,
27
+ args: mcpBin.args,
28
+ transport: 'stdio',
29
+ },
30
+ ],
31
+ },
32
+ };
33
+ }
34
+ }
35
+ //# sourceMappingURL=continue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"continue.js","sourceRoot":"","sources":["continue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAe,MAAM,WAAW,CAAC;AAE1D,MAAM,OAAO,eAAgB,SAAQ,gBAAgB;IACnD,IAAa,IAAI;QACf,OAAO,UAAU,CAAC;IACpB,CAAC;IAEQ,iBAAiB;QACxB,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC;QAC5C,OAAO;YACL,OAAO,EAAE,OAAO;YAChB,IAAI,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;YAClD,GAAG,EAAE,IAAI,CAAC,iBAAiB,EAAE;SAC9B,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,MAA2C;QAC/D,OAAO;YACL,YAAY,EAAE;gBACZ,2BAA2B,EAAE;oBAC3B;wBACE,IAAI,EAAE,oBAAoB;wBAC1B,OAAO,EAAE,MAAM,CAAC,OAAO;wBACvB,IAAI,EAAE,MAAM,CAAC,IAAI;wBACjB,SAAS,EAAE,OAAO;qBACnB;iBACF;aACF;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Continue adapter.
3
+ *
4
+ * Continue.dev reads `.continue/config.json`. This adapter exercises the same
5
+ * MCP server configuration shape that Continue uses (`experimental.modelContextProtocolServers`).
6
+ */
7
+
8
+ import { BaseAgentAdapter, AgentConfig } from './base.ts';
9
+
10
+ export class ContinueAdapter extends BaseAgentAdapter {
11
+ override get name(): string {
12
+ return 'continue';
13
+ }
14
+
15
+ override buildSpawnCommand(): { command: string; args: string[]; env: Record<string, string | undefined> } {
16
+ const cliPath = this.config.cliPath ?? 'cn';
17
+ return {
18
+ command: cliPath,
19
+ args: ['--config', this.mcpConfigPath, 'test-mcp'],
20
+ env: this.buildMcpServerEnv(),
21
+ };
22
+ }
23
+
24
+ static buildMcpConfig(mcpBin: { command: string; args: string[] }): AgentConfig['mcpConfig'] {
25
+ return {
26
+ experimental: {
27
+ modelContextProtocolServers: [
28
+ {
29
+ name: 'context-gatekeeper',
30
+ command: mcpBin.command,
31
+ args: mcpBin.args,
32
+ transport: 'stdio',
33
+ },
34
+ ],
35
+ },
36
+ };
37
+ }
38
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Cursor adapter.
3
+ *
4
+ * Cursor reads `.cursor/mcp.json` from the workspace root and uses the
5
+ * `context-gatekeeper` server definition. This adapter exercises the same
6
+ * configuration shape that Cursor itself reads: the MCP server binary is
7
+ * invoked via stdio using the exact command/args Cursor would use.
8
+ *
9
+ * Since the Cursor desktop app is not scriptable in this environment, the
10
+ * adapter instead spawns the MCP server with the same stdio contract Cursor
11
+ * uses and validates the JSON-RPC handshake against the SDK reference client.
12
+ */
13
+ import { BaseAgentAdapter, AgentConfig } from './base.ts';
14
+ export declare class CursorAdapter extends BaseAgentAdapter {
15
+ get name(): string;
16
+ buildSpawnCommand(): {
17
+ command: string;
18
+ args: string[];
19
+ env: Record<string, string | undefined>;
20
+ };
21
+ /** Build the standard `.cursor/mcp.json` configuration for documentation purposes. */
22
+ static buildMcpConfig(mcpBin: {
23
+ command: string;
24
+ args: string[];
25
+ }): AgentConfig['mcpConfig'];
26
+ }
27
+ //# sourceMappingURL=cursor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["cursor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE1D,qBAAa,aAAc,SAAQ,gBAAgB;IACjD,IAAa,IAAI,IAAI,MAAM,CAE1B;IAEQ,iBAAiB,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;KAAE;IAS1G,sFAAsF;IACtF,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,WAAW,CAAC,WAAW,CAAC;CAU7F"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Cursor adapter.
3
+ *
4
+ * Cursor reads `.cursor/mcp.json` from the workspace root and uses the
5
+ * `context-gatekeeper` server definition. This adapter exercises the same
6
+ * configuration shape that Cursor itself reads: the MCP server binary is
7
+ * invoked via stdio using the exact command/args Cursor would use.
8
+ *
9
+ * Since the Cursor desktop app is not scriptable in this environment, the
10
+ * adapter instead spawns the MCP server with the same stdio contract Cursor
11
+ * uses and validates the JSON-RPC handshake against the SDK reference client.
12
+ */
13
+ import { BaseAgentAdapter } from './base.ts';
14
+ export class CursorAdapter extends BaseAgentAdapter {
15
+ get name() {
16
+ return 'cursor';
17
+ }
18
+ buildSpawnCommand() {
19
+ const cg = this.getMcpServerCommand();
20
+ return {
21
+ command: cg.command,
22
+ args: cg.args,
23
+ env: this.buildMcpServerEnv(),
24
+ };
25
+ }
26
+ /** Build the standard `.cursor/mcp.json` configuration for documentation purposes. */
27
+ static buildMcpConfig(mcpBin) {
28
+ return {
29
+ mcpServers: {
30
+ 'context-gatekeeper': {
31
+ command: mcpBin.command,
32
+ args: mcpBin.args,
33
+ },
34
+ },
35
+ };
36
+ }
37
+ }
38
+ //# sourceMappingURL=cursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.js","sourceRoot":"","sources":["cursor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,gBAAgB,EAAe,MAAM,WAAW,CAAC;AAE1D,MAAM,OAAO,aAAc,SAAQ,gBAAgB;IACjD,IAAa,IAAI;QACf,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEQ,iBAAiB;QACxB,MAAM,EAAE,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACtC,OAAO;YACL,OAAO,EAAE,EAAE,CAAC,OAAO;YACnB,IAAI,EAAE,EAAE,CAAC,IAAI;YACb,GAAG,EAAE,IAAI,CAAC,iBAAiB,EAAE;SAC9B,CAAC;IACJ,CAAC;IAED,sFAAsF;IACtF,MAAM,CAAC,cAAc,CAAC,MAA2C;QAC/D,OAAO;YACL,UAAU,EAAE;gBACV,oBAAoB,EAAE;oBACpB,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,IAAI,EAAE,MAAM,CAAC,IAAI;iBAClB;aACF;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Cursor adapter.
3
+ *
4
+ * Cursor reads `.cursor/mcp.json` from the workspace root and uses the
5
+ * `context-gatekeeper` server definition. This adapter exercises the same
6
+ * configuration shape that Cursor itself reads: the MCP server binary is
7
+ * invoked via stdio using the exact command/args Cursor would use.
8
+ *
9
+ * Since the Cursor desktop app is not scriptable in this environment, the
10
+ * adapter instead spawns the MCP server with the same stdio contract Cursor
11
+ * uses and validates the JSON-RPC handshake against the SDK reference client.
12
+ */
13
+
14
+ import { BaseAgentAdapter, AgentConfig } from './base.ts';
15
+
16
+ export class CursorAdapter extends BaseAgentAdapter {
17
+ override get name(): string {
18
+ return 'cursor';
19
+ }
20
+
21
+ override buildSpawnCommand(): { command: string; args: string[]; env: Record<string, string | undefined> } {
22
+ const cg = this.getMcpServerCommand();
23
+ return {
24
+ command: cg.command,
25
+ args: cg.args,
26
+ env: this.buildMcpServerEnv(),
27
+ };
28
+ }
29
+
30
+ /** Build the standard `.cursor/mcp.json` configuration for documentation purposes. */
31
+ static buildMcpConfig(mcpBin: { command: string; args: string[] }): AgentConfig['mcpConfig'] {
32
+ return {
33
+ mcpServers: {
34
+ 'context-gatekeeper': {
35
+ command: mcpBin.command,
36
+ args: mcpBin.args,
37
+ },
38
+ },
39
+ };
40
+ }
41
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Build the MCP config block that will be merged into the user's agent
3
+ * config file. This is a thin wrapper that picks the right adapter for
4
+ * the target agent and forwards a fixed `mcpBin` pointing at the
5
+ * published npm package.
6
+ */
7
+ import { AgentName } from './detect.ts';
8
+ import type { AgentConfig } from '../agents/base.ts';
9
+ /**
10
+ * Build the launch command the user's agent will run to start the MCP
11
+ * server. The form is platform-aware and depends on whether the package
12
+ * has been globally installed:
13
+ *
14
+ * - Global install present (any platform):
15
+ * command = <absolute path to system node>
16
+ * args = [<absolute path to dist/mcp/server.js>]
17
+ * This avoids the `npx` dance entirely, sidesteps the Windows
18
+ * npx-cli.js relative-path bug, and does not require network access.
19
+ *
20
+ * - No global install (e.g. running from source only):
21
+ * POSIX: `npx -y context-gatekeeper`
22
+ * Windows: `cmd /c npx -y context-gatekeeper`
23
+ * This is a fallback that only works once the package is published
24
+ * to a registry the host can reach.
25
+ */
26
+ export declare function buildMcpBin(): {
27
+ command: string;
28
+ args: string[];
29
+ };
30
+ export declare const PUBLISHED_PACKAGE = "context-gatekeeper";
31
+ /**
32
+ * The launch command the user's agent will run to start the MCP server.
33
+ * Computed at import time via {@link buildMcpBin}. Kept as a constant
34
+ * for backward compatibility with code that still imports it; new code
35
+ * should call `buildMcpBin()` directly.
36
+ */
37
+ export declare const PUBLISHED_MCP_BIN: {
38
+ command: string;
39
+ args: string[];
40
+ };
41
+ /**
42
+ * Build the config block for a given agent. The result is a partial config
43
+ * object (e.g. `{ mcpServers: { 'context-gatekeeper': {...} } }`) that will
44
+ * be merged into the existing file.
45
+ */
46
+ export declare function buildConfigBlock(agent: AgentName): AgentConfig['mcpConfig'];
47
+ /**
48
+ * The key the agent stores our server under. Used by install/uninstall
49
+ * to find and remove the entry. The value is the same regardless of
50
+ * agent because we always register under the canonical
51
+ * `context-gatekeeper` name.
52
+ *
53
+ * - Cursor / Claude Desktop / Cline / Claude Code: top-level key under
54
+ * `mcpServers`.
55
+ * - Continue: entry inside `experimental.modelContextProtocolServers`,
56
+ * identified by the entry's `name` field (not a key).
57
+ */
58
+ export declare const GATEKEEPER_KEY = "context-gatekeeper";
59
+ //# sourceMappingURL=config-gen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-gen.d.ts","sourceRoot":"","sources":["config-gen.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAwErD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CASjE;AAED,eAAO,MAAM,iBAAiB,uBAAuB,CAAC;AAEtD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAkB,CAAC;AAkBpF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,WAAW,CAAC,WAAW,CAAC,CAE3E;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Build the MCP config block that will be merged into the user's agent
3
+ * config file. This is a thin wrapper that picks the right adapter for
4
+ * the target agent and forwards a fixed `mcpBin` pointing at the
5
+ * published npm package.
6
+ */
7
+ import { existsSync, readFileSync } from 'node:fs';
8
+ import { join, resolve as resolvePath } from 'node:path';
9
+ import { createRequire } from 'node:module';
10
+ import { CursorAdapter } from '../agents/cursor.ts';
11
+ import { ClaudeDesktopAdapter } from '../agents/claude-desktop.ts';
12
+ import { ClineAdapter } from '../agents/cline.ts';
13
+ import { ContinueAdapter } from '../agents/continue.ts';
14
+ import { ClaudeCodeAdapter } from '../agents/claude-code.ts';
15
+ /**
16
+ * `createRequire` from `node:module` is the canonical way to use CJS
17
+ * `require()` from ESM sources. Direct `require('node:fs')` works in CJS
18
+ * but throws `require is not defined` when this file is loaded via
19
+ * tsx/Node's ESM loader (which is the path used by `scripts/cli.ts`).
20
+ */
21
+ const cjs = createRequire(import.meta.url);
22
+ const childProcess = cjs('node:child_process');
23
+ /**
24
+ * Resolve an absolute, system-level `node` binary path. Cursor ships its
25
+ * own bundled node at `resources/helpers/node.exe`; we want to avoid
26
+ * baking that path into a user's `mcp.json`, because:
27
+ * 1. It pins the install to this specific Cursor install directory.
28
+ * 2. The bundled node lacks a few npm modules a published
29
+ * context-gatekeeper may rely on (e.g. sql.js native bindings).
30
+ *
31
+ * Strategy: parse `where node` (Windows) or `which node` (POSIX) and
32
+ * take the first result that is NOT the Cursor bundle. Fall back to
33
+ * `process.execPath` only if both lookups fail — for non-Windows or
34
+ * when no `where`/`which` is available (rare).
35
+ */
36
+ function resolveSystemNode() {
37
+ const isWin = process.platform === 'win32';
38
+ const cmd = isWin ? 'where node' : 'which node';
39
+ try {
40
+ const out = childProcess.execSync(cmd, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
41
+ const lines = out.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
42
+ // Reject anything that lives under Cursor's installation.
43
+ const nonCursor = lines.find((p) => !/cursor/i.test(p) && !/helpers\/node(\.exe)?$/i.test(p));
44
+ if (nonCursor)
45
+ return nonCursor;
46
+ if (lines.length > 0)
47
+ return lines[0];
48
+ }
49
+ catch {
50
+ // `where`/`which` failed; fall through to the safe default below.
51
+ }
52
+ // As a last resort, use this process's node. On POSIX this is correct;
53
+ // on Windows it may be the Cursor bundle, but at that point the user
54
+ // likely has no system node at all and this is the best we can do.
55
+ return process.execPath;
56
+ }
57
+ /**
58
+ * Resolve the absolute path to the *published* context-gatekeeper's
59
+ * `dist/mcp/server.js`. We rely on `npm root -g` because the recommended
60
+ * install path for end users is `npm i -g context-gatekeeper`, which
61
+ * puts a real directory under the global modules root.
62
+ *
63
+ * Returns `null` when no global install exists (e.g. the user has only
64
+ * run the package from source). Callers fall back to `npx` in that case.
65
+ */
66
+ function resolveGlobalServerBin() {
67
+ try {
68
+ const root = childProcess.execSync('npm root -g', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
69
+ const pkgRoot = resolvePath(root, PUBLISHED_PACKAGE);
70
+ const pkgJsonPath = join(pkgRoot, 'package.json');
71
+ if (!existsSync(pkgJsonPath))
72
+ return null;
73
+ const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8'));
74
+ if (pkg.name !== PUBLISHED_PACKAGE)
75
+ return null;
76
+ const relBin = pkg.bin?.[PUBLISHED_PACKAGE];
77
+ if (!relBin)
78
+ return null;
79
+ return resolvePath(pkgRoot, relBin);
80
+ }
81
+ catch (err) {
82
+ console.error('[config-gen] resolveGlobalServerBin failed:', err.message);
83
+ return null;
84
+ }
85
+ }
86
+ /**
87
+ * Build the launch command the user's agent will run to start the MCP
88
+ * server. The form is platform-aware and depends on whether the package
89
+ * has been globally installed:
90
+ *
91
+ * - Global install present (any platform):
92
+ * command = <absolute path to system node>
93
+ * args = [<absolute path to dist/mcp/server.js>]
94
+ * This avoids the `npx` dance entirely, sidesteps the Windows
95
+ * npx-cli.js relative-path bug, and does not require network access.
96
+ *
97
+ * - No global install (e.g. running from source only):
98
+ * POSIX: `npx -y context-gatekeeper`
99
+ * Windows: `cmd /c npx -y context-gatekeeper`
100
+ * This is a fallback that only works once the package is published
101
+ * to a registry the host can reach.
102
+ */
103
+ export function buildMcpBin() {
104
+ const globalBin = resolveGlobalServerBin();
105
+ if (globalBin) {
106
+ return { command: resolveSystemNode(), args: [globalBin] };
107
+ }
108
+ if (process.platform === 'win32') {
109
+ return { command: 'cmd', args: ['/c', 'npx', '-y', PUBLISHED_PACKAGE] };
110
+ }
111
+ return { command: 'npx', args: ['-y', PUBLISHED_PACKAGE] };
112
+ }
113
+ export const PUBLISHED_PACKAGE = 'context-gatekeeper';
114
+ /**
115
+ * The launch command the user's agent will run to start the MCP server.
116
+ * Computed at import time via {@link buildMcpBin}. Kept as a constant
117
+ * for backward compatibility with code that still imports it; new code
118
+ * should call `buildMcpBin()` directly.
119
+ */
120
+ export const PUBLISHED_MCP_BIN = buildMcpBin();
121
+ /** Map agent name to the adapter class whose `buildMcpConfig` we want. */
122
+ function pickAdapter(agent) {
123
+ switch (agent) {
124
+ case 'cursor':
125
+ return CursorAdapter.buildMcpConfig.bind(CursorAdapter);
126
+ case 'claude-desktop':
127
+ return ClaudeDesktopAdapter.buildMcpConfig.bind(ClaudeDesktopAdapter);
128
+ case 'cline':
129
+ return ClineAdapter.buildMcpConfig.bind(ClineAdapter);
130
+ case 'continue':
131
+ return ContinueAdapter.buildMcpConfig.bind(ContinueAdapter);
132
+ case 'claude-code':
133
+ return ClaudeCodeAdapter.buildMcpConfig.bind(ClaudeCodeAdapter);
134
+ }
135
+ }
136
+ /**
137
+ * Build the config block for a given agent. The result is a partial config
138
+ * object (e.g. `{ mcpServers: { 'context-gatekeeper': {...} } }`) that will
139
+ * be merged into the existing file.
140
+ */
141
+ export function buildConfigBlock(agent) {
142
+ return pickAdapter(agent)(PUBLISHED_MCP_BIN);
143
+ }
144
+ /**
145
+ * The key the agent stores our server under. Used by install/uninstall
146
+ * to find and remove the entry. The value is the same regardless of
147
+ * agent because we always register under the canonical
148
+ * `context-gatekeeper` name.
149
+ *
150
+ * - Cursor / Claude Desktop / Cline / Claude Code: top-level key under
151
+ * `mcpServers`.
152
+ * - Continue: entry inside `experimental.modelContextProtocolServers`,
153
+ * identified by the entry's `name` field (not a key).
154
+ */
155
+ export const GATEKEEPER_KEY = 'context-gatekeeper';
156
+ //# sourceMappingURL=config-gen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-gen.js","sourceRoot":"","sources":["config-gen.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Build the MCP config block that will be merged into the user's agent
3
+ * config file. This is a thin wrapper that picks the right adapter for
4
+ * the target agent and forwards a fixed `mcpBin` pointing at the
5
+ * published npm package.
6
+ */
7
+
8
+ import { existsSync, readFileSync } from 'node:fs';
9
+ import { join, resolve as resolvePath } from 'node:path';
10
+ import { createRequire } from 'node:module';
11
+
12
+ import { AgentName } from './detect.ts';
13
+ import { CursorAdapter } from '../agents/cursor.ts';
14
+ import { ClaudeDesktopAdapter } from '../agents/claude-desktop.ts';
15
+ import { ClineAdapter } from '../agents/cline.ts';
16
+ import { ContinueAdapter } from '../agents/continue.ts';
17
+ import { ClaudeCodeAdapter } from '../agents/claude-code.ts';
18
+ import type { AgentConfig } from '../agents/base.ts';
19
+
20
+ /**
21
+ * `createRequire` from `node:module` is the canonical way to use CJS
22
+ * `require()` from ESM sources. Direct `require('node:fs')` works in CJS
23
+ * but throws `require is not defined` when this file is loaded via
24
+ * tsx/Node's ESM loader (which is the path used by `scripts/cli.ts`).
25
+ */
26
+ const cjs = createRequire(import.meta.url);
27
+ const childProcess = cjs('node:child_process') as typeof import('node:child_process');
28
+
29
+ /**
30
+ * Resolve an absolute, system-level `node` binary path. Cursor ships its
31
+ * own bundled node at `resources/helpers/node.exe`; we want to avoid
32
+ * baking that path into a user's `mcp.json`, because:
33
+ * 1. It pins the install to this specific Cursor install directory.
34
+ * 2. The bundled node lacks a few npm modules a published
35
+ * context-gatekeeper may rely on (e.g. sql.js native bindings).
36
+ *
37
+ * Strategy: parse `where node` (Windows) or `which node` (POSIX) and
38
+ * take the first result that is NOT the Cursor bundle. Fall back to
39
+ * `process.execPath` only if both lookups fail — for non-Windows or
40
+ * when no `where`/`which` is available (rare).
41
+ */
42
+ function resolveSystemNode(): string {
43
+ const isWin = process.platform === 'win32';
44
+ const cmd = isWin ? 'where node' : 'which node';
45
+ try {
46
+ const out = childProcess.execSync(cmd, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
47
+ const lines = out.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
48
+ // Reject anything that lives under Cursor's installation.
49
+ const nonCursor = lines.find((p) => !/cursor/i.test(p) && !/helpers\/node(\.exe)?$/i.test(p));
50
+ if (nonCursor) return nonCursor;
51
+ if (lines.length > 0) return lines[0];
52
+ } catch {
53
+ // `where`/`which` failed; fall through to the safe default below.
54
+ }
55
+ // As a last resort, use this process's node. On POSIX this is correct;
56
+ // on Windows it may be the Cursor bundle, but at that point the user
57
+ // likely has no system node at all and this is the best we can do.
58
+ return process.execPath;
59
+ }
60
+
61
+ /**
62
+ * Resolve the absolute path to the *published* context-gatekeeper's
63
+ * `dist/mcp/server.js`. We rely on `npm root -g` because the recommended
64
+ * install path for end users is `npm i -g context-gatekeeper`, which
65
+ * puts a real directory under the global modules root.
66
+ *
67
+ * Returns `null` when no global install exists (e.g. the user has only
68
+ * run the package from source). Callers fall back to `npx` in that case.
69
+ */
70
+ function resolveGlobalServerBin(): string | null {
71
+ try {
72
+ const root = childProcess.execSync('npm root -g', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
73
+ const pkgRoot = resolvePath(root, PUBLISHED_PACKAGE);
74
+ const pkgJsonPath = join(pkgRoot, 'package.json');
75
+ if (!existsSync(pkgJsonPath)) return null;
76
+ const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8')) as {
77
+ name?: string;
78
+ bin?: Record<string, string>;
79
+ };
80
+ if (pkg.name !== PUBLISHED_PACKAGE) return null;
81
+ const relBin = pkg.bin?.[PUBLISHED_PACKAGE];
82
+ if (!relBin) return null;
83
+ return resolvePath(pkgRoot, relBin);
84
+ } catch (err) {
85
+ console.error('[config-gen] resolveGlobalServerBin failed:', (err as Error).message);
86
+ return null;
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Build the launch command the user's agent will run to start the MCP
92
+ * server. The form is platform-aware and depends on whether the package
93
+ * has been globally installed:
94
+ *
95
+ * - Global install present (any platform):
96
+ * command = <absolute path to system node>
97
+ * args = [<absolute path to dist/mcp/server.js>]
98
+ * This avoids the `npx` dance entirely, sidesteps the Windows
99
+ * npx-cli.js relative-path bug, and does not require network access.
100
+ *
101
+ * - No global install (e.g. running from source only):
102
+ * POSIX: `npx -y context-gatekeeper`
103
+ * Windows: `cmd /c npx -y context-gatekeeper`
104
+ * This is a fallback that only works once the package is published
105
+ * to a registry the host can reach.
106
+ */
107
+ export function buildMcpBin(): { command: string; args: string[] } {
108
+ const globalBin = resolveGlobalServerBin();
109
+ if (globalBin) {
110
+ return { command: resolveSystemNode(), args: [globalBin] };
111
+ }
112
+ if (process.platform === 'win32') {
113
+ return { command: 'cmd', args: ['/c', 'npx', '-y', PUBLISHED_PACKAGE] };
114
+ }
115
+ return { command: 'npx', args: ['-y', PUBLISHED_PACKAGE] };
116
+ }
117
+
118
+ export const PUBLISHED_PACKAGE = 'context-gatekeeper';
119
+
120
+ /**
121
+ * The launch command the user's agent will run to start the MCP server.
122
+ * Computed at import time via {@link buildMcpBin}. Kept as a constant
123
+ * for backward compatibility with code that still imports it; new code
124
+ * should call `buildMcpBin()` directly.
125
+ */
126
+ export const PUBLISHED_MCP_BIN: { command: string; args: string[] } = buildMcpBin();
127
+
128
+ /** Map agent name to the adapter class whose `buildMcpConfig` we want. */
129
+ function pickAdapter(agent: AgentName): (mcpBin: { command: string; args: string[] }) => AgentConfig['mcpConfig'] {
130
+ switch (agent) {
131
+ case 'cursor':
132
+ return CursorAdapter.buildMcpConfig.bind(CursorAdapter);
133
+ case 'claude-desktop':
134
+ return ClaudeDesktopAdapter.buildMcpConfig.bind(ClaudeDesktopAdapter);
135
+ case 'cline':
136
+ return ClineAdapter.buildMcpConfig.bind(ClineAdapter);
137
+ case 'continue':
138
+ return ContinueAdapter.buildMcpConfig.bind(ContinueAdapter);
139
+ case 'claude-code':
140
+ return ClaudeCodeAdapter.buildMcpConfig.bind(ClaudeCodeAdapter);
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Build the config block for a given agent. The result is a partial config
146
+ * object (e.g. `{ mcpServers: { 'context-gatekeeper': {...} } }`) that will
147
+ * be merged into the existing file.
148
+ */
149
+ export function buildConfigBlock(agent: AgentName): AgentConfig['mcpConfig'] {
150
+ return pickAdapter(agent)(PUBLISHED_MCP_BIN);
151
+ }
152
+
153
+ /**
154
+ * The key the agent stores our server under. Used by install/uninstall
155
+ * to find and remove the entry. The value is the same regardless of
156
+ * agent because we always register under the canonical
157
+ * `context-gatekeeper` name.
158
+ *
159
+ * - Cursor / Claude Desktop / Cline / Claude Code: top-level key under
160
+ * `mcpServers`.
161
+ * - Continue: entry inside `experimental.modelContextProtocolServers`,
162
+ * identified by the entry's `name` field (not a key).
163
+ */
164
+ export const GATEKEEPER_KEY = 'context-gatekeeper';
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Agent config-file path detection.
3
+ *
4
+ * Each supported MCP agent has its own global config path (and most also
5
+ * support a project-local override). This module maps agent names to the
6
+ * absolute path of the config file the agent will actually read, taking
7
+ * the current platform into account.
8
+ */
9
+ export type AgentName = 'cursor' | 'claude-desktop' | 'cline' | 'continue' | 'claude-code';
10
+ export type Scope = 'global' | 'project';
11
+ export interface AgentDetection {
12
+ agent: AgentName;
13
+ scope: Scope;
14
+ configPath: string;
15
+ exists: boolean;
16
+ /** True if the config file already references context-gatekeeper. */
17
+ installed: boolean;
18
+ }
19
+ export declare const SUPPORTED_AGENTS: AgentName[];
20
+ export declare function isValidAgent(name: string): name is AgentName;
21
+ /**
22
+ * Detect where the agent's config file lives. Prefers project-level when
23
+ * `scope === 'project'`, otherwise global. If `scope` is omitted, returns
24
+ * the path that exists (or would be written), preferring project-level.
25
+ */
26
+ export declare function detectAgent(agent: AgentName, options?: {
27
+ scope?: Scope;
28
+ cwd?: string;
29
+ }): AgentDetection;
30
+ /**
31
+ * Probe all supported agents for their detection state.
32
+ */
33
+ export declare function detectAll(options?: {
34
+ scope?: Scope;
35
+ cwd?: string;
36
+ }): AgentDetection[];
37
+ /**
38
+ * Filter a list of detections to those whose config file currently exists.
39
+ * Used by `--all` to skip agents that are not installed on this machine.
40
+ */
41
+ export declare function filterDetected(detections: AgentDetection[]): AgentDetection[];
42
+ //# sourceMappingURL=detect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["detect.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,gBAAgB,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa,CAAC;AAE3F,MAAM,MAAM,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzC,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,qEAAqE;IACrE,SAAS,EAAE,OAAO,CAAC;CACpB;AA0DD,eAAO,MAAM,gBAAgB,EAAE,SAAS,EAMvC,CAAC;AAEF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,SAAS,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,EAChB,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAC5C,cAAc,CAahB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,cAAc,EAAE,CAEzF;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAE7E"}