telecoder 0.0.0-stage → 1.2.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 (223) hide show
  1. package/.env.example +363 -0
  2. package/CHANGELOG.md +1186 -0
  3. package/LICENSE +22 -0
  4. package/README.md +126 -2
  5. package/dist/audio/transcribe.js +50 -0
  6. package/dist/bin/mcp-server.js +378 -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 +592 -0
  10. package/dist/bot/file-access.js +141 -0
  11. package/dist/bot/handlers/command/access.js +407 -0
  12. package/dist/bot/handlers/command/admin.js +827 -0
  13. package/dist/bot/handlers/command/auto-approve.js +138 -0
  14. package/dist/bot/handlers/command/btw.js +224 -0
  15. package/dist/bot/handlers/command/cost.js +409 -0
  16. package/dist/bot/handlers/command/media.js +197 -0
  17. package/dist/bot/handlers/command/model.js +305 -0
  18. package/dist/bot/handlers/command/prefs-scope.js +197 -0
  19. package/dist/bot/handlers/command/project.js +536 -0
  20. package/dist/bot/handlers/command/resume.js +321 -0
  21. package/dist/bot/handlers/command/session.js +438 -0
  22. package/dist/bot/handlers/command/settings.js +1012 -0
  23. package/dist/bot/handlers/command/shared.js +210 -0
  24. package/dist/bot/handlers/command/streaming-mode.js +16 -0
  25. package/dist/bot/handlers/command/tasks.js +513 -0
  26. package/dist/bot/handlers/command/topic-store.js +113 -0
  27. package/dist/bot/handlers/command/topic.js +80 -0
  28. package/dist/bot/handlers/command.handler.js +772 -0
  29. package/dist/bot/handlers/fork.handler.js +1109 -0
  30. package/dist/bot/handlers/media-fallback.js +121 -0
  31. package/dist/bot/handlers/message/replies.js +133 -0
  32. package/dist/bot/handlers/message/shared.js +117 -0
  33. package/dist/bot/handlers/message/throttle.js +49 -0
  34. package/dist/bot/handlers/message/turn-notify.js +169 -0
  35. package/dist/bot/handlers/message/turn-runner.js +141 -0
  36. package/dist/bot/handlers/message.handler.js +107 -0
  37. package/dist/bot/handlers/newbot.handler.js +221 -0
  38. package/dist/bot/handlers/photo.handler.js +327 -0
  39. package/dist/bot/handlers/prompts.handler.js +343 -0
  40. package/dist/bot/handlers/running-note.js +44 -0
  41. package/dist/bot/handlers/schedule.handler.js +303 -0
  42. package/dist/bot/handlers/session-guard.js +78 -0
  43. package/dist/bot/handlers/suggestion.handler.js +84 -0
  44. package/dist/bot/handlers/tree.handler.js +480 -0
  45. package/dist/bot/handlers/view.js +41 -0
  46. package/dist/bot/handlers/voice.handler.js +209 -0
  47. package/dist/bot/middleware/admin-only.js +49 -0
  48. package/dist/bot/middleware/auth.middleware.js +122 -0
  49. package/dist/bot/middleware/group-mention.middleware.js +139 -0
  50. package/dist/bot/middleware/group-role.middleware.js +75 -0
  51. package/dist/bot/middleware/message-batcher.js +87 -0
  52. package/dist/bot/middleware/queued-messages.js +971 -0
  53. package/dist/bot/middleware/stale-filter.js +31 -0
  54. package/dist/build-info.json +8 -0
  55. package/dist/claude/agent-watchdog.js +162 -0
  56. package/dist/claude/agent.js +1458 -0
  57. package/dist/claude/ask-user.js +295 -0
  58. package/dist/claude/auto-approve.js +225 -0
  59. package/dist/claude/auto-topic-haiku.js +126 -0
  60. package/dist/claude/available-commands.js +153 -0
  61. package/dist/claude/carry-over.js +27 -0
  62. package/dist/claude/ccr-shim.js +46 -0
  63. package/dist/claude/charter-judge.js +214 -0
  64. package/dist/claude/claude-auth.js +121 -0
  65. package/dist/claude/command-parser.js +200 -0
  66. package/dist/claude/cost-overlay-scraper.js +129 -0
  67. package/dist/claude/enabled-plugins.js +56 -0
  68. package/dist/claude/fork-tree.js +393 -0
  69. package/dist/claude/held-query.js +190 -0
  70. package/dist/claude/in-flight-tracker.js +61 -0
  71. package/dist/claude/ipc-server.js +192 -0
  72. package/dist/claude/mcp-bridge.js +453 -0
  73. package/dist/claude/mcp-tools.js +354 -0
  74. package/dist/claude/message-offsets.js +88 -0
  75. package/dist/claude/modal-relay.js +450 -0
  76. package/dist/claude/model-catalog.js +85 -0
  77. package/dist/claude/monitor-relay.js +597 -0
  78. package/dist/claude/pending-forks.js +93 -0
  79. package/dist/claude/pending-suggestions.js +50 -0
  80. package/dist/claude/permission-gate.js +337 -0
  81. package/dist/claude/permission-mode.js +178 -0
  82. package/dist/claude/poll-user.js +51 -0
  83. package/dist/claude/project-commands.js +69 -0
  84. package/dist/claude/prompt-hold.js +124 -0
  85. package/dist/claude/prompt-suggestion-scraper.js +89 -0
  86. package/dist/claude/pty-provider.js +2214 -0
  87. package/dist/claude/pty-spawn-config.js +296 -0
  88. package/dist/claude/pty-stream.js +363 -0
  89. package/dist/claude/request-queue.js +135 -0
  90. package/dist/claude/scheduled-runner.js +91 -0
  91. package/dist/claude/scheduler.js +237 -0
  92. package/dist/claude/scope-guard.js +274 -0
  93. package/dist/claude/sdk-permission-gate.js +77 -0
  94. package/dist/claude/secret-request.js +576 -0
  95. package/dist/claude/session-cost.js +41 -0
  96. package/dist/claude/session-history.js +286 -0
  97. package/dist/claude/session-jsonl.js +920 -0
  98. package/dist/claude/session-manager.js +195 -0
  99. package/dist/claude/session-scan.js +270 -0
  100. package/dist/claude/setup-token.js +285 -0
  101. package/dist/claude/side-call-options.js +45 -0
  102. package/dist/claude/side-question.js +249 -0
  103. package/dist/claude/stage-images.js +62 -0
  104. package/dist/claude/subagent-tools.js +12 -0
  105. package/dist/claude/synthetic-ctx.js +51 -0
  106. package/dist/claude/system-prompt.js +162 -0
  107. package/dist/claude/tasks-overlay-scraper.js +94 -0
  108. package/dist/claude/tip-scraper.js +78 -0
  109. package/dist/claude/tui-modal.js +501 -0
  110. package/dist/claude/tui-state.js +384 -0
  111. package/dist/claude/turn-end.js +91 -0
  112. package/dist/claude/turn-prose.js +64 -0
  113. package/dist/claude/update-banner-relay.js +70 -0
  114. package/dist/cli/commands/doctor.js +305 -0
  115. package/dist/cli/commands/help.js +25 -0
  116. package/dist/cli/commands/init.js +123 -0
  117. package/dist/cli/commands/service.js +678 -0
  118. package/dist/cli/commands/start.js +53 -0
  119. package/dist/cli/commands/version.js +11 -0
  120. package/dist/cli/dispatch.js +79 -0
  121. package/dist/cli/init/env-file.js +99 -0
  122. package/dist/cli/init/flow.js +638 -0
  123. package/dist/cli/init/prompter.js +116 -0
  124. package/dist/cli/init/telegram.js +94 -0
  125. package/dist/cli/service/render.js +212 -0
  126. package/dist/cli.js +18 -0
  127. package/dist/config-report.js +107 -0
  128. package/dist/config.js +500 -0
  129. package/dist/index.js +367 -0
  130. package/dist/launcher.js +933 -0
  131. package/dist/node-version-check.js +27 -0
  132. package/dist/providers/ccr-health.js +119 -0
  133. package/dist/providers/ccr-introspect.js +149 -0
  134. package/dist/providers/ccr-provider.js +60 -0
  135. package/dist/providers/claude-provider.js +63 -0
  136. package/dist/providers/prefs-sync.js +164 -0
  137. package/dist/providers/project-favorites.js +74 -0
  138. package/dist/providers/provider-router.js +127 -0
  139. package/dist/providers/provider-switch.js +91 -0
  140. package/dist/providers/sdk-provider.js +37 -0
  141. package/dist/providers/types.js +8 -0
  142. package/dist/providers/user-preferences.js +214 -0
  143. package/dist/restart-when-idle.js +153 -0
  144. package/dist/startup/auto-continue.js +67 -0
  145. package/dist/startup/auto-resume.js +173 -0
  146. package/dist/startup/notices.js +120 -0
  147. package/dist/startup/shared.js +44 -0
  148. package/dist/startup/verify-token.js +31 -0
  149. package/dist/telegram/access-request.js +153 -0
  150. package/dist/telegram/action-logger.js +684 -0
  151. package/dist/telegram/admin-mention.js +107 -0
  152. package/dist/telegram/background-activity-card.js +502 -0
  153. package/dist/telegram/botname-settings.js +336 -0
  154. package/dist/telegram/button-text.js +26 -0
  155. package/dist/telegram/client-options.js +27 -0
  156. package/dist/telegram/deduplication.js +33 -0
  157. package/dist/telegram/entities.js +295 -0
  158. package/dist/telegram/force-reply-tracker.js +57 -0
  159. package/dist/telegram/lettered-options.js +87 -0
  160. package/dist/telegram/markdown.js +362 -0
  161. package/dist/telegram/message-sender.js +1287 -0
  162. package/dist/telegram/prompt-label.js +142 -0
  163. package/dist/telegram/prompt-suggestion.js +54 -0
  164. package/dist/telegram/send.js +123 -0
  165. package/dist/telegram/streaming-turn.js +105 -0
  166. package/dist/telegram/suggestions-settings.js +30 -0
  167. package/dist/telegram/task-list.js +367 -0
  168. package/dist/telegram/task-tracker.js +209 -0
  169. package/dist/telegram/telegraph-settings.js +31 -0
  170. package/dist/telegram/telegraph.js +453 -0
  171. package/dist/telegram/terminal-renderer.js +671 -0
  172. package/dist/telegram/terminal-settings.js +25 -0
  173. package/dist/telegram/thread-titles.js +190 -0
  174. package/dist/telegram/threads-setup.js +117 -0
  175. package/dist/tts/tts-settings.js +62 -0
  176. package/dist/tts/tts.js +245 -0
  177. package/dist/tts/voice-reply.js +78 -0
  178. package/dist/utils/admins.js +143 -0
  179. package/dist/utils/agent-timer.js +55 -0
  180. package/dist/utils/atomic-write.js +24 -0
  181. package/dist/utils/bot-token.js +74 -0
  182. package/dist/utils/bounded-map.js +55 -0
  183. package/dist/utils/build-info.js +57 -0
  184. package/dist/utils/caffeinate.js +50 -0
  185. package/dist/utils/claude-env.js +54 -0
  186. package/dist/utils/claude-version.js +48 -0
  187. package/dist/utils/config-home.js +62 -0
  188. package/dist/utils/debug-agent.js +117 -0
  189. package/dist/utils/debug-watchdog.js +121 -0
  190. package/dist/utils/download.js +111 -0
  191. package/dist/utils/exit-codes.js +48 -0
  192. package/dist/utils/file-type.js +149 -0
  193. package/dist/utils/format.js +81 -0
  194. package/dist/utils/home-project.js +30 -0
  195. package/dist/utils/host-stall.js +51 -0
  196. package/dist/utils/id-list.js +44 -0
  197. package/dist/utils/idle-restart.js +92 -0
  198. package/dist/utils/install-mode.js +63 -0
  199. package/dist/utils/instance-config.js +148 -0
  200. package/dist/utils/instances.js +95 -0
  201. package/dist/utils/json-store.js +140 -0
  202. package/dist/utils/keyed-settings.js +62 -0
  203. package/dist/utils/legacy-env.js +35 -0
  204. package/dist/utils/npm-version.js +134 -0
  205. package/dist/utils/prefs-relay.js +107 -0
  206. package/dist/utils/proc-children.js +102 -0
  207. package/dist/utils/project-data-dir.js +33 -0
  208. package/dist/utils/reasoning-summary.js +12 -0
  209. package/dist/utils/resolve-bin.js +86 -0
  210. package/dist/utils/resolve-claude-bin.js +63 -0
  211. package/dist/utils/respawn-backoff.js +19 -0
  212. package/dist/utils/sanitize.js +91 -0
  213. package/dist/utils/session-key.js +37 -0
  214. package/dist/utils/stale-launcher.js +109 -0
  215. package/dist/utils/state-dir-migration.js +92 -0
  216. package/dist/utils/systemd.js +126 -0
  217. package/dist/utils/user-roster.js +275 -0
  218. package/dist/utils/verbosity.js +118 -0
  219. package/dist/utils/version-check.js +166 -0
  220. package/dist/utils/workspace-guard.js +44 -0
  221. package/dist/worker-restart.js +141 -0
  222. package/instances.json.example +41 -0
  223. package/package.json +76 -4
@@ -0,0 +1,210 @@
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 * as fs from 'fs';
10
+ import * as path from 'path';
11
+ import { sessionManager } from '../../../claude/session-manager.js';
12
+ import { getModel, getEffort, isDangerousMode, getActiveProviderName, } from '../../../providers/provider-router.js';
13
+ import { EntityText } from '../../../telegram/entities.js';
14
+ import { replyMarkdown } from '../../../telegram/send.js';
15
+ import { fitsOnButton } from '../../../telegram/button-text.js';
16
+ import { userPreferences } from '../../../providers/user-preferences.js';
17
+ import { getPtyProvider } from '../../../providers/claude-provider.js';
18
+ import { getSessionKeyFromCtx, parseSessionKey } from '../../../utils/session-key.js';
19
+ import { formatTimeAgo } from '../../../utils/format.js';
20
+ import { PACKAGE_ROOT } from '../../../utils/install-mode.js';
21
+ /** Repo root (the package root, in an npm install). */
22
+ export const PROJECT_ROOT = PACKAGE_ROOT;
23
+ export const BOTCTL_PATH = path.join(PROJECT_ROOT, 'scripts', 'telecoder-botctl.sh');
24
+ export function botctlExists() {
25
+ return fs.existsSync(BOTCTL_PATH);
26
+ }
27
+ /**
28
+ * Reply with standard markdown, sent as entities. For static text only: a
29
+ * dynamic part (a path, a name, an error) goes through an {@link EntityText}
30
+ * instead, since nothing escapes it here.
31
+ */
32
+ export async function replyMd(ctx, markdown) {
33
+ await replyMarkdown(ctx, markdown);
34
+ }
35
+ /**
36
+ * Resolve the session-key info and callback-data for a callback-query handler,
37
+ * gated on the data starting with `prefix`. Returns null (so the caller can
38
+ * early-return) when there is no session key, no callback data, or the data
39
+ * doesn't match the prefix. Folds the repeated keyInfo + data guard preamble
40
+ * that every prefix-scoped callback handler shares.
41
+ */
42
+ export function parseCallback(ctx, prefix) {
43
+ const keyInfo = getSessionKeyFromCtx(ctx);
44
+ if (!keyInfo)
45
+ return null;
46
+ const data = ctx.callbackQuery?.data;
47
+ if (!data || !data.startsWith(prefix))
48
+ return null;
49
+ return { ...keyInfo, data };
50
+ }
51
+ export function buildFeatureDisabledMessage(feature) {
52
+ return `⚠️ ${feature} feature is disabled in configuration.`;
53
+ }
54
+ export async function replyFeatureDisabled(ctx, feature) {
55
+ await ctx.reply(buildFeatureDisabledMessage(feature));
56
+ }
57
+ export const EFFORT_LEVELS = [
58
+ { id: 'low', label: '🐇 Low', description: 'Minimal thinking, fastest' },
59
+ { id: 'medium', label: '⚖️ Medium', description: 'Balanced speed/quality' },
60
+ { id: 'high', label: '🧠 High', description: 'Deep reasoning' },
61
+ { id: 'xhigh', label: '🔬 XHigh', description: 'Deeper than high (default on current models)' },
62
+ { id: 'max', label: '🚀 Max', description: 'Maximum effort' },
63
+ ];
64
+ /** Get the full label (e.g. "🐇 Low") for a thread's or chat's current effort level. */
65
+ export function getEffortLabel(scope) {
66
+ const effort = getEffort(scope);
67
+ if (!effort)
68
+ return undefined;
69
+ return EFFORT_LEVELS.find((l) => l.id === effort)?.label;
70
+ }
71
+ /** Build status lines appended to project confirmation messages. */
72
+ export function projectStatusSuffix(sessionKey) {
73
+ const { chatId } = parseSessionKey(sessionKey);
74
+ const model = getModel(sessionKey);
75
+ const provider = getActiveProviderName(sessionKey);
76
+ const dangerous = isDangerousMode() ? '⚠️ ENABLED' : 'Disabled';
77
+ const session = sessionManager.getSession(sessionKey);
78
+ const created = session?.createdAt
79
+ ? new Date(session.createdAt).toLocaleString()
80
+ : new Date().toLocaleString();
81
+ const sessionId = session?.claudeSessionId;
82
+ const effortLabel = getEffortLabel(sessionKey) ?? 'Default';
83
+ const suffix = new EntityText()
84
+ .add('\n• ').bold('Provider:').add(` ${provider}`)
85
+ .add('\n• ').bold('Model:').add(` ${model}`)
86
+ .add('\n• ').bold('Effort:').add(` ${effortLabel}`)
87
+ .add('\n• ').bold('Created:').add(` ${created}`)
88
+ .add('\n• ').bold('Dangerous Mode:').add(` ${dangerous}`)
89
+ .add('\n• ').bold('Session ID:').add(' ');
90
+ if (sessionId) {
91
+ suffix.code(sessionId);
92
+ suffix.add('\n\n💡 To continue this session from the terminal, copy the command below.');
93
+ }
94
+ else {
95
+ suffix.italic('pending — send a message to start');
96
+ }
97
+ return suffix.build();
98
+ }
99
+ /** The copyable command sent as a separate message. */
100
+ export function resumeCommandMessage(sessionId) {
101
+ return new EntityText().code(`claude --resume ${sessionId}`).build();
102
+ }
103
+ /** Truncate a string to fit within `maxBytes` UTF-8 bytes without splitting a codepoint. */
104
+ export function truncateToBytes(s, maxBytes) {
105
+ if (Buffer.byteLength(s, 'utf8') <= maxBytes)
106
+ return s;
107
+ let out = '';
108
+ for (const ch of s) {
109
+ if (Buffer.byteLength(out + ch, 'utf8') > maxBytes)
110
+ break;
111
+ out += ch;
112
+ }
113
+ return out;
114
+ }
115
+ export { formatTimeAgo };
116
+ /**
117
+ * How much of a session's name a picker spells out.
118
+ *
119
+ * Nothing the model writes comes close — a topic is a handful of words — but
120
+ * `/topic` takes whatever you type, and unbounded names could push a message
121
+ * past Telegram's 4096-char ceiling, which would 400 and deliver nothing at
122
+ * all. Generous enough never to touch a real name, low enough that a full
123
+ * history can't cost the whole list.
124
+ */
125
+ const MAX_SESSION_NAME_LEN = 120;
126
+ /**
127
+ * How a session is named wherever one is offered: the project, plus the topic
128
+ * when it has one. Shared so /resume and the back button name the same
129
+ * session the same way.
130
+ */
131
+ export function sessionDisplayName(entry) {
132
+ const name = entry.topic ? `${entry.projectName} · ${entry.topic}` : entry.projectName;
133
+ return name.length > MAX_SESSION_NAME_LEN
134
+ ? name.slice(0, MAX_SESSION_NAME_LEN - 1) + '…'
135
+ : name;
136
+ }
137
+ /**
138
+ * Attach the one-tap "back to the session you just left" affordance to a
139
+ * message, reusing the /resume callback. Returns the text to send and the
140
+ * options to send it with, so the six commands that offer it don't each
141
+ * repeat the append; with no session key, or no session to go back to, that
142
+ * is the message unchanged.
143
+ *
144
+ * The session's name rides on the button while it fits, which is the whole of
145
+ * the common case — `↩️ Back to telecoder (2h ago)` is one tap and adds
146
+ * nothing to the chat. It stops fitting as soon as the session has a topic,
147
+ * and a button is not a place to put text that doesn't fit: Telegram gives the
148
+ * reader no way to expand the ellipsis, so the name was simply gone and the
149
+ * button said "back to" something you couldn't read. Past that width the
150
+ * button keeps a fixed short label and the name goes in the body, where it
151
+ * survives whole.
152
+ *
153
+ * Skips the entry whose conversationId matches `excludeConversationId` so we
154
+ * don't offer to return to the session you're already in.
155
+ */
156
+ export function withBackToPrevious(text, sessionKey, excludeConversationId) {
157
+ const plain = { text, options: {} };
158
+ if (!sessionKey)
159
+ return plain;
160
+ const history = sessionManager.getSessionHistory(sessionKey, 5);
161
+ const entry = history.find((e) => e.claudeSessionId && e.conversationId !== excludeConversationId);
162
+ if (!entry)
163
+ return plain;
164
+ const timeAgo = formatTimeAgo(new Date(entry.lastActivity));
165
+ const name = sessionDisplayName(entry);
166
+ const label = `↩️ Back to ${name} (${timeAgo})`;
167
+ const fits = fitsOnButton(label);
168
+ return {
169
+ text: fits ? text : new EntityText().append(text).add(`\n\n↩️ Previous: ${name} (${timeAgo})`).build(),
170
+ options: {
171
+ reply_markup: {
172
+ inline_keyboard: [
173
+ [
174
+ {
175
+ text: fits ? label : '↩️ Back to previous',
176
+ callback_data: `resume:${entry.conversationId}`,
177
+ },
178
+ ],
179
+ ],
180
+ },
181
+ },
182
+ };
183
+ }
184
+ /**
185
+ * Settings that are read at PTY spawn time only take effect on a fresh spawn.
186
+ * Clearing the conversation makes the next message respawn with the new value,
187
+ * keeping the conversation itself intact. No-op for non-PTY providers.
188
+ */
189
+ export function restartPtyForSettingChange(sessionKey) {
190
+ if (!needsPtyRestart(sessionKey))
191
+ return false;
192
+ getPtyProvider().clearConversation(sessionKey);
193
+ return true;
194
+ }
195
+ /**
196
+ * Whether a spawn-time setting change would need a pty restart here —
197
+ * the same test restartPtyForSettingChange makes, without doing it. For
198
+ * rebuilding a confirmation whose restart already happened.
199
+ */
200
+ export function needsPtyRestart(scope) {
201
+ if (getActiveProviderName(scope) !== 'claude')
202
+ return false;
203
+ return userPreferences.getMethod(scope) === 'pty';
204
+ }
205
+ /** Note appended when a pty restart is pending. */
206
+ export const PTY_RESTART_NOTE = new EntityText()
207
+ .add('\n\n')
208
+ .italic('Claude Code restarts on your next message to pick this up (the conversation is kept).')
209
+ .build();
210
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Runtime override for the streaming/wait response mode.
3
+ *
4
+ * Its own module because it is process-global state read from several command
5
+ * domains and from message.handler — keeping it in any one domain module would
6
+ * make the others import that domain just to read a boolean.
7
+ */
8
+ import { config } from '../../../config.js';
9
+ let runtimeStreamingMode = config.STREAMING_MODE;
10
+ export function getStreamingMode() {
11
+ return runtimeStreamingMode;
12
+ }
13
+ export function setStreamingMode(mode) {
14
+ runtimeStreamingMode = mode;
15
+ }
16
+ //# sourceMappingURL=streaming-mode.js.map