grok-telegram-bot 2.0.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.
Files changed (106) hide show
  1. package/.env.example +135 -0
  2. package/CHANGELOG.md +598 -0
  3. package/LICENSE +21 -0
  4. package/README.md +644 -0
  5. package/bin/grok-tg.mjs +21 -0
  6. package/docs/INSTALL.md +153 -0
  7. package/docs/UPGRADE.md +253 -0
  8. package/docs/ops/RELEASE_CHECKLIST.md +39 -0
  9. package/package.json +74 -0
  10. package/scripts/setup.mjs +116 -0
  11. package/src/agents/catalog.ts +58 -0
  12. package/src/app/accounts.ts +162 -0
  13. package/src/app/auth-service.ts +136 -0
  14. package/src/app/grok-credentials.ts +103 -0
  15. package/src/app/instance-lock.ts +139 -0
  16. package/src/app/json-store.ts +54 -0
  17. package/src/app/reasoning.ts +30 -0
  18. package/src/app/settings-store.ts +38 -0
  19. package/src/app/stt.ts +53 -0
  20. package/src/app/types.ts +56 -0
  21. package/src/app/updater.ts +234 -0
  22. package/src/app/usage.ts +38 -0
  23. package/src/app/version.ts +41 -0
  24. package/src/bot/account-rotator.ts +52 -0
  25. package/src/bot/auth.ts +38 -0
  26. package/src/bot/bot.ts +225 -0
  27. package/src/bot/chat-controller.ts +317 -0
  28. package/src/bot/commands.ts +52 -0
  29. package/src/bot/deps.ts +67 -0
  30. package/src/bot/file-ingest.ts +190 -0
  31. package/src/bot/handlers/accounts.ts +220 -0
  32. package/src/bot/handlers/auth.ts +64 -0
  33. package/src/bot/handlers/control.ts +103 -0
  34. package/src/bot/handlers/document.ts +112 -0
  35. package/src/bot/handlers/history.ts +63 -0
  36. package/src/bot/handlers/kill.ts +54 -0
  37. package/src/bot/handlers/mcp.ts +206 -0
  38. package/src/bot/handlers/menu.ts +220 -0
  39. package/src/bot/handlers/message.ts +103 -0
  40. package/src/bot/handlers/photo.ts +123 -0
  41. package/src/bot/handlers/projects.ts +183 -0
  42. package/src/bot/handlers/running.ts +181 -0
  43. package/src/bot/handlers/session-card.ts +81 -0
  44. package/src/bot/handlers/session-kill.ts +95 -0
  45. package/src/bot/handlers/sessions.ts +148 -0
  46. package/src/bot/handlers/system.ts +51 -0
  47. package/src/bot/handlers/tasks.ts +224 -0
  48. package/src/bot/handlers/usage.ts +38 -0
  49. package/src/bot/handlers/voice.ts +55 -0
  50. package/src/bot/image-return.ts +69 -0
  51. package/src/bot/menu/ephemeral.ts +117 -0
  52. package/src/bot/menu/keyboard.ts +49 -0
  53. package/src/bot/menu/refresh.ts +13 -0
  54. package/src/bot/menu/status-panel.ts +173 -0
  55. package/src/bot/permission-service.ts +149 -0
  56. package/src/bot/prompt-content.ts +64 -0
  57. package/src/bot/prompt-retry.ts +70 -0
  58. package/src/bot/reauth-controller.ts +297 -0
  59. package/src/bot/registry.ts +186 -0
  60. package/src/bot/reply-context.ts +77 -0
  61. package/src/bot/session-fork.ts +35 -0
  62. package/src/bot/session-runtime.ts +1048 -0
  63. package/src/bot/telegram-io.ts +109 -0
  64. package/src/bot/typing.ts +35 -0
  65. package/src/bot/wizard/task-wizard.ts +214 -0
  66. package/src/cli.ts +126 -0
  67. package/src/config.ts +248 -0
  68. package/src/grok/client.ts +617 -0
  69. package/src/grok/models.ts +50 -0
  70. package/src/grok/session-log.ts +148 -0
  71. package/src/grok/transport.ts +51 -0
  72. package/src/grok/types.ts +136 -0
  73. package/src/index.ts +84 -0
  74. package/src/logger.ts +78 -0
  75. package/src/mcp/config.ts +120 -0
  76. package/src/mcp/probe.ts +218 -0
  77. package/src/mcp/types.ts +68 -0
  78. package/src/projects/manager.ts +99 -0
  79. package/src/render/chunk.ts +57 -0
  80. package/src/render/diff.ts +48 -0
  81. package/src/render/escape.ts +22 -0
  82. package/src/render/file-summary.ts +111 -0
  83. package/src/render/hashtags.ts +34 -0
  84. package/src/render/markdown.ts +130 -0
  85. package/src/render/progress-estimate.ts +63 -0
  86. package/src/render/progress.ts +80 -0
  87. package/src/render/subagent.ts +75 -0
  88. package/src/render/tool-call.ts +196 -0
  89. package/src/service/index.ts +24 -0
  90. package/src/service/linux.ts +85 -0
  91. package/src/service/macos.ts +101 -0
  92. package/src/service/platform.ts +64 -0
  93. package/src/service/types.ts +36 -0
  94. package/src/service/windows.ts +198 -0
  95. package/src/sessions/history.ts +225 -0
  96. package/src/sessions/process.ts +30 -0
  97. package/src/sessions/store.ts +133 -0
  98. package/src/sessions/tail.ts +86 -0
  99. package/src/sessions/types.ts +26 -0
  100. package/src/stream/streamer.ts +261 -0
  101. package/src/tasks/runner.ts +82 -0
  102. package/src/tasks/schedule.ts +142 -0
  103. package/src/tasks/scheduler.ts +53 -0
  104. package/src/tasks/store.ts +80 -0
  105. package/src/tasks/types.ts +33 -0
  106. package/tsconfig.json +19 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,598 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format is based on
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
+ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ The latest section is published verbatim as the GitHub Release notes by
8
+ `.github/workflows/release.yml` when a `vX.Y.Z` tag is pushed.
9
+
10
+ ## [Unreleased]
11
+
12
+ ## [2.0.0] - 2026-07-09
13
+
14
+ The **Grok Build** release โ€” the bot now drives the official **xAI Grok Build
15
+ CLI** (`grok`) over the **Agent Client Protocol (ACP)** instead of Kiro. This is
16
+ a full re-architecture (a new major version) that keeps the same feature surface.
17
+
18
+ ### Changed
19
+ - **Transport:** replaced `kiro-cli acp` with `grok agent stdio` โ€” a persistent
20
+ JSON-RPC/ACP process. After `initialize` the bot runs the ACP `authenticate`
21
+ step (`cached_token` from `grok login`, or `xai.api_key`), then
22
+ `session/new` / `session/load` / `session/prompt`, streaming `session/update`.
23
+ - **Auth:** sign in with your **xAI account** via `grok login` (browser OIDC,
24
+ token in `~/.grok/auth.json`), or `XAI_API_KEY` on a headless host. `/reauth`
25
+ runs sign-in/import from chat; `/accounts` snapshots/switches `~/.grok/auth.json`.
26
+ (No API key required โ€” you need SuperGrok or X Premium+.)
27
+ - **Binary:** `~/.grok/bin/grok`; `--always-approve` maps to trust-all;
28
+ `--no-auto-update` is passed for automation.
29
+ - **Sessions:** the bot records the sessions it drives under `<data>/sessions/`
30
+ (`<id>.json`/`.jsonl`/`.lock`), fully separate from Kiro's `~/.kiro/sessions/cli`.
31
+ - **Config home:** `~/.grok/tg`; env vars renamed `KIRO_*` โ†’ `GROK_*`; the CLI
32
+ is now `grok-tg`; the npm package is `grok-telegram-bot`.
33
+
34
+ ### Notes
35
+ - Use a **dedicated BotFather token** if you also run a Kiro bridge โ€” Telegram
36
+ allows only one long-polling consumer per token. The bot binds no local ports.
37
+ - Inline tool approvals work in ACP "ask" mode (unset `GROK_TRUST_ALL_TOOLS`).
38
+
39
+ ## [1.8.0] - 2026-07-06
40
+
41
+ The **"multi-account"** release โ€” log in to Grok from Telegram with your
42
+ **organization / company account**, **import an existing Grok CLI login**, and
43
+ keep **several accounts side by side** to switch between in a tap (with optional
44
+ **auto-rotate** when a turn gives up). Account labels now show the real **email**
45
+ (decoded from the login token) instead of "ExternalIdp", the **`โœ… Done` line and
46
+ `/usage`** surface **credits used** (when Grok reports them) plus turns this
47
+ session, and there's a new **[UPGRADE guide](docs/UPGRADE.md)** covering npm,
48
+ zip, and source updates. Plus a fix for duplicate pinned status panels during
49
+ heavy subagent work.
50
+
51
+ ### Added
52
+
53
+ - **๐Ÿข Organization / company login on `/reauth`.** A **"Your organization"**
54
+ option guides you through Grok's org sign-in. grok's org flow opens in a
55
+ **browser** (`app.grok.dev`) with a `localhost` callback, which the bot can't
56
+ drive headlessly โ€” so it shows clear steps to run `grok login` on the
57
+ machine hosting the bot, then a **"โœ… I've logged in โ€” check"** button that
58
+ verifies the login with `grok whoami` and restarts the agent to adopt it.
59
+ Works for Microsoft/Entra work-email orgs (which don't use a start URL);
60
+ **IAM Identity Center** (AWS IdC, start URL) remains its own option.
61
+ - **๐Ÿ“ฅ Import your Grok CLI login on `/reauth`.** An **"Import IDE"** option
62
+ reuses a Grok login already on this machine (Grok CLI and Grok CLI share the
63
+ AWS SSO device-token cache). Import (and account save/switch) now **verifies
64
+ the login with `grok whoami`** and only reports success when the CLI
65
+ actually accepts the token โ€” instead of a false "imported โœ…" that later fails
66
+ every turn with `dispatch failure`, you get a clear message and the guided
67
+ organization steps.
68
+ - **๐Ÿ‘ฅ Multiple accounts with `/accounts`.** Save several Grok logins side by
69
+ side and switch between them in one tap: switching copies the saved token back
70
+ over the live login and restarts the agent so sessions re-bind under the new
71
+ identity. The current login is auto-snapshotted before a switch so it's never
72
+ lost, with inline **Import Grok CLI** / **Save current login** / **Save asโ€ฆ**
73
+ (custom name) / **โœ๏ธ rename** / delete controls. Also reachable from the menu
74
+ (**๐Ÿ‘ฅ Accounts**). Credentials are stored only under the git-ignored `data/`
75
+ dir โ€” never transmitted.
76
+ - **๐Ÿ” Auto-rotate accounts on give-up (toggle in `/accounts`).** When a turn
77
+ exhausts its retries and auto-fork can't recover it, the bot can cycle through
78
+ your other saved logins โ€” switching account, restarting the agent, and
79
+ retrying the same prompt on each. The first account that works wins and stays
80
+ active; if they all fail it stops after **one full pass** (never loops) and
81
+ reports what each account returned. Off by default; flip it with the
82
+ **๐Ÿ” Auto-rotate** button in `/accounts`. (Switching is machine-global, so a
83
+ rotation moves every chat onto the working login.)
84
+ - **๐Ÿ“ง Real account names instead of "ExternalIdp".** Account labels and
85
+ `/usage` now show the login's **email**, decoded from the token's JWT claims
86
+ (`email` / `preferred_username`) when `grok whoami` can't report it (e.g.
87
+ once the short-lived access token lapses). `whoami` JSON parsing was also
88
+ hardened to read nested payloads.
89
+ - **๐Ÿช™ Credits on the Done line & in `/usage`.** When Grok reports a
90
+ credits/cost figure for a turn, it's shown on the `โœ… Done` line and in
91
+ `/usage`. `/usage` also now shows **turns this session** and your **saved
92
+ account count**. (Grok CLI doesn't expose billing limits headlessly, so full
93
+ quota still lives in the Grok app; credits appear only when the agent sends
94
+ them.)
95
+ - **โฌ†๏ธ Upgrade guide (`docs/UPGRADE.md`).** Step-by-step updating for every
96
+ install type โ€” npm (auto-update or `npm install -g โ€ฆ@latest`), 1-click/zip
97
+ (replace files, keep your `.env`/`data/`), and git/source (`git pull`) โ€” plus
98
+ how to restart, migrate a non-npm install to npm, and pin/roll back. Linked
99
+ from the README and install guide.
100
+
101
+ ### Fixed
102
+
103
+ - **๐Ÿงญ Duplicate status panels during subagent work.** With many subagents
104
+ running, every subagent update fired a status-panel refresh; because the panel
105
+ is created asynchronously (send โ†’ save id โ†’ pin), concurrent refreshes each saw
106
+ "no panel yet" and each **created and pinned a new panel** โ€” stacking dozens of
107
+ duplicates in the chat. Refreshes are now **coalesced and serialized per chat**
108
+ (only one runs at a time; a burst collapses into a single throttled follow-up),
109
+ and the panel is recreated **only when it's genuinely gone** โ€” never on a
110
+ transient edit error (e.g. 429), which previously also spawned duplicates.
111
+
112
+ ## [1.7.2] - 2026-06-25
113
+
114
+ The **"steady & solo"** release โ€” a self-computing progress bar that never spams
115
+ empty bubbles, a single-instance guard that clears ghost processes, a
116
+ path-independent `~/.grok/tg/` config home, a polished pinned status panel, and
117
+ fixes for the false idle-timeout during subagent (translation) work and the bot
118
+ rejecting its own pin messages as "Not authorized".
119
+
120
+ ### Added
121
+
122
+ - **๐Ÿ“ˆ Bot-computed task-progress fallback (`PROGRESS_FALLBACK`).** The
123
+ `{progress: N%}` bar previously depended entirely on the agent emitting the
124
+ marker โ€” and that marker is only an *instruction* the model can ignore, so
125
+ weaker/free models and long, tool-heavy turns often emitted none, leaving the
126
+ bar empty for the whole turn. Now, when `SHOW_PROGRESS` is on but no marker
127
+ arrives, the bot renders a **computed** bar derived from **real activity**
128
+ (completed tool calls, streamed output, elapsed time): it starts low, climbs in
129
+ realistic increments via a saturating curve capped at 90 % while running, and
130
+ fills to 100 % when the turn completes successfully. The estimate is monotonic
131
+ by construction, and the agent's own marker โ€” when present โ€” always takes
132
+ precedence (the fallback stops contributing the moment a real value arrives).
133
+ The bar is only ever **appended to real streamed content** โ€” it never produces
134
+ a standalone/empty bubble โ€” and the live status panel shows it on its own.
135
+ Disable with `PROGRESS_FALLBACK=false`.
136
+ - **๐Ÿ  Canonical, path-independent config home (`~/.grok/tg/`).** The `.env`
137
+ (plus `logs/`, `data/`) now lives in `~/.grok/tg/` by default, so the bot loads
138
+ the **same** configuration no matter which folder you start it from โ€” no more
139
+ "works from this directory, broken from that one". Resolution order is
140
+ `--instance` โ†’ `GROK_TG_DIR` โ†’ a `.env` in the current folder (so existing
141
+ per-folder checkouts keep working) โ†’ `~/.grok/tg`. `grok-tg setup` writes there
142
+ by default, and **`grok-tg setup --path`** prints the resolved `.env` location.
143
+ - **๐Ÿ”’ Single-instance guard, per bot token (`GROK_TG_SINGLE_INSTANCE`).** On
144
+ startup the bot takes a token-scoped lock under `~/.grok/tg/locks/`; if a
145
+ still-alive **ghost/duplicate** is already polling Telegram with that token, it
146
+ is terminated (and its child tree on Windows) so the fresh process โ€” with your
147
+ current `.env` โ€” becomes the sole `getUpdates` consumer.
148
+
149
+ ### Changed
150
+
151
+ - **๐Ÿงญ Polished status panel.** The pinned status message was redesigned for
152
+ readability: the redundant "Grok โ€” Status" header is gone, the **progress bar
153
+ is the first line** (so the collapsed pin preview shows how far along the
154
+ current task is), and the cramped space-padded columns are replaced with clean
155
+ emoji-led fields separated by ` | ` across three short lines โ€” activity
156
+ (`state | queue | sessions | watching | subagents`), location
157
+ (`project | session | context`) and config (`agent | reasoning | model`).
158
+ Counters that don't apply (empty queue, single session) are hidden instead of
159
+ shown as `0`.
160
+ - **๐Ÿงน Progress clears when a turn ends.** The task-progress value is now reset
161
+ when a turn finishes, stops, or errors, so the bar is removed from the status
162
+ panel, session cards and switch messages once the work is done (the finished
163
+ streamed message keeps its own frozen bar as a record).
164
+ - **๐Ÿซฅ Status panel only while working.** The pinned status panel now appears
165
+ while a turn is running (or a follow-up is queued) and is **removed when the
166
+ session goes idle**, so the chat stays clean between tasks. The full state is
167
+ still available on demand via **Status** in the menu (`/status`).
168
+
169
+ ### Fixed
170
+
171
+ - **โ›” Spurious "Not authorized" from the bot's own pin messages.** The auth
172
+ gate replied "โ›” Not authorized" to **every** update whose sender wasn't an
173
+ allowed user โ€” including the bot's **own** service messages. Since the status
174
+ panel is pinned/unpinned, each pin emits a `pinned_message` service update
175
+ authored by the bot, so the gate kept rejecting itself (interleaved with
176
+ normal replies). The gate now ignores updates that aren't a real user action
177
+ (the bot's own/`is_bot` updates, service messages, and updates with no
178
+ `from`), and those pin service messages are deleted on arrival so they no
179
+ longer clutter the chat. Genuine unauthorized users still get one clear reply.
180
+ - **โ›” Phantom "Not authorized" from a ghost process.** A leftover bot started
181
+ from another folder kept answering with a stale `.env` (e.g. an outdated
182
+ `ALLOWED_USERS`), rejecting you while the new process couldn't poll (Telegram
183
+ 409 Conflict). The single-instance guard above clears the ghost on startup. A
184
+ plain `grok-tg run` still **yields** to an already-running background service
185
+ rather than fighting it (no restart/kill loop).
186
+ - **โฑ๏ธ False "No agent activity โ€ฆ giving up" during subagent delegation.** The
187
+ prompt idle-timeout tracked activity per session, but subagents (e.g. parallel
188
+ translation crews) stream on their own session ids, so a main turn that
189
+ delegated heavy work looked "silent" and was killed after ~15 min even though
190
+ the agent was busy โ€” and the next message then collided with the still-running
191
+ turn as `-32603 โ€ฆ dispatch failure`. The watchdog now uses a **process-wide
192
+ activity clock** (any session/subagent stream, metadata, or subagent status
193
+ refreshes it), so a delegating turn stays alive while its subagents work; only
194
+ a genuinely silent agent trips it. When it does fire (idle or the hard cap),
195
+ the agent's turn is now **cancelled** so the session is immediately reusable.
196
+ `dispatch failure` and common connection/stream errors are also now classified
197
+ as **transient**, so they retry/auto-fork instead of surfacing as a dead end.
198
+
199
+ ## [1.7.1] - 2026-06-24
200
+
201
+ The **"sign in your way"** release โ€” `/reauth` now lets you pick how you log in
202
+ (Builder ID, Google, GitHub or IAM Identity Center) on one tidy status card, and
203
+ the live task-progress bar climbs steadily instead of appearing only at the end.
204
+
205
+ ### Added
206
+
207
+ - **๐Ÿ” `/reauth` login-method picker.** Re-authentication now opens with a
208
+ **picker** โ€” **Builder ID** (free), **Google**, **GitHub**, or **IAM Identity
209
+ Center** (Pro) โ€” driven on a **single, self-animated status message** with
210
+ inline **Cancel ยท Retry ยท Change method ยท Restart agent** controls, so the chat
211
+ no longer fills with raw spinner frames. **IAM Identity Center** sign-in is now
212
+ fully supported: the bot asks for your **start URL + region** and drives the
213
+ CLI's interactive prompts inside a pseudo-terminal (optional
214
+ `@homebridge/node-pty-prebuilt-multiarch` dependency; a clear message tells you
215
+ to run `npm install` if it's missing). The device-verification URL + code still
216
+ stream to the chat for every method. Power users can skip the picker by passing
217
+ flags directly, e.g. `/reauth --license pro --identity-provider <url> --region <region>`.
218
+
219
+ ### Changed
220
+
221
+ - **๐Ÿ“ˆ Stricter, steadier task-progress reporting.** The agent instruction behind
222
+ the `{progress: N%}` marker is now far more rigorous: a marker is required on
223
+ **every** message (not only the last), the number must be **computed from real
224
+ step completion** and is **monotonic** (never decreases within a task), and
225
+ **100 %** is reserved for work that is fully complete *and verified*. The bar
226
+ now advances in realistic increments instead of jumping to a value at the very
227
+ end.
228
+
229
+ ### Fixed
230
+
231
+ - **๐Ÿ” `/reauth` agent-restart race** (`agent restart failed: grok acp exited
232
+ (code null)`). Logging out and restarting could let the **old** agent process's
233
+ exit fail the **new** connection's `initialize` and even trigger a competing
234
+ auto-restart. The ACP client now **fully tears down** the previous process
235
+ (ignoring the exit of a process it has already replaced) **before** spawning a
236
+ fresh one, and `/reauth` takes the agent down and **waits** before logging out โ€”
237
+ so a deliberate restart is clean and the new identity sticks.
238
+ - **๐Ÿชช Stale identity after re-login.** On logout the bot now also **clears Grok's
239
+ cached auth token** (`~/.aws/sso/cache/grok-auth-token.json`), so the next login
240
+ performs a genuine device-flow authentication instead of silently reusing the
241
+ previous account's refreshable token.
242
+
243
+ ## [1.7.0] - 2026-06-23
244
+
245
+ The **"take control"** release โ€” stop a runaway session by PID, re-authenticate
246
+ Grok from your phone, watch a live task-progress bar, and install on Windows
247
+ without admin.
248
+
249
+ ### Added
250
+
251
+ - **๐Ÿ›‘ Kill a session / PID from its card (`/sessions`, `/active`).** Every
252
+ **live** session card now has a **`๐Ÿ›‘ Kill ยท pid N`** button that terminates
253
+ that session's process โ€” and its whole child tree on Windows (`taskkill /T`).
254
+ It's guarded by an inline **confirm** (Kill / Cancel) since it's destructive,
255
+ the bot's **own** agent process is never offered (killing it would take the
256
+ bot down), and the session state is re-read at every step so a session that
257
+ already stopped reports "no longer running" instead of a phantom kill. The
258
+ existing `/killall` (stop every active session at once) is unchanged and now
259
+ shares the same kill logic.
260
+ - **๐Ÿ” Re-authenticate Grok from Telegram (`/reauth`).** Logs out
261
+ (`grok logout`) and starts a fresh **device-flow** login
262
+ (`grok login --use-device-flow`) โ€” the verification URL + code are
263
+ **streamed into the chat** so you complete it on your own device โ€” then
264
+ **restarts the agent** so it picks up the new credentials. Refused while a
265
+ turn is in flight (logging out would break it) and serialised so two runs
266
+ can't overlap. Pass-through flags are supported, e.g.
267
+ `/reauth --license free` or `/reauth --license pro --region <r> --identity-provider <url>`.
268
+ - **๐Ÿ“ˆ Live task-progress bar (`SHOW_PROGRESS`, on by default).** The agent is
269
+ asked to end each message with a `{progress: N%}` marker; the bot **parses and
270
+ hides** it and renders a **green 0โ€“100 % loading bar** (`๐ŸŸฉ๐ŸŸฉ๐ŸŸฉโฌœโฌœโฌœ 50%`,
271
+ all-green โœ… at 100 %) at the bottom of the **live message**, in the pinned
272
+ **status panel**, and on **`/running` and `/sessions` cards** โ€” so you can see
273
+ how far along the current task is. Markers (and the instruction) are also
274
+ stripped from history, unread replays, previews and fork-priming, so the raw
275
+ plumbing never shows. Disable with `SHOW_PROGRESS=false`.
276
+ - **๐Ÿ”€ "Switch to this session" on background pings.** A **`๐Ÿ“จ From other
277
+ session`** Done/error notification now carries a **๐Ÿ”€ Switch to this session**
278
+ button that brings that session to the foreground in one tap.
279
+
280
+ ### Changed
281
+
282
+ - **๐ŸชŸ Windows install no longer needs admin.** `grok-tg install` used to fail
283
+ with **`schtasks create failed: ERROR: Access is denied`** for a normal user,
284
+ because registering a **logon-triggered** Scheduled Task is a privileged
285
+ operation. The installer now falls back to a hidden per-user **Startup-folder**
286
+ launcher (runs at logon, **no elevation**) when the task can't be created; an
287
+ **elevated** run still uses the nicer hidden Scheduled Task. `install`,
288
+ `start`, `stop`, `status` and `uninstall` understand both mechanisms, and a
289
+ pre-launch running-check prevents a **double-launch** (two pollers on one bot
290
+ token would otherwise trigger Telegram 409 Conflict).
291
+ - **๐Ÿ”• No interim "Done" ping from a busy background session.** A background
292
+ ("other session") turn that still has **queued follow-ups** no longer pings an
293
+ intermediate "Done" โ€” only the final, queue-empty turn announces completion,
294
+ so a session working through a queue doesn't spam you between steps.
295
+
296
+ ## [1.6.0] - 2026-06-23
297
+
298
+ The **"always-on & self-healing"** release โ€” the bot keeps itself up to date,
299
+ recovers context-full sessions on its own, threads every reply to your prompt,
300
+ and keeps the chat tidy while you drive several sessions at once.
301
+
302
+ ### Added
303
+
304
+ - **๐Ÿ”„ Auto-update (`AUTO_UPDATE`, on by default).** Once an hour the bot makes
305
+ one tiny npm request for the latest version. When a newer one exists **and the
306
+ bot is fully idle** โ€” no chat turn or scheduled task running, and no other
307
+ active Grok session on the PC โ€” it announces in chat, runs
308
+ `npm install -g grok-telegram-bot@latest`, restarts, and posts the new
309
+ release's features/fixes **tagged `#update`** so every upgrade is easy to find.
310
+ It never interrupts work, and only acts on a global npm install (a source
311
+ checkout is left to `git`). Tunable via `UPDATE_CHECK_MS`.
312
+ - **๐Ÿท Threaded replies + searchable hashtags.** **Every** message of a turn โ€”
313
+ each response bubble, tool call, the retry/fork notices and the Done line โ€” is
314
+ now sent as a **reply to your prompt** (not just the first one), so the whole
315
+ turn is visually threaded to what you asked (your prompt is left untouched).
316
+ **Every message bubble**, including the live thinking/streaming one, ends with
317
+ `#proj_โ€ฆ #sess_โ€ฆ`, so tapping a tag pulls up every message for that project or
318
+ session. (Model and reasoning tags were dropped โ€” they were noisy and rarely
319
+ useful.) Works for text, voice and photo prompts.
320
+ - **๐Ÿ” Instant fork on a context-full session (`AUTO_FORK_CONTEXT_PCT`, default
321
+ 85).** Sending to a session whose context is exhausted used to fail with
322
+ `-32603 โ€ฆ The request was throttled by the service` and then burn the whole
323
+ retry backoff (6s โ†’ 12s โ†’ 24s โ†’ 48s โ†’ 60s โ‰ˆ 2ยฝ min) before recovering โ€” because
324
+ retrying the same oversized prompt can't succeed. Now, when a prompt fails
325
+ transiently **and** the session's last-known context usage is at/above
326
+ `AUTO_FORK_CONTEXT_PCT` (or the error explicitly names a context-window
327
+ overflow), the bot **skips the retries and forks immediately**: it compacts the
328
+ conversation into a fresh continuation primed with the recent transcript and
329
+ retries your message once. Requires `AUTO_FORK_ON_ERROR`; set the % to `0` to
330
+ disable the early trigger and keep the old retry-then-fork behavior.
331
+ - **๐Ÿ—‚ Open any folder / safer project creation (`/projects`).** `/projects <path>`
332
+ now opens a session in **any existing folder** โ€” `C:\work\app`, `/home/me/app`,
333
+ `~/app`, even outside your `PROJECT_ROOTS` โ€” and **errors if the path doesn't
334
+ exist** (it's never created). `/projects new <name>` now **errors if the
335
+ project already exists** instead of silently reusing it; otherwise it creates
336
+ the folder and starts a session there. `/project` works as an alias.
337
+
338
+ ### Changed
339
+
340
+ - **๐Ÿ“„ Paginated `/projects` and `/sessions` (10 per page).** Long lists no longer
341
+ flood the chat โ€” the project picker pages in place with **โ—€ Prev / Next โ–ถ** and
342
+ a `page x/y` indicator, and session cards are shown a page at a time with the
343
+ same nav. Selecting an item still works across pages (absolute indexing).
344
+
345
+ - **โœ… "Done" summaries from other running sessions.** When you drive several
346
+ sessions at once and switch between them, a background session that finishes
347
+ now pings you โ€” clearly marked **`๐Ÿ“จ From other session [project ยท id]`** with
348
+ a **short** file count (`๐Ÿ“ +2 created ยท ~3 edited ยท โˆ’1 deleted`, or
349
+ `๐Ÿ“„ No files modified`). The session you're actively viewing still gets the
350
+ full completion message with the list of changed paths. Toggle with the new
351
+ **`NOTIFY_OTHER_SESSIONS`** env var (default `true`); set it `false` to keep
352
+ background sessions silent (their output still shows when you switch back).
353
+ File operations are tracked for background turns too, so the count is accurate
354
+ regardless of which session you were viewing. **Switching (back) into a
355
+ session also replays its last Done + file summary** at the end of the catch-up
356
+ view (so you see how it ended), and the completion line is now more compact
357
+ and professional โ€” no `end_turn`/`Files:` noise, with project-relative paths.
358
+ - **๐Ÿท Clearer skill & MCP tool lines.** Loading a skill now shows
359
+ **`๐Ÿ“š Loaded skill: <name>`** instead of a cryptic `SKILL.md:1` read line, and
360
+ MCP/extension tool calls render as **`๐Ÿงฉ Call MCP <server>: <method>`** (or
361
+ `๐Ÿงฉ Call MCP: <tool>` when the call carries no server name). Built-in
362
+ file/shell tools are never mislabelled.
363
+ - **๐Ÿ“ Projects sorted by most-recently-used.** The `/projects` picker now lists
364
+ folders **freshest first** โ€” ranked by the latest of the directory's modified
365
+ time and the newest Grok session opened in it โ€” so the project you were just
366
+ working in is at the top instead of a fixed alphabetical order.
367
+ - **๐Ÿงญ Redesigned `/running` โ€” one card per session.** Instead of a cramped
368
+ combined list, each controlled session is now its own **card** with
369
+ **๐Ÿ”€ Switch ยท ๐Ÿ“œ History ยท โœ– Close** buttons, showing its project, status, how
370
+ long ago it was last active, unread count, and a short preview of its first
371
+ prompt (reasoning directive stripped) โ€” so you can tell sessions apart and act
372
+ on each one directly. The foreground session shows โ–ถ๏ธ Current instead of Switch.
373
+ - **๐Ÿงน Self-cleaning navigation โ€” a tidy history.** Menus, session/project
374
+ cards, pickers and submenus are now **transient**: opening a new surface (or
375
+ acting on one) removes the previous one, and your command / menu-button
376
+ messages are deleted after they're handled. Boundary markers you actually want
377
+ to keep โ€” **๐Ÿ”€ Switched / โœจ New session / ๐Ÿ“ Now working inโ€ฆ**, agent output,
378
+ Done summaries and the pinned status panel โ€” always remain, so the chat reads
379
+ as a clean timeline of what happened, not a pile of menus.
380
+
381
+ ### Fixed
382
+
383
+ - **๐Ÿ‘ฏ Duplicate session cards in `/running`.** Tapping a session twice (or in
384
+ quick succession) could create **two runtimes for the same session** โ€” the
385
+ add-session paths checked "already controlled?" and then `await`ed before
386
+ reserving the runtime, so concurrent taps both passed the check. The runtime
387
+ is now reserved synchronously after the check; restores and persistence dedupe
388
+ by session id; and `/running` prunes any existing duplicate, so the list
389
+ self-heals.
390
+ - **๐Ÿ”ฃ Stray โ€œ`โ€ in streamed messages.** An unbalanced/partial code fence in an
391
+ agent message could leave an orphan lone-backtick line that rendered as a
392
+ broken-looking single backtick. Such orphan ` / `` lines are now dropped (real
393
+ triple-backtick fences and inline `code` are untouched).
394
+ - **โšก `/btw` now runs as soon as possible.** Previously `/btw <text>` only ever
395
+ parked the message in the queue โ€” so when the bot was **idle** it sat there
396
+ doing nothing until `/flush` or another message. It now runs **immediately
397
+ when idle**, and when a turn is in flight it's queued and runs **automatically
398
+ the moment that turn finishes** (an in-flight agent turn can't be interrupted).
399
+
400
+ ## [1.5.1] - 2026-06-22
401
+
402
+ ### Added
403
+
404
+ - **๐Ÿ“ฆ Install from npm** โ€” the bot is now a published package with a global
405
+ CLI: `npm install -g grok-telegram-bot` gives you the **`grok-tg`** command
406
+ (alias `grok-telegram-bot`). Multiple startup options: `grok-tg setup`
407
+ (writes `.env` + auto-detects `grok`), `grok-tg run` (foreground), and the
408
+ full 24/7 **service** controls โ€” `install ยท status ยท logs ยท stop ยท restart ยท
409
+ uninstall` โ€” auto-detected per platform. Each instance keeps its
410
+ `.env`/`logs/`/`data/` in the **folder you run it from** (resolved from the
411
+ `--instance` the service passes, the launcher's working dir, or the cwd), so a
412
+ global install never writes into `node_modules`. Cloned/zip checkouts behave
413
+ exactly as before. `tsx` moved to runtime deps (still no build step). npm is
414
+ now the **primary** install option in [docs/INSTALL.md](docs/INSTALL.md).
415
+
416
+ ### Fixed
417
+
418
+ - **๐Ÿงต Long messages split by Telegram are now stitched back together** โ€”
419
+ Telegram caps a message at 4096 characters, so a long paste arrives as several
420
+ back-to-back messages. The bot used to treat each part as its own prompt โ€”
421
+ spamming **โ€œQueued (position 1โ€ฆ4)โ€** and even replying **โ€œUnknown commandโ€**
422
+ when a split landed on a line starting with `/`. Rapid consecutive text
423
+ messages are now **coalesced within a short window into a single prompt** (one
424
+ submission, one confirmation, in order). Tunable via `MESSAGE_BATCH_MS`
425
+ (default `800`; `0` disables). A genuine lone `/typo` still gets the friendly
426
+ โ€œUnknown commandโ€ hint, and a failed submit now reports an error instead of
427
+ silently vanishing.
428
+
429
+ ## [1.5.0] - 2026-06-22
430
+
431
+ The **"mission control"** release โ€” manage the agent's MCP servers and watch
432
+ its subagents from Telegram, with quieter notifications and sturdier sessions.
433
+
434
+ ### Added
435
+
436
+ - **๐Ÿงฉ MCP control (`/mcp`)** โ€” inspect and manage the agent's MCP servers from
437
+ Telegram. Lists every configured server with its **enabled/disabled** state,
438
+ transport (stdio/http) and scope (global/workspace); a **๐Ÿงช Health-check**
439
+ runs a real MCP `initialize` handshake against each enabled server and reports
440
+ which **connected** and which **failed (and why)** โ€” connection refused,
441
+ timeout, HTTP status, bad transport, etc. **๐Ÿ”ง Enable/Disable** toggles a
442
+ server's `disabled` flag in its `mcp.json` (other fields preserved) and a
443
+ **๐Ÿ”„ Restart agent** button applies the change immediately. Tunable via
444
+ `MCP_PROBE_TIMEOUT_MS` / `MCP_PROBE_CONCURRENCY`.
445
+ - **๐Ÿ‘ฅ Subagent visibility** โ€” when the main agent delegates to subagents
446
+ ("crew") and goes quiet while waiting on them, the chat now **shows each
447
+ subagent starting, working and finishing** (via Grok's
448
+ `_grok.dev/subagent/list_update`), and the pinned status panel + `/status`
449
+ show a live `๐Ÿค– N running ยท M pending` summary. No more wondering why the
450
+ agent "isn't responding" mid-delegation. Toggle with `SHOW_SUBAGENTS`.
451
+ - **๐Ÿ” Subagent permission routing** โ€” when permission delegation is active
452
+ (non-trust-all mode), a permission request raised by a **subagent** is now
453
+ routed to its **parent chat** and clearly labelled (`Subagent "X" needs
454
+ approvalโ€ฆ`), instead of being auto-decided as unattended.
455
+ - **๐Ÿ”• Quiet notifications (on by default)** โ€” the bot now sends messages
456
+ **silently** (no notification sound) so streaming output and tool/status
457
+ chatter no longer buzz your phone. Only messages that **finish a turn**
458
+ (โœ… Done / โน Stopped / โŒ Error), **scheduled-task results**, and **permission
459
+ prompts** ring. Toggle with `QUIET_NOTIFICATIONS` (default `true`).
460
+ - **๐Ÿ” Session-aware permission prompts** โ€” when a permission request belongs to
461
+ a *background* session, the prompt names it ("Session X needs approvalโ€ฆ") and
462
+ adds a **๐Ÿ”€ Switch to it** button next to Allow/Deny (which approve in place,
463
+ without switching). Permission prompts always ring, even in quiet mode.
464
+
465
+ ### Fixed
466
+
467
+ - **๐Ÿงญ Session-switch project mismatch** โ€” after switching between controlled
468
+ sessions in different projects, the pinned status panel could show one
469
+ session's **project** next to another's **session id**. The panel now reads
470
+ the project from the live foreground session, and the persisted restore fields
471
+ are kept in sync on every switch, so project and session always match.
472
+ - **๐Ÿ” Duplicated output after switching to a busy session** โ€” following a busy
473
+ session's in-flight turn live and then sending a new message could echo output
474
+ twice (live stream + tail watcher). The follow-watch is now stopped when a new
475
+ turn starts streaming, and when the followed turn ends.
476
+ - **๐Ÿงท Lost session (and context) when the agent was waiting on a reply** โ€” if
477
+ the agent ended a turn asking a clarifying question and the ACP process
478
+ restarted during the pause before you answered (it runs 24/7, so transient
479
+ restarts happen), your reply could land in a **brand-new empty session**,
480
+ discarding the whole conversation. Re-binding a session now **retries** the
481
+ flaky load (the agent is usually mid-restart on the first attempt), and if the
482
+ session truly can't be reopened the bot **forks a linked continuation primed
483
+ with the recent transcript** instead of silently starting fresh โ€” and tells
484
+ you it did. Context (including the pending question) survives the restart.
485
+
486
+ ## [1.4.0] - 2026-06-21
487
+
488
+ The **"work on many sessions at once"** release โ€” drive several Grok sessions
489
+ from a single chat and switch between them, on a redesigned, compact menu.
490
+
491
+ ### Added
492
+
493
+ - **๐Ÿงญ Multi-session control & switching (`/running`)** โ€” one chat can now control
494
+ **several Grok sessions at once**. Start them with ๐Ÿ“ Project / ๐Ÿ†• New, then tap
495
+ **๐Ÿงญ Running** (or `/running`) to jump between them. Only the foreground session
496
+ streams live; the rest keep running **quietly** in the background. **Switching
497
+ to a session shows its recent context + every message that arrived while you
498
+ were away** (its "unread", recovered from the session's event log). Each entry
499
+ shows busy/unread badges, and you can close one with โœ– (it isn't killed). The
500
+ controlled set and foreground survive restarts.
501
+
502
+ ### Changed
503
+
504
+ - **๐ŸŽ› Redesigned menu โ€” compact, organized, hideable.** The bulky multi-row
505
+ reply keyboard is replaced by a tiny persistent bar (**โ˜ฐ Menu ยท ๐Ÿงญ Running ยท
506
+ โน Stop**) plus a clean, grouped **inline menu** opened on demand. The inline
507
+ menu shows the **current agent, model and reasoning** right on their buttons and
508
+ reopens after a change. Hide it with ๐Ÿ™ˆ and restore with `/menu` or โŒจ๏ธ Show bar.
509
+ All live state (project / agent / model / reasoning / context % / controlled
510
+ count) lives in the pinned status panel, keeping the input area uncluttered.
511
+
512
+ ### Verified
513
+
514
+ - Re-reviewed the transient-error auto-retry path end-to-end (error
515
+ classification, the `6s โ†’ 12s โ†’ 24s โ†’ 48s โ†’ 60s` backoff, the "only retry while
516
+ nothing has streamed" guard, and cancellable waits) โ€” confirmed logically
517
+ complete. (Shipped in 1.3.0; carried into this release.)
518
+
519
+ ## [1.3.0] - 2026-06-21
520
+
521
+ ### Added
522
+
523
+ - **๐Ÿ” Transient-error auto-retry with backoff** โ€” when the agent returns a
524
+ transient error (e.g. "high volume of traffic" / `-32603` "Internal error")
525
+ before any output has streamed, the bot retries with an exponential backoff
526
+ (`6s โ†’ 12s โ†’ 24s โ†’ 48s โ†’ 60s`) instead of failing immediately. The **real**
527
+ error is shown on every attempt, and a clear summary is sent once retries are
528
+ exhausted. Configurable via `PROMPT_RETRY_ATTEMPTS` (`0` disables; default
529
+ `5`); waits are interruptible with `/cancel`.
530
+ - **๐Ÿชช Session cards** โ€” `/sessions` and `/active` now render each session as a
531
+ rich card (status dot, project name + full path, created/updated times,
532
+ history size, context-usage %, short id) with **Resume/Continue ยท History ยท
533
+ Watch** buttons, replacing the cramped button grid.
534
+ - **๐Ÿ“– Install guide** โ€” new `docs/INSTALL.md`, linked from the README and from
535
+ every GitHub Release.
536
+
537
+ ### Changed
538
+
539
+ - ACP JSON-RPC errors now surface their **code and data** (and are logged), so
540
+ failures are diagnosable instead of an opaque "Internal error".
541
+ - The release workflow always attaches the clean source zip and appends a
542
+ **1-click install** footer (with a link to the install guide) to every
543
+ release's notes.
544
+
545
+ ## [1.2.0] - 2026-06-21
546
+
547
+ ### Added
548
+
549
+ - **๐Ÿ‘ฅ Contributors** โ€” a contrib.rocks avatar wall plus "How to Contribute" and
550
+ "Releasing a New Version" guidance in the README.
551
+ - **โญ Top Contributors** โ€” a curated table highlighting the people who shape the
552
+ project.
553
+ - **๐Ÿ“Š Stars** โ€” a live star-history chart in the README.
554
+ - **๐ŸŒ StarMapper** โ€” an interactive world map of the project's stargazers.
555
+ - **๐Ÿ“ฆ Release automation** โ€” `.github/workflows/release.yml` builds a clean,
556
+ downloadable source zip and publishes a GitHub Release on every `v*.*.*` tag,
557
+ using this CHANGELOG section as the release notes (auto-generated notes as a
558
+ fallback).
559
+ - **๐Ÿค– Agent instructions** โ€” a new `AGENTS.md` documenting the architecture,
560
+ conventions, and the batched-PR โ†’ conflict-resolve โ†’ merge โ†’ release workflow.
561
+ - **๐Ÿ“‹ Release checklist** โ€” `docs/ops/RELEASE_CHECKLIST.md` codifies the
562
+ pre-release validation steps.
563
+
564
+ ### Changed
565
+
566
+ - `CONTRIBUTING.md` now describes the feature-branch โ†’ pull-request โ†’ release
567
+ workflow and how versioned releases are cut.
568
+ - README roadmap updated to mark community/release tooling as shipped.
569
+
570
+ ## [1.1.0] - 2026-06-20
571
+
572
+ ### Added
573
+
574
+ - Inline approvals (`session/request_permission`): approve / approve-always /
575
+ deny risky tool calls from Telegram buttons.
576
+ - Account & context usage via `/usage`, plus a context-usage indicator in the
577
+ status panel.
578
+ - Voice messages transcribed to prompts (configurable STT endpoint).
579
+
580
+ ## [1.0.0] - 2026-06-20
581
+
582
+ ### Added
583
+
584
+ - Initial release: Telegram โ‡„ Grok CLI bridge over the Agent Client Protocol
585
+ (ACP) with projects, resumable and live sessions, queued follow-ups, edit
586
+ diffs, MarkdownV2 rendering, scheduled tasks, multi-image prompts, and a
587
+ cross-platform 24/7 background service.
588
+
589
+ [1.7.1]: https://github.com/artickc/grok-telegram-bot/releases/tag/v1.7.1
590
+ [1.7.0]: https://github.com/artickc/grok-telegram-bot/releases/tag/v1.7.0
591
+ [1.6.0]: https://github.com/artickc/grok-telegram-bot/releases/tag/v1.6.0
592
+ [1.5.1]: https://github.com/artickc/grok-telegram-bot/releases/tag/v1.5.1
593
+ [1.5.0]: https://github.com/artickc/grok-telegram-bot/releases/tag/v1.5.0
594
+ [1.4.0]: https://github.com/artickc/grok-telegram-bot/releases/tag/v1.4.0
595
+ [1.3.0]: https://github.com/artickc/grok-telegram-bot/releases/tag/v1.3.0
596
+ [1.2.0]: https://github.com/artickc/grok-telegram-bot/releases/tag/v1.2.0
597
+ [1.1.0]: https://github.com/artickc/grok-telegram-bot/releases/tag/v1.1.0
598
+ [1.0.0]: https://github.com/artickc/grok-telegram-bot/releases/tag/v1.0.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Grok Telegram Bot contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.