@jungjaehoon/mama-os 0.32.0 → 0.32.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (327) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +15 -13
  3. package/dist/agent/agent-loop.d.ts +10 -1
  4. package/dist/agent/agent-loop.d.ts.map +1 -1
  5. package/dist/agent/agent-loop.js +221 -103
  6. package/dist/agent/agent-loop.js.map +1 -1
  7. package/dist/agent/backend-model-policy.d.ts +9 -0
  8. package/dist/agent/backend-model-policy.d.ts.map +1 -0
  9. package/dist/agent/backend-model-policy.js +21 -0
  10. package/dist/agent/backend-model-policy.js.map +1 -0
  11. package/dist/agent/backend-model-runner-factory.d.ts +27 -0
  12. package/dist/agent/backend-model-runner-factory.d.ts.map +1 -0
  13. package/dist/agent/backend-model-runner-factory.js +85 -0
  14. package/dist/agent/backend-model-runner-factory.js.map +1 -0
  15. package/dist/agent/cline-cli-adapter.d.ts +124 -0
  16. package/dist/agent/cline-cli-adapter.d.ts.map +1 -0
  17. package/dist/agent/cline-cli-adapter.js +1040 -0
  18. package/dist/agent/cline-cli-adapter.js.map +1 -0
  19. package/dist/agent/cline-native-tool-policy.d.ts +3 -0
  20. package/dist/agent/cline-native-tool-policy.d.ts.map +1 -0
  21. package/dist/agent/cline-native-tool-policy.js +50 -0
  22. package/dist/agent/cline-native-tool-policy.js.map +1 -0
  23. package/dist/agent/code-act/constants.d.ts +1 -1
  24. package/dist/agent/code-act/constants.d.ts.map +1 -1
  25. package/dist/agent/code-act/constants.js +13 -1
  26. package/dist/agent/code-act/constants.js.map +1 -1
  27. package/dist/agent/code-act/host-bridge.d.ts.map +1 -1
  28. package/dist/agent/code-act/host-bridge.js +35 -74
  29. package/dist/agent/code-act/host-bridge.js.map +1 -1
  30. package/dist/agent/codex-app-server-process.d.ts +5 -0
  31. package/dist/agent/codex-app-server-process.d.ts.map +1 -1
  32. package/dist/agent/codex-app-server-process.js +30 -0
  33. package/dist/agent/codex-app-server-process.js.map +1 -1
  34. package/dist/agent/codex-auxiliary-tools.d.ts +17 -0
  35. package/dist/agent/codex-auxiliary-tools.d.ts.map +1 -0
  36. package/dist/agent/codex-auxiliary-tools.js +267 -0
  37. package/dist/agent/codex-auxiliary-tools.js.map +1 -0
  38. package/dist/agent/codex-home.d.ts.map +1 -1
  39. package/dist/agent/codex-home.js +1 -0
  40. package/dist/agent/codex-home.js.map +1 -1
  41. package/dist/agent/gateway-tool-catalog.d.ts +14 -0
  42. package/dist/agent/gateway-tool-catalog.d.ts.map +1 -0
  43. package/dist/agent/gateway-tool-catalog.js +41 -0
  44. package/dist/agent/gateway-tool-catalog.js.map +1 -0
  45. package/dist/agent/gateway-tool-executor.d.ts +12 -1
  46. package/dist/agent/gateway-tool-executor.d.ts.map +1 -1
  47. package/dist/agent/gateway-tool-executor.js +149 -15
  48. package/dist/agent/gateway-tool-executor.js.map +1 -1
  49. package/dist/agent/gateway-tools.md +5 -7
  50. package/dist/agent/managed-agent-runtime-sync.d.ts.map +1 -1
  51. package/dist/agent/managed-agent-runtime-sync.js +17 -3
  52. package/dist/agent/managed-agent-runtime-sync.js.map +1 -1
  53. package/dist/agent/managed-agent-validation.js +1 -1
  54. package/dist/agent/managed-agent-validation.js.map +1 -1
  55. package/dist/agent/model-runner.d.ts +11 -1
  56. package/dist/agent/model-runner.d.ts.map +1 -1
  57. package/dist/agent/model-runner.js +12 -1
  58. package/dist/agent/model-runner.js.map +1 -1
  59. package/dist/agent/session-pool.d.ts +10 -9
  60. package/dist/agent/session-pool.d.ts.map +1 -1
  61. package/dist/agent/session-pool.js +12 -47
  62. package/dist/agent/session-pool.js.map +1 -1
  63. package/dist/agent/tool-registry.d.ts +6 -4
  64. package/dist/agent/tool-registry.d.ts.map +1 -1
  65. package/dist/agent/tool-registry.js +62 -30
  66. package/dist/agent/tool-registry.js.map +1 -1
  67. package/dist/agent/types.d.ts +36 -4
  68. package/dist/agent/types.d.ts.map +1 -1
  69. package/dist/agent/types.js.map +1 -1
  70. package/dist/api/graph-api.d.ts.map +1 -1
  71. package/dist/api/graph-api.js +15 -5
  72. package/dist/api/graph-api.js.map +1 -1
  73. package/dist/api/index.d.ts +10 -0
  74. package/dist/api/index.d.ts.map +1 -1
  75. package/dist/api/index.js +7 -16
  76. package/dist/api/index.js.map +1 -1
  77. package/dist/cli/commands/connector.d.ts +6 -1
  78. package/dist/cli/commands/connector.d.ts.map +1 -1
  79. package/dist/cli/commands/connector.js +61 -45
  80. package/dist/cli/commands/connector.js.map +1 -1
  81. package/dist/cli/commands/init.d.ts +1 -1
  82. package/dist/cli/commands/init.d.ts.map +1 -1
  83. package/dist/cli/commands/init.js +43 -10
  84. package/dist/cli/commands/init.js.map +1 -1
  85. package/dist/cli/commands/run.d.ts.map +1 -1
  86. package/dist/cli/commands/run.js +12 -0
  87. package/dist/cli/commands/run.js.map +1 -1
  88. package/dist/cli/commands/setup.d.ts +22 -0
  89. package/dist/cli/commands/setup.d.ts.map +1 -1
  90. package/dist/cli/commands/setup.js +79 -28
  91. package/dist/cli/commands/setup.js.map +1 -1
  92. package/dist/cli/commands/start.d.ts +13 -9
  93. package/dist/cli/commands/start.d.ts.map +1 -1
  94. package/dist/cli/commands/start.js +190 -97
  95. package/dist/cli/commands/start.js.map +1 -1
  96. package/dist/cli/commands/status.d.ts.map +1 -1
  97. package/dist/cli/commands/status.js +4 -0
  98. package/dist/cli/commands/status.js.map +1 -1
  99. package/dist/cli/config/config-manager.d.ts.map +1 -1
  100. package/dist/cli/config/config-manager.js +63 -14
  101. package/dist/cli/config/config-manager.js.map +1 -1
  102. package/dist/cli/config/types.d.ts +12 -5
  103. package/dist/cli/config/types.d.ts.map +1 -1
  104. package/dist/cli/config/types.js +3 -4
  105. package/dist/cli/config/types.js.map +1 -1
  106. package/dist/cli/index.js +6 -4
  107. package/dist/cli/index.js.map +1 -1
  108. package/dist/cli/runtime/agent-loop-init.d.ts +1 -1
  109. package/dist/cli/runtime/agent-loop-init.d.ts.map +1 -1
  110. package/dist/cli/runtime/agent-loop-init.js +8 -3
  111. package/dist/cli/runtime/agent-loop-init.js.map +1 -1
  112. package/dist/cli/runtime/api-routes-init.d.ts +38 -1
  113. package/dist/cli/runtime/api-routes-init.d.ts.map +1 -1
  114. package/dist/cli/runtime/api-routes-init.js +150 -30
  115. package/dist/cli/runtime/api-routes-init.js.map +1 -1
  116. package/dist/cli/runtime/api-server-init.d.ts +4 -0
  117. package/dist/cli/runtime/api-server-init.d.ts.map +1 -1
  118. package/dist/cli/runtime/api-server-init.js +3 -1
  119. package/dist/cli/runtime/api-server-init.js.map +1 -1
  120. package/dist/cli/runtime/connector-bootstrap.d.ts +8 -0
  121. package/dist/cli/runtime/connector-bootstrap.d.ts.map +1 -0
  122. package/dist/cli/runtime/connector-bootstrap.js +14 -0
  123. package/dist/cli/runtime/connector-bootstrap.js.map +1 -0
  124. package/dist/cli/runtime/connector-init.d.ts +4 -1
  125. package/dist/cli/runtime/connector-init.d.ts.map +1 -1
  126. package/dist/cli/runtime/connector-init.js +2 -8
  127. package/dist/cli/runtime/connector-init.js.map +1 -1
  128. package/dist/cli/runtime/envelope-bootstrap.d.ts +2 -1
  129. package/dist/cli/runtime/envelope-bootstrap.d.ts.map +1 -1
  130. package/dist/cli/runtime/envelope-bootstrap.js +7 -15
  131. package/dist/cli/runtime/envelope-bootstrap.js.map +1 -1
  132. package/dist/cli/runtime/gateway-init.d.ts +1 -1
  133. package/dist/cli/runtime/gateway-init.d.ts.map +1 -1
  134. package/dist/cli/runtime/gateway-init.js.map +1 -1
  135. package/dist/cli/runtime/mama-core-init.d.ts +10 -2
  136. package/dist/cli/runtime/mama-core-init.d.ts.map +1 -1
  137. package/dist/cli/runtime/mama-core-init.js +52 -68
  138. package/dist/cli/runtime/mama-core-init.js.map +1 -1
  139. package/dist/cli/runtime/memory-agent-init.d.ts.map +1 -1
  140. package/dist/cli/runtime/memory-agent-init.js +18 -5
  141. package/dist/cli/runtime/memory-agent-init.js.map +1 -1
  142. package/dist/cli/runtime/scheduler-init.d.ts +4 -0
  143. package/dist/cli/runtime/scheduler-init.d.ts.map +1 -1
  144. package/dist/cli/runtime/scheduler-init.js +24 -3
  145. package/dist/cli/runtime/scheduler-init.js.map +1 -1
  146. package/dist/cli/runtime/shutdown.d.ts +4 -0
  147. package/dist/cli/runtime/shutdown.d.ts.map +1 -1
  148. package/dist/cli/runtime/shutdown.js +30 -6
  149. package/dist/cli/runtime/shutdown.js.map +1 -1
  150. package/dist/cli/runtime/utilities.d.ts +2 -0
  151. package/dist/cli/runtime/utilities.d.ts.map +1 -1
  152. package/dist/cli/runtime/utilities.js +33 -0
  153. package/dist/cli/runtime/utilities.js.map +1 -1
  154. package/dist/connectors/index.d.ts +4 -1
  155. package/dist/connectors/index.d.ts.map +1 -1
  156. package/dist/connectors/index.js +3 -2
  157. package/dist/connectors/index.js.map +1 -1
  158. package/dist/connectors/private-connector-policy.d.ts +150 -0
  159. package/dist/connectors/private-connector-policy.d.ts.map +1 -0
  160. package/dist/connectors/private-connector-policy.js +289 -0
  161. package/dist/connectors/private-connector-policy.js.map +1 -0
  162. package/dist/connectors/private-prompt-overlay.d.ts +17 -0
  163. package/dist/connectors/private-prompt-overlay.d.ts.map +1 -0
  164. package/dist/connectors/private-prompt-overlay.js +156 -0
  165. package/dist/connectors/private-prompt-overlay.js.map +1 -0
  166. package/dist/db/migrations/operator-task-external-lifecycle.d.ts +8 -0
  167. package/dist/db/migrations/operator-task-external-lifecycle.d.ts.map +1 -0
  168. package/dist/db/migrations/operator-task-external-lifecycle.js +169 -0
  169. package/dist/db/migrations/operator-task-external-lifecycle.js.map +1 -0
  170. package/dist/envelope/enforcer.js +8 -7
  171. package/dist/envelope/enforcer.js.map +1 -1
  172. package/dist/envelope/reactive-config.d.ts.map +1 -1
  173. package/dist/envelope/reactive-config.js +2 -1
  174. package/dist/envelope/reactive-config.js.map +1 -1
  175. package/dist/envelope/tool-connector-scope.d.ts.map +1 -1
  176. package/dist/envelope/tool-connector-scope.js +4 -0
  177. package/dist/envelope/tool-connector-scope.js.map +1 -1
  178. package/dist/gateways/discord.d.ts.map +1 -1
  179. package/dist/gateways/discord.js +11 -6
  180. package/dist/gateways/discord.js.map +1 -1
  181. package/dist/gateways/image-analyzer.d.ts +5 -0
  182. package/dist/gateways/image-analyzer.d.ts.map +1 -1
  183. package/dist/gateways/image-analyzer.js +8 -0
  184. package/dist/gateways/image-analyzer.js.map +1 -1
  185. package/dist/gateways/message-router.d.ts +11 -1
  186. package/dist/gateways/message-router.d.ts.map +1 -1
  187. package/dist/gateways/message-router.js +146 -52
  188. package/dist/gateways/message-router.js.map +1 -1
  189. package/dist/gateways/slack.d.ts.map +1 -1
  190. package/dist/gateways/slack.js +6 -2
  191. package/dist/gateways/slack.js.map +1 -1
  192. package/dist/gateways/telegram-message-ledger.d.ts +8 -1
  193. package/dist/gateways/telegram-message-ledger.d.ts.map +1 -1
  194. package/dist/gateways/telegram-message-ledger.js +141 -24
  195. package/dist/gateways/telegram-message-ledger.js.map +1 -1
  196. package/dist/gateways/telegram.d.ts +2 -0
  197. package/dist/gateways/telegram.d.ts.map +1 -1
  198. package/dist/gateways/telegram.js +19 -12
  199. package/dist/gateways/telegram.js.map +1 -1
  200. package/dist/gateways/types.d.ts +1 -1
  201. package/dist/gateways/types.d.ts.map +1 -1
  202. package/dist/index.d.ts +1 -1
  203. package/dist/index.js +1 -1
  204. package/dist/multi-agent/agent-process-manager.d.ts +14 -4
  205. package/dist/multi-agent/agent-process-manager.d.ts.map +1 -1
  206. package/dist/multi-agent/agent-process-manager.js +144 -47
  207. package/dist/multi-agent/agent-process-manager.js.map +1 -1
  208. package/dist/multi-agent/dashboard-agent-persona.d.ts +3 -3
  209. package/dist/multi-agent/dashboard-agent-persona.d.ts.map +1 -1
  210. package/dist/multi-agent/dashboard-agent-persona.js +10 -13
  211. package/dist/multi-agent/dashboard-agent-persona.js.map +1 -1
  212. package/dist/multi-agent/memory-agent-persona.d.ts +1 -1
  213. package/dist/multi-agent/memory-agent-persona.d.ts.map +1 -1
  214. package/dist/multi-agent/memory-agent-persona.js +1 -1
  215. package/dist/multi-agent/runtime-process.d.ts +3 -0
  216. package/dist/multi-agent/runtime-process.d.ts.map +1 -1
  217. package/dist/multi-agent/runtime-process.js +10 -2
  218. package/dist/multi-agent/runtime-process.js.map +1 -1
  219. package/dist/multi-agent/types.d.ts +12 -2
  220. package/dist/multi-agent/types.d.ts.map +1 -1
  221. package/dist/multi-agent/types.js.map +1 -1
  222. package/dist/multi-agent/wiki-agent-persona.d.ts +2 -2
  223. package/dist/multi-agent/wiki-agent-persona.js +2 -2
  224. package/dist/multi-agent/workflow-types.d.ts +1 -1
  225. package/dist/multi-agent/workflow-types.d.ts.map +1 -1
  226. package/dist/onboarding/complete-autonomous-prompt.d.ts +1 -1
  227. package/dist/onboarding/complete-autonomous-prompt.d.ts.map +1 -1
  228. package/dist/onboarding/complete-autonomous-prompt.js +9 -9
  229. package/dist/operator/board-slot-instructions.d.ts +1 -1
  230. package/dist/operator/board-slot-instructions.js +2 -2
  231. package/dist/operator/board-slot-instructions.js.map +1 -1
  232. package/dist/operator/briefs.d.ts +3 -0
  233. package/dist/operator/briefs.d.ts.map +1 -1
  234. package/dist/operator/briefs.js +64 -3
  235. package/dist/operator/briefs.js.map +1 -1
  236. package/dist/operator/console-brief.d.ts +6 -3
  237. package/dist/operator/console-brief.d.ts.map +1 -1
  238. package/dist/operator/console-brief.js +39 -9
  239. package/dist/operator/console-brief.js.map +1 -1
  240. package/dist/operator/external-lifecycle-candidates.d.ts +56 -0
  241. package/dist/operator/external-lifecycle-candidates.d.ts.map +1 -0
  242. package/dist/operator/external-lifecycle-candidates.js +415 -0
  243. package/dist/operator/external-lifecycle-candidates.js.map +1 -0
  244. package/dist/operator/external-lifecycle.d.ts +82 -0
  245. package/dist/operator/external-lifecycle.d.ts.map +1 -0
  246. package/dist/operator/external-lifecycle.js +27 -0
  247. package/dist/operator/external-lifecycle.js.map +1 -0
  248. package/dist/operator/file-coordination.d.ts +7 -0
  249. package/dist/operator/file-coordination.d.ts.map +1 -0
  250. package/dist/operator/file-coordination.js +84 -0
  251. package/dist/operator/file-coordination.js.map +1 -0
  252. package/dist/operator/operator-trigger-loop.d.ts +19 -4
  253. package/dist/operator/operator-trigger-loop.d.ts.map +1 -1
  254. package/dist/operator/operator-trigger-loop.js +151 -23
  255. package/dist/operator/operator-trigger-loop.js.map +1 -1
  256. package/dist/operator/pending-report-store.d.ts +62 -3
  257. package/dist/operator/pending-report-store.d.ts.map +1 -1
  258. package/dist/operator/pending-report-store.js +297 -40
  259. package/dist/operator/pending-report-store.js.map +1 -1
  260. package/dist/operator/report-carry-delivery.d.ts +35 -0
  261. package/dist/operator/report-carry-delivery.d.ts.map +1 -0
  262. package/dist/operator/report-carry-delivery.js +55 -0
  263. package/dist/operator/report-carry-delivery.js.map +1 -0
  264. package/dist/operator/report-carry.d.ts +50 -30
  265. package/dist/operator/report-carry.d.ts.map +1 -1
  266. package/dist/operator/report-carry.js +323 -71
  267. package/dist/operator/report-carry.js.map +1 -1
  268. package/dist/operator/situation-report.d.ts +30 -11
  269. package/dist/operator/situation-report.d.ts.map +1 -1
  270. package/dist/operator/situation-report.js +79 -35
  271. package/dist/operator/situation-report.js.map +1 -1
  272. package/dist/operator/task-ledger.d.ts +101 -0
  273. package/dist/operator/task-ledger.d.ts.map +1 -1
  274. package/dist/operator/task-ledger.js +599 -124
  275. package/dist/operator/task-ledger.js.map +1 -1
  276. package/dist/operator/temporal-runtime.d.ts.map +1 -1
  277. package/dist/operator/temporal-runtime.js +3 -1
  278. package/dist/operator/temporal-runtime.js.map +1 -1
  279. package/dist/operator/temporal-worker.js +1 -1
  280. package/dist/operator/trigger-author.d.ts +13 -1
  281. package/dist/operator/trigger-author.d.ts.map +1 -1
  282. package/dist/operator/trigger-author.js +35 -0
  283. package/dist/operator/trigger-author.js.map +1 -1
  284. package/dist/operator/worker-run.d.ts +1 -1
  285. package/dist/operator/worker-run.d.ts.map +1 -1
  286. package/dist/operator/worker-run.js +27 -9
  287. package/dist/operator/worker-run.js.map +1 -1
  288. package/dist/operator/workorder-consumer.d.ts +12 -1
  289. package/dist/operator/workorder-consumer.d.ts.map +1 -1
  290. package/dist/operator/workorder-consumer.js +125 -6
  291. package/dist/operator/workorder-consumer.js.map +1 -1
  292. package/dist/operator/workorder-hooks.d.ts +7 -2
  293. package/dist/operator/workorder-hooks.d.ts.map +1 -1
  294. package/dist/operator/workorder-hooks.js +22 -0
  295. package/dist/operator/workorder-hooks.js.map +1 -1
  296. package/dist/operator/workorder-publishers.d.ts +9 -2
  297. package/dist/operator/workorder-publishers.d.ts.map +1 -1
  298. package/dist/operator/workorder-publishers.js +167 -5
  299. package/dist/operator/workorder-publishers.js.map +1 -1
  300. package/dist/scheduler/cron-worker.d.ts +8 -4
  301. package/dist/scheduler/cron-worker.d.ts.map +1 -1
  302. package/dist/scheduler/cron-worker.js +56 -39
  303. package/dist/scheduler/cron-worker.js.map +1 -1
  304. package/dist/setup/setup-actions.d.ts +26 -0
  305. package/dist/setup/setup-actions.d.ts.map +1 -0
  306. package/dist/setup/setup-actions.js +371 -0
  307. package/dist/setup/setup-actions.js.map +1 -0
  308. package/dist/setup/setup-prompt.d.ts +1 -1
  309. package/dist/setup/setup-prompt.d.ts.map +1 -1
  310. package/dist/setup/setup-prompt.js +28 -33
  311. package/dist/setup/setup-prompt.js.map +1 -1
  312. package/dist/setup/setup-server.d.ts +6 -1
  313. package/dist/setup/setup-server.d.ts.map +1 -1
  314. package/dist/setup/setup-server.js +55 -9
  315. package/dist/setup/setup-server.js.map +1 -1
  316. package/dist/setup/setup-websocket.d.ts +14 -2
  317. package/dist/setup/setup-websocket.d.ts.map +1 -1
  318. package/dist/setup/setup-websocket.js +121 -37
  319. package/dist/setup/setup-websocket.js.map +1 -1
  320. package/package.json +2 -2
  321. package/public/setup.html +9 -6
  322. package/public/viewer/js/modules/agents.js +5 -4
  323. package/public/viewer/js/modules/settings.js +34 -10
  324. package/public/viewer/src/modules/agents.ts +5 -4
  325. package/public/viewer/src/modules/settings.ts +49 -11
  326. package/public/viewer/src/utils/api.ts +3 -2
  327. package/scripts/generate-gateway-tools.ts +13 -3
@@ -1,24 +1,10 @@
1
1
  /**
2
- * Context carry for the owner console (plan v6 S1-T4).
2
+ * TG-06 one-shot owner-report carry.
3
3
  *
4
- * Kagemusha's continuity mechanism, minimal form: the chat persona can
5
- * reference "the report you just received" because the last DELIVERED full
6
- * report is persisted at delivery time and injected per turn. Carry is
7
- * DERIVED state (storage-layer, never session accumulation - owner principle
8
- * "session = cache").
9
- *
10
- * Injection rides the user-message prefix path - the only channel that flows
11
- * on EVERY turn including CONTINUE (per-call system prompts never reach a
12
- * pooled CLI process).
13
- */
14
- /**
15
- * Whether a delivered report can be traced back to the run that produced it.
16
- *
17
- * Discriminated rather than a nullable id, for the reason the turn contract uses the
18
- * same shape: "no handle recorded" and "no run happened" are different facts, and a
19
- * delivered artifact that cannot be traced should say which one it is. A report is the
20
- * most consequential thing this system emits - it goes to a person and gets acted on -
21
- * so it is the last place an absence should be silent.
4
+ * The report itself is durable data, but this derived context must only reach
5
+ * the Telegram chat that received it and only until its first durable owner
6
+ * turn acknowledgement. Invalid state is deliberately not repaired here: it
7
+ * cannot safely be attributed to a target or delivery.
22
8
  */
23
9
  export type ArtifactProvenance = {
24
10
  status: 'available';
@@ -27,20 +13,54 @@ export type ArtifactProvenance = {
27
13
  status: 'unavailable';
28
14
  reason: 'no_run_handle' | 'commit_failed' | 'legacy_record';
29
15
  };
30
- export interface LastFullReport {
16
+ export interface ReportCarryTarget {
17
+ source: 'telegram';
18
+ channelId: string;
19
+ }
20
+ export interface ReportCarryV2 {
21
+ version: 2;
22
+ deliveryId: string;
23
+ target: ReportCarryTarget;
31
24
  deliveredAt: string;
32
25
  text: string;
33
26
  provenance: ArtifactProvenance;
27
+ consumedAt?: string;
28
+ consumingChannelKey?: string;
29
+ }
30
+ export interface ReportCarryPeek {
31
+ deliveryId: string;
32
+ prefix: string;
33
+ }
34
+ export interface PersistDeliveredInput {
35
+ deliveryId: string;
36
+ target: ReportCarryTarget;
37
+ deliveredAt: string;
38
+ text: string;
39
+ provenance: ArtifactProvenance;
40
+ }
41
+ export interface AckInput {
42
+ deliveryId: string;
43
+ target: ReportCarryTarget;
44
+ consumingChannelKey: string;
45
+ consumedAtIso: string;
46
+ }
47
+ export interface ReportCarryPort {
48
+ peek(target: ReportCarryTarget, nowMs?: number): ReportCarryPeek | null;
49
+ acknowledge(input: AckInput): boolean;
34
50
  }
35
51
  export declare function defaultCarryPath(): string;
36
- /** Persist the delivered full report (atomic write, same pattern as the schedule store). */
37
- export declare function persistLastFullReport(deliveredAtIso: string, text: string, provenance: ArtifactProvenance, path?: string): void;
38
- /** Load the last delivered full report; null when none exists or the file is unreadable. */
39
- export declare function loadLastFullReport(path?: string): LastFullReport | null;
40
- /**
41
- * Build the per-turn carry prefix for the owner console. Empty string when no
42
- * report has been delivered yet (nothing to carry - the persona should use
43
- * report_request/board_read instead).
44
- */
45
- export declare function buildReportCarryPrefix(path?: string): string;
52
+ /** Exact persisted provenance contract shared by report composition and outbox recovery. */
53
+ export declare function isArtifactProvenance(value: unknown): value is ArtifactProvenance;
54
+ /** @internal Atomic publisher used only while FileReportCarryStore owns its SQLite transaction. */
55
+ export declare function writeReportCarryAtomically(path: string, record: ReportCarryV2): void;
56
+ export declare class FileReportCarryStore implements ReportCarryPort {
57
+ private readonly path;
58
+ constructor(path?: string);
59
+ persistDelivered(input: PersistDeliveredInput): void;
60
+ peek(target: ReportCarryTarget, nowMs?: number): ReportCarryPeek | null;
61
+ acknowledge(input: AckInput): boolean;
62
+ private read;
63
+ private quarantineLegacy;
64
+ private warn;
65
+ }
46
66
  //# sourceMappingURL=report-carry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"report-carry.d.ts","sourceRoot":"","sources":["../../src/operator/report-carry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH;;;;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AE,KAAK,GAAE,MAAmB,GAAG,eAAe,GAAG,IAAI;IAgBnF,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;IAsBrC,OAAO,CAAC,IAAI;IA4BZ,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,IAAI;CAGb"}
@@ -1,100 +1,352 @@
1
1
  "use strict";
2
2
  /**
3
- * Context carry for the owner console (plan v6 S1-T4).
3
+ * TG-06 one-shot owner-report carry.
4
4
  *
5
- * Kagemusha's continuity mechanism, minimal form: the chat persona can
6
- * reference "the report you just received" because the last DELIVERED full
7
- * report is persisted at delivery time and injected per turn. Carry is
8
- * DERIVED state (storage-layer, never session accumulation - owner principle
9
- * "session = cache").
10
- *
11
- * Injection rides the user-message prefix path - the only channel that flows
12
- * on EVERY turn including CONTINUE (per-call system prompts never reach a
13
- * pooled CLI process).
5
+ * The report itself is durable data, but this derived context must only reach
6
+ * the Telegram chat that received it and only until its first durable owner
7
+ * turn acknowledgement. Invalid state is deliberately not repaired here: it
8
+ * cannot safely be attributed to a target or delivery.
14
9
  */
15
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.FileReportCarryStore = void 0;
16
12
  exports.defaultCarryPath = defaultCarryPath;
17
- exports.persistLastFullReport = persistLastFullReport;
18
- exports.loadLastFullReport = loadLastFullReport;
19
- exports.buildReportCarryPrefix = buildReportCarryPrefix;
13
+ exports.isArtifactProvenance = isArtifactProvenance;
14
+ exports.writeReportCarryAtomically = writeReportCarryAtomically;
15
+ const node_crypto_1 = require("node:crypto");
20
16
  const node_fs_1 = require("node:fs");
21
- const untrusted_content_js_1 = require("../utils/untrusted-content.js");
22
17
  const node_os_1 = require("node:os");
23
18
  const node_path_1 = require("node:path");
19
+ const untrusted_content_js_1 = require("../utils/untrusted-content.js");
20
+ const file_coordination_js_1 = require("./file-coordination.js");
24
21
  const CARRY_SUMMARY_MAX_CHARS = 700;
22
+ const CARRY_TTL_MS = 24 * 60 * 60 * 1000;
23
+ const STAGING_DIRECTORY_ATTEMPTS = 8;
24
+ const UNAVAILABLE_REASONS = new Set(['no_run_handle', 'commit_failed', 'legacy_record']);
25
25
  function defaultCarryPath() {
26
26
  return (0, node_path_1.join)((0, node_os_1.homedir)(), '.mama', 'operator', 'last-full-report.json');
27
27
  }
28
- /** Persist the delivered full report (atomic write, same pattern as the schedule store). */
29
- function persistLastFullReport(deliveredAtIso, text, provenance, path = defaultCarryPath()) {
30
- (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(path), { recursive: true });
31
- const tmp = (0, node_path_1.join)((0, node_path_1.dirname)(path), `.last-full-report.${process.pid}.tmp`);
32
- // 0600: the carried report is owner operational data.
33
- (0, node_fs_1.writeFileSync)(tmp, JSON.stringify({ deliveredAt: deliveredAtIso, text, provenance }), {
34
- mode: 0o600,
35
- });
36
- (0, node_fs_1.renameSync)(tmp, path);
28
+ function isRecord(value) {
29
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
30
+ }
31
+ function hasOnlyKeys(value, keys) {
32
+ const actualKeys = Object.keys(value);
33
+ return actualKeys.length === keys.length && actualKeys.every((key) => keys.includes(key));
34
+ }
35
+ function isNonEmptyString(value) {
36
+ return typeof value === 'string' && value.length > 0;
37
37
  }
38
+ function isIsoTimestamp(value) {
39
+ if (typeof value !== 'string') {
40
+ return false;
41
+ }
42
+ const milliseconds = Date.parse(value);
43
+ return Number.isFinite(milliseconds) && new Date(milliseconds).toISOString() === value;
44
+ }
45
+ function isTarget(value) {
46
+ if (!isRecord(value) || !hasOnlyKeys(value, ['source', 'channelId'])) {
47
+ return false;
48
+ }
49
+ return value.source === 'telegram' && isNonEmptyString(value.channelId);
50
+ }
51
+ /** Exact persisted provenance contract shared by report composition and outbox recovery. */
38
52
  function isArtifactProvenance(value) {
39
- if (value === null || typeof value !== 'object') {
53
+ if (!isRecord(value)) {
40
54
  return false;
41
55
  }
42
- const record = value;
43
- if (record.status === 'available') {
44
- return typeof record.modelRunId === 'string' && record.modelRunId.length > 0;
56
+ if (value.status === 'available') {
57
+ return (hasOnlyKeys(value, ['status', 'modelRunId']) &&
58
+ isNonEmptyString(value.modelRunId) &&
59
+ value.modelRunId.trim() === value.modelRunId &&
60
+ value.modelRunId.length <= 512);
45
61
  }
46
- return record.status === 'unavailable' && typeof record.reason === 'string';
62
+ return (value.status === 'unavailable' &&
63
+ hasOnlyKeys(value, ['status', 'reason']) &&
64
+ typeof value.reason === 'string' &&
65
+ UNAVAILABLE_REASONS.has(value.reason));
47
66
  }
48
- /** Load the last delivered full report; null when none exists or the file is unreadable. */
49
- function loadLastFullReport(path = defaultCarryPath()) {
50
- let raw;
51
- try {
52
- raw = (0, node_fs_1.readFileSync)(path, 'utf8');
67
+ function isReportCarryV2(value) {
68
+ if (!isRecord(value)) {
69
+ return false;
70
+ }
71
+ const consumedFieldsPresent = value.consumedAt !== undefined || value.consumingChannelKey !== undefined;
72
+ const expectedKeys = consumedFieldsPresent
73
+ ? [
74
+ 'version',
75
+ 'deliveryId',
76
+ 'target',
77
+ 'deliveredAt',
78
+ 'text',
79
+ 'provenance',
80
+ 'consumedAt',
81
+ 'consumingChannelKey',
82
+ ]
83
+ : ['version', 'deliveryId', 'target', 'deliveredAt', 'text', 'provenance'];
84
+ return (hasOnlyKeys(value, expectedKeys) &&
85
+ value.version === 2 &&
86
+ isNonEmptyString(value.deliveryId) &&
87
+ isTarget(value.target) &&
88
+ isIsoTimestamp(value.deliveredAt) &&
89
+ typeof value.text === 'string' &&
90
+ isArtifactProvenance(value.provenance) &&
91
+ (!consumedFieldsPresent ||
92
+ (isIsoTimestamp(value.consumedAt) && isNonEmptyString(value.consumingChannelKey))));
93
+ }
94
+ function isLegacyReportCarry(value) {
95
+ if (!isRecord(value) || !isIsoTimestamp(value.deliveredAt) || typeof value.text !== 'string') {
96
+ return false;
97
+ }
98
+ return (hasOnlyKeys(value, ['deliveredAt', 'text']) ||
99
+ (hasOnlyKeys(value, ['deliveredAt', 'text', 'provenance']) &&
100
+ isArtifactProvenance(value.provenance)));
101
+ }
102
+ function sameTarget(left, right) {
103
+ return left.source === right.source && left.channelId === right.channelId;
104
+ }
105
+ function sameProvenance(left, right) {
106
+ if (left.status !== right.status) {
107
+ return false;
108
+ }
109
+ if (left.status === 'available' && right.status === 'available') {
110
+ return left.modelRunId === right.modelRunId;
111
+ }
112
+ if (left.status === 'unavailable' && right.status === 'unavailable') {
113
+ return left.reason === right.reason;
114
+ }
115
+ return false;
116
+ }
117
+ function assertPersistInput(input) {
118
+ if (!isRecord(input) ||
119
+ !hasOnlyKeys(input, ['deliveryId', 'target', 'deliveredAt', 'text', 'provenance'])) {
120
+ throw new Error('Report carry persist input must contain exact fields');
121
+ }
122
+ if (!isNonEmptyString(input.deliveryId)) {
123
+ throw new Error('Report carry deliveryId must be a non-empty string');
124
+ }
125
+ if (!isTarget(input.target)) {
126
+ throw new Error('Report carry target must be an exact Telegram target');
127
+ }
128
+ if (!isIsoTimestamp(input.deliveredAt)) {
129
+ throw new Error('Report carry deliveredAt must be an ISO timestamp');
130
+ }
131
+ if (typeof input.text !== 'string') {
132
+ throw new Error('Report carry text must be a string');
133
+ }
134
+ if (!isArtifactProvenance(input.provenance)) {
135
+ throw new Error('Report carry provenance is invalid');
136
+ }
137
+ }
138
+ function assertAckInput(input) {
139
+ if (!isRecord(input) ||
140
+ !hasOnlyKeys(input, ['deliveryId', 'target', 'consumingChannelKey', 'consumedAtIso'])) {
141
+ throw new Error('Report carry acknowledgement input must contain exact fields');
142
+ }
143
+ if (!isNonEmptyString(input.deliveryId) || !isTarget(input.target)) {
144
+ throw new Error('Report carry acknowledgement has an invalid delivery target');
145
+ }
146
+ if (!isNonEmptyString(input.consumingChannelKey) || !isIsoTimestamp(input.consumedAtIso)) {
147
+ throw new Error('Report carry acknowledgement is invalid');
53
148
  }
54
- catch {
55
- // Missing file is the normal no-report-yet state.
56
- return null;
149
+ }
150
+ function isActive(record, nowMs) {
151
+ const age = nowMs - Date.parse(record.deliveredAt);
152
+ return age >= 0 && age <= CARRY_TTL_MS;
153
+ }
154
+ function buildPrefix(record) {
155
+ const summary = record.text.length > CARRY_SUMMARY_MAX_CHARS
156
+ ? `${record.text.slice(0, CARRY_SUMMARY_MAX_CHARS)}\n[... truncated - full text was delivered to the owner channel]`
157
+ : record.text;
158
+ return (`[Operator context] The last FULL situation report was delivered at ${record.deliveredAt}.\n` +
159
+ 'If the owner asks for a report or current status, reference/refresh THIS instead of ' +
160
+ `reconstructing state from memory. Content:\n${(0, untrusted_content_js_1.wrapUntrustedContent)('operator-report-carry', summary)}\n---\n`);
161
+ }
162
+ function isErrno(error, code) {
163
+ return isRecord(error) && error.code === code;
164
+ }
165
+ function createStagingDirectory(path) {
166
+ const directory = (0, node_path_1.dirname)(path);
167
+ const stem = (0, node_path_1.basename)(path);
168
+ for (let attempt = 0; attempt < STAGING_DIRECTORY_ATTEMPTS; attempt += 1) {
169
+ const stagingDirectory = (0, node_path_1.join)(directory, `.${stem}.${process.pid}.${(0, node_crypto_1.randomUUID)()}.stage`);
170
+ try {
171
+ (0, node_fs_1.mkdirSync)(stagingDirectory, { mode: 0o700 });
172
+ (0, node_fs_1.chmodSync)(stagingDirectory, 0o700);
173
+ return stagingDirectory;
174
+ }
175
+ catch (error) {
176
+ if (isErrno(error, 'EEXIST')) {
177
+ continue;
178
+ }
179
+ throw new Error(`Unable to create report carry staging directory: ${formatError(error)}`);
180
+ }
181
+ }
182
+ throw new Error('Unable to allocate unique report carry staging directory');
183
+ }
184
+ /** @internal Atomic publisher used only while FileReportCarryStore owns its SQLite transaction. */
185
+ function writeReportCarryAtomically(path, record) {
186
+ if (!isReportCarryV2(record)) {
187
+ throw new Error('Refusing to persist invalid report carry state');
57
188
  }
189
+ const directory = (0, node_path_1.dirname)(path);
190
+ (0, node_fs_1.mkdirSync)(directory, { recursive: true, mode: 0o700 });
191
+ let stagingDirectory;
192
+ let payloadPath;
193
+ let ownsPayload = false;
194
+ let published = false;
195
+ let operationError;
196
+ let cleanupError;
58
197
  try {
59
- const parsed = JSON.parse(raw);
60
- if (typeof parsed.deliveredAt !== 'string' || typeof parsed.text !== 'string') {
61
- console.warn(`[report-carry] carry file has invalid shape, ignoring: ${path}`);
198
+ stagingDirectory = createStagingDirectory(path);
199
+ payloadPath = (0, node_path_1.join)(stagingDirectory, `${(0, node_crypto_1.randomUUID)()}.json`);
200
+ (0, node_fs_1.writeFileSync)(payloadPath, `${JSON.stringify(record)}\n`, {
201
+ encoding: 'utf8',
202
+ mode: 0o600,
203
+ flag: 'wx',
204
+ });
205
+ ownsPayload = true;
206
+ (0, node_fs_1.chmodSync)(payloadPath, 0o600);
207
+ (0, node_fs_1.renameSync)(payloadPath, path);
208
+ published = true;
209
+ (0, node_fs_1.chmodSync)(path, 0o600);
210
+ }
211
+ catch (error) {
212
+ operationError = error;
213
+ }
214
+ finally {
215
+ if (ownsPayload && !published && payloadPath !== undefined) {
216
+ try {
217
+ (0, node_fs_1.unlinkSync)(payloadPath);
218
+ }
219
+ catch (error) {
220
+ if (!isErrno(error, 'ENOENT')) {
221
+ cleanupError = error;
222
+ }
223
+ }
224
+ }
225
+ if (stagingDirectory !== undefined) {
226
+ try {
227
+ (0, node_fs_1.rmdirSync)(stagingDirectory);
228
+ }
229
+ catch (error) {
230
+ if (!isErrno(error, 'ENOENT') && cleanupError === undefined) {
231
+ cleanupError = error;
232
+ }
233
+ }
234
+ }
235
+ }
236
+ if (cleanupError !== undefined) {
237
+ throw new Error(`Unable to clean report carry staging directory after ${operationError === undefined ? 'publish' : formatError(operationError)}: ${formatError(cleanupError)}`);
238
+ }
239
+ if (operationError !== undefined) {
240
+ throw operationError;
241
+ }
242
+ }
243
+ class FileReportCarryStore {
244
+ path;
245
+ constructor(path = defaultCarryPath()) {
246
+ this.path = path;
247
+ }
248
+ persistDelivered(input) {
249
+ assertPersistInput(input);
250
+ (0, file_coordination_js_1.withFileCoordinationTransaction)(this.path, 'report carry', () => {
251
+ const current = this.read();
252
+ if (current.kind === 'invalid') {
253
+ throw new Error('Refusing to overwrite invalid report carry state');
254
+ }
255
+ if (current.kind === 'legacy') {
256
+ this.quarantineLegacy();
257
+ }
258
+ if (current.kind === 'record' && current.record.deliveryId === input.deliveryId) {
259
+ const record = current.record;
260
+ if (!sameTarget(record.target, input.target) ||
261
+ record.text !== input.text ||
262
+ !sameProvenance(record.provenance, input.provenance)) {
263
+ throw new Error('Refusing same delivery ID with mismatched report carry content');
264
+ }
265
+ return;
266
+ }
267
+ writeReportCarryAtomically(this.path, {
268
+ version: 2,
269
+ deliveryId: input.deliveryId,
270
+ target: { ...input.target },
271
+ deliveredAt: input.deliveredAt,
272
+ text: input.text,
273
+ provenance: { ...input.provenance },
274
+ });
275
+ });
276
+ }
277
+ peek(target, nowMs = Date.now()) {
278
+ if (!isTarget(target) || !Number.isFinite(nowMs)) {
279
+ return null;
280
+ }
281
+ const current = this.read();
282
+ if (current.kind !== 'record' ||
283
+ current.record.consumedAt !== undefined ||
284
+ !sameTarget(current.record.target, target) ||
285
+ !isActive(current.record, nowMs)) {
62
286
  return null;
63
287
  }
64
- return {
65
- deliveredAt: parsed.deliveredAt,
66
- text: parsed.text,
67
- // A file written before provenance was carried is not the same as a report with no
68
- // run behind it, and flattening the two would make every old record look like a
69
- // failure. Named as its own reason instead.
70
- provenance: isArtifactProvenance(parsed.provenance)
71
- ? parsed.provenance
72
- : { status: 'unavailable', reason: 'legacy_record' },
73
- };
288
+ return { deliveryId: current.record.deliveryId, prefix: buildPrefix(current.record) };
74
289
  }
75
- catch (error) {
76
- // Corrupt state must be LOUD (repo rule), then fall back to no-carry.
77
- console.warn(`[report-carry] carry file corrupt, ignoring (${path}): ${error instanceof Error ? error.message : String(error)}`);
78
- return null;
290
+ acknowledge(input) {
291
+ assertAckInput(input);
292
+ return (0, file_coordination_js_1.withFileCoordinationTransaction)(this.path, 'report carry', () => {
293
+ const current = this.read();
294
+ if (current.kind !== 'record' ||
295
+ current.record.consumedAt !== undefined ||
296
+ !sameTarget(current.record.target, input.target) ||
297
+ current.record.deliveryId !== input.deliveryId ||
298
+ !isActive(current.record, Date.now())) {
299
+ return false;
300
+ }
301
+ writeReportCarryAtomically(this.path, {
302
+ ...current.record,
303
+ consumedAt: input.consumedAtIso,
304
+ consumingChannelKey: input.consumingChannelKey,
305
+ });
306
+ return true;
307
+ });
308
+ }
309
+ read() {
310
+ let raw;
311
+ try {
312
+ raw = (0, node_fs_1.readFileSync)(this.path, 'utf8');
313
+ }
314
+ catch (error) {
315
+ if (isRecord(error) && error.code === 'ENOENT') {
316
+ return { kind: 'missing' };
317
+ }
318
+ this.warn(`could not read carry state: ${formatError(error)}`);
319
+ return { kind: 'invalid' };
320
+ }
321
+ try {
322
+ const parsed = JSON.parse(raw);
323
+ if (isLegacyReportCarry(parsed)) {
324
+ this.warn('legacy unscoped carry state');
325
+ return { kind: 'legacy' };
326
+ }
327
+ if (!isReportCarryV2(parsed)) {
328
+ throw new Error('carry state is not an exact version 2 record');
329
+ }
330
+ return { kind: 'record', record: parsed };
331
+ }
332
+ catch (error) {
333
+ this.warn(`invalid carry state: ${formatError(error)}`);
334
+ return { kind: 'invalid' };
335
+ }
336
+ }
337
+ quarantineLegacy() {
338
+ const quarantinePath = `${this.path}.legacy-v1.${process.pid}.${(0, node_crypto_1.randomUUID)()}.json`;
339
+ (0, node_fs_1.renameSync)(this.path, quarantinePath);
340
+ (0, node_fs_1.chmodSync)(quarantinePath, 0o600);
341
+ console.warn(`[report-carry] quarantined legacy unscoped carry at ${quarantinePath}; ` +
342
+ 'a new target-bound delivery may now replace it');
343
+ }
344
+ warn(message) {
345
+ console.warn(`[report-carry] ${message}; refusing to inject ${this.path}`);
79
346
  }
80
347
  }
81
- /**
82
- * Build the per-turn carry prefix for the owner console. Empty string when no
83
- * report has been delivered yet (nothing to carry - the persona should use
84
- * report_request/board_read instead).
85
- */
86
- function buildReportCarryPrefix(path = defaultCarryPath()) {
87
- const last = loadLastFullReport(path);
88
- if (!last) {
89
- return '';
90
- }
91
- const summary = last.text.length > CARRY_SUMMARY_MAX_CHARS
92
- ? `${last.text.slice(0, CARRY_SUMMARY_MAX_CHARS)}\n[... truncated - full text was delivered to the owner channel]`
93
- : last.text;
94
- // The report is agent-authored but SUMMARIZES third-party content; wrapping
95
- // it keeps reproduced instructions inert across every future turn it rides.
96
- return (`[Operator context] The last FULL situation report was delivered at ${last.deliveredAt}.\n` +
97
- `If the owner asks for a report or current status, reference/refresh THIS instead of ` +
98
- `reconstructing state from memory. Content:\n${(0, untrusted_content_js_1.wrapUntrustedContent)('operator-report-carry', summary)}\n---\n`);
348
+ exports.FileReportCarryStore = FileReportCarryStore;
349
+ function formatError(error) {
350
+ return error instanceof Error ? error.message : String(error);
99
351
  }
100
352
  //# sourceMappingURL=report-carry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"report-carry.js","sourceRoot":"","sources":["../../src/operator/report-carry.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AA4BH,4CAEC;AAGD,sDAiBC;AAcD,gDAiCC;AAOD,wDAmBC;AAzHD,qCAA6E;AAC7E,wEAAqE;AACrE,qCAAkC;AAClC,yCAA0C;AAqB1C,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC,SAAgB,gBAAgB;IAC9B,OAAO,IAAA,gBAAI,EAAC,IAAA,iBAAO,GAAE,EAAE,OAAO,EAAE,UAAU,EAAE,uBAAuB,CAAC,CAAC;AACvE,CAAC;AAED,4FAA4F;AAC5F,SAAgB,qBAAqB,CACnC,cAAsB,EACtB,IAAY,EACZ,UAA8B,EAC9B,OAAe,gBAAgB,EAAE;IAEjC,IAAA,mBAAS,EAAC,IAAA,mBAAO,EAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,MAAM,GAAG,GAAG,IAAA,gBAAI,EAAC,IAAA,mBAAO,EAAC,IAAI,CAAC,EAAE,qBAAqB,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC;IACxE,sDAAsD;IACtD,IAAA,uBAAa,EACX,GAAG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AAE,CAAC;QAC7B,CAAC;IACH,CAAC;IAEO,gBAAgB;QACtB,MAAM,cAAc,GAAG,GAAG,IAAI,CAAC,IAAI,cAAc,OAAO,CAAC,GAAG,IAAI,IAAA,wBAAU,GAAE,OAAO,CAAC;QACpF,IAAA,oBAAU,EAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QACtC,IAAA,mBAAS,EAAC,cAAc,EAAE,KAAK,CAAC,CAAC;QACjC,OAAO,CAAC,IAAI,CACV,uDAAuD,cAAc,IAAI;YACvE,gDAAgD,CACnD,CAAC;IACJ,CAAC;IAEO,IAAI,CAAC,OAAe;QAC1B,OAAO,CAAC,IAAI,CAAC,kBAAkB,OAAO,wBAAwB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7E,CAAC;CACF;AAnHD,oDAmHC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
@@ -18,10 +18,11 @@
18
18
  import type { OperatorChannelEvent, OutputSink } from './operator-interfaces.js';
19
19
  import type { AskAgent } from './trigger-author.js';
20
20
  import type { BackendType } from '../agent/model-runner.js';
21
+ import { type ArtifactProvenance, type ReportCarryTarget } from './report-carry.js';
21
22
  /**
22
23
  * Machine frame tag prepended to the FULL report prompt so the report-run wiring can tell a full
23
- * report from a digest for tool-use auditing (report-run.ts). Kagemusha frames its scheduled full
24
- * report with the same bracketed-tag convention (report-prompts.ts buildFullReportPrompt).
24
+ * report from a digest for tool-use auditing (report-run.ts). The bracketed tag keeps framing
25
+ * source-neutral while remaining machine-readable.
25
26
  */
26
27
  export declare const OPERATOR_FULL_REPORT_TAG = "[operator_full_report]";
27
28
  export interface FireActivity {
@@ -40,6 +41,26 @@ export interface PreparedSituationReport {
40
41
  citedTriggerIds: string[];
41
42
  createdAtIso: string;
42
43
  deliveryId?: string;
44
+ provenance?: ArtifactProvenance;
45
+ target?: ReportCarryTarget;
46
+ payloadIdentity?: string;
47
+ occurrence?: {
48
+ kind: 'digest' | 'scheduled_full' | 'on_demand_full';
49
+ hourKey?: string;
50
+ firedAtIso?: string;
51
+ };
52
+ }
53
+ export interface DeliveredFullReport {
54
+ mode: 'full';
55
+ deliveryId: string;
56
+ citedTriggerIds: string[];
57
+ createdAtIso: string;
58
+ deliveredAtIso: string;
59
+ text: string;
60
+ provenance: ArtifactProvenance;
61
+ target?: ReportCarryTarget;
62
+ payloadIdentity?: string;
63
+ occurrence?: PreparedSituationReport['occurrence'];
43
64
  }
44
65
  export interface SituationReporterSnapshot {
45
66
  version: 1;
@@ -69,8 +90,8 @@ export interface SituationReporterOptions {
69
90
  /**
70
91
  * M2.3: tool-call instructions injected into the FULL report framing so the agent
71
92
  * ACTIVELY gathers current context (channels, tasks, memory) before writing - the
72
- * lesson from Kagemusha, whose report prompt instructs its agent to call its tools
73
- * (and which deleted its deterministic report builder for low quality). The lines
93
+ * lesson from the reference owner console: report prompts instruct the agent to call tools
94
+ * instead of relying on a low-quality deterministic report builder. The lines
74
95
  * are injected from the runtime wiring (which knows the daemon's toolset); this
75
96
  * module stays generic. Digest mode never uses them (frequent + must stay light).
76
97
  *
@@ -80,7 +101,7 @@ export interface SituationReporterOptions {
80
101
  */
81
102
  selfGatherLines?: string[] | (() => string[]);
82
103
  /**
83
- * Kagemusha dual-output mechanism: lines instructing the FULL report run to also
104
+ * Dual-output mechanism: lines instructing the FULL report run to also
84
105
  * publish the operator board slots (report_publish) before writing the text
85
106
  * report. Injected from runtime wiring (board-slot-instructions.ts); digest mode
86
107
  * never publishes the board.
@@ -94,12 +115,10 @@ export interface SituationReporterOptions {
94
115
  * of being elimination-only. Uncited fires stay NEUTRAL - not failures.
95
116
  */
96
117
  recordTriggerUse?: (triggerIds: string[]) => void;
97
- /**
98
- * Context carry (plan v6 S1-T4): called with (deliveredAtIso, reportText)
99
- * after a FULL report is successfully delivered. Runtime wiring persists it
100
- * so the owner console can reference the latest report per chat turn.
101
- */
102
- persistLastFullReport?: (deliveredAtIso: string, text: string) => void;
118
+ /** Reads the provenance of the run that just composed a FULL report. */
119
+ fullReportProvenance?: () => ArtifactProvenance;
120
+ /** Called only after a FULL report has definitely been delivered. */
121
+ persistLastFullReport?: (report: DeliveredFullReport) => void;
103
122
  }
104
123
  export declare class SituationReporter {
105
124
  private windowByChannel;