ccdeck 3.53.3 → 3.81.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 (78) hide show
  1. package/README.md +63 -7
  2. package/THIRD_PARTY_NOTICES.md +31 -1
  3. package/bin/cli/tui.js +433 -11
  4. package/dist/web/assets/{BrowserWatchModal-CJ0CW4Go.js → BrowserWatchModal-DKvBSlGT.js} +1 -1
  5. package/dist/web/assets/{IntegrationModal-DlJzBN8b.js → IntegrationModal-D3NLczRe.js} +1 -1
  6. package/dist/web/assets/{RadioPanel-CHl3s3OH.js → RadioPanel-dCIMGTd9.js} +1 -1
  7. package/dist/web/assets/{TrafficRadar-Cw3i0Hux.js → TrafficRadar-CMbwnKe7.js} +1 -1
  8. package/dist/web/assets/{UsageHistoryModal-CiB5-CTH.js → UsageHistoryModal-DkGBQaM4.js} +1 -1
  9. package/dist/web/assets/{app-xTrs4aEH.css → app-BIrh5Q0W.css} +1 -1
  10. package/dist/web/assets/{app-2vj7uk2U.js → app-l0spNrc0.js} +93 -93
  11. package/dist/web/assets/{index-D1YZbdq3.js → index-inV7HzhI.js} +1 -1
  12. package/dist/web/index.html +3 -3
  13. package/node_modules/ws/LICENSE +20 -0
  14. package/node_modules/ws/README.md +540 -0
  15. package/node_modules/ws/browser.js +8 -0
  16. package/node_modules/ws/index.js +22 -0
  17. package/node_modules/ws/lib/buffer-util.js +142 -0
  18. package/node_modules/ws/lib/constants.js +19 -0
  19. package/node_modules/ws/lib/event-target.js +292 -0
  20. package/node_modules/ws/lib/extension.js +203 -0
  21. package/node_modules/ws/lib/limiter.js +55 -0
  22. package/node_modules/ws/lib/permessage-deflate.js +530 -0
  23. package/node_modules/ws/lib/receiver.js +743 -0
  24. package/node_modules/ws/lib/sender.js +610 -0
  25. package/node_modules/ws/lib/stream.js +161 -0
  26. package/node_modules/ws/lib/subprotocol.js +62 -0
  27. package/node_modules/ws/lib/validation.js +152 -0
  28. package/node_modules/ws/lib/websocket-server.js +562 -0
  29. package/node_modules/ws/lib/websocket.js +1426 -0
  30. package/node_modules/ws/package.json +74 -0
  31. package/node_modules/ws/wrapper.mjs +21 -0
  32. package/package.json +5 -3
  33. package/release-notes.json +71 -0
  34. package/src/server/account-engine.mjs +87 -0
  35. package/src/server/account-notify.mjs +81 -16
  36. package/src/server/account-routes.mjs +49 -3
  37. package/src/server/account-watch.mjs +21 -0
  38. package/src/server/codex-auto.mjs +163 -54
  39. package/src/server/codex-engine-adapter.mjs +272 -0
  40. package/src/server/codex-engine-bridge.mjs +47 -0
  41. package/src/server/codex-engine-config.mjs +42 -0
  42. package/src/server/codex-engine-rpc.mjs +88 -0
  43. package/src/server/codex-handoff.mjs +20 -0
  44. package/src/server/codex-interactive-engine.mjs +335 -0
  45. package/src/server/codex-lan-identity.mjs +61 -0
  46. package/src/server/codex-live-checkpoint.mjs +55 -0
  47. package/src/server/codex-live-credentials.mjs +214 -0
  48. package/src/server/codex-live-engine.mjs +577 -0
  49. package/src/server/codex-live-handoff.mjs +300 -0
  50. package/src/server/codex-live-lease.mjs +64 -0
  51. package/src/server/codex-live-rpc.mjs +158 -0
  52. package/src/server/codex-profiles.mjs +34 -4
  53. package/src/server/codex-projects.mjs +308 -0
  54. package/src/server/codex-quota.mjs +36 -2
  55. package/src/server/codex-selection.mjs +78 -9
  56. package/src/server/codex-share.mjs +238 -0
  57. package/src/server/codex-terminal-runner.mjs +38 -1
  58. package/src/server/codex-terminal.mjs +15 -3
  59. package/src/server/codex-usage.mjs +69 -0
  60. package/src/server/codex-watch.mjs +3 -1
  61. package/src/server/codex-windows-private.mjs +96 -0
  62. package/src/server/codex-windows-private.ps1 +140 -0
  63. package/src/server/codex-windows-proxy.mjs +53 -0
  64. package/src/server/index.mjs +12 -4
  65. package/src/server/lan-codex-store.mjs +170 -0
  66. package/src/server/lan-codex.mjs +103 -0
  67. package/src/server/lan-deck.mjs +5 -0
  68. package/src/server/lan-engine.mjs +34 -6
  69. package/src/server/lan-manifest.mjs +16 -2
  70. package/src/server/lan-serve.mjs +16 -6
  71. package/src/server/login-service.mjs +2 -0
  72. package/src/server/pinned-build.mjs +5 -0
  73. package/src/server/request-gates.mjs +3 -0
  74. package/src/server/tui-codex.mjs +229 -0
  75. package/src/server/tui-lan.mjs +684 -0
  76. package/src/server/tui-machine.mjs +492 -0
  77. package/src/server/tui-network.mjs +730 -0
  78. package/src/server/tui-view.mjs +735 -60
@@ -0,0 +1,229 @@
1
+ // The Codex side of `ccdeck tui`: the deck's Codex accounts, drawn as the rows
2
+ // the Claude list draws, with the deck's Codex panel's words and rules
3
+ // (CodexProfilesSection.tsx, codex-accounts.ts, i18n/areas/codex/en.ts).
4
+ //
5
+ // Pure. The deck keeps the accounts (GET /api/codex-profiles), each one's
6
+ // quota (GET /api/codex-profile-quota?id=) and Codex's own Auto-switch (GET
7
+ // /api/codex-auto); bin/cli/tui.js reads them and hands them in. A Codex
8
+ // account has no slot, so a row's number is its place in the list — what 1-9
9
+ // select — and the account's id travels with the row for every action on it.
10
+ import { oneLine } from "./cli-lines.mjs";
11
+
12
+ /** A window's length as the deck's quota bars name it (codex-accounts.ts
13
+ * windowLabel): hours up to six, days past them. */
14
+ export function windowLabel(seconds) {
15
+ const s = Number(seconds);
16
+ if (!Number.isFinite(s) || s <= 0) return "limit";
17
+ const hours = s / 3_600;
18
+ return hours <= 6 ? `${Math.round(hours)}h` : `${Math.round(s / 86_400)}d`;
19
+ }
20
+
21
+ /**
22
+ * A quota answer's windows as the two lanes a row has room for: the shorter
23
+ * window in the 5-hour lane, the longer in the weekly one, each named by its
24
+ * own length. A plan with one window (Plus reports the week alone) fills the
25
+ * lane its length belongs to.
26
+ */
27
+ export function codexLanes(quota) {
28
+ if (!quota || quota.ok === false || !Array.isArray(quota.windows)) return [];
29
+ const windows = quota.windows
30
+ .filter(w => w && Number.isFinite(Number(w.usedPercent)))
31
+ .sort((x, y) => (Number(x.seconds) || 0) - (Number(y.seconds) || 0));
32
+ const lane = (w, id) => ({
33
+ id, label: windowLabel(w.seconds), pct: Math.max(0, Math.min(100, Number(w.usedPercent))),
34
+ resetAt: Number.isFinite(Number(w.resetAt)) ? Number(w.resetAt) : null,
35
+ });
36
+ if (!windows.length) return [];
37
+ if (windows.length === 1) return [lane(windows[0], Number(windows[0].seconds) > 6 * 3_600 ? "seven_day" : "five_hour")];
38
+ return [lane(windows[0], "five_hour"), lane(windows.at(-1), "seven_day")];
39
+ }
40
+
41
+ /** The accounts the deck serves, or none. */
42
+ export const codexProfiles = (state) => (Array.isArray(state.codex?.profiles) ? state.codex.profiles : []);
43
+
44
+ /** Whether the deck has a Codex side to show: it answered, with an account. */
45
+ export const hasCodex = (state) => codexProfiles(state).length > 0;
46
+
47
+ /** No login at all, by the source Codex reads it from (codex-accounts.ts signedOut). */
48
+ export function signedOut(p) {
49
+ if (p.metadataUnavailable) return false;
50
+ return p.authSource === "native" ? !p.signedIn : !p.signedInFilePresent;
51
+ }
52
+
53
+ const NOT_SIGNED_IN = {
54
+ word: "not signed in", tone: "warn", blocks: true, fix: "Sign in",
55
+ hint: "This account has no Codex login yet, so there is nothing to read and nothing to switch to.",
56
+ };
57
+
58
+ /** What reading an account's usage ran into, the deck's word for each. */
59
+ function quotaProblem(reason) {
60
+ switch (reason) {
61
+ case "no_token": return NOT_SIGNED_IN;
62
+ case "expired":
63
+ case "reauth_required":
64
+ return {
65
+ word: "login expired", tone: "warn", blocks: true, fix: "Sign in again",
66
+ hint: "Codex no longer accepts this account's login. Signing in again replaces it; the account keeps its settings and history.",
67
+ };
68
+ case "api_key_mode":
69
+ return { word: "uses an API key", tone: "muted", blocks: false, hint: "This account runs on an API key, which has no ChatGPT limits to read." };
70
+ case "cli_unavailable":
71
+ return { word: "Codex not found", tone: "warn", blocks: false, hint: "The deck cannot find the codex command on this machine, so it cannot read this account." };
72
+ case "unsupported":
73
+ case "unsupported_auth":
74
+ case "quota_unavailable":
75
+ return { word: "usage not available", tone: "muted", blocks: false, hint: "This version of Codex does not report usage for this account. Updating Codex may bring it back." };
76
+ case "http_429":
77
+ return { word: "rate limited", tone: "muted", blocks: false, hint: "OpenAI is throttling usage requests for this account. It clears on its own." };
78
+ default:
79
+ return { word: "temporary error", tone: "muted", blocks: false, hint: "A network or Codex hiccup while reading usage. The next read tries again." };
80
+ }
81
+ }
82
+
83
+ /**
84
+ * What is wrong with an account, first things first (codex-accounts.ts
85
+ * codexIssue): `{ word, hint, tone, blocks, fix }`, or null. `blocks` is a
86
+ * switch that cannot help; `fix` the sign-in that can.
87
+ */
88
+ export function codexIssue(p, quota, profiles = []) {
89
+ if (p.available === false) {
90
+ return { word: "folder missing", tone: "warn", blocks: true, hint: "The deck cannot find this account's Codex folder, so it cannot read it or switch to it." };
91
+ }
92
+ if (signedOut(p)) return NOT_SIGNED_IN;
93
+ if (p.metadataUnavailable) return quotaProblem(p.metadataReason ?? "unknown");
94
+ if (p.sameAccountAs) {
95
+ const other = profiles.find(o => o.id === p.sameAccountAs);
96
+ return {
97
+ word: other?.active ? "same as your default" : "same as another row", tone: "warn", blocks: false, fix: "Sign in again",
98
+ hint: "Both rows are signed in to one ChatGPT account, so they share one quota and switching gains nothing.",
99
+ };
100
+ }
101
+ // A login that moved while it was read is the moment after a sign-in: the
102
+ // next reading has the answer.
103
+ if (quota && quota.ok === false && quota.reason !== "profile_changed") return quotaProblem(quota.reason ?? "unknown");
104
+ return null;
105
+ }
106
+
107
+ /** A reading is stale past this, as the deck's panel has it. */
108
+ export const CODEX_STALE_MS = 15 * 60_000;
109
+
110
+ /**
111
+ * The accounts as rows: `{ num, id, email, alias, active, disabled, managed,
112
+ * lanes, fetchedAt, stale, plan, issue, headroom, codex: true }`. The alias is
113
+ * the name a person gave the account, the address its login's. A reading for
114
+ * an earlier login of the account (`identityVersion`) is not its reading.
115
+ */
116
+ export function codexRows(state, now = null) {
117
+ const profiles = codexProfiles(state);
118
+ const held = new Set(Array.isArray(state.codexAuto?.heldOut) ? state.codexAuto.heldOut : []);
119
+ const quotas = state.codexQuota ?? {};
120
+ return profiles.map((p, i) => {
121
+ let quota = quotas[p.id] ?? null;
122
+ if (quota?.identityVersion && p.identityVersion && quota.identityVersion !== p.identityVersion) quota = null;
123
+ const good = quota?.ok === false ? quota.lastGood ?? null : quota;
124
+ const lanes = codexLanes(good);
125
+ const fetchedAt = typeof good?.fetchedAt === "number" ? good.fetchedAt : null;
126
+ const alias = oneLine(p.managedLabel) || null;
127
+ return {
128
+ num: i + 1,
129
+ id: p.id,
130
+ email: oneLine(p.account) || (alias ? null : oneLine(p.label)) || null,
131
+ alias,
132
+ active: p.active === true,
133
+ disabled: held.has(p.id),
134
+ managed: p.managed === true,
135
+ lanes,
136
+ fetchedAt,
137
+ // As the panel has it: read too long ago, or the last reading failed —
138
+ // not the deck's own `stale`, which says only that it served a held reading.
139
+ stale: fetchedAt != null && (quota?.ok === false || (now != null && now - fetchedAt > CODEX_STALE_MS)),
140
+ plan: typeof good?.plan === "string" ? good.plan : null,
141
+ issue: codexIssue(p, quota, profiles),
142
+ headroom: lanes.length ? 100 - Math.max(...lanes.map(l => l.pct)) : null,
143
+ codex: true,
144
+ };
145
+ });
146
+ }
147
+
148
+ /**
149
+ * The deck's Codex ⋯ menu for a row, by its rules: the switch where it can
150
+ * help, the sign-in (in place, keeping the account), rename, rotation on every
151
+ * account but the default unless it is already out, and remove on the
152
+ * accounts the deck made.
153
+ */
154
+ export function codexMenuItems(row, { home = false, homeable = false } = {}) {
155
+ const blocked = row.issue?.blocks === true;
156
+ return [
157
+ !row.active && !blocked ? { id: "switch", key: "enter", label: "Switch to this account" } : null,
158
+ { id: "signin", key: "i", label: row.issue?.fix ?? (signedInWord(row) ? "Sign in again" : "Sign in") },
159
+ { id: "rename", key: "n", label: "Rename…" },
160
+ !row.active || row.disabled ? { id: "hold", key: "o", label: row.disabled ? "Put back in rotation" : "Hold out of rotation" } : null,
161
+ // Home, as the deck's Codex menu has it: once Codex Auto-switch is read,
162
+ // set with the switch on or off, and removable whenever it is there.
163
+ homeable || home ? { id: "home", key: "h", label: home ? "Remove home" : "Set as home" } : null,
164
+ row.managed ? { id: "remove", key: "x", label: "Remove…", danger: true } : null,
165
+ ].filter(Boolean);
166
+ }
167
+ const signedInWord = (row) => row.issue?.word !== "not signed in";
168
+
169
+ /** A name the deck takes for a Codex account (codex-selection.mjs): up to 80
170
+ * characters, no slash, no control character. Empty takes the name away. */
171
+ export function codexNameTrouble(label) {
172
+ const t = String(label ?? "").trim();
173
+ if (!t) return null;
174
+ if (/[\\/]/.test(t)) return "a name cannot hold a slash";
175
+ if (/[\x00-\x1f\x7f]/.test(t) || t.length > 80) return "up to 80 characters, no slash";
176
+ return null;
177
+ }
178
+
179
+ /** Why the deck refused a Codex change, in the panel's words. */
180
+ export const CODEX_REFUSED = Object.freeze({
181
+ selection_conflict: "another change moved the accounts just then — try again",
182
+ operation_conflict: "another change moved the accounts just then — try again",
183
+ selection_busy: "the deck is busy with another account change — try again",
184
+ unknown_profile: "the deck does not know that account any more",
185
+ invalid_label: "a name cannot hold a slash, and has 80 characters at most",
186
+ not_removable: "only accounts added in the deck can be removed here",
187
+ profile_unavailable: "the deck cannot find this account's Codex folder",
188
+ });
189
+
190
+ /**
191
+ * What a switch did to the Codex that is running, from the deck's `live`
192
+ * answer: `{ tone, text }`, the panel's own sentences.
193
+ */
194
+ export function codexLiveSaid(live, name) {
195
+ const state = live?.state;
196
+ if (state === "failed" || state === "unavailable" || state === "disconnected") {
197
+ return { tone: "warn", text: `${name} is the default, but the open Codex app could not switch — check its account with /status` };
198
+ }
199
+ if (state === "external_change") {
200
+ return { tone: "warn", text: "Codex account control is paused after a login change or lost connection — check /status in Codex" };
201
+ }
202
+ if (live?.continuation === "manual_required") {
203
+ return { tone: "warn", text: `switched to ${name} — automatic continuation could not be confirmed; check the conversation` };
204
+ }
205
+ if (state === "waiting") return { tone: "info", text: `switching to ${name} once running tools and pending input are done` };
206
+ if (live?.continuation === "waiting") return { tone: "ok", text: `switched to ${name} — waiting for subagents to resume` };
207
+ if (state === "applied") return { tone: "ok", text: `switched to ${name} — connected Codex conversations use it now` };
208
+ return { tone: "ok", text: `${name} is the default — new Codex sessions use it` };
209
+ }
210
+
211
+ // ── the sign-in ─────────────────────────────────────────────────────────────
212
+ //
213
+ // `codex login --device-auth`, run by the deck in the account's own folder:
214
+ // a link to open in any browser and a code to type there. Nothing comes back
215
+ // to type here, and it finishes by itself — which is why it works from a phone
216
+ // over SSH as well as at the desk.
217
+
218
+ /** The sign-in page's states: `{ id, name, adding, started, login }`, `login`
219
+ * the deck's GET /api/codex-profile-login-state answer. */
220
+ export const CODEX_LOGIN_LIVE = new Set(["starting", "waiting"]);
221
+ export const CODEX_LOGIN_FAILED = Object.freeze({
222
+ codex_missing: "the deck cannot find the codex command on this machine",
223
+ no_code: "codex did not print a sign-in code",
224
+ login_failed: "codex did not finish the sign-in",
225
+ code_expired: "the code expired before it was entered — enter starts a new one",
226
+ });
227
+
228
+ /** Whether the deck is still running the sign-in. */
229
+ export const codexSigninRunning = (si) => Boolean(si?.started) && (!si.login || CODEX_LOGIN_LIVE.has(si.login.state) || si.login.state === "idle");