cc-viewer 1.9.24 → 1.9.26
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/README.md +1 -1
- package/cli.js +14 -0
- package/dist/assets/App-CjP88gbM.css +1 -0
- package/dist/assets/App-CkbwkH74.js +2 -0
- package/dist/assets/ArchivePreview-1XAr8LvB.js +1 -0
- package/dist/assets/AudioPreview-7zCADwCz.css +1 -0
- package/dist/assets/AudioPreview-DGcbrJjl.js +1 -0
- package/dist/assets/{MdxEditorPanel-CT6w8hjl.js → MdxEditorPanel-DFGSL5OM.js} +1 -1
- package/dist/assets/Mobile-DFu8Kn5W.js +1 -0
- package/dist/assets/ProxyStatsModal-BU9liIIO.js +1 -0
- package/dist/assets/SubtitlePreview-BGW9y2LI.css +1 -0
- package/dist/assets/SubtitlePreview-Ca_dpMFL.js +1 -0
- package/dist/assets/{_baseUniq-BGBEhBne.js → _baseUniq-9PjtCZvX.js} +1 -1
- package/dist/assets/{arc-4pbWOEmh.js → arc-C7i0W-3s.js} +1 -1
- package/dist/assets/{architectureDiagram-Q4EWVU46-BHZPDnby.js → architectureDiagram-Q4EWVU46-B0-9CMiF.js} +1 -1
- package/dist/assets/{blockDiagram-DXYQGD6D-DszLU7Pg.js → blockDiagram-DXYQGD6D-v3Zg9ooQ.js} +1 -1
- package/dist/assets/{c4Diagram-AHTNJAMY-DbDJNYxl.js → c4Diagram-AHTNJAMY-BngN_7qF.js} +1 -1
- package/dist/assets/{channel-BpIsxDHj.js → channel-IbZhDvnM.js} +1 -1
- package/dist/assets/{chunk-4BX2VUAB-ChcBwBh2.js → chunk-4BX2VUAB-8cHviTVA.js} +1 -1
- package/dist/assets/{chunk-4TB4RGXK-DzBEAck_.js → chunk-4TB4RGXK-C3CP4doN.js} +1 -1
- package/dist/assets/{chunk-55IACEB6-9UDvmw07.js → chunk-55IACEB6-FUVA-xfN.js} +1 -1
- package/dist/assets/{chunk-EDXVE4YY-DHEU2DKg.js → chunk-EDXVE4YY-BL4ddY7-.js} +1 -1
- package/dist/assets/{chunk-FMBD7UC4-sysT0Sy2.js → chunk-FMBD7UC4-fgqPq6Tx.js} +1 -1
- package/dist/assets/{chunk-OYMX7WX6-DLXt2vYo.js → chunk-OYMX7WX6-BGnPcd9h.js} +1 -1
- package/dist/assets/{chunk-QZHKN3VN-CDIkC7QK.js → chunk-QZHKN3VN-Cs6WjmqO.js} +1 -1
- package/dist/assets/{chunk-YZCP3GAM-D9b_INz7.js → chunk-YZCP3GAM-qq4Q4j7H.js} +1 -1
- package/dist/assets/classDiagram-6PBFFD2Q-Bszndikj.js +1 -0
- package/dist/assets/classDiagram-v2-HSJHXN6E-Bszndikj.js +1 -0
- package/dist/assets/clone-MC_fW61A.js +1 -0
- package/dist/assets/{cose-bilkent-S5V4N54A-DJQwV_Dp.js → cose-bilkent-S5V4N54A-D-uK3RSk.js} +1 -1
- package/dist/assets/{dagre-KV5264BT-bl9Pq21t.js → dagre-KV5264BT-BulmeCnQ.js} +1 -1
- package/dist/assets/{diagram-5BDNPKRD-BA8CJxzI.js → diagram-5BDNPKRD-DI7Q04yx.js} +1 -1
- package/dist/assets/{diagram-G4DWMVQ6-DzSQULuz.js → diagram-G4DWMVQ6-B7zYIZac.js} +1 -1
- package/dist/assets/{diagram-MMDJMWI5-DhfHWnT4.js → diagram-MMDJMWI5-D_f5k-GJ.js} +1 -1
- package/dist/assets/{diagram-TYMM5635-BbAoFfGS.js → diagram-TYMM5635-DQ-vW7nJ.js} +1 -1
- package/dist/assets/{erDiagram-SMLLAGMA-CMjA2eBk.js → erDiagram-SMLLAGMA-BgubHrDi.js} +1 -1
- package/dist/assets/{flowDiagram-DWJPFMVM-bOubqgJ6.js → flowDiagram-DWJPFMVM-fPYA9wmX.js} +1 -1
- package/dist/assets/{ganttDiagram-T4ZO3ILL-BUIu7WwI.js → ganttDiagram-T4ZO3ILL-hNsatnIF.js} +1 -1
- package/dist/assets/{gitGraphDiagram-UUTBAWPF-B_vrztDU.js → gitGraphDiagram-UUTBAWPF-1GijxkLh.js} +1 -1
- package/dist/assets/{graph-BR3YGx52.js → graph-sNq_HPra.js} +1 -1
- package/dist/assets/{index-BMpUfdYI.js → index-BnWh6jkG.js} +1 -1
- package/dist/assets/{index-DtZAmvwJ.js → index-CmwhODrM.js} +1 -1
- package/dist/assets/{index-B88yR2TU.js → index-D6mBgqj7.js} +1 -1
- package/dist/assets/{index-mvm_Pxcf.js → index-DggrqRzx.js} +1 -1
- package/dist/assets/{index-BQx5MOpr.js → index-DiVw76Ih.js} +1 -1
- package/dist/assets/index-Dn7twftJ.js +2 -0
- package/dist/assets/{index-DwMyfQJq.js → index-ijWns1Ex.js} +1 -1
- package/dist/assets/{index-ClTuiPoz.js → index-ng96S3Hy.js} +1 -1
- package/dist/assets/{infoDiagram-42DDH7IO-Co9Db2ir.js → infoDiagram-42DDH7IO-C9HYi6HU.js} +1 -1
- package/dist/assets/{ishikawaDiagram-UXIWVN3A-4z7EydCd.js → ishikawaDiagram-UXIWVN3A-D3Ae6xRc.js} +1 -1
- package/dist/assets/{journeyDiagram-VCZTEJTY-CtLfbhYE.js → journeyDiagram-VCZTEJTY-BMPDBa6W.js} +1 -1
- package/dist/assets/{jszip.min-DtbrAiWv.js → jszip.min-D6JfNfcl.js} +1 -1
- package/dist/assets/{kanban-definition-6JOO6SKY-9ZrhOvdX.js → kanban-definition-6JOO6SKY-BXEtzhr-.js} +1 -1
- package/dist/assets/{layout-Ddo06NJO.js → layout-CbMMhBh2.js} +1 -1
- package/dist/assets/{linear-BZUsBSwS.js → linear-DivVFiS7.js} +1 -1
- package/dist/assets/{mermaid.core-O-x0KuTp.js → mermaid.core-Dq-d8oPN.js} +2 -2
- package/dist/assets/{min-PzJh19JL.js → min-CXI1r_lz.js} +1 -1
- package/dist/assets/{mindmap-definition-QFDTVHPH-C3MVo-7p.js → mindmap-definition-QFDTVHPH-CONBMUxc.js} +1 -1
- package/dist/assets/{pieDiagram-DEJITSTG-CMn9-kQc.js → pieDiagram-DEJITSTG-C0rsPXdi.js} +1 -1
- package/dist/assets/{quadrantDiagram-34T5L4WZ-9eyqTdkj.js → quadrantDiagram-34T5L4WZ-DA2PNu4u.js} +1 -1
- package/dist/assets/{requirementDiagram-MS252O5E-BJbuDOpR.js → requirementDiagram-MS252O5E-DjsBvm40.js} +1 -1
- package/dist/assets/{sankeyDiagram-XADWPNL6-CzQ1KxD3.js → sankeyDiagram-XADWPNL6-Drl_Kmzt.js} +1 -1
- package/dist/assets/{seqResourceLoaders-DH-Nl0yh.css → seqResourceLoaders-CjAnOisT.css} +1 -1
- package/dist/assets/seqResourceLoaders-L-Fzax-z.js +2 -0
- package/dist/assets/{sequenceDiagram-FGHM5R23-CfmSEAYp.js → sequenceDiagram-FGHM5R23-Dcz5NXKY.js} +1 -1
- package/dist/assets/{stateDiagram-FHFEXIEX-Brw2ZXQC.js → stateDiagram-FHFEXIEX-7P3czdgX.js} +1 -1
- package/dist/assets/{stateDiagram-v2-QKLJ7IA2-Dnyo23Rp.js → stateDiagram-v2-QKLJ7IA2-C3xgfAOE.js} +1 -1
- package/dist/assets/{timeline-definition-GMOUNBTQ-DNi7GnlG.js → timeline-definition-GMOUNBTQ-BVe-eF-9.js} +1 -1
- package/dist/assets/util-DUb-88OI.js +1 -0
- package/dist/assets/{vendor-antd-DWLgSkPo.js → vendor-antd-VJVAjRBJ.js} +1 -1
- package/dist/assets/{vendor-codemirror-CKsm_iG4.js → vendor-codemirror-D2yaEhu3.js} +1 -1
- package/dist/assets/{vendor-mdxeditor-Dah6NK0y.js → vendor-mdxeditor-DKI8QSRd.js} +2 -2
- package/dist/assets/{vendor-qrcode-CDcb8weP.js → vendor-qrcode-CDB9Y_Vp.js} +1 -1
- package/dist/assets/{vendor-virtuoso-DKUobZpA.js → vendor-virtuoso-DEFa9UCG.js} +1 -1
- package/dist/assets/{vennDiagram-DHZGUBPP-Cdkdx7gB.js → vennDiagram-DHZGUBPP-C8KL2OR8.js} +1 -1
- package/dist/assets/{wardley-RL74JXVD-YKzsVN4U.js → wardley-RL74JXVD-Dm4mxyoW.js} +1 -1
- package/dist/assets/{wardleyDiagram-NUSXRM2D-gBsb6aut.js → wardleyDiagram-NUSXRM2D-BoA34gDh.js} +1 -1
- package/dist/assets/{xychartDiagram-5P7HB3ND-Bh63NWof.js → xychartDiagram-5P7HB3ND-66ynIBzj.js} +1 -1
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/server/lib/approval-policy.js +5 -2
- package/server/lib/ask/perm-bridge.js +4 -0
- package/server/lib/ask/perm-request-bridge.js +1 -1
- package/server/lib/audio-stream.js +267 -0
- package/server/lib/auto-approve.js +26 -5
- package/server/lib/restart-helper.js +65 -0
- package/server/lib/restart.js +83 -0
- package/server/lib/sdk-manager.js +19 -10
- package/server/lib/terminal-ws-ping.js +42 -0
- package/server/lib/update-instances.js +42 -0
- package/server/lib/update-job.js +260 -0
- package/server/lib/updater.js +37 -220
- package/server/proxy.js +16 -9
- package/server/pty-manager.js +1 -0
- package/server/routes/ask-perm.js +17 -13
- package/server/routes/files-content.js +65 -0
- package/server/routes/project-meta.js +11 -7
- package/server/routes/update.js +58 -0
- package/server/server.js +67 -11
- package/dist/assets/App-BwRRqrP5.css +0 -1
- package/dist/assets/App-Cfmm41z0.js +0 -2
- package/dist/assets/ArchivePreview-dKWXN9Zp.js +0 -1
- package/dist/assets/Mobile-noWViQpL.js +0 -1
- package/dist/assets/ProxyStatsModal-BeCRPqaC.js +0 -1
- package/dist/assets/classDiagram-6PBFFD2Q-4Lh0SB4X.js +0 -1
- package/dist/assets/classDiagram-v2-HSJHXN6E-4Lh0SB4X.js +0 -1
- package/dist/assets/clone-cWiXtXrO.js +0 -1
- package/dist/assets/index-Ca3a2tOc.js +0 -2
- package/dist/assets/seqResourceLoaders-DeqzMajS.js +0 -2
package/server/proxy.js
CHANGED
|
@@ -333,7 +333,11 @@ async function handleLlmApiRequest(req, res, fullUrl, fetchOptions, body, proxyD
|
|
|
333
333
|
// maxRetryDurationMs. res 'close' before the response is finished means the
|
|
334
334
|
// client is gone → abort every in-flight/queued attempt via the engine.
|
|
335
335
|
const clientAbort = new AbortController();
|
|
336
|
+
let settleSlowUpstream = () => {};
|
|
336
337
|
res.on('close', () => {
|
|
338
|
+
// close also follows an error response ended by the outer catch. Always settle
|
|
339
|
+
// the advisory; only an unfinished response needs to abort upstream work.
|
|
340
|
+
settleSlowUpstream();
|
|
337
341
|
if (!res.writableEnded) {
|
|
338
342
|
try { clientAbort.abort(); } catch { /* best effort */ }
|
|
339
343
|
}
|
|
@@ -375,7 +379,16 @@ async function handleLlmApiRequest(req, res, fullUrl, fetchOptions, body, proxyD
|
|
|
375
379
|
if (slowTimer.unref) slowTimer.unref();
|
|
376
380
|
}
|
|
377
381
|
const clearSlowTimer = () => { if (slowTimer) { clearTimeout(slowTimer); slowTimer = null; } };
|
|
378
|
-
|
|
382
|
+
let slowResolved = false;
|
|
383
|
+
settleSlowUpstream = () => {
|
|
384
|
+
if (slowResolved) return;
|
|
385
|
+
slowResolved = true;
|
|
386
|
+
clearSlowTimer();
|
|
387
|
+
if (slowFired) {
|
|
388
|
+
__testing.emit({ type: 'resolved', requestId: slowReqId, cwd: slowCwd, instanceKey: slowInstance });
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
clientAbort.signal.addEventListener('abort', settleSlowUpstream, { once: true });
|
|
379
392
|
// The timer measures time-to-HEADERS (fetch resolves at headers). Keep it armed
|
|
380
393
|
// until the first BODY chunk so a headers-fast-then-stalled stream still counts
|
|
381
394
|
// as slow (review P1-2). markFirstByte is the real settle point: it disarms the
|
|
@@ -385,10 +398,7 @@ async function handleLlmApiRequest(req, res, fullUrl, fetchOptions, body, proxyD
|
|
|
385
398
|
const markFirstByte = () => {
|
|
386
399
|
if (slowFirstByteSeen) return;
|
|
387
400
|
slowFirstByteSeen = true;
|
|
388
|
-
|
|
389
|
-
if (slowFired) {
|
|
390
|
-
__testing.emit({ type: 'resolved', requestId: slowReqId, cwd: slowCwd, instanceKey: slowInstance });
|
|
391
|
-
}
|
|
401
|
+
settleSlowUpstream();
|
|
392
402
|
};
|
|
393
403
|
|
|
394
404
|
// 执行带重试的请求
|
|
@@ -414,10 +424,7 @@ async function handleLlmApiRequest(req, res, fullUrl, fetchOptions, body, proxyD
|
|
|
414
424
|
// (markFirstByte). Clear+resolve only when no usable response came back
|
|
415
425
|
// (network error / aborted / no response object) so the advisory never leaks.
|
|
416
426
|
if (slowFirstByteSeen || !result || !result.response) {
|
|
417
|
-
|
|
418
|
-
if (slowFired) {
|
|
419
|
-
__testing.emit({ type: 'resolved', requestId: slowReqId, cwd: slowCwd, instanceKey: slowInstance });
|
|
420
|
-
}
|
|
427
|
+
settleSlowUpstream();
|
|
421
428
|
}
|
|
422
429
|
}
|
|
423
430
|
|
package/server/pty-manager.js
CHANGED
|
@@ -445,6 +445,7 @@ async function _spawnClaudeImpl(key, proxyPort, cwd, extraArgs = [], claudePath
|
|
|
445
445
|
// process (im-process-manager already strips the same for IM workers).
|
|
446
446
|
delete env.CCV_WORKSPACE_MODE;
|
|
447
447
|
delete env.CCV_ELECTRON_MULTITAB;
|
|
448
|
+
delete env.CCV_ELECTRON_TAB;
|
|
448
449
|
// Claude Code's NO_FLICKER makes the embedded xterm use the alt screen and lose
|
|
449
450
|
// scrollback. cc-viewer strips the inherited value by default; set
|
|
450
451
|
// CCV_KEEP_CLAUDE_CODE_NO_FLICKER=1 explicitly when it is actually needed.
|
|
@@ -7,7 +7,7 @@ import { _projectName } from '../interceptor.js';
|
|
|
7
7
|
import { readPrefsRaw } from '../lib/prefs-store.js';
|
|
8
8
|
import { getCurrentProjectKey, hasFork, resolveScoped } from '../lib/project-prefs.js';
|
|
9
9
|
import { reportSwallowed } from '../lib/error-report.js';
|
|
10
|
-
import { computeAutoApprove, createAutoApproveState } from '../lib/auto-approve.js';
|
|
10
|
+
import { computeAutoApprove, createAutoApproveState, isAutoApproveEnabledValue, AUTO_APPROVE_FULL } from '../lib/auto-approve.js';
|
|
11
11
|
import { isPublishCommand } from '../lib/approval-policy.js';
|
|
12
12
|
import { computeAskAutoAnswer, createAskAutoAnswerState, pickAutoAnswers, replayAskAutoAnswerFields } from '../lib/ask-auto-answer.js';
|
|
13
13
|
|
|
@@ -537,11 +537,14 @@ function permHook(req, res, parsedUrl, isLocal, deps) {
|
|
|
537
537
|
// itself at deadline + 1s buffer when no client did. autoCancelled is set by
|
|
538
538
|
// the perm-hook-auto-cancel WS handler (the approval then stays pending for
|
|
539
539
|
// a manual decision) and replayed to fresh clients.
|
|
540
|
-
// npm publish is a hard safety floor:
|
|
541
|
-
// the
|
|
542
|
-
|
|
540
|
+
// npm publish is a hard safety floor: a human decision is required at every
|
|
541
|
+
// tier EXCEPT the explicit full auto-approve (-2, 完全免审批), which opts
|
|
542
|
+
// into letting high-risk commands through (intended for isolated
|
|
543
|
+
// containers). SDK path parity: sdk-manager.js.
|
|
544
|
+
const computedAuto = computeAutoApprove('perm', typeof cwd === 'string' && cwd ? cwd : undefined, { file: deps.getPrefsFile?.() });
|
|
545
|
+
const autoMeta = (isPublishCommand(toolName, input) && computedAuto.seconds !== AUTO_APPROVE_FULL)
|
|
543
546
|
? { enabled: false }
|
|
544
|
-
:
|
|
547
|
+
: computedAuto;
|
|
545
548
|
|
|
546
549
|
const hookEntry = {
|
|
547
550
|
toolName, input, res, timer, createdAt: Date.now(),
|
|
@@ -566,7 +569,7 @@ function permHook(req, res, parsedUrl, isLocal, deps) {
|
|
|
566
569
|
});
|
|
567
570
|
}
|
|
568
571
|
|
|
569
|
-
// Arm AFTER the entry is in the map AND the pending frame is out: instant (-1)
|
|
572
|
+
// Arm AFTER the entry is in the map AND the pending frame is out: instant (-1/-2)
|
|
570
573
|
// fires synchronously and resolves through the entry, so clients observe the
|
|
571
574
|
// order pending → resolved (never a ghost panel for an already-answered hook).
|
|
572
575
|
if (autoMeta.enabled) {
|
|
@@ -674,13 +677,14 @@ function permRequestHook(req, res, parsedUrl, isLocal, deps) {
|
|
|
674
677
|
const effective = scoped ? resolveScoped(prefs, prefs.prefsByProject[projectKey]) : prefs;
|
|
675
678
|
const autoApproveSeconds = Number(effective.autoApproveSeconds);
|
|
676
679
|
|
|
677
|
-
// autoApproveSeconds: 0 = off/manual, >0 = countdown, -1 = instant
|
|
678
|
-
// For PermissionRequest the prompt is already imminent;
|
|
679
|
-
// when the user has explicitly enabled auto-approval.
|
|
680
|
-
// countdown (>0) are treated as allow here
|
|
681
|
-
// opted into automatic approval; the countdown
|
|
682
|
-
// delay in the UI, which is irrelevant for a
|
|
683
|
-
|
|
680
|
+
// autoApproveSeconds: 0 = off/manual, >0 = countdown, -1 = instant, -2 =
|
|
681
|
+
// full auto-approve. For PermissionRequest the prompt is already imminent;
|
|
682
|
+
// we only suppress it when the user has explicitly enabled auto-approval.
|
|
683
|
+
// Both instant tiers (-1/-2) and countdown (>0) are treated as allow here
|
|
684
|
+
// because the user has already opted into automatic approval; the countdown
|
|
685
|
+
// variant simply adds a visible delay in the UI, which is irrelevant for a
|
|
686
|
+
// headless hook.
|
|
687
|
+
const shouldAutoAllow = isAutoApproveEnabledValue(autoApproveSeconds);
|
|
684
688
|
|
|
685
689
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
686
690
|
res.end(JSON.stringify({ decision: shouldAutoAllow ? 'allow' : 'ask' }));
|
|
@@ -10,6 +10,7 @@ import { loadWorkspaces } from '../workspace-registry.js';
|
|
|
10
10
|
import { listLivePtys } from '../pty-manager.js';
|
|
11
11
|
import { reportSwallowed } from '../lib/error-report.js';
|
|
12
12
|
import { isBinaryBuffer, getUtf16Encoding } from '../lib/binary-sniff.js';
|
|
13
|
+
import { AUDIO_EXTENSIONS, audioExtOf, serveAudioStream } from '../lib/audio-stream.js';
|
|
13
14
|
import { discoverClaudeMdCandidates, readCandidateById } from '../lib/claude-md-discovery.js';
|
|
14
15
|
import { getClaudeConfigDir } from '../../findcc.js';
|
|
15
16
|
import { _projectName } from '../interceptor.js';
|
|
@@ -47,6 +48,8 @@ const FILE_RAW_MIME = {
|
|
|
47
48
|
'.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg',
|
|
48
49
|
'.gif': 'image/gif', '.svg': 'image/svg+xml', '.ico': 'image/x-icon',
|
|
49
50
|
'.webp': 'image/webp', '.bmp': 'image/bmp', '.avif': 'image/avif',
|
|
51
|
+
'.apng': 'image/apng', '.jfif': 'image/jpeg',
|
|
52
|
+
'.tif': 'image/tiff', '.tiff': 'image/tiff', '.heic': 'image/heic', '.heif': 'image/heif',
|
|
50
53
|
'.html': 'text/html', '.htm': 'text/html',
|
|
51
54
|
'.css': 'text/css', '.js': 'text/javascript', '.mjs': 'text/javascript',
|
|
52
55
|
'.json': 'application/json', '.map': 'application/json', '.txt': 'text/plain',
|
|
@@ -871,6 +874,67 @@ function targetFiles(req, res, parsedUrl, isLocal, deps) {
|
|
|
871
874
|
}
|
|
872
875
|
}
|
|
873
876
|
|
|
877
|
+
// Audio preview endpoint: streams audio with single-range 206/416/304 support so
|
|
878
|
+
// browsers (esp. Safari, which probes with Range: bytes=0-1) can seek. Unlike fileRaw
|
|
879
|
+
// it never buffers the whole file (multi-GB audio), and unlike fileDownload it serves
|
|
880
|
+
// inline with a real audio/* MIME. Shares the same permission/path contract as fileDownload.
|
|
881
|
+
function audioStream(req, res, parsedUrl) {
|
|
882
|
+
try {
|
|
883
|
+
const reqPath = parsedUrl.searchParams.get('path');
|
|
884
|
+
if (!reqPath) {
|
|
885
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
886
|
+
res.end(JSON.stringify({ error: 'Invalid path' }));
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
// Same path contract as fileDownloadWithRoot: relative paths with .. are rejected.
|
|
890
|
+
const isAbs = /^([a-zA-Z]:[\\/]|[\\/])/.test(reqPath);
|
|
891
|
+
if (!isAbs && reqPath.includes('..')) {
|
|
892
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
893
|
+
res.end(JSON.stringify({ error: 'Invalid path' }));
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
const cwd = _viewRootOrReply(req, res, parsedUrl);
|
|
897
|
+
if (!cwd) return;
|
|
898
|
+
const absPath = isAbs ? reqPath : resolve(cwd, reqPath);
|
|
899
|
+
const policy = isReadAllowed(absPath);
|
|
900
|
+
if (!policy.ok) {
|
|
901
|
+
const status = reasonToStatus(policy.reason);
|
|
902
|
+
const errLabel = status === 404 ? 'File not found'
|
|
903
|
+
: status === 400 ? 'Invalid path'
|
|
904
|
+
: 'Forbidden';
|
|
905
|
+
const body = { error: errLabel, reason: policy.reason };
|
|
906
|
+
if (policy.allowedRoots) body.allowedRoots = policy.allowedRoots;
|
|
907
|
+
res.writeHead(status, { 'Content-Type': 'application/json' });
|
|
908
|
+
res.end(JSON.stringify(body));
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
const targetFile = policy.real;
|
|
912
|
+
const stat = statSync(targetFile);
|
|
913
|
+
if (!stat.isFile()) {
|
|
914
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
915
|
+
res.end(JSON.stringify({ error: 'Not a file' }));
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
// Extension is derived from the real path (not the caller's name) so case and
|
|
919
|
+
// symlink-renamed files classify consistently; reject non-audio before sniffing.
|
|
920
|
+
const ext = audioExtOf(targetFile);
|
|
921
|
+
if (!AUDIO_EXTENSIONS.has(ext)) {
|
|
922
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
923
|
+
res.end(JSON.stringify({ error: 'Unsupported audio path' }));
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
serveAudioStream(req, res, { filePath: targetFile, stat, ext });
|
|
927
|
+
} catch (err) {
|
|
928
|
+
// A throw here (EACCES stat race, null-byte path, sniff read error) must not
|
|
929
|
+
// become an unhandled rejection that kills the process (server.js:985).
|
|
930
|
+
if (res.headersSent) { reportSwallowed('audioStream.headersSent', err); res.destroy(); return; }
|
|
931
|
+
const status = ERROR_STATUS_MAP[err.code] || 500;
|
|
932
|
+
const message = status === 500 ? `Cannot read file: ${err.message}` : err.message;
|
|
933
|
+
res.writeHead(status, { 'Content-Type': 'application/json' });
|
|
934
|
+
res.end(JSON.stringify({ error: message }));
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
|
|
874
938
|
export const filesContentRoutes = [
|
|
875
939
|
{ method: 'GET', match: 'exact', path: '/api/plan-file', handler: planFile },
|
|
876
940
|
{ method: 'GET', match: 'exact', path: '/api/file-content', handler: fileContentGet },
|
|
@@ -879,6 +943,7 @@ export const filesContentRoutes = [
|
|
|
879
943
|
{ predicate: (url, method) => (url === '/api/file-raw' || url.startsWith('/api/file-raw/')) && (method === 'GET' || method === 'HEAD'), handler: fileRaw },
|
|
880
944
|
{ predicate: (url, method) => url === '/api/archive-raw' && (method === 'GET' || method === 'HEAD'), handler: archiveRaw },
|
|
881
945
|
{ predicate: (url, method) => url === '/api/download-file' && (method === 'GET' || method === 'HEAD'), handler: fileDownload },
|
|
946
|
+
{ predicate: (url, method) => url === '/api/audio-stream' && (method === 'GET' || method === 'HEAD'), handler: audioStream },
|
|
882
947
|
{ method: 'POST', match: 'exact', path: '/api/file-content', handler: fileContentPost },
|
|
883
948
|
{ method: 'GET', match: 'exact', path: '/api/target-files', handler: targetFiles },
|
|
884
949
|
];
|
|
@@ -8,7 +8,7 @@ import { sanitizePathComponent } from '../lib/v2/layout.js';
|
|
|
8
8
|
import { resolveViewRoot } from '../lib/view-root.js';
|
|
9
9
|
import { loadWorkspaces } from '../workspace-registry.js';
|
|
10
10
|
import { listLivePtys } from '../pty-manager.js';
|
|
11
|
-
import { detectHomebrewInstall } from '../lib/updater.js';
|
|
11
|
+
import { detectHomebrewInstall, detectPnpmGlobalInstall } from '../lib/updater.js';
|
|
12
12
|
|
|
13
13
|
// Multi-project (2026-10, review P2-6): stats reads for a VIEWED project must
|
|
14
14
|
// not become a presence oracle over LOG_DIR — `?project=` is accepted ONLY
|
|
@@ -43,12 +43,13 @@ function _resolveStatsName(projectParam, instanceParam, res) {
|
|
|
43
43
|
// deps 仅供单测注入;失败安全:detect 抛异常时回落到 npm(不会误导 brew 用户走 npm)。
|
|
44
44
|
export function getInstallMethod({
|
|
45
45
|
electron = process.versions && process.versions.electron,
|
|
46
|
+
electronTab = process.env.CCV_ELECTRON_TAB === '1',
|
|
46
47
|
detect = detectHomebrewInstall,
|
|
48
|
+
detectPnpm = detectPnpmGlobalInstall,
|
|
47
49
|
} = {}) {
|
|
48
|
-
if (electron) return 'electron';
|
|
49
|
-
try {
|
|
50
|
-
|
|
51
|
-
} catch { /* 探测失败 → 回落 npm */ }
|
|
50
|
+
if (electron || electronTab) return 'electron';
|
|
51
|
+
try { if (detect()) return 'brew'; } catch { }
|
|
52
|
+
try { if (detectPnpm()) return 'pnpm'; } catch { }
|
|
52
53
|
return 'npm';
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -63,11 +64,14 @@ function projectDir(req, res) {
|
|
|
63
64
|
res.end(JSON.stringify({ dir }));
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
const PROCESS_STARTED_AT = Date.now();
|
|
68
|
+
const PROCESS_ID = `${process.pid}-${PROCESS_STARTED_AT}`;
|
|
69
|
+
|
|
70
|
+
function versionInfo(req, res, parsedUrl, isLocal, deps) {
|
|
67
71
|
try {
|
|
68
72
|
const pkg = JSON.parse(readFileSync(PACKAGE_JSON, 'utf-8'));
|
|
69
73
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
70
|
-
res.end(JSON.stringify({ version: pkg.version, installMethod: getInstallMethod() }));
|
|
74
|
+
res.end(JSON.stringify({ version: pkg.version, installMethod: getInstallMethod(), processId: PROCESS_ID, canRestart: deps?.canRestartProcess === true, instanceKind: process.env.CCV_IM_PLATFORM ? 'im' : (process.env.CCV_WORKSPACE_MODE ? 'workspace' : 'normal'), instancePort: deps?.actualPort || null }));
|
|
71
75
|
} catch {
|
|
72
76
|
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
73
77
|
res.end(JSON.stringify({ error: 'Failed to read version' }));
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isAdminReq } from '../lib/is-admin.js';
|
|
2
|
+
import { isSameOriginBrowserRequest } from '../lib/same-origin.js';
|
|
3
|
+
import { reportSwallowed } from '../lib/error-report.js';
|
|
4
|
+
|
|
5
|
+
function json(res, status, value) {
|
|
6
|
+
res.writeHead(status, { 'Content-Type': 'application/json' });
|
|
7
|
+
res.end(JSON.stringify(value));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function allowed(req, res, parsedUrl, isLocal) {
|
|
11
|
+
if (isAdminReq(req, isLocal) && isSameOriginBrowserRequest(req, parsedUrl)) return true;
|
|
12
|
+
json(res, 403, { error: 'Forbidden: admin and same-origin required' });
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function status(req, res, parsedUrl, isLocal, deps) {
|
|
17
|
+
if (!allowed(req, res, parsedUrl, isLocal)) return;
|
|
18
|
+
json(res, 200, deps.updateJob.getState());
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function check(req, res, parsedUrl, isLocal, deps) {
|
|
22
|
+
if (!allowed(req, res, parsedUrl, isLocal)) return;
|
|
23
|
+
const state = await deps.updateJob.check();
|
|
24
|
+
json(res, state.status === 'error' ? 502 : 200, state);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function start(req, res, parsedUrl, isLocal, deps) {
|
|
28
|
+
if (!allowed(req, res, parsedUrl, isLocal)) return;
|
|
29
|
+
if (deps.isRuntimeStopping) { json(res, 409, { error: 'Server is stopping' }); return; }
|
|
30
|
+
if (!deps.canRestartProcess && deps.updateJob.getState().status !== 'restart_required') {
|
|
31
|
+
json(res, 409, { error: 'Restart is unavailable for this launch mode' });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (['checking', 'downloading', 'installing', 'restarting', 'restart_required'].includes(deps.updateJob.getState().status)) {
|
|
35
|
+
json(res, 200, deps.updateJob.getState());
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
deps.updateJob.start().catch((err) => reportSwallowed('update.start', err));
|
|
39
|
+
json(res, 202, deps.updateJob.getState());
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function restart(req, res, parsedUrl, isLocal, deps) {
|
|
43
|
+
if (!allowed(req, res, parsedUrl, isLocal)) return;
|
|
44
|
+
if (deps.isRuntimeStopping) { json(res, 409, { error: 'Server is stopping', code: 'stopping' }); return; }
|
|
45
|
+
if (!['restart_required', 'restarting'].includes(deps.updateJob.getState().status)) { json(res, 409, { error: 'No verified update is ready', code: 'not_ready' }); return; }
|
|
46
|
+
if (!deps.canRestartProcess) { json(res, 409, { error: 'Restart is unavailable for this launch mode' }); return; }
|
|
47
|
+
try {
|
|
48
|
+
await deps.updateJob.restart(deps.restartProcess);
|
|
49
|
+
if (!res.writableEnded) json(res, 200, { ok: true, status: 'restarting' });
|
|
50
|
+
} catch (err) { reportSwallowed('update.restart', err); if (!res.writableEnded) json(res, 500, { error: err.message }); }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const updateRoutes = [
|
|
54
|
+
{ method: 'GET', match: 'exact', path: '/api/update/status', handler: status },
|
|
55
|
+
{ method: 'POST', match: 'exact', path: '/api/update/check', handler: check },
|
|
56
|
+
{ method: 'POST', match: 'exact', path: '/api/update/start', handler: start },
|
|
57
|
+
{ method: 'POST', match: 'exact', path: '/api/update/restart', handler: restart },
|
|
58
|
+
];
|
package/server/server.js
CHANGED
|
@@ -10,6 +10,7 @@ import { promisify } from 'node:util';
|
|
|
10
10
|
import { Worker } from 'node:worker_threads';
|
|
11
11
|
import { isPathContained } from './lib/file-api.js';
|
|
12
12
|
import { sseWrite, isWireV3Enabled } from './lib/wire-compress.js';
|
|
13
|
+
import { attachTerminalWsPing } from './lib/terminal-ws-ping.js';
|
|
13
14
|
import { setEntry as askStoreSetEntry, deleteEntry as askStoreDeleteEntry, pruneStale as askStorePruneStale, markAnswered as askStoreMarkAnswered, markCancelled as askStoreMarkCancelled, loadAskStore as askStoreLoad } from './lib/ask/ask-store.js';
|
|
14
15
|
import { ASK_TIMEOUT_MS, ASK_WAITER_REAP_INTERVAL_MS, ASK_WAITER_LIVENESS_MS } from './lib/ask/ask-constants.js';
|
|
15
16
|
import { reapDeadAskWaiters, sweepOrphanedDiskAsks } from './lib/ask/ask-reaper.js';
|
|
@@ -47,6 +48,8 @@ import { resumeRoutes } from './routes/resume.js';
|
|
|
47
48
|
import { sdkContextRoutes } from './routes/sdk-context.js';
|
|
48
49
|
import { sdkMcpStatusRoutes } from './routes/sdk-mcp-status.js';
|
|
49
50
|
import { proxyStatsRoutes } from './routes/proxy-stats.js';
|
|
51
|
+
import { updateRoutes } from './routes/update.js';
|
|
52
|
+
import { UpdateJob } from './lib/update-job.js';
|
|
50
53
|
import { setProxyStatsListener, setSlowUpstreamListener } from './lib/proxy/proxy-stats.js';
|
|
51
54
|
import * as imCore from './lib/im/im-bridge-core.js';
|
|
52
55
|
import * as imProcMgr from './lib/im/im-process-manager.js';
|
|
@@ -353,6 +356,8 @@ export function setWorkspaceClaudePath(path, isNpm) {
|
|
|
353
356
|
}
|
|
354
357
|
let _launchCallback = null;
|
|
355
358
|
export function setLaunchCallback(fn) { _launchCallback = fn; }
|
|
359
|
+
let _restartHandler = null;
|
|
360
|
+
export function setRestartHandler(fn) { _restartHandler = fn; }
|
|
356
361
|
export function setWorkspaceLaunched(v) { _workspaceLaunched = v; }
|
|
357
362
|
export function initPostLaunch() {
|
|
358
363
|
startLogWatch();
|
|
@@ -509,9 +514,27 @@ setProxyStatsListener(notifyProxyStats);
|
|
|
509
514
|
// terminal WS — decides whether the slow request maps to a live session worth
|
|
510
515
|
// surfacing. The frame carries the request's own cwd/instanceKey and is routed
|
|
511
516
|
// through broadcastWsMessage, so only viewers of that workspace/instance see it.
|
|
517
|
+
const _pendingSlowUpstreams = new Map(); // requestId → the last user-visible slow frame
|
|
518
|
+
|
|
519
|
+
function _replaySlowUpstreams(ws) {
|
|
520
|
+
if (!isSdkMode || !ws || ws.readyState !== 1) return;
|
|
521
|
+
const now = Date.now();
|
|
522
|
+
for (const frame of _pendingSlowUpstreams.values()) {
|
|
523
|
+
const project = projectKeyForCwd(frame.cwd);
|
|
524
|
+
// The initial connection may precede client view hydration. In that case
|
|
525
|
+
// replay only the bound workspace, never every background workspace.
|
|
526
|
+
const viewProject = ws._ccvViewProject || _projectName;
|
|
527
|
+
if (viewProject && project !== viewProject) continue;
|
|
528
|
+
if (ws._ccvViewInstance && frame.instanceKey !== ws._ccvViewInstance) continue;
|
|
529
|
+
try {
|
|
530
|
+
ws.send(JSON.stringify({ ...frame, waitingMs: now - frame.startedAt, ts: now }));
|
|
531
|
+
} catch (err) { reportSwallowed('server.slow-upstream-replay', err); }
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
512
535
|
setSlowUpstreamListener(({ type, requestId, cwd, instanceKey, waitingMs, model } = {}) => {
|
|
513
536
|
try {
|
|
514
|
-
if (!isSdkMode || !_sdkListSessions
|
|
537
|
+
if (!isSdkMode || !_sdkListSessions) return;
|
|
515
538
|
// Match the session by the request's real cwd (and instance when present),
|
|
516
539
|
// not the process-wide bound project — concurrent workspaces would otherwise
|
|
517
540
|
// cross-attribute the advisory. No live session → the slow request is not
|
|
@@ -527,6 +550,7 @@ setSlowUpstreamListener(({ type, requestId, cwd, instanceKey, waitingMs, model }
|
|
|
527
550
|
? (sessions.find(s => s.instanceKey === instanceKey) || null)
|
|
528
551
|
: (sessions.find(s => cwd && s.cwd === cwd) || null);
|
|
529
552
|
if (type === 'resolved') {
|
|
553
|
+
if (requestId) _pendingSlowUpstreams.delete(requestId);
|
|
530
554
|
// The waited-on request settled — tell the UI to dismiss the toast. A
|
|
531
555
|
// request can settle AFTER its session closed (review P2-2): the session
|
|
532
556
|
// lookup then misses and the dismiss would be silently dropped, leaving a
|
|
@@ -541,10 +565,13 @@ setSlowUpstreamListener(({ type, requestId, cwd, instanceKey, waitingMs, model }
|
|
|
541
565
|
return;
|
|
542
566
|
}
|
|
543
567
|
if (!sess) return;
|
|
544
|
-
|
|
568
|
+
const frame = {
|
|
545
569
|
type: 'sdk-slow-upstream', cwd: sess.cwd, project: projectKeyForCwd(sess.cwd),
|
|
546
|
-
instanceKey: sess.instanceKey || null, requestId: requestId || null, waitingMs, model: model || null,
|
|
547
|
-
|
|
570
|
+
instanceKey: sess.instanceKey || null, requestId: requestId || null, waitingMs, model: model || null,
|
|
571
|
+
startedAt: Date.now() - Math.max(0, Number(waitingMs) || 0), ts: Date.now(),
|
|
572
|
+
};
|
|
573
|
+
if (frame.requestId) _pendingSlowUpstreams.set(frame.requestId, frame);
|
|
574
|
+
broadcastWsMessage(frame);
|
|
548
575
|
} catch (err) { reportSwallowed('server.slow-upstream-listener', err); }
|
|
549
576
|
});
|
|
550
577
|
|
|
@@ -732,6 +759,11 @@ function _ensureImWatch(id) {
|
|
|
732
759
|
catch (e) { console.warn(`[im-log-watcher] ensure(${id}) failed:`, e?.message || e); }
|
|
733
760
|
}
|
|
734
761
|
|
|
762
|
+
const updateJob = new UpdateJob({ get currentPort() { return actualPort; } });
|
|
763
|
+
updateJob.subscribe((state) => {
|
|
764
|
+
sendEventToClients(clients, 'update_progress', state);
|
|
765
|
+
});
|
|
766
|
+
|
|
735
767
|
const deps = {
|
|
736
768
|
// Reassignable runtime state — must stay getters.
|
|
737
769
|
get protocol() { return serverProtocol; },
|
|
@@ -747,6 +779,10 @@ const deps = {
|
|
|
747
779
|
// the live value at request time (e.g. resume.js scope-key resolution).
|
|
748
780
|
get projectName() { return _projectName || ''; },
|
|
749
781
|
get launchCallback() { return _launchCallback; },
|
|
782
|
+
updateJob,
|
|
783
|
+
restartProcess: (version) => _restartHandler(version),
|
|
784
|
+
get canRestartProcess() { return typeof _restartHandler === 'function'; },
|
|
785
|
+
get isRuntimeStopping() { return _isStopping; },
|
|
750
786
|
get workspaceClaudeArgs() { return _workspaceClaudeArgs; },
|
|
751
787
|
get workspaceClaudePath() { return _workspaceClaudePath; },
|
|
752
788
|
get workspaceIsNpmVersion() { return _workspaceIsNpmVersion; },
|
|
@@ -939,6 +975,7 @@ const _routes = [
|
|
|
939
975
|
...dingtalkRoutes,
|
|
940
976
|
...imRoutes,
|
|
941
977
|
...proxyStatsRoutes,
|
|
978
|
+
...updateRoutes,
|
|
942
979
|
...resumeRoutes,
|
|
943
980
|
...sdkContextRoutes,
|
|
944
981
|
...sdkMcpStatusRoutes,
|
|
@@ -2239,6 +2276,12 @@ async function setupTerminalWebSocket(httpServer) {
|
|
|
2239
2276
|
});
|
|
2240
2277
|
|
|
2241
2278
|
wss.on('connection', (ws) => {
|
|
2279
|
+
// Per-connection app-level ping (extracted for tests — see attachTerminalWsPing):
|
|
2280
|
+
// send-only on purpose; a dead connection is skipped (readyState gate) and the
|
|
2281
|
+
// client-side watchdog owns close+reconnect, keeping the historical broadcast
|
|
2282
|
+
// semantics (skip non-OPEN, heal on reconnect) unchanged.
|
|
2283
|
+
attachTerminalWsPing(ws);
|
|
2284
|
+
|
|
2242
2285
|
// 发送当前 PTY 状态
|
|
2243
2286
|
const state = getPtyState();
|
|
2244
2287
|
ws.send(JSON.stringify({ type: 'state', ...state }));
|
|
@@ -2283,8 +2326,9 @@ async function setupTerminalWebSocket(httpServer) {
|
|
|
2283
2326
|
ws.send(JSON.stringify({
|
|
2284
2327
|
type: 'perm-hook-pending', id, toolName: entry.toolName, input: entry.input,
|
|
2285
2328
|
autoApproveAt: entry.autoCancelled ? null : (entry.auto?.autoApproveAt ?? null),
|
|
2286
|
-
// 0 = server says OFF (fork-off / npm publish floor
|
|
2287
|
-
//
|
|
2329
|
+
// 0 = server says OFF (fork-off / npm publish floor — the floor applies at
|
|
2330
|
+
// every tier except full auto-approve -2): never let a reconnecting client
|
|
2331
|
+
// fall back to its local pref and re-arm a countdown the server disabled.
|
|
2288
2332
|
autoApproveSeconds: entry.auto?.seconds ?? 0,
|
|
2289
2333
|
autoCancelled: entry.autoCancelled === true,
|
|
2290
2334
|
}));
|
|
@@ -2357,6 +2401,8 @@ async function setupTerminalWebSocket(httpServer) {
|
|
|
2357
2401
|
// ask 类带 startedAt/timeoutMs —— 与 ask-hook replay 同款剩余时间重算。
|
|
2358
2402
|
if (isSdkMode) replaySdkPendingApprovals();
|
|
2359
2403
|
|
|
2404
|
+
_replaySlowUpstreams(ws);
|
|
2405
|
+
|
|
2360
2406
|
// Replay sdk-init snapshot so a refreshed/reconnected page restores slash-command
|
|
2361
2407
|
// surface and model info without waiting for the next session.
|
|
2362
2408
|
if (isSdkMode && _sdkGetInitSnapshot) {
|
|
@@ -2601,6 +2647,8 @@ async function setupTerminalWebSocket(httpServer) {
|
|
|
2601
2647
|
// The replay helpers already filter by the just-stamped view project+instance,
|
|
2602
2648
|
// and the frontend dedupes by id, so a full replay never double-opens a modal.)
|
|
2603
2649
|
replaySdkPendingApprovals();
|
|
2650
|
+
// Restore requests that were still waiting when this view disconnected.
|
|
2651
|
+
_replaySlowUpstreams(ws);
|
|
2604
2652
|
// Re-announce the just-viewed workspace's turn state so the spinner / Stop
|
|
2605
2653
|
// button reflects it immediately (otherwise a long-running turn shows idle
|
|
2606
2654
|
// until the next state change or heartbeat).
|
|
@@ -3958,6 +4006,16 @@ async function _doStop() {
|
|
|
3958
4006
|
}
|
|
3959
4007
|
// Tear down terminal WSS so stop/start cycles never leak a second listener on the same HTTP server.
|
|
3960
4008
|
if (terminalWss) {
|
|
4009
|
+
// A noServer WebSocketServer's close() does NOT terminate existing upgraded
|
|
4010
|
+
// connections — it only stops accepting new ones. Left alive, a zombie
|
|
4011
|
+
// connection keeps receiving the 25s ping, so the client watchdog never
|
|
4012
|
+
// judges it half-open and never reconnects to the fresh server (the exact
|
|
4013
|
+
// freeze this keepalive was added to fix). Terminate first (mirror
|
|
4014
|
+
// streamMux.close()), which fires each socket's close event and clears its
|
|
4015
|
+
// ping interval.
|
|
4016
|
+
for (const c of terminalWss.clients) {
|
|
4017
|
+
try { c.terminate(); } catch { /* already gone */ }
|
|
4018
|
+
}
|
|
3961
4019
|
terminalWss.close();
|
|
3962
4020
|
terminalWss = null;
|
|
3963
4021
|
}
|
|
@@ -4169,7 +4227,7 @@ if (!isWorkspaceMode) {
|
|
|
4169
4227
|
// 延迟 30 秒异步检查更新。
|
|
4170
4228
|
// 为什么是 30s 而非 3s:空闲/忙判断的核心是 `clients.length`(SSE 已连) + PTY + SDK。
|
|
4171
4229
|
// 3s 时大多数 client 还没连上 → busy 恒 false → 升级照打断用户。30s 给"活跃会话"留出进入窗口。
|
|
4172
|
-
//
|
|
4230
|
+
// Check only; an install is always initiated and confirmed by the user.
|
|
4173
4231
|
// 句柄必须保存:_doStop 要 clearTimeout(stop/start 循环防泄漏);.unref() 防 keep-alive。
|
|
4174
4232
|
// 测试侧三重防护:此处 unref + updater.js 的 L5 铁闸 + npm test 脚本 DISABLE_NONESSENTIAL_TRAFFIC。
|
|
4175
4233
|
_updateCheckTimer = setTimeout(async () => {
|
|
@@ -4185,17 +4243,15 @@ if (!isWorkspaceMode) {
|
|
|
4185
4243
|
// 共用 update_major_available 事件渲染 banner(前端不区分子类,命令在 i18n 文案里给)。
|
|
4186
4244
|
// brew_managed / pnpm_managed 走这里至关重要:否则 Electron / GUI 用户看不到升级提示,
|
|
4187
4245
|
// 仅 stderr 一行 console.error 在桌面模式下不可见。
|
|
4188
|
-
if (result.
|
|
4246
|
+
if (result.remoteVersion && result.status !== 'latest' && result.status !== 'disabled' && result.status !== 'error') {
|
|
4189
4247
|
// 先缓存:之后新连接的 SSE 客户端会在 events 路由里补推此事件
|
|
4190
4248
|
pendingMajorUpdate = { version: result.remoteVersion, source: result.status };
|
|
4191
4249
|
const payload = JSON.stringify(pendingMajorUpdate);
|
|
4192
4250
|
clients.forEach(client => {
|
|
4193
4251
|
try { sseWrite(client, `event: update_major_available\ndata: ${payload}\n\n`); } catch { }
|
|
4194
4252
|
});
|
|
4195
|
-
} else if (result.status === 'upgrading_in_background') {
|
|
4196
|
-
console.error(`[CC Viewer] background upgrade to ${result.remoteVersion} started (active after next launch)`);
|
|
4197
4253
|
}
|
|
4198
|
-
} catch {
|
|
4254
|
+
} catch (err) { reportSwallowed('server.update-check', err); }
|
|
4199
4255
|
}, 30_000);
|
|
4200
4256
|
_updateCheckTimer.unref();
|
|
4201
4257
|
}).catch(err => {
|