UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

76 lines (75 loc) • 5.2 kB
/** * design/180 裁决 C — the v2 header hints, read-only, over `frontmatter.extra`. * * The v2 header fields (pinned / triggers / last-confirmed / applies-when / evidence / confidence) are DELIBERATELY not * typed structure positions: the parser's closed grammar keeps unknown lines VERBATIM in `extra`, * `extra` participates in the entry rev, and the sync wire carries it — so a file with these lines * computes the SAME rev on every client vintage (old and new), and no backend/sync twin owes an * upgrade. Promoting them to typed fields would make the same bytes hash to two different revs * across a mixed fleet (the provenance note in frontmatter.ts names that exact incident shape). * * This accessor is the ONLY consumer-side reading: pure, lenient, and closed over bad values — * a malformed line reads as FIELD ABSENT, never an error and never a partial adoption. The engine * writes none of these lines of its own accord; the model does (the preference-discipline paragraph * teaches it), because an engine-written confirmation would self-declare the usage evidence it is * supposed to record. The memory write port writes the values its caller states (`evidence` / * `confidence` / `last-confirmed`, {@link STATED_HEADER_FIELDS}) and refuses one outside its type; * a line written into a file by hand is still read leniently, as above. */ /** The parsed v2 hints. Every field is absent unless a well-formed line was found. */ export interface V2HeaderHints { /** `pinned: true` — only the exact literal counts (anything else = absent). */ pinned?: boolean; /** `triggers: a, b, c` — comma-split, trimmed, empties dropped; an empty result = absent. */ triggers?: string[]; /** `last-confirmed: YYYY-MM-DD…` — kept as the raw string when it starts with an ISO-date shape; * anything else = absent (bad values must not masquerade as confirmations). */ lastConfirmedAt?: string; /** `applies-when: <free text>` — non-empty free text, trimmed. */ appliesWhen?: string; /** `evidence: <free text>` — what the entry rests on: non-empty free text, trimmed. */ evidence?: string; /** `confidence: low | medium | high` — only these exact words count (anything else = absent). */ confidence?: MemoryEntryConfidence; } /** How sure the writer of an entry was of it (`confidence:` header line). */ export type MemoryEntryConfidence = "low" | "medium" | "high"; /** * The three fields a new entry may state about its own standing through the memory write port (`MemoryEntryDraft`): the draft's * field, the header line it is written as, and the type its value must have. The port writes each given value, trimmed, as * `<line>: <value>` and keeps it only if this file's reader reads that same value back off the composed entry; the date is further * held to {@link isStatedDate}. Lines the model writes into a file are not judged here — the reader reads them leniently. */ export declare const STATED_HEADER_FIELDS: ReadonlyArray<{ readonly field: "evidence" | "confidence" | "lastConfirmedAt"; readonly line: string; readonly type: string; }>; /** True ⇔ `value` is a date the port writes as `last-confirmed`: `YYYY-MM-DD` naming a day on the calendar, alone or followed by * a `T…` time that, with the date, parses as an instant. */ export declare function isStatedDate(value: string): boolean; /** * design/336 §4.1 — the MECHANICAL instruction-form predicate (deliberately zero semantic judgment: * no model, no content heuristics — SOTA R4's LLM-judge ban). An entry is instruction-form ⇔ * - `metadata.type === "feedback"` (the declared behavior-correction type), OR * - its v2 header hints declare an injection/trigger privilege: `pinned` / `triggers` / * `applies-when` (the three hints whose whole purpose is automatic or conditional injection; * `last-confirmed`, `evidence` and `confidence` are bookkeeping and do not count). * Escape analysis: an entry that declares none of these rides the ordinary-entry row — where the * origin-marker floor governs — so NOT declaring buys no privilege; declaring buys injection * privilege AND walks through the exposure hard gate with it. ONE exported predicate on purpose: * the write side (harvest hard gate) and any read-side consumer must judge through the same * function, never through re-implementations that can drift. * * NAME COLLISION, not concept parity (test B12): `pinned` here is a * WRITE-SIDE safety-privilege declaration (instruction-form ⇒ exposure hard gate / quarantine), * while Claude Code's `pinned` is a RECALL-side display priority (up to 4 entries surfaced in a * "# Pinned memories" block). Same word, different machines — do not read one as the other. */ export declare function isInstructionEntry(fm: { type?: string; extra?: readonly string[]; }): boolean; /** Read the v2 header hints out of an entry's preserved-verbatim `extra` lines. First well-formed * occurrence of each key wins (duplicate lines are model bookkeeping noise, not a merge input). */ export declare function readV2HeaderHints(extra: readonly string[] | undefined): V2HeaderHints;