UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

82 lines (81 loc) • 6.73 kB
/** * Why a person's stored permission rules could not be read — the ONE cause vocabulary, its ONE reader and the sentences * that say it. * * The rule store refuses a read with an error that carries its kind: the code (`permission_rules.bucket_damaged` / * `bucket_unreadable` / `later_grammar`, {@link PERMISSION_RULES_DAMAGED_BUCKET_CODE}…), the system error's name (`errno`) and, * for a store directory the engine refuses to use, which way it is unsafe (`unsafe`: `"permissions"` — writable by group or * others — or `"owner"` — another account's). {@link ruleStoreFaultReasonOf} is the only place those members are read into a * word; every sentence and every notice member below is a projection of that word, so no consumer reads a refusal's prose. * * A fault names the partition(s) of the person's rules it took out (`sources`: the durable partition is the `user` and `project` * sources, the session partition the `session` source) and a reason. It carries no path: where the store lives is the operator's * disclosure line's, never a user's. */ /** * The causes a read of the person's rules fails for — each one has its own clause and its own way out below. * * Four of them are the FILE store's words: `not_readable` and `read_failed` (the code `bucket_unreadable`), `unsafe_permissions` and * `owner_mismatch` (the code `bucket_damaged` with its `unsafe` member) say "the folder or file that holds them". A store that is no * file — a host's own — states only the causes that are true of it (`damaged` when the rules it serves are not in a form this engine * reads, `no_answer`, `unclassified`, `later_grammar`): a store that stamps one of the four gets the sentence of a store that is a file. */ export declare const RULE_STORE_FAULT_REASONS: readonly ["not_readable", "read_failed", "unsafe_permissions", "owner_mismatch", "damaged", "later_grammar", "no_answer", "unclassified"]; export type RuleStoreFaultReason = (typeof RULE_STORE_FAULT_REASONS)[number]; /** The sources of the person's rules a partition serves (`org` is not a personal source and has its own status). */ export type RuleStoreSource = "user" | "project" | "session"; /** One read failure of one or more partitions of the person's rules. */ export interface RuleStoreFault { /** The sources whose rows this failure took out of the read, in `user`, `project`, `session` order (empty = not said). */ readonly sources: readonly RuleStoreSource[]; readonly reason: RuleStoreFaultReason; } /** How a store directory the engine refuses to use is unsafe, as the file store states it on the refusal it throws (an own member * beside `code` and `errno`): `permissions` — writable by group or others; `owner` — owned by another account. Absent for any * other refusal. */ export type RuleStoreUnsafe = "permissions" | "owner"; /** * The reason a store's refusal stands for — the one reading of its `code`, `errno` and `unsafe` members: * · `later_grammar` — a newer engine wrote the bucket; * · `bucket_unreadable` — the system refused or failed the read: `EACCES` / `EPERM` is `not_readable` (a permission), any other * error `read_failed`; * · `bucket_damaged` — `unsafe_permissions` / `owner_mismatch` where the refusal says which way the directory is unsafe, else * `damaged` (a link, a file that is not a regular file, bytes that are not a rule file); * · anything else — a store that states no code of ours — `unclassified`. * `no_answer` is not a refusal's: a read that did not answer in time has no error to read, and the reader that waited says it. */ export declare function ruleStoreFaultReasonOf(err: unknown): RuleStoreFaultReason; /** The sources in words (`user`, `user and project`, `user, project and session`). */ export declare function ruleStoreSourcesWord(sources: readonly RuleStoreSource[]): string; /** * The run's `permission.rule_store_unavailable` sentence (audience: the person): which partition, why, what it costs meanwhile, and * what to repair. No path. `relaxedMode` names the leg's mode when it answers the class unasked (so the cost clause states only what * that mode does — the unread rules by themselves do not make the engine ask, under `auto` the classifier judges such a call, retained * deny/ask rows still apply, and a deny rule saved since may not be in force); `undefined` otherwise (every call asks a person until a * read succeeds). */ export declare function ruleStoreUnreadableNoticeSentence(at: "prepare" | "call", faults: readonly RuleStoreFault[] | undefined, relaxedMode: string | undefined): string; /** * The `permission.rule_store_unreadable_relaxed` sentence (audience: the operator): the same partition, cause and repair, where the leg's * permission mode answers the class of the unread rules with nobody asked — the person is told by their own notice, and until a read * succeeds only the deny and ask rows of the last read that succeeded apply (under `auto` the classifier judges such a call, and a * no-ruling result or a retained ask row may still put it to a person). With `rows`, the fact is that many rows of the rules whose rule * itself could not be read: the calls they may reach are released alike, while every other row applies as read. */ export declare function ruleStoreUnreadableRelaxedSentence(mode: string, at: "prepare" | "call", faults: readonly RuleStoreFault[] | undefined, rows?: number): string; /** * The store form's ask message — the sentence the approval card carries and, when nobody can be asked, the sentence the model reads as * the call's result. Names the partition and the cause, no path; tells the model what to do instead of retrying. */ export declare function ruleStoreUnreadableAskSentence(faults: readonly RuleStoreFault[] | undefined): string; /** The identity of a fault set — what "the same thing said again" means for the person: each fault's sources and reason, order-free. */ export declare function ruleStoreFaultsKey(faults: readonly RuleStoreFault[]): string; /** Whether a value is a reason of the closed set. */ export declare function isRuleStoreFaultReason(value: unknown): value is RuleStoreFaultReason; /** * A fault list a lane or a foreign store handed over, read once: a plain array of plain records whose `sources` are members of * {@link RuleStoreSource} and whose `reason` is in the closed set — rebuilt from the values read, never the object given. Anything else * reads as no faults (`undefined`): the sentences then say the cause is not given, and what the answer meant (an unreadable store) does * not change. */ export declare function readRuleStoreFaults(value: unknown): readonly RuleStoreFault[] | undefined;