UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

55 lines (54 loc) • 4.26 kB
export const CORRUPT_SESSION_FORMS = Object.freeze(["no_header", "bad_cell", "bad_entry", "leaf_missing", "floor_missing", "parent_missing", "parent_loop", "kept_start_missing", "cut_point_missing"]); const FORM_SET = new Set(CORRUPT_SESSION_FORMS); export function isCorruptSessionForm(v) { return FORM_SET.has(v); } export const CORRUPT_SESSION_WAYS = Object.freeze(["continue", "rewind"]); export const CORRUPT_SESSION_DELETE_DOORS = Object.freeze(["owner", "operator"]); const ways = (...kept) => Object.freeze(kept); const doors = (...by) => Object.freeze(by); export const CORRUPT_SESSION_WAYS_OUT = Object.freeze({ no_header: { ways: ways(), deleteBy: doors("operator") }, bad_cell: { ways: ways(), deleteBy: doors("operator") }, bad_entry: { ways: ways(), deleteBy: doors("owner", "operator") }, leaf_missing: { ways: ways(), deleteBy: doors("owner") }, floor_missing: { ways: ways(), deleteBy: doors("owner") }, parent_missing: { ways: ways("rewind"), deleteBy: doors("owner") }, parent_loop: { ways: ways("rewind"), deleteBy: doors("owner") }, kept_start_missing: { ways: ways("rewind"), deleteBy: doors("owner") }, cut_point_missing: { ways: ways("continue", "rewind"), deleteBy: doors() }, }); const DOOR_CLAUSE = { owner: { offered: "delete it through its owner's delete and start a new session", absent: "this store offers no owner's delete, so no door of the engine removes the row: clear it in the store itself and start a new session", }, operator: { offered: "delete it through the deployment operator's door (the owner's doors refuse it) and start a new session", absent: "the owner's doors refuse it and this store offers no operator's door for an unreadable row, so no door of the engine removes it: clear it in the store itself and start a new session", }, }; const SENTENCE = { no_header: (say) => `The log has no header its store wrote, so nothing in it reads as a session: ${say.operator}.`, bad_cell: (say) => `A cell of the row's header (the owner, the occupant token, the placement) holds a value this build cannot read as a legal one, so the row is refused rather than read as someone else's or as no one's: ${say.operator}.`, bad_entry: (say) => `An entry of the log cannot be read as an entry, so the log cannot be opened as a session. When the row's head reads, ${say.owner}, or have the deployment repair the entry the refusal names; when the head read itself is refused with this word, ${say.operator}.`, leaf_missing: (say) => `The log's leaf names an entry the log does not hold, so the session cannot be opened at all (resuming at an earlier entry meets the same refusal): ${say.owner}.`, floor_missing: (say) => `The store woke a bounded window whose floor entry the loaded part of the log does not hold, so the session cannot be opened: ${say.owner}.`, parent_missing: (say) => `An entry names a parent the log does not hold: resume at, or fork from, an entry whose path to the root does not pass the break; when there is none, ${say.owner}.`, parent_loop: (say) => `The parent links loop back on themselves: resume at, or fork from, an entry whose path to the root does not reach the loop; when there is none, ${say.owner}.`, kept_start_missing: (say) => `A compaction names a first-kept entry that is not on its branch: resume at, or fork from, an entry before that compaction; when there is none, ${say.owner}.`, cut_point_missing: () => "The log lost the entry the parked checkpoint was cut at, so that checkpoint cannot resume; the session itself reads: give up the parked step (expire the checkpoint) and continue the session with a new task, or resume at an earlier entry.", }; const DOOR_MEMBER = { owner: "delete", operator: "deleteUnreadable" }; function offersDeleteDoor(store, door) { try { return typeof Reflect.get(store, DOOR_MEMBER[door]) === "function"; } catch { return false; } } export function corruptSessionWayOutSentence(form, store) { const clause = (door) => (offersDeleteDoor(store, door) ? DOOR_CLAUSE[door].offered : DOOR_CLAUSE[door].absent); return SENTENCE[form]({ owner: clause("owner"), operator: clause("operator") }); }