memorandum-mcp 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 (52) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +237 -0
  3. package/README.ru.md +237 -0
  4. package/dist/config.d.ts +36 -0
  5. package/dist/config.js +63 -0
  6. package/dist/config.js.map +1 -0
  7. package/dist/document-store.d.ts +145 -0
  8. package/dist/document-store.js +682 -0
  9. package/dist/document-store.js.map +1 -0
  10. package/dist/document-tools.d.ts +10 -0
  11. package/dist/document-tools.js +101 -0
  12. package/dist/document-tools.js.map +1 -0
  13. package/dist/document-types.d.ts +147 -0
  14. package/dist/document-types.js +125 -0
  15. package/dist/document-types.js.map +1 -0
  16. package/dist/embedder.d.ts +55 -0
  17. package/dist/embedder.js +152 -0
  18. package/dist/embedder.js.map +1 -0
  19. package/dist/embedding-queue.d.ts +66 -0
  20. package/dist/embedding-queue.js +152 -0
  21. package/dist/embedding-queue.js.map +1 -0
  22. package/dist/errors.d.ts +26 -0
  23. package/dist/errors.js +46 -0
  24. package/dist/errors.js.map +1 -0
  25. package/dist/index.d.ts +9 -0
  26. package/dist/index.js +147 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/logger.d.ts +12 -0
  29. package/dist/logger.js +22 -0
  30. package/dist/logger.js.map +1 -0
  31. package/dist/semantic-index.d.ts +126 -0
  32. package/dist/semantic-index.js +427 -0
  33. package/dist/semantic-index.js.map +1 -0
  34. package/dist/semantic-tools.d.ts +10 -0
  35. package/dist/semantic-tools.js +80 -0
  36. package/dist/semantic-tools.js.map +1 -0
  37. package/dist/semantic-types.d.ts +161 -0
  38. package/dist/semantic-types.js +101 -0
  39. package/dist/semantic-types.js.map +1 -0
  40. package/dist/store.d.ts +130 -0
  41. package/dist/store.js +389 -0
  42. package/dist/store.js.map +1 -0
  43. package/dist/tools.d.ts +15 -0
  44. package/dist/tools.js +104 -0
  45. package/dist/tools.js.map +1 -0
  46. package/dist/types.d.ts +97 -0
  47. package/dist/types.js +88 -0
  48. package/dist/types.js.map +1 -0
  49. package/dist/vector-store.d.ts +85 -0
  50. package/dist/vector-store.js +241 -0
  51. package/dist/vector-store.js.map +1 -0
  52. package/package.json +50 -0
@@ -0,0 +1,145 @@
1
+ import type { Logger } from 'pino';
2
+ import type { Config, ResolvedPaths } from './config.js';
3
+ import type { IndexFile, DocumentRestoreResult } from './document-types.js';
4
+ import type { SemanticIndex } from './semantic-index.js';
5
+ /**
6
+ * Manages document storage, indexing, and CRUD operations.
7
+ * Supports inline (markdown with frontmatter) and binary (blob with YAML sidecar) documents.
8
+ */
9
+ export declare class DocumentStore {
10
+ private readonly config;
11
+ private readonly logger;
12
+ private readonly documentsPath;
13
+ private readonly blobsPath;
14
+ private readonly indexPath;
15
+ private index;
16
+ private semanticIndex;
17
+ private dirty;
18
+ constructor(config: Config, paths: ResolvedPaths, logger: Logger);
19
+ /** Assigns the semantic index used for embedding-based search. */
20
+ setSemanticIndex(index: SemanticIndex): void;
21
+ /** Creates the documents and blobs directories if they do not already exist. */
22
+ ensureDirectories(): void;
23
+ /** Loads the document index from disk, rebuilding it if the file is missing or corrupt. */
24
+ loadIndex(): void;
25
+ /**
26
+ * Persists the in-memory index to disk if it has been modified.
27
+ * @returns `true` if the index was written, `false` if no save was needed.
28
+ */
29
+ saveIndex(): boolean;
30
+ /** Reconstructs the index by scanning all document files on disk. */
31
+ rebuildIndex(): void;
32
+ /**
33
+ * Extracts YAML frontmatter and body from a markdown string.
34
+ * @param content - Raw file content with optional `---` delimited frontmatter.
35
+ * @returns Parsed metadata object and the remaining body text.
36
+ */
37
+ parseFrontmatter(content: string): {
38
+ metadata: Record<string, unknown>;
39
+ body: string;
40
+ };
41
+ /**
42
+ * Combines metadata and body into a markdown string with YAML frontmatter.
43
+ * @param metadata - Key-value pairs to serialize as frontmatter.
44
+ * @param body - The document body text.
45
+ * @returns Formatted string with `---` delimited frontmatter followed by the body.
46
+ */
47
+ serializeFrontmatter(metadata: Record<string, unknown>, body: string): string;
48
+ /**
49
+ * Writes a file atomically by writing to a temporary file first, then renaming.
50
+ * @param filePath - Destination file path.
51
+ * @param content - String or Buffer content to write.
52
+ */
53
+ atomicWriteFile(filePath: string, content: string | Buffer): void;
54
+ /**
55
+ * Generates and returns the next unique document ID (e.g., `doc-001`).
56
+ * Increments the internal counter and marks the index as dirty.
57
+ */
58
+ getNextId(): string;
59
+ /** Returns the current in-memory index. */
60
+ getIndex(): IndexFile;
61
+ /** Replaces the in-memory index with the provided one. */
62
+ setIndex(index: IndexFile): void;
63
+ /** Absolute path to the documents directory. */
64
+ get documentsDir(): string;
65
+ /** Absolute path to the blobs subdirectory. */
66
+ get blobsDir(): string;
67
+ /** Maximum allowed document size in bytes. */
68
+ get maxDocumentSize(): number;
69
+ private validateDocumentId;
70
+ private validateBodySize;
71
+ private validateMetadataKeys;
72
+ private resolveFilePath;
73
+ private injectFileContent;
74
+ /**
75
+ * Creates or updates a document based on the `_mode` field.
76
+ * Handles both inline (text) and binary content, including file imports.
77
+ * @returns The document ID and whether it was newly created.
78
+ */
79
+ write(input: {
80
+ _mode: 'create' | 'update';
81
+ id?: string;
82
+ title?: string;
83
+ content_type?: string;
84
+ topic?: string;
85
+ description?: string;
86
+ tags?: string[];
87
+ body?: string;
88
+ file_path?: string;
89
+ metadata?: Record<string, unknown>;
90
+ }): {
91
+ id: string;
92
+ created: boolean;
93
+ };
94
+ private writeCreate;
95
+ private writeUpdate;
96
+ /**
97
+ * Reads a document by ID, returning its metadata and optionally its body content.
98
+ * @param input.id - Document ID (e.g., `doc-001`).
99
+ * @param input.include_body - Whether to include the body content (defaults to `true`).
100
+ * @returns Document metadata and body. Binary bodies are base64-encoded.
101
+ */
102
+ read(input: {
103
+ id: string;
104
+ include_body?: boolean;
105
+ }): Record<string, unknown>;
106
+ /**
107
+ * Lists documents matching the given filters.
108
+ * Supports filtering by tag, topic, content type, text search, and custom metadata.
109
+ * @returns Matching documents (up to `limit`) and the total count.
110
+ */
111
+ list(input: {
112
+ tag?: string;
113
+ topic?: string;
114
+ content_type?: string;
115
+ search?: string;
116
+ metadata?: Record<string, unknown>;
117
+ limit?: number;
118
+ }): {
119
+ documents: Record<string, unknown>[];
120
+ total: number;
121
+ };
122
+ /**
123
+ * Deletes a document by ID, removing its files from disk and the index entry.
124
+ * @param input.id - Document ID to delete.
125
+ * @returns `{ deleted: true }` if found and removed, `{ deleted: false }` if not found.
126
+ */
127
+ delete(input: {
128
+ id: string;
129
+ }): {
130
+ deleted: boolean;
131
+ };
132
+ /**
133
+ * Restores a document from the store to a file on disk.
134
+ * Verifies SHA256 integrity for binary documents. Refuses to overwrite
135
+ * existing files unless force=true.
136
+ *
137
+ * @param input - Restore parameters: id, target_path, force
138
+ * @returns Result with success status, path, and optional integrity info
139
+ */
140
+ restore(input: {
141
+ id: string;
142
+ target_path: string;
143
+ force: boolean;
144
+ }): DocumentRestoreResult;
145
+ }