telecoder 0.0.0-stage → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +363 -0
- package/CHANGELOG.md +1186 -0
- package/LICENSE +22 -0
- package/README.md +126 -2
- package/dist/audio/transcribe.js +50 -0
- package/dist/bin/mcp-server.js +378 -0
- package/dist/bin/tool-result.js +22 -0
- package/dist/bot/access/group-access.js +147 -0
- package/dist/bot/bot.js +592 -0
- package/dist/bot/file-access.js +141 -0
- package/dist/bot/handlers/command/access.js +407 -0
- package/dist/bot/handlers/command/admin.js +827 -0
- package/dist/bot/handlers/command/auto-approve.js +138 -0
- package/dist/bot/handlers/command/btw.js +224 -0
- package/dist/bot/handlers/command/cost.js +409 -0
- package/dist/bot/handlers/command/media.js +197 -0
- package/dist/bot/handlers/command/model.js +305 -0
- package/dist/bot/handlers/command/prefs-scope.js +197 -0
- package/dist/bot/handlers/command/project.js +536 -0
- package/dist/bot/handlers/command/resume.js +321 -0
- package/dist/bot/handlers/command/session.js +438 -0
- package/dist/bot/handlers/command/settings.js +1012 -0
- package/dist/bot/handlers/command/shared.js +210 -0
- package/dist/bot/handlers/command/streaming-mode.js +16 -0
- package/dist/bot/handlers/command/tasks.js +513 -0
- package/dist/bot/handlers/command/topic-store.js +113 -0
- package/dist/bot/handlers/command/topic.js +80 -0
- package/dist/bot/handlers/command.handler.js +772 -0
- package/dist/bot/handlers/fork.handler.js +1109 -0
- package/dist/bot/handlers/media-fallback.js +121 -0
- package/dist/bot/handlers/message/replies.js +133 -0
- package/dist/bot/handlers/message/shared.js +117 -0
- package/dist/bot/handlers/message/throttle.js +49 -0
- package/dist/bot/handlers/message/turn-notify.js +169 -0
- package/dist/bot/handlers/message/turn-runner.js +141 -0
- package/dist/bot/handlers/message.handler.js +107 -0
- package/dist/bot/handlers/newbot.handler.js +221 -0
- package/dist/bot/handlers/photo.handler.js +327 -0
- package/dist/bot/handlers/prompts.handler.js +343 -0
- package/dist/bot/handlers/running-note.js +44 -0
- package/dist/bot/handlers/schedule.handler.js +303 -0
- package/dist/bot/handlers/session-guard.js +78 -0
- package/dist/bot/handlers/suggestion.handler.js +84 -0
- package/dist/bot/handlers/tree.handler.js +480 -0
- package/dist/bot/handlers/view.js +41 -0
- package/dist/bot/handlers/voice.handler.js +209 -0
- package/dist/bot/middleware/admin-only.js +49 -0
- package/dist/bot/middleware/auth.middleware.js +122 -0
- package/dist/bot/middleware/group-mention.middleware.js +139 -0
- package/dist/bot/middleware/group-role.middleware.js +75 -0
- package/dist/bot/middleware/message-batcher.js +87 -0
- package/dist/bot/middleware/queued-messages.js +971 -0
- package/dist/bot/middleware/stale-filter.js +31 -0
- package/dist/build-info.json +8 -0
- package/dist/claude/agent-watchdog.js +162 -0
- package/dist/claude/agent.js +1458 -0
- package/dist/claude/ask-user.js +295 -0
- package/dist/claude/auto-approve.js +225 -0
- package/dist/claude/auto-topic-haiku.js +126 -0
- package/dist/claude/available-commands.js +153 -0
- package/dist/claude/carry-over.js +27 -0
- package/dist/claude/ccr-shim.js +46 -0
- package/dist/claude/charter-judge.js +214 -0
- package/dist/claude/claude-auth.js +121 -0
- package/dist/claude/command-parser.js +200 -0
- package/dist/claude/cost-overlay-scraper.js +129 -0
- package/dist/claude/enabled-plugins.js +56 -0
- package/dist/claude/fork-tree.js +393 -0
- package/dist/claude/held-query.js +190 -0
- package/dist/claude/in-flight-tracker.js +61 -0
- package/dist/claude/ipc-server.js +192 -0
- package/dist/claude/mcp-bridge.js +453 -0
- package/dist/claude/mcp-tools.js +354 -0
- package/dist/claude/message-offsets.js +88 -0
- package/dist/claude/modal-relay.js +450 -0
- package/dist/claude/model-catalog.js +85 -0
- package/dist/claude/monitor-relay.js +597 -0
- package/dist/claude/pending-forks.js +93 -0
- package/dist/claude/pending-suggestions.js +50 -0
- package/dist/claude/permission-gate.js +337 -0
- package/dist/claude/permission-mode.js +178 -0
- package/dist/claude/poll-user.js +51 -0
- package/dist/claude/project-commands.js +69 -0
- package/dist/claude/prompt-hold.js +124 -0
- package/dist/claude/prompt-suggestion-scraper.js +89 -0
- package/dist/claude/pty-provider.js +2214 -0
- package/dist/claude/pty-spawn-config.js +296 -0
- package/dist/claude/pty-stream.js +363 -0
- package/dist/claude/request-queue.js +135 -0
- package/dist/claude/scheduled-runner.js +91 -0
- package/dist/claude/scheduler.js +237 -0
- package/dist/claude/scope-guard.js +274 -0
- package/dist/claude/sdk-permission-gate.js +77 -0
- package/dist/claude/secret-request.js +576 -0
- package/dist/claude/session-cost.js +41 -0
- package/dist/claude/session-history.js +286 -0
- package/dist/claude/session-jsonl.js +920 -0
- package/dist/claude/session-manager.js +195 -0
- package/dist/claude/session-scan.js +270 -0
- package/dist/claude/setup-token.js +285 -0
- package/dist/claude/side-call-options.js +45 -0
- package/dist/claude/side-question.js +249 -0
- package/dist/claude/stage-images.js +62 -0
- package/dist/claude/subagent-tools.js +12 -0
- package/dist/claude/synthetic-ctx.js +51 -0
- package/dist/claude/system-prompt.js +162 -0
- package/dist/claude/tasks-overlay-scraper.js +94 -0
- package/dist/claude/tip-scraper.js +78 -0
- package/dist/claude/tui-modal.js +501 -0
- package/dist/claude/tui-state.js +384 -0
- package/dist/claude/turn-end.js +91 -0
- package/dist/claude/turn-prose.js +64 -0
- package/dist/claude/update-banner-relay.js +70 -0
- package/dist/cli/commands/doctor.js +305 -0
- package/dist/cli/commands/help.js +25 -0
- package/dist/cli/commands/init.js +123 -0
- package/dist/cli/commands/service.js +678 -0
- package/dist/cli/commands/start.js +53 -0
- package/dist/cli/commands/version.js +11 -0
- package/dist/cli/dispatch.js +79 -0
- package/dist/cli/init/env-file.js +99 -0
- package/dist/cli/init/flow.js +638 -0
- package/dist/cli/init/prompter.js +116 -0
- package/dist/cli/init/telegram.js +94 -0
- package/dist/cli/service/render.js +212 -0
- package/dist/cli.js +18 -0
- package/dist/config-report.js +107 -0
- package/dist/config.js +500 -0
- package/dist/index.js +367 -0
- package/dist/launcher.js +933 -0
- package/dist/node-version-check.js +27 -0
- package/dist/providers/ccr-health.js +119 -0
- package/dist/providers/ccr-introspect.js +149 -0
- package/dist/providers/ccr-provider.js +60 -0
- package/dist/providers/claude-provider.js +63 -0
- package/dist/providers/prefs-sync.js +164 -0
- package/dist/providers/project-favorites.js +74 -0
- package/dist/providers/provider-router.js +127 -0
- package/dist/providers/provider-switch.js +91 -0
- package/dist/providers/sdk-provider.js +37 -0
- package/dist/providers/types.js +8 -0
- package/dist/providers/user-preferences.js +214 -0
- package/dist/restart-when-idle.js +153 -0
- package/dist/startup/auto-continue.js +67 -0
- package/dist/startup/auto-resume.js +173 -0
- package/dist/startup/notices.js +120 -0
- package/dist/startup/shared.js +44 -0
- package/dist/startup/verify-token.js +31 -0
- package/dist/telegram/access-request.js +153 -0
- package/dist/telegram/action-logger.js +684 -0
- package/dist/telegram/admin-mention.js +107 -0
- package/dist/telegram/background-activity-card.js +502 -0
- package/dist/telegram/botname-settings.js +336 -0
- package/dist/telegram/button-text.js +26 -0
- package/dist/telegram/client-options.js +27 -0
- package/dist/telegram/deduplication.js +33 -0
- package/dist/telegram/entities.js +295 -0
- package/dist/telegram/force-reply-tracker.js +57 -0
- package/dist/telegram/lettered-options.js +87 -0
- package/dist/telegram/markdown.js +362 -0
- package/dist/telegram/message-sender.js +1287 -0
- package/dist/telegram/prompt-label.js +142 -0
- package/dist/telegram/prompt-suggestion.js +54 -0
- package/dist/telegram/send.js +123 -0
- package/dist/telegram/streaming-turn.js +105 -0
- package/dist/telegram/suggestions-settings.js +30 -0
- package/dist/telegram/task-list.js +367 -0
- package/dist/telegram/task-tracker.js +209 -0
- package/dist/telegram/telegraph-settings.js +31 -0
- package/dist/telegram/telegraph.js +453 -0
- package/dist/telegram/terminal-renderer.js +671 -0
- package/dist/telegram/terminal-settings.js +25 -0
- package/dist/telegram/thread-titles.js +190 -0
- package/dist/telegram/threads-setup.js +117 -0
- package/dist/tts/tts-settings.js +62 -0
- package/dist/tts/tts.js +245 -0
- package/dist/tts/voice-reply.js +78 -0
- package/dist/utils/admins.js +143 -0
- package/dist/utils/agent-timer.js +55 -0
- package/dist/utils/atomic-write.js +24 -0
- package/dist/utils/bot-token.js +74 -0
- package/dist/utils/bounded-map.js +55 -0
- package/dist/utils/build-info.js +57 -0
- package/dist/utils/caffeinate.js +50 -0
- package/dist/utils/claude-env.js +54 -0
- package/dist/utils/claude-version.js +48 -0
- package/dist/utils/config-home.js +62 -0
- package/dist/utils/debug-agent.js +117 -0
- package/dist/utils/debug-watchdog.js +121 -0
- package/dist/utils/download.js +111 -0
- package/dist/utils/exit-codes.js +48 -0
- package/dist/utils/file-type.js +149 -0
- package/dist/utils/format.js +81 -0
- package/dist/utils/home-project.js +30 -0
- package/dist/utils/host-stall.js +51 -0
- package/dist/utils/id-list.js +44 -0
- package/dist/utils/idle-restart.js +92 -0
- package/dist/utils/install-mode.js +63 -0
- package/dist/utils/instance-config.js +148 -0
- package/dist/utils/instances.js +95 -0
- package/dist/utils/json-store.js +140 -0
- package/dist/utils/keyed-settings.js +62 -0
- package/dist/utils/legacy-env.js +35 -0
- package/dist/utils/npm-version.js +134 -0
- package/dist/utils/prefs-relay.js +107 -0
- package/dist/utils/proc-children.js +102 -0
- package/dist/utils/project-data-dir.js +33 -0
- package/dist/utils/reasoning-summary.js +12 -0
- package/dist/utils/resolve-bin.js +86 -0
- package/dist/utils/resolve-claude-bin.js +63 -0
- package/dist/utils/respawn-backoff.js +19 -0
- package/dist/utils/sanitize.js +91 -0
- package/dist/utils/session-key.js +37 -0
- package/dist/utils/stale-launcher.js +109 -0
- package/dist/utils/state-dir-migration.js +92 -0
- package/dist/utils/systemd.js +126 -0
- package/dist/utils/user-roster.js +275 -0
- package/dist/utils/verbosity.js +118 -0
- package/dist/utils/version-check.js +166 -0
- package/dist/utils/workspace-guard.js +44 -0
- package/dist/worker-restart.js +141 -0
- package/instances.json.example +41 -0
- package/package.json +76 -4
package/dist/config.js
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import { config as loadEnv } from 'dotenv';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { legacyEnv } from './utils/legacy-env.js';
|
|
5
|
+
import { parseIdList } from './utils/id-list.js';
|
|
6
|
+
import { configFile } from './utils/config-home.js';
|
|
7
|
+
import { isWellFormedBotToken, MALFORMED_TOKEN_MESSAGE } from './utils/bot-token.js';
|
|
8
|
+
import { envFileStatus, formatConfigReport, problemsFromIssues, } from './config-report.js';
|
|
9
|
+
import { exitForConfigError } from './utils/exit-codes.js';
|
|
10
|
+
// Next to package.json in a checkout, ~/.telecoder/.env for an npm install —
|
|
11
|
+
// see utils/config-home.ts.
|
|
12
|
+
const defaultEnvPath = configFile('.env');
|
|
13
|
+
// Read from the real process env, not the .env file — this is the var that
|
|
14
|
+
// says *which* .env to load, so it can't come from inside one.
|
|
15
|
+
const envPath = legacyEnv('ENV_PATH') || defaultEnvPath;
|
|
16
|
+
const loadedEnv = loadEnv({ path: envPath });
|
|
17
|
+
/**
|
|
18
|
+
* Which values in the .env file are being ignored because the process was
|
|
19
|
+
* started with them already in its environment.
|
|
20
|
+
*
|
|
21
|
+
* dotenv never overwrites what is already there, which is the right default —
|
|
22
|
+
* it is how a launcher hands each worker its own instance config. The trap is
|
|
23
|
+
* that a restart inherits the environment it was started from, so a value
|
|
24
|
+
* exported into the shell that first launched the bot outranks the file
|
|
25
|
+
* forever, and no amount of editing .env or restarting from chat can dislodge
|
|
26
|
+
* it. Naming the shadowed keys at startup turns a silent mystery into a line
|
|
27
|
+
* in the log.
|
|
28
|
+
*/
|
|
29
|
+
export function findShadowedEnvKeys(fromFile, env = process.env) {
|
|
30
|
+
if (!fromFile)
|
|
31
|
+
return [];
|
|
32
|
+
// A launcher worker is handed its config through the environment on purpose.
|
|
33
|
+
if (env.TELECODER_INSTANCE_NAME)
|
|
34
|
+
return [];
|
|
35
|
+
return Object.keys(fromFile).filter((key) => env[key] !== fromFile[key]);
|
|
36
|
+
}
|
|
37
|
+
const shadowed = findShadowedEnvKeys(loadedEnv.parsed);
|
|
38
|
+
if (shadowed.length > 0) {
|
|
39
|
+
// Names only — one of these is the bot token.
|
|
40
|
+
console.warn(`[env] Ignoring ${shadowed.length} value(s) from ${envPath}: this process was started with ` +
|
|
41
|
+
`them already set in its environment, and that wins over the file — ${shadowed.join(', ')}. ` +
|
|
42
|
+
'Restart from a shell that does not export them if you meant the file to apply.');
|
|
43
|
+
}
|
|
44
|
+
const toBool = (val) => val.toLowerCase() === 'true';
|
|
45
|
+
/**
|
|
46
|
+
* A comma-separated id list, validated by parseIdList: non-numeric entries
|
|
47
|
+
* (`@alice`) and the .env.example placeholder fail startup with a message
|
|
48
|
+
* saying what to put there instead.
|
|
49
|
+
*/
|
|
50
|
+
const idList = (name, kind = 'user') => (val, ctx) => {
|
|
51
|
+
const result = parseIdList(name, val, kind);
|
|
52
|
+
if (!result.ok) {
|
|
53
|
+
ctx.addIssue({ code: 'custom', message: result.error });
|
|
54
|
+
return z.NEVER;
|
|
55
|
+
}
|
|
56
|
+
return result.ids;
|
|
57
|
+
};
|
|
58
|
+
const envSchema = z.object({
|
|
59
|
+
// Checked by shape here, before anything uses it; whether Telegram accepts
|
|
60
|
+
// it is checked at startup (startup/verify-token.ts).
|
|
61
|
+
TELEGRAM_BOT_TOKEN: z
|
|
62
|
+
.string()
|
|
63
|
+
.min(1, 'Telegram bot token is required')
|
|
64
|
+
.refine(isWellFormedBotToken, MALFORMED_TOKEN_MESSAGE),
|
|
65
|
+
ALLOWED_USER_IDS: z
|
|
66
|
+
.string()
|
|
67
|
+
.min(1, 'At least one allowed user ID is required (your own numeric Telegram id — get it from @userinfobot)')
|
|
68
|
+
.transform(idList('ALLOWED_USER_IDS'))
|
|
69
|
+
.refine((ids) => ids.length > 0, 'ALLOWED_USER_IDS has no ids in it — put your own numeric Telegram id there (get it from @userinfobot)'),
|
|
70
|
+
ALLOWED_GROUP_IDS: z
|
|
71
|
+
.string()
|
|
72
|
+
.default('')
|
|
73
|
+
.transform(idList('ALLOWED_GROUP_IDS', 'group')),
|
|
74
|
+
// The subset of ALLOWED_USER_IDS that may approve permission prompts and run
|
|
75
|
+
// bot-lifecycle / transport commands. Empty means every allowed user is an
|
|
76
|
+
// admin, which is the behaviour every install had before this existed — so a
|
|
77
|
+
// solo bot is unaffected and only a shared one needs to set it.
|
|
78
|
+
// See src/utils/admins.ts for the roster logic.
|
|
79
|
+
ADMIN_USER_IDS: z
|
|
80
|
+
.string()
|
|
81
|
+
.default('')
|
|
82
|
+
.transform(idList('ADMIN_USER_IDS')),
|
|
83
|
+
// The subset of ALLOWED_USER_IDS that may answer an approval prompt without
|
|
84
|
+
// owning the bot. An approver is still a guest everywhere else — the charter
|
|
85
|
+
// judge still reads their messages, the gate still stops their tool calls,
|
|
86
|
+
// and the lifecycle commands are still closed to them. All they gain is the
|
|
87
|
+
// right to answer *someone else's* prompt, which is what stops one owner
|
|
88
|
+
// being the bottleneck for a bot several people use.
|
|
89
|
+
//
|
|
90
|
+
// They cannot answer their own: an approval the requester taps themselves
|
|
91
|
+
// confirms nothing, which is the whole reason the roster is narrowed at all.
|
|
92
|
+
// Ids that ADMIN_USER_IDS already carries are ignored here — admins can
|
|
93
|
+
// approve anyway, and listing someone twice should not mean something new.
|
|
94
|
+
// Only meaningful alongside ADMIN_USER_IDS; with that unset every allowed
|
|
95
|
+
// user is already an admin and there is nothing left for this to widen.
|
|
96
|
+
// See src/utils/admins.ts for the roster logic.
|
|
97
|
+
APPROVER_USER_IDS: z
|
|
98
|
+
.string()
|
|
99
|
+
.default('')
|
|
100
|
+
.transform(idList('APPROVER_USER_IDS')),
|
|
101
|
+
// Confine non-admins to the groups in ALLOWED_GROUP_IDS. Without this a
|
|
102
|
+
// shared bot is still reachable in a private chat, where the owner cannot
|
|
103
|
+
// see what is being asked of it — which defeats the point of sharing it in a
|
|
104
|
+
// group. Admins are unaffected and can always DM the bot.
|
|
105
|
+
RESTRICT_TO_GROUPS: z.string().default('false').transform(toBool),
|
|
106
|
+
// Scope guard: prompt when a tool call names a path outside the shared
|
|
107
|
+
// projects, or a credential path anywhere. 'auto' follows the permission
|
|
108
|
+
// gate, which is what a shared bot wants; 'on'/'off' force it.
|
|
109
|
+
SCOPE_GUARD: z.enum(['auto', 'on', 'off']).default('auto'),
|
|
110
|
+
// Extra directories the scope guard treats as in-bounds, on top of
|
|
111
|
+
// WORKSPACE_DIR and the temp dir. Comma-separated absolute paths.
|
|
112
|
+
SCOPE_ALLOWED_PATHS: z
|
|
113
|
+
.string()
|
|
114
|
+
.default('')
|
|
115
|
+
.transform((val) => (val ? val.split(',').map((p) => p.trim()).filter(Boolean) : [])),
|
|
116
|
+
// Charter judge: a Haiku side-call that reads each guest's message against a
|
|
117
|
+
// plain-language charter and holds anything out of bounds for an admin.
|
|
118
|
+
// 'auto' turns it on when the bot has guests.
|
|
119
|
+
CHARTER_JUDGE: z.enum(['auto', 'on', 'off']).default('auto'),
|
|
120
|
+
// Path to the charter the judge reads. Defaults to CHARTER.md in the
|
|
121
|
+
// workspace root when that file exists, and to a generated one otherwise.
|
|
122
|
+
CHARTER_FILE: z.string().default(''),
|
|
123
|
+
// How long a permission prompt waits for an admin before auto-denying.
|
|
124
|
+
// Ten minutes is fine when the approver is the person who typed the request;
|
|
125
|
+
// when it is someone else's request waiting on you, it usually is not.
|
|
126
|
+
PERMISSION_PROMPT_TIMEOUT_MINUTES: z
|
|
127
|
+
.string()
|
|
128
|
+
.default('10')
|
|
129
|
+
.transform((val) => parseInt(val, 10)),
|
|
130
|
+
// In a group, only act on messages that address the bot — an @mention, a
|
|
131
|
+
// reply to something the bot sent, or a slash command. Off means every
|
|
132
|
+
// message in an allow-listed group is a prompt, which drowns out any human
|
|
133
|
+
// conversation happening in the same group.
|
|
134
|
+
GROUP_REQUIRE_MENTION: z.string().default('true').transform(toBool),
|
|
135
|
+
// Treat any reply to one of the bot's messages as addressing it, the way it
|
|
136
|
+
// worked before mentions were required. Off by default: replying is also how
|
|
137
|
+
// you quote a message, so a reply is a poor signal of intent. Answers to the
|
|
138
|
+
// bot's own ForceReply prompts are always addressed regardless.
|
|
139
|
+
GROUP_REPLY_IS_MENTION: z.string().default('false').transform(toBool),
|
|
140
|
+
// What membership of an allow-listed group grants. 'spectator' makes it
|
|
141
|
+
// presence only — people talk in the group and watch the bot work, but only
|
|
142
|
+
// someone an admin has /allow'd can send it prompts. 'contributor' makes
|
|
143
|
+
// Telegram membership the whole gate, so everyone in the room can drive the
|
|
144
|
+
// agent; that is the right answer for a group of peers and the wrong one for
|
|
145
|
+
// a group with an audience in it.
|
|
146
|
+
//
|
|
147
|
+
// Defaults to spectator, which is the safe direction and matches what the
|
|
148
|
+
// roster gate already enforced before this setting existed: someone who is
|
|
149
|
+
// in the group but not admitted could never prompt the bot.
|
|
150
|
+
GROUP_MEMBERS_DEFAULT: z.enum(['contributor', 'spectator']).default('spectator'),
|
|
151
|
+
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
|
+
WORKSPACE_DIR: z.string().default(process.env.HOME || '.'),
|
|
155
|
+
// The project this bot is for, set by /newbot for the bots it creates. A
|
|
156
|
+
// conversation with nowhere else to be starts here, and a thread in it is
|
|
157
|
+
// named without the project in front, since the bot's name already says it.
|
|
158
|
+
// Absolute, or relative to WORKSPACE_DIR.
|
|
159
|
+
HOME_PROJECT: z.string().optional(),
|
|
160
|
+
CLAUDE_EXECUTABLE_PATH: z.string().default('claude'),
|
|
161
|
+
CLAUDE_USE_BUNDLED_EXECUTABLE: z
|
|
162
|
+
.string()
|
|
163
|
+
.default('true')
|
|
164
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
165
|
+
CLAUDE_SDK_LOG_LEVEL: z.enum(['off', 'basic', 'verbose', 'trace']).default('basic'),
|
|
166
|
+
// Load user-level Claude settings (~/.claude/settings.json: plugins, hooks, MCP servers)
|
|
167
|
+
// into the bot's SDK subprocess. Default false so the bot runs in an isolated env;
|
|
168
|
+
// user-level plugins/MCP servers can otherwise inflate tool counts and trigger the
|
|
169
|
+
// SDK's tool-deferral mechanism, breaking proactive MCP tool calls (e.g. auto-topic).
|
|
170
|
+
CLAUDE_SDK_LOAD_USER_SETTINGS: z
|
|
171
|
+
.string()
|
|
172
|
+
.default('false')
|
|
173
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
174
|
+
// Path to a JSON file of extra MCP servers ({"mcpServers": {...}}) to hand the
|
|
175
|
+
// pty alongside the bot's own. Opt-in and named explicitly for the same reason
|
|
176
|
+
// the flag above defaults to false: the spawn passes --strict-mcp-config, which
|
|
177
|
+
// is what keeps the tool surface predictable, and the alternative to this is
|
|
178
|
+
// loading every server the user has ever configured — broken ones included.
|
|
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.
|
|
182
|
+
EXTRA_MCP_CONFIG: z.string().optional(),
|
|
183
|
+
// Marketplace plugins to enable inside the agent, as the `plugin@marketplace`
|
|
184
|
+
// ids `claude plugin list` prints, comma-separated. Neither transport reads
|
|
185
|
+
// ~/.claude/settings.json, which is where `enabledPlugins` normally lives, so
|
|
186
|
+
// this is the only way a plugin you enabled in the terminal reaches a
|
|
187
|
+
// Telegram session. See src/claude/enabled-plugins.ts for why they skip it.
|
|
188
|
+
CLAUDE_PLUGINS: z
|
|
189
|
+
.string()
|
|
190
|
+
.default('')
|
|
191
|
+
.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
|
+
BOT_NAME: z.string().default('TeleCoder'),
|
|
197
|
+
DYNAMIC_BOT_NAME: z
|
|
198
|
+
.string()
|
|
199
|
+
.default('false')
|
|
200
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
201
|
+
// Fire a parallel Haiku side-call on every user message to derive a topic
|
|
202
|
+
// label, independent of the main agent's tool calls. Deferral-immune because
|
|
203
|
+
// it bypasses settingSources and tools entirely. Only takes effect when
|
|
204
|
+
// dynamic bot name is enabled for the chat.
|
|
205
|
+
AUTO_TOPIC_HAIKU: z
|
|
206
|
+
.string()
|
|
207
|
+
.default('true')
|
|
208
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
209
|
+
// Default for the per-chat "predicted next prompt" feature: when enabled,
|
|
210
|
+
// TeleCoder sets CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=1 on the PTY spawn
|
|
211
|
+
// and scrapes the ghost-text suggestion that claude renders into its input
|
|
212
|
+
// box after each turn, surfacing it as an inline button under the response.
|
|
213
|
+
// Per-chat override via /suggestions; takes effect on next session spawn.
|
|
214
|
+
// Off by default — feature relies on Anthropic's growthbook flag being on
|
|
215
|
+
// for the account, and the suggestion is a speculative API call.
|
|
216
|
+
PROMPT_SUGGESTIONS_DEFAULT: z
|
|
217
|
+
.string()
|
|
218
|
+
.default('false')
|
|
219
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
220
|
+
BOT_MODE: z.enum(['dev', 'prod']).default('dev'),
|
|
221
|
+
// Transport a chat uses until someone picks one with /method. The permission
|
|
222
|
+
// gate runs on both (a PreToolUse hook either way). Per-chat /method wins.
|
|
223
|
+
CLAUDE_METHOD_DEFAULT: z.enum(['sdk', 'pty']).default('sdk'),
|
|
224
|
+
STREAMING_MODE: z.enum(['streaming', 'wait']).default('streaming'),
|
|
225
|
+
STREAMING_DEBOUNCE_MS: z
|
|
226
|
+
.string()
|
|
227
|
+
.default('500')
|
|
228
|
+
.transform((val) => parseInt(val, 10)),
|
|
229
|
+
MAX_MESSAGE_LENGTH: z
|
|
230
|
+
.string()
|
|
231
|
+
.default('4000')
|
|
232
|
+
.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
|
+
IMAGE_MAX_FILE_SIZE_MB: z
|
|
249
|
+
.string()
|
|
250
|
+
.default('20')
|
|
251
|
+
.transform((val) => parseInt(val, 10)),
|
|
252
|
+
// 19, not 25: Telegram's getFile refuses anything over 20MB, so a 25MB
|
|
253
|
+
// ceiling let files through this guard only to fail at download with an
|
|
254
|
+
// opaque 400. Matches VOICE_MAX_FILE_SIZE_MB, which already sat under the cap.
|
|
255
|
+
DOCUMENT_MAX_FILE_SIZE_MB: z
|
|
256
|
+
.string()
|
|
257
|
+
.default('19')
|
|
258
|
+
.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
|
+
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
|
+
// Voice transcription (Groq Whisper)
|
|
274
|
+
GROQ_API_KEY: z.string().optional(),
|
|
275
|
+
TRANSCRIBE_ENABLED: z.string().default('true').transform(toBool),
|
|
276
|
+
VOICE_SHOW_TRANSCRIPT: z
|
|
277
|
+
.string()
|
|
278
|
+
.default('true')
|
|
279
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
280
|
+
VOICE_MAX_FILE_SIZE_MB: z
|
|
281
|
+
.string()
|
|
282
|
+
.default('19')
|
|
283
|
+
.transform((val) => parseInt(val, 10)),
|
|
284
|
+
VOICE_LANGUAGE: z.string().default('en'),
|
|
285
|
+
VOICE_TIMEOUT_MS: z
|
|
286
|
+
.string()
|
|
287
|
+
.default('60000')
|
|
288
|
+
.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
|
+
// Verbosity tier (quiet | normal | verbose | debug). Drives the defaults
|
|
295
|
+
// for several rendering flags below; per-chat /verbosity overrides this,
|
|
296
|
+
// and explicit env vars (CONTEXT_SHOW_USAGE etc.) override the tier.
|
|
297
|
+
VERBOSITY_DEFAULT: z.enum(['quiet', 'normal', 'verbose', 'debug']).default('normal'),
|
|
298
|
+
// Context visibility — when set, overrides the verbosity tier. Leave unset
|
|
299
|
+
// to let the tier decide (recommended).
|
|
300
|
+
CONTEXT_SHOW_USAGE: z
|
|
301
|
+
.string()
|
|
302
|
+
.default('false')
|
|
303
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
304
|
+
CONTEXT_NOTIFY_COMPACTION: z
|
|
305
|
+
.string()
|
|
306
|
+
.default('true')
|
|
307
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
308
|
+
// Terminal UI mode
|
|
309
|
+
TERMINAL_UI_DEFAULT: z
|
|
310
|
+
.string()
|
|
311
|
+
.default('true')
|
|
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
|
|
323
|
+
.string()
|
|
324
|
+
.default('false')
|
|
325
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
326
|
+
// Message batching: combine the parts of a long paste Telegram split up into
|
|
327
|
+
// a single prompt. How long to wait for the next part, in ms. 0 = disabled.
|
|
328
|
+
MESSAGE_BATCH_TIMEOUT_MS: z
|
|
329
|
+
.string()
|
|
330
|
+
.default('1500')
|
|
331
|
+
.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
|
+
// Absolute wall-clock cap for a single PTY turn (ms). The turn is killed
|
|
360
|
+
// with a "turn exceeded" error if it runs longer. Default 2 h — long
|
|
361
|
+
// enough for genuinely intensive multi-step work; raise it if you regularly
|
|
362
|
+
// hit the cap on legitimately long turns.
|
|
363
|
+
CLAUDE_PTY_HARD_TIMEOUT_MS: z
|
|
364
|
+
.string()
|
|
365
|
+
.default('7200000')
|
|
366
|
+
.transform((val) => parseInt(val, 10)),
|
|
367
|
+
// How long a question from the agent — telecoder_ask_user buttons, a
|
|
368
|
+
// telecoder_poll_user poll, a Claude Code dialog relayed to the chat —
|
|
369
|
+
// waits for an answer before the turn carries on without one. The turn is
|
|
370
|
+
// paused for the whole wait, so a long timeout is a long stall whenever a
|
|
371
|
+
// question goes unanswered; keep it well under CLAUDE_PTY_HARD_TIMEOUT_MS,
|
|
372
|
+
// which ends the turn regardless. Permission prompts have their own,
|
|
373
|
+
// PERMISSION_PROMPT_TIMEOUT_MINUTES.
|
|
374
|
+
QUESTION_TIMEOUT_MINUTES: z
|
|
375
|
+
.string()
|
|
376
|
+
.default('10')
|
|
377
|
+
.transform((val) => parseInt(val, 10)),
|
|
378
|
+
// HTTP proxy for Telegram API requests (e.g. socks5://127.0.0.1:1080 or http://proxy:8080)
|
|
379
|
+
TELEGRAM_PROXY_URL: z.string().optional(),
|
|
380
|
+
// Completion notification (send a new message after long streaming tasks)
|
|
381
|
+
NOTIFICATION_ENABLED: z.string().default('true').transform(toBool),
|
|
382
|
+
NOTIFICATION_THRESHOLD_SECONDS: z
|
|
383
|
+
.string()
|
|
384
|
+
.default('60')
|
|
385
|
+
.transform((val) => parseInt(val, 10)),
|
|
386
|
+
// Claude Code Router (CCR) provider — redirects the spawned `claude` binary
|
|
387
|
+
// through a local CCR proxy so it can be backed by non-Anthropic models.
|
|
388
|
+
// Useful as a fallback when the Max usage limit is reached.
|
|
389
|
+
CCR_ENABLED: z
|
|
390
|
+
.string()
|
|
391
|
+
.default('false')
|
|
392
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
393
|
+
CCR_BASE_URL: z.string().default('http://localhost:3456'),
|
|
394
|
+
CCR_AUTH_TOKEN: z.string().default(''),
|
|
395
|
+
// When the CCR proxy isn't reachable, automatically spawn `ccr start` in
|
|
396
|
+
// the background instead of letting the spawned `claude` CLI hang on a
|
|
397
|
+
// ConnectionRefused. Off by default — opt in if you want hands-off recovery.
|
|
398
|
+
CCR_AUTOSTART: z
|
|
399
|
+
.string()
|
|
400
|
+
.default('false')
|
|
401
|
+
.transform((val) => val.toLowerCase() === 'true'),
|
|
402
|
+
// Path or name of the `ccr` binary used for autostart. Defaults to `ccr`
|
|
403
|
+
// (resolved via PATH). Override if `ccr` lives somewhere systemd can't see.
|
|
404
|
+
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
|
+
});
|
|
412
|
+
/**
|
|
413
|
+
* Print the configuration report and stop. Everything that keeps the bot from
|
|
414
|
+
* starting goes through here, so a first run sees one message in one shape —
|
|
415
|
+
* which file was read, what is wrong, and how to fix it — whichever check
|
|
416
|
+
* caught it. See config-report.ts.
|
|
417
|
+
*/
|
|
418
|
+
function failConfig(problems) {
|
|
419
|
+
console.error(formatConfigReport(problems, { path: envPath, status: envFileStatus(loadedEnv) }, { instanceName: process.env.TELECODER_INSTANCE_NAME }));
|
|
420
|
+
exitForConfigError();
|
|
421
|
+
}
|
|
422
|
+
const parsed = envSchema.safeParse(process.env);
|
|
423
|
+
if (!parsed.success) {
|
|
424
|
+
failConfig(problemsFromIssues(parsed.error.issues, process.env));
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* ADMIN_USER_IDS narrows who, among the people ALLOWED_USER_IDS lets in, may
|
|
428
|
+
* approve prompts and run lifecycle commands. It does not grant access itself.
|
|
429
|
+
*
|
|
430
|
+
* Reading it as a replacement rather than a subset is the natural mistake — the
|
|
431
|
+
* variable that mentions "admin" looks like the more powerful one — and the
|
|
432
|
+
* failure it produces is misleading: the bot dies on ALLOWED_USER_IDS being
|
|
433
|
+
* empty and never mentions the line you actually filled in. So the check names
|
|
434
|
+
* both, here, at the point of exit.
|
|
435
|
+
*/
|
|
436
|
+
if (parsed.data.ADMIN_USER_IDS.length > 0) {
|
|
437
|
+
const orphaned = parsed.data.ADMIN_USER_IDS.filter((id) => !parsed.data.ALLOWED_USER_IDS.includes(id));
|
|
438
|
+
if (orphaned.length > 0) {
|
|
439
|
+
failConfig([{
|
|
440
|
+
key: 'ADMIN_USER_IDS',
|
|
441
|
+
message: `ADMIN_USER_IDS lists ${orphaned.join(', ')}, which ALLOWED_USER_IDS does not. ` +
|
|
442
|
+
'ADMIN_USER_IDS picks the admins out of ALLOWED_USER_IDS; it does not grant access ' +
|
|
443
|
+
'on its own, so an id in one and not the other can never do anything. ' +
|
|
444
|
+
`Add ${orphaned.length === 1 ? 'it' : 'them'} to ALLOWED_USER_IDS too — the same id in both lines is normal.`,
|
|
445
|
+
}]);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* APPROVER_USER_IDS with no ADMIN_USER_IDS is a no-op: with that unset every
|
|
450
|
+
* allowed user is already an admin, so there is nobody left for this list to
|
|
451
|
+
* promote. Someone who filled it in wanted a split and got none, which is the
|
|
452
|
+
* same silent nothing the ADMIN_USER_IDS check above exists to prevent.
|
|
453
|
+
*
|
|
454
|
+
* The other way of getting it wrong — an approver no allow-list carries —
|
|
455
|
+
* is checked at startup instead, by findOrphanedApprovers(). It has to read the
|
|
456
|
+
* roster that `/allow` writes to, and this file cannot: user-roster.ts imports
|
|
457
|
+
* it. Checking only ALLOWED_USER_IDS here was wrong in precisely the case the
|
|
458
|
+
* tier exists for — a friend admitted from chat is never in that line.
|
|
459
|
+
*/
|
|
460
|
+
if (parsed.data.APPROVER_USER_IDS.length > 0 && parsed.data.ADMIN_USER_IDS.length === 0) {
|
|
461
|
+
failConfig([{
|
|
462
|
+
key: 'APPROVER_USER_IDS',
|
|
463
|
+
message: 'APPROVER_USER_IDS is set but ADMIN_USER_IDS is not. With no admin subset configured every ' +
|
|
464
|
+
'allowed user is already an admin and can approve anything, so this list would promote nobody ' +
|
|
465
|
+
'and change nothing. Set ADMIN_USER_IDS to the people who own the bot, and leave the rest here.',
|
|
466
|
+
}]);
|
|
467
|
+
}
|
|
468
|
+
export const config = { ...parsed.data };
|
|
469
|
+
// Capture which override env vars were explicitly set (after dotenv has loaded
|
|
470
|
+
// process.env). The verbosity resolver consults these to decide whether to
|
|
471
|
+
// honor the env value or fall back to the per-tier default; the startup name
|
|
472
|
+
// sync only renames the bot when BOT_NAME was asked for.
|
|
473
|
+
function isEnvSet(key) {
|
|
474
|
+
const raw = process.env[key];
|
|
475
|
+
return raw !== undefined && raw !== '';
|
|
476
|
+
}
|
|
477
|
+
export const explicitFlags = {
|
|
478
|
+
CONTEXT_SHOW_USAGE: isEnvSet('CONTEXT_SHOW_USAGE'),
|
|
479
|
+
CONTEXT_NOTIFY_COMPACTION: isEnvSet('CONTEXT_NOTIFY_COMPACTION'),
|
|
480
|
+
TERMINAL_UI_VERBOSE: isEnvSet('TERMINAL_UI_VERBOSE'),
|
|
481
|
+
BOT_NAME: isEnvSet('BOT_NAME'),
|
|
482
|
+
};
|
|
483
|
+
// ---------------------------------------------------------------------------
|
|
484
|
+
// Derived helpers (used by index.ts, command.handler.ts, session-history.ts)
|
|
485
|
+
// ---------------------------------------------------------------------------
|
|
486
|
+
import { getStateDir } from './utils/json-store.js';
|
|
487
|
+
/** Numeric bot ID extracted from the Telegram token (e.g. "123456" from "123456:ABC..."). */
|
|
488
|
+
export const BOT_ID = config.TELEGRAM_BOT_TOKEN.split(':')[0];
|
|
489
|
+
const STATE_DIR = getStateDir();
|
|
490
|
+
/** Per-bot reload marker file path so multi-instance setups don't cross-restore. */
|
|
491
|
+
export function getReloadMarkerPath() {
|
|
492
|
+
return getReloadMarkerPathForBotId(BOT_ID);
|
|
493
|
+
}
|
|
494
|
+
/** Same as getReloadMarkerPath, but for an arbitrary bot ID — used by the
|
|
495
|
+
* launcher when it needs to write markers for sibling bots on /restartbot all
|
|
496
|
+
* and /rebuildbot all. */
|
|
497
|
+
export function getReloadMarkerPathForBotId(botId) {
|
|
498
|
+
return path.join(STATE_DIR, `pending-reload-${botId}.json`);
|
|
499
|
+
}
|
|
500
|
+
//# sourceMappingURL=config.js.map
|