@qlairoslabs/acp-client 0.13.0-alpha.1 → 0.13.2-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 (343) hide show
  1. package/CONSUMER_GUIDE.md +181 -8
  2. package/MIGRATION-0.12-to-0.13.md +20 -7
  3. package/package.json +13 -2
  4. package/src/agent/config.ts +2 -0
  5. package/src/agent/conversation-manager.ts +1 -0
  6. package/src/agent/native-operations.ts +40 -0
  7. package/src/agent-session-config.ts +2 -0
  8. package/src/agent-session.ts +12 -2
  9. package/src/agent.ts +100 -2
  10. package/src/client.ts +5 -3
  11. package/src/controller-connection.ts +1 -0
  12. package/src/controller.ts +2 -0
  13. package/src/index.ts +3 -0
  14. package/src/launcher.ts +2 -0
  15. package/src/native/approvals.ts +20 -3
  16. package/src/native/capabilities.ts +2 -2
  17. package/src/native/connection.ts +1 -1
  18. package/src/native/controller.ts +5 -3
  19. package/src/native/host-config.ts +2 -0
  20. package/src/native/host.ts +83 -4
  21. package/src/native/mcp.ts +47 -0
  22. package/src/native/recovery.ts +8 -7
  23. package/src/native/reminders/routine-guard.ts +4 -3
  24. package/src/native/reminders/routine-wire.ts +1 -1
  25. package/src/native-harness/README.md +58 -1
  26. package/src/native-harness/package.json +4 -0
  27. package/src/native-harness/scripts/build-routine-zones.py +47 -0
  28. package/src/native-harness/src/capabilities/attachments/admission.ts +42 -0
  29. package/src/native-harness/src/capabilities/attachments/image-validation.ts +98 -0
  30. package/src/native-harness/src/capabilities/attachments/input.ts +1 -0
  31. package/src/native-harness/src/capabilities/attachments/read.ts +76 -0
  32. package/src/native-harness/src/capabilities/attachments/recovery.ts +26 -0
  33. package/src/native-harness/src/capabilities/attachments/selection.ts +37 -0
  34. package/src/native-harness/src/capabilities/attachments/service.ts +75 -0
  35. package/src/native-harness/src/capabilities/attachments/upload.ts +164 -0
  36. package/src/native-harness/src/capabilities/attachments/vision.ts +45 -0
  37. package/src/native-harness/src/capabilities/context/build.ts +5 -0
  38. package/src/native-harness/src/capabilities/context/session.ts +2 -1
  39. package/src/native-harness/src/capabilities/model/openrouter-stream.ts +80 -17
  40. package/src/native-harness/src/capabilities/model/runner.ts +6 -3
  41. package/src/native-harness/src/capabilities/reminders/cron-calendar.ts +50 -0
  42. package/src/native-harness/src/capabilities/reminders/cron-fields.ts +46 -0
  43. package/src/native-harness/src/capabilities/reminders/cron-proof.ts +32 -0
  44. package/src/native-harness/src/capabilities/reminders/cron-zone.ts +53 -0
  45. package/src/native-harness/src/capabilities/reminders/iana-zones.json.gz +0 -0
  46. package/src/native-harness/src/capabilities/reminders/iana-zones.ts +34 -0
  47. package/src/native-harness/src/capabilities/reminders/interval.ts +30 -0
  48. package/src/native-harness/src/capabilities/reminders/routine-advance.ts +47 -0
  49. package/src/native-harness/src/capabilities/reminders/routine-backlog.ts +47 -0
  50. package/src/native-harness/src/capabilities/reminders/routine-expiry.ts +15 -0
  51. package/src/native-harness/src/capabilities/reminders/routine-occurrence.ts +65 -0
  52. package/src/native-harness/src/capabilities/reminders/routine-schedule.ts +70 -0
  53. package/src/native-harness/src/capabilities/reminders/unattended.ts +8 -0
  54. package/src/native-harness/src/capabilities/tools/mcp/client.ts +97 -0
  55. package/src/native-harness/src/capabilities/tools/mcp/http.ts +183 -0
  56. package/src/native-harness/src/capabilities/tools/mcp/registry.ts +62 -0
  57. package/src/native-harness/src/capabilities/tools/mcp/result.ts +33 -0
  58. package/src/native-harness/src/capabilities/tools/mcp/schema.ts +77 -0
  59. package/src/native-harness/src/capabilities/tools/mcp/secrets.ts +28 -0
  60. package/src/native-harness/src/capabilities/tools/mcp/stdio.ts +105 -0
  61. package/src/native-harness/src/capabilities/tools/reminders/index.ts +27 -5
  62. package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +4 -1
  63. package/src/native-harness/src/capabilities/tools/web/config.ts +1 -0
  64. package/src/native-harness/src/capabilities/tools/web/definitions.ts +18 -0
  65. package/src/native-harness/src/capabilities/tools/web/direct-address.ts +56 -0
  66. package/src/native-harness/src/capabilities/tools/web/direct-transport.ts +235 -0
  67. package/src/native-harness/src/capabilities/tools/web/direct.ts +149 -0
  68. package/src/native-harness/src/capabilities/tools/web/exa-transport.ts +41 -0
  69. package/src/native-harness/src/capabilities/tools/web/exa.ts +71 -0
  70. package/src/native-harness/src/capabilities/tools/web/preview.ts +44 -0
  71. package/src/native-harness/src/capabilities/tools/web/registry.ts +47 -0
  72. package/src/native-harness/src/capabilities/tools/web/usage.ts +1 -0
  73. package/src/native-harness/src/contracts/agent.ts +3 -1
  74. package/src/native-harness/src/contracts/attachments.ts +62 -0
  75. package/src/native-harness/src/contracts/config-permissions.ts +14 -3
  76. package/src/native-harness/src/contracts/context.ts +1 -1
  77. package/src/native-harness/src/contracts/events.ts +2 -2
  78. package/src/native-harness/src/contracts/loop.ts +3 -3
  79. package/src/native-harness/src/contracts/mcp.ts +22 -0
  80. package/src/native-harness/src/contracts/model-execution.ts +2 -1
  81. package/src/native-harness/src/contracts/operator-controls.ts +8 -1
  82. package/src/native-harness/src/contracts/protocol.ts +21 -5
  83. package/src/native-harness/src/contracts/reminders.ts +4 -2
  84. package/src/native-harness/src/contracts/routines.ts +20 -0
  85. package/src/native-harness/src/contracts/session-file.ts +2 -0
  86. package/src/native-harness/src/contracts/session.ts +8 -3
  87. package/src/native-harness/src/contracts/storage.ts +32 -13
  88. package/src/native-harness/src/contracts/tools.ts +2 -0
  89. package/src/native-harness/src/contracts/web.ts +16 -0
  90. package/src/native-harness/src/governance/permissions/gate.ts +9 -2
  91. package/src/native-harness/src/governance/policy/resolve.ts +6 -1
  92. package/src/native-harness/src/index.ts +48 -12
  93. package/src/native-harness/src/interfaces/cli/development.ts +108 -53
  94. package/src/native-harness/src/interfaces/cli/serve.ts +2 -2
  95. package/src/native-harness/src/interfaces/cli/start.ts +22 -13
  96. package/src/native-harness/src/interfaces/client.ts +8 -2
  97. package/src/native-harness/src/interfaces/inspector/index.html +7 -1
  98. package/src/native-harness/src/interfaces/inspector/state.ts +6 -2
  99. package/src/native-harness/src/interfaces/protocol/load.ts +3 -1
  100. package/src/native-harness/src/interfaces/protocol/local.ts +13 -4
  101. package/src/native-harness/src/interfaces/protocol/operator.ts +8 -2
  102. package/src/native-harness/src/interfaces/protocol/server.ts +102 -36
  103. package/src/native-harness/src/interfaces/protocol/stdio-client.ts +8 -0
  104. package/src/native-harness/src/interfaces/web-chat/index.html +65 -12
  105. package/src/native-harness/src/interfaces/web-chat/server.ts +30 -3
  106. package/src/native-harness/src/kernel/channels.ts +27 -15
  107. package/src/native-harness/src/kernel/loop.ts +1 -1
  108. package/src/native-harness/src/runtime/config/inference-key.ts +7 -0
  109. package/src/native-harness/src/runtime/config/managed.ts +1 -1
  110. package/src/native-harness/src/runtime/config/paths.ts +8 -1
  111. package/src/native-harness/src/runtime/execution/mcp-stdio.ts +31 -0
  112. package/src/native-harness/src/runtime/reminder-validation.ts +31 -10
  113. package/src/native-harness/src/runtime/reminders.ts +2 -2
  114. package/src/native-harness/src/state/storage/archive.ts +113 -12
  115. package/src/native-harness/src/state/storage/attachment-files.ts +58 -0
  116. package/src/native-harness/src/state/storage/attachment-import.ts +106 -0
  117. package/src/native-harness/src/state/storage/attachment-tables.ts +123 -0
  118. package/src/native-harness/src/state/storage/engine.ts +396 -45
  119. package/src/native-harness/src/state/storage/inference.ts +30 -2
  120. package/src/native-harness/src/state/storage/memory-attachments.ts +56 -0
  121. package/src/native-harness/src/state/storage/memory-reminders.ts +31 -6
  122. package/src/native-harness/src/state/storage/memory.ts +32 -4
  123. package/src/native-harness/src/state/storage/reminder-archive.ts +53 -12
  124. package/src/native-harness/src/state/storage/reminder-change.ts +60 -14
  125. package/src/native-harness/src/state/storage/reminder-tables.ts +11 -3
  126. package/src/native-harness/src/state/storage/routine-row.ts +25 -0
  127. package/src/native-harness/src/state/storage/session-file.ts +22 -9
  128. package/src/native-harness/src/state/storage/sqlite-reminders.ts +48 -8
  129. package/src/native-harness/src/state/storage/sqlite.ts +59 -11
  130. package/src/native-harness/src/state/storage/web-tables.ts +47 -0
  131. package/src/native-harness/src/testing.ts +151 -56
  132. package/src/native-harness/src/util/attachment-input.ts +42 -0
  133. package/src/native-harness/src/util/config.ts +64 -9
  134. package/src/native-harness/src/util/intake.ts +7 -0
  135. package/src/native-harness/src/util/mcp-config.ts +102 -0
  136. package/src/native-harness/src/util/web-config.ts +34 -0
  137. package/src/native-harness/src/util/web-usage.ts +33 -0
  138. package/src/orchestrator/permissions.ts +6 -3
  139. package/src/permissions/conversation.ts +13 -5
  140. package/src/permissions/matcher.ts +2 -0
  141. package/src/permissions/outcome.ts +12 -1
  142. package/src/permissions/policy.ts +13 -8
  143. package/src/steering/combine.ts +1 -0
  144. package/src/steering/contracts.ts +3 -0
  145. package/src/terminals.ts +9 -6
  146. package/src/native/reminders/reminders.test.ts +0 -553
  147. package/src/native/reminders/routine-config.typecheck.ts +0 -13
  148. package/src/native/reminders/wire.typecheck.ts +0 -13
  149. package/src/native-harness/.res/README.md +0 -1
  150. package/src/native-harness/.res/architecture/README.md +0 -21
  151. package/src/native-harness/.res/architecture/context-and-data.md +0 -31
  152. package/src/native-harness/.res/architecture/execution.md +0 -42
  153. package/src/native-harness/.res/architecture/overview.md +0 -44
  154. package/src/native-harness/.res/architecture/persistence.md +0 -56
  155. package/src/native-harness/.res/architecture/suspend-and-resume.md +0 -45
  156. package/src/native-harness/.res/architecture/technical-architecture.md +0 -50
  157. package/src/native-harness/.res/decisions/0001-basic-loop.md +0 -11
  158. package/src/native-harness/.res/decisions/0002-channel-input.md +0 -17
  159. package/src/native-harness/.res/decisions/0003-inference-inspection.md +0 -14
  160. package/src/native-harness/.res/decisions/0004-shared-context.md +0 -21
  161. package/src/native-harness/.res/decisions/0005-notice-inbox.md +0 -20
  162. package/src/native-harness/.res/decisions/0006-explicit-notices.md +0 -12
  163. package/src/native-harness/.res/decisions/0007-channel-output.md +0 -12
  164. package/src/native-harness/.res/decisions/0008-browser-client.md +0 -16
  165. package/src/native-harness/.res/decisions/0009-scripted-model.md +0 -18
  166. package/src/native-harness/.res/decisions/0010-inprocess-protocol.md +0 -19
  167. package/src/native-harness/.res/decisions/0011-stdio-transport.md +0 -21
  168. package/src/native-harness/.res/decisions/0012-session-storage-contract.md +0 -37
  169. package/src/native-harness/.res/decisions/0013-durable-delivery-contract.md +0 -64
  170. package/src/native-harness/.res/decisions/0014-channel-controls-contract.md +0 -73
  171. package/src/native-harness/.res/decisions/0015-session-file-contract.md +0 -72
  172. package/src/native-harness/.res/decisions/0016-configuration-permissions.md +0 -159
  173. package/src/native-harness/.res/decisions/0017-openrouter-managed-config.md +0 -69
  174. package/src/native-harness/.res/decisions/0018-tool-dispatch-evidence.md +0 -78
  175. package/src/native-harness/.res/decisions/0019-model-execution.md +0 -188
  176. package/src/native-harness/.res/decisions/0020-startup-channel-changes.md +0 -71
  177. package/src/native-harness/.res/decisions/0021-tools-and-host-callbacks.md +0 -100
  178. package/src/native-harness/.res/decisions/0022-operator-controls.md +0 -115
  179. package/src/native-harness/.res/decisions/0023-long-running-mock.md +0 -82
  180. package/src/native-harness/.res/decisions/0024-callback-policy-names.md +0 -46
  181. package/src/native-harness/.res/decisions/0025-external-notices.md +0 -364
  182. package/src/native-harness/.res/decisions/0026-bounded-context.md +0 -81
  183. package/src/native-harness/.res/decisions/0027-development-instructions.md +0 -22
  184. package/src/native-harness/.res/decisions/0028-debug-tools.md +0 -16
  185. package/src/native-harness/.res/decisions/0029-bounded-model-call-pages.md +0 -37
  186. package/src/native-harness/.res/decisions/0030-timeline-retrieval.md +0 -145
  187. package/src/native-harness/.res/decisions/0031-one-off-reminders.md +0 -173
  188. package/src/native-harness/.res/docs/11-15.md +0 -148
  189. package/src/native-harness/.res/docs/BUSINESS_RULES.md +0 -111
  190. package/src/native-harness/.res/docs/WORK.md +0 -65
  191. package/src/native-harness/.res/docs/_/11-16-persistence/LOG.md +0 -312
  192. package/src/native-harness/.res/docs/_/11-16-persistence/PLAN.md +0 -77
  193. package/src/native-harness/.res/docs/_/11-16-persistence/SPEC.md +0 -313
  194. package/src/native-harness/.res/docs/_/11-19-channel-controls/LOG.md +0 -160
  195. package/src/native-harness/.res/docs/_/11-19-channel-controls/PLAN.md +0 -89
  196. package/src/native-harness/.res/docs/_/11-19-channel-controls/SPEC.md +0 -135
  197. package/src/native-harness/.res/docs/_/11-19-config-permissions/LOG.md +0 -143
  198. package/src/native-harness/.res/docs/_/11-19-config-permissions/PLAN.md +0 -93
  199. package/src/native-harness/.res/docs/_/11-19-config-permissions/SPEC.md +0 -181
  200. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/11-20-LOG.md +0 -433
  201. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PLAN.md +0 -60
  202. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PROTOCOL.md +0 -141
  203. package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/SPEC.md +0 -168
  204. package/src/native-harness/.res/docs/attachments/0001-DESIGN/SPEC.md +0 -111
  205. package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/PLAN.md +0 -129
  206. package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/SPEC.md +0 -135
  207. package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/LOG.md +0 -437
  208. package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/PLAN.md +0 -127
  209. package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/SPEC.md +0 -203
  210. package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/LOG.md +0 -292
  211. package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/PLAN.md +0 -91
  212. package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/SPEC.md +0 -187
  213. package/src/native-harness/.res/docs/model-execution/0001-DESIGN/LOG.md +0 -148
  214. package/src/native-harness/.res/docs/model-execution/0001-DESIGN/PLAN.md +0 -95
  215. package/src/native-harness/.res/docs/model-execution/0001-DESIGN/SPEC.md +0 -200
  216. package/src/native-harness/.res/docs/model-execution/0002-AMENDMENT-accounting/SPEC.md +0 -80
  217. package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/LOG.md +0 -206
  218. package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/PLAN.md +0 -106
  219. package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/SPEC.md +0 -297
  220. package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/LOG.md +0 -41
  221. package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/PLAN.md +0 -36
  222. package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/SPEC.md +0 -84
  223. package/src/native-harness/.res/docs/shell-execution/0001-DESIGN/SPEC.md +0 -147
  224. package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/LOG.md +0 -15
  225. package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/PLAN.md +0 -107
  226. package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/SPEC.md +0 -114
  227. package/src/native-harness/.res/docs/todos/11-19-TODO-auto_review-approve.md +0 -24
  228. package/src/native-harness/.res/docs/todos/11-20-TODO-user-entered-tool-code.md +0 -23
  229. package/src/native-harness/.res/docs/todos/11-21-TODO-node-resource-coordination.md +0 -103
  230. package/src/native-harness/.res/docs/todos/11-22-TODO-harness-m1-sequence.md +0 -50
  231. package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/LOG.md +0 -337
  232. package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/PLAN.md +0 -76
  233. package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/SPEC.md +0 -204
  234. package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/LOG.md +0 -73
  235. package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/SPEC.md +0 -64
  236. package/src/native-harness/.res/docs/tools-and-callbacks/0003-DESIGN-attachment-tools/SPEC.md +0 -58
  237. package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/LOG.md +0 -45
  238. package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/PLAN.md +0 -108
  239. package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/SPEC.md +0 -169
  240. package/src/native-harness/.res/docs/web-tools/0001-DESIGN/SPEC.md +0 -128
  241. package/src/native-harness/.res/marketing-draft.md +0 -22
  242. package/src/native-harness/.res/sandbox/1-simple-harness/README.md +0 -285
  243. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-1.md +0 -19
  244. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-10.md +0 -138
  245. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-11.md +0 -148
  246. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-12.md +0 -172
  247. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-13.md +0 -194
  248. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-14.md +0 -233
  249. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-15.md +0 -249
  250. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-16.md +0 -265
  251. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-17.md +0 -279
  252. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-18.md +0 -293
  253. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-19.md +0 -307
  254. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-2.md +0 -29
  255. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-20.md +0 -317
  256. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-21.md +0 -327
  257. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-3.md +0 -40
  258. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-4.md +0 -59
  259. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-5.md +0 -69
  260. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-6.md +0 -79
  261. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-7.md +0 -89
  262. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-8.md +0 -102
  263. package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-9.md +0 -116
  264. package/src/native-harness/.res/sandbox/1-simple-harness/conversation.jsonl +0 -49
  265. package/src/native-harness/.res/sandbox/1-simple-harness/doc.md +0 -87
  266. package/src/native-harness/.res/sandbox/1-simple-harness/harness.py +0 -289
  267. package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 2.py +0 -221
  268. package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 3.py +0 -287
  269. package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy.py +0 -165
  270. package/src/native-harness/.res/sandbox/1-simple-harness/state.json +0 -22
  271. package/src/native-harness/.res/sandbox/1-simple-harness/system-prompt.md +0 -2
  272. package/src/native-harness/AGENTS.md +0 -70
  273. package/src/native-harness/ARCHITECTURE.md +0 -249
  274. package/src/native-harness/bun.lock +0 -26
  275. package/src/native-harness/test/agent.test.ts +0 -130
  276. package/src/native-harness/test/approval-gate.test.ts +0 -255
  277. package/src/native-harness/test/approval-protocol.test.ts +0 -94
  278. package/src/native-harness/test/boundaries.test.ts +0 -18
  279. package/src/native-harness/test/channel-controls.test.ts +0 -322
  280. package/src/native-harness/test/client-abort.test.ts +0 -136
  281. package/src/native-harness/test/config-policy.test.ts +0 -301
  282. package/src/native-harness/test/conformance/storage.ts +0 -1141
  283. package/src/native-harness/test/context.test.ts +0 -177
  284. package/src/native-harness/test/crash.test.ts +0 -187
  285. package/src/native-harness/test/debug-tools.test.ts +0 -67
  286. package/src/native-harness/test/development-cli.test.ts +0 -67
  287. package/src/native-harness/test/development.test.ts +0 -171
  288. package/src/native-harness/test/dispatch-evidence.test.ts +0 -58
  289. package/src/native-harness/test/e2e.test.ts +0 -186
  290. package/src/native-harness/test/external-notices.test.ts +0 -101
  291. package/src/native-harness/test/fixtures/approval-e2e.jsonl +0 -4
  292. package/src/native-harness/test/fixtures/crash-scenario.jsonl +0 -5
  293. package/src/native-harness/test/fixtures/development-lifecycle.jsonl +0 -10
  294. package/src/native-harness/test/fixtures/echo-scenario.jsonl +0 -3
  295. package/src/native-harness/test/fixtures/format2-schema.ts +0 -27
  296. package/src/native-harness/test/fixtures/format3-schema.ts +0 -16
  297. package/src/native-harness/test/fixtures/hold-scenario.jsonl +0 -4
  298. package/src/native-harness/test/fixtures/model-e2e.jsonl +0 -3
  299. package/src/native-harness/test/fixtures/storage-owner.ts +0 -20
  300. package/src/native-harness/test/format-reply.test.ts +0 -10
  301. package/src/native-harness/test/helpers/operator-view.ts +0 -41
  302. package/src/native-harness/test/helpers/scenario.ts +0 -9
  303. package/src/native-harness/test/helpers/session.ts +0 -38
  304. package/src/native-harness/test/helpers/stdio.ts +0 -46
  305. package/src/native-harness/test/inspector.test.ts +0 -77
  306. package/src/native-harness/test/listeners.test.ts +0 -49
  307. package/src/native-harness/test/loop.test.ts +0 -88
  308. package/src/native-harness/test/model-channel-double.test.ts +0 -87
  309. package/src/native-harness/test/model-crash.test.ts +0 -62
  310. package/src/native-harness/test/model-delivery-regressions.test.ts +0 -55
  311. package/src/native-harness/test/model-e2e.test.ts +0 -71
  312. package/src/native-harness/test/model-final-filter.test.ts +0 -30
  313. package/src/native-harness/test/model-large-reply.test.ts +0 -28
  314. package/src/native-harness/test/model-live-queue.test.ts +0 -33
  315. package/src/native-harness/test/model-runner.test.ts +0 -117
  316. package/src/native-harness/test/model-storage.test.ts +0 -99
  317. package/src/native-harness/test/model-stream-adapter.test.ts +0 -26
  318. package/src/native-harness/test/model-stream-public.test.ts +0 -77
  319. package/src/native-harness/test/notices.test.ts +0 -64
  320. package/src/native-harness/test/openrouter-config.test.ts +0 -218
  321. package/src/native-harness/test/operator-controls.test.ts +0 -132
  322. package/src/native-harness/test/output.test.ts +0 -44
  323. package/src/native-harness/test/owner-config.test.ts +0 -64
  324. package/src/native-harness/test/permissions-e2e.test.ts +0 -68
  325. package/src/native-harness/test/persistence.test.ts +0 -236
  326. package/src/native-harness/test/portability.test.ts +0 -337
  327. package/src/native-harness/test/protocol.test.ts +0 -160
  328. package/src/native-harness/test/reminder-clock.test.ts +0 -61
  329. package/src/native-harness/test/reminder-stdio.test.ts +0 -140
  330. package/src/native-harness/test/reminder-storage.test.ts +0 -124
  331. package/src/native-harness/test/scenario-jsonl.test.ts +0 -112
  332. package/src/native-harness/test/scripted.test.ts +0 -92
  333. package/src/native-harness/test/session-file.test.ts +0 -51
  334. package/src/native-harness/test/startup-channel-changes.test.ts +0 -256
  335. package/src/native-harness/test/stdio.test.ts +0 -132
  336. package/src/native-harness/test/storage-memory.test.ts +0 -4
  337. package/src/native-harness/test/storage-sqlite.test.ts +0 -420
  338. package/src/native-harness/test/suspension.test.ts +0 -430
  339. package/src/native-harness/test/timeline-retrieval.test.ts +0 -211
  340. package/src/native-harness/test/tools-catalog.test.ts +0 -468
  341. package/src/native-harness/test/tools-protocol.test.ts +0 -418
  342. package/src/native-harness/test/transfers.test.ts +0 -94
  343. package/src/native-harness/test/web-chat.test.ts +0 -35
@@ -1,236 +0,0 @@
1
- import { inspectOperatorView } from "./helpers/operator-view.ts";
2
- import { afterAll, expect, test } from "bun:test";
3
- import { mkdtempSync, rmSync } from "node:fs";
4
- import { tmpdir } from "node:os";
5
- import { join } from "node:path";
6
- import { createSession } from "../src/index.ts";
7
- import { createInProcessHarness } from "../src/testing.ts";
8
- import { HarnessClient, createInProcessTransport } from "../src/client.ts";
9
- import { createProtocolServer } from "../src/interfaces/protocol/server.ts";
10
- import { FrameLimit, loadView, pageMessages } from "../src/interfaces/protocol/load.ts";
11
- import { sessionStatus } from "../src/kernel/channels.ts";
12
- import { createMemoryStorageAdapter } from "../src/state/storage/memory.ts";
13
- import type { ChannelEvent } from "../src/contracts/events.ts";
14
- import type { CreateParams } from "../src/contracts/protocol.ts";
15
- import type { SessionStorageAdapter } from "../src/contracts/storage.ts";
16
- import { recordWire, spawnHarness } from "./helpers/stdio.ts";
17
- import { lastInput, turnsEnd } from "./helpers/session.ts";
18
-
19
- const root = mkdtempSync(join(tmpdir(), "harness-persist-"));
20
- afterAll(() => rmSync(root, { recursive: true, force: true }));
21
- const setup: CreateParams = { sessionId: "kept", participants: [], channels: {}, config: {
22
- version: 1, system: "Test system", model: { protocol: "scripted", script: new URL("./fixtures/crash-scenario.jsonl", import.meta.url).pathname }, defaultPolicy: "__legacy_allow", policies: { __legacy_allow: { fallback: "allow", tools: {} } } } };
23
- const push = (channel: string, id: string, text: string) => ({ channel, item: { id, kind: "user_message" as const, sender: channel, content: [{ type: "text" as const, text }] } });
24
- function ended(client: HarnessClient, count: number) {
25
- const events: ChannelEvent[] = [];
26
- return { events, done: new Promise<void>(resolve => client.onChannelEvent(event => {
27
- events.push(event);
28
- if (events.filter(e => e.event.type === "turn_ended").length === count) resolve();
29
- })) };
30
- }
31
-
32
- for (const transport of ["in-process", "stdio"] as const) test(`${transport}: two channels survive a restart, load restores them, and new IDs do not collide`, async () => {
33
- // One durable location per transport: a home directory of SQLite files, or a
34
- // memory adapter that outlives the in-process server the way a file would.
35
- const home = mkdtempSync(join(root, "home-")), effects = join(home, "effects.log");
36
- const locations = new Map<string, SessionStorageAdapter>();
37
- const adapter = (id: string) => locations.get(id) ?? locations.set(id, createMemoryStorageAdapter()).get(id)!;
38
- const open = () => transport === "stdio" ? spawnHarness({ home, effects }) : createInProcessHarness({ adapter, effects, captureRequests: true });
39
-
40
- const first = open();
41
- try {
42
- const init = await first.client.initialize();
43
- expect(init.description.capabilities).toMatchObject({ acceptance: "durable", persistence: true });
44
- expect(init.description.capabilities.methods).toContain("session/open");
45
- await first.client.createSession(setup);
46
- const log = ended(first.client, 2);
47
- await Promise.all([first.client.push(push("a", "a1", "alpha question")), first.client.push(push("b", "b1", "beta question"))]);
48
- await log.done;
49
- } finally { await first.close(); }
50
-
51
- const second = open();
52
- try {
53
- await second.client.initialize();
54
- await expect(second.client.createSession(setup)).rejects.toMatchObject({ code: "already_exists" });
55
- await expect(second.client.openSession({ sessionId: "absent", config: setup.config })).rejects.toMatchObject({ code: "not_found" });
56
- await expect(second.client.status()).rejects.toMatchObject({ code: "not_ready" });
57
- const loaded = await inspectOperatorView(second.client, { sessionId: "kept", config: setup.config });
58
- expect(loaded.status).toMatchObject({ sessionId: "kept", lifecycle: "running", execution: "idle",
59
- channels: [{ channel: "a", pending: [] }, { channel: "b", pending: [] }] });
60
- expect(loaded.turns).toMatchObject([{ turnId: "1", state: "completed" }, { turnId: "2", state: "completed" }]);
61
- expect(loaded.turns.map(turn => turn.items).flat().sort()).toEqual(["a1", "b1"]);
62
- expect(loaded.items.map(item => [item.id, item.milestone, item.kind])).toEqual([["a1", "seen", "participant_message"], ["b1", "seen", "participant_message"]]);
63
- expect(loaded.messages.map(message => message.parts![0]!.text).sort()).toEqual(["First reply.", "First reply.", "Recording.", "Recording."]);
64
- expect(await second.client.idle()).toEqual({ idle: true });
65
- // Deduplication and conflicts survive the restart.
66
- expect(await second.client.push(push("a", "a1", "alpha question"))).toMatchObject({ duplicate: true, item: { milestone: "seen" } });
67
- await expect(second.client.push(push("a", "a1", "different"))).rejects.toMatchObject({ code: "item_conflict" });
68
- await expect(second.client.push(push("b", "a1", "alpha question"))).rejects.toMatchObject({ code: "item_conflict" });
69
-
70
- const log = ended(second.client, 1);
71
- await second.client.push(push("a", "a2", "follow up"));
72
- await log.done;
73
- const started = log.events.find(event => event.event.type === "turn_started")!;
74
- expect(started.event).toMatchObject({ turnId: "3", items: ["a2"] });
75
- expect(started.revision).toBeGreaterThan(loaded.status.revision);
76
- // The script continued from where the first process left it.
77
- expect(log.events.flatMap(event => event.event.type === "message_completed" ? [event.event.parts![0]!.text] : [])).toEqual(["Second reply."]);
78
- const messageId = log.events.flatMap(event => event.event.type === "message_completed" ? [event.event.messageId!] : [])[0]!;
79
- expect(loaded.messages.map(message => message.messageId)).not.toContain(messageId);
80
- if ("models" in second) {
81
- // The next inference is built from both restored conversations.
82
- const request = JSON.stringify(second.models.get("a")![0]!.messages);
83
- expect(request).toContain("alpha question"); expect(request).toContain("beta question"); expect(request).toContain("follow up");
84
- }
85
-
86
- const newest = await second.client.channelMessages({ channel: "a", limit: 2 });
87
- expect(newest.messages).toHaveLength(2);
88
- expect(newest.messages.at(-1)).toMatchObject({ messageId, turnId: "3" });
89
- const older = await second.client.channelMessages({ channel: "a", cursor: newest.next! });
90
- expect(older.messages.length).toBeGreaterThan(0);
91
- expect(older.messages.every(message => !newest.messages.some(newer => newer.messageId === message.messageId))).toBe(true);
92
- await expect(second.client.openSession({ sessionId: "other", config: setup.config })).rejects.toMatchObject({ code: "already_exists" });
93
- } finally { await second.close(); }
94
- }, 15000);
95
-
96
- test("an observation during execution is one snapshot: earlier events precede the response and later events follow it", async () => {
97
- let release!: () => void;
98
- let gate = new Promise<void>(resolve => { release = resolve; });
99
- const session = createSession({ systemPrompt: "test", configureTurn: () => ({ tools: [], executeTool: async () => "unused",
100
- model: async messages => { await gate; return { role: "assistant", content: lastInput(messages), calls: [] }; } }) });
101
- const transport = createInProcessTransport(createProtocolServer(async () => ({ session, close() {} }), { durable: true }));
102
- const wire = recordWire(transport) as any[];
103
- const client = new HarnessClient(transport);
104
- try {
105
- await client.initialize(); await client.createSession({ ...setup, sessionId: "memory" });
106
- const log = ended(client, 1);
107
- await client.push(push("a", "1", "first"));
108
- while (!wire.some(message => message.params?.event?.type === "turn_started")) await new Promise(resolve => setTimeout(resolve, 1));
109
- // Commit more work in the same tick the load is answered: it must not overtake the response.
110
- const loading = client.observeChannel({ channel: "a" });
111
- queueMicrotask(() => { session.agent.send({ channelId: "b", participantId: "bob", text: "racing", itemId: "2" }); release(); });
112
- const loaded = await loading;
113
- await log.done;
114
- await new Promise(resolve => setTimeout(resolve, 5));
115
- const at = wire.findIndex(message => message.result?.sessionLifecycle && message.result?.channel);
116
- const revisions = (messages: any[]) => messages.flatMap(message => message.params?.revision === undefined ? [] : [message.params.revision]);
117
- expect(revisions(wire.slice(0, at)).every(revision => revision <= loaded.revision)).toBe(true);
118
- expect(revisions(wire.slice(at + 1)).length).toBeGreaterThan(2);
119
- expect(revisions(wire.slice(at + 1)).every(revision => revision > loaded.revision)).toBe(true);
120
- expect(loaded.channel.activeTurn).toMatchObject({ turnId: "1", state: "running" });
121
- } finally { release(); client.close(); }
122
- });
123
-
124
- test("load views that cannot fit one frame fail whole; message pages respect the frame and the revision", () => {
125
- const opened = createMemoryStorageAdapter().open({ mode: "create", identity: { sessionId: "big", compatibilityKey: "" } });
126
- if (!opened.ok) throw new Error(opened.error.message);
127
- const storage = opened.value, big = "x".repeat(300_000);
128
- storage.acceptItem({ kind: "participant_message", channelId: "a", senderId: "ana", text: "hi" });
129
- const turn = storage.beginTurn("a");
130
- if (!turn.ok || !turn.value) throw new Error("no turn");
131
- for (let i = 0; i < 5; i++) storage.appendMessage(turn.value.turn.turnId, { role: "assistant", content: `${i}${big}`, calls: [] });
132
- const view = () => { const read = storage.snapshot(); if (!read.ok) throw new Error(read.error.message); return read.value; };
133
- const first = loadView(sessionStatus(view(), false), view(), 100);
134
- // Three 300 KB messages fit beside the fixed part; the rest are paged.
135
- expect(first.messages.map(message => message.parts![0]!.text[0])).toEqual(["0", "1", "2"]);
136
- expect(new TextEncoder().encode(JSON.stringify(first)).length).toBeLessThan(1024 * 1024);
137
- const before = view().revision;
138
- storage.appendMessage(turn.value.turn.turnId, { role: "assistant", content: "later", calls: [] });
139
- const rest = pageMessages(view(), before, Number(first.nextMessage), 100);
140
- expect(rest.messages.map(message => message.parts![0]!.text[0])).toEqual(["3", "4"]);
141
- expect(rest.nextMessage).toBeUndefined();
142
- // Oversized text is represented by a bounded-read reference.
143
- storage.appendMessage(turn.value.turn.turnId, { role: "assistant", content: "y".repeat(1024 * 1024), calls: [] });
144
- const prefix = pageMessages(view(), view().revision, 0, 100);
145
- expect(prefix.messages.map(message => message.parts![0]!.text[0])).toEqual(["0", "1", "2"]);
146
- const middle = pageMessages(view(), view().revision, Number(prefix.nextMessage), 100);
147
- expect(middle.messages.slice(0, 3).map(message => message.parts![0]!.text)).toEqual([`3${big}`, `4${big}`, "later"]);
148
- expect(middle.messages[3]).toMatchObject({ reference: true });
149
- expect(middle.nextMessage).toBeUndefined();
150
- expect(loadView(sessionStatus(view(), false), view(), 100).messages).toEqual(prefix.messages);
151
- // Unpaged turns and items that outgrow a frame fail the load rather than truncating it.
152
- for (let i = 0; i < 4; i++) storage.acceptItem({ kind: "participant_message", channelId: "a", senderId: "ana", text: "t", itemId: `${i}${big}` });
153
- expect(() => loadView(sessionStatus(view(), false), view(), 100)).toThrow("turns and items do not fit");
154
- });
155
-
156
- test("open readiness fits even when the legacy full view exceeds a frame", async () => {
157
- const location = createMemoryStorageAdapter();
158
- const seeded = location.open({ mode: "create", identity: { sessionId: "big", compatibilityKey: "" } });
159
- if (!seeded.ok) throw new Error(seeded.error.message);
160
- for (let i = 0; i < 4; i++) seeded.value.acceptItem({ kind: "participant_message", channelId: "a", senderId: "ana", text: "t", itemId: `${i}${"x".repeat(300_000)}` });
161
- seeded.value.close();
162
- let ran = 0;
163
- const server = createProtocolServer(async ({ mode, sessionId }) => {
164
- const opened = location.open({ mode, identity: { sessionId, compatibilityKey: "" } });
165
- if (!opened.ok) throw new Error(opened.error.message);
166
- const session = createSession({ systemPrompt: "test", storage: opened.value, configureTurn: () => ({ tools: [], executeTool: async () => "unused",
167
- model: async () => { ran++; return { role: "assistant", content: "ran", calls: [] }; } }) });
168
- return { session, close() { opened.value.close(); } };
169
- }, { durable: true });
170
- const client = new HarnessClient(createInProcessTransport(server));
171
- try {
172
- await client.initialize();
173
- const opened = await client.openSession({ sessionId: "big" });
174
- expect(opened).toMatchObject({ sessionId: "big", lifecycle: "running", revision: expect.any(Number) });
175
- expect(opened).not.toHaveProperty("messages");
176
- } finally { client.close(); }
177
- });
178
-
179
- test("a message racing turn completion reaches exactly one turn at every interleaving", async () => {
180
- // Sweep the moment a second message is accepted across the whole life of a
181
- // turn that infers, runs a tool and infers again: before, between and after
182
- // each await, including the ticks around the finish decision.
183
- for (let delay = 0; delay < 40; delay++) {
184
- let inferences = 0;
185
- const session = createSession({ systemPrompt: "test", configureTurn: turn => ({ tools: [],
186
- executeTool: async () => { await null; await null; return "result"; },
187
- model: async messages => {
188
- inferences++;
189
- await null; await null;
190
- return turn.turnId === 1 && !messages.some(message => message.role === "tool")
191
- ? { role: "assistant", content: null, calls: [{ id: "t", name: "tool", arguments: "{}" }] }
192
- : { role: "assistant", content: `answered ${lastInput(messages)}`, calls: [] };
193
- } }) });
194
- session.start();
195
- session.agent.send({ channelId: "a", participantId: "ana", text: "first", itemId: "first" });
196
- for (let tick = 0; tick < delay; tick++) await null;
197
- expect(session.agent.send({ channelId: "a", participantId: "ana", text: "second", itemId: "second" })).toMatchObject({ accepted: true, duplicate: false });
198
- while (!session.agent.idle()) await new Promise(resolve => setTimeout(resolve, 0));
199
- const view = session.snapshot();
200
- // Every turn completed, each item is linked to one turn and has one timeline entry.
201
- expect(view.turns.every(turn => turn.state.status === "completed")).toBe(true);
202
- expect(view.turns.flatMap(turn => turn.itemIds).sort()).toEqual(["first", "second"]);
203
- expect(view.timeline.filter(entry => entry.itemId === "second")).toHaveLength(1);
204
- const second = view.items.find(item => item.itemId === "second")!;
205
- expect(second.milestone).toBe("seen");
206
- // It was answered by the turn that took it: an inference ran after its entry.
207
- const answer = view.timeline.findLast(entry => entry.turnId === second.turnId && entry.message.role === "assistant")!;
208
- expect(answer.seq).toBeGreaterThan(second.entrySeq!);
209
- expect(answer.message.content).toBe("answered second");
210
- // Joined the first turn or started a second one, never both; no inference went unrecorded.
211
- expect([1, 2]).toContain(view.turns.length);
212
- expect(inferences).toBe(view.timeline.filter(entry => entry.message.role === "assistant").length);
213
- }
214
- });
215
-
216
- test("both outcomes of the race occur across the sweep, and events name the turn that took each item", async () => {
217
- const shapes = new Set<string>();
218
- for (let delay = 0; delay < 40; delay++) {
219
- const session = createSession({ systemPrompt: "test", configureTurn: () => ({ tools: [], executeTool: async () => "unused",
220
- model: async messages => { await null; await null; return { role: "assistant", content: lastInput(messages), calls: [] }; } }) });
221
- session.start();
222
- const taken = new Map<string, string>();
223
- session.subscribe(({ event }) => {
224
- if (event.type !== "turn_started" && event.type !== "turn_took") return;
225
- for (const item of event.items) { expect(taken.has(item)).toBe(false); taken.set(item, event.turnId); }
226
- });
227
- session.agent.send({ channelId: "a", participantId: "ana", text: "first", itemId: "first" });
228
- for (let tick = 0; tick < delay; tick++) await null;
229
- session.agent.send({ channelId: "a", participantId: "ana", text: "second", itemId: "second" });
230
- while (!session.agent.idle()) await new Promise(resolve => setTimeout(resolve, 0));
231
- const view = session.snapshot();
232
- expect(taken.get("second")).toBe(String(view.items.find(item => item.itemId === "second")!.turnId));
233
- shapes.add(view.turns.length === 1 ? (view.timeline.filter(entry => entry.message.role === "assistant").length === 1 ? "same take" : "steered") : "next turn");
234
- }
235
- expect([...shapes].sort()).toEqual(["next turn", "same take", "steered"]);
236
- });
@@ -1,337 +0,0 @@
1
- import { inspectOperatorView } from "./helpers/operator-view.ts";
2
- import { decodeSessionFile, encodeSessionFile } from "../src/state/storage/session-file.ts";
3
- import { afterAll, expect, test } from "bun:test";
4
- import { createHash } from "node:crypto";
5
- import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
6
- import { tmpdir } from "node:os";
7
- import { join } from "node:path";
8
- import { createInProcessHarness } from "../src/testing.ts";
9
- import type { HarnessClient } from "../src/client.ts";
10
- import { createMemoryStorageAdapter } from "../src/state/storage/memory.ts";
11
- import { createSqliteStorageAdapter } from "../src/state/storage/sqlite.ts";
12
- import type { ChannelEvent } from "../src/contracts/events.ts";
13
- import type { CreateParams, ProtocolConfig } from "../src/contracts/protocol.ts";
14
- import type { SessionStorageAdapter } from "../src/contracts/storage.ts";
15
- import { spawnHarness } from "./helpers/stdio.ts";
16
-
17
- const root = mkdtempSync(join(tmpdir(), "harness-port-"));
18
- afterAll(() => rmSync(root, { recursive: true, force: true }));
19
- // Keep the large archive fixture above one frame via committed model output.
20
- const scenarioPath = join(root, "portable.jsonl");
21
- const records = readFileSync(new URL("./fixtures/hold-scenario.jsonl", import.meta.url), "utf8").trimEnd().split("\n");
22
- records[1] = JSON.stringify({ ...JSON.parse(records[1]!), content: "p".repeat(1_100_000) });
23
- writeFileSync(scenarioPath, records.join("\n") + "\n");
24
- const config: ProtocolConfig = { version: 1, system: "Test system", model: { protocol: "scripted", script: new URL("./fixtures/hold-scenario.jsonl", import.meta.url).pathname }, defaultPolicy: "__legacy_allow", policies: { __legacy_allow: { fallback: "allow", tools: {} } } };
25
- const largeConfig: ProtocolConfig = { ...config, model: { protocol: "scripted", script: scenarioPath } };
26
- const setup: CreateParams = { sessionId: "moved", participants: [], channels: {}, config };
27
- const push = (channel: string, id: string, text: string) => ({ channel, item: { id, kind: "user_message" as const, sender: channel, content: [{ type: "text" as const, text }] } });
28
- const lines = (path: string) => existsSync(path) ? readFileSync(path, "utf8").split("\n").filter(Boolean) : [];
29
- const sha = (bytes: Uint8Array) => createHash("sha256").update(bytes).digest("hex");
30
- const b64 = (bytes: Uint8Array) => Buffer.from(bytes).toString("base64");
31
- async function until(check: () => boolean | Promise<boolean>, what: string) {
32
- for (let i = 0; i < 600; i++) { if (await check()) return; await new Promise(resolve => setTimeout(resolve, 5)); }
33
- throw new Error(`Timed out waiting for ${what}`);
34
- }
35
- function watch(client: HarnessClient) {
36
- const events: ChannelEvent[] = [];
37
- client.onChannelEvent(event => { events.push(event); });
38
- return events;
39
- }
40
- /** A home is a directory of SQLite sessions for stdio, or a set of lasting memory locations in-process. */
41
- function home(transport: "in-process" | "stdio", effects: string, limits?: { maxBytes?: number; idleMs?: number; chunkBytes?: number }) {
42
- const directory = mkdtempSync(join(root, "home-"));
43
- const locations = new Map<string, SessionStorageAdapter>();
44
- const adapter = (id: string) => locations.get(id) ?? locations.set(id, createMemoryStorageAdapter()).get(id)!;
45
- return { directory, files: () => readdirSync(directory).sort(),
46
- open: () => transport === "stdio" ? spawnHarness({ home: directory, effects }) : createInProcessHarness({ adapter, effects, transfers: directory, limits }) };
47
- }
48
- const pendingText = (i: number) => `Pending message ${i}`;
49
-
50
- test("stdio: active config and individual checkpoint survive path import after source config removal", async () => {
51
- const source = mkdtempSync(join(root, "source-config-")), dest = mkdtempSync(join(root, "dest-config-"));
52
- const effects = join(source, "effects.log"), configPath = join(source, "config.json"), path = join(source, "copy.harness"), scriptPath = join(source, "script.jsonl");
53
- if (config.model.protocol !== "scripted") throw new Error("Expected scripted test model");
54
- const script = readFileSync(config.model.script); writeFileSync(scriptPath, script);
55
- writeFileSync(configPath, JSON.stringify({ ...config, model: { ...config.model, script: scriptPath } }));
56
- const active = JSON.parse(readFileSync(configPath, "utf8"));
57
- const first = spawnHarness({ home: source, effects });
58
- try {
59
- await first.client.initialize(); await first.client.createSession({ ...setup, config: active });
60
- rmSync(configPath);
61
- await first.client.push(push("a", "a1", "start"));
62
- await until(() => lines(effects).includes("start:k"), "tool start");
63
- await first.client.push(push("a", "a2", "pending"));
64
- const suspended = first.client.suspendChannel({ channel: "a" });
65
- await until(async () => (await first.client.status()).channels[0]?.lifecycle === "suspending", "channel suspending");
66
- writeFileSync(`${effects}.release-k`, ""); await suspended;
67
- await expect(first.client.exportTo(path)).rejects.toMatchObject({ code: "busy" });
68
- await first.client.suspend();
69
- await first.client.exportTo(path);
70
- expect((decodeSessionFile(readFileSync(path), 268435456) as any).config).toEqual(active);
71
- } finally { await first.close(); }
72
- rmSync(scriptPath);
73
- const second = spawnHarness({ home: dest, effects });
74
- try {
75
- await second.client.initialize(); await second.client.importFrom(path);
76
- await expect(second.client.openSession({ sessionId: "moved" })).rejects.toMatchObject({ code: "invalid_config" });
77
- writeFileSync(scriptPath, script);
78
- const loaded = await inspectOperatorView(second.client, { sessionId: "moved" });
79
- expect(loaded.status.channels[0]).toMatchObject({ lifecycle: "suspended", pending: ["a2"], waitingForResume: true });
80
- await second.client.resume();
81
- expect((await second.client.status()).channels[0]).toMatchObject({ lifecycle: "suspended", pending: ["a2"] });
82
- const events = watch(second.client); await second.client.resumeChannel({ channel: "a" });
83
- await until(() => events.some(e => e.event.type === "turn_ended"), "resumed channel");
84
- expect(lines(effects)).toEqual(["start:k", "done:k"]);
85
- } finally { await second.close(); }
86
- const adapter = createSqliteStorageAdapter(join(dest, "moved", "session.sqlite"));
87
- const db = adapter.open({ mode: "open", identity: { sessionId: "moved", compatibilityKey: "inspection" } });
88
- if (!db.ok) throw new Error(db.error.message);
89
- expect(db.value.importedConfig()).toMatchObject({ ok: true, value: active }); db.value.close();
90
- }, 30000);
91
-
92
- /** A suspended session holding a checkpointed turn, a large committed response and pending input. */
93
- async function suspendedSource(client: HarnessClient, effects: string) {
94
- await client.initialize(); await client.createSession({ ...setup, config: largeConfig });
95
- await client.push(push("a", "a1", "start"));
96
- await until(() => lines(effects).includes("start:k"), "tool to start");
97
- for (let i = 0; i < 5; i++) await client.push(push("a", `big-${i}`, pendingText(i)));
98
- const suspending = client.suspend();
99
- await until(async () => (await client.status()).lifecycle === "suspending", "suspension to begin");
100
- writeFileSync(`${effects}.release-k`, "");
101
- return suspending;
102
- }
103
-
104
- for (const transport of ["in-process", "stdio"] as const) test(`${transport}: a suspended session larger than one frame round-trips into a fresh home and resumes there exactly once`, async () => {
105
- const effects = join(mkdtempSync(join(root, "fx-")), "effects.log");
106
- const source = home(transport, effects), destination = home(transport, effects);
107
- let archive: Uint8Array, before;
108
- const first = source.open();
109
- try {
110
- const status = await suspendedSource(first.client, effects);
111
- expect(status).toMatchObject({ lifecycle: "suspended" });
112
- before = await inspectOperatorView(first.client, { sessionId: "moved", config: largeConfig });
113
- archive = await first.client.exportArchive();
114
- // Larger than one 1 MiB frame, so it can only have crossed in chunks.
115
- expect(archive.length).toBeGreaterThan(1024 * 1024);
116
- // One binary envelope contains both the logical archive and active config.
117
- const payload = decodeSessionFile(archive, 268435456) as any;
118
- const document = payload.archive;
119
- expect(payload.config).toEqual(largeConfig);
120
- expect(Object.keys(document).sort()).toEqual(["allocation", "archiveVersion", "exportedAt", "format", "snapshot"]);
121
- expect(document).toMatchObject({ format: "harness-session", archiveVersion: 5, snapshot: { revision: before.status.revision, session: { sessionId: "moved", lifecycle: "suspended" } } });
122
- // Export by path writes the same document; its reported length and hash are those of the file.
123
- const path = join(source.directory, "moved.harness");
124
- const byPath = await first.client.exportTo(path);
125
- const file = readFileSync(path);
126
- expect(byPath).toEqual({ bytes: file.length, sha256: sha(file) });
127
- expect((decodeSessionFile(file, 268435456) as any).archive.snapshot).toEqual(document.snapshot);
128
- await expect(first.client.exportTo(path)).rejects.toMatchObject({ code: "already_exists" });
129
- expect(readFileSync(path).equals(file)).toBe(true);
130
- // Export leaves the session as it was, and no transfer file behind.
131
- expect(await inspectOperatorView(first.client, { sessionId: "moved", config: largeConfig })).toEqual(before);
132
- expect(source.files().filter(name => name.includes("transfer") || name.includes("draft"))).toEqual([]);
133
- } finally { await first.close(); }
134
-
135
- const second = destination.open();
136
- try {
137
- await second.client.initialize();
138
- const events = watch(second.client);
139
- expect(await second.client.importArchive(archive)).toEqual({ sessionId: "moved", lifecycle: "suspended", revision: before.status.revision });
140
- // Importing neither opens nor runs the copy.
141
- await expect(second.client.status()).rejects.toMatchObject({ code: "not_ready" });
142
- // An occupied destination is refused and left alone.
143
- await expect(second.client.importArchive(archive)).rejects.toMatchObject({ code: "already_exists" });
144
- const loaded = await inspectOperatorView(second.client, { sessionId: "moved", config: largeConfig });
145
- expect(loaded).toEqual(before);
146
- expect(loaded.turns).toMatchObject([{ turnId: "1", state: "suspended", items: ["a1"] }]);
147
- expect(loaded.items.map(item => [item.id, item.milestone])).toEqual([["a1", "seen"], ...[0, 1, 2, 3, 4].map(i => [`big-${i}`, "received"])]);
148
- await new Promise(resolve => setTimeout(resolve, 100));
149
- expect(events).toEqual([]);
150
- // Deduplication travelled with the session.
151
- expect(await second.client.push(push("a", "big-2", pendingText(2)))).toMatchObject({ duplicate: true, item: { milestone: "received" } });
152
- await expect(second.client.push(push("a", "big-2", "other text"))).rejects.toMatchObject({ code: "item_conflict" });
153
- await second.client.resume();
154
- await until(() => events.some(event => event.event.type === "turn_ended"), "resumed turn");
155
- expect(events.map(event => event.event.type)).toEqual(["turn_resumed", "turn_took", "items_receipt", "items_receipt", "message_completed", "turn_ended"]);
156
- expect(events[1]!.event).toMatchObject({ turnId: "1", items: [0, 1, 2, 3, 4].map(i => `big-${i}`) });
157
- // The tool that completed in the source process never ran in the destination.
158
- expect(lines(effects)).toEqual(["start:k", "done:k"]);
159
- const after = await inspectOperatorView(second.client, { sessionId: "moved", config: largeConfig });
160
- expect(after.turns).toMatchObject([{ turnId: "1", state: "completed", items: ["a1", "big-0", "big-1", "big-2", "big-3", "big-4"] }]);
161
- // IDs continue from the source's allocation state.
162
- await second.client.push(push("b", "b1", "fresh"));
163
- await until(() => events.filter(event => event.event.type === "turn_ended").length === 2, "fresh turn");
164
- expect(events.find(event => event.channel === "b")!.event).toMatchObject({ type: "turn_started", turnId: "2", items: ["b1"] });
165
- expect(events.find(event => event.channel === "b")!.revision).toBeGreaterThan(before.status.revision);
166
- } finally { await second.close(); }
167
-
168
- // A copy under a new session ID keeps the IDs inside it, by path this time.
169
- const third = destination.open();
170
- try {
171
- await third.client.initialize();
172
- expect(await third.client.importFrom(join(source.directory, "moved.harness"), "renamed")).toMatchObject({ sessionId: "renamed", lifecycle: "suspended" });
173
- const renamed = await inspectOperatorView(third.client, { sessionId: "renamed", config: largeConfig });
174
- expect(renamed).toEqual({ ...before, status: { ...before.status, sessionId: "renamed" } });
175
- } finally { await third.close(); }
176
- }, 30000);
177
-
178
- for (const transport of ["in-process", "stdio"] as const) test(`${transport}: invalid archives and broken transfers leave no session and no files`, async () => {
179
- const effects = join(mkdtempSync(join(root, "fx-")), "effects.log");
180
- const source = home(transport, effects), destination = home(transport, effects);
181
- const first = source.open();
182
- let archive: Uint8Array;
183
- try { await suspendedSource(first.client, effects); archive = await first.client.exportArchive(); }
184
- finally { await first.close(); }
185
- const second = destination.open();
186
- try {
187
- const { client } = second;
188
- await client.initialize();
189
- const baseline = destination.files();
190
- const refused = async (attempt: Promise<unknown>, code: string) => {
191
- await expect(attempt).rejects.toMatchObject({ code });
192
- await expect(inspectOperatorView(client, { sessionId: "moved", config: largeConfig })).rejects.toMatchObject({ code: "not_found" });
193
- expect(destination.files()).toEqual(baseline);
194
- };
195
- // Damaged documents: truncated, not JSON, edited content, illegal lifecycle.
196
- const edited = (change: (document: any) => void) => { const payload = decodeSessionFile(archive, 268435456) as any; change(payload.archive); return encodeSessionFile(payload, 268435456); };
197
- await refused(client.importArchive(archive.subarray(0, archive.length - 10)), "invalid_archive");
198
- await refused(client.importArchive(new TextEncoder().encode("not an archive")), "invalid_archive");
199
- await refused(client.importArchive(new Uint8Array([0xff, 0xfe, 0x00])), "invalid_archive");
200
- await refused(client.importArchive(edited(document => { document.snapshot.items[1].text = "tampered"; })), "invalid_archive");
201
- await refused(client.importArchive(edited(document => { document.snapshot.session.lifecycle = "suspending"; })), "invalid_archive");
202
- await refused(client.importArchive(edited(document => { document.snapshot.items[2].acceptedSeq = document.snapshot.items[1].acceptedSeq; })), "invalid_archive");
203
- await refused(client.importArchive(edited(document => { document.archiveVersion = 6; })), "invalid_archive");
204
- const invalidConfig = decodeSessionFile(archive, 268435456) as any;
205
- invalidConfig.config.model.script = " ";
206
- await refused(client.importArchive(encodeSessionFile(invalidConfig, 268435456)), "invalid_archive");
207
- const wrongVersion = Uint8Array.from(archive); wrongVersion[9] = 2;
208
- await refused(client.importArchive(wrongVersion), "invalid_archive");
209
- await refused(client.importArchive(Uint8Array.from([...archive, 0])), "invalid_archive");
210
- // Path sources: missing file, junk file.
211
- await refused(client.importFrom(join(destination.directory, "absent.harness")), "not_found");
212
- const junk = join(mkdtempSync(join(root, "junk-")), "junk.harness"); writeFileSync(junk, "{\"format\":");
213
- await refused(client.importFrom(junk), "invalid_archive");
214
-
215
- // Transfer rules. Bytes that do not match the announced hash or length are not an archive.
216
- const open = () => client.request("transfer/open", { bytes: archive.length, sha256: sha(archive) });
217
- let { transferId, limits } = await open();
218
- expect(limits).toEqual({ chunkBytes: 524288, maxBytes: 268435456, idleMs: 60000 });
219
- await expect(open()).rejects.toMatchObject({ code: "transfer_limit" });
220
- const chunk = archive.subarray(0, limits.chunkBytes);
221
- await expect(client.request("transfer/write", { transferId, offset: 10, data: b64(chunk) })).rejects.toMatchObject({ code: "transfer_limit" });
222
- await expect(client.request("transfer/write", { transferId, offset: 0, data: b64(archive.subarray(0, limits.chunkBytes + 1)) })).rejects.toMatchObject({ code: "transfer_limit" });
223
- await expect(client.request("transfer/write", { transferId: "unknown", offset: 0, data: b64(chunk) })).rejects.toMatchObject({ code: "not_found" });
224
- await expect(client.request("transfer/read", { transferId, offset: 0 })).rejects.toMatchObject({ code: "not_found" });
225
- // The refused chunks wrote nothing: the first accepted chunk is still at offset 0.
226
- expect(await client.request("transfer/write", { transferId, offset: 0, data: b64(chunk) })).toEqual({ received: chunk.length });
227
- await expect(client.request("transfer/write", { transferId, offset: 0, data: b64(chunk) })).rejects.toMatchObject({ code: "transfer_limit" });
228
- // Importing an incomplete upload fails and ends the transfer.
229
- await refused(client.request("session/import", { from: { type: "transfer", transferId } }), "invalid_archive");
230
- await expect(client.request("transfer/close", { transferId })).rejects.toMatchObject({ code: "not_found" });
231
- // An upload that would run past its announced length.
232
- ({ transferId } = await client.request("transfer/open", { bytes: 4, sha256: sha(archive) }));
233
- await expect(client.request("transfer/write", { transferId, offset: 0, data: b64(archive.subarray(0, 5)) })).rejects.toMatchObject({ code: "transfer_limit" });
234
- expect(await client.request("transfer/close", { transferId })).toEqual({});
235
- // Complete bytes under the wrong hash.
236
- ({ transferId } = await client.request("transfer/open", { bytes: 4, sha256: sha(archive) }));
237
- await client.request("transfer/write", { transferId, offset: 0, data: b64(archive.subarray(0, 4)) });
238
- await refused(client.request("session/import", { from: { type: "transfer", transferId } }), "invalid_archive");
239
- // Over the size limit: refused before any file exists.
240
- await refused(client.request("transfer/open", { bytes: 268435457, sha256: sha(archive) }), "transfer_limit");
241
- await refused(client.request("transfer/open", { bytes: 0, sha256: sha(archive) }), "invalid_archive");
242
- // After all of that, the real archive still imports.
243
- expect(await client.importArchive(archive)).toMatchObject({ sessionId: "moved", lifecycle: "suspended" });
244
- await expect(client.importArchive(encodeSessionFile(invalidConfig, 268435456))).rejects.toMatchObject({ code: "invalid_archive" });
245
- expect((await inspectOperatorView(client, { sessionId: "moved", config: largeConfig })).status.lifecycle).toBe("suspended");
246
- expect(destination.files().filter(name => name.includes("transfer") || name.includes("draft"))).toEqual([]);
247
- } finally { await second.close(); }
248
- }, 30000);
249
-
250
- for (const transport of ["in-process", "stdio"] as const) test(`${transport}: export is refused while work is active or pending, and allowed when idle`, async () => {
251
- const effects = join(mkdtempSync(join(root, "fx-")), "effects.log");
252
- const place = home(transport, effects);
253
- const harness = place.open();
254
- try {
255
- const { client } = harness;
256
- const init = await client.initialize();
257
- expect(init.description.capabilities.methods).toEqual(expect.arrayContaining(["session/export", "session/import", "transfer/open", "transfer/write", "transfer/read", "transfer/close"]));
258
- await expect(client.exportArchive()).rejects.toMatchObject({ code: "not_ready" });
259
- await client.createSession(setup);
260
- const events = watch(client);
261
- // Idle with nothing pending: a running-lifecycle archive.
262
- const empty = (decodeSessionFile(await client.exportArchive(), 268435456) as any).archive;
263
- expect(empty.snapshot).toMatchObject({ session: { lifecycle: "running" }, turns: [], items: [] });
264
- await client.push(push("a", "a1", "start"));
265
- await until(() => lines(effects).includes("start:k"), "tool to start");
266
- const target = join(place.directory, "busy.harness");
267
- await expect(client.exportTo(target)).rejects.toMatchObject({ code: "busy" });
268
- await expect(client.exportArchive()).rejects.toMatchObject({ code: "busy" });
269
- const suspending = client.suspend();
270
- await until(async () => (await client.status()).lifecycle === "suspending", "suspension to begin");
271
- // Suspending is not yet a clean suspension.
272
- await expect(client.exportArchive()).rejects.toMatchObject({ code: "busy" });
273
- expect(existsSync(target)).toBe(false);
274
- writeFileSync(`${effects}.release-k`, "");
275
- await suspending;
276
- // A download can be read at any offset, repeatedly, until it is closed.
277
- const { bytes, sha256, transferId } = await client.request("session/export", { to: { type: "transfer" } });
278
- const whole = Buffer.from((await client.request("transfer/read", { transferId: transferId!, offset: 0 })).data, "base64");
279
- expect(whole.length).toBe(bytes); expect(sha(whole)).toBe(sha256);
280
- expect(await client.request("transfer/read", { transferId: transferId!, offset: bytes })).toEqual({ data: "", eof: true });
281
- expect(Buffer.from((await client.request("transfer/read", { transferId: transferId!, offset: 5 })).data, "base64").equals(whole.subarray(5))).toBe(true);
282
- await expect(client.request("transfer/read", { transferId: transferId!, offset: bytes + 1 })).rejects.toMatchObject({ code: "transfer_limit" });
283
- await expect(client.request("session/export", { to: { type: "transfer" } })).rejects.toMatchObject({ code: "transfer_limit" });
284
- await expect(client.request("transfer/write", { transferId: transferId!, offset: 0, data: "AAAA" })).rejects.toMatchObject({ code: "not_found" });
285
- expect(await client.request("transfer/close", { transferId: transferId! })).toEqual({});
286
- await expect(client.request("transfer/read", { transferId: transferId!, offset: 0 })).rejects.toMatchObject({ code: "not_found" });
287
- expect(place.files().filter(name => name.includes("transfer"))).toEqual([]);
288
- await client.resume();
289
- await until(() => events.some(event => event.event.type === "turn_ended"), "turn to finish");
290
- // Completed, idle, running: exportable again.
291
- expect((decodeSessionFile(await client.exportArchive(), 268435456) as any).archive.snapshot).toMatchObject({ session: { lifecycle: "running" }, turns: [{ state: { status: "completed" } }] });
292
- } finally { await harness.close(); }
293
- }, 30000);
294
-
295
- test("an archive over the size limit is refused by export with no file, and an idle transfer is removed", async () => {
296
- const effects = join(mkdtempSync(join(root, "fx-")), "effects.log");
297
- const place = home("in-process", effects, { maxBytes: 200, idleMs: 40 });
298
- const harness = place.open();
299
- try {
300
- const { client } = harness;
301
- await client.initialize(); await client.createSession(setup);
302
- const small = await client.request("session/export", { to: { type: "transfer" } }).catch(error => error);
303
- // The empty session is already larger than this test's 200-byte limit.
304
- expect(small).toMatchObject({ code: "transfer_limit" });
305
- const target = join(place.directory, "too-big.harness");
306
- await expect(client.exportTo(target)).rejects.toMatchObject({ code: "transfer_limit" });
307
- expect(place.files()).toEqual([]);
308
- await expect(client.request("transfer/open", { bytes: 201, sha256: "0".repeat(64) })).rejects.toMatchObject({ code: "transfer_limit" });
309
- // An open transfer that goes quiet is closed and its file removed.
310
- const { transferId } = await client.request("transfer/open", { bytes: 100, sha256: "0".repeat(64) });
311
- expect(place.files()).toHaveLength(1);
312
- await new Promise(resolve => setTimeout(resolve, 120));
313
- expect(place.files()).toEqual([]);
314
- await expect(client.request("transfer/write", { transferId, offset: 0, data: "AAAA" })).rejects.toMatchObject({ code: "not_found" });
315
- // A transfer still open when the connection ends is removed with it.
316
- await client.request("transfer/open", { bytes: 100, sha256: "0".repeat(64) });
317
- expect(place.files()).toHaveLength(1);
318
- } finally { await harness.close(); }
319
- expect(place.files()).toEqual([]);
320
- });
321
-
322
- test("stdio: a transfer file left by a killed process is removed when the next process starts", async () => {
323
- const effects = join(mkdtempSync(join(root, "fx-")), "effects.log");
324
- const place = home("stdio", effects);
325
- const doomed = place.open() as ReturnType<typeof spawnHarness>;
326
- await doomed.client.initialize();
327
- const { transferId } = await doomed.client.request("transfer/open", { bytes: 100, sha256: "0".repeat(64) });
328
- await doomed.client.request("transfer/write", { transferId, offset: 0, data: "AAAA" });
329
- expect(place.files().filter(name => name.startsWith(".transfer-"))).toHaveLength(1);
330
- doomed.child.kill("SIGKILL"); await doomed.child.exited; doomed.client.close();
331
- expect(place.files().filter(name => name.startsWith(".transfer-"))).toHaveLength(1);
332
- const next = place.open();
333
- try {
334
- await next.client.initialize();
335
- expect(place.files().filter(name => name.startsWith(".transfer-"))).toEqual([]);
336
- } finally { await next.close(); }
337
- }, 15000);