claude-opencode-viewer 2.6.4 → 2.6.6

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/bin/cov.js CHANGED
@@ -18,13 +18,32 @@ const SERVER_PATH = join(__dirname, '..', 'server.js');
18
18
 
19
19
  const args = process.argv.slice(2);
20
20
 
21
+ // 端口配置
22
+ const PC_PORT_MIN = 19200;
23
+ const PC_PORT_MAX = 19220;
24
+ const DEFAULT_PORT = 7008;
25
+
26
+ function getPort() {
27
+ const portIdx = args.indexOf('--port');
28
+ if (portIdx !== -1 && args[portIdx + 1]) {
29
+ return parseInt(args[portIdx + 1]);
30
+ }
31
+ if (args.includes('--pc')) {
32
+ return PC_PORT_MIN + Math.floor(Math.random() * (PC_PORT_MAX - PC_PORT_MIN + 1));
33
+ }
34
+ return DEFAULT_PORT;
35
+ }
36
+
21
37
  if (args.includes('--help') || args.includes('-h')) {
22
38
  console.log(`
23
39
  ╔══════════════════════════════════════════════════════════╗
24
40
  ║ Claude OpenCode Viewer (cov) ║
25
41
  ╠══════════════════════════════════════════════════════════╣
26
42
  ║ 用法: ║
27
- ║ cov 在当前目录启动服务
43
+ ║ cov 在当前目录启动服务(端口7008)
44
+ ║ cov --pc PC端随机端口启动(19200-19220) ║
45
+ ║ cov --pc --https PC端HTTPS模式启动 ║
46
+ ║ cov --port <端口号> 指定端口启动 ║
28
47
  ║ cov [路径] 在指定目录启动服务 ║
29
48
  ║ cov --help, -h 显示此帮助信息 ║
30
49
  ║ cov --version, -v 显示版本号 ║
@@ -33,10 +52,7 @@ if (args.includes('--help') || args.includes('-h')) {
33
52
  ║ - 同时支持 Claude Code 和 OpenCode ║
34
53
  ║ - 丝滑切换两个 AI 终端 ║
35
54
  ║ - 支持移动端访问 ║
36
- ╠══════════════════════════════════════════════════════════╣
37
- ║ 访问地址: ║
38
- ║ 本地:http://127.0.0.1:7008 ║
39
- ║ 手机:http://<本机 IP>:7008 ║
55
+ ║ - 手机/PC 可独立端口互不干扰 ║
40
56
  ╚══════════════════════════════════════════════════════════╝
41
57
  `);
42
58
  process.exit(0);
@@ -51,9 +67,11 @@ if (args.includes('--version') || args.includes('-v')) {
51
67
  process.exit(0);
52
68
  }
53
69
 
54
- // 如果指定了路径,切换到该目录
55
- if (args.length > 0 && !args[0].startsWith('-')) {
56
- const targetPath = resolve(args[0]);
70
+ // 如果指定了路径,切换到该目录(跳过 --pc, --port 及其值)
71
+ for (const arg of args) {
72
+ if (arg.startsWith('-')) continue;
73
+ if (args[args.indexOf(arg) - 1] === '--port') continue;
74
+ const targetPath = resolve(arg);
57
75
  if (existsSync(targetPath)) {
58
76
  process.chdir(targetPath);
59
77
  console.log(`📁 工作目录:${process.cwd()}`);
@@ -61,10 +79,15 @@ if (args.length > 0 && !args[0].startsWith('-')) {
61
79
  console.error(`❌ 目录不存在:${targetPath}`);
62
80
  process.exit(1);
63
81
  }
82
+ break;
64
83
  }
65
84
 
66
85
  // 启动服务器
67
- const server = spawn(process.execPath, [SERVER_PATH], {
86
+ const port = getPort();
87
+ const serverArgs = [SERVER_PATH, String(port)];
88
+ if (args.includes('--pc')) serverArgs.push('--pc');
89
+ if (args.includes('--https')) serverArgs.push('--https');
90
+ const server = spawn(process.execPath, serverArgs, {
68
91
  stdio: 'inherit',
69
92
  cwd: process.cwd(),
70
93
  });