nova-personal-agent-server 0.4.1 → 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 +10 -0
  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 +11 -4
  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
@@ -17,6 +17,7 @@ import {} from './desktop-camera.js';
17
17
  import {} from '../composition/realtime-assembly.js';
18
18
  import {} from '../projects/project-confirmation.js';
19
19
  import {} from '../core/suggestions.js';
20
+ import { isRecord } from '../core/guards.js';
20
21
  export const DEFAULT_MAX_OUTBOUND_FRAMES = 128;
21
22
  export class DesktopSocketBridge {
22
23
  #token;
@@ -69,6 +70,10 @@ export class DesktopSocketBridge {
69
70
  #approvalView;
70
71
  #lastApprovalViewSent = null;
71
72
  #uplinkFrames = 0;
73
+ /** Time spent handing frames on, and how many were handled; shows whether frames wait in line before the provider. */
74
+ #uplinkHandledMs = 0;
75
+ #uplinkHandled = 0;
76
+ #uplinkSlowestMs = 0;
72
77
  #uplinkBytes = 0;
73
78
  #uplinkFlushedAt;
74
79
  #pingSent = new Map();
@@ -385,6 +390,20 @@ export class DesktopSocketBridge {
385
390
  }
386
391
  async receiveAudio(raw) {
387
392
  this.#recordUplink(raw.length);
393
+ const startedAt = Date.now();
394
+ try {
395
+ await this.#receiveAudioFrame(raw);
396
+ }
397
+ finally {
398
+ const took = Date.now() - startedAt;
399
+ this.#uplinkHandled += 1;
400
+ this.#uplinkHandledMs += took;
401
+ if (took > this.#uplinkSlowestMs)
402
+ this.#uplinkSlowestMs = took;
403
+ this.flushUplink();
404
+ }
405
+ }
406
+ async #receiveAudioFrame(raw) {
388
407
  const pcm = validateInputPcm(raw);
389
408
  if (this.#dictation) {
390
409
  const draft = this.#dictation;
@@ -454,8 +473,10 @@ export class DesktopSocketBridge {
454
473
  else if (this.#textReceipts.size >= 256)
455
474
  receipt = result(false, 'request_capacity');
456
475
  else {
476
+ // Preserve the host refusal code when it is a single snake_case token; never leak message detail.
477
+ const failureCode = (error) => error instanceof Error && /^[a-z][a-z0-9_]{0,63}$/u.test(error.message) ? error.message : 'submission_failed';
457
478
  // Record before calling the provider. Reconnect retries share this exact operation.
458
- const operation = Promise.resolve().then(submit).then(() => result(true), () => result(false, 'submission_failed'));
479
+ const operation = Promise.resolve().then(submit).then(() => result(true), error => result(false, failureCode(error)));
459
480
  this.#textReceipts.set(id, { hash, result: operation });
460
481
  receipt = await operation;
461
482
  }
@@ -678,7 +699,7 @@ export class DesktopSocketBridge {
678
699
  catch {
679
700
  return false;
680
701
  }
681
- if (!isPlainObject(payload))
702
+ if (!isRecord(payload))
682
703
  return false;
683
704
  if (payload.type === 'caption') {
684
705
  const sequence = payload.sequence;
@@ -815,9 +836,15 @@ export class DesktopSocketBridge {
815
836
  frames: this.#uplinkFrames,
816
837
  bytes: this.#uplinkBytes,
817
838
  elapsed: now - this.#uplinkFlushedAt,
839
+ handled: this.#uplinkHandled,
840
+ handled_ms: this.#uplinkHandledMs,
841
+ slowest_ms: this.#uplinkSlowestMs,
818
842
  });
819
843
  this.#uplinkFrames = 0;
820
844
  this.#uplinkBytes = 0;
845
+ this.#uplinkHandled = 0;
846
+ this.#uplinkHandledMs = 0;
847
+ this.#uplinkSlowestMs = 0;
821
848
  this.#uplinkFlushedAt = now;
822
849
  }
823
850
  /** Read-only views, for assertions. */
@@ -852,7 +879,7 @@ export function parseClientMessage(raw, options) {
852
879
  throw new DesktopWireProtocolError('desktop control frame is invalid JSON');
853
880
  }
854
881
  if (options.authenticated
855
- && isPlainObject(preliminary)
882
+ && isRecord(preliminary)
856
883
  && preliminary.type === 'playback.telemetry') {
857
884
  try {
858
885
  const telemetryValue = parseJsonWithIntegerFields(raw, [
@@ -914,7 +941,7 @@ export function parseClientMessage(raw, options) {
914
941
  throw cause;
915
942
  throw new DesktopWireProtocolError('desktop control frame is invalid JSON');
916
943
  }
917
- if (!isPlainObject(value) || typeof value.type !== 'string') {
944
+ if (!isRecord(value) || typeof value.type !== 'string') {
918
945
  throw new DesktopWireProtocolError('desktop control frame has no type');
919
946
  }
920
947
  if (!options.authenticated) {
@@ -1136,9 +1163,6 @@ function sameApprovalView(left, right) {
1136
1163
  && JSON.stringify(left.allowed_decisions) === JSON.stringify(right.allowed_decisions)
1137
1164
  && JSON.stringify(left.local_detail) === JSON.stringify(right.local_detail);
1138
1165
  }
1139
- function isPlainObject(value) {
1140
- return typeof value === 'object' && value !== null && !Array.isArray(value);
1141
- }
1142
1166
  /**
1143
1167
  * Compare two strings without leaking their contents through timing.
1144
1168
  *
@@ -1376,20 +1400,52 @@ export function buildDesktopRealtimeComposition(options) {
1376
1400
  let audioOwner = null;
1377
1401
  let audioClosing = 0;
1378
1402
  const voiceOperations = new Map();
1379
- const audioBridge = () => audioClosing ? undefined : audioOwner === 'phone' ? phone?.bridge : holder.desktop?.bridge;
1403
+ const audioBridge = () => {
1404
+ const space = holder.realtime?.personalAgent.spaceVoiceSink();
1405
+ if (space)
1406
+ return space;
1407
+ return audioClosing ? undefined : audioOwner === 'phone' ? phone?.bridge : holder.desktop?.bridge;
1408
+ };
1409
+ // Local owners also hold the Host-wide arbiter lease, so a Space call can never start under them.
1410
+ let localLease;
1411
+ const syncArbiter = () => {
1412
+ const arbiter = holder.realtime?.personalAgent.audioOwner;
1413
+ if (!arbiter)
1414
+ return;
1415
+ if (audioOwner === null) {
1416
+ if (localLease !== undefined)
1417
+ arbiter.release(localLease);
1418
+ localLease = undefined;
1419
+ return;
1420
+ }
1421
+ if (localLease === undefined || !arbiter.owns(localLease)) {
1422
+ try {
1423
+ localLease = arbiter.claim(audioOwner === 'phone' ? 'lan_phone' : 'desktop');
1424
+ }
1425
+ catch {
1426
+ localLease = undefined;
1427
+ }
1428
+ }
1429
+ };
1380
1430
  const publishPersonal = (frame) => { holder.desktop?.bridge.onPersonalFrame(frame); phone?.bridge.onPersonalFrame(frame); };
1381
1431
  const presentation = new Map();
1382
1432
  const effectivePresentation = () => [...presentation.values()].includes('workbench') ? 'workbench' : [...presentation.values()].includes('orb') ? 'orb' : 'background';
1383
1433
  const claimAudio = (side) => {
1384
1434
  if (audioClosing || (audioOwner !== null && audioOwner !== side))
1385
1435
  throw Error('voice_not_owned');
1436
+ if (holder.realtime?.personalAgent.audioOwner.spaceDevice !== undefined)
1437
+ throw Error('voice_not_owned');
1386
1438
  audioOwner = side;
1439
+ syncArbiter();
1387
1440
  };
1388
1441
  const command = async (side, value, context) => {
1389
1442
  const input = value;
1390
1443
  const params = input.params ?? {};
1391
1444
  const priorOwner = audioOwner;
1392
1445
  if (input.method === 'conversations.voice') {
1446
+ // The local desktop always takes over a Space call (approved decision 4); the legacy LAN phone does not.
1447
+ if (params.enabled === true && side === 'desktop')
1448
+ await requireRealtime().personalAgent.audioOwner.takeOver('taken_over');
1393
1449
  if (params.enabled === true) {
1394
1450
  try {
1395
1451
  claimAudio(side);
@@ -1416,13 +1472,15 @@ export function buildDesktopRealtimeComposition(options) {
1416
1472
  // implicit owner and drains its audio independently of phone visibility.
1417
1473
  if (input.method === 'presentation.set' && result.ok &&
1418
1474
  side === 'desktop' && params.mode !== 'orb' && audioOwner === side &&
1419
- requireRealtime().personalAgent.conversationSnapshot().voice_id === null) {
1475
+ requireRealtime().personalAgent.voiceConversationId() === null) {
1420
1476
  audioClosing++;
1421
1477
  try {
1422
1478
  await requireRealtime().service.discardInputAudio?.();
1423
1479
  await requireRealtime().service.playbackDisconnected({ resumeDelivery: true });
1424
- if (audioOwner === side)
1480
+ if (audioOwner === side) {
1425
1481
  audioOwner = null;
1482
+ syncArbiter();
1483
+ }
1426
1484
  }
1427
1485
  catch {
1428
1486
  // Failed draining must retain ownership: retry or disconnect before
@@ -1438,12 +1496,15 @@ export function buildDesktopRealtimeComposition(options) {
1438
1496
  audioOwner = priorOwner;
1439
1497
  else if (params.enabled === false)
1440
1498
  audioOwner = null;
1499
+ syncArbiter();
1441
1500
  }
1442
1501
  return result;
1443
1502
  }
1444
1503
  catch (error) {
1445
- if (input.method === 'conversations.voice')
1504
+ if (input.method === 'conversations.voice') {
1446
1505
  audioOwner = priorOwner;
1506
+ syncArbiter();
1507
+ }
1447
1508
  throw error;
1448
1509
  }
1449
1510
  finally {
@@ -1529,15 +1590,17 @@ export function buildDesktopRealtimeComposition(options) {
1529
1590
  onProjectView: view => requireDesktop().bridge.onProjectView(view),
1530
1591
  }, cameraTransport);
1531
1592
  holder.realtime = realtime;
1593
+ if (options.spaceVoice === true)
1594
+ realtime.personalAgent.enableSpaceVoice();
1532
1595
  const endpointOptions = (side) => ({
1533
1596
  token: options.token,
1534
- ownsAudio: () => !audioClosing && (audioOwner === side || (side === 'desktop' && audioOwner === null)),
1597
+ ownsAudio: () => !audioClosing && holder.realtime?.personalAgent.audioOwner.spaceDevice === undefined && (audioOwner === side || (side === 'desktop' && audioOwner === null)),
1535
1598
  ...(options.transportFailure === undefined ? {} : { transportFailure: options.transportFailure }),
1536
1599
  service: realtime.service,
1537
1600
  conversationService: id => realtime.personalAgent.conversationService(id),
1538
1601
  voiceService: () => realtime.personalAgent.voiceService(),
1539
1602
  sendConversationAudio: (id, pcm) => realtime.personalAgent.sendConversationAudio(id, pcm),
1540
- submitConversationText: (id, text, requestId, sourceTodo) => realtime.personalAgent.submitConversationText(id, text, requestId, sourceTodo),
1603
+ submitConversationText: (id, text, requestId, sourceTodo) => realtime.personalAgent.submitConversationText(id, text, requestId, sourceTodo, { local_desktop: side === 'desktop' }),
1541
1604
  validateConversationInput: (kind, id) => { if (presentation.get(side) === 'background' || realtime.personalAgent.presentationMode === 'background')
1542
1605
  throw Error('presentation_hidden'); const state = realtime.personalAgent.conversationSnapshot(); if (id !== undefined && !state.items.some(item => item.id === id))
1543
1606
  throw Error('conversation_not_found'); if (kind === 'audio' && ((id !== undefined && state.voice_id !== id) || (id === undefined && state.voice_id !== null)))
@@ -1553,23 +1616,27 @@ export function buildDesktopRealtimeComposition(options) {
1553
1616
  personalSnapshot: () => realtime.personalAgent.snapshot(),
1554
1617
  onConnectionReleased: () => {
1555
1618
  const hadPresentation = presentation.delete(side);
1556
- if (audioOwner === side && (realtime.personalAgent.conversationSnapshot().voice_id !== null || voiceOperations.has(side))) {
1619
+ if (audioOwner === side && (realtime.personalAgent.voiceConversationId() !== null || voiceOperations.has(side))) {
1557
1620
  audioClosing++;
1558
1621
  let released = false;
1559
1622
  void (async () => {
1560
1623
  await voiceOperations.get(side)?.catch(() => { });
1561
- const id = realtime.personalAgent.conversationSnapshot().voice_id;
1624
+ const id = realtime.personalAgent.voiceConversationId();
1562
1625
  if (id) {
1563
1626
  const result = await realtime.personalAgent.command({ type: 'personal.command', request_id: randomUUID(), method: 'conversations.voice', params: { id, enabled: false } });
1564
1627
  if (!result.ok)
1565
1628
  throw Error('voice_release_failed');
1566
1629
  }
1567
1630
  released = true;
1568
- })().catch(() => { }).finally(() => { if (released && audioOwner === side)
1569
- audioOwner = null; audioClosing--; });
1631
+ })().catch(() => { }).finally(() => { if (released && audioOwner === side) {
1632
+ audioOwner = null;
1633
+ syncArbiter();
1634
+ } audioClosing--; });
1570
1635
  }
1571
- else if (audioOwner === side)
1636
+ else if (audioOwner === side) {
1572
1637
  audioOwner = null;
1638
+ syncArbiter();
1639
+ }
1573
1640
  if (hadPresentation && presentation.size === 0 && realtime.personalAgent.presentationMode !== null)
1574
1641
  void realtime.personalAgent.disconnectPresentation().catch(() => { });
1575
1642
  else if (presentation.size > 0)
@@ -1943,7 +2010,11 @@ function desktopEntryFailureCode(error) {
1943
2010
  return 'personal_store_locked';
1944
2011
  if (['EACCES', 'EPERM', 'EROFS'].includes(String(value.code)))
1945
2012
  return 'filesystem_permissions';
1946
- if (['state_permissions', 'state_busy', 'state_lock_failed', 'personal_store_locked', 'workspace_not_found', 'workspace_invalid'].includes(String(value.code)))
2013
+ if (['state_permissions', 'state_busy', 'state_lock_failed', 'personal_store_locked', 'workspace_not_found', 'workspace_invalid', 'personal_store_capacity'].includes(String(value.code)))
2014
+ return String(value.code);
2015
+ // state_corrupt/state_version_unsupported are shared with ProjectStateError; only the personal
2016
+ // store owns the reset-state guidance.
2017
+ if (value.name === 'PersonalStoreError' && ['state_corrupt', 'state_version_unsupported', 'state_schema_incompatible'].includes(String(value.code)))
1947
2018
  return String(value.code);
1948
2019
  if (value.code === 'frontbrain_tool_budget_exceeded')
1949
2020
  return 'configuration_required';
@@ -16,6 +16,7 @@ import { CODING_BACKEND_IDS } from '../config/coding-backends.js';
16
16
  import { codePointLengthLikePython, stripLikePython } from '../text/python-text.js';
17
17
  import { PROJECT_CONFIRMATION_TTL_SECONDS } from '../projects/project-confirmation.js';
18
18
  import { APPROVAL_TTL_SECONDS, } from '../core/approval-port.js';
19
+ import { isRecord } from '../core/guards.js';
19
20
  /** Text frames produced on the orb socket (bootstrap, controls and camera requests). */
20
21
  export const WIRE_FRAME_TYPES = Object.freeze([
21
22
  'playback.clear',
@@ -389,7 +390,7 @@ function validateExecutorApprovalLocalDetail(detail) {
389
390
  || rawChanges.length > 64)
390
391
  throw new DesktopProtocolError('desktop executor approval view is invalid');
391
392
  for (const candidate of rawChanges) {
392
- if (!isPlainObject(candidate)) {
393
+ if (!isRecord(candidate)) {
393
394
  throw new DesktopProtocolError('desktop executor approval view is invalid');
394
395
  }
395
396
  const change = candidate;
@@ -504,7 +505,7 @@ function validatePlaybackFrame(frame) {
504
505
  }
505
506
  }
506
507
  function readIdentifier(payload, field) {
507
- if (!isPlainObject(payload))
508
+ if (!isRecord(payload))
508
509
  throw new DesktopProtocolError('desktop frame payload is invalid');
509
510
  try {
510
511
  return plainIdentifier(payload[field]);
@@ -514,7 +515,7 @@ function readIdentifier(payload, field) {
514
515
  }
515
516
  }
516
517
  function readPositiveInteger(payload, field) {
517
- if (!isPlainObject(payload))
518
+ if (!isRecord(payload))
518
519
  throw new DesktopProtocolError('desktop frame payload is invalid');
519
520
  try {
520
521
  return plainPositiveInteger(payload[field]);
@@ -524,7 +525,7 @@ function readPositiveInteger(payload, field) {
524
525
  }
525
526
  }
526
527
  function readNonNegativeInteger(payload, field) {
527
- if (!isPlainObject(payload))
528
+ if (!isRecord(payload))
528
529
  throw new DesktopProtocolError('desktop frame payload is invalid');
529
530
  const candidate = payload[field];
530
531
  if (typeof candidate !== 'number' || !Number.isInteger(candidate) || candidate < 0) {
@@ -555,9 +556,6 @@ function plainPositiveInteger(value) {
555
556
  }
556
557
  return value;
557
558
  }
558
- function isPlainObject(value) {
559
- return typeof value === 'object' && value !== null && !Array.isArray(value);
560
- }
561
559
  /**
562
560
  * Compact JSON with every non-ASCII character escaped, matching `ensure_ascii=True`.
563
561
  *
@@ -1,18 +1,20 @@
1
- import { homedir } from 'node:os';
2
- const MAX_LENGTH = 296;
3
- /** One terminal-safe line describing a startup exception, with the home directory and token-like strings removed. */
4
- export function describeStartupError(error, home = homedir()) {
5
- const code = error instanceof Error ? error.code : undefined;
6
- const detail = error instanceof Error
7
- ? `${error.name}${typeof code === 'string' ? ` [${code}]` : ''}: ${error.message}`
8
- : typeof error;
9
- let line = detail.replace(/[\r\n]+/gu, ' ');
10
- if (home.length > 1)
11
- line = line.split(home).join('~');
12
- line = line
13
- .replace(/\b(Bearer|Basic)\s+\S+/giu, '$1 <redacted>')
14
- .replace(/([?&](?:key|token|secret|password|api_key|access_token)=)[^\s&'"]+/giu, '$1<redacted>')
15
- .replace(/[A-Za-z0-9_+=-]{32,}/gu, '<redacted>');
16
- return line.slice(0, MAX_LENGTH);
1
+ const MEMORY_CONFIGURATION_VARIABLES = new Set([
2
+ 'MEMORY_PROVIDER', 'MEMORY_RECALL_ENGINE', 'MEMORY_EXTRACTORS', 'MEMORY_BACKEND',
3
+ 'MEMORY_CONNECTION', 'MEMORY_URL', 'MEMORY_TOKEN', 'MEMORY_PATH', 'MEMORY_USER_ID',
4
+ ]);
5
+ /** Project only the fixed configuration contract, never exception messages or setting values. */
6
+ export function startupConfiguration(error) {
7
+ const value = error?.startupConfiguration;
8
+ if (value?.code !== 'memory_provider_conflict' && value?.code !== 'memory_configuration_invalid')
9
+ return undefined;
10
+ if (!Array.isArray(value.variables) || value.variables.length === 0 || value.variables.length > MEMORY_CONFIGURATION_VARIABLES.size
11
+ || !value.variables.every(name => typeof name === 'string' && MEMORY_CONFIGURATION_VARIABLES.has(name)))
12
+ return undefined;
13
+ return { code: value.code, variables: [...new Set(value.variables)] };
14
+ }
15
+ /** Terminal diagnostics share the same allowlisted contract as the desktop; raw errors stay private. */
16
+ export function describeStartupError(error) {
17
+ const configuration = startupConfiguration(error);
18
+ return configuration === undefined ? 'startup_failed' : `${configuration.code}: ${configuration.variables.join(', ')}`;
17
19
  }
18
20
  //# sourceMappingURL=startup-error.js.map
@@ -11,7 +11,7 @@ import { z } from 'zod';
11
11
  import { currentModelPurpose } from '../model/model-purpose.js';
12
12
  import { Dispatcher, getGlobalDispatcher, setGlobalDispatcher } from 'undici';
13
13
  import { FEED_HEADERS, NEWS_SOURCES } from '../news/feeds.js';
14
- const manifestSchema = z.object({ version: z.literal(1), originalUserData: z.string(), originalBlackboardPath: z.string(), repository: z.string(), outputDirectory: z.string(), buildCommit: z.string().regex(/^[a-f0-9]{40}$/u), providers: z.array(z.object({ identity: z.string().min(1), origin: z.string().url(), models: z.array(z.string()).min(1) }).strict()).min(1), allowedIdentities: z.array(z.string()).min(1), runCapSeconds: z.number().int().min(10).max(3600).default(300), profileGeneration: z.boolean().default(false), news: z.boolean().default(false) }).strict();
14
+ const manifestSchema = z.object({ version: z.literal(1), originalUserData: z.string(), originalBlackboardPath: z.string(), repository: z.string(), outputDirectory: z.string(), buildCommit: z.string().regex(/^[a-f0-9]{40}$/u), providers: z.array(z.object({ identity: z.string().min(1), origin: z.string().url(), models: z.array(z.string()).min(1) }).strict()).min(1), allowedIdentities: z.array(z.string()).min(1), runCapSeconds: z.number().int().min(10).max(3600).default(300), profileGeneration: z.boolean().default(false), news: z.boolean().default(false), readExistingOnly: z.boolean().default(false), keepOpen: z.boolean().default(false), chatCallLimit: z.number().int().min(0).max(3).default(0), relayOrigins: z.array(z.string().url()).default([]) }).strict();
15
15
  let active;
16
16
  let calls = 0, blocked = 0, probeVerified = false;
17
17
  const fetchOrigin = new AsyncLocalStorage();
@@ -29,6 +29,7 @@ export function assertOriginalProfilePaths(actual, expected) {
29
29
  throw Error('acceptance_wrong_blackboard');
30
30
  }
31
31
  export function acceptanceEnabled() { return !!process.env.NOVA_WORKBENCH_ACCEPTANCE_REPORT; }
32
+ export function acceptanceReadExistingOnly() { return active?.readExistingOnly === true; }
32
33
  export function acceptanceProfileGenerationEnabled() { return active?.profileGeneration === true; }
33
34
  /** Public RSS reads are allowed only when the manifest turns news on, and only as plain GETs to the built-in feed origins. */
34
35
  export function acceptanceNewsEnabled() { return active?.news === true; }
@@ -41,6 +42,8 @@ export function loadAcceptanceManifest(environment = process.env) {
41
42
  if (!environment.NOVA_WORKBENCH_ACCEPTANCE_MANIFEST)
42
43
  throw Error('acceptance_manifest_required');
43
44
  const value = manifestSchema.parse(JSON.parse(readFileSync(environment.NOVA_WORKBENCH_ACCEPTANCE_MANIFEST, 'utf8')));
45
+ if (value.keepOpen && !value.readExistingOnly)
46
+ throw Error('acceptance_keep_open_requires_cached_results');
44
47
  const output = canonical(value.outputDirectory), report = resolve(environment.NOVA_WORKBENCH_ACCEPTANCE_REPORT);
45
48
  for (const root of [value.originalUserData, dirname(value.originalBlackboardPath), value.repository])
46
49
  if (inside(canonical(root), output))
@@ -58,8 +61,14 @@ export function loadAcceptanceManifest(environment = process.env) {
58
61
  if (url.protocol !== 'https:' || url.origin !== provider.origin || url.username || url.password)
59
62
  throw Error('acceptance_provider_origin_invalid');
60
63
  }
64
+ for (const origin of value.relayOrigins) {
65
+ const url = new URL(origin);
66
+ if (url.protocol !== 'https:' || url.origin !== origin || url.username || url.password || value.providers.some(provider => provider.origin === origin))
67
+ throw Error('acceptance_relay_origin_invalid');
68
+ }
61
69
  return value;
62
70
  }
71
+ function relayUrl(url) { return !!active?.relayOrigins.includes(url.protocol === 'wss:' ? 'https://' + url.host : url.origin) && ['https:', 'wss:'].includes(url.protocol) && !url.username && !url.password && !url.hash && url.pathname.startsWith('/v1/') && !/%(?:2f|5c)/iu.test(url.pathname); }
63
72
  function rejectEgress(code) { blocked++; appendAcceptanceCounts('egress_blocked', { blocked_calls: blocked }); throw Error(code); }
64
73
  export function acceptanceCounts() { return { model_calls: calls, blocked_calls: blocked }; }
65
74
  export function appendAcceptanceCounts(kind, counts) {
@@ -77,6 +86,8 @@ export function assertAcceptanceUrl(input, allowProvider = false) {
77
86
  return;
78
87
  if (url.protocol === 'ws:' && loopback.has(url.host))
79
88
  return;
89
+ if (relayUrl(url))
90
+ return;
80
91
  if (allowProvider && url.protocol === 'https:' && active.providers.some(provider => provider.origin === url.origin))
81
92
  return;
82
93
  if (allowProvider && url.protocol === 'https:' && newsOrigin(url.origin))
@@ -96,17 +107,19 @@ export function installAcceptanceGate(environment = process.env) {
96
107
  if (environment.DESKTOP_READY_ENDPOINT)
97
108
  allowAcceptanceLoopback(environment.DESKTOP_READY_ENDPOINT);
98
109
  assertOriginalProfilePaths({ blackboardPath: environment.BLACKBOARD_PATH ?? '' }, { userData: manifest.originalUserData, blackboardPath: manifest.originalBlackboardPath });
99
- const source = JSON.parse(readFileSync(manifest.originalBlackboardPath + '.personal.json.sources.json', 'utf8'));
100
- const grants = source.sources?.filter(record => !record.deleting && ['connected', 'error'].includes(record.view?.state ?? '')) ?? [];
101
- if (!grants.length)
102
- throw Error('acceptance_no_active_sources');
103
- const sourceIdentities = new Set(grants.flatMap(record => [record.processing_consent?.extraction_provider, record.processing_consent?.embedding_provider]).filter((id) => typeof id === 'string'));
104
- if (manifest.providers.some(provider => !sourceIdentities.has(provider.identity)) || manifest.allowedIdentities.some(identity => !sourceIdentities.has(identity)))
105
- throw Error('acceptance_provider_outside_source_grant');
106
- for (const record of grants)
107
- for (const identity of [record.processing_consent?.extraction_provider, record.processing_consent?.embedding_provider])
108
- if (!identity || !manifest.allowedIdentities.includes(identity))
109
- throw Error('acceptance_processing_grant_mismatch');
110
+ if (!manifest.readExistingOnly) {
111
+ const source = JSON.parse(readFileSync(manifest.originalBlackboardPath + '.personal.json.sources.json', 'utf8'));
112
+ const grants = source.sources?.filter(record => !record.deleting && ['connected', 'error'].includes(record.view?.state ?? '')) ?? [];
113
+ if (!grants.length)
114
+ throw Error('acceptance_no_active_sources');
115
+ const sourceIdentities = new Set(grants.flatMap(record => [record.processing_consent?.extraction_provider, record.processing_consent?.embedding_provider]).filter((id) => typeof id === 'string'));
116
+ if (manifest.providers.some(provider => !sourceIdentities.has(provider.identity)) || manifest.allowedIdentities.some(identity => !sourceIdentities.has(identity)))
117
+ throw Error('acceptance_provider_outside_source_grant');
118
+ for (const record of grants)
119
+ for (const identity of [record.processing_consent?.extraction_provider, record.processing_consent?.embedding_provider])
120
+ if (!identity || !manifest.allowedIdentities.includes(identity))
121
+ throw Error('acceptance_processing_grant_mismatch');
122
+ }
110
123
  // Preserve the method for Reflect.apply with the calling socket below.
111
124
  // eslint-disable-next-line @typescript-eslint/unbound-method
112
125
  const originalConnect = Socket.prototype.connect;
@@ -116,7 +129,7 @@ export function installAcceptanceGate(environment = process.env) {
116
129
  const host = typeof options === 'object' ? options.host : typeof args[1] === 'string' ? args[1] : undefined;
117
130
  const port = typeof options === 'object' ? options.port : options;
118
131
  // Unix sockets and arbitrary local proxies could bypass provider enforcement.
119
- const permitted = host !== undefined && (loopback.has(host + ':' + String(port)) || manifest.providers.some(provider => { const url = new URL(provider.origin); return fetchOrigin.getStore() === provider.origin && url.hostname === host && String(port) === String(url.port || 443); }) || [...newsOrigins].some(origin => { const url = new URL(origin); return newsOrigin(origin) && fetchOrigin.getStore() === origin && url.hostname === host && String(port) === '443'; }));
132
+ const permitted = host !== undefined && (loopback.has(host + ':' + String(port)) || manifest.providers.some(provider => { const url = new URL(provider.origin); return fetchOrigin.getStore() === provider.origin && url.hostname === host && String(port) === String(url.port || 443); }) || manifest.relayOrigins.some(origin => { const url = new URL(origin); return fetchOrigin.getStore() === origin && url.hostname === host && String(port) === String(url.port || 443); }) || [...newsOrigins].some(origin => { const url = new URL(origin); return newsOrigin(origin) && fetchOrigin.getStore() === origin && url.hostname === host && String(port) === '443'; }));
120
133
  if (!permitted) {
121
134
  blocked++;
122
135
  appendAcceptanceCounts('egress_blocked', { blocked_calls: blocked });
@@ -135,6 +148,9 @@ export function installAcceptanceGate(environment = process.env) {
135
148
  const protocol = options?.protocol ?? url?.protocol ?? (transport === https ? 'https:' : 'http:');
136
149
  const urlPort = url?.port === '' ? undefined : url?.port;
137
150
  const port = options?.port ?? urlPort ?? (protocol === 'https:' ? 443 : 80);
151
+ const path = options?.path ?? (url ? url.pathname + url.search : '/'), target = new URL(path, protocol + '//' + host + ':' + String(port));
152
+ if (transport === https && protocol === 'https:' && !options?.socketPath && options?.rejectUnauthorized !== false && relayUrl(target) && target.pathname === '/v1/live' && (options?.method ?? 'GET').toUpperCase() === 'GET' && Object.entries(options?.headers ?? {}).some(([key, value]) => key.toLowerCase() === 'upgrade' && String(value).toLowerCase() === 'websocket'))
153
+ return fetchOrigin.run(target.origin, () => Reflect.apply(originalRequest, transport, args));
138
154
  if (options?.socketPath || protocol !== 'http:' || host !== '127.0.0.1' || !loopback.has(host + ':' + String(port))) {
139
155
  blocked++;
140
156
  appendAcceptanceCounts('egress_blocked', { blocked_calls: blocked });
@@ -173,6 +189,21 @@ export function installAcceptanceGate(environment = process.env) {
173
189
  }
174
190
  if (typeof model !== 'string' || !manifest.providers.some(item => item.origin === new URL(url).origin && item.models.includes(model)))
175
191
  rejectEgress('acceptance_unknown_model');
192
+ if (acceptanceReadExistingOnly()) {
193
+ const payload = JSON.parse(body);
194
+ if (!manifest.chatCallLimit || payload.stream !== true || (init?.method ?? 'GET').toUpperCase() !== 'POST' || !new URL(url).pathname.endsWith('/chat/completions'))
195
+ rejectEgress('acceptance_generation_paused');
196
+ if (calls >= manifest.chatCallLimit)
197
+ rejectEgress('acceptance_chat_call_limit');
198
+ if (Buffer.byteLength(body) > 256 * 1024)
199
+ rejectEgress('acceptance_chat_input_limit');
200
+ const limitField = 'max_completion_tokens' in payload ? 'max_completion_tokens' : 'max_tokens', limit = payload[limitField];
201
+ delete payload.max_tokens;
202
+ delete payload.max_completion_tokens;
203
+ payload[limitField] = Math.min(typeof limit === 'number' && Number.isInteger(limit) && limit > 0 ? limit : 2048, 2048);
204
+ payload.n = 1;
205
+ init = { ...init, body: JSON.stringify(payload) };
206
+ }
176
207
  calls++;
177
208
  // One row per call, written when the response headers settle: purpose, endpoint, and time to first byte.
178
209
  const purpose = currentModelPurpose(), labels = { model_calls: calls, ['purpose_' + purpose]: 1, [new URL(url).pathname.endsWith('/embeddings') ? 'endpoint_embeddings' : 'endpoint_chat']: 1 }, started = performance.now();
@@ -190,6 +221,11 @@ export function installAcceptanceGate(environment = process.env) {
190
221
  throw error;
191
222
  }
192
223
  }
224
+ if (relayUrl(new URL(url))) {
225
+ if (typeof input !== 'string' && !(input instanceof URL) || !['GET', 'POST'].includes((init?.method ?? 'GET').toUpperCase()))
226
+ rejectEgress('acceptance_relay_method_invalid');
227
+ return fetchOrigin.run(new URL(url).origin, () => originalFetch(input, { ...init, redirect: 'error' }));
228
+ }
193
229
  if (newsOrigin(new URL(url).origin)) {
194
230
  // A feed read sends nothing: exactly a built-in feed URL, GET with no body, and fixed public headers in place of the caller's.
195
231
  if (typeof input !== 'string' && !(input instanceof URL) || !newsUrls.has(new URL(url).href) || init?.body !== undefined && init.body !== null || (init?.method ?? 'GET').toUpperCase() !== 'GET')
@@ -212,7 +248,7 @@ export function installAcceptanceGate(environment = process.env) {
212
248
  }
213
249
  export function acceptanceProfileHash(path) { return createHash('sha256').update(canonical(path)).digest('hex'); }
214
250
  export function assertAcceptanceGrant(expected, grants) {
215
- if (!active)
251
+ if (!active || active.readExistingOnly)
216
252
  return;
217
253
  if (!expected?.extraction_provider || !expected.embedding_provider)
218
254
  throw Error('acceptance_embedding_provider_disabled');
@@ -232,6 +268,8 @@ export function assertPersistedAcceptanceGrant(expected, hostPath) {
232
268
  throw Error('acceptance_gate_probe_missing');
233
269
  if (hostPath !== undefined && canonical(hostPath) !== canonical(active.originalBlackboardPath + '.personal.json'))
234
270
  throw Error('acceptance_wrong_host_path');
271
+ if (active.readExistingOnly)
272
+ return;
235
273
  const state = JSON.parse(readFileSync(active.originalBlackboardPath + '.personal.json.sources.json', 'utf8'));
236
274
  assertAcceptanceGrant(expected, (state.sources ?? []).filter(record => !record.deleting && ['connected', 'error'].includes(record.view?.state ?? '')).map(record => record.processing_consent ?? { extraction_provider: null, embedding_provider: null }));
237
275
  }
@@ -18,6 +18,7 @@ const parentPort = process.parentPort;
18
18
  const acceptanceProbe = acceptance ? await probeAcceptanceGate() : undefined;
19
19
  if (acceptance && acceptanceProbe)
20
20
  parentPort?.postMessage({ type: 'nova:acceptance:gate-ready', buildCommit: acceptance.buildCommit, runtimeHash: acceptanceRuntimeHash(fileURLToPath(import.meta.url)), ...acceptanceProbe });
21
+ let usageSnapshot;
21
22
  let capabilityView = () => undefined;
22
23
  let knowledgeHandle;
23
24
  let feishuHandle;
@@ -32,6 +33,8 @@ const control = installDesktopControl({ ...(parentPort === undefined ? {} : { pa
32
33
  updateCodingBackend(backend);
33
34
  },
34
35
  status: () => capabilityView(), handle: async (method, params) => {
36
+ if (method === 'usage.snapshot')
37
+ return usageSnapshot?.();
35
38
  if (['phone.start', 'phone.stop', 'phone.status'].includes(method))
36
39
  return phoneHandle?.(method, params);
37
40
  if (method.startsWith('feishu.') || method.startsWith('notifications.'))
@@ -82,11 +85,12 @@ const exitCode = await runDesktopEntryWithStopSources({
82
85
  onCoding: coding => { if (coding.updateDefaultBackend)
83
86
  updateCodingBackend = backend => coding.updateDefaultBackend(backend); },
84
87
  });
88
+ usageSnapshot = () => composition.usage.snapshot();
85
89
  phoneHandle = composition.phoneControl;
86
- capabilityView = () => ({ ...composition.realtime.capabilityStatus, state: 'running' });
90
+ capabilityView = () => ({ ...composition.realtime.capabilityStatus, modules: { ...composition.realtime.capabilityStatus.modules, memory: composition.memoryStatus }, state: 'running' });
87
91
  clearConversation = () => composition.realtime.clearConversation();
88
92
  feishuHandle = (method, params) => handleFeishuSettings(input => composition.realtime.personalAgent.command(input), method, params);
89
- personalSettingsHandle = (method, params) => handlePersonalSettings(input => composition.realtime.personalAgent.command(input), method, params);
93
+ personalSettingsHandle = (method, params) => handlePersonalSettings(composition.realtime.personalAgent.command.bind(composition.realtime.personalAgent), method, params);
90
94
  control.publish();
91
95
  return composition;
92
96
  },
@@ -1,7 +1,11 @@
1
1
  import { personalCommandSchema } from './personal-agent/contracts.js';
2
2
  import { parsePromptLanguage } from './realtime/prompt-language.js';
3
3
  export { VISION_MODELS, supportsVision } from './model/vision-capability.js';
4
- export { describeMissingBlockingEnvironment } from './config/config.js';
4
+ export { MODEL_CATALOG, MODEL_CATALOG_MODELS, MODEL_CATALOG_PROVIDERS, MODEL_LANE_IDS, MODEL_MODELS, MODEL_PROVIDERS, catalogModel, catalogProvider, defaultMaxOutputTokens, isModelRouteProvider, modelCapabilities, modelLabel, providerLabel, providerSupports, } from './model/model-catalog.js';
5
+ export { MODEL_ROUTE_LANE_IDS, MODEL_ROUTE_LANE_PROVIDERS, MODEL_ROUTE_PROVIDER_IDS, parseModelRoutes, } from './config/model-routes.js';
6
+ export { describeMissingBlockingEnvironment, resolveModelRoute } from './config/config.js';
7
+ export { describeHostBlockingEnvironment } from './space-host/host-admin.js';
8
+ export { stripLikePython } from './text/python-text.js';
5
9
  import { taskActionSchema } from './desktop/desktop-tasks.js';
6
10
  import { timingSafeEqual } from 'node:crypto';
7
11
  import { createConnection } from 'node:net';
@@ -0,0 +1,65 @@
1
+ // Rejections throw AttemptError with glossary codes. The host persists returned data before external calls.
2
+ export class AttemptError extends Error {
3
+ code;
4
+ constructor(code) {
5
+ super(code);
6
+ this.code = code;
7
+ }
8
+ }
9
+ export function advanceAttempt(state, event) {
10
+ const { attempt } = state;
11
+ const terminal = ['completed', 'cancelled', 'failed'].includes(state.task_phase);
12
+ const evidence = (ref) => {
13
+ if (typeof ref !== 'string' || ref.length === 0)
14
+ throw new AttemptError('stale_fence');
15
+ return [...state.evidence, ref];
16
+ };
17
+ if (!Number.isSafeInteger(state.effects) || state.effects < 0 || !attempt.id)
18
+ throw new AttemptError('stale_fence');
19
+ switch (event.op) {
20
+ case 'persist_intent':
21
+ if (attempt.status === 'unknown-effect')
22
+ throw new AttemptError('unknown_effect');
23
+ if (terminal || attempt.status !== 'none' || attempt.dispatch_started)
24
+ throw new AttemptError('stale_fence');
25
+ return { ...state, attempt: { ...attempt, status: 'prepared' } };
26
+ case 'retry_dispatch':
27
+ case 'mark_dispatch_started':
28
+ if (attempt.status === 'unknown-effect' || attempt.dispatch_started)
29
+ throw new AttemptError('unknown_effect');
30
+ if (terminal || attempt.status !== 'prepared')
31
+ throw new AttemptError('stale_fence');
32
+ return { ...state, task_phase: 'running', attempt: { ...attempt, status: 'dispatching', dispatch_started: true } };
33
+ case 'restart':
34
+ if (attempt.status !== 'dispatching' && attempt.status !== 'unknown-effect')
35
+ return state;
36
+ return { ...state, task_phase: terminal ? state.task_phase : 'waiting', attempt: { ...attempt, status: 'unknown-effect' } };
37
+ case 'accept':
38
+ if (terminal || attempt.status !== 'dispatching')
39
+ throw new AttemptError('stale_fence');
40
+ return { ...state, task_phase: 'verifying', attempt: { ...attempt, status: 'accepted' } };
41
+ case 'prove_not_dispatched':
42
+ if (attempt.dispatch_started)
43
+ throw new AttemptError('unknown_effect');
44
+ if (terminal || attempt.status !== 'prepared')
45
+ throw new AttemptError('stale_fence');
46
+ return { ...state, task_phase: 'failed', attempt: { ...attempt, status: 'failed' }, evidence: evidence(event.evidence_ref) };
47
+ case 'verify_outcome': {
48
+ if (attempt.status !== 'unknown-effect' || (terminal && state.task_phase !== 'cancelled'))
49
+ throw new AttemptError('stale_fence');
50
+ const grant = event.grant;
51
+ if (grant?.status !== 'approved' || !grant.grant_ref || grant.grant_ref === state.action_grant_ref
52
+ || grant.scope !== 'sandbox.fs.read' || grant.attempt_id !== attempt.id
53
+ || state.consumed_verification_grants?.includes(grant.grant_ref))
54
+ throw new AttemptError('approval_required');
55
+ if (event.outcome !== 'completed' && event.outcome !== 'failed')
56
+ throw new AttemptError('stale_fence');
57
+ return { ...state, task_phase: state.task_phase === 'cancelled' ? 'cancelled' : event.outcome,
58
+ attempt: { ...attempt, status: event.outcome === 'completed' ? 'accepted' : 'failed' },
59
+ evidence: evidence(event.evidence_ref),
60
+ consumed_verification_grants: [...state.consumed_verification_grants ?? [], grant.grant_ref] };
61
+ }
62
+ default: throw new AttemptError('stale_fence');
63
+ }
64
+ }
65
+ //# sourceMappingURL=attempt.js.map