dsh-tg-bridge 1.38.2 → 1.38.4

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.
@@ -109,7 +109,11 @@ export async function handleCallback(query) {
109
109
  const line = answerRewindPress(data, {
110
110
  used: rewindUsed,
111
111
  lang,
112
- t,
112
+ // Bound, not the raw `t`: this helper calls `t(key, vars)` with one
113
+ // argument, so the unbound import read the key as a language and returned
114
+ // the string "undefined" — which is what every rewind button answered on
115
+ // 2026-11-01 until the binding was fixed here.
116
+ t: (k, vars) => t(lang, k, vars),
113
117
  ctx: {
114
118
  sessionId,
115
119
  busy: activeTurns.has(key),
@@ -1,55 +1,55 @@
1
- // What the chat sends when the model hands back its own notes instead of a reply.
2
- //
3
- // The headless CLI's `final` text is the turn's last assistant text, and a turn
4
- // that produced no answer reports the reasoning. Forwarding it reads as "the bot
5
- // answers with its thinking", and suppressing it reads as "the turn died" — both
6
- // were real, and both are the same defect seen from two sides. The guard here
7
- // asks once more, in the same session, for a finished reply; only when that also
8
- // comes back as notes does it send the honest sentence.
9
- //
10
- // Extracted from `handle-message.mjs`, which is at its size ceiling and whose
11
- // subject is "one incoming message becomes one turn", not "what a reply is".
12
- import { looksLikeReasoning, REPLY_NUDGE, stripThinkingBlocks } from './panel.mjs';
13
- import { turnAttempt } from '../turn/turn.mjs';
14
-
15
- /** Is this text the reasoning the panel already holds, markers included? */
16
- export function isReasoningEcho(value, reasoning) {
17
- return looksLikeReasoning(value, reasoning);
18
- }
19
-
20
- /**
21
- * Produce the text the chat should send, asking the model once more if needed.
22
- *
23
- * @param {object} input
24
- * @param {object} input.result the finished turn: `{ text, error }`, replaced in
25
- * place when the second attempt produces a real answer
26
- * @param {() => string} input.reasoning the reasoning this turn collected
27
- * @param {string} input.key the topic key
28
- * @param {object} input.turnOptions the options the first attempt ran with, so
29
- * the second attempt cannot drift from it
30
- * @param {string} input.sessionId the session the first attempt ran in
31
- * @param {string} input.where the log label for this topic
32
- * @param {(line: string) => void} input.log
33
- * @param {Function} [input.retryTurn] builds the second attempt; defaults to the
34
- * real one. Injectable because the guard's tests must not spawn a CLI.
35
- * @returns {Promise<{ text: string, echoed: boolean }>} `echoed` means nothing
36
- * the person should read was produced, and the caller sends its own sentence
37
- */
38
- export async function replyText({ result, reasoning, key, turnOptions, sessionId, where, log, retryTurn = turnAttempt }) {
39
- const echoed = (value) => isReasoningEcho(value, reasoning());
40
- if (echoed(result.text)) {
41
- log(`reasoning echo for ${where} (${String(result.text).length} chars) — asking once more`);
42
- const retry = await retryTurn(REPLY_NUDGE, key, turnOptions)(sessionId);
43
- if (!retry.error && !echoed(retry.text) && stripThinkingBlocks(retry.text)) {
44
- Object.assign(result, retry);
45
- }
46
- }
47
- if (echoed(result.text)) {
48
- log(`reasoning echo suppressed for ${where} (${String(result.text).length} chars)`);
49
- return { text: '', echoed: true };
50
- }
51
- // The marker can survive inside an otherwise real reply; the chat never shows it.
52
- return { text: stripThinkingBlocks(result.text), echoed: false };
53
- }
54
-
55
- export { REPLY_NUDGE };
1
+ // What the chat sends when the model hands back its own notes instead of a reply.
2
+ //
3
+ // The headless CLI's `final` text is the turn's last assistant text, and a turn
4
+ // that produced no answer reports the reasoning. Forwarding it reads as "the bot
5
+ // answers with its thinking", and suppressing it reads as "the turn died" — both
6
+ // were real, and both are the same defect seen from two sides. The guard here
7
+ // asks once more, in the same session, for a finished reply; only when that also
8
+ // comes back as notes does it send the honest sentence.
9
+ //
10
+ // Extracted from `handle-message.mjs`, which is at its size ceiling and whose
11
+ // subject is "one incoming message becomes one turn", not "what a reply is".
12
+ import { looksLikeReasoning, REPLY_NUDGE, stripThinkingBlocks } from './panel.mjs';
13
+ import { turnAttempt } from '../turn/turn.mjs';
14
+
15
+ /** Is this text the reasoning the panel already holds, markers included? */
16
+ export function isReasoningEcho(value, reasoning) {
17
+ return looksLikeReasoning(value, reasoning);
18
+ }
19
+
20
+ /**
21
+ * Produce the text the chat should send, asking the model once more if needed.
22
+ *
23
+ * @param {object} input
24
+ * @param {object} input.result the finished turn: `{ text, error }`, replaced in
25
+ * place when the second attempt produces a real answer
26
+ * @param {() => string} input.reasoning the reasoning this turn collected
27
+ * @param {string} input.key the topic key
28
+ * @param {object} input.turnOptions the options the first attempt ran with, so
29
+ * the second attempt cannot drift from it
30
+ * @param {string} input.sessionId the session the first attempt ran in
31
+ * @param {string} input.where the log label for this topic
32
+ * @param {(line: string) => void} input.log
33
+ * @param {Function} [input.retryTurn] builds the second attempt; defaults to the
34
+ * real one. Injectable because the guard's tests must not spawn a CLI.
35
+ * @returns {Promise<{ text: string, echoed: boolean }>} `echoed` means nothing
36
+ * the person should read was produced, and the caller sends its own sentence
37
+ */
38
+ export async function replyText({ result, reasoning, key, turnOptions, sessionId, where, log, retryTurn = turnAttempt }) {
39
+ const echoed = (value) => isReasoningEcho(value, reasoning());
40
+ if (echoed(result.text)) {
41
+ log(`reasoning echo for ${where} (${String(result.text).length} chars) — asking once more`);
42
+ const retry = await retryTurn(REPLY_NUDGE, key, turnOptions)(sessionId);
43
+ if (!retry.error && !echoed(retry.text) && stripThinkingBlocks(retry.text)) {
44
+ Object.assign(result, retry);
45
+ }
46
+ }
47
+ if (echoed(result.text)) {
48
+ log(`reasoning echo suppressed for ${where} (${String(result.text).length} chars)`);
49
+ return { text: '', echoed: true };
50
+ }
51
+ // The marker can survive inside an otherwise real reply; the chat never shows it.
52
+ return { text: stripThinkingBlocks(result.text), echoed: false };
53
+ }
54
+
55
+ export { REPLY_NUDGE };
package/chat/telegram.mjs CHANGED
@@ -147,12 +147,30 @@ export async function sendWithMarkup(chatId, threadId, text, extra = {}) {
147
147
  ...thread,
148
148
  }).catch(() => {});
149
149
  }
150
- if (extra.keyboard) {
150
+ // A card may also hand its buttons over ready-made, under Telegram's own field
151
+ // name: `/load` (control/cmd-load.mjs), the held-turn notice (work/load-guard.mjs)
152
+ // and the sandbox notice (chat/handle-message.mjs) all pass
153
+ // `{ reply_markup: { inline_keyboard: rows } }`. Only `extra.keyboard` used to be
154
+ // read, so those three took the plain-send path and their buttons were never
155
+ // drawn — `/load` is a card whose whole point is its two buttons, and the sandbox
156
+ // notice tells a person to open /permissions with a button that did not exist.
157
+ // What arrives is this repo's `{ text, data }` vocabulary as often as a finished
158
+ // Telegram button, so both shapes go through the same conversion.
159
+ const rows = extra.keyboard || extra.reply_markup?.inline_keyboard;
160
+ if (rows) {
161
+ const keyboard = inlineKeyboard(rows);
162
+ if (keyboard.length === 0) {
163
+ // Every button was a label with no payload. Sending the empty keyboard would
164
+ // hide that; the text still has to arrive, and the log has to say why the
165
+ // card came without buttons.
166
+ log('inline keyboard had no usable buttons; sending without buttons');
167
+ return send(chatId, text, threadId);
168
+ }
151
169
  return tg('sendMessage', {
152
170
  chat_id: chatId,
153
171
  text,
154
172
  disable_web_page_preview: true,
155
- reply_markup: { inline_keyboard: inlineKeyboard(extra.keyboard) },
173
+ reply_markup: { inline_keyboard: keyboard },
156
174
  ...thread,
157
175
  }).catch((error) => {
158
176
  // Silence here cost a release: the card never appeared and the log said
@@ -23,7 +23,7 @@ import { saveState, state } from '../core/state.mjs';
23
23
  // missing binding here survived a green suite while every real tap died with
24
24
  // "t is not defined": the router is the only caller that has to supply it.
25
25
  import { t } from '../core/i18n.mjs';
26
- import { send, tg, tgFast } from '../chat/telegram.mjs';
26
+ import { inlineKeyboard, send, tg, tgFast } from '../chat/telegram.mjs';
27
27
 
28
28
  export const MODEL_PREFIX = 'md:';
29
29
  /** Step one: the endpoint list. `md:!p` on its own asks for it again. */
@@ -344,6 +344,12 @@ export async function handleModelPress({
344
344
  // "route → x" would read as a change to the whole install.
345
345
  const now = topicRoute({ state: live, key });
346
346
  const head = modelOf(profile);
347
+ // Acknowledge before speaking: without it Telegram keeps the spinner on the
348
+ // button for 45 seconds and then reports that the tap never answered — which is
349
+ // how a switch that worked was shown to a person as a failure. Every other
350
+ // branch of this function answered; this one did not. The toast carries the
351
+ // chosen route, because that is the one fact checked right after the tap.
352
+ await answer(`${now.provider}/${now.model}`);
347
353
  await say(t(lang, 'ctrl.model.topicSet', {
348
354
  route: `${now.provider}/${now.model}`,
349
355
  default: `${head.provider}/${head.model}`,
@@ -372,12 +378,19 @@ export function modelPressRouter({ chatId, threadId, messageId, key, lang, answe
372
378
  t,
373
379
  say: async (text) => send(chatId, text, threadId),
374
380
  answer,
375
- redraw: (card) =>
376
- tgFast('editMessageText', {
381
+ redraw: (card) => {
382
+ // `card.keyboard` is this module's own shape: `{ text, data }`. Telegram
383
+ // knows only `callback_data`, and a button with `text` and no
384
+ // `callback_data` is refused with "Text buttons are not allowed in the
385
+ // inline keyboard" — the whole edit, not just that button. Sending the
386
+ // internal shape is why every endpoint tap since 1.19 left the card on
387
+ // step one. Convert, and never hand Telegram the raw rows.
388
+ const keyboard = inlineKeyboard(card.keyboard);
389
+ return tgFast('editMessageText', {
377
390
  chat_id: chatId,
378
391
  message_id: messageId,
379
392
  text: card.text,
380
- reply_markup: { inline_keyboard: card.keyboard },
393
+ reply_markup: { inline_keyboard: keyboard },
381
394
  ...(threadId > 0 ? { message_thread_id: threadId } : {}),
382
395
  }).catch(async (error) => {
383
396
  // A refused edit used to be swallowed, which is how "the endpoint tap
@@ -388,12 +401,13 @@ export function modelPressRouter({ chatId, threadId, messageId, key, lang, answe
388
401
  await tgFast('sendMessage', {
389
402
  chat_id: chatId,
390
403
  text: card.text,
391
- reply_markup: { inline_keyboard: card.keyboard },
404
+ reply_markup: { inline_keyboard: keyboard },
392
405
  ...(threadId > 0 ? { message_thread_id: threadId } : {}),
393
406
  }).catch((sendError) => {
394
407
  log(`model card resend failed for ${key}: ${sendError.message}`);
395
408
  });
396
- }),
409
+ });
410
+ },
397
411
  }).then((claimed) => {
398
412
  if (claimed) log(`model press ${data} for ${key}`);
399
413
  return claimed;
package/docs/CHANGELOG.md CHANGED
@@ -1,5 +1,57 @@
1
1
  # CHANGELOG — DSH Telegram bridge
2
2
 
3
+ ## 1.38.4
4
+
5
+ - **A rewind button no longer answers "undefined".** `answerRewindPress()` was
6
+ handed the unbound `t`, and it calls `t(key, vars)` with one argument, so the
7
+ i18n read the key as a language and returned `String(undefined)` — every press
8
+ on the card replaced it with the single word *undefined*, in every language.
9
+ The caller now binds the topic's language, and the helper itself falls back to
10
+ the key when a translation is missing, so a caller's binding mistake stays
11
+ visible instead of becoming a message.
12
+ - **"Back N" on the usage card cuts; it no longer only cancels.** Both buttons
13
+ carried the verb `n`: the quick pick as `rw:n:<steps>`, the cancel as `rw:n::`.
14
+ The handler read the verb alone, so `/rewind` followed by "back 2" cancelled
15
+ and removed nothing — the one path the feature exists for. A step count now
16
+ decides: `rw:n:<n>` cuts, `rw:n::` cancels, and both take the same one-use
17
+ ticket, so a double tap still cannot cut twice.
18
+ - **Picking a model for one topic acknowledges the press.** That branch switched
19
+ the route, wrote the state and sent its confirmation, but never answered the
20
+ callback, so Telegram kept the spinner for 45 seconds and then reported that
21
+ the tap never answered — a switch that worked, shown as a failure, with the
22
+ confirmation arriving after the person had already pressed something else. The
23
+ toast now carries the route that took, before the confirmation text.
24
+ - **Three cards stop losing their buttons on the way out.** `/load`
25
+ (control/cmd-load.mjs), the held-turn notice (work/load-guard.mjs) and the
26
+ sandbox notice (chat/handle-message.mjs) hand their markup over as
27
+ `reply_markup`, and `sendWithMarkup()` read only `extra.keyboard` — so the
28
+ `/load` card arrived without its refresh and guard buttons, and the sandbox
29
+ notice told a person to open `/permissions` with a button that was never drawn.
30
+ Both shapes now go through the same conversion, and a keyboard with nothing
31
+ pressable is logged and sent without buttons instead of arriving empty.
32
+
33
+ ## 1.38.3
34
+
35
+ - **The `/model` endpoint tap now reaches the model list.** The report was always
36
+ the same: tap an endpoint, nothing happens, the card stays on step one, and
37
+ there is no way to test a turn on another model without asking an agent to do
38
+ it by hand. The cause was one field name. `modelCard()` builds buttons as
39
+ `{ text, data }` — this module's own shape — and the redraw sent
40
+ `card.keyboard` straight to Telegram, which knows only `callback_data` and
41
+ rejects a button that has text and no payload with `can't parse
42
+ InlineKeyboardButton: Text buttons are not allowed in the inline keyboard`.
43
+ That rejects the whole edit, so the second step was built, sent, and refused
44
+ every time since the two-step card shipped. The redraw now converts with the
45
+ same `inlineKeyboard()` every other keyboard uses, and the re-send fallback
46
+ gets the converted rows too — a fallback carrying the bad shape fails for the
47
+ same reason the edit did.
48
+ - **The test asserts the wire shape, not the local one.** Twenty-five green tests
49
+ covered this card and none of them caught it, because they checked that the
50
+ keyboard had rows after building it in memory, where `data` is correct. The
51
+ press test now walks every button of the edit and of the re-sent message and
52
+ requires `callback_data`, at most 64 bytes, and no leftover `data` field — the
53
+ three things Telegram checks before it will draw anything.
54
+
3
55
  ## 1.38.2
4
56
 
5
57
  - **A turn that ends without an answer asks once more instead of apologising.**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-tg-bridge",
3
- "version": "1.38.2",
3
+ "version": "1.38.4",
4
4
  "description": "Drive DeepSeek Harness from Telegram: one project, model and session per forum topic",
5
5
  "type": "module",
6
6
  "main": "plugin-bridge.mjs",
@@ -35,34 +35,48 @@ export function cutSession(file, steps, applyRewind) {
35
35
  * changes nothing and says why.
36
36
  */
37
37
  export function answerRewindPress(data, { t, ctx, used = new Set() }) {
38
+ // A missing translation must never reach a chat as the word "undefined": the
39
+ // helper used to be handed the unbound `t`, so `t('ctrl.rewind.cancelled')` read
40
+ // the key as a language and returned String(undefined) — which is what every
41
+ // rewind button said on 2026-11-01. Unknown keys now fall back to the key, which
42
+ // is ugly but true, and a caller's binding mistake stays visible instead of
43
+ // becoming a message.
44
+ const say = (k, vars) => {
45
+ const line = t(k, vars);
46
+ return typeof line === 'string' && line && line !== 'undefined' ? line : k;
47
+ };
38
48
  const match = REWIND_CALLBACK.exec(String(data || ''));
39
- if (!match) return t('ctrl.rewind.stale');
49
+ if (!match) return say('ctrl.rewind.stale');
40
50
  const [, verb, rawSteps, tail] = match;
41
51
  const steps = rawSteps ? Number.parseInt(rawSteps, 10) : 0;
42
- if (!ctx.sessionId || !ctx.sessionId.endsWith(tail)) return t('ctrl.rewind.stale');
43
- if (ctx.busy) return t('ctrl.rewind.busy');
52
+ if (!ctx.sessionId || !ctx.sessionId.endsWith(tail)) return say('ctrl.rewind.stale');
53
+ if (ctx.busy) return say('ctrl.rewind.busy');
44
54
  // A card is used once. Without this a double tap on "go back 2" cuts four
45
55
  // turns, and the second cut has no card left to undo it from.
46
- if (verb === 'y' && used.has(data)) return t('ctrl.rewind.stale');
47
- if (verb === 'y') used.add(data);
56
+ // `rw:n:<steps>` is the usage card's "back N" quick pick — the same cut, one
57
+ // tap. Only `rw:n::` with no number is the cancel button. Reading the verb
58
+ // alone made those two the same press, so "back 2" could only ever cancel.
59
+ const cuts = verb === 'y' || (verb === 'n' && steps > 0);
60
+ if (cuts && used.has(data)) return say('ctrl.rewind.stale');
61
+ if (cuts) used.add(data);
48
62
 
49
- if (verb === 'n') return t('ctrl.rewind.cancelled');
63
+ if (verb === 'n' && !steps) return say('ctrl.rewind.cancelled');
50
64
  if (verb === 'u') {
51
65
  const done = ctx.undo();
52
- if (done.error === 'nothing') return t('ctrl.rewind.nothing');
53
- return done.error ? t('ctrl.rewind.failed', { error: done.error }) : t('ctrl.rewind.undone');
66
+ if (done.error === 'nothing') return say('ctrl.rewind.nothing');
67
+ return done.error ? say('ctrl.rewind.failed', { error: done.error }) : say('ctrl.rewind.undone');
54
68
  }
55
- if (!steps) return t('ctrl.rewind.stale');
69
+ if (!steps) return say('ctrl.rewind.stale');
56
70
 
57
71
  const done = ctx.cut(steps);
58
72
  if (done.error) {
59
73
  const why = REFUSALS.includes(done.error)
60
- ? t(`ctrl.rewind.refused.${done.error}`, { total: done.plan?.total ?? 0, dropped: steps })
74
+ ? say(`ctrl.rewind.refused.${done.error}`, { total: done.plan?.total ?? 0, dropped: steps })
61
75
  : done.error;
62
- return t('ctrl.rewind.failed', { error: why });
76
+ return say('ctrl.rewind.failed', { error: why });
63
77
  }
64
78
  // The card becomes one line with no buttons: the turns it offered are gone.
65
79
  const kept = done.plan ? done.plan.kept : 0;
66
- if (kept > 0) return t('ctrl.rewind.done', { n: steps, turn: kept, backup: done.backup });
67
- return t('ctrl.rewind.done.alias', { n: steps, turn: 0 });
80
+ if (kept > 0) return say('ctrl.rewind.done', { n: steps, turn: kept, backup: done.backup });
81
+ return say('ctrl.rewind.done.alias', { n: steps, turn: 0 });
68
82
  }