UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

26 lines (25 loc) • 1.85 kB
/** The mode of every file the engine creates to hold its own data: owner read/write only. */ export declare const PRIVATE_FILE_MODE = 384; /** * The one way the engine opens a file it will fill and then publish under another name: a NEW file, owner-only. `open(2)` * applies a mode only to a file it creates, so a truncating open (`"w"`) of a name that is already there keeps that file's * old mode and its inode, and the rename that publishes it hands both to the official name. Two shapes of write need two * spellings, and no third: * - a temp file that is renamed or linked onto its target — {@link openExclusiveTemp}, below; * - a file whose name is fixed and sits in a directory this very call just created (a lock's owner token, a staged tree) — * `openSync(path, "wx", PRIVATE_FILE_MODE)`: a directory made a moment ago holds nothing, so `wx` cannot meet a * leftover, and a planted name is refused rather than written through. * Anything that opens a file for writing, with a mode, and neither of these, is the defect this module exists to prevent. */ /** * Open a NEW temp file named `<stem>.<pid>.<random>.tmp` for writing, and say which name it got. The open is * `O_CREAT | O_EXCL`, so it never reuses a file that is already there. A name already taken is skipped for a fresh one, * never opened, truncated or removed — whatever stands there is not ours to touch. After {@link TEMP_OPEN_ATTEMPTS} taken * names the open throws a plain `Error` carrying the last `EEXIST` as its `cause`: deliberately not an `EEXIST` itself, * because a caller that publishes with `link` answers an `EEXIST` of its own for "the target is already there", and must * not read an exhausted temp namespace as a published blob. */ export declare function openExclusiveTemp(stem: string): { fd: number; path: string; };