cc-viewer 1.9.21 → 1.9.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +2 -1
  2. package/cli.js +50 -14
  3. package/dist/assets/{App-C4f2Dpy9.js → App-DEA3HoZr.js} +2 -2
  4. package/dist/assets/{MdxEditorPanel-D7aQDQJp.js → MdxEditorPanel-CTAS2DJv.js} +1 -1
  5. package/dist/assets/{Mobile-D9ekLQFS.js → Mobile-CgVpXvs2.js} +1 -1
  6. package/dist/assets/{ProxyStatsModal-CWpgyVKI.js → ProxyStatsModal-C4sl-cuB.js} +1 -1
  7. package/dist/assets/index-CS47d9oh.js +2 -0
  8. package/dist/assets/seqResourceLoaders-CORH46PN.js +2 -0
  9. package/dist/assets/seqResourceLoaders-v4YzKhTS.css +41 -0
  10. package/dist/index.html +1 -1
  11. package/findcc.js +4 -4
  12. package/node_modules/@ccv/core/src/contentFilter.js +4 -1
  13. package/node_modules/@ccv/core/src/ultraplanTemplates.js +199 -0
  14. package/package.json +1 -1
  15. package/server/i18n.js +97 -14
  16. package/server/interceptor.js +6 -0
  17. package/server/lib/async-write-queue.js +18 -0
  18. package/server/lib/auth.js +11 -3
  19. package/server/lib/base-path.js +89 -18
  20. package/server/lib/base-url.js +209 -0
  21. package/server/lib/ensure-hooks.js +134 -2
  22. package/server/lib/im/im-bridge-core.js +16 -0
  23. package/server/lib/log-management.js +21 -1
  24. package/server/lib/plugin-runtime.js +24 -5
  25. package/server/lib/scheduled-task-executor.js +14 -2
  26. package/server/lib/scheduled-task-store.js +129 -18
  27. package/server/lib/sdk-manager.js +113 -11
  28. package/server/lib/v2/adapter.js +147 -15
  29. package/server/lib/v2/conversation-store.js +9 -0
  30. package/server/lib/v2/journal.js +35 -0
  31. package/server/lib/v2/layout.js +67 -1
  32. package/server/lib/v2/live-feed.js +15 -0
  33. package/server/lib/v2/replay.js +11 -3
  34. package/server/lib/v2/session-select.js +34 -2
  35. package/server/lib/v2/shard-manager.js +249 -0
  36. package/server/lib/v2/v2-writer.js +252 -6
  37. package/server/pty-manager.js +103 -4
  38. package/server/routes/events.js +75 -4
  39. package/server/routes/logs.js +47 -16
  40. package/server/routes/misc.js +15 -5
  41. package/server/routes/scheduled-tasks.js +13 -0
  42. package/server/server.js +123 -23
  43. package/dist/assets/index-CocpEURl.js +0 -2
  44. package/dist/assets/seqResourceLoaders-BhiCEaUt.js +0 -2
  45. package/dist/assets/seqResourceLoaders-DbccWwKz.css +0 -41
package/README.md CHANGED
@@ -156,7 +156,7 @@ Once configured, just use the `claude` command as usual. Visit `http://localhost
156
156
 
157
157
  ### Scheduled tasks
158
158
 
159
- Open **Scheduled tasks** from the (+) menu (chat input bar or terminal toolbar) to run a prompt on a schedule: a preset (hourly / daily / weekdays / weekly), a custom 5-field cron, or a one-off time. Each task either **injects the prompt into the current live session** (queued while busy, exactly as if you typed it) or **spawns a fresh isolated headless session** (SDK mode only) with a clean context.
159
+ Open **Scheduled tasks** from the (+) menu (chat input bar or terminal toolbar) to run a prompt on a schedule: a preset (hourly / daily / weekdays / weekly), a custom 5-field cron, or a one-off time. Each task either **injects the prompt into the current live session** (queued while busy, exactly as if you typed it) or **spawns a fresh isolated headless session** (SDK mode only) with a clean context. The task prompt reuses the UltraPlan input panel: pick an expert template tab (empty template by default, no wrapper) and paste/upload attachments — the wrapper and quoted paths are assembled at fire time.
160
160
 
161
161
  Task definitions and scheduling state live in `preferences.json` (the `scheduledTasks` key) and run history (last 20 per task) in `scheduled-task-runs.json` under the cc-viewer data dir, scheduled in the server's local timezone with a small per-task jitter to avoid on-the-hour stampedes. The server ticks every 10s and claims each fire under a cross-process file lock, so parallel instances / Electron tabs never double-fire. After a restart or a sleep it catches up the single most recent missed run within 7 days (earlier misses are recorded as `missed`, never back-filled one by one).
162
162
 
@@ -214,6 +214,7 @@ cc-viewer works in a single container or on a cloud host where you reach the UI
214
214
  * **Reverse-proxy note:** access control is based on the socket peer address (`X-Forwarded-For` is deliberately not trusted, to prevent spoofing). This does not affect remote admins — they authenticate by token/password, not by IP. It only means "same-container" detection relies on a real loopback connection.
215
215
 
216
216
  * **Design doc:** how local config maps to a cloud database and the cloud-sync model (cloud-authoritative, local read-only fallback) is described in [Config Convergence & Cloud-Sync Advisory](./docs/config-cloud-sync.md) ([中文](./docs/config-cloud-sync.zh.md)). This is a proposal, not yet implemented.
217
+ * **Reverse-proxy base URL:** when the platform maps the port to a public URL with a path prefix (e.g. `https://host.example.com/arca/api/v1/session/{token}`), set `CCV_BASE_URL` to it — prefix routing, WebSocket upgrades, Host allowlisting, and the share/QR links all follow automatically. See [Deploying behind a reverse-proxy URL](./docs/base-url.md) ([中文](./docs/base-url.zh.md)).
217
218
 
218
219
 
219
220
  ### Model-specific system prompts
package/cli.js CHANGED
@@ -15,7 +15,7 @@ import { INJECT_IMPORT, LEGACY_INJECT_IMPORTS, resolveCliPath, resolvePreferredC
15
15
  import { ensureHooks, removeAllManagedHooks } from './server/lib/ensure-hooks.js';
16
16
  import { injectCliJsAt, removeCliJsInjectionAt, INJECT_START as _INJECT_START, INJECT_END as _INJECT_END, buildInjectBlock as _buildInjectBlock } from './server/lib/cli-inject.js';
17
17
  import { inspectShellHook } from './server/lib/shell-hook-inspect.js';
18
- import { normalizeBasePath } from './server/lib/base-path.js';
18
+ import { resolveBaseConfig, externalUrlFromConfig } from './server/lib/base-url.js';
19
19
  import { mergeSettingsIntoArgs } from './server/lib/settings-merge.js';
20
20
  import { splitSdkLaunchArgs, resolveLaunchSystemPrompt, insertBeforeDashDash } from './server/lib/launch-config.js';
21
21
  import { createHardenedCleanup, installWinKeypressFallback } from './server/lib/term-signals.js';
@@ -314,7 +314,7 @@ async function runProxyCommand(args) {
314
314
  let npmCliEntry = null;
315
315
  if (requestedClaude) {
316
316
  const selection = assertUsableClaudeSelection(resolvePreferredClaudeSelection());
317
- if (selection?.isNpmVersion && selection.path.endsWith('.js')) {
317
+ if (selection?.isNpmVersion && (selection.path.endsWith('.js') || selection.path.endsWith('.cjs'))) {
318
318
  npmCliEntry = selection.path;
319
319
  cmd = process.execPath;
320
320
  } else if (selection?.path) {
@@ -614,8 +614,14 @@ async function runCliMode(extraClaudeArgs = [], cwd, noOpen = false) {
614
614
 
615
615
  // 4. 自动打开浏览器
616
616
  const protocol = serverMod.getProtocol();
617
- const basePath = normalizeBasePath(process.env.CCV_BASE_PATH);
618
- const url = `${protocol}://127.0.0.1:${port}${basePath}`;
617
+ const _cfg = resolveBaseConfig();
618
+ const url = `${protocol}://127.0.0.1:${port}${_cfg.basePath}`;
619
+ const _token = serverMod.getAccessToken();
620
+ // CCV_BASE_URL with a host: auto-open and the External line use the public URL (carrying
621
+ // ccv's own ?token= — without it the default token auth makes the remote link a 403 dead
622
+ // link). No request context here, so the scheme is the explicit value or https by default.
623
+ const externalUrl = externalUrlFromConfig(_cfg, { token: _token });
624
+ const openUrl = externalUrl || url;
619
625
  if (!noOpen) {
620
626
  try {
621
627
  // URL 含 & 在 cmd.exe 下会被当命令分隔符切断 query;用 spawn 数组传参避免 shell interpolation。
@@ -627,10 +633,10 @@ async function runCliMode(extraClaudeArgs = [], cwd, noOpen = false) {
627
633
  // would crash. Swallow it here as a best-effort fallback.
628
634
  let child;
629
635
  if (process.platform === 'win32') {
630
- child = spawn('cmd.exe', ['/c', 'start', '""', url], { stdio: 'ignore', detached: true, windowsHide: true });
636
+ child = spawn('cmd.exe', ['/c', 'start', '""', openUrl], { stdio: 'ignore', detached: true, windowsHide: true });
631
637
  } else {
632
638
  const cmd = process.platform === 'darwin' ? 'open' : 'xdg-open';
633
- child = spawn(cmd, [url], { stdio: 'ignore', detached: true });
639
+ child = spawn(cmd, [openUrl], { stdio: 'ignore', detached: true });
634
640
  }
635
641
  child.on('error', () => {});
636
642
  child.unref();
@@ -639,10 +645,10 @@ async function runCliMode(extraClaudeArgs = [], cwd, noOpen = false) {
639
645
 
640
646
  console.log(`CC Viewer:`);
641
647
  console.log(` ➜ Local: ${url}`);
648
+ if (externalUrl) console.log(t('server.startedExternal', { url: externalUrl }));
642
649
  const _lanIps = serverMod.getAllLocalIps();
643
- const _token = serverMod.getAccessToken();
644
650
  for (const _ip of _lanIps) {
645
- console.log(` ➜ Network: ${protocol}://${_ip}:${port}${basePath}?token=${_token}`);
651
+ console.log(` ➜ Network: ${protocol}://${_ip}:${port}${_cfg.basePath}?token=${_token}`);
646
652
  }
647
653
  // 密码登录已启用时,把当前密码打印出来 —— 否则 `ccv --usePassword`(随机密码)在 CLI 模式下
648
654
  // 用户无从得知密码(server.js 的密码打印只在非 CLI 模式生效)。空密码=无防护,给出警告。
@@ -713,6 +719,29 @@ async function runImMode(platformId) {
713
719
  // (manager 拉起的 worker 由 buildChildEnv 已剥离全部 CCV_*,此处对其为 no-op,仅覆盖手动启动路径)。
714
720
  delete process.env.CCV_DISABLE_AUTO_SYSTEM_PROMPT;
715
721
 
722
+ // CodeFuse config-dir fallback: when the worker is launched directly (not via
723
+ // the CodeFuse engine), CLAUDE_CONFIG_DIR is unset and Claude would fall back
724
+ // to ~/.claude/ — which may lack .claude.json and trigger the first-run
725
+ // onboarding/trust dialogs. Probe the known CodeFuse config dirs and pin the
726
+ // one that already has a .claude.json so the worker inherits the engine's
727
+ // pre-seeded trust state. This MUST happen before runCliMode so that
728
+ // ensureHooks() writes to the same directory the child will read.
729
+ if (!process.env.CLAUDE_CONFIG_DIR) {
730
+ const { homedir } = await import('node:os');
731
+ const { join } = await import('node:path');
732
+ const { existsSync } = await import('node:fs');
733
+ const home = homedir();
734
+ const candidates = [
735
+ process.env.CCV_CODEFUSE_ENGINE_CC,
736
+ join(home, '.codefuse', 'engine', 'cc'),
737
+ join(home, '.codefuse', 'fuse', 'engine', 'cc'),
738
+ ];
739
+ const cfEngineCc = candidates.find((p) => p && existsSync(join(p, '.claude.json')));
740
+ if (cfEngineCc) {
741
+ process.env.CLAUDE_CONFIG_DIR = cfEngineCc;
742
+ }
743
+ }
744
+
716
745
  // worker 全自动:skip-permissions + 不开浏览器,工作目录设为 IM_<id>/
717
746
  return runCliMode(['--dangerously-skip-permissions'], dir, true);
718
747
  }
@@ -920,6 +949,7 @@ async function runSdkMode(extraClaudeArgs = [], cwd, noOpen = false) {
920
949
  serverMod.setSdkGetContextUsageSnapshot(sdkManager.getContextUsageSnapshot);
921
950
  serverMod.setSdkGetMcpStatusSnapshot(sdkManager.getMcpStatusSnapshot);
922
951
  serverMod.setSdkGetSessionStateSnapshot(sdkManager.getSessionStateSnapshot);
952
+ serverMod.setSdkGetSdkTaskSnapshot(sdkManager.getSdkTaskSnapshot);
923
953
  // Busy-queue bubble actions (queue-send-now / queue-remove / queue-clear / replay).
924
954
  serverMod.setSdkSendQueuedNow(sdkManager.sendQueuedNow);
925
955
  serverMod.setSdkRemoveQueued(sdkManager.removeQueued);
@@ -958,8 +988,14 @@ async function runSdkMode(extraClaudeArgs = [], cwd, noOpen = false) {
958
988
 
959
989
  // 自动打开浏览器
960
990
  const protocol = serverMod.getProtocol();
961
- const basePath = normalizeBasePath(process.env.CCV_BASE_PATH);
962
- const url = `${protocol}://127.0.0.1:${port}${basePath}`;
991
+ const _cfg = resolveBaseConfig();
992
+ const url = `${protocol}://127.0.0.1:${port}${_cfg.basePath}`;
993
+ const _token = serverMod.getAccessToken();
994
+ // CCV_BASE_URL with a host: auto-open and the External line use the public URL (carrying
995
+ // ccv's own ?token= — without it the default token auth makes the remote link a 403 dead
996
+ // link). No request context here, so the scheme is the explicit value or https by default.
997
+ const externalUrl = externalUrlFromConfig(_cfg, { token: _token });
998
+ const openUrl = externalUrl || url;
963
999
  if (!noOpen) {
964
1000
  try {
965
1001
  // URL 含 & 在 cmd.exe 下会被当命令分隔符切断 query;用 spawn 数组传参避免 shell interpolation。
@@ -971,10 +1007,10 @@ async function runSdkMode(extraClaudeArgs = [], cwd, noOpen = false) {
971
1007
  // would crash. Swallow it here as a best-effort fallback.
972
1008
  let child;
973
1009
  if (process.platform === 'win32') {
974
- child = spawn('cmd.exe', ['/c', 'start', '""', url], { stdio: 'ignore', detached: true, windowsHide: true });
1010
+ child = spawn('cmd.exe', ['/c', 'start', '""', openUrl], { stdio: 'ignore', detached: true, windowsHide: true });
975
1011
  } else {
976
1012
  const cmd = process.platform === 'darwin' ? 'open' : 'xdg-open';
977
- child = spawn(cmd, [url], { stdio: 'ignore', detached: true });
1013
+ child = spawn(cmd, [openUrl], { stdio: 'ignore', detached: true });
978
1014
  }
979
1015
  child.on('error', () => {});
980
1016
  child.unref();
@@ -983,10 +1019,10 @@ async function runSdkMode(extraClaudeArgs = [], cwd, noOpen = false) {
983
1019
 
984
1020
  console.log(`CC Viewer (SDK mode):`);
985
1021
  console.log(` ➜ Local: ${url}`);
1022
+ if (externalUrl) console.log(t('server.startedExternal', { url: externalUrl }));
986
1023
  const _lanIps = serverMod.getAllLocalIps();
987
- const _token = serverMod.getAccessToken();
988
1024
  for (const _ip of _lanIps) {
989
- console.log(` ➜ Network: ${protocol}://${_ip}:${port}${basePath}?token=${_token}`);
1025
+ console.log(` ➜ Network: ${protocol}://${_ip}:${port}${_cfg.basePath}?token=${_token}`);
990
1026
  }
991
1027
  // 密码登录已启用时,把当前密码打印出来 —— 否则 `ccv --usePassword`(随机密码)在 CLI 模式下
992
1028
  // 用户无从得知密码(server.js 的密码打印只在非 CLI 模式生效)。空密码=无防护,给出警告。