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/.env.example ADDED
@@ -0,0 +1,135 @@
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # Grok Telegram Bot — configuration
3
+ # Copy this file to .env and fill in the values, or run: npm run setup
4
+ # ─────────────────────────────────────────────────────────────────────────────
5
+
6
+ # REQUIRED — Telegram bot token from @BotFather (https://t.me/BotFather)
7
+ TELEGRAM_BOT_TOKEN=
8
+
9
+ # RECOMMENDED — comma-separated Telegram user IDs allowed to use the bot.
10
+ # Get yours from @userinfobot. If empty, ANYONE can use the bot (unsafe).
11
+ ALLOWED_USERS=
12
+
13
+ # ── Grok Build CLI ───────────────────────────────────────────────────────────
14
+ # Path to the `grok` binary. Leave blank to use "grok" from PATH.
15
+ # The official installer puts it in ~/.grok/bin/grok (install with:
16
+ # curl -fsSL https://x.ai/cli/install.sh | bash — needs SuperGrok / X Premium+)
17
+ GROK_CLI_PATH=
18
+
19
+ # Auth: sign in with your xAI account by running `grok login` once (or use the
20
+ # bot's /reauth). No API key needed. On a headless host with no browser, you can
21
+ # instead set an xAI API key here (exported to the agent as XAI_API_KEY):
22
+ # XAI_API_KEY=
23
+
24
+ # Default model that powers Grok Build.
25
+ GROK_MODEL=grok-4.5
26
+
27
+ # Default workspace directory used when you start without picking a project.
28
+ GROK_WORKSPACE=
29
+
30
+ # Pass --always-approve to `grok agent stdio` so tool calls run without inline
31
+ # permission prompts. Set false to get Approve/Deny buttons in Telegram before
32
+ # Grok runs risky tools (file writes, shell commands) — ACP "ask" mode.
33
+ GROK_TRUST_ALL_TOOLS=true
34
+
35
+ # Comma-separated roots the /projects browser is allowed to list.
36
+ # Supports ~ for home directory. Defaults to GROK_WORKSPACE's parent + home.
37
+ # Example: H:\Lucru\Domains,C:\Lucru\Domains
38
+ PROJECT_ROOTS=
39
+
40
+ # Where the bot stores the sessions it drives (<id>.json/.jsonl/.lock). Defaults
41
+ # to <data>/sessions. Grok itself keeps sessions in its own SQLite store.
42
+ # SESSIONS_DIR=
43
+
44
+ # ── Rendering / streaming ────────────────────────────────────────────────────
45
+ # How often (ms) to edit the streaming message while the agent is typing.
46
+ STREAM_THROTTLE_MS=1500
47
+
48
+ # Coalesce rapid consecutive text messages (a long message Telegram split at
49
+ # 4096 chars) into one prompt. 0 = disable.
50
+ MESSAGE_BATCH_MS=800
51
+
52
+ # Show tool-call status messages (file reads/writes, commands). true/false
53
+ SHOW_TOOL_CALLS=true
54
+
55
+ # Show unified diffs for file edits. true/false
56
+ SHOW_EDIT_DIFFS=true
57
+
58
+ # Max lines of a diff to show inline before truncating.
59
+ DIFF_MAX_LINES=120
60
+
61
+ # Send images the agent produces this turn back to Telegram automatically, and
62
+ # a per-turn cap.
63
+ SEND_AGENT_IMAGES=true
64
+ AGENT_IMAGES_MAX=8
65
+
66
+ # Max characters of a text file attachment inlined into the prompt (0 = unlimited).
67
+ DOC_MAX_CHARS=100000
68
+
69
+ # Show sub-agent activity while the main agent waits on its sub-agents (Grok
70
+ # delegates larger tasks to parallel sub-agents). true/false
71
+ SHOW_SUBAGENTS=true
72
+
73
+ # Task-progress bar. SHOW_PROGRESS asks the agent to end each message with a
74
+ # {progress: N%} marker (hidden and rendered as a green 0–100% bar). PROGRESS_FALLBACK
75
+ # shows a bot-computed bar from real activity when the model emits no marker.
76
+ SHOW_PROGRESS=true
77
+ PROGRESS_FALLBACK=true
78
+
79
+ # Deliver a background session's "Done" summary even while you're viewing another
80
+ # session (marked "From other session"). true/false
81
+ NOTIFY_OTHER_SESSIONS=true
82
+
83
+ # ── MCP servers (/mcp) ───────────────────────────────────────────────────────
84
+ # /mcp lists MCP servers the bot can discover and health-checks them. Grok Build
85
+ # manages its own MCP servers via `grok`'s /mcps modal and ~/.grok/config.toml,
86
+ # so configure them there; the bot's /mcp view is best-effort.
87
+ # MCP_PROBE_TIMEOUT_MS=8000
88
+ # MCP_PROBE_CONCURRENCY=6
89
+
90
+ # Auto-update (default on): hourly npm check; when a newer version exists AND the
91
+ # bot is idle, it updates + restarts and posts the release notes. Global npm only.
92
+ AUTO_UPDATE=true
93
+ # UPDATE_CHECK_MS=3600000
94
+
95
+ # Log level: debug | info | warn | error
96
+ LOG_LEVEL=info
97
+
98
+ # ── Daemon / background service ──────────────────────────────────────────────
99
+ # Emit a re-bind signal after /reauth / account switch (there is no persistent
100
+ # daemon with Grok; each turn spawns `grok`). true/false
101
+ GROK_AUTO_RESTART=true
102
+
103
+ # Quiet mode: send messages silently except turn completions, task results, and
104
+ # permission prompts. true/false
105
+ QUIET_NOTIFICATIONS=true
106
+
107
+ # Give up on a turn only after this many ms with NO streaming activity.
108
+ # PROMPT_IDLE_TIMEOUT_MS=900000
109
+
110
+ # Auto-retry a turn up to N times on a transient error before any output streamed
111
+ # (6s, 12s, 24s, 48s, capped 60s). 0 = off.
112
+ # PROMPT_RETRY_ATTEMPTS=5
113
+
114
+ # When retries are exhausted on a transient error (nothing streamed), fork the
115
+ # session into a fresh primed continuation and retry once. true/false
116
+ # AUTO_FORK_ON_ERROR=true
117
+
118
+ # Fork immediately (skip backoff) when a turn fails transiently AND context usage
119
+ # is at/above this %. Requires AUTO_FORK_ON_ERROR. 0 disables. Default 85.
120
+ # AUTO_FORK_CONTEXT_PCT=85
121
+
122
+ # When a transient error hits AFTER streaming started, ask the SAME session to
123
+ # continue instead of re-running tools. true/false
124
+ # RESUME_ON_STREAM_ERROR=true
125
+
126
+ # Where to write the log file. Defaults to <project>/logs/grok-telegram-bot.log
127
+ # LOG_DIR=
128
+ # LOG_FILE=
129
+
130
+ # ── Voice messages (speech-to-text) ──────────────────────────────────────────
131
+ # Any OpenAI/Whisper-compatible transcription endpoint. xAI offers one too:
132
+ # STT_API_URL=https://api.x.ai/v1
133
+ # STT_API_KEY=
134
+ # STT_MODEL=whisper-1
135
+ # STT_LANGUAGE=