dsh-tg-bridge 1.34.1 → 1.38.2

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