telecoder 1.2.0 → 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.
- package/.env.example +142 -130
- package/CHANGELOG.md +683 -2
- package/README.md +36 -32
- package/dist/audio/transcribe.js +0 -9
- package/dist/bin/mcp-server.js +46 -61
- package/dist/bot/bot.js +162 -181
- package/dist/bot/command-catalog.js +263 -0
- package/dist/bot/deleted-threads.js +103 -0
- package/dist/bot/file-access.js +35 -26
- package/dist/bot/handlers/album.handler.js +128 -0
- package/dist/bot/handlers/{fork.handler.js → branch.handler.js} +267 -280
- package/dist/bot/handlers/command/access.js +1 -1
- package/dist/bot/handlers/command/admin.js +86 -110
- package/dist/bot/handlers/command/all-view.js +33 -0
- package/dist/bot/handlers/command/auto-approve.js +3 -3
- package/dist/bot/handlers/command/background.js +37 -0
- package/dist/bot/handlers/command/botname.js +76 -0
- package/dist/bot/handlers/command/btw.js +20 -69
- package/dist/bot/handlers/command/cleanup.js +329 -0
- package/dist/bot/handlers/command/model.js +40 -119
- package/dist/bot/handlers/command/prefs-scope.js +255 -90
- package/dist/bot/handlers/command/project.js +31 -109
- package/dist/bot/handlers/command/resume.js +8 -4
- package/dist/bot/handlers/command/session.js +74 -213
- package/dist/bot/handlers/command/settings.js +92 -447
- package/dist/bot/handlers/command/shared.js +32 -35
- package/dist/bot/handlers/command/tasks.js +263 -95
- package/dist/bot/handlers/command/thread.js +128 -0
- package/dist/bot/handlers/command/topic-store.js +14 -53
- package/dist/bot/handlers/command/topic.js +8 -61
- package/dist/bot/handlers/command/{cost.js → usage.js} +32 -59
- package/dist/bot/handlers/command-fallback.js +179 -0
- package/dist/bot/handlers/command.handler.js +96 -422
- package/dist/bot/handlers/{schedule.handler.js → loop.handler.js} +159 -73
- package/dist/bot/handlers/media-fallback.js +12 -7
- package/dist/bot/handlers/message/replies.js +10 -87
- package/dist/bot/handlers/message/shared.js +9 -31
- package/dist/bot/handlers/message/turn-notify.js +15 -49
- package/dist/bot/handlers/message/turn-runner.js +18 -103
- package/dist/bot/handlers/message.handler.js +59 -52
- package/dist/bot/handlers/newbot.handler.js +13 -4
- package/dist/bot/handlers/photo.handler.js +88 -129
- package/dist/bot/handlers/prompts.handler.js +11 -11
- package/dist/bot/handlers/running-note.js +2 -2
- package/dist/bot/handlers/session-guard.js +4 -4
- package/dist/bot/handlers/suggestion.handler.js +2 -2
- package/dist/bot/handlers/tree.handler.js +20 -20
- package/dist/bot/handlers/voice.handler.js +23 -85
- package/dist/bot/kept-threads.js +51 -0
- package/dist/bot/middleware/album-collector.js +69 -0
- package/dist/bot/middleware/auth.middleware.js +1 -1
- package/dist/bot/middleware/group-mention.middleware.js +11 -5
- package/dist/bot/middleware/queued-messages.js +143 -32
- package/dist/bot/middleware/stale-filter.js +0 -22
- package/dist/build-info.json +5 -5
- package/dist/claude/ask-user-form.js +517 -0
- package/dist/claude/ask-user.js +94 -26
- package/dist/claude/auto-topic-haiku.js +17 -0
- package/dist/claude/available-commands.js +22 -19
- package/dist/claude/background-hint.js +91 -0
- package/dist/claude/{fork-tree.js → branch-tree.js} +9 -9
- package/dist/claude/carry-over.js +0 -2
- package/dist/claude/ccr-shim.js +12 -10
- package/dist/claude/claude-auth.js +6 -10
- package/dist/claude/command-parser.js +49 -43
- package/dist/claude/cost-overlay-scraper.js +7 -2
- package/dist/claude/effort-level.js +5 -0
- package/dist/claude/enabled-plugins.js +12 -16
- package/dist/claude/in-flight-tracker.js +21 -0
- package/dist/claude/mcp-bridge.js +86 -58
- package/dist/claude/memory-guard.js +400 -0
- package/dist/claude/message-offsets.js +5 -5
- package/dist/claude/modal-relay.js +401 -34
- package/dist/claude/model-catalog.js +20 -3
- package/dist/claude/monitor-relay.js +130 -15
- package/dist/claude/native-commands.js +40 -0
- package/dist/claude/{pending-forks.js → pending-branches.js} +26 -26
- package/dist/claude/permission-gate.js +11 -10
- package/dist/claude/permission-mode.js +19 -45
- package/dist/claude/prewarm.js +70 -0
- package/dist/claude/pty-idle-reaper.js +96 -0
- package/dist/claude/pty-provider.js +473 -188
- package/dist/claude/pty-spawn-config.js +79 -32
- package/dist/claude/pty-watch.js +201 -0
- package/dist/claude/request-queue.js +7 -35
- package/dist/claude/rewind.js +111 -0
- package/dist/claude/scheduled-runner.js +1 -3
- package/dist/claude/scheduler.js +6 -2
- package/dist/claude/scope-guard.js +8 -3
- package/dist/claude/screen-marks.js +83 -0
- package/dist/claude/screen-render.js +96 -0
- package/dist/claude/session-history.js +4 -2
- package/dist/claude/session-jsonl.js +162 -15
- package/dist/claude/session-manager.js +29 -8
- package/dist/claude/session-move.js +70 -0
- package/dist/claude/shell-mode-gate.js +60 -0
- package/dist/claude/side-question.js +20 -17
- package/dist/claude/stage-images.js +5 -5
- package/dist/claude/tasks-overlay-scraper.js +143 -20
- package/dist/claude/thread-judge-haiku.js +88 -0
- package/dist/claude/tip-scraper.js +3 -4
- package/dist/claude/tui-modal.js +272 -27
- package/dist/claude/tui-state.js +74 -2
- package/dist/claude/turn-end.js +15 -1
- package/dist/claude/turn-prose.js +1 -1
- package/dist/claude/typed-answer.js +104 -0
- package/dist/claude/update-banner-relay.js +1 -1
- package/dist/cli/commands/doctor.js +48 -15
- package/dist/cli/commands/help.js +11 -2
- package/dist/cli/commands/init.js +16 -13
- package/dist/cli/commands/service.js +40 -8
- package/dist/cli/commands/start.js +10 -0
- package/dist/cli/commands/watch.js +322 -0
- package/dist/cli/dispatch.js +5 -0
- package/dist/cli/init/env-file.js +1 -1
- package/dist/cli/init/flow.js +114 -47
- package/dist/cli/init/prompter.js +8 -0
- package/dist/cli/init/telegram.js +35 -9
- package/dist/cli/service/render.js +3 -3
- package/dist/config.js +156 -131
- package/dist/index.js +107 -31
- package/dist/launcher.js +34 -7
- package/dist/providers/ccr-introspect.js +1 -8
- package/dist/providers/ccr-provider.js +19 -20
- package/dist/providers/claude-provider.js +4 -57
- package/dist/providers/prefs-sync.js +16 -59
- package/dist/providers/provider-router.js +24 -23
- package/dist/providers/spawn-settings.js +45 -0
- package/dist/providers/user-preferences.js +127 -19
- package/dist/restart-when-idle.js +27 -7
- package/dist/startup/auto-continue.js +2 -2
- package/dist/startup/auto-resume.js +3 -15
- package/dist/startup/notices.js +1 -1
- package/dist/startup/verify-token.js +4 -4
- package/dist/telegram/action-logger.js +3 -165
- package/dist/telegram/background-activity-card.js +1 -1
- package/dist/telegram/botname-settings.js +71 -125
- package/dist/telegram/client-options.js +6 -7
- package/dist/telegram/force-reply-tracker.js +55 -16
- package/dist/telegram/message-sender.js +92 -360
- package/dist/telegram/prompt-label.js +11 -5
- package/dist/telegram/streaming-turn.js +5 -7
- package/dist/telegram/table-lists.js +56 -0
- package/dist/telegram/task-list.js +4 -4
- package/dist/telegram/task-tracker.js +45 -126
- package/dist/telegram/terminal-renderer.js +1 -5
- package/dist/telegram/thread-titles.js +74 -2
- package/dist/telegram/threads-setup.js +1 -1
- package/dist/utils/admins.js +2 -2
- package/dist/utils/bot-icon.js +248 -0
- package/dist/utils/bot-token.js +8 -5
- package/dist/utils/build-info.js +3 -3
- package/dist/utils/caffeinate.js +6 -3
- package/dist/utils/claude-env.js +0 -1
- package/dist/utils/claude-version.js +2 -2
- package/dist/utils/config-home.js +3 -3
- package/dist/utils/download.js +41 -15
- package/dist/utils/exit-codes.js +11 -0
- package/dist/utils/format.js +3 -6
- package/dist/utils/home-project.js +1 -1
- package/dist/utils/idle-restart.js +1 -1
- package/dist/utils/install-mode.js +1 -1
- package/dist/utils/instance-config.js +1 -1
- package/dist/utils/instances.js +1 -1
- package/dist/utils/keyed-settings.js +2 -2
- package/dist/utils/memory-pressure.js +60 -0
- package/dist/utils/npm-version.js +2 -2
- package/dist/utils/resolve-claude-bin.js +13 -24
- package/dist/utils/respawn-backoff.js +9 -0
- package/dist/utils/stale-launcher.js +1 -1
- package/dist/utils/systemd.js +8 -8
- package/dist/utils/telegram-proxy.js +72 -0
- package/dist/utils/uploads-dir.js +27 -0
- package/dist/utils/verbosity.js +8 -8
- package/dist/utils/version-check.js +5 -5
- package/package.json +3 -4
- package/dist/bot/handlers/command/media.js +0 -197
- package/dist/bot/handlers/command/streaming-mode.js +0 -16
- package/dist/bot/handlers/message/throttle.js +0 -49
- package/dist/claude/agent-watchdog.js +0 -162
- package/dist/claude/agent.js +0 -1458
- package/dist/claude/held-query.js +0 -190
- package/dist/claude/mcp-tools.js +0 -354
- package/dist/claude/sdk-permission-gate.js +0 -77
- package/dist/claude/session-cost.js +0 -41
- package/dist/claude/system-prompt.js +0 -162
- package/dist/providers/sdk-provider.js +0 -37
- package/dist/telegram/telegraph-settings.js +0 -31
- package/dist/telegram/telegraph.js +0 -453
- package/dist/telegram/terminal-settings.js +0 -25
- package/dist/tts/tts-settings.js +0 -62
- package/dist/tts/tts.js +0 -245
- package/dist/tts/voice-reply.js +0 -78
- package/dist/utils/debug-agent.js +0 -117
- package/dist/utils/debug-watchdog.js +0 -121
- package/dist/utils/project-data-dir.js +0 -33
- package/dist/utils/reasoning-summary.js +0 -12
|
@@ -3,7 +3,7 @@ import { sessionManager } from '../../claude/session-manager.js';
|
|
|
3
3
|
import { scheduler, HARD_LIMITS } from '../../claude/scheduler.js';
|
|
4
4
|
import { getSessionKeyFromCtx } from '../../utils/session-key.js';
|
|
5
5
|
import { EntityText, joinMessages } from '../../telegram/entities.js';
|
|
6
|
-
import { replyFormatted } from '../../telegram/send.js';
|
|
6
|
+
import { replyFormatted, editCallbackMessage } from '../../telegram/send.js';
|
|
7
7
|
/** Text with `inline code` spans and nothing else — the parser errors below are written that way. */
|
|
8
8
|
function withCode(text) {
|
|
9
9
|
const b = new EntityText();
|
|
@@ -11,26 +11,30 @@ function withCode(text) {
|
|
|
11
11
|
return b.build();
|
|
12
12
|
}
|
|
13
13
|
const EXAMPLES = [
|
|
14
|
-
'/
|
|
15
|
-
'/
|
|
16
|
-
'/
|
|
17
|
-
'/
|
|
18
|
-
'/
|
|
14
|
+
'/loop 5m check the dev server',
|
|
15
|
+
'/loop summarize the git log every 1h',
|
|
16
|
+
'/loop daily 9am give me my morning standup',
|
|
17
|
+
'/loop weekdays 14:00 ping team about standups',
|
|
18
|
+
'/loop mon,wed,fri 10:30 review open PRs',
|
|
19
19
|
];
|
|
20
20
|
const USAGE = (() => {
|
|
21
|
-
const b = new EntityText().bold('Usage:').add(' ').code('/
|
|
21
|
+
const b = new EntityText().bold('Usage:').add(' ').code('/loop <interval> <prompt>').newline(2);
|
|
22
22
|
b.bold('Examples:').newline();
|
|
23
23
|
for (const example of EXAMPLES)
|
|
24
24
|
b.code(example).newline();
|
|
25
|
-
b.code('/
|
|
25
|
+
b.code('/loop 0 9 * * * morning summary').add(' (raw cron)').newline(2);
|
|
26
|
+
b.add('An interval runs the prompt once now, then every interval; a time of day waits for it.').newline(2);
|
|
26
27
|
b.bold('Options').add(' (append at the end):').newline();
|
|
27
|
-
b.code('--max-runs N').add(' cap total
|
|
28
|
-
b.code('--label "..."').add(' short title shown in the
|
|
29
|
-
b.add(`Hard limits: max ${HARD_LIMITS.MAX_PER_SESSION} active
|
|
28
|
+
b.code('--max-runs N').add(' cap total runs (default 50, max 500)').newline();
|
|
29
|
+
b.code('--label "..."').add(' short title shown in the run header').newline(2);
|
|
30
|
+
b.add(`Hard limits: max ${HARD_LIMITS.MAX_PER_SESSION} active loops per chat, `
|
|
30
31
|
+ `${HARD_LIMITS.MIN_INTERVAL_MS / 1000}s minimum interval, `
|
|
31
|
-
+ `${HARD_LIMITS.DEFAULT_MAX_RUNS}
|
|
32
|
+
+ `${HARD_LIMITS.DEFAULT_MAX_RUNS} runs by default.`);
|
|
32
33
|
return b.build();
|
|
33
34
|
})();
|
|
35
|
+
/** What /loop without an interval says: Claude Code's self-paced mode, which the chat can't have yet. */
|
|
36
|
+
const NO_INTERVAL = withCode('ℹ️ Without an interval, Claude Code\'s /loop lets Claude pick when to run again, which can\'t reach the chat yet. '
|
|
37
|
+
+ 'Give one: `/loop 10m <prompt>` or `/loop <prompt> every 10m`.');
|
|
34
38
|
const INTERVAL_UNITS = {
|
|
35
39
|
s: 1000,
|
|
36
40
|
sec: 1000,
|
|
@@ -90,8 +94,9 @@ function extractOptions(prompt) {
|
|
|
90
94
|
return { prompt: working, maxRuns, label };
|
|
91
95
|
}
|
|
92
96
|
/**
|
|
93
|
-
* Parse
|
|
94
|
-
* (in order): raw 5-field cron, `every <N><unit>`, day-keyword + time-of-day
|
|
97
|
+
* Parse a schedule at the start of /loop's input. Tries
|
|
98
|
+
* (in order): raw 5-field cron, `every <N><unit>`, day-keyword + time-of-day,
|
|
99
|
+
* a bare `<N><unit>`.
|
|
95
100
|
* Returns the consumed token count so the caller can slice the prompt off.
|
|
96
101
|
*/
|
|
97
102
|
function parseWhen(tokens) {
|
|
@@ -175,7 +180,88 @@ function parseWhen(tokens) {
|
|
|
175
180
|
consumed: 2,
|
|
176
181
|
};
|
|
177
182
|
}
|
|
178
|
-
|
|
183
|
+
// Claude Code's own leading interval: `/loop 5m <prompt>`.
|
|
184
|
+
const bare = parseInterval(first);
|
|
185
|
+
if (bare) {
|
|
186
|
+
if ('error' in bare)
|
|
187
|
+
return bare;
|
|
188
|
+
return { parsed: bare.parsed, consumed: 1 };
|
|
189
|
+
}
|
|
190
|
+
return { error: `Couldn't parse schedule. Type \`/loop\` with no args to see examples.` };
|
|
191
|
+
}
|
|
192
|
+
/** `5m`, `2h`, `30s`, `1d` as an interval, or null when the token isn't one. */
|
|
193
|
+
function parseInterval(token) {
|
|
194
|
+
const match = token.toLowerCase().match(/^(\d+)([smhd])$/);
|
|
195
|
+
if (!match)
|
|
196
|
+
return null;
|
|
197
|
+
return intervalOf(parseInt(match[1], 10), match[2]);
|
|
198
|
+
}
|
|
199
|
+
function intervalOf(amount, unitKey) {
|
|
200
|
+
const unitMs = INTERVAL_UNITS[unitKey];
|
|
201
|
+
if (!unitMs)
|
|
202
|
+
return { error: `Unknown unit \`${unitKey}\`. Use s/m/h/d.` };
|
|
203
|
+
const intervalMs = amount * unitMs;
|
|
204
|
+
if (intervalMs < HARD_LIMITS.MIN_INTERVAL_MS) {
|
|
205
|
+
return { error: `Interval must be at least ${HARD_LIMITS.MIN_INTERVAL_MS / 1000}s.` };
|
|
206
|
+
}
|
|
207
|
+
return { parsed: { kind: 'interval', intervalMs, humanDescription: `every ${amount}${unitKey}` } };
|
|
208
|
+
}
|
|
209
|
+
/** Unit words a trailing every clause may spell out, as Claude Code's /loop reads them. */
|
|
210
|
+
const UNIT_WORDS = {
|
|
211
|
+
s: 's', sec: 's', secs: 's', second: 's', seconds: 's',
|
|
212
|
+
m: 'm', min: 'm', mins: 'm', minute: 'm', minutes: 'm',
|
|
213
|
+
h: 'h', hr: 'h', hrs: 'h', hour: 'h', hours: 'h',
|
|
214
|
+
d: 'd', day: 'd', days: 'd',
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* Claude Code's rule 2: a prompt ending in `every 20m` or `every 5 minutes`.
|
|
218
|
+
* Only a time follows the every; "check every PR" is a prompt with no interval.
|
|
219
|
+
*/
|
|
220
|
+
export function parseTrailingEvery(input) {
|
|
221
|
+
const match = input.match(/^(.*?)\s*\bevery\s+(\d+)\s*([a-z]+)\s*$/i);
|
|
222
|
+
if (!match)
|
|
223
|
+
return null;
|
|
224
|
+
const unit = UNIT_WORDS[match[3].toLowerCase()];
|
|
225
|
+
if (!unit)
|
|
226
|
+
return null;
|
|
227
|
+
const interval = intervalOf(parseInt(match[2], 10), unit);
|
|
228
|
+
if ('error' in interval)
|
|
229
|
+
return interval;
|
|
230
|
+
return { parsed: interval.parsed, prompt: match[1].trim() };
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* What /loop's input asks for: when, the prompt, and whether it runs at once,
|
|
234
|
+
* which an interval does (as in Claude Code) and a time of day doesn't.
|
|
235
|
+
*/
|
|
236
|
+
export function parseLoop(input) {
|
|
237
|
+
// Split off `--` first if present: everything before it is the schedule.
|
|
238
|
+
const sepIdx = input.indexOf(' -- ');
|
|
239
|
+
const tokens = (sepIdx >= 0 ? input.slice(0, sepIdx) : input).split(/\s+/).filter(Boolean);
|
|
240
|
+
const leading = parseWhen(tokens);
|
|
241
|
+
if (!('error' in leading)) {
|
|
242
|
+
const prompt = sepIdx >= 0 ? input.slice(sepIdx + 4).trim() : tokens.slice(leading.consumed).join(' ').trim();
|
|
243
|
+
if (!prompt)
|
|
244
|
+
return { error: 'Missing prompt. After the interval, add the prompt to run each time.' };
|
|
245
|
+
return { parsed: leading.parsed, prompt, runNow: leading.parsed.kind === 'interval' };
|
|
246
|
+
}
|
|
247
|
+
// A leading spec that is one but is wrong (`every 10x`, `daily 25:00`, `20s`) says so.
|
|
248
|
+
if (sepIdx >= 0 || looksLikeSpec(tokens[0] ?? ''))
|
|
249
|
+
return leading;
|
|
250
|
+
const trailing = parseTrailingEvery(input);
|
|
251
|
+
if (trailing) {
|
|
252
|
+
if ('error' in trailing)
|
|
253
|
+
return trailing;
|
|
254
|
+
if (!trailing.prompt)
|
|
255
|
+
return { error: 'Missing prompt. Before the every, add the prompt to run each time.' };
|
|
256
|
+
return { parsed: trailing.parsed, prompt: trailing.prompt, runNow: true };
|
|
257
|
+
}
|
|
258
|
+
return { noInterval: true };
|
|
259
|
+
}
|
|
260
|
+
/** Whether a first word starts a schedule, so an error in it is about the schedule. */
|
|
261
|
+
function looksLikeSpec(first) {
|
|
262
|
+
const word = first.toLowerCase();
|
|
263
|
+
return word === 'every' || word === 'daily' || word === 'weekdays' || word === 'weekends'
|
|
264
|
+
|| /^\d+[smhd]?$/.test(word) || word.split(',').every((p) => p in DAY_OF_WEEK);
|
|
179
265
|
}
|
|
180
266
|
function formatSchedule(s) {
|
|
181
267
|
const status = s.disabled ? ' (disabled)' : '';
|
|
@@ -191,58 +277,41 @@ function formatSchedule(s) {
|
|
|
191
277
|
.add(`${status}\n${when}${labelLine}\nruns: ${s.runs}/${s.maxRuns}${nextLine}\nprompt: ${promptPreview}`)
|
|
192
278
|
.build();
|
|
193
279
|
}
|
|
194
|
-
export async function
|
|
280
|
+
export async function handleLoop(ctx) {
|
|
195
281
|
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
196
282
|
if (!keyInfo)
|
|
197
283
|
return;
|
|
198
284
|
const { sessionKey } = keyInfo;
|
|
199
285
|
const text = (ctx.message?.text ?? '').trim();
|
|
200
|
-
const stripped = text.replace(
|
|
286
|
+
const stripped = text.replace(/^\/\w+(?:@\w+)?\s*/, '');
|
|
201
287
|
if (!stripped) {
|
|
202
288
|
await replyFormatted(ctx, USAGE);
|
|
203
289
|
return;
|
|
204
290
|
}
|
|
205
|
-
// Session required so the
|
|
291
|
+
// Session required so the loop can resume into a real project later.
|
|
206
292
|
const session = sessionManager.getSession(sessionKey)
|
|
207
293
|
?? sessionManager.getOrRestoreSession(sessionKey).session;
|
|
208
294
|
if (!session) {
|
|
209
|
-
await replyFormatted(ctx, withCode('⚠️ No project set. Use `/
|
|
295
|
+
await replyFormatted(ctx, withCode('⚠️ No project set. Use `/dir` or `/resume` first, then start the loop.'));
|
|
210
296
|
return;
|
|
211
297
|
}
|
|
212
|
-
// Split off options first so they don't get eaten by the
|
|
213
|
-
const { prompt:
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
let promptPart;
|
|
218
|
-
if (sepIdx >= 0) {
|
|
219
|
-
whenPart = promptWithoutOpts.slice(0, sepIdx).trim();
|
|
220
|
-
promptPart = promptWithoutOpts.slice(sepIdx + 4).trim();
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
whenPart = promptWithoutOpts;
|
|
224
|
-
promptPart = '';
|
|
225
|
-
}
|
|
226
|
-
const whenTokens = whenPart.split(/\s+/).filter(Boolean);
|
|
227
|
-
const parseResult = parseWhen(whenTokens);
|
|
228
|
-
if ('error' in parseResult) {
|
|
229
|
-
await replyFormatted(ctx, joinMessages([withCode(`❌ ${parseResult.error}`), USAGE]));
|
|
298
|
+
// Split off options first so they don't get eaten by the parser.
|
|
299
|
+
const { prompt: input, maxRuns, label } = extractOptions(stripped);
|
|
300
|
+
const result = parseLoop(input);
|
|
301
|
+
if ('noInterval' in result) {
|
|
302
|
+
await replyFormatted(ctx, NO_INTERVAL);
|
|
230
303
|
return;
|
|
231
304
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
// No explicit `--` — take the remaining tokens as the prompt.
|
|
235
|
-
promptPart = whenTokens.slice(consumed).join(' ').trim();
|
|
236
|
-
}
|
|
237
|
-
if (!promptPart) {
|
|
238
|
-
await replyFormatted(ctx, '❌ Missing prompt. After the schedule spec, add the prompt to run on each fire.');
|
|
305
|
+
if ('error' in result) {
|
|
306
|
+
await replyFormatted(ctx, joinMessages([withCode(`❌ ${result.error}`), USAGE]));
|
|
239
307
|
return;
|
|
240
308
|
}
|
|
309
|
+
const { parsed, prompt, runNow } = result;
|
|
241
310
|
const spec = {
|
|
242
311
|
sessionKey,
|
|
243
312
|
cwd: session.workingDirectory,
|
|
244
313
|
claudeSessionId: session.claudeSessionId,
|
|
245
|
-
prompt
|
|
314
|
+
prompt,
|
|
246
315
|
label,
|
|
247
316
|
maxRuns,
|
|
248
317
|
...(parsed.kind === 'interval'
|
|
@@ -257,47 +326,64 @@ export async function handleSchedule(ctx) {
|
|
|
257
326
|
await replyFormatted(ctx, `❌ ${err instanceof Error ? err.message : String(err)}`);
|
|
258
327
|
return;
|
|
259
328
|
}
|
|
260
|
-
const next = scheduler.nextFireAt(created.id);
|
|
261
329
|
const b = new EntityText()
|
|
262
|
-
.add('✅ ').bold('
|
|
263
|
-
.add('id: ').code(created.id).newline()
|
|
330
|
+
.add('✅ ').bold('Loop started').newline()
|
|
264
331
|
.add(`when: ${parsed.humanDescription}\n`)
|
|
265
332
|
.add(`max runs: ${created.maxRuns}`);
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
333
|
+
const next = scheduler.nextFireAt(created.id);
|
|
334
|
+
if (runNow)
|
|
335
|
+
b.add('\nFirst run: now');
|
|
336
|
+
else if (next)
|
|
337
|
+
b.add('\nFirst run: ').code(new Date(next).toLocaleString());
|
|
338
|
+
b.newline(2).code('/loops').add(' lists your loops and stops one.');
|
|
269
339
|
await replyFormatted(ctx, b.build());
|
|
340
|
+
// Not awaited: the run queues behind this chat's turn like any message, and
|
|
341
|
+
// this command must not hold the chat while it does.
|
|
342
|
+
if (runNow)
|
|
343
|
+
void scheduler.fireNow(created.id);
|
|
270
344
|
}
|
|
271
|
-
|
|
345
|
+
const DELETE_PREFIX = 'loops:del:';
|
|
346
|
+
/** The /loops message: each loop, and a button per loop that stops it. */
|
|
347
|
+
function loopsMessage(sessionKey) {
|
|
348
|
+
const list = scheduler.listSchedules(sessionKey);
|
|
349
|
+
if (list.length === 0)
|
|
350
|
+
return null;
|
|
351
|
+
const heading = new EntityText().add('📋 ').bold('Loops').add(` (${list.length})`).build();
|
|
352
|
+
const keyboard = list.map((s) => {
|
|
353
|
+
const name = s.label ?? s.prompt;
|
|
354
|
+
const short = name.length > 40 ? name.slice(0, 39) + '…' : name;
|
|
355
|
+
return [{ text: `🗑 ${short}`, callback_data: `${DELETE_PREFIX}${s.id}` }];
|
|
356
|
+
});
|
|
357
|
+
return { text: joinMessages([heading, ...list.map(formatSchedule)]), keyboard };
|
|
358
|
+
}
|
|
359
|
+
const NO_LOOPS = withCode('No loops running. Start one with `/loop <interval> <prompt>`.');
|
|
360
|
+
export async function handleLoops(ctx) {
|
|
272
361
|
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
273
362
|
if (!keyInfo)
|
|
274
363
|
return;
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
await replyFormatted(ctx, withCode('No active schedules. Create one with `/schedule <when> <prompt>`.'));
|
|
364
|
+
const message = loopsMessage(keyInfo.sessionKey);
|
|
365
|
+
if (!message) {
|
|
366
|
+
await replyFormatted(ctx, NO_LOOPS);
|
|
279
367
|
return;
|
|
280
368
|
}
|
|
281
|
-
|
|
282
|
-
await replyFormatted(ctx, joinMessages([heading, ...list.map(formatSchedule)]));
|
|
369
|
+
await replyFormatted(ctx, message.text, { reply_markup: { inline_keyboard: message.keyboard } });
|
|
283
370
|
}
|
|
284
|
-
|
|
371
|
+
/** A 🗑 under /loops: stop that loop, and show the list without it. */
|
|
372
|
+
export async function handleLoopsCallback(ctx) {
|
|
285
373
|
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const { sessionKey } = keyInfo;
|
|
289
|
-
const text = (ctx.message?.text ?? '').trim();
|
|
290
|
-
const id = text.replace(/^\/unschedule(?:@\w+)?\s*/i, '').trim();
|
|
291
|
-
if (!id) {
|
|
292
|
-
await replyFormatted(ctx, withCode('Usage: `/unschedule <id>`. Use `/schedules` to see ids.'));
|
|
374
|
+
const data = ctx.callbackQuery?.data ?? '';
|
|
375
|
+
if (!keyInfo || !data.startsWith(DELETE_PREFIX))
|
|
293
376
|
return;
|
|
294
|
-
|
|
377
|
+
const id = data.slice(DELETE_PREFIX.length);
|
|
295
378
|
const target = scheduler.getSchedule(id);
|
|
296
|
-
if (!target || target.sessionKey !== sessionKey) {
|
|
297
|
-
await
|
|
298
|
-
|
|
379
|
+
if (!target || target.sessionKey !== keyInfo.sessionKey) {
|
|
380
|
+
await ctx.answerCallbackQuery({ text: 'That loop is already gone.' }).catch(() => { });
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
scheduler.deleteSchedule(id);
|
|
384
|
+
await ctx.answerCallbackQuery({ text: 'Loop stopped.' }).catch(() => { });
|
|
299
385
|
}
|
|
300
|
-
|
|
301
|
-
await
|
|
386
|
+
const message = loopsMessage(keyInfo.sessionKey);
|
|
387
|
+
await editCallbackMessage(ctx, message?.text ?? NO_LOOPS, message ? { reply_markup: { inline_keyboard: message.keyboard } } : undefined).catch(() => { });
|
|
302
388
|
}
|
|
303
|
-
//# sourceMappingURL=
|
|
389
|
+
//# sourceMappingURL=loop.handler.js.map
|
|
@@ -39,19 +39,19 @@ export async function replyTooLargeToFetch(ctx, kindTitle, fileSizeBytes) {
|
|
|
39
39
|
.build());
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* An audio file. Only voice notes become prompts, so rather than dropping the
|
|
43
|
+
* file we say so; silence here read as "the bot is broken".
|
|
44
44
|
*/
|
|
45
45
|
export async function replyBareAudio(ctx, fileSizeBytes) {
|
|
46
46
|
if (exceedsDownloadLimit(fileSizeBytes)) {
|
|
47
47
|
await replyTooLargeToFetch(ctx, 'Audio file', fileSizeBytes);
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
console.log('[Media]
|
|
50
|
+
console.log('[Media] Audio upload — unsupported, told user');
|
|
51
51
|
await replyFormatted(ctx, new EntityText()
|
|
52
52
|
.add('🎵 ').bold('Audio received').add(sizeSuffix(fileSizeBytes)).add('\n\n')
|
|
53
|
-
.add("I
|
|
54
|
-
+
|
|
53
|
+
.add("I can't read audio files. To talk to Claude, record a voice note instead, "
|
|
54
|
+
+ "or point me at the file's path if it's already on this machine.")
|
|
55
55
|
.build());
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
@@ -66,8 +66,7 @@ export async function replyUnsupportedVideo(ctx, fileSizeBytes) {
|
|
|
66
66
|
console.log('[Media] Video upload — unsupported, told user');
|
|
67
67
|
await replyFormatted(ctx, new EntityText()
|
|
68
68
|
.add('🎬 ').bold("Video isn't supported").add(sizeSuffix(fileSizeBytes)).add('\n\n')
|
|
69
|
-
.add("I can't read video files.
|
|
70
|
-
+ "or point me at the file's path if it's already on this machine.")
|
|
69
|
+
.add("I can't read video files. Point me at the file's path if it's already on this machine.")
|
|
71
70
|
.build());
|
|
72
71
|
}
|
|
73
72
|
/**
|
|
@@ -104,6 +103,12 @@ export async function handleUnsupportedVideo(ctx) {
|
|
|
104
103
|
const media = ctx.message?.video ?? ctx.message?.video_note ?? ctx.message?.animation;
|
|
105
104
|
await replyUnsupportedVideo(ctx, media?.file_size);
|
|
106
105
|
}
|
|
106
|
+
/** Entry point for `message:audio`: music and recordings, not voice notes. */
|
|
107
|
+
export async function handleUnsupportedAudio(ctx) {
|
|
108
|
+
if (!claimsMediaMessage(ctx, 'audio'))
|
|
109
|
+
return;
|
|
110
|
+
await replyBareAudio(ctx, ctx.message?.audio?.file_size);
|
|
111
|
+
}
|
|
107
112
|
/**
|
|
108
113
|
* Entry point for audio/video sent as a *document* — the path a 172MB mp3 takes
|
|
109
114
|
* when Telegram declines to treat it as playable audio.
|
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Handlers for replies to the bot's ForceReply prompts — the flows where a
|
|
3
3
|
* command posts a question and the user's *next* message is the answer
|
|
4
|
-
* (
|
|
4
|
+
* (the /dir path).
|
|
5
5
|
*
|
|
6
|
-
* `handleMessage` routes here by
|
|
6
|
+
* `handleMessage` routes here by the flow the prompt it is replying to opened
|
|
7
|
+
* (see force-reply-tracker.ts).
|
|
7
8
|
*/
|
|
8
9
|
import * as fs from 'fs';
|
|
9
10
|
import * as path from 'path';
|
|
10
|
-
import {
|
|
11
|
+
import { clearConversation } from '../../../providers/provider-router.js';
|
|
12
|
+
import { prewarmClaude } from '../../../claude/prewarm.js';
|
|
11
13
|
import { sessionManager } from '../../../claude/session-manager.js';
|
|
12
|
-
import { messageSender } from '../../../telegram/message-sender.js';
|
|
13
14
|
import { EntityText } from '../../../telegram/entities.js';
|
|
14
15
|
import { replyFormatted } from '../../../telegram/send.js';
|
|
15
|
-
import {
|
|
16
|
-
import { maybeSendVoiceReply } from '../../../tts/voice-reply.js';
|
|
17
|
-
import { projectStatusSuffix, resumeCommandMessage, clearTopicAndRefreshBotName, } from '../command.handler.js';
|
|
18
|
-
import { fireAutoTopic, requireSession, resolveUserFilePath, runQueuedTurn } from './shared.js';
|
|
19
|
-
import { refuseFilePublish } from '../../file-access.js';
|
|
20
|
-
import { progressCallbacks, toolCallbacks, withStreamingTurn } from '../../../telegram/streaming-turn.js';
|
|
21
|
-
import { closeTurn, relayCatchUpIfMissed } from './turn-notify.js';
|
|
16
|
+
import { projectStatusSuffix, resumeCommandMessage, clearTopic, } from '../command.handler.js';
|
|
22
17
|
// Handle reply to project ForceReply prompt
|
|
23
|
-
export async function
|
|
18
|
+
export async function handleDirReply(ctx, sessionKey, projectPath) {
|
|
24
19
|
let resolvedPath = projectPath.trim();
|
|
25
20
|
// Handle ~ expansion
|
|
26
21
|
if (resolvedPath.startsWith('~')) {
|
|
27
22
|
resolvedPath = path.join(process.env.HOME || '', resolvedPath.slice(1));
|
|
28
23
|
}
|
|
29
24
|
// Resolve to absolute path. Manual path entry is treated as an explicit
|
|
30
|
-
// user choice and may point anywhere on disk (mirrors typing `/
|
|
25
|
+
// user choice and may point anywhere on disk (mirrors typing `/dir <abs>`).
|
|
31
26
|
resolvedPath = path.resolve(resolvedPath);
|
|
32
27
|
// Check if exists
|
|
33
28
|
if (!fs.existsSync(resolvedPath)) {
|
|
@@ -44,7 +39,7 @@ export async function handleProjectReply(ctx, sessionKey, projectPath) {
|
|
|
44
39
|
// Set the project
|
|
45
40
|
sessionManager.setWorkingDirectory(sessionKey, resolvedPath);
|
|
46
41
|
clearConversation(sessionKey);
|
|
47
|
-
|
|
42
|
+
clearTopic(sessionKey);
|
|
48
43
|
const projectName = path.basename(resolvedPath);
|
|
49
44
|
await replyFormatted(ctx, new EntityText()
|
|
50
45
|
.add('✅ Project set: ').bold(projectName).newline(2)
|
|
@@ -56,78 +51,6 @@ export async function handleProjectReply(ctx, sessionKey, projectPath) {
|
|
|
56
51
|
if (s?.claudeSessionId) {
|
|
57
52
|
await replyFormatted(ctx, resumeCommandMessage(s.claudeSessionId));
|
|
58
53
|
}
|
|
59
|
-
|
|
60
|
-
// Handle reply to file ForceReply prompt
|
|
61
|
-
export async function handleFileReply(ctx, sessionKey, filePath) {
|
|
62
|
-
const fullPath = await resolveUserFilePath(ctx, sessionKey, filePath);
|
|
63
|
-
if (!fullPath)
|
|
64
|
-
return;
|
|
65
|
-
const success = await messageSender.sendDocument(ctx, fullPath, `📎 ${path.basename(fullPath)}`);
|
|
66
|
-
if (!success) {
|
|
67
|
-
await ctx.reply('❌ Failed to send file. It may be too large (>50MB) or inaccessible.');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// Handle reply to plan/explore/loop ForceReply prompts
|
|
71
|
-
export async function handleAgentReply(ctx, sessionKey, input, mode) {
|
|
72
|
-
if (!await requireSession(ctx, sessionKey))
|
|
73
|
-
return;
|
|
74
|
-
const trimmedInput = input.trim();
|
|
75
|
-
if (!trimmedInput) {
|
|
76
|
-
await ctx.reply('❌ Please provide a description.');
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
fireAutoTopic(ctx, sessionKey, trimmedInput);
|
|
80
|
-
await runQueuedTurn(ctx, sessionKey, trimmedInput, `AgentReply:${mode}`, async () => {
|
|
81
|
-
const startTime = Date.now();
|
|
82
|
-
await withStreamingTurn(ctx, sessionKey, trimmedInput, async (abortController) => {
|
|
83
|
-
let response;
|
|
84
|
-
if (mode === 'loop') {
|
|
85
|
-
response = await sendLoopToAgent(sessionKey, trimmedInput, {
|
|
86
|
-
...progressCallbacks(ctx),
|
|
87
|
-
abortController,
|
|
88
|
-
telegramCtx: ctx,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
response = await sendToAgent(sessionKey, trimmedInput, {
|
|
93
|
-
...progressCallbacks(ctx),
|
|
94
|
-
...toolCallbacks(ctx, sessionKey),
|
|
95
|
-
abortController,
|
|
96
|
-
command: mode,
|
|
97
|
-
telegramCtx: ctx,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
await messageSender.finishStreaming(ctx, response.text, { nextPromptSuggestion: response.nextPromptSuggestion });
|
|
101
|
-
await relayCatchUpIfMissed(ctx, sessionKey, response.text || '');
|
|
102
|
-
await maybeSendVoiceReply(ctx, response.text);
|
|
103
|
-
// Completion notification for long tasks
|
|
104
|
-
await messageSender.sendCompletionNotification(ctx, Date.now() - startTime);
|
|
105
|
-
await closeTurn(ctx, sessionKey, response, trimmedInput);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
// Handle reply to telegraph ForceReply prompt
|
|
110
|
-
export async function handleTelegraphReply(ctx, sessionKey, filePath) {
|
|
111
|
-
if (await refuseFilePublish(ctx))
|
|
112
|
-
return;
|
|
113
|
-
const fullPath = await resolveUserFilePath(ctx, sessionKey, filePath);
|
|
114
|
-
if (!fullPath)
|
|
115
|
-
return;
|
|
116
|
-
const ext = path.extname(fullPath).toLowerCase();
|
|
117
|
-
if (ext !== '.md' && ext !== '.markdown') {
|
|
118
|
-
await ctx.reply('⚠️ Telegraph works best with Markdown files (.md)');
|
|
119
|
-
}
|
|
120
|
-
await ctx.reply('📤 Creating Telegraph page...');
|
|
121
|
-
const pageUrl = await createTelegraphFromFile(fullPath);
|
|
122
|
-
if (pageUrl) {
|
|
123
|
-
const fileName = path.basename(fullPath);
|
|
124
|
-
await replyFormatted(ctx, new EntityText()
|
|
125
|
-
.add('📄 ').bold(fileName).newline(2)
|
|
126
|
-
.link('Open in Instant View', pageUrl)
|
|
127
|
-
.build());
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
await ctx.reply('❌ Failed to create Telegraph page.');
|
|
131
|
-
}
|
|
54
|
+
void prewarmClaude(ctx, sessionKey);
|
|
132
55
|
}
|
|
133
56
|
//# sourceMappingURL=replies.js.map
|
|
@@ -12,14 +12,11 @@ import { sessionManager } from '../../../claude/session-manager.js';
|
|
|
12
12
|
import { queueRequest } from '../../../claude/request-queue.js';
|
|
13
13
|
import { summarizeTopicWithHaiku } from '../../../claude/auto-topic-haiku.js';
|
|
14
14
|
import { readLastAiTitle } from '../../../claude/session-jsonl.js';
|
|
15
|
-
import { isBotNameEnabled } from '../../../telegram/botname-settings.js';
|
|
16
15
|
import { namesThread } from '../../../telegram/thread-titles.js';
|
|
17
16
|
import { userPreferences } from '../../../providers/user-preferences.js';
|
|
18
17
|
import { parseSessionKey } from '../../../utils/session-key.js';
|
|
19
|
-
import { resolveShareableFile } from '../../file-access.js';
|
|
20
18
|
import { getSessionTopic, setSessionTopic } from '../command.handler.js';
|
|
21
19
|
import { getMsSinceTopicSet } from '../command/topic-store.js';
|
|
22
|
-
import { requireSession } from '../session-guard.js';
|
|
23
20
|
import { turnErrorReply } from '../../../claude/claude-auth.js';
|
|
24
21
|
export { requireSession } from '../session-guard.js';
|
|
25
22
|
export async function replyFeatureDisabled(ctx, feature) {
|
|
@@ -27,18 +24,17 @@ export async function replyFeatureDisabled(ctx, feature) {
|
|
|
27
24
|
}
|
|
28
25
|
/**
|
|
29
26
|
* Fire-and-forget topic update via a parallel Haiku call. Runs alongside
|
|
30
|
-
* the main agent turn so the
|
|
31
|
-
* immediately, without depending on the main agent calling
|
|
27
|
+
* the main agent turn so the status line and the thread name reflect the new
|
|
28
|
+
* topic almost immediately, without depending on the main agent calling
|
|
29
|
+
* telecoder_set_topic.
|
|
32
30
|
*/
|
|
33
31
|
export function fireAutoTopic(ctx, sessionKey, userMessage) {
|
|
34
32
|
if (!config.AUTO_TOPIC_HAIKU)
|
|
35
33
|
return;
|
|
36
|
-
// Fire if the topic will be visible somewhere — the
|
|
37
|
-
//
|
|
38
|
-
// Haiku calls.
|
|
34
|
+
// Fire if the topic will be visible somewhere — the status line or the
|
|
35
|
+
// thread's name. Skipping when nothing displays it avoids wasted Haiku calls.
|
|
39
36
|
const { chatId } = parseSessionKey(sessionKey);
|
|
40
|
-
const wantsTopic =
|
|
41
|
-
|| userPreferences.getShowTopicInStatusLine(chatId)
|
|
37
|
+
const wantsTopic = userPreferences.getShowTopicInStatusLine(chatId)
|
|
42
38
|
|| namesThread(sessionKey);
|
|
43
39
|
if (!wantsTopic)
|
|
44
40
|
return;
|
|
@@ -65,9 +61,8 @@ export function fireAutoTopic(ctx, sessionKey, userMessage) {
|
|
|
65
61
|
}
|
|
66
62
|
if (!topic)
|
|
67
63
|
return;
|
|
68
|
-
// Topic lives in the status line, not the Telegram
|
|
69
|
-
//
|
|
70
|
-
// we don't want to burn Telegram's bot-name rate limit on a no-op.
|
|
64
|
+
// Topic lives in the status line and the thread name, not the Telegram
|
|
65
|
+
// bot name, so no setMyName call.
|
|
71
66
|
setSessionTopic(sessionKey, topic);
|
|
72
67
|
}
|
|
73
68
|
catch (err) {
|
|
@@ -75,30 +70,13 @@ export function fireAutoTopic(ctx, sessionKey, userMessage) {
|
|
|
75
70
|
}
|
|
76
71
|
})();
|
|
77
72
|
}
|
|
78
|
-
/**
|
|
79
|
-
* Resolve a user-typed file path against the active session, enforcing the
|
|
80
|
-
* file-access rules (see bot/file-access.ts: the credential denylist for
|
|
81
|
-
* everyone, the project directory for guests, the workspace for admins) and
|
|
82
|
-
* that the target is an existing regular file.
|
|
83
|
-
*
|
|
84
|
-
* Every rejection is reported to the chat and returns null, so callers only
|
|
85
|
-
* need to early-return. Shared by the /file and /telegraph reply handlers —
|
|
86
|
-
* they used to carry identical copies of these three checks, which meant a
|
|
87
|
-
* tightening of the containment rule could reach one and miss the other.
|
|
88
|
-
*/
|
|
89
|
-
export async function resolveUserFilePath(ctx, sessionKey, filePath) {
|
|
90
|
-
const session = await requireSession(ctx, sessionKey);
|
|
91
|
-
if (!session)
|
|
92
|
-
return null;
|
|
93
|
-
return resolveShareableFile(ctx, session.workingDirectory, filePath);
|
|
94
|
-
}
|
|
95
73
|
/**
|
|
96
74
|
* Queue a turn and turn any failure into a user-facing error.
|
|
97
75
|
*
|
|
98
76
|
* "Queue cleared" is the normal signal that a newer message superseded this
|
|
99
77
|
* one, so it exits quietly. Anything else is logged as well as reported —
|
|
100
78
|
* three of the four call sites this replaces only replied to the chat, which
|
|
101
|
-
* left failures in the
|
|
79
|
+
* left failures in the suggestion-tap and throttle-retry paths
|
|
102
80
|
* invisible from the server side.
|
|
103
81
|
*/
|
|
104
82
|
export async function runQueuedTurn(ctx, sessionKey, message, label, run) {
|