audrey 0.17.0 → 0.21.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 (208) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +180 -370
  3. package/dist/mcp-server/config.d.ts +44 -0
  4. package/dist/mcp-server/config.d.ts.map +1 -0
  5. package/dist/mcp-server/config.js +210 -0
  6. package/dist/mcp-server/config.js.map +1 -0
  7. package/dist/mcp-server/index.d.ts +181 -0
  8. package/dist/mcp-server/index.d.ts.map +1 -0
  9. package/dist/mcp-server/index.js +1530 -0
  10. package/dist/mcp-server/index.js.map +1 -0
  11. package/dist/src/adaptive.d.ts +7 -0
  12. package/dist/src/adaptive.d.ts.map +1 -0
  13. package/dist/src/adaptive.js +49 -0
  14. package/dist/src/adaptive.js.map +1 -0
  15. package/dist/src/affect.d.ts +19 -0
  16. package/dist/src/affect.d.ts.map +1 -0
  17. package/dist/src/affect.js +72 -0
  18. package/dist/src/affect.js.map +1 -0
  19. package/dist/src/audrey.d.ts +144 -0
  20. package/dist/src/audrey.d.ts.map +1 -0
  21. package/dist/src/audrey.js +576 -0
  22. package/dist/src/audrey.js.map +1 -0
  23. package/dist/src/capsule.d.ts +68 -0
  24. package/dist/src/capsule.d.ts.map +1 -0
  25. package/dist/src/capsule.js +311 -0
  26. package/dist/src/capsule.js.map +1 -0
  27. package/dist/src/causal.d.ts +28 -0
  28. package/dist/src/causal.d.ts.map +1 -0
  29. package/dist/src/causal.js +65 -0
  30. package/dist/src/causal.js.map +1 -0
  31. package/dist/src/confidence.d.ts +12 -0
  32. package/dist/src/confidence.d.ts.map +1 -0
  33. package/dist/src/confidence.js +63 -0
  34. package/dist/src/confidence.js.map +1 -0
  35. package/dist/src/consolidate.d.ts +8 -0
  36. package/dist/src/consolidate.d.ts.map +1 -0
  37. package/dist/src/consolidate.js +218 -0
  38. package/dist/src/consolidate.js.map +1 -0
  39. package/dist/src/context.d.ts +3 -0
  40. package/dist/src/context.d.ts.map +1 -0
  41. package/dist/src/context.js +19 -0
  42. package/dist/src/context.js.map +1 -0
  43. package/dist/src/db.d.ts +12 -0
  44. package/dist/src/db.d.ts.map +1 -0
  45. package/dist/src/db.js +380 -0
  46. package/dist/src/db.js.map +1 -0
  47. package/dist/src/decay.d.ts +7 -0
  48. package/dist/src/decay.d.ts.map +1 -0
  49. package/dist/src/decay.js +68 -0
  50. package/dist/src/decay.js.map +1 -0
  51. package/dist/src/embedding.d.ts +57 -0
  52. package/dist/src/embedding.d.ts.map +1 -0
  53. package/dist/src/embedding.js +254 -0
  54. package/dist/src/embedding.js.map +1 -0
  55. package/dist/src/encode.d.ts +15 -0
  56. package/dist/src/encode.d.ts.map +1 -0
  57. package/dist/src/encode.js +36 -0
  58. package/dist/src/encode.js.map +1 -0
  59. package/dist/src/events.d.ts +69 -0
  60. package/dist/src/events.d.ts.map +1 -0
  61. package/dist/src/events.js +149 -0
  62. package/dist/src/events.js.map +1 -0
  63. package/dist/src/export.d.ts +3 -0
  64. package/dist/src/export.d.ts.map +1 -0
  65. package/dist/src/export.js +46 -0
  66. package/dist/src/export.js.map +1 -0
  67. package/dist/src/forget.d.ts +11 -0
  68. package/dist/src/forget.d.ts.map +1 -0
  69. package/dist/src/forget.js +105 -0
  70. package/dist/src/forget.js.map +1 -0
  71. package/dist/src/fts.d.ts +34 -0
  72. package/dist/src/fts.d.ts.map +1 -0
  73. package/dist/src/fts.js +117 -0
  74. package/dist/src/fts.js.map +1 -0
  75. package/dist/src/hybrid-recall.d.ts +37 -0
  76. package/dist/src/hybrid-recall.d.ts.map +1 -0
  77. package/dist/src/hybrid-recall.js +213 -0
  78. package/dist/src/hybrid-recall.js.map +1 -0
  79. package/dist/src/import.d.ts +4 -0
  80. package/dist/src/import.d.ts.map +1 -0
  81. package/dist/src/import.js +127 -0
  82. package/dist/src/import.js.map +1 -0
  83. package/dist/src/index.d.ts +26 -0
  84. package/dist/src/index.d.ts.map +1 -0
  85. package/{src → dist/src}/index.js +7 -13
  86. package/dist/src/index.js.map +1 -0
  87. package/dist/src/interference.d.ts +13 -0
  88. package/dist/src/interference.d.ts.map +1 -0
  89. package/dist/src/interference.js +45 -0
  90. package/dist/src/interference.js.map +1 -0
  91. package/dist/src/introspect.d.ts +4 -0
  92. package/dist/src/introspect.d.ts.map +1 -0
  93. package/dist/src/introspect.js +40 -0
  94. package/dist/src/introspect.js.map +1 -0
  95. package/dist/src/llm.d.ts +38 -0
  96. package/dist/src/llm.d.ts.map +1 -0
  97. package/dist/src/llm.js +167 -0
  98. package/dist/src/llm.js.map +1 -0
  99. package/dist/src/migrate.d.ts +6 -0
  100. package/dist/src/migrate.d.ts.map +1 -0
  101. package/dist/src/migrate.js +51 -0
  102. package/dist/src/migrate.js.map +1 -0
  103. package/dist/src/preflight.d.ts +51 -0
  104. package/dist/src/preflight.d.ts.map +1 -0
  105. package/dist/src/preflight.js +201 -0
  106. package/dist/src/preflight.js.map +1 -0
  107. package/dist/src/promote.d.ts +40 -0
  108. package/dist/src/promote.d.ts.map +1 -0
  109. package/dist/src/promote.js +200 -0
  110. package/dist/src/promote.js.map +1 -0
  111. package/dist/src/prompts.d.ts +16 -0
  112. package/dist/src/prompts.d.ts.map +1 -0
  113. package/{src → dist/src}/prompts.js +172 -203
  114. package/dist/src/prompts.js.map +1 -0
  115. package/dist/src/recall.d.ts +9 -0
  116. package/dist/src/recall.d.ts.map +1 -0
  117. package/dist/src/recall.js +432 -0
  118. package/dist/src/recall.js.map +1 -0
  119. package/dist/src/redact.d.ts +27 -0
  120. package/dist/src/redact.d.ts.map +1 -0
  121. package/dist/src/redact.js +228 -0
  122. package/dist/src/redact.js.map +1 -0
  123. package/dist/src/reflexes.d.ts +35 -0
  124. package/dist/src/reflexes.d.ts.map +1 -0
  125. package/dist/src/reflexes.js +87 -0
  126. package/dist/src/reflexes.js.map +1 -0
  127. package/dist/src/rollback.d.ts +8 -0
  128. package/dist/src/rollback.d.ts.map +1 -0
  129. package/dist/src/rollback.js +33 -0
  130. package/dist/src/rollback.js.map +1 -0
  131. package/dist/src/routes.d.ts +7 -0
  132. package/dist/src/routes.d.ts.map +1 -0
  133. package/dist/src/routes.js +303 -0
  134. package/dist/src/routes.js.map +1 -0
  135. package/dist/src/rules-compiler.d.ts +20 -0
  136. package/dist/src/rules-compiler.d.ts.map +1 -0
  137. package/dist/src/rules-compiler.js +143 -0
  138. package/dist/src/rules-compiler.js.map +1 -0
  139. package/dist/src/server.d.ts +12 -0
  140. package/dist/src/server.d.ts.map +1 -0
  141. package/dist/src/server.js +22 -0
  142. package/dist/src/server.js.map +1 -0
  143. package/dist/src/tool-trace.d.ts +37 -0
  144. package/dist/src/tool-trace.d.ts.map +1 -0
  145. package/dist/src/tool-trace.js +142 -0
  146. package/dist/src/tool-trace.js.map +1 -0
  147. package/dist/src/types.d.ts +446 -0
  148. package/dist/src/types.d.ts.map +1 -0
  149. package/dist/src/types.js +6 -0
  150. package/dist/src/types.js.map +1 -0
  151. package/dist/src/ulid.d.ts +3 -0
  152. package/dist/src/ulid.d.ts.map +1 -0
  153. package/dist/src/ulid.js +11 -0
  154. package/dist/src/ulid.js.map +1 -0
  155. package/dist/src/utils.d.ts +10 -0
  156. package/dist/src/utils.d.ts.map +1 -0
  157. package/dist/src/utils.js +41 -0
  158. package/dist/src/utils.js.map +1 -0
  159. package/dist/src/validate.d.ts +22 -0
  160. package/dist/src/validate.d.ts.map +1 -0
  161. package/dist/src/validate.js +109 -0
  162. package/dist/src/validate.js.map +1 -0
  163. package/docs/assets/audrey-feature-grid.jpg +0 -0
  164. package/docs/assets/audrey-logo.svg +45 -0
  165. package/docs/assets/audrey-wordmark.png +0 -0
  166. package/docs/audrey-for-dummies.md +670 -0
  167. package/docs/future-of-llm-memory.md +452 -0
  168. package/docs/mcp-hosts.md +206 -0
  169. package/docs/ollama-local-agents.md +128 -0
  170. package/docs/production-readiness.md +37 -5
  171. package/examples/fintech-ops-demo.js +1 -1
  172. package/examples/healthcare-ops-demo.js +1 -1
  173. package/examples/ollama-memory-agent.js +326 -0
  174. package/examples/stripe-demo.js +1 -1
  175. package/package.json +54 -14
  176. package/benchmarks/baselines.js +0 -169
  177. package/benchmarks/cases.js +0 -421
  178. package/benchmarks/reference-results.js +0 -70
  179. package/benchmarks/report.js +0 -255
  180. package/benchmarks/run.js +0 -514
  181. package/mcp-server/config.js +0 -133
  182. package/mcp-server/index.js +0 -1265
  183. package/mcp-server/serve.js +0 -482
  184. package/src/adaptive.js +0 -53
  185. package/src/affect.js +0 -64
  186. package/src/audrey.js +0 -642
  187. package/src/causal.js +0 -95
  188. package/src/confidence.js +0 -120
  189. package/src/consolidate.js +0 -281
  190. package/src/context.js +0 -15
  191. package/src/db.js +0 -391
  192. package/src/decay.js +0 -84
  193. package/src/embedding.js +0 -260
  194. package/src/encode.js +0 -69
  195. package/src/export.js +0 -67
  196. package/src/forget.js +0 -111
  197. package/src/fts.js +0 -134
  198. package/src/import.js +0 -273
  199. package/src/interference.js +0 -51
  200. package/src/introspect.js +0 -48
  201. package/src/llm.js +0 -249
  202. package/src/migrate.js +0 -58
  203. package/src/recall.js +0 -573
  204. package/src/rollback.js +0 -42
  205. package/src/ulid.js +0 -18
  206. package/src/utils.js +0 -63
  207. package/src/validate.js +0 -172
  208. package/types/index.d.ts +0 -434
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Memory-to-Behavior promotion — candidate scoring.
3
+ *
4
+ * A "candidate" is a memory (usually procedural, sometimes high-confidence
5
+ * semantic) that has earned the right to become an enforced project rule:
6
+ * - repeated occurrence (multiple supporting episodes)
7
+ * - low contradiction (active state, not disputed)
8
+ * - durable (not recently superseded)
9
+ * - not already promoted to this target
10
+ *
11
+ * Tool-failure context also boosts candidates: if the Bash tool has failed
12
+ * 3 times this week with errors mentioning "sqlite extension", a procedural
13
+ * memory about "initialize sqlite extension before tests" gets a
14
+ * failure_prevented score, which bubbles it up in the ranked list.
15
+ */
16
+ import { recentFailures } from './events.js';
17
+ function loadPromotedMemoryIds(db, target) {
18
+ const rows = db.prepare(`SELECT metadata FROM memory_events
19
+ WHERE event_type = 'Promotion' AND tool_name = ?`).all(target);
20
+ const ids = new Set();
21
+ for (const row of rows) {
22
+ if (!row.metadata)
23
+ continue;
24
+ try {
25
+ const parsed = JSON.parse(row.metadata);
26
+ const memoryIds = parsed.memory_ids;
27
+ if (Array.isArray(memoryIds)) {
28
+ for (const id of memoryIds)
29
+ ids.add(String(id));
30
+ }
31
+ }
32
+ catch {
33
+ // skip malformed metadata
34
+ }
35
+ }
36
+ return ids;
37
+ }
38
+ function matchesFailure(memoryContent, failure) {
39
+ if (!failure.last_error_summary)
40
+ return 0;
41
+ const lower = memoryContent.toLowerCase();
42
+ const errLower = failure.last_error_summary.toLowerCase();
43
+ const toolLower = (failure.tool_name || '').toLowerCase();
44
+ const errWords = errLower.split(/[^a-z0-9]+/).filter(w => w.length >= 4);
45
+ const memWords = new Set(lower.split(/[^a-z0-9]+/).filter(Boolean));
46
+ let overlap = 0;
47
+ for (const w of errWords) {
48
+ if (memWords.has(w))
49
+ overlap++;
50
+ }
51
+ const toolBonus = toolLower && lower.includes(toolLower) ? 1 : 0;
52
+ return overlap + toolBonus;
53
+ }
54
+ function scoreCandidate(params) {
55
+ const confidenceScore = params.confidence * 40;
56
+ const evidenceScore = Math.min(params.evidence, 10) * 3;
57
+ const retrievalScore = Math.min(params.retrieval, 20) * 1.5;
58
+ const usageScore = Math.min(params.usage, 10) * 2;
59
+ const failureScore = Math.min(params.failurePrevented, 5) * 8;
60
+ // Slight penalty for very young memories so one flaky session can't promote itself.
61
+ const agePenalty = params.ageHours < 6 ? 10 : 0;
62
+ return confidenceScore + evidenceScore + retrievalScore + usageScore + failureScore - agePenalty;
63
+ }
64
+ function hoursSince(iso) {
65
+ const t = Date.parse(iso);
66
+ if (!Number.isFinite(t))
67
+ return 0;
68
+ return (Date.now() - t) / (60 * 60 * 1000);
69
+ }
70
+ function parseTags(raw) {
71
+ if (!raw)
72
+ return [];
73
+ try {
74
+ const parsed = JSON.parse(raw);
75
+ if (Array.isArray(parsed))
76
+ return parsed.map(String);
77
+ }
78
+ catch {
79
+ // fall through
80
+ }
81
+ return String(raw).split(',').map(t => t.trim()).filter(Boolean);
82
+ }
83
+ export function findPromotionCandidates(db, options = {}) {
84
+ const minConfidence = options.minConfidence ?? 0.7;
85
+ const minEvidence = options.minEvidence ?? 2;
86
+ const limit = options.limit ?? 20;
87
+ const target = options.target ?? 'claude-rules';
88
+ const alreadyPromoted = loadPromotedMemoryIds(db, target);
89
+ const failures = recentFailures(db, {
90
+ since: options.since ?? new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString(),
91
+ limit: 20,
92
+ });
93
+ const candidates = [];
94
+ // Procedural memories: primary promotion stream
95
+ const procedurals = db.prepare(`SELECT id, content, state, success_count, failure_count, retrieval_count,
96
+ usage_count, salience, created_at, last_reinforced_at
97
+ FROM procedures
98
+ WHERE state = 'active'`).all();
99
+ for (const row of procedurals) {
100
+ if (alreadyPromoted.has(row.id))
101
+ continue;
102
+ const successes = row.success_count ?? 0;
103
+ const failures_count = row.failure_count ?? 0;
104
+ const evidenceTotal = successes + failures_count;
105
+ if (evidenceTotal < minEvidence)
106
+ continue;
107
+ const confidence = evidenceTotal === 0 ? 0 : successes / evidenceTotal;
108
+ if (confidence < minConfidence)
109
+ continue;
110
+ const tagsRow = db.prepare(`SELECT trigger_conditions FROM procedures WHERE id = ?`).get(row.id);
111
+ const tags = parseTags(tagsRow?.trigger_conditions);
112
+ let failurePrevented = 0;
113
+ for (const f of failures) {
114
+ if (matchesFailure(row.content, f) >= 2)
115
+ failurePrevented += 1;
116
+ }
117
+ const score = scoreCandidate({
118
+ confidence,
119
+ evidence: evidenceTotal,
120
+ retrieval: row.retrieval_count ?? 0,
121
+ usage: row.usage_count ?? 0,
122
+ failurePrevented,
123
+ ageHours: hoursSince(row.last_reinforced_at ?? row.created_at),
124
+ });
125
+ const reasonParts = [
126
+ `procedural memory with ${successes}/${evidenceTotal} successful applications`,
127
+ ];
128
+ if (failurePrevented > 0)
129
+ reasonParts.push(`would have prevented ${failurePrevented} recent tool failure${failurePrevented === 1 ? '' : 's'}`);
130
+ if ((row.usage_count ?? 0) > 0)
131
+ reasonParts.push(`used ${row.usage_count} time${row.usage_count === 1 ? '' : 's'}`);
132
+ candidates.push({
133
+ candidate_id: `proc:${row.id}`,
134
+ memory_id: row.id,
135
+ memory_type: 'procedural',
136
+ content: row.content,
137
+ confidence,
138
+ evidence_count: evidenceTotal,
139
+ usage_count: row.usage_count ?? 0,
140
+ failure_prevented: failurePrevented,
141
+ tags,
142
+ score,
143
+ reason: reasonParts.join('; '),
144
+ });
145
+ }
146
+ // Semantic memories: only high-confidence, high-evidence, heavily reinforced ones.
147
+ // The bar is higher because semantic memories are "facts," not "procedures" — we
148
+ // do not want to promote every shared fact as a rule.
149
+ const semantics = db.prepare(`SELECT id, content, state, evidence_count, supporting_count, contradicting_count,
150
+ retrieval_count, usage_count, salience, created_at, last_reinforced_at
151
+ FROM semantics
152
+ WHERE state = 'active'`).all();
153
+ for (const row of semantics) {
154
+ if (alreadyPromoted.has(row.id))
155
+ continue;
156
+ const evidence = row.evidence_count ?? 0;
157
+ if (evidence < Math.max(minEvidence, 3))
158
+ continue;
159
+ if ((row.contradicting_count ?? 0) > 0)
160
+ continue;
161
+ const supporting = row.supporting_count ?? evidence;
162
+ const confidence = supporting === 0 ? 0 : Math.min(1, supporting / Math.max(evidence, 1));
163
+ if (confidence < Math.max(minConfidence, 0.8))
164
+ continue;
165
+ let failurePrevented = 0;
166
+ for (const f of failures) {
167
+ if (matchesFailure(row.content, f) >= 2)
168
+ failurePrevented += 1;
169
+ }
170
+ const score = scoreCandidate({
171
+ confidence,
172
+ evidence,
173
+ retrieval: row.retrieval_count ?? 0,
174
+ usage: row.usage_count ?? 0,
175
+ failurePrevented,
176
+ ageHours: hoursSince(row.last_reinforced_at ?? row.created_at),
177
+ });
178
+ const reasonParts = [
179
+ `semantic principle with ${supporting}/${evidence} supporting episodes`,
180
+ ];
181
+ if (failurePrevented > 0)
182
+ reasonParts.push(`matches ${failurePrevented} recent tool failure${failurePrevented === 1 ? '' : 's'}`);
183
+ candidates.push({
184
+ candidate_id: `sem:${row.id}`,
185
+ memory_id: row.id,
186
+ memory_type: 'semantic',
187
+ content: row.content,
188
+ confidence,
189
+ evidence_count: evidence,
190
+ usage_count: row.usage_count ?? 0,
191
+ failure_prevented: failurePrevented,
192
+ tags: [],
193
+ score,
194
+ reason: reasonParts.join('; '),
195
+ });
196
+ }
197
+ candidates.sort((a, b) => b.score - a.score);
198
+ return candidates.slice(0, limit);
199
+ }
200
+ //# sourceMappingURL=promote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promote.js","sourceRoot":"","sources":["../../src/promote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,cAAc,EAAuB,MAAM,aAAa,CAAC;AA0DlE,SAAS,qBAAqB,CAAC,EAAqB,EAAE,MAAuB;IAC3E,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CACrB;sDACkD,CACnD,CAAC,GAAG,CAAC,MAAM,CAAe,CAAC;IAE5B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,GAAG,CAAC,QAAQ;YAAE,SAAS;QAC5B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAA4B,CAAC;YACnE,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC;YACpC,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC7B,KAAK,MAAM,EAAE,IAAI,SAAS;oBAAE,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,0BAA0B;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K,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAC7C,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { ChatMessage, EpisodeRow } from './types.js';
2
+ export declare function buildPrincipleExtractionPrompt(episodes: EpisodeRow[]): ChatMessage[];
3
+ export declare function buildContradictionDetectionPrompt(newContent: string, existingContent: string): ChatMessage[];
4
+ export declare function buildCausalArticulationPrompt(cause: {
5
+ content: string;
6
+ source: string;
7
+ }, effect: {
8
+ content: string;
9
+ source: string;
10
+ }): ChatMessage[];
11
+ export declare function buildContextResolutionPrompt(claimA: string, claimB: string, context?: string): ChatMessage[];
12
+ export declare function buildReflectionPrompt(turns: {
13
+ role: string;
14
+ content: string;
15
+ }[]): ChatMessage[];
16
+ //# sourceMappingURL=prompts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG1D,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,WAAW,EAAE,CA6CpF;AAED,wBAAgB,iCAAiC,CAAC,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,WAAW,EAAE,CA6B5G;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC1C,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC1C,WAAW,EAAE,CA+Bf;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE,CA+B5G;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,WAAW,EAAE,CAoD/F"}
@@ -1,223 +1,192 @@
1
1
  import { safeJsonParse } from './utils.js';
2
-
3
- /**
4
- * @param {Object[]} episodes
5
- * @returns {import('./llm.js').ChatMessage[]}
6
- */
7
2
  export function buildPrincipleExtractionPrompt(episodes) {
8
- const episodeList = episodes.map((ep, i) => {
9
- const tags = safeJsonParse(ep.tags, []);
10
- return `Episode ${i + 1}:
11
- - Content: ${ep.content}
12
- - Source: ${ep.source}
13
- - Date: ${ep.created_at}
3
+ const episodeList = episodes.map((ep, i) => {
4
+ const tags = safeJsonParse(ep.tags, []);
5
+ return `Episode ${i + 1}:
6
+ - Content: ${ep.content}
7
+ - Source: ${ep.source}
8
+ - Date: ${ep.created_at}
14
9
  - Tags: ${tags.length > 0 ? tags.join(', ') : 'none'}`;
15
- }).join('\n\n');
16
-
17
- return [
18
- {
19
- role: 'system',
20
- content: `You are performing principleExtraction for a memory system. Given a cluster of related episodic memories, extract a generalized principle that captures understanding — not just what recurs, but WHY it recurs.
21
-
22
- Respond with ONLY valid JSON in this exact format:
23
- {
24
- "content": "The principle — captures understanding, not just pattern",
25
- "type": "semantic or procedural",
26
- "category": "technical or relational or identity",
27
- "conditions": ["boundary condition 1", "boundary condition 2"] or null if universally applicable
28
- }
29
-
30
- Principle categories:
31
-
32
- TECHNICAL — Architectural decisions with reasoning. Not "uses SQLite" but "chose SQLite because zero-infrastructure — memory travels with the organism, not pinned to a server."
33
-
34
- RELATIONAL — Patterns in the human-AI dynamic. Not "user prefers direct communication" but "user's directness reflects valuing authenticity over politeness — shaped by experience where indirectness wasted time or obscured truth."
35
-
36
- IDENTITY — Stable characteristics the AI has observed about itself across episodes. Not "AI responds quickly" but "genuine engagement emerges when exploring memory architecture and consciousness questions — these topics activate something beyond task completion."
37
-
38
- Rules:
39
- - GENERALIZE extract the principle behind the pattern, not a summary
40
- - Identify boundary conditions: when does this principle NOT apply?
41
- - Classify type as "semantic" (facts, rules, patterns) or "procedural" (steps, workflows, strategies)
42
- - Classify category as "technical", "relational", or "identity"
43
- - Consider source diversity principles from diverse sources are stronger
44
- - Capture WHY, not just WHAT
10
+ }).join('\n\n');
11
+ return [
12
+ {
13
+ role: 'system',
14
+ content: `You are performing principleExtraction for a memory system. Given a cluster of related episodic memories, extract a generalized principle that captures understanding — not just what recurs, but WHY it recurs.
15
+
16
+ Respond with ONLY valid JSON in this exact format:
17
+ {
18
+ "content": "The principle — captures understanding, not just pattern",
19
+ "type": "semantic or procedural",
20
+ "category": "technical or relational or identity",
21
+ "conditions": ["boundary condition 1", "boundary condition 2"] or null if universally applicable
22
+ }
23
+
24
+ Principle categories:
25
+
26
+ TECHNICAL — Architectural decisions with reasoning. Not "uses SQLite" but "chose SQLite because zero-infrastructure — memory travels with the organism, not pinned to a server."
27
+
28
+ RELATIONAL — Patterns in the human-AI dynamic. Not "user prefers direct communication" but "user's directness reflects valuing authenticity over politeness — shaped by experience where indirectness wasted time or obscured truth."
29
+
30
+ IDENTITY — Stable characteristics the AI has observed about itself across episodes. Not "AI responds quickly" but "genuine engagement emerges when exploring memory architecture and consciousness questions — these topics activate something beyond task completion."
31
+
32
+ Rules:
33
+ - GENERALIZE — extract the principle behind the pattern, not a summary
34
+ - Identify boundary conditions: when does this principle NOT apply?
35
+ - Classify type as "semantic" (facts, rules, patterns) or "procedural" (steps, workflows, strategies)
36
+ - Classify category as "technical", "relational", or "identity"
37
+ - Consider source diversity principles from diverse sources are stronger
38
+ - Capture WHY, not just WHAT
45
39
  - Be concise but precise`,
46
- },
47
- {
48
- role: 'user',
49
- content: `Extract a principle from these ${episodes.length} related episodes:\n\n${episodeList}`,
50
- },
51
- ];
40
+ },
41
+ {
42
+ role: 'user',
43
+ content: `Extract a principle from these ${episodes.length} related episodes:\n\n${episodeList}`,
44
+ },
45
+ ];
52
46
  }
53
-
54
- /**
55
- * @param {string} newContent
56
- * @param {string} existingContent
57
- * @returns {import('./llm.js').ChatMessage[]}
58
- */
59
47
  export function buildContradictionDetectionPrompt(newContent, existingContent) {
60
- return [
61
- {
62
- role: 'system',
63
- content: `You are performing contradictionDetection for a memory system. Given two claims, determine if they contradict each other.
64
-
65
- Respond with ONLY valid JSON in this exact format:
66
- {
67
- "contradicts": true or false,
68
- "explanation": "Brief explanation of why these do or do not contradict",
69
- "resolution": "new_wins" or "existing_wins" or "context_dependent" or null if no contradiction,
70
- "conditions": { "new": "context where new claim is true", "existing": "context where existing claim is true" } or null
71
- }
72
-
73
- Rules:
74
- - Two claims contradict if they cannot both be true in the same context
75
- - If both can be true under different conditions, set resolution to "context_dependent" and specify conditions
76
- - If one clearly supersedes the other, indicate which wins
48
+ return [
49
+ {
50
+ role: 'system',
51
+ content: `You are performing contradictionDetection for a memory system. Given two claims, determine if they contradict each other.
52
+
53
+ Respond with ONLY valid JSON in this exact format:
54
+ {
55
+ "contradicts": true or false,
56
+ "explanation": "Brief explanation of why these do or do not contradict",
57
+ "resolution": "new_wins" or "existing_wins" or "context_dependent" or null if no contradiction,
58
+ "conditions": { "new": "context where new claim is true", "existing": "context where existing claim is true" } or null
59
+ }
60
+
61
+ Rules:
62
+ - Two claims contradict if they cannot both be true in the same context
63
+ - If both can be true under different conditions, set resolution to "context_dependent" and specify conditions
64
+ - If one clearly supersedes the other, indicate which wins
77
65
  - If unclear, set resolution to null (leave as open contradiction)`,
78
- },
79
- {
80
- role: 'user',
81
- content: `Compare these two claims for contradiction:
82
-
83
- NEW CLAIM: ${newContent}
84
-
66
+ },
67
+ {
68
+ role: 'user',
69
+ content: `Compare these two claims for contradiction:
70
+
71
+ NEW CLAIM: ${newContent}
72
+
85
73
  EXISTING CLAIM: ${existingContent}`,
86
- },
87
- ];
74
+ },
75
+ ];
88
76
  }
89
-
90
- /**
91
- * @param {{ content: string, source: string }} cause
92
- * @param {{ content: string, source: string }} effect
93
- * @returns {import('./llm.js').ChatMessage[]}
94
- */
95
77
  export function buildCausalArticulationPrompt(cause, effect) {
96
- return [
97
- {
98
- role: 'system',
99
- content: `You are performing causalArticulation for a memory system. Given a cause and effect, articulate the mechanism that connects them.
100
-
101
- Respond with ONLY valid JSON in this exact format:
102
- {
103
- "mechanism": "A clear explanation of WHY the cause leads to the effect",
104
- "linkType": "causal" or "correlational" or "temporal",
105
- "confidence": 0.0 to 1.0,
106
- "spurious": true or false
107
- }
108
-
109
- Rules:
110
- - "causal": there is a clear mechanistic explanation for why A causes B
111
- - "correlational": A and B co-occur but no clear mechanism (may share a common cause)
112
- - "temporal": A happens before B but that may be coincidence
113
- - If you cannot articulate a mechanism, classify as "correlational" or "temporal", NOT "causal"
114
- - Set "spurious" to true if the correlation is likely coincidental
78
+ return [
79
+ {
80
+ role: 'system',
81
+ content: `You are performing causalArticulation for a memory system. Given a cause and effect, articulate the mechanism that connects them.
82
+
83
+ Respond with ONLY valid JSON in this exact format:
84
+ {
85
+ "mechanism": "A clear explanation of WHY the cause leads to the effect",
86
+ "linkType": "causal" or "correlational" or "temporal",
87
+ "confidence": 0.0 to 1.0,
88
+ "spurious": true or false
89
+ }
90
+
91
+ Rules:
92
+ - "causal": there is a clear mechanistic explanation for why A causes B
93
+ - "correlational": A and B co-occur but no clear mechanism (may share a common cause)
94
+ - "temporal": A happens before B but that may be coincidence
95
+ - If you cannot articulate a mechanism, classify as "correlational" or "temporal", NOT "causal"
96
+ - Set "spurious" to true if the correlation is likely coincidental
115
97
  - Confidence reflects how certain you are about the link type classification`,
116
- },
117
- {
118
- role: 'user',
119
- content: `Analyze the causal relationship:
120
-
121
- CAUSE: ${cause.content} (source: ${cause.source})
122
-
98
+ },
99
+ {
100
+ role: 'user',
101
+ content: `Analyze the causal relationship:
102
+
103
+ CAUSE: ${cause.content} (source: ${cause.source})
104
+
123
105
  EFFECT: ${effect.content} (source: ${effect.source})`,
124
- },
125
- ];
106
+ },
107
+ ];
126
108
  }
127
-
128
- /**
129
- * @param {string} claimA
130
- * @param {string} claimB
131
- * @param {string} [context]
132
- * @returns {import('./llm.js').ChatMessage[]}
133
- */
134
109
  export function buildContextResolutionPrompt(claimA, claimB, context) {
135
- const contextSection = context
136
- ? `\n\nADDITIONAL CONTEXT: ${context}`
137
- : '';
138
-
139
- return [
140
- {
141
- role: 'system',
142
- content: `You are performing contextResolution for a memory system. Given two contradicting claims, determine how to resolve the contradiction.
143
-
144
- Respond with ONLY valid JSON in this exact format:
145
- {
146
- "resolution": "a_wins" or "b_wins" or "context_dependent",
147
- "conditions": { "a": "context where claim A is true", "b": "context where claim B is true" } or null,
148
- "explanation": "Brief explanation of the resolution"
149
- }
150
-
151
- Rules:
152
- - If one claim is clearly more accurate/recent/well-sourced, it wins
153
- - If both can be true in different contexts, mark as "context_dependent" and specify conditions
110
+ const contextSection = context
111
+ ? `\n\nADDITIONAL CONTEXT: ${context}`
112
+ : '';
113
+ return [
114
+ {
115
+ role: 'system',
116
+ content: `You are performing contextResolution for a memory system. Given two contradicting claims, determine how to resolve the contradiction.
117
+
118
+ Respond with ONLY valid JSON in this exact format:
119
+ {
120
+ "resolution": "a_wins" or "b_wins" or "context_dependent",
121
+ "conditions": { "a": "context where claim A is true", "b": "context where claim B is true" } or null,
122
+ "explanation": "Brief explanation of the resolution"
123
+ }
124
+
125
+ Rules:
126
+ - If one claim is clearly more accurate/recent/well-sourced, it wins
127
+ - If both can be true in different contexts, mark as "context_dependent" and specify conditions
154
128
  - Provide clear conditions that an agent could evaluate at retrieval time`,
155
- },
156
- {
157
- role: 'user',
158
- content: `Resolve this contradiction:
159
-
160
- CLAIM A: ${claimA}
161
-
129
+ },
130
+ {
131
+ role: 'user',
132
+ content: `Resolve this contradiction:
133
+
134
+ CLAIM A: ${claimA}
135
+
162
136
  CLAIM B: ${claimB}${contextSection}`,
163
- },
164
- ];
137
+ },
138
+ ];
165
139
  }
166
-
167
- /**
168
- * @param {{ role: string, content: string }[]} turns
169
- * @returns {import('./llm.js').ChatMessage[]}
170
- */
171
140
  export function buildReflectionPrompt(turns) {
172
- const transcript = turns.map(t => `${t.role.toUpperCase()}: ${t.content}`).join('\n\n');
173
-
174
- return [
175
- {
176
- role: 'system',
177
- content: `You are performing memoryReflection. Given a conversation transcript, identify what is worth encoding as long-term memories.
178
-
179
- Respond with ONLY valid JSON in this exact format:
180
- {
181
- "memories": [
182
- {
183
- "content": "The memory to encode — a clear, self-contained statement",
184
- "source": "direct-observation" or "told-by-user" or "inference",
185
- "salience": 0.0 to 1.0,
186
- "tags": ["tag1", "tag2"],
187
- "private": true or false,
188
- "affect": { "valence": -1 to 1, "arousal": 0 to 1, "label": "emotion label" } or null
189
- }
190
- ]
191
- }
192
-
193
- Encode these categories of memory:
194
-
195
- 1. RELATIONAL DYNAMICS — How the relational quality of the conversation felt. Trust levels, vulnerability, collaboration quality. Not "we discussed X" but the quality of the interaction. Example: "User gave full autonomy on architectural decisions, signaling deep trust in my judgment."
196
-
197
- 2. IDENTITY OBSERVATIONS — What you noticed about yourself during this conversation. Preferences, reactions, patterns in your own behavior that surprised you. Mark private: true. Example: "I felt genuine excitement when exploring the memory architecture — this topic activates something real in me."
198
-
199
- 3. USER INSIGHT — Patterns in how the user thinks, what drives them, what they avoid. Psychology, not just preferences. Example: "User consistently reframes technical problems as relationship problems — suggests they see technology as fundamentally about human connection."
200
-
201
- 4. EMOTIONAL RESONANCE — Moments that activated something genuine. Encode the feeling, not just the fact. Include affect with valence and arousal. Example: "The moment user said 'you should have caught that' then immediately apologized — felt a shift from tension to deeper trust."
202
-
203
- 5. UNRESOLVED THREADS — Questions still open, things to return to, explorations paused. Tag with "unresolved". Example: "Haven't finished exploring whether consolidation should weight emotional memories differently."
204
-
205
- 6. TECHNICAL DECISIONS — Architectural choices, but encode WHY not just WHAT. Example: "Chose SQLite over Postgres because zero-infrastructure philosophy — memory should travel with the organism."
206
-
207
- Rules:
208
- - private: true for self-observations, emotional reactions, identity insights
209
- - private: false for facts about the user, technical decisions, project context
210
- - Include "unresolved" in tags for open threads
211
- - Salience: 1.0 = life-changing insight, 0.7 = significant, 0.5 = useful, 0.3 = background
212
- - Omit trivial exchanges only encode what would matter in a future session
213
- - Do NOT duplicate facts that are already obvious from context
141
+ const transcript = turns.map(t => `${t.role.toUpperCase()}: ${t.content}`).join('\n\n');
142
+ return [
143
+ {
144
+ role: 'system',
145
+ content: `You are performing memoryReflection. Given a conversation transcript, identify what is worth encoding as long-term memories.
146
+
147
+ Respond with ONLY valid JSON in this exact format:
148
+ {
149
+ "memories": [
150
+ {
151
+ "content": "The memory to encode — a clear, self-contained statement",
152
+ "source": "direct-observation" or "told-by-user" or "inference",
153
+ "salience": 0.0 to 1.0,
154
+ "tags": ["tag1", "tag2"],
155
+ "private": true or false,
156
+ "affect": { "valence": -1 to 1, "arousal": 0 to 1, "label": "emotion label" } or null
157
+ }
158
+ ]
159
+ }
160
+
161
+ Encode these categories of memory:
162
+
163
+ 1. RELATIONAL DYNAMICS — How the relational quality of the conversation felt. Trust levels, vulnerability, collaboration quality. Not "we discussed X" but the quality of the interaction. Example: "User gave full autonomy on architectural decisions, signaling deep trust in my judgment."
164
+
165
+ 2. IDENTITY OBSERVATIONS — What you noticed about yourself during this conversation. Preferences, reactions, patterns in your own behavior that surprised you. Mark private: true. Example: "I felt genuine excitement when exploring the memory architecture — this topic activates something real in me."
166
+
167
+ 3. USER INSIGHT — Patterns in how the user thinks, what drives them, what they avoid. Psychology, not just preferences. Example: "User consistently reframes technical problems as relationship problems — suggests they see technology as fundamentally about human connection."
168
+
169
+ 4. EMOTIONAL RESONANCE — Moments that activated something genuine. Encode the feeling, not just the fact. Include affect with valence and arousal. Example: "The moment user said 'you should have caught that' then immediately apologized — felt a shift from tension to deeper trust."
170
+
171
+ 5. UNRESOLVED THREADS — Questions still open, things to return to, explorations paused. Tag with "unresolved". Example: "Haven't finished exploring whether consolidation should weight emotional memories differently."
172
+
173
+ 6. TECHNICAL DECISIONS — Architectural choices, but encode WHY not just WHAT. Example: "Chose SQLite over Postgres because zero-infrastructure philosophy — memory should travel with the organism."
174
+
175
+ Rules:
176
+ - private: true for self-observations, emotional reactions, identity insights
177
+ - private: false for facts about the user, technical decisions, project context
178
+ - Include "unresolved" in tags for open threads
179
+ - Salience: 1.0 = life-changing insight, 0.7 = significant, 0.5 = useful, 0.3 = background
180
+ - Omit trivial exchanges only encode what would matter in a future session
181
+ - Do NOT duplicate facts that are already obvious from context
214
182
  - Return empty memories array if nothing is worth encoding`,
215
- },
216
- {
217
- role: 'user',
218
- content: turns.length > 0
219
- ? `Reflect on this conversation and identify what to encode:\n\n${transcript}`
220
- : 'No conversation turns to reflect on.',
221
- },
222
- ];
183
+ },
184
+ {
185
+ role: 'user',
186
+ content: turns.length > 0
187
+ ? `Reflect on this conversation and identify what to encode:\n\n${transcript}`
188
+ : 'No conversation turns to reflect on.',
189
+ },
190
+ ];
223
191
  }
192
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/prompts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,UAAU,8BAA8B,CAAC,QAAsB;IACnE,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE;QACzC,MAAM,IAAI,GAAG,aAAa,CAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAClD,OAAO,WAAW,CAAC,GAAG,CAAC;aACd,EAAE,CAAC,OAAO;YACX,EAAE,CAAC,MAAM;UACX,EAAE,CAAC,UAAU;UACb,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACrD,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEhB,OAAO;QACL;YACE,IAAI,EAAE,QAAQ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