charness 0.0.0-stage → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (988) hide show
  1. package/.env.example +88 -0
  2. package/DEVELOPMENT.md +110 -0
  3. package/LICENSE +21 -0
  4. package/MIGRATION_1_TO_2.md +24 -0
  5. package/README.md +1024 -2
  6. package/dist/accessControl.d.ts +71 -0
  7. package/dist/accessControl.d.ts.map +1 -0
  8. package/dist/accessControl.js +108 -0
  9. package/dist/accessControl.js.map +1 -0
  10. package/dist/adapters/adapterEventRouting.d.ts +51 -0
  11. package/dist/adapters/adapterEventRouting.d.ts.map +1 -0
  12. package/dist/adapters/adapterEventRouting.js +74 -0
  13. package/dist/adapters/adapterEventRouting.js.map +1 -0
  14. package/dist/adapters/adapterNames.d.ts +19 -0
  15. package/dist/adapters/adapterNames.d.ts.map +1 -0
  16. package/dist/adapters/adapterNames.js +25 -0
  17. package/dist/adapters/adapterNames.js.map +1 -0
  18. package/dist/adapters/claudeCliAdapter.d.ts +1336 -0
  19. package/dist/adapters/claudeCliAdapter.d.ts.map +1 -0
  20. package/dist/adapters/claudeCliAdapter.js +4204 -0
  21. package/dist/adapters/claudeCliAdapter.js.map +1 -0
  22. package/dist/adapters/claudeJsonStreamAdapter.d.ts +548 -0
  23. package/dist/adapters/claudeJsonStreamAdapter.d.ts.map +1 -0
  24. package/dist/adapters/claudeJsonStreamAdapter.js +1810 -0
  25. package/dist/adapters/claudeJsonStreamAdapter.js.map +1 -0
  26. package/dist/adapters/claudePlatformFlags.d.ts +35 -0
  27. package/dist/adapters/claudePlatformFlags.d.ts.map +1 -0
  28. package/dist/adapters/claudePlatformFlags.js +46 -0
  29. package/dist/adapters/claudePlatformFlags.js.map +1 -0
  30. package/dist/adapters/createAdapter.d.ts +252 -0
  31. package/dist/adapters/createAdapter.d.ts.map +1 -0
  32. package/dist/adapters/createAdapter.js +475 -0
  33. package/dist/adapters/createAdapter.js.map +1 -0
  34. package/dist/adapters/openCodeAdapter.d.ts +1446 -0
  35. package/dist/adapters/openCodeAdapter.d.ts.map +1 -0
  36. package/dist/adapters/openCodeAdapter.js +4540 -0
  37. package/dist/adapters/openCodeAdapter.js.map +1 -0
  38. package/dist/adapters/sessionLaunchDefaults.d.ts +28 -0
  39. package/dist/adapters/sessionLaunchDefaults.d.ts.map +1 -0
  40. package/dist/adapters/sessionLaunchDefaults.js +15 -0
  41. package/dist/adapters/sessionLaunchDefaults.js.map +1 -0
  42. package/dist/adapters/terminalAdapter.d.ts +68 -0
  43. package/dist/adapters/terminalAdapter.d.ts.map +1 -0
  44. package/dist/adapters/terminalAdapter.js +371 -0
  45. package/dist/adapters/terminalAdapter.js.map +1 -0
  46. package/dist/agentLogin/agentLogin.d.ts +31 -0
  47. package/dist/agentLogin/agentLogin.d.ts.map +1 -0
  48. package/dist/agentLogin/agentLogin.js +493 -0
  49. package/dist/agentLogin/agentLogin.js.map +1 -0
  50. package/dist/agentTrigger.d.ts +28 -0
  51. package/dist/agentTrigger.d.ts.map +1 -0
  52. package/dist/agentTrigger.js +53 -0
  53. package/dist/agentTrigger.js.map +1 -0
  54. package/dist/apiErrorRetry.d.ts +209 -0
  55. package/dist/apiErrorRetry.d.ts.map +1 -0
  56. package/dist/apiErrorRetry.js +351 -0
  57. package/dist/apiErrorRetry.js.map +1 -0
  58. package/dist/apiRetryKick.d.ts +148 -0
  59. package/dist/apiRetryKick.d.ts.map +1 -0
  60. package/dist/apiRetryKick.js +158 -0
  61. package/dist/apiRetryKick.js.map +1 -0
  62. package/dist/bootClassifier.d.ts +46 -0
  63. package/dist/bootClassifier.d.ts.map +1 -0
  64. package/dist/bootClassifier.js +43 -0
  65. package/dist/bootClassifier.js.map +1 -0
  66. package/dist/bot.d.ts +207 -0
  67. package/dist/bot.d.ts.map +1 -0
  68. package/dist/bot.js +10611 -0
  69. package/dist/bot.js.map +1 -0
  70. package/dist/botFileStorage.d.ts +60 -0
  71. package/dist/botFileStorage.d.ts.map +1 -0
  72. package/dist/botFileStorage.js +205 -0
  73. package/dist/botFileStorage.js.map +1 -0
  74. package/dist/cli/applyDnsFix.d.ts +7 -0
  75. package/dist/cli/applyDnsFix.d.ts.map +1 -0
  76. package/dist/cli/applyDnsFix.js +46 -0
  77. package/dist/cli/applyDnsFix.js.map +1 -0
  78. package/dist/cli/bot.d.ts +27 -0
  79. package/dist/cli/bot.d.ts.map +1 -0
  80. package/dist/cli/bot.js +98 -0
  81. package/dist/cli/bot.js.map +1 -0
  82. package/dist/cli/botEntry.d.ts +3 -0
  83. package/dist/cli/botEntry.d.ts.map +1 -0
  84. package/dist/cli/botEntry.js +11 -0
  85. package/dist/cli/botEntry.js.map +1 -0
  86. package/dist/cli/connectorGuards.d.ts +31 -0
  87. package/dist/cli/connectorGuards.d.ts.map +1 -0
  88. package/dist/cli/connectorGuards.js +159 -0
  89. package/dist/cli/connectorGuards.js.map +1 -0
  90. package/dist/cli/envLoader.d.ts +34 -0
  91. package/dist/cli/envLoader.d.ts.map +1 -0
  92. package/dist/cli/envLoader.js +132 -0
  93. package/dist/cli/envLoader.js.map +1 -0
  94. package/dist/cli/hot.d.ts +82 -0
  95. package/dist/cli/hot.d.ts.map +1 -0
  96. package/dist/cli/hot.js +323 -0
  97. package/dist/cli/hot.js.map +1 -0
  98. package/dist/cli.d.ts +3 -0
  99. package/dist/cli.d.ts.map +1 -0
  100. package/dist/cli.js +130 -0
  101. package/dist/cli.js.map +1 -0
  102. package/dist/connectors/jira/adf.d.ts +72 -0
  103. package/dist/connectors/jira/adf.d.ts.map +1 -0
  104. package/dist/connectors/jira/adf.js +407 -0
  105. package/dist/connectors/jira/adf.js.map +1 -0
  106. package/dist/connectors/jira/agentBinaries.d.ts +14 -0
  107. package/dist/connectors/jira/agentBinaries.d.ts.map +1 -0
  108. package/dist/connectors/jira/agentBinaries.js +75 -0
  109. package/dist/connectors/jira/agentBinaries.js.map +1 -0
  110. package/dist/connectors/jira/answerSink.d.ts +52 -0
  111. package/dist/connectors/jira/answerSink.d.ts.map +1 -0
  112. package/dist/connectors/jira/answerSink.js +220 -0
  113. package/dist/connectors/jira/answerSink.js.map +1 -0
  114. package/dist/connectors/jira/attachmentDownload.d.ts +41 -0
  115. package/dist/connectors/jira/attachmentDownload.d.ts.map +1 -0
  116. package/dist/connectors/jira/attachmentDownload.js +92 -0
  117. package/dist/connectors/jira/attachmentDownload.js.map +1 -0
  118. package/dist/connectors/jira/attachmentTool.d.ts +43 -0
  119. package/dist/connectors/jira/attachmentTool.d.ts.map +1 -0
  120. package/dist/connectors/jira/attachmentTool.js +150 -0
  121. package/dist/connectors/jira/attachmentTool.js.map +1 -0
  122. package/dist/connectors/jira/client.d.ts +490 -0
  123. package/dist/connectors/jira/client.d.ts.map +1 -0
  124. package/dist/connectors/jira/client.js +453 -0
  125. package/dist/connectors/jira/client.js.map +1 -0
  126. package/dist/connectors/jira/config.d.ts +117 -0
  127. package/dist/connectors/jira/config.d.ts.map +1 -0
  128. package/dist/connectors/jira/config.js +350 -0
  129. package/dist/connectors/jira/config.js.map +1 -0
  130. package/dist/connectors/jira/configFile.d.ts +10 -0
  131. package/dist/connectors/jira/configFile.d.ts.map +1 -0
  132. package/dist/connectors/jira/configFile.js +50 -0
  133. package/dist/connectors/jira/configFile.js.map +1 -0
  134. package/dist/connectors/jira/connector.d.ts +68 -0
  135. package/dist/connectors/jira/connector.d.ts.map +1 -0
  136. package/dist/connectors/jira/connector.js +257 -0
  137. package/dist/connectors/jira/connector.js.map +1 -0
  138. package/dist/connectors/jira/contextLedger.d.ts +59 -0
  139. package/dist/connectors/jira/contextLedger.d.ts.map +1 -0
  140. package/dist/connectors/jira/contextLedger.js +194 -0
  141. package/dist/connectors/jira/contextLedger.js.map +1 -0
  142. package/dist/connectors/jira/contextPreamble.d.ts +18 -0
  143. package/dist/connectors/jira/contextPreamble.d.ts.map +1 -0
  144. package/dist/connectors/jira/contextPreamble.js +31 -0
  145. package/dist/connectors/jira/contextPreamble.js.map +1 -0
  146. package/dist/connectors/jira/inbound.d.ts +132 -0
  147. package/dist/connectors/jira/inbound.d.ts.map +1 -0
  148. package/dist/connectors/jira/inbound.js +316 -0
  149. package/dist/connectors/jira/inbound.js.map +1 -0
  150. package/dist/connectors/jira/issueBlocks.d.ts +51 -0
  151. package/dist/connectors/jira/issueBlocks.d.ts.map +1 -0
  152. package/dist/connectors/jira/issueBlocks.js +182 -0
  153. package/dist/connectors/jira/issueBlocks.js.map +1 -0
  154. package/dist/connectors/jira/issueContext.d.ts +25 -0
  155. package/dist/connectors/jira/issueContext.d.ts.map +1 -0
  156. package/dist/connectors/jira/issueContext.js +53 -0
  157. package/dist/connectors/jira/issueContext.js.map +1 -0
  158. package/dist/connectors/jira/issueDelta.d.ts +35 -0
  159. package/dist/connectors/jira/issueDelta.d.ts.map +1 -0
  160. package/dist/connectors/jira/issueDelta.js +50 -0
  161. package/dist/connectors/jira/issueDelta.js.map +1 -0
  162. package/dist/connectors/jira/mediaPlaceholders.d.ts +20 -0
  163. package/dist/connectors/jira/mediaPlaceholders.d.ts.map +1 -0
  164. package/dist/connectors/jira/mediaPlaceholders.js +92 -0
  165. package/dist/connectors/jira/mediaPlaceholders.js.map +1 -0
  166. package/dist/connectors/jira/outbound.d.ts +6 -0
  167. package/dist/connectors/jira/outbound.d.ts.map +1 -0
  168. package/dist/connectors/jira/outbound.js +38 -0
  169. package/dist/connectors/jira/outbound.js.map +1 -0
  170. package/dist/connectors/jira/prompt.d.ts +37 -0
  171. package/dist/connectors/jira/prompt.d.ts.map +1 -0
  172. package/dist/connectors/jira/prompt.js +99 -0
  173. package/dist/connectors/jira/prompt.js.map +1 -0
  174. package/dist/connectors/jira/promptSpill.d.ts +50 -0
  175. package/dist/connectors/jira/promptSpill.d.ts.map +1 -0
  176. package/dist/connectors/jira/promptSpill.js +157 -0
  177. package/dist/connectors/jira/promptSpill.js.map +1 -0
  178. package/dist/connectors/jira/promptText.d.ts +7 -0
  179. package/dist/connectors/jira/promptText.d.ts.map +1 -0
  180. package/dist/connectors/jira/promptText.js +26 -0
  181. package/dist/connectors/jira/promptText.js.map +1 -0
  182. package/dist/connectors/jira/sessionKeyCodec.d.ts +16 -0
  183. package/dist/connectors/jira/sessionKeyCodec.d.ts.map +1 -0
  184. package/dist/connectors/jira/sessionKeyCodec.js +101 -0
  185. package/dist/connectors/jira/sessionKeyCodec.js.map +1 -0
  186. package/dist/connectors/jira/trigger.d.ts +50 -0
  187. package/dist/connectors/jira/trigger.d.ts.map +1 -0
  188. package/dist/connectors/jira/trigger.js +93 -0
  189. package/dist/connectors/jira/trigger.js.map +1 -0
  190. package/dist/connectors/jira/triggerLog.d.ts +51 -0
  191. package/dist/connectors/jira/triggerLog.d.ts.map +1 -0
  192. package/dist/connectors/jira/triggerLog.js +78 -0
  193. package/dist/connectors/jira/triggerLog.js.map +1 -0
  194. package/dist/connectors/jira/unconfirmedPosts.d.ts +58 -0
  195. package/dist/connectors/jira/unconfirmedPosts.d.ts.map +1 -0
  196. package/dist/connectors/jira/unconfirmedPosts.js +105 -0
  197. package/dist/connectors/jira/unconfirmedPosts.js.map +1 -0
  198. package/dist/connectors/telegram/answerSink.d.ts +46 -0
  199. package/dist/connectors/telegram/answerSink.d.ts.map +1 -0
  200. package/dist/connectors/telegram/answerSink.js +71 -0
  201. package/dist/connectors/telegram/answerSink.js.map +1 -0
  202. package/dist/connectors/telegram/commands/autoContinueLimits.d.ts +31 -0
  203. package/dist/connectors/telegram/commands/autoContinueLimits.d.ts.map +1 -0
  204. package/dist/connectors/telegram/commands/autoContinueLimits.js +142 -0
  205. package/dist/connectors/telegram/commands/autoContinueLimits.js.map +1 -0
  206. package/dist/connectors/telegram/commands/botCore.d.ts +46 -0
  207. package/dist/connectors/telegram/commands/botCore.d.ts.map +1 -0
  208. package/dist/connectors/telegram/commands/botCore.js +3 -0
  209. package/dist/connectors/telegram/commands/botCore.js.map +1 -0
  210. package/dist/connectors/telegram/commands/callbackMessage.d.ts +12 -0
  211. package/dist/connectors/telegram/commands/callbackMessage.d.ts.map +1 -0
  212. package/dist/connectors/telegram/commands/callbackMessage.js +13 -0
  213. package/dist/connectors/telegram/commands/callbackMessage.js.map +1 -0
  214. package/dist/connectors/telegram/commands/compaction.d.ts +47 -0
  215. package/dist/connectors/telegram/commands/compaction.d.ts.map +1 -0
  216. package/dist/connectors/telegram/commands/compaction.js +868 -0
  217. package/dist/connectors/telegram/commands/compaction.js.map +1 -0
  218. package/dist/connectors/telegram/commands/displayModes.d.ts +13 -0
  219. package/dist/connectors/telegram/commands/displayModes.d.ts.map +1 -0
  220. package/dist/connectors/telegram/commands/displayModes.js +335 -0
  221. package/dist/connectors/telegram/commands/displayModes.js.map +1 -0
  222. package/dist/connectors/telegram/commands/modelProviders.d.ts +95 -0
  223. package/dist/connectors/telegram/commands/modelProviders.d.ts.map +1 -0
  224. package/dist/connectors/telegram/commands/modelProviders.js +841 -0
  225. package/dist/connectors/telegram/commands/modelProviders.js.map +1 -0
  226. package/dist/connectors/telegram/commands/reminders.d.ts +54 -0
  227. package/dist/connectors/telegram/commands/reminders.d.ts.map +1 -0
  228. package/dist/connectors/telegram/commands/reminders.js +624 -0
  229. package/dist/connectors/telegram/commands/reminders.js.map +1 -0
  230. package/dist/connectors/telegram/fileIntake.d.ts +166 -0
  231. package/dist/connectors/telegram/fileIntake.d.ts.map +1 -0
  232. package/dist/connectors/telegram/fileIntake.js +304 -0
  233. package/dist/connectors/telegram/fileIntake.js.map +1 -0
  234. package/dist/connectors/telegram/fileSendGateway.d.ts +57 -0
  235. package/dist/connectors/telegram/fileSendGateway.d.ts.map +1 -0
  236. package/dist/connectors/telegram/fileSendGateway.js +221 -0
  237. package/dist/connectors/telegram/fileSendGateway.js.map +1 -0
  238. package/dist/connectors/telegram/foreignKeyFallbacks.d.ts +52 -0
  239. package/dist/connectors/telegram/foreignKeyFallbacks.d.ts.map +1 -0
  240. package/dist/connectors/telegram/foreignKeyFallbacks.js +71 -0
  241. package/dist/connectors/telegram/foreignKeyFallbacks.js.map +1 -0
  242. package/dist/connectors/telegram/inbound.d.ts +131 -0
  243. package/dist/connectors/telegram/inbound.d.ts.map +1 -0
  244. package/dist/connectors/telegram/inbound.js +278 -0
  245. package/dist/connectors/telegram/inbound.js.map +1 -0
  246. package/dist/connectors/telegram/languagePicker.d.ts +32 -0
  247. package/dist/connectors/telegram/languagePicker.d.ts.map +1 -0
  248. package/dist/connectors/telegram/languagePicker.js +55 -0
  249. package/dist/connectors/telegram/languagePicker.js.map +1 -0
  250. package/dist/connectors/telegram/messageSplit.d.ts +62 -0
  251. package/dist/connectors/telegram/messageSplit.d.ts.map +1 -0
  252. package/dist/connectors/telegram/messageSplit.js +119 -0
  253. package/dist/connectors/telegram/messageSplit.js.map +1 -0
  254. package/dist/connectors/telegram/outbound.d.ts +62 -0
  255. package/dist/connectors/telegram/outbound.d.ts.map +1 -0
  256. package/dist/connectors/telegram/outbound.js +116 -0
  257. package/dist/connectors/telegram/outbound.js.map +1 -0
  258. package/dist/connectors/telegram/output/createOutputTransport.d.ts +34 -0
  259. package/dist/connectors/telegram/output/createOutputTransport.d.ts.map +1 -0
  260. package/dist/connectors/telegram/output/createOutputTransport.js +77 -0
  261. package/dist/connectors/telegram/output/createOutputTransport.js.map +1 -0
  262. package/dist/connectors/telegram/output/dmOutputTransport.d.ts +47 -0
  263. package/dist/connectors/telegram/output/dmOutputTransport.d.ts.map +1 -0
  264. package/dist/connectors/telegram/output/dmOutputTransport.js +412 -0
  265. package/dist/connectors/telegram/output/dmOutputTransport.js.map +1 -0
  266. package/dist/connectors/telegram/outputBacklogGlue.d.ts +38 -0
  267. package/dist/connectors/telegram/outputBacklogGlue.d.ts.map +1 -0
  268. package/dist/connectors/telegram/outputBacklogGlue.js +49 -0
  269. package/dist/connectors/telegram/outputBacklogGlue.js.map +1 -0
  270. package/dist/connectors/telegram/outputFlushPlan.d.ts +93 -0
  271. package/dist/connectors/telegram/outputFlushPlan.d.ts.map +1 -0
  272. package/dist/connectors/telegram/outputFlushPlan.js +120 -0
  273. package/dist/connectors/telegram/outputFlushPlan.js.map +1 -0
  274. package/dist/connectors/telegram/questionKeyboards.d.ts +30 -0
  275. package/dist/connectors/telegram/questionKeyboards.d.ts.map +1 -0
  276. package/dist/connectors/telegram/questionKeyboards.js +37 -0
  277. package/dist/connectors/telegram/questionKeyboards.js.map +1 -0
  278. package/dist/connectors/telegram/renderAgentHtml.d.ts +27 -0
  279. package/dist/connectors/telegram/renderAgentHtml.d.ts.map +1 -0
  280. package/dist/connectors/telegram/renderAgentHtml.js +97 -0
  281. package/dist/connectors/telegram/renderAgentHtml.js.map +1 -0
  282. package/dist/connectors/telegram/sessionKeyCodec.d.ts +28 -0
  283. package/dist/connectors/telegram/sessionKeyCodec.d.ts.map +1 -0
  284. package/dist/connectors/telegram/sessionKeyCodec.js +107 -0
  285. package/dist/connectors/telegram/sessionKeyCodec.js.map +1 -0
  286. package/dist/connectors/telegram/telegramCallGuard.d.ts +19 -0
  287. package/dist/connectors/telegram/telegramCallGuard.d.ts.map +1 -0
  288. package/dist/connectors/telegram/telegramCallGuard.js +35 -0
  289. package/dist/connectors/telegram/telegramCallGuard.js.map +1 -0
  290. package/dist/connectors/telegram/timezonePicker.d.ts +85 -0
  291. package/dist/connectors/telegram/timezonePicker.d.ts.map +1 -0
  292. package/dist/connectors/telegram/timezonePicker.js +142 -0
  293. package/dist/connectors/telegram/timezonePicker.js.map +1 -0
  294. package/dist/connectors/telegram/updateDispatcher.d.ts +85 -0
  295. package/dist/connectors/telegram/updateDispatcher.d.ts.map +1 -0
  296. package/dist/connectors/telegram/updateDispatcher.js +159 -0
  297. package/dist/connectors/telegram/updateDispatcher.js.map +1 -0
  298. package/dist/connectors/test/connector.d.ts +52 -0
  299. package/dist/connectors/test/connector.d.ts.map +1 -0
  300. package/dist/connectors/test/connector.js +143 -0
  301. package/dist/connectors/test/connector.js.map +1 -0
  302. package/dist/connectors/test/sessionKeyCodec.d.ts +25 -0
  303. package/dist/connectors/test/sessionKeyCodec.d.ts.map +1 -0
  304. package/dist/connectors/test/sessionKeyCodec.js +50 -0
  305. package/dist/connectors/test/sessionKeyCodec.js.map +1 -0
  306. package/dist/diagLog.d.ts +6 -0
  307. package/dist/diagLog.d.ts.map +1 -0
  308. package/dist/diagLog.js +58 -0
  309. package/dist/diagLog.js.map +1 -0
  310. package/dist/effortLevels.d.ts +68 -0
  311. package/dist/effortLevels.d.ts.map +1 -0
  312. package/dist/effortLevels.js +114 -0
  313. package/dist/effortLevels.js.map +1 -0
  314. package/dist/folderName.d.ts +42 -0
  315. package/dist/folderName.d.ts.map +1 -0
  316. package/dist/folderName.js +51 -0
  317. package/dist/folderName.js.map +1 -0
  318. package/dist/i18n/de.d.ts +2 -0
  319. package/dist/i18n/de.d.ts.map +1 -0
  320. package/dist/i18n/de.js +537 -0
  321. package/dist/i18n/de.js.map +1 -0
  322. package/dist/i18n/en.d.ts +7 -0
  323. package/dist/i18n/en.d.ts.map +1 -0
  324. package/dist/i18n/en.js +566 -0
  325. package/dist/i18n/en.js.map +1 -0
  326. package/dist/i18n/es.d.ts +2 -0
  327. package/dist/i18n/es.d.ts.map +1 -0
  328. package/dist/i18n/es.js +537 -0
  329. package/dist/i18n/es.js.map +1 -0
  330. package/dist/i18n/fr.d.ts +2 -0
  331. package/dist/i18n/fr.d.ts.map +1 -0
  332. package/dist/i18n/fr.js +537 -0
  333. package/dist/i18n/fr.js.map +1 -0
  334. package/dist/i18n/hi.d.ts +2 -0
  335. package/dist/i18n/hi.d.ts.map +1 -0
  336. package/dist/i18n/hi.js +537 -0
  337. package/dist/i18n/hi.js.map +1 -0
  338. package/dist/i18n/ja.d.ts +2 -0
  339. package/dist/i18n/ja.d.ts.map +1 -0
  340. package/dist/i18n/ja.js +537 -0
  341. package/dist/i18n/ja.js.map +1 -0
  342. package/dist/i18n/ka.d.ts +2 -0
  343. package/dist/i18n/ka.d.ts.map +1 -0
  344. package/dist/i18n/ka.js +537 -0
  345. package/dist/i18n/ka.js.map +1 -0
  346. package/dist/i18n/pt.d.ts +2 -0
  347. package/dist/i18n/pt.d.ts.map +1 -0
  348. package/dist/i18n/pt.js +537 -0
  349. package/dist/i18n/pt.js.map +1 -0
  350. package/dist/i18n/ru.d.ts +6 -0
  351. package/dist/i18n/ru.d.ts.map +1 -0
  352. package/dist/i18n/ru.js +540 -0
  353. package/dist/i18n/ru.js.map +1 -0
  354. package/dist/i18n/uk.d.ts +8 -0
  355. package/dist/i18n/uk.d.ts.map +1 -0
  356. package/dist/i18n/uk.js +542 -0
  357. package/dist/i18n/uk.js.map +1 -0
  358. package/dist/i18n/uz.d.ts +2 -0
  359. package/dist/i18n/uz.d.ts.map +1 -0
  360. package/dist/i18n/uz.js +537 -0
  361. package/dist/i18n/uz.js.map +1 -0
  362. package/dist/i18n/zh.d.ts +2 -0
  363. package/dist/i18n/zh.d.ts.map +1 -0
  364. package/dist/i18n/zh.js +537 -0
  365. package/dist/i18n/zh.js.map +1 -0
  366. package/dist/i18n.d.ts +115 -0
  367. package/dist/i18n.d.ts.map +1 -0
  368. package/dist/i18n.js +233 -0
  369. package/dist/i18n.js.map +1 -0
  370. package/dist/index.d.ts +3 -0
  371. package/dist/index.d.ts.map +1 -0
  372. package/dist/index.js +10 -0
  373. package/dist/index.js.map +1 -0
  374. package/dist/installManager.d.ts +99 -0
  375. package/dist/installManager.d.ts.map +1 -0
  376. package/dist/installManager.js +943 -0
  377. package/dist/installManager.js.map +1 -0
  378. package/dist/instanceLock.d.ts +161 -0
  379. package/dist/instanceLock.d.ts.map +1 -0
  380. package/dist/instanceLock.js +388 -0
  381. package/dist/instanceLock.js.map +1 -0
  382. package/dist/mcpConfig.d.ts +76 -0
  383. package/dist/mcpConfig.d.ts.map +1 -0
  384. package/dist/mcpConfig.js +270 -0
  385. package/dist/mcpConfig.js.map +1 -0
  386. package/dist/openCodeOpenQuestion.d.ts +44 -0
  387. package/dist/openCodeOpenQuestion.d.ts.map +1 -0
  388. package/dist/openCodeOpenQuestion.js +64 -0
  389. package/dist/openCodeOpenQuestion.js.map +1 -0
  390. package/dist/openCodeQuestionFlow.d.ts +105 -0
  391. package/dist/openCodeQuestionFlow.d.ts.map +1 -0
  392. package/dist/openCodeQuestionFlow.js +143 -0
  393. package/dist/openCodeQuestionFlow.js.map +1 -0
  394. package/dist/openCodeSessionRouting.d.ts +133 -0
  395. package/dist/openCodeSessionRouting.d.ts.map +1 -0
  396. package/dist/openCodeSessionRouting.js +253 -0
  397. package/dist/openCodeSessionRouting.js.map +1 -0
  398. package/dist/openCodeSessionTitle.d.ts +50 -0
  399. package/dist/openCodeSessionTitle.d.ts.map +1 -0
  400. package/dist/openCodeSessionTitle.js +84 -0
  401. package/dist/openCodeSessionTitle.js.map +1 -0
  402. package/dist/outputTrace.d.ts +108 -0
  403. package/dist/outputTrace.d.ts.map +1 -0
  404. package/dist/outputTrace.js +430 -0
  405. package/dist/outputTrace.js.map +1 -0
  406. package/dist/pendingQuestionRepost.d.ts +47 -0
  407. package/dist/pendingQuestionRepost.d.ts.map +1 -0
  408. package/dist/pendingQuestionRepost.js +29 -0
  409. package/dist/pendingQuestionRepost.js.map +1 -0
  410. package/dist/pinnedStatus.d.ts +52 -0
  411. package/dist/pinnedStatus.d.ts.map +1 -0
  412. package/dist/pinnedStatus.js +36 -0
  413. package/dist/pinnedStatus.js.map +1 -0
  414. package/dist/platform/answerSink.d.ts +93 -0
  415. package/dist/platform/answerSink.d.ts.map +1 -0
  416. package/dist/platform/answerSink.js +31 -0
  417. package/dist/platform/answerSink.js.map +1 -0
  418. package/dist/platform/capabilityFallback.d.ts +39 -0
  419. package/dist/platform/capabilityFallback.d.ts.map +1 -0
  420. package/dist/platform/capabilityFallback.js +55 -0
  421. package/dist/platform/capabilityFallback.js.map +1 -0
  422. package/dist/platform/commandRouter.d.ts +51 -0
  423. package/dist/platform/commandRouter.d.ts.map +1 -0
  424. package/dist/platform/commandRouter.js +53 -0
  425. package/dist/platform/commandRouter.js.map +1 -0
  426. package/dist/platform/connectorSet.d.ts +39 -0
  427. package/dist/platform/connectorSet.d.ts.map +1 -0
  428. package/dist/platform/connectorSet.js +55 -0
  429. package/dist/platform/connectorSet.js.map +1 -0
  430. package/dist/platform/inbound.d.ts +147 -0
  431. package/dist/platform/inbound.d.ts.map +1 -0
  432. package/dist/platform/inbound.js +18 -0
  433. package/dist/platform/inbound.js.map +1 -0
  434. package/dist/platform/outbound.d.ts +225 -0
  435. package/dist/platform/outbound.d.ts.map +1 -0
  436. package/dist/platform/outbound.js +30 -0
  437. package/dist/platform/outbound.js.map +1 -0
  438. package/dist/platform/unservedStateGuard.d.ts +27 -0
  439. package/dist/platform/unservedStateGuard.d.ts.map +1 -0
  440. package/dist/platform/unservedStateGuard.js +42 -0
  441. package/dist/platform/unservedStateGuard.js.map +1 -0
  442. package/dist/postToSession.d.ts +94 -0
  443. package/dist/postToSession.d.ts.map +1 -0
  444. package/dist/postToSession.js +56 -0
  445. package/dist/postToSession.js.map +1 -0
  446. package/dist/progressLine.d.ts +180 -0
  447. package/dist/progressLine.d.ts.map +1 -0
  448. package/dist/progressLine.js +293 -0
  449. package/dist/progressLine.js.map +1 -0
  450. package/dist/rateLimiter.d.ts +246 -0
  451. package/dist/rateLimiter.d.ts.map +1 -0
  452. package/dist/rateLimiter.js +555 -0
  453. package/dist/rateLimiter.js.map +1 -0
  454. package/dist/requests/answerRequest.d.ts +57 -0
  455. package/dist/requests/answerRequest.d.ts.map +1 -0
  456. package/dist/requests/answerRequest.js +96 -0
  457. package/dist/requests/answerRequest.js.map +1 -0
  458. package/dist/requests/answerTail.d.ts +83 -0
  459. package/dist/requests/answerTail.d.ts.map +1 -0
  460. package/dist/requests/answerTail.js +102 -0
  461. package/dist/requests/answerTail.js.map +1 -0
  462. package/dist/requests/limitWaitAnswer.d.ts +87 -0
  463. package/dist/requests/limitWaitAnswer.d.ts.map +1 -0
  464. package/dist/requests/limitWaitAnswer.js +83 -0
  465. package/dist/requests/limitWaitAnswer.js.map +1 -0
  466. package/dist/requests/requestGroup.d.ts +44 -0
  467. package/dist/requests/requestGroup.d.ts.map +1 -0
  468. package/dist/requests/requestGroup.js +63 -0
  469. package/dist/requests/requestGroup.js.map +1 -0
  470. package/dist/requests/requestHeader.d.ts +70 -0
  471. package/dist/requests/requestHeader.d.ts.map +1 -0
  472. package/dist/requests/requestHeader.js +83 -0
  473. package/dist/requests/requestHeader.js.map +1 -0
  474. package/dist/requests/requestLedger.d.ts +217 -0
  475. package/dist/requests/requestLedger.d.ts.map +1 -0
  476. package/dist/requests/requestLedger.js +468 -0
  477. package/dist/requests/requestLedger.js.map +1 -0
  478. package/dist/requests/sessionTurnProbe.d.ts +52 -0
  479. package/dist/requests/sessionTurnProbe.d.ts.map +1 -0
  480. package/dist/requests/sessionTurnProbe.js +29 -0
  481. package/dist/requests/sessionTurnProbe.js.map +1 -0
  482. package/dist/requests/types.d.ts +181 -0
  483. package/dist/requests/types.d.ts.map +1 -0
  484. package/dist/requests/types.js +9 -0
  485. package/dist/requests/types.js.map +1 -0
  486. package/dist/requests/wakeUpEngine.d.ts +160 -0
  487. package/dist/requests/wakeUpEngine.d.ts.map +1 -0
  488. package/dist/requests/wakeUpEngine.js +399 -0
  489. package/dist/requests/wakeUpEngine.js.map +1 -0
  490. package/dist/requests/wakeUpRules.d.ts +151 -0
  491. package/dist/requests/wakeUpRules.d.ts.map +1 -0
  492. package/dist/requests/wakeUpRules.js +167 -0
  493. package/dist/requests/wakeUpRules.js.map +1 -0
  494. package/dist/resumeContext.d.ts +87 -0
  495. package/dist/resumeContext.d.ts.map +1 -0
  496. package/dist/resumeContext.js +114 -0
  497. package/dist/resumeContext.js.map +1 -0
  498. package/dist/scheduler/checkRun.d.ts +95 -0
  499. package/dist/scheduler/checkRun.d.ts.map +1 -0
  500. package/dist/scheduler/checkRun.js +172 -0
  501. package/dist/scheduler/checkRun.js.map +1 -0
  502. package/dist/scheduler/delivery.d.ts +99 -0
  503. package/dist/scheduler/delivery.d.ts.map +1 -0
  504. package/dist/scheduler/delivery.js +212 -0
  505. package/dist/scheduler/delivery.js.map +1 -0
  506. package/dist/scheduler/deliveryKind.d.ts +29 -0
  507. package/dist/scheduler/deliveryKind.d.ts.map +1 -0
  508. package/dist/scheduler/deliveryKind.js +39 -0
  509. package/dist/scheduler/deliveryKind.js.map +1 -0
  510. package/dist/scheduler/directoryThreads.d.ts +19 -0
  511. package/dist/scheduler/directoryThreads.d.ts.map +1 -0
  512. package/dist/scheduler/directoryThreads.js +28 -0
  513. package/dist/scheduler/directoryThreads.js.map +1 -0
  514. package/dist/scheduler/engine.d.ts +77 -0
  515. package/dist/scheduler/engine.d.ts.map +1 -0
  516. package/dist/scheduler/engine.js +337 -0
  517. package/dist/scheduler/engine.js.map +1 -0
  518. package/dist/scheduler/injection.d.ts +102 -0
  519. package/dist/scheduler/injection.d.ts.map +1 -0
  520. package/dist/scheduler/injection.js +122 -0
  521. package/dist/scheduler/injection.js.map +1 -0
  522. package/dist/scheduler/mcpBoot.d.ts +65 -0
  523. package/dist/scheduler/mcpBoot.d.ts.map +1 -0
  524. package/dist/scheduler/mcpBoot.js +60 -0
  525. package/dist/scheduler/mcpBoot.js.map +1 -0
  526. package/dist/scheduler/mcpSurface.d.ts +355 -0
  527. package/dist/scheduler/mcpSurface.d.ts.map +1 -0
  528. package/dist/scheduler/mcpSurface.js +1257 -0
  529. package/dist/scheduler/mcpSurface.js.map +1 -0
  530. package/dist/scheduler/rebindResume.d.ts +27 -0
  531. package/dist/scheduler/rebindResume.d.ts.map +1 -0
  532. package/dist/scheduler/rebindResume.js +17 -0
  533. package/dist/scheduler/rebindResume.js.map +1 -0
  534. package/dist/scheduler/recurrence.d.ts +58 -0
  535. package/dist/scheduler/recurrence.d.ts.map +1 -0
  536. package/dist/scheduler/recurrence.js +210 -0
  537. package/dist/scheduler/recurrence.js.map +1 -0
  538. package/dist/scheduler/runLedger.d.ts +59 -0
  539. package/dist/scheduler/runLedger.d.ts.map +1 -0
  540. package/dist/scheduler/runLedger.js +54 -0
  541. package/dist/scheduler/runLedger.js.map +1 -0
  542. package/dist/scheduler/store.d.ts +97 -0
  543. package/dist/scheduler/store.d.ts.map +1 -0
  544. package/dist/scheduler/store.js +124 -0
  545. package/dist/scheduler/store.js.map +1 -0
  546. package/dist/scheduler/timezoneRecompute.d.ts +61 -0
  547. package/dist/scheduler/timezoneRecompute.d.ts.map +1 -0
  548. package/dist/scheduler/timezoneRecompute.js +46 -0
  549. package/dist/scheduler/timezoneRecompute.js.map +1 -0
  550. package/dist/scheduler/types.d.ts +139 -0
  551. package/dist/scheduler/types.d.ts.map +1 -0
  552. package/dist/scheduler/types.js +8 -0
  553. package/dist/scheduler/types.js.map +1 -0
  554. package/dist/sendErrorClassifier.d.ts +45 -0
  555. package/dist/sendErrorClassifier.d.ts.map +1 -0
  556. package/dist/sendErrorClassifier.js +65 -0
  557. package/dist/sendErrorClassifier.js.map +1 -0
  558. package/dist/sessionKey.d.ts +136 -0
  559. package/dist/sessionKey.d.ts.map +1 -0
  560. package/dist/sessionKey.js +153 -0
  561. package/dist/sessionKey.js.map +1 -0
  562. package/dist/sessionPick.d.ts +42 -0
  563. package/dist/sessionPick.d.ts.map +1 -0
  564. package/dist/sessionPick.js +39 -0
  565. package/dist/sessionPick.js.map +1 -0
  566. package/dist/shutdown.d.ts +126 -0
  567. package/dist/shutdown.d.ts.map +1 -0
  568. package/dist/shutdown.js +164 -0
  569. package/dist/shutdown.js.map +1 -0
  570. package/dist/startupPromptBuffer.d.ts +85 -0
  571. package/dist/startupPromptBuffer.d.ts.map +1 -0
  572. package/dist/startupPromptBuffer.js +123 -0
  573. package/dist/startupPromptBuffer.js.map +1 -0
  574. package/dist/state.d.ts +1245 -0
  575. package/dist/state.d.ts.map +1 -0
  576. package/dist/state.js +1830 -0
  577. package/dist/state.js.map +1 -0
  578. package/dist/threadContextPreamble.d.ts +89 -0
  579. package/dist/threadContextPreamble.d.ts.map +1 -0
  580. package/dist/threadContextPreamble.js +102 -0
  581. package/dist/threadContextPreamble.js.map +1 -0
  582. package/dist/threadRouting.d.ts +164 -0
  583. package/dist/threadRouting.d.ts.map +1 -0
  584. package/dist/threadRouting.js +182 -0
  585. package/dist/threadRouting.js.map +1 -0
  586. package/dist/types.d.ts +1015 -0
  587. package/dist/types.d.ts.map +1 -0
  588. package/dist/types.js +3 -0
  589. package/dist/types.js.map +1 -0
  590. package/dist/utils/abortableFifo.d.ts +10 -0
  591. package/dist/utils/abortableFifo.d.ts.map +1 -0
  592. package/dist/utils/abortableFifo.js +55 -0
  593. package/dist/utils/abortableFifo.js.map +1 -0
  594. package/dist/utils/adoptedToolList.d.ts +27 -0
  595. package/dist/utils/adoptedToolList.d.ts.map +1 -0
  596. package/dist/utils/adoptedToolList.js +22 -0
  597. package/dist/utils/adoptedToolList.js.map +1 -0
  598. package/dist/utils/agentEnvironment.d.ts +42 -0
  599. package/dist/utils/agentEnvironment.d.ts.map +1 -0
  600. package/dist/utils/agentEnvironment.js +122 -0
  601. package/dist/utils/agentEnvironment.js.map +1 -0
  602. package/dist/utils/ansiClean.d.ts +11 -0
  603. package/dist/utils/ansiClean.d.ts.map +1 -0
  604. package/dist/utils/ansiClean.js +139 -0
  605. package/dist/utils/ansiClean.js.map +1 -0
  606. package/dist/utils/autoContinueOnLimit.d.ts +49 -0
  607. package/dist/utils/autoContinueOnLimit.d.ts.map +1 -0
  608. package/dist/utils/autoContinueOnLimit.js +69 -0
  609. package/dist/utils/autoContinueOnLimit.js.map +1 -0
  610. package/dist/utils/canonicalPathContainment.d.ts +7 -0
  611. package/dist/utils/canonicalPathContainment.d.ts.map +1 -0
  612. package/dist/utils/canonicalPathContainment.js +48 -0
  613. package/dist/utils/canonicalPathContainment.js.map +1 -0
  614. package/dist/utils/claudeAuthLogin.d.ts +71 -0
  615. package/dist/utils/claudeAuthLogin.d.ts.map +1 -0
  616. package/dist/utils/claudeAuthLogin.js +93 -0
  617. package/dist/utils/claudeAuthLogin.js.map +1 -0
  618. package/dist/utils/claudeChunkClassifier.d.ts +97 -0
  619. package/dist/utils/claudeChunkClassifier.d.ts.map +1 -0
  620. package/dist/utils/claudeChunkClassifier.js +254 -0
  621. package/dist/utils/claudeChunkClassifier.js.map +1 -0
  622. package/dist/utils/claudeCodeVersion.d.ts +31 -0
  623. package/dist/utils/claudeCodeVersion.d.ts.map +1 -0
  624. package/dist/utils/claudeCodeVersion.js +62 -0
  625. package/dist/utils/claudeCodeVersion.js.map +1 -0
  626. package/dist/utils/claudeCompactHook.d.ts +64 -0
  627. package/dist/utils/claudeCompactHook.d.ts.map +1 -0
  628. package/dist/utils/claudeCompactHook.js +98 -0
  629. package/dist/utils/claudeCompactHook.js.map +1 -0
  630. package/dist/utils/claudeLivenessAction.d.ts +208 -0
  631. package/dist/utils/claudeLivenessAction.d.ts.map +1 -0
  632. package/dist/utils/claudeLivenessAction.js +135 -0
  633. package/dist/utils/claudeLivenessAction.js.map +1 -0
  634. package/dist/utils/claudeMcpHeal.d.ts +92 -0
  635. package/dist/utils/claudeMcpHeal.d.ts.map +1 -0
  636. package/dist/utils/claudeMcpHeal.js +91 -0
  637. package/dist/utils/claudeMcpHeal.js.map +1 -0
  638. package/dist/utils/claudeRelayRouting.d.ts +86 -0
  639. package/dist/utils/claudeRelayRouting.d.ts.map +1 -0
  640. package/dist/utils/claudeRelayRouting.js +159 -0
  641. package/dist/utils/claudeRelayRouting.js.map +1 -0
  642. package/dist/utils/claudeRuntimeInfo.d.ts +26 -0
  643. package/dist/utils/claudeRuntimeInfo.d.ts.map +1 -0
  644. package/dist/utils/claudeRuntimeInfo.js +151 -0
  645. package/dist/utils/claudeRuntimeInfo.js.map +1 -0
  646. package/dist/utils/claudeScrapeShapes.d.ts +256 -0
  647. package/dist/utils/claudeScrapeShapes.d.ts.map +1 -0
  648. package/dist/utils/claudeScrapeShapes.js +290 -0
  649. package/dist/utils/claudeScrapeShapes.js.map +1 -0
  650. package/dist/utils/claudeSessionTitle.d.ts +27 -0
  651. package/dist/utils/claudeSessionTitle.d.ts.map +1 -0
  652. package/dist/utils/claudeSessionTitle.js +90 -0
  653. package/dist/utils/claudeSessionTitle.js.map +1 -0
  654. package/dist/utils/claudeStreamJson.d.ts +202 -0
  655. package/dist/utils/claudeStreamJson.d.ts.map +1 -0
  656. package/dist/utils/claudeStreamJson.js +351 -0
  657. package/dist/utils/claudeStreamJson.js.map +1 -0
  658. package/dist/utils/claudeSubagentTail.d.ts +93 -0
  659. package/dist/utils/claudeSubagentTail.d.ts.map +1 -0
  660. package/dist/utils/claudeSubagentTail.js +136 -0
  661. package/dist/utils/claudeSubagentTail.js.map +1 -0
  662. package/dist/utils/clearThreadOutputQueues.d.ts +43 -0
  663. package/dist/utils/clearThreadOutputQueues.d.ts.map +1 -0
  664. package/dist/utils/clearThreadOutputQueues.js +39 -0
  665. package/dist/utils/clearThreadOutputQueues.js.map +1 -0
  666. package/dist/utils/compactCommandRoute.d.ts +45 -0
  667. package/dist/utils/compactCommandRoute.d.ts.map +1 -0
  668. package/dist/utils/compactCommandRoute.js +36 -0
  669. package/dist/utils/compactCommandRoute.js.map +1 -0
  670. package/dist/utils/compactOnIdle.d.ts +329 -0
  671. package/dist/utils/compactOnIdle.d.ts.map +1 -0
  672. package/dist/utils/compactOnIdle.js +379 -0
  673. package/dist/utils/compactOnIdle.js.map +1 -0
  674. package/dist/utils/consoleFileTap.d.ts +51 -0
  675. package/dist/utils/consoleFileTap.d.ts.map +1 -0
  676. package/dist/utils/consoleFileTap.js +86 -0
  677. package/dist/utils/consoleFileTap.js.map +1 -0
  678. package/dist/utils/displayVerbosity.d.ts +44 -0
  679. package/dist/utils/displayVerbosity.d.ts.map +1 -0
  680. package/dist/utils/displayVerbosity.js +75 -0
  681. package/dist/utils/displayVerbosity.js.map +1 -0
  682. package/dist/utils/download.d.ts +72 -0
  683. package/dist/utils/download.d.ts.map +1 -0
  684. package/dist/utils/download.js +216 -0
  685. package/dist/utils/download.js.map +1 -0
  686. package/dist/utils/draftFinalize.d.ts +110 -0
  687. package/dist/utils/draftFinalize.d.ts.map +1 -0
  688. package/dist/utils/draftFinalize.js +100 -0
  689. package/dist/utils/draftFinalize.js.map +1 -0
  690. package/dist/utils/draftId.d.ts +36 -0
  691. package/dist/utils/draftId.d.ts.map +1 -0
  692. package/dist/utils/draftId.js +46 -0
  693. package/dist/utils/draftId.js.map +1 -0
  694. package/dist/utils/draftPacer.d.ts +72 -0
  695. package/dist/utils/draftPacer.d.ts.map +1 -0
  696. package/dist/utils/draftPacer.js +53 -0
  697. package/dist/utils/draftPacer.js.map +1 -0
  698. package/dist/utils/effortStartupKeystroke.d.ts +20 -0
  699. package/dist/utils/effortStartupKeystroke.d.ts.map +1 -0
  700. package/dist/utils/effortStartupKeystroke.js +28 -0
  701. package/dist/utils/effortStartupKeystroke.js.map +1 -0
  702. package/dist/utils/ensureSessionPlan.d.ts +70 -0
  703. package/dist/utils/ensureSessionPlan.d.ts.map +1 -0
  704. package/dist/utils/ensureSessionPlan.js +54 -0
  705. package/dist/utils/ensureSessionPlan.js.map +1 -0
  706. package/dist/utils/fileSendPlan.d.ts +217 -0
  707. package/dist/utils/fileSendPlan.d.ts.map +1 -0
  708. package/dist/utils/fileSendPlan.js +291 -0
  709. package/dist/utils/fileSendPlan.js.map +1 -0
  710. package/dist/utils/fileSendService.d.ts +94 -0
  711. package/dist/utils/fileSendService.d.ts.map +1 -0
  712. package/dist/utils/fileSendService.js +387 -0
  713. package/dist/utils/fileSendService.js.map +1 -0
  714. package/dist/utils/groupFinalizePlan.d.ts +38 -0
  715. package/dist/utils/groupFinalizePlan.d.ts.map +1 -0
  716. package/dist/utils/groupFinalizePlan.js +35 -0
  717. package/dist/utils/groupFinalizePlan.js.map +1 -0
  718. package/dist/utils/identicalOutputGuard.d.ts +83 -0
  719. package/dist/utils/identicalOutputGuard.d.ts.map +1 -0
  720. package/dist/utils/identicalOutputGuard.js +99 -0
  721. package/dist/utils/identicalOutputGuard.js.map +1 -0
  722. package/dist/utils/isoTimestamp.d.ts +16 -0
  723. package/dist/utils/isoTimestamp.d.ts.map +1 -0
  724. package/dist/utils/isoTimestamp.js +34 -0
  725. package/dist/utils/isoTimestamp.js.map +1 -0
  726. package/dist/utils/jsonStreamBusyWatchdog.d.ts +130 -0
  727. package/dist/utils/jsonStreamBusyWatchdog.d.ts.map +1 -0
  728. package/dist/utils/jsonStreamBusyWatchdog.js +122 -0
  729. package/dist/utils/jsonStreamBusyWatchdog.js.map +1 -0
  730. package/dist/utils/jsonStreamHost.d.ts +227 -0
  731. package/dist/utils/jsonStreamHost.d.ts.map +1 -0
  732. package/dist/utils/jsonStreamHost.js +417 -0
  733. package/dist/utils/jsonStreamHost.js.map +1 -0
  734. package/dist/utils/keyedTransitionQueue.d.ts +18 -0
  735. package/dist/utils/keyedTransitionQueue.d.ts.map +1 -0
  736. package/dist/utils/keyedTransitionQueue.js +34 -0
  737. package/dist/utils/keyedTransitionQueue.js.map +1 -0
  738. package/dist/utils/limitEpisodeRecovery.d.ts +92 -0
  739. package/dist/utils/limitEpisodeRecovery.d.ts.map +1 -0
  740. package/dist/utils/limitEpisodeRecovery.js +133 -0
  741. package/dist/utils/limitEpisodeRecovery.js.map +1 -0
  742. package/dist/utils/limitHeldPromptQueue.d.ts +48 -0
  743. package/dist/utils/limitHeldPromptQueue.d.ts.map +1 -0
  744. package/dist/utils/limitHeldPromptQueue.js +59 -0
  745. package/dist/utils/limitHeldPromptQueue.js.map +1 -0
  746. package/dist/utils/limitHeldPrompts.d.ts +58 -0
  747. package/dist/utils/limitHeldPrompts.d.ts.map +1 -0
  748. package/dist/utils/limitHeldPrompts.js +65 -0
  749. package/dist/utils/limitHeldPrompts.js.map +1 -0
  750. package/dist/utils/linkPreviewSuppression.d.ts +18 -0
  751. package/dist/utils/linkPreviewSuppression.d.ts.map +1 -0
  752. package/dist/utils/linkPreviewSuppression.js +37 -0
  753. package/dist/utils/linkPreviewSuppression.js.map +1 -0
  754. package/dist/utils/localClock.d.ts +15 -0
  755. package/dist/utils/localClock.d.ts.map +1 -0
  756. package/dist/utils/localClock.js +29 -0
  757. package/dist/utils/localClock.js.map +1 -0
  758. package/dist/utils/markdownTableRender.d.ts +83 -0
  759. package/dist/utils/markdownTableRender.d.ts.map +1 -0
  760. package/dist/utils/markdownTableRender.js +298 -0
  761. package/dist/utils/markdownTableRender.js.map +1 -0
  762. package/dist/utils/mediaGroupCollector.d.ts +51 -0
  763. package/dist/utils/mediaGroupCollector.d.ts.map +1 -0
  764. package/dist/utils/mediaGroupCollector.js +90 -0
  765. package/dist/utils/mediaGroupCollector.js.map +1 -0
  766. package/dist/utils/messageSendService.d.ts +136 -0
  767. package/dist/utils/messageSendService.d.ts.map +1 -0
  768. package/dist/utils/messageSendService.js +165 -0
  769. package/dist/utils/messageSendService.js.map +1 -0
  770. package/dist/utils/minutesOverride.d.ts +7 -0
  771. package/dist/utils/minutesOverride.d.ts.map +1 -0
  772. package/dist/utils/minutesOverride.js +16 -0
  773. package/dist/utils/minutesOverride.js.map +1 -0
  774. package/dist/utils/modelPickerPlan.d.ts +119 -0
  775. package/dist/utils/modelPickerPlan.d.ts.map +1 -0
  776. package/dist/utils/modelPickerPlan.js +171 -0
  777. package/dist/utils/modelPickerPlan.js.map +1 -0
  778. package/dist/utils/modelSetReplyDecision.d.ts +67 -0
  779. package/dist/utils/modelSetReplyDecision.d.ts.map +1 -0
  780. package/dist/utils/modelSetReplyDecision.js +27 -0
  781. package/dist/utils/modelSetReplyDecision.js.map +1 -0
  782. package/dist/utils/openCodeAuthLogin.d.ts +181 -0
  783. package/dist/utils/openCodeAuthLogin.d.ts.map +1 -0
  784. package/dist/utils/openCodeAuthLogin.js +393 -0
  785. package/dist/utils/openCodeAuthLogin.js.map +1 -0
  786. package/dist/utils/openCodeCompactPlugin.d.ts +81 -0
  787. package/dist/utils/openCodeCompactPlugin.d.ts.map +1 -0
  788. package/dist/utils/openCodeCompactPlugin.js +146 -0
  789. package/dist/utils/openCodeCompactPlugin.js.map +1 -0
  790. package/dist/utils/openCodeTurnActivity.d.ts +67 -0
  791. package/dist/utils/openCodeTurnActivity.d.ts.map +1 -0
  792. package/dist/utils/openCodeTurnActivity.js +27 -0
  793. package/dist/utils/openCodeTurnActivity.js.map +1 -0
  794. package/dist/utils/outputDebounce.d.ts +24 -0
  795. package/dist/utils/outputDebounce.d.ts.map +1 -0
  796. package/dist/utils/outputDebounce.js +30 -0
  797. package/dist/utils/outputDebounce.js.map +1 -0
  798. package/dist/utils/outputFlushTiming.d.ts +54 -0
  799. package/dist/utils/outputFlushTiming.d.ts.map +1 -0
  800. package/dist/utils/outputFlushTiming.js +48 -0
  801. package/dist/utils/outputFlushTiming.js.map +1 -0
  802. package/dist/utils/paginateList.d.ts +25 -0
  803. package/dist/utils/paginateList.d.ts.map +1 -0
  804. package/dist/utils/paginateList.js +32 -0
  805. package/dist/utils/paginateList.js.map +1 -0
  806. package/dist/utils/paneDiff.d.ts +55 -0
  807. package/dist/utils/paneDiff.d.ts.map +1 -0
  808. package/dist/utils/paneDiff.js +88 -0
  809. package/dist/utils/paneDiff.js.map +1 -0
  810. package/dist/utils/paneResizeGuard.d.ts +69 -0
  811. package/dist/utils/paneResizeGuard.d.ts.map +1 -0
  812. package/dist/utils/paneResizeGuard.js +91 -0
  813. package/dist/utils/paneResizeGuard.js.map +1 -0
  814. package/dist/utils/persistAdapterSessionIds.d.ts +39 -0
  815. package/dist/utils/persistAdapterSessionIds.d.ts.map +1 -0
  816. package/dist/utils/persistAdapterSessionIds.js +28 -0
  817. package/dist/utils/persistAdapterSessionIds.js.map +1 -0
  818. package/dist/utils/pinnedBannerSkipDecision.d.ts +44 -0
  819. package/dist/utils/pinnedBannerSkipDecision.d.ts.map +1 -0
  820. package/dist/utils/pinnedBannerSkipDecision.js +20 -0
  821. package/dist/utils/pinnedBannerSkipDecision.js.map +1 -0
  822. package/dist/utils/pollBackoff.d.ts +45 -0
  823. package/dist/utils/pollBackoff.d.ts.map +1 -0
  824. package/dist/utils/pollBackoff.js +44 -0
  825. package/dist/utils/pollBackoff.js.map +1 -0
  826. package/dist/utils/promptDelivery.d.ts +46 -0
  827. package/dist/utils/promptDelivery.d.ts.map +1 -0
  828. package/dist/utils/promptDelivery.js +49 -0
  829. package/dist/utils/promptDelivery.js.map +1 -0
  830. package/dist/utils/providerDisconnectPlan.d.ts +82 -0
  831. package/dist/utils/providerDisconnectPlan.d.ts.map +1 -0
  832. package/dist/utils/providerDisconnectPlan.js +110 -0
  833. package/dist/utils/providerDisconnectPlan.js.map +1 -0
  834. package/dist/utils/rateLimitLog.d.ts +48 -0
  835. package/dist/utils/rateLimitLog.d.ts.map +1 -0
  836. package/dist/utils/rateLimitLog.js +43 -0
  837. package/dist/utils/rateLimitLog.js.map +1 -0
  838. package/dist/utils/recentRelayWindow.d.ts +165 -0
  839. package/dist/utils/recentRelayWindow.d.ts.map +1 -0
  840. package/dist/utils/recentRelayWindow.js +284 -0
  841. package/dist/utils/recentRelayWindow.js.map +1 -0
  842. package/dist/utils/recvPreviewRedaction.d.ts +23 -0
  843. package/dist/utils/recvPreviewRedaction.d.ts.map +1 -0
  844. package/dist/utils/recvPreviewRedaction.js +39 -0
  845. package/dist/utils/recvPreviewRedaction.js.map +1 -0
  846. package/dist/utils/reminderFlow.d.ts +148 -0
  847. package/dist/utils/reminderFlow.d.ts.map +1 -0
  848. package/dist/utils/reminderFlow.js +122 -0
  849. package/dist/utils/reminderFlow.js.map +1 -0
  850. package/dist/utils/reminderScheduleText.d.ts +87 -0
  851. package/dist/utils/reminderScheduleText.d.ts.map +1 -0
  852. package/dist/utils/reminderScheduleText.js +135 -0
  853. package/dist/utils/reminderScheduleText.js.map +1 -0
  854. package/dist/utils/reminderWizard.d.ts +710 -0
  855. package/dist/utils/reminderWizard.d.ts.map +1 -0
  856. package/dist/utils/reminderWizard.js +1164 -0
  857. package/dist/utils/reminderWizard.js.map +1 -0
  858. package/dist/utils/replyQuote.d.ts +111 -0
  859. package/dist/utils/replyQuote.d.ts.map +1 -0
  860. package/dist/utils/replyQuote.js +122 -0
  861. package/dist/utils/replyQuote.js.map +1 -0
  862. package/dist/utils/resolveBinary.d.ts +25 -0
  863. package/dist/utils/resolveBinary.d.ts.map +1 -0
  864. package/dist/utils/resolveBinary.js +99 -0
  865. package/dist/utils/resolveBinary.js.map +1 -0
  866. package/dist/utils/retryAfterHeader.d.ts +7 -0
  867. package/dist/utils/retryAfterHeader.d.ts.map +1 -0
  868. package/dist/utils/retryAfterHeader.js +17 -0
  869. package/dist/utils/retryAfterHeader.js.map +1 -0
  870. package/dist/utils/rotatingJsonlFile.d.ts +40 -0
  871. package/dist/utils/rotatingJsonlFile.d.ts.map +1 -0
  872. package/dist/utils/rotatingJsonlFile.js +106 -0
  873. package/dist/utils/rotatingJsonlFile.js.map +1 -0
  874. package/dist/utils/rotatingLogFile.d.ts +25 -0
  875. package/dist/utils/rotatingLogFile.d.ts.map +1 -0
  876. package/dist/utils/rotatingLogFile.js +74 -0
  877. package/dist/utils/rotatingLogFile.js.map +1 -0
  878. package/dist/utils/sendRateTracker.d.ts +59 -0
  879. package/dist/utils/sendRateTracker.d.ts.map +1 -0
  880. package/dist/utils/sendRateTracker.js +144 -0
  881. package/dist/utils/sendRateTracker.js.map +1 -0
  882. package/dist/utils/serialQueue.d.ts +5 -0
  883. package/dist/utils/serialQueue.d.ts.map +1 -0
  884. package/dist/utils/serialQueue.js +14 -0
  885. package/dist/utils/serialQueue.js.map +1 -0
  886. package/dist/utils/sseStreamLifecycle.d.ts +32 -0
  887. package/dist/utils/sseStreamLifecycle.d.ts.map +1 -0
  888. package/dist/utils/sseStreamLifecycle.js +41 -0
  889. package/dist/utils/sseStreamLifecycle.js.map +1 -0
  890. package/dist/utils/startupReadiness.d.ts +119 -0
  891. package/dist/utils/startupReadiness.d.ts.map +1 -0
  892. package/dist/utils/startupReadiness.js +148 -0
  893. package/dist/utils/startupReadiness.js.map +1 -0
  894. package/dist/utils/statusFlushDecision.d.ts +18 -0
  895. package/dist/utils/statusFlushDecision.d.ts.map +1 -0
  896. package/dist/utils/statusFlushDecision.js +53 -0
  897. package/dist/utils/statusFlushDecision.js.map +1 -0
  898. package/dist/utils/subagentRender.d.ts +52 -0
  899. package/dist/utils/subagentRender.d.ts.map +1 -0
  900. package/dist/utils/subagentRender.js +66 -0
  901. package/dist/utils/subagentRender.js.map +1 -0
  902. package/dist/utils/subagentStatusRender.d.ts +90 -0
  903. package/dist/utils/subagentStatusRender.d.ts.map +1 -0
  904. package/dist/utils/subagentStatusRender.js +124 -0
  905. package/dist/utils/subagentStatusRender.js.map +1 -0
  906. package/dist/utils/telegramError.d.ts +2 -0
  907. package/dist/utils/telegramError.d.ts.map +1 -0
  908. package/dist/utils/telegramError.js +16 -0
  909. package/dist/utils/telegramError.js.map +1 -0
  910. package/dist/utils/terminalEmitPlan.d.ts +74 -0
  911. package/dist/utils/terminalEmitPlan.d.ts.map +1 -0
  912. package/dist/utils/terminalEmitPlan.js +86 -0
  913. package/dist/utils/terminalEmitPlan.js.map +1 -0
  914. package/dist/utils/thinkingRender.d.ts +74 -0
  915. package/dist/utils/thinkingRender.d.ts.map +1 -0
  916. package/dist/utils/thinkingRender.js +85 -0
  917. package/dist/utils/thinkingRender.js.map +1 -0
  918. package/dist/utils/threadStatusReport.d.ts +55 -0
  919. package/dist/utils/threadStatusReport.d.ts.map +1 -0
  920. package/dist/utils/threadStatusReport.js +65 -0
  921. package/dist/utils/threadStatusReport.js.map +1 -0
  922. package/dist/utils/threadToggle.d.ts +29 -0
  923. package/dist/utils/threadToggle.d.ts.map +1 -0
  924. package/dist/utils/threadToggle.js +39 -0
  925. package/dist/utils/threadToggle.js.map +1 -0
  926. package/dist/utils/timezone.d.ts +125 -0
  927. package/dist/utils/timezone.d.ts.map +1 -0
  928. package/dist/utils/timezone.js +278 -0
  929. package/dist/utils/timezone.js.map +1 -0
  930. package/dist/utils/tmuxExec.d.ts +61 -0
  931. package/dist/utils/tmuxExec.d.ts.map +1 -0
  932. package/dist/utils/tmuxExec.js +109 -0
  933. package/dist/utils/tmuxExec.js.map +1 -0
  934. package/dist/utils/tmuxSessionName.d.ts +34 -0
  935. package/dist/utils/tmuxSessionName.d.ts.map +1 -0
  936. package/dist/utils/tmuxSessionName.js +51 -0
  937. package/dist/utils/tmuxSessionName.js.map +1 -0
  938. package/dist/utils/toolResultRender.d.ts +61 -0
  939. package/dist/utils/toolResultRender.d.ts.map +1 -0
  940. package/dist/utils/toolResultRender.js +62 -0
  941. package/dist/utils/toolResultRender.js.map +1 -0
  942. package/dist/utils/topicRequest.d.ts +61 -0
  943. package/dist/utils/topicRequest.d.ts.map +1 -0
  944. package/dist/utils/topicRequest.js +68 -0
  945. package/dist/utils/topicRequest.js.map +1 -0
  946. package/dist/utils/topicView.d.ts +55 -0
  947. package/dist/utils/topicView.d.ts.map +1 -0
  948. package/dist/utils/topicView.js +56 -0
  949. package/dist/utils/topicView.js.map +1 -0
  950. package/dist/utils/transcribeAudio.d.ts +89 -0
  951. package/dist/utils/transcribeAudio.d.ts.map +1 -0
  952. package/dist/utils/transcribeAudio.js +249 -0
  953. package/dist/utils/transcribeAudio.js.map +1 -0
  954. package/dist/utils/transientFrames.d.ts +52 -0
  955. package/dist/utils/transientFrames.d.ts.map +1 -0
  956. package/dist/utils/transientFrames.js +41 -0
  957. package/dist/utils/transientFrames.js.map +1 -0
  958. package/dist/utils/typingActive.d.ts +35 -0
  959. package/dist/utils/typingActive.d.ts.map +1 -0
  960. package/dist/utils/typingActive.js +22 -0
  961. package/dist/utils/typingActive.js.map +1 -0
  962. package/dist/utils/typingLoopBackstop.d.ts +64 -0
  963. package/dist/utils/typingLoopBackstop.d.ts.map +1 -0
  964. package/dist/utils/typingLoopBackstop.js +68 -0
  965. package/dist/utils/typingLoopBackstop.js.map +1 -0
  966. package/dist/utils/verbosityRender.d.ts +18 -0
  967. package/dist/utils/verbosityRender.d.ts.map +1 -0
  968. package/dist/utils/verbosityRender.js +17 -0
  969. package/dist/utils/verbosityRender.js.map +1 -0
  970. package/dist/utils/wedgeRecovery.d.ts +57 -0
  971. package/dist/utils/wedgeRecovery.d.ts.map +1 -0
  972. package/dist/utils/wedgeRecovery.js +24 -0
  973. package/dist/utils/wedgeRecovery.js.map +1 -0
  974. package/dist/utils.d.ts +30 -0
  975. package/dist/utils.d.ts.map +1 -0
  976. package/dist/utils.js +61 -0
  977. package/dist/utils.js.map +1 -0
  978. package/dist/validation.d.ts +113 -0
  979. package/dist/validation.d.ts.map +1 -0
  980. package/dist/validation.js +226 -0
  981. package/dist/validation.js.map +1 -0
  982. package/dist/voiceQueue.d.ts +7 -0
  983. package/dist/voiceQueue.d.ts.map +1 -0
  984. package/dist/voiceQueue.js +33 -0
  985. package/dist/voiceQueue.js.map +1 -0
  986. package/examples/.env.example +17 -0
  987. package/examples/docker-compose.yml +36 -0
  988. package/package.json +83 -4
@@ -0,0 +1,1245 @@
1
+ import * as fs from 'fs';
2
+ import { type ApiRetryState, type JsonStreamTailOffset, type LimitEpisodeMarker, type PendingQuestionState, type ResolvedThreadDisplayPrefs, type SeenWatermark, type ThreadDisplayPrefs } from './types';
3
+ import { type SessionKey } from './sessionKey';
4
+ import type { ScheduleRecord } from './scheduler/types';
5
+ import type { OpenRequestState, UnreleasedRequestAlert } from './requests/types';
6
+ import { type RequestGroupKey } from './requests/requestGroup';
7
+ import type { Locale } from './i18n';
8
+ import type { LimitHeldPrompt } from './utils/limitHeldPrompts';
9
+ /**
10
+ * @description On-disk state for the multi-thread telegram bot.
11
+ *
12
+ * Replaces the legacy `~/.telegram-bot-messages.json` (which only persisted
13
+ * `messageIds` per user) with a richer per-`SessionKey` schema:
14
+ *
15
+ * - `bindings[key]` → thread is attached to a subdir under `WORK_ROOT`
16
+ * - `agents[key]` → which adapter the thread is using, model, session ids
17
+ * - `messages[key]` → message ids tracked by `/clear`
18
+ *
19
+ * Schema source: plan §9. Field additions for D14 (`claudeSessionId`), §13.19
20
+ * (`opencodeSessionId`) and D49 (`bindings[key].closed`) are inlined here.
21
+ *
22
+ * The file is rewritten atomically (`writeFile(tmp) → fsync(fd) → rename →
23
+ * fsync(parentDir)`, plan §13.14, T4). Concurrent mutations to the same
24
+ * `SessionKey` are serialised by a per-key async lock (plan §13.15, E3).
25
+ *
26
+ * **This module is intentionally NOT yet imported from `bot.ts`.** Plan §11
27
+ * Этап 2 wires state in only on the following commit (Этап 3) — keeping the
28
+ * landing surgical.
29
+ */
30
+ /** Current schema version stamped into `state.json`. Bump on breaking layout changes. */
31
+ export declare const STATE_SCHEMA_VERSION = 1;
32
+ export interface BindingData {
33
+ /** Subdirectory under `WORK_ROOT` this thread is attached to. */
34
+ subdir: string;
35
+ /** ISO timestamp the binding was first created. */
36
+ createdAt: string;
37
+ /**
38
+ * Whether the forum topic is currently marked closed in Telegram.
39
+ * Toggled by `forum_topic_closed` / `forum_topic_reopened` events
40
+ * (plan §13.10, D49). Closed binding is preserved on purpose — closing
41
+ * is reversible, deletion isn't.
42
+ */
43
+ closed?: boolean;
44
+ /**
45
+ * Telegram message id of the per-thread pinned status banner, if any.
46
+ * Set on first `/bind`, edited on every agent state change, unpinned +
47
+ * cleared on `/unbind`. Plan §11 Этап 7 / §20.5 / D52 area. Persisting
48
+ * the id lets a bot restart re-find the pinned message instead of
49
+ * pinning a fresh banner above it (which Telegram allows, producing a
50
+ * stack of stale pins).
51
+ */
52
+ pinnedStatusMessageId?: number;
53
+ /**
54
+ * Last banner text we successfully sent/edited for {@link pinnedStatusMessageId}.
55
+ * The in-memory `pinnedStatusTextCache` is rebuilt from this at boot so the
56
+ * startup banner-refresh wave skips the `editMessageText` round-trip when the
57
+ * computed banner equals what is already displayed (B8) — every restart
58
+ * otherwise re-edits ~9 identical banners, each a wasted "message is not
59
+ * modified" 400 burning the chat-wide send budget. Cleared whenever the
60
+ * banner message is unpinned/deleted or its id is nulled, so a stale text
61
+ * can never suppress a needed edit for a fresh banner message.
62
+ */
63
+ pinnedStatusText?: string;
64
+ /**
65
+ * Forum-topic display name, when known. The Bot API can't query a topic
66
+ * title on demand — the bot only learns it from events (`forum_topic_created`
67
+ * / `forum_topic_edited`) or when it creates the topic itself (`/new`).
68
+ * Persisted so the thread-context preamble (see `threadContextPreamble.ts`)
69
+ * can tell the agent which topic it works in across restarts. Absent for
70
+ * pre-existing topics until a rename event reveals the name.
71
+ */
72
+ topicName?: string;
73
+ }
74
+ export interface AgentData {
75
+ /** Adapter name, e.g. `'claude'` or `'opencode'`. */
76
+ name: string;
77
+ /** Optional model override (e.g. `'sonnet'`, `'anthropic/claude-3-5-sonnet'`). */
78
+ model?: string;
79
+ /**
80
+ * UUID we pass via `claude --session-id <uuid>` on a fresh start and via
81
+ * `claude --resume <uuid>` on later attaches (plan §13.1, D14). Lets two
82
+ * threads share one `workDir` without their histories cross-contaminating.
83
+ */
84
+ claudeSessionId?: string;
85
+ /**
86
+ * Server-assigned OpenCode session id. Used to re-attach the SSE stream
87
+ * after a bot restart (plan §13.19).
88
+ */
89
+ opencodeSessionId?: string;
90
+ /**
91
+ * Per-thread "seen" watermark advanced at each turn end (see
92
+ * {@link SeenWatermark}). Lets a bot restart compute how much output the agent
93
+ * produced WHILE the bot was down and recover it via the reattach recap,
94
+ * instead of silently dropping it. Optional so older state files stay valid —
95
+ * a missing value means "watermark unknown" → the recap uses its fallback
96
+ * (no-count) path. Backend-specific representation; only one sub-field is set.
97
+ */
98
+ seenWatermark?: SeenWatermark;
99
+ /**
100
+ * The digest of the bot-MCP tool definitions the json-stream process was
101
+ * started with (`SchedulerMcpHandle.getToolDigest`). Compared at adopt after a
102
+ * bot restart: a process whose tools are stale is stopped at its next idle
103
+ * point and resumed with the current ones (lifecycle plan L4). Absent for a
104
+ * row written before the digest was tracked — read as stale.
105
+ */
106
+ mcpToolDigest?: string;
107
+ /**
108
+ * json-stream stdout tail position (line-boundary byte offset into the
109
+ * external session's `stdout.jsonl`), advanced as the tail consumes lines.
110
+ * Lets a restarted bot resume the surviving process's output exactly where
111
+ * processing stopped and replay only the downtime gap (plan
112
+ * 2026-07-05-jsonstream-restart-isolation). Optional so older state files
113
+ * stay valid — a missing value seeds the adopt tail to the current EOF.
114
+ * Cleared together with the session ids on explicit release.
115
+ */
116
+ jsonStreamTail?: JsonStreamTailOffset;
117
+ /**
118
+ * When THIS thread's current agent session began, as a local-offset ISO
119
+ * string (`2026-06-27T19:42:10+04:00`, same shape `/timestamps` uses — never
120
+ * `Z`). Set to "now" on a FRESH start (`startAgentSession`) and on a
121
+ * `/sessions` resume PICK (when the thread began using that session — the
122
+ * original transcript creation time isn't cheaply recoverable). PRESERVED
123
+ * across a bot restart (reattach never overwrites an existing value; only
124
+ * backfills a missing one, e.g. an older state file) and across an adapter
125
+ * switch (`/claude_mode`, same conversation). Cleared together with the
126
+ * session ids on explicit release (`/quit`, `/new`, `/unbind`). Surfaced by
127
+ * `/status`. Optional so older state files stay valid.
128
+ */
129
+ startedAt?: string;
130
+ }
131
+ /**
132
+ * Per-thread compact-on-idle bookkeeping (F2), persisted so a bot restart does
133
+ * not erase the evidence the idle watchdog reasons about. The three instants are
134
+ * epoch ms; each is optional and reads back as `0` when absent, so a state file
135
+ * written before this existed behaves exactly like an untracked thread.
136
+ *
137
+ * The entry is bound to the agent SESSION it describes (`sessionId`), not merely
138
+ * to the thread: the instants mean "THIS session has had a turn since ITS last
139
+ * compaction", so the moment the thread's session is replaced (`/new`, `/quit`
140
+ * then start, a backend switch to a different agent, a `/sessions` resume of an
141
+ * older session) the old marker is meaningless and must read as the initial state.
142
+ * Teardown DOES clear the entry, but that depends on a `stopped`/`closed` event
143
+ * actually firing — a killed or crashed process, or any future path that swaps a
144
+ * session without it, would silently inherit the previous session's marker.
145
+ * Keying on the session id makes the reset self-enforcing regardless of which
146
+ * lifecycle events fired. Deliberate consequence: `/claude_mode` switches the
147
+ * Claude backend by RESUMING the same conversation and keeps `claudeSessionId`, so
148
+ * the marker survives that switch — correct, since the context really is the same
149
+ * and really does have something to compress.
150
+ *
151
+ * - `lastActivityAt` — last REAL activity (user message, command, forwarded
152
+ * prompt, agent output). The countdown is armed from this, so a restart
153
+ * continues where it left off instead of re-arming a flat 55 minutes.
154
+ * - `lastTurnEndAt` — last agent turn that produced output, i.e. the proof
155
+ * there is something to compress.
156
+ * - `lastCompactionAt` — last compaction of this thread (any trigger: manual
157
+ * `/compact`, the F1 tool, or an F2 idle fire).
158
+ *
159
+ * The fire guard is `lastTurnEndAt > lastCompactionAt`, which used to live in a
160
+ * process-local map: after a restart both were `0`, the comparison was false, and
161
+ * (there being no reschedule by D2) the feature stayed dead in every quiet topic
162
+ * until the operator wrote there.
163
+ */
164
+ export interface CompactIdleTrackingEntry {
165
+ /**
166
+ * The agent session these instants describe (`claudeSessionId` /
167
+ * `opencodeSessionId` of the thread's {@link AgentData} at stamping time). A
168
+ * read whose current session id differs — or is unknown — yields all zeros.
169
+ */
170
+ sessionId?: string;
171
+ lastActivityAt?: number;
172
+ lastTurnEndAt?: number;
173
+ lastCompactionAt?: number;
174
+ }
175
+ /**
176
+ * Coarse step (ms) the activity/turn stamps must move past the last PERSISTED
177
+ * value before a save is scheduled. Load-bearing for cost, not correctness:
178
+ * those two stamps are written on EVERY agent output chunk, and `state.json` is
179
+ * rewritten WHOLE (atomically, with fsync) per save — so a `scheduleSave()` per
180
+ * chunk would turn a streaming turn into a debounced disk-rewrite loop. A
181
+ * 60-second granularity is irrelevant against the 55-minute idle threshold.
182
+ */
183
+ export declare const compactIdleTrackingPersistStepMs = 60000;
184
+ export interface StateV1 {
185
+ version: number;
186
+ bindings: Record<string, BindingData>;
187
+ agents: Record<string, AgentData>;
188
+ messages: Record<string, number[]>;
189
+ /**
190
+ * Numeric chat id of the forum supergroup discovered via auto-pairing,
191
+ * persisted so the operator doesn't have to look up the `-100…` id by
192
+ * hand. Only consulted when `ALLOWED_GROUP_ID` env is unset; a numeric
193
+ * env value always wins and disables pairing.
194
+ */
195
+ pairedGroupId?: number;
196
+ /**
197
+ * Epoch milliseconds of the last successful heartbeat write — the bot
198
+ * stamps this every ~10s while running. On boot we compare `now -
199
+ * lastHeartbeatAt` against {@link HOT_RELOAD_THRESHOLD_MS}: small gaps
200
+ * are a hot reload (quiet reattach, keep buffered updates), large gaps
201
+ * (or `undefined` for fresh installs / older state files) are a cold
202
+ * start (allow the per-thread reattach ERROR notice — workDir vanished —
203
+ * optionally drop the stale update backlog).
204
+ *
205
+ * Optional so old `state.json` files (created before heartbeats existed)
206
+ * remain valid — `loadStateFile`'s shape check doesn't require it, and
207
+ * a missing value is interpreted as "treat as cold start", which is the
208
+ * conservative default we want.
209
+ */
210
+ lastHeartbeatAt?: number;
211
+ /**
212
+ * Output-trace toggle (`/trace`). `tracedThreads` holds the {@link SessionKey}
213
+ * strings explicitly opted into tracing; `traceAllThreads` traces every
214
+ * thread (cross-thread forensics). Persisted so the toggle survives a hot
215
+ * rebuild mid-debug — the writer state in `outputTrace.ts` is re-seeded from
216
+ * these at boot. `traceAllThreads` defaults to ON when absent (always-on
217
+ * observability); it is stored EXPLICITLY (incl. `false`) so a `/trace off
218
+ * all` is durable and not re-enabled by the default on the next boot.
219
+ * Lifecycle-independent: only `/trace` mutates them, never session teardown.
220
+ */
221
+ tracedThreads?: string[];
222
+ traceAllThreads?: boolean;
223
+ /**
224
+ * Explicit `/language` overrides, keyed by Telegram chat id (DM chat or whole
225
+ * forum supergroup). These beat Telegram's `from.language_code` until changed
226
+ * or reset to auto. Optional so older state files stay valid.
227
+ */
228
+ chatLocaleOverrides?: Record<string, Locale>;
229
+ /**
230
+ * Last supported Telegram client language seen in each chat, keyed by chat id.
231
+ * Used for bot-originated async events (agent output, scheduled runs) where no
232
+ * live Telegram update carries `from.language_code`. Optional for old state.
233
+ */
234
+ chatTelegramLocales?: Record<string, Locale>;
235
+ /**
236
+ * Threads with the `/timestamps` prompt-injection toggle ON (default OFF —
237
+ * absent list means no thread injects). When ON, every forwarded prompt gets
238
+ * the send-time prepended as a local-offset ISO top line (agent-facing only,
239
+ * never posted to the topic). Same persistence shape as `tracedThreads`
240
+ * (deduped/sorted {@link SessionKey} strings, dropped when empty) and equally
241
+ * lifecycle-independent: only `/timestamps` mutates it, never session
242
+ * teardown. Optional so older state files stay valid.
243
+ */
244
+ timestampThreads?: string[];
245
+ /**
246
+ * The operator's timezone, GLOBAL for the whole bot instance (not per-chat —
247
+ * the mechanism is `process.env.TZ`, which is process-global by nature). Holds
248
+ * either an IANA name (`Europe/Moscow`) or a fixed offset (`+04:00`), as
249
+ * written by `/timezone`. Absent means "use the host zone", so an install that
250
+ * never ran `/timezone` behaves exactly as it did before the setting existed —
251
+ * which is why the field is optional rather than defaulted on disk.
252
+ * Lifecycle-independent: only `/timezone` mutates it, never session teardown.
253
+ */
254
+ timezone?: string;
255
+ /**
256
+ * Providers the operator hid from the `/model` picker, GLOBAL for the whole
257
+ * bot instance (not per-topic). The only lever that works for a provider
258
+ * OpenCode enables from an environment variable (`openrouter` ←
259
+ * `OPENROUTER_API_KEY`), which `DELETE /auth/:id` cannot remove. Hiding
260
+ * filters the PICKER only — an explicit `/model <provider/model>` still
261
+ * resolves a hidden provider, so a saved model pref never breaks. Same
262
+ * persistence shape as `tracedThreads` (deduped/sorted, dropped when empty)
263
+ * and equally lifecycle-independent: only `/model` mutates it, never session
264
+ * teardown. Optional so older state files stay valid.
265
+ */
266
+ hiddenModelProviders?: string[];
267
+ /**
268
+ * Compact-on-idle toggle (`/compact_on_idle`). `compactOnIdleEnabled` is the
269
+ * INSTANCE-WIDE default, driven from the General topic; absent ⇒ ON (the
270
+ * feature ships enabled, mirroring `traceAllThreads`), stored EXPLICITLY (incl.
271
+ * `false`) so a General «Disable» is durable and not re-enabled by the default
272
+ * on the next boot. `compactOnIdleOverrides` holds per-thread explicit
273
+ * overrides keyed by {@link SessionKey} string — a present entry (true OR false)
274
+ * wins over the global default; absent ⇒ follow the default. Both optional so
275
+ * older state files stay valid; lifecycle-independent (only `/compact_on_idle`
276
+ * mutates them, never session teardown).
277
+ */
278
+ compactOnIdleEnabled?: boolean;
279
+ compactOnIdleOverrides?: Record<string, boolean>;
280
+ /**
281
+ * Full-compaction-summary toggle (`/compact_summary`). Same shape and discipline
282
+ * as the `compactOnIdle*` pair above: `compactSummaryEnabled` is the
283
+ * INSTANCE-WIDE default driven from General (absent ⇒ OFF — the operator wants a
284
+ * compaction to end in one short line; stored EXPLICITLY incl. `false` so a General
285
+ * choice is durable), and `compactSummaryOverrides` holds per-thread explicit
286
+ * overrides keyed by {@link SessionKey} string, a present entry winning over the
287
+ * default. Both optional so older state files stay valid; lifecycle-independent
288
+ * (only `/compact_summary` mutates them, never session teardown).
289
+ */
290
+ compactSummaryEnabled?: boolean;
291
+ compactSummaryOverrides?: Record<string, boolean>;
292
+ /**
293
+ * Threads whose compact-on-idle user-LATCH is spent (D2). A thread lands here
294
+ * the instant an idle-compaction FIRES and is removed only by the next genuine
295
+ * USER message — so idle compaction runs at most once per user-active period,
296
+ * and (crucially) a bot restart cannot re-enable a second fire: the reattach
297
+ * re-arms the idle timer ONLY for threads absent from this set. Same
298
+ * deduped/sorted {@link SessionKey}-string shape as `timestampThreads` (dropped
299
+ * when empty), and equally lifecycle-independent — only a fire and a user
300
+ * message mutate it, never session teardown. Optional so older state files stay
301
+ * valid (a missing value = no thread latched).
302
+ */
303
+ compactIdleLatchedThreads?: string[];
304
+ /**
305
+ * Per-thread compact-on-idle bookkeeping keyed by {@link SessionKey} string —
306
+ * the idle COUNTDOWN's restart guard (see {@link CompactIdleTrackingEntry} for
307
+ * the three instants and why losing them disabled the feature after every
308
+ * restart). Entries are dropped on session teardown (a fresh session must get
309
+ * the full window) and the whole map is dropped once empty, so an idle bot
310
+ * leaves a clean `state.json`. Optional so older state files stay valid.
311
+ */
312
+ compactIdleTracking?: Record<string, CompactIdleTrackingEntry>;
313
+ /**
314
+ * Limit auto-continue toggle (`/auto_continue_limits`). `autoContinueOnLimitEnabled` is
315
+ * the INSTANCE-WIDE default, driven from the General topic; absent ⇒ ON (the
316
+ * behaviour was unconditional before the toggle existed), stored EXPLICITLY
317
+ * (incl. `false`) so a General «Disable» is durable and not re-enabled by the
318
+ * default on the next boot. `autoContinueOnLimitOverrides` holds per-thread
319
+ * explicit overrides keyed by {@link SessionKey} string — a present entry (true
320
+ * OR false) wins over the global default. Both optional so older state files
321
+ * stay valid; lifecycle-independent (only `/auto_continue_limits` mutates them, never
322
+ * session teardown). Same shape discipline as the `compactOnIdle*` pair.
323
+ */
324
+ autoContinueOnLimitEnabled?: boolean;
325
+ autoContinueOnLimitOverrides?: Record<string, boolean>;
326
+ /**
327
+ * Persisted scheduled jobs, keyed by {@link ScheduleRecord.id}. Optional so
328
+ * older state files (created before the scheduler feature) stay valid —
329
+ * `loadStateFile`'s shape check doesn't require it and a missing value is an
330
+ * empty schedule set. The crash-critical `nextRunAt` inside each record is
331
+ * why the engine calls {@link StateStore.flush} after every fire rather than
332
+ * relying on the debounced save.
333
+ */
334
+ schedules?: Record<string, ScheduleRecord>;
335
+ /**
336
+ * Secret keying the HMAC tokens the bot mints for its own scheduler MCP
337
+ * server (see `scheduler/mcpSurface.ts`). Generated once on first use
338
+ * (`getSchedulerMcpSecret`) and persisted so the tokens injected into agent
339
+ * sessions stay valid across restarts. Optional so older state files stay
340
+ * valid — a missing value is created lazily on the first read.
341
+ */
342
+ schedulerMcpSecret?: string;
343
+ /**
344
+ * The loopback port the bot's scheduler MCP server bound on a prior boot (see
345
+ * `scheduler/mcpSurface.ts`). The listen port is EPHEMERAL by default (`0` →
346
+ * an OS-assigned port), which changes on every restart; persisting the bound
347
+ * port lets a later boot reuse it so the `telegramBot` registrations injected
348
+ * into agent sessions (which embed `http://127.0.0.1:<port>/mcp`) stay valid
349
+ * across restarts instead of pointing at a dead port. Not written when the
350
+ * operator fixes the port via `SCHEDULER_MCP_PORT`. Optional so older state
351
+ * files stay valid — a missing value means "no port to reuse, pick fresh".
352
+ */
353
+ schedulerMcpPort?: number;
354
+ /**
355
+ * In-flight interactive agent questions, keyed by {@link SessionKey} string.
356
+ * Persisted so a pending question survives a bot restart / hot reload: the
357
+ * in-memory `pendingQuestions` map (see `bot.ts`) is otherwise lost, leaving
358
+ * the agent's question tool blocked forever and the posted Telegram option
359
+ * buttons dead ("no pending question"). The persisted `messageId` lets the
360
+ * OLD buttons resolve once the map is re-armed at boot, so no question is
361
+ * re-posted. Optional so older state files stay valid — a missing value is
362
+ * an empty set. Restored at boot only for threads whose session reattached
363
+ * and is active; otherwise dropped (the question is unreachable).
364
+ */
365
+ pendingQuestions?: Record<string, PendingQuestionState>;
366
+ /**
367
+ * Armed auto-retries after a provider-side API error, keyed by
368
+ * {@link SessionKey} string. Persisted so a pending retry survives a bot
369
+ * restart / hot reload: the in-memory `apiRetries` map (see `bot.ts`) is
370
+ * otherwise lost, so an agent that died on a rate-limit / usage-limit error
371
+ * would never get its scheduled nudge — especially a multi-hour usage-limit
372
+ * wait. The persisted `fireAt` lets boot re-arm the timer (or fire one
373
+ * immediate catch-up when the time already passed). A record means ARMED: it is
374
+ * cleared once the retry's kick has run its course (its nudge forwarded, or dropped
375
+ * for good), else every restart would fire the kick again — but kept while the nudge
376
+ * only waits in the in-memory startup buffer, which a restart loses. Optional so
377
+ * older state files stay valid — a missing value is an empty set. Restored at boot
378
+ * only after sessions are reattached, so the kick lands in a live session.
379
+ */
380
+ apiRetries?: Record<string, ApiRetryState>;
381
+ /**
382
+ * Prompts held during an armed usage-limit wait (Jira plan R23), keyed by
383
+ * {@link SessionKey} string, oldest first. Kept apart from `apiRetries`: the
384
+ * wait can end without its resume (the operator writes, skips or disables it,
385
+ * the session ends), and the prompts must outlive it until they reach a
386
+ * session (`utils/limitHeldPromptQueue.ts`). Optional — absent when empty.
387
+ */
388
+ limitHeldPrompts?: Record<string, LimitHeldPrompt[]>;
389
+ /**
390
+ * Open requests of the request ledger (`requests/requestLedger.ts`), keyed by
391
+ * the serialized request GROUP (conversation + requester, `requests/requestGroup.ts`)
392
+ * — at most ONE per group (a new request of the group supersedes the open one;
393
+ * another requester's request in the same conversation stays open beside it).
394
+ * Persisted so an unanswered request, its counters
395
+ * and its next wake-up survive a bot restart. Closed requests move to the
396
+ * append-only `DATA_DIR/requests.jsonl`. Optional so older state files stay
397
+ * valid — a missing value is an empty set.
398
+ */
399
+ openRequests?: Record<string, OpenRequestState>;
400
+ /**
401
+ * Per conversation (serialized {@link SessionKey}), the message id of the
402
+ * LATEST pinned `answer_request` answer (request/answer plan S8): a new answer
403
+ * unpins it and takes its place, so a topic never keeps two answers pinned —
404
+ * across restarts too. Optional, dropped when empty.
405
+ */
406
+ answerPins?: Record<string, number>;
407
+ /**
408
+ * Alerts of CLOSED requests that are not released yet (Telegram: still
409
+ * pinned), keyed by request id. A request that closes while it holds an alert
410
+ * lands here in the same save as its close, and leaves only once the release
411
+ * succeeded — so a crash between the close and the unpin re-releases at the
412
+ * next boot instead of leaving the pin forever. Optional — absent when empty.
413
+ */
414
+ unreleasedRequestAlerts?: Record<string, UnreleasedRequestAlert>;
415
+ /**
416
+ * Boot-recovery markers: per {@link SessionKey} string, the `stdout.jsonl`
417
+ * identity the recovery last armed a limit wait from (see
418
+ * {@link LimitEpisodeMarker}). It is what stops a hot reload from resurrecting a
419
+ * wait that was already settled — «⏭ Skip once», a user takeover, or a give-up
420
+ * all clear `apiRetries`, leaving the same trailing error in the log. Optional so
421
+ * older state files stay valid; dropped when the thread's session ids are
422
+ * released or its binding goes away.
423
+ */
424
+ limitEpisodesRecovered?: Record<string, LimitEpisodeMarker>;
425
+ /**
426
+ * Per-thread OpenCode output-verbosity rendering preferences (thinking /
427
+ * tool-results / sub-agent display), keyed by {@link SessionKey} string. Each
428
+ * record only stores NON-default overrides — an absent field (or absent
429
+ * record) means "use the locked default" (see {@link StateStore.getDisplayPrefs}),
430
+ * which keeps `state.json` clean (same delete-when-default idiom as `/trace`).
431
+ * Optional so older state files stay valid — a missing value is "all threads
432
+ * on defaults". Lifecycle-independent: only `/thinking` / `/tool-results` /
433
+ * `/subagent` mutate it, never session teardown. These are bot-side rendering
434
+ * concerns, NOT agent behavior — they never change what is sent to OpenCode.
435
+ */
436
+ displayPrefs?: Record<string, ThreadDisplayPrefs>;
437
+ /**
438
+ * Per-thread TRANSIENT status-frame message ids currently on screen (the
439
+ * "✽ working…" liveness frame, the live thinking indicator, the dedicated
440
+ * sub-agent status), keyed by {@link SessionKey} string. Persisted ONLY so an
441
+ * UNGRACEFUL exit (crash / SIGKILL — the graceful shutdown sweep in `bot.ts`
442
+ * never ran) can delete whatever frame was on screen on the NEXT boot, after
443
+ * reattach (the reattached session is idle, so a leftover frame is stale by
444
+ * definition). Cosmetic, so it rides the debounced save — losing the last
445
+ * <=500ms window before a crash just falls back to the pre-fix orphan for that
446
+ * one frame (S1 covers every graceful path exactly). Optional so older state
447
+ * files stay valid — a missing value is an empty set; an empty list drops the
448
+ * key so an idle bot leaves a clean `state.json`.
449
+ */
450
+ transientFrames?: Record<string, number[]>;
451
+ }
452
+ /**
453
+ * @description Promise-chain per-key lock. The map holds the tail of each
454
+ * key's queue; new callers attach to the tail and append themselves. Errors
455
+ * in one task don't poison followers — the chain only carries scheduling,
456
+ * not values. See plan §13.15 (E3).
457
+ *
458
+ * Exported for unit tests (plan §11 Этап 7, R5).
459
+ */
460
+ export declare class KeyLock {
461
+ private chains;
462
+ withLock<T>(keyStr: string, fn: () => Promise<T>): Promise<T>;
463
+ }
464
+ /**
465
+ * @description Best-effort atomic write of `content` to `finalPath`.
466
+ *
467
+ * Sequence: `writeFile(tmp)` → `fsync(tmp)` → `rename(tmp, final)` →
468
+ * `fsync(parentDir)`. The last step is critical: without it, `rename`
469
+ * survives crashes but the new directory entry can be lost on a power
470
+ * cut on ext4 (plan §13.14, fix to T4).
471
+ *
472
+ * Tmp files are colocated with the final file so `rename` stays on the
473
+ * same filesystem (cross-fs rename would degrade to copy+unlink and break
474
+ * atomicity). Permissions on the tmp default to `0600` so a state file
475
+ * containing model preferences / session ids isn't world-readable on a
476
+ * shared host.
477
+ *
478
+ * Directory `fsync` is wrapped in a soft try/catch: on Windows opening a
479
+ * directory for read isn't supported and would throw. Our deployment
480
+ * target is Linux/Mac (plan §17.4 «Windows: not our case»), so logging
481
+ * and continuing is the right trade.
482
+ */
483
+ export declare function writeFileAtomic(finalPath: string, content: string, options?: {
484
+ mode?: number;
485
+ }): Promise<void>;
486
+ /**
487
+ * @description Try to load the state file. On a successful parse return the
488
+ * structured state. On parse failure archive the broken file to
489
+ * `state.json.corrupted-<iso>` and return `null` so the caller can start fresh.
490
+ *
491
+ * Three cases the caller cares about:
492
+ *
493
+ * 1. File doesn't exist → `null`, no archive. Fresh install.
494
+ * 2. File exists, parses → state object.
495
+ * 3. File exists, parses fails → archived, `null` returned.
496
+ * We also handle EPERM / EACCES on read here for completeness — same
497
+ * treatment: archive (if possible) and start fresh.
498
+ *
499
+ * Exported for unit tests (plan §11 Этап 7, R6).
500
+ */
501
+ export declare function loadStateFile(filePath: string): Promise<{
502
+ ok: true;
503
+ state: StateV1;
504
+ } | {
505
+ ok: false;
506
+ reason: 'missing';
507
+ } | {
508
+ ok: false;
509
+ reason: 'corrupted';
510
+ archivedTo: string | null;
511
+ error: string;
512
+ }>;
513
+ /**
514
+ * @description Migrate the legacy single-folder bot's message-id file.
515
+ *
516
+ * Old layout: `~/.telegram-bot-messages.json` keyed by raw user id.
517
+ * The 2.0 release intentionally doesn't try to merge those ids into the
518
+ * new `SessionKey`-keyed schema — the routing model changed too much for
519
+ * a clean mapping (plan §9). We just rename the file so it's preserved
520
+ * for the user's records and so it stops being read on every boot.
521
+ *
522
+ * Returns the archive path if migration happened, `null` otherwise.
523
+ */
524
+ export declare function migrateLegacyMessageIdsFile(): Promise<string | null>;
525
+ export interface StateStoreOptions {
526
+ /** Override the debounce window for tests. */
527
+ saveDebounceMs?: number;
528
+ }
529
+ /**
530
+ * @description Stateful, async-safe store for `state.json`.
531
+ *
532
+ * Construction is cheap (no I/O). Call `init()` once at boot before any
533
+ * setters fire; init loads or initialises the file, performs the legacy
534
+ * migration, and resolves. Setters return promises so callers can await
535
+ * the resulting persisted state when correctness matters more than
536
+ * throughput; non-critical writes are debounced.
537
+ */
538
+ export declare class StateStore {
539
+ private readonly dataDir;
540
+ private readonly statePath;
541
+ private readonly saveDebounceMs;
542
+ private state;
543
+ /** True if the previous on-disk state file was unreadable / corrupt. */
544
+ private corruptedOnLoad;
545
+ /** Archive path if the previous on-disk state was corrupted. */
546
+ private corruptedArchivePath;
547
+ /** Backup path if the legacy file was migrated. */
548
+ private legacyMigrationPath;
549
+ private saveTimer;
550
+ /** Tail of the chained writes so two flushes don't try to rename simultaneously. */
551
+ private writeChain;
552
+ /**
553
+ * Last compact-on-idle activity/turn stamp each thread actually asked to
554
+ * PERSIST, used to apply {@link compactIdleTrackingPersistStepMs}. In-memory
555
+ * only and deliberately NOT written to disk — it is bookkeeping ABOUT the
556
+ * bookkeeping, and after a restart the first stamp simply schedules one save.
557
+ */
558
+ private readonly compactIdleTrackingSavedAt;
559
+ private readonly keyLock;
560
+ constructor(dataDir: string, options?: StateStoreOptions);
561
+ /**
562
+ * @description One-shot boot. Creates `dataDir` if missing, performs
563
+ * legacy migration, loads the existing state file (or starts fresh on
564
+ * corruption).
565
+ */
566
+ init(): Promise<void>;
567
+ /** Path of the live state file (for logging / docs / smoke-tests). */
568
+ get stateFilePath(): string;
569
+ /** True iff the previous boot's state file was unreadable on this start. */
570
+ wasCorruptedOnLoad(): boolean;
571
+ /** Where the previous corrupted file was moved, if archival succeeded. */
572
+ getCorruptedArchivePath(): string | null;
573
+ /** Where the legacy `~/.telegram-bot-messages.json` was archived, if it existed. */
574
+ getLegacyMigrationPath(): string | null;
575
+ /**
576
+ * @description Run `fn` while holding the per-key lock for `key`. Concurrent
577
+ * calls for the SAME key are serialised; calls for different keys run in
578
+ * parallel. Failure in one holder does NOT propagate to followers (the lock
579
+ * is for serialisation only; error handling is each caller's job).
580
+ */
581
+ withLock<T>(key: SessionKey, fn: () => Promise<T>): Promise<T>;
582
+ getBinding(key: SessionKey): BindingData | null;
583
+ setBinding(key: SessionKey, subdir: string, options?: {
584
+ closed?: boolean;
585
+ topicName?: string;
586
+ }): Promise<void>;
587
+ /**
588
+ * @description Persist the forum-topic display name for a thread. Used by
589
+ * `forum_topic_edited` (rename) when a binding already exists. No-op (no
590
+ * save) when the binding is absent or the name is unchanged — symmetric to
591
+ * {@link setBindingPinnedStatusText}.
592
+ */
593
+ setBindingTopicName(key: SessionKey, topicName: string): Promise<void>;
594
+ setBindingClosed(key: SessionKey, closed: boolean): Promise<void>;
595
+ /**
596
+ * @description Persist the pinned status banner's message id for a thread,
597
+ * or clear it (pass `null`). Skipped if the binding doesn't exist — we
598
+ * don't ever want a pinned-message row dangling without a parent binding.
599
+ *
600
+ * Caller is expected to actually pin / unpin in Telegram around this
601
+ * call; this method only updates the on-disk pointer. Plan §20.5.
602
+ */
603
+ setBindingPinnedStatusMessageId(key: SessionKey, messageId: number | null): Promise<void>;
604
+ /**
605
+ * @description Persist the last banner text sent/edited for a thread, or
606
+ * clear it (pass `null`). Mirrors {@link setBindingPinnedStatusMessageId}:
607
+ * skipped if the binding doesn't exist, and a no-op (no save) when the value
608
+ * is unchanged. Read back at boot to seed `pinnedStatusTextCache` so the
609
+ * startup refresh wave skips identical-banner edits (B8).
610
+ */
611
+ setBindingPinnedStatusText(key: SessionKey, text: string | null): Promise<void>;
612
+ removeBinding(key: SessionKey): Promise<void>;
613
+ listBindings(): Array<{
614
+ key: SessionKey;
615
+ data: BindingData;
616
+ }>;
617
+ /**
618
+ * @description Find every thread currently bound to a given subdir.
619
+ * Plan §10.6 names this for `/bind` UX warning «📁 уже работают треды: ...»
620
+ * — one folder may be reached from several threads (D7).
621
+ */
622
+ listKeysForSubdir(subdir: string): SessionKey[];
623
+ getAgent(key: SessionKey): AgentData | null;
624
+ /**
625
+ * @description Upsert agent state for a thread. `name` is required (we
626
+ * don't keep an agent record without a backend choice); the rest of the
627
+ * fields are patched onto whatever exists.
628
+ */
629
+ setAgent(key: SessionKey, data: {
630
+ name: string;
631
+ } & Partial<Omit<AgentData, 'name'>>): Promise<void>;
632
+ removeAgent(key: SessionKey): Promise<void>;
633
+ getClaudeSessionId(key: SessionKey): string | null;
634
+ /**
635
+ * @description Persist the Claude `--session-id` UUID for `key`.
636
+ *
637
+ * If the thread already has an agent record, only the `claudeSessionId`
638
+ * field is patched — we keep whatever `name` was previously chosen so a
639
+ * thread currently set to `opencode` doesn't get silently flipped to
640
+ * `claude` just because we recorded a UUID. The bot picks the adapter
641
+ * via {@link setAgent} or `setThreadAdapter` — those are the right
642
+ * places to change `name`.
643
+ */
644
+ setClaudeSessionId(key: SessionKey, uuid: string): Promise<void>;
645
+ getOpenCodeSessionId(key: SessionKey): string | null;
646
+ /** Symmetric to {@link setClaudeSessionId} — does not flip `agent.name`. */
647
+ setOpenCodeSessionId(key: SessionKey, id: string): Promise<void>;
648
+ /**
649
+ * @description Advance the per-thread {@link SeenWatermark} (set at each turn
650
+ * end by the adapters via the injected writer). Merges onto the EXISTING agent
651
+ * row only — never flips `agent.name` (symmetric to
652
+ * {@link setClaudeSessionId} / {@link setOpenCodeSessionId}) and, unlike them,
653
+ * never CREATES a row: a watermark is meaningless without a live agent session
654
+ * (which always recorded its row first), so a write for an unknown thread is a
655
+ * no-op, not a dangling agent row.
656
+ */
657
+ setSeenWatermark(key: SessionKey, watermark: SeenWatermark): Promise<void>;
658
+ /**
659
+ * @description Persist the json-stream stdout tail offset (advanced by the
660
+ * adapter's tail poller through the injected writer, sealed by the shutdown
661
+ * `flush()`). Merge-only like {@link setSeenWatermark}: never flips
662
+ * `agent.name` and never creates a row — an offset is meaningless without
663
+ * the agent row its session recorded first.
664
+ */
665
+ setJsonStreamTail(key: SessionKey, tail: JsonStreamTailOffset): Promise<void>;
666
+ /**
667
+ * @description Persist the session-start timestamp (a local-offset ISO string;
668
+ * see {@link AgentData.startedAt}). Merge-only like {@link setSeenWatermark}:
669
+ * never flips `agent.name` and never CREATES a row — the caller records the
670
+ * agent row (via `setAgent` / `persistAdapterSessionIds`) first, so a write
671
+ * for an unknown thread is a no-op rather than a dangling agent row.
672
+ */
673
+ setAgentStartedAt(key: SessionKey, startedAt: string): Promise<void>;
674
+ /** Persist the tool digest a json-stream process was started with (see {@link AgentData.mcpToolDigest}); merge-only. */
675
+ setAgentMcpToolDigest(key: SessionKey, mcpToolDigest: string): Promise<void>;
676
+ /**
677
+ * @description Release both persisted session ids (and the json-stream tail
678
+ * offset, which is meaningless without its session; plus the session-start
679
+ * timestamp, which belongs to the session going away) for `key` while keeping
680
+ * `name` / `model`. Called on explicit user stop (`/quit`, `/quit-all`,
681
+ * `/new`, `/unbind`) so a later bot restart won't auto-reattach a session
682
+ * the user deliberately ended. No-op when the thread has no agent record.
683
+ */
684
+ clearAgentSessionIds(key: SessionKey): Promise<void>;
685
+ getMessageIds(key: SessionKey): number[];
686
+ /** Append IDs to the bounded in-memory ring while the caller holds the key lock. */
687
+ private appendMessageIds;
688
+ /**
689
+ * @description Append a message id to the per-thread tracking list and
690
+ * trim to the most recent `MESSAGE_ID_RING_CAP`. Anything older falls off
691
+ * the end — Telegram won't let `deleteMessages` touch messages older than
692
+ * 48h anyway (plan §11 Этап 3, U2).
693
+ */
694
+ pushMessageId(key: SessionKey, msgId: number): Promise<void>;
695
+ /** Atomically append and durably persist one Telegram response's message IDs. */
696
+ pushMessageIds(key: SessionKey, messageIds: number[]): Promise<void>;
697
+ /** Atomically hand tracked IDs to `/clear_messages` while later pushes remain tracked. */
698
+ takeMessageIds(key: SessionKey, additionalIds?: number[]): Promise<number[]>;
699
+ /**
700
+ * @description Stamp `lastHeartbeatAt = now` (ms) and schedule a debounced
701
+ * save. Called by the bot on a ~10s interval while running so the next
702
+ * boot can tell a hot reload (gap < threshold) from a real cold start
703
+ * (gap large, or no stamp at all on a fresh install).
704
+ *
705
+ * Cheap by design: a one-field mutation that piggy-backs on the existing
706
+ * debounced save loop. We don't `flush()` here — losing the last 10s
707
+ * heartbeat on a hard crash just biases the next boot toward
708
+ * "cold start", which is the conservative direction.
709
+ */
710
+ touchHeartbeat(now?: number): void;
711
+ /**
712
+ * @description Time since the last persisted heartbeat in ms, or `null`
713
+ * if the state file has no heartbeat stamp (fresh install, or pre-feature
714
+ * state file). `null` should be treated as "unknown → assume cold start".
715
+ *
716
+ * Read at boot to decide hot-vs-cold-start, ideally BEFORE the first
717
+ * `touchHeartbeat()` call or `state.flush()` (otherwise the value
718
+ * compares against ourselves and always looks like a hot reload).
719
+ */
720
+ getDowntimeMs(now?: number): number | null;
721
+ /** The auto-paired forum supergroup id, or `null` if never paired. */
722
+ getPairedGroupId(): number | null;
723
+ /**
724
+ * @description Persist the auto-paired group id and flush immediately.
725
+ *
726
+ * Unlike per-thread mutations this is a rare, one-shot critical write:
727
+ * if the process dies right after pairing we must not lose the id and
728
+ * fall back into pairing mode on the next boot. So we `flush()` rather
729
+ * than debounce.
730
+ */
731
+ setPairedGroupId(groupId: number): Promise<void>;
732
+ /**
733
+ * @description Current persisted trace toggle. `threadKeys` are the
734
+ * {@link SessionKey} strings opted into tracing; `allThreads` traces
735
+ * everything. `allThreads` defaults to TRUE on a fresh or pre-feature state
736
+ * file (always-on observability — only an explicit `/trace off all` turns it
737
+ * off, stored as a durable `false`); `threadKeys` defaults empty. Read at boot
738
+ * to seed `outputTrace.ts`.
739
+ */
740
+ getTraceConfig(): {
741
+ allThreads: boolean;
742
+ threadKeys: string[];
743
+ };
744
+ /**
745
+ * @description Persist the trace toggle. Not crash-critical (a debug aid), so
746
+ * it rides the debounced save loop rather than an immediate `flush()`. The
747
+ * `tracedThreads` array is normalised to a deduped, sorted form so the
748
+ * on-disk shape is stable across toggles; an empty list is dropped.
749
+ *
750
+ * `traceAllThreads` is stored EXPLICITLY as a boolean (including `false`):
751
+ * the all-threads default is now ON ({@link getTraceConfig}), so a `/trace
752
+ * off all` must be DURABLE and distinguishable from "never set" (which reads
753
+ * back as the ON default). Dropping it on `false` would silently re-enable
754
+ * tracing on the next boot.
755
+ */
756
+ setTraceConfig(config: {
757
+ allThreads: boolean;
758
+ threadKeys: string[];
759
+ }): Promise<void>;
760
+ getChatLocaleOverride(chatId: number): Locale | null;
761
+ getChatTelegramLocale(chatId: number): Locale | null;
762
+ setChatLocaleOverride(chatId: number, locale: Locale | null): Promise<void>;
763
+ setChatTelegramLocale(chatId: number, locale: Locale): Promise<void>;
764
+ /**
765
+ * @description Whether `/timestamps` is ON for `key` (default OFF). When ON,
766
+ * `forwardPromptToAgent` prepends the send-time as a local-offset ISO top
767
+ * line to every forwarded prompt.
768
+ */
769
+ checkIsTimestampsEnabled(key: SessionKey): boolean;
770
+ /**
771
+ * @description Persist the per-thread `/timestamps` toggle. Mirrors
772
+ * {@link setTraceConfig}'s shape discipline: the list is deduped + sorted so
773
+ * the on-disk form is stable, and an empty list is dropped (an all-defaults
774
+ * install leaves no trace in `state.json`). Not crash-critical, so it rides
775
+ * the debounced save loop.
776
+ */
777
+ setTimestampsEnabled(key: SessionKey, isEnabled: boolean): Promise<void>;
778
+ /**
779
+ * @description Providers currently hidden from the `/model` picker, in the
780
+ * stable sorted on-disk order. Empty when nothing is hidden (the default).
781
+ */
782
+ getHiddenModelProviders(): string[];
783
+ /**
784
+ * @description Hide/show one provider in the `/model` picker. Mirrors
785
+ * {@link setTimestampsEnabled}'s shape discipline: deduped + sorted so the
786
+ * on-disk form is stable across toggles, and an empty list is dropped (a
787
+ * default install leaves no trace in `state.json`). A picker preference is
788
+ * not crash-critical, so it rides the debounced save loop.
789
+ */
790
+ setModelProviderHidden(provider: string, isHidden: boolean): Promise<void>;
791
+ /**
792
+ * @description The instance-wide compact-on-idle default (driven from the
793
+ * General topic). ON when unset — same always-on default as
794
+ * {@link getTraceConfig}'s `allThreads`.
795
+ */
796
+ getCompactOnIdleGlobalDefault(): boolean;
797
+ /**
798
+ * @description The per-thread compact-on-idle override, or `undefined` when the
799
+ * thread follows the instance default. A present value (true OR false) wins.
800
+ */
801
+ getCompactOnIdleOverride(key: SessionKey): boolean | undefined;
802
+ /**
803
+ * @description Whether compact-on-idle is effectively enabled for `key`: the
804
+ * per-thread override if set, else the instance default (OFF when unset).
805
+ */
806
+ checkIsCompactOnIdleEnabled(key: SessionKey): boolean;
807
+ /**
808
+ * @description Set the instance-wide compact-on-idle default (from General).
809
+ * Stored EXPLICITLY as a boolean (incl. `false`) so a «Disable» is durable and
810
+ * distinguishable from "never set" (which reads back as the ON default) —
811
+ * mirrors {@link setTraceConfig}'s `traceAllThreads` discipline. Debounced (a
812
+ * preference, not crash-critical).
813
+ */
814
+ setCompactOnIdleGlobalDefault(enabled: boolean): Promise<void>;
815
+ /**
816
+ * @description Set the per-thread compact-on-idle override (from a regular
817
+ * topic). Stored explicitly (a present true/false wins over the global
818
+ * default); the whole map is dropped once empty so an all-default instance
819
+ * leaves a clean `state.json`. Debounced.
820
+ */
821
+ setCompactOnIdleOverride(key: SessionKey, enabled: boolean): Promise<void>;
822
+ /**
823
+ * @description The instance-wide full-compaction-summary default (driven from the
824
+ * General topic). OFF when unset, unlike {@link getCompactOnIdleGlobalDefault}:
825
+ * a compaction ends in one short line unless the summary is turned on.
826
+ */
827
+ getCompactSummaryGlobalDefault(): boolean;
828
+ /**
829
+ * @description The per-thread full-summary override, or `undefined` when the
830
+ * thread follows the instance default. A present value (true OR false) wins.
831
+ */
832
+ getCompactSummaryOverride(key: SessionKey): boolean | undefined;
833
+ /**
834
+ * @description Whether the full compaction summary is posted for `key`: the
835
+ * per-thread override if set, else the instance default (ON when unset).
836
+ */
837
+ checkIsCompactSummaryEnabled(key: SessionKey): boolean;
838
+ /**
839
+ * @description Set the instance-wide full-summary default (from General). Stored
840
+ * EXPLICITLY as a boolean (incl. `false`) so a choice is durable and
841
+ * distinguishable from "never set", which reads back as the OFF default. Debounced
842
+ * (a preference, not crash-critical) — mirrors
843
+ * {@link setCompactOnIdleGlobalDefault}.
844
+ */
845
+ setCompactSummaryGlobalDefault(enabled: boolean): Promise<void>;
846
+ /**
847
+ * @description Set the per-thread full-summary override (from a regular topic).
848
+ * Stored explicitly (a present true/false wins over the global default).
849
+ * Debounced — mirrors {@link setCompactOnIdleOverride}.
850
+ */
851
+ setCompactSummaryOverride(key: SessionKey, enabled: boolean): Promise<void>;
852
+ /**
853
+ * @description Whether `key`'s compact-on-idle user-latch is spent (D2): an
854
+ * idle-compaction already fired this user-active period and no genuine USER
855
+ * message has re-armed it since. Read by the idle watchdog's fire guard and by
856
+ * the timer-arming path (a latched thread never re-arms — so a restart can't
857
+ * re-fire). Default `false` (never latched).
858
+ */
859
+ checkIsCompactIdleLatched(key: SessionKey): boolean;
860
+ /**
861
+ * @description Set/clear `key`'s compact-on-idle user-latch (D2). Set on a
862
+ * fire, cleared on a genuine USER message / fresh session start. Mirrors
863
+ * {@link setTimestampsEnabled}'s shape discipline (deduped + sorted, dropped
864
+ * when empty) and rides the debounced save loop — the persistence is only a
865
+ * restart guard, so losing the last <=500ms is at worst one extra fire.
866
+ */
867
+ setCompactIdleLatched(key: SessionKey, isLatched: boolean): Promise<void>;
868
+ /**
869
+ * @description `key`'s persisted compact-on-idle instants, with every absent
870
+ * field read back as `0`. `0` is the explicit "no history" value both readers
871
+ * rely on: the arming path takes it as "use the full idle window" and the fire
872
+ * guard's `lastTurnEndAt > lastCompactionAt` as "nothing to compress" — so a
873
+ * pre-feature state file behaves exactly like an untracked thread.
874
+ *
875
+ * All zeros are ALSO returned whenever the entry does not belong to the thread's
876
+ * CURRENT agent session (a different `sessionId`, or either id unknown): the
877
+ * instants describe one session's context, so a session swap must reset the
878
+ * marker, and deciding that here — rather than in a teardown handler — makes it
879
+ * true regardless of which lifecycle events fired (a killed process emits none).
880
+ * Unknown-means-zero is conservative in the right direction: at worst the topic
881
+ * waits one more full idle window.
882
+ */
883
+ getCompactIdleTracking(key: SessionKey): {
884
+ lastActivityAt: number;
885
+ lastTurnEndAt: number;
886
+ lastCompactionAt: number;
887
+ };
888
+ /**
889
+ * @description Stamp `key`'s last REAL activity — the instant the idle
890
+ * countdown is measured from. Called on every agent output chunk, so the write
891
+ * is COARSE: the in-memory value is always assigned (readers are exact), but a
892
+ * save is scheduled only once the value has moved a full
893
+ * {@link compactIdleTrackingPersistStepMs} past what was last persisted. The
894
+ * assigned value also rides along for free on the next save the ~10s
895
+ * {@link touchHeartbeat} loop schedules, so the coarse step costs nothing in
896
+ * correctness — at worst the persisted stamp trails the live one by under a
897
+ * minute, against a 55-minute threshold.
898
+ */
899
+ noteCompactIdleActivity(key: SessionKey, now?: number): void;
900
+ /**
901
+ * @description Stamp that an agent turn produced output for `key` — the proof
902
+ * there is something to compress (the fire guard compares this against
903
+ * `lastCompactionAt`). Same per-chunk call frequency and therefore the same
904
+ * coarse-save rule as {@link noteCompactIdleActivity}.
905
+ */
906
+ noteCompactIdleTurnEnd(key: SessionKey, now?: number): void;
907
+ /**
908
+ * @description Stamp that `key` was just compacted (any trigger: manual
909
+ * `/compact`, the F1 tool, an F2 idle fire), closing the fire guard until the
910
+ * next turn produces output. Rare, so it always schedules a save — persisting it
911
+ * is what stops a restart from re-compacting a session nothing has touched
912
+ * since.
913
+ */
914
+ setCompactIdleCompactedAt(key: SessionKey, now?: number): Promise<void>;
915
+ /**
916
+ * @description Drop `key`'s compact-on-idle bookkeeping (session teardown:
917
+ * `/new`, `/quit`, unbind). Deliberately a full delete rather than a reset —
918
+ * with no entry the next session start finds `lastActivityAt === 0` and gets
919
+ * the FULL idle window, which is exactly the wanted behaviour for a fresh
920
+ * session, so no special case is needed on the start path. The whole map is
921
+ * dropped once empty so an idle bot leaves a clean `state.json`.
922
+ */
923
+ clearCompactIdleTracking(key: SessionKey): Promise<void>;
924
+ /**
925
+ * Assign one high-frequency compact-on-idle stamp in memory and schedule a save
926
+ * only past the coarse step (see {@link noteCompactIdleActivity}). Synchronous
927
+ * (no key lock) on purpose: it runs on the output hot path, and a single-field
928
+ * assignment cannot interleave with another write the way a read-modify-write
929
+ * of a whole record can.
930
+ */
931
+ private stampCompactIdleTracking;
932
+ /**
933
+ * The thread's CURRENT agent session id — `claudeSessionId` else
934
+ * `opencodeSessionId` from the persisted {@link AgentData} — or `undefined` when
935
+ * the thread has neither. A raw `/terminal` shell has no session id and cannot be
936
+ * compacted anyway, so "no id" means the compact-on-idle marker has nothing to
937
+ * bind to: reads return zeros and stamps are skipped, keeping `state.json` clean.
938
+ */
939
+ private getAgentSessionId;
940
+ /**
941
+ * @description The instance-wide limit-auto-continue default (driven from the
942
+ * General topic). ON when unset — the auto-resume was unconditional before the
943
+ * toggle, so the default must preserve it.
944
+ */
945
+ getAutoContinueOnLimitGlobalDefault(): boolean;
946
+ /**
947
+ * @description The per-thread limit-auto-continue override, or `undefined` when
948
+ * the thread follows the instance default. A present value (true OR false) wins.
949
+ */
950
+ getAutoContinueOnLimitOverride(key: SessionKey): boolean | undefined;
951
+ /**
952
+ * @description Whether limit auto-continue is effectively enabled for `key`: the
953
+ * per-thread override if set, else the instance default (ON when unset).
954
+ */
955
+ checkIsAutoContinueOnLimitEnabled(key: SessionKey): boolean;
956
+ /**
957
+ * @description Set the instance-wide limit-auto-continue default (from General).
958
+ * Stored EXPLICITLY as a boolean (incl. `false`) so a «Disable» is durable and
959
+ * distinguishable from "never set" (which reads back as the ON default) —
960
+ * mirrors {@link setCompactOnIdleGlobalDefault}. Debounced (a preference, not
961
+ * crash-critical).
962
+ */
963
+ setAutoContinueOnLimitGlobalDefault(enabled: boolean): Promise<void>;
964
+ /**
965
+ * @description Set the per-thread limit-auto-continue override (from a regular
966
+ * topic). Stored explicitly (a present true/false wins over the global
967
+ * default); the map is created lazily on the first override, so an all-default
968
+ * instance leaves a clean `state.json`. Debounced.
969
+ */
970
+ setAutoContinueOnLimitOverride(key: SessionKey, enabled: boolean): Promise<void>;
971
+ /**
972
+ * @description The stored operator timezone, or `null` when none is set (the
973
+ * caller then falls back to the host zone — see `utils/timezone.ts`
974
+ * `getEffectiveTimezone`). Deliberately NOT defaulted here: the store reports
975
+ * what is on disk, the resolution rule lives in one place outside it.
976
+ */
977
+ getTimezone(): string | null;
978
+ /**
979
+ * @description Store the operator timezone, or drop the field on `null`
980
+ * (reset to the host zone) so a default install leaves no trace in
981
+ * `state.json` — same shape discipline as {@link setModelProviderHidden}.
982
+ *
983
+ * Flushed eagerly rather than riding the debounced save loop: a zone change
984
+ * immediately recomputes every schedule's `nextRunAt`, and losing the zone
985
+ * while keeping the recomputed fire times would leave the two disagreeing
986
+ * after a crash.
987
+ */
988
+ setTimezone(timezone: string | null): Promise<void>;
989
+ /**
990
+ * @description Fully-resolved display preferences for `key`: every field is
991
+ * present because the locked default (`minimal` for all three) is applied
992
+ * wherever the persisted record omits it. The SSE hot path reads this, so it
993
+ * must never hand back an `undefined` field.
994
+ *
995
+ * Read-time normalization: a `state.json` written before the vocabulary was
996
+ * unified may still hold legacy names (`detailed`/`brief`/`hide`/`compact`)
997
+ * — those map onto the new vocabulary here, and an unrecognized value falls
998
+ * back to the default, so old files keep working without a migration pass.
999
+ */
1000
+ getDisplayPrefs(key: SessionKey): ResolvedThreadDisplayPrefs;
1001
+ /**
1002
+ * @description Persist one display-preference field for `key`. Setting a
1003
+ * field to its locked default DELETES the override (and drops the whole
1004
+ * record / map once empty) so an all-defaults thread leaves a clean
1005
+ * `state.json` — same delete-when-default idiom as {@link setTraceConfig}.
1006
+ * Not crash-critical (a rendering preference), so it rides the debounced
1007
+ * save loop rather than an immediate `flush()`. Callers pass an
1008
+ * already-normalized value — legacy names never reach the store on the write
1009
+ * path. The `view` field (S6) rides the same record and the same idiom, with
1010
+ * its own locked default.
1011
+ */
1012
+ setDisplayPref<TField extends keyof ThreadDisplayPrefs>(key: SessionKey, field: TField, value: NonNullable<ThreadDisplayPrefs[TField]>): Promise<void>;
1013
+ /**
1014
+ * @description Every persisted schedule across all threads, keyed by id.
1015
+ * Read at boot by the engine to re-arm timers. Returns a shallow copy of the
1016
+ * map so callers can't mutate the live state object.
1017
+ */
1018
+ getSchedules(): Record<string, ScheduleRecord>;
1019
+ /** Schedules owned by `key`, in insertion order. Empty array when none. */
1020
+ getThreadSchedules(key: SessionKey): ScheduleRecord[];
1021
+ /**
1022
+ * @description Upsert a schedule by its id. The record's `threadKey` is the
1023
+ * source of truth for ownership; callers build it via the scheduler module's
1024
+ * `createScheduleRecord`. Crash-critical fields (`nextRunAt`) ride the
1025
+ * debounced save like every other mutation — the engine calls
1026
+ * {@link flush} explicitly after a fire when the new `nextRunAt` must hit disk
1027
+ * before the process can die.
1028
+ */
1029
+ upsertSchedule(record: ScheduleRecord): Promise<void>;
1030
+ /** Remove a schedule by id. No-op (no save) when absent. */
1031
+ removeSchedule(id: string): Promise<void>;
1032
+ /**
1033
+ * @description Set the paused flag for a schedule (used by /unbind pause and
1034
+ * /bind resume in S8). Clearing the pause drops both `isPaused` and
1035
+ * `pauseReason` so the on-disk shape stays clean. No-op when the id is absent.
1036
+ */
1037
+ setSchedulePaused(id: string, paused: boolean, reason?: ScheduleRecord['pauseReason']): Promise<void>;
1038
+ /**
1039
+ * @description The HMAC secret keying the scheduler MCP tokens, created lazily
1040
+ * on first read and persisted immediately. Generated once with
1041
+ * `crypto.randomBytes` (32 bytes, hex) so the tokens the bot injects into
1042
+ * agent sessions survive restarts. The first-time write is flushed eagerly
1043
+ * (not debounced) so a crash right after minting the first token can't lose
1044
+ * the secret that token was signed with.
1045
+ */
1046
+ getSchedulerMcpSecret(): Promise<string>;
1047
+ /**
1048
+ * @description The scheduler MCP listen port persisted from a prior boot, or
1049
+ * `undefined` if never persisted (fresh / pre-feature state file). Reused so an
1050
+ * ephemeral port keeps its value across restarts (see
1051
+ * {@link StateV1.schedulerMcpPort}).
1052
+ */
1053
+ getPersistedSchedulerMcpPort(): number | undefined;
1054
+ /**
1055
+ * @description Persist the actually-bound scheduler MCP port and flush eagerly.
1056
+ * Eager (not debounced) mirrors {@link getSchedulerMcpSecret}: the injected
1057
+ * registrations point at this port, so a crash right after binding must not lose
1058
+ * it and hand the next boot a stale port. Called once at boot, only when the
1059
+ * value changed and the operator did not fix the port via env.
1060
+ */
1061
+ setSchedulerMcpPort(port: number): Promise<void>;
1062
+ /**
1063
+ * @description Every persisted pending question across all threads, keyed by
1064
+ * {@link SessionKey} string. Read at boot to re-arm the in-memory map for
1065
+ * threads whose session reattached. Returns a shallow copy so callers can't
1066
+ * mutate the live state object.
1067
+ */
1068
+ getPendingQuestions(): Record<string, PendingQuestionState>;
1069
+ /**
1070
+ * @description Persist (upsert) the pending question for `key`, mirroring the
1071
+ * in-memory `pendingQuestions.set(...)` in `bot.ts` so memory and disk never
1072
+ * drift. Crash-window is acceptable on the debounced save: the worst case
1073
+ * (process dies in the <=500ms before the flush) just falls back to the
1074
+ * pre-fix behaviour for that one question. The `messageId` patch goes through
1075
+ * here too, so the persisted record always carries the live button message.
1076
+ */
1077
+ setPendingQuestion(key: SessionKey, value: PendingQuestionState): Promise<void>;
1078
+ /**
1079
+ * @description Remove the pending question for `key`. Mirrors every in-memory
1080
+ * `pendingQuestions.delete(...)` in `bot.ts`. No-op (no save) when absent. The
1081
+ * whole map is dropped once empty so an idle bot leaves a clean `state.json`.
1082
+ */
1083
+ clearPendingQuestion(key: SessionKey): Promise<void>;
1084
+ /**
1085
+ * @description Every persisted armed auto-retry across all threads, keyed by
1086
+ * {@link SessionKey} string. Read at boot to re-arm the in-memory map after
1087
+ * sessions reattach. Returns a shallow copy so callers can't mutate the live
1088
+ * state object.
1089
+ */
1090
+ getApiRetries(): Record<string, ApiRetryState>;
1091
+ /**
1092
+ * @description Persist (upsert) the armed retry for `key`, mirroring the
1093
+ * in-memory `apiRetries.set(...)` in `bot.ts` so memory and disk never drift.
1094
+ * Crash-window is acceptable on the debounced save: the worst case (process
1095
+ * dies in the <=500ms before the flush) just loses that one armed retry, which
1096
+ * falls back to the pre-fix behaviour for that thread. Each re-arm (next
1097
+ * attempt) goes through here too, so the persisted record always carries the
1098
+ * latest attempt and `fireAt`.
1099
+ */
1100
+ setApiRetry(key: SessionKey, value: ApiRetryState): Promise<void>;
1101
+ /**
1102
+ * @description Remove the armed retry for `key`. Mirrors every in-memory
1103
+ * `apiRetries.delete(...)` in `bot.ts`. No-op (no save) when absent. The whole
1104
+ * map is dropped once empty so an idle bot leaves a clean `state.json`.
1105
+ */
1106
+ clearApiRetry(key: SessionKey): Promise<void>;
1107
+ /** @description The prompts held for `key`, oldest first; `[]` when none. A copy. */
1108
+ getLimitHeldPrompts(key: SessionKey): LimitHeldPrompt[];
1109
+ /**
1110
+ * @description Replace the prompts held for `key`; `[]` drops the entry (and
1111
+ * the map once empty). Synchronous in memory — a take must be atomic against
1112
+ * a concurrent hold — and saved debounced like the retry record it outlives.
1113
+ */
1114
+ setLimitHeldPrompts(key: SessionKey, prompts: readonly LimitHeldPrompt[]): void;
1115
+ /**
1116
+ * @description Every open request across all conversations, keyed by the
1117
+ * serialized {@link RequestGroupKey}. Returns a shallow copy so callers can't
1118
+ * mutate the live state object.
1119
+ */
1120
+ getOpenRequests(): Record<string, OpenRequestState>;
1121
+ /** @description The open request of `group`, or `undefined`. */
1122
+ getOpenRequest(group: RequestGroupKey): OpenRequestState | undefined;
1123
+ /**
1124
+ * @description Replace the open request of `group` with what `mutate` returns
1125
+ * for the current one (`undefined` removes it), under the lock of the group's
1126
+ * CONVERSATION — so a read-decide-write (supersede, close, counter update) is
1127
+ * atomic against a concurrent one for the same conversation, whichever of its
1128
+ * groups it touches. `mutate` runs
1129
+ * synchronously inside the lock; a side effect it performs (the ledger's
1130
+ * history append) therefore happens before any other writer sees the result.
1131
+ * The whole map is dropped once empty so an idle bot leaves a clean
1132
+ * `state.json`.
1133
+ */
1134
+ updateOpenRequest(group: RequestGroupKey, mutate: (current: OpenRequestState | undefined) => OpenRequestState | undefined): Promise<void>;
1135
+ /** @description The alerts of closed requests still to release (a copy). */
1136
+ getUnreleasedRequestAlerts(): Record<string, UnreleasedRequestAlert>;
1137
+ /**
1138
+ * @description Record that a closed request's alert still needs releasing.
1139
+ * Synchronous on purpose: the ledger calls it inside the close's own locked
1140
+ * step, so it rides the same save as the close.
1141
+ */
1142
+ addUnreleasedRequestAlert(requestId: string, alert: UnreleasedRequestAlert): void;
1143
+ /** @description The alert of `requestId` was released; forget it. */
1144
+ removeUnreleasedRequestAlert(requestId: string): void;
1145
+ /** @description The message id of the latest pinned answer in `key`'s conversation, or `undefined`. */
1146
+ getAnswerPinMessageId(key: SessionKey): number | undefined;
1147
+ /**
1148
+ * @description Remember the latest pinned answer of `key`'s conversation; the
1149
+ * record goes away with the thread's binding. Rides the debounced save: a lost
1150
+ * write leaves one extra pinned answer behind, never a wrong unpin.
1151
+ */
1152
+ setAnswerPinMessageId(key: SessionKey, messageId: number): Promise<void>;
1153
+ /**
1154
+ * Drop `k` from one of the optional per-conversation maps, and the map itself
1155
+ * with its last entry (an idle bot leaves a clean `state.json`). `false` when
1156
+ * there was no entry. Caller must hold the key lock.
1157
+ */
1158
+ private dropOptionalMapEntry;
1159
+ /**
1160
+ * @description The `stdout.jsonl` identity recorded when the boot recovery last
1161
+ * armed a limit wait for `key`, or `undefined` when it never did. Compared
1162
+ * against the live stat so an UNCHANGED log is not recovered twice — see
1163
+ * {@link LimitEpisodeMarker}.
1164
+ */
1165
+ getLimitEpisodeRecovered(key: SessionKey): LimitEpisodeMarker | undefined;
1166
+ /**
1167
+ * @description Record the log identity the boot recovery just armed from.
1168
+ * Debounced (a restart guard, not crash-critical: losing the last <=500ms costs
1169
+ * at worst one repeated recovery). NOT cleared by `cancelApiRetry` on purpose —
1170
+ * that fires on «⏭ Skip once» and on every inbound message, which is exactly the
1171
+ * settled-episode case the marker has to outlive.
1172
+ */
1173
+ setLimitEpisodeRecovered(key: SessionKey, value: LimitEpisodeMarker): Promise<void>;
1174
+ /**
1175
+ * Drop `keyStr`'s handled-episode marker (and the whole map once empty). Returns
1176
+ * whether anything changed. Caller must hold the key lock.
1177
+ */
1178
+ private dropLimitEpisodeRecovered;
1179
+ /**
1180
+ * @description Every persisted transient status-frame id list across all
1181
+ * threads, keyed by {@link SessionKey} string. Read at boot (after reattach) to
1182
+ * delete any frame left on screen by an UNGRACEFUL exit. Returns a shallow copy
1183
+ * so callers can't mutate the live state object.
1184
+ */
1185
+ getTransientFrames(): Record<string, number[]>;
1186
+ /**
1187
+ * @description Replace the persisted transient status-frame ids for `key`
1188
+ * (the live "✽ working…" status frame, the thinking indicator, the sub-agent
1189
+ * status — whichever are currently on screen). Mirrors the in-memory
1190
+ * `ThreadMessageState` write in `bot.ts`'s frame-id setters so disk can clean
1191
+ * up what the graceful sweep would have. Debounced (NOT flushed): the frames
1192
+ * are cosmetic. An empty list drops the key (and the whole map once empty) so an
1193
+ * idle bot leaves a clean `state.json`. A no-op (no save) when the id list is
1194
+ * unchanged, so the per-turn create/delete churn doesn't reset the save timer
1195
+ * on every identical re-persist.
1196
+ */
1197
+ setTransientFrames(key: SessionKey, ids: number[]): Promise<void>;
1198
+ /** Schedule a save in `saveDebounceMs`. Repeated calls reset the timer. */
1199
+ private scheduleSave;
1200
+ /**
1201
+ * @description Force a save right now and await on-disk persistence.
1202
+ *
1203
+ * Used by:
1204
+ * - shutdown handlers — to guarantee no in-memory state is lost,
1205
+ * - critical paths (initial corruption-archived fresh-start),
1206
+ * - tests.
1207
+ *
1208
+ * Internally serialises against any in-flight write — only one rename
1209
+ * happens at a time per store.
1210
+ */
1211
+ flush(): Promise<void>;
1212
+ }
1213
+ /**
1214
+ * @description Resolve the default `DATA_DIR` for the running bot.
1215
+ *
1216
+ * Priority:
1217
+ * 1. `process.env.DATA_DIR` (set by the operator — required for the
1218
+ * two-instance setup, plan §10.7).
1219
+ * 2. `~/.telegramCode` — single-instance default.
1220
+ *
1221
+ * Two bots on the same host MUST set distinct `DATA_DIR` values, otherwise
1222
+ * they'd silently share `state.json` and corrupt each other. Plan §16.2
1223
+ * adds a startup `.lock` check; that lives in `bot.ts` (Этап 3), not here.
1224
+ */
1225
+ export declare function resolveDataDir(): string;
1226
+ /**
1227
+ * @description Create-or-fetch the singleton store. The first call performs
1228
+ * `init()` and persists archival/migration side-effects; subsequent calls
1229
+ * just return the cached instance.
1230
+ *
1231
+ * The in-flight promise is cached to keep concurrent first-callers from
1232
+ * each constructing a separate `StateStore` (two stores → two competing
1233
+ * write chains → corrupted JSON). Production triggers only one call from
1234
+ * `startBot()`, but the cost of the guard is trivial.
1235
+ *
1236
+ * Tests should instantiate `new StateStore(...)` directly instead.
1237
+ */
1238
+ export declare function getStateStore(): Promise<StateStore>;
1239
+ /**
1240
+ * @description Reset the singleton — only for tests. Production code should
1241
+ * never call this; doing so would leak in-flight write promises.
1242
+ */
1243
+ export declare function _resetStateStoreSingletonForTests(): void;
1244
+ export { fs as _fsForTests };
1245
+ //# sourceMappingURL=state.d.ts.map