/** * Retention policy for the per-session generated config dirs * (`~/.sapiom/harness/generated//` — settings.json, * emit.cjs, mcp-config.json, system-prompt.txt). Without it every session * launch leaves a dir behind forever (real installs accumulate thousands). * * Lifecycle facts the policy rests on (see the generators in this directory * and server/index.ts's createDefaultBuildLaunchOpts): * - Most files are consumed at launch — `--settings`/`--mcp-config` are * parsed by the agent at startup, system-prompt.txt is inlined into argv * before spawn — EXCEPT emit.cjs, which the agent re-executes as a child * process on every hook event. A session's dir must therefore survive for * as long as its pty runs. * - buildLaunchOpts regenerates every file on BOTH create() and resume(), * so nothing in the dir is needed once the session has exited: deleting * at exit can never break a later resume. * * Two mechanisms: * - removeGeneratedSessionDir(): per-session delete, wired to the session's * "exited" status transition. * - sweepGeneratedDirs(): boot-time sweep for dirs the exit-time delete * never reached (crashes, force-kills, pre-retention accumulation) — * age-gated so anything plausibly still in use is left alone. * * Safety: deletion only ever targets a plain directory that is a direct * child of a root that itself looks like a dedicated generated-config dir * (resolveGeneratedRoot / childPath). Symlinked entries are never * followed and never deleted. */ /** Sweep threshold: a non-live dir must be at least this stale (mtime) to be * removed. Generous — the only cost of keeping a dead dir is disk clutter, * while a false positive on some unforeseen liveness signal is worse. */ export declare const GENERATED_SWEEP_MAX_AGE_MS: number; export interface GeneratedRetentionOptions { /** Root directory generated configs live under. Defaults to * HARNESS_PATHS.generated. Override in tests to avoid the real home dir. */ generatedRoot?: string; } export interface SweepGeneratedDirsOptions extends GeneratedRetentionOptions { /** Dirs named after a live session id are never removed, whatever their * age. Defaults to treating nothing as live. */ isLiveSession?: (harnessSessionId: string) => boolean; /** Minimum staleness before a dir is swept. Defaults to * GENERATED_SWEEP_MAX_AGE_MS. */ maxAgeMs?: number; /** Injectable clock (epoch ms) for tests. */ now?: () => number; } /** * Deletes one session's generated dir. Only call once the session's pty has * exited — the agent re-executes emit.cjs from this dir on every hook event * while it runs. Returns true if a directory was removed; a missing entry, * an escaping/malformed id, or a symlink (never followed) is false. */ export declare function removeGeneratedSessionDir(harnessSessionId: string, options?: GeneratedRetentionOptions): Promise; /** * Removes every generated dir that (a) isn't a live session's and (b) has * been stale for at least `maxAgeMs`. Covers everything the exit-time * delete can't: sessions that crashed with the harness, force-killed * processes, and accumulation from before retention existed. Only plain * directories are candidates — symlinks and stray files are left untouched. * Best-effort per entry: one undeletable dir doesn't abort the rest. * Returns the names of the dirs it removed. */ export declare function sweepGeneratedDirs(options?: SweepGeneratedDirsOptions): Promise; //# sourceMappingURL=retention.d.ts.map