dsh-tg-bridge 1.9.1 → 1.9.3
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 +9 -5
- package/bridge.mjs +12 -20
- package/control.mjs +11 -2
- package/package.json +1 -1
- package/panel.mjs +69 -9
package/README.md
CHANGED
|
@@ -264,13 +264,17 @@ Two things land in the same progress message, and neither sends a chat message o
|
|
|
264
264
|
**The model's reasoning.** Every `thinking` block the CLI commits is folded into one
|
|
265
265
|
Telegram `<blockquote expandable>`: collapsed it is a single line, tapped it opens the whole
|
|
266
266
|
trail of the turn, and it stays there after the turn ends — the same way the desktop app shows
|
|
267
|
-
a reasoning section you can expand. The block is
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
267
|
+
a reasoning section you can expand. The block is written once, in the final edit of the turn,
|
|
268
|
+
and never touched again: Telegram re-collapses an expanded block on every edit of its message,
|
|
269
|
+
which used to yank the chat away from a half-read paragraph. While the turn runs the message
|
|
270
|
+
only gets a counter (`🧠 Размышления · 4821`) and the last three steps, so the live edits stay
|
|
271
|
+
short. Escaped, and trimmed to its tail when a turn thinks longer than a message can hold; the
|
|
272
|
+
panel never exceeds one message. A cut block says `… · /thoughts`, which returns the whole
|
|
273
|
+
text. If the API refuses the markup, the same content is retried as plain text.
|
|
271
274
|
|
|
272
275
|
**The steps.** Three calls fit inline. A turn that makes more moves its complete step list into
|
|
273
|
-
a second collapsed block, so "what did it actually run" is one
|
|
276
|
+
a second collapsed block, added in that same final edit, so "what did it actually run" is one
|
|
277
|
+
tap away instead of a count.
|
|
274
278
|
|
|
275
279
|
**The agent's own notes.** The agent can add a short decision trail:
|
|
276
280
|
|
package/bridge.mjs
CHANGED
|
@@ -33,7 +33,7 @@ import { handleControl, CONTROL_COMMANDS, modelOf, reasoningOf } from './control
|
|
|
33
33
|
import { drainGoalJobs, goalOf, renderPromptBlock } from './goals.mjs';
|
|
34
34
|
import { renderPrices } from './prices.mjs';
|
|
35
35
|
import { t, resolveLang } from './i18n.mjs';
|
|
36
|
-
import { progressPanel } from './panel.mjs';
|
|
36
|
+
import { progressPanel, stepLine, addStep } from './panel.mjs';
|
|
37
37
|
|
|
38
38
|
const HOME = homedir();
|
|
39
39
|
const DSH_HOME = process.env.DSH_HOME || join(HOME, '.dsh');
|
|
@@ -925,22 +925,6 @@ function killTurn(key) {
|
|
|
925
925
|
}
|
|
926
926
|
}
|
|
927
927
|
|
|
928
|
-
/** Short, human one-liner for a tool call, mirroring what Hermes shows. */
|
|
929
|
-
function toolLine(event) {
|
|
930
|
-
const tool = event.tool || 'tool';
|
|
931
|
-
const input = event.input ?? {};
|
|
932
|
-
const pick = input.command ?? input.description ?? input.file_path ?? input.path ?? input.pattern ?? input.query ?? input.url ?? '';
|
|
933
|
-
let text = String(pick).replace(/\s+/g, ' ').trim();
|
|
934
|
-
if (input.command) {
|
|
935
|
-
// A shell command is a wall of text; keep the first statement and its
|
|
936
|
-
// verb, so the line reads "pwsh: git status" instead of the whole script.
|
|
937
|
-
text = text.split(';')[0].trim();
|
|
938
|
-
text = text.replace(/^(pwsh|powershell|cmd|bash)(\.exe)?\s+(-\S+\s+)*/i, '');
|
|
939
|
-
const verb = text.match(/^([A-Za-z0-9_.\-]+(?:\s+[a-z][a-z0-9-]*)?)/);
|
|
940
|
-
if (verb) text = verb[1];
|
|
941
|
-
}
|
|
942
|
-
return text ? `${tool}: ${text.slice(0, 48)}` : tool;
|
|
943
|
-
}
|
|
944
928
|
|
|
945
929
|
/**
|
|
946
930
|
* One editable status message per turn.
|
|
@@ -1042,8 +1026,15 @@ async function startProgress(chatId, threadId, lang = 'ru') {
|
|
|
1042
1026
|
log(`progress message failed: ${error.message}`);
|
|
1043
1027
|
}
|
|
1044
1028
|
|
|
1029
|
+
let lastView = '';
|
|
1045
1030
|
const edit = async (text, keyboard = undefined, view = null) => {
|
|
1046
1031
|
if (!messageId) return;
|
|
1032
|
+
// Re-sending identical text counts as an edit on the phone (the block
|
|
1033
|
+
// collapses and the list re-lays-out), so a no-op must not reach Telegram.
|
|
1034
|
+
if (view && keyboard === undefined && view.html === lastView) {
|
|
1035
|
+
dirty = false;
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1047
1038
|
const payload = {
|
|
1048
1039
|
chat_id: chatId,
|
|
1049
1040
|
message_id: messageId,
|
|
@@ -1058,6 +1049,7 @@ async function startProgress(chatId, threadId, lang = 'ru') {
|
|
|
1058
1049
|
if (keyboard !== undefined) body.reply_markup = keyboard ?? { inline_keyboard: [] };
|
|
1059
1050
|
await tg('editMessageText', body);
|
|
1060
1051
|
}
|
|
1052
|
+
lastView = view ? view.html : text;
|
|
1061
1053
|
lastEdit = Date.now();
|
|
1062
1054
|
} catch (error) {
|
|
1063
1055
|
// "message is not modified" and rate limits are expected: ignore quietly.
|
|
@@ -1073,7 +1065,7 @@ async function startProgress(chatId, threadId, lang = 'ru') {
|
|
|
1073
1065
|
if (!dirty) return;
|
|
1074
1066
|
dirty = false;
|
|
1075
1067
|
await edit('', undefined, panel());
|
|
1076
|
-
},
|
|
1068
|
+
}, 5000);
|
|
1077
1069
|
timer.unref?.();
|
|
1078
1070
|
}
|
|
1079
1071
|
|
|
@@ -1086,7 +1078,7 @@ async function startProgress(chatId, threadId, lang = 'ru') {
|
|
|
1086
1078
|
},
|
|
1087
1079
|
handle(event) {
|
|
1088
1080
|
if (event.type === 'tool_call') {
|
|
1089
|
-
steps
|
|
1081
|
+
addStep(steps, stepLine(event));
|
|
1090
1082
|
schedule();
|
|
1091
1083
|
return;
|
|
1092
1084
|
}
|
|
@@ -1531,7 +1523,7 @@ ${t(lang, 'help.body')}`,
|
|
|
1531
1523
|
if (event.type === 'tool_call') {
|
|
1532
1524
|
telemetry.tools += 1;
|
|
1533
1525
|
telemetry.steps += 1;
|
|
1534
|
-
log(` tool[${telemetry.steps}] ${
|
|
1526
|
+
log(` tool[${telemetry.steps}] ${(stepLine(event) || event.tool || 'tool').slice(0, 140)}`);
|
|
1535
1527
|
} else if (event.type === 'tool_result') {
|
|
1536
1528
|
const failed = event.status && event.status !== 'completed';
|
|
1537
1529
|
log(` tool[${telemetry.steps}] ${failed ? 'ОШИБКА' : 'ok'} ${String(event.tool || '').slice(0, 40)}`);
|
package/control.mjs
CHANGED
|
@@ -1692,7 +1692,7 @@ export async function handleControl(ctx) {
|
|
|
1692
1692
|
return true;
|
|
1693
1693
|
}
|
|
1694
1694
|
const file = sessionFile(join(DSH_HOME, 'sessions'), sessionId);
|
|
1695
|
-
const text = file ? lastTurnReasoning(file, { maxChars:
|
|
1695
|
+
const text = file ? lastTurnReasoning(file, { maxChars: 20000 }) : '';
|
|
1696
1696
|
if (!text) {
|
|
1697
1697
|
// Not every turn plans: a one-word answer has no reasoning part at all.
|
|
1698
1698
|
// Saying "here is what the last turn answered" beats a dead end that
|
|
@@ -1703,7 +1703,16 @@ export async function handleControl(ctx) {
|
|
|
1703
1703
|
: t(lang, 'ctrl.thoughts.none'));
|
|
1704
1704
|
return true;
|
|
1705
1705
|
}
|
|
1706
|
-
|
|
1706
|
+
// A message caps at 4096 characters; a long plan goes out in parts instead
|
|
1707
|
+
// of being cut at the first one with a "…" that hides the rest.
|
|
1708
|
+
const title = t(lang, 'ctrl.thoughts.title', { chars: text.length });
|
|
1709
|
+
const parts = [];
|
|
1710
|
+
for (let at = 0; at < text.length; at += 3600) parts.push(text.slice(at, at + 3600));
|
|
1711
|
+
parts.forEach((part, index) => {
|
|
1712
|
+
say(parts.length > 1
|
|
1713
|
+
? `${title} (${index + 1}/${parts.length})\n\n${part}`
|
|
1714
|
+
: `${title}\n\n${part}`);
|
|
1715
|
+
});
|
|
1707
1716
|
return true;
|
|
1708
1717
|
}
|
|
1709
1718
|
|
package/package.json
CHANGED
package/panel.mjs
CHANGED
|
@@ -31,14 +31,58 @@ function tailOf(text, room) {
|
|
|
31
31
|
return { text: text.slice(-room), cut: true };
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* One line for a tool call in the panel.
|
|
36
|
+
*
|
|
37
|
+
* The harness runs every call in a fresh shell, so most commands start with
|
|
38
|
+
* `cd <dir>`; that prefix says nothing about the work. Strip it (and the shell
|
|
39
|
+
* wrapper) and keep the statement that does something, with its arguments — a
|
|
40
|
+
* list of bare verbs (`pwsh: cd`, `pwsh: node`) is what made the panel read as
|
|
41
|
+
* noise. A call that only changed directory returns '' and is not shown.
|
|
42
|
+
*/
|
|
43
|
+
export function stepLine(event) {
|
|
44
|
+
const tool = event.tool || 'tool';
|
|
45
|
+
const input = event.input ?? {};
|
|
46
|
+
const pick = input.command ?? input.description ?? input.file_path ?? input.path
|
|
47
|
+
?? input.pattern ?? input.query ?? input.url ?? '';
|
|
48
|
+
let text = String(pick).replace(/\r?\n/g, ' ; ').replace(/\s+/g, ' ').trim();
|
|
49
|
+
if (input.command) {
|
|
50
|
+
text = text.replace(/^(pwsh|powershell|cmd|bash)(\.exe)?\s+(-\S+\s+)*/i, '');
|
|
51
|
+
text = text.replace(/^(cd\s+("[^"]*"|'[^']*'|\S+)\s*(?:&&|;)\s*)+/i, '');
|
|
52
|
+
text = text.replace(/^cd\s+("[^"]*"|'[^']*'|\S+)\s*$/i, '').trim();
|
|
53
|
+
text = text.replace(/\s*(?:&&|;|\|\|)\s*[\s\S]*$/, '').trim();
|
|
54
|
+
if (!text) return '';
|
|
55
|
+
}
|
|
56
|
+
return `${tool}: ${text.slice(0, 64)}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Push a step, folding a repeat into the line above it: `×3`, not three rows. */
|
|
60
|
+
export function addStep(steps, line) {
|
|
61
|
+
if (!line) return steps;
|
|
62
|
+
const at = steps.length - 1;
|
|
63
|
+
const prev = at >= 0 ? /^(.*) ×(\d+)$/.exec(steps[at]) : null;
|
|
64
|
+
if (at >= 0 && steps[at] === line) {
|
|
65
|
+
steps[at] = `${line} ×2`;
|
|
66
|
+
return steps;
|
|
67
|
+
}
|
|
68
|
+
if (prev && prev[1] === line) {
|
|
69
|
+
steps[at] = `${line} ×${Number(prev[2]) + 1}`;
|
|
70
|
+
return steps;
|
|
71
|
+
}
|
|
72
|
+
steps.push(line);
|
|
73
|
+
return steps;
|
|
74
|
+
}
|
|
75
|
+
|
|
34
76
|
/**
|
|
35
77
|
* One status message per turn, rewritten in place.
|
|
36
78
|
*
|
|
37
79
|
* Long content lives in Telegram's native `<blockquote expandable>`: collapsed it
|
|
38
80
|
* is one line, tapped it shows the whole trail, and it never floods the chat. Two
|
|
39
81
|
* blocks at most — the model's reasoning and, when a turn makes more than three
|
|
40
|
-
* tool calls, the full step list
|
|
41
|
-
*
|
|
82
|
+
* tool calls, the full step list. They appear only in the final edit (`final`):
|
|
83
|
+
* Telegram re-collapses an expanded block on every edit of its message, so a live
|
|
84
|
+
* edit that carried blocks would yank the chat away from whoever is reading one.
|
|
85
|
+
* `plain` is the same content without markup, for the fallback path when
|
|
42
86
|
* the parser refuses a message and for `plainText` installs.
|
|
43
87
|
*/
|
|
44
88
|
export function progressPanel({
|
|
@@ -50,35 +94,51 @@ export function progressPanel({
|
|
|
50
94
|
const mind = thoughts.map((line) => `💭 ${line}`);
|
|
51
95
|
const base = [head, ...mind, cache].filter(Boolean).join('\n').length;
|
|
52
96
|
|
|
53
|
-
//
|
|
54
|
-
//
|
|
97
|
+
// While the turn runs this message is rewritten every few seconds, and
|
|
98
|
+
// Telegram drops an expanded block on every edit — which is what yanks the
|
|
99
|
+
// chat away from someone mid-sentence. So a live edit stays short: the last
|
|
100
|
+
// steps inline, a counter instead of the reasoning, no collapsible content at
|
|
101
|
+
// all. The two blocks arrive once, in the final edit, which nothing touches
|
|
102
|
+
// again, so a block can be opened and read in peace.
|
|
55
103
|
const many = steps.length > 3;
|
|
56
|
-
const inline = many
|
|
104
|
+
const inline = many
|
|
105
|
+
? (final ? [] : steps.slice(-3).map((line) => `• ${line}`))
|
|
106
|
+
: steps.map((line) => `• ${line}`);
|
|
107
|
+
const more = !final && many ? t(lang, 'status.more', { n: steps.length - 3 }) : '';
|
|
108
|
+
const text = String(thinking || '').trim();
|
|
109
|
+
const live = !final && text ? `🧠 ${t(lang, 'status.thinkTitle')} · ${text.length}` : '';
|
|
57
110
|
const stepsRoom = Math.max(0, Math.min(STEPS_MAX, PANEL_MAX - base - 1200));
|
|
58
|
-
const all = many
|
|
111
|
+
const all = many && final
|
|
59
112
|
? tailOf(steps.map((line) => `• ${line}`).join('\n'), stepsRoom)
|
|
60
113
|
: { text: '', cut: false };
|
|
61
114
|
const stepsLabel = `🛠 ${t(lang, 'status.stepsTitle')} · ${steps.length}`
|
|
62
115
|
+ `${all.cut ? ` · ${t(lang, 'status.thinkCut')}` : ''}`;
|
|
63
116
|
|
|
64
|
-
const fixed = base + inline.join('\n').length + all.text.length + 120;
|
|
117
|
+
const fixed = base + inline.join('\n').length + all.text.length + more.length + live.length + 120;
|
|
65
118
|
const room = Math.max(400, Math.min(THINKING_MAX, PANEL_MAX - fixed));
|
|
66
|
-
const body = tailOf(
|
|
67
|
-
|
|
119
|
+
const body = final ? tailOf(text, room) : { text: '', cut: false };
|
|
120
|
+
// A cut block starts mid-sentence; say so and point at the one command that
|
|
121
|
+
// still has the whole text, otherwise the reasoning reads as broken.
|
|
122
|
+
const thinkLabel = `🧠 ${t(lang, 'status.thinkTitle')}`
|
|
123
|
+
+ `${body.cut ? ` · ${t(lang, 'status.thinkCut')} · /thoughts` : ''}`;
|
|
68
124
|
|
|
69
125
|
const html = [
|
|
70
126
|
head,
|
|
71
127
|
...mind.map((line) => escapeHtml(line)),
|
|
128
|
+
escapeHtml(live),
|
|
72
129
|
body.text ? `<blockquote expandable>${escapeHtml(thinkLabel)}\n${escapeHtml(body.text)}</blockquote>` : '',
|
|
73
130
|
...inline.map((line) => escapeHtml(line)),
|
|
131
|
+
escapeHtml(more),
|
|
74
132
|
all.text ? `<blockquote expandable>${escapeHtml(stepsLabel)}\n${escapeHtml(all.text)}</blockquote>` : '',
|
|
75
133
|
escapeHtml(cache),
|
|
76
134
|
].filter(Boolean).join('\n');
|
|
77
135
|
const plain = [
|
|
78
136
|
head,
|
|
79
137
|
...mind,
|
|
138
|
+
live,
|
|
80
139
|
body.text ? `${thinkLabel}\n${body.text}` : '',
|
|
81
140
|
...inline,
|
|
141
|
+
more,
|
|
82
142
|
all.text ? `${stepsLabel}\n${all.text}` : '',
|
|
83
143
|
cache,
|
|
84
144
|
].filter(Boolean).join('\n');
|