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
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.midTurnInboxMaxChars = exports.midTurnInboxSections = void 0;
37
+ exports.getMidTurnInboxDir = getMidTurnInboxDir;
38
+ exports.buildMidTurnInboxHookCommand = buildMidTurnInboxHookCommand;
39
+ exports.buildMidTurnInboxHookOutput = buildMidTurnInboxHookOutput;
40
+ exports.createMidTurnInbox = createMidTurnInbox;
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ const store_1 = require("../todos/store");
44
+ const sessionKey_1 = require("../sessionKey");
45
+ const jsonStreamHost_1 = require("./jsonStreamHost");
46
+ const tmuxExec_1 = require("./tmuxExec");
47
+ /**
48
+ * @description The per-session mid-turn INBOX of a running Claude agent: text the bot wants the agent to read inside its turn, not
49
+ * only at its next prompt. A `PostToolUse` hook (no matcher) in the launch `--settings` file prints the session's inbox file,
50
+ * `DATA_DIR/todos/inbox/<session id>.json`, after the agent's next tool call: ready hook JSON whose `additionalContext` Claude reads
51
+ * with that tool's result (probed on Claude Code 2.1.310). The hook moves the file before printing it, so a text is delivered once;
52
+ * with no file it prints nothing. The directory is the project board's (it predates the accounts note); the hook command and the
53
+ * single `PostToolUse` entry that carries it are unchanged by there being more than one kind of text in it.
54
+ *
55
+ * One file holds one or more SECTIONS, joined by a blank line: the accounts note (`limitNotes/`) and the project board's changes
56
+ * (`todos/midTurn.ts`). Each section is offered and withdrawn on its own rules — a section's withdrawal never touches another's, and
57
+ * a section is withdrawn wherever no tool call of the session can take it any more (a turn start the bot makes, a turn's end, a turn
58
+ * held open, the session's start, stop or end) — but the FILE is taken whole: when the hook moved it, every section it held counts as
59
+ * taken, and each section's `onTaken` fires once. A section withdrawn unseen keeps its owner's state (the board's changes stay unseen,
60
+ * the note stays due), so the inbox dir is empty between turns. A restart forgets what was written: at worst a text is delivered
61
+ * twice, never lost.
62
+ *
63
+ * Nothing here writes to an agent's input, stamps activity, wakes a session or opens a request: it writes and removes files.
64
+ */
65
+ /** The sections of an inbox, in the order they are joined: the short accounts note first, so the cut of an over-long board never takes it. */
66
+ exports.midTurnInboxSections = ['accounts', 'todoBoard'];
67
+ /** The inbox directory under the todos' (`DATA_DIR/todos/inbox`). */
68
+ const inboxDirName = 'inbox';
69
+ /** Claude Code caps a hook's `additionalContext`; the text is cut below it. */
70
+ exports.midTurnInboxMaxChars = 10_000;
71
+ /** A session id names a file: only these characters, so no id can reach outside the inbox. */
72
+ const sessionIdRe = /^[A-Za-z0-9_-]+$/;
73
+ const inboxFileExtension = '.json';
74
+ /** A copy the hook moved aside: `<session id>.json.<the hook's process id>` (never the bot's `….tmp`). */
75
+ const takenCopyNameRe = /^[A-Za-z0-9_-]+\.json\.(\d+)$/;
76
+ /** Private: what the agents work on. */
77
+ const inboxFileMode = 0o600;
78
+ /** What joins the sections of one inbox. */
79
+ const sectionSeparator = '\n\n';
80
+ /** @description Where the inboxes live: `DATA_DIR/todos/inbox`. */
81
+ function getMidTurnInboxDir(dataDir) {
82
+ return path.join((0, store_1.getTodosDir)(dataDir), inboxDirName);
83
+ }
84
+ /**
85
+ * The parse of a hook input, run by the bot's own `node` with the inbox dir as its argument: the input's TOP-LEVEL
86
+ * fields alone decide, in whatever order they come — a tool's own input or output naming `agent_id` or `session_id`
87
+ * is never mistaken for them. A sub-agent's call (an `agent_id`) and an id outside {@link sessionIdRe} print nothing;
88
+ * otherwise the session's inbox is moved aside, printed and removed.
89
+ */
90
+ const inboxHookScript = [
91
+ 'const fs = require("fs"), path = require("path");',
92
+ 'let text = "";',
93
+ 'process.stdin.setEncoding("utf8").on("data", (chunk) => { text += chunk; }).on("end", () => {',
94
+ ' try {',
95
+ ' const input = JSON.parse(text);',
96
+ ' if (input === null || typeof input !== "object" || "agent_id" in input) return;',
97
+ ` if (typeof input.session_id !== "string" || !${sessionIdRe.toString()}.test(input.session_id)) return;`,
98
+ ` const file = path.join(process.argv[1], input.session_id + "${inboxFileExtension}"), taken = file + "." + process.pid;`,
99
+ ' try { fs.renameSync(file, taken); } catch { return; }',
100
+ ' process.stdout.write(fs.readFileSync(taken, "utf8"));',
101
+ ' fs.rmSync(taken, { force: true });',
102
+ ' } catch {}',
103
+ '});',
104
+ ].join(' ');
105
+ /**
106
+ * @description The `PostToolUse` hook's shell command. With the inbox dir empty — nearly every tool call — it reads
107
+ * the input whole (the CLI must never write into a closed pipe) and exits; only while an inbox waits does it start
108
+ * `nodePath` (the bot's own, written at every launch) to parse the input ({@link inboxHookScript}). It always exits 0 —
109
+ * a hook failure must never stop the agent's tool.
110
+ *
111
+ * Only the MAIN agent takes the inbox. A sub-agent's tool call fires the hook too, with the SAME `session_id` and an
112
+ * `agent_id` of its own (measured on Claude Code 2.1.310); taken there, the text would land in the sub-agent's
113
+ * context and count as delivered while the main agent never got it.
114
+ */
115
+ function buildMidTurnInboxHookCommand(inboxDir, nodePath = process.execPath) {
116
+ const dir = (0, tmuxExec_1.shellSingleQuote)(inboxDir);
117
+ return [
118
+ `[ -n "$(ls -A ${dir} 2>/dev/null)" ] || { cat > /dev/null; exit 0; }`,
119
+ `${(0, tmuxExec_1.shellSingleQuote)(nodePath)} -e ${(0, tmuxExec_1.shellSingleQuote)(inboxHookScript)} ${dir}`,
120
+ 'exit 0',
121
+ ].join('; ');
122
+ }
123
+ /** @description The hook output Claude reads `text` from: `additionalContext` of a `PostToolUse` hook, within the cap. */
124
+ function buildMidTurnInboxHookOutput(text) {
125
+ const characters = [...text];
126
+ const fitted = characters.length <= exports.midTurnInboxMaxChars ? text : `${characters.slice(0, exports.midTurnInboxMaxChars - 1).join('')}…`;
127
+ return JSON.stringify({ hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext: fitted } });
128
+ }
129
+ function createMidTurnInbox(deps) {
130
+ const { inboxDir, checkIsProcessAlive = jsonStreamHost_1.checkIsPidAlive } = deps;
131
+ const pendingInboxes = new Map();
132
+ function getInboxFilePath(sessionId) {
133
+ return path.join(inboxDir, `${sessionId}${inboxFileExtension}`);
134
+ }
135
+ function writeInbox(pending) {
136
+ const text = exports.midTurnInboxSections.flatMap((section) => pending.sections.get(section)?.text ?? []).join(sectionSeparator);
137
+ fs.mkdirSync(path.dirname(pending.filePath), { recursive: true, mode: 0o700 });
138
+ const tempPath = `${pending.filePath}.${process.pid}.tmp`;
139
+ fs.writeFileSync(tempPath, buildMidTurnInboxHookOutput(text), { mode: inboxFileMode });
140
+ fs.renameSync(tempPath, pending.filePath);
141
+ }
142
+ /** The hook took the file: every section it held counts as taken. */
143
+ function reconcileOne(conversationKey) {
144
+ const pending = pendingInboxes.get(conversationKey);
145
+ if (pending === undefined || fs.existsSync(pending.filePath))
146
+ return;
147
+ pendingInboxes.delete(conversationKey);
148
+ for (const section of exports.midTurnInboxSections)
149
+ pending.sections.get(section)?.onTaken();
150
+ }
151
+ /**
152
+ * A copy the hook moved aside and never removed (its `node` ended between the move and the removal) would keep the inbox dir
153
+ * non-empty until boot. Any session's copy goes — but only once the hook that moved it is gone: a live one may be reading it this
154
+ * very moment, and its text already counts as taken.
155
+ */
156
+ function removeTakenLeftovers() {
157
+ let names;
158
+ try {
159
+ names = fs.readdirSync(inboxDir);
160
+ }
161
+ catch {
162
+ return;
163
+ }
164
+ for (const name of names) {
165
+ const hookPid = takenCopyNameRe.exec(name)?.[1];
166
+ if (hookPid !== undefined && !checkIsProcessAlive(Number(hookPid)))
167
+ fs.rmSync(path.join(inboxDir, name), { force: true });
168
+ }
169
+ }
170
+ /** Withdraw every section of the conversation's inbox and remove its file. */
171
+ function withdrawAll(conversationKey) {
172
+ const pending = pendingInboxes.get(conversationKey);
173
+ if (pending === undefined)
174
+ return;
175
+ pendingInboxes.delete(conversationKey);
176
+ fs.rmSync(pending.filePath, { force: true });
177
+ for (const section of exports.midTurnInboxSections)
178
+ pending.sections.get(section)?.onWithdrawn?.();
179
+ }
180
+ return {
181
+ offer(key, sessionId, section, offer) {
182
+ if (!sessionIdRe.test(sessionId))
183
+ return false;
184
+ const conversationKey = (0, sessionKey_1.keyToString)(key);
185
+ reconcileOne(conversationKey);
186
+ // Another session of the conversation (a restart, a resume under a new id) never takes the old session's file.
187
+ if (pendingInboxes.get(conversationKey)?.sessionId !== sessionId)
188
+ withdrawAll(conversationKey);
189
+ const pending = pendingInboxes.get(conversationKey) ?? { sessionId, filePath: getInboxFilePath(sessionId), sections: new Map() };
190
+ const replaced = pending.sections.get(section);
191
+ pending.sections.set(section, offer);
192
+ try {
193
+ writeInbox(pending);
194
+ }
195
+ catch (error) {
196
+ // The file kept its old text, so the old offer stays what the agent will read; the new one is the caller's to give back.
197
+ if (replaced === undefined)
198
+ pending.sections.delete(section);
199
+ else
200
+ pending.sections.set(section, replaced);
201
+ throw error;
202
+ }
203
+ pendingInboxes.set(conversationKey, pending);
204
+ replaced?.onWithdrawn?.();
205
+ return true;
206
+ },
207
+ checkIsWaiting(key, section) {
208
+ const conversationKey = (0, sessionKey_1.keyToString)(key);
209
+ reconcileOne(conversationKey);
210
+ return pendingInboxes.get(conversationKey)?.sections.has(section) === true;
211
+ },
212
+ reconcile(key) {
213
+ if (key !== undefined) {
214
+ reconcileOne((0, sessionKey_1.keyToString)(key));
215
+ return;
216
+ }
217
+ for (const conversationKey of [...pendingInboxes.keys()])
218
+ reconcileOne(conversationKey);
219
+ },
220
+ withdraw(key, section) {
221
+ removeTakenLeftovers();
222
+ const conversationKey = (0, sessionKey_1.keyToString)(key);
223
+ reconcileOne(conversationKey);
224
+ const pending = pendingInboxes.get(conversationKey);
225
+ const withdrawn = pending?.sections.get(section);
226
+ if (pending === undefined || withdrawn === undefined)
227
+ return;
228
+ pending.sections.delete(section);
229
+ const remaining = exports.midTurnInboxSections.flatMap((name) => pending.sections.get(name) ?? []);
230
+ try {
231
+ if (remaining.length === 0) {
232
+ pendingInboxes.delete(conversationKey);
233
+ fs.rmSync(pending.filePath, { force: true });
234
+ }
235
+ else {
236
+ writeInbox(pending);
237
+ }
238
+ }
239
+ catch (error) {
240
+ // The file would keep the withdrawn text — a hook could hand it to the agent in a LATER turn, the double note the withdrawal
241
+ // exists to prevent. Remove it whole and withdraw every section it held: «withdrawn» only means «stays due / stays unseen».
242
+ pendingInboxes.delete(conversationKey);
243
+ try {
244
+ fs.rmSync(pending.filePath, { force: true });
245
+ }
246
+ finally {
247
+ for (const offer of remaining)
248
+ offer.onWithdrawn?.();
249
+ withdrawn.onWithdrawn?.();
250
+ }
251
+ throw error;
252
+ }
253
+ withdrawn.onWithdrawn?.();
254
+ },
255
+ clearAll() {
256
+ const pendings = [...pendingInboxes.values()];
257
+ pendingInboxes.clear();
258
+ fs.rmSync(inboxDir, { recursive: true, force: true });
259
+ for (const pending of pendings)
260
+ for (const section of exports.midTurnInboxSections)
261
+ pending.sections.get(section)?.onWithdrawn?.();
262
+ },
263
+ };
264
+ }
265
+ //# sourceMappingURL=midTurnInbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"midTurnInbox.js","sourceRoot":"","sources":["../../src/utils/midTurnInbox.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,gDAEC;AAkCD,oEAOC;AAGD,kEAIC;AAkDD,gDA8HC;AA/QD,uCAAyB;AACzB,2CAA6B;AAC7B,0CAA6C;AAC7C,8CAA6D;AAC7D,qDAAmD;AACnD,yCAA8C;AAE9C;;;;;;;;;;;;;;;;;GAiBG;AAEH,8IAA8I;AACjI,QAAA,oBAAoB,GAAG,CAAC,UAAU,EAAE,WAAW,CAAU,CAAC;AAGvE,qEAAqE;AACrE,MAAM,YAAY,GAAG,OAAO,CAAC;AAC7B,+EAA+E;AAClE,QAAA,oBAAoB,GAAG,MAAM,CAAC;AAC3C,8FAA8F;AAC9F,MAAM,WAAW,G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 +1,24 @@
1
1
  import { type SessionKey } from '../sessionKey';
2
2
  import type { BufferedPromptSettled, StartupPromptBuffer } from '../startupPromptBuffer';
3
+ import type { LostWorkTelling } from './lostWork';
3
4
  /**
4
5
  * @name PromptDeliveryDeps
5
- * @description What {@link deliverPromptOrBuffer} acts through. `forwardPrompt` says where the
6
- * forward put the prompt ({@link LatePromptOutcome}); `announceQueued` tells the person their
7
- * prompt waits for the session to come up — a topic message, so it is only called for a
8
- * Telegram conversation.
6
+ * @description What {@link deliverPromptOrBuffer} acts through, every state read at the moment of the write. `forwardPrompt` says
7
+ * where the forward put the prompt ({@link LatePromptOutcome}); `checkIsSessionActive` and `wakeSession` let a prompt that finds no
8
+ * window and no live session wake the conversation first; `reportNoSession` runs when that wake found nothing (the person is told,
9
+ * unless the wake already said why; a bot-made prompt is only logged); `checkIsRefusingMessages` — a command ends or replaces the
10
+ * conversation now, so a person's prompt is not delivered at all — and `reportRefused`, which tells the person so (also when the wake
11
+ * found the conversation ended by a release while it waited; a bot-made prompt is only logged); `announceQueued` tells the person their
12
+ * prompt waits for the session to come up — a topic message, so it is only called for a Telegram conversation.
9
13
  */
10
14
  export interface PromptDeliveryDeps {
11
- startupBuffer: Pick<StartupPromptBuffer, 'addPrompt'>;
15
+ startupBuffer: Pick<StartupPromptBuffer, 'addPrompt' | 'checkIsStarting'>;
12
16
  forwardPrompt: (key: SessionKey, text: string, options: PromptDeliveryOptions) => Promise<LatePromptOutcome>;
17
+ checkIsSessionActive: (key: SessionKey) => boolean;
18
+ wakeSession: (key: SessionKey) => Promise<LateWakeResult>;
19
+ checkIsRefusingMessages: (key: SessionKey) => boolean;
20
+ reportNoSession: (key: SessionKey, isAlreadyTold: boolean, options: PromptDeliveryOptions) => Promise<void>;
21
+ reportRefused: (key: SessionKey, options: PromptDeliveryOptions) => Promise<void>;
13
22
  announceQueued: (key: SessionKey) => Promise<void>;
14
23
  }
15
24
  /**
@@ -17,9 +26,22 @@ export interface PromptDeliveryDeps {
17
26
  * @description `isPersonInput` — a person typed, spoke or sent it (a topic's text, voice, file or album): its forward does not
18
27
  * wait for the write into the agent (the topic's update queue must not hang on it), and a write that fails is told to them.
19
28
  * Every other prompt — a wake-up, a scheduled run, a retry's nudge, a tracker's post — waits for it, buffered or not.
29
+ * `isAccountsNoteCarrier` — the prompt starts a turn the person or the scheduler made (a person's message that opened a request, a
30
+ * tracker's post, a scheduled run), so its forward may attach the accounts note (`limitNotes/`); kept with the prompt through a startup
31
+ * buffer, and decorated at the replay with the figures of that moment.
32
+ * `lostWorkTelling` — how a lost-work note that rides this prompt asks to tell about the loss (`LostWorkTelling`; a tracker fire whose
33
+ * ridden request owes nothing, or with none open, asks `runHeader`: its header already says when to answer); kept through a startup
34
+ * buffer as well.
20
35
  */
21
36
  export interface PromptDeliveryOptions {
22
37
  isPersonInput?: boolean;
38
+ isAccountsNoteCarrier?: boolean;
39
+ lostWorkTelling?: LostWorkTelling;
40
+ /**
41
+ * A bot-made post's wait while a command ends or replaces the conversation: awaited before EACH routing of the write — the first one,
42
+ * and again after a wake or an adopt-replay wait, either of which may outlast the start of a move ({@link LatePromptDeliveryPorts}).
43
+ */
44
+ waitBeforeRoute?: () => Promise<void>;
23
45
  }
24
46
  /**
25
47
  * @name PromptDelivery
@@ -32,21 +54,22 @@ export interface PromptDeliveryOptions {
32
54
  */
33
55
  export type PromptDelivery = 'forwarded' | 'buffered' | 'noSession';
34
56
  /**
35
- * @description Deliver `text` to a conversation's agent while honouring the startup
36
- * window: mid-startup the prompt is buffered (it replays in order once the session
37
- * is up, exactly like a text typed during boot); otherwise it is forwarded at once.
38
- * The one "buffer-or-forward" unit shared by the text and voice handlers' mid-startup
39
- * buffering, file/album intake, `/schedule`, the Jira connector's posts and an
40
- * API-error retry's "continue" nudge — the last two reach it with a session another
41
- * caller's start may still be bringing up, where a direct forward would hit an
42
- * adapter that is not there yet.
57
+ * @description Deliver `text` to a conversation's agent, routed at the MOMENT OF THE WRITE ({@link deliverLatePrompt}): a start's or a
58
+ * stop's window open → buffered behind it (it replays in order once the session is up, exactly like a text typed during boot); a live
59
+ * session → forwarded; no window and no live session → the conversation is woken first, then forwarded. The one "buffer-or-forward"
60
+ * unit of every prompt that may meet a session another caller is starting or stopping: a person's prompt (`deliverPromptByState` in
61
+ * `bot.ts`), a scheduled run, a tracker's post, the lost-work post, a retry's «continue», a move's first prompt.
43
62
  *
44
- * `isStarting` is passed in (not read here) because the album collector captures
45
- * it AT FLUSH TIME — a session that finished booting mid-burst must forward, not
46
- * buffer.
63
+ * Nothing a caller read before an await decides it: a window that closed during the caller's awaits (its request opened, a file
64
+ * downloaded) never takes the prompt. The buffer is read and added to in the same tick, so it never refuses a prompt here
65
+ * ({@link StartupPromptBuffer.addPrompt} refuses a closed window); a refusal would be a bug and throws.
47
66
  *
48
67
  * The "queued while starting" notice is posted once per startup window, and only
49
- * for a Telegram conversation: a tracker issue has no topic to say it in (R6).
68
+ * for a Telegram conversation: a tracker issue has no topic to say it in (R6). It is
69
+ * NOT awaited (a topic send through the process-wide pacer can take seconds): this
70
+ * resolves `buffered` in the tick the buffer took the prompt, so a caller that watches
71
+ * the prompt's turn does so before any replay can write it, and before the agent can
72
+ * answer it (review 20 #2). The pacer keeps the notice's place in the topic.
50
73
  *
51
74
  * A buffered prompt lives in memory, so a restart before the start ends loses it.
52
75
  * A caller that must know how the wait ended — to keep what would re-send the prompt
@@ -55,20 +78,22 @@ export type PromptDelivery = 'forwarded' | 'buffered' | 'noSession';
55
78
  * A failed "queued" notice is logged and does not change the answer: the prompt was
56
79
  * buffered before the notice went out.
57
80
  */
58
- export declare function deliverPromptOrBuffer(deps: PromptDeliveryDeps, key: SessionKey, text: string, isStarting: boolean, onBufferedSettled?: BufferedPromptSettled, options?: PromptDeliveryOptions): Promise<PromptDelivery>;
81
+ export declare function deliverPromptOrBuffer(deps: PromptDeliveryDeps, key: SessionKey, text: string, onBufferedSettled?: BufferedPromptSettled, options?: PromptDeliveryOptions): Promise<PromptDelivery>;
59
82
  /**
60
83
  * @name LatePromptRoute
61
84
  * @description How a prompt decided on when it ARRIVED is delivered once its handler is ready to forward it:
62
85
  * `buffer` — a start or the idle stop is under way (its window is open: the prompt waits there, and the stop resumes the
63
86
  * session for it); `wake` — the process is gone meanwhile (the conversation sleeps: wake it, then forward); `forward`;
64
- * `drop` — only for a technical prompt that finds no live session without a window: nothing is done for it.
87
+ * `drop` — only for a technical prompt that finds no live session without a window: nothing is done for it;
88
+ * `refuse` — only for a person's prompt while a command ends or replaces the conversation: it is not delivered, and the person is told.
65
89
  */
66
- export type LatePromptRoute = 'buffer' | 'wake' | 'forward' | 'drop';
90
+ export type LatePromptRoute = 'buffer' | 'wake' | 'forward' | 'drop' | 'refuse';
67
91
  /**
68
92
  * @description The {@link LatePromptRoute} of a prompt, read at the moment it is forwarded. The idle stop posts a
69
93
  * re-asked question just before it stops the process, and a handler awaits between reading the session's state and the
70
94
  * forward (the tap's toast, the request it opens): written into a process being stopped the prompt was lost, and
71
- * into one already gone it was dropped.
95
+ * into one already gone it was dropped. A person's prompt that meets a command ending or replacing the conversation
96
+ * (`isRefused`) is refused, whatever the session reads as (`requests/README.md` § Turn starts, review 25 #1).
72
97
  *
73
98
  * A bot-made TECHNICAL prompt (the todo list's standalone reminder) is posted only into a live session that is idle at
74
99
  * this moment — never a resume, never held for a later one, never reported to the person: where a user's prompt would be
@@ -78,12 +103,18 @@ export declare function getLatePromptRoute(input: {
78
103
  isWindowOpen: boolean;
79
104
  isSessionActive: boolean;
80
105
  isTechnical?: boolean;
106
+ isRefused?: boolean;
81
107
  }): LatePromptRoute;
82
108
  /** @description What a wake did: whether a session is up to forward to, and whether it already told the topic something. */
83
109
  export interface LateWakeResult {
84
110
  isAwake: boolean;
85
111
  /** The wake posted a notice of its own (a start that failed says why): the report adds none. */
86
112
  isNoticePosted: boolean;
113
+ /**
114
+ * The conversation was there when the wake began and gone once its turn in the queue came: a release queued ahead ended it, so nothing
115
+ * was started (review 25 #2). Reported as the release's refusal, not as a conversation that was never there.
116
+ */
117
+ isEnded?: boolean;
87
118
  }
88
119
  /**
89
120
  * @name LatePromptDeliveryPorts
@@ -97,11 +128,25 @@ export interface LatePromptDeliveryPorts {
97
128
  isTechnical?: boolean;
98
129
  checkIsWindowOpen: () => boolean;
99
130
  checkIsSessionActive: () => boolean;
131
+ /** A person's prompt only: whether a command ends or replaces the conversation now (absent: never refused). */
132
+ checkIsRefused?: () => boolean;
133
+ /**
134
+ * A bot-made post only: awaited before EACH routing — the first, and again after a wake — while a command ends or replaces the
135
+ * conversation, so the post is routed into the conversation that follows, never into the one a move began leaving during its wake
136
+ * (review 28 nit 2). Absent: the first routing runs in the caller's tick, with no await ahead of it.
137
+ */
138
+ waitBeforeRoute?: () => Promise<void>;
100
139
  buffer: () => Promise<void>;
101
140
  wake: () => Promise<LateWakeResult>;
102
141
  /** Where the forward put the prompt: `forwarded`, or what a forward that routes it again itself (a prompt that waited for an adopt replay) ended in — passed on as the answer. */
103
142
  forward: () => Promise<LatePromptOutcome>;
104
143
  reportNoSession: (isAlreadyTold: boolean) => Promise<void>;
144
+ /**
145
+ * The prompt was refused (a command ends or replaces the conversation), or its wake found the conversation ended by a release while it
146
+ * waited: the person is told the command's line. The delivery answers `noSession`, so whatever the prompt opened is closed by its caller
147
+ * too (a report that closed it already leaves nothing to close). Absent: reported as no session.
148
+ */
149
+ reportRefused?: () => Promise<void>;
105
150
  }
106
151
  /**
107
152
  * @description Where {@link deliverLatePrompt} put the prompt; `noSession` — nowhere: nothing to deliver it to (the wake found
@@ -112,7 +157,10 @@ export type LatePromptOutcome = 'buffered' | 'forwarded' | 'noSession' | 'droppe
112
157
  /**
113
158
  * @description Deliver a prompt whose handler decided, when it arrived, that the session is live — routed again by
114
159
  * {@link getLatePromptRoute} now, after the handler's awaits. A wake that finds nothing never forwards: the forward
115
- * would show the topic as working while the adapter drops the text.
160
+ * would show the topic as working while the adapter drops the text. A wake that brought a session up is followed by
161
+ * one more routing by the state at that moment, never a blind forward: during its awaits (a fresh start's notice is a
162
+ * paced topic send) a prompt it replayed can end its turn and the per-turn stop open its window — a prompt written
163
+ * into that stopping process would be lost (review 19 nit 2).
116
164
  */
117
165
  export declare function deliverLatePrompt(ports: LatePromptDeliveryPorts): Promise<LatePromptOutcome>;
118
166
  //# sourceMappingURL=promptDelivery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"promptDelivery.d.ts","sourceRoot":"","sources":["../../src/utils/promptDelivery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAE7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAEzF;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,IAAI,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;IACtD,aAAa,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC7G,cAAc,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACpD;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,kBAAkB,EACxB,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,OAAO,EACnB,iBAAiB,CAAC,EAAE,qBAAqB,EACzC,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,cAAc,CAAC,CAkBzB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,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