dsh-tg-bridge 1.38.3 → 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),
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
@@ -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}`,
package/docs/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
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
+
3
33
  ## 1.38.3
4
34
 
5
35
  - **The `/model` endpoint tap now reaches the model list.** The report was always
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-tg-bridge",
3
- "version": "1.38.3",
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
  }