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