ccdeck 3.81.2 → 3.81.4
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/README.md +6 -4
- package/bin/cli/tui.js +4 -2
- package/dist/web/assets/{BrowserWatchModal-BahEbWu-.js → BrowserWatchModal-C2JIHDVZ.js} +1 -1
- package/dist/web/assets/{IntegrationModal-DzIizEQd.js → IntegrationModal-CO1SrDXf.js} +1 -1
- package/dist/web/assets/{RadioPanel-DKmUHqxX.js → RadioPanel-CQ7ILyIZ.js} +1 -1
- package/dist/web/assets/{TrafficRadar-B2G1nwSK.js → TrafficRadar-KOunicu_.js} +1 -1
- package/dist/web/assets/{UsageHistoryModal-M0A1co-v.js → UsageHistoryModal-BXiOEbuk.js} +1 -1
- package/dist/web/assets/{app-uL65pD1B.js → app-0jqgYDft.js} +85 -85
- package/dist/web/assets/{index-4-WbGg1k.js → index-K55Tw-ZZ.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/release-notes.json +39 -5
- package/src/server/codex-live-credentials.mjs +31 -3
- package/src/server/codex-live-rpc.mjs +23 -6
- package/src/server/codex-selection.mjs +4 -1
- package/src/server/codex-windows-private.mjs +10 -0
- package/src/server/codex-windows-private.ps1 +53 -2
- package/src/server/deck-client.mjs +9 -1
- package/src/server/deck-home.mjs +3 -2
- package/src/server/depth-facts.mjs +93 -1
- package/src/server/event-routes.mjs +8 -1
- package/src/server/feature-use.mjs +45 -0
- package/src/server/index.mjs +7 -2
- package/src/server/lan-about.mjs +7 -15
- package/src/server/os-version.mjs +57 -0
- package/src/server/reports.mjs +216 -15
- package/src/server/tui-view.mjs +10 -7
- package/src/server/usage-day.mjs +35 -2
package/src/server/lan-about.mjs
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
import { readFileSync } from "node:fs";
|
|
24
24
|
import { release as osRelease } from "node:os";
|
|
25
25
|
import { open, seal } from "./lan-sync.mjs";
|
|
26
|
+
import { osVersionOf } from "./os-version.mjs";
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* The operating system, in the words its owner would use.
|
|
@@ -30,26 +31,17 @@ import { open, seal } from "./lan-sync.mjs";
|
|
|
30
31
|
* Node reports the KERNEL — `darwin 25.5.0`, `win32 10.0.26100` — and nobody
|
|
31
32
|
* calls their laptop Darwin 25. So the numbers are translated on the machine
|
|
32
33
|
* they describe, where the translation is certain, rather than on the one
|
|
33
|
-
* reading them.
|
|
34
|
-
* on any one of them.
|
|
34
|
+
* reading them (os-version.mjs, which the usage reports share). Every input is
|
|
35
|
+
* a parameter, so all three platforms are tested on any one of them.
|
|
35
36
|
*/
|
|
36
37
|
export function osLabel({ platform, release = "", prettyName = "" } = {}) {
|
|
37
|
-
const [major, minor, build] = String(release).split(".").map(n => Number.parseInt(n, 10));
|
|
38
|
-
const dot = Number.isInteger(minor) ? `.${minor}` : "";
|
|
39
38
|
if (platform === "darwin") {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// which Apple shipped as macOS 26 to match the year.
|
|
43
|
-
if (major >= 25) return `macOS ${major + 1}${dot}`;
|
|
44
|
-
if (major >= 20) return `macOS ${major - 9}${dot}`;
|
|
45
|
-
// The 10.x years, where the kernel's major minus four is the second number.
|
|
46
|
-
return major >= 5 ? `macOS 10.${major - 4}` : "macOS";
|
|
39
|
+
const v = osVersionOf({ platform, release });
|
|
40
|
+
return v ? `macOS ${v.major}${v.minor === null ? "" : `.${v.minor}`}` : "macOS";
|
|
47
41
|
}
|
|
48
42
|
if (platform === "win32") {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (major === 10 && Number.isInteger(build)) return build >= 22_000 ? "Windows 11" : "Windows 10";
|
|
52
|
-
return "Windows";
|
|
43
|
+
const v = osVersionOf({ platform, release });
|
|
44
|
+
return v ? `Windows ${v.major}` : "Windows";
|
|
53
45
|
}
|
|
54
46
|
if (platform === "linux") return prettyName || "Linux";
|
|
55
47
|
return typeof platform === "string" && platform ? platform : "unknown";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Which release of its operating system a machine runs, read off the kernel
|
|
2
|
+
// version Node reports.
|
|
3
|
+
//
|
|
4
|
+
// Node says `darwin 25.5.0` and `win32 10.0.26100`, and nobody calls their
|
|
5
|
+
// laptop Darwin 25. The translation is shared by the two places that say it:
|
|
6
|
+
// a paired deck's card (lan-about.mjs), which words it for a person ("macOS
|
|
7
|
+
// 26.5", "Windows 11"), and the usage reports (reports.mjs), which send it as a
|
|
8
|
+
// short token ("macos-26", "windows-11"). Pure: every input is a parameter, so
|
|
9
|
+
// all three platforms are tested on any one of them, and nothing here reads the
|
|
10
|
+
// machine or throws.
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The OS release a kernel version stands for, as `{ family, major, minor }`, or
|
|
14
|
+
* null when it cannot be told: `{ family: "macos", major: 26, minor: 5 }` for
|
|
15
|
+
* darwin 25.5.0, `{ family: "windows", major: 11, minor: null }` for win32
|
|
16
|
+
* 10.0.26100. `minor` is null when the release does not say one. Only macOS and
|
|
17
|
+
* Windows: a Linux kernel's version says nothing about the distribution on it.
|
|
18
|
+
*/
|
|
19
|
+
export function osVersionOf({ platform, release = "" } = {}) {
|
|
20
|
+
const [major, minor, build] = String(release).split(".").map(n => Number.parseInt(n, 10));
|
|
21
|
+
if (platform === "darwin") {
|
|
22
|
+
if (!Number.isInteger(major)) return null;
|
|
23
|
+
const dot = Number.isInteger(minor) ? minor : null;
|
|
24
|
+
// Darwin 20 was macOS 11 and every major after it was one more — until 25,
|
|
25
|
+
// which Apple shipped as macOS 26 to match the year.
|
|
26
|
+
if (major >= 25) return { family: "macos", major: major + 1, minor: dot };
|
|
27
|
+
if (major >= 20) return { family: "macos", major: major - 9, minor: dot };
|
|
28
|
+
// The 10.x years, where the kernel's major minus four is the second number.
|
|
29
|
+
return major >= 5 ? { family: "macos", major: 10, minor: major - 4 } : null;
|
|
30
|
+
}
|
|
31
|
+
if (platform === "win32") {
|
|
32
|
+
// Windows 11 kept the version 10.0 and moved only the build, and 22000 is
|
|
33
|
+
// the first one. From here it is the only way to tell the two apart.
|
|
34
|
+
if (major === 10 && Number.isInteger(build)) return { family: "windows", major: build >= 22_000 ? 11 : 10, minor: null };
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The fields of an os-release file (os-release(5)): `KEY=value` lines, the
|
|
42
|
+
* value bare or in single or double quotes, a double-quoted one with its
|
|
43
|
+
* backslash escapes undone. Comments, blank lines and anything else are
|
|
44
|
+
* skipped. Never throws.
|
|
45
|
+
*/
|
|
46
|
+
export function osReleaseFields(text) {
|
|
47
|
+
const out = {};
|
|
48
|
+
for (const line of String(text ?? "").split(/\r?\n/)) {
|
|
49
|
+
const m = /^\s*([A-Za-z0-9_]+)=(.*)$/.exec(line);
|
|
50
|
+
if (!m) continue;
|
|
51
|
+
let value = m[2].trim();
|
|
52
|
+
const quoted = /^(["'])(.*)\1$/.exec(value);
|
|
53
|
+
if (quoted) value = quoted[1] === '"' ? quoted[2].replace(/\\([\\"$`])/g, "$1") : quoted[2];
|
|
54
|
+
out[m[1]] = value;
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
package/src/server/reports.mjs
CHANGED
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
//
|
|
10
10
|
// - an "install" event the first time, with the ccdeck.dev page its command
|
|
11
11
|
// was copied from when the command said (`--ref`, install-ref.mjs) — a
|
|
12
|
-
// page name, never anything about the person
|
|
12
|
+
// page name, never anything about the person — and how it was installed:
|
|
13
|
+
// ccdeck.dev's one-line install on macOS (curl) or Windows (irm), a
|
|
14
|
+
// downloaded installer, npx or npm (depth-facts.mjs installVia; the
|
|
15
|
+
// one-line installs leave a one-word file, `install-via`, that the first
|
|
16
|
+
// report reads and then deletes),
|
|
13
17
|
// - an "update" event, with the version it came from, when the version moves,
|
|
14
18
|
// and how the new one arrived: the deck's own update, the desktop app's
|
|
15
19
|
// updater, npx, npm, or a source checkout,
|
|
@@ -20,7 +24,10 @@
|
|
|
20
24
|
// and that day's date — numbers, never their names (see usage-day.mjs) —
|
|
21
25
|
// and which of the deck's features were used that day, as fixed names
|
|
22
26
|
// ("usage-history", "account-switch") and nothing about what was done
|
|
23
|
-
// with them (feature-use.mjs)
|
|
27
|
+
// with them (feature-use.mjs) — among them where the deck was looked at
|
|
28
|
+
// from that day: the desktop app's window ("desktop-window"), a browser
|
|
29
|
+
// tab ("browser-tab") or `ccdeck tui` ("tui"), a window or tab counted on
|
|
30
|
+
// every day it stayed open — and how the deck held up and who runs it:
|
|
24
31
|
// how long this run took to start, that day's peak memory and how many
|
|
25
32
|
// events it took in, each as a bucket ("2s", "512m", "1k"), the Claude and
|
|
26
33
|
// Codex plan as its category ("max-20x", "plus") and nothing else from the
|
|
@@ -44,14 +51,22 @@
|
|
|
44
51
|
// names, the host of every web address, every IP address and the machine
|
|
45
52
|
// name a network error carries, email addresses and key-shaped strings
|
|
46
53
|
// scrubbed out before they leave (see scrub),
|
|
47
|
-
// - a "ping" heartbeat,
|
|
48
|
-
//
|
|
49
|
-
//
|
|
54
|
+
// - a "ping" heartbeat, a minute or two after the deck starts and every ten
|
|
55
|
+
// minutes or so after that while it runs, which moves the install's "last
|
|
56
|
+
// seen" so the admin can show who is online now, and is counted per day,
|
|
57
|
+
// which is how long the deck stays open.
|
|
50
58
|
// It writes no event and carries the install id alone — no facts, no
|
|
51
59
|
// fingerprint.
|
|
52
60
|
//
|
|
53
61
|
// Each event carries the install id, the version, the OS and CPU architecture,
|
|
54
62
|
// the channel (the desktop app, npm, or a source checkout) and the runtime, plus
|
|
63
|
+
// which release of the OS it is: on macOS and Windows the release as a token
|
|
64
|
+
// (`osVersion`, "macos-15", "windows-11", translated from the kernel version as
|
|
65
|
+
// os-version.mjs does for a paired deck's card), on Linux the distribution
|
|
66
|
+
// (`distro`, os-release's ID and VERSION_ID, "ubuntu-24.04" or "arch", or
|
|
67
|
+
// "omarchy" when Omarchy's folder is there — never os-release's free-text
|
|
68
|
+
// names) and `wsl: true` under WSL (each left out where it does not apply, and
|
|
69
|
+
// never on the ping, errors or feedback), and
|
|
55
70
|
// a coarse sketch of the environment: the logical CPU count, the RAM in MB, the
|
|
56
71
|
// locale, the language chosen in the deck's own page (`uiLanguage`, "ro" or
|
|
57
72
|
// "pt-BR": the page tells the server, which keeps it in prefs.json and omits it
|
|
@@ -92,8 +107,11 @@
|
|
|
92
107
|
// be refused the same way. A 4xx the edge in front of it answers with is tried again.
|
|
93
108
|
|
|
94
109
|
import { createHash, randomUUID } from "node:crypto";
|
|
110
|
+
import { readFileSync, statSync } from "node:fs";
|
|
95
111
|
import { chmod, mkdir, readFile, unlink } from "node:fs/promises";
|
|
96
|
-
import {
|
|
112
|
+
import {
|
|
113
|
+
arch as osArch, cpus as osCpus, homedir, hostname, platform as osPlatform, release as osKernelRelease, totalmem,
|
|
114
|
+
} from "node:os";
|
|
97
115
|
import { basename, dirname, join, resolve } from "node:path";
|
|
98
116
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
99
117
|
import { inApp } from "./app-host.mjs";
|
|
@@ -107,9 +125,12 @@ import { RUNNING_VERSION } from "./running-version.mjs";
|
|
|
107
125
|
import { FEATURES, usageDay, utcDay } from "./usage-day.mjs";
|
|
108
126
|
import { setupFacts, sinceInstallBucket, whenSetupKnown } from "./activation.mjs";
|
|
109
127
|
import { notedRef, refSlug } from "./install-ref.mjs";
|
|
128
|
+
import { isWsl } from "./open-url.mjs";
|
|
129
|
+
import { osReleaseFields, osVersionOf } from "./os-version.mjs";
|
|
110
130
|
import { UI_LANGUAGE_MAX, uiLanguageCode } from "./ui-language.mjs";
|
|
111
131
|
import {
|
|
112
|
-
CLAUDE_PLANS, CODEX_PLANS, cappedCount, deckDepth, eventsBucket,
|
|
132
|
+
CLAUDE_PLANS, CODEX_PLANS, cappedCount, deckDepth, eventsBucket, installMarkFile, installVia, launchBucket,
|
|
133
|
+
memoryBucket, updateVia,
|
|
113
134
|
} from "./depth-facts.mjs";
|
|
114
135
|
import { daysUsedBucket, normaliseRating, ratingDue, ratingStage, scoreOf } from "./rating.mjs";
|
|
115
136
|
|
|
@@ -126,6 +147,13 @@ const CHECK_IN_EVERY_MS = 6 * 60 * 60 * 1000;
|
|
|
126
147
|
* not all beat on the same tick. */
|
|
127
148
|
const PING_EVERY_MS = 10 * 60 * 1000;
|
|
128
149
|
const PING_JITTER_MS = 2 * 60 * 1000;
|
|
150
|
+
/** One ping of its own soon after a start, one to two minutes in, ahead of the
|
|
151
|
+
* first beat. A restart on a day and a version already reported sends nothing
|
|
152
|
+
* at its check-in, so until the first beat the admin showed a restarted deck
|
|
153
|
+
* offline for ten minutes or more. Not at once: the boot check-in goes first,
|
|
154
|
+
* and a fleet started together still spreads out. The beats keep their pace. */
|
|
155
|
+
const FIRST_PING_MS = 60 * 1000;
|
|
156
|
+
const FIRST_PING_JITTER_MS = 60 * 1000;
|
|
129
157
|
/** The longest a 429's or a 503's Retry-After is waited for: a header that asks
|
|
130
158
|
* for a week does not silence a deck for one. */
|
|
131
159
|
const RETRY_AFTER_MAX_MS = 24 * 60 * 60 * 1000;
|
|
@@ -170,7 +198,10 @@ export function reportsOn(prefs, env = process.env) {
|
|
|
170
198
|
// The keys the API caps, so a value that would be rejected for length is not
|
|
171
199
|
// sent: it is trimmed to the cap here instead. Only ever tokens the shape of a
|
|
172
200
|
// terminal name, a shell name, a locale or a version — never anything free.
|
|
173
|
-
const TOKEN_CAPS = {
|
|
201
|
+
const TOKEN_CAPS = {
|
|
202
|
+
locale: 16, shell: 16, term: 32, claudeVersion: 32, codexVersion: 32, deviceId: 64, uiLanguage: UI_LANGUAGE_MAX,
|
|
203
|
+
osVersion: 24, distro: 32,
|
|
204
|
+
};
|
|
174
205
|
|
|
175
206
|
/** A value reduced to the API's token shape `^[0-9A-Za-z.+_-]+$`: spaces become
|
|
176
207
|
* "_" (so "Apple Terminal" rides as "Apple_Terminal"), every other disallowed
|
|
@@ -310,6 +341,99 @@ function baseName(p) {
|
|
|
310
341
|
return String(p).split(/[\\/]/).pop().replace(/\.exe$/i, "");
|
|
311
342
|
}
|
|
312
343
|
|
|
344
|
+
/** The API's token shape. A distribution's own words leave only when they are
|
|
345
|
+
* already in it: nothing is reshaped into one, as `token` does for a terminal. */
|
|
346
|
+
const TOKEN_SHAPE = /^[0-9A-Za-z.+_-]+$/;
|
|
347
|
+
|
|
348
|
+
/** `value` when it is already a token no longer than `max`, else nothing. */
|
|
349
|
+
function shaped(value, max) {
|
|
350
|
+
return typeof value === "string" && TOKEN_SHAPE.test(value) && value.length <= max ? value : undefined;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** The OS release as a token, on macOS and Windows only — "macos-15",
|
|
354
|
+
* "macos-26", "windows-10", "windows-11" — by the translation a paired deck's
|
|
355
|
+
* card uses (os-version.mjs). Nothing on Linux, which says its distribution
|
|
356
|
+
* instead (distroToken), and nothing for a release that cannot be told. */
|
|
357
|
+
export function osVersionToken({ platform = process.platform, release = "" } = {}) {
|
|
358
|
+
const v = osVersionOf({ platform, release });
|
|
359
|
+
return v ? shaped(`${v.family}-${v.major}`, TOKEN_CAPS.osVersion) : undefined;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* The Linux distribution as a token: os-release's `ID`, lowercased, with its
|
|
364
|
+
* `VERSION_ID` after a dash when it has one — "ubuntu-24.04", "fedora-41",
|
|
365
|
+
* "debian-12", and "arch", which has none. Omarchy sits on Arch and leaves
|
|
366
|
+
* Arch's os-release in place, so it is told by the folder it installs into
|
|
367
|
+
* (`omarchy`, read by the caller) or by an os-release that names it, and is
|
|
368
|
+
* sent as "omarchy".
|
|
369
|
+
*
|
|
370
|
+
* Only what is already token-shaped leaves: an ID that is not, or is longer
|
|
371
|
+
* than the cap, is nothing at all; a version that is not, or that would take
|
|
372
|
+
* the token past the cap, leaves the ID alone. The free-text fields — NAME,
|
|
373
|
+
* PRETTY_NAME — are only ever looked through for "omarchy", never sent.
|
|
374
|
+
* Never throws.
|
|
375
|
+
*/
|
|
376
|
+
export function distroToken({ osRelease = "", omarchy = false } = {}) {
|
|
377
|
+
try {
|
|
378
|
+
const f = osReleaseFields(osRelease);
|
|
379
|
+
if (omarchy === true || [f.ID, f.VARIANT_ID, f.NAME, f.PRETTY_NAME].some(v => /omarchy/i.test(v ?? ""))) return "omarchy";
|
|
380
|
+
const id = shaped(String(f.ID ?? "").trim().toLowerCase(), TOKEN_CAPS.distro);
|
|
381
|
+
if (!id) return undefined;
|
|
382
|
+
const version = String(f.VERSION_ID ?? "").trim().toLowerCase();
|
|
383
|
+
return (version && shaped(`${id}-${version}`, TOKEN_CAPS.distro)) || id;
|
|
384
|
+
} catch {
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* This Linux's distribution as distroToken words it: os-release from where the
|
|
391
|
+
* spec puts it, `/etc/os-release` and then `/usr/lib/os-release`, and Omarchy's
|
|
392
|
+
* folder under the home folder, which only ever answers yes or no. The reads
|
|
393
|
+
* are parameters so a test can stand up any machine. Never throws.
|
|
394
|
+
*/
|
|
395
|
+
export function readDistro({ read = readFileSync, isDir = isDirectory, home = homedir() } = {}) {
|
|
396
|
+
let osRelease = "";
|
|
397
|
+
for (const file of ["/etc/os-release", "/usr/lib/os-release"]) {
|
|
398
|
+
try {
|
|
399
|
+
osRelease = String(read(file, "utf8"));
|
|
400
|
+
break;
|
|
401
|
+
} catch { /* not this one */ }
|
|
402
|
+
}
|
|
403
|
+
let omarchy = false;
|
|
404
|
+
try {
|
|
405
|
+
omarchy = isDir(join(home, ".local", "share", "omarchy")) === true;
|
|
406
|
+
} catch { /* no home, no Omarchy */ }
|
|
407
|
+
return distroToken({ osRelease, omarchy });
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function isDirectory(path) {
|
|
411
|
+
try { return statSync(path).isDirectory(); } catch { return false; }
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** This machine's distribution, read the first time it is asked and kept:
|
|
415
|
+
* nothing it is read from changes under a running deck. */
|
|
416
|
+
let distroKept = null;
|
|
417
|
+
function machineDistro() {
|
|
418
|
+
if (!distroKept) {
|
|
419
|
+
let value;
|
|
420
|
+
try { value = readDistro(); } catch { value = undefined; }
|
|
421
|
+
distroKept = { value };
|
|
422
|
+
}
|
|
423
|
+
return distroKept.value;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** The kernel's release, or "" when it will not say. */
|
|
427
|
+
function kernelRelease() {
|
|
428
|
+
try { return osKernelRelease(); } catch { return ""; }
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/** Whether this Linux is WSL (open-url.mjs, which opens the browser on the
|
|
432
|
+
* Windows side for it). Never throws. */
|
|
433
|
+
function underWsl(platform, env) {
|
|
434
|
+
try { return isWsl(platform, env ?? {}) === true; } catch { return false; }
|
|
435
|
+
}
|
|
436
|
+
|
|
313
437
|
function addIf(target, key, value) {
|
|
314
438
|
if (value !== undefined) target[key] = value;
|
|
315
439
|
}
|
|
@@ -319,13 +443,18 @@ function addIf(target, key, value) {
|
|
|
319
443
|
* counts the API records as optional. `claudeVersion`/`codexVersion` are
|
|
320
444
|
* supplied by the reporter once its background probe has them (cli-versions.mjs)
|
|
321
445
|
* and omitted until then; everything else is read here from the OS and the
|
|
322
|
-
* environment.
|
|
446
|
+
* environment. The OS release, the distribution and WSL are read off this
|
|
447
|
+
* machine only when `platform` is this machine's, so a test that names
|
|
448
|
+
* another platform is never handed this one's. */
|
|
323
449
|
export function installFacts({
|
|
324
450
|
version = RUNNING_VERSION,
|
|
325
451
|
platform = process.platform,
|
|
326
452
|
arch = process.arch,
|
|
327
453
|
versions = process.versions,
|
|
328
454
|
env = process.env,
|
|
455
|
+
release = platform === process.platform ? kernelRelease() : "",
|
|
456
|
+
distro = platform === "linux" && platform === process.platform ? machineDistro() : undefined,
|
|
457
|
+
wsl = platform === "linux" && platform === process.platform ? underWsl(platform, env) : false,
|
|
329
458
|
checkout = isGitCheckout(PKG_ROOT),
|
|
330
459
|
cpus = cpuCount(),
|
|
331
460
|
memMb = totalMemMb(),
|
|
@@ -346,6 +475,12 @@ export function installFacts({
|
|
|
346
475
|
channel: inApp(env) ? "desktop" : checkout ? "checkout" : "npm",
|
|
347
476
|
runtime: versions.electron ? `electron-${versions.electron}` : `node-${versions.node}`,
|
|
348
477
|
};
|
|
478
|
+
// Which release of the system: "macos-26", "windows-11" on those two, and on
|
|
479
|
+
// Linux the distribution ("ubuntu-24.04", "arch", "omarchy") and, under WSL,
|
|
480
|
+
// `wsl: true`. Fixed tokens and one yes, never a name the machine was given.
|
|
481
|
+
addIf(facts, "osVersion", osVersionToken({ platform, release }));
|
|
482
|
+
addIf(facts, "distro", platform === "linux" ? shaped(distro, TOKEN_CAPS.distro) : undefined);
|
|
483
|
+
addIf(facts, "wsl", platform === "linux" && wsl === true ? true : undefined);
|
|
349
484
|
addIf(facts, "cpus", count(cpus));
|
|
350
485
|
addIf(facts, "memMb", count(memMb));
|
|
351
486
|
addIf(facts, "locale", token(locale, TOKEN_CAPS.locale));
|
|
@@ -551,6 +686,12 @@ export function scrub(text, home = homedir(), root = PKG_ROOT) {
|
|
|
551
686
|
* where the question's outcome is kept a second time, out of reach of an
|
|
552
687
|
* older deck's write of prefs.json (ratingFile). Default: none — the deck's
|
|
553
688
|
* own reporter passes ratingFile(), so no test writes beside a real prefs.json.
|
|
689
|
+
* @param {{ read: () => Promise<{ content: string, mtimeMs: number } | null>, remove: () => Promise<void> } | null} [deps.installMark]
|
|
690
|
+
* the mark ccdeck.dev's one-line installs leave (depth-facts.mjs
|
|
691
|
+
* installMarkFile): read for the desktop app's install event, and deleted
|
|
692
|
+
* once that event is settled, or at once when this install has reported
|
|
693
|
+
* before. Default: none — the deck's own reporter passes installMarkFile(),
|
|
694
|
+
* so no test reads or deletes a file in a real home.
|
|
554
695
|
*/
|
|
555
696
|
export function createReporter({
|
|
556
697
|
fetchImpl = globalThis.fetch,
|
|
@@ -575,11 +716,14 @@ export function createReporter({
|
|
|
575
716
|
uptime = () => process.uptime() * 1000,
|
|
576
717
|
firstRun = bootFoundNoPrefs,
|
|
577
718
|
ratingKept = null,
|
|
719
|
+
installMark = null,
|
|
578
720
|
} = {}) {
|
|
579
721
|
const errorsSent = [];
|
|
580
722
|
const lastSentAt = new Map();
|
|
581
723
|
let timer = null;
|
|
582
724
|
let pingTimer = null;
|
|
725
|
+
/** The one ping a start sends ahead of the first beat (FIRST_PING_MS). */
|
|
726
|
+
let firstPingTimer = null;
|
|
583
727
|
/** How long this run took to start, read when start() runs; null before. */
|
|
584
728
|
let launchMs = null;
|
|
585
729
|
|
|
@@ -704,6 +848,36 @@ export function createReporter({
|
|
|
704
848
|
}
|
|
705
849
|
}
|
|
706
850
|
|
|
851
|
+
/** The one-line installs' mark, for the install event. Only the desktop app
|
|
852
|
+
* reads it or deletes it: the app is what those scripts install, and an npm
|
|
853
|
+
* deck beside it, on settings of its own, is not the install the mark is
|
|
854
|
+
* about. */
|
|
855
|
+
const markHere = () => facts.channel === "desktop" && installMark != null;
|
|
856
|
+
/** Whether this run has already taken the mark away. */
|
|
857
|
+
let markGone = false;
|
|
858
|
+
|
|
859
|
+
/** The mark as read, or null. Never throws. */
|
|
860
|
+
async function markNow() {
|
|
861
|
+
if (!markHere()) return null;
|
|
862
|
+
try {
|
|
863
|
+
return (await installMark.read()) ?? null;
|
|
864
|
+
} catch {
|
|
865
|
+
return null;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/** Take the mark away, best effort, once a run. Never throws: a mark that
|
|
870
|
+
* will not go is ignored once it is a week old. */
|
|
871
|
+
async function dropMark() {
|
|
872
|
+
if (!markHere() || markGone) return;
|
|
873
|
+
markGone = true;
|
|
874
|
+
try {
|
|
875
|
+
await installMark.remove();
|
|
876
|
+
} catch {
|
|
877
|
+
// Left where it is.
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
|
|
707
881
|
/** The coarse usage the "active" report carries: the last finished day before
|
|
708
882
|
* `today`, its date as `usageDay` and its counts beside it. Nothing at all
|
|
709
883
|
* when there is no such day yet — a first launch has no yesterday — and only
|
|
@@ -987,9 +1161,14 @@ export function createReporter({
|
|
|
987
1161
|
const ref = refSlug(prefs.current().report.ref) ?? refNow();
|
|
988
1162
|
const body = { installId, kind: "install", ...factsNow(), ...setupNow() };
|
|
989
1163
|
addIf(body, "ref", ref);
|
|
1164
|
+
// How it arrived: npx or npm, or for the desktop app the one-line install
|
|
1165
|
+
// whose script left a fresh mark, else a download (depth-facts.mjs).
|
|
1166
|
+
addIf(body, "via", installVia({ channel: facts.channel, npx, mark: await markNow(), now: now() }));
|
|
990
1167
|
// Refused by the API is as done as sent: the same body would be refused again.
|
|
991
1168
|
if (settled(await call("POST", "/v1/app/events", body))) {
|
|
992
1169
|
await remember(installId, { lastVersion: facts.version, ref: "" });
|
|
1170
|
+
// Said once, and only a new install has a way it arrived.
|
|
1171
|
+
await dropMark();
|
|
993
1172
|
} else if (ref) {
|
|
994
1173
|
await remember(installId, { ref });
|
|
995
1174
|
}
|
|
@@ -1004,6 +1183,9 @@ export function createReporter({
|
|
|
1004
1183
|
await remember(installId, { lastVersion: facts.version, selfUpdate: null });
|
|
1005
1184
|
}
|
|
1006
1185
|
}
|
|
1186
|
+
// This install has reported before: a mark beside it was left by a
|
|
1187
|
+
// reinstall over it, which is not a new install.
|
|
1188
|
+
if (lastVersion) await dropMark();
|
|
1007
1189
|
|
|
1008
1190
|
if (lastActiveDay !== today) {
|
|
1009
1191
|
// Usage rides on the "active" event alone, and is read only here — the one
|
|
@@ -1245,8 +1427,13 @@ export function createReporter({
|
|
|
1245
1427
|
lastSentAt.set(key, at);
|
|
1246
1428
|
const stack = typeof error?.stack === "string" ? scrub(error.stack, home, root).slice(0, STACK_MAX) : undefined;
|
|
1247
1429
|
// Less the runtime, and less the deviceId — an error is not one of the events
|
|
1248
|
-
// the fingerprint rides on, so the personal field never leaves on one.
|
|
1249
|
-
|
|
1430
|
+
// the fingerprint rides on, so the personal field never leaves on one. The
|
|
1431
|
+
// page's language and the OS release, distribution and WSL ride on the
|
|
1432
|
+
// events alone, as their contract with the API says.
|
|
1433
|
+
const {
|
|
1434
|
+
runtime: _runtime, deviceId: _deviceId, uiLanguage: _uiLanguage,
|
|
1435
|
+
osVersion: _osVersion, distro: _distro, wsl: _wsl, ...fields
|
|
1436
|
+
} = factsNow();
|
|
1250
1437
|
return (await call("POST", "/v1/app/errors", { installId: p.report.installId, ...fields, where, message, stack })) === "sent";
|
|
1251
1438
|
}
|
|
1252
1439
|
|
|
@@ -1278,9 +1465,13 @@ export function createReporter({
|
|
|
1278
1465
|
|
|
1279
1466
|
/** Check in once the prefs are read, and every few hours after; and beat a
|
|
1280
1467
|
* heartbeat on its own, lighter timer, which also sends whatever a check-in
|
|
1281
|
-
* still owes (beat). Both timers never hold the process open.
|
|
1282
|
-
*
|
|
1283
|
-
* a
|
|
1468
|
+
* still owes (beat). Both timers never hold the process open. Ahead of the
|
|
1469
|
+
* first beat, one ping alone, one to two minutes after the start
|
|
1470
|
+
* (FIRST_PING_MS), so a restarted deck — whose check-in has nothing new to
|
|
1471
|
+
* send on a day already reported — is online again within two minutes. It
|
|
1472
|
+
* is the heartbeat's ping and nothing more: the same body, under the same
|
|
1473
|
+
* rules (reports on, an install id, no Retry-After running), and nothing
|
|
1474
|
+
* pings at the boot itself. */
|
|
1284
1475
|
function start() {
|
|
1285
1476
|
// start() runs as the deck starts listening (index.mjs), so this is the
|
|
1286
1477
|
// launch: process start to ready. A second start() keeps the first answer.
|
|
@@ -1307,7 +1498,14 @@ export function createReporter({
|
|
|
1307
1498
|
timer = setInterval(() => { if (retryDue()) void checkIn(); }, CHECK_IN_EVERY_MS);
|
|
1308
1499
|
timer.unref?.();
|
|
1309
1500
|
}
|
|
1310
|
-
if (!pingTimer)
|
|
1501
|
+
if (!pingTimer) {
|
|
1502
|
+
scheduleNextPing();
|
|
1503
|
+
firstPingTimer = setTimeout(() => {
|
|
1504
|
+
firstPingTimer = null;
|
|
1505
|
+
void ping();
|
|
1506
|
+
}, FIRST_PING_MS + Math.floor(Math.random() * FIRST_PING_JITTER_MS));
|
|
1507
|
+
firstPingTimer.unref?.();
|
|
1508
|
+
}
|
|
1311
1509
|
}
|
|
1312
1510
|
|
|
1313
1511
|
function stop() {
|
|
@@ -1315,6 +1513,8 @@ export function createReporter({
|
|
|
1315
1513
|
timer = null;
|
|
1316
1514
|
if (pingTimer) clearTimeout(pingTimer);
|
|
1317
1515
|
pingTimer = null;
|
|
1516
|
+
if (firstPingTimer) clearTimeout(firstPingTimer);
|
|
1517
|
+
firstPingTimer = null;
|
|
1318
1518
|
}
|
|
1319
1519
|
|
|
1320
1520
|
return {
|
|
@@ -1383,4 +1583,5 @@ export const reporter = createReporter({
|
|
|
1383
1583
|
return integrationsStore.connectedKinds();
|
|
1384
1584
|
},
|
|
1385
1585
|
ratingKept: ratingFile(),
|
|
1586
|
+
installMark: installMarkFile(),
|
|
1386
1587
|
});
|
package/src/server/tui-view.mjs
CHANGED
|
@@ -205,8 +205,9 @@ export function tuiKey(state, str, key = {}, { now = 0, g } = {}) {
|
|
|
205
205
|
if (str === "q" || name === "escape") return { state, effect: { type: "quit" } };
|
|
206
206
|
if (str === "?") return { state: { ...state, help: true }, effect: null };
|
|
207
207
|
|
|
208
|
-
// The
|
|
209
|
-
//
|
|
208
|
+
// The tabs: the arrows walk along them, as a tab bar anywhere else does —
|
|
209
|
+
// the way the footer offers. c (Codex's list, and back) and l (the Local
|
|
210
|
+
// network, and back) stay as shortcuts for whoever learnt them.
|
|
210
211
|
if (str === "c") return sideKey({ ...state, notice: null }, null, { now, g });
|
|
211
212
|
if (str === "l") return lanSideKey({ ...state, notice: null }, { now, g });
|
|
212
213
|
if (name === "left" || name === "right") return stepSide({ ...state, notice: null }, name === "right" ? 1 : -1);
|
|
@@ -782,18 +783,20 @@ function noticeLine(state, { tone, g, unicode, now }) {
|
|
|
782
783
|
* Each key is a cap where the terminal can draw one. */
|
|
783
784
|
function footerLine(state, width, look) {
|
|
784
785
|
const { tone, unicode, skin } = look;
|
|
786
|
+
// The tabs are walked with the arrows, offered once there is more than one.
|
|
787
|
+
const tabsKey = unicode ? "←→" : "left/right";
|
|
788
|
+
const tabs = sidesOf(state).length > 1 ? [[tabsKey, "tabs"]] : [];
|
|
785
789
|
const keys = state.signin ? signinKeys(state.signin) : state.codexSignin ? codexSigninKeys(state.codexSignin)
|
|
786
790
|
: lanInvitePage(state) ? lanInviteKeys() : onLan(state) ? [
|
|
787
791
|
...lanFooterKeys(state, { now: look.now, unicode }),
|
|
788
|
-
|
|
792
|
+
...tabs,
|
|
789
793
|
["?", "keys"],
|
|
790
794
|
["q", "quit"],
|
|
791
795
|
] : [
|
|
792
796
|
[unicode ? "↑↓" : "up/down", "move"],
|
|
793
797
|
["enter", "switch"],
|
|
794
798
|
["m", "actions"],
|
|
795
|
-
...
|
|
796
|
-
...(hasLan(state) ? [["l", "network"]] : []),
|
|
799
|
+
...tabs,
|
|
797
800
|
["b", "best"],
|
|
798
801
|
state.deck ? ["a", "auto-switch"] : ["d", "start the deck"],
|
|
799
802
|
["+", "add"],
|
|
@@ -806,7 +809,7 @@ function footerLine(state, width, look) {
|
|
|
806
809
|
const list = keys.slice();
|
|
807
810
|
// r goes first, then the moves, then b: the screen says what they do, and ?
|
|
808
811
|
// and q are how to find out and how to leave.
|
|
809
|
-
for (const drop of ["r", unicode ? "↑↓" : "up/down", "b", "+", "a", "d", "m",
|
|
812
|
+
for (const drop of ["r", unicode ? "↑↓" : "up/down", "b", "+", "a", "d", "m", tabsKey, "n", "x", "space", "enter"]) {
|
|
810
813
|
if (textWidth(draw(list)) <= width) break;
|
|
811
814
|
const i = list.findIndex(([k]) => k === drop);
|
|
812
815
|
if (i !== -1) list.splice(i, 1);
|
|
@@ -1620,7 +1623,7 @@ function withHelp(base, width, look) {
|
|
|
1620
1623
|
["a", "turn Auto-switch on or off"],
|
|
1621
1624
|
["+", "add an account, signed in from any browser"],
|
|
1622
1625
|
["r", "read the usage again"],
|
|
1623
|
-
[unicode ? "
|
|
1626
|
+
[unicode ? "← →" : "left right", `the tabs ${g.bullet} c Codex ${g.bullet} l Local network`],
|
|
1624
1627
|
["t", "the machine: live, or the last hours"],
|
|
1625
1628
|
["d", "start the deck, when none is running"],
|
|
1626
1629
|
["ctrl+l", "draw the screen again"],
|
package/src/server/usage-day.mjs
CHANGED
|
@@ -53,6 +53,10 @@ export const FEATURES = Object.freeze([
|
|
|
53
53
|
"jira", "github", "gitlab",
|
|
54
54
|
// Which CLI the day's sessions came from.
|
|
55
55
|
"claude-sessions", "codex-sessions",
|
|
56
|
+
// Where somebody looked at the deck that day: the desktop app's window, a
|
|
57
|
+
// browser tab, `ccdeck tui` (feature-use.mjs). One left open across midnight
|
|
58
|
+
// counts for the day after too (holdFeature).
|
|
59
|
+
"desktop-window", "browser-tab", "tui",
|
|
56
60
|
]);
|
|
57
61
|
const FEATURE_SET = new Set(FEATURES);
|
|
58
62
|
|
|
@@ -130,6 +134,9 @@ export function createUsageDay({ now = () => new Date() } = {}) {
|
|
|
130
134
|
/** The first use this run heard, `{ at, provider }`, for activation.mjs. */
|
|
131
135
|
let first = null;
|
|
132
136
|
const firstListeners = [];
|
|
137
|
+
/** Features in use right now, for as long as they last — a page connected —
|
|
138
|
+
* with how many hold each: every new day starts with them used. */
|
|
139
|
+
const held = new Map();
|
|
133
140
|
|
|
134
141
|
function fresh(day, floor = null) {
|
|
135
142
|
return {
|
|
@@ -164,6 +171,9 @@ export function createUsageDay({ now = () => new Date() } = {}) {
|
|
|
164
171
|
if (current?.day === day) return current;
|
|
165
172
|
if (current && current.day < day) done = totals(current);
|
|
166
173
|
current = fresh(day);
|
|
174
|
+
// What is still in use as the day turns was used on this day too: a window
|
|
175
|
+
// left open overnight is a window open today.
|
|
176
|
+
for (const name of held.keys()) current.features.add(name);
|
|
167
177
|
changes++;
|
|
168
178
|
return current;
|
|
169
179
|
}
|
|
@@ -217,6 +227,29 @@ export function createUsageDay({ now = () => new Date() } = {}) {
|
|
|
217
227
|
return true;
|
|
218
228
|
}
|
|
219
229
|
|
|
230
|
+
/**
|
|
231
|
+
* A feature in use for as long as something lasts — a page connected to the
|
|
232
|
+
* deck — rather than at one moment: used today, and on every later day it is
|
|
233
|
+
* still in use when that day starts. Returns the release, to call once when
|
|
234
|
+
* it ends, which notes it on the day it ends as well: an end the day's first
|
|
235
|
+
* reading comes after would otherwise leave that day without it. A name off
|
|
236
|
+
* FEATURES holds nothing and its release does nothing.
|
|
237
|
+
*/
|
|
238
|
+
function holdFeature(name) {
|
|
239
|
+
if (!FEATURE_SET.has(name)) return () => {};
|
|
240
|
+
noteFeature(name);
|
|
241
|
+
held.set(name, (held.get(name) ?? 0) + 1);
|
|
242
|
+
let released = false;
|
|
243
|
+
return () => {
|
|
244
|
+
if (released) return;
|
|
245
|
+
released = true;
|
|
246
|
+
noteFeature(name);
|
|
247
|
+
const left = (held.get(name) ?? 1) - 1;
|
|
248
|
+
if (left > 0) held.set(name, left);
|
|
249
|
+
else held.delete(name);
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
220
253
|
/** A Codex session's working directory, which is its project. */
|
|
221
254
|
function noteFolder(dir) {
|
|
222
255
|
if (!dir || typeof dir !== "string") return;
|
|
@@ -308,8 +341,8 @@ export function createUsageDay({ now = () => new Date() } = {}) {
|
|
|
308
341
|
}
|
|
309
342
|
|
|
310
343
|
return {
|
|
311
|
-
noteUse, noteProject, noteFolder, noteFeature, notePeak, firstUse, onFirstUse, finished, markSent, saved,
|
|
312
|
-
daysUsed,
|
|
344
|
+
noteUse, noteProject, noteFolder, noteFeature, holdFeature, notePeak, firstUse, onFirstUse, finished, markSent, saved,
|
|
345
|
+
restore, version, daysUsed,
|
|
313
346
|
};
|
|
314
347
|
}
|
|
315
348
|
|