UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

94 lines (93 loc) • 7.4 kB
/** * The `sharedArtifactReads` setting: whether reading an artifact another person shared with this user asks first. * * One rule: the first of the organization's (`managed`) and the user's own (`user`) layers that states a value decides — a word * of the set as written, anything else `ask` — and unset everywhere is `ask`; a project's or a checkout's local settings (`repo`) * have no vote. Every stated value not in force is named on `config.entries_not_applied` (kind `setting_not_applied`). * * - The layers are the ones `crossSessionInbound` takes (`managed`, `user`, `repo`), so a host hands both settings from the same * reading of its settings files; a layer's value is its object's OWN member (`undefined` / `null` = unset), each read once. A * `repo` value never decides — a file that arrives with a cloned repository must not stop the questions of whoever opens it — and * is only quoted, to be named. * - What `allow` answers is the Artifact tool's own consent question on a shared target (wherever the tool asks it: `read`, * `list_files`, `read_file`, and a publish conflict's snapshot): yes, with nobody asked, under every permission mode (`dontAsk` * included — there is no question left for it to refuse). Nothing else moves: the gate's rules on the tool (a person's or the * organization's deny or ask) and its hooks still speak before the tool runs, and the read-deny tables, the credential floor a * published local file is read through, and the read face of the file tools are each judged where they were. * * Bad values, each with its way out: a value that is no word of the set (garbage, a boolean, a number, any other spelling — a * two-word set has no range to exceed) ⇒ `unrecognized`, and `ask` where its layer decides; a value in `repo` ⇒ `layer_not_read`; * the user's word where the organization's layer decided ⇒ `organization_decides` (when it differs from the word in force). * * One reading per run: a root leg reads the seat once at its prepare; a leg an engine lane bears now (a delegated child in the * foreground, in the background, a fork, an observer) holds the reading of the leg that spawned it, carried on its inherited chain * (`InheritedGate.sharedArtifactReads`, accepted on such a leg only — a root leg reads the seat whatever its internals carry). Every * wake is a run of its own and reads the seat again: a retained teammate's wake, a teammate SendMessage revives from its stored row * (tier 3), a checkpoint resume. A leg passes on the reading it holds (read or received) even where its own Artifact seat is not valid; * only a leg that holds none and reads none hands none down, and its child reads the seat itself. * * The notice: on every leg that read the seat (a root leg or a woken one) whose Artifact tool mounts, once per session per entry set * (while the announce ledger holds it), addressed as the leg's other notices are; of a `repo` list only the first 16 places are looked * at, and how many more there are is said (`repoNotLookedAt`). Each entry: * `entry` (the value as written, bounded), `setting` (`"sharedArtifactReads"`), `layer` (`managed` / `user` / `repo`), `reason`; * frame members `inForce` (the word in force) and `decidedBy`; routing `sessionId` (plus `sourceSessionId` / `agentId` on a delegated * leg), `runId?`. The seat's getter, or a layer * member's accessor, that throws fails the prepare; a value that * throws while it is quoted is named by a placeholder. */ import { type EngineNotice } from "./engine-notice.js"; import type { LegNotice, NoticeAddress } from "./leg-identity.js"; /** The words of `sharedArtifactReads`: `ask` (the engine default — the tool's consent question is put as without the setting) and `allow`. */ export declare const SHARED_ARTIFACT_READS_SETTINGS: readonly ["ask", "allow"]; export type SharedArtifactReadsSetting = (typeof SHARED_ARTIFACT_READS_SETTINGS)[number]; /** The setting's values as a host read them from its settings files, one member per layer (`unknown`: the engine reads them). */ export interface SharedArtifactReadsLayers { /** The organization's layer: decides whenever it states a value. */ managed?: unknown; /** The user's own layer: decides where the organization's states none. */ user?: unknown; /** A project's and a checkout's local settings: no vote for this key; any value there is named as not applied. */ repo?: readonly unknown[]; } /** Which layer decided: `default` = neither stated a value; `unreadable` = the deciding layer's value is no word of the set. */ export type SharedArtifactReadsDecidedBy = "managed" | "user" | "default" | "unreadable"; /** Why an entry did not apply — the `reason` of a `setting_not_applied` entry. */ export declare const SETTING_NOT_APPLIED_REASONS: readonly ["unrecognized", "layer_not_read", "organization_decides"]; export type SettingNotAppliedReason = (typeof SETTING_NOT_APPLIED_REASONS)[number]; export interface SettingNotApplied { readonly layer: "managed" | "user" | "repo"; /** What was written, as a bounded quotation (a string as is, anything else its JSON or `String` form, or a fixed placeholder). */ readonly entry: string; readonly reason: SettingNotAppliedReason; } /** The resolution: `allow` is only ever a layer's own word (`managed` or `user`), so the pair is a union by `value`. */ export type ResolvedSharedArtifactReads = ({ readonly value: "allow"; readonly decidedBy: "managed" | "user"; } | { readonly value: "ask"; readonly decidedBy: SharedArtifactReadsDecidedBy; }) & { /** Every entry that did not apply, in layer order (managed, user, repo). */ readonly notApplied: readonly SettingNotApplied[]; /** How many places of a `repo` list past the first {@link REPO_SHOWN} were not looked at; absent when there are none. */ readonly repoNotLookedAt?: number; }; /** The one reading of the setting's layers (no I/O; each layer's member is read once). */ export declare function resolveSharedArtifactReads(layers: SharedArtifactReadsLayers | undefined): ResolvedSharedArtifactReads; /** The layers a deployment's seat hands (a value or a getter read once per prepare). */ export declare function sharedArtifactReadsLayersOf(seat: SharedArtifactReadsLayers | (() => SharedArtifactReadsLayers | undefined) | undefined): SharedArtifactReadsLayers | undefined; /** The notice for a resolution with entries that did not apply (`undefined` when every entry applied). */ export declare function sharedArtifactReadsNotice(r: ResolvedSharedArtifactReads, ids: NoticeAddress & { runId?: string; }): EngineNotice | undefined; /** Say the resolution's not-applied entries once per conversation per set, on every leg that read the seat (the caller calls it only * there: a leg holding a handed reading read nothing), addressed and admitted as the leg's notices are (`legNotice`: its own session on * a top-level leg, the tree's root naming the leg on a delegated one — whose digest names its own session, as a fork starts with its * parent's record). */ export declare function announceSharedArtifactReads(r: ResolvedSharedArtifactReads, input: { onNotice?: (n: EngineNotice) => void; oncePerSession?: (digest: string, deliver: () => void) => void; legNotice: Pick<LegNotice, "route" | "admission">; runId?: string; }): void;