dsh-tg-bridge 1.38.3 → 1.38.5

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,51 @@
1
1
  # CHANGELOG — DSH Telegram bridge
2
2
 
3
+ ## 1.38.5
4
+
5
+ - **The settings card opens the thing it names.** A row like «Модель» runs
6
+ `/model`, whose answer is a card with buttons. The press handler kept only the
7
+ text of whatever the command answered, so the model card arrived as a plain
8
+ message: it named the current model and gave no way to change it — the settings
9
+ screen could describe the install but not edit it. A card-shaped answer is now
10
+ sent under the settings card with its keyboard, in the topic it was asked in,
11
+ and a plain answer still comes as one line. `/fallback`, `/permissions`,
12
+ `/preset` and `/cd` sit behind the same door and open the same way.
13
+ - **The last thought of a turn reaches the card.** The progress card re-reads the
14
+ decision trail every three seconds, so a line written in the final seconds —
15
+ "the result is checked", the one that says how the turn ended — landed between
16
+ two ticks and never appeared at all. The card now reads the trail once more
17
+ before it is finished, and only while `/thoughts` is not off.
18
+
19
+ ## 1.38.4
20
+
21
+ - **A rewind button no longer answers "undefined".** `answerRewindPress()` was
22
+ handed the unbound `t`, and it calls `t(key, vars)` with one argument, so the
23
+ i18n read the key as a language and returned `String(undefined)` — every press
24
+ on the card replaced it with the single word *undefined*, in every language.
25
+ The caller now binds the topic's language, and the helper itself falls back to
26
+ the key when a translation is missing, so a caller's binding mistake stays
27
+ visible instead of becoming a message.
28
+ - **"Back N" on the usage card cuts; it no longer only cancels.** Both buttons
29
+ carried the verb `n`: the quick pick as `rw:n:<steps>`, the cancel as `rw:n::`.
30
+ The handler read the verb alone, so `/rewind` followed by "back 2" cancelled
31
+ and removed nothing — the one path the feature exists for. A step count now
32
+ decides: `rw:n:<n>` cuts, `rw:n::` cancels, and both take the same one-use
33
+ ticket, so a double tap still cannot cut twice.
34
+ - **Picking a model for one topic acknowledges the press.** That branch switched
35
+ the route, wrote the state and sent its confirmation, but never answered the
36
+ callback, so Telegram kept the spinner for 45 seconds and then reported that
37
+ the tap never answered — a switch that worked, shown as a failure, with the
38
+ confirmation arriving after the person had already pressed something else. The
39
+ toast now carries the route that took, before the confirmation text.
40
+ - **Three cards stop losing their buttons on the way out.** `/load`
41
+ (control/cmd-load.mjs), the held-turn notice (work/load-guard.mjs) and the
42
+ sandbox notice (chat/handle-message.mjs) hand their markup over as
43
+ `reply_markup`, and `sendWithMarkup()` read only `extra.keyboard` — so the
44
+ `/load` card arrived without its refresh and guard buttons, and the sandbox
45
+ notice told a person to open `/permissions` with a button that was never drawn.
46
+ Both shapes now go through the same conversion, and a keyboard with nothing
47
+ pressable is logged and sent without buttons instead of arriving empty.
48
+
3
49
  ## 1.38.3
4
50
 
5
51
  - **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.5",
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",
@@ -21,7 +21,7 @@ import { DIR } from '../core/paths.mjs';
21
21
  import { maxParallel } from '../turn/queue.mjs';
22
22
  import { commandFor, renderSettingsCard, settingsCurrent } from './settings-card.mjs';
23
23
  import { config, log, saveConfig, saveState, state } from '../core/state.mjs';
24
- import { inlineKeyboard, send, tg, tgFast } from '../chat/telegram.mjs';
24
+ import { inlineKeyboard, send, sendWithMarkup, tg, tgFast } from '../chat/telegram.mjs';
25
25
  import { activeTurns, baseProfileOf } from '../turn/turn.mjs';
26
26
  import { join } from 'node:path';
27
27
 
@@ -92,6 +92,17 @@ export async function handleCardPress(query, ctx) {
92
92
  // in the chat: the one line below is the chat's share of this press. Only a
93
93
  // command that failed says more than that.
94
94
  const replies = [];
95
+ // A command may answer with buttons — `/model` and `/fallback` are cards whose
96
+ // whole point is their keyboard. The adapters below used to keep only the text,
97
+ // so the settings door to the model picker opened onto a message that named the
98
+ // current model and offered no way to change it.
99
+ const cards = [];
100
+ const collect = (text, extra = {}) => {
101
+ const body = String(text ?? '');
102
+ if (extra?.keyboard || extra?.reply_markup) cards.push({ body, extra });
103
+ else replies.push(body);
104
+ return Promise.resolve(0);
105
+ };
95
106
  // A press that fails has to say so: the card is redrawn either way, and a
96
107
  // redraw alone looks exactly like success. The old path hid failures behind a
97
108
  // line the person read as a confirmation.
@@ -113,14 +124,8 @@ export async function handleCardPress(query, ctx) {
113
124
  // and vanish on restart, which is the worst of both answers.
114
125
  saveConfig,
115
126
  log,
116
- send: (text) => {
117
- replies.push(String(text ?? ''));
118
- return Promise.resolve(0);
119
- },
120
- reply: (text) => {
121
- replies.push(String(text ?? ''));
122
- return Promise.resolve(0);
123
- },
127
+ send: collect,
128
+ reply: collect,
124
129
  jobs: () => ({ active: [], queued: 0, max: maxParallel() }),
125
130
  api: tg,
126
131
  sendFile: () => Promise.resolve(0),
@@ -151,6 +156,17 @@ export async function handleCardPress(query, ctx) {
151
156
  // a failure is on the card too, so it is not repeated below it.
152
157
  if (!handled) log(`settings press ${data}: no handler answered`);
153
158
  const notLine = replies.filter(Boolean).filter((r) => r !== wanted.command);
159
+ // A card-shaped answer goes under the settings card, with its buttons: the press
160
+ // asked to go somewhere, and swallowing the keyboard is what made
161
+ // `/settings → Модель` a screen you could read but not act on.
162
+ if (cards.length > 0 && !failed) {
163
+ const card = cards[0];
164
+ await sendWithMarkup(chatId, threadId, card.body, card.extra).catch((error) => {
165
+ log(`settings press ${data}: card with buttons failed (${error.message})`);
166
+ return send(chatId, card.body, threadId).catch(() => {});
167
+ });
168
+ return;
169
+ }
154
170
  if (notLine.length > 0 && !changed && !failed) {
155
171
  await send(chatId, notLine[0], threadId).catch(() => {});
156
172
  }
package/turn/progress.mjs CHANGED
@@ -371,6 +371,21 @@ export async function startProgress(chatId, threadId, lang = config.lang || 'en'
371
371
  async finish(result) {
372
372
  clearTimeout(timer);
373
373
  clearInterval(thoughtTimer);
374
+ // One last read before the card is finished. A thought written in the last
375
+ // seconds of a turn — "the result is checked", usually, the line that matters
376
+ // most — used to land between two ticks of the loop above and never reach the
377
+ // card at all. The trail is written until the turn ends, so the last read has
378
+ // to happen at the end too.
379
+ if (reasoningMode(state, config, panelKey) !== 'off') {
380
+ try {
381
+ const rows = thoughtRows([notes, topicNotes], started);
382
+ const merged = rows.slice(-2).map((row) => row.text);
383
+ if (merged.join('\n') !== thoughts.join('\n')) thoughts = merged;
384
+ } catch {
385
+ // An unreadable file leaves the last known lines in place: the card is
386
+ // worth more than an empty promise of a trail.
387
+ }
388
+ }
374
389
  if (result?.stopped) {
375
390
  // The person pressed Стоп. The card says so in their words, not with a
376
391
  // ⚠️ and not with a retry button: nothing failed, and the session is
@@ -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
  }