dsh-tg-bridge 1.32.0 → 1.33.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
@@ -1,635 +1,657 @@
1
- # dsh-tg-bridge
2
-
3
- A Telegram bridge for [DeepSeek Harness](https://deepseek.com): drive the agent from a
4
- bot with text, voice and photos, without opening the desktop app.
5
-
6
- Each forum topic is a separate project with its own session and its own working
7
- directory. Replies arrive with progress, a "Stop" button and copyable code
8
- blocks.
9
-
10
- Never made a bot? [QUICKSTART.md](QUICKSTART.md) takes you from "no account" to
11
- a bot that answers, one step at a time.
12
-
13
- ## Features
14
-
15
- - **Text**: a regular task goes to the agent, the answer comes back in the same topic.
16
- - **Voice**: local faster-whisper, the transcript is shown before the answer.
17
- - **Photos**: the turn's own model reads them through `read_image`, text and UI
18
- included; no second model is needed (a vision overlay stays opt-in).
19
- - **Project per topic**: `/cd my-app`, and all turns run from that directory — on
20
- a permission-enabled profile the sandbox is narrowed to it too, so the agent
21
- cannot write outside the project.
22
- - **Goal and checklist per topic**: `/goal`, `/tasks`; both survive restarts and are prepended to every turn.
23
- - **`/diff` — review the turn, one hunk at a time.** The working tree is split into
24
- files and hunks; every hunk gets two buttons: explain it, or revert just that
25
- hunk. A button carries a hash of the hunk it was drawn from, so a press that
26
- arrives after the file moved on is refused instead of touching a line nobody was
27
- looking at. `/diff stat` is the file list alone.
28
- - **Live progress**: one edited message per turn — steps, a timer and the cache hit rate, plus
29
- the model's reasoning in a collapsed block you can tap open. A long turn adds a second
30
- collapsed block with every tool call, so the whole run stays in the chat as one message.
31
- - **No lost messages**: a journal with acknowledgement and replay.
32
- - **Knows how busy the computer is**: `/load` shows free space on the topic's disk,
33
- free RAM and average CPU, plus how many turns are running and waiting. `/load on`
34
- makes a prompt wait instead of starting while the machine is over a limit you set
35
- — kept, never refused, and one press sends it anyway.
36
- - **Settings per topic**: `/crew use reviewer` gives one topic its own model,
37
- effort, permissions, agent preset and language while the others keep the profile;
38
- `/crew off` returns it. Four built-in sets ship read-only and can be copied.
39
- - **Fail-fast**: when the quota runs out it switches to a free model right away.
40
- - **`dsh-tg check`**: diagnostics in one command, no changes to the system.
41
- - **Languages**: menus and service messages in `en`, `ru`, `zh`; `/lang` pins the topic language, and without it a new topic takes the language of the message itself (Cyrillic → `ru`, Han characters → `zh`), then the Telegram `language_code`, then `en`.
42
- - **"Stop"/"Retry" buttons, tool confirmations**: right in the message, no commands to type.
43
- - **`/report`**: one command turns "it broke" into a redacted document — version,
44
- profile, preset, model, directory, the last failure and the log tail, with
45
- tokens, keys and home paths removed before the file is written.
46
-
47
- ## Requirements
48
-
49
- - Node.js ≥ 24 (the version DeepSeek Harness ships; sessions are zstd-compressed)
50
- - DeepSeek Harness `0.2.1-rc.2` or newer in the `0.2.x` line (`>=0.2.1-rc.2 <0.3.0`)
51
- - DeepSeek Harness installed (`~/.dsh/profiles/headless`)
52
- - A Telegram bot token from [@BotFather](https://t.me/BotFather)
53
-
54
- The supported harness range is declared in `engines.dsh`; that field decides
55
- compatibility on its own (DSH ignores `peerDependencies` when it is present).
56
- The range includes an explicit prerelease branch, because a plain `<0.3.0`
57
- silently excludes `0.2.2-*` builds. A future `0.3.0` needs an explicit bump:
58
- the bridge relies on the `0.2.x` CLI flags and profile layout.
59
-
60
- ## Ecosystem
61
-
62
- The Chinese DSH community maintains the largest plugin catalogs and the
63
- in-app markets that read them; this bridge follows their packaging rules so it
64
- can be listed next to them:
65
-
66
- - [awesome-dsh-plugin](https://awesome-dsh-plugin.com) — bilingual (English /
67
- 中文) plugin list and the `dsh-plugin-catalog` npm package
68
- - [dsh-market](https://github.com/dsh-market/dsh-market) — the Chinese-built
69
- in-app market with one-click install and themes
70
- - [dsh-find-plugin](https://github.com/awesome-dsh-plugin/dsh-find-plugin) —
71
- finds a plugin from chat instead of browsing a catalog
72
-
73
- ## Languages
74
-
75
- - Menus (`/` in chat): three sets, `ru` by default, plus `en` and `zh`; a client whose locale matches neither gets the Russian set.
76
- - Topic language: `/lang en|ru|zh`; stored in `state.json` and survives a restart.
77
- - A new user gets the language from the Telegram `language_code`; anything that is not `ru`/`zh` → `en`.
78
- - Translated so far: menus, the start message, turn status, errors, `/cd`, `/new`, `/stop`, `/lang`,
79
- the reply to an unknown command. Long reports (`/status`, `/sessions`, `/model` and similar)
80
- are still in Russian, that is the next pass.
81
-
82
- ## Installation
83
-
84
- One command: your bot token and your numeric id. Nothing to edit by hand.
85
-
86
- **Windows, macOS or Linux — Node.js 24 or newer.** `init` and the bridge run
87
- anywhere; `setup` (stop, autostart, restart) is **Windows-only** today, so on
88
- macOS and Linux use `sh install.sh`, which registers `launchd` or `systemd --user`.
89
- `node setup.mjs --check` reports state on every platform.
90
-
91
- ```bash
92
- npx dsh-tg-bridge@latest init --token 123456789:AA... --user 123456789
93
- npx dsh-tg-bridge@latest setup
94
- ```
95
-
96
- `init` writes the token, your id and the working directory; `setup` registers
97
- autostart and starts the bridge.
98
-
99
- ### What it needs from DSH
100
-
101
- The bridge is a client of the DSH CLI, and the surface it uses is small enough to
102
- write down: `--profile`, `--json`, `--session-id`, `--expose-internals <cli.js>`
103
- when the app binary runs the CLI, and the `{"type": ...}` JSON events on stdout.
104
- Profiles are read as files (`cordis.patch.yml`, `package.json`) under
105
- `~/.dsh/profiles`. `package.json` spells the supported range out in
106
- `engines.dsh`, and it is capped below `0.3.0` on purpose: a minor bump may rename
107
- an event, and a bridge that guesses is a bridge that answers with silence.
108
-
109
- Two escape hatches, for a moved app or a DSH that ships differently:
110
-
111
- ```bash
112
- DSH_BIN=/usr/local/bin/dsh # the CLI itself, no entrypoint argument
113
- DSH_CLI_JS=/opt/dsh/lib/cli.js # just the CLI entrypoint, run by DSH_BIN
114
- DSH_APP_DIR=/opt/DeepSeek-Harness # where the desktop app is installed
115
- ```
116
-
117
- `/doctor` prints the command a turn would actually run, so a machine where these
118
- matter says so instead of failing with an empty answer.
119
-
120
- **As a DSH plugin** (the package carries a `dsh.bundle`; the catalog entry is
121
- pending review):
122
-
123
- ```bash
124
- dsh plugin --profile desktop add dsh-tg-bridge
125
- ```
126
-
127
- The plugin starts one bridge when DSH boots and stops it on shutdown; if a
128
- bridge is already running (for example from the scheduled task), it leaves it
129
- alone. Run `npx dsh-tg-bridge@latest init ...` first so a config exists.
130
-
131
- What `init` does:
132
-
133
- | What | Where |
134
- |---|---|
135
- | bot token | `~/.dsh/.credentials.yaml` → `refs.DSH_TELEGRAM_BOT_TOKEN`; other keys are left alone |
136
- | your id and working directory | `~/.dsh/tg-bridge/config.json`; an existing file is not overwritten |
137
- | `headless` profile | checked, with a hint on how to create it if missing |
138
-
139
- `init` flags: `--cwd <path>` (default `~/Projects`), `--voice` (enable
140
- voice transcription), `--dry-run` (show what would be written, change nothing).
141
-
142
- Optional provider settings live in `config.json`:
143
-
144
- | Key | Meaning |
145
- |---|---|
146
- | `providerKeys` | extra env var names to pass to a turn, read from `~/.dsh/.credentials.yaml`; default `[]` |
147
- | `pricesUrl` | retired: `/prices` always reads OpenRouter's public list and labels the number as a reference for the model |
148
- | `vision.patch` | opt-in overlay profile for photo turns; default `""` — the turn's own model reads images |
149
- | `vision.enabled` | set `true` to run photo turns on `vision.patch` instead of the topic profile |
150
- | `fallbackModels` | ordered failover chain; default `[]` — see below |
151
- | `fallbackEnabled` | `false` switches the whole chain off without editing the list; `/fallback off` sets it |
152
- | `maxParallel` | how many topics run at once, 1–8, default `3`; also `/jobs 5` in the chat |
153
- | `replayWindowMs` | how old a journaled update may be and still be replayed after a restart; default `600000` (10 min) |
154
-
155
- Each `fallbackModels` entry is one attempt, tried in order after the turn's own
156
- model refuses:
157
-
158
- ```json
159
- {
160
- "provider": "router-a",
161
- "model": "some-model",
162
- "patch": "~/.dsh/tg-bridge/model-a.yml",
163
- "free": false,
164
- "off": false
165
- }
166
- ```
167
-
168
- `patch` is an overlay file with a single `agent-default-model` row
169
- (`provider` + `model`); it is materialised once as its own profile, so the turn
170
- keeps every other setting and only the model changes. `provider` is the id the
171
- provider is written under in the profile — it decides whose key and host the
172
- pre-flight probe asks, so the same model id on two routers stays two attempts.
173
- `free` only adds `(free)` to the switch notice. `off` keeps an entry in the list
174
- but out of the walk; an entry whose `patch` file is missing is skipped the same
175
- way, and the chat says so instead of counting it.
176
-
177
- The chain may mix companies: a 503 from one provider says nothing about another,
178
- so a busy channel skips its own models and the next company is still tried. Put
179
- models from different companies next to each other — two arms of one router are
180
- one outage, not two chances — and keep the `:free` models at the end, as the
181
- last resort.
182
-
183
- **What starts a switch.** Anything the provider itself says no to: a 400/413/422
184
- refusal (its own validator rejecting the request), 401/403 (key refused), 402 or
185
- a quota/balance message (empty account), 404 (that model id is not carried),
186
- 429 (rate limit), 5xx and `get_channel_failed` / "all providers busy" (the pool
187
- is down), a dropped connection or DNS/TLS failure, and an empty answer. A refusal
188
- gets one other route, not the whole chain: it is replayed in full, and if the
189
- second vendor refuses identically the request — not the route — is what is wrong,
190
- so the reply says to start a fresh session with `/new`.
191
-
192
- **What does not start a switch.** The turn time cap, `/stop`, a session or
193
- directory error, a missing `dsh` binary: no other vendor changes those, and a
194
- replay would cost a full turn to learn the same thing. They are listed in the
195
- card so the distinction is visible instead of guessed.
196
-
197
- ### `/fallback` — the chain from the chat
198
-
199
- ```
200
- /fallback the card: chain state, numbered routes, what starts a switch
201
- /fallback on | off the whole chain (per route: /fallback off 3)
202
- /fallback use 3 | skip 3 one route back in or out
203
- /fallback up 3 | down 3 move a route in the order
204
- /fallback test [3] ask each route (or one) with a 1-token request
205
- /fallback add <provider>/<model> write an overlay and append the route
206
- /fallback first <provider>/<model> put it at the head: tried before every other route
207
- /fallback remove 3 drop a route from the list (its overlay file stays)
208
- ```
209
-
210
- Every line has a button on the card: `● n` switches a route, `↑ n` / `↓ n` move
211
- it, and the card redraws in place after each press. `test` proves the key and the
212
- channel are alive — not that the provider accepts this conversation, so a route
213
- can answer `ping` and still refuse a long prompt with a 400. The card says that
214
- in as many words.
215
-
216
- `test` also times each route: how long it takes to produce the first token, and
217
- which live route is fastest right now. Two routes that both answer are not
218
- equally good — 400 ms and 9 s feel like different products — and the head of the
219
- chain is the one a person picks on that number. A route that did not answer
220
- prints no time, so `no balance · 120 ms` can never read as "works, just slow".
221
-
222
- `first` exists because `add` appends: when the route you want should answer
223
- *before* the primary, appending it means moving it up eight times and guessing
224
- where the head is. `/fallback first router-a/deepseek-v4.1-flash` writes the
225
- same overlay and puts it at position 1 — or moves it there if it is already in
226
- the chain.
227
-
228
- Get your id from [@userinfobot](https://t.me/userinfobot), the token from
229
- [@BotFather](https://t.me/BotFather).
230
-
231
- ### Bot settings in Telegram
232
-
233
- Three things without which the bot will stay silent in a group or work only halfway:
234
-
235
- 1. **Privacy mode → Disable** (`/setprivacy` in BotFather). Otherwise the bot sees
236
- only commands, not regular text in a topic.
237
- 2. **Topics enabled** in the group settings (Edit → Topics). Without them all work
238
- goes to a single chat and per-topic sessions are not created.
239
- 3. **Pin Messages** permission for the bot. Only needed to pin the first
240
- message of a topic; without it the bridge keeps working but will not pin.
241
-
242
- You do not need to set up the command menu by hand: `init` and `setup` install it
243
- in Russian, English and Chinese at once. The menu is not refreshed by a plain
244
- bridge restart, so after adding commands run `dsh-tg menu`. The full settings
245
- table, permissions, checks and common errors are in
246
- [docs/TELEGRAM-SETUP.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/TELEGRAM-SETUP.md).
247
-
248
- **Autostart** has two routes. `sh install.sh` writes `launchd` on macOS and
249
- `systemd --user` on Linux; `dsh-tg setup` registers the `DSH-TG-Bridge` task on
250
- Windows, which runs the guarded supervisor (the same launcher on logon and every
251
- five minutes) so a crashed bridge comes back without a second poller. On macOS
252
- and Linux `setup` declines and names `install.sh`, because it stops the old
253
- bridge with `taskkill` and registers autostart through `schtasks`.
254
-
255
- **Manual install** (if you want full control):
256
-
257
- ```bash
258
- npm install -g dsh-tg-bridge
259
- dsh-tg init --token 123456789:AA... --user 123456789
260
- dsh-tg check # report only, changes nothing
261
- dsh-tg setup # stop the old bridge and start the new one
262
- ```
263
-
264
- If the bridge is already installed, `setup` restarts it on the new code and reinstalls
265
- the command menu.
266
-
267
- ## Troubleshooting
268
-
269
- Starting from nothing, or helping someone who is: [QUICKSTART.md](QUICKSTART.md)
270
- has the same answers with the terminal output they will actually see.
271
-
272
- Error replies end with a code, which tells you what to fix:
273
-
274
- | Code | Meaning |
275
- |---|---|
276
- | `INSUFFICIENT_QUOTA` | provider balance is empty: top up or stay on free models (`/prices`, `/model`) |
277
- | `TG_CONFLICT` | a second process is polling the same bot: `/doctor`, then `/restart` |
278
- | `MISSING_CREDENTIAL` | no provider key in the profile: add it in the DSH app |
279
- | `NO_DSH_CLI` | DeepSeek Harness CLI not found: check the app installation |
280
- | `NETWORK` | no network to the provider: retry, check VPN/DNS |
281
- | `SANDBOX_DENY` | DSH denied access to a file or directory: check the project path and permissions |
282
- | `UNKNOWN_MODEL` | the model from the config is unavailable: `/model` lists the working ones |
283
- | `EMPTY_RESPONSE` | the model returned nothing: retry or switch model (`/model`) |
284
- | `TURN_TIME_CAP` | the turn hit its own time ceiling: the work is saved, press Continue |
285
- | `TURN_FAILED` | cause not recognized: `/doctor` and `/logs errors` |
286
-
287
- ## Checks
288
-
289
- Send the bot:
290
-
291
- | Command | Expected |
292
- |---|---|
293
- | `/doctor` | report: pid, Telegram, disk, directory, session |
294
- | `/update` | which bridge runs, what npm has, and whether a newer release exists (`/update confirm` installs it) |
295
- | `/thoughts [file\|all\|off]` | the last turn's reasoning as a message; `file`/`all` send the full log as a Markdown document, `off` hides the block |
296
- | `/help` | commands grouped by category |
297
- | `/cd my-app` | topic bound to the project, and the sandbox narrowed to it |
298
- | `/diff [stat]` | what the turn changed, one hunk at a time: every hunk has "explain" and "revert this hunk"; a stale button is refused |
299
- | `/report` | a redacted bundle (version, profile, preset, model, cwd, last failure, log tail) sent to the owner as a document; in a group, the path only |
300
- | `/prices` | what the current model costs, and whose price that is: your provider's, the same model on another gateway, or "no public price" when nobody publishes one |
301
-
302
- ## Commands
303
-
304
- ```
305
- Work: /cd · /new · /stop · /send · /seed · /diff
306
- Goals: /goal (plan + checklist) · /goal reopen · /tasks (checklist only) · /tasks done|rm|edit <n>
307
- Sessions: /status · /sessions · /sessions <id> · /rewind [n|undo|fork [n]|branches]
308
- Agents: /agents · /agents <id> · /agents set model|depth|filter
309
- Models: /model · /model <id> · /prices
310
- Tuning: /effort · /permissions · /preset · /plan · /jobs · /remind
311
- Profiles: /profile · /profile <name> · /profile new <name> from <template>
312
- Sets: /crew · /crew use|off|new|copy|rm · /crew model <v>
313
- Extensions: /skills · /plugins · /plugins search <word> · /plugins disable|enable <id> · /soul
314
- Updates: /update · /update confirm · /update on|off|check|auto · /subscribe on|off
315
- Diagnostics: /doctor · /logs [errors|N|text] · /report
316
- Service: /app · /restart · /help
317
- Machine: /load · /load on|off · /load limit cpu|ram|disk <n>
318
- Settings: /settings — the same switches as buttons, grouped in four tabs
319
- Display: /lang · /reasoning off|card|chat · /pin on|off · /thoughts
320
- ```
321
-
322
- ### Settings as a card
323
-
324
- `/settings` draws the same switches that the commands set, in one message with
325
- four tabs: what the bot says, who answers and how hard it works, new releases,
326
- and the health checks. Each row shows what the setting is now and what a tap
327
- would change it to. A tap runs the command a person would have typed
328
- (`/reasoning chat`, `/update on`), so the card cannot disagree with the command:
329
- it is a view of them.
330
-
331
- The card stays after a tap. It is edited in place — same message, same buttons,
332
- the value in force marked with `●` and one `✓ row: value` line saying what just
333
- changed — so a second setting is one more tap instead of a second `/settings`.
334
- `✓ Done` removes the card when you are finished with it; nothing else deletes it.
335
-
336
- `📌 Pin the progress card` (`/pin on`) keeps the running card pinned, so the
337
- clock, the speed and the step list are one tap away instead of a scroll. Telegram
338
- gives a chat one pinned message, so each turn's card replaces the last one. Off by
339
- default: a bot that pins without being asked takes that slot in someone else's
340
- chat, and a group needs the right to pin at all.
341
-
342
- Nothing on the card is only available on the card. `/settings` is for people who
343
- would rather press a labelled button than remember which of `/effort`,
344
- `/preset` and `/crew` changes what.
345
-
346
- Every command answers `/help` in the chat, in the language you write in: a
347
- message written in Cyrillic or Han characters switches the topic to Russian or
348
- Chinese even when the phone's menu is set to another language, and `/lang`
349
- pins a choice above that. The Telegram menu shows the same list, minus
350
- `/subscribe`: it is one line, and a person who turns it off should not have to
351
- find it in a menu again.
352
-
353
- ## Updates
354
-
355
- The npm tag `latest` is a label, not an updater: installing a package pins the
356
- version on disk, and nothing moves until something moves it. Two switches, both
357
- about this install (not about a topic, because it is the install that updates):
358
-
359
- | Command | What it does |
360
- |---|---|
361
- | `/update` | one line: what runs here, what is published, which switches are set |
362
- | `/update on` | tell me about new releases: one message per version, checked once a day |
363
- | `/update off` | stop telling me; nothing installs, nothing moves |
364
- | `/update auto` | besides telling me, install the release by itself (checked hourly) |
365
- | `/update confirm` | install the new release now, by hand |
366
-
367
- Nothing above installs except `confirm` and `auto`, and even those only change the
368
- files: the running process keeps its old modules until `/restart confirm`, so a
369
- bad release never lands mid-chat. `confirm` and `auto` copy the replaced files to
370
- `update-backup-<date>` and print the path; copying that folder back is the way to
371
- roll back, with no state to undo.
372
-
373
- `/subscribe on|off` says the same thing as `/update on|off`, for people who do not
374
- want to read `/update` first. It is not in the Telegram menu on purpose.
375
-
376
- There are no notices about failures. The bridge cannot decide what counts as one
377
- for you, and "something failed" that nobody can act on is noise; errors stay in
378
- the chat where they happened, under `/doctor` and `/logs errors`.
379
-
380
- ## How it works
381
-
382
- ```
383
- Telegram → bridge.mjs → dsh --profile headless --json → reply
384
- │
385
- ├─ pending/ journal + ack (messages are not lost)
386
- ├─ per-topic queue (turns in topics run in parallel)
387
- ├─ progress + buttons (you can see the work is going)
388
- └─ fail-fast on quota (free models as a fallback)
389
- ```
390
-
391
- The bridge is a single process with long polling. Each turn spawns a separate
392
- CLI process that exits after the answer, so "no DSH process" between
393
- turns is normal, not a failure.
394
-
395
- ### Steering during a turn
396
-
397
- If you write in a topic while a turn is still running, the message does not queue
398
- behind it: the bridge drops the task into `~/.dsh/tg-bridge/steer/`, the `dsh-steer-inbox`
399
- plugin hands it to the live agent on its next step, and the agent immediately replies with a short
400
- line in the chat: what it is doing now and where it put the addition. If the agent stays silent
401
- for 90 seconds, the bridge writes one neutral line itself so there is no silence.
402
-
403
- Attachments work the same way. A voice note is transcribed first and its transcript is echoed in
404
- the chat, then the text is steered into the running turn; a photo or a file is downloaded to a
405
- local path and that path is steered, exactly as an idle turn would hand it over.
406
-
407
- What each kind of attachment becomes inside a running turn:
408
-
409
- | Sent | Inside the turn | Needs |
410
- |---|---|---|
411
- | voice note, audio file, audio sent as a document | transcript, echoed as `🎤 …` before the steer | `faster-whisper` on `PATH`, enabled with `init --voice`; **off by default** |
412
- | small text file (`.md`, `.json`, `.csv`, `.py`, `.log`, … up to 60 KB) | the content itself between `<file>` markers — no tool call needed | nothing |
413
- | PDF, archive, binary, anything bigger | its local path under `~/.dsh/tg-bridge/inbox/` | nothing; the agent opens it with its own tools |
414
- | video, video note, animation | its path; the agent can pull frames or sound out with ffmpeg | ffmpeg, only if frames or audio are needed |
415
- | photo | its path plus one honest line; the turn reads it with `read_image`, and says so in one line if it cannot | a model that accepts images |
416
-
417
- Voice is the one row with a hidden prerequisite. Without `faster-whisper`
418
- installed, a voice note still arrives — as a path the agent cannot read — so the
419
- bridge says transcription is off instead of pretending it heard something. Run
420
- `dsh-tg init --voice` after installing the transcriber; nothing else changes.
421
-
422
- A caption does not turn the attachment into a text-only message: it is folded into the same
423
- hand-over, so "why did this fail" plus a `.log` file arrives as one steer.
424
-
425
- An album is one request, not ten. Telegram delivers it as one update per file, all sharing a
426
- `media_group_id`; the bridge collects the group (1.2 s of quiet after the last item, at most
427
- 4 s) and hands it over once — one steer into a running turn, one turn when the topic is idle.
428
-
429
- ### When a turn hits the time ceiling
430
-
431
- `turnTimeoutMs` (default 30 min, this install 75) is a ceiling, not a target: if a turn reaches
432
- it, the bridge stops it with `⏱` instead of letting one runaway loop own the topic for hours.
433
- Nothing is lost — the session and every file the turn produced stay in place — so the message
434
- carries **⏵ Continue**, which asks the agent to check the state and go on from where it stopped.
435
- That is deliberately not the same as **Retry**, which would redo the whole task from the start.
436
-
437
- This needs the plugin from this repository:
438
-
439
- ```bash
440
- dsh plugin --profile headless add link:<path-to-repository>/plugin/steer-inbox
441
- ```
442
-
443
- and a line in `~/.dsh/profiles/headless/cordis.patch.yml`:
444
-
445
- ```yaml
446
- - insert:
447
- - id: steer-inbox
448
- name: 'dsh-steer-inbox'
449
- ```
450
-
451
- The bridge checks the profile itself: if the line is missing, it does not write the task
452
- (it would just expire) and behaves as before, queueing the message.
453
-
454
- ### Live thoughts and reasoning
455
-
456
- Two things land in the same progress message, and neither sends a chat message of its own.
457
-
458
- **The model's reasoning.** Every `thinking` block the CLI commits is folded into one
459
- Telegram `<blockquote expandable>`: collapsed it is a single line, tapped it opens the whole
460
- trail of the turn, and it stays there after the turn ends — the same way the desktop app shows
461
- a reasoning section you can expand. The block is written once, in the final edit of the turn,
462
- and never touched again: Telegram re-collapses an expanded block on every edit of its message,
463
- which used to yank the chat away from a half-read paragraph. While the turn runs the message
464
- only gets a counter (`🧠 Размышления · 4821`) and the last three steps, so the live edits stay
465
- short. Escaped, and trimmed to its tail when a turn thinks longer than a message can hold; the
466
- panel never exceeds one message. A cut block says `… · начало скрыто · /thoughts file`, which
467
- sends the whole log as a document. If the API refuses the markup, the same content is retried
468
- as plain text.
469
-
470
- **The steps.** Three calls fit inline. A turn that makes more moves its complete step list into
471
- a second collapsed block, added in that same final edit, so "what did it actually run" is one
472
- tap away instead of a count.
473
-
474
- **The agent's own notes.** The agent can add a short decision trail:
475
-
476
- ```bash
477
- node ~/.dsh/tg-bridge/say.mjs --thought "checking why the watchdog fired twice"
478
- ```
479
-
480
- The note is appended to `~/.dsh/tg-bridge/thoughts/<chat>_<thread>.jsonl`; the progress
481
- message shows the last two as `💭` lines. The command needs no ids: it falls back to the
482
- newest turn's thought file, because tool shells do not inherit the bridge environment.
483
- `--thought` sends a Telegram message of its own only in `/reasoning chat` mode.
484
-
485
- A decision the person must know before the turn ends — a release shipped, a cause found,
486
- a blocker — goes to the chat as one plain line instead:
487
-
488
- ```bash
489
- node ~/.dsh/tg-bridge/say.mjs --note "1.10.1 is on npm; restart to load it"
490
- ```
491
-
492
- `--note` sends a real message and takes the same no-ids fallback as `--thought`. The split
493
- is deliberate: `--thought` is the working trail (inside the progress message, and in `chat`
494
- mode also as its own messages), `--note` is the short line that changes what the reader
495
- expects to happen next — useful in `card` and `off` mode, redundant in `chat`. The progress
496
- message itself opens with the request echoed back (`⏳ Принял: «…» · 3 с`), so the first
497
- thing the person sees after sending names their task rather than a generic spinner.
498
-
499
- `/reasoning` is the switch for the 💭 mechanism, and it has three ends:
500
-
501
- - `/reasoning card` (the default) — every turn carries a short instruction to leave one line
502
- at each decision point (task clear, cause found, risky change, result checked), and the
503
- progress message shows the last two;
504
- - `/reasoning chat` — the same lines, each also posted as its own message, so a turn that
505
- runs for twenty minutes is read as it happens instead of scrolled back to afterwards.
506
- The prompt says so explicitly, so a line is written to stand alone;
507
- - `/reasoning off` — drops the instruction and the `💭` lines for that topic, for when the
508
- step list is all you want.
509
-
510
- A topic switched to `chat` mid-turn does not dump the steps already in the card: forwarding
511
- starts with the next line written. The setting lives in `state.json` per topic, so a chatty
512
- research topic and a terse deploy topic can differ; a `true`/`false` written by an older
513
- release still reads as `card`/`off`. The settings card offers the same three ends as buttons.
514
-
515
- The reasoning block itself is model output; `/thoughts` is what reads it back:
516
-
517
- - `/thoughts` — the last turn as a message, in parts, deleted after three minutes;
518
- - `/thoughts file` — the **whole** last turn as `reasoning-<date>-file.md`, sent as a document
519
- (a five-hour turn is tens of thousands of characters, which no chat message can hold);
520
- - `/thoughts all` — every turn of the session in one file (a long session is a couple of MB);
521
- - `/thoughts off` / `on` — keep the block out of the turn panel (the panel then shows
522
- `🧠 Размышления · N · /thoughts file`) or bring it back.
523
-
524
- The log is built from the session file on demand, so nothing is duplicated while a turn runs.
525
- Files land in `~/.dsh/tg-bridge/thoughts/` and older ones are pruned after a week.
526
-
527
- ### Profiles per topic
528
-
529
- The desktop app lets you build several profiles for different kinds of work, each with its own
530
- plugin set and model. The same switch works from a topic:
531
-
532
- ```
533
- /profile current profile, available ones, hints
534
- /profile research run this topic's turns on another profile
535
- /profile new research from web
536
- create a profile from a shipped template and bind it
537
- /profile default back to the install default
538
- ```
539
-
540
- A new profile is written by `dsh <name> --from-default-profile <template> --dump-config`, so
541
- nothing boots and no plugin is loaded at creation time; dependencies are installed by the
542
- profile's first turn. The binding is per topic: `/model` then edits that profile's model, and
543
- `/plugins` manages that profile's rows, and `/plugins search <word>` lists what the npm registry
544
- has with the `dsh-plugin` keyword — the desktop app's plugin browser, from the chat. Each result
545
- carries a plus button that runs `/plugins add <name>`.
546
-
547
- ### The directory a topic writes in
548
-
549
- `/cd my-app` does two things, and they are worth separating because they used to
550
- be one: the turn runs *in* that directory, and the sandbox *stops* at it. The
551
- second half only works on a profile that has a permission table — the bridge
552
- writes the row only when one exists, and never invents one for a profile that
553
- opted out.
554
-
555
- ```
556
- /cd my-app bind the topic: run here, and write only here
557
- /cd ~/Projects/api wide run here, but do not narrow the sandbox
558
- /cd reset unbind; the topic goes back to config.cwd
559
- /cd what this topic is bound to, and how
560
- ```
561
-
562
- | Sandbox mode | Writes inside the root | Writes outside the root |
563
- |---|---|---|
564
- | `read-only` | denied | denied |
565
- | `workspace-write` | allowed | denied |
566
- | `danger-full-access` | allowed | allowed |
567
-
568
- `workspaceRoot` is the boundary, and it holds even when the turn switches its own
569
- working directory: the refusal follows the configured root, not the directory the
570
- agent moved to. That is the point — a model that wanders into another project
571
- gets a refusal instead of a write.
572
-
573
- Three things this table does **not** say, because measurement disagreed with the
574
- obvious reading:
575
-
576
- - the sandbox row alone changes nothing. `mode: read-only` in the
577
- `sandbox-policy` row plus `defaultPreset: danger-full-access` in the permission
578
- table still wrote outside the root. The permission table wins; the sandbox row
579
- is a default for a profile that has no table.
580
- - `danger-full-access` therefore has to be chosen on purpose, per topic
581
- (`/permissions danger-full-access`), and it is the only mode that reaches
582
- outside the root.
583
- - a preset with `approval: ask` cannot be used from a chat at all: a headless
584
- turn has no approval channel, so the escalation fails closed and the turn
585
- errors. `/permissions` lists such a preset with the reason instead of letting
586
- someone pick a trap.
587
-
588
- Stock installs are not permission-enabled: `cordis.patch.yml` ships with the
589
- `tg-bridge` plugin row only, so `/cd` binds the directory and `/permissions`
590
- edits the profile-wide preset, exactly as before. The per-topic behaviour starts
591
- the first time a profile gains a permission table.
592
-
593
- ### Goals and tasks
594
-
595
- A topic carries its own goal and checklist, so the aim survives `/new`, a
596
- restart and a different session:
597
-
598
- ```
599
- /goal ship the release set or replace the goal
600
- /goal show the goal and the checklist
601
- /tasks write the migration add a task
602
- /tasks done 2 tick it off
603
- /tasks edit 2 shorter words rewrite it in place, same number
604
- /tasks rm 2 remove it
605
- /goal reopen open a closed goal again
606
- /goal done close the goal (all tasks done)
607
- /goal clear delete the goal and its tasks
608
- ```
609
-
610
- The bridge prepends the goal and the list to every turn, with the exact command
611
- that updates it (`goal.mjs`). The agent ticks tasks as it finishes them, and the
612
- next turn sees the new state. The bridge is the only writer of `state.json`: the
613
- agent drops a job file into `goal-jobs/` and the bridge applies it, so there is
614
- no lock race and no lost update.
615
-
616
- ## Security
617
-
618
- - `config.json`, `state.json`, `pending/`, logs are in `.gitignore` and never
619
- end up in the repository.
620
- - The token is stored in the DSH credentials store, not in code or config.
621
- - The bridge only replies to ids in `allowedUserIds`.
622
-
623
- ## Documentation
624
-
625
- - [docs/TELEGRAM-SETUP.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/TELEGRAM-SETUP.md): BotFather settings, group and bot permissions
626
- - [docs/SUPPORT.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/SUPPORT.md): what to send with a bug report, what never to send, and the one-line answer for "the bot went silent"
627
- - [docs/ROADMAP.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/ROADMAP.md): what comes next
628
- - [docs/UX-ANALYSIS.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/UX-ANALYSIS.md): interactive UX review
629
- - [docs/COST.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/COST.md): what one turn costs and how to reduce it
630
- - [docs/CHANGELOG.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/CHANGELOG.md): change history
631
- - [docs/RELEASE-CRITERIA.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/RELEASE-CRITERIA.md): release readiness criteria
632
-
633
- ## License
634
-
635
- MIT, see [LICENSE](LICENSE).
1
+ # dsh-tg-bridge
2
+
3
+ Drive [DeepSeek Harness](https://deepseek.com) from Telegram. It runs on the
4
+ machine that already has the harness, and it answers in the chat where you asked.
5
+
6
+ A forum topic is a project: its own session, working directory, model,
7
+ permissions and language. Two topics share the install and nothing else.
8
+
9
+ Never made a bot? [QUICKSTART.md](QUICKSTART.md) goes from "no account" to a bot
10
+ that answers, one step at a time.
11
+
12
+ ## What it does
13
+
14
+ - **A model per topic.** `/model` lists the routes the profile declares — provider
15
+ and model together — and a tap switches this topic only. `/model <route> all`
16
+ moves the default the other topics follow; `/model auto` hands the topic back.
17
+ A chat for thinking out loud and a chat for engineering no longer share one model.
18
+ - **A topic is a project.** `/cd my-app`, and every turn runs from that directory —
19
+ on a permission-enabled profile the sandbox is narrowed to it too, so the agent
20
+ cannot write outside the project.
21
+ - **One edited message per turn.** Steps, a timer and the cache hit rate, plus the
22
+ reasoning in a collapsed block you can tap open. A long turn adds a second
23
+ collapsed block with every tool call. `/stop` is a button on that message.
24
+ - **`/diff` — review the turn, one hunk at a time.** The working tree is split into
25
+ files and hunks; every hunk gets two buttons: explain it, or revert just that
26
+ hunk. A button carries a hash of the hunk it was drawn from, so a press that
27
+ arrives after the file moved on is refused instead of touching a line nobody was
28
+ looking at. `/diff stat` is the file list alone.
29
+ - **An endpoint from the chat.** `/endpoint add <id> <https://url/v1> <KEY_ENV>
30
+ [model,model]` writes the provider without an AI turn, and the key itself is
31
+ never typed — only the name of the variable that holds it. The new models appear
32
+ on `/model` as routes.
33
+ - **Input: text, voice, photos.** Voice is local faster-whisper and the transcript
34
+ is shown before the answer. A photo is read by the turn's own model through
35
+ `read_image`, text and UI included; no second model is needed.
36
+ - **Goal and checklist per topic.** `/goal`, `/tasks`; both survive restarts and
37
+ are prepended to every turn.
38
+ - **Two scopes for every setting.** `/reasoning <mode> all` moves the default,
39
+ without `all` it moves this topic; language and pinning follow the same rule,
40
+ and `/crew use reviewer` gives one topic its own effort, permissions and agent
41
+ preset (four built-in sets, read-only, copyable).
42
+ - **It says what it cost.** A turn reports tokens and the cache hit rate; `/cost`
43
+ says what the session has spent and `/prices` shows the rates it used.
44
+ - **Out of quota is not a dead end.** When the quota runs out it switches to a
45
+ free model right away, and the answer says which route answered.
46
+ - **No lost messages.** A journal with acknowledgement and replay.
47
+ - **Knows how busy the computer is.** `/load` shows free space on the topic's disk,
48
+ free RAM and average CPU, plus how many turns are running and waiting. `/load on`
49
+ makes a prompt wait instead of starting while the machine is over a limit you set
50
+ — kept, never refused, and one press sends it anyway.
51
+ - **Languages.** Menus and service messages in `en`, `ru`, `zh`; `/lang` pins the
52
+ topic language, and without it a new topic takes the language of the message
53
+ itself (Cyrillic → `ru`, Han characters → `zh`), then the Telegram
54
+ `language_code`, then `en`.
55
+ - **"Stop" / "Retry" buttons and tool confirmations** sit in the message, so there
56
+ is no command to type to stop a run.
57
+ - **`/report`.** One command turns "it broke" into a redacted document: version,
58
+ profile, preset, model, directory, the last failure and the log tail, with keys
59
+ and home paths removed before the file is written.
60
+ - **`dsh-tg check`.** Diagnostics in one command, changing nothing on the system.
61
+
62
+ ## Requirements
63
+
64
+ - Node.js ≥ 24 (the version DeepSeek Harness ships; sessions are zstd-compressed)
65
+ - DeepSeek Harness `0.2.1-rc.2` or newer in the `0.2.x` line (`>=0.2.1-rc.2 <0.3.0`)
66
+ - DeepSeek Harness installed (`~/.dsh/profiles/headless`)
67
+ - A Telegram bot token from [@BotFather](https://t.me/BotFather)
68
+
69
+ The supported harness range is declared in `engines.dsh`; that field decides
70
+ compatibility on its own (DSH ignores `peerDependencies` when it is present).
71
+ The range includes an explicit prerelease branch, because a plain `<0.3.0`
72
+ silently excludes `0.2.2-*` builds. A future `0.3.0` needs an explicit bump:
73
+ the bridge relies on the `0.2.x` CLI flags and profile layout.
74
+
75
+ ## Ecosystem
76
+
77
+ The Chinese DSH community maintains the largest plugin catalogs and the
78
+ in-app markets that read them; this bridge follows their packaging rules so it
79
+ can be listed next to them:
80
+
81
+ - [awesome-dsh-plugin](https://awesome-dsh-plugin.com) — bilingual (English /
82
+ 中文) plugin list and the `dsh-plugin-catalog` npm package
83
+ - [dsh-market](https://github.com/dsh-market/dsh-market) — the Chinese-built
84
+ in-app market with one-click install and themes
85
+ - [dsh-find-plugin](https://github.com/awesome-dsh-plugin/dsh-find-plugin) —
86
+ finds a plugin from chat instead of browsing a catalog
87
+
88
+ ## Languages
89
+
90
+ - Menus (`/` in chat): three sets, `ru` by default, plus `en` and `zh`; a client whose locale matches neither gets the Russian set.
91
+ - Topic language: `/lang en|ru|zh`; stored in `state.json` and survives a restart.
92
+ - A new user gets the language from the Telegram `language_code`; anything that is not `ru`/`zh` → `en`.
93
+ - Translated so far: menus, the start message, turn status, errors, `/cd`, `/new`, `/stop`, `/lang`,
94
+ the reply to an unknown command. Long reports (`/status`, `/sessions`, `/model` and similar)
95
+ are still in Russian, that is the next pass.
96
+
97
+ ## Installation
98
+
99
+ One command: your bot token and your numeric id. Nothing to edit by hand.
100
+
101
+ **Windows, macOS or Linux — Node.js 24 or newer.** `init` and the bridge run
102
+ anywhere; `setup` (stop, autostart, restart) is **Windows-only** today, so on
103
+ macOS and Linux use `sh install.sh`, which registers `launchd` or `systemd --user`.
104
+ `node setup.mjs --check` reports state on every platform.
105
+
106
+ ```bash
107
+ npx dsh-tg-bridge@latest init --token 123456789:AA... --user 123456789
108
+ npx dsh-tg-bridge@latest setup
109
+ ```
110
+
111
+ `init` writes the token, your id and the working directory; `setup` registers
112
+ autostart and starts the bridge.
113
+
114
+ ### What it needs from DSH
115
+
116
+ The bridge is a client of the DSH CLI, and the surface it uses is small enough to
117
+ write down: `--profile`, `--json`, `--session-id`, `--expose-internals <cli.js>`
118
+ when the app binary runs the CLI, and the `{"type": ...}` JSON events on stdout.
119
+ Profiles are read as files (`cordis.patch.yml`, `package.json`) under
120
+ `~/.dsh/profiles`. `package.json` spells the supported range out in
121
+ `engines.dsh`, and it is capped below `0.3.0` on purpose: a minor bump may rename
122
+ an event, and a bridge that guesses is a bridge that answers with silence.
123
+
124
+ Two escape hatches, for a moved app or a DSH that ships differently:
125
+
126
+ ```bash
127
+ DSH_BIN=/usr/local/bin/dsh # the CLI itself, no entrypoint argument
128
+ DSH_CLI_JS=/opt/dsh/lib/cli.js # just the CLI entrypoint, run by DSH_BIN
129
+ DSH_APP_DIR=/opt/DeepSeek-Harness # where the desktop app is installed
130
+ ```
131
+
132
+ `/doctor` prints the command a turn would actually run, so a machine where these
133
+ matter says so instead of failing with an empty answer.
134
+
135
+ **As a DSH plugin** (the package carries a `dsh.bundle`; the catalog entry is
136
+ pending review):
137
+
138
+ ```bash
139
+ dsh plugin --profile desktop add dsh-tg-bridge
140
+ ```
141
+
142
+ The plugin starts one bridge when DSH boots and stops it on shutdown; if a
143
+ bridge is already running (for example from the scheduled task), it leaves it
144
+ alone. Run `npx dsh-tg-bridge@latest init ...` first so a config exists.
145
+
146
+ What `init` does:
147
+
148
+ | What | Where |
149
+ |---|---|
150
+ | bot token | `~/.dsh/.credentials.yaml` → `refs.DSH_TELEGRAM_BOT_TOKEN`; other keys are left alone |
151
+ | your id and working directory | `~/.dsh/tg-bridge/config.json`; an existing file is not overwritten |
152
+ | `headless` profile | checked, with a hint on how to create it if missing |
153
+
154
+ `init` flags: `--cwd <path>` (default `~/Projects`), `--voice` (enable
155
+ voice transcription), `--dry-run` (show what would be written, change nothing).
156
+
157
+ Optional provider settings live in `config.json`:
158
+
159
+ | Key | Meaning |
160
+ |---|---|
161
+ | `providerKeys` | extra env var names to pass to a turn, read from `~/.dsh/.credentials.yaml`; default `[]` |
162
+ | `pricesUrl` | retired: `/prices` always reads OpenRouter's public list and labels the number as a reference for the model |
163
+ | `vision.patch` | opt-in overlay profile for photo turns; default `""` — the turn's own model reads images |
164
+ | `vision.enabled` | set `true` to run photo turns on `vision.patch` instead of the topic profile |
165
+ | `fallbackModels` | ordered failover chain; default `[]` — see below |
166
+ | `fallbackEnabled` | `false` switches the whole chain off without editing the list; `/fallback off` sets it |
167
+ | `maxParallel` | how many topics run at once, 1–8, default `3`; also `/jobs 5` in the chat |
168
+ | `replayWindowMs` | how old a journaled update may be and still be replayed after a restart; default `600000` (10 min) |
169
+
170
+ Each `fallbackModels` entry is one attempt, tried in order after the turn's own
171
+ model refuses:
172
+
173
+ ```json
174
+ {
175
+ "provider": "router-a",
176
+ "model": "some-model",
177
+ "patch": "~/.dsh/tg-bridge/model-a.yml",
178
+ "free": false,
179
+ "off": false
180
+ }
181
+ ```
182
+
183
+ `patch` is an overlay file with a single `agent-default-model` row
184
+ (`provider` + `model`); it is materialised once as its own profile, so the turn
185
+ keeps every other setting and only the model changes. `provider` is the id the
186
+ provider is written under in the profile — it decides whose key and host the
187
+ pre-flight probe asks, so the same model id on two routers stays two attempts.
188
+ `free` only adds `(free)` to the switch notice. `off` keeps an entry in the list
189
+ but out of the walk; an entry whose `patch` file is missing is skipped the same
190
+ way, and the chat says so instead of counting it.
191
+
192
+ The chain may mix companies: a 503 from one provider says nothing about another,
193
+ so a busy channel skips its own models and the next company is still tried. Put
194
+ models from different companies next to each other — two arms of one router are
195
+ one outage, not two chances — and keep the `:free` models at the end, as the
196
+ last resort.
197
+
198
+ **What starts a switch.** Anything the provider itself says no to: a 400/413/422
199
+ refusal (its own validator rejecting the request), 401/403 (key refused), 402 or
200
+ a quota/balance message (empty account), 404 (that model id is not carried),
201
+ 429 (rate limit), 5xx and `get_channel_failed` / "all providers busy" (the pool
202
+ is down), a dropped connection or DNS/TLS failure, and an empty answer. A refusal
203
+ gets one other route, not the whole chain: it is replayed in full, and if the
204
+ second vendor refuses identically the request — not the route — is what is wrong,
205
+ so the reply says to start a fresh session with `/new`.
206
+
207
+ **What does not start a switch.** The turn time cap, `/stop`, a session or
208
+ directory error, a missing `dsh` binary: no other vendor changes those, and a
209
+ replay would cost a full turn to learn the same thing. They are listed in the
210
+ card so the distinction is visible instead of guessed.
211
+
212
+ ### `/fallback` — the chain from the chat
213
+
214
+ ```
215
+ /fallback the card: chain state, numbered routes, what starts a switch
216
+ /fallback on | off the whole chain (per route: /fallback off 3)
217
+ /fallback use 3 | skip 3 one route back in or out
218
+ /fallback up 3 | down 3 move a route in the order
219
+ /fallback test [3] ask each route (or one) with a 1-token request
220
+ /fallback add <provider>/<model> write an overlay and append the route
221
+ /fallback first <provider>/<model> put it at the head: tried before every other route
222
+ /fallback remove 3 drop a route from the list (its overlay file stays)
223
+ ```
224
+
225
+ Every line has a button on the card: `● n` switches a route, `↑ n` / `↓ n` move
226
+ it, and the card redraws in place after each press. `test` proves the key and the
227
+ channel are alive — not that the provider accepts this conversation, so a route
228
+ can answer `ping` and still refuse a long prompt with a 400. The card says that
229
+ in as many words.
230
+
231
+ `test` also times each route: how long it takes to produce the first token, and
232
+ which live route is fastest right now. Two routes that both answer are not
233
+ equally good — 400 ms and 9 s feel like different products — and the head of the
234
+ chain is the one a person picks on that number. A route that did not answer
235
+ prints no time, so `no balance · 120 ms` can never read as "works, just slow".
236
+
237
+ `first` exists because `add` appends: when the route you want should answer
238
+ *before* the primary, appending it means moving it up eight times and guessing
239
+ where the head is. `/fallback first router-a/deepseek-v4.1-flash` writes the
240
+ same overlay and puts it at position 1 — or moves it there if it is already in
241
+ the chain.
242
+
243
+ Get your id from [@userinfobot](https://t.me/userinfobot), the token from
244
+ [@BotFather](https://t.me/BotFather).
245
+
246
+ ### Bot settings in Telegram
247
+
248
+ Three things without which the bot will stay silent in a group or work only halfway:
249
+
250
+ 1. **Privacy mode → Disable** (`/setprivacy` in BotFather). Otherwise the bot sees
251
+ only commands, not regular text in a topic.
252
+ 2. **Topics enabled** in the group settings (Edit → Topics). Without them all work
253
+ goes to a single chat and per-topic sessions are not created.
254
+ 3. **Pin Messages** permission for the bot. Only needed to pin the first
255
+ message of a topic; without it the bridge keeps working but will not pin.
256
+
257
+ You do not need to set up the command menu by hand: `init` and `setup` install it
258
+ in Russian, English and Chinese at once. The menu is not refreshed by a plain
259
+ bridge restart, so after adding commands run `dsh-tg menu`. The full settings
260
+ table, permissions, checks and common errors are in
261
+ [docs/TELEGRAM-SETUP.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/TELEGRAM-SETUP.md).
262
+
263
+ **Autostart** has two routes. `sh install.sh` writes `launchd` on macOS and
264
+ `systemd --user` on Linux; `dsh-tg setup` registers the `DSH-TG-Bridge` task on
265
+ Windows, which runs the guarded supervisor (the same launcher on logon and every
266
+ five minutes) so a crashed bridge comes back without a second poller. On macOS
267
+ and Linux `setup` declines and names `install.sh`, because it stops the old
268
+ bridge with `taskkill` and registers autostart through `schtasks`.
269
+
270
+ **Manual install** (if you want full control):
271
+
272
+ ```bash
273
+ npm install -g dsh-tg-bridge
274
+ dsh-tg init --token 123456789:AA... --user 123456789
275
+ dsh-tg check # report only, changes nothing
276
+ dsh-tg setup # stop the old bridge and start the new one
277
+ ```
278
+
279
+ If the bridge is already installed, `setup` restarts it on the new code and reinstalls
280
+ the command menu.
281
+
282
+ ## Troubleshooting
283
+
284
+ Starting from nothing, or helping someone who is: [QUICKSTART.md](QUICKSTART.md)
285
+ has the same answers with the terminal output they will actually see.
286
+
287
+ Error replies end with a code, which tells you what to fix:
288
+
289
+ | Code | Meaning |
290
+ |---|---|
291
+ | `INSUFFICIENT_QUOTA` | provider balance is empty: top up or stay on free models (`/prices`, `/model`) |
292
+ | `TG_CONFLICT` | a second process is polling the same bot: `/doctor`, then `/restart` |
293
+ | `MISSING_CREDENTIAL` | no provider key in the profile: add it in the DSH app |
294
+ | `NO_DSH_CLI` | DeepSeek Harness CLI not found: check the app installation |
295
+ | `NETWORK` | no network to the provider: retry, check VPN/DNS |
296
+ | `SANDBOX_DENY` | DSH denied access to a file or directory: check the project path and permissions |
297
+ | `UNKNOWN_MODEL` | the model from the config is unavailable: `/model` lists the working ones |
298
+ | `EMPTY_RESPONSE` | the model returned nothing: retry or switch model (`/model`) |
299
+ | `TURN_TIME_CAP` | the turn hit its own time ceiling: the work is saved, press Continue |
300
+ | `TURN_FAILED` | cause not recognized: `/doctor` and `/logs errors` |
301
+
302
+ ## Checks
303
+
304
+ Send the bot:
305
+
306
+ | Command | Expected |
307
+ |---|---|
308
+ | `/doctor` | report: pid, Telegram, disk, directory, session |
309
+ | `/update` | which bridge runs, what npm has, and whether a newer release exists (`/update confirm` installs it) |
310
+ | `/thoughts [file\|all\|off]` | the last turn's reasoning as a message; `file`/`all` send the full log as a Markdown document, `off` hides the block |
311
+ | `/help` | commands grouped by category |
312
+ | `/cd my-app` | topic bound to the project, and the sandbox narrowed to it |
313
+ | `/diff [stat]` | what the turn changed, one hunk at a time: every hunk has "explain" and "revert this hunk"; a stale button is refused |
314
+ | `/report` | a redacted bundle (version, profile, preset, model, cwd, last failure, log tail) sent to the owner as a document; in a group, the path only |
315
+ | `/prices` | what the current model costs, and whose price that is: your provider's, the same model on another gateway, or "no public price" when nobody publishes one |
316
+
317
+ ## Commands
318
+
319
+ ```
320
+ Work: /cd · /new · /stop · /send · /seed · /diff
321
+ Goals: /goal (plan + checklist) · /goal reopen · /tasks (checklist only) · /tasks done|rm|edit <n>
322
+ Sessions: /status · /sessions · /sessions <id> · /rewind [n|undo|fork [n]|branches]
323
+ Agents: /agents · /agents <id> · /agents set model|depth|filter
324
+ Models: /model · /model <route> · /model <route> all · /model auto · /endpoint · /prices
325
+ Tuning: /effort · /permissions · /preset · /plan · /jobs · /remind
326
+ Profiles: /profile · /profile <name> · /profile new <name> from <template>
327
+ Sets: /crew · /crew use|off|new|copy|rm · /crew model <v>
328
+ Extensions: /skills · /plugins · /plugins search <word> · /plugins disable|enable <id> · /soul
329
+ Updates: /update · /update confirm · /update on|off|check|auto · /subscribe on|off
330
+ Diagnostics: /doctor · /logs [errors|N|text] · /report
331
+ Service: /app · /restart · /help
332
+ Machine: /load · /load on|off · /load limit cpu|ram|disk <n>
333
+ Settings: /settings — the same switches as buttons, grouped in four tabs
334
+ Display: /lang · /reasoning off|card|chat · /pin on|off · /thoughts
335
+ ```
336
+
337
+ ### Settings as a card
338
+
339
+ `/settings` draws the same switches that the commands set, in one message with
340
+ four tabs: what the bot says, who answers and how hard it works, new releases,
341
+ and the health checks. Each row shows what the setting is now and what a tap
342
+ would change it to. A tap runs the command a person would have typed
343
+ (`/reasoning chat`, `/update on`), so the card cannot disagree with the command:
344
+ it is a view of them.
345
+
346
+ The card stays after a tap. It is edited in place — same message, same buttons,
347
+ the value in force marked with `●` and one `✓ row: value` line saying what just
348
+ changed — so a second setting is one more tap instead of a second `/settings`.
349
+ `✓ Done` removes the card when you are finished with it; nothing else deletes it.
350
+
351
+ `📌 Pin the progress card` (`/pin on`) keeps the running card pinned, so the
352
+ clock, the speed and the step list are one tap away instead of a scroll. Telegram
353
+ gives a chat one pinned message, so each turn's card replaces the last one. Off by
354
+ default: a bot that pins without being asked takes that slot in someone else's
355
+ chat, and a group needs the right to pin at all.
356
+
357
+ Nothing on the card is only available on the card. `/settings` is for people who
358
+ would rather press a labelled button than remember which of `/effort`,
359
+ `/preset` and `/crew` changes what.
360
+
361
+ Every command answers `/help` in the chat, in the language you write in: a
362
+ message written in Cyrillic or Han characters switches the topic to Russian or
363
+ Chinese even when the phone's menu is set to another language, and `/lang`
364
+ pins a choice above that. The Telegram menu shows the same list, minus
365
+ `/subscribe`: it is one line, and a person who turns it off should not have to
366
+ find it in a menu again.
367
+
368
+ ## Updates
369
+
370
+ The npm tag `latest` is a label, not an updater: installing a package pins the
371
+ version on disk, and nothing moves until something moves it. Two switches, both
372
+ about this install (not about a topic, because it is the install that updates):
373
+
374
+ | Command | What it does |
375
+ |---|---|
376
+ | `/update` | one line: what runs here, what is published, which switches are set |
377
+ | `/update on` | tell me about new releases: one message per version, checked once a day |
378
+ | `/update off` | stop telling me; nothing installs, nothing moves |
379
+ | `/update auto` | besides telling me, install the release by itself (checked hourly) |
380
+ | `/update confirm` | install the new release now, by hand |
381
+
382
+ Nothing above installs except `confirm` and `auto`, and even those only change the
383
+ files: the running process keeps its old modules until `/restart confirm`, so a
384
+ bad release never lands mid-chat. `confirm` and `auto` copy the replaced files to
385
+ `update-backup-<date>` and print the path; copying that folder back is the way to
386
+ roll back, with no state to undo.
387
+
388
+ `/subscribe on|off` says the same thing as `/update on|off`, for people who do not
389
+ want to read `/update` first. It is not in the Telegram menu on purpose.
390
+
391
+ There are no notices about failures. The bridge cannot decide what counts as one
392
+ for you, and "something failed" that nobody can act on is noise; errors stay in
393
+ the chat where they happened, under `/doctor` and `/logs errors`.
394
+
395
+ ## How it works
396
+
397
+ ```
398
+ Telegram → bridge.mjs → dsh --profile headless --json → reply
399
+ │
400
+ ├─ pending/ journal + ack (messages are not lost)
401
+ ├─ per-topic queue (turns in topics run in parallel)
402
+ ├─ progress + buttons (you can see the work is going)
403
+ └─ fail-fast on quota (free models as a fallback)
404
+ ```
405
+
406
+ The bridge is a single process with long polling. Each turn spawns a separate
407
+ CLI process that exits after the answer, so "no DSH process" between
408
+ turns is normal, not a failure.
409
+
410
+ ### Steering during a turn
411
+
412
+ If you write in a topic while a turn is still running, the message does not queue
413
+ behind it: the bridge drops the task into `~/.dsh/tg-bridge/steer/`, the `dsh-steer-inbox`
414
+ plugin hands it to the live agent on its next step, and the agent immediately replies with a short
415
+ line in the chat: what it is doing now and where it put the addition. If the agent stays silent
416
+ for 90 seconds, the bridge writes one neutral line itself so there is no silence.
417
+
418
+ Attachments work the same way. A voice note is transcribed first and its transcript is echoed in
419
+ the chat, then the text is steered into the running turn; a photo or a file is downloaded to a
420
+ local path and that path is steered, exactly as an idle turn would hand it over.
421
+
422
+ What each kind of attachment becomes inside a running turn:
423
+
424
+ | Sent | Inside the turn | Needs |
425
+ |---|---|---|
426
+ | voice note, audio file, audio sent as a document | transcript, echoed as `🎤 …` before the steer | `faster-whisper` on `PATH`, enabled with `init --voice`; **off by default** |
427
+ | small text file (`.md`, `.json`, `.csv`, `.py`, `.log`, … up to 60 KB) | the content itself between `<file>` markers — no tool call needed | nothing |
428
+ | PDF, archive, binary, anything bigger | its local path under `~/.dsh/tg-bridge/inbox/` | nothing; the agent opens it with its own tools |
429
+ | video, video note, animation | its path; the agent can pull frames or sound out with ffmpeg | ffmpeg, only if frames or audio are needed |
430
+ | photo | its path plus one honest line; the turn reads it with `read_image`, and says so in one line if it cannot | a model that accepts images |
431
+
432
+ Voice is the one row with a hidden prerequisite. Without `faster-whisper`
433
+ installed, a voice note still arrives — as a path the agent cannot read — so the
434
+ bridge says transcription is off instead of pretending it heard something. Run
435
+ `dsh-tg init --voice` after installing the transcriber; nothing else changes.
436
+
437
+ A caption does not turn the attachment into a text-only message: it is folded into the same
438
+ hand-over, so "why did this fail" plus a `.log` file arrives as one steer.
439
+
440
+ An album is one request, not ten. Telegram delivers it as one update per file, all sharing a
441
+ `media_group_id`; the bridge collects the group (1.2 s of quiet after the last item, at most
442
+ 4 s) and hands it over once — one steer into a running turn, one turn when the topic is idle.
443
+
444
+ ### When a turn hits the time ceiling
445
+
446
+ `turnTimeoutMs` (default 30 min, this install 75) is a ceiling, not a target: if a turn reaches
447
+ it, the bridge stops it with `⏱` instead of letting one runaway loop own the topic for hours.
448
+ Nothing is lost — the session and every file the turn produced stay in place — so the message
449
+ carries **⏵ Continue**, which asks the agent to check the state and go on from where it stopped.
450
+ That is deliberately not the same as **Retry**, which would redo the whole task from the start.
451
+
452
+ This needs the plugin from this repository:
453
+
454
+ ```bash
455
+ dsh plugin --profile headless add link:<path-to-repository>/plugin/steer-inbox
456
+ ```
457
+
458
+ and a line in `~/.dsh/profiles/headless/cordis.patch.yml`:
459
+
460
+ ```yaml
461
+ - insert:
462
+ - id: steer-inbox
463
+ name: 'dsh-steer-inbox'
464
+ ```
465
+
466
+ The bridge checks the profile itself: if the line is missing, it does not write the task
467
+ (it would just expire) and behaves as before, queueing the message.
468
+
469
+ ### Live thoughts and reasoning
470
+
471
+ Two things land in the same progress message, and neither sends a chat message of its own.
472
+
473
+ **The model's reasoning.** Every `thinking` block the CLI commits is folded into one
474
+ Telegram `<blockquote expandable>`: collapsed it is a single line, tapped it opens the whole
475
+ trail of the turn, and it stays there after the turn ends — the same way the desktop app shows
476
+ a reasoning section you can expand. The block is written once, in the final edit of the turn,
477
+ and never touched again: Telegram re-collapses an expanded block on every edit of its message,
478
+ which used to yank the chat away from a half-read paragraph. While the turn runs the message
479
+ only gets a counter (`🧠 Размышления · 4821`) and the last three steps, so the live edits stay
480
+ short. Escaped, and trimmed to its tail when a turn thinks longer than a message can hold; the
481
+ panel never exceeds one message. A cut block says `… · начало скрыто · /thoughts file`, which
482
+ sends the whole log as a document. If the API refuses the markup, the same content is retried
483
+ as plain text.
484
+
485
+ **The steps.** Three calls fit inline. A turn that makes more moves its complete step list into
486
+ a second collapsed block, added in that same final edit, so "what did it actually run" is one
487
+ tap away instead of a count.
488
+
489
+ **The agent's own notes.** The agent can add a short decision trail:
490
+
491
+ ```bash
492
+ node ~/.dsh/tg-bridge/say.mjs --thought "checking why the watchdog fired twice"
493
+ ```
494
+
495
+ The note is appended to `~/.dsh/tg-bridge/thoughts/<chat>_<thread>.jsonl`; the progress
496
+ message shows the last two as `💭` lines. The command needs no ids: it falls back to the
497
+ newest turn's thought file, because tool shells do not inherit the bridge environment.
498
+ `--thought` sends a Telegram message of its own only in `/reasoning chat` mode.
499
+
500
+ A decision the person must know before the turn ends — a release shipped, a cause found,
501
+ a blocker — goes to the chat as one plain line instead:
502
+
503
+ ```bash
504
+ node ~/.dsh/tg-bridge/say.mjs --note "1.10.1 is on npm; restart to load it"
505
+ ```
506
+
507
+ `--note` sends a real message and takes the same no-ids fallback as `--thought`. The split
508
+ is deliberate: `--thought` is the working trail (inside the progress message, and in `chat`
509
+ mode also as its own messages), `--note` is the short line that changes what the reader
510
+ expects to happen next — useful in `card` and `off` mode, redundant in `chat`. The progress
511
+ message itself opens with the request echoed back (`⏳ Принял: «…» · 3 с`), so the first
512
+ thing the person sees after sending names their task rather than a generic spinner.
513
+
514
+ `/reasoning` is the switch for the 💭 mechanism, and it has three ends:
515
+
516
+ - `/reasoning card` (the default) — every turn carries a short instruction to leave one line
517
+ at each decision point (task clear, cause found, risky change, result checked), and the
518
+ progress message shows the last two;
519
+ - `/reasoning chat` — the same lines, each also posted as its own message, so a turn that
520
+ runs for twenty minutes is read as it happens instead of scrolled back to afterwards.
521
+ The prompt says so explicitly, so a line is written to stand alone;
522
+ - `/reasoning off` — drops the instruction and the `💭` lines for that topic, for when the
523
+ step list is all you want.
524
+
525
+ A topic switched to `chat` mid-turn does not dump the steps already in the card: forwarding
526
+ starts with the next line written. The setting lives in `state.json` per topic, so a chatty
527
+ research topic and a terse deploy topic can differ; a `true`/`false` written by an older
528
+ release still reads as `card`/`off`. The settings card offers the same three ends as buttons.
529
+
530
+ The reasoning block itself is model output; `/thoughts` is what reads it back:
531
+
532
+ - `/thoughts` — the last turn as a message, in parts, deleted after three minutes;
533
+ - `/thoughts file` — the **whole** last turn as `reasoning-<date>-file.md`, sent as a document
534
+ (a five-hour turn is tens of thousands of characters, which no chat message can hold);
535
+ - `/thoughts all` — every turn of the session in one file (a long session is a couple of MB);
536
+ - `/thoughts off` / `on` — keep the block out of the turn panel (the panel then shows
537
+ `🧠 Размышления · N · /thoughts file`) or bring it back.
538
+
539
+ The log is built from the session file on demand, so nothing is duplicated while a turn runs.
540
+ Files land in `~/.dsh/tg-bridge/thoughts/` and older ones are pruned after a week.
541
+
542
+ ### Profiles per topic
543
+
544
+ The desktop app lets you build several profiles for different kinds of work, each with its own
545
+ plugin set and model. The same switch works from a topic:
546
+
547
+ ```
548
+ /profile current profile, available ones, hints
549
+ /profile research run this topic's turns on another profile
550
+ /profile new research from web
551
+ create a profile from a shipped template and bind it
552
+ /profile default back to the install default
553
+ ```
554
+
555
+ A new profile is written by `dsh <name> --from-default-profile <template> --dump-config`, so
556
+ nothing boots and no plugin is loaded at creation time; dependencies are installed by the
557
+ profile's first turn. The binding is per topic: `/plugins` manages that profile's rows, and
558
+ `/plugins search <word>` lists what the npm registry
559
+ has with the `dsh-plugin` keyword — the desktop app's plugin browser, from the chat. Each result
560
+ carries a plus button that runs `/plugins add <name>`.
561
+
562
+ `/model` is a step finer than the binding. A topic that never chose a model boots the profile
563
+ it is bound to; `/model <route>` stores the route for that topic alone, and the next turn boots a
564
+ copy of the profile with the `agent-default-model` row rewritten — provider, model and the other
565
+ keys of that row, `reasoningEffort` included, carried over. The copy is rebuilt whenever the
566
+ profile changes, so a provider added to the profile reaches the topics that had already chosen.
567
+ `/model <route> all` writes the profile itself, and `/model auto` deletes the topic's route.
568
+
569
+ ### The directory a topic writes in
570
+
571
+ `/cd my-app` does two things, and they are worth separating because they used to
572
+ be one: the turn runs *in* that directory, and the sandbox *stops* at it. The
573
+ second half only works on a profile that has a permission table — the bridge
574
+ writes the row only when one exists, and never invents one for a profile that
575
+ opted out.
576
+
577
+ ```
578
+ /cd my-app bind the topic: run here, and write only here
579
+ /cd ~/Projects/api wide run here, but do not narrow the sandbox
580
+ /cd reset unbind; the topic goes back to config.cwd
581
+ /cd what this topic is bound to, and how
582
+ ```
583
+
584
+ | Sandbox mode | Writes inside the root | Writes outside the root |
585
+ |---|---|---|
586
+ | `read-only` | denied | denied |
587
+ | `workspace-write` | allowed | denied |
588
+ | `danger-full-access` | allowed | allowed |
589
+
590
+ `workspaceRoot` is the boundary, and it holds even when the turn switches its own
591
+ working directory: the refusal follows the configured root, not the directory the
592
+ agent moved to. That is the point — a model that wanders into another project
593
+ gets a refusal instead of a write.
594
+
595
+ Three things this table does **not** say, because measurement disagreed with the
596
+ obvious reading:
597
+
598
+ - the sandbox row alone changes nothing. `mode: read-only` in the
599
+ `sandbox-policy` row plus `defaultPreset: danger-full-access` in the permission
600
+ table still wrote outside the root. The permission table wins; the sandbox row
601
+ is a default for a profile that has no table.
602
+ - `danger-full-access` therefore has to be chosen on purpose, per topic
603
+ (`/permissions danger-full-access`), and it is the only mode that reaches
604
+ outside the root.
605
+ - a preset with `approval: ask` cannot be used from a chat at all: a headless
606
+ turn has no approval channel, so the escalation fails closed and the turn
607
+ errors. `/permissions` lists such a preset with the reason instead of letting
608
+ someone pick a trap.
609
+
610
+ Stock installs are not permission-enabled: `cordis.patch.yml` ships with the
611
+ `tg-bridge` plugin row only, so `/cd` binds the directory and `/permissions`
612
+ edits the profile-wide preset, exactly as before. The per-topic behaviour starts
613
+ the first time a profile gains a permission table.
614
+
615
+ ### Goals and tasks
616
+
617
+ A topic carries its own goal and checklist, so the aim survives `/new`, a
618
+ restart and a different session:
619
+
620
+ ```
621
+ /goal ship the release set or replace the goal
622
+ /goal show the goal and the checklist
623
+ /tasks write the migration add a task
624
+ /tasks done 2 tick it off
625
+ /tasks edit 2 shorter words rewrite it in place, same number
626
+ /tasks rm 2 remove it
627
+ /goal reopen open a closed goal again
628
+ /goal done close the goal (all tasks done)
629
+ /goal clear delete the goal and its tasks
630
+ ```
631
+
632
+ The bridge prepends the goal and the list to every turn, with the exact command
633
+ that updates it (`goal.mjs`). The agent ticks tasks as it finishes them, and the
634
+ next turn sees the new state. The bridge is the only writer of `state.json`: the
635
+ agent drops a job file into `goal-jobs/` and the bridge applies it, so there is
636
+ no lock race and no lost update.
637
+
638
+ ## Security
639
+
640
+ - `config.json`, `state.json`, `pending/`, logs are in `.gitignore` and never
641
+ end up in the repository.
642
+ - The token is stored in the DSH credentials store, not in code or config.
643
+ - The bridge only replies to ids in `allowedUserIds`.
644
+
645
+ ## Documentation
646
+
647
+ - [docs/TELEGRAM-SETUP.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/TELEGRAM-SETUP.md): BotFather settings, group and bot permissions
648
+ - [docs/SUPPORT.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/SUPPORT.md): what to send with a bug report, what never to send, and the one-line answer for "the bot went silent"
649
+ - [docs/ROADMAP.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/ROADMAP.md): what comes next
650
+ - [docs/UX-ANALYSIS.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/UX-ANALYSIS.md): interactive UX review
651
+ - [docs/COST.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/COST.md): what one turn costs and how to reduce it
652
+ - [docs/CHANGELOG.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/CHANGELOG.md): change history
653
+ - [docs/RELEASE-CRITERIA.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/RELEASE-CRITERIA.md): release readiness criteria
654
+
655
+ ## License
656
+
657
+ MIT, see [LICENSE](LICENSE).