@qlairoslabs/acp-client 0.12.1 → 0.13.1-alpha.1

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 (288) hide show
  1. package/CHANGELOG-consumer-fixes.md +17 -10
  2. package/CHANGELOG-controller-interface.md +258 -0
  3. package/CHANGELOG-metering.md +29 -0
  4. package/CHANGELOG-operation-lifecycle.md +15 -1
  5. package/CONSUMER_GUIDE.md +984 -6
  6. package/MIGRATION-0.10-to-0.12.md +4 -1
  7. package/MIGRATION-0.12-to-0.13.md +288 -0
  8. package/README.md +17 -16
  9. package/package.json +11 -2
  10. package/src/acp-client-handlers.ts +48 -0
  11. package/src/activity.ts +3 -0
  12. package/src/adapters.ts +25 -0
  13. package/src/agent/adoption/provider-attachment.ts +33 -0
  14. package/src/agent/adoption/provider-session-delete.ts +1 -1
  15. package/src/agent/adoption/provider-sessions.ts +3 -2
  16. package/src/agent/append-assistant-message.ts +91 -0
  17. package/src/agent/config.ts +54 -6
  18. package/src/agent/conversation-manager.ts +95 -158
  19. package/src/agent/manager-settings.ts +1 -0
  20. package/src/agent/native-channel-lifecycle.ts +111 -0
  21. package/src/agent/native-operations.ts +39 -0
  22. package/src/agent/persisted-lifecycle.ts +44 -4
  23. package/src/agent/persistence-policy/context.ts +13 -0
  24. package/src/agent/persistence-policy/resolver.ts +7 -0
  25. package/src/agent/persistence-policy/types.ts +1 -0
  26. package/src/agent/record-capture.ts +1 -0
  27. package/src/agent-adapter-registry.ts +33 -7
  28. package/src/agent-conversation-contracts.ts +14 -1
  29. package/src/agent-conversation-errors.ts +8 -0
  30. package/src/agent-conversation-owner.ts +9 -4
  31. package/src/agent-session-config.ts +137 -0
  32. package/src/agent-session.ts +440 -934
  33. package/src/agent.ts +168 -0
  34. package/src/capabilities.ts +2 -0
  35. package/src/checkpointing/recovery.ts +3 -0
  36. package/src/cli/index.ts +3 -3
  37. package/src/cli/managed.ts +2 -2
  38. package/src/client.ts +56 -96
  39. package/src/connection-attempt.ts +95 -0
  40. package/src/controller-connection.ts +115 -0
  41. package/src/controller.ts +158 -148
  42. package/src/conversation-controller/capabilities.ts +88 -0
  43. package/src/conversation-controller/contracts.ts +208 -0
  44. package/src/conversation-controller/factory.ts +39 -0
  45. package/src/conversation-controller/guards.ts +98 -0
  46. package/src/conversation-controller/index.ts +20 -0
  47. package/src/conversation-startup.ts +35 -0
  48. package/src/conversation-turns/backend-turns.ts +373 -0
  49. package/src/conversation-turns/clear-operations.ts +37 -0
  50. package/src/conversation-turns/context.ts +135 -0
  51. package/src/conversation-turns/index.ts +4 -0
  52. package/src/conversation-turns/record-helpers.ts +75 -0
  53. package/src/conversation-turns/recording.ts +235 -0
  54. package/src/conversation-turns/run-turn.ts +367 -0
  55. package/src/conversation-turns/turn-run.ts +57 -0
  56. package/src/errors.ts +41 -0
  57. package/src/handoff-options.ts +81 -0
  58. package/src/identity/checkpoint-backed.ts +1 -1
  59. package/src/index.ts +59 -3
  60. package/src/internal-inference/coordination/manager.ts +11 -0
  61. package/src/internal-inference/runtime/harness-runtime.ts +4 -4
  62. package/src/launcher.ts +37 -2
  63. package/src/media/parts.ts +5 -0
  64. package/src/message-status.ts +83 -0
  65. package/src/metering/engine.ts +39 -64
  66. package/src/metering/measurement-provenance.ts +36 -0
  67. package/src/metering/native/durability.ts +115 -0
  68. package/src/metering/native/ledger.ts +104 -0
  69. package/src/metering/native/operation.ts +85 -0
  70. package/src/metering/native/projection.ts +114 -0
  71. package/src/metering/native/proof.ts +51 -0
  72. package/src/metering/native/requirements.ts +10 -0
  73. package/src/metering/native/retirement.ts +92 -0
  74. package/src/metering/native/source.ts +90 -0
  75. package/src/metering/record.ts +38 -1
  76. package/src/metering/state.ts +13 -3
  77. package/src/native/approvals.ts +186 -0
  78. package/src/native/capabilities.ts +17 -0
  79. package/src/native/channel-changes.ts +211 -0
  80. package/src/native/connection.ts +56 -0
  81. package/src/native/controller.ts +592 -0
  82. package/src/native/delegation-sender.ts +26 -0
  83. package/src/native/errors.ts +35 -0
  84. package/src/native/functions.ts +156 -0
  85. package/src/native/host-config.ts +59 -0
  86. package/src/native/host.ts +978 -0
  87. package/src/native/item-receipts.ts +15 -0
  88. package/src/native/metering.ts +12 -0
  89. package/src/native/records.ts +166 -0
  90. package/src/native/recovery.ts +186 -0
  91. package/src/native/reminders/fixtures/schema21.sqlite.gz +0 -0
  92. package/src/native/reminders/idle.ts +70 -0
  93. package/src/native/reminders/limits.ts +19 -0
  94. package/src/native/reminders/notifications.ts +29 -0
  95. package/src/native/reminders/routine-guard.ts +66 -0
  96. package/src/native/reminders/routine-schedule.ts +25 -0
  97. package/src/native/reminders/routine-wire.ts +21 -0
  98. package/src/native/reminders/schedule.ts +97 -0
  99. package/src/native/reminders/service.ts +280 -0
  100. package/src/native/reminders/supervisor.ts +91 -0
  101. package/src/native/reminders/sync.ts +301 -0
  102. package/src/native/reminders/wire.ts +197 -0
  103. package/src/native/submission-withdrawal.ts +65 -0
  104. package/src/native/usage.ts +15 -0
  105. package/src/native/worker-delivery.ts +61 -0
  106. package/src/native-harness/README.md +726 -0
  107. package/src/native-harness/package.json +24 -0
  108. package/src/native-harness/scripts/build-routine-zones.py +47 -0
  109. package/src/native-harness/src/capabilities/context/build.ts +59 -0
  110. package/src/native-harness/src/capabilities/context/instructions/agent-demo.md +11 -0
  111. package/src/native-harness/src/capabilities/context/instructions/agent.md +5 -0
  112. package/src/native-harness/src/capabilities/context/instructions/harness.md +7 -0
  113. package/src/native-harness/src/capabilities/context/load-instructions.ts +22 -0
  114. package/src/native-harness/src/capabilities/context/session.ts +93 -0
  115. package/src/native-harness/src/capabilities/model/attempt.ts +27 -0
  116. package/src/native-harness/src/capabilities/model/openrouter-stream.ts +72 -0
  117. package/src/native-harness/src/capabilities/model/openrouter.ts +62 -0
  118. package/src/native-harness/src/capabilities/model/runner.ts +116 -0
  119. package/src/native-harness/src/capabilities/model/scenario-attempt.ts +50 -0
  120. package/src/native-harness/src/capabilities/model/scenario-file.ts +125 -0
  121. package/src/native-harness/src/capabilities/model/scripted-error.ts +6 -0
  122. package/src/native-harness/src/capabilities/model/scripted.ts +81 -0
  123. package/src/native-harness/src/capabilities/model/usage.ts +15 -0
  124. package/src/native-harness/src/capabilities/reminders/cron-calendar.ts +50 -0
  125. package/src/native-harness/src/capabilities/reminders/cron-fields.ts +46 -0
  126. package/src/native-harness/src/capabilities/reminders/cron-proof.ts +32 -0
  127. package/src/native-harness/src/capabilities/reminders/cron-zone.ts +53 -0
  128. package/src/native-harness/src/capabilities/reminders/iana-zones.json.gz +0 -0
  129. package/src/native-harness/src/capabilities/reminders/iana-zones.ts +34 -0
  130. package/src/native-harness/src/capabilities/reminders/interval.ts +30 -0
  131. package/src/native-harness/src/capabilities/reminders/routine-advance.ts +47 -0
  132. package/src/native-harness/src/capabilities/reminders/routine-backlog.ts +47 -0
  133. package/src/native-harness/src/capabilities/reminders/routine-expiry.ts +15 -0
  134. package/src/native-harness/src/capabilities/reminders/routine-occurrence.ts +65 -0
  135. package/src/native-harness/src/capabilities/reminders/routine-schedule.ts +70 -0
  136. package/src/native-harness/src/capabilities/reminders/unattended.ts +8 -0
  137. package/src/native-harness/src/capabilities/tools/builtin/current-time.ts +28 -0
  138. package/src/native-harness/src/capabilities/tools/builtin/notify-channel.ts +17 -0
  139. package/src/native-harness/src/capabilities/tools/debug/index.ts +13 -0
  140. package/src/native-harness/src/capabilities/tools/debug/result.ts +12 -0
  141. package/src/native-harness/src/capabilities/tools/debug/test-echo.ts +16 -0
  142. package/src/native-harness/src/capabilities/tools/debug/test-fail.ts +14 -0
  143. package/src/native-harness/src/capabilities/tools/debug/test-wait.ts +19 -0
  144. package/src/native-harness/src/capabilities/tools/reminders/index.ts +97 -0
  145. package/src/native-harness/src/capabilities/tools/runtime/catalog.ts +103 -0
  146. package/src/native-harness/src/capabilities/tools/runtime/functions.ts +130 -0
  147. package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +48 -0
  148. package/src/native-harness/src/capabilities/tools/testing/echo.ts +18 -0
  149. package/src/native-harness/src/capabilities/tools/testing/record.ts +47 -0
  150. package/src/native-harness/src/capabilities/tools/timeline/index.ts +41 -0
  151. package/src/native-harness/src/client.ts +18 -0
  152. package/src/native-harness/src/contracts/agent.ts +105 -0
  153. package/src/native-harness/src/contracts/config-permissions.ts +49 -0
  154. package/src/native-harness/src/contracts/context.ts +112 -0
  155. package/src/native-harness/src/contracts/events.ts +47 -0
  156. package/src/native-harness/src/contracts/input-limits.ts +7 -0
  157. package/src/native-harness/src/contracts/inspection.ts +22 -0
  158. package/src/native-harness/src/contracts/loop.ts +31 -0
  159. package/src/native-harness/src/contracts/model-execution.ts +83 -0
  160. package/src/native-harness/src/contracts/operator-controls.ts +106 -0
  161. package/src/native-harness/src/contracts/output.ts +13 -0
  162. package/src/native-harness/src/contracts/protocol.ts +320 -0
  163. package/src/native-harness/src/contracts/reminders.ts +134 -0
  164. package/src/native-harness/src/contracts/routines.ts +20 -0
  165. package/src/native-harness/src/contracts/scenario.ts +42 -0
  166. package/src/native-harness/src/contracts/session-file.ts +20 -0
  167. package/src/native-harness/src/contracts/session.ts +184 -0
  168. package/src/native-harness/src/contracts/storage.ts +597 -0
  169. package/src/native-harness/src/contracts/timeline-retrieval.ts +40 -0
  170. package/src/native-harness/src/contracts/tools.ts +133 -0
  171. package/src/native-harness/src/governance/permissions/gate.ts +129 -0
  172. package/src/native-harness/src/governance/policy/resolve.ts +32 -0
  173. package/src/native-harness/src/index.ts +322 -0
  174. package/src/native-harness/src/interfaces/cli/chat.ts +83 -0
  175. package/src/native-harness/src/interfaces/cli/development.ts +145 -0
  176. package/src/native-harness/src/interfaces/cli/format-reply.ts +27 -0
  177. package/src/native-harness/src/interfaces/cli/listeners.ts +74 -0
  178. package/src/native-harness/src/interfaces/cli/main.ts +47 -0
  179. package/src/native-harness/src/interfaces/cli/scenario.ts +37 -0
  180. package/src/native-harness/src/interfaces/cli/serve.ts +21 -0
  181. package/src/native-harness/src/interfaces/cli/start.ts +106 -0
  182. package/src/native-harness/src/interfaces/client.ts +225 -0
  183. package/src/native-harness/src/interfaces/inspector/index.html +283 -0
  184. package/src/native-harness/src/interfaces/inspector/observe.ts +35 -0
  185. package/src/native-harness/src/interfaces/inspector/server.ts +56 -0
  186. package/src/native-harness/src/interfaces/inspector/state.ts +92 -0
  187. package/src/native-harness/src/interfaces/protocol/channel-changes.ts +153 -0
  188. package/src/native-harness/src/interfaces/protocol/framing.ts +47 -0
  189. package/src/native-harness/src/interfaces/protocol/functions.ts +87 -0
  190. package/src/native-harness/src/interfaces/protocol/in-process.ts +67 -0
  191. package/src/native-harness/src/interfaces/protocol/live-queue.ts +55 -0
  192. package/src/native-harness/src/interfaces/protocol/load.ts +60 -0
  193. package/src/native-harness/src/interfaces/protocol/local.ts +120 -0
  194. package/src/native-harness/src/interfaces/protocol/operator.ts +120 -0
  195. package/src/native-harness/src/interfaces/protocol/output.ts +59 -0
  196. package/src/native-harness/src/interfaces/protocol/server.ts +519 -0
  197. package/src/native-harness/src/interfaces/protocol/stdio-client.ts +126 -0
  198. package/src/native-harness/src/interfaces/protocol/stdio-server.ts +82 -0
  199. package/src/native-harness/src/interfaces/protocol/subscribe.ts +41 -0
  200. package/src/native-harness/src/interfaces/protocol/transfers.ts +146 -0
  201. package/src/native-harness/src/interfaces/web-chat/index.html +94 -0
  202. package/src/native-harness/src/interfaces/web-chat/server.ts +34 -0
  203. package/src/native-harness/src/kernel/channels.ts +409 -0
  204. package/src/native-harness/src/kernel/loop.ts +45 -0
  205. package/src/native-harness/src/runtime/config/development.ts +23 -0
  206. package/src/native-harness/src/runtime/config/managed.ts +2 -0
  207. package/src/native-harness/src/runtime/config/paths.ts +33 -0
  208. package/src/native-harness/src/runtime/reminder-timer.ts +42 -0
  209. package/src/native-harness/src/runtime/reminder-validation.ts +125 -0
  210. package/src/native-harness/src/runtime/reminders.ts +66 -0
  211. package/src/native-harness/src/state/storage/archive.ts +257 -0
  212. package/src/native-harness/src/state/storage/engine.ts +1204 -0
  213. package/src/native-harness/src/state/storage/inference.ts +124 -0
  214. package/src/native-harness/src/state/storage/memory-reminders.ts +103 -0
  215. package/src/native-harness/src/state/storage/memory.ts +354 -0
  216. package/src/native-harness/src/state/storage/policy-metadata.ts +32 -0
  217. package/src/native-harness/src/state/storage/reminder-archive.ts +104 -0
  218. package/src/native-harness/src/state/storage/reminder-change.ts +138 -0
  219. package/src/native-harness/src/state/storage/reminder-tables.ts +35 -0
  220. package/src/native-harness/src/state/storage/retrieval.ts +122 -0
  221. package/src/native-harness/src/state/storage/routine-row.ts +25 -0
  222. package/src/native-harness/src/state/storage/script-identity.ts +7 -0
  223. package/src/native-harness/src/state/storage/session-file.ts +85 -0
  224. package/src/native-harness/src/state/storage/sqlite-reminders.ts +174 -0
  225. package/src/native-harness/src/state/storage/sqlite.ts +632 -0
  226. package/src/native-harness/src/testing.ts +190 -0
  227. package/src/native-harness/src/util/config.ts +66 -0
  228. package/src/native-harness/src/util/intake.ts +7 -0
  229. package/src/native-harness/src/util/json.ts +41 -0
  230. package/src/native-harness/src/util/message-position.ts +3 -0
  231. package/src/native-harness/src/util/reminder-schedule.ts +44 -0
  232. package/src/native-harness/src/util/schema.ts +40 -0
  233. package/src/native-harness/src/util/timeline-text.ts +72 -0
  234. package/src/native-harness/src/util/timeline-tool-names.ts +3 -0
  235. package/src/native-harness/tsconfig.json +20 -0
  236. package/src/observation/agent-event-bus.ts +44 -18
  237. package/src/observation/index.ts +1 -0
  238. package/src/operations/contracts.ts +11 -3
  239. package/src/operations/errors.ts +5 -0
  240. package/src/operations/stale-policy.ts +1 -1
  241. package/src/operations/supervisor.ts +34 -10
  242. package/src/orchestrator/acp-delivery.ts +68 -0
  243. package/src/orchestrator/assignments.ts +27 -0
  244. package/src/orchestrator/busy.ts +15 -0
  245. package/src/orchestrator/config.ts +41 -0
  246. package/src/orchestrator/consumer-api.ts +24 -0
  247. package/src/orchestrator/contracts.ts +71 -0
  248. package/src/orchestrator/durable-assignments.ts +111 -0
  249. package/src/orchestrator/native-delegation.ts +103 -0
  250. package/src/orchestrator/orchestrator.ts +318 -0
  251. package/src/orchestrator/permissions.ts +28 -0
  252. package/src/orchestrator/policy.ts +44 -0
  253. package/src/orchestrator/pool.ts +123 -0
  254. package/src/orchestrator/tool-descriptions.ts +11 -0
  255. package/src/permissions/acp.ts +18 -0
  256. package/src/permissions/arrival.ts +13 -0
  257. package/src/permissions/consumer-config.ts +19 -0
  258. package/src/permissions/conversation.ts +288 -0
  259. package/src/permissions/matcher.ts +87 -0
  260. package/src/permissions/outcome.ts +26 -0
  261. package/src/permissions/policy.ts +86 -0
  262. package/src/permissions/request.ts +26 -0
  263. package/src/persistence/activity-projection.ts +1 -0
  264. package/src/persistence/backend.ts +34 -1
  265. package/src/persistence/channels.ts +23 -0
  266. package/src/persistence/index.ts +4 -0
  267. package/src/persistence/protocol-method.ts +5 -0
  268. package/src/persistence/reminder-wake.ts +49 -0
  269. package/src/persistence/reminders.ts +385 -0
  270. package/src/persistence/sqlite-backend.ts +84 -6
  271. package/src/persistence/sqlite-channels.ts +65 -0
  272. package/src/persistence/sqlite-reminders.ts +85 -0
  273. package/src/persistence/sqlite-schema.ts +108 -3
  274. package/src/persistence/sqlite-worker-delivery.ts +374 -0
  275. package/src/persistence/sqlite-workers.ts +59 -0
  276. package/src/persistence/worker-delivery-contract.ts +104 -0
  277. package/src/persistence/worker-terminal-reason.ts +29 -0
  278. package/src/persistence/workers.ts +19 -0
  279. package/src/provider-notices.ts +137 -0
  280. package/src/repl/commands.ts +2 -2
  281. package/src/steering/combine.ts +3 -1
  282. package/src/steering/contracts.ts +11 -2
  283. package/src/steering/controller.ts +3 -2
  284. package/src/terminals.ts +9 -6
  285. package/src/transport/acp-transport.ts +24 -14
  286. package/src/types.ts +15 -12
  287. package/src/updates.ts +14 -2
  288. package/src/wire-log.ts +1 -1
@@ -0,0 +1,106 @@
1
+ import type { ApprovalCloseReason, ApprovalRequest } from "./config-permissions.ts";
2
+ import type { ChannelChangeResult, ChannelStatusResult, ItemStatus, StoredMessage, PendingChannelChange, ProtocolConfig, TurnStatus } from "./protocol.ts";
3
+
4
+ export interface OpenResult {
5
+ sessionId: string;
6
+ lifecycle: import("./storage.ts").SessionLifecycle;
7
+ revision: number;
8
+ channelChanges?: ChannelChangeResult[];
9
+ reminderChanges?: import("./reminders.ts").ReminderChangeResult[];
10
+ reminders?: import("./reminders.ts").Reminder[];
11
+ remindersNext?: string;
12
+ nextDueAt?: string | null;
13
+ reminderRevision?: number;
14
+ unattendedTurnGuard?: { maxConsecutiveTurns: number } | null;
15
+ }
16
+
17
+ export interface ChannelObservation {
18
+ revision: number;
19
+ sessionLifecycle: import("./storage.ts").SessionLifecycle;
20
+ channel: Omit<ChannelStatusResult, "pending" | "unresolved"> & { pendingCount: number };
21
+ approvals: ApprovalRequest[];
22
+ }
23
+
24
+ /** Ordered storage position scoped to a session and channel, distinct from message identity. */
25
+ export type MessagePosition = string;
26
+ export type ConversationMessage = (StoredMessage | {
27
+ messageId: string; channel: string; turnId: string; omitted: true;
28
+ }) & { position: MessagePosition; actor: { kind: "participant"; id: string }; itemId: string } |
29
+ ((StoredMessage | { messageId: string; channel: string; turnId: string; omitted: true }) &
30
+ { position: MessagePosition; actor: { kind: "agent"; id: string }; itemId?: never });
31
+
32
+ export type ConversationPageRequest = { channel: string; limit?: number } & (
33
+ | { cursor?: never; after?: never; throughRevision?: never }
34
+ | { cursor: string; after?: never; throughRevision?: never }
35
+ | { cursor?: never; after: MessagePosition; throughRevision: number }
36
+ );
37
+
38
+ export interface TimelineEvent {
39
+ position: string;
40
+ channel: string;
41
+ turnId: string;
42
+ actor: { kind: "participant" | "agent"; id: string };
43
+ kind: "participant_message" | "assistant_message" | "channel_notice" | "external_notice" | "tool_call" | "tool_result";
44
+ sourceChannel?: string;
45
+ externalSource?: string;
46
+ /** Stable accepted identity of an external notice. */
47
+ itemId?: string;
48
+ messageId?: string;
49
+ /** Protocol bounds encoded payload bytes before publication. */
50
+ payload?: import("./loop.ts").Message;
51
+ omitted?: true;
52
+ resultReference?: import("./tools.ts").ResultReference;
53
+ }
54
+
55
+ export interface OperatorMethods {
56
+ "session/create": { params: import("./protocol.ts").CreateParams; result: OpenResult };
57
+ "session/open": { params: LoadResultOpenParams; result: OpenResult };
58
+ "channel/observe": { params: { channel: string }; result: ChannelObservation };
59
+ "channel/reconcile": {
60
+ params: { channel: string; itemIds?: string[]; turnIds?: string[]; cursor?: string };
61
+ result: { revision: number; items: ItemStatus[]; turns: TurnStatus[]; unknownItemIds: string[]; unknownTurnIds: string[];
62
+ replies: { messageId: string; turnId: string; position: MessagePosition }[]; next?: string };
63
+ };
64
+ "channel/messages": { params: ConversationPageRequest; result: { messages: ConversationMessage[]; next?: string } };
65
+ "session/timeline": { params: { limit?: number; cursor?: string }; result: { events: TimelineEvent[]; next?: string } };
66
+ }
67
+
68
+ export interface LoadResultOpenParams {
69
+ sessionId: string;
70
+ config?: ProtocolConfig;
71
+ channelChanges?: PendingChannelChange[];
72
+ reminderChanges?: import("./reminders.ts").ReminderChange[];
73
+ tools?: import("./tools.ts").ToolCatalogInput;
74
+ }
75
+
76
+ /** Internal read side. Results are detached and each read observes one revision.
77
+ * Store adapters use the numeric bounds internally. Wire cursors are decoded
78
+ * and checked by the protocol before invoking this port. */
79
+ export interface OperatorStorageReads {
80
+ readChannel(channel: string): import("./storage.ts").StorageResult<{
81
+ channel: Omit<import("./storage.ts").StoredChannel, "participantIds">;
82
+ pendingCount: number;
83
+ activeTurn?: Omit<import("./storage.ts").StoredTurn, "itemIds">;
84
+ }>;
85
+ readTracked(channel: string, itemIds: readonly string[], turnIds: readonly number[]): import("./storage.ts").StorageResult<{
86
+ items: import("./storage.ts").StoredItem[];
87
+ turns: import("./storage.ts").StoredTurn[];
88
+ }>;
89
+ readTimeline(range: {
90
+ channel?: string;
91
+ turnIds?: readonly number[];
92
+ throughRevision: number;
93
+ exclusiveSeq?: number;
94
+ direction: "older" | "newer";
95
+ kind: "conversation" | "timeline" | "replies";
96
+ limit: number;
97
+ }): import("./storage.ts").StorageResult<{ entries: import("./storage.ts").TimelineEntry[]; more: boolean }>;
98
+ }
99
+
100
+ /** Live-only signal. Observation after reconnect contains only pending requests. */
101
+ export interface ApprovalClosedEvent {
102
+ type: "approval_closed";
103
+ turnId: string;
104
+ requestId: string;
105
+ reason: ApprovalCloseReason | "dispatched";
106
+ }
@@ -0,0 +1,13 @@
1
+ /** One completed assistant message or turn failure, including notice turns. */
2
+ export interface ChannelOutput {
3
+ channelId: string;
4
+ turnId: number;
5
+ type: "reply" | "error";
6
+ text: string;
7
+ }
8
+
9
+ /** Host-owned delivery port. Subscribers receive future events for one channel. */
10
+ export interface ChannelOutputs {
11
+ publish(output: ChannelOutput): void;
12
+ subscribe(channelId: string, listener: (output: ChannelOutput) => void): () => void;
13
+ }
@@ -0,0 +1,320 @@
1
+ import type { ReminderMethods } from "./reminders.ts";
2
+ import type { OperatorMethods } from "./operator-controls.ts";
3
+ import type { ModelExecutionMethods } from "./model-execution.ts";
4
+ import type { ChannelEvent, SessionEvent } from "./events.ts";
5
+ import type { ItemKind, ItemMilestone } from "./agent.ts";
6
+
7
+ export interface Subscription { text: "final" | "stream"; tools: "none" | "summary" | "full" }
8
+ export interface InitializeParams {
9
+ protocolVersion: number;
10
+ host: { name: string; version: string };
11
+ /** Empty, or `["functions/call"]` (decision 0021) to receive callbacks. */
12
+ callbacks: string[];
13
+ approval?: boolean;
14
+ /** Decision 0021: the handler names this connection serves. A catalog tool
15
+ * whose handler is missing here is unavailable. */
16
+ functions?: string[];
17
+ subscription: Subscription;
18
+ }
19
+ export interface ProtocolConfig {
20
+ version: 1;
21
+ limits?: { unattendedTurns: number };
22
+ system: string;
23
+ model: import("./config-permissions.ts").ManagedModel;
24
+ defaultPolicy?: string;
25
+ policies?: Record<string, import("./config-permissions.ts").ToolPolicy>;
26
+ }
27
+ export interface CreateParams {
28
+ sessionId: string;
29
+ config?: ProtocolConfig;
30
+ reminderChanges?: import("./reminders.ts").ReminderChange[];
31
+ participants: { id: string; kind: "person" | "agent" | "worker" | "host" }[];
32
+ channels: Record<string, never>;
33
+ /** Decision 0020. Applied before the new session starts. */
34
+ channelChanges?: PendingChannelChange[];
35
+ /** Decision 0021. Bound before the session starts. */
36
+ tools?: import("./tools.ts").ToolCatalogInput;
37
+ }
38
+ /** Owning host submission. policyNames is a set of user-facing names, including an explicit empty set. */
39
+ export interface NotifyParams {
40
+ channel: string;
41
+ notice: { id: string; text: string; source?: string; policyNames: string[] };
42
+ }
43
+ export interface PushParams {
44
+ channel: string;
45
+ item: { id: string; kind: "user_message"; sender: string; content: { type: "text"; text: string }[]; policy?: string | null; delivery?: "queue"; wake?: true };
46
+ }
47
+ export interface InitializeResult {
48
+ protocolVersion: 1;
49
+ harness: { version: string };
50
+ description: Description;
51
+ }
52
+
53
+ export interface Description {
54
+ reminderLimits?: import("./reminders.ts").ReminderLimits;
55
+ configOptions: unknown[]; commands: unknown[]; policies: string[];
56
+ /** Advertise only implemented guarantees: `durable`/`true` are reported by a
57
+ * server only once its acceptance commits to storage before acknowledging. */
58
+ capabilities: { experimental: true; acceptance: "memory" | "durable"; methods: string[]; events: string[]; persistence: boolean;
59
+ /** Decision 0020: `session/create` and `session/open` accept `channelChanges`
60
+ * and apply them before the session starts. Absent on older servers, which
61
+ * reject the field. */
62
+ startupChannelChanges?: true;
63
+ /** Decision 0021: tool catalogs, `functions/call` callbacks and invocation records. */
64
+ functions?: true; reminders?: true; routines?: true; unattendedTurnGuard?: true };
65
+ }
66
+
67
+ // ---- Channel changes applied at open, decision 0020.
68
+
69
+ /** The host's newest desired state for one channel, decided while the harness
70
+ * was not running. A missing field leaves the value alone; `null` clears a
71
+ * name or policy. An unknown channel is created. `changeId` is opaque to the
72
+ * harness and echoed in the result so the host can match its own version. */
73
+ export interface PendingChannelChange {
74
+ channel: string;
75
+ changeId: string;
76
+ displayName?: string | null;
77
+ policy?: string | null;
78
+ /** `open` clears the channel's own suspension (never the session's);
79
+ * `suspended` suspends it; `retired` deletes it. */
80
+ lifecycle?: "open" | "suspended" | "retired";
81
+ }
82
+ /** One per batch entry, in request order. `blocked` wrote neither name nor
83
+ * policy and left the lifecycle as it was, with one exception: `channel_busy`
84
+ * (retirement found pending input or a running or checkpointed turn) durably
85
+ * suspends the channel and keeps its work. `channel_retired`: the ID is
86
+ * retired and the entry asked for something other than retirement.
87
+ * `incompatible`: the resume would continue work the current configuration
88
+ * cannot run; the channel stays suspended. */
89
+ export interface ChannelChangeResult {
90
+ channel: string;
91
+ changeId: string;
92
+ outcome: "applied" | "blocked";
93
+ reason?: "channel_busy" | "channel_retired" | "incompatible";
94
+ }
95
+
96
+ // ---- Durable operations, decision 0013. A server lists a method in
97
+ // capabilities.methods only when it implements it.
98
+
99
+ /** Stable `error.data.code` values added by decision 0013. `item_conflict`
100
+ * already exists. A lifecycle refusal never consumes or alters accepted work. */
101
+ export type DurableErrorCode =
102
+ | "item_conflict" | "not_running" | "stopped" | "invalid_state" | "incompatible"
103
+ | "owner_conflict" | "not_found" | "already_exists" | "busy"
104
+ | "invalid_archive" | "invalid_config" | "invalid_policy" | "transfer_limit" | "serialization_error" | "storage_failure"
105
+ /** Decision 0014. The channel is suspending or suspended; a retry of accepted input still returns its recorded outcome. */
106
+ | "channel_suspended"
107
+ /** The channel ID was deleted; it is reserved for good. */
108
+ | "channel_retired"
109
+ /** Deletion refused: active or checkpointed turn, or pending input. */
110
+ | "channel_busy";
111
+
112
+ /** Wire view of an accepted input. `turnId` is present from `taken` onward and
113
+ * absent for `withdrawn`. */
114
+ export interface ItemStatus {
115
+ id: string; channel: string; kind: ItemKind; sender: string;
116
+ milestone: ItemMilestone; turnId?: string;
117
+ policy?: import("./config-permissions.ts").ItemPolicy;
118
+ externalSource?: string;
119
+ }
120
+ export interface TurnStatus {
121
+ turnId: string; channel: string; items: string[];
122
+ state: "running" | "suspended" | "completed" | "failed" | "interrupted";
123
+ reason?: string;
124
+ /** Recorded calls with no recorded result; never replayed by the harness. */
125
+ uncertainCalls?: string[];
126
+ }
127
+ /** `idle`, `suspended` and unresolved interrupted work are distinguishable:
128
+ * see SessionStatus in the session contract for the exact derivation. */
129
+ export interface StatusResult {
130
+ sessionId: string; revision: number;
131
+ lifecycle: "running" | "suspending" | "suspended";
132
+ execution: "idle" | "working" | "suspending" | "suspended" | "stopped" | "incompatible";
133
+ channels: ChannelStatusResult[];
134
+ }
135
+ /** Decision 0014: channel lifecycle, turn status and pending input are
136
+ * independent. `pending` excludes withdrawn items. `waitingForResume` is true
137
+ * when pending items or a checkpoint exist that cannot run until a resume
138
+ * (channel or session); such work never makes `execution` `working`. A server
139
+ * from before decision 0014 omits `lifecycle` and `waitingForResume`: read as
140
+ * `open` and false. */
141
+ export interface ChannelStatusResult {
142
+ channel: string; displayName?: string; policy?: string;
143
+ lifecycle: "open" | "suspending" | "suspended" | "retired";
144
+ /** `phase` (decision 0021) says what a running turn is doing and since when. */
145
+ activeTurn?: { turnId: string; state: "running" | "suspended"; phase?: import("./tools.ts").TurnPhase };
146
+ pending: string[]; waitingForResume: boolean; unresolved?: TurnStatus;
147
+ }
148
+ export type StoredMessage = { messageId: string; channel: string; turnId: string } &
149
+ ({ parts: { type: "text"; text: string }[]; reference?: never } | { parts?: never; reference: true });
150
+
151
+ /** Internal view retained for development and test projections. The wire uses OpenResult and focused reads. */
152
+ export interface LoadResult {
153
+ status: StatusResult;
154
+ turns: TurnStatus[];
155
+ items: ItemStatus[];
156
+ messages: StoredMessage[];
157
+ nextMessage?: string;
158
+ /** Decision 0020: results of the batch this connection's open applied.
159
+ * Present when a batch was sent with this open or recorded by it. */
160
+ channelChanges?: ChannelChangeResult[];
161
+ }
162
+
163
+ /** Archive bytes move by path when host and harness share a filesystem, or by
164
+ * a bounded transfer otherwise. Data is base64 of at most `chunkBytes` raw
165
+ * bytes so every frame stays under the 1 MiB stdio bound. One transfer may be
166
+ * open per connection. A transfer's temporary file is deleted when it is
167
+ * closed, consumed by import, idle past `idleMs`, or its connection ends.
168
+ * An archive larger than `maxBytes` fails `transfer/open` and `session/export`
169
+ * (path or transfer) with `transfer_limit`, leaving no partial or temporary file. */
170
+ export interface TransferLimits { chunkBytes: 524288; maxBytes: 268435456; idleMs: 60000 }
171
+ export type ArchiveLocation = { type: "path"; path: string } | { type: "transfer" };
172
+
173
+ export interface DurableMethods extends ModelExecutionMethods, ReminderMethods, Omit<OperatorMethods, "session/create"> {
174
+ /** Open an existing session with runtime configuration. Returns the load
175
+ * view; a second load on the same endpoint returns a fresh view only.
176
+ * `channelChanges` (decision 0020) is validated as a whole, then applied
177
+ * after recovery and before any pending or recovered work becomes eligible;
178
+ * the view shows the resulting channel state. An invalid batch fails the
179
+ * request with nothing changed and the session not opened. A repeated load
180
+ * with the same batch, or none, reports the recorded results and applies
181
+ * nothing; a different batch fails `invalid_state`. */
182
+ // ---- Tools, decision 0021.
183
+ /** Every catalog entry and built-in with its availability. */
184
+ "session/tools": { params: Record<string, never>; result: { tools: import("./tools.ts").ToolAvailability[] } };
185
+ /** Revocable entries only (`invalid_state` otherwise; unknown name `not_found`).
186
+ * Durable. Takes effect at the next inference and at any dispatch not yet made:
187
+ * a pending approval for the tool is closed and its call skipped. */
188
+ "tool/revoke": { params: { name: string }; result: { tool: import("./tools.ts").ToolAvailability } };
189
+ "tool/restore": { params: { name: string }; result: { tool: import("./tools.ts").ToolAvailability } };
190
+ /** Runtime entries only, from the catalog bound at open. In memory. */
191
+ "tool/enable": { params: { name: string }; result: { tool: import("./tools.ts").ToolAvailability } };
192
+ "tool/remove": { params: { name: string }; result: { tool: import("./tools.ts").ToolAvailability } };
193
+ /** One call by invocation ID, from committed records. `not_found` if unknown. */
194
+ "session/tool-invocation": { params: { invocationId: string }; result: { invocation: import("./tools.ts").ToolInvocation } };
195
+ /** The calls of one turn, in request order. */
196
+ "session/tool-invocations": { params: { turn: string }; result: { invocations: import("./tools.ts").ToolInvocation[] } };
197
+ /** Only records committed at or before `revision`, after message `after`.
198
+ * `not_found` for a revision the session has not reached. */
199
+ "session/status": { params: Record<string, never>; result: StatusResult };
200
+ /** Responds after `suspended` commits. Repeating it is harmless. Fails
201
+ * `stopped` if the session is stopped before suspension commits. */
202
+ "session/suspend": { params: Record<string, never>; result: StatusResult };
203
+ /** Explicit; fails `incompatible` without consuming input or checkpoints. */
204
+ "session/resume": { params: Record<string, never>; result: StatusResult };
205
+ /** Immediate stop; running turns and checkpoints from an unfinished session
206
+ * suspension are reported interrupted. A checkpoint committed by an individual
207
+ * channel suspension is kept, and a still-suspending channel returns to
208
+ * `open`. Stdin EOF does the same. */
209
+ "session/stop": { params: Record<string, never>; result: StatusResult };
210
+ /** Allowed when suspended, or when running with no running turn, nothing
211
+ * pending, no checkpointed turn and no suspending channel; else `busy`. A
212
+ * suspended channel with neither checkpoint nor backlog does not block. For
213
+ * `transfer` the result names a readable transfer. */
214
+ "session/export": { params: { to: ArchiveLocation }; result: { bytes: number; sha256: string; transferId?: string } };
215
+ /** Validate fully, then publish atomically into a fresh home. Does not load,
216
+ * start or resume the copy. `from.transfer` names a completed upload. */
217
+ "session/import": { params: { from: { type: "path"; path: string } | { type: "transfer"; transferId: string }; sessionId?: string };
218
+ result: { sessionId: string; lifecycle: "running" | "suspended"; revision: number } };
219
+ // ---- Channel controls, decision 0014. Each is atomic, independent of the
220
+ // session lifecycle, and fails with the stable codes in DurableErrorCode.
221
+ /** Explicit create; starts nothing. Repeating the same request returns
222
+ * `created: false`; a different name for an existing channel is
223
+ * `already_exists`; a retired ID is `channel_retired`. */
224
+ "channel/create": { params: { channel: string; displayName?: string; policy?: string }; result: { channel: ChannelStatusResult; created: boolean } };
225
+ /** Display name only; `null` clears it. */
226
+ "channel/edit": { params: { channel: string; displayName: string | null; policy?: string | null }; result: { channel: ChannelStatusResult } };
227
+ /** Responds after the channel's `suspended` commits (checkpoint, completed
228
+ * turn or interrupted turn). Repeating it is harmless. Fails `stopped` if the
229
+ * session stops first. Meanwhile `channel/push` fails `channel_suspended`. */
230
+ "channel/suspend": { params: { channel: string }; result: { channel: ChannelStatusResult } };
231
+ /** Clears the channel suspension; work runs only when the session is
232
+ * `running`. Fails `incompatible` without touching the checkpoint. */
233
+ "channel/resume": { params: { channel: string }; result: { channel: ChannelStatusResult } };
234
+ /** Retires the ID. `channel_busy` while a turn is active or checkpointed or
235
+ * input is pending. */
236
+ "channel/delete": { params: { channel: string }; result: { channel: ChannelStatusResult } };
237
+ /** `taken` is the other side of the race with take and names the turn.
238
+ * Messages and notices alike. */
239
+ "channel/withdraw": { params: { channel: string; item: string };
240
+ result: { outcome: "withdrawn" | "taken"; item: ItemStatus; repeated?: boolean } };
241
+ /** Targets one turn. `interrupted: false` for a checkpointed or ended turn,
242
+ * which is left as it is; `turn` is its current status. */
243
+ "channel/interrupt": { params: { channel: string; turn: string; reason?: string };
244
+ result: { interrupted: boolean; turn: TurnStatus } };
245
+ // `reason` omitted: the stored reason is exactly "interrupted by request".
246
+ "transfer/open": { params: { bytes: number; sha256: string }; result: { transferId: string; limits: TransferLimits } };
247
+ /** Offsets are sequential; a gap, overrun or oversize chunk is `transfer_limit`. */
248
+ "transfer/write": { params: { transferId: string; offset: number; data: string }; result: { received: number } };
249
+ "transfer/read": { params: { transferId: string; offset: number }; result: { data: string; eof: boolean } };
250
+ "transfer/close": { params: { transferId: string }; result: Record<string, never> };
251
+ }
252
+ /** Sent after its lifecycle commit, on the same ordered stream as channel
253
+ * events. Delivered through `subscribeSession` on the transport and endpoint. */
254
+ export interface RpcSessionNotification { jsonrpc: "2.0"; method: "session/event"; params: SessionEvent | import("./reminders.ts").ReminderSessionEvent }
255
+ export interface Methods {
256
+ initialize: { params: InitializeParams; result: InitializeResult };
257
+ /** Validate without opening a session or starting execution. */
258
+ "config/validate": { params: { config: unknown }; result: { valid: true } };
259
+ "approval/respond": { params: { requestId: string; decision: import("./config-permissions.ts").ApprovalAnswer }; result: { accepted: true } };
260
+ /** `channelChanges` (decision 0020) follows the same rules as on load. */
261
+ "session/create": OperatorMethods["session/create"];
262
+ /** With durable acceptance the response is sent only after the inbox commit
263
+ * and includes `item` (Received, or the original item's current state for a
264
+ * retry). It never waits for or reports a reply. There is one delivery
265
+ * behavior: `delivery` and `wake` are accepted for compatibility and ignored. */
266
+ "channel/push": { params: PushParams; result: { accepted: true; item?: ItemStatus; duplicate?: boolean } };
267
+ "channel/notify": { params: NotifyParams; result: { accepted: true; item: ItemStatus; duplicate: boolean } };
268
+ "session/idle": { params: Record<string, never>; result: { idle: boolean } };
269
+ }
270
+ export interface RpcRequest { jsonrpc: "2.0"; id: number; method: string; params: unknown }
271
+ export type RpcResponse = { jsonrpc: "2.0"; id: number; result: unknown } |
272
+ { jsonrpc: "2.0"; id: number | null; error: { code: number; message: string; data: { code: string } } };
273
+ export interface RpcNotification { jsonrpc: "2.0"; method: "channel/event"; params: ChannelEvent }
274
+ // ---- Requests from the harness to the host, decision 0021. IDs are numeric,
275
+ // per connection, and separate from the IDs of host requests: direction tells
276
+ // them apart. A response for a request that is no longer outstanding is ignored.
277
+ export type RpcCallbackRequest =
278
+ | { jsonrpc: "2.0"; id: number; method: "functions/call"; params: import("./tools.ts").FunctionCall }
279
+ | { jsonrpc: "2.0"; id: number; method: "results/read"; params: import("./tools.ts").ResultRead };
280
+ /** Ends the harness's wait for `invocationId`; the handler may stop. No reply. */
281
+ export interface RpcCallbackCancel { jsonrpc: "2.0"; method: "functions/cancel"; params: { invocationId: string; reason: string } }
282
+ export type RpcCallbackResponse = { jsonrpc: "2.0"; id: number; result: unknown }
283
+ | { jsonrpc: "2.0"; id: number; error: { code: number; message: string; data: { code: string } } };
284
+ /** Transport carries envelopes; client owns correlation and request timeouts. */
285
+ export interface ClientTransport {
286
+ send(request: RpcRequest): void;
287
+ subscribe(listener: (message: RpcResponse | RpcNotification) => void): () => void;
288
+ /** Decision 0013: required of every transport once `session/event` is listed
289
+ * in capabilities. A transport must route `session/event` here and never to
290
+ * `subscribe`. Relative order with channel events and responses is the wire
291
+ * order. Optional only until the transports implement it. */
292
+ subscribeSession?(listener: (notification: RpcSessionNotification) => void): () => void;
293
+ /** Decision 0021. Requests and cancellations from the harness, in wire order
294
+ * with events. Required of a transport once `functions` is advertised. */
295
+ subscribeCallbacks?(listener: (message: RpcCallbackRequest | RpcCallbackCancel) => void): () => void;
296
+ /** Answer a callback request by its ID. */
297
+ respond?(response: RpcCallbackResponse): void;
298
+ onClose(listener: (error?: Error) => void): () => void;
299
+ close(): void;
300
+ }
301
+
302
+ /** Host owns process creation and termination; transport owns protocol IO only. */
303
+ export interface StdioConnection {
304
+ readable: ReadableStream<Uint8Array>;
305
+ write(bytes: Uint8Array): Promise<void>;
306
+ end(): void | Promise<void>;
307
+ exited?: Promise<number>;
308
+ }
309
+ export interface ProtocolEndpoint {
310
+ /** Close this connection's outstanding consumer approvals. */
311
+ disconnect?(): void;
312
+ request(request: RpcRequest): Promise<RpcResponse>;
313
+ subscribe(listener: (notification: RpcNotification) => void): () => void;
314
+ /** Lifecycle notifications, published after their commit. See ClientTransport. */
315
+ subscribeSession?(listener: (notification: RpcSessionNotification) => void): () => void;
316
+ /** Decision 0021: callback requests and cancellations for this connection's host. */
317
+ subscribeCallbacks?(listener: (message: RpcCallbackRequest | RpcCallbackCancel) => void): () => void;
318
+ /** The host's answer to a callback request. Unknown or closed IDs are ignored. */
319
+ respond?(response: RpcCallbackResponse): void;
320
+ }
@@ -0,0 +1,134 @@
1
+ /** Decision 0032, approved wire pin c8facc2. */
2
+ export type RoutineEnd = { count: number; until?: never } | { until: string; count?: never }
3
+ | { count?: never; until?: never };
4
+ export type IntervalRoutineSchedule = { every: number; startAt?: string; at?: never; cron?: never } & RoutineEnd;
5
+ export type CalendarRoutineSchedule = { cron: string; timezone: string; at?: never; every?: never } & RoutineEnd;
6
+ export type RoutineSchedule = IntervalRoutineSchedule | CalendarRoutineSchedule;
7
+ export interface RoutineDeliveryOptions {
8
+ missedRuns?: "coalesce" | "skip" | "each";
9
+ overlap?: "skip" | "queue";
10
+ }
11
+ export interface RoutineTimezoneMigration {
12
+ fromVersion: string;
13
+ targetVersion: string;
14
+ cause: "invalid_schedule" | "proof_budget";
15
+ }
16
+ export type ReminderSchedule = OneOffSchedule | RoutineSchedule;
17
+
18
+ /** Decision 0031. All persisted instants are canonical millisecond UTC ISO strings. */
19
+ export interface OneOffSchedule { at: string }
20
+ export type AgentReminderSchedule = OneOffSchedule | { in: string };
21
+ export type ReminderState = "active" | "paused" | "blocked" | "done" | "cancelled" | "expired";
22
+ export type ReminderBlockReason = "invalid_policy" | "channel_missing" | "channel_retired"
23
+ | "invalid_schedule" | "limit_exceeded" | "conflict" | "not_found" | "stale" | "invalid_state" | "unattended_guard_required";
24
+
25
+ interface ReminderFields {
26
+ id: string;
27
+ channel: string;
28
+ createdBy: "agent" | "host";
29
+ creatorId?: string;
30
+ policyNames: string[];
31
+ text: string;
32
+ state: ReminderState;
33
+ nextRunAt: string | null;
34
+ acceptedAt: string;
35
+ expiresAfter: number | null;
36
+ expiresAt: string | null;
37
+ lastRunAt?: string;
38
+ lastOccurrenceId?: string;
39
+ noticeId?: string;
40
+ blockedReason?: ReminderBlockReason;
41
+ }
42
+
43
+ /** Returned interval routines always carry their resolved startAt. */
44
+ export type OneOffReminder = ReminderFields & { schedule: OneOffSchedule; missedRuns?: never; overlap?: never;
45
+ remainingCount?: never; timezoneVersion?: never; timezoneMigration?: never };
46
+ export type Reminder = OneOffReminder | (ReminderFields & Required<RoutineDeliveryOptions> & { remainingCount?: number } & (
47
+ | { schedule: IntervalRoutineSchedule & { startAt: string }; timezoneVersion?: never; timezoneMigration?: never }
48
+ | { schedule: CalendarRoutineSchedule; timezoneVersion: string; timezoneMigration?: RoutineTimezoneMigration }
49
+ ));
50
+
51
+ type ReminderEdit = RoutineDeliveryOptions & {
52
+ text?: string;
53
+ state?: "active" | "paused";
54
+ expiresAfter?: number | null;
55
+ } & ({ schedule: ReminderSchedule; acceptedAt: string } | { schedule?: never; acceptedAt?: never });
56
+
57
+ type ChangeIdentity = { reminderId: string; changeId: number };
58
+
59
+ /** Versioned host commands. Agent mutations derive their ownership from the turn. */
60
+ export type ReminderChange = ChangeIdentity & (
61
+ | { op: "create"; payload: RoutineDeliveryOptions & { channel: string; schedule: ReminderSchedule; text: string;
62
+ acceptedAt: string; policyNames?: string[]; expiresAfter?: number | null } }
63
+ | { op: "update"; payload: ReminderEdit }
64
+ | { op: "cancel"; payload: Record<string, never> }
65
+ );
66
+
67
+ /** Internal 0031 parser and storage view until recurrence is enabled. */
68
+ export type OneOffReminderChange = (ChangeIdentity & (
69
+ | { op: "create"; payload: Omit<Extract<ReminderChange, { op: "create" }>["payload"], "schedule"> & { schedule: OneOffSchedule } }
70
+ | { op: "update"; payload: Omit<ReminderEdit, "schedule" | "acceptedAt"> &
71
+ ({ schedule: OneOffSchedule; acceptedAt: string } | { schedule?: never; acceptedAt?: never }) }
72
+ | { op: "cancel"; payload: Record<string, never> }
73
+ ));
74
+ export type OneOffReminderChangeResult = Exclude<ReminderChangeResult, { outcome: "applied" }>
75
+ | (ChangeIdentity & { outcome: "applied"; reminder: OneOffReminder; alreadyQueued?: boolean });
76
+
77
+ export type ReminderChangeResult = ChangeIdentity & (
78
+ | { outcome: "applied"; reminder: Reminder; alreadyQueued?: boolean }
79
+ | { outcome: "blocked"; reason: ReminderBlockReason }
80
+ );
81
+
82
+ export interface ReminderListParams { channel?: string; after?: string; limit?: number }
83
+ export interface ReminderList { reminders: Reminder[]; next?: string }
84
+ export interface ReminderWake { nextDueAt: string | null; reminderRevision: number }
85
+ export type ReminderOpen = {
86
+ reminderChanges: ReminderChangeResult[];
87
+ reminders: Reminder[];
88
+ remindersNext?: string;
89
+ } & (ReminderWake | { nextDueAt?: never; reminderRevision?: never });
90
+
91
+ export interface ReminderLimits {
92
+ minLeadMs: number;
93
+ minIntervalMs: number;
94
+ maxActiveRoutinesPerChannel: number;
95
+ maxRoutineCatchUp?: number;
96
+ minExpiryGraceMs: number;
97
+ maxExpiryGraceMs: number;
98
+ expiryMultiplier: number;
99
+ }
100
+
101
+ export type ReminderSessionEvent = { type: "reminders_due"; nextDueAt: string | null; revision: number };
102
+ export type ReminderChannelEvent =
103
+ | { type: "routine_disposition"; reminderId: string; firstScheduledAt: string; lastScheduledAt: string; count: number;
104
+ reason: "missed" | "catch_up_limit" | "overlap" | "expired" | "coalesced" }
105
+ | ({ type: "routine_migration_blocked"; reminderId: string } & RoutineTimezoneMigration)
106
+ | { type: "reminder_changed"; reminder: Reminder }
107
+ | { type: "reminder_fired"; reminderId: string; occurrenceId: string; scheduledAt: string; firedAt: string; noticeId: string }
108
+ | { type: "reminder_cancelled"; reminderId: string; by: "host" | "agent" | "channel_retired" }
109
+ | { type: "reminder_expired"; reminderId: string; occurrenceId: string; scheduledAt: string; expiredAt: string };
110
+
111
+ export interface ConditionalStopParams { ifIdle: true; unlessDueWithinMs?: number }
112
+ export type ConditionalStopResult = { stopped: true } | { stopped: false; reason: "busy" | "next_due_soon" };
113
+
114
+ export interface ReminderMethods {
115
+ "reminder/change": { params: ReminderChange; result: ReminderChangeResult };
116
+ "reminder/get": { params: { id: string }; result: { reminder: Reminder } };
117
+ "reminder/list": { params: ReminderListParams; result: ReminderList };
118
+ }
119
+
120
+ /** Wall time drives eligibility. A timer only requests an eligibility recheck. */
121
+ export interface ReminderClock {
122
+ now(): number;
123
+ setTimer(callback: () => void, delayMs: number): () => void;
124
+ }
125
+
126
+ /** Portable reminder state in logical archive 6. High water is derived from retained receipts. */
127
+ export interface ReminderArchiveState {
128
+ dispositions?: Array<Extract<ReminderChannelEvent, { type: "routine_disposition" | "routine_migration_blocked" }>>;
129
+ guard?: { limit: number; counters: Array<{ channel: string; spent: number }> };
130
+ rows: Array<{ sequence: number; reminder: Reminder; processedThrough?: number; episodeCutoff?: number; coalescedPending?: number; original?: string; defaultedExpiry: boolean }>;
131
+ receipts: Array<{ fingerprint: string; result: ReminderChangeResult }>;
132
+ listingRevision: number;
133
+ wake: ReminderWake;
134
+ }
@@ -0,0 +1,20 @@
1
+ /** Decision 0032. Interval durations are integer milliseconds. */
2
+ export type RoutineEnd = { count: number; until?: never } | { until: string; count?: never }
3
+ | { until?: never; count?: never };
4
+ export type IntervalRoutineSchedule = { every: number; startAt?: string } & RoutineEnd;
5
+ export type CalendarRoutineSchedule = { cron: string; timezone: string } & RoutineEnd;
6
+ export type RoutineSchedule = IntervalRoutineSchedule | CalendarRoutineSchedule;
7
+
8
+ export interface RoutineDeliveryOptions {
9
+ missedRuns?: "coalesce" | "skip" | "each";
10
+ overlap?: "skip" | "queue";
11
+ }
12
+
13
+ /** Rank and selection over concrete UTC instants, after applying the
14
+ * schedule's anchor and end. An ordinal is zero-based. A rank is inclusive. */
15
+ export interface RoutineCalendar {
16
+ at(ordinal: number): number | undefined;
17
+ rank(through: number): number;
18
+ /** Successor from the same schedule, ignoring count and until. */
19
+ nextCalendarMatch(instant: number): number | undefined;
20
+ }
@@ -0,0 +1,42 @@
1
+ /** Version and human-readable label for the first JSONL record. */
2
+ export interface ScenarioHeader { type: "scenario"; version: 1; name: string }
3
+
4
+ /** A delay relative to the preceding chunk, or to the initial delay for the
5
+ * first chunk. The final text must equal the concatenated chunks. */
6
+ export interface ScenarioChunk { afterMs: number; text: string }
7
+
8
+ export interface ScenarioCall { id: string; name: string; arguments: Record<string, unknown> }
9
+
10
+ /** One durable script position and one provider-neutral attempt. */
11
+ export type ScenarioModelRecord = {
12
+ type: "model";
13
+ channelId?: string;
14
+ delayMs?: number;
15
+ chunks?: ScenarioChunk[];
16
+ usage?: import("./model-execution.ts").ModelUsage;
17
+ } & (
18
+ | { content: string | null; calls?: ScenarioCall[]; failure?: never; wait?: never }
19
+ | { content?: never; calls?: never; failure: {
20
+ kind: Extract<import("./model-execution.ts").ModelAttemptEvent, { type: "failure" }>["kind"];
21
+ message: string;
22
+ }; wait?: never }
23
+ | { content?: never; calls?: never; failure?: never; wait: "cancel" }
24
+ );
25
+
26
+ /** A scheduled send's stable identity and its offset on the monotonic run clock. */
27
+ export interface ScenarioSend {
28
+ type: "send"; atMs: number; channelId: string; participantId: string; inputId: string; text: string;
29
+ }
30
+
31
+ export type ScenarioRecord = ScenarioHeader | ScenarioModelRecord | ScenarioSend;
32
+
33
+ /** Validated local script. Each open shares the same immutable sequences.
34
+ * Position belongs to the requesting channel, even for a default sequence. */
35
+ export interface LoadedScenario {
36
+ readonly name: string;
37
+ readonly modelDigest: string;
38
+ readonly fileDigest: string;
39
+ readonly defaultModels: readonly ScenarioModelRecord[];
40
+ readonly channelModels: ReadonlyMap<string, readonly ScenarioModelRecord[]>;
41
+ readonly sends: readonly ScenarioSend[];
42
+ }
@@ -0,0 +1,20 @@
1
+ /** Portable configuration understood by the scripted protocol server. The
2
+ * script is a destination-side file reference, retained verbatim; it is not
3
+ * embedded or required to exist during import. */
4
+ export interface PortableSessionConfig {
5
+ version: 1;
6
+ limits?: { unattendedTurns: number };
7
+ system: string;
8
+ model: import("./config-permissions.ts").ManagedModel;
9
+ /** Present on session files produced after decision 0016. */
10
+ defaultPolicy?: string;
11
+ policies?: Record<string, import("./config-permissions.ts").ToolPolicy>;
12
+ }
13
+
14
+ /** File version 1 CBOR payload. `archive` is a supported logical archive;
15
+ * defined here generically so this contract module imports nothing. Both fields
16
+ * are validated before atomic publication (decision 0015). */
17
+ export interface SessionFilePayload<Archive> {
18
+ archive: Archive;
19
+ config: PortableSessionConfig;
20
+ }