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,124 @@
1
+ /**
2
+ * Holding a guest's message until an admin has looked at it.
3
+ *
4
+ * The permission gate stops a *tool call* that is already underway. This stops
5
+ * the message that would start one — before the agent reads it, before it
6
+ * touches a file, and while the request is still a sentence a person can read
7
+ * and judge. That is the difference between supervising a machine and reviewing
8
+ * a diff after the fact.
9
+ *
10
+ * Two things ask for a hold: the charter judge (src/claude/charter-judge.ts),
11
+ * which reads the message, and nothing else yet. It lives in its own module
12
+ * because the approval UI is shared with the gate and neither should own the
13
+ * other.
14
+ */
15
+ import { config } from '../config.js';
16
+ import { closeExpiredQuestion, createPendingQuestion } from './ask-user.js';
17
+ import { parseSessionKey } from '../utils/session-key.js';
18
+ import { getPromptResponderIds, isAdmin } from '../utils/admins.js';
19
+ import { EntityText, clip } from '../telegram/entities.js';
20
+ import { resolveApproversInChat, appendApproverLine } from '../telegram/admin-mention.js';
21
+ import { isCharterJudgeEnabled, judgeMessage } from './charter-judge.js';
22
+ /** Longest excerpt of the held message we quote back into the prompt. */
23
+ const MAX_QUOTE_CHARS = 500;
24
+ const PROCEED = { proceed: true, message: '' };
25
+ function holdTimeoutMs() {
26
+ const minutes = config.PERMISSION_PROMPT_TIMEOUT_MINUTES;
27
+ return (Number.isFinite(minutes) && minutes > 0 ? minutes : 10) * 60 * 1000;
28
+ }
29
+ /**
30
+ * Run a guest's message past the charter judge, and hold it for an admin if the
31
+ * judge flags it.
32
+ *
33
+ * Admins skip the judge: a message that would only ever be held for the person
34
+ * who sent it costs a Haiku call and a button tap to arrive back where it
35
+ * started. Everything else — the scope guard and the destructive-pattern gate —
36
+ * still applies to them, because those catch what a turn *does* rather than
37
+ * what it was asked to do.
38
+ */
39
+ export async function screenPrompt(ctx, sessionKey, message) {
40
+ if (!isCharterJudgeEnabled())
41
+ return PROCEED;
42
+ if (!ctx?.chat?.id)
43
+ return PROCEED;
44
+ if (isAdmin(ctx.from?.id))
45
+ return PROCEED;
46
+ const verdict = await judgeMessage(message);
47
+ if (!verdict.hold)
48
+ return PROCEED;
49
+ console.log(`[PromptHold] held session:${sessionKey} user:${ctx.from?.id ?? '?'} — ${verdict.reason}`);
50
+ return askApprovers(ctx, sessionKey, message, verdict.reason);
51
+ }
52
+ /**
53
+ * Post the approval prompt and wait. Returns once an admin or an eligible
54
+ * approver decides, or once the timeout does it for them.
55
+ */
56
+ async function askApprovers(ctx, sessionKey, message, reason) {
57
+ const { chatId, threadId } = parseSessionKey(sessionKey);
58
+ // Admins, plus any approver who is not the person who sent the held message.
59
+ const responderIds = getPromptResponderIds(ctx.from?.id);
60
+ const responders = await resolveApproversInChat(ctx.api, chatId, responderIds);
61
+ const timeoutMs = holdTimeoutMs();
62
+ const optionLabels = ['✅ Let it run', '❌ Block'];
63
+ const { id, promise } = createPendingQuestion(optionLabels, timeoutMs, sessionKey, responderIds);
64
+ const requester = describeRequester(ctx);
65
+ const { text, entities } = buildHoldMessage({
66
+ reason,
67
+ requester,
68
+ message,
69
+ responders,
70
+ timeoutMinutes: Math.round(timeoutMs / 60000),
71
+ });
72
+ const threadOpts = threadId !== undefined ? { message_thread_id: threadId } : {};
73
+ const keyboard = optionLabels.map((label, idx) => [{ text: label, callback_data: `q:${id}:${idx}` }]);
74
+ let sent;
75
+ try {
76
+ sent = await ctx.api.sendMessage(chatId, text, {
77
+ entities,
78
+ reply_markup: { inline_keyboard: keyboard },
79
+ ...threadOpts,
80
+ });
81
+ }
82
+ catch (err) {
83
+ console.error('[PromptHold] failed to post hold prompt:', err instanceof Error ? err.message : err);
84
+ // Nobody can approve a prompt that was never delivered. Blocking is the
85
+ // only honest outcome, and the reason says why.
86
+ return {
87
+ proceed: false,
88
+ message: '🚧 This message was held for approval, but the prompt could not be posted. Nothing ran.',
89
+ };
90
+ }
91
+ const answer = await promise;
92
+ if (answer === null) {
93
+ await closeExpiredQuestion(ctx.api, sent, text, `No answer within ${Math.round(timeoutMs / 60000)} min, so nothing ran.`, entities);
94
+ }
95
+ if (!answer || answer.index === 1) {
96
+ return {
97
+ proceed: false,
98
+ message: answer === null
99
+ ? `🚧 Held for approval — ${reason}. Nobody answered in ${Math.round(timeoutMs / 60000)} min, so nothing ran.`
100
+ : `🚧 Blocked — ${reason}. Nothing ran.`,
101
+ };
102
+ }
103
+ return PROCEED;
104
+ }
105
+ /** Lay out the hold prompt. Exported for tests — the wording is the product. */
106
+ export function buildHoldMessage(parts) {
107
+ const b = new EntityText();
108
+ b.add('🚧 ').bold('Held for approval').add(` — ${parts.reason}`).newline();
109
+ if (parts.requester)
110
+ b.add('Asked by ').bold(parts.requester).newline();
111
+ b.newline();
112
+ b.pre(clip(parts.message.trim(), MAX_QUOTE_CHARS));
113
+ b.newline();
114
+ appendApproverLine(b, parts.responders);
115
+ b.newline().italic(`Nothing runs until then. Times out in ${parts.timeoutMinutes} min → blocked.`);
116
+ return b.build();
117
+ }
118
+ function describeRequester(ctx) {
119
+ const from = ctx.from;
120
+ if (!from)
121
+ return undefined;
122
+ return [from.first_name, from.last_name].filter(Boolean).join(' ') || from.username || undefined;
123
+ }
124
+ //# sourceMappingURL=prompt-hold.js.map
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Scrape Claude Code's "prompt suggestion" ghost text from the rendered
3
+ * xterm buffer.
4
+ *
5
+ * When `CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=1` is set at spawn time (and
6
+ * Anthropic's growthbook flag for it is on for the account), Claude Code
7
+ * generates a speculative next-prompt after each turn and renders it as
8
+ * ghost text inside the input box. The user would press Tab to accept; we
9
+ * scrape it and offer it as an inline button instead.
10
+ *
11
+ * Detection approach:
12
+ * The live input box always renders as three consecutive rows:
13
+ * ─────────────── (top border, U+2500 run)
14
+ * ❯ <content> (prompt row, may be empty / have a suggestion)
15
+ * ─────────────── (bottom border)
16
+ * Walking bottom-up for that signature uniquely identifies the live box
17
+ * (vs. earlier `❯ ` rows belonging to submitted prompts that have
18
+ * scrolled into the conversation history).
19
+ *
20
+ * Within the prompt row, anything past col 2 is either user-typed input,
21
+ * the suggestion ghost text, or claude's deterministic placeholder
22
+ * ("Try \"how does X work?\""). We rely on the fact that we just finished
23
+ * a turn (so the user hasn't typed anything yet) and filter out the
24
+ * placeholder by prefix.
25
+ *
26
+ * Styling-based detection (dim/inverse flags) was tried first but proved
27
+ * unreliable — the flags are present at the moment the suggestion is
28
+ * written but can be cleared by subsequent attribute resets before the
29
+ * scrape window.
30
+ */
31
+ const PLACEHOLDER_PREFIXES = ['Try '];
32
+ // U+2500 BOX DRAWINGS LIGHT HORIZONTAL — Claude Code uses this run for the
33
+ // input box top/bottom borders.
34
+ const BORDER_CHAR = '─';
35
+ function isBorderRow(line) {
36
+ // The border is a long run of U+2500; check the first ~10 cells.
37
+ for (let c = 0; c < Math.min(10, line.length); c++) {
38
+ const cell = line.getCell(c);
39
+ if (!cell)
40
+ return false;
41
+ if (cell.getChars() !== BORDER_CHAR)
42
+ return false;
43
+ }
44
+ return true;
45
+ }
46
+ function readPromptRowText(line) {
47
+ let text = '';
48
+ for (let c = 2; c < line.length; c++) {
49
+ const cell = line.getCell(c);
50
+ if (!cell)
51
+ break;
52
+ const ch = cell.getChars();
53
+ text += ch === '' || ch == null ? ' ' : ch;
54
+ }
55
+ return text.replace(/\s+$/u, '');
56
+ }
57
+ /**
58
+ * Return the ghost-text prompt suggestion currently rendered in the input
59
+ * box, or null when none is present (input is empty, user is mid-typing, or
60
+ * what's shown is the deterministic placeholder).
61
+ */
62
+ export function scrapePromptSuggestion(xterm) {
63
+ const buf = xterm.buffer.active;
64
+ for (let i = buf.length - 1; i >= 1; i--) {
65
+ const line = buf.getLine(i);
66
+ if (!line)
67
+ continue;
68
+ const cell0 = line.getCell(0);
69
+ if (!cell0 || cell0.getChars() !== '❯')
70
+ continue;
71
+ // The live input box sits between two U+2500 border rows. Earlier `❯ `
72
+ // rows in the conversation history (submitted prompts) won't satisfy
73
+ // this — they're bare lines with no surrounding borders.
74
+ const above = buf.getLine(i - 1);
75
+ const below = buf.getLine(i + 1);
76
+ if (!above || !below)
77
+ continue;
78
+ if (!isBorderRow(above) || !isBorderRow(below))
79
+ continue;
80
+ const text = readPromptRowText(line);
81
+ if (!text)
82
+ return null;
83
+ if (PLACEHOLDER_PREFIXES.some((p) => text.startsWith(p)))
84
+ return null;
85
+ return text;
86
+ }
87
+ return null;
88
+ }
89
+ //# sourceMappingURL=prompt-suggestion-scraper.js.map