nova-personal-agent-server 0.4.0 → 1.0.2

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 (327) hide show
  1. package/LICENSE +674 -201
  2. package/README.md +12 -2
  3. package/bin/nova-space-host.mjs +4 -0
  4. package/node_modules/@nova-personal-agent/relay/dist/src/cli.js +71 -0
  5. package/node_modules/@nova-personal-agent/relay/dist/src/client.js +340 -0
  6. package/node_modules/@nova-personal-agent/relay/dist/src/crypto.js +167 -0
  7. package/node_modules/@nova-personal-agent/relay/dist/src/live.js +169 -0
  8. package/node_modules/@nova-personal-agent/relay/dist/src/mailbox.js +217 -0
  9. package/node_modules/@nova-personal-agent/relay/dist/src/media.js +320 -0
  10. package/node_modules/@nova-personal-agent/relay/dist/src/pairing.js +13 -0
  11. package/node_modules/@nova-personal-agent/relay/dist/src/protocol.js +50 -0
  12. package/node_modules/@nova-personal-agent/relay/dist/src/security.js +305 -0
  13. package/node_modules/@nova-personal-agent/relay/dist/src/server.js +477 -0
  14. package/node_modules/@nova-personal-agent/relay/dist/src/source-address.js +58 -0
  15. package/node_modules/@nova-personal-agent/relay/package.json +1 -0
  16. package/package.json +13 -6
  17. package/runtime/dist/src/cascaded-text-provider.js +8 -3
  18. package/runtime/dist/src/composition/assembly.js +133 -35
  19. package/runtime/dist/src/composition/cascaded-realtime-assembly.js +114 -59
  20. package/runtime/dist/src/composition/production-composition.js +57 -21
  21. package/runtime/dist/src/composition/realtime-assembly.js +160 -52
  22. package/runtime/dist/src/composition/soul-context.js +22 -0
  23. package/runtime/dist/src/config/capability-registry.js +48 -3
  24. package/runtime/dist/src/config/cascaded-realtime-config.js +23 -10
  25. package/runtime/dist/src/config/config.js +541 -128
  26. package/runtime/dist/src/config/credential-rotation.js +26 -0
  27. package/runtime/dist/src/config/data-root.js +764 -0
  28. package/runtime/dist/src/config/diagnostics.js +3 -1
  29. package/runtime/dist/src/config/environment-contract.js +190 -188
  30. package/runtime/dist/src/config/model-routes.js +140 -0
  31. package/runtime/dist/src/config/voice-credentials.js +55 -0
  32. package/runtime/dist/src/connectors/composio/index.js +9 -0
  33. package/runtime/dist/src/connectors/feishu/index.js +258 -44
  34. package/runtime/dist/src/connectors/macos/mail.js +7 -3
  35. package/runtime/dist/src/connectors/macos/reader.js +3 -1
  36. package/runtime/dist/src/conversation-voice-provider.js +5 -2
  37. package/runtime/dist/src/core/causal-runtime.js +38 -3
  38. package/runtime/dist/src/core/context-view.js +7 -0
  39. package/runtime/dist/src/core/guards.js +32 -0
  40. package/runtime/dist/src/core/runtime.js +3 -0
  41. package/runtime/dist/src/core/schedule-tools.js +2 -2
  42. package/runtime/dist/src/core/source-processing-instructions.js +2 -2
  43. package/runtime/dist/src/core/source-processing-tools.js +3 -1
  44. package/runtime/dist/src/core/tool-schema.js +42 -7
  45. package/runtime/dist/src/desktop/desktop-camera.js +3 -5
  46. package/runtime/dist/src/desktop/desktop-control.js +41 -8
  47. package/runtime/dist/src/desktop/desktop-session.js +90 -19
  48. package/runtime/dist/src/desktop/desktop-wire.js +5 -7
  49. package/runtime/dist/src/desktop/startup-error.js +18 -16
  50. package/runtime/dist/src/desktop/workbench-acceptance.js +52 -14
  51. package/runtime/dist/src/desktop-entry.js +6 -2
  52. package/runtime/dist/src/desktop.js +5 -1
  53. package/runtime/dist/src/device/attempt.js +65 -0
  54. package/runtime/dist/src/device/authority.js +159 -0
  55. package/runtime/dist/src/device/gateway.js +87 -0
  56. package/runtime/dist/src/device/ledger.js +91 -0
  57. package/runtime/dist/src/device/ownership.js +92 -0
  58. package/runtime/dist/src/device/port.js +2 -0
  59. package/runtime/dist/src/device/schedule-ownership.js +103 -0
  60. package/runtime/dist/src/executors/acp/transport.js +2 -0
  61. package/runtime/dist/src/executors/browser.js +4 -3
  62. package/runtime/dist/src/executors/codex/adapter-project.js +58 -12
  63. package/runtime/dist/src/executors/codex/app-server-schema.js +12 -21
  64. package/runtime/dist/src/executors/codex/app-server-transport.js +32 -18
  65. package/runtime/dist/src/executors/codex/common.js +1 -1
  66. package/runtime/dist/src/executors/codex/contract.js +12 -16
  67. package/runtime/dist/src/executors/codex/credential-snapshot.js +1 -9
  68. package/runtime/dist/src/executors/codex/factory.js +54 -32
  69. package/runtime/dist/src/executors/codex/host-config.js +69 -20
  70. package/runtime/dist/src/executors/codex/launch-profile.js +3 -2
  71. package/runtime/dist/src/executors/codex/local-provider-credential.js +39 -0
  72. package/runtime/dist/src/executors/codex/process-owner.js +4 -6
  73. package/runtime/dist/src/executors/codex/production-host.js +33 -34
  74. package/runtime/dist/src/executors/codex/protocol.js +9 -14
  75. package/runtime/dist/src/executors/codex/session-title.js +6 -8
  76. package/runtime/dist/src/executors/codex/spawn-env.js +27 -6
  77. package/runtime/dist/src/executors/codex/turn-projection.js +12 -17
  78. package/runtime/dist/src/executors/codex/windows-guardian.js +4 -6
  79. package/runtime/dist/src/executors/coding/intake.js +12 -7
  80. package/runtime/dist/src/executors/computer-backend.js +18 -10
  81. package/runtime/dist/src/executors/computer-config.js +32 -0
  82. package/runtime/dist/src/executors/computer-device.js +68 -16
  83. package/runtime/dist/src/executors/computer-worker.js +18 -6
  84. package/runtime/dist/src/executors/computer.js +29 -56
  85. package/runtime/dist/src/executors/device-lock.js +14 -5
  86. package/runtime/dist/src/executors/gui-execution.js +2 -0
  87. package/runtime/dist/src/executors/index.js +0 -1
  88. package/runtime/dist/src/executors/mobile.js +9 -8
  89. package/runtime/dist/src/executors/native-process.js +4 -0
  90. package/runtime/dist/src/executors/search.js +3 -5
  91. package/runtime/dist/src/executors/task-resources.js +21 -0
  92. package/runtime/dist/src/executors/watcher.js +2 -4
  93. package/runtime/dist/src/experience/host.js +179 -0
  94. package/runtime/dist/src/index.js +2 -0
  95. package/runtime/dist/src/knowledge/assembly.js +3 -4
  96. package/runtime/dist/src/knowledge/embeddings.js +50 -34
  97. package/runtime/dist/src/knowledge/service.js +1 -0
  98. package/runtime/dist/src/knowledge/store-client.js +1 -6
  99. package/runtime/dist/src/knowledge/store-worker.js +1 -3
  100. package/runtime/dist/src/mem0/resource.js +25 -0
  101. package/runtime/dist/src/mem0/store-worker.js +234 -21
  102. package/runtime/dist/src/memory/consumer.js +31 -0
  103. package/runtime/dist/src/memory/engine-worker.js +210 -0
  104. package/runtime/dist/src/memory/entry.js +8 -1
  105. package/runtime/dist/src/memory/explicit-memory.js +20 -0
  106. package/runtime/dist/src/memory/factory.js +30 -15
  107. package/runtime/dist/src/memory/grounded-voicemem.js +10 -0
  108. package/runtime/dist/src/memory/ledger-recall-engine.js +86 -0
  109. package/runtime/dist/src/memory/prerecall-port.js +27 -0
  110. package/runtime/dist/src/memory/prerecall.js +1 -1
  111. package/runtime/dist/src/memory/production-engine.js +151 -0
  112. package/runtime/dist/src/memory/provenance.js +1 -0
  113. package/runtime/dist/src/memory/remote-personal-memory.js +3 -1
  114. package/runtime/dist/src/memory/retrieval.js +107 -22
  115. package/runtime/dist/src/memory/sensitivity.js +6 -2
  116. package/runtime/dist/src/memory/source-retrieval.js +11 -0
  117. package/runtime/dist/src/memory/tool-capabilities.js +46 -0
  118. package/runtime/dist/src/memory/voicemem-sdk/LICENSE +202 -0
  119. package/runtime/dist/src/memory/voicemem-sdk/NOTICE.md +97 -0
  120. package/runtime/dist/src/memory/voicemem-sdk/PATCH-NOTICE.md +23 -0
  121. package/runtime/dist/src/memory/voicemem-sdk/archive.js +12 -0
  122. package/runtime/dist/src/memory/voicemem-sdk/audio.js +111 -0
  123. package/runtime/dist/src/memory/voicemem-sdk/barge-in.js +59 -0
  124. package/runtime/dist/src/memory/voicemem-sdk/checkpoint.js +56 -0
  125. package/runtime/dist/src/memory/voicemem-sdk/cleanup.js +139 -0
  126. package/runtime/dist/src/memory/voicemem-sdk/dashscope-asr.js +254 -0
  127. package/runtime/dist/src/memory/voicemem-sdk/dashscope-tts.js +247 -0
  128. package/runtime/dist/src/memory/voicemem-sdk/evaluation.js +330 -0
  129. package/runtime/dist/src/memory/voicemem-sdk/extraction.js +220 -0
  130. package/runtime/dist/src/memory/voicemem-sdk/finetune-data.js +115 -0
  131. package/runtime/dist/src/memory/voicemem-sdk/finetune.js +170 -0
  132. package/runtime/dist/src/memory/voicemem-sdk/grounded-reply-preferences.js +81 -0
  133. package/runtime/dist/src/memory/voicemem-sdk/index.js +22 -0
  134. package/runtime/dist/src/memory/voicemem-sdk/local-embedding.js +164 -0
  135. package/runtime/dist/src/memory/voicemem-sdk/local-runtime.js +53 -0
  136. package/runtime/dist/src/memory/voicemem-sdk/local-speaker.js +240 -0
  137. package/runtime/dist/src/memory/voicemem-sdk/memory.js +767 -0
  138. package/runtime/dist/src/memory/voicemem-sdk/model-json.js +14 -0
  139. package/runtime/dist/src/memory/voicemem-sdk/personamem.js +209 -0
  140. package/runtime/dist/src/memory/voicemem-sdk/prompts/addenda.js +215 -0
  141. package/runtime/dist/src/memory/voicemem-sdk/prompts/additive-extraction.js +478 -0
  142. package/runtime/dist/src/memory/voicemem-sdk/prompts/index.js +32 -0
  143. package/runtime/dist/src/memory/voicemem-sdk/prompts/update-memory.js +152 -0
  144. package/runtime/dist/src/memory/voicemem-sdk/providers.js +325 -0
  145. package/runtime/dist/src/memory/voicemem-sdk/ranking.js +65 -0
  146. package/runtime/dist/src/memory/voicemem-sdk/reaction.js +33 -0
  147. package/runtime/dist/src/memory/voicemem-sdk/realtime.js +215 -0
  148. package/runtime/dist/src/memory/voicemem-sdk/reply.js +68 -0
  149. package/runtime/dist/src/memory/voicemem-sdk/routing.js +209 -0
  150. package/runtime/dist/src/memory/voicemem-sdk/slots.js +61 -0
  151. package/runtime/dist/src/memory/voicemem-sdk/speaker-bindings.js +120 -0
  152. package/runtime/dist/src/memory/voicemem-sdk/speaker-profiles.js +327 -0
  153. package/runtime/dist/src/memory/voicemem-sdk/store.js +577 -0
  154. package/runtime/dist/src/memory/voicemem-sdk/stream.js +317 -0
  155. package/runtime/dist/src/memory/voicemem-sdk/subgraph.js +113 -0
  156. package/runtime/dist/src/memory/voicemem-sdk/summaries.js +56 -0
  157. package/runtime/dist/src/memory/voicemem-sdk/time.js +157 -0
  158. package/runtime/dist/src/memory/voicemem-sdk/types.js +2 -0
  159. package/runtime/dist/src/memory-ledger/store-client.js +235 -37
  160. package/runtime/dist/src/memory-ledger/store-worker.js +8 -5
  161. package/runtime/dist/src/memory-ledger/store.js +91 -1
  162. package/runtime/dist/src/memory-substrate/consolidation.js +23 -7
  163. package/runtime/dist/src/memory-substrate/diary.js +27 -0
  164. package/runtime/dist/src/memory-substrate/engine-outbox.js +107 -0
  165. package/runtime/dist/src/memory-substrate/explicit-memory.js +112 -0
  166. package/runtime/dist/src/memory-substrate/fact-fidelity.js +68 -0
  167. package/runtime/dist/src/memory-substrate/feishu-consent.js +41 -0
  168. package/runtime/dist/src/memory-substrate/file-authority.js +29 -6
  169. package/runtime/dist/src/memory-substrate/life-operations.js +35 -9
  170. package/runtime/dist/src/memory-substrate/markdown-repository.js +271 -65
  171. package/runtime/dist/src/memory-substrate/memory-documents.js +96 -0
  172. package/runtime/dist/src/memory-substrate/migration.js +2 -0
  173. package/runtime/dist/src/memory-substrate/purge.js +12 -2
  174. package/runtime/dist/src/memory-substrate/resource.js +514 -129
  175. package/runtime/dist/src/memory-substrate/retrieval.js +8 -5
  176. package/runtime/dist/src/memory-substrate/source-operations.js +9 -1
  177. package/runtime/dist/src/memory-substrate/source-processing.js +436 -40
  178. package/runtime/dist/src/memory-substrate/source-retrieval.js +28 -0
  179. package/runtime/dist/src/memory-substrate/source-state.js +8 -0
  180. package/runtime/dist/src/memory-substrate/space-source-input.js +90 -0
  181. package/runtime/dist/src/memory-substrate/store.js +125 -23
  182. package/runtime/dist/src/model/goal-checkin-writer.js +72 -0
  183. package/runtime/dist/src/model/goal-writer.js +80 -0
  184. package/runtime/dist/src/model/jev-client.js +24 -13
  185. package/runtime/dist/src/model/model-adapters.js +2 -3
  186. package/runtime/dist/src/model/model-catalog.js +80 -0
  187. package/runtime/dist/src/model/model-gateway.js +47 -18
  188. package/runtime/dist/src/model/model-purpose.js +3 -4
  189. package/runtime/dist/src/model/personal-writer.js +536 -44
  190. package/runtime/dist/src/model/proactivity.js +50 -6
  191. package/runtime/dist/src/model/responses-model-gateway.js +59 -0
  192. package/runtime/dist/src/model/task-verifier.js +3 -3
  193. package/runtime/dist/src/model/timeline-anchors.js +77 -0
  194. package/runtime/dist/src/model/timeline-perspective.js +13 -0
  195. package/runtime/dist/src/model/timeline-selection.js +182 -0
  196. package/runtime/dist/src/model/understanding-writer.js +27 -0
  197. package/runtime/dist/src/model/vision-capability.js +3 -1
  198. package/runtime/dist/src/model/workbench-writer.js +96 -0
  199. package/runtime/dist/src/news/feeds.js +6 -10
  200. package/runtime/dist/src/news/interests.js +23 -0
  201. package/runtime/dist/src/news/service.js +87 -31
  202. package/runtime/dist/src/news/sources.json +116 -0
  203. package/runtime/dist/src/notifications/adapters/space-relay.js +4 -0
  204. package/runtime/dist/src/notifications/content.js +41 -0
  205. package/runtime/dist/src/notifications/contracts.js +4 -2
  206. package/runtime/dist/src/notifications/feed.js +6 -2
  207. package/runtime/dist/src/notifications/service.js +27 -14
  208. package/runtime/dist/src/notifications/store.js +3 -1
  209. package/runtime/dist/src/personal-agent/app-context.js +39 -4
  210. package/runtime/dist/src/personal-agent/chat-failure.js +37 -0
  211. package/runtime/dist/src/personal-agent/computer-use/contract.js +42 -0
  212. package/runtime/dist/src/personal-agent/computer-use/session.js +280 -0
  213. package/runtime/dist/src/personal-agent/computer-use/skill.js +18 -0
  214. package/runtime/dist/src/personal-agent/computer-use/tools.js +15 -0
  215. package/runtime/dist/src/personal-agent/context-candidates.js +9 -13
  216. package/runtime/dist/src/personal-agent/context-dependencies.js +28 -0
  217. package/runtime/dist/src/personal-agent/contracts.js +24 -4
  218. package/runtime/dist/src/personal-agent/conversation-runtime.js +440 -42
  219. package/runtime/dist/src/personal-agent/conversation-tool-bridge.js +97 -0
  220. package/runtime/dist/src/personal-agent/conversation-tool-policy.js +22 -0
  221. package/runtime/dist/src/personal-agent/conversations.js +71 -15
  222. package/runtime/dist/src/personal-agent/daily-brief.js +5 -0
  223. package/runtime/dist/src/personal-agent/daily-workbench.js +558 -0
  224. package/runtime/dist/src/personal-agent/discovery-window.js +36 -0
  225. package/runtime/dist/src/personal-agent/goal-checkin.js +53 -0
  226. package/runtime/dist/src/personal-agent/host.js +2379 -223
  227. package/runtime/dist/src/personal-agent/identity-context.js +33 -0
  228. package/runtime/dist/src/personal-agent/life.js +129 -11
  229. package/runtime/dist/src/personal-agent/local-shell.js +181 -0
  230. package/runtime/dist/src/personal-agent/local-tools.js +234 -0
  231. package/runtime/dist/src/personal-agent/preferred-name-sync.js +35 -0
  232. package/runtime/dist/src/personal-agent/profile-warmup.js +100 -39
  233. package/runtime/dist/src/personal-agent/project-digests.js +7 -3
  234. package/runtime/dist/src/personal-agent/project-history.js +36 -0
  235. package/runtime/dist/src/personal-agent/reading-copies.js +183 -0
  236. package/runtime/dist/src/personal-agent/scheduled-tasks.js +50 -13
  237. package/runtime/dist/src/personal-agent/scheduled-tool-runtime.js +26 -10
  238. package/runtime/dist/src/personal-agent/source-processing-agent.js +239 -17
  239. package/runtime/dist/src/personal-agent/sources.js +9 -1
  240. package/runtime/dist/src/personal-agent/store.js +124 -14
  241. package/runtime/dist/src/personal-agent/task-loop.js +3 -0
  242. package/runtime/dist/src/personal-agent/tasks.js +16 -4
  243. package/runtime/dist/src/personal-agent/timeline-brief.js +462 -0
  244. package/runtime/dist/src/personal-agent/timeline-cache.js +191 -0
  245. package/runtime/dist/src/personal-agent/timeline-cluster.js +30 -0
  246. package/runtime/dist/src/personal-agent/timeline-inputs.js +47 -0
  247. package/runtime/dist/src/personal-agent/timeline-time.js +60 -0
  248. package/runtime/dist/src/personal-agent/understanding-products.js +49 -0
  249. package/runtime/dist/src/personal-agent/understanding.js +7 -22
  250. package/runtime/dist/src/personal-agent/workbench-context.js +17 -21
  251. package/runtime/dist/src/personal-agent/workbench-copy.js +124 -0
  252. package/runtime/dist/src/personal-agent/workbench-evidence.js +77 -0
  253. package/runtime/dist/src/personal-agent/workbench-instructions.js +21 -0
  254. package/runtime/dist/src/personal-agent/workbench-runtime.js +1006 -0
  255. package/runtime/dist/src/personal-agent/workbench-shell-class.js +304 -0
  256. package/runtime/dist/src/personal-agent/workbench-store.js +292 -0
  257. package/runtime/dist/src/personal-agent/workbench-temporal.js +66 -0
  258. package/runtime/dist/src/projects/project-native-resource.js +10 -8
  259. package/runtime/dist/src/projects/project-store.js +36 -4
  260. package/runtime/dist/src/realtime/bridge.js +77 -8
  261. package/runtime/dist/src/realtime/capabilities.js +19 -0
  262. package/runtime/dist/src/realtime/cascaded/adapter.js +180 -40
  263. package/runtime/dist/src/realtime/cascaded/ark-llm.js +150 -24
  264. package/runtime/dist/src/realtime/cascaded/chat-completions-llm.js +243 -83
  265. package/runtime/dist/src/realtime/cascaded/llm-stream-limits.js +18 -0
  266. package/runtime/dist/src/realtime/cascaded/llm.js +96 -0
  267. package/runtime/dist/src/realtime/cascaded/openai-compatible-speech.js +251 -0
  268. package/runtime/dist/src/realtime/cascaded/provider.js +8 -0
  269. package/runtime/dist/src/realtime/evidence.js +1 -1
  270. package/runtime/dist/src/realtime/frontend-instructions.js +76 -55
  271. package/runtime/dist/src/realtime/gemini.js +14 -3
  272. package/runtime/dist/src/realtime/host-delivery.js +37 -4
  273. package/runtime/dist/src/realtime/protocol.js +18 -3
  274. package/runtime/dist/src/realtime/provider-projection.js +4 -1
  275. package/runtime/dist/src/realtime/provider-session.js +73 -16
  276. package/runtime/dist/src/realtime/qwen-transport.js +35 -4
  277. package/runtime/dist/src/realtime/qwen.js +144 -9
  278. package/runtime/dist/src/realtime/service-state.js +0 -1
  279. package/runtime/dist/src/realtime/service.js +93 -7
  280. package/runtime/dist/src/realtime/session.js +39 -32
  281. package/runtime/dist/src/realtime/sglang-native.js +214 -0
  282. package/runtime/dist/src/realtime/system-prompts.en.js +14 -2
  283. package/runtime/dist/src/realtime/telemetry.js +6 -3
  284. package/runtime/dist/src/realtime/tool-continuations.js +84 -7
  285. package/runtime/dist/src/realtime/transport.js +17 -0
  286. package/runtime/dist/src/realtime/usage.js +33 -17
  287. package/runtime/dist/src/realtime/volcengine/ark.js +40 -15
  288. package/runtime/dist/src/realtime/volcengine/asr.js +2 -1
  289. package/runtime/dist/src/realtime/volcengine/silence-endpointing.js +1 -7
  290. package/runtime/dist/src/realtime/volcengine/tts.js +2 -1
  291. package/runtime/dist/src/server/aoq-chat-server.js +1 -1
  292. package/runtime/dist/src/server/client-server.js +21 -0
  293. package/runtime/dist/src/server-entry.js +3 -0
  294. package/runtime/dist/src/space-host/admin-socket.js +115 -0
  295. package/runtime/dist/src/space-host/audio-owner.js +44 -0
  296. package/runtime/dist/src/space-host/cli.js +195 -0
  297. package/runtime/dist/src/space-host/config.js +247 -0
  298. package/runtime/dist/src/space-host/context-input.js +12 -0
  299. package/runtime/dist/src/space-host/contracts.js +10 -0
  300. package/runtime/dist/src/space-host/host-admin.js +114 -0
  301. package/runtime/dist/src/space-host/key-delivery.js +28 -0
  302. package/runtime/dist/src/space-host/mobile-tools.js +9 -0
  303. package/runtime/dist/src/space-host/model-settings.js +213 -0
  304. package/runtime/dist/src/space-host/projection.js +37 -0
  305. package/runtime/dist/src/space-host/push.js +137 -0
  306. package/runtime/dist/src/space-host/relay-transport.js +55 -0
  307. package/runtime/dist/src/space-host/service.js +841 -0
  308. package/runtime/dist/src/space-host/voice-crypto.js +240 -0
  309. package/runtime/dist/src/space-host/voice.js +600 -0
  310. package/runtime/dist/src/space-host/windows-secret-key.js +82 -0
  311. package/runtime/dist/src/storage/private-database.js +7 -10
  312. package/runtime/dist/src/text/unicode-normalize.js +5 -1
  313. package/runtime/dist/src/understanding/candidates.js +8 -10
  314. package/runtime/dist/src/understanding/fixture.js +1 -1
  315. package/runtime/dist/src/understanding/pipeline.js +4 -4
  316. package/runtime/dist/src/usage/context.js +23 -0
  317. package/runtime/dist/src/usage/index.js +4 -0
  318. package/runtime/dist/src/usage/ledger-worker.js +90 -0
  319. package/runtime/dist/src/usage/ledger.js +74 -0
  320. package/runtime/dist/src/usage/model-call.js +63 -0
  321. package/runtime/dist/src/usage/pricing.js +68 -0
  322. package/runtime/dist/src/usage/summary.js +69 -0
  323. package/runtime/dist/src/voicemem/store-client.js +104 -21
  324. package/runtime/dist/src/voicemem/store-worker.js +5 -8
  325. package/runtime/dist/src/voicemem/versioned-memory.js +1 -1
  326. package/src/command.mjs +8 -1
  327. package/runtime/dist/src/executors/autoglm.js +0 -376
@@ -0,0 +1,159 @@
1
+ export class AuthorityError extends Error {
2
+ code;
3
+ constructor(code) {
4
+ super(code);
5
+ this.code = code;
6
+ }
7
+ }
8
+ function fail(code) { throw new AuthorityError(code); }
9
+ const integer = (n) => {
10
+ if (!Number.isSafeInteger(n) || n < 0)
11
+ fail('stale_fence');
12
+ };
13
+ const nonempty = (s) => {
14
+ if (typeof s !== 'string' || s.length === 0)
15
+ fail('stale_fence');
16
+ };
17
+ const numbers = ['todo_version', 'goal_revision', 'control_revision', 'lifecycle_generation',
18
+ 'capability_revision', 'conversation_generation', 'data_version', 'observation_version', 'expires_at'];
19
+ const strings = ['task_id', 'owner', 'effect_class', 'proposal_digest', 'executable_digest'];
20
+ const fenceKeys = ['todo_version', 'goal_revision', 'control_revision', 'lifecycle_generation', 'capability_revision'];
21
+ function validate(b) {
22
+ for (const key of numbers)
23
+ integer(b[key]);
24
+ for (const key of strings)
25
+ nonempty(b[key]);
26
+ if (!Array.isArray(b.permission_scope) || b.permission_scope.length === 0)
27
+ fail('permission_denied');
28
+ for (const scope of b.permission_scope)
29
+ nonempty(scope);
30
+ }
31
+ function same(a, b) {
32
+ return numbers.every(k => a[k] === b[k]) && strings.every(k => a[k] === b[k])
33
+ && a.permission_scope.length === b.permission_scope.length
34
+ && a.permission_scope.every((scope, i) => scope === b.permission_scope[i]);
35
+ }
36
+ function copy(b) { return { ...b, permission_scope: [...b.permission_scope] }; }
37
+ export class Authority {
38
+ state;
39
+ clock;
40
+ constructor(state, clock) {
41
+ this.state = state;
42
+ this.clock = clock;
43
+ }
44
+ createGrant(grantRef, bindings) {
45
+ nonempty(grantRef);
46
+ validate(bindings);
47
+ if (this.state.grants.some(g => g.grant_ref === grantRef))
48
+ fail('request_conflict');
49
+ const task = this.state.tasks.find(t => t.bindings.task_id === bindings.task_id);
50
+ if (!task || !same(task.bindings, bindings)
51
+ || bindings.lifecycle_generation !== this.state.lifecycle_generation)
52
+ fail('stale_fence');
53
+ if (task.stopped)
54
+ fail('approval_revoked');
55
+ this.state.grants.push({ grant_ref: grantRef, status: 'pending', bindings: copy(bindings), consumed: false });
56
+ }
57
+ grant(ref) {
58
+ return this.state.grants.find(g => g.grant_ref === ref) ?? fail('approval_required');
59
+ }
60
+ recheck(grant) {
61
+ const task = this.state.tasks.find(t => t.bindings.task_id === grant.bindings.task_id);
62
+ if (!task) {
63
+ grant.status = 'expired';
64
+ fail('stale_fence');
65
+ }
66
+ if (task.stopped) {
67
+ grant.status = 'revoked';
68
+ fail('approval_revoked');
69
+ }
70
+ if (!grant.bindings.permission_scope.every(scope => task.permissions.includes(scope))) {
71
+ grant.status = 'revoked';
72
+ fail('permission_denied');
73
+ }
74
+ validate(task.bindings);
75
+ integer(this.state.lifecycle_generation);
76
+ const now = this.clock.now();
77
+ integer(now);
78
+ if (grant.status !== 'revoked' && (now >= grant.bindings.expires_at
79
+ || !same(grant.bindings, task.bindings)
80
+ || grant.bindings.lifecycle_generation !== this.state.lifecycle_generation)) {
81
+ grant.status = 'expired';
82
+ fail(now >= grant.bindings.expires_at ? 'approval_expired' : 'stale_fence');
83
+ }
84
+ if (grant.status === 'revoked')
85
+ fail('approval_revoked');
86
+ if (grant.status === 'expired')
87
+ fail('approval_expired');
88
+ }
89
+ approveGrant(grantRef) {
90
+ const grant = this.grant(grantRef);
91
+ this.recheck(grant);
92
+ if (grant.consumed || grant.status === 'consumed')
93
+ fail('approval_consumed');
94
+ if (grant.status !== 'pending')
95
+ fail('approval_required');
96
+ grant.status = 'approved';
97
+ }
98
+ authorizeDispatch(request) {
99
+ nonempty(request.operation_id);
100
+ nonempty(request.grant_ref);
101
+ nonempty(request.kind);
102
+ validate(request.bindings);
103
+ const previous = this.state.receipts.find(r => r.request.operation_id === request.operation_id);
104
+ if (previous) {
105
+ if (previous.request.grant_ref !== request.grant_ref || previous.request.kind !== request.kind
106
+ || !same(previous.request.bindings, request.bindings))
107
+ fail('request_conflict');
108
+ // Replay is evidence only, never permission to call the external service again.
109
+ return { intent: previous.intent, replayed: true };
110
+ }
111
+ const grant = this.grant(request.grant_ref);
112
+ this.recheck(grant);
113
+ if (!same(grant.bindings, request.bindings))
114
+ fail('stale_fence');
115
+ if (!grant.bindings.permission_scope.includes(request.kind))
116
+ fail('permission_denied');
117
+ if (grant.consumed || grant.status === 'consumed')
118
+ fail('approval_consumed');
119
+ if (grant.status !== 'approved')
120
+ fail('approval_required');
121
+ const receipt = { request: { ...request, bindings: copy(request.bindings) }, intent: 'prepared' };
122
+ this.state.receipts.push(receipt);
123
+ grant.consumed = true;
124
+ grant.status = 'consumed';
125
+ return { intent: receipt.intent, replayed: false };
126
+ }
127
+ revokeForStop(taskId) {
128
+ const task = this.state.tasks.find(t => t.bindings.task_id === taskId);
129
+ if (!task)
130
+ fail('stale_fence');
131
+ if (!task.stopped) {
132
+ integer(task.bindings.control_revision + 1);
133
+ task.bindings.control_revision++;
134
+ task.stopped = true;
135
+ }
136
+ for (const grant of this.state.grants) {
137
+ if (grant.bindings.task_id === taskId)
138
+ grant.status = 'revoked';
139
+ }
140
+ }
141
+ bumpLifecycleGeneration() {
142
+ integer(this.state.lifecycle_generation + 1);
143
+ this.state.lifecycle_generation++;
144
+ for (const task of this.state.tasks)
145
+ task.bindings.lifecycle_generation = this.state.lifecycle_generation;
146
+ for (const grant of this.state.grants) {
147
+ if (grant.status !== 'revoked')
148
+ grant.status = 'expired';
149
+ }
150
+ return this.state.lifecycle_generation;
151
+ }
152
+ classifyReply(fence) {
153
+ const task = this.state.tasks.find(t => t.bindings.task_id === fence.task_id);
154
+ const late = !task || task.stopped || fence.lifecycle_generation !== this.state.lifecycle_generation
155
+ || fenceKeys.some(k => !Number.isSafeInteger(fence[k]) || fence[k] < 0 || fence[k] !== task.bindings[k]);
156
+ return { late };
157
+ }
158
+ }
159
+ //# sourceMappingURL=authority.js.map
@@ -0,0 +1,87 @@
1
+ import { Authority } from './authority.js';
2
+ import { advanceAttempt } from './attempt.js';
3
+ import { recordReceipt } from './ownership.js';
4
+ export class DeviceGateway {
5
+ ledger;
6
+ clock;
7
+ unpersistedStops = new Set();
8
+ constructor(ledger, clock = { now: () => Date.now() }) {
9
+ this.ledger = ledger;
10
+ this.clock = clock;
11
+ }
12
+ drainStops(state) {
13
+ const authority = new Authority(state.authority, this.clock);
14
+ for (const taskId of new Set([...state.pending_stops, ...this.unpersistedStops])) {
15
+ if (state.authority.tasks.some(task => task.bindings.task_id === taskId))
16
+ authority.revokeForStop(taskId);
17
+ }
18
+ // Retain stop tombstones, including tasks not yet registered.
19
+ state.pending_stops = [...new Set([...state.pending_stops, ...this.unpersistedStops])];
20
+ }
21
+ async change(action) {
22
+ // Commit recovery separately so a rejected request cannot roll back pending revocations.
23
+ await this.ledger.transaction(state => this.drainStops(state));
24
+ return this.ledger.transaction(state => {
25
+ this.drainStops(state);
26
+ return action(state, new Authority(state.authority, this.clock));
27
+ });
28
+ }
29
+ createGrant(grantRef, bindings) {
30
+ return this.change((state, authority) => {
31
+ if (state.pending_stops.includes(bindings.task_id))
32
+ throw Error('approval_revoked');
33
+ authority.createGrant(grantRef, bindings);
34
+ });
35
+ }
36
+ approveGrant(grantRef) {
37
+ return this.change((_state, authority) => authority.approveGrant(grantRef));
38
+ }
39
+ authorizeDispatch(request) {
40
+ return this.change((state, authority) => {
41
+ const result = authority.authorizeDispatch(request);
42
+ if (!result.replayed) {
43
+ const prepared = advanceAttempt({
44
+ task_phase: 'queued', attempt: { id: request.operation_id, status: 'none', dispatch_started: false },
45
+ effects: 0, evidence: [], action_grant_ref: request.grant_ref,
46
+ }, { op: 'persist_intent' });
47
+ state.attempts.push({ operation_id: request.operation_id,
48
+ state: advanceAttempt(prepared, { op: 'mark_dispatch_started' }) });
49
+ }
50
+ return result;
51
+ });
52
+ }
53
+ recordReceipt(operationId, identity, payloadDigest, receipt) {
54
+ return this.change((state) => {
55
+ const attempt = state.attempts.find(item => item.operation_id === operationId);
56
+ if (!attempt)
57
+ throw Error('stale_fence');
58
+ const recorded = recordReceipt(state.ownership, identity, payloadDigest, receipt);
59
+ if (recorded.replayed && attempt.receipt_key !== recorded.receipt.request_key)
60
+ throw Error('request_conflict');
61
+ if (!recorded.replayed)
62
+ attempt.state = advanceAttempt(attempt.state, { op: 'accept' });
63
+ attempt.receipt_key = recorded.receipt.request_key;
64
+ state.ownership = recorded.state;
65
+ return { receipt: recorded.receipt, replayed: recorded.replayed };
66
+ });
67
+ }
68
+ classifyReply(fence) {
69
+ return this.change((_state, authority) => authority.classifyReply(fence));
70
+ }
71
+ async revokeForStop(taskId) {
72
+ if (!taskId)
73
+ throw Error('stale_fence');
74
+ // If the disk is unavailable, retain the stop in memory and fail closed on the next call.
75
+ this.unpersistedStops.add(taskId);
76
+ await this.ledger.transaction(state => {
77
+ if (!state.pending_stops.includes(taskId))
78
+ state.pending_stops.push(taskId);
79
+ });
80
+ await this.ledger.transaction(state => this.drainStops(state));
81
+ this.unpersistedStops.delete(taskId);
82
+ }
83
+ bumpLifecycleGeneration() {
84
+ return this.change((_state, authority) => authority.bumpLifecycleGeneration());
85
+ }
86
+ }
87
+ //# sourceMappingURL=gateway.js.map
@@ -0,0 +1,91 @@
1
+ import { z } from 'zod';
2
+ import { BoundedJsonStore } from '../storage/bounded-json.js';
3
+ import { advanceAttempt } from './attempt.js';
4
+ const integer = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
5
+ const text = z.string().min(1);
6
+ const phase = z.enum(['queued', 'running', 'verifying', 'waiting', 'completed', 'cancelled', 'failed']);
7
+ const bindings = z.object({
8
+ task_id: text, owner: text, todo_version: integer, goal_revision: integer, control_revision: integer,
9
+ lifecycle_generation: integer, capability_revision: integer, conversation_generation: integer,
10
+ data_version: integer, observation_version: integer, permission_scope: z.array(text).min(1),
11
+ effect_class: text, proposal_digest: text, executable_digest: text, expires_at: integer,
12
+ });
13
+ const attemptSchema = z.object({
14
+ task_phase: phase,
15
+ attempt: z.object({
16
+ id: text, status: z.enum(['none', 'prepared', 'dispatching', 'accepted', 'failed', 'unknown-effect']),
17
+ dispatch_started: z.boolean(),
18
+ }),
19
+ effects: integer, evidence: z.array(text), action_grant_ref: text,
20
+ consumed_verification_grants: z.array(text).default([]),
21
+ });
22
+ export const deviceStateSchema = z.object({
23
+ authority: z.object({
24
+ lifecycle_generation: integer,
25
+ tasks: z.array(z.object({ bindings, permissions: z.array(text), stopped: z.boolean() })),
26
+ grants: z.array(z.object({
27
+ grant_ref: text, status: z.enum(['pending', 'approved', 'consumed', 'expired', 'revoked']),
28
+ bindings, consumed: z.boolean(),
29
+ })),
30
+ receipts: z.array(z.object({
31
+ request: z.object({ grant_ref: text, operation_id: text, kind: text, bindings }),
32
+ intent: z.literal('prepared'),
33
+ })),
34
+ }),
35
+ ownership: z.object({
36
+ capacity: integer,
37
+ receipts: z.array(z.object({ id: text, request_key: text, payload_digest: text, status: text })),
38
+ }),
39
+ attempts: z.array(z.object({
40
+ operation_id: text, receipt_key: text.optional(),
41
+ state: attemptSchema,
42
+ })),
43
+ pending_stops: z.array(text),
44
+ });
45
+ export function emptyDeviceState() {
46
+ return { authority: { lifecycle_generation: 0, tasks: [], grants: [], receipts: [] },
47
+ ownership: { capacity: 10000, receipts: [] }, attempts: [], pending_stops: [] };
48
+ }
49
+ /** One ledger per path; caller holds the host process lock, as with LifeService. */
50
+ export class DeviceLedger {
51
+ store;
52
+ state;
53
+ tail = Promise.resolve();
54
+ initial;
55
+ constructor(path, options = {}) {
56
+ this.store = new BoundedJsonStore(path, deviceStateSchema, options.limit);
57
+ this.initial = deviceStateSchema.parse(options.initialState ?? emptyDeviceState());
58
+ }
59
+ async load() {
60
+ if (this.state)
61
+ return this.state;
62
+ const loaded = await this.store.read(this.initial);
63
+ const recovered = structuredClone(loaded);
64
+ for (const attempt of recovered.attempts) {
65
+ attempt.state = advanceAttempt(attempt.state, { op: 'restart' });
66
+ }
67
+ if (JSON.stringify(recovered) !== JSON.stringify(loaded))
68
+ await this.store.write(recovered);
69
+ this.state = recovered;
70
+ return recovered;
71
+ }
72
+ serialize(action) {
73
+ const run = this.tail.then(action);
74
+ this.tail = run.catch(() => { });
75
+ return run;
76
+ }
77
+ snapshot() {
78
+ return this.serialize(async () => structuredClone(await this.load()));
79
+ }
80
+ transaction(change) {
81
+ return this.serialize(async () => {
82
+ const next = structuredClone(await this.load());
83
+ const result = change(next);
84
+ const validated = deviceStateSchema.parse(next);
85
+ await this.store.write(validated);
86
+ this.state = validated;
87
+ return structuredClone(result);
88
+ });
89
+ }
90
+ }
91
+ //# sourceMappingURL=ledger.js.map
@@ -0,0 +1,92 @@
1
+ // Rejections throw OwnershipError with a device-contract glossary code; functions never mutate inputs.
2
+ export class OwnershipError extends Error {
3
+ code;
4
+ constructor(code) {
5
+ super(code);
6
+ this.code = code;
7
+ }
8
+ }
9
+ function nonempty(value) { return typeof value === 'string' && value.length > 0; }
10
+ function int53(value) { return Number.isSafeInteger(value) && value >= 0; }
11
+ export function encodeIdentity(identity) {
12
+ const values = [identity.principal, identity.device_id, identity.request_id];
13
+ if (!values.every(nonempty))
14
+ throw new OwnershipError('request_conflict');
15
+ return JSON.stringify(values);
16
+ }
17
+ export function decodeIdentity(key) {
18
+ let values;
19
+ try {
20
+ values = JSON.parse(key);
21
+ }
22
+ catch {
23
+ throw new OwnershipError('request_conflict');
24
+ }
25
+ if (!Array.isArray(values) || values.length !== 3 || !values.every(nonempty))
26
+ throw new OwnershipError('request_conflict');
27
+ const identity = { principal: values[0], device_id: values[1], request_id: values[2] };
28
+ if (encodeIdentity(identity) !== key)
29
+ throw new OwnershipError('request_conflict');
30
+ return identity;
31
+ }
32
+ // Hash these canonical bytes at the host boundary; digests are supplied, not generated here.
33
+ export function canonicalPayload(value) {
34
+ const ancestors = new Set();
35
+ const encode = (item) => {
36
+ if (item === null || typeof item === 'string' || typeof item === 'boolean')
37
+ return JSON.stringify(item);
38
+ if (typeof item === 'number' && Number.isSafeInteger(item))
39
+ return JSON.stringify(item);
40
+ if (typeof item !== 'object' || item === null || ancestors.has(item))
41
+ throw new OwnershipError('request_conflict');
42
+ ancestors.add(item);
43
+ try {
44
+ if (Array.isArray(item))
45
+ return '[' + Array.from(item, encode).join(',') + ']';
46
+ if (Object.getPrototypeOf(item) !== Object.prototype || Object.getOwnPropertySymbols(item).length)
47
+ throw new OwnershipError('request_conflict');
48
+ const record = item;
49
+ return '{' + Object.keys(record).sort().map(key => JSON.stringify(key) + ':' + encode(record[key])).join(',') + '}';
50
+ }
51
+ finally {
52
+ ancestors.delete(item);
53
+ }
54
+ };
55
+ try {
56
+ return encode(value);
57
+ }
58
+ catch {
59
+ throw new OwnershipError('request_conflict');
60
+ }
61
+ }
62
+ export function expireLease(state) { return { ...state, lease_expired: true }; }
63
+ export function requireOwner(state, deviceId) {
64
+ if (!nonempty(deviceId) || state.owner !== deviceId)
65
+ throw new OwnershipError('owner_mismatch');
66
+ }
67
+ export function processInput(state, deviceId, generation, contextVersion) {
68
+ if (!nonempty(deviceId) || state.owner !== deviceId)
69
+ throw new OwnershipError('owner_mismatch');
70
+ if (!int53(generation) || !int53(contextVersion) || state.generation !== generation
71
+ || state.context_version !== contextVersion || contextVersion === Number.MAX_SAFE_INTEGER)
72
+ throw new OwnershipError('stale_fence');
73
+ return { ...state, context_version: contextVersion + 1 };
74
+ }
75
+ export function recordReceipt(state, identity, payloadDigest, receipt) {
76
+ const key = encodeIdentity(identity);
77
+ if (!int53(state.capacity))
78
+ throw new OwnershipError('dedup_capacity');
79
+ if (!nonempty(payloadDigest) || !nonempty(receipt.id) || !nonempty(receipt.status))
80
+ throw new OwnershipError('request_conflict');
81
+ const existing = state.receipts.find(item => item.request_key === key);
82
+ if (existing) {
83
+ if (existing.payload_digest !== payloadDigest)
84
+ throw new OwnershipError('request_conflict');
85
+ return { state, receipt: existing, replayed: true };
86
+ }
87
+ if (state.receipts.length >= state.capacity)
88
+ throw new OwnershipError('dedup_capacity');
89
+ const recorded = { ...receipt, request_key: key, payload_digest: payloadDigest };
90
+ return { state: { ...state, receipts: [...state.receipts, recorded] }, receipt: recorded, replayed: false };
91
+ }
92
+ //# sourceMappingURL=ownership.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=port.js.map
@@ -0,0 +1,103 @@
1
+ import { z } from 'zod';
2
+ import { scheduleInputSchema, scheduleHash } from '../personal-agent/scheduled-tasks.js';
3
+ const spaceId = z.string().min(1).max(200).regex(/^[A-Za-z0-9_-]+$/), instant = z.string().datetime();
4
+ const claimSchema = z.object({ run_id: spaceId, slot_key: z.string().min(1).max(512), scheduled_at: instant, status: z.enum(['reserved', 'running', 'terminal']), task_id: z.string().nullable() }).strict();
5
+ export const scheduleClaimsSchema = z.object({ id: spaceId, owner_device_id: spaceId, enabled: z.boolean().default(true), definition: scheduleInputSchema, frontier: instant, claims: z.record(z.string(), claimSchema) }).strict();
6
+ const ownerSchema = scheduleClaimsSchema;
7
+ /** Durable occurrence reservations belong to the fixed Host; presence never changes ownership. */
8
+ export class ScheduleOwnership {
9
+ db;
10
+ authenticate;
11
+ requireHost;
12
+ constructor(db, authenticate, requireHost) {
13
+ this.db = db;
14
+ this.authenticate = authenticate;
15
+ this.requireHost = requireHost;
16
+ db.exec('CREATE TABLE IF NOT EXISTS schedule_claims(account_id TEXT NOT NULL,id TEXT NOT NULL,value TEXT NOT NULL,PRIMARY KEY(account_id,id))');
17
+ }
18
+ tx(fn) { this.db.exec('BEGIN IMMEDIATE'); try {
19
+ const value = fn();
20
+ this.db.exec('COMMIT');
21
+ return value;
22
+ }
23
+ catch (e) {
24
+ this.db.exec('ROLLBACK');
25
+ throw e;
26
+ } }
27
+ get(account, id) { const row = this.db.prepare('SELECT value FROM schedule_claims WHERE account_id=? AND id=?').get(account, id); if (!row)
28
+ throw Error('shared_schedule_missing'); return ownerSchema.parse(JSON.parse(String(row.value))); }
29
+ save(account, value) { if (Object.keys(value.claims).length > 4096)
30
+ throw Error('schedule_capacity'); this.db.prepare('INSERT INTO schedule_claims VALUES(?,?,?) ON CONFLICT(account_id,id) DO UPDATE SET value=excluded.value').run(account, value.id, JSON.stringify(ownerSchema.parse(value))); return value; }
31
+ list(token) { const device = this.authenticate(token); return this.db.prepare('SELECT value FROM schedule_claims WHERE account_id=?').all(device.account_id).map(r => ownerSchema.parse(JSON.parse(String(r.value)))); }
32
+ register(token, raw) {
33
+ const q = z.object({ id: spaceId, definition: scheduleInputSchema, frontier: instant }).strict().parse(raw);
34
+ return this.tx(() => {
35
+ const device = this.authenticate(token);
36
+ this.requireHost(token);
37
+ const existing = this.list(token).find(v => v.id === q.id);
38
+ if (existing) {
39
+ if (existing.owner_device_id !== device.device_id || scheduleHash(existing.definition) !== scheduleHash(q.definition))
40
+ throw Error('shared_schedule_conflict');
41
+ return existing;
42
+ }
43
+ if (this.list(token).length >= 64)
44
+ throw Error('schedule_capacity');
45
+ return this.save(device.account_id, { id: q.id, owner_device_id: device.device_id, enabled: true, definition: q.definition, frontier: q.frontier, claims: {} });
46
+ });
47
+ }
48
+ claim(token, raw) {
49
+ const q = z.object({ id: spaceId, run_id: spaceId, slot_key: z.string().min(1).max(512), scheduled_at: instant }).strict().parse(raw);
50
+ return this.tx(() => {
51
+ const device = this.authenticate(token), item = this.get(device.account_id, q.id);
52
+ this.requireHost(token);
53
+ if (!item.enabled)
54
+ throw Error('schedule_disabled');
55
+ const prior = item.claims[q.run_id];
56
+ if (prior) {
57
+ if (prior.slot_key !== q.slot_key || prior.scheduled_at !== q.scheduled_at)
58
+ throw Error('occurrence_conflict');
59
+ return prior;
60
+ }
61
+ if (Object.values(item.claims).some(v => v.slot_key === q.slot_key))
62
+ throw Error('occurrence_conflict');
63
+ if (Object.values(item.claims).some(v => v.status !== 'terminal'))
64
+ throw Error('schedule_unresolved');
65
+ if (Date.parse(q.scheduled_at) <= Date.parse(item.frontier))
66
+ throw Error('stale_schedule_frontier');
67
+ const claim = { run_id: q.run_id, slot_key: q.slot_key, scheduled_at: q.scheduled_at, status: 'reserved', task_id: null };
68
+ item.claims[q.run_id] = claim;
69
+ item.frontier = q.scheduled_at;
70
+ this.save(device.account_id, item);
71
+ return claim;
72
+ });
73
+ }
74
+ checkpoint(token, raw) {
75
+ const q = z.object({ id: spaceId, run_id: spaceId, task_id: z.string().min(1).max(512), terminal: z.boolean() }).strict().parse(raw);
76
+ return this.tx(() => {
77
+ const device = this.authenticate(token), item = this.get(device.account_id, q.id);
78
+ this.requireHost(token);
79
+ const claim = item.claims[q.run_id];
80
+ if (!claim)
81
+ throw Error('occurrence_missing');
82
+ if (claim.task_id && claim.task_id !== q.task_id)
83
+ throw Error('occurrence_conflict');
84
+ if (claim.status === 'terminal' && !q.terminal)
85
+ throw Error('occurrence_terminal');
86
+ claim.task_id = q.task_id;
87
+ claim.status = q.terminal ? 'terminal' : 'running';
88
+ this.save(device.account_id, item);
89
+ return claim;
90
+ });
91
+ }
92
+ control(token, raw) {
93
+ const q = z.object({ id: spaceId, enabled: z.boolean() }).strict().parse(raw);
94
+ return this.tx(() => {
95
+ const device = this.authenticate(token), item = this.get(device.account_id, q.id);
96
+ this.requireHost(token);
97
+ item.enabled = q.enabled;
98
+ // Do not invalidate an already dispatched run: pausing governs new claims.
99
+ return this.save(device.account_id, item);
100
+ });
101
+ }
102
+ }
103
+ //# sourceMappingURL=schedule-ownership.js.map
@@ -195,6 +195,7 @@ export class AcpTransport {
195
195
  }
196
196
  }
197
197
  async run(input, observer, deadline, completionDeadline) {
198
+ input = { ...input, workOrder: approvedPlanWorkOrder(input) };
198
199
  if (this.#running)
199
200
  return { classification: 'refused', code: 'busy', turnStartWritten: false, completion: null };
200
201
  this.#running = true;
@@ -757,4 +758,5 @@ export function createAcpBackendRouting(options) {
757
758
  create: (binding) => createAcpProjectTransport(factory, binding),
758
759
  });
759
760
  }
761
+ import { approvedPlanWorkOrder } from '../codex/app-server-transport.js';
760
762
  //# sourceMappingURL=transport.js.map
@@ -1,5 +1,6 @@
1
1
  import { homedir } from 'node:os';
2
2
  import { join } from 'node:path';
3
+ import { resolveDataRoot } from '../config/data-root.js';
3
4
  import { randomUUID } from 'node:crypto';
4
5
  import { GuiExecutionLifecycle } from './gui-execution.js';
5
6
  import { runGui, validGuiConfig } from './gui-runner.js';
@@ -9,9 +10,9 @@ export const BROWSER_DESCRIPTOR = Object.freeze({ name: 'browser', summary: 'Use
9
10
  export function loadBrowserConfig(env) {
10
11
  const engine = env.BROWSER_ENGINE ?? 'chromium';
11
12
  const config = { engine, url: env.BROWSER_URL ?? '', headless: env.BROWSER_HEADLESS !== 'false',
12
- baseUrl: env.BROWSER_BASE_URL ?? '', model: env.BROWSER_MODEL ?? '', modelFamily: env.BROWSER_MODEL_FAMILY ?? '', apiKey: env.BROWSER_API_KEY ?? '',
13
- maxSteps: Number(env.BROWSER_MAX_STEPS ?? 30), budgetMs: Number(env.BROWSER_TIMEOUT_SECONDS ?? 600) * 1000,
14
- settleMs: Number(env.BROWSER_SETTLE_MS ?? 1000), lockRoot: join(homedir(), '.nova-audio-agent', 'gui-devices') };
13
+ baseUrl: env.EXECUTOR_BASE_URL ?? '', model: env.EXECUTOR_MODEL ?? '', modelFamily: env.EXECUTOR_MODEL_FAMILY ?? '', apiKey: env.EXECUTOR_API_KEY ?? '',
14
+ maxSteps: Number(env.EXECUTOR_MAX_STEPS ?? 30), budgetMs: Number(env.EXECUTOR_TIMEOUT_SECONDS ?? 600) * 1000,
15
+ settleMs: Number(env.EXECUTOR_SETTLE_MS ?? 1000), lockRoot: join(resolveDataRoot(homedir()).root, 'gui-devices') };
15
16
  if (!['chromium', 'firefox', 'webkit'].includes(engine) || !validBrowserUrl(config.url) || !validGuiConfig(config, 'validate')
16
17
  || (env.BROWSER_HEADLESS !== undefined && !['true', 'false'].includes(env.BROWSER_HEADLESS)))
17
18
  throw Error('invalid_browser_configuration');