comisai 1.0.34 → 1.0.37

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 (448) hide show
  1. package/node_modules/@comis/agent/dist/background/auto-background-middleware.d.ts +11 -1
  2. package/node_modules/@comis/agent/dist/background/auto-background-middleware.js +30 -4
  3. package/node_modules/@comis/agent/dist/background/background-task-manager.d.ts +22 -2
  4. package/node_modules/@comis/agent/dist/background/background-task-manager.js +88 -40
  5. package/node_modules/@comis/agent/dist/background/background-task-persistence.js +34 -4
  6. package/node_modules/@comis/agent/dist/background/background-task-types.d.ts +59 -3
  7. package/node_modules/@comis/agent/dist/background/background-task-types.js +1 -1
  8. package/node_modules/@comis/agent/dist/background/completion-dispatcher.d.ts +130 -0
  9. package/node_modules/@comis/agent/dist/background/completion-dispatcher.js +215 -0
  10. package/node_modules/@comis/agent/dist/background/completion-formatter.d.ts +39 -0
  11. package/node_modules/@comis/agent/dist/background/completion-formatter.js +77 -0
  12. package/node_modules/@comis/agent/dist/background/completion-runner.d.ts +62 -0
  13. package/node_modules/@comis/agent/dist/background/completion-runner.js +234 -0
  14. package/node_modules/@comis/agent/dist/background/index.d.ts +10 -1
  15. package/node_modules/@comis/agent/dist/background/index.js +4 -0
  16. package/node_modules/@comis/agent/dist/background/session-resolver.d.ts +85 -0
  17. package/node_modules/@comis/agent/dist/background/session-resolver.js +78 -0
  18. package/node_modules/@comis/agent/dist/bootstrap/sections/messaging-sections.js +1 -0
  19. package/node_modules/@comis/agent/dist/bootstrap/sections/tool-descriptions.js +3 -3
  20. package/node_modules/@comis/agent/dist/bootstrap/sections/tooling-sections.d.ts +30 -2
  21. package/node_modules/@comis/agent/dist/bootstrap/sections/tooling-sections.js +51 -2
  22. package/node_modules/@comis/agent/dist/bootstrap/system-prompt-assembler.d.ts +22 -0
  23. package/node_modules/@comis/agent/dist/bootstrap/system-prompt-assembler.js +2 -2
  24. package/node_modules/@comis/agent/dist/bridge/bridge-event-handlers.d.ts +1 -5
  25. package/node_modules/@comis/agent/dist/bridge/bridge-event-handlers.js +2 -14
  26. package/node_modules/@comis/agent/dist/bridge/bridge-metrics.d.ts +43 -2
  27. package/node_modules/@comis/agent/dist/bridge/bridge-metrics.js +17 -2
  28. package/node_modules/@comis/agent/dist/bridge/pi-event-bridge.d.ts +32 -23
  29. package/node_modules/@comis/agent/dist/bridge/pi-event-bridge.js +145 -62
  30. package/node_modules/@comis/agent/dist/bridge/thinking-block-hash-invariant.d.ts +6 -7
  31. package/node_modules/@comis/agent/dist/bridge/thinking-block-hash-invariant.js +24 -25
  32. package/node_modules/@comis/agent/dist/budget/cost-tracker.d.ts +1 -1
  33. package/node_modules/@comis/agent/dist/context-engine/constants.d.ts +5 -5
  34. package/node_modules/@comis/agent/dist/context-engine/constants.js +12 -12
  35. package/node_modules/@comis/agent/dist/context-engine/context-engine.js +13 -4
  36. package/node_modules/@comis/agent/dist/context-engine/dag-annotator.d.ts +1 -2
  37. package/node_modules/@comis/agent/dist/context-engine/dag-annotator.js +1 -2
  38. package/node_modules/@comis/agent/dist/context-engine/llm-compaction.js +20 -16
  39. package/node_modules/@comis/agent/dist/context-engine/rehydration.js +6 -6
  40. package/node_modules/@comis/agent/dist/context-engine/signature-replay-scrubber.d.ts +12 -12
  41. package/node_modules/@comis/agent/dist/context-engine/signature-replay-scrubber.js +36 -22
  42. package/node_modules/@comis/agent/dist/context-engine/signature-surrogate-guard.d.ts +10 -10
  43. package/node_modules/@comis/agent/dist/context-engine/signature-surrogate-guard.js +14 -14
  44. package/node_modules/@comis/agent/dist/context-engine/thinking-block-cleaner.d.ts +11 -13
  45. package/node_modules/@comis/agent/dist/context-engine/thinking-block-cleaner.js +14 -15
  46. package/node_modules/@comis/agent/dist/context-engine/types-core.d.ts +15 -0
  47. package/node_modules/@comis/agent/dist/executor/cache-break-detection.d.ts +6 -6
  48. package/node_modules/@comis/agent/dist/executor/cache-break-detection.js +8 -8
  49. package/node_modules/@comis/agent/dist/executor/capability-index-context.d.ts +72 -0
  50. package/node_modules/@comis/agent/dist/executor/capability-index-context.js +329 -0
  51. package/node_modules/@comis/agent/dist/executor/drain-helper.d.ts +122 -0
  52. package/node_modules/@comis/agent/dist/executor/drain-helper.js +173 -0
  53. package/node_modules/@comis/agent/dist/executor/error-classifier.js +2 -2
  54. package/node_modules/@comis/agent/dist/executor/executor-context-engine-setup.d.ts +16 -0
  55. package/node_modules/@comis/agent/dist/executor/executor-context-engine-setup.js +46 -5
  56. package/node_modules/@comis/agent/dist/executor/executor-post-execution.d.ts +78 -4
  57. package/node_modules/@comis/agent/dist/executor/executor-post-execution.js +150 -31
  58. package/node_modules/@comis/agent/dist/executor/executor-prompt-runner.d.ts +7 -0
  59. package/node_modules/@comis/agent/dist/executor/executor-prompt-runner.js +26 -5
  60. package/node_modules/@comis/agent/dist/executor/executor-response-filter.d.ts +7 -6
  61. package/node_modules/@comis/agent/dist/executor/executor-response-filter.js +9 -42
  62. package/node_modules/@comis/agent/dist/executor/executor-tool-assembly.d.ts +18 -1
  63. package/node_modules/@comis/agent/dist/executor/executor-tool-assembly.js +20 -18
  64. package/node_modules/@comis/agent/dist/executor/gemini-cache-injector.d.ts +2 -2
  65. package/node_modules/@comis/agent/dist/executor/gemini-cache-injector.js +4 -4
  66. package/node_modules/@comis/agent/dist/executor/jit-guide-injector.d.ts +11 -2
  67. package/node_modules/@comis/agent/dist/executor/jit-guide-injector.js +16 -2
  68. package/node_modules/@comis/agent/dist/executor/phase-filter.d.ts +2 -2
  69. package/node_modules/@comis/agent/dist/executor/phase-filter.js +5 -7
  70. package/node_modules/@comis/agent/dist/executor/pi-executor.d.ts +21 -2
  71. package/node_modules/@comis/agent/dist/executor/pi-executor.js +96 -18
  72. package/node_modules/@comis/agent/dist/executor/post-batch-continuation.js +7 -7
  73. package/node_modules/@comis/agent/dist/executor/prompt-assembly.d.ts +9 -1
  74. package/node_modules/@comis/agent/dist/executor/prompt-assembly.js +15 -1
  75. package/node_modules/@comis/agent/dist/executor/stream-wrappers/request-body-injector.d.ts +1 -1
  76. package/node_modules/@comis/agent/dist/executor/stream-wrappers/request-body-injector.js +1 -1
  77. package/node_modules/@comis/agent/dist/executor/tool-deferral.d.ts +18 -27
  78. package/node_modules/@comis/agent/dist/executor/tool-deferral.js +34 -43
  79. package/node_modules/@comis/agent/dist/index.d.ts +17 -0
  80. package/node_modules/@comis/agent/dist/index.js +32 -11
  81. package/node_modules/@comis/agent/dist/model/auth-provider.d.ts +25 -2
  82. package/node_modules/@comis/agent/dist/model/auth-provider.js +6 -0
  83. package/node_modules/@comis/agent/dist/model/compaction-model-resolver.d.ts +3 -3
  84. package/node_modules/@comis/agent/dist/model/compaction-model-resolver.js +3 -3
  85. package/node_modules/@comis/agent/dist/model/model-registry-adapter.js +1 -1
  86. package/node_modules/@comis/agent/dist/model/model-scanner.js +1 -1
  87. package/node_modules/@comis/agent/dist/model/oauth-credential-store-file.d.ts +37 -0
  88. package/node_modules/@comis/agent/dist/model/oauth-credential-store-file.js +279 -0
  89. package/node_modules/@comis/agent/dist/model/oauth-credential-store-selector.d.ts +49 -0
  90. package/node_modules/@comis/agent/dist/model/oauth-credential-store-selector.js +50 -0
  91. package/node_modules/@comis/agent/dist/model/oauth-device-code.d.ts +57 -0
  92. package/node_modules/@comis/agent/dist/model/oauth-device-code.js +302 -0
  93. package/node_modules/@comis/agent/dist/model/oauth-env.d.ts +33 -0
  94. package/node_modules/@comis/agent/dist/model/oauth-env.js +38 -0
  95. package/node_modules/@comis/agent/dist/model/oauth-errors.d.ts +41 -0
  96. package/node_modules/@comis/agent/dist/model/oauth-errors.js +88 -0
  97. package/node_modules/@comis/agent/dist/model/oauth-identity.d.ts +53 -0
  98. package/node_modules/@comis/agent/dist/model/oauth-identity.js +141 -0
  99. package/node_modules/@comis/agent/dist/model/oauth-login-runner.d.ts +99 -0
  100. package/node_modules/@comis/agent/dist/model/oauth-login-runner.js +374 -0
  101. package/node_modules/@comis/agent/dist/model/oauth-tls-preflight.d.ts +58 -0
  102. package/node_modules/@comis/agent/dist/model/oauth-tls-preflight.js +82 -0
  103. package/node_modules/@comis/agent/dist/model/oauth-token-manager.d.ts +86 -16
  104. package/node_modules/@comis/agent/dist/model/oauth-token-manager.js +961 -66
  105. package/node_modules/@comis/agent/dist/model/operation-model-defaults.d.ts +9 -4
  106. package/node_modules/@comis/agent/dist/model/operation-model-defaults.js +36 -9
  107. package/node_modules/@comis/agent/dist/model/resolve-provider-api-key.d.ts +48 -0
  108. package/node_modules/@comis/agent/dist/model/resolve-provider-api-key.js +66 -0
  109. package/node_modules/@comis/agent/dist/provider/capabilities.d.ts +5 -5
  110. package/node_modules/@comis/agent/dist/provider/capabilities.js +10 -23
  111. package/node_modules/@comis/agent/dist/safety/tool-output-safety.js +3 -3
  112. package/node_modules/@comis/agent/dist/safety/tool-retry-breaker.d.ts +11 -1
  113. package/node_modules/@comis/agent/dist/safety/tool-retry-breaker.js +19 -22
  114. package/node_modules/@comis/agent/dist/session/comis-session-manager.d.ts +17 -3
  115. package/node_modules/@comis/agent/dist/session/comis-session-manager.js +1 -1
  116. package/node_modules/@comis/agent/dist/spawn/narrative-caster.d.ts +10 -0
  117. package/node_modules/@comis/agent/dist/spawn/narrative-caster.js +5 -1
  118. package/node_modules/@comis/agent/dist/spawn/pi-mono-adapters.d.ts +1 -1
  119. package/node_modules/@comis/agent/dist/spawn/pi-mono-adapters.js +5 -5
  120. package/node_modules/@comis/agent/dist/workspace/data-env.d.ts +38 -0
  121. package/node_modules/@comis/agent/dist/workspace/data-env.js +56 -0
  122. package/node_modules/@comis/agent/dist/workspace/index.d.ts +1 -0
  123. package/node_modules/@comis/agent/dist/workspace/index.js +1 -0
  124. package/node_modules/@comis/agent/dist/workspace/templates.js +5 -1
  125. package/node_modules/@comis/agent/package.json +1 -1
  126. package/node_modules/@comis/channels/dist/email/email-adapter.js +6 -6
  127. package/node_modules/@comis/channels/dist/email/imap-lifecycle.js +7 -7
  128. package/node_modules/@comis/channels/dist/index.d.ts +1 -1
  129. package/node_modules/@comis/channels/dist/index.js +1 -1
  130. package/node_modules/@comis/channels/dist/shared/channel-manager.d.ts +9 -3
  131. package/node_modules/@comis/channels/dist/shared/deliver-to-channel.js +12 -10
  132. package/node_modules/@comis/channels/dist/shared/inbound-gate.d.ts +1 -1
  133. package/node_modules/@comis/channels/dist/shared/inbound-gate.js +22 -7
  134. package/node_modules/@comis/channels/dist/shared/inbound-pipeline.d.ts +10 -3
  135. package/node_modules/@comis/channels/dist/shared/inbound-route.d.ts +1 -1
  136. package/node_modules/@comis/channels/dist/shared/inbound-route.js +13 -2
  137. package/node_modules/@comis/channels/dist/shared/response-filter.d.ts +11 -24
  138. package/node_modules/@comis/channels/dist/shared/response-filter.js +25 -53
  139. package/node_modules/@comis/channels/dist/telegram/telegram-adapter.js +1 -1
  140. package/node_modules/@comis/channels/package.json +1 -1
  141. package/node_modules/@comis/cli/dist/cli.js +2 -0
  142. package/node_modules/@comis/cli/dist/commands/agent.d.ts +3 -3
  143. package/node_modules/@comis/cli/dist/commands/agent.js +46 -3
  144. package/node_modules/@comis/cli/dist/commands/auth.d.ts +37 -0
  145. package/node_modules/@comis/cli/dist/commands/auth.js +433 -0
  146. package/node_modules/@comis/cli/dist/commands/doctor.d.ts +4 -1
  147. package/node_modules/@comis/cli/dist/commands/doctor.js +20 -5
  148. package/node_modules/@comis/cli/dist/commands/providers.d.ts +1 -2
  149. package/node_modules/@comis/cli/dist/commands/providers.js +5 -6
  150. package/node_modules/@comis/cli/dist/doctor/checks/oauth-health.d.ts +39 -0
  151. package/node_modules/@comis/cli/dist/doctor/checks/oauth-health.js +399 -0
  152. package/node_modules/@comis/cli/dist/doctor/types.d.ts +19 -0
  153. package/node_modules/@comis/cli/dist/index.d.ts +1 -0
  154. package/node_modules/@comis/cli/dist/index.js +10 -4
  155. package/node_modules/@comis/cli/dist/output/relative-time.d.ts +23 -0
  156. package/node_modules/@comis/cli/dist/output/relative-time.js +36 -0
  157. package/node_modules/@comis/cli/dist/wizard/non-interactive.js +17 -8
  158. package/node_modules/@comis/cli/dist/wizard/steps/03-provider.js +2 -1
  159. package/node_modules/@comis/cli/dist/wizard/steps/04-credentials.js +223 -34
  160. package/node_modules/@comis/cli/dist/wizard/steps/10-write-config.js +14 -0
  161. package/node_modules/@comis/cli/dist/wizard/steps/11-daemon-start.js +3 -3
  162. package/node_modules/@comis/cli/dist/wizard/types.d.ts +7 -0
  163. package/node_modules/@comis/cli/package.json +1 -1
  164. package/node_modules/@comis/core/dist/bootstrap.d.ts +1 -1
  165. package/node_modules/@comis/core/dist/config/env-substitution.d.ts +66 -0
  166. package/node_modules/@comis/core/dist/config/env-substitution.js +115 -0
  167. package/node_modules/@comis/core/dist/config/field-metadata.js +2 -0
  168. package/node_modules/@comis/core/dist/config/immutable-keys.js +4 -1
  169. package/node_modules/@comis/core/dist/config/index.d.ts +7 -1
  170. package/node_modules/@comis/core/dist/config/index.js +4 -1
  171. package/node_modules/@comis/core/dist/config/loader.js +61 -0
  172. package/node_modules/@comis/core/dist/config/managed-sections.d.ts +3 -3
  173. package/node_modules/@comis/core/dist/config/managed-sections.js +10 -5
  174. package/node_modules/@comis/core/dist/config/schema-agent.d.ts +4 -792
  175. package/node_modules/@comis/core/dist/config/schema-agent.js +16 -1
  176. package/node_modules/@comis/core/dist/config/schema-approvals.d.ts +0 -14
  177. package/node_modules/@comis/core/dist/config/schema-auto-reply-engine.d.ts +0 -6
  178. package/node_modules/@comis/core/dist/config/schema-background-tasks.d.ts +1 -6
  179. package/node_modules/@comis/core/dist/config/schema-background-tasks.js +7 -0
  180. package/node_modules/@comis/core/dist/config/schema-browser.d.ts +0 -18
  181. package/node_modules/@comis/core/dist/config/schema-channel.d.ts +0 -158
  182. package/node_modules/@comis/core/dist/config/schema-coalescer.d.ts +0 -5
  183. package/node_modules/@comis/core/dist/config/schema-daemon.d.ts +0 -32
  184. package/node_modules/@comis/core/dist/config/schema-delivery.d.ts +1 -17
  185. package/node_modules/@comis/core/dist/config/schema-delivery.js +2 -0
  186. package/node_modules/@comis/core/dist/config/schema-documentation.d.ts +0 -12
  187. package/node_modules/@comis/core/dist/config/schema-embedding.d.ts +0 -20
  188. package/node_modules/@comis/core/dist/config/schema-envelope.d.ts +0 -15
  189. package/node_modules/@comis/core/dist/config/schema-gateway.d.ts +0 -37
  190. package/node_modules/@comis/core/dist/config/schema-gemini-cache.d.ts +0 -4
  191. package/node_modules/@comis/core/dist/config/schema-gemini-cache.js +0 -2
  192. package/node_modules/@comis/core/dist/config/schema-integrations.d.ts +0 -318
  193. package/node_modules/@comis/core/dist/config/schema-lifecycle-reactions.d.ts +0 -18
  194. package/node_modules/@comis/core/dist/config/schema-memory-review.d.ts +0 -7
  195. package/node_modules/@comis/core/dist/config/schema-memory.d.ts +0 -16
  196. package/node_modules/@comis/core/dist/config/schema-messages.d.ts +0 -8
  197. package/node_modules/@comis/core/dist/config/schema-models.d.ts +0 -15
  198. package/node_modules/@comis/core/dist/config/schema-notification.d.ts +0 -5
  199. package/node_modules/@comis/core/dist/config/schema-oauth.d.ts +18 -0
  200. package/node_modules/@comis/core/dist/config/schema-oauth.js +19 -0
  201. package/node_modules/@comis/core/dist/config/schema-observability.d.ts +0 -38
  202. package/node_modules/@comis/core/dist/config/schema-output-retention.d.ts +34 -0
  203. package/node_modules/@comis/core/dist/config/schema-output-retention.js +48 -0
  204. package/node_modules/@comis/core/dist/config/schema-plugins.d.ts +0 -8
  205. package/node_modules/@comis/core/dist/config/schema-providers.d.ts +0 -64
  206. package/node_modules/@comis/core/dist/config/schema-queue.d.ts +0 -58
  207. package/node_modules/@comis/core/dist/config/schema-response-prefix.d.ts +0 -2
  208. package/node_modules/@comis/core/dist/config/schema-retry.d.ts +0 -6
  209. package/node_modules/@comis/core/dist/config/schema-scheduler.d.ts +0 -39
  210. package/node_modules/@comis/core/dist/config/schema-secrets.d.ts +0 -3
  211. package/node_modules/@comis/core/dist/config/schema-security.d.ts +0 -18
  212. package/node_modules/@comis/core/dist/config/schema-send-policy.d.ts +0 -13
  213. package/node_modules/@comis/core/dist/config/schema-sender-trust-display.d.ts +0 -5
  214. package/node_modules/@comis/core/dist/config/schema-serializer.js +2 -0
  215. package/node_modules/@comis/core/dist/config/schema-skills.d.ts +0 -63
  216. package/node_modules/@comis/core/dist/config/schema-skills.js +3 -4
  217. package/node_modules/@comis/core/dist/config/schema-streaming.d.ts +0 -38
  218. package/node_modules/@comis/core/dist/config/schema-telegram-file-guard.d.ts +0 -3
  219. package/node_modules/@comis/core/dist/config/schema-tooling.d.ts +87 -0
  220. package/node_modules/@comis/core/dist/config/schema-tooling.js +152 -0
  221. package/node_modules/@comis/core/dist/config/schema-verbosity.d.ts +0 -12
  222. package/node_modules/@comis/core/dist/config/schema-webhooks.d.ts +0 -40
  223. package/node_modules/@comis/core/dist/config/schema.d.ts +50 -37
  224. package/node_modules/@comis/core/dist/config/schema.js +9 -0
  225. package/node_modules/@comis/core/dist/context/context.d.ts +0 -4
  226. package/node_modules/@comis/core/dist/domain/approval-request.d.ts +0 -17
  227. package/node_modules/@comis/core/dist/domain/background-task-origin.d.ts +29 -0
  228. package/node_modules/@comis/core/dist/domain/background-task-origin.js +39 -0
  229. package/node_modules/@comis/core/dist/domain/delivery-origin.d.ts +0 -5
  230. package/node_modules/@comis/core/dist/domain/execution-graph.d.ts +0 -48
  231. package/node_modules/@comis/core/dist/domain/memory-entry.d.ts +0 -3
  232. package/node_modules/@comis/core/dist/domain/model-compat.d.ts +0 -4
  233. package/node_modules/@comis/core/dist/domain/normalized-message.d.ts +0 -15
  234. package/node_modules/@comis/core/dist/domain/provider-capabilities.d.ts +0 -6
  235. package/node_modules/@comis/core/dist/domain/rich-message.d.ts +0 -14
  236. package/node_modules/@comis/core/dist/domain/subagent-context-config.d.ts +0 -22
  237. package/node_modules/@comis/core/dist/domain/subagent-context-types.d.ts +0 -8
  238. package/node_modules/@comis/core/dist/event-bus/events-agent.d.ts +31 -0
  239. package/node_modules/@comis/core/dist/event-bus/events-infra.d.ts +76 -2
  240. package/node_modules/@comis/core/dist/exports/config.d.ts +2 -2
  241. package/node_modules/@comis/core/dist/exports/config.js +3 -1
  242. package/node_modules/@comis/core/dist/exports/domain.d.ts +2 -0
  243. package/node_modules/@comis/core/dist/exports/domain.js +1 -0
  244. package/node_modules/@comis/core/dist/exports/hooks.d.ts +1 -1
  245. package/node_modules/@comis/core/dist/exports/ports.d.ts +2 -2
  246. package/node_modules/@comis/core/dist/exports/ports.js +1 -1
  247. package/node_modules/@comis/core/dist/ports/channel-plugin.d.ts +0 -13
  248. package/node_modules/@comis/core/dist/ports/delivery-queue.d.ts +23 -0
  249. package/node_modules/@comis/core/dist/ports/delivery-queue.js +2 -0
  250. package/node_modules/@comis/core/dist/ports/index.d.ts +4 -0
  251. package/node_modules/@comis/core/dist/ports/index.js +5 -0
  252. package/node_modules/@comis/core/dist/ports/no-op-tool-capability.d.ts +30 -0
  253. package/node_modules/@comis/core/dist/ports/no-op-tool-capability.js +47 -0
  254. package/node_modules/@comis/core/dist/ports/oauth-credential-store.d.ts +64 -0
  255. package/node_modules/@comis/core/dist/ports/oauth-credential-store.js +37 -0
  256. package/node_modules/@comis/core/dist/ports/tool-capability.d.ts +165 -0
  257. package/node_modules/@comis/core/dist/ports/tool-capability.js +15 -0
  258. package/node_modules/@comis/core/dist/security/audit.d.ts +0 -11
  259. package/node_modules/@comis/core/dist/tool-metadata.d.ts +41 -1
  260. package/node_modules/@comis/core/dist/tool-metadata.js +1 -1
  261. package/node_modules/@comis/core/package.json +1 -1
  262. package/node_modules/@comis/daemon/bundled-skills/skill-creator/scripts/validate-skill.py +1 -1
  263. package/node_modules/@comis/daemon/dist/daemon-types.d.ts +23 -3
  264. package/node_modules/@comis/daemon/dist/daemon.js +168 -30
  265. package/node_modules/@comis/daemon/dist/index.d.ts +2 -0
  266. package/node_modules/@comis/daemon/dist/index.js +5 -0
  267. package/node_modules/@comis/daemon/dist/observability/channel-health-logger.js +3 -3
  268. package/node_modules/@comis/daemon/dist/observability/delivery-queue-logger.js +1 -1
  269. package/node_modules/@comis/daemon/dist/rpc/agent-handlers.d.ts +22 -1
  270. package/node_modules/@comis/daemon/dist/rpc/agent-handlers.js +84 -21
  271. package/node_modules/@comis/daemon/dist/rpc/agent-inline-workspace.d.ts +1 -1
  272. package/node_modules/@comis/daemon/dist/rpc/agent-inline-workspace.js +3 -3
  273. package/node_modules/@comis/daemon/dist/rpc/builtin-provider-guard.js +2 -2
  274. package/node_modules/@comis/daemon/dist/rpc/config-handlers.d.ts +9 -1
  275. package/node_modules/@comis/daemon/dist/rpc/config-handlers.js +104 -23
  276. package/node_modules/@comis/daemon/dist/rpc/credential-resolver.d.ts +30 -1
  277. package/node_modules/@comis/daemon/dist/rpc/credential-resolver.js +74 -11
  278. package/node_modules/@comis/daemon/dist/rpc/mcp-handlers.d.ts +8 -0
  279. package/node_modules/@comis/daemon/dist/rpc/mcp-handlers.js +22 -8
  280. package/node_modules/@comis/daemon/dist/rpc/model-handlers.d.ts +1 -1
  281. package/node_modules/@comis/daemon/dist/rpc/model-handlers.js +2 -2
  282. package/node_modules/@comis/daemon/dist/rpc/provider-handlers.js +9 -12
  283. package/node_modules/@comis/daemon/dist/rpc/rpc-dispatch.d.ts +1 -0
  284. package/node_modules/@comis/daemon/dist/rpc/rpc-dispatch.js +27 -2
  285. package/node_modules/@comis/daemon/dist/setup-docker-restart-warn.js +0 -1
  286. package/node_modules/@comis/daemon/dist/sub-agent-runner.d.ts +18 -0
  287. package/node_modules/@comis/daemon/dist/sub-agent-runner.js +41 -9
  288. package/node_modules/@comis/daemon/dist/wiring/index.d.ts +4 -0
  289. package/node_modules/@comis/daemon/dist/wiring/index.js +2 -0
  290. package/node_modules/@comis/daemon/dist/wiring/oauth-preflight.d.ts +21 -0
  291. package/node_modules/@comis/daemon/dist/wiring/oauth-preflight.js +134 -0
  292. package/node_modules/@comis/daemon/dist/wiring/setup-agents.d.ts +81 -2
  293. package/node_modules/@comis/daemon/dist/wiring/setup-agents.js +164 -3
  294. package/node_modules/@comis/daemon/dist/wiring/setup-background-completion-runner.d.ts +58 -0
  295. package/node_modules/@comis/daemon/dist/wiring/setup-background-completion-runner.js +59 -0
  296. package/node_modules/@comis/daemon/dist/wiring/setup-background-tasks.d.ts +10 -3
  297. package/node_modules/@comis/daemon/dist/wiring/setup-background-tasks.js +13 -7
  298. package/node_modules/@comis/daemon/dist/wiring/setup-channels.d.ts +9 -2
  299. package/node_modules/@comis/daemon/dist/wiring/setup-channels.js +35 -10
  300. package/node_modules/@comis/daemon/dist/wiring/setup-cross-session.d.ts +20 -5
  301. package/node_modules/@comis/daemon/dist/wiring/setup-cross-session.js +21 -16
  302. package/node_modules/@comis/daemon/dist/wiring/setup-delivery.d.ts +14 -5
  303. package/node_modules/@comis/daemon/dist/wiring/setup-delivery.js +65 -20
  304. package/node_modules/@comis/daemon/dist/wiring/setup-gateway.d.ts +4 -6
  305. package/node_modules/@comis/daemon/dist/wiring/setup-gateway.js +3 -5
  306. package/node_modules/@comis/daemon/dist/wiring/setup-heartbeat.d.ts +20 -5
  307. package/node_modules/@comis/daemon/dist/wiring/setup-heartbeat.js +11 -2
  308. package/node_modules/@comis/daemon/dist/wiring/setup-output-retention.d.ts +89 -0
  309. package/node_modules/@comis/daemon/dist/wiring/setup-output-retention.js +212 -0
  310. package/node_modules/@comis/daemon/dist/wiring/setup-schedulers.js +4 -0
  311. package/node_modules/@comis/daemon/dist/wiring/setup-tools.d.ts +18 -4
  312. package/node_modules/@comis/daemon/dist/wiring/setup-tools.js +29 -10
  313. package/node_modules/@comis/daemon/dist/wiring/tool-capability-adapter.d.ts +75 -0
  314. package/node_modules/@comis/daemon/dist/wiring/tool-capability-adapter.js +253 -0
  315. package/node_modules/@comis/daemon/package.json +1 -1
  316. package/node_modules/@comis/gateway/dist/index.d.ts +2 -0
  317. package/node_modules/@comis/gateway/dist/index.js +2 -0
  318. package/node_modules/@comis/gateway/dist/oauth/oauth-callback-route.d.ts +66 -0
  319. package/node_modules/@comis/gateway/dist/oauth/oauth-callback-route.js +212 -0
  320. package/node_modules/@comis/gateway/dist/server/hono-server.d.ts +14 -0
  321. package/node_modules/@comis/gateway/dist/server/hono-server.js +10 -0
  322. package/node_modules/@comis/gateway/dist/webhook/webhook-endpoint.d.ts +0 -4
  323. package/node_modules/@comis/gateway/package.json +1 -1
  324. package/node_modules/@comis/infra/dist/logging/log-fields.d.ts +23 -0
  325. package/node_modules/@comis/infra/package.json +1 -1
  326. package/node_modules/@comis/memory/dist/compaction.d.ts +3 -5
  327. package/node_modules/@comis/memory/dist/compaction.js +2 -3
  328. package/node_modules/@comis/memory/dist/delivery-queue-adapter.d.ts +2 -2
  329. package/node_modules/@comis/memory/dist/delivery-queue-adapter.js +49 -1
  330. package/node_modules/@comis/memory/dist/index.d.ts +2 -0
  331. package/node_modules/@comis/memory/dist/index.js +3 -0
  332. package/node_modules/@comis/memory/dist/memory-api.d.ts +1 -1
  333. package/node_modules/@comis/memory/dist/memory-api.js +1 -1
  334. package/node_modules/@comis/memory/dist/oauth-profile-schema.d.ts +17 -0
  335. package/node_modules/@comis/memory/dist/oauth-profile-schema.js +33 -0
  336. package/node_modules/@comis/memory/dist/oauth-profile-store-encrypted.d.ts +27 -0
  337. package/node_modules/@comis/memory/dist/oauth-profile-store-encrypted.js +144 -0
  338. package/node_modules/@comis/memory/dist/session-store.d.ts +1 -1
  339. package/node_modules/@comis/memory/dist/session-store.js +1 -1
  340. package/node_modules/@comis/memory/dist/sqlite-secret-store.d.ts +29 -3
  341. package/node_modules/@comis/memory/dist/sqlite-secret-store.js +11 -3
  342. package/node_modules/@comis/memory/package.json +1 -1
  343. package/node_modules/@comis/scheduler/dist/cron/cron-types.d.ts +0 -42
  344. package/node_modules/@comis/scheduler/dist/execution/execution-lock.d.ts +13 -0
  345. package/node_modules/@comis/scheduler/dist/execution/execution-lock.js +1 -1
  346. package/node_modules/@comis/scheduler/dist/execution/index.d.ts +2 -0
  347. package/node_modules/@comis/scheduler/dist/execution/index.js +2 -0
  348. package/node_modules/@comis/scheduler/dist/heartbeat/agent-heartbeat-source.d.ts +29 -8
  349. package/node_modules/@comis/scheduler/dist/heartbeat/agent-heartbeat-source.js +20 -8
  350. package/node_modules/@comis/scheduler/dist/index.d.ts +2 -0
  351. package/node_modules/@comis/scheduler/dist/index.js +2 -0
  352. package/node_modules/@comis/scheduler/dist/system-events/system-event-types.d.ts +0 -3
  353. package/node_modules/@comis/scheduler/dist/tasks/task-types.d.ts +0 -17
  354. package/node_modules/@comis/scheduler/package.json +1 -1
  355. package/node_modules/@comis/shared/dist/index.d.ts +3 -0
  356. package/node_modules/@comis/shared/dist/index.js +4 -0
  357. package/node_modules/@comis/shared/dist/mcp-tool-name.d.ts +78 -0
  358. package/node_modules/@comis/shared/dist/mcp-tool-name.js +92 -0
  359. package/node_modules/@comis/shared/dist/silent-tokens.d.ts +38 -0
  360. package/node_modules/@comis/shared/dist/silent-tokens.js +51 -0
  361. package/node_modules/@comis/shared/dist/visible-delivery.d.ts +28 -0
  362. package/node_modules/@comis/shared/dist/visible-delivery.js +16 -0
  363. package/node_modules/@comis/shared/package.json +1 -1
  364. package/node_modules/@comis/skills/dist/bridge/mcp-tool-bridge.d.ts +2 -13
  365. package/node_modules/@comis/skills/dist/bridge/mcp-tool-bridge.js +3 -21
  366. package/node_modules/@comis/skills/dist/bridge/schema-validator.d.ts +38 -0
  367. package/node_modules/@comis/skills/dist/bridge/schema-validator.js +169 -0
  368. package/node_modules/@comis/skills/dist/bridge/tool-metadata-enforcement.js +12 -0
  369. package/node_modules/@comis/skills/dist/bridge/tool-metadata-registry.js +133 -3
  370. package/node_modules/@comis/skills/dist/builtin/exec-diagnostics.d.ts +32 -0
  371. package/node_modules/@comis/skills/dist/builtin/exec-diagnostics.js +127 -0
  372. package/node_modules/@comis/skills/dist/builtin/exec-security.js +38 -0
  373. package/node_modules/@comis/skills/dist/builtin/exec-tool.d.ts +55 -9
  374. package/node_modules/@comis/skills/dist/builtin/exec-tool.js +392 -19
  375. package/node_modules/@comis/skills/dist/builtin/file-tools/grep-tool.js +6 -6
  376. package/node_modules/@comis/skills/dist/builtin/install-detour.d.ts +67 -0
  377. package/node_modules/@comis/skills/dist/builtin/install-detour.js +342 -0
  378. package/node_modules/@comis/skills/dist/builtin/platform/admin-manage-factory.js +5 -5
  379. package/node_modules/@comis/skills/dist/builtin/platform/agents-manage-tool.d.ts +7 -6
  380. package/node_modules/@comis/skills/dist/builtin/platform/agents-manage-tool.js +40 -29
  381. package/node_modules/@comis/skills/dist/builtin/platform/background-tasks-tool.d.ts +4 -1
  382. package/node_modules/@comis/skills/dist/builtin/platform/background-tasks-tool.js +3 -3
  383. package/node_modules/@comis/skills/dist/builtin/platform/cron-tool.js +1 -1
  384. package/node_modules/@comis/skills/dist/builtin/platform/gateway-tool.js +6 -6
  385. package/node_modules/@comis/skills/dist/builtin/platform/mcp-manage-tool.d.ts +1 -1
  386. package/node_modules/@comis/skills/dist/builtin/platform/mcp-manage-tool.js +9 -9
  387. package/node_modules/@comis/skills/dist/builtin/platform/message-tool.js +18 -0
  388. package/node_modules/@comis/skills/dist/builtin/platform/messaging-factory.d.ts +18 -1
  389. package/node_modules/@comis/skills/dist/builtin/platform/messaging-factory.js +18 -2
  390. package/node_modules/@comis/skills/dist/builtin/platform/models-manage-tool.js +3 -3
  391. package/node_modules/@comis/skills/dist/builtin/process-registry.d.ts +14 -0
  392. package/node_modules/@comis/skills/dist/builtin/process-tool.d.ts +24 -4
  393. package/node_modules/@comis/skills/dist/builtin/process-tool.js +25 -7
  394. package/node_modules/@comis/skills/dist/builtin/sandbox/bwrap-provider.d.ts +11 -0
  395. package/node_modules/@comis/skills/dist/builtin/sandbox/bwrap-provider.js +123 -1
  396. package/node_modules/@comis/skills/dist/builtin/sandbox/detect-provider.js +40 -15
  397. package/node_modules/@comis/skills/dist/index.d.ts +4 -1
  398. package/node_modules/@comis/skills/dist/index.js +3 -1
  399. package/node_modules/@comis/skills/dist/manifest/capability-parser.d.ts +44 -0
  400. package/node_modules/@comis/skills/dist/manifest/capability-parser.js +68 -0
  401. package/node_modules/@comis/skills/dist/manifest/schema.d.ts +44 -37
  402. package/node_modules/@comis/skills/dist/manifest/schema.js +35 -0
  403. package/node_modules/@comis/skills/dist/media/ssrf-fetcher.d.ts +7 -0
  404. package/node_modules/@comis/skills/dist/media/ssrf-fetcher.js +9 -2
  405. package/node_modules/@comis/skills/dist/registry/discovery.d.ts +8 -0
  406. package/node_modules/@comis/skills/dist/registry/discovery.js +10 -3
  407. package/node_modules/@comis/skills/dist/registry/skill-registry.d.ts +45 -1
  408. package/node_modules/@comis/skills/dist/registry/skill-registry.js +70 -7
  409. package/node_modules/@comis/skills/package.json +1 -1
  410. package/node_modules/@comis/web/dist/assets/{agent-detail-71BSbSfD.js → agent-detail-q8t1NB7w.js} +1 -1
  411. package/node_modules/@comis/web/dist/assets/{agent-editor-CTSDZhwT.js → agent-editor-B46io5gv.js} +1 -1
  412. package/node_modules/@comis/web/dist/assets/{agent-list-BEhni2ea.js → agent-list-DQ6g2Rcx.js} +1 -1
  413. package/node_modules/@comis/web/dist/assets/{billing-view-DVP1IvVs.js → billing-view-IWPR8LgF.js} +1 -1
  414. package/node_modules/@comis/web/dist/assets/{channel-detail-N_YK74xC.js → channel-detail-DlNNZuuC.js} +1 -1
  415. package/node_modules/@comis/web/dist/assets/{channel-list-DRk6ZJaF.js → channel-list-DhGwxiMc.js} +1 -1
  416. package/node_modules/@comis/web/dist/assets/{chat-console-Dm-GtSf9.js → chat-console-Nv6fM3Rc.js} +1 -1
  417. package/node_modules/@comis/web/dist/assets/{config-editor-CIferYX6.js → config-editor-BYKuJF76.js} +1 -1
  418. package/node_modules/@comis/web/dist/assets/{context-dag-browser-CL84rXXM.js → context-dag-browser-ClNEtzYE.js} +1 -1
  419. package/node_modules/@comis/web/dist/assets/{context-engine-B1HOTEZv.js → context-engine-BZJ6HChd.js} +1 -1
  420. package/node_modules/@comis/web/dist/assets/{delivery-view-Y6JKYVFw.js → delivery-view-Cb7I3vGu.js} +1 -1
  421. package/node_modules/@comis/web/dist/assets/{diagnostics-view-DWV1UQjz.js → diagnostics-view-9u9Lyu5a.js} +1 -1
  422. package/node_modules/@comis/web/dist/assets/{ic-chat-message-DfSERzzg.js → ic-chat-message-BFt3cVpx.js} +1 -1
  423. package/node_modules/@comis/web/dist/assets/{ic-connection-dot-CXyhlJup.js → ic-connection-dot-y77LZ3Gu.js} +1 -1
  424. package/node_modules/@comis/web/dist/assets/{ic-tool-call-DNmwTjek.js → ic-tool-call-qt6w1NQl.js} +1 -1
  425. package/node_modules/@comis/web/dist/assets/{index-CBr0Tm9_.js → index-8Tg9oc-C.js} +2 -2
  426. package/node_modules/@comis/web/dist/assets/{mcp-management-BaH2-vox.js → mcp-management-69dtH_kY.js} +2 -2
  427. package/node_modules/@comis/web/dist/assets/{media-config-CZLshJoN.js → media-config-BdjLj5c1.js} +1 -1
  428. package/node_modules/@comis/web/dist/assets/{media-test-C9NUWgo_.js → media-test-DuPqrixi.js} +1 -1
  429. package/node_modules/@comis/web/dist/assets/{memory-inspector-D_fmTcRN.js → memory-inspector-B-Pepbq-.js} +1 -1
  430. package/node_modules/@comis/web/dist/assets/{message-center-BBFlNCZn.js → message-center-B7l0yNYY.js} +1 -1
  431. package/node_modules/@comis/web/dist/assets/{models-BytGLm99.js → models-JHFHuv5S.js} +1 -1
  432. package/node_modules/@comis/web/dist/assets/{observe-view-VXtHqaqq.js → observe-view-r8mqhy4O.js} +1 -1
  433. package/node_modules/@comis/web/dist/assets/{pipeline-builder-CfXczlfJ.js → pipeline-builder-XjkiZRcR.js} +1 -1
  434. package/node_modules/@comis/web/dist/assets/{pipeline-history-CPmXFnbe.js → pipeline-history-CZqJv_Hj.js} +1 -1
  435. package/node_modules/@comis/web/dist/assets/{pipeline-history-detail-DcueTMs9.js → pipeline-history-detail-BEFGMoDy.js} +1 -1
  436. package/node_modules/@comis/web/dist/assets/{pipeline-list-B-xG5WZh.js → pipeline-list-B6q5LvO1.js} +1 -1
  437. package/node_modules/@comis/web/dist/assets/{pipeline-monitor-pnIOYaSY.js → pipeline-monitor-BNomXjVL.js} +1 -1
  438. package/node_modules/@comis/web/dist/assets/{scheduler-BtUIFHhA.js → scheduler-BJEjcGKA.js} +1 -1
  439. package/node_modules/@comis/web/dist/assets/{security-C8mWRq2y.js → security-2G1jhBfV.js} +1 -1
  440. package/node_modules/@comis/web/dist/assets/{session-detail-DgdkO5ka.js → session-detail-DmVPzFBR.js} +1 -1
  441. package/node_modules/@comis/web/dist/assets/{session-list-DcylcfTn.js → session-list-CsqMQoHs.js} +1 -1
  442. package/node_modules/@comis/web/dist/assets/{setup-wizard-BP5yjsuL.js → setup-wizard-CAdM-gSP.js} +1 -1
  443. package/node_modules/@comis/web/dist/assets/{skills-DXt1bX8Z.js → skills-2ODqKaWr.js} +1 -1
  444. package/node_modules/@comis/web/dist/assets/{subagents-C7YbUHXY.js → subagents-BFlwfTbD.js} +1 -1
  445. package/node_modules/@comis/web/dist/assets/{workspace-manager-DP6pW4wa.js → workspace-manager--CbOx_dI.js} +1 -1
  446. package/node_modules/@comis/web/dist/index.html +1 -1
  447. package/node_modules/@comis/web/package.json +1 -1
  448. package/package.json +25 -24
@@ -13,21 +13,9 @@
13
13
  */
14
14
  // ---------------------------------------------------------------------------
15
15
  // MCP attribution helpers
16
- // Defined inline to avoid cross-package import from @comis/skills.
16
+ // Re-exported from @comis/shared (canonical home).
17
17
  // ---------------------------------------------------------------------------
18
- /**
19
- * Extract the MCP server name from a sanitized tool name.
20
- * Format: `mcp__serverName--toolName`. Returns undefined for non-MCP tools.
21
- */
22
- export function extractMcpServerName(toolName) {
23
- if (!toolName.startsWith("mcp__"))
24
- return undefined;
25
- const rest = toolName.slice(5);
26
- const sepIdx = rest.indexOf("--");
27
- if (sepIdx <= 0)
28
- return undefined;
29
- return rest.slice(0, sepIdx);
30
- }
18
+ export { extractMcpServerName } from "@comis/shared";
31
19
  /**
32
20
  * Classify an MCP error message into a category for observability.
33
21
  */
@@ -26,6 +26,16 @@ export interface BridgeMetricsState {
26
26
  lastContextUsage: ContextUsageData | undefined;
27
27
  textEmitted: boolean;
28
28
  lastLlmErrorMessage: string | undefined;
29
+ /** Per-turn capture of outbound delivery events. Populated by pi-event-bridge
30
+ * on tool_execution_end for `message(action='send'|'reply'|'attach')`.
31
+ * Read by executor-post-execution.ts to make sentinel-aware decisions.
32
+ * Reset at turn start. */
33
+ outboundLog: Array<{
34
+ action: string;
35
+ channelType: string;
36
+ channelId: string;
37
+ timestamp: number;
38
+ }>;
29
39
  toolStartTimes: Map<string, number>;
30
40
  toolCallHistory: string[];
31
41
  lastActiveToolName: string | undefined;
@@ -58,12 +68,39 @@ export interface BridgeMetricsState {
58
68
  totalThinkingTokens: number;
59
69
  budgetWarningEmitted: boolean;
60
70
  thinkingBlockHashes: Map<string, ThinkingBlockHash[]>;
61
- /** 260428-hoy: Canonical (pre-mutation) snapshot of each assistant message's
62
- * full content array, captured at stream close in lockstep with thinkingBlockHashes.
71
+ /** Canonical (pre-mutation) snapshot of each assistant message's full
72
+ * content array, captured at stream close in lockstep with thinkingBlockHashes.
63
73
  * Keyed by responseId; capped at 32 with FIFO eviction in lockstep with the
64
74
  * hash store. Used by the pre-LLM-call restoration pass to heal cross-turn
65
75
  * mutation of signed thinking blocks before pi-ai serializes the next request. */
66
76
  thinkingBlockCanonical: Map<string, ReadonlyArray<unknown>>;
77
+ /** Number of pre-LLM-call hash-assertion walks performed (one per turn_start). */
78
+ hashAssertionsRan: number;
79
+ /** Total cross-turn thinking-block hash mismatches surfaced across all walks. */
80
+ hashAssertionMismatches: number;
81
+ /** Number of signature-replay scrubber invocations that scrubbed at least one
82
+ * assistant message in this execute(). Populated via ceSetup.getSignatureScrubCounters
83
+ * in executor-post-execution; surfaced here for symmetry / future bridge-side use. */
84
+ signatureScrubs: number;
85
+ /** Total tool calls across all signature-replay scrubs whose thoughtSignature
86
+ * was stripped (post-incident-visibility metric). */
87
+ signatureScrubsToolCallsAffected: number;
88
+ /**
89
+ * Per-composite-key drain inflight gate. Owned by the bridge; passed into
90
+ * `drainAt(...)` at the `tool_execution_end` call site (inline-consumption +
91
+ * composite drain).
92
+ *
93
+ * Map keyed by `${agentId}:${channelType}:${channelId}` (composite key).
94
+ * Concurrent calls for the SAME composite key return immediately
95
+ * (single-tick gate). Concurrent calls for DIFFERENT composite keys drain
96
+ * independently (multi-agent isolation).
97
+ *
98
+ * Entry cleanup: `.delete(formatted)` runs in `.finally(...)` of the
99
+ * drain promise so the Map size remains bounded across long-running
100
+ * sessions (entry removed within one event-loop tick of drain
101
+ * resolution).
102
+ */
103
+ drainInflightByKey: Map<string, Promise<void>>;
67
104
  }
68
105
  /**
69
106
  * Create a fresh metrics state with all counters zeroed.
@@ -100,4 +137,8 @@ export declare function buildBridgeResult(metrics: BridgeMetricsState, stepCount
100
137
  sessionCacheSavedUsd?: number;
101
138
  thinkingTokens?: number;
102
139
  budgetWarningEmitted?: boolean;
140
+ hashAssertionsRan?: number;
141
+ hashAssertionMismatches?: number;
142
+ signatureScrubs?: number;
143
+ signatureScrubsToolCallsAffected?: number;
103
144
  };
@@ -29,6 +29,7 @@ export function createBridgeMetrics() {
29
29
  lastContextUsage: undefined,
30
30
  textEmitted: false,
31
31
  lastLlmErrorMessage: undefined,
32
+ outboundLog: [],
32
33
  toolStartTimes: new Map(),
33
34
  toolCallHistory: [],
34
35
  lastActiveToolName: undefined,
@@ -53,6 +54,13 @@ export function createBridgeMetrics() {
53
54
  budgetWarningEmitted: false,
54
55
  thinkingBlockHashes: new Map(),
55
56
  thinkingBlockCanonical: new Map(),
57
+ // per-execute diagnostic counters
58
+ hashAssertionsRan: 0,
59
+ hashAssertionMismatches: 0,
60
+ signatureScrubs: 0,
61
+ signatureScrubsToolCallsAffected: 0,
62
+ // per-composite-key drain inflight gate.
63
+ drainInflightByKey: new Map(),
56
64
  };
57
65
  }
58
66
  /**
@@ -95,12 +103,19 @@ export function buildBridgeResult(metrics, stepCount) {
95
103
  lastStopReason: metrics.lastStopReason,
96
104
  cacheWrite5mTokens: metrics.totalCacheWrite5mTokens,
97
105
  cacheWrite1hTokens: metrics.totalCacheWrite1hTokens,
98
- // 1.3: Session-cumulative cost fields
106
+ // Session-cumulative cost fields
99
107
  sessionCostUsd: metrics.sessionCumulativeCostUsd,
100
108
  sessionCacheSavedUsd: metrics.sessionCumulativeCacheSavedUsd,
101
- // 1.5: Thinking tokens (omitted when 0 to avoid log noise)
109
+ // Thinking tokens (omitted when 0 to avoid log noise)
102
110
  thinkingTokens: metrics.totalThinkingTokens > 0 ? metrics.totalThinkingTokens : undefined,
103
111
  // Budget trajectory warning flag
104
112
  budgetWarningEmitted: metrics.budgetWarningEmitted || undefined,
113
+ // Per-execute diagnostic counters. Always populated (no `> 0` gate) — a
114
+ // `0` in the bookend log is itself meaningful ("no scrubs/assertions
115
+ // this execute") and gating would lose that signal.
116
+ hashAssertionsRan: metrics.hashAssertionsRan,
117
+ hashAssertionMismatches: metrics.hashAssertionMismatches,
118
+ signatureScrubs: metrics.signatureScrubs,
119
+ signatureScrubsToolCallsAffected: metrics.signatureScrubsToolCallsAffected,
105
120
  };
106
121
  }
@@ -20,6 +20,7 @@ import type { ProviderHealthMonitor } from "../safety/provider-health-monitor.js
20
20
  import type { ContextWindowGuard, ContextUsageData } from "../safety/context-window-guard.js";
21
21
  import type { ExecutionResult } from "../executor/types.js";
22
22
  import type { ExecutionPlan } from "../planner/types.js";
23
+ import { type DrainInflightState } from "../executor/drain-helper.js";
23
24
  import { type ThinkingBlockHash } from "./thinking-block-hash-invariant.js";
24
25
  /** Per-call TTL split estimate, populated by requestBodyInjector's onPayload.
25
26
  * Shared mutable object — written by the stream wrapper, read by the bridge. */
@@ -54,7 +55,7 @@ export interface PiEventBridgeDeps {
54
55
  * internal retry. Rate-limit windows are per-minute (longer than the SDK's
55
56
  * ~30s retry budget), so retrying within the window cannot succeed.
56
57
  * Non-`rate_limited` retryable errors (overloaded, network, 5xx) bypass this
57
- * hook -- the SDK's normal retry-with-backoff proceeds. (260501-dkl) */
58
+ * hook -- the SDK's normal retry-with-backoff proceeds. */
58
59
  onAbortRetry?: () => void;
59
60
  /** SDK context usage accessor -- returns live context metrics from AgentSession. */
60
61
  getContextUsage?: () => ContextUsageData | undefined;
@@ -106,7 +107,7 @@ export interface PiEventBridgeDeps {
106
107
  sepMessageText?: string;
107
108
  /** Execution start timestamp for SEP timing metrics. */
108
109
  sepExecutionStartMs?: number;
109
- /** Cache break detection Phase 2 callback. Returns CacheBreakEvent if break detected. */
110
+ /** Cache break detection callback. Returns CacheBreakEvent if break detected. */
110
111
  checkCacheBreak?: (input: {
111
112
  sessionKey: string;
112
113
  provider: string;
@@ -130,27 +131,27 @@ export interface PiEventBridgeDeps {
130
131
  graphId?: string;
131
132
  /** Graph node ID for cache write signal emission. Set only for graph subagents. */
132
133
  nodeId?: string;
133
- /** + 49-01: Shared mutable TTL split estimate. Populated by request-body-injector
134
+ /** Shared mutable TTL split estimate. Populated by request-body-injector
134
135
  * on each API call, read by the bridge on turn_end for per-TTL cost calculation.
135
136
  * The bridge normalizes these estimates against the actual SDK-reported cacheWriteTokens. */
136
137
  ttlSplit?: TtlSplitEstimate;
137
- /** 260428-hoy pre-call hook: invoked once per `turn_start` event, BEFORE
138
- * pi-ai serializes the next request. The closure (defined in pi-executor)
139
- * walks `session.agent.state.messages`, asserts the cross-turn
140
- * hash-invariant per assistant message with a stored hash entry (logs
141
- * ERROR on mutation), then runs the canonical-restore helper against the
142
- * canonical store (heals any mutation in-place by writing the result
143
- * back to `session.agent.state.messages`). The return value is unused by
144
- * the bridge -- the side effect is the heal write-back. Optional: when
138
+ /** Pre-call hook: invoked once per `turn_start` event, BEFORE pi-ai
139
+ * serializes the next request. The closure (defined in pi-executor) walks
140
+ * `session.agent.state.messages`, asserts the cross-turn hash-invariant
141
+ * per assistant message with a stored hash entry (logs ERROR on mutation),
142
+ * then runs the canonical-restore helper against the canonical store
143
+ * (heals any mutation in-place by writing the result back to
144
+ * `session.agent.state.messages`). The return value is unused by the
145
+ * bridge -- the side effect is the heal write-back. Optional: when
145
146
  * omitted, both the diagnostic and the heal are silently disabled
146
147
  * (e.g., unit tests that don't drive a full agent session). */
147
148
  getSessionMessages?: () => ReadonlyArray<unknown> | undefined;
148
- /** 260428-iag wire-edge diagnostic: returns the absolute path to the
149
- * per-session JSONL on disk. The bridge invokes this only when the LLM
150
- * error path detects the signed-replay rejection signature, then
151
- * diff'd against the persisted canonical to surface mutation that
152
- * occurred AFTER the bridge's restoration hook. Optional — when
153
- * omitted, the wire-edge diagnostic is a silent no-op. */
149
+ /** Wire-edge diagnostic: returns the absolute path to the per-session JSONL
150
+ * on disk. The bridge invokes this only when the LLM error path detects
151
+ * the signed-replay rejection signature, then diff'd against the persisted
152
+ * canonical to surface mutation that occurred AFTER the bridge's
153
+ * restoration hook. Optional — when omitted, the wire-edge diagnostic is
154
+ * a silent no-op. */
154
155
  getSessionJsonlPath?: () => string | null;
155
156
  }
156
157
  /** Estimated cost payload for a timed-out API request. */
@@ -193,16 +194,24 @@ export interface PiEventBridgeResult {
193
194
  };
194
195
  /** Accumulate estimated cost from a timed-out API request. */
195
196
  addGhostCost: (estimated: GhostCostEstimate) => void;
196
- /** 260428-hoy: ReadonlyMap views of the per-responseId hash store and
197
- * canonical-snapshot store, both populated at stream-close in lockstep.
198
- * The executor's pre-LLM-call closure reads both stores to drive the
199
- * hash-invariant assertion plus the canonical restore helper. Returns
200
- * ReadonlyMap views to preserve internal-state encapsulation -- the
201
- * underlying `m` object is never exported. */
197
+ /** ReadonlyMap views of the per-responseId hash store and canonical-snapshot
198
+ * store, both populated at stream-close in lockstep. The executor's
199
+ * pre-LLM-call closure reads both stores to drive the hash-invariant
200
+ * assertion plus the canonical restore helper. Returns ReadonlyMap views
201
+ * to preserve internal-state encapsulation -- the underlying `m` object is
202
+ * never exported. */
202
203
  getThinkingBlockStores: () => {
203
204
  hashes: ReadonlyMap<string, ReadonlyArray<ThinkingBlockHash>>;
204
205
  canonical: ReadonlyMap<string, ReadonlyArray<unknown>>;
205
206
  };
207
+ /**
208
+ * Expose the bridge-owned drain inflight gate so executor-post-execution
209
+ * can fire an end-of-turn backstop drainAt sharing the same composite-key
210
+ * gate map. Returns the live `BridgeMetricsState` slice -- callers MUST
211
+ * treat this as read-mostly (the only mutation contract is `drainAt`
212
+ * adding/removing entries).
213
+ */
214
+ getDrainState: () => DrainInflightState;
206
215
  }
207
216
  export { sanitizeToolArgs, extractErrorText } from "./bridge-event-handlers.js";
208
217
  /**
@@ -18,8 +18,10 @@ import { getCacheProviderInfo } from "../executor/cache-usage-helpers.js";
18
18
  import { sanitizeMcpToolNameForAnalytics } from "../executor/cache-break-detection.js";
19
19
  import { classifyError } from "../executor/error-classifier.js";
20
20
  import { extractPlanFromResponse } from "../planner/plan-extractor.js";
21
- import { extractMcpServerName, classifyMcpErrorType, sanitizeToolArgs, extractErrorText } from "./bridge-event-handlers.js";
21
+ import { extractMcpServerName } from "@comis/shared";
22
+ import { classifyMcpErrorType, sanitizeToolArgs, extractErrorText } from "./bridge-event-handlers.js";
22
23
  import { createBridgeMetrics, buildBridgeResult } from "./bridge-metrics.js";
24
+ import { drainAt } from "../executor/drain-helper.js";
23
25
  import { checkStepLimit, emitStepLimitAbort, checkBudgetLimit, emitBudgetAbort, checkBudgetTrajectory, checkContextWindow, emitContextAbort, checkCircuitBreaker, emitCircuitBreakerAbort } from "./bridge-safety-controls.js";
24
26
  import { computeThinkingBlockHashes, diffThinkingBlocksAgainstPersisted, WIRE_DIFF_HINT_FILE_MISSING, WIRE_DIFF_HINT_NOT_FOUND, } from "./thinking-block-hash-invariant.js";
25
27
  // Re-export helper functions for backward compatibility with existing imports
@@ -171,6 +173,62 @@ export function createPiEventBridge(deps) {
171
173
  durationMs,
172
174
  ...(errorText && { errorText }),
173
175
  });
176
+ // Capture outbound deliveries. The post-execution silent-sentinel
177
+ // gate reads this per-turn log to make sentinel-aware decisions
178
+ // about paired memory persistence. Reset at turn_start; bounded by
179
+ // per-turn outbound message count.
180
+ //
181
+ // On the SAME tool_execution_end event, fire
182
+ // `drainAt({agentId, channelType, channelId})` (the composite-keyed
183
+ // inline-consumption drain). The gate state lives in bridge-metrics
184
+ // (`m.drainInflightByKey`) so concurrent drains for the same
185
+ // composite key collapse to a single in-flight Promise; concurrent
186
+ // drains for different composite keys (multi-agent) run
187
+ // independently. Failures inside drainAt are suppressed with WARN
188
+ // logging -- the bridge's tool_execution_end propagation is NEVER
189
+ // aborted by drain misbehavior.
190
+ if (endEvent.toolName === "message" && toolSuccess && sanitizedArgs) {
191
+ const action = typeof sanitizedArgs.action === "string" ? sanitizedArgs.action : "";
192
+ if (action === "send" || action === "reply" || action === "attach") {
193
+ const channelType = typeof sanitizedArgs.channel_type === "string" ? sanitizedArgs.channel_type : "";
194
+ const channelId = typeof sanitizedArgs.channel_id === "string" ? sanitizedArgs.channel_id : "";
195
+ m.outboundLog.push({
196
+ action,
197
+ channelType,
198
+ channelId,
199
+ timestamp: Date.now(),
200
+ });
201
+ // Composite-key drain at the bridge call site. The composite
202
+ // (agentId, channelType, channelId) prevents cross-agent
203
+ // contamination of the inline-consumption queue. Use the
204
+ // message tool's own channel_type / channel_id when present
205
+ // (the tool resolved them); fall back to the bridge's bound
206
+ // deps.channelId when the tool args were sanitized away
207
+ // (defensive). A drain trigger with empty channelType OR empty
208
+ // channelId is skipped -- formatDrainKey would otherwise
209
+ // produce ambiguous keys.
210
+ //
211
+ // drainAt is fire-and-forget: it spawns the drain Promise and
212
+ // wraps it in suppressError internally. The kickoffDrain
213
+ // wrapper below double-wraps the synchronous invocation in
214
+ // suppressError (Promise.resolve adapter) so a (impossible)
215
+ // synchronous throw inside drainAt cannot abort the bridge's
216
+ // tool_execution_end propagation -- fire-and-forget contract /
217
+ // non-fatal drain failure.
218
+ const drainChannelType = channelType.length > 0 ? channelType : "";
219
+ const drainChannelId = channelId.length > 0 ? channelId : deps.channelId;
220
+ if (drainChannelType.length > 0 && drainChannelId.length > 0) {
221
+ const kickoffDrain = Promise.resolve().then(() => {
222
+ drainAt({
223
+ agentId: deps.agentId,
224
+ channelType: drainChannelType,
225
+ channelId: drainChannelId,
226
+ }, { drainInflightByKey: m.drainInflightByKey }, deps.logger);
227
+ });
228
+ suppressError(kickoffDrain, "bridge tool_use_complete drainAt kickoff");
229
+ }
230
+ }
231
+ }
174
232
  // Look up truncation metadata from stream wrapper registry
175
233
  const truncMeta = deps.getTruncationMeta?.(endEvent.toolCallId);
176
234
  deps.eventBus.emit("tool:executed", {
@@ -186,7 +244,7 @@ export function createPiEventBridge(deps) {
186
244
  ...(truncMeta && { truncated: truncMeta.truncated, fullChars: truncMeta.fullChars, returnedChars: truncMeta.returnedChars }),
187
245
  });
188
246
  // Reset prompt timeout after each tool completion so slow tools
189
- // do not starve subsequent LLM turns (Quick 215).
247
+ // do not starve subsequent LLM turns.
190
248
  deps.onToolExecutionEnd?.();
191
249
  // Safety: check step limit (delegated to bridge-safety-controls)
192
250
  {
@@ -222,20 +280,24 @@ export function createPiEventBridge(deps) {
222
280
  // LLM turn about to start (pre-serialize hook for assert+restore)
223
281
  // -----------------------------------------------------------------
224
282
  case "turn_start": {
225
- // 260428-hoy: Run the executor-supplied pre-call closure once per
226
- // turn, before pi-ai reads `session.agent.state.messages` to
227
- // serialize the next API request. The closure performs the
228
- // assert-then-restore pass over the live transcript and writes the
229
- // healed array back into session state when at least one swap
230
- // happens, so the bytes Anthropic sees match the canonical
231
- // stream-close snapshot. The closure swallows its own throws; the
232
- // wrapper here is belt-and-braces.
283
+ // Reset per-turn outbound capture. The log accumulates
284
+ // message(send/reply/attach) calls across the turn so the
285
+ // post-execution gate can make sentinel-aware decisions.
286
+ m.outboundLog.length = 0;
287
+ // Run the executor-supplied pre-call closure once per turn, before
288
+ // pi-ai reads `session.agent.state.messages` to serialize the next
289
+ // API request. The closure performs the assert-then-restore pass
290
+ // over the live transcript and writes the healed array back into
291
+ // session state when at least one swap happens, so the bytes
292
+ // Anthropic sees match the canonical stream-close snapshot. The
293
+ // closure swallows its own throws; the wrapper here is
294
+ // belt-and-braces.
233
295
  //
234
- // 260428-j0v: ALWAYS emit ONE INFO log carrying the counters the
235
- // bridge can derive — even when the closure is unwired or returns
236
- // undefined / no candidates. This closes the silent-success
237
- // ambiguity observed on trace c5680133 where ZERO agent.bridge.*
238
- // events appeared despite the helpers having shipped.
296
+ // ALWAYS emit ONE INFO log carrying the counters the bridge can
297
+ // derive — even when the closure is unwired or returns undefined /
298
+ // no candidates. This closes the silent-success ambiguity where
299
+ // ZERO agent.bridge.* events appeared despite the helpers having
300
+ // shipped.
239
301
  //
240
302
  // Counters are computed by the bridge's own walk of the messages
241
303
  // returned by the closure (or empty when unwired) so the executor
@@ -289,15 +351,27 @@ export function createPiEventBridge(deps) {
289
351
  // implementation; surfaced as a separate field so future asymmetric
290
352
  // assert/restore semantics are observable.
291
353
  const restoredCount = mismatchesLogged;
292
- deps.logger.info({
293
- module: "agent.bridge.hash-invariant",
354
+ m.hashAssertionsRan++;
355
+ m.hashAssertionMismatches += mismatchesLogged;
356
+ const hashAssertionPayload = {
357
+ submodule: "bridge.hash-invariant",
294
358
  candidatesChecked,
295
359
  mismatchesLogged,
296
360
  restoredCount,
297
361
  anyResponseIdMatched,
298
362
  hashStoreSize,
299
363
  canonicalStoreSize,
300
- }, "Pre-call assertion ran");
364
+ };
365
+ if (mismatchesLogged > 0) {
366
+ deps.logger.warn({
367
+ ...hashAssertionPayload,
368
+ hint: "Cross-turn thinking-block mutation detected; pre-call restore pass will heal before next API serialize. Investigate if this fires repeatedly without the heal succeeding (canonicalStoreSize === 0).",
369
+ errorKind: "internal",
370
+ }, "Pre-call assertion ran");
371
+ }
372
+ else {
373
+ deps.logger.debug(hashAssertionPayload, "Pre-call assertion ran");
374
+ }
301
375
  break;
302
376
  }
303
377
  // -----------------------------------------------------------------
@@ -337,14 +411,14 @@ export function createPiEventBridge(deps) {
337
411
  thinkingLen: typeof b.thinking === "string" ? b.thinking.length : 0,
338
412
  })),
339
413
  }, "Assistant message block accounting at stream close");
340
- // Bug A diagnostic + 260428-hoy heal: capture hashes AND a
341
- // canonical (pre-mutation) snapshot of the full content array,
342
- // keyed by responseId, in lockstep across both stores. The
343
- // hash store powers the assertion ERROR log (mutation
344
- // diagnostic); the canonical store powers the pre-call
345
- // restore pass that heals cross-turn mutation before the next
346
- // API serialize. Both stores are FIFO-evicted at 32 entries
347
- // in lockstep so they always share the same keyset.
414
+ // Diagnostic + heal: capture hashes AND a canonical (pre-mutation)
415
+ // snapshot of the full content array, keyed by responseId, in
416
+ // lockstep across both stores. The hash store powers the
417
+ // assertion ERROR log (mutation diagnostic); the canonical
418
+ // store powers the pre-call restore pass that heals cross-turn
419
+ // mutation before the next API serialize. Both stores are
420
+ // FIFO-evicted at 32 entries in lockstep so they always share
421
+ // the same keyset.
348
422
  if (typeof responseIdForLog === "string") {
349
423
  const hashes = computeThinkingBlockHashes(blocks);
350
424
  if (hashes.length > 0) {
@@ -356,11 +430,11 @@ export function createPiEventBridge(deps) {
356
430
  m.thinkingBlockCanonical.delete(oldestKey);
357
431
  }
358
432
  m.thinkingBlockHashes.set(responseIdForLog, hashes);
359
- // 260428-hoy: capture canonical (pre-mutation) full
360
- // content array so the pre-LLM-call restore pass can heal
361
- // any cross-turn mutation before pi-ai serializes the
362
- // next request. structuredClone is a Node 22 global; the
363
- // try/catch is defensive against rare exotic input shapes.
433
+ // Capture canonical (pre-mutation) full content array so
434
+ // the pre-LLM-call restore pass can heal any cross-turn
435
+ // mutation before pi-ai serializes the next request.
436
+ // structuredClone is a Node 22 global; the try/catch is
437
+ // defensive against rare exotic input shapes.
364
438
  try {
365
439
  const canonical = Object.freeze(structuredClone(blocks));
366
440
  m.thinkingBlockCanonical.set(responseIdForLog, canonical);
@@ -382,7 +456,7 @@ export function createPiEventBridge(deps) {
382
456
  const llmLatencyMs = turnWallclockMs - effectiveTurnToolMs;
383
457
  m.cumulativeLlmDurationMs += llmLatencyMs;
384
458
  m.turnToolDurationMs = 0;
385
- // R-04: Extract responseId from assistant message (optional -- not all providers supply it)
459
+ // Extract responseId from assistant message (optional -- not all providers supply it)
386
460
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK interop boundary
387
461
  const responseId = assistantMsg?.responseId;
388
462
  if (assistantMsg && "usage" in assistantMsg && assistantMsg.usage) {
@@ -421,7 +495,7 @@ export function createPiEventBridge(deps) {
421
495
  if (deps.onTurnWithCacheWrite) {
422
496
  deps.onTurnWithCacheWrite(cacheWriteTokens);
423
497
  }
424
- // Cache break detection Phase 2 (all providers, unconditional)
498
+ // Cache break detection (all providers, unconditional)
425
499
  // MUST NOT guard with cacheReadTokens > 0 -- complete cache misses (drop to 0) must be detected
426
500
  if (deps.checkCacheBreak) {
427
501
  // Detect API errors -- zero usage with error stop reason
@@ -451,7 +525,7 @@ export function createPiEventBridge(deps) {
451
525
  }
452
526
  }
453
527
  }
454
- // R-08: Extract cacheCreation breakdown (future upstream -- runtime check)
528
+ // Extract cacheCreation breakdown (future upstream -- runtime check)
455
529
  const rawUsage = usage;
456
530
  const cacheCreation = rawUsage.cacheCreation && typeof rawUsage.cacheCreation === "object"
457
531
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK interop boundary
@@ -472,7 +546,7 @@ export function createPiEventBridge(deps) {
472
546
  }
473
547
  // Record usage in budget guard (token-based, not cost-based -- stays before correction)
474
548
  deps.budgetGuard.recordUsage(usage.totalTokens);
475
- // 49-01 + COST-FIX ordering: Normalize TTL split estimates BEFORE cost correction.
549
+ // COST-FIX ordering: Normalize TTL split estimates BEFORE cost correction.
476
550
  // The injector provides raw per-TTL estimates; normalize so they sum to the
477
551
  // SDK-reported total (eliminates the 28% estimation error).
478
552
  // Mutate in-place so per-TTL cost and accumulation use normalized values.
@@ -551,10 +625,10 @@ export function createPiEventBridge(deps) {
551
625
  if (deps.onTurnCacheSavings) {
552
626
  deps.onTurnCacheSavings(savedVsUncached);
553
627
  }
554
- // 1.3: Accumulate session-cumulative costs alongside per-turn values
628
+ // Accumulate session-cumulative costs alongside per-turn values
555
629
  m.sessionCumulativeCostUsd += cost.total;
556
630
  m.sessionCumulativeCacheSavedUsd += savedVsUncached;
557
- // 1.5: Track thinking tokens from SDK usage object.
631
+ // Track thinking tokens from SDK usage object.
558
632
  // The pi-ai SDK Usage type does not have a dedicated thinking/reasoning field,
559
633
  // but future versions or raw API responses may include `reasoningTokens`.
560
634
  // Runtime-check the raw usage object for this field.
@@ -567,9 +641,9 @@ export function createPiEventBridge(deps) {
567
641
  m.totalThinkingTokens += sdkThinkingTokens;
568
642
  }
569
643
  }
570
- // 49-01: Populate cacheCreation from bridge metrics TTL split when SDK doesn't provide it.
571
- // SDK-sourced cacheCreation (from R-08 extraction) takes priority; bridge metrics
572
- // provide the fallback when pi-ai doesn't surface per-TTL breakdown.
644
+ // Populate cacheCreation from bridge metrics TTL split when SDK doesn't provide it.
645
+ // SDK-sourced cacheCreation takes priority; bridge metrics provide the fallback
646
+ // when pi-ai doesn't surface per-TTL breakdown.
573
647
  const effectiveCacheCreation = cacheCreation ?? ((m.totalCacheWrite5mTokens > 0 || m.totalCacheWrite1hTokens > 0)
574
648
  ? { shortTtl: m.totalCacheWrite5mTokens, longTtl: m.totalCacheWrite1hTokens }
575
649
  : undefined);
@@ -844,7 +918,7 @@ export function createPiEventBridge(deps) {
844
918
  break;
845
919
  }
846
920
  // -----------------------------------------------------------------
847
- // SDK auto-retry loop: abort on rate_limited (260501-dkl)
921
+ // SDK auto-retry loop: abort on rate_limited
848
922
  // -----------------------------------------------------------------
849
923
  case "auto_retry_start": {
850
924
  const errorMessage = event.errorMessage ?? "";
@@ -854,7 +928,7 @@ export function createPiEventBridge(deps) {
854
928
  const classification = classifyError(new Error(errorMessage));
855
929
  if (classification.category === "rate_limited") {
856
930
  deps.logger.info({
857
- module: "agent.bridge.auto-retry-abort",
931
+ submodule: "bridge.auto-retry-abort",
858
932
  attempt,
859
933
  maxAttempts,
860
934
  delayMs,
@@ -884,20 +958,20 @@ export function createPiEventBridge(deps) {
884
958
  hint: "Check LLM provider status",
885
959
  errorKind: "dependency",
886
960
  }, "LLM call returned error");
887
- // 260428-iag wire-edge diagnostic: when the LLM error matches the
888
- // Anthropic signed-replay rejection signature ("thinking blocks ...
889
- // cannot be modified"), diff the in-memory content against the
890
- // persisted JSONL canonical and emit one ERROR per divergent block.
891
- // Fully async / fire-and-forget — never blocks the existing error
892
- // path. Silent no-op when the signature doesn't match or when
893
- // either getSessionMessages / getSessionJsonlPath is unwired.
961
+ // Wire-edge diagnostic: when the LLM error matches the Anthropic
962
+ // signed-replay rejection signature ("thinking blocks ... cannot
963
+ // be modified"), diff the in-memory content against the persisted
964
+ // JSONL canonical and emit one ERROR per divergent block. Fully
965
+ // async / fire-and-forget — never blocks the existing error path.
966
+ // Silent no-op when the signature doesn't match or when either
967
+ // getSessionMessages / getSessionJsonlPath is unwired.
894
968
  //
895
- // 260428-j0v: ALWAYS emit ONE dispatch-decision INFO log carrying
896
- // boolean flags that explain WHY the wire-diff dispatch was or was
897
- // not entered (regex match, candidate count, callback presence) —
898
- // even when regexMatched is false or callbacks are unwired. When
899
- // the dispatch IS entered, emit a second dispatch-completion INFO
900
- // after the async candidates loop completes.
969
+ // ALWAYS emit ONE dispatch-decision INFO log carrying boolean flags
970
+ // that explain WHY the wire-diff dispatch was or was not entered
971
+ // (regex match, candidate count, callback presence) — even when
972
+ // regexMatched is false or callbacks are unwired. When the dispatch
973
+ // IS entered, emit a second dispatch-completion INFO after the
974
+ // async candidates loop completes.
901
975
  //
902
976
  // The signature regex matches Anthropic's actual 400 message:
903
977
  // "messages.N.content.M: thinking blocks cannot be modified"
@@ -936,7 +1010,7 @@ export function createPiEventBridge(deps) {
936
1010
  }
937
1011
  const jsonlPathPresent = typeof jsonlPathForDecision === "string" && jsonlPathForDecision.length > 0;
938
1012
  deps.logger.info({
939
- module: "agent.bridge.wire-diff",
1013
+ submodule: "bridge.wire-diff",
940
1014
  regexMatched,
941
1015
  candidatesFound: candidates.length,
942
1016
  jsonlPathPresent,
@@ -969,7 +1043,7 @@ export function createPiEventBridge(deps) {
969
1043
  totalDivergences += entries.length;
970
1044
  for (const entry of entries) {
971
1045
  deps.logger.error({
972
- module: "agent.bridge.wire-diff",
1046
+ submodule: "bridge.wire-diff",
973
1047
  responseId: c.responseId,
974
1048
  blockIndex: entry.blockIndex,
975
1049
  persistedHash: entry.persistedHash,
@@ -991,7 +1065,7 @@ export function createPiEventBridge(deps) {
991
1065
  // ALWAYS emit the completion INFO, even on totalDivergences=0
992
1066
  // or when every helper call hit a read error.
993
1067
  deps.logger.info({
994
- module: "agent.bridge.wire-diff",
1068
+ submodule: "bridge.wire-diff",
995
1069
  candidatesProcessed,
996
1070
  totalDivergences,
997
1071
  persistedNotFound,
@@ -1031,12 +1105,21 @@ export function createPiEventBridge(deps) {
1031
1105
  m.ghostCostUsd += estimated.costUsd;
1032
1106
  m.timedOutRequests += 1;
1033
1107
  };
1034
- // 260428-hoy: typed ReadonlyMap accessor for the executor's pre-call
1035
- // closure. Returns views over the live maps -- the executor never receives
1036
- // the mutable `m` object itself.
1108
+ // Typed ReadonlyMap accessor for the executor's pre-call closure.
1109
+ // Returns views over the live maps -- the executor never receives the
1110
+ // mutable `m` object itself.
1037
1111
  const getThinkingBlockStores = () => ({
1038
1112
  hashes: m.thinkingBlockHashes,
1039
1113
  canonical: m.thinkingBlockCanonical,
1040
1114
  });
1041
- return { listener, getResult, addGhostCost, getThinkingBlockStores };
1115
+ // Expose the per-composite-key drain inflight gate so executor-post-
1116
+ // execution can fire an end-of-turn backstop drainAt that shares the SAME
1117
+ // gate map as the bridge's tool_execution_end call site. The returned
1118
+ // object has a live reference to the underlying Map -- mutations from the
1119
+ // bridge AND the executor post-execution path land in the same state
1120
+ // container, satisfying the single-tick gate contract.
1121
+ const getDrainState = () => ({
1122
+ drainInflightByKey: m.drainInflightByKey,
1123
+ });
1124
+ return { listener, getResult, addGhostCost, getThinkingBlockStores, getDrainState };
1042
1125
  }
@@ -3,9 +3,8 @@
3
3
  *
4
4
  * Observed problem: Anthropic 400 `messages.N.content.M: thinking/redacted_thinking
5
5
  * blocks cannot be modified` errors keep firing in production even after the
6
- * surrogate-guard, drift-scrubber, and signed-replay-detector layers shipped
7
- * (260425-rvm), and even after the immutable-section redirect (260425-t40).
8
- * Trace `c7b91328-9dc5-4618-9ae8-ca207b4b93df` on 2026-04-28 hit a 400 ~2.2s
6
+ * surrogate-guard, drift-scrubber, and signed-replay-detector layers shipped,
7
+ * and even after the immutable-section redirect. A trace hit a 400 ~2.2s
9
8
  * after `turn_end` -- meaning *some other layer* mutates a signed thinking
10
9
  * block between the assistant turn and the next replay. We don't know which.
11
10
  *
@@ -23,12 +22,12 @@
23
22
  * - NEVER mutates inputs. Pure read; only output is the structured log.
24
23
  * - NEVER alters request flow. The mismatch is observable signal only --
25
24
  * Anthropic's 400 still surfaces through the existing error path
26
- * (signed-replay-detector -> executor-prompt-runner). Bug A behavior fix
27
- * is a separate quick task gated on what this diagnostic reveals.
25
+ * (signed-replay-detector -> executor-prompt-runner). The behavior fix
26
+ * for the underlying bug is gated on what this diagnostic reveals.
28
27
  *
29
28
  * Logging surface follows CLAUDE.md canonical Pino fields:
30
29
  * - object-first signature: `error({...fields}, "msg")`
31
- * - `module: "agent.bridge.hash-invariant"`
30
+ * - `submodule: "bridge.hash-invariant"` (parent logger binds `module: "agent"`)
32
31
  * - `errorKind: "internal"` (classification per AGENTS.md §2.1)
33
32
  * - `hint`: actionable next step for the on-call diagnoser
34
33
  * - `responseId`, `blockIndex`, `oldHash`, `newHash`,
@@ -137,7 +136,7 @@ export interface RestoreResult {
137
136
  * Never throws. On any unexpected error during the walk (e.g. malformed
138
137
  * canonical entry whose getter throws), the entire result is `{ messages:
139
138
  * <input ref>, restoredCount: 0, affectedResponseIds: [] }` and ONE WARN log
140
- * fires with `module: RESTORE_MODULE_FIELD, errorKind: "internal"`.
139
+ * fires with `submodule: RESTORE_SUBMODULE_FIELD, errorKind: "internal"`.
141
140
  */
142
141
  export declare function restoreCanonicalThinkingBlocks(messages: ReadonlyArray<unknown> | undefined | null, canonicalStore: ReadonlyMap<string, ReadonlyArray<unknown>>, deps?: RestoreDeps): RestoreResult;
143
142
  export declare const WIRE_DIFF_HINT_FILE_MISSING: string;