ccdeck 3.47.0 → 3.48.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 (36) hide show
  1. package/README.md +28 -4
  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 +3 -2
  6. package/bin/cli/tui.js +544 -0
  7. package/dist/web/assets/BrowserWatchModal-Dfsuy2cT.js +1 -0
  8. package/dist/web/assets/IntegrationModal-CcSR7YB-.js +7 -0
  9. package/dist/web/assets/{RadioPanel-DbmJJPsz.js → RadioPanel-s7WXdS6v.js} +1 -1
  10. package/dist/web/assets/{TrafficRadar-CPjAXd5e.js → TrafficRadar-C5GXMIwi.js} +1 -1
  11. package/dist/web/assets/UsageHistoryModal-CiExD9wF.js +1 -0
  12. package/dist/web/assets/app-BFaxhiED.js +321 -0
  13. package/dist/web/assets/app-DjlHxWHg.css +1 -0
  14. package/dist/web/assets/{index-Ca87aJP9.js → index-ByovgZ_7.js} +1 -1
  15. package/dist/web/index.html +3 -3
  16. package/package.json +1 -1
  17. package/release-notes.json +30 -3
  18. package/src/server/args.mjs +1 -0
  19. package/src/server/cli-lines.mjs +46 -0
  20. package/src/server/deck-prefs.mjs +23 -13
  21. package/src/server/gpu-metrics.mjs +78 -0
  22. package/src/server/integrations/jira-move.mjs +239 -0
  23. package/src/server/integrations/jira.mjs +30 -8
  24. package/src/server/integrations/proxy.mjs +3 -4
  25. package/src/server/integrations/routes.mjs +19 -5
  26. package/src/server/lan-deck.mjs +2 -1
  27. package/src/server/system-metrics.mjs +4 -0
  28. package/src/server/term.mjs +14 -5
  29. package/src/server/tui-screen.mjs +110 -0
  30. package/src/server/tui-view.mjs +1072 -0
  31. package/src/server/way-back.mjs +27 -0
  32. package/dist/web/assets/BrowserWatchModal-Bau0ttnH.js +0 -1
  33. package/dist/web/assets/IntegrationModal-8tTi25gA.js +0 -6
  34. package/dist/web/assets/UsageHistoryModal-qfmvXdWJ.js +0 -1
  35. package/dist/web/assets/app-BFFG6Wz8.js +0 -321
  36. package/dist/web/assets/app-DfcfHvcX.css +0 -1
@@ -14,6 +14,8 @@
14
14
  // GET /api/integrations/<kind>/<id>/asset?url= an image, read by the provider's client from its
15
15
  // own image hosts (raster only; empty 403/404)
16
16
  // GET /api/integrations/<kind>/<id>/<subpath…> the provider's own reads (registry.mjs)
17
+ // POST /api/integrations/jira/<id>/board/<boardId>/move
18
+ // one validated issue's group/rank (jira-move.mjs)
17
19
  //
18
20
  // A route that would ask a provider that is not answering (registry.mjs,
19
21
  // `available`), or ask for a saved connection whose provider this deck does
@@ -31,7 +33,7 @@
31
33
  // And what comes back is sent without it: a tracker that echoes the token
32
34
  // reaches the page, the saved connection and the log as `[redacted]`.
33
35
  import { createHash } from "node:crypto";
34
- import { readBody, send } from "../http-io.mjs";
36
+ import { readBody, readBytes, send } from "../http-io.mjs";
35
37
  import { errorBody, errorResponse, integrationError, isTypedError } from "./errors.mjs";
36
38
  import { fetchImage, IMAGE_MAX_BYTES, isSafeTarget, normaliseBaseUrl, originOf, RASTER_TYPES, rasterTypeOf } from "./proxy.mjs";
37
39
  import { getProvider, isAvailable, providerList } from "./registry.mjs";
@@ -451,9 +453,21 @@ export async function handleIntegrations(req, res, url, deps = {}) {
451
453
  // /api/integrations/<kind>/<id>/<subpath…>
452
454
  const [kind, id, ...rest] = segments;
453
455
  if (!id || rest.length === 0) return notFound(res);
454
- // Reads only, whatever the kind and whether or not this deck has its
455
- // provider: nothing under here may change anything.
456
- if (method !== "GET" && method !== "HEAD") return notAllowed(res);
456
+ // The only provider mutation is this narrowly shaped Jira operation.
457
+ // The server's normal mutation authentication and CSRF gates still apply.
458
+ const jiraMove = kind === "jira" && method === "POST" && rest.length === 3
459
+ && rest[0] === "board" && /^[1-9]\d{0,11}$/.test(rest[1]) && rest[2] === "move";
460
+ if (method !== "GET" && method !== "HEAD" && !jiraMove) return notAllowed(res);
461
+ let moveBody;
462
+ if (jiraMove) {
463
+ if (!/^application\/json(?:\s*;|$)/i.test(String(req.headers["content-type"] ?? ""))) {
464
+ throw integrationError("invalid", "Send the move as application/json.");
465
+ }
466
+ const bytes = await readBytes(req, res, 4096).catch(err => { if (!res.headersSent) throw err; return null; });
467
+ if (bytes === null) return;
468
+ try { moveBody = JSON.parse(bytes.toString("utf8")); }
469
+ catch { throw integrationError("invalid", "The move body is not valid JSON."); }
470
+ }
457
471
  const provider = getProvider(kind);
458
472
 
459
473
  // An image: whatever goes wrong, an empty 403 or 404, and the connection
@@ -486,7 +500,7 @@ export async function handleIntegrations(req, res, url, deps = {}) {
486
500
  if (secret == null) throw integrationError("expired", "No token is saved for this connection. Reconnect it in Settings.");
487
501
  const client = clientFor(provider, conn, secret, { fetchImpl });
488
502
 
489
- const read = await provider.routes(client, method, rest.join("/"), url.searchParams, req, { signal });
503
+ const read = await provider.routes(client, method, rest.join("/"), url.searchParams, req, { signal, ...(jiraMove ? { moveBody } : {}) });
490
504
  if (res.writableEnded || signal.aborted) return;
491
505
  const status = Number.isInteger(read?.status) ? read.status : 500;
492
506
  return answer(status, read?.body ?? errorBody(null));
@@ -360,7 +360,8 @@ export function lanApplyFields(prefs, { load = false, env = process.env } = {})
360
360
  // Whether paired decks are told which shared account this one is on.
361
361
  shareActive: lan.shareActive !== false,
362
362
  // Whether the account this deck is using right now may be sent to a paired
363
- // deck. Off unless somebody turned it on (#2192).
363
+ // deck. On since 3.48.1 unless somebody turned it off (normalise in
364
+ // deck-prefs.mjs, #2192).
364
365
  sendInUse: lan.sendInUse === true,
365
366
  // Discovery over Tailscale, off unless somebody turned it on, and the two
366
367
  // permissions that answer for the owner's own machines there.
@@ -18,6 +18,7 @@
18
18
  // readout the loudest producer in the application. So this is a plain poll
19
19
  // endpoint, exactly like /api/quota and /api/codex-usage already are.
20
20
  import os from "node:os";
21
+ import { startGpuMetrics, stopGpuMetrics, gpuSnapshot } from "./gpu-metrics.mjs";
21
22
  import { loadReading } from "./load-average.mjs";
22
23
  import { BUCKET_MS, labelsUnder, oldestBucketMs, pointsOf, record, resetHistory } from "./metrics-history.mjs";
23
24
  import { readAvailable, readSwap } from "./memory-metrics.mjs";
@@ -374,6 +375,7 @@ export function startSystemMetrics({ probe = false } = {}) {
374
375
  cpuTimer = setInterval(sampleCpu, CPU_INTERVAL_MS);
375
376
  memTimer = setInterval(sampleMemory, MEM_INTERVAL_MS);
376
377
  startThermalTimer();
378
+ startGpuMetrics();
377
379
  startNetworkTimers(probe);
378
380
  cpuTimer.unref?.();
379
381
  memTimer.unref?.();
@@ -401,6 +403,7 @@ export function stopSystemMetrics() {
401
403
  if (memTimer) clearInterval(memTimer);
402
404
  cpuTimer = memTimer = null;
403
405
  stopThermal();
406
+ stopGpuMetrics();
404
407
  stopNetwork();
405
408
  resetHistory();
406
409
  historySince = 0;
@@ -436,6 +439,7 @@ export function systemSnapshot() {
436
439
  // Null on a machine that publishes nothing, and the panel draws no section
437
440
  // at all for it rather than an empty one.
438
441
  thermal: thermalSnapshot(),
442
+ gpus: gpuSnapshot(),
439
443
  uptimeSec: Math.round(os.uptime()),
440
444
  platform: process.platform,
441
445
  // The rule the `load:1m` record in sampleCpu asks too — see loadReading.
@@ -83,12 +83,15 @@ export function colorProfile({ env = process.env, isTTY = false, platform = proc
83
83
  // ── colours ──────────────────────────────────────────────────────────────────
84
84
 
85
85
  /** rgb → the nearest xterm-256 index: the 6×6×6 cube, or the 24-step grey ramp
86
- * for anything neutral, which is where the muted tones land. */
86
+ * for anything neutral, which is where the muted tones land. Neutral is near
87
+ * grey, not exactly grey: the muted tone is a cool grey, and the cube's
88
+ * nearest to it is a teal — every border and every quiet word, under tmux. */
87
89
  function to256(r, g, b) {
88
- if (r === g && g === b) {
89
- if (r < 8) return 16;
90
- if (r > 248) return 231;
91
- return Math.round(((r - 8) / 247) * 24) + 232;
90
+ if (Math.max(r, g, b) - Math.min(r, g, b) < 16) {
91
+ const v = Math.round((r + g + b) / 3);
92
+ if (v < 8) return 16;
93
+ if (v > 248) return 231;
94
+ return Math.round(((v - 8) / 247) * 24) + 232;
92
95
  }
93
96
  return 16 + 36 * Math.round((r / 255) * 5) + 6 * Math.round((g / 255) * 5) + Math.round((b / 255) * 5);
94
97
  }
@@ -189,6 +192,12 @@ const ASCII_GLYPHS = {
189
192
  arrow: "->", ellipsis: "...", dash: "-", bullet: "-",
190
193
  };
191
194
 
195
+ /** Whether this shell came in over SSH: sshd sets one of these in every
196
+ * session it starts, interactive or not. */
197
+ export function overSsh(env = process.env) {
198
+ return set(env.SSH_CONNECTION) || set(env.SSH_CLIENT) || set(env.SSH_TTY);
199
+ }
200
+
192
201
  /**
193
202
  * Whether this terminal can be trusted with the box-drawing and arrow glyphs.
194
203
  *
@@ -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
+ }