nova-personal-agent-server 0.0.0-stage → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (345) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +30 -2
  3. package/bin/novapersonal-server.mjs +4 -0
  4. package/package.json +61 -4
  5. package/resources/endpointing/volcengine-v1/LICENSE.silero-vad.txt +21 -0
  6. package/resources/endpointing/volcengine-v1/MANIFEST.json +31 -0
  7. package/resources/endpointing/volcengine-v1/silence-16k-s16le.pcm +0 -0
  8. package/resources/endpointing/volcengine-v1/speech-16k-s16le.pcm +0 -0
  9. package/resources/native/codex-sandbox-probe +0 -0
  10. package/resources/native/project-native/nova_project_native.node +0 -0
  11. package/resources/native-resources-v1.json +1 -0
  12. package/runtime/dist/eval/demos.js +156 -0
  13. package/runtime/dist/eval/fixture-host.js +385 -0
  14. package/runtime/dist/eval/fixtures.js +319 -0
  15. package/runtime/dist/eval/realtime/session-fixtures.js +474 -0
  16. package/runtime/dist/eval/scorecard.js +285 -0
  17. package/runtime/dist/eval/sim.js +43 -0
  18. package/runtime/dist/src/cascaded-text-provider.js +31 -0
  19. package/runtime/dist/src/cli.js +96 -0
  20. package/runtime/dist/src/composition/assembly.js +352 -0
  21. package/runtime/dist/src/composition/cascaded-realtime-assembly.js +455 -0
  22. package/runtime/dist/src/composition/production-composition.js +389 -0
  23. package/runtime/dist/src/composition/realtime-assembly.js +1330 -0
  24. package/runtime/dist/src/config/capability-registry.js +315 -0
  25. package/runtime/dist/src/config/cascaded-realtime-config.js +146 -0
  26. package/runtime/dist/src/config/coding-backends.js +8 -0
  27. package/runtime/dist/src/config/coding-profiles.js +98 -0
  28. package/runtime/dist/src/config/config.js +857 -0
  29. package/runtime/dist/src/config/diagnostics.js +139 -0
  30. package/runtime/dist/src/config/environment-contract.js +202 -0
  31. package/runtime/dist/src/config/self-hosted.js +23 -0
  32. package/runtime/dist/src/connectors/composio/client.js +195 -0
  33. package/runtime/dist/src/connectors/composio/google.js +208 -0
  34. package/runtime/dist/src/connectors/composio/index.js +334 -0
  35. package/runtime/dist/src/connectors/feishu/cli.js +220 -0
  36. package/runtime/dist/src/connectors/feishu/index.js +980 -0
  37. package/runtime/dist/src/connectors/macos/calendar.js +35 -0
  38. package/runtime/dist/src/connectors/macos/mail.js +32 -0
  39. package/runtime/dist/src/connectors/macos/reader.js +62 -0
  40. package/runtime/dist/src/conversation-voice-provider.js +41 -0
  41. package/runtime/dist/src/core/approval-port.js +9 -0
  42. package/runtime/dist/src/core/approval.js +1328 -0
  43. package/runtime/dist/src/core/calls.js +35 -0
  44. package/runtime/dist/src/core/camera-session.js +32 -0
  45. package/runtime/dist/src/core/causal-runtime.js +650 -0
  46. package/runtime/dist/src/core/clock.js +139 -0
  47. package/runtime/dist/src/core/context-view.js +156 -0
  48. package/runtime/dist/src/core/effects.js +62 -0
  49. package/runtime/dist/src/core/events.js +217 -0
  50. package/runtime/dist/src/core/executor-diagnostic.js +9 -0
  51. package/runtime/dist/src/core/ids.js +32 -0
  52. package/runtime/dist/src/core/media-store.js +104 -0
  53. package/runtime/dist/src/core/memory.js +296 -0
  54. package/runtime/dist/src/core/pending-decision.js +64 -0
  55. package/runtime/dist/src/core/ports.js +125 -0
  56. package/runtime/dist/src/core/runtime.js +1459 -0
  57. package/runtime/dist/src/core/schedule-tools.js +15 -0
  58. package/runtime/dist/src/core/sims.js +186 -0
  59. package/runtime/dist/src/core/slots.js +97 -0
  60. package/runtime/dist/src/core/source-processing-instructions.js +3 -0
  61. package/runtime/dist/src/core/source-processing-tools.js +12 -0
  62. package/runtime/dist/src/core/suggestions.js +143 -0
  63. package/runtime/dist/src/core/task-tools.js +22 -0
  64. package/runtime/dist/src/core/tool-schema.js +212 -0
  65. package/runtime/dist/src/core/trace.js +34 -0
  66. package/runtime/dist/src/core/work-tools.js +94 -0
  67. package/runtime/dist/src/desktop/desktop-camera-source.js +31 -0
  68. package/runtime/dist/src/desktop/desktop-camera.js +281 -0
  69. package/runtime/dist/src/desktop/desktop-control.js +140 -0
  70. package/runtime/dist/src/desktop/desktop-progress.js +162 -0
  71. package/runtime/dist/src/desktop/desktop-session.js +2106 -0
  72. package/runtime/dist/src/desktop/desktop-tasks.js +80 -0
  73. package/runtime/dist/src/desktop/desktop-wire.js +605 -0
  74. package/runtime/dist/src/desktop/phone-desktop-entry.js +17 -0
  75. package/runtime/dist/src/desktop/startup-error.js +18 -0
  76. package/runtime/dist/src/desktop/workbench-acceptance.js +262 -0
  77. package/runtime/dist/src/desktop-entry.js +106 -0
  78. package/runtime/dist/src/desktop.js +1092 -0
  79. package/runtime/dist/src/executors/acp/backends.js +105 -0
  80. package/runtime/dist/src/executors/acp/mcp.js +81 -0
  81. package/runtime/dist/src/executors/acp/preflight.js +14 -0
  82. package/runtime/dist/src/executors/acp/process-owner.js +112 -0
  83. package/runtime/dist/src/executors/acp/transport.js +760 -0
  84. package/runtime/dist/src/executors/acp/windows-launch.js +68 -0
  85. package/runtime/dist/src/executors/agent-controller.js +244 -0
  86. package/runtime/dist/src/executors/autoglm.js +376 -0
  87. package/runtime/dist/src/executors/browser-device.js +102 -0
  88. package/runtime/dist/src/executors/browser.js +61 -0
  89. package/runtime/dist/src/executors/camera.js +101 -0
  90. package/runtime/dist/src/executors/chromium-frame-source.js +173 -0
  91. package/runtime/dist/src/executors/codex/adapter-live.js +292 -0
  92. package/runtime/dist/src/executors/codex/adapter-project.js +1306 -0
  93. package/runtime/dist/src/executors/codex/app-server-schema.js +712 -0
  94. package/runtime/dist/src/executors/codex/app-server-transport.js +1798 -0
  95. package/runtime/dist/src/executors/codex/approval-protocol.js +439 -0
  96. package/runtime/dist/src/executors/codex/common.js +655 -0
  97. package/runtime/dist/src/executors/codex/contract.js +581 -0
  98. package/runtime/dist/src/executors/codex/controller.js +141 -0
  99. package/runtime/dist/src/executors/codex/credential-snapshot.js +195 -0
  100. package/runtime/dist/src/executors/codex/factory.js +463 -0
  101. package/runtime/dist/src/executors/codex/host-config.js +238 -0
  102. package/runtime/dist/src/executors/codex/host.js +17 -0
  103. package/runtime/dist/src/executors/codex/index.js +19 -0
  104. package/runtime/dist/src/executors/codex/launch-profile.js +37 -0
  105. package/runtime/dist/src/executors/codex/local-sessions.js +119 -0
  106. package/runtime/dist/src/executors/codex/managed-mcp.js +196 -0
  107. package/runtime/dist/src/executors/codex/process-owner.js +398 -0
  108. package/runtime/dist/src/executors/codex/production-host.js +887 -0
  109. package/runtime/dist/src/executors/codex/progress-instructions.js +10 -0
  110. package/runtime/dist/src/executors/codex/protocol.js +581 -0
  111. package/runtime/dist/src/executors/codex/safe-json.js +87 -0
  112. package/runtime/dist/src/executors/codex/session-title.js +61 -0
  113. package/runtime/dist/src/executors/codex/shared-home.js +29 -0
  114. package/runtime/dist/src/executors/codex/spawn-env.js +162 -0
  115. package/runtime/dist/src/executors/codex/turn-projection.js +435 -0
  116. package/runtime/dist/src/executors/codex/version.js +38 -0
  117. package/runtime/dist/src/executors/codex/windows-guardian.js +716 -0
  118. package/runtime/dist/src/executors/coding/intake-model.js +103 -0
  119. package/runtime/dist/src/executors/coding/intake.js +824 -0
  120. package/runtime/dist/src/executors/coding/json-completion.js +14 -0
  121. package/runtime/dist/src/executors/coding/target-resolution.js +61 -0
  122. package/runtime/dist/src/executors/coding/work-order.js +50 -0
  123. package/runtime/dist/src/executors/coding-executor.js +23 -0
  124. package/runtime/dist/src/executors/computer-backend.js +188 -0
  125. package/runtime/dist/src/executors/computer-device.js +187 -0
  126. package/runtime/dist/src/executors/computer-worker.js +125 -0
  127. package/runtime/dist/src/executors/computer.js +100 -0
  128. package/runtime/dist/src/executors/device-lock.js +127 -0
  129. package/runtime/dist/src/executors/frame-source.js +29 -0
  130. package/runtime/dist/src/executors/gui-evidence.js +30 -0
  131. package/runtime/dist/src/executors/gui-execution.js +237 -0
  132. package/runtime/dist/src/executors/gui-runner.js +88 -0
  133. package/runtime/dist/src/executors/host-executor-capability.js +12 -0
  134. package/runtime/dist/src/executors/index.js +13 -0
  135. package/runtime/dist/src/executors/mcp-client.js +198 -0
  136. package/runtime/dist/src/executors/mcp.js +210 -0
  137. package/runtime/dist/src/executors/mobile-android.js +180 -0
  138. package/runtime/dist/src/executors/mobile-ios.js +303 -0
  139. package/runtime/dist/src/executors/mobile.js +78 -0
  140. package/runtime/dist/src/executors/search-mcp.js +146 -0
  141. package/runtime/dist/src/executors/search.js +524 -0
  142. package/runtime/dist/src/executors/task-resources.js +38 -0
  143. package/runtime/dist/src/executors/vision/assess.js +296 -0
  144. package/runtime/dist/src/executors/vision/controller-core.js +373 -0
  145. package/runtime/dist/src/executors/vision/controller.js +164 -0
  146. package/runtime/dist/src/executors/vision/lifecycle.js +69 -0
  147. package/runtime/dist/src/executors/vision.js +5 -0
  148. package/runtime/dist/src/executors/watcher.js +718 -0
  149. package/runtime/dist/src/http/bounded-response.js +37 -0
  150. package/runtime/dist/src/index.js +56 -0
  151. package/runtime/dist/src/knowledge/assembly.js +60 -0
  152. package/runtime/dist/src/knowledge/documents.js +520 -0
  153. package/runtime/dist/src/knowledge/embeddings.js +201 -0
  154. package/runtime/dist/src/knowledge/mcp.js +218 -0
  155. package/runtime/dist/src/knowledge/parse-worker.js +122 -0
  156. package/runtime/dist/src/knowledge/references.js +51 -0
  157. package/runtime/dist/src/knowledge/service.js +526 -0
  158. package/runtime/dist/src/knowledge/store-client.js +185 -0
  159. package/runtime/dist/src/knowledge/store-worker.js +843 -0
  160. package/runtime/dist/src/knowledge/types.js +2 -0
  161. package/runtime/dist/src/mcp/http-server.js +177 -0
  162. package/runtime/dist/src/mem0/resource.js +35 -0
  163. package/runtime/dist/src/mem0/store-worker.js +330 -0
  164. package/runtime/dist/src/memory/blackboard-session.js +205 -0
  165. package/runtime/dist/src/memory/blackboard-store.js +194 -0
  166. package/runtime/dist/src/memory/blackboard-worker.js +369 -0
  167. package/runtime/dist/src/memory/entry.js +39 -0
  168. package/runtime/dist/src/memory/factory.js +20 -0
  169. package/runtime/dist/src/memory/personal-memory-inspection.js +18 -0
  170. package/runtime/dist/src/memory/personal-memory.js +10 -0
  171. package/runtime/dist/src/memory/prerecall.js +20 -0
  172. package/runtime/dist/src/memory/provenance.js +17 -0
  173. package/runtime/dist/src/memory/remote-personal-memory.js +194 -0
  174. package/runtime/dist/src/memory/retrieval.js +235 -0
  175. package/runtime/dist/src/memory/sensitivity.js +261 -0
  176. package/runtime/dist/src/memory-ledger/models.js +98 -0
  177. package/runtime/dist/src/memory-ledger/store-client.js +210 -0
  178. package/runtime/dist/src/memory-ledger/store-worker.js +130 -0
  179. package/runtime/dist/src/memory-ledger/store.js +597 -0
  180. package/runtime/dist/src/memory-substrate/candidates.js +16 -0
  181. package/runtime/dist/src/memory-substrate/consolidation.js +124 -0
  182. package/runtime/dist/src/memory-substrate/file-authority.js +111 -0
  183. package/runtime/dist/src/memory-substrate/life-operations.js +280 -0
  184. package/runtime/dist/src/memory-substrate/markdown-repository.js +610 -0
  185. package/runtime/dist/src/memory-substrate/migration.js +87 -0
  186. package/runtime/dist/src/memory-substrate/profile-source-input.js +9 -0
  187. package/runtime/dist/src/memory-substrate/purge.js +398 -0
  188. package/runtime/dist/src/memory-substrate/resolution.js +32 -0
  189. package/runtime/dist/src/memory-substrate/resource.js +867 -0
  190. package/runtime/dist/src/memory-substrate/retrieval.js +85 -0
  191. package/runtime/dist/src/memory-substrate/source-operations.js +306 -0
  192. package/runtime/dist/src/memory-substrate/source-processing.js +326 -0
  193. package/runtime/dist/src/memory-substrate/source-state.js +93 -0
  194. package/runtime/dist/src/memory-substrate/store.js +534 -0
  195. package/runtime/dist/src/memory-substrate/workspace-projections.js +106 -0
  196. package/runtime/dist/src/memory-substrate/workspace.js +21 -0
  197. package/runtime/dist/src/model/jev-client.js +25 -0
  198. package/runtime/dist/src/model/model-adapters.js +64 -0
  199. package/runtime/dist/src/model/model-gateway.js +399 -0
  200. package/runtime/dist/src/model/model-lane.js +34 -0
  201. package/runtime/dist/src/model/model-purpose.js +5 -0
  202. package/runtime/dist/src/model/personal-writer.js +361 -0
  203. package/runtime/dist/src/model/proactivity.js +72 -0
  204. package/runtime/dist/src/model/prompting.js +279 -0
  205. package/runtime/dist/src/model/task-verifier.js +217 -0
  206. package/runtime/dist/src/model/vision-capability.js +10 -0
  207. package/runtime/dist/src/news/feeds.js +114 -0
  208. package/runtime/dist/src/news/jev-ranking.js +25 -0
  209. package/runtime/dist/src/news/ranking.js +26 -0
  210. package/runtime/dist/src/news/service.js +262 -0
  211. package/runtime/dist/src/notifications/adapters/feishu.js +10 -0
  212. package/runtime/dist/src/notifications/adapters/nova.js +15 -0
  213. package/runtime/dist/src/notifications/content.js +15 -0
  214. package/runtime/dist/src/notifications/contracts.js +9 -0
  215. package/runtime/dist/src/notifications/feed.js +8 -0
  216. package/runtime/dist/src/notifications/service.js +412 -0
  217. package/runtime/dist/src/notifications/store.js +4 -0
  218. package/runtime/dist/src/personal-agent/app-context.js +113 -0
  219. package/runtime/dist/src/personal-agent/approval-scope.js +8 -0
  220. package/runtime/dist/src/personal-agent/coding-targets.js +82 -0
  221. package/runtime/dist/src/personal-agent/context-candidates.js +94 -0
  222. package/runtime/dist/src/personal-agent/contracts.js +32 -0
  223. package/runtime/dist/src/personal-agent/conversation-runtime.js +536 -0
  224. package/runtime/dist/src/personal-agent/conversations.js +187 -0
  225. package/runtime/dist/src/personal-agent/daily-brief.js +53 -0
  226. package/runtime/dist/src/personal-agent/host.js +2403 -0
  227. package/runtime/dist/src/personal-agent/intake-task.js +37 -0
  228. package/runtime/dist/src/personal-agent/life.js +260 -0
  229. package/runtime/dist/src/personal-agent/memory-overview.js +19 -0
  230. package/runtime/dist/src/personal-agent/profile-sources.js +34 -0
  231. package/runtime/dist/src/personal-agent/profile-warmup.js +244 -0
  232. package/runtime/dist/src/personal-agent/project-digests.js +242 -0
  233. package/runtime/dist/src/personal-agent/sampling.js +20 -0
  234. package/runtime/dist/src/personal-agent/schedule-agent.js +60 -0
  235. package/runtime/dist/src/personal-agent/schedule-api.js +61 -0
  236. package/runtime/dist/src/personal-agent/schedule-presets.js +13 -0
  237. package/runtime/dist/src/personal-agent/schedule-reference.js +3 -0
  238. package/runtime/dist/src/personal-agent/scheduled-response-scope.js +38 -0
  239. package/runtime/dist/src/personal-agent/scheduled-run-authority.js +44 -0
  240. package/runtime/dist/src/personal-agent/scheduled-tasks.js +280 -0
  241. package/runtime/dist/src/personal-agent/scheduled-time.js +99 -0
  242. package/runtime/dist/src/personal-agent/scheduled-tool-runtime.js +109 -0
  243. package/runtime/dist/src/personal-agent/source-priority.js +142 -0
  244. package/runtime/dist/src/personal-agent/source-processing-agent.js +158 -0
  245. package/runtime/dist/src/personal-agent/source-walk.js +25 -0
  246. package/runtime/dist/src/personal-agent/sources.js +1484 -0
  247. package/runtime/dist/src/personal-agent/store-lock-worker.js +17 -0
  248. package/runtime/dist/src/personal-agent/store.js +146 -0
  249. package/runtime/dist/src/personal-agent/task-loop.js +163 -0
  250. package/runtime/dist/src/personal-agent/tasks.js +920 -0
  251. package/runtime/dist/src/personal-agent/turn-deadline.js +55 -0
  252. package/runtime/dist/src/personal-agent/understanding.js +160 -0
  253. package/runtime/dist/src/personal-agent/workbench-context.js +239 -0
  254. package/runtime/dist/src/projects/confirmed-project-capability.js +60 -0
  255. package/runtime/dist/src/projects/host-paths.js +133 -0
  256. package/runtime/dist/src/projects/managed-workspace-maintenance.js +351 -0
  257. package/runtime/dist/src/projects/project-confirmation.js +486 -0
  258. package/runtime/dist/src/projects/project-native-resource.js +284 -0
  259. package/runtime/dist/src/projects/project-node-files.js +169 -0
  260. package/runtime/dist/src/projects/project-root-file.js +16 -0
  261. package/runtime/dist/src/projects/project-state.js +504 -0
  262. package/runtime/dist/src/projects/project-store-files.js +1271 -0
  263. package/runtime/dist/src/projects/project-store.js +1345 -0
  264. package/runtime/dist/src/realtime/aoq.js +141 -0
  265. package/runtime/dist/src/realtime/bridge.js +652 -0
  266. package/runtime/dist/src/realtime/cascaded/adapter.js +1669 -0
  267. package/runtime/dist/src/realtime/cascaded/ark-llm.js +219 -0
  268. package/runtime/dist/src/realtime/cascaded/chat-completions-llm.js +478 -0
  269. package/runtime/dist/src/realtime/cascaded/gemini-speech.js +232 -0
  270. package/runtime/dist/src/realtime/cascaded/llm.js +37 -0
  271. package/runtime/dist/src/realtime/cascaded/ports.js +2 -0
  272. package/runtime/dist/src/realtime/cascaded/provider.js +216 -0
  273. package/runtime/dist/src/realtime/cascaded/qwen-llm.js +7 -0
  274. package/runtime/dist/src/realtime/cascaded/self-hosted-asr.js +110 -0
  275. package/runtime/dist/src/realtime/cascaded/self-hosted-tts.js +137 -0
  276. package/runtime/dist/src/realtime/cascaded/transcribe.js +42 -0
  277. package/runtime/dist/src/realtime/coding-progress-narration.js +28 -0
  278. package/runtime/dist/src/realtime/confirmation-turn-isolation.js +586 -0
  279. package/runtime/dist/src/realtime/dictation.js +28 -0
  280. package/runtime/dist/src/realtime/evidence.js +276 -0
  281. package/runtime/dist/src/realtime/floor.js +43 -0
  282. package/runtime/dist/src/realtime/frontend-instructions.js +195 -0
  283. package/runtime/dist/src/realtime/gemini.js +517 -0
  284. package/runtime/dist/src/realtime/history.js +122 -0
  285. package/runtime/dist/src/realtime/host-delivery.js +1711 -0
  286. package/runtime/dist/src/realtime/integrated-wire-profile.js +128 -0
  287. package/runtime/dist/src/realtime/memory-board.js +105 -0
  288. package/runtime/dist/src/realtime/openai-wire-profile.js +46 -0
  289. package/runtime/dist/src/realtime/playback.js +242 -0
  290. package/runtime/dist/src/realtime/project-confirmation-flow.js +1428 -0
  291. package/runtime/dist/src/realtime/prompt-language.js +17 -0
  292. package/runtime/dist/src/realtime/protocol.js +428 -0
  293. package/runtime/dist/src/realtime/provider-projection.js +526 -0
  294. package/runtime/dist/src/realtime/provider-session.js +491 -0
  295. package/runtime/dist/src/realtime/qwen-transport.js +144 -0
  296. package/runtime/dist/src/realtime/qwen.js +1377 -0
  297. package/runtime/dist/src/realtime/recall.js +341 -0
  298. package/runtime/dist/src/realtime/service-ports.js +8 -0
  299. package/runtime/dist/src/realtime/service-state.js +259 -0
  300. package/runtime/dist/src/realtime/service.js +1726 -0
  301. package/runtime/dist/src/realtime/session-state.js +684 -0
  302. package/runtime/dist/src/realtime/session.js +1976 -0
  303. package/runtime/dist/src/realtime/speech-prep.js +63 -0
  304. package/runtime/dist/src/realtime/streaming-speech.js +120 -0
  305. package/runtime/dist/src/realtime/system-prompts.en.js +136 -0
  306. package/runtime/dist/src/realtime/telemetry.js +144 -0
  307. package/runtime/dist/src/realtime/tool-continuations.js +1510 -0
  308. package/runtime/dist/src/realtime/transport.js +8 -0
  309. package/runtime/dist/src/realtime/usage.js +55 -0
  310. package/runtime/dist/src/realtime/user-origin-binding.js +173 -0
  311. package/runtime/dist/src/realtime/volcengine/ark.js +428 -0
  312. package/runtime/dist/src/realtime/volcengine/asr.js +573 -0
  313. package/runtime/dist/src/realtime/volcengine/audio.js +39 -0
  314. package/runtime/dist/src/realtime/volcengine/endpointing-capability.js +834 -0
  315. package/runtime/dist/src/realtime/volcengine/livekit-endpointing.js +714 -0
  316. package/runtime/dist/src/realtime/volcengine/local-eot-executor.js +33 -0
  317. package/runtime/dist/src/realtime/volcengine/protocol.js +247 -0
  318. package/runtime/dist/src/realtime/volcengine/silence-endpointing.js +237 -0
  319. package/runtime/dist/src/realtime/volcengine/tts.js +444 -0
  320. package/runtime/dist/src/realtime/volcengine/websocket.js +293 -0
  321. package/runtime/dist/src/server/aoq-chat-server.js +497 -0
  322. package/runtime/dist/src/server/client-pairing.js +192 -0
  323. package/runtime/dist/src/server/client-protocol.js +87 -0
  324. package/runtime/dist/src/server/client-server.js +312 -0
  325. package/runtime/dist/src/server/server-config.js +72 -0
  326. package/runtime/dist/src/server-entry.js +135 -0
  327. package/runtime/dist/src/storage/bounded-json.js +63 -0
  328. package/runtime/dist/src/storage/native-file-lock.js +8 -0
  329. package/runtime/dist/src/storage/native-resource-snapshot.js +41 -0
  330. package/runtime/dist/src/storage/private-database.js +120 -0
  331. package/runtime/dist/src/text/canonical-json.js +60 -0
  332. package/runtime/dist/src/text/python-number.js +18 -0
  333. package/runtime/dist/src/text/python-text.js +92 -0
  334. package/runtime/dist/src/text/unicode-casefold.js +29 -0
  335. package/runtime/dist/src/text/unicode-normalize.js +138 -0
  336. package/runtime/dist/src/text/unicode-tables.js +210 -0
  337. package/runtime/dist/src/understanding/candidates.js +77 -0
  338. package/runtime/dist/src/understanding/fixture.js +7 -0
  339. package/runtime/dist/src/understanding/jev.js +20 -0
  340. package/runtime/dist/src/understanding/pipeline.js +38 -0
  341. package/runtime/dist/src/voicemem/store-client.js +476 -0
  342. package/runtime/dist/src/voicemem/store-worker.js +380 -0
  343. package/runtime/dist/src/voicemem/versioned-memory.js +170 -0
  344. package/runtime/scripts/pair-device.mjs +109 -0
  345. package/src/command.mjs +48 -0
@@ -0,0 +1,238 @@
1
+ import { closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, realpathSync, } from 'node:fs';
2
+ import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
3
+ import { hostBinaryFromConfig, hostWorkspaceFromConfig, } from './process-owner.js';
4
+ import { hostManagedProjectRootFromConfig, hostProjectRootFromConfig, } from '../../projects/project-store.js';
5
+ import { isWellFormed, stripLikePython } from '../../text/python-text.js';
6
+ const resolvedCodexHostConfigBrand = Symbol('ResolvedCodexHostConfig');
7
+ const codexCredentialProfileBrand = Symbol('CodexCredentialProfile');
8
+ const credentialValues = new WeakMap();
9
+ export class CodexHostConfigurationError extends Error {
10
+ code;
11
+ constructor(code) {
12
+ super(code);
13
+ this.code = code;
14
+ this.name = 'CodexHostConfigurationError';
15
+ }
16
+ }
17
+ export function resolveCodexHostConfig(settings, catalog) {
18
+ if (!settings.executors.includes('codex'))
19
+ return null;
20
+ const configuredWorkspace = stripLikePython(settings.codex_workspace ?? '');
21
+ if (configuredWorkspace === '')
22
+ throw new CodexHostConfigurationError('codex_workspace_missing');
23
+ 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;
29
+ try {
30
+ workspace = hostWorkspaceFromConfig(workspacePath, safeCatalog.canonicalWorkspaces);
31
+ }
32
+ catch {
33
+ throw new CodexHostConfigurationError('codex_workspace_invalid');
34
+ }
35
+ const selector = stripLikePython(settings.codex_bin);
36
+ if (selector === 'codex' && safeCatalog.defaultBinary === null) {
37
+ throw new CodexHostConfigurationError('codex_host_unavailable');
38
+ }
39
+ const selectedBinary = selector === 'codex' ? safeCatalog.defaultBinary : selector;
40
+ if (selectedBinary === null
41
+ || !isAbsolute(selectedBinary)
42
+ || hasRejectedScriptSuffix(selectedBinary))
43
+ throw new CodexHostConfigurationError('codex_binary_invalid');
44
+ let binary;
45
+ try {
46
+ binary = hostBinaryFromConfig(selectedBinary, safeCatalog.canonicalBinaries);
47
+ }
48
+ catch {
49
+ throw new CodexHostConfigurationError('codex_binary_invalid');
50
+ }
51
+ const binaryPrefixArgs = resolveBinaryPrefixArgs(settings.codex_prefix_args);
52
+ const credential = Object.freeze({ [codexCredentialProfileBrand]: true });
53
+ credentialValues.set(credential, settings.codex_api_key);
54
+ let stateRoot;
55
+ try {
56
+ stateRoot = hostProjectRootFromConfig(ensurePrivateDirectory(expandUserPath(settings.codex_project_state_root, safeCatalog.homeDirectory)));
57
+ }
58
+ catch {
59
+ throw new CodexHostConfigurationError('codex_project_state_invalid');
60
+ }
61
+ let managedRoot;
62
+ try {
63
+ managedRoot = hostManagedProjectRootFromConfig(ensurePrivateDirectory(expandUserPath(settings.codex_managed_root, safeCatalog.homeDirectory)));
64
+ }
65
+ catch {
66
+ throw new CodexHostConfigurationError('codex_managed_root_invalid');
67
+ }
68
+ const localCodexHome = join(safeCatalog.homeDirectory, '.codex');
69
+ try {
70
+ lstatSync(localCodexHome);
71
+ }
72
+ catch (error) {
73
+ if (error.code !== 'ENOENT')
74
+ throw error;
75
+ // The selected user home already exists; preserve its ACL inheritance on Windows.
76
+ mkdirSync(localCodexHome, { mode: 0o700 });
77
+ }
78
+ return Object.freeze({
79
+ [resolvedCodexHostConfigBrand]: true,
80
+ localCodexHome: realpathSync(localCodexHome),
81
+ binary,
82
+ binaryPrefixArgs,
83
+ workspace,
84
+ credential,
85
+ prewarm: settings.codex_prewarm,
86
+ workingInterval: settings.codex_working_interval,
87
+ eagerProgress: settings.proactivity_preset === 'eager',
88
+ codexApprovalMode: settings.codex_approval_mode,
89
+ stateRoot,
90
+ managedRoot,
91
+ });
92
+ }
93
+ function resolveBinaryPrefixArgs(configured) {
94
+ if (!Array.isArray(configured) || configured.length > 1) {
95
+ throw new CodexHostConfigurationError('codex_binary_invalid');
96
+ }
97
+ const result = [];
98
+ for (const value of configured) {
99
+ if (typeof value !== 'string' || !isWellFormed(value) || !isAbsolute(value)
100
+ || !value.toLowerCase().endsWith('.js')) {
101
+ throw new CodexHostConfigurationError('codex_binary_invalid');
102
+ }
103
+ try {
104
+ const canonical = realpathSync(value);
105
+ const info = lstatSync(canonical);
106
+ if (info.isSymbolicLink() || !info.isFile() || canonical !== resolve(value))
107
+ throw new Error();
108
+ result.push(canonical);
109
+ }
110
+ catch {
111
+ throw new CodexHostConfigurationError('codex_binary_invalid');
112
+ }
113
+ }
114
+ return Object.freeze(result);
115
+ }
116
+ /** Internal host accessor; this module is intentionally absent from the runtime root exports. */
117
+ export function codexCredentialApiKey(profile) {
118
+ const value = credentialValues.get(profile);
119
+ if (value === undefined && !credentialValues.has(profile)) {
120
+ throw new CodexHostConfigurationError('codex_binary_invalid');
121
+ }
122
+ return value ?? null;
123
+ }
124
+ function validateCatalog(catalog) {
125
+ try {
126
+ if (!Array.isArray(catalog.canonicalBinaries)
127
+ || !Array.isArray(catalog.canonicalWorkspaces)
128
+ || typeof catalog.homeDirectory !== 'string'
129
+ || !isWellFormed(catalog.homeDirectory)
130
+ || !isAbsolute(catalog.homeDirectory))
131
+ throw new Error('invalid catalog');
132
+ const homeInfo = lstatSync(catalog.homeDirectory);
133
+ if (homeInfo.isSymbolicLink()
134
+ || !homeInfo.isDirectory()
135
+ || realpathSync(catalog.homeDirectory) !== resolve(catalog.homeDirectory))
136
+ throw new Error('invalid catalog');
137
+ if (catalog.defaultBinary !== null
138
+ && (typeof catalog.defaultBinary !== 'string' || !isWellFormed(catalog.defaultBinary)))
139
+ throw new Error('invalid catalog');
140
+ for (const values of [catalog.canonicalBinaries, catalog.canonicalWorkspaces]) {
141
+ for (const value of values) {
142
+ if (typeof value !== 'string' || !isWellFormed(value) || !isAbsolute(value)) {
143
+ throw new Error('invalid catalog');
144
+ }
145
+ }
146
+ }
147
+ return catalog;
148
+ }
149
+ catch {
150
+ throw new CodexHostConfigurationError('codex_binary_invalid');
151
+ }
152
+ }
153
+ export function expandUserPath(configured, homeDirectory) {
154
+ const value = stripLikePython(configured);
155
+ if (value === '~')
156
+ return homeDirectory;
157
+ if (value.startsWith('~/'))
158
+ return join(homeDirectory, value.slice(2));
159
+ return value;
160
+ }
161
+ function ensurePrivateDirectory(path) {
162
+ try {
163
+ lstatSync(path);
164
+ }
165
+ catch (error) {
166
+ if (!(error instanceof Error) || error.code !== 'ENOENT')
167
+ throw error;
168
+ // Node cannot create or validate a protected DACL. The desktop bootstrap
169
+ // must create missing Windows roots through the packaged native host
170
+ // before runtime configuration is resolved.
171
+ if (process.platform === 'win32')
172
+ throw error;
173
+ const parent = dirname(path);
174
+ const name = basename(path);
175
+ if (parent === path || name === '' || name === '.' || name === '..')
176
+ throw error;
177
+ ensurePrivateDirectory(parent);
178
+ createPrivateDirectory(parent, path);
179
+ }
180
+ return path;
181
+ }
182
+ function createPrivateDirectory(parent, path) {
183
+ const descriptor = openSync(parent, constants.O_RDONLY | (constants.O_DIRECTORY ?? 0) | (constants.O_NOFOLLOW ?? 0));
184
+ let childDescriptor = null;
185
+ try {
186
+ const retainedParent = fstatSync(descriptor, { bigint: true });
187
+ const currentParent = lstatSync(parent, { bigint: true });
188
+ if (!retainedParent.isDirectory()
189
+ || !sameIdentity(retainedParent, currentParent)
190
+ || !ownedByCurrentUser(retainedParent.uid)
191
+ || !safeParentMode(retainedParent.mode)
192
+ || realpathSync(parent) !== resolve(parent))
193
+ throw new Error('unsafe parent');
194
+ mkdirSync(path, { mode: 0o700 });
195
+ const created = lstatSync(path, { bigint: true });
196
+ childDescriptor = openSync(path, constants.O_RDONLY | (constants.O_DIRECTORY ?? 0) | (constants.O_NOFOLLOW ?? 0));
197
+ const opened = fstatSync(childDescriptor, { bigint: true });
198
+ if (!opened.isDirectory()
199
+ || !sameIdentity(created, opened)
200
+ || !ownedByCurrentUser(opened.uid)
201
+ || !privateDirectoryMode(opened.mode))
202
+ throw new Error('unsafe created directory');
203
+ const verified = fstatSync(childDescriptor, { bigint: true });
204
+ const current = lstatSync(path, { bigint: true });
205
+ const verifiedParent = fstatSync(descriptor, { bigint: true });
206
+ const currentParentAfterCreate = lstatSync(parent, { bigint: true });
207
+ if (!sameIdentity(opened, verified)
208
+ || !sameIdentity(opened, current)
209
+ || !sameIdentity(retainedParent, verifiedParent)
210
+ || !sameIdentity(retainedParent, currentParentAfterCreate)
211
+ || !privateDirectoryMode(verified.mode)
212
+ || realpathSync(path) !== resolve(path)
213
+ || dirname(realpathSync(path)) !== realpathSync(parent))
214
+ throw new Error('created directory replaced');
215
+ }
216
+ finally {
217
+ if (childDescriptor !== null)
218
+ closeSync(childDescriptor);
219
+ closeSync(descriptor);
220
+ }
221
+ }
222
+ function sameIdentity(left, right) {
223
+ return left.dev === right.dev && left.ino === right.ino;
224
+ }
225
+ function ownedByCurrentUser(uid) {
226
+ return typeof process.getuid !== 'function' || uid === BigInt(process.getuid());
227
+ }
228
+ function safeParentMode(mode) {
229
+ return (mode & 3602n) === 0n;
230
+ }
231
+ function privateDirectoryMode(mode) {
232
+ return (mode & 4095n) === 448n;
233
+ }
234
+ function hasRejectedScriptSuffix(path) {
235
+ const lower = path.toLowerCase();
236
+ return lower.endsWith('.cmd') || lower.endsWith('.bat') || lower.endsWith('.ps1');
237
+ }
238
+ //# sourceMappingURL=host-config.js.map
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Host-authority surface of the Codex executor package: spawn factories, host config resolution,
3
+ * the approval controller and the production host. Only composition roots (`desktop-entry.ts`,
4
+ * `*-assembly.ts`) import this; it is deliberately absent from the package-root barrel so the
5
+ * runtime package never exports authority bypasses (`test/codex-root-exports.test.ts`).
6
+ */
7
+ export * from './approval-protocol.js';
8
+ export { OwnedCodexAppServerTransport } from './app-server-transport.js';
9
+ export { CredentialSnapshotter, credentialSnapshotEnvironment, } from './credential-snapshot.js';
10
+ export * from './factory.js';
11
+ export * from './host-config.js';
12
+ export * from './production-host.js';
13
+ export { prepareManagedCodexMcp } from './managed-mcp.js';
14
+ export { loadWindowsGuardianFactoryFromResources } from './windows-guardian.js';
15
+ /** ACP routing for non-Codex sessions, loaded through this same lazy host entry. */
16
+ export { createAcpBackendRouting } from '../acp/transport.js';
17
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Public surface of the Codex executor package.
3
+ *
4
+ * Core (`runtime/src/**` outside `executors/**` and the composition roots) never imports anything
5
+ * under `executors/codex/`; composition roots and the barrel reach Codex only through this module
6
+ * or the registry in `../index.ts`. ESLint enforces that.
7
+ */
8
+ export * from './app-server-schema.js';
9
+ export { CODEX_DEVELOPER_INSTRUCTIONS_LIMIT, CODEX_FINAL_TEXT_LIMIT, CODEX_INTERRUPT_GRACE_MS, CODEX_PREFLIGHT_LIMIT_MS, CODEX_STDERR_LIMIT, CODEX_THREAD_ID_LIMIT, CODEX_TREE_GRACE_MS, CODEX_WORK_ORDER_LIMIT, CodexTransportError, } from './app-server-transport.js';
10
+ export * from './contract.js';
11
+ export * from './controller.js';
12
+ export * from './version.js';
13
+ export { CodexCredentialError, } from './credential-snapshot.js';
14
+ export * from './protocol.js';
15
+ export * from './turn-projection.js';
16
+ export * from './adapter-live.js';
17
+ export * from './adapter-project.js';
18
+ export { WINDOWS_GUARDIAN_FRAME_LIMIT, WINDOWS_GUARDIAN_READY_TIMEOUT_MS, CodexWindowsGuardianError, WindowsGuardianControlParser, windowsGuardianForceFrame, } from './windows-guardian.js';
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,37 @@
1
+ const ASK = Object.freeze({
2
+ id: 'ask',
3
+ controller: 'present',
4
+ thread: Object.freeze({ approvalPolicy: 'on-request', approvalsReviewer: 'user', permissions: 'nova_personal_agent' }),
5
+ });
6
+ const ASK_HEADLESS = Object.freeze({
7
+ id: 'ask_headless',
8
+ controller: 'absent',
9
+ thread: Object.freeze({ approvalPolicy: 'never', approvalsReviewer: 'user', permissions: 'nova_personal_agent' }),
10
+ });
11
+ const YOLO = Object.freeze({
12
+ id: 'yolo',
13
+ controller: 'absent',
14
+ thread: Object.freeze({ approvalPolicy: 'never', approvalsReviewer: 'user', sandbox: 'danger-full-access' }),
15
+ });
16
+ export function resolveCodexLaunchProfile(input) {
17
+ if (input.approvalMode === 'yolo')
18
+ return YOLO;
19
+ return input.project && input.foregroundBroker ? ASK : ASK_HEADLESS;
20
+ }
21
+ export function codexAppServerArgv(profile, managedMcp = false) {
22
+ const sandbox = 'permissions' in profile.thread
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
+ : ['-c', 'sandbox_mode="danger-full-access"'];
25
+ return Object.freeze([
26
+ '-a', profile.thread.approvalPolicy,
27
+ '-c', `approval_policy="${profile.thread.approvalPolicy}"`,
28
+ '-c', 'approvals_reviewer="user"',
29
+ '--disable', 'hooks', '--disable', 'multi_agent', '--disable', 'apps', '--disable', 'plugins',
30
+ '--disable', 'remote_plugin', '--disable', 'plugin_sharing', '--disable', 'tool_suggest',
31
+ '-c', 'web_search="disabled"', ...sandbox,
32
+ '-c', 'shell_environment_policy.inherit="core"',
33
+ '-c', 'shell_environment_policy.include_only=["PATH","LANG","LC_ALL","TERM"]',
34
+ ...(managedMcp ? [] : ['-c', 'mcp_servers={}']), 'app-server', '--strict-config', '--stdio',
35
+ ]);
36
+ }
37
+ //# sourceMappingURL=launch-profile.js.map
@@ -0,0 +1,119 @@
1
+ import { readFile, readdir, realpath, stat } from 'node:fs/promises';
2
+ import { basename, join, isAbsolute } from 'node:path';
3
+ import { DatabaseSync } from 'node:sqlite';
4
+ /** Read-only discovery. Resume always goes through app-server, never through copied rollout files. */
5
+ export async function readLocalCodexSessions(home, threadId) {
6
+ const files = (await readdir(home)).filter(name => /^state_\d+\.sqlite$/u.test(name))
7
+ .sort((a, b) => Number(b.slice(6, -7)) - Number(a.slice(6, -7)));
8
+ if (!files[0])
9
+ return [];
10
+ const db = new DatabaseSync(join(home, files[0]), { readOnly: true });
11
+ let rows;
12
+ try {
13
+ const columns = db.prepare('PRAGMA table_info(threads)').all().map(row => row.name);
14
+ const name = columns.includes('name') ? "COALESCE(NULLIF(name, ''), title)" : 'title';
15
+ rows = db.prepare(`SELECT id, ${name} AS title, cwd, updated_at, ${columns.includes('rollout_path') ? 'rollout_path' : 'NULL AS rollout_path'} FROM threads
16
+ WHERE archived = 0 AND source IN ('cli', 'vscode', 'exec', 'app-server')${threadId === undefined ? '' : ' AND id = ?'}
17
+ ORDER BY updated_at DESC, id LIMIT 200`).all(...(threadId === undefined ? [] : [threadId]));
18
+ }
19
+ finally {
20
+ db.close();
21
+ }
22
+ const sessions = [];
23
+ for (const row of rows) {
24
+ if (typeof row.id !== 'string' || !row.id || row.id.length > 256
25
+ || typeof row.title !== 'string' || !row.title.trim()
26
+ || typeof row.cwd !== 'string' || !isAbsolute(row.cwd)
27
+ || typeof row.updated_at !== 'number' || !Number.isFinite(row.updated_at))
28
+ continue;
29
+ try {
30
+ if (typeof row.rollout_path === 'string' && !(await stat(row.rollout_path)).isFile())
31
+ continue;
32
+ const cwd = await realpath(row.cwd);
33
+ if (!(await stat(cwd)).isDirectory())
34
+ continue;
35
+ sessions.push({ threadId: row.id, title: [...row.title.replace(/\s+/gu, ' ').trim()].slice(0, 80).join(''), cwd, updatedAt: row.updated_at });
36
+ }
37
+ catch { /* A remote or deleted workspace cannot be resumed on this host. */ }
38
+ }
39
+ return sessions;
40
+ }
41
+ /** A known missing rollout invalidates an index entry. No catalog is not proof of loss. */
42
+ export async function localRolloutAvailable(home, threadId) {
43
+ try {
44
+ const files = (await readdir(home)).filter(name => /^state_\d+\.sqlite$/u.test(name))
45
+ .sort((a, b) => Number(b.slice(6, -7)) - Number(a.slice(6, -7)));
46
+ if (!files[0])
47
+ return null;
48
+ const db = new DatabaseSync(join(home, files[0]), { readOnly: true });
49
+ let path;
50
+ try {
51
+ if (!db.prepare('PRAGMA table_info(threads)').all().some(row => row.name === 'rollout_path'))
52
+ return null;
53
+ path = db.prepare('SELECT rollout_path FROM threads WHERE id = ?').get(threadId)?.rollout_path;
54
+ }
55
+ finally {
56
+ db.close();
57
+ }
58
+ if (typeof path !== 'string')
59
+ return null;
60
+ try {
61
+ return (await stat(path)).isFile();
62
+ }
63
+ catch (error) {
64
+ if (error.code === 'ENOENT')
65
+ return false;
66
+ throw error;
67
+ }
68
+ }
69
+ catch {
70
+ return null;
71
+ } // Catalog inspection is advisory; app-server still validates any resume.
72
+ }
73
+ /** Desktop projects are explicit roots, not the execution cwd of recent threads.
74
+ * Missing desktop state retains CLI-only discovery; malformed state never expands it. */
75
+ export async function readLocalCodexProjects(home) {
76
+ let state;
77
+ try {
78
+ const path = join(home, '.codex-global-state.json');
79
+ if ((await stat(path)).size > 16 * 1024 * 1024)
80
+ return [];
81
+ const value = JSON.parse(await readFile(path, 'utf8'));
82
+ if (!value || typeof value !== 'object' || Array.isArray(value))
83
+ return [];
84
+ state = value;
85
+ }
86
+ catch (error) {
87
+ return error.code === 'ENOENT' ? null : [];
88
+ }
89
+ const record = (value) => value && typeof value === 'object' && !Array.isArray(value) ? value : {};
90
+ const assignments = record(state['thread-project-assignments']), hints = record(state['thread-workspace-root-hints']);
91
+ const projects = [];
92
+ const saved = state['local-projects'];
93
+ const entries = saved !== undefined ? Object.entries(record(saved)) :
94
+ (Array.isArray(state['electron-saved-workspace-roots']) ? state['electron-saved-workspace-roots'] : []).map((path, i) => [String(i), { rootPaths: [path] }]);
95
+ for (const [id, raw] of entries) {
96
+ const project = record(raw);
97
+ if (!Array.isArray(project.rootPaths))
98
+ continue;
99
+ for (const path of project.rootPaths) {
100
+ if (typeof path !== 'string' || !isAbsolute(path))
101
+ continue;
102
+ try {
103
+ const canonical = await realpath(path);
104
+ if (!(await stat(canonical)).isDirectory() || projects.some(item => item.path === canonical))
105
+ continue;
106
+ const threadIds = Object.keys({ ...hints, ...assignments }).filter(thread => {
107
+ const assignment = record(assignments[thread]);
108
+ if (assignments[thread] !== undefined)
109
+ return assignment.projectKind === 'local' && assignment.projectId === id;
110
+ return hints[thread] === path || hints[thread] === canonical;
111
+ });
112
+ projects.push({ path: canonical, name: [...(typeof project.name === 'string' && project.name.trim() ? project.name.trim() : basename(canonical))].slice(0, 80).join(''), threadIds });
113
+ }
114
+ catch { /* Only locally available project roots are selectable. */ }
115
+ }
116
+ }
117
+ return projects;
118
+ }
119
+ //# sourceMappingURL=local-sessions.js.map
@@ -0,0 +1,196 @@
1
+ import { SensitiveContentPolicy } from '../../memory/sensitivity.js';
2
+ import { snapshotJsonRecord } from './safe-json.js';
3
+ const sensitivity = new SensitiveContentPolicy();
4
+ const managedBrand = Symbol('ManagedCodexMcp');
5
+ const values = new WeakMap();
6
+ /** Host-only seam. Trusted entries (e.g. nova_knowledge) never pass through the external URL parser. */
7
+ export function prepareManagedCodexMcp(capabilities, trustedEntries = {}, platform = process.platform) {
8
+ const servers = Object.create(null);
9
+ const environment = Object.create(null);
10
+ const candidates = new Map();
11
+ const all = { ...capabilities.mcpServers, ...trustedEntries };
12
+ for (const [name, input] of Object.entries(all)) {
13
+ try {
14
+ const config = snapshotJsonRecord(input);
15
+ if (!capabilities.modules.coding.enabled || !config.enabled || !config.exposeTo.codex) {
16
+ updateStatus(capabilities, name, { status: 'disabled' });
17
+ continue;
18
+ }
19
+ if (!/^[a-z][a-z0-9_]{0,31}$/u.test(name)
20
+ || Object.hasOwn(trustedEntries, name) && Object.hasOwn(capabilities.mcpServers, name))
21
+ fail('codex_entry_conflict');
22
+ const enabled = Object.entries(config.tools).filter(([, tool]) => tool.enabled);
23
+ const timeouts = new Set(enabled.map(([, tool]) => Math.ceil(tool.timeoutMs / 1000)));
24
+ if (timeouts.size > 1)
25
+ fail('codex_timeout_unrepresentable');
26
+ const base = { enabled: true, enabled_tools: enabled.map(([name]) => name), disabled_tools: [],
27
+ startup_timeout_sec: 15, tool_timeout_sec: [...timeouts][0] ?? 8, default_tools_approval_mode: 'auto' };
28
+ const env = Object.create(null);
29
+ let entry;
30
+ if (config.transport === 'streamable-http') {
31
+ // Codex has no environment-reference form for URL. Never persist interpolated URL credentials.
32
+ if (config.url === undefined || config.urlInterpolated === true)
33
+ fail('codex_secret_url_unrepresentable');
34
+ const url = new URL(config.url);
35
+ if (url.username || url.password || url.hash || sensitivity.scrub('url', config.url).kind !== 'clean')
36
+ fail('codex_secret_url_unrepresentable');
37
+ const configuredHeaders = Object.entries(config.headers ?? {});
38
+ const soleHeader = configuredHeaders.length === 1 ? configuredHeaders[0] : undefined;
39
+ if (soleHeader?.[0].toLowerCase() === 'authorization' && /^Bearer [^\r\n]+$/u.test(soleHeader[1])) {
40
+ const key = `NOVA_MANAGED_MCP_${name.toUpperCase()}_TOKEN`;
41
+ env[key] = soleHeader[1].slice('Bearer '.length);
42
+ entry = { ...base, url: config.url, bearer_token_env_var: key };
43
+ }
44
+ else {
45
+ const headers = Object.fromEntries(configuredHeaders.map(([header, value], index) => {
46
+ const key = `NOVA_MANAGED_MCP_${name.toUpperCase()}_HEADER_${index}`;
47
+ env[key] = value;
48
+ return [header, key];
49
+ }));
50
+ entry = { ...base, url: config.url, env_http_headers: headers };
51
+ }
52
+ }
53
+ else {
54
+ for (const [key, value] of Object.entries(config.env ?? {})) {
55
+ // ponytail: credential-only parent env; use a scoped launcher adapter if noncredential settings are needed.
56
+ if (!safeStdioKey(key))
57
+ fail('codex_env_unrepresentable');
58
+ const canonical = platform === 'win32' ? key.toUpperCase() : key;
59
+ if (Object.hasOwn(env, canonical) && env[canonical] !== value)
60
+ fail('codex_env_conflict');
61
+ env[canonical] = value;
62
+ }
63
+ if (config.command === undefined)
64
+ fail('codex_transport_unrepresentable');
65
+ if (sensitivity.scrubCommand(config.command, config.args).kind !== 'clean')
66
+ fail('codex_secret_command_unrepresentable');
67
+ entry = { ...base, command: config.command, args: config.args ?? [], ...(Object.keys(env).length === 0 ? {} : { env_vars: Object.keys(env) }) };
68
+ }
69
+ candidates.set(name, { entry, env });
70
+ }
71
+ catch (error) {
72
+ updateStatus(capabilities, name, { status: 'failed', reason: error instanceof ProjectionError ? error.message : 'codex_projection_invalid' });
73
+ }
74
+ }
75
+ // All conflicting servers fail, independent of registry iteration order. Never pick a credential winner.
76
+ const conflicts = new Set();
77
+ const owners = new Map();
78
+ for (const [name, candidate] of candidates)
79
+ for (const [key, value] of Object.entries(candidate.env)) {
80
+ const previous = owners.get(key);
81
+ if (previous === undefined)
82
+ owners.set(key, { values: new Set([value]), names: [name] });
83
+ else {
84
+ previous.names.push(name);
85
+ previous.values.add(value);
86
+ }
87
+ }
88
+ for (const owner of owners.values())
89
+ if (owner.values.size > 1)
90
+ for (const name of owner.names)
91
+ conflicts.add(name);
92
+ for (const [name, candidate] of candidates) {
93
+ if (conflicts.has(name)) {
94
+ updateStatus(capabilities, name, { status: 'failed', reason: 'codex_env_conflict' });
95
+ continue;
96
+ }
97
+ servers[name] = freezeEntry(candidate.entry);
98
+ Object.assign(environment, candidate.env);
99
+ updateStatus(capabilities, name, { status: 'configured' });
100
+ }
101
+ const managed = Object.freeze({ [managedBrand]: true, servers: Object.freeze(servers) });
102
+ const devices = Object.keys(servers).flatMap(name => all[name]?.computerUse ? [all[name].computerUse.resource] : []);
103
+ values.set(managed, { environment: Object.freeze(environment), resources: devices.includes(null) ? null : Object.freeze([...new Set(devices)]), capabilities });
104
+ return managed;
105
+ }
106
+ function safeStdioKey(key) {
107
+ const upper = key.toUpperCase();
108
+ return /^[A-Za-z_][A-Za-z0-9_]{0,127}$/u.test(key)
109
+ && /^(?:[A-Z][A-Z0-9_]*_)?(?:KEY|TOKEN|SECRET|PASSWORD)$/u.test(upper)
110
+ && !/^(?:CODEX|OPENAI|NOVA|NODE|LD|DYLD|NPM|PYTHON|RUBY|PERL|BASH|ZSH|GIT|SSH|SSL|CURL|REQUESTS|AWS|AZURE|GOOGLE|GCLOUD)_/u.test(upper);
111
+ }
112
+ class ProjectionError extends Error {
113
+ }
114
+ function fail(reason) { throw new ProjectionError(reason); }
115
+ function freezeEntry(entry) {
116
+ Object.freeze(entry.enabled_tools);
117
+ Object.freeze(entry.disabled_tools);
118
+ if (entry.args !== undefined)
119
+ Object.freeze(entry.args);
120
+ if (entry.env_vars !== undefined)
121
+ Object.freeze(entry.env_vars);
122
+ if (entry.env_http_headers !== undefined)
123
+ Object.freeze(entry.env_http_headers);
124
+ return Object.freeze(entry);
125
+ }
126
+ export function managedMcpEnvironment(managed) {
127
+ if (managed === undefined)
128
+ return {};
129
+ const value = values.get(managed);
130
+ if (value === undefined)
131
+ throw new TypeError('invalid managed MCP authority');
132
+ return value.environment;
133
+ }
134
+ export function managedMcpConfigToml(managed) {
135
+ managedMcpEnvironment(managed);
136
+ return `mcp_servers = ${toml(managed?.servers ?? {})}\n`;
137
+ }
138
+ export function toml(value) {
139
+ if (Array.isArray(value))
140
+ return `[${value.map(toml).join(', ')}]`;
141
+ if (typeof value === 'object' && value !== null)
142
+ return `{ ${Object.entries(value).map(([key, field]) => `${toml(key)} = ${toml(field)}`).join(', ')} }`;
143
+ return JSON.stringify(value).replaceAll('\u007f', '\\u007f');
144
+ }
145
+ export function validateManagedMcpConfig(actual, managed) {
146
+ managedMcpEnvironment(managed);
147
+ const record = snapshotJsonRecord(actual);
148
+ const expected = managed?.servers ?? {};
149
+ if (!same(Object.keys(record).sort(), Object.keys(expected).sort()))
150
+ throw new TypeError('mcp servers');
151
+ for (const [name, entry] of Object.entries(expected)) {
152
+ const config = snapshotJsonRecord(record[name]);
153
+ // Real pinned 0.152.0 adds this local-only normalization; no other transport extras are admitted.
154
+ if (config.environment_id === 'local')
155
+ delete config.environment_id;
156
+ if (!same(config, entry))
157
+ throw new TypeError('mcp entry');
158
+ }
159
+ }
160
+ function same(left, right) {
161
+ if (left === right)
162
+ return true;
163
+ if (Array.isArray(left) && Array.isArray(right))
164
+ return left.length === right.length && left.every((value, index) => same(value, right[index]));
165
+ if (left === null || right === null || typeof left !== 'object' || typeof right !== 'object' || Array.isArray(left) || Array.isArray(right))
166
+ return false;
167
+ const a = left;
168
+ const b = right;
169
+ return Object.keys(a).length === Object.keys(b).length && Object.keys(a).every(key => Object.hasOwn(b, key) && same(a[key], b[key]));
170
+ }
171
+ export function recordManagedMcpVisibility(managed, name, ok) {
172
+ if (managed === undefined)
173
+ return;
174
+ const value = values.get(managed);
175
+ if (value === undefined)
176
+ throw new TypeError('invalid managed MCP authority');
177
+ updateStatus(value.capabilities, name, ok ? { status: 'ok' } : { status: 'failed', reason: 'codex_visibility' });
178
+ }
179
+ function updateStatus(capabilities, name, codex) {
180
+ const statuses = capabilities.serverStatuses;
181
+ const index = statuses.findIndex(status => status.name === name);
182
+ const previous = statuses[index];
183
+ // A failure observed in any concurrent project remains visible until a registry restart.
184
+ if (previous?.codex?.status === 'failed' && codex.status === 'ok')
185
+ return;
186
+ const next = { ...previous ?? { name, status: 'configured' }, codex };
187
+ if (index < 0)
188
+ statuses.push(next);
189
+ else
190
+ statuses[index] = next;
191
+ }
192
+ /** Conservative ownership: every configured device is held for the entire Codex run. */
193
+ export function managedMcpResources(managed) { if (!managed)
194
+ return []; const value = values.get(managed); if (!value)
195
+ throw Error('invalid managed MCP authority'); return value.resources; }
196
+ //# sourceMappingURL=managed-mcp.js.map