agent-dag 1.35.3 → 1.35.4
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/dist/web/assets/{index-DkpFbk1G.js → index-Z6DVMogL.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/src/server/codex-auth.mjs +11 -3
- package/src/server/codex-dir.mjs +171 -0
- package/src/server/codex-quota.mjs +5 -2
- package/src/server/codex-usage.mjs +24 -31
- package/src/server/index.mjs +28 -54
- package/src/server/installer.mjs +6 -5
package/dist/web/index.html
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
document.documentElement.setAttribute("data-theme", stored === "light" ? "light" : "dark");
|
|
41
41
|
})();
|
|
42
42
|
</script>
|
|
43
|
-
<script type="module" crossorigin src="/assets/index-
|
|
43
|
+
<script type="module" crossorigin src="/assets/index-Z6DVMogL.js"></script>
|
|
44
44
|
<link rel="stylesheet" crossorigin href="/assets/index-FKxgHN0p.css">
|
|
45
45
|
</head>
|
|
46
46
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-dag",
|
|
3
|
-
"version": "1.35.
|
|
3
|
+
"version": "1.35.4",
|
|
4
4
|
"description": "Live deck of Claude Code and Codex agents — watch parallel subagents fork, call tools, and return on one calm canvas. Also available as npx ccdeck and npx agent-dag.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -14,12 +14,20 @@
|
|
|
14
14
|
// a rejected promise from a background poll would take the server down.
|
|
15
15
|
import { readFile, chmod, unlink, realpath } from "node:fs/promises";
|
|
16
16
|
import { join } from "node:path";
|
|
17
|
-
import {
|
|
17
|
+
import { CODEX_HOME } from "./codex-dir.mjs";
|
|
18
18
|
import { createTemp, renameWithRetry } from "./installer.mjs";
|
|
19
19
|
import { PRODUCT } from "./brand.mjs";
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// This file used to resolve CODEX_HOME itself, as `process.env.CODEX_HOME ??
|
|
22
|
+
// join(homedir(), ".codex")`. `??` falls back on null and undefined only, so an
|
|
23
|
+
// empty CODEX_HOME — what `export CODEX_HOME=$SOME_UNSET_VAR` leaves in a
|
|
24
|
+
// profile — survived it, and join("", "auth.json") is the CWD-relative
|
|
25
|
+
// "auth.json". Of all five readers this was the expensive one to get wrong: the
|
|
26
|
+
// rotated refresh token below is single-use, so a write that lands in whatever
|
|
27
|
+
// directory the deck was started from does not lose a read, it burns the
|
|
28
|
+
// credential and costs the user a `codex login`. codex-dir.mjs owns the rule now
|
|
29
|
+
// and treats an empty value as "not set" (#375).
|
|
30
|
+
const AUTH_PATH = join(CODEX_HOME, "auth.json");
|
|
23
31
|
|
|
24
32
|
// Same client id + endpoint the Codex CLI uses (codex-rs/login/src/auth/manager.rs).
|
|
25
33
|
const CLIENT_ID = process.env.CODEX_APP_SERVER_LOGIN_CLIENT_ID ?? "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Where OpenAI Codex lives on this machine: its home directory, its rollout
|
|
2
|
+
// tree, and the walk over that tree — the Codex-side mirror of claude-dir.mjs.
|
|
3
|
+
//
|
|
4
|
+
// CODEX_HOME relocates ~/.codex wholesale, exactly as CLAUDE_CONFIG_DIR does on
|
|
5
|
+
// the Claude side, and five modules used to answer the question for themselves
|
|
6
|
+
// in three different spellings (#375):
|
|
7
|
+
//
|
|
8
|
+
// index.mjs CODEX_HOME ? resolve(CODEX_HOME) : join(homedir(), ".codex")
|
|
9
|
+
// installer.mjs the same
|
|
10
|
+
// codex-usage.mjs CODEX_HOME ? CODEX_HOME : join(homedir(), ".codex")
|
|
11
|
+
// codex-auth.mjs CODEX_HOME ?? join(homedir(), ".codex")
|
|
12
|
+
// codex-quota.mjs the same
|
|
13
|
+
//
|
|
14
|
+
// The three spellings disagree on two inputs that a shell profile produces by
|
|
15
|
+
// accident rather than by intent, and both disagreements are silent:
|
|
16
|
+
//
|
|
17
|
+
// CODEX_HOME="" — what `export CODEX_HOME=$SOME_UNSET_VAR` leaves behind.
|
|
18
|
+
// `??` only falls back on null and undefined, so the two modules spelled
|
|
19
|
+
// that way kept the empty string and then joined onto it: join("",
|
|
20
|
+
// "auth.json") is "auth.json", a CWD-RELATIVE path. codex-auth.mjs is the
|
|
21
|
+
// module that writes the rotated OpenAI refresh token back to disk, and
|
|
22
|
+
// OpenAI rotates that token single-use — so writing it to whatever
|
|
23
|
+
// directory the deck happened to be started from does not merely lose a
|
|
24
|
+
// read, it burns the credential and costs the user a `codex login`.
|
|
25
|
+
//
|
|
26
|
+
// CODEX_HOME=./relative — kept verbatim by three of the five, so the tree
|
|
27
|
+
// they read was resolved against the CWD at the moment of each readdir()
|
|
28
|
+
// rather than once at startup. Two modules therefore read a different
|
|
29
|
+
// directory than the other three whenever the deck was started from
|
|
30
|
+
// anywhere but the parent of that relative path.
|
|
31
|
+
//
|
|
32
|
+
// This module is the single answer to all of it, and every reader now imports
|
|
33
|
+
// it. The rule is the `resolve()` + truthiness form index.mjs and installer.mjs
|
|
34
|
+
// already used, because it is the one the installer writes against and the one
|
|
35
|
+
// that treats an empty value as "not set" — see codexHome() for why that is the
|
|
36
|
+
// right way round rather than merely the majority.
|
|
37
|
+
import { readdir } from "node:fs/promises";
|
|
38
|
+
import { homedir } from "node:os";
|
|
39
|
+
import { join, posix as posixPath, win32 as winPath } from "node:path";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Absolute path of the Codex home directory: $CODEX_HOME or ~/.codex.
|
|
43
|
+
*
|
|
44
|
+
* WHY AN EMPTY VALUE FALLS BACK. An empty environment variable is not a path.
|
|
45
|
+
* It is what a shell leaves behind when the variable it was assigned from does
|
|
46
|
+
* not exist, and treating it as "the current directory" turns a typo in a
|
|
47
|
+
* profile into a deck that reads and WRITES Codex state in whatever directory
|
|
48
|
+
* it was launched from. Falling back to ~/.codex is the only reading that can
|
|
49
|
+
* be right by accident; there is no user who means "put my Codex credentials in
|
|
50
|
+
* $PWD" and spells it by leaving the variable empty.
|
|
51
|
+
*
|
|
52
|
+
* WHY IT IS TRIMMED. Same argument one step further: `CODEX_HOME=" "` is the
|
|
53
|
+
* same accident with a stray space in the profile line, and claudeConfigDir()
|
|
54
|
+
* has trimmed for exactly this reason since it was written. Trimming only ever
|
|
55
|
+
* removes leading and trailing whitespace, so a real path that CONTAINS spaces
|
|
56
|
+
* — `/Users/me/Library/Application Support/codex` — is untouched, which is the
|
|
57
|
+
* case worth protecting on macOS and Windows both.
|
|
58
|
+
*
|
|
59
|
+
* WHY resolve() AND NOT realpath(). resolve() makes a relative value absolute
|
|
60
|
+
* once, here, instead of leaving every later readdir() to resolve it against
|
|
61
|
+
* whatever the CWD is by then. It deliberately does NOT follow symlinks:
|
|
62
|
+
* ~/.codex is often a link into a dotfiles repo or an encrypted volume, and
|
|
63
|
+
* canonicalising it would (a) require the directory to already exist, which it
|
|
64
|
+
* does not before the first `codex login`, and (b) make the deck rename over
|
|
65
|
+
* the link's target instead of through the link — the very thing codex-auth.mjs
|
|
66
|
+
* resolves symlinks at WRITE time to avoid. A symlinked CODEX_HOME therefore
|
|
67
|
+
* stays spelled the way the user spelled it, on purpose.
|
|
68
|
+
*
|
|
69
|
+
* The environment, home directory and platform are parameters purely so this
|
|
70
|
+
* rule can be checked for a machine the author is not sitting at: the Windows
|
|
71
|
+
* answer — drive letters, backslashes, a trailing `\` — is only ever verifiable
|
|
72
|
+
* from a POSIX box if the path flavour follows the argument rather than the
|
|
73
|
+
* host, the same trick exec.mjs and claudeCliCandidates() already use. Every
|
|
74
|
+
* caller in the deck passes nothing and gets the real machine's answer.
|
|
75
|
+
*/
|
|
76
|
+
export function codexHome(env = process.env, home = homedir(), platform = process.platform) {
|
|
77
|
+
// The path flavour follows the PLATFORM ARGUMENT, not the host, so that a
|
|
78
|
+
// Windows value is normalised by Windows rules even when the check runs on a
|
|
79
|
+
// Mac. On a real machine `platform` is `process.platform`, which makes this
|
|
80
|
+
// the same `join`/`resolve` the module would have imported anyway.
|
|
81
|
+
const path = platform === "win32" ? winPath : posixPath;
|
|
82
|
+
const override = env.CODEX_HOME?.trim();
|
|
83
|
+
return override ? path.resolve(override) : path.join(home, ".codex");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Absolute path of the rollout tree: $CODEX_HOME/sessions.
|
|
88
|
+
*
|
|
89
|
+
* Codex writes one append-only JSONL file per session under
|
|
90
|
+
* sessions/YYYY/MM/DD/, and this directory is the root of every walk below. It
|
|
91
|
+
* lives here rather than being spelled `join(CODEX_HOME, "sessions")` at each
|
|
92
|
+
* of the three walkers, because that spelling was already duplicated verbatim
|
|
93
|
+
* in index.mjs and codex-usage.mjs and had no owner to drift away from.
|
|
94
|
+
*/
|
|
95
|
+
export function codexSessionsDir(env = process.env, home = homedir(), platform = process.platform) {
|
|
96
|
+
const path = platform === "win32" ? winPath : posixPath;
|
|
97
|
+
return path.join(codexHome(env, home, platform), "sessions");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The answers for THIS process, resolved once at load.
|
|
102
|
+
*
|
|
103
|
+
* Every consumer imports these constants rather than calling the functions,
|
|
104
|
+
* which is what makes it impossible for two modules to disagree: there is now a
|
|
105
|
+
* single evaluation in the whole process instead of one per importing module.
|
|
106
|
+
* The functions above stay exported because the constants cannot be re-derived
|
|
107
|
+
* for a hypothetical environment, and the rule they encode is the thing worth
|
|
108
|
+
* pinning against every shape a CODEX_HOME can take.
|
|
109
|
+
*/
|
|
110
|
+
export const CODEX_HOME = codexHome();
|
|
111
|
+
export const CODEX_SESSIONS_DIR = codexSessionsDir();
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Returned from a walkRolloutDays visitor to end the walk immediately.
|
|
115
|
+
*
|
|
116
|
+
* A symbol rather than `true` because two of the three callers build their
|
|
117
|
+
* result by pushing into an array inside the visitor, and `Array.prototype.push`
|
|
118
|
+
* returns a number — a truthy-return protocol would have made "I collected two
|
|
119
|
+
* files" indistinguishable from "stop now".
|
|
120
|
+
*/
|
|
121
|
+
export const STOP = Symbol("stop-rollout-walk");
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Walk $CODEX_HOME/sessions/YYYY/MM/DD newest-first, handing each day directory
|
|
125
|
+
* and the names inside it to `onDay(dir, files)`.
|
|
126
|
+
*
|
|
127
|
+
* Three callers walked this tree with the same four nested readdir-and-continue
|
|
128
|
+
* blocks and differed only in the last few lines: find the file carrying a given
|
|
129
|
+
* session id (index.mjs), collect everything in the newest two day directories
|
|
130
|
+
* (index.mjs again, for the watcher), and collect everything whose filename
|
|
131
|
+
* timestamp falls inside a rolling window (codex-usage.mjs). The walk is the
|
|
132
|
+
* part that has to agree — a deck that tails one set of files and reports usage
|
|
133
|
+
* from another is reporting on a session it is not showing.
|
|
134
|
+
*
|
|
135
|
+
* EVERY LEVEL SWALLOWS ITS OWN ERROR, which is deliberate rather than lazy. The
|
|
136
|
+
* tree is written by another process while this one reads it: a day directory
|
|
137
|
+
* can be created between the listing of its month and the listing of itself, a
|
|
138
|
+
* year directory can be a broken symlink on a restored backup, and none of that
|
|
139
|
+
* is a reason to stop reading the other 364 days. A missing sessions/ directory
|
|
140
|
+
* is not an error at all — it is simply a machine where Codex has not run yet.
|
|
141
|
+
*
|
|
142
|
+
* `onYear` exists for the one caller that can rule out a whole year without
|
|
143
|
+
* opening it. Years arrive newest-first, so returning STOP from it ends the
|
|
144
|
+
* walk rather than skipping a year, which is what the caller wants: once the
|
|
145
|
+
* years are older than the window, so is everything after them.
|
|
146
|
+
*/
|
|
147
|
+
export async function walkRolloutDays(onDay, { sessionsDir = CODEX_SESSIONS_DIR, onYear = null } = {}) {
|
|
148
|
+
let years;
|
|
149
|
+
// Only four-digit names are Codex's own. The filter also keeps a stray
|
|
150
|
+
// `.DS_Store` or a `latest` symlink from costing a readdir that would fail.
|
|
151
|
+
try { years = (await readdir(sessionsDir)).filter(d => /^\d{4}$/.test(d)).sort().reverse(); }
|
|
152
|
+
catch { return; }
|
|
153
|
+
for (const year of years) {
|
|
154
|
+
if (onYear && (await onYear(year)) === STOP) return;
|
|
155
|
+
let months;
|
|
156
|
+
try { months = (await readdir(join(sessionsDir, year))).sort().reverse(); }
|
|
157
|
+
catch { continue; }
|
|
158
|
+
for (const month of months) {
|
|
159
|
+
let days;
|
|
160
|
+
try { days = (await readdir(join(sessionsDir, year, month))).sort().reverse(); }
|
|
161
|
+
catch { continue; }
|
|
162
|
+
for (const day of days) {
|
|
163
|
+
const dir = join(sessionsDir, year, month, day);
|
|
164
|
+
let files;
|
|
165
|
+
try { files = await readdir(dir); }
|
|
166
|
+
catch { continue; }
|
|
167
|
+
if ((await onDay(dir, files)) === STOP) return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -9,11 +9,14 @@
|
|
|
9
9
|
// the UI when something was dropped instead of silently showing less.
|
|
10
10
|
import { readFile } from "node:fs/promises";
|
|
11
11
|
import { join } from "node:path";
|
|
12
|
-
import {
|
|
12
|
+
import { CODEX_HOME } from "./codex-dir.mjs";
|
|
13
13
|
import { getCodexAuth, forceCodexRefresh, isCredentialHost } from "./codex-auth.mjs";
|
|
14
14
|
import { PRODUCT } from "./brand.mjs";
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// Resolved by codex-dir.mjs rather than here. This file used to spell it
|
|
17
|
+
// `process.env.CODEX_HOME ?? join(homedir(), ".codex")`, which keeps an empty
|
|
18
|
+
// CODEX_HOME instead of falling back — and then read a CWD-relative
|
|
19
|
+
// "config.toml" for the base URL every credential below is sent to (#375).
|
|
17
20
|
const CONFIG_PATH = join(CODEX_HOME, "config.toml");
|
|
18
21
|
const DEFAULT_BASE = "https://chatgpt.com/backend-api";
|
|
19
22
|
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
// Aggregates Codex token usage from ~/.codex/sessions rollout JSONL files.
|
|
2
2
|
// Unlike Claude, Codex has no CLI quota command — we derive usage from the
|
|
3
3
|
// actual session logs for 5h and 7d rolling windows.
|
|
4
|
-
import {
|
|
4
|
+
import { open, stat } from "node:fs/promises";
|
|
5
5
|
import { join } from "node:path";
|
|
6
|
-
import { homedir } from "node:os";
|
|
7
6
|
import { StringDecoder } from "node:string_decoder";
|
|
7
|
+
import { STOP, walkRolloutDays } from "./codex-dir.mjs";
|
|
8
8
|
import { PRODUCT } from "./brand.mjs";
|
|
9
9
|
|
|
10
|
-
const CODEX_HOME = process.env.CODEX_HOME
|
|
11
|
-
? process.env.CODEX_HOME
|
|
12
|
-
: join(homedir(), ".codex");
|
|
13
|
-
const CODEX_SESSIONS_DIR = join(CODEX_HOME, "sessions");
|
|
14
|
-
|
|
15
10
|
// Cache results for 60s (lighter than Claude quota — reads more files)
|
|
16
11
|
let _cache = null;
|
|
17
12
|
let _cacheAt = 0;
|
|
@@ -168,35 +163,33 @@ function parseRolloutTime(filename) {
|
|
|
168
163
|
}
|
|
169
164
|
|
|
170
165
|
// List rollout files whose start times fall within the given window.
|
|
166
|
+
//
|
|
167
|
+
// The walk over $CODEX_HOME/sessions is shared with the two entry points in
|
|
168
|
+
// index.mjs (codex-dir.mjs) rather than repeated here, so the files this counts
|
|
169
|
+
// usage from are exactly the files the watcher tails. They used to be two
|
|
170
|
+
// verbatim copies of the same four nested readdirs over two verbatim copies of
|
|
171
|
+
// the same CODEX_SESSIONS_DIR — which is how one of them came to resolve a
|
|
172
|
+
// relative CODEX_HOME differently from the other (#375).
|
|
171
173
|
async function listRolloutFiles(sinceMs) {
|
|
172
174
|
const out = [];
|
|
173
|
-
let years;
|
|
174
|
-
try { years = (await readdir(CODEX_SESSIONS_DIR)).filter(d => /^\d{4}$/.test(d)).sort().reverse(); }
|
|
175
|
-
catch { return out; }
|
|
176
|
-
|
|
177
175
|
const nowMs = Date.now();
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
for (const f of files) {
|
|
191
|
-
if (!f.endsWith(".jsonl")) continue;
|
|
192
|
-
const t = parseRolloutTime(f);
|
|
193
|
-
if (t != null && nowMs - t <= sinceMs) {
|
|
194
|
-
out.push({ path: join(dir, f), startMs: t });
|
|
195
|
-
}
|
|
176
|
+
// Years arrive newest-first, so the first one that cannot hold a file in the
|
|
177
|
+
// window ends the walk: everything after it is older still. The extra day of
|
|
178
|
+
// slack covers a session that started just before the window and a filename
|
|
179
|
+
// timestamp that is UTC while the year directory is local time.
|
|
180
|
+
const oldestYear = new Date(nowMs - sinceMs - 86400000).getFullYear();
|
|
181
|
+
await walkRolloutDays(
|
|
182
|
+
(dir, files) => {
|
|
183
|
+
for (const f of files) {
|
|
184
|
+
if (!f.endsWith(".jsonl")) continue;
|
|
185
|
+
const t = parseRolloutTime(f);
|
|
186
|
+
if (t != null && nowMs - t <= sinceMs) {
|
|
187
|
+
out.push({ path: join(dir, f), startMs: t });
|
|
196
188
|
}
|
|
197
189
|
}
|
|
198
|
-
}
|
|
199
|
-
|
|
190
|
+
},
|
|
191
|
+
{ onYear: y => (parseInt(y, 10) < oldestYear ? STOP : undefined) },
|
|
192
|
+
);
|
|
200
193
|
return out;
|
|
201
194
|
}
|
|
202
195
|
|
package/src/server/index.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { dirname } from "node:path";
|
|
|
10
10
|
import { createInterface } from "node:readline";
|
|
11
11
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
12
12
|
import { claudeConfigDir } from "./claude-dir.mjs";
|
|
13
|
+
import { CODEX_SESSIONS_DIR, STOP, walkRolloutDays } from "./codex-dir.mjs";
|
|
13
14
|
import { PRODUCT } from "./brand.mjs";
|
|
14
15
|
import { invokedName, renameNotice } from "./invoked-as.mjs";
|
|
15
16
|
import { codexCwdInWorkspace, writesCodexLog } from "./log-writer.mjs";
|
|
@@ -634,17 +635,17 @@ function maybeResolveContext(payload) {
|
|
|
634
635
|
// output_tokens, reasoning_output_tokens,
|
|
635
636
|
// total_tokens}}}}
|
|
636
637
|
// We resolve the rollout path lazily (cache sid→path), then read the tail
|
|
637
|
-
// for usage + model. CODEX_HOME overrides ~/.codex.
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
//
|
|
642
|
-
// to build its own `join(homedir(), ".codex", "sessions")` for the purpose
|
|
643
|
-
// which ignored CODEX_HOME and so named a directory that does not exist on any
|
|
638
|
+
// for usage + model. CODEX_HOME overrides ~/.codex, and codex-dir.mjs owns that
|
|
639
|
+
// rule for every module on the Codex side — this one used to spell it inline,
|
|
640
|
+
// which is how five modules ended up with three spellings of it (#375).
|
|
641
|
+
//
|
|
642
|
+
// Re-exported because bin/deck.js prints this path in the boot banner, and it
|
|
643
|
+
// used to build its own `join(homedir(), ".codex", "sessions")` for the purpose
|
|
644
|
+
// — which ignored CODEX_HOME and so named a directory that does not exist on any
|
|
644
645
|
// machine that sets it. Handing out the binding the watcher itself reads, rather
|
|
645
646
|
// than a second computation of the same rule, is what makes the printed path and
|
|
646
647
|
// the tailed path unable to disagree.
|
|
647
|
-
export
|
|
648
|
+
export { CODEX_SESSIONS_DIR };
|
|
648
649
|
const codexRolloutPathBySid = new Map();
|
|
649
650
|
const lastCodexUsageReadAt = new Map();
|
|
650
651
|
const pendingCodexUsageReads = new Set();
|
|
@@ -653,34 +654,19 @@ const CODEX_READ_THROTTLE_MS = 2500;
|
|
|
653
654
|
async function findCodexRolloutPath(sid) {
|
|
654
655
|
const cached = codexRolloutPathBySid.get(sid);
|
|
655
656
|
if (cached) return cached;
|
|
656
|
-
// Walk year → month → day → files. Codex includes the sid in the
|
|
657
|
-
// (rollout-...-<sid>.jsonl) so a directory-scoped match is enough.
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
catch { continue; }
|
|
670
|
-
for (const d of days) {
|
|
671
|
-
const dayDir = join(CODEX_SESSIONS_DIR, y, m, d);
|
|
672
|
-
let files;
|
|
673
|
-
try { files = await readdir(dayDir); } catch { continue; }
|
|
674
|
-
const hit = files.find(f => f.includes(sid) && f.endsWith(".jsonl"));
|
|
675
|
-
if (hit) {
|
|
676
|
-
const full = join(dayDir, hit);
|
|
677
|
-
codexRolloutPathBySid.set(sid, full);
|
|
678
|
-
return full;
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
return null;
|
|
657
|
+
// Walk year → month → day → files, newest first. Codex includes the sid in the
|
|
658
|
+
// filename (rollout-...-<sid>.jsonl) so a directory-scoped match is enough.
|
|
659
|
+
// The walk itself lives in codex-dir.mjs, shared with the watcher's listing
|
|
660
|
+
// below and with codex-usage.mjs, so all three read one tree the same way.
|
|
661
|
+
let found = null;
|
|
662
|
+
await walkRolloutDays((dayDir, files) => {
|
|
663
|
+
const hit = files.find(f => f.includes(sid) && f.endsWith(".jsonl"));
|
|
664
|
+
if (!hit) return;
|
|
665
|
+
found = join(dayDir, hit);
|
|
666
|
+
return STOP;
|
|
667
|
+
});
|
|
668
|
+
if (found) codexRolloutPathBySid.set(sid, found);
|
|
669
|
+
return found;
|
|
684
670
|
}
|
|
685
671
|
|
|
686
672
|
/** Tail-read a Codex rollout JSONL. Returns the last token_count info block
|
|
@@ -846,25 +832,13 @@ async function readLiveDecks() {
|
|
|
846
832
|
// of history every tick.
|
|
847
833
|
async function listRecentCodexRollouts() {
|
|
848
834
|
const out = [];
|
|
849
|
-
let years;
|
|
850
|
-
try { years = (await readdir(CODEX_SESSIONS_DIR)).filter(d => /^\d{4}$/.test(d)).sort().reverse(); }
|
|
851
|
-
catch { return out; }
|
|
852
835
|
let dayDirs = 0;
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
for (const d of days) {
|
|
860
|
-
const dir = join(CODEX_SESSIONS_DIR, y, m, d);
|
|
861
|
-
let files;
|
|
862
|
-
try { files = await readdir(dir); } catch { continue; }
|
|
863
|
-
for (const f of files) if (f.endsWith(".jsonl")) out.push(join(dir, f));
|
|
864
|
-
if (++dayDirs >= 2) return out;
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
}
|
|
836
|
+
await walkRolloutDays((dir, files) => {
|
|
837
|
+
for (const f of files) if (f.endsWith(".jsonl")) out.push(join(dir, f));
|
|
838
|
+
// Two day-directories deep is the whole point of this listing: it runs every
|
|
839
|
+
// tick, and anything older than that is a session no process will append to.
|
|
840
|
+
if (++dayDirs >= 2) return STOP;
|
|
841
|
+
});
|
|
868
842
|
return out;
|
|
869
843
|
}
|
|
870
844
|
|
package/src/server/installer.mjs
CHANGED
|
@@ -7,24 +7,25 @@
|
|
|
7
7
|
// with __agent-dag and de-duped.
|
|
8
8
|
import { readFile, mkdir, unlink, rename, open, stat, chmod } from "node:fs/promises";
|
|
9
9
|
import { existsSync } from "node:fs";
|
|
10
|
-
import { homedir } from "node:os";
|
|
11
10
|
import { join, resolve, dirname } from "node:path";
|
|
12
11
|
import { setTimeout as delay } from "node:timers/promises";
|
|
13
12
|
import { fileURLToPath } from "node:url";
|
|
14
13
|
import { claudeConfigDir } from "./claude-dir.mjs";
|
|
14
|
+
import { CODEX_HOME } from "./codex-dir.mjs";
|
|
15
15
|
import { shellQuoteArg } from "./exec.mjs";
|
|
16
16
|
import { PRODUCT } from "./brand.mjs";
|
|
17
17
|
|
|
18
18
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
19
19
|
const PKG_ROOT = resolve(__dirname, "..", "..");
|
|
20
20
|
|
|
21
|
-
const HOME = homedir();
|
|
22
21
|
// Honours CLAUDE_CONFIG_DIR, exactly as CODEX_DIR honours CODEX_HOME below.
|
|
23
22
|
// Without it the hooks land in a settings.json Claude Code never opens.
|
|
24
23
|
const CLAUDE_DIR = claudeConfigDir();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
// Both directories now come from the module that owns the rule rather than from
|
|
25
|
+
// a copy of it here — claude-dir.mjs and codex-dir.mjs. The local name stays
|
|
26
|
+
// because CODEX_DIR is what the rest of this file and its tests call it, and it
|
|
27
|
+
// says what the value is FOR here: the directory hooks.json is taken out of.
|
|
28
|
+
const CODEX_DIR = CODEX_HOME;
|
|
28
29
|
|
|
29
30
|
// Single shared discovery dir — both providers' hook scripts post here so one
|
|
30
31
|
// running agent-dag server can match either ecosystem's events. It follows the
|