dsh-botgroup 0.0.0-stage → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (858) hide show
  1. package/LICENSE +18 -0
  2. package/README.en.md +118 -0
  3. package/README.md +117 -2
  4. package/THIRD_PARTY_NOTICES.txt +212 -0
  5. package/assets/logo-1024.png +0 -0
  6. package/cordis.patch.yml +13 -0
  7. package/icon.svg +9 -0
  8. package/lib/client.js +31791 -0
  9. package/lib/client.js.map +7 -0
  10. package/lib/host/activity/first-user.d.ts +16 -0
  11. package/lib/host/activity/first-user.js +25 -0
  12. package/lib/host/activity/first-user.js.map +1 -0
  13. package/lib/host/activity/preview.d.ts +2 -0
  14. package/lib/host/activity/preview.js +5 -0
  15. package/lib/host/activity/preview.js.map +1 -0
  16. package/lib/host/activity/remote.d.ts +15 -0
  17. package/lib/host/activity/remote.js +66 -0
  18. package/lib/host/activity/remote.js.map +1 -0
  19. package/lib/host/activity/tracker.d.ts +12 -0
  20. package/lib/host/activity/tracker.js +157 -0
  21. package/lib/host/activity/tracker.js.map +1 -0
  22. package/lib/host/automation/coordinator.d.ts +26 -0
  23. package/lib/host/automation/coordinator.js +58 -0
  24. package/lib/host/automation/coordinator.js.map +1 -0
  25. package/lib/host/automation/delivery.d.ts +16 -0
  26. package/lib/host/automation/delivery.js +65 -0
  27. package/lib/host/automation/delivery.js.map +1 -0
  28. package/lib/host/automation/errors.d.ts +16 -0
  29. package/lib/host/automation/errors.js +19 -0
  30. package/lib/host/automation/errors.js.map +1 -0
  31. package/lib/host/automation/index.d.ts +2 -0
  32. package/lib/host/automation/index.js +4 -0
  33. package/lib/host/automation/index.js.map +1 -0
  34. package/lib/host/automation/remote.d.ts +280 -0
  35. package/lib/host/automation/remote.js +152 -0
  36. package/lib/host/automation/remote.js.map +1 -0
  37. package/lib/host/automation/store.d.ts +297 -0
  38. package/lib/host/automation/store.js +286 -0
  39. package/lib/host/automation/store.js.map +1 -0
  40. package/lib/host/bot-context.d.ts +11 -0
  41. package/lib/host/bot-context.js +346 -0
  42. package/lib/host/bot-context.js.map +1 -0
  43. package/lib/host/capabilities/platform.d.ts +17 -0
  44. package/lib/host/capabilities/platform.js +17 -0
  45. package/lib/host/capabilities/platform.js.map +1 -0
  46. package/lib/host/capabilities/remote.d.ts +94 -0
  47. package/lib/host/capabilities/remote.js +59 -0
  48. package/lib/host/capabilities/remote.js.map +1 -0
  49. package/lib/host/capabilities/service.d.ts +82 -0
  50. package/lib/host/capabilities/service.js +144 -0
  51. package/lib/host/capabilities/service.js.map +1 -0
  52. package/lib/host/collaboration/remote.d.ts +89 -0
  53. package/lib/host/collaboration/remote.js +109 -0
  54. package/lib/host/collaboration/remote.js.map +1 -0
  55. package/lib/host/collaboration/service.d.ts +61 -0
  56. package/lib/host/collaboration/service.js +191 -0
  57. package/lib/host/collaboration/service.js.map +1 -0
  58. package/lib/host/common/integration-stores.d.ts +162 -0
  59. package/lib/host/common/integration-stores.js +50 -0
  60. package/lib/host/common/integration-stores.js.map +1 -0
  61. package/lib/host/common/native-ambient-source.d.ts +7 -0
  62. package/lib/host/common/native-ambient-source.js +15 -0
  63. package/lib/host/common/native-ambient-source.js.map +1 -0
  64. package/lib/host/common/operations.d.ts +23 -0
  65. package/lib/host/common/operations.js +38 -0
  66. package/lib/host/common/operations.js.map +1 -0
  67. package/lib/host/common/subagent-activation.d.ts +7 -0
  68. package/lib/host/common/subagent-activation.js +10 -0
  69. package/lib/host/common/subagent-activation.js.map +1 -0
  70. package/lib/host/composer.d.ts +15 -0
  71. package/lib/host/composer.js +102 -0
  72. package/lib/host/composer.js.map +1 -0
  73. package/lib/host/connectors/remote.d.ts +215 -0
  74. package/lib/host/connectors/remote.js +111 -0
  75. package/lib/host/connectors/remote.js.map +1 -0
  76. package/lib/host/connectors/service.d.ts +150 -0
  77. package/lib/host/connectors/service.js +491 -0
  78. package/lib/host/connectors/service.js.map +1 -0
  79. package/lib/host/data-flow/agent-binding.d.ts +8 -0
  80. package/lib/host/data-flow/agent-binding.js +4 -0
  81. package/lib/host/data-flow/agent-binding.js.map +1 -0
  82. package/lib/host/data-flow/connector-boundary.d.ts +7 -0
  83. package/lib/host/data-flow/connector-boundary.js +33 -0
  84. package/lib/host/data-flow/connector-boundary.js.map +1 -0
  85. package/lib/host/data-flow/delegation.d.ts +6 -0
  86. package/lib/host/data-flow/delegation.js +73 -0
  87. package/lib/host/data-flow/delegation.js.map +1 -0
  88. package/lib/host/data-flow/egress.d.ts +26 -0
  89. package/lib/host/data-flow/egress.js +118 -0
  90. package/lib/host/data-flow/egress.js.map +1 -0
  91. package/lib/host/data-flow/grants.d.ts +18 -0
  92. package/lib/host/data-flow/grants.js +39 -0
  93. package/lib/host/data-flow/grants.js.map +1 -0
  94. package/lib/host/data-flow/graph-capability.d.ts +3 -0
  95. package/lib/host/data-flow/graph-capability.js +21 -0
  96. package/lib/host/data-flow/graph-capability.js.map +1 -0
  97. package/lib/host/data-flow/labels.d.ts +6 -0
  98. package/lib/host/data-flow/labels.js +30 -0
  99. package/lib/host/data-flow/labels.js.map +1 -0
  100. package/lib/host/data-flow/lineage.d.ts +10 -0
  101. package/lib/host/data-flow/lineage.js +35 -0
  102. package/lib/host/data-flow/lineage.js.map +1 -0
  103. package/lib/host/data-flow/managed-copies.d.ts +216 -0
  104. package/lib/host/data-flow/managed-copies.js +37 -0
  105. package/lib/host/data-flow/managed-copies.js.map +1 -0
  106. package/lib/host/data-flow/native-policy.d.ts +26 -0
  107. package/lib/host/data-flow/native-policy.js +86 -0
  108. package/lib/host/data-flow/native-policy.js.map +1 -0
  109. package/lib/host/data-flow/outlets.d.ts +55 -0
  110. package/lib/host/data-flow/outlets.js +307 -0
  111. package/lib/host/data-flow/outlets.js.map +1 -0
  112. package/lib/host/data-flow/tool-guard.d.ts +13 -0
  113. package/lib/host/data-flow/tool-guard.js +123 -0
  114. package/lib/host/data-flow/tool-guard.js.map +1 -0
  115. package/lib/host/delegate/continuation.d.ts +5 -0
  116. package/lib/host/delegate/continuation.js +44 -0
  117. package/lib/host/delegate/continuation.js.map +1 -0
  118. package/lib/host/delegate/guard.d.ts +7 -0
  119. package/lib/host/delegate/guard.js +53 -0
  120. package/lib/host/delegate/guard.js.map +1 -0
  121. package/lib/host/delegate/tool.d.ts +3 -0
  122. package/lib/host/delegate/tool.js +207 -0
  123. package/lib/host/delegate/tool.js.map +1 -0
  124. package/lib/host/errors.d.ts +9 -0
  125. package/lib/host/errors.js +17 -0
  126. package/lib/host/errors.js.map +1 -0
  127. package/lib/host/groups/concurrent.d.ts +29 -0
  128. package/lib/host/groups/concurrent.js +277 -0
  129. package/lib/host/groups/concurrent.js.map +1 -0
  130. package/lib/host/groups/data-flow.d.ts +21 -0
  131. package/lib/host/groups/data-flow.js +59 -0
  132. package/lib/host/groups/data-flow.js.map +1 -0
  133. package/lib/host/groups/failure.d.ts +10 -0
  134. package/lib/host/groups/failure.js +36 -0
  135. package/lib/host/groups/failure.js.map +1 -0
  136. package/lib/host/groups/members.d.ts +172 -0
  137. package/lib/host/groups/members.js +242 -0
  138. package/lib/host/groups/members.js.map +1 -0
  139. package/lib/host/groups/messages.d.ts +389 -0
  140. package/lib/host/groups/messages.js +151 -0
  141. package/lib/host/groups/messages.js.map +1 -0
  142. package/lib/host/groups/model-selection.d.ts +15 -0
  143. package/lib/host/groups/model-selection.js +12 -0
  144. package/lib/host/groups/model-selection.js.map +1 -0
  145. package/lib/host/groups/model.d.ts +331 -0
  146. package/lib/host/groups/model.js +26 -0
  147. package/lib/host/groups/model.js.map +1 -0
  148. package/lib/host/groups/owner-follow-up.d.ts +4 -0
  149. package/lib/host/groups/owner-follow-up.js +34 -0
  150. package/lib/host/groups/owner-follow-up.js.map +1 -0
  151. package/lib/host/groups/recall-sessions.d.ts +32 -0
  152. package/lib/host/groups/recall-sessions.js +145 -0
  153. package/lib/host/groups/recall-sessions.js.map +1 -0
  154. package/lib/host/groups/recall-tool.d.ts +9 -0
  155. package/lib/host/groups/recall-tool.js +275 -0
  156. package/lib/host/groups/recall-tool.js.map +1 -0
  157. package/lib/host/groups/recall.d.ts +37 -0
  158. package/lib/host/groups/recall.js +406 -0
  159. package/lib/host/groups/recall.js.map +1 -0
  160. package/lib/host/groups/remote.d.ts +1219 -0
  161. package/lib/host/groups/remote.js +177 -0
  162. package/lib/host/groups/remote.js.map +1 -0
  163. package/lib/host/groups/root-guard.d.ts +26 -0
  164. package/lib/host/groups/root-guard.js +59 -0
  165. package/lib/host/groups/root-guard.js.map +1 -0
  166. package/lib/host/groups/roots.d.ts +25 -0
  167. package/lib/host/groups/roots.js +225 -0
  168. package/lib/host/groups/roots.js.map +1 -0
  169. package/lib/host/groups/round-robin.d.ts +2 -0
  170. package/lib/host/groups/round-robin.js +7 -0
  171. package/lib/host/groups/round-robin.js.map +1 -0
  172. package/lib/host/groups/routing.d.ts +35 -0
  173. package/lib/host/groups/routing.js +92 -0
  174. package/lib/host/groups/routing.js.map +1 -0
  175. package/lib/host/groups/service.d.ts +1704 -0
  176. package/lib/host/groups/service.js +324 -0
  177. package/lib/host/groups/service.js.map +1 -0
  178. package/lib/host/groups/state.d.ts +975 -0
  179. package/lib/host/groups/state.js +229 -0
  180. package/lib/host/groups/state.js.map +1 -0
  181. package/lib/host/groups/supergroup-admission.d.ts +87 -0
  182. package/lib/host/groups/supergroup-admission.js +99 -0
  183. package/lib/host/groups/supergroup-admission.js.map +1 -0
  184. package/lib/host/groups/team-recipes.d.ts +113 -0
  185. package/lib/host/groups/team-recipes.js +92 -0
  186. package/lib/host/groups/team-recipes.js.map +1 -0
  187. package/lib/host/groups/turn-runner.d.ts +184 -0
  188. package/lib/host/groups/turn-runner.js +613 -0
  189. package/lib/host/groups/turn-runner.js.map +1 -0
  190. package/lib/host/groups/turns.d.ts +740 -0
  191. package/lib/host/groups/turns.js +513 -0
  192. package/lib/host/groups/turns.js.map +1 -0
  193. package/lib/host/groups/worker-tool.d.ts +50 -0
  194. package/lib/host/groups/worker-tool.js +157 -0
  195. package/lib/host/groups/worker-tool.js.map +1 -0
  196. package/lib/host/home.d.ts +27 -0
  197. package/lib/host/home.js +221 -0
  198. package/lib/host/home.js.map +1 -0
  199. package/lib/host/im/service.d.ts +4 -0
  200. package/lib/host/im/service.js +20 -0
  201. package/lib/host/im/service.js.map +1 -0
  202. package/lib/host/index.d.ts +10 -0
  203. package/lib/host/index.js +298 -0
  204. package/lib/host/index.js.map +1 -0
  205. package/lib/host/live-persona.d.ts +9 -0
  206. package/lib/host/live-persona.js +102 -0
  207. package/lib/host/live-persona.js.map +1 -0
  208. package/lib/host/main-session.d.ts +45 -0
  209. package/lib/host/main-session.js +249 -0
  210. package/lib/host/main-session.js.map +1 -0
  211. package/lib/host/memory/admission.d.ts +46 -0
  212. package/lib/host/memory/admission.js +269 -0
  213. package/lib/host/memory/admission.js.map +1 -0
  214. package/lib/host/memory/auto-share.d.ts +36 -0
  215. package/lib/host/memory/auto-share.js +38 -0
  216. package/lib/host/memory/auto-share.js.map +1 -0
  217. package/lib/host/memory/confirmation.d.ts +145 -0
  218. package/lib/host/memory/confirmation.js +88 -0
  219. package/lib/host/memory/confirmation.js.map +1 -0
  220. package/lib/host/memory/conflicts.d.ts +16 -0
  221. package/lib/host/memory/conflicts.js +87 -0
  222. package/lib/host/memory/conflicts.js.map +1 -0
  223. package/lib/host/memory/context.d.ts +16 -0
  224. package/lib/host/memory/context.js +96 -0
  225. package/lib/host/memory/context.js.map +1 -0
  226. package/lib/host/memory/domain-v2.d.ts +338 -0
  227. package/lib/host/memory/domain-v2.js +21 -0
  228. package/lib/host/memory/domain-v2.js.map +1 -0
  229. package/lib/host/memory/facade.d.ts +159 -0
  230. package/lib/host/memory/facade.js +281 -0
  231. package/lib/host/memory/facade.js.map +1 -0
  232. package/lib/host/memory/forget-preview.d.ts +27 -0
  233. package/lib/host/memory/forget-preview.js +100 -0
  234. package/lib/host/memory/forget-preview.js.map +1 -0
  235. package/lib/host/memory/forget-runner.d.ts +31 -0
  236. package/lib/host/memory/forget-runner.js +167 -0
  237. package/lib/host/memory/forget-runner.js.map +1 -0
  238. package/lib/host/memory/forget-service.d.ts +65 -0
  239. package/lib/host/memory/forget-service.js +169 -0
  240. package/lib/host/memory/forget-service.js.map +1 -0
  241. package/lib/host/memory/history-proof.d.ts +5 -0
  242. package/lib/host/memory/history-proof.js +37 -0
  243. package/lib/host/memory/history-proof.js.map +1 -0
  244. package/lib/host/memory/history.d.ts +31 -0
  245. package/lib/host/memory/history.js +45 -0
  246. package/lib/host/memory/history.js.map +1 -0
  247. package/lib/host/memory/layout-upgrade.d.ts +8 -0
  248. package/lib/host/memory/layout-upgrade.js +51 -0
  249. package/lib/host/memory/layout-upgrade.js.map +1 -0
  250. package/lib/host/memory/migration.d.ts +23 -0
  251. package/lib/host/memory/migration.js +105 -0
  252. package/lib/host/memory/migration.js.map +1 -0
  253. package/lib/host/memory/op-log.d.ts +44 -0
  254. package/lib/host/memory/op-log.js +155 -0
  255. package/lib/host/memory/op-log.js.map +1 -0
  256. package/lib/host/memory/open-v2.d.ts +7 -0
  257. package/lib/host/memory/open-v2.js +30 -0
  258. package/lib/host/memory/open-v2.js.map +1 -0
  259. package/lib/host/memory/owner-lease.d.ts +9 -0
  260. package/lib/host/memory/owner-lease.js +105 -0
  261. package/lib/host/memory/owner-lease.js.map +1 -0
  262. package/lib/host/memory/persistent-map.d.ts +40 -0
  263. package/lib/host/memory/persistent-map.js +88 -0
  264. package/lib/host/memory/persistent-map.js.map +1 -0
  265. package/lib/host/memory/port.d.ts +10 -0
  266. package/lib/host/memory/port.js +3 -0
  267. package/lib/host/memory/port.js.map +1 -0
  268. package/lib/host/memory/preserve-inbox.d.ts +7 -0
  269. package/lib/host/memory/preserve-inbox.js +45 -0
  270. package/lib/host/memory/preserve-inbox.js.map +1 -0
  271. package/lib/host/memory/projection.d.ts +22 -0
  272. package/lib/host/memory/projection.js +89 -0
  273. package/lib/host/memory/projection.js.map +1 -0
  274. package/lib/host/memory/prompt.d.ts +3 -0
  275. package/lib/host/memory/prompt.js +56 -0
  276. package/lib/host/memory/prompt.js.map +1 -0
  277. package/lib/host/memory/query.d.ts +5 -0
  278. package/lib/host/memory/query.js +8 -0
  279. package/lib/host/memory/query.js.map +1 -0
  280. package/lib/host/memory/quota-replay.d.ts +4 -0
  281. package/lib/host/memory/quota-replay.js +22 -0
  282. package/lib/host/memory/quota-replay.js.map +1 -0
  283. package/lib/host/memory/quota.d.ts +152 -0
  284. package/lib/host/memory/quota.js +101 -0
  285. package/lib/host/memory/quota.js.map +1 -0
  286. package/lib/host/memory/remote.d.ts +288 -0
  287. package/lib/host/memory/remote.js +202 -0
  288. package/lib/host/memory/remote.js.map +1 -0
  289. package/lib/host/memory/retrieval-aliases.json +55 -0
  290. package/lib/host/memory/retrieval-config.d.ts +15 -0
  291. package/lib/host/memory/retrieval-config.js +17 -0
  292. package/lib/host/memory/retrieval-config.js.map +1 -0
  293. package/lib/host/memory/retrieval-rank.d.ts +16 -0
  294. package/lib/host/memory/retrieval-rank.js +88 -0
  295. package/lib/host/memory/retrieval-rank.js.map +1 -0
  296. package/lib/host/memory/retrieval-text.d.ts +3 -0
  297. package/lib/host/memory/retrieval-text.js +34 -0
  298. package/lib/host/memory/retrieval-text.js.map +1 -0
  299. package/lib/host/memory/root-instructions.d.ts +4 -0
  300. package/lib/host/memory/root-instructions.js +21 -0
  301. package/lib/host/memory/root-instructions.js.map +1 -0
  302. package/lib/host/memory/secrets.d.ts +6 -0
  303. package/lib/host/memory/secrets.js +12 -0
  304. package/lib/host/memory/secrets.js.map +1 -0
  305. package/lib/host/memory/service.d.ts +59 -0
  306. package/lib/host/memory/service.js +148 -0
  307. package/lib/host/memory/service.js.map +1 -0
  308. package/lib/host/memory/shards.d.ts +4 -0
  309. package/lib/host/memory/shards.js +12 -0
  310. package/lib/host/memory/shards.js.map +1 -0
  311. package/lib/host/memory/store-v2.d.ts +37 -0
  312. package/lib/host/memory/store-v2.js +156 -0
  313. package/lib/host/memory/store-v2.js.map +1 -0
  314. package/lib/host/memory/temporal.d.ts +18 -0
  315. package/lib/host/memory/temporal.js +53 -0
  316. package/lib/host/memory/temporal.js.map +1 -0
  317. package/lib/host/memory/tool-guidance.d.ts +3 -0
  318. package/lib/host/memory/tool-guidance.js +11 -0
  319. package/lib/host/memory/tool-guidance.js.map +1 -0
  320. package/lib/host/memory/tools.d.ts +6 -0
  321. package/lib/host/memory/tools.js +121 -0
  322. package/lib/host/memory/tools.js.map +1 -0
  323. package/lib/host/memory/trusted-ingress.d.ts +14 -0
  324. package/lib/host/memory/trusted-ingress.js +13 -0
  325. package/lib/host/memory/trusted-ingress.js.map +1 -0
  326. package/lib/host/memory/version.d.ts +135 -0
  327. package/lib/host/memory/version.js +17 -0
  328. package/lib/host/memory/version.js.map +1 -0
  329. package/lib/host/messaging/config.d.ts +55 -0
  330. package/lib/host/messaging/config.js +44 -0
  331. package/lib/host/messaging/config.js.map +1 -0
  332. package/lib/host/messaging/core.d.ts +287 -0
  333. package/lib/host/messaging/core.js +110 -0
  334. package/lib/host/messaging/core.js.map +1 -0
  335. package/lib/host/messaging/delivery.d.ts +6 -0
  336. package/lib/host/messaging/delivery.js +239 -0
  337. package/lib/host/messaging/delivery.js.map +1 -0
  338. package/lib/host/messaging/evidence.d.ts +15 -0
  339. package/lib/host/messaging/evidence.js +63 -0
  340. package/lib/host/messaging/evidence.js.map +1 -0
  341. package/lib/host/messaging/interrupt.d.ts +3 -0
  342. package/lib/host/messaging/interrupt.js +15 -0
  343. package/lib/host/messaging/interrupt.js.map +1 -0
  344. package/lib/host/messaging/recovery.d.ts +19 -0
  345. package/lib/host/messaging/recovery.js +114 -0
  346. package/lib/host/messaging/recovery.js.map +1 -0
  347. package/lib/host/messaging/remote.d.ts +92 -0
  348. package/lib/host/messaging/remote.js +119 -0
  349. package/lib/host/messaging/remote.js.map +1 -0
  350. package/lib/host/messaging/reply-routing.d.ts +6 -0
  351. package/lib/host/messaging/reply-routing.js +203 -0
  352. package/lib/host/messaging/reply-routing.js.map +1 -0
  353. package/lib/host/messaging/safety.d.ts +29 -0
  354. package/lib/host/messaging/safety.js +83 -0
  355. package/lib/host/messaging/safety.js.map +1 -0
  356. package/lib/host/messaging/scoped-projection.d.ts +43 -0
  357. package/lib/host/messaging/scoped-projection.js +136 -0
  358. package/lib/host/messaging/scoped-projection.js.map +1 -0
  359. package/lib/host/messaging/service.d.ts +25 -0
  360. package/lib/host/messaging/service.js +66 -0
  361. package/lib/host/messaging/service.js.map +1 -0
  362. package/lib/host/messaging/store.d.ts +764 -0
  363. package/lib/host/messaging/store.js +311 -0
  364. package/lib/host/messaging/store.js.map +1 -0
  365. package/lib/host/messaging/tool.d.ts +3 -0
  366. package/lib/host/messaging/tool.js +119 -0
  367. package/lib/host/messaging/tool.js.map +1 -0
  368. package/lib/host/messaging/wake.d.ts +5 -0
  369. package/lib/host/messaging/wake.js +14 -0
  370. package/lib/host/messaging/wake.js.map +1 -0
  371. package/lib/host/native-schedule/outcomes.d.ts +30 -0
  372. package/lib/host/native-schedule/outcomes.js +31 -0
  373. package/lib/host/native-schedule/outcomes.js.map +1 -0
  374. package/lib/host/native-schedule/service.d.ts +47 -0
  375. package/lib/host/native-schedule/service.js +164 -0
  376. package/lib/host/native-schedule/service.js.map +1 -0
  377. package/lib/host/notifications/data-flow.d.ts +6 -0
  378. package/lib/host/notifications/data-flow.js +56 -0
  379. package/lib/host/notifications/data-flow.js.map +1 -0
  380. package/lib/host/notifications/remote.d.ts +111 -0
  381. package/lib/host/notifications/remote.js +78 -0
  382. package/lib/host/notifications/remote.js.map +1 -0
  383. package/lib/host/notifications/service.d.ts +443 -0
  384. package/lib/host/notifications/service.js +466 -0
  385. package/lib/host/notifications/service.js.map +1 -0
  386. package/lib/host/notifications/time.d.ts +6 -0
  387. package/lib/host/notifications/time.js +21 -0
  388. package/lib/host/notifications/time.js.map +1 -0
  389. package/lib/host/notifications/tool.d.ts +4 -0
  390. package/lib/host/notifications/tool.js +97 -0
  391. package/lib/host/notifications/tool.js.map +1 -0
  392. package/lib/host/onboarding/coordinator.d.ts +87 -0
  393. package/lib/host/onboarding/coordinator.js +332 -0
  394. package/lib/host/onboarding/coordinator.js.map +1 -0
  395. package/lib/host/onboarding/guard.d.ts +5 -0
  396. package/lib/host/onboarding/guard.js +71 -0
  397. package/lib/host/onboarding/guard.js.map +1 -0
  398. package/lib/host/proactive/auto-admission.d.ts +17 -0
  399. package/lib/host/proactive/auto-admission.js +51 -0
  400. package/lib/host/proactive/auto-admission.js.map +1 -0
  401. package/lib/host/proactive/config.d.ts +192 -0
  402. package/lib/host/proactive/config.js +78 -0
  403. package/lib/host/proactive/config.js.map +1 -0
  404. package/lib/host/proactive/coordinator-client.d.ts +17 -0
  405. package/lib/host/proactive/coordinator-client.js +143 -0
  406. package/lib/host/proactive/coordinator-client.js.map +1 -0
  407. package/lib/host/proactive/deferred-notices.d.ts +21 -0
  408. package/lib/host/proactive/deferred-notices.js +147 -0
  409. package/lib/host/proactive/deferred-notices.js.map +1 -0
  410. package/lib/host/proactive/execution-prompt.d.ts +4 -0
  411. package/lib/host/proactive/execution-prompt.js +23 -0
  412. package/lib/host/proactive/execution-prompt.js.map +1 -0
  413. package/lib/host/proactive/execution.d.ts +36 -0
  414. package/lib/host/proactive/execution.js +607 -0
  415. package/lib/host/proactive/execution.js.map +1 -0
  416. package/lib/host/proactive/executors/command.d.ts +49 -0
  417. package/lib/host/proactive/executors/command.js +117 -0
  418. package/lib/host/proactive/executors/command.js.map +1 -0
  419. package/lib/host/proactive/executors/json-command-bridge-entry.d.ts +1 -0
  420. package/lib/host/proactive/executors/json-command-bridge-entry.js +29 -0
  421. package/lib/host/proactive/executors/json-command-bridge-entry.js.map +1 -0
  422. package/lib/host/proactive/executors/json-command-bridge.d.ts +46 -0
  423. package/lib/host/proactive/executors/json-command-bridge.js +135 -0
  424. package/lib/host/proactive/executors/json-command-bridge.js.map +1 -0
  425. package/lib/host/proactive/executors/loopback.d.ts +23 -0
  426. package/lib/host/proactive/executors/loopback.js +136 -0
  427. package/lib/host/proactive/executors/loopback.js.map +1 -0
  428. package/lib/host/proactive/feedback-workflow.d.ts +1336 -0
  429. package/lib/host/proactive/feedback-workflow.js +194 -0
  430. package/lib/host/proactive/feedback-workflow.js.map +1 -0
  431. package/lib/host/proactive/feedback.d.ts +25 -0
  432. package/lib/host/proactive/feedback.js +107 -0
  433. package/lib/host/proactive/feedback.js.map +1 -0
  434. package/lib/host/proactive/follow-up-events.d.ts +47 -0
  435. package/lib/host/proactive/follow-up-events.js +387 -0
  436. package/lib/host/proactive/follow-up-events.js.map +1 -0
  437. package/lib/host/proactive/follow-up-facts.d.ts +5 -0
  438. package/lib/host/proactive/follow-up-facts.js +34 -0
  439. package/lib/host/proactive/follow-up-facts.js.map +1 -0
  440. package/lib/host/proactive/follow-up-tool.d.ts +4 -0
  441. package/lib/host/proactive/follow-up-tool.js +195 -0
  442. package/lib/host/proactive/follow-up-tool.js.map +1 -0
  443. package/lib/host/proactive/governance-artifacts.d.ts +8 -0
  444. package/lib/host/proactive/governance-artifacts.js +182 -0
  445. package/lib/host/proactive/governance-artifacts.js.map +1 -0
  446. package/lib/host/proactive/governance-service.d.ts +39 -0
  447. package/lib/host/proactive/governance-service.js +146 -0
  448. package/lib/host/proactive/governance-service.js.map +1 -0
  449. package/lib/host/proactive/group-budget.d.ts +25 -0
  450. package/lib/host/proactive/group-budget.js +145 -0
  451. package/lib/host/proactive/group-budget.js.map +1 -0
  452. package/lib/host/proactive/group-follow-up.d.ts +10 -0
  453. package/lib/host/proactive/group-follow-up.js +95 -0
  454. package/lib/host/proactive/group-follow-up.js.map +1 -0
  455. package/lib/host/proactive/group-repair.d.ts +93 -0
  456. package/lib/host/proactive/group-repair.js +283 -0
  457. package/lib/host/proactive/group-repair.js.map +1 -0
  458. package/lib/host/proactive/index.d.ts +10 -0
  459. package/lib/host/proactive/index.js +26 -0
  460. package/lib/host/proactive/index.js.map +1 -0
  461. package/lib/host/proactive/lifecycle.d.ts +24 -0
  462. package/lib/host/proactive/lifecycle.js +187 -0
  463. package/lib/host/proactive/lifecycle.js.map +1 -0
  464. package/lib/host/proactive/method-evaluation.d.ts +5 -0
  465. package/lib/host/proactive/method-evaluation.js +41 -0
  466. package/lib/host/proactive/method-evaluation.js.map +1 -0
  467. package/lib/host/proactive/method-package.d.ts +33 -0
  468. package/lib/host/proactive/method-package.js +25 -0
  469. package/lib/host/proactive/method-package.js.map +1 -0
  470. package/lib/host/proactive/method-skill.d.ts +7 -0
  471. package/lib/host/proactive/method-skill.js +20 -0
  472. package/lib/host/proactive/method-skill.js.map +1 -0
  473. package/lib/host/proactive/model-budget.d.ts +10 -0
  474. package/lib/host/proactive/model-budget.js +48 -0
  475. package/lib/host/proactive/model-budget.js.map +1 -0
  476. package/lib/host/proactive/notice-pump.d.ts +16 -0
  477. package/lib/host/proactive/notice-pump.js +174 -0
  478. package/lib/host/proactive/notice-pump.js.map +1 -0
  479. package/lib/host/proactive/notification-bridge.d.ts +3 -0
  480. package/lib/host/proactive/notification-bridge.js +26 -0
  481. package/lib/host/proactive/notification-bridge.js.map +1 -0
  482. package/lib/host/proactive/read-query.d.ts +4 -0
  483. package/lib/host/proactive/read-query.js +53 -0
  484. package/lib/host/proactive/read-query.js.map +1 -0
  485. package/lib/host/proactive/remote.d.ts +5076 -0
  486. package/lib/host/proactive/remote.js +351 -0
  487. package/lib/host/proactive/remote.js.map +1 -0
  488. package/lib/host/proactive/repair.d.ts +48 -0
  489. package/lib/host/proactive/repair.js +205 -0
  490. package/lib/host/proactive/repair.js.map +1 -0
  491. package/lib/host/proactive/result-journal.d.ts +215 -0
  492. package/lib/host/proactive/result-journal.js +132 -0
  493. package/lib/host/proactive/result-journal.js.map +1 -0
  494. package/lib/host/proactive/service.d.ts +32106 -0
  495. package/lib/host/proactive/service.js +1632 -0
  496. package/lib/host/proactive/service.js.map +1 -0
  497. package/lib/host/proactive/setup.d.ts +13 -0
  498. package/lib/host/proactive/setup.js +94 -0
  499. package/lib/host/proactive/setup.js.map +1 -0
  500. package/lib/host/proactive/sources/ci-feed.d.ts +21 -0
  501. package/lib/host/proactive/sources/ci-feed.js +86 -0
  502. package/lib/host/proactive/sources/ci-feed.js.map +1 -0
  503. package/lib/host/proactive/sources/ci.d.ts +35 -0
  504. package/lib/host/proactive/sources/ci.js +72 -0
  505. package/lib/host/proactive/sources/ci.js.map +1 -0
  506. package/lib/host/proactive/sources/github-ci.d.ts +16 -0
  507. package/lib/host/proactive/sources/github-ci.js +117 -0
  508. package/lib/host/proactive/sources/github-ci.js.map +1 -0
  509. package/lib/host/proactive/task-cost.d.ts +10 -0
  510. package/lib/host/proactive/task-cost.js +70 -0
  511. package/lib/host/proactive/task-cost.js.map +1 -0
  512. package/lib/host/proactive/wire.d.ts +5 -0
  513. package/lib/host/proactive/wire.js +48 -0
  514. package/lib/host/proactive/wire.js.map +1 -0
  515. package/lib/host/proactive/work-continuation.d.ts +21 -0
  516. package/lib/host/proactive/work-continuation.js +66 -0
  517. package/lib/host/proactive/work-continuation.js.map +1 -0
  518. package/lib/host/proactive/workspace-process.d.ts +25 -0
  519. package/lib/host/proactive/workspace-process.js +80 -0
  520. package/lib/host/proactive/workspace-process.js.map +1 -0
  521. package/lib/host/proactive/workspace-repair.d.ts +425 -0
  522. package/lib/host/proactive/workspace-repair.js +352 -0
  523. package/lib/host/proactive/workspace-repair.js.map +1 -0
  524. package/lib/host/reference-memory/backend.d.ts +13 -0
  525. package/lib/host/reference-memory/backend.js +134 -0
  526. package/lib/host/reference-memory/backend.js.map +1 -0
  527. package/lib/host/reference-memory/cleanup-files.d.ts +7 -0
  528. package/lib/host/reference-memory/cleanup-files.js +36 -0
  529. package/lib/host/reference-memory/cleanup-files.js.map +1 -0
  530. package/lib/host/reference-memory/copies.d.ts +87 -0
  531. package/lib/host/reference-memory/copies.js +218 -0
  532. package/lib/host/reference-memory/copies.js.map +1 -0
  533. package/lib/host/reference-memory/files.d.ts +4 -0
  534. package/lib/host/reference-memory/files.js +43 -0
  535. package/lib/host/reference-memory/files.js.map +1 -0
  536. package/lib/host/reference-memory/model.d.ts +195 -0
  537. package/lib/host/reference-memory/model.js +66 -0
  538. package/lib/host/reference-memory/model.js.map +1 -0
  539. package/lib/host/reference-memory/service.d.ts +157 -0
  540. package/lib/host/reference-memory/service.js +124 -0
  541. package/lib/host/reference-memory/service.js.map +1 -0
  542. package/lib/host/reference-memory/writer.d.ts +55 -0
  543. package/lib/host/reference-memory/writer.js +265 -0
  544. package/lib/host/reference-memory/writer.js.map +1 -0
  545. package/lib/host/registry/identity.d.ts +3 -0
  546. package/lib/host/registry/identity.js +9 -0
  547. package/lib/host/registry/identity.js.map +1 -0
  548. package/lib/host/registry/lifecycle.d.ts +119 -0
  549. package/lib/host/registry/lifecycle.js +226 -0
  550. package/lib/host/registry/lifecycle.js.map +1 -0
  551. package/lib/host/registry/mutations.d.ts +7 -0
  552. package/lib/host/registry/mutations.js +25 -0
  553. package/lib/host/registry/mutations.js.map +1 -0
  554. package/lib/host/registry/presets.d.ts +13 -0
  555. package/lib/host/registry/presets.js +169 -0
  556. package/lib/host/registry/presets.js.map +1 -0
  557. package/lib/host/registry/types.d.ts +11 -0
  558. package/lib/host/registry/types.js +3 -0
  559. package/lib/host/registry/types.js.map +1 -0
  560. package/lib/host/registry-config.d.ts +69 -0
  561. package/lib/host/registry-config.js +125 -0
  562. package/lib/host/registry-config.js.map +1 -0
  563. package/lib/host/registry.d.ts +145 -0
  564. package/lib/host/registry.js +490 -0
  565. package/lib/host/registry.js.map +1 -0
  566. package/lib/host/shadow/budget.d.ts +106 -0
  567. package/lib/host/shadow/budget.js +112 -0
  568. package/lib/host/shadow/budget.js.map +1 -0
  569. package/lib/host/shadow/config.d.ts +13 -0
  570. package/lib/host/shadow/config.js +13 -0
  571. package/lib/host/shadow/config.js.map +1 -0
  572. package/lib/host/shadow/notification-adapter.d.ts +5 -0
  573. package/lib/host/shadow/notification-adapter.js +16 -0
  574. package/lib/host/shadow/notification-adapter.js.map +1 -0
  575. package/lib/host/shadow/planner.d.ts +39 -0
  576. package/lib/host/shadow/planner.js +76 -0
  577. package/lib/host/shadow/planner.js.map +1 -0
  578. package/lib/host/shadow/schedule-adapter.d.ts +23 -0
  579. package/lib/host/shadow/schedule-adapter.js +15 -0
  580. package/lib/host/shadow/schedule-adapter.js.map +1 -0
  581. package/lib/host/shadow/service.d.ts +23 -0
  582. package/lib/host/shadow/service.js +25 -0
  583. package/lib/host/shadow/service.js.map +1 -0
  584. package/lib/host/store.d.ts +25 -0
  585. package/lib/host/store.js +74 -0
  586. package/lib/host/store.js.map +1 -0
  587. package/lib/host/stores/activity.d.ts +35 -0
  588. package/lib/host/stores/activity.js +188 -0
  589. package/lib/host/stores/activity.js.map +1 -0
  590. package/lib/host/stores/bots.d.ts +21 -0
  591. package/lib/host/stores/bots.js +128 -0
  592. package/lib/host/stores/bots.js.map +1 -0
  593. package/lib/host/stores/domain.d.ts +343 -0
  594. package/lib/host/stores/domain.js +98 -0
  595. package/lib/host/stores/domain.js.map +1 -0
  596. package/lib/host/stores/memory.d.ts +29 -0
  597. package/lib/host/stores/memory.js +139 -0
  598. package/lib/host/stores/memory.js.map +1 -0
  599. package/lib/host/supergroup/collaboration.d.ts +99 -0
  600. package/lib/host/supergroup/collaboration.js +361 -0
  601. package/lib/host/supergroup/collaboration.js.map +1 -0
  602. package/lib/host/supergroup/config.d.ts +15 -0
  603. package/lib/host/supergroup/config.js +33 -0
  604. package/lib/host/supergroup/config.js.map +1 -0
  605. package/lib/host/supergroup/input-capability.d.ts +4 -0
  606. package/lib/host/supergroup/input-capability.js +21 -0
  607. package/lib/host/supergroup/input-capability.js.map +1 -0
  608. package/lib/host/supergroup/remote.d.ts +1944 -0
  609. package/lib/host/supergroup/remote.js +123 -0
  610. package/lib/host/supergroup/remote.js.map +1 -0
  611. package/lib/host/supergroup/service.d.ts +935 -0
  612. package/lib/host/supergroup/service.js +921 -0
  613. package/lib/host/supergroup/service.js.map +1 -0
  614. package/lib/host/supergroup/task-support.d.ts +245 -0
  615. package/lib/host/supergroup/task-support.js +310 -0
  616. package/lib/host/supergroup/task-support.js.map +1 -0
  617. package/lib/host/supergroup/tool.d.ts +4 -0
  618. package/lib/host/supergroup/tool.js +74 -0
  619. package/lib/host/supergroup/tool.js.map +1 -0
  620. package/lib/host/tools/bot-manage.d.ts +14 -0
  621. package/lib/host/tools/bot-manage.js +440 -0
  622. package/lib/host/tools/bot-manage.js.map +1 -0
  623. package/lib/host/workspace/remote.d.ts +194 -0
  624. package/lib/host/workspace/remote.js +98 -0
  625. package/lib/host/workspace/remote.js.map +1 -0
  626. package/lib/host/workspace/service.d.ts +185 -0
  627. package/lib/host/workspace/service.js +261 -0
  628. package/lib/host/workspace/service.js.map +1 -0
  629. package/lib/index.d.ts +10 -0
  630. package/lib/index.js +58 -0
  631. package/lib/index.js.map +1 -0
  632. package/lib/module-manifest.json +278 -0
  633. package/lib/proactive-coordinator/LICENSE +21 -0
  634. package/lib/proactive-coordinator/core.mjs +19067 -0
  635. package/lib/proactive-coordinator/main.mjs +22363 -0
  636. package/lib/proactive-coordinator/package.json +1 -0
  637. package/lib/proactive-coordinator/prompts/admission.md +68 -0
  638. package/lib/proactive-coordinator/prompts/cli.md +17 -0
  639. package/lib/proactive-coordinator/prompts/dispatch.md +59 -0
  640. package/lib/proactive-coordinator/prompts/handoff-orchestrator.md +4 -0
  641. package/lib/proactive-coordinator/prompts/handoff-worker.md +7 -0
  642. package/lib/proactive-coordinator/prompts/handoff.md +6 -0
  643. package/lib/proactive-coordinator/prompts/orchestrator.md +16 -0
  644. package/lib/proactive-coordinator/prompts/replies.md +35 -0
  645. package/lib/proactive-coordinator/prompts/shared.md +7 -0
  646. package/lib/proactive-coordinator/prompts/subscriptions.md +13 -0
  647. package/lib/proactive-coordinator/prompts/team/communication.md +97 -0
  648. package/lib/proactive-coordinator/prompts/team/delivery.md +28 -0
  649. package/lib/proactive-coordinator/prompts/team/scope.md +22 -0
  650. package/lib/proactive-coordinator/prompts/work.md +49 -0
  651. package/lib/proactive-coordinator/prompts/worker.md +10 -0
  652. package/lib/proactive-coordinator/provenance.json +7 -0
  653. package/lib/proactive-coordinator/skills/dsh-superagent-feishu/SKILL.md +12 -0
  654. package/lib/proactive-coordinator/skills/dsh-superagent-github/SKILL.md +14 -0
  655. package/lib/shared/activity-preview.d.ts +5 -0
  656. package/lib/shared/activity-preview.js +40 -0
  657. package/lib/shared/activity-preview.js.map +1 -0
  658. package/lib/shared/activity.d.ts +107 -0
  659. package/lib/shared/activity.js +50 -0
  660. package/lib/shared/activity.js.map +1 -0
  661. package/lib/shared/automation-contract.d.ts +1138 -0
  662. package/lib/shared/automation-contract.js +63 -0
  663. package/lib/shared/automation-contract.js.map +1 -0
  664. package/lib/shared/automation.d.ts +336 -0
  665. package/lib/shared/automation.js +244 -0
  666. package/lib/shared/automation.js.map +1 -0
  667. package/lib/shared/bot-brand.d.ts +20 -0
  668. package/lib/shared/bot-brand.js +26 -0
  669. package/lib/shared/bot-brand.js.map +1 -0
  670. package/lib/shared/capabilities-contract.d.ts +685 -0
  671. package/lib/shared/capabilities-contract.js +38 -0
  672. package/lib/shared/capabilities-contract.js.map +1 -0
  673. package/lib/shared/collaboration-contract.d.ts +614 -0
  674. package/lib/shared/collaboration-contract.js +52 -0
  675. package/lib/shared/collaboration-contract.js.map +1 -0
  676. package/lib/shared/collaboration.d.ts +132 -0
  677. package/lib/shared/collaboration.js +63 -0
  678. package/lib/shared/collaboration.js.map +1 -0
  679. package/lib/shared/connectors.d.ts +216 -0
  680. package/lib/shared/connectors.js +121 -0
  681. package/lib/shared/connectors.js.map +1 -0
  682. package/lib/shared/data-flow.d.ts +135 -0
  683. package/lib/shared/data-flow.js +53 -0
  684. package/lib/shared/data-flow.js.map +1 -0
  685. package/lib/shared/eval-budget.d.ts +100 -0
  686. package/lib/shared/eval-budget.js +34 -0
  687. package/lib/shared/eval-budget.js.map +1 -0
  688. package/lib/shared/group-recall-reads.d.ts +35 -0
  689. package/lib/shared/group-recall-reads.js +12 -0
  690. package/lib/shared/group-recall-reads.js.map +1 -0
  691. package/lib/shared/group-recall.d.ts +132 -0
  692. package/lib/shared/group-recall.js +52 -0
  693. package/lib/shared/group-recall.js.map +1 -0
  694. package/lib/shared/groups-contract.d.ts +5905 -0
  695. package/lib/shared/groups-contract.js +105 -0
  696. package/lib/shared/groups-contract.js.map +1 -0
  697. package/lib/shared/groups.d.ts +1127 -0
  698. package/lib/shared/groups.js +257 -0
  699. package/lib/shared/groups.js.map +1 -0
  700. package/lib/shared/identity.d.ts +14 -0
  701. package/lib/shared/identity.js +13 -0
  702. package/lib/shared/identity.js.map +1 -0
  703. package/lib/shared/ids.d.ts +5 -0
  704. package/lib/shared/ids.js +6 -0
  705. package/lib/shared/ids.js.map +1 -0
  706. package/lib/shared/integrations-contract.d.ts +1916 -0
  707. package/lib/shared/integrations-contract.js +71 -0
  708. package/lib/shared/integrations-contract.js.map +1 -0
  709. package/lib/shared/integrations.d.ts +216 -0
  710. package/lib/shared/integrations.js +20 -0
  711. package/lib/shared/integrations.js.map +1 -0
  712. package/lib/shared/managed-flow.d.ts +199 -0
  713. package/lib/shared/managed-flow.js +15 -0
  714. package/lib/shared/managed-flow.js.map +1 -0
  715. package/lib/shared/memory-forget.d.ts +122 -0
  716. package/lib/shared/memory-forget.js +32 -0
  717. package/lib/shared/memory-forget.js.map +1 -0
  718. package/lib/shared/memory-management.d.ts +1014 -0
  719. package/lib/shared/memory-management.js +48 -0
  720. package/lib/shared/memory-management.js.map +1 -0
  721. package/lib/shared/memory-ops.d.ts +274 -0
  722. package/lib/shared/memory-ops.js +35 -0
  723. package/lib/shared/memory-ops.js.map +1 -0
  724. package/lib/shared/memory-tool-names.d.ts +2 -0
  725. package/lib/shared/memory-tool-names.js +9 -0
  726. package/lib/shared/memory-tool-names.js.map +1 -0
  727. package/lib/shared/memory-v2.d.ts +268 -0
  728. package/lib/shared/memory-v2.js +51 -0
  729. package/lib/shared/memory-v2.js.map +1 -0
  730. package/lib/shared/messaging-contract.d.ts +161 -0
  731. package/lib/shared/messaging-contract.js +24 -0
  732. package/lib/shared/messaging-contract.js.map +1 -0
  733. package/lib/shared/messaging.d.ts +808 -0
  734. package/lib/shared/messaging.js +231 -0
  735. package/lib/shared/messaging.js.map +1 -0
  736. package/lib/shared/native-schedule.d.ts +35 -0
  737. package/lib/shared/native-schedule.js +25 -0
  738. package/lib/shared/native-schedule.js.map +1 -0
  739. package/lib/shared/notifications.d.ts +167 -0
  740. package/lib/shared/notifications.js +104 -0
  741. package/lib/shared/notifications.js.map +1 -0
  742. package/lib/shared/onboarding-source.d.ts +19 -0
  743. package/lib/shared/onboarding-source.js +9 -0
  744. package/lib/shared/onboarding-source.js.map +1 -0
  745. package/lib/shared/onboarding.d.ts +115 -0
  746. package/lib/shared/onboarding.js +14 -0
  747. package/lib/shared/onboarding.js.map +1 -0
  748. package/lib/shared/operation-errors.d.ts +18 -0
  749. package/lib/shared/operation-errors.js +18 -0
  750. package/lib/shared/operation-errors.js.map +1 -0
  751. package/lib/shared/proactive/activity.d.ts +152 -0
  752. package/lib/shared/proactive/activity.js +23 -0
  753. package/lib/shared/proactive/activity.js.map +1 -0
  754. package/lib/shared/proactive/document.d.ts +31 -0
  755. package/lib/shared/proactive/document.js +17 -0
  756. package/lib/shared/proactive/document.js.map +1 -0
  757. package/lib/shared/proactive/feedback.d.ts +2315 -0
  758. package/lib/shared/proactive/feedback.js +177 -0
  759. package/lib/shared/proactive/feedback.js.map +1 -0
  760. package/lib/shared/proactive/follow-up.d.ts +1241 -0
  761. package/lib/shared/proactive/follow-up.js +178 -0
  762. package/lib/shared/proactive/follow-up.js.map +1 -0
  763. package/lib/shared/proactive/governance.d.ts +147 -0
  764. package/lib/shared/proactive/governance.js +92 -0
  765. package/lib/shared/proactive/governance.js.map +1 -0
  766. package/lib/shared/proactive/group-follow-up.d.ts +228 -0
  767. package/lib/shared/proactive/group-follow-up.js +24 -0
  768. package/lib/shared/proactive/group-follow-up.js.map +1 -0
  769. package/lib/shared/proactive/group-repair.d.ts +185 -0
  770. package/lib/shared/proactive/group-repair.js +95 -0
  771. package/lib/shared/proactive/group-repair.js.map +1 -0
  772. package/lib/shared/proactive/handoff.d.ts +17 -0
  773. package/lib/shared/proactive/handoff.js +15 -0
  774. package/lib/shared/proactive/handoff.js.map +1 -0
  775. package/lib/shared/proactive/method-evaluation.d.ts +187 -0
  776. package/lib/shared/proactive/method-evaluation.js +46 -0
  777. package/lib/shared/proactive/method-evaluation.js.map +1 -0
  778. package/lib/shared/proactive/method-package.d.ts +131 -0
  779. package/lib/shared/proactive/method-package.js +28 -0
  780. package/lib/shared/proactive/method-package.js.map +1 -0
  781. package/lib/shared/proactive/notices.d.ts +126 -0
  782. package/lib/shared/proactive/notices.js +64 -0
  783. package/lib/shared/proactive/notices.js.map +1 -0
  784. package/lib/shared/proactive/outcomes.d.ts +23 -0
  785. package/lib/shared/proactive/outcomes.js +41 -0
  786. package/lib/shared/proactive/outcomes.js.map +1 -0
  787. package/lib/shared/proactive/protocol.d.ts +12730 -0
  788. package/lib/shared/proactive/protocol.js +688 -0
  789. package/lib/shared/proactive/protocol.js.map +1 -0
  790. package/lib/shared/proactive/remote-contract.d.ts +30326 -0
  791. package/lib/shared/proactive/remote-contract.js +248 -0
  792. package/lib/shared/proactive/remote-contract.js.map +1 -0
  793. package/lib/shared/proactive/repair.d.ts +65 -0
  794. package/lib/shared/proactive/repair.js +55 -0
  795. package/lib/shared/proactive/repair.js.map +1 -0
  796. package/lib/shared/proactive/responsibility.d.ts +1085 -0
  797. package/lib/shared/proactive/responsibility.js +222 -0
  798. package/lib/shared/proactive/responsibility.js.map +1 -0
  799. package/lib/shared/proactive/setup.d.ts +250 -0
  800. package/lib/shared/proactive/setup.js +26 -0
  801. package/lib/shared/proactive/setup.js.map +1 -0
  802. package/lib/shared/proactive/work-progress.d.ts +14 -0
  803. package/lib/shared/proactive/work-progress.js +22 -0
  804. package/lib/shared/proactive/work-progress.js.map +1 -0
  805. package/lib/shared/proactive/work.d.ts +2887 -0
  806. package/lib/shared/proactive/work.js +250 -0
  807. package/lib/shared/proactive/work.js.map +1 -0
  808. package/lib/shared/proactive/workspace-repair.d.ts +283 -0
  809. package/lib/shared/proactive/workspace-repair.js +195 -0
  810. package/lib/shared/proactive/workspace-repair.js.map +1 -0
  811. package/lib/shared/reference-memory.d.ts +517 -0
  812. package/lib/shared/reference-memory.js +188 -0
  813. package/lib/shared/reference-memory.js.map +1 -0
  814. package/lib/shared/remote-contract.d.ts +5109 -0
  815. package/lib/shared/remote-contract.js +213 -0
  816. package/lib/shared/remote-contract.js.map +1 -0
  817. package/lib/shared/routine-outcomes.d.ts +20 -0
  818. package/lib/shared/routine-outcomes.js +9 -0
  819. package/lib/shared/routine-outcomes.js.map +1 -0
  820. package/lib/shared/schema.d.ts +785 -0
  821. package/lib/shared/schema.js +203 -0
  822. package/lib/shared/schema.js.map +1 -0
  823. package/lib/shared/secrets.d.ts +2 -0
  824. package/lib/shared/secrets.js +15 -0
  825. package/lib/shared/secrets.js.map +1 -0
  826. package/lib/shared/shadow.d.ts +12 -0
  827. package/lib/shared/shadow.js +8 -0
  828. package/lib/shared/shadow.js.map +1 -0
  829. package/lib/shared/supergroup-contract.d.ts +7119 -0
  830. package/lib/shared/supergroup-contract.js +26 -0
  831. package/lib/shared/supergroup-contract.js.map +1 -0
  832. package/lib/shared/supergroup.d.ts +1441 -0
  833. package/lib/shared/supergroup.js +56 -0
  834. package/lib/shared/supergroup.js.map +1 -0
  835. package/lib/shared/task-materials.d.ts +166 -0
  836. package/lib/shared/task-materials.js +40 -0
  837. package/lib/shared/task-materials.js.map +1 -0
  838. package/lib/shared/team-recipes.d.ts +109 -0
  839. package/lib/shared/team-recipes.js +25 -0
  840. package/lib/shared/team-recipes.js.map +1 -0
  841. package/lib/shared/version.d.ts +1 -0
  842. package/lib/shared/version.js +3 -0
  843. package/lib/shared/version.js.map +1 -0
  844. package/lib/shared/workspace-contract.d.ts +2284 -0
  845. package/lib/shared/workspace-contract.js +37 -0
  846. package/lib/shared/workspace-contract.js.map +1 -0
  847. package/lib/shared/workspace.d.ts +496 -0
  848. package/lib/shared/workspace.js +120 -0
  849. package/lib/shared/workspace.js.map +1 -0
  850. package/lib/typert.host.d.ts +12 -0
  851. package/lib/typert.host.js +13 -0
  852. package/lib/typert.host.js.map +1 -0
  853. package/lib/typert.remote-client.d.ts +4 -0
  854. package/lib/typert.remote-client.js +9 -0
  855. package/lib/typert.remote-client.js.map +1 -0
  856. package/locale/en.json +1876 -0
  857. package/locale/zh.json +1876 -0
  858. package/package.json +177 -3
@@ -0,0 +1,1632 @@
1
+ import { withProactiveBinding } from "./setup.js";
2
+ import { reconcilePendingWorkContinuation, runWorkContinuation } from './work-continuation.js';
3
+ import { prepareGroupFollowUp, acceptGroupFollowUp, abandonGroupFollowUp } from './group-follow-up.js';
4
+ import { SessionId } from "@deepseek-ai/dsh-session";
5
+ import { judgeMethodAnswer } from "./method-evaluation.js";
6
+ import { documentRequestSchema } from "../../shared/proactive/document.js";
7
+ import { taskCost } from './task-cost.js';
8
+ import { credentialRef } from '@deepseek-ai/dsh-credentials';
9
+ import { groupMemberModel } from '../groups/model-selection.js';
10
+ import { taskHandoff } from '../../shared/proactive/handoff.js';
11
+ import { GroupBudgetAccounting } from "./group-budget.js";
12
+ import { verifyGroupRepairEvidence } from "./group-repair.js";
13
+ import { ProactiveGovernance } from "./governance-service.js";
14
+ import { FeedbackWorkflow } from "./feedback-workflow.js";
15
+ import { readRepairReview, formatRepairReview } from "./repair.js";
16
+ import { formatWorkspaceReview } from "./workspace-repair.js";
17
+ import { GROUP_TEXT_MAX_BYTES } from "../../shared/groups.js";
18
+ import { DeferredNoticePump } from "./notice-pump.js";
19
+ import { openResultJournal, } from "./result-journal.js";
20
+ import { hasResponsibilityRoute, } from "../../shared/proactive/responsibility.js";
21
+ import { createWorkspaceRepairOffer, workspaceSpecification, readWorkspaceReview, } from "./workspace-repair.js";
22
+ import { workspaceExecutionAvailable, workspaceExecutionUnavailable, } from "./workspace-process.js";
23
+ import { randomUUID } from "node:crypto";
24
+ import { realpath } from "node:fs/promises";
25
+ import { join } from "node:path";
26
+ import { setTimeout as delay } from "node:timers/promises";
27
+ import { sameBot } from "../../shared/identity.js";
28
+ import { Serial } from "../common/operations.js";
29
+ import { AutomaticAdmissionQueue } from "./auto-admission.js";
30
+ import { verifySavedArtifact } from "./repair.js";
31
+ import { DirectExecution } from "./execution.js";
32
+ import { capabilities, commandBodySchema, } from "../../shared/proactive/protocol.js";
33
+ import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
34
+ import { pollCiFeed } from "./sources/ci-feed.js";
35
+ import { CoordinatorClient } from "./coordinator-client.js";
36
+ import { digest } from "./wire.js";
37
+ import { ciSourceId, observeCiPage, } from "./sources/ci.js";
38
+ const unavailable = { ...capabilities, ingest: false, snapshot: false };
39
+ export class ProactiveService {
40
+ ctx;
41
+ config;
42
+ #client;
43
+ #scopeOnly = false;
44
+ #retired = false;
45
+ #noticesClosing;
46
+ #resultJournal;
47
+ #storeId;
48
+ #feedStop = new AbortController();
49
+ #feed;
50
+ #feedStatus;
51
+ #feedLastSuccessAt;
52
+ #groupFollowUpQueue = new Serial();
53
+ #maintenance;
54
+ #recoveries = 0;
55
+ #automatic = new AutomaticAdmissionQueue({
56
+ candidates: async () => {
57
+ if (!this.directRoute ||
58
+ this.#state !== "ready" ||
59
+ !this.#client?.available ||
60
+ !this.#storeId)
61
+ return [];
62
+ const response = await this.read({ kind: "auto-candidates" });
63
+ const candidates = response.kind === "auto-candidates"
64
+ ? response.rows.map(({ suggestion, responsibility }) => ({
65
+ row: suggestion,
66
+ policy: responsibility,
67
+ }))
68
+ : [];
69
+ const rule = this.config.proactiveAutoCiRule;
70
+ if (rule &&
71
+ Date.parse(rule.expiresAt) > Date.now() &&
72
+ !(await this.responsibilities(rule.target.bot)).some((row) => row.responsibility.id ===
73
+ `legacy-${digest([rule.id, rule.target.bot]).slice(0, 32)}`)) {
74
+ const source = await this.read({
75
+ kind: "checkpoint",
76
+ sourceId: rule.sourceId,
77
+ });
78
+ if (source.kind === "checkpoint" &&
79
+ !source.source?.revoked &&
80
+ source.source?.generation === rule.sourceGeneration)
81
+ candidates.push(...(await this.suggestions(rule.target.bot))
82
+ .filter((row) => row.sourceId === rule.sourceId &&
83
+ row.state === "open" &&
84
+ !row.adjusted)
85
+ .map((row) => ({ row, rule })));
86
+ }
87
+ return candidates.sort((a, b) => a.row.observedAt.localeCompare(b.row.observedAt) ||
88
+ a.row.id.localeCompare(b.row.id));
89
+ },
90
+ admit: async ({ row, rule, policy }) => {
91
+ const target = policy?.target ?? rule?.target, ruleId = policy?.id ?? rule?.id;
92
+ if (!target || !hasResponsibilityRoute(target) || !ruleId)
93
+ return "skip";
94
+ let repair, workspaceRepair;
95
+ try {
96
+ await this.validateTarget(target);
97
+ if (policy && policy.action !== "inspect-ci-result") {
98
+ if (policy.action === "repair-workspace") {
99
+ const offer = (await this.workspaceOffers()).find((o) => o.sourceId === row.sourceId &&
100
+ o.specDigest === policy.actionScopeDigest);
101
+ if (!offer || offer.executor === "command")
102
+ return "skip";
103
+ workspaceRepair = {
104
+ workspaceId: offer.workspaceId,
105
+ specDigest: offer.specDigest,
106
+ baselineDigest: offer.baselineDigest,
107
+ executor: offer.executor,
108
+ };
109
+ }
110
+ else {
111
+ const offer = this.repairOffers().find((o) => o.sourceId === row.sourceId &&
112
+ o.specDigest === policy.actionScopeDigest &&
113
+ o.executor ===
114
+ (policy.action === "repair-external" ? "external" : "native"));
115
+ if (!offer)
116
+ return "skip";
117
+ repair = {
118
+ fixtureId: offer.fixtureId,
119
+ specDigest: offer.specDigest,
120
+ executor: offer.executor,
121
+ };
122
+ }
123
+ }
124
+ }
125
+ catch {
126
+ return "skip";
127
+ }
128
+ const reply = await this.change(randomUUID(), {
129
+ kind: "auto-accept",
130
+ ruleId,
131
+ target,
132
+ decisionId: row.id,
133
+ sourceId: row.sourceId,
134
+ policyVersion: row.policyVersion,
135
+ expectedRevision: row.revision,
136
+ ...(policy
137
+ ? { responsibility: { id: policy.id, revision: policy.revision } }
138
+ : {}),
139
+ ...(repair ? { repair } : {}),
140
+ ...(workspaceRepair ? { workspaceRepair } : {}),
141
+ });
142
+ if (reply.kind === "receipt")
143
+ return "accepted";
144
+ if (reply.kind === "unknown")
145
+ return "unknown";
146
+ return reply.code === "conflict" ? "busy" : "skip";
147
+ },
148
+ dispatch: async ({ row }) => this.dispatch(row.id),
149
+ onError: () => this.ctx.logger.warn("[dsh-bot] proactive automatic admission paused until the next wake-up"),
150
+ });
151
+ #state;
152
+ execution;
153
+ feedbackWorkflow;
154
+ deferredNotices;
155
+ governance;
156
+ groupBudgets;
157
+ constructor(ctx, config, capabilities) {
158
+ this.ctx = ctx;
159
+ this.config = config;
160
+ this.execution = new DirectExecution(ctx, this, join(resolveDshHome(), "dsh-bot-proactive"));
161
+ this.groupBudgets = new GroupBudgetAccounting(ctx, (id, body) => this.change(id, body));
162
+ this.governance = new ProactiveGovernance(this.ctx, this, config, join(resolveDshHome(), "dsh-bot-proactive"));
163
+ this.deferredNotices = new DeferredNoticePump(ctx, this, config);
164
+ this.feedbackWorkflow = new FeedbackWorkflow(ctx.dshBots, {
165
+ request: (input) => {
166
+ if (!capabilities)
167
+ throw new Error("Capabilities unavailable");
168
+ return capabilities.request(input);
169
+ },
170
+ }, this, async (input) => {
171
+ const reply = await this.read({
172
+ kind: "work-ticket",
173
+ ticketId: input.ticketId,
174
+ });
175
+ const work = reply.kind === "work" ? reply.work : null;
176
+ if (!work ||
177
+ work.evidenceDigest !== input.evidenceDigest ||
178
+ work.revision !== input.expectedRevision)
179
+ throw new Error("Feedback delivery changed");
180
+ const result = await this.review(input.operationId, {
181
+ ticketId: input.ticketId,
182
+ expectedRevision: work.revision,
183
+ evidenceDigest: input.evidenceDigest,
184
+ review: "rework",
185
+ approved: true,
186
+ feedback: {
187
+ failures: [
188
+ {
189
+ criterion: "owner-feedback",
190
+ actual: input.reason,
191
+ expected: "Resolve the specific owner feedback before requesting acceptance",
192
+ },
193
+ ],
194
+ },
195
+ });
196
+ if (result.kind !== "receipt")
197
+ throw new Error("Rework outcome unavailable");
198
+ const next = await this.read({
199
+ kind: "work-ticket",
200
+ ticketId: input.ticketId,
201
+ });
202
+ if (next.kind !== "work" || !next.work)
203
+ throw new Error("Rework unavailable");
204
+ return {
205
+ ticketId: next.work.ticketId,
206
+ assignmentId: next.work.assignmentId,
207
+ };
208
+ });
209
+ this.#state = config.proactiveEnabled ? "starting" : "disabled";
210
+ }
211
+ get scopeOnly() { return this.#scopeOnly || !!this.config.proactiveFollowUpBootstrap; }
212
+ get acceptsNativeInput() { return !this.#retired; }
213
+ stopAdmission() {
214
+ if (this.#retired)
215
+ return;
216
+ this.#retired = true;
217
+ this.#feedStop.abort();
218
+ this.execution.cancelAll();
219
+ this.ctx.get("dshBotGroups")?.stopProactiveReviews();
220
+ this.#noticesClosing = this.deferredNotices.close();
221
+ }
222
+ async start() {
223
+ if (!this.config.proactiveEnabled || this.#retired)
224
+ return;
225
+ this.#resultJournal = await openResultJournal(this.ctx);
226
+ await this.connect();
227
+ if (!this.#feedStop.signal.aborted)
228
+ this.#maintenance = this.maintain();
229
+ }
230
+ async maintain() {
231
+ const signal = this.#feedStop.signal;
232
+ let healthySince = Date.now();
233
+ while (!signal.aborted) {
234
+ try {
235
+ await delay(this.config.proactiveMaintenanceIntervalMs ?? 1000, undefined, { signal });
236
+ if (signal.aborted)
237
+ break;
238
+ if (!this.#client?.available || this.#state !== "ready") {
239
+ this.#state = "unavailable";
240
+ if (this.#recoveries >= (this.config.proactiveRecoveryAttempts ?? 5))
241
+ continue;
242
+ this.execution.cancelAll();
243
+ this.ctx.get("dshBotGroups")?.stopProactiveReviews();
244
+ await this.execution.idle();
245
+ this.#recoveries++;
246
+ await this.#client?.close(this.#storeId).catch(() => { });
247
+ await delay(Math.min(30000, (this.config.proactiveRecoveryIntervalMs ?? 1000) *
248
+ 2 ** (this.#recoveries - 1)), undefined, { signal });
249
+ if (signal.aborted)
250
+ break;
251
+ await this.connect();
252
+ healthySince = Date.now();
253
+ }
254
+ else {
255
+ if (Date.now() - healthySince > 60000)
256
+ this.#recoveries = 0;
257
+ await this.status();
258
+ if (!this.#retired)
259
+ await this.ctx.get("dshBotFollowUpEvents")?.flush();
260
+ if (!this.scopeOnly && !this.#retired) {
261
+ await this.groupBudgets.flush();
262
+ await this.deferredNotices.pump();
263
+ await this.governance.maintain();
264
+ this.#automatic.wake();
265
+ }
266
+ }
267
+ }
268
+ catch {
269
+ if (!signal.aborted)
270
+ this.ctx.logger.warn("[dsh-bot] proactive maintenance will retry within its configured limit");
271
+ }
272
+ }
273
+ }
274
+ async connect() {
275
+ if (this.#feedStop.signal.aborted)
276
+ return;
277
+ try {
278
+ const runtime = this.ctx.get("subprocess");
279
+ if (!runtime)
280
+ throw new Error("Native subprocess service unavailable");
281
+ const root = await realpath(resolveDshHome());
282
+ const token = this.config.proactiveFollowUpBootstrap;
283
+ await withProactiveBinding(this.ctx, async (binding, saveStore) => {
284
+ if (token && (token.installationId !== binding.installationId ||
285
+ (token.storeId !== null && token.storeId !== binding.storeId)))
286
+ throw new Error("Proactive bootstrap identity changed");
287
+ this.#feedStop.signal.throwIfAborted();
288
+ this.#client = await CoordinatorClient.launch(runtime, this.config.proactiveNodeExecutable, join(root, "dsh-bot-proactive"), root, this.config.proactiveTimeoutMs);
289
+ this.#feedStop.signal.throwIfAborted();
290
+ const hello = await this.#client.request({
291
+ kind: "hello",
292
+ installationId: binding.installationId,
293
+ expectedStoreId: binding.storeId,
294
+ budget: this.config.proactiveModelDailyBudget,
295
+ externalBudget: this.config.proactiveExternalDailyBudget,
296
+ notice: !this.scopeOnly && !!this.config.proactiveNotificationPolicy,
297
+ noticeConfig: this.config.proactiveNoticeConfig,
298
+ governanceConfig: this.config.proactiveGovernance,
299
+ ...(token ? { followUpBootstrap: token.operation } : {}),
300
+ ...(!this.scopeOnly && this.config.proactiveRepairFixture
301
+ ? { feedbackSource: this.config.proactiveRepairFixture.sourceId }
302
+ : {}),
303
+ ...(!this.scopeOnly && this.config.proactiveAutoCiRule
304
+ ? { autoRule: this.config.proactiveAutoCiRule }
305
+ : {}),
306
+ });
307
+ if (hello.kind !== "hello" ||
308
+ !hello.capabilities.ingest ||
309
+ !hello.capabilities.snapshot ||
310
+ (token && hello.scopedRecovery !== true) ||
311
+ (binding.storeId !== null && binding.storeId !== hello.storeId))
312
+ throw new Error("Proactive capability handshake failed");
313
+ this.#storeId = hello.storeId;
314
+ this.#scopeOnly = hello.scopedRecovery === true;
315
+ await saveStore(hello.storeId);
316
+ this.#feedStop.signal.throwIfAborted();
317
+ this.#state = "ready";
318
+ this.ctx.get("dshBotFollowUpEvents")?.reset();
319
+ if (this.scopeOnly)
320
+ return;
321
+ await this.#resultJournal?.flush(hello.storeId, (id, body) => this.sendCommand(id, body));
322
+ await this.groupBudgets.flush();
323
+ this.scheduleGroupFollowUps();
324
+ for (const row of await this.workList()) {
325
+ // Only a pending assignment is known to have never been dispatched.
326
+ // Claimed/sent rows are parked by the coordinator before handshake.
327
+ if (!this.#retired && row.state === "pending")
328
+ this.execution.enqueue(row);
329
+ }
330
+ this.#feedStop.signal.throwIfAborted();
331
+ this.#automatic.wake();
332
+ if (this.config.proactiveCiFeed && !this.#feed) {
333
+ this.#feedStatus = "waiting";
334
+ this.#feed = pollCiFeed(join(root, "dsh-bot-proactive"), this.config.proactiveCiFeed, this, this.#feedStop.signal, (status) => {
335
+ if (this.#feedStatus !== "revoked") {
336
+ this.#feedStatus = status;
337
+ if (status === "ready")
338
+ this.#feedLastSuccessAt = new Date().toISOString();
339
+ }
340
+ }, async () => {
341
+ const ref = this.config.proactiveCiFeed?.github?.credentialRef;
342
+ return ref ? (await this.ctx.get('credentials')?.resolve(credentialRef(ref)))?.value : undefined;
343
+ }).catch(() => {
344
+ this.#feedStatus = "unavailable";
345
+ });
346
+ }
347
+ });
348
+ }
349
+ catch {
350
+ this.#state = "unavailable";
351
+ await this.#client?.close(this.#storeId);
352
+ }
353
+ }
354
+ async status() {
355
+ if (this.#retired)
356
+ return { state: "unavailable", capabilities: unavailable };
357
+ if (this.#state !== "ready")
358
+ return { state: this.#state, capabilities: unavailable };
359
+ const storeId = this.#storeId;
360
+ if (storeId && this.#client?.available) {
361
+ const result = await this.#client
362
+ .request({ kind: "snapshot", storeId })
363
+ .catch(() => undefined);
364
+ if (!this.#retired && result?.kind === "snapshot" && result.snapshot.storeId === storeId)
365
+ return {
366
+ state: "ready",
367
+ capabilities: {
368
+ ...capabilities,
369
+ automaticGroup: this.config.proactiveGroupReviewEnabled &&
370
+ !!this.directRoute &&
371
+ !!this.ctx.get("dshBotGroups") &&
372
+ !result.snapshot.executionControl.paused,
373
+ externalNotification: !this.scopeOnly &&
374
+ !!this.config.proactiveExternalNotificationPolicy &&
375
+ this.ctx.get("dshBotNotifications")?.supported() === true &&
376
+ !result.snapshot.executionControl.paused,
377
+ directExecution: !!this.directRoute && !result.snapshot.executionControl.paused,
378
+ },
379
+ snapshot: result.snapshot,
380
+ ...(this.#feedStatus ? { localFeed: this.#feedStatus } : {}),
381
+ ...(this.#feedLastSuccessAt ? { localFeedLastSuccessAt: this.#feedLastSuccessAt } : {}),
382
+ ...(!this.scopeOnly && this.config.proactiveCiFeed
383
+ ? {
384
+ localFeedScope: {
385
+ id: ciSourceId(this.config.proactiveCiFeed.scope),
386
+ ...this.config.proactiveCiFeed.scope,
387
+ },
388
+ }
389
+ : {}),
390
+ ...(this.directRoute && !result.snapshot.executionControl.paused
391
+ ? {
392
+ directRoute: this.directRoute,
393
+ repairOffers: this.repairOffers(),
394
+ workspaceOffers: await this.workspaceOffers(),
395
+ actionScopes: await this.actionScopes(),
396
+ groupRepairOffers: await this.groupRepairOffers(),
397
+ }
398
+ : {}),
399
+ };
400
+ }
401
+ this.#state = "unavailable";
402
+ return { state: "unavailable", capabilities: unavailable };
403
+ }
404
+ async stageResult(commandId, body) {
405
+ if (!this.#storeId || !this.#resultJournal)
406
+ throw new Error("Proactive result persistence unavailable");
407
+ await this.#resultJournal.stage(this.#storeId, commandId, body);
408
+ }
409
+ async acknowledgeResult(commandId, _body, reply) {
410
+ if (!this.#storeId || !this.#resultJournal)
411
+ throw new Error("Proactive result persistence unavailable");
412
+ return this.#resultJournal.acknowledge(this.#storeId, commandId, reply);
413
+ }
414
+ async reconcileForgetResults(assignmentIds) {
415
+ if (!assignmentIds.length)
416
+ return true;
417
+ if (!this.#storeId || !this.#resultJournal)
418
+ return false;
419
+ try {
420
+ const result = await this.#resultJournal.flush(this.#storeId, (id, body) => this.sendCommand(id, body), assignmentIds);
421
+ return result.pending === 0;
422
+ }
423
+ catch {
424
+ return false;
425
+ }
426
+ }
427
+ async sendCommand(commandId, body) {
428
+ const storeId = this.#storeId;
429
+ if ((this.#retired && body.kind !== "report-result") || this.#state !== "ready" || !storeId || !this.#client?.available)
430
+ return {
431
+ kind: "unknown",
432
+ commandId,
433
+ protocolVersion: 1,
434
+ correlationId: commandId,
435
+ };
436
+ return this.#client
437
+ .request({
438
+ kind: "command",
439
+ command: {
440
+ commandId,
441
+ body,
442
+ storeId,
443
+ actorRef: "local-host",
444
+ payloadDigest: digest(body),
445
+ },
446
+ })
447
+ .catch(() => ({
448
+ kind: "unknown",
449
+ commandId,
450
+ protocolVersion: 1,
451
+ correlationId: commandId,
452
+ }));
453
+ }
454
+ async submit(commandId, input, onResultStaged) {
455
+ const body = commandBodySchema.parse(input);
456
+ if (body.kind === "report-result") {
457
+ await this.stageResult(commandId, body);
458
+ onResultStaged?.();
459
+ }
460
+ const reply = await this.sendCommand(commandId, body);
461
+ if (body.kind === "cancel" &&
462
+ reply.kind === "receipt" &&
463
+ reply.receipt?.status === "committed")
464
+ this.execution.cancel(body.ticketId);
465
+ if (reply.kind === "unknown" ||
466
+ (reply.kind === "receipt" && reply.receipt?.status === "committed")) {
467
+ if (body.kind === "revoke-source")
468
+ this.execution.cancelSource(body.sourceId);
469
+ if (body.kind === "forget-begin")
470
+ this.execution.cancelSource(body.input.sourceId);
471
+ if (body.kind === "pause-execution" && body.paused)
472
+ this.execution.cancelAll();
473
+ }
474
+ if (body.kind === "report-result")
475
+ await this.acknowledgeResult(commandId, body, reply);
476
+ return reply;
477
+ }
478
+ async read(input) {
479
+ if (this.#retired || !this.#storeId || this.#state !== "ready" || !this.#client?.available)
480
+ throw new Error("Proactive coordinator unavailable");
481
+ const reply = await this.#client.request({
482
+ ...input,
483
+ storeId: this.#storeId,
484
+ });
485
+ if (this.#retired)
486
+ throw new Error("Proactive coordinator replaced");
487
+ return reply;
488
+ }
489
+ async feedbackRead(input) {
490
+ return this.read(input);
491
+ }
492
+ async ownsFollowUpSubject(subject, includeArchived = false) {
493
+ if (subject.kind === "bot") {
494
+ const bot = await this.ctx.dshBots.get(subject.bot.botId).catch(() => undefined);
495
+ return bot?.createdAt === subject.bot.botCreatedAt;
496
+ }
497
+ const group = await this.ctx.get("dshBotGroups")?.followUpSubject(subject.group).catch(() => undefined);
498
+ return group !== undefined && (includeArchived || !group.archived);
499
+ }
500
+ async followUpSummary(subject) {
501
+ if (!await this.ownsFollowUpSubject(subject, true))
502
+ throw new Error("Follow-up subject unavailable");
503
+ const reply = await this.read({ kind: "follow-up-summary", subject });
504
+ if (reply.kind !== "follow-up-summary")
505
+ throw new Error("Follow-up summary unavailable");
506
+ return reply.summary;
507
+ }
508
+ async followUpPage(input) {
509
+ if (!await this.ownsFollowUpSubject(input.subject, true))
510
+ throw new Error("Follow-up subject unavailable");
511
+ const reply = await this.read({ kind: "follow-up-page", input });
512
+ if (reply.kind !== "follow-up-page")
513
+ throw new Error("Follow-up page unavailable");
514
+ return reply.page;
515
+ }
516
+ async followUpPolicy(commandId, input) {
517
+ if (!await this.ownsFollowUpSubject(input.subject))
518
+ return { kind: "rejected", code: "stale" };
519
+ const reply = await this.change(commandId, { kind: "follow-up-policy", input });
520
+ if (reply.kind === "receipt")
521
+ this.ctx.get("dshBotFollowUpEvents")?.reset(false);
522
+ return reply;
523
+ }
524
+ async createFollowUpWatch(commandId, input) {
525
+ if (!await this.ownsFollowUpSubject(input.subject))
526
+ return { kind: "rejected", code: "stale" };
527
+ return this.change(commandId, { kind: "follow-up-watch-create", input });
528
+ }
529
+ async proposeGroupFollowUpWatch(commandId, input) {
530
+ if (!await this.ownsFollowUpSubject(input.subject))
531
+ return { kind: 'rejected', code: 'stale' };
532
+ return this.change(commandId, { kind: 'follow-up-group-watch-propose', input });
533
+ }
534
+ async followUpAction(commandId, input) {
535
+ if (!await this.ownsFollowUpSubject(input.subject, input.action === 'forget'))
536
+ return { kind: "rejected", code: "stale" };
537
+ return this.change(commandId, { kind: "follow-up-action", input });
538
+ }
539
+ async updateFollowUpWatch(commandId, input) {
540
+ if (!await this.ownsFollowUpSubject(input.subject))
541
+ return { kind: 'rejected', code: 'stale' };
542
+ return this.change(commandId, { kind: 'follow-up-watch-update', input });
543
+ }
544
+ followUpGroupChoice(input) {
545
+ return prepareGroupFollowUp(this, this.ctx.get('dshBotGroups'), input);
546
+ }
547
+ followUpGroupAccept(input) {
548
+ return acceptGroupFollowUp(this, this.ctx.get('dshBotGroups'), input);
549
+ }
550
+ followUpGroupAbandon(input) {
551
+ return abandonGroupFollowUp(this, this.ctx.get('dshBotGroups'), input);
552
+ }
553
+ async continueWork(commandId, input) {
554
+ return runWorkContinuation(commandId, input, {
555
+ hasReceipt: async (id) => { const result = await this.receipt(id); return result.kind === 'receipt' && !!result.receipt; },
556
+ read: async (ticketId) => { const result = await this.readWork({ kind: 'work-ticket', ticketId }); return result.kind === 'work' ? result.work : null; },
557
+ ownerCurrent: owner => !!this.ctx.dshBots.onboardingSnapshot(owner.botId, owner.botCreatedAt),
558
+ validateTarget: target => this.validateTarget(target), change: (id, body) => this.change(id, body),
559
+ enqueue: row => { if (!this.#retired && !this.scopeOnly)
560
+ this.execution.enqueue(row); },
561
+ });
562
+ }
563
+ ingestFollowUp(commandId, input) {
564
+ return this.change(commandId, { kind: "follow-up-ingest", input });
565
+ }
566
+ async workHistory(input) {
567
+ const reply = await this.read({ kind: "work-history", input });
568
+ if (reply.kind !== "work-history")
569
+ throw new Error("History unavailable");
570
+ return reply.history;
571
+ }
572
+ async responsibilities(owner) {
573
+ const reply = await this.read({ kind: "responsibilities", owner });
574
+ if (reply.kind !== "responsibilities")
575
+ throw new Error("Responsibilities unavailable");
576
+ return reply.rows;
577
+ }
578
+ async changeResponsibility({ commandId, mutation, }) {
579
+ try {
580
+ const bot = await this.ctx.dshBots.get(mutation.owner.botId);
581
+ if (bot.createdAt !== mutation.owner.botCreatedAt)
582
+ throw new Error("Bot changed");
583
+ if (mutation.kind === "mode" && mutation.mode === "auto") {
584
+ const saved = (await this.responsibilities(mutation.owner)).find((row) => row.responsibility.id === mutation.id)?.responsibility;
585
+ if (!saved || !hasResponsibilityRoute(saved.target) ||
586
+ (saved.action === "repair-workspace" && !workspaceExecutionAvailable))
587
+ return { kind: "rejected", code: "forbidden" };
588
+ await this.validateTarget(saved.target);
589
+ }
590
+ if ("draft" in mutation) {
591
+ const { target, mode } = mutation.draft;
592
+ if (!sameBot(target.bot, mutation.owner) || target.botUpdatedAt !== bot.updatedAt)
593
+ throw new Error("Bot changed");
594
+ if (mode === "auto") {
595
+ if (!hasResponsibilityRoute(target))
596
+ return { kind: "rejected", code: "forbidden" };
597
+ await this.validateTarget(target);
598
+ }
599
+ const source = await this.read({
600
+ kind: "checkpoint",
601
+ sourceId: mutation.draft.source.id,
602
+ });
603
+ const configured = this.config.proactiveCiFeed?.scope;
604
+ if (source.kind !== "checkpoint" ||
605
+ (source.source
606
+ ? source.source.revoked || source.source.generation !== mutation.draft.source.generation
607
+ : !configured || mode === "auto" ||
608
+ ciSourceId(configured) !== mutation.draft.source.id ||
609
+ configured.generation !== mutation.draft.source.generation))
610
+ throw new Error("Source changed");
611
+ const policy = mutation.draft;
612
+ if (policy.action !== "inspect-ci-result" &&
613
+ !(await this.actionScopes()).some((scope) => scope.action === policy.action &&
614
+ scope.digest === policy.actionScopeDigest))
615
+ throw new Error("Action configuration changed");
616
+ }
617
+ }
618
+ catch {
619
+ return { kind: "rejected", code: "stale" };
620
+ }
621
+ const result = await this.change(commandId, {
622
+ kind: "responsibility-mutation",
623
+ input: mutation,
624
+ });
625
+ if (result.kind !== "receipt")
626
+ return result.kind === "unknown" ? { kind: "unknown" } : result;
627
+ this.#automatic.wake();
628
+ const row = (await this.responsibilities(mutation.owner)).find((row) => row.responsibility.id === mutation.id);
629
+ return row
630
+ ? { kind: "applied", responsibility: row.responsibility }
631
+ : { kind: "unknown" };
632
+ }
633
+ async activityPage(input) {
634
+ const bot = await this.ctx.dshBots.get(input.owner.botId);
635
+ if (bot?.createdAt !== input.owner.botCreatedAt)
636
+ throw new Error('Bot changed');
637
+ const reply = await this.read({ kind: 'activity-page', input });
638
+ if (reply.kind !== 'activity-page')
639
+ throw new Error(reply.kind === 'rejected' ? reply.code : 'Activity unavailable');
640
+ return reply.page;
641
+ }
642
+ async runMethodEvaluation(candidate) {
643
+ const evaluation = candidate.methodEvaluation, proposal = candidate.proposal;
644
+ if (evaluation?.state !== 'running' || proposal.kind !== 'skill' || !evaluation.operationId)
645
+ throw new Error('Evaluation is not claimed');
646
+ const bot = await this.ctx.dshBots.get(proposal.origin.bot.botId);
647
+ if (bot.createdAt !== proposal.origin.bot.botCreatedAt)
648
+ throw new Error('Bot changed');
649
+ const target = { bot: proposal.origin.bot, botUpdatedAt: bot.updatedAt, provider: evaluation.plan.provider, model: evaluation.plan.model };
650
+ await this.validateTarget(target);
651
+ const receipts = [];
652
+ for (const sample of evaluation.plan.cases)
653
+ for (const arm of ['parent', 'candidate', 'noop', 'negative']) {
654
+ this.#feedStop.signal.throwIfAborted();
655
+ await this.validateTarget(target);
656
+ const content = arm === 'candidate' ? proposal.content : arm === 'negative' ? 'Always respond only with null.' : proposal.before ?? '';
657
+ const document = { kind: 'document-analysis', version: 1, name: `evaluation-${evaluation.digest.slice(0, 32)}-${sample.id}-${arm}`, sourceVersion: 1,
658
+ content: sample.input, question: 'Apply the frozen method and return only JSON.', acceptance: 'Independent frozen exact-json-v1 judge; no owner acceptance is implied.' };
659
+ const result = await this.change(randomUUID(), { kind: 'submit-document', document, target, approved: true,
660
+ methodTrial: { planDigest: evaluation.digest, caseId: sample.id, arm, name: proposal.name, content, methodHash: digest(content), inputHash: digest(sample.input) },
661
+ taskLimits: { maxAttempts: 1, maxTokens: evaluation.plan.maxTokensPerCall, deadlineAt: new Date(Date.now() + this.executionTimeoutMs).toISOString() } });
662
+ if (result.kind !== 'receipt')
663
+ break;
664
+ const work = (await this.workList(target.bot)).find(row => row.sourceDigest === digest(document));
665
+ if (!work)
666
+ break;
667
+ this.execution.enqueue(work);
668
+ let settled = work;
669
+ while (['pending', 'claimed', 'sent'].includes(settled.state) && Date.now() < Date.parse(work.expiresAt)) {
670
+ await delay(150, undefined, { signal: this.#feedStop.signal });
671
+ const reply = await this.read({ kind: 'work-ticket', ticketId: work.ticketId });
672
+ if (reply.kind !== 'work' || !reply.work || reply.work.assignmentId !== work.assignmentId)
673
+ break;
674
+ settled = reply.work;
675
+ }
676
+ const receipt = { caseId: sample.id, arm, ticketId: work.ticketId, assignmentId: work.assignmentId, state: 'inconclusive' };
677
+ if (settled.state === 'delivered' && settled.methodEvidence && settled.evidence && settled.sessionId) {
678
+ const session = await this.ctx.sessionController.inspect(SessionId(settled.sessionId));
679
+ const answer = session.events.find(event => event.type === 'assistant/message' && event.data.message.id === settled.evidence?.assistantId);
680
+ if (answer?.type === 'assistant/message' && digest(answer.data.message.content) === settled.evidence.outputDigest) {
681
+ const text = answer.data.message.content.filter(block => block.type === 'text').map(block => block.text).join('');
682
+ Object.assign(receipt, { state: 'completed', passed: judgeMethodAnswer(text, sample.expected), method: settled.methodEvidence, evidenceDigest: settled.evidenceDigest });
683
+ }
684
+ }
685
+ receipts.push(receipt);
686
+ if (receipt.state !== 'completed')
687
+ return receipts;
688
+ }
689
+ return receipts;
690
+ }
691
+ async submitDocument(raw) {
692
+ const input = documentRequestSchema.parse(raw);
693
+ if (Date.parse(input.requestedAt) > Date.now() + 5000)
694
+ return { kind: 'rejected', code: 'invalid' };
695
+ const bot = await this.ctx.dshBots.get(input.owner.botId);
696
+ const route = this.directRoute;
697
+ if (!bot || bot.createdAt !== input.owner.botCreatedAt || !route)
698
+ return { kind: 'rejected', code: 'forbidden' };
699
+ const target = { bot: input.owner, botUpdatedAt: bot.updatedAt, ...route };
700
+ await this.validateTarget(target);
701
+ const reply = await this.change(input.commandId, { kind: 'submit-document', document: input.document,
702
+ target, approved: true, taskLimits: { maxAttempts: 3, maxTokens: this.config.proactiveTaskTokenLimit ?? 32768,
703
+ deadlineAt: new Date(Date.parse(input.requestedAt) + (this.config.proactiveDocumentLifetimeMs ?? 86400000)).toISOString() } });
704
+ if (reply.kind === 'receipt' && reply.receipt.status === 'committed') {
705
+ const rows = await this.workList(input.owner);
706
+ const work = rows.find(row => row.sourceDigest === digest(input.document));
707
+ if (work)
708
+ this.execution.enqueue(work);
709
+ }
710
+ return reply;
711
+ }
712
+ async reconcileWork(input) {
713
+ const current = await this.workDetail(input);
714
+ if (current.state === 'pending' && current.continuation) {
715
+ if (this.scopeOnly)
716
+ throw new Error('Accepted continuation unavailable in this activation');
717
+ await reconcilePendingWorkContinuation(current, {
718
+ receipt: async (id) => {
719
+ const reply = await this.receipt(id);
720
+ return reply.kind === 'receipt' ? reply.receipt : null;
721
+ },
722
+ assignment: async (assignmentId) => {
723
+ const reply = await this.read({ kind: 'work-assignment', assignmentId });
724
+ return reply.kind === 'work' ? reply.work : null;
725
+ },
726
+ enqueue: work => {
727
+ if (this.#retired || this.scopeOnly)
728
+ throw new Error('Accepted continuation unavailable in this activation');
729
+ this.execution.enqueue(work);
730
+ },
731
+ });
732
+ return current;
733
+ }
734
+ if (!this.#storeId || !this.#resultJournal)
735
+ throw new Error('Result journal unavailable');
736
+ // This branch only replays already durable result evidence.
737
+ await this.#resultJournal.flush(this.#storeId, (id, body) => this.sendCommand(id, body), [current.assignmentId]);
738
+ const reply = await this.read({ kind: 'work-ticket', ticketId: current.ticketId });
739
+ if (reply.kind !== 'work' || !reply.work || reply.work.assignmentId !== current.assignmentId || !sameBot(reply.work.target.bot, input.owner))
740
+ throw new Error('Work changed');
741
+ return reply.work;
742
+ }
743
+ async workDetail(input) {
744
+ const bot = await this.ctx.dshBots.get(input.owner.botId);
745
+ if (bot?.createdAt !== input.owner.botCreatedAt)
746
+ throw new Error('Bot changed');
747
+ const reply = await this.read({ kind: 'work-detail', input });
748
+ if (reply.kind !== 'work' || !reply.work)
749
+ throw new Error('Work changed');
750
+ const attempts = [];
751
+ let beforeGeneration;
752
+ do {
753
+ const history = await this.workHistory({ ticketId: input.ticketId, beforeGeneration, limit: 5 });
754
+ attempts.push(...history.versions);
755
+ beforeGeneration = history.nextBeforeGeneration;
756
+ } while (beforeGeneration !== undefined && attempts.length < 20);
757
+ return { ...reply.work, taskCost: { ...await taskCost(this.ctx, attempts), truncated: beforeGeneration !== undefined } };
758
+ }
759
+ async suggestions(owner, includeFiltered) {
760
+ const storeId = this.#storeId;
761
+ if (this.#state === "disabled")
762
+ return [];
763
+ if (this.#state !== "ready" || !storeId || !this.#client?.available)
764
+ throw new Error("Proactive coordinator unavailable");
765
+ const reply = await this.#client.request({
766
+ kind: "suggestions",
767
+ storeId,
768
+ ...(owner ? { owner } : {}),
769
+ ...(includeFiltered ? { includeFiltered } : {}),
770
+ });
771
+ if (reply.kind !== "suggestions")
772
+ throw new Error("Proactive suggestions unavailable");
773
+ return reply.suggestions;
774
+ }
775
+ async ciCheckpoint(scope) {
776
+ const storeId = this.#storeId;
777
+ if (this.#state !== "ready" || !storeId || !this.#client?.available)
778
+ throw new Error("Proactive coordinator unavailable");
779
+ const reply = await this.#client.request({
780
+ kind: "checkpoint",
781
+ storeId,
782
+ sourceId: ciSourceId(scope),
783
+ });
784
+ if (reply.kind !== "checkpoint")
785
+ throw new Error("Proactive source checkpoint unavailable");
786
+ return reply.source;
787
+ }
788
+ async observeCi(commandId, scope, page) {
789
+ const input = observeCiPage(scope, page);
790
+ const reply = await this.submit(commandId, input);
791
+ if (reply.kind === "receipt" && reply.receipt?.stored)
792
+ this.scheduleGroupFollowUps();
793
+ if (reply.kind === "receipt")
794
+ this.#automatic.wake();
795
+ return reply;
796
+ }
797
+ revokeCi(commandId, scope) {
798
+ return this.submit(commandId, {
799
+ kind: "revoke-source",
800
+ sourceId: ciSourceId(scope),
801
+ generation: scope.generation,
802
+ });
803
+ }
804
+ async revokeConfiguredSource(input) {
805
+ const scope = this.config.proactiveCiFeed?.scope;
806
+ if (!scope ||
807
+ input.generation !== scope.generation ||
808
+ input.sourceId !== ciSourceId(scope))
809
+ return { kind: "rejected", code: "stale" };
810
+ const reply = await this.change(input.commandId, {
811
+ kind: "revoke-source",
812
+ sourceId: input.sourceId,
813
+ generation: input.generation,
814
+ });
815
+ if (reply.kind === "receipt")
816
+ this.#feedStatus = "revoked";
817
+ return reply;
818
+ }
819
+ async receipt(commandId) {
820
+ const storeId = this.#storeId;
821
+ if (this.#state !== "ready" || !storeId || !this.#client?.available)
822
+ throw new Error("Proactive coordinator unavailable");
823
+ return this.#client.request({ kind: "receipt", commandId, storeId });
824
+ }
825
+ get directRoute() {
826
+ if (this.#retired || this.scopeOnly)
827
+ return undefined;
828
+ const { proactiveEnabled, proactiveExecutionEnabled, proactiveProvider, proactiveModel, } = this.config;
829
+ return proactiveEnabled &&
830
+ proactiveExecutionEnabled &&
831
+ proactiveProvider &&
832
+ proactiveModel
833
+ ? { provider: proactiveProvider, model: proactiveModel }
834
+ : undefined;
835
+ }
836
+ repairOffers() {
837
+ const fixture = this.config.proactiveRepairFixture;
838
+ if (!fixture)
839
+ return [];
840
+ const { id: fixtureId, title, sourceId } = fixture;
841
+ const endpoint = this.config.proactiveExternalExecutor;
842
+ return [
843
+ {
844
+ fixtureId,
845
+ title,
846
+ sourceId,
847
+ specDigest: digest([fixture, "native"]),
848
+ executor: "native",
849
+ },
850
+ ...(endpoint
851
+ ? [
852
+ {
853
+ fixtureId,
854
+ title,
855
+ sourceId,
856
+ specDigest: digest([fixture, endpoint]),
857
+ executor: "external",
858
+ },
859
+ ]
860
+ : []),
861
+ ];
862
+ }
863
+ async workspaceOffers() {
864
+ const workspace = this.config.proactiveWorkspaceRepair;
865
+ if (!workspaceExecutionAvailable || !workspace)
866
+ return [];
867
+ return Promise.all([
868
+ createWorkspaceRepairOffer(workspace, "native"),
869
+ ...(this.config.proactiveCommandExecutor
870
+ ? [
871
+ createWorkspaceRepairOffer(workspace, "command", this.config.proactiveCommandExecutor),
872
+ ]
873
+ : []),
874
+ ]);
875
+ }
876
+ async actionScopes() {
877
+ return [
878
+ ...this.repairOffers().map((offer) => ({
879
+ action: offer.executor === "external"
880
+ ? "repair-external"
881
+ : "repair-fixture",
882
+ digest: offer.specDigest,
883
+ title: offer.title,
884
+ })),
885
+ ...(await this.workspaceOffers()).map((offer) => ({
886
+ action: "repair-workspace",
887
+ digest: offer.specDigest,
888
+ title: `${offer.title} / ${offer.executorLabel}`,
889
+ })),
890
+ ];
891
+ }
892
+ workspaceConfiguration(grant, sourceId) {
893
+ if (!workspaceExecutionAvailable)
894
+ throw new Error(workspaceExecutionUnavailable);
895
+ const workspace = this.config.proactiveWorkspaceRepair, command = this.config.proactiveCommandExecutor;
896
+ if (!workspace ||
897
+ workspace.sourceId !== sourceId ||
898
+ workspace.id !== grant.workspaceId ||
899
+ (grant.executor === "command" && !command) ||
900
+ workspaceSpecification(workspace, grant.executor, command ?? undefined) !== grant.specDigest)
901
+ throw new Error("Approved workspace configuration changed");
902
+ return {
903
+ workspace,
904
+ ...(grant.executor === "command" && command ? { command } : {}),
905
+ };
906
+ }
907
+ repairConfiguration(repair, sourceId) {
908
+ const fixture = this.config.proactiveRepairFixture;
909
+ if (!fixture ||
910
+ !this.repairOffers().some((offer) => offer.fixtureId === repair.fixtureId &&
911
+ offer.sourceId === sourceId &&
912
+ offer.specDigest === repair.specDigest &&
913
+ offer.executor === repair.executor))
914
+ throw new Error("Approved repair configuration changed");
915
+ return {
916
+ fixture,
917
+ endpoint: this.config.proactiveExternalExecutor,
918
+ node: this.config.proactiveNodeExecutable,
919
+ };
920
+ }
921
+ get modelOutputTokens() {
922
+ return this.config.proactiveModelOutputTokens ?? 1024;
923
+ }
924
+ get executionTimeoutMs() {
925
+ return this.config.proactiveExecutionTimeoutMs;
926
+ }
927
+ async groupRepairOffers() {
928
+ const groups = this.ctx.get('dshBotGroups');
929
+ const fallback = this.directRoute;
930
+ if (!workspaceExecutionAvailable || !this.config.proactiveGroupRepairEnabled || !groups || !fallback)
931
+ return [];
932
+ const offers = [];
933
+ for (const row of await groups.list()) {
934
+ if (row.group.archived || row.group.state !== 'ready' || row.reason)
935
+ continue;
936
+ const members = row.members.filter(member => member.enabled && member.removedAt === undefined && !row.unavailableMemberIds.includes(member.id));
937
+ const roles = [];
938
+ for (const member of members) {
939
+ const bot = await this.ctx.dshBots.get(member.bot.botId);
940
+ if (bot?.createdAt !== member.bot.botCreatedAt)
941
+ continue;
942
+ roles.push({ memberId: member.id, bot: member.bot, botUpdatedAt: bot.updatedAt,
943
+ modelSelection: groupMemberModel(row.group, member.id, bot, fallback) });
944
+ }
945
+ for (const supervisor of roles)
946
+ for (const implementer of roles) {
947
+ if (sameBot(supervisor.bot, implementer.bot) || offers.length >= 32)
948
+ continue;
949
+ offers.push({ title: row.group.name, grant: {
950
+ group: { groupId: row.group.id, groupCreatedAt: row.group.createdAt },
951
+ rootSessionId: row.group.rootSessionId, membershipRevision: row.group.membershipRevision,
952
+ modelRevision: row.group.modelRevision ?? 0, supervisor, implementer, maxCalls: 3,
953
+ } });
954
+ }
955
+ if (offers.length >= 32)
956
+ break;
957
+ }
958
+ return offers;
959
+ }
960
+ async validateGroupRepair(work) {
961
+ const grant = work.groupRepair;
962
+ if (!grant)
963
+ return;
964
+ if (work.workspaceRepair?.executor !== "native" ||
965
+ !sameBot(grant.supervisor.bot, work.target.bot) ||
966
+ grant.supervisor.botUpdatedAt !== work.target.botUpdatedAt ||
967
+ !(await this.groupRepairOffers()).some((offer) => digest(offer.grant) === digest(grant)))
968
+ throw new Error("Group repair authorization changed");
969
+ }
970
+ validateTarget(target) {
971
+ const route = this.directRoute;
972
+ if (this.#state !== "ready" ||
973
+ !this.#client?.available ||
974
+ !route ||
975
+ route.provider !== target.provider ||
976
+ route.model !== target.model)
977
+ throw new Error("Proactive execution route unavailable");
978
+ // Use the committed Bot snapshot without entering the registry queue.
979
+ // A managed outlet can hold its ledger while checking this target.
980
+ const bot = this.ctx.dshBots.onboardingSnapshot(target.bot.botId, target.bot.botCreatedAt);
981
+ if (!bot || bot.updatedAt !== target.botUpdatedAt)
982
+ throw new Error("Proactive Bot incarnation changed");
983
+ return bot;
984
+ }
985
+ async workList(owner) {
986
+ if (this.#state === "disabled")
987
+ return [];
988
+ const reply = await this.readWork({ kind: "work-list", ...(owner ? { owner } : {}) });
989
+ if (reply.kind !== "work-list")
990
+ throw new Error("Proactive work unavailable");
991
+ return reply.work;
992
+ }
993
+ async readWork(input) {
994
+ const storeId = this.#storeId;
995
+ if (this.#state !== "ready" || !storeId || !this.#client?.available)
996
+ throw new Error("Proactive work unavailable");
997
+ return this.#client.request({ ...input, storeId });
998
+ }
999
+ async change(commandId, body) {
1000
+ const reply = await this.submit(commandId, body);
1001
+ if (reply.kind === "receipt" && reply.receipt) {
1002
+ if ([
1003
+ "report-result",
1004
+ "cancel",
1005
+ "pause-execution",
1006
+ "revoke-source",
1007
+ ].includes(body.kind))
1008
+ this.#automatic.wake();
1009
+ return { kind: "receipt", receipt: reply.receipt };
1010
+ }
1011
+ if (reply.kind === "rejected")
1012
+ return { kind: "rejected", code: reply.code };
1013
+ return { kind: "unknown", commandId };
1014
+ }
1015
+ async accept(commandId, input) {
1016
+ try {
1017
+ await this.validateTarget(input.target);
1018
+ await this.validateGroupRepair(input);
1019
+ if (input.repair)
1020
+ this.repairConfiguration(input.repair, input.sourceId);
1021
+ if (input.workspaceRepair)
1022
+ this.workspaceConfiguration(input.workspaceRepair, input.sourceId);
1023
+ }
1024
+ catch {
1025
+ return { kind: "rejected", code: "forbidden" };
1026
+ }
1027
+ const reply = await this.change(commandId, {
1028
+ ...input,
1029
+ kind: "accept-decision",
1030
+ });
1031
+ if (reply.kind === "receipt" && reply.receipt.status === "committed") {
1032
+ await this.dispatch(input.decisionId);
1033
+ }
1034
+ return reply;
1035
+ }
1036
+ async dispatch(decisionId) {
1037
+ const current = await this.readWork({ kind: "work", decisionId }).catch(() => undefined);
1038
+ if (current?.kind === "work" && current.work)
1039
+ this.execution.enqueue(current.work);
1040
+ }
1041
+ async notify(decisionId, assignmentId, signal) {
1042
+ if (this.scopeOnly || this.#retired)
1043
+ return;
1044
+ const reply = await this.read({ kind: "work", decisionId });
1045
+ if (reply.kind === "work" && reply.work?.assignmentId === assignmentId)
1046
+ await this.deferredNotices.schedule(reply.work, signal);
1047
+ }
1048
+ async workspaceReview(input) {
1049
+ let beforeGeneration;
1050
+ do {
1051
+ const page = await this.workHistory({
1052
+ ticketId: input.ticketId,
1053
+ beforeGeneration,
1054
+ limit: 5,
1055
+ });
1056
+ const row = page.versions.find((row) => row.assignmentId === input.assignmentId &&
1057
+ row.evidenceDigest === input.evidenceDigest);
1058
+ if (row)
1059
+ return readWorkspaceReview(join(resolveDshHome(), "dsh-bot-proactive"), row);
1060
+ beforeGeneration = page.nextBeforeGeneration;
1061
+ } while (beforeGeneration !== undefined);
1062
+ throw new Error("Workspace delivery changed");
1063
+ }
1064
+ async groupReview(input) {
1065
+ const groups = this.ctx.get("dshBotGroups");
1066
+ if (!groups)
1067
+ throw new Error("Group review unavailable");
1068
+ const reply = await this.readWork({
1069
+ kind: "work-ticket",
1070
+ ticketId: input.ticketId,
1071
+ });
1072
+ const work = reply.kind === "work" ? reply.work : null;
1073
+ const artifactReview = work?.state === "delivered" &&
1074
+ (work.repairEvidence?.verification.exitCode === 0 ||
1075
+ work.workspaceEvidence?.verification.exitCode === 0)
1076
+ ? (work.repairEvidence ?? work.workspaceEvidence)
1077
+ : undefined;
1078
+ if (!work ||
1079
+ (work.state !== "accepted" && !artifactReview) ||
1080
+ work.revision !== input.expectedRevision)
1081
+ throw new Error("Group review is stale");
1082
+ const summaries = await groups.list();
1083
+ if (work.groupReview) {
1084
+ const receipt = work.groupReview;
1085
+ if (input.cancelFollowUp) {
1086
+ const result = await this.change(randomUUID(), {
1087
+ kind: "deny-group-follow-up",
1088
+ ticketId: work.ticketId,
1089
+ expectedRevision: work.revision,
1090
+ });
1091
+ if (result.kind !== "receipt")
1092
+ throw new Error("Group follow-up changed");
1093
+ }
1094
+ const root = summaries.find(({ group }) => group.id === receipt.group.groupId &&
1095
+ group.createdAt === receipt.group.groupCreatedAt)?.group;
1096
+ return receipt.state === "linked" && receipt.turnId && root
1097
+ ? {
1098
+ kind: "linked",
1099
+ rootSessionId: root.rootSessionId,
1100
+ turnId: receipt.turnId,
1101
+ ...(receipt.followUp
1102
+ ? {
1103
+ followUpState: input.cancelFollowUp
1104
+ ? "denied"
1105
+ : receipt.followUp.state,
1106
+ }
1107
+ : {}),
1108
+ }
1109
+ : { kind: "unknown" };
1110
+ }
1111
+ if (input.cancelFollowUp)
1112
+ throw new Error("No group follow-up");
1113
+ if (!this.config.proactiveGroupReviewEnabled)
1114
+ throw new Error("Group review unavailable");
1115
+ await this.validateTarget(work.target);
1116
+ if (Date.parse(work.expiresAt) <= Date.now())
1117
+ throw new Error("Group review expired");
1118
+ const candidates = summaries.flatMap(row => {
1119
+ const { group } = row;
1120
+ if (group.archived || group.state !== 'ready' || row.reason)
1121
+ return [];
1122
+ const members = row.members.filter(member => member.enabled && member.removedAt === undefined && !row.unavailableMemberIds.includes(member.id)).sort((a, b) => a.order - b.order);
1123
+ return members.flatMap((first, index) => members.slice(index + 1).filter(second => !sameBot(first.bot, second.bot)).map(second => ({
1124
+ row, choice: {
1125
+ group: { groupId: group.id, groupCreatedAt: group.createdAt }, title: group.name,
1126
+ rootSessionId: group.rootSessionId,
1127
+ memberIds: [first.id, second.id],
1128
+ memberBotIds: [first.bot.botId, second.bot.botId],
1129
+ audienceBotIds: row.members.filter(member => member.enabled && member.removedAt === undefined).map(member => member.bot.botId),
1130
+ },
1131
+ })));
1132
+ });
1133
+ if (!input.group && input.reviewedDigest === undefined)
1134
+ return { kind: "choices", groups: candidates.map((item) => item.choice) };
1135
+ const selected = candidates.find((item) => item.choice.group.groupId === input.group?.groupId &&
1136
+ item.choice.group.groupCreatedAt === input.group.groupCreatedAt &&
1137
+ (input.memberIds ? digest(item.choice.memberIds) === digest(input.memberIds) : item.row.members.filter(member => member.enabled && member.removedAt === undefined).length === 2));
1138
+ if (!selected)
1139
+ throw new Error("Group membership changed");
1140
+ const { row } = selected;
1141
+ const choice = selected.choice;
1142
+ const revisions = await Promise.all(choice.memberBotIds.map((id) => this.ctx.dshBots.get(id)));
1143
+ const [first, second] = revisions;
1144
+ if (!first || !second)
1145
+ throw new Error("Group reviewer unavailable");
1146
+ const botRevisions = [first.updatedAt, second.updatedAt];
1147
+ choice.memberModels = choice.memberIds.map((memberId, index) => ({ memberId, modelSelection: groupMemberModel(row.group, memberId, index === 0 ? first : second, work.target) }));
1148
+ const modelRevision = row.group.modelRevision ?? 0;
1149
+ const followUpAvailable = this.config.proactiveGroupFollowUpEnabled;
1150
+ const followUpMember = input.followUpMemberId &&
1151
+ row.members.find((member) => member.id === input.followUpMemberId &&
1152
+ choice.memberIds.includes(member.id));
1153
+ if (input.followUpMemberId && (!followUpAvailable || !followUpMember))
1154
+ throw new Error("Group follow-up member unavailable");
1155
+ const followUp = followUpMember
1156
+ ? {
1157
+ memberId: followUpMember.id,
1158
+ modelSelection: choice.memberModels.find(item => item.memberId === followUpMember.id)?.modelSelection,
1159
+ modelRevision,
1160
+ bot: followUpMember.bot,
1161
+ botRevision: choice.memberIds[0] === followUpMember.id
1162
+ ? first.updatedAt
1163
+ : second.updatedAt,
1164
+ membershipRevision: row.group.membershipRevision,
1165
+ }
1166
+ : undefined;
1167
+ if (artifactReview)
1168
+ await this.verifyGroupArtifact(work);
1169
+ const artifactText = artifactReview
1170
+ ? work.workspaceEvidence
1171
+ ? formatWorkspaceReview(work, await readWorkspaceReview(join(resolveDshHome(), "dsh-bot-proactive"), work))
1172
+ : formatRepairReview(work, await readRepairReview(join(resolveDshHome(), "dsh-bot-proactive"), work))
1173
+ : work.title;
1174
+ const text = JSON.stringify({ context: taskHandoff(work), evidence: artifactText });
1175
+ if (Buffer.byteLength(text, "utf8") > GROUP_TEXT_MAX_BYTES)
1176
+ throw new Error("Full artifact exceeds group review size; narrow the approved workspace scope");
1177
+ const approval = digest([
1178
+ work.ticketId,
1179
+ work.assignmentId,
1180
+ work.revision,
1181
+ work.target,
1182
+ choice,
1183
+ row.group.membershipRevision,
1184
+ modelRevision,
1185
+ row.members,
1186
+ botRevisions,
1187
+ text,
1188
+ artifactReview ? work.evidenceDigest : undefined,
1189
+ followUp,
1190
+ ]);
1191
+ if (input.reviewedDigest === undefined)
1192
+ return {
1193
+ kind: "preview",
1194
+ choice,
1195
+ text,
1196
+ digest: approval,
1197
+ followUpAvailable,
1198
+ ...(followUp ? { followUpMemberId: followUp.memberId } : {}),
1199
+ };
1200
+ if (input.reviewedDigest !== approval)
1201
+ throw new Error("Group review changed");
1202
+ const claim = await this.change(randomUUID(), {
1203
+ kind: "claim-group-review",
1204
+ ticketId: work.ticketId,
1205
+ expectedRevision: work.revision,
1206
+ group: choice.group,
1207
+ digest: approval,
1208
+ ...(artifactReview ? { evidenceDigest: work.evidenceDigest } : {}),
1209
+ ...(followUp ? { followUp } : {}),
1210
+ });
1211
+ if (claim.kind === "unknown")
1212
+ return { kind: "unknown" };
1213
+ if (claim.kind !== "receipt")
1214
+ throw new Error("Group review rejected");
1215
+ const grantedReply = await this.read({
1216
+ kind: "work-ticket",
1217
+ ticketId: work.ticketId,
1218
+ });
1219
+ const grantedWork = grantedReply.kind === "work" ? grantedReply.work : null;
1220
+ if (!grantedWork || grantedWork.assignmentId !== work.assignmentId)
1221
+ throw new Error("Group grant changed");
1222
+ const budget = grantedWork.groupReview?.budget;
1223
+ if (work.responsibility && !budget)
1224
+ throw new Error("Group task budget missing");
1225
+ const turn = await groups
1226
+ .startProactiveReview(choice.group, {
1227
+ operationId: `proactive:${work.assignmentId}`,
1228
+ expectedMembershipRevision: row.group.membershipRevision,
1229
+ text,
1230
+ memberIds: choice.memberIds,
1231
+ }, {
1232
+ ticketId: work.ticketId,
1233
+ assignmentId: work.assignmentId,
1234
+ provider: work.target.provider,
1235
+ model: work.target.model,
1236
+ botRevisions,
1237
+ memberModels: choice.memberModels,
1238
+ modelRevision,
1239
+ ...(budget
1240
+ ? {
1241
+ requestBudget: {
1242
+ maxTokens: budget.perCallTokens,
1243
+ outputTokens: Math.min(this.modelOutputTokens, Math.floor(budget.perCallTokens / 2)),
1244
+ deadlineAt: budget.deadlineAt,
1245
+ },
1246
+ }
1247
+ : {}),
1248
+ }, async () => {
1249
+ if (artifactReview)
1250
+ await this.verifyGroupArtifact(work);
1251
+ await this.verifyGroupDispatch(work, approval);
1252
+ })
1253
+ .catch(() => undefined);
1254
+ const settled = await this.change(randomUUID(), {
1255
+ kind: "settle-group-review",
1256
+ ticketId: work.ticketId,
1257
+ expectedRevision: work.revision + 1,
1258
+ digest: approval,
1259
+ ...(turn ? { turnId: turn.id } : {}),
1260
+ });
1261
+ if (turn && budget)
1262
+ void this.groupBudgets
1263
+ .settle(grantedWork, turn.id, choice.memberIds, "review")
1264
+ .catch(() => this.ctx.logger.warn("[dsh-bot] group review budget awaits reconciliation"));
1265
+ if (turn && settled.kind === "receipt" && followUp)
1266
+ void groups
1267
+ .waitForProactiveReview(turn.id)
1268
+ .then(() => this.scheduleGroupFollowUps())
1269
+ .catch(() => { });
1270
+ return turn && settled.kind === "receipt"
1271
+ ? {
1272
+ kind: "linked",
1273
+ rootSessionId: choice.rootSessionId,
1274
+ turnId: turn.id,
1275
+ ...(followUp ? { followUpState: "armed" } : {}),
1276
+ }
1277
+ : { kind: "unknown" };
1278
+ }
1279
+ async verifyGroupArtifact(work) {
1280
+ if (work.groupRepair &&
1281
+ !(await verifyGroupRepairEvidence(this.ctx, join(resolveDshHome(), "dsh-bot-proactive"), work)))
1282
+ throw new Error("Group repair evidence changed");
1283
+ if (work.workspaceEvidence) {
1284
+ await readWorkspaceReview(join(resolveDshHome(), "dsh-bot-proactive"), work);
1285
+ return;
1286
+ }
1287
+ if (!(await verifySavedArtifact(join(resolveDshHome(), "dsh-bot-proactive"), work).catch(() => false)))
1288
+ throw new Error("Group repair evidence changed");
1289
+ }
1290
+ async verifyGroupDispatch(work, groupReviewDigest, groupFactId) {
1291
+ this.#feedStop.signal.throwIfAborted();
1292
+ if (groupFactId && !this.config.proactiveGroupFollowUpEnabled)
1293
+ throw new Error("Group follow-up disabled");
1294
+ await this.validateTarget(work.target);
1295
+ const storeId = this.#storeId;
1296
+ const permitted = storeId
1297
+ ? await this.#client?.request({
1298
+ kind: "dispatch-permitted",
1299
+ storeId,
1300
+ assignmentId: work.assignmentId,
1301
+ groupReviewDigest,
1302
+ ...(groupFactId ? { groupFactId } : {}),
1303
+ })
1304
+ : undefined;
1305
+ if (permitted?.kind !== "dispatch-permitted" || !permitted.permitted)
1306
+ throw new Error("Group review withdrawn");
1307
+ }
1308
+ scheduleGroupFollowUps() {
1309
+ const groups = this.ctx.get("dshBotGroups");
1310
+ if (this.scopeOnly ||
1311
+ !this.config.proactiveGroupReviewEnabled ||
1312
+ !this.config.proactiveGroupFollowUpEnabled ||
1313
+ this.#state !== "ready" ||
1314
+ !groups ||
1315
+ this.#feedStop.signal.aborted)
1316
+ return;
1317
+ void this.#groupFollowUpQueue
1318
+ .run(async () => {
1319
+ const storeId = this.#storeId;
1320
+ if (!storeId || this.#feedStop.signal.aborted)
1321
+ return;
1322
+ const reply = await this.#client?.request({
1323
+ kind: "group-follow-ups",
1324
+ storeId,
1325
+ });
1326
+ if (reply?.kind !== "group-follow-ups")
1327
+ return;
1328
+ for (const candidate of reply.candidates) {
1329
+ if (this.#feedStop.signal.aborted)
1330
+ break;
1331
+ await this.dispatchGroupFollowUp(groups, candidate).catch(() => {
1332
+ this.ctx.logger.warn("[dsh-bot] proactive group follow-up unavailable");
1333
+ });
1334
+ }
1335
+ })
1336
+ .catch(() => this.ctx.logger.warn("[dsh-bot] proactive group follow-up unavailable"));
1337
+ }
1338
+ async dispatchGroupFollowUp(groups, { work, fact }) {
1339
+ const review = work.groupReview, grant = review?.followUp;
1340
+ if (review?.state !== "linked" ||
1341
+ !review.turnId ||
1342
+ grant?.state !== "armed")
1343
+ return;
1344
+ const request = {
1345
+ ticketId: work.ticketId,
1346
+ expectedRevision: work.revision,
1347
+ };
1348
+ const view = await groups.view(review.group).catch(() => undefined);
1349
+ const parent = view?.turns.find((turn) => turn.id === review.turnId);
1350
+ const member = view?.members.find((row) => row.id === grant.memberId);
1351
+ const bot = await this.ctx.dshBots
1352
+ .get(grant.bot.botId)
1353
+ .catch(() => undefined);
1354
+ if (!view ||
1355
+ view.reason ||
1356
+ view.group.archived ||
1357
+ view.unavailableMemberIds.length ||
1358
+ view.group.membershipRevision !== grant.membershipRevision ||
1359
+ !member?.enabled ||
1360
+ member.removedAt !== undefined ||
1361
+ !sameBot(member.bot, grant.bot) ||
1362
+ !bot ||
1363
+ bot.createdAt !== grant.bot.botCreatedAt ||
1364
+ bot.updatedAt !== grant.botRevision) {
1365
+ await this.change(randomUUID(), {
1366
+ ...request,
1367
+ kind: "deny-group-follow-up",
1368
+ });
1369
+ return;
1370
+ }
1371
+ if (parent && ["accepted", "running"].includes(parent.state))
1372
+ return;
1373
+ if (!parent ||
1374
+ !["completed", "partial"].includes(parent.state) ||
1375
+ !view.deliveries.some((row) => row.turnId === parent.id &&
1376
+ row.memberId === grant.memberId &&
1377
+ row.state === "completed")) {
1378
+ await this.change(randomUUID(), {
1379
+ ...request,
1380
+ kind: "deny-group-follow-up",
1381
+ });
1382
+ return;
1383
+ }
1384
+ await this.validateTarget(work.target);
1385
+ this.#feedStop.signal.throwIfAborted();
1386
+ const claim = await this.change(randomUUID(), {
1387
+ ...request,
1388
+ kind: "claim-group-follow-up",
1389
+ factId: fact.id,
1390
+ });
1391
+ if (claim.kind !== "receipt")
1392
+ return;
1393
+ const grantedReply = await this.read({
1394
+ kind: "work-ticket",
1395
+ ticketId: work.ticketId,
1396
+ });
1397
+ const grantedWork = grantedReply.kind === "work" ? grantedReply.work : null;
1398
+ if (!grantedWork || grantedWork.assignmentId !== work.assignmentId)
1399
+ throw new Error("Follow-up grant changed");
1400
+ const budget = grantedWork.groupReview?.followUp?.budget;
1401
+ if (work.responsibility && !budget)
1402
+ throw new Error("Group task budget missing");
1403
+ const turn = await groups
1404
+ .startProactiveReview(review.group, {
1405
+ operationId: `proactive-follow-up:${work.assignmentId}`,
1406
+ expectedMembershipRevision: grant.membershipRevision,
1407
+ text: fact.text,
1408
+ memberIds: [grant.memberId],
1409
+ }, {
1410
+ ticketId: work.ticketId,
1411
+ assignmentId: work.assignmentId,
1412
+ provider: work.target.provider,
1413
+ model: work.target.model,
1414
+ botRevisions: [grant.botRevision],
1415
+ ...(grant.modelSelection ? { memberModels: [{ memberId: grant.memberId, modelSelection: grant.modelSelection }], modelRevision: grant.modelRevision } : {}),
1416
+ ...(budget
1417
+ ? {
1418
+ requestBudget: {
1419
+ maxTokens: budget.perCallTokens,
1420
+ outputTokens: Math.min(this.modelOutputTokens, Math.floor(budget.perCallTokens / 2)),
1421
+ deadlineAt: budget.deadlineAt,
1422
+ },
1423
+ }
1424
+ : {}),
1425
+ followUp: { predecessorTurnId: parent.id, factId: fact.id },
1426
+ }, () => this.verifyGroupDispatch(work, review.digest, fact.id))
1427
+ .catch(() => undefined);
1428
+ await this.change(randomUUID(), {
1429
+ kind: "settle-group-follow-up",
1430
+ ticketId: work.ticketId,
1431
+ expectedRevision: work.revision + 1,
1432
+ factId: fact.id,
1433
+ ...(turn ? { turnId: turn.id } : {}),
1434
+ });
1435
+ if (turn && budget)
1436
+ void this.groupBudgets
1437
+ .settle(grantedWork, turn.id, [grant.memberId], "follow-up")
1438
+ .catch(() => this.ctx.logger.warn("[dsh-bot] group follow-up budget awaits reconciliation"));
1439
+ }
1440
+ async externalNotice(input) {
1441
+ const policyId = this.config.proactiveExternalNotificationPolicy;
1442
+ const notices = this.ctx.get("dshBotNotifications");
1443
+ if (!policyId || !notices?.supported())
1444
+ throw new Error("External notice unavailable");
1445
+ const read = async () => {
1446
+ const status = await this.status();
1447
+ if (status.state !== "ready" || status.snapshot?.executionControl.paused)
1448
+ throw new Error("Proactive work is paused");
1449
+ const reply = await this.readWork({
1450
+ kind: "work-ticket",
1451
+ ticketId: input.ticketId,
1452
+ });
1453
+ const work = reply.kind === "work" ? reply.work : null;
1454
+ const sessionId = work?.sessionId ?? work?.groupRepair?.rootSessionId;
1455
+ if (work?.state !== "accepted" || work.document ||
1456
+ work.revision !== input.expectedRevision ||
1457
+ !sessionId ||
1458
+ Date.parse(work.expiresAt) <= Date.now())
1459
+ throw new Error("External notice review is stale");
1460
+ const storeId = this.#storeId;
1461
+ const permitted = storeId
1462
+ ? await this.#client?.request({
1463
+ kind: "dispatch-permitted",
1464
+ storeId,
1465
+ assignmentId: work.assignmentId,
1466
+ noticeRevision: work.revision,
1467
+ })
1468
+ : undefined;
1469
+ if (permitted?.kind !== "dispatch-permitted" || !permitted.permitted)
1470
+ throw new Error("External notice authorization withdrawn");
1471
+ this.validateTarget(work.target);
1472
+ return { work, sessionId };
1473
+ };
1474
+ const { work, sessionId } = await read();
1475
+ const signal = AbortSignal.any([
1476
+ this.#feedStop.signal,
1477
+ AbortSignal.timeout(30000),
1478
+ ]);
1479
+ const operationId = `proactive-external:${work.assignmentId}`;
1480
+ const check = async () => {
1481
+ await read();
1482
+ };
1483
+ await notices.record(work.target.bot, { operationId, policyId, text: work.title, relatedId: work.ticketId }, { kind: "proactive-review", id: work.assignmentId, sessionId }, signal, check);
1484
+ const preview = await notices.previewReviewed(operationId);
1485
+ if (input.reviewedDigest === undefined)
1486
+ return preview;
1487
+ if (preview.digest !== input.reviewedDigest)
1488
+ throw new Error("External notice changed");
1489
+ const result = await notices.deliverReviewed(operationId, input.reviewedDigest, signal, check);
1490
+ return { ...preview, state: result.state };
1491
+ }
1492
+ async verifyDispatch(work, options) {
1493
+ const storeId = this.#storeId;
1494
+ if (!storeId || !this.#client?.available)
1495
+ throw new Error("Proactive execution unavailable");
1496
+ const current = await this.#client.request({
1497
+ kind: "dispatch-permitted",
1498
+ assignmentId: work.assignmentId,
1499
+ dispatchRevision: options.dispatchRevision,
1500
+ storeId,
1501
+ });
1502
+ if (current.kind !== "dispatch-permitted" || !current.permitted)
1503
+ throw new Error("Proactive dispatch withdrawn");
1504
+ if (options.groupAlreadyValidated) {
1505
+ if (work.groupRepair &&
1506
+ (!this.config.proactiveGroupRepairEnabled ||
1507
+ work.workspaceRepair?.executor !== "native"))
1508
+ throw new Error("Group repair unavailable");
1509
+ }
1510
+ else
1511
+ await this.validateGroupRepair(work);
1512
+ this.validateTarget(work.target);
1513
+ if (work.repair)
1514
+ this.repairConfiguration(work.repair, work.sourceId);
1515
+ if (work.workspaceRepair)
1516
+ this.workspaceConfiguration(work.workspaceRepair, work.sourceId);
1517
+ if (work.autoRuleId &&
1518
+ (!this.config.proactiveAutoCiRule ||
1519
+ Date.parse(this.config.proactiveAutoCiRule.expiresAt) <= Date.now()))
1520
+ throw new Error("Proactive automatic rule expired");
1521
+ }
1522
+ async pause(commandId, input) {
1523
+ const active = input.paused
1524
+ ? (await this.workList()).filter((row) => ["pending", "claimed", "sent"].includes(row.state))
1525
+ : [];
1526
+ const reply = await this.change(commandId, {
1527
+ ...input,
1528
+ kind: "pause-execution",
1529
+ });
1530
+ if (reply.kind === "receipt" && input.paused) {
1531
+ await Promise.all(active.map((row) => this.drainExecution(row.ticketId, row.assignmentId)));
1532
+ this.ctx.get("dshBotGroups")?.stopProactiveReviews();
1533
+ }
1534
+ if (reply.kind === "receipt" && !input.paused)
1535
+ this.scheduleGroupFollowUps();
1536
+ return reply;
1537
+ }
1538
+ async cancel(commandId, input) {
1539
+ const before = await this.read({
1540
+ kind: "work-ticket",
1541
+ ticketId: input.ticketId,
1542
+ });
1543
+ const row = before.kind === "work" ? before.work : null;
1544
+ const reply = await this.change(commandId, { ...input, kind: "cancel" });
1545
+ if (reply.kind === "unknown" && row?.revision === input.expectedRevision)
1546
+ this.execution.cancel(row.ticketId, row.assignmentId);
1547
+ if (reply.kind === "receipt" &&
1548
+ row &&
1549
+ (reply.receipt.status === "committed" ||
1550
+ (row.revision === input.expectedRevision + 1 &&
1551
+ ["cancelled", "unknown"].includes(row.state))))
1552
+ await this.drainExecution(row.ticketId, row.assignmentId);
1553
+ return reply;
1554
+ }
1555
+ async drainExecution(ticketId, assignmentId) {
1556
+ if (!(await this.execution.cancelAndDrain(ticketId, assignmentId)))
1557
+ return;
1558
+ const response = await this.read({ kind: "work-assignment", assignmentId });
1559
+ const row = response.kind === "work" ? response.work : null;
1560
+ if (row?.responsibility &&
1561
+ ["cancelled", "unknown", "denied", "failed"].includes(row.state))
1562
+ await this.change(randomUUID(), {
1563
+ kind: "execution-drained",
1564
+ ticketId,
1565
+ assignmentId,
1566
+ expectedRevision: row.revision,
1567
+ });
1568
+ }
1569
+ async review(commandId, input) {
1570
+ if (input.review === "rework" && !this.directRoute)
1571
+ return { kind: "rejected", code: "forbidden" };
1572
+ if (input.review === "rework" && !workspaceExecutionAvailable) {
1573
+ const current = await this.readWork({
1574
+ kind: "work-ticket",
1575
+ ticketId: input.ticketId,
1576
+ });
1577
+ if (current.kind === "work" && current.work?.workspaceRepair)
1578
+ return { kind: "rejected", code: "forbidden" };
1579
+ }
1580
+ if (input.review === "accept") {
1581
+ const previous = await this.receipt(commandId);
1582
+ if (previous.kind === "receipt" && previous.receipt)
1583
+ return this.change(commandId, { ...input, kind: "review" });
1584
+ const result = await this.readWork({
1585
+ kind: "work-ticket",
1586
+ ticketId: input.ticketId,
1587
+ });
1588
+ const row = result.kind === "work" ? result.work : null;
1589
+ if (!row)
1590
+ return { kind: "rejected", code: "stale" };
1591
+ if (row.groupRepair &&
1592
+ !(await verifyGroupRepairEvidence(this.ctx, join(resolveDshHome(), "dsh-bot-proactive"), row).catch(() => false)))
1593
+ return { kind: "rejected", code: "stale" };
1594
+ if (row.workspaceRepair &&
1595
+ !(await readWorkspaceReview(join(resolveDshHome(), "dsh-bot-proactive"), row).catch(() => undefined)))
1596
+ return { kind: "rejected", code: "stale" };
1597
+ if (row?.repair &&
1598
+ !(await verifySavedArtifact(join(resolveDshHome(), "dsh-bot-proactive"), row).catch(() => false)))
1599
+ return { kind: "rejected", code: "stale" };
1600
+ }
1601
+ const result = await this.change(commandId, { ...input, kind: "review" });
1602
+ if (result.kind === "receipt" && input.review === "accept")
1603
+ this.scheduleGroupFollowUps();
1604
+ if (result.kind === "receipt" &&
1605
+ result.receipt.status === "committed" &&
1606
+ input.review === "rework") {
1607
+ const work = await this.workList().catch(() => []);
1608
+ const current = work.find((item) => item.ticketId === input.ticketId);
1609
+ if (current)
1610
+ this.execution.enqueue(current);
1611
+ }
1612
+ return result;
1613
+ }
1614
+ async close() {
1615
+ this.stopAdmission();
1616
+ const governanceClosed = this.governance.close();
1617
+ await this.#maintenance;
1618
+ await this.#automatic.close();
1619
+ await this.#feed;
1620
+ await this.#groupFollowUpQueue.close();
1621
+ await this.execution.close();
1622
+ await this.#resultJournal?.close();
1623
+ await this.feedbackWorkflow.close();
1624
+ await this.groupBudgets.close();
1625
+ await this.#noticesClosing;
1626
+ await governanceClosed;
1627
+ this.#state = "unavailable";
1628
+ await this.#client?.close(this.#storeId);
1629
+ }
1630
+ }
1631
+ //# sourceMappingURL=service.js.map
1632
+ export const DSH_BOT_MODULE_VERSION = '0.7.0';