UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

677 lines • 58.2 kB
/**
 * design/99 §E6 — per-session permission rules: a durable, session-scoped policy narrowing folded into the
 * task-time {@link import("./tool-policy.js").ToolPolicy} (see {@link import("./runner/session-rule-policy.js").createSessionRulePolicy}).
 *
 * Why core-owned (not a parallel service store): the rules must be ENFORCED by the same policy fold that runs
 * every tool call, so storage and enforcement can't drift (the capability-token invariant). core defines
 * the seam + an InMemory default; a deployment supplies a DURABLE cross-replica backend (its CAS-rev semantics
 * must match this InMemory one byte-for-byte — a cross-backend equivalence test is the contract).
 *
 * Safety model:
 * - **tighten-only below what an operator wrote**: a NORMAL write may not loosen the row's operator part
 *   ({@link StoredSessionRules.operatorRules}: what the last operator write set; absent, the whole row) — above it, it
 *   may take back what normal writes added (a deny, its own allowlist or allowDirs narrowing). The one `putRules` is
 *   the write port and the delete port alike: a rule leaves every gate that reads the row when the row stops holding it.
 *   core has NO role system — `operator` is a boolean the caller FREEZES from a verified principal (mirrors
 *   `steer.trusted`); core never adjudicates operator-ness, it only honors the flag.
 * - **CAS rev** (optimistic concurrency): a `putRules` with a stale `expectedRev` is rejected, so two replicas
 *   can't lose an update (mirrors the checkpoint store's `resolve` OCC).
 * - **one grammar**: the two rule buckets hold rule ENTRIES — the grammar every entry list reads, through its one reader
 *   (`readRuleEntry`, allow-entry.ts): a tool name, a protocol namespace, a shell command rule (`Bash(git push:*)`), a
 *   path rule, a name or host rule. Entries are stored as written; every station that validates, compares, matches or
 *   names one reads that reader's answer ({@link judgeSessionRulesWrite}, {@link loosenReasons}, the run-time layer).
 * - **a row keeps its grammar**: the write judge stamps the grammar it read the entries in ({@link SESSION_RULES_GRAMMAR}), and
 *   every station reads a row's entries in the grammar the row carries ({@link readSessionRulesShape}) — an entry keeps the meaning
 *   its writer's grammar gave it, one that grammar could not read takes this engine's, and a row whose entries the two grammars
 *   read differently is announced ({@link earlierGrammarReads}).
 * - **a writer declares its grammar**: a write body carries the `grammar` its entries are written in, and the engine never
 *   supplies one — a body without it is refused `grammar_required` before anything is read ({@link judgeSessionRulesWrite}), a
 *   stored row handed back included (an unstamped one was stored in grammar 0, and its writer says so). An entry the writer's
 *   grammar reads as no rule is then refused as such, rather than reborn as a rule by a reading the writer never made.
 * - **rules are read as rules or not at all**: rules whose shape cannot be read, or whose toolDeny holds an entry no grammar
 *   reads ({@link unreadableDenyEntries}), refuse every call until an operator writes them afresh — never read as fewer.
 * - **NOT A SANDBOX**: a shell command rule reads the command line the call carries (every program run in its connector
 *   chain); the real isolation boundary is the executionEnv, never these rules.
 */
import { compileAllowList, type AllowEntryInert, type AllowEntryInertDetail, type AllowEntryInertReason } from "./allow-entry.js";
import type { EngineNotice } from "./engine-notice.js";
import { type PrincipalRekeyInput, type RekeyConflict, type RekeyDone, type RekeyPlan } from "./identity-rekey.js";
/** The per-session rules. All optional; an absent bucket imposes no constraint of that kind. */
export interface SessionPermissionRules {
    /** If set, ONLY the calls these entries admit are allowed — a narrowing allowlist: a call no entry admits is refused.
     *  Rule entries read in the allow direction (`Read`, `mcp__srv`, `Bash(git:*)`, `Edit(src/**)`). */
    toolAllow?: string[];
    /** Entries whose calls are always refused (deny wins) — rule entries read in the deny direction (`Bash`, `Bash(rm:*)`,
     *  `mcp__srv__delete_*`, `Read(//etc/**)`). */
    toolDeny?: string[];
    /** If set, WRITE tools (`Write`/`Edit`) may only target paths within these dirs; a write-capable
     *  tool that can't be path-confined (e.g. `Bash`) is denied while this is set. Stored RAW; resolved at run time. */
    allowDirs?: string[];
}
/** Every bucket a rules object holds, and how its entries are read: a rule-entry list in one direction, or the write
 *  confinement's directories. A key outside this table is no bucket ({@link readSessionRulesShape} refuses it). */
declare const SESSION_RULE_BUCKETS: {
    readonly toolAllow: "allow";
    readonly toolDeny: "deny";
    readonly allowDirs: "dirs";
};
/** A bucket that holds rule entries. */
export type SessionRuleEntryField = {
    [K in keyof typeof SESSION_RULE_BUCKETS]: (typeof SESSION_RULE_BUCKETS)[K] extends "dirs" ? never : K;
}[keyof typeof SESSION_RULE_BUCKETS];
/**
 * The rule grammar this engine reads a session's rule entries in: the `grammar` the write judge stamps on every rules value it
 * judges ({@link judgeSessionRulesWrite}), so every store that writes through it keeps the stamp on the row. It counts
 * revisions of what an entry MEANS and moves only when that changes:
 *  - 0, the reading before the one entry reader: a bucket's entries were tool names compared as written, so an allow entry the
 *    reader now reads as speaking for another name (`Bash(rm:*)`, `Bash(*)`) named no tool and admitted nothing — and so did
 *    `*`, one more name no tool carried, which voided nothing beside it;
 *  - 1, the one entry reader taking its tool name from the lenient rule parser (trimmed before a `(`, any character but a
 *    blank, a parenthesis or a control / format character);
 *  - 2, the rule syntax's tool-name head (`ruleSpellingOf`): a name is read as written, in the characters names are minted in;
 *  - 3, the whole-protocol names (`mcp__*`, `mcp__*__*`, see `wholeProtocolOf`) read as a deny rule in `toolDeny` — every tool of the
 *    protocol — where grammar 2 read them as an entry that names nothing. An engine of grammar 2 given a row written in grammar 3
 *    refuses it ({@link grammarOf}) rather than read the deny as nothing;
 *  - 4, the delegation tool's type rules (`Agent(<subagent_type>)`) read as a rule on the agent type the call runs — where grammar 3
 *    read them as an entry with no rule form (and its write judge refused one) — and a Bash pattern (`Bash(git * main)`, a star
 *    anywhere but the two trailing markers) reads as the `pattern` match form — where grammar 3 had no form for it — so an engine of
 *    grammar 3 given a row written in grammar 4 refuses it rather than read an `Agent(…)` or `Bash(<pattern>)` deny as nothing;
 *  - 5, a `*` in a tool name is the name grammar's pattern: in `toolDeny` anywhere in the name, over the whole name (`Re*d`, `*` —
 *    every tool), where grammar 4 read `*` and a `*` in a protocol peer as entries that name nothing, `Re*d` as an exact name and a
 *    name starting with `*` as no rule; in `toolAllow` it grants nothing by itself and the entries beside it keep their reading,
 *    where grammars 1–4 voided a list holding it. An engine of grammar 4 given a row written in grammar 5 refuses it rather than
 *    read a `*` deny as nothing. In the same revision a host pattern with an empty label (`WebFetch(domain:.evil.test)`) or a `*`
 *    the URL parser folds (`*.`) is no rule, where grammar 4 read the exact host it spelled; an earlier row's such entry reads as no rule;
 *  - 6, a persisted rule with no content (`SendUserFile`, `Bash`, `Bash(*)`) is the WHOLE-TOOL rule (`match: "tool"`), where grammar 5's
 *    persisted grammar read every bare name as no rule. A session's entries mean what they meant (the entry reader already read a bare
 *    name as the whole tool), so no earlier entry reads differently; the stamp moves for the persisted store's buckets and the sync
 *    wire's states, so an engine of grammar 5 given a bucket written in grammar 6 refuses it whole rather than drop a whole-tool deny
 *    as damage. No persisted row of an earlier stamp can hold a bare name (every entrance refused one), so none is read anew;
 *  - 7, an exact MCP tool name with `__` in its body (`mcp__a__b`, no `*`) in `toolDeny` reads every MCP server spelling it can
 *    stand for (`peerReadingsOf`: tool `b` of server `a` AND every tool of server `a__b`), where grammar 6 read the one exact tool.
 *    A session row an earlier grammar wrote reads such an entry as the one exact tool, announced (the revision table); an engine of
 *    grammar 6 given a row written in grammar 7 refuses it rather than read the deny as the narrower exact tool. The persisted store
 *    and the rule-sync wire stamp 7 as well, so a grammar-6 engine refuses their buckets and states too — but this revision does not
 *    pay the persisted store the reading of its earlier stamps owed below: a stored whole-tool deny / ask of such a name in a
 *    bucket of stamp 6 reads in this grammar, the wider way (#3085);
 *  - 8, a persisted rule may name a whole A2A peer — `a2a__<peer>`, its other spelling `a2a__<peer>__*` reading back as it — reaching
 *    every tool minted under that peer under every behavior, where grammar 7's persisted grammar refused the name as a set of tools. A
 *    session's entries mean what they meant (the entry reader already read a protocol peer as every tool of it), so no earlier entry
 *    reads differently; the stamp moves for the persisted store's buckets and the sync wire's states, so an engine of grammar 7 given
 *    a bucket written in grammar 8 refuses it whole as a newer engine's (`PERMISSION_RULES_LATER_GRAMMAR_CODE`) rather than read a
 *    whole-peer row by a grammar that has no such rule. No persisted row of an earlier stamp can hold such a name (every entrance
 *    refused one), so none is read anew.
 * A row an earlier grammar wrote keeps the meaning that grammar gave its entries, and an entry that grammar could not read takes
 * this one's ({@link earlierGrammarReads}, over the revisions above as one table); an entry this grammar reads as no rule reads as
 * `earlier_grammar` ({@link compileSessionRuleBucket}).
 *
 * The persisted rule store stamps the same number on each bucket it writes (and the rule-sync wire on each state it sends):
 * a stored rule's text is a `Tool(content)` entry read by the same parser, so every revision of what such a text means is a
 * revision counted here. A revision that touches only the entry list (a tool-name head, a protocol name) moves the persisted
 * stamp too, and an engine before it then refuses a bucket it could have read — the refusing side. The persisted store keeps
 * no earlier reading: its rows are read in this grammar whatever stamp at or below it they carry, so a revision that changes
 * what an existing persisted rule text means owes that store a reading of its earlier stamps, as {@link earlierGrammarReads}
 * is for entries. Every stamp is judged by {@link readRuleGrammarStamp}.
 */
export declare const SESSION_RULES_GRAMMAR = 8;
/** {@link SessionPermissionRules} plus the monotonic `rev` the store stamps (the OCC key). */
export interface StoredSessionRules extends SessionPermissionRules {
    rev: number;
    /** The row's LINEAGE: which generation of this key the row belongs to. `rev` counts within one lineage; an
     *  erase (`deleteBySession`) ends it, and the next write on the key starts the next generation, so a reader
     *  can tell a recreated row from a continuation of the one it enforces whatever `rev` the new row wears.
     *  Absent = generation 0 (a backend that predates the mark, or a row written before it). */
    gen?: number;
    /** The rule grammar the row's entries are read in ({@link SESSION_RULES_GRAMMAR}), stamped by the write judge. Absent =
     *  a row stored before the stamp: grammar 0. */
    grammar?: number;
    /** The row's OPERATOR PART: the buckets (and their grammar) the last operator write set — the line a non-operator write
     *  may not loosen ({@link judgeSessionRulesWrite}). Minted by the write judge alone, and present only once a non-operator
     *  write stamped the row (it carries the part it was judged against; over no row, the part of the value it wrote when that
     *  value is a stored row — a rev from 1 — else an empty part). ABSENT = the whole row is the operator's: an operator write, and a row stored before
     *  the member, read fail-closed. Never enforced itself — the row's buckets are what every gate reads. */
    operatorRules?: SessionPermissionRules & {
        grammar: number;
    };
}
/** A rules value as the shape reading hands it on ({@link readSessionRulesShape}): its buckets, the grammar its entries
 *  are read in — resolved, so a store that serves it on beside its own counters serves the row's grammar with it — and the
 *  row's operator part when it carries one ({@link StoredSessionRules.operatorRules}). */
export type SessionRulesInGrammar = SessionPermissionRules & {
    grammar: number;
    operatorRules?: SessionPermissionRules & {
        grammar: number;
    };
};
/** Options for {@link SessionPolicyStore.putRules}. */
export interface PutRulesOptions {
    /** CAS: reject the write if the stored `rev` is not this (optimistic concurrency). Omit to skip the check. */
    expectedRev?: number;
    /** When true, this write MAY loosen the rules (remove a deny / widen an allowlist or allowDirs), and what it writes is
     *  the operator's whole. A NORMAL (non-operator) write may not loosen the row's operator part
     *  ({@link StoredSessionRules.operatorRules}). core does NOT verify operator-ness — the caller (service) FREEZES
     *  this from a verified, role-checked principal (mirrors `steer.trusted`). */
    operator?: boolean;
    /** What this write does with the entries it carries over from the stored row whose reading changes with the grammar it declares
     *  ({@link SessionRuleReread}) — {@link SessionRulesRereadPosture}. Absent: such a write is refused `reread_not_accepted`
     *  (operator writes included). Neither arm takes a loosening of the row's operator part: the tighten comparison runs first. */
    rereads?: SessionRulesRereadPosture;
}
/**
 * How a write treats the entries it rereads ({@link PutRulesOptions.rereads}), one closed word per arm:
 *  - `accept_listed` — the writer has shown its person each new reading and takes it: `entries` names EXACTLY the entries the write
 *    rereads (one too many or one too few is refused `reread_not_accepted`; over a row it rereads nothing in, a non-empty list too);
 *  - `adopt_row` — the caller declares that the value is a whole row another store has already judged, together with its stamp
 *    (`grammar`): it is written as that row, so no entry of the stored row is carried over and none is reread. The engine cannot
 *    verify where the value came from. All it skips is the reread confirmation of the owner's own entries — a non-operator write
 *    is still compared against the row's operator part (`grammar_older_than_rules`, `loosen_forbidden`), and every entry is
 *    still read in the value's grammar (`inert_entry`).
 */
export type SessionRulesRereadPosture = {
    readonly kind: "accept_listed";
    readonly entries: readonly SessionRuleEntryRef[];
} | {
    readonly kind: "adopt_row";
};
/** One entry of one rule bucket, named by its bucket and its text as written. */
export interface SessionRuleEntryRef {
    readonly field: SessionRuleEntryField;
    readonly entry: string;
}
/** An entry a write carries over from the stored row (same bucket, same text) that the grammar the write declares reads
 *  otherwise than the row's grammar did: what it meant there (`was`) and what it means as written now (`now`), in the
 *  revision table's words. */
export interface SessionRuleReread extends SessionRuleEntryRef {
    readonly was: string;
    readonly now: string;
}
/** The way out a refusal names when the session's stored rules are ones {@link rewriteSessionRules} would change: rewrite them
 *  in the current rule grammar (`stampsGrammar`) first, then write. The one machine word of that way out — the write
 *  refusal's `detail.rewrite` and the earlier-grammar notice's `detail.rewrite` carry the same. */
export interface SessionRulesRewriteWayOut {
    readonly by: "rewrite_in_current_grammar";
    readonly stampsGrammar: number;
}
/** The {@link SessionPolicyError.detail} of a `grammar_older_than_rules` refusal: the grammar the write declares and the grammar
 *  of the stored rules it is compared against (the row's operator part), with the rewrite way out when it applies. */
export interface SessionRuleGrammarRefusal {
    readonly declaredGrammar: number;
    readonly rulesGrammar: number;
    readonly rewrite?: SessionRulesRewriteWayOut;
}
/** The {@link SessionPolicyError.detail} of a `reread_not_accepted` refusal: every entry the write rereads, the entries it
 *  accepted (`accept_listed`, {@link PutRulesOptions.rereads}), the ways through ({@link SessionRuleRereadWay}) and the rewrite way
 *  out when it applies. */
export interface SessionRuleRereadRefusal {
    readonly rereads: readonly SessionRuleReread[];
    readonly accepted: readonly SessionRuleEntryRef[];
    readonly ways: readonly SessionRuleRereadWay[];
    readonly rewrite?: SessionRulesRewriteWayOut;
}
/** A way a write refused `reread_not_accepted` gets through, one closed word each: `declare_stored_grammar` — declare `grammar`, the
 *  stored rules' own, and every carried entry keeps its stored reading (present only when the judge takes the same value
 *  declaring that grammar — its entries read there, the operator part's checks pass);
 *  `accept_listed` — send `rereads: { kind: "accept_listed", entries }` naming exactly the entries in `rereads` (none ⇒ send none). */
export type SessionRuleRereadWay = {
    readonly by: "declare_stored_grammar";
    readonly grammar: number;
} | {
    readonly by: "accept_listed";
};
/** The {@link SessionPolicyError.detail} of a `loosen_forbidden` refusal, present only when the stored rules are ones
 *  {@link rewriteSessionRules} would change: a carried entry the write's grammar reads wider than the row's can be the loosening. */
export interface SessionRuleLoosenRefusal {
    readonly rewrite: SessionRulesRewriteWayOut;
}
/** The {@link SessionPolicyError.detail} of an `invalid_shape` refusal: which key, and what it holds — its TYPE, never its
 *  value (`a string`, `null`, `an array holding an entry that is not a string`), or `not a rule bucket` for a key outside
 *  the buckets. `field` is empty when the rules value itself is not an object. */
export interface SessionRuleShapeRefusal {
    field: string;
    got: string;
}
/** The {@link SessionPolicyError.detail} of an `inert_entry` refusal: which bucket, which entry, and why it reads as nothing —
 *  the entry reader's own answer (`readRuleEntry`), reason and facts unchanged. */
export interface SessionRuleEntryRefusal extends AllowEntryInertDetail {
    field: SessionRuleEntryField;
    entry: string;
    reason: AllowEntryInertReason;
    /** Present when the stored rules the write lands on are ones {@link rewriteSessionRules} would change. */
    rewrite?: SessionRulesRewriteWayOut;
}
/** Typed error from {@link SessionPolicyStore.putRules}. `conflict` = stale `expectedRev`; `loosen_forbidden`
 *  = a non-operator write tried to relax what an operator wrote; `corrupt` = a backend could not read what it stored (a row, or the
 *  erase-surviving rev mark of {@link SessionPolicyStore.deleteBySession}) and refuses rather than read it as fewer rules or
 *  stamp an unproven rev; `invalid_shape` = the rules value is not an object of buckets, each a list of strings
 *  ({@link readSessionRulesShape}), or the write's `rereads` is not one of its arms; `inert_entry` = a bucket holds
 *  an entry the entry reader reads as nothing; `grammar_required` = the write body declares no rule grammar (a write names the
 *  grammar its entries are written in — the engine never supplies one; no `detail`); `grammar_older_than_rules` = a
 *  non-operator write declares a grammar older than the stored rules it is compared against, when those assert anything ({@link SessionRuleGrammarRefusal});
 *  `reread_not_accepted` = a write that changes the row's grammar carries entries the two grammars read differently and does not
 *  accept exactly those ({@link SessionRuleRereadRefusal}). `detail` is present on `invalid_shape`, `inert_entry`,
 *  `grammar_older_than_rules` and `reread_not_accepted`, and on `loosen_forbidden` when it carries the rewrite way out
 *  ({@link SessionRuleLoosenRefusal}); on no other code. */
export declare class SessionPolicyError extends Error {
    readonly code: "conflict" | "loosen_forbidden" | "corrupt" | "invalid_shape" | "inert_entry" | "grammar_required" | "grammar_older_than_rules" | "reread_not_accepted";
    readonly detail?: (SessionRuleShapeRefusal | SessionRuleEntryRefusal | SessionRuleGrammarRefusal | SessionRuleRereadRefusal | SessionRuleLoosenRefusal) | undefined;
    constructor(code: "conflict" | "loosen_forbidden" | "corrupt" | "invalid_shape" | "inert_entry" | "grammar_required" | "grammar_older_than_rules" | "reread_not_accepted", message: string, detail?: (SessionRuleShapeRefusal | SessionRuleEntryRefusal | SessionRuleGrammarRefusal | SessionRuleRereadRefusal | SessionRuleLoosenRefusal) | undefined);
}
/** Construction options both bundled stores take. */
export interface SessionPolicyStoreOptions {
    /** The names this deployment mounts its OWN tools under — the roster the store reads a rule entry's tool name against
     *  (`readRuleEntry`): a retired name declared here is an ordinary name to the write and to the loosening check alike.
     *  Absent = none. Each name keeps the caller tool name contract a deployment tool's name keeps at the mount
     *  (`callerToolNameProblem`: a name a rule can name, no `__`); one that does not is refused at construction. */
    mountedToolNames?: Iterable<string>;
}
/** A store's declared roster from {@link SessionPolicyStoreOptions.mountedToolNames} — the one reader both bundled stores
 *  (and so `FileStorageBackendOptions.sessionPolicy`) construct through, refusing loudly when it is not a list of plain
 *  tool names (a bare string would iterate by character). */
export declare function readMountedToolNames(value: unknown): ReadonlySet<string>;
/**
 * The principal a session-rules key is filed under, read once by the engine's reading of a principal offered to a face that
 * tolerates none ({@link readPrincipal}): a name is its own key; absence — `undefined`, and the empty string, which the task door
 * and every bucket resolver read as no principal — is the session-wide key; a value that was provided and is not a name is
 * refused (`TypeError`, naming the fault) before any row is read or written: read as absence it would be the anonymous key's
 * rules, read as a key it would be a bucket no task can ask under. Both bundled stores read their `principal` argument here.
 */
export declare function sessionRulesPrincipalOf(principal: unknown, verb: "getRules" | "putRules"): string | undefined;
/** An inherited session-rules key (an ancestor entry of a chain or a checkpoint) in one spelling, by the one reading of a stored member
 *  ({@link readStoredPrincipal}): a recorded `principal` of `""` (an earlier release's spelling of no principal) or `null` (a host's
 *  empty column) is the entry without the member, so it matches, re-reads and is handed on as the session-wide key. A value that is no
 *  name stays as handed: a checkpoint's is refused by the row verdict, a chain's by the store's read (the layer keeps its seed). */
export declare function inheritedRuleKeyOf<Entry extends {
    readonly principal?: string;
}>(entry: Entry): Entry;
/** A row's rule content: its buckets, its grammar and its operator part (the counters are the key's, not the content). */
export type SessionRuleContent = SessionPermissionRules & Pick<StoredSessionRules, "grammar" | "operatorRules">;
/**
 * Two rows of ONE session-rules key as the one row that enforces both — the law the file store folds a row an earlier release filed under the
 * principal `""` into the session-wide key's row by (the two keys are one key from the reading of the principal on: {@link sessionRulesPrincipalOf}),
 * and the law a host's store twin carrying such rows over reads the same way. Session rules only tighten, so the join refuses whatever either row
 * refuses: `toolDeny` — the entries either row holds; `toolAllow` and `allowDirs` — the entries both rows keep (a list only one row sets is
 * that row's); the operator part (`operatorRules`) the same way, from each row's line (its part, else its whole buckets). Entries compare as written.
 * `undefined` — the rows cannot be one row: their rule grammars differ (a row's own `grammar`, absent = 0, or its operator part's), and an
 * entry's reading moves with the grammar; the file store then refuses with `SessionPolicyError("corrupt")` rather than read one row's entries
 * in the other's grammar. The answer is CONTENT only (no `rev`, `gen`, `__sid` or mark: those are the store's counters for the key, which a file
 * store keeps in its mark file and a twin keeps in its own column) and a new object (neither row is changed). Pure.
 */
export declare function conjoinSessionRuleRows(a: StoredSessionRules, b: StoredSessionRules): SessionRuleContent | undefined;
/**
 * The seam a deployment implements for DURABLE, cross-replica per-session rules. Unset on `RunnerDeps` ⇒ the
 * feature is OFF (no rules read, zero behavior change). Keyed on `(sessionId, principal-owner)`: core passes
 * the running task's `principal` as the owner key — a name, or absent for a task that names no one (never `""`) — and the
 * bundled stores read the argument by {@link sessionRulesPrincipalOf}; ownership/operator AUTHORIZATION is the
 * implementation's job (core has no identity system). `getRules` returns the rules to ENFORCE for a task; `putRules` writes them.
 */
/** A (principal, rules) pair for one session — the unit {@link SessionPolicyStore.listBySession} returns. */
export interface SessionRulesRecord {
    /** The principal these rules apply to (undefined = the session-wide default). */
    principal: string | undefined;
    rules: StoredSessionRules;
}
export interface SessionPolicyStore {
    getRules(sessionId: string, principal?: string): Promise<StoredSessionRules | null>;
    /** Write the rules for a key through the one write judge ({@link judgeSessionRulesWrite}): CAS on `expectedRev`, the
     *  declared grammar (`rules.grammar` — the rule grammar the writer wrote the entries in; absent is `grammar_required`), the
     *  shape, every entry's reading (operator writes included), then, for a non-operator write, the check against the row's
     *  operator part — each refusal a {@link SessionPolicyError}, and nothing is written. The same call is the delete port: a
     *  value without an entry takes it out of every gate that reads the row. */
    putRules(sessionId: string, principal: string | undefined, rules: SessionRulesInGrammar, opts?: PutRulesOptions): Promise<StoredSessionRules>;
    /**
     * 2c session-sync: every (principal, rules) record for `sessionId` across ALL principals — `getRules`
     * is per-(sessionId, principal), but a cross-backend session EXPORT must bundle the WHOLE session's policy.
     * The importer replays each via `putRules(sessionId, record.principal, record.rules)` — the record's own `grammar` stamp
     * rides along (a record stored before the stamp has none: the importer declares it grammar 0, the reading such a row was
     * stored under, and a write of it is otherwise refused `grammar_required`). Optional — a backend
     * that supports cross-backend policy export implements it (local backend uses the in-memory/file impl).
     */
    listBySession?(sessionId: string): Promise<SessionRulesRecord[]>;
    /**
     * 2c session-sync, the ERASE half (server C1b, 2026-07-26): remove EVERY (principal, rules) record for
     * `sessionId`. An importer that OVERWRITES a session must be able to erase the abandoned branch's policy
     * rows — without this seam they survive the overwrite and keep enforcing the old branch's rules against
     * the new content. Optional like {@link listBySession} (a sync-capable backend implements both); the two
     * bundled impls do. Idempotent: deleting a session with no records is a no-op.
     *
     * @contract session_policy.rev_survives_delete — a key's `rev` (one key = `(sessionId, principal)`, the unit
     * a row is stored under) is a HIGH-WATER MARK that survives this erase: the first `putRules` on that key
     * after a `deleteBySession` stamps a `rev` strictly greater than every rev the key ever carried, so no later
     * row of that key reads a smaller `rev` than an earlier one (another principal's row on the same session
     * counts on its own), and a
     * tighten-only (non-operator) write landing after an erase cannot slip under a floor a reader already
     * enforced. A backend that reads "no row" as rev 0 must therefore keep the mark past the row (the bundled
     * in-memory store and a deployment's SQL twin both do). The erase also ends the row's LINEAGE: the next
     * write on the key carries the next `gen`, so a reader that enforces a row treats a later row of another
     * generation as not comparable whatever its rev — a recreated row cannot pass for a continuation.
     */
    deleteBySession?(sessionId: string): Promise<void>;
    /**
     * Re-file one owner's rows under another principal, in the steps {@link import("./identity-rekey.js").REKEY_MODES}
     * names (`plan` → `arrive` → the caller's own commit → `leave`, or `withdraw` when that commit failed); REQUIRED, as
     * every identity seat's re-key member is. The input is read by
     * {@link import("./identity-rekey.js").readPrincipalRekeyInput} before anything is read or written. The answer arm is
     * bound to the step: `plan` answers a plan, `arrive` answers done or conflict, `leave` / `withdraw` answer done.
     *
     * @contract session_policy.rekey_principal — `rekeyPrincipal({ from, toPrincipal, mode })` re-files every row stored under
     * `(sessionId, from)` — `from` resolved through the store's own key reading, aliases included — to `(sessionId,
     * toPrincipal)`, in steps the caller keeps apart. `arrive` first records on the source key's mark an arrival `{ to,
     * source stamp, arrival stamp }` (the source row and both counters untouched), then lands the target mark at the arrival
     * stamp — the per-position maximum of the row's own `(rev, gen)` and the target key's next-write stamp `(mark.rev + 1,
     * mark.gen)` — and then the row; a mark-only source key raises the target mark to the per-position maximum of the two
     * marks, a floor the target's own later writes keep (an ordinary write never lowers a mark in either position). A row whose rules cannot be read travels without a new stamp: a JSON object is re-attributed to `toPrincipal`,
     * any other bytes travel as they are, attributed by the target mark. `leave` performs, on each source key whose arrival
     * record still matches its row, exactly the erase step `deleteBySession` performs on one key (the record survives that
     * erase); a source row the record does not match stays where it is. `withdraw` performs that erase step on each target
     * row the record matches, then clears the record. A target row that is not this move's arrival, or either key sealed or
     * lineage-lost, makes `arrive` answer `conflict` with nothing written; two rows never merge. Any ordinary write to the
     * source key replaces its mark and so drops the record.
     */
    rekeyPrincipal(input: PrincipalRekeyInput & {
        readonly mode: "plan";
    }): Promise<RekeyPlan>;
    rekeyPrincipal(input: PrincipalRekeyInput & {
        readonly mode: "arrive";
    }): Promise<RekeyDone | RekeyConflict>;
    rekeyPrincipal(input: PrincipalRekeyInput & {
        readonly mode: "leave" | "withdraw";
    }): Promise<RekeyDone>;
}
/**
 * LEXICAL path containment for the tighten gate. **Must agree with the runtime's view of what a dir IS** (the
 * runtime resolves `..`/`.`/`//` via `canonicalizeTarget`): both args are `posix.normalize`d FIRST so a
 * non-operator can't carry across a write-confinement OUTSIDE the prior dir by writing `<prior>/../etc` — which is
 * lexically "within `<prior>`" by a naive `startsWith` but canonicalizes to `/etc` at run time (the tighten
 * gate must never UNDER-report a loosening).
 *
 * The `..`-resolving `posix.normalize` pass is THIS function's own job (the tighten gate's `..`-carrying across
 * defense above) and is NOT shared with the runtime's `isWithin` (session-rule-policy.ts), which compares
 * already-canonicalized keys and never resolves `..` itself — the two functions agree on every OTHER input
 * (same win-family fold, same prefix semantics) but diverge on inputs that still carry an unresolved `..`,
 * which is exactly the tighten-gate-only case this function exists to catch.
 *
 * RESIDUAL (documented, bounded): the gate is LEXICAL and cannot follow symlinks at write time, while the
 * runtime IS symlink-aware. A stored allowDir whose LAST component is a pre-existing symlink to outside the
 * prior set would be seen as "within" by this gate yet resolve elsewhere at run time. This is bounded: while an
 * `allowDirs` confinement is active the runtime DENIES `bash` (non-path-confinable), so a confined non-operator
 * cannot CREATE such a symlink — it must pre-exist on the deployment's filesystem. Operators / the durable
 * backend should keep `allowDirs` to real directories; a future symlink-aware write-time canonicalize closes it.
 */
declare function lexWithin(root: string, p: string): boolean;
/**
 * THE ONE JUDGE of a rule grammar stamp, whichever store carries it — a session-rules row ({@link readSessionRulesShape}),
 * the persisted rule store's bucket and the rule-sync wire: the grammar the stamped rules are read in, or the fault that
 * makes them unreadable. `absent` is what a missing stamp reads as (each store says what its unstamped rules were written
 * in). A stamp is a whole number no greater than {@link SESSION_RULES_GRAMMAR}: a later grammar is one this engine cannot
 * read the rules in, and reading them in an older one could grant what their writer refused or drop a refusal it cannot
 * name — so they are refused WHOLE (`later`), never read in part. `rules` names the stamped rules in the sentence, `held`
 * what they hold (`entries`, `rows`).
 */
export declare function readRuleGrammarStamp(stamp: unknown, absent: number, words: {
    readonly rules: string;
    readonly held: string;
}): {
    grammar: number;
} | {
    got: string;
    sentence: string;
    later?: true;
};
/**
 * THE ONE SHAPE READING of a rules value — what every station that takes one reads it through: the write (incoming rules),
 * a store's read-back of its own rows, the tighten comparison's prior, the run-time layer's served row. A rules value is an
 * object whose keys are buckets ({@link SessionPermissionRules}); each bucket present is a list of strings (`allowDirs`: of
 * non-blank strings — a directory is no blank). A bucket's TYPE is all this reads: what an entry means is the entry reader's,
 * in the grammar the value is written in ({@link grammarOf}), handed on as `grammar`. The store's counters (`rev`, `gen`) are
 * passed over, the row's operator part is read as rules of its own and handed on ({@link readOperatorPart}), and a key
 * holding `undefined` holds nothing. Anything else is a fault, named by key and by TYPE, never by value —
 * a bare string is never one rule and never its characters (`"rm"` spread into `["r","m"]`), and a key outside the buckets is
 * never dropped (a dropped deny is a deny nobody enforces).
 */
export declare function readSessionRulesShape(value: unknown): {
    rules: SessionRulesInGrammar;
} | {
    fault: SessionRuleShapeRefusal;
    sentence: string;
};
/** The CANONICAL stored form of a rules value: its shape read ({@link readSessionRulesShape} — a fault refuses with
 *  `invalid_shape`), every list copied (detached from the caller's arrays), and `allowDirs` lexically `posix.normalize`d so the
 *  stored form is `..`-free and the tighten diff compares the form the runtime resolves. Both bundled stores and a durable twin
 *  stamp exactly this, so a structuredClone and a JSON round-trip of it are byte-identical. */
export declare function normalizeRules(rules: unknown): SessionPermissionRules;
/**
 * THE ONE ANSWER to "can these rules' denies be read?": the `toolDeny` entries the list reading ({@link compileSessionRuleBucket},
 * in the rules' own grammar) reads as no rule at all. Rules whose deny bucket holds one cannot be read, and rules that cannot be
 * read are never read as fewer: they refuse every call (the run-time layer) and a non-operator write over them is a loosening
 * ({@link loosenReasons}) — until an operator writes them afresh, and the write judge refuses such an entry. Unlike a definition
 * file a plugin ships, which its user cannot edit, a session's rules are written by the session's own operator and can be
 * rewritten, so a deny nobody can read costs one write instead of quietly guarding nothing. An entry the grammar reads that names
 * no mounted tool (or `*`) is not here: it names nothing and refuses nothing, the rest of the bucket refusing as written.
 * `roster` as in {@link compileSessionRuleBucket}; it never changes this answer (a spelling is read before a name is judged).
 */
export declare function unreadableDenyEntries(rules: SessionRulesInGrammar, roster?: ReadonlySet<string>): AllowEntryInert[];
/**
 * THE LIST READING of one rule bucket of a rules value the shape reading read — what the run-time layer enforces, the tighten
 * comparison compares and the write judge refuses on: the one entry reader over each entry, in the bucket's direction, against
 * `roster` when given, in the grammar the value is written in ({@link earlierGrammarReads}: an entry keeps the meaning its
 * writer's grammar gave it, and one that grammar could not read takes this engine's). The reading is an entry's — save the one
 * list reading a row keeps: grammars 1–4 voided an allow list holding `*` (in any spelling their voiding test read as `*`, `* (*)`
 * included), so such a row's allow list grants nothing; from grammar 5 a `*` grants nothing by itself and the list beside it is read
 * as written. The entries that read as nothing are listed in order, those an earlier grammar reads so (`earlier_grammar`) last.
 */
export declare function compileSessionRuleBucket(rules: SessionRulesInGrammar, field: SessionRuleEntryField, roster?: ReadonlySet<string>): ReturnType<typeof compileAllowList>;
/** The entries of one bucket a stored row's earlier grammar announces ({@link earlierGrammarReads}: its writer's meaning and this
 *  grammar's differ) — what `config.session_rules_earlier_grammar` names, one bucket at a time. */
export declare function earlierGrammarEntries(rules: SessionRulesInGrammar, field: SessionRuleEntryField): string[];
/**
 * The advisory for the entries of one bucket a stored row's earlier grammar reads as nothing ({@link compileSessionRuleBucket},
 * `earlier_grammar`; `grammar` = the row's): the session, the bucket, the entries as written, what they do and the way out. An
 * entry this engine's grammar reads as no rule is named with the reader's word — in `toolAllow` it admits nothing, in `toolDeny`
 * the rules cannot be read and every call is refused ({@link unreadableDenyEntries}); the way out is a rewrite leaving it out
 * (the write judge refuses an entry it cannot read). A grammar-0 allow entry that named no tool there is told as it always was:
 * to make a parenthesized one the rule it now spells, or (`*`, which is no allow rule in any grammar) to leave it out. `part` keeps one
 * sentence of the three (the one a notice frame of {@link earlierGrammarNotices} says); without it, all that apply.
 */
export declare function earlierGrammarAdvisory(sessionId: string | undefined, entries: readonly string[], field: SessionRuleEntryField, grammar: number, part?: "named_no_tool" | "no_rule" | "revised"): string;
/** The reader's word for one entry an earlier grammar announces: `no_rule` — this engine's rule grammar reads it as no rule;
 *  `named_no_tool` — a grammar-0 allow entry the bare-name comparison of its day read as naming no tool; `grammar_revised` — a
 *  grammar revision after the row's gave the entry another meaning, and the message names both and which one the rules enforce. */
export type EarlierGrammarReader = "no_rule" | "named_no_tool" | "grammar_revised";
/**
 * The notices for the entries of one bucket a stored row's earlier grammar reads as nothing or otherwise (audience `user` — the
 * session's rules are what the person's calls are judged by), one frame per destination (7.70.0; before it, one
 * `config.session_rules_earlier_grammar` frame for all of them): an allow-list entry that reads as nothing, or that named no tool in
 * grammar 0, is `config.entries_not_applied` (kind `session_rule_unread` / `session_rule_named_no_tool`, with `count` and `identity`);
 * a deny list that cannot be read is `config.session_rules_earlier_grammar`; entries whose meaning a later grammar revised are
 * `config.session_rules_reread`. Each message is {@link earlierGrammarAdvisory} with that destination's sentence alone, and every
 * `detail` carries the same facts for a machine — `bucket` (the field), `storedGrammar` (the row's), `entries` (its entries, each as
 * `noticeRuleText` hands rule text to a notice, with its reader's word), `rewrite` (the way out, the same word a write's
 * refusal carries: rewrite the stored rules in the current grammar, `stampsGrammar` — {@link rewriteSessionRules}), `rulesSessionId`
 * (whose rules — an ancestor's on a delegated child's inherited layer) and `sessionId` (the run that read them). The two ids come
 * together or not at all: a layer a host built itself (`createSessionRulePolicy`) belongs to no session, and its notice names none.
 */
export declare function earlierGrammarNotices(input: {
    entries: readonly string[];
    field: SessionRuleEntryField;
    grammar: number;
} & ({
    rulesSessionId: string;
    sessionId: string;
} | {
    rulesSessionId?: undefined;
    sessionId?: undefined;
})): EngineNotice[];
/** The clause a run-time refusal carries when the allowlist it judged by holds entries its earlier grammar reads as nothing
 *  ({@link compileSessionRuleBucket}; `grammar` = the row's): the grammar the rules are stored in, then which entries name no tool
 *  there (grammar 0: `*` by its spelling, the parenthesized ones counted) and how many this engine's grammar reads as no rule —
 *  counted, since a stored entry's own text is data and never reaches a sentence the model reads — then the way out, in the one
 *  sentence every face of it says ({@link REWRITE_IN_CURRENT_GRAMMAR}). Empty when none. */
export declare function earlierGrammarRefusalClause(entries: readonly string[], grammar: number): string;
/** A layer's delivery of the entries its snapshots' earlier grammar reads as nothing ({@link compileSessionRuleBucket},
 *  `earlier_grammar`), one bucket at a time with the grammar its row is written in, to `sink`: once per distinct set per layer
 *  (the ledger is this closure's), an empty set is no news, and a throwing sink never changes what the snapshot enforces. There is
 *  always a sink: a layer whose host gave none is handed the engine's notice throat with no seat of its own, never none. */
export declare function earlierGrammarAnnouncer(sink: (entries: readonly string[], field: SessionRuleEntryField, grammar: number) => void): (entries: readonly string[], field: SessionRuleEntryField, grammar: number) => void;
/**
 * THE ONE WRITE JUDGE every store applies before it stamps a row (both bundled stores, and a durable backend at the same point):
 * the rules to stamp, or a {@link SessionPolicyError}, in this order — `conflict` (a stale `expectedRev` against `prior`'s rev),
 * `grammar_required` (the value declares no `grammar` — read before anything else of it: the writer names the grammar its
 * entries are written in and the engine never supplies one, so a value without the stamp is no reading at all, a stored row
 * handed back included), `invalid_shape` ({@link normalizeRules}), `inert_entry` (an entry that reads as nothing in the grammar
 * the rules DECLARE they are written in; operator writes included — a rule that names nothing guards nothing whoever writes
 * it), then, for a non-operator write over a row, `corrupt` when the row cannot be read as rules (the comparison never reads it
 * as fewer), `grammar_older_than_rules` when the value declares a grammar older than the row's OPERATOR PART
 * ({@link StoredSessionRules.operatorRules}; absent, the whole row) and that part asserts anything (a bucket present, an empty
 * list included), and `loosen_forbidden` ({@link loosenReasons}) against that part, and last, for any write over a row it can
 * read, `reread_not_accepted` unless {@link PutRulesOptions.rereads} accepts exactly the entries it rereads or adopts the row.
 * Over no row there is no rev to compare, no tighten gate and nothing reread, and a judge called with `prior = null` (a host's
 * pre-read of a value's shape and entries) answers only those content refusals. Below what an operator wrote nothing moves;
 * above it, a non-operator takes back what non-operator writes added.
 *
 * ONE READING PER WRITE: the value is read, compared and stamped in the grammar it declares — `grammar` on the rules to stamp is
 * that grammar, so a row keeps the meaning its writer gave its entries whatever store keeps it. The comparison reads its two sides
 * each in its own grammar, which is sound only when the value's grammar is no older than the part's (comparing toward a later
 * grammar names every loosening, comparing back hides one — a later grammar's wider deny read as the earlier exact name), hence
 * `grammar_older_than_rules` — asked only of a part that asserts something: an empty part has no loosening to hide. A write that changes the row's grammar and carries an entry the two grammars read differently
 * ({@link SessionRuleReread}) is refused unless it accepts exactly those entries: a host that hands back stored entries under a
 * grammar its person never chose would otherwise change their meaning in silence. A refusal carries the rewrite way out
 * ({@link SessionRulesRewriteWayOut}) when the stored rules are ones {@link rewriteSessionRules} would change.
 *
 * The rules to stamp carry, from a non-operator write, the operator part it was judged against: over no row, the value's own
 * when it is a stored row handed in ({@link isStoredRow}), else an empty one in the value's grammar (an operator write's whole
 * value is the operator's, so it carries none). THIS is the one place both stamps are minted, so every store that stores what the
 * judge returns keeps them. `mountedToolNames` = the store's declaration ({@link SessionPolicyStoreOptions.mountedToolNames}).
 */
export declare function judgeSessionRulesWrite(prior: StoredSessionRules | null, rules: unknown, opts: PutRulesOptions | undefined, mountedToolNames?: ReadonlySet<string>): SessionRulesInGrammar;
/** An entry {@link rewriteSessionRules} cannot carry over unchanged: `unreadable_deny` — a deny no grammar reads (the rules refuse
 *  every call), `not_proven` — the current grammar reads it otherwise than the stored grammar (`was` → `now`). `remedy` says what a
 *  person can do: `accept_reread` — the new reading is a tightening the current grammar reads as a rule, so a write declaring the
 *  current grammar that accepts it (`accept_listed`, {@link PutRulesOptions.rereads}) takes it; `leave_out` — it can only be left out (taking
 *  the new reading would loosen, or the current grammar reads it as no rule), and leaving out a deny is an operator's write. */
export interface SessionRulesRewriteRefusal extends SessionRuleEntryRef {
    readonly why: "unreadable_deny" | "not_proven";
    readonly remedy: "accept_reread" | "leave_out";
    readonly was?: string;
    readonly now?: string;
}
/** What {@link rewriteSessionRules} answers: the rewritten rules (in the current grammar) and the entries it left out because they
 *  did nothing; or every entry it cannot carry over, nothing rewritten, with the entries it would leave out (`dropped`, the whole
 *  answer at once: a host that settles `entries` and leaves out `dropped` writes a value that rereads nothing else); or the
 *  value's own refusal — the shape reading's, or a value that is neither a stored row nor declares its grammar. */
export type SessionRulesRewrite = {
    readonly kind: "rewritten";
    readonly fromGrammar: number;
    readonly rules: SessionRulesInGrammar;
    readonly dropped: readonly SessionRuleEntryRef[];
} | {
    readonly kind: "refused";
    readonly fromGrammar: number;
    readonly entries: readonly SessionRulesRewriteRefusal[];
    readonly dropped: readonly SessionRuleEntryRef[];
} | {
    readonly kind: "unreadable";
    readonly fault: SessionRuleShapeRefusal;
    readonly sentence: string;
};
/**
 * THE ONE REWRITE of stored session rules into the current rule grammar ({@link SESSION_RULES_GRAMMAR}) — a pure reading of the
 * value (no store, no I/O): the way a host carries a row stored in an earlier grammar (or one holding entries that do nothing)
 * over, at its person's action, before it writes a change. Each entry of each rule bucket, read in the row's grammar
 * ({@link earlierGrammarReads}, the revision table):
 *  - it reads as nothing and so did nothing — an allow entry that admitted nothing, a deny entry that names nothing — ⇒ left
 *    out (`dropped`); a list left empty stays present, so an allowlist that admitted nothing still admits nothing;
 *  - it is a deny no grammar reads (the rules refuse every call) ⇒ not carried (`unreadable_deny`);
 *  - the current grammar reads it the same ({@link rereadEntry}) ⇒ kept as written;
 *  - the current grammar reads it otherwise ⇒ not carried (`not_proven`, with the revision table's `was` / `now`).
 * Any entry not carried ⇒ `refused`, naming every such entry and every one it would leave out, and NOTHING is rewritten — a half-carried row would keep some
 * meanings and silently change none, but its person could not tell which. Else `rewritten`: the buckets (`allowDirs` as stored)
 * stamped with the current grammar — a value to write declaring it (non-operator writes included: what it keeps reads the same and
 * what it leaves out did nothing, so the write loosens nothing and rereads nothing). The row's operator part is not carried: the
 * write judge takes it from the stored row. A value the shape reading cannot read ⇒ `unreadable`, in that reading's words; so is a
 * value with no grammar stamp that is no stored row (no `rev`) — it names no grammar to read it in, and none is assumed.
 * Entries are read against the store's roster ({@link storeRoster}: the engine's catalog and `options.mountedToolNames`, the
 * declaration the store the result is written to was built with) — the write judge's own reading, so a name no tool answers to
 * there (a retired name, a case twin) did nothing and is left out, and the result is a value that store's judge accepts.
 */
export declare function rewriteSessionRules(row: unknown, options?: {
    readonly mountedToolNames?: Iterable<string>;
}): SessionRulesRewrite;
/**
 * Pure tighten-only diff: the reasons `next` LOOSENS `prior` (empty ⇒ `next` is a pure tightening or no-op), over the EFFECTIVE
 * entries of each rule bucket — the list as the run-time layer enforces it ({@link effectiveEntries}). Rules whose toolDeny holds
 * an entry no grammar reads ({@link unreadableDenyEntries}) refuse every call: as `next` they loosen nothing, and as `prior`
 * every readable `next` loosens them (one reason, naming the entries). Any other entry that reads as
 * nothing is in neither side's effect, so removing one relaxes nothing and adding one widens nothing (the way a session's owner
 * takes out an entry that names nothing); an allowlist a `*` voids (in this engine's grammar; in grammar 0 a `*` is one such entry beside the rest) admits nothing, so dropping the `*` widens. toolDeny: removing an effective entry loosens. toolAllow: removing the list
 * (→ everything allowed) or adding an effective entry outside the prior set loosens; prior-undefined → any defined next only
 * narrows. allowDirs: removing confinement, or adding a dir not within some prior dir, loosens (coarse raw containment).
 * Entries compare as written, each side's in the grammar that side is written in (a stored row's entry that its grammar reads as
 * nothing is in no effect, so writing it in this engine's grammar widens). Both sides are read through
 * {@link readSessionRulesShape} first: a side it cannot read (a key that is no bucket — a retired one included) throws
 * `invalid_shape` rather than compare without it. `mountedToolNames` = the store's declaration
 * ({@link SessionPolicyStoreOptions.mountedToolNames}; empty when it has none), read with the engine's catalog as the one
 * {@link storeRoster} the write judge reads: a case twin of an engine tool (`BASH`) is no entry on either side, so its owner can
 * take a stored one out (and adding one widens nothing).
 */
export declare function loosenReasons(priorValue: SessionPermissionRules, nextValue: SessionPermissionRules, mountedToolNames?: ReadonlySet<string>): string[];
/**
 * Does row `a` belong to the SAME lineage as row `b` — the one question every reader asks before it compares
 * two rows' `rev`, asked in ONE place so a `gen` that is ABSENT cannot mean three different things at three
 * stations. It means what {@link StoredSessionRules.gen} says it means: generation ZERO. A row that spells
 * `gen: 0` and a row that omits it are therefore the same row's generation, and a row of generation 1 does not
 * continue either of them — which is the case the readings used to disagree on, each treating absence as
 * "unknown, so do not judge" and letting a recreated row pass for a continuation of the one it enforced.
 *
 * ABSENCE STILL CARRIES ONE OTHER FACT, and it is a different question: a backend that stamps no lineage at
 * ALL gives its reader no recycle evidence, so a reader that has one of its own (it watched the row vanish)
 * keeps using it. That test asks whether the FIELD is there, never what it compares to, and it is the caller's
 * to make — this predicate answers only "same lineage or not".
 */
export declare function continuesLineage(a: {
    gen?: number;
}, b: {
    gen?: number;
}): boolean;
/**
 * In-process default {@link SessionPolicyStore} (single-replica). A deployment that needs cross-replica
 * durability supplies its own backend with the SAME CAS-rev + write-judge semantics. Single-threaded JS makes
 * the read-check-write trivially atomic here; a durable backend folds it into a CAS WHERE clause.
 */
export declare class InMemorySessionPolicyStore implements SessionPolicyStore {
    private readonly map;
    /** {@link SessionPolicyStoreOptions.mountedToolNames}, read once at construction. */
    private readonly mountedToolNames;
    constructor(options?: SessionPolicyStoreOptions);
    /**
     * The per-key mark {@link SessionPolicyStore.deleteBySession} may not erase: the largest `rev` this key has
     * ever been stamped with, kept outside the row so removing the row cannot roll the counter back. Written by
     * every stamp, read by the next one and by a re-key, and never collected — an erase frees the row and keeps
     * this, so the cost is one integer per distinct key the process has ever written. A re-key's arrival record
     * rides on it ({@link SessionPolicyStore.rekeyPrincipal}); every ordinary stamp replaces the entry and drops it.
     */
    private readonly highWater;
    private key;
    /** The (session id, principal) pair a key of this store spells — {@link key} read back, never a cast of the parse. */
    private keyParts;
    getRules(sessionId: string, principal?: string): Promise<StoredSessionRules | null>;
    putRules(sessionId: string, principal: string | undefined, rules: SessionRulesInGrammar, opts?: PutRulesOptions): Promise<StoredSessionRules>;
    listBySession(sessionId: string): Promise<SessionRulesRecord[]>;
    deleteBySession(sessionId: string): Promise<void>;
    rekeyPrincipal(input: PrincipalRekeyInput & {
        readonly mode: "plan";
    }): Promise<RekeyPlan>;
    rekeyPrincipal(input: PrincipalRekeyInput & {
        readonly mode: "arrive";
    }): Promise<RekeyDone | RekeyConflict>;
    rekeyPrincipal(input: PrincipalRekeyInput & {
        readonly mode: "leave" | "withdraw";
    }): Promise<RekeyDone>;
}
/** Test-only escape hatch for the module-private tighten-gate containment predicate (mirrors the
 *  `__testables` convention in file-snapshot-store.ts) — lets a regression pin the fold's win-family
 *  conditionality directly rather than only through `loosenReasons`'s allowDirs branch. */
export declare const __testables: {
    lexWithin: typeof lexWithin;
};
export {};