@jungjaehoon/mama-core 2.4.0 → 4.0.0

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 (374) hide show
  1. package/README.md +76 -239
  2. package/db/migrations/030-case-first-memory-substrate.sql +13 -98
  3. package/db/migrations/034-add-connector-event-scope-columns.sql +9 -13
  4. package/db/migrations/039-add-connector-event-operator-ingest-seq.sql +9 -95
  5. package/db/migrations/062-refresh-connector-event-sequences.sql +9 -113
  6. package/db/migrations/063-refresh-legacy-connector-event-updates.sql +9 -32
  7. package/db/migrations/067-add-connector-event-source-entity-id.sql +9 -13
  8. package/db/migrations/068-tool-trace-diagnostics.sql +13 -0
  9. package/db/migrations/069-create-registry-nodes.sql +52 -0
  10. package/db/migrations/070-record-identity.sql +35 -0
  11. package/db/migrations/071-service-operation-origins.sql +187 -0
  12. package/db/migrations/072-observation-versions.sql +29 -0
  13. package/db/migrations/073-registry-corrections.sql +45 -0
  14. package/db/migrations/074-work-graph-ref-kinds.sql +39 -0
  15. package/db/migrations/075-agent-judgments.sql +58 -0
  16. package/db/migrations/076-scoped-checkpoint-bindings.sql +15 -0
  17. package/db/migrations/077-legacy-record-kind.sql +6 -0
  18. package/db/migrations/078-source-ingest-commands.sql +18 -0
  19. package/db/migrations/079-twin-edge-relations.sql +43 -0
  20. package/db/migrations/080-restore-duration-days.sql +7 -0
  21. package/db/migrations/081-mailbox.sql +61 -0
  22. package/db/migrations/082-commitments-row-id.sql +12 -0
  23. package/db/migrations/083-observation-is-the-evidence.sql +49 -0
  24. package/db/migrations/084-scope-kind-is-not-the-cores-to-list.sql +34 -0
  25. package/db/migrations/085-a-migration-has-a-source.sql +37 -0
  26. package/db/migrations/086-the-mailbox-is-generic.sql +110 -0
  27. package/db/migrations/087-mailbox-payload.sql +5 -0
  28. package/db/migrations/088-native-input-journal.sql +14 -0
  29. package/db/migrations/089-native-turn-receipt-lookup.sql +3 -0
  30. package/db/migrations/090-model-run-native-inputs.sql +29 -0
  31. package/db/migrations/091-native-turn-results.sql +11 -0
  32. package/db/migrations/092-restore-decision-fts.sql +34 -0
  33. package/db/migrations/093-native-turn-primary-kind.sql +14 -0
  34. package/db/migrations/094-commitment-run-provenance.sql +9 -0
  35. package/db/migrations/095-model-run-native-input-identity.sql +39 -0
  36. package/db/migrations/096-drop-connector-event-index-fts.sql +9 -0
  37. package/db/migrations/097-native-input-json-validity.sql +37 -0
  38. package/db/migrations/098-workflow-memory-kind.sql +105 -0
  39. package/dist/action-contracts.d.ts +212 -0
  40. package/dist/action-contracts.js +10 -0
  41. package/dist/api/catalog.d.ts +118 -0
  42. package/dist/api/catalog.js +1756 -0
  43. package/dist/api/dispatch.d.ts +76 -0
  44. package/dist/api/dispatch.js +372 -0
  45. package/dist/canonicalize.d.ts +2 -2
  46. package/dist/canonicalize.js +3 -3
  47. package/dist/client/client.d.ts +33 -0
  48. package/dist/client/client.js +123 -0
  49. package/dist/client/ipc.d.ts +81 -0
  50. package/dist/client/ipc.js +314 -0
  51. package/dist/db-adapter/base-adapter.d.ts +6 -66
  52. package/dist/db-adapter/base-adapter.js +6 -6
  53. package/dist/db-adapter/index.d.ts +5 -5
  54. package/dist/db-adapter/index.js +2 -5
  55. package/dist/db-adapter/node-sqlite-adapter.d.ts +87 -15
  56. package/dist/db-adapter/node-sqlite-adapter.js +2045 -568
  57. package/dist/db-manager.d.ts +53 -97
  58. package/dist/db-manager.js +121 -603
  59. package/dist/embedding/embedder.d.ts +132 -0
  60. package/dist/embedding/embedder.js +299 -0
  61. package/dist/identity/principal-repository.d.ts +2 -2
  62. package/dist/index.d.ts +43 -58
  63. package/dist/index.js +99 -145
  64. package/dist/{context-compile/channel-grant.d.ts → knowledge/access.d.ts} +12 -17
  65. package/dist/knowledge/access.js +663 -0
  66. package/dist/knowledge/case-errors.d.ts +31 -0
  67. package/dist/knowledge/case-errors.js +40 -0
  68. package/dist/{cases/search-rollup.d.ts → knowledge/case-search-rollup.d.ts} +5 -4
  69. package/dist/{cases/search-rollup.js → knowledge/case-search-rollup.js} +6 -8
  70. package/dist/{cases/store.d.ts → knowledge/case-store.d.ts} +3 -6
  71. package/dist/{cases/store.js → knowledge/case-store.js} +7 -42
  72. package/dist/{cases/timeline-range.d.ts → knowledge/case-timeline-range.d.ts} +3 -3
  73. package/dist/{cases/timeline-range.js → knowledge/case-timeline-range.js} +47 -25
  74. package/dist/{cases/types.d.ts → knowledge/case-types.d.ts} +8 -2
  75. package/dist/{cases/types.js → knowledge/case-types.js} +1 -1
  76. package/dist/knowledge/commitments.d.ts +188 -0
  77. package/dist/knowledge/commitments.js +370 -0
  78. package/dist/knowledge/decision-edges.d.ts +70 -0
  79. package/dist/knowledge/decision-edges.js +123 -0
  80. package/dist/{agent-graph/types.d.ts → knowledge/graph-query.d.ts} +80 -70
  81. package/dist/knowledge/graph-query.js +1585 -0
  82. package/dist/knowledge/identity.d.ts +16 -0
  83. package/dist/knowledge/identity.js +22 -0
  84. package/dist/knowledge/index.d.ts +47 -0
  85. package/dist/knowledge/index.js +90 -0
  86. package/dist/knowledge/judgments.d.ts +118 -0
  87. package/dist/knowledge/judgments.js +808 -0
  88. package/dist/knowledge/observations.d.ts +160 -0
  89. package/dist/knowledge/observations.js +449 -0
  90. package/dist/knowledge/question-type.d.ts +34 -0
  91. package/dist/knowledge/question-type.js +70 -0
  92. package/dist/{search → knowledge}/ranker-features.js +1 -1
  93. package/dist/{search → knowledge}/search-quality.d.ts +0 -1
  94. package/dist/knowledge/search.d.ts +38 -0
  95. package/dist/knowledge/search.js +91 -0
  96. package/dist/knowledge/source-ingest.d.ts +65 -0
  97. package/dist/knowledge/source-ingest.js +174 -0
  98. package/dist/{edges/types.d.ts → knowledge/twin-edge-types.d.ts} +31 -4
  99. package/dist/{edges/types.js → knowledge/twin-edge-types.js} +13 -2
  100. package/dist/knowledge/work-dates.d.ts +49 -0
  101. package/dist/knowledge/work-dates.js +120 -0
  102. package/dist/mama-api.d.ts +116 -778
  103. package/dist/mama-api.js +313 -2457
  104. package/dist/memory/api.d.ts +264 -24
  105. package/dist/memory/api.js +1633 -843
  106. package/dist/memory/bootstrap-builder.d.ts +2 -1
  107. package/dist/memory/bootstrap-builder.js +5 -5
  108. package/dist/memory/channel-summary-state-store.d.ts +3 -2
  109. package/dist/memory/channel-summary-state-store.js +53 -51
  110. package/dist/memory/channel-summary-store.d.ts +5 -3
  111. package/dist/memory/channel-summary-store.js +3 -8
  112. package/dist/memory/dashboard-read.d.ts +46 -0
  113. package/dist/memory/dashboard-read.js +94 -0
  114. package/dist/memory/event-store.d.ts +3 -3
  115. package/dist/memory/event-store.js +3 -10
  116. package/dist/memory/finding-store.d.ts +3 -2
  117. package/dist/memory/finding-store.js +2 -7
  118. package/dist/memory/graph-read.d.ts +52 -0
  119. package/dist/memory/graph-read.js +130 -0
  120. package/dist/memory/judgment-types.d.ts +394 -0
  121. package/dist/memory/judgment-types.js +16 -0
  122. package/dist/memory/provenance-audit.d.ts +5 -2
  123. package/dist/memory/provenance-audit.js +8 -14
  124. package/dist/memory/provenance-live.d.ts +141 -0
  125. package/dist/memory/provenance-live.js +409 -0
  126. package/dist/memory/provenance-query.d.ts +5 -4
  127. package/dist/memory/provenance-query.js +21 -29
  128. package/dist/memory/provenance-resolver.d.ts +191 -0
  129. package/dist/memory/provenance-resolver.js +155 -0
  130. package/dist/memory/provenance.d.ts +1 -11
  131. package/dist/memory/provenance.js +2 -33
  132. package/dist/memory/recall-sanitize.d.ts +55 -0
  133. package/dist/memory/recall-sanitize.js +144 -0
  134. package/dist/memory/secret-filter.d.ts +32 -0
  135. package/dist/memory/secret-filter.js +126 -0
  136. package/dist/memory/truth-store.d.ts +2 -1
  137. package/dist/memory/truth-store.js +1 -4
  138. package/dist/memory/types.d.ts +74 -24
  139. package/dist/memory/types.js +75 -5
  140. package/dist/memory/write-adapters.d.ts +98 -0
  141. package/dist/memory/write-adapters.js +242 -0
  142. package/dist/operations/owner-action-effects.d.ts +53 -0
  143. package/dist/operations/owner-action-effects.js +96 -0
  144. package/dist/provenance/source-ref.d.ts +1 -1
  145. package/dist/provenance/source-ref.js +0 -2
  146. package/dist/registry/corrections.d.ts +31 -0
  147. package/dist/registry/corrections.js +332 -0
  148. package/dist/registry/record-identity.d.ts +49 -0
  149. package/dist/registry/record-identity.js +133 -0
  150. package/dist/registry/store.d.ts +101 -0
  151. package/dist/registry/store.js +395 -0
  152. package/dist/registry/types.d.ts +28 -0
  153. package/dist/registry/types.js +5 -0
  154. package/dist/relevance-scorer.js +2 -2
  155. package/dist/runtime/agent-event-bus.d.ts +50 -0
  156. package/dist/runtime/agent-event-bus.js +101 -0
  157. package/dist/runtime/drivers/claude-cli-wrapper.d.ts +155 -0
  158. package/dist/runtime/drivers/claude-cli-wrapper.js +392 -0
  159. package/dist/runtime/drivers/cli-arg-redaction.d.ts +2 -0
  160. package/dist/runtime/drivers/cli-arg-redaction.js +18 -0
  161. package/dist/runtime/drivers/cli-secret-redaction.d.ts +17 -0
  162. package/dist/runtime/drivers/cli-secret-redaction.js +126 -0
  163. package/dist/runtime/drivers/codex-app-server-process.d.ts +277 -0
  164. package/dist/runtime/drivers/codex-app-server-process.js +2342 -0
  165. package/dist/runtime/drivers/codex-auxiliary-tools.d.ts +17 -0
  166. package/dist/runtime/drivers/codex-auxiliary-tools.js +267 -0
  167. package/dist/runtime/drivers/codex-home.d.ts +20 -0
  168. package/dist/runtime/drivers/codex-home.js +674 -0
  169. package/dist/runtime/drivers/codex-thread-registry.d.ts +63 -0
  170. package/dist/runtime/drivers/codex-thread-registry.js +433 -0
  171. package/dist/runtime/drivers/persistent-cli-adapter.d.ts +160 -0
  172. package/dist/runtime/drivers/persistent-cli-adapter.js +396 -0
  173. package/dist/runtime/drivers/persistent-cli-process.d.ts +424 -0
  174. package/dist/runtime/drivers/persistent-cli-process.js +1543 -0
  175. package/dist/runtime/drivers/types.d.ts +456 -0
  176. package/dist/runtime/drivers/types.js +110 -0
  177. package/dist/runtime/mailbox.d.ts +223 -0
  178. package/dist/runtime/mailbox.js +582 -0
  179. package/dist/runtime/model-run-store.d.ts +28 -0
  180. package/dist/{model-runs/store.js → runtime/model-run-store.js} +81 -41
  181. package/dist/runtime/model-run-types.d.ts +132 -0
  182. package/dist/{model-runs/types.js → runtime/model-run-types.js} +1 -1
  183. package/dist/runtime/native-effect-observer.d.ts +22 -0
  184. package/dist/runtime/native-effect-observer.js +103 -0
  185. package/dist/runtime/native-input-journal.d.ts +46 -0
  186. package/dist/runtime/native-input-journal.js +308 -0
  187. package/dist/runtime/native-prompt.d.ts +118 -0
  188. package/dist/runtime/native-prompt.js +496 -0
  189. package/dist/runtime/native-session.d.ts +10 -0
  190. package/dist/{agent-graph/index.js → runtime/native-session.js} +9 -6
  191. package/dist/runtime/native-tool-trace-observer.d.ts +5 -0
  192. package/dist/runtime/native-tool-trace-observer.js +65 -0
  193. package/dist/runtime/native-turn.d.ts +272 -0
  194. package/dist/runtime/native-turn.js +1041 -0
  195. package/dist/runtime/operations.d.ts +236 -0
  196. package/dist/runtime/operations.js +565 -0
  197. package/dist/runtime/post-tool-handler.d.ts +74 -0
  198. package/dist/runtime/post-tool-handler.js +137 -0
  199. package/dist/runtime/prompt-layers.d.ts +126 -0
  200. package/dist/runtime/prompt-layers.js +239 -0
  201. package/dist/runtime/runtime-process.d.ts +102 -0
  202. package/dist/runtime/runtime-process.js +206 -0
  203. package/dist/runtime/runtime.d.ts +278 -0
  204. package/dist/runtime/runtime.js +563 -0
  205. package/dist/runtime/session-pool.d.ts +176 -0
  206. package/dist/runtime/session-pool.js +369 -0
  207. package/dist/runtime/stimulus-payload.d.ts +5 -0
  208. package/dist/runtime/stimulus-payload.js +50 -0
  209. package/dist/runtime/subagent-bridge.d.ts +24 -0
  210. package/dist/{agent-graph/types.js → runtime/subagent-bridge.js} +1 -1
  211. package/dist/runtime/text-completion.d.ts +22 -0
  212. package/dist/{agent-situation/types.js → runtime/text-completion.js} +1 -1
  213. package/dist/runtime/token-estimator.d.ts +25 -0
  214. package/dist/runtime/token-estimator.js +75 -0
  215. package/dist/runtime/tool-trace-store.d.ts +22 -0
  216. package/dist/runtime/tool-trace-store.js +242 -0
  217. package/dist/runtime/trace-summary.d.ts +5 -0
  218. package/dist/runtime/trace-summary.js +74 -0
  219. package/dist/runtime/turn-text.d.ts +23 -0
  220. package/dist/runtime/turn-text.js +41 -0
  221. package/dist/storage/database.d.ts +67 -0
  222. package/dist/storage/database.js +158 -0
  223. package/package.json +20 -34
  224. package/dist/agent-graph/alias-write.d.ts +0 -3
  225. package/dist/agent-graph/alias-write.js +0 -234
  226. package/dist/agent-graph/entity-resolve.d.ts +0 -3
  227. package/dist/agent-graph/entity-resolve.js +0 -271
  228. package/dist/agent-graph/errors.d.ts +0 -4
  229. package/dist/agent-graph/errors.js +0 -11
  230. package/dist/agent-graph/graph-query.d.ts +0 -5
  231. package/dist/agent-graph/graph-query.js +0 -360
  232. package/dist/agent-graph/index.d.ts +0 -6
  233. package/dist/agent-situation/builder.d.ts +0 -8
  234. package/dist/agent-situation/builder.js +0 -239
  235. package/dist/agent-situation/cache-key.d.ts +0 -4
  236. package/dist/agent-situation/cache-key.js +0 -64
  237. package/dist/agent-situation/index.d.ts +0 -7
  238. package/dist/agent-situation/index.js +0 -28
  239. package/dist/agent-situation/packet-store.d.ts +0 -27
  240. package/dist/agent-situation/packet-store.js +0 -228
  241. package/dist/agent-situation/ranking-policy.d.ts +0 -18
  242. package/dist/agent-situation/ranking-policy.js +0 -75
  243. package/dist/agent-situation/source-readers.d.ts +0 -52
  244. package/dist/agent-situation/source-readers.js +0 -300
  245. package/dist/agent-situation/types.d.ts +0 -195
  246. package/dist/cases/wiki-page-index.d.ts +0 -37
  247. package/dist/cases/wiki-page-index.js +0 -201
  248. package/dist/config-loader.d.ts +0 -68
  249. package/dist/config-loader.js +0 -239
  250. package/dist/connectors/event-index.d.ts +0 -24
  251. package/dist/connectors/event-index.js +0 -245
  252. package/dist/connectors/raw-query.d.ts +0 -40
  253. package/dist/connectors/raw-query.js +0 -412
  254. package/dist/connectors/types.d.ts +0 -117
  255. package/dist/connectors/types.js +0 -3
  256. package/dist/context-compile/boundary-defaults.d.ts +0 -12
  257. package/dist/context-compile/boundary-defaults.js +0 -105
  258. package/dist/context-compile/channel-grant.js +0 -66
  259. package/dist/context-compile/compiler-policy.d.ts +0 -39
  260. package/dist/context-compile/compiler-policy.js +0 -147
  261. package/dist/context-compile/compiler.d.ts +0 -18
  262. package/dist/context-compile/compiler.js +0 -404
  263. package/dist/context-compile/index.d.ts +0 -10
  264. package/dist/context-compile/index.js +0 -26
  265. package/dist/context-compile/packet-store.d.ts +0 -8
  266. package/dist/context-compile/packet-store.js +0 -239
  267. package/dist/context-compile/ref.d.ts +0 -7
  268. package/dist/context-compile/ref.js +0 -102
  269. package/dist/context-compile/source-readers.d.ts +0 -70
  270. package/dist/context-compile/source-readers.js +0 -840
  271. package/dist/context-compile/types.d.ts +0 -155
  272. package/dist/context-compile/types.js +0 -11
  273. package/dist/context-compile/visibility.d.ts +0 -21
  274. package/dist/context-compile/visibility.js +0 -224
  275. package/dist/decision-tracker.d.ts +0 -206
  276. package/dist/decision-tracker.js +0 -481
  277. package/dist/edges/ref-validation.d.ts +0 -7
  278. package/dist/edges/ref-validation.js +0 -321
  279. package/dist/edges/store.d.ts +0 -8
  280. package/dist/edges/store.js +0 -129
  281. package/dist/embedding-client.d.ts +0 -28
  282. package/dist/embedding-client.js +0 -53
  283. package/dist/embedding-server/index.d.ts +0 -67
  284. package/dist/embedding-server/index.js +0 -405
  285. package/dist/embedding-server/mobile/auth.d.ts +0 -44
  286. package/dist/embedding-server/mobile/auth.js +0 -150
  287. package/dist/embedding-server/mobile/daemon.d.ts +0 -129
  288. package/dist/embedding-server/mobile/daemon.js +0 -313
  289. package/dist/embedding-server/mobile/output-parser.d.ts +0 -115
  290. package/dist/embedding-server/mobile/output-parser.js +0 -241
  291. package/dist/embedding-server/mobile/session-api.d.ts +0 -57
  292. package/dist/embedding-server/mobile/session-api.js +0 -261
  293. package/dist/embedding-server/mobile/session-manager.d.ts +0 -138
  294. package/dist/embedding-server/mobile/session-manager.js +0 -378
  295. package/dist/embedding-server/mobile/websocket-handler.d.ts +0 -137
  296. package/dist/embedding-server/mobile/websocket-handler.js +0 -486
  297. package/dist/embeddings.d.ts +0 -68
  298. package/dist/embeddings.js +0 -244
  299. package/dist/entities/audit-metrics.d.ts +0 -68
  300. package/dist/entities/audit-metrics.js +0 -124
  301. package/dist/entities/candidate-generator.d.ts +0 -8
  302. package/dist/entities/candidate-generator.js +0 -24
  303. package/dist/entities/entity-linked-decision-counts.d.ts +0 -2
  304. package/dist/entities/entity-linked-decision-counts.js +0 -29
  305. package/dist/entities/entity-list.d.ts +0 -22
  306. package/dist/entities/entity-list.js +0 -3
  307. package/dist/entities/entity-orphan-list.d.ts +0 -17
  308. package/dist/entities/entity-orphan-list.js +0 -3
  309. package/dist/entities/entity-search.d.ts +0 -20
  310. package/dist/entities/entity-search.js +0 -3
  311. package/dist/entities/errors.d.ts +0 -55
  312. package/dist/entities/errors.js +0 -100
  313. package/dist/entities/lineage-store.d.ts +0 -28
  314. package/dist/entities/lineage-store.js +0 -204
  315. package/dist/entities/normalization.d.ts +0 -14
  316. package/dist/entities/normalization.js +0 -63
  317. package/dist/entities/policy-store.d.ts +0 -8
  318. package/dist/entities/policy-store.js +0 -75
  319. package/dist/entities/policy-types.d.ts +0 -72
  320. package/dist/entities/policy-types.js +0 -59
  321. package/dist/entities/projection.d.ts +0 -8
  322. package/dist/entities/projection.js +0 -82
  323. package/dist/entities/provenance-query.d.ts +0 -32
  324. package/dist/entities/provenance-query.js +0 -3
  325. package/dist/entities/read-identity.d.ts +0 -31
  326. package/dist/entities/read-identity.js +0 -264
  327. package/dist/entities/recall-bridge.d.ts +0 -5
  328. package/dist/entities/recall-bridge.js +0 -171
  329. package/dist/entities/resolution-engine.d.ts +0 -8
  330. package/dist/entities/resolution-engine.js +0 -3
  331. package/dist/entities/rollback-preview.d.ts +0 -35
  332. package/dist/entities/rollback-preview.js +0 -3
  333. package/dist/entities/source-locator.d.ts +0 -3
  334. package/dist/entities/source-locator.js +0 -32
  335. package/dist/entities/store.d.ts +0 -69
  336. package/dist/entities/store.js +0 -544
  337. package/dist/entities/types.d.ts +0 -166
  338. package/dist/entities/types.js +0 -30
  339. package/dist/memory/extraction-prompt.d.ts +0 -4
  340. package/dist/memory/extraction-prompt.js +0 -89
  341. package/dist/memory/scope-backfill.d.ts +0 -14
  342. package/dist/memory/scope-backfill.js +0 -3
  343. package/dist/memory/scope-store.d.ts +0 -4
  344. package/dist/memory/scope-store.js +0 -9
  345. package/dist/memory-store.d.ts +0 -87
  346. package/dist/memory-store.js +0 -78
  347. package/dist/model-runs/store.d.ts +0 -13
  348. package/dist/model-runs/tool-trace-store.d.ts +0 -4
  349. package/dist/model-runs/tool-trace-store.js +0 -118
  350. package/dist/model-runs/types.d.ts +0 -72
  351. package/dist/notification-manager.d.ts +0 -7
  352. package/dist/notification-manager.js +0 -12
  353. package/dist/outcome-tracker.d.ts +0 -151
  354. package/dist/outcome-tracker.js +0 -271
  355. package/dist/query-intent.d.ts +0 -23
  356. package/dist/query-intent.js +0 -114
  357. package/dist/runtime/trusted-provenance.d.ts +0 -3
  358. package/dist/runtime/trusted-provenance.js +0 -6
  359. package/dist/search/question-type.d.ts +0 -5
  360. package/dist/search/question-type.js +0 -41
  361. package/dist/test-utils.d.ts +0 -80
  362. package/dist/test-utils.js +0 -218
  363. package/dist/tier-validator.d.ts +0 -43
  364. package/dist/tier-validator.js +0 -159
  365. package/dist/time-formatter.d.ts +0 -25
  366. package/dist/time-formatter.js +0 -93
  367. /package/dist/{search → knowledge}/feedback-store.d.ts +0 -0
  368. /package/dist/{search → knowledge}/feedback-store.js +0 -0
  369. /package/dist/{search → knowledge}/ranker-features.d.ts +0 -0
  370. /package/dist/{search → knowledge}/ranker-rescore.d.ts +0 -0
  371. /package/dist/{search → knowledge}/ranker-rescore.js +0 -0
  372. /package/dist/{search → knowledge}/ranker-trainer.d.ts +0 -0
  373. /package/dist/{search → knowledge}/ranker-trainer.js +0 -0
  374. /package/dist/{search → knowledge}/search-quality.js +0 -0
@@ -0,0 +1,674 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_CODEX_REASONING_EFFORT = exports.CODEX_REASONING_EFFORTS = void 0;
4
+ exports.buildMAMACodexAppServerConfig = buildMAMACodexAppServerConfig;
5
+ exports.buildCodexAppServerLaunchConfig = buildCodexAppServerLaunchConfig;
6
+ const fs_1 = require("fs");
7
+ const node_crypto_1 = require("node:crypto");
8
+ const ENV_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
9
+ const SERVER_NAME_PATTERN = /^[A-Za-z0-9_.-]+$/;
10
+ const AUTH_MODES = new Set(['oauth', 'chatgpt']);
11
+ const APPROVAL_MODES = new Set(['auto', 'prompt', 'writes', 'approve']);
12
+ const HTTP_HEADER_NAME_PATTERN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
13
+ const ROOT_FIELDS = new Set(['mcpServers', '_installedBy']);
14
+ const SERVER_FIELDS = new Set([
15
+ 'command',
16
+ 'args',
17
+ 'env',
18
+ 'env_vars',
19
+ 'cwd',
20
+ 'experimental_environment',
21
+ 'url',
22
+ 'auth',
23
+ 'bearer_token_env_var',
24
+ 'http_headers',
25
+ 'env_http_headers',
26
+ 'required',
27
+ 'supports_parallel_tool_calls',
28
+ 'environment_id',
29
+ 'startup_timeout_sec',
30
+ 'startup_timeout_ms',
31
+ 'tool_timeout_sec',
32
+ 'tool_timeout_ms',
33
+ 'enabled',
34
+ 'enabled_tools',
35
+ 'disabled_tools',
36
+ 'allowed_tools',
37
+ 'denied_tools',
38
+ 'default_tools_approval_mode',
39
+ 'tools',
40
+ 'scopes',
41
+ 'oauth_resource',
42
+ '_installedBy',
43
+ ]);
44
+ function isRecord(value) {
45
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
46
+ }
47
+ function rejectUnknownFields(value, allowed, location) {
48
+ for (const key of Object.keys(value)) {
49
+ validateTomlString(key, `${location} field name`);
50
+ if (!allowed.has(key)) {
51
+ throw new Error(`Unsupported field ${location}.${key}`);
52
+ }
53
+ }
54
+ }
55
+ function requireString(value, location) {
56
+ if (typeof value !== 'string' || value.length === 0) {
57
+ throw new Error(`${location} must be a non-empty string`);
58
+ }
59
+ validateTomlString(value, location);
60
+ return value;
61
+ }
62
+ function validateUnicodeScalarString(value, location) {
63
+ for (let index = 0; index < value.length; index += 1) {
64
+ const codeUnit = value.charCodeAt(index);
65
+ if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {
66
+ const next = value.charCodeAt(index + 1);
67
+ if (index + 1 >= value.length || next < 0xdc00 || next > 0xdfff) {
68
+ throw new Error(`${location} must contain only Unicode scalar values`);
69
+ }
70
+ index += 1;
71
+ }
72
+ else if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) {
73
+ throw new Error(`${location} must contain only Unicode scalar values`);
74
+ }
75
+ }
76
+ }
77
+ function validateTomlString(value, location) {
78
+ validateUnicodeScalarString(value, location);
79
+ for (let index = 0; index < value.length; index += 1) {
80
+ const codeUnit = value.charCodeAt(index);
81
+ if (codeUnit <= 0x1f || codeUnit === 0x7f) {
82
+ throw new Error(`${location} must not contain TOML control characters`);
83
+ }
84
+ }
85
+ }
86
+ function validateChildEnvValue(value, location) {
87
+ validateUnicodeScalarString(value, location);
88
+ if (value.includes('\0')) {
89
+ throw new Error(`${location} must not contain NUL`);
90
+ }
91
+ }
92
+ function validateHttpHeaderValue(value, location) {
93
+ validateUnicodeScalarString(value, location);
94
+ for (let index = 0; index < value.length; index += 1) {
95
+ const codeUnit = value.charCodeAt(index);
96
+ if ((codeUnit <= 0x1f && codeUnit !== 0x09) || codeUnit === 0x7f) {
97
+ throw new Error(`${location} contains an invalid HTTP header value`);
98
+ }
99
+ }
100
+ }
101
+ function optionalString(value, location) {
102
+ return value === undefined ? undefined : requireString(value, location);
103
+ }
104
+ function optionalBoolean(value, location) {
105
+ if (value === undefined) {
106
+ return undefined;
107
+ }
108
+ if (typeof value !== 'boolean') {
109
+ throw new Error(`${location} must be a boolean`);
110
+ }
111
+ return value;
112
+ }
113
+ function optionalPositiveNumber(value, location) {
114
+ if (value === undefined) {
115
+ return undefined;
116
+ }
117
+ if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
118
+ throw new Error(`${location} must be a positive finite number`);
119
+ }
120
+ return value;
121
+ }
122
+ function optionalStringArray(value, location) {
123
+ if (value === undefined) {
124
+ return undefined;
125
+ }
126
+ if (!Array.isArray(value) || value.some((entry) => typeof entry !== 'string')) {
127
+ throw new Error(`${location} must be an array of strings`);
128
+ }
129
+ return value.map((entry, index) => {
130
+ validateTomlString(entry, `${location}[${index}]`);
131
+ return entry;
132
+ });
133
+ }
134
+ function codeUnitCompare(left, right) {
135
+ return left < right ? -1 : left > right ? 1 : 0;
136
+ }
137
+ function optionalStringSet(value, location) {
138
+ const entries = optionalStringArray(value, location);
139
+ return entries === undefined ? undefined : [...new Set(entries)].sort(codeUnitCompare);
140
+ }
141
+ function requireEnum(value, allowed, location) {
142
+ const result = requireString(value, location);
143
+ if (!allowed.has(result)) {
144
+ throw new Error(`${location} has an unsupported value`);
145
+ }
146
+ return result;
147
+ }
148
+ function stringRecord(value, location, validateValue = validateTomlString) {
149
+ if (value === undefined) {
150
+ return undefined;
151
+ }
152
+ if (!isRecord(value)) {
153
+ throw new Error(`${location} must be an object`);
154
+ }
155
+ const result = Object.create(null);
156
+ for (const key of Object.keys(value).sort()) {
157
+ validateTomlString(key, `${location} key`);
158
+ const entry = value[key];
159
+ if (typeof entry !== 'string') {
160
+ throw new Error(`${location}.${key} must be a string`);
161
+ }
162
+ validateValue(entry, `${location}.${key}`);
163
+ result[key] = entry;
164
+ }
165
+ return result;
166
+ }
167
+ function validateEnvName(name, location) {
168
+ validateUnicodeScalarString(name, location);
169
+ if (!ENV_NAME_PATTERN.test(name)) {
170
+ throw new Error(`${location} contains invalid environment name ${name}`);
171
+ }
172
+ }
173
+ function validateHeaderName(name, location) {
174
+ validateUnicodeScalarString(name, location);
175
+ if (!HTTP_HEADER_NAME_PATTERN.test(name)) {
176
+ throw new Error(`${location} contains an invalid HTTP header name`);
177
+ }
178
+ }
179
+ function validateHttpUrl(value, location) {
180
+ let parsed;
181
+ try {
182
+ parsed = new URL(value);
183
+ }
184
+ catch {
185
+ throw new Error(`${location} must be a valid HTTP URL`);
186
+ }
187
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
188
+ throw new Error(`${location} must use http or https`);
189
+ }
190
+ if (parsed.username !== '' || parsed.password !== '') {
191
+ throw new Error(`${location} must not contain user information`);
192
+ }
193
+ if (value.includes('?')) {
194
+ throw new Error(`${location} must not contain a query; use environment-backed authentication`);
195
+ }
196
+ if (value.includes('#')) {
197
+ throw new Error(`${location} must not contain a fragment`);
198
+ }
199
+ return value;
200
+ }
201
+ function tomlBooleanOrNumber(value) {
202
+ return String(value);
203
+ }
204
+ function tomlInlineApprovalTable(value, location) {
205
+ if (value === undefined) {
206
+ return undefined;
207
+ }
208
+ if (!isRecord(value)) {
209
+ throw new Error(`${location} must be an object`);
210
+ }
211
+ const entries = [];
212
+ for (const toolName of Object.keys(value).sort()) {
213
+ validateTomlString(toolName, `${location} tool name`);
214
+ if (!SERVER_NAME_PATTERN.test(toolName)) {
215
+ throw new Error(`${location} contains invalid tool name ${toolName}`);
216
+ }
217
+ const tool = value[toolName];
218
+ if (!isRecord(tool)) {
219
+ throw new Error(`${location}.${toolName} must be an object`);
220
+ }
221
+ rejectUnknownFields(tool, new Set(['approval_mode']), `${location}.${toolName}`);
222
+ const approvalMode = requireEnum(tool.approval_mode, APPROVAL_MODES, `${location}.${toolName}.approval_mode`);
223
+ entries.push(`${tomlString(toolName)} = { approval_mode = ${tomlString(approvalMode)} }`);
224
+ }
225
+ return `{ ${entries.join(', ')} }`;
226
+ }
227
+ function normalizedApprovalTools(value, location) {
228
+ if (value === undefined) {
229
+ return undefined;
230
+ }
231
+ if (!isRecord(value)) {
232
+ throw new Error(`${location} must be an object`);
233
+ }
234
+ const result = Object.create(null);
235
+ for (const toolName of Object.keys(value).sort()) {
236
+ const tool = value[toolName];
237
+ if (!isRecord(tool)) {
238
+ throw new Error(`${location}.${toolName} must be an object`);
239
+ }
240
+ const normalizedTool = Object.create(null);
241
+ normalizedTool.approval_mode = requireEnum(tool.approval_mode, APPROVAL_MODES, `${location}.${toolName}.approval_mode`);
242
+ result[toolName] = normalizedTool;
243
+ }
244
+ return result;
245
+ }
246
+ function addOverride(args, path, value) {
247
+ args.push('-c', `${path}=${value}`);
248
+ }
249
+ function consolidateMcpOverrides(overrides) {
250
+ if (overrides.length === 0) {
251
+ return [];
252
+ }
253
+ const servers = new Map();
254
+ for (let index = 1; index < overrides.length; index += 2) {
255
+ const assignment = overrides[index];
256
+ const separator = assignment.indexOf('=');
257
+ const path = assignment.slice(0, separator);
258
+ const value = assignment.slice(separator + 1);
259
+ const prefix = 'mcp_servers.';
260
+ const fieldSeparator = path.lastIndexOf('.');
261
+ const name = JSON.parse(path.slice(prefix.length, fieldSeparator));
262
+ if (typeof name !== 'string') {
263
+ throw new Error('Internal MCP override name must be a string');
264
+ }
265
+ const fields = servers.get(name) ?? [];
266
+ fields.push([path.slice(fieldSeparator + 1), value]);
267
+ servers.set(name, fields);
268
+ }
269
+ const entries = [...servers.entries()].map(([name, fields]) => {
270
+ const serialized = fields.map(([field, value]) => `${field} = ${value}`).join(', ');
271
+ return `${tomlString(name)} = { ${serialized} }`;
272
+ });
273
+ return ['-c', `mcp_servers={ ${entries.join(', ')} }`];
274
+ }
275
+ function registerUserBinding(userBindings, generatedBindings, name) {
276
+ if (generatedBindings.has(name)) {
277
+ throw new Error(`Environment binding ${name} collides with a generated secret source`);
278
+ }
279
+ userBindings.add(name);
280
+ }
281
+ function reserveGeneratedBinding(env, userBindings, generatedBindings, name, origin) {
282
+ const existing = generatedBindings.get(name);
283
+ if (existing !== undefined && existing !== origin) {
284
+ throw new Error(`Generated secret source ${name} has conflicting origins`);
285
+ }
286
+ if (existing === origin) {
287
+ return;
288
+ }
289
+ if (Object.prototype.hasOwnProperty.call(env, name) || userBindings.has(name)) {
290
+ throw new Error(`Generated secret source ${name} collides with a user environment binding`);
291
+ }
292
+ generatedBindings.set(name, origin);
293
+ }
294
+ function setChildSecret(env, name, value, configuredNames) {
295
+ const configured = configuredNames.get(name);
296
+ if (configured !== undefined && configured !== value) {
297
+ throw new Error(`Conflicting values configured for environment name ${name}`);
298
+ }
299
+ const inherited = env[name];
300
+ if (inherited !== undefined && inherited !== value) {
301
+ throw new Error(`Configured value conflicts with inherited environment name ${name}`);
302
+ }
303
+ configuredNames.set(name, value);
304
+ env[name] = value;
305
+ }
306
+ function generatedHeaderEnvName(serverName, headerName) {
307
+ const server = serverName.toUpperCase().replace(/[^A-Z0-9_]/g, '_');
308
+ const header = headerName.toUpperCase().replace(/[^A-Z0-9_]/g, '_');
309
+ const suffix = (0, node_crypto_1.createHash)('sha256')
310
+ .update(`${serverName}\0${headerName}`)
311
+ .digest('hex')
312
+ .slice(0, 12)
313
+ .toUpperCase();
314
+ return `MAMA_MCP_${server}_HTTP_HEADER_${header}_${suffix}`;
315
+ }
316
+ function fingerprintPolicy(value) {
317
+ return (0, node_crypto_1.createHash)('sha256').update(JSON.stringify(value)).digest('hex');
318
+ }
319
+ function tomlString(value) {
320
+ validateTomlString(value, 'TOML string');
321
+ return JSON.stringify(value);
322
+ }
323
+ function tomlStringArray(values) {
324
+ return `[${values.map(tomlString).join(', ')}]`;
325
+ }
326
+ function tomlInlineQuotedStringTable(values) {
327
+ const entries = Object.entries(values).map(([key, value]) => `${tomlString(key)} = ${tomlString(value)}`);
328
+ return `{ ${entries.join(', ')} }`;
329
+ }
330
+ exports.CODEX_REASONING_EFFORTS = ['low', 'medium', 'high', 'xhigh', 'max'];
331
+ exports.DEFAULT_CODEX_REASONING_EFFORT = 'high';
332
+ /**
333
+ * Unset means the default; anything else must be a value Codex actually accepts.
334
+ * Coercing an unknown effort to the default would silently run the whole install
335
+ * at a reasoning level the owner did not ask for, so it throws instead.
336
+ */
337
+ function resolveCodexReasoningEffort(effort) {
338
+ if (effort === undefined || effort === null || effort === '') {
339
+ return exports.DEFAULT_CODEX_REASONING_EFFORT;
340
+ }
341
+ if (!exports.CODEX_REASONING_EFFORTS.includes(effort)) {
342
+ throw new Error(`Unsupported Codex reasoning effort "${effort}"; expected one of ${exports.CODEX_REASONING_EFFORTS.join(', ')}`);
343
+ }
344
+ return effort;
345
+ }
346
+ function buildMAMACodexAppServerConfig(effort, hostNotes, options = {}) {
347
+ return [
348
+ ...(options.webSearch ? ['web_search = "live"'] : []),
349
+ options.deniedReadPaths?.length
350
+ ? 'approval_policy = "never"'
351
+ : 'approval_policy = "on-request"',
352
+ ...(options.deniedReadPaths?.length
353
+ ? ['default_permissions = "host-workspace"']
354
+ : ['sandbox_mode = "workspace-write"']),
355
+ `model_reasoning_effort = ${tomlString(resolveCodexReasoningEffort(effort))}`,
356
+ 'instructions = ""',
357
+ 'developer_instructions = ""',
358
+ 'include_apps_instructions = false',
359
+ 'include_environment_context = false',
360
+ ...(options.allowLoginShell === undefined
361
+ ? []
362
+ : [`allow_login_shell = ${options.allowLoginShell}`]),
363
+ ...(options.shellEnvironment === undefined
364
+ ? []
365
+ : [
366
+ '',
367
+ '[shell_environment_policy.set]',
368
+ ...Object.entries(options.shellEnvironment).map(([name, value]) => `${tomlString(name)} = ${tomlString(value)}`),
369
+ ]),
370
+ '',
371
+ ...(options.deniedReadPaths?.length
372
+ ? [
373
+ '[permissions.host-workspace]',
374
+ 'extends = ":workspace"',
375
+ '[permissions.host-workspace.filesystem]',
376
+ ...options.deniedReadPaths.map((path) => `${tomlString(path)} = "deny"`),
377
+ '[permissions.host-workspace.network]',
378
+ 'enabled = false',
379
+ '',
380
+ ]
381
+ : []),
382
+ '[analytics]',
383
+ 'enabled = false',
384
+ '',
385
+ '[features]',
386
+ // The owner agent may create native Codex subagents when it decides a goal
387
+ // needs parallel or specialized work. Channels never create agents.
388
+ 'multi_agent = true',
389
+ 'plugins = false',
390
+ 'apps = false',
391
+ 'tool_search = false',
392
+ `shell_tool = ${options.shellTool ?? false}`,
393
+ 'unified_exec = false',
394
+ `web_search = ${options.webSearch ?? false}`,
395
+ 'browser_use = false',
396
+ 'computer_use = false',
397
+ 'image_generation = false',
398
+ '',
399
+ // What the host owns and what this file must not carry. The sentence is
400
+ // the product's, so the product supplies it.
401
+ ...(hostNotes ?? [
402
+ '# The host owns identity, skills, memory tools and evidence gates.',
403
+ '# The app-server is isolated under the managed host home.',
404
+ '# Runner-specific MCP servers are supplied per process and never written here.',
405
+ ]),
406
+ ].join('\n');
407
+ }
408
+ function buildCodexAppServerLaunchConfig(mcpConfigPath, processEnv) {
409
+ const childEnv = Object.create(null);
410
+ for (const [name, value] of Object.entries(processEnv)) {
411
+ childEnv[name] = value;
412
+ }
413
+ if (mcpConfigPath === undefined) {
414
+ return {
415
+ args: [],
416
+ env: childEnv,
417
+ fingerprint: fingerprintPolicy({}),
418
+ secretFingerprint: fingerprintPolicy({}),
419
+ };
420
+ }
421
+ let parsed;
422
+ try {
423
+ parsed = JSON.parse((0, fs_1.readFileSync)(mcpConfigPath, 'utf-8'));
424
+ }
425
+ catch (error) {
426
+ const reason = error instanceof SyntaxError ? 'invalid JSON' : 'unreadable file';
427
+ throw new Error(`MCP config is ${reason}`);
428
+ }
429
+ if (!isRecord(parsed)) {
430
+ throw new Error('MCP config root must be an object');
431
+ }
432
+ rejectUnknownFields(parsed, ROOT_FIELDS, 'root');
433
+ if (!isRecord(parsed.mcpServers)) {
434
+ throw new Error('root.mcpServers must be an object');
435
+ }
436
+ const mcpServers = parsed.mcpServers;
437
+ const args = [];
438
+ const configuredNames = new Map();
439
+ const userBindings = new Set();
440
+ const generatedBindings = new Map();
441
+ const normalizedServers = Object.create(null);
442
+ for (const name of Object.keys(mcpServers).sort()) {
443
+ validateTomlString(name, 'MCP server name');
444
+ if (!SERVER_NAME_PATTERN.test(name)) {
445
+ throw new Error(`Invalid MCP server name ${name}`);
446
+ }
447
+ const raw = mcpServers[name];
448
+ if (!isRecord(raw)) {
449
+ throw new Error(`mcpServers.${name} must be an object`);
450
+ }
451
+ rejectUnknownFields(raw, SERVER_FIELDS, `mcpServers.${name}`);
452
+ // MAMA is owned by the canonical native host bridge. Passing the server
453
+ // to app-server would create an unprojected bypass around role, runtime,
454
+ // tier, and envelope enforcement.
455
+ if (name === 'mama') {
456
+ continue;
457
+ }
458
+ const location = `mcpServers.${name}`;
459
+ const command = optionalString(raw.command, `${location}.command`);
460
+ const rawUrl = optionalString(raw.url, `${location}.url`);
461
+ const url = rawUrl === undefined ? undefined : validateHttpUrl(rawUrl, `${location}.url`);
462
+ if ((command === undefined) === (url === undefined)) {
463
+ throw new Error(`${location} must configure exactly one of command or url`);
464
+ }
465
+ const base = `mcp_servers.${tomlString(name)}`;
466
+ const normalized = Object.create(null);
467
+ normalized.transport = command === undefined ? 'http' : 'stdio';
468
+ if (command !== undefined) {
469
+ addOverride(args, `${base}.command`, tomlString(command));
470
+ normalized.command = command;
471
+ }
472
+ else if (url !== undefined) {
473
+ addOverride(args, `${base}.url`, tomlString(url));
474
+ normalized.url = url;
475
+ }
476
+ const serverArgs = optionalStringArray(raw.args, `${location}.args`);
477
+ if (serverArgs !== undefined) {
478
+ if (command === undefined) {
479
+ throw new Error(`${location}.args is only valid for stdio servers`);
480
+ }
481
+ addOverride(args, `${base}.args`, tomlStringArray(serverArgs));
482
+ normalized.args = serverArgs;
483
+ }
484
+ const literalEnv = stringRecord(raw.env, `${location}.env`, validateChildEnvValue);
485
+ const inheritedEnvNames = optionalStringArray(raw.env_vars, `${location}.env_vars`);
486
+ if ((literalEnv !== undefined || inheritedEnvNames !== undefined) && command === undefined) {
487
+ throw new Error(`${location}.env and env_vars are only valid for stdio servers`);
488
+ }
489
+ const allEnvNames = new Set();
490
+ for (const envName of inheritedEnvNames ?? []) {
491
+ validateEnvName(envName, `${location}.env_vars`);
492
+ registerUserBinding(userBindings, generatedBindings, envName);
493
+ allEnvNames.add(envName);
494
+ }
495
+ for (const [envName, value] of Object.entries(literalEnv ?? {})) {
496
+ validateEnvName(envName, `${location}.env`);
497
+ registerUserBinding(userBindings, generatedBindings, envName);
498
+ setChildSecret(childEnv, envName, value, configuredNames);
499
+ allEnvNames.add(envName);
500
+ }
501
+ if (allEnvNames.size > 0) {
502
+ const envNames = [...allEnvNames].sort();
503
+ addOverride(args, `${base}.env_vars`, tomlStringArray(envNames));
504
+ normalized.env_vars = envNames;
505
+ }
506
+ const cwd = optionalString(raw.cwd, `${location}.cwd`);
507
+ if (cwd !== undefined) {
508
+ if (command === undefined) {
509
+ throw new Error(`${location}.cwd is only valid for stdio servers`);
510
+ }
511
+ addOverride(args, `${base}.cwd`, tomlString(cwd));
512
+ normalized.cwd = cwd;
513
+ }
514
+ const experimentalEnvironment = optionalString(raw.experimental_environment, `${location}.experimental_environment`);
515
+ if (experimentalEnvironment !== undefined && command === undefined) {
516
+ throw new Error(`${location}.experimental_environment is only valid for stdio servers`);
517
+ }
518
+ const environmentId = optionalString(raw.environment_id, `${location}.environment_id`);
519
+ if (experimentalEnvironment !== undefined && environmentId !== undefined) {
520
+ throw new Error(`${location} cannot set both experimental_environment and environment_id`);
521
+ }
522
+ const effectiveEnvironmentId = environmentId ?? experimentalEnvironment;
523
+ if (effectiveEnvironmentId !== undefined) {
524
+ addOverride(args, `${base}.environment_id`, tomlString(effectiveEnvironmentId));
525
+ normalized.environment_id = effectiveEnvironmentId;
526
+ }
527
+ const auth = raw.auth === undefined ? undefined : requireEnum(raw.auth, AUTH_MODES, `${location}.auth`);
528
+ if (auth !== undefined) {
529
+ if (url === undefined) {
530
+ throw new Error(`${location}.auth is only valid for HTTP servers`);
531
+ }
532
+ addOverride(args, `${base}.auth`, tomlString(auth));
533
+ normalized.auth = auth;
534
+ }
535
+ const bearerTokenEnvVar = optionalString(raw.bearer_token_env_var, `${location}.bearer_token_env_var`);
536
+ if (bearerTokenEnvVar !== undefined) {
537
+ if (url === undefined) {
538
+ throw new Error(`${location}.bearer_token_env_var is only valid for HTTP servers`);
539
+ }
540
+ validateEnvName(bearerTokenEnvVar, `${location}.bearer_token_env_var`);
541
+ registerUserBinding(userBindings, generatedBindings, bearerTokenEnvVar);
542
+ addOverride(args, `${base}.bearer_token_env_var`, tomlString(bearerTokenEnvVar));
543
+ normalized.bearer_token_env_var = bearerTokenEnvVar;
544
+ }
545
+ const literalHeaders = stringRecord(raw.http_headers, `${location}.http_headers`, validateHttpHeaderValue);
546
+ const envHeaders = stringRecord(raw.env_http_headers, `${location}.env_http_headers`) ?? {};
547
+ if ((literalHeaders !== undefined || Object.keys(envHeaders).length > 0) && url === undefined) {
548
+ throw new Error(`${location} HTTP headers are only valid for HTTP servers`);
549
+ }
550
+ const effectiveHeaderBindings = Object.create(null);
551
+ for (const [headerName, envName] of Object.entries(envHeaders)) {
552
+ validateHeaderName(headerName, `${location}.env_http_headers`);
553
+ validateEnvName(envName, `${location}.env_http_headers.${headerName}`);
554
+ const canonicalHeader = headerName.toLowerCase();
555
+ if (effectiveHeaderBindings[canonicalHeader] !== undefined) {
556
+ throw new Error(`${location} configures header ${canonicalHeader} more than once`);
557
+ }
558
+ registerUserBinding(userBindings, generatedBindings, envName);
559
+ effectiveHeaderBindings[canonicalHeader] = envName;
560
+ }
561
+ for (const [headerName, value] of Object.entries(literalHeaders ?? {})) {
562
+ validateHeaderName(headerName, `${location}.http_headers`);
563
+ const canonicalHeader = headerName.toLowerCase();
564
+ if (effectiveHeaderBindings[canonicalHeader] !== undefined) {
565
+ throw new Error(`${location} configures header ${canonicalHeader} more than once`);
566
+ }
567
+ const generatedName = generatedHeaderEnvName(name, canonicalHeader);
568
+ reserveGeneratedBinding(childEnv, userBindings, generatedBindings, generatedName, `${name}:generated-header:${canonicalHeader}`);
569
+ setChildSecret(childEnv, generatedName, value, configuredNames);
570
+ effectiveHeaderBindings[canonicalHeader] = generatedName;
571
+ }
572
+ if (Object.keys(effectiveHeaderBindings).length > 0) {
573
+ const sortedBindings = Object.create(null);
574
+ for (const [headerName, envName] of Object.entries(effectiveHeaderBindings).sort(([left], [right]) => codeUnitCompare(left, right))) {
575
+ sortedBindings[headerName] = envName;
576
+ }
577
+ addOverride(args, `${base}.env_http_headers`, tomlInlineQuotedStringTable(sortedBindings));
578
+ normalized.env_http_headers = sortedBindings;
579
+ }
580
+ const required = optionalBoolean(raw.required, `${location}.required`);
581
+ const parallel = optionalBoolean(raw.supports_parallel_tool_calls, `${location}.supports_parallel_tool_calls`);
582
+ const enabled = optionalBoolean(raw.enabled, `${location}.enabled`);
583
+ for (const [field, value] of [
584
+ ['required', required],
585
+ ['supports_parallel_tool_calls', parallel],
586
+ ['enabled', enabled],
587
+ ]) {
588
+ if (value !== undefined) {
589
+ addOverride(args, `${base}.${field}`, tomlBooleanOrNumber(value));
590
+ normalized[field] = value;
591
+ }
592
+ }
593
+ const startupSeconds = optionalPositiveNumber(raw.startup_timeout_sec, `${location}.startup_timeout_sec`);
594
+ const startupMilliseconds = optionalPositiveNumber(raw.startup_timeout_ms, `${location}.startup_timeout_ms`);
595
+ const toolSeconds = optionalPositiveNumber(raw.tool_timeout_sec, `${location}.tool_timeout_sec`);
596
+ const toolMilliseconds = optionalPositiveNumber(raw.tool_timeout_ms, `${location}.tool_timeout_ms`);
597
+ if (startupSeconds !== undefined && startupMilliseconds !== undefined) {
598
+ throw new Error(`${location} cannot set both startup timeout units`);
599
+ }
600
+ if (toolSeconds !== undefined && toolMilliseconds !== undefined) {
601
+ throw new Error(`${location} cannot set both tool timeout units`);
602
+ }
603
+ const effectiveStartupSeconds = startupSeconds ??
604
+ (startupMilliseconds === undefined ? undefined : startupMilliseconds / 1000);
605
+ const effectiveToolSeconds = toolSeconds ?? (toolMilliseconds === undefined ? undefined : toolMilliseconds / 1000);
606
+ if (effectiveStartupSeconds !== undefined) {
607
+ addOverride(args, `${base}.startup_timeout_sec`, String(effectiveStartupSeconds));
608
+ normalized.startup_timeout_sec = effectiveStartupSeconds;
609
+ }
610
+ if (effectiveToolSeconds !== undefined) {
611
+ addOverride(args, `${base}.tool_timeout_sec`, String(effectiveToolSeconds));
612
+ normalized.tool_timeout_sec = effectiveToolSeconds;
613
+ }
614
+ const enabledTools = optionalStringSet(raw.enabled_tools, `${location}.enabled_tools`);
615
+ const allowedTools = optionalStringSet(raw.allowed_tools, `${location}.allowed_tools`);
616
+ const disabledTools = optionalStringSet(raw.disabled_tools, `${location}.disabled_tools`);
617
+ const deniedTools = optionalStringSet(raw.denied_tools, `${location}.denied_tools`);
618
+ if (enabledTools !== undefined && allowedTools !== undefined) {
619
+ throw new Error(`${location} cannot set both enabled_tools and allowed_tools`);
620
+ }
621
+ if (disabledTools !== undefined && deniedTools !== undefined) {
622
+ throw new Error(`${location} cannot set both disabled_tools and denied_tools`);
623
+ }
624
+ const effectiveEnabledTools = enabledTools ?? allowedTools;
625
+ const effectiveDisabledTools = disabledTools ?? deniedTools;
626
+ if (effectiveEnabledTools !== undefined) {
627
+ addOverride(args, `${base}.enabled_tools`, tomlStringArray(effectiveEnabledTools));
628
+ normalized.enabled_tools = effectiveEnabledTools;
629
+ }
630
+ if (effectiveDisabledTools !== undefined) {
631
+ addOverride(args, `${base}.disabled_tools`, tomlStringArray(effectiveDisabledTools));
632
+ normalized.disabled_tools = effectiveDisabledTools;
633
+ }
634
+ const defaultApproval = raw.default_tools_approval_mode === undefined
635
+ ? undefined
636
+ : requireEnum(raw.default_tools_approval_mode, APPROVAL_MODES, `${location}.default_tools_approval_mode`);
637
+ if (defaultApproval !== undefined) {
638
+ addOverride(args, `${base}.default_tools_approval_mode`, tomlString(defaultApproval));
639
+ normalized.default_tools_approval_mode = defaultApproval;
640
+ }
641
+ const toolsToml = tomlInlineApprovalTable(raw.tools, `${location}.tools`);
642
+ if (toolsToml !== undefined) {
643
+ addOverride(args, `${base}.tools`, toolsToml);
644
+ normalized.tools = normalizedApprovalTools(raw.tools, `${location}.tools`);
645
+ }
646
+ const scopes = optionalStringSet(raw.scopes, `${location}.scopes`);
647
+ if (scopes !== undefined) {
648
+ addOverride(args, `${base}.scopes`, tomlStringArray(scopes));
649
+ normalized.scopes = scopes;
650
+ }
651
+ const rawOauthResource = optionalString(raw.oauth_resource, `${location}.oauth_resource`);
652
+ const oauthResource = rawOauthResource === undefined
653
+ ? undefined
654
+ : validateHttpUrl(rawOauthResource, `${location}.oauth_resource`);
655
+ if (oauthResource !== undefined) {
656
+ if (url === undefined) {
657
+ throw new Error(`${location}.oauth_resource is only valid for HTTP servers`);
658
+ }
659
+ addOverride(args, `${base}.oauth_resource`, tomlString(oauthResource));
660
+ normalized.oauth_resource = oauthResource;
661
+ }
662
+ normalizedServers[name] = normalized;
663
+ }
664
+ const secretBindings = [...new Set([...userBindings, ...generatedBindings.keys()])]
665
+ .sort(codeUnitCompare)
666
+ .map((name) => [name, childEnv[name] ?? null]);
667
+ return {
668
+ args: consolidateMcpOverrides(args),
669
+ env: childEnv,
670
+ fingerprint: fingerprintPolicy(normalizedServers),
671
+ secretFingerprint: fingerprintPolicy(secretBindings),
672
+ };
673
+ }
674
+ //# sourceMappingURL=codex-home.js.map