ccdeck 3.82.4 → 4.0.1

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 (145) hide show
  1. package/LICENSING.md +42 -4
  2. package/README.md +183 -72
  3. package/THIRD_PARTY_NOTICES.md +243 -17
  4. package/bin/cli/tui.js +58 -4
  5. package/bin/deck.js +27 -1
  6. package/dist/web/assets/AccountBridge-fp-fsMx-.js +1 -0
  7. package/dist/web/assets/AccountSection-Cu-96Q00.js +1 -0
  8. package/dist/web/assets/BrowserWatchModal-CvUx07C6.js +1 -0
  9. package/dist/web/assets/FeedbackConversations-BgVk0nkA.js +1 -0
  10. package/dist/web/assets/IntegrationModal-CEj5oJg4.js +7 -0
  11. package/dist/web/assets/IntegrationSkeleton-DD7YiFgd.js +1 -0
  12. package/dist/web/assets/RadioPanel-BhnzWRCT.js +1 -0
  13. package/dist/web/assets/StageShell-DmJu3dU1.js +4 -0
  14. package/dist/web/assets/TrafficRadar-C8-ieIw5.js +8 -0
  15. package/dist/web/assets/UsageHistoryModal-BThv9Kja.js +1 -0
  16. package/dist/web/assets/addon-unicode-graphemes-DW3WJwyh.js +18 -0
  17. package/dist/web/assets/addon-web-links-BWjmmSgS.js +12 -0
  18. package/dist/web/assets/addon-webgl-CLK4R-_u.js +75 -0
  19. package/dist/web/assets/app-DtosBis5.css +1 -0
  20. package/dist/web/assets/app-ZMmmEHxF.js +361 -0
  21. package/dist/web/assets/{index-B-l-VxLm.js → index-zSxC5ueJ.js} +1 -1
  22. package/dist/web/assets/inspector-status-pane-BgQG0bQi.js +1 -0
  23. package/dist/web/assets/screens-DD0uCtat.js +12 -0
  24. package/dist/web/assets/screens-DUniTTbC.css +1 -0
  25. package/dist/web/assets/stage-board-J2rKA9Pg.js +2 -0
  26. package/dist/web/assets/use-account-DvFObI4M.js +1 -0
  27. package/dist/web/assets/xterm-4jYizCpg.js +27 -0
  28. package/dist/web/assets/xterm-sheet-6GBZ9nXN.css +32 -0
  29. package/dist/web/index.html +16 -6
  30. package/package.json +13 -1
  31. package/release-notes.json +69 -1
  32. package/src/server/account-client.mjs +196 -0
  33. package/src/server/account-connect.mjs +238 -0
  34. package/src/server/account-flag.mjs +106 -0
  35. package/src/server/account-projects.mjs +1 -1
  36. package/src/server/account-service.mjs +532 -0
  37. package/src/server/account-status.mjs +293 -0
  38. package/src/server/account-store.mjs +137 -0
  39. package/src/server/account-sync.mjs +473 -0
  40. package/src/server/account-token-store.mjs +216 -0
  41. package/src/server/account-ui-fields.mjs +126 -0
  42. package/src/server/account-watch.mjs +1 -1
  43. package/src/server/browser-watch-log.mjs +1 -1
  44. package/src/server/browser-watch-store.mjs +1 -1
  45. package/src/server/ccdeck-account-routes.mjs +252 -0
  46. package/src/server/ccusage-install.mjs +2 -2
  47. package/src/server/ccusage-registry.mjs +4 -4
  48. package/src/server/ccusage-session.mjs +11 -0
  49. package/src/server/claude-accounts.mjs +1 -1
  50. package/src/server/claude-recovery.mjs +9 -4
  51. package/src/server/claude-settings-catalog.mjs +6 -6
  52. package/src/server/claude-settings.mjs +1 -1
  53. package/src/server/codex-auto.mjs +1 -1
  54. package/src/server/codex-cost-usage.mjs +7 -2
  55. package/src/server/codex-live-checkpoint.mjs +24 -9
  56. package/src/server/codex-live-engine.mjs +14 -4
  57. package/src/server/codex-live-handoff.mjs +53 -9
  58. package/src/server/codex-names.mjs +49 -0
  59. package/src/server/codex-translate.mjs +1 -1
  60. package/src/server/codex-ultrafast.d.mts +3 -0
  61. package/src/server/codex-ultrafast.mjs +5 -0
  62. package/src/server/codex-watch.mjs +25 -0
  63. package/src/server/command-panel-engine.mjs +300 -0
  64. package/src/server/command-panel-platform.mjs +99 -0
  65. package/src/server/cswap-auto-choice.mjs +1 -1
  66. package/src/server/cswap-auto-loop.mjs +1 -1
  67. package/src/server/cswap-install.mjs +21 -40
  68. package/src/server/deck-home.mjs +6 -0
  69. package/src/server/deck-prefs.mjs +53 -1
  70. package/src/server/detach.mjs +1 -1
  71. package/src/server/engine-download.mjs +277 -0
  72. package/src/server/engine-install.mjs +378 -0
  73. package/src/server/engine-package.mjs +267 -0
  74. package/src/server/event-log.mjs +7 -1
  75. package/src/server/event-pipeline.mjs +29 -1
  76. package/src/server/ghostty-handoff.mjs +81 -0
  77. package/src/server/index.mjs +143 -5
  78. package/src/server/installer.mjs +4 -1
  79. package/src/server/integrations/jira-write-guard.mjs +14 -208
  80. package/src/server/integrations/store.mjs +37 -19
  81. package/src/server/integrations/write-guard.mjs +223 -0
  82. package/src/server/intel-cpu-temperature.mjs +26 -0
  83. package/src/server/lifecycle.mjs +69 -6
  84. package/src/server/log-replay.mjs +4 -0
  85. package/src/server/login-service.mjs +7 -1
  86. package/src/server/macmon.mjs +1 -1
  87. package/src/server/npm-latest.mjs +1 -1
  88. package/src/server/org-telemetry.mjs +1 -1
  89. package/src/server/output-watch.mjs +4 -1
  90. package/src/server/panel-provenance.mjs +390 -0
  91. package/src/server/pinned-build.mjs +14 -0
  92. package/src/server/prefs-refusal.mjs +8 -1
  93. package/src/server/prefs-routes.mjs +60 -11
  94. package/src/server/pro-engine-client.mjs +339 -0
  95. package/src/server/pro-engine-install.mjs +294 -0
  96. package/src/server/pro-engine-terminal.mjs +308 -0
  97. package/src/server/project-discovery.mjs +139 -0
  98. package/src/server/provider-session-name.mjs +58 -0
  99. package/src/server/quota-closes.mjs +1 -1
  100. package/src/server/quota-history.mjs +1 -1
  101. package/src/server/reports.mjs +86 -21
  102. package/src/server/request-gates.mjs +34 -5
  103. package/src/server/restart-note.mjs +1 -1
  104. package/src/server/seed-boundary.mjs +489 -0
  105. package/src/server/session-counts.mjs +244 -0
  106. package/src/server/session-deck-names.mjs +143 -0
  107. package/src/server/session-enrichment.mjs +43 -6
  108. package/src/server/session-name-route.mjs +73 -0
  109. package/src/server/session-summary.mjs +12 -1
  110. package/src/server/session-transcript-routes.mjs +167 -0
  111. package/src/server/swap-log.mjs +1 -1
  112. package/src/server/system-metrics.mjs +57 -0
  113. package/src/server/terminal-bridge.mjs +485 -0
  114. package/src/server/terminal-folder.mjs +61 -0
  115. package/src/server/terminal-js-routes.mjs +752 -0
  116. package/src/server/terminal-routes.mjs +553 -0
  117. package/src/server/terminal-sessions.mjs +759 -0
  118. package/src/server/terminal-socket.mjs +403 -0
  119. package/src/server/terminal-target.mjs +928 -0
  120. package/src/server/thermal-metrics.mjs +13 -9
  121. package/src/server/tmux-control.mjs +1319 -0
  122. package/src/server/tmux-download.mjs +220 -0
  123. package/src/server/tmux.mjs +542 -0
  124. package/src/server/token-redact.mjs +42 -3
  125. package/src/server/tool-audit-report.mjs +44 -6
  126. package/src/server/tool-audit-routes.mjs +12 -1
  127. package/src/server/tool-audit.mjs +42 -8
  128. package/src/server/traffic-radar-monitor.mjs +1 -1
  129. package/src/server/traffic-radar-permission.mjs +1 -1
  130. package/src/server/transcript-gate.mjs +1 -1
  131. package/src/server/transcript-scan.mjs +15 -7
  132. package/src/server/transcript-turns.mjs +154 -0
  133. package/src/server/tui-network.mjs +1 -0
  134. package/src/server/tui-view.mjs +28 -0
  135. package/src/server/utf8-carry.mjs +159 -0
  136. package/src/server/uv-bootstrap.mjs +2 -2
  137. package/src/server/windows-acl.mjs +158 -0
  138. package/src/server/ws-frames.mjs +690 -0
  139. package/dist/web/assets/BrowserWatchModal-CWVooKxD.js +0 -1
  140. package/dist/web/assets/IntegrationModal-DLX43RIK.js +0 -7
  141. package/dist/web/assets/RadioPanel-Cj6PjrvQ.js +0 -1
  142. package/dist/web/assets/TrafficRadar-Bq1YcuHB.js +0 -8
  143. package/dist/web/assets/UsageHistoryModal-CMSCca5_.js +0 -1
  144. package/dist/web/assets/app-BHxsMz3-.js +0 -358
  145. package/dist/web/assets/app-CbXmr9rC.css +0 -1
@@ -0,0 +1,167 @@
1
+ // GET /api/session/transcript?session=<id>&provider=<claude|codex>.
2
+ // Chat reads one transcript already tracked by the Claude output watch or
3
+ // the Codex rollout watcher. Requests without provider use Claude.
4
+ //
5
+ // THE ID IS A KEY AND NOTHING ELSE. It is checked against a short alphabet
6
+ // before anything is looked up, and then only asks the watch's map for a path;
7
+ // no path is built from it and none is taken from the request. Anything the
8
+ // route will not read gets the same answer, so the route never tells which
9
+ // files exist. What is refused: an id the deck does not know; a stored path
10
+ // that no longer passes the transcript gate; a file that is itself a symlink;
11
+ // a path that reaches its file through a symlinked folder, or through a `..`
12
+ // after one (the file's real path must stay under the real path of a
13
+ // transcript root); a folder, a pipe or any file that is not a regular file; a
14
+ // file swapped for another between the stat and the open.
15
+ //
16
+ // WHAT IS NOT: a hard link. A second name for the same file is the same file
17
+ // to the system, and nothing here can tell it from the original. Making one
18
+ // needs write access to the projects folder, which is the same user who holds
19
+ // the deck's token (transcript-gate.mjs), so this route does not claim to
20
+ // refuse it.
21
+ //
22
+ // THE SAME GATES AS THE OTHER ROUTES THAT SHOW SESSION CONTENT: the path is in
23
+ // GUARDED_READS (request-gates.mjs), so the router's Host and same-origin or
24
+ // token check has run; and on top of it a request that did not come from this
25
+ // computer is refused here, as Settings › Claude Code's are, so a paired deck
26
+ // never reads a conversation through this server.
27
+ //
28
+ // BOUNDED. The last READ_WINDOW bytes are read, never more, however large the
29
+ // file. Cut at the front, the partial first line is dropped and the answer says
30
+ // `complete: false`. A line longer than the window gives no turn; the read is
31
+ // never grown to fit it.
32
+ import { constants } from "node:fs";
33
+ import { basename, dirname, relative, sep } from "node:path";
34
+ import { lstat as fsLstat, open as fsOpen, realpath as fsRealpath } from "node:fs/promises";
35
+ import { send } from "./http-io.mjs";
36
+ import { claudeTranscriptRoots, isClaudeTranscriptPath } from "./transcript-gate.mjs";
37
+ import { outputWatch } from "./session-tracking.mjs";
38
+ import { codexTranscriptWindow, transcriptWindow } from "./transcript-turns.mjs";
39
+ import { rolloutNameId } from "./codex-dir.mjs";
40
+ import { codexProfileSessionDirs } from "./codex-profiles.mjs";
41
+ import { codexTranscriptPath } from "./codex-watch.mjs";
42
+
43
+ export const SESSION_TRANSCRIPT_ROUTE = "/api/session/transcript";
44
+
45
+ /** The most bytes read from the end of a transcript. */
46
+ export const READ_WINDOW = 512 * 1024;
47
+
48
+ const UUID = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
49
+ const SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
50
+
51
+ const loopback = req => ["127.0.0.1", "::1", "::ffff:127.0.0.1"].includes(req.socket.remoteAddress);
52
+
53
+ function transcriptQuery(params) {
54
+ const keys = [...params.keys()];
55
+ if (new Set(keys).size !== keys.length || keys.some(key => key !== "session" && key !== "provider" && key !== "continuation")) return null;
56
+ const session = params.get("session");
57
+ const provider = params.get("provider") ?? "claude";
58
+ if (!SESSION_ID.test(session ?? "") || (provider !== "claude" && provider !== "codex")) return null;
59
+ const continuation = params.has("continuation");
60
+ if (continuation && (params.get("continuation") !== "1" || provider !== "claude" || !UUID.test(session))) return null;
61
+ return { session, provider, continuation };
62
+ }
63
+
64
+ function isCodexTranscriptPath(path, roots, session) {
65
+ if (rolloutNameId(basename(path)) !== session) return false;
66
+ return roots.some(root => /^\d{4}\/\d{2}\/\d{2}\/[^/]+$/.test(relative(root, path).split(sep).join("/")));
67
+ }
68
+
69
+ const unknown = res => send(res, 404, { ok: false, reason: "unknown_session" });
70
+
71
+ /**
72
+ * The tail of the file at `path` as lines, or null for a file this route will not read.
73
+ * `lstat` first (a symlink is refused), then opened read-only and non-blocking, and the
74
+ * handle's own `fstat` must be the same regular file `lstat` saw, so a swap in between
75
+ * is refused too.
76
+ */
77
+ async function readTail(path, io) {
78
+ const before = await io.lstat(path, { bigint: true });
79
+ if (!before.isFile()) return null;
80
+ // Where the file really is, after every link on the way, must still be in a
81
+ // transcript root (themselves resolved: ~/.claude is often a link).
82
+ const real = await io.realpath(path);
83
+ const roots = [];
84
+ for (const root of io.roots) {
85
+ try { roots.push(await io.realpath(root)); } catch { /* a root that does not exist holds nothing */ }
86
+ }
87
+ if (!io.allowed(real, roots)) return null;
88
+ const handle = await io.open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
89
+ try {
90
+ const after = await handle.stat({ bigint: true });
91
+ if (!after.isFile() || after.dev !== before.dev || after.ino !== before.ino) return null;
92
+ const size = Number(after.size);
93
+ const from = Math.max(0, size - READ_WINDOW);
94
+ const want = size - from;
95
+ const buf = Buffer.alloc(want);
96
+ let got = 0;
97
+ while (got < want) {
98
+ const { bytesRead } = await handle.read(buf, got, want - got, from + got);
99
+ if (bytesRead === 0) break;
100
+ got += bytesRead;
101
+ }
102
+ let text = buf.toString("utf8", 0, got);
103
+ const complete = from === 0;
104
+ if (!complete) {
105
+ const nl = text.indexOf("\n");
106
+ text = nl < 0 ? "" : text.slice(nl + 1);
107
+ }
108
+ return { complete, lines: text.split("\n") };
109
+ } finally {
110
+ await handle.close();
111
+ }
112
+ }
113
+
114
+ /** Claude writes this event in the original transcript when /background changes its UUID. */
115
+ function continuedSession(lines, source) {
116
+ for (let i = lines.length - 1; i >= 0; i -= 1) {
117
+ let event;
118
+ try { event = JSON.parse(lines[i]); } catch { continue; }
119
+ if (event?.type !== "continued-in" || event.sessionId !== source) continue;
120
+ const next = event.continuedInSessionId;
121
+ return typeof next === "string" && UUID.test(next) && next.toLowerCase() !== source.toLowerCase() ? next : null;
122
+ }
123
+ return null;
124
+ }
125
+
126
+ export async function handleSessionTranscript(req, res, io = {}) {
127
+ if (!loopback(req)) return send(res, 403, { ok: false, error: "A conversation can be read on this computer only." });
128
+ if (req.method !== "GET") return send(res, 405, { ok: false, error: "Use GET." });
129
+ const query = transcriptQuery(new URL(req.url, "http://localhost").searchParams);
130
+ if (!query) return send(res, 400, { ok: false, reason: "bad_session" });
131
+ const { session, provider, continuation } = query;
132
+ const codex = provider === "codex";
133
+ const pathOf = io.pathOf ?? (codex ? codexTranscriptPath : sid => outputWatch.pathOf(sid));
134
+ const allowed = codex ? (path, roots) => isCodexTranscriptPath(path, roots, session) : isClaudeTranscriptPath;
135
+ const realpath = io.realpath ?? fsRealpath;
136
+ let tail;
137
+ let next = null;
138
+ try {
139
+ const path = pathOf(session);
140
+ if (typeof path !== "string") return unknown(res);
141
+ const roots = await (io.roots ?? (codex ? codexProfileSessionDirs : claudeTranscriptRoots))();
142
+ if (!(io.isTranscriptPath ?? allowed)(path, roots)) return unknown(res);
143
+ tail = await readTail(path, {
144
+ lstat: io.lstat ?? fsLstat, open: io.open ?? fsOpen,
145
+ realpath, roots, allowed,
146
+ });
147
+ if (continuation && tail && basename(path) === `${session}.jsonl`) {
148
+ const candidate = continuedSession(tail.lines, session);
149
+ const destination = candidate && pathOf(candidate);
150
+ // An idle background worker may be attachable before writing a transcript.
151
+ // The pane verifies the backend's live target and the session's project.
152
+ if (candidate && typeof destination !== "string") next = candidate;
153
+ if (typeof destination === "string" && basename(destination) === `${candidate}.jsonl` && allowed(destination, roots)) {
154
+ const dest = await realpath(destination);
155
+ const src = await realpath(path);
156
+ // Same resolved project within the same profile. No scan of other sessions.
157
+ if (dirname(dest) === dirname(src) && basename(dest) === `${candidate}.jsonl`) next = candidate;
158
+ }
159
+ }
160
+ } catch { return unknown(res); }
161
+ if (!tail) return unknown(res);
162
+ if (continuation) return send(res, 200, { ok: true, sessionId: next });
163
+ const { turns, cut } = (codex ? codexTranscriptWindow : transcriptWindow)(tail.lines);
164
+ // Not complete when the byte window began after the file's start, or when the
165
+ // turn cap dropped turns from the front.
166
+ return send(res, 200, { ok: true, complete: tail.complete && !cut, turns });
167
+ }
@@ -97,7 +97,7 @@ export async function readSwapLog(path = swapLogPath(), { strict = false } = {})
97
97
  /** Append one swap line. Creates the log directory on first use. Best-effort:
98
98
  * a failure to record must never break a switch, so callers ignore rejection. */
99
99
  export async function appendSwap(entry, path = swapLogPath()) {
100
- await mkdir(join(path, ".."), { recursive: true });
100
+ await mkdir(join(path, ".."), { recursive: true, mode: 0o700 });
101
101
  await appendFile(path, JSON.stringify(entry) + "\n", "utf8");
102
102
  }
103
103
 
@@ -52,6 +52,15 @@ let swap = null;
52
52
  const cpuHistory = [];
53
53
  let memory = null;
54
54
  let memInFlight = false;
55
+ /** When the newest CPU and memory readings were taken, by the wall clock — the
56
+ * `sampledAt` machineReading hands the account's status frame, so the console
57
+ * can say how old each number is. 0 before the first one. */
58
+ let lastCpuAt = 0;
59
+ let lastMemAt = 0;
60
+ /** Memory polls that ran and could not measure, since the last one that could.
61
+ * A sampler that has run and found nothing is `unavailable`; one that has not
62
+ * run yet is only warming up. */
63
+ let memMisses = 0;
55
64
  /** When sampling started, so a modal can say what "since" means. */
56
65
  let historySince = 0;
57
66
 
@@ -331,7 +340,11 @@ async function sampleMemory() {
331
340
  available,
332
341
  usedPct: Math.max(0, Math.min(100, Math.round(((total - available) / total) * 1000) / 10)),
333
342
  };
343
+ lastMemAt = Date.now();
344
+ memMisses = 0;
334
345
  record("mem:physical", memory.usedPct);
346
+ } else {
347
+ memMisses++;
335
348
  }
336
349
  // Same 30s cadence as memory, and for the same reason: it moves in minutes
337
350
  // and costs a subprocess on two of the three platforms.
@@ -346,6 +359,7 @@ function sampleCpu() {
346
359
  const pct = cpuPercent();
347
360
  if (pct == null) return;
348
361
  cores = per;
362
+ lastCpuAt = Date.now();
349
363
  cpuHistory.push(pct);
350
364
  while (cpuHistory.length > HISTORY) cpuHistory.shift();
351
365
  record("cpu:all", pct);
@@ -413,6 +427,9 @@ export function stopSystemMetrics() {
413
427
  memory = null;
414
428
  cores = null;
415
429
  swap = null;
430
+ lastCpuAt = 0;
431
+ lastMemAt = 0;
432
+ memMisses = 0;
416
433
  // The process list's Windows baseline and its last list, which go together.
417
434
  resetProcessList();
418
435
  }
@@ -449,3 +466,43 @@ export function systemSnapshot() {
449
466
  sampledAt: Date.now(),
450
467
  };
451
468
  }
469
+
470
+ /**
471
+ * CPU and memory as the account's status frame carries them (account-status.mjs):
472
+ * the newest readings and when each was taken, or why there is none.
473
+ *
474
+ * cpu { pct, cores, sampledAt } — `pct` is exactly the Machine panel's
475
+ * number, the busy share of every core since the previous 3-second
476
+ * sample; or { unknown: "warming-up" } before two samples exist
477
+ * memory { usedPct, totalMb, sampledAt } — (total - available) / total with
478
+ * the platform's own "available"; or { unknown: "warming-up" } before
479
+ * the first poll, { unknown: "unavailable" } once polls have run and
480
+ * none could measure
481
+ *
482
+ * A reading the sampler has not been started for at all is `unavailable`.
483
+ *
484
+ * SIDE-EFFECT FREE, and that is the reason it exists beside systemSnapshot
485
+ * rather than reading it: systemSnapshot calls notePanelPoll, which tells the
486
+ * network section a panel is open and so starts the probe that times the API
487
+ * and reads the route — the one part of this module that leaves the machine.
488
+ * A frame sent every fifteen seconds must never be what keeps that probe
489
+ * running. machine-reading.test.ts holds this to it. No load average, by the
490
+ * owner's decision: CPU and memory only.
491
+ */
492
+ export function machineReading() {
493
+ const running = cpuTimer != null;
494
+ // A machine that lists no cores has a percentage nobody can read against.
495
+ const coreCount = os.cpus().length;
496
+ const cpu = !running || coreCount < 1 ? { unknown: "unavailable" }
497
+ : cpuHistory.length && lastCpuAt ? { pct: cpuHistory[cpuHistory.length - 1], cores: coreCount, sampledAt: lastCpuAt }
498
+ : { unknown: "warming-up" };
499
+ return { cpu, memory: memoryReading(running) };
500
+ }
501
+
502
+ function memoryReading(running) {
503
+ if (memory && lastMemAt) {
504
+ return { usedPct: memory.usedPct, totalMb: Math.max(1, Math.round(memory.total / (1024 * 1024))), sampledAt: lastMemAt };
505
+ }
506
+ if (!running) return { unknown: "unavailable" };
507
+ return { unknown: memMisses > 0 ? "unavailable" : "warming-up" };
508
+ }