minimem 0.0.4 → 0.0.6
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.
- package/README.md +6 -0
- package/dist/index.cjs +3984 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +858 -0
- package/dist/internal.cjs +286 -0
- package/dist/internal.cjs.map +1 -0
- package/dist/internal.d.cts +65 -0
- package/dist/session.cjs +298 -0
- package/dist/session.cjs.map +1 -0
- package/dist/session.d.cts +96 -0
- package/package.json +12 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/session.ts"],"sourcesContent":["/**\n * Session tracking for memory entries\n *\n * Captures context about the originating session (Claude Code, VS Code, etc.)\n * and stores it as YAML frontmatter in memory files.\n */\n\nimport * as os from \"node:os\";\n\n/**\n * Session metadata for memory entries\n */\nexport type SessionContext = {\n /** Session identifier (e.g., Claude Code session ID) */\n id?: string;\n /** Source application (claude-code, vscode, cursor, etc.) */\n source?: string;\n /** Project directory path */\n project?: string;\n /** Path to session transcript/log file */\n transcript?: string;\n};\n\n/**\n * Source provenance for a knowledge entry\n */\nexport type KnowledgeSource = {\n origin?: string;\n trajectories?: string[];\n agentId?: string;\n};\n\n/**\n * A directional link from this entry to another knowledge node\n */\nexport type KnowledgeLink = {\n target: string;\n relation: string;\n layer?: string;\n};\n\n/**\n * Frontmatter structure for memory files\n */\nexport type MemoryFrontmatter = {\n session?: SessionContext;\n created?: string;\n updated?: string;\n tags?: string[];\n /** Knowledge node identifier */\n id?: string;\n /** Knowledge entry type */\n type?: \"observation\" | \"entity\" | \"domain-summary\" | string;\n /** Domain tags for this knowledge entry */\n domain?: string[];\n /** Entity references in this knowledge entry */\n entities?: string[];\n /** Confidence score 0-1 */\n confidence?: number;\n /** Source provenance */\n source?: KnowledgeSource;\n /** Links to other knowledge nodes */\n links?: KnowledgeLink[];\n /** ID of the entry this supersedes */\n supersedes?: string | null;\n};\n\n/**\n * Parse YAML frontmatter from content\n *\n * Frontmatter is delimited by --- at the start and end:\n * ```\n * ---\n * session:\n * id: abc123\n * source: claude-code\n * created: 2024-01-27T14:30:00Z\n * ---\n * Actual content here...\n * ```\n */\nexport function parseFrontmatter(content: string): {\n frontmatter: MemoryFrontmatter | undefined;\n body: string;\n} {\n const frontmatterRegex = /^---\\n([\\s\\S]*?)\\n---\\n/;\n const match = content.match(frontmatterRegex);\n\n if (!match) {\n return { frontmatter: undefined, body: content };\n }\n\n const yamlContent = match[1];\n const body = content.slice(match[0].length);\n\n try {\n const frontmatter = parseSimpleYaml(yamlContent);\n return { frontmatter, body };\n } catch {\n // If parsing fails, treat as no frontmatter\n return { frontmatter: undefined, body: content };\n }\n}\n\n/**\n * Simple YAML parser for frontmatter.\n *\n * **Limitations** (by design — keeps the dependency count at zero):\n * - Does not handle multi-line strings (block scalars `|` / `>`)\n * - Does not preserve comments\n * - Keys must be simple `\\w+` identifiers (no quoted or special-char keys)\n *\n * Supports:\n * - Multi-level nesting (objects within objects)\n * - Inline arrays `[a, b]`\n * - YAML list items with `- ` syntax (including `- {key: val}` objects)\n * - Null values via `~` or `null`\n */\nfunction parseSimpleYaml(yaml: string): MemoryFrontmatter {\n const lines = yaml.split(\"\\n\");\n return parseYamlBlock(lines, 0, 0, lines.length).value as MemoryFrontmatter;\n}\n\n/**\n * Parse a block of YAML lines at a given indentation level into an object.\n * Returns the parsed value and the line index where parsing stopped.\n */\nfunction parseYamlBlock(\n lines: string[],\n indent: number,\n startIdx: number,\n endIdx: number,\n): { value: Record<string, unknown>; nextIdx: number } {\n const result: Record<string, unknown> = {};\n let i = startIdx;\n\n while (i < endIdx) {\n const line = lines[i];\n if (!line || !line.trim()) {\n i++;\n continue;\n }\n\n const lineIndent = getIndent(line);\n // If we've dedented back beyond our level, stop\n if (lineIndent < indent) break;\n // Skip lines indented deeper than expected (shouldn't happen at top of block)\n if (lineIndent > indent) {\n i++;\n continue;\n }\n\n // Match a key: value line\n const keyMatch = line.match(/^(\\s*)([\\w-]+):\\s*(.*)?$/);\n if (!keyMatch) {\n i++;\n continue;\n }\n\n const [, , key, rawValue] = keyMatch;\n const value = rawValue?.trim() ?? \"\";\n\n if (value === \"\" || value === undefined) {\n // Could be an object or a list starting on next lines\n const nextNonEmpty = findNextNonEmptyLine(lines, i + 1, endIdx);\n if (nextNonEmpty < endIdx) {\n const nextLine = lines[nextNonEmpty]!;\n const nextIndent = getIndent(nextLine);\n if (nextIndent > indent) {\n // Check if it's a list (starts with \"- \")\n if (nextLine.trimStart().startsWith(\"- \")) {\n const listResult = parseYamlList(lines, nextIndent, i + 1, endIdx);\n result[key] = listResult.value;\n i = listResult.nextIdx;\n } else {\n // Nested object\n const blockResult = parseYamlBlock(lines, nextIndent, i + 1, endIdx);\n result[key] = blockResult.value;\n i = blockResult.nextIdx;\n }\n continue;\n }\n }\n // Empty value, no nested content\n result[key] = null;\n i++;\n } else {\n result[key] = parseYamlValue(value);\n i++;\n }\n }\n\n return { value: result, nextIdx: i };\n}\n\n/**\n * Parse a YAML list (lines starting with \"- \") at a given indentation level.\n */\nfunction parseYamlList(\n lines: string[],\n indent: number,\n startIdx: number,\n endIdx: number,\n): { value: unknown[]; nextIdx: number } {\n const result: unknown[] = [];\n let i = startIdx;\n\n while (i < endIdx) {\n const line = lines[i];\n if (!line || !line.trim()) {\n i++;\n continue;\n }\n\n const lineIndent = getIndent(line);\n if (lineIndent < indent) break;\n if (lineIndent > indent) {\n i++;\n continue;\n }\n\n const trimmed = line.trimStart();\n if (!trimmed.startsWith(\"- \")) break;\n\n // Get content after \"- \"\n const itemContent = trimmed.slice(2).trim();\n\n if (itemContent === \"\" || itemContent === undefined) {\n // Sub-block under this list item\n const nextNonEmpty = findNextNonEmptyLine(lines, i + 1, endIdx);\n if (nextNonEmpty < endIdx) {\n const nextIndent = getIndent(lines[nextNonEmpty]!);\n if (nextIndent > indent) {\n const blockResult = parseYamlBlock(lines, nextIndent, i + 1, endIdx);\n result.push(blockResult.value);\n i = blockResult.nextIdx;\n continue;\n }\n }\n result.push(null);\n i++;\n } else {\n // Check for inline key: value (object item like \"- target: foo\")\n const kvMatch = itemContent.match(/^([\\w-]+):\\s*(.*)$/);\n if (kvMatch) {\n // This list item is an object — collect all keys at this item's indent + 2\n const obj: Record<string, unknown> = {};\n const [, firstKey, firstVal] = kvMatch;\n obj[firstKey] = parseYamlValue(firstVal?.trim() ?? \"\");\n\n // Look for continuation keys indented further\n const itemKeyIndent = indent + 2;\n let j = i + 1;\n while (j < endIdx) {\n const nextLine = lines[j];\n if (!nextLine || !nextLine.trim()) {\n j++;\n continue;\n }\n const nextLineIndent = getIndent(nextLine);\n if (nextLineIndent < itemKeyIndent) break;\n if (nextLineIndent === itemKeyIndent) {\n const nextKv = nextLine.match(/^\\s*([\\w-]+):\\s*(.*)$/);\n if (nextKv) {\n const [, nk, nv] = nextKv;\n obj[nk] = parseYamlValue(nv?.trim() ?? \"\");\n j++;\n continue;\n }\n }\n break;\n }\n result.push(obj);\n i = j;\n } else {\n result.push(parseYamlValue(itemContent));\n i++;\n }\n }\n }\n\n return { value: result, nextIdx: i };\n}\n\nfunction getIndent(line: string): number {\n const match = line.match(/^(\\s*)/);\n return match ? match[1].length : 0;\n}\n\nfunction findNextNonEmptyLine(lines: string[], from: number, end: number): number {\n for (let i = from; i < end; i++) {\n if (lines[i]?.trim()) return i;\n }\n return end;\n}\n\n/**\n * Parse a YAML value (handles strings, numbers, booleans, null, arrays)\n */\nfunction parseYamlValue(value: string): unknown {\n // Empty string\n if (value === \"\") return null;\n\n // Remove quotes if present\n if ((value.startsWith('\"') && value.endsWith('\"')) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))) {\n return value.slice(1, -1);\n }\n\n // Null\n if (value === \"null\" || value === \"~\") return null;\n\n // Boolean\n if (value === \"true\") return true;\n if (value === \"false\") return false;\n\n // Number\n const num = Number(value);\n if (!isNaN(num) && value !== \"\") return num;\n\n // Array (simple inline format)\n if (value.startsWith(\"[\") && value.endsWith(\"]\")) {\n const inner = value.slice(1, -1);\n if (inner.trim() === \"\") return [];\n return inner.split(\",\").map((s) => parseYamlValue(s.trim()));\n }\n\n // String\n return value;\n}\n\n/**\n * Serialize frontmatter to YAML string\n */\nexport function serializeFrontmatter(frontmatter: MemoryFrontmatter): string {\n const lines: string[] = [\"---\"];\n\n if (frontmatter.id) {\n lines.push(`id: ${frontmatter.id}`);\n }\n\n if (frontmatter.type) {\n lines.push(`type: ${frontmatter.type}`);\n }\n\n if (frontmatter.session) {\n lines.push(\"session:\");\n const session = frontmatter.session;\n if (session.id) lines.push(` id: ${session.id}`);\n if (session.source) lines.push(` source: ${session.source}`);\n if (session.project) lines.push(` project: ${formatPath(session.project)}`);\n if (session.transcript) lines.push(` transcript: ${formatPath(session.transcript)}`);\n }\n\n if (frontmatter.created) {\n lines.push(`created: ${frontmatter.created}`);\n }\n\n if (frontmatter.updated) {\n lines.push(`updated: ${frontmatter.updated}`);\n }\n\n if (frontmatter.tags && frontmatter.tags.length > 0) {\n lines.push(`tags: [${frontmatter.tags.join(\", \")}]`);\n }\n\n if (frontmatter.domain && frontmatter.domain.length > 0) {\n lines.push(`domain: [${frontmatter.domain.join(\", \")}]`);\n }\n\n if (frontmatter.entities && frontmatter.entities.length > 0) {\n lines.push(`entities: [${frontmatter.entities.join(\", \")}]`);\n }\n\n if (frontmatter.confidence !== undefined) {\n lines.push(`confidence: ${frontmatter.confidence}`);\n }\n\n if (frontmatter.source) {\n lines.push(\"source:\");\n if (frontmatter.source.origin) lines.push(` origin: ${frontmatter.source.origin}`);\n if (frontmatter.source.trajectories && frontmatter.source.trajectories.length > 0) {\n lines.push(` trajectories: [${frontmatter.source.trajectories.join(\", \")}]`);\n }\n if (frontmatter.source.agentId) lines.push(` agentId: ${frontmatter.source.agentId}`);\n }\n\n if (frontmatter.links && frontmatter.links.length > 0) {\n lines.push(\"links:\");\n for (const link of frontmatter.links) {\n lines.push(` - target: ${link.target}`);\n lines.push(` relation: ${link.relation}`);\n if (link.layer) lines.push(` layer: ${link.layer}`);\n }\n }\n\n if (frontmatter.supersedes !== undefined) {\n lines.push(`supersedes: ${frontmatter.supersedes === null ? \"~\" : frontmatter.supersedes}`);\n }\n\n lines.push(\"---\");\n return lines.join(\"\\n\") + \"\\n\";\n}\n\n/**\n * Add or update frontmatter in content\n */\nexport function addFrontmatter(\n content: string,\n frontmatter: MemoryFrontmatter,\n): string {\n const { frontmatter: existing, body } = parseFrontmatter(content);\n\n // Merge with existing frontmatter\n const merged: MemoryFrontmatter = {\n ...existing,\n ...frontmatter,\n session: {\n ...existing?.session,\n ...frontmatter.session,\n },\n };\n\n // Update timestamp\n if (!merged.created) {\n merged.created = new Date().toISOString();\n }\n merged.updated = new Date().toISOString();\n\n return serializeFrontmatter(merged) + body;\n}\n\n/**\n * Add session context as frontmatter to content\n */\nexport function addSessionToContent(\n content: string,\n session: SessionContext,\n): string {\n return addFrontmatter(content, { session });\n}\n\n/**\n * Format path for display (use ~ for home directory)\n */\nfunction formatPath(filePath: string): string {\n const home = os.homedir();\n if (filePath.startsWith(home)) {\n return \"~\" + filePath.slice(home.length);\n }\n return filePath;\n}\n\n/**\n * Extract session context from file content\n */\nexport function extractSession(content: string): SessionContext | undefined {\n const { frontmatter } = parseFrontmatter(content);\n return frontmatter?.session;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,SAAoB;AA0Eb,SAAS,iBAAiB,SAG/B;AACA,QAAM,mBAAmB;AACzB,QAAM,QAAQ,QAAQ,MAAM,gBAAgB;AAE5C,MAAI,CAAC,OAAO;AACV,WAAO,EAAE,aAAa,QAAW,MAAM,QAAQ;AAAA,EACjD;AAEA,QAAM,cAAc,MAAM,CAAC;AAC3B,QAAM,OAAO,QAAQ,MAAM,MAAM,CAAC,EAAE,MAAM;AAE1C,MAAI;AACF,UAAM,cAAc,gBAAgB,WAAW;AAC/C,WAAO,EAAE,aAAa,KA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A,EACF;AAGA,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO,WAAU,oBAAI,KAAK,GAAE,YAAY;AAAA,EAC1C;AACA,SAAO,WAAU,oBAAI,KAAK,GAAE,YAAY;AAExC,SAAO,qBAAqB,MAAM,IAAI;AACxC;AAKO,SAAS,oBACd,SACA,SACQ;AACR,SAAO,eAAe,SAAS,EAAE,QAAQ,CAAC;AAC5C;AAKA,SAAS,WAAW,UAA0B;AAC5C,QAAM,OAAU,WAAQ;AACxB,MAAI,SAAS,WAAW,IAAI,GAAG;AAC7B,WAAO,MAAM,SAAS,MAAM,KAAK,MAAM;AAAA,EACzC;AACA,SAAO;AACT;AAKO,SAAS,eAAe,SAA6C;AAC1E,QAAM,EAAE,YAAY,IAAI,iBAAiB,OAAO;AAChD,SAAO,aAAa;AACtB;","names":[]}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session tracking for memory entries
|
|
3
|
+
*
|
|
4
|
+
* Captures context about the originating session (Claude Code, VS Code, etc.)
|
|
5
|
+
* and stores it as YAML frontmatter in memory files.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Session metadata for memory entries
|
|
9
|
+
*/
|
|
10
|
+
type SessionContext = {
|
|
11
|
+
/** Session identifier (e.g., Claude Code session ID) */
|
|
12
|
+
id?: string;
|
|
13
|
+
/** Source application (claude-code, vscode, cursor, etc.) */
|
|
14
|
+
source?: string;
|
|
15
|
+
/** Project directory path */
|
|
16
|
+
project?: string;
|
|
17
|
+
/** Path to session transcript/log file */
|
|
18
|
+
transcript?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Source provenance for a knowledge entry
|
|
22
|
+
*/
|
|
23
|
+
type KnowledgeSource = {
|
|
24
|
+
origin?: string;
|
|
25
|
+
trajectories?: string[];
|
|
26
|
+
agentId?: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A directional link from this entry to another knowledge node
|
|
30
|
+
*/
|
|
31
|
+
type KnowledgeLink = {
|
|
32
|
+
target: string;
|
|
33
|
+
relation: string;
|
|
34
|
+
layer?: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Frontmatter structure for memory files
|
|
38
|
+
*/
|
|
39
|
+
type MemoryFrontmatter = {
|
|
40
|
+
session?: SessionContext;
|
|
41
|
+
created?: string;
|
|
42
|
+
updated?: string;
|
|
43
|
+
tags?: string[];
|
|
44
|
+
/** Knowledge node identifier */
|
|
45
|
+
id?: string;
|
|
46
|
+
/** Knowledge entry type */
|
|
47
|
+
type?: "observation" | "entity" | "domain-summary" | string;
|
|
48
|
+
/** Domain tags for this knowledge entry */
|
|
49
|
+
domain?: string[];
|
|
50
|
+
/** Entity references in this knowledge entry */
|
|
51
|
+
entities?: string[];
|
|
52
|
+
/** Confidence score 0-1 */
|
|
53
|
+
confidence?: number;
|
|
54
|
+
/** Source provenance */
|
|
55
|
+
source?: KnowledgeSource;
|
|
56
|
+
/** Links to other knowledge nodes */
|
|
57
|
+
links?: KnowledgeLink[];
|
|
58
|
+
/** ID of the entry this supersedes */
|
|
59
|
+
supersedes?: string | null;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Parse YAML frontmatter from content
|
|
63
|
+
*
|
|
64
|
+
* Frontmatter is delimited by --- at the start and end:
|
|
65
|
+
* ```
|
|
66
|
+
* ---
|
|
67
|
+
* session:
|
|
68
|
+
* id: abc123
|
|
69
|
+
* source: claude-code
|
|
70
|
+
* created: 2024-01-27T14:30:00Z
|
|
71
|
+
* ---
|
|
72
|
+
* Actual content here...
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function parseFrontmatter(content: string): {
|
|
76
|
+
frontmatter: MemoryFrontmatter | undefined;
|
|
77
|
+
body: string;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Serialize frontmatter to YAML string
|
|
81
|
+
*/
|
|
82
|
+
declare function serializeFrontmatter(frontmatter: MemoryFrontmatter): string;
|
|
83
|
+
/**
|
|
84
|
+
* Add or update frontmatter in content
|
|
85
|
+
*/
|
|
86
|
+
declare function addFrontmatter(content: string, frontmatter: MemoryFrontmatter): string;
|
|
87
|
+
/**
|
|
88
|
+
* Add session context as frontmatter to content
|
|
89
|
+
*/
|
|
90
|
+
declare function addSessionToContent(content: string, session: SessionContext): string;
|
|
91
|
+
/**
|
|
92
|
+
* Extract session context from file content
|
|
93
|
+
*/
|
|
94
|
+
declare function extractSession(content: string): SessionContext | undefined;
|
|
95
|
+
|
|
96
|
+
export { type KnowledgeLink, type KnowledgeSource, type MemoryFrontmatter, type SessionContext, addFrontmatter, addSessionToContent, extractSession, parseFrontmatter, serializeFrontmatter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minimem",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "A lightweight file-based memory system with vector search for AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,15 +9,18 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.js"
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
13
14
|
},
|
|
14
15
|
"./session": {
|
|
15
16
|
"types": "./dist/session.d.ts",
|
|
16
|
-
"import": "./dist/session.js"
|
|
17
|
+
"import": "./dist/session.js",
|
|
18
|
+
"require": "./dist/session.cjs"
|
|
17
19
|
},
|
|
18
20
|
"./internal": {
|
|
19
21
|
"types": "./dist/internal.d.ts",
|
|
20
|
-
"import": "./dist/internal.js"
|
|
22
|
+
"import": "./dist/internal.js",
|
|
23
|
+
"require": "./dist/internal.cjs"
|
|
21
24
|
}
|
|
22
25
|
},
|
|
23
26
|
"files": [
|
|
@@ -31,7 +34,11 @@
|
|
|
31
34
|
"test:integration": "npx tsx --test src/__tests__/minimem.integration.test.ts",
|
|
32
35
|
"test:cli": "npx tsx --test src/cli/__tests__/commands.test.ts",
|
|
33
36
|
"test:all": "npm run test && npm run test:integration && npm run test:cli",
|
|
34
|
-
"prepublishOnly": "npm run build"
|
|
37
|
+
"prepublishOnly": "npm run build",
|
|
38
|
+
"version:patch": "npm version patch && git push && git push --tags",
|
|
39
|
+
"version:minor": "npm version minor && git push && git push --tags",
|
|
40
|
+
"version:major": "npm version major && git push && git push --tags",
|
|
41
|
+
"publish:npm": "npm run build && npm publish"
|
|
35
42
|
},
|
|
36
43
|
"keywords": [
|
|
37
44
|
"memory",
|