@orkestrel/agent 0.0.36 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2458,6 +2458,17 @@ export declare function buildLedgerCut(steps: ReadonlyArray<LedgerLine | string>
2458
2458
  */
2459
2459
  export declare function buildLedgerIndex(registry: LedgerRegistry): LedgerIndex;
2460
2460
 
2461
+ /**
2462
+ * Encodes a sentence's record placement without comparing rendered text.
2463
+ * @param line - The record key, title, source, and zero-based sentence index
2464
+ * @returns The serialized placement identity
2465
+ * @example
2466
+ * ```ts
2467
+ * buildLedgerLineKey({ key: 'rules', title: 'Rules', source: 'one', sentence: 0 })
2468
+ * ```
2469
+ */
2470
+ export declare function buildLedgerLineKey(line: Pick<LedgerOccurrence, 'key' | 'title' | 'source' | 'sentence'>): string;
2471
+
2461
2472
  /**
2462
2473
  * Derives complete source identities, first occurrences, and local references from the actual lines of the records.
2463
2474
  * @param messages - Original messages whose indexed sentences establish completeness
@@ -2574,17 +2585,17 @@ export declare function buildRecapMessage(section: Section): Message;
2574
2585
  * Projects the owner records and the rules record from a conversation's messages.
2575
2586
  *
2576
2587
  * @remarks
2577
- * Each line is a sentence of a live message, verbatim except that a sentence that opens with a pronoun opens with its party and a colon. A message is live when it is a user message,
2578
- * or a tool message whose finding is the last finding of its call, and the input neither excludes it nor
2579
- * files it quiet or replaced. A finding with an undefined `result` still replaces the earlier
2580
- * finding of the same call, so the earlier result leaves every record.
2588
+ * Each line is a sentence of a live message, verbatim except that a sentence that opens with a
2589
+ * pronoun opens with its party and a colon. {@link collectLive} retains user messages and the
2590
+ * earliest finding in each call identity's last run of identical text, subject to exclusions,
2591
+ * quiet classification, and supersessions. An undefined result still replaces the earlier finding.
2581
2592
  *
2582
2593
  * A live message joins the owner records its entities name, directly or through a linked lookup
2583
2594
  * argument. A message that names no owner joins where its earlier side of an amendment pair joins,
2584
2595
  * or on the rules record when it is filed as a rule or a correction, and is an orphan otherwise.
2585
2596
  *
2586
- * Every live sentence is retained. Accepted direct edges are listed in `amendments`. An amending message
2587
- * that is itself superseded retains its accepted edge without restoring its text.
2597
+ * Every live sentence is retained. Accepted edges are listed in `amendments`. An amender that is
2598
+ * superseded points to its newest live successor, or retains its endpoint when none exists.
2588
2599
  *
2589
2600
  * A sentence that opens with a pronoun takes the party named in the sentence before it. The reading
2590
2601
  * trusts capitals, so a capitalized word that is no person, such as a carrier named mid-sentence,
@@ -2836,13 +2847,13 @@ export declare class Classifier implements ClassifierInterface {
2836
2847
  /**
2837
2848
  * Reads the category a message is filed under.
2838
2849
  * @param id - The message id
2839
- * @returns The assigned category, the recorded category at the cutoff, or `undefined`
2850
+ * @returns The assigned category, the recorded category at the cutoff, or `undefined`; a quiet winner suppressed by the user literal floor remains undecided
2840
2851
  */
2841
2852
  category(id: string): LedgerCategory | undefined;
2842
2853
  /**
2843
2854
  * Reports whether a message files under a quiet category.
2844
2855
  * @param id - The message id
2845
- * @returns True if the assigned or recorded category is quiet; false otherwise.
2856
+ * @returns True if the assigned category is quiet or the recorded quiet weight reaches the cutoff, except for a user message carrying an id or number; false otherwise
2846
2857
  */
2847
2858
  quiet(id: string): boolean;
2848
2859
  /**
@@ -2899,14 +2910,14 @@ export declare interface ClassifierInterface {
2899
2910
  */
2900
2911
  classify(requests: ReadonlySet<string>, signal: AbortSignal): Promise<ClassifierResult>;
2901
2912
  /**
2902
- * Returns the category a message is filed under, or undefined when no category reaches its cutoff.
2913
+ * Returns the assigned or recorded category, or undefined when no category reaches its cutoff or the user literal floor suppresses a quiet winner.
2903
2914
  *
2904
2915
  * @param id - The id of the message
2905
2916
  * @returns The category, or undefined
2906
2917
  */
2907
2918
  category(id: string): LedgerCategory | undefined;
2908
2919
  /**
2909
- * Returns true if the message is filed as quiet; false otherwise.
2920
+ * Returns true for a quiet assignment or a recorded quiet weight at the cutoff, except for a user message carrying an id or number; false otherwise.
2910
2921
  *
2911
2922
  * @param id - The id of the message
2912
2923
  * @returns True if the message is quiet; false otherwise.
@@ -3009,17 +3020,18 @@ export declare interface CodedErrorOptions {
3009
3020
  }
3010
3021
 
3011
3022
  /**
3012
- * Collects accepted direct amendments of live messages.
3023
+ * Collects accepted amendments of live messages, following superseded amenders to live successors.
3013
3024
  *
3014
3025
  * @remarks
3015
3026
  * An accepted edge relates an earlier live message to an amender without claiming which sentences
3016
- * changed. An amender takes effect while live and retains its edge after another message supersedes
3017
- * it, without restoring the superseded text. An excluded or quiet user or tool message has no effect.
3027
+ * changed. A superseded amender points to its newest reachable live successor in conversation order,
3028
+ * with cycles guarded and duplicate endpoints removed. With no live successor, its endpoint stays.
3029
+ * This never restores superseded text. An excluded or quiet user or tool message has no effect.
3018
3030
  *
3019
3031
  * @param input - The exclusions and classification to read
3020
3032
  * @param byId - The messages by id
3021
3033
  * @param live - The live message ids from {@link collectLive}
3022
- * @returns The distinct accepted direct edges in conversation order
3034
+ * @returns The distinct accepted edges in conversation order
3023
3035
  *
3024
3036
  * @example
3025
3037
  * ```ts
@@ -3067,15 +3079,54 @@ export declare function collectExchanges(messages: readonly Message[]): Readonly
3067
3079
  */
3068
3080
  export declare function collectImageData(files: readonly FileInterface[]): readonly string[];
3069
3081
 
3082
+ /**
3083
+ * Captures source bytes and direct amendment edges for a held window.
3084
+ * @param messages - Current stored messages
3085
+ * @param sources - Requests, replies, and record sources the window holds
3086
+ * @param amendments - Accepted direct amendment edges from the current projection
3087
+ * @returns Source and edge identities for stale detection
3088
+ * @example
3089
+ * ```ts
3090
+ * collectLedgerEvidence([], new Set(), []).messages.size // 0
3091
+ * ```
3092
+ */
3093
+ export declare function collectLedgerEvidence(messages: readonly Message[], sources: ReadonlySet<string>, amendments: readonly LedgerAmendment[]): LedgerEvidence;
3094
+
3095
+ /**
3096
+ * Collects the record's sentence receipts not already held by a window.
3097
+ * @param record - The selected record with its original sentence identities
3098
+ * @param held - Placement identities already rendered in the window
3099
+ * @returns The remaining sentences with their record placement
3100
+ * @example
3101
+ * ```ts
3102
+ * collectLedgerLines({ key: 'rules', title: 'Rules', members: [], lines: [] }, new Set()) // []
3103
+ * ```
3104
+ */
3105
+ export declare function collectLedgerLines(record: LedgerRecord, held: ReadonlySet<string>): readonly LedgerOccurrence[];
3106
+
3107
+ /**
3108
+ * Selects each marked request's unambiguous final call-free reply.
3109
+ * @param messages - Stored conversation messages in order
3110
+ * @param requests - Marked request ids delimiting reply intervals
3111
+ * @param notes - Ledger notes that separate answer passes
3112
+ * @returns Eligible final replies keyed by request id
3113
+ * @example
3114
+ * ```ts
3115
+ * collectLedgerReplies([], new Set(), new Set()).size // 0
3116
+ * ```
3117
+ */
3118
+ export declare function collectLedgerReplies(messages: readonly Message[], requests: ReadonlySet<string>, notes: ReadonlySet<string>): ReadonlyMap<string, Message>;
3119
+
3070
3120
  /**
3071
3121
  * Collects the ids of the live messages in conversation order.
3072
3122
  *
3073
3123
  * @remarks
3074
- * A message is live when it is a user message, or a tool message whose finding is the last finding of its
3075
- * call, and the input neither excludes it nor files it quiet or replaced. A finding replaces any
3076
- * earlier finding of the same call, an empty one included, so an empty lookup leaves the earlier
3077
- * result out of every record. A finding with no canonical identity stays live as its own source
3078
- * and participates in no replacement.
3124
+ * A message is live when it is a user message or the first unsuperseded finding in its canonical
3125
+ * call identity's last run of identical text, and the input neither excludes it nor files it quiet
3126
+ * or superseded. When the whole run is superseded, its first finding reaches that final filter.
3127
+ * Different text or an undefined result replaces the earlier run, so an empty lookup leaves the
3128
+ * earlier result out of every record. A thrown lookup leaves the earlier result live. A finding
3129
+ * with no canonical identity participates in no replacement.
3079
3130
  *
3080
3131
  * @param input - The messages, findings, and classification to read
3081
3132
  * @returns The live message ids
@@ -3115,6 +3166,22 @@ export declare function collectNames(text: string): readonly string[];
3115
3166
  */
3116
3167
  export declare function collectProjectionIds(projection: LedgerProjection): ReadonlySet<string>;
3117
3168
 
3169
+ /**
3170
+ * Collects stored messages eligible to open the recall offer.
3171
+ * @remarks
3172
+ * Notes and findings without a result do not open the offer. User statements, including quiet
3173
+ * statements available through recall's word route, can open it; this helper does not filter results.
3174
+ * @param input - The messages, findings, and classification
3175
+ * @param requests - The marked request ids
3176
+ * @param notes - The annotation ids to exclude
3177
+ * @returns User statements, lookup findings with results, marked requests, and nonblank call-free replies
3178
+ * @example
3179
+ * ```ts
3180
+ * collectRecallMessages(input, new Set(), new Set()) // eligible stored messages
3181
+ * ```
3182
+ */
3183
+ export declare function collectRecallMessages(input: LedgerProjectionInput, requests: ReadonlySet<string>, notes: ReadonlySet<string>): readonly Message[];
3184
+
3118
3185
  /**
3119
3186
  * Collects the ids and the owner names the lookup findings named.
3120
3187
  *
@@ -5282,12 +5349,19 @@ export declare function createThinkSplitter(): ThinkSplitterInterface;
5282
5349
  * Cuts entries to a room and names how many it left out.
5283
5350
  *
5284
5351
  * @remarks
5285
- * The cut keeps at least one entry. When it leaves entries out, its last line reads
5352
+ * By default the cut keeps at least one entry. With `first: false`, it keeps whole entries only
5353
+ * when the joined result, tool framing, and omission line fit, and considers later entries after
5354
+ * an oversized group. When it leaves some entries out, its last line reads
5286
5355
  * `N older items not shown; name a narrower topic to narrow the recall`, which
5287
- * {@link matchesCutLine} recognizes.
5356
+ * {@link matchesCutLine} recognizes. Pass `more` when the entries aren't in age order, so the line
5357
+ * doesn't claim an omitted entry is older than a kept one. A fitted cut also uses `more` when it
5358
+ * skips an entry before a kept one. With no kept entry it reads
5359
+ * `N older items didn't fit in this request; answer from the messages you can see`.
5288
5360
  *
5289
5361
  * @param entries - The entries in the order they are kept
5290
5362
  * @param room - The estimate units the joined entries can take
5363
+ * @param kind - What the cut line calls an omitted entry. Default: `older`
5364
+ * @param first - If `true`, keeps the first entry regardless of room; if `false`, fits every entry and the omission line. Default: `true`
5291
5365
  * @returns The kept entries followed by the cut line when any were left out, joined by newlines
5292
5366
  *
5293
5367
  * @example
@@ -5295,7 +5369,7 @@ export declare function createThinkSplitter(): ThinkSplitterInterface;
5295
5369
  * cutListing(['first entry', 'second entry'], 1) // 'first entry\n1 older item not shown; name a narrower topic to narrow the recall'
5296
5370
  * ```
5297
5371
  */
5298
- export declare function cutListing(entries: readonly string[], room: number): string;
5372
+ export declare function cutListing(entries: readonly string[], room: number, kind?: 'older' | 'more', first?: boolean): string;
5299
5373
 
5300
5374
  /**
5301
5375
  * Backs a {@link ConversationStoreInterface} with one table of the `databases` layer — a
@@ -5608,6 +5682,19 @@ export declare function describeSnapshotRefusal(noun: string, id: unknown, fault
5608
5682
  /** Matches the logprob decoding failure `invalid or duplicate top logprob token`, which the ledger holds for the ledger's life. */
5609
5683
  export declare const DETERMINISTIC_JUDGE_ERROR: RegExp;
5610
5684
 
5685
+ /**
5686
+ * Digests held messages, lookup call context, stored copies, and sentence receipts using canonical text.
5687
+ * This non-cryptographic checksum detects host edits and makes no security claim.
5688
+ * @param exchanges - The stored exchange entries
5689
+ * @param messages - The conversation holding their messages
5690
+ * @returns The hexadecimal checksum, or undefined when a required message is absent or canonical encoding fails
5691
+ * @example
5692
+ * ```ts
5693
+ * digestLedgerWindow([], []) // a deterministic hexadecimal checksum
5694
+ * ```
5695
+ */
5696
+ export declare function digestLedgerWindow(exchanges: readonly LedgerExchangeSnapshot[], messages: readonly Message[]): string | undefined;
5697
+
5611
5698
  /**
5612
5699
  * Estimates the context-token footprint of a batch of messages — each message's content plus
5613
5700
  * {@link import('./constants.js').MESSAGE_TOKEN_OVERHEAD}, a tool-call JSON estimate, a thinking estimate, and
@@ -5874,8 +5961,9 @@ export declare function freezeJSON(value: unknown): unknown;
5874
5961
  * has left.
5875
5962
  *
5876
5963
  * @remarks
5877
- * `observe` rescales from the first call of each finished request with the overhead cost taken out,
5878
- * and keeps that request's calls for the marginal rate and the longest final completion for the reply
5964
+ * `observe` rescales from the first call only when `spared` is absent, zero, or at least `overhead`,
5965
+ * with `max(0, overhead - spared)` taken out. A partially spared call keeps the existing scale.
5966
+ * It keeps that request's calls for the marginal rate and the longest final completion for the reply
5879
5967
  * reserve after subtracting its thinking. `overhead` never changes after construction.
5880
5968
  * {@link GaugeOptions} defines the measured use, reply reserve, and recall-room formulas.
5881
5969
  * {@link LedgerOptions} defines the ledger's plan budget and recall close rule.
@@ -5921,7 +6009,10 @@ export declare class Gauge implements GaugeInterface {
5921
6009
  * @remarks
5922
6010
  * `estimate` is the `estimateMessages` estimate of the call's messages. `prompt` and `completion`
5923
6011
  * are the tokens the provider reported, absent when it reported none. `tools` is the count of tool
5924
- * definitions the call advertised.
6012
+ * definitions the call advertised. `spared` is the tokens of definitions it did not advertise;
6013
+ * estimated use subtracts it from overhead, floored at 0. Omission means 0. Observation rescales
6014
+ * only with exact overhead: `spared` absent or zero retains all overhead, and `spared` at or above
6015
+ * overhead retains none. A partially spared first call keeps the prior scale.
5925
6016
  * `thinking` estimates the completion tokens spent on thinking from its share of the generated
5926
6017
  * characters, rounded to the nearest integer and capped at `completion`. With replay `'none'`,
5927
6018
  * the measured call uses `prompt + completion - thinking`; other policies retain the whole
@@ -5929,6 +6020,8 @@ export declare class Gauge implements GaugeInterface {
5929
6020
  */
5930
6021
  export declare interface GaugeCall {
5931
6022
  readonly estimate: number;
6023
+ /** Tokens spared by tool definitions this call did not advertise. Default: 0. */
6024
+ readonly spared?: number;
5932
6025
  readonly prompt?: number;
5933
6026
  readonly completion?: number;
5934
6027
  readonly thinking?: number;
@@ -5999,11 +6092,16 @@ export declare interface GaugeInterface extends LedgerGauge {
5999
6092
  * nonnegative safe integer less than `capacity`; construction throws `LedgerError` with code
6000
6093
  * `'CAPACITY'` otherwise. `replay` names the thinking the next request carries. Default: `'none'`.
6001
6094
  * Measured use is `prompt + completion - (thinking ?? 0)` for `'none'`, and `prompt + completion`
6002
- * otherwise; absent completion counts as 0. Without prompt usage, use is `overhead + scale * estimate`.
6095
+ * otherwise; absent completion counts as 0. Without prompt usage, use is
6096
+ * `max(0, overhead - (spared ?? 0)) + scale * estimate`.
6003
6097
  * Capacity left is `max(0, capacity - used)`. The reply reserve adds recall uniform at the marginal
6004
6098
  * rate to the largest observed reply's `completion - (thinking ?? 0)` for every policy.
6005
- * Without a positive reply observation, it prices the longest reply text at that rate. Recall room is
6006
- * `max(0, (remainder - predict - reserve) / 2 / rate)`; recall closes at `remainder - predict < 2 * reserve`.
6099
+ * Without a positive reply observation, it prices the longest reply text at that rate. The room formula
6100
+ * `max(0, (remainder - predict - reserve) / 2 / rate)` is the planning forecast. The ledger's runtime
6101
+ * recall instead fits results below `capacity - predict`, anchoring the prefix to reported usage
6102
+ * and pricing additions at the larger of the marginal rate and the request's measured rate, with
6103
+ * `LEDGER_SCALE_DRIFT` headroom. The measured rate subtracts overhead only where `observe` would
6104
+ * rescale; partially spared calls retain the marginal rate. Missing usage uses an estimate.
6007
6105
  */
6008
6106
  export declare interface GaugeOptions extends LedgerGauge {
6009
6107
  readonly capacity: number;
@@ -6046,6 +6144,23 @@ export declare function handleAgentQueueJob(registry: AgentRegistryInterface, pa
6046
6144
  */
6047
6145
  export declare function hasCalls(message: Pick<Message, 'calls'>): boolean;
6048
6146
 
6147
+ /**
6148
+ * Checks whether an eligible earlier message is absent from the prompt or incompletely covered.
6149
+ * A successful finding is held when a finding with the same canonical identity and text is fully received.
6150
+ * @param input - The messages, findings, and classification
6151
+ * @param request - The current request id; only messages before it count
6152
+ * @param requests - The marked request ids
6153
+ * @param notes - The annotation ids to exclude
6154
+ * @param messages - The seed tail and held exchange messages; lookup stubs retain their rendered text
6155
+ * @param lines - The receipts held by the window and the request copy together
6156
+ * @returns True if an eligible earlier message is absent or only partly covered; false otherwise
6157
+ * @example
6158
+ * ```ts
6159
+ * hasHiddenRecall(input, request.id, requests, notes, tail, lines) // whether to offer recall
6160
+ * ```
6161
+ */
6162
+ export declare function hasHiddenRecall(input: LedgerProjectionInput, request: string, requests: ReadonlySet<string>, notes: ReadonlySet<string>, messages: readonly Message[], lines: readonly LedgerReceipt[]): boolean;
6163
+
6049
6164
  /**
6050
6165
  * Identifies a lookup finding for projection by its tool name and normalized arguments.
6051
6166
  *
@@ -6721,6 +6836,8 @@ export declare function isLedgerQuestion(value: unknown): value is LedgerQuestio
6721
6836
  * guard is structural: it admits a conversation holding a stored `system` role
6722
6837
  * or a repeated id, which `requireConversationSnapshot` and the `Conversation` constructor then
6723
6838
  * refuse as the stored-data check a ledger's hydrate runs.
6839
+ * A present `window` must be nonempty and exactly shaped. This guard does not audit its references
6840
+ * or sentence ranges. Hydration discards the window when its digest disagrees or cannot be computed.
6724
6841
  *
6725
6842
  * @param value - The value to inspect, such as a parsed checkpoint
6726
6843
  * @returns True if the value has the shape of a ledger snapshot whose marked ids name messages of its own conversation; false otherwise
@@ -6733,6 +6850,17 @@ export declare function isLedgerQuestion(value: unknown): value is LedgerQuestio
6733
6850
  */
6734
6851
  export declare function isLedgerSnapshot(value: unknown): value is LedgerSnapshot;
6735
6852
 
6853
+ /**
6854
+ * Checks whether a value has the exact shape of a nonempty exchange window.
6855
+ * @param value - The untrusted window
6856
+ * @returns True if the window and its members are well shaped; false otherwise
6857
+ * @example
6858
+ * ```ts
6859
+ * isLedgerWindowSnapshot({ digest: 'checksum', exchanges: [{ request: 'request', reply: 'reply', lines: [] }], amendments: [] }) // true
6860
+ * ```
6861
+ */
6862
+ export declare function isLedgerWindowSnapshot(value: unknown): value is LedgerWindowSnapshot;
6863
+
6736
6864
  /**
6737
6865
  * Checks whether a value is a stored memo revision: a record with a string `id`, `name`,
6738
6866
  * `description`, and `content`, a finite `time`, and an optional `origin`.
@@ -7543,8 +7671,8 @@ export declare class Ledger implements LedgerInterface {
7543
7671
  */
7544
7672
  calibrate(signal: AbortSignal): Promise<LedgerGauge>;
7545
7673
  /**
7546
- * Serializes the conversation, the marked ids, and the gauge into a snapshot a later ledger hydrates from.
7547
- * @returns The snapshot, each id list in conversation order and `gauge` present after the ledger holds one
7674
+ * Serializes the conversation, marked ids, gauge, and completed exchange window for a later ledger.
7675
+ * @returns The snapshot, each id list in conversation order, with a gauge and window only when held
7548
7676
  * @throws {AgentError} Thrown when a request or calibration is active (code `'CONCURRENCY'`)
7549
7677
  */
7550
7678
  snapshot(): LedgerSnapshot;
@@ -7585,6 +7713,12 @@ export declare const LEDGER_OWNER_PREFIX = "owner:";
7585
7713
  */
7586
7714
  export declare const LEDGER_QUESTIONS: LedgerQuestion;
7587
7715
 
7716
+ /** Labels recalled conversation text by its origin. */
7717
+ export declare const LEDGER_RECALL_LABELS: Readonly<{
7718
+ request: "Earlier request:";
7719
+ reply: "Earlier reply:";
7720
+ }>;
7721
+
7588
7722
  /** Names the key of the record that holds the rules no owner claims. */
7589
7723
  export declare const LEDGER_RULES_KEY = "rules";
7590
7724
 
@@ -7680,6 +7814,14 @@ export declare interface LedgerCorrectionOptions {
7680
7814
  readonly narrow?: boolean;
7681
7815
  }
7682
7816
 
7817
+ /** Carries a planned copy and its validity evidence to request settlement. */
7818
+ export declare interface LedgerDraft {
7819
+ readonly copy: Message;
7820
+ readonly lines: readonly LedgerOccurrence[];
7821
+ readonly evidence: LedgerEvidence;
7822
+ readonly window: readonly LedgerExchange[];
7823
+ }
7824
+
7683
7825
  /**
7684
7826
  * Lists the registry ids and owner ids a text names.
7685
7827
  *
@@ -7742,6 +7884,27 @@ export declare type LedgerErrorCode =
7742
7884
  /** Reports filing wording that `isLedgerQuestion` refuses. */
7743
7885
  | 'QUESTION';
7744
7886
 
7887
+ /** Captures held message identities and the accepted edges used to validate their copies. */
7888
+ export declare interface LedgerEvidence {
7889
+ readonly messages: ReadonlySet<string>;
7890
+ readonly amendments: ReadonlyMap<string, LedgerAmendment>;
7891
+ }
7892
+
7893
+ /** Carries a completed request copy, its stored reply, and the sentences the copy rendered. */
7894
+ export declare interface LedgerExchange {
7895
+ readonly request: Message;
7896
+ readonly reply: Message;
7897
+ readonly lines: readonly LedgerOccurrence[];
7898
+ }
7899
+
7900
+ /** Carries the sent request text, stored pair ids, and sentence placements of one exchange. */
7901
+ export declare interface LedgerExchangeSnapshot {
7902
+ readonly request: string;
7903
+ readonly copy?: string;
7904
+ readonly reply: string;
7905
+ readonly lines: readonly LedgerReceipt[];
7906
+ }
7907
+
7745
7908
  /**
7746
7909
  * Carries the price of a prompt in tokens, measured against the model the ledger serves.
7747
7910
  *
@@ -7881,6 +8044,14 @@ export declare interface LedgerLine {
7881
8044
  readonly role: MessageRole;
7882
8045
  }
7883
8046
 
8047
+ /** Carries a recall result, its accepted whole groups, lookup line translations, and provider-turn position. */
8048
+ export declare interface LedgerListing {
8049
+ readonly result: string;
8050
+ readonly lines: ReadonlyMap<string, string>;
8051
+ readonly groups: readonly string[];
8052
+ readonly turn: number;
8053
+ }
8054
+
7884
8055
  /**
7885
8056
  * Carries one application lookup: the tool the model calls and the handler that reads its results.
7886
8057
  *
@@ -7961,6 +8132,10 @@ export declare interface LedgerNote {
7961
8132
  readonly closure: string;
7962
8133
  }
7963
8134
 
8135
+ /** Carries a rendered sentence with its record placement. */
8136
+ export declare interface LedgerOccurrence extends LedgerLine, LedgerReceipt {
8137
+ }
8138
+
7964
8139
  /**
7965
8140
  * Configures a ledger: its judge and the wording and cutoffs it files with, the desk topics, the
7966
8141
  * context capacity, and the optional first-pass thinking, lookups, gauge, shares, snapshot, recall
@@ -7976,7 +8151,10 @@ export declare interface LedgerNote {
7976
8151
  * nonnegative safe integer less than `capacity`; construction throws `LedgerError` with code
7977
8152
  * `'CAPACITY'` otherwise. The plan budgets
7978
8153
  * `max(0, (capacity - predict) * share.prompt - overhead) / (1 + LEDGER_SCALE_DRIFT)`.
7979
- * Recall closes when `remainder - predict < 2 * reserve`. `snapshot` hydrates the conversation and
8154
+ * The plan retains its `remainder - predict < 2 * reserve` admission rule. Runtime recall fits whole
8155
+ * results to measured remaining capacity at the larger of the gauge rate and the request's measured
8156
+ * rate, allowing `LEDGER_SCALE_DRIFT` for new text. Lack of room omits results without closing recall.
8157
+ * `snapshot` hydrates the conversation and
7980
8158
  * the marked ids a ledger's `snapshot()` returned; construction throws `LedgerError` with code
7981
8159
  * `'SNAPSHOT'` when `isLedgerSnapshot` refuses it, and `ConversationError` with code `'ROLE'` or
7982
8160
  * `'SNAPSHOT'` when its conversation holds a `system` message or repeats an id.
@@ -8091,6 +8269,14 @@ export declare interface LedgerRecallOptions {
8091
8269
  readonly limit?: number;
8092
8270
  }
8093
8271
 
8272
+ /** Identifies an original sentence at one record placement. */
8273
+ export declare interface LedgerReceipt {
8274
+ readonly key: string;
8275
+ readonly title: string;
8276
+ readonly source: string;
8277
+ readonly sentence: number;
8278
+ }
8279
+
8094
8280
  /**
8095
8281
  * Carries one record: the live messages placed on one owner or on the rules, as lines.
8096
8282
  *
@@ -8107,6 +8293,12 @@ export declare interface LedgerRecord {
8107
8293
  readonly lines: readonly LedgerLine[];
8108
8294
  }
8109
8295
 
8296
+ /** Carries the answer note and the partial messages omitted from its prompt. */
8297
+ export declare interface LedgerRecovery {
8298
+ readonly digest: string | undefined;
8299
+ readonly omitted: ReadonlySet<string>;
8300
+ }
8301
+
8110
8302
  /**
8111
8303
  * Carries the ids the ledger's lookups named and the owners among them.
8112
8304
  *
@@ -8138,6 +8330,12 @@ export declare interface LedgerRenderContext {
8138
8330
  readonly references: ReadonlyMap<string, string>;
8139
8331
  }
8140
8332
 
8333
+ /** Carries rendered record text and its sentences in emission order. */
8334
+ export declare interface LedgerRenderResult {
8335
+ readonly text: string;
8336
+ readonly lines: readonly LedgerOccurrence[];
8337
+ }
8338
+
8141
8339
  /**
8142
8340
  * Holds what one ledger request keeps while it is served: its message, its filing attempts and
8143
8341
  * plan, the gauge calls of its passes, and its repeat and recall stops.
@@ -8179,6 +8377,10 @@ export declare class LedgerRequest implements LedgerRequestInterface {
8179
8377
  * @returns The planned selection, or undefined before one
8180
8378
  */
8181
8379
  get plan(): Selection | undefined;
8380
+ get scope(): ScopeInterface | undefined;
8381
+ apply(scope: ScopeInterface): void;
8382
+ /** Returns the copy and receipts adopted by the last provider turn. */
8383
+ get sent(): LedgerDraft | undefined;
8182
8384
  /**
8183
8385
  * Returns the selection the current pass's run adopted last.
8184
8386
  *
@@ -8217,11 +8419,13 @@ export declare class LedgerRequest implements LedgerRequestInterface {
8217
8419
  think(messages: readonly Message[]): void;
8218
8420
  fault(error: unknown): void;
8219
8421
  faulted(error: unknown): boolean;
8220
- file(attempts: readonly ClassifierAttempt[], plan?: Selection): void;
8422
+ file(attempts: readonly ClassifierAttempt[], plan?: Selection, draft?: LedgerDraft): void;
8221
8423
  admit(name: string, args: Readonly<Record<string, unknown>>): void;
8222
8424
  recall(): void;
8223
8425
  close(): void;
8224
- list(result: string, lines: ReadonlyMap<string, string>): void;
8426
+ list(result: string, lines: ReadonlyMap<string, string>, groups: readonly string[]): void;
8427
+ /** Returns recall results with their accepted whole groups and provider-turn positions. */
8428
+ get listings(): readonly LedgerListing[];
8225
8429
  lines(result: string): ReadonlyMap<string, string> | undefined;
8226
8430
  }
8227
8431
 
@@ -8238,6 +8442,12 @@ export declare class LedgerRequest implements LedgerRequestInterface {
8238
8442
  * thinking, until its pass observes the next call, and is final from then on.
8239
8443
  */
8240
8444
  export declare interface LedgerRequestInterface {
8445
+ /** Holds the scope last applied by the ledger's plan, or undefined before one. */
8446
+ readonly scope: ScopeInterface | undefined;
8447
+ /** Records the scope applied by the ledger's plan for conditional restoration at settle. */
8448
+ apply(scope: ScopeInterface): void;
8449
+ /** Holds the copy and receipts adopted by the last provider turn, or undefined for a view fallback. */
8450
+ readonly sent: LedgerDraft | undefined;
8241
8451
  /** Records an error the request's run reported through its `fault` event. */
8242
8452
  fault(error: unknown): void;
8243
8453
  /**
@@ -8310,8 +8520,9 @@ export declare interface LedgerRequestInterface {
8310
8520
  *
8311
8521
  * @param attempts - The selection's filing attempts, in asking order
8312
8522
  * @param plan - The planned selection, or undefined when planning failed
8523
+ * @param draft - The copy and receipts eligible for adoption; omission discards that eligibility
8313
8524
  */
8314
- file(attempts: readonly ClassifierAttempt[], plan?: Selection): void;
8525
+ file(attempts: readonly ClassifierAttempt[], plan?: Selection, draft?: LedgerDraft): void;
8315
8526
  /**
8316
8527
  * Admits one tool call of the request, compared by tool name and canonical arguments.
8317
8528
  *
@@ -8334,8 +8545,11 @@ export declare interface LedgerRequestInterface {
8334
8545
  *
8335
8546
  * @param result - The recall result text
8336
8547
  * @param lines - Each listed lookup line mapped to the first line of its stored content
8548
+ * @param groups - The complete candidate groups, in listing order; only groups present in the result are retained
8337
8549
  */
8338
- list(result: string, lines: ReadonlyMap<string, string>): void;
8550
+ list(result: string, lines: ReadonlyMap<string, string>, groups: readonly string[]): void;
8551
+ /** Holds each recall result with its accepted groups and provider-turn position. */
8552
+ readonly listings: readonly LedgerListing[];
8339
8553
  /**
8340
8554
  * Returns the stored first lines a recall result listed.
8341
8555
  *
@@ -8368,7 +8582,11 @@ export declare interface LedgerResult extends AgentResult {
8368
8582
  *
8369
8583
  * @remarks
8370
8584
  * `prompt` is a share of the ledger's `capacity`; the overhead tokens of the gauge come out of it
8371
- * before the records and the tail take the rest. `tail` is a share of what remains for messages.
8585
+ * before the records and the tail take the rest. `tail` bounds only the seed tail. The seed and
8586
+ * records are planned before the completed-exchange window spends spare room. The full window
8587
+ * with a delta copy, then its newest plain exchange with a full copy, then no exchange are priced
8588
+ * in that order. Admission cannot close an otherwise open recall or displace a selected record
8589
+ * line or seed message. A seed stub reads visibility across the window and the copy together.
8372
8590
  * Each share must be finite, greater than 0, and at most 1.
8373
8591
  */
8374
8592
  export declare interface LedgerShare {
@@ -8388,7 +8606,14 @@ export declare interface LedgerShare {
8388
8606
  * not carried, so a hydrated ledger sizes and closes `recall` from its fallback reserve until it
8389
8607
  * completes a request. A question a `strict: false` classifier held after a deterministic judge
8390
8608
  * failure is not carried, so a hydrated ledger asks it again. Hydrating a second ledger from one snapshot forks
8391
- * it at the parent's frontier.
8609
+ * it at the parent's frontier. `window`, when present, retains sent request copies, reply ids,
8610
+ * sentence receipts, and accepted amendment edges. The next plan keeps the same conversation
8611
+ * prefix when the live and hydrated reserves admit the same exchange rung. A rung between those
8612
+ * reserves can differ because hydration carries no gauge observations; this moves the prefix,
8613
+ * never the record coverage. A plain request omits `copy` because its content already lives in `conversation`.
8614
+ * The required window `digest` checks canonical held messages, lookup call context, copies, and receipts. A mismatch drains
8615
+ * the window and its evidence; a missing digest refuses the snapshot. An unencodable held message
8616
+ * makes `snapshot()` omit the window. The checksum detects edits, not authenticity.
8392
8617
  */
8393
8618
  export declare interface LedgerSnapshot {
8394
8619
  readonly conversation: ConversationSnapshot;
@@ -8396,9 +8621,10 @@ export declare interface LedgerSnapshot {
8396
8621
  readonly notes: readonly string[];
8397
8622
  readonly failures: readonly string[];
8398
8623
  readonly gauge?: LedgerGauge;
8624
+ readonly window?: LedgerWindowSnapshot;
8399
8625
  }
8400
8626
 
8401
- /** Reads the faults of a refused ledger snapshot. */
8627
+ /** Reads structural faults of a ledger snapshot, including its optional held exchange window. */
8402
8628
  export declare const ledgerSnapshotContract: ContractInterface<Readonly<{
8403
8629
  conversation: Readonly<{
8404
8630
  id: string;
@@ -8558,6 +8784,25 @@ gauge?: Readonly<{
8558
8784
  scale: number;
8559
8785
  overhead: number;
8560
8786
  } & {}>;
8787
+ window?: Readonly<{
8788
+ digest: string;
8789
+ exchanges: readonly Readonly<{
8790
+ request: string;
8791
+ reply: string;
8792
+ lines: readonly Readonly<{
8793
+ key: string;
8794
+ title: string;
8795
+ source: string;
8796
+ sentence: number;
8797
+ } & {}>[];
8798
+ } & {
8799
+ copy?: string;
8800
+ }>[];
8801
+ amendments: readonly Readonly<{
8802
+ earlier: string;
8803
+ later: string;
8804
+ } & {}>[];
8805
+ } & {}>;
8561
8806
  }>>;
8562
8807
 
8563
8808
  /**
@@ -8678,6 +8923,24 @@ gauge: OptionalShape<ObjectShape< {
8678
8923
  scale: NumberShape;
8679
8924
  overhead: NumberShape;
8680
8925
  }, boolean | ContractShape>>;
8926
+ window: OptionalShape<ObjectShape< {
8927
+ digest: StringShape;
8928
+ exchanges: ArrayShape<ObjectShape< {
8929
+ request: StringShape;
8930
+ copy: OptionalShape<StringShape>;
8931
+ reply: StringShape;
8932
+ lines: ArrayShape<ObjectShape< {
8933
+ key: StringShape;
8934
+ title: StringShape;
8935
+ source: StringShape;
8936
+ sentence: NumberShape;
8937
+ }, boolean | ContractShape>>;
8938
+ }, boolean | ContractShape>>;
8939
+ amendments: ArrayShape<ObjectShape< {
8940
+ earlier: StringShape;
8941
+ later: StringShape;
8942
+ }, boolean | ContractShape>>;
8943
+ }, boolean | ContractShape>>;
8681
8944
  }, boolean | ContractShape>;
8682
8945
 
8683
8946
  /**
@@ -8717,6 +8980,54 @@ export declare interface LedgerTopic {
8717
8980
  readonly requested?: boolean;
8718
8981
  }
8719
8982
 
8983
+ /** Reads structural faults of a serialized exchange window. */
8984
+ export declare const ledgerWindowContract: ContractInterface<Readonly<{
8985
+ digest: string;
8986
+ exchanges: readonly Readonly<{
8987
+ request: string;
8988
+ reply: string;
8989
+ lines: readonly Readonly<{
8990
+ key: string;
8991
+ title: string;
8992
+ source: string;
8993
+ sentence: number;
8994
+ } & {}>[];
8995
+ } & {
8996
+ copy?: string;
8997
+ }>[];
8998
+ amendments: readonly Readonly<{
8999
+ earlier: string;
9000
+ later: string;
9001
+ } & {}>[];
9002
+ } & {}>>;
9003
+
9004
+ /** Describes the minimal serialized evidence of a nonempty exchange window. */
9005
+ export declare const ledgerWindowShape: ObjectShape< {
9006
+ digest: StringShape;
9007
+ exchanges: ArrayShape<ObjectShape< {
9008
+ request: StringShape;
9009
+ copy: OptionalShape<StringShape>;
9010
+ reply: StringShape;
9011
+ lines: ArrayShape<ObjectShape< {
9012
+ key: StringShape;
9013
+ title: StringShape;
9014
+ source: StringShape;
9015
+ sentence: NumberShape;
9016
+ }, boolean | ContractShape>>;
9017
+ }, boolean | ContractShape>>;
9018
+ amendments: ArrayShape<ObjectShape< {
9019
+ earlier: StringShape;
9020
+ later: StringShape;
9021
+ }, boolean | ContractShape>>;
9022
+ }, boolean | ContractShape>;
9023
+
9024
+ /** Carries a nonempty exchange window, its message, copy, and receipt checksum, and its accepted edges. */
9025
+ export declare interface LedgerWindowSnapshot {
9026
+ readonly digest: string;
9027
+ readonly exchanges: readonly LedgerExchangeSnapshot[];
9028
+ readonly amendments: readonly LedgerAmendment[];
9029
+ }
9030
+
8720
9031
  /** Carries the lowercase words and non-opening capitalized names of a message. */
8721
9032
  export declare interface LedgerWordSet {
8722
9033
  readonly words: ReadonlySet<string>;
@@ -8842,6 +9153,18 @@ export declare function matchesJSON(left: unknown, right: unknown): boolean;
8842
9153
  */
8843
9154
  export declare function matchesJudgment(judgment: Judgment, question: JudgeQuestion, sources: readonly string[], state: string, model: string): boolean;
8844
9155
 
9156
+ /**
9157
+ * Checks whether two successful findings carry the same text for the same canonical lookup.
9158
+ * @param left - The finding to compare
9159
+ * @param right - The candidate copy
9160
+ * @returns True for the same finding or equal canonical identities and text; unkeyable findings match only themselves
9161
+ * @example
9162
+ * ```ts
9163
+ * matchesLookup(finding, finding) // true when it has a result
9164
+ * ```
9165
+ */
9166
+ export declare function matchesLookup(left: LedgerLookupFinding, right: LedgerLookupFinding): boolean;
9167
+
8845
9168
  /**
8846
9169
  * Bounds the decoded error excerpt's input in bytes — `2048`, the leading bytes of a non-OK
8847
9170
  * response body handed to the decoder before the read cancels the remainder, so a `ProviderError`
@@ -12204,6 +12527,7 @@ export declare type SystemOneEntry = JudgeEntry | null;
12204
12527
  *
12205
12528
  * @remarks
12206
12529
  * The caller supplies the server origin and model. Every question travels in one request.
12530
+ * Wire keys are zero-based positions in question entry order; answers return under the caller's ids.
12207
12531
  * Server measures are ignored; the response model is preserved.
12208
12532
  * `headers` supplies authentication through the shared judge engine.
12209
12533
  * The example readings are those of the response Ollama 0.40.0 returned for that request on 2026-10-07.
@@ -12254,14 +12578,14 @@ export declare class SystemOneJudge extends AgentJudge {
12254
12578
  /** Identifies the System One protocol. */
12255
12579
  readonly name = "systemone";
12256
12580
  /**
12257
- * Projects the state and questions onto the System One request with the configured model.
12581
+ * Projects the state and questions onto the System One request with the configured model and positional keys.
12258
12582
  *
12259
12583
  * @param request - The state and questions keyed by caller id
12260
12584
  * @returns The System One request body
12261
12585
  */
12262
12586
  encode(request: JudgeRequest): SystemOneRequest;
12263
12587
  /**
12264
- * Decodes requested System One answers and reports the server model and available usage.
12588
+ * Decodes positional System One answers under caller ids and reports the server model and available usage.
12265
12589
  *
12266
12590
  * @param value - The parsed response body
12267
12591
  * @param request - The questions defining the expected answers