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
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `telecoder watch` — the live Claude Code screen behind a chat, read-only.
|
|
3
|
+
*
|
|
4
|
+
* The bot drives a real `claude` per chat and serves its screen on
|
|
5
|
+
* a socket (claude/pty-watch.ts). This command connects to it and shows that
|
|
6
|
+
* screen in this terminal as it changes: what you'd see had you typed the
|
|
7
|
+
* chat's messages into Claude Code yourself.
|
|
8
|
+
*
|
|
9
|
+
* It keeps its own copy of the screen and paints that row by row, so it works
|
|
10
|
+
* in a terminal of any size: a larger one shows the screen in its corner, a
|
|
11
|
+
* smaller one a part of it.
|
|
12
|
+
*/
|
|
13
|
+
import * as fs from 'fs';
|
|
14
|
+
import * as net from 'net';
|
|
15
|
+
import * as path from 'path';
|
|
16
|
+
import headless from '@xterm/headless';
|
|
17
|
+
import { getWatchDir } from '../../claude/pty-watch.js';
|
|
18
|
+
import { renderRows } from '../../claude/screen-render.js';
|
|
19
|
+
const { Terminal } = headless;
|
|
20
|
+
const POLL_MS = 500;
|
|
21
|
+
const FRAME_MS = 33;
|
|
22
|
+
const CONNECT_TIMEOUT_MS = 1500;
|
|
23
|
+
export function usage() {
|
|
24
|
+
return [
|
|
25
|
+
'Usage: telecoder watch [<project>] [--list]',
|
|
26
|
+
'',
|
|
27
|
+
'Shows the live Claude Code screen of a chat, read-only: what Claude Code looks like',
|
|
28
|
+
'while TeleCoder drives it. With several chats running it shows the most recently',
|
|
29
|
+
'active one; with none it waits for the next message. Ctrl+C leaves.',
|
|
30
|
+
'',
|
|
31
|
+
' <project> only a chat in this project (its folder name), or of this bot (@name)',
|
|
32
|
+
' --list list the running Claude Code sessions and exit',
|
|
33
|
+
'',
|
|
34
|
+
'PTY_WATCH=false in the .env turns it off.',
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
/** The project a session works in: its folder's name. */
|
|
38
|
+
export function projectOf(session) {
|
|
39
|
+
return path.basename(session.cwd) || session.cwd;
|
|
40
|
+
}
|
|
41
|
+
/** The session to show: the most recently active one that matches `filter`. */
|
|
42
|
+
export function pickSession(sessions, filter) {
|
|
43
|
+
const wanted = filter?.replace(/^@/, '').toLowerCase();
|
|
44
|
+
return sessions
|
|
45
|
+
.filter((s) => !wanted || projectOf(s).toLowerCase() === wanted || s.bot.toLowerCase() === wanted || s.key === wanted)
|
|
46
|
+
.sort((a, b) => b.lastActiveAt - a.lastActiveAt)[0];
|
|
47
|
+
}
|
|
48
|
+
function ago(ms) {
|
|
49
|
+
const s = Math.max(0, Math.round(ms / 1000));
|
|
50
|
+
if (s < 60)
|
|
51
|
+
return `${s}s`;
|
|
52
|
+
if (s < 3600)
|
|
53
|
+
return `${Math.round(s / 60)}m`;
|
|
54
|
+
return `${Math.round(s / 3600)}h`;
|
|
55
|
+
}
|
|
56
|
+
export function formatList(sessions, now = Date.now()) {
|
|
57
|
+
if (sessions.length === 0)
|
|
58
|
+
return ['No Claude Code session is running. One starts when a chat picks its project or gets its next message.'];
|
|
59
|
+
const rows = [...sessions]
|
|
60
|
+
.sort((a, b) => b.lastActiveAt - a.lastActiveAt)
|
|
61
|
+
.map((s) => [`@${s.bot}`, projectOf(s), `chat ${s.key}`, `active ${ago(now - s.lastActiveAt)} ago`]);
|
|
62
|
+
const widths = rows[0].map((_, i) => Math.max(...rows.map((r) => r[i].length)));
|
|
63
|
+
return rows.map((r) => r.map((cell, i) => cell.padEnd(widths[i])).join(' ').trimEnd());
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Which screen row goes at the top when only `visible` of `rows` fit. Claude
|
|
67
|
+
* Code fills its screen from the top, so the part to keep is the one that ends
|
|
68
|
+
* at the last row with something on it.
|
|
69
|
+
*/
|
|
70
|
+
export function cropStart(rows, visible, lastUsedRow) {
|
|
71
|
+
if (visible >= rows)
|
|
72
|
+
return 0;
|
|
73
|
+
return Math.max(0, Math.min(lastUsedRow + 1 - visible, rows - visible));
|
|
74
|
+
}
|
|
75
|
+
/** Ask one bot's socket for its sessions. Resolves with none when nothing answers. */
|
|
76
|
+
function listSocket(socketFile) {
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
const socket = net.createConnection(socketFile);
|
|
79
|
+
let buffered = '';
|
|
80
|
+
const done = (sessions) => {
|
|
81
|
+
socket.destroy();
|
|
82
|
+
resolve(sessions);
|
|
83
|
+
};
|
|
84
|
+
socket.setEncoding('utf8');
|
|
85
|
+
socket.setTimeout(CONNECT_TIMEOUT_MS, () => done([]));
|
|
86
|
+
socket.on('error', () => done([]));
|
|
87
|
+
socket.on('connect', () => socket.write('{"op":"list"}\n'));
|
|
88
|
+
socket.on('data', (data) => {
|
|
89
|
+
buffered += data;
|
|
90
|
+
const newline = buffered.indexOf('\n');
|
|
91
|
+
if (newline === -1)
|
|
92
|
+
return;
|
|
93
|
+
try {
|
|
94
|
+
const reply = JSON.parse(buffered.slice(0, newline));
|
|
95
|
+
done((reply.sessions ?? []).map((s) => ({ ...s, bot: reply.bot ?? '', socket: socketFile })));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
done([]);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
export async function discover(dir = getWatchDir()) {
|
|
104
|
+
let names;
|
|
105
|
+
try {
|
|
106
|
+
names = fs.readdirSync(dir).filter((name) => name.endsWith('.sock'));
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return { bots: 0, sessions: [] };
|
|
110
|
+
}
|
|
111
|
+
let bots = 0;
|
|
112
|
+
const all = await Promise.all(names.map(async (name) => {
|
|
113
|
+
const file = path.join(dir, name);
|
|
114
|
+
const alive = await new Promise((resolve) => {
|
|
115
|
+
const probe = net.createConnection(file);
|
|
116
|
+
probe.on('connect', () => { probe.destroy(); resolve(true); });
|
|
117
|
+
probe.on('error', () => resolve(false));
|
|
118
|
+
});
|
|
119
|
+
if (!alive)
|
|
120
|
+
return [];
|
|
121
|
+
bots++;
|
|
122
|
+
return listSocket(file);
|
|
123
|
+
}));
|
|
124
|
+
return { bots, sessions: all.flat() };
|
|
125
|
+
}
|
|
126
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
127
|
+
/** Paints one session's screen into the terminal until it ends or `signal` aborts. */
|
|
128
|
+
function show(session, out, signal) {
|
|
129
|
+
return new Promise((resolve) => {
|
|
130
|
+
const socket = net.createConnection(session.socket);
|
|
131
|
+
let mirror = null;
|
|
132
|
+
let painted = [];
|
|
133
|
+
let paintedFooter = '';
|
|
134
|
+
let dirty = false;
|
|
135
|
+
let buffered = '';
|
|
136
|
+
let settled = false;
|
|
137
|
+
const paint = () => {
|
|
138
|
+
if (!mirror || !dirty)
|
|
139
|
+
return;
|
|
140
|
+
dirty = false;
|
|
141
|
+
const width = out.columns || mirror.cols;
|
|
142
|
+
const height = out.rows || mirror.rows + 1;
|
|
143
|
+
const visible = Math.max(1, Math.min(mirror.rows, height - 1));
|
|
144
|
+
const cols = Math.min(mirror.cols, width);
|
|
145
|
+
const buffer = mirror.buffer.active;
|
|
146
|
+
let lastUsed = 0;
|
|
147
|
+
// Trimmed by hand: the snapshot fills every row with spaces.
|
|
148
|
+
for (let y = mirror.rows - 1; y >= 0; y--) {
|
|
149
|
+
if (buffer.getLine(buffer.baseY + y)?.translateToString(true).trim()) {
|
|
150
|
+
lastUsed = y;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const start = cropStart(mirror.rows, visible, lastUsed);
|
|
155
|
+
const rows = renderRows(mirror, { maxCols: cols }).slice(start, start + visible);
|
|
156
|
+
const clear = cols < width ? '\x1b[K' : '';
|
|
157
|
+
let frame = '';
|
|
158
|
+
rows.forEach((row, i) => {
|
|
159
|
+
if (painted[i] === row)
|
|
160
|
+
return;
|
|
161
|
+
painted[i] = row;
|
|
162
|
+
frame += `\x1b[${i + 1};1H${row}${clear}`;
|
|
163
|
+
});
|
|
164
|
+
const cropped = cols < mirror.cols || visible < mirror.rows;
|
|
165
|
+
const footer = [
|
|
166
|
+
' telecoder watch',
|
|
167
|
+
`@${session.bot}`,
|
|
168
|
+
projectOf(session),
|
|
169
|
+
'read-only',
|
|
170
|
+
'Ctrl+C leaves',
|
|
171
|
+
cropped ? `part of ${mirror.cols}x${mirror.rows} shown, enlarge the terminal for all` : '',
|
|
172
|
+
].filter(Boolean).join(' · ').concat(' ').slice(0, width);
|
|
173
|
+
if (footer !== paintedFooter && height > visible) {
|
|
174
|
+
paintedFooter = footer;
|
|
175
|
+
frame += `\x1b[${visible + 1};1H\x1b[0;7m${footer}\x1b[0m\x1b[K`;
|
|
176
|
+
}
|
|
177
|
+
if (frame)
|
|
178
|
+
out.write(frame);
|
|
179
|
+
};
|
|
180
|
+
const timer = setInterval(paint, FRAME_MS);
|
|
181
|
+
const repaintAll = () => {
|
|
182
|
+
painted = [];
|
|
183
|
+
paintedFooter = '';
|
|
184
|
+
dirty = true;
|
|
185
|
+
out.write('\x1b[2J');
|
|
186
|
+
};
|
|
187
|
+
out.on('resize', repaintAll);
|
|
188
|
+
const finish = (how) => {
|
|
189
|
+
if (settled)
|
|
190
|
+
return;
|
|
191
|
+
settled = true;
|
|
192
|
+
paint();
|
|
193
|
+
clearInterval(timer);
|
|
194
|
+
out.off('resize', repaintAll);
|
|
195
|
+
signal.removeEventListener('abort', onAbort);
|
|
196
|
+
socket.destroy();
|
|
197
|
+
resolve(how);
|
|
198
|
+
};
|
|
199
|
+
const onAbort = () => finish('aborted');
|
|
200
|
+
signal.addEventListener('abort', onAbort);
|
|
201
|
+
socket.setEncoding('utf8');
|
|
202
|
+
socket.on('connect', () => socket.write(`${JSON.stringify({ op: 'watch', key: session.key })}\n`));
|
|
203
|
+
socket.on('error', () => finish('ended'));
|
|
204
|
+
socket.on('close', () => finish('ended'));
|
|
205
|
+
socket.on('data', (data) => {
|
|
206
|
+
buffered += data;
|
|
207
|
+
let newline;
|
|
208
|
+
while ((newline = buffered.indexOf('\n')) !== -1) {
|
|
209
|
+
const line = buffered.slice(0, newline);
|
|
210
|
+
buffered = buffered.slice(newline + 1);
|
|
211
|
+
let message;
|
|
212
|
+
try {
|
|
213
|
+
message = JSON.parse(line);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (message.type === 'screen') {
|
|
219
|
+
mirror = new Terminal({ cols: message.cols ?? 120, rows: message.rows ?? 40, scrollback: 0, allowProposedApi: true });
|
|
220
|
+
repaintAll();
|
|
221
|
+
}
|
|
222
|
+
if ((message.type === 'screen' || message.type === 'data') && mirror && message.data) {
|
|
223
|
+
mirror.write(message.data, () => { dirty = true; });
|
|
224
|
+
}
|
|
225
|
+
else if (message.type === 'end' || message.type === 'error') {
|
|
226
|
+
// Let what was written reach the screen before leaving.
|
|
227
|
+
if (mirror)
|
|
228
|
+
mirror.write('', () => { dirty = true; finish('ended'); });
|
|
229
|
+
else
|
|
230
|
+
finish('ended');
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
export async function run(args, io) {
|
|
237
|
+
const filter = args.find((arg) => !arg.startsWith('--'));
|
|
238
|
+
const unknown = args.find((arg) => arg.startsWith('--') && arg !== '--list');
|
|
239
|
+
if (unknown) {
|
|
240
|
+
io.err(`Unknown option: ${unknown}`);
|
|
241
|
+
for (const line of usage())
|
|
242
|
+
io.err(line);
|
|
243
|
+
return 2;
|
|
244
|
+
}
|
|
245
|
+
if (args.includes('--list')) {
|
|
246
|
+
const found = await discover();
|
|
247
|
+
if (found.bots === 0) {
|
|
248
|
+
io.err('No running bot to watch. Start one with "telecoder start" or "telecoder service install".');
|
|
249
|
+
return 1;
|
|
250
|
+
}
|
|
251
|
+
for (const line of formatList(found.sessions))
|
|
252
|
+
io.out(line);
|
|
253
|
+
return 0;
|
|
254
|
+
}
|
|
255
|
+
const out = process.stdout;
|
|
256
|
+
const input = process.stdin;
|
|
257
|
+
if (!out.isTTY) {
|
|
258
|
+
io.err('telecoder watch draws a live screen, so it needs a terminal. "telecoder watch --list" works anywhere.');
|
|
259
|
+
return 1;
|
|
260
|
+
}
|
|
261
|
+
if ((await discover()).bots === 0) {
|
|
262
|
+
io.err('No running bot to watch. Start one with "telecoder start" or "telecoder service install".');
|
|
263
|
+
io.err('(A bot with PTY_WATCH=false, or one that runs as another user, can\'t be watched.)');
|
|
264
|
+
return 1;
|
|
265
|
+
}
|
|
266
|
+
const abort = new AbortController();
|
|
267
|
+
const leave = () => abort.abort();
|
|
268
|
+
const onKey = (key) => {
|
|
269
|
+
// Ctrl+C, Ctrl+D, q
|
|
270
|
+
if (key[0] === 3 || key[0] === 4 || key.toString() === 'q')
|
|
271
|
+
leave();
|
|
272
|
+
};
|
|
273
|
+
if (input.isTTY) {
|
|
274
|
+
input.setRawMode(true);
|
|
275
|
+
input.resume();
|
|
276
|
+
input.on('data', onKey);
|
|
277
|
+
}
|
|
278
|
+
process.on('SIGINT', leave);
|
|
279
|
+
process.on('SIGTERM', leave);
|
|
280
|
+
// The alternate screen, so leaving gives the terminal back as it was; no
|
|
281
|
+
// cursor and no wrapping, since every row is placed where it belongs.
|
|
282
|
+
out.write('\x1b[?1049h\x1b[?25l\x1b[?7l\x1b[2J\x1b[H');
|
|
283
|
+
const notice = (text) => {
|
|
284
|
+
const row = out.rows || 1;
|
|
285
|
+
out.write(`\x1b[${row};1H\x1b[0;2m${text.slice(0, out.columns || 80)}\x1b[0m\x1b[K`);
|
|
286
|
+
};
|
|
287
|
+
try {
|
|
288
|
+
let waitingSaid = false;
|
|
289
|
+
while (!abort.signal.aborted) {
|
|
290
|
+
const session = pickSession((await discover()).sessions, filter);
|
|
291
|
+
if (!session) {
|
|
292
|
+
if (!waitingSaid) {
|
|
293
|
+
notice(filter
|
|
294
|
+
? ` Waiting for a Claude Code session in "${filter}". Send that chat a message. Ctrl+C leaves.`
|
|
295
|
+
: ' Waiting for a Claude Code session. Send your bot a message. Ctrl+C leaves.');
|
|
296
|
+
waitingSaid = true;
|
|
297
|
+
}
|
|
298
|
+
await Promise.race([sleep(POLL_MS), new Promise((resolve) => abort.signal.addEventListener('abort', () => resolve(), { once: true }))]);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
waitingSaid = false;
|
|
302
|
+
const how = await show(session, out, abort.signal);
|
|
303
|
+
if (how === 'ended') {
|
|
304
|
+
notice(' That Claude Code session ended. Waiting for the next one. Ctrl+C leaves.');
|
|
305
|
+
waitingSaid = true;
|
|
306
|
+
await sleep(POLL_MS);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
finally {
|
|
311
|
+
out.write('\x1b[0m\x1b[?7h\x1b[?25h\x1b[?1049l');
|
|
312
|
+
if (input.isTTY) {
|
|
313
|
+
input.off('data', onKey);
|
|
314
|
+
input.setRawMode(false);
|
|
315
|
+
input.pause();
|
|
316
|
+
}
|
|
317
|
+
process.off('SIGINT', leave);
|
|
318
|
+
process.off('SIGTERM', leave);
|
|
319
|
+
}
|
|
320
|
+
return 0;
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=watch.js.map
|
package/dist/cli/dispatch.js
CHANGED
|
@@ -36,6 +36,11 @@ export const COMMANDS = {
|
|
|
36
36
|
usage: 'install|status|logs|restart|uninstall',
|
|
37
37
|
load: () => import('./commands/service.js'),
|
|
38
38
|
},
|
|
39
|
+
watch: {
|
|
40
|
+
summary: 'Show the live Claude Code screen of a chat, read-only',
|
|
41
|
+
usage: '[<project>] [--list]',
|
|
42
|
+
load: () => import('./commands/watch.js'),
|
|
43
|
+
},
|
|
39
44
|
help: {
|
|
40
45
|
summary: 'Show this help',
|
|
41
46
|
load: () => import('./commands/help.js'),
|
|
@@ -15,7 +15,7 @@ export const ENV_HEADER = [
|
|
|
15
15
|
'#',
|
|
16
16
|
'# Only the settings the wizard asked about are here; everything else runs on',
|
|
17
17
|
'# its default. Every setting, with what it does, is listed in .env.example',
|
|
18
|
-
'# (in the package, or https://github.com/
|
|
18
|
+
'# (in the package, or https://github.com/telecoderbot/telecoder/blob/main/.env.example)',
|
|
19
19
|
'# and in the Configuration Reference: https://telecoder.dev',
|
|
20
20
|
'# Run `telecoder init` again to change these, or edit this file by hand.',
|
|
21
21
|
];
|
package/dist/cli/init/flow.js
CHANGED
|
@@ -5,18 +5,25 @@
|
|
|
5
5
|
*
|
|
6
6
|
* The steps: check the machine (doctor's checks), decide what to do with an
|
|
7
7
|
* existing .env, get and check the bot token, find the owner's id by having
|
|
8
|
-
* them message the bot, pick a workspace
|
|
8
|
+
* them message the bot, pick a workspace, two optional
|
|
9
9
|
* features, write the file, and have the bot say hello.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Telegram is reached through the proxy the bot would use, when there is one:
|
|
12
|
+
* TELEGRAM_PROXY_URL or the usual proxy variables, from the environment or
|
|
13
|
+
* the .env being edited. One from the environment is written to the .env.
|
|
14
|
+
*
|
|
15
|
+
* Secrets are never printed: not the token, not the Groq key, not a proxy's
|
|
16
|
+
* password, not in errors (telegram.ts redacts those) and not in the summary
|
|
17
|
+
* before writing.
|
|
13
18
|
*/
|
|
14
19
|
import * as fs from 'fs';
|
|
15
20
|
import * as path from 'path';
|
|
16
21
|
import { parse as parseEnv } from 'dotenv';
|
|
17
22
|
import { isWellFormedBotToken, MALFORMED_TOKEN_MESSAGE, REJECTED_TOKEN_MESSAGE } from '../../utils/bot-token.js';
|
|
23
|
+
import { BOT_ICON_FILENAME, botIconJpeg } from '../../utils/bot-icon.js';
|
|
18
24
|
import { parseIdList } from '../../utils/id-list.js';
|
|
19
25
|
import { redactSecrets } from '../../utils/sanitize.js';
|
|
26
|
+
import { findProxy } from '../../utils/telegram-proxy.js';
|
|
20
27
|
import { backupFile, renderEnv, updateEnvText, writeEnvFile } from './env-file.js';
|
|
21
28
|
import { isAbort } from './prompter.js';
|
|
22
29
|
import { TelegramApiError, TelegramNetworkError, } from './telegram.js';
|
|
@@ -114,7 +121,7 @@ async function wizard(opts, deps, interactive, markWritten) {
|
|
|
114
121
|
show(r);
|
|
115
122
|
const ptyWorks = pre.nodePty.every((r) => r.status === 'ok');
|
|
116
123
|
if (!ptyWorks)
|
|
117
|
-
p.say('
|
|
124
|
+
p.say(' TeleCoder drives Claude Code in a pty, so chats will fail until it loads.');
|
|
118
125
|
p.say('');
|
|
119
126
|
// ── 2. An existing .env ─────────────────────────────────────
|
|
120
127
|
let existing = {};
|
|
@@ -147,8 +154,22 @@ async function wizard(opts, deps, interactive, markWritten) {
|
|
|
147
154
|
p.say('');
|
|
148
155
|
}
|
|
149
156
|
const editing = existingText !== undefined;
|
|
157
|
+
// The proxy the bot would use: the environment wins over the file, as it
|
|
158
|
+
// does there.
|
|
159
|
+
const proxy = findProxy((setting) => deps.env[setting] ?? existing[setting]);
|
|
160
|
+
// One that only the shell has is gone when a service starts the bot.
|
|
161
|
+
const saveProxy = proxy !== undefined && deps.env[proxy.setting] !== undefined
|
|
162
|
+
&& existing.TELEGRAM_PROXY_URL !== proxy.url;
|
|
163
|
+
if (proxy) {
|
|
164
|
+
const from = deps.env[proxy.setting] !== undefined ? "your shell's environment" : 'the current .env';
|
|
165
|
+
p.say(`Reaching Telegram through the proxy ${redactSecrets(proxy.url)} (${proxy.setting} in ${from}).`);
|
|
166
|
+
if (saveProxy) {
|
|
167
|
+
p.say(' A service starts TeleCoder outside your shell, so the proxy goes in the .env too, as TELEGRAM_PROXY_URL.');
|
|
168
|
+
}
|
|
169
|
+
p.say('');
|
|
170
|
+
}
|
|
150
171
|
// ── 3. Bot token ────────────────────────────────────────────
|
|
151
|
-
const { token, bot, client } = await stepToken(opts, deps, interactive, editing ? existing.TELEGRAM_BOT_TOKEN : undefined);
|
|
172
|
+
const { token, bot, client } = await stepToken(opts, deps, interactive, editing ? existing.TELEGRAM_BOT_TOKEN : undefined, proxy?.url);
|
|
152
173
|
p.say(`Connected to @${bot.username}`);
|
|
153
174
|
p.say('');
|
|
154
175
|
// ── 4. Owner ────────────────────────────────────────────────
|
|
@@ -157,47 +178,32 @@ async function wizard(opts, deps, interactive, markWritten) {
|
|
|
157
178
|
// ── 5. Workspace ────────────────────────────────────────────
|
|
158
179
|
const workspace = await stepWorkspace(opts, deps, interactive, editing ? existing.WORKSPACE_DIR : undefined);
|
|
159
180
|
p.say('');
|
|
160
|
-
// ── 6.
|
|
161
|
-
const currentTransport = existing.CLAUDE_METHOD_DEFAULT === 'pty' ? 'pty' : 'sdk';
|
|
162
|
-
let transport = opts.transport ?? currentTransport;
|
|
163
|
-
if (interactive && !opts.transport) {
|
|
164
|
-
transport = await p.choose('How should TeleCoder run Claude Code? (/method switches it per chat later)', [
|
|
165
|
-
{ key: 'sdk', label: 'SDK: the Claude Agent SDK. Simplest, and it tracks cost per turn.' },
|
|
166
|
-
{ key: 'pty', label: 'PTY: your own `claude` CLI in a terminal, its dialogs relayed to Telegram. More moving parts; needs node-pty.' },
|
|
167
|
-
], currentTransport);
|
|
168
|
-
}
|
|
169
|
-
if (transport === 'pty' && !ptyWorks)
|
|
170
|
-
p.say('! node-pty did not load (see above): PTY chats will fail until it does.');
|
|
171
|
-
p.say('');
|
|
172
|
-
// ── 7. Optional features ────────────────────────────────────
|
|
181
|
+
// ── 6. Optional features ────────────────────────────────────
|
|
173
182
|
const groqKey = await stepVoice(opts, deps, interactive, editing ? existing.GROQ_API_KEY : undefined);
|
|
174
|
-
const
|
|
175
|
-
let telegraph = opts.telegraph ?? wasTelegraph;
|
|
176
|
-
if (interactive && opts.telegraph === undefined) {
|
|
177
|
-
telegraph = await p.confirm('Publish long replies as Telegraph (Instant View) pages too? The pages are public to anyone with the link, and can\'t be deleted.', wasTelegraph);
|
|
178
|
-
}
|
|
183
|
+
const icon = await stepIcon(opts, client, bot);
|
|
179
184
|
p.say('');
|
|
180
|
-
// ──
|
|
185
|
+
// ── 7. Write ────────────────────────────────────────────────
|
|
181
186
|
const values = {
|
|
182
187
|
TELEGRAM_BOT_TOKEN: token,
|
|
183
188
|
ALLOWED_USER_IDS: owner.idList,
|
|
184
189
|
WORKSPACE_DIR: workspace,
|
|
185
|
-
CLAUDE_METHOD_DEFAULT: transport,
|
|
186
190
|
};
|
|
187
191
|
Object.assign(values, claudeLogin);
|
|
188
192
|
if (groqKey)
|
|
189
193
|
values.GROQ_API_KEY = groqKey;
|
|
190
|
-
if (
|
|
191
|
-
values.
|
|
194
|
+
if (proxy && saveProxy)
|
|
195
|
+
values.TELEGRAM_PROXY_URL = proxy.url;
|
|
192
196
|
p.say(`About to write ${deps.envPath}:`);
|
|
193
197
|
p.say(` Bot @${bot.username} (token hidden)`);
|
|
194
198
|
p.say(` Allowed users ${owner.idList}`);
|
|
195
199
|
p.say(` Workspace ${workspace}`);
|
|
196
|
-
p.say(` Transport ${transport.toUpperCase()}`);
|
|
197
200
|
for (const key of Object.keys(claudeLogin))
|
|
198
201
|
p.say(` Claude login ${key}=<hidden>`);
|
|
199
|
-
p.say(` Voice ${groqKey ? 'on (Groq key hidden)' : 'off'}`);
|
|
200
|
-
|
|
202
|
+
p.say(` Voice ${groqKey ? 'on (Groq key hidden)' : 'off (run telecoder init again to add it)'}`);
|
|
203
|
+
if (proxy && saveProxy)
|
|
204
|
+
p.say(` Proxy ${redactSecrets(proxy.url)}`);
|
|
205
|
+
if (icon)
|
|
206
|
+
p.say(' Bot picture the TeleCoder icon (--no-icon to skip)');
|
|
201
207
|
if (interactive && !await p.confirm('Write it?', true))
|
|
202
208
|
throw new Stop('Nothing was written.', 1);
|
|
203
209
|
let content;
|
|
@@ -208,8 +214,6 @@ async function wizard(opts, deps, interactive, markWritten) {
|
|
|
208
214
|
updates[key] = value;
|
|
209
215
|
if (!groqKey && existing.GROQ_API_KEY)
|
|
210
216
|
updates.GROQ_API_KEY = undefined;
|
|
211
|
-
if (!telegraph && wasTelegraph)
|
|
212
|
-
updates.TELEGRAPH_ENABLED = 'false';
|
|
213
217
|
content = updateEnvText(existingText, updates);
|
|
214
218
|
}
|
|
215
219
|
else {
|
|
@@ -221,6 +225,16 @@ async function wizard(opts, deps, interactive, markWritten) {
|
|
|
221
225
|
if (owner.otherRoles) {
|
|
222
226
|
p.say('! ADMIN_USER_IDS / APPROVER_USER_IDS are set in this file: check they are still in ALLOWED_USER_IDS.');
|
|
223
227
|
}
|
|
228
|
+
if (icon) {
|
|
229
|
+
try {
|
|
230
|
+
await client.setProfilePhoto(botIconJpeg(), BOT_ICON_FILENAME);
|
|
231
|
+
p.say(`✓ Gave @${bot.username} the TeleCoder icon`);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
p.say(`! Couldn't set the bot's picture: ${describeTelegramError(error)}`);
|
|
235
|
+
p.say(' The bot works without one. @BotFather can set a picture too: Edit Bot, then Edit Botpic.');
|
|
236
|
+
}
|
|
237
|
+
}
|
|
224
238
|
// ── 9. Hello, and what next ─────────────────────────────────
|
|
225
239
|
if (!opts.noTestMessage) {
|
|
226
240
|
try {
|
|
@@ -239,11 +253,29 @@ async function wizard(opts, deps, interactive, markWritten) {
|
|
|
239
253
|
p.say('Now:');
|
|
240
254
|
p.say(` ${startCommand.padEnd(18)}run the bot, then message it on Telegram`);
|
|
241
255
|
p.say(` ${'telecoder doctor'.padEnd(18)}check the setup again any time`);
|
|
242
|
-
// A checkout runs under pm2
|
|
243
|
-
if (interactive && deps.requestService && !deps.isCheckout
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
256
|
+
// A checkout runs under pm2; the service is for npm installs.
|
|
257
|
+
if (interactive && deps.requestService && !deps.isCheckout) {
|
|
258
|
+
const plan = deps.planService ? await deps.planService() : undefined;
|
|
259
|
+
if (plan && !plan.ready) {
|
|
260
|
+
// Nothing to approve: say what stands in the way instead of asking.
|
|
261
|
+
p.say('');
|
|
262
|
+
p.say(plan.manager ? `! telecoder service install would set up ${plan.lines[0]}` : `! ${plan.lines[0]}`);
|
|
263
|
+
for (const line of plan.lines.slice(1))
|
|
264
|
+
p.say(` ${line}`);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
let question = 'Keep it running in the background now (telecoder service install)?';
|
|
268
|
+
if (plan) {
|
|
269
|
+
p.say('');
|
|
270
|
+
p.say(`telecoder service install keeps it running in the background. Here that is ${plan.lines[0]}`);
|
|
271
|
+
for (const line of plan.lines.slice(1))
|
|
272
|
+
p.say(` ${line}`);
|
|
273
|
+
question = `Set up the ${plan.manager === 'launchd' ? 'LaunchAgent' : 'systemd service'} now?`;
|
|
274
|
+
}
|
|
275
|
+
if (await p.confirm(question, true)) {
|
|
276
|
+
deps.requestService();
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
247
279
|
}
|
|
248
280
|
p.say('Next: run `telecoder service install` to keep it running in the background.');
|
|
249
281
|
}
|
|
@@ -278,8 +310,9 @@ async function stepEnvLogin(deps, interactive, vars) {
|
|
|
278
310
|
if (!found.length)
|
|
279
311
|
return {};
|
|
280
312
|
const names = found.join(' and ');
|
|
281
|
-
p.say(`! Claude Code
|
|
282
|
-
p.say(
|
|
313
|
+
p.say(`! Claude Code logs in with ${names} from your shell's environment.`);
|
|
314
|
+
p.say(` When TeleCoder runs as a service, it starts outside your shell and doesn't have ${names}, so Claude Code would be logged out.`);
|
|
315
|
+
p.say(` The wizard can put ${names} in TeleCoder's .env, so TeleCoder always has it.`);
|
|
283
316
|
const save = interactive
|
|
284
317
|
? await p.confirm(`Save ${names} in the .env too (readable by you only)?`, true)
|
|
285
318
|
: true;
|
|
@@ -295,10 +328,10 @@ async function stepEnvLogin(deps, interactive, vars) {
|
|
|
295
328
|
export function cleanToken(raw) {
|
|
296
329
|
return raw.trim().replace(/^(['"])(.*)\1$/, '$2').trim();
|
|
297
330
|
}
|
|
298
|
-
async function stepToken(opts, deps, interactive, current) {
|
|
331
|
+
async function stepToken(opts, deps, interactive, current, proxyUrl) {
|
|
299
332
|
const p = deps.prompter;
|
|
300
333
|
const check = async (token) => {
|
|
301
|
-
const client = deps.makeClient(token);
|
|
334
|
+
const client = deps.makeClient(token, proxyUrl);
|
|
302
335
|
const bot = await client.getMe();
|
|
303
336
|
return { token, bot, client };
|
|
304
337
|
};
|
|
@@ -312,7 +345,7 @@ async function stepToken(opts, deps, interactive, current) {
|
|
|
312
345
|
return await check(token);
|
|
313
346
|
}
|
|
314
347
|
catch (error) {
|
|
315
|
-
throw new Stop(
|
|
348
|
+
throw new Stop(describeFirstCallError(error));
|
|
316
349
|
}
|
|
317
350
|
}
|
|
318
351
|
if (!interactive) {
|
|
@@ -326,7 +359,7 @@ async function stepToken(opts, deps, interactive, current) {
|
|
|
326
359
|
return found;
|
|
327
360
|
}
|
|
328
361
|
catch (error) {
|
|
329
|
-
p.say(`The current token doesn't work: ${
|
|
362
|
+
p.say(`The current token doesn't work: ${describeFirstCallError(error)}`);
|
|
330
363
|
}
|
|
331
364
|
}
|
|
332
365
|
p.say('Bot token. If you don\'t have a bot yet:');
|
|
@@ -346,7 +379,7 @@ async function stepToken(opts, deps, interactive, current) {
|
|
|
346
379
|
return await check(token);
|
|
347
380
|
}
|
|
348
381
|
catch (error) {
|
|
349
|
-
p.say(
|
|
382
|
+
p.say(describeFirstCallError(error));
|
|
350
383
|
if (error instanceof TelegramNetworkError && await p.confirm('Try again?', true))
|
|
351
384
|
continue;
|
|
352
385
|
break;
|
|
@@ -460,7 +493,7 @@ async function captureOwner(deps, client, bot) {
|
|
|
460
493
|
return null;
|
|
461
494
|
}
|
|
462
495
|
p.say(`Now open https://t.me/${bot.username} and send /start, from your own account.`);
|
|
463
|
-
p.say('The bot replies
|
|
496
|
+
p.say('The bot replies there, and this setup then asks you here to confirm it was you.');
|
|
464
497
|
p.say(`Waiting for it, up to ${Math.round(waitMs / 60_000)} minutes. Or type your numeric id and press Enter. Ctrl+C cancels.`);
|
|
465
498
|
const deadline = now() + waitMs;
|
|
466
499
|
let found = null;
|
|
@@ -562,7 +595,7 @@ async function stepWorkspace(opts, deps, interactive, current) {
|
|
|
562
595
|
const def = current ?? suggestWorkspace(deps.homedir);
|
|
563
596
|
if (!interactive)
|
|
564
597
|
return def;
|
|
565
|
-
p.say('Workspace: the folder your projects are in. /
|
|
598
|
+
p.say('Workspace: the folder your projects are in. /dir picks one of them for Claude to work in,');
|
|
566
599
|
p.say('and admins can fetch files from anywhere inside it with /file.');
|
|
567
600
|
for (;;) {
|
|
568
601
|
const answer = await p.ask('Workspace directory:', { default: tildify(def, deps.homedir) });
|
|
@@ -599,6 +632,23 @@ function isDir(dir) {
|
|
|
599
632
|
return false;
|
|
600
633
|
}
|
|
601
634
|
}
|
|
635
|
+
/**
|
|
636
|
+
* Whether to give the bot the TeleCoder icon. A bot without a picture gets it
|
|
637
|
+
* without being asked: a picture beats a grey initial, the summary says so before
|
|
638
|
+
* anything is written, and --no-icon is there for whoever disagrees. A picture
|
|
639
|
+
* the bot already has is only replaced when --icon asks for it.
|
|
640
|
+
*/
|
|
641
|
+
async function stepIcon(opts, client, bot) {
|
|
642
|
+
if (opts.icon !== undefined)
|
|
643
|
+
return opts.icon;
|
|
644
|
+
try {
|
|
645
|
+
return !await client.hasProfilePhoto(bot.id);
|
|
646
|
+
}
|
|
647
|
+
catch {
|
|
648
|
+
// Can't tell, so leave the picture alone.
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
602
652
|
async function stepVoice(opts, deps, interactive, current) {
|
|
603
653
|
const p = deps.prompter;
|
|
604
654
|
if (opts.groqKeyEnv) {
|
|
@@ -609,7 +659,8 @@ async function stepVoice(opts, deps, interactive, current) {
|
|
|
609
659
|
}
|
|
610
660
|
if (!interactive)
|
|
611
661
|
return current;
|
|
612
|
-
const on = await p.confirm('
|
|
662
|
+
const on = await p.confirm('Optional: transcribe voice notes with Groq Whisper? Needs a Groq API key '
|
|
663
|
+
+ '(https://console.groq.com/keys; it has a free tier). You can turn this on later by running telecoder init again.', Boolean(current));
|
|
613
664
|
if (!on)
|
|
614
665
|
return undefined;
|
|
615
666
|
if (current && await p.confirm('Keep the current Groq key?', true))
|
|
@@ -631,8 +682,24 @@ export function describeTelegramError(error) {
|
|
|
631
682
|
return `Telegram said: ${error.description}`;
|
|
632
683
|
}
|
|
633
684
|
if (error instanceof TelegramNetworkError) {
|
|
685
|
+
if (error.proxy) {
|
|
686
|
+
return `Couldn't reach api.telegram.org through the proxy ${error.proxy} (${error.message}). ` +
|
|
687
|
+
'Check that the proxy is running and reachable, and try again.';
|
|
688
|
+
}
|
|
634
689
|
return `Couldn't reach api.telegram.org (${error.message}). Check the network connection, and try again.`;
|
|
635
690
|
}
|
|
636
691
|
return redactSecrets(error instanceof Error ? error.message : String(error));
|
|
637
692
|
}
|
|
693
|
+
/**
|
|
694
|
+
* The same for the wizard's first call to Telegram, the token check. A
|
|
695
|
+
* network failure there may mean Telegram is blocked on this network, so it
|
|
696
|
+
* names the setting that gets around that, as the bot's own startup check does.
|
|
697
|
+
*/
|
|
698
|
+
export function describeFirstCallError(error) {
|
|
699
|
+
const said = describeTelegramError(error);
|
|
700
|
+
if (!(error instanceof TelegramNetworkError) || error.proxy)
|
|
701
|
+
return said;
|
|
702
|
+
return `${said} If Telegram is blocked on this network, run the wizard with TELEGRAM_PROXY_URL ` +
|
|
703
|
+
'set to an HTTP or HTTPS proxy (e.g. http://127.0.0.1:8080).';
|
|
704
|
+
}
|
|
638
705
|
//# sourceMappingURL=flow.js.map
|
|
@@ -32,6 +32,14 @@ export function createTerminalPrompter(input = process.stdin, output = process.s
|
|
|
32
32
|
callback();
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
|
+
// readline takes the terminal's width from its output stream. Without it, it
|
|
36
|
+
// assumes an endless line, and after a question that wraps it parks the cursor
|
|
37
|
+
// at the right edge of the screen, where the typed answer then lands.
|
|
38
|
+
Object.defineProperties(echo, {
|
|
39
|
+
columns: { get: () => output.columns },
|
|
40
|
+
rows: { get: () => output.rows },
|
|
41
|
+
});
|
|
42
|
+
output.on?.('resize', () => echo.emit('resize'));
|
|
35
43
|
let rl;
|
|
36
44
|
const open = () => {
|
|
37
45
|
if (rl)
|