@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
30 lines • 2.36 kB
TypeScript
/**
* `<dir>/c-<generation>.sock` when it fits `sun_path`; otherwise the same name under a short private directory,
* `/tmp/senpi-tc-<sha256(dir)[:12]>/` - never `TMPDIR`, whose macOS default is itself too long. The fallback is
* predictable, so it is used only when it is a real directory of this user with no group or other access; when
* anything else holds that name (another user's directory, a symlink), the socket goes under a fresh `mkdtemp`
* directory instead, so a squatter on the predictable name can neither take the channel over nor block the start.
*/
export declare function channelSocketPath(dir: string, generation: number): Promise<string>;
/** The short private directory a socket falls back to when `<dir>/c-<generation>.sock` does not fit `sun_path`. */
export declare function fallbackSocketRoot(dir: string): string;
export interface ListenerFiles {
readonly logicalPath: string;
readonly secretPath: string;
readonly secret: Buffer;
}
/**
* Claims the socket root, writes this generation's secret into it as a new file, and proves both before anything else
* touches the root. A sibling's close-time sweep can remove the still-empty root between the claim and the secret write,
* and another user can take the name in that window. The exclusive, no-follow write then either fails (ENOENT, EACCES,
* EEXIST on a planted entry) or creates a new file in the taken directory; it never follows or truncates what is there.
* So after the write the root is claimed again and the secret checked to be our own regular file in it, and only then is
* a stale socket of this generation removed. Any failure withdraws a secret this attempt created without ever acting on
* another file: its bytes are destroyed through its own handle once that handle is proven to be the file the create made,
* and its name is unlinked only through a root proven ours again. A root swapped before the withdrawal therefore never
* leads it to another directory's file; the exact limit is that an unprovable root may keep our now-empty file. A
* first-attempt failure a taken fallback root explains retries, and the retry's claim refuses that root and moves to a
* fresh `mkdtemp` directory.
*/
export declare function claimListenerFiles(dir: string, generation: number): Promise<ListenerFiles>;
//# sourceMappingURL=socket-root.d.ts.map