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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The handful of Bot API calls `telecoder init` makes, over plain fetch
|
|
2
|
+
* The handful of Bot API calls `telecoder init` makes, over plain fetch, or
|
|
3
|
+
* through a proxy when the wizard found one (utils/telegram-proxy.ts).
|
|
3
4
|
*
|
|
4
|
-
* Not grammY: the wizard needs
|
|
5
|
+
* Not grammY: the wizard needs a handful of methods, wants to own the long poll (so
|
|
5
6
|
* Ctrl+C can cancel it), and must never let the token reach a log line — every
|
|
6
7
|
* error leaving this module has been through redactSecrets, and the token
|
|
7
8
|
* itself is replaced too, in case Telegram ever changes its shape.
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
* it, and nothing else should set it.
|
|
12
13
|
*/
|
|
13
14
|
import { redactSecrets } from '../../utils/sanitize.js';
|
|
15
|
+
import { fetchThroughProxy } from '../../utils/telegram-proxy.js';
|
|
14
16
|
export const DEFAULT_API_ROOT = 'https://api.telegram.org';
|
|
15
17
|
/** Telegram answered, with ok: false. */
|
|
16
18
|
export class TelegramApiError extends Error {
|
|
@@ -27,36 +29,50 @@ export class TelegramApiError extends Error {
|
|
|
27
29
|
}
|
|
28
30
|
/** Telegram couldn't be reached at all. The message is already redacted. */
|
|
29
31
|
export class TelegramNetworkError extends Error {
|
|
30
|
-
|
|
32
|
+
proxy;
|
|
33
|
+
/**
|
|
34
|
+
* @param proxy The proxy the request went through, if any, with its password
|
|
35
|
+
* taken out: a proxy that is down is the likelier cause then.
|
|
36
|
+
*/
|
|
37
|
+
constructor(message, proxy) {
|
|
31
38
|
super(message);
|
|
39
|
+
this.proxy = proxy;
|
|
32
40
|
this.name = 'TelegramNetworkError';
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
|
-
|
|
43
|
+
/** `proxyUrl` sends the calls through an HTTP or HTTPS proxy; `fetchImpl` replaces the transport outright (tests). */
|
|
44
|
+
export function createTelegramClient(token, { apiRoot = DEFAULT_API_ROOT, proxyUrl, fetchImpl = proxyUrl ? fetchThroughProxy(proxyUrl) : fetch } = {}) {
|
|
36
45
|
const base = `${apiRoot.replace(/\/+$/, '')}/bot${token}`;
|
|
37
46
|
const scrub = (text) => redactSecrets(text.replaceAll(token, '<token>'));
|
|
47
|
+
/** `params` as JSON, or a FormData when the call uploads a file. */
|
|
38
48
|
async function call(method, params = {}, signal, timeoutMs = 15_000) {
|
|
39
49
|
const timeout = AbortSignal.timeout(timeoutMs);
|
|
40
50
|
let res;
|
|
41
51
|
try {
|
|
42
52
|
res = await fetchImpl(`${base}/${method}`, {
|
|
43
53
|
method: 'POST',
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
// fetch writes a FormData's own content-type, boundary included.
|
|
55
|
+
...(params instanceof FormData
|
|
56
|
+
? { body: params }
|
|
57
|
+
: { headers: { 'content-type': 'application/json' }, body: JSON.stringify(params) }),
|
|
46
58
|
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
47
59
|
});
|
|
48
60
|
}
|
|
49
61
|
catch (error) {
|
|
50
62
|
if (signal?.aborted)
|
|
51
63
|
throw signal.reason ?? error;
|
|
52
|
-
throw new TelegramNetworkError(scrub(describeFetchError(error)));
|
|
64
|
+
throw new TelegramNetworkError(scrub(describeFetchError(error)), proxyUrl ? scrub(proxyUrl) : undefined);
|
|
53
65
|
}
|
|
54
66
|
let body;
|
|
55
67
|
try {
|
|
56
68
|
body = await res.json();
|
|
57
69
|
}
|
|
58
70
|
catch {
|
|
59
|
-
|
|
71
|
+
const what = scrub(`HTTP ${res.status}, not a Bot API answer`);
|
|
72
|
+
// Through a proxy that is the proxy talking (a 407, an error page), not Telegram.
|
|
73
|
+
if (proxyUrl)
|
|
74
|
+
throw new TelegramNetworkError(what, scrub(proxyUrl));
|
|
75
|
+
throw new TelegramApiError(method, res.status, what);
|
|
60
76
|
}
|
|
61
77
|
if (!body.ok) {
|
|
62
78
|
throw new TelegramApiError(method, body.error_code ?? res.status, scrub(body.description ?? `HTTP ${res.status}`));
|
|
@@ -73,10 +89,20 @@ export function createTelegramClient(token, { apiRoot = DEFAULT_API_ROOT, fetchI
|
|
|
73
89
|
sendMessage: async (chatId, text, entities) => {
|
|
74
90
|
await call('sendMessage', { chat_id: chatId, text, ...(entities ? { entities } : {}) });
|
|
75
91
|
},
|
|
92
|
+
hasProfilePhoto: async (userId) => {
|
|
93
|
+
const photos = await call('getUserProfilePhotos', { user_id: userId, limit: 1 });
|
|
94
|
+
return photos.total_count > 0;
|
|
95
|
+
},
|
|
96
|
+
setProfilePhoto: async (jpeg, filename) => {
|
|
97
|
+
const form = new FormData();
|
|
98
|
+
form.set('photo', JSON.stringify({ type: 'static', photo: 'attach://picture' }));
|
|
99
|
+
form.set('picture', new Blob([jpeg], { type: 'image/jpeg' }), filename);
|
|
100
|
+
await call('setMyProfilePhoto', form, undefined, 30_000);
|
|
101
|
+
},
|
|
76
102
|
};
|
|
77
103
|
}
|
|
78
104
|
/** "fetch failed" says nothing; its cause (ENOTFOUND, ECONNREFUSED…) does. */
|
|
79
|
-
function describeFetchError(error) {
|
|
105
|
+
export function describeFetchError(error) {
|
|
80
106
|
let current = error;
|
|
81
107
|
let best = error instanceof Error ? error.message : String(error);
|
|
82
108
|
for (let depth = 0; depth < 4 && current instanceof Error; depth++) {
|
|
@@ -105,12 +105,12 @@ export function renderSystemdUnit(spec) {
|
|
|
105
105
|
systemdEnvironment('PATH', spec.pathEnv),
|
|
106
106
|
...spec.env.map(([key, value]) => systemdEnvironment(key, value)),
|
|
107
107
|
systemdEnvironment(SERVICE_MANAGER_ENV, 'systemd'),
|
|
108
|
-
'# always, not on-failure: /
|
|
108
|
+
'# always, not on-failure: /botrestart exits for systemd to bring the bot back.',
|
|
109
109
|
'# `systemctl --user stop` is still a stop — systemd never restarts a unit it',
|
|
110
110
|
'# was told to stop.',
|
|
111
111
|
'Restart=always',
|
|
112
112
|
'RestartSec=5',
|
|
113
|
-
`# ${RESTART_EXIT_CODE} is the exit /
|
|
113
|
+
`# ${RESTART_EXIT_CODE} is the exit /botrestart uses: logged as a clean exit, restarted all the same.`,
|
|
114
114
|
`SuccessExitStatus=${RESTART_EXIT_CODE}`,
|
|
115
115
|
`# ${EXIT_CONFIG} is a configuration problem (a missing setting, a rejected token):`,
|
|
116
116
|
'# starting again would only print the same error. Fix it, then',
|
|
@@ -129,7 +129,7 @@ const xml = (value) => assertOneLine(value)
|
|
|
129
129
|
.replace(/>/g, '>')
|
|
130
130
|
.replace(/"/g, '"');
|
|
131
131
|
/**
|
|
132
|
-
* The LaunchAgent. KeepAlive restarts on any non-zero exit (so /
|
|
132
|
+
* The LaunchAgent. KeepAlive restarts on any non-zero exit (so /botrestart's
|
|
133
133
|
* 75 and a crash both come back) and not on a zero one — launchd has no way to
|
|
134
134
|
* single out one exit code the way RestartPreventExitStatus= does, so a bot
|
|
135
135
|
* stopped by its config exits 0 under launchd instead (see
|
package/dist/config.js
CHANGED
|
@@ -14,6 +14,8 @@ const defaultEnvPath = configFile('.env');
|
|
|
14
14
|
// says *which* .env to load, so it can't come from inside one.
|
|
15
15
|
const envPath = legacyEnv('ENV_PATH') || defaultEnvPath;
|
|
16
16
|
const loadedEnv = loadEnv({ path: envPath });
|
|
17
|
+
/** The .env file this process read, for messages that tell the user where to add a setting. */
|
|
18
|
+
export const envFilePath = envPath;
|
|
17
19
|
/**
|
|
18
20
|
* Which values in the .env file are being ignored because the process was
|
|
19
21
|
* started with them already in its environment.
|
|
@@ -149,59 +151,47 @@ const envSchema = z.object({
|
|
|
149
151
|
// in the group but not admitted could never prompt the bot.
|
|
150
152
|
GROUP_MEMBERS_DEFAULT: z.enum(['contributor', 'spectator']).default('spectator'),
|
|
151
153
|
ANTHROPIC_API_KEY: z.string().optional(), // Optional - uses Claude Max subscription if not set
|
|
152
|
-
// OpenAI (TTS)
|
|
153
|
-
OPENAI_API_KEY: z.string().optional(),
|
|
154
154
|
WORKSPACE_DIR: z.string().default(process.env.HOME || '.'),
|
|
155
155
|
// The project this bot is for, set by /newbot for the bots it creates. A
|
|
156
156
|
// conversation with nowhere else to be starts here, and a thread in it is
|
|
157
157
|
// named without the project in front, since the bot's name already says it.
|
|
158
158
|
// Absolute, or relative to WORKSPACE_DIR.
|
|
159
159
|
HOME_PROJECT: z.string().optional(),
|
|
160
|
+
// The `claude` the Haiku side calls (topic names, the charter judge) run
|
|
161
|
+
// through: the copy bundled with the agent SDK, or CLAUDE_EXECUTABLE_PATH
|
|
162
|
+
// when the flag is false. The ptys spawn CLAUDE_BIN, else the one on PATH.
|
|
160
163
|
CLAUDE_EXECUTABLE_PATH: z.string().default('claude'),
|
|
161
164
|
CLAUDE_USE_BUNDLED_EXECUTABLE: z
|
|
162
165
|
.string()
|
|
163
166
|
.default('true')
|
|
164
167
|
.transform((val) => val.toLowerCase() === 'true'),
|
|
165
|
-
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
.default('false')
|
|
173
|
-
.transform((val) => val.toLowerCase() === 'true'),
|
|
168
|
+
// Whether the pty gets the Claude Code setup of the account the bot runs as:
|
|
169
|
+
// ~/.claude (CLAUDE.md, skills, commands, agents, settings.json), its MCP
|
|
170
|
+
// servers, its plugins' servers and its claude.ai connectors. 'auto' brings
|
|
171
|
+
// it along unless the bot has guests, who would otherwise work with the
|
|
172
|
+
// owner's own instructions and connectors; 'on'/'off' force it. See
|
|
173
|
+
// loadsUserSetup in src/claude/pty-spawn-config.ts.
|
|
174
|
+
CLAUDE_USER_SETUP: z.enum(['auto', 'on', 'off']).default('auto'),
|
|
174
175
|
// Path to a JSON file of extra MCP servers ({"mcpServers": {...}}) to hand the
|
|
175
|
-
// pty alongside the bot's own.
|
|
176
|
-
// the
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
// Named separately from CLAUDE_SDK_LOAD_USER_SETTINGS because MCP servers live
|
|
180
|
-
// in ~/.claude.json rather than in settings.json: --setting-sources cannot
|
|
181
|
-
// reach them either way.
|
|
176
|
+
// pty alongside the bot's own. For a server only the bot should have, and
|
|
177
|
+
// the one way to add any while the user setup stays out (CLAUDE_USER_SETUP):
|
|
178
|
+
// the spawn then passes --strict-mcp-config, and MCP servers live in
|
|
179
|
+
// ~/.claude.json rather than in settings.json.
|
|
182
180
|
EXTRA_MCP_CONFIG: z.string().optional(),
|
|
183
181
|
// Marketplace plugins to enable inside the agent, as the `plugin@marketplace`
|
|
184
|
-
// ids `claude plugin list` prints, comma-separated.
|
|
185
|
-
// ~/.claude/settings.json
|
|
186
|
-
// this
|
|
187
|
-
//
|
|
182
|
+
// ids `claude plugin list` prints, comma-separated. A plugin enabled in the
|
|
183
|
+
// terminal sits in ~/.claude/settings.json and comes with the user setup;
|
|
184
|
+
// this names the ones to bring while that stays out (CLAUDE_USER_SETUP), or
|
|
185
|
+
// to enable for the bot alone. See src/claude/enabled-plugins.ts.
|
|
188
186
|
CLAUDE_PLUGINS: z
|
|
189
187
|
.string()
|
|
190
188
|
.default('')
|
|
191
189
|
.transform((val) => val ? val.split(',').map((name) => name.trim()).filter(Boolean) : []),
|
|
192
|
-
CLAUDE_REASONING_SUMMARY: z
|
|
193
|
-
.string()
|
|
194
|
-
.default('true')
|
|
195
|
-
.transform((val) => val.toLowerCase() === 'true'),
|
|
196
190
|
BOT_NAME: z.string().default('TeleCoder'),
|
|
197
|
-
DYNAMIC_BOT_NAME: z
|
|
198
|
-
.string()
|
|
199
|
-
.default('false')
|
|
200
|
-
.transform((val) => val.toLowerCase() === 'true'),
|
|
201
191
|
// Fire a parallel Haiku side-call on every user message to derive a topic
|
|
202
|
-
// label
|
|
203
|
-
//
|
|
204
|
-
//
|
|
192
|
+
// label for the status line and the thread name, independent of the main
|
|
193
|
+
// agent's tool calls. Deferral-immune because it bypasses settingSources and
|
|
194
|
+
// tools entirely. Skipped when nothing in the chat shows the topic.
|
|
205
195
|
AUTO_TOPIC_HAIKU: z
|
|
206
196
|
.string()
|
|
207
197
|
.default('true')
|
|
@@ -217,34 +207,18 @@ const envSchema = z.object({
|
|
|
217
207
|
.string()
|
|
218
208
|
.default('false')
|
|
219
209
|
.transform((val) => val.toLowerCase() === 'true'),
|
|
220
|
-
|
|
221
|
-
//
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
.
|
|
227
|
-
.
|
|
228
|
-
.transform((val) => parseInt(val, 10)),
|
|
210
|
+
// The status line that closes every reply (project, effort, model, context),
|
|
211
|
+
// for chats that haven't used /footer. On: in Telegram it's the only
|
|
212
|
+
// place those show, and a new user doesn't know the command. The topic
|
|
213
|
+
// line comes with it; the last prompts and the resume command stay opt-in.
|
|
214
|
+
STATUS_LINE_DEFAULT: z
|
|
215
|
+
.string()
|
|
216
|
+
.default('true')
|
|
217
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
229
218
|
MAX_MESSAGE_LENGTH: z
|
|
230
219
|
.string()
|
|
231
220
|
.default('4000')
|
|
232
221
|
.transform((val) => parseInt(val, 10)),
|
|
233
|
-
// TTS Configuration
|
|
234
|
-
TTS_ENABLED: z.string().default('true').transform(toBool),
|
|
235
|
-
TTS_PROVIDER: z.enum(['groq', 'openai']).default('groq'),
|
|
236
|
-
TTS_MODEL: z.string().default('gpt-4o-mini-tts'),
|
|
237
|
-
TTS_VOICE: z.string().default('coral'),
|
|
238
|
-
TTS_INSTRUCTIONS: z.string().default('Speak in a friendly, natural conversational tone.'),
|
|
239
|
-
TTS_SPEED: z
|
|
240
|
-
.string()
|
|
241
|
-
.default('1.0')
|
|
242
|
-
.transform((val) => parseFloat(val)),
|
|
243
|
-
TTS_MAX_CHARS: z
|
|
244
|
-
.string()
|
|
245
|
-
.default('4096')
|
|
246
|
-
.transform((val) => parseInt(val, 10)),
|
|
247
|
-
TTS_RESPONSE_FORMAT: z.string().default('opus'),
|
|
248
222
|
IMAGE_MAX_FILE_SIZE_MB: z
|
|
249
223
|
.string()
|
|
250
224
|
.default('20')
|
|
@@ -256,20 +230,7 @@ const envSchema = z.object({
|
|
|
256
230
|
.string()
|
|
257
231
|
.default('19')
|
|
258
232
|
.transform((val) => parseInt(val, 10)),
|
|
259
|
-
// New config options
|
|
260
|
-
DANGEROUS_MODE: z
|
|
261
|
-
.string()
|
|
262
|
-
.default('false')
|
|
263
|
-
.transform((val) => val.toLowerCase() === 'true'),
|
|
264
|
-
MAX_LOOP_ITERATIONS: z
|
|
265
|
-
.string()
|
|
266
|
-
.default('5')
|
|
267
|
-
.transform((val) => parseInt(val, 10)),
|
|
268
233
|
AUTO_RESTORE_SESSION: z.string().default('false').transform(toBool),
|
|
269
|
-
// Telegraph (Instant View for long messages). Opt-in: every page is public
|
|
270
|
-
// on telegra.ph to anyone with the link, so replies — which can quote code,
|
|
271
|
-
// paths and anything else Claude read — are not published unless asked.
|
|
272
|
-
TELEGRAPH_ENABLED: z.string().default('false').transform(toBool),
|
|
273
234
|
// Voice transcription (Groq Whisper)
|
|
274
235
|
GROQ_API_KEY: z.string().optional(),
|
|
275
236
|
TRANSCRIBE_ENABLED: z.string().default('true').transform(toBool),
|
|
@@ -286,11 +247,6 @@ const envSchema = z.object({
|
|
|
286
247
|
.string()
|
|
287
248
|
.default('60000')
|
|
288
249
|
.transform((val) => parseInt(val, 10)),
|
|
289
|
-
// Transcribe command: send .txt file if transcript exceeds this many chars
|
|
290
|
-
TRANSCRIBE_FILE_THRESHOLD_CHARS: z
|
|
291
|
-
.string()
|
|
292
|
-
.default('4000')
|
|
293
|
-
.transform((val) => parseInt(val, 10)),
|
|
294
250
|
// Verbosity tier (quiet | normal | verbose | debug). Drives the defaults
|
|
295
251
|
// for several rendering flags below; per-chat /verbosity overrides this,
|
|
296
252
|
// and explicit env vars (CONTEXT_SHOW_USAGE etc.) override the tier.
|
|
@@ -305,21 +261,10 @@ const envSchema = z.object({
|
|
|
305
261
|
.string()
|
|
306
262
|
.default('true')
|
|
307
263
|
.transform((val) => val.toLowerCase() === 'true'),
|
|
308
|
-
//
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
.transform((val) => val.toLowerCase() === 'true'),
|
|
313
|
-
// Terminal UI verbose: show full commands/paths without truncation and longer session previews.
|
|
314
|
-
// When set, overrides the verbosity tier.
|
|
315
|
-
TERMINAL_UI_VERBOSE: z
|
|
316
|
-
.string()
|
|
317
|
-
.default('false')
|
|
318
|
-
.transform((val) => val.toLowerCase() === 'true'),
|
|
319
|
-
// Logging: show SDK hook JSON dumps (PreToolUse, PostToolUse, stderr, etc.)
|
|
320
|
-
// When false (default), verbose mode shows clean operational logs without hook noise.
|
|
321
|
-
// When true, verbose mode includes full hook JSON payloads and stderr output.
|
|
322
|
-
LOG_AGENT_HOOKS: z
|
|
264
|
+
// Show a tool's full input — the whole Bash command, the full path or URL —
|
|
265
|
+
// in the live status message instead of a shortened one. When set, overrides
|
|
266
|
+
// the verbosity tier, which turns it on from verbose up. Was TERMINAL_UI_VERBOSE.
|
|
267
|
+
FULL_TOOL_INPUTS: z
|
|
323
268
|
.string()
|
|
324
269
|
.default('false')
|
|
325
270
|
.transform((val) => val.toLowerCase() === 'true'),
|
|
@@ -329,33 +274,6 @@ const envSchema = z.object({
|
|
|
329
274
|
.string()
|
|
330
275
|
.default('1500')
|
|
331
276
|
.transform((val) => parseInt(val, 10)),
|
|
332
|
-
// Cancel behaviour: auto-cancel running query when user sends a new message
|
|
333
|
-
CANCEL_ON_NEW_MESSAGE: z
|
|
334
|
-
.string()
|
|
335
|
-
.default('false')
|
|
336
|
-
.transform((val) => val.toLowerCase() === 'true'),
|
|
337
|
-
// Agent watchdog: detect stuck/unresponsive agent queries
|
|
338
|
-
AGENT_WATCHDOG_ENABLED: z.string().default('true').transform(toBool),
|
|
339
|
-
AGENT_WATCHDOG_WARN_SECONDS: z
|
|
340
|
-
.string()
|
|
341
|
-
.default('30')
|
|
342
|
-
.transform((val) => parseInt(val, 10)),
|
|
343
|
-
AGENT_WATCHDOG_LOG_SECONDS: z
|
|
344
|
-
.string()
|
|
345
|
-
.default('10')
|
|
346
|
-
.transform((val) => parseInt(val, 10)),
|
|
347
|
-
AGENT_QUERY_TIMEOUT_MS: z
|
|
348
|
-
.string()
|
|
349
|
-
.default('0')
|
|
350
|
-
.transform((val) => parseInt(val, 10)), // 0 = disabled
|
|
351
|
-
AGENT_SILENCE_TIMEOUT_MS: z
|
|
352
|
-
.string()
|
|
353
|
-
.default('180000')
|
|
354
|
-
.transform((val) => parseInt(val, 10)), // 0 = disabled, default 3 minutes
|
|
355
|
-
AGENT_STALE_TOOL_TIMEOUT_MS: z
|
|
356
|
-
.string()
|
|
357
|
-
.default('180000')
|
|
358
|
-
.transform((val) => parseInt(val, 10)), // 0 = disabled, default 3 minutes
|
|
359
277
|
// Absolute wall-clock cap for a single PTY turn (ms). The turn is killed
|
|
360
278
|
// with a "turn exceeded" error if it runs longer. Default 2 h — long
|
|
361
279
|
// enough for genuinely intensive multi-step work; raise it if you regularly
|
|
@@ -364,6 +282,61 @@ const envSchema = z.object({
|
|
|
364
282
|
.string()
|
|
365
283
|
.default('7200000')
|
|
366
284
|
.transform((val) => parseInt(val, 10)),
|
|
285
|
+
// How long an idle PTY session's `claude` process is kept (ms). Each one
|
|
286
|
+
// holds a few hundred MB between turns; past this it is ended, and the next
|
|
287
|
+
// message resumes the conversation from its transcript in a new one. A
|
|
288
|
+
// session with a turn, a background task or a background shell running is
|
|
289
|
+
// never ended. Also what cleans up after a thread deleted by hand, which
|
|
290
|
+
// Telegram doesn't tell the bot about. 0 = keep them until a restart.
|
|
291
|
+
CLAUDE_PTY_IDLE_TIMEOUT_MS: z
|
|
292
|
+
.string()
|
|
293
|
+
.default('3600000')
|
|
294
|
+
.transform((val) => parseInt(val, 10)),
|
|
295
|
+
// `telecoder watch`: serve each chat's live Claude Code screen, read-only,
|
|
296
|
+
// on a Unix socket in ~/.telecoder/watch that only this user can open.
|
|
297
|
+
// false turns it off.
|
|
298
|
+
PTY_WATCH: z
|
|
299
|
+
.string()
|
|
300
|
+
.default('true')
|
|
301
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
302
|
+
// Start a chat's `claude` as soon as its conversation is chosen — /dir,
|
|
303
|
+
// /clear, /resume — instead of on the first message after, so that message
|
|
304
|
+
// doesn't wait for Claude Code to start. Skipped without a word when memory
|
|
305
|
+
// is under the guard's floor; one nobody ends up using is ended by the idle
|
|
306
|
+
// timeout like any other. false starts it on the first message.
|
|
307
|
+
PREWARM_CLAUDE: z
|
|
308
|
+
.string()
|
|
309
|
+
.default('true')
|
|
310
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
311
|
+
// Memory guard. Before a typed message starts a new `claude` for a chat
|
|
312
|
+
// — a new chat or thread, or one whose claude was ended — the machine's
|
|
313
|
+
// available memory (MemAvailable) is checked, less a few hundred MB for
|
|
314
|
+
// every claude still starting up (one just let through hasn't taken its
|
|
315
|
+
// memory yet). Under this many MB, claudes idle longer than
|
|
316
|
+
// MEMORY_GUARD_REAP_IDLE_MS are ended first; if that still leaves too
|
|
317
|
+
// little, the chat is asked whether to start anyway, end the longest-idle
|
|
318
|
+
// claude first, or drop the message. "auto" (the default) is a quarter of
|
|
319
|
+
// the machine's RAM, at least 1024 MB: with 1 GB left on an 8 GB box the
|
|
320
|
+
// machine is usually deep in swap already. 0 turns the guard off.
|
|
321
|
+
MEMORY_GUARD_MIN_AVAILABLE_MB: z
|
|
322
|
+
.string()
|
|
323
|
+
.default('auto')
|
|
324
|
+
.transform((val) => (val.trim().toLowerCase() === 'auto' ? 'auto' : parseInt(val, 10))),
|
|
325
|
+
// Swap in use above this many MB also counts as tight, so the guard asks
|
|
326
|
+
// even while MemAvailable looks fine. Off by default (0): pages stay in swap
|
|
327
|
+
// long after the pressure that put them there has passed, so on a machine
|
|
328
|
+
// that swaps at all this nags on every new chat.
|
|
329
|
+
MEMORY_GUARD_MAX_SWAP_USED_MB: z
|
|
330
|
+
.string()
|
|
331
|
+
.default('0')
|
|
332
|
+
.transform((val) => parseInt(val, 10)),
|
|
333
|
+
// The shorter idle window the guard reaps with when memory is tight, in ms.
|
|
334
|
+
// A chat whose claude was reaped this way resumes from its transcript on its
|
|
335
|
+
// next message, a few seconds slower. Default 300000 = 5 min.
|
|
336
|
+
MEMORY_GUARD_REAP_IDLE_MS: z
|
|
337
|
+
.string()
|
|
338
|
+
.default('300000')
|
|
339
|
+
.transform((val) => parseInt(val, 10)),
|
|
367
340
|
// How long a question from the agent — telecoder_ask_user buttons, a
|
|
368
341
|
// telecoder_poll_user poll, a Claude Code dialog relayed to the chat —
|
|
369
342
|
// waits for an answer before the turn carries on without one. The turn is
|
|
@@ -375,7 +348,9 @@ const envSchema = z.object({
|
|
|
375
348
|
.string()
|
|
376
349
|
.default('10')
|
|
377
350
|
.transform((val) => parseInt(val, 10)),
|
|
378
|
-
// HTTP proxy for Telegram API requests
|
|
351
|
+
// HTTP or HTTPS proxy for Telegram API requests and for downloading files
|
|
352
|
+
// sent to the bot (e.g. http://127.0.0.1:8080). Not SOCKS: the client is an
|
|
353
|
+
// HttpsProxyAgent (src/telegram/client-options.ts).
|
|
379
354
|
TELEGRAM_PROXY_URL: z.string().optional(),
|
|
380
355
|
// Completion notification (send a new message after long streaming tasks)
|
|
381
356
|
NOTIFICATION_ENABLED: z.string().default('true').transform(toBool),
|
|
@@ -402,12 +377,6 @@ const envSchema = z.object({
|
|
|
402
377
|
// Path or name of the `ccr` binary used for autostart. Defaults to `ccr`
|
|
403
378
|
// (resolved via PATH). Override if `ccr` lives somewhere systemd can't see.
|
|
404
379
|
CCR_BINARY: z.string().default('ccr'),
|
|
405
|
-
// When the Anthropic API reports a Max usage limit, automatically prompt
|
|
406
|
-
// the user with an inline keyboard offering to switch to CCR.
|
|
407
|
-
CCR_AUTO_PROMPT_ON_THROTTLE: z
|
|
408
|
-
.string()
|
|
409
|
-
.default('true')
|
|
410
|
-
.transform((val) => val.toLowerCase() === 'true'),
|
|
411
380
|
});
|
|
412
381
|
/**
|
|
413
382
|
* Print the configuration report and stop. Everything that keeps the bot from
|
|
@@ -419,9 +388,27 @@ function failConfig(problems) {
|
|
|
419
388
|
console.error(formatConfigReport(problems, { path: envPath, status: envFileStatus(loadedEnv) }, { instanceName: process.env.TELECODER_INSTANCE_NAME }));
|
|
420
389
|
exitForConfigError();
|
|
421
390
|
}
|
|
422
|
-
|
|
391
|
+
/**
|
|
392
|
+
* Settings that took a new name, old → new. The old name keeps working, read
|
|
393
|
+
* only when the new one isn't set, and index.ts says once at startup to rename
|
|
394
|
+
* it in the .env.
|
|
395
|
+
*/
|
|
396
|
+
export const RENAMED_SETTINGS = {
|
|
397
|
+
TERMINAL_UI_VERBOSE: 'FULL_TOOL_INPUTS',
|
|
398
|
+
};
|
|
399
|
+
/** `env` with each renamed setting's old value under its new name, unless the new one is set. */
|
|
400
|
+
export function withRenamedSettings(env) {
|
|
401
|
+
const out = { ...env };
|
|
402
|
+
for (const [old, now] of Object.entries(RENAMED_SETTINGS)) {
|
|
403
|
+
if (!out[now] && out[old])
|
|
404
|
+
out[now] = out[old];
|
|
405
|
+
}
|
|
406
|
+
return out;
|
|
407
|
+
}
|
|
408
|
+
const env = withRenamedSettings(process.env);
|
|
409
|
+
const parsed = envSchema.safeParse(env);
|
|
423
410
|
if (!parsed.success) {
|
|
424
|
-
failConfig(problemsFromIssues(parsed.error.issues,
|
|
411
|
+
failConfig(problemsFromIssues(parsed.error.issues, env));
|
|
425
412
|
}
|
|
426
413
|
/**
|
|
427
414
|
* ADMIN_USER_IDS narrows who, among the people ALLOWED_USER_IDS lets in, may
|
|
@@ -471,29 +458,67 @@ export const config = { ...parsed.data };
|
|
|
471
458
|
// honor the env value or fall back to the per-tier default; the startup name
|
|
472
459
|
// sync only renames the bot when BOT_NAME was asked for.
|
|
473
460
|
function isEnvSet(key) {
|
|
474
|
-
const raw =
|
|
461
|
+
const raw = env[key];
|
|
475
462
|
return raw !== undefined && raw !== '';
|
|
476
463
|
}
|
|
477
464
|
export const explicitFlags = {
|
|
478
465
|
CONTEXT_SHOW_USAGE: isEnvSet('CONTEXT_SHOW_USAGE'),
|
|
479
466
|
CONTEXT_NOTIFY_COMPACTION: isEnvSet('CONTEXT_NOTIFY_COMPACTION'),
|
|
480
|
-
|
|
467
|
+
FULL_TOOL_INPUTS: isEnvSet('FULL_TOOL_INPUTS'),
|
|
481
468
|
BOT_NAME: isEnvSet('BOT_NAME'),
|
|
482
469
|
};
|
|
483
470
|
// ---------------------------------------------------------------------------
|
|
484
471
|
// Derived helpers (used by index.ts, command.handler.ts, session-history.ts)
|
|
485
472
|
// ---------------------------------------------------------------------------
|
|
486
|
-
import
|
|
473
|
+
import * as fs from 'fs';
|
|
474
|
+
import { getStateDir, ensureStateDir, readJsonFile, writeJsonFile } from './utils/json-store.js';
|
|
487
475
|
/** Numeric bot ID extracted from the Telegram token (e.g. "123456" from "123456:ABC..."). */
|
|
488
476
|
export const BOT_ID = config.TELEGRAM_BOT_TOKEN.split(':')[0];
|
|
489
477
|
const STATE_DIR = getStateDir();
|
|
478
|
+
const botNameFileSchema = z.object({ name: z.string().min(1).max(64) });
|
|
479
|
+
const envBotName = config.BOT_NAME;
|
|
480
|
+
let botNameSource = explicitFlags.BOT_NAME ? 'env' : 'default';
|
|
481
|
+
/** The file holding the name set with `/botname`, one per bot. */
|
|
482
|
+
export function getBotNameFilePath() {
|
|
483
|
+
return path.join(STATE_DIR, `botname-${BOT_ID}.json`);
|
|
484
|
+
}
|
|
485
|
+
// A name set with /botname wins over BOT_NAME. It's applied here, as the config
|
|
486
|
+
// loads, so every module that reads config.BOT_NAME at import time sees it too.
|
|
487
|
+
{
|
|
488
|
+
const stored = readJsonFile(getBotNameFilePath(), botNameFileSchema, 'BotName')?.name;
|
|
489
|
+
if (stored) {
|
|
490
|
+
config.BOT_NAME = stored;
|
|
491
|
+
botNameSource = 'command';
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
export function getBotNameSource() {
|
|
495
|
+
return botNameSource;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Save the name set with `/botname`, or clear it (`undefined`) so the bot goes
|
|
499
|
+
* back to `BOT_NAME`. Updates `config.BOT_NAME` in place for the running process;
|
|
500
|
+
* the Telegram side is the caller's job. Throws when the file can't be written.
|
|
501
|
+
*/
|
|
502
|
+
export function setStoredBotName(name) {
|
|
503
|
+
const file = getBotNameFilePath();
|
|
504
|
+
if (name) {
|
|
505
|
+
ensureStateDir(STATE_DIR, 'BotName');
|
|
506
|
+
writeJsonFile(file, { name }, 'BotName', { rethrow: true });
|
|
507
|
+
config.BOT_NAME = name;
|
|
508
|
+
botNameSource = 'command';
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
fs.rmSync(file, { force: true });
|
|
512
|
+
config.BOT_NAME = envBotName;
|
|
513
|
+
botNameSource = explicitFlags.BOT_NAME ? 'env' : 'default';
|
|
514
|
+
}
|
|
490
515
|
/** Per-bot reload marker file path so multi-instance setups don't cross-restore. */
|
|
491
516
|
export function getReloadMarkerPath() {
|
|
492
517
|
return getReloadMarkerPathForBotId(BOT_ID);
|
|
493
518
|
}
|
|
494
519
|
/** Same as getReloadMarkerPath, but for an arbitrary bot ID — used by the
|
|
495
|
-
* launcher when it needs to write markers for sibling bots on /
|
|
496
|
-
* and /
|
|
520
|
+
* launcher when it needs to write markers for sibling bots on /botrestart all
|
|
521
|
+
* and /botrebuild all. */
|
|
497
522
|
export function getReloadMarkerPathForBotId(botId) {
|
|
498
523
|
return path.join(STATE_DIR, `pending-reload-${botId}.json`);
|
|
499
524
|
}
|