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
@@ -118,10 +118,19 @@ export async function createCodexAssemblyResource(options) {
118
118
  available = options.transportFactory.available === true;
119
119
  }
120
120
  catch { /* safe failure below */ }
121
- if (!available) {
121
+ const codex = available && options.config.codexAvailable ? options.config : null;
122
+ // Codex is mandatory only as the default backend; an ACP default runs with Codex absent.
123
+ const initialBackend = options.backends?.initialBackend ?? 'codex';
124
+ if (codex === null && (options.backends === undefined || !isAcpBackend(initialBackend))) {
122
125
  throw new CodexHostConfigurationError('codex_host_unavailable');
123
126
  }
124
- return await createProjectResource(options);
127
+ if (codex === null) {
128
+ try {
129
+ options.onDiagnostic?.('coding_codex_absent');
130
+ }
131
+ catch { /* diagnostics are advisory */ }
132
+ }
133
+ return await createProjectResource(options, codex);
125
134
  }
126
135
  function isCodexTransport(value) {
127
136
  try {
@@ -137,7 +146,7 @@ function isCodexTransport(value) {
137
146
  return false;
138
147
  }
139
148
  }
140
- async function createProjectResource(options) {
149
+ async function createProjectResource(options, codex) {
141
150
  const host = options.projectHost;
142
151
  const stateRoot = options.config.stateRoot;
143
152
  const managedRoot = options.config.managedRoot;
@@ -208,8 +217,8 @@ async function createProjectResource(options) {
208
217
  unsubscribeApproval?.();
209
218
  throw new CodexHostConfigurationError('codex_project_host_unsupported');
210
219
  }
211
- const warmHome = options.config.prewarm && options.config.localCodexHome
212
- ? hostPersistentHomeFromConfig(options.config.localCodexHome, [options.config.localCodexHome]) : null;
220
+ const warmHome = codex !== null && codex.prewarm && codex.localCodexHome
221
+ ? hostPersistentHomeFromConfig(codex.localCodexHome, [codex.localCodexHome]) : null;
213
222
  let warmReady = false;
214
223
  const routing = options.backends;
215
224
  let defaultBackend = routing?.initialBackend ?? 'codex';
@@ -219,25 +228,29 @@ async function createProjectResource(options) {
219
228
  let store = null;
220
229
  let startupTransport = null;
221
230
  try {
222
- startupTransport = options.transportFactory.create(Object.freeze({
223
- ...(options.managedMcp === undefined ? {} : { managedMcp: options.managedMcp }),
224
- mode: warmHome === null ? 'live' : 'project',
225
- preserveHome: warmHome !== null,
226
- binary: options.config.binary,
227
- binaryPrefixArgs: options.config.binaryPrefixArgs,
228
- workspace: options.config.workspace,
229
- codexHome: warmHome,
230
- credential: options.config.credential,
231
- resumeThreadId: null,
232
- workingInterval: options.config.workingInterval,
233
- eagerProgress: options.config.eagerProgress,
234
- launchProfile: warmHome !== null ? launchProfile : resolveCodexLaunchProfile({
235
- approvalMode: options.config.codexApprovalMode, project: false, foregroundBroker: false,
236
- }),
237
- approvalController: warmHome === null ? null : scopedApproval({ work_id: randomUUID(), project: '', title: 'Codex startup' }),
238
- }));
239
- if (!isCodexTransport(startupTransport)) {
240
- throw new CodexHostConfigurationError('codex_host_unavailable');
231
+ // The startup transport certifies Codex; with Codex absent there is nothing to certify up front
232
+ // because ACP backends run their own preflight per task.
233
+ if (codex !== null) {
234
+ startupTransport = options.transportFactory.create(Object.freeze({
235
+ ...(options.managedMcp === undefined ? {} : { managedMcp: options.managedMcp }),
236
+ mode: warmHome === null ? 'live' : 'project',
237
+ preserveHome: warmHome !== null,
238
+ binary: codex.binary,
239
+ binaryPrefixArgs: codex.binaryPrefixArgs,
240
+ workspace: codex.workspace,
241
+ codexHome: warmHome,
242
+ credential: codex.credential,
243
+ resumeThreadId: null,
244
+ workingInterval: codex.workingInterval,
245
+ eagerProgress: codex.eagerProgress,
246
+ launchProfile: warmHome !== null ? launchProfile : resolveCodexLaunchProfile({
247
+ approvalMode: codex.codexApprovalMode, project: false, foregroundBroker: false,
248
+ }),
249
+ approvalController: warmHome === null ? null : scopedApproval({ work_id: randomUUID(), project: '', title: 'Codex startup' }),
250
+ }));
251
+ if (!isCodexTransport(startupTransport)) {
252
+ throw new CodexHostConfigurationError('codex_host_unavailable');
253
+ }
241
254
  }
242
255
  store = await ProjectStore.open({
243
256
  stateRoot,
@@ -249,15 +262,16 @@ async function createProjectResource(options) {
249
262
  });
250
263
  const derivedName = basename(hostWorkspacePath(options.config.workspace)) || 'workspace';
251
264
  const displayName = [...derivedName].slice(0, MAX_PROJECT_WORKSPACE_NAME).join('');
252
- await store.ensureImported(displayName, options.config.workspace);
265
+ const defaultWorkspace = await store.ensureImported(displayName, options.config.workspace);
253
266
  const confirmation = new ProjectConfirmationController({
254
267
  clock: options.clock,
255
268
  idFactory: options.idFactory,
256
269
  });
257
270
  const adapter = new ProjectCodexAdapter({
271
+ defaultWorkspaceId: defaultWorkspace.workspace_id,
258
272
  ...(options.managedMcp ? { managedMcp: options.managedMcp } : {}),
259
273
  store,
260
- ...(options.config.localCodexHome === undefined ? {} : { localCodexHome: options.config.localCodexHome }),
274
+ ...(codex?.localCodexHome === undefined ? {} : { localCodexHome: codex.localCodexHome }),
261
275
  confirmation,
262
276
  ...(approvalController === null ? {} : { codexApproval: approvalController }),
263
277
  defaultBackend: defaultBinding,
@@ -278,6 +292,9 @@ async function createProjectResource(options) {
278
292
  throw error;
279
293
  }
280
294
  }
295
+ // A Codex session on a host without Codex stays recorded and retryable, like an unroutable ACP one.
296
+ if (codex === null)
297
+ throw new CodexTransportError('resume_unavailable');
281
298
  const codexHome = binding.codexHome;
282
299
  if (codexHome === null)
283
300
  throw new CodexHostConfigurationError('codex_host_unavailable');
@@ -298,14 +315,14 @@ async function createProjectResource(options) {
298
315
  ...(options.managedMcp === undefined ? {} : { managedMcp: options.managedMcp }),
299
316
  preserveHome: binding.preserveHome ?? false,
300
317
  mode: 'project',
301
- binary: options.config.binary,
302
- binaryPrefixArgs: options.config.binaryPrefixArgs,
318
+ binary: codex.binary,
319
+ binaryPrefixArgs: codex.binaryPrefixArgs,
303
320
  workspace: binding.workspace,
304
321
  codexHome,
305
- credential: options.config.credential,
322
+ credential: codex.credential,
306
323
  resumeThreadId: binding.resumeThreadId,
307
- workingInterval: options.config.workingInterval,
308
- eagerProgress: options.config.eagerProgress,
324
+ workingInterval: codex.workingInterval,
325
+ eagerProgress: codex.eagerProgress,
309
326
  launchProfile,
310
327
  approvalController: approval,
311
328
  }));
@@ -329,6 +346,9 @@ async function createProjectResource(options) {
329
346
  catch { /* advisory */ } }, ready => { warmReady = ready; }, backend => {
330
347
  if (!CODING_BACKEND_IDS.includes(backend) || (backend !== 'codex' && routing === undefined))
331
348
  throw new Error('invalid_coding_backend');
349
+ // New sessions cannot default to a backend this host cannot launch; the current default stays.
350
+ if (backend === 'codex' && codex === null)
351
+ throw new Error('coding_backend_unavailable');
332
352
  defaultBackend = backend;
333
353
  });
334
354
  }
@@ -392,6 +412,8 @@ class ProjectCodexAssemblyResource {
392
412
  return this.#startOperation;
393
413
  }
394
414
  async #startFresh() {
415
+ if (this.#startupTransport === null)
416
+ return;
395
417
  if (this.prewarmConnection && this.#startupTransport.prewarmConnection) {
396
418
  // Certification remains mandatory; warming a certified connection is only an optimization.
397
419
  try {
@@ -450,7 +472,7 @@ class ProjectCodexAssemblyResource {
450
472
  this.onPrewarmReady(false);
451
473
  this.invalidateApprovals('shutdown');
452
474
  try {
453
- await this.#startupTransport.close('shutdown');
475
+ await this.#startupTransport?.close('shutdown');
454
476
  await this.adapter.close();
455
477
  }
456
478
  finally {
@@ -14,36 +14,80 @@ export class CodexHostConfigurationError extends Error {
14
14
  this.name = 'CodexHostConfigurationError';
15
15
  }
16
16
  }
17
+ /** Codex selected as the default backend: the Codex binary is mandatory. */
17
18
  export function resolveCodexHostConfig(settings, catalog) {
18
19
  if (!settings.executors.includes('codex'))
19
20
  return null;
21
+ const { safeCatalog, workspacePath } = resolveCatalogWorkspace(settings, catalog);
22
+ if (safeCatalog.canonicalBinaries.length === 0
23
+ || safeCatalog.canonicalWorkspaces.length === 0)
24
+ throw new CodexHostConfigurationError('codex_host_unavailable');
25
+ const workspace = resolveWorkspace(workspacePath, safeCatalog);
26
+ const launch = resolveCodexLaunch(settings, safeCatalog);
27
+ const roots = resolveProjectRoots(settings, safeCatalog);
28
+ return Object.freeze({
29
+ ...codingBase(settings, workspace, roots),
30
+ codexAvailable: true,
31
+ localCodexHome: ensureLocalCodexHome(safeCatalog),
32
+ ...launch,
33
+ });
34
+ }
35
+ /**
36
+ * Coding host for the selected default backend. Codex stays mandatory when it is the default;
37
+ * an ACP default only needs the workspace and project roots, and Codex becomes an optional
38
+ * extra backend that is present only when its binary resolves.
39
+ */
40
+ export function resolveCodingHostConfig(settings, catalog) {
41
+ if (settings.coding_backend === 'codex')
42
+ return resolveCodexHostConfig(settings, catalog);
43
+ if (!settings.executors.includes('codex'))
44
+ return null;
45
+ const { safeCatalog, workspacePath } = resolveCatalogWorkspace(settings, catalog);
46
+ if (safeCatalog.canonicalWorkspaces.length === 0)
47
+ throw new CodexHostConfigurationError('codex_workspace_invalid');
48
+ const workspace = resolveWorkspace(workspacePath, safeCatalog);
49
+ const roots = resolveProjectRoots(settings, safeCatalog);
50
+ const base = codingBase(settings, workspace, roots);
51
+ // Codex is optional here: any failure resolving its launch tuple or home drops Codex, never the ACP default.
52
+ let codex;
53
+ try {
54
+ codex = { ...resolveCodexLaunch(settings, safeCatalog), localCodexHome: ensureLocalCodexHome(safeCatalog) };
55
+ }
56
+ catch {
57
+ return Object.freeze({ ...base, codexAvailable: false });
58
+ }
59
+ return Object.freeze({ ...base, codexAvailable: true, ...codex });
60
+ }
61
+ function resolveCatalogWorkspace(settings, catalog) {
20
62
  const configuredWorkspace = stripLikePython(settings.codex_workspace ?? '');
21
63
  if (configuredWorkspace === '')
22
64
  throw new CodexHostConfigurationError('codex_workspace_missing');
23
65
  const safeCatalog = validateCatalog(catalog);
24
- const workspacePath = expandUserPath(configuredWorkspace, safeCatalog.homeDirectory);
25
- if (safeCatalog.canonicalBinaries.length === 0
26
- || safeCatalog.canonicalWorkspaces.length === 0)
27
- throw new CodexHostConfigurationError('codex_host_unavailable');
28
- let workspace;
66
+ return { safeCatalog, workspacePath: expandUserPath(configuredWorkspace, safeCatalog.homeDirectory) };
67
+ }
68
+ function resolveWorkspace(workspacePath, catalog) {
29
69
  try {
30
- workspace = hostWorkspaceFromConfig(workspacePath, safeCatalog.canonicalWorkspaces);
70
+ return hostWorkspaceFromConfig(workspacePath, catalog.canonicalWorkspaces);
31
71
  }
32
72
  catch {
33
73
  throw new CodexHostConfigurationError('codex_workspace_invalid');
34
74
  }
75
+ }
76
+ function resolveCodexLaunch(settings, catalog) {
77
+ if (catalog.canonicalBinaries.length === 0)
78
+ throw new CodexHostConfigurationError('codex_host_unavailable');
35
79
  const selector = stripLikePython(settings.codex_bin);
36
- if (selector === 'codex' && safeCatalog.defaultBinary === null) {
80
+ if (selector === 'codex' && catalog.defaultBinary === null) {
37
81
  throw new CodexHostConfigurationError('codex_host_unavailable');
38
82
  }
39
- const selectedBinary = selector === 'codex' ? safeCatalog.defaultBinary : selector;
83
+ const selectedBinary = selector === 'codex' ? catalog.defaultBinary : selector;
40
84
  if (selectedBinary === null
41
85
  || !isAbsolute(selectedBinary)
42
86
  || hasRejectedScriptSuffix(selectedBinary))
43
87
  throw new CodexHostConfigurationError('codex_binary_invalid');
44
88
  let binary;
45
89
  try {
46
- binary = hostBinaryFromConfig(selectedBinary, safeCatalog.canonicalBinaries);
90
+ binary = hostBinaryFromConfig(selectedBinary, catalog.canonicalBinaries);
47
91
  }
48
92
  catch {
49
93
  throw new CodexHostConfigurationError('codex_binary_invalid');
@@ -51,21 +95,27 @@ export function resolveCodexHostConfig(settings, catalog) {
51
95
  const binaryPrefixArgs = resolveBinaryPrefixArgs(settings.codex_prefix_args);
52
96
  const credential = Object.freeze({ [codexCredentialProfileBrand]: true });
53
97
  credentialValues.set(credential, settings.codex_api_key);
98
+ return { binary, binaryPrefixArgs, credential };
99
+ }
100
+ function resolveProjectRoots(settings, catalog) {
54
101
  let stateRoot;
55
102
  try {
56
- stateRoot = hostProjectRootFromConfig(ensurePrivateDirectory(expandUserPath(settings.codex_project_state_root, safeCatalog.homeDirectory)));
103
+ stateRoot = hostProjectRootFromConfig(ensurePrivateDirectory(expandUserPath(settings.codex_project_state_root, catalog.homeDirectory)));
57
104
  }
58
105
  catch {
59
106
  throw new CodexHostConfigurationError('codex_project_state_invalid');
60
107
  }
61
108
  let managedRoot;
62
109
  try {
63
- managedRoot = hostManagedProjectRootFromConfig(ensurePrivateDirectory(expandUserPath(settings.codex_managed_root, safeCatalog.homeDirectory)));
110
+ managedRoot = hostManagedProjectRootFromConfig(ensurePrivateDirectory(expandUserPath(settings.codex_managed_root, catalog.homeDirectory)));
64
111
  }
65
112
  catch {
66
113
  throw new CodexHostConfigurationError('codex_managed_root_invalid');
67
114
  }
68
- const localCodexHome = join(safeCatalog.homeDirectory, '.codex');
115
+ return { stateRoot, managedRoot };
116
+ }
117
+ function ensureLocalCodexHome(catalog) {
118
+ const localCodexHome = join(catalog.homeDirectory, '.codex');
69
119
  try {
70
120
  lstatSync(localCodexHome);
71
121
  }
@@ -75,20 +125,19 @@ export function resolveCodexHostConfig(settings, catalog) {
75
125
  // The selected user home already exists; preserve its ACL inheritance on Windows.
76
126
  mkdirSync(localCodexHome, { mode: 0o700 });
77
127
  }
78
- return Object.freeze({
128
+ return realpathSync(localCodexHome);
129
+ }
130
+ function codingBase(settings, workspace, roots) {
131
+ return {
79
132
  [resolvedCodexHostConfigBrand]: true,
80
- localCodexHome: realpathSync(localCodexHome),
81
- binary,
82
- binaryPrefixArgs,
83
133
  workspace,
84
- credential,
85
134
  prewarm: settings.codex_prewarm,
86
135
  workingInterval: settings.codex_working_interval,
87
136
  eagerProgress: settings.proactivity_preset === 'eager',
88
137
  codexApprovalMode: settings.codex_approval_mode,
89
- stateRoot,
90
- managedRoot,
91
- });
138
+ stateRoot: roots.stateRoot,
139
+ managedRoot: roots.managedRoot,
140
+ };
92
141
  }
93
142
  function resolveBinaryPrefixArgs(configured) {
94
143
  if (!Array.isArray(configured) || configured.length > 1) {
@@ -18,7 +18,7 @@ export function resolveCodexLaunchProfile(input) {
18
18
  return YOLO;
19
19
  return input.project && input.foregroundBroker ? ASK : ASK_HEADLESS;
20
20
  }
21
- export function codexAppServerArgv(profile, managedMcp = false) {
21
+ export function codexAppServerArgv(profile, managedMcp = false, strictConfig = true) {
22
22
  const sandbox = 'permissions' in profile.thread
23
23
  ? ['-c', 'default_permissions="nova_personal_agent"', '-c', 'permissions.nova_personal_agent={ filesystem = { ":root" = "read", ":workspace_roots" = { "." = "write", ".git" = "read", ".agents" = "read", ".codex" = "read" } }, network = { enabled = false } }']
24
24
  : ['-c', 'sandbox_mode="danger-full-access"'];
@@ -31,7 +31,8 @@ export function codexAppServerArgv(profile, managedMcp = false) {
31
31
  '-c', 'web_search="disabled"', ...sandbox,
32
32
  '-c', 'shell_environment_policy.inherit="core"',
33
33
  '-c', 'shell_environment_policy.include_only=["PATH","LANG","LC_ALL","TERM"]',
34
- ...(managedMcp ? [] : ['-c', 'mcp_servers={}']), 'app-server', '--strict-config', '--stdio',
34
+ ...(managedMcp ? [] : ['-c', 'mcp_servers={}']), 'app-server',
35
+ ...(strictConfig ? ['--strict-config'] : []), '--stdio',
35
36
  ]);
36
37
  }
37
38
  //# sourceMappingURL=launch-profile.js.map
@@ -0,0 +1,39 @@
1
+ import { realpathSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { parse } from 'smol-toml';
4
+ import { snapshotRegularFile } from '../../storage/native-resource-snapshot.js';
5
+ /** Provider configuration can supply credentials independently of a saved OpenAI login. */
6
+ export function hasLocalProviderCredential(codexHome) {
7
+ try {
8
+ const path = realpathSync(join(codexHome, 'config.toml'));
9
+ const bytes = snapshotRegularFile(path, 2 * 1024 * 1024).bytes;
10
+ const config = parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
11
+ const selected = config.model_provider;
12
+ if (typeof selected !== 'string' || selected === ''
13
+ || ['openai', 'ollama', 'lmstudio', 'amazon-bedrock'].includes(selected))
14
+ return false;
15
+ const providers = config.model_providers;
16
+ if (!isTable(providers))
17
+ return false;
18
+ const provider = providers[selected];
19
+ if (!isTable(provider) || typeof provider.base_url !== 'string'
20
+ || provider.base_url.trim() === '')
21
+ return false;
22
+ if (typeof provider.experimental_bearer_token === 'string'
23
+ && provider.experimental_bearer_token.trim() !== '')
24
+ return true;
25
+ const authPath = realpathSync(join(codexHome, 'auth.json'));
26
+ const authBytes = snapshotRegularFile(authPath, 1024 * 1024).bytes;
27
+ const auth = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(authBytes));
28
+ return isTable(auth) && typeof auth.OPENAI_API_KEY === 'string'
29
+ && auth.OPENAI_API_KEY.trim() !== '';
30
+ }
31
+ catch {
32
+ // Keep the existing login failure for absent, unreadable or malformed configuration.
33
+ return false;
34
+ }
35
+ }
36
+ function isTable(value) {
37
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
38
+ }
39
+ //# sourceMappingURL=local-provider-credential.js.map
@@ -2,9 +2,10 @@ import { spawn } from 'node:child_process';
2
2
  import { closeSync, fstatSync, openSync, readSync, statSync } from 'node:fs';
3
3
  import { isAbsolute } from 'node:path';
4
4
  import { managedMcpConfigToml, managedMcpEnvironment } from './managed-mcp.js';
5
- import { apiKeyProviderOverrides, NOVA_API_KEY_ENV, validateCodexEnvironment } from './spawn-env.js';
5
+ import { apiKeyProviderOverrides, NOVA_API_KEY_ENV, NOVA_RESPONSES_PROXY_ENV, validateCodexEnvironment } from './spawn-env.js';
6
6
  import { hostEphemeralHomeFromConfig, hostHomeForTest, hostHomeValue, HostPathError, hostPersistentHomeFromConfig, hostWorkspaceForTest, hostWorkspaceFromConfig, hostWorkspacePath, refreshEphemeralHomeIdentity, requireCanonicalPath, safeCanonicalPath, } from '../../projects/host-paths.js';
7
7
  import { codexAppServerArgv, resolveCodexLaunchProfile, } from './launch-profile.js';
8
+ import { isErrno } from '../../core/guards.js';
8
9
  const hostBinaryBrand = Symbol('HostBinary');
9
10
  export { HostPathError as CodexProcessOwnerError, hostHomeForTest as hostCodexHomeForTest, hostHomeValue as hostCodexHomeValue, hostEphemeralHomeFromConfig as hostEphemeralCodexHomeFromConfig, hostPersistentHomeFromConfig as hostPersistentCodexHomeFromConfig, hostWorkspaceForTest, hostWorkspaceFromConfig, hostWorkspacePath, refreshEphemeralHomeIdentity as refreshEphemeralCodexHomeIdentity };
10
11
  const CodexProcessOwnerError = HostPathError;
@@ -76,10 +77,10 @@ export function createCodexSpawnSpec(input) {
76
77
  ...validateBinaryPrefixArgs(input.prefixArgs),
77
78
  ...(input.managedMcp ? ['-c', managedMcpConfigToml(input.managedMcp).trim()] : []),
78
79
  ...(input.sharedHomeOverrides ?? []),
79
- ...(environment[NOVA_API_KEY_ENV] === undefined ? [] : apiKeyProviderOverrides()),
80
+ ...(environment[NOVA_API_KEY_ENV] === undefined ? [] : apiKeyProviderOverrides(environment[NOVA_RESPONSES_PROXY_ENV])),
80
81
  ...codexAppServerArgv(input.launchProfile ?? resolveCodexLaunchProfile({
81
82
  approvalMode: 'ask', project: false, foregroundBroker: false,
82
- }), input.managedMcp !== undefined || input.preserveHome === true),
83
+ }), input.managedMcp !== undefined || input.preserveHome === true, input.allowLegacyProviderConfig !== true),
83
84
  ]),
84
85
  cwd,
85
86
  environment,
@@ -377,9 +378,6 @@ function requireStringRecord(value) {
377
378
  }
378
379
  return value;
379
380
  }
380
- function isErrno(error, code) {
381
- return typeof error === 'object' && error !== null && Reflect.get(error, 'code') === code;
382
- }
383
381
  async function settlesWithin(work, milliseconds) {
384
382
  if (milliseconds <= 0)
385
383
  return false;
@@ -17,6 +17,8 @@ import { expandUserPath } from './host-config.js';
17
17
  import { loadProjectNativeHostFromResources, protectDefaultProjectDirectories, } from '../../projects/project-native-resource.js';
18
18
  import { stripLikePython } from '../../text/python-text.js';
19
19
  import { admitCodexCliVersion } from './version.js';
20
+ import { hasLocalProviderCredential } from './local-provider-credential.js';
21
+ import { exactKeys, isErrno, isPlainRecord } from '../../core/guards.js';
20
22
  const PROBE_ID = 'codex_sandbox_probe';
21
23
  const PROBE_PATH = 'native/codex-sandbox-probe';
22
24
  const PROBE_PATH_WINDOWS = 'native/codex-sandbox-probe.exe';
@@ -58,13 +60,32 @@ export function createProductionCodexHost(settings, options = {}) {
58
60
  const resourcesPath = options.resourcesPath ?? packagedResourcesPath();
59
61
  if (resourcesPath === null
60
62
  || workspace === null
61
- || binary === null
62
63
  || homeDirectory === null)
63
64
  return Object.freeze({
64
65
  catalog,
65
66
  transportFactory: unavailableCodexBackendTransportFactory,
66
67
  projectHost: null,
67
68
  });
69
+ // Project roots and locks serve every coding backend, so they never depend on the Codex CLI.
70
+ let projectHost = loadProjectNativeHostFromResources({
71
+ resourcesPath,
72
+ platform,
73
+ arch,
74
+ electronAbi: options.electronAbi ?? process.versions.modules,
75
+ });
76
+ if (projectHost !== null && !protectDefaultProjectDirectories(projectHost, {
77
+ homeDirectory,
78
+ stateRoot: canonicalDirectory(stripLikePython(settings.codex_project_state_root)),
79
+ managedRoot: canonicalDirectory(stripLikePython(settings.codex_managed_root)),
80
+ workspace,
81
+ }))
82
+ projectHost = null;
83
+ if (binary === null)
84
+ return Object.freeze({
85
+ catalog,
86
+ transportFactory: unavailableCodexBackendTransportFactory,
87
+ projectHost,
88
+ });
68
89
  const hostEnvironment = (platform === 'win32'
69
90
  || typeof environment.HOME === 'string' && environment.HOME !== ''
70
91
  ? environment
@@ -74,7 +95,7 @@ export function createProductionCodexHost(settings, options = {}) {
74
95
  return Object.freeze({
75
96
  catalog,
76
97
  transportFactory: unavailableCodexBackendTransportFactory,
77
- projectHost: null,
98
+ projectHost,
78
99
  });
79
100
  const windowsGuardianFactory = platform === 'win32'
80
101
  ? loadWindowsGuardianFactoryFromResources({ resourcesPath, platform, arch })
@@ -83,21 +104,8 @@ export function createProductionCodexHost(settings, options = {}) {
83
104
  return Object.freeze({
84
105
  catalog,
85
106
  transportFactory: unavailableCodexBackendTransportFactory,
86
- projectHost: null,
107
+ projectHost,
87
108
  });
88
- let projectHost = loadProjectNativeHostFromResources({
89
- resourcesPath,
90
- platform,
91
- arch,
92
- electronAbi: options.electronAbi ?? process.versions.modules,
93
- });
94
- if (projectHost !== null && !protectDefaultProjectDirectories(projectHost, {
95
- homeDirectory,
96
- stateRoot: canonicalDirectory(stripLikePython(settings.codex_project_state_root)),
97
- managedRoot: canonicalDirectory(stripLikePython(settings.codex_managed_root)),
98
- workspace,
99
- }))
100
- projectHost = null;
101
109
  const temporaryDirectory = options.temporaryDirectory === undefined
102
110
  ? canonicalSystemTemporaryDirectoryForTest(tmpdir())
103
111
  : canonicalDirectory(options.temporaryDirectory);
@@ -239,15 +247,19 @@ export class NativeCodexHostPreflightRunner {
239
247
  else {
240
248
  observePreflight(observe, 'login');
241
249
  const loginResult = await this.#command(binary, [...prefixArgs, 'login', 'status'], workspace, deadline, 4096, config.preserveHome ? { ...this.#environment, CODEX_HOME: hostCodexHomeValue(config.codexHome).path } : this.#environment, observe);
242
- let identity;
243
250
  try {
244
- identity = parseLogin(loginResult);
251
+ const identity = parseLogin(loginResult);
252
+ credential = Object.freeze({ present: true, identity, policy: 'saved_login' });
245
253
  }
246
254
  catch (error) {
247
- this.#emitDiagnostic(loginDiagnostic(loginResult));
248
- throw error;
255
+ if (config.preserveHome && hasLocalProviderCredential(hostCodexHomeValue(config.codexHome).path)) {
256
+ credential = Object.freeze({ present: true, identity: 'api_key', policy: 'provider_config' });
257
+ }
258
+ else {
259
+ this.#emitDiagnostic(loginDiagnostic(loginResult));
260
+ throw error;
261
+ }
249
262
  }
250
- credential = Object.freeze({ present: true, identity, policy: 'saved_login' });
251
263
  }
252
264
  observePreflight(observe, 'sandbox');
253
265
  const limits = await this.#runSandboxProbe(binary, prefixArgs, workspace, deadline, observe);
@@ -826,19 +838,6 @@ function requireExactRecord(value, keys) {
826
838
  throw new Error('native resource rejected');
827
839
  }
828
840
  }
829
- function isPlainRecord(value) {
830
- if (typeof value !== 'object' || value === null || Array.isArray(value))
831
- return false;
832
- const prototype = Object.getPrototypeOf(value);
833
- return prototype === Object.prototype || prototype === null;
834
- }
835
- function exactKeys(value, expected) {
836
- const keys = Object.keys(value);
837
- return keys.length === expected.length && expected.every(key => Object.hasOwn(value, key));
838
- }
839
- function isErrno(error, code) {
840
- return typeof error === 'object' && error !== null && Reflect.get(error, 'code') === code;
841
- }
842
841
  function packagedResourcesPath() {
843
842
  const value = process.resourcesPath;
844
843
  return typeof value === 'string' && value !== '' ? value : null;
@@ -1,4 +1,5 @@
1
1
  import { snapshotJsonValue } from './safe-json.js';
2
+ import { isPlainRecord } from '../../core/guards.js';
2
3
  export const MAX_JSONL_LINE = 256 * 1024;
3
4
  export const MAX_STDOUT = 2 * 1024 * 1024;
4
5
  // A 24,000-code-point steer can require six JSON bytes per character, plus its RPC envelope.
@@ -201,7 +202,7 @@ export class JsonRpcConnection {
201
202
  || (typeof idSnapshot !== 'string' && (typeof idSnapshot !== 'number'
202
203
  || !Number.isSafeInteger(idSnapshot)))
203
204
  || typeof methodSnapshot !== 'string'
204
- || !isPlainObject(paramsSnapshot))
205
+ || !isPlainRecord(paramsSnapshot))
205
206
  throw new TypeError('invalid server request');
206
207
  requestId = idSnapshot;
207
208
  method = methodSnapshot;
@@ -241,7 +242,7 @@ export class JsonRpcConnection {
241
242
  const emittedAtMs = Object.hasOwn(message, 'emittedAtMs') ? message.emittedAtMs : undefined;
242
243
  const allowedKeys = new Set(['method', 'params', 'emittedAtMs']);
243
244
  if (typeof method !== 'string'
244
- || !isPlainObject(params)
245
+ || !isPlainRecord(params)
245
246
  || keys.some(key => !allowedKeys.has(key))
246
247
  || (Object.hasOwn(message, 'emittedAtMs') && (typeof emittedAtMs !== 'number'
247
248
  || !Number.isSafeInteger(emittedAtMs)
@@ -273,7 +274,7 @@ export class JsonRpcConnection {
273
274
  pending.resolve(message.result);
274
275
  return;
275
276
  }
276
- if (keys.length === 2 && isPlainObject(message.error)) {
277
+ if (keys.length === 2 && isPlainRecord(message.error)) {
277
278
  const remoteCode = message.error.code;
278
279
  const serverCode = typeof remoteCode === 'number' && Number.isSafeInteger(remoteCode)
279
280
  ? remoteCode
@@ -438,18 +439,18 @@ export class JsonRpcConnection {
438
439
  }
439
440
  }
440
441
  function isResolvedServerRequest(value) {
441
- if (!isPlainObject(value))
442
+ if (!isPlainRecord(value))
442
443
  return false;
443
444
  const candidate = value;
444
445
  return Object.keys(candidate).length === 1 && candidate.resolved === true;
445
446
  }
446
447
  function isServerResponse(value) {
447
- if (!isPlainObject(value) || Object.keys(value).length !== 1)
448
+ if (!isPlainRecord(value) || Object.keys(value).length !== 1)
448
449
  return false;
449
450
  const candidate = value;
450
451
  if (Object.hasOwn(candidate, 'result'))
451
452
  return true;
452
- if (!Object.hasOwn(candidate, 'error') || !isPlainObject(candidate.error))
453
+ if (!Object.hasOwn(candidate, 'error') || !isPlainRecord(candidate.error))
453
454
  return false;
454
455
  return Object.keys(candidate.error).length === 2
455
456
  && typeof candidate.error.code === 'number'
@@ -476,7 +477,7 @@ function decodeMessage(line) {
476
477
  try {
477
478
  const text = fatalDecoder.decode(line.subarray(0, line.byteLength - 1));
478
479
  const value = JSON.parse(text);
479
- if (!isPlainObject(value) || Object.keys(value).length === 0)
480
+ if (!isPlainRecord(value) || Object.keys(value).length === 0)
480
481
  throw new TypeError('invalid');
481
482
  assertDecodedNumbers(value);
482
483
  return value;
@@ -497,17 +498,11 @@ function assertDecodedNumbers(value) {
497
498
  assertDecodedNumbers(item);
498
499
  return;
499
500
  }
500
- if (isPlainObject(value)) {
501
+ if (isPlainRecord(value)) {
501
502
  for (const item of Object.values(value))
502
503
  assertDecodedNumbers(item);
503
504
  }
504
505
  }
505
- function isPlainObject(value) {
506
- if (typeof value !== 'object' || value === null || Array.isArray(value))
507
- return false;
508
- const prototype = Object.getPrototypeOf(value);
509
- return prototype === Object.prototype || prototype === null;
510
- }
511
506
  function isUint8Array(value) {
512
507
  if (!ArrayBuffer.isView(value) || typedArrayTag === undefined)
513
508
  return false;