dsh-tg-bridge 1.18.0 → 1.19.1
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 +1 -1
- package/README.md +11 -8
- package/bot-menu.mjs +0 -12
- package/bridge.mjs +117 -72
- package/control.mjs +142 -11
- package/failures.mjs +44 -0
- package/help-explain.mjs +20 -13
- package/i18n.mjs +1945 -1891
- package/menu-card.mjs +222 -84
- package/model-probe.mjs +46 -4
- package/package.json +3 -1
- package/plugin-search.mjs +46 -0
- package/rewind.mjs +94 -8
- package/skills/dsh-tg-bridge-onboarding/SKILL.md +1 -1
package/QUICKSTART.md
CHANGED
|
@@ -82,7 +82,7 @@ Everything below is typed in the chat, not in a terminal.
|
|
|
82
82
|
| Cheaper or stronger model | `/model` then pick, or `/model <id>` |
|
|
83
83
|
| More freedom for commands | `/permissions` |
|
|
84
84
|
| See what it is doing | it posts a live progress message; `/thoughts` toggles the 💭 notes |
|
|
85
|
-
| A plan you can tick off | `/goal <what done looks like>`, then `/task <step>`, then `/
|
|
85
|
+
| A plan you can tick off | `/goal <what done looks like>`, then `/task <step>`, then bare `/task` to tap items |
|
|
86
86
|
| Stop a long answer | `/stop` |
|
|
87
87
|
| Tell me about new versions, or stop | /update on / /update off — neither one installs anything |
|
|
88
88
|
| Install an update, then load it | /update confirm, then /restart confirm |
|
package/README.md
CHANGED
|
@@ -22,9 +22,9 @@ a bot that answers, one step at a time.
|
|
|
22
22
|
the model's reasoning in a collapsed block you can tap open. A long turn adds a second
|
|
23
23
|
collapsed block with every tool call, so the whole run stays in the chat as one message.
|
|
24
24
|
- **No lost messages**: a journal with acknowledgement and replay.
|
|
25
|
-
- **Settings per topic**: `/
|
|
25
|
+
- **Settings per topic**: `/crew use reviewer` gives one topic its own model,
|
|
26
26
|
effort, permissions, agent preset and language while the others keep the profile;
|
|
27
|
-
`/
|
|
27
|
+
`/crew 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
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`.
|
|
@@ -165,6 +165,7 @@ Error replies end with a code, which tells you what to fix:
|
|
|
165
165
|
| `SANDBOX_DENY` | DSH denied access to a file or directory: check the project path and permissions |
|
|
166
166
|
| `UNKNOWN_MODEL` | the model from the config is unavailable: `/model` lists the working ones |
|
|
167
167
|
| `EMPTY_RESPONSE` | the model returned nothing: retry or switch model (`/model`) |
|
|
168
|
+
| `TURN_TIME_CAP` | the turn hit its own time ceiling: the work is saved, press Continue |
|
|
168
169
|
| `TURN_FAILED` | cause not recognized: `/doctor` and `/logs errors` |
|
|
169
170
|
|
|
170
171
|
## Checks
|
|
@@ -185,14 +186,14 @@ Send the bot:
|
|
|
185
186
|
|
|
186
187
|
```
|
|
187
188
|
Work: /cd · /new · /stop · /send · /seed
|
|
188
|
-
Goals: /goal · /task · /
|
|
189
|
+
Goals: /goal · /task · /task done|rm <n>
|
|
189
190
|
Sessions: /status · /sessions · /resume
|
|
190
191
|
Agents: /agents · /agents <id> · /agents set model|depth|filter
|
|
191
|
-
Models: /model · /model <id> · /
|
|
192
|
+
Models: /model · /model <id> · /prices
|
|
192
193
|
Tuning: /effort · /permissions · /preset · /plan · /jobs · /remind
|
|
193
194
|
Profiles: /profile · /profile <name> · /profile new <name> from <template>
|
|
194
|
-
Sets: /
|
|
195
|
-
Extensions: /skills · /plugins · /
|
|
195
|
+
Sets: /crew · /crew use|off|new|copy|rm · /crew model <v>
|
|
196
|
+
Extensions: /skills · /plugins · /plugins search <word> · /plugins disable|enable <id> · /soul
|
|
196
197
|
Updates: /version · /update · /update confirm · /update on|off|check|auto · /subscribe on|off
|
|
197
198
|
Diagnostics: /doctor · /logs [errors|N|text]
|
|
198
199
|
Service: /app · /restart · /help
|
|
@@ -212,7 +213,7 @@ delete it and the chat is back to what it was.
|
|
|
212
213
|
|
|
213
214
|
Nothing on the card is only available on the card. `/settings` is for people who
|
|
214
215
|
would rather press a labelled button than remember which of `/effort`,
|
|
215
|
-
`/preset` and `/
|
|
216
|
+
`/preset` and `/crew` changes what.
|
|
216
217
|
|
|
217
218
|
Every command answers `/help` in the chat, in the language you write in: a
|
|
218
219
|
message written in Cyrillic or Han characters switches the topic to Russian or
|
|
@@ -395,7 +396,9 @@ plugin set and model. The same switch works from a topic:
|
|
|
395
396
|
A new profile is written by `dsh <name> --from-default-profile <template> --dump-config`, so
|
|
396
397
|
nothing boots and no plugin is loaded at creation time; dependencies are installed by the
|
|
397
398
|
profile's first turn. The binding is per topic: `/model` then edits that profile's model, and
|
|
398
|
-
`/plugins` manages that profile's rows
|
|
399
|
+
`/plugins` manages that profile's rows, and `/plugins search <word>` lists what the npm registry
|
|
400
|
+
has with the `dsh-plugin` keyword — the desktop app's plugin browser, from the chat. Each result
|
|
401
|
+
carries a plus button that runs `/plugins add <name>`.
|
|
399
402
|
|
|
400
403
|
### Goals and tasks
|
|
401
404
|
|
package/bot-menu.mjs
CHANGED
|
@@ -38,15 +38,12 @@ const COMMANDS = [
|
|
|
38
38
|
{ command: 'seed', description: 'Засеять пустую тему текстом и закрепить' },
|
|
39
39
|
{ command: 'goal', description: 'Цель темы: /goal <текст>, /goal done' },
|
|
40
40
|
{ command: 'task', description: 'Задачи: /task <текст>, /task done <n>' },
|
|
41
|
-
{ command: 'tasks', description: 'Список задач кнопками: нажатие закрывает' },
|
|
42
41
|
{ command: 'sessions', description: 'Сессии темы — обычный текст продолжает последнюю' },
|
|
43
42
|
{ command: 'resume', description: 'Продолжить сессию: /resume <id>' },
|
|
44
43
|
{ command: 'model', description: 'Показать или сменить: /model, /model <id>' },
|
|
45
|
-
{ command: 'models', description: 'Все модели профиля и цены' },
|
|
46
44
|
{ command: 'skills', description: 'Скиллы: список или текст одного' },
|
|
47
45
|
{ command: 'soul', description: 'Персона: показать или задать' },
|
|
48
46
|
{ command: 'plugins', description: 'Список, add, remove, disable, enable — всё здесь' },
|
|
49
|
-
{ command: 'plugin', description: 'Старая форма /plugins — то же самое' },
|
|
50
47
|
{ command: 'app', description: 'Приложение DSH, не мост: /app restart confirm' },
|
|
51
48
|
{ command: 'restart', description: 'Перезапуск моста: /restart confirm' },
|
|
52
49
|
{ command: 'doctor', description: 'Диагностика: мост, сеть, диск, плагины, сессия' },
|
|
@@ -59,7 +56,6 @@ const COMMANDS = [
|
|
|
59
56
|
{ command: 'reasoning', description: 'Заметки по ходу: /reasoning on|off' },
|
|
60
57
|
{ command: 'profile', description: 'Профиль темы: /profile <имя>, /profile new' },
|
|
61
58
|
{ command: 'agents', description: 'Агенты и субагенты: кто, на какой модели, кого запускали' },
|
|
62
|
-
{ command: 'agentset', description: 'Набор настроек темы: модель, права, пресет одним переключателем' },
|
|
63
59
|
{ command: 'effort', description: 'Усилие рассуждения модели: /effort high' },
|
|
64
60
|
{ command: 'permissions', description: 'Права профиля: пресет песочницы и подтверждений' },
|
|
65
61
|
{ command: 'preset', description: 'Пресет агента (персона и инструменты): /preset <id>' },
|
|
@@ -82,15 +78,12 @@ const COMMANDS_EN = [
|
|
|
82
78
|
{ command: 'seed', description: 'Seed an empty topic with text and pin it' },
|
|
83
79
|
{ command: 'goal', description: 'Topic goal: /goal <text>, /goal done' },
|
|
84
80
|
{ command: 'task', description: 'Checklist: /task <text>, /task done <n>' },
|
|
85
|
-
{ command: 'tasks', description: 'Task list as buttons: tap to close' },
|
|
86
81
|
{ command: 'sessions', description: 'Sessions of this topic — plain text continues the last one' },
|
|
87
82
|
{ command: 'resume', description: 'Continue a session: /resume <id>' },
|
|
88
83
|
{ command: 'model', description: 'Show or switch: /model, /model <id>' },
|
|
89
|
-
{ command: 'models', description: 'All models of this profile with prices' },
|
|
90
84
|
{ command: 'skills', description: 'Installed skills' },
|
|
91
85
|
{ command: 'soul', description: 'Agent persona' },
|
|
92
86
|
{ command: 'plugins', description: 'List, add, remove, disable, enable — all here' },
|
|
93
|
-
{ command: 'plugin', description: 'Старая форма /plugins — то же самое' },
|
|
94
87
|
{ command: 'app', description: 'DSH desktop app (not the bridge)' },
|
|
95
88
|
{ command: 'restart', description: 'Restart the bridge: /restart confirm' },
|
|
96
89
|
{ command: 'doctor', description: 'Diagnostics: bridge, network, disk, plugins, session' },
|
|
@@ -103,7 +96,6 @@ const COMMANDS_EN = [
|
|
|
103
96
|
{ command: 'reasoning', description: 'Working notes: /reasoning on|off' },
|
|
104
97
|
{ command: 'profile', description: 'Topic profile: /profile <name>, /profile new' },
|
|
105
98
|
{ command: 'agents', description: 'Agents and subagents: who runs, on which model, who was spawned' },
|
|
106
|
-
{ command: 'agentset', description: 'Named settings for this topic: model, permissions, preset in one switch' },
|
|
107
99
|
{ command: 'effort', description: 'Reasoning effort: /effort high' },
|
|
108
100
|
{ command: 'permissions', description: 'Profile permissions: sandbox and approval preset' },
|
|
109
101
|
{ command: 'preset', description: 'Agent preset (persona and tools): /preset <id>' },
|
|
@@ -126,15 +118,12 @@ const COMMANDS_ZH = [
|
|
|
126
118
|
{ command: 'seed', description: '用文本初始化空话题并置顶' },
|
|
127
119
|
{ command: 'goal', description: '本话题目标:/goal <文本>、/goal done' },
|
|
128
120
|
{ command: 'task', description: '任务清单:/task <文本>、/task done <n>' },
|
|
129
|
-
{ command: 'tasks', description: '任务列表按钮:点击即完成' },
|
|
130
121
|
{ command: 'sessions', description: '本主题的会话 —— 直接发文字会延续最近一个' },
|
|
131
122
|
{ command: 'resume', description: '继续会话:/resume <id>' },
|
|
132
123
|
{ command: 'model', description: '查看或切换:/model, /model <id>' },
|
|
133
|
-
{ command: 'models', description: '本配置档的全部模型与价格' },
|
|
134
124
|
{ command: 'skills', description: '已安装的技能' },
|
|
135
125
|
{ command: 'soul', description: '代理人格设定' },
|
|
136
126
|
{ command: 'plugins', description: '列表、add、remove、disable、enable 都在这里' },
|
|
137
|
-
{ command: 'plugin', description: 'Старая форма /plugins — то же самое' },
|
|
138
127
|
{ command: 'app', description: 'DSH 桌面应用(不是桥接)' },
|
|
139
128
|
{ command: 'restart', description: '重启桥接:/restart confirm' },
|
|
140
129
|
{ command: 'doctor', description: '诊断:桥接、网络、磁盘、插件、会话' },
|
|
@@ -147,7 +136,6 @@ const COMMANDS_ZH = [
|
|
|
147
136
|
{ command: 'reasoning', description: '工作记录:/reasoning on|off' },
|
|
148
137
|
{ command: 'profile', description: '话题配置档:/profile <名称>,/profile new' },
|
|
149
138
|
{ command: 'agents', description: '智能体与子智能体:谁在运行、用什么模型、启动过谁' },
|
|
150
|
-
{ command: 'agentset', description: '本话题的命名设置:模型、权限、预设一键切换' },
|
|
151
139
|
{ command: 'effort', description: '推理力度:/effort high' },
|
|
152
140
|
{ command: 'permissions', description: '配置档权限:沙箱与确认预设' },
|
|
153
141
|
{ command: 'preset', description: '智能体预设(人格与工具):/preset <id>' },
|
package/bridge.mjs
CHANGED
|
@@ -31,6 +31,7 @@ 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 { firstLiveModel, describeVerdicts, probeHint, probeModel } from './model-probe.mjs';
|
|
34
|
+
import { explainFailure } from './failures.mjs';
|
|
34
35
|
import { handleControl, CONTROL_COMMANDS, modelOf, modelsOf, reasoningOf } from './control.mjs';
|
|
35
36
|
import { bridgeVersion, installRelease, npmLatestAsync } from './control.mjs';
|
|
36
37
|
import { dueForCheck, updateState } from './update-policy.mjs';
|
|
@@ -48,7 +49,7 @@ import { commandFor, renderSettingsCard, settingsCurrent } from './settings-card
|
|
|
48
49
|
import { answerRewindPress, cutSession, isRewindPress } from './rewind-buttons.mjs';
|
|
49
50
|
import { applyRewind, newestBackup, restoreBackup } from './rewind.mjs';
|
|
50
51
|
import { sessionFile } from './thoughts.mjs';
|
|
51
|
-
import { MENU_PREFIX, commandForName, isMenuPress, renderPanel, runsUnasked } from './menu-card.mjs';
|
|
52
|
+
import { MENU_PREFIX, commandForName, isMenuPress, keyboardCommand, menuTarget, renderPanel, runsUnasked } from './menu-card.mjs';
|
|
52
53
|
|
|
53
54
|
const HOME = homedir();
|
|
54
55
|
const DSH_HOME = process.env.DSH_HOME || join(HOME, '.dsh');
|
|
@@ -803,6 +804,42 @@ function topicName(chatId, threadId) {
|
|
|
803
804
|
* a button cannot do is money or state the person did not mean — so a press
|
|
804
805
|
* never falls through to an AI turn.
|
|
805
806
|
*/
|
|
807
|
+
/**
|
|
808
|
+
* A message that carries buttons. Inline rows are the usual case; a persistent
|
|
809
|
+
* reply keyboard (`/menu on`) and taking it away again are the two other markup
|
|
810
|
+
* shapes a person can end up with, so every call site hands its intent here
|
|
811
|
+
* instead of building `reply_markup` itself.
|
|
812
|
+
*/
|
|
813
|
+
async function sendWithMarkup(chatId, threadId, text, extra = {}) {
|
|
814
|
+
const thread = threadId > 0 ? { message_thread_id: threadId } : {};
|
|
815
|
+
if (extra.removeKeyboard) {
|
|
816
|
+
return tg('sendMessage', {
|
|
817
|
+
chat_id: chatId,
|
|
818
|
+
text,
|
|
819
|
+
reply_markup: { remove_keyboard: true },
|
|
820
|
+
...thread,
|
|
821
|
+
}).catch(() => {});
|
|
822
|
+
}
|
|
823
|
+
if (extra.persistent) {
|
|
824
|
+
return tg('sendMessage', {
|
|
825
|
+
chat_id: chatId,
|
|
826
|
+
text,
|
|
827
|
+
reply_markup: { keyboard: extra.persistent, resize_keyboard: true, is_persistent: true },
|
|
828
|
+
...thread,
|
|
829
|
+
}).catch(() => {});
|
|
830
|
+
}
|
|
831
|
+
if (extra.keyboard) {
|
|
832
|
+
return tg('sendMessage', {
|
|
833
|
+
chat_id: chatId,
|
|
834
|
+
text,
|
|
835
|
+
disable_web_page_preview: true,
|
|
836
|
+
reply_markup: { inline_keyboard: extra.keyboard },
|
|
837
|
+
...thread,
|
|
838
|
+
}).catch(() => {});
|
|
839
|
+
}
|
|
840
|
+
return send(chatId, text, threadId);
|
|
841
|
+
}
|
|
842
|
+
|
|
806
843
|
async function runCommandFromButton(typed, { chatId, threadId, key }) {
|
|
807
844
|
const lang = langFor(chatId, threadId);
|
|
808
845
|
const [head, ...rest] = typed.trim().split(/\s+/);
|
|
@@ -830,15 +867,7 @@ async function runCommandFromButton(typed, { chatId, threadId, key }) {
|
|
|
830
867
|
sendFile: (p, caption = '') => sendFile(chatId, threadId, p, caption),
|
|
831
868
|
seedTopic: ensureTopicSeed,
|
|
832
869
|
profile: profileOf(key),
|
|
833
|
-
reply: (out, extra = {}) => (extra
|
|
834
|
-
? tg('sendMessage', {
|
|
835
|
-
chat_id: chatId,
|
|
836
|
-
text: out,
|
|
837
|
-
disable_web_page_preview: true,
|
|
838
|
-
reply_markup: { inline_keyboard: extra.keyboard },
|
|
839
|
-
...(threadId > 0 ? { message_thread_id: threadId } : {}),
|
|
840
|
-
}).catch(() => {})
|
|
841
|
-
: send(chatId, out, threadId)),
|
|
870
|
+
reply: (out, extra = {}) => sendWithMarkup(chatId, threadId, out, extra),
|
|
842
871
|
stopTurn: (k) => {
|
|
843
872
|
const child = activeTurns.get(k);
|
|
844
873
|
if (!child) return false;
|
|
@@ -1556,6 +1585,20 @@ async function handleMessage(msg, album = null) {
|
|
|
1556
1585
|
}
|
|
1557
1586
|
}
|
|
1558
1587
|
|
|
1588
|
+
// A tap on the persistent keyboard (`/menu on`) arrives as its own label,
|
|
1589
|
+
// with no slash: "Меню", "Статус", "Стоп", "Новый". Only while the keyboard is
|
|
1590
|
+
// on — the same word typed by hand is a prompt, not a command. The label is
|
|
1591
|
+
// matched in every language, because the keyboard outlives a /lang switch.
|
|
1592
|
+
if (state.menu?.[key]) {
|
|
1593
|
+
const mapped = ['ru', 'en', 'zh']
|
|
1594
|
+
.map((code) => keyboardCommand(text, { t: (k, v) => t(code, k, v) }))
|
|
1595
|
+
.find(Boolean);
|
|
1596
|
+
if (mapped) {
|
|
1597
|
+
log(`menu key "${text}" -> ${mapped} for ${key}`);
|
|
1598
|
+
text = mapped;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1559
1602
|
const space = text.indexOf(' ');
|
|
1560
1603
|
const head = space === -1 ? text : text.slice(0, space);
|
|
1561
1604
|
const command = commandOf(head);
|
|
@@ -1640,15 +1683,7 @@ ${t(lang, 'help.body')}`,
|
|
|
1640
1683
|
lang,
|
|
1641
1684
|
});
|
|
1642
1685
|
},
|
|
1643
|
-
reply: (out, extra = {}) => (extra
|
|
1644
|
-
? tg('sendMessage', {
|
|
1645
|
-
chat_id: chatId,
|
|
1646
|
-
text: out,
|
|
1647
|
-
disable_web_page_preview: true,
|
|
1648
|
-
reply_markup: { inline_keyboard: extra.keyboard },
|
|
1649
|
-
...(threadId > 0 ? { message_thread_id: threadId } : {}),
|
|
1650
|
-
}).catch(() => {})
|
|
1651
|
-
: send(chatId, out, threadId)),
|
|
1686
|
+
reply: (out, extra = {}) => sendWithMarkup(chatId, threadId, out, extra),
|
|
1652
1687
|
stopTurn: (k) => {
|
|
1653
1688
|
const child = activeTurns.get(k);
|
|
1654
1689
|
if (!child) return false;
|
|
@@ -1735,7 +1770,7 @@ ${t(lang, 'help.body')}`,
|
|
|
1735
1770
|
log(` tool[${telemetry.steps}] ${(stepLine(event) || event.tool || 'tool').slice(0, 140)}`);
|
|
1736
1771
|
} else if (event.type === 'tool_result') {
|
|
1737
1772
|
const failed = event.status && event.status !== 'completed';
|
|
1738
|
-
log(` tool[${telemetry.steps}] ${failed ? '
|
|
1773
|
+
log(` tool[${telemetry.steps}] ${failed ? 'ERROR' : 'ok'} ${String(event.tool || '').slice(0, 40)}`);
|
|
1739
1774
|
} else if (event.type === 'status' && event.usage) {
|
|
1740
1775
|
if (Number.isFinite(event.usage.inputTokens)) telemetry.inputTokens = event.usage.inputTokens;
|
|
1741
1776
|
if (Number.isFinite(event.usage.cacheReadTokens)) telemetry.cacheReadTokens = event.usage.cacheReadTokens;
|
|
@@ -1890,39 +1925,6 @@ ${t(lang, 'help.body')}`,
|
|
|
1890
1925
|
// `probeHint` lives in model-probe.mjs: this file used it at the call site and
|
|
1891
1926
|
// defined it below, and the hint never reached the person.
|
|
1892
1927
|
|
|
1893
|
-
/**
|
|
1894
|
-
* Turn a raw CLI/provider error into `CODE` plus one actionable line.
|
|
1895
|
-
*
|
|
1896
|
-
* Raw text like `AUTH 403 insufficient_user_quota` means nothing to a person on
|
|
1897
|
-
* a phone; the code makes the failure greppable and the hint says what to do.
|
|
1898
|
-
*/
|
|
1899
|
-
function explainFailure(text, lang = 'ru') {
|
|
1900
|
-
const raw = String(text);
|
|
1901
|
-
// The regular expressions match the CLI's and the provider's own words, so
|
|
1902
|
-
// they stay as they are; only the hint on the right follows the topic language.
|
|
1903
|
-
const cases = [
|
|
1904
|
-
[/insufficient_user_quota|insufficient quota|AUTH\b|\b402\b|\bbalance\b|баланс|billing/i,
|
|
1905
|
-
'INSUFFICIENT_QUOTA', 'bridge.fail.quota'],
|
|
1906
|
-
[/Conflict: terminated by other getUpdates|\b409\b/i,
|
|
1907
|
-
'TG_CONFLICT', 'bridge.fail.conflict'],
|
|
1908
|
-
[/MISSING_CREDENTIAL|no credentials|not authenticated/i,
|
|
1909
|
-
'MISSING_CREDENTIAL', 'bridge.fail.noCredential'],
|
|
1910
|
-
[/ENOENT|not recognized|не найден.*dsh|dsh\.cmd/i,
|
|
1911
|
-
'NO_DSH_CLI', 'bridge.fail.noCli'],
|
|
1912
|
-
[/fetch failed|ETIMEDOUT|ECONNREFUSED|ENOTFOUND|socket hang up|network/i,
|
|
1913
|
-
'NETWORK', 'bridge.fail.network'],
|
|
1914
|
-
[/EACCES|EPERM|access is denied|отказано в доступе|sandbox|permission denied/i,
|
|
1915
|
-
'SANDBOX_DENY', 'bridge.fail.sandbox'],
|
|
1916
|
-
[/UNKNOWN_MODEL|model not found|no such model/i,
|
|
1917
|
-
'UNKNOWN_MODEL', 'bridge.fail.unknownModel'],
|
|
1918
|
-
[/empty response|EMPTY_RESPONSE|no output|пустой ответ/i,
|
|
1919
|
-
'EMPTY_RESPONSE', 'bridge.fail.empty'],
|
|
1920
|
-
];
|
|
1921
|
-
for (const [re, code, hint] of cases) {
|
|
1922
|
-
if (re.test(raw)) return `${raw}\n\n${code}: ${t(lang, hint)}`;
|
|
1923
|
-
}
|
|
1924
|
-
return `${raw}\n\nTURN_FAILED: ${t(lang, 'bridge.fail.generic')}`;
|
|
1925
|
-
}
|
|
1926
1928
|
|
|
1927
1929
|
// Per-topic turn queues: one turn at a time inside a topic, different topics run
|
|
1928
1930
|
// in parallel. Bounded, because every turn is a full Electron process.
|
|
@@ -2347,27 +2349,70 @@ async function handleCallback(query) {
|
|
|
2347
2349
|
return;
|
|
2348
2350
|
}
|
|
2349
2351
|
|
|
2352
|
+
// A search result's plus button. The name came from the registry and the
|
|
2353
|
+
// command is the one the hint under the list names, so a tap installs exactly
|
|
2354
|
+
// what was read — no hidden second path into pnpm.
|
|
2355
|
+
if (data.startsWith('pl:i:')) {
|
|
2356
|
+
const wanted = data.slice(5);
|
|
2357
|
+
if (!/^(@[a-z0-9._-]+\/)?[a-z0-9._-]+$/i.test(wanted)) {
|
|
2358
|
+
await answer(t(lang, 'bridge.cb.unknown'));
|
|
2359
|
+
return;
|
|
2360
|
+
}
|
|
2361
|
+
await clearKeyboard();
|
|
2362
|
+
await answer(`/plugin add ${wanted}`);
|
|
2363
|
+
log(`plugin install via button: ${wanted}`);
|
|
2364
|
+
await runCommandFromButton(`/plugin add ${wanted}`, { chatId, threadId, key, lang });
|
|
2365
|
+
return;
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
if (data.startsWith('fk:')) {
|
|
2369
|
+
// A branch button from /branches. It does what `/resume <id>` does, so the
|
|
2370
|
+
// topic moves onto that branch and the answer comes from the command
|
|
2371
|
+
// itself — one implementation, one sentence.
|
|
2372
|
+
const wanted = data.slice(3);
|
|
2373
|
+
if (!/^session-[0-9a-f-]{36}$/.test(wanted)) {
|
|
2374
|
+
await answer(t(lang, 'bridge.cb.unknown'));
|
|
2375
|
+
return;
|
|
2376
|
+
}
|
|
2377
|
+
await clearKeyboard();
|
|
2378
|
+
await runCommandFromButton(`/resume ${wanted.slice(8)}`, { chatId, threadId, key, lang });
|
|
2379
|
+
return;
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2350
2382
|
if (isMenuPress(data)) {
|
|
2351
|
-
// The panel
|
|
2352
|
-
//
|
|
2353
|
-
//
|
|
2354
|
-
// `
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2383
|
+
// The panel is a set of cards: the hub, then one page per section. Moving
|
|
2384
|
+
// between them edits this message, so browsing costs no new messages. A
|
|
2385
|
+
// command press is exactly a typed command, so it goes through the same
|
|
2386
|
+
// `handleControl`; the card is replaced by whatever that command answers.
|
|
2387
|
+
const target = menuTarget(data);
|
|
2388
|
+
if (target.kind === 'hub' || target.kind === 'section') {
|
|
2389
|
+
const card = renderPanel({ t: (k, v) => t(lang, k, v), page: target.page || '' });
|
|
2390
|
+
await tg('editMessageText', {
|
|
2391
|
+
chat_id: chatId,
|
|
2392
|
+
message_id: messageId,
|
|
2393
|
+
text: card.text,
|
|
2394
|
+
reply_markup: { inline_keyboard: card.keyboard },
|
|
2395
|
+
...(threadId > 0 ? { message_thread_id: threadId } : {}),
|
|
2396
|
+
}).catch(() => {});
|
|
2397
|
+
await answer(t(lang, 'bridge.cb.done'));
|
|
2398
|
+
return;
|
|
2399
|
+
}
|
|
2400
|
+
if (target.kind === 'close') {
|
|
2401
|
+
// The card collapses into one line that can be deleted by hand, and the
|
|
2402
|
+
// buttons go with it: a panel that stays open is a panel that lies about
|
|
2403
|
+
// being closed.
|
|
2404
|
+
await tg('editMessageText', {
|
|
2405
|
+
chat_id: chatId,
|
|
2406
|
+
message_id: messageId,
|
|
2407
|
+
text: t(lang, 'ctrl.menu.closed'),
|
|
2408
|
+
reply_markup: { inline_keyboard: [] },
|
|
2409
|
+
...(threadId > 0 ? { thread_id: threadId, message_thread_id: threadId } : {}),
|
|
2410
|
+
}).catch(() => {});
|
|
2411
|
+
await answer(t(lang, 'ctrl.menu.closedToast'));
|
|
2412
|
+
log(`menu closed for ${key}`);
|
|
2413
|
+
return;
|
|
2370
2414
|
}
|
|
2415
|
+
const name = target.kind === 'command' ? target.name : '';
|
|
2371
2416
|
await clearKeyboard();
|
|
2372
2417
|
// `/new` and `/stop` change something when typed alone, and a stray tap on
|
|
2373
2418
|
// them is a command nobody asked for — so they open their explanation.
|
package/control.mjs
CHANGED
|
@@ -17,13 +17,14 @@ import { setRowConfig, unsetRowConfig } from './profile-edit.mjs';
|
|
|
17
17
|
import { parseReminder, stampAt, upcoming } from './reminders.mjs';
|
|
18
18
|
import { AgentsetStore, emptySet, slugId } from './agentsets.mjs';
|
|
19
19
|
import { SETTINGS_PAGES, renderSettingsCard, settingsCurrent } from './settings-card.mjs';
|
|
20
|
-
import { planRewind } from './rewind.mjs';
|
|
20
|
+
import { applyFork, planFork, planRewind } from './rewind.mjs';
|
|
21
21
|
import { cutSession, isRewindPress } from './rewind-buttons.mjs';
|
|
22
22
|
import { renderRewindCard, renderRewindUsage } from './rewind-card.mjs';
|
|
23
|
-
import { MENU_GROUPS, commandForName, renderPanel } from './menu-card.mjs';
|
|
23
|
+
import { MENU_GROUPS, commandForName, renderPanel, replyKeyboard } from './menu-card.mjs';
|
|
24
24
|
import { explainCommand } from './help-explain.mjs';
|
|
25
25
|
import { profileValues, resolveSettings } from './settings.mjs';
|
|
26
26
|
import { UPDATE_DEFAULTS, describeUpdate, modeChange, updateState } from './update-policy.mjs';
|
|
27
|
+
import { rowLine, searchPlugins } from './plugin-search.mjs';
|
|
27
28
|
|
|
28
29
|
const HOME = homedir();
|
|
29
30
|
const DSH_HOME = process.env.DSH_HOME || join(HOME, '.dsh');
|
|
@@ -673,10 +674,30 @@ export const CONTROL_COMMANDS = [
|
|
|
673
674
|
'jobs', 'remind', 'sessions', 'resume', 'plugins', 'plugin',
|
|
674
675
|
'skills', 'soul', 'restart', 'app', 'stop', 'new', 'seed', 'send', 'cd',
|
|
675
676
|
'prices', 'help', 'doctor', 'logs', 'lang', 'reasoning', 'goal', 'task', 'tasks',
|
|
676
|
-
'thoughts', 'version', 'update', 'agentset', 'subscribe', 'settings',
|
|
677
|
-
'rewind', 'menu',
|
|
677
|
+
'thoughts', 'version', 'update', 'crew', 'agentset', 'subscribe', 'settings',
|
|
678
|
+
'rewind', 'fork', 'branches', 'menu',
|
|
678
679
|
];
|
|
679
680
|
|
|
681
|
+
/**
|
|
682
|
+
* Old spellings that no longer have a job of their own. A phone keyboard turns
|
|
683
|
+
* `task` into `tasks` and `model` into `models` without the person noticing, so
|
|
684
|
+
* each pair is ONE command: one name in `/help` and the panel, and the other
|
|
685
|
+
* spelling quietly routed to it. A name that is documented is a name a person
|
|
686
|
+
* can mistype; a name that is not documented is a name nobody has to remember.
|
|
687
|
+
*/
|
|
688
|
+
export const COMMAND_ALIASES = {
|
|
689
|
+
tasks: 'task',
|
|
690
|
+
models: 'model',
|
|
691
|
+
plugin: 'plugins',
|
|
692
|
+
agentset: 'crew',
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* What `/help`, the panel and the Telegram menu are allowed to say. Aliases are
|
|
697
|
+
* deliberately absent: they work, and they are never advertised.
|
|
698
|
+
*/
|
|
699
|
+
export const DOCUMENTED_COMMANDS = CONTROL_COMMANDS.filter((name) => !COMMAND_ALIASES[name]);
|
|
700
|
+
|
|
680
701
|
/**
|
|
681
702
|
* Working notes ("💭" lines in the progress message) are on unless the topic or
|
|
682
703
|
* the config says otherwise. Per-topic wins over the install default, so one
|
|
@@ -723,16 +744,21 @@ export async function handleControl(ctx) {
|
|
|
723
744
|
// without one it follows the install default.
|
|
724
745
|
const activeProfile = profile || config.profile || 'headless';
|
|
725
746
|
|
|
747
|
+
// Old spellings of a command route to the one name that owns the job, before
|
|
748
|
+
// anything else looks at the argument.
|
|
749
|
+
const bare = command.startsWith('/') ? command.slice(1) : command;
|
|
750
|
+
const canonical = COMMAND_ALIASES[bare];
|
|
751
|
+
let effective = canonical ? `/${canonical}` : command;
|
|
752
|
+
|
|
726
753
|
// One command for one job: `/plugins` is both the list and the way to change
|
|
727
754
|
// things. Two near-identical names (`/plugin` / `/plugins`) invited the exact
|
|
728
755
|
// mistake of typing the plural with an action. The singular form stays as an
|
|
729
756
|
// alias so old instructions and muscle memory keep working.
|
|
730
|
-
let effective = command;
|
|
731
757
|
if (effective === '/plugins') {
|
|
732
758
|
const [maybeAction] = String(arg || '').trim().split(/\s+/);
|
|
733
759
|
// `/plugins add|remove|disable|enable …` is the same work as `/plugin …`;
|
|
734
760
|
// the case bodies read `arg`, which already holds the action and its value.
|
|
735
|
-
if (['add', 'remove', 'disable', 'enable'].includes((maybeAction || '').toLowerCase())) {
|
|
761
|
+
if (['add', 'remove', 'disable', 'enable', 'search', 'find'].includes((maybeAction || '').toLowerCase())) {
|
|
736
762
|
effective = '/plugin';
|
|
737
763
|
}
|
|
738
764
|
}
|
|
@@ -1407,6 +1433,43 @@ export async function handleControl(ctx) {
|
|
|
1407
1433
|
const [action, ...rest] = (arg || '').split(/\s+/);
|
|
1408
1434
|
const target = (rest[0] === 'headless' || rest[0] === 'desktop') && rest.length > 1 ? rest.shift() : 'desktop';
|
|
1409
1435
|
const value = rest.join(' ').trim();
|
|
1436
|
+
if (action === 'search' || action === 'find') {
|
|
1437
|
+
// The marketplace, from the chat. A word is optional: with none, the
|
|
1438
|
+
// registry lists what DSH plugins exist at all — the question the
|
|
1439
|
+
// desktop app answers with a page.
|
|
1440
|
+
const found = await searchPlugins(value, { fetchImpl: ctx.fetch || fetch });
|
|
1441
|
+
if (!found.ok) {
|
|
1442
|
+
say(t(lang, 'ctrl.plugin.searchFailed', { err: found.error }));
|
|
1443
|
+
return true;
|
|
1444
|
+
}
|
|
1445
|
+
if (!found.rows.length) {
|
|
1446
|
+
say(t(lang, 'ctrl.plugin.searchEmpty', { word: value || 'dsh-plugin' }));
|
|
1447
|
+
return true;
|
|
1448
|
+
}
|
|
1449
|
+
const installed = new Set(pluginsOf(target).bundles);
|
|
1450
|
+
const body = found.rows.map((row) => rowLine(row, installed.has(row.name))).join('\n\n');
|
|
1451
|
+
// A button under a result is the shortest honest path from "I found it"
|
|
1452
|
+
// to "it is installed": it runs `/plugin add <name>` and nothing else.
|
|
1453
|
+
say(
|
|
1454
|
+
[
|
|
1455
|
+
t(lang, 'ctrl.plugin.searchTitle', {
|
|
1456
|
+
n: found.rows.length,
|
|
1457
|
+
word: value || t(lang, 'ctrl.plugin.searchAll'),
|
|
1458
|
+
profile: target,
|
|
1459
|
+
}),
|
|
1460
|
+
'',
|
|
1461
|
+
body,
|
|
1462
|
+
'',
|
|
1463
|
+
t(lang, 'ctrl.plugin.searchHint'),
|
|
1464
|
+
].join('\n'),
|
|
1465
|
+
{
|
|
1466
|
+
keyboard: found.rows.slice(0, 6).map((row) => [
|
|
1467
|
+
{ text: `+ ${row.name}`, callback_data: `pl:i:${row.name}` },
|
|
1468
|
+
]),
|
|
1469
|
+
},
|
|
1470
|
+
);
|
|
1471
|
+
return true;
|
|
1472
|
+
}
|
|
1410
1473
|
if (!action || !value) {
|
|
1411
1474
|
say(t(lang, 'ctrl.plugin.usage'));
|
|
1412
1475
|
return true;
|
|
@@ -1721,11 +1784,28 @@ export async function handleControl(ctx) {
|
|
|
1721
1784
|
}
|
|
1722
1785
|
|
|
1723
1786
|
case '/menu': {
|
|
1724
|
-
//
|
|
1725
|
-
//
|
|
1726
|
-
//
|
|
1787
|
+
// Two ways in. `/menu` is the hub card: six sections, each one a page of
|
|
1788
|
+
// commands that replace the card in place, so nobody has to spell a
|
|
1789
|
+
// command and the chat keeps one message instead of a wall of them.
|
|
1790
|
+
// `/menu on|off` is the other way: a Telegram reply keyboard under the
|
|
1791
|
+
// message field, which is what a person who does not read commands at all
|
|
1792
|
+
// needs — and it can be taken away again.
|
|
1727
1793
|
const page = String(arg || '').trim().toLowerCase();
|
|
1728
|
-
|
|
1794
|
+
if (page === 'on' || page === 'off') {
|
|
1795
|
+
state.menu = state.menu || {};
|
|
1796
|
+
state.menu[key] = page === 'on';
|
|
1797
|
+
ctx.saveState();
|
|
1798
|
+
log(`menu keyboard ${page} for ${key}`);
|
|
1799
|
+
await reply(
|
|
1800
|
+
t(lang, page === 'on' ? 'ctrl.menu.keyOn' : 'ctrl.menu.keyOff'),
|
|
1801
|
+
page === 'on' ? { persistent: replyKeyboard({ t: (k, vars) => t(lang, k, vars) }) } : { removeKeyboard: true },
|
|
1802
|
+
);
|
|
1803
|
+
return true;
|
|
1804
|
+
}
|
|
1805
|
+
const card = renderPanel({
|
|
1806
|
+
t: (k, vars) => t(lang, k, vars),
|
|
1807
|
+
page: MENU_GROUPS.includes(page) ? page : '',
|
|
1808
|
+
});
|
|
1729
1809
|
await reply(card.text, { keyboard: card.keyboard });
|
|
1730
1810
|
return true;
|
|
1731
1811
|
}
|
|
@@ -1769,6 +1849,57 @@ export async function handleControl(ctx) {
|
|
|
1769
1849
|
return true;
|
|
1770
1850
|
}
|
|
1771
1851
|
|
|
1852
|
+
case '/fork': {
|
|
1853
|
+
// The desktop app's "branch from here", without losing the road you were
|
|
1854
|
+
// on: the session is not cut, a copy of it up to the branch point becomes
|
|
1855
|
+
// a session of its own, and this topic moves onto the copy. `/fork` alone
|
|
1856
|
+
// branches from the end; `/fork 2` branches from two turns back.
|
|
1857
|
+
const sessionId = state.sessions[key] || '';
|
|
1858
|
+
if (!sessionId) { say(t(lang, 'ctrl.fork.noSession')); return true; }
|
|
1859
|
+
if (ctx.activeTurns && ctx.activeTurns.has(key)) { say(t(lang, 'ctrl.fork.busy')); return true; }
|
|
1860
|
+
const wanted = String(arg || '').trim().toLowerCase();
|
|
1861
|
+
const steps = wanted ? Number.parseInt(wanted, 10) : 0;
|
|
1862
|
+
if (wanted && (!Number.isInteger(steps) || steps < 0)) { say(t(lang, 'ctrl.fork.usage')); return true; }
|
|
1863
|
+
const file = sessionFile(join(DSH_HOME, 'sessions'), sessionId);
|
|
1864
|
+
const plan = planFork(file, steps);
|
|
1865
|
+
if (plan.reason) {
|
|
1866
|
+
// The same refusals as a cut: a session being written is the one file
|
|
1867
|
+
// this must never copy, and the reason is the same sentence.
|
|
1868
|
+
say(t(lang, `ctrl.rewind.refused.${plan.reason}`, { total: plan.total, dropped: steps }));
|
|
1869
|
+
return true;
|
|
1870
|
+
}
|
|
1871
|
+
let made;
|
|
1872
|
+
try {
|
|
1873
|
+
made = applyFork(file, plan.offset, plan.size);
|
|
1874
|
+
} catch (error) {
|
|
1875
|
+
say(t(lang, 'ctrl.fork.failed', { error: error.message }));
|
|
1876
|
+
return true;
|
|
1877
|
+
}
|
|
1878
|
+
state.sessions[key] = made.id;
|
|
1879
|
+
state.forks = state.forks || {};
|
|
1880
|
+
const list = state.forks[key] || [];
|
|
1881
|
+
list.push({ id: made.id, from: sessionId, at: Date.now(), kept: plan.kept });
|
|
1882
|
+
// The last dozen is enough to pick from, and state.json stays small.
|
|
1883
|
+
state.forks[key] = list.slice(-12);
|
|
1884
|
+
ctx.saveState();
|
|
1885
|
+
log(`fork ${sessionId} -> ${made.id} at turn ${plan.kept} for ${key}`);
|
|
1886
|
+
say(t(lang, 'ctrl.fork.done', { id: made.id, kept: plan.kept }));
|
|
1887
|
+
return true;
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
case '/branches': {
|
|
1891
|
+
const list = state.forks?.[key] || [];
|
|
1892
|
+
const current = state.sessions[key] || '';
|
|
1893
|
+
if (!list.length) { say(t(lang, 'ctrl.fork.none')); return true; }
|
|
1894
|
+
const rows = list.map((entry) => [{
|
|
1895
|
+
text: `${entry.id === current ? '• ' : ''}${entry.id.slice(8, 16)} · ${t(lang, 'ctrl.fork.turns', { n: entry.kept })}`,
|
|
1896
|
+
data: `fk:${entry.id}`,
|
|
1897
|
+
}]);
|
|
1898
|
+
const head = [t(lang, 'ctrl.fork.list', { n: list.length }), t(lang, 'ctrl.fork.current', { id: current || '—' })];
|
|
1899
|
+
await reply(head.join('\n'), { keyboard: rows });
|
|
1900
|
+
return true;
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1772
1903
|
case '/new': {
|
|
1773
1904
|
delete state.sessions[key];
|
|
1774
1905
|
ctx.saveState();
|
|
@@ -2182,7 +2313,7 @@ export async function handleControl(ctx) {
|
|
|
2182
2313
|
return true;
|
|
2183
2314
|
}
|
|
2184
2315
|
|
|
2185
|
-
case '/
|
|
2316
|
+
case '/crew': {
|
|
2186
2317
|
const store = agentset();
|
|
2187
2318
|
if (store.error) say(t(lang, 'ctrl.set.storeBroken', { error: store.error }));
|
|
2188
2319
|
const bound = state.agentsets?.[key] || '';
|