charness 4.2.0 → 4.3.1

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 (553) hide show
  1. package/CHANGELOG.md +168 -2
  2. package/DEVELOPMENT.md +58 -10
  3. package/LICENSE +331 -151
  4. package/MIGRATION_3_TO_4.md +8 -5
  5. package/README.md +21 -9
  6. package/SETUP.md +54 -10
  7. package/agent-plugin/README.md +10 -3
  8. package/agent-plugin/skills/charness-delegate-claude/SKILL.md +18 -27
  9. package/agent-plugin/skills/charness-delegate-opencode/SKILL.md +5 -3
  10. package/agent-plugin/skills/charness-orchestration/SKILL.md +62 -16
  11. package/dist/adapters/claudeCliAdapter.d.ts +4 -0
  12. package/dist/adapters/claudeCliAdapter.d.ts.map +1 -1
  13. package/dist/adapters/claudeCliAdapter.js +13 -0
  14. package/dist/adapters/claudeCliAdapter.js.map +1 -1
  15. package/dist/adapters/claudeJsonStreamAdapter.d.ts +136 -10
  16. package/dist/adapters/claudeJsonStreamAdapter.d.ts.map +1 -1
  17. package/dist/adapters/claudeJsonStreamAdapter.js +365 -77
  18. package/dist/adapters/claudeJsonStreamAdapter.js.map +1 -1
  19. package/dist/adapters/createAdapter.d.ts +12 -3
  20. package/dist/adapters/createAdapter.d.ts.map +1 -1
  21. package/dist/adapters/createAdapter.js +39 -13
  22. package/dist/adapters/createAdapter.js.map +1 -1
  23. package/dist/adapters/openCodeAdapter.d.ts +34 -0
  24. package/dist/adapters/openCodeAdapter.d.ts.map +1 -1
  25. package/dist/adapters/openCodeAdapter.js +118 -11
  26. package/dist/adapters/openCodeAdapter.js.map +1 -1
  27. package/dist/apiErrorRetry.d.ts +11 -3
  28. package/dist/apiErrorRetry.d.ts.map +1 -1
  29. package/dist/apiErrorRetry.js +33 -3
  30. package/dist/apiErrorRetry.js.map +1 -1
  31. package/dist/apiRetryKick.d.ts +18 -7
  32. package/dist/apiRetryKick.d.ts.map +1 -1
  33. package/dist/apiRetryKick.js +26 -13
  34. package/dist/apiRetryKick.js.map +1 -1
  35. package/dist/bot.d.ts +2 -6
  36. package/dist/bot.d.ts.map +1 -1
  37. package/dist/bot.js +2055 -653
  38. package/dist/bot.js.map +1 -1
  39. package/dist/cli/claudeProfiles.d.ts +28 -6
  40. package/dist/cli/claudeProfiles.d.ts.map +1 -1
  41. package/dist/cli/claudeProfiles.js +89 -22
  42. package/dist/cli/claudeProfiles.js.map +1 -1
  43. package/dist/cli.d.ts.map +1 -1
  44. package/dist/cli.js +2 -1
  45. package/dist/cli.js.map +1 -1
  46. package/dist/connectors/jira/answerSink.d.ts +102 -7
  47. package/dist/connectors/jira/answerSink.d.ts.map +1 -1
  48. package/dist/connectors/jira/answerSink.js +366 -60
  49. package/dist/connectors/jira/answerSink.js.map +1 -1
  50. package/dist/connectors/jira/answerThreads.d.ts +44 -0
  51. package/dist/connectors/jira/answerThreads.d.ts.map +1 -0
  52. package/dist/connectors/jira/answerThreads.js +85 -0
  53. package/dist/connectors/jira/answerThreads.js.map +1 -0
  54. package/dist/connectors/jira/client.d.ts +67 -2
  55. package/dist/connectors/jira/client.d.ts.map +1 -1
  56. package/dist/connectors/jira/client.js +176 -4
  57. package/dist/connectors/jira/client.js.map +1 -1
  58. package/dist/connectors/jira/config.d.ts +6 -0
  59. package/dist/connectors/jira/config.d.ts.map +1 -1
  60. package/dist/connectors/jira/config.js +14 -1
  61. package/dist/connectors/jira/config.js.map +1 -1
  62. package/dist/connectors/jira/connector.d.ts +19 -0
  63. package/dist/connectors/jira/connector.d.ts.map +1 -1
  64. package/dist/connectors/jira/connector.js +68 -6
  65. package/dist/connectors/jira/connector.js.map +1 -1
  66. package/dist/connectors/jira/contextPreamble.d.ts.map +1 -1
  67. package/dist/connectors/jira/contextPreamble.js +6 -1
  68. package/dist/connectors/jira/contextPreamble.js.map +1 -1
  69. package/dist/connectors/jira/inbound.d.ts +21 -6
  70. package/dist/connectors/jira/inbound.d.ts.map +1 -1
  71. package/dist/connectors/jira/inbound.js +22 -16
  72. package/dist/connectors/jira/inbound.js.map +1 -1
  73. package/dist/connectors/jira/issueBlocks.d.ts +8 -1
  74. package/dist/connectors/jira/issueBlocks.d.ts.map +1 -1
  75. package/dist/connectors/jira/issueBlocks.js +38 -2
  76. package/dist/connectors/jira/issueBlocks.js.map +1 -1
  77. package/dist/connectors/jira/operatorIssue.d.ts +28 -0
  78. package/dist/connectors/jira/operatorIssue.d.ts.map +1 -0
  79. package/dist/connectors/jira/operatorIssue.js +81 -0
  80. package/dist/connectors/jira/operatorIssue.js.map +1 -0
  81. package/dist/connectors/jira/outbound.d.ts +8 -4
  82. package/dist/connectors/jira/outbound.d.ts.map +1 -1
  83. package/dist/connectors/jira/outbound.js +16 -8
  84. package/dist/connectors/jira/outbound.js.map +1 -1
  85. package/dist/connectors/jira/outgoingFileCheck.d.ts +37 -0
  86. package/dist/connectors/jira/outgoingFileCheck.d.ts.map +1 -0
  87. package/dist/connectors/jira/outgoingFileCheck.js +279 -0
  88. package/dist/connectors/jira/outgoingFileCheck.js.map +1 -0
  89. package/dist/connectors/jira/outgoingFiles.d.ts +81 -0
  90. package/dist/connectors/jira/outgoingFiles.d.ts.map +1 -0
  91. package/dist/connectors/jira/outgoingFiles.js +268 -0
  92. package/dist/connectors/jira/outgoingFiles.js.map +1 -0
  93. package/dist/connectors/jira/progressComments.d.ts +69 -0
  94. package/dist/connectors/jira/progressComments.d.ts.map +1 -0
  95. package/dist/connectors/jira/progressComments.js +136 -0
  96. package/dist/connectors/jira/progressComments.js.map +1 -0
  97. package/dist/connectors/jira/prompt.d.ts +5 -1
  98. package/dist/connectors/jira/prompt.d.ts.map +1 -1
  99. package/dist/connectors/jira/prompt.js +23 -3
  100. package/dist/connectors/jira/prompt.js.map +1 -1
  101. package/dist/connectors/jira/promptSpill.js +1 -1
  102. package/dist/connectors/jira/promptSpill.js.map +1 -1
  103. package/dist/connectors/jira/trigger.d.ts +13 -5
  104. package/dist/connectors/jira/trigger.d.ts.map +1 -1
  105. package/dist/connectors/jira/trigger.js +13 -7
  106. package/dist/connectors/jira/trigger.js.map +1 -1
  107. package/dist/connectors/jira/uploadedFiles.d.ts +48 -0
  108. package/dist/connectors/jira/uploadedFiles.d.ts.map +1 -0
  109. package/dist/connectors/jira/uploadedFiles.js +123 -0
  110. package/dist/connectors/jira/uploadedFiles.js.map +1 -0
  111. package/dist/connectors/telegram/commands/backendSwitch.d.ts +9 -1
  112. package/dist/connectors/telegram/commands/backendSwitch.d.ts.map +1 -1
  113. package/dist/connectors/telegram/commands/backendSwitch.js +17 -8
  114. package/dist/connectors/telegram/commands/backendSwitch.js.map +1 -1
  115. package/dist/connectors/telegram/commands/botSkills.d.ts +2 -0
  116. package/dist/connectors/telegram/commands/botSkills.d.ts.map +1 -1
  117. package/dist/connectors/telegram/commands/botSkills.js +17 -2
  118. package/dist/connectors/telegram/commands/botSkills.js.map +1 -1
  119. package/dist/connectors/telegram/commands/claudeAccounts.d.ts +6 -0
  120. package/dist/connectors/telegram/commands/claudeAccounts.d.ts.map +1 -1
  121. package/dist/connectors/telegram/commands/claudeAccounts.js +22 -4
  122. package/dist/connectors/telegram/commands/claudeAccounts.js.map +1 -1
  123. package/dist/connectors/telegram/commands/compaction.d.ts +14 -3
  124. package/dist/connectors/telegram/commands/compaction.d.ts.map +1 -1
  125. package/dist/connectors/telegram/commands/compaction.js +261 -96
  126. package/dist/connectors/telegram/commands/compaction.js.map +1 -1
  127. package/dist/connectors/telegram/commands/limitReminders.d.ts +21 -0
  128. package/dist/connectors/telegram/commands/limitReminders.d.ts.map +1 -0
  129. package/dist/connectors/telegram/commands/limitReminders.js +95 -0
  130. package/dist/connectors/telegram/commands/limitReminders.js.map +1 -0
  131. package/dist/connectors/telegram/commands/limitsBoard.d.ts +4 -0
  132. package/dist/connectors/telegram/commands/limitsBoard.d.ts.map +1 -1
  133. package/dist/connectors/telegram/commands/limitsBoard.js +27 -6
  134. package/dist/connectors/telegram/commands/limitsBoard.js.map +1 -1
  135. package/dist/connectors/telegram/commands/modelProviders.d.ts +2 -2
  136. package/dist/connectors/telegram/commands/modelProviders.d.ts.map +1 -1
  137. package/dist/connectors/telegram/commands/modelProviders.js +27 -16
  138. package/dist/connectors/telegram/commands/modelProviders.js.map +1 -1
  139. package/dist/connectors/telegram/commands/topicCommand.d.ts.map +1 -1
  140. package/dist/connectors/telegram/commands/topicCommand.js +7 -2
  141. package/dist/connectors/telegram/commands/topicCommand.js.map +1 -1
  142. package/dist/connectors/telegram/commands/workerRoles.d.ts +25 -0
  143. package/dist/connectors/telegram/commands/workerRoles.d.ts.map +1 -0
  144. package/dist/connectors/telegram/commands/workerRoles.js +259 -0
  145. package/dist/connectors/telegram/commands/workerRoles.js.map +1 -0
  146. package/dist/connectors/telegram/groupWelcome.d.ts +12 -0
  147. package/dist/connectors/telegram/groupWelcome.d.ts.map +1 -0
  148. package/dist/connectors/telegram/groupWelcome.js +12 -0
  149. package/dist/connectors/telegram/groupWelcome.js.map +1 -0
  150. package/dist/connectors/telegram/inbound.d.ts +7 -0
  151. package/dist/connectors/telegram/inbound.d.ts.map +1 -1
  152. package/dist/connectors/telegram/inbound.js +10 -0
  153. package/dist/connectors/telegram/inbound.js.map +1 -1
  154. package/dist/connectors/telegram/outputFlushPlan.d.ts +12 -0
  155. package/dist/connectors/telegram/outputFlushPlan.d.ts.map +1 -1
  156. package/dist/connectors/telegram/outputFlushPlan.js +12 -0
  157. package/dist/connectors/telegram/outputFlushPlan.js.map +1 -1
  158. package/dist/connectors/telegram/runnerPairingMessages.d.ts +1 -1
  159. package/dist/connectors/telegram/topicIndicator.d.ts +1 -1
  160. package/dist/connectors/telegram/topicIndicator.d.ts.map +1 -1
  161. package/dist/connectors/telegram/topicIndicator.js +103 -5
  162. package/dist/connectors/telegram/topicIndicator.js.map +1 -1
  163. package/dist/effortLevels.d.ts +6 -0
  164. package/dist/effortLevels.d.ts.map +1 -1
  165. package/dist/effortLevels.js +6 -1
  166. package/dist/effortLevels.js.map +1 -1
  167. package/dist/i18n/de.d.ts.map +1 -1
  168. package/dist/i18n/de.js +95 -14
  169. package/dist/i18n/de.js.map +1 -1
  170. package/dist/i18n/en.d.ts.map +1 -1
  171. package/dist/i18n/en.js +95 -14
  172. package/dist/i18n/en.js.map +1 -1
  173. package/dist/i18n/es.d.ts.map +1 -1
  174. package/dist/i18n/es.js +95 -14
  175. package/dist/i18n/es.js.map +1 -1
  176. package/dist/i18n/fr.d.ts.map +1 -1
  177. package/dist/i18n/fr.js +95 -14
  178. package/dist/i18n/fr.js.map +1 -1
  179. package/dist/i18n/hi.d.ts.map +1 -1
  180. package/dist/i18n/hi.js +95 -14
  181. package/dist/i18n/hi.js.map +1 -1
  182. package/dist/i18n/ja.d.ts.map +1 -1
  183. package/dist/i18n/ja.js +95 -14
  184. package/dist/i18n/ja.js.map +1 -1
  185. package/dist/i18n/ka.d.ts.map +1 -1
  186. package/dist/i18n/ka.js +95 -14
  187. package/dist/i18n/ka.js.map +1 -1
  188. package/dist/i18n/pt.d.ts.map +1 -1
  189. package/dist/i18n/pt.js +95 -14
  190. package/dist/i18n/pt.js.map +1 -1
  191. package/dist/i18n/ru.d.ts.map +1 -1
  192. package/dist/i18n/ru.js +95 -14
  193. package/dist/i18n/ru.js.map +1 -1
  194. package/dist/i18n/uk.d.ts.map +1 -1
  195. package/dist/i18n/uk.js +95 -14
  196. package/dist/i18n/uk.js.map +1 -1
  197. package/dist/i18n/uz.d.ts.map +1 -1
  198. package/dist/i18n/uz.js +95 -14
  199. package/dist/i18n/uz.js.map +1 -1
  200. package/dist/i18n/zh.d.ts.map +1 -1
  201. package/dist/i18n/zh.js +95 -14
  202. package/dist/i18n/zh.js.map +1 -1
  203. package/dist/instanceSettings.d.ts +24 -2
  204. package/dist/instanceSettings.d.ts.map +1 -1
  205. package/dist/instanceSettings.js +75 -3
  206. package/dist/instanceSettings.js.map +1 -1
  207. package/dist/limitNotes/engine.d.ts +47 -0
  208. package/dist/limitNotes/engine.d.ts.map +1 -0
  209. package/dist/limitNotes/engine.js +98 -0
  210. package/dist/limitNotes/engine.js.map +1 -0
  211. package/dist/limitNotes/noteText.d.ts +33 -0
  212. package/dist/limitNotes/noteText.d.ts.map +1 -0
  213. package/dist/limitNotes/noteText.js +55 -0
  214. package/dist/limitNotes/noteText.js.map +1 -0
  215. package/dist/limitNotes/plan.d.ts +147 -0
  216. package/dist/limitNotes/plan.d.ts.map +1 -0
  217. package/dist/limitNotes/plan.js +323 -0
  218. package/dist/limitNotes/plan.js.map +1 -0
  219. package/dist/limitNotes/reminderChoices.d.ts +30 -0
  220. package/dist/limitNotes/reminderChoices.d.ts.map +1 -0
  221. package/dist/limitNotes/reminderChoices.js +48 -0
  222. package/dist/limitNotes/reminderChoices.js.map +1 -0
  223. package/dist/limitNotes/service.d.ts +106 -0
  224. package/dist/limitNotes/service.d.ts.map +1 -0
  225. package/dist/limitNotes/service.js +169 -0
  226. package/dist/limitNotes/service.js.map +1 -0
  227. package/dist/openCodeSessionTitle.js +1 -1
  228. package/dist/openCodeSessionTitle.js.map +1 -1
  229. package/dist/outputTrace.d.ts +19 -0
  230. package/dist/outputTrace.d.ts.map +1 -1
  231. package/dist/outputTrace.js +23 -2
  232. package/dist/outputTrace.js.map +1 -1
  233. package/dist/platform/answerSink.d.ts +23 -0
  234. package/dist/platform/answerSink.d.ts.map +1 -1
  235. package/dist/platform/answerSink.js.map +1 -1
  236. package/dist/platform/operatorAlert.d.ts +24 -0
  237. package/dist/platform/operatorAlert.d.ts.map +1 -0
  238. package/dist/platform/operatorAlert.js +9 -0
  239. package/dist/platform/operatorAlert.js.map +1 -0
  240. package/dist/postToSession.d.ts +34 -2
  241. package/dist/postToSession.d.ts.map +1 -1
  242. package/dist/postToSession.js +31 -2
  243. package/dist/postToSession.js.map +1 -1
  244. package/dist/remoteRun/exitCodes.d.ts +2 -2
  245. package/dist/remoteRun/exitCodes.d.ts.map +1 -1
  246. package/dist/remoteRun/exitCodes.js +2 -2
  247. package/dist/remoteRun/exitCodes.js.map +1 -1
  248. package/dist/remoteRun/foreground.d.ts.map +1 -1
  249. package/dist/remoteRun/foreground.js +5 -1
  250. package/dist/remoteRun/foreground.js.map +1 -1
  251. package/dist/remoteRun/runnerClient.d.ts +1 -1
  252. package/dist/remoteRun/runnerClient.d.ts.map +1 -1
  253. package/dist/remoteRun/runnerClient.js +3 -3
  254. package/dist/remoteRun/runnerClient.js.map +1 -1
  255. package/dist/requests/answerRequest.d.ts +3 -0
  256. package/dist/requests/answerRequest.d.ts.map +1 -1
  257. package/dist/requests/answerRequest.js +9 -2
  258. package/dist/requests/answerRequest.js.map +1 -1
  259. package/dist/requests/limitWaitAnswer.d.ts +14 -0
  260. package/dist/requests/limitWaitAnswer.d.ts.map +1 -1
  261. package/dist/requests/limitWaitAnswer.js +26 -4
  262. package/dist/requests/limitWaitAnswer.js.map +1 -1
  263. package/dist/requests/requestHeader.d.ts +37 -5
  264. package/dist/requests/requestHeader.d.ts.map +1 -1
  265. package/dist/requests/requestHeader.js +70 -17
  266. package/dist/requests/requestHeader.js.map +1 -1
  267. package/dist/requests/scheduleWait.d.ts +79 -0
  268. package/dist/requests/scheduleWait.d.ts.map +1 -0
  269. package/dist/requests/scheduleWait.js +101 -0
  270. package/dist/requests/scheduleWait.js.map +1 -0
  271. package/dist/requests/sessionTurnProbe.d.ts +26 -3
  272. package/dist/requests/sessionTurnProbe.d.ts.map +1 -1
  273. package/dist/requests/sessionTurnProbe.js +22 -3
  274. package/dist/requests/sessionTurnProbe.js.map +1 -1
  275. package/dist/requests/topicRequestSettle.d.ts +13 -7
  276. package/dist/requests/topicRequestSettle.d.ts.map +1 -1
  277. package/dist/requests/topicRequestSettle.js +2 -2
  278. package/dist/requests/topicRequestSettle.js.map +1 -1
  279. package/dist/requests/trackerTurnPoster.d.ts +30 -0
  280. package/dist/requests/trackerTurnPoster.d.ts.map +1 -0
  281. package/dist/requests/trackerTurnPoster.js +36 -0
  282. package/dist/requests/trackerTurnPoster.js.map +1 -0
  283. package/dist/requests/types.d.ts +26 -5
  284. package/dist/requests/types.d.ts.map +1 -1
  285. package/dist/requests/wakeUpEngine.d.ts +201 -12
  286. package/dist/requests/wakeUpEngine.d.ts.map +1 -1
  287. package/dist/requests/wakeUpEngine.js +514 -44
  288. package/dist/requests/wakeUpEngine.js.map +1 -1
  289. package/dist/requests/wakeUpRules.d.ts +185 -14
  290. package/dist/requests/wakeUpRules.d.ts.map +1 -1
  291. package/dist/requests/wakeUpRules.js +169 -36
  292. package/dist/requests/wakeUpRules.js.map +1 -1
  293. package/dist/resumeContext.d.ts +2 -2
  294. package/dist/resumeContext.js +3 -3
  295. package/dist/resumeContext.js.map +1 -1
  296. package/dist/runnerUtility/adminService.js +1 -1
  297. package/dist/runnerUtility/adminService.js.map +1 -1
  298. package/dist/runnerUtility/guiAgent.d.ts +1 -1
  299. package/dist/runnerUtility/guiAgent.d.ts.map +1 -1
  300. package/dist/runnerUtility/guiAgent.js +1 -1
  301. package/dist/runnerUtility/guiAgent.js.map +1 -1
  302. package/dist/runnerUtility/managedNode.d.ts +3 -3
  303. package/dist/runnerUtility/managedNode.d.ts.map +1 -1
  304. package/dist/runnerUtility/managedNode.js +2 -2
  305. package/dist/runnerUtility/managedNode.js.map +1 -1
  306. package/dist/runnerUtility/runnerConfig.d.ts +1 -1
  307. package/dist/runnerUtility/runnerHome.d.ts +1 -1
  308. package/dist/runnerUtility/runnerHome.js +1 -1
  309. package/dist/runnerUtility/serviceCommon.d.ts +1 -1
  310. package/dist/runnerUtility/serviceCommon.d.ts.map +1 -1
  311. package/dist/runnerUtility/serviceCommon.js +1 -1
  312. package/dist/runnerUtility/serviceCommon.js.map +1 -1
  313. package/dist/runners/bootstrapLine.js +1 -1
  314. package/dist/runners/hubPackage.d.ts +1 -1
  315. package/dist/runners/hubPackage.js +3 -3
  316. package/dist/runners/hubPackage.js.map +1 -1
  317. package/dist/runners/hubPaths.d.ts +1 -1
  318. package/dist/runners/hubPaths.d.ts.map +1 -1
  319. package/dist/runners/runnerLock.d.ts +2 -2
  320. package/dist/runners/runnerLock.d.ts.map +1 -1
  321. package/dist/runners/runnerLock.js +2 -2
  322. package/dist/runners/runnerLock.js.map +1 -1
  323. package/dist/scheduler/checkRun.d.ts +2 -0
  324. package/dist/scheduler/checkRun.d.ts.map +1 -1
  325. package/dist/scheduler/checkRun.js +5 -1
  326. package/dist/scheduler/checkRun.js.map +1 -1
  327. package/dist/scheduler/delivery.d.ts +57 -0
  328. package/dist/scheduler/delivery.d.ts.map +1 -1
  329. package/dist/scheduler/delivery.js +152 -14
  330. package/dist/scheduler/delivery.js.map +1 -1
  331. package/dist/scheduler/injection.d.ts +6 -0
  332. package/dist/scheduler/injection.d.ts.map +1 -1
  333. package/dist/scheduler/injection.js +10 -0
  334. package/dist/scheduler/injection.js.map +1 -1
  335. package/dist/scheduler/mcpSurface.d.ts +68 -4
  336. package/dist/scheduler/mcpSurface.d.ts.map +1 -1
  337. package/dist/scheduler/mcpSurface.js +363 -189
  338. package/dist/scheduler/mcpSurface.js.map +1 -1
  339. package/dist/scheduler/rebindResume.d.ts +24 -0
  340. package/dist/scheduler/rebindResume.d.ts.map +1 -1
  341. package/dist/scheduler/rebindResume.js +32 -0
  342. package/dist/scheduler/rebindResume.js.map +1 -1
  343. package/dist/scheduler/scheduleToolWording.d.ts +29 -0
  344. package/dist/scheduler/scheduleToolWording.d.ts.map +1 -0
  345. package/dist/scheduler/scheduleToolWording.js +117 -0
  346. package/dist/scheduler/scheduleToolWording.js.map +1 -0
  347. package/dist/scheduler/scheduledRunTarget.d.ts +90 -0
  348. package/dist/scheduler/scheduledRunTarget.d.ts.map +1 -0
  349. package/dist/scheduler/scheduledRunTarget.js +92 -0
  350. package/dist/scheduler/scheduledRunTarget.js.map +1 -0
  351. package/dist/scheduler/store.d.ts +2 -0
  352. package/dist/scheduler/store.d.ts.map +1 -1
  353. package/dist/scheduler/store.js +2 -0
  354. package/dist/scheduler/store.js.map +1 -1
  355. package/dist/scheduler/types.d.ts +10 -0
  356. package/dist/scheduler/types.d.ts.map +1 -1
  357. package/dist/scheduler/workerWatch.d.ts +2 -0
  358. package/dist/scheduler/workerWatch.d.ts.map +1 -1
  359. package/dist/scheduler/workerWatch.js +3 -3
  360. package/dist/scheduler/workerWatch.js.map +1 -1
  361. package/dist/selfUpdate/constants.d.ts +2 -0
  362. package/dist/selfUpdate/constants.d.ts.map +1 -1
  363. package/dist/selfUpdate/constants.js +3 -1
  364. package/dist/selfUpdate/constants.js.map +1 -1
  365. package/dist/selfUpdate/emittedSource.d.ts.map +1 -1
  366. package/dist/selfUpdate/emittedSource.js +1 -1
  367. package/dist/selfUpdate/emittedSource.js.map +1 -1
  368. package/dist/selfUpdate/updateRuntime.js +1 -1
  369. package/dist/selfUpdate/updateRuntime.js.map +1 -1
  370. package/dist/sessionPick.d.ts +1 -1
  371. package/dist/sessionPick.js +1 -1
  372. package/dist/shutdown.d.ts +12 -0
  373. package/dist/shutdown.d.ts.map +1 -1
  374. package/dist/shutdown.js +11 -0
  375. package/dist/shutdown.js.map +1 -1
  376. package/dist/startupPromptBuffer.d.ts +35 -6
  377. package/dist/startupPromptBuffer.d.ts.map +1 -1
  378. package/dist/startupPromptBuffer.js +70 -21
  379. package/dist/startupPromptBuffer.js.map +1 -1
  380. package/dist/state.d.ts +173 -25
  381. package/dist/state.d.ts.map +1 -1
  382. package/dist/state.js +282 -58
  383. package/dist/state.js.map +1 -1
  384. package/dist/testTimings.d.ts +8 -3
  385. package/dist/testTimings.d.ts.map +1 -1
  386. package/dist/testTimings.js +15 -2
  387. package/dist/testTimings.js.map +1 -1
  388. package/dist/threadContextPreamble.d.ts +7 -0
  389. package/dist/threadContextPreamble.d.ts.map +1 -1
  390. package/dist/threadContextPreamble.js +11 -0
  391. package/dist/threadContextPreamble.js.map +1 -1
  392. package/dist/threadRouting.d.ts +12 -0
  393. package/dist/threadRouting.d.ts.map +1 -1
  394. package/dist/threadRouting.js +15 -0
  395. package/dist/threadRouting.js.map +1 -1
  396. package/dist/todos/midTurn.d.ts +15 -41
  397. package/dist/todos/midTurn.d.ts.map +1 -1
  398. package/dist/todos/midTurn.js +27 -171
  399. package/dist/todos/midTurn.js.map +1 -1
  400. package/dist/types.d.ts +147 -23
  401. package/dist/types.d.ts.map +1 -1
  402. package/dist/types.js +10 -0
  403. package/dist/types.js.map +1 -1
  404. package/dist/utils/backendSwitchPlan.d.ts +3 -3
  405. package/dist/utils/backendSwitchPlan.js +3 -3
  406. package/dist/utils/claudeAccountAlert.d.ts +104 -0
  407. package/dist/utils/claudeAccountAlert.d.ts.map +1 -0
  408. package/dist/utils/claudeAccountAlert.js +130 -0
  409. package/dist/utils/claudeAccountAlert.js.map +1 -0
  410. package/dist/utils/claudeAccountPickerPlan.d.ts +7 -0
  411. package/dist/utils/claudeAccountPickerPlan.d.ts.map +1 -1
  412. package/dist/utils/claudeAccountPickerPlan.js +13 -2
  413. package/dist/utils/claudeAccountPickerPlan.js.map +1 -1
  414. package/dist/utils/claudeAuthRefusal.d.ts +122 -0
  415. package/dist/utils/claudeAuthRefusal.d.ts.map +1 -0
  416. package/dist/utils/claudeAuthRefusal.js +228 -0
  417. package/dist/utils/claudeAuthRefusal.js.map +1 -0
  418. package/dist/utils/claudeCompactHook.d.ts +6 -6
  419. package/dist/utils/claudeCompactHook.js +8 -8
  420. package/dist/utils/claudeCompactHook.js.map +1 -1
  421. package/dist/utils/claudeProfileUsageViews.d.ts +54 -2
  422. package/dist/utils/claudeProfileUsageViews.d.ts.map +1 -1
  423. package/dist/utils/claudeProfileUsageViews.js +44 -1
  424. package/dist/utils/claudeProfileUsageViews.js.map +1 -1
  425. package/dist/utils/claudeProfiles.d.ts.map +1 -1
  426. package/dist/utils/claudeProfiles.js +10 -1
  427. package/dist/utils/claudeProfiles.js.map +1 -1
  428. package/dist/utils/claudeRuntimeInfo.d.ts +24 -0
  429. package/dist/utils/claudeRuntimeInfo.d.ts.map +1 -1
  430. package/dist/utils/claudeRuntimeInfo.js +128 -3
  431. package/dist/utils/claudeRuntimeInfo.js.map +1 -1
  432. package/dist/utils/claudeScheduledJobs.d.ts +6 -2
  433. package/dist/utils/claudeScheduledJobs.d.ts.map +1 -1
  434. package/dist/utils/claudeScheduledJobs.js +10 -2
  435. package/dist/utils/claudeScheduledJobs.js.map +1 -1
  436. package/dist/utils/claudeSessionTitle.js +1 -1
  437. package/dist/utils/claudeSessionTitle.js.map +1 -1
  438. package/dist/utils/claudeStreamJson.d.ts +28 -2
  439. package/dist/utils/claudeStreamJson.d.ts.map +1 -1
  440. package/dist/utils/claudeStreamJson.js +33 -3
  441. package/dist/utils/claudeStreamJson.js.map +1 -1
  442. package/dist/utils/claudeTranscriptEpoch.d.ts +14 -0
  443. package/dist/utils/claudeTranscriptEpoch.d.ts.map +1 -1
  444. package/dist/utils/claudeTranscriptEpoch.js +79 -19
  445. package/dist/utils/claudeTranscriptEpoch.js.map +1 -1
  446. package/dist/utils/claudeUsage.d.ts +103 -7
  447. package/dist/utils/claudeUsage.d.ts.map +1 -1
  448. package/dist/utils/claudeUsage.js +108 -15
  449. package/dist/utils/claudeUsage.js.map +1 -1
  450. package/dist/utils/compactOnIdle.d.ts +139 -29
  451. package/dist/utils/compactOnIdle.d.ts.map +1 -1
  452. package/dist/utils/compactOnIdle.js +163 -36
  453. package/dist/utils/compactOnIdle.js.map +1 -1
  454. package/dist/utils/conversationEnding.d.ts +76 -0
  455. package/dist/utils/conversationEnding.d.ts.map +1 -0
  456. package/dist/utils/conversationEnding.js +117 -0
  457. package/dist/utils/conversationEnding.js.map +1 -0
  458. package/dist/utils/doctorLine.d.ts +10 -0
  459. package/dist/utils/doctorLine.d.ts.map +1 -1
  460. package/dist/utils/doctorLine.js +16 -0
  461. package/dist/utils/doctorLine.js.map +1 -1
  462. package/dist/utils/fallbackBridge.d.ts.map +1 -1
  463. package/dist/utils/fallbackBridge.js +2 -1
  464. package/dist/utils/fallbackBridge.js.map +1 -1
  465. package/dist/utils/fallbackChain.d.ts +2 -0
  466. package/dist/utils/fallbackChain.d.ts.map +1 -1
  467. package/dist/utils/fallbackChain.js +4 -3
  468. package/dist/utils/fallbackChain.js.map +1 -1
  469. package/dist/utils/fallbackSwitchNotice.d.ts +11 -4
  470. package/dist/utils/fallbackSwitchNotice.d.ts.map +1 -1
  471. package/dist/utils/fallbackSwitchNotice.js +9 -5
  472. package/dist/utils/fallbackSwitchNotice.js.map +1 -1
  473. package/dist/utils/fileSendService.d.ts +31 -0
  474. package/dist/utils/fileSendService.d.ts.map +1 -1
  475. package/dist/utils/fileSendService.js +45 -2
  476. package/dist/utils/fileSendService.js.map +1 -1
  477. package/dist/utils/jsonStreamHost.d.ts +2 -0
  478. package/dist/utils/jsonStreamHost.d.ts.map +1 -1
  479. package/dist/utils/jsonStreamHost.js +4 -1
  480. package/dist/utils/jsonStreamHost.js.map +1 -1
  481. package/dist/utils/jsonStreamPendingWork.d.ts +14 -2
  482. package/dist/utils/jsonStreamPendingWork.d.ts.map +1 -1
  483. package/dist/utils/jsonStreamPendingWork.js +25 -5
  484. package/dist/utils/jsonStreamPendingWork.js.map +1 -1
  485. package/dist/utils/jsonStreamUnconsumedInput.d.ts +80 -0
  486. package/dist/utils/jsonStreamUnconsumedInput.d.ts.map +1 -0
  487. package/dist/utils/jsonStreamUnconsumedInput.js +99 -0
  488. package/dist/utils/jsonStreamUnconsumedInput.js.map +1 -0
  489. package/dist/utils/limitEpisodeRecovery.d.ts +43 -4
  490. package/dist/utils/limitEpisodeRecovery.d.ts.map +1 -1
  491. package/dist/utils/limitEpisodeRecovery.js +107 -20
  492. package/dist/utils/limitEpisodeRecovery.js.map +1 -1
  493. package/dist/utils/limitHeldPrompts.d.ts +21 -11
  494. package/dist/utils/limitHeldPrompts.d.ts.map +1 -1
  495. package/dist/utils/limitHeldPrompts.js +12 -9
  496. package/dist/utils/limitHeldPrompts.js.map +1 -1
  497. package/dist/utils/limitRemindersScreenPlan.d.ts +63 -0
  498. package/dist/utils/limitRemindersScreenPlan.d.ts.map +1 -0
  499. package/dist/utils/limitRemindersScreenPlan.js +121 -0
  500. package/dist/utils/limitRemindersScreenPlan.js.map +1 -0
  501. package/dist/utils/limitSwitchPlan.d.ts +51 -14
  502. package/dist/utils/limitSwitchPlan.d.ts.map +1 -1
  503. package/dist/utils/limitSwitchPlan.js +33 -15
  504. package/dist/utils/limitSwitchPlan.js.map +1 -1
  505. package/dist/utils/limitsBoardPlan.d.ts +16 -7
  506. package/dist/utils/limitsBoardPlan.d.ts.map +1 -1
  507. package/dist/utils/limitsBoardPlan.js +41 -9
  508. package/dist/utils/limitsBoardPlan.js.map +1 -1
  509. package/dist/utils/lostWork.d.ts +16 -2
  510. package/dist/utils/lostWork.d.ts.map +1 -1
  511. package/dist/utils/lostWork.js +16 -3
  512. package/dist/utils/lostWork.js.map +1 -1
  513. package/dist/utils/messageContext.d.ts +2 -2
  514. package/dist/utils/messageContext.js +2 -2
  515. package/dist/utils/midTurnInbox.d.ts +79 -0
  516. package/dist/utils/midTurnInbox.d.ts.map +1 -0
  517. package/dist/utils/midTurnInbox.js +265 -0
  518. package/dist/utils/midTurnInbox.js.map +1 -0
  519. package/dist/utils/promptDelivery.d.ts +70 -22
  520. package/dist/utils/promptDelivery.d.ts.map +1 -1
  521. package/dist/utils/promptDelivery.js +100 -42
  522. package/dist/utils/promptDelivery.js.map +1 -1
  523. package/dist/utils/topicIndicatorPlan.d.ts +13 -3
  524. package/dist/utils/topicIndicatorPlan.d.ts.map +1 -1
  525. package/dist/utils/topicIndicatorPlan.js +26 -4
  526. package/dist/utils/topicIndicatorPlan.js.map +1 -1
  527. package/dist/utils/topicRequest.d.ts +3 -0
  528. package/dist/utils/topicRequest.d.ts.map +1 -1
  529. package/dist/utils/topicRequest.js +4 -0
  530. package/dist/utils/topicRequest.js.map +1 -1
  531. package/dist/utils/workerRoles.d.ts +122 -0
  532. package/dist/utils/workerRoles.d.ts.map +1 -0
  533. package/dist/utils/workerRoles.js +160 -0
  534. package/dist/utils/workerRoles.js.map +1 -0
  535. package/dist/utils/workerRolesScreenPlan.d.ts +118 -0
  536. package/dist/utils/workerRolesScreenPlan.d.ts.map +1 -0
  537. package/dist/utils/workerRolesScreenPlan.js +232 -0
  538. package/dist/utils/workerRolesScreenPlan.js.map +1 -0
  539. package/dist/utils/workingSignals.d.ts +59 -0
  540. package/dist/utils/workingSignals.d.ts.map +1 -0
  541. package/dist/utils/workingSignals.js +60 -0
  542. package/dist/utils/workingSignals.js.map +1 -0
  543. package/licensing.json +88 -0
  544. package/npm-shrinkwrap.json +2 -2
  545. package/package.json +7 -7
  546. package/{remoteRun → runner-scripts}/runner.sh +6 -3
  547. package/LICENSE-COMMERCIAL.md +0 -142
  548. package/dist/agentTrigger.d.ts +0 -28
  549. package/dist/agentTrigger.d.ts.map +0 -1
  550. package/dist/agentTrigger.js +0 -53
  551. package/dist/agentTrigger.js.map +0 -1
  552. /package/{remoteRun → runner-scripts}/ensureNode.sh +0 -0
  553. /package/{remoteRun → runner-scripts}/runner-package-lock.json +0 -0
@@ -1,13 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jiraQuestionContinueText = exports.jiraReadBackDelayMs = exports.jiraReadBackClockSkewMs = exports.jiraReadBackCommentCount = void 0;
3
+ exports.jiraFilesUnavailableError = exports.jiraQuestionContinueText = exports.jiraReadBackDelayMs = exports.jiraReadBackClockSkewMs = exports.jiraReadBackCommentCount = void 0;
4
4
  exports.buildJiraAlertText = buildJiraAlertText;
5
5
  exports.buildJiraParkText = buildJiraParkText;
6
6
  exports.buildJiraMentionParkText = buildJiraMentionParkText;
7
7
  exports.buildJiraUpdatesPausedText = buildJiraUpdatesPausedText;
8
8
  exports.buildJiraQueuedText = buildJiraQueuedText;
9
9
  exports.buildJiraReplyLeftOutWarning = buildJiraReplyLeftOutWarning;
10
+ exports.buildJiraOtherThreadsWarning = buildJiraOtherThreadsWarning;
11
+ exports.buildJiraThreadRefusedWarning = buildJiraThreadRefusedWarning;
12
+ exports.buildJiraProgressUpdatedText = buildJiraProgressUpdatedText;
13
+ exports.buildJiraProgressClosedText = buildJiraProgressClosedText;
10
14
  exports.buildJiraUntrustedText = buildJiraUntrustedText;
15
+ exports.getOriginThreadRootId = getOriginThreadRootId;
11
16
  exports.createJiraAnswerSink = createJiraAnswerSink;
12
17
  const requestGroup_1 = require("../../requests/requestGroup");
13
18
  const adf_1 = require("./adf");
@@ -16,6 +21,8 @@ const client_1 = require("./client");
16
21
  const unconfirmedPosts_1 = require("./unconfirmedPosts");
17
22
  const trigger_1 = require("./trigger");
18
23
  const issueBlocks_1 = require("./issueBlocks");
24
+ const outgoingFiles_1 = require("./outgoingFiles");
25
+ const progressComments_1 = require("./progressComments");
19
26
  /**
20
27
  * @description The Jira connector's answer sink (plan J6, D20, R18): an answer
21
28
  * becomes one or more comments by the AI account, in order; a `question` or a
@@ -30,6 +37,37 @@ const issueBlocks_1 = require("./issueBlocks");
30
37
  * request, the issue is read first and a comment that did land is not posted
31
38
  * twice. The agent cannot look at the issue itself, so every failure tells it
32
39
  * what to send again. Bot texts on the issue are English (D20).
40
+ *
41
+ * Comment threads: an answer goes into the thread of the first comment it replies to (`replyToCommentIds`), else into
42
+ * the thread the request's latest issue update came from (`answerThreads.ts`: its newest comment was a reply there; the
43
+ * agent's answer delivered uses it up, a notice the bot writes does not), else into the thread its request was opened
44
+ * in (the origin's {@link jiraReplyThreadAttribute}), else it is a top-level comment; the request's alert and the
45
+ * notices about its trigger follow the request's own thread. Jira threads are one level deep, so a reply always names
46
+ * the thread's top-level comment. A thread Jira refuses (400: its comments are gone)
47
+ * gets the comment top-level instead, and the agent is told.
48
+ *
49
+ * Files: an answer's `files` are attached to the issue BEFORE its comment is posted and shown in it, after its text
50
+ * (`outgoingFiles.ts`); a file that cannot be attached fails the answer with nothing posted. `postFiles` is
51
+ * `send_file_to_user` on an issue: the files, and the caption as text, in a comment of their own.
52
+ *
53
+ * One progress comment per request (`progressComments.ts`): the first `progress` answer of a request posts a comment and the sink
54
+ * remembers it (on disk); each next one EDITS it to the newest text, with a line saying when it was last updated, in the thread
55
+ * the first stood in — an edit moves nothing and notifies nobody. A `question` or `final` answer is a new comment as ever, and it
56
+ * closes the progress comments it ends — its request's and those of the requests it replaced, the ones let go earlier (an issue
57
+ * update, a note that was a comment of its own, the alert) included: a line on top says the notes were interim and the answer (or
58
+ * the question) is in a newer comment, so no note still reads as work under way ("pipeline 42 is running now, I'll report when it
59
+ * finishes") once the answer stands below it. The closing comes after the hand-back: it is cosmetic, the hand-back notifies. An edit Jira refuses (the comment is gone, 400, 403), or
60
+ * one of unknown outcome whose read-back shows the old text and whose one repeat does not land, posts the text as a new comment
61
+ * instead (with R18's read-back) and that one is remembered — the text is never lost. An edit of unknown outcome whose comment cannot be read is an error that tells the agent
62
+ * to send it again: nothing is posted, and the resend edits the same comment (a new comment would show the text twice). A progress answer is kept as that one comment only when it is a plain note: it carries no
63
+ * files, replies to no comment (an edit notifies nobody, a reply is meant to) and fits one comment; any other is a comment of its
64
+ * own, like a question, and the progress comment is let go, so the next note starts below it. So is an issue update the request
65
+ * receives (`noteIssueUpdate`, a reply or a top-level comment): what the agent answers to the person is a new comment below theirs
66
+ * — in the thread it asked for — and the notes after it edit that one. The bot's own notice that repeats for a request (`RequestAnswerDelivery.repeatKey`: a
67
+ * usage-limit wait once more) is kept the same way, in a slot of its own — but only for back-to-back repeats: once the agent's own
68
+ * answer is delivered (posted or edited), another bot comment of its own stands below it (an account moved, no account usable, the
69
+ * give-up alert) or an issue update arrives, the notice is let go and the next one is a new comment below; a bot notice without a
70
+ * key is a comment each time.
33
71
  */
34
72
  /** How many of the issue's newest comments R18's read-back looks through. */
35
73
  exports.jiraReadBackCommentCount = 20;
@@ -48,13 +86,20 @@ exports.jiraReadBackDelayMs = 10_000;
48
86
  /** How much of the first unposted part a partial delivery quotes, so the agent can tell where to resend from. */
49
87
  const missingPartPreviewChars = 80;
50
88
  const alertTexts = {
51
- silentTurns: 'the agent ended its turns without answering, and the reminders gave up',
52
- wakeCap: 'the agent was reminded as many times as allowed without answering',
53
- wakeFailed: "the agent's session could not be reached to remind it",
89
+ // Also two turn ends in a row that left the request open with nothing armed (the nudge between them): the agent may have sent
90
+ // progress notes, so «no answer» would be untrue — it left the work without a final answer.
91
+ silentTurns: 'The AI stopped working on this without a final answer, even after it was reminded.',
92
+ wakeCap: 'The AI was reminded as many times as allowed and still gave no answer here.',
93
+ wakeFailed: "The AI's session could not be reached to remind it, so there is no answer here.",
54
94
  };
55
- /** @description The alert comment: which request, why, and that a person is needed (D20). */
56
- function buildJiraAlertText(requestId, reason) {
57
- return `⚠️ The AI could not finish request ${requestId}: ${alertTexts[reason]}. A person needs to look at this issue.`;
95
+ /**
96
+ * @description The alert comment (D20), in words a reader of the issue understands: what happened, and in one line what it means for
97
+ * them — nothing more happens by itself, a person has to look, and how to try again. The request's id stays out of it (the bot's log
98
+ * names it). A turn refused for the AI's Claude account never ends here: the bot says that in words of its own and moves the work, or
99
+ * the work waits for the account (`bot.ts` `handleClaudeAuthRefusal`).
100
+ */
101
+ function buildJiraAlertText(reason) {
102
+ return `⚠️ ${alertTexts[reason]} It will not go on by itself: a person needs to look at this issue. To try again, hand it to the AI again or mention it in a comment.`;
58
103
  }
59
104
  /** @description The park notice (D12): over the run budget, handed back without a new request. Hand-overs and mentions share the budget. */
60
105
  function buildJiraParkText(runBudgetPer24h) {
@@ -94,6 +139,38 @@ function buildJiraReplyLeftOutWarning(commentIds) {
94
139
  return `Delivered, but these comments' authors were not mentioned: ${commentIds.join(', ')}. ` +
95
140
  'Only comments you were shown in this conversation, written by a trusted person, can be replied to this way.';
96
141
  }
142
+ /**
143
+ * @description The warning of an answer that replied to comments in several threads: one answer is one place, so it
144
+ * went into the thread of the first comment it replied to; the others' authors were only mentioned.
145
+ */
146
+ function buildJiraOtherThreadsWarning(threadRootId, commentIds) {
147
+ return `Delivered in the thread of comment ${threadRootId}, but ${commentIds.length === 1 ? 'comment' : 'comments'} ${commentIds.join(', ')} ` +
148
+ `${commentIds.length === 1 ? 'is' : 'are'} in another thread: ${commentIds.length === 1 ? 'its author was' : 'their authors were'} mentioned, ` +
149
+ 'and the answer is not there. To answer in that thread too, send a separate answer that replies to it.';
150
+ }
151
+ /** @description The warning of an answer whose thread Jira refused (its comments are gone): it was posted as a new top-level comment. */
152
+ function buildJiraThreadRefusedWarning(threadRootId) {
153
+ return `The thread of comment ${threadRootId} no longer takes replies (Jira refused it), so the answer was posted as a new comment instead.`;
154
+ }
155
+ /** A moment as the notices tell time: UTC, to the minute. */
156
+ function formatUtcMinute(atMs) {
157
+ return `${new Date(atMs).toISOString().slice(0, 16).replace('T', ' ')} UTC`;
158
+ }
159
+ /** @description The line an edited progress comment ends with: when it was last updated. */
160
+ function buildJiraProgressUpdatedText(atMs) {
161
+ return `Last updated ${formatUtcMinute(atMs)}`;
162
+ }
163
+ const progressDoneMark = '✅ Done';
164
+ const progressPausedMark = '⏸ Paused';
165
+ /**
166
+ * @description The line a progress comment gets on top once its request has its answer (`final`) or asks the requester (`question`):
167
+ * the notes below it were interim, and where to read on.
168
+ */
169
+ function buildJiraProgressClosedText(kind, atMs) {
170
+ return kind === 'final'
171
+ ? `${progressDoneMark} ${formatUtcMinute(atMs)}: these were interim notes, the answer is in a newer comment.`
172
+ : `${progressPausedMark} ${formatUtcMinute(atMs)} for a question: these were interim notes, the question is in a newer comment.`;
173
+ }
97
174
  /** @description The last paragraph of a hand-over's `question` comment: how the requester lets the agent go on. */
98
175
  exports.jiraQuestionContinueText = 'To let me go on, answer in a comment and assign the issue back to me.';
99
176
  /**
@@ -103,6 +180,32 @@ exports.jiraQuestionContinueText = 'To let me go on, answer in a comment and ass
103
180
  function buildJiraUntrustedText(groupName) {
104
181
  return `Only members of the AI's trusted group (${groupName}) can hand it work, so nothing was started. Ask a member to hand it over.`;
105
182
  }
183
+ /** The refusal of files where the sink has no way to attach them. */
184
+ exports.jiraFilesUnavailableError = 'files cannot be attached to a Jira issue on this instance; nothing was posted';
185
+ /** Jira's answer to a reply whose thread it does not have: the request is refused, nothing was posted. */
186
+ const threadRefusedStatus = 400;
187
+ /**
188
+ * The slot an answer is kept in as ONE comment edited by the next such answer, or `null` when it is a comment of its own: only a
189
+ * plain `progress` note — no files, no reply to a comment — and, of the bot's notices, one that carries a repeat key.
190
+ */
191
+ function getEditableSlot(delivery) {
192
+ const isPlain = delivery.kind === 'progress' && (delivery.files?.length ?? 0) === 0 && (delivery.replyToCommentIds?.length ?? 0) === 0;
193
+ if (!isPlain)
194
+ return null;
195
+ if (!delivery.isBotNotice)
196
+ return progressComments_1.jiraProgressSlot;
197
+ return delivery.repeatKey === undefined ? null : (0, progressComments_1.getJiraNoticeSlot)(delivery.repeatKey);
198
+ }
199
+ /** `body` with the line saying when it was last updated as one more paragraph, in italics. */
200
+ function getBodyWithUpdatedLine(body, atMs) {
201
+ const updatedParagraph = { type: 'paragraph', content: [{ type: 'text', text: buildJiraProgressUpdatedText(atMs), marks: [{ type: 'em' }] }] };
202
+ return { ...body, content: [...body.content, updatedParagraph] };
203
+ }
204
+ /** The thread a request's answers go into by default: the origin's {@link jiraReplyThreadAttribute}, when it is a comment id. */
205
+ function getOriginThreadRootId(origin) {
206
+ const threadRootId = origin.attributes[trigger_1.jiraReplyThreadAttribute];
207
+ return threadRootId !== undefined && /^\d+$/.test(threadRootId) ? threadRootId : null;
208
+ }
106
209
  /** A comment's text as the read-back compares it: its plain text, whitespace collapsed. */
107
210
  function getComparableText(body) {
108
211
  return (0, promptText_1.getSingleLineText)((0, adf_1.getAdfText)(body));
@@ -119,13 +222,14 @@ function getBodyWithContinueLine(body) {
119
222
  }
120
223
  function createJiraAnswerSink(deps) {
121
224
  const { client } = deps;
122
- /** Is the comment on the issue, by the AI account, dated from the post's start on? `null` — the issue could not be read. */
123
- async function checkIsCommentOnIssue(issueKey, comparableText, postStartedAt) {
225
+ /** The comment on the issue, by the AI account, dated from the post's start on, with this text: its id; `false` — none; `null` — the issue could not be read. */
226
+ async function findCommentOnIssue(issueKey, comparableText, postStartedAt) {
124
227
  try {
125
228
  const comments = await client.getRecentComments(issueKey, exports.jiraReadBackCommentCount);
126
- return comments.some((comment) => comment.author?.accountId === deps.aiAccountId
229
+ const found = comments.find((comment) => comment.author?.accountId === deps.aiAccountId
127
230
  && Date.parse(comment.created) >= postStartedAt - exports.jiraReadBackClockSkewMs
128
231
  && getComparableText(comment.body) === comparableText);
232
+ return found ? found.id : false;
129
233
  }
130
234
  catch (error) {
131
235
  console.warn(`[jira] ${issueKey}: read-back failed: ${error instanceof Error ? error.message : String(error)}`);
@@ -133,52 +237,127 @@ function createJiraAnswerSink(deps) {
133
237
  }
134
238
  }
135
239
  /**
136
- * Post one comment. With a `requestId`, a post left unconfirmed is remembered,
137
- * and a resend of a remembered one reads the issue first (R29).
240
+ * Post one comment, in the thread of `parentId` (a top-level comment's id) or top-level (`null`). With a
241
+ * `requestId`, a post left unconfirmed is remembered, and a resend of a remembered one reads the issue first (R29).
138
242
  */
139
- async function postComment(issueKey, body, requestId) {
243
+ async function postComment(issueKey, body, requestId, parentId) {
140
244
  const comparableText = getComparableText(body);
141
245
  const bodyHash = (0, unconfirmedPosts_1.getCommentBodyHash)(comparableText);
142
246
  const earlierPostedAt = requestId === null ? null : deps.unconfirmedPosts.getPostedAt(requestId, bodyHash);
143
247
  if (requestId !== null && earlierPostedAt !== null) {
144
- const isEarlierOnIssue = await checkIsCommentOnIssue(issueKey, comparableText, earlierPostedAt);
145
- if (isEarlierOnIssue === null) {
248
+ const earlierCommentId = await findCommentOnIssue(issueKey, comparableText, earlierPostedAt);
249
+ if (earlierCommentId === null) {
146
250
  return { kind: 'unchecked', detail: 'the issue could not be read to check whether the earlier attempt landed' };
147
251
  }
148
252
  deps.unconfirmedPosts.settle(requestId, bodyHash);
149
- if (isEarlierOnIssue)
150
- return 'posted';
253
+ if (earlierCommentId !== false)
254
+ return { kind: 'posted', commentId: earlierCommentId };
151
255
  }
152
256
  const postStartedAt = deps.now();
153
257
  let result;
154
258
  try {
155
- result = await client.addComment(issueKey, body);
259
+ result = await client.addComment(issueKey, body, parentId);
156
260
  }
157
261
  catch (error) {
158
- return { kind: 'refused', detail: error instanceof Error ? error.message : String(error) };
262
+ return { kind: 'refused', detail: error instanceof Error ? error.message : String(error), status: error instanceof client_1.JiraHttpError ? error.status : 0 };
159
263
  }
160
264
  if (result.outcome === 'created')
161
- return 'posted';
265
+ return { kind: 'posted', commentId: result.id };
162
266
  // R18: a post that timed out or met a 5xx may still be committing on Jira's side.
163
267
  await deps.wait(exports.jiraReadBackDelayMs);
164
- const isOnIssue = await checkIsCommentOnIssue(issueKey, comparableText, postStartedAt);
165
- if (isOnIssue === true)
166
- return 'posted';
268
+ const landedCommentId = await findCommentOnIssue(issueKey, comparableText, postStartedAt);
269
+ if (landedCommentId !== false && landedCommentId !== null)
270
+ return { kind: 'posted', commentId: landedCommentId };
167
271
  if (requestId !== null)
168
272
  deps.unconfirmedPosts.recordUnconfirmed(requestId, bodyHash, postStartedAt);
169
- return isOnIssue === false
273
+ return landedCommentId === false
170
274
  ? { kind: 'notPosted', detail: `${result.reason}; it was not on the issue ${exports.jiraReadBackDelayMs / 1000} s later` }
171
275
  : { kind: 'unknown', detail: result.reason };
172
276
  }
173
- async function postComments(issueKey, bodies, requestId) {
174
- let postedCount = 0;
277
+ /**
278
+ * Post `bodies` in order, in the thread of `threadRootId` or top-level (`null`). A reply Jira refuses with 400 — the
279
+ * thread's comments are gone — is posted top-level instead, and so is the rest of the answer: a refusal posted nothing.
280
+ */
281
+ async function postComments(issueKey, bodies, requestId, threadRootId) {
282
+ const commentIds = [];
283
+ let parentId = threadRootId;
284
+ let refusedThreadRootId = null;
175
285
  for (const body of bodies) {
176
- const outcome = await postComment(issueKey, body, requestId);
177
- if (outcome !== 'posted')
178
- return { postedCount, failure: outcome };
179
- postedCount += 1;
286
+ let outcome = await postComment(issueKey, body, requestId, parentId);
287
+ if (outcome.kind === 'refused' && outcome.status === threadRefusedStatus && parentId !== null) {
288
+ console.warn(`[jira] ${issueKey}: the thread of comment ${parentId} was refused (${outcome.detail}); posting top-level`);
289
+ refusedThreadRootId = parentId;
290
+ parentId = null;
291
+ outcome = await postComment(issueKey, body, requestId, null);
292
+ }
293
+ if (outcome.kind !== 'posted')
294
+ return { postedCount: commentIds.length, commentIds, failure: outcome, refusedThreadRootId };
295
+ commentIds.push(outcome.commentId);
296
+ }
297
+ return { postedCount: commentIds.length, commentIds, failure: null, refusedThreadRootId };
298
+ }
299
+ /** One try at the edit: `edited`, a refusal that changed nothing (404, 400, 403, a rate limit), or an outcome Jira did not confirm. */
300
+ async function sendEdit(issueKey, commentId, body) {
301
+ try {
302
+ await client.editComment(issueKey, commentId, body);
303
+ return 'edited';
304
+ }
305
+ catch (error) {
306
+ const status = error instanceof client_1.JiraHttpError || error instanceof client_1.JiraAuthError ? error.status : 0;
307
+ const isRefused = error instanceof client_1.JiraAuthError || (status >= 400 && status < 500);
308
+ return { kind: isRefused ? 'refused' : 'unconfirmed', detail: error instanceof Error ? error.message : String(error) };
309
+ }
310
+ }
311
+ /**
312
+ * Replace the text of comment `commentId` with `body`. `edited` — it is there now. `notEdited` — it is not (the comment is gone, Jira
313
+ * refuses the edit): the caller posts the text as a new comment. `unknown` — Jira did not confirm the edit and the comment could not
314
+ * be read to check: nothing may be posted (the edit may have landed — the text would stand twice), and the agent is told to send it
315
+ * again, which edits the same comment again. An edit repeats harmlessly, so after an outcome Jira did not confirm (a timeout, a 5xx
316
+ * after the client's retries) the comment is read after the read-back's wait: the new text on it counts as edited, the OLD text
317
+ * gets ONE more edit (the first may still be committing, or was lost) before the text goes into a new comment.
318
+ */
319
+ async function editCommentText(issueKey, commentId, body) {
320
+ const first = await sendEdit(issueKey, commentId, body);
321
+ if (first === 'edited')
322
+ return first;
323
+ if (first.kind === 'refused')
324
+ return { kind: 'notEdited', detail: first.detail };
325
+ await deps.wait(exports.jiraReadBackDelayMs);
326
+ let shown;
327
+ try {
328
+ shown = await client.getComment(issueKey, commentId);
329
+ }
330
+ catch (readError) {
331
+ // A comment that is gone cannot have been edited; one that cannot be read leaves the outcome open.
332
+ if (readError instanceof client_1.JiraHttpError && readError.status === 404)
333
+ return { kind: 'notEdited', detail: `${first.detail}; the comment is gone` };
334
+ console.warn(`[jira] ${issueKey}: read-back of comment ${commentId} after an edit of unknown outcome failed: ${readError instanceof Error ? readError.message : String(readError)}`);
335
+ return { kind: 'unknown', detail: first.detail };
336
+ }
337
+ if (getComparableText(shown.body) === getComparableText(body))
338
+ return 'edited';
339
+ const second = await sendEdit(issueKey, commentId, body);
340
+ return second === 'edited' ? second : { kind: 'notEdited', detail: second.detail };
341
+ }
342
+ /**
343
+ * Put the closing line on top of each progress comment an answer of `kind` ends. Cosmetic: the answer has landed, so a comment that
344
+ * cannot be read or edited stays as it is, with a warning; one that already carries a closing line is left alone.
345
+ */
346
+ async function closeProgressComments(issueKey, commentIds, kind) {
347
+ const [closedParagraph] = (0, adf_1.createPlainTextAdf)(buildJiraProgressClosedText(kind, deps.now())).content;
348
+ for (const commentId of commentIds) {
349
+ try {
350
+ const shown = await client.getComment(issueKey, commentId);
351
+ const content = shown.body?.content ?? [];
352
+ const firstLine = (0, adf_1.getAdfText)(content[0] ?? null);
353
+ if (firstLine.startsWith(progressDoneMark) || firstLine.startsWith(progressPausedMark))
354
+ continue;
355
+ await client.editComment(issueKey, commentId, { version: 1, type: 'doc', content: [closedParagraph, ...content] });
356
+ }
357
+ catch (error) {
358
+ console.warn(`[jira] ${issueKey}: progress comment ${commentId} could not be marked ${kind === 'final' ? 'done' : 'paused'}: ${error instanceof Error ? error.message : String(error)}`);
359
+ }
180
360
  }
181
- return { postedCount, failure: null };
182
361
  }
183
362
  /**
184
363
  * The person a mention request is about: its comment's author, when it is the request's requester and a person
@@ -201,9 +380,9 @@ function createJiraAnswerSink(deps) {
201
380
  }
202
381
  }
203
382
  /**
204
- * The author of comment `commentId` when the agent may reply to it that way: the conversation was shown it and
205
- * its text was readable then, its author is a person other than the AI account, and — with a trusted group —
206
- * the comment is trusted now (author and last editor). `null` otherwise.
383
+ * Comment `commentId` when the agent may reply to it — its author to mention, the thread the answer goes into:
384
+ * the conversation was shown it and its text was readable then, its author is a person other than the AI account,
385
+ * and — with a trusted group — the comment is trusted now (author and last editor). `null` otherwise.
207
386
  */
208
387
  async function getReplyTarget(issueKey, commentId) {
209
388
  const shown = deps.contextLedger.getShownBlock(issueKey, `comment:${commentId}`);
@@ -215,7 +394,7 @@ function createJiraAnswerSink(deps) {
215
394
  if (!author || author.accountId === deps.aiAccountId || !(0, trigger_1.checkIsPersonAccount)(author))
216
395
  return null;
217
396
  const trust = deps.getTrust();
218
- return trust && !(0, issueBlocks_1.checkIsCommentTrusted)(comment, trust) ? null : author;
397
+ return trust && !(0, issueBlocks_1.checkIsCommentTrusted)(comment, trust) ? null : { author, threadRootId: (0, client_1.getCommentThreadRootId)(comment) };
219
398
  }
220
399
  catch (error) {
221
400
  // An id Jira does not know is the agent's slip, told to it in the result; anything else is the operator's to see.
@@ -227,9 +406,10 @@ function createJiraAnswerSink(deps) {
227
406
  }
228
407
  /**
229
408
  * Whom an answer notifies, requester first, each once: the requester of a mention request, and the authors of the
230
- * comments the answer replies to. `leftOutCommentIds` are the replies that did not qualify.
409
+ * comments the answer replies to. `leftOutCommentIds` are the replies that did not qualify; `threadRootId` is the
410
+ * thread of the first that did (`null`: none did), and `otherThreadCommentIds` those that qualified in another thread.
231
411
  */
232
- async function resolveMentionTargets(issueKey, delivery) {
412
+ async function resolveReplyTargets(issueKey, delivery) {
233
413
  const targets = new Map();
234
414
  if (delivery.origin.kind === 'trackerMention') {
235
415
  const requester = await getMentionRequester(issueKey, delivery.origin);
@@ -237,14 +417,34 @@ function createJiraAnswerSink(deps) {
237
417
  targets.set(requester.accountId, requester);
238
418
  }
239
419
  const leftOutCommentIds = [];
420
+ const otherThreadCommentIds = [];
421
+ let threadRootId = null;
240
422
  for (const commentId of new Set(delivery.replyToCommentIds ?? [])) {
241
- const author = await getReplyTarget(issueKey, commentId);
242
- if (author)
243
- targets.set(author.accountId, author);
244
- else
423
+ const target = await getReplyTarget(issueKey, commentId);
424
+ if (!target) {
245
425
  leftOutCommentIds.push(commentId);
426
+ continue;
427
+ }
428
+ targets.set(target.author.accountId, target.author);
429
+ if (threadRootId === null)
430
+ threadRootId = target.threadRootId;
431
+ else if (target.threadRootId !== threadRootId)
432
+ otherThreadCommentIds.push(commentId);
433
+ }
434
+ return { targets: [...targets.values()], leftOutCommentIds, threadRootId, otherThreadCommentIds };
435
+ }
436
+ /** The answer's files attached (`null`: it carries none), or why they could not be. */
437
+ async function attachAnswerFiles(issueKey, paths) {
438
+ if (!paths || paths.length === 0)
439
+ return null;
440
+ if (!deps.attachFiles)
441
+ return { ok: false, error: exports.jiraFilesUnavailableError };
442
+ try {
443
+ return await deps.attachFiles(issueKey, paths, { isShownInline: true });
444
+ }
445
+ catch (error) {
446
+ return { ok: false, error: `the files could not be attached (${error instanceof Error ? error.message : String(error)}); nothing was posted` };
246
447
  }
247
- return { targets: [...targets.values()], leftOutCommentIds };
248
448
  }
249
449
  /** Hand the issue back to the requester while it is still the AI's; a warning when that could not happen. */
250
450
  async function handBack(issueKey, requesterAccountId) {
@@ -266,16 +466,16 @@ function createJiraAnswerSink(deps) {
266
466
  * A notice the bot writes itself (no agent ran), then the hand-back to the requester. A notice that did not land
267
467
  * is a warning and no hand-back: the issue stays the AI's, and the trigger is recorded already, so it is not repeated.
268
468
  */
269
- async function postNoticeAndHandBack(issueKey, requester, notice, noticeKind) {
270
- if (!await postNotice(issueKey, notice, noticeKind))
469
+ async function postNoticeAndHandBack(issueKey, requester, notice, noticeKind, threadRootId) {
470
+ if (!await postNotice(issueKey, notice, noticeKind, threadRootId))
271
471
  return;
272
472
  const handBackWarning = await handBack(issueKey, requester?.accountId ?? requestGroup_1.emptyRequester);
273
473
  if (handBackWarning)
274
474
  console.warn(`[jira] ${issueKey}: ${noticeKind}: ${handBackWarning}`);
275
475
  }
276
- /** A notice the bot writes itself; `false` (and a warning) when it did not land. */
277
- async function postNotice(issueKey, notice, noticeKind) {
278
- const posted = await postComments(issueKey, [notice], null);
476
+ /** A notice the bot writes itself, in the thread of `threadRootId` or top-level; `false` (and a warning) when it did not land. */
477
+ async function postNotice(issueKey, notice, noticeKind, threadRootId) {
478
+ const posted = await postComments(issueKey, [notice], null, threadRootId);
279
479
  if (posted.postedCount === 0 && posted.failure) {
280
480
  console.warn(`[jira] ${issueKey}: ${noticeKind} notice not posted: ${getNothingPostedError(posted.failure)}`);
281
481
  return false;
@@ -301,6 +501,11 @@ function createJiraAnswerSink(deps) {
301
501
  return `Nothing was posted: ${failure.detail}. Send the answer again in a few minutes`;
302
502
  }
303
503
  }
504
+ /** The edit of the progress comment was not confirmed and the comment could not be read: nothing was posted, the resend edits it again. */
505
+ function getEditUnknownError(detail) {
506
+ return `Jira did not confirm the edit of your progress comment and the comment could not be read to check it (${detail}); it may be edited already. ` +
507
+ 'Nothing was posted. Send the progress again, unchanged: the same comment is edited again, which is safe to repeat';
508
+ }
304
509
  /** A failure after some comments landed: where the unposted rest starts, so only that rest is sent again. */
305
510
  function getMissingPartsWarning(bodies, posted, failure) {
306
511
  const restStart = `"${getTextPreview(bodies[posted.postedCount])}"`;
@@ -315,25 +520,85 @@ function createJiraAnswerSink(deps) {
315
520
  return `${postedPart}, the rest did not (${failure.detail}). Send the rest again, starting at ${restStart} — not the comments already posted`;
316
521
  }
317
522
  return {
523
+ noteIssueUpdate(requestId, threadRootId) {
524
+ deps.answerThreads.note(requestId, threadRootId);
525
+ deps.progressComments.forgetAll(requestId);
526
+ },
527
+ noteLinkedIssueUpdate(requestId) {
528
+ deps.progressComments.forgetAll(requestId);
529
+ },
318
530
  async deliverAnswer(key, delivery) {
319
531
  const issueKey = key.thread;
320
- const { targets, leftOutCommentIds } = await resolveMentionTargets(issueKey, delivery);
321
- const bodies = targets.length > 0
532
+ const replies = await resolveReplyTargets(issueKey, delivery);
533
+ const { targets, leftOutCommentIds } = replies;
534
+ // The comment the agent replies to decides the thread; else the thread an update of the request came from; else the
535
+ // thread the request was opened in; else top-level.
536
+ let threadRootId = replies.threadRootId ?? deps.answerThreads.get(delivery.requestId) ?? getOriginThreadRootId(delivery.origin);
537
+ const textBodies = targets.length > 0
322
538
  ? (0, adf_1.createCommentBodiesWithLeadingNode)(delivery.body, (0, adf_1.createMentionParagraph)(targets))
323
539
  : (0, adf_1.createCommentBodies)(delivery.body);
324
- if (bodies.length === 0)
540
+ if (textBodies.length === 0)
325
541
  return { ok: false, error: 'the answer is empty' };
542
+ // Attached before anything is posted: a file that cannot be attached leaves the answer undelivered, safe to send again.
543
+ const files = await attachAnswerFiles(issueKey, delivery.files);
544
+ if (files && !files.ok)
545
+ return { ok: false, error: files.error };
546
+ const bodies = files ? (0, outgoingFiles_1.appendNodesToBodies)(textBodies, files.nodes) : textBodies;
326
547
  // Only a hand-over's question hands the issue back, so only it carries the line saying how to give it back —
327
548
  // and only while its request is open: a superseded request's question hands nothing back.
328
549
  const isHandOver = delivery.origin.kind === 'trackerEvent';
329
550
  if (isHandOver && delivery.isRequestOpen && delivery.kind === 'question')
330
551
  bodies[bodies.length - 1] = getBodyWithContinueLine(bodies[bodies.length - 1]);
331
- const posted = await postComments(issueKey, bodies, delivery.requestId);
552
+ // A plain note that fits one comment is kept as that comment, edited by the next one.
553
+ const slot = bodies.length === 1 ? getEditableSlot(delivery) : null;
554
+ const kept = slot === null ? null : deps.progressComments.get(delivery.requestId, slot);
555
+ if (slot !== null && kept !== null) {
556
+ const edited = await editCommentText(issueKey, kept.commentId, getBodyWithUpdatedLine(bodies[0], deps.now()));
557
+ if (edited === 'edited') {
558
+ // The agent has spoken since the bot's notices: the next one of them is a new comment below, not an edit above.
559
+ if (!delivery.isBotNotice)
560
+ deps.progressComments.forgetAll(delivery.requestId, [slot]);
561
+ return { ok: true };
562
+ }
563
+ // An edit that may have landed: nothing is posted, the comment stays the kept one and the resend edits it again.
564
+ if (edited.kind === 'unknown')
565
+ return { ok: false, error: getEditUnknownError(edited.detail) };
566
+ // The text goes into a new comment in the thread the old one stood in, which stays the progress comment's.
567
+ console.warn(`[jira] ${issueKey}: comment ${kept.commentId} could not be edited (${edited.detail}); posting the progress as a new comment`);
568
+ threadRootId = kept.threadRootId;
569
+ }
570
+ // The progress comments this answer ends: its request's and those of the requests it replaced, kept or released.
571
+ const isEndingAnswer = !delivery.isBotNotice && (delivery.kind === 'final' || delivery.kind === 'question');
572
+ const endedRequestIds = isEndingAnswer ? [delivery.requestId, ...(delivery.supersededRequestIds ?? [])] : [];
573
+ const endedProgressCommentIds = [...new Set(endedRequestIds.flatMap((requestId) => deps.progressComments.listToClose(requestId)))];
574
+ const posted = await postComments(issueKey, bodies, delivery.requestId, threadRootId);
332
575
  if (posted.postedCount === 0 && posted.failure)
333
576
  return { ok: false, error: getNothingPostedError(posted.failure) };
334
- const warnings = [];
577
+ // The agent's answer is there: the thread an update put it in is used up, the next answer goes where they go by default.
578
+ // A notice the bot wrote (a usage limit, a refused sign-in) goes into that thread too but uses nothing up: the agent's
579
+ // answer to the reply is still owed, and comes after the resume.
580
+ if (!delivery.isBotNotice)
581
+ deps.answerThreads.consume(delivery.requestId);
582
+ if (slot !== null)
583
+ deps.progressComments.remember(delivery.requestId, slot, posted.commentIds[0], posted.refusedThreadRootId === null ? threadRootId : null);
584
+ // A comment was added: every chain of edits that stands above it ends, so the next of each is a new comment below — a notice
585
+ // of the bot's own is one chain, the agent's progress note another. The agent's answer ends the bot's notices (a question, a
586
+ // final answer or a note that is a comment of its own ends its progress comment too); a bot comment that stands on its own
587
+ // (an account moved, no account usable) ends the notices and leaves the agent's note, which it has nothing to do with. A request
588
+ // this answer ends is settled instead: everything it keeps is dropped at once, with no release line for a comment just closed.
589
+ if (!endedRequestIds.includes(delivery.requestId)) {
590
+ deps.progressComments.forgetAll(delivery.requestId, [...(slot === null ? [] : [slot]), ...(delivery.isBotNotice ? [progressComments_1.jiraProgressSlot] : [])]);
591
+ }
592
+ for (const requestId of endedRequestIds)
593
+ deps.progressComments.settle(requestId);
594
+ const warnings = [...(files?.notes ?? [])];
335
595
  if (leftOutCommentIds.length > 0)
336
596
  warnings.push(buildJiraReplyLeftOutWarning(leftOutCommentIds));
597
+ if (replies.threadRootId !== null && replies.otherThreadCommentIds.length > 0) {
598
+ warnings.push(buildJiraOtherThreadsWarning(replies.threadRootId, replies.otherThreadCommentIds));
599
+ }
600
+ if (posted.refusedThreadRootId !== null)
601
+ warnings.push(buildJiraThreadRefusedWarning(posted.refusedThreadRootId));
337
602
  if (posted.failure)
338
603
  warnings.push(getMissingPartsWarning(bodies, posted, posted.failure));
339
604
  // An answer to a request that is no longer open (superseded by a newer one) must not take the issue from it.
@@ -343,13 +608,20 @@ function createJiraAnswerSink(deps) {
343
608
  if (handBackWarning)
344
609
  warnings.push(handBackWarning);
345
610
  }
611
+ // Cosmetic, so after what notifies the requester: a slow Jira delays the closing lines, never the hand-back.
612
+ if (isEndingAnswer) {
613
+ await closeProgressComments(issueKey, endedProgressCommentIds.filter((commentId) => !posted.commentIds.includes(commentId)), delivery.kind === 'final' ? 'final' : 'question');
614
+ }
346
615
  return warnings.length > 0 ? { ok: true, warning: warnings.join('; ') } : { ok: true };
347
616
  },
348
617
  async deliverAlert(key, alert) {
349
618
  const issueKey = key.thread;
350
- const posted = await postComments(issueKey, [(0, adf_1.convertMarkdownToAdf)(buildJiraAlertText(alert.requestId, alert.reason))], alert.requestId);
619
+ const posted = await postComments(issueKey, [(0, adf_1.convertMarkdownToAdf)(buildJiraAlertText(alert.reason))], alert.requestId, getOriginThreadRootId(alert.origin));
351
620
  if (posted.postedCount === 0 && posted.failure)
352
621
  return { ok: false, error: getNothingPostedError(posted.failure) };
622
+ // The comment names no request: the log does. Everything kept up to date above it stays as it is: later notes start below.
623
+ console.log(`[jira] ${issueKey}: request ${alert.requestId} given up (${alert.reason}); the alert comment is posted`);
624
+ deps.progressComments.forgetAll(alert.requestId);
353
625
  if (alert.origin.kind === 'trackerEvent') {
354
626
  const handBackWarning = await handBack(issueKey, (0, requestGroup_1.getRequestRequester)(alert.origin));
355
627
  if (handBackWarning)
@@ -359,17 +631,51 @@ function createJiraAnswerSink(deps) {
359
631
  return { ok: true };
360
632
  },
361
633
  async releaseAlert() { },
362
- parkIssue: (issueKey, requester) => postNoticeAndHandBack(issueKey, requester, (0, adf_1.convertMarkdownToAdf)(buildJiraParkText(deps.runBudgetPer24h)), 'park'),
363
- parkMention: async (issueKey) => {
364
- await postNotice(issueKey, (0, adf_1.convertMarkdownToAdf)(buildJiraMentionParkText(deps.runBudgetPer24h)), 'mention park');
634
+ parkIssue: (issueKey, requester, threadRootId = null) => postNoticeAndHandBack(issueKey, requester, (0, adf_1.convertMarkdownToAdf)(buildJiraParkText(deps.runBudgetPer24h)), 'park', threadRootId),
635
+ parkMention: async (issueKey, threadRootId = null) => {
636
+ await postNotice(issueKey, (0, adf_1.convertMarkdownToAdf)(buildJiraMentionParkText(deps.runBudgetPer24h)), 'mention park', threadRootId);
365
637
  },
638
+ // The issue's, not a trigger's: top-level.
366
639
  postUpdatesPausedNotice: async (issueKey, maxUpdates, untilMs) => {
367
- await postNotice(issueKey, (0, adf_1.createPlainTextAdf)(buildJiraUpdatesPausedText(maxUpdates, untilMs)), 'updates paused');
640
+ await postNotice(issueKey, (0, adf_1.createPlainTextAdf)(buildJiraUpdatesPausedText(maxUpdates, untilMs)), 'updates paused', null);
641
+ },
642
+ postQueuedNotice: async (issueKey, queue, threadRootId = null) => {
643
+ await postNotice(issueKey, (0, adf_1.convertMarkdownToAdf)(buildJiraQueuedText(queue.maxConcurrent, queue.aheadCount)), 'queued', threadRootId);
368
644
  },
369
- postQueuedNotice: async (issueKey, queue) => {
370
- await postNotice(issueKey, (0, adf_1.convertMarkdownToAdf)(buildJiraQueuedText(queue.maxConcurrent, queue.aheadCount)), 'queued');
645
+ // A hand-over's: it has no comment, so top-level.
646
+ refuseUntrusted: (issueKey, requester, groupName) => postNoticeAndHandBack(issueKey, requester, (0, adf_1.createPlainTextAdf)(buildJiraUntrustedText(groupName)), 'untrusted', null),
647
+ postFiles: async (issueKey, request, threadRootId) => {
648
+ if (!deps.attachFiles)
649
+ return { ok: false, error: exports.jiraFilesUnavailableError };
650
+ let files;
651
+ try {
652
+ files = await deps.attachFiles(issueKey, request.paths, { isShownInline: !request.isAsLinks });
653
+ }
654
+ catch (error) {
655
+ return { ok: false, error: `the files could not be attached (${error instanceof Error ? error.message : String(error)}); nothing was posted` };
656
+ }
657
+ if (!files.ok)
658
+ return { ok: false, error: files.error };
659
+ const caption = request.caption?.trim() ?? '';
660
+ const bodies = (0, outgoingFiles_1.appendNodesToBodies)(caption === '' ? [] : (0, adf_1.createCommentBodies)(caption), files.nodes);
661
+ const posted = await postComments(issueKey, bodies, null, threadRootId);
662
+ if (posted.postedCount === 0 && posted.failure) {
663
+ const error = `the files are attached to ${issueKey} — ${files.summary} — but the comment that shows them was not posted (${posted.failure.detail}); ` +
664
+ 'sending them again reuses the attachments';
665
+ return posted.failure.kind === 'unknown' ? { ok: false, kind: 'deliveryUnknown', error } : { ok: false, error };
666
+ }
667
+ const notes = [
668
+ ...files.notes,
669
+ ...(posted.refusedThreadRootId === null ? [] : [buildJiraThreadRefusedWarning(posted.refusedThreadRootId)]),
670
+ ...(posted.failure ? [`only the first ${posted.postedCount} of the comment's ${bodies.length} parts were posted (${posted.failure.detail})`] : []),
671
+ ];
672
+ const place = threadRootId === null || posted.refusedThreadRootId !== null ? 'a comment' : `a comment in the thread of comment ${threadRootId}`;
673
+ return {
674
+ ok: true,
675
+ summary: `Posted in ${place} on ${issueKey}: ${files.summary}.${notes.length > 0 ? ` Note: ${notes.join('; ')}.` : ''}`,
676
+ sentKinds: files.sentKinds,
677
+ };
371
678
  },
372
- refuseUntrusted: (issueKey, requester, groupName) => postNoticeAndHandBack(issueKey, requester, (0, adf_1.createPlainTextAdf)(buildJiraUntrustedText(groupName)), 'untrusted'),
373
679
  };
374
680
  }
375
681
  //# sourceMappingURL=answerSink.js.map