claude-cognitive 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 (196) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +256 -0
  3. package/bin/claude-cognitive.js +9 -0
  4. package/dist/agents/context.d.ts +40 -0
  5. package/dist/agents/context.d.ts.map +1 -0
  6. package/dist/agents/context.js +144 -0
  7. package/dist/agents/context.js.map +1 -0
  8. package/dist/agents/index.d.ts +9 -0
  9. package/dist/agents/index.d.ts.map +1 -0
  10. package/dist/agents/index.js +11 -0
  11. package/dist/agents/index.js.map +1 -0
  12. package/dist/agents/loader.d.ts +48 -0
  13. package/dist/agents/loader.d.ts.map +1 -0
  14. package/dist/agents/loader.js +157 -0
  15. package/dist/agents/loader.js.map +1 -0
  16. package/dist/agents/templates.d.ts +51 -0
  17. package/dist/agents/templates.d.ts.map +1 -0
  18. package/dist/agents/templates.js +186 -0
  19. package/dist/agents/templates.js.map +1 -0
  20. package/dist/agents/types.d.ts +52 -0
  21. package/dist/agents/types.d.ts.map +1 -0
  22. package/dist/agents/types.js +6 -0
  23. package/dist/agents/types.js.map +1 -0
  24. package/dist/cli/commands/config.d.ts +10 -0
  25. package/dist/cli/commands/config.d.ts.map +1 -0
  26. package/dist/cli/commands/config.js +22 -0
  27. package/dist/cli/commands/config.js.map +1 -0
  28. package/dist/cli/commands/index.d.ts +17 -0
  29. package/dist/cli/commands/index.d.ts.map +1 -0
  30. package/dist/cli/commands/index.js +17 -0
  31. package/dist/cli/commands/index.js.map +1 -0
  32. package/dist/cli/commands/init.d.ts +10 -0
  33. package/dist/cli/commands/init.d.ts.map +1 -0
  34. package/dist/cli/commands/init.js +109 -0
  35. package/dist/cli/commands/init.js.map +1 -0
  36. package/dist/cli/commands/install.d.ts +10 -0
  37. package/dist/cli/commands/install.d.ts.map +1 -0
  38. package/dist/cli/commands/install.js +440 -0
  39. package/dist/cli/commands/install.js.map +1 -0
  40. package/dist/cli/commands/learn.d.ts +10 -0
  41. package/dist/cli/commands/learn.d.ts.map +1 -0
  42. package/dist/cli/commands/learn.js +33 -0
  43. package/dist/cli/commands/learn.js.map +1 -0
  44. package/dist/cli/commands/recall.d.ts +10 -0
  45. package/dist/cli/commands/recall.d.ts.map +1 -0
  46. package/dist/cli/commands/recall.js +52 -0
  47. package/dist/cli/commands/recall.js.map +1 -0
  48. package/dist/cli/commands/reflect.d.ts +10 -0
  49. package/dist/cli/commands/reflect.d.ts.map +1 -0
  50. package/dist/cli/commands/reflect.js +48 -0
  51. package/dist/cli/commands/reflect.js.map +1 -0
  52. package/dist/cli/commands/semantic.d.ts +10 -0
  53. package/dist/cli/commands/semantic.d.ts.map +1 -0
  54. package/dist/cli/commands/semantic.js +67 -0
  55. package/dist/cli/commands/semantic.js.map +1 -0
  56. package/dist/cli/commands/serve.d.ts +10 -0
  57. package/dist/cli/commands/serve.d.ts.map +1 -0
  58. package/dist/cli/commands/serve.js +61 -0
  59. package/dist/cli/commands/serve.js.map +1 -0
  60. package/dist/cli/commands/status.d.ts +10 -0
  61. package/dist/cli/commands/status.d.ts.map +1 -0
  62. package/dist/cli/commands/status.js +44 -0
  63. package/dist/cli/commands/status.js.map +1 -0
  64. package/dist/cli/commands/sync.d.ts +10 -0
  65. package/dist/cli/commands/sync.d.ts.map +1 -0
  66. package/dist/cli/commands/sync.js +260 -0
  67. package/dist/cli/commands/sync.js.map +1 -0
  68. package/dist/cli/commands/uninstall.d.ts +10 -0
  69. package/dist/cli/commands/uninstall.d.ts.map +1 -0
  70. package/dist/cli/commands/uninstall.js +205 -0
  71. package/dist/cli/commands/uninstall.js.map +1 -0
  72. package/dist/cli/commands/update-bank.d.ts +10 -0
  73. package/dist/cli/commands/update-bank.d.ts.map +1 -0
  74. package/dist/cli/commands/update-bank.js +129 -0
  75. package/dist/cli/commands/update-bank.js.map +1 -0
  76. package/dist/cli/index.d.ts +6 -0
  77. package/dist/cli/index.d.ts.map +1 -0
  78. package/dist/cli/index.js +56 -0
  79. package/dist/cli/index.js.map +1 -0
  80. package/dist/cli/utils/errors.d.ts +42 -0
  81. package/dist/cli/utils/errors.d.ts.map +1 -0
  82. package/dist/cli/utils/errors.js +78 -0
  83. package/dist/cli/utils/errors.js.map +1 -0
  84. package/dist/cli/utils/index.d.ts +9 -0
  85. package/dist/cli/utils/index.d.ts.map +1 -0
  86. package/dist/cli/utils/index.js +7 -0
  87. package/dist/cli/utils/index.js.map +1 -0
  88. package/dist/cli/utils/output.d.ts +90 -0
  89. package/dist/cli/utils/output.d.ts.map +1 -0
  90. package/dist/cli/utils/output.js +164 -0
  91. package/dist/cli/utils/output.js.map +1 -0
  92. package/dist/client.d.ts +200 -0
  93. package/dist/client.d.ts.map +1 -0
  94. package/dist/client.js +447 -0
  95. package/dist/client.js.map +1 -0
  96. package/dist/config.d.ts +44 -0
  97. package/dist/config.d.ts.map +1 -0
  98. package/dist/config.js +264 -0
  99. package/dist/config.js.map +1 -0
  100. package/dist/errors.d.ts +72 -0
  101. package/dist/errors.d.ts.map +1 -0
  102. package/dist/errors.js +188 -0
  103. package/dist/errors.js.map +1 -0
  104. package/dist/events.d.ts +148 -0
  105. package/dist/events.d.ts.map +1 -0
  106. package/dist/events.js +115 -0
  107. package/dist/events.js.map +1 -0
  108. package/dist/hooks/index.d.ts +7 -0
  109. package/dist/hooks/index.d.ts.map +1 -0
  110. package/dist/hooks/index.js +7 -0
  111. package/dist/hooks/index.js.map +1 -0
  112. package/dist/hooks/inject-context.d.ts +18 -0
  113. package/dist/hooks/inject-context.d.ts.map +1 -0
  114. package/dist/hooks/inject-context.js +57 -0
  115. package/dist/hooks/inject-context.js.map +1 -0
  116. package/dist/hooks/process-session.d.ts +18 -0
  117. package/dist/hooks/process-session.d.ts.map +1 -0
  118. package/dist/hooks/process-session.js +119 -0
  119. package/dist/hooks/process-session.js.map +1 -0
  120. package/dist/index.d.ts +63 -0
  121. package/dist/index.d.ts.map +1 -0
  122. package/dist/index.js +59 -0
  123. package/dist/index.js.map +1 -0
  124. package/dist/learn/analyzers/git.d.ts +62 -0
  125. package/dist/learn/analyzers/git.d.ts.map +1 -0
  126. package/dist/learn/analyzers/git.js +183 -0
  127. package/dist/learn/analyzers/git.js.map +1 -0
  128. package/dist/learn/analyzers/index.d.ts +15 -0
  129. package/dist/learn/analyzers/index.d.ts.map +1 -0
  130. package/dist/learn/analyzers/index.js +10 -0
  131. package/dist/learn/analyzers/index.js.map +1 -0
  132. package/dist/learn/analyzers/package.d.ts +57 -0
  133. package/dist/learn/analyzers/package.d.ts.map +1 -0
  134. package/dist/learn/analyzers/package.js +245 -0
  135. package/dist/learn/analyzers/package.js.map +1 -0
  136. package/dist/learn/analyzers/readme.d.ts +27 -0
  137. package/dist/learn/analyzers/readme.d.ts.map +1 -0
  138. package/dist/learn/analyzers/readme.js +163 -0
  139. package/dist/learn/analyzers/readme.js.map +1 -0
  140. package/dist/learn/analyzers/source.d.ts +70 -0
  141. package/dist/learn/analyzers/source.d.ts.map +1 -0
  142. package/dist/learn/analyzers/source.js +231 -0
  143. package/dist/learn/analyzers/source.js.map +1 -0
  144. package/dist/learn/analyzers/structure.d.ts +39 -0
  145. package/dist/learn/analyzers/structure.d.ts.map +1 -0
  146. package/dist/learn/analyzers/structure.js +172 -0
  147. package/dist/learn/analyzers/structure.js.map +1 -0
  148. package/dist/learn/extractor.d.ts +76 -0
  149. package/dist/learn/extractor.d.ts.map +1 -0
  150. package/dist/learn/extractor.js +302 -0
  151. package/dist/learn/extractor.js.map +1 -0
  152. package/dist/learn/index.d.ts +31 -0
  153. package/dist/learn/index.d.ts.map +1 -0
  154. package/dist/learn/index.js +165 -0
  155. package/dist/learn/index.js.map +1 -0
  156. package/dist/mcp/handlers.d.ts +23 -0
  157. package/dist/mcp/handlers.d.ts.map +1 -0
  158. package/dist/mcp/handlers.js +124 -0
  159. package/dist/mcp/handlers.js.map +1 -0
  160. package/dist/mcp/index.d.ts +32 -0
  161. package/dist/mcp/index.d.ts.map +1 -0
  162. package/dist/mcp/index.js +40 -0
  163. package/dist/mcp/index.js.map +1 -0
  164. package/dist/mcp/server.d.ts +79 -0
  165. package/dist/mcp/server.d.ts.map +1 -0
  166. package/dist/mcp/server.js +277 -0
  167. package/dist/mcp/server.js.map +1 -0
  168. package/dist/mcp/tools.d.ts +59 -0
  169. package/dist/mcp/tools.d.ts.map +1 -0
  170. package/dist/mcp/tools.js +43 -0
  171. package/dist/mcp/tools.js.map +1 -0
  172. package/dist/mcp/types.d.ts +65 -0
  173. package/dist/mcp/types.d.ts.map +1 -0
  174. package/dist/mcp/types.js +6 -0
  175. package/dist/mcp/types.js.map +1 -0
  176. package/dist/mind.d.ts +250 -0
  177. package/dist/mind.d.ts.map +1 -0
  178. package/dist/mind.js +637 -0
  179. package/dist/mind.js.map +1 -0
  180. package/dist/promotion.d.ts +112 -0
  181. package/dist/promotion.d.ts.map +1 -0
  182. package/dist/promotion.js +196 -0
  183. package/dist/promotion.js.map +1 -0
  184. package/dist/retry.d.ts +70 -0
  185. package/dist/retry.d.ts.map +1 -0
  186. package/dist/retry.js +122 -0
  187. package/dist/retry.js.map +1 -0
  188. package/dist/semantic.d.ts +202 -0
  189. package/dist/semantic.d.ts.map +1 -0
  190. package/dist/semantic.js +424 -0
  191. package/dist/semantic.js.map +1 -0
  192. package/dist/types.d.ts +363 -0
  193. package/dist/types.d.ts.map +1 -0
  194. package/dist/types.js +30 -0
  195. package/dist/types.js.map +1 -0
  196. package/package.json +70 -0
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Semantic memory management for claude-cognitive.
3
+ * Manages the .claude/memory.md file with section-based storage.
4
+ * @module semantic
5
+ */
6
+ import type { Observation } from "./events.js";
7
+ /** Default template for new semantic memory files */
8
+ export declare const DEFAULT_TEMPLATE = "## Tech Stack\n\n<!-- Technologies used in this project -->\n\n## Key Decisions\n\n<!-- Important architectural and design decisions -->\n\n## Critical Paths\n\n<!-- Important file relationships and code paths -->\n\n## Observations\n\n<!-- Promoted observations from Hindsight -->\n";
9
+ /** Options for SemanticMemory constructor */
10
+ export interface SemanticMemoryOptions {
11
+ /** Create file with template if it doesn't exist (default: true) */
12
+ createIfMissing?: boolean;
13
+ /** Custom template content for new files */
14
+ template?: string;
15
+ }
16
+ /** Result of parsing a markdown file into sections */
17
+ export interface ParseResult {
18
+ /** Map of section name to content (without header) */
19
+ sections: Map<string, string>;
20
+ /** Original section order for preserving structure */
21
+ order: string[];
22
+ /** Any content before the first H2 header (preamble) */
23
+ preamble: string;
24
+ }
25
+ /**
26
+ * Manages the .claude/memory.md semantic memory file.
27
+ *
28
+ * Provides section-based access to markdown content with:
29
+ * - Lazy loading (load on first access)
30
+ * - Section preservation (maintains structure)
31
+ * - Atomic writes (write to temp, then rename)
32
+ * - Observation promotion support
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const semantic = new SemanticMemory('/path/to/project');
37
+ * await semantic.load();
38
+ *
39
+ * const stack = semantic.get('Tech Stack');
40
+ * semantic.append('Observations', '- New insight (2025-01-02)');
41
+ * await semantic.save();
42
+ * ```
43
+ */
44
+ export declare class SemanticMemory {
45
+ /** Project root directory (stored for reference, used in filePath calculation) */
46
+ readonly projectPath: string;
47
+ /** Relative path to memory file from project root (stored for reference) */
48
+ readonly relativePath: string;
49
+ /** Full absolute path to memory file */
50
+ private readonly filePath;
51
+ /** Options for behavior customization */
52
+ private readonly options;
53
+ /** Parsed sections (null if not loaded) */
54
+ private sections;
55
+ /** Section order for preserving structure */
56
+ private sectionOrder;
57
+ /** Preamble content (before first H2) */
58
+ private preamble;
59
+ /** Whether the file has been modified since last save */
60
+ private dirty;
61
+ /** Lock for preventing concurrent writes */
62
+ private writeLock;
63
+ /**
64
+ * Create a new SemanticMemory instance.
65
+ *
66
+ * @param projectPath - Project root directory
67
+ * @param relativePath - Path to memory file relative to project (default: ".claude/memory.md")
68
+ * @param options - Configuration options
69
+ */
70
+ constructor(projectPath: string, relativePath?: string, options?: SemanticMemoryOptions);
71
+ /**
72
+ * Load the semantic memory file.
73
+ *
74
+ * If the file doesn't exist and createIfMissing is true,
75
+ * creates it with the default template.
76
+ *
77
+ * @throws {Error} If file cannot be read or created
78
+ */
79
+ load(): Promise<void>;
80
+ /**
81
+ * Save the semantic memory file.
82
+ *
83
+ * Uses atomic write (temp file + rename) to prevent corruption.
84
+ * Thread-safe via internal lock.
85
+ *
86
+ * @throws {Error} If file cannot be written
87
+ */
88
+ save(): Promise<void>;
89
+ /**
90
+ * Get content of a section.
91
+ *
92
+ * @param section - Section name (without ##)
93
+ * @returns Section content, or undefined if not found
94
+ */
95
+ get(section: string): string | undefined;
96
+ /**
97
+ * Set content of a section.
98
+ *
99
+ * If section doesn't exist, creates it at the end.
100
+ *
101
+ * @param section - Section name (without ##)
102
+ * @param content - New content (without header)
103
+ */
104
+ set(section: string, content: string): void;
105
+ /**
106
+ * Append an item to a section.
107
+ *
108
+ * If section doesn't exist, creates it.
109
+ * Ensures proper newline handling.
110
+ *
111
+ * @param section - Section name (without ##)
112
+ * @param item - Item to append (will be added on new line)
113
+ */
114
+ append(section: string, item: string): void;
115
+ /**
116
+ * Check if a section exists.
117
+ *
118
+ * @param section - Section name
119
+ * @returns True if section exists
120
+ */
121
+ has(section: string): boolean;
122
+ /**
123
+ * Get all section names.
124
+ *
125
+ * @returns Array of section names in order
126
+ */
127
+ getSectionNames(): string[];
128
+ /**
129
+ * Delete a section.
130
+ *
131
+ * @param section - Section name to delete
132
+ * @returns True if section was deleted
133
+ */
134
+ delete(section: string): boolean;
135
+ /**
136
+ * Format semantic memory as context string for injection.
137
+ *
138
+ * Returns the full file content with a header, suitable for
139
+ * including in session context.
140
+ *
141
+ * @returns Formatted context string
142
+ */
143
+ toContext(): string;
144
+ /**
145
+ * Promote an observation to the Observations section.
146
+ *
147
+ * Formats the observation with timestamp and appends to
148
+ * the Observations section.
149
+ *
150
+ * @param observation - Observation to promote
151
+ * @param autoSave - Whether to save immediately (default: true)
152
+ */
153
+ promoteObservation(observation: Observation, autoSave?: boolean): Promise<void>;
154
+ /**
155
+ * Get the absolute file path.
156
+ */
157
+ getFilePath(): string;
158
+ /**
159
+ * Check if changes are pending save.
160
+ */
161
+ isDirty(): boolean;
162
+ /**
163
+ * Check if file is loaded.
164
+ */
165
+ isLoaded(): boolean;
166
+ /**
167
+ * Parse markdown content into sections.
168
+ * @internal
169
+ */
170
+ private parseMarkdown;
171
+ /**
172
+ * Create file with default template.
173
+ * @internal
174
+ */
175
+ private createWithTemplate;
176
+ /**
177
+ * Perform the actual save operation.
178
+ * @internal
179
+ */
180
+ private performSave;
181
+ /**
182
+ * Convert sections back to markdown.
183
+ * @internal
184
+ */
185
+ private toMarkdown;
186
+ /**
187
+ * Check if content has non-comment text.
188
+ * @internal
189
+ */
190
+ private hasNonCommentContent;
191
+ /**
192
+ * Assert that sections are loaded.
193
+ * @internal
194
+ */
195
+ private assertLoaded;
196
+ /**
197
+ * Check if error is a file not found error.
198
+ * @internal
199
+ */
200
+ private isNotFoundError;
201
+ }
202
+ //# sourceMappingURL=semantic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic.d.ts","sourceRoot":"","sources":["../src/semantic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAM/C,qDAAqD;AACrD,eAAO,MAAM,gBAAgB,gSAe5B,CAAC;AASF,6CAA6C;AAC7C,MAAM,WAAW,qBAAqB;IACpC,oEAAoE;IACpE,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,sDAAsD;AACtD,MAAM,WAAW,WAAW;IAC1B,sDAAsD;IACtD,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,sDAAsD;IACtD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,wDAAwD;IACxD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAMD;;;;;;;;;;;;;;;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G,kBAAkB,CACtB,WAAW,EAAE,WAAW,EACxB,QAAQ,GAAE,OAAc,GACvB,OAAO,CAAC,IAAI,CAAC;IAiBhB;;OAEG;IACH,WAAW,IAAI,MAAM;IAIrB;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,QAAQ,IAAI,OAAO;IAQnB;;;OAGG;IACH,OAAO,CAAC,aAAa;IAuCrB;;;OAGG;YACW,kBAAkB;IAgBhC;;;OAGG;YACW,WAAW;IAYzB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAmBlB;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAM5B;;;OAGG;IACH,OAAO,CAAC,YAAY;IAMpB;;;OAGG;IACH,OAAO,CAAC,eAAe;CAOxB"}
@@ -0,0 +1,424 @@
1
+ /**
2
+ * Semantic memory management for claude-cognitive.
3
+ * Manages the .claude/memory.md file with section-based storage.
4
+ * @module semantic
5
+ */
6
+ import { readFile, writeFile, mkdir } from "node:fs/promises";
7
+ import { dirname, join, isAbsolute } from "node:path";
8
+ // ============================================
9
+ // Constants
10
+ // ============================================
11
+ /** Default template for new semantic memory files */
12
+ export const DEFAULT_TEMPLATE = `## Tech Stack
13
+
14
+ <!-- Technologies used in this project -->
15
+
16
+ ## Key Decisions
17
+
18
+ <!-- Important architectural and design decisions -->
19
+
20
+ ## Critical Paths
21
+
22
+ <!-- Important file relationships and code paths -->
23
+
24
+ ## Observations
25
+
26
+ <!-- Promoted observations from Hindsight -->
27
+ `;
28
+ /** Header regex to match H2 sections */
29
+ const SECTION_HEADER_REGEX = /^##\s+(.+)$/;
30
+ // ============================================
31
+ // SemanticMemory Class
32
+ // ============================================
33
+ /**
34
+ * Manages the .claude/memory.md semantic memory file.
35
+ *
36
+ * Provides section-based access to markdown content with:
37
+ * - Lazy loading (load on first access)
38
+ * - Section preservation (maintains structure)
39
+ * - Atomic writes (write to temp, then rename)
40
+ * - Observation promotion support
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const semantic = new SemanticMemory('/path/to/project');
45
+ * await semantic.load();
46
+ *
47
+ * const stack = semantic.get('Tech Stack');
48
+ * semantic.append('Observations', '- New insight (2025-01-02)');
49
+ * await semantic.save();
50
+ * ```
51
+ */
52
+ export class SemanticMemory {
53
+ /** Project root directory (stored for reference, used in filePath calculation) */
54
+ projectPath;
55
+ /** Relative path to memory file from project root (stored for reference) */
56
+ relativePath;
57
+ /** Full absolute path to memory file */
58
+ filePath;
59
+ /** Options for behavior customization */
60
+ options;
61
+ /** Parsed sections (null if not loaded) */
62
+ sections = null;
63
+ /** Section order for preserving structure */
64
+ sectionOrder = [];
65
+ /** Preamble content (before first H2) */
66
+ preamble = "";
67
+ /** Whether the file has been modified since last save */
68
+ dirty = false;
69
+ /** Lock for preventing concurrent writes */
70
+ writeLock = null;
71
+ /**
72
+ * Create a new SemanticMemory instance.
73
+ *
74
+ * @param projectPath - Project root directory
75
+ * @param relativePath - Path to memory file relative to project (default: ".claude/memory.md")
76
+ * @param options - Configuration options
77
+ */
78
+ constructor(projectPath, relativePath = ".claude/memory.md", options = {}) {
79
+ this.projectPath = projectPath;
80
+ this.relativePath = relativePath;
81
+ this.filePath = isAbsolute(relativePath)
82
+ ? relativePath
83
+ : join(projectPath, relativePath);
84
+ this.options = {
85
+ createIfMissing: options.createIfMissing ?? true,
86
+ template: options.template ?? DEFAULT_TEMPLATE,
87
+ };
88
+ }
89
+ // ============================================
90
+ // Core Operations
91
+ // ============================================
92
+ /**
93
+ * Load the semantic memory file.
94
+ *
95
+ * If the file doesn't exist and createIfMissing is true,
96
+ * creates it with the default template.
97
+ *
98
+ * @throws {Error} If file cannot be read or created
99
+ */
100
+ async load() {
101
+ try {
102
+ const content = await readFile(this.filePath, "utf-8");
103
+ const parsed = this.parseMarkdown(content);
104
+ this.sections = parsed.sections;
105
+ this.sectionOrder = parsed.order;
106
+ this.preamble = parsed.preamble;
107
+ this.dirty = false;
108
+ }
109
+ catch (error) {
110
+ if (this.isNotFoundError(error) && this.options.createIfMissing) {
111
+ // Try to create directory and file with template
112
+ try {
113
+ await this.createWithTemplate();
114
+ }
115
+ catch {
116
+ // If we can't create the file, just initialize with empty sections
117
+ // This allows the system to continue even if the directory doesn't exist
118
+ this.sections = new Map();
119
+ this.sectionOrder = [];
120
+ this.preamble = "";
121
+ this.dirty = false;
122
+ }
123
+ }
124
+ else {
125
+ throw error;
126
+ }
127
+ }
128
+ }
129
+ /**
130
+ * Save the semantic memory file.
131
+ *
132
+ * Uses atomic write (temp file + rename) to prevent corruption.
133
+ * Thread-safe via internal lock.
134
+ *
135
+ * @throws {Error} If file cannot be written
136
+ */
137
+ async save() {
138
+ if (!this.sections) {
139
+ throw new Error("SemanticMemory not loaded. Call load() first.");
140
+ }
141
+ if (!this.dirty) {
142
+ return; // No changes to save
143
+ }
144
+ // Wait for any pending write to complete
145
+ if (this.writeLock) {
146
+ await this.writeLock;
147
+ }
148
+ // Create new write lock
149
+ this.writeLock = this.performSave();
150
+ await this.writeLock;
151
+ this.writeLock = null;
152
+ }
153
+ /**
154
+ * Get content of a section.
155
+ *
156
+ * @param section - Section name (without ##)
157
+ * @returns Section content, or undefined if not found
158
+ */
159
+ get(section) {
160
+ this.assertLoaded();
161
+ return this.sections.get(section);
162
+ }
163
+ /**
164
+ * Set content of a section.
165
+ *
166
+ * If section doesn't exist, creates it at the end.
167
+ *
168
+ * @param section - Section name (without ##)
169
+ * @param content - New content (without header)
170
+ */
171
+ set(section, content) {
172
+ this.assertLoaded();
173
+ if (!this.sections.has(section)) {
174
+ this.sectionOrder.push(section);
175
+ }
176
+ this.sections.set(section, content);
177
+ this.dirty = true;
178
+ }
179
+ /**
180
+ * Append an item to a section.
181
+ *
182
+ * If section doesn't exist, creates it.
183
+ * Ensures proper newline handling.
184
+ *
185
+ * @param section - Section name (without ##)
186
+ * @param item - Item to append (will be added on new line)
187
+ */
188
+ append(section, item) {
189
+ this.assertLoaded();
190
+ const existing = this.sections.get(section) ?? "";
191
+ const trimmed = existing.trimEnd();
192
+ const separator = trimmed.length > 0 ? "\n" : "";
193
+ this.set(section, trimmed + separator + item);
194
+ }
195
+ /**
196
+ * Check if a section exists.
197
+ *
198
+ * @param section - Section name
199
+ * @returns True if section exists
200
+ */
201
+ has(section) {
202
+ this.assertLoaded();
203
+ return this.sections.has(section);
204
+ }
205
+ /**
206
+ * Get all section names.
207
+ *
208
+ * @returns Array of section names in order
209
+ */
210
+ getSectionNames() {
211
+ this.assertLoaded();
212
+ return [...this.sectionOrder];
213
+ }
214
+ /**
215
+ * Delete a section.
216
+ *
217
+ * @param section - Section name to delete
218
+ * @returns True if section was deleted
219
+ */
220
+ delete(section) {
221
+ this.assertLoaded();
222
+ const deleted = this.sections.delete(section);
223
+ if (deleted) {
224
+ this.sectionOrder = this.sectionOrder.filter((s) => s !== section);
225
+ this.dirty = true;
226
+ }
227
+ return deleted;
228
+ }
229
+ // ============================================
230
+ // Context Formatting
231
+ // ============================================
232
+ /**
233
+ * Format semantic memory as context string for injection.
234
+ *
235
+ * Returns the full file content with a header, suitable for
236
+ * including in session context.
237
+ *
238
+ * @returns Formatted context string
239
+ */
240
+ toContext() {
241
+ this.assertLoaded();
242
+ const sectionParts = [];
243
+ for (const section of this.sectionOrder) {
244
+ const content = this.sections.get(section);
245
+ // Check if content has meaningful text (not just comments)
246
+ if (content && this.hasNonCommentContent(content)) {
247
+ sectionParts.push(`## ${section}`);
248
+ sectionParts.push(content.trim());
249
+ sectionParts.push("");
250
+ }
251
+ }
252
+ // If no sections with content, return empty string
253
+ if (sectionParts.length === 0) {
254
+ return "";
255
+ }
256
+ // Add header and join
257
+ const parts = [];
258
+ parts.push("### Semantic Memory (.claude/memory.md)");
259
+ parts.push("");
260
+ parts.push(...sectionParts);
261
+ return parts.join("\n").trimEnd();
262
+ }
263
+ // ============================================
264
+ // Observation Promotion
265
+ // ============================================
266
+ /**
267
+ * Promote an observation to the Observations section.
268
+ *
269
+ * Formats the observation with timestamp and appends to
270
+ * the Observations section.
271
+ *
272
+ * @param observation - Observation to promote
273
+ * @param autoSave - Whether to save immediately (default: true)
274
+ */
275
+ async promoteObservation(observation, autoSave = true) {
276
+ this.assertLoaded();
277
+ const date = new Date().toISOString().split("T")[0]; // YYYY-MM-DD
278
+ const entry = `- ${observation.text} (promoted: ${date}, confidence: ${observation.confidence.toFixed(2)})`;
279
+ this.append("Observations", entry);
280
+ if (autoSave) {
281
+ await this.save();
282
+ }
283
+ }
284
+ // ============================================
285
+ // Utilities
286
+ // ============================================
287
+ /**
288
+ * Get the absolute file path.
289
+ */
290
+ getFilePath() {
291
+ return this.filePath;
292
+ }
293
+ /**
294
+ * Check if changes are pending save.
295
+ */
296
+ isDirty() {
297
+ return this.dirty;
298
+ }
299
+ /**
300
+ * Check if file is loaded.
301
+ */
302
+ isLoaded() {
303
+ return this.sections !== null;
304
+ }
305
+ // ============================================
306
+ // Private Methods
307
+ // ============================================
308
+ /**
309
+ * Parse markdown content into sections.
310
+ * @internal
311
+ */
312
+ parseMarkdown(content) {
313
+ const lines = content.split("\n");
314
+ const sections = new Map();
315
+ const order = [];
316
+ let preamble = "";
317
+ let currentSection = null;
318
+ let currentContent = [];
319
+ for (const line of lines) {
320
+ const match = line.match(SECTION_HEADER_REGEX);
321
+ if (match && match[1]) {
322
+ // Save previous section
323
+ if (currentSection !== null) {
324
+ sections.set(currentSection, currentContent.join("\n"));
325
+ }
326
+ else if (currentContent.length > 0) {
327
+ preamble = currentContent.join("\n");
328
+ }
329
+ // Start new section
330
+ currentSection = match[1].trim();
331
+ order.push(currentSection);
332
+ currentContent = [];
333
+ }
334
+ else {
335
+ currentContent.push(line);
336
+ }
337
+ }
338
+ // Save final section
339
+ if (currentSection !== null) {
340
+ sections.set(currentSection, currentContent.join("\n"));
341
+ }
342
+ else if (currentContent.length > 0) {
343
+ preamble = currentContent.join("\n");
344
+ }
345
+ return { sections, order, preamble };
346
+ }
347
+ /**
348
+ * Create file with default template.
349
+ * @internal
350
+ */
351
+ async createWithTemplate() {
352
+ // Ensure directory exists
353
+ const dir = dirname(this.filePath);
354
+ await mkdir(dir, { recursive: true });
355
+ // Write template
356
+ await writeFile(this.filePath, this.options.template, "utf-8");
357
+ // Parse the template
358
+ const parsed = this.parseMarkdown(this.options.template);
359
+ this.sections = parsed.sections;
360
+ this.sectionOrder = parsed.order;
361
+ this.preamble = parsed.preamble;
362
+ this.dirty = false;
363
+ }
364
+ /**
365
+ * Perform the actual save operation.
366
+ * @internal
367
+ */
368
+ async performSave() {
369
+ const content = this.toMarkdown();
370
+ // Ensure directory exists (in case it was deleted)
371
+ const dir = dirname(this.filePath);
372
+ await mkdir(dir, { recursive: true });
373
+ // Write file
374
+ await writeFile(this.filePath, content, "utf-8");
375
+ this.dirty = false;
376
+ }
377
+ /**
378
+ * Convert sections back to markdown.
379
+ * @internal
380
+ */
381
+ toMarkdown() {
382
+ const parts = [];
383
+ // Include preamble if present
384
+ if (this.preamble.trim().length > 0) {
385
+ parts.push(this.preamble);
386
+ parts.push("");
387
+ }
388
+ // Add sections in order
389
+ for (const section of this.sectionOrder) {
390
+ const content = this.sections.get(section) ?? "";
391
+ parts.push(`## ${section}`);
392
+ parts.push(content);
393
+ }
394
+ return parts.join("\n");
395
+ }
396
+ /**
397
+ * Check if content has non-comment text.
398
+ * @internal
399
+ */
400
+ hasNonCommentContent(content) {
401
+ // Remove HTML comments and check if anything meaningful remains
402
+ const withoutComments = content.replace(/<!--[\s\S]*?-->/g, "");
403
+ return withoutComments.trim().length > 0;
404
+ }
405
+ /**
406
+ * Assert that sections are loaded.
407
+ * @internal
408
+ */
409
+ assertLoaded() {
410
+ if (!this.sections) {
411
+ throw new Error("SemanticMemory not loaded. Call load() first.");
412
+ }
413
+ }
414
+ /**
415
+ * Check if error is a file not found error.
416
+ * @internal
417
+ */
418
+ isNotFoundError(error) {
419
+ return (error instanceof Error &&
420
+ "code" in error &&
421
+ error.code === "ENOENT");
422
+ }
423
+ }
424
+ //# sourceMappingURL=semantic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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