cc-viewer 1.9.3 → 1.9.5

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 (37) hide show
  1. package/README.md +5 -5
  2. package/cli.js +29 -2
  3. package/dist/assets/App-Bj_-wfrB.js +2 -0
  4. package/dist/assets/App-DuDeDOuX.css +1 -0
  5. package/dist/assets/{MdxEditorPanel-Ck8B5a5v.js → MdxEditorPanel-DD2IrRnW.js} +1 -1
  6. package/dist/assets/{Mobile-B8AkKb0z.js → Mobile-BQBQkr2V.js} +1 -1
  7. package/dist/assets/{ProxyStatsModal-DsDVMf-c.js → ProxyStatsModal-8VYl6n39.js} +1 -1
  8. package/dist/assets/index-CloXv0sm.js +2 -0
  9. package/dist/assets/{seqResourceLoaders-BsMFNfvR.css → seqResourceLoaders-Bg9Lz8pH.css} +1 -1
  10. package/dist/assets/seqResourceLoaders-M4XGblXm.js +2 -0
  11. package/dist/index.html +1 -1
  12. package/package.json +1 -1
  13. package/server/interceptor.js +176 -14
  14. package/server/lib/git-diff.js +14 -8
  15. package/server/lib/scope-router.js +68 -0
  16. package/server/lib/sdk-manager.js +1524 -895
  17. package/server/lib/task-state.js +74 -34
  18. package/server/lib/turn-end-bridge.js +6 -1
  19. package/server/lib/v2/live-feed.js +7 -6
  20. package/server/lib/v2/view-router.js +48 -0
  21. package/server/lib/workflow-watcher.js +13 -6
  22. package/server/lib/ws-mux.js +473 -0
  23. package/server/pty-manager.js +53 -0
  24. package/server/routes/ask-perm.js +13 -8
  25. package/server/routes/events.js +190 -74
  26. package/server/routes/resume.js +79 -1
  27. package/server/routes/sdk-context.js +24 -0
  28. package/server/routes/sdk-mcp-status.js +24 -0
  29. package/server/routes/session-pin.js +12 -2
  30. package/server/routes/workflow-journal.js +5 -2
  31. package/server/routes/workspaces.js +31 -2
  32. package/server/scratch-pty-manager.js +127 -46
  33. package/server/server.js +616 -108
  34. package/dist/assets/App-BzXO6ATr.js +0 -2
  35. package/dist/assets/App-DJ4yNvwz.css +0 -1
  36. package/dist/assets/index-Dq5UPr6v.js +0 -2
  37. package/dist/assets/seqResourceLoaders-BsQ6KXpV.js +0 -2
package/README.md CHANGED
@@ -61,14 +61,14 @@ Once started in programming mode, the web page opens automatically.
61
61
 
62
62
  cc-viewer also ships as a native desktop app: [download page](https://github.com/weiesky/cc-viewer/releases)
63
63
 
64
- ### SDK mode (headless, `ccv -SDK`)
64
+ ### SDK mode (headless, `ccv --sdk`)
65
65
 
66
- `ccv -SDK` runs the session through the Agent SDK instead of an interactive terminal — no terminal panel, messages are sent from the web UI, and everything else (session logs, streaming typewriter, usage stats) works the same as in terminal mode.
66
+ `ccv --sdk` runs the session through the Agent SDK instead of an interactive terminal — no main PTY, messages are sent from the web UI, and everything else (session logs, streaming typewriter, usage stats) works the same as in terminal mode. The header still exposes a **Terminal** button, but it opens the standalone scratch multi-tab shell (unrelated to the SDK session), not a project PTY.
67
67
 
68
68
  ```bash
69
- ccv -SDK # headless session; chat from the browser
70
- ccv -SDK -c # continue the most recent session
71
- ccv -SDK --model sonnet # pick a model
69
+ ccv --sdk # headless session; chat from the browser
70
+ ccv --sdk -c # continue the most recent session
71
+ ccv --sdk --model sonnet # pick a model
72
72
  ```
73
73
 
74
74
  Approvals (Bash/Edit/Write/WebFetch/…) pop up in the browser with allow / deny / allow-for-session, and `AskUserQuestion` / plan prompts appear as modals. `npm publish` always requires an explicit approval — even with `--d`. Requires the `@anthropic-ai/claude-agent-sdk` package (bundled with cc-viewer); falls back to terminal mode if unavailable.
package/cli.js CHANGED
@@ -788,6 +788,13 @@ async function runSdkMode(extraClaudeArgs = [], cwd, noOpen = false) {
788
788
  const childEnv = {
789
789
  ...process.env,
790
790
  ANTHROPIC_BASE_URL: proxyBaseUrl,
791
+ // Opt the CLI child into emitting `session_state_changed` messages (idle /
792
+ // running / requires_action) — the authoritative turn-level busy signal the
793
+ // conversation spinner needs. Gated emission point in the CLI binary; harmless
794
+ // on older CLIs (unknown env is ignored, sdk-manager falls back to
795
+ // push-running/result-idle broadcasts). Top-level childEnv, not settings.env:
796
+ // the settings merge path could be overridden by user settings.
797
+ CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: '1',
791
798
  // 与 PTY 子进程同款(pty-manager.js:247):SDK 子进程的 cli.js 若已被 -logger/PTY 注入
792
799
  // interceptor,CCV_PROXY_MODE=1 让它只装 fetch hook 而不再自起 server;wire 捕获本来
793
800
  // 就发生在主进程 proxy 的出站 fetch(ANTHROPIC_BASE_URL 指过来),此键保证子进程不双起。
@@ -850,12 +857,15 @@ async function runSdkMode(extraClaudeArgs = [], cwd, noOpen = false) {
850
857
  // 若 SDK 内部异常吞掉了 result 消息这条信号就丢了 —— 至少打个 warn 让排查时有线索。
851
858
  // 显式 typeof 检查:以前用可选链 `?.()` 在 export 缺失时返回 undefined → catch 永远不触发
852
859
  // → 「至少 warn」承诺落空,turn-end 静默丢,bug 极难追。
853
- onTurnEnd: ({ sessionId, ts }) => {
860
+ onTurnEnd: ({ sessionId, ts, cwd }) => {
854
861
  if (typeof serverMod.broadcastTurnEnd !== 'function') {
855
862
  console.warn('[sdk] serverMod.broadcastTurnEnd is not a function (export missing?); turn-end signal dropped');
856
863
  return;
857
864
  }
858
- try { serverMod.broadcastTurnEnd(sessionId, ts); }
865
+ // Per-workspace (2026-10): forward the session cwd so the server routes the
866
+ // turn_end to THIS workspace's scope (SDK has no Stop-hook POST; without a
867
+ // scope hint every SDK turn-end resolved to the bound project).
868
+ try { serverMod.broadcastTurnEnd(sessionId, ts, null, cwd); }
859
869
  catch (err) { console.warn('[sdk] broadcastTurnEnd threw:', err?.message); }
860
870
  },
861
871
  // query 级失败(spawn/protocol/iterator)推到 Web UI toast —— 此前只有 console.error,
@@ -863,6 +873,20 @@ async function runSdkMode(extraClaudeArgs = [], cwd, noOpen = false) {
863
873
  onQueryError: (message) => serverMod.broadcastWsMessage({ type: 'sdk-error', message }),
864
874
  });
865
875
 
876
+ // Per-cwd multi-session (2026-10-12): hand the boot launch config (proxy env, model,
877
+ // permission, executable, user args) to the manager as a process-level template. The
878
+ // workspace-launch route uses it to register a session for a NEW cwd — without it the new
879
+ // session would get no env (bypassing the proxy → no transcript, no per-cwd routing).
880
+ // launchResume is boot-only and deliberately NOT templated.
881
+ sdkManager.setSdkLaunchConfig({
882
+ permissionMode,
883
+ env: childEnv,
884
+ settings: JSON.parse(settingsMerge.settingsJson),
885
+ model: sdkArgs.model,
886
+ userArgs: sdkArgs.rest,
887
+ claudeExecutable: sdkClaudePath,
888
+ });
889
+
866
890
  // 注册 SDK 回调到 server.js(WS 消息路由用)
867
891
  serverMod.setSdkResolveApproval(sdkManager.resolveApproval);
868
892
  serverMod.setSdkCancelApproval(sdkManager.cancelApproval);
@@ -870,6 +894,9 @@ async function runSdkMode(extraClaudeArgs = [], cwd, noOpen = false) {
870
894
  serverMod.setSdkInterruptTurn(sdkManager.interruptTurn);
871
895
  serverMod.setSdkGetPendingApprovals(sdkManager.getPendingApprovals);
872
896
  serverMod.setSdkGetInitSnapshot(sdkManager.getSdkInitSnapshot);
897
+ serverMod.setSdkGetContextUsageSnapshot(sdkManager.getContextUsageSnapshot);
898
+ serverMod.setSdkGetMcpStatusSnapshot(sdkManager.getMcpStatusSnapshot);
899
+ serverMod.setSdkGetSessionStateSnapshot(sdkManager.getSessionStateSnapshot);
873
900
  // Busy-queue bubble actions (queue-send-now / queue-remove / queue-clear / replay).
874
901
  serverMod.setSdkSendQueuedNow(sdkManager.sendQueuedNow);
875
902
  serverMod.setSdkRemoveQueued(sdkManager.removeQueued);