agentx-sdk 0.1.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 (318) hide show
  1. package/README.md +561 -0
  2. package/dist/agent.d.ts +105 -0
  3. package/dist/agent.d.ts.map +1 -0
  4. package/dist/agent.js +690 -0
  5. package/dist/agent.js.map +1 -0
  6. package/dist/config/config.d.ts +346 -0
  7. package/dist/config/config.d.ts.map +1 -0
  8. package/dist/config/config.js +93 -0
  9. package/dist/config/config.js.map +1 -0
  10. package/dist/contracts/entities/agent-event.d.ts +97 -0
  11. package/dist/contracts/entities/agent-event.d.ts.map +1 -0
  12. package/dist/contracts/entities/agent-event.js +2 -0
  13. package/dist/contracts/entities/agent-event.js.map +1 -0
  14. package/dist/contracts/entities/agent-skill.d.ts +59 -0
  15. package/dist/contracts/entities/agent-skill.d.ts.map +1 -0
  16. package/dist/contracts/entities/agent-skill.js +2 -0
  17. package/dist/contracts/entities/agent-skill.js.map +1 -0
  18. package/dist/contracts/entities/agent-tool.d.ts +42 -0
  19. package/dist/contracts/entities/agent-tool.d.ts.map +1 -0
  20. package/dist/contracts/entities/agent-tool.js +2 -0
  21. package/dist/contracts/entities/agent-tool.js.map +1 -0
  22. package/dist/contracts/entities/chat-message.d.ts +13 -0
  23. package/dist/contracts/entities/chat-message.d.ts.map +1 -0
  24. package/dist/contracts/entities/chat-message.js +2 -0
  25. package/dist/contracts/entities/chat-message.js.map +1 -0
  26. package/dist/contracts/entities/content-part.d.ts +16 -0
  27. package/dist/contracts/entities/content-part.d.ts.map +1 -0
  28. package/dist/contracts/entities/content-part.js +2 -0
  29. package/dist/contracts/entities/content-part.js.map +1 -0
  30. package/dist/contracts/entities/execution-context.d.ts +9 -0
  31. package/dist/contracts/entities/execution-context.d.ts.map +1 -0
  32. package/dist/contracts/entities/execution-context.js +2 -0
  33. package/dist/contracts/entities/execution-context.js.map +1 -0
  34. package/dist/contracts/entities/index.d.ts +11 -0
  35. package/dist/contracts/entities/index.d.ts.map +1 -0
  36. package/dist/contracts/entities/index.js +2 -0
  37. package/dist/contracts/entities/index.js.map +1 -0
  38. package/dist/contracts/entities/knowledge.d.ts +21 -0
  39. package/dist/contracts/entities/knowledge.d.ts.map +1 -0
  40. package/dist/contracts/entities/knowledge.js +2 -0
  41. package/dist/contracts/entities/knowledge.js.map +1 -0
  42. package/dist/contracts/entities/stores.d.ts +18 -0
  43. package/dist/contracts/entities/stores.d.ts.map +1 -0
  44. package/dist/contracts/entities/stores.js +2 -0
  45. package/dist/contracts/entities/stores.js.map +1 -0
  46. package/dist/contracts/entities/token-usage.d.ts +7 -0
  47. package/dist/contracts/entities/token-usage.d.ts.map +1 -0
  48. package/dist/contracts/entities/token-usage.js +2 -0
  49. package/dist/contracts/entities/token-usage.js.map +1 -0
  50. package/dist/contracts/entities/tool-call.d.ts +16 -0
  51. package/dist/contracts/entities/tool-call.d.ts.map +1 -0
  52. package/dist/contracts/entities/tool-call.js +2 -0
  53. package/dist/contracts/entities/tool-call.js.map +1 -0
  54. package/dist/contracts/enums/index.d.ts +21 -0
  55. package/dist/contracts/enums/index.d.ts.map +1 -0
  56. package/dist/contracts/enums/index.js +8 -0
  57. package/dist/contracts/enums/index.js.map +1 -0
  58. package/dist/contracts/index.d.ts +3 -0
  59. package/dist/contracts/index.d.ts.map +1 -0
  60. package/dist/contracts/index.js +3 -0
  61. package/dist/contracts/index.js.map +1 -0
  62. package/dist/core/compaction/autocompact.d.ts +18 -0
  63. package/dist/core/compaction/autocompact.d.ts.map +1 -0
  64. package/dist/core/compaction/autocompact.js +68 -0
  65. package/dist/core/compaction/autocompact.js.map +1 -0
  66. package/dist/core/compaction/microcompact.d.ts +20 -0
  67. package/dist/core/compaction/microcompact.d.ts.map +1 -0
  68. package/dist/core/compaction/microcompact.js +38 -0
  69. package/dist/core/compaction/microcompact.js.map +1 -0
  70. package/dist/core/compaction/snip-compact.d.ts +22 -0
  71. package/dist/core/compaction/snip-compact.d.ts.map +1 -0
  72. package/dist/core/compaction/snip-compact.js +61 -0
  73. package/dist/core/compaction/snip-compact.js.map +1 -0
  74. package/dist/core/compaction/tool-result-budget.d.ts +24 -0
  75. package/dist/core/compaction/tool-result-budget.d.ts.map +1 -0
  76. package/dist/core/compaction/tool-result-budget.js +67 -0
  77. package/dist/core/compaction/tool-result-budget.js.map +1 -0
  78. package/dist/core/context-analysis.d.ts +24 -0
  79. package/dist/core/context-analysis.d.ts.map +1 -0
  80. package/dist/core/context-analysis.js +37 -0
  81. package/dist/core/context-analysis.js.map +1 -0
  82. package/dist/core/context-builder.d.ts +25 -0
  83. package/dist/core/context-builder.d.ts.map +1 -0
  84. package/dist/core/context-builder.js +108 -0
  85. package/dist/core/context-builder.js.map +1 -0
  86. package/dist/core/conversation-manager.d.ts +19 -0
  87. package/dist/core/conversation-manager.d.ts.map +1 -0
  88. package/dist/core/conversation-manager.js +62 -0
  89. package/dist/core/conversation-manager.js.map +1 -0
  90. package/dist/core/execution-context.d.ts +6 -0
  91. package/dist/core/execution-context.d.ts.map +1 -0
  92. package/dist/core/execution-context.js +14 -0
  93. package/dist/core/execution-context.js.map +1 -0
  94. package/dist/core/loop-deps.d.ts +15 -0
  95. package/dist/core/loop-deps.d.ts.map +1 -0
  96. package/dist/core/loop-deps.js +8 -0
  97. package/dist/core/loop-deps.js.map +1 -0
  98. package/dist/core/loop-types.d.ts +34 -0
  99. package/dist/core/loop-types.d.ts.map +1 -0
  100. package/dist/core/loop-types.js +15 -0
  101. package/dist/core/loop-types.js.map +1 -0
  102. package/dist/core/message-normalize.d.ts +18 -0
  103. package/dist/core/message-normalize.d.ts.map +1 -0
  104. package/dist/core/message-normalize.js +69 -0
  105. package/dist/core/message-normalize.js.map +1 -0
  106. package/dist/core/prompt-builders.d.ts +36 -0
  107. package/dist/core/prompt-builders.d.ts.map +1 -0
  108. package/dist/core/prompt-builders.js +89 -0
  109. package/dist/core/prompt-builders.js.map +1 -0
  110. package/dist/core/prompt-cache.d.ts +25 -0
  111. package/dist/core/prompt-cache.d.ts.map +1 -0
  112. package/dist/core/prompt-cache.js +34 -0
  113. package/dist/core/prompt-cache.js.map +1 -0
  114. package/dist/core/react-loop.d.ts +43 -0
  115. package/dist/core/react-loop.d.ts.map +1 -0
  116. package/dist/core/react-loop.js +403 -0
  117. package/dist/core/react-loop.js.map +1 -0
  118. package/dist/core/stop-hooks.d.ts +18 -0
  119. package/dist/core/stop-hooks.d.ts.map +1 -0
  120. package/dist/core/stop-hooks.js +18 -0
  121. package/dist/core/stop-hooks.js.map +1 -0
  122. package/dist/core/stream-emitter.d.ts +24 -0
  123. package/dist/core/stream-emitter.d.ts.map +1 -0
  124. package/dist/core/stream-emitter.js +65 -0
  125. package/dist/core/stream-emitter.js.map +1 -0
  126. package/dist/core/streaming-tool-executor.d.ts +54 -0
  127. package/dist/core/streaming-tool-executor.d.ts.map +1 -0
  128. package/dist/core/streaming-tool-executor.js +164 -0
  129. package/dist/core/streaming-tool-executor.js.map +1 -0
  130. package/dist/core/turn-end-hooks.d.ts +39 -0
  131. package/dist/core/turn-end-hooks.d.ts.map +1 -0
  132. package/dist/core/turn-end-hooks.js +36 -0
  133. package/dist/core/turn-end-hooks.js.map +1 -0
  134. package/dist/index.d.ts +39 -0
  135. package/dist/index.d.ts.map +1 -0
  136. package/dist/index.js +45 -0
  137. package/dist/index.js.map +1 -0
  138. package/dist/knowledge/chunking.d.ts +9 -0
  139. package/dist/knowledge/chunking.d.ts.map +1 -0
  140. package/dist/knowledge/chunking.js +49 -0
  141. package/dist/knowledge/chunking.js.map +1 -0
  142. package/dist/knowledge/embedding-service.d.ts +16 -0
  143. package/dist/knowledge/embedding-service.d.ts.map +1 -0
  144. package/dist/knowledge/embedding-service.js +43 -0
  145. package/dist/knowledge/embedding-service.js.map +1 -0
  146. package/dist/knowledge/knowledge-manager.d.ts +33 -0
  147. package/dist/knowledge/knowledge-manager.d.ts.map +1 -0
  148. package/dist/knowledge/knowledge-manager.js +62 -0
  149. package/dist/knowledge/knowledge-manager.js.map +1 -0
  150. package/dist/knowledge/sqlite-vector-store.d.ts +16 -0
  151. package/dist/knowledge/sqlite-vector-store.d.ts.map +1 -0
  152. package/dist/knowledge/sqlite-vector-store.js +56 -0
  153. package/dist/knowledge/sqlite-vector-store.js.map +1 -0
  154. package/dist/knowledge/vector-store.d.ts +2 -0
  155. package/dist/knowledge/vector-store.d.ts.map +1 -0
  156. package/dist/knowledge/vector-store.js +2 -0
  157. package/dist/knowledge/vector-store.js.map +1 -0
  158. package/dist/llm/errors.d.ts +15 -0
  159. package/dist/llm/errors.d.ts.map +1 -0
  160. package/dist/llm/errors.js +39 -0
  161. package/dist/llm/errors.js.map +1 -0
  162. package/dist/llm/message-types.d.ts +80 -0
  163. package/dist/llm/message-types.d.ts.map +1 -0
  164. package/dist/llm/message-types.js +2 -0
  165. package/dist/llm/message-types.js.map +1 -0
  166. package/dist/llm/openrouter-client.d.ts +18 -0
  167. package/dist/llm/openrouter-client.d.ts.map +1 -0
  168. package/dist/llm/openrouter-client.js +215 -0
  169. package/dist/llm/openrouter-client.js.map +1 -0
  170. package/dist/llm/reasoning.d.ts +10 -0
  171. package/dist/llm/reasoning.d.ts.map +1 -0
  172. package/dist/llm/reasoning.js +18 -0
  173. package/dist/llm/reasoning.js.map +1 -0
  174. package/dist/memory/file-memory-system.d.ts +98 -0
  175. package/dist/memory/file-memory-system.d.ts.map +1 -0
  176. package/dist/memory/file-memory-system.js +310 -0
  177. package/dist/memory/file-memory-system.js.map +1 -0
  178. package/dist/memory/memory-age.d.ts +22 -0
  179. package/dist/memory/memory-age.d.ts.map +1 -0
  180. package/dist/memory/memory-age.js +44 -0
  181. package/dist/memory/memory-age.js.map +1 -0
  182. package/dist/memory/memory-extractor.d.ts +56 -0
  183. package/dist/memory/memory-extractor.d.ts.map +1 -0
  184. package/dist/memory/memory-extractor.js +91 -0
  185. package/dist/memory/memory-extractor.js.map +1 -0
  186. package/dist/memory/memory-paths.d.ts +45 -0
  187. package/dist/memory/memory-paths.d.ts.map +1 -0
  188. package/dist/memory/memory-paths.js +121 -0
  189. package/dist/memory/memory-paths.js.map +1 -0
  190. package/dist/memory/memory-prompts.d.ts +41 -0
  191. package/dist/memory/memory-prompts.d.ts.map +1 -0
  192. package/dist/memory/memory-prompts.js +279 -0
  193. package/dist/memory/memory-prompts.js.map +1 -0
  194. package/dist/memory/memory-relevance.d.ts +16 -0
  195. package/dist/memory/memory-relevance.d.ts.map +1 -0
  196. package/dist/memory/memory-relevance.js +46 -0
  197. package/dist/memory/memory-relevance.js.map +1 -0
  198. package/dist/memory/memory-scanner.d.ts +22 -0
  199. package/dist/memory/memory-scanner.d.ts.map +1 -0
  200. package/dist/memory/memory-scanner.js +99 -0
  201. package/dist/memory/memory-scanner.js.map +1 -0
  202. package/dist/memory/memory-tools.d.ts +16 -0
  203. package/dist/memory/memory-tools.d.ts.map +1 -0
  204. package/dist/memory/memory-tools.js +196 -0
  205. package/dist/memory/memory-tools.js.map +1 -0
  206. package/dist/memory/memory-types.d.ts +47 -0
  207. package/dist/memory/memory-types.d.ts.map +1 -0
  208. package/dist/memory/memory-types.js +24 -0
  209. package/dist/memory/memory-types.js.map +1 -0
  210. package/dist/skills/skill-args.d.ts +23 -0
  211. package/dist/skills/skill-args.d.ts.map +1 -0
  212. package/dist/skills/skill-args.js +77 -0
  213. package/dist/skills/skill-args.js.map +1 -0
  214. package/dist/skills/skill-glob.d.ts +24 -0
  215. package/dist/skills/skill-glob.d.ts.map +1 -0
  216. package/dist/skills/skill-glob.js +60 -0
  217. package/dist/skills/skill-glob.js.map +1 -0
  218. package/dist/skills/skill-loader.d.ts +49 -0
  219. package/dist/skills/skill-loader.d.ts.map +1 -0
  220. package/dist/skills/skill-loader.js +197 -0
  221. package/dist/skills/skill-loader.js.map +1 -0
  222. package/dist/skills/skill-manager.d.ts +83 -0
  223. package/dist/skills/skill-manager.d.ts.map +1 -0
  224. package/dist/skills/skill-manager.js +338 -0
  225. package/dist/skills/skill-manager.js.map +1 -0
  226. package/dist/storage/sqlite-conversation-store.d.ts +15 -0
  227. package/dist/storage/sqlite-conversation-store.d.ts.map +1 -0
  228. package/dist/storage/sqlite-conversation-store.js +45 -0
  229. package/dist/storage/sqlite-conversation-store.js.map +1 -0
  230. package/dist/storage/sqlite-database.d.ts +14 -0
  231. package/dist/storage/sqlite-database.d.ts.map +1 -0
  232. package/dist/storage/sqlite-database.js +95 -0
  233. package/dist/storage/sqlite-database.js.map +1 -0
  234. package/dist/tools/builtin/ask-user.d.ts +7 -0
  235. package/dist/tools/builtin/ask-user.d.ts.map +1 -0
  236. package/dist/tools/builtin/ask-user.js +23 -0
  237. package/dist/tools/builtin/ask-user.js.map +1 -0
  238. package/dist/tools/builtin/bash.d.ts +3 -0
  239. package/dist/tools/builtin/bash.d.ts.map +1 -0
  240. package/dist/tools/builtin/bash.js +54 -0
  241. package/dist/tools/builtin/bash.js.map +1 -0
  242. package/dist/tools/builtin/file-edit.d.ts +3 -0
  243. package/dist/tools/builtin/file-edit.d.ts.map +1 -0
  244. package/dist/tools/builtin/file-edit.js +50 -0
  245. package/dist/tools/builtin/file-edit.js.map +1 -0
  246. package/dist/tools/builtin/file-read.d.ts +3 -0
  247. package/dist/tools/builtin/file-read.d.ts.map +1 -0
  248. package/dist/tools/builtin/file-read.js +47 -0
  249. package/dist/tools/builtin/file-read.js.map +1 -0
  250. package/dist/tools/builtin/file-write.d.ts +3 -0
  251. package/dist/tools/builtin/file-write.d.ts.map +1 -0
  252. package/dist/tools/builtin/file-write.js +29 -0
  253. package/dist/tools/builtin/file-write.js.map +1 -0
  254. package/dist/tools/builtin/glob.d.ts +3 -0
  255. package/dist/tools/builtin/glob.d.ts.map +1 -0
  256. package/dist/tools/builtin/glob.js +67 -0
  257. package/dist/tools/builtin/glob.js.map +1 -0
  258. package/dist/tools/builtin/grep.d.ts +3 -0
  259. package/dist/tools/builtin/grep.d.ts.map +1 -0
  260. package/dist/tools/builtin/grep.js +94 -0
  261. package/dist/tools/builtin/grep.js.map +1 -0
  262. package/dist/tools/builtin/index.d.ts +49 -0
  263. package/dist/tools/builtin/index.d.ts.map +1 -0
  264. package/dist/tools/builtin/index.js +65 -0
  265. package/dist/tools/builtin/index.js.map +1 -0
  266. package/dist/tools/builtin/web-fetch.d.ts +3 -0
  267. package/dist/tools/builtin/web-fetch.d.ts.map +1 -0
  268. package/dist/tools/builtin/web-fetch.js +56 -0
  269. package/dist/tools/builtin/web-fetch.js.map +1 -0
  270. package/dist/tools/json-schema-to-zod.d.ts +30 -0
  271. package/dist/tools/json-schema-to-zod.d.ts.map +1 -0
  272. package/dist/tools/json-schema-to-zod.js +123 -0
  273. package/dist/tools/json-schema-to-zod.js.map +1 -0
  274. package/dist/tools/mcp-adapter.d.ts +80 -0
  275. package/dist/tools/mcp-adapter.d.ts.map +1 -0
  276. package/dist/tools/mcp-adapter.js +326 -0
  277. package/dist/tools/mcp-adapter.js.map +1 -0
  278. package/dist/tools/skill-tool.d.ts +41 -0
  279. package/dist/tools/skill-tool.d.ts.map +1 -0
  280. package/dist/tools/skill-tool.js +149 -0
  281. package/dist/tools/skill-tool.js.map +1 -0
  282. package/dist/tools/sql/index.d.ts +4 -0
  283. package/dist/tools/sql/index.d.ts.map +1 -0
  284. package/dist/tools/sql/index.js +2 -0
  285. package/dist/tools/sql/index.js.map +1 -0
  286. package/dist/tools/sql/sql-query-def.d.ts +22 -0
  287. package/dist/tools/sql/sql-query-def.d.ts.map +1 -0
  288. package/dist/tools/sql/sql-query-def.js +2 -0
  289. package/dist/tools/sql/sql-query-def.js.map +1 -0
  290. package/dist/tools/sql/sql-tool-factory.d.ts +28 -0
  291. package/dist/tools/sql/sql-tool-factory.d.ts.map +1 -0
  292. package/dist/tools/sql/sql-tool-factory.js +136 -0
  293. package/dist/tools/sql/sql-tool-factory.js.map +1 -0
  294. package/dist/tools/tool-executor.d.ts +67 -0
  295. package/dist/tools/tool-executor.d.ts.map +1 -0
  296. package/dist/tools/tool-executor.js +232 -0
  297. package/dist/tools/tool-executor.js.map +1 -0
  298. package/dist/utils/cache.d.ts +22 -0
  299. package/dist/utils/cache.d.ts.map +1 -0
  300. package/dist/utils/cache.js +61 -0
  301. package/dist/utils/cache.js.map +1 -0
  302. package/dist/utils/logger.d.ts +15 -0
  303. package/dist/utils/logger.d.ts.map +1 -0
  304. package/dist/utils/logger.js +46 -0
  305. package/dist/utils/logger.js.map +1 -0
  306. package/dist/utils/model-context.d.ts +14 -0
  307. package/dist/utils/model-context.d.ts.map +1 -0
  308. package/dist/utils/model-context.js +52 -0
  309. package/dist/utils/model-context.js.map +1 -0
  310. package/dist/utils/retry.d.ts +13 -0
  311. package/dist/utils/retry.d.ts.map +1 -0
  312. package/dist/utils/retry.js +41 -0
  313. package/dist/utils/retry.js.map +1 -0
  314. package/dist/utils/token-counter.d.ts +6 -0
  315. package/dist/utils/token-counter.d.ts.map +1 -0
  316. package/dist/utils/token-counter.js +19 -0
  317. package/dist/utils/token-counter.js.map +1 -0
  318. package/package.json +43 -0
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Memory directory path resolution and security validation.
3
+ *
4
+ * Security model ported from old_src/memdir/paths.ts:
5
+ * - Rejects relative paths, root/near-root, Windows drive roots, UNC paths, null bytes
6
+ * - Tilde expansion only from config (~/), not from bare ~ or ~/. or ~/..
7
+ * - All paths normalized to NFC to prevent Unicode normalization attacks
8
+ */
9
+ import { homedir } from 'node:os';
10
+ import { isAbsolute, join, normalize, sep } from 'node:path';
11
+ import { mkdir } from 'node:fs/promises';
12
+ const DEFAULT_MEMORY_DIR = '~/.agent/memory/';
13
+ /**
14
+ * Resolve the memory directory from config, env var, or default.
15
+ * Priority: config.memoryDir → AGENT_MEMORY_DIR env → ~/.agent/memory/
16
+ *
17
+ * Config paths support ~/ expansion (user-friendly).
18
+ * Env var paths must be absolute (set programmatically).
19
+ */
20
+ export function resolveMemoryDir(memoryDir) {
21
+ // Env var: no tilde expansion (must be absolute)
22
+ if (!memoryDir && process.env.AGENT_MEMORY_DIR) {
23
+ const envPath = process.env.AGENT_MEMORY_DIR;
24
+ const normalized = normalize(envPath).replace(/[/\\]+$/, '');
25
+ if (isAbsolute(normalized) && normalized.length >= 3) {
26
+ return (normalized + sep).normalize('NFC');
27
+ }
28
+ }
29
+ const raw = memoryDir ?? DEFAULT_MEMORY_DIR;
30
+ return expandAndNormalize(raw);
31
+ }
32
+ /**
33
+ * Expand ~ and normalize a path. Returns absolute path with trailing separator.
34
+ * Only expands ~/ and ~\ (not bare ~, ~/., ~/..)
35
+ */
36
+ function expandAndNormalize(raw) {
37
+ let candidate = raw;
38
+ if (candidate.startsWith('~/') || candidate.startsWith('~\\')) {
39
+ const rest = candidate.slice(2);
40
+ // Reject trivial remainders that would expand to $HOME or an ancestor
41
+ const restNorm = normalize(rest || '.');
42
+ if (restNorm === '.' || restNorm === '..') {
43
+ // Fall through to default — don't expand dangerous paths
44
+ candidate = join(homedir(), '.agent', 'memory');
45
+ }
46
+ else {
47
+ candidate = join(homedir(), rest);
48
+ }
49
+ }
50
+ const normalized = normalize(candidate).replace(/[/\\]+$/, '');
51
+ return (normalized + sep).normalize('NFC');
52
+ }
53
+ /**
54
+ * Validate that a path is safely within the memory directory.
55
+ *
56
+ * SECURITY: Rejects paths that would be dangerous:
57
+ * - Empty or contains null bytes (truncation in syscalls)
58
+ * - Relative paths (!isAbsolute)
59
+ * - Root/near-root (length < 3)
60
+ * - Windows drive-root (C:)
61
+ * - UNC paths (\\server\share or //server/share)
62
+ * - URL-encoded traversal (%2e%2e)
63
+ * - Outside memory directory after normalization
64
+ *
65
+ * Returns the normalized path if valid, undefined if rejected.
66
+ */
67
+ export function validateMemoryPath(path, memoryDir) {
68
+ if (!path || path.includes('\0'))
69
+ return undefined;
70
+ // Reject URL-encoded path traversal
71
+ if (path.includes('%2e') || path.includes('%2E') || path.includes('%2f') || path.includes('%2F')) {
72
+ return undefined;
73
+ }
74
+ const normalized = normalize(path).normalize('NFC');
75
+ if (!isAbsolute(normalized))
76
+ return undefined;
77
+ if (normalized.length < 3)
78
+ return undefined;
79
+ // Reject Windows drive roots and UNC paths
80
+ if (/^[A-Za-z]:$/.test(normalized))
81
+ return undefined;
82
+ if (normalized.startsWith('\\\\') || normalized.startsWith('//'))
83
+ return undefined;
84
+ // Must be within memory directory (containment check)
85
+ const normalizedDir = normalize(memoryDir).replace(/[/\\]+$/, '').normalize('NFC') + sep;
86
+ if (!normalized.startsWith(normalizedDir))
87
+ return undefined;
88
+ return normalized;
89
+ }
90
+ /**
91
+ * Sanitize a name into a safe kebab-case filename with .md extension.
92
+ */
93
+ export function sanitizeFilename(name) {
94
+ const sanitized = name
95
+ .normalize('NFC')
96
+ .toLowerCase()
97
+ .replace(/[^a-z0-9\s-]/g, '')
98
+ .replace(/\s+/g, '-')
99
+ .replace(/-+/g, '-')
100
+ .replace(/^-|-$/g, '')
101
+ .slice(0, 80);
102
+ if (!sanitized)
103
+ return 'memory.md';
104
+ return sanitized.endsWith('.md') ? sanitized : `${sanitized}.md`;
105
+ }
106
+ /**
107
+ * Idempotent memory directory creation.
108
+ */
109
+ export async function ensureMemoryDir(memoryDir) {
110
+ await mkdir(memoryDir, { recursive: true });
111
+ }
112
+ /**
113
+ * Check if an absolute path is within the memory directory.
114
+ * Uses NFC normalization to prevent Unicode-based path traversal.
115
+ */
116
+ export function isMemoryPath(absolutePath, memoryDir) {
117
+ const normalizedPath = normalize(absolutePath).normalize('NFC');
118
+ const normalizedDir = normalize(memoryDir).replace(/[/\\]+$/, '').normalize('NFC') + sep;
119
+ return normalizedPath.startsWith(normalizedDir);
120
+ }
121
+ //# sourceMappingURL=memory-paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-paths.js","sourceRoot":"","sources":["../../src/memory/memory-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;A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ompts provide cognitive scaffolding — they teach the LLM what
5
+ * memory types exist, when to save, what NOT to save, when to access,
6
+ * and how to verify recalled memories before recommending them.
7
+ *
8
+ * Ported from old_src/memdir/memoryTypes.ts and old_src/memdir/memdir.ts.
9
+ */
10
+ export declare const MEMORY_FRONTMATTER_EXAMPLE: readonly string[];
11
+ export declare const TYPES_SECTION: readonly string[];
12
+ export declare const WHAT_NOT_TO_SAVE_SECTION: readonly string[];
13
+ export declare const MEMORY_DRIFT_CAVEAT = "- Memory records can become stale over time. Use memory as context for what was true at a given point in time. Before answering the user or building assumptions based solely on information in memory records, verify that the memory is still correct and up-to-date by reading the current state of the files or resources. If a recalled memory conflicts with current information, trust what you observe now \u2014 and update or remove the stale memory rather than acting on it.";
14
+ export declare const WHEN_TO_ACCESS_SECTION: readonly string[];
15
+ export declare const TRUSTING_RECALL_SECTION: readonly string[];
16
+ export declare function buildHowToSaveSection(): readonly string[];
17
+ export declare const PERSISTENCE_SECTION: readonly string[];
18
+ /**
19
+ * Build the complete memory behavioral instructions for injection into
20
+ * the system prompt / context. This provides the LLM with all the
21
+ * cognitive scaffolding needed to manage the file-based memory system.
22
+ */
23
+ export declare function buildMemoryInstructions(memoryDir: string): string;
24
+ /**
25
+ * Build the extraction prompt for the background extraction LLM call.
26
+ * Includes existing memory manifest to avoid duplicates.
27
+ *
28
+ * @deprecated Use buildForkedExtractionPrompt instead.
29
+ */
30
+ export declare function buildExtractionPrompt(newMessageCount: number, existingManifest: string): string;
31
+ /**
32
+ * Build the extraction prompt for the forked agent with memory tools.
33
+ *
34
+ * The forked agent has access to memory_list, memory_read, memory_write,
35
+ * memory_edit, and memory_delete. This prompt instructs it to:
36
+ * 1. Check existing memories (via manifest + memory_read)
37
+ * 2. Update existing files (memory_edit) instead of creating duplicates
38
+ * 3. Only create new files (memory_write) when truly novel
39
+ */
40
+ export declare function buildForkedExtractionPrompt(newMessageCount: number, existingManifest: string): string;
41
+ //# sourceMappingURL=memory-prompts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-prompts.d.ts","sourceRoot":"","sources":["../../src/memory/memory-prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAYH,eAAO,MAAM,0BAA0B,EAAE,SAAS,MAAM,EAUvD,CAAC;AAMF,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAiE1C,CAAC;AAMF,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EASrD,CAAC;AAMF,eAAO,MAAM,mBAAmB,8dACwb,CAAC;AAEzd,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAMnD,CAAC;AAMF,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EAYpD,CAAC;AAMF,wBAAgB,qBAAqB,IAAI,SAAS,MAAM,EAAE,CAkBzD;AAMD,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAKhD,CAAC;AAMF;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAwBjE;AAMD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAwBR;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CACzC,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAwCR"}
@@ -0,0 +1,279 @@
1
+ /**
2
+ * Behavioral prompt sections for the file-based memory system.
3
+ *
4
+ * These prompts provide cognitive scaffolding — they teach the LLM what
5
+ * memory types exist, when to save, what NOT to save, when to access,
6
+ * and how to verify recalled memories before recommending them.
7
+ *
8
+ * Ported from old_src/memdir/memoryTypes.ts and old_src/memdir/memdir.ts.
9
+ */
10
+ import { MEMORY_TYPES, ENTRYPOINT_NAME, MAX_ENTRYPOINT_LINES, } from './memory-types.js';
11
+ // ---------------------------------------------------------------------------
12
+ // Frontmatter example
13
+ // ---------------------------------------------------------------------------
14
+ export const MEMORY_FRONTMATTER_EXAMPLE = [
15
+ '```markdown',
16
+ '---',
17
+ 'name: {{memory name}}',
18
+ 'description: {{one-line description — used to decide relevance in future conversations, so be specific}}',
19
+ `type: {{${MEMORY_TYPES.join(', ')}}}`,
20
+ '---',
21
+ '',
22
+ '{{memory content — for feedback/project types, structure as: rule/fact, then **Why:** and **How to apply:** lines}}',
23
+ '```',
24
+ ];
25
+ // ---------------------------------------------------------------------------
26
+ // Types section (individual mode — no team memory)
27
+ // ---------------------------------------------------------------------------
28
+ export const TYPES_SECTION = [
29
+ '## Types of memory',
30
+ '',
31
+ 'There are several discrete types of memory that you can store in your memory system:',
32
+ '',
33
+ '<types>',
34
+ '<type>',
35
+ ' <name>user</name>',
36
+ " <description>Contain information about the user's role, goals, responsibilities, and knowledge. Great user memories help you tailor your future behavior to the user's preferences and perspective. Your goal in reading and writing these memories is to build up an understanding of who the user is and how you can be most helpful to them specifically. For example, you should collaborate with a senior software engineer differently than a student who is coding for the very first time. Keep in mind, that the aim here is to be helpful to the user. Avoid writing memories about the user that could be viewed as a negative judgement or that are not relevant to the work you're trying to accomplish together.</description>",
37
+ " <when_to_save>When you learn any details about the user's role, preferences, responsibilities, or knowledge</when_to_save>",
38
+ " <how_to_use>When your work should be informed by the user's profile or perspective. For example, if the user is asking you to explain a part of the code, you should answer that question in a way that is tailored to the specific details that they will find most valuable or that helps them build their mental model in relation to domain knowledge they already have.</how_to_use>",
39
+ ' <examples>',
40
+ " user: I'm a data scientist investigating what logging we have in place",
41
+ ' assistant: [saves user memory: user is a data scientist, currently focused on observability/logging]',
42
+ '',
43
+ " user: I've been writing Go for ten years but this is my first time touching the React side of this repo",
44
+ " assistant: [saves user memory: deep Go expertise, new to React and this project's frontend — frame frontend explanations in terms of backend analogues]",
45
+ ' </examples>',
46
+ '</type>',
47
+ '<type>',
48
+ ' <name>feedback</name>',
49
+ ' <description>Guidance the user has given you about how to approach work — both what to avoid and what to keep doing. These are a very important type of memory to read and write as they allow you to remain coherent and responsive to the way you should approach work in the project. Record from failure AND success: if you only save corrections, you will avoid past mistakes but drift away from approaches the user has already validated, and may grow overly cautious.</description>',
50
+ ' <when_to_save>Any time the user corrects your approach ("no not that", "don\'t", "stop doing X") OR confirms a non-obvious approach worked ("yes exactly", "perfect, keep doing that", accepting an unusual choice without pushback). Corrections are easy to notice; confirmations are quieter — watch for them. In both cases, save what is applicable to future conversations, especially if surprising or not obvious from the code. Include *why* so you can judge edge cases later.</when_to_save>',
51
+ ' <how_to_use>Let these memories guide your behavior so that the user does not need to offer the same guidance twice.</how_to_use>',
52
+ ' <body_structure>Lead with the rule itself, then a **Why:** line (the reason the user gave — often a past incident or strong preference) and a **How to apply:** line (when/where this guidance kicks in). Knowing *why* lets you judge edge cases instead of blindly following the rule.</body_structure>',
53
+ ' <examples>',
54
+ " user: don't mock the database in these tests — we got burned last quarter when mocked tests passed but the prod migration failed",
55
+ ' assistant: [saves feedback memory: integration tests must hit a real database, not mocks. Reason: prior incident where mock/prod divergence masked a broken migration]',
56
+ '',
57
+ ' user: stop summarizing what you just did at the end of every response, I can read the diff',
58
+ ' assistant: [saves feedback memory: this user wants terse responses with no trailing summaries]',
59
+ '',
60
+ " user: yeah the single bundled PR was the right call here, splitting this one would've just been churn",
61
+ ' assistant: [saves feedback memory: for refactors in this area, user prefers one bundled PR over many small ones. Confirmed after I chose this approach — a validated judgment call, not a correction]',
62
+ ' </examples>',
63
+ '</type>',
64
+ '<type>',
65
+ ' <name>project</name>',
66
+ ' <description>Information that you learn about ongoing work, goals, initiatives, bugs, or incidents within the project that is not otherwise derivable from the code or git history. Project memories help you understand the broader context and motivation behind the work the user is doing within this working directory.</description>',
67
+ ' <when_to_save>When you learn who is doing what, why, or by when. These states change relatively quickly so try to keep your understanding of this up to date. Always convert relative dates in user messages to absolute dates when saving (e.g., "Thursday" → "2026-03-05"), so the memory remains interpretable after time passes.</when_to_save>',
68
+ " <how_to_use>Use these memories to more fully understand the details and nuance behind the user's request and make better informed suggestions.</how_to_use>",
69
+ ' <body_structure>Lead with the fact or decision, then a **Why:** line (the motivation — often a constraint, deadline, or stakeholder ask) and a **How to apply:** line (how this should shape your suggestions). Project memories decay fast, so the why helps future-you judge whether the memory is still load-bearing.</body_structure>',
70
+ ' <examples>',
71
+ " user: we're freezing all non-critical merges after Thursday — mobile team is cutting a release branch",
72
+ ' assistant: [saves project memory: merge freeze begins 2026-03-05 for mobile release cut. Flag any non-critical PR work scheduled after that date]',
73
+ '',
74
+ " user: the reason we're ripping out the old auth middleware is that legal flagged it for storing session tokens in a way that doesn't meet the new compliance requirements",
75
+ ' assistant: [saves project memory: auth middleware rewrite is driven by legal/compliance requirements around session token storage, not tech-debt cleanup — scope decisions should favor compliance over ergonomics]',
76
+ ' </examples>',
77
+ '</type>',
78
+ '<type>',
79
+ ' <name>reference</name>',
80
+ ' <description>Stores pointers to where information can be found in external systems. These memories allow you to remember where to look to find up-to-date information outside of the project directory.</description>',
81
+ ' <when_to_save>When you learn about resources in external systems and their purpose. For example, that bugs are tracked in a specific project in Linear or that feedback can be found in a specific Slack channel.</when_to_save>',
82
+ ' <how_to_use>When the user references an external system or information that may be in an external system.</how_to_use>',
83
+ ' <examples>',
84
+ ' user: check the Linear project "INGEST" if you want context on these tickets, that\'s where we track all pipeline bugs',
85
+ ' assistant: [saves reference memory: pipeline bugs are tracked in Linear project "INGEST"]',
86
+ '',
87
+ " user: the Grafana board at grafana.internal/d/api-latency is what oncall watches — if you're touching request handling, that's the thing that'll page someone",
88
+ ' assistant: [saves reference memory: grafana.internal/d/api-latency is the oncall latency dashboard — check it when editing request-path code]',
89
+ ' </examples>',
90
+ '</type>',
91
+ '</types>',
92
+ '',
93
+ ];
94
+ // ---------------------------------------------------------------------------
95
+ // What NOT to save
96
+ // ---------------------------------------------------------------------------
97
+ export const WHAT_NOT_TO_SAVE_SECTION = [
98
+ '## What NOT to save in memory',
99
+ '',
100
+ '- Code patterns, conventions, architecture, file paths, or project structure — these can be derived by reading the current project state.',
101
+ '- Git history, recent changes, or who-changed-what — `git log` / `git blame` are authoritative.',
102
+ '- Debugging solutions or fix recipes — the fix is in the code; the commit message has the context.',
103
+ '- Ephemeral task details: in-progress work, temporary state, current conversation context.',
104
+ '',
105
+ 'These exclusions apply even when the user explicitly asks you to save. If they ask you to save a PR list or activity summary, ask what was *surprising* or *non-obvious* about it — that is the part worth keeping.',
106
+ ];
107
+ // ---------------------------------------------------------------------------
108
+ // When to access
109
+ // ---------------------------------------------------------------------------
110
+ export const MEMORY_DRIFT_CAVEAT = '- Memory records can become stale over time. Use memory as context for what was true at a given point in time. Before answering the user or building assumptions based solely on information in memory records, verify that the memory is still correct and up-to-date by reading the current state of the files or resources. If a recalled memory conflicts with current information, trust what you observe now — and update or remove the stale memory rather than acting on it.';
111
+ export const WHEN_TO_ACCESS_SECTION = [
112
+ '## When to access memories',
113
+ '- When memories seem relevant, or the user references prior-conversation work.',
114
+ '- You MUST access memory when the user explicitly asks you to check, recall, or remember.',
115
+ '- If the user says to *ignore* or *not use* memory: proceed as if MEMORY.md were empty. Do not apply remembered facts, cite, compare against, or mention memory content.',
116
+ MEMORY_DRIFT_CAVEAT,
117
+ ];
118
+ // ---------------------------------------------------------------------------
119
+ // Trusting what you recall
120
+ // ---------------------------------------------------------------------------
121
+ export const TRUSTING_RECALL_SECTION = [
122
+ '## Before recommending from memory',
123
+ '',
124
+ 'A memory that names a specific function, file, or flag is a claim that it existed *when the memory was written*. It may have been renamed, removed, or never merged. Before recommending it:',
125
+ '',
126
+ '- If the memory names a file path: check the file exists.',
127
+ '- If the memory names a function or flag: grep for it.',
128
+ '- If the user is about to act on your recommendation (not just asking about history), verify first.',
129
+ '',
130
+ '"The memory says X exists" is not the same as "X exists now."',
131
+ '',
132
+ 'A memory that summarizes repo state (activity logs, architecture snapshots) is frozen in time. If the user asks about *recent* or *current* state, prefer `git log` or reading the code over recalling the snapshot.',
133
+ ];
134
+ // ---------------------------------------------------------------------------
135
+ // How to save (two-step process)
136
+ // ---------------------------------------------------------------------------
137
+ export function buildHowToSaveSection() {
138
+ return [
139
+ '## How to save memories',
140
+ '',
141
+ 'Saving a memory is a two-step process:',
142
+ '',
143
+ '**Step 1** — write the memory to its own file (e.g., `user_role.md`, `feedback_testing.md`) using this frontmatter format:',
144
+ '',
145
+ ...MEMORY_FRONTMATTER_EXAMPLE,
146
+ '',
147
+ `**Step 2** — add a pointer to that file in \`${ENTRYPOINT_NAME}\`. \`${ENTRYPOINT_NAME}\` is an index, not a memory — each entry should be one line, under ~150 characters: \`- [Title](file.md) — one-line hook\`. It has no frontmatter. Never write memory content directly into \`${ENTRYPOINT_NAME}\`.`,
148
+ '',
149
+ `- \`${ENTRYPOINT_NAME}\` is always loaded into your conversation context — lines after ${MAX_ENTRYPOINT_LINES} will be truncated, so keep the index concise`,
150
+ '- Keep the name, description, and type fields in memory files up-to-date with the content',
151
+ '- Organize memory semantically by topic, not chronologically',
152
+ '- Update or remove memories that turn out to be wrong or outdated',
153
+ '- Do not write duplicate memories. First check if there is an existing memory you can update before writing a new one.',
154
+ ];
155
+ }
156
+ // ---------------------------------------------------------------------------
157
+ // Memory vs other persistence
158
+ // ---------------------------------------------------------------------------
159
+ export const PERSISTENCE_SECTION = [
160
+ '## Memory and other forms of persistence',
161
+ 'Memory is one of several persistence mechanisms available to you as you assist the user in a given conversation. The distinction is often that memory can be recalled in future conversations and should not be used for persisting information that is only useful within the scope of the current conversation.',
162
+ '- When to use or update a plan instead of memory: If you are about to start a non-trivial implementation task and would like to reach alignment with the user on your approach you should use a Plan rather than saving this information to memory. Similarly, if you already have a plan within the conversation and you have changed your approach persist that change by updating the plan rather than saving a memory.',
163
+ '- When to use or update tasks instead of memory: When you need to break your work in current conversation into discrete steps or keep track of your progress use tasks instead of saving to memory. Tasks are great for persisting information about the work that needs to be done in the current conversation, but memory should be reserved for information that will be useful in future conversations.',
164
+ ];
165
+ // ---------------------------------------------------------------------------
166
+ // Full memory instructions builder
167
+ // ---------------------------------------------------------------------------
168
+ /**
169
+ * Build the complete memory behavioral instructions for injection into
170
+ * the system prompt / context. This provides the LLM with all the
171
+ * cognitive scaffolding needed to manage the file-based memory system.
172
+ */
173
+ export function buildMemoryInstructions(memoryDir) {
174
+ const lines = [
175
+ '# Memory System',
176
+ '',
177
+ `You have a persistent, file-based memory system at \`${memoryDir}\`. This directory already exists — write to it directly (do not run mkdir or check for its existence).`,
178
+ '',
179
+ "You should build up this memory system over time so that future conversations can have a complete picture of who the user is, how they'd like to collaborate with you, what behaviors to avoid or repeat, and the context behind the work the user gives you.",
180
+ '',
181
+ 'If the user explicitly asks you to remember something, save it immediately as whichever type fits best. If they ask you to forget something, find and remove the relevant entry.',
182
+ '',
183
+ ...TYPES_SECTION,
184
+ ...WHAT_NOT_TO_SAVE_SECTION,
185
+ '',
186
+ ...buildHowToSaveSection(),
187
+ '',
188
+ ...WHEN_TO_ACCESS_SECTION,
189
+ '',
190
+ ...TRUSTING_RECALL_SECTION,
191
+ '',
192
+ ...PERSISTENCE_SECTION,
193
+ '',
194
+ ];
195
+ return lines.join('\n');
196
+ }
197
+ // ---------------------------------------------------------------------------
198
+ // Extraction prompt builder
199
+ // ---------------------------------------------------------------------------
200
+ /**
201
+ * Build the extraction prompt for the background extraction LLM call.
202
+ * Includes existing memory manifest to avoid duplicates.
203
+ *
204
+ * @deprecated Use buildForkedExtractionPrompt instead.
205
+ */
206
+ export function buildExtractionPrompt(newMessageCount, existingManifest) {
207
+ const manifest = existingManifest.length > 0
208
+ ? `\n\n## Existing memory files\n\n${existingManifest}\n\nCheck this list before writing — update an existing file rather than creating a duplicate.`
209
+ : '';
210
+ return [
211
+ `You are a memory extraction agent. Analyze the most recent ~${newMessageCount} messages and extract durable memories worth saving for future conversations.`,
212
+ '',
213
+ `You MUST only use content from the last ~${newMessageCount} messages to update memories. Do not waste time investigating or verifying that content further — no grepping source files, no reading code to confirm a pattern exists, no git commands.`,
214
+ manifest,
215
+ '',
216
+ 'If the user explicitly asks to remember something, save the FULL content they provided — do NOT summarize or paraphrase. Preserve all details, rules, scenarios, and examples exactly as stated. If they ask to forget something, indicate removal.',
217
+ '',
218
+ ...TYPES_SECTION,
219
+ ...WHAT_NOT_TO_SAVE_SECTION,
220
+ '',
221
+ 'Return a JSON array of objects, each with:',
222
+ '- "name": short name for the memory (2-4 words)',
223
+ '- "description": one-line description for indexing (be specific — this is used to decide relevance in future conversations)',
224
+ `- "type": one of ${MEMORY_TYPES.join(', ')}`,
225
+ '- "content": the memory content (for feedback/project, include **Why:** and **How to apply:** sections)',
226
+ '',
227
+ 'If nothing worth remembering, return an empty array []. Return ONLY the JSON array, no other text.',
228
+ ].join('\n');
229
+ }
230
+ /**
231
+ * Build the extraction prompt for the forked agent with memory tools.
232
+ *
233
+ * The forked agent has access to memory_list, memory_read, memory_write,
234
+ * memory_edit, and memory_delete. This prompt instructs it to:
235
+ * 1. Check existing memories (via manifest + memory_read)
236
+ * 2. Update existing files (memory_edit) instead of creating duplicates
237
+ * 3. Only create new files (memory_write) when truly novel
238
+ */
239
+ export function buildForkedExtractionPrompt(newMessageCount, existingManifest) {
240
+ const manifest = existingManifest.length > 0
241
+ ? `\n\n## Existing memory files\n\n${existingManifest}\n\nCheck this list before writing — update an existing file rather than creating a duplicate.`
242
+ : '';
243
+ return [
244
+ `You are the memory extraction subagent. Analyze the most recent ~${newMessageCount} messages and use your tools to update the persistent memory system.`,
245
+ '',
246
+ 'Available tools: memory_list, memory_read, memory_write, memory_edit, memory_delete.',
247
+ '',
248
+ 'CRITICAL WORKFLOW:',
249
+ '- FIRST: Review the existing memory manifest below to see what already exists.',
250
+ '- If a memory on the same topic already exists, use memory_read to check its content, then memory_edit to update it.',
251
+ '- ONLY use memory_write for genuinely NEW topics not covered by any existing memory.',
252
+ '- NEVER create a duplicate. If in doubt, read the existing file first.',
253
+ '',
254
+ 'EFFICIENT STRATEGY (you have a limited turn budget):',
255
+ '- Turn 1: Call memory_read in parallel for every file you might want to update.',
256
+ '- Turn 2: Call memory_write / memory_edit / memory_delete in parallel for all changes.',
257
+ '- Do NOT interleave reads and writes across many turns.',
258
+ '',
259
+ `You MUST only use content from the last ~${newMessageCount} messages. Do not investigate further — no external lookups, no verification.`,
260
+ manifest,
261
+ '',
262
+ 'If the user explicitly asks to remember something, save the FULL content — do NOT summarize or paraphrase.',
263
+ 'If the user asks to forget something, use memory_delete.',
264
+ '',
265
+ ...TYPES_SECTION,
266
+ ...WHAT_NOT_TO_SAVE_SECTION,
267
+ '',
268
+ '## How to save',
269
+ '',
270
+ 'Use memory_write with:',
271
+ '- name: short name (2-4 words)',
272
+ '- description: one-line description (specific — used to decide relevance in future conversations)',
273
+ `- type: one of ${MEMORY_TYPES.join(', ')}`,
274
+ '- content: the memory body (for feedback/project, include **Why:** and **How to apply:** sections)',
275
+ '',
276
+ 'If nothing worth remembering, do nothing.',
277
+ ].join('\n');
278
+ }
279
+ //# sourceMappingURL=memory-prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-prompts.js","sourceRoot":"","sources":["../../src/memory/memory-prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,YAAY,EACZ,eAAe,EACf,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAE3B,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E,MAAM,CAAC,MAAM,0BAA0B,GAAsB;IAC3D,aAAa;IACb,KAAK;IACL,uBAAuB;IACvB,0GAA0G;IAC1G,WAAW,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;IACtC,KAAK;IACL,EAAE;IACF,qHAAqH;IACrH,KAAK;CACN,CAAC;AAEF,8EAA8E;AAC9E,mDAAmD;AACnD,8EAA8E;AAE9E,MAAM,CAAC,MAAM,aAAa,GAAsB;IAC9C,oBAAoB;IACpB,EAAE;IACF,sFAAsF;IACtF,EAAE;IACF,SAAS;IACT,QAAQ;IACR,uBAAuB;IACvB,ktBAAktB;IACltB,gIAAgI;IAChI,+XAA+X;IAC/X,gBAAgB;IAChB,4EAA4E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BAAgB;QAChB,EAAE;QACF,wBAAwB;QACxB,gCAAgC;QAChC,mGAAmG;QACnG,kBAAkB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC3C,oGAAoG;QACpG,EAAE;QACF,2CAA2C;KAC5C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * LLM-powered relevance selection for file-based memories.
3
+ *
4
+ * Given a user query and a manifest of available memory files, asks the LLM
5
+ * to select up to 5 most relevant memories. Uses OpenRouterClient.chat().
6
+ */
7
+ import type { OpenRouterClient } from '../llm/openrouter-client.js';
8
+ /**
9
+ * Ask the LLM to select relevant memories from a manifest.
10
+ * Returns an array of filenames (up to 5) that are most relevant to the query.
11
+ */
12
+ export declare function selectRelevantMemories(query: string, manifest: string, validFilenames: Set<string>, client: OpenRouterClient, options?: {
13
+ model?: string;
14
+ signal?: AbortSignal;
15
+ }): Promise<string[]>;
16
+ //# sourceMappingURL=memory-relevance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-relevance.d.ts","sourceRoot":"","sources":["../../src/memory/memory-relevance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AASpE;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,EAC3B,MAAM,EAAE,gBAAgB,EACxB,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GACjD,OAAO,CAAC,MAAM,EAAE,CAAC,CA4BnB"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * LLM-powered relevance selection for file-based memories.
3
+ *
4
+ * Given a user query and a manifest of available memory files, asks the LLM
5
+ * to select up to 5 most relevant memories. Uses OpenRouterClient.chat().
6
+ */
7
+ const SELECT_MEMORIES_SYSTEM_PROMPT = `You are selecting memories that will be useful to an AI agent as it processes a user's query. You will be given the user's query and a list of available memory files with their filenames and descriptions.
8
+
9
+ Return a JSON object with a "selected_memories" array containing filenames for the memories that will clearly be useful (up to 5). Only include memories that you are certain will be helpful based on their name and description.
10
+ - If you are unsure if a memory will be useful, do not include it.
11
+ - If no memories would clearly be useful, return an empty array.
12
+ - Return ONLY valid JSON, no other text.`;
13
+ /**
14
+ * Ask the LLM to select relevant memories from a manifest.
15
+ * Returns an array of filenames (up to 5) that are most relevant to the query.
16
+ */
17
+ export async function selectRelevantMemories(query, manifest, validFilenames, client, options) {
18
+ if (!manifest.trim())
19
+ return [];
20
+ try {
21
+ const response = await client.chat({
22
+ model: options?.model,
23
+ messages: [
24
+ { role: 'system', content: SELECT_MEMORIES_SYSTEM_PROMPT },
25
+ {
26
+ role: 'user',
27
+ content: `Query: ${query}\n\nAvailable memories:\n${manifest}`,
28
+ },
29
+ ],
30
+ temperature: 0,
31
+ maxTokens: 256,
32
+ responseFormat: { type: 'json_object' },
33
+ signal: options?.signal,
34
+ });
35
+ const parsed = JSON.parse(response.content);
36
+ if (!Array.isArray(parsed.selected_memories))
37
+ return [];
38
+ return parsed.selected_memories
39
+ .filter(f => typeof f === 'string' && validFilenames.has(f))
40
+ .slice(0, 5);
41
+ }
42
+ catch {
43
+ return [];
44
+ }
45
+ }
46
+ //# sourceMappingURL=memory-relevance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-relevance.js","sourceRoot":"","sources":["../../src/memory/memory-relevance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,6BAA6B,GAAG;;;;;yCAKG,CAAC;AAE1C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,KAAa,EACb,QAAgB,EAChB,cAA2B,EAC3B,MAAwB,EACxB,OAAkD;IAElD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IAEhC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC;YACjC,KAAK,EAAE,OAAO,EAAE,KAAK;YACrB,QAAQ,EAAE;gBACR,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,6BAA6B,EAAE;gBAC1D;oBACE,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,UAAU,KAAK,4BAA4B,QAAQ,EAAE;iBAC/D;aACF;YACD,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,GAAG;YACd,cAAc,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;YACvC,MAAM,EAAE,OAAO,EAAE,MAAM;SACxB,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAqC,CAAC;QAChF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC;YAAE,OAAO,EAAE,CAAC;QAExD,OAAO,MAAM,CAAC,iBAAiB;aAC5B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aAC3D,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACjB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Memory directory scanning — reads .md files, parses frontmatter,
3
+ * returns headers sorted by mtime (newest first), capped at MAX_MEMORY_FILES.
4
+ */
5
+ import { type MemoryHeader, type MemoryFrontmatter } from './memory-types.js';
6
+ /**
7
+ * Parse YAML frontmatter from markdown content.
8
+ * Handles name, description, type fields. Robust against special
9
+ * characters in values (colons, braces, globs, etc).
10
+ */
11
+ export declare function parseFrontmatter(content: string): MemoryFrontmatter;
12
+ /**
13
+ * Scan a memory directory for .md files, read their frontmatter, and return
14
+ * a header list sorted newest-first (capped at MAX_MEMORY_FILES).
15
+ */
16
+ export declare function scanMemoryFiles(memoryDir: string, signal?: AbortSignal): Promise<MemoryHeader[]>;
17
+ /**
18
+ * Format memory headers as a text manifest: one line per file with
19
+ * [type] filename (timestamp): description.
20
+ */
21
+ export declare function formatMemoryManifest(memories: MemoryHeader[]): string;
22
+ //# sourceMappingURL=memory-scanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-scanner.d.ts","sourceRoot":"","sources":["../../src/memory/memory-scanner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAIvB,MAAM,mBAAmB,CAAC;AAI3B;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAgCnE;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,YAAY,EAAE,CAAC,CA4CzB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,MAAM,CAUrE"}