@shliamb/dsh-telegram-bot 0.2.5 β†’ 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@ Package: [`@shliamb/dsh-telegram-bot`](https://www.npmjs.com/package/@shliamb/ds
6
6
 
7
7
  Telegram bridge for **DeepSeek Harness**. The plugin runs inside the Harness Host as an external bundle: you talk to the agent from a private Telegram chat, choose a workspace and session, follow long turns with a live progress message, and manage the Host remotely.
8
8
 
9
- > **Status:** Phase 2.2, early alpha. The bundle targets DeepSeek Harness `0.2.2-alpha.3` and the `web` profile.
9
+ > **Status:** 0.2.7, early beta. The bundle targets DeepSeek Harness `0.2.2-alpha.3` and the `web` profile.
10
10
 
11
11
  ## Features
12
12
 
@@ -16,10 +16,26 @@ Telegram bridge for **DeepSeek Harness**. The plugin runs inside the Harness Hos
16
16
  - One editable progress message per turn (`πŸ’­ thinking`, `πŸ”§ tool`, `✍️ writing`, `βœ… done`) instead of a stream of bash output.
17
17
  - Parallel turns: switch to another workspace while an older turn keeps updating. Its final answer still arrives in the same chat.
18
18
  - Tool approvals and agent questions as inline buttons; typed text answers as custom, including multi-select.
19
+ - Questions and approvals follow the active Telegram session: the bot claims them for that session; every other session stays in Web and gets a text notice after 15 seconds.
19
20
  - Main menu with account balance, workspace, session, context usage and colored buttons.
21
+ - Context percentage matches the Web meter, including right after compaction, and refreshes every time you open `/start` or `/menu`.
22
+ - Draft sessions are hidden and reused, so pressing **New session** twice does not create duplicates; the current session is marked `βœ…`.
20
23
  - Sound on/off per chat, history compaction via `/compact`, and a confirmed stop.
21
24
  - Admin screen with log download and remote Harness restart.
22
- - Russian or English UI, chosen from the Telegram client language (`ru*` β†’ Russian, otherwise English).
25
+ - Russian or English UI automatically, chosen from the Telegram interface language (`ru*` β†’ Russian, any other β†’ English). Menus, buttons, progress, questions, approvals and command descriptions follow it; the Web settings page follows the Web UI locale.
26
+
27
+ ## Screenshots
28
+
29
+ ![Telegram main menu in Russian](https://raw.githubusercontent.com/shliamb/HarnessBot/main/images/telegram-menu-ru.jpg)
30
+
31
+ The main menu in Russian: balance, active workspace and session, context usage, and action buttons.
32
+
33
+ ## What's new
34
+
35
+ - **0.2.7 β€” fresh context and calm compaction.** The menu reads the projection view (`projectedTokens`), so the percentage is correct immediately after compaction and on every `/start`; pressing **Compact** replaces the confirmation with a waiting message and removes the buttons.
36
+ - **0.2.6 β€” routing.** Questions and approvals belong to the Session currently open in Telegram. Other Sessions stay in Web, and after 15 seconds the bot sends a text notice with the workspace and Session name.
37
+ - **0.2.5 β€” context and sessions.** The context percentage now matches Web after compaction (`projectedTokens`), empty draft Sessions are reused and hidden, and the current Session is marked `βœ…`.
38
+ - **Languages.** The whole bot follows Telegram's interface language: `ru*` β†’ Russian, any other β†’ English. The binding locale is refreshed on every update, so a language change applies to progress, answers, questions and approvals immediately.
23
39
 
24
40
  ## Requirements
25
41
 
@@ -29,6 +45,13 @@ Telegram bridge for **DeepSeek Harness**. The plugin runs inside the Harness Hos
29
45
  - Your numeric Telegram user ID, for example from [@userinfobot](https://t.me/userinfobot).
30
46
  - A running Host. One bot token can be polled by only one Host process at a time (otherwise Telegram returns `409 Conflict`).
31
47
 
48
+ ## Stack
49
+
50
+ - DeepSeek Harness `web` profile, installed as an external Cordis bundle (`cordis.patch.yml`).
51
+ - TypeScript on Node.js `>= 24.9`; grammY for long polling.
52
+ - React settings page registered through DSH client slots.
53
+ - No runtime imports of `@deepseek-ai/dsh-*`: Host services are described by local types.
54
+
32
55
  ## Installation
33
56
 
34
57
  The package is published on npm as **`@shliamb/dsh-telegram-bot`**. The short name `dsh-telegram-bot` is already used by another project, so use the scoped name.
@@ -59,13 +82,13 @@ Adding a new bundle requires a Host restart. Chat sessions and bindings survive
59
82
  The repository also contains a ready-to-install archive:
60
83
 
61
84
  ```text
62
- dist/shliamb-dsh-telegram-bot-0.2.5.tgz
85
+ dist/shliamb-dsh-telegram-bot-0.2.7.tgz
63
86
  ```
64
87
 
65
88
  If the `dsh` CLI is on your `PATH`, run this from the repository root:
66
89
 
67
90
  ```bash
68
- dsh plugin --profile web add ./dist/shliamb-dsh-telegram-bot-0.2.5.tgz
91
+ dsh plugin --profile web add ./dist/shliamb-dsh-telegram-bot-0.2.7.tgz
69
92
  dsh web
70
93
  ```
71
94
 
@@ -73,7 +96,7 @@ If you run Harness from a source checkout, use `pnpm dsh` from that checkout and
73
96
 
74
97
  ```bash
75
98
  cd /path/to/deepseek-harness
76
- pnpm dsh plugin --profile web add /path/to/HarnessBot/dist/shliamb-dsh-telegram-bot-0.2.5.tgz
99
+ pnpm dsh plugin --profile web add /path/to/HarnessBot/dist/shliamb-dsh-telegram-bot-0.2.7.tgz
77
100
  pnpm dsh web
78
101
  ```
79
102
 
@@ -160,7 +183,7 @@ On a fresh Host start the bot sends the admin a single **β€œHarness is online”
160
183
 
161
184
  ### Commands
162
185
 
163
- Only `/start` is shown in Telegram's command menu. The other commands are hidden but still work when typed manually.
186
+ Only `/start` is shown in Telegram's command menu. `/admin` is additionally scoped to the admin chat; the other commands are hidden but still work when typed manually.
164
187
 
165
188
  | Command | Description |
166
189
  | --- | --- |
@@ -174,6 +197,10 @@ Only `/start` is shown in Telegram's command menu. The other commands are hidden
174
197
 
175
198
  Final answers are sent as separate rich messages. Long text is split into parts that fit Telegram's message limit. If rich formatting fails, the plugin retries with rich HTML and then with plain text, so the answer is not lost.
176
199
 
200
+ ### Languages
201
+
202
+ The bot follows Telegram's interface language: a `ru*` code selects Russian, any other code selects English. The binding locale is refreshed on every update, so progress, final answers, questions and approvals switch immediately after you change Telegram's language. Command descriptions use the same rule. The Web settings page follows the Web UI locale. Agent-produced text is left as the agent wrote it.
203
+
177
204
  ### Workspaces and sessions
178
205
 
179
206
  After you choose a workspace:
@@ -202,13 +229,15 @@ Turn tracking lives in Host memory. If the Host is restarted in the middle of a
202
229
 
203
230
  ### Approvals and questions
204
231
 
205
- When the agent requests a tool approval, the bot sends an inline **Allow** / **Deny** keyboard. When the agent asks a question with predefined options, the answers are inline buttons as well. Requests time out after 10 minutes.
232
+ When the agent requests a tool approval, the bot sends an inline **Allow** / **Deny** keyboard. When the agent asks a question with predefined options, the answers are inline buttons as well. In Telegram the card is closed after 10 minutes; an unanswered question is returned as skipped.
206
233
 
207
234
  Approvals and questions are answered for the bound session. The bot asks one question at a time. For a single-select question, tapping an option answers immediately; for a multi-select question, toggle the options and tap **Done**. Typing text while a question is open sends it as the custom answer (for multi-select it supplements the selected options), and **Skip** leaves the question unanswered. While a question or approval is open, ordinary text is not queued as a new prompt.
208
235
 
236
+ Where the prompt appears is decided by the Telegram binding. If the request belongs to the Session currently open in the bot, Telegram claims it and shows the buttons. Any other Session keeps the prompt in Web; if Web has not settled it within 15 seconds, the bot sends a plain text notice naming the workspace and Session. This keeps Web as the primary surface while a deliberately opened Telegram Session takes over its own questions and approvals.
237
+
209
238
  ### Compaction, sound and stop
210
239
 
211
- - **Compact** shows the current context percentage and asks for confirmation. The plugin calls the preset-scoped `/compact` command through the `commands` service and reports the localized result and the new percentage. If the agent is busy, compaction is refused.
240
+ - **Compact** shows the current context percentage and asks for confirmation. Pressing **Compact** replaces the card with a waiting message and removes the buttons, so repeated taps do nothing. The plugin calls the preset-scoped `/compact` command through the `commands` service and reports the localized result and the new percentage. If the agent is busy, compaction is refused.
212
241
  - **Sound** is stored per chat. When it is off, answers, progress edits and the startup greeting use `disable_notification`.
213
242
  - **Stop** asks for confirmation, then cancels the current turn with `agent.cancel({ kind: 'user' })`.
214
243
 
@@ -283,6 +312,7 @@ pnpm pack --pack-destination dist
283
312
  src/index.ts Host plugin: config, bot runtime, menus, commands
284
313
  src/client/index.tsx Web settings page (token + admin ID)
285
314
  src/client/locales.ts Russian and English UI strings
315
+ images/ README screenshots
286
316
  src/state/index.ts Chat bindings in the storageDomain
287
317
  src/logging/index.ts JSONL file log with rotation
288
318
  src/*/SPEC.md Module contracts and data formats
@@ -299,13 +329,15 @@ dist/ Prebuilt install archive
299
329
  - Web settings expose only the token and the admin ID; `lowBalanceUsd`, `rich` and `apiRoot` are configured through `cordis.patch.yml`.
300
330
  - No voice or file handling: Telegram transcribes voice messages itself.
301
331
  - No proxy configuration.
302
- - Approvals and questions are tied to the bound session. An unbound or unsupported question is answered in the Web UI; Telegram supports single-select, multi-select, custom text and skip.
332
+ - Questions and approvals for the active Telegram session appear only in Telegram; other sessions stay in Web with a delayed text notice. Telegram supports single-select, multi-select, custom text and skip.
303
333
  - Progress tracking is in memory, so a Host restart in the middle of a turn can leave a stale progress message.
304
334
 
305
335
  ## Roadmap
306
336
 
307
- - Phase 2.2: `/history`, reply routing, completion notifications for other sessions.
308
- - Phase 3.2: npm package and listing in the plugin catalog.
337
+ - Done in 0.2.5: context meter from `projectedTokens`, draft-session reuse, `βœ…` current session, English command fallback, locale sync.
338
+ - Done in 0.2.6: active-session routing for questions and approvals, 15-second Web-waiting text notice, diagnostics.
339
+ - Done in 0.2.7: context from the projection snapshot, forced refresh on menu open, compact waiting state, removed the redundant question-keyboard clear call.
340
+ - Next: `/history`; reply routing; completion notifications for other sessions; plugin catalog listing.
309
341
 
310
342
  ## License
311
343
 
package/README.ru.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Telegram-мост для **DeepSeek Harness**. Плагин устанавливаСтся Π² ΠΏΡ€ΠΎΡ„ΠΈΠ»ΡŒ `web` ΠΊΠ°ΠΊ внСшний Π±Π°Π½Π΄Π» ΠΈ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ Π²Π½ΡƒΡ‚Ρ€ΠΈ Host-процСсса: Π²Ρ‹ ΠΎΠ±Ρ‰Π°Π΅Ρ‚Π΅ΡΡŒ с Π°Π³Π΅Π½Ρ‚ΠΎΠΌ ΠΈΠ· ΠΏΡ€ΠΈΠ²Π°Ρ‚Π½ΠΎΠ³ΠΎ Ρ‡Π°Ρ‚Π° Telegram, Π²Ρ‹Π±ΠΈΡ€Π°Π΅Ρ‚Π΅ пространство ΠΈ сСссию, слСдитС Π·Π° Π΄Π»ΠΈΠ½Π½Ρ‹ΠΌΠΈ Ρ…ΠΎΠ΄Π°ΠΌΠΈ Ρ‡Π΅Ρ€Π΅Π· ΠΎΠ΄Π½ΠΎ progress-сообщСниС ΠΈ управляСтС Host ΡƒΠ΄Π°Π»Ρ‘Π½Π½ΠΎ.
8
8
 
9
- > **Бтатус:** Phase 2.2, ранняя Π°Π»ΡŒΡ„Π°. Π‘Π°Π½Π΄Π» рассчитан Π½Π° DeepSeek Harness `0.2.2-alpha.3` ΠΈ ΠΏΡ€ΠΎΡ„ΠΈΠ»ΡŒ `web`.
9
+ > **Бтатус:** 0.2.7, ранняя Π±Π΅Ρ‚Π°. Π‘Π°Π½Π΄Π» рассчитан Π½Π° DeepSeek Harness `0.2.2-alpha.3` ΠΈ ΠΏΡ€ΠΎΡ„ΠΈΠ»ΡŒ `web`.
10
10
 
11
11
  ## ВозмоТности
12
12
 
@@ -16,10 +16,26 @@ Telegram-мост для **DeepSeek Harness**. Плагин устанавлив
16
16
  - Одно Ρ€Π΅Π΄Π°ΠΊΡ‚ΠΈΡ€ΡƒΠ΅ΠΌΠΎΠ΅ progress-сообщСниС Π½Π° Ρ…ΠΎΠ΄ (`πŸ’­ Π΄ΡƒΠΌΠ°Π΅Ρ‚`, `πŸ”§ инструмСнт`, `✍️ ΠΏΠΈΡˆΠ΅Ρ‚`, `βœ… Π³ΠΎΡ‚ΠΎΠ²ΠΎ`) вмСсто ΠΏΠΎΡ‚ΠΎΠΊΠ° bash-Π²Ρ‹Π²ΠΎΠ΄Π°.
17
17
  - ΠŸΠ°Ρ€Π°Π»Π»Π΅Π»ΡŒΠ½Ρ‹Π΅ Ρ…ΠΎΠ΄Ρ‹: ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠ΅Ρ€Π΅ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒΡΡ Π² Π΄Ρ€ΡƒΠ³ΠΎΠ΅ пространство, Π° староС progress-сообщСниС ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠΈΡ‚ ΠΎΠ±Π½ΠΎΠ²Π»ΡΡ‚ΡŒΡΡ. Π€ΠΈΠ½Π°Π»ΡŒΠ½Ρ‹ΠΉ ΠΎΡ‚Π²Π΅Ρ‚ всё Ρ€Π°Π²Π½ΠΎ ΠΏΡ€ΠΈΠ΄Ρ‘Ρ‚ Π² Ρ‚ΠΎΡ‚ ΠΆΠ΅ Ρ‡Π°Ρ‚.
18
18
  - ΠŸΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π΅Π½ΠΈΡ инструмСнтов ΠΈ вопросы Π°Π³Π΅Π½Ρ‚Π° ΠΊΠ½ΠΎΠΏΠΊΠ°ΠΌΠΈ; тСкст принимаСтся ΠΊΠ°ΠΊ «свой ΠΎΡ‚Π²Π΅Ρ‚Β», Π²ΠΊΠ»ΡŽΡ‡Π°Ρ ΠΌΡƒΠ»ΡŒΡ‚ΠΈΠ²Ρ‹Π±ΠΎΡ€.
19
+ - Вопросы ΠΈ подтвСрТдСния ΠΈΠ΄ΡƒΡ‚ Π² Ρ‚Ρƒ сСссию, которая ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚Π° Π² Telegram; ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Π΅ сСссии ΠΎΡΡ‚Π°ΡŽΡ‚ΡΡ Π² Web ΠΈ Ρ‡Π΅Ρ€Π΅Π· 15 сСкунд ΠΏΠΎΠ»ΡƒΡ‡Π°ΡŽΡ‚ тСкстовоС ΡƒΠ²Π΅Π΄ΠΎΠΌΠ»Π΅Π½ΠΈΠ΅.
19
20
  - Π“Π»Π°Π²Π½ΠΎΠ΅ мСню с балансом, пространством, сСссиСй, ΠΏΡ€ΠΎΡ†Π΅Π½Ρ‚ΠΎΠΌ контСкста ΠΈ Ρ†Π²Π΅Ρ‚Π½Ρ‹ΠΌΠΈ ΠΊΠ½ΠΎΠΏΠΊΠ°ΠΌΠΈ.
21
+ - ΠŸΡ€ΠΎΡ†Π΅Π½Ρ‚ контСкста совпадаСт с Web, Π² Ρ‚ΠΎΠΌ числС сразу послС сТатия, ΠΈ обновляСтся ΠΏΡ€ΠΈ ΠΊΠ°ΠΆΠ΄ΠΎΠΌ ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚ΠΈΠΈ `/start` ΠΈΠ»ΠΈ `/menu`.
22
+ - ΠŸΡƒΡΡ‚Ρ‹Π΅ сСссии скрыты ΠΈ ΠΏΠ΅Ρ€Π΅ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ: ΠΏΠΎΠ²Ρ‚ΠΎΡ€Π½ΠΎΠ΅ Π½Π°ΠΆΠ°Ρ‚ΠΈΠ΅ «Новая сСссия» Π½Π΅ ΠΏΠ»ΠΎΠ΄ΠΈΡ‚ Π΄ΡƒΠ±Π»ΠΈ, тСкущая ΠΏΠΎΠΌΠ΅Ρ‡Π΅Π½Π° `βœ…`.
20
23
  - Π—Π²ΡƒΠΊ on/off для Ρ‡Π°Ρ‚Π°, сТатиС истории Ρ‡Π΅Ρ€Π΅Π· `/compact`, остановка с ΠΏΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π΅Π½ΠΈΠ΅ΠΌ.
21
24
  - Админ-экран с Π»ΠΎΠ³Π°ΠΌΠΈ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΎΠΌ ΠΈ ΡƒΠ΄Π°Π»Ρ‘Π½Π½Ρ‹ΠΌ пСрСзапуском Harness.
22
- - Русский ΠΈΠ»ΠΈ английский интСрфСйс ΠΏΠΎ языку Telegram (`ru*` β†’ русский, ΠΈΠ½Π°Ρ‡Π΅ английский).
25
+ - Русский ΠΈΠ»ΠΈ английский интСрфСйс автоматичСски ΠΏΠΎ языку Telegram (`ru*` β†’ русский, любой Π΄Ρ€ΡƒΠ³ΠΎΠΉ β†’ английский). МСню, ΠΊΠ½ΠΎΠΏΠΊΠΈ, progress, вопросы, подтвСрТдСния ΠΈ описания ΠΊΠΎΠΌΠ°Π½Π΄ ΡΠ»Π΅Π΄ΡƒΡŽΡ‚ этому ΠΏΡ€Π°Π²ΠΈΠ»Ρƒ; страница настроСк Π² Web β€” языку Web-интСрфСйса.
26
+
27
+ ## Π‘ΠΊΡ€ΠΈΠ½ΡˆΠΎΡ‚Ρ‹
28
+
29
+ ![Π“Π»Π°Π²Π½ΠΎΠ΅ мСню Telegram Π½Π° русском](https://raw.githubusercontent.com/shliamb/HarnessBot/main/images/telegram-menu-ru.jpg)
30
+
31
+ Π“Π»Π°Π²Π½ΠΎΠ΅ мСню Π½Π° русском: баланс, Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠ΅ пространство ΠΈ сСссия, ΠΏΡ€ΠΎΡ†Π΅Π½Ρ‚ контСкста ΠΈ ΠΊΠ½ΠΎΠΏΠΊΠΈ дСйствий.
32
+
33
+ ## Π§Ρ‚ΠΎ Π½ΠΎΠ²ΠΎΠ³ΠΎ
34
+
35
+ - **0.2.7 β€” свСТий контСкст ΠΈ спокойноС сТатиС.** МСню Ρ‡ΠΈΡ‚Π°Π΅Ρ‚ projection view (`projectedTokens`), поэтому ΠΏΡ€ΠΎΡ†Π΅Π½Ρ‚ Π²Π΅Ρ€Π½Ρ‹ΠΉ сразу послС сТатия ΠΈ ΠΏΡ€ΠΈ ΠΊΠ°ΠΆΠ΄ΠΎΠΌ `/start`; Π½Π°ΠΆΠ°Ρ‚ΠΈΠ΅ **Β«Π‘ΠΆΠ°Ρ‚ΡŒΒ»** замСняСт ΠΏΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π΅Π½ΠΈΠ΅ сообщСниСм Β«ΠžΠΆΠΈΠ΄Π°ΠΉΡ‚Π΅Β» ΠΈ ΡƒΠ±ΠΈΡ€Π°Π΅Ρ‚ ΠΊΠ½ΠΎΠΏΠΊΠΈ.
36
+ - **0.2.6 β€” ΠΌΠ°Ρ€ΡˆΡ€ΡƒΡ‚ΠΈΠ·Π°Ρ†ΠΈΡ.** Вопросы ΠΈ подтвСрТдСния ΠΏΡ€ΠΈΠ½Π°Π΄Π»Π΅ΠΆΠ°Ρ‚ сСссии, которая сСйчас ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚Π° Π² Telegram. ΠžΡΡ‚Π°Π»ΡŒΠ½Ρ‹Π΅ сСссии ΠΎΡΡ‚Π°ΡŽΡ‚ΡΡ Π² Web, Π° Ρ‡Π΅Ρ€Π΅Π· 15 сСкунд Π±ΠΎΡ‚ присылаСт тСкст с Π½Π°Π·Π²Π°Π½ΠΈΠ΅ΠΌ пространства ΠΈ сСссии.
37
+ - **0.2.5 β€” контСкст ΠΈ сСссии.** ΠŸΡ€ΠΎΡ†Π΅Π½Ρ‚ контСкста совпадаСт с Web послС сТатия (`projectedTokens`), пустыС Ρ‡Π΅Ρ€Π½ΠΎΠ²ΠΈΠΊΠΈ сСссий скрыты ΠΈ ΠΏΠ΅Ρ€Π΅ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ΡΡ, тСкущая ΠΏΠΎΠΌΠ΅Ρ‡Π΅Π½Π° `βœ…`.
38
+ - **Π―Π·Ρ‹ΠΊΠΈ.** Π’Π΅ΡΡŒ Π±ΠΎΡ‚ слСдуСт языку интСрфСйса Telegram: `ru*` β†’ русский, любой Π΄Ρ€ΡƒΠ³ΠΎΠΉ β†’ английский. Π›ΠΎΠΊΠ°Π»ΡŒ привязки обновляСтся Π½Π° ΠΊΠ°ΠΆΠ΄ΠΎΠΌ сообщСнии, поэтому смСна языка сразу примСняСтся ΠΊ progress, ΠΎΡ‚Π²Π΅Ρ‚Π°ΠΌ, вопросам ΠΈ подтвСрТдСниям.
23
39
 
24
40
  ## ВрСбования
25
41
 
@@ -29,6 +45,13 @@ Telegram-мост для **DeepSeek Harness**. Плагин устанавлив
29
45
  - Числовой Telegram ID, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ ΠΈΠ· [@userinfobot](https://t.me/userinfobot).
30
46
  - Π—Π°ΠΏΡƒΡ‰Π΅Π½Π½Ρ‹ΠΉ Host. Один Ρ‚ΠΎΠΊΠ΅Π½ ΠΌΠΎΠΆΠ΅Ρ‚ ΠΎΠΏΡ€Π°ΡˆΠΈΠ²Π°Ρ‚ΡŒ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΎΠ΄ΠΈΠ½ Host-процСсс (ΠΈΠ½Π°Ρ‡Π΅ Telegram Π²Π΅Ρ€Π½Ρ‘Ρ‚ `409 Conflict`).
31
47
 
48
+ ## Π‘Ρ‚Π΅ΠΊ
49
+
50
+ - DeepSeek Harness, ΠΏΡ€ΠΎΡ„ΠΈΠ»ΡŒ `web`, установка внСшним Cordis-Π±Π°Π½Π΄Π»ΠΎΠΌ (`cordis.patch.yml`).
51
+ - TypeScript, Node.js `>= 24.9`, grammY для long polling.
52
+ - React-страница настроСк Ρ‡Π΅Ρ€Π΅Π· client slots DSH.
53
+ - Π‘Π΅Π· runtime-ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΎΠ² `@deepseek-ai/dsh-*`: сСрвисы Host описаны Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΌΠΈ Ρ‚ΠΈΠΏΠ°ΠΌΠΈ.
54
+
32
55
  ## Установка
33
56
 
34
57
  ΠŸΠ°ΠΊΠ΅Ρ‚ ΠΎΠΏΡƒΠ±Π»ΠΈΠΊΠΎΠ²Π°Π½ Π² npm ΠΊΠ°ΠΊ **`@shliamb/dsh-telegram-bot`**. ΠšΠΎΡ€ΠΎΡ‚ΠΊΠΎΠ΅ имя `dsh-telegram-bot` ΡƒΠΆΠ΅ занято Π΄Ρ€ΡƒΠ³ΠΈΠΌ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ΠΎΠΌ, поэтому ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ имя со scope.
@@ -59,13 +82,13 @@ pnpm dsh web
59
82
  Π’ Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΈ Ρ‚Π°ΠΊΠΆΠ΅ Π»Π΅ΠΆΠΈΡ‚ Π³ΠΎΡ‚ΠΎΠ²Ρ‹ΠΉ ΠΊ установкС Π°Ρ€Ρ…ΠΈΠ²:
60
83
 
61
84
  ```text
62
- dist/shliamb-dsh-telegram-bot-0.2.5.tgz
85
+ dist/shliamb-dsh-telegram-bot-0.2.7.tgz
63
86
  ```
64
87
 
65
88
  Если ΠΊΠΎΠΌΠ°Π½Π΄Π° `dsh` доступна Π² `PATH`, Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈΡ‚Π΅ ΠΈΠ· корня рСпозитория:
66
89
 
67
90
  ```bash
68
- dsh plugin --profile web add ./dist/shliamb-dsh-telegram-bot-0.2.5.tgz
91
+ dsh plugin --profile web add ./dist/shliamb-dsh-telegram-bot-0.2.7.tgz
69
92
  dsh web
70
93
  ```
71
94
 
@@ -73,7 +96,7 @@ dsh web
73
96
 
74
97
  ```bash
75
98
  cd /path/to/deepseek-harness
76
- pnpm dsh plugin --profile web add /path/to/HarnessBot/dist/shliamb-dsh-telegram-bot-0.2.5.tgz
99
+ pnpm dsh plugin --profile web add /path/to/HarnessBot/dist/shliamb-dsh-telegram-bot-0.2.7.tgz
77
100
  pnpm dsh web
78
101
  ```
79
102
 
@@ -160,7 +183,7 @@ ID Π°Π΄ΠΌΠΈΠ½Π° хранится Π² ΠΊΠΎΠ½Ρ„ΠΈΠ³Π΅ ΠΏΠ»Π°Π³ΠΈΠ½Π°. Если `all
160
183
 
161
184
  ### ΠšΠΎΠΌΠ°Π½Π΄Ρ‹
162
185
 
163
- Π’ мСню ΠΊΠΎΠΌΠ°Π½Π΄ Telegram Π²ΠΈΠ΄Π½Π° Ρ‚ΠΎΠ»ΡŒΠΊΠΎ `/start`. ΠžΡΡ‚Π°Π»ΡŒΠ½Ρ‹Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ скрыты, Π½ΠΎ Ρ€Π°Π±ΠΎΡ‚Π°ΡŽΡ‚ ΠΏΡ€ΠΈ Π²Π²ΠΎΠ΄Π΅ Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ.
186
+ Π’ мСню ΠΊΠΎΠΌΠ°Π½Π΄ Telegram Π²ΠΈΠ΄Π½Π° Ρ‚ΠΎΠ»ΡŒΠΊΠΎ `/start`. `/admin` Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ доступСн Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² Ρ‡Π°Ρ‚Π΅ Π°Π΄ΠΌΠΈΠ½Π°; ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ скрыты, Π½ΠΎ Ρ€Π°Π±ΠΎΡ‚Π°ΡŽΡ‚ ΠΏΡ€ΠΈ Π²Π²ΠΎΠ΄Π΅ Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ.
164
187
 
165
188
  | Команда | ОписаниС |
166
189
  | --- | --- |
@@ -174,6 +197,10 @@ ID Π°Π΄ΠΌΠΈΠ½Π° хранится Π² ΠΊΠΎΠ½Ρ„ΠΈΠ³Π΅ ΠΏΠ»Π°Π³ΠΈΠ½Π°. Если `all
174
197
 
175
198
  Π€ΠΈΠ½Π°Π»ΡŒΠ½Ρ‹Π΅ ΠΎΡ‚Π²Π΅Ρ‚Ρ‹ приходят ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹ΠΌΠΈ rich-сообщСниями. Π”Π»ΠΈΠ½Π½Ρ‹ΠΉ тСкст дСлится Π½Π° части ΠΏΠΎ Π»ΠΈΠΌΠΈΡ‚Ρƒ Telegram. Если rich-Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Π½Π΅ ΡƒΠ΄Π°Π»ΠΎΡΡŒ, ΠΏΠ»Π°Π³ΠΈΠ½ повторяСт ΠΏΠΎΠΏΡ‹Ρ‚ΠΊΡƒ с rich HTML, Π·Π°Ρ‚Π΅ΠΌ с ΠΎΠ±Ρ‹Ρ‡Π½Ρ‹ΠΌ тСкстом, поэтому ΠΎΡ‚Π²Π΅Ρ‚ Π½Π΅ тСряСтся.
176
199
 
200
+ ### Π―Π·Ρ‹ΠΊΠΈ
201
+
202
+ Π‘ΠΎΡ‚ слСдуСт языку интСрфСйса Telegram: ΠΊΠΎΠ΄ `ru*` Π²ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ русский, любой Π΄Ρ€ΡƒΠ³ΠΎΠΉ β€” английский. Π›ΠΎΠΊΠ°Π»ΡŒ привязки обновляСтся Π½Π° ΠΊΠ°ΠΆΠ΄ΠΎΠΌ сообщСнии, поэтому progress, Ρ„ΠΈΠ½Π°Π»ΡŒΠ½Ρ‹Π΅ ΠΎΡ‚Π²Π΅Ρ‚Ρ‹, вопросы ΠΈ подтвСрТдСния сразу ΠΏΠ΅Ρ€Π΅ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‚ΡΡ послС смСны языка Π² Telegram. Описания ΠΊΠΎΠΌΠ°Π½Π΄ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ Ρ‚ΠΎ ΠΆΠ΅ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ. Π‘Ρ‚Ρ€Π°Π½ΠΈΡ†Π° настроСк Π² Web слСдуСт языку Web-интСрфСйса. ВСкст, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΏΠΈΡˆΠ΅Ρ‚ Π°Π³Π΅Π½Ρ‚, остаётся Π½Π° языкС Π°Π³Π΅Π½Ρ‚Π°.
203
+
177
204
  ### ΠŸΡ€ΠΎΡΡ‚Ρ€Π°Π½ΡΡ‚Π²Π° ΠΈ сСссии
178
205
 
179
206
  ПослС Π²Ρ‹Π±ΠΎΡ€Π° пространства:
@@ -202,13 +229,15 @@ ID Π°Π΄ΠΌΠΈΠ½Π° хранится Π² ΠΊΠΎΠ½Ρ„ΠΈΠ³Π΅ ΠΏΠ»Π°Π³ΠΈΠ½Π°. Если `all
202
229
 
203
230
  ### ΠŸΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π΅Π½ΠΈΡ ΠΈ вопросы
204
231
 
205
- Когда Π°Π³Π΅Π½Ρ‚ просит ΠΏΠΎΠ΄Ρ‚Π²Π΅Ρ€Π΄ΠΈΡ‚ΡŒ инструмСнт, Π±ΠΎΡ‚ присылаСт inline-ΠΊΠ½ΠΎΠΏΠΊΠΈ **Β«Π Π°Π·Ρ€Π΅ΡˆΠΈΡ‚ΡŒΒ»** / **Β«Π—Π°ΠΏΡ€Π΅Ρ‚ΠΈΡ‚ΡŒΒ»**. Когда Π°Π³Π΅Π½Ρ‚ Π·Π°Π΄Π°Ρ‘Ρ‚ вопрос с Π³ΠΎΡ‚ΠΎΠ²Ρ‹ΠΌΠΈ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚Π°ΠΌΠΈ, ΠΎΡ‚Π²Π΅Ρ‚Ρ‹ Ρ‚ΠΎΠΆΠ΅ приходят ΠΊΠ½ΠΎΠΏΠΊΠ°ΠΌΠΈ. Π’Π°ΠΉΠΌΠ°ΡƒΡ‚ запроса β€” 10 ΠΌΠΈΠ½ΡƒΡ‚.
232
+ Когда Π°Π³Π΅Π½Ρ‚ просит ΠΏΠΎΠ΄Ρ‚Π²Π΅Ρ€Π΄ΠΈΡ‚ΡŒ инструмСнт, Π±ΠΎΡ‚ присылаСт inline-ΠΊΠ½ΠΎΠΏΠΊΠΈ **Β«Π Π°Π·Ρ€Π΅ΡˆΠΈΡ‚ΡŒΒ»** / **Β«Π—Π°ΠΏΡ€Π΅Ρ‚ΠΈΡ‚ΡŒΒ»**. Когда Π°Π³Π΅Π½Ρ‚ Π·Π°Π΄Π°Ρ‘Ρ‚ вопрос с Π³ΠΎΡ‚ΠΎΠ²Ρ‹ΠΌΠΈ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚Π°ΠΌΠΈ, ΠΎΡ‚Π²Π΅Ρ‚Ρ‹ Ρ‚ΠΎΠΆΠ΅ приходят ΠΊΠ½ΠΎΠΏΠΊΠ°ΠΌΠΈ. Π’ Telegram ΠΊΠ°Ρ€Ρ‚ΠΎΡ‡ΠΊΠ° закрываСтся Ρ‡Π΅Ρ€Π΅Π· 10 ΠΌΠΈΠ½ΡƒΡ‚; вопрос Π±Π΅Π· ΠΎΡ‚Π²Π΅Ρ‚Π° возвращаСтся ΠΊΠ°ΠΊ ΠΏΡ€ΠΎΠΏΡƒΡ‰Π΅Π½Π½Ρ‹ΠΉ.
206
233
 
207
234
  ΠŸΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π΅Π½ΠΈΡ ΠΈ вопросы ΠΎΡ‚Π²Π΅Ρ‡Π°ΡŽΡ‚ΡΡ для привязанной сСссии. Π‘ΠΎΡ‚ Π·Π°Π΄Π°Ρ‘Ρ‚ вопросы ΠΏΠΎ ΠΎΠ΄Π½ΠΎΠΌΡƒ. Π’ single-select Π½Π°ΠΆΠ°Ρ‚ΠΈΠ΅ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚Π° сразу отправляСт ΠΎΡ‚Π²Π΅Ρ‚; Π² multi-select ΠΎΡ‚ΠΌΠ΅Ρ‚ΡŒ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚Ρ‹ ΠΈ Π½Π°ΠΆΠΌΠΈ **Β«Π“ΠΎΡ‚ΠΎΠ²ΠΎΒ»**. ВСкст, ΠΎΡ‚ΠΏΡ€Π°Π²Π»Π΅Π½Π½Ρ‹ΠΉ ΠΏΡ€ΠΈ ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚ΠΎΠΌ вопросС, ΡƒΡ…ΠΎΠ΄ΠΈΡ‚ ΠΊΠ°ΠΊ «свой ΠΎΡ‚Π²Π΅Ρ‚Β» (Π² multi-select дополняСт Π²Ρ‹Π±Ρ€Π°Π½Π½Ρ‹Π΅ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚Ρ‹), Π° **Β«ΠŸΡ€ΠΎΠΏΡƒΡΡ‚ΠΈΡ‚ΡŒΒ»** оставляСт вопрос Π±Π΅Π· ΠΎΡ‚Π²Π΅Ρ‚Π°. Пока вопрос ΠΈΠ»ΠΈ approval ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚, ΠΎΠ±Ρ‹Ρ‡Π½Ρ‹ΠΉ тСкст Π½Π΅ ставится Π² ΠΎΡ‡Π΅Ρ€Π΅Π΄ΡŒ ΠΊΠ°ΠΊ новая Π·Π°Π΄Π°Ρ‡Π°.
208
235
 
236
+ ΠšΡƒΠ΄Π° ΠΏΡ€ΠΈΠ΄Ρ‘Ρ‚ запрос, Ρ€Π΅ΡˆΠ°Π΅Ρ‚ привязка Telegram. Если запрос относится ΠΊ сСссии, которая сСйчас ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚Π° Π² Π±ΠΎΡ‚Π΅, Telegram Π·Π°Π±ΠΈΡ€Π°Π΅Ρ‚ Π΅Π³ΠΎ ΠΈ ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ ΠΊΠ½ΠΎΠΏΠΊΠΈ. Π›ΡŽΠ±Π°Ρ другая сСссия оставляСт запрос Π² Web; Ссли Web Π½Π΅ ΠΎΡ‚Π²Π΅Ρ‚ΠΈΠ» Π·Π° 15 сСкунд, Π±ΠΎΡ‚ присылаСт ΠΎΠ±Ρ‹Ρ‡Π½ΠΎΠ΅ тСкстовоС ΡƒΠ²Π΅Π΄ΠΎΠΌΠ»Π΅Π½ΠΈΠ΅ с Π½Π°Π·Π²Π°Π½ΠΈΠ΅ΠΌ пространства ΠΈ сСссии. Π’Π°ΠΊ Web остаётся основным экраном, Π° ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½ΠΎ открытая сСссия Π² Telegram Π·Π°Π±ΠΈΡ€Π°Π΅Ρ‚ свои вопросы ΠΈ подтвСрТдСния.
237
+
209
238
  ### Π‘ΠΆΠ°Ρ‚ΠΈΠ΅, Π·Π²ΡƒΠΊ ΠΈ остановка
210
239
 
211
- - **Β«Π‘ΠΆΠ°Ρ‚ΡŒΒ»** ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΏΡ€ΠΎΡ†Π΅Π½Ρ‚ контСкста ΠΈ просит ΠΏΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π΅Π½ΠΈΠ΅. Плагин Π²Ρ‹Π·Ρ‹Π²Π°Π΅Ρ‚ preset-ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ `/compact` Ρ‡Π΅Ρ€Π΅Π· сСрвис `commands`, Π·Π°Ρ‚Π΅ΠΌ ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ Π»ΠΎΠΊΠ°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ ΠΈ Π½ΠΎΠ²Ρ‹ΠΉ ΠΏΡ€ΠΎΡ†Π΅Π½Ρ‚. Если Π°Π³Π΅Π½Ρ‚ занят, сТатиС отклоняСтся.
240
+ - **Β«Π‘ΠΆΠ°Ρ‚ΡŒΒ»** ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΏΡ€ΠΎΡ†Π΅Π½Ρ‚ контСкста ΠΈ просит ΠΏΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π΅Π½ΠΈΠ΅. ПослС наТатия **Β«Π‘ΠΆΠ°Ρ‚ΡŒΒ»** ΠΊΠ°Ρ€Ρ‚ΠΎΡ‡ΠΊΠ° замСняСтся сообщСниСм Β«ΠžΠΆΠΈΠ΄Π°ΠΉΡ‚Π΅Β», Π° ΠΊΠ½ΠΎΠΏΠΊΠΈ ΠΈΡΡ‡Π΅Π·Π°ΡŽΡ‚, поэтому ΠΏΠΎΠ²Ρ‚ΠΎΡ€Π½Ρ‹Π΅ наТатия Π½ΠΈΡ‡Π΅Π³ΠΎ Π½Π΅ Π΄Π΅Π»Π°ΡŽΡ‚. Плагин Π²Ρ‹Π·Ρ‹Π²Π°Π΅Ρ‚ preset-ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ `/compact` Ρ‡Π΅Ρ€Π΅Π· сСрвис `commands`, Π·Π°Ρ‚Π΅ΠΌ ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅Ρ‚ Π»ΠΎΠΊΠ°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ ΠΈ Π½ΠΎΠ²Ρ‹ΠΉ ΠΏΡ€ΠΎΡ†Π΅Π½Ρ‚. Если Π°Π³Π΅Π½Ρ‚ занят, сТатиС отклоняСтся.
212
241
  - **Β«Π—Π²ΡƒΠΊΒ»** хранится для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Ρ‡Π°Ρ‚Π°. Когда ΠΎΠ½ Π²Ρ‹ΠΊΠ»ΡŽΡ‡Π΅Π½, ΠΎΡ‚Π²Π΅Ρ‚Ρ‹, ΠΏΡ€Π°Π²ΠΊΠΈ progress ΠΈ привСтствиС ΠΏΡ€ΠΈ стартС ΠΈΠ΄ΡƒΡ‚ с `disable_notification`.
213
242
  - **Β«Π‘Ρ‚ΠΎΠΏΒ»** просит ΠΏΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π΅Π½ΠΈΠ΅, Π·Π°Ρ‚Π΅ΠΌ отмСняСт Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ Ρ…ΠΎΠ΄ Ρ‡Π΅Ρ€Π΅Π· `agent.cancel({ kind: 'user' })`.
214
243
 
@@ -283,6 +312,7 @@ pnpm pack --pack-destination dist
283
312
  src/index.ts Host-ΠΏΠ»Π°Π³ΠΈΠ½: ΠΊΠΎΠ½Ρ„ΠΈΠ³, runtime Π±ΠΎΡ‚Π°, мСню, ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹
284
313
  src/client/index.tsx Web-страница настроСк (Ρ‚ΠΎΠΊΠ΅Π½ + ID Π°Π΄ΠΌΠΈΠ½Π°)
285
314
  src/client/locales.ts РусскиС ΠΈ английскиС строки интСрфСйса
315
+ images/ Π‘ΠΊΡ€ΠΈΠ½ΡˆΠΎΡ‚Ρ‹ для README
286
316
  src/state/index.ts ΠŸΡ€ΠΈΠ²ΡΠ·ΠΊΠΈ Ρ‡Π°Ρ‚ΠΎΠ² Π² storageDomain
287
317
  src/logging/index.ts JSONL-Π»ΠΎΠ³ с Ρ€ΠΎΡ‚Π°Ρ†ΠΈΠ΅ΠΉ
288
318
  src/*/SPEC.md ΠšΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚Ρ‹ ΠΌΠΎΠ΄ΡƒΠ»Π΅ΠΉ ΠΈ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚Ρ‹ Π΄Π°Π½Π½Ρ‹Ρ…
@@ -299,13 +329,14 @@ dist/ Π“ΠΎΡ‚ΠΎΠ²Ρ‹ΠΉ установочный Π°Ρ€Ρ…ΠΈΠ²
299
329
  - Π’ Web-настройках Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ρ‚ΠΎΠΊΠ΅Π½ ΠΈ ID Π°Π΄ΠΌΠΈΠ½Π°; `lowBalanceUsd`, `rich` ΠΈ `apiRoot` Π·Π°Π΄Π°ΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· `cordis.patch.yml`.
300
330
  - НСт голосовых ΠΈ Ρ„Π°ΠΉΠ»ΠΎΠ²: Telegram сам транскрибируСт голос.
301
331
  - НСт настройки прокси.
302
- - ΠŸΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π΅Π½ΠΈΡ ΠΈ вопросы привязаны ΠΊ Π²Ρ‹Π±Ρ€Π°Π½Π½ΠΎΠΉ сСссии. НСпривязанный ΠΈΠ»ΠΈ Π½Π΅ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅ΠΌΡ‹ΠΉ вопрос отвСчаСтся Π² Web; Π² Telegram Ρ€Π°Π±ΠΎΡ‚Π°ΡŽΡ‚ single-select, multi-select, свой тСкст ΠΈ пропуск.
332
+ - Вопросы ΠΈ подтвСрТдСния Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΉ Telegram-сСссии ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°ΡŽΡ‚ΡΡ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π² Telegram; ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Π΅ сСссии ΠΎΡΡ‚Π°ΡŽΡ‚ΡΡ Π² Web с ΠΎΡ‚Π»ΠΎΠΆΠ΅Π½Π½Ρ‹ΠΌ тСкстовым ΡƒΠ²Π΅Π΄ΠΎΠΌΠ»Π΅Π½ΠΈΠ΅ΠΌ. Telegram ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ single-select, multi-select, свой тСкст ΠΈ пропуск.
303
333
  - ΠžΡ‚ΡΠ»Π΅ΠΆΠΈΠ²Π°Π½ΠΈΠ΅ progress ΠΆΠΈΠ²Ρ‘Ρ‚ Π² памяти, поэтому пСрСзапуск Host посрСди Ρ…ΠΎΠ΄Π° ΠΌΠΎΠΆΠ΅Ρ‚ ΠΎΡΡ‚Π°Π²ΠΈΡ‚ΡŒ ΡƒΡΡ‚Π°Ρ€Π΅Π²ΡˆΠ΅Π΅ progress-сообщСниС.
304
334
 
305
335
  ## Roadmap
306
336
 
307
- - Phase 2.2: `/history`, ΠΌΠ°Ρ€ΡˆΡ€ΡƒΡ‚ΠΈΠ·Π°Ρ†ΠΈΡ ΠΎΡ‚Π²Π΅Ρ‚ΠΎΠ², увСдомлСния ΠΎ Π·Π°Π²Π΅Ρ€ΡˆΠ΅Π½ΠΈΠΈ Π² Π΄Ρ€ΡƒΠ³ΠΈΡ… сСссиях.
308
- - Phase 3.2: npm-ΠΏΠ°ΠΊΠ΅Ρ‚ ΠΈ публикация Π² ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π΅ ΠΏΠ»Π°Π³ΠΈΠ½ΠΎΠ².
337
+ - Π“ΠΎΡ‚ΠΎΠ²ΠΎ Π² 0.2.5: ΠΏΡ€ΠΎΡ†Π΅Π½Ρ‚ контСкста ΠΏΠΎ `projectedTokens`, ΠΏΠ΅Ρ€Π΅ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Π½ΠΈΠ΅ пустых сСссий, `βœ…` Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ сСссии, английский fallback ΠΊΠΎΠΌΠ°Π½Π΄, синхронизация Π»ΠΎΠΊΠ°Π»ΠΈ.
338
+ - Π“ΠΎΡ‚ΠΎΠ²ΠΎ Π² 0.2.6: ΠΌΠ°Ρ€ΡˆΡ€ΡƒΡ‚ΠΈΠ·Π°Ρ†ΠΈΡ вопросов ΠΈ ΠΏΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π΅Π½ΠΈΠΉ ΠΏΠΎ Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΉ сСссии, тСкстовоС ΡƒΠ²Π΅Π΄ΠΎΠΌΠ»Π΅Π½ΠΈΠ΅ Web Ρ‡Π΅Ρ€Π΅Π· 15 сСкунд, диагностика.
339
+ - Π”Π°Π»ΡŒΡˆΠ΅: ΡƒΠ±Ρ€Π°Ρ‚ΡŒ лишнюю очистку ΠΊΠ»Π°Π²ΠΈΠ°Ρ‚ΡƒΡ€Ρ‹ вопроса; `/history`; ΠΌΠ°Ρ€ΡˆΡ€ΡƒΡ‚ΠΈΠ·Π°Ρ†ΠΈΡ ΠΎΡ‚Π²Π΅Ρ‚ΠΎΠ²; увСдомлСния ΠΎ Π·Π°Π²Π΅Ρ€ΡˆΠ΅Π½ΠΈΠΈ Π² Π΄Ρ€ΡƒΠ³ΠΈΡ… сСссиях; ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ ΠΏΠ»Π°Π³ΠΈΠ½ΠΎΠ².
309
340
 
310
341
  ## ЛицСнзия
311
342
 
package/lib/index.d.ts CHANGED
@@ -70,6 +70,10 @@ interface DshSessionEvent {
70
70
  readonly type: string;
71
71
  readonly data: Record<string, unknown>;
72
72
  }
73
+ interface ListenerOptions {
74
+ /** Add this listener ahead of listeners registered earlier for the event. */
75
+ prepend?: boolean;
76
+ }
73
77
  interface HarnessContext {
74
78
  readonly logger: Logger;
75
79
  get(name: string): unknown;
@@ -77,8 +81,8 @@ interface HarnessContext {
77
81
  on(event: 'session/event', listener: (session: DshSession, event: DshSessionEvent) => void): () => void;
78
82
  on(event: 'credentials/reference-updated', listener: (ref: string) => void): () => void;
79
83
  on(event: 'settings/document-updated', listener: (namespace: string, revision: number) => void): () => void;
80
- on(event: 'approval/request', listener: (request: ApprovalRequest, next: () => Promise<ApprovalOutcome>) => Promise<ApprovalOutcome>): () => void;
81
- on(event: 'user-questions/request', listener: (request: AskQuestionRequest, next: () => Promise<AskQuestionAnswer>) => Promise<AskQuestionAnswer>): () => void;
84
+ on(event: 'approval/request', listener: (request: ApprovalRequest, next: () => Promise<ApprovalOutcome>) => Promise<ApprovalOutcome>, options?: ListenerOptions): () => void;
85
+ on(event: 'user-questions/request', listener: (request: AskQuestionRequest, next: () => Promise<AskQuestionAnswer>) => Promise<AskQuestionAnswer>, options?: ListenerOptions): () => void;
82
86
  }
83
87
  /**
84
88
  * Loader/settings schema. Only `adminUserId` is volatile: it is the one field
package/lib/index.js CHANGED
@@ -59,6 +59,9 @@ const STRINGS = {
59
59
  selectSession: 'Π’Ρ‹Π±Π΅Ρ€ΠΈ сСссию:',
60
60
  noSessions: 'Π’ этом пространствС ΠΏΠΎΠΊΠ° Π½Π΅Ρ‚ сСссий. НаТми «Новая сСссия» ΠΈΠ»ΠΈ просто напиши тСкст.',
61
61
  sessionLegend: 'βœ… β€” тСкущая, 🟒 β€” Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚, βšͺ β€” ΠΎΠΆΠΈΠ΄Π°Π΅Ρ‚',
62
+ webWaitingQuestion: '⏳ Π’ Web оТидаСтся ΠΎΡ‚Π²Π΅Ρ‚',
63
+ webWaitingApproval: '⏳ Π’ Web оТидаСтся ΠΏΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π΅Π½ΠΈΠ΅',
64
+ webWaitingHint: 'ΠžΡ‚ΠΊΡ€ΠΎΠΉ Web, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠΈΡ‚ΡŒ.',
62
65
  sessions: 'πŸ”„ БСссии',
63
66
  backToWorkspaces: '◀️ ΠŸΡ€ΠΎΡΡ‚Ρ€Π°Π½ΡΡ‚Π²Π°',
64
67
  newSession: 'βž• Новая сСссия',
@@ -81,6 +84,8 @@ const STRINGS = {
81
84
  compactNoHistory: 'НСчСго ΡΠΆΠΈΠΌΠ°Ρ‚ΡŒ.',
82
85
  compactConfirm: 'Бтарая история Π±ΡƒΠ΄Π΅Ρ‚ Π·Π°ΠΌΠ΅Π½Π΅Π½Π° ΠΊΡ€Π°Ρ‚ΠΊΠΈΠΌ Ρ€Π΅Π·ΡŽΠΌΠ΅.',
83
86
  compactDone: 'Π˜ΡΡ‚ΠΎΡ€ΠΈΡ сТата.',
87
+ compactWorking: '⏳ БТимаю ΠΈΡΡ‚ΠΎΡ€ΠΈΡŽβ€¦\nΠŸΠΎΠ΄ΠΎΠΆΠ΄ΠΈΡ‚Π΅, поТалуйста.',
88
+ compactResultTitle: 'Π‘ΠΆΠ°Ρ‚ΠΈΠ΅ истории',
84
89
  stop: '⏹ Π‘Ρ‚ΠΎΠΏ',
85
90
  stopDone: 'ΠžΡΡ‚Π°Π½ΠΎΠ²Π»Π΅Π½ΠΎ.',
86
91
  stopIdle: 'НСчСго ΠΎΡΡ‚Π°Π½Π°Π²Π»ΠΈΠ²Π°Ρ‚ΡŒ.',
@@ -173,6 +178,9 @@ const STRINGS = {
173
178
  selectSession: 'Choose a session:',
174
179
  noSessions: 'No sessions in this workspace yet. Tap New session or just send text.',
175
180
  sessionLegend: 'βœ… current, 🟒 running, βšͺ idle',
181
+ webWaitingQuestion: '⏳ Web is waiting for an answer',
182
+ webWaitingApproval: '⏳ Web is waiting for approval',
183
+ webWaitingHint: 'Open Web to continue.',
176
184
  sessions: 'πŸ”„ Sessions',
177
185
  backToWorkspaces: '◀️ Workspaces',
178
186
  newSession: 'βž• New session',
@@ -195,6 +203,8 @@ const STRINGS = {
195
203
  compactNoHistory: 'No compactable history.',
196
204
  compactConfirm: 'Older history will be replaced by a short summary.',
197
205
  compactDone: 'History compacted.',
206
+ compactWorking: '⏳ Compacting history…\nPlease wait.',
207
+ compactResultTitle: 'History compaction',
198
208
  stop: '⏹ Stop',
199
209
  stopDone: 'Stopped.',
200
210
  stopIdle: 'Nothing to stop.',
@@ -493,7 +503,7 @@ async function getBalance(runtime, locale, force = false) {
493
503
  }
494
504
  try {
495
505
  const result = await runtime.account.getBalance({
496
- version: '@shliamb/dsh-telegram-bot/0.2.4',
506
+ version: '@shliamb/dsh-telegram-bot/0.2.7',
497
507
  locale,
498
508
  timezoneOffsetSeconds: -new Date().getTimezoneOffset() * 60,
499
509
  });
@@ -525,28 +535,45 @@ async function getBalance(runtime, locale, force = false) {
525
535
  return cache.value === undefined ? {} : { display: cache.value, amount: cache.amount, currency: cache.currency };
526
536
  }
527
537
  }
528
- async function getSessionContextLabel(runtime, sessionId) {
529
- if (runtime.tokenMeter === undefined)
530
- return undefined;
531
- const cached = runtime.contextCache.get(sessionId);
532
- if (cached !== undefined && Date.now() - cached.at < 15_000) {
533
- return cached.percent === undefined ? undefined : `${cached.percent}%`;
538
+ /**
539
+ * Read the client-facing context pressure. The projection view is the only
540
+ * place that carries `projectedTokens`, which already accounts for compaction;
541
+ * the token-meter facade returns the provider sample alone and therefore
542
+ * looks stale until the next request.
543
+ */
544
+ function readContextPressure(runtime, session) {
545
+ try {
546
+ const snapshot = runtime.sessionProjections?.snapshot(session, ['contextPressure']);
547
+ const value = asRecord(snapshot?.values['contextPressure']);
548
+ if (value !== undefined) {
549
+ return {
550
+ ...(typeof value['pressureTokens'] === 'number' ? { pressureTokens: value['pressureTokens'] } : {}),
551
+ ...(typeof value['projectedTokens'] === 'number' ? { projectedTokens: value['projectedTokens'] } : {}),
552
+ ...(typeof value['contextWindow'] === 'number' ? { contextWindow: value['contextWindow'] } : {}),
553
+ };
554
+ }
534
555
  }
556
+ catch (error) {
557
+ runtime.logger.warn('context-projection-failed', messageOf(error));
558
+ }
559
+ return runtime.tokenMeter?.contextPressure(session);
560
+ }
561
+ async function getSessionContextLabel(runtime, sessionId) {
535
562
  try {
536
563
  const result = await runtime.sessions.resolveAgent(sessionId);
537
564
  if (result.agent === undefined)
538
565
  return undefined;
539
- const pressure = runtime.tokenMeter.contextPressure(result.agent.session);
540
- // `pressureTokens` is the last request's prompt size and cannot see a
541
- // compaction. `projectedTokens` applies the surface delta since that
542
- // sample, matching the Web context meter.
566
+ const pressure = readContextPressure(runtime, result.agent.session);
567
+ if (pressure === undefined)
568
+ return undefined;
569
+ // Match the Web meter: `projectedTokens` is what the next request would
570
+ // carry, so compaction is visible immediately.
543
571
  const used = pressure.projectedTokens ?? pressure.pressureTokens;
544
572
  const percent = used !== undefined
545
573
  && pressure.contextWindow !== undefined
546
574
  && pressure.contextWindow > 0
547
- ? Math.round(100 * used / pressure.contextWindow)
575
+ ? Math.min(100, Math.round(100 * used / pressure.contextWindow))
548
576
  : undefined;
549
- runtime.contextCache.set(sessionId, { percent, at: Date.now() });
550
577
  return percent === undefined ? undefined : `${percent}%`;
551
578
  }
552
579
  catch (error) {
@@ -559,10 +586,10 @@ async function getContextLabel(runtime, binding) {
559
586
  return undefined;
560
587
  return getSessionContextLabel(runtime, binding.activeSessionId);
561
588
  }
562
- async function getMenuState(runtime, chatId, locale) {
589
+ async function getMenuState(runtime, chatId, locale, forceBalance = false) {
563
590
  const binding = runtime.store.get(chatId);
564
591
  const [balance, context] = await Promise.all([
565
- getBalance(runtime, locale),
592
+ getBalance(runtime, locale, forceBalance),
566
593
  getContextLabel(runtime, binding),
567
594
  ]);
568
595
  return {
@@ -649,7 +676,6 @@ async function runCompact(runtime, chatId, locale, sessionId) {
649
676
  // The preset that owns the session registers /compact together with its
650
677
  // isolated compaction backend; calling the command uses the same path as Web.
651
678
  const execution = await commands.execute(result.agent, '/compact', [], AbortSignal.timeout(300_000));
652
- runtime.contextCache.delete(sessionId);
653
679
  if (execution === undefined)
654
680
  return t(locale, 'compactUnavailable');
655
681
  runtime.logger.info('compact-result', 'manual compaction finished', {
@@ -673,7 +699,7 @@ async function runCompact(runtime, chatId, locale, sessionId) {
673
699
  async function statusText(runtime, chatId, locale) {
674
700
  const binding = runtime.store.get(chatId);
675
701
  const workspace = binding?.activeWorkspaceId === undefined ? undefined : runtime.workspaces.get(binding.activeWorkspaceId);
676
- const balance = await getBalance(runtime, locale);
702
+ const balance = await getBalance(runtime, locale, true);
677
703
  const context = await getContextLabel(runtime, binding);
678
704
  let agentStatus = 'β€”';
679
705
  if (binding?.activeSessionId !== undefined) {
@@ -866,29 +892,49 @@ function buildQuestionResultView(question, answer, outcome, locale) {
866
892
  }
867
893
  return { html: html.join('\n'), text: text.join('\n'), keyboard: new InlineKeyboard() };
868
894
  }
869
- async function clearQuestionKeyboard(runtime, chatId, messageId) {
870
- try {
871
- await runtime.bot.api.editMessageReplyMarkup(chatId, messageId, { reply_markup: new InlineKeyboard() });
872
- }
873
- catch (error) {
874
- runtime.logger.warn('question-keyboard-clear-failed', messageOf(error), { chatId });
875
- }
876
- }
877
895
  async function handleApproval(runtime, request, next) {
878
896
  if (request.signal?.aborted === true)
879
897
  return 'cancelled';
880
- const chatIdRaw = chatForSession(runtime, request.agent.session.id);
881
- if (chatIdRaw === undefined)
882
- return next();
883
- const chatId = Number(chatIdRaw);
884
- if (!Number.isSafeInteger(chatId))
885
- return next();
886
- const binding = runtime.store.get(chatIdRaw);
898
+ const sessionId = request.agent.session.id;
899
+ const target = answerTargetForSession(runtime, sessionId);
900
+ if (target === undefined) {
901
+ runtime.logger.info('approval-delegated', 'session is not bound to a Telegram chat', {
902
+ sessionId,
903
+ toolName: request.toolName,
904
+ reason: 'unbound',
905
+ });
906
+ const answer = next();
907
+ scheduleWebWaitingNotice(runtime, undefined, sessionId, 'approval', answer, request.toolName);
908
+ return answer;
909
+ }
910
+ const { chatId, binding, active } = target;
887
911
  const locale = binding?.locale ?? 'ru';
912
+ if (!active) {
913
+ runtime.logger.info('approval-delegated', 'session is not active in Telegram', {
914
+ chatId,
915
+ sessionId,
916
+ toolName: request.toolName,
917
+ reason: 'not-active',
918
+ });
919
+ const answer = next();
920
+ scheduleWebWaitingNotice(runtime, target, sessionId, 'approval', answer, request.toolName);
921
+ return answer;
922
+ }
923
+ runtime.logger.info('approval-claimed', 'approval claimed for Telegram', {
924
+ chatId,
925
+ sessionId,
926
+ toolName: request.toolName,
927
+ });
888
928
  const token = randomUUID().slice(0, 8);
889
929
  const messageId = await sendRich(runtime, chatId, buildApprovalView(request, token, locale), binding?.sound === false);
890
- if (messageId === undefined)
930
+ if (messageId === undefined) {
931
+ runtime.logger.info('approval-delegated', 'could not send approval to Telegram', {
932
+ chatId,
933
+ sessionId,
934
+ reason: 'send-failed',
935
+ });
891
936
  return next();
937
+ }
892
938
  return await new Promise((resolve) => {
893
939
  let settled = false;
894
940
  let timer;
@@ -985,7 +1031,6 @@ async function askQuestion(runtime, chatId, sessionId, locale, question, questio
985
1031
  const result = buildQuestionResultView(question, answer, outcome, locale);
986
1032
  void (async () => {
987
1033
  await editRich(runtime, chatId, messageId, result);
988
- await clearQuestionKeyboard(runtime, chatId, messageId);
989
1034
  })();
990
1035
  runtime.logger.info('question-closed', 'agent question closed', {
991
1036
  chatId,
@@ -1016,8 +1061,10 @@ async function askQuestion(runtime, chatId, sessionId, locale, question, questio
1016
1061
  return await answerPromise;
1017
1062
  }
1018
1063
  async function handleQuestion(runtime, request, next) {
1019
- if (request.agent === undefined)
1064
+ if (request.agent === undefined) {
1065
+ runtime.logger.info('question-delegated', 'question has no owning agent', { reason: 'no-agent' });
1020
1066
  return next();
1067
+ }
1021
1068
  if (request.questions.length === 0)
1022
1069
  return next();
1023
1070
  const aborted = () => request.signal?.aborted === true;
@@ -1026,15 +1073,36 @@ async function handleQuestion(runtime, request, next) {
1026
1073
  });
1027
1074
  if (aborted())
1028
1075
  return skippedAll();
1029
- const chatIdRaw = chatForSession(runtime, request.agent.session.id);
1030
- if (chatIdRaw === undefined)
1031
- return next();
1032
- const chatId = Number(chatIdRaw);
1033
- if (!Number.isSafeInteger(chatId))
1034
- return next();
1035
- const binding = runtime.store.get(chatIdRaw);
1076
+ const sessionId = request.agent.session.id;
1077
+ const target = answerTargetForSession(runtime, sessionId);
1078
+ if (target === undefined) {
1079
+ runtime.logger.info('question-delegated', 'session is not bound to a Telegram chat', {
1080
+ sessionId,
1081
+ reason: 'unbound',
1082
+ });
1083
+ const answer = next();
1084
+ scheduleWebWaitingNotice(runtime, undefined, sessionId, 'question', answer);
1085
+ return answer;
1086
+ }
1087
+ const { chatId, binding, active } = target;
1036
1088
  const locale = binding?.locale ?? 'ru';
1037
1089
  const silent = binding?.sound === false;
1090
+ if (!active) {
1091
+ runtime.logger.info('question-delegated', 'session is not active in Telegram', {
1092
+ chatId,
1093
+ sessionId,
1094
+ reason: 'not-active',
1095
+ questions: request.questions.length,
1096
+ });
1097
+ const answer = next();
1098
+ scheduleWebWaitingNotice(runtime, target, sessionId, 'question', answer);
1099
+ return answer;
1100
+ }
1101
+ runtime.logger.info('question-claimed', 'question claimed for Telegram', {
1102
+ chatId,
1103
+ sessionId,
1104
+ questions: request.questions.length,
1105
+ });
1038
1106
  // Serialize whole question batches per chat. A second Session can ask while
1039
1107
  // the first batch is between questions; let it wait for the visible batch
1040
1108
  // instead of overtaking or cancelling it.
@@ -1042,7 +1110,7 @@ async function handleQuestion(runtime, request, next) {
1042
1110
  if (previousBatch !== undefined) {
1043
1111
  runtime.logger.info('question-batch-queued', 'waiting for the visible question batch', {
1044
1112
  chatId,
1045
- sessionId: request.agent.session.id,
1113
+ sessionId,
1046
1114
  });
1047
1115
  await previousBatch;
1048
1116
  if (aborted())
@@ -1061,10 +1129,16 @@ async function handleQuestion(runtime, request, next) {
1061
1129
  continue;
1062
1130
  }
1063
1131
  try {
1064
- const item = await askQuestion(runtime, chatId, request.agent.session.id, locale, question, index, request.questions.length, silent, request.signal, deadline);
1132
+ const item = await askQuestion(runtime, chatId, sessionId, locale, question, index, request.questions.length, silent, request.signal, deadline);
1065
1133
  if (item === undefined) {
1066
- if (answers.length === 0)
1134
+ if (answers.length === 0) {
1135
+ runtime.logger.info('question-delegated', 'could not send question to Telegram', {
1136
+ chatId,
1137
+ sessionId,
1138
+ reason: 'send-failed',
1139
+ });
1067
1140
  return next();
1141
+ }
1068
1142
  answers.push({ id: question.id, selected: [] });
1069
1143
  }
1070
1144
  else {
@@ -1074,7 +1148,7 @@ async function handleQuestion(runtime, request, next) {
1074
1148
  catch (error) {
1075
1149
  runtime.logger.error('question-failed', messageOf(error), {
1076
1150
  chatId,
1077
- sessionId: request.agent.session.id,
1151
+ sessionId,
1078
1152
  questionId: question.id,
1079
1153
  });
1080
1154
  answers.push({ id: question.id, selected: [] });
@@ -1221,8 +1295,8 @@ async function sendPlain(runtime, chatId, text, silent = false) {
1221
1295
  runtime.logger.error('send-failed', messageOf(error), { chatId });
1222
1296
  }
1223
1297
  }
1224
- async function sendMainMenu(runtime, chatId, locale, editMessageId) {
1225
- const state = await getMenuState(runtime, chatId, locale);
1298
+ async function sendMainMenu(runtime, chatId, locale, editMessageId, forceBalance = false) {
1299
+ const state = await getMenuState(runtime, chatId, locale, forceBalance);
1226
1300
  const view = buildMainMenu(runtime.workspaces.list(), state, locale);
1227
1301
  if (editMessageId !== undefined)
1228
1302
  await editRich(runtime, chatId, editMessageId, view);
@@ -1277,6 +1351,25 @@ function buildCompactView(state, locale) {
1277
1351
  const keyboard = new InlineKeyboard().text(t(locale, 'compact'), 'compact:yes').text(t(locale, 'back'), 'menu:home');
1278
1352
  return { html, text, keyboard };
1279
1353
  }
1354
+ function buildCompactWaitingView(locale) {
1355
+ const text = t(locale, 'compactWorking');
1356
+ return {
1357
+ html: `<p>${escapeHtml(text).replaceAll('\n', '<br>')}</p>`,
1358
+ text,
1359
+ keyboard: new InlineKeyboard(),
1360
+ };
1361
+ }
1362
+ function buildCompactResultView(text, locale) {
1363
+ return {
1364
+ html: [
1365
+ `<h2>${escapeHtml(t(locale, 'compactResultTitle'))}</h2>`,
1366
+ `<p>${escapeHtml(text).replaceAll('\n', '<br>')}</p>`,
1367
+ `<tg-button-row align="left"><tg-button type="callback_data" style="primary" data="menu:home">${escapeHtml(t(locale, 'home'))}</tg-button></tg-button-row>`,
1368
+ ].join('\n'),
1369
+ text,
1370
+ keyboard: new InlineKeyboard().text(t(locale, 'home'), 'menu:home'),
1371
+ };
1372
+ }
1280
1373
  function sessionTitle(session, locale) {
1281
1374
  if (session.blank)
1282
1375
  return t(locale, 'newSessionTitle');
@@ -1536,6 +1629,67 @@ function chatForSession(runtime, sessionId) {
1536
1629
  return String(tracked);
1537
1630
  return runtime.store.sessionChat(sessionId);
1538
1631
  }
1632
+ function answerTargetForSession(runtime, sessionId) {
1633
+ const chatIdRaw = chatForSession(runtime, sessionId);
1634
+ if (chatIdRaw === undefined)
1635
+ return undefined;
1636
+ const chatId = Number(chatIdRaw);
1637
+ if (!Number.isSafeInteger(chatId))
1638
+ return undefined;
1639
+ const binding = runtime.store.get(chatIdRaw);
1640
+ return { chatId, binding, active: binding?.activeSessionId === sessionId };
1641
+ }
1642
+ function workspaceTitleFor(runtime, sessionId) {
1643
+ return runtime.workspaces.list().find(workspace => workspace.sessionIds.includes(sessionId))?.title;
1644
+ }
1645
+ /**
1646
+ * Tell the Telegram chat that a question or approval for another Session is
1647
+ * waiting in Web. This never claims the request: the Web answerer still gets it
1648
+ * through `next()`.
1649
+ */
1650
+ async function notifyWebWaiting(runtime, target, locale, sessionId, kind, toolName) {
1651
+ const workspace = workspaceTitleFor(runtime, sessionId) ?? 'β€”';
1652
+ const place = `${workspace} / ${t(locale, 'session')} ${sessionId.slice(0, 8)}`;
1653
+ const head = kind === 'question' ? t(locale, 'webWaitingQuestion') : t(locale, 'webWaitingApproval');
1654
+ const subject = kind === 'approval' && toolName !== undefined ? ` (${toolName})` : '';
1655
+ const text = `${head}${subject}: ${place}\n${t(locale, 'webWaitingHint')}`;
1656
+ await sendPlain(runtime, target.chatId, text, target.binding?.sound === false);
1657
+ }
1658
+ /** Sessions without their own Telegram route still report to the admin chat. */
1659
+ function webNoticeTarget(runtime, target) {
1660
+ if (target !== undefined)
1661
+ return target;
1662
+ const admin = runtime.adminUserId;
1663
+ if (admin === undefined)
1664
+ return undefined;
1665
+ return { chatId: admin, binding: runtime.store.get(String(admin)), active: false };
1666
+ }
1667
+ const WEB_WAITING_NOTICE_MS = 15_000;
1668
+ /**
1669
+ * Ping the Telegram chat only when Web has not settled the request quickly.
1670
+ * If the user is already answering in Web, the notice is cancelled, so the
1671
+ * bot does not duplicate every Web card.
1672
+ */
1673
+ function scheduleWebWaitingNotice(runtime, target, sessionId, kind, answered, toolName, delayMs = WEB_WAITING_NOTICE_MS) {
1674
+ const noticeTarget = webNoticeTarget(runtime, target);
1675
+ if (noticeTarget === undefined)
1676
+ return;
1677
+ const locale = noticeTarget.binding?.locale ?? 'ru';
1678
+ let settled = false;
1679
+ const timer = setTimeout(() => {
1680
+ if (settled)
1681
+ return;
1682
+ runtime.logger.info('web-waiting-notice', 'notifying Telegram about a Web request', {
1683
+ chatId: noticeTarget.chatId,
1684
+ sessionId,
1685
+ kind,
1686
+ ...(toolName === undefined ? {} : { toolName }),
1687
+ });
1688
+ void notifyWebWaiting(runtime, noticeTarget, locale, sessionId, kind, toolName);
1689
+ }, delayMs);
1690
+ timer.unref?.();
1691
+ void answered.then(() => { settled = true; clearTimeout(timer); }, () => { settled = true; clearTimeout(timer); });
1692
+ }
1539
1693
  async function handleSessionEvent(runtime, session, event) {
1540
1694
  if (session.header.origin === 'subagent')
1541
1695
  return;
@@ -1580,11 +1734,6 @@ async function handleSessionEvent(runtime, session, event) {
1580
1734
  void maybeWarnLowBalance(runtime, chatId, locale, silent);
1581
1735
  break;
1582
1736
  }
1583
- case 'compaction/end':
1584
- // Compaction can also be started from Web; drop the cached percentage
1585
- // so the next menu reads the updated projection immediately.
1586
- runtime.contextCache.delete(session.id);
1587
- break;
1588
1737
  default:
1589
1738
  break;
1590
1739
  }
@@ -1651,6 +1800,7 @@ async function runBot(ctx, config, workspaces, sessions, credentials, logger, si
1651
1800
  }
1652
1801
  const account = ctx.get('accountController');
1653
1802
  const tokenMeter = ctx.get('tokenMeter');
1803
+ const sessionProjections = ctx.get('sessionProjections');
1654
1804
  const commands = ctx.get('commands');
1655
1805
  const runtime = {
1656
1806
  bot,
@@ -1659,6 +1809,7 @@ async function runBot(ctx, config, workspaces, sessions, credentials, logger, si
1659
1809
  sessions,
1660
1810
  account,
1661
1811
  tokenMeter,
1812
+ sessionProjections,
1662
1813
  commands,
1663
1814
  adminUserId,
1664
1815
  allowedUserIds: [...allowedUserIds],
@@ -1673,7 +1824,6 @@ async function runBot(ctx, config, workspaces, sessions, credentials, logger, si
1673
1824
  pendingQuestionChats: new Map(),
1674
1825
  questionQueues: new Map(),
1675
1826
  balanceCache: { at: 0 },
1676
- contextCache: new Map(),
1677
1827
  lowBalanceWarnedAt: new Map(),
1678
1828
  rich: config.rich !== false,
1679
1829
  lowBalanceUsd: config.lowBalanceUsd ?? 1,
@@ -1685,8 +1835,11 @@ async function runBot(ctx, config, workspaces, sessions, credentials, logger, si
1685
1835
  logger.error('event-failed', messageOf(error), { sessionId: session.id, event: event.type });
1686
1836
  });
1687
1837
  }));
1688
- disposers.push(ctx.on('approval/request', (request, next) => handleApproval(runtime, request, next)));
1689
- disposers.push(ctx.on('user-questions/request', (request, next) => handleQuestion(runtime, request, next)));
1838
+ // Answerers run as a waterfall, and the Web bridge is registered earlier.
1839
+ // Prepending lets the bot decide first: it claims questions for the active
1840
+ // Telegram Session and delegates everything else to Web.
1841
+ disposers.push(ctx.on('approval/request', (request, next) => handleApproval(runtime, request, next), { prepend: true }));
1842
+ disposers.push(ctx.on('user-questions/request', (request, next) => handleQuestion(runtime, request, next), { prepend: true }));
1690
1843
  // Log Telegram API failures once per method per 30 seconds; polling can
1691
1844
  // otherwise flood the file during a network outage.
1692
1845
  const lastApiError = new Map();
@@ -1746,14 +1899,14 @@ async function runBot(ctx, config, workspaces, sessions, credentials, logger, si
1746
1899
  if (binding !== undefined) {
1747
1900
  await store.set({ ...binding, locale, updatedAt: Date.now() });
1748
1901
  }
1749
- await sendMainMenu(runtime, chatId, locale);
1902
+ await sendMainMenu(runtime, chatId, locale, undefined, true);
1750
1903
  });
1751
1904
  bot.command('menu', async (grammyCtx) => {
1752
1905
  const chatId = grammyCtx.chat?.id;
1753
1906
  if (chatId === undefined)
1754
1907
  return;
1755
1908
  const locale = localeOf(grammyCtx.from?.language_code);
1756
- await sendMainMenu(runtime, chatId, locale);
1909
+ await sendMainMenu(runtime, chatId, locale, undefined, true);
1757
1910
  });
1758
1911
  bot.command('new', async (grammyCtx) => {
1759
1912
  const chatId = grammyCtx.chat?.id;
@@ -1805,8 +1958,13 @@ async function runBot(ctx, config, workspaces, sessions, credentials, logger, si
1805
1958
  await grammyCtx.reply(t(locale, 'noActiveSession'));
1806
1959
  return;
1807
1960
  }
1808
- await grammyCtx.reply(await runCompact(runtime, chatId, locale, binding.activeSessionId));
1809
- await sendMainMenu(runtime, chatId, locale);
1961
+ const waitingId = await sendRich(runtime, chatId, buildCompactWaitingView(locale), binding.sound === false);
1962
+ const text = await runCompact(runtime, chatId, locale, binding.activeSessionId);
1963
+ if (waitingId === undefined)
1964
+ await grammyCtx.reply(text);
1965
+ else
1966
+ await editRich(runtime, chatId, waitingId, buildCompactResultView(text, locale));
1967
+ await sendMainMenu(runtime, chatId, locale, undefined, true);
1810
1968
  });
1811
1969
  bot.callbackQuery(/^ws:(.+)$/, async (grammyCtx) => {
1812
1970
  const workspaceId = grammyCtx.match[1];
@@ -1925,7 +2083,7 @@ async function runBot(ctx, config, workspaces, sessions, credentials, logger, si
1925
2083
  return;
1926
2084
  const locale = localeOf(grammyCtx.from?.language_code);
1927
2085
  await grammyCtx.answerCallbackQuery().catch(() => undefined);
1928
- await sendMainMenu(runtime, chatId, locale, grammyCtx.callbackQuery?.message?.message_id);
2086
+ await sendMainMenu(runtime, chatId, locale, grammyCtx.callbackQuery?.message?.message_id, true);
1929
2087
  });
1930
2088
  bot.callbackQuery('menu:sound', async (grammyCtx) => {
1931
2089
  const chatId = grammyCtx.chat?.id;
@@ -1993,14 +2151,12 @@ async function runBot(ctx, config, workspaces, sessions, credentials, logger, si
1993
2151
  await grammyCtx.answerCallbackQuery({ text: t(locale, 'noActiveSession') }).catch(() => undefined);
1994
2152
  return;
1995
2153
  }
1996
- await grammyCtx.answerCallbackQuery({ text: t(locale, 'compact') }).catch(() => undefined);
1997
- const text = await runCompact(runtime, chatId, locale, binding.activeSessionId);
1998
- const view = {
1999
- html: `<h2>${escapeHtml(t(locale, 'compactHistory'))}</h2><p>${escapeHtml(text)}</p><tg-button-row align="left"><tg-button type="callback_data" style="primary" data="menu:home">${escapeHtml(t(locale, 'home'))}</tg-button></tg-button-row>`,
2000
- text,
2001
- keyboard: new InlineKeyboard().text(t(locale, 'home'), 'menu:home'),
2002
- };
2154
+ await grammyCtx.answerCallbackQuery().catch(() => undefined);
2003
2155
  const messageId = grammyCtx.callbackQuery?.message?.message_id;
2156
+ if (messageId !== undefined)
2157
+ await editRich(runtime, chatId, messageId, buildCompactWaitingView(locale));
2158
+ const text = await runCompact(runtime, chatId, locale, binding.activeSessionId);
2159
+ const view = buildCompactResultView(text, locale);
2004
2160
  if (messageId !== undefined)
2005
2161
  await editRich(runtime, chatId, messageId, view);
2006
2162
  else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shliamb/dsh-telegram-bot",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Telegram bridge for DeepSeek Harness",
5
5
  "keywords": [
6
6
  "deepseek-harness",