UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

110 lines (109 loc) • 5.5 kB
import { type CcPeerFrameFields } from "./cross-session-envelope.js"; /** CC `z8t` — a line longer than this (characters, before its newline) drops the connection. */ export declare const CC_PEER_LINE_MAX_CHARS = 1048576; /** CC `f9n` — a connection with no complete line within this is closed. */ export declare const CC_PEER_FIRST_LINE_DEADLINE_MS = 30000; /** CC's sender socket timeout. */ export declare const CC_PEER_SEND_TIMEOUT_MS = 5000; /** CC `z` — the socket path wall (bytes) of `sun_path`. */ export declare const CC_PEER_SOCKET_PATH_MAX_BYTES = 103; /** CC — the read cap of one key file. */ export declare const CC_PEER_KEY_FILE_MAX_BYTES = 4096; /** CC `$vr` — the registration row's protocol word. */ export declare const CC_PEER_PROTOCOL = 1; /** CC `msgV`. */ export declare const CC_PEER_MESSAGE_VERSION = 1; /** CC `C` — a peer token is 16 random bytes, spelled as 32 lowercase hex. */ export declare const CC_PEER_TOKEN_RE: RegExp; /** CC `xjn` — a published key file: `<pid>.<sha256 of the socket path>.key`. */ export declare const CC_PEER_KEY_FILE_RE: RegExp; /** CC — a registration row file is `<pid>.json`, the pid spelled canonically. */ export declare const CC_PEER_ROW_FILE_RE: RegExp; /** This engine's doorbell action. */ export declare const CC_PEER_NUDGE_ACTION = "mailbox_nudge"; /** The hash a key file is named by: sha-256 of the socket's resolved path (CC `Z`). */ export declare function ccPeerSocketDigest(socketPath: string): string; /** The key file name a process publishes for the socket it listens on. */ export declare function ccPeerKeyFileName(pid: number, socketPath: string): string; /** The address a frame names its sender by (CC `aV`): `uds:` + the percent-encoded socket path. */ export declare function ccPeerAddress(socketPath: string): string; /** * Where the reference agent puts its socket and its session registry (CC 2.1.296, `XDG_RUNTIME_DIR` (cli296.js:274840)): the socket at * `${XDG_RUNTIME_DIR || CLAUDE_CODE_TMPDIR || /tmp}/cc-socks/<pid>.sock`, falling back to * `/tmp/cc-socks-<uid>/<pid>.sock` when that path is past the `sun_path` wall; the registry at * `${CLAUDE_CONFIG_DIR || ~/.claude}/sessions`. Pure: the caller hands in the environment it means. */ export declare function ccPeerDefaultLocations(args: { env: Readonly<Record<string, string | undefined>>; homedir: string; pid: number; uid?: number; }): { socketPath: string; registryDir: string; }; /** The auth line (CC `Gbo`). */ export declare function encodeCcAuthLine(token: string): string; /** One message line (CC's sender frame, key order as the reference writes it). `fields` and `body` go * through the envelope text codec; `from` is the sender's own address. */ export declare function encodeCcUserLine(args: { fields: CcPeerFrameFields; body: string; from?: string; msgId?: string; }): string; /** The doorbell line: a control frame that carries nothing — no content, no sender (the record in the box says who). */ export declare function encodeCcNudgeLine(args?: { msgId?: string; }): string; /** What one wire line is. `toSession` on a message: absent = unaddressed; `null` = present but not a * string (never equal to any session id). */ export type CcPeerLine = { kind: "auth"; token: string | undefined; } | { kind: "user"; content: string; from?: string; toSession?: string | null; attachments: boolean; } | { kind: "nudge"; } | { kind: "unhandled"; type: string; action?: string; } | { kind: "malformed"; why: string; }; /** The ONE reader of an untyped wire value (a parsed JSON line). */ export declare function readCcPeerLine(value: unknown): CcPeerLine; /** Parse one line of text; a line that is not JSON is `malformed`. */ export declare function parseCcPeerLine(line: string): CcPeerLine; /** The facts a session of this engine publishes in the reference agent's registry. */ export interface CcRegistrationFacts { pid: number; sessionId: string; socketPath: string; startedAt: number; updatedAt: number; cwd?: string; name?: string; entrypoint?: string; /** The process start token the reference reads (`ps -o lstart=`, C locale, UTC). Absent = the reference * judges the row by its pid alone. */ procStart?: string; /** The identity of the mailbox store this session drains (`MailboxStore.identity`). Absent = the store cannot * say, and the row then carries no capability bit: every sender reaches this session over its socket. */ storeIdentity?: string; /** The occupant of this session's row (`PeerChannelSelf.occupant`; `null` = no token). Carried in the row as this engine's own * member (`occupant` — the reference agent ignores members it does not know), so a sender of this engine that reaches the * session through its box stamps what it parks for that occupant. */ occupant: string | null; } /** The registration row this engine writes into the reference agent's registry (`<pid>.json`): the * reference's field names, the protocol word, and the capability broadcast — `peerFeatures` carries the one * bit naming the store this session drains ({@link semaMailboxFeature}) and nothing else (this engine takes * none of the reference's socket features: idle subscriptions and artifact yields travel through the box). */ export declare function ccRegistrationRow(facts: CcRegistrationFacts): Record<string, unknown>;