@dsh-ray/assistant-delivery 0.0.1-seed.0 → 0.2.0

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.
Files changed (185) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +610 -1
  3. package/bin/dsh-restart-supervisor.js +102 -0
  4. package/cordis.patch.yml +29 -0
  5. package/lib/acceptance.d.ts +54 -0
  6. package/lib/acceptance.d.ts.map +1 -0
  7. package/lib/acceptance.js +2 -0
  8. package/lib/acceptance.js.map +1 -0
  9. package/lib/agent-runtime.d.ts +247 -0
  10. package/lib/agent-runtime.d.ts.map +1 -0
  11. package/lib/agent-runtime.js +4458 -0
  12. package/lib/agent-runtime.js.map +1 -0
  13. package/lib/approval-status-context.d.ts +8 -0
  14. package/lib/approval-status-context.d.ts.map +1 -0
  15. package/lib/approval-status-context.js +55 -0
  16. package/lib/approval-status-context.js.map +1 -0
  17. package/lib/attention-audit-store.d.ts +54 -0
  18. package/lib/attention-audit-store.d.ts.map +1 -0
  19. package/lib/attention-audit-store.js +213 -0
  20. package/lib/attention-audit-store.js.map +1 -0
  21. package/lib/attention-enforcement.d.ts +75 -0
  22. package/lib/attention-enforcement.d.ts.map +1 -0
  23. package/lib/attention-enforcement.js +84 -0
  24. package/lib/attention-enforcement.js.map +1 -0
  25. package/lib/attention.d.ts +208 -0
  26. package/lib/attention.d.ts.map +1 -0
  27. package/lib/attention.js +288 -0
  28. package/lib/attention.js.map +1 -0
  29. package/lib/canonical.d.ts +28 -0
  30. package/lib/canonical.d.ts.map +1 -0
  31. package/lib/canonical.js +190 -0
  32. package/lib/canonical.js.map +1 -0
  33. package/lib/coordinator.d.ts +134 -0
  34. package/lib/coordinator.d.ts.map +1 -0
  35. package/lib/coordinator.js +746 -0
  36. package/lib/coordinator.js.map +1 -0
  37. package/lib/feedback-command.d.ts +105 -0
  38. package/lib/feedback-command.d.ts.map +1 -0
  39. package/lib/feedback-command.js +547 -0
  40. package/lib/feedback-command.js.map +1 -0
  41. package/lib/foreground-observation.d.ts +66 -0
  42. package/lib/foreground-observation.d.ts.map +1 -0
  43. package/lib/foreground-observation.js +13 -0
  44. package/lib/foreground-observation.js.map +1 -0
  45. package/lib/foreground-termination.d.ts +31 -0
  46. package/lib/foreground-termination.d.ts.map +1 -0
  47. package/lib/foreground-termination.js +42 -0
  48. package/lib/foreground-termination.js.map +1 -0
  49. package/lib/goal-wake-types.d.ts +93 -0
  50. package/lib/goal-wake-types.d.ts.map +1 -0
  51. package/lib/goal-wake-types.js +70 -0
  52. package/lib/goal-wake-types.js.map +1 -0
  53. package/lib/in-process-reload-runtime.d.ts +120 -0
  54. package/lib/in-process-reload-runtime.d.ts.map +1 -0
  55. package/lib/in-process-reload-runtime.js +1280 -0
  56. package/lib/in-process-reload-runtime.js.map +1 -0
  57. package/lib/inbound-images.d.ts +38 -0
  58. package/lib/inbound-images.d.ts.map +1 -0
  59. package/lib/inbound-images.js +269 -0
  60. package/lib/inbound-images.js.map +1 -0
  61. package/lib/index.d.ts +41 -0
  62. package/lib/index.d.ts.map +1 -0
  63. package/lib/index.js +25 -0
  64. package/lib/index.js.map +1 -0
  65. package/lib/learning-command.d.ts +40 -0
  66. package/lib/learning-command.d.ts.map +1 -0
  67. package/lib/learning-command.js +57 -0
  68. package/lib/learning-command.js.map +1 -0
  69. package/lib/native-termination.d.ts +12 -0
  70. package/lib/native-termination.d.ts.map +1 -0
  71. package/lib/native-termination.js +57 -0
  72. package/lib/native-termination.js.map +1 -0
  73. package/lib/native-web-owner.d.ts +97 -0
  74. package/lib/native-web-owner.d.ts.map +1 -0
  75. package/lib/native-web-owner.js +338 -0
  76. package/lib/native-web-owner.js.map +1 -0
  77. package/lib/operator-snapshot.d.ts +107 -0
  78. package/lib/operator-snapshot.d.ts.map +1 -0
  79. package/lib/operator-snapshot.js +1013 -0
  80. package/lib/operator-snapshot.js.map +1 -0
  81. package/lib/operator.d.ts +25 -0
  82. package/lib/operator.d.ts.map +1 -0
  83. package/lib/operator.js +48 -0
  84. package/lib/operator.js.map +1 -0
  85. package/lib/progress-attention.d.ts +55 -0
  86. package/lib/progress-attention.d.ts.map +1 -0
  87. package/lib/progress-attention.js +128 -0
  88. package/lib/progress-attention.js.map +1 -0
  89. package/lib/reply-replay.d.ts +52 -0
  90. package/lib/reply-replay.d.ts.map +1 -0
  91. package/lib/reply-replay.js +122 -0
  92. package/lib/reply-replay.js.map +1 -0
  93. package/lib/restart-native.d.ts +47 -0
  94. package/lib/restart-native.d.ts.map +1 -0
  95. package/lib/restart-native.js +170 -0
  96. package/lib/restart-native.js.map +1 -0
  97. package/lib/restart-runtime.d.ts +38 -0
  98. package/lib/restart-runtime.d.ts.map +1 -0
  99. package/lib/restart-runtime.js +335 -0
  100. package/lib/restart-runtime.js.map +1 -0
  101. package/lib/restart-store.d.ts +132 -0
  102. package/lib/restart-store.d.ts.map +1 -0
  103. package/lib/restart-store.js +757 -0
  104. package/lib/restart-store.js.map +1 -0
  105. package/lib/restart-supervisor.d.ts +129 -0
  106. package/lib/restart-supervisor.d.ts.map +1 -0
  107. package/lib/restart-supervisor.js +615 -0
  108. package/lib/restart-supervisor.js.map +1 -0
  109. package/lib/service.d.ts +1279 -0
  110. package/lib/service.d.ts.map +1 -0
  111. package/lib/service.js +8694 -0
  112. package/lib/service.js.map +1 -0
  113. package/lib/session-commands.d.ts +52 -0
  114. package/lib/session-commands.d.ts.map +1 -0
  115. package/lib/session-commands.js +180 -0
  116. package/lib/session-commands.js.map +1 -0
  117. package/lib/session-lease-runtime.d.ts +70 -0
  118. package/lib/session-lease-runtime.d.ts.map +1 -0
  119. package/lib/session-lease-runtime.js +395 -0
  120. package/lib/session-lease-runtime.js.map +1 -0
  121. package/lib/session-lease-types.d.ts +27 -0
  122. package/lib/session-lease-types.d.ts.map +1 -0
  123. package/lib/session-lease-types.js +2 -0
  124. package/lib/session-lease-types.js.map +1 -0
  125. package/lib/sqlite.d.ts +8 -0
  126. package/lib/sqlite.d.ts.map +1 -0
  127. package/lib/sqlite.js +1665 -0
  128. package/lib/sqlite.js.map +1 -0
  129. package/lib/store.d.ts +1267 -0
  130. package/lib/store.d.ts.map +1 -0
  131. package/lib/store.js +8039 -0
  132. package/lib/store.js.map +1 -0
  133. package/lib/tools.d.ts +4 -0
  134. package/lib/tools.d.ts.map +1 -0
  135. package/lib/tools.js +73 -0
  136. package/lib/tools.js.map +1 -0
  137. package/lib/types.d.ts +1091 -0
  138. package/lib/types.d.ts.map +1 -0
  139. package/lib/types.js +10 -0
  140. package/lib/types.js.map +1 -0
  141. package/lib/version-query.d.ts +77 -0
  142. package/lib/version-query.d.ts.map +1 -0
  143. package/lib/version-query.js +2208 -0
  144. package/lib/version-query.js.map +1 -0
  145. package/lib/version.d.ts +2 -0
  146. package/lib/version.d.ts.map +1 -0
  147. package/lib/version.js +2 -0
  148. package/lib/version.js.map +1 -0
  149. package/lib/work-item-engineering-context.d.ts +127 -0
  150. package/lib/work-item-engineering-context.d.ts.map +1 -0
  151. package/lib/work-item-engineering-context.js +151 -0
  152. package/lib/work-item-engineering-context.js.map +1 -0
  153. package/lib/work-item-feedback-schema.d.ts +2 -0
  154. package/lib/work-item-feedback-schema.d.ts.map +1 -0
  155. package/lib/work-item-feedback-schema.js +29 -0
  156. package/lib/work-item-feedback-schema.js.map +1 -0
  157. package/lib/work-item-feedback-store.d.ts +29 -0
  158. package/lib/work-item-feedback-store.d.ts.map +1 -0
  159. package/lib/work-item-feedback-store.js +111 -0
  160. package/lib/work-item-feedback-store.js.map +1 -0
  161. package/lib/work-item-feedback.d.ts +157 -0
  162. package/lib/work-item-feedback.d.ts.map +1 -0
  163. package/lib/work-item-feedback.js +2 -0
  164. package/lib/work-item-feedback.js.map +1 -0
  165. package/lib/work-item-replies-schema.d.ts +3 -0
  166. package/lib/work-item-replies-schema.d.ts.map +1 -0
  167. package/lib/work-item-replies-schema.js +45 -0
  168. package/lib/work-item-replies-schema.js.map +1 -0
  169. package/lib/work-item-replies-store.d.ts +43 -0
  170. package/lib/work-item-replies-store.d.ts.map +1 -0
  171. package/lib/work-item-replies-store.js +203 -0
  172. package/lib/work-item-replies-store.js.map +1 -0
  173. package/lib/work-item-replies.d.ts +93 -0
  174. package/lib/work-item-replies.d.ts.map +1 -0
  175. package/lib/work-item-replies.js +15 -0
  176. package/lib/work-item-replies.js.map +1 -0
  177. package/lib/workflow-auto-producer.d.ts +37 -0
  178. package/lib/workflow-auto-producer.d.ts.map +1 -0
  179. package/lib/workflow-auto-producer.js +58 -0
  180. package/lib/workflow-auto-producer.js.map +1 -0
  181. package/lib/workflow-command.d.ts +16 -0
  182. package/lib/workflow-command.d.ts.map +1 -0
  183. package/lib/workflow-command.js +52 -0
  184. package/lib/workflow-command.js.map +1 -0
  185. package/package.json +174 -4
package/lib/store.d.ts ADDED
@@ -0,0 +1,1267 @@
1
+ import { WorkItemFeedbackStore } from './work-item-feedback-store.js';
2
+ import { AttentionAuditStore } from './attention-audit-store.js';
3
+ import { WorkItemRepliesStore } from './work-item-replies-store.js';
4
+ import { type ForegroundTerminationObservation } from './foreground-termination.js';
5
+ import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
6
+ import type { ApprovalDispatchRouteV2 } from '@dsh-ray/assistant-policy';
7
+ import { type ResolvedWorkflowAutomationTemplate, type WorkflowAutomationTemplate, type WorkflowAutomationTemplateContent, type WorkflowStepFingerprint, type WorkflowTraceRevision, type WorkflowTraceSourceAttestation } from '@dsh-ray/assistant-growth-contract';
8
+ import { type ObjectiveCommand, type ObjectiveFeedbackStatus } from './feedback-command.js';
9
+ import type { WorkItemFeedbackIntent, WorkItemFeedbackSource } from './work-item-feedback.js';
10
+ import type { StoredWorkItemReport } from './work-item-replies-store.js';
11
+ import type { WorkItemReplySource } from './work-item-replies.js';
12
+ import { type OwnerGoalOutcomeFeedbackLocator, type OwnerGoalOutcomeFeedbackProof } from './goal-wake-types.js';
13
+ import type { AcceptanceContract, AcceptedExecution, ForegroundExecution } from './acceptance.js';
14
+ import type { ForegroundTaskIdentity, OwnerForegroundToolInput } from './foreground-observation.js';
15
+ import type { SessionLease, SessionLeaseClaim, SessionLeaseTarget } from './session-lease-types.js';
16
+ import type { ConversationBinding, ConversationModelSelection, ConversationRef, DeadLetterResolutionKind, DeadLetterResolutionReceipt, DeadLetterResolutionResult, DeliveryAttachment, DeliveryGoalOutcomeTarget, DeliveryPreferenceEvent, DeliveryPresentationUpdate, DeliveryPrincipal, DeliveryProgressIntent, DeliveryProgressRecord, DeliveryReceipt, ExternalPrincipalKey, InboundEnvelope, InboxRecord, OutboundIntent, OutboundTextAttachment, ModelPickerIntent, ModelPickerState, ModelRouteRef, OwnerApprovalForPreferenceInput, OwnerRouteAuthority, OwnerForegroundTaskSource, OwnerForegroundTaskSourceScope, OwnerForegroundTaskSourceCursor, OwnerForegroundTaskSourcePage, OwnerForegroundTaskSourceContent, OwnerForegroundTaskInput, OwnerForegroundTaskSourceRef, OutboxRecord, PairingChallenge, PermissionPickerIntent, StoredDeliveryPresentation } from './types.js';
17
+ export type DeliveryStoreErrorCode = 'conflict' | 'idempotency-conflict' | 'invalid-binding' | 'invalid-envelope' | 'invalid-intent' | 'not-found' | 'pairing-expired' | 'pairing-invalid' | 'pairing-locked' | 'pairing-principal-mismatch' | 'pairing-replayed' | 'receipt-mismatch' | 'stale-fence' | 'unauthorized-principal' | 'version-conflict';
18
+ export declare class DeliveryStoreError extends Error {
19
+ readonly code: DeliveryStoreErrorCode;
20
+ constructor(code: DeliveryStoreErrorCode, message: string);
21
+ }
22
+ interface DeliveryStoreOptions {
23
+ path: string;
24
+ now?: () => number;
25
+ codeGenerator?: () => string;
26
+ maxTextBytes?: number;
27
+ }
28
+ export interface OwnerRouteDispatchGuard {
29
+ readonly ownerRoutes: readonly Readonly<OwnerRouteAuthority>[];
30
+ /** False is an explicit revocation; throw means the check is unavailable and must be retried without I/O. */
31
+ readonly authorize: (input: {
32
+ authority: Readonly<OwnerRouteAuthority>;
33
+ sourceId: string;
34
+ idempotencyKey: string;
35
+ }) => boolean;
36
+ }
37
+ export type OwnerRouteDispatchValidation = {
38
+ kind: 'not-route';
39
+ } | {
40
+ kind: 'authorized';
41
+ } | {
42
+ kind: 'deferred';
43
+ failureCode: string;
44
+ } | {
45
+ kind: 'denied';
46
+ failureCode: string;
47
+ };
48
+ /**
49
+ * Immutable binding evidence required at the Inbox-to-Agent dispatch boundary.
50
+ *
51
+ * A Host-native input uses the same snapshot when it atomically admits and
52
+ * claims its exact Inbox, then again before it crosses `dispatch-started`.
53
+ */
54
+ export type InboundDispatchBindingSnapshot = Pick<ConversationBinding, 'conversation' | 'generation' | 'id' | 'principal' | 'sessionId' | 'version'>;
55
+ export interface ApprovalDispatchCursor {
56
+ createdAt: number;
57
+ proposalId: string;
58
+ }
59
+ export interface ApprovalDispatchCursorState {
60
+ version: number;
61
+ after?: ApprovalDispatchCursor;
62
+ }
63
+ interface WorkflowTraceRevisionRow {
64
+ subject_ref: string;
65
+ version: number;
66
+ source_generation: number;
67
+ source_authority_digest: string;
68
+ scope_key: string;
69
+ workspace: string;
70
+ preset: string;
71
+ disposition: WorkflowTraceRevision['disposition'];
72
+ digest: string;
73
+ payload_json: string;
74
+ created_at: number;
75
+ }
76
+ interface WorkflowTraceOutboxRow extends WorkflowTraceRevisionRow {
77
+ status: 'delivered' | 'pending' | 'retry_wait';
78
+ attempt_count: number;
79
+ next_attempt_at: number;
80
+ failure_code: string | null;
81
+ updated_at: number;
82
+ }
83
+ interface PreferenceProjectionLane {
84
+ epoch: string;
85
+ workspace: string;
86
+ preset: string;
87
+ principalRecordId: string;
88
+ principalVersion: number;
89
+ admissionSequence: number;
90
+ }
91
+ interface WorkflowTemplateRow {
92
+ template_ref: string;
93
+ template_digest: string;
94
+ scope_key: string;
95
+ workspace: string;
96
+ preset: string;
97
+ owner_binding_id: string;
98
+ content_json: string;
99
+ privacy_kind: WorkflowAutomationTemplate['privacyAttestation']['kind'];
100
+ privacy_attestation_id: string;
101
+ privacy_attestation_digest: string;
102
+ review_receipt_json: string;
103
+ status: 'active' | 'revoked';
104
+ review_inbox_id: string;
105
+ source_inbox_id: string;
106
+ source_outbox_id: string;
107
+ created_at: number;
108
+ updated_at: number;
109
+ version: number;
110
+ }
111
+ export interface WorkflowTraceOutboxEntry {
112
+ revision: Readonly<WorkflowTraceRevision>;
113
+ status: WorkflowTraceOutboxRow['status'];
114
+ attemptCount: number;
115
+ nextAttemptAt: number;
116
+ failureCode?: string;
117
+ updatedAt: number;
118
+ }
119
+ export interface PreferenceProjectionOutboxEntry {
120
+ batchKey: string;
121
+ payloadDigest: string;
122
+ events: readonly Readonly<DeliveryPreferenceEvent>[];
123
+ lane?: Readonly<PreferenceProjectionLane>;
124
+ attemptCount: number;
125
+ nextAttemptAt: number;
126
+ failureCode?: string;
127
+ }
128
+ export type PreferenceProjectionFenceResult = 'completed' | 'ignored' | 'missing';
129
+ export interface OwnerWorkflowTraceCommandResult {
130
+ revision: Readonly<WorkflowTraceRevision>;
131
+ template?: Readonly<WorkflowAutomationTemplate>;
132
+ replayed: boolean;
133
+ }
134
+ /**
135
+ * The durable result of an authenticated owner objective judgement over one
136
+ * ordinary Agent reply. Only an achieved judgement with a closed-set,
137
+ * deterministic template can create a workflow trace.
138
+ */
139
+ export type VerifiedWorkflowTraceFeedbackResult = Readonly<{
140
+ ownerFeedbackState?: Readonly<{
141
+ version: number;
142
+ objectiveStatus: 'achieved' | 'partial' | 'not-achieved' | 'unknown';
143
+ }>;
144
+ }> & (Readonly<{
145
+ outcome: 'trace-recorded';
146
+ revision: Readonly<WorkflowTraceRevision>;
147
+ template: Readonly<WorkflowAutomationTemplate>;
148
+ replayed: boolean;
149
+ }> | Readonly<{
150
+ outcome: 'no-trace';
151
+ reason: 'objective-not-achieved' | 'privacy-abstained';
152
+ replayed: boolean;
153
+ }>);
154
+ /** Shared binding/principal anchors every review kind must carry. */
155
+ export interface WorkflowTemplateReviewBinding {
156
+ bindingId: string;
157
+ bindingVersion: number;
158
+ bindingGeneration: number;
159
+ principalId: string;
160
+ }
161
+ /**
162
+ * Review receipt anchored on the live Inbox/Outbox fence for the owner-explicit
163
+ * and deterministic-deidentification routes stored in workflow_template_registry.
164
+ */
165
+ export type StoredWorkflowTemplateReview = Readonly<WorkflowTemplateReviewBinding> & (Readonly<{
166
+ kind: 'inbox-anchored';
167
+ reviewInboxId: string;
168
+ sourceInboxId: string;
169
+ sourceOutboxId: string;
170
+ }> | Readonly<{
171
+ /**
172
+ * Anchored on a Delivery-reverified owner-root successful Goal run rather
173
+ * than a live conversation fence. It carries the exact goal/run/acceptance
174
+ * identity and the owner-run-trace digest instead of inbox/outbox ids.
175
+ */
176
+ kind: 'goal-anchored';
177
+ ownerRouteId: string;
178
+ goalId: string;
179
+ nativeGoalId: string;
180
+ sessionId: string;
181
+ runId: string;
182
+ turn: number;
183
+ acceptanceContractId: string;
184
+ acceptanceReceiptDigest: string;
185
+ ownerRunTraceDigest: string;
186
+ taskRef: string;
187
+ }>);
188
+ export interface StoredWorkflowTemplate {
189
+ resolved: Readonly<ResolvedWorkflowAutomationTemplate>;
190
+ review: StoredWorkflowTemplateReview;
191
+ status: WorkflowTemplateRow['status'];
192
+ version: number;
193
+ }
194
+ /**
195
+ * Outcome of an owner-anchored workflow learning attempt. A goal that cannot be
196
+ * honestly reduced to the single `assistant.agent-turn` step Automations can
197
+ * safely materialize abstains with zero writes rather than emitting a trace.
198
+ */
199
+ export type CommitOwnerAnchoredWorkflowTraceResult = Readonly<{
200
+ outcome: 'trace-recorded';
201
+ revision: Readonly<WorkflowTraceRevision>;
202
+ template: Readonly<WorkflowAutomationTemplate>;
203
+ replayed: boolean;
204
+ }> | Readonly<{
205
+ outcome: 'abstained';
206
+ reason: 'not-reducible';
207
+ replayed: false;
208
+ }>;
209
+ export type NaturalObjectiveIntent = Readonly<{
210
+ inboxId: string;
211
+ envelopeHash: string;
212
+ sourceInboxId: string;
213
+ sourceOutboxId: string;
214
+ bindingId: string;
215
+ bindingVersion: number;
216
+ bindingGeneration: number;
217
+ principalRecordId: string;
218
+ principalVersion: number;
219
+ admissionEpoch: string;
220
+ admissionSequence: number;
221
+ occurredAt: number;
222
+ selection: ObjectiveFeedbackStatus | 'withdraw';
223
+ status: 'awaiting-evaluation' | 'frozen' | 'projected' | 'conflict';
224
+ command?: Extract<ObjectiveCommand, {
225
+ kind: 'objective' | 'objective-revision';
226
+ }>;
227
+ canonical?: Readonly<{
228
+ version: number;
229
+ objectiveStatus: ObjectiveFeedbackStatus | 'unknown';
230
+ }>;
231
+ }>;
232
+ export declare class DeliveryStore {
233
+ readonly workItemReplies: WorkItemRepliesStore;
234
+ readonly workItemFeedback: WorkItemFeedbackStore;
235
+ readonly attentionAudit: AttentionAuditStore;
236
+ private readonly database;
237
+ /** Scan position only; every candidate is authorized again before a provider retry. */
238
+ private readonly progressRecoveryCursors;
239
+ private readonly databaseInstanceId;
240
+ private readonly now;
241
+ private readonly codeGenerator;
242
+ private readonly maxTextBytes;
243
+ private closed;
244
+ private writerTransactionActive;
245
+ constructor(options: DeliveryStoreOptions);
246
+ /**
247
+ * Idempotent startup repair for links written before revoking an owner
248
+ * detached them: an active linked principal whose root is not the active
249
+ * owner yields no alias receipt today, but a later reactivation of that
250
+ * owner record would silently restore it. Detach exactly those rows, as
251
+ * `revokePrincipal` now does. No schema change; a no-op once clean. Links
252
+ * whose owner was already revoked and reactivated before this repair are
253
+ * indistinguishable from fresh links and are not touched.
254
+ */
255
+ private detachLinksOfInactiveOwners;
256
+ instanceId(): string;
257
+ issuePairing(input: ExternalPrincipalKey, options: {
258
+ ttlMs: number;
259
+ maxAttempts: number;
260
+ }): {
261
+ challenge: PairingChallenge;
262
+ code: string;
263
+ };
264
+ confirmPairing(input: {
265
+ challengeId: string;
266
+ principal: ExternalPrincipalKey;
267
+ code: string;
268
+ }): DeliveryPrincipal;
269
+ /**
270
+ * Trusted local owner rotation. Unlike an ordinary pairing, this promotes
271
+ * the exact replacement principal and retires every previous active owner in
272
+ * one SQLite transaction, so setup can never leave two active owners or turn
273
+ * the newly discovered owner into a merely linked identity.
274
+ */
275
+ handoffOwner(input: ExternalPrincipalKey): DeliveryPrincipal;
276
+ /**
277
+ * Bootstrap one empty Delivery database for a fixed local operator. This is
278
+ * deliberately narrower than handoffOwner(): once any principal history
279
+ * exists it can only return the exact, sole active owner without changing a
280
+ * row, its bindings, or any linked authority.
281
+ */
282
+ ensureOwner(input: ExternalPrincipalKey): DeliveryPrincipal;
283
+ isAuthorizedPrincipal(input: ExternalPrincipalKey): boolean;
284
+ /** The single active owner, or `undefined` while owner authority is absent/ambiguous. */
285
+ activeOwnerPrincipal(): DeliveryPrincipal | undefined;
286
+ /**
287
+ * Activate one explicitly allowlisted peer bot as a linked principal of the
288
+ * current owner. This never creates an owner and never revives a revoked row:
289
+ * the peer lane is an exact owner-configured authorization, not pairing or a
290
+ * silent upgrade of an existing identity.
291
+ */
292
+ ensurePeerPrincipal(input: ExternalPrincipalKey, ownerPrincipalId: string, options?: {
293
+ readonly reauthorize?: boolean;
294
+ }): DeliveryPrincipal;
295
+ getPrincipal(input: ExternalPrincipalKey): DeliveryPrincipal | undefined;
296
+ private getBindingPrincipal;
297
+ createBinding(input: {
298
+ conversation: ConversationRef;
299
+ principal: ExternalPrincipalKey;
300
+ workspace: string;
301
+ agentPreset: string;
302
+ sessionId: string;
303
+ policyRef: string;
304
+ expectedGeneration?: number;
305
+ constructionLease?: SessionLease;
306
+ }): ConversationBinding;
307
+ /**
308
+ * Snapshot the generation a newly-created session must use. `createBinding`
309
+ * revalidates this value under `BEGIN IMMEDIATE` when passed as
310
+ * `expectedGeneration`, so a concurrent generation change fails closed.
311
+ */
312
+ nextBindingGeneration(input: ConversationRef): number;
313
+ getActiveBinding(input: ConversationRef): ConversationBinding | undefined;
314
+ getBinding(id: string): ConversationBinding | undefined;
315
+ listBindings(input: ConversationRef): ConversationBinding[];
316
+ /** Read-only operator query. Callers must apply their own exact route checks. */
317
+ listActiveBindings(): ConversationBinding[];
318
+ /**
319
+ * Read-only: newest inbound `received_at` per candidate binding, counting any
320
+ * generation of the same conversation from the same principal (so a `/new`
321
+ * rotation keeps its history). Bindings without inbound are absent. Callers
322
+ * bound the candidate list.
323
+ */
324
+ latestInboundAtByBinding(bindingIds: readonly string[]): ReadonlyMap<string, number>;
325
+ /**
326
+ * Read-only: the newest still-unsettled earlier report of one work item from
327
+ * one source (any of `sourceIds`: canonical and as-sent forms), so a router can keep the next revision behind it on one lane.
328
+ * Unsettled means the claim-order states (`pending`, `retry_wait`,
329
+ * `attempting`, `unknown_after_send`) without an operator cancel; terminal
330
+ * rows never match. Scoped by the origin binding's workspace and the
331
+ * `outbox_claim` status index. A linked row is a Host-routed
332
+ * `dsh.linked-report` v1 row of this origin with a lower `reportRevision`.
333
+ * An origin row is queued on the origin binding and is either a typed report
334
+ * (`delivery_work_item_reports` target with a lower `reportRevision`) or a
335
+ * plain background notice whose WP19 audit row records `purpose: 'result'`
336
+ * and this `workItemId`; that plain lane carries no revision, so any such
337
+ * committed row of the item counts as earlier.
338
+ */
339
+ findUnsettledWorkItemReport(input: Readonly<{
340
+ sourceIds: readonly string[];
341
+ workspace: string;
342
+ originBindingId: string;
343
+ itemId: string;
344
+ beforeRevision: number;
345
+ }>): Readonly<{
346
+ outboxId: string;
347
+ bindingId: string;
348
+ route: 'origin' | 'linked';
349
+ }> | undefined;
350
+ /** Snapshot one exact active owner binding under the Delivery write fence. */
351
+ resolveApprovalRouteByBinding(input: Readonly<{
352
+ sourceId: string;
353
+ bindingId: string;
354
+ scope: Readonly<{
355
+ workspace: string;
356
+ preset: string;
357
+ }>;
358
+ principalId?: string;
359
+ }>): ApprovalDispatchRouteV2 | undefined;
360
+ /** Resolve one unique current owner from content-free Host authority evidence. */
361
+ resolveOwnerApprovalForPreference(input: Readonly<OwnerApprovalForPreferenceInput>): ApprovalDispatchRouteV2 | undefined;
362
+ getBindingBySession(sessionId: string): ConversationBinding | undefined;
363
+ /** Read one exact Agent owner attestation under a single SQLite snapshot. */
364
+ getPreferencePrincipalForSession(input: Readonly<{
365
+ sessionId: string;
366
+ workspace: string | undefined;
367
+ preset: string | undefined;
368
+ }>): Readonly<{
369
+ binding: ConversationBinding;
370
+ principal: DeliveryPrincipal;
371
+ }> | undefined;
372
+ getModelSelection(input: ConversationRef): ConversationModelSelection | undefined;
373
+ setModelSelection(input: ConversationRef, route: ModelRouteRef): ConversationModelSelection;
374
+ clearModelSelection(input: ConversationRef): boolean;
375
+ /**
376
+ * Remove one now-invalid persisted effort without replacing a newer model choice.
377
+ *
378
+ * Model capability directories are intentionally live data: an effort selected yesterday can
379
+ * disappear when a provider changes a model or account entitlement. The compare-and-swap keeps
380
+ * a concurrently chosen provider/model/effort authoritative instead of silently applying this
381
+ * recovery to it.
382
+ */
383
+ clearStaleModelReasoningEffort(input: {
384
+ conversation: ConversationRef;
385
+ expected: Pick<ConversationModelSelection, 'provider' | 'model' | 'reasoningEffort' | 'version'>;
386
+ }): {
387
+ applied: false;
388
+ } | {
389
+ applied: true;
390
+ selection: ConversationModelSelection;
391
+ };
392
+ beginModelCommand(input: ConversationRef): number;
393
+ commitModelCommand(input: {
394
+ conversation: ConversationRef;
395
+ expectedEpoch: number;
396
+ route?: ModelRouteRef;
397
+ }): {
398
+ applied: false;
399
+ } | {
400
+ applied: true;
401
+ selection?: ConversationModelSelection;
402
+ };
403
+ rotateBinding(input: {
404
+ bindingId: string;
405
+ expectedVersion: number;
406
+ sessionId: string;
407
+ }): ConversationBinding;
408
+ /**
409
+ * Consume one exact `/new` Inbox while rotating its binding.
410
+ *
411
+ * The Inbox transition is part of the same SQLite commit as revoking the
412
+ * previous binding and inserting its successor. Consequently a provider
413
+ * replay can observe either the entirely old state or the entirely new
414
+ * state, never a rotated binding paired with an unconsumed command.
415
+ */
416
+ rotateBindingAndQueueCommand(input: {
417
+ bindingId: string;
418
+ expectedVersion: number;
419
+ sessionId: string;
420
+ inboxId: string;
421
+ }): {
422
+ binding: ConversationBinding;
423
+ inbox: InboxRecord;
424
+ };
425
+ acceptInbound(input: InboundEnvelope): {
426
+ duplicate: boolean;
427
+ record: InboxRecord;
428
+ };
429
+ /**
430
+ * Admit and claim one exact Host-native input under one SQLite write fence.
431
+ *
432
+ * The normal Delivery scheduler can only claim queued work. Publishing a
433
+ * fresh native input directly as `claimed` therefore prevents it from
434
+ * observing a moment where the input is in the ordinary queue. Replays are
435
+ * read-only: a duplicate never renews, reclaims, or otherwise re-executes
436
+ * its existing Inbox.
437
+ */
438
+ claimNativeInbox(input: {
439
+ envelope: InboundEnvelope;
440
+ binding: Readonly<InboundDispatchBindingSnapshot>;
441
+ ownerLineage: {
442
+ principalRecordId: string;
443
+ principalVersion: number;
444
+ };
445
+ ownerId: string;
446
+ leaseMs: number;
447
+ }): {
448
+ duplicate: boolean;
449
+ record: InboxRecord;
450
+ fencingToken?: number;
451
+ };
452
+ listAttachments(input: {
453
+ ownerKind: 'inbox' | 'outbox';
454
+ ownerId: string;
455
+ }): DeliveryAttachment[];
456
+ /**
457
+ * Return complete durable image references in the provider descriptor order.
458
+ * `undefined` means the image descriptors have not been materialized yet.
459
+ */
460
+ listReadyInboundImageRefs(inboxId: string): readonly ImageAttachmentRef[] | undefined;
461
+ /** Atomically persist one ordered image batch while the caller still owns the live inbox lease. */
462
+ commitInboundImageRefs(input: {
463
+ inboxId: string;
464
+ ownerId: string;
465
+ fencingToken: number;
466
+ images: readonly {
467
+ ref: ImageAttachmentRef;
468
+ contentSha256: string;
469
+ }[];
470
+ }): readonly ImageAttachmentRef[];
471
+ queueInbox(inboxId: string, bindingId: string): InboxRecord;
472
+ /**
473
+ * Finish an Inbox without dispatching it to the Agent. Slice-5 owner-question
474
+ * replies are admitted, applied by their registered consumer, and only then
475
+ * marked processed. Idempotent for an already-processed Inbox bound to the
476
+ * same binding; any later lifecycle state is a conflict.
477
+ */
478
+ markInboxProcessed(inboxId: string, bindingId: string): InboxRecord;
479
+ /**
480
+ * Establish a durable command boundary before `/stop` or `/new` is queued.
481
+ *
482
+ * Every earlier record in the same binding that has not crossed the exact
483
+ * dispatch marker becomes terminal in one transaction. A normal claim
484
+ * carrying `dispatch-started` is deliberately left live because the external
485
+ * Agent may have observed it already. Exact permission commands instead get
486
+ * a durable cancelled-recovery marker before the runtime is asked to abort.
487
+ */
488
+ cancelUndispatchedInboxBefore(input: {
489
+ bindingId: string;
490
+ beforeInboxId: string;
491
+ failureCode: string;
492
+ }): {
493
+ cancelled: number;
494
+ dispatching: number;
495
+ claimedInboxIds: string[];
496
+ dispatchingInboxIds: string[];
497
+ replyChildItemIds?: string[];
498
+ };
499
+ getInbox(id: string): InboxRecord | undefined;
500
+ getInboxByProviderEvent(channel: string, account: string, eventId: string): InboxRecord | undefined;
501
+ private progressAuthority;
502
+ private progressRecord;
503
+ private progressRow;
504
+ /** Reserve before provider I/O; a stranded creating row must never trigger another create. */
505
+ beginProgress(intent: DeliveryProgressIntent, credentialFingerprint: string, sequence: number, showDetails: boolean): {
506
+ record: DeliveryProgressRecord;
507
+ created: boolean;
508
+ } | undefined;
509
+ getProgress(intent: DeliveryProgressIntent, credentialFingerprint: string): DeliveryProgressRecord | undefined;
510
+ attachProgressHandle(intent: DeliveryProgressIntent, credentialFingerprint: string, providerHandle: string): DeliveryProgressRecord | undefined;
511
+ advanceProgress(intent: DeliveryProgressIntent, credentialFingerprint: string): DeliveryProgressRecord | undefined;
512
+ stageProgressTerminal(intent: DeliveryProgressIntent, credentialFingerprint: string): DeliveryProgressRecord | undefined;
513
+ confirmProgressTerminal(intent: DeliveryProgressIntent, credentialFingerprint: string): void;
514
+ /** Only authoritative settled Inbox rows are eligible for restart repair. */
515
+ recoverProgress(channel: string, account: string, credentialFingerprint: string, limit: number, authorize?: (binding: ConversationBinding, inbox: InboxRecord) => boolean): DeliveryProgressRecord[];
516
+ /** Return the oldest durable admission that did not finish before another Inbox. */
517
+ findPendingInboundBefore(input: {
518
+ conversation: ConversationRef;
519
+ principal: ExternalPrincipalKey;
520
+ beforeInboxId: string;
521
+ }): InboxRecord | undefined;
522
+ /**
523
+ * List a bounded page of persisted admissions that have not reached the
524
+ * worker queue yet. The admission cursor, rather than timestamps or rowid,
525
+ * preserves the global order across restarts and database maintenance.
526
+ */
527
+ listRecoverableInboundAdmissions(input?: {
528
+ afterSequence?: number;
529
+ limit?: number;
530
+ }): InboxRecord[];
531
+ /** Scan durable, unacknowledged dispatched turns without replaying their Agent work. */
532
+ listInterruptedInboxNotices(input?: {
533
+ afterSequence?: number;
534
+ limit?: number;
535
+ }): InboxRecord[];
536
+ /** The final notice decision and Outbox insert share one SQLite writer fence. */
537
+ enqueueInterruptedInboxNotice(input: {
538
+ inboxId: string;
539
+ binding: Readonly<ConversationBinding>;
540
+ intent: OutboundIntent;
541
+ }): OutboxRecord;
542
+ /** Recheck a queued interruption notice immediately before an adapter send. */
543
+ canSendInterruptedInboxNotice(record: Readonly<OutboxRecord>): boolean;
544
+ private interruptedInboxNoticeCurrent;
545
+ listInbox(input?: {
546
+ bindingId?: string;
547
+ limit?: number;
548
+ }): InboxRecord[];
549
+ getDeadLetterResolution(input: {
550
+ kind: DeadLetterResolutionKind;
551
+ id: string;
552
+ attemptCount: number;
553
+ }): DeadLetterResolutionReceipt | undefined;
554
+ health(): {
555
+ pendingInbox: number;
556
+ /** All retained Inbox rows in dead_letter, including operator-resolved tombstones. */
557
+ deadLetterInbox: number;
558
+ actionableDeadLetterInbox: number;
559
+ resolvedDeadLetterInbox: number;
560
+ pendingOutbox: number;
561
+ /** All retained Outbox rows in dead, including operator-resolved tombstones. */
562
+ deadLetterOutbox: number;
563
+ actionableDeadLetterOutbox: number;
564
+ resolvedDeadLetterOutbox: number;
565
+ /** All retained ambiguous Outbox rows, including operator-resolved tombstones. */
566
+ unknownOutbox: number;
567
+ actionableUnknownOutbox: number;
568
+ resolvedUnknownOutbox: number;
569
+ pendingPresentations: number;
570
+ deadPresentations: number;
571
+ };
572
+ getApprovalDispatchCursor(): ApprovalDispatchCursorState;
573
+ advanceApprovalDispatchCursor(input: {
574
+ expectedVersion: number;
575
+ after?: Readonly<ApprovalDispatchCursor>;
576
+ }): ApprovalDispatchCursorState;
577
+ deadLetterInbox(inboxId: string, failureCode: string): InboxRecord;
578
+ /** A durable control message wins even while its async binding transition is waiting. */
579
+ hasRestartCancellationAfter(inboxId: string, binding: Readonly<ConversationBinding>): boolean;
580
+ /** The fence and Inbox claims share this database's write transaction. */
581
+ setRestartFence(requestId: string, sourceInvocationId: string): void;
582
+ getRestartFence(): {
583
+ requestId: string;
584
+ sourceInvocationId: string;
585
+ } | undefined;
586
+ clearRestartFence(requestId: string): void;
587
+ claimInbox(input: {
588
+ ownerId: string;
589
+ leaseMs: number;
590
+ limit: number;
591
+ maxAttempts: number;
592
+ maintenanceLimit?: number;
593
+ }): {
594
+ record: InboxRecord;
595
+ fencingToken: number;
596
+ }[];
597
+ finishInbox(input: {
598
+ inboxId: string;
599
+ ownerId: string;
600
+ fencingToken: number;
601
+ outcome: 'dead_letter' | 'processed' | 'retry_wait';
602
+ failureCode?: string;
603
+ retryAt?: number;
604
+ }): InboxRecord;
605
+ /** Return an undispatched Inbox to its queue while another live session holds the lane. */
606
+ deferInboxForSessionLease(input: {
607
+ inboxId: string;
608
+ ownerId: string;
609
+ fencingToken: number;
610
+ retryAt: number;
611
+ }): boolean;
612
+ markInboxDispatching(input: {
613
+ inboxId: string;
614
+ ownerId: string;
615
+ fencingToken: number;
616
+ binding: Readonly<InboundDispatchBindingSnapshot>;
617
+ }): InboxRecord;
618
+ /** Immutable pre-prompt binding for a foreground acceptance contract. */
619
+ bindForegroundTaskAcceptance(input: {
620
+ inboxId: string;
621
+ contractId: string;
622
+ contractDigest: string;
623
+ scope: {
624
+ workspace: string;
625
+ preset: string;
626
+ };
627
+ owner: {
628
+ principalRecordId: string;
629
+ principalVersion: number;
630
+ };
631
+ binding: Pick<ConversationBinding, 'id' | 'version' | 'generation'>;
632
+ dispatchedAt: number;
633
+ }): void;
634
+ finishForegroundTaskAcceptance(input: {
635
+ contractId: string;
636
+ status: AcceptedExecution['status'];
637
+ quiescent: boolean;
638
+ completedAt: number;
639
+ }): void;
640
+ recordForegroundTaskModelSelection(input: {
641
+ contractId: string;
642
+ provider: string;
643
+ model: string;
644
+ reasoningEffort?: string;
645
+ }): void;
646
+ inspectForegroundAcceptedExecution(contract: AcceptanceContract): AcceptedExecution | null;
647
+ /**
648
+ * Re-read the immutable acceptance fence for one exact owner reply target.
649
+ * This deliberately exposes only the completed execution receipt: callers
650
+ * cannot manufacture a foreground subject by naming an arbitrary Inbox.
651
+ */
652
+ inspectForegroundAcceptedExecutionForOwner(input: {
653
+ inboxId: string;
654
+ scope: {
655
+ workspace: string;
656
+ preset: string;
657
+ };
658
+ owner: {
659
+ principalRecordId: string;
660
+ principalVersion: number;
661
+ };
662
+ bindingId: string;
663
+ }): AcceptedExecution | null;
664
+ /** One SQL snapshot binds a pending execution to its still claimed Inbox and current owner. */
665
+ inspectPendingForegroundToolTask(input: Readonly<{
666
+ inboxId: string;
667
+ sessionId: string;
668
+ scope: {
669
+ workspace: string;
670
+ preset: string;
671
+ };
672
+ owner: {
673
+ principalRecordId: string;
674
+ principalVersion: number;
675
+ };
676
+ binding: {
677
+ id: string;
678
+ version: number;
679
+ generation: number;
680
+ };
681
+ }>): Readonly<ForegroundTaskIdentity> | undefined;
682
+ /** Internal Host read: the service supplies an actual unsettled-call task proof.
683
+ * This pending lane does not weaken the separate terminal source reader. */
684
+ readPendingForegroundToolInput(input: Readonly<{
685
+ task: ForegroundTaskIdentity;
686
+ offset?: number;
687
+ maxBytes?: number;
688
+ }>): Readonly<Omit<OwnerForegroundToolInput, 'protocol' | 'attestation'>> | undefined;
689
+ /** Immutable pre-prompt receipt for an authenticated owner foreground turn. */
690
+ bindForegroundTaskExecution(input: {
691
+ inboxId: string;
692
+ scope: {
693
+ workspace: string;
694
+ preset: string;
695
+ };
696
+ owner: {
697
+ principalRecordId: string;
698
+ principalVersion: number;
699
+ };
700
+ binding: Pick<ConversationBinding, 'id' | 'version' | 'generation'>;
701
+ dispatchedAt: number;
702
+ }): void;
703
+ finishForegroundTaskExecution(input: {
704
+ inboxId: string;
705
+ status: ForegroundExecution['status'];
706
+ quiescent: boolean;
707
+ completedAt: number;
708
+ termination?: Readonly<ForegroundTerminationObservation>;
709
+ }): void;
710
+ recordForegroundExecutionModelSelection(input: {
711
+ inboxId: string;
712
+ provider: string;
713
+ model: string;
714
+ reasoningEffort?: string;
715
+ }): void;
716
+ private foregroundSourceFence;
717
+ private foregroundSource;
718
+ /** Host-only durable completion feed. Mutable delivery state never hides a completion. */
719
+ listOwnerForegroundTaskSources(input: OwnerForegroundTaskSourceScope & {
720
+ after?: Readonly<OwnerForegroundTaskSourceCursor>;
721
+ limit?: number;
722
+ }, authority: OwnerRouteAuthority): Readonly<OwnerForegroundTaskSourcePage>;
723
+ /** Host-only exact inbox metadata under the same owner writer fence as the feed. */
724
+ inspectOwnerForegroundTaskSource(input: OwnerForegroundTaskSourceScope & {
725
+ inboxId: string;
726
+ }, authority: OwnerRouteAuthority): Readonly<OwnerForegroundTaskSource> | undefined;
727
+ /** Content comes from the canonical Inbox/Outbox, with no alternate text ledger. */
728
+ readOwnerForegroundTaskSource(input: OwnerForegroundTaskSourceScope & {
729
+ inboxId: string;
730
+ expectedSourceDigest: string;
731
+ maxInputBytes?: number;
732
+ maxReplyBytes?: number;
733
+ }, authority: OwnerRouteAuthority): Readonly<OwnerForegroundTaskSourceContent> | undefined;
734
+ /** Original canonical input for new Host-observed terminal executions; never a replay grant. */
735
+ readOwnerForegroundTaskInput(input: OwnerForegroundTaskSourceScope & {
736
+ inboxId: string;
737
+ expectedSourceDigest: string;
738
+ offset?: number;
739
+ maxBytes?: number;
740
+ }, authority: OwnerRouteAuthority): Readonly<OwnerForegroundTaskInput> | undefined;
741
+ /** Lock order: Delivery, then downstream Evaluation/Memory writer fences. */
742
+ withOwnerForegroundTaskSourceFence<T>(input: OwnerForegroundTaskSourceScope & {
743
+ inboxId: string;
744
+ expectedSourceDigest: string;
745
+ maxInputBytes?: number;
746
+ maxReplyBytes?: number;
747
+ }, authority: OwnerRouteAuthority, callback: (source: Readonly<OwnerForegroundTaskSourceContent>) => T): T;
748
+ /** One owner check and one Delivery writer transaction for an ordered set of exact sources. */
749
+ withOwnerForegroundTaskSourcesFence<T>(input: OwnerForegroundTaskSourceScope & {
750
+ sources: readonly Readonly<OwnerForegroundTaskSourceRef>[];
751
+ }, authority: OwnerRouteAuthority, callback: (sources: readonly (Readonly<OwnerForegroundTaskSourceContent> | undefined)[]) => T): T;
752
+ /** Internal Host composition seam. Keeps one Delivery transaction across mixed source locks. */
753
+ withOwnerLearningSourceFence<T>(input: OwnerForegroundTaskSourceScope, authority: OwnerRouteAuthority, callback: () => T): T;
754
+ private assertForegroundSourceSyncResult;
755
+ private withForegroundSourceRead;
756
+ private foregroundSourceContent;
757
+ inspectForegroundExecutionForOwner(input: {
758
+ inboxId: string;
759
+ scope: {
760
+ workspace: string;
761
+ preset: string;
762
+ };
763
+ owner: {
764
+ principalRecordId: string;
765
+ principalVersion: number;
766
+ };
767
+ bindingId: string;
768
+ bindingVersion: number;
769
+ bindingGeneration: number;
770
+ }): ForegroundExecution | null;
771
+ renewInboxClaim(input: {
772
+ inboxId: string;
773
+ ownerId: string;
774
+ fencingToken: number;
775
+ leaseMs: number;
776
+ }): boolean;
777
+ recoverInbox(input: {
778
+ maxAttempts: number;
779
+ limit?: number;
780
+ }): InboxRecord[];
781
+ enqueue(input: OutboundIntent): OutboxRecord;
782
+ private enqueueIntent;
783
+ /**
784
+ * Atomically revalidate one immutable Policy route and insert its approval
785
+ * Outbox. Legacy routes are deliberately not accepted by this boundary.
786
+ */
787
+ enqueueApprovalRoute(input: {
788
+ route: Readonly<ApprovalDispatchRouteV2>;
789
+ intent: Readonly<{
790
+ approval: NonNullable<OutboundIntent['approval']>;
791
+ idempotencyKey: string;
792
+ text: string;
793
+ }>;
794
+ }): OutboxRecord;
795
+ /** Atomically insert a typed whole-goal result and its immutable authority sidecar. */
796
+ enqueueGoalOutcomeTarget(input: Readonly<{
797
+ intent: OutboundIntent;
798
+ locator: OwnerGoalOutcomeFeedbackLocator;
799
+ proof: OwnerGoalOutcomeFeedbackProof;
800
+ }>): OutboxRecord;
801
+ getGoalOutcomeTarget(outboxId: string): DeliveryGoalOutcomeTarget | undefined;
802
+ /**
803
+ * Resolve and enqueue one Host-owned stable owner route under the same
804
+ * `BEGIN IMMEDIATE` fence as Outbox insertion.
805
+ *
806
+ * This closes the `/new` race between an earlier read and insertion. An
807
+ * existing idempotency winner is returned without mutation (including
808
+ * `unknown_after_send`) only after both the current route and the winner's
809
+ * immutable historical route receipt are revalidated.
810
+ */
811
+ enqueueOwnerRoute(input: {
812
+ authority: OwnerRouteAuthority;
813
+ sourceId: string;
814
+ sourceHash: string;
815
+ idempotencyKey: string;
816
+ text: string;
817
+ format?: 'markdown' | 'plain';
818
+ attachment?: OutboundTextAttachment;
819
+ }): OutboxRecord;
820
+ getOutbox(id: string): OutboxRecord | undefined;
821
+ getOutboxByIdempotencyKey(idempotencyKeyInput: string): OutboxRecord | undefined;
822
+ /** Persist the latest desired replacement for one exact durable message. */
823
+ publishDeliveryPresentation(input: DeliveryPresentationUpdate): StoredDeliveryPresentation;
824
+ getDeliveryPresentation(presentationKeyInput: string): StoredDeliveryPresentation | undefined;
825
+ claimDeliveryPresentation(input: {
826
+ ownerId: string;
827
+ leaseMs: number;
828
+ /** Lifecycles already attempted by this drain pass. */
829
+ excludePresentationKeys?: readonly string[];
830
+ }): {
831
+ presentation: StoredDeliveryPresentation;
832
+ fencingToken: number;
833
+ } | undefined;
834
+ finishDeliveryPresentation(input: {
835
+ presentationKey: string;
836
+ revision: number;
837
+ ownerId: string;
838
+ fencingToken: number;
839
+ outcome: 'presented' | 'retry_wait' | 'dead';
840
+ providerMessageId?: string;
841
+ failureCode?: string;
842
+ nextAttemptAt?: number;
843
+ }): StoredDeliveryPresentation;
844
+ /** Exact provider-addressed lookup used only to bind authenticated replies. */
845
+ getOutboxByProviderMessage(channelInput: string, accountInput: string, providerMessageIdInput: string): OutboxRecord | undefined;
846
+ /**
847
+ * Exact provider-addressed lookup that refuses ambiguity. The schema's
848
+ * unique index already prevents duplicates; this is defense in depth for a
849
+ * reply binding that must never attach to the wrong message.
850
+ */
851
+ getUniqueOutboxByProviderMessage(channelInput: string, accountInput: string, providerMessageIdInput: string): OutboxRecord | undefined;
852
+ getApprovalIntent(operationId: string, bindingId: string): NonNullable<OutboundIntent['approval']> | undefined;
853
+ getModelPicker(operationId: string, bindingId: string): ModelPickerIntent | undefined;
854
+ getModelPickerRecord(operationId: string, bindingId: string): OutboxRecord | undefined;
855
+ getPermissionPicker(operationId: string, bindingId: string): PermissionPickerIntent | undefined;
856
+ getPermissionPickerRecord(operationId: string, bindingId: string): OutboxRecord | undefined;
857
+ getModelPickerState(operationId: string, bindingId: string): ModelPickerState | undefined;
858
+ advanceModelPicker(input: {
859
+ operationId: string;
860
+ bindingId: string;
861
+ expected: ModelPickerState;
862
+ next: ModelRouteRef;
863
+ }): {
864
+ applied: boolean;
865
+ state: ModelPickerState;
866
+ };
867
+ listOutbox(input?: {
868
+ bindingId?: string;
869
+ limit?: number;
870
+ }): OutboxRecord[];
871
+ /** Recheck a claimed route immediately before provider I/O. */
872
+ validateClaimedOwnerRoute(recordInput: Readonly<OutboxRecord>, guard: Readonly<OwnerRouteDispatchGuard>): OwnerRouteDispatchValidation;
873
+ /** Recheck a durable owner route before mutating its exact provider message. */
874
+ validatePresentationOwnerRoute(recordInput: Readonly<OutboxRecord>, guard: Readonly<OwnerRouteDispatchGuard>): OwnerRouteDispatchValidation;
875
+ private inspectOwnerRouteDispatch;
876
+ private ownerRouteIsProvablyUnsent;
877
+ private rebindOwnerRouteBeforeClaim;
878
+ private deadLetterOwnerRouteBeforeClaim;
879
+ private deferOwnerRouteBeforeClaim;
880
+ claimOutbox(input: {
881
+ ownerId: string;
882
+ leaseMs: number;
883
+ limit: number;
884
+ maxAttempts: number;
885
+ /** Undefined preserves the legacy store-level behavior; an empty list parks every unknown lane. */
886
+ unknownReconcileRoutes?: readonly Readonly<{
887
+ channel: string;
888
+ account: string;
889
+ }>[];
890
+ /** Locally active work that must not be reclaimed even if its durable lease was externally lost. */
891
+ excludeIds?: readonly string[];
892
+ maintenanceLimit?: number;
893
+ ownerRouteGuard?: Readonly<OwnerRouteDispatchGuard>;
894
+ }): {
895
+ record: OutboxRecord;
896
+ fencingToken: number;
897
+ mode: 'reconcile' | 'send';
898
+ }[];
899
+ renewOutboxClaim(input: {
900
+ outboxId: string;
901
+ ownerId: string;
902
+ fencingToken: number;
903
+ leaseMs: number;
904
+ }): boolean;
905
+ finishOutbox(input: {
906
+ outboxId: string;
907
+ ownerId: string;
908
+ fencingToken: number;
909
+ outcome: 'accepted' | 'dead' | 'retry_wait' | 'unknown_after_send';
910
+ providerMessageId?: string;
911
+ failureCode?: string;
912
+ retryAt?: number;
913
+ }): OutboxRecord;
914
+ recoverOutbox(input: {
915
+ maxAttempts: number;
916
+ limit?: number;
917
+ }): OutboxRecord[];
918
+ recordReceipt(input: DeliveryReceipt): OutboxRecord;
919
+ revokePrincipal(id: string, expectedVersion: number): DeliveryPrincipal;
920
+ linkPrincipal(input: {
921
+ owner: ExternalPrincipalKey;
922
+ linked: ExternalPrincipalKey;
923
+ expectedLinkedVersion: number;
924
+ }): DeliveryPrincipal;
925
+ resolveInbox(input: {
926
+ inboxId: string;
927
+ expectedAttemptCount: number;
928
+ resolution: 'cancel' | 'retry';
929
+ operatorId: string;
930
+ }): DeadLetterResolutionResult<InboxRecord>;
931
+ resolveOutbox(input: {
932
+ outboxId: string;
933
+ expectedAttemptCount: number;
934
+ resolution: 'cancel' | 'retry';
935
+ operatorId: string;
936
+ }): DeadLetterResolutionResult<OutboxRecord>;
937
+ beginApprovalSettlement(input: {
938
+ operationId: string;
939
+ payload: unknown;
940
+ createIfMissing?: boolean;
941
+ }): {
942
+ payloadHash: string;
943
+ replayed: boolean;
944
+ result?: unknown;
945
+ };
946
+ completeApprovalSettlement(input: {
947
+ operationId: string;
948
+ payloadHash: string;
949
+ result: unknown;
950
+ }): unknown;
951
+ beginModelSelectionSettlement(input: {
952
+ operationId: string;
953
+ bindingId: string;
954
+ expected: ModelPickerState;
955
+ payload: unknown;
956
+ createIfMissing?: boolean;
957
+ }): {
958
+ payloadHash: string;
959
+ replayed: boolean;
960
+ status: 'completed' | 'pending';
961
+ result?: unknown;
962
+ };
963
+ getModelSelectionSettlement(input: {
964
+ operationId: string;
965
+ bindingId: string;
966
+ expected: ModelPickerState;
967
+ payload: unknown;
968
+ }): {
969
+ status: 'completed' | 'pending' | 'processing';
970
+ result?: unknown;
971
+ } | undefined;
972
+ claimModelSelectionSettlements(input: {
973
+ ownerId: string;
974
+ leaseMs: number;
975
+ limit?: number;
976
+ }): Array<{
977
+ operationId: string;
978
+ bindingId: string;
979
+ payloadHash: string;
980
+ payload: unknown;
981
+ fencingToken: number;
982
+ }>;
983
+ nextModelSelectionClaimAt(): number | undefined;
984
+ renewModelSelectionSettlement(input: {
985
+ operationId: string;
986
+ ownerId: string;
987
+ fencingToken: number;
988
+ leaseMs: number;
989
+ }): boolean;
990
+ completeModelSelectionSettlement(input: {
991
+ operationId: string;
992
+ payloadHash: string;
993
+ result: unknown;
994
+ selection?: {
995
+ conversation: ConversationRef;
996
+ route: ModelRouteRef;
997
+ };
998
+ reply?: OutboundIntent;
999
+ superseded?: {
1000
+ result: unknown;
1001
+ reply?: OutboundIntent;
1002
+ };
1003
+ ownerId?: string;
1004
+ fencingToken?: number;
1005
+ }): unknown;
1006
+ workflowTraceSourceAttestation(): Readonly<WorkflowTraceSourceAttestation>;
1007
+ /**
1008
+ * Apply one already-authenticated source revision. First version may be any
1009
+ * positive integer and gaps are allowed; lower versions and same-version
1010
+ * content changes fail closed.
1011
+ */
1012
+ recordWorkflowTraceRevision(input: Readonly<WorkflowTraceRevision>): {
1013
+ revision: Readonly<WorkflowTraceRevision>;
1014
+ replayed: boolean;
1015
+ };
1016
+ /**
1017
+ * Atomic owner command ledger + private template review + source revision.
1018
+ * Prompt text is stored only in workflow_template_registry.content_json; the
1019
+ * command receipt and Growth trace carry only references and digests.
1020
+ */
1021
+ commitOwnerWorkflowTraceCommand(input: Readonly<{
1022
+ action: 'retract' | 'upsert';
1023
+ operationId: string;
1024
+ payloadDigest: string;
1025
+ binding: Readonly<ConversationBinding>;
1026
+ reviewInboxId: string;
1027
+ sourceInboxId: string;
1028
+ sourceOutboxId: string;
1029
+ subjectRef: string;
1030
+ occurredAt: number;
1031
+ taskRef?: string;
1032
+ /** Principal identity is derived below from the authenticated live binding. */
1033
+ templateContent?: Readonly<Omit<WorkflowAutomationTemplateContent, 'principalId'>>;
1034
+ steps?: readonly Readonly<WorkflowStepFingerprint>[];
1035
+ }>): OwnerWorkflowTraceCommandResult;
1036
+ /**
1037
+ * Atomically admit one authenticated owner work-item result and the explicit
1038
+ * continuation requested in the same reply. The result insert owns the single
1039
+ * Inbox handoff; the continuation insert reuses that processed Inbox in the
1040
+ * same transaction. A failure in either lane leaves neither row behind, so a
1041
+ * provider retry can attempt both again instead of losing one silently.
1042
+ */
1043
+ admitOwnerWorkItemFeedbackWithReply(input: Readonly<{
1044
+ feedback: WorkItemFeedbackSource;
1045
+ binding: Readonly<ConversationBinding>;
1046
+ report: StoredWorkItemReport;
1047
+ fence: () => void;
1048
+ }>): Readonly<{
1049
+ feedback: WorkItemFeedbackIntent;
1050
+ reply: WorkItemReplySource;
1051
+ }>;
1052
+ getNaturalObjectiveIntent(inboxId: string): NaturalObjectiveIntent | undefined;
1053
+ listPendingNaturalObjectiveIntents(limit?: number, afterAdmissionSequence?: number): readonly NaturalObjectiveIntent[];
1054
+ hasEarlierPendingNaturalObjectiveIntent(sourceOutboxId: string, admissionSequence: number): boolean;
1055
+ /** Same source proof required by the local workflow commit, before Evaluation append. */
1056
+ isVerifiedForegroundObjectiveTarget(binding: Readonly<ConversationBinding>, sourceInboxId: string, sourceOutboxId: string): boolean;
1057
+ /** Freeze the immutable owner wording and exact completed result before any Evaluation I/O. */
1058
+ prepareNaturalObjectiveIntent(input: Readonly<{
1059
+ binding: Readonly<ConversationBinding>;
1060
+ feedbackInboxId: string;
1061
+ sourceInboxId: string;
1062
+ sourceOutboxId: string;
1063
+ selection: ObjectiveFeedbackStatus | 'withdraw';
1064
+ }>): NaturalObjectiveIntent;
1065
+ /** A CAS command is fixed once; retries may never inspect a newer version and rebase it. */
1066
+ freezeNaturalObjectiveIntent(inboxId: string, current: Readonly<{
1067
+ version: number;
1068
+ objectiveStatus: ObjectiveFeedbackStatus | 'unknown';
1069
+ }> | undefined): NaturalObjectiveIntent | undefined;
1070
+ settleNaturalObjectiveIntent(inboxId: string, status: 'projected' | 'conflict', canonical?: NaturalObjectiveIntent['canonical']): void;
1071
+ findNaturalObjectiveFeedbackByOperation(sourceOutboxId: string, operationId: string, lineage: Readonly<{
1072
+ principalRecordId: string;
1073
+ principalVersion: number;
1074
+ }>): Readonly<{
1075
+ inboxId: string;
1076
+ text: string;
1077
+ truncated: boolean;
1078
+ }> | undefined;
1079
+ verifiedWorkflowObjectiveState(sourceOutboxId: string, lineage?: Readonly<{
1080
+ principalRecordId: string;
1081
+ principalVersion: number;
1082
+ }>): {
1083
+ version: number;
1084
+ objectiveStatus: 'achieved' | 'partial' | 'not-achieved' | 'unknown';
1085
+ } | undefined;
1086
+ /** Commit exact owner feedback (typed command or frozen natural intent) and closed-set workflow evidence. */
1087
+ commitVerifiedWorkflowTraceFeedback(input: Readonly<{
1088
+ binding: Readonly<ConversationBinding>;
1089
+ feedbackInboxId: string;
1090
+ sourceInboxId: string;
1091
+ sourceOutboxId: string;
1092
+ objectiveStatus: 'achieved' | 'partial' | 'not-achieved' | 'unknown';
1093
+ command?: Readonly<import('./feedback-command.js').ObjectiveRevisionCommand>;
1094
+ }>): VerifiedWorkflowTraceFeedbackResult;
1095
+ /**
1096
+ * Record a workflow learned from one Delivery-reverified owner-root successful
1097
+ * Goal run. Unlike the two conversation-fenced routes, there is no live
1098
+ * Inbox/Outbox: the caller (the Host-only Delivery service method) must have
1099
+ * independently re-fetched the verified Goals source and the owner-run-trace
1100
+ * proof, so this method never accepts a caller-supplied prompt, template, or
1101
+ * proof digest — all of them are rebuilt below from the verified source.
1102
+ *
1103
+ * The goal must be honestly reducible to the single built-in
1104
+ * `assistant.agent-turn` step that paused Growth materialization can run
1105
+ * (exactly one step, zero executable/business tools). Otherwise it abstains
1106
+ * with zero writes. The raw objective is stored only in the new table's
1107
+ * content_json and never enters the trace. Re-submitting the same verified
1108
+ * run deterministically replays its prior revision.
1109
+ */
1110
+ commitOwnerAnchoredWorkflowTrace(input: Readonly<{
1111
+ binding: Readonly<ConversationBinding>;
1112
+ ownerRouteId: string;
1113
+ scope: Readonly<{
1114
+ workspace: string;
1115
+ preset: string;
1116
+ }>;
1117
+ goal: Readonly<{
1118
+ id: string;
1119
+ definition: Readonly<{
1120
+ version: number;
1121
+ digest: string;
1122
+ objective: string;
1123
+ }>;
1124
+ sessionId: string;
1125
+ nativeGoalId: string;
1126
+ }>;
1127
+ runId: string;
1128
+ turn: number;
1129
+ acceptance: Readonly<{
1130
+ contractId: string;
1131
+ receiptDigest: string;
1132
+ verifiedAt: number;
1133
+ validUntil: number;
1134
+ }>;
1135
+ steps: readonly Readonly<{
1136
+ id: string;
1137
+ toolName: string;
1138
+ }>[];
1139
+ failedObservations?: readonly unknown[];
1140
+ /** Trusted owner-run-trace digest re-fetched by the service via Goals Host proof. */
1141
+ ownerRunTraceDigest: string;
1142
+ }>): CommitOwnerAnchoredWorkflowTraceResult;
1143
+ private insertVerifiedWorkflowTaskFeedback;
1144
+ private replayVerifiedWorkflowTraceFeedback;
1145
+ getWorkflowAutomationTemplate(templateInput: Readonly<WorkflowAutomationTemplate>): StoredWorkflowTemplate | undefined;
1146
+ /**
1147
+ * Rebuild a template learned from a Delivery-reverified owner-root Goal run.
1148
+ * Every column and receipt field is re-derived and cross-checked; a mismatch
1149
+ * fails closed rather than resolving attacker- or corruption-influenced data.
1150
+ */
1151
+ private getOwnerAnchoredWorkflowTemplate;
1152
+ requeueCurrentWorkflowTraces(): number;
1153
+ enqueuePreferenceProjection(events: readonly Readonly<DeliveryPreferenceEvent>[]): Readonly<{
1154
+ batchKey: string;
1155
+ payloadDigest: string;
1156
+ replayed: boolean;
1157
+ }>;
1158
+ /**
1159
+ * Persist an Agent reply and its content-free learning projection under one
1160
+ * SQLite commit. A process crash can therefore expose neither row or both,
1161
+ * but never a durable reply that permanently lost its completion signal.
1162
+ */
1163
+ enqueueReplyWithPreferenceProjection(input: OutboundIntent, eventsForReply: (reply: Readonly<OutboxRecord>) => readonly Readonly<DeliveryPreferenceEvent>[] | undefined): Readonly<{
1164
+ reply: OutboxRecord;
1165
+ projection?: Readonly<{
1166
+ batchKey: string;
1167
+ payloadDigest: string;
1168
+ replayed: boolean;
1169
+ }>;
1170
+ }>;
1171
+ listPendingPreferenceProjections(limitInput?: number, nowInput?: number): PreferenceProjectionOutboxEntry[];
1172
+ /** Earliest retry time among global legacy or exact owner-lane heads. */
1173
+ nextPreferenceProjectionAttemptAt(nowInput?: number): number | undefined;
1174
+ /**
1175
+ * A direct control may run only after every earlier projection in its exact
1176
+ * owner lane is terminal. Valid legacy rows are a global upgrade barrier
1177
+ * because their missing cursor makes a narrower comparison impossible.
1178
+ */
1179
+ hasBlockingPreferenceProjectionBefore(input: Readonly<{
1180
+ scope: Readonly<{
1181
+ workspace: string;
1182
+ preset: string;
1183
+ }>;
1184
+ principalLineage: Readonly<{
1185
+ principalRecordId: string;
1186
+ principalVersion: number;
1187
+ }>;
1188
+ admissionCursor: Readonly<{
1189
+ epoch: string;
1190
+ sequence: number;
1191
+ }>;
1192
+ }>): boolean;
1193
+ completePreferenceProjection(input: {
1194
+ batchKey: string;
1195
+ payloadDigest: string;
1196
+ }): void;
1197
+ deferPreferenceProjection(input: {
1198
+ batchKey: string;
1199
+ payloadDigest: string;
1200
+ now: number;
1201
+ retryAt: number;
1202
+ failureCode: string;
1203
+ }): void;
1204
+ /**
1205
+ * Revalidate one previously-read batch against the live Delivery owner.
1206
+ * Stale, legacy, poison, already-terminal, and peer-completed rows are
1207
+ * acknowledged without invoking a downstream sink.
1208
+ */
1209
+ preferenceProjectionHasCurrentOwner(input: {
1210
+ batchKey: string;
1211
+ payloadDigest: string;
1212
+ }): boolean;
1213
+ /**
1214
+ * Linearizable projection for a process-local synchronous Preference writer.
1215
+ * Delivery's BEGIN IMMEDIATE remains held while Preference commits, giving
1216
+ * all cooperating processes the fixed Delivery -> Preference lock order.
1217
+ * A handoff therefore linearizes wholly before the callback (which is then
1218
+ * skipped) or wholly after the Preference commit and Delivery ACK.
1219
+ */
1220
+ projectPreferenceProjectionUnderOwnerFence(input: {
1221
+ batchKey: string;
1222
+ payloadDigest: string;
1223
+ }, project: (entry: Readonly<PreferenceProjectionOutboxEntry>) => void): PreferenceProjectionFenceResult;
1224
+ requeuePreferenceProjections(): number;
1225
+ private normalizePreferenceProjectionLanes;
1226
+ private currentPreferenceProjectionInTransaction;
1227
+ private terminalizePreferenceProjectionInTransaction;
1228
+ private validPreferenceProjectionEntries;
1229
+ private insertPreferenceProjection;
1230
+ listPendingWorkflowTraceRevisions(limitInput?: number, nowInput?: number): WorkflowTraceOutboxEntry[];
1231
+ completeWorkflowTraceRevision(input: {
1232
+ subjectRef: string;
1233
+ version: number;
1234
+ digest: string;
1235
+ now?: number;
1236
+ }): void;
1237
+ deferWorkflowTraceRevision(input: {
1238
+ subjectRef: string;
1239
+ version: number;
1240
+ digest: string;
1241
+ now: number;
1242
+ retryAt: number;
1243
+ failureCode: string;
1244
+ }): void;
1245
+ private insertWorkflowTraceRevisionInTransaction;
1246
+ private revokeCurrentWorkflowTemplateInTransaction;
1247
+ /** Ownership survives release, revocation and restart; it is not an active-lease query. */
1248
+ requiresSessionLease(sessionId: string): boolean;
1249
+ claimSessionLease(target: SessionLeaseTarget, holderId: string, leaseMs: number): SessionLeaseClaim;
1250
+ markSessionLeaseDispatched(lease: SessionLease): boolean;
1251
+ hasSessionLease(lease: SessionLease): boolean;
1252
+ renewSessionLease(lease: SessionLease, leaseMs: number): boolean;
1253
+ finishSessionLease(lease: SessionLease, result: {
1254
+ quiescent: boolean;
1255
+ }): boolean;
1256
+ private sessionLeaseShape;
1257
+ /** Re-reads target authority; no runtime-supplied binding is trusted after claim. */
1258
+ private sessionLeaseAuthority;
1259
+ private sessionLeaseCurrent;
1260
+ close(): void;
1261
+ private transaction;
1262
+ private advanceModelCommandEpoch;
1263
+ private nextBindingGenerationByHash;
1264
+ private assertOpen;
1265
+ }
1266
+ export {};
1267
+ //# sourceMappingURL=store.d.ts.map