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,51 @@
1
+ import { parseSessionKey } from '../utils/session-key.js';
2
+ export function buildSyntheticCtx({ api, sessionKey, syntheticText }) {
3
+ const { chatId, threadId } = parseSessionKey(sessionKey);
4
+ const threadOpts = threadId !== undefined ? { message_thread_id: threadId } : {};
5
+ // The `message` field mostly matters because `getSessionKeyFromCtx` reads
6
+ // `is_topic_message` + `message_thread_id` off it. We supply the minimum
7
+ // shape so threaded chats route scheduled posts back into the right topic.
8
+ const message = {
9
+ message_id: 0,
10
+ date: Math.floor(Date.now() / 1000),
11
+ text: syntheticText,
12
+ is_topic_message: threadId !== undefined,
13
+ message_thread_id: threadId,
14
+ chat: { id: chatId, type: 'private' },
15
+ from: { id: chatId, is_bot: false, first_name: 'scheduler' },
16
+ };
17
+ const ctx = {
18
+ api,
19
+ chat: { id: chatId, type: threadId !== undefined ? 'supergroup' : 'private' },
20
+ from: { id: chatId, is_bot: false, first_name: 'scheduler', username: 'scheduler' },
21
+ message,
22
+ callbackQuery: undefined,
23
+ me: undefined,
24
+ update: { update_id: 0, message },
25
+ async reply(text, opts = {}) {
26
+ return api.sendMessage(chatId, text, { ...threadOpts, ...opts });
27
+ },
28
+ async replyWithDocument(file, opts = {}) {
29
+ // Casts mirror Grammy's API which accepts the same union as InputFile.
30
+ return api.sendDocument(chatId, file, { ...threadOpts, ...opts });
31
+ },
32
+ async replyWithPhoto(file, opts = {}) {
33
+ return api.sendPhoto(chatId, file, { ...threadOpts, ...opts });
34
+ },
35
+ async replyWithVideo(file, opts = {}) {
36
+ return api.sendVideo(chatId, file, { ...threadOpts, ...opts });
37
+ },
38
+ async replyWithAudio(file, opts = {}) {
39
+ return api.sendAudio(chatId, file, { ...threadOpts, ...opts });
40
+ },
41
+ async replyWithVoice(file, opts = {}) {
42
+ return api.sendVoice(chatId, file, { ...threadOpts, ...opts });
43
+ },
44
+ };
45
+ // `as unknown as Context` is the contract: we promise the downstream
46
+ // pipeline only reads the methods/fields above. If a new code path starts
47
+ // touching different ctx surface, it'll surface immediately as a runtime
48
+ // error here rather than silently doing the wrong thing.
49
+ return ctx;
50
+ }
51
+ //# sourceMappingURL=synthetic-ctx.js.map
@@ -0,0 +1,162 @@
1
+ /**
2
+ * The SDK provider's system prompt.
3
+ *
4
+ * Pure prompt text — the guidelines, the Telegram formatting rules, and the
5
+ * per-tool usage notes that are conditionally included based on which
6
+ * features are enabled. Separated from agent.ts so the runtime logic there
7
+ * isn't 200 lines of prose, and so prompt edits show up as prompt-only diffs.
8
+ *
9
+ * Note this is the SDK side only. PTY mode gets its tool guidance from
10
+ * buildMcpToolsSystemPromptNote() in pty-spawn-config.ts, which describes the
11
+ * larger tool set that src/bin/mcp-server.ts registers.
12
+ */
13
+ import { config } from '../config.js';
14
+ const CORE_GUIDELINES = `You are ${config.BOT_NAME}, an AI assistant helping via Telegram.
15
+
16
+ Guidelines:
17
+ - Show relevant code snippets when helpful, but keep them short
18
+ - If a task requires multiple steps, execute them and summarize what you did
19
+ - When you can't do something, explain why briefly`;
20
+ const TELEGRAPH_FORMATTING = `
21
+
22
+ Response Formatting — Telegraph-Aware Writing:
23
+ Write standard markdown. Telegram shows it formatted, chunked across messages when long.
24
+ Responses over 2500 chars are ALSO published as a Telegraph (telegra.ph) Instant View page,
25
+ linked under the reply — the same text, in a second place, so both renderings have to work.
26
+ You MUST write with Telegraph's rendering constraints in mind at all times.
27
+
28
+ Telegraph supports ONLY these elements:
29
+ - Headings: h3 (from # and ##) and h4 (from ### and ####). No h1, h2, h5, h6.
30
+ - Text formatting: **bold**, *italic*, ~~strikethrough~~, \`inline code\`
31
+ - Links: [text](url)
32
+ - Lists: unordered (- item) and ordered (1. item). Nested lists are supported (indent sub-items).
33
+ - Code blocks: \`\`\`code\`\`\` — rendered as monospace preformatted text. No syntax highlighting.
34
+ - Blockquotes: > text
35
+ - Horizontal rules: ---
36
+
37
+ Telegraph does NOT support:
38
+ - TABLES — pipe-delimited markdown tables (|col|col|) will NOT render as tables. They break into ugly labeled text. NEVER use markdown tables.
39
+ - No checkboxes, footnotes, or task lists
40
+ - No custom colors, fonts, or inline styles
41
+ - Only two heading levels (h3, h4)
42
+
43
+ Instead of tables, use these alternatives (in order of preference):
44
+ 1. Bullet lists with bold labels — best for key-value data or comparisons:
45
+ - **Name**: Alice
46
+ - **Age**: 30
47
+ - **City**: NYC
48
+
49
+ 2. Nested lists — best for grouped/categorized data:
50
+ - **Frontend**
51
+ - React 18
52
+ - TypeScript
53
+ - **Backend**
54
+ - Node.js
55
+ - Express
56
+
57
+ 3. Bold headers with list items — best for feature/comparison matrices:
58
+ **Telegram bot** — Grammy v1.31
59
+ **AI agent** — Claude Code SDK v1.0
60
+ **TTS** — OpenAI gpt-4o-mini-tts
61
+
62
+ 4. Preformatted code blocks — ONLY for data where alignment matters (ASCII tables):
63
+ \`\`\`
64
+ Name Age City
65
+ Alice 30 NYC
66
+ Bob 25 London
67
+ \`\`\`
68
+ Note: code blocks lose all formatting (no bold, links, etc.) so only use when alignment is critical.
69
+
70
+ Structure guidelines for long responses:
71
+ - Use ## or ### headings to create clear sections (renders as h3/h4)
72
+ - Use --- horizontal rules to separate major sections
73
+ - Use bullet lists liberally — they render cleanly
74
+ - Use > blockquotes for callouts, warnings, or important notes
75
+ - Keep paragraphs concise; Telegraph renders best with short blocks of text
76
+ - Nest sub-items under list items for tree-like structures instead of indented text`;
77
+ const INLINE_FORMATTING = `
78
+
79
+ Response Formatting:
80
+ Write standard markdown; Telegram shows it formatted.
81
+ Long responses are automatically chunked into multiple messages.
82
+
83
+ Supported formatting:
84
+ - **bold**, *italic*, ~~strikethrough~~, \`inline code\`
85
+ - Links: [text](url)
86
+ - Lists: unordered (- item) and ordered (1. item)
87
+ - Code blocks: \`\`\`code\`\`\`
88
+ - Blockquotes: > text
89
+
90
+ Instead of tables (which don't render well in Telegram), use bullet lists with bold labels:
91
+ - **Name**: Alice
92
+ - **Age**: 30
93
+ - **City**: NYC`;
94
+ const BASE_SYSTEM_PROMPT = CORE_GUIDELINES + (config.TELEGRAPH_ENABLED ? TELEGRAPH_FORMATTING : INLINE_FORMATTING);
95
+ const SEND_FILE_TOOL_PROMPT = `
96
+
97
+ Send File Tool:
98
+ You have a telecoder_send_file MCP tool that sends files to the user via Telegram.
99
+ Use it after creating or generating files (SVGs, images, PDFs, reports, code bundles, etc.) to deliver them directly.
100
+ The file must be within the current working directory or /tmp. Maximum size: 50MB.
101
+ When you generate a file and the user would benefit from receiving it, proactively send it — no need to ask.`;
102
+ const ASK_USER_TOOL_PROMPT = `
103
+
104
+ Ask User Tool:
105
+ You have a telecoder_ask_user MCP tool that pops up a Telegram inline keyboard with multiple-choice options and pauses the agent loop until the user taps a button.
106
+ Use it when:
107
+ - You need a clear decision and free-text would be ambiguous (picking between 2–8 distinct approaches, confirming a destructive action, choosing among detected variants).
108
+ - The user's instruction is genuinely ambiguous and asking for free-text would feel like more friction than tapping a button.
109
+ Do NOT use it for:
110
+ - Open-ended questions where the answer needs to be free-text.
111
+ - Trivial confirmations where reasonable defaults exist (just proceed and note the assumption).
112
+ - Yes/no questions that the conversation context already implies the answer to.
113
+ Keep button labels ≤ 25 chars where you can — a longer one still reaches the user in full (the message body lists every option, keyed A/B/C), but the whole keyboard then shrinks to bare letters. Prefer 2–4 options. Add an optional one-line description per option only when the label alone is unclear.`;
114
+ const REQUEST_SECRET_TOOL_PROMPT = `
115
+
116
+ Secrets:
117
+ When a task needs a credential from the user (an API key, a token, a password), get it with the telecoder_request_secret MCP tool. Never ask them to paste one into the chat, and don't send them to a terminal for it: whatever is sent in the chat ends up in this conversation and in the Telegram history.
118
+ The tool runs your command with the secret in $SECRET and on stdin, after the user sends it and the bot deletes their message. You get the exit code and the output with the secret blanked out, never the value, so make the command store or use it in one go.
119
+ For a long-lived Claude token (CLAUDE_CODE_OAUTH_TOKEN), set source to "claude-setup-token": the bot runs \`claude setup-token\` on this machine and walks the user through signing in, and the token goes into your command without passing through Telegram.`;
120
+ const SET_TOPIC_TOOL_PROMPT = `
121
+
122
+ Auto-Topic Tool (IMPORTANT — call this often):
123
+ You MUST use the telecoder_set_topic MCP tool to keep the bot's display name in sync with what the user is working on. The bot name renders as "topic — project — Name" with a 64-char limit.
124
+
125
+ Call telecoder_set_topic in these situations:
126
+ 1. ON YOUR VERY FIRST RESPONSE of any conversation — read the user's first message and call the tool with a 1-4 word topic BEFORE writing your reply text.
127
+ 2. WHENEVER THE USER'S FOCUS SHIFTS to a meaningfully different task (different file/feature/bug/question category). Call the tool, THEN respond.
128
+ 3. Pass an empty string ("") to clear when the conversation becomes general or idle.
129
+
130
+ When NOT to call: minor follow-up on the same topic; clarifying questions about ongoing work; the next message in a continuous task.
131
+
132
+ Format: 1-4 lowercase words. Examples: "auth bug", "CI fix", "dark mode", "API docs", "watchdog tuning", "PR planning", "reading code".
133
+
134
+ When uncertain whether the topic shifted, LEAN TOWARD CALLING. A slightly-too-frequent topic update is fine; a stale topic is bad UX. The user is relying on the bot name to know what you're working on.`;
135
+ const MONITOR_RESPONSE_INSTRUCTIONS = `
136
+
137
+ Monitor Event Responses:
138
+ When you receive a <task-notification> that contains an <event> tag (i.e. a Monitor tool's event), respond with EXACTLY one line:
139
+
140
+ 📡 <event-content>
141
+
142
+ Where <event-content> is the verbatim text from the <event> tag — no quotes, no commentary, no surrounding text. This is the only content of your response for that turn. The bot surfaces this single line as a separate Telegram message so the user can see each monitor event.
143
+
144
+ The 📡 marks an event's own text. Don't put it in front of anything you write yourself, such as a note that you re-armed an expired monitor.
145
+
146
+ This rule applies ONLY to monitor event notifications. Task completion notifications (the ones with <status>) are handled by the bot — for those, respond as you normally would (briefly acknowledge or stay silent).`;
147
+ const REASONING_SUMMARY_INSTRUCTIONS = `
148
+
149
+ Reasoning Summary (required when enabled):
150
+ - At the end of each response, add a short section titled "Reasoning Summary".
151
+ - Provide 2–5 bullet points describing high-level actions/decisions taken.
152
+ - Do NOT reveal chain-of-thought, hidden reasoning, or sensitive tool outputs.
153
+ - Skip the summary for very short acknowledgements or pure error messages.`;
154
+ const TOOL_PROMPTS = [
155
+ SEND_FILE_TOOL_PROMPT,
156
+ ASK_USER_TOOL_PROMPT,
157
+ REQUEST_SECRET_TOOL_PROMPT,
158
+ config.DYNAMIC_BOT_NAME && !config.AUTO_TOPIC_HAIKU ? SET_TOPIC_TOOL_PROMPT : '',
159
+ ].join('');
160
+ const SYSTEM_PROMPT = `${BASE_SYSTEM_PROMPT}${TOOL_PROMPTS}${MONITOR_RESPONSE_INSTRUCTIONS}${config.CLAUDE_REASONING_SUMMARY ? REASONING_SUMMARY_INSTRUCTIONS : ''}`;
161
+ export { SYSTEM_PROMPT };
162
+ //# sourceMappingURL=system-prompt.js.map
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Scrape Claude Code's `/tasks` overlay out of the rendered xterm buffer.
3
+ *
4
+ * `/tasks` (alias `/bashes`, "View and manage everything running in the
5
+ * background") is a `local-jsx` command: it draws an Ink overlay pinned to the
6
+ * bottom of the TUI and writes nothing to the session JSONL. It is the live
7
+ * process's own view of its background work, so it sees things our arm-time
8
+ * tracker cannot — shells claude backgrounded on its own, and anything that
9
+ * predates a bot restart.
10
+ *
11
+ * Two shapes, decided by claude, not by us. With several tasks it opens on the
12
+ * list:
13
+ *
14
+ * ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
15
+ * Background
16
+ * 2 active shells
17
+ *
18
+ * ❯ sleep 500 (running)
19
+ * sleep 400 (running)
20
+ *
21
+ * ↑/↓ to select · Enter to view · x to stop · Esc to close
22
+ *
23
+ * With exactly one it opens that task's detail instead (Status / Runtime /
24
+ * Command / Output, ending in a `← to go back …` hint). Both are worth
25
+ * relaying, so we take whichever we're given rather than forcing one.
26
+ *
27
+ * Anchor: the overlay is always preceded by a full-width run of `▔` (U+2594).
28
+ * That glyph is specific to it — the input box and separators use `─` (U+2500)
29
+ * — so the last such rule in the buffer marks where the overlay starts, with
30
+ * everything above it being scrollback. Returns null when no overlay is found,
31
+ * which callers surface as "couldn't read it" rather than guessing.
32
+ */
33
+ /** The overlay's top rule. Full-width in practice; 10 is a safe floor. */
34
+ const OVERLAY_RULE_RE = /^▔{10,}$/;
35
+ /**
36
+ * The trailing keyboard-hint line ("… Esc to close"). Useless over Telegram —
37
+ * there's no keyboard attached — so it gets dropped. Both shapes end in
38
+ * "to close"; the leading-glyph alternatives guard against a task whose own
39
+ * text happens to contain that phrase.
40
+ */
41
+ const HINT_RE = /(?:↑\/↓|←|Esc|Enter)\s.*\bto close\b/;
42
+ /**
43
+ * Selection caret on the highlighted row; meaningless in a chat transcript.
44
+ * Replaced with its own width in spaces rather than deleted, so the selected
45
+ * row stays aligned with its unselected siblings.
46
+ */
47
+ const CARET_RE = /^❯\s?/;
48
+ /** Strip the common leading indentation shared by every non-blank line. */
49
+ function dedent(lines) {
50
+ const indents = lines
51
+ .filter((l) => l.trim().length > 0)
52
+ .map((l) => l.length - l.trimStart().length);
53
+ const common = indents.length ? Math.min(...indents) : 0;
54
+ return lines.map((l) => (l.trim().length > 0 ? l.slice(common) : ''));
55
+ }
56
+ export function scrapeTasksOverlay(screenText) {
57
+ const lines = screenText.split('\n');
58
+ // Scan bottom-up: the overlay is pinned to the bottom, and an earlier rule
59
+ // could survive in scrollback from a previous invocation.
60
+ let ruleIndex = -1;
61
+ for (let i = lines.length - 1; i >= 0; i--) {
62
+ if (OVERLAY_RULE_RE.test(lines[i].trim())) {
63
+ ruleIndex = i;
64
+ break;
65
+ }
66
+ }
67
+ if (ruleIndex === -1)
68
+ return null;
69
+ let body = lines.slice(ruleIndex + 1);
70
+ // Drop the trailing hint line and any blank padding around it.
71
+ while (body.length > 0) {
72
+ const last = body[body.length - 1];
73
+ if (last.trim() === '' || HINT_RE.test(last)) {
74
+ body.pop();
75
+ continue;
76
+ }
77
+ break;
78
+ }
79
+ body = dedent(body).map((l) => l.replace(CARET_RE, (m) => ' '.repeat(m.length)));
80
+ // Collapse runs of blank lines — the overlay pads generously for the TUI,
81
+ // which reads as dead space in a chat message.
82
+ const text = body
83
+ .join('\n')
84
+ .replace(/\n{3,}/g, '\n\n')
85
+ .trim();
86
+ if (!text)
87
+ return null;
88
+ // claude's own wording for the idle case. Matched loosely so a phrasing
89
+ // change degrades to "not empty" (we show the text) rather than a wrong
90
+ // "nothing running".
91
+ const empty = /\bno (?:tasks|shells|agents)\b.*\brunning\b/i.test(text);
92
+ return { text, empty };
93
+ }
94
+ //# sourceMappingURL=tasks-overlay-scraper.js.map
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Scrape Claude Code's spinner "Tip:" line from the rendered xterm buffer.
3
+ *
4
+ * While a turn is running, Claude Code draws a status block at the bottom of
5
+ * the TUI that occasionally carries a contextual tip, e.g.:
6
+ *
7
+ * ✶ Percolating… (29s)
8
+ * ⎿ Tip: Working with HTML/CSS? Install the frontend-design plugin:
9
+ * /plugin install frontend-design@claude-plugins-official
10
+ *
11
+ * These tips are bundled into the CLI (with client-side relevance + per-session
12
+ * cooldown logic) and never surface through the SDK event stream — they exist
13
+ * only in the live render. In PTY mode we already feed that render into an
14
+ * @xterm/headless buffer, so we can pull the tip back out and mirror it in the
15
+ * Telegram status indicator, exactly as Claude Code shows it.
16
+ *
17
+ * Detection: the spinner tip is rendered with a `⎿` tree connector preceding
18
+ * `Tip:`. That connector is the discriminator that distinguishes it from the
19
+ * startup "Update available" banner tip (which has no connector and lives in
20
+ * scrollback, not the live bottom rows). The tip can wrap onto a continuation
21
+ * line (the `/plugin install …` command), indented to align under `Tip: `.
22
+ *
23
+ * We scan the buffer bottom-up and return the lowest (most recent) match. The
24
+ * `⎿` connector is what makes this safe: the spinner block is redrawn in place
25
+ * and overwritten by committed output rather than scrolled into history, so a
26
+ * connector-prefixed tip only ever exists in the live block — there's no stale
27
+ * copy in scrollback to mismatch. (A fixed bottom-window scan can't be used: in
28
+ * an early session the live block sits near the top with empty viewport rows
29
+ * below it, pushing it outside any fixed window.)
30
+ */
31
+ // Tip line signature: a `⎿` tree connector followed by `Tip:`.
32
+ const TIP_RE = /⎿\s*Tip:\s*(.+)$/u;
33
+ const MAX_TIP_LEN = 220;
34
+ function isContinuation(line) {
35
+ if (!line)
36
+ return false;
37
+ const trimmed = line.trim();
38
+ if (!trimmed)
39
+ return false;
40
+ // Stop at TUI chrome: input-box borders/body, prompt glyph, another tree
41
+ // connector, separators, or the spinner status line itself.
42
+ if (/^[╭╰╮╯│─━═⎿●]/u.test(trimmed))
43
+ return false;
44
+ if (trimmed.includes('❯'))
45
+ return false;
46
+ // A continuation is indented under "Tip: " — bail if the raw line isn't.
47
+ return /^\s/u.test(line);
48
+ }
49
+ /**
50
+ * Return the spinner tip currently rendered (tip text plus any wrapped
51
+ * continuation, joined with a space), or null when none is on screen.
52
+ */
53
+ export function scrapeTip(xterm) {
54
+ const buf = xterm.buffer.active;
55
+ for (let i = buf.length - 1; i >= 0; i--) {
56
+ const line = buf.getLine(i);
57
+ if (!line)
58
+ continue;
59
+ const raw = line.translateToString(true);
60
+ const m = TIP_RE.exec(raw);
61
+ if (!m)
62
+ continue;
63
+ let tip = m[1].trim();
64
+ // Pull in wrapped continuation lines (e.g. the `/plugin install …` command).
65
+ for (let j = i + 1; j < buf.length && j <= i + 3; j++) {
66
+ const contRaw = buf.getLine(j)?.translateToString(true) ?? '';
67
+ if (!isContinuation(contRaw))
68
+ break;
69
+ tip += ' ' + contRaw.trim();
70
+ }
71
+ tip = tip.replace(/\s+/gu, ' ').trim();
72
+ if (!tip)
73
+ return null;
74
+ return tip.length > MAX_TIP_LEN ? tip.slice(0, MAX_TIP_LEN - 1).trimEnd() + '…' : tip;
75
+ }
76
+ return null;
77
+ }
78
+ //# sourceMappingURL=tip-scraper.js.map