@chude/memory 4.0.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 (184) hide show
  1. package/README.md +294 -0
  2. package/dist/application/index.d.ts +6 -0
  3. package/dist/application/services/ambient-context-service.d.ts +90 -0
  4. package/dist/application/services/backfill-service.d.ts +71 -0
  5. package/dist/application/services/budget-allocator.d.ts +57 -0
  6. package/dist/application/services/embedding-service.d.ts +131 -0
  7. package/dist/application/services/export-service.d.ts +225 -0
  8. package/dist/application/services/extraction-pipeline.d.ts +50 -0
  9. package/dist/application/services/friction-service.d.ts +148 -0
  10. package/dist/application/services/fts-sanitizer.d.ts +25 -0
  11. package/dist/application/services/index.d.ts +34 -0
  12. package/dist/application/services/llm-extractor.d.ts +96 -0
  13. package/dist/application/services/memory-file-sync-service.d.ts +58 -0
  14. package/dist/application/services/pattern-extractor.d.ts +95 -0
  15. package/dist/application/services/recovery-service.d.ts +81 -0
  16. package/dist/application/services/rrf-fusion.d.ts +53 -0
  17. package/dist/application/services/smart-context-service.d.ts +126 -0
  18. package/dist/application/services/sync-service.d.ts +157 -0
  19. package/dist/application/services/temporal-decay.d.ts +62 -0
  20. package/dist/domain/entities/backfill-state.d.ts +56 -0
  21. package/dist/domain/entities/entity.d.ts +131 -0
  22. package/dist/domain/entities/extraction-state.d.ts +128 -0
  23. package/dist/domain/entities/fact.d.ts +59 -0
  24. package/dist/domain/entities/friction-entry.d.ts +84 -0
  25. package/dist/domain/entities/index.d.ts +15 -0
  26. package/dist/domain/entities/link.d.ts +74 -0
  27. package/dist/domain/entities/memory-file.d.ts +78 -0
  28. package/dist/domain/entities/message.d.ts +70 -0
  29. package/dist/domain/entities/session.d.ts +93 -0
  30. package/dist/domain/entities/tool-use.d.ts +85 -0
  31. package/dist/domain/errors/error-codes.d.ts +37 -0
  32. package/dist/domain/errors/index.d.ts +8 -0
  33. package/dist/domain/errors/memory-error.d.ts +52 -0
  34. package/dist/domain/errors/unknown-error.d.ts +9 -0
  35. package/dist/domain/index.d.ts +11 -0
  36. package/dist/domain/ports/embedding.d.ts +96 -0
  37. package/dist/domain/ports/extraction.d.ts +13 -0
  38. package/dist/domain/ports/index.d.ts +14 -0
  39. package/dist/domain/ports/redactor.d.ts +17 -0
  40. package/dist/domain/ports/repositories.d.ts +658 -0
  41. package/dist/domain/ports/services.d.ts +180 -0
  42. package/dist/domain/ports/signals.d.ts +82 -0
  43. package/dist/domain/ports/sources.d.ts +122 -0
  44. package/dist/domain/ports/types.d.ts +150 -0
  45. package/dist/domain/services/content-extractor.d.ts +61 -0
  46. package/dist/domain/services/index.d.ts +8 -0
  47. package/dist/domain/services/path-decoder.d.ts +56 -0
  48. package/dist/domain/services/query-parser.d.ts +47 -0
  49. package/dist/domain/value-objects/embedding-config.d.ts +56 -0
  50. package/dist/domain/value-objects/embedding-result.d.ts +46 -0
  51. package/dist/domain/value-objects/index.d.ts +10 -0
  52. package/dist/domain/value-objects/project-path.d.ts +92 -0
  53. package/dist/domain/value-objects/search-query.d.ts +30 -0
  54. package/dist/domain/value-objects/search-result.d.ts +92 -0
  55. package/dist/index.d.ts +15 -0
  56. package/dist/index.js +1548 -0
  57. package/dist/infrastructure/database/connection.d.ts +161 -0
  58. package/dist/infrastructure/database/event-log.d.ts +22 -0
  59. package/dist/infrastructure/database/health-checker.d.ts +248 -0
  60. package/dist/infrastructure/database/index.d.ts +11 -0
  61. package/dist/infrastructure/database/repositories/backfill-state-repository.d.ts +19 -0
  62. package/dist/infrastructure/database/repositories/embedding-repository.d.ts +121 -0
  63. package/dist/infrastructure/database/repositories/entity-repository.d.ts +73 -0
  64. package/dist/infrastructure/database/repositories/extraction-log-repository.d.ts +17 -0
  65. package/dist/infrastructure/database/repositories/extraction-state-repository.d.ts +52 -0
  66. package/dist/infrastructure/database/repositories/fact-repository.d.ts +25 -0
  67. package/dist/infrastructure/database/repositories/friction-repository.d.ts +41 -0
  68. package/dist/infrastructure/database/repositories/index.d.ts +17 -0
  69. package/dist/infrastructure/database/repositories/link-repository.d.ts +64 -0
  70. package/dist/infrastructure/database/repositories/memory-file-repository.d.ts +28 -0
  71. package/dist/infrastructure/database/repositories/message-repository.d.ts +87 -0
  72. package/dist/infrastructure/database/repositories/session-repository.d.ts +125 -0
  73. package/dist/infrastructure/database/repositories/tool-use-repository.d.ts +72 -0
  74. package/dist/infrastructure/database/schema.d.ts +203 -0
  75. package/dist/infrastructure/database/services/context-service.d.ts +93 -0
  76. package/dist/infrastructure/database/services/hybrid-search-service.d.ts +156 -0
  77. package/dist/infrastructure/database/services/index.d.ts +10 -0
  78. package/dist/infrastructure/database/services/search-service.d.ts +57 -0
  79. package/dist/infrastructure/database/services/stats-service.d.ts +36 -0
  80. package/dist/infrastructure/embedding/background-embedder.d.ts +125 -0
  81. package/dist/infrastructure/embedding/embedding-provider-factory.d.ts +44 -0
  82. package/dist/infrastructure/embedding/index.d.ts +5 -0
  83. package/dist/infrastructure/embedding/ollama-provider.d.ts +41 -0
  84. package/dist/infrastructure/embedding/openai-provider.d.ts +38 -0
  85. package/dist/infrastructure/embedding/transformers-js-provider.d.ts +34 -0
  86. package/dist/infrastructure/external/index.d.ts +7 -0
  87. package/dist/infrastructure/external/qmd-runner.d.ts +36 -0
  88. package/dist/infrastructure/hooks/auto-memory-writer.d.ts +52 -0
  89. package/dist/infrastructure/hooks/config-manager.d.ts +237 -0
  90. package/dist/infrastructure/hooks/git-syncer.d.ts +44 -0
  91. package/dist/infrastructure/hooks/hook-runner.d.ts +126 -0
  92. package/dist/infrastructure/hooks/index.d.ts +12 -0
  93. package/dist/infrastructure/hooks/log-writer.d.ts +106 -0
  94. package/dist/infrastructure/hooks/settings-manager.d.ts +163 -0
  95. package/dist/infrastructure/hooks/sync-hook-script.d.ts +83 -0
  96. package/dist/infrastructure/hooks/sync-logger-adapter.d.ts +17 -0
  97. package/dist/infrastructure/index.d.ts +11 -0
  98. package/dist/infrastructure/llm/anthropic-extractor.d.ts +20 -0
  99. package/dist/infrastructure/llm/claude-cli-extractor.d.ts +14 -0
  100. package/dist/infrastructure/llm/claude-summary-generator.d.ts +14 -0
  101. package/dist/infrastructure/llm/extraction-helper.d.ts +16 -0
  102. package/dist/infrastructure/llm/ollama-extractor.d.ts +20 -0
  103. package/dist/infrastructure/llm/openai-extractor.d.ts +23 -0
  104. package/dist/infrastructure/migration.d.ts +103 -0
  105. package/dist/infrastructure/parsers/event-classifier.d.ts +111 -0
  106. package/dist/infrastructure/parsers/index.d.ts +8 -0
  107. package/dist/infrastructure/parsers/jsonl-parser.d.ts +25 -0
  108. package/dist/infrastructure/parsers/timestamp.d.ts +18 -0
  109. package/dist/infrastructure/paths.d.ts +129 -0
  110. package/dist/infrastructure/providers/provider-defaults.d.ts +11 -0
  111. package/dist/infrastructure/providers/provider-registry.d.ts +28 -0
  112. package/dist/infrastructure/security/pattern-redactor.d.ts +6 -0
  113. package/dist/infrastructure/signals/adapters.d.ts +27 -0
  114. package/dist/infrastructure/signals/checkpoint-manager.d.ts +83 -0
  115. package/dist/infrastructure/signals/index.d.ts +8 -0
  116. package/dist/infrastructure/signals/signal-handler.d.ts +113 -0
  117. package/dist/infrastructure/sources/index.d.ts +8 -0
  118. package/dist/infrastructure/sources/memory-file-scanner.d.ts +23 -0
  119. package/dist/infrastructure/sources/project-name-resolver.d.ts +67 -0
  120. package/dist/infrastructure/sources/session-source.d.ts +70 -0
  121. package/dist/presentation/cli/command-result.d.ts +10 -0
  122. package/dist/presentation/cli/commands/_helpers/capture-json.d.ts +36 -0
  123. package/dist/presentation/cli/commands/_helpers/deprecation-warning.d.ts +41 -0
  124. package/dist/presentation/cli/commands/backfill.d.ts +56 -0
  125. package/dist/presentation/cli/commands/browse.d.ts +55 -0
  126. package/dist/presentation/cli/commands/completion.d.ts +61 -0
  127. package/dist/presentation/cli/commands/context.d.ts +53 -0
  128. package/dist/presentation/cli/commands/doctor.d.ts +55 -0
  129. package/dist/presentation/cli/commands/export.d.ts +36 -0
  130. package/dist/presentation/cli/commands/extract.d.ts +40 -0
  131. package/dist/presentation/cli/commands/facts.d.ts +17 -0
  132. package/dist/presentation/cli/commands/friction/dashboard.d.ts +18 -0
  133. package/dist/presentation/cli/commands/friction/index.d.ts +12 -0
  134. package/dist/presentation/cli/commands/friction/list.d.ts +12 -0
  135. package/dist/presentation/cli/commands/friction/log.d.ts +12 -0
  136. package/dist/presentation/cli/commands/friction/purge.d.ts +12 -0
  137. package/dist/presentation/cli/commands/friction/resolve.d.ts +12 -0
  138. package/dist/presentation/cli/commands/friction/types.d.ts +86 -0
  139. package/dist/presentation/cli/commands/friction/wontfix.d.ts +12 -0
  140. package/dist/presentation/cli/commands/import.d.ts +38 -0
  141. package/dist/presentation/cli/commands/index.d.ts +51 -0
  142. package/dist/presentation/cli/commands/install.d.ts +67 -0
  143. package/dist/presentation/cli/commands/list.d.ts +61 -0
  144. package/dist/presentation/cli/commands/migrate.d.ts +36 -0
  145. package/dist/presentation/cli/commands/purge.d.ts +100 -0
  146. package/dist/presentation/cli/commands/query.d.ts +51 -0
  147. package/dist/presentation/cli/commands/related.d.ts +47 -0
  148. package/dist/presentation/cli/commands/remote.d.ts +36 -0
  149. package/dist/presentation/cli/commands/search.d.ts +100 -0
  150. package/dist/presentation/cli/commands/show.d.ts +51 -0
  151. package/dist/presentation/cli/commands/stats.d.ts +38 -0
  152. package/dist/presentation/cli/commands/status.d.ts +152 -0
  153. package/dist/presentation/cli/commands/sync/ambient.d.ts +22 -0
  154. package/dist/presentation/cli/commands/sync/background.d.ts +23 -0
  155. package/dist/presentation/cli/commands/sync/embedding-pass.d.ts +32 -0
  156. package/dist/presentation/cli/commands/sync/helpers.d.ts +25 -0
  157. package/dist/presentation/cli/commands/sync/index.d.ts +17 -0
  158. package/dist/presentation/cli/commands/sync/memory-files.d.ts +26 -0
  159. package/dist/presentation/cli/commands/sync/types.d.ts +163 -0
  160. package/dist/presentation/cli/commands/uninstall.d.ts +44 -0
  161. package/dist/presentation/cli/db-startup.d.ts +61 -0
  162. package/dist/presentation/cli/formatters/ai-formatter.d.ts +38 -0
  163. package/dist/presentation/cli/formatters/color.d.ts +82 -0
  164. package/dist/presentation/cli/formatters/context-formatter.d.ts +55 -0
  165. package/dist/presentation/cli/formatters/dto-helpers.d.ts +176 -0
  166. package/dist/presentation/cli/formatters/envelope.d.ts +136 -0
  167. package/dist/presentation/cli/formatters/error-formatter.d.ts +41 -0
  168. package/dist/presentation/cli/formatters/friction-dashboard.d.ts +46 -0
  169. package/dist/presentation/cli/formatters/index.d.ts +17 -0
  170. package/dist/presentation/cli/formatters/list-formatter.d.ts +48 -0
  171. package/dist/presentation/cli/formatters/output-formatter.d.ts +98 -0
  172. package/dist/presentation/cli/formatters/related-formatter.d.ts +57 -0
  173. package/dist/presentation/cli/formatters/show-formatter.d.ts +63 -0
  174. package/dist/presentation/cli/formatters/stats-formatter.d.ts +54 -0
  175. package/dist/presentation/cli/formatters/text-width.d.ts +37 -0
  176. package/dist/presentation/cli/formatters/timestamp-formatter.d.ts +38 -0
  177. package/dist/presentation/cli/index.d.ts +10 -0
  178. package/dist/presentation/cli/index.js +1664 -0
  179. package/dist/presentation/cli/parsers/date-parser.d.ts +28 -0
  180. package/dist/presentation/cli/parsers/index.d.ts +6 -0
  181. package/dist/presentation/cli/pickers/index.d.ts +6 -0
  182. package/dist/presentation/cli/pickers/session-picker.d.ts +59 -0
  183. package/dist/presentation/cli/progress-reporter.d.ts +199 -0
  184. package/package.json +94 -0
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Migration Module
3
+ *
4
+ * Detects legacy ~/.memory-nexus/ directory and migrates data to new
5
+ * XDG-compliant paths. All operations are synchronous with rollback
6
+ * safety on failure.
7
+ *
8
+ * After successful data moves, re-installs hooks with new binary name
9
+ * by calling uninstallHooks() then installHooks().
10
+ */
11
+ /**
12
+ * Migration status values.
13
+ *
14
+ * - not-needed: No legacy directory exists (fresh install or already migrated+cleaned)
15
+ * - pending: Legacy directory exists but new paths do not
16
+ * - complete: New paths exist and no legacy directory remains
17
+ * - partial: Both legacy and new paths exist (interrupted migration or manual partial copy)
18
+ */
19
+ export type MigrationStatus = "not-needed" | "pending" | "complete" | "partial";
20
+ /**
21
+ * Result of getMigrationStatus().
22
+ */
23
+ export interface MigrationStatusResult {
24
+ /** Whether the legacy directory exists */
25
+ legacyExists: boolean;
26
+ /** Whether the new config or data directory exists */
27
+ newExists: boolean;
28
+ /** Computed migration status */
29
+ status: MigrationStatus;
30
+ }
31
+ /**
32
+ * Result of migrateFromLegacy().
33
+ */
34
+ export interface MigrationResult {
35
+ /** Whether migration completed successfully (data was moved) */
36
+ migrated: boolean;
37
+ /** List of item names that were moved */
38
+ itemsMoved: string[];
39
+ /** Error messages (empty on full success) */
40
+ errors: string[];
41
+ }
42
+ /**
43
+ * Check migration status by examining legacy and new paths.
44
+ *
45
+ * @returns Status result with legacy/new existence flags and computed status
46
+ */
47
+ export declare function getMigrationStatus(): MigrationStatusResult;
48
+ /**
49
+ * Check whether a legacy database needs migration to XDG paths.
50
+ *
51
+ * Returns true when the legacy ~/.memory-nexus/memory.db exists AND either:
52
+ * (a) no XDG database exists yet, OR
53
+ * (b) the legacy database is larger than the XDG database (empty stub).
54
+ *
55
+ * This is a lightweight check for the CLI entry point to decide whether
56
+ * to run migrateFromLegacy() before any command action can create an
57
+ * empty database via initializeDatabase().
58
+ *
59
+ * ORDERING CONTRACT: The CLI entry point (index.ts) must call this
60
+ * function and, if true, call migrateFromLegacy() BEFORE program.parse()
61
+ * dispatches to any command that calls initializeDatabase(). This
62
+ * prevents the empty-stub race condition where initializeDatabase()
63
+ * creates a 221KB empty database before migration can move the real
64
+ * 266MB legacy database into place.
65
+ *
66
+ * This function does NOT import from connection.ts. The guard lives
67
+ * at the presentation layer (index.ts), not the infrastructure layer
68
+ * (connection.ts), to avoid coupling between independent modules.
69
+ */
70
+ export declare function isMigrationPending(): boolean;
71
+ /**
72
+ * Migrate data from legacy ~/.memory-nexus/ to new XDG paths.
73
+ *
74
+ * This function is SYNCHRONOUS. All filesystem operations use sync variants.
75
+ *
76
+ * Migration order (by priority):
77
+ * 1. Database (memory.db) - most critical
78
+ * 2. Config (config.json) - user preferences
79
+ * 3. Checkpoint (sync-checkpoint.json) - sync progress
80
+ * 4. Logs directory - debugging data
81
+ * 5. Hooks directory - hook scripts
82
+ * 6. Backups directory - settings backups
83
+ *
84
+ * On any move failure, all completed moves are rolled back in reverse order.
85
+ * After successful data moves, hooks are re-installed with new binary name.
86
+ * Hook re-install failure is logged but does not fail the migration.
87
+ *
88
+ * @returns Migration result with moved items list and any errors
89
+ */
90
+ export declare function migrateFromLegacy(): MigrationResult;
91
+ /**
92
+ * Move a file or directory, handling cross-filesystem (EXDEV) errors.
93
+ *
94
+ * First attempts renameSync (atomic on same filesystem).
95
+ * On EXDEV error, falls back to copy + delete.
96
+ *
97
+ * Exported for testing EXDEV fallback logic.
98
+ *
99
+ * @param source Source path
100
+ * @param dest Destination path
101
+ * @param isDir Whether the source is a directory
102
+ */
103
+ export declare function moveFileOrDir(source: string, dest: string, isDir: boolean): void;
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Event Classifier
3
+ *
4
+ * Routes raw JSON events from JSONL files to the appropriate ParsedEvent type.
5
+ * Implements extraction logic for each event type.
6
+ *
7
+ * Based on research in: .planning/research/JSONL-EVENT-SCHEMA.md
8
+ */
9
+ import type { ParsedEvent, ToolUseEventData, ToolResultEventData } from "../../domain/ports/types.js";
10
+ /**
11
+ * Raw event structure from JSONL files.
12
+ */
13
+ interface RawEvent {
14
+ type: string;
15
+ uuid?: string;
16
+ timestamp?: string;
17
+ [key: string]: unknown;
18
+ }
19
+ /**
20
+ * Raw user event structure.
21
+ */
22
+ interface RawUserEvent extends RawEvent {
23
+ type: "user";
24
+ uuid: string;
25
+ timestamp: string;
26
+ message: {
27
+ role: "user";
28
+ content: string | RawToolResultBlock[];
29
+ };
30
+ cwd?: string;
31
+ gitBranch?: string;
32
+ }
33
+ /**
34
+ * Raw tool result block in user message content.
35
+ */
36
+ interface RawToolResultBlock {
37
+ type: "tool_result";
38
+ tool_use_id: string;
39
+ content: string | unknown;
40
+ is_error?: boolean;
41
+ }
42
+ /**
43
+ * Raw assistant event structure.
44
+ */
45
+ interface RawAssistantEvent extends RawEvent {
46
+ type: "assistant";
47
+ uuid: string;
48
+ timestamp: string;
49
+ message: {
50
+ model?: string;
51
+ content: RawContentBlock[];
52
+ usage?: {
53
+ input_tokens: number;
54
+ output_tokens: number;
55
+ };
56
+ };
57
+ }
58
+ /**
59
+ * Raw content block types in assistant message.
60
+ */
61
+ type RawContentBlock = {
62
+ type: "text";
63
+ text: string;
64
+ } | {
65
+ type: "tool_use";
66
+ id: string;
67
+ name: string;
68
+ input: Record<string, unknown>;
69
+ } | {
70
+ type: "thinking";
71
+ thinking: string;
72
+ signature?: string;
73
+ };
74
+ /**
75
+ * Check if a value is a valid event object.
76
+ *
77
+ * @param value The value to check
78
+ * @returns true if the value is a valid event object
79
+ */
80
+ export declare function isValidEvent(value: unknown): value is RawEvent;
81
+ /**
82
+ * Classify a raw JSON event into a ParsedEvent.
83
+ *
84
+ * Routes the event to the appropriate extractor based on type,
85
+ * or returns a skipped event for non-extracted types.
86
+ *
87
+ * @param raw The raw JSON event object
88
+ * @returns Classified ParsedEvent
89
+ */
90
+ export declare function classifyEvent(raw: unknown): ParsedEvent;
91
+ /**
92
+ * Extract tool use events from an assistant event.
93
+ *
94
+ * Creates separate ToolUseEventData for each tool_use block,
95
+ * enabling easier querying of tool usage.
96
+ *
97
+ * @param raw The raw assistant event
98
+ * @returns Array of tool use event data
99
+ */
100
+ export declare function extractToolUseEvents(raw: RawAssistantEvent): ToolUseEventData[];
101
+ /**
102
+ * Extract tool result events from a user event.
103
+ *
104
+ * Creates separate ToolResultEventData for each tool_result block,
105
+ * enabling easier querying of tool outputs.
106
+ *
107
+ * @param raw The raw user event
108
+ * @returns Array of tool result event data
109
+ */
110
+ export declare function extractToolResultEvents(raw: RawUserEvent): ToolResultEventData[];
111
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Parser Adapters
3
+ *
4
+ * Implementations for parsing Claude Code session files.
5
+ */
6
+ export { JsonlEventParser } from "./jsonl-parser.js";
7
+ export { classifyEvent, isValidEvent, extractToolUseEvents, extractToolResultEvents, } from "./event-classifier.js";
8
+ export { normalizeTimestamp } from "./timestamp.js";
@@ -0,0 +1,25 @@
1
+ /**
2
+ * JSONL Parser Adapter
3
+ *
4
+ * Implements streaming JSONL parsing for Claude Code session files.
5
+ * Uses readline.createInterface for memory-efficient line-by-line processing.
6
+ */
7
+ import type { IEventParser, ParsedEvent } from "../../domain/ports/index.js";
8
+ /**
9
+ * Streaming JSONL parser for Claude Code session files.
10
+ *
11
+ * Parses session files line-by-line without loading the entire file
12
+ * into memory. Handles malformed JSON gracefully by yielding
13
+ * "skipped" events with error details.
14
+ *
15
+ * @implements {IEventParser}
16
+ */
17
+ export declare class JsonlEventParser implements IEventParser {
18
+ /**
19
+ * Parse events from a JSONL session file.
20
+ *
21
+ * @param filePath Full path to the JSONL file
22
+ * @yields ParsedEvent for each line (or skipped event for errors)
23
+ */
24
+ parse(filePath: string): AsyncGenerator<ParsedEvent>;
25
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Timestamp Normalization
3
+ *
4
+ * Normalizes various timestamp formats to ISO 8601 for consistent storage.
5
+ */
6
+ /**
7
+ * Normalize various timestamp formats to ISO 8601.
8
+ *
9
+ * Handles:
10
+ * - Already ISO 8601 strings
11
+ * - Unix timestamps (seconds or milliseconds)
12
+ * - Date objects
13
+ * - Other parseable date strings
14
+ *
15
+ * @param value The value to normalize (string, number, Date, or unknown)
16
+ * @returns ISO 8601 formatted timestamp string
17
+ */
18
+ export declare function normalizeTimestamp(value: unknown): string;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Centralized Paths Module
3
+ *
4
+ * Single source of truth for all filesystem paths used by memory.
5
+ * Respects XDG Base Directory Specification with correct fallbacks.
6
+ *
7
+ * Config paths: $XDG_CONFIG_HOME/memory (default: ~/.config/memory)
8
+ * Data paths: $XDG_DATA_HOME/memory (default: ~/.local/share/memory)
9
+ * Legacy memory files: $MEMORY_HOME (default: ~/.memory)
10
+ * Legacy path: ~/.memory-nexus (for migration detection; not overridable)
11
+ */
12
+ /**
13
+ * Get the configuration directory.
14
+ *
15
+ * Resolution order:
16
+ * 1. $XDG_CONFIG_HOME/memory (if XDG_CONFIG_HOME set)
17
+ * 2. ~/.config/memory (default)
18
+ *
19
+ * @returns Absolute path to the config directory
20
+ */
21
+ export declare function getConfigDir(): string;
22
+ /**
23
+ * Get the data directory.
24
+ *
25
+ * Resolution order:
26
+ * 1. $XDG_DATA_HOME/memory (if XDG_DATA_HOME set)
27
+ * 2. ~/.local/share/memory (default)
28
+ *
29
+ * @returns Absolute path to the data directory
30
+ */
31
+ export declare function getDataDir(): string;
32
+ /**
33
+ * Get the legacy directory path.
34
+ *
35
+ * Always returns ~/.memory-nexus regardless of XDG vars or test overrides.
36
+ * Used solely for migration detection.
37
+ *
38
+ * @returns Absolute path to the legacy directory
39
+ */
40
+ export declare function getLegacyDir(): string;
41
+ /**
42
+ * Get the memory directory path.
43
+ *
44
+ * Returns the directory where agent-written markdown files are stored
45
+ * (DECISIONS.md, LEARNINGS.md, USER-PREFS.md, daily logs, per-project notes).
46
+ * Not under XDG -- this is a content directory authored directly by the user
47
+ * and Claude, separate from the tool's own config/data.
48
+ *
49
+ * Resolution order:
50
+ * 1. $MEMORY_HOME (if set and non-empty)
51
+ * 2. ~/.memory (default)
52
+ *
53
+ * Env-var semantics (GNUPGHOME / JAVA_HOME tradition: exact tool-root path,
54
+ * NOT the XDG_*_HOME "base + APP_NAME" convention):
55
+ * - $MEMORY_HOME=/foo means the memory dir IS /foo, not /foo/memory
56
+ * - empty string is ignored (falls through to default)
57
+ * - no `~` expansion -- pass an absolute or fully-resolved path
58
+ * - relative paths are used as-is and resolved by the consuming syscall
59
+ *
60
+ * Use cases for $MEMORY_HOME (production, beyond tests):
61
+ * - sandboxed runs where you don't want to touch the user's real ~/.memory
62
+ * - container/CI workflows that need a writable location under a chosen mount
63
+ * - multi-instance setups (e.g., per-profile development)
64
+ *
65
+ * @returns Absolute path to the memory directory
66
+ */
67
+ export declare function getMemoryDir(): string;
68
+ /**
69
+ * Get the path to the config file.
70
+ *
71
+ * @returns Absolute path to config.json
72
+ */
73
+ export declare function getConfigPath(): string;
74
+ /**
75
+ * Get the path to the database file.
76
+ *
77
+ * @returns Absolute path to memory.db
78
+ */
79
+ export declare function getDbPath(): string;
80
+ /**
81
+ * Get the path to the logs directory.
82
+ *
83
+ * @returns Absolute path to the logs directory
84
+ */
85
+ export declare function getLogDir(): string;
86
+ /**
87
+ * Get the path to the hooks directory.
88
+ *
89
+ * @returns Absolute path to the hooks directory
90
+ */
91
+ export declare function getHookDir(): string;
92
+ /**
93
+ * Get the path to the backups directory.
94
+ *
95
+ * @returns Absolute path to the backups directory
96
+ */
97
+ export declare function getBackupDir(): string;
98
+ /**
99
+ * Get the path to the sync checkpoint file.
100
+ *
101
+ * @returns Absolute path to sync-checkpoint.json
102
+ */
103
+ export declare function getCheckpointPath(): string;
104
+ /**
105
+ * Get the path to the events directory.
106
+ *
107
+ * @returns Absolute path to the events directory
108
+ */
109
+ export declare function getEventsDir(): string;
110
+ /**
111
+ * Get the path to the event log file.
112
+ *
113
+ * @returns Absolute path to events.jsonl
114
+ */
115
+ export declare function getEventLogPath(): string;
116
+ /**
117
+ * Get the path to a machine-specific event log file.
118
+ *
119
+ * @param machineId The unique identifier of the machine
120
+ * @returns Absolute path to events-<machineId>.jsonl
121
+ */
122
+ export declare function getMachineLogPath(machineId: string): string;
123
+ /**
124
+ * Get all event log files (both machine-specific events-*.jsonl and legacy events.jsonl).
125
+ *
126
+ * @param eventsDir Optional directory override (primarily for test isolation)
127
+ * @returns Array of absolute paths to event log files
128
+ */
129
+ export declare function getAllLogFiles(eventsDir?: string): string[];
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Provider defaults shared by configuration loading and provider registry.
3
+ *
4
+ * This file intentionally contains only data. It lets config-manager apply
5
+ * provider-specific embedding defaults without importing provider factories.
6
+ */
7
+ export declare const EMBEDDING_PROVIDER_DEFAULTS: Record<string, {
8
+ model: string;
9
+ dimensions: number;
10
+ }>;
11
+ export declare const EXTRACTION_PROVIDER_DEFAULT_MODELS: Record<string, string>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Provider Registry
3
+ *
4
+ * Internal registry for runtime provider capabilities. This is deliberately
5
+ * not an external plugin loader: provider support is explicit, testable, and
6
+ * wired through typed factories.
7
+ */
8
+ import type { IEmbeddingProvider } from "../../domain/ports/embedding.js";
9
+ import type { IExtractionProvider } from "../../domain/ports/extraction.js";
10
+ import type { EmbeddingConfigData, MemoryConfig } from "../hooks/config-manager.js";
11
+ export interface ProviderReadiness {
12
+ ready: boolean;
13
+ readyReason?: string | undefined;
14
+ }
15
+ export declare function listEmbeddingProviderIds(): string[];
16
+ export declare function listExtractionProviderIds(): string[];
17
+ export declare function unsupportedEmbeddingProviderMessage(providerId: string): string;
18
+ export declare function unsupportedExtractionProviderMessage(providerId: string): string;
19
+ export declare function getEmbeddingProviderDefaults(providerId: string): {
20
+ model: string;
21
+ dimensions: number;
22
+ } | undefined;
23
+ export declare function checkEmbeddingProviderReadiness(config: EmbeddingConfigData): ProviderReadiness;
24
+ export declare function createEmbeddingProvider(config: EmbeddingConfigData): IEmbeddingProvider;
25
+ export declare function resolveExtractionProviderId(config: Pick<MemoryConfig, "embedding">, env?: NodeJS.ProcessEnv): string;
26
+ export declare function getExtractionModel(_config: Pick<MemoryConfig, "embedding">, providerId: string, env?: NodeJS.ProcessEnv): string;
27
+ export declare function checkExtractionProviderReadiness(config: Pick<MemoryConfig, "embedding">, providerId?: string): ProviderReadiness;
28
+ export declare function createExtractionProvider(config: Pick<MemoryConfig, "embedding">): IExtractionProvider;
@@ -0,0 +1,6 @@
1
+ import type { IRedactor, JsonRedactionResult, RedactionResult } from "../../domain/ports/redactor.js";
2
+ export declare class PatternRedactor implements IRedactor {
3
+ redactText(input: string): RedactionResult;
4
+ redactJson<T>(input: T): JsonRedactionResult<T>;
5
+ private redactUnknown;
6
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Domain Port Adapters for Signal Infrastructure
3
+ *
4
+ * Wraps free functions from signal-handler and checkpoint-manager
5
+ * into class-based adapters implementing domain port interfaces.
6
+ */
7
+ import type { ISyncAbortSignal, ICheckpointManager, SyncCheckpoint } from "../../domain/ports/signals.js";
8
+ /**
9
+ * Adapter wrapping the process signal handler's shouldAbort() function.
10
+ */
11
+ export declare class ProcessAbortSignal implements ISyncAbortSignal {
12
+ shouldAbort(): boolean;
13
+ }
14
+ /**
15
+ * Adapter wrapping the filesystem checkpoint manager functions.
16
+ *
17
+ * @param path Optional explicit checkpoint file path. When omitted, the
18
+ * production XDG-resolved path is used. Tests construct with a temp
19
+ * path to achieve isolation without process-wide state.
20
+ */
21
+ export declare class FileCheckpointManager implements ICheckpointManager {
22
+ private readonly path?;
23
+ constructor(path?: string | undefined);
24
+ load(): SyncCheckpoint | null;
25
+ save(checkpoint: SyncCheckpoint): void;
26
+ clear(): void;
27
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Checkpoint Manager
3
+ *
4
+ * Manages sync progress checkpointing for recovery from interrupted syncs.
5
+ * Checkpoints stored in ~/.memory-nexus/sync-checkpoint.json
6
+ *
7
+ * Implements graceful handling of missing/invalid checkpoint files.
8
+ *
9
+ * Each function accepts an optional `path` argument. When omitted, the
10
+ * production XDG-resolved path is used. When provided, that path is used
11
+ * directly (used by tests to point at a temp file). This avoids
12
+ * module-level mutable state and the test-pollution risk that comes with
13
+ * it; see scripts/check-test-isolation.ts.
14
+ */
15
+ /**
16
+ * Sync checkpoint interface
17
+ *
18
+ * Tracks progress of an interrupted sync operation:
19
+ * - startedAt: When the sync began (ISO timestamp)
20
+ * - totalSessions: Total number of sessions to sync
21
+ * - completedSessions: Number of sessions completed
22
+ * - completedSessionIds: List of completed session IDs for filtering
23
+ * - lastCompletedAt: When last session was completed (ISO timestamp, null if none)
24
+ */
25
+ export interface SyncCheckpoint {
26
+ /** When the sync began (ISO timestamp) */
27
+ startedAt: string;
28
+ /** Total number of sessions to sync */
29
+ totalSessions: number;
30
+ /** Number of sessions completed */
31
+ completedSessions: number;
32
+ /** List of completed session IDs */
33
+ completedSessionIds: string[];
34
+ /** When last session was completed (ISO timestamp, null if none) */
35
+ lastCompletedAt: string | null;
36
+ }
37
+ /**
38
+ * Get the path to the checkpoint file.
39
+ *
40
+ * @param override Optional explicit path (used by tests). When omitted,
41
+ * resolves via the production paths module (XDG-respecting).
42
+ * @returns Path to sync-checkpoint.json
43
+ */
44
+ export declare function getCheckpointPath(override?: string): string;
45
+ /**
46
+ * Save checkpoint to disk
47
+ *
48
+ * Creates the directory if it doesn't exist.
49
+ * Handles errors gracefully (logs but doesn't throw).
50
+ *
51
+ * @param checkpoint Checkpoint data to save
52
+ * @param path Optional explicit path (used by tests)
53
+ */
54
+ export declare function saveCheckpoint(checkpoint: SyncCheckpoint, path?: string): void;
55
+ /**
56
+ * Load checkpoint from disk
57
+ *
58
+ * Gracefully handles:
59
+ * - Missing checkpoint file (returns null)
60
+ * - Invalid JSON (returns null with warning)
61
+ *
62
+ * @param path Optional explicit path (used by tests)
63
+ * @returns Checkpoint data or null if not found/invalid
64
+ */
65
+ export declare function loadCheckpoint(path?: string): SyncCheckpoint | null;
66
+ /**
67
+ * Clear checkpoint from disk
68
+ *
69
+ * Called on successful sync completion.
70
+ * Silently ignores missing file.
71
+ *
72
+ * @param path Optional explicit path (used by tests)
73
+ */
74
+ export declare function clearCheckpoint(path?: string): void;
75
+ /**
76
+ * Check if a checkpoint exists
77
+ *
78
+ * Quick existence check without loading the file.
79
+ *
80
+ * @param path Optional explicit path (used by tests)
81
+ * @returns true if checkpoint file exists
82
+ */
83
+ export declare function hasCheckpoint(path?: string): boolean;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Signals Module
3
+ *
4
+ * Signal handling and checkpoint management for graceful shutdown.
5
+ */
6
+ export * from "./checkpoint-manager.js";
7
+ export * from "./signal-handler.js";
8
+ export { ProcessAbortSignal, FileCheckpointManager } from "./adapters.js";
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Signal Handler
3
+ *
4
+ * Handles SIGINT (Ctrl+C) and SIGTERM for graceful shutdown.
5
+ * Provides 3-option prompt on first interrupt, force exit on second.
6
+ *
7
+ * Usage:
8
+ * 1. Call setupSignalHandlers() at CLI startup
9
+ * 2. Register cleanup functions with registerCleanup()
10
+ * 3. Check shouldAbort() in long-running loops
11
+ * 4. Unregister cleanups on successful completion
12
+ */
13
+ /**
14
+ * Set TTY override for testing
15
+ *
16
+ * @param isTTY Value to use, or null to use actual stdin.isTTY
17
+ */
18
+ export declare function setTtyOverride(isTTY: boolean | null): void;
19
+ /**
20
+ * Set process exit override for testing
21
+ *
22
+ * @param exitFn Function to call instead of process.exit, or null for actual
23
+ */
24
+ export declare function setExitOverride(exitFn: ((code: number) => void) | null): void;
25
+ /**
26
+ * Set up signal handlers for SIGINT and SIGTERM
27
+ *
28
+ * Safe to call multiple times (handlers only registered once).
29
+ * SIGINT: Ctrl+C
30
+ * SIGTERM: Kill signal (e.g., from process manager)
31
+ */
32
+ export declare function setupSignalHandlers(): void;
33
+ /**
34
+ * Check if shutdown has been requested
35
+ *
36
+ * Long-running operations should check this periodically
37
+ * and exit gracefully when true.
38
+ *
39
+ * @returns true if shutdown requested
40
+ */
41
+ export declare function shouldAbort(): boolean;
42
+ /**
43
+ * Register a cleanup function
44
+ *
45
+ * Cleanup functions are called before exit, in registration order.
46
+ * Use for closing database connections, saving state, etc.
47
+ *
48
+ * @param fn Async function to call on shutdown
49
+ */
50
+ export declare function registerCleanup(fn: () => Promise<void>): void;
51
+ /**
52
+ * Unregister a cleanup function
53
+ *
54
+ * Call when a resource has been properly closed/released.
55
+ *
56
+ * @param fn Function to remove from cleanup list
57
+ */
58
+ export declare function unregisterCleanup(fn: () => Promise<void>): void;
59
+ /**
60
+ * Reset all signal handler state
61
+ *
62
+ * For testing purposes only.
63
+ * Note: Does not unregister process signal handlers.
64
+ */
65
+ export declare function resetState(): void;
66
+ /**
67
+ * Set shutdown state directly
68
+ *
69
+ * For testing purposes only.
70
+ *
71
+ * @param shutting Whether to set shutdown state
72
+ */
73
+ export declare function setShuttingDown(shutting: boolean): void;
74
+ /**
75
+ * Get current interrupt count
76
+ *
77
+ * For testing purposes only.
78
+ *
79
+ * @returns Number of interrupt signals received
80
+ */
81
+ export declare function getInterruptCount(): number;
82
+ /**
83
+ * Increment interrupt count
84
+ *
85
+ * For testing purposes only.
86
+ */
87
+ export declare function incrementInterruptCount(): void;
88
+ /**
89
+ * Get cleanup function count
90
+ *
91
+ * For testing purposes only.
92
+ *
93
+ * @returns Number of registered cleanup functions
94
+ */
95
+ export declare function getCleanupCount(): number;
96
+ /**
97
+ * Trigger signal handling directly.
98
+ *
99
+ * For testing purposes only.
100
+ */
101
+ export declare function handleSignalForTesting(): Promise<void>;
102
+ /**
103
+ * Trigger choice handling directly.
104
+ *
105
+ * For testing purposes only.
106
+ */
107
+ export declare function handleChoiceForTesting(choice: 1 | 2 | 3): Promise<void>;
108
+ /**
109
+ * Run registered cleanups directly.
110
+ *
111
+ * For testing purposes only.
112
+ */
113
+ export declare function runCleanupsForTesting(): Promise<void>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Source Infrastructure
3
+ *
4
+ * Adapters for discovering and accessing Claude Code session files.
5
+ */
6
+ export { FileSystemSessionSource, type SessionSourceOptions, } from "./session-source.js";
7
+ export { ProjectNameResolver } from "./project-name-resolver.js";
8
+ export { MemoryFileScanner } from "./memory-file-scanner.js";