@jungjaehoon/mama-core 2.4.1 → 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 (371) 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/069-create-registry-nodes.sql +52 -0
  9. package/db/migrations/070-record-identity.sql +35 -0
  10. package/db/migrations/071-service-operation-origins.sql +187 -0
  11. package/db/migrations/072-observation-versions.sql +29 -0
  12. package/db/migrations/073-registry-corrections.sql +45 -0
  13. package/db/migrations/074-work-graph-ref-kinds.sql +39 -0
  14. package/db/migrations/075-agent-judgments.sql +58 -0
  15. package/db/migrations/076-scoped-checkpoint-bindings.sql +15 -0
  16. package/db/migrations/077-legacy-record-kind.sql +6 -0
  17. package/db/migrations/078-source-ingest-commands.sql +18 -0
  18. package/db/migrations/079-twin-edge-relations.sql +43 -0
  19. package/db/migrations/080-restore-duration-days.sql +7 -0
  20. package/db/migrations/081-mailbox.sql +61 -0
  21. package/db/migrations/082-commitments-row-id.sql +12 -0
  22. package/db/migrations/083-observation-is-the-evidence.sql +49 -0
  23. package/db/migrations/084-scope-kind-is-not-the-cores-to-list.sql +34 -0
  24. package/db/migrations/085-a-migration-has-a-source.sql +37 -0
  25. package/db/migrations/086-the-mailbox-is-generic.sql +110 -0
  26. package/db/migrations/087-mailbox-payload.sql +5 -0
  27. package/db/migrations/088-native-input-journal.sql +14 -0
  28. package/db/migrations/089-native-turn-receipt-lookup.sql +3 -0
  29. package/db/migrations/090-model-run-native-inputs.sql +29 -0
  30. package/db/migrations/091-native-turn-results.sql +11 -0
  31. package/db/migrations/092-restore-decision-fts.sql +34 -0
  32. package/db/migrations/093-native-turn-primary-kind.sql +14 -0
  33. package/db/migrations/094-commitment-run-provenance.sql +9 -0
  34. package/db/migrations/095-model-run-native-input-identity.sql +39 -0
  35. package/db/migrations/096-drop-connector-event-index-fts.sql +9 -0
  36. package/db/migrations/097-native-input-json-validity.sql +37 -0
  37. package/db/migrations/098-workflow-memory-kind.sql +105 -0
  38. package/dist/action-contracts.d.ts +212 -0
  39. package/dist/action-contracts.js +10 -0
  40. package/dist/api/catalog.d.ts +118 -0
  41. package/dist/api/catalog.js +1756 -0
  42. package/dist/api/dispatch.d.ts +76 -0
  43. package/dist/api/dispatch.js +372 -0
  44. package/dist/canonicalize.d.ts +2 -2
  45. package/dist/canonicalize.js +3 -3
  46. package/dist/client/client.d.ts +33 -0
  47. package/dist/client/client.js +123 -0
  48. package/dist/client/ipc.d.ts +81 -0
  49. package/dist/client/ipc.js +314 -0
  50. package/dist/db-adapter/base-adapter.d.ts +6 -66
  51. package/dist/db-adapter/base-adapter.js +6 -6
  52. package/dist/db-adapter/index.d.ts +5 -5
  53. package/dist/db-adapter/index.js +2 -5
  54. package/dist/db-adapter/node-sqlite-adapter.d.ts +85 -15
  55. package/dist/db-adapter/node-sqlite-adapter.js +1968 -570
  56. package/dist/db-manager.d.ts +53 -97
  57. package/dist/db-manager.js +121 -603
  58. package/dist/embedding/embedder.d.ts +132 -0
  59. package/dist/embedding/embedder.js +299 -0
  60. package/dist/identity/principal-repository.d.ts +2 -2
  61. package/dist/index.d.ts +43 -58
  62. package/dist/index.js +97 -145
  63. package/dist/{context-compile/channel-grant.d.ts → knowledge/access.d.ts} +12 -17
  64. package/dist/knowledge/access.js +663 -0
  65. package/dist/knowledge/case-errors.d.ts +31 -0
  66. package/dist/knowledge/case-errors.js +40 -0
  67. package/dist/{cases/search-rollup.d.ts → knowledge/case-search-rollup.d.ts} +5 -4
  68. package/dist/{cases/search-rollup.js → knowledge/case-search-rollup.js} +6 -8
  69. package/dist/{cases/store.d.ts → knowledge/case-store.d.ts} +3 -6
  70. package/dist/{cases/store.js → knowledge/case-store.js} +7 -42
  71. package/dist/{cases/timeline-range.d.ts → knowledge/case-timeline-range.d.ts} +3 -3
  72. package/dist/{cases/timeline-range.js → knowledge/case-timeline-range.js} +47 -25
  73. package/dist/{cases/types.d.ts → knowledge/case-types.d.ts} +8 -2
  74. package/dist/{cases/types.js → knowledge/case-types.js} +1 -1
  75. package/dist/knowledge/commitments.d.ts +188 -0
  76. package/dist/knowledge/commitments.js +370 -0
  77. package/dist/knowledge/decision-edges.d.ts +70 -0
  78. package/dist/knowledge/decision-edges.js +123 -0
  79. package/dist/{agent-graph/types.d.ts → knowledge/graph-query.d.ts} +80 -70
  80. package/dist/knowledge/graph-query.js +1585 -0
  81. package/dist/knowledge/identity.d.ts +16 -0
  82. package/dist/knowledge/identity.js +22 -0
  83. package/dist/knowledge/index.d.ts +47 -0
  84. package/dist/knowledge/index.js +90 -0
  85. package/dist/knowledge/judgments.d.ts +118 -0
  86. package/dist/knowledge/judgments.js +808 -0
  87. package/dist/knowledge/observations.d.ts +160 -0
  88. package/dist/knowledge/observations.js +449 -0
  89. package/dist/knowledge/question-type.d.ts +34 -0
  90. package/dist/knowledge/question-type.js +70 -0
  91. package/dist/{search → knowledge}/ranker-features.js +1 -1
  92. package/dist/{search → knowledge}/search-quality.d.ts +0 -1
  93. package/dist/knowledge/search.d.ts +38 -0
  94. package/dist/knowledge/search.js +91 -0
  95. package/dist/knowledge/source-ingest.d.ts +65 -0
  96. package/dist/knowledge/source-ingest.js +174 -0
  97. package/dist/{edges/types.d.ts → knowledge/twin-edge-types.d.ts} +31 -4
  98. package/dist/{edges/types.js → knowledge/twin-edge-types.js} +13 -2
  99. package/dist/knowledge/work-dates.d.ts +49 -0
  100. package/dist/knowledge/work-dates.js +120 -0
  101. package/dist/mama-api.d.ts +114 -778
  102. package/dist/mama-api.js +313 -2461
  103. package/dist/memory/api.d.ts +264 -24
  104. package/dist/memory/api.js +1633 -843
  105. package/dist/memory/bootstrap-builder.d.ts +2 -1
  106. package/dist/memory/bootstrap-builder.js +5 -5
  107. package/dist/memory/channel-summary-state-store.d.ts +3 -2
  108. package/dist/memory/channel-summary-state-store.js +53 -51
  109. package/dist/memory/channel-summary-store.d.ts +5 -3
  110. package/dist/memory/channel-summary-store.js +3 -8
  111. package/dist/memory/dashboard-read.d.ts +46 -0
  112. package/dist/memory/dashboard-read.js +94 -0
  113. package/dist/memory/event-store.d.ts +3 -3
  114. package/dist/memory/event-store.js +3 -10
  115. package/dist/memory/finding-store.d.ts +3 -2
  116. package/dist/memory/finding-store.js +2 -7
  117. package/dist/memory/graph-read.d.ts +52 -0
  118. package/dist/memory/graph-read.js +130 -0
  119. package/dist/memory/judgment-types.d.ts +394 -0
  120. package/dist/memory/judgment-types.js +16 -0
  121. package/dist/memory/provenance-audit.d.ts +5 -2
  122. package/dist/memory/provenance-audit.js +8 -14
  123. package/dist/memory/provenance-live.d.ts +141 -0
  124. package/dist/memory/provenance-live.js +409 -0
  125. package/dist/memory/provenance-query.d.ts +5 -4
  126. package/dist/memory/provenance-query.js +21 -29
  127. package/dist/memory/provenance-resolver.d.ts +191 -0
  128. package/dist/memory/provenance-resolver.js +155 -0
  129. package/dist/memory/provenance.d.ts +1 -11
  130. package/dist/memory/provenance.js +2 -33
  131. package/dist/memory/recall-sanitize.d.ts +55 -0
  132. package/dist/memory/recall-sanitize.js +144 -0
  133. package/dist/memory/secret-filter.d.ts +32 -0
  134. package/dist/memory/secret-filter.js +126 -0
  135. package/dist/memory/truth-store.d.ts +2 -1
  136. package/dist/memory/truth-store.js +1 -4
  137. package/dist/memory/types.d.ts +74 -24
  138. package/dist/memory/types.js +75 -5
  139. package/dist/memory/write-adapters.d.ts +98 -0
  140. package/dist/memory/write-adapters.js +242 -0
  141. package/dist/operations/owner-action-effects.d.ts +53 -0
  142. package/dist/operations/owner-action-effects.js +96 -0
  143. package/dist/provenance/source-ref.d.ts +1 -1
  144. package/dist/provenance/source-ref.js +0 -2
  145. package/dist/registry/corrections.d.ts +31 -0
  146. package/dist/registry/corrections.js +332 -0
  147. package/dist/registry/record-identity.d.ts +49 -0
  148. package/dist/registry/record-identity.js +133 -0
  149. package/dist/registry/store.d.ts +101 -0
  150. package/dist/registry/store.js +395 -0
  151. package/dist/registry/types.d.ts +28 -0
  152. package/dist/registry/types.js +5 -0
  153. package/dist/relevance-scorer.js +2 -2
  154. package/dist/runtime/agent-event-bus.d.ts +50 -0
  155. package/dist/runtime/agent-event-bus.js +101 -0
  156. package/dist/runtime/drivers/claude-cli-wrapper.d.ts +155 -0
  157. package/dist/runtime/drivers/claude-cli-wrapper.js +392 -0
  158. package/dist/runtime/drivers/cli-arg-redaction.d.ts +2 -0
  159. package/dist/runtime/drivers/cli-arg-redaction.js +18 -0
  160. package/dist/runtime/drivers/cli-secret-redaction.d.ts +17 -0
  161. package/dist/runtime/drivers/cli-secret-redaction.js +126 -0
  162. package/dist/runtime/drivers/codex-app-server-process.d.ts +277 -0
  163. package/dist/runtime/drivers/codex-app-server-process.js +2342 -0
  164. package/dist/runtime/drivers/codex-auxiliary-tools.d.ts +17 -0
  165. package/dist/runtime/drivers/codex-auxiliary-tools.js +267 -0
  166. package/dist/runtime/drivers/codex-home.d.ts +20 -0
  167. package/dist/runtime/drivers/codex-home.js +674 -0
  168. package/dist/runtime/drivers/codex-thread-registry.d.ts +63 -0
  169. package/dist/runtime/drivers/codex-thread-registry.js +433 -0
  170. package/dist/runtime/drivers/persistent-cli-adapter.d.ts +160 -0
  171. package/dist/runtime/drivers/persistent-cli-adapter.js +396 -0
  172. package/dist/runtime/drivers/persistent-cli-process.d.ts +424 -0
  173. package/dist/runtime/drivers/persistent-cli-process.js +1543 -0
  174. package/dist/runtime/drivers/types.d.ts +456 -0
  175. package/dist/runtime/drivers/types.js +110 -0
  176. package/dist/runtime/mailbox.d.ts +223 -0
  177. package/dist/runtime/mailbox.js +582 -0
  178. package/dist/runtime/model-run-store.d.ts +28 -0
  179. package/dist/{model-runs/store.js → runtime/model-run-store.js} +81 -41
  180. package/dist/{model-runs/types.d.ts → runtime/model-run-types.d.ts} +33 -4
  181. package/dist/{model-runs/types.js → runtime/model-run-types.js} +1 -1
  182. package/dist/runtime/native-effect-observer.d.ts +22 -0
  183. package/dist/runtime/native-effect-observer.js +103 -0
  184. package/dist/runtime/native-input-journal.d.ts +46 -0
  185. package/dist/runtime/native-input-journal.js +308 -0
  186. package/dist/runtime/native-prompt.d.ts +118 -0
  187. package/dist/runtime/native-prompt.js +496 -0
  188. package/dist/runtime/native-session.d.ts +10 -0
  189. package/dist/{agent-graph/index.js → runtime/native-session.js} +9 -6
  190. package/dist/runtime/native-tool-trace-observer.d.ts +5 -0
  191. package/dist/runtime/native-tool-trace-observer.js +65 -0
  192. package/dist/runtime/native-turn.d.ts +272 -0
  193. package/dist/runtime/native-turn.js +1041 -0
  194. package/dist/runtime/operations.d.ts +236 -0
  195. package/dist/runtime/operations.js +565 -0
  196. package/dist/runtime/post-tool-handler.d.ts +74 -0
  197. package/dist/runtime/post-tool-handler.js +137 -0
  198. package/dist/runtime/prompt-layers.d.ts +126 -0
  199. package/dist/runtime/prompt-layers.js +239 -0
  200. package/dist/runtime/runtime-process.d.ts +102 -0
  201. package/dist/runtime/runtime-process.js +206 -0
  202. package/dist/runtime/runtime.d.ts +278 -0
  203. package/dist/runtime/runtime.js +563 -0
  204. package/dist/runtime/session-pool.d.ts +176 -0
  205. package/dist/runtime/session-pool.js +369 -0
  206. package/dist/runtime/stimulus-payload.d.ts +5 -0
  207. package/dist/runtime/stimulus-payload.js +50 -0
  208. package/dist/runtime/subagent-bridge.d.ts +24 -0
  209. package/dist/{agent-graph/types.js → runtime/subagent-bridge.js} +1 -1
  210. package/dist/runtime/text-completion.d.ts +22 -0
  211. package/dist/{agent-situation/types.js → runtime/text-completion.js} +1 -1
  212. package/dist/runtime/token-estimator.d.ts +25 -0
  213. package/dist/runtime/token-estimator.js +75 -0
  214. package/dist/runtime/tool-trace-store.d.ts +22 -0
  215. package/dist/{model-runs → runtime}/tool-trace-store.js +46 -27
  216. package/dist/runtime/trace-summary.d.ts +5 -0
  217. package/dist/runtime/trace-summary.js +74 -0
  218. package/dist/runtime/turn-text.d.ts +23 -0
  219. package/dist/runtime/turn-text.js +41 -0
  220. package/dist/storage/database.d.ts +67 -0
  221. package/dist/storage/database.js +158 -0
  222. package/package.json +20 -34
  223. package/dist/agent-graph/alias-write.d.ts +0 -3
  224. package/dist/agent-graph/alias-write.js +0 -234
  225. package/dist/agent-graph/entity-resolve.d.ts +0 -3
  226. package/dist/agent-graph/entity-resolve.js +0 -271
  227. package/dist/agent-graph/errors.d.ts +0 -4
  228. package/dist/agent-graph/errors.js +0 -11
  229. package/dist/agent-graph/graph-query.d.ts +0 -5
  230. package/dist/agent-graph/graph-query.js +0 -360
  231. package/dist/agent-graph/index.d.ts +0 -6
  232. package/dist/agent-situation/builder.d.ts +0 -8
  233. package/dist/agent-situation/builder.js +0 -239
  234. package/dist/agent-situation/cache-key.d.ts +0 -4
  235. package/dist/agent-situation/cache-key.js +0 -64
  236. package/dist/agent-situation/index.d.ts +0 -7
  237. package/dist/agent-situation/index.js +0 -28
  238. package/dist/agent-situation/packet-store.d.ts +0 -27
  239. package/dist/agent-situation/packet-store.js +0 -228
  240. package/dist/agent-situation/ranking-policy.d.ts +0 -18
  241. package/dist/agent-situation/ranking-policy.js +0 -75
  242. package/dist/agent-situation/source-readers.d.ts +0 -52
  243. package/dist/agent-situation/source-readers.js +0 -300
  244. package/dist/agent-situation/types.d.ts +0 -195
  245. package/dist/cases/wiki-page-index.d.ts +0 -37
  246. package/dist/cases/wiki-page-index.js +0 -201
  247. package/dist/config-loader.d.ts +0 -68
  248. package/dist/config-loader.js +0 -239
  249. package/dist/connectors/event-index.d.ts +0 -24
  250. package/dist/connectors/event-index.js +0 -245
  251. package/dist/connectors/raw-query.d.ts +0 -40
  252. package/dist/connectors/raw-query.js +0 -412
  253. package/dist/connectors/types.d.ts +0 -117
  254. package/dist/connectors/types.js +0 -3
  255. package/dist/context-compile/boundary-defaults.d.ts +0 -12
  256. package/dist/context-compile/boundary-defaults.js +0 -105
  257. package/dist/context-compile/channel-grant.js +0 -66
  258. package/dist/context-compile/compiler-policy.d.ts +0 -39
  259. package/dist/context-compile/compiler-policy.js +0 -147
  260. package/dist/context-compile/compiler.d.ts +0 -18
  261. package/dist/context-compile/compiler.js +0 -404
  262. package/dist/context-compile/index.d.ts +0 -10
  263. package/dist/context-compile/index.js +0 -26
  264. package/dist/context-compile/packet-store.d.ts +0 -8
  265. package/dist/context-compile/packet-store.js +0 -239
  266. package/dist/context-compile/ref.d.ts +0 -7
  267. package/dist/context-compile/ref.js +0 -102
  268. package/dist/context-compile/source-readers.d.ts +0 -70
  269. package/dist/context-compile/source-readers.js +0 -840
  270. package/dist/context-compile/types.d.ts +0 -155
  271. package/dist/context-compile/types.js +0 -11
  272. package/dist/context-compile/visibility.d.ts +0 -21
  273. package/dist/context-compile/visibility.js +0 -224
  274. package/dist/decision-tracker.d.ts +0 -206
  275. package/dist/decision-tracker.js +0 -481
  276. package/dist/edges/ref-validation.d.ts +0 -7
  277. package/dist/edges/ref-validation.js +0 -321
  278. package/dist/edges/store.d.ts +0 -8
  279. package/dist/edges/store.js +0 -129
  280. package/dist/embedding-client.d.ts +0 -28
  281. package/dist/embedding-client.js +0 -53
  282. package/dist/embedding-server/index.d.ts +0 -67
  283. package/dist/embedding-server/index.js +0 -405
  284. package/dist/embedding-server/mobile/auth.d.ts +0 -44
  285. package/dist/embedding-server/mobile/auth.js +0 -150
  286. package/dist/embedding-server/mobile/daemon.d.ts +0 -129
  287. package/dist/embedding-server/mobile/daemon.js +0 -313
  288. package/dist/embedding-server/mobile/output-parser.d.ts +0 -115
  289. package/dist/embedding-server/mobile/output-parser.js +0 -241
  290. package/dist/embedding-server/mobile/session-api.d.ts +0 -57
  291. package/dist/embedding-server/mobile/session-api.js +0 -261
  292. package/dist/embedding-server/mobile/session-manager.d.ts +0 -138
  293. package/dist/embedding-server/mobile/session-manager.js +0 -378
  294. package/dist/embedding-server/mobile/websocket-handler.d.ts +0 -137
  295. package/dist/embedding-server/mobile/websocket-handler.js +0 -486
  296. package/dist/embeddings.d.ts +0 -68
  297. package/dist/embeddings.js +0 -244
  298. package/dist/entities/audit-metrics.d.ts +0 -68
  299. package/dist/entities/audit-metrics.js +0 -124
  300. package/dist/entities/candidate-generator.d.ts +0 -8
  301. package/dist/entities/candidate-generator.js +0 -24
  302. package/dist/entities/entity-linked-decision-counts.d.ts +0 -2
  303. package/dist/entities/entity-linked-decision-counts.js +0 -29
  304. package/dist/entities/entity-list.d.ts +0 -22
  305. package/dist/entities/entity-list.js +0 -3
  306. package/dist/entities/entity-orphan-list.d.ts +0 -17
  307. package/dist/entities/entity-orphan-list.js +0 -3
  308. package/dist/entities/entity-search.d.ts +0 -20
  309. package/dist/entities/entity-search.js +0 -3
  310. package/dist/entities/errors.d.ts +0 -55
  311. package/dist/entities/errors.js +0 -100
  312. package/dist/entities/lineage-store.d.ts +0 -28
  313. package/dist/entities/lineage-store.js +0 -204
  314. package/dist/entities/normalization.d.ts +0 -14
  315. package/dist/entities/normalization.js +0 -63
  316. package/dist/entities/policy-store.d.ts +0 -8
  317. package/dist/entities/policy-store.js +0 -75
  318. package/dist/entities/policy-types.d.ts +0 -72
  319. package/dist/entities/policy-types.js +0 -59
  320. package/dist/entities/projection.d.ts +0 -8
  321. package/dist/entities/projection.js +0 -82
  322. package/dist/entities/provenance-query.d.ts +0 -32
  323. package/dist/entities/provenance-query.js +0 -3
  324. package/dist/entities/read-identity.d.ts +0 -31
  325. package/dist/entities/read-identity.js +0 -264
  326. package/dist/entities/recall-bridge.d.ts +0 -5
  327. package/dist/entities/recall-bridge.js +0 -171
  328. package/dist/entities/resolution-engine.d.ts +0 -8
  329. package/dist/entities/resolution-engine.js +0 -3
  330. package/dist/entities/rollback-preview.d.ts +0 -35
  331. package/dist/entities/rollback-preview.js +0 -3
  332. package/dist/entities/source-locator.d.ts +0 -3
  333. package/dist/entities/source-locator.js +0 -32
  334. package/dist/entities/store.d.ts +0 -69
  335. package/dist/entities/store.js +0 -544
  336. package/dist/entities/types.d.ts +0 -166
  337. package/dist/entities/types.js +0 -30
  338. package/dist/memory/extraction-prompt.d.ts +0 -4
  339. package/dist/memory/extraction-prompt.js +0 -89
  340. package/dist/memory/scope-backfill.d.ts +0 -14
  341. package/dist/memory/scope-backfill.js +0 -3
  342. package/dist/memory/scope-store.d.ts +0 -4
  343. package/dist/memory/scope-store.js +0 -9
  344. package/dist/memory-store.d.ts +0 -87
  345. package/dist/memory-store.js +0 -78
  346. package/dist/model-runs/store.d.ts +0 -13
  347. package/dist/model-runs/tool-trace-store.d.ts +0 -8
  348. package/dist/notification-manager.d.ts +0 -7
  349. package/dist/notification-manager.js +0 -12
  350. package/dist/outcome-tracker.d.ts +0 -151
  351. package/dist/outcome-tracker.js +0 -271
  352. package/dist/query-intent.d.ts +0 -23
  353. package/dist/query-intent.js +0 -114
  354. package/dist/runtime/trusted-provenance.d.ts +0 -3
  355. package/dist/runtime/trusted-provenance.js +0 -6
  356. package/dist/search/question-type.d.ts +0 -5
  357. package/dist/search/question-type.js +0 -41
  358. package/dist/test-utils.d.ts +0 -80
  359. package/dist/test-utils.js +0 -218
  360. package/dist/tier-validator.d.ts +0 -43
  361. package/dist/tier-validator.js +0 -159
  362. package/dist/time-formatter.d.ts +0 -25
  363. package/dist/time-formatter.js +0 -93
  364. /package/dist/{search → knowledge}/feedback-store.d.ts +0 -0
  365. /package/dist/{search → knowledge}/feedback-store.js +0 -0
  366. /package/dist/{search → knowledge}/ranker-features.d.ts +0 -0
  367. /package/dist/{search → knowledge}/ranker-rescore.d.ts +0 -0
  368. /package/dist/{search → knowledge}/ranker-rescore.js +0 -0
  369. /package/dist/{search → knowledge}/ranker-trainer.d.ts +0 -0
  370. /package/dist/{search → knowledge}/ranker-trainer.js +0 -0
  371. /package/dist/{search → knowledge}/search-quality.js +0 -0
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CodexRuntimeProcess = void 0;
4
+ const events_1 = require("events");
5
+ const codex_app_server_process_js_1 = require("./drivers/codex-app-server-process.js");
6
+ const codex_auxiliary_tools_js_1 = require("./drivers/codex-auxiliary-tools.js");
7
+ /**
8
+ * Session-persistent Codex wrapper with the same minimal contract used by
9
+ * multi-agent runtime (sendMessage/isReady/stop + idle events).
10
+ *
11
+ * Implements both AgentRuntimeProcess (multi-agent) and IModelRunner (agent-loop).
12
+ * Uses one Codex app-server connection and multiplexes durable threads by
13
+ * session key. Different sessions may run concurrently; turns for the same
14
+ * session are serialized by CodexAppServerProcess.
15
+ */
16
+ class CodexRuntimeProcess extends events_1.EventEmitter {
17
+ backendType = 'codex';
18
+ /** codex app-server spawns native subagents and reports the spawn via onSubagentStart. */
19
+ supportsNativeSubagents = true;
20
+ options;
21
+ appServer;
22
+ auxiliaryToolBridge;
23
+ defaultSessionKey;
24
+ systemPrompt;
25
+ stopped = false;
26
+ activeRequests = 0;
27
+ subagentCompletionAcceptance = null;
28
+ subagentCompletionAcceptanceRequired = false;
29
+ // ─── Metrics tracking ───
30
+ _requestCount = 0;
31
+ _failureCount = 0;
32
+ _totalLatencyMs = 0;
33
+ _lastRequestAt = null;
34
+ constructor(options) {
35
+ super();
36
+ this.options = { ...options };
37
+ this.defaultSessionKey = options.defaultSessionKey ?? 'default';
38
+ this.systemPrompt = options.systemPrompt ?? '';
39
+ this.appServer = new codex_app_server_process_js_1.CodexAppServerProcess({
40
+ hostRootDir: options.hostRootDir,
41
+ sessionKey: this.defaultSessionKey,
42
+ model: options.model ?? 'gpt-5.4',
43
+ systemPrompt: this.systemPrompt,
44
+ cwd: options.cwd ?? process.cwd(),
45
+ sandbox: options.sandbox ?? 'workspace-write',
46
+ command: options.command,
47
+ requestTimeout: options.requestTimeout,
48
+ codexHome: options.codexHome,
49
+ isolatedHome: options.isolatedHome,
50
+ registryRoot: options.registryRoot,
51
+ mcpConfigPath: options.mcpConfigPath,
52
+ authSourcePath: options.authSourcePath,
53
+ effort: options.effort,
54
+ shellTool: options.shellTool,
55
+ webSearch: options.webSearch,
56
+ shellEnvironment: options.shellEnvironment,
57
+ processEnv: options.processEnv,
58
+ deniedReadPaths: options.deniedReadPaths,
59
+ allowLoginShell: options.allowLoginShell,
60
+ // A completed child is accepted by the consumer's durable intake before the
61
+ // driver forgets it. Started events remain observational.
62
+ onSubagentEvent: (event) => {
63
+ if (event.kind === 'completed') {
64
+ if (this.subagentCompletionAcceptanceRequired && !this.subagentCompletionAcceptance) {
65
+ throw new Error('Subagent completion acceptance is detached');
66
+ }
67
+ this.subagentCompletionAcceptance?.(event);
68
+ }
69
+ try {
70
+ this.emit('subagent', event);
71
+ }
72
+ catch (error) {
73
+ console.warn(`[CodexRuntimeProcess] subagent observer failed: ${error instanceof Error ? error.message : String(error)}`);
74
+ }
75
+ },
76
+ createSubagentBridge: options.createSubagentBridge,
77
+ });
78
+ this.auxiliaryToolBridge = options.auxiliaryToolPolicy
79
+ ? (0, codex_auxiliary_tools_js_1.createCodexAuxiliaryToolBridge)({
80
+ ...options.auxiliaryToolPolicy,
81
+ executeCommand: (command, cwd, roots, signal) => this.appServer.executeSandboxedCommand(command, cwd, roots, signal),
82
+ })
83
+ : undefined;
84
+ }
85
+ /** Synchronous durable acceptance of child completion, before driver cleanup. */
86
+ registerSubagentCompletionAcceptance(accept) {
87
+ if (this.subagentCompletionAcceptance) {
88
+ throw new Error('Subagent completion acceptance is already registered');
89
+ }
90
+ this.subagentCompletionAcceptanceRequired = true;
91
+ this.subagentCompletionAcceptance = accept;
92
+ return () => {
93
+ if (this.subagentCompletionAcceptance === accept)
94
+ this.subagentCompletionAcceptance = null;
95
+ };
96
+ }
97
+ // ─── IModelRunner.prompt() ─────────────────────────────────────────────
98
+ async prompt(content, callbacks, options) {
99
+ return this.execute(content, callbacks, options);
100
+ }
101
+ steer(content, target, options) {
102
+ return this.appServer.steer(content, target, options?.sessionKey ?? options?.sessionId ?? this.defaultSessionKey, options?.beforeSend);
103
+ }
104
+ getSessionPolicyStatus(options) {
105
+ return this.appServer.getSessionPolicyStatus({
106
+ sessionKey: options.sessionKey ?? options.sessionId ?? this.defaultSessionKey,
107
+ model: options.model ?? this.options.model,
108
+ systemPrompt: options.systemPrompt ?? this.systemPrompt,
109
+ requestTimeout: options.requestTimeout ?? this.options.requestTimeout,
110
+ policyFingerprint: options.sessionPolicyFingerprint,
111
+ restrictedReadRoots: options.restrictedReadRoots,
112
+ cwd: options.cwd,
113
+ resumeSession: options.resumeSession,
114
+ hostToolBridge: options.hostToolBridge ?? this.auxiliaryToolBridge,
115
+ });
116
+ }
117
+ resetSession(sessionId, sessionKey) {
118
+ return this.appServer.reset(sessionKey ?? sessionId ?? this.defaultSessionKey);
119
+ }
120
+ // ─── AgentRuntimeProcess.sendMessage() ─────────────────────────────────
121
+ async sendMessage(content, callbacks) {
122
+ return this.execute(content, callbacks);
123
+ }
124
+ async execute(content, callbacks, promptOptions) {
125
+ if (this.stopped) {
126
+ throw this.notifyError(new Error('Process is dead'), callbacks);
127
+ }
128
+ this.activeRequests++;
129
+ const startTime = Date.now();
130
+ this._requestCount++;
131
+ this._lastRequestAt = startTime;
132
+ try {
133
+ const normalized = await this.appServer.prompt(content, callbacks, {
134
+ nativeInputId: promptOptions?.nativeInputId,
135
+ sessionKey: promptOptions?.sessionKey ?? promptOptions?.sessionId ?? this.defaultSessionKey,
136
+ model: promptOptions?.model ?? this.options.model,
137
+ systemPrompt: promptOptions?.systemPrompt ?? this.systemPrompt,
138
+ requestTimeout: promptOptions?.requestTimeout ?? this.options.requestTimeout,
139
+ policyFingerprint: promptOptions?.sessionPolicyFingerprint,
140
+ restrictedReadRoots: promptOptions?.restrictedReadRoots,
141
+ cwd: promptOptions?.cwd,
142
+ resumeSession: promptOptions?.resumeSession,
143
+ hostToolBridge: promptOptions?.hostToolBridge ?? this.auxiliaryToolBridge,
144
+ resumeInstructions: promptOptions?.resumeInstructions,
145
+ preparePrompt: promptOptions?.preparePrompt,
146
+ promptTelemetry: promptOptions?.promptTelemetry,
147
+ });
148
+ this._totalLatencyMs += Date.now() - startTime;
149
+ callbacks?.onFinal?.({ content: normalized.response, toolUseBlocks: [] });
150
+ return normalized;
151
+ }
152
+ catch (err) {
153
+ this._failureCount++;
154
+ this._totalLatencyMs += Date.now() - startTime;
155
+ throw this.notifyError(err, callbacks);
156
+ }
157
+ finally {
158
+ this.activeRequests--;
159
+ if (!this.stopped && this.activeRequests === 0) {
160
+ this.emit('idle');
161
+ }
162
+ }
163
+ }
164
+ notifyError(error, callbacks) {
165
+ const normalized = error instanceof Error ? error : new Error(String(error));
166
+ try {
167
+ callbacks?.onError?.(normalized);
168
+ }
169
+ catch {
170
+ // Consumer callback failures must not replace the model failure.
171
+ }
172
+ return normalized;
173
+ }
174
+ // ─── IModelRunner session management ───────────────────────────────────
175
+ setSessionId(id) {
176
+ this.defaultSessionKey = id;
177
+ }
178
+ setSystemPrompt(prompt) {
179
+ this.systemPrompt = prompt;
180
+ }
181
+ // ─── IModelRunner health & metrics ─────────────────────────────────────
182
+ isReady() {
183
+ return !this.stopped;
184
+ }
185
+ isHealthy() {
186
+ return !this.stopped;
187
+ }
188
+ getMetrics() {
189
+ return {
190
+ requestCount: this._requestCount,
191
+ failureCount: this._failureCount,
192
+ avgLatencyMs: this._requestCount > 0 ? Math.round(this._totalLatencyMs / this._requestCount) : 0,
193
+ lastRequestAt: this._lastRequestAt,
194
+ };
195
+ }
196
+ async stop() {
197
+ this.stopped = true;
198
+ await this.appServer.stop();
199
+ this.emit('close', 0);
200
+ }
201
+ getSessionId() {
202
+ return this.appServer.getThreadId(this.defaultSessionKey) ?? '';
203
+ }
204
+ }
205
+ exports.CodexRuntimeProcess = CodexRuntimeProcess;
206
+ //# sourceMappingURL=runtime-process.js.map
@@ -0,0 +1,278 @@
1
+ import type { ContentBlock, PromptCallbacks } from './drivers/types.js';
2
+ import type { NativeTurnResult } from './native-turn.js';
3
+ import type { ActionSessionFacts } from '../action-contracts.js';
4
+ import type { ActionCatalog } from '../api/catalog.js';
5
+ import type { ActionDispatcher } from '../api/dispatch.js';
6
+ import type { TextCompletion } from './text-completion.js';
7
+ import type { JudgmentAccess } from '../knowledge/judgments.js';
8
+ import type { DatabaseAdapter } from '../db-manager.js';
9
+ import type { NativeInputDispatch, NativeInputReceipt } from './drivers/types.js';
10
+ import type { NativeTurnResultRecord } from './native-input-journal.js';
11
+ import { type IpcRequest } from '../client/ipc.js';
12
+ import { Mailbox, type MailboxRow, type Stimulus, type StimulusKind } from './mailbox.js';
13
+ /** The paths product assembly must state — the runtime never derives them. */
14
+ export interface RuntimePaths {
15
+ /** Private Unix socket the action catalog is served on. */
16
+ socketPath: string;
17
+ }
18
+ /**
19
+ * One caller of this runtime. The credential file is what names the principal:
20
+ * whoever presents that token is that principal and gets exactly its access.
21
+ * The path is stated by the product for the same reason every other path is —
22
+ * core composing `<dir>/<principalId>` would let a principal's name choose a
23
+ * file.
24
+ */
25
+ export interface RuntimePrincipal {
26
+ access: JudgmentAccess;
27
+ /** Rotated-per-boot token file (0600) this principal's callers present. */
28
+ credentialPath: string;
29
+ /**
30
+ * The run this principal's calls answer to, when its host can name one.
31
+ *
32
+ * An action whose authority is the run — execution evidence — is uncallable
33
+ * on a surface that names none, and a socket cannot derive a run from a
34
+ * request. The host that assembles the principal states it here, once, beside
35
+ * the access; a host that cannot name it omits it and its calls stay honestly
36
+ * unattributed.
37
+ */
38
+ runEvidenceScope?: ActionSessionFacts['runEvidenceScope'];
39
+ }
40
+ /**
41
+ * The harness this runtime opened, from the outside.
42
+ *
43
+ * §4.3 gives `runtime.start` the DB, the native session, the model and the
44
+ * socket, and gives `stop` exactly what start opened. The session itself is
45
+ * built by product assembly - which harness, which workspace, which persona is
46
+ * the product's statement - and handed here so that ONE subject decides when it
47
+ * is alive. Before this, shutdown stopped the loop, disposed the session pool
48
+ * and closed the socket as three separate steps in one function, and the order
49
+ * between them was that function's private knowledge.
50
+ */
51
+ export interface NativeInvocationOptions {
52
+ nativeInputId?: string;
53
+ onModelRunStarted?: (modelRunId: string) => void;
54
+ prepareSessionContent?: (session: import('./drivers/types.js').NativeSessionState) => Promise<ContentBlock[]>;
55
+ streamCallbacks?: PromptCallbacks;
56
+ }
57
+ export interface NativeSessionHandle {
58
+ /** One request to the native harness; model/tool iteration remains inside that harness. */
59
+ runTurn?(content: ContentBlock[], request?: NativeInvocationOptions): Promise<NativeTurnResult>;
60
+ /** Retire the native context and its pool route, preserving durable product records. */
61
+ resetSession?(sessionKey: string): Promise<void>;
62
+ /** Add input to the exact active turn; the runtime journals this input separately. */
63
+ steer?(content: string, target: NativeInputReceipt, sessionKey: string, beforeSend?: () => void): Promise<NativeInputReceipt>;
64
+ /** Release the harness and the sessions it holds. Called once, by `stop`. */
65
+ stop(): Promise<void>;
66
+ }
67
+ /**
68
+ * A delivery that must NOT be tried again.
69
+ *
70
+ * Retry is the runtime's default because most failures are transient. Some are
71
+ * not: an external effect whose outcome is unknown cannot be replayed on a
72
+ * guess (§4.3), and a stimulus whose delivery already spent one must park where
73
+ * a person can see it rather than repeat it. Throwing this from `deliver` says
74
+ * exactly that — park the row dead, spend no attempt, and name it through
75
+ * `onDead`.
76
+ */
77
+ export declare class StimulusQuarantine extends Error {
78
+ constructor(reason: string);
79
+ }
80
+ /**
81
+ * How an accepted stimulus reaches the loop.
82
+ *
83
+ * The runtime journals dispatch before native IO and ACKs the native receipt.
84
+ * Returning from `deliver` settles the consumer adapter; it does not prove a
85
+ * judgment or an external effect. After dispatch, failures require reconciliation.
86
+ * Only failures known to precede dispatch remain eligible for automatic retry.
87
+ *
88
+ * This is delivery, not a second turn loop: what runs inside `deliver` is the
89
+ * native session the product already has, with its own resume, steering and
90
+ * turn observation. Nothing here interprets the stimulus, and nothing here
91
+ * decides a turn is finished — an ack says the loop took it and no more.
92
+ */
93
+ export interface NativeDeliveryContext {
94
+ nativeInputId: string;
95
+ /** Read the one final result for a shared turn under this input's principal. */
96
+ resultForReceipt(receipt: NativeInputReceipt): NativeTurnResultRecord | null;
97
+ run<TRequest extends object>(content: ContentBlock[], request?: TRequest & NativeInvocationOptions): Promise<NativeTurnResult>;
98
+ /** Native steer acceptance, never a model result or an effect receipt. */
99
+ steer(content: string, target: NativeInputReceipt, sessionKey: string): Promise<NativeInputReceipt>;
100
+ wasDispatched(): boolean;
101
+ /** Must persist successfully before writing the input to the native transport. */
102
+ onInputDispatch(input: NativeInputDispatch): void;
103
+ /** Native acknowledgement, distinct from model completion and external effects. */
104
+ onAccepted(receipt: NativeInputReceipt): void;
105
+ }
106
+ export interface StimulusDelivery {
107
+ deliver(row: MailboxRow, context: NativeDeliveryContext): Promise<void>;
108
+ /** Reuse recorded results only. Never submit the input to a model again. */
109
+ reconcile?(row: MailboxRow): Promise<'settled' | 'unresolved'>;
110
+ onUncertain?(row: MailboxRow, reason: string): void | Promise<void>;
111
+ /** Consumer ports may still be opening; keep accepted inputs without spending attempts. */
112
+ ready?(): boolean;
113
+ /**
114
+ * A row this runtime parked dead, named once, as it happens.
115
+ *
116
+ * The runtime owns the claim and the retry, so it is the only subject that
117
+ * knows a stimulus was lost for good. A consumer that had to discover its own
118
+ * losses by re-reading the table would be claiming rows again to find them -
119
+ * which is the second claimer this door exists to remove.
120
+ */
121
+ onDead?(row: MailboxRow, reason: string): void | Promise<void>;
122
+ /**
123
+ * Kinds delivered ahead of the rest. §4.3 forbids a host FIFO in which the
124
+ * person's current request waits behind a mass replay; stating the owner's
125
+ * own message here is what keeps that from happening.
126
+ */
127
+ prefer?: readonly StimulusKind[];
128
+ /** How long a claim may go unacked before it returns to pending. */
129
+ leaseMs?: number;
130
+ /** How many rows one tick delivers before yielding. */
131
+ maxPerTick?: number;
132
+ /** Bound inputs waiting for native ACK; accepted model results do not consume this window. */
133
+ maxPendingInputs?: number;
134
+ /**
135
+ * How often to look when nothing has been accepted. `0` means only on accept.
136
+ *
137
+ * This is the floor under acceptance, not the way work normally arrives, so
138
+ * it is paced to the shortest retry backoff rather than to latency: an accept
139
+ * drains immediately, and nothing else becomes deliverable between ticks
140
+ * except a retry whose minimum wait is a minute.
141
+ */
142
+ intervalMs?: number;
143
+ }
144
+ /**
145
+ * What acceptance means, and what it does not.
146
+ *
147
+ * `accepted` says the stimulus is durable and will be delivered. It is not a
148
+ * claim that anything has been read, decided or done — v7 §4.4 is explicit that
149
+ * a delivery ACK is not a work receipt, and this receipt is one step earlier
150
+ * than that. `duplicate` says every ref the producer stated was already
151
+ * durable, so there is no new row and nothing was lost.
152
+ */
153
+ export interface StimulusReceipt {
154
+ /** The durable row, or `null` when the stimulus was already held. */
155
+ inputId: string | null;
156
+ state: 'accepted' | 'duplicate';
157
+ }
158
+ export interface StartRuntimeOptions {
159
+ paths: RuntimePaths;
160
+ catalog: ActionCatalog;
161
+ dispatch: ActionDispatcher;
162
+ /**
163
+ * Every principal this runtime serves, each with its own credential file.
164
+ * The credential is a bearer token for local session proof only; it is never
165
+ * written to prompts, shared env, or logs. Two principals may not share a
166
+ * credential path — the token would no longer name one caller.
167
+ */
168
+ principals: readonly RuntimePrincipal[];
169
+ /**
170
+ * Passed through to the socket server — host-stated call-site facts for
171
+ * calls on this socket (e.g. the surface name and the credential binding
172
+ * hash). Facts the socket cannot truthfully state stay absent.
173
+ */
174
+ sessionFacts?: (access: JudgmentAccess, request: IpcRequest) => ActionSessionFacts | undefined;
175
+ /** Passed through to the socket server — reclaim a dead socket file, refuse a live one. */
176
+ reclaimStaleSocket?: boolean;
177
+ /**
178
+ * The one model this runtime opens, for the actions that need text back.
179
+ *
180
+ * A library that opens its own model decides for every host that installs it
181
+ * (§2.1). Absent means this runtime has no model to ask, and the actions
182
+ * that would have used one say so rather than answering as if they had.
183
+ */
184
+ runner?: TextCompletion;
185
+ /**
186
+ * The store the durable intake is opened against.
187
+ *
188
+ * Stated by the product for the same reason every path is: core does not
189
+ * choose which database a consumer's mailbox lives in. Absent means this
190
+ * runtime has no intake, and `accept` refuses instead of quietly dropping a
191
+ * stimulus whose producer believes it is now durable.
192
+ */
193
+ mailbox?: {
194
+ adapter: DatabaseAdapter;
195
+ clock?: () => number;
196
+ };
197
+ /**
198
+ * Where an accepted stimulus goes. Absent means this runtime accepts and
199
+ * keeps but hands nothing on — the store is then drained by whoever states
200
+ * they own it, and `drainOnce` is the door they use.
201
+ */
202
+ delivery?: StimulusDelivery;
203
+ /**
204
+ * The harness this runtime owns for its lifetime.
205
+ *
206
+ * Absent means this runtime serves actions and keeps stimuli but opened no
207
+ * model session - an MCP-only profile is exactly that, and it should not
208
+ * pretend to close one.
209
+ */
210
+ nativeSession?: NativeSessionHandle;
211
+ }
212
+ export interface RuntimeHandle {
213
+ /** Internal host port: only a currently claimed input may invoke the native session. */
214
+ runNative<TRequest extends object>(nativeInputId: string, content: ContentBlock[], request?: TRequest & NativeInvocationOptions): Promise<NativeTurnResult>;
215
+ socketPath: string;
216
+ /** The model this runtime opened, or undefined when it opened none. */
217
+ runner?: TextCompletion;
218
+ /**
219
+ * The durable intake this runtime opened, for the consumer that drains it.
220
+ *
221
+ * One store, opened once, by the subject that owns the loop's material. A
222
+ * product that constructed its own would have two openers of one table and
223
+ * no single place that says when it exists.
224
+ */
225
+ mailbox?: Mailbox;
226
+ /**
227
+ * The one door a stimulus enters by. Durable on return, and nothing else.
228
+ *
229
+ * Refuses — loudly — a principal this runtime does not serve, an unknown
230
+ * kind, a stimulus with no channel identity, and a runtime that opened no
231
+ * intake. A producer holding a receipt believes the stimulus is kept, so
232
+ * none of those may pass quietly.
233
+ */
234
+ accept(stimulus: Stimulus): StimulusReceipt;
235
+ /**
236
+ * Deliver what is pending, once. Returns what happened, so a caller that
237
+ * drives the drain itself can tell idle from failing.
238
+ *
239
+ * Runs the stale-claim replay first: a claim is a lease, so a delivery that
240
+ * died mid-flight is owed again rather than lost.
241
+ */
242
+ drainOnce(): Promise<{
243
+ delivered: number;
244
+ failed: number;
245
+ dead: number;
246
+ }>;
247
+ /**
248
+ * The principal a presented credential names, or `undefined` for nobody.
249
+ *
250
+ * One boot issues the credentials; this is the same table the socket
251
+ * resolves against, read by a second local door rather than duplicated. It
252
+ * only ever narrows: an absent or unknown credential resolves to nobody, and
253
+ * there is no caller this answers for that the socket would not.
254
+ */
255
+ principalFor(credential: string | undefined): RuntimePrincipal | undefined;
256
+ /** Whether this boot currently serves an exact principal for durable intake. */
257
+ servesPrincipal(principalId: string): boolean;
258
+ /** Add a product-identified caller to the live socket and intake without reopening either. */
259
+ servePrincipal(principal: RuntimePrincipal): void;
260
+ /** Remove a caller's socket identity and durable-intake admission immediately. */
261
+ unservePrincipal(principalId: string): void;
262
+ /** The harness this runtime opened, or undefined when it opened none. */
263
+ nativeSession?: Pick<NativeSessionHandle, 'stop' | 'resetSession'>;
264
+ /**
265
+ * Closes what start opened, in the order that makes each close safe: the
266
+ * drain first so nothing new is handed out, then the harness, then the socket
267
+ * and this boot's credential. A caller that stops answering action calls
268
+ * before the turn using them has ended would fail that turn on the way out.
269
+ */
270
+ stop(): Promise<void>;
271
+ }
272
+ /**
273
+ * Opens the action surface: issues the session credential and serves
274
+ * `catalog`/`dispatch` on the private socket. `stop` closes the socket and
275
+ * removes the credential file it wrote — nothing else.
276
+ */
277
+ export declare function startRuntime(options: StartRuntimeOptions): Promise<RuntimeHandle>;
278
+ //# sourceMappingURL=runtime.d.ts.map