UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

46 lines • 1.97 kB
/** * One GENERATION's files inside an endpoint's daemon directory, and the error every daemon-state path * reports. Split out of `host-daemon-paths.ts` (senpi#2566), which re-exports every name here. */ import { chmod, mkdir } from "node:fs/promises"; import { join } from "node:path"; const DIRECTORY_MODE = 0o700; export function generationPaths(paths, instanceId) { const dir = join(paths.generationsDir, instanceId); return { dir, relativeDir: `generations/${instanceId}`, pidFile: join(dir, "host.pid"), settingsFile: join(dir, "settings.json"), scratchDir: join(dir, "scratch"), childPidFile: join(dir, "host-child.pid"), stopIntentFile: join(dir, "stop-intent.json"), drainRequestFile: join(dir, "drain-request.json"), childDrainRequestFile: join(dir, "host-drain-request.json"), drainWatchFile: join(dir, "drain-watch.json"), stalledFile: join(dir, "host-stalled.json"), aliveFile: join(dir, "host-alive.json"), stopProgressFile: join(dir, "stop-progress.json"), }; } /** A daemon directory that cannot be created or written, named so the caller can say WHICH path failed. */ export class HostDaemonStateError extends Error { constructor(path, cause) { super(`RPC daemon state directory ${path} is not usable: ${cause instanceof Error ? cause.message : cause}`, { cause, }); this.name = "HostDaemonStateError"; this.path = path; } } /** Creates one generation's private directory. Same failure shape as the daemon directory itself. */ export async function createGenerationDirectory(generation) { try { await mkdir(generation.scratchDir, { recursive: true, mode: DIRECTORY_MODE }); await chmod(generation.dir, DIRECTORY_MODE); } catch (cause) { throw new HostDaemonStateError(generation.dir, cause); } } //# sourceMappingURL=host-generation-paths.js.map