@adhd/agent-mcp 2.0.1 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/AGENTS.md +236 -0
  2. package/CHANGELOG.md +115 -0
  3. package/LICENSE +21 -0
  4. package/README.md +201 -0
  5. package/adhd-agent-mcp-2.1.1.tgz +0 -0
  6. package/docs/architecture-and-security.md +405 -0
  7. package/docs/marketing/.catalog/capabilities.md +143 -0
  8. package/docs/marketing/.catalog/consumer.md +111 -0
  9. package/docs/marketing/.catalog/distribution.md +223 -0
  10. package/docs/marketing/.catalog/doc-conformance.md +237 -0
  11. package/docs/marketing/.catalog/doc-ops.md +98 -0
  12. package/docs/marketing/.catalog/metrics.md +119 -0
  13. package/docs/marketing/.catalog/required-tooling.md +224 -0
  14. package/docs/marketing/.catalog/review.md +164 -0
  15. package/docs/provider-call-audit.md +254 -0
  16. package/drizzle/0007_smart_callisto.sql +40 -0
  17. package/drizzle/0008_cache_and_peak_context_usage.sql +19 -0
  18. package/drizzle/0009_restore_sessions_agent_fk.sql +29 -0
  19. package/drizzle/meta/0007_snapshot.json +658 -0
  20. package/drizzle/meta/_journal.json +22 -1
  21. package/llms.txt +133 -0
  22. package/package.json +30 -51
  23. package/src/__tests__/integration/harness.d.ts +871 -39
  24. package/src/__tests__/integration/harness.d.ts.map +1 -1
  25. package/src/__tests__/integration/harness.js +93 -87
  26. package/src/__tests__/integration/harness.js.map +1 -1
  27. package/src/__tests__/integration/scripted-provider.d.ts +1 -2
  28. package/src/__tests__/integration/scripted-provider.d.ts.map +1 -1
  29. package/src/__tests__/integration/scripted-provider.js +1 -3
  30. package/src/__tests__/integration/scripted-provider.js.map +1 -1
  31. package/src/config.d.ts +6 -69
  32. package/src/config.d.ts.map +1 -1
  33. package/src/config.js +1 -50
  34. package/src/config.js.map +1 -1
  35. package/src/db/client.d.ts +1516 -2
  36. package/src/db/client.d.ts.map +1 -1
  37. package/src/db/client.js +4 -2
  38. package/src/db/client.js.map +1 -1
  39. package/src/db/migrate-runner.d.ts +0 -28
  40. package/src/db/migrate-runner.d.ts.map +1 -1
  41. package/src/db/migrate-runner.js +0 -24
  42. package/src/db/migrate-runner.js.map +1 -1
  43. package/src/db/migrate.d.ts +0 -7
  44. package/src/db/migrate.d.ts.map +1 -1
  45. package/src/db/migrate.js +0 -7
  46. package/src/db/migrate.js.map +1 -1
  47. package/src/db/schema.d.ts +0 -1260
  48. package/src/db/schema.d.ts.map +1 -1
  49. package/src/db/schema.js +2 -179
  50. package/src/db/schema.js.map +1 -1
  51. package/src/index.d.ts +3 -42
  52. package/src/index.d.ts.map +1 -1
  53. package/src/index.js +32 -123
  54. package/src/index.js.map +1 -1
  55. package/src/logger.d.ts +0 -8
  56. package/src/logger.d.ts.map +1 -1
  57. package/src/logger.js +1 -12
  58. package/src/logger.js.map +1 -1
  59. package/src/scripts/agent-mcp-tail.d.ts +3 -0
  60. package/src/scripts/agent-mcp-tail.d.ts.map +1 -0
  61. package/src/scripts/agent-mcp-tail.js +227 -0
  62. package/src/scripts/agent-mcp-tail.js.map +1 -0
  63. package/src/server.d.ts +13 -34
  64. package/src/server.d.ts.map +1 -1
  65. package/src/server.js +234 -326
  66. package/src/server.js.map +1 -1
  67. package/src/store/agent-store.d.ts +3 -16
  68. package/src/store/agent-store.d.ts.map +1 -1
  69. package/src/store/agent-store.js +38 -41
  70. package/src/store/agent-store.js.map +1 -1
  71. package/src/streaming/chat-gateway.d.ts +17 -0
  72. package/src/streaming/chat-gateway.d.ts.map +1 -0
  73. package/src/streaming/chat-gateway.js +336 -0
  74. package/src/streaming/chat-gateway.js.map +1 -0
  75. package/src/streaming/event-bus.d.ts +4 -0
  76. package/src/streaming/event-bus.d.ts.map +1 -1
  77. package/src/streaming/event-bus.js +14 -1
  78. package/src/streaming/event-bus.js.map +1 -1
  79. package/src/streaming/sse-server.d.ts +3 -14
  80. package/src/streaming/sse-server.d.ts.map +1 -1
  81. package/src/streaming/sse-server.js +37 -37
  82. package/src/streaming/sse-server.js.map +1 -1
  83. package/src/utils/load-env.d.ts +0 -14
  84. package/src/utils/load-env.d.ts.map +1 -1
  85. package/src/utils/load-env.js +0 -18
  86. package/src/utils/load-env.js.map +1 -1
  87. package/src/clients/http-client.d.ts +0 -24
  88. package/src/clients/http-client.d.ts.map +0 -1
  89. package/src/clients/http-client.js +0 -98
  90. package/src/clients/http-client.js.map +0 -1
  91. package/src/clients/in-process.d.ts +0 -27
  92. package/src/clients/in-process.d.ts.map +0 -1
  93. package/src/clients/in-process.js +0 -37
  94. package/src/clients/in-process.js.map +0 -1
  95. package/src/clients/index.d.ts +0 -7
  96. package/src/clients/index.d.ts.map +0 -1
  97. package/src/clients/index.js +0 -5
  98. package/src/clients/index.js.map +0 -1
  99. package/src/clients/registry.d.ts +0 -54
  100. package/src/clients/registry.d.ts.map +0 -1
  101. package/src/clients/registry.js +0 -164
  102. package/src/clients/registry.js.map +0 -1
  103. package/src/clients/stdio-client.d.ts +0 -16
  104. package/src/clients/stdio-client.d.ts.map +0 -1
  105. package/src/clients/stdio-client.js +0 -97
  106. package/src/clients/stdio-client.js.map +0 -1
  107. package/src/clients/tool-naming.d.ts +0 -44
  108. package/src/clients/tool-naming.d.ts.map +0 -1
  109. package/src/clients/tool-naming.js +0 -65
  110. package/src/clients/tool-naming.js.map +0 -1
  111. package/src/clients/types.d.ts +0 -18
  112. package/src/clients/types.d.ts.map +0 -1
  113. package/src/clients/types.js +0 -2
  114. package/src/clients/types.js.map +0 -1
  115. package/src/engine/dag-engine.d.ts +0 -62
  116. package/src/engine/dag-engine.d.ts.map +0 -1
  117. package/src/engine/dag-engine.js +0 -158
  118. package/src/engine/dag-engine.js.map +0 -1
  119. package/src/engine/hooks.d.ts +0 -24
  120. package/src/engine/hooks.d.ts.map +0 -1
  121. package/src/engine/hooks.js +0 -50
  122. package/src/engine/hooks.js.map +0 -1
  123. package/src/engine/orchestrator.d.ts +0 -40
  124. package/src/engine/orchestrator.d.ts.map +0 -1
  125. package/src/engine/orchestrator.js +0 -507
  126. package/src/engine/orchestrator.js.map +0 -1
  127. package/src/engine/policy.d.ts +0 -66
  128. package/src/engine/policy.d.ts.map +0 -1
  129. package/src/engine/policy.js +0 -112
  130. package/src/engine/policy.js.map +0 -1
  131. package/src/engine/prompt-resolver.d.ts +0 -89
  132. package/src/engine/prompt-resolver.d.ts.map +0 -1
  133. package/src/engine/prompt-resolver.js +0 -96
  134. package/src/engine/prompt-resolver.js.map +0 -1
  135. package/src/engine/queue.d.ts +0 -29
  136. package/src/engine/queue.d.ts.map +0 -1
  137. package/src/engine/queue.js +0 -56
  138. package/src/engine/queue.js.map +0 -1
  139. package/src/plugins/index.d.ts +0 -2
  140. package/src/plugins/index.d.ts.map +0 -1
  141. package/src/plugins/index.js +0 -2
  142. package/src/plugins/index.js.map +0 -1
  143. package/src/plugins/loader.d.ts +0 -65
  144. package/src/plugins/loader.d.ts.map +0 -1
  145. package/src/plugins/loader.js +0 -222
  146. package/src/plugins/loader.js.map +0 -1
  147. package/src/plugins/usage-plugin.d.ts +0 -27
  148. package/src/plugins/usage-plugin.d.ts.map +0 -1
  149. package/src/plugins/usage-plugin.js +0 -148
  150. package/src/plugins/usage-plugin.js.map +0 -1
  151. package/src/providers/anthropic.d.ts +0 -13
  152. package/src/providers/anthropic.d.ts.map +0 -1
  153. package/src/providers/anthropic.js +0 -260
  154. package/src/providers/anthropic.js.map +0 -1
  155. package/src/providers/claudecli.d.ts +0 -153
  156. package/src/providers/claudecli.d.ts.map +0 -1
  157. package/src/providers/claudecli.js +0 -510
  158. package/src/providers/claudecli.js.map +0 -1
  159. package/src/providers/factory.d.ts +0 -10
  160. package/src/providers/factory.d.ts.map +0 -1
  161. package/src/providers/factory.js +0 -24
  162. package/src/providers/factory.js.map +0 -1
  163. package/src/providers/index.d.ts +0 -6
  164. package/src/providers/index.d.ts.map +0 -1
  165. package/src/providers/index.js +0 -5
  166. package/src/providers/index.js.map +0 -1
  167. package/src/providers/openai.d.ts +0 -14
  168. package/src/providers/openai.d.ts.map +0 -1
  169. package/src/providers/openai.js +0 -162
  170. package/src/providers/openai.js.map +0 -1
  171. package/src/providers/types.d.ts +0 -36
  172. package/src/providers/types.d.ts.map +0 -1
  173. package/src/providers/types.js +0 -2
  174. package/src/providers/types.js.map +0 -1
  175. package/src/store/composed-prompt-store.d.ts +0 -24
  176. package/src/store/composed-prompt-store.d.ts.map +0 -1
  177. package/src/store/composed-prompt-store.js +0 -75
  178. package/src/store/composed-prompt-store.js.map +0 -1
  179. package/src/store/index.d.ts +0 -5
  180. package/src/store/index.d.ts.map +0 -1
  181. package/src/store/index.js +0 -5
  182. package/src/store/index.js.map +0 -1
  183. package/src/store/session-store.d.ts +0 -45
  184. package/src/store/session-store.d.ts.map +0 -1
  185. package/src/store/session-store.js +0 -197
  186. package/src/store/session-store.js.map +0 -1
  187. package/src/store/task-store.d.ts +0 -55
  188. package/src/store/task-store.d.ts.map +0 -1
  189. package/src/store/task-store.js +0 -186
  190. package/src/store/task-store.js.map +0 -1
  191. package/src/tools/agent-crud.d.ts +0 -15
  192. package/src/tools/agent-crud.d.ts.map +0 -1
  193. package/src/tools/agent-crud.js +0 -32
  194. package/src/tools/agent-crud.js.map +0 -1
  195. package/src/tools/session.d.ts +0 -33
  196. package/src/tools/session.d.ts.map +0 -1
  197. package/src/tools/session.js +0 -73
  198. package/src/tools/session.js.map +0 -1
  199. package/src/tools/task.d.ts +0 -86
  200. package/src/tools/task.d.ts.map +0 -1
  201. package/src/tools/task.js +0 -406
  202. package/src/tools/task.js.map +0 -1
  203. package/src/tools/usage.d.ts +0 -60
  204. package/src/tools/usage.d.ts.map +0 -1
  205. package/src/tools/usage.js +0 -174
  206. package/src/tools/usage.js.map +0 -1
  207. package/src/types/agent.d.ts +0 -2
  208. package/src/types/agent.d.ts.map +0 -1
  209. package/src/types/agent.js +0 -3
  210. package/src/types/agent.js.map +0 -1
  211. package/src/types/execution.d.ts +0 -2
  212. package/src/types/execution.d.ts.map +0 -1
  213. package/src/types/execution.js +0 -3
  214. package/src/types/execution.js.map +0 -1
  215. package/src/types/index.d.ts +0 -2
  216. package/src/types/index.d.ts.map +0 -1
  217. package/src/types/index.js +0 -2
  218. package/src/types/index.js.map +0 -1
  219. package/src/types/mcp.d.ts +0 -2
  220. package/src/types/mcp.d.ts.map +0 -1
  221. package/src/types/mcp.js +0 -3
  222. package/src/types/mcp.js.map +0 -1
  223. package/src/types/message.d.ts +0 -2
  224. package/src/types/message.d.ts.map +0 -1
  225. package/src/types/message.js +0 -3
  226. package/src/types/message.js.map +0 -1
  227. package/src/types/session.d.ts +0 -2
  228. package/src/types/session.d.ts.map +0 -1
  229. package/src/types/session.js +0 -3
  230. package/src/types/session.js.map +0 -1
  231. package/src/types/task.d.ts +0 -2
  232. package/src/types/task.d.ts.map +0 -1
  233. package/src/types/task.js +0 -3
  234. package/src/types/task.js.map +0 -1
  235. package/src/utils/ids.d.ts +0 -2
  236. package/src/utils/ids.d.ts.map +0 -1
  237. package/src/utils/ids.js +0 -5
  238. package/src/utils/ids.js.map +0 -1
  239. package/src/utils/logger.d.ts +0 -2
  240. package/src/utils/logger.d.ts.map +0 -1
  241. package/src/utils/logger.js +0 -5
  242. package/src/utils/logger.js.map +0 -1
  243. package/src/utils/timestamps.d.ts +0 -2
  244. package/src/utils/timestamps.d.ts.map +0 -1
  245. package/src/utils/timestamps.js +0 -4
  246. package/src/utils/timestamps.js.map +0 -1
  247. package/src/validation/agent.d.ts +0 -400
  248. package/src/validation/agent.d.ts.map +0 -1
  249. package/src/validation/agent.js +0 -251
  250. package/src/validation/agent.js.map +0 -1
  251. package/src/validation/agents.d.ts +0 -2
  252. package/src/validation/agents.d.ts.map +0 -1
  253. package/src/validation/agents.js +0 -3
  254. package/src/validation/agents.js.map +0 -1
  255. package/src/validation/errors.d.ts +0 -32
  256. package/src/validation/errors.d.ts.map +0 -1
  257. package/src/validation/errors.js +0 -42
  258. package/src/validation/errors.js.map +0 -1
  259. package/src/validation/execution.d.ts +0 -86
  260. package/src/validation/execution.d.ts.map +0 -1
  261. package/src/validation/execution.js +0 -28
  262. package/src/validation/execution.js.map +0 -1
  263. package/src/validation/index.d.ts +0 -9
  264. package/src/validation/index.d.ts.map +0 -1
  265. package/src/validation/index.js +0 -9
  266. package/src/validation/index.js.map +0 -1
  267. package/src/validation/mcp.d.ts +0 -42
  268. package/src/validation/mcp.d.ts.map +0 -1
  269. package/src/validation/mcp.js +0 -28
  270. package/src/validation/mcp.js.map +0 -1
  271. package/src/validation/message.d.ts +0 -43
  272. package/src/validation/message.d.ts.map +0 -1
  273. package/src/validation/message.js +0 -23
  274. package/src/validation/message.js.map +0 -1
  275. package/src/validation/session.d.ts +0 -49
  276. package/src/validation/session.d.ts.map +0 -1
  277. package/src/validation/session.js +0 -34
  278. package/src/validation/session.js.map +0 -1
  279. package/src/validation/task.d.ts +0 -146
  280. package/src/validation/task.d.ts.map +0 -1
  281. package/src/validation/task.js +0 -95
  282. package/src/validation/task.js.map +0 -1
  283. package/src/validation/tasks.d.ts +0 -2
  284. package/src/validation/tasks.d.ts.map +0 -1
  285. package/src/validation/tasks.js +0 -3
  286. package/src/validation/tasks.js.map +0 -1
  287. package/src/validation/usage.d.ts +0 -89
  288. package/src/validation/usage.d.ts.map +0 -1
  289. package/src/validation/usage.js +0 -98
  290. package/src/validation/usage.js.map +0 -1
@@ -1,112 +0,0 @@
1
- import { ToolError } from "../validation/errors.js";
2
- // ── internal helpers ──────────────────────────────────────────────────────────
3
- /**
4
- * Extract the first numeric value for `key` from rate-type template rules.
5
- * Returns undefined when no rate template carries the key.
6
- */
7
- function readRateLimit(templates, key) {
8
- if (!templates)
9
- return undefined;
10
- for (const t of templates) {
11
- if (t.type !== "rate")
12
- continue;
13
- const val = t.rules[key];
14
- if (typeof val === "number" && Number.isFinite(val))
15
- return val;
16
- }
17
- return undefined;
18
- }
19
- /**
20
- * Extract the allowedAgents allowlist from permission-type template rules.
21
- *
22
- * A permission template is applied only when `mode === "allowlist"`. When found,
23
- * returns the `allowlist` array (possibly empty = block all). Returns undefined
24
- * when no permission template with mode=allowlist is present.
25
- */
26
- function readPermissionAllowlist(templates) {
27
- if (!templates)
28
- return undefined;
29
- for (const t of templates) {
30
- if (t.type !== "permission")
31
- continue;
32
- if (t.rules["mode"] !== "allowlist")
33
- continue;
34
- const list = t.rules["allowlist"];
35
- if (Array.isArray(list))
36
- return list;
37
- }
38
- return undefined;
39
- }
40
- /**
41
- * PolicyEngine enforces the three SPEC §9 safety invariants:
42
- *
43
- * 1. Recursion depth limit
44
- * 2. Tool call loop limit
45
- * 3. AllowedAgents list (per-agent override takes full precedence over server default)
46
- *
47
- * Limits are resolved in priority order:
48
- * 1. Per-agent agentDefinition fields (highest — always wins)
49
- * 2. @adhd/agent-policy template rules (when policyTemplateRules is supplied)
50
- * 3. PolicyConfig server defaults (hardcoded fallback)
51
- *
52
- * Throws ToolError on any violation. Does not mutate state.
53
- */
54
- export class PolicyEngine {
55
- config;
56
- constructor(config) {
57
- this.config = config;
58
- }
59
- check(input) {
60
- const { executionContext, targetTool, targetAgentName } = input;
61
- const callingAgent = executionContext.agentDefinition;
62
- const templates = this.config.policyTemplateRules;
63
- // ── Check 1: Recursion depth ──────────────────────────────────────
64
- //
65
- // Priority: agentDefinition.maxToolLoops → rate template max_recursion_depth
66
- // → serverMaxDepth (default)
67
- const templateMaxDepth = readRateLimit(templates, "max_recursion_depth");
68
- const serverMaxDepth = templateMaxDepth !== undefined
69
- ? Math.min(templateMaxDepth, this.config.serverMaxDepth)
70
- : this.config.serverMaxDepth;
71
- const effectiveMaxDepth = Math.min(callingAgent.maxToolLoops ?? serverMaxDepth, serverMaxDepth);
72
- if (executionContext.recursionDepth >= effectiveMaxDepth) {
73
- throw new ToolError("MAX_DEPTH_EXCEEDED", `Recursion depth ${executionContext.recursionDepth} has reached or exceeded the maximum of ${effectiveMaxDepth}`);
74
- }
75
- // ── Check 2: Tool call loop limit ─────────────────────────────────
76
- //
77
- // Priority: agentDefinition.maxToolLoops → rate template max_tool_loops
78
- // → serverMaxToolLoops (default)
79
- const templateMaxToolLoops = readRateLimit(templates, "max_tool_loops");
80
- const serverMaxToolLoops = templateMaxToolLoops !== undefined
81
- ? Math.min(templateMaxToolLoops, this.config.serverMaxToolLoops)
82
- : this.config.serverMaxToolLoops;
83
- const effectiveMaxToolLoops = Math.min(callingAgent.maxToolLoops ?? serverMaxToolLoops, serverMaxToolLoops);
84
- if (executionContext.toolCallCount >= effectiveMaxToolLoops) {
85
- throw new ToolError("MAX_TOOL_LOOPS_EXCEEDED", `Tool call count ${executionContext.toolCallCount} has reached or exceeded the maximum of ${effectiveMaxToolLoops}`);
86
- }
87
- // ── Check 3: AllowedAgents (only for agent delegation) ────────────
88
- if (targetTool === "agent-mcp__agent" && targetAgentName !== undefined) {
89
- // Per-agent allowedAgents takes FULL precedence over everything.
90
- const agentAllowedAgents = callingAgent.permissions.allowedAgents;
91
- let effectiveAllowedAgents;
92
- if (agentAllowedAgents !== undefined) {
93
- // Agent-level always wins — ignore templates and server default.
94
- effectiveAllowedAgents = agentAllowedAgents;
95
- }
96
- else {
97
- // Check permission template allowlist first, then server default.
98
- const templateAllowlist = readPermissionAllowlist(templates);
99
- effectiveAllowedAgents = templateAllowlist !== undefined
100
- ? templateAllowlist
101
- : this.config.serverAllowedAgents;
102
- }
103
- // If effectiveAllowedAgents is undefined → unrestricted
104
- if (effectiveAllowedAgents !== undefined) {
105
- if (!effectiveAllowedAgents.includes(targetAgentName)) {
106
- throw new ToolError("DELEGATION_NOT_ALLOWED", `Agent '${executionContext.agentName}' is not allowed to delegate to '${targetAgentName}'`);
107
- }
108
- }
109
- }
110
- }
111
- }
112
- //# sourceMappingURL=policy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"policy.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/policy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAoEpD,i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AAI,UAAU,KAAK,kBAAkB,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;YACrE,iEAAiE;YACjE,MAAM,kBAAkB,GAAG,YAAY,CAAC,WAAW,CAAC,aAAa,CAAC;YAElE,IAAI,sBAA4C,CAAC;YACjD,IAAI,kBAAkB,KAAK,SAAS,EAAE,CAAC;gBACnC,iEAAiE;gBACjE,sBAAsB,GAAG,kBAAkB,CAAC;YAChD,CAAC;iBAAM,CAAC;gBACJ,kEAAkE;gBAClE,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC;gBAC7D,sBAAsB,GAAG,iBAAiB,KAAK,SAAS;oBACpD,CAAC,CAAC,iBAAiB;oBACnB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC;YAC1C,CAAC;YAED,wDAAwD;YACxD,IAAI,sBAAsB,KAAK,SAAS,EAAE,CAAC;gBACvC,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;oBACpD,MAAM,IAAI,SAAS,CACf,wBAAwB,EACxB,UAAU,gBAAgB,CAAC,SAAS,oCAAoC,eAAe,GAAG,CAC7F,CAAC;gBACN,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;CACJ"}
@@ -1,89 +0,0 @@
1
- /**
2
- * prompt-resolver — resolves a compiled system-prompt for a session start.
3
- *
4
- * Flow:
5
- * 1. Compute context_hash from (agentSlug, platform, context).
6
- * 2. Look up agent-mcp's own composed_prompts cache via ComposedPromptStore.
7
- * 3. HIT → return {content, id} WITHOUT calling compileAgent.
8
- * 4. MISS → call compileAgent(…), upsert the row, return {content, id}.
9
- *
10
- * compileAgent is injected as a parameter (compileAgentFn) so tests can stub it
11
- * without modifying production code. Production callers pass the real
12
- * `compileAgent` from @adhd/agent-compiler.
13
- *
14
- * [compiler-integration.1] — imports compileAgent from @adhd/agent-compiler
15
- * [compiler-integration.2] — caches/looks up the composed prompt and writes composed_prompt_id
16
- */
17
- import type { BetterSQLite3Database } from "drizzle-orm/better-sqlite3";
18
- import type { CompileInput, CompiledAgent } from "@adhd/agent-compiler";
19
- import type { ComposedPromptStore } from "../store/composed-prompt-store.js";
20
- export interface ResolveInput {
21
- /** Slug (name) of the agent to resolve. */
22
- agentSlug: string;
23
- /** Target platform id (e.g. "claude_code", "claude_api"). */
24
- platform: string;
25
- /** Runtime context key/value map (e.g. `{ ticket_type: "security" }`). */
26
- context?: Record<string, string>;
27
- }
28
- export interface ResolveResult {
29
- /** Flat system-prompt string produced by compileAgent() or served from cache. */
30
- content: string;
31
- /** Row id in agent-mcp's composed_prompts table — written to sessions.composed_prompt_id. */
32
- id: string;
33
- }
34
- /**
35
- * Injectable compile function — matches the signature of
36
- * `compileAgent` from @adhd/agent-compiler so tests can stub it.
37
- */
38
- export type CompileAgentFn = (input: CompileInput) => CompiledAgent;
39
- export interface PromptResolverDeps {
40
- /** Agent-mcp's own composed_prompts cache store. */
41
- composedPromptStore: ComposedPromptStore;
42
- /**
43
- * The compileAgent function from @adhd/agent-compiler.
44
- * Injectable so tests can stub without touching production code.
45
- */
46
- compileAgentFn: CompileAgentFn;
47
- /**
48
- * Registry DB handle passed through to compileAgent on cache MISS.
49
- * Must point at the agent-registry SQLite file (all four table prefixes).
50
- * Unused on a cache HIT.
51
- */
52
- registryDb: BetterSQLite3Database<any>;
53
- }
54
- /**
55
- * Compute a deterministic SHA-256 cache key from (agentSlug, platform, context).
56
- *
57
- * The key encodes every runtime dimension that could produce a different compiled
58
- * artifact: the agent identity, the target platform, and any runtime context
59
- * key/value pairs. Keys in `context` are sorted before serialisation so that
60
- * insertion order cannot produce different hashes for identical logical inputs.
61
- *
62
- * @returns 64-character lowercase hex SHA-256 string.
63
- */
64
- export declare function computeContextHash(agentSlug: string, platform: string, context: Record<string, string>): string;
65
- /**
66
- * Resolve the compiled system-prompt for a session start.
67
- *
68
- * On a cache HIT (agent-mcp's `composed_prompts` already has a row for this
69
- * agent + context hash) the cached `{content, id}` is returned WITHOUT calling
70
- * compileAgent — the registry round-trip is skipped entirely.
71
- *
72
- * On a cache MISS, compileAgent is called with the supplied `registryDb` handle.
73
- * The result is upserted into agent-mcp's `composed_prompts` table and the
74
- * returned `id` is suitable for writing to `sessions.composed_prompt_id`.
75
- *
76
- * **Flat-prompt fallback (backward compatibility):** when `compileAgentFn`
77
- * throws (e.g. the agent has no registry composition — `AgentError` with code
78
- * `AGENT_NOT_FOUND`, or a `CompositionError`) this function returns `null`
79
- * instead of propagating. The caller (`agentTool`) then falls back to the
80
- * stored `agentDefinition.systemPrompt`, so a legacy flat-`systemPrompt` agent
81
- * continues to work even when a live registry DB is wired.
82
- *
83
- * @param input - Agent slug, target platform, and optional runtime context.
84
- * @param deps - Injected ComposedPromptStore, compileAgentFn, and registry DB.
85
- * @returns {content, id} on success, or `null` when no registry composition
86
- * exists for the agent (caller must fall back to the flat systemPrompt).
87
- */
88
- export declare function resolveComposedPrompt(input: ResolveInput, deps: PromptResolverDeps): ResolveResult | null;
89
- //# sourceMappingURL=prompt-resolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompt-resolver.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/prompt-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAK7E,MAAM,WAAW,YAAY;IACzB,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,aAAa;IAC1B,iFAAiF;IACjF,OAAO,EAAE,MAAM,CAAC;IAChB,6FAA6F;IAC7F,EAAE,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,aAAa,CAAC;AAEpE,MAAM,WAAW,kBAAkB;IAC/B,oDAAoD;IACpD,mBAAmB,EAAE,mBAAmB,CAAC;IACzC;;;OAGG;IACH,cAAc,EAAE,cAAc,CAAC;IAC/B;;;;OAIG;IAEH,UAAU,EAAE,qBAAqB,CAAC,GAAG,CAAC,CAAC;CAC1C;AAID;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,MAAM,CAMR;AAID;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CACjC,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,kBAAkB,GACzB,aAAa,GAAG,IAAI,CAmDtB"}
@@ -1,96 +0,0 @@
1
- /**
2
- * prompt-resolver — resolves a compiled system-prompt for a session start.
3
- *
4
- * Flow:
5
- * 1. Compute context_hash from (agentSlug, platform, context).
6
- * 2. Look up agent-mcp's own composed_prompts cache via ComposedPromptStore.
7
- * 3. HIT → return {content, id} WITHOUT calling compileAgent.
8
- * 4. MISS → call compileAgent(…), upsert the row, return {content, id}.
9
- *
10
- * compileAgent is injected as a parameter (compileAgentFn) so tests can stub it
11
- * without modifying production code. Production callers pass the real
12
- * `compileAgent` from @adhd/agent-compiler.
13
- *
14
- * [compiler-integration.1] — imports compileAgent from @adhd/agent-compiler
15
- * [compiler-integration.2] — caches/looks up the composed prompt and writes composed_prompt_id
16
- */
17
- import { createHash } from "node:crypto";
18
- import { logger } from "../logger.js";
19
- // ── Context hash ─────────────────────────────────────────────────────────────
20
- /**
21
- * Compute a deterministic SHA-256 cache key from (agentSlug, platform, context).
22
- *
23
- * The key encodes every runtime dimension that could produce a different compiled
24
- * artifact: the agent identity, the target platform, and any runtime context
25
- * key/value pairs. Keys in `context` are sorted before serialisation so that
26
- * insertion order cannot produce different hashes for identical logical inputs.
27
- *
28
- * @returns 64-character lowercase hex SHA-256 string.
29
- */
30
- export function computeContextHash(agentSlug, platform, context) {
31
- const sortedContext = Object.fromEntries(Object.keys(context).sort().map(k => [k, context[k]]));
32
- const payload = `${agentSlug}|${platform}|${JSON.stringify(sortedContext)}`;
33
- return createHash("sha256").update(payload, "utf8").digest("hex");
34
- }
35
- // ── Public resolver ──────────────────────────────────────────────────────────
36
- /**
37
- * Resolve the compiled system-prompt for a session start.
38
- *
39
- * On a cache HIT (agent-mcp's `composed_prompts` already has a row for this
40
- * agent + context hash) the cached `{content, id}` is returned WITHOUT calling
41
- * compileAgent — the registry round-trip is skipped entirely.
42
- *
43
- * On a cache MISS, compileAgent is called with the supplied `registryDb` handle.
44
- * The result is upserted into agent-mcp's `composed_prompts` table and the
45
- * returned `id` is suitable for writing to `sessions.composed_prompt_id`.
46
- *
47
- * **Flat-prompt fallback (backward compatibility):** when `compileAgentFn`
48
- * throws (e.g. the agent has no registry composition — `AgentError` with code
49
- * `AGENT_NOT_FOUND`, or a `CompositionError`) this function returns `null`
50
- * instead of propagating. The caller (`agentTool`) then falls back to the
51
- * stored `agentDefinition.systemPrompt`, so a legacy flat-`systemPrompt` agent
52
- * continues to work even when a live registry DB is wired.
53
- *
54
- * @param input - Agent slug, target platform, and optional runtime context.
55
- * @param deps - Injected ComposedPromptStore, compileAgentFn, and registry DB.
56
- * @returns {content, id} on success, or `null` when no registry composition
57
- * exists for the agent (caller must fall back to the flat systemPrompt).
58
- */
59
- export function resolveComposedPrompt(input, deps) {
60
- const { agentSlug, platform, context = {} } = input;
61
- const { composedPromptStore, compileAgentFn, registryDb } = deps;
62
- const contextHash = computeContextHash(agentSlug, platform, context);
63
- // ── Cache HIT ────────────────────────────────────────────────────────────
64
- const cached = composedPromptStore.findByAgentContext(agentSlug, contextHash);
65
- if (cached) {
66
- logger.debug({ agentSlug, composedPromptId: cached.id }, "Composed prompt cache hit — skipping compileAgent");
67
- return { content: cached.content, id: cached.id };
68
- }
69
- // ── Cache MISS — compile and upsert ──────────────────────────────────────
70
- logger.debug({ agentSlug, platform }, "Composed prompt cache miss — calling compileAgent");
71
- let compiled;
72
- try {
73
- compiled = compileAgentFn({
74
- agentSlug,
75
- platform,
76
- context,
77
- db: registryDb,
78
- });
79
- }
80
- catch (err) {
81
- // No registry composition for this agent — fall back to the stored
82
- // flat systemPrompt. Log at debug level: this is expected for agents
83
- // that were created via agent_create without registry backing.
84
- logger.debug({ agentSlug, err }, "compileAgent threw — no registry composition; falling back to flat systemPrompt");
85
- return null;
86
- }
87
- const row = composedPromptStore.upsert({
88
- agentSlug,
89
- contextHash,
90
- content: compiled.content,
91
- componentVersions: JSON.stringify(compiled.componentVersions ?? {}),
92
- });
93
- logger.info({ agentSlug, composedPromptId: row.id }, "Composed prompt compiled and cached");
94
- return { content: row.content, id: row.id };
95
- }
96
- //# sourceMappingURL=prompt-resolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompt-resolver.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/prompt-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMzC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AA2CtC,gFAAgF;AAEhF;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAC9B,SAAiB,EACjB,QAAgB,EAChB,OAA+B;IAE/B,MAAM,aAAa,GAAG,MAAM,CAAC,WAAW,CACpC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC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,EAAE,CAAC;QACX,mEAAmE;QACnE,sEAAsE;QACtE,+DAA+D;QAC/D,MAAM,CAAC,KAAK,CACR,EAAE,SAAS,EAAE,GAAG,EAAE,EAClB,iFAAiF,CACpF,CAAC;QACF,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,GAAG,GAAG,mBAAmB,CAAC,MAAM,CAAC;QACnC,SAAS;QACT,WAAW;QACX,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,IAAI,EAAE,CAAC;KACtE,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CACP,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,CAAC,EAAE,EAAE,EACvC,qCAAqC,CACxC,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;AAChD,CAAC"}
@@ -1,29 +0,0 @@
1
- export type BackgroundTaskFn = () => Promise<void>;
2
- /**
3
- * BackgroundQueue wraps p-queue to run async tasks with concurrency limiting.
4
- *
5
- * TaskStore is NOT a dependency of BackgroundQueue's constructor — it is
6
- * injected into each enqueue call to avoid circular dependencies. The queue
7
- * only knows how to run tasks; the caller controls persistence.
8
- */
9
- export declare class BackgroundQueue {
10
- private readonly queue;
11
- constructor(concurrency?: number);
12
- /**
13
- * Enqueue a background task.
14
- *
15
- * The task function is responsible for calling
16
- * `taskStore.updateStatus(taskId, ...)` on completion or failure.
17
- * The orchestrator handles this internally via try/catch/finally.
18
- */
19
- enqueue(taskId: string, runFn: BackgroundTaskFn): void;
20
- get pending(): number;
21
- get size(): number;
22
- /**
23
- * Returns a Promise that resolves when the queue has drained to idle
24
- * (all currently enqueued and running tasks have finished).
25
- * Delegates to p-queue's own `onIdle()`.
26
- */
27
- onIdle(): Promise<void>;
28
- }
29
- //# sourceMappingURL=queue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/queue.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnD;;;;;;GAMG;AACH,qBAAa,eAAe;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEnB,WAAW,CAAC,EAAE,MAAM;IAMhC;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,IAAI;IAkBtD,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;OAIG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAG1B"}
@@ -1,56 +0,0 @@
1
- import PQueue from "p-queue";
2
- import { logger } from "../logger.js";
3
- import { config } from "../config.js";
4
- /**
5
- * BackgroundQueue wraps p-queue to run async tasks with concurrency limiting.
6
- *
7
- * TaskStore is NOT a dependency of BackgroundQueue's constructor — it is
8
- * injected into each enqueue call to avoid circular dependencies. The queue
9
- * only knows how to run tasks; the caller controls persistence.
10
- */
11
- export class BackgroundQueue {
12
- queue;
13
- constructor(concurrency) {
14
- const resolvedConcurrency = concurrency ?? config.queue.concurrency;
15
- this.queue = new PQueue({ concurrency: resolvedConcurrency });
16
- }
17
- /**
18
- * Enqueue a background task.
19
- *
20
- * The task function is responsible for calling
21
- * `taskStore.updateStatus(taskId, ...)` on completion or failure.
22
- * The orchestrator handles this internally via try/catch/finally.
23
- */
24
- enqueue(taskId, runFn) {
25
- this.queue.add(async () => {
26
- logger.debug({ taskId }, "Background task dequeued");
27
- try {
28
- await runFn();
29
- }
30
- catch (error) {
31
- // DEBT-001 error boundary: the orchestrator's try/catch/finally already
32
- // updates the task status and emits TASK_FAILED before re-throwing.
33
- // Swallowing here is intentional — rethrowing would surface as an
34
- // unhandled rejection in p-queue and reach our process.on("unhandledRejection")
35
- // handler, killing the server for a per-task failure. Log for observability.
36
- logger.error({ taskId, error }, "Background task failed");
37
- }
38
- });
39
- logger.debug({ taskId, pending: this.queue.pending, size: this.queue.size }, "Background task enqueued");
40
- }
41
- get pending() {
42
- return this.queue.pending;
43
- }
44
- get size() {
45
- return this.queue.size;
46
- }
47
- /**
48
- * Returns a Promise that resolves when the queue has drained to idle
49
- * (all currently enqueued and running tasks have finished).
50
- * Delegates to p-queue's own `onIdle()`.
51
- */
52
- onIdle() {
53
- return this.queue.onIdle();
54
- }
55
- }
56
- //# sourceMappingURL=queue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/queue.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC;;;;;;GAMG;AACH,MAAM,OAAO,eAAe;IACP,KAAK,CAAS;IAE/B,YAAY,WAAoB;QAC5B,MAAM,mBAAmB,GAAG,WAAW,IAAI,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC;QAEpE,IAAI,CAAC,KAAK,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC,CAAC;IAClE,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,MAAc,EAAE,KAAuB;QAC3C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;YACtB,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,EAAE,0BAA0B,CAAC,CAAC;YACrD,IAAI,CAAC;gBACD,MAAM,KAAK,EAAE,CAAC;YAClB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,wEAAwE;gBACxE,oEAAoE;gBACpE,kEAAkE;gBAClE,gFAAgF;gBAChF,6EAA6E;gBAC7E,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,wBAAwB,CAAC,CAAC;YAC9D,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,0BAA0B,CAAC,CAAC;IAC7G,CAAC;IAED,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IAC9B,CAAC;IAED,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,MAAM;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC;CACJ"}
@@ -1,2 +0,0 @@
1
- export { UsagePlugin } from "./usage-plugin.js";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
@@ -1,2 +0,0 @@
1
- export { UsagePlugin } from "./usage-plugin.js";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
@@ -1,65 +0,0 @@
1
- import { z } from "zod";
2
- import type { IHookRegistry } from "@adhd/agent-mcp-types";
3
- declare const pluginEntrySchema: z.ZodObject<{
4
- module: z.ZodString;
5
- config: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
6
- }, z.core.$strip>;
7
- /** JSON schema for the agent-mcp.config.json file itself. */
8
- export declare const agentMcpConfigFileSchema: z.ZodObject<{
9
- plugins: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
10
- module: z.ZodString;
11
- config: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
12
- }, z.core.$strip>>>>;
13
- }, z.core.$strip>;
14
- export type AgentMcpConfigFile = z.infer<typeof agentMcpConfigFileSchema>;
15
- export type PluginEntry = z.infer<typeof pluginEntrySchema>;
16
- /**
17
- * Returns the path to the active agent-mcp config file, or `null` if none is
18
- * found. Search order:
19
- * 1. `configPathOverride` (when provided directly — used by tests)
20
- * or `ADHD_AGENT_CONFIG` singleton value — absolute path to any JSON file
21
- * 2. `{cwd}/agent-mcp.config.json` — project-local (next to package.json)
22
- * 3. `{HOME}/.agent-mcp/config.json` — global user config
23
- *
24
- * @param configPathOverride — explicit path that takes priority over the
25
- * singleton value; pass `null` to force "no explicit path" (skip the env
26
- * lookup) without passing an actual file path.
27
- */
28
- export declare function findConfigFile(configPathOverride?: string | null): string | null;
29
- /**
30
- * Reads, parses, and validates the agent-mcp config file. Returns
31
- * `{ plugins: [] }` on any failure so the caller can always destructure safely.
32
- *
33
- * @param configPathOverride — forwarded to `findConfigFile`; used in tests.
34
- */
35
- export declare function loadConfigFile(configPathOverride?: string | null): AgentMcpConfigFile;
36
- /**
37
- * Resolves a module specifier to a `file://` URL string for `import()`.
38
- *
39
- * - Absolute/relative paths → converted via `pathToFileURL`.
40
- * - Package names → resolved via `createRequire` from `process.cwd()` first
41
- * (project-local `node_modules`, works for `npx` users), then from the server
42
- * binary's directory (monorepo / global installs). Throws if unresolvable.
43
- */
44
- export declare function resolveSpecifier(specifier: string): Promise<string>;
45
- /**
46
- * Discovers and installs all external plugins. Never throws.
47
- *
48
- * Processing order:
49
- * 1. Plugins from the agent-mcp config file (with optional validated `config` blocks).
50
- * 2. Specifiers from `ADHD_AGENT_PLUGINS` (comma-separated, no per-plugin options).
51
- *
52
- * All failures (bad config file, unresolvable module, failed schema validation,
53
- * factory errors) are logged at `error` level and skipped — a broken plugin
54
- * never prevents the server from starting.
55
- *
56
- * @param overrides — explicit values for testability; production code omits this.
57
- * `configPath` — forwarded to `findConfigFile`
58
- * `pluginEntries` — explicit module list (replaces `config.plugins.entries`)
59
- */
60
- export declare function loadExternalPlugins(hooks: IHookRegistry, db: unknown, overrides?: {
61
- configPath?: string | null;
62
- pluginEntries?: string[];
63
- }): Promise<void>;
64
- export {};
65
- //# sourceMappingURL=loader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/plugins/loader.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,aAAa,EAAwC,MAAM,uBAAuB,CAAC;AAIjG,QAAA,MAAM,iBAAiB;;;iBAKrB,CAAC;AAEH,6DAA6D;AAC7D,eAAO,MAAM,wBAAwB;;;;;iBAEnC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC1E,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AA0B5D;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAsBhF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,kBAAkB,CA6BrF;AAID;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA2BzE;AA6ED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,mBAAmB,CACrC,KAAK,EAAE,aAAa,EACpB,EAAE,EAAE,OAAO,EACX,SAAS,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GACrE,OAAO,CAAC,IAAI,CAAC,CAYf"}