charness 4.0.1 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/DEVELOPMENT.md +3 -2
  3. package/SETUP.md +34 -8
  4. package/dist/adapters/claudeCliAdapter.d.ts.map +1 -1
  5. package/dist/adapters/claudeCliAdapter.js +3 -2
  6. package/dist/adapters/claudeCliAdapter.js.map +1 -1
  7. package/dist/adapters/claudeJsonStreamAdapter.d.ts +61 -5
  8. package/dist/adapters/claudeJsonStreamAdapter.d.ts.map +1 -1
  9. package/dist/adapters/claudeJsonStreamAdapter.js +147 -18
  10. package/dist/adapters/claudeJsonStreamAdapter.js.map +1 -1
  11. package/dist/adapters/openCodeAdapter.d.ts +1 -0
  12. package/dist/adapters/openCodeAdapter.d.ts.map +1 -1
  13. package/dist/adapters/openCodeAdapter.js +11 -0
  14. package/dist/adapters/openCodeAdapter.js.map +1 -1
  15. package/dist/bot.d.ts.map +1 -1
  16. package/dist/bot.js +430 -297
  17. package/dist/bot.js.map +1 -1
  18. package/dist/connectors/jira/answerSink.d.ts +8 -0
  19. package/dist/connectors/jira/answerSink.d.ts.map +1 -1
  20. package/dist/connectors/jira/answerSink.js +15 -0
  21. package/dist/connectors/jira/answerSink.js.map +1 -1
  22. package/dist/connectors/jira/config.d.ts +16 -0
  23. package/dist/connectors/jira/config.d.ts.map +1 -1
  24. package/dist/connectors/jira/config.js +21 -2
  25. package/dist/connectors/jira/config.js.map +1 -1
  26. package/dist/connectors/jira/connector.d.ts +10 -3
  27. package/dist/connectors/jira/connector.d.ts.map +1 -1
  28. package/dist/connectors/jira/connector.js +21 -3
  29. package/dist/connectors/jira/connector.js.map +1 -1
  30. package/dist/connectors/jira/inbound.d.ts +200 -18
  31. package/dist/connectors/jira/inbound.d.ts.map +1 -1
  32. package/dist/connectors/jira/inbound.js +814 -43
  33. package/dist/connectors/jira/inbound.js.map +1 -1
  34. package/dist/connectors/jira/prompt.d.ts +46 -0
  35. package/dist/connectors/jira/prompt.d.ts.map +1 -1
  36. package/dist/connectors/jira/prompt.js +123 -15
  37. package/dist/connectors/jira/prompt.js.map +1 -1
  38. package/dist/connectors/jira/trigger.d.ts +27 -4
  39. package/dist/connectors/jira/trigger.d.ts.map +1 -1
  40. package/dist/connectors/jira/trigger.js +35 -1
  41. package/dist/connectors/jira/trigger.js.map +1 -1
  42. package/dist/connectors/jira/triggerLog.d.ts +60 -5
  43. package/dist/connectors/jira/triggerLog.d.ts.map +1 -1
  44. package/dist/connectors/jira/triggerLog.js +116 -7
  45. package/dist/connectors/jira/triggerLog.js.map +1 -1
  46. package/dist/connectors/telegram/answerSink.d.ts +12 -0
  47. package/dist/connectors/telegram/answerSink.d.ts.map +1 -1
  48. package/dist/connectors/telegram/answerSink.js +23 -0
  49. package/dist/connectors/telegram/answerSink.js.map +1 -1
  50. package/dist/connectors/telegram/botApiConnection.d.ts +2 -1
  51. package/dist/connectors/telegram/botApiConnection.d.ts.map +1 -1
  52. package/dist/connectors/telegram/botApiConnection.js +19 -1
  53. package/dist/connectors/telegram/botApiConnection.js.map +1 -1
  54. package/dist/connectors/telegram/commands/botCore.d.ts +13 -5
  55. package/dist/connectors/telegram/commands/botCore.d.ts.map +1 -1
  56. package/dist/connectors/telegram/commands/runners.d.ts +29 -2
  57. package/dist/connectors/telegram/commands/runners.d.ts.map +1 -1
  58. package/dist/connectors/telegram/commands/runners.js +84 -45
  59. package/dist/connectors/telegram/commands/runners.js.map +1 -1
  60. package/dist/connectors/telegram/outbound.d.ts +1 -1
  61. package/dist/connectors/telegram/outbound.d.ts.map +1 -1
  62. package/dist/connectors/telegram/outbound.js +3 -1
  63. package/dist/connectors/telegram/outbound.js.map +1 -1
  64. package/dist/connectors/telegram/outputBacklogGlue.d.ts +1 -1
  65. package/dist/connectors/telegram/outputBacklogGlue.js +1 -1
  66. package/dist/connectors/telegram/outputFlushPlan.d.ts +23 -8
  67. package/dist/connectors/telegram/outputFlushPlan.d.ts.map +1 -1
  68. package/dist/connectors/telegram/outputFlushPlan.js +22 -13
  69. package/dist/connectors/telegram/outputFlushPlan.js.map +1 -1
  70. package/dist/connectors/telegram/pinnedNoticeSlot.d.ts +31 -0
  71. package/dist/connectors/telegram/pinnedNoticeSlot.d.ts.map +1 -0
  72. package/dist/connectors/telegram/pinnedNoticeSlot.js +43 -0
  73. package/dist/connectors/telegram/pinnedNoticeSlot.js.map +1 -0
  74. package/dist/connectors/telegram/sendOutcome.d.ts +50 -0
  75. package/dist/connectors/telegram/sendOutcome.d.ts.map +1 -0
  76. package/dist/connectors/telegram/sendOutcome.js +49 -0
  77. package/dist/connectors/telegram/sendOutcome.js.map +1 -0
  78. package/dist/connectors/telegram/telegramFailureRetry.d.ts +17 -0
  79. package/dist/connectors/telegram/telegramFailureRetry.d.ts.map +1 -0
  80. package/dist/connectors/telegram/telegramFailureRetry.js +29 -0
  81. package/dist/connectors/telegram/telegramFailureRetry.js.map +1 -0
  82. package/dist/connectors/telegram/unpinMessages.d.ts +1 -1
  83. package/dist/connectors/telegram/unpinMessages.d.ts.map +1 -1
  84. package/dist/connectors/telegram/unpinMessages.js +3 -18
  85. package/dist/connectors/telegram/unpinMessages.js.map +1 -1
  86. package/dist/hooks/claudeSkillsRestoreHook.d.ts +105 -0
  87. package/dist/hooks/claudeSkillsRestoreHook.d.ts.map +1 -0
  88. package/dist/hooks/claudeSkillsRestoreHook.js +276 -0
  89. package/dist/hooks/claudeSkillsRestoreHook.js.map +1 -0
  90. package/dist/i18n/de.d.ts.map +1 -1
  91. package/dist/i18n/de.js +4 -0
  92. package/dist/i18n/de.js.map +1 -1
  93. package/dist/i18n/en.d.ts.map +1 -1
  94. package/dist/i18n/en.js +4 -0
  95. package/dist/i18n/en.js.map +1 -1
  96. package/dist/i18n/es.d.ts.map +1 -1
  97. package/dist/i18n/es.js +4 -0
  98. package/dist/i18n/es.js.map +1 -1
  99. package/dist/i18n/fr.d.ts.map +1 -1
  100. package/dist/i18n/fr.js +4 -0
  101. package/dist/i18n/fr.js.map +1 -1
  102. package/dist/i18n/hi.d.ts.map +1 -1
  103. package/dist/i18n/hi.js +4 -0
  104. package/dist/i18n/hi.js.map +1 -1
  105. package/dist/i18n/ja.d.ts.map +1 -1
  106. package/dist/i18n/ja.js +4 -0
  107. package/dist/i18n/ja.js.map +1 -1
  108. package/dist/i18n/ka.d.ts.map +1 -1
  109. package/dist/i18n/ka.js +4 -0
  110. package/dist/i18n/ka.js.map +1 -1
  111. package/dist/i18n/pt.d.ts.map +1 -1
  112. package/dist/i18n/pt.js +4 -0
  113. package/dist/i18n/pt.js.map +1 -1
  114. package/dist/i18n/ru.d.ts.map +1 -1
  115. package/dist/i18n/ru.js +4 -0
  116. package/dist/i18n/ru.js.map +1 -1
  117. package/dist/i18n/uk.d.ts.map +1 -1
  118. package/dist/i18n/uk.js +4 -0
  119. package/dist/i18n/uk.js.map +1 -1
  120. package/dist/i18n/uz.d.ts.map +1 -1
  121. package/dist/i18n/uz.js +4 -0
  122. package/dist/i18n/uz.js.map +1 -1
  123. package/dist/i18n/zh.d.ts.map +1 -1
  124. package/dist/i18n/zh.js +4 -0
  125. package/dist/i18n/zh.js.map +1 -1
  126. package/dist/i18n.d.ts.map +1 -1
  127. package/dist/i18n.js +2 -1
  128. package/dist/i18n.js.map +1 -1
  129. package/dist/platform/outbound.d.ts +4 -1
  130. package/dist/platform/outbound.d.ts.map +1 -1
  131. package/dist/platform/outbound.js.map +1 -1
  132. package/dist/rateLimiter.d.ts +33 -1
  133. package/dist/rateLimiter.d.ts.map +1 -1
  134. package/dist/rateLimiter.js +91 -5
  135. package/dist/rateLimiter.js.map +1 -1
  136. package/dist/requests/requestHeader.d.ts.map +1 -1
  137. package/dist/requests/requestHeader.js +1 -0
  138. package/dist/requests/requestHeader.js.map +1 -1
  139. package/dist/requests/types.d.ts +4 -1
  140. package/dist/requests/types.d.ts.map +1 -1
  141. package/dist/requests/wakeUpEngine.d.ts +31 -1
  142. package/dist/requests/wakeUpEngine.d.ts.map +1 -1
  143. package/dist/requests/wakeUpEngine.js +94 -2
  144. package/dist/requests/wakeUpEngine.js.map +1 -1
  145. package/dist/requests/wakeUpRules.d.ts +7 -0
  146. package/dist/requests/wakeUpRules.d.ts.map +1 -1
  147. package/dist/requests/wakeUpRules.js +14 -0
  148. package/dist/requests/wakeUpRules.js.map +1 -1
  149. package/dist/runnerUtility/pueueDaemon.d.ts +7 -13
  150. package/dist/runnerUtility/pueueDaemon.d.ts.map +1 -1
  151. package/dist/runnerUtility/pueueDaemon.js +8 -27
  152. package/dist/runnerUtility/pueueDaemon.js.map +1 -1
  153. package/dist/scheduler/engine.d.ts +17 -4
  154. package/dist/scheduler/engine.d.ts.map +1 -1
  155. package/dist/scheduler/engine.js +55 -10
  156. package/dist/scheduler/engine.js.map +1 -1
  157. package/dist/scheduler/mcpBoot.d.ts +6 -2
  158. package/dist/scheduler/mcpBoot.d.ts.map +1 -1
  159. package/dist/scheduler/mcpBoot.js +7 -1
  160. package/dist/scheduler/mcpBoot.js.map +1 -1
  161. package/dist/scheduler/mcpSurface.d.ts.map +1 -1
  162. package/dist/scheduler/mcpSurface.js +18 -9
  163. package/dist/scheduler/mcpSurface.js.map +1 -1
  164. package/dist/selfUpdate/selfCheck.d.ts.map +1 -1
  165. package/dist/selfUpdate/selfCheck.js +1 -1
  166. package/dist/selfUpdate/selfCheck.js.map +1 -1
  167. package/dist/sendErrorClassifier.d.ts +6 -0
  168. package/dist/sendErrorClassifier.d.ts.map +1 -1
  169. package/dist/sendErrorClassifier.js +9 -0
  170. package/dist/sendErrorClassifier.js.map +1 -1
  171. package/dist/startupPromptBuffer.d.ts +8 -8
  172. package/dist/startupPromptBuffer.d.ts.map +1 -1
  173. package/dist/startupPromptBuffer.js +7 -5
  174. package/dist/startupPromptBuffer.js.map +1 -1
  175. package/dist/testTimings.d.ts +6 -3
  176. package/dist/testTimings.d.ts.map +1 -1
  177. package/dist/testTimings.js +7 -2
  178. package/dist/testTimings.js.map +1 -1
  179. package/dist/threadRouting.d.ts +23 -0
  180. package/dist/threadRouting.d.ts.map +1 -1
  181. package/dist/threadRouting.js +28 -0
  182. package/dist/threadRouting.js.map +1 -1
  183. package/dist/trackers/taskAgentSlots.d.ts +42 -3
  184. package/dist/trackers/taskAgentSlots.d.ts.map +1 -1
  185. package/dist/trackers/taskAgentSlots.js +31 -11
  186. package/dist/trackers/taskAgentSlots.js.map +1 -1
  187. package/dist/types.d.ts +16 -0
  188. package/dist/types.d.ts.map +1 -1
  189. package/dist/utils/agentPlugin.d.ts +7 -0
  190. package/dist/utils/agentPlugin.d.ts.map +1 -1
  191. package/dist/utils/agentPlugin.js +12 -0
  192. package/dist/utils/agentPlugin.js.map +1 -1
  193. package/dist/utils/claudeCompactHook.d.ts +73 -10
  194. package/dist/utils/claudeCompactHook.d.ts.map +1 -1
  195. package/dist/utils/claudeCompactHook.js +96 -17
  196. package/dist/utils/claudeCompactHook.js.map +1 -1
  197. package/dist/utils/claudeProfiles.d.ts +8 -0
  198. package/dist/utils/claudeProfiles.d.ts.map +1 -1
  199. package/dist/utils/claudeProfiles.js +12 -2
  200. package/dist/utils/claudeProfiles.js.map +1 -1
  201. package/dist/utils/claudeTranscriptEpoch.d.ts +15 -0
  202. package/dist/utils/claudeTranscriptEpoch.d.ts.map +1 -0
  203. package/dist/utils/claudeTranscriptEpoch.js +120 -0
  204. package/dist/utils/claudeTranscriptEpoch.js.map +1 -0
  205. package/dist/utils/clearStatusCoalescer.d.ts +24 -0
  206. package/dist/utils/clearStatusCoalescer.d.ts.map +1 -0
  207. package/dist/utils/clearStatusCoalescer.js +25 -0
  208. package/dist/utils/clearStatusCoalescer.js.map +1 -0
  209. package/dist/utils/compactOnIdle.d.ts +91 -34
  210. package/dist/utils/compactOnIdle.d.ts.map +1 -1
  211. package/dist/utils/compactOnIdle.js +149 -31
  212. package/dist/utils/compactOnIdle.js.map +1 -1
  213. package/dist/utils/fileSendPlan.d.ts +30 -8
  214. package/dist/utils/fileSendPlan.d.ts.map +1 -1
  215. package/dist/utils/fileSendPlan.js +37 -12
  216. package/dist/utils/fileSendPlan.js.map +1 -1
  217. package/dist/utils/fileSendService.d.ts +1 -1
  218. package/dist/utils/fileSendService.d.ts.map +1 -1
  219. package/dist/utils/fileSendService.js +9 -1
  220. package/dist/utils/fileSendService.js.map +1 -1
  221. package/dist/utils/groupOutputBacklog.d.ts +90 -0
  222. package/dist/utils/groupOutputBacklog.d.ts.map +1 -0
  223. package/dist/utils/groupOutputBacklog.js +134 -0
  224. package/dist/utils/groupOutputBacklog.js.map +1 -0
  225. package/dist/utils/imageDimensions.d.ts +32 -0
  226. package/dist/utils/imageDimensions.d.ts.map +1 -0
  227. package/dist/utils/imageDimensions.js +181 -0
  228. package/dist/utils/imageDimensions.js.map +1 -0
  229. package/dist/utils/jsonStreamHost.d.ts +35 -9
  230. package/dist/utils/jsonStreamHost.d.ts.map +1 -1
  231. package/dist/utils/jsonStreamHost.js +59 -16
  232. package/dist/utils/jsonStreamHost.js.map +1 -1
  233. package/dist/utils/lostWork.d.ts +8 -2
  234. package/dist/utils/lostWork.d.ts.map +1 -1
  235. package/dist/utils/lostWork.js +9 -5
  236. package/dist/utils/lostWork.js.map +1 -1
  237. package/dist/utils/messageSendService.d.ts +26 -3
  238. package/dist/utils/messageSendService.d.ts.map +1 -1
  239. package/dist/utils/messageSendService.js +35 -3
  240. package/dist/utils/messageSendService.js.map +1 -1
  241. package/dist/utils/openCodeCompactPlugin.d.ts +33 -0
  242. package/dist/utils/openCodeCompactPlugin.d.ts.map +1 -1
  243. package/dist/utils/openCodeCompactPlugin.js +192 -1
  244. package/dist/utils/openCodeCompactPlugin.js.map +1 -1
  245. package/dist/utils/promptDelivery.d.ts +11 -2
  246. package/dist/utils/promptDelivery.d.ts.map +1 -1
  247. package/dist/utils/promptDelivery.js +3 -3
  248. package/dist/utils/promptDelivery.js.map +1 -1
  249. package/dist/utils/skillsRestore.d.ts +235 -0
  250. package/dist/utils/skillsRestore.d.ts.map +1 -0
  251. package/dist/utils/skillsRestore.js +515 -0
  252. package/dist/utils/skillsRestore.js.map +1 -0
  253. package/dist/utils/statusFlushDecision.js +1 -1
  254. package/dist/utils/streamedCompactionSummary.d.ts +4 -4
  255. package/dist/utils/streamedCompactionSummary.js +5 -5
  256. package/dist/utils/streamedCompactionSummary.js.map +1 -1
  257. package/dist/utils/streamedOutputLanding.d.ts +14 -0
  258. package/dist/utils/streamedOutputLanding.d.ts.map +1 -0
  259. package/dist/utils/streamedOutputLanding.js +45 -0
  260. package/dist/utils/streamedOutputLanding.js.map +1 -0
  261. package/dist/utils/typingLoopBackstop.d.ts +8 -7
  262. package/dist/utils/typingLoopBackstop.d.ts.map +1 -1
  263. package/dist/utils/typingLoopBackstop.js +6 -5
  264. package/dist/utils/typingLoopBackstop.js.map +1 -1
  265. package/npm-shrinkwrap.json +2 -2
  266. package/package.json +1 -1
  267. package/dist/utils/clearThreadOutputQueues.d.ts +0 -44
  268. package/dist/utils/clearThreadOutputQueues.d.ts.map +0 -1
  269. package/dist/utils/clearThreadOutputQueues.js +0 -39
  270. package/dist/utils/clearThreadOutputQueues.js.map +0 -1
  271. package/dist/utils/groupFinalizePlan.d.ts +0 -36
  272. package/dist/utils/groupFinalizePlan.d.ts.map +0 -1
  273. package/dist/utils/groupFinalizePlan.js +0 -31
  274. package/dist/utils/groupFinalizePlan.js.map +0 -1
@@ -89,21 +89,32 @@ export interface PendingOutputSegment {
89
89
  }
90
90
  /**
91
91
  * @name PendingOutputBuffer
92
- * @description What a thread's output queue holds until its debounce ends, oldest segment first: `bot.ts`'s
93
- * `OutputQueueState` carries it and the helpers below keep it consistent.
92
+ * @description The thread's ONE ordered backlog of unsent agent text, oldest segment first: `bot.ts`'s `OutputQueueState` carries
93
+ * it and the helpers below keep it consistent. Every segment has a number, in the order it was queued: the oldest pending one
94
+ * is `firstSeq`, the next `firstSeq + 1`, and so on. Taking the oldest out moves `firstSeq` on; a 429 leftover put back at the
95
+ * head takes its number back. A landing waits for a number to settle (`utils/groupOutputBacklog.ts`): it SEALS the segments
96
+ * up to `sealedThroughSeq`, so text queued after it never joins text it waits for.
94
97
  */
95
98
  export interface PendingOutputBuffer {
96
99
  pendingSegments: PendingOutputSegment[];
100
+ /** The number of `pendingSegments[0]`; one past the newest segment ever queued while nothing is pending. */
101
+ firstSeq: number;
102
+ /** Segments numbered up to here take no more text: a batch queued after them starts a segment of its own. */
103
+ sealedThroughSeq: number;
97
104
  }
98
105
  /** @description The thread's mark that the next output opens a new message (a prompt forwarded, a session started, a question posted, a status frame shown). */
99
106
  export interface NewMessageMark {
100
107
  needsNewMessage: boolean;
101
108
  }
109
+ /** @description The number of the newest segment queued so far (pending, or already taken out to be sent). */
110
+ export declare function getNewestPendingSeq(buffer: PendingOutputBuffer): number;
102
111
  /**
103
112
  * @description Queue one batch of agent output. Without a mark set it joins the newest segment (or starts the first one). With
104
113
  * the mark set it starts a segment of its own and spends the mark — also when an earlier segment is still waiting: that
105
114
  * text belongs to the turn before the boundary, so it flushes where it was going (as a continuation of the message it
106
- * extends) and the batch after the boundary opens a new message.
115
+ * extends) and the batch after the boundary opens a new message. A SEALED newest segment (a landing waits for it) takes no
116
+ * more text either: the batch starts a segment of its own, as a continuation when it is one — so it extends the message
117
+ * the sealed text lands in, as it would after any flush.
107
118
  *
108
119
  * The mark belongs to the first text queued AFTER it, not to whichever send completes next: a send already under way when the
109
120
  * boundary was marked (the previous turn's text on a slow Bot API round trip) would otherwise spend it, and the new turn's
@@ -116,12 +127,16 @@ export declare function addPendingOutput(buffer: PendingOutputBuffer, mark: NewM
116
127
  }): void;
117
128
  /** @description Whether anything waits to be sent. */
118
129
  export declare function checkHasPendingOutput(buffer: PendingOutputBuffer): boolean;
119
- /** @description Take the oldest segment out for a flush. `null` when nothing is pending. */
120
- export declare function takePendingOutput(buffer: PendingOutputBuffer): PendingOutputSegment | null;
130
+ /** @description Take the oldest segment out to send it, with its number. `null` when nothing is pending. */
131
+ export declare function takePendingOutput(buffer: PendingOutputBuffer): {
132
+ segment: PendingOutputSegment;
133
+ seq: number;
134
+ } | null;
121
135
  /**
122
- * @description Put the text a flush could not send (see {@link getUnsentRemainder}) back at the FRONT of the buffer: it is
123
- * older than anything queued during the send. It restarts a fresh message (its predecessors landed or were edited in
124
- * place already), so it is not a continuation; it joins the next segment unless a boundary was marked before that one.
136
+ * @description Put the text a send could not land (see {@link getUnsentRemainder}) back at the HEAD of the backlog, under the
137
+ * number of the segment it came from: it is older than everything still pending, and nothing was taken out since that segment
138
+ * (one send at a time). It restarts a fresh message (its predecessors landed or were edited in place already), so it is not a
139
+ * continuation, and it stays a segment of its own — never mixed with the newer text behind it.
125
140
  */
126
141
  export declare function requeueUnsentRemainder(buffer: PendingOutputBuffer, unsentRemainder: string): void;
127
142
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"outputFlushPlan.d.ts","sourceRoot":"","sources":["../../../src/connectors/telegram/outputFlushPlan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAUH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,cAAc,EAAE,OAAO,CAAC;IACxB,6EAA6E;IAC7E,eAAe,EAAE,OAAO,CAAC;IACzB,+DAA+D;IAC/D,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mEAAmE;IACnE,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,eAAe;IAC9B,wEAAwE;IACxE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB;;;OAGG;IACH,oBAAoB,EAAE,OAAO,CAAC;CAC/B;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,GAAG,eAAe,CAgB3E;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,yBAAyB,CACvC,kBAAkB,EAAE,OAAO,EAC3B,aAAa,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,EAAE,MAAM,CAAC;CAC1B;AAED,gKAAgK;AAChK,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,8GAA8G;AAC9G,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAEvE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,mBAAmB,EAC3B,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAC;IAAC,kBAAkB,EAAE,OAAO,CAAA;CAAE,GAC9E,IAAI,CASN;AAED,sDAAsD;AACtD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAE1E;AAED,4GAA4G;AAC5G,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,GAAG;IAAE,OAAO,EAAE,oBAAoB,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAMpH;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI,CAGjG;AAOD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKrF"}
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.getOutputFlushPlan = getOutputFlushPlan;
17
17
  exports.getGroupDeltaContinuation = getGroupDeltaContinuation;
18
18
  exports.appendPendingOutput = appendPendingOutput;
19
+ exports.getNewestPendingSeq = getNewestPendingSeq;
19
20
  exports.addPendingOutput = addPendingOutput;
20
21
  exports.checkHasPendingOutput = checkHasPendingOutput;
21
22
  exports.takePendingOutput = takePendingOutput;
@@ -95,11 +96,17 @@ function appendPendingOutput(pending, output, isContinuation, startsNewParagraph
95
96
  return pending + output;
96
97
  return startsNewParagraph ? `${pending}\n\n${output}` : `${pending}\n${output}`;
97
98
  }
99
+ /** @description The number of the newest segment queued so far (pending, or already taken out to be sent). */
100
+ function getNewestPendingSeq(buffer) {
101
+ return buffer.firstSeq + buffer.pendingSegments.length - 1;
102
+ }
98
103
  /**
99
104
  * @description Queue one batch of agent output. Without a mark set it joins the newest segment (or starts the first one). With
100
105
  * the mark set it starts a segment of its own and spends the mark — also when an earlier segment is still waiting: that
101
106
  * text belongs to the turn before the boundary, so it flushes where it was going (as a continuation of the message it
102
- * extends) and the batch after the boundary opens a new message.
107
+ * extends) and the batch after the boundary opens a new message. A SEALED newest segment (a landing waits for it) takes no
108
+ * more text either: the batch starts a segment of its own, as a continuation when it is one — so it extends the message
109
+ * the sealed text lands in, as it would after any flush.
103
110
  *
104
111
  * The mark belongs to the first text queued AFTER it, not to whichever send completes next: a send already under way when the
105
112
  * boundary was marked (the previous turn's text on a slow Bot API round trip) would otherwise spend it, and the new turn's
@@ -109,7 +116,7 @@ function addPendingOutput(buffer, mark, batch) {
109
116
  if (batch.output === '')
110
117
  return;
111
118
  const newest = buffer.pendingSegments.at(-1);
112
- if (newest && !mark.needsNewMessage) {
119
+ if (newest && !mark.needsNewMessage && getNewestPendingSeq(buffer) > buffer.sealedThroughSeq) {
113
120
  newest.output = appendPendingOutput(newest.output, batch.output, batch.isContinuation, batch.startsNewParagraph);
114
121
  return;
115
122
  }
@@ -120,22 +127,24 @@ function addPendingOutput(buffer, mark, batch) {
120
127
  function checkHasPendingOutput(buffer) {
121
128
  return buffer.pendingSegments.length > 0;
122
129
  }
123
- /** @description Take the oldest segment out for a flush. `null` when nothing is pending. */
130
+ /** @description Take the oldest segment out to send it, with its number. `null` when nothing is pending. */
124
131
  function takePendingOutput(buffer) {
125
- return buffer.pendingSegments.shift() ?? null;
132
+ const segment = buffer.pendingSegments.shift();
133
+ if (!segment)
134
+ return null;
135
+ const seq = buffer.firstSeq;
136
+ buffer.firstSeq += 1;
137
+ return { segment, seq };
126
138
  }
127
139
  /**
128
- * @description Put the text a flush could not send (see {@link getUnsentRemainder}) back at the FRONT of the buffer: it is
129
- * older than anything queued during the send. It restarts a fresh message (its predecessors landed or were edited in
130
- * place already), so it is not a continuation; it joins the next segment unless a boundary was marked before that one.
140
+ * @description Put the text a send could not land (see {@link getUnsentRemainder}) back at the HEAD of the backlog, under the
141
+ * number of the segment it came from: it is older than everything still pending, and nothing was taken out since that segment
142
+ * (one send at a time). It restarts a fresh message (its predecessors landed or were edited in place already), so it is not a
143
+ * continuation, and it stays a segment of its own — never mixed with the newer text behind it.
131
144
  */
132
145
  function requeueUnsentRemainder(buffer, unsentRemainder) {
133
- const [next, ...later] = buffer.pendingSegments;
134
- if (next && !next.startsNewMessage) {
135
- buffer.pendingSegments = [{ output: appendPendingOutput(unsentRemainder, next.output, false), isContinuation: false, startsNewMessage: false }, ...later];
136
- return;
137
- }
138
- buffer.pendingSegments = [{ output: unsentRemainder, isContinuation: false, startsNewMessage: false }, ...buffer.pendingSegments];
146
+ buffer.pendingSegments.unshift({ output: unsentRemainder, isContinuation: false, startsNewMessage: false });
147
+ buffer.firstSeq -= 1;
139
148
  }
140
149
  /** Separator used to re-join un-sent chunks before re-enqueueing them (S2). The
141
150
  * planner re-splits the rejoined text next flush, so a blank line keeps the
@@ -1 +1 @@
1
- {"version":3,"file":"outputFlushPlan.js","sourceRoot":"","sources":["../../../src/connectors/telegram/outputFlushPlan.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAsCH,gDAgBC;AA2BD,8DAOC;AAYD,kDASC;AAuCD,4CAaC;AAGD,sDAEC;AAGD,8CAEC;AAOD,wDAOC;AAqBD,gDAKC;AAjND,iDAA8C;AAC9C,uDAAoD;AAEpD;;uDAEuD;AACvD,MAAM,qBAAqB,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,IAAA,iCAAe,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC;AA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wBAAwB,GAAG,MAAM,CAAC;AAExC;;;;;;;;;;;;;GAaG;AACH,SAAgB,kBAAkB,CAAC,MAAgB,EAAE,SAAiB;IACpE,IAAI,SAAS,IAAI,MAAM,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAC5C,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC1C,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACxC,OAAO,SAAS,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { ThreadSendOutcome } from './sendOutcome';
2
+ /**
3
+ * @description The one-notice slots of a kind of pinned notice (the logged-out notice, the limit-resumed notice), by topic: the id
4
+ * of the notice pinned this episode, or {@link pinnedNoticePendingSentinel} while its post is under way. A taken slot means the
5
+ * notice was surfaced this episode, and the next event of the same episode posts no second one.
6
+ */
7
+ export type PinnedNoticeSlots = Map<string, number>;
8
+ /**
9
+ * @description What a slot holds between its reservation and the pin, so a burst of events cannot race two notices out. A real
10
+ * Telegram message id is always positive, so `-1` can never collide with one.
11
+ */
12
+ export declare const pinnedNoticePendingSentinel = -1;
13
+ /** @description The two Bot API moves of a pinned notice, bound to its topic and text by the bot. */
14
+ export interface PinnedNoticePorts {
15
+ send: () => Promise<ThreadSendOutcome>;
16
+ /** Pin the posted notice so the muted topic fires a notification. */
17
+ pin: (messageId: number) => Promise<void>;
18
+ }
19
+ /**
20
+ * @description Post and pin the notice of `topic` once per episode. The slot is reserved BEFORE the post, so a burst of events
21
+ * posts one notice. A post that FAILED releases it — a later event of the episode tries again. A post whose outcome is unknown
22
+ * keeps it: the notice may be in the topic, and a second one would be posted under it; its id is not known, so it is not pinned.
23
+ * A slot released while the post was under way (a teardown) is not taken back, and the notice is left unpinned.
24
+ */
25
+ export declare function surfacePinnedNotice(slots: PinnedNoticeSlots, topic: string, ports: PinnedNoticePorts): Promise<void>;
26
+ /**
27
+ * @description End the episode of `topic`'s notice: free its slot, so a later episode notifies again, and give back the id of the
28
+ * notice to unpin — `null` when none was pinned (no slot, or one whose pin never landed).
29
+ */
30
+ export declare function releasePinnedNoticeSlot(slots: PinnedNoticeSlots, topic: string): number | null;
31
+ //# sourceMappingURL=pinnedNoticeSlot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pinnedNoticeSlot.d.ts","sourceRoot":"","sources":["../../../src/connectors/telegram/pinnedNoticeSlot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAE9C,qGAAqG;AACrG,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACvC,qEAAqE;IACrE,GAAG,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAW1H;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK9F"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pinnedNoticePendingSentinel = void 0;
4
+ exports.surfacePinnedNotice = surfacePinnedNotice;
5
+ exports.releasePinnedNoticeSlot = releasePinnedNoticeSlot;
6
+ /**
7
+ * @description What a slot holds between its reservation and the pin, so a burst of events cannot race two notices out. A real
8
+ * Telegram message id is always positive, so `-1` can never collide with one.
9
+ */
10
+ exports.pinnedNoticePendingSentinel = -1;
11
+ /**
12
+ * @description Post and pin the notice of `topic` once per episode. The slot is reserved BEFORE the post, so a burst of events
13
+ * posts one notice. A post that FAILED releases it — a later event of the episode tries again. A post whose outcome is unknown
14
+ * keeps it: the notice may be in the topic, and a second one would be posted under it; its id is not known, so it is not pinned.
15
+ * A slot released while the post was under way (a teardown) is not taken back, and the notice is left unpinned.
16
+ */
17
+ async function surfacePinnedNotice(slots, topic, ports) {
18
+ if (slots.has(topic))
19
+ return;
20
+ slots.set(topic, exports.pinnedNoticePendingSentinel);
21
+ const outcome = await ports.send();
22
+ if (outcome.kind === 'failed') {
23
+ if (slots.get(topic) === exports.pinnedNoticePendingSentinel)
24
+ slots.delete(topic);
25
+ return;
26
+ }
27
+ if (outcome.kind === 'unknown' || !slots.has(topic))
28
+ return;
29
+ slots.set(topic, outcome.messageId);
30
+ await ports.pin(outcome.messageId);
31
+ }
32
+ /**
33
+ * @description End the episode of `topic`'s notice: free its slot, so a later episode notifies again, and give back the id of the
34
+ * notice to unpin — `null` when none was pinned (no slot, or one whose pin never landed).
35
+ */
36
+ function releasePinnedNoticeSlot(slots, topic) {
37
+ const pinnedId = slots.get(topic);
38
+ if (pinnedId === undefined)
39
+ return null;
40
+ slots.delete(topic);
41
+ return pinnedId === exports.pinnedNoticePendingSentinel ? null : pinnedId;
42
+ }
43
+ //# sourceMappingURL=pinnedNoticeSlot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pinnedNoticeSlot.js","sourceRoot":"","sources":["../../../src/connectors/telegram/pinnedNoticeSlot.ts"],"names":[],"mappings":";;;AA4BA,kDAWC;AAMD,0DAKC;AAzCD;;;GAGG;AACU,QAAA,2BAA2B,GAAG,CAAC,CAAC,CAAC;AAS9C;;;;;GAKG;AACI,KAAK,UAAU,mBAAmB,CAAC,KAAwB,EAAE,KAAa,EAAE,KAAwB;IACzG,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO;IAC7B,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,mCAA2B,CAAC,CAAC;IAC9C,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;IACnC,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,mCAA2B;YAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1E,OAAO;IACT,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO;IAC5D,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,MAAM,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AACrC,CAAC;AAED;;;GAGG;AACH,SAAgB,uBAAuB,CAAC,KAAwB,EAAE,KAAa;IAC7E,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACxC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpB,OAAO,QAAQ,KAAK,mCAA2B,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;AACpE,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { GroupOutputSendResult } from '../../utils/groupOutputBacklog';
2
+ import type { ThreadMessageEdit } from './commands/botCore';
3
+ /**
4
+ * @description How a send to a topic ended: `sent` with the message id; `failed` — it did not land, and `isRetryable` says
5
+ * whether trying again later may help (a 429, a 5xx, no answer from the network) or not (a closed topic, another 4xx), and `isForbidden`
6
+ * (set only when true) that Telegram answered 403 — the bot may not write to that chat at all (see `checkIsForbiddenError`);
7
+ * `unknown` — the Bot API did not answer within the send queue's deadline (`rateLimiter.ts` `SendOutcomeUnknownError`): the
8
+ * message may or may not be in the topic, so it must NOT be sent again.
9
+ */
10
+ export type ThreadSendOutcome = {
11
+ kind: 'sent';
12
+ messageId: number;
13
+ } | {
14
+ kind: 'failed';
15
+ isRetryable: boolean;
16
+ isForbidden?: boolean;
17
+ } | {
18
+ kind: 'unknown';
19
+ };
20
+ /** @description How an edit of a topic message ended, with `unknown` as for a send: it may or may not be applied. */
21
+ export type ThreadEditOutcome = ThreadMessageEdit | 'unknown';
22
+ /**
23
+ * @description What an edit whose outcome is unknown means to the bot's callers: made. A caller answers a FAILED edit by posting
24
+ * the content anew (a status or thinking frame gets a new message, a screen is posted again, the output flush sends the text
25
+ * fresh) — and if the edit did land, the topic would then show it twice. A missed edit is the smaller harm: the next edit of
26
+ * the same message rewrites it whole.
27
+ */
28
+ export declare function getCallerEditResult(outcome: ThreadEditOutcome): ThreadMessageEdit;
29
+ /** @description The message the topic's output continues: what the next continuation edits, and the text it appends to. */
30
+ export interface OutputMessageCursor {
31
+ lastMessageId: number | null;
32
+ lastMessageText: string | null;
33
+ }
34
+ /** @description The two Bot API moves of one output flush, bound to a topic by the bot. */
35
+ export interface OutputChunkPorts {
36
+ /** Edit the last message to `chunk` (a continuation that grows it in place). */
37
+ editLastMessage: (messageId: number, chunk: string) => Promise<ThreadEditOutcome>;
38
+ /** Send `chunk` as a message of its own. */
39
+ sendChunk: (chunk: string) => Promise<ThreadSendOutcome>;
40
+ }
41
+ /**
42
+ * @description Land the chunks of one output flush (`getOutputFlushPlan`), in order, updating `cursor`. When `isFirstChunkAnEdit`
43
+ * the first chunk grows the last message in place; an edit that failed sends every chunk fresh instead (the message was deleted,
44
+ * say), but an edit whose outcome is UNKNOWN counts as made — sent fresh, the text could appear twice. A chunk that FAILS stops
45
+ * the run (the cooldown would drop the rest too) and the rest is the remainder, with whether trying it again may help (the
46
+ * backlog puts it back, or drops it when Telegram refused it for good). A chunk whose outcome is UNKNOWN counts as sent
47
+ * and is never sent again; the next text opens a message of its own, since the message it would continue is not known.
48
+ */
49
+ export declare function sendOutputChunks(chunks: string[], isFirstChunkAnEdit: boolean, cursor: OutputMessageCursor, ports: OutputChunkPorts): Promise<GroupOutputSendResult>;
50
+ //# sourceMappingURL=sendOutcome.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendOutcome.d.ts","sourceRoot":"","sources":["../../../src/connectors/telegram/sendOutcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAG5D;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,WAAW,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAE5J,qHAAqH;AACrH,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,SAAS,CAAC;AAE9D;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,GAAG,iBAAiB,CAEjF;AAED,2HAA2H;AAC3H,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,2FAA2F;AAC3F,MAAM,WAAW,gBAAgB;IAC/B,gFAAgF;IAChF,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClF,4CAA4C;IAC5C,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC1D;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EAAE,EAChB,kBAAkB,EAAE,OAAO,EAC3B,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,qBAAqB,CAAC,CAwBhC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCallerEditResult = getCallerEditResult;
4
+ exports.sendOutputChunks = sendOutputChunks;
5
+ const outputFlushPlan_1 = require("./outputFlushPlan");
6
+ /**
7
+ * @description What an edit whose outcome is unknown means to the bot's callers: made. A caller answers a FAILED edit by posting
8
+ * the content anew (a status or thinking frame gets a new message, a screen is posted again, the output flush sends the text
9
+ * fresh) — and if the edit did land, the topic would then show it twice. A missed edit is the smaller harm: the next edit of
10
+ * the same message rewrites it whole.
11
+ */
12
+ function getCallerEditResult(outcome) {
13
+ return outcome === 'unknown' ? 'edited' : outcome;
14
+ }
15
+ /**
16
+ * @description Land the chunks of one output flush (`getOutputFlushPlan`), in order, updating `cursor`. When `isFirstChunkAnEdit`
17
+ * the first chunk grows the last message in place; an edit that failed sends every chunk fresh instead (the message was deleted,
18
+ * say), but an edit whose outcome is UNKNOWN counts as made — sent fresh, the text could appear twice. A chunk that FAILS stops
19
+ * the run (the cooldown would drop the rest too) and the rest is the remainder, with whether trying it again may help (the
20
+ * backlog puts it back, or drops it when Telegram refused it for good). A chunk whose outcome is UNKNOWN counts as sent
21
+ * and is never sent again; the next text opens a message of its own, since the message it would continue is not known.
22
+ */
23
+ async function sendOutputChunks(chunks, isFirstChunkAnEdit, cursor, ports) {
24
+ let startIndex = 0;
25
+ if (isFirstChunkAnEdit && cursor.lastMessageId !== null) {
26
+ const editOutcome = chunks[0] === cursor.lastMessageText ? 'edited' : await ports.editLastMessage(cursor.lastMessageId, chunks[0]);
27
+ if (editOutcome === 'edited' || editOutcome === 'unknown') {
28
+ cursor.lastMessageText = chunks[0];
29
+ startIndex = 1;
30
+ }
31
+ }
32
+ for (let index = startIndex; index < chunks.length; index++) {
33
+ const outcome = await ports.sendChunk(chunks[index]);
34
+ if (outcome.kind === 'failed') {
35
+ const unsentRemainder = (0, outputFlushPlan_1.getUnsentRemainder)(chunks, index);
36
+ return unsentRemainder === null ? { unsentRemainder: null } : { unsentRemainder, isRetryable: outcome.isRetryable };
37
+ }
38
+ if (outcome.kind === 'sent') {
39
+ cursor.lastMessageId = outcome.messageId;
40
+ cursor.lastMessageText = chunks[index];
41
+ }
42
+ else {
43
+ cursor.lastMessageId = null;
44
+ cursor.lastMessageText = null;
45
+ }
46
+ }
47
+ return { unsentRemainder: null };
48
+ }
49
+ //# sourceMappingURL=sendOutcome.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendOutcome.js","sourceRoot":"","sources":["../../../src/connectors/telegram/sendOutcome.ts"],"names":[],"mappings":";;AAsBA,kDAEC;AAwBD,4CA6BC;AA3ED,uDAAuD;AAcvD;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,OAA0B;IAC5D,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;AACpD,CAAC;AAgBD;;;;;;;GAOG;AACI,KAAK,UAAU,gBAAgB,CACpC,MAAgB,EAChB,kBAA2B,EAC3B,MAA2B,EAC3B,KAAuB;IAEvB,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,kBAAkB,IAAI,MAAM,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;QACxD,MAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACnI,IAAI,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC1D,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACnC,UAAU,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;IACD,KAAK,IAAI,KAAK,GAAG,UAAU,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC5D,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACrD,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC9B,MAAM,eAAe,GAAG,IAAA,oCAAkB,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAC1D,OAAO,eAAe,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;QACtH,CAAC;QACD,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5B,MAAM,CAAC,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC;YACzC,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,aAAa,GAAG,IAAI,CAAC;YAC5B,MAAM,CAAC,eAAe,GAAG,IAAI,CAAC;QAChC,CAAC;IACH,CAAC;IACD,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;AACnC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { ThreadSendOutcome } from './sendOutcome';
2
+ /**
3
+ * @description Whether a Bot API call that failed with `error` may succeed if made again later. A Bot API answer is judged by its
4
+ * code (429 and 5xx pass, any other is final: the topic is closed, the message is gone, the bot lost its right, the chat is
5
+ * gone); the pacer's own «rate limit survived the wait» error passes too; with no answer at all only the NETWORK may be at fault
6
+ * (Telegram unreachable or silent). Anything else — a bug in our code, a TypeError, a thrown string — is final: the same
7
+ * exception would come back at every try, for ever.
8
+ */
9
+ export declare function checkIsTelegramFailureRetryable(error: unknown): boolean;
10
+ /**
11
+ * @description The outcome of a send that FAILED with `error`: whether trying again later may help ({@link checkIsTelegramFailureRetryable}) and — set
12
+ * only when true — that Telegram answered 403, so the bot may not write to that chat at all (a person who never opened a private chat with it, or blocked it).
13
+ */
14
+ export declare function getFailedSendOutcome(error: unknown): Extract<ThreadSendOutcome, {
15
+ kind: 'failed';
16
+ }>;
17
+ //# sourceMappingURL=telegramFailureRetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telegramFailureRetry.d.ts","sourceRoot":"","sources":["../../../src/connectors/telegram/telegramFailureRetry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIvE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAEnG"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkIsTelegramFailureRetryable = checkIsTelegramFailureRetryable;
4
+ exports.getFailedSendOutcome = getFailedSendOutcome;
5
+ const rateLimiter_1 = require("../../rateLimiter");
6
+ const sendErrorClassifier_1 = require("../../sendErrorClassifier");
7
+ const telegramError_1 = require("../../utils/telegramError");
8
+ /**
9
+ * @description Whether a Bot API call that failed with `error` may succeed if made again later. A Bot API answer is judged by its
10
+ * code (429 and 5xx pass, any other is final: the topic is closed, the message is gone, the bot lost its right, the chat is
11
+ * gone); the pacer's own «rate limit survived the wait» error passes too; with no answer at all only the NETWORK may be at fault
12
+ * (Telegram unreachable or silent). Anything else — a bug in our code, a TypeError, a thrown string — is final: the same
13
+ * exception would come back at every try, for ever.
14
+ */
15
+ function checkIsTelegramFailureRetryable(error) {
16
+ if ((0, rateLimiter_1.checkIsRateLimitedError)(error))
17
+ return true;
18
+ if ((0, sendErrorClassifier_1.checkIsApiError)(error) && (0, sendErrorClassifier_1.getErrorCode)(error) !== undefined)
19
+ return (0, telegramError_1.checkIsRetryableTelegramError)(error);
20
+ return (0, telegramError_1.checkIsNetworkError)(error);
21
+ }
22
+ /**
23
+ * @description The outcome of a send that FAILED with `error`: whether trying again later may help ({@link checkIsTelegramFailureRetryable}) and — set
24
+ * only when true — that Telegram answered 403, so the bot may not write to that chat at all (a person who never opened a private chat with it, or blocked it).
25
+ */
26
+ function getFailedSendOutcome(error) {
27
+ return { kind: 'failed', isRetryable: checkIsTelegramFailureRetryable(error), ...((0, sendErrorClassifier_1.checkIsForbiddenError)(error) ? { isForbidden: true } : {}) };
28
+ }
29
+ //# sourceMappingURL=telegramFailureRetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telegramFailureRetry.js","sourceRoot":"","sources":["../../../src/connectors/telegram/telegramFailureRetry.ts"],"names":[],"mappings":";;AAYA,0EAIC;AAMD,oDAEC;AAxBD,mDAA4D;AAC5D,mEAAiG;AACjG,6DAA+F;AAG/F;;;;;;GAMG;AACH,SAAgB,+BAA+B,CAAC,KAAc;IAC5D,IAAI,IAAA,qCAAuB,EAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAChD,IAAI,IAAA,qCAAe,EAAC,KAAK,CAAC,IAAI,IAAA,kCAAY,EAAC,KAAK,CAAC,KAAK,SAAS;QAAE,OAAO,IAAA,6CAA6B,EAAC,KAAK,CAAC,CAAC;IAC7G,OAAO,IAAA,mCAAmB,EAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,KAAc;IACjD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,+BAA+B,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,IAAA,2CAAqB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACjJ,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * pinned (Telegram answers «message to unpin not found»), the bot lost the right to pin, the chat is gone — a retry changes
5
5
  * nothing, so the id counts as released and the caller forgets it. So is an error that is neither the network's nor a Bot API
6
6
  * answer (a bug of ours): it would repeat at every run. Only a failure that may pass is reported back: Telegram never answered
7
- * (a dropped connection, a timeout), an exhausted rate-limit wait, a 429, or a 5xx (`checkShouldTryUnpinAgain`). There is no cap
7
+ * (a dropped connection, a timeout), an exhausted rate-limit wait, a 429, or a 5xx (`checkIsTelegramFailureRetryable`). There is no cap
8
8
  * on the tries of a retryable id: the outage that causes one ends. Never rejects; `onFailure` is told every failure, final or
9
9
  * not, to log it.
10
10
  */
@@ -1 +1 @@
1
- {"version":3,"file":"unpinMessages.d.ts","sourceRoot":"","sources":["../../../src/connectors/telegram/unpinMessages.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CACnD,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC9C,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,GACrD,OAAO,CAAC,MAAM,EAAE,CAAC,CAWnB"}
1
+ {"version":3,"file":"unpinMessages.d.ts","sourceRoot":"","sources":["../../../src/connectors/telegram/unpinMessages.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CACnD,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC9C,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,GACrD,OAAO,CAAC,MAAM,EAAE,CAAC,CAWnB"}
@@ -1,29 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unpinMessagesReportingRetryable = unpinMessagesReportingRetryable;
4
- const rateLimiter_1 = require("../../rateLimiter");
5
- const sendErrorClassifier_1 = require("../../sendErrorClassifier");
6
- const telegramError_1 = require("../../utils/telegramError");
7
- /**
8
- * @description Whether an unpin that failed with `error` may succeed later. A Bot API answer is judged by its code (429 and 5xx
9
- * pass, any other is final); the pacer's own «rate limit survived the wait» error passes too; with no answer at all only the
10
- * NETWORK may be at fault (Telegram unreachable or silent). Anything else — a bug in our code, a TypeError, a thrown string — is
11
- * final: the same exception would come back at every run of the check, for ever, and one log line each time.
12
- */
13
- function checkShouldTryUnpinAgain(error) {
14
- if ((0, rateLimiter_1.checkIsRateLimitedError)(error))
15
- return true;
16
- if ((0, sendErrorClassifier_1.checkIsApiError)(error) && (0, sendErrorClassifier_1.getErrorCode)(error) !== undefined)
17
- return (0, telegramError_1.checkIsRetryableTelegramError)(error);
18
- return (0, telegramError_1.checkIsNetworkError)(error);
19
- }
4
+ const telegramFailureRetry_1 = require("./telegramFailureRetry");
20
5
  /**
21
6
  * @description Unpin messages one by one and resolve with the ids still pinned that are WORTH ANOTHER TRY — the contract of
22
7
  * the scheduler's `unpinMessages` port. A failure the Bot API answered for good is final: the message is gone, was never
23
8
  * pinned (Telegram answers «message to unpin not found»), the bot lost the right to pin, the chat is gone — a retry changes
24
9
  * nothing, so the id counts as released and the caller forgets it. So is an error that is neither the network's nor a Bot API
25
10
  * answer (a bug of ours): it would repeat at every run. Only a failure that may pass is reported back: Telegram never answered
26
- * (a dropped connection, a timeout), an exhausted rate-limit wait, a 429, or a 5xx (`checkShouldTryUnpinAgain`). There is no cap
11
+ * (a dropped connection, a timeout), an exhausted rate-limit wait, a 429, or a 5xx (`checkIsTelegramFailureRetryable`). There is no cap
27
12
  * on the tries of a retryable id: the outage that causes one ends. Never rejects; `onFailure` is told every failure, final or
28
13
  * not, to log it.
29
14
  */
@@ -35,7 +20,7 @@ async function unpinMessagesReportingRetryable(messageIds, unpinOne, onFailure)
35
20
  }
36
21
  catch (error) {
37
22
  onFailure(messageId, error);
38
- if (checkShouldTryUnpinAgain(error))
23
+ if ((0, telegramFailureRetry_1.checkIsTelegramFailureRetryable)(error))
39
24
  idsToTryAgain.push(messageId);
40
25
  }
41
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"unpinMessages.js","sourceRoot":"","sources":["../../../src/connectors/telegram/unpinMessages.ts"],"names":[],"mappings":";;AA0BA,0EAeC;AAzCD,mDAA4D;AAC5D,mEAA0E;AAC1E,6DAA+F;AAE/F;;;;;GAKG;AACH,SAAS,wBAAwB,CAAC,KAAc;IAC9C,IAAI,IAAA,qCAAuB,EAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAChD,IAAI,IAAA,qCAAe,EAAC,KAAK,CAAC,IAAI,IAAA,kCAAY,EAAC,KAAK,CAAC,KAAK,SAAS;QAAE,OAAO,IAAA,6CAA6B,EAAC,KAAK,CAAC,CAAC;IAC7G,OAAO,IAAA,mCAAmB,EAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,+BAA+B,CACnD,UAA6B,EAC7B,QAA8C,EAC9C,SAAsD;IAEtD,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YAC5B,IAAI,wBAAwB,CAAC,KAAK,CAAC;gBAAE,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
1
+ {"version":3,"file":"unpinMessages.js","sourceRoot":"","sources":["../../../src/connectors/telegram/unpinMessages.ts"],"names":[],"mappings":";;AAYA,0EAeC;AA3BD,iEAAyE;AAEzE;;;;;;;;;GASG;AACI,KAAK,UAAU,+BAA+B,CACnD,UAA6B,EAC7B,QAA8C,EAC9C,SAAsD;IAEtD,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YAC5B,IAAI,IAAA,sDAA+B,EAAC,KAAK,CAAC;gBAAE,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * @description The Claude skills restore's `SessionStart` hook (matcher `compact`), run by the CLI right after every
3
+ * compaction — one process per slot (`utils/claudeCompactHook.ts` writes `node <this file> <slot> <slot count>
4
+ * <unavailable skills dir or ''> <order dir>` into the launch settings). Each reads the hook input on stdin, works out the
5
+ * WHOLE restore — the skills the transcript shows were loaded since the previous compaction, their current text — and prints
6
+ * its own part as `hookSpecificOutput.additionalContext` (`utils/skillsRestore.ts`). All slots compute the same restore from
7
+ * the same transcript and files, so the parts fit together; a slot past the last part prints nothing.
8
+ *
9
+ * The parts reach the agent strictly by number: the CLI runs the hooks of one event in parallel and takes each one's output
10
+ * when its process ends, so unchained slots land in any order (measured on Claude Code 2.1.323: five parts reached the
11
+ * transcript as [5, 2, 1, 3, 4]). The slots therefore form a chain ({@link waitForPreviousSlot}): slot i prints only once slot
12
+ * i-1 has printed and its process is gone, with a bound so a broken slot never holds the rest back. The part labels stay as
13
+ * the backstop. A launch written before the chain passes no order folder and gets none.
14
+ *
15
+ * Runs inside the agent's process, long after the bot started it, and must never disturb it: it imports only pure modules
16
+ * (no `bot.ts`, no environment), and on ANY doubt — input that is not a compaction's, a sub-agent's (`agent_id`), a missing
17
+ * transcript, no skill — it prints nothing and exits 0.
18
+ *
19
+ * Measured on Claude Code 2.1.322 for this design (plan S0): the hooks of one `SessionStart` all run, in parallel; the
20
+ * transcript does not yet hold the compaction's own boundary and summary while they run (`PostCompact` comes after), so the
21
+ * last epoch read back here is exactly what the compaction summarised.
22
+ */
23
+ /** The hook's command line: its slot (1-based), the slot count of the launch, the folder of skills it cannot load, the chain's folder. */
24
+ export interface SkillsRestoreHookArguments {
25
+ slot: number;
26
+ slotCount: number;
27
+ unavailableSkillsDir: string | null;
28
+ /** Where the slots of a compaction leave their done-markers; `null` (a launch written before the chain): no chain. */
29
+ orderDir: string | null;
30
+ }
31
+ /** What one slot does for a compaction. */
32
+ export interface SkillsRestoreSlotPlan {
33
+ /** The hook JSON it prints, `null` for nothing. */
34
+ output: string | null;
35
+ /**
36
+ * The compaction it belongs to: a hash of the transcript and of the epoch lines the restore is built from — the same for
37
+ * every slot of one compaction, another for every later one (each epoch holds records of its own, a uuid in each). `null`
38
+ * when there is nothing to restore, or no compaction: then there is no chain.
39
+ */
40
+ eventId: string | null;
41
+ /** How many parts the whole restore has (0 for none): the slot with the last one ends the chain. */
42
+ partCount: number;
43
+ }
44
+ /** @description What slot `hookArguments.slot` does for `inputText` (the hook input JSON). */
45
+ export declare function planSkillsRestoreSlot(inputText: string, hookArguments: SkillsRestoreHookArguments): SkillsRestoreSlotPlan;
46
+ /** How the slots of one compaction wait for each other. */
47
+ export interface SlotChainTimings {
48
+ /**
49
+ * How long a slot waits for EACH predecessor that has not finished, counted from the chain's last step: a slot two links
50
+ * behind a broken one waits twice as long, so the broken one's successor gives up first and the order holds after it.
51
+ */
52
+ slotWaitMs: number;
53
+ /** No slot waits longer than this from its own start, whatever happens: well inside the CLI's timeout of a hook. */
54
+ chainCapMs: number;
55
+ /** An extra pause after the previous slot's process is gone, before this slot prints. */
56
+ settleMs: number;
57
+ pollMs: number;
58
+ }
59
+ /**
60
+ * The chain's timings, from the live probe (`live/skillsRestoreLive.test.ts`, Claude Code 2.1.323, a shared machine at a load
61
+ * of about 10, four compactions of five parts each): every restore landed as [1, 2, 3, 4, 5]; the CLI took consecutive parts
62
+ * 16 to 236 ms apart (median 46), once 784 ms where a slot itself started late, and the last part 1.1–1.3 s after the first
63
+ * hook started. So no settle pause: once the previous slot's process is gone the CLI already holds its output, and this
64
+ * slot's own print and exit come later still. Three seconds per missing step leave room for a slot that starts slowly, and
65
+ * twenty in all stay inside the 30-second hook timeout (`skillsRestoreHookTimeoutSeconds`).
66
+ */
67
+ export declare const skillsRestoreSlotChainTimings: SlotChainTimings;
68
+ /** How old a marker must be before the first slot of a later compaction deletes it: far past any chain. */
69
+ export declare const skillsRestoreMarkerMaxAgeMs: number;
70
+ /** What a slot leaves when it is done: its pid, and its parent's — the shell the CLI ran its command in. */
71
+ export interface SlotMarker {
72
+ pid: number;
73
+ parentPid: number;
74
+ }
75
+ /**
76
+ * @description Leave slot `slot`'s done-marker for compaction `eventId` (written whole: a temporary file renamed). A marker
77
+ * that cannot be written costs the next slot its wait bound, nothing else: never an error.
78
+ */
79
+ export declare function writeSlotMarker(orderDir: string, eventId: string, slot: number, marker?: SlotMarker): void;
80
+ /** How a slot's wait ended: it is slot 1, the previous slot is done, or the bound ran out. */
81
+ export type SlotWaitOutcome = 'first' | 'afterPrevious' | 'timedOut';
82
+ /**
83
+ * @description Wait until slot `slot - 1` of compaction `eventId` is done: its marker is there AND its process is gone — the
84
+ * CLI takes a hook's output when the hook's process ends, so only then can this slot's output come after it. The process
85
+ * waited for is the predecessor's shell (the CLI's own child) when the slots run in shells of their own, else the
86
+ * predecessor itself. Gives up after {@link SlotChainTimings.slotWaitMs} per missing predecessor since the chain's last step,
87
+ * and at {@link SlotChainTimings.chainCapMs} in any case. A marker of another compaction is never taken: its event id differs.
88
+ */
89
+ export declare function waitForPreviousSlot(input: {
90
+ orderDir: string;
91
+ eventId: string;
92
+ slot: number;
93
+ timings: SlotChainTimings;
94
+ }): Promise<SlotWaitOutcome>;
95
+ /** @description Delete the markers in `orderDir` last changed before `olderThanMs` (and their temporary files); nothing else. */
96
+ export declare function sweepStaleSlotMarkers(orderDir: string, olderThanMs: number): void;
97
+ /**
98
+ * @description One slot's whole run: work out its part; in a chain, wait for the previous slot, print, leave its own marker and
99
+ * delete the one it waited for (only this slot ever reads it). A slot with no part leaves its marker at once, so nothing waits
100
+ * on it. The slot with the LAST part ends the chain: it leaves no marker and deletes every one of its compaction (the empty
101
+ * slots' too — they started with it and are long done). Slot 1 also sweeps markers older compactions left behind (a slot that
102
+ * ended after the chain did, one cut off by the CLI).
103
+ */
104
+ export declare function runSkillsRestoreSlot(inputText: string, hookArguments: SkillsRestoreHookArguments, writeOutput: (output: string) => Promise<void>, timings?: SlotChainTimings): Promise<void>;
105
+ //# sourceMappingURL=claudeSkillsRestoreHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claudeSkillsRestoreHook.d.ts","sourceRoot":"","sources":["../../src/hooks/claudeSkillsRestoreHook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAmBH,0IAA0I;AAC1I,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,sHAAsH;IACtH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAqBD,2CAA2C;AAC3C,MAAM,WAAW,qBAAqB;IACpC,mDAAmD;IACnD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB;;;;OAIG;IAC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