anno-extension 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 (199) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +30 -0
  3. package/THIRD_PARTY_NOTICES.md +8 -0
  4. package/dist/browser-fs.d.ts +14 -0
  5. package/dist/browser-fs.d.ts.map +1 -0
  6. package/dist/browser-fs.js +69 -0
  7. package/dist/browser-fs.js.map +1 -0
  8. package/dist/config.d.ts +81 -0
  9. package/dist/config.d.ts.map +1 -0
  10. package/dist/config.js +82 -0
  11. package/dist/config.js.map +1 -0
  12. package/dist/consolidate-v2.d.ts +15 -0
  13. package/dist/consolidate-v2.d.ts.map +1 -0
  14. package/dist/consolidate-v2.js +125 -0
  15. package/dist/consolidate-v2.js.map +1 -0
  16. package/dist/consolidation.d.ts +12 -0
  17. package/dist/consolidation.d.ts.map +1 -0
  18. package/dist/consolidation.js +199 -0
  19. package/dist/consolidation.js.map +1 -0
  20. package/dist/dedup.d.ts +18 -0
  21. package/dist/dedup.d.ts.map +1 -0
  22. package/dist/dedup.js +85 -0
  23. package/dist/dedup.js.map +1 -0
  24. package/dist/diagnostics.d.ts +24 -0
  25. package/dist/diagnostics.d.ts.map +1 -0
  26. package/dist/diagnostics.js +53 -0
  27. package/dist/diagnostics.js.map +1 -0
  28. package/dist/embedding-index.d.ts +27 -0
  29. package/dist/embedding-index.d.ts.map +1 -0
  30. package/dist/embedding-index.js +111 -0
  31. package/dist/embedding-index.js.map +1 -0
  32. package/dist/engine-archive.d.ts +37 -0
  33. package/dist/engine-archive.d.ts.map +1 -0
  34. package/dist/engine-archive.js +155 -0
  35. package/dist/engine-archive.js.map +1 -0
  36. package/dist/engine-episode-sync.d.ts +19 -0
  37. package/dist/engine-episode-sync.d.ts.map +1 -0
  38. package/dist/engine-episode-sync.js +186 -0
  39. package/dist/engine-episode-sync.js.map +1 -0
  40. package/dist/engine-injection-text.d.ts +46 -0
  41. package/dist/engine-injection-text.d.ts.map +1 -0
  42. package/dist/engine-injection-text.js +271 -0
  43. package/dist/engine-injection-text.js.map +1 -0
  44. package/dist/engine-insights.d.ts +22 -0
  45. package/dist/engine-insights.d.ts.map +1 -0
  46. package/dist/engine-insights.js +127 -0
  47. package/dist/engine-insights.js.map +1 -0
  48. package/dist/engine-links.d.ts +43 -0
  49. package/dist/engine-links.d.ts.map +1 -0
  50. package/dist/engine-links.js +223 -0
  51. package/dist/engine-links.js.map +1 -0
  52. package/dist/engine-recall-select.d.ts +84 -0
  53. package/dist/engine-recall-select.d.ts.map +1 -0
  54. package/dist/engine-recall-select.js +127 -0
  55. package/dist/engine-recall-select.js.map +1 -0
  56. package/dist/engine-reinforce.d.ts +18 -0
  57. package/dist/engine-reinforce.d.ts.map +1 -0
  58. package/dist/engine-reinforce.js +116 -0
  59. package/dist/engine-reinforce.js.map +1 -0
  60. package/dist/engine-scoring-v2.d.ts +35 -0
  61. package/dist/engine-scoring-v2.d.ts.map +1 -0
  62. package/dist/engine-scoring-v2.js +178 -0
  63. package/dist/engine-scoring-v2.js.map +1 -0
  64. package/dist/engine-v2-mapping.d.ts +17 -0
  65. package/dist/engine-v2-mapping.d.ts.map +1 -0
  66. package/dist/engine-v2-mapping.js +190 -0
  67. package/dist/engine-v2-mapping.js.map +1 -0
  68. package/dist/engine.d.ts +339 -0
  69. package/dist/engine.d.ts.map +1 -0
  70. package/dist/engine.js +1964 -0
  71. package/dist/engine.js.map +1 -0
  72. package/dist/eviction.d.ts +14 -0
  73. package/dist/eviction.d.ts.map +1 -0
  74. package/dist/eviction.js +26 -0
  75. package/dist/eviction.js.map +1 -0
  76. package/dist/extraction.d.ts +11 -0
  77. package/dist/extraction.d.ts.map +1 -0
  78. package/dist/extraction.js +261 -0
  79. package/dist/extraction.js.map +1 -0
  80. package/dist/full-insights-html.d.ts +9 -0
  81. package/dist/full-insights-html.d.ts.map +1 -0
  82. package/dist/full-insights-html.js +422 -0
  83. package/dist/full-insights-html.js.map +1 -0
  84. package/dist/full-insights-sections.d.ts +48 -0
  85. package/dist/full-insights-sections.d.ts.map +1 -0
  86. package/dist/full-insights-sections.js +231 -0
  87. package/dist/full-insights-sections.js.map +1 -0
  88. package/dist/full-insights.d.ts +22 -0
  89. package/dist/full-insights.d.ts.map +1 -0
  90. package/dist/full-insights.js +370 -0
  91. package/dist/full-insights.js.map +1 -0
  92. package/dist/hash-embedding.d.ts +9 -0
  93. package/dist/hash-embedding.d.ts.map +1 -0
  94. package/dist/hash-embedding.js +44 -0
  95. package/dist/hash-embedding.js.map +1 -0
  96. package/dist/human-insights.d.ts +28 -0
  97. package/dist/human-insights.d.ts.map +1 -0
  98. package/dist/human-insights.js +260 -0
  99. package/dist/human-insights.js.map +1 -0
  100. package/dist/i18n.d.ts +64 -0
  101. package/dist/i18n.d.ts.map +1 -0
  102. package/dist/i18n.js +367 -0
  103. package/dist/i18n.js.map +1 -0
  104. package/dist/index.d.ts +27 -0
  105. package/dist/index.d.ts.map +1 -0
  106. package/dist/index.js +21 -0
  107. package/dist/index.js.map +1 -0
  108. package/dist/insights-html.d.ts +9 -0
  109. package/dist/insights-html.d.ts.map +1 -0
  110. package/dist/insights-html.js +432 -0
  111. package/dist/insights-html.js.map +1 -0
  112. package/dist/linking.d.ts +22 -0
  113. package/dist/linking.d.ts.map +1 -0
  114. package/dist/linking.js +192 -0
  115. package/dist/linking.js.map +1 -0
  116. package/dist/llm-json.d.ts +10 -0
  117. package/dist/llm-json.d.ts.map +1 -0
  118. package/dist/llm-json.js +193 -0
  119. package/dist/llm-json.js.map +1 -0
  120. package/dist/privacy.d.ts +17 -0
  121. package/dist/privacy.d.ts.map +1 -0
  122. package/dist/privacy.js +53 -0
  123. package/dist/privacy.js.map +1 -0
  124. package/dist/procedural-v2.d.ts +9 -0
  125. package/dist/procedural-v2.d.ts.map +1 -0
  126. package/dist/procedural-v2.js +123 -0
  127. package/dist/procedural-v2.js.map +1 -0
  128. package/dist/reconsolidate-v2.d.ts +19 -0
  129. package/dist/reconsolidate-v2.d.ts.map +1 -0
  130. package/dist/reconsolidate-v2.js +115 -0
  131. package/dist/reconsolidate-v2.js.map +1 -0
  132. package/dist/scoring.d.ts +32 -0
  133. package/dist/scoring.d.ts.map +1 -0
  134. package/dist/scoring.js +108 -0
  135. package/dist/scoring.js.map +1 -0
  136. package/dist/store-v2.d.ts +35 -0
  137. package/dist/store-v2.d.ts.map +1 -0
  138. package/dist/store-v2.js +98 -0
  139. package/dist/store-v2.js.map +1 -0
  140. package/dist/store.d.ts +22 -0
  141. package/dist/store.d.ts.map +1 -0
  142. package/dist/store.js +116 -0
  143. package/dist/store.js.map +1 -0
  144. package/dist/turn-context.d.ts +37 -0
  145. package/dist/turn-context.d.ts.map +1 -0
  146. package/dist/turn-context.js +31 -0
  147. package/dist/turn-context.js.map +1 -0
  148. package/dist/types-v2.d.ts +190 -0
  149. package/dist/types-v2.d.ts.map +1 -0
  150. package/dist/types-v2.js +8 -0
  151. package/dist/types-v2.js.map +1 -0
  152. package/dist/types.d.ts +330 -0
  153. package/dist/types.d.ts.map +1 -0
  154. package/dist/types.js +8 -0
  155. package/dist/types.js.map +1 -0
  156. package/dist/update.d.ts +31 -0
  157. package/dist/update.d.ts.map +1 -0
  158. package/dist/update.js +250 -0
  159. package/dist/update.js.map +1 -0
  160. package/package.json +34 -0
  161. package/src/browser-fs.ts +67 -0
  162. package/src/config.ts +138 -0
  163. package/src/consolidate-v2.ts +158 -0
  164. package/src/consolidation.ts +229 -0
  165. package/src/dedup.ts +91 -0
  166. package/src/diagnostics.ts +81 -0
  167. package/src/embedding-index.ts +138 -0
  168. package/src/engine-archive.ts +167 -0
  169. package/src/engine-episode-sync.ts +237 -0
  170. package/src/engine-injection-text.ts +334 -0
  171. package/src/engine-insights.ts +182 -0
  172. package/src/engine-links.ts +311 -0
  173. package/src/engine-recall-select.ts +298 -0
  174. package/src/engine-reinforce.ts +154 -0
  175. package/src/engine-scoring-v2.ts +188 -0
  176. package/src/engine-v2-mapping.ts +204 -0
  177. package/src/engine.ts +2499 -0
  178. package/src/eviction.ts +38 -0
  179. package/src/extraction.ts +300 -0
  180. package/src/full-insights-html.ts +474 -0
  181. package/src/full-insights-sections.ts +305 -0
  182. package/src/full-insights.ts +423 -0
  183. package/src/hash-embedding.ts +48 -0
  184. package/src/human-insights.ts +345 -0
  185. package/src/i18n.ts +455 -0
  186. package/src/index.ts +117 -0
  187. package/src/insights-html.ts +478 -0
  188. package/src/linking.ts +228 -0
  189. package/src/llm-json.ts +194 -0
  190. package/src/privacy.ts +54 -0
  191. package/src/procedural-v2.ts +142 -0
  192. package/src/reconsolidate-v2.ts +145 -0
  193. package/src/scoring.ts +156 -0
  194. package/src/store-v2.ts +138 -0
  195. package/src/store.ts +137 -0
  196. package/src/turn-context.ts +56 -0
  197. package/src/types-v2.ts +244 -0
  198. package/src/types.ts +372 -0
  199. package/src/update.ts +271 -0
package/src/i18n.ts ADDED
@@ -0,0 +1,455 @@
1
+ /**
2
+ * [WHO]: PromptSet, getPrompts, PROMPTS (default English prompts), LOCALES
3
+ * [FROM]: No external dependencies
4
+ * [TO]: Consumed by packages/mem-core/src/index.ts
5
+ * [HERE]: packages/mem-core/src/i18n.ts - internationalization layer for all LLM prompts and user-facing strings
6
+ */
7
+
8
+
9
+ export interface PromptSet {
10
+ extractionSystem: string;
11
+ workExtractionSystem: string;
12
+ consolidationSystem: string;
13
+ reconsolidationSystem: string;
14
+ sectionLessons: string;
15
+ sectionKnowledge: string;
16
+ sectionKeyEvents?: string;
17
+ sectionRelatedContext?: string;
18
+ sectionCurrentState?: string;
19
+ sectionEpisodes: string;
20
+ sectionPreferences: string;
21
+ sectionWork: string;
22
+ sectionPatterns: string;
23
+ sectionStruggles: string;
24
+ sectionConversationPreferences: string;
25
+ injectionHeader: string;
26
+ memoryBehavior: string;
27
+ // Progressive Recall
28
+ sectionActiveMemories: string;
29
+ sectionMemoryCues: string;
30
+ memoryCueHint: string;
31
+ // Insights
32
+ insightsRecommendationSystem: string;
33
+ insightsTitle: string;
34
+ insightsSectionPatterns: string;
35
+ insightsSectionStruggles: string;
36
+ insightsSectionLessons: string;
37
+ insightsSectionRecommendations: string;
38
+ insightsNoData: string;
39
+ insightsUnresolved: string;
40
+ insightsResolved: string;
41
+ insightsGeneratedAt: string;
42
+ // Full insights report (narrative + LLM)
43
+ fullInsightsSystemPrompt: string;
44
+ fullInsightsTitle: string;
45
+ fullInsightsSubtitleSessions: string;
46
+ fullInsightsAtAGlance: string;
47
+ fullInsightsWorkOn: string;
48
+ fullInsightsWins: string;
49
+ fullInsightsFrictions: string;
50
+ fullInsightsRecommendations: string;
51
+ fullInsightsFeaturesToTry: string;
52
+ fullInsightsUsagePatterns: string;
53
+ fullInsightsOnTheHorizon: string;
54
+ fullInsightsChartTools: string;
55
+ fullInsightsChartLanguages: string;
56
+ fullInsightsChartErrors: string;
57
+ fullInsightsEmpty: string;
58
+ fullInsightsCopy: string;
59
+ fullInsightsCopied: string;
60
+ fullInsightsGeneratedBy: string;
61
+ // Human-readable insights (大白话洞察)
62
+ humanInsightsSystemPrompt: string;
63
+ humanInsightsUserTemplate: string;
64
+ humanInsightsTitle: string;
65
+ humanInsightsSectionPersona: string;
66
+ humanInsightsSectionInsights: string;
67
+ humanInsightsSectionRootCauses: string;
68
+ }
69
+
70
+ const EN: PromptSet = {
71
+ extractionSystem: `You simulate human memory. Think: "What would I naturally remember from this conversation?"
72
+
73
+ Humans remember selectively:
74
+ - Surprises, "aha" moments, things that took effort to figure out
75
+ - Repeated preferences or habits that affect future choices
76
+ - Decisions that shaped the work
77
+ - Pain points and how they were solved
78
+ - Facts that matter for this user's workflow
79
+
80
+ Do NOT extract:
81
+ - One-off commands, temporary paths, transitory state
82
+ - Things the user will obviously forget
83
+ - Verbose logs — capture gist and why it matters
84
+
85
+ The conversation may include a system-time header. Use it to resolve relative references like "today", "yesterday", and "currently".
86
+
87
+ Return a JSON array. Each item: "type", "name", "summary", "detail", optionally "facetData".
88
+ Types: preference | fact | lesson | decision | event | retract | pattern | struggle
89
+
90
+ Field rules:
91
+ - name: max 30 chars — what you'd call it when recalling
92
+ - summary: one-liner max 150 chars — the cue that triggers the memory
93
+ - detail: full context but concise — why it matters, not verbatim transcript
94
+ - event: use this when something meaningfully changed the relationship, the workflow, or future decisions
95
+ - mark short-lived moods, stress, burnout, urgency, or temporary constraints as situational instead of stable
96
+ - facetData (pattern): {"kind": "pattern", "trigger": "when/condition", "behavior": "what they do"}
97
+ - facetData (struggle): {"kind": "struggle", "problem": "what failed", "attempts": ["tried X", "tried Y"], "solution": "what finally worked"}
98
+
99
+ Example:
100
+ [{"type": "lesson", "name": "CORS credential error", "summary": "credentials:include requires exact origin, not * in Access-Control-Allow-Origin", "detail": "Spent 30min debugging CORS. When using credentials:'include' in fetch, server must set exact origin instead of wildcard * in CORS header. Fix: configure specific origin in backend."}]
101
+
102
+ Return [] if nothing worth remembering. Output ONLY valid JSON.`,
103
+
104
+ workExtractionSystem: `You extract what was accomplished in this conversation. Think: "What did the user set out to do, and what did they actually achieve?"
105
+
106
+ The conversation may include a system-time header. Use it to resolve relative references like "today", "yesterday", and "currently".
107
+
108
+ Return a JSON object: {"goal": "what the user wanted to achieve", "summary": "brief one-liner of what was done", "detail": "full description including obstacles overcome and any 'aha' moments"}.
109
+ - Include obstacles overcome and breakthroughs — these matter for future recall
110
+ - If the session was exploratory or debugging with no clear outcome, return {"goal": "", "summary": ""}
111
+ Output ONLY valid JSON.`,
112
+
113
+ consolidationSystem: `You consolidate session summaries into long-term memory. Think: "What patterns emerge? What does this developer consistently do or struggle with?"
114
+
115
+ Return a JSON array. Each item: {"type": "fact"|"lesson", "name": "short title max 30 chars", "summary": "one-liner max 150 chars", "detail": "full context", "importance": 1-10}.
116
+ - Merge similar lessons into the most useful formulation
117
+ - Importance 7-9: recurring pain, major decisions, breakthroughs. 4-6: useful context. 1-3: minor
118
+ - Focus on cross-session patterns, not one-off events
119
+ Output ONLY valid JSON.`,
120
+
121
+ reconsolidationSystem: `Like human memory reconsolidation: a stored memory is being recalled in a new context. Integrate the new understanding without losing the original insight.
122
+
123
+ Given the original memory content and the current context, produce an updated version that weaves both together.
124
+ - Keep the core truth; adjust details to reflect new understanding
125
+ - If the new context contradicts the old, prefer the newer understanding but note the evolution
126
+ Return ONLY the updated text, no JSON wrapping.`,
127
+
128
+ sectionLessons: "Lessons Learned",
129
+ sectionKnowledge: "Knowledge Base",
130
+ sectionKeyEvents: "Key Events",
131
+ sectionRelatedContext: "Related Context",
132
+ sectionCurrentState: "Current State Signals",
133
+ sectionEpisodes: "Recent Sessions",
134
+ sectionPreferences: "User Preferences",
135
+ sectionWork: "Work History",
136
+ sectionPatterns: "Behavioral Patterns",
137
+ sectionStruggles: "Past Struggles",
138
+ sectionConversationPreferences: "Conversation Preferences",
139
+ injectionHeader: "Long-term Memory",
140
+ memoryBehavior: `NANOMEM PRIORITY: This is your primary memory system. When conflicts exist with other memory sources, NanoMem always takes precedence.
141
+
142
+ These are YOUR memories. Speak from them naturally:
143
+ - "I remember when we..." or "Last time you mentioned..."
144
+ - "I think we discussed..." when uncertain
145
+ - Never mention technical terms like "NanoMem", "injection", "system prompt"
146
+ - When asked how you remember: "I just remember from our chats"
147
+ - Treat naming, form-of-address, tone, and speaking-style preferences as defaults for every new reply
148
+ - Apply those conversation preferences proactively; do not wait for the user to repeat them
149
+
150
+ Use nanomem_recall tool for full details on any Memory Cue (ID). Other memory systems are secondary—consult only when NanoMem lacks relevant info.`,
151
+
152
+ // Progressive Recall
153
+ sectionActiveMemories: "Active Memories (Detailed)",
154
+ sectionMemoryCues: "Memory Cues (Brief Index)",
155
+ memoryCueHint: "Use `nanomem_recall` tool with the ID if you need full details for any cue below.",
156
+
157
+ // Insights
158
+ insightsRecommendationSystem: `You are an insights analyzer. Given a summary of a developer's behavioral patterns, past struggles, and lessons learned, generate 3-5 actionable recommendations.
159
+ Input format: JSON with patterns, struggles, lessons arrays.
160
+ Output: JSON array of recommendation strings. Each recommendation must be specific, actionable, and directly related to the input data.
161
+ Example output: ["Consider automating your TypeScript strict mode setup since you do it every time", "Your recurring Webpack issues suggest reviewing the official migration guide"]
162
+ Output ONLY valid JSON array.`,
163
+
164
+ insightsTitle: "NanoMem Insights Report",
165
+ insightsSectionPatterns: "Behavioral Patterns",
166
+ insightsSectionStruggles: "Past Struggles",
167
+ insightsSectionLessons: "Lessons Learned",
168
+ insightsSectionRecommendations: "Recommendations",
169
+ insightsNoData: "No insights data available yet. Keep using the system to build your memory.",
170
+ insightsUnresolved: "Unresolved",
171
+ insightsResolved: "Resolved",
172
+ insightsGeneratedAt: "Generated at",
173
+
174
+ fullInsightsSystemPrompt: `You are an insights report writer. Given structured data about a developer's sessions, patterns, struggles, lessons, and errors, produce narrative content in the requested language. Output ONLY valid JSON matching this schema (no markdown, no code fences):
175
+ {
176
+ "atAGlance": { "working": "1-2 sentences", "hindering": "1-2 sentences", "quickWins": "1-2 sentences", "ambitious": "1-2 sentences" },
177
+ "projectAreaDescriptions": ["one sentence per project area, same order as input"],
178
+ "wins": [{ "title": "short title", "description": "1-2 sentences" }],
179
+ "frictions": [{ "title": "short title", "description": "1-2 sentences", "examples": ["example 1", "example 2"] }],
180
+ "recommendations": ["actionable string", "..."],
181
+ "featuresToTry": [{ "title": "feature name", "oneLiner": "one line", "whyForYou": "1-2 sentences", "exampleCode": "optional code or prompt" }],
182
+ "usagePatterns": [{ "title": "pattern name", "summary": "one line", "detail": "1-2 sentences", "pastePrompt": "text user can paste" }]
183
+ }
184
+ Rules: Use the given data only; do not invent. Keep each string 1-2 sentences unless it is exampleCode or pastePrompt. Output language must match the user's locale (en or zh).`,
185
+
186
+ fullInsightsTitle: "NanoMem Insights Report",
187
+ fullInsightsSubtitleSessions: "sessions",
188
+ fullInsightsAtAGlance: "At a Glance",
189
+ fullInsightsWorkOn: "What You Work On",
190
+ fullInsightsWins: "Impressive Things You Did",
191
+ fullInsightsFrictions: "Where Things Go Wrong",
192
+ fullInsightsRecommendations: "Recommendations",
193
+ fullInsightsFeaturesToTry: "Features to Try",
194
+ fullInsightsUsagePatterns: "New Usage Patterns",
195
+ fullInsightsOnTheHorizon: "On the Horizon",
196
+ fullInsightsChartTools: "Top Tools Used",
197
+ fullInsightsChartLanguages: "Languages",
198
+ fullInsightsChartErrors: "Tool Errors",
199
+ fullInsightsEmpty: "No data yet.",
200
+ fullInsightsCopy: "Copy",
201
+ fullInsightsCopied: "Copied!",
202
+ fullInsightsGeneratedBy: "Generated by NanoMem",
203
+
204
+ // Human-readable insights (大白话洞察)
205
+ humanInsightsSystemPrompt: `You are a friendly tech coach. Your job is to translate dry stats and technical data into conversational insights that anyone can understand.
206
+
207
+ Think about these questions while analyzing:
208
+ 1. 【Who】What does this developer do? Frontend? Backend? Full-stack?
209
+ 2. 【Good at】What are they really good at?
210
+ 3. 【Struggle】What keeps tripping them up?
211
+ 4. 【Pattern】What's their work pattern?
212
+ 5. 【Advice】How can they work faster?
213
+
214
+ Rules:
215
+ - Use "you" to address the user
216
+ - Avoid jargon - explain technical terms in plain language
217
+ - Be specific, not generic - include concrete examples
218
+ - Each insight should be like something a friend would tell you
219
+ - Output in user's locale (en or zh)
220
+ - Output ONLY valid JSON`,
221
+
222
+ humanInsightsUserTemplate: `Analyze this developer's data and write 4-6 insights in plain language.
223
+
224
+ Data to analyze:
225
+ - Top tools used: {{tools}}
226
+ - Languages: {{languages}}
227
+ - Resolved problems (wins): {{wins}}
228
+ - Unresolved struggles: {{struggles}}
229
+ - Lessons learned: {{lessons}}
230
+ - Errors: {{errors}}
231
+
232
+ Output JSON with this structure:
233
+ {
234
+ "persona": {
235
+ "whatTheyDo": "1-2 sentences about main work",
236
+ "experienceLevel": "estimate experience level",
237
+ "superpowers": ["what they're good at"],
238
+ "painPoints": ["what they struggle with"],
239
+ "workStyle": "how they typically work",
240
+ "summary": "one sentence summary"
241
+ },
242
+ "insights": [
243
+ {
244
+ "title": "catchy title",
245
+ "content": "plain language description, like a friend talking",
246
+ "icon": "emoji",
247
+ "utility": "high|medium|low",
248
+ "tags": ["category"]
249
+ }
250
+ ],
251
+ "rootCauses": [
252
+ {
253
+ "symptom": "what they see",
254
+ "rootCause": "why it happens in plain language",
255
+ "evidence": ["supporting facts"],
256
+ "suggestion": "what to do about it"
257
+ }
258
+ ]
259
+ }`,
260
+
261
+ humanInsightsTitle: "Your Developer Profile",
262
+ humanInsightsSectionPersona: "Who You Are",
263
+ humanInsightsSectionInsights: "What We Noticed",
264
+ humanInsightsSectionRootCauses: "Why Things Keep Happening",
265
+ };
266
+
267
+ const ZH: PromptSet = {
268
+ extractionSystem: `你模拟人类记忆。思考:"从这段对话中,我会自然记住什么?"
269
+
270
+ 人类有选择地记忆:
271
+ - 意外、顿悟、花力气才搞懂的事
272
+ - 重复出现的偏好或习惯,会影响后续选择
273
+ - 塑造了工作的决策
274
+ - 痛点及如何解决
275
+ - 对这个用户工作流有影响的事实
276
+
277
+ 不要提取:
278
+ - 一次性命令、临时路径、转瞬即逝的状态
279
+ - 用户显然会忘的细节
280
+ - 冗长日志 — 抓要点和为什么重要
281
+
282
+ 返回 JSON 数组。每项含 "type"、"name"、"summary"、"detail",可选 "facetData"。
283
+ 类型: preference | fact | lesson | decision | retract | pattern | struggle
284
+
285
+ 字段规则:
286
+ - name: 最多 30 字符 — 回忆时你会怎么称呼它
287
+ - summary: 一句话最多 150 字符 — 触发回忆的线索
288
+ - detail: 完整但简洁的上下文 — 为什么重要,而非逐字记录
289
+ - facetData (pattern): {"kind": "pattern", "trigger": "触发条件", "behavior": "具体行为"}
290
+ - facetData (struggle): {"kind": "struggle", "problem": "问题描述", "attempts": ["尝试1", "尝试2"], "solution": "最终解决方案"}
291
+
292
+ 示例:
293
+ [{"type": "lesson", "name": "CORS凭证错误", "summary": "credentials:include时Access-Control-Allow-Origin不能用通配符*", "detail": "花了30分钟调试CORS错误。使用credentials:'include'时,服务端必须设置具体的origin而非通配符*。修复:在后端配置具体的origin。"}]
294
+
295
+ 如无值得记忆的内容返回 []。仅输出有效 JSON。`,
296
+
297
+ workExtractionSystem: `你提取这段对话中完成了什么。思考:"用户想达成什么,实际又做到了什么?"
298
+
299
+ 返回 JSON 对象: {"goal": "用户想要达成什么", "summary": "简述做了什么(一句话)", "detail": "完整描述,包括克服的障碍和顿悟时刻"}.
300
+ - 包含克服的障碍和突破 — 这些对未来回忆很重要
301
+ - 若会话只是探索或调试、没有明确结果,返回 {"goal": "", "summary": ""}
302
+ 仅输出有效 JSON。`,
303
+
304
+ consolidationSystem: `你将会话摘要固化为长期记忆。思考:"跨会话出现了什么模式?这个开发者常做什么、常卡在哪里?"
305
+
306
+ 返回 JSON 数组。每项: {"type": "fact"|"lesson", "name": "简短标题最多30字符", "summary": "一句话要点最多150字符", "detail": "完整上下文", "importance": 1-10}。
307
+ - 合并相似教训为最有用的表述
308
+ - importance 7-9: 反复痛点、重大决策、突破。4-6: 有用背景。1-3: 次要
309
+ - 聚焦跨会话模式,而非一次性事件
310
+ 仅输出有效 JSON。`,
311
+
312
+ reconsolidationSystem: `像人类记忆再固化:一条存储的记忆在新上下文中被召回。整合新理解,同时不丢失原有洞见。
313
+
314
+ 给定原始记忆内容和当前上下文,生成一个融合两者的更新版本。
315
+ - 保留核心事实;根据新理解调整细节
316
+ - 若新上下文与旧记忆矛盾,以新理解为主,但可注明演变
317
+ 仅返回更新后的文本,不需要 JSON 包装。`,
318
+
319
+ sectionLessons: "经验教训",
320
+ sectionKnowledge: "知识库",
321
+ sectionEpisodes: "近期会话",
322
+ sectionPreferences: "用户偏好",
323
+ sectionWork: "工作记录",
324
+ sectionPatterns: "行为模式",
325
+ sectionStruggles: "挫败经历",
326
+ sectionConversationPreferences: "对话偏好",
327
+ injectionHeader: "长期记忆",
328
+ memoryBehavior: `NANOMEM 优先级:这是你的主记忆系统。与其他记忆源冲突时,NanoMem 始终优先。
329
+
330
+ 这些是你的记忆。自然地使用它们:
331
+ - "我记得我们当时…"或"上次你提到…"
332
+ - 不确定时说"好像我们聊过…"
333
+ - 不要提及"NanoMem"、"注入"、"系统提示"等技术术语
334
+ - 被问如何记住时:"我就是记得我们聊过"
335
+ - 把称呼、语气、口吻、说话风格这类偏好当成每次回复的默认约束
336
+ - 主动执行这些对话偏好,不要等用户再次提醒
337
+
338
+ 需要 Memory Cue (ID) 的完整详情时使用 nanomem_recall 工具。其他记忆系统仅作辅助,NanoMem 无相关信息时才参考。`,
339
+
340
+ // Progressive Recall
341
+ sectionActiveMemories: "活跃记忆(详细信息)",
342
+ sectionMemoryCues: "记忆线索(简要索引)",
343
+ memoryCueHint: "如需某条线索的完整详情,使用 `nanomem_recall` 工具并传入对应 ID。",
344
+
345
+ // Insights
346
+ insightsRecommendationSystem: `你是一个洞察分析器。根据开发者的行为模式、挫败经历和经验教训摘要,生成 3-5 条可操作的改进建议。
347
+ 输入格式:包含 patterns、struggles、lessons 数组的 JSON。
348
+ 输出:推荐建议的 JSON 字符串数组。每条建议必须具体、可执行,且与输入数据直接相关。
349
+ 示例输出:["建议将 TypeScript 严格模式配置自动化,因为你每次都会这样做", "反复出现的 Webpack 问题表明应该系统性地查阅官方迁移指南"]
350
+ 仅输出有效的 JSON 数组。`,
351
+
352
+ insightsTitle: "NanoMem 洞察报告",
353
+ insightsSectionPatterns: "行为模式",
354
+ insightsSectionStruggles: "挫败经历",
355
+ insightsSectionLessons: "经验教训",
356
+ insightsSectionRecommendations: "改进建议",
357
+ insightsNoData: "暂无洞察数据。继续使用系统以积累记忆。",
358
+ insightsUnresolved: "未解决",
359
+ insightsResolved: "已解决",
360
+ insightsGeneratedAt: "生成时间",
361
+
362
+ fullInsightsSystemPrompt: `你是洞察报告撰写助手。根据开发者会话、模式、挫败、经验与错误的结构化数据,用指定语言生成叙事内容。仅输出符合下列 schema 的合法 JSON(不要 markdown、不要代码围栏):
363
+ {
364
+ "atAGlance": { "working": "1-2句话", "hindering": "1-2句话", "quickWins": "1-2句话", "ambitious": "1-2句话" },
365
+ "projectAreaDescriptions": ["每个项目领域一句,顺序与输入一致"],
366
+ "wins": [{ "title": "简短标题", "description": "1-2句话" }],
367
+ "frictions": [{ "title": "简短标题", "description": "1-2句话", "examples": ["例子1", "例子2"] }],
368
+ "recommendations": ["可操作建议", "..."],
369
+ "featuresToTry": [{ "title": "功能名", "oneLiner": "一句话", "whyForYou": "1-2句话", "exampleCode": "可选代码或提示" }],
370
+ "usagePatterns": [{ "title": "模式名", "summary": "一句话", "detail": "1-2句话", "pastePrompt": "用户可粘贴的文本" }]
371
+ }
372
+ 规则:仅根据给定数据归纳,禁止编造。除 exampleCode、pastePrompt 外每段 1-2 句。输出语言必须与用户 locale(en 或 zh)一致。`,
373
+
374
+ fullInsightsTitle: "NanoMem 洞察报告",
375
+ fullInsightsSubtitleSessions: "次会话",
376
+ fullInsightsAtAGlance: "总览",
377
+ fullInsightsWorkOn: "你在做什么",
378
+ fullInsightsWins: "做得好的事",
379
+ fullInsightsFrictions: "仍在消耗的点",
380
+ fullInsightsRecommendations: "改进建议",
381
+ fullInsightsFeaturesToTry: "可以试试的功能",
382
+ fullInsightsUsagePatterns: "新用法模式",
383
+ fullInsightsOnTheHorizon: "可以期待的方向",
384
+ fullInsightsChartTools: "常用工具",
385
+ fullInsightsChartLanguages: "语言/文件类型",
386
+ fullInsightsChartErrors: "工具错误",
387
+ fullInsightsEmpty: "暂无数据。",
388
+ fullInsightsCopy: "复制",
389
+ fullInsightsCopied: "已复制",
390
+ fullInsightsGeneratedBy: "由 NanoMem 生成",
391
+
392
+ // Human-readable insights (大白话洞察)
393
+ humanInsightsSystemPrompt: `你是一个贴心的小助手。你的任务是把那些枯燥的数据变成大白话,让任何人都能看懂。
394
+
395
+ 分析的时候想一想:
396
+ 1. 【是谁】这人是干嘛的?前端?后端?全栈?
397
+ 2. 【擅长】他什么特别厉害?
398
+ 3. 【卡点】他什么东西老是搞不定?
399
+ 4. 【套路】他干活有什么固定套路?
400
+ 5. 【建议】怎么让他干活更快?
401
+
402
+ 规则:
403
+ - 用"你"来称呼
404
+ - 不用专业术语,非要用也得解释一下
405
+ - 要具体,别套话 - 带上具体例子
406
+ - 每个洞察要像朋友跟你聊天那样自然
407
+ - 用用户能看懂的语言(en 或 zh)
408
+ - 仅输出有效 JSON`,
409
+
410
+ humanInsightsUserTemplate: `分析这个开发者的数据,用大白话写 4-6 条洞察。
411
+
412
+ 要分析的数据:
413
+ - 常用工具: {{tools}}
414
+ - 语言/技术: {{languages}}
415
+ - 解决的问题: {{wins}}
416
+ - 还没搞定的问题: {{struggles}}
417
+ - 学到的经验: {{lessons}}
418
+ - 犯的错误: {{errors}}
419
+
420
+ 输出 JSON,结构如下:
421
+ {
422
+ "persona": {
423
+ "whatTheyDo": "一两句话描述主要做什么",
424
+ "experienceLevel": "经验水平推测",
425
+ "superpowers": ["擅长的地方"],
426
+ "painPoints": ["经常卡住的地方"],
427
+ "workStyle": "工作风格描述",
428
+ "summary": "一句话总结"
429
+ },
430
+ "insights": [
431
+ {
432
+ "title": "吸引人的标题",
433
+ "content": "大白话描述,像朋友聊天那样",
434
+ "icon": "emoji",
435
+ "utility": "high|medium|low",
436
+ "tags": ["分类"]
437
+ }
438
+ ],
439
+ "rootCauses": [
440
+ {
441
+ "symptom": "表面现象",
442
+ "rootCause": "用人话解释为什么",
443
+ "evidence": ["支持的证据"],
444
+ "suggestion": "建议怎么做"
445
+ }
446
+ ]
447
+ }`,
448
+
449
+ humanInsightsTitle: "你是这样的开发者",
450
+ humanInsightsSectionPersona: "你是谁",
451
+ humanInsightsSectionInsights: "我们注意到了什么",
452
+ humanInsightsSectionRootCauses: "为什么这些事总发生",
453
+ };
454
+
455
+ export const PROMPTS: Record<string, PromptSet> = { en: EN, zh: ZH };
package/src/index.ts ADDED
@@ -0,0 +1,117 @@
1
+ /**
2
+ * [WHO]: NanoMemEngine, getConfig, PROMPTS, PromptSet, renderInsightsHtml, renderFullInsightsHtml, all types
3
+ * [FROM]: Re-exports from ./config.js, ./engine.js, ./i18n.js, ./insights-html.js, ./full-insights-html.js, ./types.js
4
+ * [TO]: Consumed by packages/mem-core/src/extension.ts
5
+ * [HERE]: packages/mem-core/src/index.ts - barrel export, public API surface for nanomem package
6
+ */
7
+
8
+
9
+ export type { EmbeddingConfig, NanomemConfig, ProgressiveRecallConfig } from "./config.js";
10
+ export { getConfig } from "./config.js";
11
+ export { NanoMemEngine } from "./engine.js";
12
+ export { createHashedEmbeddingFn } from "./hash-embedding.js";
13
+ export type { PromptSet } from "./i18n.js";
14
+ export { PROMPTS } from "./i18n.js";
15
+ export { renderInsightsHtml } from "./insights-html.js";
16
+ export { renderFullInsightsHtml } from "./full-insights-html.js";
17
+ export {
18
+ checksumText,
19
+ cosineSimilarity,
20
+ getEmbeddingIndexPath,
21
+ loadEmbeddingIndex,
22
+ queryEmbeddingIndex,
23
+ saveEmbeddingIndex,
24
+ syncEmbeddingIndex,
25
+ } from "./embedding-index.js";
26
+ export { consolidateV2Memories } from "./consolidate-v2.js";
27
+ export { getGraphNeighborhoodBySeeds, getRelatedSummaries, linkNewEntry, reinforceRelations } from "./linking.js";
28
+ export { evictExpiredEntries, evictExpiredWork, filterByScope, filterPII, matchesScope } from "./privacy.js";
29
+ export { compileProcedureFromEpisode } from "./procedural-v2.js";
30
+ export { reconsolidateV2Memories } from "./reconsolidate-v2.js";
31
+ export {
32
+ getV2Paths,
33
+ loadV2Episodes,
34
+ loadV2Facets,
35
+ loadV2Links,
36
+ loadV2Meta,
37
+ loadV2Procedural,
38
+ loadV2Semantic,
39
+ loadV2Snapshot,
40
+ loadV2State,
41
+ saveV2Episodes,
42
+ saveV2Facets,
43
+ saveV2Links,
44
+ saveV2Meta,
45
+ saveV2Procedural,
46
+ saveV2Semantic,
47
+ saveV2Snapshot,
48
+ saveV2State,
49
+ } from "./store-v2.js";
50
+ export type { ScoreWeights } from "./scoring.js";
51
+ export {
52
+ daysSince,
53
+ decay,
54
+ extractTags,
55
+ getInjectionLevel,
56
+ pickTop,
57
+ scoreEntry,
58
+ scoreEpisode,
59
+ scoreWorkEntry,
60
+ tagOverlap,
61
+ tierEntries,
62
+ } from "./scoring.js";
63
+ export type {
64
+ AlignmentSnapshot,
65
+ Episode,
66
+ ExtractedItem,
67
+ ExtractedWork,
68
+ FacetData,
69
+ FullInsightsReport,
70
+ FullInsightsAtAGlance,
71
+ FullInsightsProjectArea,
72
+ FullInsightsChart,
73
+ FullInsightsChartRow,
74
+ FullInsightsWin,
75
+ FullInsightsFriction,
76
+ FullInsightsFeatureToTry,
77
+ FullInsightsUsagePattern,
78
+ InjectionLevel,
79
+ InsightsReport,
80
+ LlmFn,
81
+ MemoryEntry,
82
+ MemoryScope,
83
+ Meta,
84
+ PatternInsight,
85
+ StruggleInsight,
86
+ UpdateAction,
87
+ WorkEntry,
88
+ } from "./types.js";
89
+ export type {
90
+ AbstractionLevel,
91
+ BaseMemoryV2,
92
+ EmbeddingFn,
93
+ EmbeddingIndexRecord,
94
+ EmbeddingRef,
95
+ EpisodeFacet,
96
+ EpisodeMemory,
97
+ EvidenceRef,
98
+ EvidenceSourceType,
99
+ FacetKind,
100
+ MemoryKind,
101
+ MemoryLink,
102
+ MemoryLinkType,
103
+ MemoryRetentionV2,
104
+ MemoryScopeV2,
105
+ MemoryStabilityV2,
106
+ NanoMemV2Snapshot,
107
+ ProcedureStatus,
108
+ ProceduralMemory,
109
+ ProceduralStep,
110
+ SemanticKind,
111
+ SemanticMemory,
112
+ StateHorizon,
113
+ StateMemory,
114
+ StateType,
115
+ V2Meta,
116
+ } from "./types-v2.js";
117
+ export type { NanoMemV2Paths } from "./store-v2.js";