claude-mem 3.3.7 → 3.3.9
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 +183 -46
- package/dist/bin/cli.d.ts +2 -0
- package/dist/bin/cli.js +179 -0
- package/dist/commands/compress.d.ts +2 -0
- package/dist/commands/compress.js +27 -0
- package/dist/commands/hooks.d.ts +19 -0
- package/dist/commands/hooks.js +131 -0
- package/dist/commands/install.d.ts +2 -0
- package/dist/commands/install.js +836 -0
- package/dist/commands/load-context.d.ts +2 -0
- package/dist/commands/load-context.js +151 -0
- package/dist/commands/logs.d.ts +2 -0
- package/dist/commands/logs.js +76 -0
- package/dist/commands/migrate-to-jsonl.d.ts +5 -0
- package/dist/commands/migrate-to-jsonl.js +99 -0
- package/dist/commands/restore.d.ts +1 -0
- package/dist/commands/restore.js +20 -0
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +136 -0
- package/dist/commands/trash-empty.d.ts +3 -0
- package/dist/commands/trash-empty.js +56 -0
- package/dist/commands/trash-view.d.ts +1 -0
- package/dist/commands/trash-view.js +101 -0
- package/dist/commands/trash.d.ts +6 -0
- package/dist/commands/trash.js +49 -0
- package/dist/commands/uninstall.d.ts +2 -0
- package/dist/commands/uninstall.js +107 -0
- package/dist/constants.d.ts +271 -0
- package/dist/constants.js +199 -0
- package/dist/core/compression/TranscriptCompressor.d.ts +79 -0
- package/dist/core/compression/TranscriptCompressor.js +585 -0
- package/dist/core/orchestration/PromptOrchestrator.d.ts +165 -0
- package/dist/core/orchestration/PromptOrchestrator.js +182 -0
- package/dist/lib/time-utils.d.ts +5 -0
- package/dist/lib/time-utils.js +70 -0
- package/dist/prompts/constants.d.ts +126 -0
- package/dist/prompts/constants.js +161 -0
- package/dist/prompts/index.d.ts +10 -0
- package/dist/prompts/index.js +11 -0
- package/dist/prompts/templates/analysis/AnalysisTemplates.d.ts +13 -0
- package/dist/prompts/templates/analysis/AnalysisTemplates.js +94 -0
- package/dist/prompts/templates/context/ContextTemplates.d.ts +119 -0
- package/dist/prompts/templates/context/ContextTemplates.js +399 -0
- package/dist/prompts/templates/hooks/HookTemplates.d.ts +175 -0
- package/dist/prompts/templates/hooks/HookTemplates.js +394 -0
- package/dist/prompts/templates/hooks/HookTemplates.test.d.ts +7 -0
- package/dist/prompts/templates/hooks/HookTemplates.test.js +127 -0
- package/dist/shared/config.d.ts +4 -0
- package/dist/shared/config.js +41 -0
- package/dist/shared/error-handler.d.ts +22 -0
- package/dist/shared/error-handler.js +142 -0
- package/dist/shared/logger.d.ts +19 -0
- package/dist/shared/logger.js +51 -0
- package/dist/shared/paths.d.ts +28 -0
- package/dist/shared/paths.js +100 -0
- package/dist/shared/settings.d.ts +41 -0
- package/dist/shared/settings.js +81 -0
- package/dist/shared/types.d.ts +145 -0
- package/dist/shared/types.js +78 -0
- package/docs/STATUS.md +155 -0
- package/docs/chroma-backend-migration.md +161 -0
- package/docs/landing-page-outline.md +287 -0
- package/docs/multi-platform-builds.md +96 -0
- package/docs/plans/cloud-service-plan.md +274 -0
- package/docs/plans/fix-response-format-issue.md +61 -0
- package/docs/plans/restructure-session-hook-output.md +102 -0
- package/docs/plans/session-start-hook-investigation.md +45 -0
- package/docs/plans/src-reorganization-plan.md +181 -0
- package/docs/plans/terminal-effects-decision.md +22 -0
- package/docs/plans/terminal-effects-integration.md +82 -0
- package/docs/plans/trash-bin-feature-plan.md +240 -0
- package/docs/plans/trash-bin-minimal-plan.md +102 -0
- package/docs/reference/bun-single-executable.md +584 -0
- package/docs/reference/cc-output-styles.md +99 -0
- package/docs/reference/chroma-mcp-project-memory-example.md +80 -0
- package/docs/reference/chroma-mcp-team-example.md +92 -0
- package/docs/reference/claude-code/cc-hooks.md +787 -0
- package/docs/reference/claude-code/cc-status-line.md +202 -0
- package/docs/reference/claude-code/hook-configuration.md +173 -0
- package/docs/reference/claude-code/hook-responses.md +127 -0
- package/docs/reference/claude-code/hooks.md +175 -0
- package/docs/reference/claude-code/mcp-configuration.md +133 -0
- package/docs/reference/claude-code/session-start-hook.md +82 -0
- package/docs/reference/load-context-format-example.md +33 -0
- package/docs/reference/mcp-sdk/mcp-typescript-sdk-readme.md +1323 -0
- package/docs/reference/mcp-sdk/server-implementation.md +286 -0
- package/docs/reference/mcp-sdk/stdio-transport.md +345 -0
- package/docs/todos/fix-response-format-tasks.md +43 -0
- package/docs/todos/implementation-todos.md +280 -0
- package/docs/todos/restructure-hook-output-tasks.md +103 -0
- package/docs/todos/session-start-hook-fix.md +26 -0
- package/docs/todos/terminal-effects-tasks.md +42 -0
- package/docs/todos/trash-bin-implementation-todos.md +348 -0
- package/docs/todos/trash-bin-minimal-todos.md +27 -0
- package/package.json +56 -6
- package/claude-mem +0 -0
package/README.md
CHANGED
|
@@ -2,77 +2,214 @@
|
|
|
2
2
|
|
|
3
3
|
**Truth + Context = Clarity**
|
|
4
4
|
|
|
5
|
-
A
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
A revolutionary memory system that transforms your Claude Code conversations into a persistent, intelligent knowledge base. Never lose valuable insights, code patterns, or debugging solutions again. Your AI assistant finally has a memory that spans across all your projects and sessions.
|
|
6
|
+
|
|
7
|
+
## 🚀 Why Claude-Mem?
|
|
8
|
+
|
|
9
|
+
### The Problem We Solve
|
|
10
|
+
- **Lost Context**: Starting every Claude Code session from scratch
|
|
11
|
+
- **Repeated Explanations**: Re-describing your codebase and architecture repeatedly
|
|
12
|
+
- **Fragmented Knowledge**: Valuable insights scattered across hundreds of conversations
|
|
13
|
+
- **Context Switching**: Losing progress when switching between projects or devices
|
|
14
|
+
- **Knowledge Decay**: Brilliant solutions forgotten and re-discovered multiple times
|
|
15
|
+
|
|
16
|
+
### The Claude-Mem Solution
|
|
17
|
+
Transform your Claude Code experience from forgetful to persistent, from isolated sessions to connected knowledge, from starting over to building upon previous insights.
|
|
18
|
+
|
|
19
|
+
## ✨ Key Features
|
|
20
|
+
|
|
21
|
+
### 🧠 **Intelligent Memory Compression**
|
|
22
|
+
- Automatically extracts key learnings from your Claude Code conversations
|
|
23
|
+
- Identifies patterns, architectural decisions, and breakthrough moments
|
|
24
|
+
- Compresses hours of conversation into searchable, actionable knowledge
|
|
25
|
+
- Uses advanced AI analysis to understand context and significance
|
|
26
|
+
|
|
27
|
+
### 🔄 **Seamless Integration**
|
|
28
|
+
- **One-command setup**: `claude-mem install` and you're ready
|
|
29
|
+
- **Zero friction**: Works invisibly in the background
|
|
30
|
+
- **Automatic triggers**: Memory compression on `/compact` and `/clear`
|
|
31
|
+
- **Instant context loading**: New sessions start with relevant memories
|
|
32
|
+
|
|
33
|
+
### 🎯 **Smart Context Loading**
|
|
34
|
+
- Loads relevant memories when starting new sessions
|
|
35
|
+
- Project-aware context selection
|
|
36
|
+
- Semantic search finds related knowledge across all sessions
|
|
37
|
+
- Prevents re-explaining the same concepts repeatedly
|
|
38
|
+
|
|
39
|
+
### 📚 **Comprehensive Knowledge Base**
|
|
40
|
+
- Stores technical implementations, bug fixes, and solutions
|
|
41
|
+
- Captures design patterns and architectural decisions
|
|
42
|
+
- Remembers tool configurations and setup procedures
|
|
43
|
+
- Archives complete conversation transcripts for detailed reference
|
|
44
|
+
|
|
45
|
+
### 🔍 **Powerful Search & Retrieval**
|
|
46
|
+
- Vector-based semantic search finds related concepts
|
|
47
|
+
- Keyword search for specific terms and technologies
|
|
48
|
+
- Project filtering to focus on relevant memories
|
|
49
|
+
- Time-based filtering to find recent insights
|
|
50
|
+
|
|
51
|
+
## 🛠 Installation & Setup
|
|
52
|
+
|
|
53
|
+
### Quick Install
|
|
18
54
|
```bash
|
|
19
55
|
# Install globally
|
|
20
56
|
npm install -g claude-mem
|
|
21
57
|
|
|
22
|
-
#
|
|
58
|
+
# Set up Claude Code integration
|
|
59
|
+
claude-mem install
|
|
60
|
+
|
|
61
|
+
# Restart Claude Code to activate
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Alternative Installation
|
|
65
|
+
```bash
|
|
66
|
+
# Use without installing globally
|
|
23
67
|
npx claude-mem install
|
|
24
68
|
```
|
|
25
69
|
|
|
26
|
-
|
|
70
|
+
### Verification
|
|
71
|
+
```bash
|
|
72
|
+
# Check installation status
|
|
73
|
+
claude-mem status
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 💻 How It Works
|
|
27
77
|
|
|
28
|
-
|
|
78
|
+
### The Memory Lifecycle
|
|
79
|
+
|
|
80
|
+
1. **🎬 Session Start**: Claude-mem loads relevant context from your knowledge base
|
|
81
|
+
2. **💬 Active Session**: You work normally in Claude Code - no changes needed
|
|
82
|
+
3. **🗜️ Memory Compression**: Use `/compact` or `/clear` to trigger intelligent compression
|
|
83
|
+
4. **🧠 Knowledge Extraction**: AI analysis extracts key learnings and patterns
|
|
84
|
+
5. **💾 Persistent Storage**: Memories stored in searchable vector database
|
|
85
|
+
6. **🔄 Context Ready**: Next session starts with relevant memories loaded
|
|
86
|
+
|
|
87
|
+
### Technical Architecture
|
|
88
|
+
|
|
89
|
+
- **Vector Database**: ChromaDB for semantic search and storage
|
|
90
|
+
- **MCP Integration**: Model Context Protocol for Claude Code communication
|
|
91
|
+
- **AI Analysis**: Advanced prompt engineering for knowledge extraction
|
|
92
|
+
- **Local Storage**: All data stored locally in `~/.claude-mem/`
|
|
93
|
+
|
|
94
|
+
## 📋 Commands Reference
|
|
95
|
+
|
|
96
|
+
### Core Commands
|
|
29
97
|
```bash
|
|
30
|
-
claude-mem install
|
|
98
|
+
claude-mem install # Set up Claude Code integration
|
|
99
|
+
claude-mem status # Check system status and configuration
|
|
100
|
+
claude-mem load-context # View and search stored memories
|
|
101
|
+
claude-mem logs # View system logs and debug information
|
|
102
|
+
claude-mem uninstall # Remove Claude Code hooks
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Advanced Usage
|
|
106
|
+
```bash
|
|
107
|
+
claude-mem compress <file> # Manually compress a transcript file
|
|
108
|
+
claude-mem restore # Restore from backups
|
|
109
|
+
claude-mem trash-view # View deleted files (Smart Trash feature)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 📁 Storage Structure
|
|
113
|
+
|
|
114
|
+
Your claude-mem data is organized in `~/.claude-mem/`:
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
~/.claude-mem/
|
|
118
|
+
├── index/ # ChromaDB vector database
|
|
119
|
+
├── archives/ # Original conversation transcripts
|
|
120
|
+
├── hooks/ # Claude Code integration scripts
|
|
121
|
+
├── trash/ # Smart Trash (deleted files)
|
|
122
|
+
└── logs/ # System logs and debug information
|
|
31
123
|
```
|
|
32
124
|
|
|
33
|
-
|
|
125
|
+
## 🌟 Real-World Benefits
|
|
126
|
+
|
|
127
|
+
### For Individual Developers
|
|
128
|
+
- **Faster Problem Solving**: Find solutions you've used before instantly
|
|
129
|
+
- **Knowledge Accumulation**: Build expertise that persists across projects
|
|
130
|
+
- **Context Continuity**: Pick up where you left off, even weeks later
|
|
131
|
+
- **Pattern Recognition**: See how you've solved similar problems before
|
|
132
|
+
|
|
133
|
+
### For Teams (Coming Soon)
|
|
134
|
+
- **Shared Knowledge**: Team-wide memory accessible to all members
|
|
135
|
+
- **Onboarding Acceleration**: New team members access collective knowledge
|
|
136
|
+
- **Best Practices**: Capture and share proven solutions
|
|
137
|
+
- **Institutional Memory**: Prevent knowledge loss when team members leave
|
|
138
|
+
|
|
139
|
+
## 🚀 Coming Soon: Cloud Sync
|
|
34
140
|
|
|
35
|
-
|
|
141
|
+
### Individual Plan ($9.95/month)
|
|
142
|
+
- **Multi-device sync**: Access your memories on any device
|
|
143
|
+
- **Cloud backup**: Never lose your knowledge base
|
|
144
|
+
- **Enhanced search**: Advanced filtering and semantic search
|
|
145
|
+
- **API access**: Integrate with your own tools and workflows
|
|
36
146
|
|
|
37
|
-
|
|
147
|
+
### Team Plan ($29.95/month, 3+ seats)
|
|
148
|
+
- **Shared memories**: Team-wide knowledge base
|
|
149
|
+
- **Role-based access**: Control what memories are shared
|
|
150
|
+
- **Admin dashboard**: Manage team members and usage
|
|
151
|
+
- **Priority support**: Direct access to our engineering team
|
|
38
152
|
|
|
39
|
-
|
|
153
|
+
[**Join the waitlist**](https://claude-mem.ai) for early access to cloud features.
|
|
40
154
|
|
|
41
|
-
|
|
42
|
-
- `claude-mem status` - Check system status
|
|
43
|
-
- `claude-mem compress <transcript>` - Manually compress a transcript
|
|
44
|
-
- `claude-mem load-context` - View stored memories
|
|
45
|
-
- `claude-mem logs` - View system logs
|
|
46
|
-
- `claude-mem uninstall` - Remove Claude Code hooks
|
|
155
|
+
## 🛡️ Privacy & Security
|
|
47
156
|
|
|
48
|
-
|
|
157
|
+
- **Local-first**: All data stored locally by default
|
|
158
|
+
- **No tracking**: We don't collect or transmit your conversations
|
|
159
|
+
- **Your data**: You own and control your knowledge base
|
|
160
|
+
- **Open architecture**: ChromaDB and MCP are open standards
|
|
49
161
|
|
|
50
|
-
|
|
51
|
-
2. Entities (components, patterns, fixes, etc.) are extracted and stored
|
|
52
|
-
3. When you start a new Claude Code session, relevant context is automatically loaded
|
|
53
|
-
4. Your knowledge base grows smarter with each session
|
|
162
|
+
## 🆘 Troubleshooting
|
|
54
163
|
|
|
55
|
-
|
|
164
|
+
### Common Issues
|
|
56
165
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
-
|
|
166
|
+
**Hook not triggering?**
|
|
167
|
+
```bash
|
|
168
|
+
claude-mem status # Check installation
|
|
169
|
+
claude-mem install --force # Reinstall hooks
|
|
170
|
+
```
|
|
60
171
|
|
|
61
|
-
|
|
172
|
+
**Context not loading?**
|
|
173
|
+
```bash
|
|
174
|
+
claude-mem load-context # Verify memories exist
|
|
175
|
+
claude-mem logs # Check for errors
|
|
176
|
+
```
|
|
62
177
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
178
|
+
**Performance issues?**
|
|
179
|
+
```bash
|
|
180
|
+
# ChromaDB maintenance (if needed)
|
|
181
|
+
claude-mem status # Check memory usage
|
|
182
|
+
```
|
|
67
183
|
|
|
68
|
-
##
|
|
184
|
+
## 🔧 Requirements
|
|
69
185
|
|
|
70
|
-
|
|
186
|
+
- **Node.js**: 18.0 or higher
|
|
187
|
+
- **Claude Code**: Latest version recommended
|
|
188
|
+
- **Storage**: ~100MB for typical usage
|
|
189
|
+
- **Memory**: 2GB RAM minimum for large knowledge bases
|
|
71
190
|
|
|
72
|
-
## Support
|
|
191
|
+
## 📞 Support & Community
|
|
192
|
+
|
|
193
|
+
- **Documentation**: Complete guides at [claude-mem.ai/docs](https://claude-mem.ai/docs)
|
|
194
|
+
- **Issues**: Report bugs at [GitHub Issues](https://github.com/thedotmack/claude-mem/issues)
|
|
195
|
+
- **Feature Requests**: [GitHub Discussions](https://github.com/thedotmack/claude-mem/discussions)
|
|
196
|
+
- **Community**: Join our [Discord](https://discord.gg/claude-mem) for tips and discussions
|
|
197
|
+
|
|
198
|
+
## 📄 License
|
|
199
|
+
|
|
200
|
+
This software is free to use but is NOT open source. See [LICENSE](LICENSE) file for complete terms.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 🎯 Ready to Transform Your Claude Code Experience?
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
npm install -g claude-mem
|
|
208
|
+
claude-mem install
|
|
209
|
+
```
|
|
73
210
|
|
|
74
|
-
|
|
211
|
+
**Your AI assistant is about to get a lot smarter.** 🧠✨
|
|
75
212
|
|
|
76
213
|
---
|
|
77
214
|
|
|
78
|
-
*Built with ❤️ for
|
|
215
|
+
*Built with ❤️ for developers who believe AI assistants should remember and learn from every conversation.*
|
package/dist/bin/cli.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// <Block> 1.1 ====================================
|
|
3
|
+
// CLI Dependencies and Imports Setup
|
|
4
|
+
// Natural pattern: Import what you need before using it
|
|
5
|
+
import { Command } from 'commander';
|
|
6
|
+
import { PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_DESCRIPTION } from '../shared/config.js';
|
|
7
|
+
// Import command handlers
|
|
8
|
+
import { compress } from '../commands/compress.js';
|
|
9
|
+
import { install } from '../commands/install.js';
|
|
10
|
+
import { uninstall } from '../commands/uninstall.js';
|
|
11
|
+
import { status } from '../commands/status.js';
|
|
12
|
+
import { logs } from '../commands/logs.js';
|
|
13
|
+
import { loadContext } from '../commands/load-context.js';
|
|
14
|
+
import { trash } from '../commands/trash.js';
|
|
15
|
+
import { restore } from '../commands/restore.js';
|
|
16
|
+
const program = new Command();
|
|
17
|
+
// </Block> =======================================
|
|
18
|
+
// <Block> 1.2 ====================================
|
|
19
|
+
// Program Configuration
|
|
20
|
+
// Natural pattern: Configure program metadata first
|
|
21
|
+
program
|
|
22
|
+
.name(PACKAGE_NAME)
|
|
23
|
+
.description(PACKAGE_DESCRIPTION)
|
|
24
|
+
.version(PACKAGE_VERSION);
|
|
25
|
+
// </Block> =======================================
|
|
26
|
+
// <Block> 1.3 ====================================
|
|
27
|
+
// Compress Command Definition
|
|
28
|
+
// Natural pattern: Define command with its options and handler
|
|
29
|
+
// Compress command
|
|
30
|
+
program
|
|
31
|
+
.command('compress [transcript]')
|
|
32
|
+
.description('Compress a Claude Code transcript into memory')
|
|
33
|
+
.option('--output <path>', 'Output directory for compressed files')
|
|
34
|
+
.option('--dry-run', 'Show what would be compressed without doing it')
|
|
35
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
36
|
+
.action(compress);
|
|
37
|
+
// </Block> =======================================
|
|
38
|
+
// <Block> 1.4 ====================================
|
|
39
|
+
// Install Command Definition
|
|
40
|
+
// Natural pattern: Define command with its options and handler
|
|
41
|
+
// Install command
|
|
42
|
+
program
|
|
43
|
+
.command('install')
|
|
44
|
+
.description('Install Claude Code hooks for automatic compression')
|
|
45
|
+
.option('--user', 'Install for current user (default)')
|
|
46
|
+
.option('--project', 'Install for current project only')
|
|
47
|
+
.option('--local', 'Install to custom local directory')
|
|
48
|
+
.option('--path <path>', 'Custom installation path (with --local)')
|
|
49
|
+
.option('--timeout <ms>', 'Hook execution timeout in milliseconds', '180000')
|
|
50
|
+
.option('--skip-mcp', 'Skip Chroma MCP server installation')
|
|
51
|
+
.option('--force', 'Force installation even if already installed')
|
|
52
|
+
.action(install);
|
|
53
|
+
// </Block> =======================================
|
|
54
|
+
// <Block> 1.5 ====================================
|
|
55
|
+
// Uninstall Command Definition
|
|
56
|
+
// Natural pattern: Define command with its options and handler
|
|
57
|
+
// Uninstall command
|
|
58
|
+
program
|
|
59
|
+
.command('uninstall')
|
|
60
|
+
.description('Remove Claude Code hooks')
|
|
61
|
+
.option('--user', 'Remove from user settings (default)')
|
|
62
|
+
.option('--project', 'Remove from project settings')
|
|
63
|
+
.option('--all', 'Remove from both user and project settings')
|
|
64
|
+
.action(uninstall);
|
|
65
|
+
// </Block> =======================================
|
|
66
|
+
// <Block> 1.6 ====================================
|
|
67
|
+
// Status Command Definition
|
|
68
|
+
// Natural pattern: Define command with its handler
|
|
69
|
+
// Status command
|
|
70
|
+
program
|
|
71
|
+
.command('status')
|
|
72
|
+
.description('Check installation status of Claude Memory System')
|
|
73
|
+
.action(status);
|
|
74
|
+
// </Block> =======================================
|
|
75
|
+
// <Block> 1.7 ====================================
|
|
76
|
+
// Logs Command Definition
|
|
77
|
+
// Natural pattern: Define command with its options and handler
|
|
78
|
+
// Logs command
|
|
79
|
+
program
|
|
80
|
+
.command('logs')
|
|
81
|
+
.description('View claude-mem operation logs')
|
|
82
|
+
.option('--debug', 'Show debug logs only')
|
|
83
|
+
.option('--error', 'Show error logs only')
|
|
84
|
+
.option('--tail [n]', 'Show last n lines', '50')
|
|
85
|
+
.option('--follow', 'Follow log output')
|
|
86
|
+
.action(logs);
|
|
87
|
+
// </Block> =======================================
|
|
88
|
+
// <Block> 1.8 ====================================
|
|
89
|
+
// Load-Context Command Definition
|
|
90
|
+
// Natural pattern: Define command with its options and handler
|
|
91
|
+
// Load-context command
|
|
92
|
+
program
|
|
93
|
+
.command('load-context')
|
|
94
|
+
.description('Load compressed memories for current session')
|
|
95
|
+
.option('--project <name>', 'Filter by project name')
|
|
96
|
+
.option('--count <n>', 'Number of memories to load', '10')
|
|
97
|
+
.option('--raw', 'Output raw JSON instead of formatted text')
|
|
98
|
+
.option('--format <type>', 'Output format: json, session-start, or default')
|
|
99
|
+
.action(loadContext);
|
|
100
|
+
// </Block> =======================================
|
|
101
|
+
// <Block> 1.9 ====================================
|
|
102
|
+
// Trash and Restore Commands Definition
|
|
103
|
+
// Natural pattern: Define commands for safe file operations
|
|
104
|
+
// Trash command with subcommands
|
|
105
|
+
const trashCmd = program
|
|
106
|
+
.command('trash')
|
|
107
|
+
.description('Manage trash bin for safe file deletion')
|
|
108
|
+
.argument('[files...]', 'Files to move to trash')
|
|
109
|
+
.option('-r, --recursive', 'Remove directories recursively')
|
|
110
|
+
.option('-R', 'Remove directories recursively (same as -r)')
|
|
111
|
+
.option('-f, --force', 'Suppress errors for nonexistent files')
|
|
112
|
+
.action(async (files, options) => {
|
|
113
|
+
// If no files provided, show help
|
|
114
|
+
if (!files || files.length === 0) {
|
|
115
|
+
trashCmd.outputHelp();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// Map -R to recursive
|
|
119
|
+
if (options.R)
|
|
120
|
+
options.recursive = true;
|
|
121
|
+
await trash(files, {
|
|
122
|
+
force: options.force,
|
|
123
|
+
recursive: options.recursive
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
// Trash view subcommand
|
|
127
|
+
trashCmd
|
|
128
|
+
.command('view')
|
|
129
|
+
.description('View contents of trash bin')
|
|
130
|
+
.action(async () => {
|
|
131
|
+
const { viewTrash } = await import('../commands/trash-view.js');
|
|
132
|
+
await viewTrash();
|
|
133
|
+
});
|
|
134
|
+
// Trash empty subcommand
|
|
135
|
+
trashCmd
|
|
136
|
+
.command('empty')
|
|
137
|
+
.description('Permanently delete all files in trash')
|
|
138
|
+
.option('-f, --force', 'Skip confirmation prompt')
|
|
139
|
+
.action(async (options) => {
|
|
140
|
+
const { emptyTrash } = await import('../commands/trash-empty.js');
|
|
141
|
+
await emptyTrash(options);
|
|
142
|
+
});
|
|
143
|
+
// Restore command
|
|
144
|
+
program
|
|
145
|
+
.command('restore')
|
|
146
|
+
.description('Restore files from trash interactively')
|
|
147
|
+
.action(restore);
|
|
148
|
+
// </Block> =======================================
|
|
149
|
+
// <Block> 1.10 ===================================
|
|
150
|
+
// Hook Commands for Binary Distribution
|
|
151
|
+
// Internal commands called by hook wrappers
|
|
152
|
+
program
|
|
153
|
+
.command('hook:pre-compact', { hidden: true })
|
|
154
|
+
.description('Internal pre-compact hook handler')
|
|
155
|
+
.action(async () => {
|
|
156
|
+
const { preCompactHook } = await import('../commands/hooks.js');
|
|
157
|
+
await preCompactHook();
|
|
158
|
+
});
|
|
159
|
+
program
|
|
160
|
+
.command('hook:session-start', { hidden: true })
|
|
161
|
+
.description('Internal session-start hook handler')
|
|
162
|
+
.action(async () => {
|
|
163
|
+
const { sessionStartHook } = await import('../commands/hooks.js');
|
|
164
|
+
await sessionStartHook();
|
|
165
|
+
});
|
|
166
|
+
program
|
|
167
|
+
.command('hook:session-end', { hidden: true })
|
|
168
|
+
.description('Internal session-end hook handler')
|
|
169
|
+
.action(async () => {
|
|
170
|
+
const { sessionEndHook } = await import('../commands/hooks.js');
|
|
171
|
+
await sessionEndHook();
|
|
172
|
+
});
|
|
173
|
+
// </Block> =======================================
|
|
174
|
+
// <Block> 1.11 ===================================
|
|
175
|
+
// CLI Execution
|
|
176
|
+
// Natural pattern: After defining all commands, parse and execute
|
|
177
|
+
// Parse arguments and execute
|
|
178
|
+
program.parse();
|
|
179
|
+
// </Block> =======================================
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { basename } from 'path';
|
|
2
|
+
import { createLoadingMessage, createCompletionMessage, createOperationSummary, createUserFriendlyError } from '../prompts/templates/context/ContextTemplates.js';
|
|
3
|
+
export async function compress(transcript, options = {}) {
|
|
4
|
+
console.log(createLoadingMessage('compressing'));
|
|
5
|
+
if (!transcript) {
|
|
6
|
+
console.log(createUserFriendlyError('Compression', 'No transcript file provided', 'Please provide a path to a transcript file'));
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const startTime = Date.now();
|
|
11
|
+
// Import and run compression
|
|
12
|
+
const { TranscriptCompressor } = await import('../core/compression/TranscriptCompressor.js');
|
|
13
|
+
const compressor = new TranscriptCompressor({
|
|
14
|
+
verbose: options.verbose || false
|
|
15
|
+
});
|
|
16
|
+
const sessionId = options.sessionId || basename(transcript, '.jsonl');
|
|
17
|
+
const archivePath = await compressor.compress(transcript, sessionId);
|
|
18
|
+
const duration = Date.now() - startTime;
|
|
19
|
+
console.log(createCompletionMessage('Compression', undefined, `Session archived as ${basename(archivePath)}`));
|
|
20
|
+
console.log(createOperationSummary('compress', { count: 1, duration, details: `Session: ${sessionId}` }));
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
24
|
+
console.log(createUserFriendlyError('Compression', errorMessage, 'Check that the transcript file exists and you have write permissions'));
|
|
25
|
+
throw error; // Re-throw to maintain existing error handling behavior
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook command handlers for binary distribution
|
|
3
|
+
* These execute the actual hook logic embedded in the binary
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Pre-compact hook handler
|
|
7
|
+
* Runs compression on the Claude Code transcript
|
|
8
|
+
*/
|
|
9
|
+
export declare function preCompactHook(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Session-start hook handler
|
|
12
|
+
* Loads context for the new session
|
|
13
|
+
*/
|
|
14
|
+
export declare function sessionStartHook(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Session-end hook handler
|
|
17
|
+
* Compresses session transcript when ending with /clear
|
|
18
|
+
*/
|
|
19
|
+
export declare function sessionEndHook(): Promise<void>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook command handlers for binary distribution
|
|
3
|
+
* These execute the actual hook logic embedded in the binary
|
|
4
|
+
*/
|
|
5
|
+
import { compress } from './compress.js';
|
|
6
|
+
import { loadContext } from './load-context.js';
|
|
7
|
+
/**
|
|
8
|
+
* Pre-compact hook handler
|
|
9
|
+
* Runs compression on the Claude Code transcript
|
|
10
|
+
*/
|
|
11
|
+
export async function preCompactHook() {
|
|
12
|
+
try {
|
|
13
|
+
// Read hook data from stdin (Claude Code sends JSON)
|
|
14
|
+
let inputData = '';
|
|
15
|
+
// Set up stdin to read data
|
|
16
|
+
process.stdin.setEncoding('utf8');
|
|
17
|
+
// Collect all input data
|
|
18
|
+
for await (const chunk of process.stdin) {
|
|
19
|
+
inputData += chunk;
|
|
20
|
+
}
|
|
21
|
+
// Parse the JSON input
|
|
22
|
+
let transcriptPath;
|
|
23
|
+
if (inputData) {
|
|
24
|
+
try {
|
|
25
|
+
const hookData = JSON.parse(inputData);
|
|
26
|
+
transcriptPath = hookData.transcript_path;
|
|
27
|
+
}
|
|
28
|
+
catch (parseError) {
|
|
29
|
+
// If JSON parsing fails, treat the input as a direct path
|
|
30
|
+
transcriptPath = inputData.trim();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Fallback to environment variable or command line argument
|
|
34
|
+
if (!transcriptPath) {
|
|
35
|
+
transcriptPath = process.env.TRANSCRIPT_PATH || process.argv[2];
|
|
36
|
+
}
|
|
37
|
+
if (!transcriptPath) {
|
|
38
|
+
console.log('🗜️ Compressing session transcript...');
|
|
39
|
+
console.log('❌ No transcript path provided to pre-compact hook');
|
|
40
|
+
console.log('Hook data received:', inputData || 'none');
|
|
41
|
+
console.log('Environment TRANSCRIPT_PATH:', process.env.TRANSCRIPT_PATH || 'not set');
|
|
42
|
+
console.log('Command line args:', process.argv.slice(2));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// Run compression with the transcript path
|
|
46
|
+
await compress(transcriptPath, { dryRun: false });
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error('Pre-compact hook failed:', error.message);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Session-start hook handler
|
|
55
|
+
* Loads context for the new session
|
|
56
|
+
*/
|
|
57
|
+
export async function sessionStartHook() {
|
|
58
|
+
try {
|
|
59
|
+
// Read hook data from stdin (Claude Code sends JSON)
|
|
60
|
+
let inputData = '';
|
|
61
|
+
// Set up stdin to read data
|
|
62
|
+
process.stdin.setEncoding('utf8');
|
|
63
|
+
// Collect all input data
|
|
64
|
+
for await (const chunk of process.stdin) {
|
|
65
|
+
inputData += chunk;
|
|
66
|
+
}
|
|
67
|
+
// Parse the JSON input to get the current working directory
|
|
68
|
+
let project;
|
|
69
|
+
if (inputData) {
|
|
70
|
+
try {
|
|
71
|
+
const hookData = JSON.parse(inputData);
|
|
72
|
+
// Extract project name from cwd if provided
|
|
73
|
+
if (hookData.cwd) {
|
|
74
|
+
const pathParts = hookData.cwd.split('/');
|
|
75
|
+
project = pathParts[pathParts.length - 1];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (parseError) {
|
|
79
|
+
// If JSON parsing fails, continue without project filtering
|
|
80
|
+
console.error('Failed to parse session-start hook data:', parseError);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// If no project from hook data, try to get from current working directory
|
|
84
|
+
if (!project) {
|
|
85
|
+
const pathParts = process.cwd().split('/');
|
|
86
|
+
project = pathParts[pathParts.length - 1];
|
|
87
|
+
}
|
|
88
|
+
// Load context with session-start format and project filtering
|
|
89
|
+
await loadContext({ format: 'session-start', count: '10', project });
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.error('Session-start hook failed:', error.message);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Session-end hook handler
|
|
98
|
+
* Compresses session transcript when ending with /clear
|
|
99
|
+
*/
|
|
100
|
+
export async function sessionEndHook() {
|
|
101
|
+
try {
|
|
102
|
+
// Read hook data from stdin (Claude Code sends JSON)
|
|
103
|
+
let inputData = '';
|
|
104
|
+
// Set up stdin to read data
|
|
105
|
+
process.stdin.setEncoding('utf8');
|
|
106
|
+
// Collect all input data
|
|
107
|
+
for await (const chunk of process.stdin) {
|
|
108
|
+
inputData += chunk;
|
|
109
|
+
}
|
|
110
|
+
// Parse the JSON input to check the reason for session end
|
|
111
|
+
if (inputData) {
|
|
112
|
+
try {
|
|
113
|
+
const hookData = JSON.parse(inputData);
|
|
114
|
+
// If reason is "clear", compress the session transcript before it's deleted
|
|
115
|
+
if (hookData.reason === 'clear' && hookData.transcript_path) {
|
|
116
|
+
console.log('🗜️ Compressing current session before /clear...');
|
|
117
|
+
await compress(hookData.transcript_path, { dryRun: false });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (parseError) {
|
|
121
|
+
// If JSON parsing fails, log but don't fail the hook
|
|
122
|
+
console.error('Failed to parse hook data:', parseError);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
console.log('Session ended successfully');
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error('Session-end hook failed:', error.message);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
}
|