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.
- package/CHANGELOG.md +18 -0
- package/DEVELOPMENT.md +2 -1
- package/agent-plugin/skills/charness-delegate-claude/SKILL.md +2 -0
- package/agent-plugin/skills/charness-orchestration/SKILL.md +5 -0
- package/dist/adapters/claudeCliAdapter.d.ts.map +1 -1
- package/dist/adapters/claudeCliAdapter.js +3 -2
- package/dist/adapters/claudeCliAdapter.js.map +1 -1
- package/dist/adapters/claudeJsonStreamAdapter.d.ts +1 -0
- package/dist/adapters/claudeJsonStreamAdapter.d.ts.map +1 -1
- package/dist/adapters/claudeJsonStreamAdapter.js +19 -4
- package/dist/adapters/claudeJsonStreamAdapter.js.map +1 -1
- package/dist/adapters/openCodeAdapter.d.ts +1 -0
- package/dist/adapters/openCodeAdapter.d.ts.map +1 -1
- package/dist/adapters/openCodeAdapter.js +11 -0
- package/dist/adapters/openCodeAdapter.js.map +1 -1
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +268 -268
- package/dist/bot.js.map +1 -1
- package/dist/connectors/telegram/answerSink.d.ts +12 -0
- package/dist/connectors/telegram/answerSink.d.ts.map +1 -1
- package/dist/connectors/telegram/answerSink.js +23 -0
- package/dist/connectors/telegram/answerSink.js.map +1 -1
- package/dist/connectors/telegram/botApiConnection.d.ts +2 -1
- package/dist/connectors/telegram/botApiConnection.d.ts.map +1 -1
- package/dist/connectors/telegram/botApiConnection.js +19 -1
- package/dist/connectors/telegram/botApiConnection.js.map +1 -1
- package/dist/connectors/telegram/commands/botCore.d.ts +13 -5
- package/dist/connectors/telegram/commands/botCore.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/runners.d.ts +1 -1
- package/dist/connectors/telegram/commands/runners.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/runners.js +9 -5
- package/dist/connectors/telegram/commands/runners.js.map +1 -1
- package/dist/connectors/telegram/outbound.d.ts +1 -1
- package/dist/connectors/telegram/outbound.d.ts.map +1 -1
- package/dist/connectors/telegram/outbound.js +3 -1
- package/dist/connectors/telegram/outbound.js.map +1 -1
- package/dist/connectors/telegram/outputBacklogGlue.d.ts +1 -1
- package/dist/connectors/telegram/outputBacklogGlue.js +1 -1
- package/dist/connectors/telegram/outputFlushPlan.d.ts +23 -8
- package/dist/connectors/telegram/outputFlushPlan.d.ts.map +1 -1
- package/dist/connectors/telegram/outputFlushPlan.js +22 -13
- package/dist/connectors/telegram/outputFlushPlan.js.map +1 -1
- package/dist/connectors/telegram/pinnedNoticeSlot.d.ts +31 -0
- package/dist/connectors/telegram/pinnedNoticeSlot.d.ts.map +1 -0
- package/dist/connectors/telegram/pinnedNoticeSlot.js +43 -0
- package/dist/connectors/telegram/pinnedNoticeSlot.js.map +1 -0
- package/dist/connectors/telegram/sendOutcome.d.ts +48 -0
- package/dist/connectors/telegram/sendOutcome.d.ts.map +1 -0
- package/dist/connectors/telegram/sendOutcome.js +49 -0
- package/dist/connectors/telegram/sendOutcome.js.map +1 -0
- package/dist/connectors/telegram/telegramFailureRetry.d.ts +9 -0
- package/dist/connectors/telegram/telegramFailureRetry.d.ts.map +1 -0
- package/dist/connectors/telegram/telegramFailureRetry.js +21 -0
- package/dist/connectors/telegram/telegramFailureRetry.js.map +1 -0
- package/dist/connectors/telegram/unpinMessages.d.ts +1 -1
- package/dist/connectors/telegram/unpinMessages.d.ts.map +1 -1
- package/dist/connectors/telegram/unpinMessages.js +3 -18
- package/dist/connectors/telegram/unpinMessages.js.map +1 -1
- package/dist/hooks/claudeSkillsRestoreHook.d.ts +105 -0
- package/dist/hooks/claudeSkillsRestoreHook.d.ts.map +1 -0
- package/dist/hooks/claudeSkillsRestoreHook.js +276 -0
- package/dist/hooks/claudeSkillsRestoreHook.js.map +1 -0
- package/dist/platform/outbound.d.ts +4 -1
- package/dist/platform/outbound.d.ts.map +1 -1
- package/dist/platform/outbound.js.map +1 -1
- package/dist/rateLimiter.d.ts +33 -1
- package/dist/rateLimiter.d.ts.map +1 -1
- package/dist/rateLimiter.js +91 -5
- package/dist/rateLimiter.js.map +1 -1
- package/dist/runnerUtility/pueueDaemon.d.ts +7 -13
- package/dist/runnerUtility/pueueDaemon.d.ts.map +1 -1
- package/dist/runnerUtility/pueueDaemon.js +8 -27
- package/dist/runnerUtility/pueueDaemon.js.map +1 -1
- package/dist/selfUpdate/selfCheck.d.ts.map +1 -1
- package/dist/selfUpdate/selfCheck.js +1 -1
- package/dist/selfUpdate/selfCheck.js.map +1 -1
- package/dist/testTimings.d.ts +4 -2
- package/dist/testTimings.d.ts.map +1 -1
- package/dist/testTimings.js +4 -1
- package/dist/testTimings.js.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/agentPlugin.d.ts +7 -0
- package/dist/utils/agentPlugin.d.ts.map +1 -1
- package/dist/utils/agentPlugin.js +12 -0
- package/dist/utils/agentPlugin.js.map +1 -1
- package/dist/utils/claudeCompactHook.d.ts +73 -10
- package/dist/utils/claudeCompactHook.d.ts.map +1 -1
- package/dist/utils/claudeCompactHook.js +96 -17
- package/dist/utils/claudeCompactHook.js.map +1 -1
- package/dist/utils/claudeProfiles.d.ts +8 -0
- package/dist/utils/claudeProfiles.d.ts.map +1 -1
- package/dist/utils/claudeProfiles.js +12 -2
- package/dist/utils/claudeProfiles.js.map +1 -1
- package/dist/utils/claudeTranscriptEpoch.d.ts +15 -0
- package/dist/utils/claudeTranscriptEpoch.d.ts.map +1 -0
- package/dist/utils/claudeTranscriptEpoch.js +120 -0
- package/dist/utils/claudeTranscriptEpoch.js.map +1 -0
- package/dist/utils/clearStatusCoalescer.d.ts +24 -0
- package/dist/utils/clearStatusCoalescer.d.ts.map +1 -0
- package/dist/utils/clearStatusCoalescer.js +25 -0
- package/dist/utils/clearStatusCoalescer.js.map +1 -0
- package/dist/utils/compactOnIdle.d.ts +91 -34
- package/dist/utils/compactOnIdle.d.ts.map +1 -1
- package/dist/utils/compactOnIdle.js +149 -31
- package/dist/utils/compactOnIdle.js.map +1 -1
- package/dist/utils/groupOutputBacklog.d.ts +90 -0
- package/dist/utils/groupOutputBacklog.d.ts.map +1 -0
- package/dist/utils/groupOutputBacklog.js +134 -0
- package/dist/utils/groupOutputBacklog.js.map +1 -0
- package/dist/utils/messageSendService.d.ts +26 -3
- package/dist/utils/messageSendService.d.ts.map +1 -1
- package/dist/utils/messageSendService.js +35 -3
- package/dist/utils/messageSendService.js.map +1 -1
- package/dist/utils/openCodeCompactPlugin.d.ts +33 -0
- package/dist/utils/openCodeCompactPlugin.d.ts.map +1 -1
- package/dist/utils/openCodeCompactPlugin.js +192 -1
- package/dist/utils/openCodeCompactPlugin.js.map +1 -1
- package/dist/utils/skillsRestore.d.ts +235 -0
- package/dist/utils/skillsRestore.d.ts.map +1 -0
- package/dist/utils/skillsRestore.js +515 -0
- package/dist/utils/skillsRestore.js.map +1 -0
- package/dist/utils/statusFlushDecision.js +1 -1
- package/dist/utils/streamedCompactionSummary.d.ts +4 -4
- package/dist/utils/streamedCompactionSummary.js +5 -5
- package/dist/utils/streamedCompactionSummary.js.map +1 -1
- package/dist/utils/streamedOutputLanding.d.ts +14 -0
- package/dist/utils/streamedOutputLanding.d.ts.map +1 -0
- package/dist/utils/streamedOutputLanding.js +45 -0
- package/dist/utils/streamedOutputLanding.js.map +1 -0
- package/dist/utils/typingLoopBackstop.d.ts +8 -7
- package/dist/utils/typingLoopBackstop.d.ts.map +1 -1
- package/dist/utils/typingLoopBackstop.js +6 -5
- package/dist/utils/typingLoopBackstop.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/utils/clearThreadOutputQueues.d.ts +0 -44
- package/dist/utils/clearThreadOutputQueues.d.ts.map +0 -1
- package/dist/utils/clearThreadOutputQueues.js +0 -39
- package/dist/utils/clearThreadOutputQueues.js.map +0 -1
- package/dist/utils/groupFinalizePlan.d.ts +0 -36
- package/dist/utils/groupFinalizePlan.d.ts.map +0 -1
- package/dist/utils/groupFinalizePlan.js +0 -31
- package/dist/utils/groupFinalizePlan.js.map +0 -1
|
@@ -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
|
|
130
|
+
/** @description Take the oldest segment out to send it, with its number. `null` when nothing is pending. */
|
|
124
131
|
function takePendingOutput(buffer) {
|
|
125
|
-
|
|
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
|
|
129
|
-
*
|
|
130
|
-
*
|
|
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
|
-
|
|
134
|
-
|
|
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;
|
|
1
|
+
{"version":3,"file":"outputFlushPlan.js","sourceRoot":"","sources":["../../../src/connectors/telegram/outputFlushPlan.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAsCH,gDAgBC;AA2BD,8DAOC;AAYD,kDASC;AAqCD,kDAEC;AAcD,4CAaC;AAGD,sDAEC;AAGD,8CAMC;AAQD,wDAGC;AAqBD,gDAKC;AAhOD,iDAA8C;AAC9C,uDAAoD;AAEpD;;uDAEuD;AACvD,MAAM,qBAAqB,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,IAAA,iCAAe,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC;AAyBvF;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,KAAuB;IACxD,MAAM,SAAS,GACb,KAAK,CAAC,cAAc;QACpB,CAAC,KAAK,CAAC,eAAe;QACtB,KAAK,CAAC,aAAa,KAAK,IAAI;QAC5B,KAAK,CAAC,eAAe,KAAK,IAAI,CAAC;IACjC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO;YACL,MAAM,EAAE,IAAA,2BAAY,EAAC,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,qBAAqB,CAAC;YACpE,oBAA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AgB,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,48 @@
|
|
|
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);
|
|
6
|
+
* `unknown` — the Bot API did not answer within the send queue's deadline (`rateLimiter.ts` `SendOutcomeUnknownError`): the
|
|
7
|
+
* message may or may not be in the topic, so it must NOT be sent again.
|
|
8
|
+
*/
|
|
9
|
+
export type ThreadSendOutcome = {
|
|
10
|
+
kind: 'sent';
|
|
11
|
+
messageId: number;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'failed';
|
|
14
|
+
isRetryable: boolean;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'unknown';
|
|
17
|
+
};
|
|
18
|
+
/** @description How an edit of a topic message ended, with `unknown` as for a send: it may or may not be applied. */
|
|
19
|
+
export type ThreadEditOutcome = ThreadMessageEdit | 'unknown';
|
|
20
|
+
/**
|
|
21
|
+
* @description What an edit whose outcome is unknown means to the bot's callers: made. A caller answers a FAILED edit by posting
|
|
22
|
+
* the content anew (a status or thinking frame gets a new message, a screen is posted again, the output flush sends the text
|
|
23
|
+
* 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
|
|
24
|
+
* the same message rewrites it whole.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getCallerEditResult(outcome: ThreadEditOutcome): ThreadMessageEdit;
|
|
27
|
+
/** @description The message the topic's output continues: what the next continuation edits, and the text it appends to. */
|
|
28
|
+
export interface OutputMessageCursor {
|
|
29
|
+
lastMessageId: number | null;
|
|
30
|
+
lastMessageText: string | null;
|
|
31
|
+
}
|
|
32
|
+
/** @description The two Bot API moves of one output flush, bound to a topic by the bot. */
|
|
33
|
+
export interface OutputChunkPorts {
|
|
34
|
+
/** Edit the last message to `chunk` (a continuation that grows it in place). */
|
|
35
|
+
editLastMessage: (messageId: number, chunk: string) => Promise<ThreadEditOutcome>;
|
|
36
|
+
/** Send `chunk` as a message of its own. */
|
|
37
|
+
sendChunk: (chunk: string) => Promise<ThreadSendOutcome>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @description Land the chunks of one output flush (`getOutputFlushPlan`), in order, updating `cursor`. When `isFirstChunkAnEdit`
|
|
41
|
+
* the first chunk grows the last message in place; an edit that failed sends every chunk fresh instead (the message was deleted,
|
|
42
|
+
* say), but an edit whose outcome is UNKNOWN counts as made — sent fresh, the text could appear twice. A chunk that FAILS stops
|
|
43
|
+
* the run (the cooldown would drop the rest too) and the rest is the remainder, with whether trying it again may help (the
|
|
44
|
+
* backlog puts it back, or drops it when Telegram refused it for good). A chunk whose outcome is UNKNOWN counts as sent
|
|
45
|
+
* and is never sent again; the next text opens a message of its own, since the message it would continue is not known.
|
|
46
|
+
*/
|
|
47
|
+
export declare function sendOutputChunks(chunks: string[], isFirstChunkAnEdit: boolean, cursor: OutputMessageCursor, ports: OutputChunkPorts): Promise<GroupOutputSendResult>;
|
|
48
|
+
//# 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;;;;;GAKG;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,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAErI,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":";;AAqBA,kDAEC;AAwBD,4CA6BC;AA1ED,uDAAuD;AAavD;;;;;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,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Whether a Bot API call that failed with `error` may succeed if made again later. A Bot API answer is judged by its
|
|
3
|
+
* 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
|
|
4
|
+
* 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
|
|
5
|
+
* (Telegram unreachable or silent). Anything else — a bug in our code, a TypeError, a thrown string — is final: the same
|
|
6
|
+
* exception would come back at every try, for ever.
|
|
7
|
+
*/
|
|
8
|
+
export declare function checkIsTelegramFailureRetryable(error: unknown): boolean;
|
|
9
|
+
//# sourceMappingURL=telegramFailureRetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegramFailureRetry.d.ts","sourceRoot":"","sources":["../../../src/connectors/telegram/telegramFailureRetry.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIvE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkIsTelegramFailureRetryable = checkIsTelegramFailureRetryable;
|
|
4
|
+
const rateLimiter_1 = require("../../rateLimiter");
|
|
5
|
+
const sendErrorClassifier_1 = require("../../sendErrorClassifier");
|
|
6
|
+
const telegramError_1 = require("../../utils/telegramError");
|
|
7
|
+
/**
|
|
8
|
+
* @description Whether a Bot API call that failed with `error` may succeed if made again later. A Bot API answer is judged by its
|
|
9
|
+
* 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
|
|
10
|
+
* 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
|
|
11
|
+
* (Telegram unreachable or silent). Anything else — a bug in our code, a TypeError, a thrown string — is final: the same
|
|
12
|
+
* exception would come back at every try, for ever.
|
|
13
|
+
*/
|
|
14
|
+
function checkIsTelegramFailureRetryable(error) {
|
|
15
|
+
if ((0, rateLimiter_1.checkIsRateLimitedError)(error))
|
|
16
|
+
return true;
|
|
17
|
+
if ((0, sendErrorClassifier_1.checkIsApiError)(error) && (0, sendErrorClassifier_1.getErrorCode)(error) !== undefined)
|
|
18
|
+
return (0, telegramError_1.checkIsRetryableTelegramError)(error);
|
|
19
|
+
return (0, telegramError_1.checkIsNetworkError)(error);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=telegramFailureRetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegramFailureRetry.js","sourceRoot":"","sources":["../../../src/connectors/telegram/telegramFailureRetry.ts"],"names":[],"mappings":";;AAWA,0EAIC;AAfD,mDAA4D;AAC5D,mEAA0E;AAC1E,6DAA+F;AAE/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"}
|
|
@@ -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 (`
|
|
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":"
|
|
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
|
|
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 (`
|
|
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 (
|
|
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":";;
|
|
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,IA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