cc-viewer 1.8.14 → 1.8.15

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 (42) hide show
  1. package/README.md +6 -5
  2. package/cli.js +19 -0
  3. package/dist/assets/{App-ZWY7wiA3.js → App-DxDo_tCQ.js} +2 -2
  4. package/dist/assets/{MdxEditorPanel-D89HBOrd.js → MdxEditorPanel-Ddpu5ELR.js} +1 -1
  5. package/dist/assets/{Mobile-CitUOMlD.js → Mobile-DA0yMMgI.js} +1 -1
  6. package/dist/assets/{ProxyStatsModal-B92bNhle.js → ProxyStatsModal-DKKfSpXx.js} +1 -1
  7. package/dist/assets/index-BCpkzaVk.js +2 -0
  8. package/dist/assets/seqResourceLoaders-BkzxH2jr.js +2 -0
  9. package/dist/index.html +1 -1
  10. package/node_modules/@ccv/core/src/context-rules.js +5 -0
  11. package/package.json +1 -1
  12. package/server/i18n.js +2 -2
  13. package/server/interceptor.js +176 -21
  14. package/server/lib/builtin-model-prompts.js +12 -1
  15. package/server/lib/create_system_prompt.js +94 -1
  16. package/server/lib/interceptor-core.js +144 -0
  17. package/server/lib/launch-config.js +83 -3
  18. package/server/lib/model-system-prompts.js +6 -1
  19. package/server/lib/proxy/proxy-retry.js +57 -2
  20. package/server/lib/resume-watchdog.js +108 -0
  21. package/server/lib/session-id.js +33 -0
  22. package/server/lib/shell-hook-inspect.js +48 -0
  23. package/server/lib/system-prompt-files.js +14 -0
  24. package/server/lib/system-prompt-live.js +622 -0
  25. package/server/lib/v2/identity.js +3 -24
  26. package/server/lib/v2/session-select.js +11 -8
  27. package/server/lib/v2/v2-writer.js +13 -5
  28. package/server/proxy.js +32 -6
  29. package/server/routes/events.js +9 -3
  30. package/server/routes/preferences.js +6 -1
  31. package/server/routes/workspaces.js +3 -2
  32. package/server/server.js +33 -5
  33. package/server/system-prompt-templates/presets/GLM-5.2.md +2 -0
  34. package/server/system-prompt-templates/presets/GLM-5.3.md +2 -0
  35. package/server/system-prompt-templates/presets/{Qwen-3.7-Max.md → Qwen-3.md} +3 -1
  36. package/server/system-prompt-templates/presets/deepseek-v4-flash.md +2 -0
  37. package/server/system-prompt-templates/presets/deepseek-v4-pro.md +2 -0
  38. package/server/system-prompt-templates/presets/index.json +7 -7
  39. package/server/system-prompt-templates/presets/kimi-k2.7-code.md +3 -0
  40. package/server/system-prompt-templates/presets/kimi-k3.md +2 -0
  41. package/dist/assets/index-OWc1WNdK.js +0 -2
  42. package/dist/assets/seqResourceLoaders-Bng7YSRv.js +0 -2
package/README.md CHANGED
@@ -210,11 +210,12 @@ cc-viewer works in a single container or on a cloud host where you reach the UI
210
210
 
211
211
  The **Edit System Prompt** modal (hamburger menu → Edit System Prompt) is tabbed:
212
212
 
213
- * The **Default** tab keeps the classic behavior: it writes `CC_SYSTEM.md` (override) or `CC_APPEND_SYSTEM.md` (append) into the current workspace, injected as `--system-prompt-file` / `--append-system-prompt-file` on the next ccv launch.
214
- * **Model tabs**: click **+ Add model**, type a name such as `opus` or `Gemini3`, and pick a scope — **Global** (`~/.claude/cc-viewer/system_prompt/`, applies to every workspace) or **Workspace** (`<project>/system_prompt/`). The name field offers type-ahead suggestions from your locally configured models (hot-reload proxy profiles and `settings.json`); names already added in the chosen scope are hidden, and arbitrary free-form names remain allowed. Each tab has its own Append/Override switch and Markdown preview.
215
- * Entries are stored as uppercase files: `OPUS_SYSTEM.md` (override) or `OPUS_APPEND_SYSTEM.md` (append). Matching is fuzzy — a case-insensitive substring of the model ID resolved from the ACTIVE configuration (an active third-party proxy profile's model mapping > the launch environment's `ANTHROPIC_MODEL`/`CLAUDE_MODEL` > the `model` configured in `settings.json`; with no configuration signal, no entry is injected), so `opus` matches `claude-opus-4-8[1m]` regardless of version. Switching the proxy profile mid-session re-matches only after the claude session is restarted, and a `--model` flag passed through extra args is not consulted (known limitations). A workspace match beats a global one; within a scope the longest name wins; a matched entry fully replaces the Default files for that launch.
216
- * **Built-in presets are default-effective:** the package ships tuned prompts for `deepseek-v4-pro`, `deepseek-v4-flash`, `GLM-5.2`, `Qwen-3.7-Max`, `kimi-k2.7-code` and `kimi-k3` — when the resolved model matches one of them and no entry of yours matches, the built-in prompt is injected automatically (your own files always win: workspace > global > built-in). Built-in tabs carry a **Built-in** badge in the modal: edit and save to materialize your override, or use the tab's × to **disable** a built-in (recorded in `<scope>/system_prompt/.builtin-disabled.json`). A disabled built-in falls back to the Default files, and the header entry stays visible marked "Disabled" so you can re-enable it at any time.
217
- * Saving a tab empty deletes the entry. Model switches made mid-session apply at the next relaunch. Set `CCV_DISABLE_AUTO_SYSTEM_PROMPT=1` to disable all automatic injection. You may commit `<project>/system_prompt/` to share prompts with your team, or add it to `.gitignore` to keep them private.
213
+ * **Default** tab: writes `CC_SYSTEM.md` (override) or `CC_APPEND_SYSTEM.md` (append) into the workspace, injected on the next ccv launch.
214
+ * **Model tabs**: add a model by name (`opus`, `Gemini3`, …) in **Global** (`~/.claude/cc-viewer/system_prompt/`) or **Workspace** (`<project>/system_prompt/`) scope; each tab has its own Append/Override switch and preview. Names match fuzzily against the resolved model ID (so `opus` matches `claude-opus-4-8[1m]`); workspace beats global, longest name wins, a matched entry fully replaces the Default files.
215
+ * **Built-in presets**: tuned system prompts deeply adapted to the Kimi, DeepSeek, Qwen, and GLM families injected automatically when the resolved model matches and no entry of yours does (your files always win). Disable one via its tab's ×.
216
+ * The system text follows hot-switched main models mid-session, pinned per session+model (KV-cache busted once at the switch). Saving a tab empty deletes the entry. Set `CCV_DISABLE_AUTO_SYSTEM_PROMPT=1` to disable all auto-injection, or `CCV_DISABLE_LIVE_SYSTEM_PROMPT=1` to disable only the mid-session follow.
217
+
218
+ **Continuing a session from the terminal:** `claude -c` / `claude -r` only keep the injected system prompt (and therefore the prompt-prefix KV cache) when the request goes through ccv. The shell hook installed by `ccv -logger` routes terminal `claude` calls through ccv — it takes effect in **new terminals** (or after sourcing your rc file). If you bypass it (hook missing, or invoking the claude binary directly), the resume launches with a different system text: the prefix cache is fully rewritten once (it re-warms on the next request; the detection is logged to the browser console). Cache entries also expire ~5 minutes after the last request regardless. When in doubt, continue sessions from the panel's continue entry, which always re-injects the full launch arguments.
218
219
 
219
220
  ### Logger mode (view the complete Claude Code session)
220
221
 
package/cli.js CHANGED
@@ -14,6 +14,7 @@ import { t } from './server/i18n.js';
14
14
  import { INJECT_IMPORT, LEGACY_INJECT_IMPORTS, resolveCliPath, resolvePreferredClaudeSelection, resolveNativePath, buildShellCandidates, setLogDir, LOG_DIR, hasClaude2xWrapper, getGlobalNodeModulesDir, PACKAGES, getClaudeConfigDir, isBrowserOpenSuppressed, applyAgentTeamsDefault } from './findcc.js';
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
+ import { inspectShellHook } from './server/lib/shell-hook-inspect.js';
17
18
  import { normalizeBasePath } from './server/lib/base-path.js';
18
19
  import { mergeSettingsIntoArgs } from './server/lib/settings-merge.js';
19
20
  import { splitSdkLaunchArgs, resolveLaunchSystemPrompt, insertBeforeDashDash } from './server/lib/launch-config.js';
@@ -36,6 +37,20 @@ const INJECT_BLOCK = _buildInjectBlock(INJECT_IMPORT);
36
37
  const SHELL_HOOK_START = '# >>> CC-Viewer Auto-Inject >>>';
37
38
  const SHELL_HOOK_END = '# <<< CC-Viewer Auto-Inject <<<';
38
39
 
40
+ // L1: hook 状态只读探针(server 侧经 /api/claude-settings 暴露;inspectShellHook 的
41
+ // 实现放 server/lib/shell-hook-inspect.js,cli.js 只注入自己的模板构造器做 stale 判定)。
42
+ const _inspectShellHookState = () => inspectShellHook(buildShellHook);
43
+
44
+ // 供 server(routes/preferences.js)读取 hook 状态:GUI 启动时把最近一次检查结果写到这里,
45
+ // 避免 server 反向 import side-effectful 的 cli.js。
46
+ export const shellHookState = { installed: null, stale: null, path: null, corrupt: null, checkedAt: null };
47
+ function refreshShellHookState() {
48
+ try {
49
+ const r = _inspectShellHookState();
50
+ Object.assign(shellHookState, r, { checkedAt: Date.now() });
51
+ } catch { /* 探针失败只退化为「未知」,绝不影响启动 */ }
52
+ }
53
+
39
54
  const cliPath = resolveCliPath();
40
55
 
41
56
  // Unified "claude not found" error message: distinguishes between "Claude Code 2.x wrapper
@@ -481,6 +496,10 @@ async function runCliMode(extraClaudeArgs = [], cwd, noOpen = false) {
481
496
  // 确保 AskUserQuestion hook 已注册到 ~/.claude/settings.json
482
497
  ensureHooks();
483
498
 
499
+ // L1: shell hook 状态检查(只读;结果经 shellHookState 暴露给 /api/claude-settings,
500
+ // 面板据此提示「重开终端使其生效」——绝不自动改用户 rc:删掉 = 不想装)。
501
+ refreshShellHookState();
502
+
484
503
  // 2. 设置 CLI 模式标记(必须在 import proxy.js 之前,
485
504
  // 因为 proxy.js → interceptor.js 可能触发 server.js 加载,
486
505
  // server.js 的 isCliMode 在模块顶层求值且只执行一次)