@jungjaehoon/mama-os 0.53.1 → 0.58.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 (1729) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +62 -259
  3. package/db/migrations/001-connector-event-index.sql +251 -0
  4. package/dist/agent/claude-native-tool-policy.d.ts +17 -0
  5. package/dist/agent/claude-native-tool-policy.d.ts.map +1 -0
  6. package/dist/agent/claude-native-tool-policy.js +88 -0
  7. package/dist/agent/claude-native-tool-policy.js.map +1 -0
  8. package/dist/api/attachment-actions.d.ts +16 -0
  9. package/dist/api/attachment-actions.d.ts.map +1 -0
  10. package/dist/api/attachment-actions.js +280 -0
  11. package/dist/api/attachment-actions.js.map +1 -0
  12. package/dist/api/auth-middleware.d.ts +15 -55
  13. package/dist/api/auth-middleware.d.ts.map +1 -1
  14. package/dist/api/auth-middleware.js +56 -233
  15. package/dist/api/auth-middleware.js.map +1 -1
  16. package/dist/api/cf-access.d.ts +6 -0
  17. package/dist/api/cf-access.d.ts.map +1 -0
  18. package/dist/api/cf-access.js +121 -0
  19. package/dist/api/cf-access.js.map +1 -0
  20. package/dist/api/file-delivery.d.ts +29 -0
  21. package/dist/api/file-delivery.d.ts.map +1 -0
  22. package/dist/api/file-delivery.js +90 -0
  23. package/dist/api/file-delivery.js.map +1 -0
  24. package/dist/api/help-actions.d.ts +12 -0
  25. package/dist/api/help-actions.d.ts.map +1 -0
  26. package/dist/api/help-actions.js +70 -0
  27. package/dist/api/help-actions.js.map +1 -0
  28. package/dist/api/owner-timezone-actions.d.ts +10 -0
  29. package/dist/api/owner-timezone-actions.d.ts.map +1 -0
  30. package/dist/api/owner-timezone-actions.js +73 -0
  31. package/dist/api/owner-timezone-actions.js.map +1 -0
  32. package/dist/api/record-actions.d.ts +8 -0
  33. package/dist/api/record-actions.d.ts.map +1 -0
  34. package/dist/api/record-actions.js +53 -0
  35. package/dist/api/record-actions.js.map +1 -0
  36. package/dist/api/report-actions.d.ts +20 -0
  37. package/dist/api/report-actions.d.ts.map +1 -0
  38. package/dist/api/report-actions.js +137 -0
  39. package/dist/api/report-actions.js.map +1 -0
  40. package/dist/api/report-handler.d.ts +15 -11
  41. package/dist/api/report-handler.d.ts.map +1 -1
  42. package/dist/api/report-handler.js +48 -120
  43. package/dist/api/report-handler.js.map +1 -1
  44. package/dist/api/report-persistence.d.ts +3 -3
  45. package/dist/api/report-persistence.d.ts.map +1 -1
  46. package/dist/api/report-persistence.js +35 -10
  47. package/dist/api/report-persistence.js.map +1 -1
  48. package/dist/api/report-source-actions.d.ts +11 -0
  49. package/dist/api/report-source-actions.d.ts.map +1 -0
  50. package/dist/api/report-source-actions.js +309 -0
  51. package/dist/api/report-source-actions.js.map +1 -0
  52. package/dist/api/security-events.d.ts +23 -0
  53. package/dist/api/security-events.d.ts.map +1 -0
  54. package/dist/api/security-events.js +71 -0
  55. package/dist/api/security-events.js.map +1 -0
  56. package/dist/api/source-actions.d.ts +9 -0
  57. package/dist/api/source-actions.d.ts.map +1 -0
  58. package/dist/api/source-actions.js +274 -0
  59. package/dist/api/source-actions.js.map +1 -0
  60. package/dist/api/stored-source-reader.d.ts +21 -0
  61. package/dist/api/stored-source-reader.d.ts.map +1 -0
  62. package/dist/api/stored-source-reader.js +269 -0
  63. package/dist/api/stored-source-reader.js.map +1 -0
  64. package/dist/api/viewer-data.d.ts +143 -0
  65. package/dist/api/viewer-data.d.ts.map +1 -0
  66. package/dist/api/viewer-data.js +518 -0
  67. package/dist/api/viewer-data.js.map +1 -0
  68. package/dist/api/viewer-request-security.d.ts +12 -0
  69. package/dist/api/viewer-request-security.d.ts.map +1 -0
  70. package/dist/api/viewer-request-security.js +217 -0
  71. package/dist/api/viewer-request-security.js.map +1 -0
  72. package/dist/api/viewer-server.d.ts +56 -0
  73. package/dist/api/viewer-server.d.ts.map +1 -0
  74. package/dist/api/viewer-server.js +937 -0
  75. package/dist/api/viewer-server.js.map +1 -0
  76. package/dist/api/wiki-actions.d.ts +20 -0
  77. package/dist/api/wiki-actions.d.ts.map +1 -0
  78. package/dist/api/wiki-actions.js +296 -0
  79. package/dist/api/wiki-actions.js.map +1 -0
  80. package/dist/api/work-actions.d.ts +96 -0
  81. package/dist/api/work-actions.d.ts.map +1 -0
  82. package/dist/api/work-actions.js +956 -0
  83. package/dist/api/work-actions.js.map +1 -0
  84. package/dist/cli/commands/daemon.d.ts +90 -0
  85. package/dist/cli/commands/daemon.d.ts.map +1 -0
  86. package/dist/cli/commands/daemon.js +632 -0
  87. package/dist/cli/commands/daemon.js.map +1 -0
  88. package/dist/cli/commands/init.d.ts +7 -18
  89. package/dist/cli/commands/init.d.ts.map +1 -1
  90. package/dist/cli/commands/init.js +357 -273
  91. package/dist/cli/commands/init.js.map +1 -1
  92. package/dist/cli/commands/replay.d.ts +12 -0
  93. package/dist/cli/commands/replay.d.ts.map +1 -0
  94. package/dist/cli/commands/replay.js +145 -0
  95. package/dist/cli/commands/replay.js.map +1 -0
  96. package/dist/cli/commands/secret.d.ts +6 -0
  97. package/dist/cli/commands/secret.d.ts.map +1 -0
  98. package/dist/cli/commands/secret.js +24 -0
  99. package/dist/cli/commands/secret.js.map +1 -0
  100. package/dist/cli/index.d.ts +0 -5
  101. package/dist/cli/index.d.ts.map +1 -1
  102. package/dist/cli/index.js +52 -95
  103. package/dist/cli/index.js.map +1 -1
  104. package/dist/cli/launch-files.d.ts +10 -0
  105. package/dist/cli/launch-files.d.ts.map +1 -0
  106. package/dist/cli/launch-files.js +74 -0
  107. package/dist/cli/launch-files.js.map +1 -0
  108. package/dist/cli/prompt.d.ts +15 -0
  109. package/dist/cli/prompt.d.ts.map +1 -0
  110. package/dist/cli/prompt.js +64 -0
  111. package/dist/cli/prompt.js.map +1 -0
  112. package/dist/cli/runtime/action-mcp-config.d.ts +15 -0
  113. package/dist/cli/runtime/action-mcp-config.d.ts.map +1 -0
  114. package/dist/cli/runtime/action-mcp-config.js +56 -0
  115. package/dist/cli/runtime/action-mcp-config.js.map +1 -0
  116. package/dist/cli/runtime/claude-caller-config.d.ts +4 -0
  117. package/dist/cli/runtime/claude-caller-config.d.ts.map +1 -0
  118. package/dist/cli/runtime/claude-caller-config.js +46 -0
  119. package/dist/cli/runtime/claude-caller-config.js.map +1 -0
  120. package/dist/cli/secrets.d.ts +9 -0
  121. package/dist/cli/secrets.d.ts.map +1 -0
  122. package/dist/cli/secrets.js +94 -0
  123. package/dist/cli/secrets.js.map +1 -0
  124. package/dist/connectors/calendar/index.d.ts +11 -10
  125. package/dist/connectors/calendar/index.d.ts.map +1 -1
  126. package/dist/connectors/calendar/index.js +171 -97
  127. package/dist/connectors/calendar/index.js.map +1 -1
  128. package/dist/connectors/chatwork/index.d.ts +31 -5
  129. package/dist/connectors/chatwork/index.d.ts.map +1 -1
  130. package/dist/connectors/chatwork/index.js +184 -20
  131. package/dist/connectors/chatwork/index.js.map +1 -1
  132. package/dist/connectors/claude-code/index.d.ts +0 -2
  133. package/dist/connectors/claude-code/index.d.ts.map +1 -1
  134. package/dist/connectors/claude-code/index.js +94 -70
  135. package/dist/connectors/claude-code/index.js.map +1 -1
  136. package/dist/connectors/config-loader.d.ts +1 -6
  137. package/dist/connectors/config-loader.d.ts.map +1 -1
  138. package/dist/connectors/config-loader.js +154 -134
  139. package/dist/connectors/config-loader.js.map +1 -1
  140. package/dist/connectors/discord/index.d.ts +8 -1
  141. package/dist/connectors/discord/index.d.ts.map +1 -1
  142. package/dist/connectors/discord/index.js +110 -32
  143. package/dist/connectors/discord/index.js.map +1 -1
  144. package/dist/connectors/drive/index.d.ts +10 -5
  145. package/dist/connectors/drive/index.d.ts.map +1 -1
  146. package/dist/connectors/drive/index.js +145 -88
  147. package/dist/connectors/drive/index.js.map +1 -1
  148. package/dist/connectors/framework/attachment-io.d.ts +5 -0
  149. package/dist/connectors/framework/attachment-io.d.ts.map +1 -0
  150. package/dist/connectors/framework/attachment-io.js +72 -0
  151. package/dist/connectors/framework/attachment-io.js.map +1 -0
  152. package/dist/connectors/framework/attachments.d.ts +32 -0
  153. package/dist/connectors/framework/attachments.d.ts.map +1 -0
  154. package/dist/connectors/framework/attachments.js +14 -0
  155. package/dist/connectors/framework/attachments.js.map +1 -0
  156. package/dist/connectors/framework/connector-event-types.d.ts +136 -0
  157. package/dist/connectors/framework/connector-event-types.d.ts.map +1 -0
  158. package/dist/connectors/framework/connector-event-types.js +3 -0
  159. package/dist/connectors/framework/connector-event-types.js.map +1 -0
  160. package/dist/connectors/framework/connector-state.d.ts +3 -0
  161. package/dist/connectors/framework/connector-state.d.ts.map +1 -0
  162. package/dist/connectors/framework/connector-state.js +47 -0
  163. package/dist/connectors/framework/connector-state.js.map +1 -0
  164. package/dist/connectors/framework/event-index.d.ts +28 -0
  165. package/dist/connectors/framework/event-index.d.ts.map +1 -0
  166. package/dist/connectors/framework/event-index.js +354 -0
  167. package/dist/connectors/framework/event-index.js.map +1 -0
  168. package/dist/connectors/framework/gws-utils.d.ts +3 -8
  169. package/dist/connectors/framework/gws-utils.d.ts.map +1 -1
  170. package/dist/connectors/framework/gws-utils.js +23 -30
  171. package/dist/connectors/framework/gws-utils.js.map +1 -1
  172. package/dist/connectors/framework/index.d.ts +4 -2
  173. package/dist/connectors/framework/index.d.ts.map +1 -1
  174. package/dist/connectors/framework/index.js +8 -6
  175. package/dist/connectors/framework/index.js.map +1 -1
  176. package/dist/connectors/framework/polling-scheduler.d.ts +71 -52
  177. package/dist/connectors/framework/polling-scheduler.d.ts.map +1 -1
  178. package/dist/connectors/framework/polling-scheduler.js +236 -168
  179. package/dist/connectors/framework/polling-scheduler.js.map +1 -1
  180. package/dist/connectors/framework/raw-query.d.ts +44 -0
  181. package/dist/connectors/framework/raw-query.d.ts.map +1 -0
  182. package/dist/connectors/framework/raw-query.js +584 -0
  183. package/dist/connectors/framework/raw-query.js.map +1 -0
  184. package/dist/connectors/framework/stored-index-read.d.ts +16 -0
  185. package/dist/connectors/framework/stored-index-read.d.ts.map +1 -0
  186. package/dist/connectors/framework/stored-index-read.js +66 -0
  187. package/dist/connectors/framework/stored-index-read.js.map +1 -0
  188. package/dist/connectors/framework/types.d.ts +17 -61
  189. package/dist/connectors/framework/types.d.ts.map +1 -1
  190. package/dist/connectors/framework/types.js +0 -4
  191. package/dist/connectors/framework/types.js.map +1 -1
  192. package/dist/connectors/gmail/index.d.ts +3 -2
  193. package/dist/connectors/gmail/index.d.ts.map +1 -1
  194. package/dist/connectors/gmail/index.js +74 -27
  195. package/dist/connectors/gmail/index.js.map +1 -1
  196. package/dist/connectors/ical/index.d.ts +29 -0
  197. package/dist/connectors/ical/index.d.ts.map +1 -0
  198. package/dist/connectors/ical/index.js +220 -0
  199. package/dist/connectors/ical/index.js.map +1 -0
  200. package/dist/connectors/ical/parser.d.ts +13 -0
  201. package/dist/connectors/ical/parser.d.ts.map +1 -0
  202. package/dist/connectors/ical/parser.js +117 -0
  203. package/dist/connectors/ical/parser.js.map +1 -0
  204. package/dist/connectors/imessage/index.d.ts +3 -1
  205. package/dist/connectors/imessage/index.d.ts.map +1 -1
  206. package/dist/connectors/imessage/index.js +31 -16
  207. package/dist/connectors/imessage/index.js.map +1 -1
  208. package/dist/connectors/index.d.ts +12 -5
  209. package/dist/connectors/index.d.ts.map +1 -1
  210. package/dist/connectors/index.js +67 -18
  211. package/dist/connectors/index.js.map +1 -1
  212. package/dist/connectors/kagemusha/index.d.ts +7 -19
  213. package/dist/connectors/kagemusha/index.d.ts.map +1 -1
  214. package/dist/connectors/kagemusha/index.js +123 -173
  215. package/dist/connectors/kagemusha/index.js.map +1 -1
  216. package/dist/connectors/notion/index.d.ts.map +1 -1
  217. package/dist/connectors/notion/index.js +79 -36
  218. package/dist/connectors/notion/index.js.map +1 -1
  219. package/dist/connectors/obsidian/index.d.ts +1 -1
  220. package/dist/connectors/obsidian/index.d.ts.map +1 -1
  221. package/dist/connectors/obsidian/index.js +59 -57
  222. package/dist/connectors/obsidian/index.js.map +1 -1
  223. package/dist/connectors/sheets/index.d.ts +8 -4
  224. package/dist/connectors/sheets/index.d.ts.map +1 -1
  225. package/dist/connectors/sheets/index.js +155 -143
  226. package/dist/connectors/sheets/index.js.map +1 -1
  227. package/dist/connectors/slack/index.d.ts +24 -5
  228. package/dist/connectors/slack/index.d.ts.map +1 -1
  229. package/dist/connectors/slack/index.js +177 -39
  230. package/dist/connectors/slack/index.js.map +1 -1
  231. package/dist/connectors/telegram/index.d.ts +9 -2
  232. package/dist/connectors/telegram/index.d.ts.map +1 -1
  233. package/dist/connectors/telegram/index.js +119 -70
  234. package/dist/connectors/telegram/index.js.map +1 -1
  235. package/dist/connectors/trello/index.d.ts +10 -3
  236. package/dist/connectors/trello/index.d.ts.map +1 -1
  237. package/dist/connectors/trello/index.js +88 -39
  238. package/dist/connectors/trello/index.js.map +1 -1
  239. package/dist/gateways/base-gateway.d.ts +9 -33
  240. package/dist/gateways/base-gateway.d.ts.map +1 -1
  241. package/dist/gateways/base-gateway.js +7 -28
  242. package/dist/gateways/base-gateway.js.map +1 -1
  243. package/dist/gateways/conversation-record.d.ts +52 -0
  244. package/dist/gateways/conversation-record.d.ts.map +1 -0
  245. package/dist/gateways/conversation-record.js +220 -0
  246. package/dist/gateways/conversation-record.js.map +1 -0
  247. package/dist/gateways/discord.d.ts +33 -135
  248. package/dist/gateways/discord.d.ts.map +1 -1
  249. package/dist/gateways/discord.js +258 -778
  250. package/dist/gateways/discord.js.map +1 -1
  251. package/dist/gateways/session-store.d.ts +28 -9
  252. package/dist/gateways/session-store.d.ts.map +1 -1
  253. package/dist/gateways/session-store.js +192 -60
  254. package/dist/gateways/session-store.js.map +1 -1
  255. package/dist/gateways/slack.d.ts +35 -105
  256. package/dist/gateways/slack.d.ts.map +1 -1
  257. package/dist/gateways/slack.js +282 -440
  258. package/dist/gateways/slack.js.map +1 -1
  259. package/dist/gateways/telegram-attachments.d.ts +32 -0
  260. package/dist/gateways/telegram-attachments.d.ts.map +1 -0
  261. package/dist/gateways/telegram-attachments.js +113 -0
  262. package/dist/gateways/telegram-attachments.js.map +1 -0
  263. package/dist/gateways/telegram-errors.d.ts +3 -0
  264. package/dist/gateways/telegram-errors.d.ts.map +1 -0
  265. package/dist/gateways/telegram-errors.js +10 -0
  266. package/dist/gateways/telegram-errors.js.map +1 -0
  267. package/dist/gateways/telegram-format.d.ts.map +1 -1
  268. package/dist/gateways/telegram-format.js +11 -3
  269. package/dist/gateways/telegram-format.js.map +1 -1
  270. package/dist/gateways/telegram-message-ledger.d.ts +31 -25
  271. package/dist/gateways/telegram-message-ledger.d.ts.map +1 -1
  272. package/dist/gateways/telegram-message-ledger.js +122 -146
  273. package/dist/gateways/telegram-message-ledger.js.map +1 -1
  274. package/dist/gateways/telegram-response-presenter.d.ts +3 -1
  275. package/dist/gateways/telegram-response-presenter.d.ts.map +1 -1
  276. package/dist/gateways/telegram-response-presenter.js +14 -0
  277. package/dist/gateways/telegram-response-presenter.js.map +1 -1
  278. package/dist/gateways/telegram-text-entities.d.ts +2 -3
  279. package/dist/gateways/telegram-text-entities.d.ts.map +1 -1
  280. package/dist/gateways/telegram-text-entities.js +4 -5
  281. package/dist/gateways/telegram-text-entities.js.map +1 -1
  282. package/dist/gateways/telegram.d.ts +39 -101
  283. package/dist/gateways/telegram.d.ts.map +1 -1
  284. package/dist/gateways/telegram.js +406 -919
  285. package/dist/gateways/telegram.js.map +1 -1
  286. package/dist/gateways/turn-contract.d.ts +27 -87
  287. package/dist/gateways/turn-contract.d.ts.map +1 -1
  288. package/dist/gateways/types.d.ts +14 -299
  289. package/dist/gateways/types.d.ts.map +1 -1
  290. package/dist/gateways/types.js +0 -3
  291. package/dist/gateways/types.js.map +1 -1
  292. package/dist/index.d.ts +1 -6
  293. package/dist/index.d.ts.map +1 -1
  294. package/dist/index.js +0 -23
  295. package/dist/index.js.map +1 -1
  296. package/dist/operator/board-read-views.d.ts +8 -10
  297. package/dist/operator/board-read-views.d.ts.map +1 -1
  298. package/dist/operator/board-read-views.js +7 -16
  299. package/dist/operator/board-read-views.js.map +1 -1
  300. package/dist/operator/board-slot-instructions.d.ts +5 -8
  301. package/dist/operator/board-slot-instructions.d.ts.map +1 -1
  302. package/dist/operator/board-slot-instructions.js +12 -24
  303. package/dist/operator/board-slot-instructions.js.map +1 -1
  304. package/dist/replay/import-manifest.d.ts +21 -0
  305. package/dist/replay/import-manifest.d.ts.map +1 -0
  306. package/dist/replay/import-manifest.js +157 -0
  307. package/dist/replay/import-manifest.js.map +1 -0
  308. package/dist/replay/jev-client.d.ts +35 -0
  309. package/dist/replay/jev-client.d.ts.map +1 -0
  310. package/dist/replay/jev-client.js +141 -0
  311. package/dist/replay/jev-client.js.map +1 -0
  312. package/dist/replay/kagemusha-import.d.ts +35 -0
  313. package/dist/replay/kagemusha-import.d.ts.map +1 -0
  314. package/dist/replay/kagemusha-import.js +543 -0
  315. package/dist/replay/kagemusha-import.js.map +1 -0
  316. package/dist/replay/replay-cursor.d.ts +31 -0
  317. package/dist/replay/replay-cursor.d.ts.map +1 -0
  318. package/dist/replay/replay-cursor.js +189 -0
  319. package/dist/replay/replay-cursor.js.map +1 -0
  320. package/dist/replay/replay-feeder.d.ts +55 -0
  321. package/dist/replay/replay-feeder.d.ts.map +1 -0
  322. package/dist/replay/replay-feeder.js +214 -0
  323. package/dist/replay/replay-feeder.js.map +1 -0
  324. package/dist/replay/replay-ledger.d.ts +32 -0
  325. package/dist/replay/replay-ledger.d.ts.map +1 -0
  326. package/dist/replay/replay-ledger.js +91 -0
  327. package/dist/replay/replay-ledger.js.map +1 -0
  328. package/dist/replay/replay-source-catalog.d.ts +66 -0
  329. package/dist/replay/replay-source-catalog.d.ts.map +1 -0
  330. package/dist/replay/replay-source-catalog.js +332 -0
  331. package/dist/replay/replay-source-catalog.js.map +1 -0
  332. package/dist/replay/trello-import.d.ts +33 -0
  333. package/dist/replay/trello-import.d.ts.map +1 -0
  334. package/dist/replay/trello-import.js +204 -0
  335. package/dist/replay/trello-import.js.map +1 -0
  336. package/dist/replay/window-queue.d.ts +116 -0
  337. package/dist/replay/window-queue.d.ts.map +1 -0
  338. package/dist/replay/window-queue.js +497 -0
  339. package/dist/replay/window-queue.js.map +1 -0
  340. package/dist/runtime/action-mcp-server.d.ts +30 -0
  341. package/dist/runtime/action-mcp-server.d.ts.map +1 -0
  342. package/dist/runtime/action-mcp-server.js +178 -0
  343. package/dist/runtime/action-mcp-server.js.map +1 -0
  344. package/dist/runtime/action-surface.d.ts +47 -0
  345. package/dist/runtime/action-surface.d.ts.map +1 -0
  346. package/dist/runtime/action-surface.js +192 -0
  347. package/dist/runtime/action-surface.js.map +1 -0
  348. package/dist/runtime/backend-security.d.ts +7 -0
  349. package/dist/runtime/backend-security.d.ts.map +1 -0
  350. package/dist/runtime/backend-security.js +28 -0
  351. package/dist/runtime/backend-security.js.map +1 -0
  352. package/dist/runtime/claude-caller-hook.d.ts +20 -0
  353. package/dist/runtime/claude-caller-hook.d.ts.map +1 -0
  354. package/dist/runtime/claude-caller-hook.js +41 -0
  355. package/dist/runtime/claude-caller-hook.js.map +1 -0
  356. package/dist/runtime/config.d.ts +84 -0
  357. package/dist/runtime/config.d.ts.map +1 -0
  358. package/dist/runtime/config.js +361 -0
  359. package/dist/runtime/config.js.map +1 -0
  360. package/dist/runtime/connectors.d.ts +41 -0
  361. package/dist/runtime/connectors.d.ts.map +1 -0
  362. package/dist/runtime/connectors.js +187 -0
  363. package/dist/runtime/connectors.js.map +1 -0
  364. package/dist/runtime/core-db.d.ts +8 -0
  365. package/dist/runtime/core-db.d.ts.map +1 -0
  366. package/dist/runtime/core-db.js +19 -0
  367. package/dist/runtime/core-db.js.map +1 -0
  368. package/dist/runtime/model-cache.d.ts +9 -0
  369. package/dist/runtime/model-cache.d.ts.map +1 -0
  370. package/dist/runtime/model-cache.js +22 -0
  371. package/dist/runtime/model-cache.js.map +1 -0
  372. package/dist/runtime/native-session.d.ts +86 -0
  373. package/dist/runtime/native-session.d.ts.map +1 -0
  374. package/dist/runtime/native-session.js +282 -0
  375. package/dist/runtime/native-session.js.map +1 -0
  376. package/dist/runtime/owner-policy.d.ts +10 -0
  377. package/dist/runtime/owner-policy.d.ts.map +1 -0
  378. package/dist/runtime/owner-policy.js +35 -0
  379. package/dist/runtime/owner-policy.js.map +1 -0
  380. package/dist/runtime/owner-runtime.d.ts +89 -0
  381. package/dist/runtime/owner-runtime.d.ts.map +1 -0
  382. package/dist/runtime/owner-runtime.js +319 -0
  383. package/dist/runtime/owner-runtime.js.map +1 -0
  384. package/dist/runtime/owner-system-prompt.d.ts +16 -0
  385. package/dist/runtime/owner-system-prompt.d.ts.map +1 -0
  386. package/dist/runtime/owner-system-prompt.js +118 -0
  387. package/dist/runtime/owner-system-prompt.js.map +1 -0
  388. package/dist/runtime/recent-owner-exchanges.d.ts +8 -0
  389. package/dist/runtime/recent-owner-exchanges.d.ts.map +1 -0
  390. package/dist/runtime/recent-owner-exchanges.js +27 -0
  391. package/dist/runtime/recent-owner-exchanges.js.map +1 -0
  392. package/dist/runtime/record-orders.d.ts +49 -0
  393. package/dist/runtime/record-orders.d.ts.map +1 -0
  394. package/dist/runtime/record-orders.js +152 -0
  395. package/dist/runtime/record-orders.js.map +1 -0
  396. package/dist/runtime/report-scheduler.d.ts +24 -0
  397. package/dist/runtime/report-scheduler.d.ts.map +1 -0
  398. package/dist/runtime/report-scheduler.js +100 -0
  399. package/dist/runtime/report-scheduler.js.map +1 -0
  400. package/dist/runtime/session-credential.d.ts +5 -0
  401. package/dist/runtime/session-credential.d.ts.map +1 -0
  402. package/dist/runtime/session-credential.js +19 -0
  403. package/dist/runtime/session-credential.js.map +1 -0
  404. package/dist/runtime/stimulus-delivery.d.ts +83 -0
  405. package/dist/runtime/stimulus-delivery.d.ts.map +1 -0
  406. package/dist/runtime/stimulus-delivery.js +507 -0
  407. package/dist/runtime/stimulus-delivery.js.map +1 -0
  408. package/dist/runtime/timezone.d.ts +15 -0
  409. package/dist/runtime/timezone.d.ts.map +1 -0
  410. package/dist/runtime/timezone.js +128 -0
  411. package/dist/runtime/timezone.js.map +1 -0
  412. package/dist/runtime/turn-orders.d.ts +86 -0
  413. package/dist/runtime/turn-orders.d.ts.map +1 -0
  414. package/dist/runtime/turn-orders.js +272 -0
  415. package/dist/runtime/turn-orders.js.map +1 -0
  416. package/dist/sqlite.d.ts +7 -32
  417. package/dist/sqlite.d.ts.map +1 -1
  418. package/dist/sqlite.js +10 -48
  419. package/dist/sqlite.js.map +1 -1
  420. package/dist/storage/migrations/raw-item-revisions.d.ts +6 -0
  421. package/dist/storage/migrations/raw-item-revisions.d.ts.map +1 -0
  422. package/dist/storage/migrations/raw-item-revisions.js +109 -0
  423. package/dist/storage/migrations/raw-item-revisions.js.map +1 -0
  424. package/dist/storage/migrations-source.d.ts +5 -0
  425. package/dist/storage/migrations-source.d.ts.map +1 -0
  426. package/dist/storage/migrations-source.js +24 -0
  427. package/dist/storage/migrations-source.js.map +1 -0
  428. package/dist/storage/source-archive.d.ts +123 -0
  429. package/dist/storage/source-archive.d.ts.map +1 -0
  430. package/dist/storage/source-archive.js +595 -0
  431. package/dist/storage/source-archive.js.map +1 -0
  432. package/dist/storage-sqlite.d.ts +59 -0
  433. package/dist/storage-sqlite.d.ts.map +1 -0
  434. package/dist/storage-sqlite.js +75 -0
  435. package/dist/storage-sqlite.js.map +1 -0
  436. package/dist/utils/untrusted-content.d.ts +5 -35
  437. package/dist/utils/untrusted-content.d.ts.map +1 -1
  438. package/dist/utils/untrusted-content.js +16 -75
  439. package/dist/utils/untrusted-content.js.map +1 -1
  440. package/dist/wiki/obsidian-writer.d.ts +4 -2
  441. package/dist/wiki/obsidian-writer.d.ts.map +1 -1
  442. package/dist/wiki/obsidian-writer.js +85 -4
  443. package/dist/wiki/obsidian-writer.js.map +1 -1
  444. package/dist/wiki/path-safety.d.ts +2 -0
  445. package/dist/wiki/path-safety.d.ts.map +1 -1
  446. package/dist/wiki/path-safety.js +11 -3
  447. package/dist/wiki/path-safety.js.map +1 -1
  448. package/dist/wiki/wiki-edits.d.ts +17 -0
  449. package/dist/wiki/wiki-edits.d.ts.map +1 -0
  450. package/dist/wiki/wiki-edits.js +75 -0
  451. package/dist/wiki/wiki-edits.js.map +1 -0
  452. package/dist/wiki/wiki-read.d.ts +20 -11
  453. package/dist/wiki/wiki-read.d.ts.map +1 -1
  454. package/dist/wiki/wiki-read.js +87 -89
  455. package/dist/wiki/wiki-read.js.map +1 -1
  456. package/dist/wiki-artifacts/types.d.ts +1 -1
  457. package/dist/wiki-artifacts/types.d.ts.map +1 -1
  458. package/dist/wiki-artifacts/wiki-publish-adapter.d.ts.map +1 -1
  459. package/dist/wiki-artifacts/wiki-publish-adapter.js +13 -9
  460. package/dist/wiki-artifacts/wiki-publish-adapter.js.map +1 -1
  461. package/package.json +11 -41
  462. package/public/viewer/js/modules/graph.js +111 -41
  463. package/public/viewer/js/modules/memory.js +4 -31
  464. package/public/viewer/js/modules/wiki.js +0 -37
  465. package/public/viewer/js/utils/api.js +4 -50
  466. package/public/viewer/log-viewer.html +46 -0
  467. package/public/viewer/operator/operator.css +1 -1
  468. package/public/viewer/operator/operator.js +10835 -8211
  469. package/public/viewer/src/modules/graph.ts +133 -41
  470. package/public/viewer/src/modules/memory.ts +4 -31
  471. package/public/viewer/src/modules/wiki.ts +0 -42
  472. package/public/viewer/src/types/global.d.ts +1 -1
  473. package/public/viewer/src/utils/api.ts +7 -83
  474. package/public/viewer/viewer.html +7 -96
  475. package/dist/agent/agent-loop.d.ts +0 -289
  476. package/dist/agent/agent-loop.d.ts.map +0 -1
  477. package/dist/agent/agent-loop.js +0 -2842
  478. package/dist/agent/agent-loop.js.map +0 -1
  479. package/dist/agent/attachment-text-extractor.d.ts +0 -2
  480. package/dist/agent/attachment-text-extractor.d.ts.map +0 -1
  481. package/dist/agent/attachment-text-extractor.js +0 -128
  482. package/dist/agent/attachment-text-extractor.js.map +0 -1
  483. package/dist/agent/backend-model-policy.d.ts +0 -58
  484. package/dist/agent/backend-model-policy.d.ts.map +0 -1
  485. package/dist/agent/backend-model-policy.js +0 -167
  486. package/dist/agent/backend-model-policy.js.map +0 -1
  487. package/dist/agent/backend-model-runner-factory.d.ts +0 -27
  488. package/dist/agent/backend-model-runner-factory.d.ts.map +0 -1
  489. package/dist/agent/backend-model-runner-factory.js +0 -88
  490. package/dist/agent/backend-model-runner-factory.js.map +0 -1
  491. package/dist/agent/claude-cli-wrapper.d.ts +0 -144
  492. package/dist/agent/claude-cli-wrapper.d.ts.map +0 -1
  493. package/dist/agent/claude-cli-wrapper.js +0 -382
  494. package/dist/agent/claude-cli-wrapper.js.map +0 -1
  495. package/dist/agent/cli-arg-redaction.d.ts +0 -2
  496. package/dist/agent/cli-arg-redaction.d.ts.map +0 -1
  497. package/dist/agent/cli-arg-redaction.js +0 -18
  498. package/dist/agent/cli-arg-redaction.js.map +0 -1
  499. package/dist/agent/cline-cli-adapter.d.ts +0 -126
  500. package/dist/agent/cline-cli-adapter.d.ts.map +0 -1
  501. package/dist/agent/cline-cli-adapter.js +0 -1042
  502. package/dist/agent/cline-cli-adapter.js.map +0 -1
  503. package/dist/agent/cline-native-tool-policy.d.ts +0 -9
  504. package/dist/agent/cline-native-tool-policy.d.ts.map +0 -1
  505. package/dist/agent/cline-native-tool-policy.js +0 -61
  506. package/dist/agent/cline-native-tool-policy.js.map +0 -1
  507. package/dist/agent/code-act/completed-terminal-result.d.ts +0 -5
  508. package/dist/agent/code-act/completed-terminal-result.d.ts.map +0 -1
  509. package/dist/agent/code-act/completed-terminal-result.js +0 -83
  510. package/dist/agent/code-act/completed-terminal-result.js.map +0 -1
  511. package/dist/agent/code-act/constants.d.ts +0 -11
  512. package/dist/agent/code-act/constants.d.ts.map +0 -1
  513. package/dist/agent/code-act/constants.js +0 -64
  514. package/dist/agent/code-act/constants.js.map +0 -1
  515. package/dist/agent/code-act/host-bridge.d.ts +0 -50
  516. package/dist/agent/code-act/host-bridge.d.ts.map +0 -1
  517. package/dist/agent/code-act/host-bridge.js +0 -1405
  518. package/dist/agent/code-act/host-bridge.js.map +0 -1
  519. package/dist/agent/code-act/index.d.ts +0 -10
  520. package/dist/agent/code-act/index.d.ts.map +0 -1
  521. package/dist/agent/code-act/index.js +0 -22
  522. package/dist/agent/code-act/index.js.map +0 -1
  523. package/dist/agent/code-act/run-context-registry.d.ts +0 -36
  524. package/dist/agent/code-act/run-context-registry.d.ts.map +0 -1
  525. package/dist/agent/code-act/run-context-registry.js +0 -143
  526. package/dist/agent/code-act/run-context-registry.js.map +0 -1
  527. package/dist/agent/code-act/sandbox.d.ts +0 -25
  528. package/dist/agent/code-act/sandbox.d.ts.map +0 -1
  529. package/dist/agent/code-act/sandbox.js +0 -494
  530. package/dist/agent/code-act/sandbox.js.map +0 -1
  531. package/dist/agent/code-act/tool-catalog.d.ts +0 -30
  532. package/dist/agent/code-act/tool-catalog.d.ts.map +0 -1
  533. package/dist/agent/code-act/tool-catalog.js +0 -185
  534. package/dist/agent/code-act/tool-catalog.js.map +0 -1
  535. package/dist/agent/code-act/tool-policy.d.ts +0 -51
  536. package/dist/agent/code-act/tool-policy.d.ts.map +0 -1
  537. package/dist/agent/code-act/tool-policy.js +0 -160
  538. package/dist/agent/code-act/tool-policy.js.map +0 -1
  539. package/dist/agent/code-act/type-definition-generator.d.ts +0 -19
  540. package/dist/agent/code-act/type-definition-generator.d.ts.map +0 -1
  541. package/dist/agent/code-act/type-definition-generator.js +0 -73
  542. package/dist/agent/code-act/type-definition-generator.js.map +0 -1
  543. package/dist/agent/code-act/types.d.ts +0 -57
  544. package/dist/agent/code-act/types.d.ts.map +0 -1
  545. package/dist/agent/code-act/types.js +0 -14
  546. package/dist/agent/code-act/types.js.map +0 -1
  547. package/dist/agent/codex-app-server-process.d.ts +0 -257
  548. package/dist/agent/codex-app-server-process.d.ts.map +0 -1
  549. package/dist/agent/codex-app-server-process.js +0 -2084
  550. package/dist/agent/codex-app-server-process.js.map +0 -1
  551. package/dist/agent/codex-auth.d.ts +0 -2
  552. package/dist/agent/codex-auth.d.ts.map +0 -1
  553. package/dist/agent/codex-auth.js +0 -17
  554. package/dist/agent/codex-auth.js.map +0 -1
  555. package/dist/agent/codex-auxiliary-tools.d.ts +0 -17
  556. package/dist/agent/codex-auxiliary-tools.d.ts.map +0 -1
  557. package/dist/agent/codex-auxiliary-tools.js +0 -267
  558. package/dist/agent/codex-auxiliary-tools.js.map +0 -1
  559. package/dist/agent/codex-home.d.ts +0 -13
  560. package/dist/agent/codex-home.d.ts.map +0 -1
  561. package/dist/agent/codex-home.js +0 -644
  562. package/dist/agent/codex-home.js.map +0 -1
  563. package/dist/agent/codex-thread-registry.d.ts +0 -63
  564. package/dist/agent/codex-thread-registry.d.ts.map +0 -1
  565. package/dist/agent/codex-thread-registry.js +0 -433
  566. package/dist/agent/codex-thread-registry.js.map +0 -1
  567. package/dist/agent/content-dedup.d.ts +0 -86
  568. package/dist/agent/content-dedup.d.ts.map +0 -1
  569. package/dist/agent/content-dedup.js +0 -114
  570. package/dist/agent/content-dedup.js.map +0 -1
  571. package/dist/agent/context-compile-contract.d.ts +0 -5
  572. package/dist/agent/context-compile-contract.d.ts.map +0 -1
  573. package/dist/agent/context-compile-contract.js +0 -8
  574. package/dist/agent/context-compile-contract.js.map +0 -1
  575. package/dist/agent/context-compile-service.d.ts +0 -60
  576. package/dist/agent/context-compile-service.d.ts.map +0 -1
  577. package/dist/agent/context-compile-service.js +0 -481
  578. package/dist/agent/context-compile-service.js.map +0 -1
  579. package/dist/agent/context-prompt-builder.d.ts +0 -24
  580. package/dist/agent/context-prompt-builder.d.ts.map +0 -1
  581. package/dist/agent/context-prompt-builder.js +0 -61
  582. package/dist/agent/context-prompt-builder.js.map +0 -1
  583. package/dist/agent/contract-extractor.d.ts +0 -124
  584. package/dist/agent/contract-extractor.d.ts.map +0 -1
  585. package/dist/agent/contract-extractor.js +0 -465
  586. package/dist/agent/contract-extractor.js.map +0 -1
  587. package/dist/agent/drive-tools.d.ts +0 -83
  588. package/dist/agent/drive-tools.d.ts.map +0 -1
  589. package/dist/agent/drive-tools.js +0 -338
  590. package/dist/agent/drive-tools.js.map +0 -1
  591. package/dist/agent/gateway-tool-catalog.d.ts +0 -14
  592. package/dist/agent/gateway-tool-catalog.d.ts.map +0 -1
  593. package/dist/agent/gateway-tool-catalog.js +0 -41
  594. package/dist/agent/gateway-tool-catalog.js.map +0 -1
  595. package/dist/agent/gateway-tool-executor.d.ts +0 -353
  596. package/dist/agent/gateway-tool-executor.d.ts.map +0 -1
  597. package/dist/agent/gateway-tool-executor.js +0 -5448
  598. package/dist/agent/gateway-tool-executor.js.map +0 -1
  599. package/dist/agent/gateway-tools.md +0 -166
  600. package/dist/agent/image-translation-tools.d.ts +0 -48
  601. package/dist/agent/image-translation-tools.d.ts.map +0 -1
  602. package/dist/agent/image-translation-tools.js +0 -274
  603. package/dist/agent/image-translation-tools.js.map +0 -1
  604. package/dist/agent/index.d.ts +0 -13
  605. package/dist/agent/index.d.ts.map +0 -1
  606. package/dist/agent/index.js +0 -18
  607. package/dist/agent/index.js.map +0 -1
  608. package/dist/agent/mama-tool-handlers.d.ts +0 -11
  609. package/dist/agent/mama-tool-handlers.d.ts.map +0 -1
  610. package/dist/agent/mama-tool-handlers.js +0 -220
  611. package/dist/agent/mama-tool-handlers.js.map +0 -1
  612. package/dist/agent/managed-agent-runtime-sync.d.ts +0 -36
  613. package/dist/agent/managed-agent-runtime-sync.d.ts.map +0 -1
  614. package/dist/agent/managed-agent-runtime-sync.js +0 -245
  615. package/dist/agent/managed-agent-runtime-sync.js.map +0 -1
  616. package/dist/agent/managed-agent-validation.d.ts +0 -4
  617. package/dist/agent/managed-agent-validation.d.ts.map +0 -1
  618. package/dist/agent/managed-agent-validation.js +0 -85
  619. package/dist/agent/managed-agent-validation.js.map +0 -1
  620. package/dist/agent/model-runner.d.ts +0 -180
  621. package/dist/agent/model-runner.d.ts.map +0 -1
  622. package/dist/agent/model-runner.js +0 -54
  623. package/dist/agent/model-runner.js.map +0 -1
  624. package/dist/agent/native-effect-observer.d.ts +0 -20
  625. package/dist/agent/native-effect-observer.d.ts.map +0 -1
  626. package/dist/agent/native-effect-observer.js +0 -86
  627. package/dist/agent/native-effect-observer.js.map +0 -1
  628. package/dist/agent/obsidian-cli-args.d.ts +0 -14
  629. package/dist/agent/obsidian-cli-args.d.ts.map +0 -1
  630. package/dist/agent/obsidian-cli-args.js +0 -57
  631. package/dist/agent/obsidian-cli-args.js.map +0 -1
  632. package/dist/agent/os-agent-capabilities.md +0 -367
  633. package/dist/agent/persistent-cli-adapter.d.ts +0 -173
  634. package/dist/agent/persistent-cli-adapter.d.ts.map +0 -1
  635. package/dist/agent/persistent-cli-adapter.js +0 -506
  636. package/dist/agent/persistent-cli-adapter.js.map +0 -1
  637. package/dist/agent/persistent-cli-process.d.ts +0 -392
  638. package/dist/agent/persistent-cli-process.d.ts.map +0 -1
  639. package/dist/agent/persistent-cli-process.js +0 -1568
  640. package/dist/agent/persistent-cli-process.js.map +0 -1
  641. package/dist/agent/post-tool-handler.d.ts +0 -27
  642. package/dist/agent/post-tool-handler.d.ts.map +0 -1
  643. package/dist/agent/post-tool-handler.js +0 -194
  644. package/dist/agent/post-tool-handler.js.map +0 -1
  645. package/dist/agent/pre-compact-handler.d.ts +0 -36
  646. package/dist/agent/pre-compact-handler.d.ts.map +0 -1
  647. package/dist/agent/pre-compact-handler.js +0 -162
  648. package/dist/agent/pre-compact-handler.js.map +0 -1
  649. package/dist/agent/prompt-enhancer.d.ts +0 -33
  650. package/dist/agent/prompt-enhancer.d.ts.map +0 -1
  651. package/dist/agent/prompt-enhancer.js +0 -811
  652. package/dist/agent/prompt-enhancer.js.map +0 -1
  653. package/dist/agent/prompt-size-monitor.d.ts +0 -104
  654. package/dist/agent/prompt-size-monitor.d.ts.map +0 -1
  655. package/dist/agent/prompt-size-monitor.js +0 -192
  656. package/dist/agent/prompt-size-monitor.js.map +0 -1
  657. package/dist/agent/role-manager.d.ts +0 -122
  658. package/dist/agent/role-manager.d.ts.map +0 -1
  659. package/dist/agent/role-manager.js +0 -300
  660. package/dist/agent/role-manager.js.map +0 -1
  661. package/dist/agent/session-pool.d.ts +0 -176
  662. package/dist/agent/session-pool.d.ts.map +0 -1
  663. package/dist/agent/session-pool.js +0 -368
  664. package/dist/agent/session-pool.js.map +0 -1
  665. package/dist/agent/skill-loader.d.ts +0 -87
  666. package/dist/agent/skill-loader.d.ts.map +0 -1
  667. package/dist/agent/skill-loader.js +0 -461
  668. package/dist/agent/skill-loader.js.map +0 -1
  669. package/dist/agent/stop-continuation-handler.d.ts +0 -106
  670. package/dist/agent/stop-continuation-handler.d.ts.map +0 -1
  671. package/dist/agent/stop-continuation-handler.js +0 -230
  672. package/dist/agent/stop-continuation-handler.js.map +0 -1
  673. package/dist/agent/subagent-run-reconcile.d.ts +0 -23
  674. package/dist/agent/subagent-run-reconcile.d.ts.map +0 -1
  675. package/dist/agent/subagent-run-reconcile.js +0 -56
  676. package/dist/agent/subagent-run-reconcile.js.map +0 -1
  677. package/dist/agent/temporal-code-act-breaker.d.ts +0 -26
  678. package/dist/agent/temporal-code-act-breaker.d.ts.map +0 -1
  679. package/dist/agent/temporal-code-act-breaker.js +0 -94
  680. package/dist/agent/temporal-code-act-breaker.js.map +0 -1
  681. package/dist/agent/token-estimator.d.ts +0 -25
  682. package/dist/agent/token-estimator.d.ts.map +0 -1
  683. package/dist/agent/token-estimator.js +0 -75
  684. package/dist/agent/token-estimator.js.map +0 -1
  685. package/dist/agent/tool-registry.d.ts +0 -81
  686. package/dist/agent/tool-registry.d.ts.map +0 -1
  687. package/dist/agent/tool-registry.js +0 -876
  688. package/dist/agent/tool-registry.js.map +0 -1
  689. package/dist/agent/types.d.ts +0 -1261
  690. package/dist/agent/types.d.ts.map +0 -1
  691. package/dist/agent/types.js +0 -60
  692. package/dist/agent/types.js.map +0 -1
  693. package/dist/agent/yaml-frontmatter.d.ts +0 -75
  694. package/dist/agent/yaml-frontmatter.d.ts.map +0 -1
  695. package/dist/agent/yaml-frontmatter.js +0 -166
  696. package/dist/agent/yaml-frontmatter.js.map +0 -1
  697. package/dist/api/agent-context-handler.d.ts +0 -10
  698. package/dist/api/agent-context-handler.d.ts.map +0 -1
  699. package/dist/api/agent-context-handler.js +0 -216
  700. package/dist/api/agent-context-handler.js.map +0 -1
  701. package/dist/api/agent-graph-handler.d.ts +0 -18
  702. package/dist/api/agent-graph-handler.d.ts.map +0 -1
  703. package/dist/api/agent-graph-handler.js +0 -569
  704. package/dist/api/agent-graph-handler.js.map +0 -1
  705. package/dist/api/agent-handler.d.ts +0 -36
  706. package/dist/api/agent-handler.d.ts.map +0 -1
  707. package/dist/api/agent-handler.js +0 -223
  708. package/dist/api/agent-handler.js.map +0 -1
  709. package/dist/api/agent-raw-handler.d.ts +0 -70
  710. package/dist/api/agent-raw-handler.d.ts.map +0 -1
  711. package/dist/api/agent-raw-handler.js +0 -262
  712. package/dist/api/agent-raw-handler.js.map +0 -1
  713. package/dist/api/agent-situation-handler.d.ts +0 -14
  714. package/dist/api/agent-situation-handler.d.ts.map +0 -1
  715. package/dist/api/agent-situation-handler.js +0 -383
  716. package/dist/api/agent-situation-handler.js.map +0 -1
  717. package/dist/api/connector-feed-handler.d.ts +0 -42
  718. package/dist/api/connector-feed-handler.d.ts.map +0 -1
  719. package/dist/api/connector-feed-handler.js +0 -180
  720. package/dist/api/connector-feed-handler.js.map +0 -1
  721. package/dist/api/cron-handler.d.ts +0 -44
  722. package/dist/api/cron-handler.d.ts.map +0 -1
  723. package/dist/api/cron-handler.js +0 -261
  724. package/dist/api/cron-handler.js.map +0 -1
  725. package/dist/api/entity-audit-handler.d.ts +0 -12
  726. package/dist/api/entity-audit-handler.d.ts.map +0 -1
  727. package/dist/api/entity-audit-handler.js +0 -119
  728. package/dist/api/entity-audit-handler.js.map +0 -1
  729. package/dist/api/entity-audit-queue.d.ts +0 -74
  730. package/dist/api/entity-audit-queue.d.ts.map +0 -1
  731. package/dist/api/entity-audit-queue.js +0 -123
  732. package/dist/api/entity-audit-queue.js.map +0 -1
  733. package/dist/api/entity-audit-runner.d.ts +0 -9
  734. package/dist/api/entity-audit-runner.d.ts.map +0 -1
  735. package/dist/api/entity-audit-runner.js +0 -240
  736. package/dist/api/entity-audit-runner.js.map +0 -1
  737. package/dist/api/entity-review-handler.d.ts +0 -18
  738. package/dist/api/entity-review-handler.d.ts.map +0 -1
  739. package/dist/api/entity-review-handler.js +0 -521
  740. package/dist/api/entity-review-handler.js.map +0 -1
  741. package/dist/api/error-handler.d.ts +0 -22
  742. package/dist/api/error-handler.d.ts.map +0 -1
  743. package/dist/api/error-handler.js +0 -104
  744. package/dist/api/error-handler.js.map +0 -1
  745. package/dist/api/graph-api-types.d.ts +0 -105
  746. package/dist/api/graph-api-types.d.ts.map +0 -1
  747. package/dist/api/graph-api-types.js +0 -6
  748. package/dist/api/graph-api-types.js.map +0 -1
  749. package/dist/api/graph-api.d.ts +0 -42
  750. package/dist/api/graph-api.d.ts.map +0 -1
  751. package/dist/api/graph-api.js +0 -3460
  752. package/dist/api/graph-api.js.map +0 -1
  753. package/dist/api/heartbeat-handler.d.ts +0 -49
  754. package/dist/api/heartbeat-handler.d.ts.map +0 -1
  755. package/dist/api/heartbeat-handler.js +0 -106
  756. package/dist/api/heartbeat-handler.js.map +0 -1
  757. package/dist/api/index.d.ts +0 -145
  758. package/dist/api/index.d.ts.map +0 -1
  759. package/dist/api/index.js +0 -448
  760. package/dist/api/index.js.map +0 -1
  761. package/dist/api/intelligence-handler.d.ts +0 -116
  762. package/dist/api/intelligence-handler.d.ts.map +0 -1
  763. package/dist/api/intelligence-handler.js +0 -280
  764. package/dist/api/intelligence-handler.js.map +0 -1
  765. package/dist/api/memory-provenance-handler.d.ts +0 -3
  766. package/dist/api/memory-provenance-handler.d.ts.map +0 -1
  767. package/dist/api/memory-provenance-handler.js +0 -120
  768. package/dist/api/memory-provenance-handler.js.map +0 -1
  769. package/dist/api/operator-handler.d.ts +0 -19
  770. package/dist/api/operator-handler.d.ts.map +0 -1
  771. package/dist/api/operator-handler.js +0 -106
  772. package/dist/api/operator-handler.js.map +0 -1
  773. package/dist/api/operator-summary.d.ts +0 -3
  774. package/dist/api/operator-summary.d.ts.map +0 -1
  775. package/dist/api/operator-summary.js +0 -72
  776. package/dist/api/operator-summary.js.map +0 -1
  777. package/dist/api/operator-tasks-handler.d.ts +0 -7
  778. package/dist/api/operator-tasks-handler.d.ts.map +0 -1
  779. package/dist/api/operator-tasks-handler.js +0 -192
  780. package/dist/api/operator-tasks-handler.js.map +0 -1
  781. package/dist/api/runtime-status-handler.d.ts +0 -42
  782. package/dist/api/runtime-status-handler.d.ts.map +0 -1
  783. package/dist/api/runtime-status-handler.js +0 -56
  784. package/dist/api/runtime-status-handler.js.map +0 -1
  785. package/dist/api/skills-handler.d.ts +0 -12
  786. package/dist/api/skills-handler.d.ts.map +0 -1
  787. package/dist/api/skills-handler.js +0 -156
  788. package/dist/api/skills-handler.js.map +0 -1
  789. package/dist/api/token-handler.d.ts +0 -33
  790. package/dist/api/token-handler.d.ts.map +0 -1
  791. package/dist/api/token-handler.js +0 -118
  792. package/dist/api/token-handler.js.map +0 -1
  793. package/dist/api/types.d.ts +0 -155
  794. package/dist/api/types.d.ts.map +0 -1
  795. package/dist/api/types.js +0 -49
  796. package/dist/api/types.js.map +0 -1
  797. package/dist/api/ui-command-handler.d.ts +0 -48
  798. package/dist/api/ui-command-handler.d.ts.map +0 -1
  799. package/dist/api/ui-command-handler.js +0 -160
  800. package/dist/api/ui-command-handler.js.map +0 -1
  801. package/dist/api/upload-handler.d.ts +0 -12
  802. package/dist/api/upload-handler.d.ts.map +0 -1
  803. package/dist/api/upload-handler.js +0 -321
  804. package/dist/api/upload-handler.js.map +0 -1
  805. package/dist/api/wiki-handler.d.ts +0 -19
  806. package/dist/api/wiki-handler.d.ts.map +0 -1
  807. package/dist/api/wiki-handler.js +0 -136
  808. package/dist/api/wiki-handler.js.map +0 -1
  809. package/dist/api/worker-envelope.d.ts +0 -26
  810. package/dist/api/worker-envelope.d.ts.map +0 -1
  811. package/dist/api/worker-envelope.js +0 -176
  812. package/dist/api/worker-envelope.js.map +0 -1
  813. package/dist/auth/claude-client.d.ts +0 -12
  814. package/dist/auth/claude-client.d.ts.map +0 -1
  815. package/dist/auth/claude-client.js +0 -36
  816. package/dist/auth/claude-client.js.map +0 -1
  817. package/dist/auth/claude-code-auth.d.ts +0 -12
  818. package/dist/auth/claude-code-auth.d.ts.map +0 -1
  819. package/dist/auth/claude-code-auth.js +0 -85
  820. package/dist/auth/claude-code-auth.js.map +0 -1
  821. package/dist/auth/index.d.ts +0 -9
  822. package/dist/auth/index.d.ts.map +0 -1
  823. package/dist/auth/index.js +0 -13
  824. package/dist/auth/index.js.map +0 -1
  825. package/dist/auth/oauth-manager.d.ts +0 -59
  826. package/dist/auth/oauth-manager.d.ts.map +0 -1
  827. package/dist/auth/oauth-manager.js +0 -252
  828. package/dist/auth/oauth-manager.js.map +0 -1
  829. package/dist/auth/types.d.ts +0 -92
  830. package/dist/auth/types.d.ts.map +0 -1
  831. package/dist/auth/types.js +0 -23
  832. package/dist/auth/types.js.map +0 -1
  833. package/dist/cli/commands/connector.d.ts +0 -14
  834. package/dist/cli/commands/connector.d.ts.map +0 -1
  835. package/dist/cli/commands/connector.js +0 -174
  836. package/dist/cli/commands/connector.js.map +0 -1
  837. package/dist/cli/commands/gateway.d.ts +0 -18
  838. package/dist/cli/commands/gateway.d.ts.map +0 -1
  839. package/dist/cli/commands/gateway.js +0 -144
  840. package/dist/cli/commands/gateway.js.map +0 -1
  841. package/dist/cli/commands/report.d.ts +0 -14
  842. package/dist/cli/commands/report.d.ts.map +0 -1
  843. package/dist/cli/commands/report.js +0 -102
  844. package/dist/cli/commands/report.js.map +0 -1
  845. package/dist/cli/commands/run.d.ts +0 -19
  846. package/dist/cli/commands/run.d.ts.map +0 -1
  847. package/dist/cli/commands/run.js +0 -123
  848. package/dist/cli/commands/run.js.map +0 -1
  849. package/dist/cli/commands/setup.d.ts +0 -3
  850. package/dist/cli/commands/setup.d.ts.map +0 -1
  851. package/dist/cli/commands/setup.js +0 -9
  852. package/dist/cli/commands/setup.js.map +0 -1
  853. package/dist/cli/commands/start.d.ts +0 -263
  854. package/dist/cli/commands/start.d.ts.map +0 -1
  855. package/dist/cli/commands/start.js +0 -2230
  856. package/dist/cli/commands/start.js.map +0 -1
  857. package/dist/cli/commands/status.d.ts +0 -18
  858. package/dist/cli/commands/status.d.ts.map +0 -1
  859. package/dist/cli/commands/status.js +0 -326
  860. package/dist/cli/commands/status.js.map +0 -1
  861. package/dist/cli/commands/stop.d.ts +0 -28
  862. package/dist/cli/commands/stop.d.ts.map +0 -1
  863. package/dist/cli/commands/stop.js +0 -597
  864. package/dist/cli/commands/stop.js.map +0 -1
  865. package/dist/cli/config/config-manager.d.ts +0 -84
  866. package/dist/cli/config/config-manager.d.ts.map +0 -1
  867. package/dist/cli/config/config-manager.js +0 -886
  868. package/dist/cli/config/config-manager.js.map +0 -1
  869. package/dist/cli/config/types.d.ts +0 -633
  870. package/dist/cli/config/types.d.ts.map +0 -1
  871. package/dist/cli/config/types.js +0 -247
  872. package/dist/cli/config/types.js.map +0 -1
  873. package/dist/cli/runtime/agent-loop-init.d.ts +0 -53
  874. package/dist/cli/runtime/agent-loop-init.d.ts.map +0 -1
  875. package/dist/cli/runtime/agent-loop-init.js +0 -368
  876. package/dist/cli/runtime/agent-loop-init.js.map +0 -1
  877. package/dist/cli/runtime/api-routes-init.d.ts +0 -84
  878. package/dist/cli/runtime/api-routes-init.d.ts.map +0 -1
  879. package/dist/cli/runtime/api-routes-init.js +0 -1542
  880. package/dist/cli/runtime/api-routes-init.js.map +0 -1
  881. package/dist/cli/runtime/api-server-init.d.ts +0 -59
  882. package/dist/cli/runtime/api-server-init.d.ts.map +0 -1
  883. package/dist/cli/runtime/api-server-init.js +0 -159
  884. package/dist/cli/runtime/api-server-init.js.map +0 -1
  885. package/dist/cli/runtime/code-act-executor.d.ts +0 -14
  886. package/dist/cli/runtime/code-act-executor.d.ts.map +0 -1
  887. package/dist/cli/runtime/code-act-executor.js +0 -108
  888. package/dist/cli/runtime/code-act-executor.js.map +0 -1
  889. package/dist/cli/runtime/connector-bootstrap.d.ts +0 -8
  890. package/dist/cli/runtime/connector-bootstrap.d.ts.map +0 -1
  891. package/dist/cli/runtime/connector-bootstrap.js +0 -14
  892. package/dist/cli/runtime/connector-bootstrap.js.map +0 -1
  893. package/dist/cli/runtime/connector-init.d.ts +0 -64
  894. package/dist/cli/runtime/connector-init.d.ts.map +0 -1
  895. package/dist/cli/runtime/connector-init.js +0 -237
  896. package/dist/cli/runtime/connector-init.js.map +0 -1
  897. package/dist/cli/runtime/daemon.d.ts +0 -38
  898. package/dist/cli/runtime/daemon.d.ts.map +0 -1
  899. package/dist/cli/runtime/daemon.js +0 -263
  900. package/dist/cli/runtime/daemon.js.map +0 -1
  901. package/dist/cli/runtime/envelope-bootstrap.d.ts +0 -17
  902. package/dist/cli/runtime/envelope-bootstrap.d.ts.map +0 -1
  903. package/dist/cli/runtime/envelope-bootstrap.js +0 -56
  904. package/dist/cli/runtime/envelope-bootstrap.js.map +0 -1
  905. package/dist/cli/runtime/gateway-init.d.ts +0 -55
  906. package/dist/cli/runtime/gateway-init.d.ts.map +0 -1
  907. package/dist/cli/runtime/gateway-init.js +0 -196
  908. package/dist/cli/runtime/gateway-init.js.map +0 -1
  909. package/dist/cli/runtime/gateway-wiring.d.ts +0 -51
  910. package/dist/cli/runtime/gateway-wiring.d.ts.map +0 -1
  911. package/dist/cli/runtime/gateway-wiring.js +0 -215
  912. package/dist/cli/runtime/gateway-wiring.js.map +0 -1
  913. package/dist/cli/runtime/mama-core-init.d.ts +0 -42
  914. package/dist/cli/runtime/mama-core-init.d.ts.map +0 -1
  915. package/dist/cli/runtime/mama-core-init.js +0 -211
  916. package/dist/cli/runtime/mama-core-init.js.map +0 -1
  917. package/dist/cli/runtime/message-router-config.d.ts +0 -4
  918. package/dist/cli/runtime/message-router-config.d.ts.map +0 -1
  919. package/dist/cli/runtime/message-router-config.js +0 -11
  920. package/dist/cli/runtime/message-router-config.js.map +0 -1
  921. package/dist/cli/runtime/metrics-init.d.ts +0 -28
  922. package/dist/cli/runtime/metrics-init.d.ts.map +0 -1
  923. package/dist/cli/runtime/metrics-init.js +0 -131
  924. package/dist/cli/runtime/metrics-init.js.map +0 -1
  925. package/dist/cli/runtime/owner-backfill.d.ts +0 -24
  926. package/dist/cli/runtime/owner-backfill.d.ts.map +0 -1
  927. package/dist/cli/runtime/owner-backfill.js +0 -24
  928. package/dist/cli/runtime/owner-backfill.js.map +0 -1
  929. package/dist/cli/runtime/scheduler-init.d.ts +0 -60
  930. package/dist/cli/runtime/scheduler-init.d.ts.map +0 -1
  931. package/dist/cli/runtime/scheduler-init.js +0 -173
  932. package/dist/cli/runtime/scheduler-init.js.map +0 -1
  933. package/dist/cli/runtime/server-start.d.ts +0 -23
  934. package/dist/cli/runtime/server-start.d.ts.map +0 -1
  935. package/dist/cli/runtime/server-start.js +0 -174
  936. package/dist/cli/runtime/server-start.js.map +0 -1
  937. package/dist/cli/runtime/shutdown.d.ts +0 -46
  938. package/dist/cli/runtime/shutdown.d.ts.map +0 -1
  939. package/dist/cli/runtime/shutdown.js +0 -240
  940. package/dist/cli/runtime/shutdown.js.map +0 -1
  941. package/dist/cli/runtime/temporal-init.d.ts +0 -26
  942. package/dist/cli/runtime/temporal-init.d.ts.map +0 -1
  943. package/dist/cli/runtime/temporal-init.js +0 -57
  944. package/dist/cli/runtime/temporal-init.js.map +0 -1
  945. package/dist/cli/runtime/types.d.ts +0 -127
  946. package/dist/cli/runtime/types.d.ts.map +0 -1
  947. package/dist/cli/runtime/types.js +0 -12
  948. package/dist/cli/runtime/types.js.map +0 -1
  949. package/dist/cli/runtime/utilities.d.ts +0 -72
  950. package/dist/cli/runtime/utilities.d.ts.map +0 -1
  951. package/dist/cli/runtime/utilities.js +0 -472
  952. package/dist/cli/runtime/utilities.js.map +0 -1
  953. package/dist/cli/shutdown-utils.d.ts +0 -6
  954. package/dist/cli/shutdown-utils.d.ts.map +0 -1
  955. package/dist/cli/shutdown-utils.js +0 -11
  956. package/dist/cli/shutdown-utils.js.map +0 -1
  957. package/dist/cli/utils/pid-manager.d.ts +0 -56
  958. package/dist/cli/utils/pid-manager.d.ts.map +0 -1
  959. package/dist/cli/utils/pid-manager.js +0 -141
  960. package/dist/cli/utils/pid-manager.js.map +0 -1
  961. package/dist/concurrency/index.d.ts +0 -13
  962. package/dist/concurrency/index.d.ts.map +0 -1
  963. package/dist/concurrency/index.js +0 -22
  964. package/dist/concurrency/index.js.map +0 -1
  965. package/dist/concurrency/lane-manager.d.ts +0 -113
  966. package/dist/concurrency/lane-manager.d.ts.map +0 -1
  967. package/dist/concurrency/lane-manager.js +0 -248
  968. package/dist/concurrency/lane-manager.js.map +0 -1
  969. package/dist/concurrency/session-key.d.ts +0 -41
  970. package/dist/concurrency/session-key.d.ts.map +0 -1
  971. package/dist/concurrency/session-key.js +0 -61
  972. package/dist/concurrency/session-key.js.map +0 -1
  973. package/dist/concurrency/types.d.ts +0 -73
  974. package/dist/concurrency/types.d.ts.map +0 -1
  975. package/dist/concurrency/types.js +0 -16
  976. package/dist/concurrency/types.js.map +0 -1
  977. package/dist/connectors/framework/raw-store.d.ts +0 -63
  978. package/dist/connectors/framework/raw-store.d.ts.map +0 -1
  979. package/dist/connectors/framework/raw-store.js +0 -356
  980. package/dist/connectors/framework/raw-store.js.map +0 -1
  981. package/dist/connectors/kagemusha/query-tools.d.ts +0 -146
  982. package/dist/connectors/kagemusha/query-tools.d.ts.map +0 -1
  983. package/dist/connectors/kagemusha/query-tools.js +0 -467
  984. package/dist/connectors/kagemusha/query-tools.js.map +0 -1
  985. package/dist/connectors/private-connector-policy.d.ts +0 -174
  986. package/dist/connectors/private-connector-policy.d.ts.map +0 -1
  987. package/dist/connectors/private-connector-policy.js +0 -299
  988. package/dist/connectors/private-connector-policy.js.map +0 -1
  989. package/dist/connectors/private-prompt-overlay.d.ts +0 -17
  990. package/dist/connectors/private-prompt-overlay.d.ts.map +0 -1
  991. package/dist/connectors/private-prompt-overlay.js +0 -156
  992. package/dist/connectors/private-prompt-overlay.js.map +0 -1
  993. package/dist/connectors/trello/query-tools.d.ts +0 -243
  994. package/dist/connectors/trello/query-tools.d.ts.map +0 -1
  995. package/dist/connectors/trello/query-tools.js +0 -661
  996. package/dist/connectors/trello/query-tools.js.map +0 -1
  997. package/dist/db/agent-store.d.ts +0 -145
  998. package/dist/db/agent-store.d.ts.map +0 -1
  999. package/dist/db/agent-store.js +0 -279
  1000. package/dist/db/agent-store.js.map +0 -1
  1001. package/dist/db/migrations/agent-activity-envelope-hash.d.ts +0 -3
  1002. package/dist/db/migrations/agent-activity-envelope-hash.d.ts.map +0 -1
  1003. package/dist/db/migrations/agent-activity-envelope-hash.js +0 -29
  1004. package/dist/db/migrations/agent-activity-envelope-hash.js.map +0 -1
  1005. package/dist/db/migrations/agent-activity-gateway-call-id.d.ts +0 -3
  1006. package/dist/db/migrations/agent-activity-gateway-call-id.d.ts.map +0 -1
  1007. package/dist/db/migrations/agent-activity-gateway-call-id.js +0 -17
  1008. package/dist/db/migrations/agent-activity-gateway-call-id.js.map +0 -1
  1009. package/dist/db/migrations/agent-activity-tool-name.d.ts +0 -8
  1010. package/dist/db/migrations/agent-activity-tool-name.d.ts.map +0 -1
  1011. package/dist/db/migrations/agent-activity-tool-name.js +0 -24
  1012. package/dist/db/migrations/agent-activity-tool-name.js.map +0 -1
  1013. package/dist/db/migrations/agent-activity-validation-columns.d.ts +0 -3
  1014. package/dist/db/migrations/agent-activity-validation-columns.d.ts.map +0 -1
  1015. package/dist/db/migrations/agent-activity-validation-columns.js +0 -22
  1016. package/dist/db/migrations/agent-activity-validation-columns.js.map +0 -1
  1017. package/dist/db/migrations/agent-metrics-response-avg.d.ts +0 -3
  1018. package/dist/db/migrations/agent-metrics-response-avg.d.ts.map +0 -1
  1019. package/dist/db/migrations/agent-metrics-response-avg.js +0 -19
  1020. package/dist/db/migrations/agent-metrics-response-avg.js.map +0 -1
  1021. package/dist/db/migrations/agent-store-tables.d.ts +0 -3
  1022. package/dist/db/migrations/agent-store-tables.d.ts.map +0 -1
  1023. package/dist/db/migrations/agent-store-tables.js +0 -64
  1024. package/dist/db/migrations/agent-store-tables.js.map +0 -1
  1025. package/dist/db/migrations/envelope-tables.d.ts +0 -3
  1026. package/dist/db/migrations/envelope-tables.d.ts.map +0 -1
  1027. package/dist/db/migrations/envelope-tables.js +0 -38
  1028. package/dist/db/migrations/envelope-tables.js.map +0 -1
  1029. package/dist/db/migrations/operator-owner-action-candidates.d.ts +0 -19
  1030. package/dist/db/migrations/operator-owner-action-candidates.d.ts.map +0 -1
  1031. package/dist/db/migrations/operator-owner-action-candidates.js +0 -254
  1032. package/dist/db/migrations/operator-owner-action-candidates.js.map +0 -1
  1033. package/dist/db/migrations/operator-procedures.d.ts +0 -4
  1034. package/dist/db/migrations/operator-procedures.d.ts.map +0 -1
  1035. package/dist/db/migrations/operator-procedures.js +0 -63
  1036. package/dist/db/migrations/operator-procedures.js.map +0 -1
  1037. package/dist/db/migrations/operator-task-classification.d.ts +0 -15
  1038. package/dist/db/migrations/operator-task-classification.d.ts.map +0 -1
  1039. package/dist/db/migrations/operator-task-classification.js +0 -25
  1040. package/dist/db/migrations/operator-task-classification.js.map +0 -1
  1041. package/dist/db/migrations/operator-task-external-lifecycle.d.ts +0 -17
  1042. package/dist/db/migrations/operator-task-external-lifecycle.d.ts.map +0 -1
  1043. package/dist/db/migrations/operator-task-external-lifecycle.js +0 -199
  1044. package/dist/db/migrations/operator-task-external-lifecycle.js.map +0 -1
  1045. package/dist/db/migrations/operator-task-review-lifecycle.d.ts +0 -4
  1046. package/dist/db/migrations/operator-task-review-lifecycle.d.ts.map +0 -1
  1047. package/dist/db/migrations/operator-task-review-lifecycle.js +0 -17
  1048. package/dist/db/migrations/operator-task-review-lifecycle.js.map +0 -1
  1049. package/dist/db/migrations/operator-task-temporal.d.ts +0 -8
  1050. package/dist/db/migrations/operator-task-temporal.d.ts.map +0 -1
  1051. package/dist/db/migrations/operator-task-temporal.js +0 -214
  1052. package/dist/db/migrations/operator-task-temporal.js.map +0 -1
  1053. package/dist/db/migrations/owner-action-effects.d.ts +0 -18
  1054. package/dist/db/migrations/owner-action-effects.d.ts.map +0 -1
  1055. package/dist/db/migrations/owner-action-effects.js +0 -111
  1056. package/dist/db/migrations/owner-action-effects.js.map +0 -1
  1057. package/dist/db/migrations/raw-item-revisions.d.ts +0 -4
  1058. package/dist/db/migrations/raw-item-revisions.d.ts.map +0 -1
  1059. package/dist/db/migrations/raw-item-revisions.js +0 -29
  1060. package/dist/db/migrations/raw-item-revisions.js.map +0 -1
  1061. package/dist/db/migrations/token-usage-agent-version.d.ts +0 -3
  1062. package/dist/db/migrations/token-usage-agent-version.d.ts.map +0 -1
  1063. package/dist/db/migrations/token-usage-agent-version.js +0 -16
  1064. package/dist/db/migrations/token-usage-agent-version.js.map +0 -1
  1065. package/dist/db/migrations/validation-session-tables.d.ts +0 -3
  1066. package/dist/db/migrations/validation-session-tables.d.ts.map +0 -1
  1067. package/dist/db/migrations/validation-session-tables.js +0 -59
  1068. package/dist/db/migrations/validation-session-tables.js.map +0 -1
  1069. package/dist/envelope/authority.d.ts +0 -15
  1070. package/dist/envelope/authority.d.ts.map +0 -1
  1071. package/dist/envelope/authority.js +0 -95
  1072. package/dist/envelope/authority.js.map +0 -1
  1073. package/dist/envelope/canonical.d.ts +0 -14
  1074. package/dist/envelope/canonical.d.ts.map +0 -1
  1075. package/dist/envelope/canonical.js +0 -68
  1076. package/dist/envelope/canonical.js.map +0 -1
  1077. package/dist/envelope/enforcer.d.ts +0 -30
  1078. package/dist/envelope/enforcer.d.ts.map +0 -1
  1079. package/dist/envelope/enforcer.js +0 -286
  1080. package/dist/envelope/enforcer.js.map +0 -1
  1081. package/dist/envelope/expiry.d.ts +0 -2
  1082. package/dist/envelope/expiry.d.ts.map +0 -1
  1083. package/dist/envelope/expiry.js +0 -15
  1084. package/dist/envelope/expiry.js.map +0 -1
  1085. package/dist/envelope/index.d.ts +0 -9
  1086. package/dist/envelope/index.d.ts.map +0 -1
  1087. package/dist/envelope/index.js +0 -25
  1088. package/dist/envelope/index.js.map +0 -1
  1089. package/dist/envelope/key-provider.d.ts +0 -7
  1090. package/dist/envelope/key-provider.d.ts.map +0 -1
  1091. package/dist/envelope/key-provider.js +0 -137
  1092. package/dist/envelope/key-provider.js.map +0 -1
  1093. package/dist/envelope/reactive-config.d.ts +0 -24
  1094. package/dist/envelope/reactive-config.d.ts.map +0 -1
  1095. package/dist/envelope/reactive-config.js +0 -198
  1096. package/dist/envelope/reactive-config.js.map +0 -1
  1097. package/dist/envelope/run-guard.d.ts +0 -10
  1098. package/dist/envelope/run-guard.d.ts.map +0 -1
  1099. package/dist/envelope/run-guard.js +0 -19
  1100. package/dist/envelope/run-guard.js.map +0 -1
  1101. package/dist/envelope/signature.d.ts +0 -15
  1102. package/dist/envelope/signature.d.ts.map +0 -1
  1103. package/dist/envelope/signature.js +0 -75
  1104. package/dist/envelope/signature.js.map +0 -1
  1105. package/dist/envelope/store.d.ts +0 -16
  1106. package/dist/envelope/store.d.ts.map +0 -1
  1107. package/dist/envelope/store.js +0 -118
  1108. package/dist/envelope/store.js.map +0 -1
  1109. package/dist/envelope/tool-connector-scope.d.ts +0 -35
  1110. package/dist/envelope/tool-connector-scope.d.ts.map +0 -1
  1111. package/dist/envelope/tool-connector-scope.js +0 -61
  1112. package/dist/envelope/tool-connector-scope.js.map +0 -1
  1113. package/dist/envelope/types.d.ts +0 -60
  1114. package/dist/envelope/types.d.ts.map +0 -1
  1115. package/dist/envelope/types.js +0 -9
  1116. package/dist/envelope/types.js.map +0 -1
  1117. package/dist/evidence/effects.d.ts +0 -125
  1118. package/dist/evidence/effects.d.ts.map +0 -1
  1119. package/dist/evidence/effects.js +0 -409
  1120. package/dist/evidence/effects.js.map +0 -1
  1121. package/dist/evidence/read.d.ts +0 -130
  1122. package/dist/evidence/read.d.ts.map +0 -1
  1123. package/dist/evidence/read.js +0 -167
  1124. package/dist/evidence/read.js.map +0 -1
  1125. package/dist/gateways/attachment-utils.d.ts +0 -28
  1126. package/dist/gateways/attachment-utils.d.ts.map +0 -1
  1127. package/dist/gateways/attachment-utils.js +0 -489
  1128. package/dist/gateways/attachment-utils.js.map +0 -1
  1129. package/dist/gateways/channel-history.d.ts +0 -148
  1130. package/dist/gateways/channel-history.d.ts.map +0 -1
  1131. package/dist/gateways/channel-history.js +0 -385
  1132. package/dist/gateways/channel-history.js.map +0 -1
  1133. package/dist/gateways/context-injector.d.ts +0 -255
  1134. package/dist/gateways/context-injector.d.ts.map +0 -1
  1135. package/dist/gateways/context-injector.js +0 -285
  1136. package/dist/gateways/context-injector.js.map +0 -1
  1137. package/dist/gateways/image-analyzer.d.ts +0 -28
  1138. package/dist/gateways/image-analyzer.d.ts.map +0 -1
  1139. package/dist/gateways/image-analyzer.js +0 -154
  1140. package/dist/gateways/image-analyzer.js.map +0 -1
  1141. package/dist/gateways/index.d.ts +0 -35
  1142. package/dist/gateways/index.d.ts.map +0 -1
  1143. package/dist/gateways/index.js +0 -55
  1144. package/dist/gateways/index.js.map +0 -1
  1145. package/dist/gateways/member-candidate-store.d.ts +0 -26
  1146. package/dist/gateways/member-candidate-store.d.ts.map +0 -1
  1147. package/dist/gateways/member-candidate-store.js +0 -90
  1148. package/dist/gateways/member-candidate-store.js.map +0 -1
  1149. package/dist/gateways/member-effective-scope.d.ts +0 -25
  1150. package/dist/gateways/member-effective-scope.d.ts.map +0 -1
  1151. package/dist/gateways/member-effective-scope.js +0 -323
  1152. package/dist/gateways/member-effective-scope.js.map +0 -1
  1153. package/dist/gateways/message-router.d.ts +0 -239
  1154. package/dist/gateways/message-router.d.ts.map +0 -1
  1155. package/dist/gateways/message-router.js +0 -1714
  1156. package/dist/gateways/message-router.js.map +0 -1
  1157. package/dist/gateways/plugin-loader.d.ts +0 -80
  1158. package/dist/gateways/plugin-loader.d.ts.map +0 -1
  1159. package/dist/gateways/plugin-loader.js +0 -299
  1160. package/dist/gateways/plugin-loader.js.map +0 -1
  1161. package/dist/gateways/principal.d.ts +0 -37
  1162. package/dist/gateways/principal.d.ts.map +0 -1
  1163. package/dist/gateways/principal.js +0 -95
  1164. package/dist/gateways/principal.js.map +0 -1
  1165. package/dist/gateways/report-projection-v1.d.ts +0 -41
  1166. package/dist/gateways/report-projection-v1.d.ts.map +0 -1
  1167. package/dist/gateways/report-projection-v1.js +0 -160
  1168. package/dist/gateways/report-projection-v1.js.map +0 -1
  1169. package/dist/gateways/telegram-media.d.ts +0 -41
  1170. package/dist/gateways/telegram-media.d.ts.map +0 -1
  1171. package/dist/gateways/telegram-media.js +0 -242
  1172. package/dist/gateways/telegram-media.js.map +0 -1
  1173. package/dist/gateways/telegram-report-context-store.d.ts +0 -131
  1174. package/dist/gateways/telegram-report-context-store.d.ts.map +0 -1
  1175. package/dist/gateways/telegram-report-context-store.js +0 -388
  1176. package/dist/gateways/telegram-report-context-store.js.map +0 -1
  1177. package/dist/gateways/tool-status-tracker.d.ts +0 -87
  1178. package/dist/gateways/tool-status-tracker.d.ts.map +0 -1
  1179. package/dist/gateways/tool-status-tracker.js +0 -284
  1180. package/dist/gateways/tool-status-tracker.js.map +0 -1
  1181. package/dist/mcp/code-act-api-client.d.ts +0 -32
  1182. package/dist/mcp/code-act-api-client.d.ts.map +0 -1
  1183. package/dist/mcp/code-act-api-client.js +0 -80
  1184. package/dist/mcp/code-act-api-client.js.map +0 -1
  1185. package/dist/mcp/code-act-mcp-config.d.ts +0 -49
  1186. package/dist/mcp/code-act-mcp-config.d.ts.map +0 -1
  1187. package/dist/mcp/code-act-mcp-config.js +0 -124
  1188. package/dist/mcp/code-act-mcp-config.js.map +0 -1
  1189. package/dist/mcp/code-act-server.d.ts +0 -14
  1190. package/dist/mcp/code-act-server.d.ts.map +0 -1
  1191. package/dist/mcp/code-act-server.js +0 -204
  1192. package/dist/mcp/code-act-server.js.map +0 -1
  1193. package/dist/mcp/code-act-terminal-transport.d.ts +0 -64
  1194. package/dist/mcp/code-act-terminal-transport.d.ts.map +0 -1
  1195. package/dist/mcp/code-act-terminal-transport.js +0 -176
  1196. package/dist/mcp/code-act-terminal-transport.js.map +0 -1
  1197. package/dist/memory/agent-notice-queue.d.ts +0 -24
  1198. package/dist/memory/agent-notice-queue.d.ts.map +0 -1
  1199. package/dist/memory/agent-notice-queue.js +0 -40
  1200. package/dist/memory/agent-notice-queue.js.map +0 -1
  1201. package/dist/memory/audit-task-queue.d.ts +0 -28
  1202. package/dist/memory/audit-task-queue.d.ts.map +0 -1
  1203. package/dist/memory/audit-task-queue.js +0 -29
  1204. package/dist/memory/audit-task-queue.js.map +0 -1
  1205. package/dist/memory/bootstrap-context.d.ts +0 -12
  1206. package/dist/memory/bootstrap-context.d.ts.map +0 -1
  1207. package/dist/memory/bootstrap-context.js +0 -68
  1208. package/dist/memory/bootstrap-context.js.map +0 -1
  1209. package/dist/memory/history-extractor.d.ts +0 -69
  1210. package/dist/memory/history-extractor.d.ts.map +0 -1
  1211. package/dist/memory/history-extractor.js +0 -210
  1212. package/dist/memory/history-extractor.js.map +0 -1
  1213. package/dist/memory/memory-agent-ack.d.ts +0 -4
  1214. package/dist/memory/memory-agent-ack.d.ts.map +0 -1
  1215. package/dist/memory/memory-agent-ack.js +0 -54
  1216. package/dist/memory/memory-agent-ack.js.map +0 -1
  1217. package/dist/memory/memory-agent-dashboard.d.ts +0 -35
  1218. package/dist/memory/memory-agent-dashboard.d.ts.map +0 -1
  1219. package/dist/memory/memory-agent-dashboard.js +0 -116
  1220. package/dist/memory/memory-agent-dashboard.js.map +0 -1
  1221. package/dist/memory/memory-logger.d.ts +0 -47
  1222. package/dist/memory/memory-logger.d.ts.map +0 -1
  1223. package/dist/memory/memory-logger.js +0 -126
  1224. package/dist/memory/memory-logger.js.map +0 -1
  1225. package/dist/memory/provenance-live.d.ts +0 -111
  1226. package/dist/memory/provenance-live.d.ts.map +0 -1
  1227. package/dist/memory/provenance-live.js +0 -381
  1228. package/dist/memory/provenance-live.js.map +0 -1
  1229. package/dist/memory/provenance-resolver.d.ts +0 -184
  1230. package/dist/memory/provenance-resolver.d.ts.map +0 -1
  1231. package/dist/memory/provenance-resolver.js +0 -152
  1232. package/dist/memory/provenance-resolver.js.map +0 -1
  1233. package/dist/memory/raw-backed-memory-ingest.d.ts +0 -26
  1234. package/dist/memory/raw-backed-memory-ingest.d.ts.map +0 -1
  1235. package/dist/memory/raw-backed-memory-ingest.js +0 -214
  1236. package/dist/memory/raw-backed-memory-ingest.js.map +0 -1
  1237. package/dist/memory/recall-bundle-formatter.d.ts +0 -26
  1238. package/dist/memory/recall-bundle-formatter.d.ts.map +0 -1
  1239. package/dist/memory/recall-bundle-formatter.js +0 -53
  1240. package/dist/memory/recall-bundle-formatter.js.map +0 -1
  1241. package/dist/memory/save-candidate-extractor.d.ts +0 -16
  1242. package/dist/memory/save-candidate-extractor.d.ts.map +0 -1
  1243. package/dist/memory/save-candidate-extractor.js +0 -127
  1244. package/dist/memory/save-candidate-extractor.js.map +0 -1
  1245. package/dist/memory/save-candidate-types.d.ts +0 -16
  1246. package/dist/memory/save-candidate-types.d.ts.map +0 -1
  1247. package/dist/memory/save-candidate-types.js +0 -3
  1248. package/dist/memory/save-candidate-types.js.map +0 -1
  1249. package/dist/memory/scope-context.d.ts +0 -12
  1250. package/dist/memory/scope-context.d.ts.map +0 -1
  1251. package/dist/memory/scope-context.js +0 -18
  1252. package/dist/memory/scope-context.js.map +0 -1
  1253. package/dist/memory/secret-filter.d.ts +0 -23
  1254. package/dist/memory/secret-filter.d.ts.map +0 -1
  1255. package/dist/memory/secret-filter.js +0 -90
  1256. package/dist/memory/secret-filter.js.map +0 -1
  1257. package/dist/multi-agent/agent-event-bus.d.ts +0 -50
  1258. package/dist/multi-agent/agent-event-bus.d.ts.map +0 -1
  1259. package/dist/multi-agent/agent-event-bus.js +0 -101
  1260. package/dist/multi-agent/agent-event-bus.js.map +0 -1
  1261. package/dist/multi-agent/agent-process-manager.d.ts +0 -205
  1262. package/dist/multi-agent/agent-process-manager.d.ts.map +0 -1
  1263. package/dist/multi-agent/agent-process-manager.js +0 -1191
  1264. package/dist/multi-agent/agent-process-manager.js.map +0 -1
  1265. package/dist/multi-agent/bmad-templates.d.ts +0 -49
  1266. package/dist/multi-agent/bmad-templates.d.ts.map +0 -1
  1267. package/dist/multi-agent/bmad-templates.js +0 -121
  1268. package/dist/multi-agent/bmad-templates.js.map +0 -1
  1269. package/dist/multi-agent/runtime-process.d.ts +0 -74
  1270. package/dist/multi-agent/runtime-process.d.ts.map +0 -1
  1271. package/dist/multi-agent/runtime-process.js +0 -160
  1272. package/dist/multi-agent/runtime-process.js.map +0 -1
  1273. package/dist/multi-agent/tool-permission-manager.d.ts +0 -70
  1274. package/dist/multi-agent/tool-permission-manager.d.ts.map +0 -1
  1275. package/dist/multi-agent/tool-permission-manager.js +0 -195
  1276. package/dist/multi-agent/tool-permission-manager.js.map +0 -1
  1277. package/dist/multi-agent/types.d.ts +0 -438
  1278. package/dist/multi-agent/types.d.ts.map +0 -1
  1279. package/dist/multi-agent/types.js +0 -27
  1280. package/dist/multi-agent/types.js.map +0 -1
  1281. package/dist/multi-agent/wiki-agent-persona.d.ts +0 -16
  1282. package/dist/multi-agent/wiki-agent-persona.d.ts.map +0 -1
  1283. package/dist/multi-agent/wiki-agent-persona.js +0 -23
  1284. package/dist/multi-agent/wiki-agent-persona.js.map +0 -1
  1285. package/dist/multi-agent/workflow-types.d.ts +0 -186
  1286. package/dist/multi-agent/workflow-types.d.ts.map +0 -1
  1287. package/dist/multi-agent/workflow-types.js +0 -9
  1288. package/dist/multi-agent/workflow-types.js.map +0 -1
  1289. package/dist/observability/code-audit.d.ts +0 -87
  1290. package/dist/observability/code-audit.d.ts.map +0 -1
  1291. package/dist/observability/code-audit.js +0 -414
  1292. package/dist/observability/code-audit.js.map +0 -1
  1293. package/dist/observability/health-check.d.ts +0 -102
  1294. package/dist/observability/health-check.d.ts.map +0 -1
  1295. package/dist/observability/health-check.js +0 -422
  1296. package/dist/observability/health-check.js.map +0 -1
  1297. package/dist/observability/health-score.d.ts +0 -29
  1298. package/dist/observability/health-score.d.ts.map +0 -1
  1299. package/dist/observability/health-score.js +0 -83
  1300. package/dist/observability/health-score.js.map +0 -1
  1301. package/dist/observability/metrics-cleanup.d.ts +0 -24
  1302. package/dist/observability/metrics-cleanup.d.ts.map +0 -1
  1303. package/dist/observability/metrics-cleanup.js +0 -51
  1304. package/dist/observability/metrics-cleanup.js.map +0 -1
  1305. package/dist/observability/metrics-store.d.ts +0 -52
  1306. package/dist/observability/metrics-store.d.ts.map +0 -1
  1307. package/dist/observability/metrics-store.js +0 -186
  1308. package/dist/observability/metrics-store.js.map +0 -1
  1309. package/dist/observability/operational-issues.d.ts +0 -55
  1310. package/dist/observability/operational-issues.d.ts.map +0 -1
  1311. package/dist/observability/operational-issues.js +0 -170
  1312. package/dist/observability/operational-issues.js.map +0 -1
  1313. package/dist/onboarding/agent-contract.d.ts +0 -42
  1314. package/dist/onboarding/agent-contract.d.ts.map +0 -1
  1315. package/dist/onboarding/agent-contract.js +0 -129
  1316. package/dist/onboarding/agent-contract.js.map +0 -1
  1317. package/dist/onboarding/assess-live.d.ts +0 -22
  1318. package/dist/onboarding/assess-live.d.ts.map +0 -1
  1319. package/dist/onboarding/assess-live.js +0 -200
  1320. package/dist/onboarding/assess-live.js.map +0 -1
  1321. package/dist/onboarding/bootstrap-template.d.ts +0 -5
  1322. package/dist/onboarding/bootstrap-template.d.ts.map +0 -1
  1323. package/dist/onboarding/bootstrap-template.js +0 -34
  1324. package/dist/onboarding/bootstrap-template.js.map +0 -1
  1325. package/dist/operator/action-verifier.d.ts +0 -75
  1326. package/dist/operator/action-verifier.d.ts.map +0 -1
  1327. package/dist/operator/action-verifier.js +0 -149
  1328. package/dist/operator/action-verifier.js.map +0 -1
  1329. package/dist/operator/board-delta-gate.d.ts +0 -131
  1330. package/dist/operator/board-delta-gate.d.ts.map +0 -1
  1331. package/dist/operator/board-delta-gate.js +0 -181
  1332. package/dist/operator/board-delta-gate.js.map +0 -1
  1333. package/dist/operator/board-pipeline-render.d.ts +0 -16
  1334. package/dist/operator/board-pipeline-render.d.ts.map +0 -1
  1335. package/dist/operator/board-pipeline-render.js +0 -69
  1336. package/dist/operator/board-pipeline-render.js.map +0 -1
  1337. package/dist/operator/board-reconcile.d.ts +0 -61
  1338. package/dist/operator/board-reconcile.d.ts.map +0 -1
  1339. package/dist/operator/board-reconcile.js +0 -157
  1340. package/dist/operator/board-reconcile.js.map +0 -1
  1341. package/dist/operator/board-refresh-gate.d.ts +0 -39
  1342. package/dist/operator/board-refresh-gate.d.ts.map +0 -1
  1343. package/dist/operator/board-refresh-gate.js +0 -83
  1344. package/dist/operator/board-refresh-gate.js.map +0 -1
  1345. package/dist/operator/changes-projection.d.ts +0 -72
  1346. package/dist/operator/changes-projection.d.ts.map +0 -1
  1347. package/dist/operator/changes-projection.js +0 -110
  1348. package/dist/operator/changes-projection.js.map +0 -1
  1349. package/dist/operator/connector-delta-repo.d.ts +0 -33
  1350. package/dist/operator/connector-delta-repo.d.ts.map +0 -1
  1351. package/dist/operator/connector-delta-repo.js +0 -0
  1352. package/dist/operator/connector-delta-repo.js.map +0 -1
  1353. package/dist/operator/console-brief.d.ts +0 -40
  1354. package/dist/operator/console-brief.d.ts.map +0 -1
  1355. package/dist/operator/console-brief.js +0 -246
  1356. package/dist/operator/console-brief.js.map +0 -1
  1357. package/dist/operator/experience-evidence.d.ts +0 -18
  1358. package/dist/operator/experience-evidence.d.ts.map +0 -1
  1359. package/dist/operator/experience-evidence.js +0 -82
  1360. package/dist/operator/experience-evidence.js.map +0 -1
  1361. package/dist/operator/experience-hints.d.ts +0 -44
  1362. package/dist/operator/experience-hints.d.ts.map +0 -1
  1363. package/dist/operator/experience-hints.js +0 -98
  1364. package/dist/operator/experience-hints.js.map +0 -1
  1365. package/dist/operator/external-correlation.d.ts +0 -94
  1366. package/dist/operator/external-correlation.d.ts.map +0 -1
  1367. package/dist/operator/external-correlation.js +0 -177
  1368. package/dist/operator/external-correlation.js.map +0 -1
  1369. package/dist/operator/external-lifecycle-candidates.d.ts +0 -70
  1370. package/dist/operator/external-lifecycle-candidates.d.ts.map +0 -1
  1371. package/dist/operator/external-lifecycle-candidates.js +0 -579
  1372. package/dist/operator/external-lifecycle-candidates.js.map +0 -1
  1373. package/dist/operator/external-lifecycle-discovery.d.ts +0 -61
  1374. package/dist/operator/external-lifecycle-discovery.d.ts.map +0 -1
  1375. package/dist/operator/external-lifecycle-discovery.js +0 -103
  1376. package/dist/operator/external-lifecycle-discovery.js.map +0 -1
  1377. package/dist/operator/external-lifecycle.d.ts +0 -105
  1378. package/dist/operator/external-lifecycle.d.ts.map +0 -1
  1379. package/dist/operator/external-lifecycle.js +0 -27
  1380. package/dist/operator/external-lifecycle.js.map +0 -1
  1381. package/dist/operator/file-coordination.d.ts +0 -7
  1382. package/dist/operator/file-coordination.d.ts.map +0 -1
  1383. package/dist/operator/file-coordination.js +0 -84
  1384. package/dist/operator/file-coordination.js.map +0 -1
  1385. package/dist/operator/file-export.d.ts +0 -22
  1386. package/dist/operator/file-export.d.ts.map +0 -1
  1387. package/dist/operator/file-export.js +0 -115
  1388. package/dist/operator/file-export.js.map +0 -1
  1389. package/dist/operator/leg-cadence.d.ts +0 -72
  1390. package/dist/operator/leg-cadence.d.ts.map +0 -1
  1391. package/dist/operator/leg-cadence.js +0 -122
  1392. package/dist/operator/leg-cadence.js.map +0 -1
  1393. package/dist/operator/mama-memory-port.d.ts +0 -13
  1394. package/dist/operator/mama-memory-port.d.ts.map +0 -1
  1395. package/dist/operator/mama-memory-port.js +0 -33
  1396. package/dist/operator/mama-memory-port.js.map +0 -1
  1397. package/dist/operator/operator-interfaces.d.ts +0 -136
  1398. package/dist/operator/operator-interfaces.d.ts.map +0 -1
  1399. package/dist/operator/operator-interfaces.js +0 -15
  1400. package/dist/operator/operator-interfaces.js.map +0 -1
  1401. package/dist/operator/operator-trigger-loop.d.ts +0 -203
  1402. package/dist/operator/operator-trigger-loop.d.ts.map +0 -1
  1403. package/dist/operator/operator-trigger-loop.js +0 -827
  1404. package/dist/operator/operator-trigger-loop.js.map +0 -1
  1405. package/dist/operator/owner-action-effects.d.ts +0 -112
  1406. package/dist/operator/owner-action-effects.d.ts.map +0 -1
  1407. package/dist/operator/owner-action-effects.js +0 -375
  1408. package/dist/operator/owner-action-effects.js.map +0 -1
  1409. package/dist/operator/owner-event-effects.d.ts +0 -65
  1410. package/dist/operator/owner-event-effects.d.ts.map +0 -1
  1411. package/dist/operator/owner-event-effects.js +0 -249
  1412. package/dist/operator/owner-event-effects.js.map +0 -1
  1413. package/dist/operator/owner-event-inbox.d.ts +0 -124
  1414. package/dist/operator/owner-event-inbox.d.ts.map +0 -1
  1415. package/dist/operator/owner-event-inbox.js +0 -440
  1416. package/dist/operator/owner-event-inbox.js.map +0 -1
  1417. package/dist/operator/owner-event-loop.d.ts +0 -99
  1418. package/dist/operator/owner-event-loop.d.ts.map +0 -1
  1419. package/dist/operator/owner-event-loop.js +0 -253
  1420. package/dist/operator/owner-event-loop.js.map +0 -1
  1421. package/dist/operator/owner-event-outcome.d.ts +0 -36
  1422. package/dist/operator/owner-event-outcome.d.ts.map +0 -1
  1423. package/dist/operator/owner-event-outcome.js +0 -174
  1424. package/dist/operator/owner-event-outcome.js.map +0 -1
  1425. package/dist/operator/owner-event-policy.d.ts +0 -40
  1426. package/dist/operator/owner-event-policy.d.ts.map +0 -1
  1427. package/dist/operator/owner-event-policy.js +0 -75
  1428. package/dist/operator/owner-event-policy.js.map +0 -1
  1429. package/dist/operator/owner-event-prompt.d.ts +0 -21
  1430. package/dist/operator/owner-event-prompt.d.ts.map +0 -1
  1431. package/dist/operator/owner-event-prompt.js +0 -69
  1432. package/dist/operator/owner-event-prompt.js.map +0 -1
  1433. package/dist/operator/owner-runtime-journal.d.ts +0 -21
  1434. package/dist/operator/owner-runtime-journal.d.ts.map +0 -1
  1435. package/dist/operator/owner-runtime-journal.js +0 -135
  1436. package/dist/operator/owner-runtime-journal.js.map +0 -1
  1437. package/dist/operator/owner-runtime.d.ts +0 -48
  1438. package/dist/operator/owner-runtime.d.ts.map +0 -1
  1439. package/dist/operator/owner-runtime.js +0 -99
  1440. package/dist/operator/owner-runtime.js.map +0 -1
  1441. package/dist/operator/pending-report-store.d.ts +0 -99
  1442. package/dist/operator/pending-report-store.d.ts.map +0 -1
  1443. package/dist/operator/pending-report-store.js +0 -554
  1444. package/dist/operator/pending-report-store.js.map +0 -1
  1445. package/dist/operator/procedure-activation.d.ts +0 -7
  1446. package/dist/operator/procedure-activation.d.ts.map +0 -1
  1447. package/dist/operator/procedure-activation.js +0 -132
  1448. package/dist/operator/procedure-activation.js.map +0 -1
  1449. package/dist/operator/procedure-projection.d.ts +0 -25
  1450. package/dist/operator/procedure-projection.d.ts.map +0 -1
  1451. package/dist/operator/procedure-projection.js +0 -80
  1452. package/dist/operator/procedure-projection.js.map +0 -1
  1453. package/dist/operator/procedure-runtime.d.ts +0 -45
  1454. package/dist/operator/procedure-runtime.d.ts.map +0 -1
  1455. package/dist/operator/procedure-runtime.js +0 -496
  1456. package/dist/operator/procedure-runtime.js.map +0 -1
  1457. package/dist/operator/procedure-store.d.ts +0 -97
  1458. package/dist/operator/procedure-store.d.ts.map +0 -1
  1459. package/dist/operator/procedure-store.js +0 -368
  1460. package/dist/operator/procedure-store.js.map +0 -1
  1461. package/dist/operator/provenance-lookup.d.ts +0 -18
  1462. package/dist/operator/provenance-lookup.d.ts.map +0 -1
  1463. package/dist/operator/provenance-lookup.js +0 -54
  1464. package/dist/operator/provenance-lookup.js.map +0 -1
  1465. package/dist/operator/repair-request.d.ts +0 -29
  1466. package/dist/operator/repair-request.d.ts.map +0 -1
  1467. package/dist/operator/repair-request.js +0 -115
  1468. package/dist/operator/repair-request.js.map +0 -1
  1469. package/dist/operator/report-carry-delivery.d.ts +0 -35
  1470. package/dist/operator/report-carry-delivery.d.ts.map +0 -1
  1471. package/dist/operator/report-carry-delivery.js +0 -55
  1472. package/dist/operator/report-carry-delivery.js.map +0 -1
  1473. package/dist/operator/report-carry.d.ts +0 -66
  1474. package/dist/operator/report-carry.d.ts.map +0 -1
  1475. package/dist/operator/report-carry.js +0 -352
  1476. package/dist/operator/report-carry.js.map +0 -1
  1477. package/dist/operator/report-delivery-coordinator.d.ts +0 -84
  1478. package/dist/operator/report-delivery-coordinator.d.ts.map +0 -1
  1479. package/dist/operator/report-delivery-coordinator.js +0 -146
  1480. package/dist/operator/report-delivery-coordinator.js.map +0 -1
  1481. package/dist/operator/report-run.d.ts +0 -52
  1482. package/dist/operator/report-run.d.ts.map +0 -1
  1483. package/dist/operator/report-run.js +0 -32
  1484. package/dist/operator/report-run.js.map +0 -1
  1485. package/dist/operator/report-scheduler.d.ts +0 -66
  1486. package/dist/operator/report-scheduler.d.ts.map +0 -1
  1487. package/dist/operator/report-scheduler.js +0 -135
  1488. package/dist/operator/report-scheduler.js.map +0 -1
  1489. package/dist/operator/runtime-config.d.ts +0 -10
  1490. package/dist/operator/runtime-config.d.ts.map +0 -1
  1491. package/dist/operator/runtime-config.js +0 -21
  1492. package/dist/operator/runtime-config.js.map +0 -1
  1493. package/dist/operator/situation-report.d.ts +0 -197
  1494. package/dist/operator/situation-report.d.ts.map +0 -1
  1495. package/dist/operator/situation-report.js +0 -462
  1496. package/dist/operator/situation-report.js.map +0 -1
  1497. package/dist/operator/subagent-stimulus.d.ts +0 -34
  1498. package/dist/operator/subagent-stimulus.d.ts.map +0 -1
  1499. package/dist/operator/subagent-stimulus.js +0 -145
  1500. package/dist/operator/subagent-stimulus.js.map +0 -1
  1501. package/dist/operator/task-ledger.d.ts +0 -879
  1502. package/dist/operator/task-ledger.d.ts.map +0 -1
  1503. package/dist/operator/task-ledger.js +0 -3601
  1504. package/dist/operator/task-ledger.js.map +0 -1
  1505. package/dist/operator/task-list-views.d.ts +0 -91
  1506. package/dist/operator/task-list-views.d.ts.map +0 -1
  1507. package/dist/operator/task-list-views.js +0 -532
  1508. package/dist/operator/task-list-views.js.map +0 -1
  1509. package/dist/operator/task-temporal.d.ts +0 -24
  1510. package/dist/operator/task-temporal.d.ts.map +0 -1
  1511. package/dist/operator/task-temporal.js +0 -123
  1512. package/dist/operator/task-temporal.js.map +0 -1
  1513. package/dist/operator/temporal-effect.d.ts +0 -65
  1514. package/dist/operator/temporal-effect.d.ts.map +0 -1
  1515. package/dist/operator/temporal-effect.js +0 -71
  1516. package/dist/operator/temporal-effect.js.map +0 -1
  1517. package/dist/operator/temporal-reconcile.d.ts +0 -49
  1518. package/dist/operator/temporal-reconcile.d.ts.map +0 -1
  1519. package/dist/operator/temporal-reconcile.js +0 -231
  1520. package/dist/operator/temporal-reconcile.js.map +0 -1
  1521. package/dist/operator/temporal-runtime.d.ts +0 -51
  1522. package/dist/operator/temporal-runtime.d.ts.map +0 -1
  1523. package/dist/operator/temporal-runtime.js +0 -104
  1524. package/dist/operator/temporal-runtime.js.map +0 -1
  1525. package/dist/operator/temporal-worker.d.ts +0 -18
  1526. package/dist/operator/temporal-worker.d.ts.map +0 -1
  1527. package/dist/operator/temporal-worker.js +0 -82
  1528. package/dist/operator/temporal-worker.js.map +0 -1
  1529. package/dist/operator/thread-brief-memory.d.ts +0 -29
  1530. package/dist/operator/thread-brief-memory.d.ts.map +0 -1
  1531. package/dist/operator/thread-brief-memory.js +0 -61
  1532. package/dist/operator/thread-brief-memory.js.map +0 -1
  1533. package/dist/operator/trigger-author.d.ts +0 -63
  1534. package/dist/operator/trigger-author.d.ts.map +0 -1
  1535. package/dist/operator/trigger-author.js +0 -384
  1536. package/dist/operator/trigger-author.js.map +0 -1
  1537. package/dist/operator/trigger-evolve.d.ts +0 -31
  1538. package/dist/operator/trigger-evolve.d.ts.map +0 -1
  1539. package/dist/operator/trigger-evolve.js +0 -51
  1540. package/dist/operator/trigger-evolve.js.map +0 -1
  1541. package/dist/operator/trigger-fire.d.ts +0 -29
  1542. package/dist/operator/trigger-fire.d.ts.map +0 -1
  1543. package/dist/operator/trigger-fire.js +0 -41
  1544. package/dist/operator/trigger-fire.js.map +0 -1
  1545. package/dist/operator/trigger-matcher.d.ts +0 -19
  1546. package/dist/operator/trigger-matcher.d.ts.map +0 -1
  1547. package/dist/operator/trigger-matcher.js +0 -65
  1548. package/dist/operator/trigger-matcher.js.map +0 -1
  1549. package/dist/operator/trigger-registry.d.ts +0 -58
  1550. package/dist/operator/trigger-registry.d.ts.map +0 -1
  1551. package/dist/operator/trigger-registry.js +0 -349
  1552. package/dist/operator/trigger-registry.js.map +0 -1
  1553. package/dist/operator/trigger-review.d.ts +0 -23
  1554. package/dist/operator/trigger-review.d.ts.map +0 -1
  1555. package/dist/operator/trigger-review.js +0 -193
  1556. package/dist/operator/trigger-review.js.map +0 -1
  1557. package/dist/operator/trigger-types.d.ts +0 -95
  1558. package/dist/operator/trigger-types.d.ts.map +0 -1
  1559. package/dist/operator/trigger-types.js +0 -14
  1560. package/dist/operator/trigger-types.js.map +0 -1
  1561. package/dist/operator/wiki-continuity.d.ts +0 -153
  1562. package/dist/operator/wiki-continuity.d.ts.map +0 -1
  1563. package/dist/operator/wiki-continuity.js +0 -221
  1564. package/dist/operator/wiki-continuity.js.map +0 -1
  1565. package/dist/operator/worker-run.d.ts +0 -109
  1566. package/dist/operator/worker-run.d.ts.map +0 -1
  1567. package/dist/operator/worker-run.js +0 -131
  1568. package/dist/operator/worker-run.js.map +0 -1
  1569. package/dist/operator/workorder-consumer.d.ts +0 -294
  1570. package/dist/operator/workorder-consumer.d.ts.map +0 -1
  1571. package/dist/operator/workorder-consumer.js +0 -1108
  1572. package/dist/operator/workorder-consumer.js.map +0 -1
  1573. package/dist/operator/workorder-hooks.d.ts +0 -162
  1574. package/dist/operator/workorder-hooks.d.ts.map +0 -1
  1575. package/dist/operator/workorder-hooks.js +0 -342
  1576. package/dist/operator/workorder-hooks.js.map +0 -1
  1577. package/dist/operator/workorder-publishers.d.ts +0 -117
  1578. package/dist/operator/workorder-publishers.d.ts.map +0 -1
  1579. package/dist/operator/workorder-publishers.js +0 -544
  1580. package/dist/operator/workorder-publishers.js.map +0 -1
  1581. package/dist/runners/cli-runner.d.ts +0 -59
  1582. package/dist/runners/cli-runner.d.ts.map +0 -1
  1583. package/dist/runners/cli-runner.js +0 -191
  1584. package/dist/runners/cli-runner.js.map +0 -1
  1585. package/dist/runners/index.d.ts +0 -11
  1586. package/dist/runners/index.d.ts.map +0 -1
  1587. package/dist/runners/index.js +0 -15
  1588. package/dist/runners/index.js.map +0 -1
  1589. package/dist/runners/types.d.ts +0 -81
  1590. package/dist/runners/types.d.ts.map +0 -1
  1591. package/dist/runners/types.js +0 -31
  1592. package/dist/runners/types.js.map +0 -1
  1593. package/dist/scheduler/cron-result-router.d.ts +0 -24
  1594. package/dist/scheduler/cron-result-router.d.ts.map +0 -1
  1595. package/dist/scheduler/cron-result-router.js +0 -63
  1596. package/dist/scheduler/cron-result-router.js.map +0 -1
  1597. package/dist/scheduler/cron-scheduler.d.ts +0 -115
  1598. package/dist/scheduler/cron-scheduler.d.ts.map +0 -1
  1599. package/dist/scheduler/cron-scheduler.js +0 -336
  1600. package/dist/scheduler/cron-scheduler.js.map +0 -1
  1601. package/dist/scheduler/cron-worker.d.ts +0 -39
  1602. package/dist/scheduler/cron-worker.d.ts.map +0 -1
  1603. package/dist/scheduler/cron-worker.js +0 -94
  1604. package/dist/scheduler/cron-worker.js.map +0 -1
  1605. package/dist/scheduler/heartbeat.d.ts +0 -64
  1606. package/dist/scheduler/heartbeat.d.ts.map +0 -1
  1607. package/dist/scheduler/heartbeat.js +0 -197
  1608. package/dist/scheduler/heartbeat.js.map +0 -1
  1609. package/dist/scheduler/index.d.ts +0 -26
  1610. package/dist/scheduler/index.d.ts.map +0 -1
  1611. package/dist/scheduler/index.js +0 -37
  1612. package/dist/scheduler/index.js.map +0 -1
  1613. package/dist/scheduler/job-lock.d.ts +0 -85
  1614. package/dist/scheduler/job-lock.d.ts.map +0 -1
  1615. package/dist/scheduler/job-lock.js +0 -137
  1616. package/dist/scheduler/job-lock.js.map +0 -1
  1617. package/dist/scheduler/recovery.d.ts +0 -78
  1618. package/dist/scheduler/recovery.d.ts.map +0 -1
  1619. package/dist/scheduler/recovery.js +0 -124
  1620. package/dist/scheduler/recovery.js.map +0 -1
  1621. package/dist/scheduler/schedule-store.d.ts +0 -112
  1622. package/dist/scheduler/schedule-store.d.ts.map +0 -1
  1623. package/dist/scheduler/schedule-store.js +0 -259
  1624. package/dist/scheduler/schedule-store.js.map +0 -1
  1625. package/dist/scheduler/token-keep-alive.d.ts +0 -49
  1626. package/dist/scheduler/token-keep-alive.d.ts.map +0 -1
  1627. package/dist/scheduler/token-keep-alive.js +0 -102
  1628. package/dist/scheduler/token-keep-alive.js.map +0 -1
  1629. package/dist/scheduler/types.d.ts +0 -98
  1630. package/dist/scheduler/types.d.ts.map +0 -1
  1631. package/dist/scheduler/types.js +0 -21
  1632. package/dist/scheduler/types.js.map +0 -1
  1633. package/dist/security/security-monitor.d.ts +0 -56
  1634. package/dist/security/security-monitor.d.ts.map +0 -1
  1635. package/dist/security/security-monitor.js +0 -779
  1636. package/dist/security/security-monitor.js.map +0 -1
  1637. package/dist/security/trusted-proxy.d.ts +0 -9
  1638. package/dist/security/trusted-proxy.d.ts.map +0 -1
  1639. package/dist/security/trusted-proxy.js +0 -36
  1640. package/dist/security/trusted-proxy.js.map +0 -1
  1641. package/dist/skills/index.d.ts +0 -10
  1642. package/dist/skills/index.d.ts.map +0 -1
  1643. package/dist/skills/index.js +0 -26
  1644. package/dist/skills/index.js.map +0 -1
  1645. package/dist/skills/skill-executor.d.ts +0 -48
  1646. package/dist/skills/skill-executor.d.ts.map +0 -1
  1647. package/dist/skills/skill-executor.js +0 -483
  1648. package/dist/skills/skill-executor.js.map +0 -1
  1649. package/dist/skills/skill-loader.d.ts +0 -40
  1650. package/dist/skills/skill-loader.d.ts.map +0 -1
  1651. package/dist/skills/skill-loader.js +0 -233
  1652. package/dist/skills/skill-loader.js.map +0 -1
  1653. package/dist/skills/skill-matcher.d.ts +0 -33
  1654. package/dist/skills/skill-matcher.d.ts.map +0 -1
  1655. package/dist/skills/skill-matcher.js +0 -190
  1656. package/dist/skills/skill-matcher.js.map +0 -1
  1657. package/dist/skills/skill-registry.d.ts +0 -117
  1658. package/dist/skills/skill-registry.d.ts.map +0 -1
  1659. package/dist/skills/skill-registry.js +0 -627
  1660. package/dist/skills/skill-registry.js.map +0 -1
  1661. package/dist/skills/types.d.ts +0 -131
  1662. package/dist/skills/types.d.ts.map +0 -1
  1663. package/dist/skills/types.js +0 -12
  1664. package/dist/skills/types.js.map +0 -1
  1665. package/dist/utils/log-sanitizer.d.ts +0 -79
  1666. package/dist/utils/log-sanitizer.d.ts.map +0 -1
  1667. package/dist/utils/log-sanitizer.js +0 -215
  1668. package/dist/utils/log-sanitizer.js.map +0 -1
  1669. package/dist/validation/session-service.d.ts +0 -72
  1670. package/dist/validation/session-service.d.ts.map +0 -1
  1671. package/dist/validation/session-service.js +0 -298
  1672. package/dist/validation/session-service.js.map +0 -1
  1673. package/dist/validation/store.d.ts +0 -25
  1674. package/dist/validation/store.d.ts.map +0 -1
  1675. package/dist/validation/store.js +0 -200
  1676. package/dist/validation/store.js.map +0 -1
  1677. package/dist/validation/types.d.ts +0 -119
  1678. package/dist/validation/types.d.ts.map +0 -1
  1679. package/dist/validation/types.js +0 -57
  1680. package/dist/validation/types.js.map +0 -1
  1681. package/dist/wiki/wiki-turn-contract.d.ts +0 -19
  1682. package/dist/wiki/wiki-turn-contract.d.ts.map +0 -1
  1683. package/dist/wiki/wiki-turn-contract.js +0 -60
  1684. package/dist/wiki/wiki-turn-contract.js.map +0 -1
  1685. package/public/viewer/js/utils/ui-commands.js +0 -88
  1686. package/public/viewer/src/utils/ui-commands.ts +0 -114
  1687. package/scripts/attachment/extract-office-text.js +0 -179
  1688. package/scripts/attachment/extract-pdf-text.swift +0 -36
  1689. package/scripts/backfill-channel-keys.ts +0 -509
  1690. package/scripts/crack-failure-digests.ts +0 -55
  1691. package/scripts/generate-gateway-tools.ts +0 -131
  1692. package/scripts/image/fb-overlay.py +0 -128
  1693. package/scripts/image/ocr-image.py +0 -38
  1694. package/scripts/postinstall.js +0 -161
  1695. package/scripts/setup-ocr.js +0 -120
  1696. package/templates/AGENTS.claude.md +0 -23
  1697. package/templates/AGENTS.codex.md +0 -11
  1698. package/templates/bmad/LICENSE +0 -28
  1699. package/templates/bmad/architecture.md +0 -343
  1700. package/templates/bmad/bmm-workflow-status.template.yaml +0 -66
  1701. package/templates/bmad/prd.md +0 -198
  1702. package/templates/bmad/product-brief.md +0 -149
  1703. package/templates/bmad/sprint-status.template.yaml +0 -35
  1704. package/templates/bmad/tech-spec.md +0 -151
  1705. package/templates/entity-audit-fixtures/cross-language-aliases.json +0 -28
  1706. package/templates/entity-audit-fixtures/gold-canonical-identities.json +0 -46
  1707. package/templates/skills/danggeun-monitor.md +0 -88
  1708. package/templates/skills/document-analyze.md +0 -63
  1709. package/templates/skills/frontend-design.md +0 -71
  1710. package/templates/skills/image-translate.md +0 -62
  1711. package/templates/skills/multi-agent-collab.md +0 -145
  1712. package/templates/skills/scheduling.md +0 -107
  1713. package/templates/workspace/skill-forge/DESIGN.md +0 -115
  1714. package/templates/workspace/skill-forge/agents/architect.ts +0 -295
  1715. package/templates/workspace/skill-forge/agents/developer.ts +0 -364
  1716. package/templates/workspace/skill-forge/agents/qa.ts +0 -313
  1717. package/templates/workspace/skill-forge/claude-api.ts +0 -353
  1718. package/templates/workspace/skill-forge/discord-ui.ts +0 -580
  1719. package/templates/workspace/skill-forge/error-handler.ts +0 -354
  1720. package/templates/workspace/skill-forge/mama-integration.ts +0 -357
  1721. package/templates/workspace/skill-forge/orchestrator.ts +0 -495
  1722. package/templates/workspace/skill-forge/output/generated-skills/skills/hello-world/README.md +0 -24
  1723. package/templates/workspace/skill-forge/output/generated-skills/skills/hello-world/index.ts +0 -79
  1724. package/templates/workspace/skill-forge/output/generated-skills/skills/hello-world/types.ts +0 -17
  1725. package/templates/workspace/skill-forge/package.json +0 -21
  1726. package/templates/workspace/skill-forge/state/session.json +0 -132
  1727. package/templates/workspace/skill-forge/test-e2e.ts +0 -139
  1728. package/templates/workspace/skill-forge/tsconfig.json +0 -20
  1729. package/templates/workspace/skill-forge/types.ts +0 -159
@@ -1,2084 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CodexAppServerProcess = void 0;
4
- const node_child_process_1 = require("node:child_process");
5
- const node_crypto_1 = require("node:crypto");
6
- const node_fs_1 = require("node:fs");
7
- const node_os_1 = require("node:os");
8
- const node_path_1 = require("node:path");
9
- const node_readline_1 = require("node:readline");
10
- const model_runner_js_1 = require("./model-runner.js");
11
- const codex_home_js_1 = require("./codex-home.js");
12
- const codex_thread_registry_js_1 = require("./codex-thread-registry.js");
13
- const DEFAULT_TIMEOUT = 300_000;
14
- const STOP_GRACE_MS = 200;
15
- const STDERR_LIMIT = 4_000;
16
- const CLIENT_INFO = { name: 'mama-codex-app-server', version: '1.0.0' };
17
- const TURN_STATUSES = new Set(['completed', 'interrupted', 'failed', 'inProgress']);
18
- const TURN_ITEM_VIEWS = new Set(['notLoaded', 'summary', 'full']);
19
- const APPROVAL_REVIEWERS = new Set(['user', 'auto_review', 'guardian_subagent']);
20
- const OVERLOADED_ERROR_CODE = -32001;
21
- const OVERLOAD_RETRY_LIMIT = 4;
22
- const OVERLOAD_RETRY_BASE_MS = 25;
23
- const TURN_START_RECONCILE_GRACE_MS = 250;
24
- const SUBAGENT_FINAL_TEXT_LIMIT = 4_000;
25
- /** Wait for the child's own `turn/completed` after the parent announced it finished. */
26
- const SUBAGENT_COMPLETION_GRACE_MS = 5_000;
27
- /** A registered child that never completes is reported failed rather than leaked. */
28
- const SUBAGENT_TTL_MS = 45 * 60_000;
29
- /** Bound on remembered finished child threads; identity, not history. */
30
- const MAX_FINISHED_SUBAGENTS = 200;
31
- const SUBAGENT_AUTHORITY_UNAVAILABLE = 'subagent authority unavailable';
32
- const SUBAGENT_AUTHORITY_EXPIRED = 'subagent authority expired';
33
- /** EnvelopeViolation code prefix the enforcer returns once a grant is past its wall. */
34
- const ENVELOPE_EXPIRED_MARKER = '[expired]';
35
- class CodexAppServerRpcError extends Error {
36
- code;
37
- constructor(code, message) {
38
- super(message);
39
- this.name = 'CodexAppServerRpcError';
40
- this.code = code;
41
- }
42
- }
43
- function object(value) {
44
- return typeof value === 'object' && value !== null && !Array.isArray(value)
45
- ? value
46
- : undefined;
47
- }
48
- function stableJson(value) {
49
- if (Array.isArray(value)) {
50
- return value.map(stableJson);
51
- }
52
- const record = object(value);
53
- if (!record) {
54
- return value;
55
- }
56
- return Object.fromEntries(Object.keys(record)
57
- .sort()
58
- .map((key) => [key, stableJson(record[key])]));
59
- }
60
- function deepFreeze(value) {
61
- if (Array.isArray(value)) {
62
- for (const item of value) {
63
- deepFreeze(item);
64
- }
65
- Object.freeze(value);
66
- return;
67
- }
68
- const record = object(value);
69
- if (record) {
70
- for (const item of Object.values(record)) {
71
- deepFreeze(item);
72
- }
73
- Object.freeze(record);
74
- }
75
- }
76
- function snapshotHostToolBridge(bridge) {
77
- if (!bridge) {
78
- return undefined;
79
- }
80
- const tools = bridge.tools
81
- .map((tool) => stableJson(tool))
82
- .sort((left, right) => left.name.localeCompare(right.name));
83
- deepFreeze(tools);
84
- const execute = bridge.execute.bind(bridge);
85
- return Object.freeze({ tools, execute });
86
- }
87
- function errorMessage(value, fallback) {
88
- const record = object(value);
89
- return typeof record?.message === 'string' && record.message ? record.message : fallback;
90
- }
91
- function stringField(record, name, context) {
92
- const value = record[name];
93
- if (typeof value !== 'string') {
94
- throw new Error(`Codex app-server returned malformed ${context}.${name}`);
95
- }
96
- return value;
97
- }
98
- function nullableStringField(record, name, context) {
99
- const value = record[name];
100
- if (value !== null && typeof value !== 'string') {
101
- throw new Error(`Codex app-server returned malformed ${context}.${name}`);
102
- }
103
- }
104
- function nullableNumberField(record, name, context) {
105
- const value = record[name];
106
- if (value !== null && (typeof value !== 'number' || !Number.isFinite(value))) {
107
- throw new Error(`Codex app-server returned malformed ${context}.${name}`);
108
- }
109
- }
110
- function validateTurn(value, context) {
111
- const turn = object(value);
112
- if (!turn) {
113
- throw new Error(`Codex app-server returned malformed ${context}`);
114
- }
115
- stringField(turn, 'id', context);
116
- if (!Array.isArray(turn.items) || !TURN_ITEM_VIEWS.has(String(turn.itemsView))) {
117
- throw new Error(`Codex app-server returned malformed ${context} items`);
118
- }
119
- if (!TURN_STATUSES.has(String(turn.status))) {
120
- throw new Error(`Codex app-server returned malformed ${context}.status`);
121
- }
122
- if (turn.error !== null) {
123
- const error = object(turn.error);
124
- if (!error ||
125
- typeof error.message !== 'string' ||
126
- error.codexErrorInfo === undefined ||
127
- (error.additionalDetails !== null && typeof error.additionalDetails !== 'string')) {
128
- throw new Error(`Codex app-server returned malformed ${context}.error`);
129
- }
130
- }
131
- nullableNumberField(turn, 'startedAt', context);
132
- nullableNumberField(turn, 'completedAt', context);
133
- nullableNumberField(turn, 'durationMs', context);
134
- return turn;
135
- }
136
- function validateThread(value) {
137
- const thread = object(value);
138
- if (!thread) {
139
- throw new Error('Codex app-server returned malformed thread');
140
- }
141
- for (const field of ['id', 'sessionId', 'preview', 'modelProvider', 'cwd', 'cliVersion']) {
142
- stringField(thread, field, 'thread');
143
- }
144
- for (const field of [
145
- 'forkedFromId',
146
- 'parentThreadId',
147
- 'path',
148
- 'threadSource',
149
- 'agentNickname',
150
- 'agentRole',
151
- 'name',
152
- ]) {
153
- nullableStringField(thread, field, 'thread');
154
- }
155
- if (typeof thread.ephemeral !== 'boolean') {
156
- throw new Error('Codex app-server returned malformed thread.ephemeral');
157
- }
158
- for (const field of ['createdAt', 'updatedAt']) {
159
- if (typeof thread[field] !== 'number' || !Number.isFinite(thread[field])) {
160
- throw new Error(`Codex app-server returned malformed thread.${field}`);
161
- }
162
- }
163
- nullableNumberField(thread, 'recencyAt', 'thread');
164
- const status = object(thread.status);
165
- if (!status ||
166
- !['notLoaded', 'idle', 'systemError', 'active'].includes(String(status.type)) ||
167
- (status.type === 'active' && !Array.isArray(status.activeFlags))) {
168
- throw new Error('Codex app-server returned malformed thread.status');
169
- }
170
- const sourceValid = typeof thread.source === 'string' || object(thread.source) !== undefined;
171
- if (!sourceValid ||
172
- (thread.gitInfo !== null && !object(thread.gitInfo)) ||
173
- !Array.isArray(thread.turns)) {
174
- throw new Error('Codex app-server returned malformed thread metadata');
175
- }
176
- for (const turn of thread.turns) {
177
- validateTurn(turn, 'thread.turns[]');
178
- }
179
- return thread;
180
- }
181
- function shaFile(path) {
182
- return (0, node_crypto_1.createHash)('sha256').update((0, node_fs_1.readFileSync)(path)).digest('hex');
183
- }
184
- function managedFileSignature(path) {
185
- if (!(0, node_fs_1.existsSync)(path)) {
186
- return undefined;
187
- }
188
- const stat = (0, node_fs_1.statSync)(path);
189
- return `${stat.dev}:${stat.ino}:${stat.mode}:${stat.size}:${stat.mtimeMs}:${stat.ctimeMs}`;
190
- }
191
- function ensurePrivateDirectory(path) {
192
- (0, node_fs_1.mkdirSync)(path, { recursive: true, mode: 0o700 });
193
- (0, node_fs_1.chmodSync)(path, 0o700);
194
- }
195
- function atomicPrivateWrite(path, value) {
196
- ensurePrivateDirectory((0, node_path_1.dirname)(path));
197
- const temporary = `${path}.${process.pid}.${(0, node_crypto_1.randomUUID)()}.tmp`;
198
- (0, node_fs_1.writeFileSync)(temporary, value, { encoding: 'utf8', mode: 0o600, flag: 'wx' });
199
- (0, node_fs_1.chmodSync)(temporary, 0o600);
200
- (0, node_fs_1.renameSync)(temporary, path);
201
- (0, node_fs_1.chmodSync)(path, 0o600);
202
- }
203
- function copyAuthAtomically(source, destination) {
204
- if (!(0, node_fs_1.existsSync)(source) ||
205
- (0, node_fs_1.statSync)(source).size === 0 ||
206
- (0, node_path_1.resolve)(source) === (0, node_path_1.resolve)(destination)) {
207
- return;
208
- }
209
- ensurePrivateDirectory((0, node_path_1.dirname)(destination));
210
- const temporary = `${destination}.${process.pid}.${(0, node_crypto_1.randomUUID)()}.tmp`;
211
- (0, node_fs_1.copyFileSync)(source, temporary);
212
- (0, node_fs_1.chmodSync)(temporary, 0o600);
213
- (0, node_fs_1.renameSync)(temporary, destination);
214
- (0, node_fs_1.chmodSync)(destination, 0o600);
215
- }
216
- function configuredSecretValues(launch) {
217
- const names = new Set();
218
- const addJsonString = (source) => {
219
- try {
220
- const name = JSON.parse(source);
221
- if (typeof name === 'string' && /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) {
222
- names.add(name);
223
- }
224
- }
225
- catch (error) {
226
- throw new Error('Codex app-server launch config contained malformed environment quoting', {
227
- cause: error,
228
- });
229
- }
230
- };
231
- for (const argument of launch.args) {
232
- for (const match of argument.matchAll(/env_vars\s*=\s*\[([^\]]*)\]/g)) {
233
- for (const quoted of match[1].matchAll(/"(?:\\.|[^"\\])*"/g)) {
234
- addJsonString(quoted[0]);
235
- }
236
- }
237
- for (const match of argument.matchAll(/bearer_token_env_var\s*=\s*("(?:\\.|[^"\\])*")/g)) {
238
- addJsonString(match[1]);
239
- }
240
- for (const match of argument.matchAll(/env_http_headers\s*=\s*\{([^}]*)\}/g)) {
241
- for (const binding of match[1].matchAll(/=\s*("(?:\\.|[^"\\])*")/g)) {
242
- addJsonString(binding[1]);
243
- }
244
- }
245
- }
246
- const values = new Set();
247
- for (const name of names) {
248
- const value = launch.env[name];
249
- if (typeof value === 'string' && value.length > 0) {
250
- values.add(value);
251
- }
252
- }
253
- return values;
254
- }
255
- class CodexAppServerProcess {
256
- options;
257
- registry;
258
- child;
259
- stdout;
260
- stderr;
261
- nextId = 0;
262
- pending = new Map();
263
- lateTurnStarts = new Map();
264
- turnStartReconciliations = new Map();
265
- turns = new Map();
266
- subagents = new Map();
267
- /**
268
- * Child threads that already reported a terminal status. The SAME `started`
269
- * announcement arrives as both an item/started and an item/completed view, and the
270
- * second view can land after the child's own turn/completed - `subagents.has` no longer
271
- * dedupes it then, so it would mint a second authority and a second completion for a
272
- * dead child. Bounded FIFO: identity of recent children, not a growing ledger.
273
- */
274
- finishedSubagents = new Set();
275
- threadContexts = new Map();
276
- sessions = new Map();
277
- sessionQueues = new Map();
278
- connectionQueue = Promise.resolve();
279
- startPromise;
280
- shutdownPromise;
281
- stopped = false;
282
- stderrTail = '';
283
- secrets = new Set();
284
- authFingerprint;
285
- authFingerprintInitialized = false;
286
- authSourceSignature;
287
- managedConfigFingerprint;
288
- managedConfigSignature;
289
- secretLaunchFingerprint;
290
- secretLaunchFingerprintInitialized = false;
291
- killTimer;
292
- finalKillTimer;
293
- constructor(options) {
294
- const mamaRoot = (0, node_path_1.join)((0, node_os_1.homedir)(), '.mama');
295
- this.options = {
296
- ...options,
297
- command: options.command ?? 'codex',
298
- requestTimeout: options.requestTimeout ?? DEFAULT_TIMEOUT,
299
- codexHome: (0, node_path_1.resolve)(options.codexHome ?? (0, node_path_1.join)(mamaRoot, '.codex')),
300
- isolatedHome: (0, node_path_1.resolve)(options.isolatedHome ?? (0, node_path_1.join)(mamaRoot, 'codex-runtime', 'home')),
301
- registryRoot: (0, node_path_1.resolve)(options.registryRoot ?? (0, node_path_1.join)(mamaRoot, 'codex-runtime', 'threads')),
302
- cwd: (0, node_path_1.resolve)(options.cwd),
303
- };
304
- ensurePrivateDirectory((0, node_path_1.dirname)(this.options.registryRoot));
305
- this.registry = new codex_thread_registry_js_1.CodexThreadRegistry({ rootDir: this.options.registryRoot });
306
- }
307
- async prompt(text, callbacks, overrides = {}) {
308
- if (this.stopped) {
309
- throw new Error('Codex app-server process is stopped');
310
- }
311
- const session = this.resolveSessionPolicy(overrides);
312
- return this.enqueueSession(session.sessionKey, async () => {
313
- try {
314
- if (this.stopped) {
315
- throw new Error('Codex app-server process is stopped');
316
- }
317
- const launch = (0, codex_home_js_1.buildCodexAppServerLaunchConfig)(this.options.mcpConfigPath, process.env);
318
- if (overrides.resumeSession === false) {
319
- this.discardSessionThreadState(session.sessionKey, 'session was restarted');
320
- this.registry.remove(session.sessionKey);
321
- this.sessions.delete(session.sessionKey);
322
- }
323
- this.assertRegistryPolicy(session, launch);
324
- await this.prepareConnection(launch, session.requestTimeout);
325
- let state = this.sessions.get(session.sessionKey);
326
- if (!state?.threadId) {
327
- try {
328
- state = await this.openThread(session, launch);
329
- }
330
- catch (error) {
331
- if (this.child && !this.shutdownPromise) {
332
- await this.shutdown(this.toError(error));
333
- }
334
- throw error;
335
- }
336
- this.sessions.set(session.sessionKey, state);
337
- }
338
- const reconciliation = this.turnStartReconciliations.get(state.threadId);
339
- if (reconciliation) {
340
- await reconciliation.promise;
341
- await this.prepareConnection(launch, session.requestTimeout);
342
- state = this.sessions.get(session.sessionKey);
343
- if (!state?.threadId) {
344
- state = await this.openThread(session, launch);
345
- this.sessions.set(session.sessionKey, state);
346
- }
347
- }
348
- const replayReminder = Boolean(state.bootstrapPending && session.systemPrompt);
349
- const turnText = replayReminder
350
- ? `<system-reminder>\nFresh MAMA runtime context after resuming this durable thread:\n${session.systemPrompt.replace(/<\/system-reminder>/gi, '')}\n</system-reminder>\n\n${text}`
351
- : text;
352
- // One line per turn, where the text that actually reaches the model is known.
353
- // This is what makes "fixed things once, turns carry only deltas" measurable
354
- // from daemon.log instead of asserted.
355
- console.log(`[prompt] thread=${state.threadId} kind=${session.promptTelemetry?.kind ?? 'chat'} ` +
356
- `chars=${turnText.length} brief=${session.promptTelemetry?.brief ?? 'omitted'} ` +
357
- `reminder=${replayReminder ? 'sent' : 'omitted'}`);
358
- // A Codex-native child can be announced after this turn resolved, so remember
359
- // which session the thread belongs to outside the PendingTurn lifetime. The
360
- // parent's BRIDGE is deliberately not kept: a child gets its own authority.
361
- // A session that rotated its thread leaves the previous thread's context behind,
362
- // and a stale entry both leaks and lets a dead thread announce children.
363
- this.pruneThreadContexts(session.sessionKey, state.threadId);
364
- this.threadContexts.set(state.threadId, {
365
- sessionKey: session.sessionKey,
366
- onToolUse: callbacks?.onToolUse,
367
- onToolComplete: callbacks?.onToolComplete,
368
- });
369
- const result = await this.startTurn(state.threadId, turnText, callbacks, session.requestTimeout, session.hostToolBridge, overrides.runTokenBudget);
370
- state.bootstrapPending = false;
371
- return result;
372
- }
373
- catch (error) {
374
- if (error instanceof CodexAppServerRpcError &&
375
- error.code !== OVERLOADED_ERROR_CODE &&
376
- this.child &&
377
- !this.shutdownPromise) {
378
- await this.shutdown(error);
379
- }
380
- if (this.shutdownPromise) {
381
- await this.shutdownPromise;
382
- }
383
- throw error;
384
- }
385
- });
386
- }
387
- async reset(sessionKey = this.options.sessionKey) {
388
- await this.enqueueSession(sessionKey, async () => {
389
- this.discardSessionThreadState(sessionKey, 'session was reset');
390
- this.registry.remove(sessionKey);
391
- this.sessions.delete(sessionKey);
392
- });
393
- }
394
- getSessionPolicyStatus(overrides = {}) {
395
- const session = this.resolveSessionPolicy(overrides);
396
- const record = this.registry.load(session.sessionKey);
397
- if (!record) {
398
- return 'missing';
399
- }
400
- const launch = (0, codex_home_js_1.buildCodexAppServerLaunchConfig)(this.options.mcpConfigPath, process.env);
401
- return this.registryPolicyMatches(record, session, launch) ? 'compatible' : 'mismatch';
402
- }
403
- async stop() {
404
- this.stopped = true;
405
- await this.shutdown(new Error('Codex app-server process stopped'));
406
- this.terminateSubagents(new Error('Codex app-server process stopped'));
407
- this.threadContexts.clear();
408
- }
409
- async executeSandboxedCommand(command, cwd, roots, signal) {
410
- signal?.throwIfAborted();
411
- if (!this.child)
412
- throw new Error('Codex app-server is not connected');
413
- const shellCommand = process.platform === 'win32'
414
- ? ['cmd.exe', '/d', '/s', '/c', command]
415
- : ['/bin/sh', '-c', command];
416
- const result = object(await this.request('command/exec', {
417
- command: shellCommand,
418
- cwd,
419
- sandboxPolicy: {
420
- type: 'workspaceWrite',
421
- writableRoots: [...roots],
422
- readOnlyAccess: {
423
- type: 'restricted',
424
- includePlatformDefaults: true,
425
- readableRoots: [...roots],
426
- },
427
- networkAccess: false,
428
- },
429
- timeoutMs: this.options.requestTimeout,
430
- }, this.options.requestTimeout));
431
- signal?.throwIfAborted();
432
- if (typeof result?.exitCode !== 'number' ||
433
- typeof result.stdout !== 'string' ||
434
- typeof result.stderr !== 'string') {
435
- throw new Error('Codex app-server returned a malformed command result');
436
- }
437
- return { exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr };
438
- }
439
- getThreadId(sessionKey = this.options.sessionKey) {
440
- return this.sessions.get(sessionKey)?.threadId || undefined;
441
- }
442
- getStatus() {
443
- return {
444
- running: this.child !== undefined,
445
- childPid: this.child?.pid,
446
- pendingRequestCount: this.pending.size,
447
- hasActiveTurn: this.turns.size > 0,
448
- stdoutListenerCount: this.stdout?.listenerCount('line') ?? 0,
449
- stderrListenerCount: this.stderr?.listenerCount('line') ?? 0,
450
- shutdownTimerActive: this.killTimer !== undefined || this.finalKillTimer !== undefined,
451
- };
452
- }
453
- resolveSessionPolicy(overrides) {
454
- const hostToolBridge = snapshotHostToolBridge(overrides.hostToolBridge);
455
- return {
456
- sessionKey: overrides.sessionKey ?? this.options.sessionKey,
457
- model: overrides.model ?? this.options.model,
458
- systemPrompt: overrides.systemPrompt ?? this.options.systemPrompt,
459
- cwd: (0, node_path_1.resolve)(overrides.cwd ?? this.options.cwd),
460
- sandbox: overrides.sandbox ?? this.options.sandbox,
461
- requestTimeout: overrides.requestTimeout ?? this.options.requestTimeout,
462
- policyFingerprint: overrides.policyFingerprint ?? this.options.policyFingerprint,
463
- hostToolBridge,
464
- resumeInstructions: overrides.resumeInstructions,
465
- promptTelemetry: overrides.promptTelemetry,
466
- };
467
- }
468
- enqueueSession(sessionKey, operation) {
469
- const previous = this.sessionQueues.get(sessionKey) ?? Promise.resolve();
470
- const result = previous.catch(() => undefined).then(operation);
471
- const tail = result.then(() => undefined, () => undefined);
472
- this.sessionQueues.set(sessionKey, tail);
473
- void tail.finally(() => {
474
- if (this.sessionQueues.get(sessionKey) === tail) {
475
- this.sessionQueues.delete(sessionKey);
476
- }
477
- });
478
- return result;
479
- }
480
- async prepareConnection(launch, requestTimeout) {
481
- const operation = this.connectionQueue.then(async () => {
482
- if (this.stopped) {
483
- throw new Error('Codex app-server process is stopped');
484
- }
485
- if (this.shutdownPromise) {
486
- await this.shutdownPromise;
487
- }
488
- if (this.stopped) {
489
- throw new Error('Codex app-server process is stopped');
490
- }
491
- const refreshed = this.prepareManagedFiles(launch);
492
- if (refreshed && this.child) {
493
- await this.restart();
494
- }
495
- try {
496
- await this.ensureStarted(launch, requestTimeout);
497
- }
498
- catch (error) {
499
- if (this.child && !this.shutdownPromise) {
500
- await this.shutdown(this.toError(error));
501
- }
502
- throw error;
503
- }
504
- });
505
- this.connectionQueue = operation.catch(() => undefined);
506
- await operation;
507
- }
508
- assertRegistryPolicy(session, launch) {
509
- const record = this.registry.load(session.sessionKey);
510
- if (!record) {
511
- return;
512
- }
513
- if (!this.registryPolicyMatches(record, session, launch)) {
514
- throw new Error('Codex app-server thread policy mismatch; reset the session explicitly');
515
- }
516
- }
517
- registryPolicyMatches(record, session, launch) {
518
- return (record.model === session.model &&
519
- record.cwd === session.cwd &&
520
- record.systemPromptFingerprint === this.policyFingerprint(session) &&
521
- record.mcpConfigFingerprint === launch.fingerprint);
522
- }
523
- prepareManagedFiles(launch) {
524
- ensurePrivateDirectory(this.options.codexHome);
525
- ensurePrivateDirectory(this.options.isolatedHome);
526
- const configPath = (0, node_path_1.join)(this.options.codexHome, 'config.toml');
527
- const config = (0, codex_home_js_1.buildMAMACodexAppServerConfig)(this.options.effort);
528
- const configFingerprint = (0, codex_thread_registry_js_1.fingerprintText)(config);
529
- const configSignature = managedFileSignature(configPath);
530
- if (this.managedConfigFingerprint !== configFingerprint ||
531
- this.managedConfigSignature !== configSignature) {
532
- if (configSignature === undefined || shaFile(configPath) !== configFingerprint) {
533
- atomicPrivateWrite(configPath, config);
534
- }
535
- this.managedConfigFingerprint = configFingerprint;
536
- this.managedConfigSignature = managedFileSignature(configPath);
537
- }
538
- const sourceAuth = (0, node_path_1.join)((0, node_os_1.homedir)(), '.codex', 'auth.json');
539
- const destinationAuth = (0, node_path_1.join)(this.options.codexHome, 'auth.json');
540
- const sourceStat = (0, node_fs_1.existsSync)(sourceAuth) ? (0, node_fs_1.statSync)(sourceAuth) : undefined;
541
- const sourceSignature = sourceStat && sourceStat.size > 0
542
- ? `${(0, node_fs_1.realpathSync)(sourceAuth)}:${sourceStat.size}:${sourceStat.mtimeMs}:${sourceStat.ctimeMs}`
543
- : undefined;
544
- let sourceFingerprint = this.authFingerprint;
545
- if (!this.authFingerprintInitialized ||
546
- this.authSourceSignature !== sourceSignature ||
547
- (sourceSignature !== undefined && !(0, node_fs_1.existsSync)(destinationAuth))) {
548
- sourceFingerprint = sourceSignature ? shaFile(sourceAuth) : undefined;
549
- if (sourceFingerprint &&
550
- (!(0, node_fs_1.existsSync)(destinationAuth) || shaFile(destinationAuth) !== sourceFingerprint)) {
551
- copyAuthAtomically(sourceAuth, destinationAuth);
552
- }
553
- }
554
- const changed = this.authFingerprintInitialized && this.authFingerprint !== sourceFingerprint;
555
- this.authFingerprint = sourceFingerprint;
556
- this.authFingerprintInitialized = true;
557
- this.authSourceSignature = sourceSignature;
558
- const secretChanged = this.secretLaunchFingerprintInitialized &&
559
- this.secretLaunchFingerprint !== launch.secretFingerprint;
560
- if (!this.secretLaunchFingerprintInitialized ||
561
- this.secretLaunchFingerprint !== launch.secretFingerprint) {
562
- this.secrets = configuredSecretValues(launch);
563
- this.secretLaunchFingerprint = launch.secretFingerprint;
564
- this.secretLaunchFingerprintInitialized = true;
565
- }
566
- return changed || secretChanged;
567
- }
568
- async ensureStarted(launch, requestTimeout) {
569
- if (this.child) {
570
- return;
571
- }
572
- if (!this.startPromise) {
573
- this.startPromise = this.start(launch, requestTimeout);
574
- }
575
- try {
576
- await this.startPromise;
577
- }
578
- finally {
579
- this.startPromise = undefined;
580
- }
581
- }
582
- async start(launch, requestTimeout) {
583
- const child = (0, node_child_process_1.spawn)(this.options.command, ['app-server', '--strict-config', '--stdio', ...launch.args], {
584
- cwd: this.options.cwd,
585
- env: { ...launch.env, HOME: this.options.isolatedHome, CODEX_HOME: this.options.codexHome },
586
- stdio: ['pipe', 'pipe', 'pipe'],
587
- });
588
- this.child = child;
589
- this.stdout = (0, node_readline_1.createInterface)({ input: child.stdout, crlfDelay: Infinity });
590
- this.stderr = (0, node_readline_1.createInterface)({ input: child.stderr, crlfDelay: Infinity });
591
- this.stdout.on('line', (line) => this.handleLine(child, line));
592
- this.stderr.on('line', (line) => this.handleStderr(line));
593
- child.once('error', (error) => this.failProcess(child, error));
594
- child.once('exit', (code, signal) => this.failProcess(child, new Error(`Codex app-server exited (${code ?? signal ?? 'unknown'})`)));
595
- const initialized = await this.request('initialize', {
596
- clientInfo: CLIENT_INFO,
597
- capabilities: { experimentalApi: true },
598
- }, requestTimeout);
599
- const initializeResponse = object(initialized);
600
- if (!initializeResponse ||
601
- typeof initializeResponse.userAgent !== 'string' ||
602
- typeof initializeResponse.codexHome !== 'string' ||
603
- typeof initializeResponse.platformFamily !== 'string' ||
604
- typeof initializeResponse.platformOs !== 'string') {
605
- throw new Error('Codex app-server initialize returned a malformed response');
606
- }
607
- if ((0, node_fs_1.realpathSync)(initializeResponse.codexHome) !== (0, node_fs_1.realpathSync)(this.options.codexHome)) {
608
- throw new Error('Codex app-server initialize returned an unexpected CODEX_HOME');
609
- }
610
- this.notify('initialized');
611
- }
612
- async openThread(session, launch) {
613
- const record = this.registry.load(session.sessionKey);
614
- if (record) {
615
- // A rehydrated thread carries its original instructions only in the model's own
616
- // history, where compaction eventually erodes them. ThreadResumeParams accepts
617
- // baseInstructions, so re-anchor through the protocol when the caller can supply
618
- // the full text. assertRegistryPolicy already proved the stored policy fingerprint
619
- // matches this session, and the caller builds these instructions from the same
620
- // composed-prompt sources that produced that fingerprint - so re-supplying them
621
- // restates the agreed policy rather than switching to a new one.
622
- const resumeInstructions = session.resumeInstructions
623
- ? await session.resumeInstructions()
624
- : undefined;
625
- if (session.resumeInstructions && !resumeInstructions?.trim()) {
626
- // No-fallback: silently resuming without instructions is the very failure this
627
- // path exists to remove.
628
- throw new Error('Codex app-server resume instructions resolved to empty text');
629
- }
630
- const resumeParams = {
631
- threadId: record.threadId,
632
- model: session.model,
633
- cwd: session.cwd,
634
- approvalPolicy: 'never',
635
- sandbox: session.sandbox,
636
- };
637
- if (resumeInstructions) {
638
- resumeParams.baseInstructions = resumeInstructions;
639
- }
640
- const result = object(await this.request('thread/resume', resumeParams, session.requestTimeout));
641
- this.validateResponsePolicy(result, session);
642
- this.validateInstructionMetadata(result, session);
643
- const resumed = validateThread(result?.thread);
644
- if (typeof resumed?.id !== 'string' || resumed.id !== record.threadId) {
645
- throw new Error('Codex app-server resumed an unexpected thread');
646
- }
647
- // Instructions delivered through the protocol make the turn-text bootstrap
648
- // redundant; without them the legacy <system-reminder> replay still applies.
649
- return { threadId: record.threadId, bootstrapPending: resumeInstructions === undefined };
650
- }
651
- const threadStartParams = {
652
- model: session.model,
653
- cwd: session.cwd,
654
- approvalPolicy: 'never',
655
- sandbox: session.sandbox,
656
- baseInstructions: session.systemPrompt,
657
- config: {},
658
- };
659
- if (session.hostToolBridge) {
660
- threadStartParams.dynamicTools = session.hostToolBridge.tools;
661
- }
662
- const result = object(await this.request('thread/start', threadStartParams, session.requestTimeout));
663
- this.validateResponsePolicy(result, session);
664
- this.validateInstructionMetadata(result, session);
665
- const thread = validateThread(result?.thread);
666
- if (typeof thread?.id !== 'string' || !thread.id) {
667
- throw new Error('Codex app-server thread/start returned no thread id');
668
- }
669
- this.registry.save({
670
- sessionKey: session.sessionKey,
671
- threadId: thread.id,
672
- model: session.model,
673
- cwd: session.cwd,
674
- systemPromptFingerprint: this.policyFingerprint(session),
675
- mcpConfigFingerprint: launch.fingerprint,
676
- });
677
- return { threadId: thread.id, bootstrapPending: false };
678
- }
679
- policyFingerprint(session) {
680
- const base = session.policyFingerprint ?? (0, codex_thread_registry_js_1.fingerprintText)(session.systemPrompt);
681
- const tools = session.hostToolBridge?.tools;
682
- if (!tools?.length) {
683
- return base;
684
- }
685
- return (0, codex_thread_registry_js_1.fingerprintText)(`${base}\n${JSON.stringify(tools)}`);
686
- }
687
- validateInstructionMetadata(result, session) {
688
- const sources = result?.instructionSources;
689
- if (!Array.isArray(sources)) {
690
- throw new Error('Codex app-server returned malformed instruction sources');
691
- }
692
- const managedRoots = [session.cwd, this.options.codexHome].map((root) => (0, node_fs_1.realpathSync)(root));
693
- for (const source of sources) {
694
- if (typeof source !== 'string') {
695
- throw new Error('Codex app-server returned malformed instruction source');
696
- }
697
- let path;
698
- try {
699
- path = (0, node_fs_1.realpathSync)((0, node_path_1.resolve)(session.cwd, source));
700
- }
701
- catch (error) {
702
- throw new Error('Codex app-server loaded an instruction source outside managed roots', {
703
- cause: error,
704
- });
705
- }
706
- const allowed = managedRoots.some((root) => {
707
- const childPath = (0, node_path_1.relative)(root, path);
708
- return (childPath === '' ||
709
- (childPath !== '..' && !childPath.startsWith(`..${node_path_1.sep}`) && !(0, node_path_1.isAbsolute)(childPath)));
710
- });
711
- if (!allowed) {
712
- throw new Error('Codex app-server loaded an instruction source outside managed roots');
713
- }
714
- }
715
- }
716
- validateResponsePolicy(result, session) {
717
- if (!result) {
718
- throw new Error('Codex app-server returned a malformed thread response');
719
- }
720
- if (typeof result.modelProvider !== 'string' ||
721
- (result.serviceTier !== null && typeof result.serviceTier !== 'string') ||
722
- !APPROVAL_REVIEWERS.has(String(result.approvalsReviewer)) ||
723
- (result.reasoningEffort !== null && typeof result.reasoningEffort !== 'string')) {
724
- throw new Error('Codex app-server returned malformed thread response metadata');
725
- }
726
- if (typeof result.model !== 'string' || result.model !== session.model) {
727
- throw new Error('Codex app-server response model did not match the requested policy');
728
- }
729
- if (typeof result.cwd !== 'string' || (0, node_path_1.resolve)(result.cwd) !== session.cwd) {
730
- throw new Error('Codex app-server response cwd did not match the requested policy');
731
- }
732
- if (result.approvalPolicy !== 'never') {
733
- throw new Error('Codex app-server response approval policy was not never');
734
- }
735
- const sandbox = object(result.sandbox);
736
- const expectedSandboxType = {
737
- 'read-only': 'readOnly',
738
- 'workspace-write': 'workspaceWrite',
739
- 'danger-full-access': 'dangerFullAccess',
740
- }[session.sandbox];
741
- if (typeof sandbox?.type !== 'string' || sandbox.type !== expectedSandboxType) {
742
- throw new Error('Codex app-server response sandbox did not match the requested policy');
743
- }
744
- if (sandbox.type === 'readOnly' && typeof sandbox.networkAccess !== 'boolean') {
745
- throw new Error('Codex app-server returned a malformed read-only sandbox policy');
746
- }
747
- if (sandbox.type === 'workspaceWrite' &&
748
- (!Array.isArray(sandbox.writableRoots) ||
749
- typeof sandbox.networkAccess !== 'boolean' ||
750
- typeof sandbox.excludeTmpdirEnvVar !== 'boolean' ||
751
- typeof sandbox.excludeSlashTmp !== 'boolean')) {
752
- throw new Error('Codex app-server returned a malformed workspace-write sandbox policy');
753
- }
754
- }
755
- startTurn(threadId, text, callbacks, requestTimeout, hostToolBridge, runTokenBudget) {
756
- return new Promise((resolveTurn, rejectTurn) => {
757
- const abortController = new AbortController();
758
- const timer = setTimeout(() => {
759
- const error = new Error(`Codex app-server turn timed out after ${requestTimeout}ms`);
760
- this.timeoutTurn(threadId, error, requestTimeout);
761
- }, requestTimeout);
762
- timer.unref();
763
- const pendingTurn = {
764
- threadId,
765
- chunks: [],
766
- usage: { input_tokens: 0, output_tokens: 0 },
767
- runTokenBudget,
768
- timer,
769
- requestTimeout,
770
- queuedNotifications: [],
771
- queuedToolRequests: [],
772
- toolCallQueue: Promise.resolve(),
773
- toolCallResults: new Map(),
774
- stoppingCallIds: new Set(),
775
- hostToolBridge,
776
- abortController,
777
- intentionalStop: false,
778
- onDelta: callbacks?.onDelta,
779
- onToolUse: callbacks?.onToolUse,
780
- onToolComplete: callbacks?.onToolComplete,
781
- onSubagentStart: callbacks?.onSubagentStart,
782
- nativeItems: new Map(),
783
- resolve: resolveTurn,
784
- reject: rejectTurn,
785
- };
786
- this.turns.set(threadId, pendingTurn);
787
- this.request('turn/start', {
788
- threadId,
789
- input: [{ type: 'text', text, text_elements: [] }],
790
- }, requestTimeout)
791
- .then((value) => {
792
- const turn = validateTurn(object(value)?.turn, 'turn/start turn');
793
- if (typeof turn?.id !== 'string' || !turn.id) {
794
- this.failTurn(threadId, new Error('Codex app-server turn/start returned no turn id'));
795
- return;
796
- }
797
- const activeTurn = this.turns.get(threadId);
798
- if (activeTurn === pendingTurn) {
799
- activeTurn.turnId = turn.id;
800
- const queued = activeTurn.queuedNotifications.splice(0);
801
- for (const notification of queued) {
802
- this.handleNotification(notification.method, notification.params);
803
- }
804
- const queuedToolRequests = activeTurn.queuedToolRequests.splice(0);
805
- for (const request of queuedToolRequests) {
806
- this.handleDynamicToolRequest(request, activeTurn);
807
- }
808
- }
809
- else if (this.turnStartReconciliations.has(threadId)) {
810
- void this.reconcileAcknowledgedTurn(threadId, turn.id, requestTimeout);
811
- }
812
- })
813
- .catch((error) => {
814
- if (this.turns.get(threadId) === pendingTurn) {
815
- this.failTurn(threadId, this.toError(error));
816
- return;
817
- }
818
- const reconciliation = this.turnStartReconciliations.get(threadId);
819
- if (!reconciliation) {
820
- return;
821
- }
822
- if (error instanceof CodexAppServerRpcError) {
823
- this.completeTurnStartReconciliation(threadId, reconciliation);
824
- }
825
- else if (!reconciliation.recoveryTimer) {
826
- void this.shutdown(this.toError(error)).finally(() => {
827
- this.completeTurnStartReconciliation(threadId, reconciliation);
828
- });
829
- }
830
- });
831
- });
832
- }
833
- async request(method, params, requestTimeout = this.options.requestTimeout) {
834
- for (let attempt = 0;; attempt++) {
835
- try {
836
- return await this.requestOnce(method, params, requestTimeout);
837
- }
838
- catch (error) {
839
- if (!(error instanceof CodexAppServerRpcError) ||
840
- error.code !== OVERLOADED_ERROR_CODE ||
841
- attempt >= OVERLOAD_RETRY_LIMIT - 1) {
842
- throw error;
843
- }
844
- const delay = OVERLOAD_RETRY_BASE_MS * 2 ** attempt + Math.floor(Math.random() * 10);
845
- await new Promise((resolveDelay) => {
846
- const timer = setTimeout(resolveDelay, delay);
847
- timer.unref();
848
- });
849
- }
850
- }
851
- }
852
- requestOnce(method, params, requestTimeout) {
853
- const child = this.child;
854
- if (!child?.stdin.writable) {
855
- return Promise.reject(new Error('Codex app-server stdin is not writable'));
856
- }
857
- const id = ++this.nextId;
858
- return new Promise((resolveRequest, rejectRequest) => {
859
- const timer = setTimeout(() => {
860
- this.pending.delete(id);
861
- const error = new Error(`Codex app-server ${method} timed out after ${requestTimeout}ms`);
862
- const threadId = method === 'turn/start' ? object(params)?.threadId : undefined;
863
- if (typeof threadId === 'string' && threadId) {
864
- const reconciliation = this.getOrCreateTurnStartReconciliation(threadId);
865
- reconciliation.recoveryTimer = setTimeout(() => {
866
- this.lateTurnStarts.delete(id);
867
- void this.shutdown(error).finally(() => {
868
- this.completeTurnStartReconciliation(threadId, reconciliation);
869
- });
870
- }, Math.max(requestTimeout, TURN_START_RECONCILE_GRACE_MS));
871
- reconciliation.recoveryTimer.unref();
872
- this.lateTurnStarts.set(id, { threadId, requestTimeout, reconciliation });
873
- rejectRequest(error);
874
- return;
875
- }
876
- rejectRequest(error);
877
- void this.shutdown(error);
878
- }, requestTimeout);
879
- timer.unref();
880
- this.pending.set(id, { method, timer, resolve: resolveRequest, reject: rejectRequest });
881
- child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`);
882
- });
883
- }
884
- notify(method, params) {
885
- if (!this.child?.stdin.writable) {
886
- throw new Error('Codex app-server stdin is not writable');
887
- }
888
- const message = params === undefined ? { jsonrpc: '2.0', method } : { jsonrpc: '2.0', method, params };
889
- this.child.stdin.write(`${JSON.stringify(message)}\n`);
890
- }
891
- handleLine(child, line) {
892
- if (child !== this.child || !line.trim()) {
893
- return;
894
- }
895
- let message;
896
- try {
897
- const parsed = JSON.parse(line);
898
- const record = object(parsed);
899
- if (!record) {
900
- throw new Error('not an object');
901
- }
902
- message = record;
903
- }
904
- catch {
905
- const error = new Error('Codex app-server emitted malformed JSON');
906
- this.failAll(error);
907
- void this.shutdown(error);
908
- return;
909
- }
910
- // Codex 0.144 accepts JSON-RPC 2.0 requests but omits the `jsonrpc`
911
- // member from its responses and notifications on the stdio wire.
912
- if (message.jsonrpc !== undefined && message.jsonrpc !== '2.0') {
913
- const error = new Error('Codex app-server emitted a malformed protocol message');
914
- this.failAll(error);
915
- void this.shutdown(error);
916
- return;
917
- }
918
- const hasMethod = typeof message.method === 'string';
919
- const hasResult = Object.hasOwn(message, 'result');
920
- const hasError = Object.hasOwn(message, 'error');
921
- const hasRequestId = typeof message.id === 'number' || typeof message.id === 'string';
922
- const serverRequest = hasMethod && hasRequestId && !hasResult && !hasError;
923
- const notification = hasMethod && !hasRequestId && !hasResult && !hasError;
924
- const response = !hasMethod && typeof message.id === 'number' && hasResult !== hasError;
925
- if ([serverRequest, notification, response].filter(Boolean).length !== 1) {
926
- const error = new Error('Codex app-server emitted a malformed protocol message');
927
- this.failAll(error);
928
- void this.shutdown(error);
929
- return;
930
- }
931
- if (typeof message.method === 'string' &&
932
- (typeof message.id === 'number' || typeof message.id === 'string')) {
933
- this.handleServerRequest(child, message.id, message.method, message.params);
934
- return;
935
- }
936
- if (typeof message.id === 'number') {
937
- const lateTurnStart = this.lateTurnStarts.get(message.id);
938
- if (lateTurnStart) {
939
- this.handleLateTurnStartResponse(message.id, lateTurnStart, message);
940
- return;
941
- }
942
- const pending = this.pending.get(message.id);
943
- if (!pending) {
944
- const error = new Error('Codex app-server response id did not match a pending request');
945
- this.failAll(error);
946
- void this.shutdown(error);
947
- return;
948
- }
949
- clearTimeout(pending.timer);
950
- this.pending.delete(message.id);
951
- if (message.error !== undefined) {
952
- const rpcError = object(message.error);
953
- const code = typeof rpcError?.code === 'number' ? rpcError.code : 0;
954
- pending.reject(new CodexAppServerRpcError(code, this.redact(errorMessage(message.error, `${pending.method} failed`))));
955
- }
956
- else if (!Object.hasOwn(message, 'result')) {
957
- pending.reject(new Error(`Codex app-server ${pending.method} returned a malformed response`));
958
- }
959
- else {
960
- pending.resolve(message.result);
961
- }
962
- return;
963
- }
964
- if (typeof message.method === 'string') {
965
- this.handleNotification(message.method, message.params);
966
- }
967
- }
968
- handleNotification(method, params) {
969
- const data = object(params);
970
- if (!data || typeof data.threadId !== 'string') {
971
- return;
972
- }
973
- if (this.handleSubagentNotification(method, data.threadId, data)) {
974
- return;
975
- }
976
- const turn = this.turns.get(data.threadId);
977
- if (!turn) {
978
- return;
979
- }
980
- const completedTurn = method === 'turn/completed' ? object(data.turn) : undefined;
981
- const eventTurnId = typeof data.turnId === 'string'
982
- ? data.turnId
983
- : typeof completedTurn?.id === 'string'
984
- ? completedTurn.id
985
- : undefined;
986
- if (eventTurnId && !turn.turnId) {
987
- turn.queuedNotifications.push({ method, params });
988
- return;
989
- }
990
- if (eventTurnId && eventTurnId !== turn.turnId) {
991
- return;
992
- }
993
- // TG-03/04/05/06: these notifications observe native effects; they are not
994
- // pre-execution hooks. Dynamic/MCP calls retain their existing host bridge.
995
- if (method === 'item/started' || method === 'item/completed') {
996
- if (typeof data.turnId !== 'string' || data.turnId !== turn.turnId) {
997
- return;
998
- }
999
- const item = object(data.item);
1000
- if (!item || typeof item.id !== 'string' || typeof item.type !== 'string') {
1001
- return;
1002
- }
1003
- if (!['commandExecution', 'fileChange', 'collabAgentToolCall'].includes(item.type)) {
1004
- return;
1005
- }
1006
- this.refreshTurnIdleTimeout(turn);
1007
- try {
1008
- let observed = turn.nativeItems.get(item.id);
1009
- if (!observed) {
1010
- observed = { name: item.type, completed: false };
1011
- turn.nativeItems.set(item.id, observed);
1012
- // Persist bounded identity only: command bodies and file diffs can contain secrets.
1013
- turn.onToolUse?.(item.type, { nativeToolUseId: item.id });
1014
- }
1015
- if (method === 'item/completed' && !observed.completed) {
1016
- observed.completed = true;
1017
- const isError = item.status !== 'completed' ||
1018
- (typeof item.exitCode === 'number' && item.exitCode !== 0);
1019
- turn.onToolComplete?.(observed.name, item.id, isError);
1020
- }
1021
- }
1022
- catch (error) {
1023
- this.failTurn(turn.threadId, this.toError(error));
1024
- }
1025
- return;
1026
- }
1027
- if (method === 'item/agentMessage/delta') {
1028
- if (typeof data.turnId !== 'string' || data.turnId !== turn.turnId) {
1029
- return;
1030
- }
1031
- if (typeof data.delta === 'string') {
1032
- this.refreshTurnIdleTimeout(turn);
1033
- turn.chunks.push(data.delta);
1034
- try {
1035
- turn.onDelta?.(data.delta);
1036
- }
1037
- catch (error) {
1038
- this.failTurn(turn.threadId, this.toError(error));
1039
- }
1040
- }
1041
- return;
1042
- }
1043
- if (method === 'thread/tokenUsage/updated') {
1044
- if (typeof data.turnId !== 'string' || data.turnId !== turn.turnId) {
1045
- return;
1046
- }
1047
- const tokenUsage = object(data.tokenUsage);
1048
- const last = object(tokenUsage?.last);
1049
- const total = object(tokenUsage?.total);
1050
- this.refreshTurnIdleTimeout(turn);
1051
- const num = (value) => (typeof value === 'number' ? value : 0);
1052
- if (total) {
1053
- // Turn usage = cumulative-thread delta. The baseline derives from the
1054
- // first total-bearing event (total minus its own call, minus any usage
1055
- // already accumulated from total-less events this turn), so a resumed
1056
- // thread's unseen history is never attributed to this turn, and a
1057
- // multi-call tool-loop turn keeps its earlier calls (recording only
1058
- // `last` undercounted ~5x against the rollout ground truth).
1059
- turn.usageBaseline ??= {
1060
- input: num(total.inputTokens) - num(last?.inputTokens) - turn.usage.input_tokens,
1061
- output: num(total.outputTokens) - num(last?.outputTokens) - turn.usage.output_tokens,
1062
- cached: num(total.cachedInputTokens) -
1063
- num(last?.cachedInputTokens) -
1064
- (turn.usage.cache_read_input_tokens ?? 0),
1065
- };
1066
- // A total below the baseline (compaction/rollback resetting the thread
1067
- // counter) must never write negative usage into the metrics DB.
1068
- const input = num(total.inputTokens) - turn.usageBaseline.input;
1069
- const output = num(total.outputTokens) - turn.usageBaseline.output;
1070
- const cached = num(total.cachedInputTokens) - turn.usageBaseline.cached;
1071
- if ((input < 0 || output < 0 || cached < 0) && !turn.usageShrinkWarned) {
1072
- turn.usageShrinkWarned = true;
1073
- console.warn('[CodexAppServer] cumulative token total shrank below the turn baseline; clamping usage to 0');
1074
- }
1075
- turn.usage = {
1076
- input_tokens: Math.max(0, input),
1077
- output_tokens: Math.max(0, output),
1078
- cache_read_input_tokens: Math.max(0, cached),
1079
- };
1080
- this.enforceTurnBudget(turn.threadId, turn);
1081
- }
1082
- else {
1083
- // No cumulative total on this event: accumulate per-call usage.
1084
- turn.usage = {
1085
- input_tokens: turn.usage.input_tokens + num(last?.inputTokens),
1086
- output_tokens: turn.usage.output_tokens + num(last?.outputTokens),
1087
- cache_read_input_tokens: (turn.usage.cache_read_input_tokens ?? 0) + num(last?.cachedInputTokens),
1088
- };
1089
- this.enforceTurnBudget(turn.threadId, turn);
1090
- }
1091
- return;
1092
- }
1093
- if (method !== 'turn/completed') {
1094
- return;
1095
- }
1096
- const completed = completedTurn;
1097
- if (!completed ||
1098
- typeof completed.id !== 'string' ||
1099
- (turn.turnId && completed.id !== turn.turnId))
1100
- return;
1101
- const status = completed.status;
1102
- if (status === 'inProgress') {
1103
- return;
1104
- }
1105
- try {
1106
- validateTurn(completed, 'turn/completed turn');
1107
- }
1108
- catch (error) {
1109
- this.failTurn(turn.threadId, this.toError(error));
1110
- return;
1111
- }
1112
- if (turn.abortError) {
1113
- this.failTurn(turn.threadId, turn.abortError);
1114
- return;
1115
- }
1116
- if (status === 'failed') {
1117
- this.failTurn(turn.threadId, new Error(this.redact(errorMessage(completed.error, 'Codex app-server turn failed'))));
1118
- return;
1119
- }
1120
- if (status === 'interrupted') {
1121
- if (turn.abortError) {
1122
- this.failTurn(turn.threadId, turn.abortError);
1123
- }
1124
- else if (turn.intentionalStop) {
1125
- this.resolveTurn(turn);
1126
- }
1127
- else {
1128
- this.failTurn(turn.threadId, new Error('Codex app-server turn was interrupted'));
1129
- }
1130
- return;
1131
- }
1132
- if (status !== 'completed') {
1133
- this.failTurn(turn.threadId, new Error(`Codex app-server returned unknown turn status: ${String(status)}`));
1134
- return;
1135
- }
1136
- this.resolveTurn(turn);
1137
- }
1138
- resolveTurn(turn) {
1139
- if (this.turns.get(turn.threadId) !== turn) {
1140
- return;
1141
- }
1142
- this.turns.delete(turn.threadId);
1143
- clearTimeout(turn.timer);
1144
- this.clearTurnCallbacks(turn);
1145
- turn.resolve({
1146
- response: turn.chunks.join(''),
1147
- usage: turn.usage,
1148
- session_id: turn.threadId,
1149
- toolUseBlocks: undefined,
1150
- hasToolUse: false,
1151
- });
1152
- }
1153
- // ─── Codex-native subagents ───────────────────────────────────────────────
1154
- //
1155
- // Codex announces a child on the PARENT thread as a `subAgentActivity` item and then
1156
- // drives the child on its OWN thread id, which outlives the parent turn. Nothing here
1157
- // blocks a run. A child NEVER inherits the parent turn's bridge: the parent's envelope
1158
- // expires with the parent's wall and the child cannot renew it, so a child that
1159
- // inherited it would lose every tool mid-run and still report "done". The host issues
1160
- // the child its own authority instead (`createSubagentBridge`), or the child has none
1161
- // and its calls are refused loudly.
1162
- /** Returns true when this notification belongs to the subagent surface and was consumed. */
1163
- handleSubagentNotification(method, threadId, data) {
1164
- if (method === 'item/started' || method === 'item/completed') {
1165
- const item = object(data.item);
1166
- if (item?.type === 'subAgentActivity') {
1167
- // Only a thread this process actually drives may announce children.
1168
- if (!this.subagents.has(threadId) && !this.threadContexts.has(threadId)) {
1169
- return false;
1170
- }
1171
- if (item.kind === 'started') {
1172
- this.registerSubagent(threadId, item);
1173
- }
1174
- else if (item.kind === 'completed') {
1175
- this.observeParentSideCompletion(threadId, item);
1176
- }
1177
- return true;
1178
- }
1179
- const child = this.subagents.get(threadId);
1180
- if (!child) {
1181
- return false;
1182
- }
1183
- this.refreshParentTurnIdleTimeout(child);
1184
- if (method === 'item/completed' &&
1185
- item?.type === 'agentMessage' &&
1186
- item.phase === 'final_answer' &&
1187
- typeof item.text === 'string') {
1188
- child.finalText = item.text.slice(0, SUBAGENT_FINAL_TEXT_LIMIT);
1189
- }
1190
- return true;
1191
- }
1192
- const child = this.subagents.get(threadId);
1193
- if (!child) {
1194
- return false;
1195
- }
1196
- this.refreshParentTurnIdleTimeout(child);
1197
- if (method !== 'turn/completed') {
1198
- return true;
1199
- }
1200
- const completed = object(data.turn);
1201
- const status = completed?.status;
1202
- if (status === 'inProgress') {
1203
- return true;
1204
- }
1205
- if (status !== 'completed' && status !== 'failed' && status !== 'interrupted') {
1206
- return true;
1207
- }
1208
- if (!child.finalText) {
1209
- child.finalText = this.subagentFinalText(completed?.items);
1210
- }
1211
- // The child's OWN turn/completed is the only completing event: the parent-side
1212
- // announcement carries neither status nor result.
1213
- this.finishSubagent(threadId, status, status === 'failed'
1214
- ? this.redact(errorMessage(completed?.error, 'Codex app-server subagent turn failed'))
1215
- : undefined);
1216
- return true;
1217
- }
1218
- subagentFinalText(items) {
1219
- if (!Array.isArray(items)) {
1220
- return '';
1221
- }
1222
- let text = '';
1223
- for (const entry of items) {
1224
- const item = object(entry);
1225
- if (item?.type === 'agentMessage' && typeof item.text === 'string') {
1226
- text = item.text;
1227
- }
1228
- }
1229
- return text.slice(0, SUBAGENT_FINAL_TEXT_LIMIT);
1230
- }
1231
- /** A working child keeps the parent's idle timeout alive (the parent may be in wait_agent). */
1232
- refreshParentTurnIdleTimeout(child) {
1233
- const parentTurn = this.turns.get(child.parentThreadId);
1234
- if (parentTurn) {
1235
- this.refreshTurnIdleTimeout(parentTurn);
1236
- }
1237
- }
1238
- /** Drop every thread context this session left behind on a previous thread id. */
1239
- pruneThreadContexts(sessionKey, currentThreadId) {
1240
- for (const [threadId, context] of this.threadContexts) {
1241
- if (context.sessionKey === sessionKey && threadId !== currentThreadId) {
1242
- this.threadContexts.delete(threadId);
1243
- }
1244
- }
1245
- }
1246
- knownThreadIds() {
1247
- const ids = new Set(this.threadContexts.keys());
1248
- for (const state of this.sessions.values()) {
1249
- if (state.threadId) {
1250
- ids.add(state.threadId);
1251
- }
1252
- }
1253
- for (const threadId of this.turns.keys()) {
1254
- ids.add(threadId);
1255
- }
1256
- return ids;
1257
- }
1258
- registerSubagent(parentThreadId, item) {
1259
- const agentThreadId = typeof item.agentThreadId === 'string' ? item.agentThreadId : '';
1260
- if (!agentThreadId || this.subagents.has(agentThreadId)) {
1261
- // The same `started` announcement arrives twice (item/started + item/completed views).
1262
- return;
1263
- }
1264
- if (this.finishedSubagents.has(agentThreadId)) {
1265
- // The second view of that announcement lost the race with the child's own
1266
- // turn/completed. Re-registering would resurrect a finished child.
1267
- console.warn(`[CodexAppServer] subagent announcement ignored: thread=${agentThreadId} already finished`);
1268
- return;
1269
- }
1270
- // A child may never claim a thread this process already drives: that would let one
1271
- // session's announcement capture another session's live parent thread.
1272
- if (this.knownThreadIds().has(agentThreadId)) {
1273
- console.warn(`[CodexAppServer] subagent announcement refused: thread=${agentThreadId} is a live thread`);
1274
- return;
1275
- }
1276
- // A grandchild's session comes from the child that announced it.
1277
- const parent = this.subagents.get(parentThreadId) ?? this.threadContexts.get(parentThreadId);
1278
- if (!parent) {
1279
- return;
1280
- }
1281
- const agentPath = typeof item.agentPath === 'string' ? item.agentPath : '';
1282
- // Observed admission: tell the PARENT'S live turn that this run handed work to a
1283
- // child. Nothing else on the item stream carries that fact - on codex-cli 0.153.4
1284
- // a spawn surfaces ONLY as `subAgentActivity`, which this handler consumes before
1285
- // the native-item path. Never routed through onToolUse (effect ledger, see
1286
- // PromptCallbacks.onSubagentStart).
1287
- const parentTurn = this.turns.get(parentThreadId);
1288
- if (parentTurn?.onSubagentStart) {
1289
- const itemId = typeof item.id === 'string' ? item.id : '';
1290
- try {
1291
- parentTurn.onSubagentStart({ agentThreadId, agentPath, itemId });
1292
- }
1293
- catch (error) {
1294
- console.warn(`[CodexAppServer] onSubagentStart callback failed: ${this.toError(error).message}`);
1295
- }
1296
- }
1297
- const factory = this.options.createSubagentBridge;
1298
- const child = {
1299
- parentThreadId,
1300
- sessionKey: parent.sessionKey,
1301
- agentPath,
1302
- onToolUse: parent.onToolUse,
1303
- onToolComplete: parent.onToolComplete,
1304
- finalText: '',
1305
- startedAt: Date.now(),
1306
- toolCallQueue: Promise.resolve(),
1307
- toolCallResults: new Map(),
1308
- stoppingCallIds: new Set(),
1309
- abortController: new AbortController(),
1310
- authorityWarned: false,
1311
- authority: factory
1312
- ? factory({
1313
- sessionKey: parent.sessionKey,
1314
- parentThreadId,
1315
- agentThreadId,
1316
- agentPath,
1317
- })
1318
- .then((authority) => authority ?? null)
1319
- .catch((error) => {
1320
- console.warn(`[CodexAppServer] subagent authority factory failed thread=${agentThreadId}: ${this.toError(error).message}`);
1321
- return null;
1322
- })
1323
- : Promise.resolve(null),
1324
- };
1325
- child.ttlTimer = setTimeout(() => {
1326
- child.ttlTimer = undefined;
1327
- this.finishSubagent(agentThreadId, 'failed', 'subagent produced no completion');
1328
- }, this.options.subagentTtlMs ?? SUBAGENT_TTL_MS);
1329
- child.ttlTimer.unref();
1330
- this.subagents.set(agentThreadId, child);
1331
- console.log(`[CodexAppServer] subagent started path=${agentPath} thread=${agentThreadId}`);
1332
- this.emitSubagentEvent({
1333
- kind: 'started',
1334
- sessionKey: parent.sessionKey,
1335
- parentThreadId,
1336
- agentThreadId,
1337
- agentPath,
1338
- });
1339
- }
1340
- /**
1341
- * The parent says a child finished. That is an announcement, not a result: it can win
1342
- * the race against the child's own `turn/completed`, which is what carries status and
1343
- * final text. Wait a bounded grace for the real event, then report `unknown`.
1344
- */
1345
- observeParentSideCompletion(announcingThreadId, item) {
1346
- const agentThreadId = typeof item.agentThreadId === 'string' ? item.agentThreadId : '';
1347
- const child = agentThreadId ? this.subagents.get(agentThreadId) : undefined;
1348
- if (!child) {
1349
- return;
1350
- }
1351
- if (child.parentThreadId !== announcingThreadId) {
1352
- console.warn(`[CodexAppServer] subagent completion refused: thread=${announcingThreadId} does not own ${agentThreadId}`);
1353
- return;
1354
- }
1355
- if (child.graceTimer) {
1356
- return;
1357
- }
1358
- child.graceTimer = setTimeout(() => {
1359
- child.graceTimer = undefined;
1360
- console.warn(`[CodexAppServer] subagent completion unconfirmed path=${child.agentPath} thread=${agentThreadId}`);
1361
- this.finishSubagent(agentThreadId, 'unknown');
1362
- }, this.options.subagentGraceMs ?? SUBAGENT_COMPLETION_GRACE_MS);
1363
- child.graceTimer.unref();
1364
- }
1365
- /**
1366
- * Emits exactly one completion per child thread and releases its authority with the
1367
- * same terminal status. Grandchildren keep their own entries.
1368
- */
1369
- finishSubagent(agentThreadId, status, error) {
1370
- const child = this.subagents.get(agentThreadId);
1371
- if (!child) {
1372
- return;
1373
- }
1374
- this.subagents.delete(agentThreadId);
1375
- this.rememberFinishedSubagent(agentThreadId);
1376
- this.clearSubagentTimers(child);
1377
- console.log(`[CodexAppServer] subagent completed status=${status} path=${child.agentPath} thread=${agentThreadId}`);
1378
- const finalText = child.finalText ? this.redact(child.finalText) : '';
1379
- this.emitSubagentEvent({
1380
- kind: 'completed',
1381
- sessionKey: child.sessionKey,
1382
- parentThreadId: child.parentThreadId,
1383
- agentThreadId,
1384
- agentPath: child.agentPath,
1385
- status,
1386
- ...(finalText ? { finalText } : {}),
1387
- ...(error ? { error } : {}),
1388
- });
1389
- void child.authority
1390
- .then(async (authority) => {
1391
- if (!authority) {
1392
- return;
1393
- }
1394
- await authority.release({ status, ...(error ? { error } : {}) });
1395
- })
1396
- .catch((releaseError) => {
1397
- console.warn(`[CodexAppServer] subagent authority release failed thread=${agentThreadId}: ${this.toError(releaseError).message}`);
1398
- });
1399
- }
1400
- /** FIFO-bounded identity of finished children; the oldest id is forgotten first. */
1401
- rememberFinishedSubagent(agentThreadId) {
1402
- this.finishedSubagents.add(agentThreadId);
1403
- while (this.finishedSubagents.size > MAX_FINISHED_SUBAGENTS) {
1404
- const oldest = this.finishedSubagents.values().next().value;
1405
- if (oldest === undefined) {
1406
- return;
1407
- }
1408
- this.finishedSubagents.delete(oldest);
1409
- }
1410
- }
1411
- clearSubagentTimers(child) {
1412
- if (child.ttlTimer) {
1413
- clearTimeout(child.ttlTimer);
1414
- child.ttlTimer = undefined;
1415
- }
1416
- if (child.graceTimer) {
1417
- clearTimeout(child.graceTimer);
1418
- child.graceTimer = undefined;
1419
- }
1420
- }
1421
- emitSubagentEvent(event) {
1422
- const emit = this.options.onSubagentEvent;
1423
- if (!emit) {
1424
- return;
1425
- }
1426
- try {
1427
- emit(event);
1428
- }
1429
- catch (error) {
1430
- console.warn(`[CodexAppServer] subagent event listener failed: ${this.toError(error).message}`);
1431
- }
1432
- }
1433
- /** Every live child is reported interrupted and its authority released. */
1434
- terminateSubagents(reason) {
1435
- const safe = this.toError(reason);
1436
- for (const agentThreadId of [...this.subagents.keys()]) {
1437
- const child = this.subagents.get(agentThreadId);
1438
- if (!child) {
1439
- continue;
1440
- }
1441
- child.abortController.abort(safe);
1442
- this.finishSubagent(agentThreadId, 'interrupted', safe.message);
1443
- }
1444
- }
1445
- /** A reset/restart drops the thread's context and interrupts its children. */
1446
- discardSessionThreadState(sessionKey, reason) {
1447
- const threadId = this.sessions.get(sessionKey)?.threadId;
1448
- if (threadId) {
1449
- this.threadContexts.delete(threadId);
1450
- }
1451
- for (const agentThreadId of [...this.subagents.keys()]) {
1452
- const child = this.subagents.get(agentThreadId);
1453
- if (!child || child.sessionKey !== sessionKey) {
1454
- continue;
1455
- }
1456
- child.abortController.abort(new Error(`Codex app-server ${reason}`));
1457
- this.finishSubagent(agentThreadId, 'interrupted', reason);
1458
- }
1459
- }
1460
- handleSubagentToolRequest(request, agentThreadId, child, data) {
1461
- this.refreshParentTurnIdleTimeout(child);
1462
- // The child's authority is host-issued and asynchronous; its calls queue until it
1463
- // resolves rather than falling back to anything the parent held.
1464
- void child.authority.then((authority) => {
1465
- try {
1466
- const turnId = this.requiredToolString(data, 'turnId');
1467
- const callId = this.requiredToolString(data, 'callId');
1468
- const tool = this.requiredToolString(data, 'tool');
1469
- if (data.namespace !== null && typeof data.namespace !== 'string') {
1470
- throw new Error('Codex app-server tool call namespace must be null or a string');
1471
- }
1472
- const input = object(data.arguments);
1473
- if (!input) {
1474
- throw new Error('Codex app-server tool call arguments must be an object');
1475
- }
1476
- if (!authority) {
1477
- if (!child.authorityWarned) {
1478
- child.authorityWarned = true;
1479
- console.warn(`[CodexAppServer] ${SUBAGENT_AUTHORITY_UNAVAILABLE} path=${child.agentPath} thread=${agentThreadId}`);
1480
- }
1481
- this.replyToolError(request, `${SUBAGENT_AUTHORITY_UNAVAILABLE}: ${tool} was refused`);
1482
- return;
1483
- }
1484
- const bridge = authority.bridge;
1485
- if (!bridge.tools.some((definition) => definition.name === tool)) {
1486
- throw new Error(`Codex app-server tool call ${tool} was not advertised`);
1487
- }
1488
- this.dispatchSubagentToolCall(request, agentThreadId, child, bridge, {
1489
- turnId,
1490
- callId,
1491
- tool,
1492
- namespace: data.namespace ?? null,
1493
- input,
1494
- });
1495
- }
1496
- catch (error) {
1497
- // A child's protocol error is reported to the child only: the parent turn it was
1498
- // spawned from may already have resolved, and there is nothing here to fail.
1499
- this.replyToolError(request, this.toError(error).message);
1500
- }
1501
- });
1502
- }
1503
- dispatchSubagentToolCall(request, agentThreadId, child, bridge, call) {
1504
- const { turnId, callId, tool, namespace, input } = call;
1505
- const identity = JSON.stringify(stableJson({ threadId: agentThreadId, turnId, tool, namespace, arguments: input }));
1506
- const existing = child.toolCallResults.get(callId);
1507
- if (existing && existing.identity !== identity) {
1508
- throw new Error(`Codex app-server callId ${callId} had a conflicting request`);
1509
- }
1510
- let execution = existing?.execution;
1511
- if (!execution) {
1512
- execution = child.toolCallQueue
1513
- .then(async () => {
1514
- if (!this.isSubagentToolActive(request, agentThreadId, child)) {
1515
- return {
1516
- result: this.toolResult(false, 'Codex app-server tool call is no longer active'),
1517
- stop: false,
1518
- abortError: undefined,
1519
- };
1520
- }
1521
- try {
1522
- child.onToolUse?.(tool, {
1523
- nativeToolUseId: callId,
1524
- subagentThreadId: agentThreadId,
1525
- agentPath: child.agentPath,
1526
- });
1527
- }
1528
- catch (error) {
1529
- console.warn(`[CodexAppServer] subagent onToolUse failed: ${this.toError(error).message}`);
1530
- }
1531
- let result;
1532
- try {
1533
- result = await bridge.execute({
1534
- callId,
1535
- name: tool,
1536
- input,
1537
- signal: child.abortController.signal,
1538
- });
1539
- }
1540
- catch (error) {
1541
- result = { content: this.toError(error).message, isError: true };
1542
- }
1543
- const resultData = object(result);
1544
- if (!resultData ||
1545
- typeof resultData.content !== 'string' ||
1546
- typeof resultData.isError !== 'boolean') {
1547
- this.reportSubagentToolComplete(child, tool, callId, true);
1548
- return {
1549
- result: this.toolResult(false, 'Host tool returned a malformed result'),
1550
- stop: false,
1551
- abortError: undefined,
1552
- };
1553
- }
1554
- this.reportSubagentToolComplete(child, tool, callId, resultData.isError);
1555
- if (resultData.isError && resultData.content.includes(ENVELOPE_EXPIRED_MARKER)) {
1556
- // Expired authority is named, never silently downgraded to a plain failure:
1557
- // a child whose grant ran out must not read as work that merely did not apply.
1558
- return {
1559
- result: this.toolResult(false, `${SUBAGENT_AUTHORITY_EXPIRED}: ${resultData.content}`),
1560
- stop: false,
1561
- abortError: undefined,
1562
- };
1563
- }
1564
- return {
1565
- result: this.toolResult(!resultData.isError, resultData.content),
1566
- stop: resultData.stop === true || resultData.abort === true,
1567
- abortError: undefined,
1568
- };
1569
- })
1570
- .catch((error) => ({
1571
- result: this.toolResult(false, this.toError(error).message),
1572
- stop: false,
1573
- abortError: undefined,
1574
- }));
1575
- child.toolCallResults.set(callId, { identity, execution });
1576
- child.toolCallQueue = execution.then(() => undefined, () => undefined);
1577
- }
1578
- void execution.then(({ result, stop }) => {
1579
- if (!this.isSubagentToolActive(request, agentThreadId, child)) {
1580
- if (this.child === request.child) {
1581
- this.replyToolError(request, 'Codex app-server tool call is no longer active');
1582
- }
1583
- return;
1584
- }
1585
- this.reply(request.child, { jsonrpc: '2.0', id: request.id, result });
1586
- if (stop && !child.stoppingCallIds.has(callId)) {
1587
- child.stoppingCallIds.add(callId);
1588
- child.abortController.abort(new Error('Codex app-server subagent tool stopped the run'));
1589
- void this.request('turn/interrupt', { threadId: agentThreadId, turnId }).catch((error) => console.warn(`[CodexAppServer] subagent interrupt failed: ${this.toError(error).message}`));
1590
- }
1591
- });
1592
- }
1593
- reportSubagentToolComplete(child, tool, callId, isError) {
1594
- try {
1595
- child.onToolComplete?.(tool, callId, isError);
1596
- }
1597
- catch (error) {
1598
- console.warn(`[CodexAppServer] subagent onToolComplete failed: ${this.toError(error).message}`);
1599
- }
1600
- }
1601
- isSubagentToolActive(request, agentThreadId, child) {
1602
- return (this.child === request.child &&
1603
- this.subagents.get(agentThreadId) === child &&
1604
- !child.abortController.signal.aborted);
1605
- }
1606
- handleServerRequest(child, id, method, params) {
1607
- if (method === 'item/tool/call') {
1608
- this.handleDynamicToolRequest({ child, id, params });
1609
- return;
1610
- }
1611
- const bodies = {
1612
- 'item/tool/requestUserInput': { answers: {} },
1613
- 'mcpServer/elicitation/request': { action: 'decline', content: null, _meta: null },
1614
- 'item/commandExecution/requestApproval': { decision: 'decline' },
1615
- 'item/fileChange/requestApproval': { decision: 'decline' },
1616
- 'item/permissions/requestApproval': {
1617
- permissions: {},
1618
- scope: 'turn',
1619
- strictAutoReview: true,
1620
- },
1621
- applyPatchApproval: { decision: 'denied' },
1622
- execCommandApproval: { decision: 'denied' },
1623
- };
1624
- if (Object.hasOwn(bodies, method)) {
1625
- this.reply(child, { jsonrpc: '2.0', id, result: bodies[method] });
1626
- }
1627
- else {
1628
- this.reply(child, {
1629
- jsonrpc: '2.0',
1630
- id,
1631
- error: { code: -32601, message: `Unsupported app-server request: ${method}` },
1632
- });
1633
- }
1634
- }
1635
- handleDynamicToolRequest(request, expectedTurn) {
1636
- const data = object(request.params);
1637
- const threadId = typeof data?.threadId === 'string' ? data.threadId : undefined;
1638
- const turn = threadId ? this.turns.get(threadId) : undefined;
1639
- if (data && threadId && !turn && !expectedTurn) {
1640
- // A Codex-native child calls on ITS OWN thread id, which never holds a PendingTurn.
1641
- const child = this.subagents.get(threadId);
1642
- if (child) {
1643
- this.handleSubagentToolRequest(request, threadId, child, data);
1644
- return;
1645
- }
1646
- }
1647
- if (!data || !turn || !turn.hostToolBridge || (expectedTurn && turn !== expectedTurn)) {
1648
- this.replyDisabledTool(request);
1649
- return;
1650
- }
1651
- try {
1652
- const turnId = this.requiredToolString(data, 'turnId');
1653
- const callId = this.requiredToolString(data, 'callId');
1654
- const tool = this.requiredToolString(data, 'tool');
1655
- if (data.namespace !== null && typeof data.namespace !== 'string') {
1656
- throw new Error('Codex app-server tool call namespace must be null or a string');
1657
- }
1658
- const input = object(data.arguments);
1659
- if (!input) {
1660
- throw new Error('Codex app-server tool call arguments must be an object');
1661
- }
1662
- if (!turn.hostToolBridge.tools.some((definition) => definition.name === tool)) {
1663
- throw new Error(`Codex app-server tool call ${tool} was not advertised`);
1664
- }
1665
- if (!turn.turnId) {
1666
- turn.queuedToolRequests.push(request);
1667
- return;
1668
- }
1669
- if (turnId !== turn.turnId) {
1670
- this.failToolProtocol(request, turn, new Error('Codex app-server tool call did not match the active turn'));
1671
- return;
1672
- }
1673
- this.refreshTurnIdleTimeout(turn);
1674
- this.dispatchDynamicToolCall(request, turn, callId, tool, data.namespace, input);
1675
- }
1676
- catch (error) {
1677
- this.failToolProtocol(request, turn, this.toError(error));
1678
- }
1679
- }
1680
- failToolProtocol(request, turn, error) {
1681
- const failure = this.toError(error);
1682
- this.replyToolError(request, failure.message);
1683
- this.failTurn(turn.threadId, failure);
1684
- if (this.child === request.child && !this.shutdownPromise) {
1685
- void this.shutdown(failure);
1686
- }
1687
- }
1688
- requiredToolString(data, field) {
1689
- const value = data[field];
1690
- if (typeof value !== 'string' || !value) {
1691
- throw new Error(`Codex app-server tool call ${field} must be a string`);
1692
- }
1693
- return value;
1694
- }
1695
- dispatchDynamicToolCall(request, turn, callId, tool, namespace, input) {
1696
- const identity = JSON.stringify(stableJson({
1697
- threadId: turn.threadId,
1698
- turnId: turn.turnId,
1699
- tool,
1700
- namespace,
1701
- arguments: input,
1702
- }));
1703
- const existing = turn.toolCallResults.get(callId);
1704
- if (existing && existing.identity !== identity) {
1705
- throw new Error(`Codex app-server callId ${callId} had a conflicting request`);
1706
- }
1707
- let execution = existing?.execution;
1708
- if (!execution) {
1709
- const bridge = turn.hostToolBridge;
1710
- if (!bridge) {
1711
- this.replyDisabledTool(request);
1712
- return;
1713
- }
1714
- execution = turn.toolCallQueue
1715
- .then(async () => {
1716
- if (!this.isToolTurnActive(request, turn)) {
1717
- return {
1718
- result: this.toolResult(false, 'Codex app-server tool call is no longer active'),
1719
- stop: false,
1720
- abortError: undefined,
1721
- };
1722
- }
1723
- let result;
1724
- try {
1725
- result = await bridge.execute({
1726
- callId,
1727
- name: tool,
1728
- input,
1729
- signal: turn.abortController.signal,
1730
- });
1731
- }
1732
- catch (error) {
1733
- result = { content: this.toError(error).message, isError: true };
1734
- }
1735
- const resultData = object(result);
1736
- if (!resultData ||
1737
- typeof resultData.content !== 'string' ||
1738
- typeof resultData.isError !== 'boolean') {
1739
- return {
1740
- result: this.toolResult(false, 'Host tool returned a malformed result'),
1741
- stop: false,
1742
- abortError: undefined,
1743
- };
1744
- }
1745
- const abortError = resultData.abort === true && resultData.isError
1746
- ? (0, model_runner_js_1.isHostToolTerminalCode)(resultData.terminalCode)
1747
- ? new model_runner_js_1.HostToolTerminalError(resultData.terminalCode, resultData.content)
1748
- : new Error(resultData.content)
1749
- : undefined;
1750
- if (abortError instanceof model_runner_js_1.HostToolTerminalError) {
1751
- turn.settledTerminalError ??= abortError;
1752
- }
1753
- return {
1754
- result: this.toolResult(!resultData.isError, resultData.content),
1755
- stop: resultData.stop === true && !resultData.isError,
1756
- abortError,
1757
- };
1758
- })
1759
- .catch((error) => ({
1760
- result: this.toolResult(false, this.toError(error).message),
1761
- stop: false,
1762
- abortError: undefined,
1763
- }));
1764
- turn.toolCallResults.set(callId, { identity, execution });
1765
- turn.toolCallQueue = execution.then(() => undefined, () => undefined);
1766
- }
1767
- void execution.then(({ result, stop, abortError }) => {
1768
- if (!this.isToolTurnActive(request, turn)) {
1769
- if (this.child === request.child) {
1770
- this.replyToolError(request, 'Codex app-server tool call is no longer active');
1771
- }
1772
- return;
1773
- }
1774
- this.refreshTurnIdleTimeout(turn);
1775
- this.reply(request.child, { jsonrpc: '2.0', id: request.id, result });
1776
- if (abortError && !turn.stoppingCallIds.has(callId)) {
1777
- turn.stoppingCallIds.add(callId);
1778
- turn.abortError = abortError;
1779
- void this.request('turn/interrupt', { threadId: turn.threadId, turnId: turn.turnId }).catch((error) => this.failTurn(turn.threadId, this.toError(error)));
1780
- }
1781
- else if (stop && !turn.stoppingCallIds.has(callId)) {
1782
- turn.stoppingCallIds.add(callId);
1783
- turn.intentionalStop = true;
1784
- void this.request('turn/interrupt', { threadId: turn.threadId, turnId: turn.turnId }).catch((error) => this.failTurn(turn.threadId, this.toError(error)));
1785
- }
1786
- });
1787
- }
1788
- isToolTurnActive(request, turn) {
1789
- return (this.child === request.child &&
1790
- this.turns.get(turn.threadId) === turn &&
1791
- !turn.intentionalStop &&
1792
- !turn.abortError &&
1793
- !turn.abortController.signal.aborted);
1794
- }
1795
- toolResult(success, content) {
1796
- return { success, contentItems: [{ type: 'inputText', text: content }] };
1797
- }
1798
- replyDisabledTool(request) {
1799
- this.reply(request.child, {
1800
- jsonrpc: '2.0',
1801
- id: request.id,
1802
- result: this.toolResult(false, 'Native app-server tools are disabled by MAMA'),
1803
- });
1804
- }
1805
- replyToolError(request, message) {
1806
- this.reply(request.child, {
1807
- jsonrpc: '2.0',
1808
- id: request.id,
1809
- error: { code: -32602, message },
1810
- });
1811
- }
1812
- reply(child, message) {
1813
- if (child.stdin.writable) {
1814
- child.stdin.write(`${JSON.stringify(message)}\n`);
1815
- }
1816
- }
1817
- handleStderr(line) {
1818
- this.stderrTail = `${this.stderrTail}${this.redact(line)}\n`.slice(-STDERR_LIMIT);
1819
- }
1820
- redact(value) {
1821
- let result = value;
1822
- for (const secret of this.secrets) {
1823
- result = result.split(secret).join('[REDACTED]');
1824
- }
1825
- return result;
1826
- }
1827
- toError(error) {
1828
- if (error instanceof model_runner_js_1.HostToolTerminalError) {
1829
- return new model_runner_js_1.HostToolTerminalError(error.terminalCode, this.redact(error.message));
1830
- }
1831
- return error instanceof Error
1832
- ? new Error(this.redact(error.message))
1833
- : new Error(this.redact(String(error)));
1834
- }
1835
- refreshTurnIdleTimeout(turn) {
1836
- if (this.turns.get(turn.threadId) !== turn) {
1837
- return;
1838
- }
1839
- clearTimeout(turn.timer);
1840
- turn.timer = setTimeout(() => {
1841
- const error = new Error(`Codex app-server turn timed out after ${turn.requestTimeout}ms without progress`);
1842
- this.timeoutTurn(turn.threadId, error, turn.requestTimeout);
1843
- }, turn.requestTimeout);
1844
- turn.timer.unref();
1845
- }
1846
- failTurn(threadId, error) {
1847
- const turn = this.turns.get(threadId);
1848
- if (!turn) {
1849
- return;
1850
- }
1851
- this.turns.delete(threadId);
1852
- clearTimeout(turn.timer);
1853
- turn.abortController.abort(error);
1854
- turn.queuedNotifications.length = 0;
1855
- turn.queuedToolRequests.length = 0;
1856
- const safe = this.toError(error);
1857
- // A gateway mutation that cannot be interrupted must settle before the
1858
- // caller sees failure. This prevents retries from racing a late mutation.
1859
- void turn.toolCallQueue.finally(() => {
1860
- this.clearTurnCallbacks(turn);
1861
- const terminalError = turn.settledTerminalError ??
1862
- (turn.abortError instanceof model_runner_js_1.HostToolTerminalError ? turn.abortError : undefined);
1863
- turn.reject(this.toError(terminalError ?? safe));
1864
- });
1865
- }
1866
- /** Interrupt a turn whose counted usage crossed its run budget; the loop reports stoppedBy. */
1867
- enforceTurnBudget(threadId, turn) {
1868
- const budget = turn.runTokenBudget ?? 0;
1869
- if (budget <= 0 || turn.budgetStopped) {
1870
- return;
1871
- }
1872
- // Codex reports inputTokens INCLUSIVE of cachedInputTokens (OpenAI usage semantics),
1873
- // so cached is not added again: 0.44.0 counted a 2.8M wiki turn as 5.5M.
1874
- const counted = turn.usage.input_tokens + turn.usage.output_tokens;
1875
- if (counted < budget) {
1876
- return;
1877
- }
1878
- turn.budgetStopped = true;
1879
- const error = new Error(`run budget stop: ${counted} >= ${budget} counted tokens inside one turn`);
1880
- error.code = 'RUN_BUDGET_STOP';
1881
- // The interrupted turn's usage rides on the error: the loop's success path never
1882
- // runs for it, and the most expensive run of the day must not count as zero.
1883
- error.usage = { ...turn.usage };
1884
- this.timeoutTurn(threadId, error, DEFAULT_TIMEOUT);
1885
- }
1886
- timeoutTurn(threadId, error, requestTimeout) {
1887
- const turn = this.turns.get(threadId);
1888
- if (!turn) {
1889
- return;
1890
- }
1891
- const turnId = turn.turnId;
1892
- if (!turnId) {
1893
- this.getOrCreateTurnStartReconciliation(threadId);
1894
- }
1895
- this.failTurn(threadId, error);
1896
- if (!turnId) {
1897
- return;
1898
- }
1899
- void this.request('turn/interrupt', { threadId, turnId }, requestTimeout).catch((interruptError) => {
1900
- if (this.child && !this.shutdownPromise) {
1901
- void this.shutdown(this.toError(interruptError));
1902
- }
1903
- });
1904
- }
1905
- getOrCreateTurnStartReconciliation(threadId) {
1906
- const existing = this.turnStartReconciliations.get(threadId);
1907
- if (existing) {
1908
- return existing;
1909
- }
1910
- let resolveReconciliation;
1911
- const promise = new Promise((resolvePromise) => {
1912
- resolveReconciliation = resolvePromise;
1913
- });
1914
- const reconciliation = {
1915
- promise,
1916
- resolve: () => resolveReconciliation?.(),
1917
- };
1918
- this.turnStartReconciliations.set(threadId, reconciliation);
1919
- return reconciliation;
1920
- }
1921
- completeTurnStartReconciliation(threadId, reconciliation) {
1922
- if (this.turnStartReconciliations.get(threadId) !== reconciliation) {
1923
- return;
1924
- }
1925
- if (reconciliation.recoveryTimer) {
1926
- clearTimeout(reconciliation.recoveryTimer);
1927
- reconciliation.recoveryTimer = undefined;
1928
- }
1929
- this.turnStartReconciliations.delete(threadId);
1930
- reconciliation.resolve();
1931
- }
1932
- async reconcileAcknowledgedTurn(threadId, turnId, requestTimeout) {
1933
- const reconciliation = this.turnStartReconciliations.get(threadId);
1934
- if (!reconciliation) {
1935
- return;
1936
- }
1937
- try {
1938
- await this.request('turn/interrupt', { threadId, turnId }, requestTimeout);
1939
- this.completeTurnStartReconciliation(threadId, reconciliation);
1940
- }
1941
- catch (error) {
1942
- await this.shutdown(this.toError(error));
1943
- this.completeTurnStartReconciliation(threadId, reconciliation);
1944
- }
1945
- }
1946
- handleLateTurnStartResponse(id, late, message) {
1947
- this.lateTurnStarts.delete(id);
1948
- if (late.reconciliation.recoveryTimer) {
1949
- clearTimeout(late.reconciliation.recoveryTimer);
1950
- late.reconciliation.recoveryTimer = undefined;
1951
- }
1952
- if (message.error !== undefined) {
1953
- this.completeTurnStartReconciliation(late.threadId, late.reconciliation);
1954
- return;
1955
- }
1956
- try {
1957
- const turn = validateTurn(object(message.result)?.turn, 'late turn/start turn');
1958
- if (typeof turn?.id !== 'string' || !turn.id) {
1959
- throw new Error('Codex app-server late turn/start returned no turn id');
1960
- }
1961
- void this.reconcileAcknowledgedTurn(late.threadId, turn.id, late.requestTimeout);
1962
- }
1963
- catch (error) {
1964
- void this.shutdown(this.toError(error)).finally(() => {
1965
- this.completeTurnStartReconciliation(late.threadId, late.reconciliation);
1966
- });
1967
- }
1968
- }
1969
- clearTurnCallbacks(turn) {
1970
- turn.queuedNotifications.length = 0;
1971
- turn.queuedToolRequests.length = 0;
1972
- turn.toolCallResults.clear();
1973
- turn.stoppingCallIds.clear();
1974
- turn.hostToolBridge = undefined;
1975
- turn.onDelta = undefined;
1976
- }
1977
- failAll(error) {
1978
- const safe = this.toError(error);
1979
- // Pending child tool calls abort exactly like a parent turn's.
1980
- for (const child of this.subagents.values()) {
1981
- child.abortController.abort(safe);
1982
- }
1983
- for (const threadId of [...this.turns.keys()]) {
1984
- this.failTurn(threadId, safe);
1985
- }
1986
- for (const [id, pending] of this.pending) {
1987
- clearTimeout(pending.timer);
1988
- this.pending.delete(id);
1989
- pending.reject(safe);
1990
- }
1991
- }
1992
- failProcess(child, error) {
1993
- if (child !== this.child) {
1994
- return;
1995
- }
1996
- const suffix = this.stderrTail ? `: ${this.stderrTail}` : '';
1997
- this.failAll(new Error(this.redact(`${error.message}${suffix}`)));
1998
- this.detach(child);
1999
- }
2000
- async restart() {
2001
- await this.shutdown(new Error('Codex app-server restarting after auth refresh'));
2002
- this.sessions.clear();
2003
- }
2004
- async shutdown(reason) {
2005
- if (this.shutdownPromise) {
2006
- return this.shutdownPromise;
2007
- }
2008
- const operation = this.performShutdown(reason);
2009
- this.shutdownPromise = operation;
2010
- try {
2011
- await operation;
2012
- }
2013
- finally {
2014
- if (this.shutdownPromise === operation) {
2015
- this.shutdownPromise = undefined;
2016
- }
2017
- }
2018
- }
2019
- async performShutdown(reason) {
2020
- const child = this.child;
2021
- if (!child) {
2022
- return;
2023
- }
2024
- this.failAll(reason);
2025
- await new Promise((resolveStop) => {
2026
- let settled = false;
2027
- const finish = () => {
2028
- if (settled) {
2029
- return;
2030
- }
2031
- settled = true;
2032
- if (this.killTimer) {
2033
- clearTimeout(this.killTimer);
2034
- this.killTimer = undefined;
2035
- }
2036
- if (this.finalKillTimer) {
2037
- clearTimeout(this.finalKillTimer);
2038
- this.finalKillTimer = undefined;
2039
- }
2040
- this.detach(child);
2041
- resolveStop();
2042
- };
2043
- child.once('exit', finish);
2044
- child.kill('SIGTERM');
2045
- this.killTimer = setTimeout(() => {
2046
- if (child.exitCode === null && child.signalCode === null) {
2047
- child.kill('SIGKILL');
2048
- }
2049
- this.killTimer = undefined;
2050
- this.finalKillTimer = setTimeout(finish, STOP_GRACE_MS);
2051
- this.finalKillTimer.unref();
2052
- }, STOP_GRACE_MS);
2053
- this.killTimer.unref();
2054
- if (child.exitCode !== null || child.signalCode !== null) {
2055
- finish();
2056
- }
2057
- });
2058
- }
2059
- detach(child) {
2060
- if (this.child !== child) {
2061
- return;
2062
- }
2063
- this.stdout?.close();
2064
- this.stderr?.close();
2065
- child.removeAllListeners();
2066
- child.stdin.removeAllListeners();
2067
- child.stdout.removeAllListeners();
2068
- child.stderr.removeAllListeners();
2069
- this.stdout = undefined;
2070
- this.stderr = undefined;
2071
- this.child = undefined;
2072
- this.sessions.clear();
2073
- // The connection is gone, so every child is gone with it: say so once per child and
2074
- // release its authority instead of dropping the registry silently.
2075
- this.terminateSubagents(new Error('Codex app-server connection closed'));
2076
- this.threadContexts.clear();
2077
- this.lateTurnStarts.clear();
2078
- for (const [threadId, reconciliation] of this.turnStartReconciliations) {
2079
- this.completeTurnStartReconciliation(threadId, reconciliation);
2080
- }
2081
- }
2082
- }
2083
- exports.CodexAppServerProcess = CodexAppServerProcess;
2084
- //# sourceMappingURL=codex-app-server-process.js.map