claude-code-smart-fork 1.0.0 → 1.0.1

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 CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  🔀 **Smart session forking for Claude Code** - Find and resume relevant historical sessions across all your projects using AI-powered semantic search.
4
4
 
5
+ **[中文](README.zh-CN.md)** | **[English](README.md)**
6
+
5
7
  [![npm version](https://badge.fury.io/js/claude-code-smart-fork.svg)](https://www.npmjs.com/package/claude-code-smart-fork)
6
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
- [![Node.js CI](https://github.com/yourusername/claude-code-smart-fork/actions/workflows/ci.yml/badge.svg)](https://github.com/yourusername/claude-code-smart-fork/actions)
9
+ [![Node.js CI](https://github.com/fjibj/claude-code-smart-fork/actions/workflows/ci.yml/badge.svg)](https://github.com/fjibj/claude-code-smart-fork/actions)
8
10
 
9
11
  ## 🌟 Features
10
12
 
@@ -262,7 +264,7 @@ All data is stored locally in `~/.smart-fork/`:
262
264
 
263
265
  ```bash
264
266
  # Clone the repository
265
- git clone https://github.com/yourusername/claude-code-smart-fork.git
267
+ git clone https://github.com/fjibj/claude-code-smart-fork.git
266
268
  cd claude-code-smart-fork
267
269
 
268
270
  # Install dependencies
@@ -312,6 +314,6 @@ MIT License - see [LICENSE](LICENSE) file for details.
312
314
 
313
315
  ## 📮 Support
314
316
 
315
- - 🐛 [Report a bug](https://github.com/yourusername/claude-code-smart-fork/issues)
316
- - 💡 [Request a feature](https://github.com/yourusername/claude-code-smart-fork/issues)
317
- - 📧 Contact: your-email@example.com
317
+ - 🐛 [Report a bug](https://github.com/fjibj/claude-code-smart-fork/issues)
318
+ - 💡 [Request a feature](https://github.com/fjibj/claude-code-smart-fork/issues)
319
+ - 📧 Contact: fjibj@users.noreply.github.com
package/README.zh-CN.md CHANGED
@@ -1,34 +1,68 @@
1
- # Claude Code Smart Fork 中文文档
1
+ # Claude Code Smart Fork
2
2
 
3
3
  🔀 **Claude Code 智能会话分支** - 使用 AI 驱动的语义搜索,在所有项目中查找并恢复相关的历史会话。
4
4
 
5
- ## 功能特性
5
+ **[中文](README.zh-CN.md)** | **[English](README.md)**
6
+
7
+ [![npm version](https://badge.fury.io/js/claude-code-smart-fork.svg)](https://www.npmjs.com/package/claude-code-smart-fork)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+ [![Node.js CI](https://github.com/fjibj/claude-code-smart-fork/actions/workflows/ci.yml/badge.svg)](https://github.com/fjibj/claude-code-smart-fork/actions)
10
+
11
+ ## 🌟 功能特性
6
12
 
7
13
  - 🔍 **语义搜索** - 基于含义而非关键词查找相关会话
8
14
  - 🌐 **跨项目** - 在所有项目中搜索,不限于当前项目
9
15
  - 🤖 **AI 驱动** - 使用嵌入向量理解上下文和意图
10
16
  - ⚡ **快速** - 本地向量存储,即时返回结果
11
17
  - 🔒 **隐私** - 默认所有数据保存在本地
18
+ - 🎯 **简易集成** - 作为 slash 命令无缝集成到 Claude Code
12
19
 
13
- ## 快速开始
20
+ ## 📦 安装
14
21
 
15
22
  ```bash
16
- # 安装
23
+ # 全局安装
17
24
  npm install -g claude-code-smart-fork
18
25
 
19
- # 索引当前会话
26
+ # 或使用 npx(无需安装)
27
+ npx claude-code-smart-fork
28
+ ```
29
+
30
+ ## 🚀 快速开始
31
+
32
+ ### 1. 索引当前会话
33
+
34
+ ```bash
20
35
  smart-fork index --summary "实现用户认证功能"
36
+ ```
21
37
 
22
- # 查找相关会话
38
+ ### 2. 查找相关会话
39
+
40
+ ```bash
23
41
  smart-fork detect
42
+ ```
24
43
 
25
- # 跨所有项目搜索
26
- smart-fork detect --all
44
+ ### 3. 切换到会话
45
+
46
+ ```bash
47
+ smart-fork fork-to <session-id>
27
48
  ```
28
49
 
29
- ## Claude Code 集成
50
+ ## 🛠️ 使用方法
51
+
52
+ ### CLI 命令
53
+
54
+ | 命令 | 描述 |
55
+ |---------|-------------|
56
+ | `smart-fork index` | 索引当前会话以供将来搜索 |
57
+ | `smart-fork detect` | 查找相关的历史会话 |
58
+ | `smart-fork detect --all` | 跨所有项目搜索 |
59
+ | `smart-fork list` | 列出所有已索引的会话 |
60
+ | `smart-fork status` | 显示当前状态和建议 |
61
+ | `smart-fork export <id>` | 将会话导出为 JSON |
30
62
 
31
- 安装后,在 Claude Code 中可以使用以下命令:
63
+ ### Claude Code 集成
64
+
65
+ 安装后,Claude Code 中可以使用以下 slash 命令:
32
66
 
33
67
  ```
34
68
  /index-session - 索引当前会话
@@ -38,8 +72,248 @@ smart-fork detect --all
38
72
  /fork-status - 显示状态和建议
39
73
  ```
40
74
 
41
- ## 更多文档
75
+ ## ⚙️ 配置
76
+
77
+ 创建 `~/.smart-fork/config.json`:
78
+
79
+ ```json
80
+ {
81
+ "embedding": {
82
+ "provider": "local",
83
+ "model": "all-MiniLM-L6-v2",
84
+ "dimension": 384
85
+ },
86
+ "vectorStore": {
87
+ "provider": "local",
88
+ "collectionName": "smart-fork-sessions"
89
+ },
90
+ "storage": {
91
+ "sessionsDir": "~/.smart-fork/sessions",
92
+ "indexPath": "~/.smart-fork/index.json"
93
+ }
94
+ }
95
+ ```
96
+
97
+ ### 嵌入提供者
98
+
99
+ #### 本地(默认)- 无需 API 密钥
100
+ ```json
101
+ {
102
+ "embedding": {
103
+ "provider": "local",
104
+ "model": "all-MiniLM-L6-v2"
105
+ }
106
+ }
107
+ ```
108
+
109
+ #### OpenAI
110
+ ```json
111
+ {
112
+ "embedding": {
113
+ "provider": "openai",
114
+ "model": "text-embedding-3-small"
115
+ }
116
+ }
117
+ ```
118
+ 需要 `OPENAI_API_KEY` 环境变量。
119
+
120
+ #### Ollama
121
+ ```json
122
+ {
123
+ "embedding": {
124
+ "provider": "ollama",
125
+ "model": "nomic-embed-text"
126
+ }
127
+ }
128
+ ```
129
+ 需要运行 Ollama 服务器。
130
+
131
+ ## 💡 使用示例
132
+
133
+ ### 示例 1:使用对话历史索引会话
134
+
135
+ ```bash
136
+ # 创建对话历史文件
137
+ cat > conversation.json << 'EOF'
138
+ [
139
+ {
140
+ "id": "turn-1",
141
+ "timestamp": 1709400000000,
142
+ "userMessage": {
143
+ "content": "如何实现用户认证?",
144
+ "metadata": { "files": ["auth.js"] }
145
+ },
146
+ "assistantMessage": {
147
+ "content": "建议使用 JWT + OAuth2。JWT 适合无状态认证,OAuth2 适合第三方登录。",
148
+ "toolCalls": [{"id": "1", "type": "search", "parameters": {"query": "JWT 最佳实践"}}]
149
+ }
150
+ },
151
+ {
152
+ "id": "turn-2",
153
+ "timestamp": 1709400100000,
154
+ "userMessage": {
155
+ "content": "给我代码示例"
156
+ },
157
+ "assistantMessage": {
158
+ "content": "这是一个使用 Node.js 和 jsonwebtoken 的示例...",
159
+ "toolCalls": [
160
+ {"id": "2", "type": "read_file", "parameters": {"path": "examples/auth.js"}},
161
+ {"id": "3", "type": "edit_file", "parameters": {"path": "src/auth.js"}}
162
+ ]
163
+ }
164
+ }
165
+ ]
166
+ EOF
167
+
168
+ # 索引会话
169
+ smart-fork index --conversation conversation.json --summary "使用 JWT 的用户认证" --tags "auth,jwt,nodejs"
170
+
171
+ # 输出:
172
+ # ✓ Session indexed successfully!
173
+ # Session ID: 096549e9-13bd-45bd-9f6c-659d55c78b35
174
+ # Conversation turns: 2
175
+ # Total messages: 4
176
+ ```
177
+
178
+ ### 示例 2:查找并恢复会话
179
+
180
+ ```bash
181
+ # 搜索相关会话
182
+ smart-fork detect --query "认证 JWT 代码示例"
183
+
184
+ # 输出:
185
+ # ✓ Found 1 relevant session(s):
186
+ #
187
+ # 1. my-first-app
188
+ # Path: D:\\claudecode\\MyAICodes\\my-first-app
189
+ # Relevance: 85%
190
+ # Summary: 使用 JWT 的用户认证
191
+ # Last updated: 2026/3/2
192
+
193
+ # 切换到会话
194
+ smart-fork fork-to 096549e9-13bd-45bd-9f6c-659d55c78b35
195
+
196
+ # 输出:
197
+ # 💬 对话历史:
198
+ # ────────────────────────────────────────────────────────────
199
+ # [1] 👤 用户:
200
+ # 如何实现用户认证?
201
+ # 🤖 助手:
202
+ # 建议使用 JWT + OAuth2...
203
+ # 🔧 工具调用:search
204
+ # ────────────────────────────────────────────────────────────
205
+ # [2] 👤 用户:
206
+ # 给我代码示例
207
+ # 🤖 助手:
208
+ # 这是一个 Node.js 示例...
209
+ # 🔧 工具调用:read_file, edit_file
210
+ # ────────────────────────────────────────────────────────────
211
+ # ✨ Total turns: 2
212
+ # 💡 你可以从这里继续对话。
213
+ ```
214
+
215
+ ### 示例 3:跨项目搜索
216
+
217
+ ```bash
218
+ # 在多个项目中索引会话
219
+ # 项目 A:API 网关
220
+ cd ~/projects/api-gateway
221
+ smart-fork index --summary "实现限流中间件"
222
+
223
+ # 项目 B:前端
224
+ cd ~/projects/frontend
225
+ smart-fork index --summary "设置 React 认证上下文"
226
+
227
+ # 跨所有项目搜索
228
+ cd ~/projects/api-gateway
229
+ smart-fork detect --all --query "认证中间件"
230
+
231
+ # 结果将显示来自两个项目的相关会话!
232
+ ```
233
+
234
+ ### 示例 4:使用 Claude Code Slash 命令
235
+
236
+ ```bash
237
+ # 在 Claude Code 中使用 slash 命令:
238
+
239
+ # 索引当前会话
240
+ /index-session 实现用户认证 --tags auth,jwt
241
+
242
+ # 稍后,查找相关会话
243
+ /fork-detect
244
+
245
+ # 切换到指定会话
246
+ /fork-to 096549e9-13bd-45bd-9f6c-659d55c78b35
247
+
248
+ # 列出所有会话
249
+ /list-sessions
250
+ ```
251
+
252
+ ## 📁 数据存储
253
+
254
+ 所有数据本地存储在 `~/.smart-fork/`:
255
+
256
+ ```
257
+ ~/.smart-fork/
258
+ ├── sessions/ # 完整会话数据 (JSON)
259
+ ├── index.json # 会话索引和嵌入向量
260
+ └── config.json # 用户配置
261
+ ```
262
+
263
+ ## 🔧 开发
264
+
265
+ ```bash
266
+ # 克隆仓库
267
+ git clone https://github.com/fjibj/claude-code-smart-fork.git
268
+ cd claude-code-smart-fork
269
+
270
+ # 安装依赖
271
+ npm install
272
+
273
+ # 构建项目
274
+ npm run build
275
+
276
+ # 运行测试
277
+ npm test
278
+
279
+ # 开发模式
280
+ npm run dev
281
+ ```
282
+
283
+ ## 📚 API 使用
284
+
285
+ ```typescript
286
+ import { ForkDetector, SessionManager } from 'claude-code-smart-fork';
287
+
288
+ const detector = new ForkDetector();
289
+ await detector.initialize();
290
+
291
+ // 查找相关会话
292
+ const results = await detector.findRelevantSessions({
293
+ text: "如何实现认证?",
294
+ limit: 5
295
+ });
296
+
297
+ // 切换到会话
298
+ const sessionManager = new SessionManager();
299
+ await sessionManager.forkToSession(results[0].session.id);
300
+ ```
301
+
302
+ ## 🤝 贡献
303
+
304
+ 欢迎贡献!请参阅 [CONTRIBUTING.md](CONTRIBUTING.md) 获取指南。
305
+
306
+ ## 📄 许可证
307
+
308
+ MIT 许可证 - 详见 [LICENSE](LICENSE) 文件。
309
+
310
+ ## 🙏 致谢
311
+
312
+ - 灵感来自对更好的 Claude Code 会话管理的需求
313
+ - 感谢开源社区提供的强大工具
314
+
315
+ ## 📮 支持
42
316
 
43
- - [英文 README](./README.md)
44
- - [贡献指南](./CONTRIBUTING.md)
45
- - [更新日志](./CHANGELOG.md)
317
+ - 🐛 [报告 Bug](https://github.com/fjibj/claude-code-smart-fork/issues)
318
+ - 💡 [请求功能](https://github.com/fjibj/claude-code-smart-fork/issues)
319
+ - 📧 联系:fjibj@users.noreply.github.com
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-smart-fork",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Smart session forking for Claude Code - find and resume relevant historical sessions across projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,8 +11,10 @@
11
11
  },
12
12
  "files": [
13
13
  "dist/**/*",
14
+ "scripts/**/*",
14
15
  "LICENSE",
15
16
  "README.md",
17
+ "README.zh-CN.md",
16
18
  "CHANGELOG.md"
17
19
  ],
18
20
  "scripts": {
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Post-install script
3
+ * Sets up Claude Code integration automatically
4
+ */
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const os = require('os');
9
+
10
+ function installClaudeHooks() {
11
+ console.log('🔧 Setting up Claude Code Smart Fork integration...\n');
12
+
13
+ // Find Claude Code configuration directory
14
+ const possiblePaths = [
15
+ // macOS
16
+ path.join(os.homedir(), 'Library', 'Application Support', 'Claude', 'settings.json'),
17
+ // Linux
18
+ path.join(os.homedir(), '.config', 'claude', 'settings.json'),
19
+ // Windows
20
+ path.join(os.homedir(), 'AppData', 'Roaming', 'Claude', 'settings.json'),
21
+ ];
22
+
23
+ // Check for CLAUDE_CONFIG environment variable
24
+ if (process.env.CLAUDE_CONFIG) {
25
+ possiblePaths.unshift(path.join(process.env.CLAUDE_CONFIG, 'settings.json'));
26
+ }
27
+
28
+ let claudeConfigPath = null;
29
+ for (const p of possiblePaths) {
30
+ if (fs.existsSync(p)) {
31
+ claudeConfigPath = p;
32
+ break;
33
+ }
34
+ }
35
+
36
+ if (!claudeConfigPath) {
37
+ console.log('⚠️ Claude Code configuration not found automatically.');
38
+ console.log('To manually install slash commands, add the following to your Claude Code settings:\n');
39
+ console.log(JSON.stringify({
40
+ slashCommands: [
41
+ {
42
+ name: 'fork-detect',
43
+ description: 'Find relevant historical sessions across all projects',
44
+ entrypoint: 'npx smart-fork detect'
45
+ },
46
+ {
47
+ name: 'fork-to',
48
+ description: 'Switch to a specific historical session',
49
+ entrypoint: 'npx smart-fork fork-to'
50
+ },
51
+ {
52
+ name: 'index-session',
53
+ description: 'Index current session for future searching',
54
+ entrypoint: 'npx smart-fork index'
55
+ },
56
+ {
57
+ name: 'list-sessions',
58
+ description: 'List all indexed sessions',
59
+ entrypoint: 'npx smart-fork list'
60
+ }
61
+ ]
62
+ }, null, 2));
63
+ return;
64
+ }
65
+
66
+ // Read existing config
67
+ let config = {};
68
+ try {
69
+ config = JSON.parse(fs.readFileSync(claudeConfigPath, 'utf-8'));
70
+ } catch {
71
+ // File doesn't exist or is invalid, start fresh
72
+ }
73
+
74
+ // Add our slash commands
75
+ config.slashCommands = config.slashCommands || [];
76
+
77
+ const ourCommands = [
78
+ {
79
+ name: 'fork-detect',
80
+ description: 'Find relevant historical sessions across all projects',
81
+ entrypoint: 'npx smart-fork detect'
82
+ },
83
+ {
84
+ name: 'fork-to',
85
+ description: 'Switch to a specific historical session (usage: /fork-to <session-id>)',
86
+ entrypoint: 'npx smart-fork fork-to'
87
+ },
88
+ {
89
+ name: 'index-session',
90
+ description: 'Index current session for future searching',
91
+ entrypoint: 'npx smart-fork index'
92
+ },
93
+ {
94
+ name: 'list-sessions',
95
+ description: 'List all indexed sessions',
96
+ entrypoint: 'npx smart-fork list'
97
+ },
98
+ {
99
+ name: 'fork-status',
100
+ description: 'Show current fork status and suggestions',
101
+ entrypoint: 'npx smart-fork status'
102
+ }
103
+ ];
104
+
105
+ // Remove existing commands with same names
106
+ config.slashCommands = config.slashCommands.filter(
107
+ cmd => !ourCommands.some(our => our.name === cmd.name)
108
+ );
109
+
110
+ // Add our commands
111
+ config.slashCommands.push(...ourCommands);
112
+
113
+ // Save config
114
+ fs.mkdirSync(path.dirname(claudeConfigPath), { recursive: true });
115
+ fs.writeFileSync(claudeConfigPath, JSON.stringify(config, null, 2));
116
+
117
+ console.log('✅ Claude Code integration installed successfully!\n');
118
+ console.log('Available slash commands:');
119
+ ourCommands.forEach(cmd => {
120
+ console.log(` /${cmd.name} - ${cmd.description}`);
121
+ });
122
+ console.log('\nUsage:');
123
+ console.log(' 1. Index your current session: /index-session');
124
+ console.log(' 2. Later, find relevant sessions: /fork-detect');
125
+ console.log(' 3. Switch to a session: /fork-to <session-id>');
126
+ }
127
+
128
+ // Run installation
129
+ installClaudeHooks();