@burtson-labs/agent-core 1.6.13

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 (195) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +88 -0
  3. package/dist/index.d.ts +16 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +52 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/mcp/activation.d.ts +60 -0
  8. package/dist/mcp/activation.d.ts.map +1 -0
  9. package/dist/mcp/activation.js +139 -0
  10. package/dist/mcp/activation.js.map +1 -0
  11. package/dist/mcp/clientPool.d.ts +202 -0
  12. package/dist/mcp/clientPool.d.ts.map +1 -0
  13. package/dist/mcp/clientPool.js +469 -0
  14. package/dist/mcp/clientPool.js.map +1 -0
  15. package/dist/mcp/index.d.ts +18 -0
  16. package/dist/mcp/index.d.ts.map +1 -0
  17. package/dist/mcp/index.js +28 -0
  18. package/dist/mcp/index.js.map +1 -0
  19. package/dist/mcp/server.d.ts +43 -0
  20. package/dist/mcp/server.d.ts.map +1 -0
  21. package/dist/mcp/server.js +130 -0
  22. package/dist/mcp/server.js.map +1 -0
  23. package/dist/mcp/toolAdapter.d.ts +57 -0
  24. package/dist/mcp/toolAdapter.d.ts.map +1 -0
  25. package/dist/mcp/toolAdapter.js +223 -0
  26. package/dist/mcp/toolAdapter.js.map +1 -0
  27. package/dist/mcp/types.d.ts +122 -0
  28. package/dist/mcp/types.d.ts.map +1 -0
  29. package/dist/mcp/types.js +15 -0
  30. package/dist/mcp/types.js.map +1 -0
  31. package/dist/providers/deterministic-provider.d.ts +21 -0
  32. package/dist/providers/deterministic-provider.d.ts.map +1 -0
  33. package/dist/providers/deterministic-provider.js +80 -0
  34. package/dist/providers/deterministic-provider.js.map +1 -0
  35. package/dist/providers/provider-client.d.ts +12 -0
  36. package/dist/providers/provider-client.d.ts.map +1 -0
  37. package/dist/providers/provider-client.js +11 -0
  38. package/dist/providers/provider-client.js.map +1 -0
  39. package/dist/runtime/AgentRuntime.d.ts +67 -0
  40. package/dist/runtime/AgentRuntime.d.ts.map +1 -0
  41. package/dist/runtime/AgentRuntime.js +382 -0
  42. package/dist/runtime/AgentRuntime.js.map +1 -0
  43. package/dist/security/secretPatterns.d.ts +76 -0
  44. package/dist/security/secretPatterns.d.ts.map +1 -0
  45. package/dist/security/secretPatterns.js +290 -0
  46. package/dist/security/secretPatterns.js.map +1 -0
  47. package/dist/tools/ask-user-tool.d.ts +19 -0
  48. package/dist/tools/ask-user-tool.d.ts.map +1 -0
  49. package/dist/tools/ask-user-tool.js +148 -0
  50. package/dist/tools/ask-user-tool.js.map +1 -0
  51. package/dist/tools/compactMessages.d.ts +52 -0
  52. package/dist/tools/compactMessages.d.ts.map +1 -0
  53. package/dist/tools/compactMessages.js +158 -0
  54. package/dist/tools/compactMessages.js.map +1 -0
  55. package/dist/tools/core-tools.d.ts +29 -0
  56. package/dist/tools/core-tools.d.ts.map +1 -0
  57. package/dist/tools/core-tools.js +2214 -0
  58. package/dist/tools/core-tools.js.map +1 -0
  59. package/dist/tools/git-tools.d.ts +32 -0
  60. package/dist/tools/git-tools.d.ts.map +1 -0
  61. package/dist/tools/git-tools.js +330 -0
  62. package/dist/tools/git-tools.js.map +1 -0
  63. package/dist/tools/index.d.ts +15 -0
  64. package/dist/tools/index.d.ts.map +1 -0
  65. package/dist/tools/index.js +31 -0
  66. package/dist/tools/index.js.map +1 -0
  67. package/dist/tools/language-adapters.d.ts +48 -0
  68. package/dist/tools/language-adapters.d.ts.map +1 -0
  69. package/dist/tools/language-adapters.js +299 -0
  70. package/dist/tools/language-adapters.js.map +1 -0
  71. package/dist/tools/loop/compactionTrigger.d.ts +47 -0
  72. package/dist/tools/loop/compactionTrigger.d.ts.map +1 -0
  73. package/dist/tools/loop/compactionTrigger.js +32 -0
  74. package/dist/tools/loop/compactionTrigger.js.map +1 -0
  75. package/dist/tools/loop/finalAnswerNudges.d.ts +68 -0
  76. package/dist/tools/loop/finalAnswerNudges.d.ts.map +1 -0
  77. package/dist/tools/loop/finalAnswerNudges.js +87 -0
  78. package/dist/tools/loop/finalAnswerNudges.js.map +1 -0
  79. package/dist/tools/loop/goalAnchor.d.ts +72 -0
  80. package/dist/tools/loop/goalAnchor.d.ts.map +1 -0
  81. package/dist/tools/loop/goalAnchor.js +76 -0
  82. package/dist/tools/loop/goalAnchor.js.map +1 -0
  83. package/dist/tools/loop/llmStream.d.ts +70 -0
  84. package/dist/tools/loop/llmStream.d.ts.map +1 -0
  85. package/dist/tools/loop/llmStream.js +181 -0
  86. package/dist/tools/loop/llmStream.js.map +1 -0
  87. package/dist/tools/loop/parallelExecute.d.ts +57 -0
  88. package/dist/tools/loop/parallelExecute.d.ts.map +1 -0
  89. package/dist/tools/loop/parallelExecute.js +54 -0
  90. package/dist/tools/loop/parallelExecute.js.map +1 -0
  91. package/dist/tools/loop/singleToolExecute.d.ts +71 -0
  92. package/dist/tools/loop/singleToolExecute.d.ts.map +1 -0
  93. package/dist/tools/loop/singleToolExecute.js +139 -0
  94. package/dist/tools/loop/singleToolExecute.js.map +1 -0
  95. package/dist/tools/loop/toolCallNormalize.d.ts +57 -0
  96. package/dist/tools/loop/toolCallNormalize.d.ts.map +1 -0
  97. package/dist/tools/loop/toolCallNormalize.js +99 -0
  98. package/dist/tools/loop/toolCallNormalize.js.map +1 -0
  99. package/dist/tools/loop/turnSetup.d.ts +43 -0
  100. package/dist/tools/loop/turnSetup.d.ts.map +1 -0
  101. package/dist/tools/loop/turnSetup.js +48 -0
  102. package/dist/tools/loop/turnSetup.js.map +1 -0
  103. package/dist/tools/ocr.d.ts +52 -0
  104. package/dist/tools/ocr.d.ts.map +1 -0
  105. package/dist/tools/ocr.js +238 -0
  106. package/dist/tools/ocr.js.map +1 -0
  107. package/dist/tools/post-edit-checks.d.ts +46 -0
  108. package/dist/tools/post-edit-checks.d.ts.map +1 -0
  109. package/dist/tools/post-edit-checks.js +236 -0
  110. package/dist/tools/post-edit-checks.js.map +1 -0
  111. package/dist/tools/skill-loader.d.ts +94 -0
  112. package/dist/tools/skill-loader.d.ts.map +1 -0
  113. package/dist/tools/skill-loader.js +422 -0
  114. package/dist/tools/skill-loader.js.map +1 -0
  115. package/dist/tools/skill-registry.d.ts +44 -0
  116. package/dist/tools/skill-registry.d.ts.map +1 -0
  117. package/dist/tools/skill-registry.js +118 -0
  118. package/dist/tools/skill-registry.js.map +1 -0
  119. package/dist/tools/skill-types.d.ts +38 -0
  120. package/dist/tools/skill-types.d.ts.map +1 -0
  121. package/dist/tools/skill-types.js +10 -0
  122. package/dist/tools/skill-types.js.map +1 -0
  123. package/dist/tools/skills/code-review-skill.d.ts +9 -0
  124. package/dist/tools/skills/code-review-skill.d.ts.map +1 -0
  125. package/dist/tools/skills/code-review-skill.js +66 -0
  126. package/dist/tools/skills/code-review-skill.js.map +1 -0
  127. package/dist/tools/skills/core-skill.d.ts +13 -0
  128. package/dist/tools/skills/core-skill.d.ts.map +1 -0
  129. package/dist/tools/skills/core-skill.js +23 -0
  130. package/dist/tools/skills/core-skill.js.map +1 -0
  131. package/dist/tools/skills/git-skill.d.ts +10 -0
  132. package/dist/tools/skills/git-skill.d.ts.map +1 -0
  133. package/dist/tools/skills/git-skill.js +30 -0
  134. package/dist/tools/skills/git-skill.js.map +1 -0
  135. package/dist/tools/skills/index.d.ts +17 -0
  136. package/dist/tools/skills/index.d.ts.map +1 -0
  137. package/dist/tools/skills/index.js +49 -0
  138. package/dist/tools/skills/index.js.map +1 -0
  139. package/dist/tools/skills/interaction-skill.d.ts +14 -0
  140. package/dist/tools/skills/interaction-skill.d.ts.map +1 -0
  141. package/dist/tools/skills/interaction-skill.js +24 -0
  142. package/dist/tools/skills/interaction-skill.js.map +1 -0
  143. package/dist/tools/skills/mail-search-skill.d.ts +25 -0
  144. package/dist/tools/skills/mail-search-skill.d.ts.map +1 -0
  145. package/dist/tools/skills/mail-search-skill.js +343 -0
  146. package/dist/tools/skills/mail-search-skill.js.map +1 -0
  147. package/dist/tools/skills/plan-skill.d.ts +10 -0
  148. package/dist/tools/skills/plan-skill.d.ts.map +1 -0
  149. package/dist/tools/skills/plan-skill.js +126 -0
  150. package/dist/tools/skills/plan-skill.js.map +1 -0
  151. package/dist/tools/skills/semantic-search-skill.d.ts +22 -0
  152. package/dist/tools/skills/semantic-search-skill.d.ts.map +1 -0
  153. package/dist/tools/skills/semantic-search-skill.js +244 -0
  154. package/dist/tools/skills/semantic-search-skill.js.map +1 -0
  155. package/dist/tools/skills/test-gen-skill.d.ts +9 -0
  156. package/dist/tools/skills/test-gen-skill.d.ts.map +1 -0
  157. package/dist/tools/skills/test-gen-skill.js +123 -0
  158. package/dist/tools/skills/test-gen-skill.js.map +1 -0
  159. package/dist/tools/tool-registry.d.ts +60 -0
  160. package/dist/tools/tool-registry.d.ts.map +1 -0
  161. package/dist/tools/tool-registry.js +200 -0
  162. package/dist/tools/tool-registry.js.map +1 -0
  163. package/dist/tools/tool-types.d.ts +281 -0
  164. package/dist/tools/tool-types.d.ts.map +1 -0
  165. package/dist/tools/tool-types.js +10 -0
  166. package/dist/tools/tool-types.js.map +1 -0
  167. package/dist/tools/tool-use-loop.d.ts +231 -0
  168. package/dist/tools/tool-use-loop.d.ts.map +1 -0
  169. package/dist/tools/tool-use-loop.js +2057 -0
  170. package/dist/tools/tool-use-loop.js.map +1 -0
  171. package/dist/tools/tool-use-parser.d.ts +78 -0
  172. package/dist/tools/tool-use-parser.d.ts.map +1 -0
  173. package/dist/tools/tool-use-parser.js +427 -0
  174. package/dist/tools/tool-use-parser.js.map +1 -0
  175. package/dist/tools/toolAvailabilityDetector.d.ts +48 -0
  176. package/dist/tools/toolAvailabilityDetector.d.ts.map +1 -0
  177. package/dist/tools/toolAvailabilityDetector.js +156 -0
  178. package/dist/tools/toolAvailabilityDetector.js.map +1 -0
  179. package/dist/tools/unified-patch.d.ts +87 -0
  180. package/dist/tools/unified-patch.d.ts.map +1 -0
  181. package/dist/tools/unified-patch.js +217 -0
  182. package/dist/tools/unified-patch.js.map +1 -0
  183. package/dist/types/agent.d.ts +69 -0
  184. package/dist/types/agent.d.ts.map +1 -0
  185. package/dist/types/agent.js +54 -0
  186. package/dist/types/agent.js.map +1 -0
  187. package/dist/types/tasks.d.ts +22 -0
  188. package/dist/types/tasks.d.ts.map +1 -0
  189. package/dist/types/tasks.js +3 -0
  190. package/dist/types/tasks.js.map +1 -0
  191. package/dist/utils/event-emitter.d.ts +13 -0
  192. package/dist/utils/event-emitter.d.ts.map +1 -0
  193. package/dist/utils/event-emitter.js +54 -0
  194. package/dist/utils/event-emitter.js.map +1 -0
  195. package/package.json +33 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientPool.js","sourceRoot":"","sources":["../../src/mcp/clientPool.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDH,0DAsBC;AAzED,+CAAiC;AA6CjC;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,IAAY,EAAE,MAAuB;IAC3E,qEAAqE;IACrE,oEAAoE;IACpE,mEAAmE;IACnE,sCAAsC;IACtC,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACf,MAAM,OAAO,GAAG;YACd,IAAI;YACJ,IAAI,EAAE,KAAc;YACpB,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,QAAQ,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC;SACpC,CAAC;QACF,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAChG,CAAC;IACD,MAAM,OAAO,GAAG;QACd,IAAI;QACJ,IAAI,EAAE,OAAgB;QACtB,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE;QAC7B,IAAI,EAAE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AO,EAAE,CAAC;YACtB,qDAAqD;YACrD,+DAA+D;YAC/D,gDAAgD;YAChD,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;QAChC,CAAC;QACD,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACjC,OAAO,EAAE,aAAa,EAAE,UAAU,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC;QACzD,CAAC;QACD,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACjC,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC;QACjD,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAzUD,sCAyUC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * MCP — Model Context Protocol — entry point.
3
+ *
4
+ * Bandit speaks MCP as a CLIENT. See docs/integration-playlist/mcp-roadmap.md
5
+ * for the phased plan. Phase 1 (this module) lays the groundwork:
6
+ * spawn child-process MCP servers via stdio, enumerate their tools,
7
+ * register them in Bandit's existing ToolRegistry with `<server>.<tool>`
8
+ * names. Phase 2 layers on the user-visible config + UX.
9
+ *
10
+ * Off by default — a host that never registers any servers in the
11
+ * pool gets zero behavior change. No backward-compat risk.
12
+ */
13
+ export { McpClientPool, fingerprintServerConfig, type McpClientPoolOptions, type McpTrustGate, type McpToolsDiscoveredCallback, type RemoteToolDef as McpRemoteToolDef } from './clientPool';
14
+ export { mcpToolToAgentTool, getAllMcpAgentTools } from './toolAdapter';
15
+ export { serveBanditMcp } from './server';
16
+ export { shouldActivateServer, effectiveTriggers, inferProviderHint } from './activation';
17
+ export type { McpServerConfig, McpServersFile, McpServerStatus, McpServerSnapshot } from './types';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAC/B,KAAK,aAAa,IAAI,gBAAgB,EACvC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,iBAAiB,EAClB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * MCP — Model Context Protocol — entry point.
4
+ *
5
+ * Bandit speaks MCP as a CLIENT. See docs/integration-playlist/mcp-roadmap.md
6
+ * for the phased plan. Phase 1 (this module) lays the groundwork:
7
+ * spawn child-process MCP servers via stdio, enumerate their tools,
8
+ * register them in Bandit's existing ToolRegistry with `<server>.<tool>`
9
+ * names. Phase 2 layers on the user-visible config + UX.
10
+ *
11
+ * Off by default — a host that never registers any servers in the
12
+ * pool gets zero behavior change. No backward-compat risk.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.inferProviderHint = exports.effectiveTriggers = exports.shouldActivateServer = exports.serveBanditMcp = exports.getAllMcpAgentTools = exports.mcpToolToAgentTool = exports.fingerprintServerConfig = exports.McpClientPool = void 0;
16
+ var clientPool_1 = require("./clientPool");
17
+ Object.defineProperty(exports, "McpClientPool", { enumerable: true, get: function () { return clientPool_1.McpClientPool; } });
18
+ Object.defineProperty(exports, "fingerprintServerConfig", { enumerable: true, get: function () { return clientPool_1.fingerprintServerConfig; } });
19
+ var toolAdapter_1 = require("./toolAdapter");
20
+ Object.defineProperty(exports, "mcpToolToAgentTool", { enumerable: true, get: function () { return toolAdapter_1.mcpToolToAgentTool; } });
21
+ Object.defineProperty(exports, "getAllMcpAgentTools", { enumerable: true, get: function () { return toolAdapter_1.getAllMcpAgentTools; } });
22
+ var server_1 = require("./server");
23
+ Object.defineProperty(exports, "serveBanditMcp", { enumerable: true, get: function () { return server_1.serveBanditMcp; } });
24
+ var activation_1 = require("./activation");
25
+ Object.defineProperty(exports, "shouldActivateServer", { enumerable: true, get: function () { return activation_1.shouldActivateServer; } });
26
+ Object.defineProperty(exports, "effectiveTriggers", { enumerable: true, get: function () { return activation_1.effectiveTriggers; } });
27
+ Object.defineProperty(exports, "inferProviderHint", { enumerable: true, get: function () { return activation_1.inferProviderHint; } });
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,2CAOsB;AANpB,2GAAA,aAAa,OAAA;AACb,qHAAA,uBAAuB,OAAA;AAMzB,6CAAwE;AAA/D,iHAAA,kBAAkB,OAAA;AAAE,kHAAA,mBAAmB,OAAA;AAChD,mCAA0C;AAAjC,wGAAA,cAAc,OAAA;AACvB,2CAIsB;AAHpB,kHAAA,oBAAoB,OAAA;AACpB,+GAAA,iBAAiB,OAAA;AACjB,+GAAA,iBAAiB,OAAA"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Bandit-as-MCP-server. Exposes Bandit's native tool surface
3
+ * (read_file, write_file, apply_edit, replace_range, list_files, ls, search_code,
4
+ * find_directory, run_command, etc.) over MCP stdio so other clients
5
+ * — Claude Desktop, Cursor, Cline, Continue, any MCP-speaking host —
6
+ * can drive Bandit the same way Bandit drives external servers.
7
+ *
8
+ * Mirror of the client code path: SDK is required lazily so a missing
9
+ * dep can never crash module load (matters because this module ships
10
+ * inside the same agent-core dist that the IDE extension imports
11
+ * eagerly). Failures during tool calls return a structured error
12
+ * result with isError: true rather than throwing.
13
+ */
14
+ import type { AgentTool, ToolExecutionContext } from '../tools/tool-types';
15
+ interface ServeOptions {
16
+ /** Tools to expose. Hosts pass a ToolRegistry's contents — usually
17
+ * the core skill's tools plus run_command. read-only mode skips
18
+ * write_file / apply_edit / replace_range / run_command. */
19
+ tools: AgentTool[];
20
+ /** ToolExecutionContext for tool invocations. The host owns this
21
+ * so it can wire up filesystem access, language adapters, etc.,
22
+ * exactly the way Bandit's own loop wires them. */
23
+ toolCtx: ToolExecutionContext;
24
+ /** Server name advertised in the MCP handshake. Defaults to
25
+ * "bandit". MCP clients show this in their UI. */
26
+ name?: string;
27
+ /** Server version advertised in the handshake. Defaults to the
28
+ * agent-core package version. */
29
+ version?: string;
30
+ /** Optional logger. Defaults to console.error. Stdout is reserved
31
+ * for the JSON-RPC stream — never log there. */
32
+ log?: (line: string) => void;
33
+ }
34
+ /**
35
+ * Spin up an MCP server that exposes Bandit's native tools over
36
+ * stdio. Returns a promise that resolves when the transport closes
37
+ * (typically when the parent client disconnects). The caller
38
+ * controls the process lifetime — typical usage is a CLI subcommand
39
+ * that just awaits this promise then exits.
40
+ */
41
+ export declare function serveBanditMcp(options: ServeOptions): Promise<void>;
42
+ export {};
43
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3E,UAAU,YAAY;IACpB;;iEAE6D;IAC7D,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB;;wDAEoD;IACpD,OAAO,EAAE,oBAAoB,CAAC;IAC9B;uDACmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;sCACkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;qDACiD;IACjD,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9B;AA2CD;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAuEzE"}
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ /**
3
+ * Bandit-as-MCP-server. Exposes Bandit's native tool surface
4
+ * (read_file, write_file, apply_edit, replace_range, list_files, ls, search_code,
5
+ * find_directory, run_command, etc.) over MCP stdio so other clients
6
+ * — Claude Desktop, Cursor, Cline, Continue, any MCP-speaking host —
7
+ * can drive Bandit the same way Bandit drives external servers.
8
+ *
9
+ * Mirror of the client code path: SDK is required lazily so a missing
10
+ * dep can never crash module load (matters because this module ships
11
+ * inside the same agent-core dist that the IDE extension imports
12
+ * eagerly). Failures during tool calls return a structured error
13
+ * result with isError: true rather than throwing.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.serveBanditMcp = serveBanditMcp;
17
+ /**
18
+ * Convert a Bandit AgentTool's flat parameter list into MCP's
19
+ * JSON-Schema input shape. Best-effort — every parameter is typed as
20
+ * `string` since AgentTool doesn't carry richer type info, with the
21
+ * description preserved verbatim. MCP clients that strict-validate
22
+ * input still get a clean schema; clients that don't validate just
23
+ * see a documented set of fields.
24
+ */
25
+ function toolInputSchema(tool) {
26
+ const properties = {};
27
+ const required = [];
28
+ for (const p of tool.parameters) {
29
+ properties[p.name] = { type: 'string', description: p.description };
30
+ if (p.required)
31
+ required.push(p.name);
32
+ }
33
+ return { type: 'object', properties, required };
34
+ }
35
+ /**
36
+ * Coerce the MCP arguments object into the flat Record<string,string>
37
+ * shape Bandit's AgentTool.execute expects. Non-string values get
38
+ * JSON.stringify'd back to text so an MCP client passing a number /
39
+ * boolean / nested object still reaches our tool with a usable
40
+ * representation — matches the equivalent coercion done client-side
41
+ * in toolAdapter.ts when going the other direction.
42
+ */
43
+ function coerceArgs(raw) {
44
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
45
+ return {};
46
+ const out = {};
47
+ for (const [k, v] of Object.entries(raw)) {
48
+ if (typeof v === 'string')
49
+ out[k] = v;
50
+ else if (v === null || v === undefined)
51
+ continue;
52
+ else
53
+ out[k] = JSON.stringify(v);
54
+ }
55
+ return out;
56
+ }
57
+ /**
58
+ * Spin up an MCP server that exposes Bandit's native tools over
59
+ * stdio. Returns a promise that resolves when the transport closes
60
+ * (typically when the parent client disconnects). The caller
61
+ * controls the process lifetime — typical usage is a CLI subcommand
62
+ * that just awaits this promise then exits.
63
+ */
64
+ async function serveBanditMcp(options) {
65
+ // SDK loaded lazily — same pattern as clientPool.ts. A dep
66
+ // resolution failure inside the SDK never trips at module load,
67
+ // only when an actual host tries to start the server. Means
68
+ // `import { serveBanditMcp }` is safe in code paths that may or
69
+ // may not actually run the server.
70
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
71
+ const serverMod = require('@modelcontextprotocol/sdk/server/index.js');
72
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
73
+ const stdioMod = require('@modelcontextprotocol/sdk/server/stdio.js');
74
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
75
+ const typesMod = require('@modelcontextprotocol/sdk/types.js');
76
+ const { Server } = serverMod;
77
+ const { StdioServerTransport } = stdioMod;
78
+ const { ListToolsRequestSchema, CallToolRequestSchema } = typesMod;
79
+ const log = options.log ?? ((line) => process.stderr.write(line + '\n'));
80
+ const tools = options.tools;
81
+ const toolByName = new Map();
82
+ for (const t of tools)
83
+ toolByName.set(t.name, t);
84
+ const server = new Server({ name: options.name ?? 'bandit', version: options.version ?? '1.0.0' }, { capabilities: { tools: {} } });
85
+ // tools/list — return every registered tool's metadata.
86
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
87
+ tools: tools.map((t) => ({
88
+ name: t.name,
89
+ description: t.description,
90
+ inputSchema: toolInputSchema(t)
91
+ }))
92
+ }));
93
+ // tools/call — dispatch into the AgentTool's execute. Errors
94
+ // surface as MCP isError results rather than thrown exceptions so
95
+ // the calling client gets a clean, parseable response.
96
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
97
+ const tool = toolByName.get(request.params.name);
98
+ if (!tool) {
99
+ return {
100
+ isError: true,
101
+ content: [{ type: 'text', text: `Unknown tool: ${request.params.name}` }]
102
+ };
103
+ }
104
+ try {
105
+ const args = coerceArgs(request.params.arguments);
106
+ const result = await tool.execute(args, options.toolCtx);
107
+ return {
108
+ isError: !!result.isError,
109
+ content: [{ type: 'text', text: result.output }]
110
+ };
111
+ }
112
+ catch (err) {
113
+ const msg = err instanceof Error ? err.message : String(err);
114
+ log(`tool call ${request.params.name} threw: ${msg}`);
115
+ return {
116
+ isError: true,
117
+ content: [{ type: 'text', text: `Tool error: ${msg}` }]
118
+ };
119
+ }
120
+ });
121
+ log(`bandit MCP server: ready on stdio with ${tools.length} tool${tools.length === 1 ? '' : 's'}`);
122
+ const transport = new StdioServerTransport();
123
+ await server.connect(transport);
124
+ // server.connect returns once the transport is wired but stays
125
+ // alive on stdio reads. Hook close so the host's await resolves.
126
+ await new Promise((resolve) => {
127
+ transport.onclose = () => resolve();
128
+ });
129
+ }
130
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAwEH,wCAuEC;AAvHD;;;;;;;GAOG;AACH,SAAS,eAAe,CAAC,IAAe;IAKtC,MAAM,UAAU,GAA0D,EAAE,CAAC;IAC7E,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QAChC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QACpE,IAAI,CAAC,CAAC,QAAQ;YAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,U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AC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Adapt MCP tool definitions to Bandit's AgentTool interface so the
3
+ * existing tool-use loop can call them with no special-casing.
4
+ *
5
+ * server "slack" exposes tool "post_message" → AgentTool named
6
+ * "slack.post_message" registered alongside read_file / apply_edit /
7
+ * etc. The model invokes it via the same <tool_call>{...}</tool_call>
8
+ * envelope it uses for native tools.
9
+ *
10
+ * Namespacing is non-negotiable: collisions with native tool names
11
+ * (read_file, write_file, etc) would silently shadow Bandit's own
12
+ * implementations. Always `<server>.<tool>`.
13
+ */
14
+ import type { AgentTool } from '../tools/tool-types';
15
+ import type { McpClientPool } from './clientPool';
16
+ interface JsonSchemaNode {
17
+ type?: string;
18
+ description?: string;
19
+ properties?: Record<string, JsonSchemaNode>;
20
+ required?: string[];
21
+ items?: JsonSchemaNode;
22
+ enum?: Array<string | number | boolean>;
23
+ }
24
+ interface RemoteToolDef {
25
+ name: string;
26
+ description?: string;
27
+ inputSchema?: JsonSchemaNode;
28
+ }
29
+ /**
30
+ * Build an AgentTool that proxies through the pool to the named
31
+ * server's named tool. Parameter list is derived from the MCP tool's
32
+ * input schema; description is preserved verbatim with a small
33
+ * "(via MCP server <name>)" suffix so the user reading their session
34
+ * log can tell which server's tools the agent reached for.
35
+ */
36
+ export declare function mcpToolToAgentTool(serverName: string, remote: RemoteToolDef, pool: McpClientPool): AgentTool;
37
+ /**
38
+ * Convenience: enumerate every connected server's tools and return
39
+ * AgentTool wrappers ready to register with the existing
40
+ * ToolRegistry. Call from the host (extension or CLI) after the user's
41
+ * mcp-servers.json has been loaded into the pool.
42
+ *
43
+ * The optional `prompt` argument enables activation filtering: when
44
+ * provided, servers configured with `activation: "on-mention"` are
45
+ * only included if their trigger keywords match the prompt. Servers
46
+ * with `activation: "always"` (the default) always contribute their
47
+ * tools regardless of prompt. Pass `undefined` (or omit) to register
48
+ * every server's tools — the -and-earlier behavior.
49
+ *
50
+ * Each server's discoverTools() will lazily spawn the process — so
51
+ * the first call per server after session start does pay the spawn
52
+ * cost. With on-mention activation, that cost only fires for prompts
53
+ * that actually trigger the server.
54
+ */
55
+ export declare function getAllMcpAgentTools(pool: McpClientPool, prompt?: string): Promise<AgentTool[]>;
56
+ export {};
57
+ //# sourceMappingURL=toolAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolAdapter.d.ts","sourceRoot":"","sources":["../../src/mcp/toolAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAkF,MAAM,qBAAqB,CAAC;AACrI,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AASlD,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CACzC;AAED,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,cAAc,CAAC;CAC9B;AAiFD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,aAAa,GAClB,SAAS,CA8DX;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,aAAa,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,SAAS,EAAE,CAAC,CAqBtB"}
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ /**
3
+ * Adapt MCP tool definitions to Bandit's AgentTool interface so the
4
+ * existing tool-use loop can call them with no special-casing.
5
+ *
6
+ * server "slack" exposes tool "post_message" → AgentTool named
7
+ * "slack.post_message" registered alongside read_file / apply_edit /
8
+ * etc. The model invokes it via the same <tool_call>{...}</tool_call>
9
+ * envelope it uses for native tools.
10
+ *
11
+ * Namespacing is non-negotiable: collisions with native tool names
12
+ * (read_file, write_file, etc) would silently shadow Bandit's own
13
+ * implementations. Always `<server>.<tool>`.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.mcpToolToAgentTool = mcpToolToAgentTool;
17
+ exports.getAllMcpAgentTools = getAllMcpAgentTools;
18
+ const activation_1 = require("./activation");
19
+ /**
20
+ * Translate one MCP JSON-Schema node into the slimmer
21
+ * AgentToolParameterSchema shape. Recursive for object properties and
22
+ * array items so a `createFilter` param like `criteria: { type: object,
23
+ * properties: { from, to, subject, query } }` keeps its shape all the
24
+ * way to the model — instead of getting flattened to a single opaque
25
+ * "string" param the way the legacy converter did.
26
+ */
27
+ function toAgentSchema(node) {
28
+ if (!node)
29
+ return undefined;
30
+ const t = node.type;
31
+ const ALLOWED = new Set(['object', 'array', 'string', 'number', 'integer', 'boolean', 'null']);
32
+ if (t && !ALLOWED.has(t))
33
+ return undefined;
34
+ const out = {};
35
+ if (t)
36
+ out.type = t;
37
+ if (node.description)
38
+ out.description = node.description;
39
+ if (node.enum)
40
+ out.enum = node.enum;
41
+ if (t === 'object' && node.properties) {
42
+ out.properties = {};
43
+ for (const [k, v] of Object.entries(node.properties)) {
44
+ const child = toAgentSchema(v);
45
+ if (child) {
46
+ out.properties[k] = child.description
47
+ ? { ...child, description: child.description }
48
+ : { ...child, description: v.description };
49
+ }
50
+ }
51
+ if (node.required && node.required.length > 0)
52
+ out.required = node.required;
53
+ }
54
+ else if (t === 'array' && node.items) {
55
+ const child = toAgentSchema(node.items);
56
+ if (child)
57
+ out.items = child;
58
+ }
59
+ return out;
60
+ }
61
+ /**
62
+ * Convert an MCP tool's JSON-Schema input to Bandit's AgentToolParameter[].
63
+ * Each parameter now carries the original JSON Schema type info on the
64
+ * optional `schema` field, so downstream renderers (native-tools
65
+ * provider schema + system-prompt block) tell the model the real shape
66
+ * (object/array/etc) instead of the legacy "every param is a string."
67
+ * That's the fix for MCP tools whose backends reject string-encoded
68
+ * objects with "Expected object, received string."
69
+ */
70
+ function convertInputSchema(schema) {
71
+ if (!schema || schema.type !== 'object' || !schema.properties)
72
+ return [];
73
+ const required = new Set(schema.required ?? []);
74
+ return Object.entries(schema.properties).map(([name, prop]) => {
75
+ const subSchema = toAgentSchema(prop);
76
+ return {
77
+ name,
78
+ description: prop?.description ?? `(${prop?.type ?? 'any'})`,
79
+ required: required.has(name),
80
+ schema: subSchema
81
+ };
82
+ });
83
+ }
84
+ /**
85
+ * Render an MCP tool result into the plaintext form Bandit's loop
86
+ * expects. MCP results are an array of content blocks (text / image
87
+ * / resource); for v1 we concatenate every text block and surface
88
+ * non-text blocks as a one-line marker so the model knows it received
89
+ * non-text data without us inlining bytes.
90
+ */
91
+ function renderMcpResult(result) {
92
+ const blocks = result?.content ?? [];
93
+ const textParts = [];
94
+ for (const block of blocks) {
95
+ if (block.type === 'text' && typeof block.text === 'string') {
96
+ textParts.push(block.text);
97
+ }
98
+ else {
99
+ textParts.push(`[mcp:${block.type}] (non-text content omitted)`);
100
+ }
101
+ }
102
+ const output = textParts.join('\n').trim() || '(empty MCP response)';
103
+ return { output, isError: !!result?.isError };
104
+ }
105
+ /**
106
+ * Build an AgentTool that proxies through the pool to the named
107
+ * server's named tool. Parameter list is derived from the MCP tool's
108
+ * input schema; description is preserved verbatim with a small
109
+ * "(via MCP server <name>)" suffix so the user reading their session
110
+ * log can tell which server's tools the agent reached for.
111
+ */
112
+ function mcpToolToAgentTool(serverName, remote, pool) {
113
+ const namespacedName = `${serverName}.${remote.name}`;
114
+ const description = remote.description
115
+ ? `${remote.description} (via MCP server "${serverName}")`
116
+ : `MCP tool "${remote.name}" exposed by server "${serverName}".`;
117
+ const parameters = convertInputSchema(remote.inputSchema);
118
+ return {
119
+ name: namespacedName,
120
+ description,
121
+ parameters,
122
+ async execute(params, _ctx) {
123
+ try {
124
+ // Bandit's tool-use loop hands us params as Record<string, string>
125
+ // (the tool-call parser stringifies nested objects/arrays before
126
+ // they reach execute()) — we reverse that here so MCP tools
127
+ // whose backends actually validate object/array shapes receive
128
+ // the original structure.
129
+ //
130
+ // Critical bug shipped pre-1.7.282: the prior `\[|\{` regex
131
+ // only matched a SINGLE literal `[` or `{` character, NOT a
132
+ // full JSON array/object string starting with those. So
133
+ // `{"from":"npm"}` failed the test, JSON.parse never ran,
134
+ // and the MCP server got the raw string — zod rejected with
135
+ // "Expected object, received string." The schema-passthrough
136
+ // fix in v1.7.281 made the MODEL emit objects correctly but
137
+ // they were still being stringified on the way through Bandit's
138
+ // parser AND this regex never put them back. Fix: detect
139
+ // start-of-JSON characters with `^[{[]`, not the broken
140
+ // single-char alternatives.
141
+ const args = {};
142
+ for (const [k, v] of Object.entries(params)) {
143
+ if (typeof v !== 'string') {
144
+ args[k] = v;
145
+ continue;
146
+ }
147
+ const trimmed = v.trim();
148
+ if (trimmed === '') {
149
+ args[k] = v;
150
+ continue;
151
+ }
152
+ const looksLikeJson = trimmed.startsWith('{') ||
153
+ trimmed.startsWith('[') ||
154
+ /^"[\s\S]*"$/.test(trimmed) ||
155
+ /^(-?\d+(?:\.\d+)?|true|false|null)$/.test(trimmed);
156
+ if (looksLikeJson) {
157
+ try {
158
+ args[k] = JSON.parse(trimmed);
159
+ }
160
+ catch {
161
+ args[k] = v;
162
+ }
163
+ }
164
+ else {
165
+ args[k] = v;
166
+ }
167
+ }
168
+ const result = await pool.callTool(serverName, remote.name, args);
169
+ return renderMcpResult(result);
170
+ }
171
+ catch (err) {
172
+ const msg = err instanceof Error ? err.message : String(err);
173
+ return {
174
+ output: `Error invoking ${namespacedName}: ${msg}`,
175
+ isError: true
176
+ };
177
+ }
178
+ }
179
+ };
180
+ }
181
+ /**
182
+ * Convenience: enumerate every connected server's tools and return
183
+ * AgentTool wrappers ready to register with the existing
184
+ * ToolRegistry. Call from the host (extension or CLI) after the user's
185
+ * mcp-servers.json has been loaded into the pool.
186
+ *
187
+ * The optional `prompt` argument enables activation filtering: when
188
+ * provided, servers configured with `activation: "on-mention"` are
189
+ * only included if their trigger keywords match the prompt. Servers
190
+ * with `activation: "always"` (the default) always contribute their
191
+ * tools regardless of prompt. Pass `undefined` (or omit) to register
192
+ * every server's tools — the -and-earlier behavior.
193
+ *
194
+ * Each server's discoverTools() will lazily spawn the process — so
195
+ * the first call per server after session start does pay the spawn
196
+ * cost. With on-mention activation, that cost only fires for prompts
197
+ * that actually trigger the server.
198
+ */
199
+ async function getAllMcpAgentTools(pool, prompt) {
200
+ const out = [];
201
+ for (const snap of pool.snapshot()) {
202
+ if (!(0, activation_1.shouldActivateServer)(snap.name, snap.config, prompt))
203
+ continue;
204
+ // Defer the FIRST-TIME spawn for `always`-mode servers without a
205
+ // cached tool list. Without this gate, every "hi" triggers
206
+ // `discoverTools` → `ensureConnected` → `spawnAndHandshake` →
207
+ // trust prompt, even though the agent has no MCP intent. With
208
+ // the gate: skip enumeration unless either (a) the user's prompt
209
+ // mentions the server / one of its triggers, or (b) we already
210
+ // have a cached tool list and the spawn is therefore not needed
211
+ // for this enumeration call. After the first successful spawn
212
+ // the cache populates and subsequent prompts never re-spawn.
213
+ const cached = pool.hasCachedTools(snap.name);
214
+ if (!cached && !(0, activation_1.isServerMentioned)(snap.name, snap.config, prompt))
215
+ continue;
216
+ const tools = await pool.discoverTools(snap.name);
217
+ for (const remote of tools) {
218
+ out.push(mcpToolToAgentTool(snap.name, remote, pool));
219
+ }
220
+ }
221
+ return out;
222
+ }
223
+ //# sourceMappingURL=toolAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolAdapter.js","sourceRoot":"","sources":["../../src/mcp/toolAdapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAiHH,gDAk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