ccdeck 3.52.0 → 3.53.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 +13 -4
- package/bin/cli/help.js +1 -1
- package/bin/cli/one-shot.js +3 -2
- package/bin/cli/second-start.js +2 -2
- package/bin/cli/uninstall.js +1 -1
- package/bin/codex-profile.js +21 -0
- package/bin/deck.js +4 -3
- package/dist/web/assets/{BrowserWatchModal-CRqdEVdh.js → BrowserWatchModal-ByNoan60.js} +1 -1
- package/dist/web/assets/{IntegrationModal-BDzEIGSM.js → IntegrationModal-tKQbB-JM.js} +1 -1
- package/dist/web/assets/{RadioPanel-BJlsCpnN.js → RadioPanel-yTqDyeoT.js} +1 -1
- package/dist/web/assets/{TrafficRadar-BGxw-hlO.js → TrafficRadar-Dse2YLny.js} +1 -1
- package/dist/web/assets/{UsageHistoryModal-C_WBpNIp.js → UsageHistoryModal-Cmbih6Xe.js} +1 -1
- package/dist/web/assets/{app-B53fC4gE.js → app-Dx9D4Afq.js} +96 -96
- package/dist/web/assets/{app-Co1HNGP8.css → app-xTrs4aEH.css} +1 -1
- package/dist/web/assets/{index-D9nJhUJR.js → index-BsEQrAAC.js} +1 -1
- package/dist/web/index.html +3 -3
- package/package.json +1 -1
- package/release-notes.json +24 -1
- package/src/server/account-routes.mjs +99 -0
- package/src/server/account-watch.mjs +1 -1
- package/src/server/cli-versions.mjs +3 -3
- package/src/server/codex-auth.mjs +51 -9
- package/src/server/codex-auto.mjs +196 -0
- package/src/server/codex-login.mjs +117 -0
- package/src/server/codex-native-account.mjs +288 -0
- package/src/server/codex-profiles.mjs +243 -0
- package/src/server/codex-quota.mjs +370 -251
- package/src/server/codex-selection.mjs +371 -0
- package/src/server/codex-terminal-runner.mjs +78 -0
- package/src/server/codex-terminal.mjs +109 -0
- package/src/server/codex-watch.mjs +38 -22
- package/src/server/depth-facts.mjs +1 -1
- package/src/server/discovery.mjs +13 -0
- package/src/server/index.mjs +19 -1
- package/src/server/installer.mjs +11 -5
- package/src/server/log-election.mjs +32 -3
- package/src/server/login-service.mjs +1 -1
- package/src/server/memory-files.mjs +2 -2
- package/src/server/pinned-build.mjs +3 -0
- package/src/server/request-gates.mjs +9 -0
- package/src/server/running-deck.mjs +12 -1
- package/src/server/session-enrichment.mjs +2 -2
- package/src/server/tool-audit.mjs +15 -1
- package/src/server/usage-routes.mjs +1 -1
|
@@ -8,16 +8,17 @@
|
|
|
8
8
|
// cwd and the chunked reader from the modules that own them — nothing here
|
|
9
9
|
// reads the ring or the SSE clients. index.mjs starts the watcher. The bodies
|
|
10
10
|
// are unchanged.
|
|
11
|
-
import { stat } from "node:fs/promises";
|
|
12
|
-
import { basename, join } from "node:path";
|
|
11
|
+
import { stat, readdir } from "node:fs/promises";
|
|
12
|
+
import { basename, dirname, join } from "node:path";
|
|
13
13
|
import { PRODUCT } from "./brand.mjs";
|
|
14
14
|
import { STOP, rolloutNameId, sidFromRolloutName, walkRolloutDays } from "./codex-dir.mjs";
|
|
15
|
+
import { codexProfileSessionDirs } from "./codex-profiles.mjs";
|
|
15
16
|
// What one rollout line means as a hook payload, and the shape of the header
|
|
16
17
|
// record that says whose rollout it is — see codex-translate.mjs. The watcher
|
|
17
18
|
// below still decides which lines are read and where each one goes.
|
|
18
19
|
import { codexObjToPayload, codexSessionModel, sessionMeta } from "./codex-translate.mjs";
|
|
19
20
|
import { noteCodexSkills } from "./codex-skills.mjs";
|
|
20
|
-
import { codexCwdInWorkspace, writesCodexLog } from "./log-election.mjs";
|
|
21
|
+
import { canonicalLogPath, codexCwdInWorkspace, writesCodexLog } from "./log-election.mjs";
|
|
21
22
|
// The one spelling of a rollout's cwd — see canonical-path.mjs.
|
|
22
23
|
import { canonicalCwd } from "./canonical-path.mjs";
|
|
23
24
|
import { eventLogPath } from "./event-log.mjs";
|
|
@@ -163,19 +164,27 @@ let codexWorkspace = "";
|
|
|
163
164
|
// land in today's dir, so this captures live activity without scanning years
|
|
164
165
|
// of history every tick. With `all`, the rest of the tree is listed too, as
|
|
165
166
|
// `older` — the walk codexOlderRollouts is filled from.
|
|
167
|
+
const rolloutHome = path => dirname(dirname(dirname(dirname(dirname(path)))));
|
|
168
|
+
|
|
166
169
|
async function listRecentCodexRollouts(all = false) {
|
|
167
170
|
const out = [];
|
|
168
171
|
const older = [];
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
172
|
+
const availableHomes = new Set();
|
|
173
|
+
const sweepHomes = new Set();
|
|
174
|
+
// Each home needs its own two newest days. Otherwise a busy default account
|
|
175
|
+
// can prevent the newest rollout in an alternate account from being seen.
|
|
176
|
+
for (const sessionsDir of await codexProfileSessionDirs()) {
|
|
177
|
+
try { await readdir(sessionsDir); availableHomes.add(dirname(sessionsDir)); } catch { continue; }
|
|
178
|
+
const before = out.length;
|
|
179
|
+
let dayDirs = 0;
|
|
180
|
+
await walkRolloutDays((dir, files) => {
|
|
181
|
+
const into = dayDirs < 2 ? out : older;
|
|
182
|
+
for (const f of files) if (f.endsWith(".jsonl")) into.push(join(dir, f));
|
|
183
|
+
if (++dayDirs >= 2 && !all) return STOP;
|
|
184
|
+
}, { sessionsDir });
|
|
185
|
+
if (out.length > before) sweepHomes.add(dirname(sessionsDir));
|
|
186
|
+
}
|
|
187
|
+
return { files: out, older, availableHomes, sweepHomes };
|
|
179
188
|
}
|
|
180
189
|
|
|
181
190
|
/** Which of the two ways a rollout can fail to say whose it is has been printed
|
|
@@ -445,9 +454,9 @@ function emitCodexLines(state, consume, persist) {
|
|
|
445
454
|
* or a session that sat idle past the window — is read from where this deck
|
|
446
455
|
* stopped, joined late. The listing takes the entry back if the path is listed.
|
|
447
456
|
*/
|
|
448
|
-
function sweepCodexCursors(now) {
|
|
457
|
+
function sweepCodexCursors(now, availableHomes) {
|
|
449
458
|
for (const [p, s] of codexFileState) {
|
|
450
|
-
if (now - (s.seenAt ?? 0) > CODEX_STATE_TTL_MS) {
|
|
459
|
+
if (availableHomes.has(rolloutHome(p)) && now - (s.seenAt ?? 0) > CODEX_STATE_TTL_MS) {
|
|
451
460
|
codexFileState.delete(p);
|
|
452
461
|
codexOlderRollouts.set(p, s.offset);
|
|
453
462
|
}
|
|
@@ -472,15 +481,21 @@ function catalogOlderRollouts(older) {
|
|
|
472
481
|
* for each that has grown since its last look, opened joined late from the
|
|
473
482
|
* size it had then. See codexOlderRollouts.
|
|
474
483
|
*/
|
|
475
|
-
async function openGrownOlderRollouts(now) {
|
|
484
|
+
async function openGrownOlderRollouts(now, availableHomes) {
|
|
476
485
|
const opened = [];
|
|
477
486
|
const due = Math.min(CODEX_OLDER_STATS_PER_TICK, codexOlderRollouts.size);
|
|
478
487
|
for (let i = 0; i < due; i++) {
|
|
479
488
|
const path = nextOlderRollout();
|
|
480
489
|
if (path == null) break;
|
|
490
|
+
if (!availableHomes.has(rolloutHome(path))) continue;
|
|
481
491
|
const was = codexOlderRollouts.get(path);
|
|
482
492
|
let st;
|
|
483
|
-
try { st = await stat(path); } catch
|
|
493
|
+
try { st = await stat(path); } catch (error) {
|
|
494
|
+
if (error.code === "ENOENT") {
|
|
495
|
+
try { await readdir(dirname(path)); codexOlderRollouts.delete(path); } catch { /* unavailable subtree: retain offset */ }
|
|
496
|
+
}
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
484
499
|
if (was == null || st.size <= was) { codexOlderRollouts.set(path, st.size); continue; }
|
|
485
500
|
const header = await readCodexHeader(path);
|
|
486
501
|
if (!header || !header.sid) continue; // the size it grew from is kept; next round
|
|
@@ -535,7 +550,7 @@ async function scanRollouts(firstRun) {
|
|
|
535
550
|
// `null` rather than 0 for "never", so a clock that starts near the epoch,
|
|
536
551
|
// or a faked one, cannot make boot look recent.
|
|
537
552
|
const walkAll = codexOlderWalkedAt == null || Math.abs(now - codexOlderWalkedAt) >= CODEX_STATE_TTL_MS;
|
|
538
|
-
const { files: recentFiles, older } = await listRecentCodexRollouts(walkAll);
|
|
553
|
+
const { files: recentFiles, older, availableHomes, sweepHomes } = await listRecentCodexRollouts(walkAll);
|
|
539
554
|
const recent = new Set(recentFiles);
|
|
540
555
|
const files = recoverAtBoot ? [...recentFiles, ...older] : recentFiles;
|
|
541
556
|
if (walkAll) { codexOlderWalkedAt = now; catalogOlderRollouts(older); }
|
|
@@ -575,7 +590,7 @@ async function scanRollouts(firstRun) {
|
|
|
575
590
|
state.mtimeMs = st.mtimeMs;
|
|
576
591
|
due.push({ path, st, state });
|
|
577
592
|
}
|
|
578
|
-
due.push(...await openGrownOlderRollouts(now));
|
|
593
|
+
due.push(...await openGrownOlderRollouts(now, availableHomes));
|
|
579
594
|
|
|
580
595
|
// Retry an unstable prefix only after its file changes. The live cursor
|
|
581
596
|
// stays behind an incomplete line and never replays skipped tool history.
|
|
@@ -673,7 +688,8 @@ async function scanRollouts(firstRun) {
|
|
|
673
688
|
// lines, and the answer must be the same for every event in it — a root
|
|
674
689
|
// written by one deck and its tool calls by another is worse than either.
|
|
675
690
|
const persist = !eventLogPath()
|
|
676
|
-
|| writesCodexLog({ decks: await liveDecks(), pid: process.pid, cwd: state.cwd
|
|
691
|
+
|| writesCodexLog({ decks: await liveDecks(), pid: process.pid, cwd: state.cwd,
|
|
692
|
+
codexHome: canonicalLogPath(rolloutHome(path)), });
|
|
677
693
|
|
|
678
694
|
emitCodexLines(state, consume, persist);
|
|
679
695
|
|
|
@@ -689,7 +705,7 @@ async function scanRollouts(firstRun) {
|
|
|
689
705
|
// lines, and a batch whose roots and tool calls went to one deck's log
|
|
690
706
|
// while its memory list went to every deck's is the split the election
|
|
691
707
|
// exists to prevent (#447).
|
|
692
|
-
if (state.rootOpened) maybeResolveCodexMemory(state.sid, state.cwd, persist);
|
|
708
|
+
if (state.rootOpened) maybeResolveCodexMemory(state.sid, state.cwd, persist, rolloutHome(path));
|
|
693
709
|
}
|
|
694
710
|
|
|
695
711
|
// AN EMPTY LISTING IS NOT EVIDENCE THAT ANYTHING WENT AWAY, and skipping
|
|
@@ -706,7 +722,7 @@ async function scanRollouts(firstRun) {
|
|
|
706
722
|
// Nothing is lost by waiting: an empty listing means no file can be read
|
|
707
723
|
// this tick anyway, and a tree that really is empty stays empty, so the
|
|
708
724
|
// first tick that lists anything at all sweeps what is genuinely stale.
|
|
709
|
-
if (files.length) sweepCodexCursors(now);
|
|
725
|
+
if (files.length) sweepCodexCursors(now, sweepHomes);
|
|
710
726
|
} catch {
|
|
711
727
|
/* swallow — watcher must never crash the server */
|
|
712
728
|
}
|
|
@@ -136,7 +136,7 @@ async function claudePlan(env) {
|
|
|
136
136
|
/** The Codex plan, never refreshing a token to learn it. */
|
|
137
137
|
async function codexPlan() {
|
|
138
138
|
const { getCodexAuth } = await import("./codex-auth.mjs");
|
|
139
|
-
const auth = await getCodexAuth({ allowRefresh: false });
|
|
139
|
+
const auth = await getCodexAuth({ allowRefresh: false, selectedReadOnly: true, enableNative: true });
|
|
140
140
|
if (auth?.apiKeyMode) return "api";
|
|
141
141
|
return auth?.ok ? codexPlanToken(auth.planType) : undefined;
|
|
142
142
|
}
|
package/src/server/discovery.mjs
CHANGED
|
@@ -15,6 +15,8 @@ import { join } from "node:path";
|
|
|
15
15
|
import { claudeConfigDir } from "./claude-dir.mjs";
|
|
16
16
|
// Under the name installer.mjs gives it, which is the one the bodies below use.
|
|
17
17
|
import { CODEX_HOME as CODEX_DIR } from "./codex-dir.mjs";
|
|
18
|
+
import { configuredCodexHomes } from "./codex-profiles.mjs";
|
|
19
|
+
import { readCodexSelection } from "./codex-selection.mjs";
|
|
18
20
|
import { canonicalLogPath } from "./log-election.mjs";
|
|
19
21
|
import { stripBom, writeFileAtomic } from "./atomic-write.mjs";
|
|
20
22
|
|
|
@@ -53,6 +55,15 @@ export function codexHomeField(codex) {
|
|
|
53
55
|
return codex !== false ? canonicalLogPath(CODEX_DIR) : null;
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
/** Canonical monitored roots, shared by registration and startup matching. */
|
|
59
|
+
export async function codexHomesField(codex) {
|
|
60
|
+
if (codex === false) return [];
|
|
61
|
+
let homes;
|
|
62
|
+
try { homes = (await readCodexSelection()).homes; }
|
|
63
|
+
catch { homes = configuredCodexHomes(); } // still serve recovery UI; never used for auth
|
|
64
|
+
return [...new Set(homes.map(canonicalLogPath))].sort();
|
|
65
|
+
}
|
|
66
|
+
|
|
56
67
|
// Every deck's token lives in this directory, and writeFileAtomic's temp file is
|
|
57
68
|
// created beside its target with whatever the umask allows — 0644 on most
|
|
58
69
|
// machines — so for the moment before the rename the token would sit in a
|
|
@@ -125,6 +136,7 @@ export async function writeDiscovery({ port, workspace, token, persist = null, c
|
|
|
125
136
|
// codex-dir.mjs goes on reading and writing through the spelling the user
|
|
126
137
|
// chose, which it has to for a symlinked home (see codexHome() there).
|
|
127
138
|
codexHome: codexHomeField(codex),
|
|
139
|
+
codexHomes: await codexHomesField(codex),
|
|
128
140
|
// Does this deck run Browser Watch? The watch elects a single writer among
|
|
129
141
|
// the decks on a machine, and it elected on port alone — so an older ccdeck
|
|
130
142
|
// that predates the feature won the election by having the lower port and
|
|
@@ -209,6 +221,7 @@ export async function ensureDiscovery({ port, workspace, token, persist = null,
|
|
|
209
221
|
&& (d.persist ?? null) === persistField(persist)
|
|
210
222
|
&& d.codex === (codex !== false)
|
|
211
223
|
&& d.codexHome === codexHomeField(codex)
|
|
224
|
+
&& JSON.stringify(d.codexHomes) === JSON.stringify(await codexHomesField(codex))
|
|
212
225
|
&& d.claude === (claude !== false)
|
|
213
226
|
&& (d.version ?? "") === (typeof version === "string" ? version : "")
|
|
214
227
|
&& (d.parent ?? null) === (Number.isInteger(parent) ? parent : null)) {
|
package/src/server/index.mjs
CHANGED
|
@@ -164,7 +164,7 @@ export { sendInternalError };
|
|
|
164
164
|
// The accounts surface's routes — see account-routes.mjs. The boot wires the
|
|
165
165
|
// stale-copy repair and starts auto-switch through the same module.
|
|
166
166
|
import { handleStopContinue, handleStopContinueRead } from "./stop-continue.mjs";
|
|
167
|
-
import { cswapAutoModule, getProjectRollup, handleAccountLoginState, handleAccountProjects, handleClaudeAccountAdmin, handleClaudeAccountSwitch, handleClaudeAccounts, handleCswapAuto, handleCswapAutoAction, wireAccountOrigins, wireStaleCopyRepair } from "./account-routes.mjs";
|
|
167
|
+
import { cswapAutoModule, getProjectRollup, handleAccountLoginState, handleAccountProjects, handleClaudeAccountAdmin, handleClaudeAccountSwitch, handleClaudeAccounts, handleCodexProfiles, handleCodexProfileQuota, handleCodexProfileLaunch, handleCodexProfileMutation, handleCodexProfileLogin, handleCodexProfileLoginFlow, handleCodexTerminalCommand, handleCodexAuto, handleCodexAutoAction, handleCswapAuto, handleCswapAutoAction, wireAccountOrigins, wireStaleCopyRepair } from "./account-routes.mjs";
|
|
168
168
|
// Browser Watch's three routes — see browser-watch-routes.mjs.
|
|
169
169
|
import { handleBrowserWatch, handleBrowserWatchDismiss, handleBrowserWatchSettings } from "./browser-watch-routes.mjs";
|
|
170
170
|
// The music routes, every one behind AGENTS_DECK_NO_MUSIC — see music-routes.mjs.
|
|
@@ -401,6 +401,21 @@ export async function startServer({ port = 4317, host = "127.0.0.1", persist = n
|
|
|
401
401
|
if (req.method === "POST" && url.pathname === "/api/browser-watch/dismiss") return guard(handleBrowserWatchDismiss(req, res), res);
|
|
402
402
|
if (req.method === "GET" && url.pathname === "/api/account-projects") return guard(handleAccountProjects(req, res), res);
|
|
403
403
|
if (req.method === "GET" && url.pathname === "/api/claude-accounts") return guard(handleClaudeAccounts(req, res), res);
|
|
404
|
+
if (req.method === "GET" && url.pathname === "/api/codex-profiles") return guard(handleCodexProfiles(req, res), res);
|
|
405
|
+
if (req.method === "GET" && url.pathname === "/api/codex-profile-quota") return guard(handleCodexProfileQuota(req, res), res);
|
|
406
|
+
if (req.method === "GET" && url.pathname === "/api/codex-profile-launch") return guard(handleCodexProfileLaunch(req, res), res);
|
|
407
|
+
if (req.method === "GET" && url.pathname === "/api/codex-auto") return guard(handleCodexAuto(req, res), res);
|
|
408
|
+
if (req.method === "POST" && url.pathname === "/api/codex-auto") return guard(handleCodexAutoAction(req, res), res);
|
|
409
|
+
if (req.method === "POST" && url.pathname === "/api/codex-profile-select") return guard(handleCodexProfileMutation(req, res, "select"), res);
|
|
410
|
+
if (req.method === "POST" && url.pathname === "/api/codex-profile-add") return guard(handleCodexProfileMutation(req, res, "add"), res);
|
|
411
|
+
if (req.method === "POST" && url.pathname === "/api/codex-profile-remove") return guard(handleCodexProfileMutation(req, res, "remove"), res);
|
|
412
|
+
if (req.method === "POST" && url.pathname === "/api/codex-profile-rename") return guard(handleCodexProfileMutation(req, res, "rename"), res);
|
|
413
|
+
if (req.method === "POST" && url.pathname === "/api/codex-profile-replace-login") return guard(handleCodexProfileMutation(req, res, "replace"), res);
|
|
414
|
+
if (req.method === "POST" && url.pathname === "/api/codex-profile-login-start") return guard(handleCodexProfileLoginFlow(req, res, "start"), res);
|
|
415
|
+
if (req.method === "POST" && url.pathname === "/api/codex-profile-login-cancel") return guard(handleCodexProfileLoginFlow(req, res, "cancel"), res);
|
|
416
|
+
if (req.method === "GET" && url.pathname === "/api/codex-profile-login-state") return guard(handleCodexProfileLoginFlow(req, res, "state"), res);
|
|
417
|
+
if (req.method === "GET" && url.pathname === "/api/codex-profile-login") return guard(handleCodexProfileLogin(req, res), res);
|
|
418
|
+
if (req.method === "GET" && url.pathname === "/api/codex-terminal-command") return guard(handleCodexTerminalCommand(req, res), res);
|
|
404
419
|
if (req.method === "POST" && url.pathname === "/api/claude-accounts/switch") return guard(handleClaudeAccountSwitch(req, res), res);
|
|
405
420
|
if (req.method === "GET" && url.pathname === "/api/claude-accounts/login") return guard(handleAccountLoginState(req, res), res);
|
|
406
421
|
if (req.method === "POST" && url.pathname === "/api/claude-accounts/admin") return guard(handleClaudeAccountAdmin(req, res), res);
|
|
@@ -579,6 +594,9 @@ export async function startServer({ port = 4317, host = "127.0.0.1", persist = n
|
|
|
579
594
|
// being installed or upgraded underneath them (#1043) — null from every
|
|
580
595
|
// caller with nothing to wait for.
|
|
581
596
|
cswapAutoModule().then(m => m.initCswapAuto({ after: cswapQuiet })).catch(() => {});
|
|
597
|
+
// Codex's Auto-switch, on the deck's own loop. A settings read a minute
|
|
598
|
+
// unless somebody turned it on (codex-auto.mjs).
|
|
599
|
+
import("./codex-auto.mjs").then(m => m.startCodexAutoLoop()).catch(() => {});
|
|
582
600
|
// The account notifications' own quota reads, for the providers this deck
|
|
583
601
|
// watches. Idle — a check of two switches every couple of minutes — unless
|
|
584
602
|
// the threshold or the reset notification is on.
|
package/src/server/installer.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import { claudeCodeVersions, claudeConfigDir, claudeVersionAtLeast } from "./cla
|
|
|
14
14
|
// The first Claude Code that knows StopFailure — see stop-failure.mjs.
|
|
15
15
|
import { STOP_FAILURE, STOP_FAILURE_SINCE } from "./stop-failure.mjs";
|
|
16
16
|
import { CODEX_HOME } from "./codex-dir.mjs";
|
|
17
|
+
import { configuredCodexHomes, readCodexSelection } from "./codex-selection.mjs";
|
|
17
18
|
import { shellQuoteArg } from "./exec.mjs";
|
|
18
19
|
// The read-before-rewrite and the atomic replace every settings writer goes
|
|
19
20
|
// through — see atomic-write.mjs.
|
|
@@ -689,10 +690,15 @@ export async function uninstallHooks({ provider = "claude", beforeWrite = null }
|
|
|
689
690
|
return { ok: true, changed, provider, settingsPath: cfg.settingsPath };
|
|
690
691
|
}
|
|
691
692
|
|
|
692
|
-
/**
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
693
|
+
/** Whether an available configured or persisted Codex home can be watched. */
|
|
694
|
+
export async function hasCodexInstalled(options = {}) {
|
|
695
|
+
try {
|
|
696
|
+
const selection = await readCodexSelection(options);
|
|
697
|
+
return selection.profiles.some(profile => profile.available);
|
|
698
|
+
} catch {
|
|
699
|
+
// Invalid selection metadata must not crash startup or invent managed homes.
|
|
700
|
+
return configuredCodexHomes(options.env, options.home, options.platform).some(directory => existsSync(directory));
|
|
701
|
+
}
|
|
696
702
|
}
|
|
697
703
|
|
|
698
704
|
/**
|
|
@@ -759,4 +765,4 @@ export { AGENT_DAG_DIR, CLAUDE_DIR, CODEX_DIR };
|
|
|
759
765
|
// This deck's discovery record, which moved to discovery.mjs. Exported from this
|
|
760
766
|
// file before they moved, and still: bin/deck.js and the CLI import them from
|
|
761
767
|
// here.
|
|
762
|
-
export { codexHomeField, discoveryPath, ensureDiscovery, keepDiscovery, removeDiscovery, writeDiscovery } from "./discovery.mjs";
|
|
768
|
+
export { codexHomesField, codexHomeField, discoveryPath, ensureDiscovery, keepDiscovery, removeDiscovery, writeDiscovery } from "./discovery.mjs";
|
|
@@ -213,7 +213,7 @@ export function sameCodexTree(a, b, platform = process.platform) {
|
|
|
213
213
|
* challenge, and is simply looking somewhere else. The same deck launched with
|
|
214
214
|
* a stale CODEX_HOME is the duller version of it.
|
|
215
215
|
*/
|
|
216
|
-
export function writesCodexLog({ decks, pid, cwd, platform = process.platform }) {
|
|
216
|
+
export function writesCodexLog({ decks, pid, cwd, codexHome = null, platform = process.platform }) {
|
|
217
217
|
const live = Array.isArray(decks) ? decks : [];
|
|
218
218
|
const self = live.find(d => d && d.pid === pid) ?? null;
|
|
219
219
|
// No record of our own on disk — the window before the first heartbeat writes
|
|
@@ -224,12 +224,41 @@ export function writesCodexLog({ decks, pid, cwd, platform = process.platform })
|
|
|
224
224
|
if (!self || typeof self.persist !== "string" || self.persist === "") return true;
|
|
225
225
|
|
|
226
226
|
const group = [self];
|
|
227
|
+
const losingLegacyReaders = new Set();
|
|
227
228
|
for (const d of live) {
|
|
228
229
|
if (!d || d.pid === self.pid) continue;
|
|
229
230
|
if (d.codex === false) continue;
|
|
230
|
-
if (
|
|
231
|
+
if (codexHome) {
|
|
232
|
+
const roots = Array.isArray(d.codexHomes) ? d.codexHomes : [d.codexHome];
|
|
233
|
+
if (!roots.some(root => sameCodexTree(root, codexHome, platform))) continue;
|
|
234
|
+
} else if (!sameCodexTree(self.codexHome, d.codexHome, platform)) continue;
|
|
231
235
|
if (!codexCwdInWorkspace(cwd, d.workspace ?? "", platform)) continue;
|
|
232
236
|
group.push(d);
|
|
233
237
|
}
|
|
234
|
-
|
|
238
|
+
if (codexHome) {
|
|
239
|
+
// Legacy decks only compare primary homes. Prefer those readers for this
|
|
240
|
+
// log so an alternate-home reader cannot elect itself beside a legacy writer.
|
|
241
|
+
const sharing = group.filter(d => typeof d.persist === "string" && d.persist !== ""
|
|
242
|
+
&& sameCodexTree(d.persist, self.persist, platform));
|
|
243
|
+
// Legacy readers elect using primary homes, not monitored home sets. Ask
|
|
244
|
+
// which of them actually wins that protocol before electing ourselves for
|
|
245
|
+
// an alternate home. A wildcard alone is not an owner: it may lose to us,
|
|
246
|
+
// while a known primary reader can win after excluding our primary home.
|
|
247
|
+
for (const reader of sharing) {
|
|
248
|
+
if (reader.pid === self.pid || Array.isArray(reader.codexHomes)) continue;
|
|
249
|
+
const legacyGroup = live.filter(d => d && (d.pid === reader.pid || (
|
|
250
|
+
d.codex !== false && sameCodexTree(reader.codexHome, d.codexHome, platform)
|
|
251
|
+
&& codexCwdInWorkspace(cwd, d.workspace ?? "", platform)
|
|
252
|
+
)));
|
|
253
|
+
if (electWriters(legacyGroup, platform).has(reader)) return false;
|
|
254
|
+
losingLegacyReaders.add(reader);
|
|
255
|
+
}
|
|
256
|
+
// A legacy reader that lost its own election cannot be preferred here.
|
|
257
|
+
const primary = sharing.filter(d => (d === self || Array.isArray(d.codexHomes))
|
|
258
|
+
&& typeof d.codexHome === "string" && d.codexHome !== ""
|
|
259
|
+
&& sameCodexTree(d.codexHome, codexHome, platform));
|
|
260
|
+
if (primary.length) return electWriters(primary, platform).has(self);
|
|
261
|
+
}
|
|
262
|
+
// A reader that stands down under its own protocol cannot own the fallback.
|
|
263
|
+
return electWriters(group.filter(reader => !losingLegacyReaders.has(reader)), platform).has(self);
|
|
235
264
|
}
|
|
@@ -399,7 +399,7 @@ export function scopeEnv(env = process.env) {
|
|
|
399
399
|
* ones that are set, for the reason scopeEnv gives.
|
|
400
400
|
*/
|
|
401
401
|
export const SETTING_VARS = Object.freeze([
|
|
402
|
-
"AGENT_DAG_PORT",
|
|
402
|
+
"AGENT_DAG_PORT", "CCDECK_CODEX_HOMES",
|
|
403
403
|
"AGENTS_DECK_NO_INSTALL", "AGENTS_DECK_NO_DOWNLOAD", "AGENTS_DECK_NO_UPDATE_CHECK", "AGENTS_DECK_NO_STATUS",
|
|
404
404
|
"AGENTS_DECK_NO_FRESHEN", "AGENTS_DECK_NO_NOTIFY", "AGENTS_DECK_NO_LAN", "AGENTS_DECK_NO_REPORTS",
|
|
405
405
|
"AGENTS_DECK_CSWAP", "AGENTS_DECK_CLAUDE", "AGENTS_DECK_CCUSAGE", "CLAUDE_SWAP_BACKUP", "AGENTS_DECK_LHM_PORT",
|
|
@@ -151,13 +151,13 @@ export async function scanClaudeMdFiles(cwd) {
|
|
|
151
151
|
* worth pinning directly, rather than through a watcher, a temp home and a
|
|
152
152
|
* 1.5s poll.
|
|
153
153
|
*/
|
|
154
|
-
export async function scanAgentsMdFiles(cwd) {
|
|
154
|
+
export async function scanAgentsMdFiles(cwd, codexHome = CODEX_HOME) {
|
|
155
155
|
if (!cwd || typeof cwd !== "string") return [];
|
|
156
156
|
// Codex has no `.codex/AGENTS.md` per-directory convention to mirror CC's
|
|
157
157
|
// `.claude/CLAUDE.md`, so the per-level list is the single filename.
|
|
158
158
|
const paths = memoryWalkPaths(cwd, ["AGENTS.md"]);
|
|
159
159
|
// The user-global instructions file, which Codex loads for every session
|
|
160
160
|
// whatever the cwd — the counterpart of ~/.claude/CLAUDE.md.
|
|
161
|
-
paths.push(join(
|
|
161
|
+
paths.push(join(codexHome, "AGENTS.md"));
|
|
162
162
|
return collectMemoryFiles(paths);
|
|
163
163
|
}
|
|
@@ -443,6 +443,15 @@ export const GUARDED_READS = new Set([
|
|
|
443
443
|
// standing question's own words, which is the ring's secret in fewer bytes.
|
|
444
444
|
"/api/sessions",
|
|
445
445
|
"/api/claude-accounts",
|
|
446
|
+
// Reveals the local machine's Codex profile roster, even though paths and
|
|
447
|
+
// credentials are deliberately omitted from the response.
|
|
448
|
+
"/api/codex-profiles",
|
|
449
|
+
"/api/codex-profile-quota",
|
|
450
|
+
"/api/codex-auto",
|
|
451
|
+
"/api/codex-profile-launch",
|
|
452
|
+
"/api/codex-profile-login",
|
|
453
|
+
"/api/codex-profile-login-state",
|
|
454
|
+
"/api/codex-terminal-command",
|
|
446
455
|
"/api/claude-accounts/login",
|
|
447
456
|
"/api/browser-watch",
|
|
448
457
|
"/api/lan",
|
|
@@ -102,13 +102,24 @@ export function deckRegistryDir(env = process.env, home = undefined) {
|
|
|
102
102
|
* that asks on behalf of a start names its tree: the start itself, and
|
|
103
103
|
* `--status` marking the deck a bare start would open (#1134).
|
|
104
104
|
*/
|
|
105
|
+
function sameMonitoredHomes(record, want) {
|
|
106
|
+
if (!Array.isArray(want.codexHomes)) return true;
|
|
107
|
+
const roots = Array.isArray(record.codexHomes) ? record.codexHomes
|
|
108
|
+
: typeof record.codexHome === "string" ? [record.codexHome] : null;
|
|
109
|
+
if (roots === null) return want.codexHomes.length <= 1;
|
|
110
|
+
const actual = [...new Set(roots)];
|
|
111
|
+
const expected = [...new Set(want.codexHomes)];
|
|
112
|
+
return actual.length === expected.length && expected.every(home => actual.some(root => sameCodexTree(root, home)));
|
|
113
|
+
}
|
|
114
|
+
|
|
105
115
|
export function sameShape(record, want = {}) {
|
|
106
116
|
if (!record) return false;
|
|
107
117
|
return (record.workspace ?? "") === (want.workspace ?? "")
|
|
108
118
|
&& (record.persist ?? null) === (want.persist ?? null)
|
|
109
119
|
&& record.codex === (want.codex !== false)
|
|
110
120
|
&& record.claude === (want.claude !== false)
|
|
111
|
-
&& sameCodexTree(record.codexHome, want.codexHome)
|
|
121
|
+
&& sameCodexTree(record.codexHome, want.codexHome)
|
|
122
|
+
&& sameMonitoredHomes(record, want);
|
|
112
123
|
}
|
|
113
124
|
|
|
114
125
|
/**
|
|
@@ -644,9 +644,9 @@ const codexMemoryReads = sessionReadGate(CONTEXT_READ_THROTTLE_MS);
|
|
|
644
644
|
* discovery record: a line written twice is recoverable, a deck that quietly
|
|
645
645
|
* records nothing is not.
|
|
646
646
|
*/
|
|
647
|
-
function maybeResolveCodexMemory(sid, cwd, persist) {
|
|
647
|
+
function maybeResolveCodexMemory(sid, cwd, persist, codexHome) {
|
|
648
648
|
if (!sid || !cwd) return;
|
|
649
|
-
codexMemoryReads.run(sid, () => scanAgentsMdFiles(cwd)
|
|
649
|
+
codexMemoryReads.run(sid, () => scanAgentsMdFiles(cwd, codexHome)
|
|
650
650
|
.then(memoryFiles => {
|
|
651
651
|
// Nothing found is not a fact worth an event: the reducer merges a
|
|
652
652
|
// ContextObserved into whatever the session already had, and an empty list
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Append-only, local metadata. Never stores raw command arguments or tool outputs.
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { appendFile, mkdir, readFile, readdir, stat, unlink } from 'node:fs/promises';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
4
5
|
import { join } from 'node:path';
|
|
5
6
|
import { Worker } from 'node:worker_threads';
|
|
6
7
|
import { deckDataDir } from './deck-home.mjs';
|
|
@@ -183,9 +184,22 @@ export function createToolAudit({ dir, now = Date.now, runReport = workerReport
|
|
|
183
184
|
async close() { await enqueue(flush); },
|
|
184
185
|
};
|
|
185
186
|
}
|
|
186
|
-
|
|
187
|
+
/** A worker cannot start while the process's working directory is gone: Node asks
|
|
188
|
+
* for it while it sets the worker up, and the folder the deck was started from
|
|
189
|
+
* can be deleted at any time after (a temporary or build folder, a removed
|
|
190
|
+
* project). The report then failed with `ENOENT … uv_cwd` for as long as the
|
|
191
|
+
* deck ran. Nothing here depends on the directory, so a missing one is replaced
|
|
192
|
+
* by the home directory, which every later worker, spawn and relative path then
|
|
193
|
+
* starts from. */
|
|
194
|
+
export function ensureUsableCwd() {
|
|
195
|
+
try { process.cwd(); return; } catch { /* gone: move out of it */ }
|
|
196
|
+
try { process.chdir(homedir()); } catch { /* a worker may still start; its own error says so */ }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function workerReport(input, signal) {
|
|
187
200
|
return new Promise((resolve, reject) => {
|
|
188
201
|
if (signal?.aborted) return reject(new Error('Report cancelled'));
|
|
202
|
+
ensureUsableCwd();
|
|
189
203
|
// Serialize the already-loaded function so self-update cannot mix builds.
|
|
190
204
|
const build = input.query.view === 'skills' ? buildSkillReport : buildToolAuditReport;
|
|
191
205
|
const code = `const { parentPort, workerData } = require('node:worker_threads'); (${build.toString()})(workerData, { createReadStream: require('node:fs').createReadStream, createInterface: require('node:readline').createInterface }).then(result => parentPort.postMessage(result));`;
|
|
@@ -54,7 +54,7 @@ export async function handleCodexQuota(req, res) {
|
|
|
54
54
|
);
|
|
55
55
|
const url = new URL(req.url, "http://localhost");
|
|
56
56
|
const force = url.searchParams.get("refresh") === "1";
|
|
57
|
-
const quota = await fetchCodexQuota({ force });
|
|
57
|
+
const quota = await fetchCodexQuota({ force, enableNative: true });
|
|
58
58
|
send(res, 200, quota);
|
|
59
59
|
}
|
|
60
60
|
|