fix(global-discover): count the interactive Codex CLI (codex_cli_rs) in its own cli bucket

This commit is contained in:
garrytan committed 2026-10-08 06:38:35 +00:00
1 parent 67d800618b
commit 6badda839a
2 files changed
+19 -12

No files matched your search

+7 -5
View File
@@ -17,7 +17,7 @@ import { canonicalRemote } from "../lib/remote-identity";
// ── Types ──────────────────────────────────────────────────────────────────
type CodexOriginator = "desktop" | "exec" | "claude_code" | "other";
type CodexOriginator = "cli" | "desktop" | "exec" | "claude_code" | "other";
type CodexOriginatorCounts = Record<CodexOriginator, number>;
interface Session {
@@ -288,12 +288,14 @@ export function extractCwdFromJsonl(filePath: string): string | null {
return null;
}
// Separates interactive Codex Desktop work from codex exec runs and Claude
// Code-driven calls. Missing, unknown and non-string values count as "other",
// Separates interactive Codex CLI and Desktop work from codex exec runs and
// Claude Code-driven calls. The interactive CLI's default originator is
// codex_cli_rs. Missing, unknown and non-string values count as "other",
// so the buckets always sum to the Codex session total.
function normalizeCodexOriginator(raw: unknown): CodexOriginator {
if (typeof raw !== "string") return "other";
const value = raw.trim().toLowerCase();
if (value === "codex_cli_rs") return "cli";
if (value === "codex desktop" || value === "codex_desktop") return "desktop";
if (value === "codex_exec" || value === "codex exec") return "exec";
if (value === "claude code" || value === "claude_code") return "claude_code";
@@ -301,7 +303,7 @@ function normalizeCodexOriginator(raw: unknown): CodexOriginator {
}
function countCodexOriginators(sessions: Session[]): CodexOriginatorCounts {
const counts: CodexOriginatorCounts = { desktop: 0, exec: 0, claude_code: 0, other: 0 };
const counts: CodexOriginatorCounts = { cli: 0, desktop: 0, exec: 0, claude_code: 0, other: 0 };
for (const s of sessions) {
if (s.tool === "codex") counts[s.codexOriginator ?? "other"]++;
}
@@ -309,7 +311,7 @@ function countCodexOriginators(sessions: Session[]): CodexOriginatorCounts {
}
function formatCodexOriginators(o: CodexOriginatorCounts): string {
return `desktop=${o.desktop}, exec=${o.exec}, claude_code=${o.claude_code}, other=${o.other}`;
return `cli=${o.cli}, desktop=${o.desktop}, exec=${o.exec}, claude_code=${o.claude_code}, other=${o.other}`;
}
function scanCodex(since: Date): Session[] {
+12 -7
View File
@@ -333,24 +333,29 @@ describe("gstack-global-discover", () => {
const originators = () => JSON.parse(discover()).tools.codex.originators;
test("the interactive Codex CLI (codex_cli_rs) goes to cli", () => {
writeCodex("codex_cli_rs");
expect(originators()).toEqual({ cli: 1, desktop: 0, exec: 0, claude_code: 0, other: 0 });
});
test("Codex Desktop goes to desktop", () => {
writeCodex("Codex Desktop");
expect(originators()).toEqual({ desktop: 1, exec: 0, claude_code: 0, other: 0 });
expect(originators()).toEqual({ cli: 0, desktop: 1, exec: 0, claude_code: 0, other: 0 });
});
test("codex_exec goes to exec", () => {
writeCodex("codex_exec");
expect(originators()).toEqual({ desktop: 0, exec: 1, claude_code: 0, other: 0 });
expect(originators()).toEqual({ cli: 0, desktop: 0, exec: 1, claude_code: 0, other: 0 });
});
test("Claude Code goes to claude_code", () => {
writeCodex("Claude Code");
expect(originators()).toEqual({ desktop: 0, exec: 0, claude_code: 1, other: 0 });
expect(originators()).toEqual({ cli: 0, desktop: 0, exec: 0, claude_code: 1, other: 0 });
});
test("surrounding whitespace and case are ignored", () => {
writeCodex(" CODEX DESKTOP ");
expect(originators()).toEqual({ desktop: 1, exec: 0, claude_code: 0, other: 0 });
expect(originators()).toEqual({ cli: 0, desktop: 1, exec: 0, claude_code: 0, other: 0 });
});
test("missing, null, numeric and unknown originators go to other", () => {
@@ -360,7 +365,7 @@ describe("gstack-global-discover", () => {
writeCodex("future-agent");
const json = JSON.parse(discover());
expect(json.tools.codex.total_sessions).toBe(4);
expect(json.tools.codex.originators).toEqual({ desktop: 0, exec: 0, claude_code: 0, other: 4 });
expect(json.tools.codex.originators).toEqual({ cli: 0, desktop: 0, exec: 0, claude_code: 0, other: 4 });
});
test("per-repo and global buckets sum to the codex total and print in the summary", () => {
@@ -374,9 +379,9 @@ describe("gstack-global-discover", () => {
expect(json.tools.codex.total_sessions).toBe(5);
expect(sum(json.tools.codex.originators)).toBe(5);
const repo = json.repos.find((r: { paths: string[] }) => r.paths.includes(repoDir));
expect(repo.codex_originators).toEqual({ desktop: 1, exec: 2, claude_code: 1, other: 1 });
expect(repo.codex_originators).toEqual({ cli: 0, desktop: 1, exec: 2, claude_code: 1, other: 1 });
expect(sum(repo.codex_originators)).toBe(repo.sessions.codex);
expect(discover("summary")).toContain("Codex originators: desktop=1, exec=2, claude_code=1, other=1");
expect(discover("summary")).toContain("Codex originators: cli=0, desktop=1, exec=2, claude_code=1, other=1");
});
});