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
|
@@ -41,8 +41,9 @@
|
|
|
41
41
|
// anything.
|
|
42
42
|
import {
|
|
43
43
|
addTrusted, ANNOUNCE_MS, credentialAad, dropTrusted, identityFrom, open, peerWhy, plan, PRESENT_MS,
|
|
44
|
-
sharedWith, stillListed, transferChallenge, trustedPeer,
|
|
44
|
+
sharedWith, slotFor, stillListed, transferChallenge, trustedPeer,
|
|
45
45
|
} from "./lan-sync.mjs";
|
|
46
|
+
import { isCodexKey, offeredCodex, planCodex } from "./lan-codex.mjs";
|
|
46
47
|
import { mintInvite, readInvite } from "./lan-invite.mjs";
|
|
47
48
|
import { createInviteOffer } from "./lan-invite-offer.mjs";
|
|
48
49
|
import { syncAccounts } from "./lan-accounts.mjs";
|
|
@@ -252,6 +253,10 @@ function askOver(conn, frame) {
|
|
|
252
253
|
*/
|
|
253
254
|
export function createEngine({
|
|
254
255
|
readAccounts, exportAccount, importAccount, checkArrivals, liveLogin,
|
|
256
|
+
/** This deck's Codex logins — `readAccounts`, `exportAccount(id, key)` and
|
|
257
|
+
* `importAccount(blob, step, mine)`, see lan-codex-store.mjs — or nothing,
|
|
258
|
+
* which is a deck that offers and takes Claude logins only. */
|
|
259
|
+
codex = null,
|
|
255
260
|
onChange, onError, onIdentity, onPort, onTrust, onUnpaired, onDial, onShared, now = Date.now,
|
|
256
261
|
/**
|
|
257
262
|
* The UDP socket the beacon shouts through, injectable for the same reason
|
|
@@ -440,6 +445,15 @@ export function createEngine({
|
|
|
440
445
|
await usage?.refresh(accounts);
|
|
441
446
|
return accounts;
|
|
442
447
|
};
|
|
448
|
+
/** This deck's Codex logins in the same shape, or null for a deck without
|
|
449
|
+
* them. A Codex store that cannot be read offers nothing this time; it is
|
|
450
|
+
* never a reason for a round, or the Claude logins in it, to fail. */
|
|
451
|
+
const localCodex = codex ? async () => {
|
|
452
|
+
try {
|
|
453
|
+
const rows = await codex.readAccounts();
|
|
454
|
+
return Array.isArray(rows) ? rows.filter(r => isCodexKey(r?.key)) : [];
|
|
455
|
+
} catch { return []; }
|
|
456
|
+
} : null;
|
|
443
457
|
|
|
444
458
|
/** This deck's side of the manifest exchange: the frame it sends, what it
|
|
445
459
|
* keeps of the one it hears — a paired deck's card and the logins it offers,
|
|
@@ -522,6 +536,7 @@ export function createEngine({
|
|
|
522
536
|
const { serve } = createServe({
|
|
523
537
|
settings: () => cfg, serverNow: () => server, myFp: () => identity.fp,
|
|
524
538
|
inbound, learnCaller, keepManifest, manifestFrame, localAccounts, liveLogin, exportAccount, onError,
|
|
539
|
+
localCodex, exportCodex: codex ? (id, key) => codex.exportAccount(id, key) : null,
|
|
525
540
|
});
|
|
526
541
|
|
|
527
542
|
/**
|
|
@@ -626,7 +641,8 @@ export function createEngine({
|
|
|
626
641
|
/** Checks the logins a round brought, once, and records any reason one is
|
|
627
642
|
* unusable here on its row. An unanswered check is not a failure. */
|
|
628
643
|
const markArrivals = async done => {
|
|
629
|
-
|
|
644
|
+
// claude-swap's logins only: it is claude-swap that is asked.
|
|
645
|
+
const arrived = done.filter(d => d.ok && d.provider !== "codex");
|
|
630
646
|
if (!arrived.length || !checkArrivals) return;
|
|
631
647
|
let found = null;
|
|
632
648
|
try { found = await checkArrivals(arrived); } catch { /* unasked is not a failure of the round */ }
|
|
@@ -742,10 +758,11 @@ export function createEngine({
|
|
|
742
758
|
&& trustedPeer(cfg.trusted, conn.peerFp)?.pub === conn.peerPub;
|
|
743
759
|
if (!stillPaired()) throw new Error("peer no longer paired");
|
|
744
760
|
const mine = await localAccounts();
|
|
761
|
+
const mineCodex = localCodex ? await localCodex() : null;
|
|
745
762
|
// The owner can revoke trust or disable sync while the store is read.
|
|
746
763
|
// Never send this deck's account identities on that old connection.
|
|
747
764
|
if (!stillPaired()) throw new Error("peer no longer paired");
|
|
748
|
-
const theirs = await ask(manifestFrame(mine, conn.key, conn.peerFp));
|
|
765
|
+
const theirs = await ask(manifestFrame(mine, conn.key, conn.peerFp, mineCodex));
|
|
749
766
|
// A response from a round that was stopped or unpaired is stale even
|
|
750
767
|
// when the peer had already sent it before the setting changed.
|
|
751
768
|
if (!stillPaired()) throw new Error("peer no longer paired");
|
|
@@ -802,7 +819,14 @@ export function createEngine({
|
|
|
802
819
|
// the store lock, while the panel drew 50 and every other paired deck
|
|
803
820
|
// waited behind it. `step.key` also reached transferChallenge and
|
|
804
821
|
// importAccount untyped, which `offered`'s filter would have caught.
|
|
805
|
-
|
|
822
|
+
// AND THEN ITS CODEX LOGINS, after every Claude one and by the same steps
|
|
823
|
+
// below — a `want` with its own proof, a sealed `have`, an import, a tick
|
|
824
|
+
// onward for an add. Their own list, read off the frame here because the
|
|
825
|
+
// token history the heal needs is not kept (see lan-codex.mjs).
|
|
826
|
+
const wanted = [
|
|
827
|
+
...plan(mine, list),
|
|
828
|
+
...(mineCodex ? planCodex(mineCodex, offeredCodex(theirs.codex)) : []),
|
|
829
|
+
];
|
|
806
830
|
/** One login, asked for and opened: a `want` carrying its own proof that
|
|
807
831
|
* names the account (see transferChallenge), and the `have` opened under
|
|
808
832
|
* the additional data it was sealed with. The login, or why there is
|
|
@@ -840,9 +864,13 @@ export function createEngine({
|
|
|
840
864
|
// The step goes down with the blob: the wiring has to know WHICH account
|
|
841
865
|
// it is placing before it may treat a decline as an empty slot rather
|
|
842
866
|
// than as a healthy one.
|
|
867
|
+
// A Codex login goes to the Codex store, with the copy it heals.
|
|
843
868
|
let got;
|
|
844
|
-
try {
|
|
845
|
-
|
|
869
|
+
try {
|
|
870
|
+
got = step.provider === "codex"
|
|
871
|
+
? await codex.importAccount(blob, step, slotFor(mineCodex, step.key))
|
|
872
|
+
: await importAccount(blob, step);
|
|
873
|
+
} catch {
|
|
846
874
|
// One local store failure must not erase earlier arrivals or stop
|
|
847
875
|
// independent logins from being received. Store diagnostics can
|
|
848
876
|
// contain credential material, so only a fixed verdict leaves here.
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// lan-copies.mjs's, and the card's are lan-about.mjs's.
|
|
7
7
|
import { currentFor, heardCurrent, manifestFor, offered, sharedWith } from "./lan-sync.mjs";
|
|
8
8
|
import { openAbout, sealAbout } from "./lan-about.mjs";
|
|
9
|
+
import { codexManifest, offeredCodex } from "./lan-codex.mjs";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* `about` is this deck's own card, or null for a deck built without one. `now`
|
|
@@ -40,7 +41,7 @@ export function createManifests({ about, now, myFp, settings, usage = null }) {
|
|
|
40
41
|
* it shares with that deck (see sharedWith), which of them it is on, and its
|
|
41
42
|
* card. One frame whichever way it travels — the question a round asks, and
|
|
42
43
|
* the answer `serve` gives. */
|
|
43
|
-
const manifestFrame = (accounts, key, toFp) => {
|
|
44
|
+
const manifestFrame = (accounts, key, toFp, codexAccounts = null) => {
|
|
44
45
|
const cfg = settings();
|
|
45
46
|
const shared = sharedWith(cfg, toFp);
|
|
46
47
|
const list = manifestFor(accounts, shared, { sendInUse: cfg.sendInUse === true, shareActive: cfg.shareActive });
|
|
@@ -51,6 +52,12 @@ export function createManifests({ about, now, myFp, settings, usage = null }) {
|
|
|
51
52
|
// The readings this deck owns for accounts in `list`, sealed like the
|
|
52
53
|
// card. An older deck ignores the key, as it ignores the card.
|
|
53
54
|
...(usage ? usage.fieldFor(key, toFp, list) : {}),
|
|
55
|
+
// The Codex logins it shares with that deck, by Claude's rules, in a list
|
|
56
|
+
// of their own that an older deck never reads — see lan-codex.mjs. Sent
|
|
57
|
+
// empty too, so unticking the last one is heard.
|
|
58
|
+
...(Array.isArray(codexAccounts)
|
|
59
|
+
? { codex: codexManifest(codexAccounts, shared, { sendInUse: cfg.sendInUse === true, shareActive: cfg.shareActive }) }
|
|
60
|
+
: {}),
|
|
54
61
|
};
|
|
55
62
|
};
|
|
56
63
|
|
|
@@ -67,7 +74,14 @@ export function createManifests({ about, now, myFp, settings, usage = null }) {
|
|
|
67
74
|
if (card) aboutBy.set(fromFp, { ...card, at: now() });
|
|
68
75
|
if (!Array.isArray(frame.accounts)) return null;
|
|
69
76
|
const list = offered(frame.accounts);
|
|
70
|
-
offersBy.set(fromFp, {
|
|
77
|
+
offersBy.set(fromFp, {
|
|
78
|
+
at: now(), accounts: list, current: heardCurrent(frame.current, list),
|
|
79
|
+
// Its Codex logins, from a deck new enough to send them — without their
|
|
80
|
+
// token history, which only the round reads, and reads off the frame.
|
|
81
|
+
...(Array.isArray(frame.codex)
|
|
82
|
+
? { codex: offeredCodex(frame.codex).map(({ rt: _rt, was: _was, ...row }) => row) }
|
|
83
|
+
: {}),
|
|
84
|
+
});
|
|
71
85
|
// Never awaited: handing a reading to claude-swap runs behind the round.
|
|
72
86
|
usage?.heard(key, frame, fromFp, list);
|
|
73
87
|
return list;
|
package/src/server/lan-serve.mjs
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// of them can change while the store is read.
|
|
8
8
|
import { credentialAad, IN_USE, mayGiveInUse, seal, sharedWith, slotFor, transferChallenge, trustedPeer } from "./lan-sync.mjs";
|
|
9
9
|
import { liveLoginIs } from "./account-health.mjs";
|
|
10
|
+
import { isCodexKey } from "./lan-codex.mjs";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* `settings`, `serverNow` and `myFp` answer the engine's settings in force,
|
|
@@ -15,11 +16,13 @@ import { liveLoginIs } from "./account-health.mjs";
|
|
|
15
16
|
* `learnCaller` is the engine's dial-back for a paired deck nothing here
|
|
16
17
|
* dials. `keepManifest` and `manifestFrame` are lan-manifest.mjs's,
|
|
17
18
|
* `localAccounts` reads the store in the rules' shape, and `liveLogin`,
|
|
18
|
-
* `exportAccount` and `onError` are the engine's own.
|
|
19
|
+
* `exportAccount` and `onError` are the engine's own. `localCodex` and
|
|
20
|
+
* `exportCodex` are the same two for Codex logins, or null on a deck without
|
|
21
|
+
* them — see lan-codex.mjs.
|
|
19
22
|
*/
|
|
20
23
|
export function createServe({
|
|
21
24
|
settings, serverNow, myFp, inbound, learnCaller, keepManifest, manifestFrame, localAccounts, liveLogin, exportAccount,
|
|
22
|
-
onError,
|
|
25
|
+
localCodex = null, exportCodex = null, onError,
|
|
23
26
|
}) {
|
|
24
27
|
/** Frames from a deck that finished the handshake AND that somebody here has
|
|
25
28
|
* accepted. Nothing reaches this before both, which is the whole point of
|
|
@@ -48,11 +51,12 @@ export function createServe({
|
|
|
48
51
|
// nothing here dials is ever known by what it offers.
|
|
49
52
|
keepManifest(ctx.key, msg, ctx.peerFp);
|
|
50
53
|
const accounts = await localAccounts();
|
|
54
|
+
const codexAccounts = localCodex ? await localCodex() : null;
|
|
51
55
|
// Reading the store can take long enough for the owner to unpair this
|
|
52
56
|
// deck. Do not disclose account identities or the active account from
|
|
53
57
|
// a manifest assembled before that decision.
|
|
54
58
|
if (!mayAnswer()) return ctx.send({ t: "no", why: "not paired" });
|
|
55
|
-
return ctx.send(manifestFrame(accounts, ctx.key, ctx.peerFp));
|
|
59
|
+
return ctx.send(manifestFrame(accounts, ctx.key, ctx.peerFp, codexAccounts));
|
|
56
60
|
}
|
|
57
61
|
if (msg.t === "want") {
|
|
58
62
|
// A listener may have authenticated this socket before its owner
|
|
@@ -78,10 +82,16 @@ export function createServe({
|
|
|
78
82
|
if (typeof msg.proof !== "string" || msg.proof !== want) {
|
|
79
83
|
return ctx.send({ t: "no", why: "proof" });
|
|
80
84
|
}
|
|
85
|
+
// A CODEX LOGIN takes every step below in the same order, from its own
|
|
86
|
+
// store: the tick, the slot, the one this deck is on, readable, alive.
|
|
87
|
+
// Only the CLI check is Claude's, since it asks claude-swap who is
|
|
88
|
+
// signed in. A deck without Codex has none to give.
|
|
89
|
+
const codexWant = isCodexKey(msg.key);
|
|
90
|
+
if (codexWant && !(localCodex && exportCodex)) return ctx.send({ t: "no", why: "not mine to give" });
|
|
81
91
|
// Only what the user ticked, checked again here rather than trusted
|
|
82
92
|
// from the manifest we sent: the list can change between the two, and
|
|
83
93
|
// the answer that matters is the one at the moment of sending.
|
|
84
|
-
const accounts = await localAccounts();
|
|
94
|
+
const accounts = codexWant ? await localCodex() : await localAccounts();
|
|
85
95
|
if (!maySend()) return ctx.send({ t: "no", why: "not shared" });
|
|
86
96
|
// The slot manifestFor told the peer about, by the same rule: with two
|
|
87
97
|
// slots for one identity, an expired one listed first must not hide a
|
|
@@ -106,11 +116,16 @@ export function createServe({
|
|
|
106
116
|
if (!mine.alive) return ctx.send({ t: "no", why: "not mine to give" });
|
|
107
117
|
// The active slot exports the live CLI login, and its verdict can
|
|
108
118
|
// predate a `/login` as somebody else, so ask the CLI who it is now.
|
|
109
|
-
if (mine.active && liveLogin && !liveLoginIs(await liveLogin(), mine.email, mine.org)) {
|
|
119
|
+
if (!codexWant && mine.active && liveLogin && !liveLoginIs(await liveLogin(), mine.email, mine.org)) {
|
|
110
120
|
return ctx.send({ t: "no", why: "export failed" });
|
|
111
121
|
}
|
|
112
122
|
if (!maySend()) return ctx.send({ t: "no", why: "not shared" });
|
|
113
|
-
|
|
123
|
+
let blob;
|
|
124
|
+
try { blob = codexWant ? await exportCodex(mine.num, msg.key) : await exportAccount(mine.num, msg.key); }
|
|
125
|
+
catch (err) {
|
|
126
|
+
if (codexWant && err?.code === 'windows_permissions_required') return ctx.send({ t: 'no', why: 'windows_permissions_required' });
|
|
127
|
+
throw err;
|
|
128
|
+
}
|
|
114
129
|
if (!maySend()) return ctx.send({ t: "no", why: "not shared" });
|
|
115
130
|
// A Mac's failed export refreshes the verdict behind `readable` in the
|
|
116
131
|
// background, so when the Keychain was why, the next ask is answered by
|
package/src/server/lifecycle.mjs
CHANGED
|
@@ -166,7 +166,7 @@ async function handleUpgrade(_req, res) {
|
|
|
166
166
|
// has finished booting this settled long ago; it only waits for a press that
|
|
167
167
|
// lands in the first moments of a boot, or on a server nothing marked ready.
|
|
168
168
|
await pinRunningBuild();
|
|
169
|
-
const out = startUpgrade({ pkgRoot: PKG_ROOT });
|
|
169
|
+
const out = startUpgrade({ pkgRoot: PKG_ROOT, running: RUNNING_VERSION });
|
|
170
170
|
if (out.ok) selfUpdateStarted();
|
|
171
171
|
send(res, out.ok ? 200 : 409, out);
|
|
172
172
|
}
|
|
@@ -414,7 +414,7 @@ async function awayUpdateTick() {
|
|
|
414
414
|
// Pinned before npm is spawned, never after it — see pinned-build.mjs. On a
|
|
415
415
|
// deck bin/deck.js has marked ready this is a promise that settled long ago.
|
|
416
416
|
await pinRunningBuild();
|
|
417
|
-
const started = su.startUpgrade({ pkgRoot: PKG_ROOT });
|
|
417
|
+
const started = su.startUpgrade({ pkgRoot: PKG_ROOT, running: RUNNING_VERSION });
|
|
418
418
|
if (started?.ok) selfUpdateStarted();
|
|
419
419
|
return step.act;
|
|
420
420
|
}
|
|
@@ -9,14 +9,16 @@
|
|
|
9
9
|
// upgrade is refused and how the last one went for the version report, and
|
|
10
10
|
// re-exports every name, so index.mjs still reaches startUpgrade there. The
|
|
11
11
|
// code is unchanged.
|
|
12
|
+
import { npmPrefix } from "./terminal-cli.mjs";
|
|
13
|
+
import { isOlder } from "./version-order.mjs";
|
|
12
14
|
import { inApp } from "./app-host.mjs";
|
|
13
15
|
import { accessSync, constants as FS, unlinkSync, writeFileSync } from "node:fs";
|
|
14
16
|
import { spawn } from "node:child_process";
|
|
15
17
|
import { join, resolve } from "node:path";
|
|
16
|
-
import { killTree, shimPath, spawnSpec } from "./exec.mjs";
|
|
18
|
+
import { killTree, shimPath, spawnSpec, shellQuoteArg } from "./exec.mjs";
|
|
17
19
|
import { npmCliLaunch } from "./npx.mjs";
|
|
18
20
|
import {
|
|
19
|
-
frozenNameInstall, hostPackage, installedName, isGitCheckout, isNpxInstall, isOneOffRun,
|
|
21
|
+
frozenNameInstall, hostPackage, installedName, installedVersion, isGitCheckout, isNpxInstall, isOneOffRun,
|
|
20
22
|
PUBLISHED_NAME, successorRoot, upgradeCommand, upgradeName,
|
|
21
23
|
} from "./install-layout.mjs";
|
|
22
24
|
|
|
@@ -235,7 +237,7 @@ export function upgradeStatus() {
|
|
|
235
237
|
* assembled from request input: the only thing that varies is which alias, and
|
|
236
238
|
* that is read off the install on disk and confined to ALIAS_PACKAGES.
|
|
237
239
|
*/
|
|
238
|
-
export function startUpgrade({ pkgRoot, name = PUBLISHED_NAME }) {
|
|
240
|
+
export function startUpgrade({ pkgRoot, name = PUBLISHED_NAME, running = installedVersion(pkgRoot) }) {
|
|
239
241
|
if (_upgrade.state === "running") return { ok: true, already: true, command: _upgrade.command };
|
|
240
242
|
const blocked = upgradeBlock(pkgRoot);
|
|
241
243
|
if (blocked) return { ok: false, reason: blocked, command: upgradeCommand(pkgRoot, name) };
|
|
@@ -245,18 +247,27 @@ export function startUpgrade({ pkgRoot, name = PUBLISHED_NAME }) {
|
|
|
245
247
|
// there wrote a tree this process never reads, so the version on disk never
|
|
246
248
|
// moved and the same update was offered forever.
|
|
247
249
|
const target = upgradeName(pkgRoot, name);
|
|
248
|
-
const
|
|
250
|
+
const installRoot = hostPackage(pkgRoot, installedName(pkgRoot))?.root ?? successorRoot(pkgRoot) ?? pkgRoot;
|
|
251
|
+
const prefix = npmPrefix(installRoot, undefined, process.platform);
|
|
252
|
+
const spec = upgradeSpec(target, process.platform, undefined, prefix);
|
|
249
253
|
// The LOGICAL vector, not the cmd.exe line: this string is shown to the user
|
|
250
254
|
// and is the one they can paste. `cmd /d /s /c "…"` is an implementation
|
|
251
255
|
// detail of how this platform reaches npm, and pasting it would be advice
|
|
252
256
|
// about the deck rather than about their install.
|
|
253
|
-
const command = `npm ${spec.plain.join(" ")}`;
|
|
257
|
+
const command = `npm ${spec.plain.map(arg => arg === prefix ? shellQuoteArg(arg) : arg).join(" ")}`;
|
|
254
258
|
setUpgrade("running", command);
|
|
255
259
|
// Deliberately does not restart anything once it is done. The new files on
|
|
256
260
|
// disk make installedVersion() disagree with the running one, and the
|
|
257
261
|
// ordinary drift path takes it from there — including its wait for an idle
|
|
258
262
|
// moment.
|
|
259
|
-
if (!runInstall(spec, (state, error) =>
|
|
263
|
+
if (!runInstall(spec, (state, error) => {
|
|
264
|
+
// A zero exit can mean npm wrote into another Node manager's prefix, or
|
|
265
|
+
// installed the same version again. Only the active copy's fresh manifest
|
|
266
|
+
// can establish that there are newer files for this process to restart.
|
|
267
|
+
if (state === "done" && !isOlder(running, installedVersion(pkgRoot))) {
|
|
268
|
+
setUpgrade("failed", command, "The install finished, but this running copy was not updated. Retry the update or reinstall this copy in its existing location.");
|
|
269
|
+
} else setUpgrade(state, command, error);
|
|
270
|
+
})) {
|
|
260
271
|
return { ok: false, reason: "spawn_failed", command };
|
|
261
272
|
}
|
|
262
273
|
return { ok: true, command };
|
|
@@ -66,6 +66,9 @@ const PINNED_MODULES = [
|
|
|
66
66
|
"codex-auto.mjs",
|
|
67
67
|
"codex-profiles.mjs", "codex-selection.mjs", "codex-live-engine.mjs",
|
|
68
68
|
"codex-share.mjs", "codex-login.mjs",
|
|
69
|
+
// The Codex profile Projects report, reached only through import() from its
|
|
70
|
+
// route (it imports account-projects.mjs, pinned below, for the day rule).
|
|
71
|
+
"codex-projects.mjs",
|
|
69
72
|
"ccusage.mjs",
|
|
70
73
|
"browser-watch.mjs",
|
|
71
74
|
"browser-watch-store.mjs",
|
|
@@ -447,6 +447,9 @@ export const GUARDED_READS = new Set([
|
|
|
447
447
|
// credentials are deliberately omitted from the response.
|
|
448
448
|
"/api/codex-profiles",
|
|
449
449
|
"/api/codex-profile-quota",
|
|
450
|
+
// Per-project token spend of one Codex profile: the Claude report's class of
|
|
451
|
+
// secret, under the same rule as /api/account-projects below.
|
|
452
|
+
"/api/codex-profile-projects",
|
|
450
453
|
"/api/codex-auto",
|
|
451
454
|
"/api/codex-profile-launch",
|
|
452
455
|
"/api/codex-profile-login",
|
|
@@ -60,79 +60,9 @@ export {
|
|
|
60
60
|
upgradeStatus,
|
|
61
61
|
} from "./npm-upgrade.mjs";
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
import { isOlder } from "./version-order.mjs";
|
|
64
|
+
export { isOlder } from "./version-order.mjs";
|
|
64
65
|
|
|
65
|
-
/** Numeric-segment compare of one version's parts: -1, 0 or 1. Non-numeric
|
|
66
|
-
* segments count as 0 and missing segments pad with 0, so "1.30" sorts before
|
|
67
|
-
* "1.30.1" and "1.9.0" before "1.10.0". */
|
|
68
|
-
function cmpParts(x, y) {
|
|
69
|
-
for (let i = 0; i < Math.max(x.length, y.length); i++) {
|
|
70
|
-
const d = (x[i] ?? 0) - (y[i] ?? 0);
|
|
71
|
-
if (d !== 0) return d < 0 ? -1 : 1;
|
|
72
|
-
}
|
|
73
|
-
return 0;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** A version split at the FIRST `-`: the release on one side, the prerelease
|
|
77
|
-
* identifiers on the other, or null when there is no prerelease at all.
|
|
78
|
-
*
|
|
79
|
-
* `+` stays inside the release half rather than starting a third part, which
|
|
80
|
-
* keeps build metadata reading exactly as it read before — `1.0.0+build.7`
|
|
81
|
-
* segments to [1,0,0,0,7] and therefore sorts above `1.0.0`. That is inherited
|
|
82
|
-
* behaviour rather than a design, this repo has never published one, and a
|
|
83
|
-
* change to it belongs in its own issue. */
|
|
84
|
-
function versionParts(v) {
|
|
85
|
-
const nums = (s) => s.split(/[.+]/).map(n => parseInt(n, 10)).map(n => Number.isNaN(n) ? 0 : n);
|
|
86
|
-
const dash = v.indexOf("-");
|
|
87
|
-
if (dash === -1) return { release: nums(v), pre: null };
|
|
88
|
-
return { release: nums(v.slice(0, dash)), pre: nums(v.slice(dash + 1)) };
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** True when `a` sorts before `b`.
|
|
92
|
-
*
|
|
93
|
-
* A PRERELEASE SORTS BELOW THE RELEASE IT PRECEDES (#976), which is semver's
|
|
94
|
-
* rule and was not this function's. Splitting on `[.\-+]` and mapping
|
|
95
|
-
* non-numeric segments to 0 made `3.23.0-rc.1` segment to [3,23,0,0,1] — five
|
|
96
|
-
* numbers against the release's three, so it compared ABOVE `3.23.0` and the
|
|
97
|
-
* release compared below the candidate it was meant to supersede:
|
|
98
|
-
*
|
|
99
|
-
* isOlder("3.23.0-rc.1", "3.23.0") = false ← the release never looked newer
|
|
100
|
-
* isOlder("3.23.0", "3.23.0-rc.1") = true ← and the deck would go backwards
|
|
101
|
-
*
|
|
102
|
-
* What that costs is not a cosmetic ordering. `autoUpdate` defaults on, so a
|
|
103
|
-
* deck that has ended up on a prerelease — installed by hand by a tester, or
|
|
104
|
-
* by the dist-tag accident publish.yml now prevents — produces no upgrade
|
|
105
|
-
* notice when the real release ships, shows nothing in the banner, and has no
|
|
106
|
-
* way to come back off it from inside the product. A bad release can be
|
|
107
|
-
* followed by a good one; a fleet that cannot SEE the good one cannot be
|
|
108
|
-
* rescued by publishing it, which is why this half matters even with the
|
|
109
|
-
* dist-tag half in place.
|
|
110
|
-
*
|
|
111
|
-
* Ordinary numeric ordering is untouched — the release halves are compared
|
|
112
|
-
* exactly as before — and so is build metadata; see versionParts.
|
|
113
|
-
*
|
|
114
|
-
* cswap-install.mjs had this written out a second time, without the type guard
|
|
115
|
-
* below, and imports it from here now (#374). The two bodies were identical:
|
|
116
|
-
* swept over 271,441 version-string pairs they disagreed on none, and the
|
|
117
|
-
* guard was the whole difference — `isOlder(null, "1.0.0")` answers false here
|
|
118
|
-
* and threw a TypeError there. Nothing could reach that call with a non-string
|
|
119
|
-
* (both arguments are behind `typeof v === "string"` checks at the one call
|
|
120
|
-
* site), so this is the copy with a test behind it absorbing the one without,
|
|
121
|
-
* not a bug fix. That sweep is now one-sided on prerelease pairs and
|
|
122
|
-
* duplicated-helpers.test.ts says which, rather than asserting an equality
|
|
123
|
-
* that has deliberately stopped holding. */
|
|
124
|
-
export function isOlder(a, b) {
|
|
125
|
-
if (typeof a !== "string" || typeof b !== "string") return false;
|
|
126
|
-
const x = versionParts(a), y = versionParts(b);
|
|
127
|
-
const release = cmpParts(x.release, y.release);
|
|
128
|
-
if (release !== 0) return release < 0;
|
|
129
|
-
// Same release. A version carrying a prerelease is below the plain one, and
|
|
130
|
-
// never the other way round; two prereleases of one release compare on their
|
|
131
|
-
// own identifiers, so rc.2 is above rc.1.
|
|
132
|
-
if (x.pre && !y.pre) return true;
|
|
133
|
-
if (!x.pre || !y.pre) return false;
|
|
134
|
-
return cmpParts(x.pre, y.pre) < 0;
|
|
135
|
-
}
|
|
136
66
|
|
|
137
67
|
// ── the notice ───────────────────────────────────────────────────────────────
|
|
138
68
|
|
|
@@ -75,8 +75,14 @@ function unixCli({ env, exists, read, realpath }) {
|
|
|
75
75
|
* — or null for any other layout: pnpm, yarn and bun keep their globals
|
|
76
76
|
* elsewhere, and a project's own node_modules has a package around it, as a
|
|
77
77
|
* global prefix's `lib` never does (install-layout.mjs, frozenNameInstall). */
|
|
78
|
-
function npmPrefix(root, read) {
|
|
79
|
-
const
|
|
78
|
+
export function npmPrefix(root, read = readFileSync, platform = "linux") {
|
|
79
|
+
const path = platform === "win32" ? win32 : posix;
|
|
80
|
+
const modules = path.dirname(root);
|
|
81
|
+
if (platform === "win32") {
|
|
82
|
+
const prefix = path.dirname(modules);
|
|
83
|
+
return path.basename(modules).toLowerCase() === "node_modules"
|
|
84
|
+
&& manifest(path.join(prefix, "package.json"), read) === undefined ? prefix : null;
|
|
85
|
+
}
|
|
80
86
|
const lib = posix.dirname(modules);
|
|
81
87
|
if (posix.basename(modules) !== "node_modules" || posix.basename(lib) !== "lib") return null;
|
|
82
88
|
if (manifest(posix.join(lib, "package.json"), read) !== undefined) return null;
|
|
@@ -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");
|