Files
openclaw/extensions/codex/src/migration/helpers.ts
pashpashpash 027ea5f08b Isolate Codex app-server state per agent (#74556)
* fix(codex): isolate app-server home per agent

* fix(codex): isolate native Codex assets per agent

* fix(channels): mark inbound system events untrusted

* fix(doctor): warn on personal Codex agent skills

* test(doctor): cover personal Codex agent skills warning

* fix(codex): forward auth profiles to harness runs

* fix(codex): preserve auto auth for harness runs

* fix(codex): auto-select harness auth profiles

* test(codex): type harness auth mock

* feat(codex): select migrated skills

* fix(codex): satisfy migration selection lint

* docs: add codex isolation changelog
2026-05-01 04:49:02 +09:00

61 lines
1.3 KiB
TypeScript

import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
export async function exists(filePath: string): Promise<boolean> {
try {
await fs.access(filePath);
return true;
} catch {
return false;
}
}
export async function isDirectory(filePath: string | undefined): Promise<boolean> {
if (!filePath) {
return false;
}
try {
return (await fs.stat(filePath)).isDirectory();
} catch {
return false;
}
}
export function resolveUserHomeDir(): string {
return process.env.HOME?.trim() || os.homedir();
}
export function resolveHomePath(value: string): string {
if (value === "~") {
return resolveUserHomeDir();
}
if (value.startsWith("~/")) {
return path.join(resolveUserHomeDir(), value.slice(2));
}
return path.resolve(value);
}
export function sanitizeName(value: string): string {
return value
.trim()
.toLowerCase()
.replaceAll(/[^a-z0-9._-]+/gu, "-")
.replaceAll(/^-+|-+$/gu, "")
.slice(0, 64);
}
export async function readJsonObject(
filePath: string | undefined,
): Promise<Record<string, unknown>> {
if (!filePath) {
return {};
}
try {
const parsed = JSON.parse(await fs.readFile(filePath, "utf8"));
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
} catch {
return {};
}
}