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
@@ -1,6 +1,7 @@
1
1
  import type { BackgroundTasksConfig } from "@comis/core";
2
2
  import type { AgentToolResult } from "@mariozechner/pi-agent-core";
3
3
  import type { BackgroundTaskManager, NotifyFn } from "./background-task-manager.js";
4
+ import type { BackgroundTaskOrigin } from "./background-task-types.js";
4
5
  /**
5
6
  * Tool definition interface matching pi-agent-core ToolDefinition.
6
7
  *
@@ -19,9 +20,18 @@ export interface ToolDefinition {
19
20
  /**
20
21
  * Wrap a tool's execute() with auto-background promotion on timeout.
21
22
  *
23
+ * `originResolver` is called synchronously at promote-time (before the agent
24
+ * yields) so the captured origin reflects the originating session, not the
25
+ * background continuation context. Returns undefined when the wrap-site cannot
26
+ * resolve a valid origin (e.g., during a non-session-bound subagent path) --
27
+ * in that case the wrapper falls through to foreground execution (no promote).
28
+ *
29
+ * Explicit threading, NOT AsyncLocalStorage. Origin flows through factory
30
+ * params end-to-end.
31
+ *
22
32
  * If the tool is in `config.excludeTools`, returns unchanged.
23
33
  * If the tool completes before `config.autoBackgroundMs`, returns the result directly.
24
34
  * If the tool exceeds the timeout, promotes to background via manager.promote().
25
35
  * If promotion fails (concurrency limit), awaits the tool normally (foreground fallback).
26
36
  */
27
- export declare function wrapToolForAutoBackground(tool: ToolDefinition, manager: BackgroundTaskManager, config: BackgroundTasksConfig, notifyFn: NotifyFn, agentId: string): ToolDefinition;
37
+ export declare function wrapToolForAutoBackground(tool: ToolDefinition, manager: BackgroundTaskManager, config: BackgroundTasksConfig, notifyFn: NotifyFn, originResolver: () => BackgroundTaskOrigin | undefined): ToolDefinition;
@@ -12,12 +12,30 @@ import { suppressError } from "@comis/shared";
12
12
  /**
13
13
  * Wrap a tool's execute() with auto-background promotion on timeout.
14
14
  *
15
+ * `originResolver` is called synchronously at promote-time (before the agent
16
+ * yields) so the captured origin reflects the originating session, not the
17
+ * background continuation context. Returns undefined when the wrap-site cannot
18
+ * resolve a valid origin (e.g., during a non-session-bound subagent path) --
19
+ * in that case the wrapper falls through to foreground execution (no promote).
20
+ *
21
+ * Explicit threading, NOT AsyncLocalStorage. Origin flows through factory
22
+ * params end-to-end.
23
+ *
15
24
  * If the tool is in `config.excludeTools`, returns unchanged.
16
25
  * If the tool completes before `config.autoBackgroundMs`, returns the result directly.
17
26
  * If the tool exceeds the timeout, promotes to background via manager.promote().
18
27
  * If promotion fails (concurrency limit), awaits the tool normally (foreground fallback).
19
28
  */
20
- export function wrapToolForAutoBackground(tool, manager, config, notifyFn, agentId) {
29
+ export function wrapToolForAutoBackground(tool, manager, config, notifyFn, originResolver) {
30
+ // `exec` opts out of the generic auto-background wrapper to enforce
31
+ // single-owner backgrounding. The exec-tool's own internal escalation path
32
+ // (packages/skills/src/builtin/exec-tool.ts:613-668) is the SOLE
33
+ // backgrounding owner for `exec`; the generic timeout-based wrapper would
34
+ // double-promote. Hardcoded literal — does NOT modify config.excludeTools
35
+ // so operator-set exclusions remain unchanged.
36
+ if (tool.name === "exec") {
37
+ return tool;
38
+ }
21
39
  if (config.excludeTools.includes(tool.name)) {
22
40
  return tool;
23
41
  }
@@ -57,8 +75,16 @@ export function wrapToolForAutoBackground(tool, manager, config, notifyFn, agent
57
75
  if (raceResult.kind === "result") {
58
76
  return raceResult.value;
59
77
  }
60
- // Timeout: attempt background promotion
61
- const promoteResult = manager.promote(agentId, tool.name, taskPromise, ac);
78
+ // Timeout: resolve origin synchronously before yielding to the background.
79
+ // Explicit threading, NOT AsyncLocalStorage.
80
+ const origin = originResolver();
81
+ if (!origin) {
82
+ // No originating session context (e.g., wrap-site is a subagent without
83
+ // a captured caller session). Treat like a concurrency-limit fallback:
84
+ // run the tool in the foreground, no background promotion.
85
+ return await taskPromise;
86
+ }
87
+ const promoteResult = manager.promote(tool.name, taskPromise, ac, origin);
62
88
  if (!promoteResult.ok) {
63
89
  // Concurrency limit hit: fall back to foreground (await normally)
64
90
  return await taskPromise;
@@ -73,7 +99,7 @@ export function wrapToolForAutoBackground(tool, manager, config, notifyFn, agent
73
99
  // collapses to `content: undefined` and triggers the silent-LLM-failure
74
100
  // cascade (see AGENTS.md / auto-background-middleware.test.ts invariant).
75
101
  const placeholderText = `Tool "${tool.name}" is taking longer than expected and has been moved to the background. ` +
76
- `Task ID: ${taskId}. The user will be notified when it completes.`;
102
+ `Task ID: ${taskId}. I'll continue when it completes.`;
77
103
  return {
78
104
  content: [{ type: "text", text: placeholderText }],
79
105
  details: {
@@ -1,6 +1,6 @@
1
1
  import { type Result } from "@comis/shared";
2
2
  import type { TypedEventBus } from "@comis/core";
3
- import type { BackgroundTask } from "./background-task-types.js";
3
+ import type { BackgroundTask, BackgroundTaskOrigin, BackgroundSessionState, BackgroundTaskNotificationPolicy } from "./background-task-types.js";
4
4
  /** Notification callback fired when background task completes or fails. */
5
5
  export type NotifyFn = (opts: {
6
6
  agentId: string;
@@ -21,8 +21,21 @@ export interface BackgroundTaskManagerOpts {
21
21
  maxBackgroundDurationMs?: number;
22
22
  }
23
23
  export interface BackgroundTaskManager {
24
- promote(agentId: string, toolName: string, promise: Promise<unknown>, ac: AbortController): Result<string, Error>;
24
+ promote(toolName: string, promise: Promise<unknown>, ac: AbortController, origin: BackgroundTaskOrigin, notificationPolicy?: BackgroundTaskNotificationPolicy): Result<string, Error>;
25
+ /**
26
+ * Mark a task as completed.
27
+ *
28
+ * The legacy `notifyFn` argument is preserved for backward compatibility but
29
+ * unused — the completion-dispatcher subscribes to the
30
+ * `background_task:completed` event emitted here and decides whether to fire
31
+ * the user-visible fallback notification. Single-owner contract eliminates
32
+ * double-notify.
33
+ */
25
34
  complete(taskId: string, result: unknown, notifyFn?: NotifyFn): void;
35
+ /**
36
+ * Mark a task as failed. See `complete` for the single-owner note — the
37
+ * `notifyFn` argument is unused; the dispatcher routes notification.
38
+ */
26
39
  fail(taskId: string, error: unknown, notifyFn?: NotifyFn): void;
27
40
  cancel(taskId: string): Result<void, Error>;
28
41
  getTask(taskId: string): BackgroundTask | undefined;
@@ -30,5 +43,12 @@ export interface BackgroundTaskManager {
30
43
  getAllTasks(): BackgroundTask[];
31
44
  recoverOnStartup(): void;
32
45
  cleanup(maxAgeMs?: number): void;
46
+ /**
47
+ * Atomically transition the in-memory task's dispatchState AND persist.
48
+ * Returns true on success; false if task does not exist. The dispatcher
49
+ * calls this from its handler so SIGKILL-recovery preserves the recovered
50
+ * state across daemon restart.
51
+ */
52
+ transitionDispatchState(taskId: string, next: BackgroundSessionState): boolean;
33
53
  }
34
54
  export declare function createBackgroundTaskManager(opts: BackgroundTaskManagerOpts): BackgroundTaskManager;
@@ -8,7 +8,7 @@
8
8
  * @module
9
9
  */
10
10
  import { randomUUID } from "node:crypto";
11
- import { ok, err, suppressError } from "@comis/shared";
11
+ import { ok, err } from "@comis/shared";
12
12
  import { persistTaskSync, recoverTasks, removeTaskFile } from "./background-task-persistence.js";
13
13
  const MAX_RESULT_CHARS = 102_400; // 100KB
14
14
  export function createBackgroundTaskManager(opts) {
@@ -35,7 +35,26 @@ export function createBackgroundTaskManager(opts) {
35
35
  }
36
36
  }
37
37
  const manager = {
38
- promote(agentId, toolName, promise, ac) {
38
+ promote(toolName, promise, ac, origin, notificationPolicy) {
39
+ // Reject calls with missing/invalid origin (no silent fallback).
40
+ if (!origin || typeof origin !== "object") {
41
+ return err(new Error("BackgroundTaskOrigin is required (received undefined or non-object)"));
42
+ }
43
+ if (!origin.agentId || origin.agentId.length === 0) {
44
+ return err(new Error("BackgroundTaskOrigin.agentId must be a non-empty string"));
45
+ }
46
+ if (!origin.sessionKey || origin.sessionKey.length === 0) {
47
+ return err(new Error("BackgroundTaskOrigin.sessionKey must be a non-empty string"));
48
+ }
49
+ if (!origin.channelType || origin.channelType.length === 0) {
50
+ return err(new Error("BackgroundTaskOrigin.channelType must be a non-empty string"));
51
+ }
52
+ if (!origin.channelId || origin.channelId.length === 0) {
53
+ return err(new Error("BackgroundTaskOrigin.channelId must be a non-empty string"));
54
+ }
55
+ // traceId may be null (per BackgroundTaskOriginSchema), so no length check.
56
+ // backgroundHopCount has a schema-level default of 0; no inline guard needed.
57
+ const agentId = origin.agentId;
39
58
  const agentCurrent = perAgentCount.get(agentId) ?? 0;
40
59
  if (agentCurrent >= maxPerAgent) {
41
60
  return err(new Error(`Concurrency limit exceeded: agent ${agentId} has ${agentCurrent}/${maxPerAgent} tasks`));
@@ -46,24 +65,30 @@ export function createBackgroundTaskManager(opts) {
46
65
  const taskId = randomUUID();
47
66
  const task = {
48
67
  id: taskId,
49
- agentId,
50
68
  toolName,
51
69
  status: "running",
52
70
  startedAt: Date.now(),
71
+ origin,
72
+ // Seed the dispatch state machine. Default policy is "deferred" —
73
+ // the dispatcher inspects dispatchState before firing fallback notify
74
+ // (at-most-once).
75
+ notificationPolicy: notificationPolicy ?? "deferred",
76
+ dispatchState: "pending",
53
77
  _promise: promise,
54
78
  _abortController: ac,
55
79
  };
56
- tasks.set(taskId, task);
57
- incrementCounters(agentId);
58
- // sync write BEFORE returning placeholder
59
- persistTaskSync(dataDir, task);
60
- // Hard timeout
61
- task._hardTimeoutTimer = setTimeout(() => {
80
+ // Hard-timeout abort
81
+ const timer = setTimeout(() => {
62
82
  if (task.status === "running") {
63
83
  ac.abort();
64
84
  manager.fail(taskId, new Error("Hard timeout exceeded"));
65
85
  }
66
86
  }, maxBackgroundDurationMs);
87
+ timer.unref();
88
+ task._hardTimeoutTimer = timer;
89
+ tasks.set(taskId, task);
90
+ incrementCounters(agentId);
91
+ persistTaskSync(dataDir, task);
67
92
  eventBus.emit("background_task:promoted", {
68
93
  agentId,
69
94
  taskId,
@@ -72,7 +97,7 @@ export function createBackgroundTaskManager(opts) {
72
97
  });
73
98
  return ok(taskId);
74
99
  },
75
- complete(taskId, result, notifyFn) {
100
+ complete(taskId, result, _notifyFn) {
76
101
  const task = tasks.get(taskId);
77
102
  if (!task || task.status !== "running")
78
103
  return;
@@ -81,26 +106,25 @@ export function createBackgroundTaskManager(opts) {
81
106
  task.result = truncateResult(result);
82
107
  if (task._hardTimeoutTimer)
83
108
  clearTimeout(task._hardTimeoutTimer);
84
- decrementCounters(task.agentId);
109
+ decrementCounters(task.origin.agentId);
85
110
  persistTaskSync(dataDir, task);
86
111
  const durationMs = task.completedAt - task.startedAt;
87
112
  eventBus.emit("background_task:completed", {
88
- agentId: task.agentId,
113
+ agentId: task.origin.agentId,
89
114
  taskId,
90
115
  toolName: task.toolName,
91
116
  durationMs,
117
+ origin: task.origin,
92
118
  timestamp: Date.now(),
93
119
  });
94
- if (notifyFn) {
95
- suppressError(notifyFn({
96
- agentId: task.agentId,
97
- message: `Background task "${task.toolName}" completed (${Math.round(durationMs / 1000)}s). Task ID: ${taskId}`,
98
- priority: "normal",
99
- origin: "background_task",
100
- }), "background task completion notification");
101
- }
120
+ // Notification routing lives in the completion-dispatcher (subscribed
121
+ // to background_task:completed above). The legacy `notifyFn` argument
122
+ // is kept for backward compatibility but unused here — the dispatcher
123
+ // inspects task.dispatchState before firing the user-visible fallback,
124
+ // and the runner skips when state is "notified" (single-owner contract,
125
+ // zero spurious outbound).
102
126
  },
103
- fail(taskId, error, notifyFn) {
127
+ fail(taskId, error, _notifyFn) {
104
128
  const task = tasks.get(taskId);
105
129
  if (!task || task.status !== "running")
106
130
  return;
@@ -109,25 +133,19 @@ export function createBackgroundTaskManager(opts) {
109
133
  task.error = error instanceof Error ? error.message : String(error);
110
134
  if (task._hardTimeoutTimer)
111
135
  clearTimeout(task._hardTimeoutTimer);
112
- decrementCounters(task.agentId);
136
+ decrementCounters(task.origin.agentId);
113
137
  persistTaskSync(dataDir, task);
114
138
  const durationMs = task.completedAt - task.startedAt;
115
139
  eventBus.emit("background_task:failed", {
116
- agentId: task.agentId,
140
+ agentId: task.origin.agentId,
117
141
  taskId,
118
142
  toolName: task.toolName,
119
143
  error: task.error,
120
144
  durationMs,
145
+ origin: task.origin,
121
146
  timestamp: Date.now(),
122
147
  });
123
- if (notifyFn) {
124
- suppressError(notifyFn({
125
- agentId: task.agentId,
126
- message: `Background task "${task.toolName}" failed: ${task.error}. Task ID: ${taskId}`,
127
- priority: "normal",
128
- origin: "background_task",
129
- }), "background task failure notification");
130
- }
148
+ // See complete() above — notifyFn arg is unused; dispatcher owns routing.
131
149
  },
132
150
  cancel(taskId) {
133
151
  const task = tasks.get(taskId);
@@ -141,10 +159,10 @@ export function createBackgroundTaskManager(opts) {
141
159
  task._abortController.abort();
142
160
  if (task._hardTimeoutTimer)
143
161
  clearTimeout(task._hardTimeoutTimer);
144
- decrementCounters(task.agentId);
162
+ decrementCounters(task.origin.agentId);
145
163
  persistTaskSync(dataDir, task);
146
164
  eventBus.emit("background_task:cancelled", {
147
- agentId: task.agentId,
165
+ agentId: task.origin.agentId,
148
166
  taskId,
149
167
  toolName: task.toolName,
150
168
  timestamp: Date.now(),
@@ -155,7 +173,7 @@ export function createBackgroundTaskManager(opts) {
155
173
  return tasks.get(taskId);
156
174
  },
157
175
  getTasks(agentId) {
158
- return [...tasks.values()].filter((t) => t.agentId === agentId);
176
+ return [...tasks.values()].filter((t) => t.origin.agentId === agentId);
159
177
  },
160
178
  getAllTasks() {
161
179
  return [...tasks.values()];
@@ -163,20 +181,37 @@ export function createBackgroundTaskManager(opts) {
163
181
  recoverOnStartup() {
164
182
  const recovered = recoverTasks(dataDir);
165
183
  let count = 0;
184
+ let dispatchPreserved = 0;
166
185
  for (const persisted of recovered) {
167
- // Only import tasks that were recovered (previously running -> now failed)
168
- const task = {
169
- ...persisted,
170
- };
186
+ // The persistence-write contract guarantees populated origin /
187
+ // notificationPolicy / dispatchState on every task file.
188
+ // background-task-persistence.ts rejects shape-malformed files
189
+ // (missing id / toolName) before they reach here; we propagate the
190
+ // persisted record as-is.
191
+ const task = persisted;
171
192
  tasks.set(task.id, task);
172
193
  if (persisted.status === "failed" && persisted.error === "Daemon restarted while task was running") {
194
+ // Recovery-without-events: if dispatchState is already "notified" or
195
+ // "dispatched", the dispatcher already routed pre-restart; do NOT
196
+ // re-emit the background_task:failed event (which would re-trigger
197
+ // fallback).
198
+ if (task.dispatchState === "notified" || task.dispatchState === "dispatched") {
199
+ dispatchPreserved++;
200
+ logger.debug({
201
+ taskId: task.id,
202
+ dispatchState: task.dispatchState,
203
+ hint: "Pre-restart dispatch state preserved; skipping re-emit (D-S2 recovery-without-events)",
204
+ }, "Recovery: skipped re-emit");
205
+ continue;
206
+ }
173
207
  count++;
174
208
  eventBus.emit("background_task:failed", {
175
- agentId: task.agentId,
209
+ agentId: task.origin.agentId,
176
210
  taskId: task.id,
177
211
  toolName: task.toolName,
178
212
  error: persisted.error,
179
213
  durationMs: (persisted.completedAt ?? Date.now()) - persisted.startedAt,
214
+ origin: task.origin,
180
215
  timestamp: Date.now(),
181
216
  });
182
217
  }
@@ -184,13 +219,26 @@ export function createBackgroundTaskManager(opts) {
184
219
  if (count > 0) {
185
220
  logger.info({ count }, "Recovered background tasks marked as failed");
186
221
  }
222
+ if (dispatchPreserved > 0) {
223
+ logger.info({ count: dispatchPreserved }, "Recovered tasks with preserved dispatch state (no re-emit)");
224
+ }
225
+ },
226
+ transitionDispatchState(taskId, next) {
227
+ const task = tasks.get(taskId);
228
+ if (!task)
229
+ return false;
230
+ // Idempotent — same-state transitions are allowed (no-op write).
231
+ task.dispatchState = next;
232
+ // Persist atomically so recovery-after-SIGKILL sees the transition.
233
+ persistTaskSync(dataDir, task);
234
+ return true;
187
235
  },
188
236
  cleanup(maxAgeMs = 86_400_000) {
189
237
  const cutoff = Date.now() - maxAgeMs;
190
238
  for (const [taskId, task] of tasks) {
191
239
  if (task.status !== "running" && (task.completedAt ?? task.startedAt) < cutoff) {
192
240
  tasks.delete(taskId);
193
- removeTaskFile(dataDir, task.agentId, taskId);
241
+ removeTaskFile(dataDir, task.origin.agentId, taskId);
194
242
  }
195
243
  }
196
244
  },
@@ -7,23 +7,30 @@
7
7
  *
8
8
  * @module
9
9
  */
10
- import { mkdirSync, writeFileSync, readFileSync, readdirSync, unlinkSync, existsSync } from "node:fs";
10
+ import { mkdirSync, writeFileSync, readFileSync, readdirSync, statSync, unlinkSync, existsSync } from "node:fs";
11
11
  import { safePath } from "@comis/core";
12
12
  /** Directory name under data dir for background task state files. */
13
13
  export const TASK_DIR_NAME = "background-tasks";
14
14
  /**
15
15
  * Extract the serializable subset from a BackgroundTask.
16
+ *
17
+ * notificationPolicy + dispatchState are copied across when present so the
18
+ * state machine survives daemon restart-recovery. Both fields are optional in
19
+ * PersistedTaskState; we use spread-when-defined to avoid emitting
20
+ * `"notificationPolicy": undefined` to disk for callers that do not set them.
16
21
  */
17
22
  function toPersistedState(task) {
18
23
  return {
19
24
  id: task.id,
20
- agentId: task.agentId,
21
25
  toolName: task.toolName,
22
26
  status: task.status,
23
27
  startedAt: task.startedAt,
24
28
  completedAt: task.completedAt,
25
29
  result: task.result,
26
30
  error: task.error,
31
+ origin: task.origin,
32
+ ...(task.notificationPolicy !== undefined && { notificationPolicy: task.notificationPolicy }),
33
+ ...(task.dispatchState !== undefined && { dispatchState: task.dispatchState }),
27
34
  };
28
35
  }
29
36
  /**
@@ -32,7 +39,7 @@ function toPersistedState(task) {
32
39
  * Writes to `dataDir/{agentId}/{taskId}.json`.
33
40
  */
34
41
  export function persistTaskSync(dataDir, task) {
35
- const agentDir = safePath(dataDir, task.agentId);
42
+ const agentDir = safePath(dataDir, task.origin.agentId);
36
43
  mkdirSync(agentDir, { recursive: true });
37
44
  const filePath = safePath(agentDir, `${task.id}.json`);
38
45
  const state = "_promise" in task ? toPersistedState(task) : task;
@@ -72,6 +79,20 @@ export function recoverTasks(dataDir) {
72
79
  }
73
80
  for (const agentId of agentDirs) {
74
81
  const agentDir = safePath(dataDir, agentId);
82
+ // Guard against non-directory entries in dataDir. statSync may throw if
83
+ // the entry vanished between readdirSync and here; skip gracefully.
84
+ // Non-directory entries (lock files, READMEs, accidental
85
+ // file-with-agentId-name) MUST be skipped explicitly so they don't
86
+ // shadow legitimate agent recovery silently.
87
+ let dirStat;
88
+ try {
89
+ dirStat = statSync(agentDir);
90
+ }
91
+ catch {
92
+ continue;
93
+ }
94
+ if (!dirStat.isDirectory())
95
+ continue;
75
96
  let files;
76
97
  try {
77
98
  files = readdirSync(agentDir);
@@ -85,7 +106,16 @@ export function recoverTasks(dataDir) {
85
106
  const filePath = safePath(agentDir, file);
86
107
  try {
87
108
  const raw = readFileSync(filePath, "utf-8");
88
- const task = JSON.parse(raw);
109
+ const parsed = JSON.parse(raw);
110
+ // Shape guard — skip completely malformed files. Tasks always carry
111
+ // id + toolName + origin; the producer-side persistTaskSync writes
112
+ // all three unconditionally. A file failing this guard is either
113
+ // truncated mid-write or a legacy artifact operators should clean
114
+ // up manually.
115
+ if (!parsed.id || !parsed.toolName || !parsed.origin) {
116
+ continue;
117
+ }
118
+ const task = parsed;
89
119
  if (task.status === "running") {
90
120
  task.status = "failed";
91
121
  task.error = "Daemon restarted while task was running";
@@ -1,18 +1,62 @@
1
1
  /**
2
- * Background task types for automatic tool execution promotion.
2
+ * Background task type definitions.
3
3
  *
4
4
  * @module
5
5
  */
6
+ import type { BackgroundTaskOrigin } from "@comis/core";
7
+ export type { BackgroundTaskOrigin };
6
8
  export type BackgroundTaskStatus = "running" | "completed" | "failed" | "cancelled";
9
+ /**
10
+ * Notification policy for a background task. Typed enum (NOT a boolean):
11
+ * preserves intent across restart-recovery so the recovered task's dispatch
12
+ * path matches its original promote-time intent. A boolean collapses to
13
+ * true/false on rehydrate and loses the distinction between "the operator
14
+ * wanted deferred routing" and "the operator wanted immediate notification".
15
+ *
16
+ * - "deferred" — Default. Wait for the dispatcher to attempt session
17
+ * re-entry; only fall back to user-visible notification
18
+ * when re-entry fails (session expired, hop cap hit).
19
+ * - "immediate" — Skip the dispatcher; fire user-visible notification
20
+ * immediately. Reserved for tasks that explicitly want
21
+ * the legacy literal-text notification.
22
+ * - "silent" — Skip both dispatcher and user-visible notification.
23
+ * Reserved for fully-internal tasks.
24
+ *
25
+ * Default for new promote() calls: "deferred".
26
+ */
27
+ export type BackgroundTaskNotificationPolicy = "deferred" | "immediate" | "silent";
28
+ /**
29
+ * Three-state session lifecycle for a background task's notification routing.
30
+ * State-machine transitions are the single source of truth for at-most-once
31
+ * fallback.
32
+ *
33
+ * - "pending" — Promotion happened; no completion event yet (or completion
34
+ * event arrived but dispatcher has not classified it).
35
+ * - "notified" — Fallback notification fired (user-visible literal text);
36
+ * recovery-after-restart MUST NOT re-emit.
37
+ * - "dispatched" — Re-entry triggered against the originating session;
38
+ * no fallback notification needed.
39
+ */
40
+ export type BackgroundSessionState = "pending" | "notified" | "dispatched";
7
41
  export interface BackgroundTask {
8
42
  id: string;
9
- agentId: string;
10
43
  toolName: string;
11
44
  status: BackgroundTaskStatus;
12
45
  startedAt: number;
13
46
  completedAt?: number;
14
47
  result?: string;
15
48
  error?: string;
49
+ /** Originating session attribution (incl. backgroundHopCount) -- captured at
50
+ * promote-time, persisted on disk, preserved across recoverOnStartup.
51
+ * Required (no silent fallback). */
52
+ origin: BackgroundTaskOrigin;
53
+ /** Live notification policy. Optional; recovery defaults to "deferred" when
54
+ * absent. */
55
+ notificationPolicy?: BackgroundTaskNotificationPolicy;
56
+ /** Live three-state session lifecycle. Optional; recovery defaults to
57
+ * "pending" when absent. The dispatcher inspects this before firing
58
+ * notifyFn. */
59
+ dispatchState?: BackgroundSessionState;
16
60
  _promise?: Promise<unknown>;
17
61
  _abortController?: AbortController;
18
62
  _hardTimeoutTimer?: ReturnType<typeof setTimeout>;
@@ -20,11 +64,23 @@ export interface BackgroundTask {
20
64
  /** Serializable subset of BackgroundTask for file persistence. */
21
65
  export interface PersistedTaskState {
22
66
  id: string;
23
- agentId: string;
24
67
  toolName: string;
25
68
  status: BackgroundTaskStatus;
26
69
  startedAt: number;
27
70
  completedAt?: number;
28
71
  result?: string;
29
72
  error?: string;
73
+ /** Persisted origin -- read back by recoverOnStartup so completion routing
74
+ * survives daemon restarts. */
75
+ origin: BackgroundTaskOrigin;
76
+ /**
77
+ * Notification policy chosen at promote time. Optional; recovery defaults
78
+ * to "deferred" when absent.
79
+ */
80
+ notificationPolicy?: BackgroundTaskNotificationPolicy;
81
+ /**
82
+ * Three-state session lifecycle. Optional; recovery defaults to "pending"
83
+ * when absent. The dispatcher inspects this before firing notifyFn.
84
+ */
85
+ dispatchState?: BackgroundSessionState;
30
86
  }
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  /**
3
- * Background task types for automatic tool execution promotion.
3
+ * Background task type definitions.
4
4
  *
5
5
  * @module
6
6
  */