@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.
- package/README.md +294 -0
- package/dist/application/index.d.ts +6 -0
- package/dist/application/services/ambient-context-service.d.ts +90 -0
- package/dist/application/services/backfill-service.d.ts +71 -0
- package/dist/application/services/budget-allocator.d.ts +57 -0
- package/dist/application/services/embedding-service.d.ts +131 -0
- package/dist/application/services/export-service.d.ts +225 -0
- package/dist/application/services/extraction-pipeline.d.ts +50 -0
- package/dist/application/services/friction-service.d.ts +148 -0
- package/dist/application/services/fts-sanitizer.d.ts +25 -0
- package/dist/application/services/index.d.ts +34 -0
- package/dist/application/services/llm-extractor.d.ts +96 -0
- package/dist/application/services/memory-file-sync-service.d.ts +58 -0
- package/dist/application/services/pattern-extractor.d.ts +95 -0
- package/dist/application/services/recovery-service.d.ts +81 -0
- package/dist/application/services/rrf-fusion.d.ts +53 -0
- package/dist/application/services/smart-context-service.d.ts +126 -0
- package/dist/application/services/sync-service.d.ts +157 -0
- package/dist/application/services/temporal-decay.d.ts +62 -0
- package/dist/domain/entities/backfill-state.d.ts +56 -0
- package/dist/domain/entities/entity.d.ts +131 -0
- package/dist/domain/entities/extraction-state.d.ts +128 -0
- package/dist/domain/entities/fact.d.ts +59 -0
- package/dist/domain/entities/friction-entry.d.ts +84 -0
- package/dist/domain/entities/index.d.ts +15 -0
- package/dist/domain/entities/link.d.ts +74 -0
- package/dist/domain/entities/memory-file.d.ts +78 -0
- package/dist/domain/entities/message.d.ts +70 -0
- package/dist/domain/entities/session.d.ts +93 -0
- package/dist/domain/entities/tool-use.d.ts +85 -0
- package/dist/domain/errors/error-codes.d.ts +37 -0
- package/dist/domain/errors/index.d.ts +8 -0
- package/dist/domain/errors/memory-error.d.ts +52 -0
- package/dist/domain/errors/unknown-error.d.ts +9 -0
- package/dist/domain/index.d.ts +11 -0
- package/dist/domain/ports/embedding.d.ts +96 -0
- package/dist/domain/ports/extraction.d.ts +13 -0
- package/dist/domain/ports/index.d.ts +14 -0
- package/dist/domain/ports/redactor.d.ts +17 -0
- package/dist/domain/ports/repositories.d.ts +658 -0
- package/dist/domain/ports/services.d.ts +180 -0
- package/dist/domain/ports/signals.d.ts +82 -0
- package/dist/domain/ports/sources.d.ts +122 -0
- package/dist/domain/ports/types.d.ts +150 -0
- package/dist/domain/services/content-extractor.d.ts +61 -0
- package/dist/domain/services/index.d.ts +8 -0
- package/dist/domain/services/path-decoder.d.ts +56 -0
- package/dist/domain/services/query-parser.d.ts +47 -0
- package/dist/domain/value-objects/embedding-config.d.ts +56 -0
- package/dist/domain/value-objects/embedding-result.d.ts +46 -0
- package/dist/domain/value-objects/index.d.ts +10 -0
- package/dist/domain/value-objects/project-path.d.ts +92 -0
- package/dist/domain/value-objects/search-query.d.ts +30 -0
- package/dist/domain/value-objects/search-result.d.ts +92 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +1548 -0
- package/dist/infrastructure/database/connection.d.ts +161 -0
- package/dist/infrastructure/database/event-log.d.ts +22 -0
- package/dist/infrastructure/database/health-checker.d.ts +248 -0
- package/dist/infrastructure/database/index.d.ts +11 -0
- package/dist/infrastructure/database/repositories/backfill-state-repository.d.ts +19 -0
- package/dist/infrastructure/database/repositories/embedding-repository.d.ts +121 -0
- package/dist/infrastructure/database/repositories/entity-repository.d.ts +73 -0
- package/dist/infrastructure/database/repositories/extraction-log-repository.d.ts +17 -0
- package/dist/infrastructure/database/repositories/extraction-state-repository.d.ts +52 -0
- package/dist/infrastructure/database/repositories/fact-repository.d.ts +25 -0
- package/dist/infrastructure/database/repositories/friction-repository.d.ts +41 -0
- package/dist/infrastructure/database/repositories/index.d.ts +17 -0
- package/dist/infrastructure/database/repositories/link-repository.d.ts +64 -0
- package/dist/infrastructure/database/repositories/memory-file-repository.d.ts +28 -0
- package/dist/infrastructure/database/repositories/message-repository.d.ts +87 -0
- package/dist/infrastructure/database/repositories/session-repository.d.ts +125 -0
- package/dist/infrastructure/database/repositories/tool-use-repository.d.ts +72 -0
- package/dist/infrastructure/database/schema.d.ts +203 -0
- package/dist/infrastructure/database/services/context-service.d.ts +93 -0
- package/dist/infrastructure/database/services/hybrid-search-service.d.ts +156 -0
- package/dist/infrastructure/database/services/index.d.ts +10 -0
- package/dist/infrastructure/database/services/search-service.d.ts +57 -0
- package/dist/infrastructure/database/services/stats-service.d.ts +36 -0
- package/dist/infrastructure/embedding/background-embedder.d.ts +125 -0
- package/dist/infrastructure/embedding/embedding-provider-factory.d.ts +44 -0
- package/dist/infrastructure/embedding/index.d.ts +5 -0
- package/dist/infrastructure/embedding/ollama-provider.d.ts +41 -0
- package/dist/infrastructure/embedding/openai-provider.d.ts +38 -0
- package/dist/infrastructure/embedding/transformers-js-provider.d.ts +34 -0
- package/dist/infrastructure/external/index.d.ts +7 -0
- package/dist/infrastructure/external/qmd-runner.d.ts +36 -0
- package/dist/infrastructure/hooks/auto-memory-writer.d.ts +52 -0
- package/dist/infrastructure/hooks/config-manager.d.ts +237 -0
- package/dist/infrastructure/hooks/git-syncer.d.ts +44 -0
- package/dist/infrastructure/hooks/hook-runner.d.ts +126 -0
- package/dist/infrastructure/hooks/index.d.ts +12 -0
- package/dist/infrastructure/hooks/log-writer.d.ts +106 -0
- package/dist/infrastructure/hooks/settings-manager.d.ts +163 -0
- package/dist/infrastructure/hooks/sync-hook-script.d.ts +83 -0
- package/dist/infrastructure/hooks/sync-logger-adapter.d.ts +17 -0
- package/dist/infrastructure/index.d.ts +11 -0
- package/dist/infrastructure/llm/anthropic-extractor.d.ts +20 -0
- package/dist/infrastructure/llm/claude-cli-extractor.d.ts +14 -0
- package/dist/infrastructure/llm/claude-summary-generator.d.ts +14 -0
- package/dist/infrastructure/llm/extraction-helper.d.ts +16 -0
- package/dist/infrastructure/llm/ollama-extractor.d.ts +20 -0
- package/dist/infrastructure/llm/openai-extractor.d.ts +23 -0
- package/dist/infrastructure/migration.d.ts +103 -0
- package/dist/infrastructure/parsers/event-classifier.d.ts +111 -0
- package/dist/infrastructure/parsers/index.d.ts +8 -0
- package/dist/infrastructure/parsers/jsonl-parser.d.ts +25 -0
- package/dist/infrastructure/parsers/timestamp.d.ts +18 -0
- package/dist/infrastructure/paths.d.ts +129 -0
- package/dist/infrastructure/providers/provider-defaults.d.ts +11 -0
- package/dist/infrastructure/providers/provider-registry.d.ts +28 -0
- package/dist/infrastructure/security/pattern-redactor.d.ts +6 -0
- package/dist/infrastructure/signals/adapters.d.ts +27 -0
- package/dist/infrastructure/signals/checkpoint-manager.d.ts +83 -0
- package/dist/infrastructure/signals/index.d.ts +8 -0
- package/dist/infrastructure/signals/signal-handler.d.ts +113 -0
- package/dist/infrastructure/sources/index.d.ts +8 -0
- package/dist/infrastructure/sources/memory-file-scanner.d.ts +23 -0
- package/dist/infrastructure/sources/project-name-resolver.d.ts +67 -0
- package/dist/infrastructure/sources/session-source.d.ts +70 -0
- package/dist/presentation/cli/command-result.d.ts +10 -0
- package/dist/presentation/cli/commands/_helpers/capture-json.d.ts +36 -0
- package/dist/presentation/cli/commands/_helpers/deprecation-warning.d.ts +41 -0
- package/dist/presentation/cli/commands/backfill.d.ts +56 -0
- package/dist/presentation/cli/commands/browse.d.ts +55 -0
- package/dist/presentation/cli/commands/completion.d.ts +61 -0
- package/dist/presentation/cli/commands/context.d.ts +53 -0
- package/dist/presentation/cli/commands/doctor.d.ts +55 -0
- package/dist/presentation/cli/commands/export.d.ts +36 -0
- package/dist/presentation/cli/commands/extract.d.ts +40 -0
- package/dist/presentation/cli/commands/facts.d.ts +17 -0
- package/dist/presentation/cli/commands/friction/dashboard.d.ts +18 -0
- package/dist/presentation/cli/commands/friction/index.d.ts +12 -0
- package/dist/presentation/cli/commands/friction/list.d.ts +12 -0
- package/dist/presentation/cli/commands/friction/log.d.ts +12 -0
- package/dist/presentation/cli/commands/friction/purge.d.ts +12 -0
- package/dist/presentation/cli/commands/friction/resolve.d.ts +12 -0
- package/dist/presentation/cli/commands/friction/types.d.ts +86 -0
- package/dist/presentation/cli/commands/friction/wontfix.d.ts +12 -0
- package/dist/presentation/cli/commands/import.d.ts +38 -0
- package/dist/presentation/cli/commands/index.d.ts +51 -0
- package/dist/presentation/cli/commands/install.d.ts +67 -0
- package/dist/presentation/cli/commands/list.d.ts +61 -0
- package/dist/presentation/cli/commands/migrate.d.ts +36 -0
- package/dist/presentation/cli/commands/purge.d.ts +100 -0
- package/dist/presentation/cli/commands/query.d.ts +51 -0
- package/dist/presentation/cli/commands/related.d.ts +47 -0
- package/dist/presentation/cli/commands/remote.d.ts +36 -0
- package/dist/presentation/cli/commands/search.d.ts +100 -0
- package/dist/presentation/cli/commands/show.d.ts +51 -0
- package/dist/presentation/cli/commands/stats.d.ts +38 -0
- package/dist/presentation/cli/commands/status.d.ts +152 -0
- package/dist/presentation/cli/commands/sync/ambient.d.ts +22 -0
- package/dist/presentation/cli/commands/sync/background.d.ts +23 -0
- package/dist/presentation/cli/commands/sync/embedding-pass.d.ts +32 -0
- package/dist/presentation/cli/commands/sync/helpers.d.ts +25 -0
- package/dist/presentation/cli/commands/sync/index.d.ts +17 -0
- package/dist/presentation/cli/commands/sync/memory-files.d.ts +26 -0
- package/dist/presentation/cli/commands/sync/types.d.ts +163 -0
- package/dist/presentation/cli/commands/uninstall.d.ts +44 -0
- package/dist/presentation/cli/db-startup.d.ts +61 -0
- package/dist/presentation/cli/formatters/ai-formatter.d.ts +38 -0
- package/dist/presentation/cli/formatters/color.d.ts +82 -0
- package/dist/presentation/cli/formatters/context-formatter.d.ts +55 -0
- package/dist/presentation/cli/formatters/dto-helpers.d.ts +176 -0
- package/dist/presentation/cli/formatters/envelope.d.ts +136 -0
- package/dist/presentation/cli/formatters/error-formatter.d.ts +41 -0
- package/dist/presentation/cli/formatters/friction-dashboard.d.ts +46 -0
- package/dist/presentation/cli/formatters/index.d.ts +17 -0
- package/dist/presentation/cli/formatters/list-formatter.d.ts +48 -0
- package/dist/presentation/cli/formatters/output-formatter.d.ts +98 -0
- package/dist/presentation/cli/formatters/related-formatter.d.ts +57 -0
- package/dist/presentation/cli/formatters/show-formatter.d.ts +63 -0
- package/dist/presentation/cli/formatters/stats-formatter.d.ts +54 -0
- package/dist/presentation/cli/formatters/text-width.d.ts +37 -0
- package/dist/presentation/cli/formatters/timestamp-formatter.d.ts +38 -0
- package/dist/presentation/cli/index.d.ts +10 -0
- package/dist/presentation/cli/index.js +1664 -0
- package/dist/presentation/cli/parsers/date-parser.d.ts +28 -0
- package/dist/presentation/cli/parsers/index.d.ts +6 -0
- package/dist/presentation/cli/pickers/index.d.ts +6 -0
- package/dist/presentation/cli/pickers/session-picker.d.ts +59 -0
- package/dist/presentation/cli/progress-reporter.d.ts +199 -0
- package/package.json +94 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Port Interfaces
|
|
3
|
+
*
|
|
4
|
+
* Defines contracts for domain services that may have infrastructure
|
|
5
|
+
* dependencies. These interfaces allow the domain to define what
|
|
6
|
+
* services it needs without knowing the implementation details.
|
|
7
|
+
*/
|
|
8
|
+
import type { SearchQuery } from "../value-objects/search-query.js";
|
|
9
|
+
import type { SearchResult } from "../value-objects/search-result.js";
|
|
10
|
+
import type { MessageRole } from "../entities/message.js";
|
|
11
|
+
/**
|
|
12
|
+
* Options for filtering and limiting search results.
|
|
13
|
+
*
|
|
14
|
+
* All properties are optional. When not specified:
|
|
15
|
+
* - limit defaults to implementation-specific value
|
|
16
|
+
* - filters are not applied
|
|
17
|
+
*/
|
|
18
|
+
export interface SearchOptions {
|
|
19
|
+
/** Maximum number of results to return */
|
|
20
|
+
limit?: number | undefined;
|
|
21
|
+
/** Filter results to a specific project name (case-insensitive substring match) */
|
|
22
|
+
projectFilter?: string | undefined;
|
|
23
|
+
/** Filter by message role (user or assistant). Can be single role or array of roles. */
|
|
24
|
+
roleFilter?: MessageRole | MessageRole[] | undefined;
|
|
25
|
+
/** Only include results after this date */
|
|
26
|
+
sinceDate?: Date | undefined;
|
|
27
|
+
/** Only include results before this date */
|
|
28
|
+
beforeDate?: Date | undefined;
|
|
29
|
+
/** Filter results to a specific session ID */
|
|
30
|
+
sessionFilter?: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** Search mode for hybrid search */
|
|
33
|
+
export type SearchMode = "auto" | "fts" | "vector" | "hybrid";
|
|
34
|
+
/**
|
|
35
|
+
* Extended search options with hybrid mode support.
|
|
36
|
+
*/
|
|
37
|
+
export interface HybridSearchOptions extends SearchOptions {
|
|
38
|
+
/** Search mode selection. Default: 'auto' */
|
|
39
|
+
mode?: SearchMode | undefined;
|
|
40
|
+
/** Disable temporal decay scoring for this search */
|
|
41
|
+
noDecay?: boolean | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Service for full-text search across session content.
|
|
45
|
+
*
|
|
46
|
+
* Implementations use FTS5 for efficient text matching.
|
|
47
|
+
* Results are ranked by relevance score.
|
|
48
|
+
*/
|
|
49
|
+
export interface ISearchService {
|
|
50
|
+
/**
|
|
51
|
+
* Search for content matching the query.
|
|
52
|
+
*
|
|
53
|
+
* Uses full-text search with ranking. Results are ordered by
|
|
54
|
+
* relevance score (highest first).
|
|
55
|
+
*
|
|
56
|
+
* @param query The search query (validated)
|
|
57
|
+
* @param options Optional search filters and limits
|
|
58
|
+
* @returns Array of search results, ranked by relevance
|
|
59
|
+
*/
|
|
60
|
+
search(query: SearchQuery, options?: SearchOptions): Promise<SearchResult[]>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Per-project statistics.
|
|
64
|
+
*/
|
|
65
|
+
export interface ProjectStats {
|
|
66
|
+
projectName: string;
|
|
67
|
+
sessionCount: number;
|
|
68
|
+
messageCount: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Database statistics result.
|
|
72
|
+
*/
|
|
73
|
+
export interface StatsResult {
|
|
74
|
+
totalSessions: number;
|
|
75
|
+
totalMessages: number;
|
|
76
|
+
totalToolUses: number;
|
|
77
|
+
databaseSizeBytes: number;
|
|
78
|
+
projectBreakdown: ProjectStats[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Service for database statistics queries.
|
|
82
|
+
*/
|
|
83
|
+
export interface IStatsService {
|
|
84
|
+
/**
|
|
85
|
+
* Get database-wide statistics with per-project breakdown.
|
|
86
|
+
*
|
|
87
|
+
* @param projectLimit Maximum projects to include in breakdown (default 10)
|
|
88
|
+
* @returns Statistics including totals and per-project breakdown
|
|
89
|
+
*/
|
|
90
|
+
getStats(projectLimit?: number): Promise<StatsResult>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Port for generating structured summaries from session content.
|
|
94
|
+
*
|
|
95
|
+
* Implementations invoke an LLM (e.g., claude -p) to produce
|
|
96
|
+
* a daily log entry from raw session messages.
|
|
97
|
+
*/
|
|
98
|
+
export interface ISummaryGenerator {
|
|
99
|
+
/**
|
|
100
|
+
* Generate a structured daily log summary from session content.
|
|
101
|
+
*
|
|
102
|
+
* @param content Extracted session content (user messages + assistant text)
|
|
103
|
+
* @param sessionId Session identifier for the summary header
|
|
104
|
+
* @param projectName Project name for context
|
|
105
|
+
* @param startTime Session start time (ISO string)
|
|
106
|
+
* @param endTime Session end time (ISO string)
|
|
107
|
+
* @returns Formatted markdown summary in daily log format
|
|
108
|
+
*/
|
|
109
|
+
generateSummary(content: string, sessionId: string, projectName: string, startTime: string, endTime: string): Promise<string>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Result from an external markdown file search (e.g., qmd).
|
|
113
|
+
*
|
|
114
|
+
* Fields match qmd's --json output shape. Optional fields may not
|
|
115
|
+
* be present depending on the external tool's configuration and
|
|
116
|
+
* index state.
|
|
117
|
+
*/
|
|
118
|
+
export interface QmdSearchResult {
|
|
119
|
+
/** Document ID from the external tool's index */
|
|
120
|
+
docid?: string;
|
|
121
|
+
/** Relevance score */
|
|
122
|
+
score: number;
|
|
123
|
+
/** File path (may use tool-specific URI format, e.g., qmd://) */
|
|
124
|
+
file: string;
|
|
125
|
+
/** Document title extracted from markdown */
|
|
126
|
+
title: string;
|
|
127
|
+
/** Surrounding text context */
|
|
128
|
+
context?: string;
|
|
129
|
+
/** Highlighted match snippet */
|
|
130
|
+
snippet?: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Health information for an external search provider.
|
|
134
|
+
*/
|
|
135
|
+
export interface QmdHealthInfo {
|
|
136
|
+
/** Whether the external tool binary was found in PATH */
|
|
137
|
+
available: boolean;
|
|
138
|
+
/** Resolved binary path, null if not found */
|
|
139
|
+
path: string | null;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Port for delegating search to an external tool (e.g., qmd).
|
|
143
|
+
*
|
|
144
|
+
* Implementations invoke the tool as a subprocess and parse its
|
|
145
|
+
* output into typed results. The domain defines the contract;
|
|
146
|
+
* infrastructure implements the subprocess invocation.
|
|
147
|
+
*/
|
|
148
|
+
export interface IExternalSearchProvider {
|
|
149
|
+
/** Execute search against external tool, return parsed results */
|
|
150
|
+
search(query: string): Promise<QmdSearchResult[]>;
|
|
151
|
+
/** Synchronous check if the external tool is available in PATH */
|
|
152
|
+
isAvailable(): boolean;
|
|
153
|
+
/** Synchronous check returning availability and resolved binary path */
|
|
154
|
+
getHealthInfo(): QmdHealthInfo;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Port for writing ambient context artifacts.
|
|
158
|
+
*
|
|
159
|
+
* Implementations handle filesystem operations to write context.md
|
|
160
|
+
* (complete overwrite) and update MEMORY.md (marker-based merge).
|
|
161
|
+
*/
|
|
162
|
+
export interface IAmbientContextWriter {
|
|
163
|
+
/**
|
|
164
|
+
* Write the full context file (complete overwrite).
|
|
165
|
+
*
|
|
166
|
+
* @param autoMemoryDir Directory path for the auto-memory artifacts
|
|
167
|
+
* @param content Content to write as context.md
|
|
168
|
+
*/
|
|
169
|
+
writeContextFile(autoMemoryDir: string, content: string): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Update the MEMORY.md block using marker-based merge.
|
|
172
|
+
*
|
|
173
|
+
* Content between `<!-- memory-cli:start -->` and `<!-- memory-cli:end -->`
|
|
174
|
+
* markers is replaced. Content outside markers is preserved.
|
|
175
|
+
*
|
|
176
|
+
* @param autoMemoryDir Directory path for the auto-memory artifacts
|
|
177
|
+
* @param blockContent Content to place between markers
|
|
178
|
+
*/
|
|
179
|
+
updateMemoryBlock(autoMemoryDir: string, blockContent: string): Promise<void>;
|
|
180
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signal Port Interfaces
|
|
3
|
+
*
|
|
4
|
+
* Defines contracts for abort signaling, checkpoint management,
|
|
5
|
+
* and sync logging. These interfaces abstract infrastructure concerns
|
|
6
|
+
* (filesystem, process signals) from application services.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Checkpoint data for recovering from interrupted sync operations.
|
|
10
|
+
*
|
|
11
|
+
* Tracks which sessions have been completed so that a resumed sync
|
|
12
|
+
* can skip already-processed sessions.
|
|
13
|
+
*/
|
|
14
|
+
export interface SyncCheckpoint {
|
|
15
|
+
/** When the sync began (ISO timestamp) */
|
|
16
|
+
startedAt: string;
|
|
17
|
+
/** Total number of sessions to sync */
|
|
18
|
+
totalSessions: number;
|
|
19
|
+
/** Number of sessions completed */
|
|
20
|
+
completedSessions: number;
|
|
21
|
+
/** List of completed session IDs */
|
|
22
|
+
completedSessionIds: string[];
|
|
23
|
+
/** When last session was completed (ISO timestamp, null if none) */
|
|
24
|
+
lastCompletedAt: string | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Abort signal for long-running sync operations.
|
|
28
|
+
*
|
|
29
|
+
* Implementations check process signals (SIGINT/SIGTERM) or other
|
|
30
|
+
* abort triggers. The sync loop checks this between sessions.
|
|
31
|
+
*/
|
|
32
|
+
export interface ISyncAbortSignal {
|
|
33
|
+
/**
|
|
34
|
+
* Check if abort has been requested.
|
|
35
|
+
*
|
|
36
|
+
* @returns true if the operation should stop
|
|
37
|
+
*/
|
|
38
|
+
shouldAbort(): boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Checkpoint persistence for sync recovery.
|
|
42
|
+
*
|
|
43
|
+
* Implementations store checkpoint state to disk so that interrupted
|
|
44
|
+
* syncs can resume from where they left off.
|
|
45
|
+
*/
|
|
46
|
+
export interface ICheckpointManager {
|
|
47
|
+
/**
|
|
48
|
+
* Load the most recent checkpoint.
|
|
49
|
+
*
|
|
50
|
+
* @returns Checkpoint data, or null if no checkpoint exists
|
|
51
|
+
*/
|
|
52
|
+
load(): SyncCheckpoint | null;
|
|
53
|
+
/**
|
|
54
|
+
* Save checkpoint state.
|
|
55
|
+
*
|
|
56
|
+
* @param checkpoint Checkpoint data to persist
|
|
57
|
+
*/
|
|
58
|
+
save(checkpoint: SyncCheckpoint): void;
|
|
59
|
+
/**
|
|
60
|
+
* Clear checkpoint after successful sync completion.
|
|
61
|
+
*/
|
|
62
|
+
clear(): void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Structured logger for sync operations.
|
|
66
|
+
*
|
|
67
|
+
* Implementations write log entries to structured storage
|
|
68
|
+
* (JSON lines files, databases, etc.).
|
|
69
|
+
*/
|
|
70
|
+
export interface ISyncLogger {
|
|
71
|
+
/**
|
|
72
|
+
* Write a structured log entry.
|
|
73
|
+
*
|
|
74
|
+
* @param entry Log entry with level, message, and optional context
|
|
75
|
+
*/
|
|
76
|
+
log(entry: {
|
|
77
|
+
level: "debug" | "info" | "warn" | "error";
|
|
78
|
+
message: string;
|
|
79
|
+
sessionId?: string;
|
|
80
|
+
error?: string;
|
|
81
|
+
}): void;
|
|
82
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source Port Interfaces
|
|
3
|
+
*
|
|
4
|
+
* Defines contracts for accessing external data sources.
|
|
5
|
+
* These interfaces abstract filesystem and parsing operations.
|
|
6
|
+
*/
|
|
7
|
+
import type { MemoryFileType } from "../entities/memory-file.js";
|
|
8
|
+
import type { ProjectPath } from "../value-objects/project-path.js";
|
|
9
|
+
import type { ParsedEvent } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Information about a discovered session file.
|
|
12
|
+
*
|
|
13
|
+
* Used during session discovery to identify available sessions
|
|
14
|
+
* without loading their full content.
|
|
15
|
+
*/
|
|
16
|
+
export interface SessionFileInfo {
|
|
17
|
+
/** Session UUID (derived from filename) */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Full path to the JSONL file */
|
|
20
|
+
path: string;
|
|
21
|
+
/** Project this session belongs to */
|
|
22
|
+
projectPath: ProjectPath;
|
|
23
|
+
/** Last modification time of the file */
|
|
24
|
+
modifiedTime: Date;
|
|
25
|
+
/** File size in bytes */
|
|
26
|
+
size: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Source for discovering Claude Code session files.
|
|
30
|
+
*
|
|
31
|
+
* Implementations scan the Claude Code projects directory
|
|
32
|
+
* to find available session JSONL files.
|
|
33
|
+
*/
|
|
34
|
+
export interface ISessionSource {
|
|
35
|
+
/**
|
|
36
|
+
* Discover all available session files.
|
|
37
|
+
*
|
|
38
|
+
* Scans the Claude Code projects directory structure:
|
|
39
|
+
* ~/.claude/projects/<encoded-path>/<session-uuid>.jsonl
|
|
40
|
+
*
|
|
41
|
+
* @returns Array of session file information
|
|
42
|
+
*/
|
|
43
|
+
discoverSessions(): Promise<SessionFileInfo[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Get the full path to a session file by ID.
|
|
46
|
+
*
|
|
47
|
+
* @param sessionId The session UUID
|
|
48
|
+
* @returns Full path to the JSONL file, or null if not found
|
|
49
|
+
*/
|
|
50
|
+
getSessionFile(sessionId: string): Promise<string | null>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parser for extracting events from JSONL session files.
|
|
54
|
+
*
|
|
55
|
+
* Uses streaming to handle large files efficiently without
|
|
56
|
+
* loading the entire file into memory.
|
|
57
|
+
*/
|
|
58
|
+
export interface IEventParser {
|
|
59
|
+
/**
|
|
60
|
+
* Parse events from a session file.
|
|
61
|
+
*
|
|
62
|
+
* Returns an async iterable that yields events one at a time.
|
|
63
|
+
* Events that cannot be parsed or are not relevant are yielded
|
|
64
|
+
* as "skipped" events with a reason.
|
|
65
|
+
*
|
|
66
|
+
* @param filePath Full path to the JSONL file
|
|
67
|
+
* @returns Async iterable of parsed events
|
|
68
|
+
*/
|
|
69
|
+
parse(filePath: string): AsyncIterable<ParsedEvent>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Resolver for mapping encoded directory paths to project names.
|
|
73
|
+
*
|
|
74
|
+
* Claude Code encodes directory paths in a lossy way (spaces, hyphens,
|
|
75
|
+
* slashes all become dashes). Implementations resolve the actual project
|
|
76
|
+
* name by walking the filesystem or using cached mappings.
|
|
77
|
+
*/
|
|
78
|
+
export interface IProjectNameResolver {
|
|
79
|
+
/**
|
|
80
|
+
* Resolve a project name from a full encoded path.
|
|
81
|
+
*
|
|
82
|
+
* @param encodedPath The encoded directory path (e.g., "C--Users-Destiny-Projects-memory-nexus")
|
|
83
|
+
* @returns The resolved project name (e.g., "memory-nexus")
|
|
84
|
+
*/
|
|
85
|
+
resolveFromEncodedPath(encodedPath: string): string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Information about a discovered memory file.
|
|
89
|
+
*
|
|
90
|
+
* Returned by IMemoryFileScanner during file discovery.
|
|
91
|
+
* Contains all data needed to create a MemoryFile entity.
|
|
92
|
+
*/
|
|
93
|
+
export interface MemoryFileInfo {
|
|
94
|
+
/** Path relative to the legacy memory-file root (uses forward slashes) */
|
|
95
|
+
filePath: string;
|
|
96
|
+
/** Absolute path for reading */
|
|
97
|
+
absolutePath: string;
|
|
98
|
+
/** Classified file type */
|
|
99
|
+
fileType: MemoryFileType;
|
|
100
|
+
/** Encoded project path, or undefined for global files */
|
|
101
|
+
projectEncoded?: string | undefined;
|
|
102
|
+
/** SHA-256 hash of file content */
|
|
103
|
+
contentHash: string;
|
|
104
|
+
/** Full file content */
|
|
105
|
+
content: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Scanner for discovering legacy markdown memory files.
|
|
109
|
+
*
|
|
110
|
+
* Implementations discover .md files, classify their type from
|
|
111
|
+
* path patterns, extract project encoded names, and compute
|
|
112
|
+
* content hashes. Returns empty array when the directory does
|
|
113
|
+
* not exist (graceful no-op).
|
|
114
|
+
*/
|
|
115
|
+
export interface IMemoryFileScanner {
|
|
116
|
+
/**
|
|
117
|
+
* Discover all legacy memory files.
|
|
118
|
+
*
|
|
119
|
+
* @returns Array of discovered file info, empty if directory missing
|
|
120
|
+
*/
|
|
121
|
+
discoverFiles(): Promise<MemoryFileInfo[]>;
|
|
122
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsed Event Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the discriminated union for events parsed from JSONL files.
|
|
5
|
+
* These types represent the domain's view of Claude Code session events.
|
|
6
|
+
*
|
|
7
|
+
* Based on research in: .planning/research/JSONL-EVENT-SCHEMA.md
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Content block within an assistant message.
|
|
11
|
+
* Can be text or a tool use invocation.
|
|
12
|
+
*/
|
|
13
|
+
export type ContentBlock = {
|
|
14
|
+
type: "text";
|
|
15
|
+
text: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: "tool_use";
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
input: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Data extracted from a user message event.
|
|
24
|
+
*/
|
|
25
|
+
export interface UserEventData {
|
|
26
|
+
/** Unique event identifier */
|
|
27
|
+
uuid: string;
|
|
28
|
+
/** User message content */
|
|
29
|
+
message: {
|
|
30
|
+
content: string;
|
|
31
|
+
};
|
|
32
|
+
/** ISO 8601 timestamp */
|
|
33
|
+
timestamp: string;
|
|
34
|
+
/** Working directory at time of message */
|
|
35
|
+
cwd?: string;
|
|
36
|
+
/** Git branch if in a repository */
|
|
37
|
+
gitBranch?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Data extracted from an assistant message event.
|
|
41
|
+
*/
|
|
42
|
+
export interface AssistantEventData {
|
|
43
|
+
/** Unique event identifier */
|
|
44
|
+
uuid: string;
|
|
45
|
+
/** Assistant message with content blocks */
|
|
46
|
+
message: {
|
|
47
|
+
content: ContentBlock[];
|
|
48
|
+
/** Model used for this response */
|
|
49
|
+
model?: string;
|
|
50
|
+
};
|
|
51
|
+
/** ISO 8601 timestamp */
|
|
52
|
+
timestamp: string;
|
|
53
|
+
/** Token usage statistics */
|
|
54
|
+
usage?: {
|
|
55
|
+
inputTokens: number;
|
|
56
|
+
outputTokens: number;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Data extracted from a tool use event.
|
|
61
|
+
* Represents when Claude invokes a tool.
|
|
62
|
+
*/
|
|
63
|
+
export interface ToolUseEventData {
|
|
64
|
+
/** Unique tool use identifier */
|
|
65
|
+
uuid: string;
|
|
66
|
+
/** Name of the tool invoked */
|
|
67
|
+
name: string;
|
|
68
|
+
/** Input parameters passed to the tool */
|
|
69
|
+
input: Record<string, unknown>;
|
|
70
|
+
/** ISO 8601 timestamp */
|
|
71
|
+
timestamp: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Data extracted from a tool result event.
|
|
75
|
+
* Represents the output from a tool invocation.
|
|
76
|
+
*/
|
|
77
|
+
export interface ToolResultEventData {
|
|
78
|
+
/** Unique result identifier */
|
|
79
|
+
uuid: string;
|
|
80
|
+
/** ID of the tool use this result corresponds to */
|
|
81
|
+
toolUseId: string;
|
|
82
|
+
/** Result content (output or error message) */
|
|
83
|
+
content: string;
|
|
84
|
+
/** Whether the tool execution resulted in an error */
|
|
85
|
+
isError: boolean;
|
|
86
|
+
/** ISO 8601 timestamp */
|
|
87
|
+
timestamp: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Data extracted from a summary event.
|
|
91
|
+
* Summaries are compressed session history for context management.
|
|
92
|
+
*/
|
|
93
|
+
export interface SummaryEventData {
|
|
94
|
+
/** Condensed session content */
|
|
95
|
+
content: string;
|
|
96
|
+
/** ISO 8601 timestamp */
|
|
97
|
+
timestamp: string;
|
|
98
|
+
/** UUID of the last event this summary covers */
|
|
99
|
+
leafUuid?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Data extracted from a system event.
|
|
103
|
+
* System events track timing and configuration.
|
|
104
|
+
*/
|
|
105
|
+
export interface SystemEventData {
|
|
106
|
+
/** System event subtype (e.g., "turn_duration") */
|
|
107
|
+
subtype: string;
|
|
108
|
+
/** Event-specific data */
|
|
109
|
+
data: unknown;
|
|
110
|
+
/** ISO 8601 timestamp */
|
|
111
|
+
timestamp: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Discriminated union of all parsed event types.
|
|
115
|
+
*
|
|
116
|
+
* Use type narrowing with switch/case on the `type` field:
|
|
117
|
+
* ```typescript
|
|
118
|
+
* switch (event.type) {
|
|
119
|
+
* case "user":
|
|
120
|
+
* // event.data is UserEventData
|
|
121
|
+
* break;
|
|
122
|
+
* case "assistant":
|
|
123
|
+
* // event.data is AssistantEventData
|
|
124
|
+
* break;
|
|
125
|
+
* // ...
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export type ParsedEvent = {
|
|
130
|
+
type: "user";
|
|
131
|
+
data: UserEventData;
|
|
132
|
+
} | {
|
|
133
|
+
type: "assistant";
|
|
134
|
+
data: AssistantEventData;
|
|
135
|
+
} | {
|
|
136
|
+
type: "tool_use";
|
|
137
|
+
data: ToolUseEventData;
|
|
138
|
+
} | {
|
|
139
|
+
type: "tool_result";
|
|
140
|
+
data: ToolResultEventData;
|
|
141
|
+
} | {
|
|
142
|
+
type: "summary";
|
|
143
|
+
data: SummaryEventData;
|
|
144
|
+
} | {
|
|
145
|
+
type: "system";
|
|
146
|
+
data: SystemEventData;
|
|
147
|
+
} | {
|
|
148
|
+
type: "skipped";
|
|
149
|
+
reason: string;
|
|
150
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ContentExtractor Domain Service
|
|
3
|
+
*
|
|
4
|
+
* Extracts structured content from Claude Code session JSONL lines.
|
|
5
|
+
* Handles parsing of messages, tool uses, and tool results.
|
|
6
|
+
*
|
|
7
|
+
* Service properties:
|
|
8
|
+
* - Stateless operations
|
|
9
|
+
* - Pure functions (no side effects)
|
|
10
|
+
* - Domain logic only (no infrastructure concerns)
|
|
11
|
+
*/
|
|
12
|
+
interface MessageContent {
|
|
13
|
+
role: "user" | "assistant";
|
|
14
|
+
content: string;
|
|
15
|
+
}
|
|
16
|
+
interface ToolUseContent {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
input: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
interface ToolResultContent {
|
|
22
|
+
toolUseId: string;
|
|
23
|
+
content: string;
|
|
24
|
+
isError: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare class ContentExtractor {
|
|
27
|
+
/**
|
|
28
|
+
* Extract message content from a JSONL line.
|
|
29
|
+
* @param jsonLine A single line from a JSONL file
|
|
30
|
+
* @returns Message content or null if not a message line
|
|
31
|
+
*/
|
|
32
|
+
static extractMessageContent(jsonLine: string): MessageContent | null;
|
|
33
|
+
/**
|
|
34
|
+
* Extract tool uses from a JSONL line.
|
|
35
|
+
* @param jsonLine A single line from a JSONL file
|
|
36
|
+
* @returns Array of tool use objects (empty if none found)
|
|
37
|
+
*/
|
|
38
|
+
static extractToolUses(jsonLine: string): ToolUseContent[];
|
|
39
|
+
/**
|
|
40
|
+
* Extract tool results from a JSONL line.
|
|
41
|
+
* @param jsonLine A single line from a JSONL file
|
|
42
|
+
* @returns Array of tool result objects (empty if none found)
|
|
43
|
+
*/
|
|
44
|
+
static extractToolResults(jsonLine: string): ToolResultContent[];
|
|
45
|
+
/**
|
|
46
|
+
* Check if a JSONL line represents a message (human or assistant).
|
|
47
|
+
* @param jsonLine A single line from a JSONL file
|
|
48
|
+
* @returns true if line is a message
|
|
49
|
+
*/
|
|
50
|
+
static isMessageLine(jsonLine: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Extract timestamp from a JSONL line.
|
|
53
|
+
* @param jsonLine A single line from a JSONL file
|
|
54
|
+
* @returns Date object or null if no valid timestamp
|
|
55
|
+
*/
|
|
56
|
+
static extractTimestamp(jsonLine: string): Date | null;
|
|
57
|
+
private static parseJson;
|
|
58
|
+
private static isMessageType;
|
|
59
|
+
private static extractTextContent;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain Services
|
|
3
|
+
*
|
|
4
|
+
* Stateless operations that don't naturally fit in entities or value objects.
|
|
5
|
+
*/
|
|
6
|
+
export { ContentExtractor } from "./content-extractor.js";
|
|
7
|
+
export { PathDecoder } from "./path-decoder.js";
|
|
8
|
+
export { QueryParser, type ParsedQuery, type QueryFilters, } from "./query-parser.js";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PathDecoder Domain Service
|
|
3
|
+
*
|
|
4
|
+
* Handles decoding of encoded project directory names from Claude Code's
|
|
5
|
+
* session storage format back to their original file system paths.
|
|
6
|
+
*
|
|
7
|
+
* Service properties:
|
|
8
|
+
* - Stateless operations
|
|
9
|
+
* - Pure functions (no side effects)
|
|
10
|
+
* - Domain logic only (no infrastructure concerns)
|
|
11
|
+
*/
|
|
12
|
+
import { ProjectPath } from "../value-objects/index.js";
|
|
13
|
+
export declare class PathDecoder {
|
|
14
|
+
/**
|
|
15
|
+
* Decode an encoded project directory name to a ProjectPath value object.
|
|
16
|
+
* @param encoded The encoded directory name (e.g., "C--Users-Destiny-Projects-foo")
|
|
17
|
+
* @returns ProjectPath value object with decoded path
|
|
18
|
+
*/
|
|
19
|
+
static decodeProjectDirectory(encoded: string): ProjectPath;
|
|
20
|
+
/**
|
|
21
|
+
* Check if a string appears to be an encoded path from Claude Code.
|
|
22
|
+
* @param value The string to check
|
|
23
|
+
* @returns true if it matches encoded path patterns
|
|
24
|
+
*/
|
|
25
|
+
static isEncodedPath(value: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Extract the project name from an encoded path.
|
|
28
|
+
* Note: This is a convenience method that decodes and extracts.
|
|
29
|
+
* @param encoded The encoded directory name
|
|
30
|
+
* @returns The project name (last segment of the path)
|
|
31
|
+
*/
|
|
32
|
+
static extractProjectName(encoded: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Filter a list of strings to only include encoded paths.
|
|
35
|
+
* Useful for processing directory listings from Claude Code's session storage.
|
|
36
|
+
* @param items List of directory/file names
|
|
37
|
+
* @returns Only the items that appear to be encoded paths
|
|
38
|
+
*/
|
|
39
|
+
static filterEncodedPaths(items: string[]): string[];
|
|
40
|
+
/**
|
|
41
|
+
* Translates absolute paths between Windows (e.g. C:\foo\bar) and WSL Unix mount (/mnt/c/foo/bar) styles.
|
|
42
|
+
* @param path The path to translate
|
|
43
|
+
* @param targetPlatform The target platform to translate for (defaults to process.platform)
|
|
44
|
+
* @returns The translated path string
|
|
45
|
+
*/
|
|
46
|
+
static translatePath(path: string, targetPlatform?: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves a path, optionally translating it if the target file/directory
|
|
49
|
+
* does not exist at the original path but exists at the translated path.
|
|
50
|
+
* @param path The path to resolve
|
|
51
|
+
* @param existsSyncFn Function to check file existence (optional)
|
|
52
|
+
* @param targetPlatform The target platform (defaults to process.platform)
|
|
53
|
+
* @returns The resolved or translated path string
|
|
54
|
+
*/
|
|
55
|
+
static resolveExistingPath(path: string, existsSyncFn?: (p: string) => boolean, targetPlatform?: string): string;
|
|
56
|
+
}
|