Skip to content

Commit 2523943

Browse files
authored
feat(codex): name additional session-catalog homes (#124807)
1 parent 8b9650d commit 2523943

6 files changed

Lines changed: 89 additions & 46 deletions

File tree

‎docs/plugins/codex-harness-reference.md‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ outside OpenClaw:
8585
enabled: true,
8686
config: {
8787
sessionCatalog: {
88-
homes: ["/path/to/additional-codex-home"],
88+
homes: [
89+
"/path/to/additional-codex-home",
90+
{ path: "/path/to/review-codex-home", label: "Review sessions" },
91+
],
8992
},
9093
},
9194
},
@@ -95,10 +98,12 @@ outside OpenClaw:
9598
```
9699

97100
Configured stores appear in the sidebar alongside automatically discovered
98-
ones, labeled `Local Codex · configured <n>` and grouped by each session's
99-
working directory. Sessions in these stores support the same view, continue,
100-
and archive actions, and the selected OpenClaw agent still owns the resulting
101-
connection; `homes` only adds catalog sources.
101+
ones, labeled `Local Codex · <label>` and grouped by each session's working
102+
directory. String entries and objects without `label` use the basename of the
103+
canonicalized home directory; an explicit `label` overrides that default.
104+
Sessions in these stores support the same view, continue, and archive actions,
105+
and the selected OpenClaw agent still owns the resulting connection; `homes`
106+
only adds catalog sources.
102107

103108
Only existing directories are included. Equivalent paths are canonicalized and
104109
deduplicated against the automatic homes, and automatic homes keep priority

‎extensions/codex/openclaw.plugin.json‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,20 @@
8484
"enabled": { "type": "boolean", "default": true },
8585
"homes": {
8686
"type": "array",
87-
"items": { "type": "string", "minLength": 1, "pattern": "\\S" }
87+
"items": {
88+
"anyOf": [
89+
{ "type": "string", "minLength": 1, "pattern": "\\S" },
90+
{
91+
"type": "object",
92+
"additionalProperties": false,
93+
"required": ["path"],
94+
"properties": {
95+
"path": { "type": "string", "minLength": 1, "pattern": "\\S" },
96+
"label": { "type": "string", "minLength": 1, "pattern": "\\S" }
97+
}
98+
}
99+
]
100+
}
88101
}
89102
}
90103
},
@@ -406,7 +419,7 @@
406419
},
407420
"sessionCatalog.homes": {
408421
"label": "Additional Codex Homes",
409-
"help": "Existing local Codex home directories to include in native session discovery. Paths are canonicalized and deduplicated. Requires appServer.transport=stdio and a Gateway restart.",
422+
"help": "Existing local Codex home directories to include in native session discovery. String paths use the canonical directory basename as their label; object entries can override it with label. Paths are canonicalized and deduplicated. Requires appServer.transport=stdio and a Gateway restart.",
410423
"advanced": true
411424
},
412425
"codexDynamicToolsLoading": {

‎extensions/codex/src/app-server/config.test.ts‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,29 @@ describe("Codex app-server config", () => {
367367
).toStrictEqual({});
368368
});
369369

370-
it("parses native session discovery options", () => {
370+
it("parses named native session discovery homes and rejects empty labels", () => {
371371
expect(
372372
readCodexPluginConfig({
373-
sessionCatalog: { enabled: false, homes: [" /srv/codex-extra "] },
373+
sessionCatalog: {
374+
enabled: false,
375+
homes: [
376+
" /srv/codex-string ",
377+
{ path: " /srv/codex-named ", label: " Named store " },
378+
{ path: " /srv/codex-default " },
379+
],
380+
},
374381
}).sessionCatalog,
375-
).toEqual({ enabled: false, homes: ["/srv/codex-extra"] });
376-
expect(readCodexPluginConfig({ sessionCatalog: { homes: [" "] } })).toStrictEqual({});
382+
).toEqual({
383+
enabled: false,
384+
homes: [
385+
"/srv/codex-string",
386+
{ path: "/srv/codex-named", label: "Named store" },
387+
{ path: "/srv/codex-default" },
388+
],
389+
});
390+
expect(
391+
readCodexPluginConfig({ sessionCatalog: { homes: [{ path: "/srv/codex", label: " " }] } }),
392+
).toStrictEqual({});
377393
});
378394

379395
it.each([

‎extensions/codex/src/app-server/session-discovery-config.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { z } from "zod";
22

3+
const codexSessionCatalogHomeSchema = z.union([
4+
z.string().trim().min(1),
5+
z.object({ path: z.string().trim().min(1), label: z.string().trim().min(1).optional() }).strict(),
6+
]);
7+
38
export const codexSessionCatalogConfigSchema = z
49
.object({
510
enabled: z.boolean().optional(),
6-
homes: z.array(z.string().trim().min(1)).optional(),
11+
homes: z.array(codexSessionCatalogHomeSchema).optional(),
712
})
813
.strict();
914

‎extensions/codex/src/session-catalog-homes.ts‎

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type { CodexCatalogHome } from "./session-catalog-types.js";
2424
type CatalogHomeCandidate = {
2525
codexHome: string;
2626
label: string;
27-
usesProcessHomeFallback: boolean;
27+
usesProcessHomeFallback?: boolean;
2828
};
2929

3030
function canonicalCatalogHome(value: string): string {
@@ -36,13 +36,16 @@ function canonicalCatalogHome(value: string): string {
3636
}
3737
}
3838

39-
function existingCanonicalCatalogHome(value: string): string | undefined {
39+
function existingCatalogHomeCandidates(value: string, label?: string): CatalogHomeCandidate[] {
40+
const codexHome = canonicalCatalogHome(value);
4041
try {
41-
const codexHome = fs.realpathSync.native(path.resolve(value));
42-
return fs.statSync(codexHome).isDirectory() ? codexHome : undefined;
42+
if (!fs.statSync(codexHome).isDirectory()) {
43+
return [];
44+
}
4345
} catch {
44-
return undefined;
46+
return [];
4547
}
48+
return [{ codexHome, label: `Local Codex · ${label ?? path.basename(codexHome)}` }];
4649
}
4750

4851
function catalogHomeId(codexHome: string): string {
@@ -93,27 +96,15 @@ function resolveCodexCatalogHomes(params: {
9396
left === ownerAgentId ? -1 : right === ownerAgentId ? 1 : left.localeCompare(right),
9497
);
9598
candidates.push(
96-
...agentIds.flatMap((agentId) => {
97-
const codexHome = canonicalCatalogHome(
99+
...agentIds.flatMap((agentId) =>
100+
existingCatalogHomeCandidates(
98101
resolveCodexAppServerHomeDir(resolveAgentDir(config, agentId, env)),
99-
);
100-
return fs.existsSync(codexHome)
101-
? [{ codexHome, label: `Local Codex · ${agentId}`, usesProcessHomeFallback: false }]
102-
: [];
103-
}),
104-
);
105-
candidates.push(
106-
...configuredHomes.flatMap((value, index) => {
107-
const codexHome = existingCanonicalCatalogHome(value);
108-
return codexHome
109-
? [
110-
{
111-
codexHome,
112-
label: `Local Codex · configured ${index + 1}`,
113-
usesProcessHomeFallback: false,
114-
},
115-
]
116-
: [];
102+
agentId,
103+
),
104+
),
105+
...configuredHomes.flatMap((entry) => {
106+
const { path: home, label } = typeof entry === "string" ? { path: entry } : entry;
107+
return existingCatalogHomeCandidates(home, label);
117108
}),
118109
);
119110
}
@@ -144,7 +135,7 @@ function resolveCodexCatalogHomes(params: {
144135
env: { ...base.start.env, CODEX_HOME: candidate.codexHome },
145136
},
146137
},
147-
usesProcessHomeFallback: candidate.usesProcessHomeFallback,
138+
usesProcessHomeFallback: candidate.usesProcessHomeFallback ?? false,
148139
});
149140
if (homes.length >= MAX_HOST_COUNT) {
150141
break;

‎extensions/codex/src/session-catalog-listing.test.ts‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,11 @@ describe("Codex supervision catalog", () => {
293293
tempDirs.push(root);
294294
const alphaAgentDir = path.join(root, "agents", "alpha", "agent");
295295
const betaAgentDir = path.join(root, "agents", "beta", "agent");
296+
const fileAgentDir = path.join(root, "agents", "file", "agent");
296297
const processCodexHome = path.join(root, "process-codex-home");
297298
const alphaCodexHome = resolveCodexAppServerHomeDir(alphaAgentDir);
298299
const betaCodexHome = resolveCodexAppServerHomeDir(betaAgentDir);
300+
const fileAgentCodexHome = resolveCodexAppServerHomeDir(fileAgentDir);
299301
const configuredCodexHomes = Array.from({ length: MAX_HOST_COUNT }, (_, index) =>
300302
path.join(root, "configured-codex-home", String(index)),
301303
);
@@ -310,13 +312,17 @@ describe("Codex supervision catalog", () => {
310312
await Promise.all([
311313
fs.symlink(configuredCodexHome, configuredCodexHomeAlias, "dir"),
312314
fs.writeFile(configuredFile, "not a directory"),
315+
fs
316+
.mkdir(fileAgentDir, { recursive: true })
317+
.then(() => fs.writeFile(fileAgentCodexHome, "not a directory")),
313318
]);
314319
const runtimeConfig = {
315320
agents: {
316321
ownership: "explicit",
317322
list: [
318323
{ id: "alpha", agentDir: alphaAgentDir },
319324
{ id: "beta", agentDir: betaAgentDir },
325+
{ id: "file", agentDir: fileAgentDir },
320326
],
321327
},
322328
} as OpenClawConfig;
@@ -331,11 +337,13 @@ describe("Codex supervision catalog", () => {
331337
sessionCatalog: {
332338
homes: [
333339
configuredCodexHome,
334-
configuredCodexHomeAlias,
340+
{ path: configuredCodexHomeAlias, label: "Duplicate alias" },
341+
{ path: configuredCodexHomes[1]!, label: "Named store" },
342+
{ path: configuredCodexHomes[2]! },
335343
alphaCodexHome,
336344
path.join(root, "missing-codex-home"),
337345
configuredFile,
338-
...configuredCodexHomes.slice(1),
346+
...configuredCodexHomes.slice(3),
339347
],
340348
},
341349
}),
@@ -350,6 +358,11 @@ describe("Codex supervision catalog", () => {
350358
expect(resolvedHomes.filter((home) => configuredCodexHomes.includes(home))).toHaveLength(
351359
MAX_HOST_COUNT - 3,
352360
);
361+
expect(homes.slice(3, 6).map((home) => home.label)).toEqual([
362+
"Local Codex · 0",
363+
"Local Codex · Named store",
364+
"Local Codex · 2",
365+
]);
353366
expect(homes.map((home) => home.agentDir)).toEqual(Array(MAX_HOST_COUNT).fill(betaAgentDir));
354367
expect(homes[0]?.hostId).toBe(CODEX_LOCAL_SESSION_HOST_ID);
355368
expect(homes.slice(1).every((home) => home.hostId.startsWith("gateway:local:"))).toBe(true);
@@ -423,19 +436,19 @@ describe("Codex supervision catalog", () => {
423436
},
424437
} as OpenClawConfig;
425438
let runtimeConfig = configA;
426-
const existsSync = vi.spyOn(fsSync, "existsSync");
439+
const statSync = vi.spyOn(fsSync, "statSync");
427440
try {
428441
const resolver = createCodexCatalogHomeResolver({
429442
config: configA,
430443
getRuntimeConfig: () => runtimeConfig,
431444
getPluginConfig: () => ({ supervision: { enabled: true } }),
432445
env: { ...process.env, CODEX_HOME: processCodexHome },
433446
});
434-
const seedDiscoveryCount = existsSync.mock.calls.length;
447+
const seedDiscoveryCount = statSync.mock.calls.length;
435448

436449
expect(resolver.forAgent("alpha")).not.toHaveLength(0);
437450
expect(resolver.forAgent("alpha")).not.toHaveLength(0);
438-
expect(existsSync).toHaveBeenCalledTimes(seedDiscoveryCount);
451+
expect(statSync).toHaveBeenCalledTimes(seedDiscoveryCount);
439452

440453
runtimeConfig = configB;
441454
const betaHomes = resolver.forAgent("beta");
@@ -446,12 +459,12 @@ describe("Codex supervision catalog", () => {
446459
betaCodexHome,
447460
),
448461
).toBe(true);
449-
const reloadedDiscoveryCount = existsSync.mock.calls.length;
462+
const reloadedDiscoveryCount = statSync.mock.calls.length;
450463

451464
expect(resolver.forAgent("beta")).toEqual(betaHomes);
452-
expect(existsSync).toHaveBeenCalledTimes(reloadedDiscoveryCount);
465+
expect(statSync).toHaveBeenCalledTimes(reloadedDiscoveryCount);
453466
} finally {
454-
existsSync.mockRestore();
467+
statSync.mockRestore();
455468
}
456469
});
457470

0 commit comments

Comments
 (0)