@yaklabs-ai/plugin-sdk 0.15.2 → 0.26.3

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.
@@ -110,7 +110,7 @@ declare type AttachmentsMessage = CustomMessage<AttachmentsDetails> & {
110
110
  * or an {@link IdentityAttribution} for identity-bearing origins with no registry entry.
111
111
  *
112
112
  * Narrowing hazard: `SourceInfo` and `IdentityAttribution` both have a `string` `source`,
113
- * so a `source` value never distinguishes them — narrow `SourceInfo` by `"path" in x`
113
+ * so a `source` value never distinguishes them - narrow `SourceInfo` by `"path" in x`
114
114
  * (its required field), not by inspecting `source`.
115
115
  */
116
116
  declare type AttributionSource = SourceInfo | {
@@ -126,7 +126,7 @@ declare type AttributionSource = SourceInfo | {
126
126
  /**
127
127
  * The availability-facts message: who the user is connected as, which auth-gated tools are
128
128
  * waiting on a connect, and which installed plugins are not connected. DURABLE and never
129
- * turn-bound — that is the whole point of the kind.
129
+ * turn-bound - that is the whole point of the kind.
130
130
  *
131
131
  * These three facts used to be rendered into the system prompt, where they were the last
132
132
  * in-session prefix mutation (#2996): each of them changes on a connect or disconnect, and a
@@ -453,9 +453,9 @@ declare const CorpusResourceInvocationQuery: z.ZodObject<{
453
453
  }, z.core.$strict>>;
454
454
  limit: z.ZodOptional<z.ZodNumber>;
455
455
  rootCreatedByKind: z.ZodOptional<z.ZodEnum<{
456
+ plugin: "plugin";
456
457
  human: "human";
457
458
  agent: "agent";
458
- plugin: "plugin";
459
459
  trigger: "trigger";
460
460
  daemon: "daemon";
461
461
  }>>;
@@ -540,7 +540,7 @@ declare const DAEMON_SERVICE_TURN_CUSTOM_TYPE = "daemon_service_turn";
540
540
  /**
541
541
  * A daemon-synthesized turn; `service` selects the per-service wrapper at the
542
542
  * boundary. `followup_lane` (a followup session's instruction turn) has no
543
- * reserved wrapper tag yet — it renders through the generic provenance-aware
543
+ * reserved wrapper tag yet - it renders through the generic provenance-aware
544
544
  * `kay_context` fallback until the lane message shape settles.
545
545
  */
546
546
  declare interface DaemonServiceTurnDetails {
@@ -549,8 +549,8 @@ declare interface DaemonServiceTurnDetails {
549
549
  /**
550
550
  * A short, HUMAN-facing description of this turn, for a visible service whose
551
551
  * `content` is not written for a person. For `"continuation"`, `content` is
552
- * the MODEL's input — a runtime-authored instruction ("Complete the
553
- * remaining part of that request. Do not propose another …") — and showing
552
+ * the MODEL's input - a runtime-authored instruction ("Complete the
553
+ * remaining part of that request. Do not propose another ...") - and showing
554
554
  * it to a person reads as though the user is being instructed, so the visible
555
555
  * row renders THIS instead. A continuation renderer missing a summary must
556
556
  * degrade to its own generic phrasing, never to `content`. For
@@ -632,9 +632,9 @@ declare interface DroppedContribution {
632
632
 
633
633
  /**
634
634
  * The Dynamic Context message: retrieval-produced context delivered right after human
635
- * text enters the conversation (prompt, steer, or a drained follow-up batch — one
635
+ * text enters the conversation (prompt, steer, or a drained follow-up batch - one
636
636
  * message per delivery moment). Assembled by the daemon's Dynamic Context coordinator
637
- * from per-contributor sections; push-only (contributors add a section or nothing —
637
+ * from per-contributor sections; push-only (contributors add a section or nothing -
638
638
  * they never mutate the human text or cancel the turn). Persisted like any other
639
639
  * message so the append-only transcript keeps the prompt cache warm.
640
640
  */
@@ -642,7 +642,7 @@ declare const DYNAMIC_CONTEXT_CUSTOM_TYPE = "dynamic_context";
642
642
 
643
643
  /**
644
644
  * The delivery moment that produced a Dynamic Context message: a new human prompt, a
645
- * mid-run steer, or a drained follow-up queue bundled as one batch (the batch law —
645
+ * mid-run steer, or a drained follow-up queue bundled as one batch (the batch law -
646
646
  * one retrieval pass per delivery moment, N drained texts = one message).
647
647
  */
648
648
  declare type DynamicContextChannel = "prompt" | "steer" | "follow_up";
@@ -679,7 +679,7 @@ declare type DynamicContextMessage = CustomMessage<DynamicContextDetails> & {
679
679
  /**
680
680
  * One contributor's section of a Dynamic Context message. `contributorId` owns the
681
681
  * inner wrapper tag at the model boundary (derived from the registration id, sanitized
682
- * by the projection — never free-form), so sections stay parsable per contributor.
682
+ * by the projection - never free-form), so sections stay parsable per contributor.
683
683
  */
684
684
  declare interface DynamicContextSection {
685
685
  readonly contributorId: string;
@@ -835,6 +835,42 @@ declare const Factor: (input: string) => [unknown, string] | [];
835
835
 
836
836
  declare function FactorMapping(input: [unknown, unknown, unknown, unknown, unknown]): unknown;
837
837
 
838
+ declare const FAILURE_RELATIONS: readonly ["caused-by", "retry-of", "recovery-of", "cleanup-of"];
839
+
840
+ declare type FailureJsonValue = null | boolean | number | string | readonly FailureJsonValue[] | {
841
+ readonly [key: string]: FailureJsonValue;
842
+ };
843
+
844
+ declare interface FailureOccurrence<C = FailureJsonValue> {
845
+ readonly ref: FailureRef;
846
+ readonly sourceRef: FailureRef;
847
+ readonly domain: string;
848
+ readonly code: string;
849
+ readonly context: {
850
+ readonly component: string;
851
+ readonly operation: string;
852
+ readonly operationRef?: FailureRef | undefined;
853
+ readonly attemptRef?: FailureRef | undefined;
854
+ readonly phase?: string | undefined;
855
+ readonly requestRef?: FailureRef | undefined;
856
+ readonly traceId?: string | undefined;
857
+ readonly spanId?: string | undefined;
858
+ };
859
+ readonly cause: C;
860
+ readonly relations?: readonly {
861
+ readonly kind: FailureRelationKind;
862
+ readonly failureRef: FailureRef;
863
+ }[] | undefined;
864
+ readonly diagnosticRef?: FailureRef | undefined;
865
+ }
866
+
867
+ declare interface FailureRef {
868
+ readonly authority: string;
869
+ readonly id: string;
870
+ }
871
+
872
+ declare type FailureRelationKind = (typeof FAILURE_RELATIONS)[number];
873
+
838
874
  /** Creates a Function type. */
839
875
  declare function _Function_<Parameters extends TSchema[], ReturnType extends TSchema>(parameters: [...Parameters], returnType: ReturnType, options?: TSchemaOptions): TFunction<Parameters, ReturnType>;
840
876
 
@@ -1206,6 +1242,10 @@ declare type JsonRepresentation<T> = IsAny_2<T> extends true ? JsonValue : unkno
1206
1242
  [TKey in keyof T]: JsonRepresentation<Exclude<T[TKey], undefined>>;
1207
1243
  } : never;
1208
1244
 
1245
+ declare const JsonSchema: z.ZodRecord<z.ZodString, z.ZodType<JsonValue_3, unknown, z.core.$ZodTypeInternals<JsonValue_3, unknown>>>;
1246
+
1247
+ declare type JsonSchema = z.infer<typeof JsonSchema>;
1248
+
1209
1249
  declare type JsonValue = null | boolean | number | string | readonly JsonValue[] | JsonObject;
1210
1250
 
1211
1251
  declare type JsonValue_2 = null | boolean | number | string | JsonValue_2[] | {
@@ -1218,115 +1258,68 @@ declare type JsonValue_3 = string | number | boolean | null | JsonValue_3[] | {
1218
1258
 
1219
1259
  declare const JsonValue_3: z.ZodType<JsonValue_3>;
1220
1260
 
1221
- /**
1222
- * Raw read access to every stored session's transcript. Always present on
1223
- * `KayAppPluginApi`; each read is checked against the `corpus.read` claim, and refused
1224
- * unless the user has granted it. Data is raw and un-redacted — the plugin filters to what it
1225
- * needs. Invocation queries are bounded pages. Transcript reads materialize a whole session
1226
- * before yielding; the iterable does not promise per-entry streaming or an allocation bound.
1227
- */
1228
- declare interface KayAppCorpus {
1229
- /** Page invocation leads under the live grant; inspect exclusions even on available empty pages. */
1230
- listResourceInvocations(query: CorpusResourceInvocationQuery): Promise<CorpusResourceInvocationPage>;
1231
- /** Enumerate every stored session, newest-first. */
1232
- listSessions(): AsyncIterable<KayAppCorpusSession>;
1261
+ /** The inert session-config subset a plugin-authored agent definition may contribute. */
1262
+ declare interface KayAppAgentDefinitionConfig {
1233
1263
  /**
1234
- * Yield one session's full entry log oldest→newest; an unknown id yields nothing. Treat the
1235
- * entries as read-only: for a session the daemon holds in memory they are its live objects.
1264
+ * The definition's instructions: what this agent exists to do. Rendered as the
1265
+ * agent-configuration trailer at the END of Bonsai's own prompt document, subordinate to
1266
+ * everything above it. A definition never replaces Bonsai's prompt; it extends it.
1236
1267
  */
1237
- readEntries(sessionId: string): AsyncIterable<TranscriptEntry>;
1238
- /**
1239
- * Active-branch entries from the latest canonical human turn opener (send companions included)
1240
- * through the anchor, oldest first. Mid-turn steers and machine wakes remain inside that window;
1241
- * attachment-only openers and fresh card answers count. Missing sessions/anchors return [];
1242
- * unsupported hosts may omit it.
1243
- * Reads never fall back to materializing the full log.
1244
- */
1245
- readLatestHumanWindow?(sessionId: string, options?: {
1246
- readonly throughEntryId?: string;
1247
- }): Promise<readonly TranscriptEntry[]>;
1248
- /**
1249
- * Read one bounded page of a session's stored transcript. The host resolves `sessionId` to its
1250
- * authoritative indexed path and validates the opaque cursor before reading. When
1251
- * `throughEntryId` is supplied, the page ends at that entry and the cursor stays at the start of
1252
- * the commit holding it: the commit's other entries are returned for the caller to filter, and
1253
- * the next page replays that commit. A page can hold no entries at all (storage records with no
1254
- * entry) while more follows; a record longer than the page is stepped over and counted in
1255
- * `oversizedRecords`.
1256
- */
1257
- readEntryBatch?(sessionId: string, options?: {
1258
- readonly cursor?: JsonValue_3;
1259
- readonly throughEntryId?: string;
1260
- /** Host-only cancellation for the bounded physical read. */
1261
- readonly signal?: AbortSignal;
1262
- }): Promise<KayAppCorpusEntryBatch>;
1268
+ readonly instructions?: string;
1269
+ readonly activeToolNames?: readonly KayAppSessionRunHostToolName[];
1270
+ readonly backgroundTasksEnabled?: boolean;
1271
+ readonly model?: string;
1272
+ readonly thinkingLevel?: KayAppThinkingLevel;
1273
+ readonly cwd?: string;
1263
1274
  /**
1264
- * Read a cheap transcript change marker without loading the entry log. Unknown or deleted
1265
- * sessions yield `undefined`.
1275
+ * The definition's structured-output contract for a settled turn. Bonsai's own default agent
1276
+ * carries its standing-recap contract through this field; a plugin-authored definition may
1277
+ * carry one too, with the same discipline: keep it optional, and use `whenToSubmit` to say
1278
+ * when it applies rather than making every turn terminate through it.
1266
1279
  */
1267
- readSessionSourceMark(sessionId: string): Promise<KayAppCorpusSourceMark | undefined>;
1280
+ readonly finalOutput?: KayAppAgentDefinitionFinalOutput;
1268
1281
  }
1269
1282
 
1270
- /** One bounded page from the host's stored transcript reader. */
1271
- declare interface KayAppCorpusEntryBatch {
1272
- readonly entries: readonly TranscriptEntry[];
1273
- /** Opaque JSON cursor after the physical page; only the host may interpret it or open its path. */
1274
- readonly cursor: JsonValue_3;
1275
- /** Opaque cursor at the physical page start, for a partial logical chunk. */
1276
- readonly pageStartCursor?: JsonValue_3;
1277
- readonly mode: "replace" | "append";
1278
- /**
1279
- * `record-too-large`: a record longer than the page that the host could not step over, because
1280
- * its end is not written yet or lies past the host's scan limit.
1281
- */
1282
- readonly status: "complete" | "more" | "awaiting-append" | "record-too-large";
1283
- /** Present when a caller supplied `throughEntryId`. */
1284
- readonly anchorFound?: boolean;
1285
- /** Records on this page the host could not parse; its other entries are returned. */
1286
- readonly malformedRecords: number;
1287
- /**
1288
- * Records longer than the page that this read stepped over without parsing them: at most one,
1289
- * and the page then holds no entries. When the caller's `throughEntryId` is inside it,
1290
- * `anchorFound` is true and the cursor is after it.
1291
- */
1292
- readonly oversizedRecords?: number;
1293
- /** Bytes of the stepped-over record, when there is one. */
1294
- readonly oversizedRecordBytes?: number;
1283
+ /** A plugin-authored definition's structured-output contract (the wire's final-output shape). */
1284
+ declare interface KayAppAgentDefinitionFinalOutput {
1285
+ /** JSON Schema for the structured value a matching turn submits. */
1286
+ readonly schema: JsonSchema;
1287
+ readonly required?: boolean | "per-run";
1288
+ readonly sessionTitle?: boolean;
1289
+ readonly whenToSubmit?: string;
1290
+ }
1291
+
1292
+ /**
1293
+ * An opaque handle to one definition THIS plugin registered. `define` returns it; `sessions.run`
1294
+ * accepts it in place of an inline definition.
1295
+ *
1296
+ * The brand keeps plugin code from CONSTRUCTING one - there is no value of this type an honest
1297
+ * plugin can author, so a legitimate ref only ever exists by being returned from this plugin's own
1298
+ * `define` call. That is a TypeScript authoring property, not the runtime security boundary: a
1299
+ * determined plugin can still forge a structurally similar object at runtime, where the brand is
1300
+ * erased. The actual boundary is host-side - the host re-validates every ref it receives against
1301
+ * its own live registry (does a definition with this identity still exist, and does it belong to
1302
+ * the calling plugin), on every use. A forged or stale ref resolves to nothing and the run is
1303
+ * rejected; it never resolves to somebody else's definition.
1304
+ */
1305
+ declare interface KayAppAgentDefinitionRef {
1306
+ /** Brand only - erased at runtime, and unnameable (so unconstructable) from plugin code. */
1307
+ readonly [kayAppAgentDefinitionRefBrand]: "kay.app/agent-definition-ref";
1295
1308
  }
1296
1309
 
1297
- /** One stored session, as the granted corpus enumerates them. Keyed by its stable `sessionId`. */
1298
- declare interface KayAppCorpusSession {
1310
+ declare const kayAppAgentDefinitionRefBrand: unique symbol;
1311
+
1312
+ /** A newly persisted AgentSession. */
1313
+ declare interface KayAppCreatedSession {
1299
1314
  readonly sessionId: string;
1315
+ readonly title?: string | undefined;
1300
1316
  /**
1301
- * Who the session is for, as stamped when it was created: a person's own session (`user`), a
1302
- * spawned subagent, or a session Bonsai runs with nobody watching (`system`, `followup`). It lets
1303
- * a reader skip sessions without opening their transcripts. Absent when the index does not know
1304
- * it (a session older than origin stamping, or a row not yet rebuilt from its transcript): that
1305
- * is unknown, not `user`.
1317
+ * Whether a requested first turn actually started. Absent when no `message` was asked for.
1318
+ *
1319
+ * False means the session is open but empty: say so rather than claiming a running start that
1320
+ * did not happen. True means the turn began, not that it completed.
1306
1321
  */
1307
- readonly origin?: KayAppSessionOrigin | undefined;
1308
- /** Resolved session title from the live index, when one exists. */
1309
- readonly title?: string | undefined;
1310
- /** Session creation time in ISO-8601 UTC, when the index has it. */
1311
- readonly createdAt?: string | undefined;
1312
- /** Last conversation activity in ISO-8601 UTC, when the index has it. */
1313
- readonly updatedAt?: string | undefined;
1314
- /** Current execution directory, when the index has it. */
1315
- readonly cwd?: string | undefined;
1316
- /** Persisted project binding; `null` means explicitly unassigned. */
1317
- readonly projectId?: string | null | undefined;
1318
- /** Parent session for a spawned member, when lineage is indexed. */
1319
- readonly parentSessionId?: string | null | undefined;
1320
- /** Family root session identity, when lineage is indexed. */
1321
- readonly rootSessionId?: string | undefined;
1322
- }
1323
-
1324
- /** Cheap identity for the current contents of one stored session transcript. */
1325
- declare interface KayAppCorpusSourceMark {
1326
- readonly mtimeMs: number;
1327
- readonly sizeBytes: number;
1328
- /** Opaque content/source identity; absent on legacy or test corpus implementations. */
1329
- readonly sourceRevision?: string | undefined;
1322
+ readonly messageDelivered?: boolean | undefined;
1330
1323
  }
1331
1324
 
1332
1325
  /**
@@ -1356,10 +1349,17 @@ declare interface KayAppModelCompleteInput {
1356
1349
  /** Exact provider-qualified reference or `small`/`medium`/`large`/`ultra`. */
1357
1350
  readonly model: string;
1358
1351
  readonly thinkingLevel?: KayAppThinkingLevel;
1359
- /** Defaults to 2048; accepted range is 1–8192. */
1352
+ /** Defaults to 2048; accepted range is 1-8192. */
1360
1353
  readonly maxTokens?: number;
1361
- /** Defaults to 60000 ms; accepted range is 1000–120000 ms. */
1354
+ /** Defaults to 60000 ms; accepted range is 1000-120000 ms. */
1362
1355
  readonly timeoutMs?: number;
1356
+ /**
1357
+ * The session event this call answers. With one, the call's spend is charged to
1358
+ * `cause.sourceSessionId`, which must be a session one of this plugin's `sessionEvents` handlers
1359
+ * is handling right now (otherwise the call is `rejected`). Without one, the spend is the
1360
+ * plugin's own.
1361
+ */
1362
+ readonly cause?: KayAppSessionEventCause;
1363
1363
  }
1364
1364
 
1365
1365
  declare type KayAppModelCompleteOutcome = {
@@ -1433,13 +1433,14 @@ declare interface KayAppModelInfo {
1433
1433
  readonly releaseDate?: string;
1434
1434
  readonly composition?: "single" | "router" | "ensemble";
1435
1435
  /**
1436
- * Why the model is switched off right now, when a setting the person
1437
- * controls disables it: `privacy-setting` is Bonsai's switch that turns off
1438
- * hosted providers that store data. Bonsai never selects a disabled model
1439
- * and refuses a request on it, so a plugin should not offer or pin one.
1440
- * Absent means the model is not disabled.
1436
+ * Why the model is switched off right now. `privacy-setting` is Bonsai's
1437
+ * switch that turns off hosted providers that store data;
1438
+ * `subscription-reauth` means the provider's only credential is a
1439
+ * subscription the provider refused to renew, until the person reconnects it.
1440
+ * Bonsai never selects a disabled model and refuses a request on it, so a
1441
+ * plugin should not offer or pin one. Absent means the model is not disabled.
1441
1442
  */
1442
- readonly disabledBy?: "privacy-setting";
1443
+ readonly disabledBy?: "privacy-setting" | "subscription-reauth";
1443
1444
  }
1444
1445
 
1445
1446
  /** Input or output modality advertised by a model. */
@@ -1454,9 +1455,12 @@ declare interface KayAppModels {
1454
1455
  /**
1455
1456
  * Returns the four product model tiers, each with its live point-in-time resolution
1456
1457
  * when one is currently eligible right now. Re-fetch rather than cache across auth or
1457
- * precedence-config changes — the projection is checked-strength, never minting.
1458
+ * precedence-config changes - the projection is checked-strength, never minting.
1458
1459
  */
1459
- listTiers(): Promise<readonly KayAppModelTierInfo[]>;
1460
+ listTiers(options?: {
1461
+ /** Resolve each tier on this provider, the way a session pinned to it would. */
1462
+ readonly provider?: string;
1463
+ }): Promise<readonly KayAppModelTierInfo[]>;
1460
1464
  /**
1461
1465
  * Run one isolated, cost-accounted completion. Present only when the host composed a model
1462
1466
  * lane; each call authorizes a `models.complete` claim (kay.app) against the grant ledger.
@@ -1485,7 +1489,7 @@ declare interface KayAppModelScores {
1485
1489
  declare type KayAppModelTierId = "small" | "medium" | "large" | "ultra";
1486
1490
 
1487
1491
  /**
1488
- * The plugin-safe projection of one product model tier (small/medium/large/ultra —
1492
+ * The plugin-safe projection of one product model tier (small/medium/large/ultra -
1489
1493
  * see {@link KayAppModels.listTiers}), with its live point-in-time resolution when a model
1490
1494
  * is currently eligible for it. Deliberately has NO analogous per-model tier field on
1491
1495
  * {@link KayAppModelInfo}: a model's tier membership is carried-forward identity, not
@@ -1504,6 +1508,226 @@ declare interface KayAppModelTierInfo {
1504
1508
  };
1505
1509
  }
1506
1510
 
1511
+ /** An ephemeral one-shot agent definition. Identity and permission rules remain host-owned. */
1512
+ declare interface KayAppSessionAgentDefinition {
1513
+ readonly name: string;
1514
+ readonly description?: string;
1515
+ readonly icon?: string;
1516
+ readonly config: KayAppAgentDefinitionConfig;
1517
+ }
1518
+
1519
+ /**
1520
+ * One annotation on a session's log: what the person sees beside the conversation (its title, its
1521
+ * recap line, the suggested next steps, a work block's headline) and the facts behind them. Each
1522
+ * optional field follows one rule: OMITTED says nothing and leaves the standing value alone, while
1523
+ * an explicit value replaces it (`[]` withdraws the next steps, `false` clears a compaction offer).
1524
+ */
1525
+ declare interface KayAppSessionAnnotation {
1526
+ readonly titleChange: string | null;
1527
+ readonly summaryAddition: string | null;
1528
+ readonly nextSteps?: readonly string[] | undefined;
1529
+ /** A one-line label for the closed work block {@link workBlock} names. */
1530
+ readonly workHeadline?: string;
1531
+ readonly workHeadlineReview?: readonly ({
1532
+ readonly labelKind: "result" | "purpose";
1533
+ readonly text: string;
1534
+ readonly faultProbability: number | null;
1535
+ readonly accepted: boolean;
1536
+ readonly reason?: string;
1537
+ } | {
1538
+ readonly attempt: {
1539
+ readonly outcome: "none" | "rejected" | "error";
1540
+ };
1541
+ })[];
1542
+ readonly workBlock?: WorkBlockCoverage;
1543
+ readonly goodCompactionOpportunity?: boolean;
1544
+ /** The last entry the annotation reviewed: the transcript marker's anchor. */
1545
+ readonly reviewedThroughEntryId?: string;
1546
+ /** A tier the remaining work suits better, or null when the current one still fits. */
1547
+ readonly suggestedModelTier?: KayAppModelTierId | null;
1548
+ readonly outcomeVerdict?: KayAppSessionOutcomeVerdict | null;
1549
+ /** At most three; a verdict naming the annotated session itself is dropped. */
1550
+ readonly deferredVerdicts?: readonly KayAppSessionDeferredVerdict[];
1551
+ }
1552
+
1553
+ /** One stored session's spend, including the sessions it started. */
1554
+ declare interface KayAppSessionCost {
1555
+ readonly sessionId: string;
1556
+ readonly rootSessionId: string;
1557
+ /** When the read finished, ISO-8601 UTC. */
1558
+ readonly asOf: string;
1559
+ /** The days the read covered, and whether it stopped before the whole range. */
1560
+ readonly coverage: {
1561
+ readonly startDay: string;
1562
+ readonly endDay: string;
1563
+ readonly scan: {
1564
+ readonly complete: true;
1565
+ } | {
1566
+ readonly complete: false;
1567
+ readonly completeAfterDay: string;
1568
+ };
1569
+ readonly truncated: boolean;
1570
+ /** True when the model list was capped; the totals still count every call. */
1571
+ readonly modelInventoryTruncated?: boolean;
1572
+ };
1573
+ readonly total: KayAppSessionCostBreakdown;
1574
+ /** Calls the session made itself. */
1575
+ readonly direct: KayAppSessionCostBreakdown;
1576
+ /** Calls made by sessions it started. */
1577
+ readonly descendants: KayAppSessionCostBreakdown;
1578
+ /** Calls in the session family that name no session. */
1579
+ readonly unattributed: KayAppSessionCostBreakdown;
1580
+ readonly descendantSessionCount: number;
1581
+ readonly models: readonly KayAppSessionCostModelBreakdown[];
1582
+ }
1583
+
1584
+ /**
1585
+ * What `readCost` answers. `unavailable` covers a plugin without `sessions.read`, a host that records
1586
+ * no usage, an unknown or deleted session, and a read that failed; it is never zeros.
1587
+ */
1588
+ declare type KayAppSessionCostAnswer = {
1589
+ readonly status: "ok";
1590
+ readonly cost: KayAppSessionCost;
1591
+ } | {
1592
+ readonly status: "unavailable";
1593
+ readonly reason: string;
1594
+ };
1595
+
1596
+ /**
1597
+ * What a set of model calls cost. Measured dollars come from the provider; catalog estimates
1598
+ * price calls the provider did not bill directly; unknown calls have no price either way.
1599
+ */
1600
+ declare interface KayAppSessionCostBreakdown {
1601
+ readonly measuredUsd: number;
1602
+ readonly measuredCallCount: number;
1603
+ readonly catalogEstimateUsd: number;
1604
+ readonly catalogEstimateCallCount: number;
1605
+ readonly unknownCallCount: number;
1606
+ readonly callCount: number;
1607
+ readonly tokens: KayAppSessionCostTokens;
1608
+ }
1609
+
1610
+ declare interface KayAppSessionCostModelBreakdown {
1611
+ /** Null when older telemetry has no model identity. */
1612
+ readonly model: string | null;
1613
+ /** The one provider that served this model's calls; absent when unattributed or split. */
1614
+ readonly provider?: string;
1615
+ readonly total: KayAppSessionCostBreakdown;
1616
+ }
1617
+
1618
+ /** Token counts across a set of model calls. */
1619
+ declare interface KayAppSessionCostTokens {
1620
+ readonly input: number;
1621
+ readonly output: number;
1622
+ readonly cacheRead: number;
1623
+ readonly cacheWrite: number;
1624
+ }
1625
+
1626
+ /** A verdict about an EARLIER session, filed on the annotated one and naming its subject. */
1627
+ declare interface KayAppSessionDeferredVerdict {
1628
+ readonly subjectSessionId: string;
1629
+ readonly verdict: KayAppSessionVerdict;
1630
+ readonly confidence: KayAppSessionVerdictConfidence;
1631
+ readonly basis: string;
1632
+ readonly rubricVersion: number;
1633
+ }
1634
+
1635
+ /** One bounded page from the host's stored transcript reader. */
1636
+ declare interface KayAppSessionEntryBatch {
1637
+ readonly entries: readonly TranscriptEntry[];
1638
+ /** Opaque JSON cursor after the physical page; only the host may interpret it or open its path. */
1639
+ readonly cursor: JsonValue_3;
1640
+ /** Opaque cursor at the physical page start, for a partial logical chunk. */
1641
+ readonly pageStartCursor?: JsonValue_3;
1642
+ readonly mode: "replace" | "append";
1643
+ /**
1644
+ * `record-too-large`: a record longer than the page that the host could not step over, because
1645
+ * its end is not written yet or lies past the host's scan limit.
1646
+ */
1647
+ readonly status: "complete" | "more" | "awaiting-append" | "record-too-large";
1648
+ /** Present when a caller supplied `throughEntryId`. */
1649
+ readonly anchorFound?: boolean;
1650
+ /** Records on this page the host could not parse; its other entries are returned. */
1651
+ readonly malformedRecords: number;
1652
+ /**
1653
+ * Records longer than the page that this read stepped over without parsing them: at most one,
1654
+ * and the page then holds no entries. When the caller's `throughEntryId` is inside it,
1655
+ * `anchorFound` is true and the cursor is after it.
1656
+ */
1657
+ readonly oversizedRecords?: number;
1658
+ /** Bytes of the stepped-over record, when there is one. */
1659
+ readonly oversizedRecordBytes?: number;
1660
+ }
1661
+
1662
+ /**
1663
+ * The cause a plugin supplies to {@link KayAppAgents.run} (G1, 2026-09) - what a
1664
+ * `app.sessionEvents.subscribe` handler is reacting to. This is the WHOLE cause the plugin
1665
+ * states; the host derives `plugin` itself from the calling plugin id (never taken from this
1666
+ * object), mints a `traceId`, and stamps the spawned session's provenance with everything here.
1667
+ *
1668
+ * TWO KINDS (G5, 2026-09). `kind` omitted or `"session-event"` is the original, LIVE shape: a
1669
+ * `sessionEvents.subscribe` handler reacting to a published event, which the `event` field names.
1670
+ * `kind: "backfill"` is a plugin's own HISTORICAL-session sweep - run at its own initiative (over
1671
+ * sessions it discovers through its granted `KayAppSessions`, not from a published event), so there
1672
+ * is no `event` to carry. A backfill cause should always supply `dedupeKey` (by convention
1673
+ * `` `backfill:${sessionId}` ``, never enforced by the host) so a sweep can never double-run the
1674
+ * same historical session across daemon restarts.
1675
+ */
1676
+ declare type KayAppSessionEventCause = {
1677
+ readonly kind?: "session-event";
1678
+ /** This plugin's own name for the handler making this run, e.g. `"work-record"`. Not minted. */
1679
+ readonly handler: string;
1680
+ /** The session whose event caused this run - ordinarily the event's own `sessionId`. */
1681
+ readonly sourceSessionId: string;
1682
+ readonly event: {
1683
+ readonly type: KayAppSessionEventType;
1684
+ readonly entryId: string;
1685
+ /**
1686
+ * The delivered event's own {@link KayAppTurnSettledSessionEvent.runId}, when the handler
1687
+ * has one to relay - always present for a `turn-settled` event, legitimately absent for a
1688
+ * `phase-shift` one (an observation can span more than one run). Relay it verbatim; never
1689
+ * substitute a run id resolved another way.
1690
+ */
1691
+ readonly runId?: string;
1692
+ /** Exact prior persisted boundary for a projected human-message event; null means empty history. */
1693
+ readonly throughEntryId?: string | null;
1694
+ };
1695
+ /**
1696
+ * Exact-match dedupe key. The host REFUSES a second run carrying the same key outright (a
1697
+ * rejected outcome, never a silent skip), so a handler can tell a genuine duplicate from an
1698
+ * ordinary rejection. Omit to admit every call unconditionally.
1699
+ */
1700
+ readonly dedupeKey?: string;
1701
+ } | {
1702
+ readonly kind: "backfill";
1703
+ readonly handler: string;
1704
+ readonly sourceSessionId: string;
1705
+ readonly dedupeKey?: string;
1706
+ };
1707
+
1708
+ /**
1709
+ * A closed, extensible union: a projected human or persisted assistant message, a settled turn, an accepted phase-shift
1710
+ * observation, or a projected interface action. They share one subscribable set now that there is
1711
+ * no dispatcher chaining one job's completion into another's `when`. Adding a type is additive,
1712
+ * never breaking: `assistant-message` is the fifth.
1713
+ */
1714
+ declare type KayAppSessionEventType = "human-message" | "assistant-message" | "turn-settled" | "phase-shift" | "ui-action";
1715
+
1716
+ /** Index rows, most recently active first. Deleted sessions are never listed. */
1717
+ declare interface KayAppSessionList {
1718
+ readonly sessions: readonly KayAppStoredSession[];
1719
+ /** How many sessions the index lists in total; present only for the offset form. */
1720
+ readonly totalCount?: number;
1721
+ }
1722
+
1723
+ /** One page of the session index by position, or the rows for these ids. */
1724
+ declare type KayAppSessionListRequest = {
1725
+ readonly offset: number;
1726
+ readonly limit: number;
1727
+ } | {
1728
+ readonly sessionIds: readonly string[];
1729
+ };
1730
+
1507
1731
  declare type KayAppSessionOrigin = {
1508
1732
  readonly kind: "user";
1509
1733
  readonly surface?: string | undefined;
@@ -1519,6 +1743,448 @@ declare type KayAppSessionOrigin = {
1519
1743
  readonly forkedAtEntryId?: string | undefined;
1520
1744
  };
1521
1745
 
1746
+ /** A judgment of whether the annotated session's own work served the user. */
1747
+ declare interface KayAppSessionOutcomeVerdict {
1748
+ readonly verdict: KayAppSessionVerdict;
1749
+ readonly confidence: KayAppSessionVerdictConfidence;
1750
+ /** The stated evidence. The host cuts an over-long basis on a word boundary. */
1751
+ readonly basis: string;
1752
+ /** User-correction turns counted in the transcript. */
1753
+ readonly correctionsObserved: number;
1754
+ /** Visible retry loops counted in the transcript. */
1755
+ readonly retriesObserved: number;
1756
+ readonly rubricVersion: number;
1757
+ }
1758
+
1759
+ /**
1760
+ * One bounded page of a session's stored transcript, oldest first, or why there is none. Pass
1761
+ * `cursor` back for the next page. `replace` means the page starts over from the first record: the
1762
+ * first page always does, and a later one does when the session was written to after your first
1763
+ * page was read and a write changed a record before the cursor, or when its storage was replaced.
1764
+ * Anything derived from earlier pages is then stale; the `replace` page is the new first page.
1765
+ */
1766
+ declare type KayAppSessionPage = {
1767
+ readonly kind: "page";
1768
+ readonly items: readonly KayAppSessionPageItem[];
1769
+ /** Opaque JSON: only the host interprets it. */
1770
+ readonly cursor: JsonValue_3;
1771
+ readonly mode: "replace" | "append";
1772
+ /** `more`: read again from `cursor`. `complete`: nothing more is stored. */
1773
+ readonly status: "more" | "complete";
1774
+ } | KayAppSessionPageFailure;
1775
+
1776
+ /**
1777
+ * Why a session's page could not be read: `unknown` (no index row, or a deleted one), `missing`
1778
+ * (indexed, but its storage is gone), `unrecognized` (a chat still on its legacy `.jsonl`, which
1779
+ * converts on its next open), `unreadable` (a permission refusal, an I/O error or a store the
1780
+ * host cannot read, with its reason), `busy` (the host's reads are overloaded, out of memory or
1781
+ * timed out; the same read may succeed in a moment), or `escaped` (the index row resolves outside
1782
+ * this install's session storage, so nothing was read).
1783
+ */
1784
+ declare type KayAppSessionPageFailure = {
1785
+ readonly kind: "unknown";
1786
+ } | {
1787
+ readonly kind: "missing";
1788
+ } | {
1789
+ readonly kind: "unrecognized";
1790
+ } | {
1791
+ readonly kind: "unreadable";
1792
+ readonly reason: string;
1793
+ } | {
1794
+ readonly kind: "busy";
1795
+ readonly reason: string;
1796
+ } | {
1797
+ readonly kind: "escaped";
1798
+ };
1799
+
1800
+ /**
1801
+ * One item of a {@link KayAppSessionPage}, in stored order: an entry, or a stored record that did
1802
+ * not parse (`unreadable`, with the storage row's id), which still takes its place. Rely on
1803
+ * `entry`, `preview`, `unreadable` and `entryId`; `commitSeq` and `commitIndex` only order items
1804
+ * within one session's pages and are not stable across hosts.
1805
+ *
1806
+ * An entry over 256 KiB stored is its preview: its long text is cut to about its first 8 KB and
1807
+ * its images and files are replaced, and `preview.bytes` is the whole entry's stored size. Body
1808
+ * references stay with the host, so no SDK read returns the rest yet.
1809
+ */
1810
+ declare type KayAppSessionPageItem = (Omit<Extract<TranscriptPageItem, {
1811
+ readonly entry: unknown;
1812
+ }>, "bodies"> & {
1813
+ readonly preview?: {
1814
+ readonly bytes: number;
1815
+ };
1816
+ }) | Extract<TranscriptPageItem, {
1817
+ readonly unreadable: unknown;
1818
+ }>;
1819
+
1820
+ /**
1821
+ * What one headless system run reports back. The run's spend is read from the
1822
+ * ledger after the turn settles; `cost` is absent when no spend rows were
1823
+ * found and `complete: false` marks a run with at least one unpriced turn.
1824
+ */
1825
+ declare interface KayAppSessionRunBase {
1826
+ readonly kind: "ran";
1827
+ readonly sessionId: string;
1828
+ /** The run that produced this outcome, when the owning path can name it. */
1829
+ readonly runId?: string | undefined;
1830
+ /** Host-captured provenance for the producing session, retained for direct store writes. */
1831
+ readonly provenanceCapture?: Record<string, unknown> | undefined;
1832
+ /** The run's final output text (the headless session's reply channel). */
1833
+ readonly output: string;
1834
+ /** Present when a structured completion was requested and the run completed. */
1835
+ readonly result?: JsonValue_3;
1836
+ readonly errorMessage?: string | undefined;
1837
+ /** Attested live host-tool roster when the caller requested one explicitly. */
1838
+ readonly activeToolNames?: readonly KayAppSessionRunHostToolName[] | undefined;
1839
+ readonly cost?: {
1840
+ readonly usd: number;
1841
+ readonly inputTokens: number;
1842
+ readonly outputTokens: number;
1843
+ readonly complete: boolean;
1844
+ } | undefined;
1845
+ }
1846
+
1847
+ /** How a headless system run returns its terminal answer. */
1848
+ declare type KayAppSessionRunCompletion = {
1849
+ readonly kind: "text";
1850
+ } | {
1851
+ readonly kind: "structured";
1852
+ /** JSON Schema for the required value returned through `result`. */
1853
+ readonly schema: JsonSchema;
1854
+ };
1855
+
1856
+ /** Provider-neutral recorded classification; an unclassified failure omits the field. */
1857
+ declare type KayAppSessionRunFailureReason = Exclude<RunFailureReason, "unknown">;
1858
+
1859
+ /**
1860
+ * The identity of a failed run's retained failure: the same ref the runtime keeps on the
1861
+ * session and the automation run. A workflow that fails BECAUSE this run failed passes it as
1862
+ * its error's `cause` (`{ cause: { failureRef } }`), and the host reports that failure, not a
1863
+ * guess from whichever run settled last.
1864
+ */
1865
+ declare interface KayAppSessionRunFailureRef {
1866
+ readonly authority: string;
1867
+ readonly id: string;
1868
+ }
1869
+
1870
+ /** One host-tool name in a one-shot system run's explicit ceiling. */
1871
+ declare type KayAppSessionRunHostToolName = string;
1872
+
1873
+ /** The one-shot headless run request shared by `sessions.run` and workflow contexts. */
1874
+ declare interface KayAppSessionRunInput {
1875
+ /** Attribution slug (`^[a-z][a-z0-9-]*$`) naming what this run is for. */
1876
+ readonly purpose: string;
1877
+ readonly instructions: string;
1878
+ /** Defaults to ordinary reply text when omitted. */
1879
+ readonly completion?: KayAppSessionRunCompletion | undefined;
1880
+ readonly label?: string | undefined;
1881
+ /**
1882
+ * Stable identity of this call within one run. Two calls with the same key are the same unit
1883
+ * of work: on resume after a crash, a settled result for the key is returned instead of running
1884
+ * the agent again. Omit it and the call is never memoized: it re-runs if the run resumes.
1885
+ *
1886
+ * Only a workflow's `runAgent` reads this. `sessions.run` has no run to resume, so it ignores
1887
+ * the key entirely.
1888
+ *
1889
+ * The key is YOUR declaration, so it must name the WORK and nothing else. Anything regenerated
1890
+ * per attempt (a UUID, a timestamp, a nonce spliced into the prompt) makes every key unique and
1891
+ * memoizes nothing. Derive it from the item being worked on: the bucket key, the source id, a
1892
+ * constant for a stage that happens once.
1893
+ *
1894
+ * The same key twice inside one run is legitimate and is NOT collapsed: a retry of a stage that
1895
+ * failed is a second unit of work, and the engine matches the i-th call for a key to the i-th
1896
+ * recorded result. Distinct work must therefore carry distinct keys, because reusing one key
1897
+ * for two different items would hand the first item's result to the second on resume.
1898
+ *
1899
+ * At most 200 characters, and non-empty once trimmed; anything else is rejected at the call.
1900
+ */
1901
+ readonly key?: string | undefined;
1902
+ readonly cwd?: string | undefined;
1903
+ /**
1904
+ * How long the run may take. What an omitted value means belongs to the door you called, and
1905
+ * the two doors differ:
1906
+ *
1907
+ * - `sessions.run` - omitted is five minutes, and any value is clamped into [10 s, 600 s].
1908
+ * This door always bounds its runs, so `null` is rejected.
1909
+ * - a workflow's `runAgent` - omitted means the agent runs until it FINISHES, however long that
1910
+ * takes. A number bounds it (unclamped, up to the protocol's one-hour maximum), and `null` is
1911
+ * the explicit spelling of the same "no clock" the omitted form already gives you.
1912
+ */
1913
+ readonly timeoutMs?: number | null | undefined;
1914
+ /**
1915
+ * Absolute epoch-millisecond boundary for admission plus execution. The host starts a turn
1916
+ * only when one full `timeoutMs` still fits strictly before this deadline, so a run with no
1917
+ * clock cannot carry one - it has no turn length to fit.
1918
+ */
1919
+ readonly deadlineAtMs?: number | undefined;
1920
+ /**
1921
+ * Explicit host-tool roster for this one-shot run. The host enforces it as a subtractive
1922
+ * ceiling; reserved session-builtins such as `submit_final` remain available. The caller owns
1923
+ * any replay-safety policy for the names it supplies.
1924
+ */
1925
+ readonly activeToolNames?: readonly KayAppSessionRunHostToolName[] | undefined;
1926
+ /**
1927
+ * The run's model, as either an exact pin (a provider-qualified reference from
1928
+ * `KayAppModels.list`) or a tier word (`small`/`medium`/`large`/`ultra` -
1929
+ * see `KayAppModels.listTiers`); absent, the daemon resolves
1930
+ * the configured default. A tier word resolves through the same chokepoint every
1931
+ * other tier selection does - the daemon picks the concrete model, never the
1932
+ * plugin. An unavailable pin fails the run rather than silently substituting.
1933
+ */
1934
+ readonly model?: string | undefined;
1935
+ /** Pin the run's thinking level; absent, the daemon resolves its default. */
1936
+ readonly thinkingLevel?: KayAppThinkingLevel | undefined;
1937
+ /**
1938
+ * Which agent runs this one-shot, in either of the two forms a plugin may name one.
1939
+ *
1940
+ * An INLINE {@link KayAppSessionAgentDefinition} describes an agent for this run alone: the
1941
+ * host stamps its identity, accepts no permission rules, and the definition dies with the run.
1942
+ * It stays for one-shot callers with nothing to reuse.
1943
+ *
1944
+ * A {@link KayAppAgentDefinitionRef} names one of THIS plugin's definitions registered during
1945
+ * activation, which may carry permission rules and may own its own `completion` contract.
1946
+ * When the referenced definition owns a completion, a run-level {@link completion} is
1947
+ * REJECTED rather than merged - see {@link KayAppAgentDefinition.completion}.
1948
+ *
1949
+ * Absent, the run takes the host's default agent, unchanged.
1950
+ */
1951
+ readonly agent?: KayAppSessionAgentDefinition | KayAppAgentDefinitionRef | undefined;
1952
+ }
1953
+
1954
+ declare type KayAppSessionRunOutcome = (KayAppSessionRunBase & {
1955
+ readonly state: "failed";
1956
+ /** The retained failure record, absent when the runtime kept none for this run. */
1957
+ readonly failure?: (RunFailureRecord & {
1958
+ readonly retryable: boolean;
1959
+ }) | undefined;
1960
+ /** The retained failure's identity, when the runtime kept one for this run. */
1961
+ readonly failureRef?: KayAppSessionRunFailureRef | undefined;
1962
+ /** Present when the runtime could classify the failure. */
1963
+ readonly failureReason?: KayAppSessionRunFailureReason | undefined;
1964
+ /** Bounded provider-suggested delay before retrying this terminal failure. */
1965
+ readonly retryAfterMs?: number | undefined;
1966
+ }) | (KayAppSessionRunBase & {
1967
+ readonly state: "completed" | "cancelled";
1968
+ readonly failureReason?: never;
1969
+ }) | {
1970
+ readonly kind: "unavailable";
1971
+ }
1972
+ /** The host refused the run - pool exhausted or invalid input. */
1973
+ | {
1974
+ readonly kind: "rejected";
1975
+ readonly reason: string;
1976
+ }
1977
+ /**
1978
+ * `agents.run`-only (G1, 2026-09): `cause.dedupeKey` matched an already-admitted run.
1979
+ * `existingSessionId` names that run's session so a handler can look up its result instead of
1980
+ * treating this as an ordinary rejection. `sessions.run`/`workflows` never produce
1981
+ * this case - they carry no `cause.dedupeKey` concept - so their existing exhaustive switches
1982
+ * are unaffected in practice; only a switch reached through `agents.run`'s outcome need add it.
1983
+ */
1984
+ | {
1985
+ readonly kind: "deduplicated";
1986
+ readonly existingSessionId: string;
1987
+ };
1988
+
1989
+ /** Settled run outcomes of one session, tallied from its log. */
1990
+ declare interface KayAppSessionRunTally {
1991
+ readonly completed: number;
1992
+ readonly interrupted: number;
1993
+ readonly cancelled: number;
1994
+ readonly failed: number;
1995
+ }
1996
+
1997
+ /**
1998
+ * Stored conversation reads and session operations. Reads check `sessions.read`; actions retain
1999
+ * their separate `sessions.create`, `sessions.update`, and `sessions.run` claims. Control methods
2000
+ * are absent when the host composed no session-control lane. History is raw and un-redacted.
2001
+ * `readEntries` may materialize a whole session; use bounded reads for bounded allocation.
2002
+ */
2003
+ declare interface KayAppSessions {
2004
+ /** Page invocation leads under the live grant; inspect exclusions even on available empty pages. */
2005
+ listResourceInvocations(query: CorpusResourceInvocationQuery): Promise<CorpusResourceInvocationPage>;
2006
+ /** Enumerate every stored session, newest-first. */
2007
+ listSessions(): AsyncIterable<KayAppStoredSession>;
2008
+ /**
2009
+ * Yield one session's full entry log oldest->newest; an unknown id yields nothing. Treat the
2010
+ * entries as read-only: for a session the daemon holds in memory they are its live objects.
2011
+ */
2012
+ readEntries(sessionId: string): AsyncIterable<TranscriptEntry>;
2013
+ /**
2014
+ * Active-branch entries from the latest canonical human turn opener (send companions included)
2015
+ * through the anchor, oldest first. Mid-turn steers and machine wakes remain inside that window;
2016
+ * attachment-only openers and fresh card answers count. Missing sessions/anchors return [];
2017
+ * unsupported hosts may omit it.
2018
+ * Reads never fall back to materializing the full log.
2019
+ */
2020
+ readLatestHumanWindow?(sessionId: string, options?: {
2021
+ readonly throughEntryId?: string;
2022
+ }): Promise<readonly TranscriptEntry[]>;
2023
+ /**
2024
+ * What one stored session cost, which models served it, and from which providers. A session's
2025
+ * cost is part of reading it, so this checks `sessions.read` like the other reads (SDK 0.17.4).
2026
+ * Never rejects: anything it cannot answer is `unavailable`. Unsupported hosts may omit it.
2027
+ */
2028
+ readCost?(sessionId: string): Promise<KayAppSessionCostAnswer>;
2029
+ /**
2030
+ * Read one bounded page of a session's stored transcript. The host resolves `sessionId` to its
2031
+ * authoritative indexed path and validates the opaque cursor before reading. When
2032
+ * `throughEntryId` is supplied, the page ends at that entry and the cursor stays at the start of
2033
+ * the commit holding it: the commit's other entries are returned for the caller to filter, and
2034
+ * the next page replays that commit. A page can hold no entries at all (storage records with no
2035
+ * entry) while more follows; a record longer than the page is stepped over and counted in
2036
+ * `oversizedRecords`.
2037
+ */
2038
+ readEntryBatch?(sessionId: string, options?: {
2039
+ readonly cursor?: JsonValue_3;
2040
+ readonly throughEntryId?: string;
2041
+ /** Host-only cancellation for the bounded physical read. */
2042
+ readonly signal?: AbortSignal;
2043
+ }): Promise<KayAppSessionEntryBatch>;
2044
+ /**
2045
+ * Read one page of a session's stored transcript (SDK 0.19.2): every record, at most 256 records
2046
+ * and 1 MiB per page, with an entry over 256 KiB returned as its preview (see
2047
+ * {@link KayAppSessionPageItem}). The host resolves the id through its session index (a deleted
2048
+ * session is `unknown`), checks the storage lies inside this install's session storage, and
2049
+ * answers a session it cannot read as a typed failure rather than a rejection. Checked against
2050
+ * `sessions.read` at every call, a continuation included. Unsupported hosts may omit it.
2051
+ */
2052
+ readPage?(sessionId: string, options?: {
2053
+ readonly cursor?: JsonValue_3;
2054
+ }): Promise<KayAppSessionPage>;
2055
+ /**
2056
+ * One page of the session index, or the rows for given ids (SDK 0.19.2), at most 500 rows or
2057
+ * ids per call: ids past that are dropped, so page by offset/limit or chunk the ids. Checked
2058
+ * against `sessions.read`. Unsupported hosts may omit it.
2059
+ */
2060
+ listSessionPage?(request: KayAppSessionListRequest): Promise<KayAppSessionList>;
2061
+ /**
2062
+ * Read a cheap transcript change marker without loading the entry log. Unknown or deleted
2063
+ * sessions yield `undefined`.
2064
+ */
2065
+ readSessionSourceMark(sessionId: string): Promise<KayAppSessionSourceMark | undefined>;
2066
+ /**
2067
+ * The session's standing recap, run tally and model choice, folded by the host from the
2068
+ * session's own log. Checked against `sessions.read`. An unknown session resolves `undefined`.
2069
+ */
2070
+ readSessionState?(sessionId: string): Promise<KayAppSessionState | undefined>;
2071
+ /**
2072
+ * Write one annotation onto a session's log. Checked against `sessions.annotate`, and only for
2073
+ * a session whose event one of this plugin's `sessionEvents` handlers is handling right now: a
2074
+ * call for any other session, or after the handler returned, rejects. The host applies its own
2075
+ * bounds to every verdict. `judgeModel` names the `provider/modelId` that rendered the verdicts,
2076
+ * when it is not the session's own model.
2077
+ */
2078
+ annotate?(sessionId: string, annotation: KayAppSessionAnnotation, options?: {
2079
+ readonly judgeModel?: string;
2080
+ }): Promise<void>;
2081
+ /**
2082
+ * Ask the host to compact a session's context now. Checked against `sessions.compact`, bound
2083
+ * like {@link annotate}. Resolves `false`, a normal answer, when the person has not allowed it or
2084
+ * the context is too empty to be worth a compaction; `true` once it compacted. Rejects only when
2085
+ * an allowed compaction failed.
2086
+ */
2087
+ compact?(sessionId: string): Promise<boolean>;
2088
+ create?(input: {
2089
+ /** Omit to inherit the opener's cwd, unless an explicit project supplies its default. */
2090
+ readonly cwd?: string;
2091
+ /** Omit to inherit the opener; null explicitly selects no project. */
2092
+ readonly projectId?: string | null;
2093
+ readonly title?: string | undefined;
2094
+ /**
2095
+ * The new session's model, as a tier word (`small`, `medium`, `large`, `ultra`): the daemon
2096
+ * picks the concrete model through the same tier resolution every other tier choice takes.
2097
+ * Absent, the person's own selection applies, so a session a plugin opens on its own account
2098
+ * runs on whatever they happen to be using, Ultra included. Work that does not need a strong
2099
+ * model names a tier. A tier only: an exact model pin is not offered here.
2100
+ */
2101
+ readonly tier?: KayAppModelTierId | undefined;
2102
+ /**
2103
+ * The session asking for this one, so the daemon can record which session opened it.
2104
+ * Pass the calling tool's own `ctx.sessionId` and nothing else: the daemon vets the id
2105
+ * against its live sessions and drops an edge it cannot confirm, so an invented value
2106
+ * buys nothing.
2107
+ */
2108
+ readonly openedBySessionId?: string;
2109
+ /**
2110
+ * A first user turn to deliver into the new session, so it opens already working rather than
2111
+ * blank. Absent leaves it empty and waiting.
2112
+ *
2113
+ * Resolves once the turn has STARTED, never once it has finished: the caller is mid-turn in
2114
+ * its own session, and waiting on another agent's whole answer would freeze the conversation
2115
+ * that opened the tab. Check {@link KayAppCreatedSession.messageDelivered} to see whether it
2116
+ * actually started.
2117
+ */
2118
+ readonly message?: string;
2119
+ }): Promise<{
2120
+ readonly kind: "created";
2121
+ readonly session: KayAppCreatedSession;
2122
+ } | {
2123
+ readonly kind: "unavailable";
2124
+ }>;
2125
+ /**
2126
+ * Admit one approved command into a blank session this capability instance created. The host
2127
+ * resolves the command against the session's live command index and returns once it is admitted,
2128
+ * not when the model turn finishes. Implementations may omit this on older hosts.
2129
+ */
2130
+ start?(input: {
2131
+ readonly sessionId: string;
2132
+ readonly command: string;
2133
+ readonly typedName: string;
2134
+ readonly argsText: string;
2135
+ }): Promise<{
2136
+ readonly kind: "started";
2137
+ } | {
2138
+ readonly kind: "unavailable";
2139
+ }>;
2140
+ /**
2141
+ * Change this tool call's current session project without changing its working directory.
2142
+ * Checked against `sessions.update`. The host-stamped context selects the session; plugins
2143
+ * cannot target an arbitrary session id.
2144
+ */
2145
+ setProject?(input: {
2146
+ readonly projectId: string | null;
2147
+ }, context: KayAppToolContext): Promise<{
2148
+ readonly kind: "updated";
2149
+ readonly projectId: string | null;
2150
+ readonly cwd: string;
2151
+ } | {
2152
+ readonly kind: "unavailable";
2153
+ }>;
2154
+ /**
2155
+ * Run one hidden headless system session through Bonsai's harness and resolve
2156
+ * with its final output - the sole sanctioned way for a `kay.app` plugin to
2157
+ * spend model tokens outside a session-event handler. Checked per call against
2158
+ * the `sessions.run` claim. A plugin may request a model/tier and supply
2159
+ * a strict ephemeral agent definition, but the host validates and resolves
2160
+ * both, strips permission authority, and stamps the spend surface as
2161
+ * `plugin/<pluginId>/<purpose>`, so every run is ledger-attributed to the
2162
+ * plugin by construction.
2163
+ */
2164
+ run?(input: KayAppSessionRunInput): Promise<KayAppSessionRunOutcome>;
2165
+ }
2166
+
2167
+ /** Cheap identity for the current contents of one stored session transcript. */
2168
+ declare interface KayAppSessionSourceMark {
2169
+ readonly mtimeMs: number;
2170
+ readonly sizeBytes: number;
2171
+ /** Opaque content/source identity; absent on legacy or test corpus implementations. */
2172
+ readonly sourceRevision?: string | undefined;
2173
+ }
2174
+
2175
+ /** A few facts folded from one session's own log, without reading the log. */
2176
+ declare interface KayAppSessionState {
2177
+ /** The recap line the person is reading now; absent when the session has none yet. */
2178
+ readonly standingRecap?: string;
2179
+ /** Absent when the host cannot answer for the session. */
2180
+ readonly runTally?: KayAppSessionRunTally;
2181
+ /** The session's model choice when it is a tier; absent for an exact model or none. */
2182
+ readonly modelSelection?: {
2183
+ readonly tierId: KayAppModelTierId;
2184
+ readonly provider?: string;
2185
+ };
2186
+ }
2187
+
1522
2188
  export declare interface KayAppSessionSummaryChunk {
1523
2189
  readonly goal: string;
1524
2190
  readonly work: readonly string[];
@@ -1601,6 +2267,12 @@ export declare interface KayAppSessionSummaryResult {
1601
2267
  readonly continuation?: KayAppSessionSummaryContinuation;
1602
2268
  }
1603
2269
 
2270
+ /** How a session's work is judged to have served the user. `"unclear"` is a real answer, not a failure. */
2271
+ declare type KayAppSessionVerdict = "good" | "mixed" | "bad" | "unclear";
2272
+
2273
+ /** The judge's own certainty: a tuning filter, never a weight the reader applies. */
2274
+ declare type KayAppSessionVerdictConfidence = "low" | "medium" | "high";
2275
+
1604
2276
  export declare interface KayAppSessionWorkSummary {
1605
2277
  readonly goal: string;
1606
2278
  readonly work: readonly string[];
@@ -1609,14 +2281,49 @@ export declare interface KayAppSessionWorkSummary {
1609
2281
  readonly openWork: readonly string[];
1610
2282
  }
1611
2283
 
1612
- /**
1613
- * The plugin-facing `kay.app` models contract (`app.models`): the plugin-safe model catalog and
1614
- * tiers, image-model resolution, the direct-completion broker, and the reasoning-effort ladder that
1615
- * sessions and completions share. Changes to this contract belong in this module.
1616
- */
2284
+ /** One indexed stored conversation, keyed by its stable `sessionId`. */
2285
+ declare interface KayAppStoredSession {
2286
+ readonly sessionId: string;
2287
+ /**
2288
+ * Who the session is for, as stamped when it was created: a person's own session (`user`), a
2289
+ * spawned subagent, or a session Bonsai runs with nobody watching (`system`, `followup`). It lets
2290
+ * a reader skip sessions without opening their transcripts. Absent when the index does not know
2291
+ * it (a session older than origin stamping, or a row not yet rebuilt from its transcript): that
2292
+ * is unknown, not `user`.
2293
+ */
2294
+ readonly origin?: KayAppSessionOrigin | undefined;
2295
+ /** Resolved session title from the live index, when one exists. */
2296
+ readonly title?: string | undefined;
2297
+ /** Session creation time in ISO-8601 UTC, when the index has it. */
2298
+ readonly createdAt?: string | undefined;
2299
+ /** Last conversation activity in ISO-8601 UTC, when the index has it. */
2300
+ readonly updatedAt?: string | undefined;
2301
+ /** Current execution directory, when the index has it. */
2302
+ readonly cwd?: string | undefined;
2303
+ /** Persisted project binding; `null` means explicitly unassigned. */
2304
+ readonly projectId?: string | null | undefined;
2305
+ /** Parent session for a spawned member, when lineage is indexed. */
2306
+ readonly parentSessionId?: string | null | undefined;
2307
+ /** Family root session identity, when lineage is indexed. */
2308
+ readonly rootSessionId?: string | undefined;
2309
+ }
2310
+
1617
2311
  /** Bonsai's reasoning-effort ladder, in ascending order. */
1618
2312
  declare type KayAppThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
1619
2313
 
2314
+ /**
2315
+ * The host-stamped per-call context an app-contributed tool's `execute` receives. The app
2316
+ * activation is app-lifetime code serving EVERY session, so unlike a kernel tool (whose session
2317
+ * is ambient) it must be told which session is calling - the same host-stamping rule as
2318
+ * `ctx.sessionId` on an app URI module's `UriResolveContext`, and never caller-influenced.
2319
+ */
2320
+ declare interface KayAppToolContext {
2321
+ /** The calling session's stable id. */
2322
+ readonly sessionId: string;
2323
+ /** The calling session's live, re-rootable working directory at execute time. */
2324
+ readonly cwd: string;
2325
+ }
2326
+
1620
2327
  /** Applies a KeyOf action to the given type. */
1621
2328
  declare function KeyOf<Type extends TSchema>(type: Type, options?: TSchemaOptions): TKeyOf_2<Type>;
1622
2329
 
@@ -2348,7 +3055,7 @@ declare type ReadonlyOptionalKeys<Properties extends TProperties, Result extends
2348
3055
  declare const ReadonlyType: typeof ReadonlyObject;
2349
3056
 
2350
3057
  /** Return the same source revision used by {@link summarizeSession}, without model calls. */
2351
- export declare function readSessionSummaryRevision(corpus: KayAppCorpus, sessionId: string): Promise<string | undefined>;
3058
+ export declare function readSessionSummaryRevision(storedSessions: KayAppSessions, sessionId: string): Promise<string | undefined>;
2352
3059
 
2353
3060
  /** Creates a Record type. */
2354
3061
  declare function Record_2<Key extends TSchema, Value extends TSchema>(key: Key, value: Value, options?: TObjectOptions): TRecordAction<Key, Value>;
@@ -2437,6 +3144,9 @@ declare function ReturnTypeDeferred<Type extends TSchema>(type: Type, options?:
2437
3144
  */
2438
3145
  declare const RUN_CONTINUATION_CARRIER_CUSTOM_TYPE = "herd_run_continuation";
2439
3146
 
3147
+ /** Observed cause of a failed request or interrupted run. */
3148
+ declare const RUN_FAILURE_REASONS: readonly ["account_unreachable", "auth", "cancelled", "content_blocked", "context_overflow", "final_output_missing", "invalid_request", "model_disabled", "model_unavailable", "network", "organization_unavailable", "overloaded", "quota_exhausted", "rate_limit", "runtime_interrupted", "safeguard_block", "seat_unpaid", "server_error", "sign_in_required", "stream_interrupted", "timeout", "unknown"];
3149
+
2440
3150
  /**
2441
3151
  * What a {@link RUN_CONTINUATION_CARRIER_CUSTOM_TYPE} carrier records about the failed turns it
2442
3152
  * continues.
@@ -2458,12 +3168,80 @@ declare type RunContinuationCarrierMessage = CustomMessage<RunContinuationCarrie
2458
3168
  readonly display: false;
2459
3169
  };
2460
3170
 
3171
+ declare type RunFailureCause = z.infer<typeof runFailureCauseSchema>;
3172
+
3173
+ declare const runFailureCauseSchema: z.ZodObject<{
3174
+ reason: z.ZodEnum<{
3175
+ cancelled: "cancelled";
3176
+ timeout: "timeout";
3177
+ account_unreachable: "account_unreachable";
3178
+ auth: "auth";
3179
+ content_blocked: "content_blocked";
3180
+ context_overflow: "context_overflow";
3181
+ final_output_missing: "final_output_missing";
3182
+ invalid_request: "invalid_request";
3183
+ model_disabled: "model_disabled";
3184
+ model_unavailable: "model_unavailable";
3185
+ network: "network";
3186
+ organization_unavailable: "organization_unavailable";
3187
+ overloaded: "overloaded";
3188
+ quota_exhausted: "quota_exhausted";
3189
+ rate_limit: "rate_limit";
3190
+ runtime_interrupted: "runtime_interrupted";
3191
+ safeguard_block: "safeguard_block";
3192
+ seat_unpaid: "seat_unpaid";
3193
+ server_error: "server_error";
3194
+ sign_in_required: "sign_in_required";
3195
+ stream_interrupted: "stream_interrupted";
3196
+ unknown: "unknown";
3197
+ }>;
3198
+ source: z.ZodEnum<{
3199
+ assistant_message: "assistant_message";
3200
+ exception: "exception";
3201
+ runtime: "runtime";
3202
+ }>;
3203
+ authDisposition: z.ZodOptional<z.ZodEnum<{
3204
+ unauthorized: "unauthorized";
3205
+ forbidden: "forbidden";
3206
+ }>>;
3207
+ provider: z.ZodOptional<z.ZodString>;
3208
+ api: z.ZodOptional<z.ZodString>;
3209
+ model: z.ZodOptional<z.ZodString>;
3210
+ httpStatus: z.ZodOptional<z.ZodNumber>;
3211
+ providerCode: z.ZodOptional<z.ZodString>;
3212
+ exitCode: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
3213
+ signal: z.ZodOptional<z.ZodNullable<z.ZodString>>;
3214
+ observation: z.ZodOptional<z.ZodEnum<{
3215
+ process_exit: "process_exit";
3216
+ next_launch: "next_launch";
3217
+ }>>;
3218
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
3219
+ retryable: z.ZodOptional<z.ZodBoolean>;
3220
+ accountId: z.ZodOptional<z.ZodString>;
3221
+ authSource: z.ZodOptional<z.ZodEnum<{
3222
+ oauth: "oauth";
3223
+ "api-key": "api-key";
3224
+ }>>;
3225
+ credentialRef: z.ZodOptional<z.ZodString>;
3226
+ }, z.core.$strict>;
3227
+
3228
+ declare type RunFailureOccurrence = FailureOccurrence<RunFailureCause>;
3229
+
3230
+ declare type RunFailureReason = (typeof RUN_FAILURE_REASONS)[number];
3231
+
3232
+ declare type RunFailureRecord = z.infer<typeof runFailureRecordSchema>;
3233
+
3234
+ declare const runFailureRecordSchema: z.ZodObject<{
3235
+ failure: z.ZodType<RunFailureOccurrence, unknown, z.core.$ZodTypeInternals<RunFailureOccurrence, unknown>>;
3236
+ errorText: z.ZodString;
3237
+ }, z.core.$strict>;
3238
+
2461
3239
  /**
2462
3240
  * A durable runtime notice: the daemon telling the HUMAN, in the transcript,
2463
- * that something it was going to do on their behalf did not happen — and why.
3241
+ * that something it was going to do on their behalf did not happen - and why.
2464
3242
  * Same kernel posture as {@link COLLABORATION_MESSAGE_CUSTOM_TYPE}: the kernel
2465
3243
  * persists and projects the typed carrier; the daemon decides when one is
2466
- * warranted. Delivery never starts a run — that is the type's whole reason to
3244
+ * warranted. Delivery never starts a run - that is the type's whole reason to
2467
3245
  * exist. Its producers are the daemon's `RuntimeNoticeKind`s (agent-runtime
2468
3246
  * `context-message-builders.ts`). The first was #3365's dropped-continuation
2469
3247
  * path, retired with readiness continuations (#12512): a state a user could not
@@ -2476,7 +3254,7 @@ declare const RUNTIME_NOTICE_CUSTOM_TYPE = "runtime_notice";
2476
3254
  /**
2477
3255
  * Details of a {@link RUNTIME_NOTICE_CUSTOM_TYPE} entry. `noticeKind` is a
2478
3256
  * closed vocabulary owned by the daemon's builder (`RuntimeNoticeKind` in
2479
- * agent-runtime) — the kernel persists and projects whatever kind arrives,
3257
+ * agent-runtime) - the kernel persists and projects whatever kind arrives,
2480
3258
  * typed as string here for the same reason collaboration `kind` stays narrow
2481
3259
  * there and open here: the kernel must not need a release to learn a new one.
2482
3260
  */
@@ -2962,7 +3740,7 @@ declare const SessionProvenanceRecord: z.ZodObject<{
2962
3740
 
2963
3741
  declare type SessionProvenanceRecord = z.infer<typeof SessionProvenanceRecord>;
2964
3742
 
2965
- export declare function sessionSummarySourceRevision(mark: KayAppCorpusSourceMark): string;
3743
+ export declare function sessionSummarySourceRevision(mark: KayAppSessionSourceMark): string;
2966
3744
 
2967
3745
  declare interface SourceInfo {
2968
3746
  path: string;
@@ -3098,7 +3876,7 @@ declare const SUBAGENT_RESULT_CUSTOM_TYPE = "subagent_result";
3098
3876
 
3099
3877
  /**
3100
3878
  * A child-declared, openable result reference: a resolved URI + a display title.
3101
- * Kernel-generic on purpose — herd-agent must not learn Bonsai "artifact" semantics.
3879
+ * Kernel-generic on purpose - herd-agent must not learn Bonsai "artifact" semantics.
3102
3880
  */
3103
3881
  declare interface SubagentDeliverable {
3104
3882
  readonly uri: string;
@@ -3108,7 +3886,7 @@ declare interface SubagentDeliverable {
3108
3886
  /**
3109
3887
  * Details of a subagent-result context message. Provenance rides the fixed `provenance` key (the
3110
3888
  * `AttributionSource` family: `{source:"subagent", sourceId: childSessionId, label?}`), shared with
3111
- * every other context kind — the legacy `attribution` sibling is no longer written.
3889
+ * every other context kind - the legacy `attribution` sibling is no longer written.
3112
3890
  */
3113
3891
  declare interface SubagentResultDetails {
3114
3892
  readonly provenance: AttributionSource;
@@ -3123,10 +3901,10 @@ declare interface SubagentResultDetails {
3123
3901
  */
3124
3902
  readonly summary?: string;
3125
3903
  /**
3126
- * The settled task this result answers — the per-assignment correlation key
3904
+ * The settled task this result answers - the per-assignment correlation key
3127
3905
  * (#2933). `childSessionId` alone is NOT an identity: follow-up tasks reuse
3128
3906
  * the child session, so one child can produce many results. Absent on rows
3129
- * persisted before the key existed — readers of legacy rows must tolerate
3907
+ * persisted before the key existed - readers of legacy rows must tolerate
3130
3908
  * several same-`sourceId` rows with no task key and treat recency, not
3131
3909
  * first-match, as the tiebreaker.
3132
3910
  */
@@ -3162,7 +3940,7 @@ declare type SubagentResultMessage = CustomMessage<SubagentResultDetails> & {
3162
3940
  export declare function summarizeSession(input: SummarizeSessionInput): Promise<KayAppSessionSummaryResult>;
3163
3941
 
3164
3942
  export declare interface SummarizeSessionInput {
3165
- readonly corpus: KayAppCorpus;
3943
+ readonly sessions: KayAppSessions;
3166
3944
  readonly models: KayAppModels;
3167
3945
  readonly sessionId: string;
3168
3946
  readonly previous?: KayAppSessionSummaryResult;
@@ -5617,8 +6395,73 @@ declare type TPropertyValues<Properties extends TProperties, Keys extends string
5617
6395
 
5618
6396
  declare type TPropertyValuesReduce<Properties extends TProperties, Keys extends string[], Result extends TSchema[] = []> = Keys extends [infer Left extends string, ...infer Right extends string[]] ? Left extends keyof Properties ? TPropertyValuesReduce<Properties, Right, [...Result, Properties[Left]]> : TPropertyValuesReduce<Properties, Right, Result> : Result;
5619
6397
 
6398
+ /**
6399
+ * Where a body an item's preview leaves out lives. A reference is a position, not a capability:
6400
+ * holding one grants nothing. It crosses process boundaries (to the app, to plugins) as plain data,
6401
+ * and is fetched on demand through the host, which authorizes the caller for the session again and
6402
+ * resolves the storage from the session, never from the reference, so a reference cannot reach
6403
+ * another session.
6404
+ *
6405
+ * - `record`: the entry is larger than the page allowed. With `contentIndex`, the body is the JSON
6406
+ * of that one content block of the entry's message (a long text, an image, a file the preview
6407
+ * cut or replaced); an entry whose size lies in content blocks is referenced block by block.
6408
+ * Without it, the body is the whole projected entry's JSON, which a reader issues for every
6409
+ * entry it cuts, beside the block references when the entry has some, or alone when they would
6410
+ * not fit the item. A caller reads only references a page issued and never builds one, so a
6411
+ * reader may make them opaque. Either way the reader extracts and slices the body in storage,
6412
+ * never holding more than a chunk of it. The body is the projection as of commit `asOf`, so
6413
+ * every chunk of one body comes from the same version: when a later commit changes the
6414
+ * entry's projection (an overlay, an input binding), retrieval rejects with `body_changed` and the
6415
+ * caller reads the entry again for a fresh reference. Otherwise the reference lives as long as
6416
+ * the file's incarnation.
6417
+ * - `tool-output`: the tool result was clamped when it entered the transcript and its full output
6418
+ * was spilled beside the session (what `tool-output://<toolCallId>` reads). It lives as long as the
6419
+ * session's directory; a spill that was never written or was since removed reads as
6420
+ * `body_missing`.
6421
+ */
6422
+ declare type TranscriptBodyReference = {
6423
+ readonly kind: "record";
6424
+ readonly incarnation: string;
6425
+ readonly entryId: string;
6426
+ /** One content block of the entry's message, 0-based; absent for the whole entry. */
6427
+ readonly contentIndex?: number;
6428
+ /** The head commit the preview was cut at: the projection the body is read as. */
6429
+ readonly asOf: number;
6430
+ /** The body's size, in bytes of its JSON form. */
6431
+ readonly bytes: number;
6432
+ } | {
6433
+ readonly kind: "tool-output";
6434
+ readonly toolCallId: string;
6435
+ /** Absent when the reader did not stat the spill. */
6436
+ readonly bytes?: number;
6437
+ };
6438
+
5620
6439
  declare type TranscriptEntry = MessageEntry | CompactionEntry | BranchSummaryEntry | CustomEntry;
5621
6440
 
6441
+ /**
6442
+ * One item of a page, in stored order. With `bodies`, `entry` is a preview: its large text is cut
6443
+ * and its images and files replaced, so the item fits the page, and each reference says where one
6444
+ * left-out body is: the whole entry, one replaced block, the spilled tool output. A spilled tool
6445
+ * result always lists its `tool-output` reference, also when the entry is cut too. An
6446
+ * `unreadable` item is a stored record that does not parse as an entry; it still takes a place,
6447
+ * and its id is the storage row's, which every stored record has, so a cursor can name it.
6448
+ * `(commitSeq, commitIndex)` is the item's stored order, so a holder can insert an item it did not
6449
+ * have (a revision that makes an entry appear) at its place. The entry's own `seq` is not a
6450
+ * position here: a reader that pages by cursor does not count the entries before an item.
6451
+ */
6452
+ declare type TranscriptPageItem = {
6453
+ readonly entry: TranscriptEntry;
6454
+ readonly commitSeq: number;
6455
+ /** The record's place among its commit's stored records: items sort by (commitSeq, commitIndex). */
6456
+ readonly commitIndex: number;
6457
+ readonly bodies?: readonly TranscriptBodyReference[];
6458
+ } | {
6459
+ readonly unreadable: "malformed-json" | "malformed-entry";
6460
+ readonly commitSeq: number;
6461
+ readonly commitIndex: number;
6462
+ readonly entryId: string;
6463
+ };
6464
+
5622
6465
  declare type TReadonly<Type extends TSchema = TSchema> = (Type & {
5623
6466
  '~readonly': true;
5624
6467
  });
@@ -6514,7 +7357,7 @@ declare type TZipDistributionArray<Arguments extends TSchema[], DistributionArra
6514
7357
 
6515
7358
  declare const UI_ACTION_CUSTOM_TYPE = "ui_action";
6516
7359
 
6517
- /** A generative-UI interaction — the human acting, carried with its originating tool call. */
7360
+ /** A generative-UI interaction - the human acting, carried with its originating tool call. */
6518
7361
  declare interface UiActionDetails {
6519
7362
  readonly provenance: AttributionSource;
6520
7363
  /**
@@ -6606,14 +7449,14 @@ declare interface Usage {
6606
7449
 
6607
7450
  /**
6608
7451
  * The user-invoked message: everything the composer INTENTIONALLY pulled into a
6609
- * send — today the resolved content of skill- and prompt-template-bound slash
6610
- * commands — carried beside the human turn instead of fabricated into its text.
7452
+ * send - today the resolved content of skill- and prompt-template-bound slash
7453
+ * commands - carried beside the human turn instead of fabricated into its text.
6611
7454
  * The user turn stays exactly what was typed (`/pr-review 123`); this message
6612
7455
  * delivers what that intent resolved to, one message per send, in per-feature
6613
- * sections (`skills`, `prompt_templates` — a future feature adds a SIBLING
7456
+ * sections (`skills`, `prompt_templates` - a future feature adds a SIBLING
6614
7457
  * section, never a second meaning for an existing one). Sibling of
6615
7458
  * `dynamic_context` in grammar (a sectioned wrapper) but not in policy: it is
6616
- * assembled synchronously and fail-closed at command dispatch — never a
7459
+ * assembled synchronously and fail-closed at command dispatch - never a
6617
7460
  * retrieval pass, budget, or debounce, because the content IS the send's
6618
7461
  * meaning, not something computed from it.
6619
7462
  */
@@ -6628,18 +7471,18 @@ declare const USER_PASTED_CONTENT_CUSTOM_TYPE = "user_pasted_content";
6628
7471
 
6629
7472
  /**
6630
7473
  * The user shell command result: a command the HUMAN ran directly through the
6631
- * composer's `!` shell escape — no model in the loop, no permission prompt —
7474
+ * composer's `!` shell escape - no model in the loop, no permission prompt -
6632
7475
  * carried into context so the agent can pick up where the user's manual work
6633
7476
  * left off. The third verb of the user-origin family: `tab_context` is what the
6634
7477
  * user is looking at, `ui_action` is what they clicked, `user_shell_command` is
6635
- * what they DID. Durable (never turn-bound) and it must never wake the agent —
7478
+ * what they DID. Durable (never turn-bound) and it must never wake the agent -
6636
7479
  * delivery policy lives with the host (D1: silent context).
6637
7480
  */
6638
7481
  declare const USER_SHELL_COMMAND_CUSTOM_TYPE = "user_shell_command";
6639
7482
 
6640
7483
  /**
6641
7484
  * Details of a `user_invoked` message. The message `content` is empty by
6642
- * construction — the model wrapper renders entirely from these typed sections
7485
+ * construction - the model wrapper renders entirely from these typed sections
6643
7486
  * (the `dynamic_context` details-first posture). One typed slot per feature
6644
7487
  * section; both are always present (empty arrays elide their section at the
6645
7488
  * model boundary).
@@ -6652,7 +7495,7 @@ declare interface UserInvokedDetails {
6652
7495
 
6653
7496
  /**
6654
7497
  * One invocation entry inside a `user_invoked` feature section: the resource's
6655
- * resolved name, the literal command the user typed (`/pr-review 123` — kept
7498
+ * resolved name, the literal command the user typed (`/pr-review 123` - kept
6656
7499
  * verbatim, alias and all), and the resolved content that command pulled in.
6657
7500
  */
6658
7501
  declare interface UserInvokedEntry {
@@ -6710,7 +7553,7 @@ declare type UserPastedContentMessage = CustomMessage<UserPastedContentDetails>
6710
7553
  */
6711
7554
  declare interface UserShellCommandDetails {
6712
7555
  readonly provenance: AttributionSource;
6713
- /** The background-task id the run rode — correlates the card with live task events. */
7556
+ /** The background-task id the run rode - correlates the card with live task events. */
6714
7557
  readonly taskId: string;
6715
7558
  readonly command: string;
6716
7559
  readonly cwd: string;
@@ -6805,6 +7648,18 @@ declare const WithValue: (input: string) => [unknown, string] | [];
6805
7648
 
6806
7649
  declare function WithValueMapping(input: unknown): unknown;
6807
7650
 
7651
+ declare type WorkBlockCoverage = z.infer<typeof WorkBlockCoverageSchema>;
7652
+
7653
+ /**
7654
+ * Exact ordered completed executions, addressed by persisted tool-result entry IDs.
7655
+ * Provider call IDs can repeat across retries and turns; they are never ownership keys.
7656
+ */
7657
+ declare const WorkBlockCoverageSchema: z.ZodObject<{
7658
+ firstToolResultEntryId: z.ZodString;
7659
+ lastToolResultEntryId: z.ZodString;
7660
+ toolResultEntryIds: z.ZodArray<z.ZodString>;
7661
+ }, z.core.$strict>;
7662
+
6808
7663
  declare interface XAdditionalItems<AdditionalItems extends XSchema = XSchema> {
6809
7664
  additionalItems: AdditionalItems;
6810
7665
  }