UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

554 lines • 53.3 kB
/**
 * The environment a spawned child inherits: which of this process's variables it must not see.
 *
 * A child the engine spawns may run what the MODEL chose (a tool shell, a gate over model-written code, a language
 * server). Under the `"scrub"` policy (the default) it inherits every variable but those the judgment below names and those a
 * protocol peer's credential reference names or the host declares a peer entry of its own references ({@link holdPeerHeldNames},
 * {@link declarePeerHeldEnv}) — deleted whole, never rewritten; `"all"` and a `string[]`
 * allow list are the caller's explicit alternatives
 * ({@link inheritedHostEnv}): `"all"` is the whole environment less the engine's own namespace's credential names (rule 4 alone,
 * {@link isNamespaceCredentialName} — the engine's own slots are no one else's to hand on), a list is exactly the names it
 * lists. Whatever the policy, an entry that is one of the engine's own credentials is never inherited:
 * its name is one the deployment declared, or its value equals a credential value the deployment declared or the
 * engine holds ({@link declareWithheldEnv}, {@link holdOwnCredentialValues}). One judgment per variable and policy
 * ({@link judgeInheritedEntries}) — the first rule that answers:
 *   1. exempt — git's environment config and the proxy variables, handed on as written by the shape rules ({@link isExemptEnvName});
 *   2. `exact-name` — a known credential name (the vocabulary's exact env names);
 *   3. `prefix-rule` — the OpenTelemetry settings ({@link OTEL_ENV_RE});
 *   4. `namespace-rule` — a credential word as any segment of a name in the engine's own `SEMA_` namespace;
 *   5. `name-rule` — a credential-shaped name ({@link nameIsCredentialShaped}) off the vocabulary's non-secret exact names;
 *   6. `value-rule` — a value that carries a credential ({@link looksLikeCredentialValue});
 *   7. `own-credential` — one of the engine's own credentials: no policy hands it on;
 *   8. `peer-held` — a variable held for a protocol peer.
 * Rules 1–6 are the shape rules ({@link classifySecretEnvEntry}): 2–5 its name half ({@link isSensitiveName}), 6 its value half, 1 the
 * env-entry exemption read before both. The scrub reads 1–8; `"all"` reads 4 and 7; a list reads 7. {@link isSecretEnvKey} and
 * {@link scrubSecretEnv} — what a host asks — answer with the scrub's judgment the composition reads, over the tables as they stand. The exempt families, the
 * credential names, the name shape and the value predicate follow the reference implementation's subprocess-env scrub
 * as written, three ways stricter: plural `TOKENS` is a credential word unless a count word touches it, the GitHub
 * token names are not held back from the name shape, and the name shape always runs.
 */
import { type RedactionConfidence, type RedactionSource } from "@sema-agent/primitives";
import { type EngineNotice } from "./engine-notice.js";
import type { ToolAxesSurface } from "./mcp-server-spec.js";
/** THE namespace rule: is `name` a credential slot of the engine's own namespace? A name there with a credential word in any
 *  segment (`SEMA_MODEL_KEY_<entry>`, `SEMA_WEBSEARCH_KEY_<provider>`) is the engine's own credential by construction, read only
 *  inside this process, so neither `"scrub"` nor `"all"` hands it to a child (an allow list naming it does: that is the host's
 *  own statement). It judges by segment, so a path or count setting with a credential word in its name is caught too (KL-1099a).
 *  Read by the name judgment ({@link sensitiveNameKind}, the `"scrub"` policy) and by the `"all"` policy's arm ({@link policyArm}),
 *  and exported from the package root: a host judging a name it hands a child itself asks the question the `"all"` arm asks. */
export declare function isNamespaceCredentialName(name: string): boolean;
/** Does a value carry a credential? A URL userinfo (after every `scheme://`, and a leading `//`) with a password or a
 *  token-like user; a userinfo with no `//` in front of it the vocabulary reads; a credential assignment; a webhook URL; a Sonar login; a
 *  private-key header; an `Authorization` header, `token …`, `Bearer …` or `Basic …` with credential-shaped content (the
 *  value forms are the vocabulary's rows, {@link ENV_VALUES}). Reads the first {@link VALUE_SCAN_LIMIT} code units. The value half of the judgment, exported apart from the env
 *  entry's exemptions ({@link isExemptEnvName}): a caller holding a value that is no environment variable asks this. */
export declare function looksLikeCredentialValue(value: string): boolean;
/** Which rule withheld an entry — the first that answers ({@link judgeInheritedEntries}): one of the scrub's shape rules (the `"all"` policy
 *  withholds under `namespace-rule` alone); `own-credential` — the entry is one of the engine's own credentials (its name is declared, or
 *  its value equals a declared or engine-held credential value: {@link declareWithheldEnv}), which every policy withholds; or `peer-held` —
 *  a variable a protocol peer's credential reference names, a token the engine holds for that peer ({@link holdPeerHeldNames}), which the
 *  `"scrub"` policy withholds by name, and which is `own-credential` when it is also one of the engine's own. */
export type SecretEnvFindingKind = "exact-name" | "name-rule" | "namespace-rule" | "prefix-rule" | "value-rule" | "peer-held" | "own-credential";
/** One env entry withheld (deleted) from a child's environment: its name — never its value, so the record is
 *  loggable —, the rule that withheld it, how strong that claim is, and the minting module. */
export interface SecretEnvFinding {
    key: string;
    kind: SecretEnvFindingKind;
    confidence: RedactionConfidence;
    source: RedactionSource;
    /** Present on an entry {@link hostChildEnv} withheld whose value the settings layer set (`settingsEnv` gave the name a
     *  value, over this process's environment or not): what the person who wrote the settings file wrote. Absent on an entry
     *  of this process's environment. */
    layer?: "settingsEnv";
}
/** Does `key` name a credential? The name half of the judgment ({@link sensitiveNameKind}), exported apart from the env
 *  entry's exemptions ({@link isExemptEnvName}): a caller holding a key that is no environment variable (a member of a
 *  record) asks this, and an exempt name is no exception there. */
export declare function isSensitiveName(key: string): boolean;
/** Does an entry carry a credential by its look alone (the shape rules, no table)? The question a protocol peer's seat answer is read
 *  by (`peer-seat.ts`: which of its environment members' values are credentials the engine takes in); not part of the package entry. */
export declare function entryLooksLikeCredential(name: string, value: string | undefined): boolean;
/** Does the `"scrub"` policy withhold `key`? The scrub's judgment ({@link judgeInheritedEntries}) over the tables as they stand — what a
 *  child composed now under the scrub loses: with `value`, exactly the answer {@link scrubSecretEnv} gives for that entry; without it,
 *  the answer for its name alone (the value rule and an own credential's value then have nothing to read). */
export declare function isSecretEnvKey(key: string, value?: string): boolean;
/** The `"scrub"` policy over `env`: `env` without every entry {@link isSecretEnvKey} withholds, the rest as written — the arm a child
 *  composed under the scrub reads ({@link inheritedHostEnv}). `findings` is an optional caller-owned collector: each withheld entry is
 *  pushed onto it (name, rule, confidence), none of them present in the result. `env` itself is not modified. */
export declare function scrubSecretEnv(env: NodeJS.ProcessEnv, findings?: SecretEnvFinding[]): NodeJS.ProcessEnv;
/** How much of this process's environment a child spawned on this host inherits — the `inheritEnv` value. */
export type InheritEnvPolicy = "all" | "scrub" | string[];
/** {@link envNameKey} on a named platform — the one fold, for a reader that judges another platform's environment. */
export declare function envNameKeyOn(name: string, platform: NodeJS.Platform): string;
/** What {@link declareWithheldEnv} takes: the engine's own credentials in this process's environment. */
export interface WithheldEnvDeclaration {
    /** Names of variables that are the engine's own credentials: never inherited, and an allow list naming one is refused. */
    readonly names: readonly string[];
    /** Credential values this deployment holds: an inherited entry whose value equals one — the same string, compared
     *  whole, never as a part — is never inherited, whatever its name. A value must be a credential: not white space only,
     *  a flag or placeholder word, one character repeated, or fewer than eight characters. */
    readonly values: readonly string[];
}
/** One character, three times or more, and nothing else: `xxxxxxxx`, `00000000` (a known vendor token prefix is set aside
 *  first, the env value view's `tokenHead`: `sk-xxxxxxxx`). The language of `/^(\S)\1{2,}$/u` — one code point that is
 *  no white space, repeated — read by comparing the text with that code point repeated, not by a back-reference loop: a
 *  regex engine keeps backtrack state per repetition, so a value of a few million characters would exhaust it. Exported
 *  for the checks that hold it to that language; not part of the package entry. */
export declare function isOneCharacterRepeated(text: string): boolean;
/**
 * THE one reading of an empty credential: a string with nothing but white space in it, the empty string included, is no
 * credential, whoever hands it and wherever it is handed. Every face that asks "was a credential handed at all" reads
 * this one: the withheld table's entry rule ({@link notACredentialReason}, its first answer), the engine's credential
 * intake ({@link holdOwnCredentialValues}: a blank value is not taken in and not said), the route law
 * (`route-adjudicator.ts`: a blank `apiKey` or a blank credential header is the keyless door — its source keeps its
 * rank, so no other source's credential rides in its place, and nothing of it goes out or is bound) and the memory
 * distiller's chat seat (a blank key is no key). White space is what `String.prototype.trim` removes.
 */
export declare function isBlankCredential(value: string): boolean;
/** {@link notACredentialReason}'s answer as a yes: the same guess for the second place that pays for withholding a string — every
 *  occurrence of a request's key taken out of a remote's words (`remoteWords`): a key that names no secret (`EMPTY`, a local gateway's
 *  one-letter key) is left in the words, as it is left to every child. */
export declare function namesASecret(value: string): boolean;
/**
 * THE one answer to "why is this value no credential value" — the member of {@link WithheldEnvJudgment.valueProblems} a value gets, word for
 * word, and the sentence {@link declareWithheldEnv} refuses a value by (`values[i] is not a credential value (got <this>)`; for a value whose reading
 * throws the declaration throws what that reading throws, where this function answers the words below).
 * `undefined` = it is one: a string a variable can hold (not the empty string, no NUL, no unpaired surrogate) that is not white space only, has at
 * least {@link CREDENTIAL_MIN_CHARS} characters once trimmed, is no flag or placeholder word and not one character repeated — so withholding every
 * variable that holds it takes no setting (`CI=1`, `FORCE_COLOR=true`) from a child. Otherwise a phrase (a value that is no string reads as its kind) that never
 * repeats the value; a value whose reading throws (a revoked Proxy) says so, in words that name no value. A host that is about to declare a credential it
 * derives from its own configuration (a header value, a token) asks this first and declares only what it answers `undefined` to (the declaration
 * still refuses a value that a variable this host hands every child holds: that part reads the environment, and this does not). Pure: it reads no
 * process state and never throws.
 */
export declare function credentialValueProblemOf(v: unknown): string | undefined;
/**
 * Declare the engine's own credentials in this process's environment — the engine's or its host's: an approval
 * bearer, a service token — by name and by value. From then on no child spawned on this host inherits one, whatever the
 * policy: every spawn site reads its environment through {@link inheritedHostEnv}, which subtracts from `"all"`, from the
 * scrub's result and from an allow list's every entry that is one of the engine's own credentials (each one present is a
 * finding of kind `own-credential`), and {@link inheritEnvPolicyProblem} refuses an allow list naming a declared name.
 * A NAME is compared as the platform compares variable names: exactly, but case-blind on Windows. A VALUE is compared
 * whole, as the same string: an entry holding it as a part (`Bearer <value>`, a URL, an encoding of it) is not its value.
 * Besides the declared values, every value the engine took in itself ({@link holdOwnCredentialValues}) is withheld the
 * same way. A variable a host hands a child itself (a shell's `shellEnv`, a per-exec `env`, a language server's `env`,
 * an MCP server entry's `env`) is its explicit grant and is not read against the table.
 *
 * Declared once, at start-up, before anything spawns; a later call REPLACES the declaration whole (a configuration
 * reload), read from the next spawn on — a spawn whose environment is already read (one announcing its findings) keeps
 * it; the values the engine took in stay. The lists are copied, and a value is kept only as a digest (no credential is
 * held by the table). A malformed table — not a plain object `{ names, values }` (the names-only list of earlier releases
 * included), a member besides those two, a list that is a Proxy or whose element throws while it is read, a name that
 * is no variable name or that the host hands every child anyway ({@link runtimeSuppliedEnv}), a value that is not a
 * string a variable can hold or is no credential ({@link notACredentialReason}: white space only, a flag or placeholder
 * word, one character repeated, fewer than {@link CREDENTIAL_MIN_CHARS} characters — withholding it would take a setting
 * such as `CI=true` from every child) or that is, in this process's environment now, the value of such a variable —
 * throws and leaves the declaration as it was. A value listed twice is the one value (the declaration is a set). No
 * refusal sentence repeats a value. A value refused as no credential is the one value the refusal names: the host was
 * told of it there, so the engine's intake ({@link holdOwnCredentialValues}) does not say it again.
 *
 * Two Windows readings, measured on a real machine: a withheld name that the child's own shell or runtime re-creates
 * with a DEFAULT of its own (`ComSpec`, `PATHEXT`, `HOME`, `CommonProgramFiles`, …) shows up in the child's table with
 * that default, never with this process's value — withheld, not leaked; and the disclosure (`detail.ownCredentials`)
 * spells each withheld name as this process's environment spells it, not as the declaration spelled it.
 */
export declare function declareWithheldEnv(table: WithheldEnvDeclaration): void;
/** What {@link judgeWithheldEnv} answers of one variable name, a closed set: `name` — a declared name (compared as the platform compares names);
 *  `value` — not declared by name, but its value in the environment is a declared credential value (compared whole); `none` — neither, so
 *  the declaration would not withhold it; `malformed_name` — no variable can have a name of this shape (empty, holding `=` or a NUL, an
 *  unpaired surrogate), so the question has no answer — asked apart, never read as `none`. (A name with white space is a possible variable:
 *  it answers `value` or `none`, never `name`, since a declaration refuses to name one.) */
export declare const WITHHELD_ENV_ANSWERS: readonly ["name", "value", "none", "malformed_name"];
export type WithheldEnvAnswer = (typeof WITHHELD_ENV_ANSWERS)[number];
/** What {@link judgeWithheldEnv} says of a declaration candidate. */
export interface WithheldEnvJudgment {
    /** The sentence {@link declareWithheldEnv} would throw for this candidate, word for word (it repeats no value; a stray member of the table
     *  is shown by its name, as the declaration shows it); absent when it would take it. */
    readonly refusal?: string;
    /** Per member of the candidate's `values`, in order: why that value is no credential value (a phrase that never repeats the value; a value
     *  whose reading throws says "a value that could not be read"), or `undefined` for one that is. Empty when the candidate was refused before its
     *  values were read (its shape, its names). */
    readonly valueProblems: readonly (string | undefined)[];
    /** What the declaration does to one variable of the environment judged against: see {@link WithheldEnvAnswer}. A refused candidate declares
     *  nothing, so every possible name answers `none`. */
    readonly answer: (name: string) => WithheldEnvAnswer;
}
/**
 * {@link declareWithheldEnv}'s judgment as a PURE function: what would happen if this candidate were declared in an environment that holds
 * `env` — the refusal it would meet, why each of its values is no credential, and, for any variable name, whether the declaration would
 * withhold it by name, by value or not at all. It reads no process state (not `process.env`, not the declared table, not the values the engine
 * took in; beyond the platform word that decides how names compare and the MCP SDK's list of variables it hands a child, the same list
 * the declaration reads) and writes none (it marks no value as said, declares nothing): a host's doctor
 * or configuration fold asks about a candidate before it declares, and `declareWithheldEnv` is the same reading over `process.env` followed by the
 * write, so the two cannot read a table differently. The values the engine itself holds (taken in at a brain's construction or a peer's dial) are
 * process state and no part of this judgment — they are withheld in addition, and a variable holding one answers `none` here. Names are compared
 * as this platform compares them (case-blind on Windows). `env` is copied once, at the call, as its own enumerable string entries (a later change
 * to it moves no answer); hand a plain record — an accessor on it runs at that copy, and what it throws goes one of three ways: a candidate
 * that carries values reads the environment while it is read, so the throw is the refusal (its message is the sentence — whatever the accessor's
 * code wrote, not one of the declaration's own; the real declaration never reads a variable it does not name); a candidate that
 * carries none reads it after, so the throw leaves the function as it was thrown; a candidate refused before that never copies it. `candidate` is whatever the host holds: a
 * value that is no table, a table the receipt refuses (a Proxy, a member that throws) or a value whose reading throws is answered as a refusal.
 */
export declare function judgeWithheldEnv(candidate: unknown, env: Readonly<Record<string, string | undefined>>): WithheldEnvJudgment;
/**
 * The engine takes in the variables a protocol peer's credential reference names — where the engine receives a declaration: the one
 * receipt of an MCP server or an A2A peer (`snapshotDeclaredEntry`, locked-config.ts), whose reference of kind `env` points, by its
 * `headers` and `env` maps, at variables of the resolver's environment. Such a variable is a token the engine holds FOR that peer, never
 * one a command needs: from then on, for the life of the process, the `"scrub"` policy withholds it BY NAME from every child spawned on
 * this host (a finding of kind `peer-held`) — whatever header carries it, whatever shape the seat's answer gives its value, before the
 * peer is ever dialled. `"all"` and an allow list hand it on as they hand on any variable (the value arm still withholds an entry whose
 * value the engine took in from the seat's answer, {@link holdOwnCredentialValues}). A name the environment does not hold withholds
 * nothing and is not said; a re-declaration ({@link declareWithheldEnv}) does not remove one. A variable the peer's own child needs reaches
 * it through the seat's answer (a stdio server's `env`), which no inheritance reads. A name some layer of this host hands every child
 * whatever the spawn passes ({@link runtimeSuppliedEnv}) is not taken in — the table's one entry rule for a name
 * ({@link peerHeldEntryRefusal}, which the host's declaration reads too), the one the own-credentials declaration refuses such a name by:
 * no reading can withhold it, so no finding may say it was withheld. The receipt does not refuse the declaration
 * for it (a refusal there would change which declarations are accepted); a seat that answers its value as a credential meets the value
 * intake's refusal at the dial ({@link holdOwnCredentialValues}). `entry` is how a sentence names the entry whose reference this is
 * (`MCP server "acme"`): kept beside each name, it is what the person's notice gives as the reason the name is held back
 * ({@link withheldEnvUserNotice}) to the person of a leg whose receipt took it in ({@link peerEntriesTakenIn}). The names are the
 * thread's (kept in their own slot, {@link PeerHeldNames}): a shell of another session or another Runner in this process is held back
 * from them too, and its notice says another entry in this process names the variable, without naming that entry.
 */
export declare function holdPeerHeldNames(names: Iterable<string>, entry: string): void;
/**
 * Why a name does not enter the table of variables held for a peer, a closed set: `handed_every_child` — some layer of this host hands
 * every child that variable from this process's environment whatever the spawn passes ({@link runtimeSuppliedEnv}: Node's
 * `NODE_V8_COVERAGE`, the MCP stdio transport's default inherited set — on POSIX `HOME LOGNAME PATH SHELL TERM USER` — and on Windows
 * libuv's required variables), so no reading can withhold it; `not_a_variable_name` — no variable has a name of this shape (empty,
 * holding `=`, a NUL or white space, an unpaired surrogate).
 */
export declare const PEER_HELD_ENV_NOT_TAKEN_REASONS: readonly ["handed_every_child", "not_a_variable_name"];
export type PeerHeldEnvNotTakenReason = (typeof PEER_HELD_ENV_NOT_TAKEN_REASONS)[number];
/** To whom a person's notice names the entry of a {@link declarePeerHeldEnv} declaration. */
export type PeerHeldEnvAudience = "every_leg" | {
    readonly isolationScope: string;
};
/** What {@link declarePeerHeldEnv} takes. */
export interface PeerHeldEnvDeclaration {
    /** The variables of this process's environment the entry's credential reference reads — names, never values. */
    readonly names: readonly string[];
    /** The entry whose reference reads them: its surface (`"mcp"` — an MCP server, `"a2a"` — an A2A peer; the closed set
     *  {@link ToolAxesSurface}) and its name as the host's configuration holds it, whatever it holds — a LABEL, never an identity: any string
     *  is taken (empty, white space at an end, a control character, any length), and its content never makes the declaration refused. It
     *  only tells the entry apart and names it, as the receipt names an entry it takes in: a sentence writes `MCP server "acme "` — quoted,
     *  escaped and folded to one line; a spelling longer than 80 characters (the opening quote counted) is cut to its first 80 and ends in
     *  `…`, and a name longer than 4096 UTF-16 units is spelled from its first 4096 alone (so any length costs the same; its spelling is
     *  always cut). Two names that read the same there are one entry. */
    readonly entry: {
        readonly surface: ToolAxesSurface;
        readonly name: string;
    };
    /** To whom a person's notice that one of these variables was held back names this entry. Absent — to no one: every leg's notice says
     *  another entry in this process names the variable (the narrowest, and the reading before this declaration existed).
     *  `{ isolationScope }` — to the legs whose isolation scope (`TaskSpec.isolationScope`, else `TaskSpec.principal`) is this one; a leg
     *  that names neither is in no scope and is never named to (a scope declared as `"default"` included). A delegated leg's notice is read
     *  at its tree's root, so it is named to only while it works in its delegation tree's domain (the one the root works in — a child the
     *  delegation tool starts does); a delegated leg with no tree domain, or outside it, never is. `"every_leg"` — to every leg
     *  of this thread: ONLY for an entry of the deployment itself, never one of a principal's — in a deployment of several principals it
     *  says the entry's name to every session. */
    readonly namedTo?: PeerHeldEnvAudience;
}
/** One name {@link declarePeerHeldEnv} did not take in, and why. */
export interface PeerHeldEnvNameNotTaken {
    readonly name: string;
    readonly reason: PeerHeldEnvNotTakenReason;
}
/** What {@link declarePeerHeldEnv} answers. */
export interface PeerHeldEnvReceipt {
    /** The names not taken in, in the order given, each with its reason ({@link PEER_HELD_ENV_NOT_TAKEN_REASONS}). Not a refusal: every other
     *  name was taken in. Empty when all were. */
    readonly notTaken: readonly PeerHeldEnvNameNotTaken[];
    /** The names this call took in that the table did not hold before, that this process's environment holds now, once a child has been
     *  spawned under the scrub in this thread: by the engine — a shell child of `NodeExecutionEnv` (a command — which may be adopted as a
     *  background shell — or a background shell), a language server of `NodeLspManager` or an oracle gate's command — from its spawn call
     *  on, whether or not the spawn later failed. Only ever true from then: such a child keeps the environment it started with, and one
     *  that has ended may have left a service holding it, so it says only "may still be in a child already started". A child under `"all"`
     *  or a list was handed these variables by its policy anyway; a read or a host's composition of an environment, a Runner built and the
     *  engine's own probes spawn no such child: none of them makes a name late. A child a host spawns itself counts once the host says so
     *  ({@link noteChildSpawned}). Empty otherwise. */
    readonly heldLate: readonly string[];
}
/**
 * Declare the variables a protocol peer entry of the HOST's references — an MCP server or an A2A peer whose credential reference reaches
 * the engine as an opaque handle (`handle` / `vault` / `assertion`), whose seat then reads these variables: the engine cannot see the
 * names, so the host says them. From then on, for the life of the thread, they are held exactly as the variables an `env` reference names
 * are held when the declaration receipt takes them in ({@link holdPeerHeldNames}) — the same table, the same entry rule: the `"scrub"`
 * policy withholds each one by name from every child spawned on this host (the model's shell, a background shell, a git probe, a language
 * server, a gate's command; a finding of kind `peer-held`); `"all"` and an allow list hand it on, as they hand on any variable.
 *
 * Only ever added to: a second declaration adds its names to what is held, an entry declared again is the same entry, and nothing — no
 * declaration, no {@link declareWithheldEnv} — removes a name for the life of the thread (an entry the host's configuration drops keeps
 * its names held until the process restarts: the narrower direction). `namedTo` only widens as well: the same entry declared to two
 * audiences is named to both.
 *
 * A name that is not taken in is ANSWERED, never refused: {@link PeerHeldEnvReceipt.notTaken}, each with its reason
 * ({@link PEER_HELD_ENV_NOT_TAKEN_REASONS}). A malformed declaration THROWS and takes nothing in: not a plain object, a member besides
 * `names`, `entry` and `namedTo`, `names` not an array (or a Proxy, or an element that throws while it is read, or an element that is not
 * a string), an `entry` that is not `{ surface, name }` over a surface of {@link ToolAxesSurface} and a string, a `namedTo` that is neither
 * `"every_leg"` nor `{ isolationScope }` over a name. The entry's name is never judged beyond being a string: a name the host's own mount
 * judge refuses (white space at an end, a control character, empty, too long) still declares that entry's variables — they are the peer's
 * all the same — and the entry is named by it as written ({@link PeerHeldEnvDeclaration.entry}). The audience's scope, by contrast, is an
 * identity a leg is compared by, so it must be a name.
 *
 * WHEN: at start-up, before the first child is spawned — it needs no Runner, and the table is made at its first use — and again at each
 * configuration change (only what is new takes effect). A child's environment is composed when it starts: a child already running keeps
 * what it started with, so a declaration made after such a child started may be late for it — {@link PeerHeldEnvReceipt.heldLate}
 * names what may be. Per THREAD, as {@link declareWithheldEnv}: a host that composes a child's environment in a worker declares there too.
 *
 * The two declarations, side by side: {@link declareWithheldEnv} — the engine's own credentials (names and values): withheld under EVERY
 * policy, an allow list naming one is refused, a finding of kind `own-credential`, each declaration REPLACES the last; this one — the
 * variables a peer's reference reads: withheld under the scrub alone, `"all"` and a list hand them on, a finding of kind `peer-held`,
 * only ever added to. A name neither can withhold: the first throws the whole table, this one answers it in `notTaken`. An entry: the
 * first has none; this one's is a label whose content never makes the declaration refused.
 */
export declare function declarePeerHeldEnv(declaration: PeerHeldEnvDeclaration): PeerHeldEnvReceipt;
/** The entries a receipt took in, per variable: the process's table's own shape ({@link PeerHeldNames}), but only the (variable, entry) pairs
 *  one receipt took in. */
export type PeerEntriesTaken = ReadonlyMap<string, ReadonlySet<string>>;
/**
 * Run a leg's receipt (`receive`, synchronous; runner/leg-receipt.ts) and collect the (variable, entry) pairs {@link holdPeerHeldNames} takes
 * in meanwhile: what that leg holds, the only pairs its person's notice names an entry for. An intake outside such a call (a host's own
 * materialization, another leg's receipt) is no leg's.
 */
export declare function peerEntriesTakenIn<T>(receive: () => T): {
    readonly value: T;
    readonly entries: PeerEntriesTaken;
};
/**
 * The engine takes credential values in — each where the engine receives it: a first-party brain's construction
 * credential (`brainConfigSnapshot`), a model entry's own credential headers (`resolveRouteCredential`), the credential
 * headers and variables a protocol peer's seat answers (`PeerCarrier`, before the answer is judged — a refused answer's
 * values are taken in too), the memory distiller's chat seat key (`openAiCompatChatSeat`,
 * and `RunnerDeps.memoryConsolidationDriver.chat` at `new Runner`, before that seat is built). From then on, for the
 * life of the process, no child spawned on this host inherits an entry whose value equals one: the same table, the same
 * subtraction, finding and disclosure as a declared value ({@link declareWithheldEnv}). A credential the engine is handed
 * per request (a per-model auth hook's answer) is not taken in: the host that resolves it owns it and declares it.
 * An absent or blank value ({@link isBlankCredential}) adds nothing and is not said: it is no credential, and no request
 * carries it (the route law reads a blank key as the keyless door). A value that is no credential otherwise
 * ({@link notACredentialReason}: a flag or placeholder word, one character repeated, fewer than
 * {@link CREDENTIAL_MIN_CHARS} characters — the key a local
 * gateway is told to be handed) is not taken in: its holder uses it as given (it is no bad value), and the variables
 * that hold the same string stay with every child. Said once per process per value, never the value, as the notice
 * `config.credential_not_withheld` through the engine's one notice throat ({@link deliverEngineNotice}): to `onNotice`
 * when the intake has the structured seat in hand (the `RunnerDeps` receipt at `new Runner`), else to the process's
 * default seat ({@link import("./engine-notice.js").setDefaultEngineNoticeSeat}) when a host installed one, else as that
 * notice's process line (the throat's own arm for an absent seat — a brain's construction, a request's route
 * reading, a peer's dial, a directly built distiller seat). A value the host's declaration refused as no credential
 * ({@link declareWithheldEnv}) was told in that refusal and is on the same account: not said again. A value that is, in this process's
 * environment now, the value of a variable every child is handed whatever the spawn passes cannot be withheld: the intake
 * throws (`config.invalid_argument`, the variable named, never the value) and takes nothing in — the brain is not built,
 * the peer is not dialed.
 */
export declare function holdOwnCredentialValues(values: Iterable<string | undefined>, onNotice?: (notice: EngineNotice) => void): void;
/** THE one reading of which HTTP header carries a credential by its NAME — the credential vocabulary's header-name
 *  reading ({@link isSensitiveHeaderName}: `Authorization`, `Proxy-Authorization`, `X-Api-Key`, Azure's `api-key`,
 *  `x-goog-api-key`, `Cookie`, any name holding a credential word; not a gateway's own spelling of a name the
 *  vocabulary declares non-secret, `cf-aig-cache-key` / `X-Idempotency-Key`). The reading of a record MEMBER's name
 *  (`isSensitiveRecordKey`), which decides what a record shows, takes those declared names whole only. Every face that
 *  asks "which header is a credential, by its name" reads this one: the withheld-value intake below
 *  ({@link credentialHeaderValues}) and the route law — which bag carries a credential, which header values a per-model
 *  credential's identity is read from, which headers the per-model winner strips, which the user-header merge leaves to
 *  that strip, which the run-static stream options refuse. The NAME is the shared half: the intake adds a half of its
 *  own, a value that looks like a credential under any name ({@link looksLikeCredentialValue}) — a guess it may make,
 *  because withholding a value from a child costs little; the route law does not, because a header it reads as a
 *  credential replaces the deployment's key and is bound to an origin, and a guess that is wrong drops a key that should
 *  have gone out. */
export declare function isCredentialHeaderName(name: string): boolean;
/** Whether a credential header's value is `<auth-scheme> <credentials>` by definition (RFC 9110 §11.6.2 / §11.7.2:
 *  `Authorization`, `Proxy-Authorization`) — the scheme word is public and the credentials part is the secret. Any other
 *  credential header's value is opaque, read whole. */
export declare function isSchemedCredentialHeader(name: string): boolean;
/** The credential values a header bag carries: each header whose name is a credential header ({@link isCredentialHeaderName})
 *  or whose value carries one ({@link looksLikeCredentialValue}), as written and, when it reads `<scheme> <credentials>`,
 *  its credentials part too — the spelling a variable copied from it would carry. A schemed header's
 *  ({@link isSchemedCredentialHeader}) value over a credentials part that is no credential (`Bearer 1`) gives that part
 *  alone — the engine's intake then does not take it in — and not the whole value, which carries nothing else. Any other
 *  header (`User-Agent`, `Accept`, a region) is no credential. */
export declare function credentialHeaderValues(headers: Readonly<Record<string, string>> | undefined): string[];
/** Test seam: never called by production code (a host re-declares `{ names: [], values: [] }`; what the engine took in stays). */
export declare function __resetWithheldEnv(): void;
/**
 * THE environment a child spawned ON THIS HOST inherits: the policy's arm, which under every policy withholds the engine's own
 * credentials — a declared name, or a value equal to a declared or engine-held credential value ({@link declareWithheldEnv},
 * {@link holdOwnCredentialValues}). The arms: `"scrub"` (and absent) is this process's environment through
 * {@link scrubSecretEnv} (the shape rules and the variables the engine holds for a protocol peer, {@link holdPeerHeldNames}, by name); `"all"` is this process's environment as written, less the credential names of the engine's own
 * namespace (the namespace rule, {@link isNamespaceCredentialName}, and none of the scrub's other rules); a `string[]` is exactly the
 * named variables that are set, as written — a strict allow list, so a name it leaves out (`PATH` included) is not
 * inherited, and one it names is handed on whatever its shape. `findings` collects every entry withheld, one each, under the first rule
 * that answers ({@link judgeInheritedEntries}: a shape rule, else `own-credential`, else `peer-held`).
 *
 * A policy {@link inheritEnvPolicyProblem} refuses throws that reason HERE, at every spawn, read against the
 * declaration as it stands: a value that is no policy at all (never read as the scrub), and an allow list naming a
 * declared own credential — whenever the declaration was made, so the refusal at spawn time is the invariant. The
 * spawn sites that take a policy (the tool shell's `NodeExecutionEnv` at construction, the oracle gate per gate) also
 * ask first, so a host that declared before building them hears it at start-up.
 */
export declare function inheritedHostEnv(policy: InheritEnvPolicy | undefined, findings?: SecretEnvFinding[]): NodeJS.ProcessEnv;
/** Whether a policy composes by the scrub's arm (`"scrub"`, and absent): the one reading {@link policyArm} composes by and a spawn is
 *  recorded by. Each site reads it off one value: a shell start off its kept `inheritEnv`, read again right after the spawn call
 *  returns (not the value its composer read); an oracle gate off the one value its composition read. */
export declare function composedUnderScrub(policy: InheritEnvPolicy | undefined): policy is "scrub" | undefined;
/** THE one writer of "a child has been spawned under the scrub in this thread" — the question {@link PeerHeldEnvReceipt.heldLate} asks
 *  ("may a child already started hold this name"): `underScrub` is {@link composedUnderScrub} of the site's one reading of the policy
 *  (a shell start: its environment's kept policy, read after the spawn call returns; an oracle gate: the value its composition read).
 *  Only ever set: a child that has closed may have left a service holding the same environment behind (a background shell that starts
 *  a daemon and exits), so no end is read. Called by the site that made the spawn call, right after the call returns — the environment
 *  is the child's from that call on, whether or not the child then starts (a shell, a language server or an oracle gate's command whose
 *  program is not found records too); a call that throws at once records nothing. Takes no policy and never throws (the caller's own
 *  reading of the policy is outside it): a slot a host made unwritable (frozen, not extensible, a setter that throws) takes no record
 *  and keeps what it held — "not yet" when nothing was recorded before it was made so, "spawned" when something was. */
export declare function recordChildSpawned(underScrub: boolean): void;
/**
 * Say that THIS HOST spawned a child of its own with an environment composed under `policy` ({@link hostChildEnv},
 * {@link inheritedHostEnv}): from then on {@link PeerHeldEnvReceipt.heldLate} counts it, as it counts the engine's own children (a slot
 * the host made unwritable before any record takes none, without an error: {@link recordChildSpawned}). Call it right after the spawn
 * call, with the policy that child's environment was composed under, in the thread that spawned it (a worker has its own table).
 * `"scrub"` and absent record; `"all"` and an allow list record nothing (a later declaration withholds nothing from their child: `"all"`
 * hands on every variable, a list the ones it names). Composing or reading an environment records nothing.
 *
 * A value that is no policy THROWS `noteChildSpawned: <why>` and records nothing — judged before anything is written, as a declaration is:
 * a string other than `"scrub"` and `"all"`, a value of another kind (a table such as `{ policy }` included), a list holding an element
 * that is no variable name (a hole included, read by index as `undefined` unless the list's prototype supplies it), a list whose element
 * throws while it is read, and a Proxy. The judgment uses the language's own tests and one read of the list by index into an
 * engine-owned copy: no method or trap of the value's own runs (an accessor element is read once, as that copy reads it). The sentence
 * names the value's kind (a string by its length), never the value.
 */
export declare function noteChildSpawned(policy: InheritEnvPolicy | undefined): void;
/** What a child spawned on this host starts with ({@link hostChildEnv}), and the inherited entries it does not receive:
 *  the inheritance's findings less every name the composed environment sets (a grant's entry is the host's, never a loss). */
export interface HostChildEnv {
    readonly env: NodeJS.ProcessEnv;
    readonly withheld: readonly SecretEnvFinding[];
}
/** What the inherited part of a host child's environment is read from, past the policy alone ({@link hostChildEnv}'s
 *  first argument as a table; a bare policy reads as `{ policy }`). */
export interface HostChildInheritance {
    /** How much of the base a child inherits — the {@link InheritEnvPolicy} (absent: `"scrub"`). */
    readonly policy?: InheritEnvPolicy | undefined;
    /** The settings file's `env` block: laid over this process's environment BEFORE the policy reads it, so it is part of
     *  the base — read by the same arm and the same own-credentials judgment as every other inherited entry (by name and
     *  by value), its withheld entries accounted with `layer: "settingsEnv"`. A name it sets wins over this process's
     *  variable of that name (compared as the platform compares names, the value under the spelling the process has);
     *  an `undefined` value unsets it. A grant laid after the inherited part wins over it. Absent: the base is this
     *  process's environment, exactly. Read once, as a grant is read; a bad one is refused as a bad grant is. */
    readonly settingsEnv?: Readonly<NodeJS.ProcessEnv> | undefined;
}
type EnvEntries = readonly (readonly [string, string | undefined])[];
/** Why one environment layer — a grant (`label` = `env grant <n>`) or the settings layer (`settingsEnv`) — is not an
 *  object of variable names to strings, or its entries: read once, as a spread reads it (own enumerable entries). A bad
 *  name is not repeated and no value is: either may hold a credential. */
export declare function readEnvLayer(layer: unknown, label: string): EnvEntries | string;
/** Why {@link hostChildEnv} would refuse these inputs, or `undefined` — the same judgment. It takes the table (or a bare policy), so
 *  `{}` reads as `scrub`; to judge one policy value alone — a configuration field — use {@link inheritEnvPolicyProblem}. It answers a
 *  sentence for every input the judgment can read; a caller's own getter or list element that reads once and throws on a later read
 *  reaches the caller as thrown. */
export declare function hostChildEnvProblem(inherit: unknown, ...grants: readonly unknown[]): string | undefined;
/**
 * THE environment a child spawned ON THIS HOST starts with: the inherited part — this process's environment, with the
 * settings layer laid over it when `inherit` is a table carrying `settingsEnv` ({@link HostChildInheritance}), read by the
 * policy's arm, less the engine's own credentials — then each grant in order (a later grant's value wins, names compared
 * as the platform compares them; an `undefined` value unsets). A bare policy is `{ policy }`: the base is this process's
 * environment ({@link inheritedHostEnv}). The tool shell's children (the run's `inheritEnv` is its policy) and a local
 * language server (`"scrub"`, the host's `NodeLspManagerOptions.env` as its grant) are composed here. So can a host's own
 * executor for a settings command hook, which this package does not run: the settings file's `env` block is its
 * `settingsEnv` (never a grant: a grant is not read against the declaration), the hook's own variables its grant, and the
 * policy its own (`inheritEnv` is not applied to a hook's child). An own credential is never inherited, whichever layer
 * of the base carries it; a grant is the host's explicit act and is not read against the declaration. A table with a
 * member besides `policy` and `settingsEnv` (or that is a Proxy, not a plain object, or whose member throws while read), a
 * layer that is not an object or throws while read, a name that is empty or holds `=`, NUL or an unpaired surrogate,
 * and a value that is not a string or holds NUL or an unpaired surrogate throw, as a refused policy does
 * ({@link hostChildEnvProblem}).
 */
export declare function hostChildEnv(inherit: InheritEnvPolicy | HostChildInheritance | undefined, ...grants: readonly (Readonly<NodeJS.ProcessEnv> | undefined)[]): HostChildEnv;
/** Why `value` is not an {@link InheritEnvPolicy} this deployment can read (absent counts as one — the scrub), or
 *  `undefined` when it is: a malformed policy, or an allow list naming one of the declared own credentials
 *  ({@link declareWithheldEnv}, compared as it says). */
export declare function inheritEnvPolicyProblem(value: unknown): string | undefined;
/** The declaration half of {@link inheritEnvPolicyProblem}, for a value whose shape is a policy: the first entry of an allow
 *  list that names one of the declared own credentials, and the sentence refusing it; `undefined` for a word, or a list
 *  naming none. A judged list can only turn up here after a declaration made since it was judged. */
export declare function declaredInheritEntry(value: unknown): {
    index: number;
    name: string;
    refusal: string;
} | undefined;
/** Test seam: never called by production code. */
export declare function __resetSecretEnvScrubNoticeAnnouncement(): void;
/** What both disclosures say about one set of findings: every withheld name, and those that are the engine's own
 *  credentials — withheld under every policy — whatever kind a finding says ({@link ownCredentialJudge}, the
 *  composition's own judgment, over the entry's value in this process's environment: every finding names an entry of
 *  it). The rest the policy withheld: an allow list naming them hands them on, and so does `"all"` — except the names of the
 *  engine's own namespace ({@link isNamespaceCredentialName}), which `"all"` withholds too. */
export declare function withheldEnvNames(findings: readonly SecretEnvFinding[]): {
    names: string[];
    ownCredentials: string[];
};
/**
 * The ONE disclosure point for a scrub's withheld keys. Routed through {@link deliverEngineNotice} — the
 * engine's one notice throat — so a wired `onNotice` seat REPLACES the console line exactly as every
 * other `EngineNotice` does, and an absent seat (no default seat installed) prints the same words as one process line.
 * `detail` is {@link withheldEnvNames}: `names` every withheld key, `ownCredentials` (present only when one was
 * withheld) the subset that is the engine's own credentials. Once per PROCESS, never per call or per site; an
 * EMPTY findings array is a no-op.
 */
export declare function announceSecretEnvScrub(onNotice: ((notice: EngineNotice) => void) | undefined, findings: readonly SecretEnvFinding[]): void;
/**
 * The ways out `inherit_env.names_withheld` carries as data (`detail.remedies`, the member family `delegation.ask_unresolvable`
 * already uses for its ways out: a list of `{ kind }` objects over a closed set, absent when there is no way out) — one kind per
 * way the engine has today: `inherit_env` — the run's `inheritEnv` (a list naming the variable, or `"all"`) hands on the variables
 * the credential scrub held back, which is the `names` that are not `ownCredentials` (the engine's own credentials have no way
 * out: no policy hands them on, so a `withheld` notice whose names are all its own carries no `remedies`); a name of the engine's
 * own namespace (a finding of kind `namespace-rule`) is handed on by a list naming it, not by `"all"`, which withholds it too;
 * `execution_environment` — the environment did not say what it withholds (`state: "unknown"`), so the variable a command finds
 * unset is set in the execution environment itself. A host renders the kind in its own language; the notice's sentence says the
 * same in English.
 */
export declare const WITHHELD_ENV_REMEDY_KINDS: readonly ["inherit_env", "execution_environment"];
export type WithheldEnvRemedyKind = (typeof WITHHELD_ENV_REMEDY_KINDS)[number];
/** One way out of {@link WITHHELD_ENV_REMEDY_KINDS}, as `detail.remedies` carries it. */
export interface WithheldEnvRemedy {
    readonly kind: WithheldEnvRemedyKind;
}
/** The `InheritEnvPolicy` forms a host may declare its callers can write (`ExecutionEnv.inheritEnvForms`). */
export declare const INHERIT_ENV_FORMS: readonly ["scrub", "all", "list"];
export type InheritEnvForm = (typeof INHERIT_ENV_FORMS)[number];
/** Reads a host-declared `inheritEnvForms` value (`undefined` = undeclared, else a plain array of distinct words of {@link INHERIT_ENV_FORMS}). */
export declare function readInheritEnvForms(value: unknown): {
    readonly ok: true;
    readonly forms: readonly InheritEnvForm[] | undefined;
} | {
    readonly ok: false;
    readonly valueType: string;
};
/**
 * The session user's half of the same fact, from the execution environment's `withheldEnv`: the notice telling the
 * person whose run drives a tool shell which variables of the engine's environment that shell does not receive — names
 * only, never a value, split as {@link withheldEnvNames} splits them, with the way out for each half (`detail.state`
 * `"withheld"`); or, when the environment answered `"unknown"`, that the engine could not determine them (`"unknown"`,
 * no names: an empty list never stands for unknown). `undefined` when nothing is withheld. Minted by the Runner
 * (`runner/shell-env-withheld.ts`). The sentence says what happened, that it is a protection asking nothing of the person,
 * and the one thing to do if a command needs a withheld variable (the engine's own credentials: nothing hands them on; a name
 * the namespace rule caught: a list naming it, or the host's explicit grant, does, and the sentence says `"all"` does not; a name a
 * protocol peer's credential reference named: the entry that names it is the reason, named when the leg whose shell this is took in that
 * variable and entry at its receipt — `mine` — or the host declared that entry to an audience the leg is in — its `isolationScope`, read
 * against `deliveredScope`, the scope of the root a delegated leg's notice is delivered to ({@link noticeReaderScope}) — {@link peerHeldHalf}).
 * When `inheritEnvForms` is supplied, the sentence's inheritance forms are restricted to that declared subset (`detail.remedies` is unchanged).
 */
export declare function withheldEnvUserNotice(...args: Parameters<typeof mintWithheldEnvUserNotice>): EngineNotice | undefined;
/** {@link withheldEnvUserNotice}'s notice, and `fact`: what that telling is about, the key of the session's once-per-session record
 *  (`runner/shell-env-withheld.ts`) — the state; each withheld name under the reason the sentence gives it (with the entries it names
 *  for a peer's), sorted; the ways out the sentence offers (a list, `"all"`; absent when no name has one); the delegated leg it names.
 *  The wording is not in it: a sentence that reads differently about the same facts is the same telling. */
export interface WithheldEnvUserNoticeMint {
    readonly notice: EngineNotice;
    readonly fact: string;
}
export declare function mintWithheldEnvUserNotice(withheld: readonly SecretEnvFinding[] | "unknown", at: {
    sessionId: string;
    runId?: string | undefined;
    sourceSessionId?: string | undefined;
    agentId?: string | undefined;
}, mine?: PeerEntriesTaken, isolationScope?: string, deliveredScope?: string, inheritEnvForms?: readonly InheritEnvForm[]): WithheldEnvUserNoticeMint | undefined;
export {};