@jhihjian/claude-daemon 1.1.0 → 1.1.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.
Files changed (3) hide show
  1. package/bin/cli.js +110 -18
  2. package/install.ps1 +209 -0
  3. package/package.json +2 -1
package/bin/cli.js CHANGED
@@ -3,11 +3,13 @@
3
3
  /**
4
4
  * claude-daemon CLI
5
5
  * npm 包的命令行入口
6
+ * 支持 Windows、Linux、macOS
6
7
  */
7
8
 
8
- const { execSync } = require('child_process');
9
+ const { execSync, spawn } = require('child_process');
9
10
  const { join } = require('path');
10
11
  const { existsSync } = require('fs');
12
+ const os = require('os');
11
13
 
12
14
  const COLORS = {
13
15
  reset: '\x1b[0m',
@@ -43,44 +45,134 @@ function printUsage() {
43
45
  console.log('');
44
46
  }
45
47
 
48
+ /**
49
+ * 检测系统平台
50
+ */
51
+ function detectPlatform() {
52
+ const platform = os.platform();
53
+
54
+ if (platform === 'win32') {
55
+ return 'windows';
56
+ } else if (platform === 'darwin') {
57
+ return 'macos';
58
+ } else if (platform === 'linux') {
59
+ return 'linux';
60
+ }
61
+
62
+ return 'unknown';
63
+ }
64
+
65
+ /**
66
+ * 安装函数
67
+ */
46
68
  function install() {
47
69
  printBanner();
48
- log('green', '[1/3] 定位安装脚本...');
70
+
71
+ const platform = detectPlatform();
72
+ log('green', `[1/4] 检测系统平台: ${platform}`);
73
+ console.log('');
74
+
75
+ log('green', '[2/4] 定位安装脚本...');
49
76
 
50
77
  // 获取包的安装路径
51
78
  const packageDir = join(__dirname, '..');
52
- const installScript = join(packageDir, 'install.sh');
53
79
 
54
- if (!existsSync(installScript)) {
55
- log('red', '✗ 找不到 install.sh');
56
- log('yellow', '请确保包安装正确');
57
- process.exit(1);
80
+ let installScript;
81
+ let useShell = false;
82
+
83
+ if (platform === 'windows') {
84
+ // Windows: 使用 PowerShell 脚本
85
+ installScript = join(packageDir, 'install.ps1');
86
+
87
+ if (!existsSync(installScript)) {
88
+ log('red', '✗ 找不到 install.ps1');
89
+ log('yellow', '请确保包安装正确');
90
+ process.exit(1);
91
+ }
92
+
93
+ log('green', ' ✓ 找到 Windows 安装脚本 (install.ps1)');
94
+ } else {
95
+ // Linux/macOS: 使用 bash 脚本
96
+ installScript = join(packageDir, 'install.sh');
97
+ useShell = true;
98
+
99
+ if (!existsSync(installScript)) {
100
+ log('red', '✗ 找不到 install.sh');
101
+ log('yellow', '请确保包安装正确');
102
+ process.exit(1);
103
+ }
104
+
105
+ log('green', ' ✓ 找到安装脚本 (install.sh)');
58
106
  }
59
107
 
60
- log('green', ' ✓ 找到安装脚本');
61
108
  console.log('');
62
-
63
- log('green', '[2/3] 执行安装...');
109
+ log('green', '[3/4] 执行安装...');
64
110
  console.log('');
65
111
 
66
112
  try {
67
- // 执行安装脚本
68
- execSync(`bash "${installScript}"`, {
69
- stdio: 'inherit',
70
- cwd: packageDir,
71
- });
113
+ if (platform === 'windows') {
114
+ // Windows: 使用 PowerShell 执行
115
+ const powershell = spawn('powershell.exe', [
116
+ '-ExecutionPolicy', 'Bypass',
117
+ '-File', installScript
118
+ ], {
119
+ stdio: 'inherit',
120
+ cwd: packageDir,
121
+ });
122
+
123
+ powershell.on('close', (code) => {
124
+ if (code !== 0) {
125
+ log('red', '\n✗ 安装失败');
126
+ log('yellow', '请查看错误信息并重试');
127
+ log('yellow', '\n提示: 如果遇到权限问题,请以管理员身份运行 PowerShell');
128
+ process.exit(1);
129
+ }
130
+
131
+ printSuccess(platform);
132
+ });
133
+
134
+ } else {
135
+ // Linux/macOS: 使用 bash 执行
136
+ execSync(`bash "${installScript}"`, {
137
+ stdio: 'inherit',
138
+ cwd: packageDir,
139
+ });
140
+
141
+ printSuccess(platform);
142
+ }
143
+
72
144
  } catch (error) {
73
145
  log('red', '\n✗ 安装失败');
74
146
  log('yellow', '请查看错误信息并重试');
147
+
148
+ if (platform === 'windows') {
149
+ log('yellow', '\n提示: 如果遇到权限问题,请以管理员身份运行 PowerShell');
150
+ }
151
+
75
152
  process.exit(1);
76
153
  }
154
+ }
77
155
 
156
+ /**
157
+ * 打印安装成功信息
158
+ */
159
+ function printSuccess(platform) {
78
160
  console.log('');
79
- log('green', '[3/3] 安装完成!');
161
+ log('green', '[4/4] 安装完成!');
80
162
  console.log('');
81
163
  log('yellow', '下一步:');
82
- console.log(' 1. 重新加载 shell: source ~/.bashrc');
83
- console.log(' 2. 测试: claude-sessions recent 5');
164
+
165
+ if (platform === 'windows') {
166
+ console.log(' 1. 重启终端或重新加载 PowerShell 配置');
167
+ console.log(' 2. 测试: claude-sessions recent 5');
168
+ } else {
169
+ console.log(' 1. 重新加载 shell: source ~/.bashrc (或 source ~/.zshrc)');
170
+ console.log(' 2. 测试: claude-sessions recent 5');
171
+ }
172
+
173
+ console.log('');
174
+ log('yellow', '查看文档:');
175
+ console.log(' https://github.com/JhihJian/claude-daemon');
84
176
  console.log('');
85
177
  }
86
178
 
package/install.ps1 ADDED
@@ -0,0 +1,209 @@
1
+ # Claude Code 会话历史系统 - Windows PowerShell 安装脚本
2
+ # 版本: 1.0
3
+
4
+ param(
5
+ [switch]$Force
6
+ )
7
+
8
+ Write-Host "======================================" -ForegroundColor Green
9
+ Write-Host "Claude Code 会话历史系统 - 安装程序" -ForegroundColor Green
10
+ Write-Host "======================================" -ForegroundColor Green
11
+ Write-Host ""
12
+
13
+ # 检测系统
14
+ Write-Host "检测到系统: Windows" -ForegroundColor Yellow
15
+ Write-Host "PowerShell 版本: $($PSVersionTable.PSVersion)" -ForegroundColor Yellow
16
+ Write-Host ""
17
+
18
+ # 获取脚本所在目录
19
+ $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
20
+ Write-Host "安装源目录: $ScriptDir" -ForegroundColor Yellow
21
+ Write-Host ""
22
+
23
+ # 1. 检查 Bun
24
+ Write-Host "[1/6] 检查 Bun 运行时..." -ForegroundColor Green
25
+ $BunPath = Get-Command bun -ErrorAction SilentlyContinue
26
+
27
+ if ($BunPath) {
28
+ Write-Host "✓ Bun 已安装: $($BunPath.Source)" -ForegroundColor Green
29
+ $BunExe = $BunPath.Source
30
+ } else {
31
+ Write-Host "⚠ Bun 未安装,正在安装..." -ForegroundColor Yellow
32
+
33
+ # 安装 Bun for Windows
34
+ irm bun.sh/install.ps1 | iex
35
+
36
+ # 刷新环境变量
37
+ $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
38
+
39
+ $BunExe = "$env:USERPROFILE\.bun\bin\bun.exe"
40
+ Write-Host "✓ Bun 安装完成: $BunExe" -ForegroundColor Green
41
+ }
42
+ Write-Host ""
43
+
44
+ # 2. 创建目录结构
45
+ Write-Host "[2/6] 创建目录结构..." -ForegroundColor Green
46
+ $ClaudeDir = "$env:USERPROFILE\.claude"
47
+ $SessionsDir = "$ClaudeDir\SESSIONS"
48
+
49
+ $Directories = @(
50
+ "$SessionsDir\raw",
51
+ "$SessionsDir\analysis\summaries",
52
+ "$SessionsDir\analysis\by-type",
53
+ "$SessionsDir\analysis\by-directory",
54
+ "$SessionsDir\index",
55
+ "$ClaudeDir\hooks"
56
+ )
57
+
58
+ foreach ($Dir in $Directories) {
59
+ if (-not (Test-Path $Dir)) {
60
+ New-Item -ItemType Directory -Path $Dir -Force | Out-Null
61
+ }
62
+ }
63
+ Write-Host "✓ 目录创建完成" -ForegroundColor Green
64
+ Write-Host ""
65
+
66
+ # 3. 配置 hooks
67
+ Write-Host "[3/6] 配置 hooks..." -ForegroundColor Green
68
+ $HookFiles = Get-ChildItem -Path "$ScriptDir\hooks\*.ts"
69
+
70
+ foreach ($Hook in $HookFiles) {
71
+ # 读取文件内容
72
+ $Content = Get-Content $Hook.FullName -Raw
73
+
74
+ # 替换 shebang 为 Windows Bun 路径
75
+ $Content = $Content -replace '^#!.*', "#!$BunExe"
76
+
77
+ # 保存到目标位置
78
+ $TargetPath = "$ClaudeDir\hooks\$($Hook.Name)"
79
+ Set-Content -Path $TargetPath -Value $Content -NoNewline
80
+
81
+ Write-Host " ✓ $($Hook.Name)" -ForegroundColor Green
82
+ }
83
+ Write-Host ""
84
+
85
+ # 4. 配置 Claude Code settings
86
+ Write-Host "[4/6] 配置 Claude Code..." -ForegroundColor Green
87
+ $SettingsFile = "$ClaudeDir\settings.json"
88
+
89
+ if (Test-Path $SettingsFile) {
90
+ Write-Host "⚠ settings.json 已存在,备份到 settings.json.backup" -ForegroundColor Yellow
91
+ Copy-Item $SettingsFile "$SettingsFile.backup" -Force
92
+ }
93
+
94
+ # 创建 settings.json(使用 Windows 路径格式)
95
+ $HooksPath = $ClaudeDir.Replace('\', '\\') + "\\hooks"
96
+ $Settings = @{
97
+ model = "opus"
98
+ hooks = @{
99
+ SessionStart = @(
100
+ @{
101
+ hooks = @(
102
+ @{
103
+ type = "command"
104
+ command = "$HooksPath\\SessionRecorder.hook.ts"
105
+ }
106
+ )
107
+ }
108
+ )
109
+ PostToolUse = @(
110
+ @{
111
+ hooks = @(
112
+ @{
113
+ type = "command"
114
+ command = "$HooksPath\\SessionToolCapture-v2.hook.ts"
115
+ }
116
+ )
117
+ }
118
+ )
119
+ Stop = @(
120
+ @{
121
+ hooks = @(
122
+ @{
123
+ type = "command"
124
+ command = "$HooksPath\\SessionAnalyzer.hook.ts"
125
+ }
126
+ )
127
+ }
128
+ )
129
+ }
130
+ }
131
+
132
+ $Settings | ConvertTo-Json -Depth 10 | Set-Content $SettingsFile
133
+ Write-Host "✓ settings.json 配置完成" -ForegroundColor Green
134
+ Write-Host ""
135
+
136
+ # 5. 安装查询工具
137
+ Write-Host "[5/6] 安装查询工具..." -ForegroundColor Green
138
+ $BinDir = "$env:USERPROFILE\bin"
139
+
140
+ if (-not (Test-Path $BinDir)) {
141
+ New-Item -ItemType Directory -Path $BinDir | Out-Null
142
+ }
143
+
144
+ # 创建查询工具的包装脚本
145
+ $WrapperScript = @"
146
+ # Claude 会话历史查询工具
147
+ param([string]`$Command, [string]`$Arg1, [string]`$Arg2)
148
+
149
+ `$BunPath = "$BunExe"
150
+ `$ToolsDir = "$ScriptDir\tools"
151
+
152
+ switch (`$Command) {
153
+ "recent" {
154
+ & `$BunPath "`$ToolsDir\SessionQuery.ts" recent `$Arg1
155
+ }
156
+ "type" {
157
+ & `$BunPath "`$ToolsDir\SessionQuery.ts" type `$Arg1
158
+ }
159
+ "dir" {
160
+ & `$BunPath "`$ToolsDir\SessionQuery.ts" dir `$Arg1
161
+ }
162
+ "stats" {
163
+ & `$BunPath "`$ToolsDir\SessionStats.ts" `$Arg1
164
+ }
165
+ "show" {
166
+ Write-Host "show 命令在 Windows 上需要使用 WSL 或 Git Bash" -ForegroundColor Yellow
167
+ Write-Host "请使用: bun `$ToolsDir\SessionQuery.ts recent 1" -ForegroundColor Yellow
168
+ }
169
+ default {
170
+ Write-Host "用法:"
171
+ Write-Host " claude-sessions recent [N] - 查看最近 N 个会话"
172
+ Write-Host " claude-sessions type <类型> - 查看指定类型的会话"
173
+ Write-Host " claude-sessions dir <目录> - 查看指定目录的会话"
174
+ Write-Host " claude-sessions stats global - 查看全局统计"
175
+ }
176
+ }
177
+ "@
178
+
179
+ Set-Content -Path "$BinDir\claude-sessions.ps1" -Value $WrapperScript
180
+ Write-Host "✓ 查询工具安装完成" -ForegroundColor Green
181
+ Write-Host ""
182
+
183
+ # 6. 配置环境变量
184
+ Write-Host "[6/6] 配置环境变量..." -ForegroundColor Green
185
+
186
+ # 添加到用户 PATH
187
+ $UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
188
+ if ($UserPath -notlike "*$BinDir*") {
189
+ [Environment]::SetEnvironmentVariable("Path", "$UserPath;$BinDir", "User")
190
+ Write-Host "✓ 已添加到 PATH" -ForegroundColor Green
191
+ } else {
192
+ Write-Host "✓ PATH 已配置" -ForegroundColor Green
193
+ }
194
+
195
+ Write-Host ""
196
+ Write-Host "======================================" -ForegroundColor Green
197
+ Write-Host "✓ 安装完成!" -ForegroundColor Green
198
+ Write-Host "======================================" -ForegroundColor Green
199
+ Write-Host ""
200
+ Write-Host "使用方法:" -ForegroundColor Yellow
201
+ Write-Host ""
202
+ Write-Host " PowerShell -File $BinDir\claude-sessions.ps1 recent 5" -ForegroundColor Green
203
+ Write-Host " 或者直接使用 Bun:" -ForegroundColor Green
204
+ Write-Host " bun $ScriptDir\tools\SessionQuery.ts recent 5" -ForegroundColor Green
205
+ Write-Host ""
206
+ Write-Host "重要提示:" -ForegroundColor Yellow
207
+ Write-Host " 1. 重启 PowerShell 以加载新的 PATH" -ForegroundColor Yellow
208
+ Write-Host " 2. 查看 Windows 指南: cat $ScriptDir\WINDOWS.md" -ForegroundColor Yellow
209
+ Write-Host ""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jhihjian/claude-daemon",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Claude Code 会话历史记录系统 - 自动记录、分类和分析 Claude Code 会话",
5
5
  "keywords": [
6
6
  "claude",
@@ -30,6 +30,7 @@
30
30
  "tools/",
31
31
  "bin/",
32
32
  "install.sh",
33
+ "install.ps1",
33
34
  "README.md",
34
35
  "QUICKSTART.md"
35
36
  ],