@sema-agent/core
Version:
Stateless, task-oriented AI agent core
62 lines (61 loc) • 4.87 kB
TypeScript
/**
* The consolidation driver's write judge — the seat `runMemoryConsolidationDriver` asks (for the library directory before it
* claims anything, then for each file a commit lands) — minted by ONE constructor, {@link createConsolidationWriteJudge}, for
* every caller: the Runner's auto lane (a leg, with every layer a model's own `Write` meets on it) and a host's own
* consolidation valve (no leg: its rule store, the person, the local-owner declaration, its caller policy). The judgment is
* `createSyntheticWriteJudge`'s over the person's and the org's rows read through the gate's own lanes; nothing here judges.
* Beside it, the refusal's notice dialect ({@link deliverWriteRefusal}).
*/
import { type SyntheticReadLayers, type SyntheticWriteFacts } from "../synthetic-read-verdict.js";
import { type ConsolidationWriteJudge } from "../memory-engine/consolidation-driver.js";
import { type EngineNotice } from "../engine-notice.js";
import type { PermissionRuleStoreProvider } from "../permission-rule-provider.js";
import { type ToolPolicy } from "../tool-policy.js";
import type { ExecutionEnv } from "../../internal/harness-types.js";
import { createPermissionRuleLanes } from "./permission-rule-lanes.js";
/** What every caller states: the layers a host has. */
export interface ConsolidationWriteJudgeInput {
/** The deployment's permission-rule store (`RunnerDeps.permissionRuleStore`): the person's standing rows and the org's. */
ruleStoreProvider?: PermissionRuleStoreProvider;
/** Whose rows are read: the principal the library belongs to. Absent or empty ⇒ the anonymous floor (no personal row),
* or the local owner's bucket where `localOwnerDeclared`. */
principal?: string;
/** `RunnerDeps.localOwnerRules`: a declaration a store cannot honor is refused at construction, loudly. */
localOwnerDeclared?: boolean;
/** The deployment's caller policy (`RunnerDeps.toolPolicy`), asked with a live signal and a request that states nobody can
* be asked about it (`ToolCallRequest.approvalReach: "none"`) — never an approver. */
callerPolicy?: ToolPolicy;
/** The session the person's session-scoped rows are read under. Absent ⇒ the judgment is no session's: no session row applies. */
sessionId?: string;
/** Where the person's relative and `~/` rows anchor: the project root (also which project rows apply) and the home. Absent ⇒
* such a row cannot be anchored, and a deny or ask it holds is an OBJECTION (fail closed) — the judge never guesses where a
* row would have pointed. */
anchors?: {
root?: string;
home?: string;
};
/** The environment the library's paths and the rows' heads resolve in — the one a leg of this deployment judges in (links
* followed both ways: a row spelled through a link binds the target's real location, a target spelled through one is judged
* where it leads). Absent ⇒ the engine process's own filesystem, where an in-process file backend writes the library. */
executionEnv?: ExecutionEnv;
}
/** What a leg adds — the Runner's prepare passes it; a host has none of it. */
export interface ConsolidationWriteJudgeLeg {
/** The leg's reader of the person's rows, one the run's cut does not end (the judge is asked after the run). */
rows: Parameters<typeof createPermissionRuleLanes>[0]["rows"];
/** The leg's facts the lanes judge against: its session, root and anchors, its resolution of rule heads, its sinks. */
lanes: Omit<Parameters<typeof createPermissionRuleLanes>[0], "provider" | "localOwnerDeclared" | "principal" | "rows">;
/** The layers only a leg has: its skill rows, its narrowing fold, the live inherited policies, its target stamp. */
layers: Omit<SyntheticReadLayers, "callerPolicy" | "persistedRuleLane" | "orgRuleLane" | "signal">;
/** The facts a live write carries on the leg, read at each judgment. */
facts: () => SyntheticWriteFacts;
}
/**
* The consolidation write judge: each target the run asks about is put, as one `Write` of that path under a deadline of its
* own, to the synthetic Write judge over the caller policy, the person's and the org's rows (the gate's own lanes over a
* reader of the store) and whatever layers `leg` adds. The answer is the judge's, unchanged. A host passes `input` alone; the
* engine's leg passes the same `input` and its `leg`, so the same rows give the same answer on both.
*/
export declare function createConsolidationWriteJudge(input: ConsolidationWriteJudgeInput, leg?: ConsolidationWriteJudgeLeg): ConsolidationWriteJudge;
/** Deliver a write-judge refusal as the verb's refusal notice; false (nothing delivered) for any other error. */
export declare function deliverWriteRefusal(err: unknown, scope: string, onNotice: ((notice: EngineNotice) => void) | undefined): boolean;