dsh-tg-bridge 1.26.0 → 1.27.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 +19 -1
- package/bridge.mjs +14 -0
- package/callbacks.mjs +17 -3
- package/commands-registry.mjs +1 -1
- package/control/cmd-bridge.mjs +23 -6
- package/control/cmd-fallback.mjs +48 -2
- package/control/cmd-load.mjs +66 -0
- package/control/cmd-views.mjs +6 -1
- package/control/models.mjs +40 -14
- package/control.mjs +3 -2
- package/fallback-card.mjs +17 -1
- package/handle-message.mjs +34 -14
- package/help-explain.mjs +1 -1
- package/i18n/en/core.mjs +5 -2
- package/i18n/en/ctrl.mjs +27 -0
- package/i18n/en/fallback.mjs +7 -2
- package/i18n/ru/core.mjs +5 -2
- package/i18n/ru/ctrl.mjs +27 -0
- package/i18n/ru/fallback.mjs +7 -2
- package/i18n/zh/core.mjs +5 -2
- package/i18n/zh/ctrl.mjs +27 -0
- package/i18n/zh/fallback.mjs +7 -2
- package/load-card.mjs +68 -0
- package/load-guard.mjs +70 -0
- package/machine.mjs +147 -0
- package/menu-card.mjs +1 -1
- package/model-probe.mjs +58 -11
- package/package.json +6 -1
- package/progress.mjs +15 -1
- package/settings-card.mjs +7 -2
- package/turn-outcome.mjs +35 -0
- package/turn.mjs +28 -15
package/README.md
CHANGED
|
@@ -24,6 +24,10 @@ a bot that answers, one step at a time.
|
|
|
24
24
|
the model's reasoning in a collapsed block you can tap open. A long turn adds a second
|
|
25
25
|
collapsed block with every tool call, so the whole run stays in the chat as one message.
|
|
26
26
|
- **No lost messages**: a journal with acknowledgement and replay.
|
|
27
|
+
- **Knows how busy the computer is**: `/load` shows free space on the topic's disk,
|
|
28
|
+
free RAM and average CPU, plus how many turns are running and waiting. `/load on`
|
|
29
|
+
makes a prompt wait instead of starting while the machine is over a limit you set
|
|
30
|
+
— kept, never refused, and one press sends it anyway.
|
|
27
31
|
- **Settings per topic**: `/crew use reviewer` gives one topic its own model,
|
|
28
32
|
effort, permissions, agent preset and language while the others keep the profile;
|
|
29
33
|
`/crew off` returns it. Four built-in sets ship read-only and can be copied.
|
|
@@ -172,7 +176,8 @@ card so the distinction is visible instead of guessed.
|
|
|
172
176
|
/fallback use 3 | skip 3 one route back in or out
|
|
173
177
|
/fallback up 3 | down 3 move a route in the order
|
|
174
178
|
/fallback test [3] ask each route (or one) with a 1-token request
|
|
175
|
-
/fallback add <provider>/<model>
|
|
179
|
+
/fallback add <provider>/<model> write an overlay and append the route
|
|
180
|
+
/fallback first <provider>/<model> put it at the head: tried before every other route
|
|
176
181
|
/fallback remove 3 drop a route from the list (its overlay file stays)
|
|
177
182
|
```
|
|
178
183
|
|
|
@@ -182,6 +187,18 @@ channel are alive — not that the provider accepts this conversation, so a rout
|
|
|
182
187
|
can answer `ping` and still refuse a long prompt with a 400. The card says that
|
|
183
188
|
in as many words.
|
|
184
189
|
|
|
190
|
+
`test` also times each route: how long it takes to produce the first token, and
|
|
191
|
+
which live route is fastest right now. Two routes that both answer are not
|
|
192
|
+
equally good — 400 ms and 9 s feel like different products — and the head of the
|
|
193
|
+
chain is the one a person picks on that number. A route that did not answer
|
|
194
|
+
prints no time, so `no balance · 120 ms` can never read as "works, just slow".
|
|
195
|
+
|
|
196
|
+
`first` exists because `add` appends: when the route you want should answer
|
|
197
|
+
*before* the primary, appending it means moving it up eight times and guessing
|
|
198
|
+
where the head is. `/fallback first router-a/deepseek-v4.1-flash` writes the
|
|
199
|
+
same overlay and puts it at position 1 — or moves it there if it is already in
|
|
200
|
+
the chain.
|
|
201
|
+
|
|
185
202
|
Get your id from [@userinfobot](https://t.me/userinfobot), the token from
|
|
186
203
|
[@BotFather](https://t.me/BotFather).
|
|
187
204
|
|
|
@@ -270,6 +287,7 @@ Extensions: /skills · /plugins · /plugins search <word> · /plugins disable|
|
|
|
270
287
|
Updates: /update · /update confirm · /update on|off|check|auto · /subscribe on|off
|
|
271
288
|
Diagnostics: /doctor · /logs [errors|N|text] · /report
|
|
272
289
|
Service: /app · /restart · /help
|
|
290
|
+
Machine: /load · /load on|off · /load limit cpu|ram|disk <n>
|
|
273
291
|
Settings: /settings — the same switches as buttons, grouped in four tabs
|
|
274
292
|
Display: /lang · /reasoning off|card|chat · /pin on|off · /thoughts
|
|
275
293
|
```
|
package/bridge.mjs
CHANGED
|
@@ -166,6 +166,20 @@ async function main() {
|
|
|
166
166
|
`✅ ${t(lang, 'msg.restarted', { pid: process.pid })}`,
|
|
167
167
|
notice.threadId || 0,
|
|
168
168
|
);
|
|
169
|
+
// A turn is a child process, so the restart killed it. The topic it was
|
|
170
|
+
// working in is left with a card stuck on ⏳ and no reason for it: the
|
|
171
|
+
// person there typed a message, walked away, and comes back to a card
|
|
172
|
+
// that stopped moving. Say so where the work was, not only where the
|
|
173
|
+
// restart was ordered.
|
|
174
|
+
for (const place of Array.isArray(notice.interrupted) ? notice.interrupted : []) {
|
|
175
|
+
if (place.chatId === notice.chatId && (place.threadId || 0) === (notice.threadId || 0)) continue;
|
|
176
|
+
try {
|
|
177
|
+
const there = resolveLang(state, sessionKey(place.chatId, place.threadId || 0), null, config);
|
|
178
|
+
await send(place.chatId, `⚠️ ${t(there, 'msg.turnInterrupted')}`, place.threadId || 0);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
log(`interrupted notice failed for ${place.chatId}:${place.threadId}: ${error.message}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
169
183
|
}
|
|
170
184
|
}
|
|
171
185
|
} catch (error) {
|
package/callbacks.mjs
CHANGED
|
@@ -7,10 +7,11 @@ import { isFallbackPress, pressTarget } from './fallback-card.mjs';
|
|
|
7
7
|
import { progressOf, toggleTask } from './goals.mjs';
|
|
8
8
|
import { handleMessage } from './handle-message.mjs';
|
|
9
9
|
import { resolveLang, t } from './i18n.mjs';
|
|
10
|
+
import { handleLoadPress } from './load-guard.mjs';
|
|
10
11
|
import { sessionKey } from './keys.mjs';
|
|
11
12
|
import { commandForName, isMenuPress, menuTarget, renderPanel, runsUnasked } from './menu-card.mjs';
|
|
12
13
|
import { DIR, DSH_HOME, LOG } from './paths.mjs';
|
|
13
|
-
import { approvals, enqueue, lastPrompt, maxParallel, rewindUsed } from './queue.mjs';
|
|
14
|
+
import { approvals, enqueue, lastPrompt, maxParallel, redeliver, rewindUsed } from './queue.mjs';
|
|
14
15
|
import { answerRewindPress, cutSession, isRewindPress } from './rewind-buttons.mjs';
|
|
15
16
|
import { applyRewind, newestBackup, restoreBackup } from './rewind.mjs';
|
|
16
17
|
import { runCommandFromButton } from './run-command.mjs';
|
|
@@ -153,6 +154,13 @@ export async function handleCallback(query) {
|
|
|
153
154
|
return;
|
|
154
155
|
}
|
|
155
156
|
|
|
157
|
+
// A button on the load card, or on the notice that held a prompt back. Both
|
|
158
|
+
// are `/load` verbs, so the tap and the typed command run the same code.
|
|
159
|
+
if (data.startsWith('ld:')) {
|
|
160
|
+
await handleLoadPress({ data, key, t, lang, answer, clearKeyboard, redeliver, runCommandFromButton, chatId, threadId, log });
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
156
164
|
// A button on the failover card. Every press becomes the verb of `/fallback`,
|
|
157
165
|
// so a tap and a typed line land in the same code — and the command redraws the
|
|
158
166
|
// card, which is why the old keyboard is trimmed only when the press leaves it.
|
|
@@ -358,11 +366,17 @@ export async function handleCardPress(query, ctx) {
|
|
|
358
366
|
text: card.text,
|
|
359
367
|
reply_markup: { inline_keyboard: inlineKeyboard(card.keyboard) },
|
|
360
368
|
...(threadId > 0 ? { message_thread_id: threadId } : {}),
|
|
361
|
-
}).catch((error) =>
|
|
369
|
+
}).catch((error) => {
|
|
370
|
+
const why = String(error.message || '');
|
|
371
|
+
// Tapping the tab you are already on is not a failure: Telegram refuses an
|
|
372
|
+
// edit that changes nothing, and the card is already what the press asked
|
|
373
|
+
// for. Logging it as a failure made a working tap look broken.
|
|
374
|
+
if (!/message is not modified/i.test(why)) log(`settings card redraw failed: ${why}`);
|
|
375
|
+
});
|
|
362
376
|
await tg('answerCallbackQuery', { callback_query_id: query.id }).catch(() => {});
|
|
363
377
|
};
|
|
364
378
|
|
|
365
|
-
if (wanted.
|
|
379
|
+
if (wanted.tab) {
|
|
366
380
|
await redraw(wanted.page);
|
|
367
381
|
return;
|
|
368
382
|
}
|
package/commands-registry.mjs
CHANGED
|
@@ -12,7 +12,7 @@ export const CONTROL_COMMANDS = [
|
|
|
12
12
|
'skills', 'soul', 'restart', 'app', 'stop', 'new', 'seed', 'send', 'cd',
|
|
13
13
|
'prices', 'help', 'doctor', 'logs', 'report', 'lang', 'reasoning', 'pin', 'goal', 'task', 'tasks',
|
|
14
14
|
'thoughts', 'version', 'update', 'crew', 'agentset', 'subscribe', 'settings',
|
|
15
|
-
'rewind', 'fork', 'branches', 'menu', 'fallback',
|
|
15
|
+
'rewind', 'fork', 'branches', 'menu', 'fallback', 'load',
|
|
16
16
|
];
|
|
17
17
|
|
|
18
18
|
/**
|
package/control/cmd-bridge.mjs
CHANGED
|
@@ -25,7 +25,7 @@ import { profileValues, resolveSettings } from '../settings.mjs';
|
|
|
25
25
|
import { UPDATE_DEFAULTS, describeUpdate, modeChange, updateState } from '../update-policy.mjs';
|
|
26
26
|
import { isNewer, pluginInfo, rowLine, searchPlugins } from '../plugin-search.mjs';
|
|
27
27
|
import { COMMAND_ALIASES, CONTROL_COMMANDS, DOCUMENTED_COMMANDS } from '../commands-registry.mjs';
|
|
28
|
-
import { APP, CLI_JS, DSH_CMD, DSH_HOME, DIR, EXE, HOME, LOG, PROFILES, THOUGHT_DIR } from '../paths.mjs';
|
|
28
|
+
import { APP, CLI_JS, DSH_CMD, DSH_HOME, DIR, EXE, HOME, LOG, PROFILES, RESTART_NOTICE, THOUGHT_DIR } from '../paths.mjs';
|
|
29
29
|
import { read, readJson, patchPath, pkgPath, OVERLAY_MARK, modelsOf, modelOf, windowOf, modelIndent, depthOf, modelsReport, setModel, disabledIds, setDisabled, writePatch } from './models.mjs';
|
|
30
30
|
import { listPids, waitForExit, waitForStart, pluginsOf, bundleRowIds, addBundle, removeBundle, createProfile, dshPlugin } from './plugins.mjs';
|
|
31
31
|
import { cwdSlug, bareId, stamp, recentSessions, sessionTitle } from './sessions.mjs';
|
|
@@ -83,12 +83,29 @@ export async function handleBridgeCommands(ctx) {
|
|
|
83
83
|
const bridge = fileURLToPath(new URL('./bridge.mjs', import.meta.url));
|
|
84
84
|
// Tell the replacement process where to confirm, so the chat does not go
|
|
85
85
|
// silent after "Перезапускаю мост…" (it did, twice on 2026-10-24).
|
|
86
|
+
//
|
|
87
|
+
// It also carries the topics whose turn this restart is about to kill. A
|
|
88
|
+
// turn is a child process: `process.exit` takes it down with the bridge, and
|
|
89
|
+
// the topic it was working in keeps a card that says ⏳ forever, with nothing
|
|
90
|
+
// to explain it. The person in that topic finds out by scrolling to a card
|
|
91
|
+
// that stopped moving — so the new process names each one.
|
|
92
|
+
const interrupted = [...(ctx.activeTurns?.keys?.() || [])]
|
|
93
|
+
.map((k) => String(k).split(':'))
|
|
94
|
+
.map(([chat, thread]) => ({ chatId: Number(chat), threadId: Number(thread) || 0 }))
|
|
95
|
+
.filter((t2) => Number.isFinite(t2.chatId) && t2.chatId > 0);
|
|
86
96
|
try {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
// The path the reader uses, not a path relative to this file: this case
|
|
98
|
+
// lives in `control/`, and the old `new URL('./restart-notice.json', …)`
|
|
99
|
+
// wrote the note one directory below where `bridge.mjs` looked for it.
|
|
100
|
+
// Every restart confirmation since then was silently lost — the person
|
|
101
|
+
// saw "Перезапускаю мост…" and then nothing, which is exactly the doubt
|
|
102
|
+
// the note exists to remove.
|
|
103
|
+
writeFileSync(RESTART_NOTICE, JSON.stringify({
|
|
104
|
+
chatId: ctx.chatId,
|
|
105
|
+
threadId: ctx.threadId || 0,
|
|
106
|
+
at: Date.now(),
|
|
107
|
+
interrupted,
|
|
108
|
+
}), 'utf8');
|
|
92
109
|
} catch (error) {
|
|
93
110
|
log(`restart notice not written: ${error.message}`);
|
|
94
111
|
}
|
package/control/cmd-fallback.mjs
CHANGED
|
@@ -62,6 +62,9 @@ const VERDICT = {
|
|
|
62
62
|
busy: 'busy',
|
|
63
63
|
network: 'network',
|
|
64
64
|
missing: 'missing',
|
|
65
|
+
// A 200 with no body: the route took the request and said nothing. Saying "ok"
|
|
66
|
+
// there is how a dead channel looks healthy on the card.
|
|
67
|
+
empty: 'empty',
|
|
65
68
|
};
|
|
66
69
|
|
|
67
70
|
export async function handleFallbackCommands(ctx) {
|
|
@@ -190,6 +193,49 @@ export async function handleFallbackCommands(ctx) {
|
|
|
190
193
|
return true;
|
|
191
194
|
}
|
|
192
195
|
|
|
196
|
+
// A route the person wants tried FIRST, not appended.
|
|
197
|
+
//
|
|
198
|
+
// `add` puts a route at the tail, which is right for a spare and wrong for
|
|
199
|
+
// the one that should answer when the primary is busy: moving it up eight
|
|
200
|
+
// times is eight presses, and the last one is always a guess about where the
|
|
201
|
+
// head is. This is `add` plus "put it in front", in one word.
|
|
202
|
+
case 'first':
|
|
203
|
+
case 'head': {
|
|
204
|
+
const route = splitRoute(rest.join(' '));
|
|
205
|
+
if (!route.model) {
|
|
206
|
+
say(t(lang, 'ctrl.fallback.addUsage'));
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
const known = providerIds(activeProfile);
|
|
210
|
+
const provider = route.provider || known[0] || '';
|
|
211
|
+
if (!known.includes(provider)) {
|
|
212
|
+
say(t(lang, 'ctrl.fallback.unknownProvider', { name: provider || '?', list: known.join(', ') }));
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
const full = `${provider}/${route.model}`;
|
|
216
|
+
// Already in the chain: move it instead of adding a twin. Two entries of
|
|
217
|
+
// one route would be tried twice for the same failure.
|
|
218
|
+
const existing = chain.findIndex((item) => item.provider === provider && item.model === route.model);
|
|
219
|
+
if (existing === 0) {
|
|
220
|
+
say(t(lang, 'ctrl.fallback.alreadyFirst', { route: full }));
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
if (existing > 0) {
|
|
224
|
+
const [moved] = chain.splice(existing, 1);
|
|
225
|
+
chain.unshift(moved);
|
|
226
|
+
done('ctrl.fallback.moved', { route: labelOf(moved), n: 1 });
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
const patch = join(DIR, overlayName({ provider, model: route.model }));
|
|
230
|
+
writeFileSync(patch, overlayText({ provider, model: route.model }), 'utf8');
|
|
231
|
+
const fresh = { provider, model: route.model, patch };
|
|
232
|
+
if (/:free$/i.test(route.model)) fresh.free = true;
|
|
233
|
+
chain.unshift(fresh);
|
|
234
|
+
log(`fallback: added ${full} at the head (${patch})`);
|
|
235
|
+
done('ctrl.fallback.addedFirst', { route: full });
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
|
|
193
239
|
// A probe proves the key works, not that this conversation is acceptable: the
|
|
194
240
|
// hint says so, because "route is fine" beside a 400 would be a lie.
|
|
195
241
|
//
|
|
@@ -217,8 +263,8 @@ export async function handleFallbackCommands(ctx) {
|
|
|
217
263
|
}));
|
|
218
264
|
const rows = targets.map((item) => {
|
|
219
265
|
const verdict = verdicts.get(item) || { kind: 'other' };
|
|
220
|
-
log(`fallback probe ${labelOf(item)}: ${verdict.kind}${verdict.detail ? ` (${String(verdict.detail).slice(0, 80)})` : ''}`);
|
|
221
|
-
return { n: chain.indexOf(item) + 1, route: labelOf(item), kind: VERDICT[verdict.kind] || 'other' };
|
|
266
|
+
log(`fallback probe ${labelOf(item)}: ${verdict.kind} ${verdict.ms || 0}ms${verdict.detail ? ` (${String(verdict.detail).slice(0, 80)})` : ''}`);
|
|
267
|
+
return { n: chain.indexOf(item) + 1, route: labelOf(item), kind: VERDICT[verdict.kind] || 'other', ms: verdict.ms };
|
|
222
268
|
});
|
|
223
269
|
// One way back to the card: the probe answer is long, and the person who
|
|
224
270
|
// just learned route 4 is dead wants the list, not a typed command.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// `/load`: what this computer is doing, and the guard that keeps it usable.
|
|
2
|
+
//
|
|
3
|
+
// One group of the `/` surface. `control.mjs` owns the dispatch and this file
|
|
4
|
+
// owns the command.
|
|
5
|
+
import { normalizeLang, t } from '../i18n.mjs';
|
|
6
|
+
import { guardOf, sampleMachine } from '../machine.mjs';
|
|
7
|
+
import { loadPress, renderLoadCard } from '../load-card.mjs';
|
|
8
|
+
import { saveConfig } from '../state.mjs';
|
|
9
|
+
|
|
10
|
+
/** The card, drawn once and reused by every verb that ends in "show me". */
|
|
11
|
+
async function drawLoad({ ctx, lang, guard }) {
|
|
12
|
+
const jobs = ctx.jobs ? ctx.jobs() : { active: [], queued: 0, max: 0 };
|
|
13
|
+
const sample = await sampleMachine({ drive: undefined });
|
|
14
|
+
const card = renderLoadCard({
|
|
15
|
+
t: (key, vars) => t(lang, key, vars),
|
|
16
|
+
sample,
|
|
17
|
+
guard,
|
|
18
|
+
turns: jobs.active.length,
|
|
19
|
+
queued: jobs.queued,
|
|
20
|
+
max: jobs.max,
|
|
21
|
+
});
|
|
22
|
+
await ctx.reply(card.text, { reply_markup: { inline_keyboard: card.keyboard } });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function handleLoadCommands(ctx) {
|
|
26
|
+
const { command, arg, reply, log, config, lang: rawLang } = ctx;
|
|
27
|
+
const lang = normalizeLang(rawLang) || normalizeLang(config?.lang) || 'en';
|
|
28
|
+
const effective = ctx.effective || command;
|
|
29
|
+
if (effective !== '/load') return false;
|
|
30
|
+
|
|
31
|
+
const guard = guardOf(config.loadGuard);
|
|
32
|
+
const verb = String(arg || '').trim().toLowerCase();
|
|
33
|
+
if (!verb) {
|
|
34
|
+
await drawLoad({ ctx, lang, guard });
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (verb === 'on' || verb === 'off' || verb === 'guard') {
|
|
38
|
+
const want = verb === 'guard' ? !guard.enabled : verb === 'on';
|
|
39
|
+
config.loadGuard = { ...guard, enabled: want };
|
|
40
|
+
saveConfig();
|
|
41
|
+
log(`load guard ${want ? 'on' : 'off'}: cpu>${guard.cpuPct}%, ram<${guard.ramFreePct}%, disk<${guard.diskFreeGb}GB`);
|
|
42
|
+
await drawLoad({ ctx, lang, guard: { ...guard, enabled: want } });
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
// `/load limit cpu 80` — one number at a time, because a person changing the
|
|
46
|
+
// limit is looking at the reading that annoyed them.
|
|
47
|
+
const [, what, raw] = /^(?:limit|l)\s+(cpu|ram|disk)\s+(\d+(?:[.,]\d+)?)$/.exec(verb) || [];
|
|
48
|
+
if (what) {
|
|
49
|
+
const value = Number(String(raw).replace(',', '.'));
|
|
50
|
+
const field = what === 'cpu' ? 'cpuPct' : what === 'ram' ? 'ramFreePct' : 'diskFreeGb';
|
|
51
|
+
const next = { ...guard, [field]: value };
|
|
52
|
+
config.loadGuard = next;
|
|
53
|
+
saveConfig();
|
|
54
|
+
log(`load limit ${field}=${value}`);
|
|
55
|
+
await drawLoad({ ctx, lang, guard: next });
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (verb === 'limit' || verb === 'limits') {
|
|
59
|
+
await reply(t(lang, 'ctrl.load.limitsNow', { cpu: guard.cpuPct, ram: guard.ramFreePct, disk: guard.diskFreeGb }));
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
await reply(t(lang, 'ctrl.load.usage'));
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { loadPress };
|
package/control/cmd-views.mjs
CHANGED
|
@@ -123,9 +123,14 @@ export async function handleViewCommands(ctx) {
|
|
|
123
123
|
return true;
|
|
124
124
|
}
|
|
125
125
|
const desktop = scope === 'both' ? setModel('desktop', wanted) : false;
|
|
126
|
+
// Report the route the patch now carries, not the string that was typed:
|
|
127
|
+
// `/model deepseek-v4.1-flash` leaves the provider as it was, and the answer
|
|
128
|
+
// is the only place that says so. "Model → deepseek" while the turn still
|
|
129
|
+
// runs on the slow host is the confusion this line exists to remove.
|
|
130
|
+
const route = modelOf(activeProfile);
|
|
126
131
|
say(t(lang, 'ctrl.model.switched', {
|
|
127
132
|
name: activeProfile,
|
|
128
|
-
model:
|
|
133
|
+
model: `${route.provider}/${route.model}`,
|
|
129
134
|
desktop: desktop ? t(lang, 'ctrl.model.withDesktop', { model: wanted }) : '',
|
|
130
135
|
}));
|
|
131
136
|
return true;
|
package/control/models.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
// Reading and changing a profile's model: the patch row, the overlay, the window.
|
|
2
|
-
//
|
|
3
|
-
// Split out of `control.mjs` by the 500-line plan: the command handlers that
|
|
4
|
-
// follow call these, and none of them needs the dispatcher to do it.
|
|
5
|
-
import { copyFileSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
6
|
-
import { join } from 'node:path';
|
|
7
|
-
import { t } from '../i18n.mjs';
|
|
8
|
-
import {
|
|
9
|
-
|
|
1
|
+
// Reading and changing a profile's model: the patch row, the overlay, the window.
|
|
2
|
+
//
|
|
3
|
+
// Split out of `control.mjs` by the 500-line plan: the command handlers that
|
|
4
|
+
// follow call these, and none of them needs the dispatcher to do it.
|
|
5
|
+
import { copyFileSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { t } from '../i18n.mjs';
|
|
8
|
+
import { providerRows } from '../model-probe.mjs';
|
|
9
|
+
import { PROFILES } from '../paths.mjs';
|
|
10
|
+
|
|
10
11
|
export const read = (path) => {
|
|
11
12
|
try {
|
|
12
13
|
return readFileSync(path, 'utf8');
|
|
@@ -134,15 +135,40 @@ export function modelsReport(lang, profile) {
|
|
|
134
135
|
].join('\n');
|
|
135
136
|
}
|
|
136
137
|
|
|
137
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* Rewrite the default model of a profile; returns false for an unknown id.
|
|
140
|
+
*
|
|
141
|
+
* `provider/model` moves the route as well as the model. Without that a person
|
|
142
|
+
* who wants the SAME model on a different router has no way to say so: `/model
|
|
143
|
+
* deepseek-v4.1-flash` keeps whatever provider the patch already had, so the
|
|
144
|
+
* switch silently keeps the slow host — the one case where "I changed the model"
|
|
145
|
+
* and "the answers come from somewhere else now" are different claims.
|
|
146
|
+
*/
|
|
138
147
|
export function setModel(profile, wanted) {
|
|
148
|
+
const text0 = String(wanted || '').trim();
|
|
149
|
+
const slash = text0.indexOf('/');
|
|
150
|
+
const provider = slash > 0 ? text0.slice(0, slash) : '';
|
|
151
|
+
const model = slash > 0 ? text0.slice(slash + 1) : text0;
|
|
152
|
+
if (!model) return false;
|
|
139
153
|
const ids = modelsOf(profile);
|
|
140
|
-
if (ids.length > 0 && !ids.includes(
|
|
154
|
+
if (ids.length > 0 && !ids.includes(model)) return false;
|
|
141
155
|
const path = patchPath(profile);
|
|
142
156
|
const text = read(path);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
157
|
+
// A provider the profile does not declare cannot boot the turn: writing it
|
|
158
|
+
// anyway would leave a patch that looks edited and a bot that cannot answer,
|
|
159
|
+
// so the row is checked before the file is touched.
|
|
160
|
+
if (provider && !providerRows(text).some((row) => row.id === provider)) return false;
|
|
161
|
+
const block = /- id: agent-default-model[\s\S]*?(?=\n- id:|\n- insert:|$)/.exec(text);
|
|
162
|
+
if (!block) return false;
|
|
163
|
+
// Provider first, then model: both live in the same block, and replacing the
|
|
164
|
+
// block wholesale would drop `reasoningEffort` and anything else a person set.
|
|
165
|
+
let next = block[0].replace(/^(\s+model:\s*)\S+/m, `$1${model}`);
|
|
166
|
+
if (provider) {
|
|
167
|
+
if (/^\s+provider:\s*\S+/m.test(next)) next = next.replace(/^(\s+provider:\s*)\S+/m, `$1${provider}`);
|
|
168
|
+
else next = next.replace(/^(\s+model:\s*\S+)/m, `$1\n provider: ${provider}`);
|
|
169
|
+
}
|
|
170
|
+
if (next === block[0]) return false;
|
|
171
|
+
writeFileSync(path, text.replace(block[0], next), 'utf8');
|
|
146
172
|
return true;
|
|
147
173
|
}
|
|
148
174
|
|
package/control.mjs
CHANGED
|
@@ -29,7 +29,8 @@ import { COMMAND_ALIASES, CONTROL_COMMANDS, DOCUMENTED_COMMANDS } from './comman
|
|
|
29
29
|
|
|
30
30
|
import { handleAgentCommands } from './control/cmd-agents.mjs';
|
|
31
31
|
import { handleBridgeCommands } from './control/cmd-bridge.mjs';
|
|
32
|
-
import { handleFallbackCommands } from './control/cmd-fallback.mjs';
|
|
32
|
+
import { handleFallbackCommands } from './control/cmd-fallback.mjs';
|
|
33
|
+
import { handleLoadCommands } from './control/cmd-load.mjs';
|
|
33
34
|
import { handlePluginCommands } from './control/cmd-plugin.mjs';
|
|
34
35
|
import { handleSessionCommands } from './control/cmd-session.mjs';
|
|
35
36
|
import { handleSkillCommands } from './control/cmd-skills.mjs';
|
|
@@ -106,7 +107,7 @@ export async function handleControl(ctx) {
|
|
|
106
107
|
// that is not its job. The order is alphabetical, not meaningful: no two
|
|
107
108
|
// groups claim the same command, so a miss falls through to `default` below.
|
|
108
109
|
const child = { ...ctx, effective, command, arg: effectiveArgText, send, reply, log, profile, state, key, config, lang };
|
|
109
|
-
for (const handler of [handleAgentCommands, handleBridgeCommands, handleFallbackCommands, handlePluginCommands, handleSessionCommands, handleSkillCommands, handleTaskCommands, handleViewCommands]) {
|
|
110
|
+
for (const handler of [handleAgentCommands, handleBridgeCommands, handleFallbackCommands, handleLoadCommands, handlePluginCommands, handleSessionCommands, handleSkillCommands, handleTaskCommands, handleViewCommands]) {
|
|
110
111
|
if (await handler(child)) return true;
|
|
111
112
|
}
|
|
112
113
|
// Nothing claimed it: the bridge answers an unknown `/` command itself, with
|
package/fallback-card.mjs
CHANGED
|
@@ -165,17 +165,33 @@ export function removeKeyboard({ t, chain = [] }) {
|
|
|
165
165
|
*
|
|
166
166
|
* A probe proves the key works, not that the provider accepts this conversation;
|
|
167
167
|
* a card that said "all routes are fine" beside a 400 would send the person to
|
|
168
|
-
* the wrong fix.
|
|
168
|
+
* the wrong fix. It also prints how long each route took to say one token: two
|
|
169
|
+
* routes that both answer "ok" are not equally good, and a person picking the
|
|
170
|
+
* first of the chain is choosing on speed, not on the word "ok".
|
|
169
171
|
*/
|
|
170
172
|
export function renderProbe({ t, rows = [] }) {
|
|
171
173
|
const lines = [t('ctrl.fallback.testTitle')];
|
|
172
174
|
for (const row of rows) {
|
|
175
|
+
// Latency is printed only for a route that actually answered. "no balance ·
|
|
176
|
+
// 120 ms" invites the reading "it works, it is just slow", which is the one
|
|
177
|
+
// thing a dead route must never look like.
|
|
178
|
+
const speed = row.kind === 'ok' && Number.isFinite(row.ms) && row.ms > 0
|
|
179
|
+
? t('ctrl.fallback.testSpeed', { ms: row.ms })
|
|
180
|
+
: '';
|
|
173
181
|
lines.push(t('ctrl.fallback.testLine', {
|
|
174
182
|
n: row.n,
|
|
175
183
|
route: row.route,
|
|
176
184
|
verdict: t(`ctrl.fallback.verdict.${row.kind}`),
|
|
185
|
+
speed,
|
|
177
186
|
}));
|
|
178
187
|
}
|
|
188
|
+
// The fastest route that answered, named once: the list already shows it, but
|
|
189
|
+
// the whole point of measuring is the one-line verdict a person acts on.
|
|
190
|
+
const live = rows.filter((row) => row.kind === 'ok' && Number.isFinite(row.ms));
|
|
191
|
+
if (live.length > 1) {
|
|
192
|
+
const best = live.reduce((a, b) => (a.ms <= b.ms ? a : b));
|
|
193
|
+
lines.push('', t('ctrl.fallback.testFastest', { route: best.route, ms: best.ms }));
|
|
194
|
+
}
|
|
179
195
|
lines.push('', t('ctrl.fallback.testHint'));
|
|
180
196
|
return lines.join('\n');
|
|
181
197
|
}
|
package/handle-message.mjs
CHANGED
|
@@ -13,6 +13,8 @@ import { runFallbackChain } from './fallback.mjs';
|
|
|
13
13
|
import { goalOf, renderPromptBlock } from './goals.mjs';
|
|
14
14
|
import { resolveLang, t } from './i18n.mjs';
|
|
15
15
|
import { sessionKey, threadOf } from './keys.mjs';
|
|
16
|
+
import { holdIfLoaded } from './load-guard.mjs';
|
|
17
|
+
import { guardOf } from './machine.mjs';
|
|
16
18
|
import { mediaPrompt } from './media.mjs';
|
|
17
19
|
import { keyboardCommand } from './menu-card.mjs';
|
|
18
20
|
import { looksLikeReasoning, stepLine } from './panel.mjs';
|
|
@@ -284,20 +286,6 @@ ${t(lang, 'help.body')}`,
|
|
|
284
286
|
// something to resend. Bounded: only the latest prompt per topic matters.
|
|
285
287
|
lastPrompt.set(key, msg);
|
|
286
288
|
|
|
287
|
-
const stop = { done: false };
|
|
288
|
-
const typing = typingLoop(chatId, threadId, stop);
|
|
289
|
-
const started = Date.now();
|
|
290
|
-
// Capture the session BEFORE the turn starts. A second message for the same
|
|
291
|
-
// topic can overwrite `state.sessions[key]` while this turn is still running
|
|
292
|
-
// (two messages a few seconds apart, or a copy-paste), and the late writer
|
|
293
|
-
// then attached a fresh session id to a conversation that already had one.
|
|
294
|
-
const sessionAtStart = state.sessions[key];
|
|
295
|
-
// Remember the topic a turn is running in: it is where a release notice goes,
|
|
296
|
-
// since a notice is about the install and the install serves every topic.
|
|
297
|
-
if (state.lastKey !== key) {
|
|
298
|
-
state.lastKey = key;
|
|
299
|
-
saveState();
|
|
300
|
-
}
|
|
301
289
|
// Project directory bound to this topic (set with /cd); config.cwd otherwise.
|
|
302
290
|
// A bound directory that has been deleted or renamed is reported as such: the
|
|
303
291
|
// old silent fallback to config.cwd ran the turn in a different project than
|
|
@@ -309,11 +297,35 @@ ${t(lang, 'help.body')}`,
|
|
|
309
297
|
return;
|
|
310
298
|
}
|
|
311
299
|
const cwd = boundDir || config.cwd;
|
|
300
|
+
|
|
301
|
+
// The load guard: one more Electron child on a machine at 95 % CPU is the
|
|
302
|
+
// difference between a slow window and a frozen one for whoever else is using
|
|
303
|
+
// this computer. Checked before the first process, when nothing is spent yet;
|
|
304
|
+
// the prompt is held, not refused — see `load-guard.mjs`.
|
|
305
|
+
if (await holdIfLoaded({ t, lang, key, where, cwd, chatId, threadId, msg, album, sendWithMarkup, log, guard: guardOf(config.loadGuard) })) return;
|
|
306
|
+
|
|
312
307
|
// What the person actually wrote, before any injected block: the progress
|
|
313
308
|
// message echoes it back so the first thing they see names their task, not a
|
|
314
309
|
// generic spinner.
|
|
315
310
|
const request = text;
|
|
316
311
|
|
|
312
|
+
// The typing indicator and the turn clock start here, after the guard: a
|
|
313
|
+
// "bot is typing" bubble over a turn that is not running is a lie.
|
|
314
|
+
const stop = { done: false };
|
|
315
|
+
const typing = typingLoop(chatId, threadId, stop);
|
|
316
|
+
const started = Date.now();
|
|
317
|
+
// Capture the session BEFORE the turn starts. A second message for the same
|
|
318
|
+
// topic can overwrite `state.sessions[key]` while this turn is still running
|
|
319
|
+
// (two messages a few seconds apart, or a copy-paste), and the late writer
|
|
320
|
+
// then attached a fresh session id to a conversation that already had one.
|
|
321
|
+
const sessionAtStart = state.sessions[key];
|
|
322
|
+
// Remember the topic a turn is running in: it is where a release notice goes,
|
|
323
|
+
// since a notice is about the install and the install serves every topic.
|
|
324
|
+
if (state.lastKey !== key) {
|
|
325
|
+
state.lastKey = key;
|
|
326
|
+
saveState();
|
|
327
|
+
}
|
|
328
|
+
|
|
317
329
|
// Desktop-style goal: the topic's goal and task list travel with every turn,
|
|
318
330
|
// so a fresh session after /new still knows what the project is aiming at.
|
|
319
331
|
// Without a goal the turn still gets the one line that says how to start one:
|
|
@@ -446,6 +458,14 @@ ${t(lang, 'help.body')}`,
|
|
|
446
458
|
? Math.round((telemetry.cacheReadTokens / Math.max(1, telemetry.cacheReadTokens + telemetry.inputTokens)) * 100)
|
|
447
459
|
: 0;
|
|
448
460
|
const summary = `tools=${telemetry.tools} tokens=${telemetry.inputTokens} cache=${cachePct}% model=${telemetry.model} cwd=${cwd}`;
|
|
461
|
+
if (result.stopped) {
|
|
462
|
+
// Stopped on purpose: no answer, but nothing broke either. It gets its own
|
|
463
|
+
// log word so "why did the turn end" is answerable without guessing, and it
|
|
464
|
+
// deliberately does NOT overwrite `state.lastFailure` — `/report` after a
|
|
465
|
+
// stop should describe the last real failure, not the stop itself.
|
|
466
|
+
log(`turn stopped ${where} ${seconds}s ${summary}`);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
449
469
|
if (result.error) {
|
|
450
470
|
// The status message already carries the failure (progress.finish turned it
|
|
451
471
|
// into the error report), so only the log gets the detail here — a second
|
package/help-explain.mjs
CHANGED
|
@@ -16,7 +16,7 @@ const SECTION = {
|
|
|
16
16
|
effort: 'Tuning', permissions: 'Tuning', preset: 'Tuning', crew: 'Tuning', plan: 'Tuning', jobs: 'Tuning', remind: 'Tuning',
|
|
17
17
|
skills: 'Extensions', plugins: 'Extensions', soul: 'Extensions',
|
|
18
18
|
update: 'Versions', subscribe: 'Versions',
|
|
19
|
-
settings: 'Other', lang: 'Other', reasoning: 'Other', pin: 'Other', doctor: 'Other', logs: 'Other', report: 'Other',
|
|
19
|
+
load: 'Models', settings: 'Other', lang: 'Other', reasoning: 'Other', pin: 'Other', doctor: 'Other', logs: 'Other', report: 'Other',
|
|
20
20
|
app: 'Other', restart: 'Other', help: 'Other', menu: 'Panels',
|
|
21
21
|
};
|
|
22
22
|
|
package/i18n/en/core.mjs
CHANGED
|
@@ -6,7 +6,7 @@ export default {
|
|
|
6
6
|
'status.failed': 'Turn failed',
|
|
7
7
|
'status.queued': 'queued',
|
|
8
8
|
'status.stop': 'Stop',
|
|
9
|
-
'bridge.progress.
|
|
9
|
+
'bridge.progress.topicId': 'Topic: id {n}',
|
|
10
10
|
'bridge.progress.topic': 'Topic: {name} (id {n})',
|
|
11
11
|
'settings.row.toggle': '{label}: {now}' + String.fromCharCode(10) + ' tap to get {next}. {hint}',
|
|
12
12
|
'settings.row.action': '{label}' + String.fromCharCode(10) + ' {hint}',
|
|
@@ -14,7 +14,7 @@ export default {
|
|
|
14
14
|
'settings.state.on': 'on',
|
|
15
15
|
'settings.state.off': 'off',
|
|
16
16
|
'settings.state.auto': 'auto',
|
|
17
|
-
'help.body': "Write the task as plain text. Each forum topic is its own session:\n\nWork: /cd \u003cproject\u003e · /new · /stop · /send \u003cfile\u003e · /seed \u003ctext\u003e\nGoals: /goal · /tasks [\u003ctext\u003e|done N] · /tasks (tap to tick)\nSessions: /status · /sessions [\u003cid\u003e] · /rewind [n|undo|fork [n]|branches] · /new · /profile \u003cname\u003e\nAgents: /agents · /agents set model|depth|filter … @tool\nModels: /model · /model \u003cid\u003e · /fallback · /prices · /thoughts\nTuning: /effort · /permissions · /preset · /crew [use|show|off|new] · /plan · /jobs [n] · /remind\nExtensions: /skills · /plugins [add|remove] · /soul\nVersions: /update [confirm|on|off|auto] · /subscribe on|off\nOther: /settings · /lang · /reasoning · /pin · /doctor · /logs [errors|N] · /report · /app · /restart · /help\nPanels: /menu — the same commands as buttons, page by page. /menu on puts four keys under the message field.",
|
|
17
|
+
'help.body': "Write the task as plain text. Each forum topic is its own session:\n\nWork: /cd \u003cproject\u003e · /new · /stop · /send \u003cfile\u003e · /seed \u003ctext\u003e\nGoals: /goal · /tasks [\u003ctext\u003e|done N] · /tasks (tap to tick)\nSessions: /status · /sessions [\u003cid\u003e] · /rewind [n|undo|fork [n]|branches] · /new · /profile \u003cname\u003e\nAgents: /agents · /agents set model|depth|filter … @tool\nModels: /model · /model \u003cid\u003e · /fallback · /load · /prices · /thoughts\nTuning: /effort · /permissions · /preset · /crew [use|show|off|new] · /plan · /jobs [n] · /remind\nExtensions: /skills · /plugins [add|remove] · /soul\nVersions: /update [confirm|on|off|auto] · /subscribe on|off\nOther: /settings · /lang · /reasoning · /pin · /doctor · /logs [errors|N] · /report · /app · /restart · /help\nPanels: /menu — the same commands as buttons, page by page. /menu on puts four keys under the message field.",
|
|
18
18
|
'settings.reply.title': 'What the bot says',
|
|
19
19
|
'settings.agent.title': 'Who answers, and how hard it works',
|
|
20
20
|
'settings.updates.title': 'New releases (this install, not this topic)',
|
|
@@ -98,6 +98,8 @@ export default {
|
|
|
98
98
|
'steer.ackFallback': '↪ Got the addition — folding it into this turn.',
|
|
99
99
|
'msg.started': 'Telegram bridge for DSH is running (headless). Send a task; /help for commands.',
|
|
100
100
|
'msg.restarted': 'Bridge restarted — back online (pid {pid}).\nThe topic and session are the same; keep going.',
|
|
101
|
+
'msg.turnStopped': 'Turn stopped. The session is intact — write again to continue from here.',
|
|
102
|
+
'msg.turnInterrupted': 'The restart stopped the turn that was running here. Send the message again — the session is intact, only this turn is gone.',
|
|
101
103
|
'cmd.restart.prompt': 'To restart the bridge: /restart confirm. For the DSH app: /app restart confirm.',
|
|
102
104
|
'cmd.restart.started': 'Restarting the bridge…',
|
|
103
105
|
'msg.generalGuard': "This is the General topic, where topics are started. {cmd} changes “{topic}”, so open that topic and send it there. Reading works here: /status, /sessions, /stop.",
|
|
@@ -250,4 +252,5 @@ export default {
|
|
|
250
252
|
'bridge.cb.taskDone': 'Done',
|
|
251
253
|
'bridge.cb.taskUndone': 'Reopened',
|
|
252
254
|
'bridge.cb.taskStale': 'That task is gone — /tasks shows the current list',
|
|
255
|
+
'msg.loadHeld': "Held back: {what}. Nothing was started, so nothing was spent — press «Run anyway» to send it now, or wait until the machine calms down.",
|
|
253
256
|
};
|
package/i18n/en/ctrl.mjs
CHANGED
|
@@ -458,4 +458,31 @@ export default {
|
|
|
458
458
|
'ctrl.set.storeBroken': '⚠️ {error}',
|
|
459
459
|
'ctrl.set.reloaded': 'Reloaded: {n} sets.',
|
|
460
460
|
'ctrl.set.dropped': 'Not applied: {field} — the profile does not declare it.',
|
|
461
|
+
'ctrl.load.title': "This computer · {host}",
|
|
462
|
+
'ctrl.load.cpu': "CPU",
|
|
463
|
+
'ctrl.load.ram': "Memory",
|
|
464
|
+
'ctrl.load.ramValue': "{free} of {total} GB free ({pct}% used)",
|
|
465
|
+
'ctrl.load.disk': "Disk {drive}",
|
|
466
|
+
'ctrl.load.unknown': "unreadable",
|
|
467
|
+
'ctrl.load.diskValue': "{free} of {total} GB free ({pct}% used)",
|
|
468
|
+
'ctrl.load.bridge': "Bridge: {turns} of {max} turn slots busy, {queued} waiting",
|
|
469
|
+
'ctrl.load.uptime': "Up {hours} h · {cores} cores",
|
|
470
|
+
'ctrl.load.guardOn': "Guard is ON: a new turn waits while the machine is over a limit.",
|
|
471
|
+
'ctrl.load.guardOff': "Guard is OFF: turns start whatever the machine is doing.",
|
|
472
|
+
'ctrl.load.limits': "Limits: CPU {cpu}% · memory below {ram}% free · disk below {disk} GB",
|
|
473
|
+
'ctrl.load.limitsOff': "Limits are kept for when you turn the guard on.",
|
|
474
|
+
'ctrl.load.over': "Over a limit: {what}.",
|
|
475
|
+
'ctrl.load.what.cpu': "CPU {value}% (limit {limit}%)",
|
|
476
|
+
'ctrl.load.what.ram': "memory {value}% free (limit {limit}%)",
|
|
477
|
+
'ctrl.load.what.disk': "disk {value} GB free (limit {limit} GB)",
|
|
478
|
+
'ctrl.load.usage': "Tap to refresh · /load on|off · /load limit cpu 80 · /load limit ram 10 · /load limit disk 20",
|
|
479
|
+
'ctrl.load.refresh': "Refresh",
|
|
480
|
+
'ctrl.load.turnOn': "Guard on",
|
|
481
|
+
'ctrl.load.turnOff': "Guard off",
|
|
482
|
+
'ctrl.load.limitsNow': "Limits — CPU {cpu}% · memory below {ram}% free · disk below {disk} GB.",
|
|
483
|
+
'ctrl.help.about.load': "How busy this computer is: CPU, memory, disk, and how many turn slots the bridge is using. The guard holds a new turn while the machine is over a limit, so somebody else at the same computer is not frozen out.",
|
|
484
|
+
'ctrl.load.runAnyway': "Run anyway",
|
|
485
|
+
'ctrl.load.running': "Running it now.",
|
|
486
|
+
'ctrl.load.refreshing': "Refreshing.",
|
|
487
|
+
'ctrl.load.heldGone': "That held message is gone — send it again.",
|
|
461
488
|
};
|