@agentmemory/agentmemory 0.7.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 (259) hide show
  1. package/.claude-plugin/marketplace.json +14 -0
  2. package/.github/workflows/ci.yml +22 -0
  3. package/.github/workflows/publish.yml +28 -0
  4. package/AGENTS.md +113 -0
  5. package/LICENSE +190 -0
  6. package/README.md +828 -0
  7. package/assets/banner.png +0 -0
  8. package/assets/demo.gif +0 -0
  9. package/assets/demo.mp4 +0 -0
  10. package/benchmark/QUALITY.md +73 -0
  11. package/benchmark/REAL-EMBEDDINGS.md +67 -0
  12. package/benchmark/SCALE.md +110 -0
  13. package/benchmark/dataset.ts +293 -0
  14. package/benchmark/quality-eval.ts +643 -0
  15. package/benchmark/real-embeddings-eval.ts +405 -0
  16. package/benchmark/scale-eval.ts +398 -0
  17. package/dist/cli.d.mts +1 -0
  18. package/dist/cli.mjs +137 -0
  19. package/dist/cli.mjs.map +1 -0
  20. package/dist/docker-compose.yml +14 -0
  21. package/dist/hooks/notification.d.mts +1 -0
  22. package/dist/hooks/notification.mjs +45 -0
  23. package/dist/hooks/notification.mjs.map +1 -0
  24. package/dist/hooks/post-tool-failure.d.mts +1 -0
  25. package/dist/hooks/post-tool-failure.mjs +45 -0
  26. package/dist/hooks/post-tool-failure.mjs.map +1 -0
  27. package/dist/hooks/post-tool-use.d.mts +1 -0
  28. package/dist/hooks/post-tool-use.mjs +53 -0
  29. package/dist/hooks/post-tool-use.mjs.map +1 -0
  30. package/dist/hooks/pre-compact.d.mts +1 -0
  31. package/dist/hooks/pre-compact.mjs +50 -0
  32. package/dist/hooks/pre-compact.mjs.map +1 -0
  33. package/dist/hooks/pre-tool-use.d.mts +1 -0
  34. package/dist/hooks/pre-tool-use.mjs +69 -0
  35. package/dist/hooks/pre-tool-use.mjs.map +1 -0
  36. package/dist/hooks/prompt-submit.d.mts +1 -0
  37. package/dist/hooks/prompt-submit.mjs +40 -0
  38. package/dist/hooks/prompt-submit.mjs.map +1 -0
  39. package/dist/hooks/session-end.d.mts +1 -0
  40. package/dist/hooks/session-end.mjs +61 -0
  41. package/dist/hooks/session-end.mjs.map +1 -0
  42. package/dist/hooks/session-start.d.mts +1 -0
  43. package/dist/hooks/session-start.mjs +42 -0
  44. package/dist/hooks/session-start.mjs.map +1 -0
  45. package/dist/hooks/stop.d.mts +1 -0
  46. package/dist/hooks/stop.mjs +33 -0
  47. package/dist/hooks/stop.mjs.map +1 -0
  48. package/dist/hooks/subagent-start.d.mts +1 -0
  49. package/dist/hooks/subagent-start.mjs +43 -0
  50. package/dist/hooks/subagent-start.mjs.map +1 -0
  51. package/dist/hooks/subagent-stop.d.mts +1 -0
  52. package/dist/hooks/subagent-stop.mjs +45 -0
  53. package/dist/hooks/subagent-stop.mjs.map +1 -0
  54. package/dist/hooks/task-completed.d.mts +1 -0
  55. package/dist/hooks/task-completed.mjs +46 -0
  56. package/dist/hooks/task-completed.mjs.map +1 -0
  57. package/dist/iii-config.yaml +51 -0
  58. package/dist/index.d.mts +2 -0
  59. package/dist/index.mjs +13776 -0
  60. package/dist/index.mjs.map +1 -0
  61. package/dist/src-QxitMPfJ.mjs +13775 -0
  62. package/dist/src-QxitMPfJ.mjs.map +1 -0
  63. package/dist/standalone.d.mts +1 -0
  64. package/dist/standalone.mjs +1155 -0
  65. package/dist/standalone.mjs.map +1 -0
  66. package/dist/transformers-BX_tgxdO.mjs +38684 -0
  67. package/dist/transformers-BX_tgxdO.mjs.map +1 -0
  68. package/dist/transformers-KMm1i9no.mjs +38683 -0
  69. package/dist/transformers-KMm1i9no.mjs.map +1 -0
  70. package/docker-compose.yml +14 -0
  71. package/iii-config.yaml +51 -0
  72. package/package.json +59 -0
  73. package/plugin/.claude-plugin/plugin.json +10 -0
  74. package/plugin/hooks/hooks.json +77 -0
  75. package/plugin/scripts/diagnostics.mjs +551 -0
  76. package/plugin/scripts/notification.mjs +45 -0
  77. package/plugin/scripts/post-tool-failure.mjs +45 -0
  78. package/plugin/scripts/post-tool-use.mjs +53 -0
  79. package/plugin/scripts/pre-compact.mjs +50 -0
  80. package/plugin/scripts/pre-tool-use.mjs +69 -0
  81. package/plugin/scripts/prompt-submit.mjs +40 -0
  82. package/plugin/scripts/session-end.mjs +61 -0
  83. package/plugin/scripts/session-start.mjs +42 -0
  84. package/plugin/scripts/stop.mjs +33 -0
  85. package/plugin/scripts/subagent-start.mjs +43 -0
  86. package/plugin/scripts/subagent-stop.mjs +45 -0
  87. package/plugin/scripts/task-completed.mjs +46 -0
  88. package/plugin/skills/forget/SKILL.md +32 -0
  89. package/plugin/skills/recall/SKILL.md +18 -0
  90. package/plugin/skills/remember/SKILL.md +25 -0
  91. package/plugin/skills/session-history/SKILL.md +17 -0
  92. package/src/auth.ts +12 -0
  93. package/src/cli.ts +159 -0
  94. package/src/config.ts +221 -0
  95. package/src/eval/metrics-store.ts +65 -0
  96. package/src/eval/quality.ts +51 -0
  97. package/src/eval/schemas.ts +124 -0
  98. package/src/eval/self-correct.ts +28 -0
  99. package/src/eval/validator.ts +31 -0
  100. package/src/functions/actions.ts +288 -0
  101. package/src/functions/audit.ts +61 -0
  102. package/src/functions/auto-forget.ts +169 -0
  103. package/src/functions/branch-aware.ts +169 -0
  104. package/src/functions/cascade.ts +80 -0
  105. package/src/functions/checkpoints.ts +209 -0
  106. package/src/functions/claude-bridge.ts +161 -0
  107. package/src/functions/compress.ts +194 -0
  108. package/src/functions/consolidate.ts +212 -0
  109. package/src/functions/consolidation-pipeline.ts +258 -0
  110. package/src/functions/context.ts +169 -0
  111. package/src/functions/crystallize.ts +293 -0
  112. package/src/functions/dedup.ts +57 -0
  113. package/src/functions/diagnostics.ts +785 -0
  114. package/src/functions/enrich.ts +132 -0
  115. package/src/functions/evict.ts +163 -0
  116. package/src/functions/export-import.ts +508 -0
  117. package/src/functions/facets.ts +248 -0
  118. package/src/functions/file-index.ts +106 -0
  119. package/src/functions/flow-compress.ts +214 -0
  120. package/src/functions/frontier.ts +196 -0
  121. package/src/functions/governance.ts +131 -0
  122. package/src/functions/graph-retrieval.ts +277 -0
  123. package/src/functions/graph.ts +275 -0
  124. package/src/functions/leases.ts +216 -0
  125. package/src/functions/lessons.ts +253 -0
  126. package/src/functions/mesh.ts +434 -0
  127. package/src/functions/migrate.ts +165 -0
  128. package/src/functions/observe.ts +144 -0
  129. package/src/functions/obsidian-export.ts +310 -0
  130. package/src/functions/patterns.ts +138 -0
  131. package/src/functions/privacy.ts +39 -0
  132. package/src/functions/profile.ts +155 -0
  133. package/src/functions/query-expansion.ts +186 -0
  134. package/src/functions/relations.ts +237 -0
  135. package/src/functions/remember.ts +162 -0
  136. package/src/functions/retention.ts +235 -0
  137. package/src/functions/routines.ts +289 -0
  138. package/src/functions/search.ts +80 -0
  139. package/src/functions/sentinels.ts +417 -0
  140. package/src/functions/signals.ts +186 -0
  141. package/src/functions/sketches.ts +274 -0
  142. package/src/functions/sliding-window.ts +257 -0
  143. package/src/functions/smart-search.ts +115 -0
  144. package/src/functions/snapshot.ts +219 -0
  145. package/src/functions/summarize.ts +155 -0
  146. package/src/functions/team.ts +147 -0
  147. package/src/functions/temporal-graph.ts +476 -0
  148. package/src/functions/timeline.ts +138 -0
  149. package/src/functions/verify.ts +117 -0
  150. package/src/health/monitor.ts +110 -0
  151. package/src/health/thresholds.ts +73 -0
  152. package/src/hooks/notification.ts +52 -0
  153. package/src/hooks/post-tool-failure.ts +58 -0
  154. package/src/hooks/post-tool-use.ts +62 -0
  155. package/src/hooks/pre-compact.ts +60 -0
  156. package/src/hooks/pre-tool-use.ts +72 -0
  157. package/src/hooks/prompt-submit.ts +46 -0
  158. package/src/hooks/session-end.ts +71 -0
  159. package/src/hooks/session-start.ts +48 -0
  160. package/src/hooks/stop.ts +39 -0
  161. package/src/hooks/subagent-start.ts +49 -0
  162. package/src/hooks/subagent-stop.ts +54 -0
  163. package/src/hooks/task-completed.ts +54 -0
  164. package/src/index.ts +342 -0
  165. package/src/mcp/in-memory-kv.ts +61 -0
  166. package/src/mcp/server.ts +1455 -0
  167. package/src/mcp/standalone.ts +177 -0
  168. package/src/mcp/tools-registry.ts +769 -0
  169. package/src/mcp/transport.ts +91 -0
  170. package/src/prompts/compression.ts +67 -0
  171. package/src/prompts/consolidation.ts +48 -0
  172. package/src/prompts/graph-extraction.ts +35 -0
  173. package/src/prompts/summary.ts +38 -0
  174. package/src/prompts/xml.ts +26 -0
  175. package/src/providers/agent-sdk.ts +34 -0
  176. package/src/providers/anthropic.ts +35 -0
  177. package/src/providers/circuit-breaker.ts +82 -0
  178. package/src/providers/embedding/cohere.ts +46 -0
  179. package/src/providers/embedding/gemini.ts +54 -0
  180. package/src/providers/embedding/index.ts +39 -0
  181. package/src/providers/embedding/local.ts +52 -0
  182. package/src/providers/embedding/openai.ts +45 -0
  183. package/src/providers/embedding/openrouter.ts +51 -0
  184. package/src/providers/embedding/voyage.ts +46 -0
  185. package/src/providers/fallback-chain.ts +31 -0
  186. package/src/providers/index.ts +84 -0
  187. package/src/providers/openrouter.ts +71 -0
  188. package/src/providers/resilient.ts +37 -0
  189. package/src/state/hybrid-search.ts +295 -0
  190. package/src/state/index-persistence.ts +63 -0
  191. package/src/state/keyed-mutex.ts +18 -0
  192. package/src/state/kv.ts +33 -0
  193. package/src/state/schema.ts +71 -0
  194. package/src/state/search-index.ts +245 -0
  195. package/src/state/stemmer.ts +104 -0
  196. package/src/state/synonyms.ts +63 -0
  197. package/src/state/vector-index.ts +130 -0
  198. package/src/telemetry/setup.ts +116 -0
  199. package/src/triggers/api.ts +1904 -0
  200. package/src/triggers/events.ts +71 -0
  201. package/src/types.ts +769 -0
  202. package/src/version.ts +1 -0
  203. package/src/viewer/index.html +2497 -0
  204. package/src/viewer/server.ts +207 -0
  205. package/src/xenova.d.ts +3 -0
  206. package/test/actions.test.ts +490 -0
  207. package/test/audit.test.ts +108 -0
  208. package/test/auto-forget.test.ts +188 -0
  209. package/test/cascade.test.ts +277 -0
  210. package/test/checkpoints.test.ts +493 -0
  211. package/test/circuit-breaker.test.ts +107 -0
  212. package/test/claude-bridge.test.ts +178 -0
  213. package/test/confidence.test.ts +247 -0
  214. package/test/consistency.test.ts +61 -0
  215. package/test/consolidation-pipeline.test.ts +251 -0
  216. package/test/crystallize.test.ts +521 -0
  217. package/test/diagnostics.test.ts +638 -0
  218. package/test/embedding-provider.test.ts +49 -0
  219. package/test/enrich.test.ts +209 -0
  220. package/test/eval.test.ts +300 -0
  221. package/test/export-import.test.ts +251 -0
  222. package/test/facets.test.ts +448 -0
  223. package/test/fallback-chain.test.ts +93 -0
  224. package/test/frontier.test.ts +485 -0
  225. package/test/governance.test.ts +147 -0
  226. package/test/graph-retrieval.test.ts +186 -0
  227. package/test/graph.test.ts +160 -0
  228. package/test/helpers/mocks.ts +40 -0
  229. package/test/hybrid-search.test.ts +145 -0
  230. package/test/index-persistence.test.ts +124 -0
  231. package/test/integration.test.ts +265 -0
  232. package/test/leases.test.ts +399 -0
  233. package/test/mcp-prompts.test.ts +218 -0
  234. package/test/mcp-resources.test.ts +286 -0
  235. package/test/mcp-standalone.test.ts +113 -0
  236. package/test/mesh.test.ts +700 -0
  237. package/test/privacy.test.ts +87 -0
  238. package/test/profile.test.ts +161 -0
  239. package/test/query-expansion.test.ts +154 -0
  240. package/test/relations.test.ts +198 -0
  241. package/test/retention.test.ts +245 -0
  242. package/test/routines.test.ts +497 -0
  243. package/test/schema-fingerprint.test.ts +81 -0
  244. package/test/schema.test.ts +42 -0
  245. package/test/search-index.test.ts +128 -0
  246. package/test/sentinels.test.ts +626 -0
  247. package/test/signals.test.ts +410 -0
  248. package/test/sketches.test.ts +549 -0
  249. package/test/sliding-window.test.ts +199 -0
  250. package/test/smart-search.test.ts +169 -0
  251. package/test/snapshot.test.ts +165 -0
  252. package/test/team.test.ts +156 -0
  253. package/test/temporal-graph.test.ts +378 -0
  254. package/test/timeline.test.ts +148 -0
  255. package/test/vector-index.test.ts +79 -0
  256. package/test/verify.test.ts +209 -0
  257. package/test/xml.test.ts +65 -0
  258. package/tsconfig.json +22 -0
  259. package/tsdown.config.ts +62 -0
@@ -0,0 +1,209 @@
1
+ import { describe, it, expect, beforeEach, vi } from "vitest";
2
+
3
+ vi.mock("iii-sdk", () => ({
4
+ getContext: () => ({
5
+ logger: { info: vi.fn(), error: vi.fn(), warn: vi.fn() },
6
+ }),
7
+ }));
8
+
9
+ import { registerVerifyFunction } from "../src/functions/verify.js";
10
+ import type { Memory, CompressedObservation, Session } from "../src/types.js";
11
+ import { mockKV, mockSdk } from "./helpers/mocks.js";
12
+
13
+ describe("Verify Function", () => {
14
+ let sdk: ReturnType<typeof mockSdk>;
15
+ let kv: ReturnType<typeof mockKV>;
16
+
17
+ beforeEach(() => {
18
+ sdk = mockSdk();
19
+ kv = mockKV();
20
+ vi.clearAllMocks();
21
+ registerVerifyFunction(sdk as never, kv as never);
22
+ });
23
+
24
+ it("returns error when id is missing", async () => {
25
+ const result = (await sdk.trigger("mem::verify", {})) as {
26
+ success: boolean;
27
+ error: string;
28
+ };
29
+ expect(result.success).toBe(false);
30
+ expect(result.error).toBe("id is required");
31
+ });
32
+
33
+ it("returns not found for unknown id", async () => {
34
+ const result = (await sdk.trigger("mem::verify", {
35
+ id: "unknown_123",
36
+ })) as { success: boolean; error: string };
37
+ expect(result.success).toBe(false);
38
+ expect(result.error).toBe("not found");
39
+ });
40
+
41
+ it("verifies a memory with citation chain", async () => {
42
+ const session: Session = {
43
+ id: "ses_1",
44
+ project: "/test/project",
45
+ cwd: "/test",
46
+ startedAt: "2026-03-01T00:00:00Z",
47
+ status: "completed",
48
+ observationCount: 2,
49
+ };
50
+ await kv.set("mem:sessions", "ses_1", session);
51
+
52
+ const obs: CompressedObservation = {
53
+ id: "obs_1",
54
+ sessionId: "ses_1",
55
+ timestamp: "2026-03-01T00:01:00Z",
56
+ type: "decision",
57
+ title: "Chose React over Vue",
58
+ facts: ["React chosen for ecosystem"],
59
+ narrative: "Team decided on React",
60
+ concepts: ["react", "frontend"],
61
+ files: ["src/App.tsx"],
62
+ importance: 8,
63
+ confidence: 0.85,
64
+ };
65
+ await kv.set("mem:obs:ses_1", "obs_1", obs);
66
+
67
+ const memory: Memory = {
68
+ id: "mem_1",
69
+ createdAt: "2026-03-01T00:02:00Z",
70
+ updatedAt: "2026-03-01T00:02:00Z",
71
+ type: "architecture",
72
+ title: "Using React for frontend",
73
+ content: "The team uses React for the frontend framework",
74
+ concepts: ["react", "frontend"],
75
+ files: ["src/App.tsx"],
76
+ sessionIds: ["ses_1"],
77
+ strength: 8,
78
+ version: 1,
79
+ isLatest: true,
80
+ sourceObservationIds: ["obs_1"],
81
+ };
82
+ await kv.set("mem:memories", "mem_1", memory);
83
+
84
+ const result = (await sdk.trigger("mem::verify", { id: "mem_1" })) as {
85
+ success: boolean;
86
+ type: string;
87
+ citations: Array<{
88
+ observationId: string;
89
+ confidence: number;
90
+ sessionProject: string;
91
+ }>;
92
+ citationCount: number;
93
+ };
94
+
95
+ expect(result.success).toBe(true);
96
+ expect(result.type).toBe("memory");
97
+ expect(result.citationCount).toBe(1);
98
+ expect(result.citations[0].observationId).toBe("obs_1");
99
+ expect(result.citations[0].confidence).toBe(0.85);
100
+ expect(result.citations[0].sessionProject).toBe("/test/project");
101
+ });
102
+
103
+ it("verifies a memory with no source observations", async () => {
104
+ const memory: Memory = {
105
+ id: "mem_2",
106
+ createdAt: "2026-03-01T00:00:00Z",
107
+ updatedAt: "2026-03-01T00:00:00Z",
108
+ type: "fact",
109
+ title: "API uses REST",
110
+ content: "The API follows REST conventions",
111
+ concepts: ["api", "rest"],
112
+ files: [],
113
+ sessionIds: [],
114
+ strength: 5,
115
+ version: 1,
116
+ isLatest: true,
117
+ };
118
+ await kv.set("mem:memories", "mem_2", memory);
119
+
120
+ const result = (await sdk.trigger("mem::verify", { id: "mem_2" })) as {
121
+ success: boolean;
122
+ type: string;
123
+ citationCount: number;
124
+ citations: unknown[];
125
+ };
126
+
127
+ expect(result.success).toBe(true);
128
+ expect(result.type).toBe("memory");
129
+ expect(result.citationCount).toBe(0);
130
+ expect(result.citations).toEqual([]);
131
+ });
132
+
133
+ it("verifies an observation directly", async () => {
134
+ const session: Session = {
135
+ id: "ses_2",
136
+ project: "/my/project",
137
+ cwd: "/my",
138
+ startedAt: "2026-03-01T00:00:00Z",
139
+ status: "active",
140
+ observationCount: 1,
141
+ };
142
+ await kv.set("mem:sessions", "ses_2", session);
143
+
144
+ const obs: CompressedObservation = {
145
+ id: "obs_direct",
146
+ sessionId: "ses_2",
147
+ timestamp: "2026-03-01T00:01:00Z",
148
+ type: "file_write",
149
+ title: "Created index.ts",
150
+ facts: ["Created file"],
151
+ narrative: "Agent created the index file",
152
+ concepts: ["typescript"],
153
+ files: ["index.ts"],
154
+ importance: 6,
155
+ confidence: 0.72,
156
+ };
157
+ await kv.set("mem:obs:ses_2", "obs_direct", obs);
158
+
159
+ const result = (await sdk.trigger("mem::verify", {
160
+ id: "obs_direct",
161
+ })) as {
162
+ success: boolean;
163
+ type: string;
164
+ observation: { id: string; confidence: number };
165
+ session: { project: string };
166
+ };
167
+
168
+ expect(result.success).toBe(true);
169
+ expect(result.type).toBe("observation");
170
+ expect(result.observation.id).toBe("obs_direct");
171
+ expect(result.observation.confidence).toBe(0.72);
172
+ expect(result.session.project).toBe("/my/project");
173
+ });
174
+
175
+ it("returns memory info with supersede chain", async () => {
176
+ const memory: Memory = {
177
+ id: "mem_v2",
178
+ createdAt: "2026-03-02T00:00:00Z",
179
+ updatedAt: "2026-03-02T00:00:00Z",
180
+ type: "pattern",
181
+ title: "Updated pattern",
182
+ content: "Updated pattern content",
183
+ concepts: ["testing"],
184
+ files: [],
185
+ sessionIds: [],
186
+ strength: 9,
187
+ version: 2,
188
+ parentId: "mem_v1",
189
+ supersedes: ["mem_v1"],
190
+ isLatest: true,
191
+ };
192
+ await kv.set("mem:memories", "mem_v2", memory);
193
+
194
+ const result = (await sdk.trigger("mem::verify", { id: "mem_v2" })) as {
195
+ success: boolean;
196
+ memory: {
197
+ id: string;
198
+ version: number;
199
+ parentId: string;
200
+ supersedes: string[];
201
+ };
202
+ };
203
+
204
+ expect(result.success).toBe(true);
205
+ expect(result.memory.version).toBe(2);
206
+ expect(result.memory.parentId).toBe("mem_v1");
207
+ expect(result.memory.supersedes).toEqual(["mem_v1"]);
208
+ });
209
+ });
@@ -0,0 +1,65 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { getXmlTag, getXmlChildren } from '../src/prompts/xml.js'
3
+
4
+ describe('getXmlTag', () => {
5
+ it('extracts simple tag content', () => {
6
+ expect(getXmlTag('<title>Hello World</title>', 'title')).toBe('Hello World')
7
+ })
8
+
9
+ it('extracts multiline content', () => {
10
+ expect(getXmlTag('<narrative>\nLine 1\nLine 2\n</narrative>', 'narrative')).toBe('Line 1\nLine 2')
11
+ })
12
+
13
+ it('returns empty string for missing tag', () => {
14
+ expect(getXmlTag('<title>Hello</title>', 'missing')).toBe('')
15
+ })
16
+
17
+ it('returns first match for duplicate tags', () => {
18
+ expect(getXmlTag('<title>First</title><title>Second</title>', 'title')).toBe('First')
19
+ })
20
+
21
+ it('returns empty string for empty tag', () => {
22
+ expect(getXmlTag('<title></title>', 'title')).toBe('')
23
+ })
24
+
25
+ it('trims whitespace', () => {
26
+ expect(getXmlTag('<title> trimmed </title>', 'title')).toBe('trimmed')
27
+ })
28
+
29
+ it('returns empty for invalid tag names', () => {
30
+ expect(getXmlTag('<foo>bar</foo>', '.*')).toBe('')
31
+ })
32
+
33
+ it('returns empty for tag with special regex chars', () => {
34
+ expect(getXmlTag('<foo>bar</foo>', 'a(b')).toBe('')
35
+ })
36
+ })
37
+
38
+ describe('getXmlChildren', () => {
39
+ it('extracts child elements', () => {
40
+ const xml = '<facts><fact>One</fact><fact>Two</fact></facts>'
41
+ expect(getXmlChildren(xml, 'facts', 'fact')).toEqual(['One', 'Two'])
42
+ })
43
+
44
+ it('returns empty array for missing parent', () => {
45
+ expect(getXmlChildren('<foo>bar</foo>', 'facts', 'fact')).toEqual([])
46
+ })
47
+
48
+ it('returns empty array for missing children', () => {
49
+ expect(getXmlChildren('<facts></facts>', 'facts', 'fact')).toEqual([])
50
+ })
51
+
52
+ it('trims child content', () => {
53
+ const xml = '<facts><fact> trimmed </fact></facts>'
54
+ expect(getXmlChildren(xml, 'facts', 'fact')).toEqual(['trimmed'])
55
+ })
56
+
57
+ it('handles multiline children', () => {
58
+ const xml = '<decisions><decision>Use JWT\nfor auth</decision></decisions>'
59
+ expect(getXmlChildren(xml, 'decisions', 'decision')).toEqual(['Use JWT\nfor auth'])
60
+ })
61
+
62
+ it('returns empty for invalid parent tag name', () => {
63
+ expect(getXmlChildren('<facts><fact>A</fact></facts>', '.*', 'fact')).toEqual([])
64
+ })
65
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "sourceMap": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "strict": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "resolveJsonModule": true,
16
+ "isolatedModules": true,
17
+ "noUnusedLocals": true,
18
+ "noUnusedParameters": true
19
+ },
20
+ "include": ["src/**/*"],
21
+ "exclude": ["node_modules", "dist", "test", "src/hooks"]
22
+ }
@@ -0,0 +1,62 @@
1
+ import { defineConfig } from "tsdown";
2
+
3
+ const hookEntries = [
4
+ "src/hooks/session-start.ts",
5
+ "src/hooks/prompt-submit.ts",
6
+ "src/hooks/pre-tool-use.ts",
7
+ "src/hooks/post-tool-use.ts",
8
+ "src/hooks/post-tool-failure.ts",
9
+ "src/hooks/pre-compact.ts",
10
+ "src/hooks/subagent-start.ts",
11
+ "src/hooks/subagent-stop.ts",
12
+ "src/hooks/notification.ts",
13
+ "src/hooks/task-completed.ts",
14
+ "src/hooks/stop.ts",
15
+ "src/hooks/session-end.ts",
16
+ ];
17
+
18
+ const shared = {
19
+ format: ["esm"] as const,
20
+ target: "node20" as const,
21
+ inlineOnly: false as const,
22
+ };
23
+
24
+ export default defineConfig([
25
+ {
26
+ entry: ["src/index.ts"],
27
+ outDir: "dist",
28
+ ...shared,
29
+ dts: true,
30
+ clean: true,
31
+ sourcemap: true,
32
+ banner: { js: "#!/usr/bin/env node" },
33
+ },
34
+ {
35
+ entry: ["src/cli.ts"],
36
+ outDir: "dist",
37
+ ...shared,
38
+ clean: false,
39
+ sourcemap: false,
40
+ },
41
+ {
42
+ entry: ["src/mcp/standalone.ts"],
43
+ outDir: "dist",
44
+ ...shared,
45
+ clean: false,
46
+ sourcemap: false,
47
+ },
48
+ {
49
+ entry: hookEntries,
50
+ outDir: "dist/hooks",
51
+ ...shared,
52
+ clean: false,
53
+ sourcemap: false,
54
+ },
55
+ {
56
+ entry: hookEntries,
57
+ outDir: "plugin/scripts",
58
+ ...shared,
59
+ clean: false,
60
+ sourcemap: false,
61
+ },
62
+ ]);