cc-viewer 1.2.7 → 1.2.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/dist/index.html CHANGED
@@ -6,7 +6,7 @@
6
6
  <title>Claude Code Viewer</title>
7
7
  <link rel="icon" href="/favicon.ico?v=1">
8
8
  <link rel="shortcut icon" href="/favicon.ico?v=1">
9
- <script type="module" crossorigin src="/assets/index-CN78DISW.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-Do8E8Nxd.js"></script>
10
10
  <link rel="stylesheet" crossorigin href="/assets/index-DhZ8St4J.css">
11
11
  </head>
12
12
  <body>
package/findcc.js ADDED
@@ -0,0 +1,107 @@
1
+ import { resolve, join } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { existsSync } from 'node:fs';
4
+ import { homedir } from 'node:os';
5
+ import { execSync } from 'node:child_process';
6
+
7
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
8
+
9
+ // ============ 配置区(第三方适配只需修改此处)============
10
+
11
+ // 日志存储根目录(所有项目日志、偏好设置均存放于此)
12
+ export const LOG_DIR = join(homedir(), '.claude', 'cc-viewer');
13
+
14
+ // npm 包名候选列表(按优先级排列)
15
+ export const PACKAGES = ['@anthropic-ai/claude-code', '@ali/claude-code'];
16
+
17
+ // npm 包内的入口文件(相对于包根目录)
18
+ export const CLI_ENTRY = 'cli.js';
19
+
20
+ // native 二进制候选路径(~ 会在运行时展开为 homedir())
21
+ const NATIVE_CANDIDATES = [
22
+ '~/.claude/local/claude',
23
+ '/usr/local/bin/claude',
24
+ '~/.local/bin/claude',
25
+ '/opt/homebrew/bin/claude',
26
+ ];
27
+
28
+ // 用于 which/command -v 查找的命令名
29
+ export const BINARY_NAME = 'claude';
30
+
31
+ // 注入到 cli.js 的 import 语句(相对路径,基于 cli.js 所在位置)
32
+ export const INJECT_IMPORT = "import '../../cc-viewer/interceptor.js';";
33
+
34
+ // ============ 导出函数 ============
35
+
36
+ export function getGlobalNodeModulesDir() {
37
+ try {
38
+ return execSync('npm root -g', { encoding: 'utf-8' }).trim();
39
+ } catch {
40
+ return null;
41
+ }
42
+ }
43
+
44
+ export function resolveCliPath() {
45
+ // 候选基础目录:__dirname 的上级(适用于常规 npm 安装)+ 全局 node_modules(适用于符号链接安装)
46
+ const baseDirs = [resolve(__dirname, '..')];
47
+ const globalRoot = getGlobalNodeModulesDir();
48
+ if (globalRoot && globalRoot !== resolve(__dirname, '..')) {
49
+ baseDirs.push(globalRoot);
50
+ }
51
+
52
+ for (const baseDir of baseDirs) {
53
+ for (const packageName of PACKAGES) {
54
+ const candidate = join(baseDir, packageName, CLI_ENTRY);
55
+ if (existsSync(candidate)) {
56
+ return candidate;
57
+ }
58
+ }
59
+ }
60
+ // 兜底:返回全局目录下的默认路径,便于错误提示
61
+ return join(globalRoot || resolve(__dirname, '..'), PACKAGES[0], CLI_ENTRY);
62
+ }
63
+
64
+ export function resolveNativePath() {
65
+ // 1. 尝试 which/command -v(继承当前 process.env PATH)
66
+ for (const cmd of [`which ${BINARY_NAME}`, `command -v ${BINARY_NAME}`]) {
67
+ try {
68
+ const result = execSync(cmd, { encoding: 'utf-8', shell: true, env: process.env }).trim();
69
+ // 排除 shell function 的输出(多行说明不是路径)
70
+ if (result && !result.includes('\n') && existsSync(result)) {
71
+ return result;
72
+ }
73
+ } catch {
74
+ // ignore
75
+ }
76
+ }
77
+
78
+ // 2. 检查常见 native 安装路径
79
+ const home = homedir();
80
+ const candidates = NATIVE_CANDIDATES.map(p =>
81
+ p.startsWith('~') ? join(home, p.slice(2)) : p
82
+ );
83
+ for (const p of candidates) {
84
+ if (existsSync(p)) {
85
+ return p;
86
+ }
87
+ }
88
+
89
+ return null;
90
+ }
91
+
92
+ export function buildShellCandidates() {
93
+ const globalRoot = getGlobalNodeModulesDir();
94
+ // 使用 $HOME 而非硬编码绝对路径,保证 shell 可移植性
95
+ const dirs = [];
96
+ if (globalRoot) {
97
+ // 将绝对路径中的 homedir 替换为 $HOME
98
+ const home = homedir();
99
+ const shellRoot = globalRoot.startsWith(home)
100
+ ? '$HOME' + globalRoot.slice(home.length)
101
+ : globalRoot;
102
+ for (const pkg of PACKAGES) {
103
+ dirs.push(`"${shellRoot}/${pkg}/${CLI_ENTRY}"`);
104
+ }
105
+ }
106
+ return dirs.join(' ');
107
+ }