@adhd/agent-mcp 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhd/agent-mcp",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Stateful MCP-native agent runtime with provider abstraction and recursive delegation",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,9 +1,24 @@
1
+ import type { HookEvent, HookEventMap, HookHandler, IHookRegistry, EnforcementEvent, EnforcementHandler } from "@adhd/agent-mcp-types";
1
2
  /**
2
- * Re-exports HookRegistry from @adhd/agent-mcp-types so the server can
3
- * import it via the local path "./engine/hooks.js" without the implementation
4
- * living in this package. This keeps @adhd/agent-mcp-budget's test suite able
5
- * to instantiate HookRegistry from @adhd/agent-mcp-types without creating a
6
- * circular Nx dependency with @adhd/agent-mcp.
3
+ * Concrete implementation of IHookRegistry used by the agent-mcp server.
4
+ *
5
+ * NOTE: A copy of this class also lives in @adhd/agent-mcp-types so plugin
6
+ * authors can instantiate it in their own tests without taking a runtime
7
+ * dependency on the full server package. Keep the two in sync until DEBT-009
8
+ * is resolved (extraction to @adhd/agent-mcp-hooks).
9
+ *
10
+ * Observational handlers registered via register() have their throws swallowed
11
+ * and logged — a buggy plugin never kills a task.
12
+ *
13
+ * Enforcement handlers registered via registerEnforcement() propagate throws
14
+ * so the orchestrator can fail the task with BUDGET_EXCEEDED.
7
15
  */
8
- export { HookRegistry } from "@adhd/agent-mcp-types";
16
+ export declare class HookRegistry implements IHookRegistry {
17
+ private readonly handlers;
18
+ private readonly enforcementHandlers;
19
+ register<E extends HookEvent>(event: E, handler: HookHandler<E>): void;
20
+ emit<E extends HookEvent>(event: E, payload: HookEventMap[E]): Promise<void>;
21
+ registerEnforcement<E extends EnforcementEvent>(event: E, handler: EnforcementHandler<E>): void;
22
+ enforce<E extends EnforcementEvent>(event: E, payload: HookEventMap[E]): Promise<void>;
23
+ }
9
24
  //# sourceMappingURL=hooks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,SAAS,EACT,YAAY,EACZ,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EACrB,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAa,YAAW,aAAa;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6D;IACtF,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAuE;IAE3G,QAAQ,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI;IAMhE,IAAI,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAYlF,mBAAmB,CAAC,CAAC,SAAS,gBAAgB,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAAI;IAMzF,OAAO,CAAC,CAAC,SAAS,gBAAgB,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAO/F"}
@@ -1,9 +1,50 @@
1
1
  /**
2
- * Re-exports HookRegistry from @adhd/agent-mcp-types so the server can
3
- * import it via the local path "./engine/hooks.js" without the implementation
4
- * living in this package. This keeps @adhd/agent-mcp-budget's test suite able
5
- * to instantiate HookRegistry from @adhd/agent-mcp-types without creating a
6
- * circular Nx dependency with @adhd/agent-mcp.
2
+ * Concrete implementation of IHookRegistry used by the agent-mcp server.
3
+ *
4
+ * NOTE: A copy of this class also lives in @adhd/agent-mcp-types so plugin
5
+ * authors can instantiate it in their own tests without taking a runtime
6
+ * dependency on the full server package. Keep the two in sync until DEBT-009
7
+ * is resolved (extraction to @adhd/agent-mcp-hooks).
8
+ *
9
+ * Observational handlers registered via register() have their throws swallowed
10
+ * and logged — a buggy plugin never kills a task.
11
+ *
12
+ * Enforcement handlers registered via registerEnforcement() propagate throws
13
+ * so the orchestrator can fail the task with BUDGET_EXCEEDED.
7
14
  */
8
- export { HookRegistry } from "@adhd/agent-mcp-types";
15
+ export class HookRegistry {
16
+ handlers = new Map();
17
+ enforcementHandlers = new Map();
18
+ register(event, handler) {
19
+ const list = this.handlers.get(event) ?? [];
20
+ list.push(handler);
21
+ this.handlers.set(event, list);
22
+ }
23
+ async emit(event, payload) {
24
+ const list = this.handlers.get(event);
25
+ if (!list?.length)
26
+ return;
27
+ for (const handler of list) {
28
+ try {
29
+ await handler(payload);
30
+ }
31
+ catch (err) {
32
+ console.warn("[HookRegistry] hook handler error (swallowed)", { event, err });
33
+ }
34
+ }
35
+ }
36
+ registerEnforcement(event, handler) {
37
+ const list = this.enforcementHandlers.get(event) ?? [];
38
+ list.push(handler);
39
+ this.enforcementHandlers.set(event, list);
40
+ }
41
+ async enforce(event, payload) {
42
+ const list = this.enforcementHandlers.get(event);
43
+ if (!list?.length)
44
+ return;
45
+ for (const handler of list) {
46
+ await handler(payload);
47
+ }
48
+ }
49
+ }
9
50
  //# sourceMappingURL=hooks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,u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