dsh-tg-bridge 1.13.2 → 1.15.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/QUICKSTART.md +17 -15
- package/README.md +58 -7
- package/bot-menu.mjs +14 -5
- package/bridge.mjs +226 -2
- package/cli.mjs +13 -7
- package/control.mjs +250 -48
- package/i18n.mjs +1558 -1305
- package/install-hooks.mjs +6 -2
- package/package.json +3 -1
- package/panel.mjs +8 -3
- package/prices.mjs +104 -22
- package/scan-secrets.mjs +58 -5
- package/settings-card.mjs +190 -0
- package/update-policy.mjs +126 -0
package/QUICKSTART.md
CHANGED
|
@@ -38,7 +38,7 @@ Optional but recommended in the same chat:
|
|
|
38
38
|
## 2. Tell the bridge about the token
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
npx dsh-tg@latest init --token <the token> --user <your id>
|
|
41
|
+
npx dsh-tg-bridge@latest init --token <the token> --user <your id>
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
- **`<the token>`** — the line from step 1, in quotes if your shell needs it.
|
|
@@ -54,12 +54,13 @@ would write without writing.
|
|
|
54
54
|
## 3. Start the bridge
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
|
-
npx dsh-tg@latest setup
|
|
57
|
+
npx dsh-tg-bridge@latest setup
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
This registers the bridge so it starts with your session and runs it once.
|
|
61
|
-
|
|
62
|
-
things in [If it does not
|
|
60
|
+
This registers the bridge so it starts with your session and runs it once. It
|
|
61
|
+
ends with `ok new bridge pid <number>` — that number is the running bridge. A
|
|
62
|
+
failure here is almost always one of the three things in [If it does not
|
|
63
|
+
work](#if-it-does-not-work).
|
|
63
64
|
|
|
64
65
|
## 4. Say hello
|
|
65
66
|
|
|
@@ -83,10 +84,11 @@ Everything below is typed in the chat, not in a terminal.
|
|
|
83
84
|
| See what it is doing | it posts a live progress message; `/thoughts` toggles the 💭 notes |
|
|
84
85
|
| A plan you can tick off | `/goal <what done looks like>`, then `/task <step>`, then `/tasks` to tap items |
|
|
85
86
|
| Stop a long answer | `/stop` |
|
|
86
|
-
|
|
|
87
|
+
| Tell me about new versions, or stop | /update on / /update off — neither one installs anything |
|
|
88
|
+
| Install an update, then load it | /update confirm, then /restart confirm |
|
|
87
89
|
| Everything it can do | `/help` |
|
|
88
90
|
|
|
89
|
-
`/lang` pins the reply language; without it the bridge answers in the language
|
|
91
|
+
`/lang` pins the reply language; without it the bridge answers in the language your
|
|
90
92
|
write in (Russian, Chinese, otherwise English).
|
|
91
93
|
|
|
92
94
|
---
|
|
@@ -95,14 +97,14 @@ write in (Russian, Chinese, otherwise English).
|
|
|
95
97
|
|
|
96
98
|
| What you see | What it means |
|
|
97
99
|
|---|---|
|
|
98
|
-
| Nothing at all after `hi` | The id in `config.json` is not yours, or the bridge is not running: `npx dsh-tg@latest setup` again and read its output. |
|
|
100
|
+
| Nothing at all after `hi` | The id in `config.json` is not yours, or the bridge is not running: `npx dsh-tg-bridge@latest setup` again and read its output. |
|
|
99
101
|
| `401 Unauthorized` | The token is wrong or was revoked by BotFather. Run `init` again with a fresh token. |
|
|
100
102
|
| Works in private chat, silent in a group | Privacy mode is on: `/setprivacy` → Disable, then remove and re-add the bot to the group. |
|
|
101
|
-
| `Error [ERR_MODULE_NOT_FOUND]` on start | The
|
|
102
|
-
| Bot answers in the wrong language | `/lang ru` / `/lang en` / `/lang zh
|
|
103
|
+
| `Error [ERR_MODULE_NOT_FOUND]` on start | The running copy is older than the files it imports. A global install never updates itself: `npm i -g dsh-tg-bridge@latest`, then `/restart confirm` in the chat. With `npx` this cannot happen — `npx dsh-tg-bridge@latest` fetches the newest release on every launch. |
|
|
104
|
+
| Bot answers in the wrong language | `/lang ru` / `/lang en` / `/lang zh` — one command pins it for the topic. |
|
|
103
105
|
| Two answers to one message | Another copy of the bridge is running: `/status` shows the pid, kill the duplicate. |
|
|
104
106
|
|
|
105
|
-
Still stuck: `/doctor` in the chat, or `npx dsh-tg@latest check` in a
|
|
107
|
+
Still stuck: `/doctor` in the chat, or `npx dsh-tg-bridge@latest check` in a
|
|
106
108
|
terminal — both print what is missing and how to fix it.
|
|
107
109
|
|
|
108
110
|
---
|
|
@@ -121,10 +123,10 @@ An agent helping a person needs three answers, then can do the rest:
|
|
|
121
123
|
Then:
|
|
122
124
|
|
|
123
125
|
```bash
|
|
124
|
-
npx dsh-tg@latest check # what is missing right now
|
|
125
|
-
npx dsh-tg@latest init --token <token> --user <id> [--cwd <path>] [--dry-run]
|
|
126
|
-
npx dsh-tg@latest setup # register autostart and start
|
|
127
|
-
npx dsh-tg@latest menu # push the command menu to Telegram
|
|
126
|
+
npx dsh-tg-bridge@latest check # what is missing right now
|
|
127
|
+
npx dsh-tg-bridge@latest init --token <token> --user <id> [--cwd <path>] [--dry-run]
|
|
128
|
+
npx dsh-tg-bridge@latest setup # register autostart and start
|
|
129
|
+
npx dsh-tg-bridge@latest menu # push the command menu to Telegram
|
|
128
130
|
```
|
|
129
131
|
|
|
130
132
|
Verify with a real message, not with logs: ask the person to send `hi` and wait
|
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ a bot that answers, one step at a time.
|
|
|
27
27
|
`/agentset off` returns it. Four built-in sets ship read-only and can be copied.
|
|
28
28
|
- **Fail-fast**: when the quota runs out it switches to a free model right away.
|
|
29
29
|
- **`dsh-tg check`**: diagnostics in one command, no changes to the system.
|
|
30
|
-
- **Languages**: menus and service messages in `en`, `ru`, `zh`; `/lang`
|
|
30
|
+
- **Languages**: menus and service messages in `en`, `ru`, `zh`; `/lang` pins the topic language, and without it a new topic takes the language of the message itself (Cyrillic → `ru`, Han characters → `zh`), then the Telegram `language_code`, then `en`.
|
|
31
31
|
- **"Stop"/"Retry" buttons, tool confirmations**: right in the message, no commands to type.
|
|
32
32
|
|
|
33
33
|
## Requirements
|
|
@@ -58,7 +58,7 @@ can be listed next to them:
|
|
|
58
58
|
|
|
59
59
|
## Languages
|
|
60
60
|
|
|
61
|
-
- Menus (`/` in chat): three sets, `ru` by default, plus `en` and `zh
|
|
61
|
+
- Menus (`/` in chat): three sets, `ru` by default, plus `en` and `zh`; a client whose locale matches neither gets the Russian set.
|
|
62
62
|
- Topic language: `/lang en|ru|zh`; stored in `state.json` and survives a restart.
|
|
63
63
|
- A new user gets the language from the Telegram `language_code`; anything that is not `ru`/`zh` → `en`.
|
|
64
64
|
- Translated so far: menus, the start message, turn status, errors, `/cd`, `/new`, `/stop`, `/lang`,
|
|
@@ -179,24 +179,75 @@ Send the bot:
|
|
|
179
179
|
| `/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 |
|
|
180
180
|
| `/help` | commands grouped by category |
|
|
181
181
|
| `/cd my-app` | topic bound to the project |
|
|
182
|
-
| `/prices` | model
|
|
182
|
+
| `/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 |
|
|
183
183
|
|
|
184
184
|
## Commands
|
|
185
185
|
|
|
186
186
|
```
|
|
187
187
|
Work: /cd · /new · /stop · /send · /seed
|
|
188
|
-
Goals: /goal · /task
|
|
188
|
+
Goals: /goal · /task · /tasks
|
|
189
189
|
Sessions: /status · /sessions · /resume
|
|
190
190
|
Agents: /agents · /agents <id> · /agents set model|depth|filter
|
|
191
|
-
Models: /model · /model <id> · /prices
|
|
191
|
+
Models: /model · /model <id> · /models · /prices
|
|
192
192
|
Tuning: /effort · /permissions · /preset · /plan · /jobs · /remind
|
|
193
193
|
Profiles: /profile · /profile <name> · /profile new <name> from <template>
|
|
194
|
-
|
|
194
|
+
Sets: /agentset · /agentset use|off|new|copy|rm · /agentset model <v>
|
|
195
|
+
Extensions: /skills · /plugins · /plugin disable|enable <id> · /soul
|
|
196
|
+
Updates: /version · /update · /update confirm · /update on|off|check|auto · /subscribe on|off
|
|
195
197
|
Diagnostics: /doctor · /logs [errors|N|text]
|
|
196
198
|
Service: /app · /restart · /help
|
|
197
|
-
|
|
199
|
+
Settings: /settings — the same switches as buttons, grouped in four tabs
|
|
200
|
+
Display: /lang · /reasoning on|off · /thoughts
|
|
198
201
|
```
|
|
199
202
|
|
|
203
|
+
### Settings as a card
|
|
204
|
+
|
|
205
|
+
`/settings` draws the same switches that the commands set, in one message with
|
|
206
|
+
four tabs: what the bot says, who answers and how hard it works, new releases,
|
|
207
|
+
and the health checks. Each row shows what the setting is now and what a tap
|
|
208
|
+
would change it to. A tap runs the command a person would have typed
|
|
209
|
+
(`/reasoning off`, `/update on`), so the card cannot disagree with the command:
|
|
210
|
+
it is a view of them. After the change the card collapses into one plain line —
|
|
211
|
+
delete it and the chat is back to what it was.
|
|
212
|
+
|
|
213
|
+
Nothing on the card is only available on the card. `/settings` is for people who
|
|
214
|
+
would rather press a labelled button than remember which of `/effort`,
|
|
215
|
+
`/preset` and `/agentset` changes what.
|
|
216
|
+
|
|
217
|
+
Every command answers `/help` in the chat, in the language you write in: a
|
|
218
|
+
message written in Cyrillic or Han characters switches the topic to Russian or
|
|
219
|
+
Chinese even when the phone's menu is set to another language, and `/lang`
|
|
220
|
+
pins a choice above that. The Telegram menu shows the same list, minus
|
|
221
|
+
`/subscribe`: it is one line, and a person who turns it off should not have to
|
|
222
|
+
find it in a menu again.
|
|
223
|
+
|
|
224
|
+
## Updates
|
|
225
|
+
|
|
226
|
+
The npm tag `latest` is a label, not an updater: installing a package pins the
|
|
227
|
+
version on disk, and nothing moves until something moves it. Two switches, both
|
|
228
|
+
about this install (not about a topic, because it is the install that updates):
|
|
229
|
+
|
|
230
|
+
| Command | What it does |
|
|
231
|
+
|---|---|
|
|
232
|
+
| `/update` | one line: what runs here, what is published, which switches are set |
|
|
233
|
+
| `/update on` | tell me about new releases: one message per version, checked once a day |
|
|
234
|
+
| `/update off` | stop telling me; nothing installs, nothing moves |
|
|
235
|
+
| `/update auto` | besides telling me, install the release by itself (checked hourly) |
|
|
236
|
+
| `/update confirm` | install the new release now, by hand |
|
|
237
|
+
|
|
238
|
+
Nothing above installs except `confirm` and `auto`, and even those only change the
|
|
239
|
+
files: the running process keeps its old modules until `/restart confirm`, so a
|
|
240
|
+
bad release never lands mid-chat. `confirm` and `auto` copy the replaced files to
|
|
241
|
+
`update-backup-<date>` and print the path; copying that folder back is the way to
|
|
242
|
+
roll back, with no state to undo.
|
|
243
|
+
|
|
244
|
+
`/subscribe on|off` says the same thing as `/update on|off`, for people who do not
|
|
245
|
+
want to read `/update` first. It is not in the Telegram menu on purpose.
|
|
246
|
+
|
|
247
|
+
There are no notices about failures. The bridge cannot decide what counts as one
|
|
248
|
+
for you, and "something failed" that nobody can act on is noise; errors stay in
|
|
249
|
+
the chat where they happened, under `/doctor` and `/logs errors`.
|
|
250
|
+
|
|
200
251
|
## How it works
|
|
201
252
|
|
|
202
253
|
```
|
package/bot-menu.mjs
CHANGED
|
@@ -42,14 +42,17 @@ const COMMANDS = [
|
|
|
42
42
|
{ command: 'sessions', description: 'Сессии темы — обычный текст продолжает последнюю' },
|
|
43
43
|
{ command: 'resume', description: 'Продолжить сессию: /resume <id>' },
|
|
44
44
|
{ command: 'model', description: 'Показать или сменить: /model, /model <id>' },
|
|
45
|
+
{ command: 'models', description: 'Все модели профиля и цены' },
|
|
45
46
|
{ command: 'skills', description: 'Скиллы: список или текст одного' },
|
|
46
47
|
{ command: 'soul', description: 'Персона: показать или задать' },
|
|
47
|
-
{ command: 'plugins', description: 'Список и
|
|
48
|
+
{ command: 'plugins', description: 'Список и включение: disable/enable (add/remove — /plugin)' },
|
|
49
|
+
{ command: 'plugin', description: 'Один плагин: /plugin disable <id>' },
|
|
48
50
|
{ command: 'app', description: 'Приложение DSH, не мост: /app restart confirm' },
|
|
49
51
|
{ command: 'restart', description: 'Перезапуск моста: /restart confirm' },
|
|
50
52
|
{ command: 'doctor', description: 'Диагностика: мост, сеть, диск, плагины, сессия' },
|
|
51
53
|
{ command: 'logs', description: 'Лог: /logs, /logs 100, /logs errors, /logs file' },
|
|
52
54
|
{ command: 'help', description: 'Все команды и подсказки' },
|
|
55
|
+
{ command: 'settings', description: 'Настройки кнопками, по разделам' },
|
|
53
56
|
{ command: 'lang', description: 'Язык интерфейса: en, ru, zh' },
|
|
54
57
|
{ command: 'reasoning', description: 'Заметки по ходу: /reasoning on|off' },
|
|
55
58
|
{ command: 'profile', description: 'Профиль темы: /profile <имя>, /profile new' },
|
|
@@ -81,14 +84,17 @@ const COMMANDS_EN = [
|
|
|
81
84
|
{ command: 'sessions', description: 'Sessions of this topic — plain text continues the last one' },
|
|
82
85
|
{ command: 'resume', description: 'Continue a session: /resume <id>' },
|
|
83
86
|
{ command: 'model', description: 'Show or switch: /model, /model <id>' },
|
|
87
|
+
{ command: 'models', description: 'All models of this profile with prices' },
|
|
84
88
|
{ command: 'skills', description: 'Installed skills' },
|
|
85
89
|
{ command: 'soul', description: 'Agent persona' },
|
|
86
|
-
{ command: 'plugins', description: 'List and
|
|
90
|
+
{ command: 'plugins', description: 'List and toggle: disable/enable (add/remove is /plugin)' },
|
|
91
|
+
{ command: 'plugin', description: 'One plugin: /plugin disable <id>' },
|
|
87
92
|
{ command: 'app', description: 'DSH desktop app (not the bridge)' },
|
|
88
93
|
{ command: 'restart', description: 'Restart the bridge: /restart confirm' },
|
|
89
94
|
{ command: 'doctor', description: 'Diagnostics: bridge, network, disk, plugins, session' },
|
|
90
95
|
{ command: 'logs', description: 'Log: /logs, /logs 100, /logs errors, /logs file' },
|
|
91
96
|
{ command: 'help', description: 'All commands and hints' },
|
|
97
|
+
{ command: 'settings', description: 'Settings as buttons, grouped by topic' },
|
|
92
98
|
{ command: 'lang', description: 'Interface language: en, ru, zh' },
|
|
93
99
|
{ command: 'reasoning', description: 'Working notes: /reasoning on|off' },
|
|
94
100
|
{ command: 'profile', description: 'Topic profile: /profile <name>, /profile new' },
|
|
@@ -101,8 +107,8 @@ const COMMANDS_EN = [
|
|
|
101
107
|
{ command: 'jobs', description: 'What the bridge runs now: turns and queue' },
|
|
102
108
|
{ command: 'remind', description: 'Reminder: /remind +15m text or 09:30 text' },
|
|
103
109
|
{ command: 'thoughts', description: 'Reasoning of the last turn (text, file or off)' },
|
|
104
|
-
{ command: 'version', description: 'Bridge version and
|
|
105
|
-
{ command: 'update', description: 'Update
|
|
110
|
+
{ command: 'version', description: 'Bridge version and how updates are handled' },
|
|
111
|
+
{ command: 'update', description: 'Update and its mode: /update, /update on|off|confirm' },
|
|
106
112
|
];
|
|
107
113
|
|
|
108
114
|
/** Chinese menu (language_code: zh-hans). */
|
|
@@ -120,14 +126,17 @@ const COMMANDS_ZH = [
|
|
|
120
126
|
{ command: 'sessions', description: '本主题的会话 —— 直接发文字会延续最近一个' },
|
|
121
127
|
{ command: 'resume', description: '继续会话:/resume <id>' },
|
|
122
128
|
{ command: 'model', description: '查看或切换:/model, /model <id>' },
|
|
129
|
+
{ command: 'models', description: '本配置档的全部模型与价格' },
|
|
123
130
|
{ command: 'skills', description: '已安装的技能' },
|
|
124
131
|
{ command: 'soul', description: '代理人格设定' },
|
|
125
|
-
{ command: 'plugins', description: '
|
|
132
|
+
{ command: 'plugins', description: '列表与开关:disable/enable(add/remove 用 /plugin)' },
|
|
133
|
+
{ command: 'plugin', description: '单个插件:/plugin disable <id>' },
|
|
126
134
|
{ command: 'app', description: 'DSH 桌面应用(不是桥接)' },
|
|
127
135
|
{ command: 'restart', description: '重启桥接:/restart confirm' },
|
|
128
136
|
{ command: 'doctor', description: '诊断:桥接、网络、磁盘、插件、会话' },
|
|
129
137
|
{ command: 'logs', description: '日志:/logs、/logs 100、/logs errors、/logs file' },
|
|
130
138
|
{ command: 'help', description: '全部命令与提示' },
|
|
139
|
+
{ command: 'settings', description: '用按钮调设置,按主题分组' },
|
|
131
140
|
{ command: 'lang', description: '界面语言:en、ru、zh' },
|
|
132
141
|
{ command: 'reasoning', description: '工作记录:/reasoning on|off' },
|
|
133
142
|
{ command: 'profile', description: '话题配置档:/profile <名称>,/profile new' },
|
package/bridge.mjs
CHANGED
|
@@ -31,6 +31,8 @@ import { turnArgs } from './cli-args.mjs';
|
|
|
31
31
|
import { chunk, markdownParts, toPlainText, toTelegramHtml } from './format.mjs';
|
|
32
32
|
import { ensureProfile } from './profiles.mjs';
|
|
33
33
|
import { handleControl, CONTROL_COMMANDS, modelOf, modelsOf, reasoningOf } from './control.mjs';
|
|
34
|
+
import { bridgeVersion, installRelease, npmLatestAsync } from './control.mjs';
|
|
35
|
+
import { dueForCheck, updateState } from './update-policy.mjs';
|
|
34
36
|
import { drainGoalJobs, goalOf, progressOf, renderPromptBlock, toggleTask } from './goals.mjs';
|
|
35
37
|
import { renderPrices } from './prices.mjs';
|
|
36
38
|
import { t, resolveLang } from './i18n.mjs';
|
|
@@ -41,6 +43,7 @@ import { parseAgentPresets, parsePermissionPresets, parseReasoningEfforts } from
|
|
|
41
43
|
import { drainAsetJobs } from './aset-jobs.mjs';
|
|
42
44
|
import { materialiseProfile, pruneDerived } from './aset-profile.mjs';
|
|
43
45
|
import { parseCallback } from './aset-schema.mjs';
|
|
46
|
+
import { commandFor, renderSettingsCard, settingsCurrent } from './settings-card.mjs';
|
|
44
47
|
|
|
45
48
|
const HOME = homedir();
|
|
46
49
|
const DSH_HOME = process.env.DSH_HOME || join(HOME, '.dsh');
|
|
@@ -749,6 +752,44 @@ function langFor(chatId, threadId = 0) {
|
|
|
749
752
|
return resolveLang(state, sessionKey(chatId, threadId), null, config);
|
|
750
753
|
}
|
|
751
754
|
|
|
755
|
+
/**
|
|
756
|
+
* Where a release notice goes: the last chat a turn ran in.
|
|
757
|
+
*
|
|
758
|
+
* `state.sessions[key]` is a session id, not a record, so the order is by last
|
|
759
|
+
* use — the bridge records it in `state.lastKey` whenever it starts a turn. With
|
|
760
|
+
* no session at all (a fresh install that never talked) a notice is pointless,
|
|
761
|
+
* and nothing is sent.
|
|
762
|
+
*/
|
|
763
|
+
function lastTurnTarget() {
|
|
764
|
+
const key = typeof state.lastKey === 'string' ? state.lastKey : '';
|
|
765
|
+
const [chat, thread] = key.split(':');
|
|
766
|
+
const chatId = Number(chat);
|
|
767
|
+
if (!Number.isInteger(chatId) || chatId <= 0) return null;
|
|
768
|
+
return { chatId, threadId: Number(thread) || 0 };
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* The forum topic's own title, for a card that has to say where it is.
|
|
773
|
+
*
|
|
774
|
+
* One API call per topic, then cached for the life of the process: a rename
|
|
775
|
+
* shows up on the next restart, which is a fair trade for not calling Telegram
|
|
776
|
+
* on every panel edit. A failure caches the empty name — a card is not worth a
|
|
777
|
+
* retry storm — and the caller renders the id alone.
|
|
778
|
+
*/
|
|
779
|
+
const topicNames = new Map();
|
|
780
|
+
function topicName(chatId, threadId) {
|
|
781
|
+
const cacheKey = sessionKey(chatId, threadId);
|
|
782
|
+
if (topicNames.has(cacheKey)) return topicNames.get(cacheKey);
|
|
783
|
+
topicNames.set(cacheKey, '');
|
|
784
|
+
tg('getForumTopic', { chat_id: chatId, message_thread_id: threadId })
|
|
785
|
+
.then((res) => {
|
|
786
|
+
const name = String(res?.name || '').trim();
|
|
787
|
+
if (name) topicNames.set(cacheKey, name);
|
|
788
|
+
})
|
|
789
|
+
.catch(() => {});
|
|
790
|
+
return '';
|
|
791
|
+
}
|
|
792
|
+
|
|
752
793
|
async function send(chatId, text, threadId = 0, replyTo = 0) {
|
|
753
794
|
// Who is reading: the topic's language decides even the fallback line, so an
|
|
754
795
|
// English or Chinese topic never sees a Russian placeholder.
|
|
@@ -1046,6 +1087,11 @@ async function startProgress(chatId, threadId, lang = 'ru', task = '', chip = ''
|
|
|
1046
1087
|
: '';
|
|
1047
1088
|
return progressPanel({
|
|
1048
1089
|
lang,
|
|
1090
|
+
// Two topics run at once in a group, so a card that does not name its topic
|
|
1091
|
+
// is unattributable the moment it scrolls: the same 💭 line in the wrong
|
|
1092
|
+
// place looks like a cross-topic bug, and half the time it is one. The
|
|
1093
|
+
// name comes from Telegram, cached: one API call per topic per process.
|
|
1094
|
+
topic: threadId ? t(lang, 'bridge.progress.topic', { n: threadId, name: topicName(chatId, threadId) || t(lang, 'bridge.progress.topicNoName') }) : '',
|
|
1049
1095
|
seconds: Math.round((Date.now() - started) / 1000),
|
|
1050
1096
|
final,
|
|
1051
1097
|
steps,
|
|
@@ -1566,6 +1612,12 @@ ${t(lang, 'help.body')}`,
|
|
|
1566
1612
|
// (two messages a few seconds apart, or a copy-paste), and the late writer
|
|
1567
1613
|
// then attached a fresh session id to a conversation that already had one.
|
|
1568
1614
|
const sessionAtStart = state.sessions[key];
|
|
1615
|
+
// Remember the topic a turn is running in: it is where a release notice goes,
|
|
1616
|
+
// since a notice is about the install and the install serves every topic.
|
|
1617
|
+
if (state.lastKey !== key) {
|
|
1618
|
+
state.lastKey = key;
|
|
1619
|
+
saveState();
|
|
1620
|
+
}
|
|
1569
1621
|
// Project directory bound to this topic (set with /cd); config.cwd otherwise.
|
|
1570
1622
|
const cwd = (state.cwd && state.cwd[key]) || config.cwd;
|
|
1571
1623
|
// What the person actually wrote, before any injected block: the progress
|
|
@@ -2116,8 +2168,6 @@ async function handleCallback(query) {
|
|
|
2116
2168
|
const messageId = query.message?.message_id;
|
|
2117
2169
|
const threadId = query.message?.message_thread_id ?? 0;
|
|
2118
2170
|
const key = sessionKey(chatId, threadId);
|
|
2119
|
-
// One lookup for every answer: a button press carries no message of its own,
|
|
2120
|
-
// so the language comes from the topic the buttons were posted in.
|
|
2121
2171
|
const lang = resolveLang(state, key, null, config);
|
|
2122
2172
|
const answer = (text, show = false) =>
|
|
2123
2173
|
tg('answerCallbackQuery', { callback_query_id: query.id, text, show_alert: show }).catch(() => {});
|
|
@@ -2138,6 +2188,14 @@ async function handleCallback(query) {
|
|
|
2138
2188
|
const clearKeyboard = () =>
|
|
2139
2189
|
tg('editMessageReplyMarkup', { chat_id: chatId, message_id: messageId, reply_markup: { inline_keyboard: [] } }).catch(() => {});
|
|
2140
2190
|
|
|
2191
|
+
if (data.startsWith('m:')) {
|
|
2192
|
+
// The settings card. Its own answer path, because a tap that redraws or
|
|
2193
|
+
// flips one setting must not go through the defaults below (`clearKeyboard`
|
|
2194
|
+
// would strip the tabs it is about to draw again).
|
|
2195
|
+
await handleCardPress(query, { chatId, messageId, threadId, key, lang });
|
|
2196
|
+
return;
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2141
2199
|
if (data === 'stop') {
|
|
2142
2200
|
const killed = killTurn(key);
|
|
2143
2201
|
await clearKeyboard();
|
|
@@ -2240,6 +2298,126 @@ async function handleCallback(query) {
|
|
|
2240
2298
|
await answer(t(lang, 'bridge.cb.unknown'));
|
|
2241
2299
|
}
|
|
2242
2300
|
|
|
2301
|
+
/**
|
|
2302
|
+
* Answer a button from the settings card.
|
|
2303
|
+
*
|
|
2304
|
+
* Two kinds of press, one rule: the card is a view of the commands.
|
|
2305
|
+
*
|
|
2306
|
+
* - A tab (`m:agent`) redraws the same message as another page.
|
|
2307
|
+
* - A switch or a door (`m:reasoning:on`, `m:model`) runs the command a person
|
|
2308
|
+
* would have typed, through `handleControl`, and then replaces the card with
|
|
2309
|
+
* one plain line saying what changed. The card does not stay: a menu left in
|
|
2310
|
+
* the history is what the person asked to avoid, and one line is easier to
|
|
2311
|
+
* delete than a twelve-row keyboard.
|
|
2312
|
+
*
|
|
2313
|
+
* The press carries no text of its own, which is why `handleMessage` is not this
|
|
2314
|
+
* path's entry point: it would journal, queue and spend a turn on a tap.
|
|
2315
|
+
*/
|
|
2316
|
+
async function handleCardPress(query, ctx) {
|
|
2317
|
+
const { chatId, messageId, threadId, key, lang } = ctx;
|
|
2318
|
+
const data = String(query.data || '');
|
|
2319
|
+
const current = settingsCurrent({ config, state, key, reasoningOf });
|
|
2320
|
+
const updateMode = state.update?.mode || 'check';
|
|
2321
|
+
const wanted = commandFor({ t: (k, vars) => t(lang, k, vars), current, updateMode }, data);
|
|
2322
|
+
|
|
2323
|
+
if (!wanted) {
|
|
2324
|
+
await tg('answerCallbackQuery', { callback_query_id: query.id, text: t(lang, 'settings.card.stale') }).catch(() => {});
|
|
2325
|
+
return;
|
|
2326
|
+
}
|
|
2327
|
+
|
|
2328
|
+
if (wanted.page) {
|
|
2329
|
+
const card = renderSettingsCard({
|
|
2330
|
+
page: wanted.page,
|
|
2331
|
+
t: (k, vars) => t(lang, k, vars),
|
|
2332
|
+
current,
|
|
2333
|
+
updateMode,
|
|
2334
|
+
bound: boundSetOf(key),
|
|
2335
|
+
});
|
|
2336
|
+
await tg('editMessageText', {
|
|
2337
|
+
chat_id: chatId,
|
|
2338
|
+
message_id: messageId,
|
|
2339
|
+
text: card.text,
|
|
2340
|
+
reply_markup: { inline_keyboard: card.keyboard },
|
|
2341
|
+
...(threadId > 0 ? { message_thread_id: threadId } : {}),
|
|
2342
|
+
}).catch((error) => log(`settings card redraw failed: ${error.message}`));
|
|
2343
|
+
await tg('answerCallbackQuery', { callback_query_id: query.id }).catch(() => {});
|
|
2344
|
+
return;
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
// Run the command. Whatever it answers goes in the log and, by default, not
|
|
2348
|
+
// in the chat: the one line below is the chat's share of this press. Only a
|
|
2349
|
+
// command that failed says more than that.
|
|
2350
|
+
const replies = [];
|
|
2351
|
+
const [head, ...rest] = wanted.command.split(/\s+/);
|
|
2352
|
+
const handled = await handleControl({
|
|
2353
|
+
command: head,
|
|
2354
|
+
arg: rest.join(' '),
|
|
2355
|
+
text: wanted.command,
|
|
2356
|
+
lang,
|
|
2357
|
+
chatId,
|
|
2358
|
+
threadId,
|
|
2359
|
+
key,
|
|
2360
|
+
state,
|
|
2361
|
+
config,
|
|
2362
|
+
activeTurns,
|
|
2363
|
+
saveState,
|
|
2364
|
+
log,
|
|
2365
|
+
send: (text) => {
|
|
2366
|
+
replies.push(String(text ?? ''));
|
|
2367
|
+
return Promise.resolve(0);
|
|
2368
|
+
},
|
|
2369
|
+
reply: (text) => {
|
|
2370
|
+
replies.push(String(text ?? ''));
|
|
2371
|
+
return Promise.resolve(0);
|
|
2372
|
+
},
|
|
2373
|
+
jobs: () => ({ active: [], queued: 0, max: MAX_PARALLEL }),
|
|
2374
|
+
api: tg,
|
|
2375
|
+
sendFile: () => Promise.resolve(0),
|
|
2376
|
+
profile: profileOf(key),
|
|
2377
|
+
prices: () => Promise.resolve(''),
|
|
2378
|
+
}).catch((error) => {
|
|
2379
|
+
log(`settings press ${data} failed: ${error.message}`);
|
|
2380
|
+
replies.push(error.message);
|
|
2381
|
+
return true;
|
|
2382
|
+
});
|
|
2383
|
+
|
|
2384
|
+
const changed = Boolean(wanted.value);
|
|
2385
|
+
const answerText = changed
|
|
2386
|
+
? t(lang, 'settings.card.changed', { label: wanted.label, value: wanted.value })
|
|
2387
|
+
: t(lang, 'settings.card.door', { command: wanted.command });
|
|
2388
|
+
|
|
2389
|
+
// The card becomes the line: the buttons go away with the text they described.
|
|
2390
|
+
await tg('editMessageText', {
|
|
2391
|
+
chat_id: chatId,
|
|
2392
|
+
message_id: messageId,
|
|
2393
|
+
text: answerText,
|
|
2394
|
+
...(threadId > 0 ? { message_thread_id: threadId } : {}),
|
|
2395
|
+
}).catch(() => {});
|
|
2396
|
+
await tg('answerCallbackQuery', { callback_query_id: query.id }).catch(() => {});
|
|
2397
|
+
|
|
2398
|
+
// A door that opened to nothing (an unknown set id, a command that is not
|
|
2399
|
+
// allowed here) still has something to say; it goes under the line, once.
|
|
2400
|
+
if (!handled) log(`settings press ${data}: no handler answered`);
|
|
2401
|
+
const notLine = replies.filter(Boolean).filter((r) => r !== answerText);
|
|
2402
|
+
if (notLine.length > 0 && !changed) {
|
|
2403
|
+
await send(chatId, notLine[0], threadId).catch(() => {});
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
/**
|
|
2408
|
+
* The set bound to this topic, for the card that names it. Read through the
|
|
2409
|
+
* agentset store the commands use, so the card never keeps a second copy.
|
|
2410
|
+
*/
|
|
2411
|
+
function boundSetOf(key) {
|
|
2412
|
+
const id = state.agentsets?.[key];
|
|
2413
|
+
if (!id) return null;
|
|
2414
|
+
try {
|
|
2415
|
+
return new AgentsetStore(join(DIR, 'agentsets.json')).load().get(id) || null;
|
|
2416
|
+
} catch {
|
|
2417
|
+
return null;
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2243
2421
|
/**
|
|
2244
2422
|
* Turn runner with an IDLE deadline and a live progress sink.
|
|
2245
2423
|
*
|
|
@@ -2509,7 +2687,53 @@ async function main() {
|
|
|
2509
2687
|
}
|
|
2510
2688
|
|
|
2511
2689
|
let pollFailures = 0;
|
|
2690
|
+
// Release and failure notices ride the poll loop's own idle: they are one
|
|
2691
|
+
// message every few hours at most, and a timer would keep the process awake
|
|
2692
|
+
// for nothing. The first check runs a few minutes after a start, so a
|
|
2693
|
+
// restarting machine does not hit the registry on every boot.
|
|
2694
|
+
const notice = { mode: '', startAt: Date.now() + 3 * 60 * 1000 };
|
|
2695
|
+
const noticeMode = () => (state.update && typeof state.update.mode === 'string' ? state.update.mode : 'check');
|
|
2696
|
+
/** Where a notice goes: the chat that last ran a turn. */
|
|
2697
|
+
const noticeTarget = () => lastTurnTarget();
|
|
2698
|
+
const maybeNotice = async () => {
|
|
2699
|
+
try {
|
|
2700
|
+
const target = noticeTarget();
|
|
2701
|
+
if (!target) return;
|
|
2702
|
+
const mode = noticeMode();
|
|
2703
|
+
const checkedAt = Number(state.update?.checkedAt) || 0;
|
|
2704
|
+
if (mode === 'off' || !dueForCheck({ mode, checkedAt, now: Date.now() })) return;
|
|
2705
|
+
// One attempt per interval, even if it fails: an offline laptop must not
|
|
2706
|
+
// retry the registry on every poll.
|
|
2707
|
+
state.update = { ...(state.update || {}), checkedAt: Date.now() };
|
|
2708
|
+
saveState();
|
|
2709
|
+
const latest = await npmLatestAsync();
|
|
2710
|
+
if (!latest) return;
|
|
2711
|
+
const lang = langFor(target.chatId, target.threadId);
|
|
2712
|
+
const result = updateState({ installed: bridgeVersion(), latest, mode, notified: state.update?.notified || '' });
|
|
2713
|
+
if (result.auto) {
|
|
2714
|
+
// The files change, the running process does not: the person still says
|
|
2715
|
+
// when the new code loads, so a bad release never arrives mid-chat.
|
|
2716
|
+
const backup = installRelease(latest);
|
|
2717
|
+
state.update = { ...(state.update || {}), notified: latest };
|
|
2718
|
+
saveState();
|
|
2719
|
+
await send(target.chatId, t(lang, 'ctrl.update.done', { v: latest }) + '\n' + t(lang, 'ctrl.update.backup', { path: join(DIR, backup) }), target.threadId);
|
|
2720
|
+
return;
|
|
2721
|
+
}
|
|
2722
|
+
if (!result.notify) return;
|
|
2723
|
+
state.update = { ...(state.update || {}), notified: latest };
|
|
2724
|
+
saveState();
|
|
2725
|
+
await send(target.chatId, t(lang, 'ctrl.subscribe.notice', { v: latest }), target.threadId);
|
|
2726
|
+
} catch (error) {
|
|
2727
|
+
log(`update notice skipped: ${error.message}`);
|
|
2728
|
+
}
|
|
2729
|
+
};
|
|
2512
2730
|
for (;;) {
|
|
2731
|
+
if (Date.now() >= notice.startAt) {
|
|
2732
|
+
notice.startAt = Date.now() + 15 * 60 * 1000;
|
|
2733
|
+
if (notice.mode !== noticeMode()) notice.startAt = Date.now() + 3 * 60 * 1000;
|
|
2734
|
+
notice.mode = noticeMode();
|
|
2735
|
+
void maybeNotice();
|
|
2736
|
+
}
|
|
2513
2737
|
try {
|
|
2514
2738
|
// `callback_query` is required for inline buttons: without it Telegram
|
|
2515
2739
|
// never delivers button presses, so «Стоп» would draw but do nothing.
|
package/cli.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// dsh-tg — CLI entrypoint for the Telegram bridge of DeepSeek Harness.
|
|
3
3
|
//
|
|
4
|
-
// npx dsh-tg init --token <T> --user <ID> write config + credentials, no editing
|
|
5
|
-
// npx dsh-tg setup install/restart the bridge
|
|
6
|
-
// npx dsh-tg check diagnostics only, changes nothing
|
|
7
|
-
// npx dsh-tg doctor supervisor report (pid, log tail)
|
|
8
|
-
// npx dsh-tg menu register the bot command menu
|
|
9
|
-
// npx dsh-tg start run the bridge in the foreground
|
|
4
|
+
// npx dsh-tg-bridge init --token <T> --user <ID> write config + credentials, no editing
|
|
5
|
+
// npx dsh-tg-bridge setup install/restart the bridge
|
|
6
|
+
// npx dsh-tg-bridge check diagnostics only, changes nothing
|
|
7
|
+
// npx dsh-tg-bridge doctor supervisor report (pid, log tail)
|
|
8
|
+
// npx dsh-tg-bridge menu register the bot command menu
|
|
9
|
+
// npx dsh-tg-bridge start run the bridge in the foreground
|
|
10
10
|
//
|
|
11
11
|
// The goal of `init` is a cold start with ONE command: the person pastes the
|
|
12
12
|
// bot token and their numeric id, and nothing else needs hand-editing.
|
|
@@ -75,6 +75,12 @@ function flag(name, fallback = '') {
|
|
|
75
75
|
const help = `
|
|
76
76
|
dsh-tg ${pkg.version} — Telegram bridge for DeepSeek Harness
|
|
77
77
|
|
|
78
|
+
Install once, then use the short name:
|
|
79
|
+
npm i -g dsh-tg-bridge → dsh-tg setup
|
|
80
|
+
Without installing, run the same things through npx (the PACKAGE name, not the
|
|
81
|
+
command name — \`npx dsh-tg\` alone does not resolve):
|
|
82
|
+
npx dsh-tg-bridge@latest setup
|
|
83
|
+
|
|
78
84
|
dsh-tg init --token <bot-token> --user <your-id> настроить всё одной командой
|
|
79
85
|
dsh-tg setup установить и перезапустить мост (setup.log хранит шаги)
|
|
80
86
|
dsh-tg check диагностика, ничего не меняет
|
|
@@ -216,7 +222,7 @@ switch (cmd) {
|
|
|
216
222
|
case 'doctor': run('bridge-kick.mjs', rest); break;
|
|
217
223
|
case 'menu': run('bot-menu.mjs', rest); break;
|
|
218
224
|
case 'start': run('bridge.mjs', rest, { sync: true }); break;
|
|
219
|
-
case 'version': console.log(pkg.version); break;
|
|
225
|
+
case 'version': case '--version': case '-v': console.log(pkg.version); break;
|
|
220
226
|
case 'help': case '--help': case '-h': console.log(help); break;
|
|
221
227
|
default:
|
|
222
228
|
console.error(`unknown command: ${cmd}`);
|