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
@@ -10,6 +10,7 @@ const sessionKeyCodec_1 = require("../sessionKeyCodec");
10
10
  const i18n_1 = require("../../../i18n");
11
11
  const compactCommandRoute_1 = require("../../../utils/compactCommandRoute");
12
12
  const compactOnIdle_1 = require("../../../utils/compactOnIdle");
13
+ const workingSignals_1 = require("../../../utils/workingSignals");
13
14
  const streamedCompactionSummary_1 = require("../../../utils/streamedCompactionSummary");
14
15
  const compactSelfReviewFlags_1 = require("../../../utils/compactSelfReviewFlags");
15
16
  const questionKeyboards_1 = require("../questionKeyboards");
@@ -54,9 +55,12 @@ async function getCompactionInstruction(adapter, key, opts) {
54
55
  // ONE compaction path (plan 2026-09-14-self-compact-and-compact-on-idle).
55
56
  /** F1 poll cadence while waiting for the current turn to finish before draining. */
56
57
  const deferredCompactionPollMs = 3_000;
58
+ /** The callback data of a growth-threshold button: `coi_gr_<tokens>` — a preset of {@link compactGrowthPresetTokens}, so the data is short and never a free value. */
59
+ const growthButtonPrefix = 'coi_gr_';
60
+ const tokensPerThousand = 1000;
57
61
  /**
58
- * Build the `/compact_on_idle` picker keyboard: Enable / Disable, then Show / Hide
59
- * summary, then Show / Hide self-review, ✓ on the current value of each.
62
+ * Build the `/compact_on_idle` picker keyboard: Enable / Disable, then the growth threshold's presets, then Show / Hide
63
+ * summary, then Show / Hide self-review, ✓ on the current value of each (a threshold typed outside the presets has none).
60
64
  */
61
65
  function buildCompactOnIdleKeyboard(picker) {
62
66
  return telegraf_1.Markup.inlineKeyboard([
@@ -64,6 +68,7 @@ function buildCompactOnIdleKeyboard(picker) {
64
68
  telegraf_1.Markup.button.callback((0, i18n_1.t)('compactOnIdle.enableButton') + (picker.isIdleEnabled ? ' ✓' : ''), 'coi_on'),
65
69
  telegraf_1.Markup.button.callback((0, i18n_1.t)('compactOnIdle.disableButton') + (!picker.isIdleEnabled ? ' ✓' : ''), 'coi_off'),
66
70
  ],
71
+ compactOnIdle_1.compactGrowthPresetTokens.map((tokens) => telegraf_1.Markup.button.callback(`${tokens / tokensPerThousand}k${tokens === picker.growthTokens ? ' ✓' : ''}`, `${growthButtonPrefix}${tokens}`)),
67
72
  [
68
73
  telegraf_1.Markup.button.callback((0, i18n_1.t)('compactOnIdle.summaryShowButton') + (picker.isSummaryEnabled ? ' ✓' : ''), 'coi_sum_on'),
69
74
  telegraf_1.Markup.button.callback((0, i18n_1.t)('compactOnIdle.summaryHideButton') + (!picker.isSummaryEnabled ? ' ✓' : ''), 'coi_sum_off'),
@@ -80,7 +85,7 @@ function buildCompactOnIdleKeyboard(picker) {
80
85
  * state the typing loop and the request probe read, and the `register…()` calls.
81
86
  */
82
87
  function createCompaction(ports) {
83
- const { startTypingLoader, forwardPromptToAgent, pendingQuestions, clearPendingQuestion, closeQuestionMessage, setQuestionAsideAtIdle, idleWindowMs, checkIsLimitWaitArmed, suspendThreadSession, resumeSleepingSessionForCompaction, getThreadAdapter, deliverLabel, resumeSleepingSessionForPrompt, checkIsStarting, closeOrphanQuestionMessage, notePersonActivity, compactSelfReviewFlagDirs, bot, command, getState, replyToThread, editThreadKeyboard, authoriseContext, authoriseSpeaker, withThreadLocale, checkIsGeneral, wakeSleepingSession } = ports;
88
+ const { startTypingLoader, readSleepingContext, forwardPromptToAgent, pendingQuestions, clearPendingQuestion, closeQuestionMessage, setQuestionAsideAtIdle, idleWindowMs, checkIsLimitWaitArmed, suspendThreadSession, resumeSleepingSessionForCompaction, getThreadAdapter, deliverLabel, resumeSleepingSessionForPrompt, checkIsStarting, closeOrphanQuestionMessage, notePersonActivity, compactSelfReviewFlagDirs, bot, command, getState, replyToThread, editThreadMessage, editThreadKeyboard, authoriseContext, authoriseSpeaker, withThreadLocale, checkIsGeneral, wakeSleepingSession } = ports;
84
89
  /**
85
90
  * @description Resolve the `/compact` route for a thread's current backend — the
86
91
  * pure {@link getCompactCommandRoute} wrapped with the live adapter reading.
@@ -330,7 +335,7 @@ function createCompaction(ports) {
330
335
  function getThreadCompactionState(kStr) {
331
336
  let existing = threadCompactionStates.get(kStr);
332
337
  if (!existing) {
333
- existing = { idleTimer: null };
338
+ existing = { idleTimer: null, contextSampleTimer: null, ownCompactionsSeen: null, isIdleMarkMissed: false };
334
339
  threadCompactionStates.set(kStr, existing);
335
340
  }
336
341
  return existing;
@@ -347,6 +352,11 @@ function createCompaction(ports) {
347
352
  remainder: 'remainder',
348
353
  overdue: 'overdue (staggered)',
349
354
  };
355
+ /** The line a held idle mark posts into the topic (once), by why the process is held. */
356
+ const idleHeldNoticeKeys = {
357
+ backgroundWork: 'compactOnIdle.skipped.backgroundWorkNotice',
358
+ unconsumedInput: 'compactOnIdle.skipped.unconsumedInputNotice',
359
+ };
350
360
  /**
351
361
  * @description Re-arm the F2 idle timer for a thread on REAL activity (a user
352
362
  * message / command, a forwarded prompt, or agent output). Stamps the persisted
@@ -376,15 +386,13 @@ function createCompaction(ports) {
376
386
  * {@link rearmThreadIdleTimer} — one body so the two entry points can only differ
377
387
  * in whether they count as activity. Arms when an agent session is active and no
378
388
  * compaction is in flight. On a backend that is STOPPED at the idle mark
379
- * (`suspendSession`, L3) the timer is armed regardless of the compaction toggle
380
- * and the user-latch: the stop happens either way (L-D1), and the fire decides
381
- * the compaction. On any other backend the timer exists for the compaction
382
- * alone, so it is armed only when the feature is enabled for the thread AND the
383
- * user-latch is NOT spent (D2): once an idle-compaction has fired this
384
- * user-active period the thread stays latched — agent output resets nothing, and
385
- * only a genuine USER message (via {@link noteThreadUserActivity}) clears the
386
- * latch. That latch, being persisted, is also what stops a restart from
387
- * re-firing.
389
+ * (`suspendSession`, L3) the timer is armed regardless of the compaction toggle:
390
+ * the stop happens either way (L-D1), and the fire decides the compaction. On any other
391
+ * backend the timer exists for the compaction alone, so it is armed only when the
392
+ * feature is enabled for the thread. Nothing else holds the arming back: how often a
393
+ * conversation is compacted is the fire's decision (`getIdleFireDecision`: a turn since
394
+ * the last compaction, and the context grown enough), so a restart cannot re-fire either —
395
+ * the compaction's own stamp and the saved baseline are persisted.
388
396
  */
389
397
  function armThreadIdleTimer(key, opts) {
390
398
  const kStr = (0, sessionKey_1.keyToString)(key);
@@ -399,20 +407,15 @@ function createCompaction(ports) {
399
407
  return;
400
408
  // L-D7: a SLEEPING per-turn session keeps its countdown while a compaction is due — the fire wakes it,
401
409
  // compacts it, and stops it again; every other sleeping or idle-less session has no timer.
402
- if (!adapter.checkIsActive(key) && !(adapter.name === adapterNames_1.claudePerTurnAdapterName && checkIsCompactionDue(key)))
410
+ if (!adapter.checkIsActive(key) && !(adapter.name === adapterNames_1.claudePerTurnAdapterName && checkIsCompactionPending(key)))
403
411
  return;
404
412
  const now = Date.now();
405
- // Stamp AFTER the enabled/active guards (a disabled or session-less topic has no
406
- // countdown to measure) but BEFORE the latch guard: a latched thread still has
407
- // activity worth recording — the latch only suppresses the TIMER.
413
+ // Stamp AFTER the enabled/active guards: a disabled or session-less topic has no countdown to measure.
408
414
  if (opts.isRealActivity)
409
415
  getState().noteCompactIdleActivity(key, now);
410
- // D2: a spent latch means idle-compaction already fired this user-active period
411
- // — do NOT re-arm until a genuine USER message clears the latch.
412
- if (!isSuspendable && getState().checkIsCompactIdleLatched(key))
413
- return;
414
416
  const { lastActivityAt } = getState().getCompactIdleTracking(key);
415
417
  const { delayMs, kind } = (0, compactOnIdle_1.getIdleCompactionArmDecision)({ threadKeyString: kStr, lastActivityAt, now, idleWindowMs });
418
+ getThreadCompactionState(kStr).isIdleMarkMissed = kind === 'overdue';
416
419
  if (!opts.isRealActivity) {
417
420
  // Session-start / re-adopt only (once per thread per boot, or per manual start) —
418
421
  // was the other blind spot: nothing showed whether an adopted thread got re-armed
@@ -442,19 +445,6 @@ function createCompaction(ports) {
442
445
  timer.unref?.();
443
446
  compactionState.idleTimer = timer;
444
447
  }
445
- /**
446
- * @description A genuine USER message (text / voice / file) or a fresh session
447
- * start (D2): clear the spent idle-compaction latch so the next idle period can
448
- * compact again, THEN reset/arm the idle timer. Distinct from
449
- * {@link noteThreadActivity} — which agent output and bot-initiated forwards also
450
- * call — because those must NEVER re-arm the latch, only a real user does.
451
- */
452
- function noteThreadUserActivity(key) {
453
- if (getState().checkIsCompactIdleLatched(key)) {
454
- void getState().setCompactIdleLatched(key, false);
455
- }
456
- noteThreadActivity(key);
457
- }
458
448
  /**
459
449
  * Mark that an agent turn produced output — there is now something to compress.
460
450
  * PERSISTED: the fire guard compares this against the last compaction, and after a
@@ -466,6 +456,81 @@ function createCompaction(ports) {
466
456
  if (threadsCompacting.has(kStr))
467
457
  return; // the compaction's own output isn't a turn
468
458
  getState().noteCompactIdleTurnEnd(key);
459
+ // The json-stream backends say when a turn ends (`noteThreadTurnContext`); the others only stream output, so the context size
460
+ // is read once that output has settled.
461
+ if (!(0, adapterNames_1.checkIsJsonStreamBackend)(getThreadAdapter(key).name))
462
+ scheduleThreadContextSample(key);
463
+ }
464
+ /**
465
+ * @description Read what the conversation weighs now and record it (`noteCompactIdleContext`): the context after its newest model call
466
+ * (`getContextUsedTokens`, the figure the idle compaction's growth is measured up to) and, while it has no baseline or a compaction
467
+ * the bot did not issue replaced its epoch (`getOwnCompactionCount` moved) or may have (the first reading of a bot lifetime, every
468
+ * read of a sleeping conversation: the baseline is a RECHECK, replaced by what is read and kept when nothing is), the context its
469
+ * epoch's FIRST model call saw (`getFirstCallContextTokens`, read from the conversation's history — the baseline). Both reads start in the same tick, before a
470
+ * per-turn process is stopped; a conversation whose process IS stopped is read from its transcript by its persisted session
471
+ * (`readSleepingContext`). Not for the compaction's own turn, and a reading that a compaction overtook while the backend answered is
472
+ * dropped — it describes the context of before. A backend that cannot say leaves the figures as they were: a conversation never
473
+ * compacted is not held back by the gate then, one that was compacted is ({@link checkIsContextGrownEnough}).
474
+ */
475
+ async function sampleThreadContext(key) {
476
+ const kStr = (0, sessionKey_1.keyToString)(key);
477
+ if (threadsCompacting.has(kStr))
478
+ return;
479
+ const adapter = getThreadAdapter(key);
480
+ const isAsleep = !adapter.checkIsActive(key);
481
+ if (isAsleep ? !(0, adapterNames_1.checkIsJsonStreamBackend)(adapter.name) : !adapter.getContextUsedTokens)
482
+ return;
483
+ const { lastCompactionAt: compactedAtBefore, baselineContextTokens } = getState().getCompactIdleTracking(key);
484
+ const compactionState = getThreadCompactionState(kStr);
485
+ // A live session's count of the compactions it did not issue: a change since the last reading is a replaced epoch.
486
+ const ownCompactions = isAsleep ? null : adapter.getOwnCompactionCount?.(key) ?? 0;
487
+ const isNewEpoch = ownCompactions !== null && ownCompactions !== (compactionState.ownCompactionsSeen ?? 0);
488
+ // A compaction the count cannot show — one the CLI made before a restart whose boundary the replay no longer reaches, one the
489
+ // server made while the bot was down, one of a sleeping conversation — is caught by reading the epoch's first call again: once per
490
+ // bot lifetime (nothing seen yet) and at every read of a sleeping conversation. It costs a history read and changes nothing when
491
+ // the epoch is the same.
492
+ const isBaselineRecheck = baselineContextTokens !== null && !isNewEpoch && (isAsleep || compactionState.ownCompactionsSeen === null);
493
+ const isBaselineNeeded = isNewEpoch || isBaselineRecheck || baselineContextTokens === null;
494
+ let reading;
495
+ try {
496
+ reading = isAsleep
497
+ ? await readSleepingContext(key, isBaselineNeeded)
498
+ : await readLiveContext(key, adapter, isBaselineNeeded);
499
+ }
500
+ catch (error) {
501
+ console.warn(`[compact-on-idle] ${kStr} reading the context size failed: ${error instanceof Error ? error.message : error}`);
502
+ return;
503
+ }
504
+ if (reading === null || reading.lastContextTokens === null || reading.lastContextTokens <= 0)
505
+ return;
506
+ if (threadsCompacting.has(kStr) || getState().getCompactIdleTracking(key).lastCompactionAt !== compactedAtBefore)
507
+ return;
508
+ getState().noteCompactIdleContext(key, { lastContextTokens: reading.lastContextTokens, firstCallContextTokens: reading.firstCallContextTokens, isNewEpoch, isBaselineRecheck });
509
+ if (ownCompactions !== null)
510
+ compactionState.ownCompactionsSeen = ownCompactions;
511
+ }
512
+ /** What a live session weighs, from its adapter: both reads started in the caller's tick. */
513
+ function readLiveContext(key, adapter, isBaselineNeeded) {
514
+ return Promise.all([
515
+ adapter.getContextUsedTokens?.(key) ?? null,
516
+ isBaselineNeeded ? adapter.getFirstCallContextTokens?.(key) ?? null : null,
517
+ ]).then(([lastContextTokens, firstCallContextTokens]) => ({ lastContextTokens, firstCallContextTokens }));
518
+ }
519
+ /** A turn of a json-stream conversation ended: read its context size right away — a per-turn process is stopped within moments. */
520
+ function noteThreadTurnContext(key) {
521
+ void sampleThreadContext(key);
522
+ }
523
+ /** The debounced read of {@link sampleThreadContext}: every output of the thread moves it back. */
524
+ function scheduleThreadContextSample(key) {
525
+ const compactionState = getThreadCompactionState((0, sessionKey_1.keyToString)(key));
526
+ if (compactionState.contextSampleTimer)
527
+ clearTimeout(compactionState.contextSampleTimer);
528
+ const timer = setTimeout(() => {
529
+ compactionState.contextSampleTimer = null;
530
+ void sampleThreadContext(key);
531
+ }, compactOnIdle_1.contextSampleDebounceMs);
532
+ timer.unref?.();
533
+ compactionState.contextSampleTimer = timer;
469
534
  }
470
535
  /** Whether the agent's `compact_conversation` armed a compaction for when the turn ends (F1). */
471
536
  function checkIsDeferredCompactionArmed(key) {
@@ -477,6 +542,8 @@ function createCompaction(ports) {
477
542
  const compactionState = threadCompactionStates.get(kStr);
478
543
  if (compactionState?.idleTimer)
479
544
  clearTimeout(compactionState.idleTimer);
545
+ if (compactionState?.contextSampleTimer)
546
+ clearTimeout(compactionState.contextSampleTimer);
480
547
  threadCompactionStates.delete(kStr);
481
548
  streamedSummaryTracker.clear(kStr);
482
549
  // Drop the persisted instants too, so the NEXT session in this topic starts with
@@ -491,7 +558,7 @@ function createCompaction(ports) {
491
558
  closeReAskedQuestion(key);
492
559
  }
493
560
  /**
494
- * @description Whether the topic's process is WORKING right now (L-D2). The
561
+ * @description What keeps the topic's process WORKING right now (L-D2), by name; empty when it is idle. The
495
562
  * turn and the background work are read APART: a pending interactive question
496
563
  * makes the session report busy, but it is idle-WAITING, not running a turn —
497
564
  * D1 treats that as a FIRE condition (reject + compact + re-ask), so the
@@ -499,27 +566,49 @@ function createCompaction(ports) {
499
566
  * not yet taken in or a compaction in flight: with those the process is working
500
567
  * whatever the question says, and is neither compacted nor stopped.
501
568
  */
502
- function checkIsThreadWorking(key, adapter) {
503
- return (0, compactOnIdle_1.checkIsWorkingAtIdle)({
569
+ function getThreadWorkingSignals(key, adapter) {
570
+ return (0, compactOnIdle_1.getWorkingSignalsAtIdle)({
504
571
  isBusy: adapter.checkIsBusy?.(key) ?? false,
505
572
  hasPendingQuestion: pendingQuestions.has((0, sessionKey_1.keyToString)(key)),
506
- hasBackgroundWork: adapter.checkHasBackgroundWork?.(key) ?? false,
573
+ backgroundSignals: adapter.getBackgroundWorkSignals?.(key) ?? [],
507
574
  });
508
575
  }
509
576
  /**
510
- * @description The idle timer fired (F2 + lifecycle plan L3): nothing while the
511
- * process works; else compact once when the guard allows (D1/D2, L-D6), then — on
512
- * a backend that can be suspended — stop the process, the session kept resumable
513
- * (L-D1: whether or not the compaction ran). The stop re-checks "working" after
514
- * the compaction: a prompt taken in meanwhile keeps the process.
577
+ * Whether a SLEEPING per-turn session could have something to compress (L-D7): enabled and a turn since the last compaction. What it
578
+ * weighs is not asked here — a stopped session is read when the countdown fires ({@link sampleThreadContext}), and the figures
579
+ * saved may be missing (a state kept before they were) or a turn's reading lost — so the countdown is armed whenever there is a turn
580
+ * to compress, and the fire decides ({@link checkIsCompactionDue}).
515
581
  */
516
- /** Whether the idle compaction has something to do for the topic: enabled, not latched (D2), a turn since the last compaction. */
517
- function checkIsCompactionDue(key) {
518
- if (!getState().checkIsCompactOnIdleEnabled(key) || getState().checkIsCompactIdleLatched(key))
582
+ function checkIsCompactionPending(key) {
583
+ if (!getState().checkIsCompactOnIdleEnabled(key))
519
584
  return false;
520
585
  const { lastTurnEndAt, lastCompactionAt } = getState().getCompactIdleTracking(key);
521
586
  return lastTurnEndAt > lastCompactionAt;
522
587
  }
588
+ /**
589
+ * Whether the idle compaction has something to do for a SLEEPING per-turn session (L-D7), once it has been measured at the fire:
590
+ * pending, and the context grown enough since the last compaction ({@link getIdleFireDecision} decides the same way, so a session
591
+ * is never resumed for a compaction the fire would then refuse). A session woken only by the bot's own checks is resumed for its
592
+ * compaction too: nothing depends on who woke it.
593
+ */
594
+ function checkIsCompactionDue(key) {
595
+ if (!checkIsCompactionPending(key))
596
+ return false;
597
+ const { lastCompactionAt, baselineContextTokens, lastContextTokens } = getState().getCompactIdleTracking(key);
598
+ return (0, compactOnIdle_1.checkIsContextGrownEnough)({
599
+ contextGrowthTokens: (0, compactOnIdle_1.getContextGrowthTokens)({ baselineContextTokens, lastContextTokens }),
600
+ growthThresholdTokens: getState().getCompactGrowthTokens(key),
601
+ hasEarlierCompaction: lastCompactionAt > 0,
602
+ });
603
+ }
604
+ /**
605
+ * @description The idle timer fired (F2 + lifecycle plan L3): nothing while the
606
+ * process works; else compact once when the guard allows (D1, L-D6: a turn since the last
607
+ * compaction, the context grown enough), then — on a backend that can be suspended — stop the
608
+ * process, the session kept resumable. The compaction comes first and the stop follows it
609
+ * whether or not it ran (L-D1). The stop re-checks "working" after the compaction: a prompt taken in meanwhile
610
+ * keeps the process.
611
+ */
523
612
  async function onIdleCompactionTimerFired(key) {
524
613
  const kStr = (0, sessionKey_1.keyToString)(key);
525
614
  const adapter = getThreadAdapter(key);
@@ -534,8 +623,17 @@ function createCompaction(ports) {
534
623
  return;
535
624
  }
536
625
  }
537
- // L-D7: a sleeping per-turn session is resumed for its compaction; the stop below puts it back to sleep.
538
- if (!adapter.checkIsActive(key) && adapter.name === adapterNames_1.claudePerTurnAdapterName && checkIsCompactionDue(key)) {
626
+ const isIdleMarkMissed = getThreadCompactionState(kStr).isIdleMarkMissed;
627
+ // What the conversation weighs is read NOW, at the mark that decides on it — from its live adapter, or from its transcript when it
628
+ // sleeps — never taken on trust from the last turn's reading alone: a state kept before the figures existed has none (every topic
629
+ // idle when this was deployed), a restart can fall between a turn's end and its reading, and a reading can miss (a transcript
630
+ // not written yet). A turn that ended on an API error is no such case: the reader skips the error record and reads the last real
631
+ // call. Without it a conversation compacted before and not yet measured would sleep uncompacted at its mark.
632
+ if (!isIdleMarkMissed && checkIsCompactionPending(key))
633
+ await sampleThreadContext(key);
634
+ // L-D7: a sleeping per-turn session is resumed for its compaction; the stop below puts it back to sleep. Not for a fire that
635
+ // missed the idle mark: it compacts nothing, so waking the session only to stop it again would be for nothing.
636
+ if (!adapter.checkIsActive(key) && adapter.name === adapterNames_1.claudePerTurnAdapterName && checkIsCompactionDue(key) && !isIdleMarkMissed) {
539
637
  if (!(await resumeSleepingSessionForCompaction(key))) {
540
638
  console.log(`[compact-on-idle] ${kStr} sleeping per-turn session could not be resumed for its compaction`);
541
639
  return;
@@ -552,16 +650,23 @@ function createCompaction(ports) {
552
650
  // Both instants come from the store, so a restart no longer erases the evidence
553
651
  // that this session has an un-compacted turn (the bug: two in-memory zeros made
554
652
  // `0 > 0` false, and D2's no-reschedule rule then left the feature dead).
555
- const { lastTurnEndAt, lastCompactionAt } = getState().getCompactIdleTracking(key);
653
+ const { lastTurnEndAt, lastCompactionAt, lastActivityAt, lastHeldMarkAt, baselineContextTokens, lastContextTokens } = getState().getCompactIdleTracking(key);
654
+ const workingSignals = getThreadWorkingSignals(key, adapter);
556
655
  const decision = (0, compactOnIdle_1.getIdleFireDecision)({
557
656
  isSessionActive: adapter.checkIsActive(key),
558
- isWorking: checkIsThreadWorking(key, adapter),
657
+ workingSignals,
658
+ isIdleMarkSpent: (0, compactOnIdle_1.checkIsIdleMarkSpent)({ lastActivityAt, lastHeldMarkAt }),
659
+ isIdleMarkMissed,
559
660
  isEnabled: getState().checkIsCompactOnIdleEnabled(key),
560
- isLatched: getState().checkIsCompactIdleLatched(key),
561
661
  hasCompletedTurnSinceCompaction: lastTurnEndAt > lastCompactionAt,
562
662
  isLimitWaitArmed: checkIsLimitWaitArmed(key),
663
+ contextGrowthTokens: (0, compactOnIdle_1.getContextGrowthTokens)({ baselineContextTokens, lastContextTokens }),
664
+ growthThresholdTokens: getState().getCompactGrowthTokens(key),
665
+ hasEarlierCompaction: lastCompactionAt > 0,
563
666
  canSuspend: typeof adapter.suspendSession === 'function',
564
667
  });
668
+ if (decision.isIdleMarkHeld)
669
+ await noteIdleMarkHeld(key, decision.heldNoticeReason);
565
670
  if (decision.shouldCompact) {
566
671
  await runIdleCompaction(key, adapter);
567
672
  }
@@ -572,11 +677,9 @@ function createCompaction(ports) {
572
677
  console.log(`[compact-on-idle] ${kStr} timer fired but the compaction is skipped: ${decision.compactionSkipReasons.join(', ')}`);
573
678
  }
574
679
  if (!decision.shouldSuspend) {
575
- // D2: no reschedule. A real running turn resets the timer via
576
- // `noteThreadActivity` with its output and its end; every other miss re-arms
577
- // only on the next genuine USER message (which clears the latch) — except a
578
- // process kept only by the agent's own pending work, which is looked at
579
- // again (bounded hold).
680
+ // No reschedule. A real running turn resets the timer via `noteThreadActivity` with its output and its
681
+ // end, and any later activity re-arms it — except a process kept only by the agent's own pending work,
682
+ // which is looked at again (bounded hold).
580
683
  console.log(`[compact-on-idle] ${kStr} process kept: ${decision.suspendSkipReasons.join(', ')}`);
581
684
  armPendingWorkRecheck(key, adapter);
582
685
  return;
@@ -586,41 +689,63 @@ function createCompaction(ports) {
586
689
  console.log(`[compact-on-idle] ${kStr} process already stopped during the idle fire`);
587
690
  return;
588
691
  }
589
- if (checkIsThreadWorking(key, adapter)) {
590
- console.log(`[compact-on-idle] ${kStr} process kept: it started working during the idle fire`);
692
+ const signalsAfterFire = getThreadWorkingSignals(key, adapter);
693
+ if (signalsAfterFire.length > 0) {
694
+ console.log(`[compact-on-idle] ${kStr} process kept: it started working during the idle fire (${(0, workingSignals_1.describeWorkingSignals)(signalsAfterFire)})`);
591
695
  armPendingWorkRecheck(key, adapter);
592
696
  return;
593
697
  }
698
+ // A turn that only a pending question holds (D1) is blocked on it. Nothing was compacted here (compaction would have cleared the
699
+ // question), so the stop would find the process busy and do nothing, and its re-arm would fire this again every few minutes for
700
+ // as long as the question waits. Keep the process and do not re-arm: the answer is activity, and re-arms the countdown (D2).
701
+ if (pendingQuestions.has(kStr) && (adapter.checkIsBusy?.(key) ?? false)) {
702
+ console.log(`[compact-on-idle] ${kStr} process kept: its turn waits on a pending question; the answer re-arms the countdown`);
703
+ return;
704
+ }
594
705
  await suspendThreadSession(key);
595
706
  }
596
707
  /**
597
- * @description The idle fire found the process kept ONLY by the agent's own pending work (background tasks,
598
- * scheduled jobs, a finished task's turn on its way) — no real turn runs. Look again at the next idle window or when
599
- * the pending-work hold runs out, whichever is first: a task that never reports produces no output to re-arm the
600
- * timer, and the hold must still end. A real turn keeps D2's rule — its output re-arms the timer.
708
+ * @description The idle mark found the process working and forwent a compaction that was due: remember it (persisted — a
709
+ * restart must neither repeat the line nor compact late) and, when there is something to say, tell the topic ONCE, silently,
710
+ * that the compaction was skipped and why. A re-check of this mark never gets here: it only decides the stop.
711
+ */
712
+ async function noteIdleMarkHeld(key, noticeReason) {
713
+ // Remembered — and flushed to disk, the save is debounced — BEFORE the post: a restart or a crash between the two must not post it twice.
714
+ await getState().setCompactIdleMarkHeldAt(key);
715
+ await getState().flush();
716
+ // A tracker issue has no topic to narrate into (R6): the mark is held there all the same, silently.
717
+ if (noticeReason === null || !(0, sessionKeyCodec_1.checkIsTelegramKey)(key)) {
718
+ console.log(`[compact-on-idle] ${(0, sessionKey_1.keyToString)(key)} the idle mark is held: its compaction is forgone, nothing to tell the topic`);
719
+ return;
720
+ }
721
+ console.log(`[compact-on-idle] ${(0, sessionKey_1.keyToString)(key)} the idle mark is held (${noticeReason}): its compaction is forgone, the topic is told once`);
722
+ await replyToThread(key, (0, i18n_1.t)(idleHeldNoticeKeys[noticeReason]));
723
+ }
724
+ /**
725
+ * @description The idle fire found the process kept ONLY by signals that are not a running turn (the agent's own background
726
+ * tasks, scheduled jobs, a finished task's turn on its way, input not yet taken in, a compaction in flight). Look again at the
727
+ * next idle window or when the pending-work hold runs out, whichever is first: a task that never reports produces no output
728
+ * to re-arm the timer, and the hold must still end. A real turn keeps D2's rule — its output re-arms the timer. The look
729
+ * again decides only the STOP: a held mark never compacts late (`getIdleFireDecision`).
601
730
  */
602
731
  function armPendingWorkRecheck(key, adapter) {
603
732
  const kStr = (0, sessionKey_1.keyToString)(key);
604
733
  if (!adapter.checkIsActive(key))
605
734
  return;
606
- const isRealTurn = (0, compactOnIdle_1.checkIsBusyForRealTurn)({ isBusy: adapter.checkIsBusy?.(key) ?? false, hasPendingQuestion: pendingQuestions.has(kStr) });
607
- if (isRealTurn || !(adapter.checkHasBackgroundWork?.(key) ?? false))
735
+ const workingSignals = getThreadWorkingSignals(key, adapter);
736
+ if (workingSignals.length === 0 || workingSignals.some((signal) => signal.kind === 'turn'))
608
737
  return;
609
738
  const delayMs = (0, compactOnIdle_1.getPendingWorkRecheckDelayMs)({ idleWindowMs, holdRemainingMs: adapter.getPendingWorkHoldRemainingMs?.(key) ?? null });
610
- console.log(`[compact-on-idle] ${kStr} looks again in ${(delayMs / 60_000).toFixed(1)} min: only the agent's own pending work keeps it`);
739
+ console.log(`[compact-on-idle] ${kStr} looks again in ${(delayMs / 60_000).toFixed(1)} min: kept only by ${(0, workingSignals_1.describeWorkingSignals)(workingSignals)}, no turn runs`);
611
740
  setIdleFireTimer(key, delayMs);
612
741
  }
613
- /** The idle compaction itself (D1/D2): latch, stamp, re-ask a pending question after it, post the outcome. */
742
+ /** The idle compaction itself (D1): stamp, re-ask a pending question after it, post the outcome. */
614
743
  async function runIdleCompaction(key, adapter) {
615
744
  const kStr = (0, sessionKey_1.keyToString)(key);
616
745
  const hasPendingQuestion = pendingQuestions.has(kStr);
617
- // D2: latch the thread the instant the fire is decided (BEFORE any output) and
618
- // persist it, so a bot restart can't re-fire and no second compaction runs this
619
- // user-active period. Stamp `lastCompactionAt` too so the re-fire guard holds
620
- // even if the compaction itself runs long.
621
- void getState().setCompactIdleLatched(key, true);
622
- // Awaited (unlike the latch): the stamp must be in place BEFORE the compaction
623
- // starts, since it is what closes the "has an un-compacted turn" guard.
746
+ // Stamp `lastCompactionAt` the instant the fire is decided (BEFORE any output), persisted, so a bot restart or a compaction
747
+ // that runs long can't fire a second one: the stamp closes the «has an un-compacted turn» guard, and clears the growth
748
+ // baseline — the next turn that ends starts it over. Awaited: it must be in place BEFORE the compaction starts.
624
749
  await getState().setCompactIdleCompactedAt(key);
625
750
  // D1: a pending question at idle → reject it server-side to UNBLOCK the turn
626
751
  // (reusing each backend's abort-error swallow via rejectQuestion + SIGINT),
@@ -1092,7 +1217,7 @@ function createCompaction(ports) {
1092
1217
  // Taken before anything is awaited, so no other path uses or closes it, but with no result written yet: the label may reach no
1093
1218
  // session, and a re-ask that lands meanwhile is left as it is until that is known.
1094
1219
  takeReAskedQuestionForAnswer(key);
1095
- // A person wrote — the latch clears like for any message; the record is gone, so nothing is closed as «not answered».
1220
+ // A person wrote — the record is gone, so nothing is closed as «not answered».
1096
1221
  notePersonActivity(key);
1097
1222
  const outcome = await deliverLabel(key, label, messageContext);
1098
1223
  if (outcome === 'noSession') {
@@ -1191,6 +1316,20 @@ function createCompaction(ports) {
1191
1316
  // it, in this process or after a restart.
1192
1317
  await runNarratedCompaction(key, getThreadCompactRoute(key), 'compact-tool');
1193
1318
  }
1319
+ /**
1320
+ * @description The growth threshold of the `/compact_on_idle` command (typed value or preset button): regular topic → the
1321
+ * per-thread value; General topic → the instance-wide default. Read when the idle mark fires, so nothing is re-armed.
1322
+ */
1323
+ async function applyCompactGrowth(key, isGeneral, tokens) {
1324
+ const vars = { tokens: (0, compactOnIdle_1.formatTokenCount)(tokens) };
1325
+ if (isGeneral) {
1326
+ await getState().setCompactGrowthGlobalDefault(tokens);
1327
+ await replyToThread(key, (0, i18n_1.t)('compactOnIdle.setGrowthGlobal', vars));
1328
+ return;
1329
+ }
1330
+ await getState().setCompactGrowthOverride(key, tokens);
1331
+ await replyToThread(key, (0, i18n_1.t)('compactOnIdle.setGrowthThisTopic', vars));
1332
+ }
1194
1333
  /**
1195
1334
  * @description Shared core of the `/compact_on_idle` command + its inline
1196
1335
  * callback. Regular topic → the per-thread override; General topic → the
@@ -1224,19 +1363,35 @@ function createCompaction(ports) {
1224
1363
  return isGeneral
1225
1364
  ? {
1226
1365
  isIdleEnabled: getState().getCompactOnIdleGlobalDefault(),
1366
+ growthTokens: getState().getCompactGrowthGlobalDefault(),
1227
1367
  isSummaryEnabled: getState().getCompactSummaryGlobalDefault(),
1228
1368
  isSelfReviewEnabled: getState().getCompactSelfReviewGlobalDefault(),
1229
1369
  }
1230
1370
  : {
1231
1371
  isIdleEnabled: getState().checkIsCompactOnIdleEnabled(key),
1372
+ growthTokens: getState().getCompactGrowthTokens(key),
1232
1373
  isSummaryEnabled: getState().checkIsCompactSummaryEnabled(key),
1233
1374
  isSelfReviewEnabled: getState().checkIsCompactSelfReviewEnabled(key),
1234
1375
  };
1235
1376
  }
1377
+ /** The picker's text: a line for each setting, in the order of its keyboard's rows, from the settings as they stand. */
1378
+ function buildCompactOnIdleTitle(isGeneral, picker) {
1379
+ const vars = {
1380
+ state: picker.isIdleEnabled ? (0, i18n_1.t)('compactOnIdle.on') : (0, i18n_1.t)('compactOnIdle.off'),
1381
+ growthLine: (0, i18n_1.t)('compactOnIdle.growthLine', { tokens: (0, compactOnIdle_1.formatTokenCount)(picker.growthTokens) }),
1382
+ summaryLine: (0, i18n_1.t)('compactOnIdle.summaryLine', {
1383
+ state: picker.isSummaryEnabled ? (0, i18n_1.t)('compactSummary.on') : (0, i18n_1.t)('compactSummary.off'),
1384
+ }),
1385
+ selfReviewLine: (0, i18n_1.t)('compactOnIdle.selfReviewLine', {
1386
+ state: picker.isSelfReviewEnabled ? (0, i18n_1.t)('compactSelfReview.on') : (0, i18n_1.t)('compactSelfReview.off'),
1387
+ }),
1388
+ };
1389
+ return isGeneral ? (0, i18n_1.t)('compactOnIdle.titleGeneral', vars) : (0, i18n_1.t)('compactOnIdle.title', vars);
1390
+ }
1236
1391
  /**
1237
1392
  * @description A tap on the `/compact_on_idle` picker — either row. `apply` writes
1238
- * the setting and posts its confirmation; the keyboard is then re-rendered from the
1239
- * stored state so the ✓ of BOTH rows is right.
1393
+ * the setting and posts its confirmation; the picker — its text, whose lines name the settings, and its keyboard — is then re-rendered
1394
+ * from the stored state, so the ✓ and every figure shown are right.
1240
1395
  */
1241
1396
  async function handleCompactOnIdleCallback(ctx, apply) {
1242
1397
  const key = await authoriseContext(ctx);
@@ -1249,11 +1404,13 @@ function createCompaction(ports) {
1249
1404
  // outlive the callback, and a late answer throws — skipping the keyboard re-render below.
1250
1405
  await ctx.answerCbQuery();
1251
1406
  await withThreadLocale(key, () => apply(key, isGeneral));
1252
- // Re-render the picker keyboard so the ✓ follows the new state.
1407
+ // Re-render the picker, its text with it: the lines say the threshold and the switches, and must not keep the old ones under a ✓ that moved.
1253
1408
  const pickerMessageId = (0, callbackMessage_1.getCallbackMessageId)(ctx);
1254
1409
  if (pickerMessageId !== null) {
1255
- const keyboard = withThreadLocale(key, () => buildCompactOnIdleKeyboard(getCompactOnIdlePickerState(key, isGeneral)));
1256
- await editThreadKeyboard(key, pickerMessageId, keyboard.reply_markup, 'coi_cb');
1410
+ await withThreadLocale(key, async () => {
1411
+ const picker = getCompactOnIdlePickerState(key, isGeneral);
1412
+ await editThreadMessage(key, pickerMessageId, buildCompactOnIdleTitle(isGeneral, picker), buildCompactOnIdleKeyboard(picker));
1413
+ });
1257
1414
  }
1258
1415
  }
1259
1416
  /**
@@ -1403,28 +1560,28 @@ function createCompaction(ports) {
1403
1560
  command('compact_on_idle', async (_ctx, key, parsed) => {
1404
1561
  const arg = parsed.args.join(' ').toLowerCase();
1405
1562
  const isGeneral = checkIsGeneral(key);
1406
- if (!isGeneral) {
1407
- if (!getThreadAdapter(key).checkIsActive(key) || getThreadCompactRoute(key) === 'notSupported') {
1408
- await replyToThread(key, (0, i18n_1.t)('compactOnIdle.unsupported'));
1409
- return;
1410
- }
1563
+ // Only a raw shell, with no context to compact, is refused — like `/compact_summary`: the threshold and the toggles are read when
1564
+ // the idle mark fires, so they are as meaningful in a sleeping topic (a json-stream one is asleep most of the time) as in a live one.
1565
+ if (!isGeneral && getThreadCompactRoute(key) === 'notSupported') {
1566
+ await replyToThread(key, (0, i18n_1.t)('compactOnIdle.unsupported'));
1567
+ return;
1411
1568
  }
1412
1569
  if (arg === 'on' || arg === 'off') {
1413
1570
  await applyCompactOnIdle(key, isGeneral, arg === 'on');
1414
1571
  return;
1415
1572
  }
1573
+ // Anything else typed is the growth threshold (`50000`, `50k`); a word that is no number is refused, never shown as a picker.
1574
+ if (arg !== '') {
1575
+ const tokens = (0, compactOnIdle_1.parseCompactGrowthTokens)(arg);
1576
+ if (tokens === null) {
1577
+ await replyToThread(key, (0, i18n_1.t)('compactOnIdle.growthInvalid', { max: (0, compactOnIdle_1.formatTokenCount)(compactOnIdle_1.maxCompactGrowthTokens) }));
1578
+ return;
1579
+ }
1580
+ await applyCompactGrowth(key, isGeneral, tokens);
1581
+ return;
1582
+ }
1416
1583
  const picker = getCompactOnIdlePickerState(key, isGeneral);
1417
- const vars = {
1418
- state: picker.isIdleEnabled ? (0, i18n_1.t)('compactOnIdle.on') : (0, i18n_1.t)('compactOnIdle.off'),
1419
- summaryLine: (0, i18n_1.t)('compactOnIdle.summaryLine', {
1420
- state: picker.isSummaryEnabled ? (0, i18n_1.t)('compactSummary.on') : (0, i18n_1.t)('compactSummary.off'),
1421
- }),
1422
- selfReviewLine: (0, i18n_1.t)('compactOnIdle.selfReviewLine', {
1423
- state: picker.isSelfReviewEnabled ? (0, i18n_1.t)('compactSelfReview.on') : (0, i18n_1.t)('compactSelfReview.off'),
1424
- }),
1425
- };
1426
- const title = isGeneral ? (0, i18n_1.t)('compactOnIdle.titleGeneral', vars) : (0, i18n_1.t)('compactOnIdle.title', vars);
1427
- await replyToThread(key, title, buildCompactOnIdleKeyboard(picker));
1584
+ await replyToThread(key, buildCompactOnIdleTitle(isGeneral, picker), buildCompactOnIdleKeyboard(picker));
1428
1585
  });
1429
1586
  // `/compact_summary` — toggle writing the agent's FULL compaction summary into the
1430
1587
  // topic. Regular topic → per-thread override; General → the instance-wide default.
@@ -1481,6 +1638,14 @@ function createCompaction(ports) {
1481
1638
  function registerCompactionCallbacks() {
1482
1639
  bot.action('coi_on', (ctx) => handleCompactOnIdleCallback(ctx, (key, isGeneral) => applyCompactOnIdle(key, isGeneral, true)));
1483
1640
  bot.action('coi_off', (ctx) => handleCompactOnIdleCallback(ctx, (key, isGeneral) => applyCompactOnIdle(key, isGeneral, false)));
1641
+ bot.action(new RegExp(`^${growthButtonPrefix}(\\d+)$`), (ctx) => {
1642
+ const tokens = Number(ctx.match[1]);
1643
+ // Only a preset the picker offers: a stale or forged value changes nothing.
1644
+ return handleCompactOnIdleCallback(ctx, async (key, isGeneral) => {
1645
+ if (compactOnIdle_1.compactGrowthPresetTokens.includes(tokens))
1646
+ await applyCompactGrowth(key, isGeneral, tokens);
1647
+ });
1648
+ });
1484
1649
  bot.action('coi_sum_on', (ctx) => handleCompactOnIdleCallback(ctx, async (key, isGeneral) => {
1485
1650
  await replyToThread(key, await applyCompactSummary(key, isGeneral, true));
1486
1651
  }));
@@ -1502,7 +1667,7 @@ function createCompaction(ports) {
1502
1667
  return {
1503
1668
  checkIsThreadCompacting,
1504
1669
  noteThreadActivity,
1505
- noteThreadUserActivity,
1670
+ noteThreadTurnContext,
1506
1671
  markThreadTurnProducedOutput,
1507
1672
  postOwnCompactionInstructionGaps,
1508
1673
  syncThreadCompactSelfReviewFlags,