dsh-tg-bridge 1.5.4 → 1.6.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/README.md CHANGED
@@ -11,7 +11,8 @@ blocks.
11
11
 
12
12
  - **Text**: a regular task goes to the agent, the answer comes back in the same topic.
13
13
  - **Voice**: local faster-whisper, the transcript is shown before the answer.
14
- - **Photos**: sent to a vision-capable model; text and UI are recognized.
14
+ - **Photos**: the turn's own model reads them through `read_image`, text and UI
15
+ included; no second model is needed (a vision overlay stays opt-in).
15
16
  - **Project per topic**: `/cd my-app`, and all turns run from that directory.
16
17
  - **Goal and checklist per topic**: `/goal`, `/task`; both survive restarts and are prepended to every turn.
17
18
  - **Live progress**: "⏳ Working..." with steps, a timer and the cache hit rate at the end.
@@ -53,7 +54,7 @@ can be listed next to them:
53
54
  - Topic language: `/lang en|ru|zh`; stored in `state.json` and survives a restart.
54
55
  - A new user gets the language from the Telegram `language_code`; anything that is not `ru`/`zh` → `en`.
55
56
  - Translated so far: menus, the start message, turn status, errors, `/cd`, `/new`, `/stop`, `/lang`,
56
- the reply to an unknown command. Long reports (`/status`, `/sessions`, `/models` and similar)
57
+ the reply to an unknown command. Long reports (`/status`, `/sessions`, `/model` and similar)
57
58
  are still in Russian, that is the next pass.
58
59
 
59
60
  ## Installation
@@ -98,7 +99,8 @@ Optional provider settings live in `config.json`:
98
99
  |---|---|
99
100
  | `providerKeys` | extra env var names to pass to a turn, read from `~/.dsh/.credentials.yaml`; default `[]` |
100
101
  | `pricesUrl` | public model page for `/prices`; default `""` uses models.dev only |
101
- | `vision.patch` | overlay for photo turns; default `""` (photos are text-only until set) |
102
+ | `vision.patch` | opt-in overlay profile for photo turns; default `""` — the turn's own model reads images |
103
+ | `vision.enabled` | set `true` to run photo turns on `vision.patch` instead of the topic profile |
102
104
  | `fallbackModels` | free-model fallbacks; default `[]` |
103
105
 
104
106
  Get your id from [@userinfobot](https://t.me/userinfobot), the token from
@@ -144,13 +146,13 @@ Error replies end with a code, which tells you what to fix:
144
146
 
145
147
  | Code | Meaning |
146
148
  |---|---|
147
- | `INSUFFICIENT_QUOTA` | provider balance is empty: top up or stay on free models (`/prices`, `/models`) |
149
+ | `INSUFFICIENT_QUOTA` | provider balance is empty: top up or stay on free models (`/prices`, `/model`) |
148
150
  | `TG_CONFLICT` | a second process is polling the same bot: `/doctor`, then `/restart` |
149
151
  | `MISSING_CREDENTIAL` | no provider key in the profile: add it in the DSH app |
150
152
  | `NO_DSH_CLI` | DeepSeek Harness CLI not found: check the app installation |
151
153
  | `NETWORK` | no network to the provider: retry, check VPN/DNS |
152
154
  | `SANDBOX_DENY` | DSH denied access to a file or directory: check the project path and permissions |
153
- | `UNKNOWN_MODEL` | the model from the config is unavailable: `/models` lists the working ones |
155
+ | `UNKNOWN_MODEL` | the model from the config is unavailable: `/model` lists the working ones |
154
156
  | `EMPTY_RESPONSE` | the model returned nothing: retry or switch model (`/model`) |
155
157
  | `TURN_FAILED` | cause not recognized: `/doctor` and `/logs errors` |
156
158
 
@@ -171,10 +173,12 @@ Send the bot:
171
173
  Work: /cd · /new · /stop · /send · /seed
172
174
  Goals: /goal · /task
173
175
  Sessions: /status · /sessions · /resume
174
- Models: /models · /model · /prices
175
- Extensions: /skills · /plugins · /plugin · /soul
176
+ Models: /model · /model <id> · /prices
177
+ Profiles: /profile · /profile <name> · /profile new <name> from <template>
178
+ Extensions: /skills · /plugins · /soul
176
179
  Diagnostics: /doctor · /logs [errors|N|text]
177
180
  Service: /app · /restart · /help
181
+ Display: /lang · /reasoning on|off
178
182
  ```
179
183
 
180
184
  ## How it works
@@ -200,6 +204,35 @@ plugin hands it to the live agent on its next step, and the agent immediately re
200
204
  line in the chat: what it is doing now and where it put the addition. If the agent stays silent
201
205
  for 90 seconds, the bridge writes one neutral line itself so there is no silence.
202
206
 
207
+ Attachments work the same way. A voice note is transcribed first and its transcript is echoed in
208
+ the chat, then the text is steered into the running turn; a photo or a file is downloaded to a
209
+ local path and that path is steered, exactly as an idle turn would hand it over.
210
+
211
+ What each kind of attachment becomes inside a running turn:
212
+
213
+ | Sent | Inside the turn |
214
+ |---|---|
215
+ | voice note, audio file, audio sent as a document | transcript, echoed as `🎤 …` before the steer |
216
+ | small text file (`.md`, `.json`, `.csv`, `.py`, `.log`, … up to 60 KB) | the content itself between `<file>` markers — no tool call needed |
217
+ | PDF, archive, binary, anything bigger | its local path under `~/.dsh/tg-bridge/inbox/` |
218
+ | video, video note, animation | its path; the agent can pull frames or sound out with ffmpeg |
219
+ | photo | its path plus one honest line; the turn reads it with `read_image`, and says so in one line if it cannot |
220
+
221
+ A caption does not turn the attachment into a text-only message: it is folded into the same
222
+ hand-over, so "why did this fail" plus a `.log` file arrives as one steer.
223
+
224
+ An album is one request, not ten. Telegram delivers it as one update per file, all sharing a
225
+ `media_group_id`; the bridge collects the group (1.2 s of quiet after the last item, at most
226
+ 4 s) and hands it over once — one steer into a running turn, one turn when the topic is idle.
227
+
228
+ ### When a turn hits the time ceiling
229
+
230
+ `turnTimeoutMs` (default 30 min, this install 75) is a ceiling, not a target: if a turn reaches
231
+ it, the bridge stops it with `⏱` instead of letting one runaway loop own the topic for hours.
232
+ Nothing is lost — the session and every file the turn produced stay in place — so the message
233
+ carries **⏵ Continue**, which asks the agent to check the state and go on from where it stopped.
234
+ That is deliberately not the same as **Retry**, which would redo the whole task from the start.
235
+
203
236
  This needs the plugin from this repository:
204
237
 
205
238
  ```bash
@@ -231,6 +264,30 @@ message shows the last two as `💭` lines. The command needs no ids: it falls b
231
264
  newest turn's thought file, because tool shells do not inherit the bridge environment.
232
265
  `--thought` never sends a Telegram message on its own.
233
266
 
267
+ `/reasoning` is the switch for the whole mechanism. It is on by default: every turn carries a
268
+ short instruction to leave one line at each decision point (task clear, cause found, risky
269
+ change, result checked). `/reasoning off` drops the instruction and the `💭` lines for that
270
+ topic — useful when the step list is all you want. The setting lives in `state.json` per topic,
271
+ so a chatty research topic and a terse deploy topic can differ.
272
+
273
+ ### Profiles per topic
274
+
275
+ The desktop app lets you build several profiles for different kinds of work, each with its own
276
+ plugin set and model. The same switch works from a topic:
277
+
278
+ ```
279
+ /profile current profile, available ones, hints
280
+ /profile research run this topic's turns on another profile
281
+ /profile new research from web
282
+ create a profile from a shipped template and bind it
283
+ /profile default back to the install default
284
+ ```
285
+
286
+ A new profile is written by `dsh <name> --from-default-profile <template> --dump-config`, so
287
+ nothing boots and no plugin is loaded at creation time; dependencies are installed by the
288
+ profile's first turn. The binding is per topic: `/model` then edits that profile's model, and
289
+ `/plugins` manages that profile's rows.
290
+
234
291
  ### Goals and tasks
235
292
 
236
293
  A topic carries its own goal and checklist, so the aim survives `/new`, a
package/albums.mjs ADDED
@@ -0,0 +1,37 @@
1
+ // Album batching.
2
+ //
3
+ // Telegram delivers an album as one update per file, a few hundred ms apart,
4
+ // all sharing a `media_group_id`. Buffering them by that id turns "ten photos"
5
+ // into one hand-over instead of ten steers or ten turns.
6
+ //
7
+ // The wait is quiet-based: it restarts with each new item so a slow upload is
8
+ // not cut off, and it is capped by `maxMs` so one stuck item cannot hold the
9
+ // batch forever.
10
+
11
+ export function createAlbumBuffer({ quietMs = 1200, maxMs = 4000, onFlush } = {}) {
12
+ if (typeof onFlush !== 'function') throw new Error('createAlbumBuffer needs onFlush');
13
+ const groups = new Map();
14
+
15
+ return {
16
+ /** Add one item to its group; returns how long until the group flushes. */
17
+ push(key, item, now = Date.now()) {
18
+ const entry = groups.get(key) || { items: [], timer: null, started: now };
19
+ entry.items.push(item);
20
+ if (entry.timer) clearTimeout(entry.timer);
21
+ const left = maxMs - (now - entry.started);
22
+ const wait = Math.max(0, Math.min(quietMs, left));
23
+ entry.timer = setTimeout(() => {
24
+ if (groups.get(key) === entry) groups.delete(key);
25
+ onFlush(entry.items, key);
26
+ }, wait);
27
+ entry.timer.unref?.();
28
+ groups.set(key, entry);
29
+ return wait;
30
+ },
31
+
32
+ /** Groups still collecting; 0 means nothing is pending. */
33
+ pending() {
34
+ return groups.size;
35
+ },
36
+ };
37
+ }
package/bot-menu.mjs CHANGED
@@ -38,19 +38,20 @@ const COMMANDS = [
38
38
  { command: 'seed', description: 'Засеять пустую тему текстом и закрепить' },
39
39
  { command: 'goal', description: 'Цель темы: /goal <текст>, /goal done' },
40
40
  { command: 'task', description: 'Задачи: /task <текст>, /task done <n>' },
41
- { command: 'sessions', description: 'Последние сессии' },
42
- { command: 'resume', description: 'Продолжить сессию по id' },
43
- { command: 'models', description: 'Список моделей' },
44
- { command: 'model', description: 'Сменить модель: /model <id>' },
41
+ { command: 'sessions', description: 'Список сессий темы' },
42
+ { command: 'resume', description: 'Продолжить сессию: /resume <id>' },
43
+ { command: 'model', description: 'Показать или сменить: /model, /model <id>' },
45
44
  { command: 'skills', description: 'Скиллы: список или текст одного' },
46
45
  { command: 'soul', description: 'Персона: показать или задать' },
47
46
  { command: 'plugins', description: 'Список и управление: add/remove/disable/enable' },
48
- { command: 'app', description: 'Перезапуск приложения: /app restart confirm' },
47
+ { command: 'app', description: 'Приложение DSH, не мост: /app restart confirm' },
49
48
  { command: 'restart', description: 'Перезапуск моста: /restart confirm' },
50
49
  { command: 'doctor', description: 'Диагностика: мост, сеть, диск, каталог, сессия' },
51
50
  { command: 'logs', description: 'Хвост лога моста: /logs 50 или /logs TG_NET' },
52
51
  { command: 'help', description: 'Все команды и подсказки' },
53
52
  { command: 'lang', description: 'Язык интерфейса: en, ru, zh' },
53
+ { command: 'reasoning', description: 'Заметки по ходу: /reasoning on|off' },
54
+ { command: 'profile', description: 'Профиль темы: /profile <имя>, /profile new' },
54
55
  ];
55
56
 
56
57
  /** English menu (language_code: en). Same commands, translated descriptions. */
@@ -64,19 +65,20 @@ const COMMANDS_EN = [
64
65
  { command: 'seed', description: 'Seed an empty topic with text and pin it' },
65
66
  { command: 'goal', description: 'Topic goal: /goal <text>, /goal done' },
66
67
  { command: 'task', description: 'Checklist: /task <text>, /task done <n>' },
67
- { command: 'sessions', description: 'Recent sessions' },
68
- { command: 'resume', description: 'Continue a session by id' },
69
- { command: 'models', description: 'Available models' },
70
- { command: 'model', description: 'Show or switch the model' },
68
+ { command: 'sessions', description: 'This topic\u2019s sessions' },
69
+ { command: 'resume', description: 'Continue a session: /resume <id>' },
70
+ { command: 'model', description: 'Show or switch: /model, /model <id>' },
71
71
  { command: 'skills', description: 'Installed skills' },
72
72
  { command: 'soul', description: 'Agent persona' },
73
73
  { command: 'plugins', description: 'List and manage: add/remove/disable/enable' },
74
- { command: 'app', description: 'Desktop app control' },
74
+ { command: 'app', description: 'DSH desktop app (not the bridge)' },
75
75
  { command: 'restart', description: 'Restart the bridge: /restart confirm' },
76
76
  { command: 'doctor', description: 'Diagnostics: bridge, network, disk, directory, session' },
77
77
  { command: 'logs', description: 'Bridge log tail: /logs 50 or /logs TG_NET' },
78
78
  { command: 'help', description: 'All commands and hints' },
79
79
  { command: 'lang', description: 'Interface language: en, ru, zh' },
80
+ { command: 'reasoning', description: 'Working notes: /reasoning on|off' },
81
+ { command: 'profile', description: 'Topic profile: /profile <name>, /profile new' },
80
82
  ];
81
83
 
82
84
  /** Chinese menu (language_code: zh-hans). */
@@ -90,19 +92,20 @@ const COMMANDS_ZH = [
90
92
  { command: 'seed', description: '用文本初始化空话题并置顶' },
91
93
  { command: 'goal', description: '本话题目标:/goal <文本>、/goal done' },
92
94
  { command: 'task', description: '任务清单:/task <文本>、/task done <n>' },
93
- { command: 'sessions', description: '最近的会话' },
94
- { command: 'resume', description: '按 id 继续会话' },
95
- { command: 'models', description: '可用模型' },
96
- { command: 'model', description: '查看或切换模型' },
95
+ { command: 'sessions', description: '本主题的会话列表' },
96
+ { command: 'resume', description: '继续会话:/resume <id>' },
97
+ { command: 'model', description: '查看或切换:/model, /model <id>' },
97
98
  { command: 'skills', description: '已安装的技能' },
98
99
  { command: 'soul', description: '代理人格设定' },
99
100
  { command: 'plugins', description: '列表与管理:add/remove/disable/enable' },
100
- { command: 'app', description: '桌面应用控制' },
101
+ { command: 'app', description: 'DSH 桌面应用(不是桥接)' },
101
102
  { command: 'restart', description: '重启桥接:/restart confirm' },
102
103
  { command: 'doctor', description: '诊断:桥接、网络、磁盘、目录、会话' },
103
104
  { command: 'logs', description: '桥接日志:/logs 50 或 /logs TG_NET' },
104
105
  { command: 'help', description: '全部命令与提示' },
105
106
  { command: 'lang', description: '界面语言:en、ru、zh' },
107
+ { command: 'reasoning', description: '工作记录:/reasoning on|off' },
108
+ { command: 'profile', description: '话题配置档:/profile <名称>,/profile new' },
106
109
  ];
107
110
 
108
111
  async function api(method, body) {