claude-opencode-viewer 2.6.19 → 2.6.21
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/index-pc.html +9 -1
- package/package.json +1 -1
- package/server.js +36 -11
package/index-pc.html
CHANGED
|
@@ -848,10 +848,18 @@
|
|
|
848
848
|
}
|
|
849
849
|
|
|
850
850
|
// PC端尺寸计算
|
|
851
|
+
var resizeRetryCount = 0;
|
|
851
852
|
function resize() {
|
|
852
853
|
var container = document.getElementById('terminal');
|
|
853
854
|
var cellDims = getCellDims();
|
|
854
|
-
if (!cellDims)
|
|
855
|
+
if (!cellDims) {
|
|
856
|
+
if (resizeRetryCount < 10) {
|
|
857
|
+
resizeRetryCount++;
|
|
858
|
+
setTimeout(resize, 200);
|
|
859
|
+
}
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
resizeRetryCount = 0;
|
|
855
863
|
var charW = cellDims.width;
|
|
856
864
|
var charH = cellDims.height;
|
|
857
865
|
var availW = container.clientWidth;
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -162,6 +162,26 @@ function findCommand(cmd) {
|
|
|
162
162
|
return cmd;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
function killProcessTree(proc) {
|
|
166
|
+
if (!proc || !proc.pid) return;
|
|
167
|
+
const pid = proc.pid;
|
|
168
|
+
// 1. 尝试杀整个进程组(负 PID)
|
|
169
|
+
try { process.kill(-pid, 'SIGTERM'); } catch {}
|
|
170
|
+
// 2. 杀 pty 进程本身
|
|
171
|
+
try { proc.kill(); } catch {}
|
|
172
|
+
// 3. 1秒后检查,如果还活着就 SIGKILL 强杀
|
|
173
|
+
setTimeout(() => {
|
|
174
|
+
try {
|
|
175
|
+
process.kill(-pid, 0); // 检查进程组是否还在
|
|
176
|
+
process.kill(-pid, 'SIGKILL');
|
|
177
|
+
} catch {}
|
|
178
|
+
try {
|
|
179
|
+
process.kill(pid, 0);
|
|
180
|
+
process.kill(pid, 'SIGKILL');
|
|
181
|
+
} catch {}
|
|
182
|
+
}, 1000);
|
|
183
|
+
}
|
|
184
|
+
|
|
165
185
|
async function spawnProcess(mode, sessionId = null) {
|
|
166
186
|
const pty = await getPty();
|
|
167
187
|
fixSpawnHelperPermissions();
|
|
@@ -245,7 +265,7 @@ async function spawnProcess(mode, sessionId = null) {
|
|
|
245
265
|
if (claudeProcess && claudeProcess !== proc && claudeProcess.pid) {
|
|
246
266
|
try {
|
|
247
267
|
console.log(`[spawnProcess] 清理旧 claude 进程 PID: ${claudeProcess.pid}`);
|
|
248
|
-
claudeProcess
|
|
268
|
+
killProcessTree(claudeProcess);
|
|
249
269
|
} catch {}
|
|
250
270
|
}
|
|
251
271
|
claudeProcess = proc;
|
|
@@ -253,7 +273,7 @@ async function spawnProcess(mode, sessionId = null) {
|
|
|
253
273
|
if (opencodeProcess && opencodeProcess !== proc && opencodeProcess.pid) {
|
|
254
274
|
try {
|
|
255
275
|
console.log(`[spawnProcess] 清理旧 opencode 进程 PID: ${opencodeProcess.pid}`);
|
|
256
|
-
opencodeProcess
|
|
276
|
+
killProcessTree(opencodeProcess);
|
|
257
277
|
} catch {}
|
|
258
278
|
}
|
|
259
279
|
opencodeProcess = proc;
|
|
@@ -287,7 +307,7 @@ async function switchMode(newMode) {
|
|
|
287
307
|
if (currentMode === 'claude' && claudeProcess) {
|
|
288
308
|
try {
|
|
289
309
|
console.log(`[switchMode] 杀死 claude 进程 PID: ${claudeProcess.pid}`);
|
|
290
|
-
claudeProcess
|
|
310
|
+
killProcessTree(claudeProcess);
|
|
291
311
|
} catch (e) {
|
|
292
312
|
console.log('[switchMode] 杀死 claude 进程失败:', e.message);
|
|
293
313
|
}
|
|
@@ -295,7 +315,7 @@ async function switchMode(newMode) {
|
|
|
295
315
|
} else if (currentMode === 'opencode' && opencodeProcess) {
|
|
296
316
|
try {
|
|
297
317
|
console.log(`[switchMode] 杀死 opencode 进程 PID: ${opencodeProcess.pid}`);
|
|
298
|
-
opencodeProcess
|
|
318
|
+
killProcessTree(opencodeProcess);
|
|
299
319
|
} catch (e) {
|
|
300
320
|
console.log('[switchMode] 杀死 opencode 进程失败:', e.message);
|
|
301
321
|
}
|
|
@@ -546,7 +566,7 @@ const requestHandler = async (req, res) => {
|
|
|
546
566
|
const changes = stdout.split('\n').filter(Boolean).map(line => ({
|
|
547
567
|
status: line.substring(0, 2).trim(),
|
|
548
568
|
file: line.substring(3),
|
|
549
|
-
})).filter(c => !/^core
|
|
569
|
+
})).filter(c => !/^core-/.test(c.file));
|
|
550
570
|
res.end(JSON.stringify({ changes }));
|
|
551
571
|
} catch (err) {
|
|
552
572
|
res.end(JSON.stringify({ changes: [], error: err.message }));
|
|
@@ -701,7 +721,7 @@ wssInst.on('connection', (ws, req) => {
|
|
|
701
721
|
const sid = currentSessionId;
|
|
702
722
|
try {
|
|
703
723
|
if (opencodeProcess) {
|
|
704
|
-
opencodeProcess
|
|
724
|
+
killProcessTree(opencodeProcess);
|
|
705
725
|
opencodeProcess = null;
|
|
706
726
|
currentProcess = null;
|
|
707
727
|
}
|
|
@@ -797,7 +817,7 @@ wssInst.on('connection', (ws, req) => {
|
|
|
797
817
|
if (opencodeProcess) {
|
|
798
818
|
try {
|
|
799
819
|
console.log(`[restore] 杀死当前进程 PID: ${opencodeProcess.pid}`);
|
|
800
|
-
opencodeProcess
|
|
820
|
+
killProcessTree(opencodeProcess);
|
|
801
821
|
} catch (e) {
|
|
802
822
|
console.log('[restore] 杀死进程失败:', e.message);
|
|
803
823
|
}
|
|
@@ -843,11 +863,11 @@ wssInst.on('connection', (ws, req) => {
|
|
|
843
863
|
currentSessionId = null; // 立即清除旧会话 ID
|
|
844
864
|
|
|
845
865
|
if (mode === 'opencode' && opencodeProcess) {
|
|
846
|
-
try { opencodeProcess
|
|
866
|
+
try { killProcessTree(opencodeProcess); } catch {}
|
|
847
867
|
opencodeProcess = null;
|
|
848
868
|
currentProcess = null;
|
|
849
869
|
} else if (mode === 'claude' && claudeProcess) {
|
|
850
|
-
try { claudeProcess
|
|
870
|
+
try { killProcessTree(claudeProcess); } catch {}
|
|
851
871
|
claudeProcess = null;
|
|
852
872
|
currentProcess = null;
|
|
853
873
|
}
|
|
@@ -920,8 +940,13 @@ wssInst.on('connection', (ws, req) => {
|
|
|
920
940
|
|
|
921
941
|
createServerAndWss();
|
|
922
942
|
|
|
923
|
-
|
|
924
|
-
|
|
943
|
+
function cleanupAndExit() {
|
|
944
|
+
if (claudeProcess) killProcessTree(claudeProcess);
|
|
945
|
+
if (opencodeProcess) killProcessTree(opencodeProcess);
|
|
946
|
+
setTimeout(() => process.exit(0), 500);
|
|
947
|
+
}
|
|
948
|
+
process.on('SIGINT', cleanupAndExit);
|
|
949
|
+
process.on('SIGTERM', cleanupAndExit);
|
|
925
950
|
|
|
926
951
|
// 端口范围,用于端口冲突重试
|
|
927
952
|
const PORT_MIN = IS_PC ? 19200 : 7008;
|