import { type TwinAction } from './actions.js'; import { type CredentialPayload, type Sealer } from './credential.js'; import { type CredentialCustody } from './executor.js'; import type { RemoteExecute, RemoteExecuteResponse } from './remote-execute.js'; import { type Check, type DeployPolicy, type RootConfig, type StateSystemAdapters } from './state-system.js'; /** What a perform answers: the id the vendor minted (the local id when it kept ours), its URL, and * the vendor's answer as fields for the landed copy. */ export type PushOutcome = { externalId: string; url?: string; data?: Record; /** the successful vendor response for the caller, distinct from the resource fields stored in data */ response?: RemoteExecuteResponse; /** the group's entry the id is for, when it is not the group's first (a cascade writes children first) */ actionId?: string; /** the group's other entries the answer named an id for (a resource's `companions`) */ also?: Array<{ actionId: string; externalId: string; data?: Record; }>; /** the group's entries the vendor refused while it took the rest (a git push to a root without `atomic`, each ref its * own outcome: ADR 0031); each settles refused with its reason */ refused?: Array<{ actionId: string; reason: string; }>; }; /** What a perform is handed beside the executor: a resolver from a local id to the vendor's (an * entry authored against `twin-1` crosses against `REAL-42` once that subject's landing adopted it). */ /** `credential`: the sealed credential's keyed fingerprint (credential.ts — an HMAC under the sealing key, or the * vault's transit hmac at a pinned key version, * never the secret and no offline oracle for it), so a pack keys its budget ledger per real credential: * every World and branch performing with one vendor key then shares that key's one allowance. */ export type PerformContext = { resolve: (type: string, localId: string) => string; service?: string; root?: string; credential?: string; localGroup?: TwinAction[]; }; /** One request's entries (a group: they share its `correlationId`), performed as the one call that made them. */ export type PerformAction = (execute: RemoteExecute, group: TwinAction[], ctx: PerformContext) => Promise; export declare function performContext(service: string, root?: string, credential?: string): PerformContext; /** The user's key-encryption key: `$XDG_CONFIG_HOME/volter/kek` (created on first use). */ export declare function userKekPath(): string; export declare function userKek(): string; export declare function setSealingKeySource(source: (() => string) | null): void; export declare function sealingKey(): string; export declare function setSealer(sealer: Sealer | null): void; export declare function currentSealer(): Sealer; /** The destination a credential is bound to (SealedBody.bound): the origin it is sent to, and only that. */ export declare function destinationOf(url: string): string; /** * Open the credential sealed at `path`, under the current sealer, for `bound` (destinationOf the place it is about to * be sent; omitted where it is sent nowhere, a webhook's signing secret). A record bound elsewhere, or bound nowhere, * refuses. A record the host's vault did not seal (`v: 1`) is sealed again by the vault (decision 0034), keeping its * binding, placedAt and fingerprint (its identity, as a rotation keeps them). The rewrite lands only over the record that was read; if another came meanwhile, that one is opened instead, * so a credential replaced while this one moved is never handed out. */ export declare function openSealedAt(path: string, slot: string, bound?: string): Promise; /** Whether this host seals through a vault (setSealer): what a record under the host's key is moved to. */ export declare function sealsThroughVault(): boolean; /** openSealedAt, with the exact record it answers from: the text it read, or the text its own move wrote. A rotation * lands only over that text (rootCustody), so it never mistakes another record for the one it opened. */ export declare function openSealedRecord(path: string, slot: string, bound?: string, again?: boolean): Promise<{ payload: CredentialPayload; text: string; } | null>; /** A root as a world materializes it: the config plus the path of the sealed credential. */ export type BoundRoot = RootConfig & { credential: string; }; /** Open the credential a root names, under the current sealer, for the root's own origin. */ export declare function openRootCredential(root: BoundRoot, vendor?: string): Promise; /** Seal a credential the vendor rotated (an `exchange` with `rotate`) where the root's was, under the same key, slot and * binding. It is the same credential: its placedAt and fingerprint stay (a pack's budget keys its ledger by the * fingerprint, and a new one per grant would start the ledger over), and rotatedAt says when. `source` is the record * the rotation began from: if another credential was set meanwhile, the rotation is dropped, never written over it. */ export declare function resealRootCredential(root: BoundRoot, payload: CredentialPayload, vendor?: string, source?: string | null): Promise; /** Beside a root's credential, the record of a rotation its seal failed to keep (`rootCustody`'s `unsealed`). */ export declare function unsealedMarkerOf(root: BoundRoot): string; /** The root's custody for an exchange that rotates: the credential as sealed now, and the seal of a rotated one, which * lands only over the record that was opened. */ export declare function rootCustody(root: BoundRoot, vendor?: string): CredentialCustody; /** The vendor a root belongs to: its credential is sealed under the vendor's name. */ export declare function vendorOf(root: BoundRoot): string; /** The world a root belongs to: the credential sits at `/.volter/credentials/.json`. */ export declare function worldRootOf(root: BoundRoot): string; /** The checks a world runs before any entry is performed: the shipped no-secrets check, then every * file under `.volter/checks/` exporting `{ name, run }`. */ export declare function loadChecks(worldRoot: string): Promise; /** How a check file becomes a Check. Locally the file is imported; a hosted World's host supplies a * loader that runs the check in an isolate of its own, with no network and nothing of the World's. */ export type CheckLoader = (path: string, name: string) => Promise; export declare function setCheckLoader(loader: CheckLoader | null): void; /** One check file through the host's loader: what placing a check validates with. */ export declare function loadCheck(path: string, name: string): Promise; export type Head = { kind: 'simulated'; } | { kind: 'real'; deploy: DeployPolicy; root: BoundRoot; }; /** The root a state service under `root` is bound to — its own root.json, else a sibling state's * (slack records under `chat`; the root was written under `slack`). */ export declare function boundRoot(service: string, root?: string): BoundRoot | null; /** What this twin's head does with a write. */ export declare function headOf(service: string, root?: string): Head; /** A check refused the write: the entry is in the log as refused; the pack answers in the vendor's error shape. */ export declare class RefusedWriteError extends Error { readonly check: string; readonly reason: string; readonly actionId: string; constructor(check: string, reason: string, actionId: string); } /** The head could not be bound for a write that needed it (no credential sealed, no adapter registered, * no root): a server-side fault, answered as one. */ export declare class HeadError extends Error { constructor(message: string); } /** The vendor refused or failed the write: the entry is in the log as failed, with the vendor's words. */ export declare class VendorWriteError extends Error { readonly actionId: string; constructor(message: string, actionId: string); } export type DeployReport = { /** entries performed by this call */ pushed: number; deployed: Array<{ actionId: string; externalId?: string; at: string; /** what the vendor answered, as the adapter returned it */ data?: unknown; response?: RemoteExecuteResponse; }>; /** the first refusal; nothing after it was attempted */ refused?: { actionId: string; check: string; reason: string; }; /** the first failure, with the vendor's words; nothing after it was attempted */ failed?: { actionId: string; error: string; }; /** a group the vendor took in part: its entries it refused, each with its reason; nothing after it was attempted */ partial?: Array<{ actionId: string; reason: string; }>; /** entries after the refusal or failure, not attempted */ skipped: string[]; /** entries whose landed copy already said `deployed` — not performed again */ replayed: string[]; /** entries the World's own doors made (a door, a screen, the gap, the clock, a seed): never offered to the vendor */ worldOnly: string[]; }; /** The branch entries a root twin still has to settle: `set` rows, not reverted, whose landed copy is absent or says * `failed`/`skipped` (a `deployed` or `refused` copy settles the entry), split into what is offered to the vendor (a * surface write or a git push on a subject the vendor can have) and what is the World's own: a write a door, a screen, the gap, the * clock or a seed made, and any write on a subject only the World's own writes made. */ export declare function settlingEntries(service: string, root?: string): { offered: TwinAction[]; worldOnly: TwinAction[]; }; /** The entries a root twin offers the vendor (settlingEntries' `offered`). */ export declare function deployableEntries(service: string, root?: string): TwinAction[]; /** * PERFORM this twin's deployable entries against its root, in order, checks in front of every one, * stopping at the first refusal or failure. Each outcome lands as the entry's copy with its receipt * on the parent log. `actionIds` narrows to a changeset's (or one write's) entries. */ export declare function performEntries(opts: { service: string; root?: string; actionIds?: string[]; at?: string; checks?: Check[]; adapters?: StateSystemAdapters; execute?: RemoteExecute; }): Promise; /** * The write path's second half (serve.ts): a write just appended to a twin whose head is real and * `auto` is performed now. Returns the vendor's id when it minted one, so the answer carries it. * Raises `RefusedWriteError` / `VendorWriteError` for the pack to answer in the vendor's shape. */ /** Whether `performAtHead` would perform an entry now (a twin whose root says `auto`, outside a pack fetch's deferred * group): a caller appending several writes at once appends them one at a time then, each performed before the next. */ export declare function performsAtHeadNow(service: string, root?: string): boolean; export declare function performAtHead(service: string, action: Pick, root?: string): Promise<{ performed: boolean; externalId?: string; data?: unknown; }>; /** Run a pack fetch's handling of one request with its writes' perform deferred to the group (`performRequestGroup`): * its answer, and whether it appended (a request that wrote nothing has no group, and consults no head). */ export declare function deferPerform(request: string, fn: () => Promise): Promise<{ value: T; appended: boolean; }>; /** Under `auto`, perform the entries one request made as one call (the real-system adapters, "Perform"): the ids the * vendor gave them by local id, or the vendor's refusal or failure, the request's entries reverted as performAtHead * reverts one. Nothing when the head is not real and auto, or the request wrote nothing the vendor is offered. */ export declare function performRequestGroup(service: string, request: string, root?: string): Promise<{ ids: Map; response?: RemoteExecuteResponse; refused?: Array<{ actionId: string; reason: string; }>; } | RefusedWriteError | VendorWriteError>; /** Wrap a pack's fetch: a `RefusedWriteError` or `VendorWriteError` the head raised becomes the * vendor's own error body (the pack's `shape`), so an app under live use sees what the vendor * would have said. Anything else propagates. */ export declare function answerVendorErrors(fetch: (request: Request) => Promise, shape: (error: RefusedWriteError | VendorWriteError) => Response): (request: Request) => Promise;