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,74 @@
1
+ {
2
+ "name": "ws",
3
+ "version": "8.22.1",
4
+ "description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js",
5
+ "keywords": [
6
+ "HyBi",
7
+ "Push",
8
+ "RFC-6455",
9
+ "WebSocket",
10
+ "WebSockets",
11
+ "real-time"
12
+ ],
13
+ "homepage": "https://github.com/websockets/ws",
14
+ "bugs": "https://github.com/websockets/ws/issues",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/websockets/ws.git"
18
+ },
19
+ "author": "Einar Otto Stangvik <einaros@gmail.com> (http://2x.io)",
20
+ "license": "MIT",
21
+ "main": "index.js",
22
+ "exports": {
23
+ ".": {
24
+ "browser": "./browser.js",
25
+ "import": "./wrapper.mjs",
26
+ "require": "./index.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "browser": "browser.js",
31
+ "engines": {
32
+ "node": ">=10.0.0"
33
+ },
34
+ "files": [
35
+ "browser.js",
36
+ "index.js",
37
+ "lib/*.js",
38
+ "wrapper.mjs"
39
+ ],
40
+ "scripts": {
41
+ "test": "nyc --reporter=lcov --reporter=text mocha --throw-deprecation test/*.test.js",
42
+ "integration": "mocha --throw-deprecation test/*.integration.js",
43
+ "lint": "eslint . && prettier --check --ignore-path .gitignore \"**/*.{json,md,yaml,yml}\""
44
+ },
45
+ "peerDependencies": {
46
+ "bufferutil": "^4.0.1",
47
+ "utf-8-validate": ">=5.0.2"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "bufferutil": {
51
+ "optional": true
52
+ },
53
+ "utf-8-validate": {
54
+ "optional": true
55
+ }
56
+ },
57
+ "devDependencies": {
58
+ "@eslint/js": "^10.0.1",
59
+ "benchmark": "^2.1.4",
60
+ "bufferutil": "^4.0.1",
61
+ "eslint": "^10.0.1",
62
+ "eslint-config-prettier": "^10.0.1",
63
+ "eslint-plugin-prettier": "^5.0.0",
64
+ "globals": "^17.0.0",
65
+ "mocha": "^8.4.0",
66
+ "nyc": "^15.0.0",
67
+ "prettier": "^3.0.0",
68
+ "utf-8-validate": "^6.0.0"
69
+ },
70
+ "allowScripts": {
71
+ "bufferutil": true,
72
+ "utf-8-validate": true
73
+ }
74
+ }
@@ -0,0 +1,21 @@
1
+ import createWebSocketStream from './lib/stream.js';
2
+ import extension from './lib/extension.js';
3
+ import PerMessageDeflate from './lib/permessage-deflate.js';
4
+ import Receiver from './lib/receiver.js';
5
+ import Sender from './lib/sender.js';
6
+ import subprotocol from './lib/subprotocol.js';
7
+ import WebSocket from './lib/websocket.js';
8
+ import WebSocketServer from './lib/websocket-server.js';
9
+
10
+ export {
11
+ createWebSocketStream,
12
+ extension,
13
+ PerMessageDeflate,
14
+ Receiver,
15
+ Sender,
16
+ subprotocol,
17
+ WebSocket,
18
+ WebSocketServer
19
+ };
20
+
21
+ export default WebSocket;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccdeck",
3
- "version": "3.53.3",
3
+ "version": "3.81.0",
4
4
  "description": "Local dashboard for Claude Code and Codex CLI sessions: which Claude Code session needs input, every tool call and Claude Code subagent live, token cost and quota, several Claude accounts. Run npx ccdeck.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -98,9 +98,11 @@
98
98
  "vitest": "^2.1.9"
99
99
  },
100
100
  "dependencies": {
101
- "fs-native-extensions": "1.5.2"
101
+ "fs-native-extensions": "1.5.2",
102
+ "ws": "8.22.1"
102
103
  },
103
104
  "bundledDependencies": [
104
- "fs-native-extensions"
105
+ "fs-native-extensions",
106
+ "ws"
105
107
  ]
106
108
  }
@@ -84,6 +84,8 @@
84
84
  "without one."
85
85
  ],
86
86
  "//summaries": {
87
+ "3.81.0": "Codex accounts on a par with Claude's, Codex over Local network, and ccdeck tui for the whole deck",
88
+ "3.80.0": "Codex account switching, continuation and sharing",
87
89
  "3.53.0": "Codex accounts, with sign-in, switching and Auto-switch",
88
90
  "3.52.0": "ccdeck in nine more languages",
89
91
  "3.51.0": "Jira integration updates",
@@ -134,6 +136,75 @@
134
136
  "3.53.1",
135
137
  "3.53.3"
136
138
  ],
139
+ "3.81.0": [
140
+ {
141
+ "title": "👥 Codex accounts work the way Claude's do",
142
+ "body": "A Codex account's menu now has Set as home, Share and Projects, and Auto-switch shows even when you have only one Codex account.",
143
+ "priority": "highlight",
144
+ "icon": "accounts",
145
+ "details": "Auto-switch moves back to the home account once it has room again, and a notification says each move it makes. Projects shows where that account's work went, per project and per day."
146
+ },
147
+ {
148
+ "title": "📡 Share Codex logins with your paired decks",
149
+ "body": "Local network now lists Codex logins beside Claude's, and a paired deck adds a login you tick as a Codex account of its own.",
150
+ "priority": "highlight",
151
+ "icon": "accounts",
152
+ "noticeLabel": "Login privacy",
153
+ "notice": "Only the logins you tick are sent, and the one this deck is using stays here unless Send the login this deck is using too is on. A copy another deck renewed is repaired in place; a separate sign-in is never replaced.",
154
+ "details": "Codex rows show which paired decks a login is offered to, as Claude rows do, and Local network opens from the Codex side too."
155
+ },
156
+ {
157
+ "title": "⌨️ ccdeck tui looks after the whole deck over SSH",
158
+ "body": "The terminal view now draws the machine live, manages Claude and Codex accounts from a menu, and pairs and shares decks on a Local network tab.",
159
+ "priority": "highlight",
160
+ "details": "A Codex account signs in with a link and a code you type into any browser."
161
+ },
162
+ {
163
+ "title": "➕ Paste a Codex share from the + button",
164
+ "body": "Import Codex accounts is now the Paste a share tab under + in the Codex accounts panel, as on Claude's side."
165
+ },
166
+ {
167
+ "title": "🪟 The desktop window comes back the way you closed it",
168
+ "body": "Reopened from the tray, the Dock or a second launch, the window keeps its size and place, and stays maximized or full screen if it was.",
169
+ "details": "On macOS, a window reopened after an update or at login never enters full screen."
170
+ }
171
+ ],
172
+ "3.80.0": [
173
+ {
174
+ "title": "Switch Codex accounts without losing your place",
175
+ "body": "Move supported running Codex conversations and their subagents to another account, then continue the same work.",
176
+ "priority": "highlight",
177
+ "icon": "accounts",
178
+ "noticeLabel": "Compatibility",
179
+ "notice": "Requires Codex 0.166.0 or newer and a private auth.json login on a supported shared native server. Conversations connected to that server switch together. ccdeck waits for tools and approvals, and must stay open to renew the selected login. After a lost connection or restart, a server that cannot confirm the workspace identity requires Reconnect selected account. If continuation is unconfirmed, check the conversation before continuing manually; uncertain sends are never repeated automatically."
180
+ },
181
+ {
182
+ "title": "Share Codex logins between your machines",
183
+ "body": "Choose accounts to export, then paste the code into Import Codex accounts on another machine, including Windows.",
184
+ "priority": "highlight",
185
+ "icon": "accounts",
186
+ "noticeLabel": "Login privacy",
187
+ "notice": "Sharing is optional and exports live ChatGPT credentials, including the renewal token, from file-backed logins. The code is encoded, not encrypted, and has no automatic expiry or ccdeck revocation. Use a trusted private channel and delete clipboard or message copies afterward. Renewal on one machine can invalidate the other copy and require signing in again. Configuration and conversation history are not transferred."
188
+ },
189
+ {
190
+ "title": "See your available Codex resets",
191
+ "body": "Usage shows saved rate-limit resets and their nearest expiry when the selected account provides them.",
192
+ "priority": "highlight",
193
+ "noticeLabel": "Availability",
194
+ "notice": "Reset inventory requires a validated file-backed login and an available provider reading. Checking the inventory never spends a reset."
195
+ },
196
+ {
197
+ "title": "Continue managed terminal tasks on another account",
198
+ "body": "With Codex Auto-switch enabled, supported terminal tasks can resume the same conversation on an account with quota after a usage-limit failure.",
199
+ "priority": "required",
200
+ "noticeLabel": "Terminal setup",
201
+ "notice": "Update an existing setup with Enable in terminal, then open a new terminal. Interactive continuation requires Codex 0.166.0 or newer with the native remote transport. Only supported commands launched through ccdeck terminal selection are covered; explicit CODEX_HOME pins, independent sessions and incompatible profile settings require manual handling."
202
+ },
203
+ {
204
+ "title": "Help us improve Codex support",
205
+ "body": "We are continuing to improve Codex support, and feedback on switching, subagents and sharing is welcome through the Feedback button in ccdeck."
206
+ }
207
+ ],
137
208
  "3.53.2": [
138
209
  {
139
210
  "title": "🔁 The deck stays up on machines without Codex",
@@ -0,0 +1,87 @@
1
+ // Provider-independent selection and continuation. Claude deliberately keeps its
2
+ // existing cswap path; only an explicitly supplied adapter can run this engine.
3
+ export function chooseEngineAccount(rows, quotas, { threshold = 90, next = 'room', heldOut = [], exclude = [], nowSec = Date.now() / 1000 } = {}) {
4
+ const excluded = new Set([...heldOut, ...exclude]);
5
+ const fits = rows.flatMap(row => {
6
+ if (excluded.has(row.id) || excluded.has(row.sameAccountAs) || row.available === false
7
+ || !(row.signedIn ?? row.signedInFilePresent)) return [];
8
+ const q = quotas.get(row.id);
9
+ if (!q?.ok || q.stale || Number.isFinite(q.fetchedAt) && nowSec * 1000 - q.fetchedAt > 15 * 60_000) return [];
10
+ const windows = (q.windows ?? []).filter(w => Number.isFinite(w.usedPercent) && w.usedPercent >= 0 && (w.resetAt == null || w.resetAt > nowSec));
11
+ // An empty or expired reading is unknown, never unlimited room.
12
+ if (!windows.length) return [];
13
+ const load = Math.max(...windows.map(w => w.usedPercent));
14
+ if (load >= threshold) return [];
15
+ const weekly = windows.find(w => w.seconds >= 6 * 86400 && w.resetAt != null && w.resetAt - nowSec <= 4 * 86400);
16
+ return [{ id: row.id, load, reset: weekly?.resetAt ?? null }];
17
+ });
18
+ const soon = next === 'weekly' ? fits.filter(f => f.reset !== null) : [];
19
+ return (soon.length ? soon.sort((a, b) => a.reset - b.reset || a.load - b.load) : fits.sort((a, b) => a.load - b.load))[0] ?? null;
20
+ }
21
+
22
+ /** Every retry starts only after the adapter has observed the previous process
23
+ * exit and a terminal usage-limit failure. No retry of a partial/unknown result,
24
+ * no `--last`, no global account change, no repeated account in the same run. */
25
+ export async function runAccountEngine(adapter, initial, { signal, onSwitch = () => {} } = {}) {
26
+ const tried = new Set();
27
+ let current = initial;
28
+ let threadId = initial.threadId ?? null;
29
+ for (let attempt = 0; attempt < 32; attempt++) {
30
+ if (signal?.aborted) return { code: 130, reason: 'cancelled' };
31
+ tried.add(current.id);
32
+ const result = await adapter.run(current, { signal });
33
+ if (signal?.aborted) return { ...result, reason: 'cancelled' };
34
+ const manual = result.reason === 'manual_switch';
35
+ if ((!manual && result.reason !== 'usage_limit') || !result.threadId || result.code === 0) return result;
36
+ if (!manual && threadId && threadId !== result.threadId) return { ...result, reason: 'thread_changed' };
37
+ threadId = result.threadId;
38
+ const settings = await adapter.settings();
39
+ if (!manual && !settings.enabled) return { ...result, reason: 'disabled' };
40
+ const rows = await adapter.accounts();
41
+ const source = rows.find(row => row.id === current.id);
42
+ if (!source) return { ...result, reason: 'source_unavailable' };
43
+ let pick;
44
+ if (manual) {
45
+ const target = rows.find(row => row.id === result.targetId && row.id !== current.id && row.available !== false && (row.signedIn ?? row.signedInFilePresent));
46
+ if (!target) return { ...result, reason: 'target_unavailable' };
47
+ pick = { id: target.id };
48
+ } else {
49
+ const exclude = [...tried];
50
+ for (const row of rows) if (row.sameAccountAs === current.id || source.sameAccountAs === row.id
51
+ || source.sameAccountAs && row.sameAccountAs === source.sameAccountAs) exclude.push(row.id);
52
+ const quotas = new Map();
53
+ for (const row of rows) {
54
+ if (signal?.aborted) return { ...result, reason: 'cancelled' };
55
+ if (!exclude.includes(row.id) && !settings.heldOut?.includes(row.id)) {
56
+ try { quotas.set(row.id, await adapter.quota(row.id)); } catch { /* unavailable is not room */ }
57
+ }
58
+ }
59
+ pick = chooseEngineAccount(rows, quotas, { ...settings, exclude });
60
+ if (!pick) return { ...result, reason: 'no_account_with_room' };
61
+ const latest = await adapter.settings();
62
+ if (!latest.enabled || signal?.aborted) return { ...result, reason: 'cancelled' };
63
+ if (!chooseEngineAccount(rows.filter(row => row.id === pick.id), quotas, { ...latest, exclude })) return { ...result, reason: 'settings_changed' };
64
+ }
65
+ // Do not move a stopped rollout into an account we cannot launch.
66
+ if (!manual && attempt === 31) return { ...result, reason: 'attempt_limit' };
67
+ let next;
68
+ try { next = await adapter.prepare({ from: current, id: pick.id, threadId }); }
69
+ catch { return { ...result, reason: 'handoff_failed' }; }
70
+ const abandon = async reason => {
71
+ try { await next.restoreSource?.(); }
72
+ catch { return { ...result, reason: 'handoff_failed' }; }
73
+ return { ...result, reason };
74
+ };
75
+ if (signal?.aborted) return abandon('cancelled');
76
+ let beforeLaunch;
77
+ try { beforeLaunch = await adapter.settings(); }
78
+ catch { return abandon('handoff_failed'); }
79
+ if (signal?.aborted) return abandon('cancelled');
80
+ if (!manual && (!beforeLaunch.enabled || beforeLaunch.heldOut?.includes(next.id))) return abandon('disabled');
81
+ try { onSwitch({ from: current.id, to: next.id, threadId }); }
82
+ catch { return abandon('handoff_failed'); }
83
+ if (manual) { tried.clear(); attempt = -1; }
84
+ current = next;
85
+ }
86
+ return { code: 1, reason: 'attempt_limit', threadId };
87
+ }
@@ -1,7 +1,8 @@
1
1
  // Four notifications about the accounts the deck is on, and the rules for when
2
2
  // each is said.
3
3
  //
4
- // SWAP the deck's own auto-switch tick moved the live Claude account.
4
+ // SWAP the deck's own auto-switch tick moved the live Claude account,
5
+ // or Codex's moved the default Codex account (codex-auto.mjs).
5
6
  // Said once per switch, with the reason the tick itself carries,
6
7
  // and never for a switch somebody pressed: those do not come
7
8
  // through a tick at all.
@@ -31,6 +32,14 @@
31
32
  // never saw because the tick saw it first is written down from the tick, so the
32
33
  // account does not announce it later when it is live again.
33
34
  //
35
+ // Codex's loop, by the same rule and its own tick (`codexTick`): a threshold
36
+ // notice for the live Codex account is held while Codex's Auto-switch and the
37
+ // swap switch are on, and a Codex tick answers only for Codex notices, as a
38
+ // Claude tick only for Claude's. A Codex tick reads its two windows without
39
+ // their names, so a crossing only the tick saw is said by the swap and not
40
+ // written down; a later reading of that account in the same window, on it
41
+ // again by hand, says it once.
42
+ //
34
43
  // ONE INCIDENT, ONE NOTIFICATION, by the same rule. A login that dies makes the
35
44
  // deck run a tick at once (cswap-auto-loop.mjs `tickSoon`), so while the loop
36
45
  // and the swap switch are on the stopped notice waits for the first tick that
@@ -274,6 +283,8 @@ export function resetNotice({ provider, accountName, window }) {
274
283
 
275
284
  /** The title the OS helper shows, which has no app name above it. */
276
285
  export const SWAP_WHO = "Claude auto-switch";
286
+ /** The same, for a move Codex's Auto-switch made. */
287
+ export const CODEX_SWAP_WHO = "Codex auto-switch";
277
288
 
278
289
  /**
279
290
  * What the switch away from `from` was about, from the tick's own poll: the
@@ -304,25 +315,25 @@ export function usedBefore(result, fromNumber) {
304
315
  * sooner. A switch for any other reason — the account's usage could not be
305
316
  * read — says where it went and from where, and nothing about why.
306
317
  */
307
- export function swapNotice({ toName, fromName, used, threshold, trigger = null, resetAt = null, now = Date.now() }) {
318
+ export function swapNotice({ toName, fromName, used, threshold, trigger = null, resetAt = null, now = Date.now(), who = SWAP_WHO }) {
308
319
  const to = toName ? cut(toName, NAME_MAX) : "another account";
309
320
  const verb = trigger === "home" ? "Back on" : "Switched to";
310
- if (!fromName) return { who: SWAP_WHO, body: `${verb} ${to}` };
321
+ if (!fromName) return { who, body: `${verb} ${to}` };
311
322
  const from = cut(fromName, NAME_MAX);
312
323
  // The deck's own failover (autoswitch-failover.mjs) moved for one reason
313
324
  // only, and it is the one the user has to act on: sign in again.
314
325
  if (trigger === "login-expired") {
315
- return { who: SWAP_WHO, body: `Switched to ${to} · ${from}'s login expired, sign in again to use it` };
326
+ return { who, body: `Switched to ${to} · ${from}'s login expired, sign in again to use it` };
316
327
  }
317
- if (used != null && used >= 100) return { who: SWAP_WHO, body: `${verb} ${to} · ${from} reached 100%` };
328
+ if (used != null && used >= 100) return { who, body: `${verb} ${to} · ${from} reached 100%` };
318
329
  if (used != null && typeof threshold === "number" && used >= threshold) {
319
- return { who: SWAP_WHO, body: `${verb} ${to} · ${from} reached ${pctLabel(threshold)}%` };
330
+ return { who, body: `${verb} ${to} · ${from} reached ${pctLabel(threshold)}%` };
320
331
  }
321
- if (trigger === "home") return { who: SWAP_WHO, body: `Back on ${to} · your home account` };
332
+ if (trigger === "home") return { who, body: `Back on ${to} · your home account` };
322
333
  if (trigger === "weekly-reset" && typeof resetAt === "number" && resetAt * 1000 > now) {
323
- return { who: SWAP_WHO, body: `Switched to ${to} · weekly limit resets in ${inDuration(resetAt, now)}` };
334
+ return { who, body: `Switched to ${to} · weekly limit resets in ${inDuration(resetAt, now)}` };
324
335
  }
325
- return { who: SWAP_WHO, body: `Switched to ${to} from ${from}` };
336
+ return { who, body: `Switched to ${to} from ${from}` };
326
337
  }
327
338
 
328
339
  /** How long a stop gathers the rest of its incident before it is said, when no
@@ -457,8 +468,13 @@ export function createAccountNotifier({
457
468
  * ran with — together, whether a tick may yet carry a crossing. */
458
469
  let autoOn = false;
459
470
  let policy = null;
471
+ /** The same two for Codex's loop, which ticks on its own. */
472
+ let codexAutoOn = false;
473
+ let codexPolicy = null;
460
474
  /** Threshold notices held for a tick, by record key. */
461
475
  const held = new Map();
476
+ /** The held notices one provider's tick answers for. */
477
+ const heldOf = provider => [...held.values()].filter(e => e.provider === provider);
462
478
  let holdTimer = null;
463
479
  let saving = Promise.resolve();
464
480
  /** The stop incident being gathered or held, or the one already said while
@@ -571,9 +587,12 @@ export function createAccountNotifier({
571
587
  const incidentFor = startedAt =>
572
588
  incident && !incident.said && incident.held && (startedAt == null || startedAt >= incident.firstAt) ? incident : null;
573
589
 
574
- /** Should a threshold notice for this window wait for the next tick? */
575
- const holdFor = (provider, level) =>
576
- provider === "claude" && autoOn && settings().swap && (policy == null || level >= policy);
590
+ /** Should a threshold notice for this window wait for the next tick? Only
591
+ * while that provider's loop is on, and only at the level it moves at. */
592
+ const holdFor = (provider, level) => {
593
+ const [on, at] = provider === "claude" ? [autoOn, policy] : provider === "codex" ? [codexAutoOn, codexPolicy] : [false, null];
594
+ return on && settings().swap && (at == null || level >= at);
595
+ };
577
596
 
578
597
  async function observe(provider, account, windows) {
579
598
  try {
@@ -645,7 +664,7 @@ export function createAccountNotifier({
645
664
  if (!result.switched) {
646
665
  // A cooldown is the one answer that says a switch is still coming.
647
666
  if (result.event === "no-switch" && result.reason === "cooldown") return;
648
- release([...held.values()]);
667
+ release(heldOf("claude"));
649
668
  if (sayStuck) {
650
669
  stuckSaid.set(stuckKey, now());
651
670
  const notice = stuckNotice({ fromName: stuckFrom?.name ?? null });
@@ -671,13 +690,13 @@ export function createAccountNotifier({
671
690
  // Only the live account's notices are ever held, and the live account
672
691
  // is the one a switch leaves — so when the store could not name it, every
673
692
  // held Claude notice is still that account's.
674
- const carried = [...held.values()].filter(e => e.provider === "claude" && (!from?.key || e.accountKey === from.key));
693
+ const carried = heldOf("claude").filter(e => !from?.key || e.accountKey === from.key);
675
694
  for (const entry of carried) {
676
695
  held.delete(entry.key);
677
696
  if (s.swap) markSaid(entry, entry.levels); else sayThreshold(entry);
678
697
  }
679
698
  if (from?.key) carryFromPoll(result, from, at, !s.swap);
680
- release([...held.values()]);
699
+ release(heldOf("claude"));
681
700
  if (s.swap) {
682
701
  const notice = swapNotice({
683
702
  toName: to?.name ?? null, fromName: from?.name ?? null,
@@ -704,6 +723,46 @@ export function createAccountNotifier({
704
723
  }
705
724
  }
706
725
 
726
+ /**
727
+ * One finished tick of Codex's Auto-switch (codex-auto.mjs).
728
+ *
729
+ * `t` is what the tick did: `{ enabled }` when the loop is off, else also
730
+ * `threshold` and `switched`, with `reason: "cooldown"` for a tick that
731
+ * waited out the last move, and for a move `from` and `to` (`{ id, name }`),
732
+ * the `used` share of the account it left and the `trigger` — "proactive" for
733
+ * one that reached the threshold, "home" for a move to the home account.
734
+ */
735
+ async function codexTick(t) {
736
+ try {
737
+ await ready;
738
+ if (!t || typeof t !== "object") return;
739
+ codexAutoOn = t.enabled === true;
740
+ if (!codexAutoOn) { release(heldOf("codex")); return; }
741
+ if (typeof t.threshold === "number" && Number.isFinite(t.threshold)) codexPolicy = t.threshold;
742
+ if (!t.switched) {
743
+ if (t.reason !== "cooldown") release(heldOf("codex"));
744
+ return;
745
+ }
746
+ const s = settings();
747
+ // Only the live account's notices are held, and a move leaves the live
748
+ // account, so every held Codex notice is the crossing this move carries.
749
+ const carried = heldOf("codex");
750
+ for (const entry of carried) {
751
+ held.delete(entry.key);
752
+ if (s.swap) markSaid(entry, entry.levels); else sayThreshold(entry);
753
+ }
754
+ if (s.swap) {
755
+ say(swapNotice({
756
+ who: CODEX_SWAP_WHO, toName: t.to?.name ?? null, fromName: t.from?.name ?? null,
757
+ used: typeof t.used === "number" ? t.used : null, threshold: t.threshold, trigger: t.trigger ?? null, now: now(),
758
+ }));
759
+ }
760
+ if (carried.length > 0) await persist();
761
+ } catch (err) {
762
+ onError?.(err);
763
+ }
764
+ }
765
+
707
766
  /** The levels the tick's poll saw the account it left at, written into that
708
767
  * account's records — and said as threshold notices when no swap will. */
709
768
  function carryFromPoll(result, from, at, sayThem) {
@@ -735,15 +794,21 @@ export function createAccountNotifier({
735
794
  ready,
736
795
  observe,
737
796
  tick,
797
+ codexTick,
738
798
  stopped,
739
799
  /** The loop was switched on or off. Off, nothing will carry what is held. */
740
800
  autoSwitch(on) {
741
801
  autoOn = on === true;
742
802
  if (!autoOn) {
743
- release([...held.values()]);
803
+ release(heldOf("claude"));
744
804
  if (incident?.held && !incident.said) sayIncident();
745
805
  }
746
806
  },
807
+ /** Codex's loop, as the last tick found it, for a notifier made after it. */
808
+ codexAutoSwitch(on) {
809
+ codexAutoOn = on === true;
810
+ if (!codexAutoOn) release(heldOf("codex"));
811
+ },
747
812
  /** For the suite: the records as they stand, what is held, and the stop
748
813
  * incident. */
749
814
  records: () => records,
@@ -43,7 +43,30 @@ export async function handleCodexProfiles(_req, res) {
43
43
  const { discoverCodexProfiles } = await import('./codex-profiles.mjs');
44
44
  const { readCodexSelection } = await import('./codex-selection.mjs');
45
45
  const selection = await readCodexSelection();
46
- send(res, 200, { profiles: await discoverCodexProfiles({ selection, enableNative: true }), revision: selection.revision });
46
+ const { codexLiveAccountStatus } = await import('./codex-live-engine.mjs');
47
+ send(res, 200, { profiles: await discoverCodexProfiles({ selection, enableNative: true }), revision: selection.revision, live: codexLiveAccountStatus() });
48
+ }
49
+
50
+ /** Manual credential transfer is POST-only and behind the global mutation
51
+ * gate. All failures are fixed codes: no auth, blob, native stderr or paths
52
+ * can reach the generic request logger/reporting path. */
53
+ export async function handleCodexAccountShare(req, res, action) {
54
+ try {
55
+ const { createCodexShare, importCodexShare, CODEX_SHARE_MAX_LENGTH } = await import('./codex-share.mjs');
56
+ const raw = await readBody(req, res, CODEX_SHARE_MAX_LENGTH + 4096).catch(() => null);
57
+ let body;
58
+ try { body = JSON.parse(raw ?? ''); } catch { return send(res, 400, { ok: false, reason: 'bad_request' }); }
59
+ const allowed = action === 'export' ? ['ids'] : ['blob', 'expectedRevision'];
60
+ if (!body || typeof body !== 'object' || Array.isArray(body) || Object.keys(body).some(key => !allowed.includes(key))) {
61
+ return send(res, 400, { ok: false, reason: 'bad_request' });
62
+ }
63
+ const result = await (action === 'export' ? createCodexShare(body) : importCodexShare(body));
64
+ send(res, 200, result);
65
+ } catch (error) {
66
+ const safe = new Set(['invalid_profiles', 'unknown_profile', 'file_auth_required', 'unsupported_auth', 'share_too_large', 'invalid_share', 'invalid_revision', 'selection_conflict', 'selection_busy', 'registry_corrupt', 'registry_write_failed', 'profile_unavailable', 'import_write_failed', 'windows_permissions_failed']);
67
+ const reason = safe.has(error?.code) ? error.code : 'share_failed';
68
+ send(res, ['selection_conflict', 'selection_busy'].includes(reason) ? 409 : reason === 'unknown_profile' ? 404 : 400, { ok: false, reason });
69
+ }
47
70
  }
48
71
 
49
72
  export async function handleCodexProfileMutation(req, res, action) {
@@ -57,13 +80,18 @@ export async function handleCodexProfileMutation(req, res, action) {
57
80
  // that is about to be moved away: stop it first, so nothing lands there.
58
81
  if (action === 'remove' && typeof body.id === 'string') (await import('./codex-login.mjs')).cancelCodexLogin(body.id);
59
82
  try {
60
- const result = action === 'select' ? await selectCodexProfile(body)
83
+ const result = action === 'select' ? await selectCodexProfile({ ...body, switchRunning: true })
61
84
  : action === 'remove' ? await removeCodexProfile(body)
62
85
  : action === 'replace' ? await replaceCodexLogin(body)
63
86
  : action === 'rename' ? await renameCodexProfile(body) : await addCodexProfile(body);
87
+ let live;
88
+ if (action === 'select') {
89
+ try { live = await (await import('./codex-live-engine.mjs')).requestCodexLiveAccount(result.runningSelection); }
90
+ catch { live = { state: 'failed', reason: 'live_switch_failed', profileId: null }; }
91
+ }
64
92
  // Registry paths are local implementation details; only explicit command
65
93
  // requests below return a home as part of a copyable terminal command.
66
- send(res, 200, { ok: true, id: result.id ?? result.profileId, revision: result.revision, status: result.status });
94
+ send(res, 200, { ok: true, id: result.id ?? result.profileId, revision: result.revision, status: result.status, ...(live ? { live } : {}) });
67
95
  } catch (error) {
68
96
  const reason = error?.code ?? 'operation_failed';
69
97
  const conflicts = ['selection_conflict', 'operation_conflict', 'selection_busy'];
@@ -128,6 +156,24 @@ export async function handleCodexProfileQuota(req, res) {
128
156
  send(res, 200, await readCodexProfileQuota(id, { enableNative: true }));
129
157
  }
130
158
 
159
+ /** One Codex profile's Projects report (codex-projects.mjs): the Claude report's
160
+ * shape, for the same dialog. `days` is clamped as handleAccountProjects clamps
161
+ * it. The id is validated here and resolved to a home only against the trusted
162
+ * roster; the answer carries no home path and no account id. */
163
+ export async function handleCodexProfileProjects(req, res) {
164
+ const url = new URL(req.url, 'http://localhost');
165
+ const id = url.searchParams.get('id');
166
+ // A missing `days` is 7, not 0: Number(null) is 0, which would read as "all".
167
+ const raw = url.searchParams.get('days');
168
+ const d = raw === null || raw === '' ? NaN : Number(raw);
169
+ const days = d === 1 ? 1 : d === 30 ? 30 : d === 0 ? 0 : 7;
170
+ const { idPattern } = await import('./codex-selection.mjs');
171
+ if (typeof id !== 'string' || !idPattern.test(id)) return send(res, 400, { ok: false, reason: 'bad_profile' });
172
+ const { codexProjectsReport } = await import('./codex-projects.mjs');
173
+ const report = await codexProjectsReport({ id, days });
174
+ send(res, report.ok ? 200 : 404, report);
175
+ }
176
+
131
177
  export async function handleCodexProfileLaunch(req, res) {
132
178
  const { codexProfileLaunchCommand } = await import('./codex-profiles.mjs');
133
179
  const id = new URL(req.url, 'http://localhost').searchParams.get('id');
@@ -45,6 +45,8 @@ export const WATCH_MS = 2 * 60_000;
45
45
  let _deps = null;
46
46
  let _notifier = null;
47
47
  let _autoOn = false;
48
+ /** Whether Codex's Auto-switch was on at its last tick. */
49
+ let _codexAutoOn = false;
48
50
  let _timer = null;
49
51
  let _watching = null;
50
52
  /** The auto-switch loop's "tick now", handed in by the loop as it loads
@@ -79,6 +81,7 @@ function notifier() {
79
81
  },
80
82
  });
81
83
  _notifier.autoSwitch(_autoOn);
84
+ _notifier.codexAutoSwitch(_codexAutoOn);
82
85
  return _notifier;
83
86
  }
84
87
 
@@ -115,6 +118,24 @@ export function noteAutoTick(result, meta = {}) {
115
118
  .catch(() => {});
116
119
  }
117
120
 
121
+ /**
122
+ * A finished tick of Codex's Auto-switch (codex-auto.mjs), which reports every
123
+ * tick here — the loop is started with this as its `onTick` (index.mjs), since
124
+ * codex-auto.mjs also runs inside the terminal helper and imports nothing of
125
+ * the deck's notifications. The tick names both accounts itself; no store is
126
+ * read. Never throws.
127
+ */
128
+ export function noteCodexAutoTick(outcome) {
129
+ try {
130
+ if (!outcome || typeof outcome !== "object") return Promise.resolve();
131
+ _codexAutoOn = outcome.enabled === true;
132
+ const n = notifier();
133
+ return n ? n.codexTick(outcome).catch(() => {}) : Promise.resolve();
134
+ } catch {
135
+ return Promise.resolve();
136
+ }
137
+ }
138
+
118
139
  /** What each organization's settings were last seen to turn on, as the
119
140
  * sentence a swap notice carries (org-telemetry.mjs), or null. */
120
141
  async function telemetryReader() {