cc-viewer 1.9.0 → 1.9.2
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 +3 -1
- package/cli.js +33 -4
- package/concepts/ar/UltraPlan.md +1 -1
- package/concepts/da/UltraPlan.md +1 -1
- package/concepts/de/UltraPlan.md +1 -1
- package/concepts/en/UltraPlan.md +1 -1
- package/concepts/es/UltraPlan.md +1 -1
- package/concepts/fr/UltraPlan.md +1 -1
- package/concepts/it/UltraPlan.md +1 -1
- package/concepts/ja/UltraPlan.md +1 -1
- package/concepts/ko/UltraPlan.md +1 -1
- package/concepts/no/UltraPlan.md +1 -1
- package/concepts/pl/UltraPlan.md +1 -1
- package/concepts/pt-BR/UltraPlan.md +1 -1
- package/concepts/ru/UltraPlan.md +1 -1
- package/concepts/th/UltraPlan.md +1 -1
- package/concepts/tr/UltraPlan.md +1 -1
- package/concepts/uk/UltraPlan.md +1 -1
- package/concepts/zh/UltraPlan.md +1 -1
- package/concepts/zh-TW/UltraPlan.md +1 -1
- package/dist/assets/App-DJ4yNvwz.css +1 -0
- package/dist/assets/App-DPRn6oGn.js +2 -0
- package/dist/assets/{MdxEditorPanel-3j8rS3IT.js → MdxEditorPanel-Ci4ldhd7.js} +1 -1
- package/dist/assets/{MdxEditorPanel-Dpn-4ydO.css → MdxEditorPanel-DTfdj6GS.css} +1 -1
- package/dist/assets/Mobile-Dq-KcO1s.js +1 -0
- package/dist/assets/ProxyStatsModal-CUFpqt1s.js +1 -0
- package/dist/assets/{_baseUniq-B3e4JaL0.js → _baseUniq-CwQykUuc.js} +1 -1
- package/dist/assets/{arc-DnoPn_qY.js → arc-EdUdBxtG.js} +1 -1
- package/dist/assets/{architectureDiagram-Q4EWVU46-DrPKTbxH.js → architectureDiagram-Q4EWVU46-DtBIdElY.js} +1 -1
- package/dist/assets/{blockDiagram-DXYQGD6D-CEaO0Vcw.js → blockDiagram-DXYQGD6D-guNZIKkZ.js} +1 -1
- package/dist/assets/{c4Diagram-AHTNJAMY-BLaawFeg.js → c4Diagram-AHTNJAMY-xV5vB-Z9.js} +1 -1
- package/dist/assets/{channel-DnYR1fF4.js → channel-DYEktNap.js} +1 -1
- package/dist/assets/{chunk-4BX2VUAB-Bfd4edKZ.js → chunk-4BX2VUAB-ZTkItpvj.js} +1 -1
- package/dist/assets/{chunk-4TB4RGXK-t2nMQmY7.js → chunk-4TB4RGXK-dYIewyyR.js} +1 -1
- package/dist/assets/{chunk-55IACEB6-C6tLOjGX.js → chunk-55IACEB6-CSsPNgPX.js} +1 -1
- package/dist/assets/{chunk-EDXVE4YY-dWCvxbCb.js → chunk-EDXVE4YY-CnMiuqzQ.js} +1 -1
- package/dist/assets/{chunk-FMBD7UC4-BHELZLPK.js → chunk-FMBD7UC4-CVpATPZ3.js} +1 -1
- package/dist/assets/{chunk-OYMX7WX6-C8XTkH1S.js → chunk-OYMX7WX6-Dpq4s8dW.js} +1 -1
- package/dist/assets/{chunk-QZHKN3VN-CD0j6SAs.js → chunk-QZHKN3VN-Bnojh6X6.js} +1 -1
- package/dist/assets/{chunk-YZCP3GAM-D4dKfXJJ.js → chunk-YZCP3GAM-BYqK4Dsa.js} +1 -1
- package/dist/assets/classDiagram-6PBFFD2Q-ClGF33bF.js +1 -0
- package/dist/assets/classDiagram-v2-HSJHXN6E-ClGF33bF.js +1 -0
- package/dist/assets/clone-CFj55h49.js +1 -0
- package/dist/assets/{cose-bilkent-S5V4N54A-BF2HsiSD.js → cose-bilkent-S5V4N54A-OJ7mmWyV.js} +1 -1
- package/dist/assets/{dagre-KV5264BT-f3h967yx.js → dagre-KV5264BT-B1Kwd_Rk.js} +1 -1
- package/dist/assets/{diagram-5BDNPKRD-B9PzHQfh.js → diagram-5BDNPKRD-D8qrw8sp.js} +1 -1
- package/dist/assets/{diagram-G4DWMVQ6-kR953Bqm.js → diagram-G4DWMVQ6-ip-N4ho8.js} +1 -1
- package/dist/assets/{diagram-MMDJMWI5-DAewa2eg.js → diagram-MMDJMWI5-2PZaskUF.js} +1 -1
- package/dist/assets/{diagram-TYMM5635-C8HNTH6I.js → diagram-TYMM5635-CeAOQUZP.js} +1 -1
- package/dist/assets/{erDiagram-SMLLAGMA-BQ5P8wWK.js → erDiagram-SMLLAGMA-BCBaEYEb.js} +1 -1
- package/dist/assets/{flowDiagram-DWJPFMVM-BIpEkrMR.js → flowDiagram-DWJPFMVM-CsGyIqcX.js} +1 -1
- package/dist/assets/{ganttDiagram-T4ZO3ILL-CWqSfB5v.js → ganttDiagram-T4ZO3ILL-COsj3FZ-.js} +1 -1
- package/dist/assets/{gitGraphDiagram-UUTBAWPF-Ba-9yEbQ.js → gitGraphDiagram-UUTBAWPF-DvQVQGJG.js} +1 -1
- package/dist/assets/{graph-D3zXKQ6P.js → graph-BSB9fDSP.js} +1 -1
- package/dist/assets/index-BLzca-ta.css +1 -0
- package/dist/assets/{index-G3xd-gLo.js → index-BRw4Iz2O.js} +1 -1
- package/dist/assets/{index-DClD_EkN.js → index-Bo-12bug.js} +1 -1
- package/dist/assets/{index-DSd5P3WQ.js → index-BuVComcY.js} +1 -1
- package/dist/assets/{index-HLrnYsI1.js → index-CNNAYjkF.js} +1 -1
- package/dist/assets/index-Ci38xZiX.js +2 -0
- package/dist/assets/{index-Bm3A5VLb.js → index-DKufsAzx.js} +1 -1
- package/dist/assets/{index-C9N0rZ7Z.js → index-DXBfwPYD.js} +1 -1
- package/dist/assets/{index-Q8wp4Nof.js → index-eM2ih5n7.js} +1 -1
- package/dist/assets/{infoDiagram-42DDH7IO-Cxm79ZJR.js → infoDiagram-42DDH7IO-eNucS4iW.js} +1 -1
- package/dist/assets/{ishikawaDiagram-UXIWVN3A-Cd0vZP1B.js → ishikawaDiagram-UXIWVN3A-Dxxj-gUX.js} +1 -1
- package/dist/assets/{journeyDiagram-VCZTEJTY-B2b57HXk.js → journeyDiagram-VCZTEJTY-yJJzVEBb.js} +1 -1
- package/dist/assets/{jszip.min-Bj5uiEb2.js → jszip.min-ByI0ds5u.js} +1 -1
- package/dist/assets/{kanban-definition-6JOO6SKY-YCERiUCO.js → kanban-definition-6JOO6SKY-2rfTi2zw.js} +1 -1
- package/dist/assets/{layout-Do5TlO2U.js → layout-DTmHj0Wm.js} +1 -1
- package/dist/assets/{linear-BiJNTDgN.js → linear-BOA3a9FE.js} +1 -1
- package/dist/assets/{mermaid.core-Dg0McRZt.js → mermaid.core-5H-NR79H.js} +3 -3
- package/dist/assets/{min-T51iefht.js → min-CpjFTEec.js} +1 -1
- package/dist/assets/{mindmap-definition-QFDTVHPH-Cu_GJxY3.js → mindmap-definition-QFDTVHPH-B8KCjFgB.js} +1 -1
- package/dist/assets/{pieDiagram-DEJITSTG-DldHHZXi.js → pieDiagram-DEJITSTG-BARy96g5.js} +1 -1
- package/dist/assets/{quadrantDiagram-34T5L4WZ-BzyTPNAJ.js → quadrantDiagram-34T5L4WZ-DYoTapuI.js} +1 -1
- package/dist/assets/{requirementDiagram-MS252O5E-C5xxFkvG.js → requirementDiagram-MS252O5E-EeANLLK2.js} +1 -1
- package/dist/assets/{sankeyDiagram-XADWPNL6-OxdjoaE1.js → sankeyDiagram-XADWPNL6-DmQ-YVPj.js} +1 -1
- package/dist/assets/seqResourceLoaders-B0p7e_lM.js +2 -0
- package/dist/assets/seqResourceLoaders-BsMFNfvR.css +41 -0
- package/dist/assets/{sequenceDiagram-FGHM5R23-C7c89uIS.js → sequenceDiagram-FGHM5R23-SZtW0rYC.js} +1 -1
- package/dist/assets/{stateDiagram-FHFEXIEX-ssdJnDrO.js → stateDiagram-FHFEXIEX-CEygsIld.js} +1 -1
- package/dist/assets/{stateDiagram-v2-QKLJ7IA2-BP-0WClK.js → stateDiagram-v2-QKLJ7IA2-BU1XPhBe.js} +1 -1
- package/dist/assets/{timeline-definition-GMOUNBTQ-sWScEpSM.js → timeline-definition-GMOUNBTQ-DhPBaQBt.js} +1 -1
- package/dist/assets/{vendor-antd-DKIytXho.js → vendor-antd-CS_S2mBN.js} +1 -1
- package/dist/assets/{vendor-codemirror-4qgXq03k.js → vendor-codemirror-B5l-VbBO.js} +1 -1
- package/dist/assets/{vendor-mdxeditor-D5Z5D9fq.js → vendor-mdxeditor-Cz09a1_I.js} +2 -2
- package/dist/assets/{vendor-qrcode-B7lb5qk1.js → vendor-qrcode-qbbntD6-.js} +1 -1
- package/dist/assets/{vendor-virtuoso-BqoXlbhH.js → vendor-virtuoso-Sk8fQ4Hx.js} +1 -1
- package/dist/assets/{vennDiagram-DHZGUBPP-DNfXR0ge.js → vennDiagram-DHZGUBPP-NniTHxDw.js} +1 -1
- package/dist/assets/{wardley-RL74JXVD-JXd--CRD.js → wardley-RL74JXVD-D9SNOrDw.js} +1 -1
- package/dist/assets/{wardleyDiagram-NUSXRM2D-DHmNyVPM.js → wardleyDiagram-NUSXRM2D-DvHXKNza.js} +1 -1
- package/dist/assets/{xychartDiagram-5P7HB3ND-CTb0gltZ.js → xychartDiagram-5P7HB3ND-CaiwPTQB.js} +1 -1
- package/dist/index.html +5 -5
- package/package.json +1 -1
- package/server/interceptor.js +192 -24
- package/server/lib/ask/ask-store.js +7 -3
- package/server/lib/async-file-lock.js +29 -5
- package/server/lib/auth.js +71 -54
- package/server/lib/chat-queue.js +67 -4
- package/server/lib/config-backup.js +8 -5
- package/server/lib/credential-access.js +233 -0
- package/server/lib/credential-migrate.js +147 -0
- package/server/lib/credential-store.js +120 -0
- package/server/lib/credential-vault.js +112 -0
- package/server/lib/file-access-policy.js +16 -0
- package/server/lib/git-diff.js +49 -20
- package/server/lib/im/im-config.js +81 -31
- package/server/lib/im-deny.js +22 -8
- package/server/lib/json-store.js +264 -0
- package/server/lib/log-watcher.js +9 -1
- package/server/lib/prefs-store.js +8 -33
- package/server/lib/same-origin.js +22 -0
- package/server/lib/session-pin-store.js +7 -14
- package/server/lib/v2/convert.js +1 -1
- package/server/lib/v2/layout.js +53 -3
- package/server/lib/v2/live-feed.js +41 -4
- package/server/lib/v2/resume-list.js +150 -0
- package/server/lib/v2/session-select.js +63 -14
- package/server/lib/v2/v2-writer.js +172 -34
- package/server/lib/v2/view-router.js +83 -0
- package/server/lib/view-root.js +209 -0
- package/server/pty-manager.js +809 -163
- package/server/routes/ask-perm.js +21 -1
- package/server/routes/auth.js +21 -1
- package/server/routes/events.js +123 -7
- package/server/routes/expert.js +46 -14
- package/server/routes/files-content.js +72 -7
- package/server/routes/files-fs.js +28 -3
- package/server/routes/git.js +31 -5
- package/server/routes/im.js +15 -2
- package/server/routes/preferences.js +59 -46
- package/server/routes/project-meta.js +32 -3
- package/server/routes/proxy-stats.js +33 -5
- package/server/routes/resume.js +457 -0
- package/server/routes/search.js +23 -1
- package/server/routes/skills.js +18 -2
- package/server/routes/v2.js +6 -1
- package/server/routes/workspaces.js +18 -5
- package/server/server.js +199 -25
- package/server/system-prompt-templates/presets/GLM-5.2.md +0 -1
- package/server/system-prompt-templates/presets/GLM-5.3.md +0 -1
- package/server/system-prompt-templates/presets/Qwen-3.md +0 -1
- package/server/system-prompt-templates/presets/deepseek-v4-flash.md +0 -1
- package/server/system-prompt-templates/presets/deepseek-v4-pro.md +0 -1
- package/server/system-prompt-templates/presets/kimi-k2.7-code.md +0 -1
- package/server/system-prompt-templates/presets/kimi-k3.md +1 -1
- package/server/system-prompt-templates/systemPromptModel.md +0 -1
- package/server/workspace-registry.js +150 -75
- package/ultraAgents/code-expert.json +1 -1
- package/dist/assets/App-M61pqQEx.css +0 -1
- package/dist/assets/App-_HfxMJvv.js +0 -2
- package/dist/assets/Mobile-DaRLB7Gh.js +0 -1
- package/dist/assets/ProxyStatsModal-dlPIDlx-.js +0 -1
- package/dist/assets/classDiagram-6PBFFD2Q-BecPAAuk.js +0 -1
- package/dist/assets/classDiagram-v2-HSJHXN6E-BecPAAuk.js +0 -1
- package/dist/assets/clone-B0_ghF3F.js +0 -1
- package/dist/assets/index-CjbBUDGP.js +0 -2
- package/dist/assets/index-Nvk8r3tO.css +0 -1
- package/dist/assets/seqResourceLoaders-B_FSQh3U.css +0 -41
- package/dist/assets/seqResourceLoaders-hqLhsiGO.js +0 -2
|
@@ -3,7 +3,7 @@ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
|
3
3
|
import { join, dirname } from 'node:path';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { LOG_DIR, setLogDir, getClaudeConfigDir, discoverClaudeExecutables, resolveExplicitClaudePath, CLAUDE_EXECUTABLE_PREF_KEY } from '../../findcc.js';
|
|
6
|
-
import { PROFILE_PATH, _defaultConfig, getActiveProfileId, getStoredRoles, isOfficialDefaultEndpoint, setActiveProfileForWorkspace, _loadProxyProfile, RETRY_CONFIG_PATH, _retryConfigState, _loadRetryConfigState } from '../interceptor.js';
|
|
6
|
+
import { PROFILE_PATH, _defaultConfig, getActiveProfileId, getStoredRoles, isOfficialDefaultEndpoint, setActiveProfileForWorkspace, _loadProxyProfile, hydrateProfilesWithApiKeys, RETRY_CONFIG_PATH, _retryConfigState, _loadRetryConfigState } from '../interceptor.js';
|
|
7
7
|
import { migrateProxyProfileList, isValidRoleValue, PROXY_ROLE_KEYS } from '../lib/interceptor-core.js';
|
|
8
8
|
import { DEFAULT_RETRY_CONFIG, validateRetryConfig, resolveRetryConfig } from '../lib/proxy/proxy-retry.js';
|
|
9
9
|
import { discoverCcSwitchProviders, mergeImportedProfiles } from '../lib/ccswitch-import.js';
|
|
@@ -15,7 +15,10 @@ import { inspectShellHook } from '../lib/shell-hook-inspect.js';
|
|
|
15
15
|
import { sendEventToClients } from '../lib/log-watcher.js';
|
|
16
16
|
import { listPlatforms } from '../lib/im/im-config.js';
|
|
17
17
|
import { mutatePrefs, applyPrefsPatch, readPrefsRaw } from '../lib/prefs-store.js';
|
|
18
|
+
import { mutateJsonSync } from '../lib/json-store.js';
|
|
19
|
+
import { persistProfilesApiKeys } from '../lib/credential-access.js';
|
|
18
20
|
import { isAdminReq } from '../lib/is-admin.js';
|
|
21
|
+
import { isSameOriginBrowserRequest } from '../lib/same-origin.js';
|
|
19
22
|
import {
|
|
20
23
|
getCurrentProjectKey, getCurrentProjectName, hasFork, listForks, resolveScoped,
|
|
21
24
|
} from '../lib/project-prefs.js';
|
|
@@ -27,22 +30,6 @@ function stripImConfigs(obj) {
|
|
|
27
30
|
if (obj) for (const id of listPlatforms()) delete obj[id];
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
// Loopback identifies the socket peer, not the browser page that initiated a
|
|
31
|
-
// request. Since the server intentionally has permissive CORS for legacy APIs,
|
|
32
|
-
// sensitive executable-selection endpoints need their own same-origin guard.
|
|
33
|
-
function isSameOriginBrowserRequest(req, parsedUrl) {
|
|
34
|
-
const origin = req.headers?.origin;
|
|
35
|
-
if (!origin) return true; // CLI/native clients do not send Origin.
|
|
36
|
-
if (req.headers?.['sec-fetch-site'] === 'cross-site') return false;
|
|
37
|
-
try {
|
|
38
|
-
const originUrl = new URL(origin);
|
|
39
|
-
if (parsedUrl?.origin) return originUrl.origin.toLowerCase() === parsedUrl.origin.toLowerCase();
|
|
40
|
-
return originUrl.host.toLowerCase() === String(req.headers?.host || '').toLowerCase();
|
|
41
|
-
} catch {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
33
|
// /theme 选择器特征:选项文案高特异、不太可能出现在普通生成输出里(ESC 兜底的门控签名)
|
|
47
34
|
const THEME_PICKER_RE = /Auto \(match terminal\)|colorblind-friendly/;
|
|
48
35
|
|
|
@@ -163,12 +150,18 @@ function preferencesPost(req, res, parsedUrl, isLocal, deps) {
|
|
|
163
150
|
// 切日志目录:把旧文件的完整内容(含 auth 密码 / prefsByProject forks / 其它偏好)带到新位置,
|
|
164
151
|
// 避免切目录后密码与各项目 fork 凭空消失;并把写目标在 setLogDir 前后固定为"新文件",让本次
|
|
165
152
|
// 合并只跑在一个文件 / 一把锁上(不再因 LOG_DIR 中途漂移而劈裂进程内锁队列)。
|
|
153
|
+
// logDir 是机器全局、可改变进程数据根的操作(移动 vault 根会影响 LAN 门与代理注入),
|
|
154
|
+
// 因此只允许 admin(本机 loopback 或已鉴权远程 admin)触发——未鉴权远程/项目客户端直接剥掉。
|
|
166
155
|
let targetFile = deps.getPrefsFile();
|
|
167
156
|
let carried = null;
|
|
168
157
|
if (incoming.logDir && typeof incoming.logDir === 'string') {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
158
|
+
if (!isAdminReq(req, isLocal)) {
|
|
159
|
+
delete incoming.logDir; // non-admin cannot move the data root (would open the LAN gate)
|
|
160
|
+
} else {
|
|
161
|
+
carried = readPrefsRaw(targetFile); // 旧文件全量(锁外读,迁移属罕见 admin 操作)
|
|
162
|
+
setLogDir(incoming.logDir);
|
|
163
|
+
targetFile = deps.getPrefsFile();
|
|
164
|
+
}
|
|
172
165
|
}
|
|
173
166
|
// 全局写入:locked + atomic(prefs-store),与 fork 写共用同一把锁,避免并发写互相覆盖含密码的
|
|
174
167
|
// preferences.json。Deep-merge approvalModal 的逻辑下沉到 applyPrefsPatch,与 /api/project-prefs
|
|
@@ -310,14 +303,28 @@ function proxyProfilesGet(req, res, parsedUrl, isLocal, deps) {
|
|
|
310
303
|
if (Array.isArray(data.profiles)) {
|
|
311
304
|
const { profiles: migrated, changed } = migrateProxyProfileList(data.profiles);
|
|
312
305
|
if (changed) {
|
|
313
|
-
data = { ...data, profiles: migrated };
|
|
314
306
|
try {
|
|
315
|
-
|
|
316
|
-
|
|
307
|
+
// Write the migration back while pulling apiKeys into the vault (so the old plaintext is
|
|
308
|
+
// never re-persisted). Read-merge-write INSIDE the lock (mutateJsonSync mutates in place
|
|
309
|
+
// and the kernel writes back the same reference), mutexed with the startup credential-strip
|
|
310
|
+
// and proxyProfilesPost.
|
|
311
|
+
mutateJsonSync(PROFILE_PATH, (current) => {
|
|
312
|
+
const base = (current && typeof current === 'object' && !Array.isArray(current)) ? current : {};
|
|
313
|
+
const stripped = persistProfilesApiKeys(migrated, null, { isMaskedFn: () => false });
|
|
314
|
+
base.profiles = stripped;
|
|
315
|
+
return base;
|
|
316
|
+
}, { mode: 0o600, strictCorrupt: true, fallback: {} });
|
|
317
|
+
data = { ...data, profiles: migrated };
|
|
317
318
|
_loadProxyProfile();
|
|
318
319
|
} catch { /* 迁移落盘失败不阻塞 GET;下次仍会尝试 */ }
|
|
319
320
|
}
|
|
320
321
|
}
|
|
322
|
+
// profile.json no longer carries apiKeys (they live in the credential vault) — decrypt-backfill
|
|
323
|
+
// them onto the list for serving. The local admin gets plaintext to view/copy; a remote caller
|
|
324
|
+
// is masked by deps.maskProfiles below (same as before).
|
|
325
|
+
if (Array.isArray(data.profiles)) {
|
|
326
|
+
data = { ...data, profiles: hydrateProfilesWithApiKeys(data.profiles) };
|
|
327
|
+
}
|
|
321
328
|
// 用 interceptor.getActiveProfileId() 返回 effective active(workspace > profile.json.active > 'max')
|
|
322
329
|
const effectiveActive = getActiveProfileId();
|
|
323
330
|
// 本机(127.0.0.1)= admin:下发明文 profile.apiKey 供本人在编辑表单(👁 折叠)里查阅/复制;已授权
|
|
@@ -353,22 +360,21 @@ function proxyProfilesPost(req, res, parsedUrl, isLocal, deps) {
|
|
|
353
360
|
if (!incoming.profiles.some(p => p.id === 'max')) {
|
|
354
361
|
incoming.profiles = [{ id: 'max', name: 'Default' }, ...(incoming.profiles || [])];
|
|
355
362
|
}
|
|
356
|
-
//
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
writeFileSync(PROFILE_PATH, JSON.stringify(toWrite, null, 2), { mode: 0o600 });
|
|
363
|
+
// Only the profiles list is written to profile.json; `active` is no longer persisted here
|
|
364
|
+
// (avoids cross-process clobbering). The existing file's `active` field is preserved so an
|
|
365
|
+
// older ccv or a hand editor can still fall back to it. Read-merge-write INSIDE the lock
|
|
366
|
+
// (mutateJsonSync), mutexed with the startup credential-strip and setActiveProfileForWorkspace —
|
|
367
|
+
// an unlocked snapshot would let persistProfilesApiKeys' deletion loop remove concurrently-added
|
|
368
|
+
// vault entries and overwrite the whole list.
|
|
369
|
+
// apiKey 抽出到凭证 vault(密文存 credentials.json),profile.json 不再携带 key。
|
|
370
|
+
// masked 回显 → 保留该 profile 的既有 vault 条目(不动、不回写 sentinel);
|
|
371
|
+
// 新明文 → 写 vault;空 → 删该条目;被移除的 profile(全量替换端点)→ 删其 vault 条目。
|
|
372
|
+
mutateJsonSync(PROFILE_PATH, (current) => {
|
|
373
|
+
const existing = (current && typeof current === 'object' && !Array.isArray(current)) ? current : {};
|
|
374
|
+
const strippedProfiles = persistProfilesApiKeys(incoming.profiles, existing.profiles, { isMaskedFn: deps.isMasked });
|
|
375
|
+
existing.profiles = strippedProfiles;
|
|
376
|
+
return existing;
|
|
377
|
+
}, { mode: 0o600, strictCorrupt: true, fallback: {} });
|
|
372
378
|
// 角色分配校验:只认 subagent/teammate 两个 key(roles.main 之类的杂键直接丢弃);
|
|
373
379
|
// 值必须是 follow / max / 入参 profiles 里存在的 id(按将落盘的列表校验,而非旧文件),
|
|
374
380
|
// 非法值归 'follow'(宽容风格,不 400)。被删 profile 的悬空角色由读取时归 follow 兜底。
|
|
@@ -541,13 +547,20 @@ async function ccswitchImportPost(req, res, _parsedUrl, isLocal, deps) {
|
|
|
541
547
|
}
|
|
542
548
|
existing = parsed;
|
|
543
549
|
}
|
|
544
|
-
// merge
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
//
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
550
|
+
// Persist: locked read-merge-write (mutateJsonSync), mutexed with the other profile.json
|
|
551
|
+
// writers. The merge MUST be recomputed inside the lock against the CURRENT on-disk list —
|
|
552
|
+
// computing it outside from a pre-lock snapshot and overwriting the whole list would erase a
|
|
553
|
+
// proxy-profiles POST that lands in that window. apiKeys are pulled into the vault; merge
|
|
554
|
+
// semantics never delete existing vault entries (no existingProfiles passed). cc-switch imports
|
|
555
|
+
// fresh plaintext keys (not a masked echo), so isMaskedFn is always false. `merged` is read
|
|
556
|
+
// back out of the lock for the response counts.
|
|
557
|
+
let merged = null;
|
|
558
|
+
mutateJsonSync(PROFILE_PATH, (current) => {
|
|
559
|
+
const base = (current && typeof current === 'object' && !Array.isArray(current)) ? current : {};
|
|
560
|
+
merged = mergeImportedProfiles(base.profiles || [], result.profiles);
|
|
561
|
+
base.profiles = persistProfilesApiKeys(merged.profiles, null, { isMaskedFn: () => false });
|
|
562
|
+
return base;
|
|
563
|
+
}, { mode: 0o600, strictCorrupt: true, fallback: {} });
|
|
551
564
|
// active 处理:setActive=true 且 cc-switch 有 current → 切换;否则保持现状
|
|
552
565
|
let activeChanged = false;
|
|
553
566
|
if (setActive && result.currentId) {
|
|
@@ -4,8 +4,32 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { PACKAGE_JSON } from '../_paths.js';
|
|
5
5
|
import { LOG_DIR } from '../../findcc.js';
|
|
6
6
|
import { _projectName } from '../interceptor.js';
|
|
7
|
+
import { sanitizePathComponent } from '../lib/v2/layout.js';
|
|
8
|
+
import { resolveViewRoot } from '../lib/view-root.js';
|
|
9
|
+
import { loadWorkspaces } from '../workspace-registry.js';
|
|
10
|
+
import { listLivePtys } from '../pty-manager.js';
|
|
7
11
|
import { detectHomebrewInstall } from '../lib/updater.js';
|
|
8
12
|
|
|
13
|
+
// Multi-project (2026-10, review P2-6): stats reads for a VIEWED project must
|
|
14
|
+
// not become a presence oracle over LOG_DIR — `?project=` is accepted ONLY
|
|
15
|
+
// when it resolves to a registered workspace / live PTY (or the bound
|
|
16
|
+
// project), never an arbitrary sanitized name.
|
|
17
|
+
function _resolveStatsName(projectParam, res) {
|
|
18
|
+
if (!projectParam) return _projectName || '';
|
|
19
|
+
const r = resolveViewRoot({
|
|
20
|
+
projectParam,
|
|
21
|
+
boundCwd: process.env.CCV_PROJECT_DIR || process.cwd(),
|
|
22
|
+
loadWorkspaces,
|
|
23
|
+
listLivePtys,
|
|
24
|
+
});
|
|
25
|
+
if (!r.ok) {
|
|
26
|
+
res.writeHead(r.status, { 'Content-Type': 'application/json' });
|
|
27
|
+
res.end(JSON.stringify({ error: r.error }));
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return sanitizePathComponent(projectParam);
|
|
31
|
+
}
|
|
32
|
+
|
|
9
33
|
// 判定当前 cc-viewer 的安装渠道,供前端精准匹配升级命令。
|
|
10
34
|
// - electron:桌面版(in-process server),走 GitHub Releases 重新下载安装包。
|
|
11
35
|
// - brew:Homebrew Cellar 布局命中 → `brew upgrade cc-viewer`(npm install -g 会跟 Cellar 打架)。
|
|
@@ -44,14 +68,19 @@ function versionInfo(req, res) {
|
|
|
44
68
|
}
|
|
45
69
|
}
|
|
46
70
|
|
|
47
|
-
function projectStats(req, res) {
|
|
71
|
+
function projectStats(req, res, parsedUrl) {
|
|
48
72
|
try {
|
|
49
|
-
|
|
73
|
+
// Multi-project (2026-10): project-stats resolves the VIEWED project
|
|
74
|
+
// (?project=, registered/live only — never an arbitrary name).
|
|
75
|
+
const projectParam = parsedUrl && parsedUrl.searchParams ? parsedUrl.searchParams.get('project') : null;
|
|
76
|
+
const name = _resolveStatsName(projectParam, res);
|
|
77
|
+
if (name === null) return; // error already replied
|
|
78
|
+
if (!name) {
|
|
50
79
|
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
51
80
|
res.end(JSON.stringify({ error: 'No project name' }));
|
|
52
81
|
return;
|
|
53
82
|
}
|
|
54
|
-
const statsFile = join(LOG_DIR,
|
|
83
|
+
const statsFile = join(LOG_DIR, name, `${name}.json`);
|
|
55
84
|
if (!existsSync(statsFile)) {
|
|
56
85
|
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
57
86
|
res.end(JSON.stringify({ error: 'Stats file not found' }));
|
|
@@ -10,17 +10,45 @@ import { readFileSync, existsSync } from 'node:fs';
|
|
|
10
10
|
import { join } from 'node:path';
|
|
11
11
|
import { LOG_DIR } from '../../findcc.js';
|
|
12
12
|
import { _projectName } from '../interceptor.js';
|
|
13
|
+
import { sanitizePathComponent } from '../lib/v2/layout.js';
|
|
14
|
+
import { resolveViewRoot } from '../lib/view-root.js';
|
|
15
|
+
import { loadWorkspaces } from '../workspace-registry.js';
|
|
16
|
+
import { listLivePtys } from '../pty-manager.js';
|
|
13
17
|
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
|
|
18
|
+
// Multi-project (2026-10, review P2-6): stats reads for a VIEWED project must
|
|
19
|
+
// not become a presence oracle over LOG_DIR — `?project=` is accepted ONLY
|
|
20
|
+
// when it resolves to a registered workspace / live PTY (or the bound
|
|
21
|
+
// project), never an arbitrary sanitized name.
|
|
22
|
+
function _resolveStatsName(projectParam, res) {
|
|
23
|
+
if (!projectParam) return _projectName || '';
|
|
24
|
+
const r = resolveViewRoot({
|
|
25
|
+
projectParam,
|
|
26
|
+
boundCwd: process.env.CCV_PROJECT_DIR || process.cwd(),
|
|
27
|
+
loadWorkspaces,
|
|
28
|
+
listLivePtys,
|
|
29
|
+
});
|
|
30
|
+
if (!r.ok) {
|
|
31
|
+
res.writeHead(r.status, { 'Content-Type': 'application/json' });
|
|
32
|
+
res.end(JSON.stringify({ error: r.error }));
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return sanitizePathComponent(projectParam);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// GET /api/proxy-stats — returns the VIEWED project's proxy retry stats
|
|
39
|
+
// (?project=, registered/live only; the log store is name-keyed, not fs-dir).
|
|
40
|
+
// Response body: { proxyStats: {...} }; null when there is no data.
|
|
41
|
+
function getProxyStats(req, res, parsedUrl) {
|
|
17
42
|
try {
|
|
18
|
-
|
|
43
|
+
const projectParam = parsedUrl && parsedUrl.searchParams ? parsedUrl.searchParams.get('project') : null;
|
|
44
|
+
const name = _resolveStatsName(projectParam, res);
|
|
45
|
+
if (name === null) return; // error already replied
|
|
46
|
+
if (!name) {
|
|
19
47
|
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
20
48
|
res.end(JSON.stringify({ error: 'No project name', proxyStats: null }));
|
|
21
49
|
return;
|
|
22
50
|
}
|
|
23
|
-
const statsFile = join(LOG_DIR,
|
|
51
|
+
const statsFile = join(LOG_DIR, name, `${name}.json`);
|
|
24
52
|
if (!existsSync(statsFile)) {
|
|
25
53
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
26
54
|
res.end(JSON.stringify({ proxyStats: null }));
|