memorix 1.0.6 → 1.0.7

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.
@@ -0,0 +1,396 @@
1
+ /**
2
+ * Memorix Core Types
3
+ *
4
+ * Data model sources:
5
+ * - Entity/Relation/KnowledgeGraph: MCP Official Memory Server (v0.6.3)
6
+ * - Observation/ObservationType: claude-mem Progressive Disclosure
7
+ * - UnifiedRule/RuleSource: Memorix original (rules sync)
8
+ *
9
+ * Designed for extensibility: new agent formats (Kiro, Copilot, Antigravity)
10
+ * can be added by extending RuleSource and adding format adapters.
11
+ */
12
+ /** A node in the knowledge graph representing a concept, component, or config */
13
+ interface Entity {
14
+ name: string;
15
+ entityType: string;
16
+ observations: string[];
17
+ }
18
+ /** A directed edge between two entities */
19
+ interface Relation {
20
+ from: string;
21
+ to: string;
22
+ relationType: string;
23
+ }
24
+ /** The complete knowledge graph */
25
+ interface KnowledgeGraph {
26
+ entities: Entity[];
27
+ relations: Relation[];
28
+ }
29
+ /**
30
+ * Observation type classification using claude-mem's icon-based legend system.
31
+ *
32
+ * Icon mapping:
33
+ * 🎯 session-request — User's original goal
34
+ * 🔴 gotcha — Critical pitfall / trap
35
+ * 🟡 problem-solution — Bug fix or workaround
36
+ * 🔵 how-it-works — Technical explanation
37
+ * 🟢 what-changed — Code/architecture change
38
+ * 🟣 discovery — New learning or insight
39
+ * 🟠 why-it-exists — Design rationale
40
+ * 🟤 decision — Architecture decision
41
+ * ⚖️ trade-off — Deliberate compromise
42
+ * 🧠 reasoning — Why this approach was chosen (System 2 reasoning trace)
43
+ */
44
+ type ObservationType = 'session-request' | 'gotcha' | 'problem-solution' | 'how-it-works' | 'what-changed' | 'discovery' | 'why-it-exists' | 'decision' | 'trade-off' | 'reasoning';
45
+ /** Map from ObservationType to display icon */
46
+ declare const OBSERVATION_ICONS: Record<ObservationType, string>;
47
+ /** Observation lifecycle status */
48
+ type ObservationStatus = 'active' | 'resolved' | 'archived';
49
+ /** Progress tracking for task/feature observations */
50
+ interface ProgressInfo {
51
+ feature: string;
52
+ status: 'in-progress' | 'completed' | 'blocked';
53
+ completion?: number;
54
+ }
55
+ /** A rich observation record attached to an entity */
56
+ interface Observation {
57
+ id: number;
58
+ entityName: string;
59
+ type: ObservationType;
60
+ title: string;
61
+ narrative: string;
62
+ facts: string[];
63
+ filesModified: string[];
64
+ concepts: string[];
65
+ tokens: number;
66
+ createdAt: string;
67
+ updatedAt?: string;
68
+ projectId: string;
69
+ /** Whether the observation contains causal language (because, due to, etc.) */
70
+ hasCausalLanguage?: boolean;
71
+ /** Optional topic key for upsert — same project+topicKey updates existing observation */
72
+ topicKey?: string;
73
+ /** How many times this observation was revised via topic key upsert (starts at 1) */
74
+ revisionCount?: number;
75
+ /** Session ID this observation belongs to */
76
+ sessionId?: string;
77
+ /** Lifecycle status: active (default) → resolved → archived */
78
+ status?: ObservationStatus;
79
+ /** ID of the observation that superseded this one (set when auto-resolved by topicKey upsert) */
80
+ supersededBy?: number;
81
+ /** Progress tracking for task/feature observations */
82
+ progress?: ProgressInfo;
83
+ /** Origin of this observation: agent (IDE hooks/MCP), git (commit ingest), manual (CLI) */
84
+ source?: 'agent' | 'git' | 'manual';
85
+ /** Git commit hash if source is 'git' */
86
+ commitHash?: string;
87
+ /** Related commit hashes — links reasoning memories to the commits they explain */
88
+ relatedCommits?: string[];
89
+ /** Related entity names — explicit cross-references to other memory entities */
90
+ relatedEntities?: string[];
91
+ /** Provenance detail: how this observation entered the system */
92
+ sourceDetail?: 'explicit' | 'hook' | 'git-ingest';
93
+ /** Value category from formation pipeline evaluation */
94
+ valueCategory?: 'core' | 'contextual' | 'ephemeral';
95
+ /** Phase 4a: Agent ID that created this observation (team attribution) */
96
+ createdByAgentId?: string;
97
+ /** Phase 4a: Monotonic write generation — snapshot of storage_generation at write time (watermark coherence) */
98
+ writeGeneration?: number;
99
+ }
100
+ /** A coding session tracked by Memorix */
101
+ interface Session {
102
+ id: string;
103
+ projectId: string;
104
+ startedAt: string;
105
+ endedAt?: string;
106
+ summary?: string;
107
+ status: 'active' | 'completed';
108
+ /** Agent/IDE that started this session */
109
+ agent?: string;
110
+ }
111
+ /** L1 index entry — lightweight, ~50-100 tokens per result */
112
+ interface IndexEntry {
113
+ id: number;
114
+ time: string;
115
+ type: ObservationType;
116
+ icon: string;
117
+ title: string;
118
+ tokens: number;
119
+ /** Relevance score from search (time-decayed). Used by compact engine. */
120
+ score?: number;
121
+ /** Project that owns this observation. Needed to disambiguate global results. */
122
+ projectId?: string;
123
+ /** Origin of the memory for source-aware retrieval and display. */
124
+ source?: 'agent' | 'git' | 'manual';
125
+ /** Provenance detail for source-aware display */
126
+ sourceDetail?: 'explicit' | 'hook' | 'git-ingest';
127
+ /** Value category for source-aware ranking */
128
+ valueCategory?: 'core' | 'contextual' | 'ephemeral';
129
+ /** Explainable recall: why this result matched. */
130
+ matchedFields?: string[];
131
+ /** Entity name — used for entity-affinity scoring and workstream deduplication. */
132
+ entityName?: string;
133
+ /** Document type: observation or mini-skill (Phase 3a) */
134
+ documentType?: DocumentType;
135
+ /** Knowledge layer for layer-aware ranking (Phase 3a) */
136
+ knowledgeLayer?: KnowledgeLayer;
137
+ }
138
+ /** Explicit reference to an observation, optionally scoped to a project. */
139
+ interface ObservationRef {
140
+ id: number;
141
+ projectId?: string;
142
+ }
143
+ /** L2 timeline context — observations around an anchor */
144
+ interface TimelineContext {
145
+ anchorId: number;
146
+ anchorEntry: IndexEntry | null;
147
+ before: IndexEntry[];
148
+ after: IndexEntry[];
149
+ }
150
+ /** Search options for the compact engine */
151
+ interface SearchOptions {
152
+ query: string;
153
+ limit?: number;
154
+ type?: ObservationType;
155
+ projectId?: string;
156
+ since?: string;
157
+ until?: string;
158
+ /** Token budget — trim results to fit within this many tokens (0 = unlimited) */
159
+ maxTokens?: number;
160
+ /** Filter by observation status. Default: 'active' (only show active memories) */
161
+ status?: ObservationStatus | 'all';
162
+ /** Filter by observation source: 'agent', 'git', 'manual', or undefined for all */
163
+ source?: 'agent' | 'git' | 'manual';
164
+ }
165
+ /** Topic key family heuristics for suggesting stable topic keys */
166
+ declare const TOPIC_KEY_FAMILIES: Record<string, string[]>;
167
+ /** The document shape stored in Orama */
168
+ interface MemorixDocument {
169
+ id: string;
170
+ observationId: number;
171
+ entityName: string;
172
+ type: string;
173
+ title: string;
174
+ narrative: string;
175
+ facts: string;
176
+ filesModified: string;
177
+ concepts: string;
178
+ tokens: number;
179
+ createdAt: string;
180
+ projectId: string;
181
+ /** Number of times this observation was returned in search results */
182
+ accessCount: number;
183
+ /** ISO timestamp of last access via search/detail */
184
+ lastAccessedAt: string;
185
+ /** Lifecycle status: active, resolved, archived */
186
+ status: string;
187
+ /** Origin: agent, git, manual */
188
+ source: string;
189
+ /** Provenance detail: explicit, hook, or git-ingest */
190
+ sourceDetail?: string;
191
+ /** Value category from formation evaluation */
192
+ valueCategory?: string;
193
+ /** Optional vector embedding for semantic/hybrid retrieval */
194
+ embedding?: number[];
195
+ /** Document type: observation or mini-skill (Phase 3a) */
196
+ documentType?: DocumentType;
197
+ /** Knowledge layer for layer-aware ranking (Phase 3a) */
198
+ knowledgeLayer?: KnowledgeLayer;
199
+ }
200
+ /**
201
+ * Supported agent/IDE rule sources.
202
+ * All 7 major AI IDEs are supported.
203
+ */
204
+ type RuleSource = 'cursor' | 'claude-code' | 'codex' | 'windsurf' | 'antigravity' | 'gemini-cli' | 'copilot' | 'kiro' | 'trae' | 'memorix';
205
+ /** A parsed rule in the unified intermediate representation */
206
+ interface UnifiedRule {
207
+ id: string;
208
+ content: string;
209
+ description?: string;
210
+ source: RuleSource;
211
+ scope: 'global' | 'project' | 'path-specific';
212
+ paths?: string[];
213
+ alwaysApply?: boolean;
214
+ priority: number;
215
+ hash: string;
216
+ }
217
+ /**
218
+ * Format adapter interface — implement this for each agent/IDE.
219
+ * Adding a new agent (e.g., Kiro) only requires implementing this interface.
220
+ */
221
+ interface RuleFormatAdapter {
222
+ /** Unique identifier for this agent format */
223
+ readonly source: RuleSource;
224
+ /** File paths/globs this adapter can parse */
225
+ readonly filePatterns: string[];
226
+ /** Parse rule files into unified representation */
227
+ parse(filePath: string, content: string): UnifiedRule[];
228
+ /** Generate rule file content from unified representation */
229
+ generate(rules: UnifiedRule[]): {
230
+ filePath: string;
231
+ content: string;
232
+ }[];
233
+ }
234
+ interface ProjectInfo {
235
+ id: string;
236
+ name: string;
237
+ gitRemote?: string;
238
+ rootPath: string;
239
+ }
240
+ /**
241
+ * Diagnostic failure info from project detection.
242
+ * Tells callers exactly WHY detection failed so they can report actionable errors.
243
+ */
244
+ type DetectionFailureReason = 'path_not_found' | 'not_a_directory' | 'no_git' | 'git_worktree_error' | 'git_safe_directory' | 'remote_resolve_failed';
245
+ interface DetectionFailure {
246
+ reason: DetectionFailureReason;
247
+ path: string;
248
+ detail: string;
249
+ }
250
+ interface DetectionResult {
251
+ project: ProjectInfo | null;
252
+ failure: DetectionFailure | null;
253
+ }
254
+ interface MemorixConfig {
255
+ dataDir: string;
256
+ projectId: string;
257
+ projectName: string;
258
+ enableEmbeddings: boolean;
259
+ enableRulesSync: boolean;
260
+ watchRuleFiles: boolean;
261
+ }
262
+ declare const DEFAULT_CONFIG: Partial<MemorixConfig>;
263
+ /** Supported agent targets for workspace sync */
264
+ type AgentTarget = 'windsurf' | 'cursor' | 'claude-code' | 'codex' | 'copilot' | 'antigravity' | 'gemini-cli' | 'kiro' | 'opencode' | 'trae';
265
+ /** A unified MCP server entry across all agent config formats */
266
+ interface MCPServerEntry {
267
+ name: string;
268
+ /** Command for stdio transport */
269
+ command: string;
270
+ /** Args for stdio transport */
271
+ args: string[];
272
+ /** Environment variables */
273
+ env?: Record<string, string> | null;
274
+ /** URL for HTTP/SSE transport (Codex uses `url`, Windsurf uses `serverUrl`) */
275
+ url?: string;
276
+ /** HTTP headers (Windsurf uses `headers` for HTTP transport) */
277
+ headers?: Record<string, string>;
278
+ /** Whether this server is disabled */
279
+ disabled?: boolean;
280
+ }
281
+ /** Unified workflow entry */
282
+ interface WorkflowEntry {
283
+ name: string;
284
+ description: string;
285
+ content: string;
286
+ source: AgentTarget;
287
+ filePath: string;
288
+ }
289
+ /** A skill folder discovered from an agent's skills directory */
290
+ interface SkillEntry {
291
+ name: string;
292
+ description: string;
293
+ sourcePath: string;
294
+ sourceAgent: AgentTarget;
295
+ }
296
+ /** Conflict when two agents have a skill with the same folder name */
297
+ interface SkillConflict {
298
+ name: string;
299
+ kept: SkillEntry;
300
+ skipped: SkillEntry;
301
+ }
302
+ /** Result of a workspace sync operation */
303
+ interface WorkspaceSyncResult {
304
+ mcpServers: {
305
+ scanned: MCPServerEntry[];
306
+ generated: {
307
+ filePath: string;
308
+ content: string;
309
+ }[];
310
+ };
311
+ workflows: {
312
+ scanned: WorkflowEntry[];
313
+ generated: {
314
+ filePath: string;
315
+ content: string;
316
+ }[];
317
+ };
318
+ rules: {
319
+ scanned: number;
320
+ generated: number;
321
+ };
322
+ skills: {
323
+ scanned: SkillEntry[];
324
+ conflicts: SkillConflict[];
325
+ copied: string[];
326
+ skipped: string[];
327
+ };
328
+ }
329
+ /** A mini-skill promoted from one or more observations */
330
+ interface MiniSkill {
331
+ id: number;
332
+ /** Observation IDs this mini-skill was derived from (live refs, best-effort) */
333
+ sourceObservationIds: number[];
334
+ /** Entity the source observations belong to */
335
+ sourceEntity: string;
336
+ /** Short title for the skill */
337
+ title: string;
338
+ /** What the agent should do (imperative instruction) */
339
+ instruction: string;
340
+ /** When this skill should be applied (scenario description) */
341
+ trigger: string;
342
+ /** Key facts extracted from source observations */
343
+ facts: string[];
344
+ /** Project this skill belongs to */
345
+ projectId: string;
346
+ /** ISO timestamp */
347
+ createdAt: string;
348
+ /** How many times this skill was injected in session_start */
349
+ usedCount: number;
350
+ /** Classification tags */
351
+ tags: string[];
352
+ /** Frozen source observation content at promote time (JSON, immutable provenance proof) */
353
+ sourceSnapshot?: string;
354
+ /** ISO timestamp of last modification (Phase 3a: set once at creation) */
355
+ updatedAt?: string;
356
+ }
357
+ /** A single observation entry within a source snapshot */
358
+ interface SnapshotObservation {
359
+ id: number;
360
+ title: string;
361
+ type: string;
362
+ narrative: string;
363
+ facts: string[];
364
+ entityName: string;
365
+ projectId: string;
366
+ createdAt: string;
367
+ /** Frozen source detail for provenance (explicit / hook / git-ingest) */
368
+ sourceDetail?: string;
369
+ }
370
+ /** Frozen source content captured at promote time */
371
+ interface SourceSnapshot {
372
+ observations: SnapshotObservation[];
373
+ promotedAt: string;
374
+ }
375
+ /** Classification of knowledge for layer-aware ranking */
376
+ type KnowledgeLayer = 'project-truth' | 'promoted' | 'evidence';
377
+ /** Document type discriminator for Orama index */
378
+ type DocumentType = 'observation' | 'mini-skill';
379
+ /** A typed reference to a memory object (observation or mini-skill) */
380
+ interface MemoryRef {
381
+ kind: 'obs' | 'skill';
382
+ id: number;
383
+ projectId?: string;
384
+ }
385
+ /** MCP config format adapter interface */
386
+ interface MCPConfigAdapter {
387
+ readonly source: AgentTarget;
388
+ /** Parse MCP server entries from a config file */
389
+ parse(content: string): MCPServerEntry[];
390
+ /** Generate config file content from MCP server entries */
391
+ generate(servers: MCPServerEntry[]): string;
392
+ /** Get the default config file path for this agent */
393
+ getConfigPath(projectRoot?: string): string;
394
+ }
395
+
396
+ export { type AgentTarget, DEFAULT_CONFIG, type DetectionFailure, type DetectionFailureReason, type DetectionResult, type DocumentType, type Entity, type IndexEntry, type KnowledgeGraph, type KnowledgeLayer, type MCPConfigAdapter, type MCPServerEntry, type MemorixConfig, type MemorixDocument, type MemoryRef, type MiniSkill, OBSERVATION_ICONS, type Observation, type ObservationRef, type ObservationStatus, type ObservationType, type ProgressInfo, type ProjectInfo, type Relation, type RuleFormatAdapter, type RuleSource, type SearchOptions, type Session, type SkillConflict, type SkillEntry, type SnapshotObservation, type SourceSnapshot, TOPIC_KEY_FAMILIES, type TimelineContext, type UnifiedRule, type WorkflowEntry, type WorkspaceSyncResult };
package/dist/types.js ADDED
@@ -0,0 +1,32 @@
1
+ // src/types.ts
2
+ var OBSERVATION_ICONS = {
3
+ "session-request": "\u{1F3AF}",
4
+ "gotcha": "\u{1F534}",
5
+ "problem-solution": "\u{1F7E1}",
6
+ "how-it-works": "\u{1F535}",
7
+ "what-changed": "\u{1F7E2}",
8
+ "discovery": "\u{1F7E3}",
9
+ "why-it-exists": "\u{1F7E0}",
10
+ "decision": "\u{1F7E4}",
11
+ "trade-off": "\u2696\uFE0F",
12
+ "reasoning": "\u{1F9E0}"
13
+ };
14
+ var TOPIC_KEY_FAMILIES = {
15
+ "architecture": ["architecture", "design", "adr", "structure", "pattern"],
16
+ "bug": ["bugfix", "fix", "error", "regression", "crash", "problem-solution"],
17
+ "decision": ["decision", "trade-off", "choice", "strategy"],
18
+ "config": ["config", "setup", "env", "environment", "deployment"],
19
+ "discovery": ["discovery", "learning", "insight", "gotcha"],
20
+ "pattern": ["pattern", "convention", "standard", "best-practice"]
21
+ };
22
+ var DEFAULT_CONFIG = {
23
+ enableEmbeddings: false,
24
+ enableRulesSync: false,
25
+ watchRuleFiles: false
26
+ };
27
+ export {
28
+ DEFAULT_CONFIG,
29
+ OBSERVATION_ICONS,
30
+ TOPIC_KEY_FAMILIES
31
+ };
32
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\r\n * Memorix Core Types\r\n *\r\n * Data model sources:\r\n * - Entity/Relation/KnowledgeGraph: MCP Official Memory Server (v0.6.3)\r\n * - Observation/ObservationType: claude-mem Progressive Disclosure\r\n * - UnifiedRule/RuleSource: Memorix original (rules sync)\r\n *\r\n * Designed for extensibility: new agent formats (Kiro, Copilot, Antigravity)\r\n * can be added by extending RuleSource and adding format adapters.\r\n */\r\n\r\n// ============================================================\r\n// Knowledge Graph (adopted from MCP Official Memory Server)\r\n// ============================================================\r\n\r\n/** A node in the knowledge graph representing a concept, component, or config */\r\nexport interface Entity {\r\n name: string;\r\n entityType: string;\r\n observations: string[];\r\n}\r\n\r\n/** A directed edge between two entities */\r\nexport interface Relation {\r\n from: string;\r\n to: string;\r\n relationType: string;\r\n}\r\n\r\n/** The complete knowledge graph */\r\nexport interface KnowledgeGraph {\r\n entities: Entity[];\r\n relations: Relation[];\r\n}\r\n\r\n// ============================================================\r\n// Observation (adopted from claude-mem Progressive Disclosure)\r\n// ============================================================\r\n\r\n/**\r\n * Observation type classification using claude-mem's icon-based legend system.\r\n *\r\n * Icon mapping:\r\n * 🎯 session-request — User's original goal\r\n * 🔴 gotcha — Critical pitfall / trap\r\n * 🟡 problem-solution — Bug fix or workaround\r\n * 🔵 how-it-works — Technical explanation\r\n * 🟢 what-changed — Code/architecture change\r\n * 🟣 discovery — New learning or insight\r\n * 🟠 why-it-exists — Design rationale\r\n * 🟤 decision — Architecture decision\r\n * ⚖️ trade-off — Deliberate compromise\r\n * 🧠 reasoning — Why this approach was chosen (System 2 reasoning trace)\r\n */\r\nexport type ObservationType =\r\n | 'session-request'\r\n | 'gotcha'\r\n | 'problem-solution'\r\n | 'how-it-works'\r\n | 'what-changed'\r\n | 'discovery'\r\n | 'why-it-exists'\r\n | 'decision'\r\n | 'trade-off'\r\n | 'reasoning';\r\n\r\n/** Map from ObservationType to display icon */\r\nexport const OBSERVATION_ICONS: Record<ObservationType, string> = {\r\n 'session-request': '🎯',\r\n 'gotcha': '🔴',\r\n 'problem-solution': '🟡',\r\n 'how-it-works': '🔵',\r\n 'what-changed': '🟢',\r\n 'discovery': '🟣',\r\n 'why-it-exists': '🟠',\r\n 'decision': '🟤',\r\n 'trade-off': '⚖️',\r\n 'reasoning': '🧠',\r\n};\r\n\r\n/** Observation lifecycle status */\r\nexport type ObservationStatus = 'active' | 'resolved' | 'archived';\r\n\r\n/** Progress tracking for task/feature observations */\r\nexport interface ProgressInfo {\r\n feature: string;\r\n status: 'in-progress' | 'completed' | 'blocked';\r\n completion?: number;\r\n}\r\n\r\n/** A rich observation record attached to an entity */\r\nexport interface Observation {\r\n id: number;\r\n entityName: string;\r\n type: ObservationType;\r\n title: string;\r\n narrative: string;\r\n facts: string[];\r\n filesModified: string[];\r\n concepts: string[];\r\n tokens: number;\r\n createdAt: string;\r\n updatedAt?: string;\r\n projectId: string;\r\n /** Whether the observation contains causal language (because, due to, etc.) */\r\n hasCausalLanguage?: boolean;\r\n /** Optional topic key for upsert — same project+topicKey updates existing observation */\r\n topicKey?: string;\r\n /** How many times this observation was revised via topic key upsert (starts at 1) */\r\n revisionCount?: number;\r\n /** Session ID this observation belongs to */\r\n sessionId?: string;\r\n /** Lifecycle status: active (default) → resolved → archived */\r\n status?: ObservationStatus;\r\n /** ID of the observation that superseded this one (set when auto-resolved by topicKey upsert) */\r\n supersededBy?: number;\r\n /** Progress tracking for task/feature observations */\r\n progress?: ProgressInfo;\r\n /** Origin of this observation: agent (IDE hooks/MCP), git (commit ingest), manual (CLI) */\r\n source?: 'agent' | 'git' | 'manual';\r\n /** Git commit hash if source is 'git' */\r\n commitHash?: string;\r\n /** Related commit hashes — links reasoning memories to the commits they explain */\r\n relatedCommits?: string[];\r\n /** Related entity names — explicit cross-references to other memory entities */\r\n relatedEntities?: string[];\r\n /** Provenance detail: how this observation entered the system */\r\n sourceDetail?: 'explicit' | 'hook' | 'git-ingest';\r\n /** Value category from formation pipeline evaluation */\r\n valueCategory?: 'core' | 'contextual' | 'ephemeral';\r\n /** Phase 4a: Agent ID that created this observation (team attribution) */\r\n createdByAgentId?: string;\r\n /** Phase 4a: Monotonic write generation — snapshot of storage_generation at write time (watermark coherence) */\r\n writeGeneration?: number;\r\n}\r\n\r\n// ============================================================\r\n// Session Lifecycle (inspired by Engram's session management)\r\n// ============================================================\r\n\r\n/** A coding session tracked by Memorix */\r\nexport interface Session {\r\n id: string;\r\n projectId: string;\r\n startedAt: string;\r\n endedAt?: string;\r\n summary?: string;\r\n status: 'active' | 'completed';\r\n /** Agent/IDE that started this session */\r\n agent?: string;\r\n}\r\n\r\n// ============================================================\r\n// Compact Engine (adopted from claude-mem 3-layer workflow)\r\n// ============================================================\r\n\r\n/** L1 index entry — lightweight, ~50-100 tokens per result */\r\nexport interface IndexEntry {\r\n id: number;\r\n time: string;\r\n type: ObservationType;\r\n icon: string;\r\n title: string;\r\n tokens: number;\r\n /** Relevance score from search (time-decayed). Used by compact engine. */\r\n score?: number;\r\n /** Project that owns this observation. Needed to disambiguate global results. */\r\n projectId?: string;\r\n /** Origin of the memory for source-aware retrieval and display. */\r\n source?: 'agent' | 'git' | 'manual';\r\n /** Provenance detail for source-aware display */\r\n sourceDetail?: 'explicit' | 'hook' | 'git-ingest';\r\n /** Value category for source-aware ranking */\r\n valueCategory?: 'core' | 'contextual' | 'ephemeral';\r\n /** Explainable recall: why this result matched. */\r\n matchedFields?: string[];\r\n /** Entity name — used for entity-affinity scoring and workstream deduplication. */\r\n entityName?: string;\r\n /** Document type: observation or mini-skill (Phase 3a) */\r\n documentType?: DocumentType;\r\n /** Knowledge layer for layer-aware ranking (Phase 3a) */\r\n knowledgeLayer?: KnowledgeLayer;\r\n}\r\n\r\n/** Explicit reference to an observation, optionally scoped to a project. */\r\nexport interface ObservationRef {\r\n id: number;\r\n projectId?: string;\r\n}\r\n\r\n/** L2 timeline context — observations around an anchor */\r\nexport interface TimelineContext {\r\n anchorId: number;\r\n anchorEntry: IndexEntry | null;\r\n before: IndexEntry[];\r\n after: IndexEntry[];\r\n}\r\n\r\n/** Search options for the compact engine */\r\nexport interface SearchOptions {\r\n query: string;\r\n limit?: number;\r\n type?: ObservationType;\r\n projectId?: string;\r\n since?: string;\r\n until?: string;\r\n /** Token budget — trim results to fit within this many tokens (0 = unlimited) */\r\n maxTokens?: number;\r\n /** Filter by observation status. Default: 'active' (only show active memories) */\r\n status?: ObservationStatus | 'all';\r\n /** Filter by observation source: 'agent', 'git', 'manual', or undefined for all */\r\n source?: 'agent' | 'git' | 'manual';\r\n}\r\n\r\n/** Topic key family heuristics for suggesting stable topic keys */\r\nexport const TOPIC_KEY_FAMILIES: Record<string, string[]> = {\r\n 'architecture': ['architecture', 'design', 'adr', 'structure', 'pattern'],\r\n 'bug': ['bugfix', 'fix', 'error', 'regression', 'crash', 'problem-solution'],\r\n 'decision': ['decision', 'trade-off', 'choice', 'strategy'],\r\n 'config': ['config', 'setup', 'env', 'environment', 'deployment'],\r\n 'discovery': ['discovery', 'learning', 'insight', 'gotcha'],\r\n 'pattern': ['pattern', 'convention', 'standard', 'best-practice'],\r\n};\r\n\r\n// ============================================================\r\n// Orama Document Schema\r\n// ============================================================\r\n\r\n/** The document shape stored in Orama */\r\nexport interface MemorixDocument {\r\n id: string;\r\n observationId: number;\r\n entityName: string;\r\n type: string;\r\n title: string;\r\n narrative: string;\r\n facts: string;\r\n filesModified: string;\r\n concepts: string;\r\n tokens: number;\r\n createdAt: string;\r\n projectId: string;\r\n /** Number of times this observation was returned in search results */\r\n accessCount: number;\r\n /** ISO timestamp of last access via search/detail */\r\n lastAccessedAt: string;\r\n /** Lifecycle status: active, resolved, archived */\r\n status: string;\r\n /** Origin: agent, git, manual */\r\n source: string;\r\n /** Provenance detail: explicit, hook, or git-ingest */\r\n sourceDetail?: string;\r\n /** Value category from formation evaluation */\r\n valueCategory?: string;\r\n /** Optional vector embedding for semantic/hybrid retrieval */\r\n embedding?: number[];\r\n /** Document type: observation or mini-skill (Phase 3a) */\r\n documentType?: DocumentType;\r\n /** Knowledge layer for layer-aware ranking (Phase 3a) */\r\n knowledgeLayer?: KnowledgeLayer;\r\n}\r\n\r\n// ============================================================\r\n// Rules System (Memorix original — extensible for new agents)\r\n// ============================================================\r\n\r\n/**\r\n * Supported agent/IDE rule sources.\r\n * All 7 major AI IDEs are supported.\r\n */\r\nexport type RuleSource =\r\n | 'cursor'\r\n | 'claude-code'\r\n | 'codex'\r\n | 'windsurf'\r\n | 'antigravity'\r\n | 'gemini-cli'\r\n | 'copilot'\r\n | 'kiro'\r\n | 'trae'\r\n | 'memorix';\r\n\r\n/** A parsed rule in the unified intermediate representation */\r\nexport interface UnifiedRule {\r\n id: string;\r\n content: string;\r\n description?: string;\r\n source: RuleSource;\r\n scope: 'global' | 'project' | 'path-specific';\r\n paths?: string[];\r\n alwaysApply?: boolean;\r\n priority: number;\r\n hash: string;\r\n}\r\n\r\n/**\r\n * Format adapter interface — implement this for each agent/IDE.\r\n * Adding a new agent (e.g., Kiro) only requires implementing this interface.\r\n */\r\nexport interface RuleFormatAdapter {\r\n /** Unique identifier for this agent format */\r\n readonly source: RuleSource;\r\n\r\n /** File paths/globs this adapter can parse */\r\n readonly filePatterns: string[];\r\n\r\n /** Parse rule files into unified representation */\r\n parse(filePath: string, content: string): UnifiedRule[];\r\n\r\n /** Generate rule file content from unified representation */\r\n generate(rules: UnifiedRule[]): { filePath: string; content: string }[];\r\n}\r\n\r\n// ============================================================\r\n// Project Identity\r\n// ============================================================\r\n\r\nexport interface ProjectInfo {\r\n id: string;\r\n name: string;\r\n gitRemote?: string;\r\n rootPath: string;\r\n}\r\n\r\n/**\r\n * Diagnostic failure info from project detection.\r\n * Tells callers exactly WHY detection failed so they can report actionable errors.\r\n */\r\nexport type DetectionFailureReason =\r\n | 'path_not_found'\r\n | 'not_a_directory'\r\n | 'no_git'\r\n | 'git_worktree_error'\r\n | 'git_safe_directory'\r\n | 'remote_resolve_failed';\r\n\r\nexport interface DetectionFailure {\r\n reason: DetectionFailureReason;\r\n path: string;\r\n detail: string;\r\n}\r\n\r\nexport interface DetectionResult {\r\n project: ProjectInfo | null;\r\n failure: DetectionFailure | null;\r\n}\r\n\r\n// ============================================================\r\n// Memorix Server Configuration\r\n// ============================================================\r\n\r\nexport interface MemorixConfig {\r\n dataDir: string;\r\n projectId: string;\r\n projectName: string;\r\n enableEmbeddings: boolean;\r\n enableRulesSync: boolean;\r\n watchRuleFiles: boolean;\r\n}\r\n\r\nexport const DEFAULT_CONFIG: Partial<MemorixConfig> = {\r\n enableEmbeddings: false,\r\n enableRulesSync: false,\r\n watchRuleFiles: false,\r\n};\r\n\r\n// ============================================================\r\n// Workspace Sync — Cross-Agent workspace migration\r\n// ============================================================\r\n\r\n/** Supported agent targets for workspace sync */\r\nexport type AgentTarget = 'windsurf' | 'cursor' | 'claude-code' | 'codex' | 'copilot' | 'antigravity' | 'gemini-cli' | 'kiro' | 'opencode' | 'trae';\r\n\r\n/** A unified MCP server entry across all agent config formats */\r\nexport interface MCPServerEntry {\r\n name: string;\r\n /** Command for stdio transport */\r\n command: string;\r\n /** Args for stdio transport */\r\n args: string[];\r\n /** Environment variables */\r\n env?: Record<string, string> | null;\r\n /** URL for HTTP/SSE transport (Codex uses `url`, Windsurf uses `serverUrl`) */\r\n url?: string;\r\n /** HTTP headers (Windsurf uses `headers` for HTTP transport) */\r\n headers?: Record<string, string>;\r\n /** Whether this server is disabled */\r\n disabled?: boolean;\r\n}\r\n\r\n/** Unified workflow entry */\r\nexport interface WorkflowEntry {\r\n name: string;\r\n description: string;\r\n content: string;\r\n source: AgentTarget;\r\n filePath: string;\r\n}\r\n\r\n/** A skill folder discovered from an agent's skills directory */\r\nexport interface SkillEntry {\r\n name: string;\r\n description: string;\r\n sourcePath: string;\r\n sourceAgent: AgentTarget;\r\n}\r\n\r\n/** Conflict when two agents have a skill with the same folder name */\r\nexport interface SkillConflict {\r\n name: string;\r\n kept: SkillEntry;\r\n skipped: SkillEntry;\r\n}\r\n\r\n/** Result of a workspace sync operation */\r\nexport interface WorkspaceSyncResult {\r\n mcpServers: {\r\n scanned: MCPServerEntry[];\r\n generated: { filePath: string; content: string }[];\r\n };\r\n workflows: {\r\n scanned: WorkflowEntry[];\r\n generated: { filePath: string; content: string }[];\r\n };\r\n rules: {\r\n scanned: number;\r\n generated: number;\r\n };\r\n skills: {\r\n scanned: SkillEntry[];\r\n conflicts: SkillConflict[];\r\n copied: string[];\r\n skipped: string[];\r\n };\r\n}\r\n\r\n// ============================================================\r\n// Mini-Skills — Promoted memories that never decay\r\n// ============================================================\r\n\r\n/** A mini-skill promoted from one or more observations */\r\nexport interface MiniSkill {\r\n id: number;\r\n /** Observation IDs this mini-skill was derived from (live refs, best-effort) */\r\n sourceObservationIds: number[];\r\n /** Entity the source observations belong to */\r\n sourceEntity: string;\r\n /** Short title for the skill */\r\n title: string;\r\n /** What the agent should do (imperative instruction) */\r\n instruction: string;\r\n /** When this skill should be applied (scenario description) */\r\n trigger: string;\r\n /** Key facts extracted from source observations */\r\n facts: string[];\r\n /** Project this skill belongs to */\r\n projectId: string;\r\n /** ISO timestamp */\r\n createdAt: string;\r\n /** How many times this skill was injected in session_start */\r\n usedCount: number;\r\n /** Classification tags */\r\n tags: string[];\r\n /** Frozen source observation content at promote time (JSON, immutable provenance proof) */\r\n sourceSnapshot?: string;\r\n /** ISO timestamp of last modification (Phase 3a: set once at creation) */\r\n updatedAt?: string;\r\n}\r\n\r\n// ============================================================\r\n// Source Snapshot — immutable provenance proof for promoted knowledge\r\n// ============================================================\r\n\r\n/** A single observation entry within a source snapshot */\r\nexport interface SnapshotObservation {\r\n id: number;\r\n title: string;\r\n type: string;\r\n narrative: string;\r\n facts: string[];\r\n entityName: string;\r\n projectId: string;\r\n createdAt: string;\r\n /** Frozen source detail for provenance (explicit / hook / git-ingest) */\r\n sourceDetail?: string;\r\n}\r\n\r\n/** Frozen source content captured at promote time */\r\nexport interface SourceSnapshot {\r\n observations: SnapshotObservation[];\r\n promotedAt: string;\r\n}\r\n\r\n// ============================================================\r\n// Knowledge Layer — Phase 3a retrieval classification\r\n// ============================================================\r\n\r\n/** Classification of knowledge for layer-aware ranking */\r\nexport type KnowledgeLayer = 'project-truth' | 'promoted' | 'evidence';\r\n\r\n/** Document type discriminator for Orama index */\r\nexport type DocumentType = 'observation' | 'mini-skill';\r\n\r\n// ============================================================\r\n// Typed Memory Reference — Phase 3a reference protocol\r\n// ============================================================\r\n\r\n/** A typed reference to a memory object (observation or mini-skill) */\r\nexport interface MemoryRef {\r\n kind: 'obs' | 'skill';\r\n id: number;\r\n projectId?: string;\r\n}\r\n\r\n/** MCP config format adapter interface */\r\nexport interface MCPConfigAdapter {\r\n readonly source: AgentTarget;\r\n /** Parse MCP server entries from a config file */\r\n parse(content: string): MCPServerEntry[];\r\n /** Generate config file content from MCP server entries */\r\n generate(servers: MCPServerEntry[]): string;\r\n /** Get the default config file path for this agent */\r\n getConfigPath(projectRoot?: string): string;\r\n}\r\n"],"mappings":";AAoEO,IAAM,oBAAqD;AAAA,EAChE,mBAAmB;AAAA,EACnB,UAAU;AAAA,EACV,oBAAoB;AAAA,EACpB,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,iBAAiB;AAAA,EACjB,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,aAAa;AACf;AAyIO,IAAM,qBAA+C;AAAA,EAC1D,gBAAgB,CAAC,gBAAgB,UAAU,OAAO,aAAa,SAAS;AAAA,EACxE,OAAO,CAAC,UAAU,OAAO,SAAS,cAAc,SAAS,kBAAkB;AAAA,EAC3E,YAAY,CAAC,YAAY,aAAa,UAAU,UAAU;AAAA,EAC1D,UAAU,CAAC,UAAU,SAAS,OAAO,eAAe,YAAY;AAAA,EAChE,aAAa,CAAC,aAAa,YAAY,WAAW,QAAQ;AAAA,EAC1D,WAAW,CAAC,WAAW,cAAc,YAAY,eAAe;AAClE;AA0IO,IAAM,iBAAyC;AAAA,EACpD,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,gBAAgB;AAClB;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memorix",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Open-source cross-agent memory layer for coding agents across Cursor, Claude Code, Codex, Windsurf, Gemini CLI, Copilot, Kiro, OpenCode, Antigravity, and Trae via MCP.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -13,23 +13,42 @@
13
13
  ".": {
14
14
  "import": "./dist/index.js",
15
15
  "types": "./dist/index.d.ts"
16
+ },
17
+ "./types": {
18
+ "import": "./dist/types.js",
19
+ "types": "./dist/types.d.ts"
16
20
  }
17
21
  },
18
22
  "files": [
19
- "dist",
23
+ "dist/index.js",
24
+ "dist/index.js.map",
25
+ "dist/index.d.ts",
26
+ "dist/types.js",
27
+ "dist/types.js.map",
28
+ "dist/types.d.ts",
29
+ "dist/cli/index.js",
30
+ "dist/cli/index.js.map",
31
+ "dist/cli/index.d.ts",
32
+ "dist/dashboard/static/app.js",
33
+ "dist/dashboard/static/index.html",
34
+ "dist/dashboard/static/style.css",
35
+ "dist/dashboard/static/logo.png",
20
36
  "README.md",
21
37
  "LICENSE",
22
38
  "CHANGELOG.md",
23
39
  "CLAUDE.md",
24
40
  "llms.txt",
25
- "llms-full.txt"
41
+ "llms-full.txt",
42
+ "README.zh-CN.md"
26
43
  ],
27
44
  "scripts": {
28
- "build": "tsup",
45
+ "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsup",
29
46
  "dev": "tsup --watch",
30
47
  "start": "node dist/index.js",
31
48
  "test": "vitest run",
32
49
  "test:watch": "vitest",
50
+ "test:llm-live": "MEMORIX_RUN_LIVE_LLM_TESTS=1 vitest run tests/integration/formation-llm-quality.test.ts",
51
+ "test:e2e": "vitest run tests/e2e/",
33
52
  "lint": "tsc --noEmit",
34
53
  "prepublishOnly": "npm run build && npm test"
35
54
  },
@@ -96,9 +115,11 @@
96
115
  },
97
116
  "optionalDependencies": {
98
117
  "@huggingface/transformers": "^3.0.0",
118
+ "better-sqlite3": "^11.0.0",
99
119
  "fastembed": "^1.14.4"
100
120
  },
101
121
  "devDependencies": {
122
+ "@types/better-sqlite3": "^7.6.0",
102
123
  "@types/diff": "^7.0.0",
103
124
  "@types/node": "^22.0.0",
104
125
  "@types/react": "^19.2.14",