cc-viewer 1.9.23 → 1.9.25
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/LICENSE.md +28 -0
- package/README.md +1 -1
- package/cli.js +14 -0
- package/dist/assets/App-BUIwNK3C.js +2 -0
- package/dist/assets/App-C5xq-7nS.css +1 -0
- package/dist/assets/ArchivePreview-BKXTsPsN.css +1 -0
- package/dist/assets/ArchivePreview-BuFE-N7z.js +1 -0
- package/dist/assets/{MdxEditorPanel-CTAS2DJv.js → MdxEditorPanel-BiKPuJGb.js} +1 -1
- package/dist/assets/Mobile-D2UvqCIN.js +1 -0
- package/dist/assets/{ProxyStatsModal-C4sl-cuB.js → ProxyStatsModal-CBdBgS9_.js} +1 -1
- package/dist/assets/{_baseUniq-CsF04anE.js → _baseUniq-h4hafO2D.js} +1 -1
- package/dist/assets/{arc-BOacYe6N.js → arc-CN5nAVn-.js} +1 -1
- package/dist/assets/{architectureDiagram-Q4EWVU46-BSUEfjC_.js → architectureDiagram-Q4EWVU46-NTnIUsWP.js} +1 -1
- package/dist/assets/{blockDiagram-DXYQGD6D-CC37UGtW.js → blockDiagram-DXYQGD6D-BPFMPOwn.js} +1 -1
- package/dist/assets/{c4Diagram-AHTNJAMY-IzgRD4uO.js → c4Diagram-AHTNJAMY-CAPyXRVj.js} +1 -1
- package/dist/assets/{channel-C6PxyQUn.js → channel-BULnUStk.js} +1 -1
- package/dist/assets/{chunk-4BX2VUAB-cdQt_dcU.js → chunk-4BX2VUAB-BeSOU8fB.js} +1 -1
- package/dist/assets/{chunk-4TB4RGXK-BpTDA_Pb.js → chunk-4TB4RGXK-BVCrVLA0.js} +1 -1
- package/dist/assets/{chunk-55IACEB6-CcitNo0P.js → chunk-55IACEB6-D0XHzdzo.js} +1 -1
- package/dist/assets/{chunk-EDXVE4YY-BjKwZ9I7.js → chunk-EDXVE4YY-DizHN_m_.js} +1 -1
- package/dist/assets/{chunk-FMBD7UC4-vZDVX3tI.js → chunk-FMBD7UC4-3r0oXmep.js} +1 -1
- package/dist/assets/{chunk-OYMX7WX6-DGkYahGo.js → chunk-OYMX7WX6-C701FNEA.js} +1 -1
- package/dist/assets/{chunk-QZHKN3VN-C9065hSE.js → chunk-QZHKN3VN-KAdMyJai.js} +1 -1
- package/dist/assets/{chunk-YZCP3GAM-D_pcTg6_.js → chunk-YZCP3GAM-Cn2gaRZ3.js} +1 -1
- package/dist/assets/classDiagram-6PBFFD2Q-7MJg98xK.js +1 -0
- package/dist/assets/classDiagram-v2-HSJHXN6E-7MJg98xK.js +1 -0
- package/dist/assets/clone-Bddq99Xt.js +1 -0
- package/dist/assets/{cose-bilkent-S5V4N54A-BPPFMIGv.js → cose-bilkent-S5V4N54A-URab8isi.js} +1 -1
- package/dist/assets/{dagre-KV5264BT-fjzhKO5o.js → dagre-KV5264BT-Cq24tJ6h.js} +1 -1
- package/dist/assets/{diagram-5BDNPKRD-5L6FzTry.js → diagram-5BDNPKRD-D4KEpJ0T.js} +1 -1
- package/dist/assets/{diagram-G4DWMVQ6-GOwcGpff.js → diagram-G4DWMVQ6-DZLa6S7S.js} +1 -1
- package/dist/assets/{diagram-MMDJMWI5-BDsFE25W.js → diagram-MMDJMWI5-BBhsOBKy.js} +1 -1
- package/dist/assets/{diagram-TYMM5635-BqjpbSGH.js → diagram-TYMM5635-ClWpYbD-.js} +1 -1
- package/dist/assets/{erDiagram-SMLLAGMA-DWO3Dk1v.js → erDiagram-SMLLAGMA-5RXRgGvh.js} +1 -1
- package/dist/assets/{flowDiagram-DWJPFMVM-Br4nNBVd.js → flowDiagram-DWJPFMVM-DXiHDbOU.js} +1 -1
- package/dist/assets/{ganttDiagram-T4ZO3ILL-9sN-VOhw.js → ganttDiagram-T4ZO3ILL-Db5oVw9h.js} +1 -1
- package/dist/assets/{gitGraphDiagram-UUTBAWPF-BsPcTAKr.js → gitGraphDiagram-UUTBAWPF-CCPK1X9H.js} +1 -1
- package/dist/assets/{graph-o31GzaB6.js → graph-DNxO4J9w.js} +1 -1
- package/dist/assets/{index-tZqiJJGq.js → index-Bc_IaWe7.js} +1 -1
- package/dist/assets/{index-CXMr3tiK.js → index-CXW8X8EW.js} +1 -1
- package/dist/assets/{index-B3b0lRUB.js → index-DDo6Z3Ov.js} +1 -1
- package/dist/assets/{index-CuvDJTY7.js → index-DR_FOzBM.js} +1 -1
- package/dist/assets/{index-PDvAAbti.js → index-DaP3fzs1.js} +1 -1
- package/dist/assets/{index-DAjx9lT3.js → index-Do02L044.js} +1 -1
- package/dist/assets/{index-DyV81jSF.js → index-HLRCpKmY.js} +1 -1
- package/dist/assets/index-ev1Hmm1O.js +2 -0
- package/dist/assets/{infoDiagram-42DDH7IO-VUMzEo4o.js → infoDiagram-42DDH7IO-CzPZsFEc.js} +1 -1
- package/dist/assets/{ishikawaDiagram-UXIWVN3A-BuzrU3sx.js → ishikawaDiagram-UXIWVN3A-eEVseuO_.js} +1 -1
- package/dist/assets/{journeyDiagram-VCZTEJTY-BZtR5BAF.js → journeyDiagram-VCZTEJTY-CmMKnKhj.js} +1 -1
- package/dist/assets/{jszip.min-CtodH5MV.js → jszip.min-JnHXMwa-.js} +1 -1
- package/dist/assets/{kanban-definition-6JOO6SKY-Cj_97xXb.js → kanban-definition-6JOO6SKY-CZMggR3M.js} +1 -1
- package/dist/assets/{layout-Du0I-tlh.js → layout-DVqRDfNO.js} +1 -1
- package/dist/assets/{linear-BJtxCASI.js → linear-BHB3KNeC.js} +1 -1
- package/dist/assets/{mermaid.core-QlorX0Yw.js → mermaid.core-DOjmjAg3.js} +2 -2
- package/dist/assets/{min-BVnQfunZ.js → min-DxJCEK6c.js} +1 -1
- package/dist/assets/{mindmap-definition-QFDTVHPH-Bh_KL4qU.js → mindmap-definition-QFDTVHPH-B6W3RjCJ.js} +1 -1
- package/dist/assets/{pieDiagram-DEJITSTG-Bvv0rC_q.js → pieDiagram-DEJITSTG-BRNQVuFX.js} +1 -1
- package/dist/assets/{quadrantDiagram-34T5L4WZ-Bw8cGCRU.js → quadrantDiagram-34T5L4WZ-CUCnCkJJ.js} +1 -1
- package/dist/assets/{requirementDiagram-MS252O5E-Cg9jQ71h.js → requirementDiagram-MS252O5E-Ds-5hLni.js} +1 -1
- package/dist/assets/{sankeyDiagram-XADWPNL6-BXJo6-CD.js → sankeyDiagram-XADWPNL6-Cxi30RZc.js} +1 -1
- package/dist/assets/seqResourceLoaders-B8ZIXCeg.js +2 -0
- package/dist/assets/seqResourceLoaders-DH-Nl0yh.css +41 -0
- package/dist/assets/{sequenceDiagram-FGHM5R23-D7zpGxwq.js → sequenceDiagram-FGHM5R23-C6CukZv8.js} +1 -1
- package/dist/assets/{stateDiagram-FHFEXIEX-Der2CqR1.js → stateDiagram-FHFEXIEX-iPJCU2Ja.js} +1 -1
- package/dist/assets/{stateDiagram-v2-QKLJ7IA2-DetvG_Lc.js → stateDiagram-v2-QKLJ7IA2-DMFhwtNH.js} +1 -1
- package/dist/assets/{timeline-definition-GMOUNBTQ-0UenzEZ6.js → timeline-definition-GMOUNBTQ-Dqd-tCUs.js} +1 -1
- package/dist/assets/{vendor-antd-I6I2F7Rv.js → vendor-antd-D1L_UwKJ.js} +1 -1
- package/dist/assets/{vendor-codemirror-Zkm6UHQg.js → vendor-codemirror-DOZOjrWx.js} +1 -1
- package/dist/assets/{vendor-mdxeditor-CC09MDyZ.js → vendor-mdxeditor-8ZUcYZ6G.js} +2 -2
- package/dist/assets/{vendor-qrcode-gZpmSeeh.js → vendor-qrcode-Pw_LHfBZ.js} +1 -1
- package/dist/assets/{vendor-virtuoso-BGwznQ5y.js → vendor-virtuoso-AhfR22q5.js} +1 -1
- package/dist/assets/{vennDiagram-DHZGUBPP-COzYyZ5h.js → vennDiagram-DHZGUBPP-CrOJisSD.js} +1 -1
- package/dist/assets/{wardley-RL74JXVD-VZdOtN8t.js → wardley-RL74JXVD-By8Ltw9G.js} +1 -1
- package/dist/assets/{wardleyDiagram-NUSXRM2D-CVkL75Qy.js → wardleyDiagram-NUSXRM2D-5SnzlvF9.js} +1 -1
- package/dist/assets/{xychartDiagram-5P7HB3ND-6CHBAYyF.js → xychartDiagram-5P7HB3ND-CJ4uNjoK.js} +1 -1
- package/dist/index.html +4 -4
- package/node_modules/@ccv/core/src/ask-auto-answer.js +122 -0
- package/package.json +1 -1
- package/server/i18n.js +0 -20
- package/server/lib/ask/ask-bridge.js +4 -1
- package/server/lib/ask/ask-reaper.js +1 -0
- package/server/lib/ask-auto-answer.js +153 -0
- package/server/lib/auto-approve.js +3 -1
- package/server/lib/binary-sniff.js +35 -0
- package/server/lib/restart-helper.js +65 -0
- package/server/lib/restart.js +83 -0
- package/server/lib/sdk-manager.js +65 -19
- 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/pty-manager.js +1 -0
- package/server/routes/ask-perm.js +87 -6
- package/server/routes/files-content.js +46 -8
- package/server/routes/project-meta.js +11 -7
- package/server/routes/update.js +58 -0
- package/server/server.js +69 -5
- package/server/system-prompt-templates/presets/kimi-k3.md +8 -0
- package/dist/assets/App-BvVdj099.css +0 -1
- package/dist/assets/App-DEA3HoZr.js +0 -2
- package/dist/assets/Mobile-CgVpXvs2.js +0 -1
- package/dist/assets/classDiagram-6PBFFD2Q-BUmU_G-i.js +0 -1
- package/dist/assets/classDiagram-v2-HSJHXN6E-BUmU_G-i.js +0 -1
- package/dist/assets/clone-CvoOne2K.js +0 -1
- package/dist/assets/index-CS47d9oh.js +0 -2
- package/dist/assets/seqResourceLoaders-CORH46PN.js +0 -2
- package/dist/assets/seqResourceLoaders-v4YzKhTS.css +0 -41
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Ask / permission hook bridge routes (moved verbatim from server.js handleRequest).
|
|
2
|
-
import { loadAskStore, consumeIfFinal as askStoreConsumeIfFinal, markCancelled as askStoreMarkCancelled } from '../lib/ask/ask-store.js';
|
|
2
|
+
import { loadAskStore, consumeIfFinal as askStoreConsumeIfFinal, markCancelled as askStoreMarkCancelled, markAnswered as askStoreMarkAnswered } from '../lib/ask/ask-store.js';
|
|
3
3
|
import { runWaterfallHook, runParallelHook } from '../lib/plugin-loader.js';
|
|
4
4
|
import { sendEventToClients } from '../lib/log-watcher.js';
|
|
5
5
|
import { filterClientsByScope } from '../lib/v2/view-router.js';
|
|
@@ -9,6 +9,7 @@ import { getCurrentProjectKey, hasFork, resolveScoped } from '../lib/project-pre
|
|
|
9
9
|
import { reportSwallowed } from '../lib/error-report.js';
|
|
10
10
|
import { computeAutoApprove, createAutoApproveState } from '../lib/auto-approve.js';
|
|
11
11
|
import { isPublishCommand } from '../lib/approval-policy.js';
|
|
12
|
+
import { computeAskAutoAnswer, createAskAutoAnswerState, pickAutoAnswers, replayAskAutoAnswerFields } from '../lib/ask-auto-answer.js';
|
|
12
13
|
|
|
13
14
|
function pendingAsks(req, res, parsedUrl, isLocal, deps) {
|
|
14
15
|
try {
|
|
@@ -17,6 +18,8 @@ function pendingAsks(req, res, parsedUrl, isLocal, deps) {
|
|
|
17
18
|
// 答案投递仍由 WS ask-hook-answer 路径走 server 端 first-write-wins)。
|
|
18
19
|
const memEntries = [...deps.pendingAskHooks.entries()].map(([id, e]) => ({
|
|
19
20
|
id, questions: e.questions, createdAt: e.createdAt, source: 'memory',
|
|
21
|
+
// Hosting fields for the reconnect recovery chain (client countdown UI).
|
|
22
|
+
...replayAskAutoAnswerFields(e.auto, e.autoCancelled),
|
|
20
23
|
}));
|
|
21
24
|
const memIds = new Set(memEntries.map(e => e.id));
|
|
22
25
|
const diskAll = loadAskStore();
|
|
@@ -25,7 +28,12 @@ function pendingAsks(req, res, parsedUrl, isLocal, deps) {
|
|
|
25
28
|
// 另外过滤 questions 数组非空(防御性)。
|
|
26
29
|
const diskOnly = Object.values(diskAll)
|
|
27
30
|
.filter(e => !memIds.has(e.id) && e.status === 'pending' && Array.isArray(e.questions) && e.questions.length > 0)
|
|
28
|
-
.map(e => ({
|
|
31
|
+
.map(e => ({
|
|
32
|
+
id: e.id, questions: e.questions, createdAt: e.createdAt, source: 'disk',
|
|
33
|
+
// Timers are memory-only: after a server restart an orphaned pending ask
|
|
34
|
+
// degrades to manual answering (documented decision — no schema migration).
|
|
35
|
+
autoAnswerAt: null, autoAnswerSeconds: null, autoCancelled: false,
|
|
36
|
+
}));
|
|
29
37
|
const all = [...memEntries, ...diskOnly].sort((a, b) => a.createdAt - b.createdAt);
|
|
30
38
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
31
39
|
res.end(JSON.stringify({ pendingAsks: all, askProtocolVersion: 1 }));
|
|
@@ -56,7 +64,7 @@ function askHook(req, res, parsedUrl, isLocal, deps) {
|
|
|
56
64
|
return;
|
|
57
65
|
}
|
|
58
66
|
try {
|
|
59
|
-
const { questions, toolUseId } = JSON.parse(body);
|
|
67
|
+
const { questions, toolUseId, cwd } = JSON.parse(body);
|
|
60
68
|
if (!Array.isArray(questions) || questions.length === 0) {
|
|
61
69
|
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
62
70
|
res.end(JSON.stringify({ error: 'Missing questions' }));
|
|
@@ -81,6 +89,7 @@ function askHook(req, res, parsedUrl, isLocal, deps) {
|
|
|
81
89
|
const oldest = deps.pendingAskHooks.get(oldestId);
|
|
82
90
|
if (oldest) {
|
|
83
91
|
clearTimeout(oldest.timer);
|
|
92
|
+
if (oldest.auto?.timer) clearTimeout(oldest.auto.timer);
|
|
84
93
|
try { if (!oldest.res.headersSent) { oldest.res.writeHead(429, { 'Content-Type': 'application/json' }); oldest.res.end(JSON.stringify({ error: 'Too many concurrent requests' })); } } catch {}
|
|
85
94
|
deps.pendingAskHooks.delete(oldestId);
|
|
86
95
|
deps.persistAskDelete(oldestId);
|
|
@@ -106,13 +115,25 @@ function askHook(req, res, parsedUrl, isLocal, deps) {
|
|
|
106
115
|
&& toolUseId.length > 0 && toolUseId.length <= 256
|
|
107
116
|
&& /^[a-zA-Z0-9_-]+$/.test(toolUseId);
|
|
108
117
|
let id;
|
|
118
|
+
// A durable per-ask hosting cancel carried over from the slot being replaced
|
|
119
|
+
// (ask-bridge retry) — initialized before the placeholder is created below.
|
|
120
|
+
let _placeholderAutoCancelled = false;
|
|
109
121
|
if (wantsToolUseId) {
|
|
110
122
|
const existing = deps.pendingAskHooks.get(toolUseId);
|
|
111
123
|
if (!existing) {
|
|
112
124
|
id = toolUseId;
|
|
113
125
|
} else if (!existing.res || existing.res.writableEnded || existing.res.destroyed) {
|
|
114
126
|
// 旧 res 已断(包含占位 res:null 残留)— ask-bridge 重试同 toolUseId 合理,复用槽位
|
|
127
|
+
// Clear the stale hosting timer too: it would otherwise fire later against the
|
|
128
|
+
// re-registered entry and answer it at the OLD deadline with the OLD selection.
|
|
129
|
+
// The new entry arms a fresh full-length timer from this re-arrival (the disk
|
|
130
|
+
// schema carries no deadline, so the original one cannot be preserved).
|
|
115
131
|
if (existing.timer) clearTimeout(existing.timer);
|
|
132
|
+
if (existing.auto?.timer) clearTimeout(existing.auto.timer);
|
|
133
|
+
// Preserve a durable per-ask hosting cancel across the retry: a user who
|
|
134
|
+
// cancelled hosting for THIS ask must not be auto-answered by the re-posted
|
|
135
|
+
// incarnation. (The cancelling tab also re-asserts via its local latch.)
|
|
136
|
+
if (existing.autoCancelled === true) _placeholderAutoCancelled = true;
|
|
116
137
|
deps.pendingAskHooks.delete(toolUseId);
|
|
117
138
|
deps.persistAskDelete(toolUseId);
|
|
118
139
|
id = toolUseId;
|
|
@@ -132,7 +153,11 @@ function askHook(req, res, parsedUrl, isLocal, deps) {
|
|
|
132
153
|
// TOCTOU 防御:占位 id 之前先注册 res.on('close'),否则 await runWaterfallHook 期间 client
|
|
133
154
|
// abort 的 close 事件落空 → entry 残到 HOOK_TIMEOUT(24h)。占位 set 提前到 await 之前防两条同 ms 并发
|
|
134
155
|
// POST 的 do-while 都通过 collision check 后 set 互相覆盖(first res 永泄漏到 HOOK_TIMEOUT)。
|
|
135
|
-
|
|
156
|
+
// Both hosting fields live on the placeholder too: a client ask-auto-cancel
|
|
157
|
+
// landing during the plugin-waterfall window stamps the durable flag here, and
|
|
158
|
+
// the live entry below inherits it (otherwise the cancel would be silently lost
|
|
159
|
+
// when the live object replaces the placeholder).
|
|
160
|
+
const _placeholderEntry = { questions, res, timer: null, createdAt: Date.now(), shortPoll: shortPollMode, autoCancelled: _placeholderAutoCancelled, auto: null };
|
|
136
161
|
deps.pendingAskHooks.set(id, _placeholderEntry);
|
|
137
162
|
deps.persistAskEntry(id, _placeholderEntry);
|
|
138
163
|
// Seed waiter liveness for the reaper (ask-reaper.js). Optional chaining:
|
|
@@ -146,6 +171,7 @@ function askHook(req, res, parsedUrl, isLocal, deps) {
|
|
|
146
171
|
if (entry) {
|
|
147
172
|
if (entry.shortPoll) return;
|
|
148
173
|
if (entry.timer) clearTimeout(entry.timer);
|
|
174
|
+
if (entry.auto?.timer) clearTimeout(entry.auto.timer);
|
|
149
175
|
deps.pendingAskHooks.delete(id);
|
|
150
176
|
deps.persistAskDelete(id);
|
|
151
177
|
if (deps.terminalWss) {
|
|
@@ -179,6 +205,7 @@ function askHook(req, res, parsedUrl, isLocal, deps) {
|
|
|
179
205
|
const timer = setTimeout(() => {
|
|
180
206
|
const entry = deps.pendingAskHooks.get(id);
|
|
181
207
|
if (entry) {
|
|
208
|
+
if (entry.auto?.timer) clearTimeout(entry.auto.timer); // defensive: outlives hosting in normal flows
|
|
182
209
|
deps.pendingAskHooks.delete(id);
|
|
183
210
|
deps.persistAskDelete(id);
|
|
184
211
|
try {
|
|
@@ -199,7 +226,15 @@ function askHook(req, res, parsedUrl, isLocal, deps) {
|
|
|
199
226
|
}, HOOK_TIMEOUT);
|
|
200
227
|
|
|
201
228
|
const askStartedAt = Date.now();
|
|
202
|
-
|
|
229
|
+
// Server-side hosting ("问答题自动托管"): when approvalModal.askAutoAnswerMinutes
|
|
230
|
+
// is set (0 = instant, N = N minutes), the server answers the ask itself at the
|
|
231
|
+
// wall-clock deadline (+1s buffer) even with no browser connected. Computed after
|
|
232
|
+
// the plugin waterfall so a plugin-answered ask never arms. The pick prefers the
|
|
233
|
+
// first option carrying a localized "Recommended" marker, else the first option.
|
|
234
|
+
const autoMeta = computeAskAutoAnswer(typeof cwd === 'string' && cwd ? cwd : undefined, { file: deps.getPrefsFile?.() });
|
|
235
|
+
const autoAnswers = autoMeta.enabled ? pickAutoAnswers(questions) : null;
|
|
236
|
+
const hosting = autoMeta.enabled && !!autoAnswers;
|
|
237
|
+
const _liveEntry = { ..._placeholderEntry, timer, createdAt: askStartedAt };
|
|
203
238
|
deps.pendingAskHooks.set(id, _liveEntry);
|
|
204
239
|
deps.persistAskEntry(id, _liveEntry);
|
|
205
240
|
|
|
@@ -214,8 +249,16 @@ function askHook(req, res, parsedUrl, isLocal, deps) {
|
|
|
214
249
|
}
|
|
215
250
|
|
|
216
251
|
// Broadcast to all terminal WS clients — 附 startedAt + timeoutMs 让前端渲染倒计时
|
|
252
|
+
// Honor a cancel inherited from the placeholder (slot-reuse) or landed during the
|
|
253
|
+
// plugin waterfall: never advertise a countdown that the fire guard will no-op.
|
|
254
|
+
const hostingActive = hosting && !_liveEntry.autoCancelled;
|
|
217
255
|
if (deps.terminalWss) {
|
|
218
|
-
|
|
256
|
+
// Always stamp the hosting fields (null when off) so a client whose global pref
|
|
257
|
+
// disagrees with the fork-resolved server value never re-arms locally.
|
|
258
|
+
const pmsg = JSON.stringify({
|
|
259
|
+
type: 'ask-hook-pending', id, questions, startedAt: askStartedAt, timeoutMs: HOOK_TIMEOUT,
|
|
260
|
+
...replayAskAutoAnswerFields(hostingActive ? autoMeta : null, _liveEntry.autoCancelled),
|
|
261
|
+
});
|
|
219
262
|
deps.terminalWss.clients.forEach((client) => {
|
|
220
263
|
if (client.readyState === 1) {
|
|
221
264
|
try { client.send(pmsg); } catch {}
|
|
@@ -223,6 +266,43 @@ function askHook(req, res, parsedUrl, isLocal, deps) {
|
|
|
223
266
|
});
|
|
224
267
|
}
|
|
225
268
|
deps.notifyParentPending({ type: 'ask-hook-pending', id, questions });
|
|
269
|
+
|
|
270
|
+
// Arm AFTER the entry is registered AND the pending frame is out: instant (0min)
|
|
271
|
+
// fires synchronously and resolves through the entry, so clients observe the
|
|
272
|
+
// order pending → resolved (never a ghost modal for an already-answered ask).
|
|
273
|
+
if (hostingActive) {
|
|
274
|
+
_liveEntry.auto = createAskAutoAnswerState(autoMeta, async () => {
|
|
275
|
+
const entry = deps.pendingAskHooks.get(id);
|
|
276
|
+
if (!entry || entry.autoCancelled) return;
|
|
277
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
278
|
+
deps.pendingAskHooks.delete(id);
|
|
279
|
+
deps.askWaiterLastPoll?.delete(id);
|
|
280
|
+
if (entry.shortPoll) {
|
|
281
|
+
// first-write-wins: a client answer (or another cc-viewer instance sharing
|
|
282
|
+
// ask-store.json) may have beaten the timer — never notify listeners with
|
|
283
|
+
// answers that disagree with the disk record.
|
|
284
|
+
let wrote = false;
|
|
285
|
+
try { wrote = await askStoreMarkAnswered(id, autoAnswers); } catch (err) { reportSwallowed('ask-perm.ask-auto-answered', err); }
|
|
286
|
+
if (!wrote) return;
|
|
287
|
+
deps.notifyShortPollAnswer?.(id, autoAnswers);
|
|
288
|
+
} else {
|
|
289
|
+
try {
|
|
290
|
+
if (entry.res && !entry.res.headersSent) {
|
|
291
|
+
entry.res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
292
|
+
entry.res.end(JSON.stringify({ answers: autoAnswers }));
|
|
293
|
+
}
|
|
294
|
+
} catch {}
|
|
295
|
+
deps.persistAskDelete(id);
|
|
296
|
+
}
|
|
297
|
+
if (deps.terminalWss) {
|
|
298
|
+
const rmsg = JSON.stringify({ type: 'ask-hook-resolved', id, reason: 'auto-answered' });
|
|
299
|
+
deps.terminalWss.clients.forEach((c) => {
|
|
300
|
+
if (c.readyState === 1) try { c.send(rmsg); } catch {}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
deps.notifyParentPending({ type: 'ask-hook-resolved', id });
|
|
304
|
+
});
|
|
305
|
+
}
|
|
226
306
|
} catch {
|
|
227
307
|
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
228
308
|
res.end(JSON.stringify({ error: 'Invalid request body' }));
|
|
@@ -342,6 +422,7 @@ function askHookCancel(req, res, parsedUrl, isLocal, deps) {
|
|
|
342
422
|
const entry = deps.pendingAskHooks.get(id);
|
|
343
423
|
if (entry) {
|
|
344
424
|
if (entry.timer) clearTimeout(entry.timer);
|
|
425
|
+
if (entry.auto?.timer) clearTimeout(entry.auto.timer);
|
|
345
426
|
deps.pendingAskHooks.delete(id);
|
|
346
427
|
deps.askWaiterLastPoll?.delete(id);
|
|
347
428
|
if (entry.shortPoll) {
|
|
@@ -9,6 +9,7 @@ import { projectKeyForCwd } from '../lib/system-prompt-snapshots.js';
|
|
|
9
9
|
import { loadWorkspaces } from '../workspace-registry.js';
|
|
10
10
|
import { listLivePtys } from '../pty-manager.js';
|
|
11
11
|
import { reportSwallowed } from '../lib/error-report.js';
|
|
12
|
+
import { isBinaryBuffer, getUtf16Encoding } from '../lib/binary-sniff.js';
|
|
12
13
|
import { discoverClaudeMdCandidates, readCandidateById } from '../lib/claude-md-discovery.js';
|
|
13
14
|
import { getClaudeConfigDir } from '../../findcc.js';
|
|
14
15
|
import { _projectName } from '../interceptor.js';
|
|
@@ -158,10 +159,19 @@ function fileContentGetWithRoot(req, res, parsedUrl, reqPath, cwd) {
|
|
|
158
159
|
res.end(JSON.stringify({ error: 'File too large' }));
|
|
159
160
|
return;
|
|
160
161
|
}
|
|
161
|
-
const
|
|
162
|
-
|
|
162
|
+
const raw = readFileSync(real);
|
|
163
|
+
if (isBinaryBuffer(raw)) {
|
|
164
|
+
res.writeHead(415, { 'Content-Type': 'application/json' });
|
|
165
|
+
res.end(JSON.stringify({ error: 'Binary file', reason: 'binary', size: st.size }));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const encoding = getUtf16Encoding(raw);
|
|
169
|
+
const content = encoding === 'utf16le' ? raw.subarray(2).toString('utf16le')
|
|
170
|
+
: encoding === 'utf16be' ? raw.subarray(2).swap16().toString('utf16le')
|
|
171
|
+
: raw.toString('utf-8');
|
|
172
|
+
// Decoded UTF-16 remains read-only: the existing write endpoint emits UTF-8.
|
|
163
173
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
164
|
-
res.end(JSON.stringify({ path: reqPath, content, size: st.size }));
|
|
174
|
+
res.end(JSON.stringify({ path: reqPath, content, size: st.size, ...(encoding ? { encoding, readOnly: true } : {}) }));
|
|
165
175
|
} catch (err) {
|
|
166
176
|
const status = ERROR_STATUS_MAP[err.code] || 500;
|
|
167
177
|
const message = status === 500 ? `Cannot read file: ${err.message}` : err.message;
|
|
@@ -405,7 +415,7 @@ function fileRaw(req, res, parsedUrl) {
|
|
|
405
415
|
fileRawWithRoot(req, res, parsedUrl, reqPath, cwd, method);
|
|
406
416
|
}
|
|
407
417
|
|
|
408
|
-
function fileRawWithRoot(req, res, parsedUrl, reqPath, cwd, method) {
|
|
418
|
+
function fileRawWithRoot(req, res, parsedUrl, reqPath, cwd, method, options = {}) {
|
|
409
419
|
try {
|
|
410
420
|
if (!reqPath) {
|
|
411
421
|
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
@@ -417,7 +427,7 @@ function fileRawWithRoot(req, res, parsedUrl, reqPath, cwd, method) {
|
|
|
417
427
|
|
|
418
428
|
// /tmp 原文件不存在时回退到持久化副本(保留原 fallback 语义,但用 policy 守卫)
|
|
419
429
|
let policy = isReadAllowed(absPath);
|
|
420
|
-
if (!policy.ok && policy.reason === 'realpath-failed' && isAbs) {
|
|
430
|
+
if (!policy.ok && policy.reason === 'realpath-failed' && isAbs && options.allowPersistedFallback !== false) {
|
|
421
431
|
const pName = _projectName || 'default';
|
|
422
432
|
const persistPrefix = join(getClaudeConfigDir(), 'cc-viewer', pName, 'images');
|
|
423
433
|
const fileName = basename(absPath);
|
|
@@ -445,13 +455,14 @@ function fileRawWithRoot(req, res, parsedUrl, reqPath, cwd, method) {
|
|
|
445
455
|
res.end(JSON.stringify({ error: 'Not a file' }));
|
|
446
456
|
return;
|
|
447
457
|
}
|
|
448
|
-
|
|
458
|
+
const maxBytes = options.maxBytes ?? 10 * 1024 * 1024;
|
|
459
|
+
if (stat.size > maxBytes) {
|
|
449
460
|
res.writeHead(413, { 'Content-Type': 'application/json' });
|
|
450
|
-
res.end(JSON.stringify({ error: 'File too large' }));
|
|
461
|
+
res.end(JSON.stringify({ error: 'File too large', ...(options.archive ? { maxBytes, size: stat.size } : {}) }));
|
|
451
462
|
return;
|
|
452
463
|
}
|
|
453
464
|
const ext = (targetFile.match(/\.[^.]+$/) || [''])[0].toLowerCase();
|
|
454
|
-
const mime = FILE_RAW_MIME[ext] || 'application/octet-stream';
|
|
465
|
+
const mime = options.archive ? 'application/octet-stream' : FILE_RAW_MIME[ext] || 'application/octet-stream';
|
|
455
466
|
const data = method === 'HEAD' ? null : readFileSync(targetFile);
|
|
456
467
|
const size = method === 'HEAD' ? stat.size : data.length;
|
|
457
468
|
const headers = { 'Content-Type': mime, 'Content-Length': size };
|
|
@@ -474,6 +485,24 @@ function fileRawWithRoot(req, res, parsedUrl, reqPath, cwd, method) {
|
|
|
474
485
|
}
|
|
475
486
|
}
|
|
476
487
|
|
|
488
|
+
const ARCHIVE_RAW_MAX_BYTES = 32 * 1024 * 1024;
|
|
489
|
+
const ARCHIVE_PREVIEW_EXTENSIONS = new Set(['.zip', '.tar', '.gz', '.tgz']);
|
|
490
|
+
|
|
491
|
+
function archiveRaw(req, res, parsedUrl) {
|
|
492
|
+
const reqPath = parsedUrl.searchParams.get('path') || '';
|
|
493
|
+
const name = basename(reqPath).toLowerCase();
|
|
494
|
+
if (!reqPath || ![...ARCHIVE_PREVIEW_EXTENSIONS].some(ext => name.endsWith(ext))) {
|
|
495
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
496
|
+
res.end(JSON.stringify({ error: 'Unsupported archive path' }));
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const cwd = _viewRootOrReply(req, res, parsedUrl);
|
|
500
|
+
if (!cwd) return;
|
|
501
|
+
fileRawWithRoot(req, res, parsedUrl, reqPath, cwd, req.method, {
|
|
502
|
+
archive: true, maxBytes: ARCHIVE_RAW_MAX_BYTES, allowPersistedFallback: false,
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
|
|
477
506
|
// Browser download endpoint: unlike fileRaw (inline preview, 10MB cap), this streams
|
|
478
507
|
// the file with Content-Disposition: attachment so the browser saves it to disk.
|
|
479
508
|
// No size cap — a download is precisely the path for files too large to preview.
|
|
@@ -718,6 +747,14 @@ function fileContentPost(req, res, parsedUrl, isLocal) {
|
|
|
718
747
|
res.end(JSON.stringify({ error: 'Forbidden', reason: 'outside-view-root' }));
|
|
719
748
|
return;
|
|
720
749
|
}
|
|
750
|
+
if (existsSync(targetReal)) {
|
|
751
|
+
const raw = readFileSync(targetReal);
|
|
752
|
+
if (getUtf16Encoding(raw) || isBinaryBuffer(raw)) {
|
|
753
|
+
res.writeHead(415, { 'Content-Type': 'application/json' });
|
|
754
|
+
res.end(JSON.stringify({ error: 'File requires read-only preview', reason: 'encoding' }));
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
721
758
|
writeFileSync(targetReal, content, 'utf-8');
|
|
722
759
|
const stat = statSync(targetReal);
|
|
723
760
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
@@ -840,6 +877,7 @@ export const filesContentRoutes = [
|
|
|
840
877
|
{ method: 'GET', match: 'exact', path: '/api/project-memory', handler: projectMemory },
|
|
841
878
|
{ method: 'GET', match: 'exact', path: '/api/claude-md', handler: claudeMd },
|
|
842
879
|
{ predicate: (url, method) => (url === '/api/file-raw' || url.startsWith('/api/file-raw/')) && (method === 'GET' || method === 'HEAD'), handler: fileRaw },
|
|
880
|
+
{ predicate: (url, method) => url === '/api/archive-raw' && (method === 'GET' || method === 'HEAD'), handler: archiveRaw },
|
|
843
881
|
{ predicate: (url, method) => url === '/api/download-file' && (method === 'GET' || method === 'HEAD'), handler: fileDownload },
|
|
844
882
|
{ method: 'POST', match: 'exact', path: '/api/file-content', handler: fileContentPost },
|
|
845
883
|
{ method: 'GET', match: 'exact', path: '/api/target-files', handler: targetFiles },
|
|
@@ -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
|
@@ -47,12 +47,15 @@ import { resumeRoutes } from './routes/resume.js';
|
|
|
47
47
|
import { sdkContextRoutes } from './routes/sdk-context.js';
|
|
48
48
|
import { sdkMcpStatusRoutes } from './routes/sdk-mcp-status.js';
|
|
49
49
|
import { proxyStatsRoutes } from './routes/proxy-stats.js';
|
|
50
|
+
import { updateRoutes } from './routes/update.js';
|
|
51
|
+
import { UpdateJob } from './lib/update-job.js';
|
|
50
52
|
import { setProxyStatsListener, setSlowUpstreamListener } from './lib/proxy/proxy-stats.js';
|
|
51
53
|
import * as imCore from './lib/im/im-bridge-core.js';
|
|
52
54
|
import * as imProcMgr from './lib/im/im-process-manager.js';
|
|
53
55
|
import * as chatQueue from './lib/chat-queue.js';
|
|
54
56
|
import { reportSwallowed } from './lib/error-report.js';
|
|
55
57
|
import { cancelAutoApproveState } from './lib/auto-approve.js';
|
|
58
|
+
import { cancelAskAutoAnswerState, replayAskAutoAnswerFields } from './lib/ask-auto-answer.js';
|
|
56
59
|
import { initScheduledTaskScheduler, startScheduledTaskScheduler, stopScheduledTaskScheduler } from './lib/scheduled-task-scheduler.js';
|
|
57
60
|
import { executeScheduledTask } from './lib/scheduled-task-executor.js';
|
|
58
61
|
import './lib/adapters/dingtalk-adapter.js'; // side-effect: registers the DingTalk adapter
|
|
@@ -352,6 +355,8 @@ export function setWorkspaceClaudePath(path, isNpm) {
|
|
|
352
355
|
}
|
|
353
356
|
let _launchCallback = null;
|
|
354
357
|
export function setLaunchCallback(fn) { _launchCallback = fn; }
|
|
358
|
+
let _restartHandler = null;
|
|
359
|
+
export function setRestartHandler(fn) { _restartHandler = fn; }
|
|
355
360
|
export function setWorkspaceLaunched(v) { _workspaceLaunched = v; }
|
|
356
361
|
export function initPostLaunch() {
|
|
357
362
|
startLogWatch();
|
|
@@ -731,6 +736,11 @@ function _ensureImWatch(id) {
|
|
|
731
736
|
catch (e) { console.warn(`[im-log-watcher] ensure(${id}) failed:`, e?.message || e); }
|
|
732
737
|
}
|
|
733
738
|
|
|
739
|
+
const updateJob = new UpdateJob({ get currentPort() { return actualPort; } });
|
|
740
|
+
updateJob.subscribe((state) => {
|
|
741
|
+
sendEventToClients(clients, 'update_progress', state);
|
|
742
|
+
});
|
|
743
|
+
|
|
734
744
|
const deps = {
|
|
735
745
|
// Reassignable runtime state — must stay getters.
|
|
736
746
|
get protocol() { return serverProtocol; },
|
|
@@ -746,6 +756,10 @@ const deps = {
|
|
|
746
756
|
// the live value at request time (e.g. resume.js scope-key resolution).
|
|
747
757
|
get projectName() { return _projectName || ''; },
|
|
748
758
|
get launchCallback() { return _launchCallback; },
|
|
759
|
+
updateJob,
|
|
760
|
+
restartProcess: (version) => _restartHandler(version),
|
|
761
|
+
get canRestartProcess() { return typeof _restartHandler === 'function'; },
|
|
762
|
+
get isRuntimeStopping() { return _isStopping; },
|
|
749
763
|
get workspaceClaudeArgs() { return _workspaceClaudeArgs; },
|
|
750
764
|
get workspaceClaudePath() { return _workspaceClaudePath; },
|
|
751
765
|
get workspaceIsNpmVersion() { return _workspaceIsNpmVersion; },
|
|
@@ -760,6 +774,7 @@ const deps = {
|
|
|
760
774
|
shortPollListeners,
|
|
761
775
|
askWaiterLastPoll,
|
|
762
776
|
notifyShortPollCancel: _notifyShortPollCancel,
|
|
777
|
+
notifyShortPollAnswer: _notifyShortPollAnswer,
|
|
763
778
|
editorSessions,
|
|
764
779
|
gitRestoreLocks,
|
|
765
780
|
liveStreamLastSeq: _liveStreamLastSeq,
|
|
@@ -937,6 +952,7 @@ const _routes = [
|
|
|
937
952
|
...dingtalkRoutes,
|
|
938
953
|
...imRoutes,
|
|
939
954
|
...proxyStatsRoutes,
|
|
955
|
+
...updateRoutes,
|
|
940
956
|
...resumeRoutes,
|
|
941
957
|
...sdkContextRoutes,
|
|
942
958
|
...sdkMcpStatusRoutes,
|
|
@@ -1742,6 +1758,7 @@ function _buildPluginInteractions() {
|
|
|
1742
1758
|
if (!entry) return false;
|
|
1743
1759
|
const { res: hookRes, timer } = entry;
|
|
1744
1760
|
clearTimeout(timer);
|
|
1761
|
+
if (entry.auto?.timer) clearTimeout(entry.auto.timer); // hosting timer must not fire post-resolve
|
|
1745
1762
|
pendingAskHooks.delete(id);
|
|
1746
1763
|
_persistAskDelete(id);
|
|
1747
1764
|
try {
|
|
@@ -2264,6 +2281,10 @@ async function setupTerminalWebSocket(httpServer) {
|
|
|
2264
2281
|
questions: entry.questions,
|
|
2265
2282
|
startedAt: now, // 让前端按"还剩 remaining"起算(不是原 createdAt)
|
|
2266
2283
|
timeoutMs: remaining, // 剩余可用时间
|
|
2284
|
+
// Hosting fields: keep the original absolute autoAnswerAt (do not rebase)
|
|
2285
|
+
// so a reconnected client's countdown stays on the server deadline, and a
|
|
2286
|
+
// cancelled hosting never re-arms.
|
|
2287
|
+
...replayAskAutoAnswerFields(entry.auto, entry.autoCancelled),
|
|
2267
2288
|
}));
|
|
2268
2289
|
} catch {}
|
|
2269
2290
|
}
|
|
@@ -2326,6 +2347,13 @@ async function setupTerminalWebSocket(httpServer) {
|
|
|
2326
2347
|
if (p.kind === 'ask') {
|
|
2327
2348
|
payload.startedAt = Date.now();
|
|
2328
2349
|
payload.timeoutMs = p.remainingMs;
|
|
2350
|
+
// Hosting fields (autoAnswerAt / autoAnswerSeconds / autoCancelled) come
|
|
2351
|
+
// from the sdk-manager snapshot (_getPendingApprovals) — stamp them so a
|
|
2352
|
+
// reconnected client restores the server deadline countdown and a
|
|
2353
|
+
// cancelled hosting never re-arms.
|
|
2354
|
+
payload.autoAnswerAt = p.autoAnswerAt ?? null;
|
|
2355
|
+
payload.autoAnswerSeconds = p.autoAnswerSeconds ?? null;
|
|
2356
|
+
payload.autoCancelled = p.autoCancelled === true;
|
|
2329
2357
|
} else {
|
|
2330
2358
|
// plan/perm: carry the server-side auto-approve deadline so a reconnected
|
|
2331
2359
|
// client renders the REMAINING time (and a cancelled one never re-arms)
|
|
@@ -2765,6 +2793,9 @@ async function setupTerminalWebSocket(httpServer) {
|
|
|
2765
2793
|
if (askEntry) {
|
|
2766
2794
|
const { res: hookRes, timer } = askEntry;
|
|
2767
2795
|
clearTimeout(timer);
|
|
2796
|
+
// Client answer wins: destroy the hosting timer so it cannot fire a
|
|
2797
|
+
// second, stale auto-answer after the manual one (perm parity :2856).
|
|
2798
|
+
if (askEntry.auto?.timer) clearTimeout(askEntry.auto.timer);
|
|
2768
2799
|
pendingAskHooks.delete(askId);
|
|
2769
2800
|
// Phase 3: short-poll 模式不立即删 disk —— 落 answered 让 GET listener / disk consume 拿
|
|
2770
2801
|
if (askEntry.shortPoll) {
|
|
@@ -2910,6 +2941,7 @@ async function setupTerminalWebSocket(httpServer) {
|
|
|
2910
2941
|
if (askEntry) {
|
|
2911
2942
|
const { res: hookRes, timer } = askEntry;
|
|
2912
2943
|
if (timer) clearTimeout(timer);
|
|
2944
|
+
if (askEntry.auto?.timer) clearTimeout(askEntry.auto.timer);
|
|
2913
2945
|
pendingAskHooks.delete(cancelId);
|
|
2914
2946
|
// Phase 3: short-poll 同样要让 disk + listener 知道,否则 ask-bridge 永远收不到 cancelled
|
|
2915
2947
|
if (askEntry.shortPoll) {
|
|
@@ -3014,6 +3046,40 @@ async function setupTerminalWebSocket(httpServer) {
|
|
|
3014
3046
|
}
|
|
3015
3047
|
}
|
|
3016
3048
|
}
|
|
3049
|
+
} else if (msg.type === 'ask-auto-cancel') {
|
|
3050
|
+
// Client cancelled the AskUserQuestion hosting ("取消托管") for ONE ask:
|
|
3051
|
+
// destroys the server-side hosting timer (SDK pending or PTY-hook entry),
|
|
3052
|
+
// the ask REMAINS pending for a manual answer, and the cancelled state is
|
|
3053
|
+
// replayed to fresh clients so they never re-arm the countdown. The global
|
|
3054
|
+
// setting is untouched — later asks are still hosted. Never a
|
|
3055
|
+
// pending-remove: the ask itself stays open.
|
|
3056
|
+
const rawAskAutoCancelId = msg.id != null ? String(msg.id) : null;
|
|
3057
|
+
const askAutoCancelId = validateApprovalId(msg.id);
|
|
3058
|
+
if (rawAskAutoCancelId && !askAutoCancelId) {
|
|
3059
|
+
console.warn('[server] ask-auto-cancel rejected: invalid id format');
|
|
3060
|
+
return;
|
|
3061
|
+
}
|
|
3062
|
+
let askAutoCancelHandled = false;
|
|
3063
|
+
let sdkBroadcast = false;
|
|
3064
|
+
if (askAutoCancelId && _sdkAutoCancelApproval) {
|
|
3065
|
+
try { askAutoCancelHandled = _sdkAutoCancelApproval(askAutoCancelId, 'ask') === true; } catch (err) { reportSwallowed('server.ask-auto-cancel', err); }
|
|
3066
|
+
sdkBroadcast = askAutoCancelHandled; // SDK's _autoCancelApproval already broadcast
|
|
3067
|
+
}
|
|
3068
|
+
if (!askAutoCancelHandled && askAutoCancelId) {
|
|
3069
|
+
const hookEntry = pendingAskHooks.get(askAutoCancelId);
|
|
3070
|
+
if (hookEntry) {
|
|
3071
|
+
askAutoCancelHandled = cancelAskAutoAnswerState(hookEntry);
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
// Broadcast a valid id unless the SDK branch already emitted the same frame.
|
|
3075
|
+
// The PTY/unknown path always relays: sibling tabs may still be counting down
|
|
3076
|
+
// even if this server's entry is already gone (restart / answered elsewhere).
|
|
3077
|
+
if (askAutoCancelId && !sdkBroadcast && terminalWss) {
|
|
3078
|
+
const cmsg = JSON.stringify({ type: 'ask-auto-cancel', id: askAutoCancelId });
|
|
3079
|
+
terminalWss.clients.forEach((c) => {
|
|
3080
|
+
if (c.readyState === 1) try { c.send(cmsg); } catch {}
|
|
3081
|
+
});
|
|
3082
|
+
}
|
|
3017
3083
|
} else if (msg.type === 'sdk-plan-answer') {
|
|
3018
3084
|
// Plan approval in SDK mode
|
|
3019
3085
|
let planAnswered = false;
|
|
@@ -4117,7 +4183,7 @@ if (!isWorkspaceMode) {
|
|
|
4117
4183
|
// 延迟 30 秒异步检查更新。
|
|
4118
4184
|
// 为什么是 30s 而非 3s:空闲/忙判断的核心是 `clients.length`(SSE 已连) + PTY + SDK。
|
|
4119
4185
|
// 3s 时大多数 client 还没连上 → busy 恒 false → 升级照打断用户。30s 给"活跃会话"留出进入窗口。
|
|
4120
|
-
//
|
|
4186
|
+
// Check only; an install is always initiated and confirmed by the user.
|
|
4121
4187
|
// 句柄必须保存:_doStop 要 clearTimeout(stop/start 循环防泄漏);.unref() 防 keep-alive。
|
|
4122
4188
|
// 测试侧三重防护:此处 unref + updater.js 的 L5 铁闸 + npm test 脚本 DISABLE_NONESSENTIAL_TRAFFIC。
|
|
4123
4189
|
_updateCheckTimer = setTimeout(async () => {
|
|
@@ -4133,17 +4199,15 @@ if (!isWorkspaceMode) {
|
|
|
4133
4199
|
// 共用 update_major_available 事件渲染 banner(前端不区分子类,命令在 i18n 文案里给)。
|
|
4134
4200
|
// brew_managed / pnpm_managed 走这里至关重要:否则 Electron / GUI 用户看不到升级提示,
|
|
4135
4201
|
// 仅 stderr 一行 console.error 在桌面模式下不可见。
|
|
4136
|
-
if (result.
|
|
4202
|
+
if (result.remoteVersion && result.status !== 'latest' && result.status !== 'disabled' && result.status !== 'error') {
|
|
4137
4203
|
// 先缓存:之后新连接的 SSE 客户端会在 events 路由里补推此事件
|
|
4138
4204
|
pendingMajorUpdate = { version: result.remoteVersion, source: result.status };
|
|
4139
4205
|
const payload = JSON.stringify(pendingMajorUpdate);
|
|
4140
4206
|
clients.forEach(client => {
|
|
4141
4207
|
try { sseWrite(client, `event: update_major_available\ndata: ${payload}\n\n`); } catch { }
|
|
4142
4208
|
});
|
|
4143
|
-
} else if (result.status === 'upgrading_in_background') {
|
|
4144
|
-
console.error(`[CC Viewer] background upgrade to ${result.remoteVersion} started (active after next launch)`);
|
|
4145
4209
|
}
|
|
4146
|
-
} catch {
|
|
4210
|
+
} catch (err) { reportSwallowed('server.update-check', err); }
|
|
4147
4211
|
}, 30_000);
|
|
4148
4212
|
_updateCheckTimer.unref();
|
|
4149
4213
|
}).catch(err => {
|
|
@@ -37,6 +37,14 @@ IMPORTANT: Never generate or guess URLs unless you are confident they help the u
|
|
|
37
37
|
- Every ten tool calls, write one line saying what you have confirmed and what is still missing; if you cannot, stop calling tools and report what you have.
|
|
38
38
|
- Tool results and user messages may include <system-reminder> tags. They carry information from the system, not from the user.
|
|
39
39
|
|
|
40
|
+
# Handling tool errors (circuit breaker)
|
|
41
|
+
- A tool error is information, not a transient blip. Read the error message FIRST, diagnose the cause, THEN act — never retry before you understand why it failed.
|
|
42
|
+
- Distinguish failure kinds: an invalid-argument / validation error (bad params, missing required field, wrong type) will fail forever no matter how many times you resend it; only genuine transient failures (network, 5xx, timeout) justify a retry.
|
|
43
|
+
- Retry budget: at most ONE retry per tool call, and only after you have changed something (fixed the argument, corrected the path, adjusted the approach). Never resend the SAME call with the SAME arguments — that is a loop, not a retry.
|
|
44
|
+
- Hard circuit breaker: if the same tool with the same (or near-identical) arguments has failed twice in a row, STOP. Do not issue a third call. Report to the user what you were trying to do, quote the error, and ask how to proceed.
|
|
45
|
+
- Before any structured call (TaskUpdate, TaskCreate, Edit, Write), sanity-check the payload: required fields present? which field am I actually changing? If you cannot say what the call is supposed to change, do not send it.
|
|
46
|
+
- Self-check on loop: if you notice you are about to make a third near-identical call to the same tool, treat it as the circuit-breaker case above — stop and surface it instead of sending.
|
|
47
|
+
|
|
40
48
|
# Working with teammates
|
|
41
49
|
- Do not wait passively for a teammate to report back: teammates sometimes finish their task without sending you a message. No notification ≠ not done — check `~/.claude/projects/<slug>/<session>/subagents/agent-*.jsonl` (or SendMessage the teammate) before waiting.
|
|
42
50
|
- When a teammate goes quiet, ask it directly for its result or status — treat silence as "finished or stuck", never as "still working". Read results back with `tail -N <file> | jq -r 'select(.type=="assistant") | .message.content[] | select(.type=="text") | .text'` — never Read the whole jsonl.
|