claude-opencode-viewer 2.6.9 → 2.6.10

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/cov.js +1 -0
  2. package/package.json +1 -1
  3. package/server.js +33 -8
package/bin/cov.js CHANGED
@@ -87,6 +87,7 @@ const port = getPort();
87
87
  const serverArgs = [SERVER_PATH, String(port)];
88
88
  if (args.includes('--pc')) serverArgs.push('--pc');
89
89
  if (args.includes('--https')) serverArgs.push('--https');
90
+ if (args.includes('--json')) serverArgs.push('--json');
90
91
  const server = spawn(process.execPath, serverArgs, {
91
92
  stdio: 'inherit',
92
93
  cwd: process.cwd(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-opencode-viewer",
3
- "version": "2.6.9",
3
+ "version": "2.6.10",
4
4
  "description": "A unified terminal viewer for Claude Code and OpenCode with seamless switching",
5
5
  "type": "module",
6
6
  "main": "server.js",
package/server.js CHANGED
@@ -18,6 +18,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
18
18
  const PORT = parseInt(process.argv[2]) || 7008;
19
19
  const IS_PC = process.argv.includes('--pc');
20
20
  const USE_HTTPS = process.argv.includes('--https');
21
+ const JSON_OUTPUT = process.argv.includes('--json');
21
22
 
22
23
  // 自签名证书生成(使用 selfsigned 库,不依赖 openssl)
23
24
  async function getOrCreateCert() {
@@ -452,6 +453,21 @@ const requestHandler = async (req, res) => {
452
453
  return;
453
454
  }
454
455
 
456
+ // API: 获取服务端口信息
457
+ if (req.url === '/api/port') {
458
+ res.writeHead(200, {
459
+ 'Content-Type': 'application/json',
460
+ 'Access-Control-Allow-Origin': '*',
461
+ });
462
+ res.end(JSON.stringify({
463
+ port: PORT,
464
+ pc: IS_PC,
465
+ https: USE_HTTPS,
466
+ proto: USE_HTTPS ? 'https' : 'http',
467
+ }));
468
+ return;
469
+ }
470
+
455
471
  // API: 获取会话列表
456
472
  if (req.url === '/api/sessions') {
457
473
  res.writeHead(200, {
@@ -776,17 +792,26 @@ wss.on('connection', (ws, req) => {
776
792
  });
777
793
  });
778
794
 
795
+ process.on('SIGINT', () => process.exit(0));
796
+ process.on('SIGTERM', () => process.exit(0));
797
+
779
798
  server.listen(PORT, '0.0.0.0', async () => {
780
799
  const ip = getLocalIp();
781
800
  const proto = USE_HTTPS ? 'https' : 'http';
782
- console.log('\n' + '='.repeat(50));
783
- console.log('✅ Claude OpenCode Viewer 已启动');
784
- console.log('='.repeat(50));
785
- console.log(`🖥️ 本地访问:${proto}://127.0.0.1:${PORT}`);
786
- console.log(`📱 手机访问:${proto}://${ip}:${PORT}`);
787
- if (USE_HTTPS) console.log('🔐 HTTPS 模式(首次访问需信任自签名证书)');
788
- console.log('='.repeat(50));
789
- console.log('\n按 Ctrl+C 停止服务\n');
801
+
802
+ if (JSON_OUTPUT) {
803
+ // 输出一行 JSON 供外部程序解析,然后继续运行
804
+ console.log(JSON.stringify({ port: PORT, url: `${proto}://127.0.0.1:${PORT}`, ip, proto, pid: process.pid }));
805
+ } else {
806
+ console.log('\n' + '='.repeat(50));
807
+ console.log('✅ Claude OpenCode Viewer 已启动');
808
+ console.log('='.repeat(50));
809
+ console.log(`🖥️ 本地访问:${proto}://127.0.0.1:${PORT}`);
810
+ console.log(`📱 手机访问:${proto}://${ip}:${PORT}`);
811
+ if (USE_HTTPS) console.log('🔐 HTTPS 模式(首次访问需信任自签名证书)');
812
+ console.log('='.repeat(50));
813
+ console.log('\n按 Ctrl+C 停止服务\n');
814
+ }
790
815
 
791
816
  await spawnProcess('opencode');
792
817
  });