cc-viewer 1.9.33 → 1.9.35

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/dist/index.html CHANGED
@@ -21,7 +21,7 @@
21
21
  // 整体显示大小已弃用 CSS zoom:Electron 改用 webFrame.setZoomFactor(首屏抢占见
22
22
  // electron/tab-content-preload.js),纯浏览器交由用户用浏览器自带快捷键缩放,故此处不再设 zoom。
23
23
  </script>
24
- <script type="module" crossorigin src="./assets/index-BQAck4ag.js"></script>
24
+ <script type="module" crossorigin src="./assets/index-OTFFui4C.js"></script>
25
25
  <link rel="modulepreload" crossorigin href="./assets/vendor-antd-C5Wsfsxn.js">
26
26
  <link rel="modulepreload" crossorigin href="./assets/vendor-codemirror-DPXDhteu.js">
27
27
  <link rel="modulepreload" crossorigin href="./assets/vendor-mdxeditor-DLPCj_fe.js">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-viewer",
3
- "version": "1.9.33",
3
+ "version": "1.9.35",
4
4
  "description": "Claude Code logging, visualization, and management toolkit — launch a web viewer alongside Claude Code with full request/response tracing, proxy, and mobile support",
5
5
  "license": "MIT",
6
6
  "main": "server.js",
@@ -632,6 +632,28 @@ const _v2Writer = new V2Writer({
632
632
  });
633
633
  export { _v2Writer };
634
634
 
635
+ /**
636
+ * Retire a CLOSED random-key SDK session's routing (2026-11) so its late traffic (a
637
+ * draining child's heartbeat/completion) can no longer move `_currentSid` /
638
+ * `_currentSidByInstance` into its old dir. Called ONLY from the explicit SDK close path
639
+ * (routes/resume.js, when closeSdkSession reports wasFreshKey===true) — never from a
640
+ * launch or initForWorkspace/resetForLiveRelaunch: a same-cwd sibling stays LIVE and
641
+ * depends on its per-instance pointers surviving a relaunch.
642
+ */
643
+ export function retireInstance(instanceKey) {
644
+ try { _v2Writer.retireInstance(instanceKey); } catch (err) { reportSwallowed('interceptor.retire-instance', err); }
645
+ }
646
+
647
+ /**
648
+ * Release a CLOSED instance's per-instance routing state WITHOUT retiring the key
649
+ * (2026-11, same-cwd sibling close). Used by the SDK close path for a DETERMINISTIC cwd
650
+ * key (wasFreshKey=false) — that key is re-created on a normal relaunch, so it must be
651
+ * cleared, never retired. See v2-writer.releaseInstance.
652
+ */
653
+ export function releaseInstance(instanceKey) {
654
+ try { _v2Writer.releaseInstance(instanceKey); } catch (err) { reportSwallowed('interceptor.release-instance', err); }
655
+ }
656
+
635
657
  // S6b: the live read source — the current v2 session dir once the writer has
636
658
  // resolved a session; '' before the first request (readers treat a missing
637
659
  // path as an empty stream, same as v1's not-yet-created file did).
@@ -705,6 +727,11 @@ export function getLiveLogSource({ serveInFlight = true } = {}) {
705
727
  export function markSessionStart(payload) {
706
728
  try {
707
729
  const { source, sessionId, transcriptPath, cwd } = payload || {};
730
+ // Same-cwd twin routing (R1): the PTY that spawned this claude stamped its
731
+ // instanceKey into the env, forwarded by session-start-bridge. Validate the
732
+ // shape before letting it steer the resume-switch routing.
733
+ const rawInst = (payload && typeof payload.instanceKey === 'string') ? payload.instanceKey : '';
734
+ const instanceKey = /^ccv-[0-9a-f]+$/.test(rawInst) ? rawInst : null;
708
735
  // 'resume' re-binds the writer AND feeds snapshot Bind B; 'fork' feeds only
709
736
  // Bind B (a fork mints a fresh wire sid + the fork mark suppresses adoption,
710
737
  // so the writer routes it correctly without a switch). Everything else is
@@ -740,8 +767,11 @@ export function markSessionStart(payload) {
740
767
  _v2Writer.beginResumeSwitch({
741
768
  transcriptUuid,
742
769
  hookSid: (typeof sessionId === 'string' && sessionId) ? sessionId : null,
743
- // Keyed by the resumed conversation's project (bound = undefined default).
770
+ // Keyed by the resumed conversation's project (bound = undefined default)
771
+ // AND by this instance, so a same-cwd twin's /resume switch is consumed
772
+ // only by that twin's own next main request, never a sibling's.
744
773
  project: resumeProject || undefined,
774
+ instanceKey,
745
775
  });
746
776
  };
747
777
  if (!resumeProject || (_projectName && resumeProject === _projectName)) {
@@ -849,10 +879,12 @@ const _initPromise = Promise.resolve();
849
879
 
850
880
  export { LOG_FILE, _initPromise, _projectName, _logDir };
851
881
 
852
- // 工作区模式:绑定指定路径的项目(v2 会话目录由 V2Writer 按需创建)。
853
- // forceNew 仅存于签名兼容(Electron multi-tab 传入):v2 下每个 claude 进程
854
- // 天然是新 session,无旧文件可复用。
855
- export function initForWorkspace(projectPath, { forceNew = false } = {}) { // eslint-disable-line no-unused-vars
882
+ // Workspace mode: bind the project at the given path (v2 session dirs are
883
+ // created on demand by V2Writer). forceNew (a second claude instance in the
884
+ // same cwd) keeps the live twin's session bindings/owner.lock on a same-project
885
+ // re-bind — the new process gets a fresh sid and a fresh dir; the twin's must
886
+ // not be cleared.
887
+ export function initForWorkspace(projectPath, { forceNew = false, preserveLiveTwin = false } = {}) {
856
888
  const projectName = projectKeyForCwd(projectPath);
857
889
  const dir = join(LOG_DIR, projectName);
858
890
  try { mkdirSync(dir, { recursive: true }); } catch {}
@@ -870,7 +902,22 @@ export function initForWorkspace(projectPath, { forceNew = false } = {}) { // es
870
902
  // Fresh workspace context — no carried names apply; future requests must
871
903
  // create session dirs under the NEW project.
872
904
  _agentSpawnRegistry.clear();
873
- _v2Writer.resetSessions(previousProject || null); // also clears the per-process `-c` adoption latch
905
+ // forceNew on the SAME project: a live same-cwd twin keeps its session
906
+ // bindings + owner.lock claims (releasing them would expose its dirs to a
907
+ // sibling's cold-load/adoption). Only launch-boundary state that could hijack
908
+ // or misroute the fresh twin is cleared. Any other switch keeps the old
909
+ // scoped reset semantics.
910
+ //
911
+ // SDK +1 (preserveLiveTwin, 2026-11): the same-cwd sibling stays LIVE and the new
912
+ // child always carries x-ccv-instance, so it never enters the process-global
913
+ // `_pendingNoSid` bucket. resetForLiveRelaunch's project-level clear
914
+ // (`_pendingNoSidByInstance`/`_lateHandles`) would instead drain the SURVIVING
915
+ // sibling's in-flight buckets — so the SDK +1 path skips the writer reset entirely.
916
+ if (forceNew && previousProject && previousProject === projectName) {
917
+ if (!preserveLiveTwin) _v2Writer.resetForLiveRelaunch(projectName);
918
+ } else {
919
+ _v2Writer.resetSessions(previousProject || null); // also clears the per-process `-c` adoption latch
920
+ }
874
921
  // A `--fork-session` / `-r` launch marks fork/resume intent; neither must
875
922
  // leak into a LATER workspace's `-c` (in a long-lived server that would
876
923
  // permanently suppress adoption). Clear both marks per launch and re-sync —
@@ -0,0 +1,25 @@
1
+ // Shared continuation-arg stripping for "fresh session" launches (forceNew).
2
+ // Consumed by the workspace launch route (packages/app/server/routes/workspaces.js)
3
+ // and the Electron main process (apps/electron/electron/main.js via async import) —
4
+ // keep this the single source of truth so the two argv paths can never drift.
5
+ //
6
+ // `-r`/`--resume` carry a VALUE in the next argv slot — the orphan would land as
7
+ // claude's first positional prompt; `--continue=<x>`/`--resume=<x>` single-token
8
+ // forms and `--fork-session` (invalid without a continue flag) must go too.
9
+
10
+ const VALUE_FLAGS = new Set(['-r', '--resume']);
11
+ const LONE_FLAGS = new Set(['-c', '--continue', '-r', '--resume', '--fork-session']);
12
+
13
+ export function stripContinuationArgs(args) {
14
+ if (!Array.isArray(args)) return [];
15
+ const out = [];
16
+ for (let i = 0; i < args.length; i++) {
17
+ const a = args[i];
18
+ if (typeof a !== 'string') continue;
19
+ if (VALUE_FLAGS.has(a)) { i++; continue; } // flag + its value
20
+ if (LONE_FLAGS.has(a)) continue;
21
+ if (a.startsWith('--continue=') || a.startsWith('--resume=')) continue;
22
+ out.push(a);
23
+ }
24
+ return out;
25
+ }
@@ -44,9 +44,12 @@ export async function executeScheduledTask(task, claim, io) {
44
44
  async function _injectSdk(task, io) {
45
45
  const sdk = io.sdk;
46
46
  if (!sdk || !sdk.isSdkAvailable()) return { status: 'failed', reason: 'sdk_unavailable' };
47
- // The resident session is a per-cwd singleton — find the one for the task's cwd.
48
- const target = sdk.listSdkSessions().find(s => io.samePath(s.cwd, task.cwd));
49
- if (!target) return { status: 'failed', reason: 'no_live_session' };
47
+ // A cwd may host several same-cwd sibling sessions (multi-instance, 2026-11): pick the
48
+ // ACTIVE one when it lives in this cwd, else the deterministic (non-fresh) primary, else
49
+ // the most recent — never just the first-registered.
50
+ const matches = sdk.listSdkSessions().filter(s => io.samePath(s.cwd, task.cwd));
51
+ if (!matches.length) return { status: 'failed', reason: 'no_live_session' };
52
+ const target = matches.find(s => s.active) || matches.find(s => s.isFreshKey === false) || matches[matches.length - 1];
50
53
 
51
54
  // Queue-full precheck (P1-4): _sendUserMessage resolves normally even when the queue
52
55
  // rejects the message (broadcasts queue-rejected and returns), so a dispatched verdict