ccdeck 3.46.0 → 3.48.0

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 (68) hide show
  1. package/README.md +99 -46
  2. package/bin/cli/commands.js +17 -9
  3. package/bin/cli/help.js +9 -4
  4. package/bin/cli/second-start.js +4 -2
  5. package/bin/cli/startup.js +26 -2
  6. package/bin/cli/tui.js +544 -0
  7. package/bin/deck.js +32 -1
  8. package/dist/web/assets/{BrowserWatchModal-CoX9FIUE.js → BrowserWatchModal-DuopT2Oa.js} +1 -1
  9. package/dist/web/assets/IntegrationModal-CszT-tts.js +7 -0
  10. package/dist/web/assets/{RadioPanel-biw_BbZq.js → RadioPanel-Cn3WvPUG.js} +1 -1
  11. package/dist/web/assets/TrafficRadar-DZA8XSi7.js +8 -0
  12. package/dist/web/assets/UsageHistoryModal-MgZJLXbF.js +1 -0
  13. package/dist/web/assets/app-DjlHxWHg.css +1 -0
  14. package/dist/web/assets/app-F1xryJpn.js +321 -0
  15. package/dist/web/assets/claude-settings-index-1Qg1AUda.js +1 -0
  16. package/dist/web/assets/{index-DmENqVdt.js → index-BK9avF1k.js} +1 -1
  17. package/dist/web/index.html +3 -3
  18. package/package.json +1 -1
  19. package/release-notes.json +58 -2
  20. package/src/server/args.mjs +1 -0
  21. package/src/server/ccusage-install.mjs +58 -1
  22. package/src/server/ccusage-registry.mjs +289 -0
  23. package/src/server/ccusage-runner.mjs +9 -2
  24. package/src/server/claude-accounts.mjs +21 -0
  25. package/src/server/claude-login.mjs +21 -3
  26. package/src/server/claude-settings-catalog.d.mts +37 -0
  27. package/src/server/claude-settings-catalog.mjs +169 -0
  28. package/src/server/claude-settings-docs.mjs +109 -0
  29. package/src/server/claude-settings-index.json +251 -0
  30. package/src/server/claude-settings-routes.mjs +46 -0
  31. package/src/server/claude-settings.mjs +406 -0
  32. package/src/server/cli-arrival.mjs +64 -0
  33. package/src/server/cli-lines.mjs +46 -0
  34. package/src/server/gpu-metrics.mjs +78 -0
  35. package/src/server/index.mjs +18 -2
  36. package/src/server/integrations/jira-move.mjs +239 -0
  37. package/src/server/integrations/jira.mjs +30 -8
  38. package/src/server/integrations/proxy.mjs +14 -6
  39. package/src/server/integrations/routes.mjs +25 -9
  40. package/src/server/quota-close-watch.mjs +81 -0
  41. package/src/server/quota-closes.mjs +181 -0
  42. package/src/server/quota-history.mjs +8 -1
  43. package/src/server/quota-shape.mjs +12 -0
  44. package/src/server/quota.mjs +28 -1
  45. package/src/server/request-gates.mjs +3 -1
  46. package/src/server/system-metrics.mjs +4 -0
  47. package/src/server/term.mjs +14 -5
  48. package/src/server/tool-audit-operations.mjs +30 -10
  49. package/src/server/tool-audit-report.mjs +79 -7
  50. package/src/server/tool-audit-routes.mjs +1 -1
  51. package/src/server/tool-audit-skills.mjs +8 -3
  52. package/src/server/tool-audit.mjs +55 -5
  53. package/src/server/traffic-radar-capture.mjs +3 -3
  54. package/src/server/traffic-radar-config.mjs +10 -3
  55. package/src/server/traffic-radar-monitor.mjs +8 -5
  56. package/src/server/traffic-radar-permission.mjs +162 -0
  57. package/src/server/traffic-radar-platform.mjs +9 -3
  58. package/src/server/traffic-radar-routes.mjs +8 -18
  59. package/src/server/traffic-radar-service.mjs +76 -92
  60. package/src/server/tui-screen.mjs +110 -0
  61. package/src/server/tui-view.mjs +1072 -0
  62. package/src/server/usage-routes.mjs +14 -2
  63. package/src/server/way-back.mjs +27 -0
  64. package/dist/web/assets/IntegrationModal-B1ypkK-E.js +0 -5
  65. package/dist/web/assets/TrafficRadar-nhtFoYVv.js +0 -8
  66. package/dist/web/assets/UsageHistoryModal-Bd-JRAa4.js +0 -1
  67. package/dist/web/assets/app-BlRY6EME.css +0 -1
  68. package/dist/web/assets/app-DhGvSH7o.js +0 -319
@@ -1,136 +1,120 @@
1
1
  import { CaptureSetupError } from './traffic-radar-platform.mjs';
2
2
  import { isIP } from 'node:net';
3
+ import { lookup } from 'node:dns/promises';
3
4
 
4
5
  export function radarTargets(snapshot) {
5
6
  // A running Claude's launch environment names a collector as settings do.
6
7
  const variables = [...(snapshot?.config?.variables ?? []), ...(snapshot?.environment ?? [])];
7
- const configured = variables.filter(v => v.key.endsWith('ENDPOINT')).flatMap(({ value }) => {
8
- try {
9
- const url = new URL(value);
10
- return ['http:', 'https:'].includes(url.protocol) && isIP(url.hostname) === 4
11
- ? [`${url.hostname}:${url.port || (url.protocol === 'https:' ? 443 : 80)}`] : [];
12
- } catch { return []; }
13
- });
8
+ const configured = [], named = [];
9
+ for (const { key, value } of variables) {
10
+ if (!key.endsWith('ENDPOINT')) continue;
11
+ let url;
12
+ try { url = new URL(value); } catch { continue; }
13
+ if (!['http:', 'https:'].includes(url.protocol)) continue;
14
+ const port = url.port || (url.protocol === 'https:' ? 443 : 80);
15
+ if (isIP(url.hostname) === 4) configured.push(`${url.hostname}:${port}`);
16
+ // A name is looked up before capture (resolveCollector); an IPv6 literal,
17
+ // which URL keeps in brackets, is neither.
18
+ else if (url.hostname && !url.hostname.startsWith('[')) named.push(`${url.hostname}:${port}`);
19
+ }
14
20
  // An arbitrary Claude HTTPS connection is not evidence of a collector, nor an
15
21
  // attempt nothing has answered.
16
22
  const observed = (snapshot?.connections ?? []).filter(c => c.active === true && !c.connecting && /:4317$/.test(c.destination) && isIP(c.destination.slice(0, c.destination.lastIndexOf(':'))) === 4).map(c => c.destination);
17
- return { configured: [...new Set(configured)], observed: [...new Set(observed)] };
23
+ return { configured: [...new Set(configured)], named: [...new Set(named)], observed: [...new Set(observed)] };
24
+ }
25
+
26
+ /** A collector named by host, such as otel.example.com:4317, as the IPv4
27
+ * address Claude reaches it at. Capture filters on an address, and with no
28
+ * destination picker any more a name is the only way such a collector is
29
+ * found. A lookup that fails or hangs past `ms` names nothing. */
30
+ export async function resolveCollector(target, find = lookup, ms = 2000) {
31
+ const at = target.lastIndexOf(':');
32
+ let timer;
33
+ const late = new Promise(resolve => { timer = setTimeout(resolve, ms, null); timer.unref?.(); });
34
+ try {
35
+ const found = await Promise.race([find(target.slice(0, at), { family: 4 }).catch(() => null), late]);
36
+ return found && isIP(found.address) === 4 ? `${found.address}:${target.slice(at + 1)}` : null;
37
+ } finally { clearTimeout(timer); }
18
38
  }
19
39
 
20
40
  const savedDestinations = value => Array.isArray(value)
21
41
  ? value.filter(v => typeof v === 'string' && /^\d+\.\d+\.\d+\.\d+:\d+$/.test(v)).slice(0, 8) : [];
22
42
 
23
- /** Own the automatic-monitoring preference independently of whether capture is ready yet.
43
+ /** Radar monitors by itself, always: there is no switch and no Start (the
44
+ * owner, 2026-10-23, reversing v3.44.0's opt-in). The service finds Claude
45
+ * Code's collector — configured endpoints first, named ones looked up, then the
46
+ * collectors it remembers and active OTLP/gRPC connections on port 4317 — and
47
+ * keeps capture on it, retrying while none is found or capture is not ready.
24
48
  *
25
- * AUTOMATIC MONITORING IS OPT-IN. `enabled` here is Settings › Radar's switch,
26
- * kept in its own file (`preferences`, radar-settings-<port>.json) and on only
27
- * where that file says `automatic: true`. A fresh deck, and a deck upgraded
28
- * from a release that never wrote the file, has it off: nothing is discovered,
29
- * nothing is retried, and the capture behaves exactly as it did before, with
30
- * the person choosing a destination and starting it in Radar's Monitor view
31
- * (`capture.prepare`/`capture.stop`, which keep their own radar-monitor-<port>
32
- * .json opt-in and resume a monitor the person started, as they always did).
33
- * Only while the switch is on does the service find the collector itself and
34
- * retry every `pollMs`. */
35
- export function createRadarService({ capture, preferences, discover, pollMs = 5000 }) {
36
- let enabled = false, port = null, remembered = [], revision = 0, timer = null, disposed = false;
37
- let ready = Promise.resolve(), syncing = null, setupError = null;
38
- const settings = () => ({ ok: true, enabled, setupError });
39
- const save = () => preferences.write(port, { automatic: enabled, destinations: remembered });
40
- const stopLoop = () => { clearInterval(timer); timer = null; };
41
- const startLoop = () => {
42
- stopLoop();
43
- if (enabled && !disposed) { timer = setInterval(() => void sync(), pollMs); timer.unref?.(); }
44
- };
49
+ * Discovery samples Claude's processes (ps and lsof, /proc, or PowerShell), so
50
+ * every deck pays for it: it runs every `pollMs` only while Radar is open,
51
+ * which the page shows by reading the capture, and every `idleMs` otherwise.
52
+ * `radar-settings-<port>.json` keeps the collectors found, so a restart goes
53
+ * back to them; a monitor started by hand in an earlier release resumes too,
54
+ * and is where discovery looks first when no setting names a collector. */
55
+ export function createRadarService({ capture, preferences, discover, resolve = resolveCollector, pollMs = 5000, idleMs = 60000, openMs = 15000, now = Date.now }) {
56
+ let port = null, remembered = [], timer = null, disposed = false;
57
+ let syncing = null, setupError = null, syncedAt = -Infinity, readAt = -Infinity;
58
+ const save = () => preferences.write(port, { destinations: remembered });
45
59
  async function sync() {
46
- if (!enabled || disposed || !port) return;
60
+ if (disposed || !port) return;
47
61
  if (syncing) return syncing;
48
- const operation = revision;
62
+ syncedAt = now();
49
63
  syncing = (async () => {
50
64
  try {
51
- const { configured, observed } = radarTargets(await discover());
52
- if (operation !== revision || !enabled || disposed) return;
53
- const targets = [...new Set(configured.length ? configured : [...remembered, ...observed])].sort().slice(0, 8);
65
+ const { configured, named, observed } = radarTargets(await discover());
66
+ const looked = (await Promise.all(named.map(target => resolve(target)))).filter(Boolean);
67
+ if (disposed) return;
68
+ const settings = [...configured, ...looked];
69
+ const targets = [...new Set(settings.length ? settings : [...remembered, ...observed])].sort().slice(0, 8);
54
70
  if (!targets.length) { setupError = null; return; }
55
71
  const current = capture.read();
56
72
  const existing = (current.sources ?? []).map(s => s.destination).sort();
57
73
  if (current.enabled && JSON.stringify(existing) === JSON.stringify(targets)) { setupError = null; return; }
58
74
  await capture.prepare(targets, port);
59
- // Stopped with its opt-in saved off: a setup that lands after the switch
60
- // went off must not leave a monitor that resumes after a restart.
61
- if (operation !== revision || !enabled || disposed) { await capture.stop('stopped', !disposed); return; }
75
+ // A setup that lands after the deck shut the service down must not
76
+ // leave a monitor running, or one that resumes after a restart.
77
+ if (disposed) { await capture.stop('stopped', false); return; }
62
78
  remembered = targets;
63
79
  setupError = null;
64
80
  await save();
65
81
  } catch (error) {
66
- if (operation === revision && enabled && !disposed) setupError = error instanceof CaptureSetupError ? error.message : 'Monitoring setup failed. Retrying automatically.';
82
+ if (!disposed) setupError = error instanceof CaptureSetupError ? error.message : 'Monitoring setup failed. Retrying automatically.';
67
83
  }
68
84
  })().finally(() => { syncing = null; });
69
85
  return syncing;
70
86
  }
87
+ const tick = () => { if (now() - readAt < openMs || now() - syncedAt >= idleMs) void sync(); };
71
88
  return {
72
89
  ...capture,
73
- resume(requestedPort) {
90
+ async resume(requestedPort) {
74
91
  port = requestedPort;
75
- const operation = ++revision;
76
- ready = (async () => {
77
- const saved = await preferences.read(port);
78
- if (operation !== revision || disposed) return;
79
- enabled = saved?.automatic === true;
80
- remembered = savedDestinations(saved?.destinations);
81
- if (enabled) startLoop();
82
- // Off: the capture's own opt-in, as before — a monitor resumes only
83
- // where the person started one and did not stop it.
84
- else await capture.resume(port);
85
- })();
86
- return ready.then(sync);
87
- },
88
- async settings() { await ready; return settings(); },
89
- async setEnabled(next) {
90
- if (typeof next !== 'boolean') throw new Error('Radar enabled must be a boolean.');
91
- await ready;
92
- if (!port || disposed) throw new Error('Radar is not ready.');
93
- const previous = enabled, operation = ++revision;
94
- enabled = next;
95
- stopLoop();
96
- if (next) {
97
- // A monitor the person started by hand is where automatic monitoring
98
- // looks first when Claude's settings name no collector.
99
- const running = (capture.read().sources ?? []).map(s => s.destination);
100
- if (running.length) remembered = savedDestinations(running);
101
- } else { setupError = null; await capture.stop(); }
102
- try { await save(); }
103
- catch (error) {
104
- if (operation === revision) { enabled = previous; startLoop(); if (enabled) void sync(); }
105
- throw error;
106
- }
107
- if (operation === revision && enabled) {
108
- startLoop();
109
- // A slow older setup must finish/cancel before starting a new one.
110
- if (syncing) void syncing.then(sync); else void sync();
111
- }
112
- return settings();
92
+ const saved = await preferences.read(port);
93
+ if (disposed) return;
94
+ remembered = savedDestinations(saved?.destinations);
95
+ await capture.resume(port);
96
+ if (disposed) return;
97
+ if (!remembered.length) remembered = savedDestinations((capture.read().sources ?? []).map(s => s.destination));
98
+ clearInterval(timer);
99
+ timer = setInterval(tick, pollMs); timer.unref?.();
100
+ return sync();
113
101
  },
114
- async prepare(destination, requestedPort) {
115
- await ready;
116
- // Off: the Monitor view's own Start, unchanged.
117
- if (!enabled) return capture.prepare(destination, requestedPort);
118
- const operation = ++revision;
119
- const result = await capture.prepare(destination, requestedPort);
120
- if (operation !== revision || !enabled || disposed) { await capture.stop('stopped', !disposed); throw new Error('Radar setup was cancelled.'); }
121
- remembered = Array.isArray(destination) ? destination : [destination];
122
- await save();
123
- return result;
102
+ /** Start capture again now: permission was just granted (traffic-radar-permission.mjs). */
103
+ async retry() {
104
+ setupError = null;
105
+ const running = (capture.read().sources ?? []).map(s => s.destination);
106
+ if (!running.length || disposed || !port) return sync();
107
+ try { await capture.prepare(running, port); }
108
+ catch (error) { setupError = error instanceof CaptureSetupError ? error.message : 'Monitoring setup failed. Retrying automatically.'; }
124
109
  },
125
- // Off, Stop monitoring is the Monitor view's, as before; on, stopping is
126
- // turning automatic monitoring off.
127
- stop(...args) { return enabled ? this.setEnabled(false) : capture.stop(...args); },
128
110
  read() {
111
+ // Radar is open: look now rather than waiting out the idle interval.
112
+ readAt = now();
113
+ if (now() - syncedAt >= pollMs) void sync();
129
114
  const value = capture.read();
130
- if (!enabled) return { ...value, automatic: false };
131
115
  return { ...value, automatic: true, featureEnabled: true, setupError,
132
116
  state: setupError && !value.enabled ? 'error' : value.state };
133
117
  },
134
- dispose() { disposed = true; revision++; stopLoop(); capture.dispose(); },
118
+ dispose() { disposed = true; clearInterval(timer); timer = null; capture.dispose(); },
135
119
  };
136
120
  }
@@ -0,0 +1,110 @@
1
+ // The terminal `ccdeck tui` draws on: the alternate screen, painted a row at a
2
+ // time, and handed back exactly as it was found.
3
+ //
4
+ // THE ALTERNATE SCREEN, so the view never scrolls the shell's own history away
5
+ // and leaves nothing behind when it closes — what `less`, `top` and every
6
+ // editor do. Wrapping is turned off for as long as the view is up: a row one
7
+ // column too wide would otherwise push every row under it down by one, and the
8
+ // view would go on painting rows that are no longer where it thinks they are.
9
+ //
10
+ // ONLY THE ROWS THAT CHANGED are written, each addressed by its row and cleared
11
+ // to its end, so a refresh every second over a slow SSH link sends a few bytes
12
+ // rather than the screen. A frame is written between the synchronized-output
13
+ // marks (DEC mode 2026): a terminal that knows them shows it whole, and one
14
+ // that does not ignores them, which is what an unknown private mode is for.
15
+ // Except on Windows, where every console is conhost's: it froze on the first
16
+ // frame held between the marks and drew the ones after it seconds later or
17
+ // only once the view was left (Windows 11 24H2, under sshd). Conhost draws the
18
+ // screen from its own copy of it anyway, so there no frame is held.
19
+ //
20
+ // ONE RUN OF TEXT MAY FLOW: a sign-in link is hundreds of characters, and cut
21
+ // into rows by us it is a link no terminal can click and no mouse can copy
22
+ // whole. So a frame can carry one `run`, written edge to edge with wrapping on,
23
+ // which the terminal wraps itself and knows to be one line. The rows it wrapped
24
+ // into stay marked as wrapped after it has gone, and a row still marked is
25
+ // joined to the one above it for selecting and for finding links. Erasing such
26
+ // a row from its first column takes the mark off in xterm.js, but not over
27
+ // conhost, which passes on only what changed; clearing the screen takes it off
28
+ // everywhere. So a frame that leaves a wrapped row behind is written whole.
29
+ //
30
+ // Pure in the sense that matters for a test: everything goes through `write`,
31
+ // and nothing reads the terminal.
32
+ import { CURSOR_HIDE, CURSOR_SHOW } from "./term.mjs";
33
+
34
+ export const ALT_SCREEN_ON = "\x1b[?1049h";
35
+ export const ALT_SCREEN_OFF = "\x1b[?1049l";
36
+ export const WRAP_OFF = "\x1b[?7l";
37
+ export const WRAP_ON = "\x1b[?7h";
38
+ export const SYNC_ON = "\x1b[?2026h";
39
+ export const SYNC_OFF = "\x1b[?2026l";
40
+ const RESET = "\x1b[0m";
41
+ const CLEAR = "\x1b[2J";
42
+ const HOME = "\x1b[H";
43
+
44
+ /** Whether a frame is held between the synchronized-output marks here. */
45
+ export const framesHeld = (platform = process.platform) => platform !== "win32";
46
+
47
+ /**
48
+ * A screen over `write`. `enter` takes the terminal, `paint(lines, run)` shows
49
+ * a frame, `invalidate` forgets what is on screen so the next frame is written
50
+ * whole (a resize, Ctrl+L), and `leave` puts the terminal back. `leave` is
51
+ * safe to call twice and before `enter`, since every way out calls it.
52
+ * `held` says whether a frame goes between the synchronized-output marks.
53
+ *
54
+ * `run` is `{ row, rows, text, full }`: `text` written from the start of `row`
55
+ * with wrapping on, over the `rows` rows whose `lines` are its pieces, and
56
+ * `full` when its last piece reaches the last column — the cursor waits there
57
+ * to wrap, and clearing the row from it would take the last character.
58
+ */
59
+ export function createScreen(write, { held = framesHeld() } = {}) {
60
+ let shown = null;
61
+ let shownRun = null;
62
+ let wrapped = new Set();
63
+ let on = false;
64
+ const send = (s) => {
65
+ try { write(s); } catch { /* the terminal went away; nothing left to draw on */ }
66
+ };
67
+ return {
68
+ get active() { return on; },
69
+ enter() {
70
+ on = true;
71
+ shown = null;
72
+ send(`${ALT_SCREEN_ON}${CURSOR_HIDE}${WRAP_OFF}${HOME}${CLEAR}`);
73
+ },
74
+ paint(lines, run = null) {
75
+ if (!on) return;
76
+ let out = "";
77
+ const flows = new Set(run ? Array.from({ length: run.rows - 1 }, (_, k) => run.row + 1 + k) : []);
78
+ if ([...wrapped].some(i => !flows.has(i))) shown = null;
79
+ const whole = shown == null;
80
+ if (whole) out += `${RESET}${HOME}${CLEAR}`;
81
+ const inRun = (i) => run != null && i >= run.row && i < run.row + run.rows;
82
+ for (let i = 0; i < lines.length; i++) {
83
+ if (inRun(i) || (!whole && shown[i] === lines[i])) continue;
84
+ // The reset before the clear, so the rest of the row is cleared in the
85
+ // terminal's own background rather than in the last colour drawn.
86
+ out += `\x1b[${i + 1};1H${lines[i]}${RESET}\x1b[K`;
87
+ }
88
+ if (run) {
89
+ let same = !whole && shownRun === run.text;
90
+ for (let i = run.row; same && i < run.row + run.rows; i++) same = shown[i] === lines[i];
91
+ if (!same) out += `\x1b[${run.row + 1};1H${RESET}${WRAP_ON}${run.text}${RESET}${WRAP_OFF}${run.full ? "" : "\x1b[K"}`;
92
+ }
93
+ // A frame shorter than the last one: the rows it no longer has.
94
+ if (!whole) for (let i = lines.length; i < shown.length; i++) out += `\x1b[${i + 1};1H\x1b[K`;
95
+ shown = lines.slice();
96
+ shownRun = run?.text ?? null;
97
+ wrapped = flows;
98
+ if (out) send(held ? `${SYNC_ON}${out}${SYNC_OFF}` : out);
99
+ },
100
+ invalidate() { shown = null; shownRun = null; },
101
+ leave() {
102
+ if (!on) return;
103
+ on = false;
104
+ shown = null;
105
+ shownRun = null;
106
+ wrapped = new Set();
107
+ send(`${held ? SYNC_OFF : ""}${RESET}${WRAP_ON}${CURSOR_SHOW}${ALT_SCREEN_OFF}`);
108
+ },
109
+ };
110
+ }