claude-mem 3.2.0 → 3.2.2

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 (50) hide show
  1. package/claude-mem +0 -0
  2. package/package.json +1 -2
  3. package/dist/bin/cli.d.ts +0 -2
  4. package/dist/bin/cli.js +0 -129
  5. package/dist/commands/compress.d.ts +0 -2
  6. package/dist/commands/compress.js +0 -27
  7. package/dist/commands/hooks.d.ts +0 -19
  8. package/dist/commands/hooks.js +0 -131
  9. package/dist/commands/install.d.ts +0 -2
  10. package/dist/commands/install.js +0 -649
  11. package/dist/commands/load-context.d.ts +0 -2
  12. package/dist/commands/load-context.js +0 -108
  13. package/dist/commands/logs.d.ts +0 -2
  14. package/dist/commands/logs.js +0 -76
  15. package/dist/commands/migrate-to-jsonl.d.ts +0 -5
  16. package/dist/commands/migrate-to-jsonl.js +0 -99
  17. package/dist/commands/status.d.ts +0 -1
  18. package/dist/commands/status.js +0 -136
  19. package/dist/commands/uninstall.d.ts +0 -2
  20. package/dist/commands/uninstall.js +0 -107
  21. package/dist/constants.d.ts +0 -271
  22. package/dist/constants.js +0 -199
  23. package/dist/core/compression/TranscriptCompressor.d.ts +0 -83
  24. package/dist/core/compression/TranscriptCompressor.js +0 -602
  25. package/dist/core/orchestration/PromptOrchestrator.d.ts +0 -165
  26. package/dist/core/orchestration/PromptOrchestrator.js +0 -182
  27. package/dist/lib/time-utils.d.ts +0 -5
  28. package/dist/lib/time-utils.js +0 -70
  29. package/dist/prompts/constants.d.ts +0 -126
  30. package/dist/prompts/constants.js +0 -161
  31. package/dist/prompts/index.d.ts +0 -10
  32. package/dist/prompts/index.js +0 -11
  33. package/dist/prompts/templates/analysis/AnalysisTemplates.d.ts +0 -13
  34. package/dist/prompts/templates/analysis/AnalysisTemplates.js +0 -94
  35. package/dist/prompts/templates/context/ContextTemplates.d.ts +0 -119
  36. package/dist/prompts/templates/context/ContextTemplates.js +0 -399
  37. package/dist/prompts/templates/hooks/HookTemplates.d.ts +0 -175
  38. package/dist/prompts/templates/hooks/HookTemplates.js +0 -394
  39. package/dist/prompts/templates/hooks/HookTemplates.test.d.ts +0 -7
  40. package/dist/prompts/templates/hooks/HookTemplates.test.js +0 -127
  41. package/dist/shared/config.d.ts +0 -4
  42. package/dist/shared/config.js +0 -41
  43. package/dist/shared/error-handler.d.ts +0 -22
  44. package/dist/shared/error-handler.js +0 -142
  45. package/dist/shared/logger.d.ts +0 -19
  46. package/dist/shared/logger.js +0 -51
  47. package/dist/shared/paths.d.ts +0 -28
  48. package/dist/shared/paths.js +0 -100
  49. package/dist/shared/types.d.ts +0 -141
  50. package/dist/shared/types.js +0 -78
@@ -1,165 +0,0 @@
1
- /**
2
- * PromptOrchestrator - Single source of truth for all prompt generation
3
- *
4
- * This class serves as the central orchestrator for generating different types of prompts
5
- * used throughout the claude-mem system. It provides clear, well-typed interfaces and
6
- * methods for creating prompts for LLM analysis, human context, and system integration.
7
- */
8
- /**
9
- * Context data for LLM analysis prompts
10
- */
11
- export interface AnalysisContext {
12
- /** The transcript content to analyze */
13
- transcriptContent: string;
14
- /** Session identifier */
15
- sessionId: string;
16
- /** Project name for context */
17
- projectName?: string;
18
- /** Custom analysis instructions */
19
- customInstructions?: string;
20
- /** Compression trigger type */
21
- trigger?: 'manual' | 'auto';
22
- /** Original token count */
23
- originalTokens?: number;
24
- /** Target compression ratio */
25
- targetCompressionRatio?: number;
26
- }
27
- /**
28
- * Context data for human-facing session prompts
29
- */
30
- export interface SessionContext {
31
- /** Session identifier */
32
- sessionId: string;
33
- /** Source of the session start */
34
- source: 'startup' | 'compact' | 'vscode' | 'web';
35
- /** Project name */
36
- projectName?: string;
37
- /** Additional context to provide to the human */
38
- additionalContext?: string;
39
- /** Path to the transcript file */
40
- transcriptPath?: string;
41
- /** Working directory */
42
- cwd?: string;
43
- }
44
- /**
45
- * Context data for hook response generation
46
- */
47
- export interface HookContext {
48
- /** The hook event name */
49
- hookEventName: string;
50
- /** Session identifier */
51
- sessionId: string;
52
- /** Success status */
53
- success: boolean;
54
- /** Optional message */
55
- message?: string;
56
- /** Additional data specific to the hook */
57
- data?: Record<string, unknown>;
58
- /** Whether to continue processing */
59
- shouldContinue?: boolean;
60
- /** Reason for stopping if applicable */
61
- stopReason?: string;
62
- }
63
- /**
64
- * Generated analysis prompt for LLM consumption
65
- */
66
- export interface AnalysisPrompt {
67
- /** The formatted prompt text */
68
- prompt: string;
69
- /** Context used to generate the prompt */
70
- context: AnalysisContext;
71
- /** Prompt type identifier */
72
- type: 'analysis';
73
- /** Generated timestamp */
74
- timestamp: string;
75
- }
76
- /**
77
- * Generated session prompt for human context
78
- */
79
- export interface SessionPrompt {
80
- /** The formatted message text */
81
- message: string;
82
- /** Context used to generate the prompt */
83
- context: SessionContext;
84
- /** Prompt type identifier */
85
- type: 'session';
86
- /** Generated timestamp */
87
- timestamp: string;
88
- }
89
- /**
90
- * Generated hook response
91
- */
92
- export interface HookResponse {
93
- /** Whether to continue processing */
94
- continue: boolean;
95
- /** Reason for stopping if continue is false */
96
- stopReason?: string;
97
- /** Whether to suppress output */
98
- suppressOutput?: boolean;
99
- /** Hook-specific output data */
100
- hookSpecificOutput?: Record<string, unknown>;
101
- /** Context used to generate the response */
102
- context: HookContext;
103
- /** Response type identifier */
104
- type: 'hook';
105
- /** Generated timestamp */
106
- timestamp: string;
107
- }
108
- /**
109
- * Central orchestrator for all prompt generation in the claude-mem system
110
- */
111
- export declare class PromptOrchestrator {
112
- private projectName;
113
- constructor(projectName?: string);
114
- /**
115
- * Creates an analysis prompt for LLM processing of transcript content
116
- */
117
- createAnalysisPrompt(context: AnalysisContext): AnalysisPrompt;
118
- /**
119
- * Creates a session start prompt for human context
120
- */
121
- createSessionStartPrompt(context: SessionContext): SessionPrompt;
122
- /**
123
- * Creates a hook response for system integration
124
- */
125
- createHookResponse(context: HookContext): HookResponse;
126
- private buildAnalysisPrompt;
127
- private buildSessionStartMessage;
128
- private buildHookResponse;
129
- /**
130
- * Validates that an AnalysisContext has required fields
131
- */
132
- validateAnalysisContext(context: Partial<AnalysisContext>): context is AnalysisContext;
133
- /**
134
- * Validates that a SessionContext has required fields
135
- */
136
- validateSessionContext(context: Partial<SessionContext>): context is SessionContext;
137
- /**
138
- * Validates that a HookContext has required fields
139
- */
140
- validateHookContext(context: Partial<HookContext>): context is HookContext;
141
- /**
142
- * Gets the project name for this orchestrator instance
143
- */
144
- getProjectName(): string;
145
- /**
146
- * Sets a new project name for this orchestrator instance
147
- */
148
- setProjectName(projectName: string): void;
149
- }
150
- /**
151
- * Creates a new PromptOrchestrator instance
152
- */
153
- export declare function createPromptOrchestrator(projectName?: string): PromptOrchestrator;
154
- /**
155
- * Creates an analysis context from basic parameters
156
- */
157
- export declare function createAnalysisContext(transcriptContent: string, sessionId: string, options?: Partial<Omit<AnalysisContext, 'transcriptContent' | 'sessionId'>>): AnalysisContext;
158
- /**
159
- * Creates a session context from basic parameters
160
- */
161
- export declare function createSessionContext(sessionId: string, source: SessionContext['source'], options?: Partial<Omit<SessionContext, 'sessionId' | 'source'>>): SessionContext;
162
- /**
163
- * Creates a hook context from basic parameters
164
- */
165
- export declare function createHookContext(hookEventName: string, sessionId: string, success: boolean, options?: Partial<Omit<HookContext, 'hookEventName' | 'sessionId' | 'success'>>): HookContext;
@@ -1,182 +0,0 @@
1
- /**
2
- * PromptOrchestrator - Single source of truth for all prompt generation
3
- *
4
- * This class serves as the central orchestrator for generating different types of prompts
5
- * used throughout the claude-mem system. It provides clear, well-typed interfaces and
6
- * methods for creating prompts for LLM analysis, human context, and system integration.
7
- */
8
- import { createAnalysisPrompt } from '../../prompts/templates/analysis/AnalysisTemplates.js';
9
- // =============================================================================
10
- // PROMPT ORCHESTRATOR CLASS
11
- // =============================================================================
12
- /**
13
- * Central orchestrator for all prompt generation in the claude-mem system
14
- */
15
- export class PromptOrchestrator {
16
- projectName;
17
- constructor(projectName = 'claude-mem') {
18
- this.projectName = projectName;
19
- }
20
- /**
21
- * Creates an analysis prompt for LLM processing of transcript content
22
- */
23
- createAnalysisPrompt(context) {
24
- const timestamp = new Date().toISOString();
25
- const prompt = this.buildAnalysisPrompt(context);
26
- return {
27
- prompt,
28
- context,
29
- type: 'analysis',
30
- timestamp,
31
- };
32
- }
33
- /**
34
- * Creates a session start prompt for human context
35
- */
36
- createSessionStartPrompt(context) {
37
- const timestamp = new Date().toISOString();
38
- const message = this.buildSessionStartMessage(context);
39
- return {
40
- message,
41
- context,
42
- type: 'session',
43
- timestamp,
44
- };
45
- }
46
- /**
47
- * Creates a hook response for system integration
48
- */
49
- createHookResponse(context) {
50
- const timestamp = new Date().toISOString();
51
- const response = this.buildHookResponse(context);
52
- return {
53
- ...response,
54
- context,
55
- type: 'hook',
56
- timestamp,
57
- };
58
- }
59
- // =============================================================================
60
- // PRIVATE PROMPT BUILDERS
61
- // =============================================================================
62
- buildAnalysisPrompt(context) {
63
- const { transcriptContent, sessionId, projectName = this.projectName, } = context;
64
- // Extract project prefix from project name (convert to snake_case)
65
- const projectPrefix = projectName.replace(/[-\s]/g, '_').toLowerCase();
66
- // Use the simple prompt with the transcript included
67
- return createAnalysisPrompt(transcriptContent, sessionId, projectPrefix);
68
- }
69
- buildSessionStartMessage(context) {
70
- const { sessionId, source, projectName = this.projectName, additionalContext, transcriptPath, cwd, } = context;
71
- let message = `## Session Started (${source})
72
-
73
- **Project**: ${projectName}
74
- **Session ID**: ${sessionId} `;
75
- if (transcriptPath) {
76
- message += `**Transcript**: ${transcriptPath} `;
77
- }
78
- if (cwd) {
79
- message += `**Working Directory**: ${cwd} `;
80
- }
81
- if (additionalContext) {
82
- message += `\n### Additional Context\n${additionalContext}`;
83
- }
84
- message += `\n\nMemory system is active and ready to preserve context across sessions.`;
85
- return message;
86
- }
87
- buildHookResponse(context) {
88
- const { hookEventName, success, message, data, shouldContinue = success, stopReason, } = context;
89
- const response = {
90
- continue: shouldContinue,
91
- suppressOutput: false,
92
- };
93
- if (!shouldContinue && stopReason) {
94
- response.stopReason = stopReason;
95
- }
96
- // Add hook-specific output based on event type
97
- if (hookEventName === 'SessionStart') {
98
- response.hookSpecificOutput = {
99
- hookEventName: 'SessionStart',
100
- additionalContext: message,
101
- ...data,
102
- };
103
- }
104
- else if (data) {
105
- response.hookSpecificOutput = data;
106
- }
107
- return response;
108
- }
109
- // =============================================================================
110
- // UTILITY METHODS
111
- // =============================================================================
112
- /**
113
- * Validates that an AnalysisContext has required fields
114
- */
115
- validateAnalysisContext(context) {
116
- return !!(context.transcriptContent && context.sessionId);
117
- }
118
- /**
119
- * Validates that a SessionContext has required fields
120
- */
121
- validateSessionContext(context) {
122
- return !!(context.sessionId && context.source);
123
- }
124
- /**
125
- * Validates that a HookContext has required fields
126
- */
127
- validateHookContext(context) {
128
- return !!(context.hookEventName && context.sessionId && typeof context.success === 'boolean');
129
- }
130
- /**
131
- * Gets the project name for this orchestrator instance
132
- */
133
- getProjectName() {
134
- return this.projectName;
135
- }
136
- /**
137
- * Sets a new project name for this orchestrator instance
138
- */
139
- setProjectName(projectName) {
140
- this.projectName = projectName;
141
- }
142
- }
143
- // =============================================================================
144
- // FACTORY FUNCTIONS
145
- // =============================================================================
146
- /**
147
- * Creates a new PromptOrchestrator instance
148
- */
149
- export function createPromptOrchestrator(projectName) {
150
- return new PromptOrchestrator(projectName);
151
- }
152
- /**
153
- * Creates an analysis context from basic parameters
154
- */
155
- export function createAnalysisContext(transcriptContent, sessionId, options = {}) {
156
- return {
157
- transcriptContent,
158
- sessionId,
159
- ...options,
160
- };
161
- }
162
- /**
163
- * Creates a session context from basic parameters
164
- */
165
- export function createSessionContext(sessionId, source, options = {}) {
166
- return {
167
- sessionId,
168
- source,
169
- ...options,
170
- };
171
- }
172
- /**
173
- * Creates a hook context from basic parameters
174
- */
175
- export function createHookContext(hookEventName, sessionId, success, options = {}) {
176
- return {
177
- hookEventName,
178
- sessionId,
179
- success,
180
- ...options,
181
- };
182
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * Time utilities for formatting relative timestamps
3
- */
4
- export declare function formatRelativeTime(timestamp: string | Date): string;
5
- export declare function parseTimestamp(entry: any): Date | null;
@@ -1,70 +0,0 @@
1
- /**
2
- * Time utilities for formatting relative timestamps
3
- */
4
- export function formatRelativeTime(timestamp) {
5
- try {
6
- const date = timestamp instanceof Date ? timestamp : new Date(timestamp);
7
- const now = new Date();
8
- const diffMs = now.getTime() - date.getTime();
9
- const diffSeconds = Math.floor(diffMs / 1000);
10
- const diffMinutes = Math.floor(diffSeconds / 60);
11
- const diffHours = Math.floor(diffMinutes / 60);
12
- const diffDays = Math.floor(diffHours / 24);
13
- const diffWeeks = Math.floor(diffDays / 7);
14
- const diffMonths = Math.floor(diffDays / 30);
15
- if (diffSeconds < 60) {
16
- return 'Just now';
17
- }
18
- else if (diffMinutes < 60) {
19
- return diffMinutes === 1 ? '1 minute ago' : `${diffMinutes} minutes ago`;
20
- }
21
- else if (diffHours < 24) {
22
- return diffHours === 1 ? '1 hour ago' : `${diffHours} hours ago`;
23
- }
24
- else if (diffDays === 1) {
25
- return 'Yesterday';
26
- }
27
- else if (diffDays < 7) {
28
- return `${diffDays} days ago`;
29
- }
30
- else if (diffWeeks === 1) {
31
- return '1 week ago';
32
- }
33
- else if (diffWeeks < 4) {
34
- return `${diffWeeks} weeks ago`;
35
- }
36
- else if (diffMonths === 1) {
37
- return '1 month ago';
38
- }
39
- else if (diffMonths < 12) {
40
- return `${diffMonths} months ago`;
41
- }
42
- else {
43
- const diffYears = Math.floor(diffMonths / 12);
44
- return diffYears === 1 ? '1 year ago' : `${diffYears} years ago`;
45
- }
46
- }
47
- catch (error) {
48
- // Return a fallback for invalid timestamps
49
- return 'Recently';
50
- }
51
- }
52
- export function parseTimestamp(entry) {
53
- // Try multiple timestamp fields that might exist
54
- const possibleFields = ['timestamp', 'created_at', 'date', 'time'];
55
- for (const field of possibleFields) {
56
- if (entry[field]) {
57
- try {
58
- const date = new Date(entry[field]);
59
- if (!isNaN(date.getTime())) {
60
- return date;
61
- }
62
- }
63
- catch {
64
- continue;
65
- }
66
- }
67
- }
68
- // If no valid timestamp found, return null
69
- return null;
70
- }
@@ -1,126 +0,0 @@
1
- /**
2
- * Claude Memory System - Prompt-Related Constants and Templates
3
- *
4
- * This file contains all prompts, instructions, and output templates
5
- * for the analysis and context priming system.
6
- */
7
- import * as HookTemplates from './templates/hooks/HookTemplates.js';
8
- /**
9
- * Entity naming patterns for the knowledge graph
10
- */
11
- export declare const ENTITY_NAMING_PATTERNS: {
12
- readonly component: "Component_Name";
13
- readonly decision: "Decision_Name";
14
- readonly pattern: "Pattern_Name";
15
- readonly tool: "Tool_Name";
16
- readonly fix: "Fix_Name";
17
- readonly workflow: "Workflow_Name";
18
- };
19
- /**
20
- * Available entity types for classification
21
- */
22
- export declare const ENTITY_TYPES: {
23
- readonly component: "component";
24
- readonly pattern: "pattern";
25
- readonly workflow: "workflow";
26
- readonly integration: "integration";
27
- readonly concept: "concept";
28
- readonly decision: "decision";
29
- readonly tool: "tool";
30
- readonly fix: "fix";
31
- };
32
- /**
33
- * Standard observation fields for entities
34
- */
35
- export declare const OBSERVATION_FIELDS: readonly ["Core purpose: [what it fundamentally does]", "Brief description: [one-line summary for session-start display]", "Implementation: [key technical details, code patterns]", "Dependencies: [what it requires or builds upon]", "Usage context: [when/why it's used]", "Performance characteristics: [speed, reliability, constraints]", "Integration points: [how it connects to other systems]", "Keywords: [searchable terms for this concept]", "Decision rationale: [why this approach was chosen]", "Next steps: [what needs to be done next with this component]", "Files modified: [list of files changed]", "Tools used: [development tools/commands used]"];
36
- /**
37
- * Relationship types for creating meaningful entity connections
38
- */
39
- export declare const RELATIONSHIP_TYPES: readonly ["executes_via", "orchestrates_through", "validates_using", "provides_auth_to", "manages_state_for", "processes_events_from", "caches_data_from", "routes_requests_to", "transforms_data_for", "extends", "enhances_performance_of", "builds_upon", "fixes_issue_in", "replaces", "optimizes", "triggers_tool", "receives_result_from"];
40
- /**
41
- * System message templates for context priming
42
- */
43
- export declare const CONTEXT_TEMPLATES: {
44
- readonly PRIMARY_CONTEXT: (projectName: string) => string;
45
- readonly RECENT_SESSIONS: (sessionList: string) => string;
46
- readonly AVAILABLE_ENTITIES: (type: string, entities: string[], hasMore: boolean, moreCount: number) => string;
47
- readonly SESSION_START_HEADER: "🧠 Active Working Context from Previous Sessions:";
48
- readonly SESSION_START_SEPARATOR: string;
49
- readonly RESUME_INSTRUCTIONS: "šŸ’” TO RESUME: Load active components with chroma_get_documents([\"<exact_document_ids>\"])\nšŸ“Š TO EXPLORE: Search related work with chroma_query_documents([\"<keywords>\"])";
50
- };
51
- /**
52
- * Session start formatting templates
53
- */
54
- export declare const SESSION_START_TEMPLATES: {
55
- readonly FOCUS_LINE: (focus: string) => string;
56
- readonly LAST_WORKED: (timeAgo: string, projectName: string) => string;
57
- readonly SECTIONS: {
58
- readonly COMPONENTS: "šŸŽÆ ACTIVE COMPONENTS (load these for context):";
59
- readonly DECISIONS: "šŸ”„ RECENT DECISIONS & PATTERNS:";
60
- readonly TOOLS: "šŸ› ļø TOOLS & INFRASTRUCTURE:";
61
- readonly FIXES: "šŸ› RECENT FIXES:";
62
- readonly ACTIONS: "⚔ NEXT ACTIONS:";
63
- };
64
- readonly ACTION_PREFIX: "ā–” ";
65
- readonly ENTITY_BULLET: "• ";
66
- };
67
- /**
68
- * Time formatting for "time ago" displays
69
- */
70
- export declare const TIME_FORMATS: {
71
- readonly JUST_NOW: "just now";
72
- readonly HOURS_AGO: (hours: number) => string;
73
- readonly DAYS_AGO: (days: number) => string;
74
- readonly RECENTLY: "recently";
75
- };
76
- /**
77
- * Standard hook response structures for Claude Code integration
78
- */
79
- export declare const HOOK_RESPONSES: {
80
- readonly SUCCESS: (hookEventName: string, message: string) => {
81
- hookSpecificOutput: {
82
- hookEventName: string;
83
- status: string;
84
- message: string;
85
- };
86
- suppressOutput: boolean;
87
- };
88
- readonly SKIPPED: (hookEventName: string, message: string) => {
89
- hookSpecificOutput: {
90
- hookEventName: string;
91
- status: string;
92
- message: string;
93
- };
94
- suppressOutput: boolean;
95
- };
96
- readonly BLOCKED: (reason: string) => {
97
- decision: string;
98
- reason: string;
99
- };
100
- readonly CONTINUE: (hookEventName: string, additionalContext?: string) => {
101
- hookSpecificOutput?: {
102
- hookEventName: string;
103
- additionalContext: string;
104
- } | undefined;
105
- continue: boolean;
106
- };
107
- readonly ERROR: (reason: string) => {
108
- decision: string;
109
- reason: string;
110
- };
111
- };
112
- /**
113
- * Pre-defined hook messages
114
- */
115
- export declare const HOOK_MESSAGES: {
116
- readonly COMPRESSION_SUCCESS: "Memory compression completed successfully";
117
- readonly COMPRESSION_FAILED: (stderr: string) => string;
118
- readonly CONTEXT_LOADED: "Project context loaded successfully";
119
- readonly CONTEXT_SKIPPED: "Continuing session - context loading skipped";
120
- readonly NO_TRANSCRIPT: "No transcript path provided";
121
- readonly HOOK_ERROR: (error: string) => string;
122
- };
123
- /**
124
- * Export hook templates for direct usage
125
- */
126
- export { HookTemplates };