dsh-tg-bridge 1.7.3 → 1.7.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.
package/bot-menu.mjs CHANGED
@@ -47,7 +47,7 @@ const COMMANDS = [
47
47
  { command: 'app', description: 'Приложение DSH, не мост: /app restart confirm' },
48
48
  { command: 'restart', description: 'Перезапуск моста: /restart confirm' },
49
49
  { command: 'doctor', description: 'Диагностика: мост, сеть, диск, плагины, сессия' },
50
- { command: 'logs', description: 'Лог: /logs, /logs 100, /logs errors, /logs <текст>' },
50
+ { command: 'logs', description: 'Лог: /logs, /logs 100, /logs errors, /logs file' },
51
51
  { command: 'help', description: 'Все команды и подсказки' },
52
52
  { command: 'lang', description: 'Язык интерфейса: en, ru, zh' },
53
53
  { command: 'reasoning', description: 'Заметки по ходу: /reasoning on|off' },
@@ -77,7 +77,7 @@ const COMMANDS_EN = [
77
77
  { command: 'app', description: 'DSH desktop app (not the bridge)' },
78
78
  { command: 'restart', description: 'Restart the bridge: /restart confirm' },
79
79
  { command: 'doctor', description: 'Diagnostics: bridge, network, disk, plugins, session' },
80
- { command: 'logs', description: 'Log: /logs, /logs 100, /logs errors, /logs <text>' },
80
+ { command: 'logs', description: 'Log: /logs, /logs 100, /logs errors, /logs file' },
81
81
  { command: 'help', description: 'All commands and hints' },
82
82
  { command: 'lang', description: 'Interface language: en, ru, zh' },
83
83
  { command: 'reasoning', description: 'Working notes: /reasoning on|off' },
@@ -107,7 +107,7 @@ const COMMANDS_ZH = [
107
107
  { command: 'app', description: 'DSH 桌面应用(不是桥接)' },
108
108
  { command: 'restart', description: '重启桥接:/restart confirm' },
109
109
  { command: 'doctor', description: '诊断:桥接、网络、磁盘、插件、会话' },
110
- { command: 'logs', description: '日志:/logs、/logs 100、/logs errors、/logs <文本>' },
110
+ { command: 'logs', description: '日志:/logs、/logs 100、/logs errors、/logs file' },
111
111
  { command: 'help', description: '全部命令与提示' },
112
112
  { command: 'lang', description: '界面语言:en、ru、zh' },
113
113
  { command: 'reasoning', description: '工作记录:/reasoning on|off' },
package/bridge.mjs CHANGED
@@ -2301,10 +2301,22 @@ async function main() {
2301
2301
 
2302
2302
  // Replay anything the previous process owed an answer. Runs before polling so
2303
2303
  // a crash mid-turn costs one duplicate-free retry, not a lost message.
2304
+ //
2305
+ // One bad entry must not become a restart loop: `accept` throwing here used to
2306
+ // leave the update pending forever, so the bridge replayed it, died, and was
2307
+ // restarted by the supervisor — every ninety seconds, with a stack trace and
2308
+ // nothing else. Drop the entry after reporting it.
2304
2309
  const owed = pendingUpdates();
2305
2310
  if (owed.length > 0) {
2306
2311
  log(`replaying ${owed.length} pending update(s) from the journal`);
2307
- for (const { update } of owed) accept(update, true);
2312
+ for (const { update } of owed) {
2313
+ try {
2314
+ accept(update, true);
2315
+ } catch (error) {
2316
+ log(`replay of update ${update?.update_id} failed, dropping it: ${error.message}`);
2317
+ ack(update?.update_id);
2318
+ }
2319
+ }
2308
2320
  }
2309
2321
 
2310
2322
  let pollFailures = 0;
package/control.mjs CHANGED
@@ -438,6 +438,32 @@ export function reasoningOf(state, config, key) {
438
438
  return config?.reasoning !== false;
439
439
  }
440
440
 
441
+ /**
442
+ * The chat view of `bridge.log`. Delivery chatter ("sent chat=…") answers
443
+ * nothing when the question is "what did the agent do", so the default view
444
+ * hides it — it stays in the file for delivery debugging. `errors` keeps the
445
+ * bridge's own faults and drops tool results, which are part of the work.
446
+ */
447
+ export function filterLogLines(lines, filter, count) {
448
+ const isChatter = (line) =>
449
+ /\bsent chat=/.test(line)
450
+ || /\bin \d+ /.test(line)
451
+ || /bridge started|bot @|replaying \d+ pending|topic \d+ (?:seeded|logged)/.test(line);
452
+ const isToolLine = (line) => line.includes('tool[') || /\]\s+(?:pwsh|bash|shell)\b/.test(line);
453
+
454
+ let pool;
455
+ if (filter === 'errors') {
456
+ pool = lines.filter((line) => !isToolLine(line)
457
+ && /turn failed|FATAL|unhandled|poll error|Conflict|quota|AUTH|exiting code=[1-9]|cannot |failed to/i.test(line));
458
+ } else if (filter) {
459
+ const needle = filter.toLowerCase();
460
+ pool = lines.filter((line) => line.toLowerCase().includes(needle));
461
+ } else {
462
+ pool = lines.filter((line) => !isChatter(line));
463
+ }
464
+ return { pool, tail: pool.slice(-count) };
465
+ }
466
+
441
467
  export async function handleControl(ctx) {
442
468
  const { command, arg, send, reply, log, profile, state, key, config, lang } = ctx;
443
469
  const say = (text) => reply(text);
@@ -1126,8 +1152,24 @@ export async function handleControl(ctx) {
1126
1152
 
1127
1153
  case '/logs': {
1128
1154
  // `/logs` — meaningful events, `/logs 100` — more, `/logs <text>` —
1129
- // filter, `/logs errors` — failures only.
1155
+ // filter, `/logs errors` — failures only, `/logs file` — the whole file
1156
+ // as a document, when the answer needs the part chat cannot hold.
1130
1157
  const file = join(DSH_HOME, 'tg-bridge', 'bridge.log');
1158
+ const wanted = (arg || '').trim();
1159
+ if (/^(file|full|all|файл|файлом|全文|文件)$/i.test(wanted)) {
1160
+ if (!ctx.sendFile) {
1161
+ say(t(lang, 'ctrl.logs.noFileChannel'));
1162
+ return true;
1163
+ }
1164
+ try {
1165
+ await ctx.sendFile(file, t(lang, 'ctrl.logs.fileCaption', {
1166
+ mb: (statSync(file).size / 1024 ** 2).toFixed(1),
1167
+ }));
1168
+ } catch (error) {
1169
+ say(t(lang, 'ctrl.logs.unreadable', { err: error.message }));
1170
+ }
1171
+ return true;
1172
+ }
1131
1173
  let lines = [];
1132
1174
  try {
1133
1175
  lines = readFileSync(file, 'utf8').split(/\r?\n/).filter(Boolean);
@@ -1138,30 +1180,12 @@ export async function handleControl(ctx) {
1138
1180
  const numeric = Number(arg);
1139
1181
  const count = Number.isInteger(numeric) && numeric > 0 ? Math.min(numeric, 200) : 30;
1140
1182
  const filter = Number.isInteger(numeric) ? '' : (arg || '').trim();
1141
-
1142
- // Delivery chatter ("in 123", "sent chat=...") answers nothing when the
1143
- // question is "what did the agent do". It stays in the file for delivery
1144
- // debugging but is hidden from the chat view.
1145
- const isChatter = (line) =>
1146
- /\bsent chat=/.test(line)
1147
- || /\bin \d+ /.test(line)
1148
- || /bridge started|bot @|replaying \d+ pending|topic \d+ (?:seeded|logged)/.test(line);
1149
-
1150
- let pool;
1151
- if (filter === 'errors') {
1152
- pool = lines.filter((line) => /turn failed|ОШИБКА|error|poll error|409|Conflict|quota|AUTH/i.test(line));
1153
- } else if (filter) {
1154
- const needle = filter.toLowerCase();
1155
- pool = lines.filter((line) => line.toLowerCase().includes(needle));
1156
- } else {
1157
- pool = lines.filter((line) => !isChatter(line));
1158
- }
1183
+ const { pool, tail } = filterLogLines(lines, filter, count);
1159
1184
 
1160
1185
  if (pool.length === 0) {
1161
1186
  say(filter ? t(lang, 'ctrl.logs.noMatch', { filter }) : t(lang, 'ctrl.logs.empty'));
1162
1187
  return true;
1163
1188
  }
1164
- const tail = pool.slice(-count);
1165
1189
  const header = filter === 'errors'
1166
1190
  ? t(lang, 'ctrl.logs.errors', { shown: tail.length, total: pool.length })
1167
1191
  : t(lang, 'ctrl.logs.title', { shown: tail.length, total: pool.length });
@@ -1206,6 +1230,15 @@ export async function handleControl(ctx) {
1206
1230
  if (installed && latest && installed !== latest) lines.push(t(lang, 'ctrl.version.update', { v: latest }));
1207
1231
  lines.push(t(lang, 'ctrl.version.root', { path: where }));
1208
1232
  lines.push(t(lang, 'ctrl.version.hint'));
1233
+ // The number above comes from package.json on disk; the code actually
1234
+ // answering this came from the files as they were at process start. When
1235
+ // ./sync-runtime.mjs (or /update) has since replaced them, saying so
1236
+ // beats a version that reads as live while it is not.
1237
+ const started = Date.now() - process.uptime() * 1000;
1238
+ const newest = newestModuleMtime(where);
1239
+ if (newest && newest > started + 2000) {
1240
+ lines.push(t(lang, 'ctrl.version.stale', { when: stamp(newest) }));
1241
+ }
1209
1242
  say(lines.join('\n'));
1210
1243
  return true;
1211
1244
  }
@@ -1293,6 +1326,19 @@ function bridgeVersion() {
1293
1326
  }
1294
1327
  }
1295
1328
 
1329
+ /** Newest mtime among the modules a bridge install is made of, or 0. */
1330
+ function newestModuleMtime(root) {
1331
+ let newest = 0;
1332
+ try {
1333
+ for (const name of readdirSync(root)) {
1334
+ if (!name.endsWith('.mjs')) continue;
1335
+ const at = statSync(join(root, name)).mtimeMs;
1336
+ if (at > newest) newest = at;
1337
+ }
1338
+ } catch {}
1339
+ return newest;
1340
+ }
1341
+
1296
1342
  /** Latest published version of an npm package, or '' when npm is unreachable. */
1297
1343
  function npmLatest(name) {
1298
1344
  try {
package/i18n.mjs CHANGED
@@ -81,8 +81,8 @@ const DICT = {
81
81
  'ctrl.status.contextNoWindow': 'Context: {now} tokens (window unknown: set contextWindow in config.json)',
82
82
  'ctrl.status.lifetime': 'Session tokens billed: {n}',
83
83
  'ctrl.status.steps': 'Turns in the session: {n}',
84
- 'ctrl.status.turns': 'Agent running: {state} ({n} turn(s))',
85
- 'ctrl.status.running': 'yes',
84
+ 'ctrl.status.turns': 'Agent running: {state} ({n} turn(s))',
85
+ 'ctrl.status.running': 'yes',
86
86
  'ctrl.status.idle': 'no',
87
87
  'ctrl.status.notes': 'Working notes (💭 in progress): {state}',
88
88
  'ctrl.status.on': 'on',
@@ -136,6 +136,7 @@ const DICT = {
136
136
  'ctrl.version.offline': 'unreachable',
137
137
  'ctrl.version.update': 'Update available: /update, then /update confirm',
138
138
  'ctrl.version.root': 'Bridge directory: {path}',
139
+ 'ctrl.version.stale': 'Files are newer than this process ({when}) — /restart confirm loads them.',
139
140
  'ctrl.version.hint': 'The new code loads after /restart confirm; the current chat keeps running until then.',
140
141
  'ctrl.update.available': 'Version {from} is running, {to} is on npm.\nInstall it: /update confirm.\nEverything keeps working on the old code until /restart confirm.',
141
142
  'ctrl.update.current': 'Already on {v} — the latest published version.',
@@ -197,6 +198,8 @@ const DICT = {
197
198
  'ctrl.logs.empty': 'The log is empty.',
198
199
  'ctrl.logs.errors': 'Errors ({shown} of {total})',
199
200
  'ctrl.logs.title': 'Log ({shown} of {total})',
201
+ 'ctrl.logs.fileCaption': 'bridge.log, {mb} MB — the whole file',
202
+ 'ctrl.logs.noFileChannel': 'This bridge build cannot send files; use /logs 200.',
200
203
  'ctrl.thoughts.title': '🧠 Reasoning of the last turn ({chars} chars, kept for a few minutes):',
201
204
  'ctrl.thoughts.none': 'The last turn stored no reasoning plan.',
202
205
  'ctrl.thoughts.lastAnswer': 'What the last turn answered:',
@@ -351,8 +354,8 @@ const DICT = {
351
354
  'ctrl.status.contextNoWindow': 'Контекст: {now} токенов (окно неизвестно: укажи contextWindow в config.json)',
352
355
  'ctrl.status.lifetime': 'Токенов за сессию: {n}',
353
356
  'ctrl.status.steps': 'Ходов в сессии: {n}',
354
- 'ctrl.status.turns': 'Агент работает: {state} ({n} ход(ов))',
355
- 'ctrl.status.running': 'да',
357
+ 'ctrl.status.turns': 'Агент работает: {state} ({n} ход(ов))',
358
+ 'ctrl.status.running': 'да',
356
359
  'ctrl.status.idle': 'нет',
357
360
  'ctrl.status.notes': 'Заметки по ходу (💭 в прогрессе): {state}',
358
361
  'ctrl.status.on': 'включены',
@@ -406,6 +409,7 @@ const DICT = {
406
409
  'ctrl.version.offline': 'недоступен',
407
410
  'ctrl.version.update': 'Есть обновление: /update, затем /update confirm',
408
411
  'ctrl.version.root': 'Каталог моста: {path}',
412
+ 'ctrl.version.stale': 'Файлы новее запуска ({when}) — /restart confirm загрузит их.',
409
413
  'ctrl.version.hint': 'Новый код включится после /restart confirm — до этого чат работает как есть.',
410
414
  'ctrl.update.available': 'Работает {from}, на npm уже {to}.\nПоставить: /update confirm.\nДо /restart confirm всё работает на старом коде.',
411
415
  'ctrl.update.current': 'Уже стоит {v} — это последняя опубликованная версия.',
@@ -467,6 +471,8 @@ const DICT = {
467
471
  'ctrl.logs.empty': 'Лог пуст.',
468
472
  'ctrl.logs.errors': 'Ошибки ({shown} из {total})',
469
473
  'ctrl.logs.title': 'Лог ({shown} из {total})',
474
+ 'ctrl.logs.fileCaption': 'bridge.log, {mb} МБ — файл целиком',
475
+ 'ctrl.logs.noFileChannel': 'Эта сборка моста не умеет отправлять файлы; используй /logs 200.',
470
476
  'ctrl.thoughts.title': '🧠 Рассуждения последнего хода ({chars} символов, повисят несколько минут):',
471
477
  'ctrl.thoughts.none': 'В последнем ходе не сохранилось плана рассуждений.',
472
478
  'ctrl.thoughts.lastAnswer': 'Последний ход ответил так:',
@@ -621,8 +627,8 @@ const DICT = {
621
627
  'ctrl.status.contextNoWindow': '上下文:{now} 个 token(窗口未知:在 config.json 里设置 contextWindow)',
622
628
  'ctrl.status.lifetime': '本会话累计 token:{n}',
623
629
  'ctrl.status.steps': '会话中的轮次:{n}',
624
- 'ctrl.status.turns': '代理运行中:{state}({n} 个任务)',
625
- 'ctrl.status.running': '是',
630
+ 'ctrl.status.turns': '代理运行中:{state}({n} 个任务)',
631
+ 'ctrl.status.running': '是',
626
632
  'ctrl.status.idle': '否',
627
633
  'ctrl.status.notes': '工作记录(进度中的 💭):{state}',
628
634
  'ctrl.status.on': '开',
@@ -676,6 +682,7 @@ const DICT = {
676
682
  'ctrl.version.offline': '不可达',
677
683
  'ctrl.version.update': '有更新:/update,然后 /update confirm',
678
684
  'ctrl.version.root': '桥接目录:{path}',
685
+ 'ctrl.version.stale': '文件比本进程更新({when})—— /restart confirm 后生效。',
679
686
  'ctrl.version.hint': '新代码在 /restart confirm 之后生效;在此之前聊天照常运行。',
680
687
  'ctrl.update.available': '当前 {from},npm 上已是 {to}。\n安装:/update confirm。\n在 /restart confirm 之前一切仍用旧代码。',
681
688
  'ctrl.update.current': '已经是 {v} —— 最新发布版本。',
@@ -737,6 +744,8 @@ const DICT = {
737
744
  'ctrl.logs.empty': '日志为空。',
738
745
  'ctrl.logs.errors': '错误({shown}/{total})',
739
746
  'ctrl.logs.title': '日志({shown}/{total})',
747
+ 'ctrl.logs.fileCaption': 'bridge.log,{mb} MB —— 完整文件',
748
+ 'ctrl.logs.noFileChannel': '这个桥接版本无法发送文件;请用 /logs 200。',
740
749
  'ctrl.thoughts.title': '🧠 上一轮的推理({chars} 字符,几分钟后消失):',
741
750
  'ctrl.thoughts.none': '上一轮没有保存推理过程。',
742
751
  'ctrl.thoughts.lastAnswer': '上一轮的回答:',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-tg-bridge",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "description": "Telegram bridge for DeepSeek Harness: text, voice, photos and project-per-topic sessions without opening the desktop app",
5
5
  "type": "module",
6
6
  "main": "plugin-bridge.mjs",