charness 4.0.0 → 4.1.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 (144) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/DEVELOPMENT.md +2 -1
  3. package/agent-plugin/skills/charness-delegate-claude/SKILL.md +2 -0
  4. package/agent-plugin/skills/charness-orchestration/SKILL.md +5 -0
  5. package/dist/adapters/claudeCliAdapter.d.ts.map +1 -1
  6. package/dist/adapters/claudeCliAdapter.js +3 -2
  7. package/dist/adapters/claudeCliAdapter.js.map +1 -1
  8. package/dist/adapters/claudeJsonStreamAdapter.d.ts +1 -0
  9. package/dist/adapters/claudeJsonStreamAdapter.d.ts.map +1 -1
  10. package/dist/adapters/claudeJsonStreamAdapter.js +19 -4
  11. package/dist/adapters/claudeJsonStreamAdapter.js.map +1 -1
  12. package/dist/adapters/openCodeAdapter.d.ts +1 -0
  13. package/dist/adapters/openCodeAdapter.d.ts.map +1 -1
  14. package/dist/adapters/openCodeAdapter.js +11 -0
  15. package/dist/adapters/openCodeAdapter.js.map +1 -1
  16. package/dist/bot.d.ts.map +1 -1
  17. package/dist/bot.js +268 -268
  18. package/dist/bot.js.map +1 -1
  19. package/dist/connectors/telegram/answerSink.d.ts +12 -0
  20. package/dist/connectors/telegram/answerSink.d.ts.map +1 -1
  21. package/dist/connectors/telegram/answerSink.js +23 -0
  22. package/dist/connectors/telegram/answerSink.js.map +1 -1
  23. package/dist/connectors/telegram/botApiConnection.d.ts +2 -1
  24. package/dist/connectors/telegram/botApiConnection.d.ts.map +1 -1
  25. package/dist/connectors/telegram/botApiConnection.js +19 -1
  26. package/dist/connectors/telegram/botApiConnection.js.map +1 -1
  27. package/dist/connectors/telegram/commands/botCore.d.ts +13 -5
  28. package/dist/connectors/telegram/commands/botCore.d.ts.map +1 -1
  29. package/dist/connectors/telegram/commands/runners.d.ts +1 -1
  30. package/dist/connectors/telegram/commands/runners.d.ts.map +1 -1
  31. package/dist/connectors/telegram/commands/runners.js +9 -5
  32. package/dist/connectors/telegram/commands/runners.js.map +1 -1
  33. package/dist/connectors/telegram/outbound.d.ts +1 -1
  34. package/dist/connectors/telegram/outbound.d.ts.map +1 -1
  35. package/dist/connectors/telegram/outbound.js +3 -1
  36. package/dist/connectors/telegram/outbound.js.map +1 -1
  37. package/dist/connectors/telegram/outputBacklogGlue.d.ts +1 -1
  38. package/dist/connectors/telegram/outputBacklogGlue.js +1 -1
  39. package/dist/connectors/telegram/outputFlushPlan.d.ts +23 -8
  40. package/dist/connectors/telegram/outputFlushPlan.d.ts.map +1 -1
  41. package/dist/connectors/telegram/outputFlushPlan.js +22 -13
  42. package/dist/connectors/telegram/outputFlushPlan.js.map +1 -1
  43. package/dist/connectors/telegram/pinnedNoticeSlot.d.ts +31 -0
  44. package/dist/connectors/telegram/pinnedNoticeSlot.d.ts.map +1 -0
  45. package/dist/connectors/telegram/pinnedNoticeSlot.js +43 -0
  46. package/dist/connectors/telegram/pinnedNoticeSlot.js.map +1 -0
  47. package/dist/connectors/telegram/sendOutcome.d.ts +48 -0
  48. package/dist/connectors/telegram/sendOutcome.d.ts.map +1 -0
  49. package/dist/connectors/telegram/sendOutcome.js +49 -0
  50. package/dist/connectors/telegram/sendOutcome.js.map +1 -0
  51. package/dist/connectors/telegram/telegramFailureRetry.d.ts +9 -0
  52. package/dist/connectors/telegram/telegramFailureRetry.d.ts.map +1 -0
  53. package/dist/connectors/telegram/telegramFailureRetry.js +21 -0
  54. package/dist/connectors/telegram/telegramFailureRetry.js.map +1 -0
  55. package/dist/connectors/telegram/unpinMessages.d.ts +1 -1
  56. package/dist/connectors/telegram/unpinMessages.d.ts.map +1 -1
  57. package/dist/connectors/telegram/unpinMessages.js +3 -18
  58. package/dist/connectors/telegram/unpinMessages.js.map +1 -1
  59. package/dist/hooks/claudeSkillsRestoreHook.d.ts +105 -0
  60. package/dist/hooks/claudeSkillsRestoreHook.d.ts.map +1 -0
  61. package/dist/hooks/claudeSkillsRestoreHook.js +276 -0
  62. package/dist/hooks/claudeSkillsRestoreHook.js.map +1 -0
  63. package/dist/platform/outbound.d.ts +4 -1
  64. package/dist/platform/outbound.d.ts.map +1 -1
  65. package/dist/platform/outbound.js.map +1 -1
  66. package/dist/rateLimiter.d.ts +33 -1
  67. package/dist/rateLimiter.d.ts.map +1 -1
  68. package/dist/rateLimiter.js +91 -5
  69. package/dist/rateLimiter.js.map +1 -1
  70. package/dist/runnerUtility/pueueDaemon.d.ts +7 -13
  71. package/dist/runnerUtility/pueueDaemon.d.ts.map +1 -1
  72. package/dist/runnerUtility/pueueDaemon.js +8 -27
  73. package/dist/runnerUtility/pueueDaemon.js.map +1 -1
  74. package/dist/selfUpdate/selfCheck.d.ts.map +1 -1
  75. package/dist/selfUpdate/selfCheck.js +1 -1
  76. package/dist/selfUpdate/selfCheck.js.map +1 -1
  77. package/dist/testTimings.d.ts +4 -2
  78. package/dist/testTimings.d.ts.map +1 -1
  79. package/dist/testTimings.js +4 -1
  80. package/dist/testTimings.js.map +1 -1
  81. package/dist/types.d.ts +9 -0
  82. package/dist/types.d.ts.map +1 -1
  83. package/dist/utils/agentPlugin.d.ts +7 -0
  84. package/dist/utils/agentPlugin.d.ts.map +1 -1
  85. package/dist/utils/agentPlugin.js +12 -0
  86. package/dist/utils/agentPlugin.js.map +1 -1
  87. package/dist/utils/claudeCompactHook.d.ts +73 -10
  88. package/dist/utils/claudeCompactHook.d.ts.map +1 -1
  89. package/dist/utils/claudeCompactHook.js +96 -17
  90. package/dist/utils/claudeCompactHook.js.map +1 -1
  91. package/dist/utils/claudeProfiles.d.ts +8 -0
  92. package/dist/utils/claudeProfiles.d.ts.map +1 -1
  93. package/dist/utils/claudeProfiles.js +12 -2
  94. package/dist/utils/claudeProfiles.js.map +1 -1
  95. package/dist/utils/claudeTranscriptEpoch.d.ts +15 -0
  96. package/dist/utils/claudeTranscriptEpoch.d.ts.map +1 -0
  97. package/dist/utils/claudeTranscriptEpoch.js +120 -0
  98. package/dist/utils/claudeTranscriptEpoch.js.map +1 -0
  99. package/dist/utils/clearStatusCoalescer.d.ts +24 -0
  100. package/dist/utils/clearStatusCoalescer.d.ts.map +1 -0
  101. package/dist/utils/clearStatusCoalescer.js +25 -0
  102. package/dist/utils/clearStatusCoalescer.js.map +1 -0
  103. package/dist/utils/compactOnIdle.d.ts +91 -34
  104. package/dist/utils/compactOnIdle.d.ts.map +1 -1
  105. package/dist/utils/compactOnIdle.js +149 -31
  106. package/dist/utils/compactOnIdle.js.map +1 -1
  107. package/dist/utils/groupOutputBacklog.d.ts +90 -0
  108. package/dist/utils/groupOutputBacklog.d.ts.map +1 -0
  109. package/dist/utils/groupOutputBacklog.js +134 -0
  110. package/dist/utils/groupOutputBacklog.js.map +1 -0
  111. package/dist/utils/messageSendService.d.ts +26 -3
  112. package/dist/utils/messageSendService.d.ts.map +1 -1
  113. package/dist/utils/messageSendService.js +35 -3
  114. package/dist/utils/messageSendService.js.map +1 -1
  115. package/dist/utils/openCodeCompactPlugin.d.ts +33 -0
  116. package/dist/utils/openCodeCompactPlugin.d.ts.map +1 -1
  117. package/dist/utils/openCodeCompactPlugin.js +192 -1
  118. package/dist/utils/openCodeCompactPlugin.js.map +1 -1
  119. package/dist/utils/skillsRestore.d.ts +235 -0
  120. package/dist/utils/skillsRestore.d.ts.map +1 -0
  121. package/dist/utils/skillsRestore.js +515 -0
  122. package/dist/utils/skillsRestore.js.map +1 -0
  123. package/dist/utils/statusFlushDecision.js +1 -1
  124. package/dist/utils/streamedCompactionSummary.d.ts +4 -4
  125. package/dist/utils/streamedCompactionSummary.js +5 -5
  126. package/dist/utils/streamedCompactionSummary.js.map +1 -1
  127. package/dist/utils/streamedOutputLanding.d.ts +14 -0
  128. package/dist/utils/streamedOutputLanding.d.ts.map +1 -0
  129. package/dist/utils/streamedOutputLanding.js +45 -0
  130. package/dist/utils/streamedOutputLanding.js.map +1 -0
  131. package/dist/utils/typingLoopBackstop.d.ts +8 -7
  132. package/dist/utils/typingLoopBackstop.d.ts.map +1 -1
  133. package/dist/utils/typingLoopBackstop.js +6 -5
  134. package/dist/utils/typingLoopBackstop.js.map +1 -1
  135. package/npm-shrinkwrap.json +2 -2
  136. package/package.json +1 -1
  137. package/dist/utils/clearThreadOutputQueues.d.ts +0 -44
  138. package/dist/utils/clearThreadOutputQueues.d.ts.map +0 -1
  139. package/dist/utils/clearThreadOutputQueues.js +0 -39
  140. package/dist/utils/clearThreadOutputQueues.js.map +0 -1
  141. package/dist/utils/groupFinalizePlan.d.ts +0 -36
  142. package/dist/utils/groupFinalizePlan.d.ts.map +0 -1
  143. package/dist/utils/groupFinalizePlan.js +0 -31
  144. package/dist/utils/groupFinalizePlan.js.map +0 -1
@@ -0,0 +1,90 @@
1
+ /**
2
+ * @description A Telegram topic's group-mode output: ONE ordered backlog of the agent's unsent text, one loop that sends it
3
+ * from the head, and the waits of the posts that must come after it. `bot.ts` owns the queue state and injects the send; this
4
+ * module owns the order. What it keeps, whatever overlaps (two landings, a 429, a stop, a send that hangs):
5
+ *
6
+ * 1. Every piece of text is queued once, in the order the agent produced it, and leaves the backlog only to be sent, from the
7
+ * head, one send at a time ({@link drainGroupOutput}).
8
+ * 2. A piece is sent at most once. A 429 (or a failure of the network) that kept part of it from landing puts that part back
9
+ * at the HEAD (it is older than everything still queued) for the retry; a refusal for good (a closed topic, another 4xx)
10
+ * drops it, logged — a retry would fail the same way and hold all newer text behind it for ever; a send whose outcome is
11
+ * unknown (the Bot API did not answer within its deadline, `rateLimiter.ts`) counts as sent and is never sent again — the
12
+ * send reports it as landed.
13
+ * 3. A post that must come after the text — an answer, the messages of `send_messages_to_user`, a question, a tool status
14
+ * frame — waits until every piece queued before it has settled: landed, dropped by a stop, or of unknown outcome
15
+ * ({@link landGroupOutput}). It does not capture text: it marks a number and waits for it, so two landings, a 429 leftover
16
+ * and a stop never hold separate slices that could be sent out of order.
17
+ * 4. A stop gives every piece queued so far ONE final attempt: a 429 then drops the rest of that piece, logged
18
+ * ({@link startFinalGroupOutputAttempt}). Nothing is dropped up front.
19
+ * 5. Nothing waits for ever: every send is bounded by its Bot API deadline, and the callers bound their waits
20
+ * (`streamedOutputLanding.ts`).
21
+ */
22
+ import { type PendingOutputBuffer, type PendingOutputSegment } from '../connectors/telegram/outputFlushPlan';
23
+ /**
24
+ * @name GroupOutputBacklog
25
+ * @description The part of `bot.ts`'s `OutputQueueState` the sending of a topic's output touches.
26
+ */
27
+ export interface GroupOutputBacklog extends PendingOutputBuffer {
28
+ /** The armed debounce timer that would send the still-growing newest segment later. `null` = none. */
29
+ debounceTimer: NodeJS.Timeout | null;
30
+ /** The send loop is running: it picks up whatever a landing or a flush asks for while it sends. */
31
+ isDraining: boolean;
32
+ /** Every segment numbered up to here has settled: landed, dropped by a stop, or of unknown outcome. */
33
+ settledSeq: number;
34
+ /** Segments numbered up to here get one final attempt (a stop): a 429 drops them instead of putting them back. */
35
+ finalAttemptThroughSeq: number;
36
+ /** The posts waiting for a number to settle, in no particular order. */
37
+ settleWaiters: GroupOutputSettleWaiter[];
38
+ }
39
+ /** A post waiting until every segment numbered up to `seq` has settled. */
40
+ interface GroupOutputSettleWaiter {
41
+ seq: number;
42
+ resolve: () => void;
43
+ }
44
+ /**
45
+ * @description What one send of a segment left: nothing (all of it landed, or its outcome is unknown), or the text it could not
46
+ * land and whether trying it again may help — a 429 or a network failure, as opposed to a refusal for good.
47
+ */
48
+ export type GroupOutputSendResult = {
49
+ unsentRemainder: null;
50
+ } | {
51
+ unsentRemainder: string;
52
+ isRetryable: boolean;
53
+ };
54
+ /** Why the send loop dropped text: a stop's final attempt failed, or Telegram refused it for good. */
55
+ export type GroupOutputDropReason = 'finalAttempt' | 'refused';
56
+ /** @description What the send loop needs from the bot: the send itself and what to do when it cannot go on. */
57
+ export interface GroupOutputDrainDeps {
58
+ sendSegment: (segment: PendingOutputSegment) => Promise<GroupOutputSendResult>;
59
+ /** A retryable failure put text back at the head and the loop stopped: arm the retry. */
60
+ onStalled: () => void;
61
+ /** `unsentRemainder` of `segment` is dropped, for `reason`. */
62
+ onDropped: (segment: PendingOutputSegment, unsentRemainder: string, reason: GroupOutputDropReason) => void;
63
+ /** A send threw instead of resolving: the segment counts as sent (never sent again) and the loop goes on. */
64
+ onSendError: (error: Error) => void;
65
+ }
66
+ /** @description An empty backlog: nothing queued, nothing sending, nothing waiting. Segments are numbered from 1. */
67
+ export declare function createGroupOutputBacklog(): GroupOutputBacklog;
68
+ /**
69
+ * @description Send the backlog from the head through segment `throughSeq` (sealing everything up to it, so no later text joins
70
+ * it). One loop per backlog: a call while it runs only moves its target on, and the loop sends what was asked for in order.
71
+ * The loop stops at the target, when the backlog is empty, or when a 429 put text back at the head (`onStalled`).
72
+ */
73
+ export declare function drainGroupOutput(backlog: GroupOutputBacklog, throughSeq: number, deps: GroupOutputDrainDeps): void;
74
+ /**
75
+ * @description Land everything queued so far before the caller posts what must come after it: seal the newest segment, send the
76
+ * backlog through it now (the debounce no longer waits for it) and resolve once every segment up to it has settled — also
77
+ * one already being sent. Nothing is captured: a 429 leftover goes back to the head, a stop settles what it drops, and a
78
+ * landing that started later waits for a later number, so the order of the text never depends on which landing sends it.
79
+ */
80
+ export declare function landGroupOutput(backlog: GroupOutputBacklog, deps: GroupOutputDrainDeps): Promise<void>;
81
+ /**
82
+ * @description A stop: give every segment queued so far one final attempt, in order, after the send under way. A 429 on that
83
+ * attempt drops what is left of the segment (`onDropped`) instead of putting it back, so nothing is retried after the stop.
84
+ * Resolves once they have all settled. Text queued after the call is the next session's and is sent as usual.
85
+ */
86
+ export declare function startFinalGroupOutputAttempt(backlog: GroupOutputBacklog, deps: GroupOutputDrainDeps): Promise<void>;
87
+ /** @description Resolve once every segment numbered up to `seq` has settled (at once when they all have). */
88
+ export declare function waitForGroupOutputSettled(backlog: GroupOutputBacklog, seq: number): Promise<void>;
89
+ export {};
90
+ //# sourceMappingURL=groupOutputBacklog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groupOutputBacklog.d.ts","sourceRoot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H,wBAAgB,wBAAwB,IAAI,kBAAkB,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAKlH;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAKtG;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAInH;AAED,6GAA6G;AAC7G,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKjG"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ /**
3
+ * @description A Telegram topic's group-mode output: ONE ordered backlog of the agent's unsent text, one loop that sends it
4
+ * from the head, and the waits of the posts that must come after it. `bot.ts` owns the queue state and injects the send; this
5
+ * module owns the order. What it keeps, whatever overlaps (two landings, a 429, a stop, a send that hangs):
6
+ *
7
+ * 1. Every piece of text is queued once, in the order the agent produced it, and leaves the backlog only to be sent, from the
8
+ * head, one send at a time ({@link drainGroupOutput}).
9
+ * 2. A piece is sent at most once. A 429 (or a failure of the network) that kept part of it from landing puts that part back
10
+ * at the HEAD (it is older than everything still queued) for the retry; a refusal for good (a closed topic, another 4xx)
11
+ * drops it, logged — a retry would fail the same way and hold all newer text behind it for ever; a send whose outcome is
12
+ * unknown (the Bot API did not answer within its deadline, `rateLimiter.ts`) counts as sent and is never sent again — the
13
+ * send reports it as landed.
14
+ * 3. A post that must come after the text — an answer, the messages of `send_messages_to_user`, a question, a tool status
15
+ * frame — waits until every piece queued before it has settled: landed, dropped by a stop, or of unknown outcome
16
+ * ({@link landGroupOutput}). It does not capture text: it marks a number and waits for it, so two landings, a 429 leftover
17
+ * and a stop never hold separate slices that could be sent out of order.
18
+ * 4. A stop gives every piece queued so far ONE final attempt: a 429 then drops the rest of that piece, logged
19
+ * ({@link startFinalGroupOutputAttempt}). Nothing is dropped up front.
20
+ * 5. Nothing waits for ever: every send is bounded by its Bot API deadline, and the callers bound their waits
21
+ * (`streamedOutputLanding.ts`).
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.createGroupOutputBacklog = createGroupOutputBacklog;
25
+ exports.drainGroupOutput = drainGroupOutput;
26
+ exports.landGroupOutput = landGroupOutput;
27
+ exports.startFinalGroupOutputAttempt = startFinalGroupOutputAttempt;
28
+ exports.waitForGroupOutputSettled = waitForGroupOutputSettled;
29
+ const outputFlushPlan_1 = require("../connectors/telegram/outputFlushPlan");
30
+ /** @description An empty backlog: nothing queued, nothing sending, nothing waiting. Segments are numbered from 1. */
31
+ function createGroupOutputBacklog() {
32
+ return { pendingSegments: [], firstSeq: 1, sealedThroughSeq: 0, debounceTimer: null, isDraining: false, settledSeq: 0, finalAttemptThroughSeq: 0, settleWaiters: [] };
33
+ }
34
+ /**
35
+ * @description Send the backlog from the head through segment `throughSeq` (sealing everything up to it, so no later text joins
36
+ * it). One loop per backlog: a call while it runs only moves its target on, and the loop sends what was asked for in order.
37
+ * The loop stops at the target, when the backlog is empty, or when a 429 put text back at the head (`onStalled`).
38
+ */
39
+ function drainGroupOutput(backlog, throughSeq, deps) {
40
+ backlog.sealedThroughSeq = Math.max(backlog.sealedThroughSeq, throughSeq);
41
+ if (backlog.isDraining)
42
+ return;
43
+ backlog.isDraining = true;
44
+ void runDrainLoop(backlog, deps);
45
+ }
46
+ /**
47
+ * @description Land everything queued so far before the caller posts what must come after it: seal the newest segment, send the
48
+ * backlog through it now (the debounce no longer waits for it) and resolve once every segment up to it has settled — also
49
+ * one already being sent. Nothing is captured: a 429 leftover goes back to the head, a stop settles what it drops, and a
50
+ * landing that started later waits for a later number, so the order of the text never depends on which landing sends it.
51
+ */
52
+ function landGroupOutput(backlog, deps) {
53
+ const throughSeq = (0, outputFlushPlan_1.getNewestPendingSeq)(backlog);
54
+ clearDebounceTimer(backlog);
55
+ drainGroupOutput(backlog, throughSeq, deps);
56
+ return waitForGroupOutputSettled(backlog, throughSeq);
57
+ }
58
+ /**
59
+ * @description A stop: give every segment queued so far one final attempt, in order, after the send under way. A 429 on that
60
+ * attempt drops what is left of the segment (`onDropped`) instead of putting it back, so nothing is retried after the stop.
61
+ * Resolves once they have all settled. Text queued after the call is the next session's and is sent as usual.
62
+ */
63
+ function startFinalGroupOutputAttempt(backlog, deps) {
64
+ const throughSeq = (0, outputFlushPlan_1.getNewestPendingSeq)(backlog);
65
+ backlog.finalAttemptThroughSeq = Math.max(backlog.finalAttemptThroughSeq, throughSeq);
66
+ return landGroupOutput(backlog, deps);
67
+ }
68
+ /** @description Resolve once every segment numbered up to `seq` has settled (at once when they all have). */
69
+ function waitForGroupOutputSettled(backlog, seq) {
70
+ if (backlog.settledSeq >= seq)
71
+ return Promise.resolve();
72
+ return new Promise((resolve) => {
73
+ backlog.settleWaiters.push({ seq, resolve });
74
+ });
75
+ }
76
+ function clearDebounceTimer(backlog) {
77
+ if (!backlog.debounceTimer)
78
+ return;
79
+ clearTimeout(backlog.debounceTimer);
80
+ backlog.debounceTimer = null;
81
+ }
82
+ /**
83
+ * The send loop. `isDraining` is cleared in the SAME synchronous step as the check that found nothing more to send, so a call
84
+ * of {@link drainGroupOutput} can never land between the two and be left unserved.
85
+ */
86
+ async function runDrainLoop(backlog, deps) {
87
+ try {
88
+ while (backlog.pendingSegments.length > 0 && backlog.firstSeq <= backlog.sealedThroughSeq) {
89
+ const taken = (0, outputFlushPlan_1.takePendingOutput)(backlog);
90
+ if (!taken)
91
+ return;
92
+ const result = await sendSegmentOnce(taken.segment, deps);
93
+ if (result.unsentRemainder !== null) {
94
+ if (!result.isRetryable) {
95
+ deps.onDropped(taken.segment, result.unsentRemainder, 'refused');
96
+ }
97
+ else if (taken.seq > backlog.finalAttemptThroughSeq) {
98
+ (0, outputFlushPlan_1.requeueUnsentRemainder)(backlog, result.unsentRemainder);
99
+ deps.onStalled();
100
+ return;
101
+ }
102
+ else {
103
+ deps.onDropped(taken.segment, result.unsentRemainder, 'finalAttempt');
104
+ }
105
+ }
106
+ settleGroupOutputThrough(backlog, taken.seq);
107
+ }
108
+ }
109
+ finally {
110
+ backlog.isDraining = false;
111
+ }
112
+ }
113
+ /** A blank segment would only earn a Telegram error and is no text: it settles without a send. */
114
+ async function sendSegmentOnce(segment, deps) {
115
+ if (segment.output.trim() === '')
116
+ return { unsentRemainder: null };
117
+ try {
118
+ return await deps.sendSegment(segment);
119
+ }
120
+ catch (error) {
121
+ deps.onSendError(error instanceof Error ? error : new Error(String(error)));
122
+ return { unsentRemainder: null };
123
+ }
124
+ }
125
+ function settleGroupOutputThrough(backlog, seq) {
126
+ backlog.settledSeq = Math.max(backlog.settledSeq, seq);
127
+ const settled = backlog.settleWaiters.filter((waiter) => waiter.seq <= backlog.settledSeq);
128
+ if (settled.length === 0)
129
+ return;
130
+ backlog.settleWaiters = backlog.settleWaiters.filter((waiter) => waiter.seq > backlog.settledSeq);
131
+ for (const waiter of settled)
132
+ waiter.resolve();
133
+ }
134
+ //# sourceMappingURL=groupOutputBacklog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groupOutputBacklog.js","sourceRoot":"","sources":["../../src/utils/groupOutputBacklog.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAgDH,4DAEC;AAOD,4CAKC;AAQD,0CAKC;AAOD,oEAIC;AAGD,8DAKC;AA5FD,4EAA6K;AA6C7K,qHAAqH;AACrH,SAAgB,wBAAwB;IACtC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC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9 @@ export type DiscreteMessageItem = string | {
39
39
  * attempted but did not land (a partial delivery stays `ok`), so a caller can
40
40
  * tell a partial delivery from a full one without parsing `summary`.
41
41
  * `sentMessageIds` are the TEXT messages that landed, in order — what a caller
42
- * pins or edits afterwards (an answer's pin, S8); attachments are not listed.
42
+ * pins or edits afterwards (an answer's pin, S8); attachments are not listed. A
43
+ * batch that ended on a delivery of unknown outcome (`deliveryUnknown`) lists the
44
+ * ones that landed before it.
43
45
  */
44
46
  export type SendMessagesToThreadResult = {
45
47
  ok: true;
@@ -53,6 +55,7 @@ export type SendMessagesToThreadResult = {
53
55
  ok: false;
54
56
  kind: 'deliveryUnknown';
55
57
  error: string;
58
+ sentMessageIds: number[];
56
59
  };
57
60
  export type SendMessagesToThread = (threadKey: string, args: SendMessagesToThreadOptions) => Promise<SendMessagesToThreadResult>;
58
61
  export interface SendMessagesToThreadOptions {
@@ -78,6 +81,13 @@ export interface SendMessagesToThreadOptions {
78
81
  * topic with notifications).
79
82
  */
80
83
  export declare const maxDiscreteMessages = 50;
84
+ /**
85
+ * @description A text message whose delivery outcome is unknown: the platform did not answer within its deadline, so it may or
86
+ * may not be in the topic. `sendChunk` throws it; the batch ends as `deliveryUnknown`, and the message is never sent again.
87
+ */
88
+ export declare class MessageDeliveryUnknownError extends Error {
89
+ constructor();
90
+ }
81
91
  export interface SendMessagesToThreadDeps<TTarget> {
82
92
  /** Map the scope-resolved thread key string to the concrete send target. */
83
93
  resolveTarget(threadKey: string): {
@@ -91,7 +101,8 @@ export interface SendMessagesToThreadDeps<TTarget> {
91
101
  * Send ONE already-split chunk as its own permanent message; resolves the sent
92
102
  * message id, `null` when it did not land. The caller wires this to the bot's
93
103
  * paced HTML-with-plain-fallback send so ordering / rate-limiting / `/clear`
94
- * tracking are reused.
104
+ * tracking are reused. Throws {@link MessageDeliveryUnknownError} when the
105
+ * outcome is unknown (it must not be sent again).
95
106
  */
96
107
  sendChunk(target: TTarget, chunk: string, signal?: AbortSignal): Promise<number | null>;
97
108
  /**
@@ -111,6 +122,14 @@ export interface SendMessagesToThreadDeps<TTarget> {
111
122
  maxMessageLength: number;
112
123
  /** Rendered-length measure so an over-cap RENDERED message is split like normal output. */
113
124
  measureRendered(chunk: string): number;
125
+ /**
126
+ * Land what the agent streamed before this call into the topic — the text its backend still batches and the output the topic
127
+ * still debounces or is sending — so the messages of this call are posted BELOW it. The agent writes its text, then calls the
128
+ * tool: without this the text, held back for a moment, would appear under the messages it led up to. A landing that fails is
129
+ * logged and never holds the messages back, and one that does not end within `streamedOutputLandingLimitMs` is given up on:
130
+ * a send that hangs must not hold the agent's tool call.
131
+ */
132
+ landStreamedOutput(target: TTarget): Promise<void>;
114
133
  }
115
134
  /**
116
135
  * @description Build the discrete-message sender. Each item is delivered as its
@@ -123,6 +142,9 @@ export interface SendMessagesToThreadDeps<TTarget> {
123
142
  * and letting that escape hid how many messages had already landed (the agent's
124
143
  * natural retry then posted them twice).
125
144
  *
145
+ * The agent's streamed text lands first ({@link SendMessagesToThreadDeps.landStreamedOutput}): the messages are the last thing the
146
+ * agent has written when they are posted, so they are posted last — the answer of `answer_request` rides this sender too.
147
+ *
126
148
  * Items are validated up front (an all-empty object → error, nothing sent) so
127
149
  * the service mirrors the MCP schema's all-or-nothing rejection. Failure is NOT
128
150
  * swallowed: if every send failed the result is an ERROR (with any attachment
@@ -132,7 +154,8 @@ export interface SendMessagesToThreadDeps<TTarget> {
132
154
  * attachment kinds taken from what the file pipeline reports it SENT, never from
133
155
  * the extension. An attachment whose delivery outcome is unknown terminates the
134
156
  * batch with a `deliveryUnknown` result so the agent does not blindly retry
135
- * (mirrors `send_file_to_user`).
157
+ * (mirrors `send_file_to_user`); so does a text message whose outcome is unknown
158
+ * ({@link MessageDeliveryUnknownError}).
136
159
  */
137
160
  export declare function createSendMessagesToThread<TTarget>(deps: SendMessagesToThreadDeps<TTarget>): SendMessagesToThread;
138
161
  //# sourceMappingURL=messageSendService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"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KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,EAAE,CAAC;IACpG,+GAA+G;IAC/G,gBAAgB,EAAE,MAAM,CAAC;IACzB,2FAA2F;IAC3F,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvC;;;;;;OAMG;IACH,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpD;AA8DD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAChD,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,GACtC,oBAAoB,CA0GtB"}
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.maxDiscreteMessages = void 0;
3
+ exports.MessageDeliveryUnknownError = exports.maxDiscreteMessages = void 0;
4
4
  exports.createSendMessagesToThread = createSendMessagesToThread;
5
5
  const utils_1 = require("../utils");
6
+ const streamedOutputLanding_1 = require("./streamedOutputLanding");
6
7
  const sentKindsSummary_1 = require("./sentKindsSummary");
7
8
  /**
8
9
  * Upper bound on how many discrete messages one call may deliver. A per-item
@@ -11,6 +12,17 @@ const sentKindsSummary_1 = require("./sentKindsSummary");
11
12
  * topic with notifications).
12
13
  */
13
14
  exports.maxDiscreteMessages = 50;
15
+ /**
16
+ * @description A text message whose delivery outcome is unknown: the platform did not answer within its deadline, so it may or
17
+ * may not be in the topic. `sendChunk` throws it; the batch ends as `deliveryUnknown`, and the message is never sent again.
18
+ */
19
+ class MessageDeliveryUnknownError extends Error {
20
+ constructor() {
21
+ super('the platform did not confirm the message in time; it may or may not be in the topic');
22
+ this.name = 'MessageDeliveryUnknownError';
23
+ }
24
+ }
25
+ exports.MessageDeliveryUnknownError = MessageDeliveryUnknownError;
14
26
  /** Trim a value and report whether anything non-blank remains. */
15
27
  function getNonBlank(value) {
16
28
  if (value === undefined)
@@ -66,6 +78,9 @@ function buildCancelledResult(landed) {
66
78
  * and letting that escape hid how many messages had already landed (the agent's
67
79
  * natural retry then posted them twice).
68
80
  *
81
+ * The agent's streamed text lands first ({@link SendMessagesToThreadDeps.landStreamedOutput}): the messages are the last thing the
82
+ * agent has written when they are posted, so they are posted last — the answer of `answer_request` rides this sender too.
83
+ *
69
84
  * Items are validated up front (an all-empty object → error, nothing sent) so
70
85
  * the service mirrors the MCP schema's all-or-nothing rejection. Failure is NOT
71
86
  * swallowed: if every send failed the result is an ERROR (with any attachment
@@ -75,7 +90,8 @@ function buildCancelledResult(landed) {
75
90
  * attachment kinds taken from what the file pipeline reports it SENT, never from
76
91
  * the extension. An attachment whose delivery outcome is unknown terminates the
77
92
  * batch with a `deliveryUnknown` result so the agent does not blindly retry
78
- * (mirrors `send_file_to_user`).
93
+ * (mirrors `send_file_to_user`); so does a text message whose outcome is unknown
94
+ * ({@link MessageDeliveryUnknownError}).
79
95
  */
80
96
  function createSendMessagesToThread(deps) {
81
97
  return async (threadKey, { messages, authorizedWorkDir, signal }) => {
@@ -90,6 +106,7 @@ function createSendMessagesToThread(deps) {
90
106
  if (!resolved.ok)
91
107
  return { ok: false, error: resolved.error };
92
108
  const { target } = resolved;
109
+ await (0, streamedOutputLanding_1.landStreamedOutputWithinLimit)(() => deps.landStreamedOutput(target), threadKey);
93
110
  let attempted = 0;
94
111
  let landed = 0;
95
112
  const deliveredKinds = [];
@@ -135,6 +152,7 @@ function createSendMessagesToThread(deps) {
135
152
  kind: 'deliveryUnknown',
136
153
  error: `Delivered ${formatMessageCount(landed)} before an attachment's delivery ` +
137
154
  `outcome became unknown: ${fileResult.error}`,
155
+ sentMessageIds,
138
156
  };
139
157
  }
140
158
  else {
@@ -145,7 +163,21 @@ function createSendMessagesToThread(deps) {
145
163
  const chunks = deps.splitMessage(item.text, deps.maxMessageLength, deps.measureRendered);
146
164
  for (const chunk of chunks) {
147
165
  attempted += 1;
148
- const messageId = await deps.sendChunk(target, chunk, signal);
166
+ let messageId;
167
+ try {
168
+ messageId = await deps.sendChunk(target, chunk, signal);
169
+ }
170
+ catch (error) {
171
+ if (!(error instanceof MessageDeliveryUnknownError))
172
+ throw error;
173
+ // Like an attachment of unknown fate: the batch ends here, and the caller is told not to send it again.
174
+ return {
175
+ ok: false,
176
+ kind: 'deliveryUnknown',
177
+ error: `Delivered ${formatMessageCount(landed)} before a message's delivery outcome became unknown: ${error.message}`,
178
+ sentMessageIds,
179
+ };
180
+ }
149
181
  if (messageId === null)
150
182
  continue;
151
183
  landed += 1;
@@ -1 +1 @@
1
- {"version":3,"file":"messageSendService.js","sourceRoot":"","sources":["../../src/utils/messageSendService.ts"],"names":[],"mappings":";;;AAgMA,gEA8FC;AA9RD,oCAA6C;AAE7C,yDAAoE;AAuEpE;;;;;GAKG;AACU,QAAA,mBAAmB,GAAG,EAAE,CAAC;AA6CtC,kEAAkE;AAClE,SAAS,WAAW,CAAC,KAAyB;IAC5C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACrD,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,4BAA4B,CAAC,IAAyB;IAC7D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACpF,CAAC;IACD,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO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AC;IACrF,CAAC,CAAC;AACJ,CAAC"}
@@ -41,6 +41,22 @@
41
41
  * therefore leaves the resume guidance out of its instruction when the folder's
42
42
  * instance has the CURRENT plugin ({@link checkHasOpenCodeCompactPlugin} over
43
43
  * `GET /config`), and keeps it otherwise.
44
+ *
45
+ * The same plugin gives a session its skills back after every compaction (plan `2026-11-12-skills-reload-after-compaction`,
46
+ * S4): nothing reloads a skill there by itself, so the summary used to drop its text entirely. Its
47
+ * `experimental.chat.messages.transform` hook runs before every model request of the session's loop (measured on the fork
48
+ * build: the overflow compaction's synthetic "Continue…" request, the first request after a manual compaction and after a
49
+ * server restart all carried the part it added) and over the in-memory list only — nothing it adds is stored, sent over SSE
50
+ * or shown. Once the list holds a finished summary it adds ONE synthetic text part, the restore ({@link
51
+ * buildOpenCodeCompactPluginSource}), to the compaction's own user message — right before the summary, a fixed place, so
52
+ * every later request starts the same and the prompt cache holds. Within one turn the fork converts a message once and
53
+ * reuses that while the message IDS stay an unchanged prefix (`appendOnlyModelMessages`, verified in the fork's
54
+ * `session/prompt.ts`: the snapshot starts over only on a compaction, a sub-task and an overflow): a restore rebuilt in the
55
+ * same turn — the lookups of the first one did not answer in time — would never reach the provider. So the message the part
56
+ * rides on carries an id tagged with the restore's revision (in memory only; the provider never sees message ids): a new
57
+ * text, a new id, a fresh conversion; the same text, the same id, the same prefix. The compaction's own request runs the hook too, but
58
+ * the fork hides the earlier summaries from it (measured on the first and on a second compaction), so it holds none and is
59
+ * left as it is.
44
60
  */
45
61
  /** OpenCode requires a path plugin to export an id. */
46
62
  export declare const openCodeCompactPluginId = "charness-compaction";
@@ -65,6 +81,11 @@ export declare function getOpenCodeCompactPluginContext(isWithInstructionGaps: b
65
81
  * time means ON, like one that fails: the section is asked for, as before the switch.
66
82
  */
67
83
  export declare const openCodeAncestryLookupTimeoutMs = 2000;
84
+ /**
85
+ * How long the restore waits for the session's stored history: longer than the other lookups, since a long session's whole
86
+ * history is a big answer and the read runs once per compaction (a whole restore is kept for the summary's later requests).
87
+ */
88
+ export declare const openCodeHistoryLookupTimeoutMs = 10000;
68
89
  /**
69
90
  * @description The plugin module source: a v1 plugin (`default` export with `id` + `server`). Before a compaction it looks for
70
91
  * the flag the bot keeps for the session (`utils/compactSelfReviewFlags.ts`): present ⇒ `/compact_self_review` is off for the
@@ -76,6 +97,18 @@ export declare const openCodeAncestryLookupTimeoutMs = 2000;
76
97
  * {@link maxSessionAncestryDepth} levels: a topic's sub-agents follow the topic. A folder with no flag in it at all costs no
77
98
  * request. A session id that is not a plain id, a lookup that fails or is not answered within
78
99
  * {@link openCodeAncestryLookupTimeoutMs}, or any read failure means ON: the section is asked for, as before the switch.
100
+ *
101
+ * Before every model request (`experimental.chat.messages.transform`) it gives the skills back once the list holds a finished
102
+ * summary: the skills of the session's stored history (`client.session.messages`, every compaction so far) and of the
103
+ * summary's block, the server's current text of each (`GET /skill`; the plugin's client is the v1 SDK, which has no method for
104
+ * it, so the request goes through its inner client, which carries the folder and the password — measured on the fork build),
105
+ * a skill whose call is already after the summary only named, a name only the block holds (with the history known) given a
106
+ * "load it" line. A restore whose lookups both answered is kept for the summary, so every later request gets the same text;
107
+ * one that is not whole (a lookup failed or timed out) serves its request only, is logged to the server log once per summary,
108
+ * and the next request asks again. The history waits up to {@link openCodeHistoryLookupTimeoutMs}, the skill list up to
109
+ * {@link openCodeAncestryLookupTimeoutMs}: a history that does not come is replaced by the calls the list itself holds, a
110
+ * skill list that does not come leaves "load it with the skill tool" lines. Should the SDK's inner client be gone, the skill
111
+ * list is fetched from the server directly (logged once). Nothing ever throws out of it or holds the request longer.
79
112
  */
80
113
  export declare function buildOpenCodeCompactPluginSource(input: {
81
114
  context: string;
@@ -1 +1 @@
1
- {"version":3,"file":"openCodeCompactPlugin.d.ts","sourceRoot":"","sources":["../../src/utils/openCodeCompactPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAUH,uDAAuD;AAC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