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
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Injects CachedContent name into Gemini API payloads and atomically strips
6
6
  * the three inherited fields (systemInstruction, tools, toolConfig) to avoid
7
- * double-billing. Operates inside the onPayload hook (post-buildParams) per D-04.
7
+ * double-billing. Operates inside the onPayload hook (post-buildParams).
8
8
  *
9
9
  * Handles cache injection, inherited field stripping, and staleness recovery.
10
10
  *
@@ -103,7 +103,7 @@ export function createGeminiCacheInjector(config, logger) {
103
103
  config.onPayloadForCacheDetection?.(resolvedParams, modelInfo);
104
104
  return resolvedParams;
105
105
  }
106
- // D-03: Assertion -- all three fields must be present for stripping
106
+ // Assertion -- all three fields must be present for stripping
107
107
  if (configObj.systemInstruction === undefined ||
108
108
  configObj.tools === undefined ||
109
109
  configObj.toolConfig === undefined) {
@@ -112,7 +112,7 @@ export function createGeminiCacheInjector(config, logger) {
112
112
  cacheName: entry.name,
113
113
  hint: "Expected fields missing from config -- cache entry stale, evicting",
114
114
  errorKind: "validation",
115
- }, "Gemini cache injector: stale cache detected (D-03)");
115
+ }, "Gemini cache injector: stale cache detected");
116
116
  suppressError(config.cacheManager.dispose(config.sessionKey), "stale-cache-eviction-d03");
117
117
  config.onPayloadForCacheDetection?.(resolvedParams, modelInfo);
118
118
  return resolvedParams;
@@ -129,7 +129,7 @@ export function createGeminiCacheInjector(config, logger) {
129
129
  }, "Gemini cache injector: injected cached content");
130
130
  // Notify caller of successful cache injection for observability
131
131
  config.onCacheHit?.(entry);
132
- // D-07: Phase 1 cache break detection callback
132
+ // Cache break detection callback
133
133
  config.onPayloadForCacheDetection?.(resolvedParams, modelInfo);
134
134
  return resolvedParams;
135
135
  },
@@ -35,10 +35,19 @@ import type { AgentToolResult } from "@mariozechner/pi-agent-core";
35
35
  *
36
36
  * - If no guide exists for the tool, returns result unchanged.
37
37
  * - If guide was already delivered in this session, returns result unchanged.
38
- * - Always marks the tool as delivered (even on error).
39
- * - Skips injection when result has isError: true (but still marks delivered).
38
+ * - Skips injection when result has isError: true and does NOT mark delivered
39
+ * (so a retry can fire see regression coverage in `jit-guide-injector.test.ts`).
40
40
  * - Logs at INFO level when guide is injected.
41
41
  *
42
+ * **Re-injection de-dup contract.** The `deliveredGuides` Set is the single
43
+ * source of truth for which guide ids have been injected within the current
44
+ * scope (per-session by default; cleared on session reset by pi-executor).
45
+ * Within a single turn — even when the same tool fires multiple times via
46
+ * mid-turn discovery / retries — the same guide id is not re-injected
47
+ * because the early-return on `deliveredGuides.has(...)` fires on the
48
+ * second-and-later check. The existing Set IS the per-turn (and per-session)
49
+ * tracker; no second data structure is needed.
50
+ *
42
51
  * Note: AgentToolResult does not formally include isError (it is set by
43
52
  * the agent-loop on the message level), but some tools (MCP, discovery)
44
53
  * include it at runtime. We check for it defensively.
@@ -42,10 +42,19 @@ const PRIVILEGED_SECTION_KEY = "section:privileged";
42
42
  *
43
43
  * - If no guide exists for the tool, returns result unchanged.
44
44
  * - If guide was already delivered in this session, returns result unchanged.
45
- * - Always marks the tool as delivered (even on error).
46
- * - Skips injection when result has isError: true (but still marks delivered).
45
+ * - Skips injection when result has isError: true and does NOT mark delivered
46
+ * (so a retry can fire see regression coverage in `jit-guide-injector.test.ts`).
47
47
  * - Logs at INFO level when guide is injected.
48
48
  *
49
+ * **Re-injection de-dup contract.** The `deliveredGuides` Set is the single
50
+ * source of truth for which guide ids have been injected within the current
51
+ * scope (per-session by default; cleared on session reset by pi-executor).
52
+ * Within a single turn — even when the same tool fires multiple times via
53
+ * mid-turn discovery / retries — the same guide id is not re-injected
54
+ * because the early-return on `deliveredGuides.has(...)` fires on the
55
+ * second-and-later check. The existing Set IS the per-turn (and per-session)
56
+ * tracker; no second data structure is needed.
57
+ *
49
58
  * Note: AgentToolResult does not formally include isError (it is set by
50
59
  * the agent-loop on the message level), but some tools (MCP, discovery)
51
60
  * include it at runtime. We check for it defensively.
@@ -67,6 +76,11 @@ export function wrapToolResultWithGuide(toolName, result, deliveredGuides, logge
67
76
  const wantsPrivileged = PRIVILEGED_TOOL_SET.has(toolName) &&
68
77
  !deliveredGuides.has(PRIVILEGED_SECTION_KEY) &&
69
78
  !!SYSTEM_PROMPT_GUIDES["__privileged_tools__"];
79
+ // Re-injection de-dup: when every candidate guide id is already in
80
+ // `deliveredGuides`, none of `wantsTool`/`wantsSection`/`wantsPrivileged`
81
+ // is true and we early-return without appending. This single check is the
82
+ // per-turn (and per-session) de-dup gate — the same `deliveredGuides` Set
83
+ // passed across calls within a turn IS the injectedGuideIds tracker.
70
84
  if (!wantsTool && !wantsSection && !wantsPrivileged)
71
85
  return result;
72
86
  // Skip on error — but DO NOT consume delivery slots so a retry can fire.
@@ -25,13 +25,13 @@ export declare function isVisibleTextBlock(block: any): boolean;
25
25
  * - cross-turn boundary (role === "user" encountered before a
26
26
  * qualifying assistant) — return "" because the user message marks
27
27
  * the start of the current execution window; assistants before it
28
- * belong to prior turns (260501-gyy).
28
+ * belong to prior turns.
29
29
  *
30
30
  * When the resulting last assistant contains commentary-phase text
31
31
  * blocks, drops them and returns only visible text. Otherwise returns
32
32
  * the visible (non-commentary) text blocks of the last assistant
33
33
  * directly — does NOT delegate to session.getLastAssistantText(),
34
34
  * which walks past empty messages and would re-introduce the
35
- * synthetic-leak (260501-egj).
35
+ * synthetic-leak.
36
36
  */
37
37
  export declare function getVisibleAssistantText(session: any): string;
@@ -41,21 +41,20 @@ export function isVisibleTextBlock(block) {
41
41
  * - cross-turn boundary (role === "user" encountered before a
42
42
  * qualifying assistant) — return "" because the user message marks
43
43
  * the start of the current execution window; assistants before it
44
- * belong to prior turns (260501-gyy).
44
+ * belong to prior turns.
45
45
  *
46
46
  * When the resulting last assistant contains commentary-phase text
47
47
  * blocks, drops them and returns only visible text. Otherwise returns
48
48
  * the visible (non-commentary) text blocks of the last assistant
49
49
  * directly — does NOT delegate to session.getLastAssistantText(),
50
50
  * which walks past empty messages and would re-introduce the
51
- * synthetic-leak (260501-egj).
51
+ * synthetic-leak.
52
52
  */
53
53
  export function getVisibleAssistantText(session) {
54
54
  const messages = session?.messages;
55
55
  // Find last "real" assistant message in the CURRENT execution window —
56
56
  // skip aborted-empty, error-empty, and synthetic-injected; stop at the
57
- // first user message (turn boundary) to avoid leaking prior-turn text
58
- // (260501-gyy).
57
+ // first user message (turn boundary) to avoid leaking prior-turn text.
59
58
  const lastAssistant = (() => {
60
59
  if (!Array.isArray(messages))
61
60
  return undefined;
@@ -93,9 +92,8 @@ export function getVisibleAssistantText(session) {
93
92
  // No commentary — return lastAssistant's visible text directly.
94
93
  // Do NOT delegate to session.getLastAssistantText() because it walks
95
94
  // past empty messages (aborted/error/etc.) and re-introduces the
96
- // synthetic-leak (production bug 260501-egj: post-restart-resumption
97
- // rate-limit returned synthetic placeholder instead of the
98
- // 260501-cur "Rate limit exceeded" terminal error).
95
+ // synthetic-leak (post-restart-resumption rate-limit returned synthetic
96
+ // placeholder instead of the "Rate limit exceeded" terminal error).
99
97
  if (!lastAssistant?.content || !Array.isArray(lastAssistant.content))
100
98
  return "";
101
99
  return lastAssistant.content
@@ -21,7 +21,7 @@
21
21
  */
22
22
  import type { ToolDefinition } from "@mariozechner/pi-coding-agent";
23
23
  import type { AuthStorage, ModelRegistry } from "@mariozechner/pi-coding-agent";
24
- import { type PerAgentConfig, type TypedEventBus, type MemoryPort, type HookRunner, type SecretManager, type EnvelopeConfig, type OutputGuardPort, type InputValidationResult, type InputSecurityGuard, type InjectionRateLimiter, type SenderTrustDisplayConfig } from "@comis/core";
24
+ import { type PerAgentConfig, type TypedEventBus, type MemoryPort, type HookRunner, type SecretManager, type EnvelopeConfig, type OutputGuardPort, type InputValidationResult, type InputSecurityGuard, type InjectionRateLimiter, type SenderTrustDisplayConfig, type ToolCapabilityPort } from "@comis/core";
25
25
  import type { ComisLogger } from "@comis/infra";
26
26
  import type { AgentTool } from "@mariozechner/pi-agent-core";
27
27
  import type { BudgetGuard } from "../budget/budget-guard.js";
@@ -33,6 +33,7 @@ import type { MessageSendLimiter } from "../safety/message-send-limiter.js";
33
33
  import type { ProviderHealthMonitor } from "../safety/provider-health-monitor.js";
34
34
  import type { ComisSessionManager } from "../session/comis-session-manager.js";
35
35
  import type { AuthRotationAdapter } from "../model/auth-rotation-adapter.js";
36
+ import type { OAuthTokenManager } from "../model/oauth-token-manager.js";
36
37
  import type { ActiveRunRegistry } from "./active-run-registry.js";
37
38
  import type { GeminiCacheManager } from "./gemini-cache-manager.js";
38
39
  import type { BackgroundTaskManager, NotifyFn } from "../background/index.js";
@@ -52,7 +53,7 @@ import type { AgentExecutor } from "./types.js";
52
53
  */
53
54
  export declare function createBeforeToolCallGuard(stepCounter: StepCounter, budgetGuard: BudgetGuard, circuitBreaker: CircuitBreaker, toolRetryBreaker?: ToolRetryBreaker, messageSendLimiter?: MessageSendLimiter): (context: unknown, _signal?: AbortSignal) => Promise<import("../safety/message-send-limiter.js").MessageSendVerdict | undefined>;
54
55
  /**
55
- * Merge SDK session stats into execution result for token totals (R-13).
56
+ * Merge SDK session stats into execution result for token totals.
56
57
  *
57
58
  * Token counts (input, output, cacheRead, cacheWrite, total) are sourced
58
59
  * from the SDK's cumulative session stats -- single source of truth.
@@ -120,6 +121,18 @@ export interface PiExecutorDeps {
120
121
  fallbackModels?: string[];
121
122
  /** Optional auth rotation adapter for multi-key providers. */
122
123
  authRotation?: AuthRotationAdapter;
124
+ /**
125
+ * Optional OAuth token manager. When provided, the per-LLM-call
126
+ * dispatch hook in execute() resolves the OAuth token via the resolver
127
+ * chain (agent-config -> lastGood -> first available) and sets it into
128
+ * authStorage's runtime override Map for pi-coding-agent's outbound LLM
129
+ * call.
130
+ *
131
+ * Single hook per execute() — long-running execute()s
132
+ * (>= 1 hour) may see token expire mid-loop; revisit if observed
133
+ * in production.
134
+ */
135
+ oauthManager?: OAuthTokenManager;
123
136
  /** Active run registry for mid-execution steering. */
124
137
  activeRunRegistry?: ActiveRunRegistry;
125
138
  /** Daemon-level tracing defaults for rotation. */
@@ -156,6 +169,12 @@ export interface PiExecutorDeps {
156
169
  embeddingEnqueue?: (entryId: string, content: string) => void;
157
170
  /** Optional embedding port for semantic search in discover_tools. */
158
171
  embeddingPort?: import("@comis/core").EmbeddingPort;
172
+ /**
173
+ * Tool-capability port for the per-turn capability-index renderer.
174
+ * Daemon wiring injects createNoOpCapabilityPort() from @comis/core
175
+ * until the live adapter ships.
176
+ */
177
+ toolCapabilityPort: ToolCapabilityPort;
159
178
  /** Sender trust display config from AppConfig. */
160
179
  senderTrustDisplayConfig?: SenderTrustDisplayConfig;
161
180
  /** Documentation config from AppConfig. */
@@ -27,6 +27,7 @@ tryGetContext, ContextEngineConfigSchema, } from "@comis/core";
27
27
  import { suppressError } from "@comis/shared";
28
28
  import { createToolRetryBreaker } from "../safety/tool-retry-breaker.js";
29
29
  import { createMessageSendLimiter } from "../safety/message-send-limiter.js";
30
+ import { resolveProviderApiKey } from "../model/resolve-provider-api-key.js";
30
31
  import { repairOrphanedMessages, scrubPoisonedThinkingBlocks } from "../session/orphaned-message-repair.js";
31
32
  import { scrubRedactedToolCalls } from "../session/scrub-redacted-tool-calls.js";
32
33
  import { createPiEventBridge } from "../bridge/pi-event-bridge.js";
@@ -51,7 +52,7 @@ import { validateInput } from "./executor-input-guard.js";
51
52
  import { scanWithOutputGuard } from "./executor-response-filter.js";
52
53
  import { normalizeModelCompat } from "../provider/model-compat.js";
53
54
  import { normalizeModelId } from "../provider/model-id-normalize.js";
54
- import { isAnthropicFamily, isGoogleFamily } from "../provider/capabilities.js";
55
+ import { isAnthropicFamily, isGoogleFamily, resolveProviderCapabilities } from "../provider/capabilities.js";
55
56
  import { detectOnboardingState } from "../workspace/onboarding-detector.js";
56
57
  import { PromptTimeoutError } from "./prompt-timeout.js";
57
58
  import { classifyError, classifyPromptTimeout } from "./error-classifier.js";
@@ -66,7 +67,7 @@ import { randomUUID } from "node:crypto";
66
67
  /** Number of turns to restrict breakpoints after server eviction. */
67
68
  const EVICTION_COOLDOWN_TURNS = 2;
68
69
  // ---------------------------------------------------------------------------
69
- // R-12: Proactive tool-call safety guard
70
+ // Proactive tool-call safety guard
70
71
  // ---------------------------------------------------------------------------
71
72
  /**
72
73
  * Create a beforeToolCall guard that proactively blocks tool execution when
@@ -123,10 +124,10 @@ export function createBeforeToolCallGuard(stepCounter, budgetGuard, circuitBreak
123
124
  };
124
125
  }
125
126
  // ---------------------------------------------------------------------------
126
- // R-13: Session stats delegation helper
127
+ // Session stats delegation helper
127
128
  // ---------------------------------------------------------------------------
128
129
  /**
129
- * Merge SDK session stats into execution result for token totals (R-13).
130
+ * Merge SDK session stats into execution result for token totals.
130
131
  *
131
132
  * Token counts (input, output, cacheRead, cacheWrite, total) are sourced
132
133
  * from the SDK's cumulative session stats -- single source of truth.
@@ -197,6 +198,27 @@ export function createPiExecutor(config, deps) {
197
198
  async execute(msg, sessionKey, tools, onDelta, agentId, _directives, _prevTimestamp, overrides) {
198
199
  // a. Record execution start time
199
200
  const executionStartMs = Date.now();
201
+ // a-bis. Pre-resolve OAuth token before any pi-coding-agent
202
+ // dispatch. The setRuntimeApiKey side-effect inside resolveProviderApiKey
203
+ // carries the token into pi-coding-agent's outbound LLM request via the
204
+ // runtime-override priority path. For OAuth-eligible
205
+ // providers (openai-codex, anthropic, github-copilot via pi-ai's
206
+ // built-in registry) the resolver chain (agent-config -> lastGood ->
207
+ // first available) runs and refreshes the token if expired. For
208
+ // non-OAuth providers the helper falls through to authStorage.getApiKey.
209
+ //
210
+ // Throw-propagation: on OAuthError the helper throws
211
+ // an Error containing the OAuthError.message. Outer async callers
212
+ // (gateway routes via Hono, channel handlers via try/catch) lift the
213
+ // throw into a user-facing error response. OAuthError
214
+ // is fatal — no env-var fallback, no retry, no silent rotation.
215
+ // CLAUDE.md "no empty catch" honored because we don't add a catch
216
+ // here at all; the resolver itself logs via the oauth-resolver module.
217
+ await resolveProviderApiKey(config.provider, {
218
+ authStorage: deps.authStorage,
219
+ oauthManager: deps.oauthManager,
220
+ agentConfig: config,
221
+ });
200
222
  // b. Initialize result
201
223
  const result = {
202
224
  response: "",
@@ -378,7 +400,7 @@ export function createPiExecutor(config, deps) {
378
400
  provider: resolvedModel.provider,
379
401
  id: resolvedModel.id,
380
402
  }) : undefined;
381
- // f. Execute within session adapter (R-11: use ephemeral adapter if provided)
403
+ // f. Execute within session adapter (use ephemeral adapter if provided)
382
404
  const sessionAdapter = overrides?.ephemeralSessionAdapter ?? deps.sessionAdapter;
383
405
  const lockResult = await sessionAdapter.withSession(sessionKey, async (sm) => {
384
406
  // Repair orphaned messages
@@ -428,6 +450,7 @@ export function createPiExecutor(config, deps) {
428
450
  const stableGetPromptSkillsXml = frozenPromptSkillsXml !== undefined
429
451
  ? () => frozenPromptSkillsXml
430
452
  : deps.getPromptSkillsXml;
453
+ // toolCapabilityPort flows through frozenDeps spread — no explicit re-assignment.
431
454
  const frozenDeps = { ...deps, getPromptSkillsXml: stableGetPromptSkillsXml };
432
455
  // Tool assembly pipeline: merge, settings, prompt, deferral, JIT, pruning, snapshot, normalization, serializer
433
456
  // Extracted to executor-tool-assembly.ts
@@ -437,7 +460,7 @@ export function createPiExecutor(config, deps) {
437
460
  resolvedModel, modelCompat, agentId, safetyReinforcement, _directives,
438
461
  });
439
462
  const { mergedCustomTools, } = toolAssembly;
440
- const { deferralResult, deferredContext, modelTier, discoveryTracker, settingsManager, resourceLoaderOptions, promptResult, cachedSystemTokensEstimate, } = toolAssembly;
463
+ const { deferralResult, deferredContext, capabilityIndexResult, modelTier, discoveryTracker, settingsManager, resourceLoaderOptions, promptResult, cachedSystemTokensEstimate, } = toolAssembly;
441
464
  const currentDiscoveryTracker = toolAssembly.currentDiscoveryTracker;
442
465
  const { systemPrompt, systemPromptBlocks, dynamicPreamble, inlineMemory } = promptResult;
443
466
  // DAG ingestion hook -- install BEFORE microcompaction
@@ -515,8 +538,8 @@ export function createPiExecutor(config, deps) {
515
538
  const messageSendLimiter = createMessageSendLimiter({
516
539
  maxSendsPerExecution: deps.maxSendsPerExecution ?? 3,
517
540
  });
518
- // R-12: Proactive safety -- block tool execution before it starts
519
- // when safety limits are already reached. Existing reactive checks in
541
+ // Proactive safety -- block tool execution before it starts when
542
+ // safety limits are already reached. Existing reactive checks in
520
543
  // pi-event-bridge remain as fallback for limits crossed during execution.
521
544
  // NOTE: beforeToolCall replaces the extension runner's hook. Comis does
522
545
  // not load pi-mono extensions, so this override is safe.
@@ -641,6 +664,18 @@ export function createPiExecutor(config, deps) {
641
664
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
642
665
  session.agent.transformContext = ceSetup.contextEngine.transformContext;
643
666
  }
667
+ // Align register/deregister key shape with
668
+ // BackgroundSessionResolver.formatComposite so production lookups via
669
+ // resolveActiveSession({agentId, channelType, channelId}) find the
670
+ // handle this execute() call registers. session-resolver.test.ts
671
+ // locks the formula — drift on either side breaks that test.
672
+ // NormalizedMessageSchema enforces channelType / channelId are
673
+ // non-empty (z.string().min(1)), so this composition is unconditional.
674
+ const resolverRegisterKey = formatSessionKey({
675
+ tenantId: agentId ?? "default",
676
+ channelId: `${msg.channelType}:${msg.channelId}`,
677
+ userId: msg.channelId,
678
+ });
644
679
  // Register active run for mid-execution steering
645
680
  if (deps.activeRunRegistry) {
646
681
  const handle = {
@@ -650,9 +685,9 @@ export function createPiExecutor(config, deps) {
650
685
  isStreaming: () => session.isStreaming,
651
686
  isCompacting: () => session.isCompacting,
652
687
  };
653
- const registered = deps.activeRunRegistry.register(formattedKey, handle);
688
+ const registered = deps.activeRunRegistry.register(resolverRegisterKey, handle);
654
689
  if (!registered) {
655
- deps.logger.warn({ sessionKey: formattedKey, hint: "Session already has an active run; concurrent execution may cause issues", errorKind: "resource" }, "Active run already registered");
690
+ deps.logger.warn({ sessionKey: resolverRegisterKey, hint: "Session already has an active run; concurrent execution may cause issues", errorKind: "resource" }, "Active run already registered");
656
691
  }
657
692
  }
658
693
  // SDK tool management validation and introspection.
@@ -726,7 +761,7 @@ export function createPiExecutor(config, deps) {
726
761
  deps.logger.debug({ err: sdkSkillError, hint: "SDK skill population failed, Comis discovery still active", errorKind: "dependency" }, "SDK skill population non-fatal error");
727
762
  }
728
763
  // session.sendCustomMessage() is available for operator annotations.
729
- // REQUIREMENTS.md refers to appendCustomEntry() which is the SessionManager-level API;
764
+ // Note: appendCustomEntry() is the SessionManager-level API;
730
765
  // the AgentSession wrapper exposes this as sendCustomMessage({ customType, content, display, details }).
731
766
  // Future commands or hooks can call this to inject custom entries into the JSONL session.
732
767
  // Apply command directives (thinking, compact, model, export, fork, branch)
@@ -775,7 +810,7 @@ export function createPiExecutor(config, deps) {
775
810
  session.abortCompaction();
776
811
  suppressError(session.abort(), "session abort on compaction cancel");
777
812
  },
778
- // 260501-dkl: cancel the SDK's internal auto-retry loop when the
813
+ // Cancel the SDK's internal auto-retry loop when the
779
814
  // bridge classifies the auto_retry_start error as `rate_limited`.
780
815
  // Rate-limit windows (per-minute) outlast the SDK's retry budget
781
816
  // (~30s), so retrying within the window cannot succeed.
@@ -820,7 +855,7 @@ export function createPiExecutor(config, deps) {
820
855
  sepConfig: sepEnabled ? { maxSteps: config.sep?.maxSteps ?? 15, minSteps: config.sep?.minSteps ?? 3 } : undefined,
821
856
  sepMessageText: sepEnabled ? (msg.text ?? "") : undefined,
822
857
  sepExecutionStartMs: sepEnabled ? executionStartMs : undefined,
823
- // Cache break detection Phase 2 callback.
858
+ // Cache break detection post-call callback.
824
859
  // Enrich with elapsed time for tiered server-side attribution.
825
860
  checkCacheBreak: (input) => cacheBreakDetector.checkResponseForCacheBreak({
826
861
  ...input,
@@ -841,7 +876,7 @@ export function createPiExecutor(config, deps) {
841
876
  timestamp: Date.now(),
842
877
  };
843
878
  },
844
- // 260428-hoy: pre-LLM-call hook -- runs once per `turn_start`,
879
+ // Pre-LLM-call hook -- runs once per `turn_start`,
845
880
  // BEFORE pi-ai serializes the next request. Asserts the
846
881
  // cross-turn hash invariant (logs ERROR per mutated block, with
847
882
  // module:"agent.bridge.hash-invariant"), then heals any mutated
@@ -893,7 +928,7 @@ export function createPiExecutor(config, deps) {
893
928
  }
894
929
  return live;
895
930
  },
896
- // 260428-iag wire-edge diagnostic: resolves the per-session JSONL
931
+ // Wire-edge diagnostic: resolves the per-session JSONL
897
932
  // path on demand. The bridge invokes this only after detecting the
898
933
  // signed-replay rejection signature on a 400 — never on the happy
899
934
  // path. Path comes from the same sessionAdapter that already
@@ -996,12 +1031,46 @@ export function createPiExecutor(config, deps) {
996
1031
  // Applied AFTER sideEffects so the background placeholder is returned instead of
997
1032
  // waiting for sideEffects processing. When the tool completes in background,
998
1033
  // the sideEffects are still processed by the original wrapped execute.
1034
+ // Capture origin at wrap-time via explicit threading.
1035
+ // The closure reads runPrompt-scope variables synchronously each invocation
1036
+ // so the captured origin reflects the originating session, not the
1037
+ // background-continuation context (which lacks these locals).
999
1038
  if (deps.backgroundTaskManager && config.backgroundTasks?.enabled !== false) {
1000
1039
  const bgConfig = BackgroundTasksConfigSchema.parse(config.backgroundTasks ?? {});
1040
+ const resolvedAgentId = agentId ?? "default";
1041
+ const originResolver = () => {
1042
+ // Defensive: if any required field is unexpectedly missing, fall through
1043
+ // to foreground execution (no background promotion). Promotion requires
1044
+ // a complete origin.
1045
+ if (!formattedKey || formattedKey.length === 0)
1046
+ return undefined;
1047
+ if (!msg.channelType || msg.channelType.length === 0)
1048
+ return undefined;
1049
+ if (!msg.channelId || msg.channelId.length === 0)
1050
+ return undefined;
1051
+ // Read incoming hop count off msg.metadata so the runner can enforce
1052
+ // the recursion bound. Top-level user messages have no
1053
+ // metadata.backgroundHopCount -> default to 0.
1054
+ // Cast metadata defensively because NormalizedMessageSchema.metadata
1055
+ // is z.record(z.string(), z.unknown()).
1056
+ const meta = msg.metadata;
1057
+ const rawHopCount = meta?.backgroundHopCount;
1058
+ const incomingHopCount = typeof rawHopCount === "number" && Number.isFinite(rawHopCount) && rawHopCount >= 0
1059
+ ? Math.floor(rawHopCount)
1060
+ : 0;
1061
+ return {
1062
+ agentId: resolvedAgentId,
1063
+ sessionKey: formattedKey,
1064
+ channelType: msg.channelType,
1065
+ channelId: msg.channelId,
1066
+ traceId: executionId ?? null,
1067
+ backgroundHopCount: incomingHopCount,
1068
+ };
1069
+ };
1001
1070
  for (const tool of mergedCustomTools) {
1002
1071
  const wrapped = wrapToolForAutoBackground(
1003
1072
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK interop boundary
1004
- tool, deps.backgroundTaskManager, bgConfig, deps.backgroundNotifyFn ?? (async () => { }), agentId ?? "default");
1073
+ tool, deps.backgroundTaskManager, bgConfig, deps.backgroundNotifyFn ?? (async () => { }), originResolver);
1005
1074
  tool.execute = wrapped.execute;
1006
1075
  }
1007
1076
  }
@@ -1011,7 +1080,7 @@ export function createPiExecutor(config, deps) {
1011
1080
  const promptRunResult = await runPrompt({
1012
1081
  msg, session, config, sessionKey, formattedKey, agentId, result,
1013
1082
  executionOverrides, executionStartMs, effectiveTimeout, executionId,
1014
- bridge, dynamicPreamble, deferredContext, inlineMemory,
1083
+ bridge, dynamicPreamble, deferredContext, capabilityIndexResult, inlineMemory,
1015
1084
  systemPrompt,
1016
1085
  mergedCustomTools,
1017
1086
  cmdResult, sepEnabled, executionPlanRef,
@@ -1088,13 +1157,22 @@ export function createPiExecutor(config, deps) {
1088
1157
  // Post-execution cleanup: stats merge, cache metrics, memory persist, session cleanup
1089
1158
  // Extracted to executor-post-execution.ts
1090
1159
  await postExecution({
1091
- result, session, sm, config, msg, sessionKey, formattedKey, agentId,
1160
+ result, session, sm, config, msg, sessionKey, formattedKey, resolverRegisterKey, agentId,
1092
1161
  executionStartMs, executionId, executionOverrides,
1093
1162
  bridge, unsubscribe,
1094
1163
  contextEngineRef, ceSetup, streamSetup,
1095
1164
  getTruncationSummary, getTurnBudgetSummary,
1096
1165
  executionPlanRef, sepEnabled, isOnboarding,
1097
1166
  geminiCacheHit, geminiCachedTokens, modelTier,
1167
+ // Provider attribution tag for the bookend log.
1168
+ // resolvedModel?.provider is the post-resolution / post-override
1169
+ // provider; falling back to config.provider records operator
1170
+ // INTENT on the silent-fallback misconfig path (resolvedModel
1171
+ // undefined). resolveProviderCapabilities is computed once here
1172
+ // to keep executor-post-execution.ts free of capability-cascade
1173
+ // imports.
1174
+ provider: resolvedModel?.provider ?? config.provider,
1175
+ providerFamily: resolveProviderCapabilities(resolvedModel?.provider ?? config.provider).providerFamily,
1098
1176
  deferralResult, mergedCustomTools, deliveredGuides,
1099
1177
  deps: {
1100
1178
  eventBus: deps.eventBus,
@@ -15,7 +15,7 @@ import { fromPromise, ok, err } from "@comis/shared";
15
15
  // ---------------------------------------------------------------------------
16
16
  // Implementation
17
17
  // ---------------------------------------------------------------------------
18
- const MODULE = "agent.executor.post-batch-continuation";
18
+ const SUBMODULE = "executor.post-batch-continuation";
19
19
  /* eslint-disable @typescript-eslint/no-explicit-any */
20
20
  function isToolCallBlock(block) {
21
21
  return block?.type === "toolCall" || block?.type === "tool_use";
@@ -84,7 +84,7 @@ export async function runPostBatchContinuation(deps) {
84
84
  const { session, messages, config, logger, agentId, getVisibleAssistantText } = deps;
85
85
  // Step 1: disable check.
86
86
  if (!config.enabled || config.maxRetries === 0) {
87
- logger.info({ module: MODULE, agentId, decision: "skip", reason: "disabled" }, "Post-batch continuation skipped");
87
+ logger.info({ submodule: SUBMODULE, agentId, decision: "skip", reason: "disabled" }, "Post-batch continuation skipped");
88
88
  return ok({
89
89
  recovered: false,
90
90
  attempts: 0,
@@ -97,7 +97,7 @@ export async function runPostBatchContinuation(deps) {
97
97
  /* eslint-disable @typescript-eslint/no-explicit-any */
98
98
  const msgs = messages;
99
99
  if (!Array.isArray(msgs) || msgs.length === 0) {
100
- logger.info({ module: MODULE, agentId, decision: "skip", reason: "non_empty_final" }, "Post-batch continuation skipped");
100
+ logger.info({ submodule: SUBMODULE, agentId, decision: "skip", reason: "non_empty_final" }, "Post-batch continuation skipped");
101
101
  return ok({
102
102
  recovered: false,
103
103
  attempts: 0,
@@ -113,7 +113,7 @@ export async function runPostBatchContinuation(deps) {
113
113
  !hasThinkingBlock(last.content) &&
114
114
  !hasToolCallBlock(last.content);
115
115
  if (!lastIsEmpty) {
116
- logger.info({ module: MODULE, agentId, decision: "skip", reason: "non_empty_final" }, "Post-batch continuation skipped");
116
+ logger.info({ submodule: SUBMODULE, agentId, decision: "skip", reason: "non_empty_final" }, "Post-batch continuation skipped");
117
117
  return ok({
118
118
  recovered: false,
119
119
  attempts: 0,
@@ -141,7 +141,7 @@ export async function runPostBatchContinuation(deps) {
141
141
  /* eslint-enable @typescript-eslint/no-explicit-any */
142
142
  const priorToolNames = [...priorToolNamesSet];
143
143
  if (priorToolCallCount === 0) {
144
- logger.info({ module: MODULE, agentId, decision: "skip", reason: "no_tool_calls" }, "Post-batch continuation skipped");
144
+ logger.info({ submodule: SUBMODULE, agentId, decision: "skip", reason: "no_tool_calls" }, "Post-batch continuation skipped");
145
145
  return ok({
146
146
  recovered: false,
147
147
  attempts: 0,
@@ -152,7 +152,7 @@ export async function runPostBatchContinuation(deps) {
152
152
  }
153
153
  // Step 4: decision-log fire.
154
154
  logger.info({
155
- module: MODULE,
155
+ submodule: SUBMODULE,
156
156
  agentId,
157
157
  decision: "fire",
158
158
  reason: "empty_after_tool_batch",
@@ -170,7 +170,7 @@ export async function runPostBatchContinuation(deps) {
170
170
  const text = getVisibleAssistantText(session);
171
171
  const outcomeForLog = text && text.length > 0 ? "recovered" : "still_empty";
172
172
  logger.info({
173
- module: MODULE,
173
+ submodule: SUBMODULE,
174
174
  agentId,
175
175
  attempt,
176
176
  maxAttempts: config.maxRetries,
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @module
10
10
  */
11
- import type { SessionKey, NormalizedMessage, PerAgentConfig, MemoryPort, HookRunner, SecretManager, EnvelopeConfig, WrapExternalContentOptions, TypedEventBus, SenderTrustDisplayConfig, SpawnPacket, DeliveryMirrorPort, ModelOperationType } from "@comis/core";
11
+ import type { SessionKey, NormalizedMessage, PerAgentConfig, MemoryPort, HookRunner, SecretManager, EnvelopeConfig, WrapExternalContentOptions, TypedEventBus, SenderTrustDisplayConfig, SpawnPacket, DeliveryMirrorPort, ModelOperationType, ToolCapabilityPort } from "@comis/core";
12
12
  import type { ComisLogger } from "@comis/infra";
13
13
  import type { ToolDefinition } from "@mariozechner/pi-coding-agent";
14
14
  import type { BootstrapContextFile } from "../bootstrap/types.js";
@@ -130,6 +130,14 @@ export interface PromptAssemblyParams {
130
130
  }>;
131
131
  /** Platform message character limit for auto verbosity mode. Resolved by caller from channelRegistry. */
132
132
  channelMaxChars?: number;
133
+ /**
134
+ * Tool-capability port for the gate flag.
135
+ * Only `port.isCapabilityIndexEnabled()` is read from this file — live-runtime
136
+ * port accessors (skill catalog, connected MCP servers, deferred-tool state)
137
+ * are FORBIDDEN here per the cache-fence invariant. Architecture-grep tests
138
+ * statically enforce this restriction.
139
+ */
140
+ toolCapabilityPort: ToolCapabilityPort;
133
141
  };
134
142
  msg: NormalizedMessage;
135
143
  sessionKey: SessionKey;
@@ -331,7 +331,7 @@ export async function assembleExecutionPrompt(params) {
331
331
  // Consolidated lightContext flag: heartbeat implies light-context regardless
332
332
  // of the explicit msg.metadata.lightContext flag. Callers that only set the
333
333
  // metadata flag OR only set operationType="heartbeat" produce identical
334
- // prompt output (design-doc §Risks: "Heartbeat lightContext and operationType drift").
334
+ // prompt output.
335
335
  const effectiveLightContext = msg.metadata?.lightContext === true || params.operationType === "heartbeat";
336
336
  // 2. Load workspace bootstrap files (skip for "none" mode)
337
337
  let bootstrapContextFiles = [];
@@ -522,6 +522,13 @@ export async function assembleExecutionPrompt(params) {
522
522
  const isOnboarding = await detectOnboardingState(deps.workspaceDir);
523
523
  // Shared params for both assembleRichSystemPrompt and assembleRichSystemPromptBlocks.
524
524
  // Using a single variable guarantees identity by construction.
525
+ //
526
+ // Hot-flip safety: the capability-index gate value is read once per
527
+ // assembleExecutionPrompt call via
528
+ // `deps.toolCapabilityPort.isCapabilityIndexEnabled()`. The flag is
529
+ // restart-required and stable across the session by config contract, so the
530
+ // cached system-prompt prefix is NOT retroactively rewritten when the
531
+ // underlying YAML changes mid-session.
525
532
  const assemblerParams = {
526
533
  agentName: config.name,
527
534
  promptMode,
@@ -554,6 +561,13 @@ export async function assembleExecutionPrompt(params) {
554
561
  subagentRole: undefined, // relocated to dynamic preamble for sub-agent cache sharing
555
562
  excludeBootstrapFromContext: true, // BOOTSTRAP.md is either elevated (onboarding) or dead weight (post-onboarding); never useful in Project Context
556
563
  workspaceProfile: config.workspace?.profile,
564
+ /**
565
+ * Read once per call. The value is config-derived / restart-required,
566
+ * so it's stable across all turns in this session. Reading it via the
567
+ * port (rather than from config directly) isolates this code from the
568
+ * config-schema shape and matches the live adapter contract.
569
+ */
570
+ capabilityIndexEnabled: deps.toolCapabilityPort.isCapabilityIndexEnabled(),
557
571
  sepEnabled: params.sepEnabled,
558
572
  };
559
573
  let systemPrompt = assembleRichSystemPrompt(assemblerParams);
@@ -40,7 +40,7 @@ export interface RequestBodyInjectorConfig {
40
40
  * but system prompt + tools are still worth caching. */
41
41
  getMinTokensOverride?: () => number | undefined;
42
42
  /** Callback invoked with the API-ready payload after cache breakpoint
43
- * placement. Used by cache break detector Phase 1 to extract prompt state for
43
+ * placement. Used by the cache break detector to extract prompt state for
44
44
  * change detection. Receives the mutated params, the model, and (for Anthropic) the HTTP headers. */
45
45
  onPayloadForCacheDetection?: (params: Record<string, unknown>, model: {
46
46
  id: string;
@@ -1484,7 +1484,7 @@ export function createRequestBodyInjector(config, logger) {
1484
1484
  mergedHeaders["anthropic-beta"] = allBetas.join(", ");
1485
1485
  }
1486
1486
  }
1487
- // Feed payload to cache break detector Phase 1 (after breakpoint placement)
1487
+ // Feed payload to cache break detector (after breakpoint placement)
1488
1488
  if (config.onPayloadForCacheDetection) {
1489
1489
  config.onPayloadForCacheDetection(result, model, mergedHeaders);
1490
1490
  }