telecoder 0.0.0-stage → 1.3.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 (235) hide show
  1. package/.env.example +375 -0
  2. package/CHANGELOG.md +1867 -0
  3. package/LICENSE +22 -0
  4. package/README.md +130 -2
  5. package/dist/audio/transcribe.js +41 -0
  6. package/dist/bin/mcp-server.js +363 -0
  7. package/dist/bin/tool-result.js +22 -0
  8. package/dist/bot/access/group-access.js +147 -0
  9. package/dist/bot/bot.js +573 -0
  10. package/dist/bot/command-catalog.js +263 -0
  11. package/dist/bot/deleted-threads.js +103 -0
  12. package/dist/bot/file-access.js +150 -0
  13. package/dist/bot/handlers/album.handler.js +128 -0
  14. package/dist/bot/handlers/branch.handler.js +1096 -0
  15. package/dist/bot/handlers/command/access.js +407 -0
  16. package/dist/bot/handlers/command/admin.js +803 -0
  17. package/dist/bot/handlers/command/all-view.js +33 -0
  18. package/dist/bot/handlers/command/auto-approve.js +138 -0
  19. package/dist/bot/handlers/command/background.js +37 -0
  20. package/dist/bot/handlers/command/botname.js +76 -0
  21. package/dist/bot/handlers/command/btw.js +175 -0
  22. package/dist/bot/handlers/command/cleanup.js +329 -0
  23. package/dist/bot/handlers/command/model.js +226 -0
  24. package/dist/bot/handlers/command/prefs-scope.js +362 -0
  25. package/dist/bot/handlers/command/project.js +458 -0
  26. package/dist/bot/handlers/command/resume.js +325 -0
  27. package/dist/bot/handlers/command/session.js +299 -0
  28. package/dist/bot/handlers/command/settings.js +657 -0
  29. package/dist/bot/handlers/command/shared.js +207 -0
  30. package/dist/bot/handlers/command/tasks.js +681 -0
  31. package/dist/bot/handlers/command/thread.js +128 -0
  32. package/dist/bot/handlers/command/topic-store.js +74 -0
  33. package/dist/bot/handlers/command/topic.js +27 -0
  34. package/dist/bot/handlers/command/usage.js +382 -0
  35. package/dist/bot/handlers/command-fallback.js +179 -0
  36. package/dist/bot/handlers/command.handler.js +446 -0
  37. package/dist/bot/handlers/loop.handler.js +389 -0
  38. package/dist/bot/handlers/media-fallback.js +126 -0
  39. package/dist/bot/handlers/message/replies.js +56 -0
  40. package/dist/bot/handlers/message/shared.js +95 -0
  41. package/dist/bot/handlers/message/turn-notify.js +135 -0
  42. package/dist/bot/handlers/message/turn-runner.js +56 -0
  43. package/dist/bot/handlers/message.handler.js +114 -0
  44. package/dist/bot/handlers/newbot.handler.js +230 -0
  45. package/dist/bot/handlers/photo.handler.js +286 -0
  46. package/dist/bot/handlers/prompts.handler.js +343 -0
  47. package/dist/bot/handlers/running-note.js +44 -0
  48. package/dist/bot/handlers/session-guard.js +78 -0
  49. package/dist/bot/handlers/suggestion.handler.js +84 -0
  50. package/dist/bot/handlers/tree.handler.js +480 -0
  51. package/dist/bot/handlers/view.js +41 -0
  52. package/dist/bot/handlers/voice.handler.js +147 -0
  53. package/dist/bot/kept-threads.js +51 -0
  54. package/dist/bot/middleware/admin-only.js +49 -0
  55. package/dist/bot/middleware/album-collector.js +69 -0
  56. package/dist/bot/middleware/auth.middleware.js +122 -0
  57. package/dist/bot/middleware/group-mention.middleware.js +145 -0
  58. package/dist/bot/middleware/group-role.middleware.js +75 -0
  59. package/dist/bot/middleware/message-batcher.js +87 -0
  60. package/dist/bot/middleware/queued-messages.js +1082 -0
  61. package/dist/bot/middleware/stale-filter.js +9 -0
  62. package/dist/build-info.json +8 -0
  63. package/dist/claude/ask-user-form.js +517 -0
  64. package/dist/claude/ask-user.js +363 -0
  65. package/dist/claude/auto-approve.js +225 -0
  66. package/dist/claude/auto-topic-haiku.js +143 -0
  67. package/dist/claude/available-commands.js +156 -0
  68. package/dist/claude/background-hint.js +91 -0
  69. package/dist/claude/branch-tree.js +393 -0
  70. package/dist/claude/carry-over.js +25 -0
  71. package/dist/claude/ccr-shim.js +48 -0
  72. package/dist/claude/charter-judge.js +214 -0
  73. package/dist/claude/claude-auth.js +117 -0
  74. package/dist/claude/command-parser.js +206 -0
  75. package/dist/claude/cost-overlay-scraper.js +134 -0
  76. package/dist/claude/effort-level.js +5 -0
  77. package/dist/claude/enabled-plugins.js +52 -0
  78. package/dist/claude/in-flight-tracker.js +82 -0
  79. package/dist/claude/ipc-server.js +192 -0
  80. package/dist/claude/mcp-bridge.js +481 -0
  81. package/dist/claude/memory-guard.js +400 -0
  82. package/dist/claude/message-offsets.js +88 -0
  83. package/dist/claude/modal-relay.js +817 -0
  84. package/dist/claude/model-catalog.js +102 -0
  85. package/dist/claude/monitor-relay.js +712 -0
  86. package/dist/claude/native-commands.js +40 -0
  87. package/dist/claude/pending-branches.js +93 -0
  88. package/dist/claude/pending-suggestions.js +50 -0
  89. package/dist/claude/permission-gate.js +338 -0
  90. package/dist/claude/permission-mode.js +152 -0
  91. package/dist/claude/poll-user.js +51 -0
  92. package/dist/claude/prewarm.js +70 -0
  93. package/dist/claude/project-commands.js +69 -0
  94. package/dist/claude/prompt-hold.js +124 -0
  95. package/dist/claude/prompt-suggestion-scraper.js +89 -0
  96. package/dist/claude/pty-idle-reaper.js +96 -0
  97. package/dist/claude/pty-provider.js +2499 -0
  98. package/dist/claude/pty-spawn-config.js +343 -0
  99. package/dist/claude/pty-stream.js +363 -0
  100. package/dist/claude/pty-watch.js +201 -0
  101. package/dist/claude/request-queue.js +107 -0
  102. package/dist/claude/rewind.js +111 -0
  103. package/dist/claude/scheduled-runner.js +89 -0
  104. package/dist/claude/scheduler.js +241 -0
  105. package/dist/claude/scope-guard.js +279 -0
  106. package/dist/claude/screen-marks.js +83 -0
  107. package/dist/claude/screen-render.js +96 -0
  108. package/dist/claude/secret-request.js +576 -0
  109. package/dist/claude/session-history.js +288 -0
  110. package/dist/claude/session-jsonl.js +1067 -0
  111. package/dist/claude/session-manager.js +216 -0
  112. package/dist/claude/session-move.js +70 -0
  113. package/dist/claude/session-scan.js +270 -0
  114. package/dist/claude/setup-token.js +285 -0
  115. package/dist/claude/shell-mode-gate.js +60 -0
  116. package/dist/claude/side-call-options.js +45 -0
  117. package/dist/claude/side-question.js +252 -0
  118. package/dist/claude/stage-images.js +62 -0
  119. package/dist/claude/subagent-tools.js +12 -0
  120. package/dist/claude/synthetic-ctx.js +51 -0
  121. package/dist/claude/tasks-overlay-scraper.js +217 -0
  122. package/dist/claude/thread-judge-haiku.js +88 -0
  123. package/dist/claude/tip-scraper.js +77 -0
  124. package/dist/claude/tui-modal.js +746 -0
  125. package/dist/claude/tui-state.js +456 -0
  126. package/dist/claude/turn-end.js +105 -0
  127. package/dist/claude/turn-prose.js +64 -0
  128. package/dist/claude/typed-answer.js +104 -0
  129. package/dist/claude/update-banner-relay.js +70 -0
  130. package/dist/cli/commands/doctor.js +338 -0
  131. package/dist/cli/commands/help.js +34 -0
  132. package/dist/cli/commands/init.js +126 -0
  133. package/dist/cli/commands/service.js +710 -0
  134. package/dist/cli/commands/start.js +63 -0
  135. package/dist/cli/commands/version.js +11 -0
  136. package/dist/cli/commands/watch.js +322 -0
  137. package/dist/cli/dispatch.js +84 -0
  138. package/dist/cli/init/env-file.js +99 -0
  139. package/dist/cli/init/flow.js +705 -0
  140. package/dist/cli/init/prompter.js +124 -0
  141. package/dist/cli/init/telegram.js +120 -0
  142. package/dist/cli/service/render.js +212 -0
  143. package/dist/cli.js +18 -0
  144. package/dist/config-report.js +107 -0
  145. package/dist/config.js +525 -0
  146. package/dist/index.js +443 -0
  147. package/dist/launcher.js +960 -0
  148. package/dist/node-version-check.js +27 -0
  149. package/dist/providers/ccr-health.js +119 -0
  150. package/dist/providers/ccr-introspect.js +142 -0
  151. package/dist/providers/ccr-provider.js +59 -0
  152. package/dist/providers/claude-provider.js +10 -0
  153. package/dist/providers/prefs-sync.js +121 -0
  154. package/dist/providers/project-favorites.js +74 -0
  155. package/dist/providers/provider-router.js +128 -0
  156. package/dist/providers/provider-switch.js +91 -0
  157. package/dist/providers/spawn-settings.js +45 -0
  158. package/dist/providers/types.js +8 -0
  159. package/dist/providers/user-preferences.js +322 -0
  160. package/dist/restart-when-idle.js +173 -0
  161. package/dist/startup/auto-continue.js +67 -0
  162. package/dist/startup/auto-resume.js +161 -0
  163. package/dist/startup/notices.js +120 -0
  164. package/dist/startup/shared.js +44 -0
  165. package/dist/startup/verify-token.js +31 -0
  166. package/dist/telegram/access-request.js +153 -0
  167. package/dist/telegram/action-logger.js +522 -0
  168. package/dist/telegram/admin-mention.js +107 -0
  169. package/dist/telegram/background-activity-card.js +502 -0
  170. package/dist/telegram/botname-settings.js +282 -0
  171. package/dist/telegram/button-text.js +26 -0
  172. package/dist/telegram/client-options.js +26 -0
  173. package/dist/telegram/deduplication.js +33 -0
  174. package/dist/telegram/entities.js +295 -0
  175. package/dist/telegram/force-reply-tracker.js +96 -0
  176. package/dist/telegram/lettered-options.js +87 -0
  177. package/dist/telegram/markdown.js +362 -0
  178. package/dist/telegram/message-sender.js +1019 -0
  179. package/dist/telegram/prompt-label.js +148 -0
  180. package/dist/telegram/prompt-suggestion.js +54 -0
  181. package/dist/telegram/send.js +123 -0
  182. package/dist/telegram/streaming-turn.js +103 -0
  183. package/dist/telegram/suggestions-settings.js +30 -0
  184. package/dist/telegram/table-lists.js +56 -0
  185. package/dist/telegram/task-list.js +367 -0
  186. package/dist/telegram/task-tracker.js +128 -0
  187. package/dist/telegram/terminal-renderer.js +667 -0
  188. package/dist/telegram/thread-titles.js +262 -0
  189. package/dist/telegram/threads-setup.js +117 -0
  190. package/dist/utils/admins.js +143 -0
  191. package/dist/utils/agent-timer.js +55 -0
  192. package/dist/utils/atomic-write.js +24 -0
  193. package/dist/utils/bot-icon.js +248 -0
  194. package/dist/utils/bot-token.js +77 -0
  195. package/dist/utils/bounded-map.js +55 -0
  196. package/dist/utils/build-info.js +57 -0
  197. package/dist/utils/caffeinate.js +53 -0
  198. package/dist/utils/claude-env.js +53 -0
  199. package/dist/utils/claude-version.js +48 -0
  200. package/dist/utils/config-home.js +62 -0
  201. package/dist/utils/download.js +137 -0
  202. package/dist/utils/exit-codes.js +59 -0
  203. package/dist/utils/file-type.js +149 -0
  204. package/dist/utils/format.js +78 -0
  205. package/dist/utils/home-project.js +30 -0
  206. package/dist/utils/host-stall.js +51 -0
  207. package/dist/utils/id-list.js +44 -0
  208. package/dist/utils/idle-restart.js +92 -0
  209. package/dist/utils/install-mode.js +63 -0
  210. package/dist/utils/instance-config.js +148 -0
  211. package/dist/utils/instances.js +95 -0
  212. package/dist/utils/json-store.js +140 -0
  213. package/dist/utils/keyed-settings.js +62 -0
  214. package/dist/utils/legacy-env.js +35 -0
  215. package/dist/utils/memory-pressure.js +60 -0
  216. package/dist/utils/npm-version.js +134 -0
  217. package/dist/utils/prefs-relay.js +107 -0
  218. package/dist/utils/proc-children.js +102 -0
  219. package/dist/utils/resolve-bin.js +86 -0
  220. package/dist/utils/resolve-claude-bin.js +52 -0
  221. package/dist/utils/respawn-backoff.js +28 -0
  222. package/dist/utils/sanitize.js +91 -0
  223. package/dist/utils/session-key.js +37 -0
  224. package/dist/utils/stale-launcher.js +109 -0
  225. package/dist/utils/state-dir-migration.js +92 -0
  226. package/dist/utils/systemd.js +126 -0
  227. package/dist/utils/telegram-proxy.js +72 -0
  228. package/dist/utils/uploads-dir.js +27 -0
  229. package/dist/utils/user-roster.js +275 -0
  230. package/dist/utils/verbosity.js +118 -0
  231. package/dist/utils/version-check.js +166 -0
  232. package/dist/utils/workspace-guard.js +44 -0
  233. package/dist/worker-restart.js +141 -0
  234. package/instances.json.example +41 -0
  235. package/package.json +75 -4
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Helpers shared across the command handlers.
3
+ *
4
+ * These are the pieces that several unrelated command domains all reach for —
5
+ * the markdown reply shorthand, the callback-query preamble, the project
6
+ * status block. They live here so the domain modules depend on one small
7
+ * shared surface instead of on each other.
8
+ */
9
+ import { sessionManager } from '../../../claude/session-manager.js';
10
+ import { envFilePath } from '../../../config.js';
11
+ import { getModel, getEffort, getActiveProviderName, } from '../../../providers/provider-router.js';
12
+ import { EntityText } from '../../../telegram/entities.js';
13
+ import { replyMarkdown } from '../../../telegram/send.js';
14
+ import { fitsOnButton } from '../../../telegram/button-text.js';
15
+ import { getSessionKeyFromCtx } from '../../../utils/session-key.js';
16
+ import { formatTimeAgo } from '../../../utils/format.js';
17
+ import { PACKAGE_ROOT } from '../../../utils/install-mode.js';
18
+ /** Repo root (the package root, in an npm install). */
19
+ export const PROJECT_ROOT = PACKAGE_ROOT;
20
+ /**
21
+ * Reply with standard markdown, sent as entities. For static text only: a
22
+ * dynamic part (a path, a name, an error) goes through an {@link EntityText}
23
+ * instead, since nothing escapes it here.
24
+ */
25
+ export async function replyMd(ctx, markdown) {
26
+ await replyMarkdown(ctx, markdown);
27
+ }
28
+ /**
29
+ * Resolve the session-key info and callback-data for a callback-query handler,
30
+ * gated on the data starting with `prefix`. Returns null (so the caller can
31
+ * early-return) when there is no session key, no callback data, or the data
32
+ * doesn't match the prefix. Folds the repeated keyInfo + data guard preamble
33
+ * that every prefix-scoped callback handler shares.
34
+ */
35
+ export function parseCallback(ctx, prefix) {
36
+ const keyInfo = getSessionKeyFromCtx(ctx);
37
+ if (!keyInfo)
38
+ return null;
39
+ const data = ctx.callbackQuery?.data;
40
+ if (!data || !data.startsWith(prefix))
41
+ return null;
42
+ return { ...keyInfo, data };
43
+ }
44
+ export function buildFeatureDisabledMessage(feature) {
45
+ return `⚠️ ${feature} feature is disabled in configuration.`;
46
+ }
47
+ export async function replyFeatureDisabled(ctx, feature) {
48
+ await ctx.reply(buildFeatureDisabledMessage(feature));
49
+ }
50
+ /**
51
+ * What a voice note gets when no Groq key is set: how to turn
52
+ * transcription on, instead of a "Transcribing..." ack followed by a raw
53
+ * "GROQ_API_KEY not configured" error. Declining voice in `telecoder init` is
54
+ * the common case, so this is where most people learn how to add it later.
55
+ */
56
+ export function buildVoiceNotSetUpMessage() {
57
+ return [
58
+ '🎤 Voice transcription is off: no Groq API key is set.',
59
+ '',
60
+ 'To turn it on, get a key at https://console.groq.com/keys (Groq has a free tier), then either:',
61
+ '• run `telecoder init` again — it keeps your other answers and asks for the key, or',
62
+ `• add GROQ_API_KEY=gsk_... to ${envFilePath} and /botrestart.`,
63
+ ].join('\n');
64
+ }
65
+ export async function replyVoiceNotSetUp(ctx) {
66
+ await ctx.reply(buildVoiceNotSetUpMessage());
67
+ }
68
+ export const EFFORT_LEVELS = [
69
+ { id: 'low', label: '🐇 Low', description: 'Minimal thinking, fastest' },
70
+ { id: 'medium', label: '⚖️ Medium', description: 'Balanced speed/quality' },
71
+ { id: 'high', label: '🧠 High', description: 'Deep reasoning' },
72
+ { id: 'xhigh', label: '🔬 XHigh', description: 'Deeper than high (default on current models)' },
73
+ { id: 'max', label: '🚀 Max', description: 'Maximum effort' },
74
+ ];
75
+ /** Get the full label (e.g. "🐇 Low") for a thread's or chat's current effort level. */
76
+ export function getEffortLabel(scope) {
77
+ const effort = getEffort(scope);
78
+ if (!effort)
79
+ return undefined;
80
+ return effortLevelLabel(effort);
81
+ }
82
+ /**
83
+ * The label for an effort level by name, for the one the session log reports
84
+ * when the chat set none itself. The CLI logs the API's four levels, so
85
+ * 'xhigh' never comes from there; a level this list doesn't know is shown as
86
+ * it was logged rather than dropped.
87
+ */
88
+ export function effortLevelLabel(effort) {
89
+ return EFFORT_LEVELS.find((l) => l.id === effort)?.label
90
+ ?? `🧠 ${effort.charAt(0).toUpperCase()}${effort.slice(1)}`;
91
+ }
92
+ /** Build status lines appended to project confirmation messages. */
93
+ export function projectStatusSuffix(sessionKey) {
94
+ const model = getModel(sessionKey);
95
+ const provider = getActiveProviderName(sessionKey);
96
+ const session = sessionManager.getSession(sessionKey);
97
+ const created = session?.createdAt
98
+ ? new Date(session.createdAt).toLocaleString()
99
+ : new Date().toLocaleString();
100
+ const sessionId = session?.claudeSessionId;
101
+ const effortLabel = getEffortLabel(sessionKey) ?? 'Default';
102
+ const suffix = new EntityText()
103
+ .add('\n• ').bold('Provider:').add(` ${provider}`)
104
+ .add('\n• ').bold('Model:').add(` ${model}`)
105
+ .add('\n• ').bold('Effort:').add(` ${effortLabel}`)
106
+ .add('\n• ').bold('Created:').add(` ${created}`)
107
+ .add('\n• ').bold('Session ID:').add(' ');
108
+ if (sessionId) {
109
+ suffix.code(sessionId);
110
+ suffix.add('\n\n💡 To continue this session from the terminal, copy the command below.');
111
+ }
112
+ else {
113
+ suffix.italic('pending — send a message to start');
114
+ }
115
+ return suffix.build();
116
+ }
117
+ /** The copyable command sent as a separate message. */
118
+ export function resumeCommandMessage(sessionId) {
119
+ return new EntityText().code(`claude --resume ${sessionId}`).build();
120
+ }
121
+ /** Truncate a string to fit within `maxBytes` UTF-8 bytes without splitting a codepoint. */
122
+ export function truncateToBytes(s, maxBytes) {
123
+ if (Buffer.byteLength(s, 'utf8') <= maxBytes)
124
+ return s;
125
+ let out = '';
126
+ for (const ch of s) {
127
+ if (Buffer.byteLength(out + ch, 'utf8') > maxBytes)
128
+ break;
129
+ out += ch;
130
+ }
131
+ return out;
132
+ }
133
+ export { formatTimeAgo };
134
+ /**
135
+ * How much of a session's name a picker spells out.
136
+ *
137
+ * Nothing the model writes comes close — a topic is a handful of words — but
138
+ * `/topic` takes whatever you type, and unbounded names could push a message
139
+ * past Telegram's 4096-char ceiling, which would 400 and deliver nothing at
140
+ * all. Generous enough never to touch a real name, low enough that a full
141
+ * history can't cost the whole list.
142
+ */
143
+ const MAX_SESSION_NAME_LEN = 120;
144
+ /**
145
+ * How a session is named wherever one is offered: the project, plus the topic
146
+ * when it has one. Shared so /resume and the back button name the same
147
+ * session the same way.
148
+ */
149
+ export function sessionDisplayName(entry) {
150
+ const name = entry.topic ? `${entry.projectName} · ${entry.topic}` : entry.projectName;
151
+ return name.length > MAX_SESSION_NAME_LEN
152
+ ? name.slice(0, MAX_SESSION_NAME_LEN - 1) + '…'
153
+ : name;
154
+ }
155
+ /**
156
+ * Attach the one-tap "back to the session you just left" affordance to a
157
+ * message, reusing the /resume callback. Returns the text to send and the
158
+ * options to send it with, so the six commands that offer it don't each
159
+ * repeat the append; with no session key, or no session to go back to, that
160
+ * is the message unchanged.
161
+ *
162
+ * The session's name rides on the button while it fits, which is the whole of
163
+ * the common case — `↩️ Back to telecoder (2h ago)` is one tap and adds
164
+ * nothing to the chat. It stops fitting as soon as the session has a topic,
165
+ * and a button is not a place to put text that doesn't fit: Telegram gives the
166
+ * reader no way to expand the ellipsis, so the name was simply gone and the
167
+ * button said "back to" something you couldn't read. Past that width the
168
+ * button keeps a fixed short label and the name goes in the body, where it
169
+ * survives whole.
170
+ *
171
+ * Skips the entry whose conversationId matches `excludeConversationId` so we
172
+ * don't offer to return to the session you're already in.
173
+ */
174
+ export function withBackToPrevious(text, sessionKey, excludeConversationId) {
175
+ const plain = { text, options: {} };
176
+ if (!sessionKey)
177
+ return plain;
178
+ const history = sessionManager.getSessionHistory(sessionKey, 5);
179
+ const entry = history.find((e) => e.claudeSessionId && e.conversationId !== excludeConversationId);
180
+ if (!entry)
181
+ return plain;
182
+ const timeAgo = formatTimeAgo(new Date(entry.lastActivity));
183
+ const name = sessionDisplayName(entry);
184
+ const label = `↩️ Back to ${name} (${timeAgo})`;
185
+ const fits = fitsOnButton(label);
186
+ return {
187
+ text: fits ? text : new EntityText().append(text).add(`\n\n↩️ Previous: ${name} (${timeAgo})`).build(),
188
+ options: {
189
+ reply_markup: {
190
+ inline_keyboard: [
191
+ [
192
+ {
193
+ text: fits ? label : '↩️ Back to previous',
194
+ callback_data: `resume:${entry.conversationId}`,
195
+ },
196
+ ],
197
+ ],
198
+ },
199
+ },
200
+ };
201
+ }
202
+ /** Note appended when a pty restart is pending. */
203
+ export const PTY_RESTART_NOTE = new EntityText()
204
+ .add('\n\n')
205
+ .italic('Claude Code restarts on your next message to pick this up (the conversation is kept).')
206
+ .build();
207
+ //# sourceMappingURL=shared.js.map