offrouter-adapter-codex 0.2.0 → 0.2.2

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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * offrouter-adapter-codex public surface.
3
+ * Install / rollback for Codex personal profiles (MCP config entry).
4
+ */
5
+ export declare const ADAPTER_CODEX_PACKAGE: "offrouter-adapter-codex";
6
+ export { isCodexHarnessProfile, isSafeProfileId, isWorkLikeProfile, listAllowlistedPersonalCodexProfiles, resolveCodexProfileDir, SAFE_PROFILE_ID_RE, } from "./profile.js";
7
+ export type { ResolveCodexProfileDirOptions } from "./profile.js";
8
+ export { CODEX_CONFIG_REL, CODEX_INSTALL_STATE_REL, CodexInstallStateSchema, evaluateInstallProfilePolicy, formatInstallDiffText, installCodexProfile, } from "./install.js";
9
+ export type { CodexInstallOptions, CodexInstallResult, CodexInstallState, InstallChangeKind, InstallFileChange, } from "./install.js";
10
+ export { rollbackCodexProfile } from "./rollback.js";
11
+ export type { CodexRollbackOptions, CodexRollbackResult } from "./rollback.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,qBAAqB,EAAG,yBAAkC,CAAC;AAExE,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,oCAAoC,EACpC,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAElE,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,uBAAuB,EACvB,4BAA4B,EAC5B,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * offrouter-adapter-codex public surface.
3
+ * Install / rollback for Codex personal profiles (MCP config entry).
4
+ */
5
+ export const ADAPTER_CODEX_PACKAGE = "offrouter-adapter-codex";
6
+ export { isCodexHarnessProfile, isSafeProfileId, isWorkLikeProfile, listAllowlistedPersonalCodexProfiles, resolveCodexProfileDir, SAFE_PROFILE_ID_RE, } from "./profile.js";
7
+ export { CODEX_CONFIG_REL, CODEX_INSTALL_STATE_REL, CodexInstallStateSchema, evaluateInstallProfilePolicy, formatInstallDiffText, installCodexProfile, } from "./install.js";
8
+ export { rollbackCodexProfile } from "./rollback.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,yBAAkC,CAAC;AAExE,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,oCAAoC,EACpC,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,uBAAuB,EACvB,4BAA4B,EAC5B,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAStB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,99 @@
1
+ import { type OffRouterConfig, type PolicyDenialCode } from "offrouter-core";
2
+ import { z } from "zod";
3
+ export declare const CODEX_INSTALL_STATE_REL: ".offrouter/codex-install-state.json";
4
+ export declare const CODEX_CONFIG_REL: "config.toml";
5
+ export declare const CodexInstallStateSchema: z.ZodObject<{
6
+ version: z.ZodLiteral<1>;
7
+ profile: z.ZodString;
8
+ harness: z.ZodLiteral<"codex">;
9
+ installedAt: z.ZodString;
10
+ configRelative: z.ZodLiteral<"config.toml">;
11
+ files: z.ZodRecord<z.ZodString, z.ZodObject<{
12
+ previous: z.ZodNullable<z.ZodString>;
13
+ hash: z.ZodOptional<z.ZodString>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ previous: string | null;
16
+ hash?: string | undefined;
17
+ }, {
18
+ previous: string | null;
19
+ hash?: string | undefined;
20
+ }>>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ version: 1;
23
+ profile: string;
24
+ harness: "codex";
25
+ installedAt: string;
26
+ configRelative: "config.toml";
27
+ files: Record<string, {
28
+ previous: string | null;
29
+ hash?: string | undefined;
30
+ }>;
31
+ }, {
32
+ version: 1;
33
+ profile: string;
34
+ harness: "codex";
35
+ installedAt: string;
36
+ configRelative: "config.toml";
37
+ files: Record<string, {
38
+ previous: string | null;
39
+ hash?: string | undefined;
40
+ }>;
41
+ }>;
42
+ export type CodexInstallState = z.infer<typeof CodexInstallStateSchema>;
43
+ export type InstallChangeKind = "create" | "update" | "unchanged" | "remove";
44
+ export interface InstallFileChange {
45
+ path: string;
46
+ relativePath: string;
47
+ kind: InstallChangeKind;
48
+ /** Diff-like summary line for human output. */
49
+ summary: string;
50
+ }
51
+ export interface CodexInstallOptions {
52
+ profile: string;
53
+ config: OffRouterConfig;
54
+ env?: NodeJS.ProcessEnv;
55
+ homedir?: () => string;
56
+ dryRun?: boolean;
57
+ }
58
+ export interface CodexInstallResult {
59
+ ok: boolean;
60
+ dryRun: boolean;
61
+ profile: string;
62
+ profileDir: string;
63
+ changes: InstallFileChange[];
64
+ message: string;
65
+ errorCode?: PolicyDenialCode | "install_error";
66
+ statePath?: string;
67
+ }
68
+ /**
69
+ * Produce the desired config.toml content for the OffRouter MCP entry using a
70
+ * TOML parser (smol-toml) instead of ad hoc string surgery.
71
+ *
72
+ * - Missing/empty file => fresh config containing only the MCP entry.
73
+ * - Existing file already has [mcp_servers.offrouter] with matching
74
+ * command/args => return the original bytes unchanged (idempotent).
75
+ * - Existing file has a conflicting offrouter entry (or none) => set/replace
76
+ * the entry and stringify, preserving all other unrelated keys.
77
+ *
78
+ * smol-toml does not preserve comments on round-trip; that is accepted as
79
+ * best-effort per the project rule against ad hoc config parsing.
80
+ */
81
+ export declare function patchConfigForMcp(existing: string | null): string;
82
+ /**
83
+ * Use routeRequest with empty candidates so work/unallowlisted profile denials
84
+ * reuse the same core policy codes users see from route explain / hooks.
85
+ */
86
+ export declare function evaluateInstallProfilePolicy(profile: string, config: OffRouterConfig): {
87
+ allowed: boolean;
88
+ errorCode?: PolicyDenialCode;
89
+ message?: string;
90
+ };
91
+ /**
92
+ * Install the OffRouter Codex MCP entry into a single profile directory.
93
+ */
94
+ export declare function installCodexProfile(options: CodexInstallOptions): Promise<CodexInstallResult>;
95
+ /**
96
+ * Human-readable diff-like text for an install/uninstall result matrix.
97
+ */
98
+ export declare function formatInstallDiffText(results: CodexInstallResult[], headline?: string): string;
99
+ //# sourceMappingURL=install.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAaA,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,gBAAgB,EAEtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,eAAO,MAAM,uBAAuB,EAClC,qCAA8C,CAAC;AAEjD,eAAO,MAAM,gBAAgB,EAAG,aAAsB,CAAC;AAOvD,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAalC,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE7E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@ -0,0 +1,361 @@
1
+ /**
2
+ * Profile-scoped installer for Codex personal profiles.
3
+ *
4
+ * Unlike the Claude adapter (which copies a plugin tree), the Codex adapter
5
+ * writes ONE MCP server entry into the profile's TOML config file
6
+ * (profile-scoped) at <profileDir>/config.toml and records rollback metadata
7
+ * inside the target profile (.offrouter/codex-install-state.json).
8
+ */
9
+ import { access, mkdir, readFile, writeFile } from "node:fs/promises";
10
+ import { constants } from "node:fs";
11
+ import { createHash } from "node:crypto";
12
+ import { dirname, join } from "node:path";
13
+ import { homedir as osHomedir } from "node:os";
14
+ import { ROUTE_PROTOCOL_VERSION, routeRequest, } from "offrouter-core";
15
+ import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
16
+ import { z } from "zod";
17
+ import { isCodexHarnessProfile, isSafeProfileId, isWorkLikeProfile, resolveCodexProfileDir, } from "./profile.js";
18
+ export const CODEX_INSTALL_STATE_REL = ".offrouter/codex-install-state.json";
19
+ export const CODEX_CONFIG_REL = "config.toml";
20
+ /** Table name and command/args for the OffRouter MCP server entry. */
21
+ const OFFROUTER_MCP_SERVER_NAME = "offrouter";
22
+ const OFFROUTER_MCP_COMMAND = "offrouter";
23
+ const OFFROUTER_MCP_ARGS = ["mcp", "serve"];
24
+ export const CodexInstallStateSchema = z.object({
25
+ version: z.literal(1),
26
+ profile: z.string().min(1),
27
+ harness: z.literal("codex"),
28
+ installedAt: z.string().min(1),
29
+ configRelative: z.literal(CODEX_CONFIG_REL),
30
+ files: z.record(z.string().min(1), z.object({
31
+ previous: z.string().nullable(),
32
+ hash: z.string().optional(),
33
+ })),
34
+ });
35
+ async function pathExists(path) {
36
+ try {
37
+ await access(path, constants.F_OK);
38
+ return true;
39
+ }
40
+ catch {
41
+ return false;
42
+ }
43
+ }
44
+ function sha256(content) {
45
+ return createHash("sha256").update(content).digest("hex");
46
+ }
47
+ function changeSummary(kind, relativePath) {
48
+ switch (kind) {
49
+ case "create":
50
+ return `+ ${relativePath}`;
51
+ case "update":
52
+ return `~ ${relativePath}`;
53
+ case "unchanged":
54
+ return `= ${relativePath}`;
55
+ case "remove":
56
+ return `- ${relativePath}`;
57
+ default:
58
+ return `? ${relativePath}`;
59
+ }
60
+ }
61
+ /**
62
+ * Produce the desired config.toml content for the OffRouter MCP entry using a
63
+ * TOML parser (smol-toml) instead of ad hoc string surgery.
64
+ *
65
+ * - Missing/empty file => fresh config containing only the MCP entry.
66
+ * - Existing file already has [mcp_servers.offrouter] with matching
67
+ * command/args => return the original bytes unchanged (idempotent).
68
+ * - Existing file has a conflicting offrouter entry (or none) => set/replace
69
+ * the entry and stringify, preserving all other unrelated keys.
70
+ *
71
+ * smol-toml does not preserve comments on round-trip; that is accepted as
72
+ * best-effort per the project rule against ad hoc config parsing.
73
+ */
74
+ export function patchConfigForMcp(existing) {
75
+ if (existing === null || existing.trim() === "") {
76
+ return stringifyToml(freshOffrouterConfig());
77
+ }
78
+ const root = parseToml(existing);
79
+ const servers = isTomlTable(root.mcp_servers) ? root.mcp_servers : undefined;
80
+ if (servers !== undefined &&
81
+ isOffrouterMcpEntry(servers[OFFROUTER_MCP_SERVER_NAME])) {
82
+ return existing;
83
+ }
84
+ const nextRoot = {
85
+ ...root,
86
+ mcp_servers: {
87
+ ...(servers ?? {}),
88
+ [OFFROUTER_MCP_SERVER_NAME]: offrouterMcpEntry(),
89
+ },
90
+ };
91
+ return stringifyToml(nextRoot);
92
+ }
93
+ function isTomlTable(value) {
94
+ return (typeof value === "object" && value !== null && !Array.isArray(value));
95
+ }
96
+ /**
97
+ * True when an existing [mcp_servers.offrouter] entry already matches the
98
+ * OffRouter command/args. Detects a correct prior install by value (not by
99
+ * string equality) so a conflicting entry is overwritten.
100
+ */
101
+ function isOffrouterMcpEntry(value) {
102
+ if (!isTomlTable(value)) {
103
+ return false;
104
+ }
105
+ if (value.command !== OFFROUTER_MCP_COMMAND) {
106
+ return false;
107
+ }
108
+ const args = value.args;
109
+ if (!Array.isArray(args) || args.length !== OFFROUTER_MCP_ARGS.length) {
110
+ return false;
111
+ }
112
+ return args.every((item, index) => item === OFFROUTER_MCP_ARGS[index]);
113
+ }
114
+ function offrouterMcpEntry() {
115
+ return {
116
+ command: OFFROUTER_MCP_COMMAND,
117
+ args: [...OFFROUTER_MCP_ARGS],
118
+ };
119
+ }
120
+ function freshOffrouterConfig() {
121
+ return {
122
+ mcp_servers: {
123
+ [OFFROUTER_MCP_SERVER_NAME]: offrouterMcpEntry(),
124
+ },
125
+ };
126
+ }
127
+ function tinyPolicyProbeRequest(profile) {
128
+ return {
129
+ requestId: "install-policy-probe",
130
+ protocolVersion: ROUTE_PROTOCOL_VERSION,
131
+ harness: { kind: "codex", profile },
132
+ task: {
133
+ promptPreview: "install policy probe",
134
+ promptDigest: "sha256:install-policy-probe",
135
+ kind: "other",
136
+ risk: "low",
137
+ },
138
+ workspace: { cwd: "/tmp/offrouter-install-probe", trusted: true },
139
+ constraints: {
140
+ subscriptionFirst: true,
141
+ allowApiKeyFallback: false,
142
+ },
143
+ };
144
+ }
145
+ /**
146
+ * Use routeRequest with empty candidates so work/unallowlisted profile denials
147
+ * reuse the same core policy codes users see from route explain / hooks.
148
+ */
149
+ export function evaluateInstallProfilePolicy(profile, config) {
150
+ const decision = routeRequest(tinyPolicyProbeRequest(profile), [], config.policy);
151
+ const denials = decision.policyDenials ?? [];
152
+ const hard = denials.find((d) => d.code === "work_profile_denied" ||
153
+ d.code === "profile_not_allowlisted" ||
154
+ d.code === "privacy_label_denied");
155
+ if (hard) {
156
+ return {
157
+ allowed: false,
158
+ errorCode: hard.code,
159
+ message: hard.message,
160
+ };
161
+ }
162
+ // Empty candidates also sets needsConfiguration + may include
163
+ // profile_not_allowlisted even for personal unallowlisted. When allowlisted,
164
+ // only needsConfiguration remains; that is fine for install.
165
+ const profileDenial = denials.find((d) => d.target === "profile");
166
+ if (profileDenial) {
167
+ return {
168
+ allowed: false,
169
+ errorCode: profileDenial.code,
170
+ message: profileDenial.message,
171
+ };
172
+ }
173
+ if (!config.policy.allowlistedProfiles.includes(profile)) {
174
+ return {
175
+ allowed: false,
176
+ errorCode: "profile_not_allowlisted",
177
+ message: `Profile ${profile} is not allowlisted. Add it explicitly before installing or routing.`,
178
+ };
179
+ }
180
+ return { allowed: true };
181
+ }
182
+ /**
183
+ * Install the OffRouter Codex MCP entry into a single profile directory.
184
+ */
185
+ export async function installCodexProfile(options) {
186
+ const { profile, config, dryRun = false, env = process.env, homedir = osHomedir, } = options;
187
+ if (!isSafeProfileId(profile)) {
188
+ return {
189
+ ok: false,
190
+ dryRun,
191
+ profile,
192
+ profileDir: "",
193
+ changes: [],
194
+ message: "Unsafe profile id. Use letters, numbers, dots, underscores, and dashes only.",
195
+ errorCode: "install_error",
196
+ };
197
+ }
198
+ const profileDir = resolveCodexProfileDir(profile, { env, homedir });
199
+ const statePath = join(profileDir, CODEX_INSTALL_STATE_REL);
200
+ const configPath = join(profileDir, CODEX_CONFIG_REL);
201
+ if (!isCodexHarnessProfile(profile)) {
202
+ return {
203
+ ok: false,
204
+ dryRun,
205
+ profile,
206
+ profileDir,
207
+ changes: [],
208
+ message: "Codex install supports only profile ids named codex or starting with codex-.",
209
+ errorCode: "install_error",
210
+ };
211
+ }
212
+ // Work-like profile ids (e.g. codex-work, codex-work-staging) are never
213
+ // installable, even when allowlisted. This mirrors the filter used by
214
+ // listAllowlistedPersonalCodexProfiles so explicit and --all-personal
215
+ // installs apply the same personal-only boundary.
216
+ if (isWorkLikeProfile(profile)) {
217
+ return {
218
+ ok: false,
219
+ dryRun,
220
+ profile,
221
+ profileDir,
222
+ changes: [],
223
+ message: `Profile ${profile} looks like a work profile and is never installable, even if allowlisted. Use a personal profile such as codex-personal.`,
224
+ errorCode: "work_profile_denied",
225
+ };
226
+ }
227
+ const policy = evaluateInstallProfilePolicy(profile, config);
228
+ if (!policy.allowed) {
229
+ return {
230
+ ok: false,
231
+ dryRun,
232
+ profile,
233
+ profileDir,
234
+ changes: [],
235
+ message: policy.message ?? `Profile ${profile} is not installable.`,
236
+ errorCode: policy.errorCode ?? "install_error",
237
+ };
238
+ }
239
+ // Preserve original previous contents across re-installs (idempotent rollback).
240
+ let priorState = null;
241
+ if (await pathExists(statePath)) {
242
+ try {
243
+ const raw = await readFile(statePath, "utf8");
244
+ priorState = CodexInstallStateSchema.parse(JSON.parse(raw));
245
+ }
246
+ catch (err) {
247
+ const detail = err instanceof Error ? err.message : String(err);
248
+ return {
249
+ ok: false,
250
+ dryRun,
251
+ profile,
252
+ profileDir,
253
+ changes: [],
254
+ message: `Invalid install state at ${statePath}: ${detail}`,
255
+ errorCode: "install_error",
256
+ };
257
+ }
258
+ }
259
+ const changes = [];
260
+ // --- config.toml MCP entry ---
261
+ let current = null;
262
+ if (await pathExists(configPath)) {
263
+ current = await readFile(configPath, "utf8");
264
+ }
265
+ const priorFile = priorState?.files[CODEX_CONFIG_REL];
266
+ const previous = priorFile !== undefined ? priorFile.previous : current;
267
+ const desired = patchConfigForMcp(current);
268
+ let kind;
269
+ if (current === null) {
270
+ kind = "create";
271
+ }
272
+ else if (current === desired) {
273
+ kind = "unchanged";
274
+ }
275
+ else {
276
+ kind = "update";
277
+ }
278
+ changes.push({
279
+ path: configPath,
280
+ relativePath: CODEX_CONFIG_REL,
281
+ kind,
282
+ summary: changeSummary(kind, CODEX_CONFIG_REL),
283
+ });
284
+ if (!dryRun && kind !== "unchanged") {
285
+ await mkdir(dirname(configPath), { recursive: true });
286
+ await writeFile(configPath, desired, "utf8");
287
+ }
288
+ // --- install state metadata ---
289
+ const state = {
290
+ version: 1,
291
+ profile,
292
+ harness: "codex",
293
+ installedAt: priorState?.installedAt ?? new Date().toISOString(),
294
+ configRelative: CODEX_CONFIG_REL,
295
+ files: {
296
+ [CODEX_CONFIG_REL]: {
297
+ previous,
298
+ hash: sha256(desired),
299
+ },
300
+ },
301
+ };
302
+ const stateJson = `${JSON.stringify(state, null, 2)}\n`;
303
+ let stateKind = "create";
304
+ if (await pathExists(statePath)) {
305
+ const existing = await readFile(statePath, "utf8");
306
+ stateKind = existing === stateJson ? "unchanged" : "update";
307
+ }
308
+ changes.push({
309
+ path: statePath,
310
+ relativePath: CODEX_INSTALL_STATE_REL,
311
+ kind: stateKind,
312
+ summary: changeSummary(stateKind, CODEX_INSTALL_STATE_REL),
313
+ });
314
+ if (!dryRun && stateKind !== "unchanged") {
315
+ await mkdir(dirname(statePath), { recursive: true });
316
+ await writeFile(statePath, stateJson, "utf8");
317
+ }
318
+ const wrote = changes.filter((c) => c.kind === "create" || c.kind === "update");
319
+ const message = dryRun
320
+ ? `Dry run: would apply ${wrote.length} file change(s) for profile ${profile}.`
321
+ : `Installed OffRouter Codex MCP entry for profile ${profile} (${wrote.length} file change(s)).`;
322
+ return {
323
+ ok: true,
324
+ dryRun,
325
+ profile,
326
+ profileDir,
327
+ changes,
328
+ message,
329
+ statePath,
330
+ };
331
+ }
332
+ /**
333
+ * Human-readable diff-like text for an install/uninstall result matrix.
334
+ */
335
+ export function formatInstallDiffText(results, headline) {
336
+ const lines = [];
337
+ if (headline) {
338
+ lines.push(headline);
339
+ }
340
+ for (const result of results) {
341
+ lines.push(``);
342
+ lines.push(`## ${result.profile} (${result.ok ? (result.dryRun ? "dry-run" : "applied") : "error"})`);
343
+ lines.push(`profileDir: ${result.profileDir}`);
344
+ if (!result.ok) {
345
+ lines.push(`error: ${result.message}`);
346
+ continue;
347
+ }
348
+ for (const change of result.changes) {
349
+ if (change.kind === "unchanged")
350
+ continue;
351
+ lines.push(change.summary);
352
+ }
353
+ const unchanged = result.changes.filter((c) => c.kind === "unchanged").length;
354
+ if (unchanged > 0) {
355
+ lines.push(`= ${unchanged} unchanged`);
356
+ }
357
+ lines.push(result.message);
358
+ }
359
+ return lines.join("\n").trimEnd() + "\n";
360
+ }
361
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.js","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,MAAM,EAAE,KAAK,EAA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,CAAC,IAAI,CAAC,UAAU,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;YACvC,SAAS;QACX,CAAC;QACD,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACpC,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW;gBAAE,SAAS;YAC1C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CACrC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAC9B,CAAC,MAAM,CAAC;QACT,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;YAClB,KAAK,CAAC,IAAI,CAAC,KAAK,SAAS,YAAY,CAAC,CAAC;QACzC,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { OffRouterConfig } from "offrouter-core";
2
+ export declare const SAFE_PROFILE_ID_RE: RegExp;
3
+ export declare function isSafeProfileId(profile: string): boolean;
4
+ export interface ResolveCodexProfileDirOptions {
5
+ env?: NodeJS.ProcessEnv;
6
+ homedir?: () => string;
7
+ }
8
+ /**
9
+ * Resolve the on-disk Codex profile directory for a OffRouter profile id.
10
+ *
11
+ * - When OFFROUTER_CODEX_PROFILES_DIR is set: $DIR/<profile>
12
+ * - profile id `codex` -> CODEX_HOME (if set) else ~/.codex
13
+ * - otherwise -> ~/.<profile> (e.g. codex-personal -> ~/.codex-personal)
14
+ */
15
+ export declare function resolveCodexProfileDir(profile: string, options?: ResolveCodexProfileDirOptions): string;
16
+ /**
17
+ * Personal Codex profiles only: id starts with "codex" or is exactly "codex".
18
+ */
19
+ export declare function isCodexHarnessProfile(profile: string): boolean;
20
+ export declare function isWorkLikeProfile(profile: string): boolean;
21
+ /**
22
+ * Allowlisted personal Codex profiles eligible for install --all-personal.
23
+ * Excludes the bare global `codex` profile (only mutable when explicit) and
24
+ * work-like ids, and applies deniedProfilePatterns glob filters.
25
+ */
26
+ export declare function listAllowlistedPersonalCodexProfiles(config: OffRouterConfig): string[];
27
+ //# sourceMappingURL=profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,eAAO,MAAM,kBAAkB,QAAiC,CAAC;AAEjE,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAExD;AAED,MAAM,WAAW,6BAA6B;IAC5C,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC;CACxB;AAUD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,6BAAkC,GAC1C,MAAM,CAiBR;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE1D;AAQD;;;;GAIG;AACH,wBAAgB,oCAAoC,CAClD,MAAM,EAAE,eAAe,GACtB,MAAM,EAAE,CAaV"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Codex profile directory resolution and allowlist helpers.
3
+ *
4
+ * Mirrors the Claude adapter's profile isolation model:
5
+ * - env OFFROUTER_CODEX_PROFILES_DIR set => <root>/<profile>
6
+ * - profile === "codex" => env CODEX_HOME || ~/.codex (bare global; only
7
+ * mutable when explicitly allowlisted)
8
+ * - otherwise => ~/.<profile> (e.g. codex-personal => ~/.codex-personal)
9
+ */
10
+ import { homedir as osHomedir } from "node:os";
11
+ import { join, resolve } from "node:path";
12
+ export const SAFE_PROFILE_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
13
+ export function isSafeProfileId(profile) {
14
+ return SAFE_PROFILE_ID_RE.test(profile);
15
+ }
16
+ function envValue(env, key) {
17
+ const v = env?.[key]?.trim();
18
+ return v || undefined;
19
+ }
20
+ /**
21
+ * Resolve the on-disk Codex profile directory for a OffRouter profile id.
22
+ *
23
+ * - When OFFROUTER_CODEX_PROFILES_DIR is set: $DIR/<profile>
24
+ * - profile id `codex` -> CODEX_HOME (if set) else ~/.codex
25
+ * - otherwise -> ~/.<profile> (e.g. codex-personal -> ~/.codex-personal)
26
+ */
27
+ export function resolveCodexProfileDir(profile, options = {}) {
28
+ if (!isSafeProfileId(profile)) {
29
+ throw new Error(`Unsafe profile id "${profile}". Use letters, numbers, dots, underscores, and dashes only.`);
30
+ }
31
+ const env = options.env ?? process.env;
32
+ const home = (options.homedir ?? osHomedir)();
33
+ const profilesRoot = envValue(env, "OFFROUTER_CODEX_PROFILES_DIR");
34
+ if (profilesRoot) {
35
+ return resolve(join(profilesRoot, profile));
36
+ }
37
+ if (profile === "codex") {
38
+ const codexHome = envValue(env, "CODEX_HOME");
39
+ return resolve(codexHome ?? join(home, ".codex"));
40
+ }
41
+ return resolve(join(home, `.${profile}`));
42
+ }
43
+ /**
44
+ * Personal Codex profiles only: id starts with "codex" or is exactly "codex".
45
+ */
46
+ export function isCodexHarnessProfile(profile) {
47
+ return profile === "codex" || profile.startsWith("codex-");
48
+ }
49
+ export function isWorkLikeProfile(profile) {
50
+ return profile.endsWith("-work") || profile.includes("-work-");
51
+ }
52
+ function matchGlob(pattern, value) {
53
+ const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
54
+ const re = new RegExp(`^${escaped.replace(/\*/g, ".*")}$`);
55
+ return re.test(value);
56
+ }
57
+ /**
58
+ * Allowlisted personal Codex profiles eligible for install --all-personal.
59
+ * Excludes the bare global `codex` profile (only mutable when explicit) and
60
+ * work-like ids, and applies deniedProfilePatterns glob filters.
61
+ */
62
+ export function listAllowlistedPersonalCodexProfiles(config) {
63
+ return [...config.policy.allowlistedProfiles]
64
+ .filter((id) => isSafeProfileId(id) &&
65
+ isCodexHarnessProfile(id) &&
66
+ id !== "codex" &&
67
+ !isWorkLikeProfile(id) &&
68
+ !(config.policy.deniedProfilePatterns ?? []).some((p) => matchGlob(p, id)))
69
+ .sort((a, b) => a.localeCompare(b));
70
+ }
71
+ //# sourceMappingURL=profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,8BAA8B,CAAC;AAEjE,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC;AAOD,SAAS,QAAQ,CACf,GAAkC,EAClC,GAAW;IAEX,MAAM,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IAC7B,OAAO,CAAC,IAAI,SAAS,CAAC;AACxB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAAe,EACf,UAAyC,EAAE;IAE3C,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CACb,sBAAsB,OAAO,8DAA8D,CAC5F,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACvC,MAAM,IAAI,GAAG,CAAC,OAAO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,mBAAmB,CAAC;SAC1C,MAAM,CACL,CAAC,EAAE,EAAE,EAAE,CACL,eAAe,CAAC,EAAE,CAAC;QACnB,qBAAqB,CAAC,EAAE,CAAC;QACzB,EAAE,KAAK,OAAO;QACd,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACtB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACtD,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CACjB,CACJ;SACA,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type InstallFileChange } from "./install.js";
2
+ export interface CodexRollbackOptions {
3
+ profile: string;
4
+ env?: NodeJS.ProcessEnv;
5
+ homedir?: () => string;
6
+ dryRun?: boolean;
7
+ /** Optional absolute override of the profile directory (tests). */
8
+ profileDir?: string;
9
+ }
10
+ export interface CodexRollbackResult {
11
+ ok: boolean;
12
+ dryRun: boolean;
13
+ profile: string;
14
+ profileDir: string;
15
+ changes: InstallFileChange[];
16
+ message: string;
17
+ errorCode?: "no_install_state" | "invalid_install_state" | "rollback_error";
18
+ }
19
+ /**
20
+ * Restore files tracked by codex-install-state.json for a profile.
21
+ */
22
+ export declare function rollbackCodexProfile(options: CodexRollbackOptions): Promise<CodexRollbackResult>;
23
+ //# sourceMappingURL=rollback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollback.d.ts","sourceRoot":"","sources":["../src/rollback.ts"],"names":[],"mappings":"AASA,OAAO,EAML,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,kBAAkB,GAAG,uBAAuB,GAAG,gBAAgB,CAAC;CAC7E;AAmID;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CA8G9B"}