ccdeck 3.80.0 → 3.81.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.
- package/README.md +23 -4
- package/bin/cli/tui.js +433 -11
- package/dist/web/assets/{BrowserWatchModal-Bfvo_8H6.js → BrowserWatchModal-BcvsD8Np.js} +1 -1
- package/dist/web/assets/{IntegrationModal-GS5jIQ_J.js → IntegrationModal-BMtv2XWR.js} +1 -1
- package/dist/web/assets/{RadioPanel-Bxd2ElWb.js → RadioPanel-k65VVqTb.js} +1 -1
- package/dist/web/assets/{TrafficRadar-FgHBI2Oh.js → TrafficRadar-BNw0skS3.js} +1 -1
- package/dist/web/assets/{UsageHistoryModal-APwKtE2J.js → UsageHistoryModal-CYxrrwCl.js} +1 -1
- package/dist/web/assets/{app-xTrs4aEH.css → app-BIrh5Q0W.css} +1 -1
- package/dist/web/assets/{app-BzHVsgB2.js → app-DCoamBD4.js} +93 -93
- package/dist/web/assets/{index-7whwMaPX.js → index-BMX8nr4f.js} +1 -1
- package/dist/web/index.html +3 -3
- package/package.json +1 -1
- package/release-notes.json +62 -0
- package/src/server/account-notify.mjs +81 -16
- package/src/server/account-routes.mjs +20 -2
- package/src/server/account-watch.mjs +21 -0
- package/src/server/codex-auto.mjs +157 -37
- package/src/server/codex-lan-identity.mjs +61 -0
- package/src/server/codex-live-engine.mjs +28 -2
- package/src/server/codex-live-rpc.mjs +4 -1
- package/src/server/codex-profiles.mjs +34 -4
- package/src/server/codex-projects.mjs +308 -0
- package/src/server/codex-selection.mjs +17 -2
- package/src/server/codex-share.mjs +74 -12
- package/src/server/codex-terminal.mjs +1 -1
- package/src/server/codex-usage.mjs +69 -0
- package/src/server/codex-windows-private.mjs +2 -0
- package/src/server/codex-windows-private.ps1 +48 -1
- package/src/server/index.mjs +6 -4
- package/src/server/lan-codex-store.mjs +173 -0
- package/src/server/lan-codex.mjs +103 -0
- package/src/server/lan-copies.mjs +1 -1
- package/src/server/lan-deck.mjs +5 -0
- package/src/server/lan-engine.mjs +34 -6
- package/src/server/lan-manifest.mjs +16 -2
- package/src/server/lan-serve.mjs +21 -6
- package/src/server/lifecycle.mjs +2 -2
- package/src/server/npm-upgrade.mjs +17 -6
- package/src/server/pinned-build.mjs +3 -0
- package/src/server/request-gates.mjs +3 -0
- package/src/server/self-update.mjs +2 -72
- package/src/server/terminal-cli.mjs +8 -2
- package/src/server/tui-codex.mjs +229 -0
- package/src/server/tui-lan.mjs +684 -0
- package/src/server/tui-machine.mjs +492 -0
- package/src/server/tui-network.mjs +730 -0
- package/src/server/tui-view.mjs +735 -60
- package/src/server/version-order.mjs +74 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./app-
|
|
1
|
+
import"./app-DCoamBD4.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))i(e);new MutationObserver(e=>{for(const r of e)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function s(e){const r={};return e.integrity&&(r.integrity=e.integrity),e.referrerPolicy&&(r.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?r.credentials="include":e.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(e){if(e.ep)return;e.ep=!0;const r=s(e);fetch(e.href,r)}})();
|
package/dist/web/index.html
CHANGED
|
@@ -77,9 +77,9 @@
|
|
|
77
77
|
document.documentElement.setAttribute("data-density", density === "tightest" || density === "tighter" || density === "compact" || density === "comfortable" ? density : "default");
|
|
78
78
|
})();
|
|
79
79
|
</script>
|
|
80
|
-
<script type="module" crossorigin src="/assets/index-
|
|
81
|
-
<link rel="modulepreload" crossorigin href="/assets/app-
|
|
82
|
-
<link rel="stylesheet" crossorigin href="/assets/app-
|
|
80
|
+
<script type="module" crossorigin src="/assets/index-BMX8nr4f.js"></script>
|
|
81
|
+
<link rel="modulepreload" crossorigin href="/assets/app-DCoamBD4.js">
|
|
82
|
+
<link rel="stylesheet" crossorigin href="/assets/app-BIrh5Q0W.css">
|
|
83
83
|
</head>
|
|
84
84
|
<body>
|
|
85
85
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ccdeck",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.81.1",
|
|
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": {
|
package/release-notes.json
CHANGED
|
@@ -84,6 +84,8 @@
|
|
|
84
84
|
"without one."
|
|
85
85
|
],
|
|
86
86
|
"//summaries": {
|
|
87
|
+
"3.81.1": "Codex reconnection and Windows fixes",
|
|
88
|
+
"3.81.0": "Codex accounts on a par with Claude's, Codex over Local network, and ccdeck tui for the whole deck",
|
|
87
89
|
"3.80.0": "Codex account switching, continuation and sharing",
|
|
88
90
|
"3.53.0": "Codex accounts, with sign-in, switching and Auto-switch",
|
|
89
91
|
"3.52.0": "ccdeck in nine more languages",
|
|
@@ -135,6 +137,66 @@
|
|
|
135
137
|
"3.53.1",
|
|
136
138
|
"3.53.3"
|
|
137
139
|
],
|
|
140
|
+
"3.81.1": [
|
|
141
|
+
{
|
|
142
|
+
"title": "Fix Codex sharing on Windows",
|
|
143
|
+
"body": "Codex logins blocked by Windows folder permissions can now be prepared for sharing from the Share dialog.",
|
|
144
|
+
"priority": "highlight",
|
|
145
|
+
"icon": "accounts",
|
|
146
|
+
"noticeLabel": "Folder permissions",
|
|
147
|
+
"notice": "Secure permissions and share is optional and restricts the selected Codex folders and auth.json to your Windows user, including changes to inherited access for their contents. Your login, settings and active account stay in place. Automatic network sync never changes folder permissions."
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"title": "Windows updates reach the copy you use",
|
|
151
|
+
"body": "Global npm updates now target the active installation and confirm that newer files arrived before showing installed.",
|
|
152
|
+
"priority": "highlight",
|
|
153
|
+
"noticeLabel": "Already stuck?",
|
|
154
|
+
"notice": "An older Windows installation already stuck at installed may need one manual update to receive this fix. For the desktop app, run the latest Windows installer. For npm, follow the Windows recovery steps in README, then restart ccdeck. Accounts and settings are kept."
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"title": "Reconnect Codex without a false login-change warning",
|
|
158
|
+
"body": "Connecting to an unchanged Codex account no longer pauses control because of its initial account update.",
|
|
159
|
+
"priority": "highlight",
|
|
160
|
+
"icon": "accounts"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"title": "See why a shared login did not arrive",
|
|
164
|
+
"body": "The network map now shows a failed transfer instead of promising that the login will arrive next round."
|
|
165
|
+
}
|
|
166
|
+
],
|
|
167
|
+
"3.81.0": [
|
|
168
|
+
{
|
|
169
|
+
"title": "👥 Codex accounts work the way Claude's do",
|
|
170
|
+
"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.",
|
|
171
|
+
"priority": "highlight",
|
|
172
|
+
"icon": "accounts",
|
|
173
|
+
"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."
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"title": "📡 Share Codex logins with your paired decks",
|
|
177
|
+
"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.",
|
|
178
|
+
"priority": "highlight",
|
|
179
|
+
"icon": "accounts",
|
|
180
|
+
"noticeLabel": "Login privacy",
|
|
181
|
+
"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.",
|
|
182
|
+
"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."
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"title": "⌨️ ccdeck tui looks after the whole deck over SSH",
|
|
186
|
+
"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.",
|
|
187
|
+
"priority": "highlight",
|
|
188
|
+
"details": "A Codex account signs in with a link and a code you type into any browser."
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"title": "➕ Paste a Codex share from the + button",
|
|
192
|
+
"body": "Import Codex accounts is now the Paste a share tab under + in the Codex accounts panel, as on Claude's side."
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"title": "🪟 The desktop window comes back the way you closed it",
|
|
196
|
+
"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.",
|
|
197
|
+
"details": "On macOS, a window reopened after an update or at login never enters full screen."
|
|
198
|
+
}
|
|
199
|
+
],
|
|
138
200
|
"3.80.0": [
|
|
139
201
|
{
|
|
140
202
|
"title": "Switch Codex accounts without losing your place",
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
330
|
+
return { who, body: `${verb} ${to} · ${from} reached ${pctLabel(threshold)}%` };
|
|
320
331
|
}
|
|
321
|
-
if (trigger === "home") return { who
|
|
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
|
|
334
|
+
return { who, body: `Switched to ${to} · weekly limit resets in ${inDuration(resetAt, now)}` };
|
|
324
335
|
}
|
|
325
|
-
return { who
|
|
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
|
-
|
|
576
|
-
|
|
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(
|
|
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 =
|
|
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(
|
|
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(
|
|
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,
|
|
@@ -56,14 +56,14 @@ export async function handleCodexAccountShare(req, res, action) {
|
|
|
56
56
|
const raw = await readBody(req, res, CODEX_SHARE_MAX_LENGTH + 4096).catch(() => null);
|
|
57
57
|
let body;
|
|
58
58
|
try { body = JSON.parse(raw ?? ''); } catch { return send(res, 400, { ok: false, reason: 'bad_request' }); }
|
|
59
|
-
const allowed = action === 'export' ? ['ids'] : ['blob', 'expectedRevision'];
|
|
59
|
+
const allowed = action === 'export' ? ['ids', 'preparePermissions'] : ['blob', 'expectedRevision'];
|
|
60
60
|
if (!body || typeof body !== 'object' || Array.isArray(body) || Object.keys(body).some(key => !allowed.includes(key))) {
|
|
61
61
|
return send(res, 400, { ok: false, reason: 'bad_request' });
|
|
62
62
|
}
|
|
63
63
|
const result = await (action === 'export' ? createCodexShare(body) : importCodexShare(body));
|
|
64
64
|
send(res, 200, result);
|
|
65
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']);
|
|
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', 'windows_permissions_required', 'windows_share_protection_failed']);
|
|
67
67
|
const reason = safe.has(error?.code) ? error.code : 'share_failed';
|
|
68
68
|
send(res, ['selection_conflict', 'selection_busy'].includes(reason) ? 409 : reason === 'unknown_profile' ? 404 : 400, { ok: false, reason });
|
|
69
69
|
}
|
|
@@ -156,6 +156,24 @@ export async function handleCodexProfileQuota(req, res) {
|
|
|
156
156
|
send(res, 200, await readCodexProfileQuota(id, { enableNative: true }));
|
|
157
157
|
}
|
|
158
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
|
+
|
|
159
177
|
export async function handleCodexProfileLaunch(req, res) {
|
|
160
178
|
const { codexProfileLaunchCommand } = await import('./codex-profiles.mjs');
|
|
161
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() {
|
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
// nearly full, move the default to another account that still has room.
|
|
3
3
|
// This loop moves only the registry's default, through selectCodexProfile.
|
|
4
4
|
// Managed exec continuation is a separate adapter of the shared account engine.
|
|
5
|
+
//
|
|
6
|
+
// A HOME ACCOUNT, as Claude's has (account-choice.mjs), by the same rules: it
|
|
7
|
+
// is the first place a full account goes; Auto-switch takes the default back
|
|
8
|
+
// there once it has room again, but only from an account Auto-switch moved to
|
|
9
|
+
// and only after the move has settled — never from one somebody picked by hand;
|
|
10
|
+
// and setting a home while elsewhere moves there on the next tick. Home is a
|
|
11
|
+
// profile, kept by its id, since a Codex account here is a folder.
|
|
5
12
|
import { readFile, mkdir, unlink } from 'node:fs/promises';
|
|
6
13
|
import { randomUUID } from 'node:crypto';
|
|
7
14
|
import { dirname, join, resolve } from 'node:path';
|
|
@@ -19,6 +26,13 @@ const THRESHOLD_MAX = 99;
|
|
|
19
26
|
const DEFAULT_THRESHOLD = '90';
|
|
20
27
|
const COOLDOWN_MS = 5 * 60_000;
|
|
21
28
|
const TICK_MS = 60_000;
|
|
29
|
+
/** How far under the threshold home must sit to be landed on, so a full
|
|
30
|
+
* account is not left for one that fills again at once (ROOM_MARGIN_PCT). */
|
|
31
|
+
const ROOM_MARGIN_PCT = 5;
|
|
32
|
+
/** How long after a move the way back home waits (SETTLE_MS). */
|
|
33
|
+
const SETTLE_MS = 30 * 60_000;
|
|
34
|
+
/** A reading older than this is not landed on, as chooseEngineAccount. */
|
|
35
|
+
const FRESH_FOR_MS = 15 * 60_000;
|
|
22
36
|
const idPattern = /^[a-f0-9]{20}$/;
|
|
23
37
|
|
|
24
38
|
const storeDir = o => resolve(o.store ?? deckDataDir());
|
|
@@ -38,6 +52,8 @@ function validThreshold(v) {
|
|
|
38
52
|
return n >= THRESHOLD_MIN && n <= THRESHOLD_MAX;
|
|
39
53
|
}
|
|
40
54
|
|
|
55
|
+
const idOrNull = v => (typeof v === 'string' && idPattern.test(v) ? v : null);
|
|
56
|
+
|
|
41
57
|
async function load(o) {
|
|
42
58
|
let raw = {};
|
|
43
59
|
try { raw = JSON.parse(await readFile(filePath(o), 'utf8')) ?? {}; } catch { /* missing or corrupt: defaults */ }
|
|
@@ -46,6 +62,16 @@ async function load(o) {
|
|
|
46
62
|
threshold: validThreshold(raw.threshold) ? raw.threshold : DEFAULT_THRESHOLD,
|
|
47
63
|
next: raw.next === 'weekly' ? 'weekly' : 'room',
|
|
48
64
|
heldOut: Array.isArray(raw.heldOut) ? [...new Set(raw.heldOut.filter(id => typeof id === 'string' && idPattern.test(id)))] : [],
|
|
65
|
+
home: idOrNull(raw.home),
|
|
66
|
+
// A home was just set, so the next tick may take the default there.
|
|
67
|
+
goHome: raw.goHome === true && idOrNull(raw.home) != null,
|
|
68
|
+
// The default in use was picked by hand, so the optional way home leaves
|
|
69
|
+
// it alone until it fills or a home is set.
|
|
70
|
+
manual: raw.manual === true,
|
|
71
|
+
// The default the last tick saw, which is how a pick by hand is told from
|
|
72
|
+
// one of Auto-switch's own.
|
|
73
|
+
lastActive: idOrNull(raw.lastActive),
|
|
74
|
+
movedAt: Number.isFinite(raw.movedAt) ? raw.movedAt : 0,
|
|
49
75
|
};
|
|
50
76
|
}
|
|
51
77
|
|
|
@@ -66,7 +92,10 @@ const statusOf = (o, s) => ({
|
|
|
66
92
|
external: false,
|
|
67
93
|
lastTick: mem(o).lastTick,
|
|
68
94
|
settings: { 'autoswitch.threshold': { value: s.threshold, isDefault: s.threshold === DEFAULT_THRESHOLD } },
|
|
95
|
+
// `home` is Claude's shape (an email and an organization); a Codex home is a
|
|
96
|
+
// profile, so it travels as `homeId` and `home` stays empty.
|
|
69
97
|
choice: { next: s.next, home: null },
|
|
98
|
+
homeId: s.home,
|
|
70
99
|
heldOut: s.heldOut,
|
|
71
100
|
});
|
|
72
101
|
|
|
@@ -83,6 +112,18 @@ export function applyCodexAuto(body, options = {}) {
|
|
|
83
112
|
return run;
|
|
84
113
|
}
|
|
85
114
|
|
|
115
|
+
/** What a tick learned, written over the file as it is when the write runs —
|
|
116
|
+
* in the same queue as the panel's writes, so neither undoes the other. */
|
|
117
|
+
function update(options, change) {
|
|
118
|
+
const run = writes.then(async () => {
|
|
119
|
+
const state = await load(options);
|
|
120
|
+
const next = change(state);
|
|
121
|
+
if (next && JSON.stringify(next) !== JSON.stringify(state)) await save(options, next);
|
|
122
|
+
});
|
|
123
|
+
writes = run.catch(() => {});
|
|
124
|
+
return run;
|
|
125
|
+
}
|
|
126
|
+
|
|
86
127
|
async function apply(body, options) {
|
|
87
128
|
const bad = { ok: false, reason: 'bad_request' };
|
|
88
129
|
if (!body || typeof body !== 'object') return bad;
|
|
@@ -105,6 +146,14 @@ async function apply(body, options) {
|
|
|
105
146
|
state.heldOut = state.heldOut.filter(id => id !== body.id);
|
|
106
147
|
if (!body.enabled) state.heldOut.push(body.id);
|
|
107
148
|
break;
|
|
149
|
+
case 'home':
|
|
150
|
+
// One home; null removes it. Set with Auto-switch on or off, as Claude's:
|
|
151
|
+
// a tick reads it only while the switch is on.
|
|
152
|
+
if (body.id !== null && idOrNull(body.id) == null) return bad;
|
|
153
|
+
state.home = body.id;
|
|
154
|
+
state.goHome = body.id !== null;
|
|
155
|
+
state.manual = false;
|
|
156
|
+
break;
|
|
108
157
|
default:
|
|
109
158
|
return bad;
|
|
110
159
|
}
|
|
@@ -119,53 +168,124 @@ const loadOf = live => (live.length ? Math.max(...live.map(w => w.usedPercent))
|
|
|
119
168
|
|
|
120
169
|
const hasLogin = row => (row.signedIn === undefined ? row.signedInFilePresent === true : row.signedIn === true);
|
|
121
170
|
|
|
171
|
+
/** Two profiles that are one ChatGPT account share one quota, so being on
|
|
172
|
+
* either is being on it. */
|
|
173
|
+
const sameLogin = (a, b) => a.id === b.id || a.sameAccountAs === b.id || b.sameAccountAs === a.id
|
|
174
|
+
|| (a.sameAccountAs != null && a.sameAccountAs === b.sameAccountAs);
|
|
175
|
+
|
|
176
|
+
/** What the notifications call a profile: its own name, else who it is signed
|
|
177
|
+
* in as, else the row's label. */
|
|
178
|
+
const nameOf = row => row.managedLabel || row.account || row.label || null;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* One round of the loop. `options.onTick`, when given, is told what the round
|
|
182
|
+
* did (account-watch.mjs `noteCodexAutoTick`, which says the swap notice):
|
|
183
|
+
* `{ enabled: false }` while the loop is off; else `threshold` and `switched`,
|
|
184
|
+
* `reason: 'cooldown'` while the last move settles, and for a move `from`,
|
|
185
|
+
* `to`, `used` and `trigger`. A round that failed tells nothing.
|
|
186
|
+
*/
|
|
122
187
|
export async function codexAutoTick(options = {}) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
188
|
+
let outcome = null;
|
|
189
|
+
try { outcome = await tickOnce(options); } catch { /* a failed round is retried on the next tick */ }
|
|
190
|
+
if (outcome) {
|
|
191
|
+
try { options.onTick?.(outcome); } catch { /* never the loop's problem */ }
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function tickOnce(options) {
|
|
196
|
+
const state = await load(options);
|
|
197
|
+
if (!state.enabled) return { enabled: false };
|
|
198
|
+
const m = mem(options);
|
|
199
|
+
const now = options.now ?? Date.now;
|
|
200
|
+
const threshold = Number(state.threshold);
|
|
201
|
+
const stayed = { enabled: true, threshold, switched: false };
|
|
202
|
+
if (now() - m.lastSwitchAt < COOLDOWN_MS) return { ...stayed, reason: 'cooldown' };
|
|
203
|
+
const nowSec = Math.floor(now() / 1000);
|
|
204
|
+
const readSelection = options.readSelection ?? readCodexSelection;
|
|
205
|
+
const discover = options.discover ?? discoverCodexProfiles;
|
|
206
|
+
const readQuota = options.readQuota ?? readCodexProfileQuota;
|
|
207
|
+
const select = options.select ?? selectCodexProfile;
|
|
208
|
+
|
|
209
|
+
const selection = await readSelection(options);
|
|
210
|
+
const rows = await discover({ ...options, selection, enableNative: true });
|
|
211
|
+
const current = rows.find(r => r.id === selection.profileId);
|
|
212
|
+
if (!current) return stayed;
|
|
213
|
+
const homeRow = state.home ? rows.find(r => r.id === state.home) ?? null : null;
|
|
214
|
+
const onHome = homeRow != null && sameLogin(homeRow, current);
|
|
215
|
+
|
|
216
|
+
// WHO PICKED THE DEFAULT IN USE. One the last tick did not see is a pick
|
|
217
|
+
// by hand — the panel's Switch, or Codex itself — and stays picked until it
|
|
218
|
+
// fills or a home is set. Written over the file as it is now only when the
|
|
219
|
+
// person has not changed home since it was read, or this would undo them.
|
|
220
|
+
const manual = state.manual || (state.lastActive != null && state.lastActive !== current.id);
|
|
221
|
+
const goHome = state.goHome && !onHome;
|
|
222
|
+
if (manual !== state.manual || goHome !== state.goHome || state.lastActive !== current.id) {
|
|
223
|
+
await update(options, s => (s.home === state.home && s.goHome === state.goHome && s.manual === state.manual
|
|
224
|
+
? { ...s, manual, goHome, lastActive: current.id }
|
|
225
|
+
: { ...s, lastActive: current.id }));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const readOpts = { ...options, selection, enableNative: true };
|
|
229
|
+
const currentQuota = await readQuota(current.id, readOpts);
|
|
230
|
+
// Only a reading taken now says how full an account is: the last good one
|
|
231
|
+
// kept for a failed read is an old number, and acting on it moves sessions
|
|
232
|
+
// for a window that may have reset, or onto an account that has since filled.
|
|
233
|
+
const currentLoad = currentQuota?.ok && !currentQuota.stale ? loadOf(liveWindows(currentQuota, nowSec)) : null;
|
|
234
|
+
if (currentLoad === null) return stayed;
|
|
147
235
|
|
|
236
|
+
// Home has room: in rotation, signed in, read recently, and comfortably
|
|
237
|
+
// under the threshold on every window that has not reset.
|
|
238
|
+
const homeHasRoom = async () => {
|
|
239
|
+
if (!homeRow || onHome || homeRow.available === false || !hasLogin(homeRow) || state.heldOut.includes(homeRow.id)) return false;
|
|
240
|
+
const q = await readQuota(homeRow.id, readOpts);
|
|
241
|
+
if (!q?.ok || q.stale || (Number.isFinite(q.fetchedAt) && now() - q.fetchedAt > FRESH_FOR_MS)) return false;
|
|
242
|
+
const load = loadOf(liveWindows(q, nowSec));
|
|
243
|
+
return load !== null && load < threshold - ROOM_MARGIN_PCT;
|
|
244
|
+
};
|
|
245
|
+
/** Move the default to `row`; what the round did, for the notifications. */
|
|
246
|
+
const move = async (row, trigger) => {
|
|
247
|
+
try {
|
|
248
|
+
await select({ id: row.id, expectedRevision: selection.revision, operationId: randomUUID() }, options);
|
|
249
|
+
} catch (e) {
|
|
250
|
+
if (e?.code === 'selection_conflict') return stayed; // somebody else moved it; look again next tick
|
|
251
|
+
throw e;
|
|
252
|
+
}
|
|
253
|
+
m.lastSwitchAt = now();
|
|
254
|
+
m.lastTick = { at: now(), event: 'switched', to: row.id, trigger };
|
|
255
|
+
await update(options, s => ({ ...s, manual: false, lastActive: row.id, movedAt: now(), goHome: s.goHome && row.id !== s.home }));
|
|
256
|
+
return {
|
|
257
|
+
...stayed, switched: true, trigger, used: currentLoad,
|
|
258
|
+
from: { id: current.id, name: nameOf(current) }, to: { id: row.id, name: nameOf(row) },
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
if (currentLoad >= threshold) {
|
|
263
|
+
// HAS TO LEAVE: home first, then the account the engine picks.
|
|
264
|
+
if (await homeHasRoom()) return move(homeRow, 'home');
|
|
148
265
|
// A row that is the same ChatGPT account shares the quota that just ran out.
|
|
149
|
-
const roster = rows.filter(r => r.id !==
|
|
150
|
-
&& !state.heldOut.includes(r.id) && r.sameAccountAs !==
|
|
266
|
+
const roster = rows.filter(r => r.id !== current.id && r.available && hasLogin(r)
|
|
267
|
+
&& !state.heldOut.includes(r.id) && r.sameAccountAs !== current.id);
|
|
151
268
|
const quotas = new Map();
|
|
152
269
|
for (const row of roster) { // one at a time: each read may spawn a process
|
|
153
270
|
quotas.set(row.id, await readQuota(row.id, readOpts));
|
|
154
271
|
}
|
|
155
272
|
const pick = chooseEngineAccount(roster, quotas, { threshold, next: state.next, nowSec });
|
|
156
|
-
|
|
273
|
+
const target = pick ? roster.find(r => r.id === pick.id) : null;
|
|
274
|
+
if (!target) {
|
|
157
275
|
m.lastTick = { at: now(), event: 'nowhere', reason: 'no_account_with_room' };
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
await select({ id: pick.id, expectedRevision: selection.revision, operationId: randomUUID() }, options);
|
|
162
|
-
} catch (e) {
|
|
163
|
-
if (e?.code === 'selection_conflict') return; // somebody else moved it; look again next tick
|
|
164
|
-
throw e;
|
|
276
|
+
return stayed;
|
|
165
277
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
278
|
+
return move(target, 'proactive');
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// BELOW THE THRESHOLD the one move made is the way home, and it is
|
|
282
|
+
// optional: never from home itself, never from a pick by hand, and only
|
|
283
|
+
// once the last move has settled — unless a home was just set, when the
|
|
284
|
+
// person asked to be taken there.
|
|
285
|
+
if (!homeRow || onHome) return stayed;
|
|
286
|
+
const settled = now() - Math.max(m.lastSwitchAt, state.movedAt) >= SETTLE_MS;
|
|
287
|
+
if ((goHome || (!manual && settled)) && await homeHasRoom()) return move(homeRow, 'home');
|
|
288
|
+
return stayed;
|
|
169
289
|
}
|
|
170
290
|
|
|
171
291
|
let stopLoop = null;
|