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
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `telecoder doctor` — check that what TeleCoder needs is in place, without
|
|
3
|
+
* starting it.
|
|
4
|
+
*
|
|
5
|
+
* Reads the .env itself (dotenv.parse, not the bot's config module, which
|
|
6
|
+
* exits on the first invalid value) so it can report every problem at once.
|
|
7
|
+
* Nothing here costs money: the Claude login is checked with
|
|
8
|
+
* `claude auth status`, and the Telegram token only goes over the network
|
|
9
|
+
* with --live (a getMe call).
|
|
10
|
+
*/
|
|
11
|
+
import { execFile } from 'child_process';
|
|
12
|
+
import * as fs from 'fs';
|
|
13
|
+
import * as os from 'os';
|
|
14
|
+
import * as path from 'path';
|
|
15
|
+
import { parse as parseEnv } from 'dotenv';
|
|
16
|
+
import { getConfigHomeInfo, configFile } from '../../utils/config-home.js';
|
|
17
|
+
import { getInstallMode, getInstalledVersion, PACKAGE_ROOT } from '../../utils/install-mode.js';
|
|
18
|
+
import { legacyEnv } from '../../utils/legacy-env.js';
|
|
19
|
+
import { parseIdList, PLACEHOLDER_USER_ID } from '../../utils/id-list.js';
|
|
20
|
+
import { resolveInstances, InstancesConfigError } from '../../utils/instance-config.js';
|
|
21
|
+
import { resolveBin } from '../../utils/resolve-bin.js';
|
|
22
|
+
import { redactSecrets } from '../../utils/sanitize.js';
|
|
23
|
+
import { MIN_NODE_MAJOR } from '../../node-version-check.js';
|
|
24
|
+
import { SERVICE_MANAGER_ENV } from '../../utils/exit-codes.js';
|
|
25
|
+
export { MIN_NODE_MAJOR };
|
|
26
|
+
const ok = (label, ...detail) => ({ status: 'ok', label, detail });
|
|
27
|
+
const warn = (label, ...detail) => ({ status: 'warn', label, detail });
|
|
28
|
+
const fail = (label, ...detail) => ({ status: 'fail', label, detail });
|
|
29
|
+
// ── Pure checks (tested directly) ──────────────────────────────
|
|
30
|
+
export function checkNodeVersion(version = process.versions.node) {
|
|
31
|
+
const major = parseInt(version.split('.')[0], 10);
|
|
32
|
+
return major >= MIN_NODE_MAJOR
|
|
33
|
+
? ok(`Node.js ${version}`)
|
|
34
|
+
: fail(`Node.js ${version} is too old`, `TeleCoder needs Node.js ${MIN_NODE_MAJOR} or newer.`);
|
|
35
|
+
}
|
|
36
|
+
/** `<bot id>:<secret>`, the shape @BotFather hands out. */
|
|
37
|
+
export function tokenLooksValid(token) {
|
|
38
|
+
return /^\d{5,}:[A-Za-z0-9_-]{30,}$/.test(token.trim());
|
|
39
|
+
}
|
|
40
|
+
export function checkToken(token, where) {
|
|
41
|
+
if (!token)
|
|
42
|
+
return fail('TELEGRAM_BOT_TOKEN is not set', `Add it to ${where} (get one from @BotFather).`);
|
|
43
|
+
if (!tokenLooksValid(token)) {
|
|
44
|
+
return fail('TELEGRAM_BOT_TOKEN does not look like a bot token', 'Expected <bot id>:<secret>, e.g. 123456789:AA… — copy it again from @BotFather.');
|
|
45
|
+
}
|
|
46
|
+
return ok(`Bot token for bot ${token.split(':')[0]}`);
|
|
47
|
+
}
|
|
48
|
+
export function checkAllowedUsers(raw) {
|
|
49
|
+
if (!raw?.trim()) {
|
|
50
|
+
return fail('ALLOWED_USER_IDS is not set', '"telecoder init" finds your numeric Telegram id, or get it from @userinfobot.');
|
|
51
|
+
}
|
|
52
|
+
const parsed = parseIdList('ALLOWED_USER_IDS', raw);
|
|
53
|
+
if (!parsed.ok)
|
|
54
|
+
return fail('ALLOWED_USER_IDS is invalid', parsed.error);
|
|
55
|
+
if (parsed.ids.includes(PLACEHOLDER_USER_ID)) {
|
|
56
|
+
return fail(`ALLOWED_USER_IDS still has the placeholder ${PLACEHOLDER_USER_ID}`, 'Replace it with your own numeric Telegram id (get it from @userinfobot).');
|
|
57
|
+
}
|
|
58
|
+
return ok(`Allowed users: ${parsed.ids.join(', ')}`);
|
|
59
|
+
}
|
|
60
|
+
/** What `claude auth status --json` says about being logged in; null when it can't be read. */
|
|
61
|
+
export function parseAuthStatus(stdout) {
|
|
62
|
+
try {
|
|
63
|
+
const parsed = JSON.parse(stdout);
|
|
64
|
+
if (typeof parsed.loggedIn !== 'boolean')
|
|
65
|
+
return null;
|
|
66
|
+
return { loggedIn: parsed.loggedIn, method: typeof parsed.authMethod === 'string' ? parsed.authMethod : undefined };
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const SERVICE_LOGIN_NOTE = (envPath) => `This runs under the service, which doesn't see your shell's environment: a login kept in ${CLAUDE_CREDENTIAL_VARS.join(', ')} has to be in ${envPath}.`;
|
|
73
|
+
/**
|
|
74
|
+
* A login that lives only in the shell's environment works from a terminal,
|
|
75
|
+
* but a service starts without that environment. `envOnly` is what
|
|
76
|
+
* envOnlyLogin found; a variable kept in the .env is fine, the bot loads it.
|
|
77
|
+
*/
|
|
78
|
+
export function checkLoginSurvivesService(envOnly, fileEnv, envPath) {
|
|
79
|
+
if (!envOnly.length || envOnly.some((key) => fileEnv[key]?.trim()))
|
|
80
|
+
return null;
|
|
81
|
+
const vars = envOnly.join(' / ');
|
|
82
|
+
return warn(`Claude Code's login comes from ${vars} in this shell's environment, not stored credentials`, `A background service (telecoder service install) won't see it, so the bot would start logged out there.`, `Add ${vars} to ${envPath} (readable by you only), or log in with "claude auth login".`);
|
|
83
|
+
}
|
|
84
|
+
// ── Checks that look at the machine ────────────────────────────
|
|
85
|
+
function exec(cmd, args, timeout = 15_000, env) {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
execFile(cmd, args, { timeout, maxBuffer: 1024 * 1024, env }, (error, stdout, stderr) => {
|
|
88
|
+
const code = error ? (typeof error.code === 'number' ? error.code : null) : 0;
|
|
89
|
+
resolve({ code, stdout: String(stdout ?? ''), stderr: String(stderr ?? '') });
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function onPath(name) {
|
|
94
|
+
const resolved = resolveBin(name);
|
|
95
|
+
return path.isAbsolute(resolved);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The variables in the .env that change how claude logs in. The bot loads
|
|
99
|
+
* them into its own environment, so `claude auth status` has to see them too,
|
|
100
|
+
* or a login kept in the .env reads as none.
|
|
101
|
+
*/
|
|
102
|
+
const CLAUDE_AUTH_VARS = [
|
|
103
|
+
'ANTHROPIC_API_KEY', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_BASE_URL', 'CLAUDE_CODE_OAUTH_TOKEN', 'CLAUDE_CONFIG_DIR',
|
|
104
|
+
'CLAUDE_CODE_USE_BEDROCK', 'CLAUDE_CODE_USE_VERTEX', 'CLAUDE_CODE_USE_FOUNDRY',
|
|
105
|
+
];
|
|
106
|
+
export function claudeAuthEnv(value, base = process.env) {
|
|
107
|
+
const env = { ...base };
|
|
108
|
+
for (const key of CLAUDE_AUTH_VARS) {
|
|
109
|
+
const v = value(key);
|
|
110
|
+
if (v)
|
|
111
|
+
env[key] = v;
|
|
112
|
+
}
|
|
113
|
+
return env;
|
|
114
|
+
}
|
|
115
|
+
/** The variables that are a Claude login by themselves, as opposed to stored credentials. */
|
|
116
|
+
export const CLAUDE_CREDENTIAL_VARS = ['CLAUDE_CODE_OAUTH_TOKEN', 'ANTHROPIC_API_KEY', 'ANTHROPIC_AUTH_TOKEN'];
|
|
117
|
+
/** The credential variables set (non-empty) in `env`. */
|
|
118
|
+
export function credentialVarsIn(env) {
|
|
119
|
+
return CLAUDE_CREDENTIAL_VARS.filter((key) => env[key]?.trim());
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Whether claude is logged in once the credential variables are taken away:
|
|
123
|
+
* true means stored credentials (~/.claude/.credentials.json, or the macOS
|
|
124
|
+
* keychain), which a service finds too. null when it can't tell (an older CLI
|
|
125
|
+
* without `auth status`), in which case the credentials file is the best sign.
|
|
126
|
+
*/
|
|
127
|
+
export async function hasStoredLogin(executable, env = process.env) {
|
|
128
|
+
const bin = path.isAbsolute(executable) || executable.includes('/') ? executable : resolveBin(executable);
|
|
129
|
+
const bare = { ...env };
|
|
130
|
+
for (const key of CLAUDE_CREDENTIAL_VARS)
|
|
131
|
+
delete bare[key];
|
|
132
|
+
const status = parseAuthStatus((await exec(bin, ['auth', 'status', '--json'], 20_000, bare)).stdout);
|
|
133
|
+
if (status)
|
|
134
|
+
return status.loggedIn;
|
|
135
|
+
const configDir = env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
|
|
136
|
+
return fs.existsSync(path.join(configDir, '.credentials.json')) ? true : null;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The credential variables a working login depends on: set in `env`, and
|
|
140
|
+
* claude logged out without them. Empty when the login is stored, or there
|
|
141
|
+
* is none to speak of.
|
|
142
|
+
*/
|
|
143
|
+
export async function envOnlyLogin(executable, env = process.env) {
|
|
144
|
+
const vars = credentialVarsIn(env);
|
|
145
|
+
if (!vars.length)
|
|
146
|
+
return [];
|
|
147
|
+
return (await hasStoredLogin(executable, env)) ? [] : vars;
|
|
148
|
+
}
|
|
149
|
+
export async function checkClaude(executable, env = process.env) {
|
|
150
|
+
const bin = path.isAbsolute(executable) || executable.includes('/') ? executable : resolveBin(executable);
|
|
151
|
+
const version = await exec(bin, ['--version'], 15_000, env);
|
|
152
|
+
if (version.code !== 0) {
|
|
153
|
+
return [fail(`Claude Code CLI not found (${executable})`, 'Install it: curl -fsSL https://claude.ai/install.sh | bash — or set CLAUDE_EXECUTABLE_PATH.')];
|
|
154
|
+
}
|
|
155
|
+
const results = [ok(`Claude Code ${version.stdout.trim().split('\n')[0]}`)];
|
|
156
|
+
const auth = await exec(bin, ['auth', 'status', '--json'], 20_000, env);
|
|
157
|
+
const status = parseAuthStatus(auth.stdout);
|
|
158
|
+
if (status?.loggedIn) {
|
|
159
|
+
results.push(ok(`Claude Code is logged in${status.method ? ` (${status.method})` : ''}`));
|
|
160
|
+
}
|
|
161
|
+
else if (status) {
|
|
162
|
+
results.push(fail('Claude Code is not logged in', 'Run "claude" once and log in, or run "claude setup-token" and set CLAUDE_CODE_OAUTH_TOKEN in the .env.'));
|
|
163
|
+
}
|
|
164
|
+
else if (env.ANTHROPIC_API_KEY || env.CLAUDE_CODE_OAUTH_TOKEN
|
|
165
|
+
|| fs.existsSync(path.join(os.homedir(), '.claude', '.credentials.json'))) {
|
|
166
|
+
// An older CLI without `auth status`: credentials on disk are the best sign.
|
|
167
|
+
results.push(ok('Claude Code credentials found'));
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
results.push(warn("Couldn't confirm the Claude Code login", 'If the bot can\'t answer, run "claude" once and log in.'));
|
|
171
|
+
}
|
|
172
|
+
return results;
|
|
173
|
+
}
|
|
174
|
+
export async function checkNodePty() {
|
|
175
|
+
try {
|
|
176
|
+
await import('node-pty');
|
|
177
|
+
return [ok('node-pty loads')];
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
const missing = [
|
|
181
|
+
['a C compiler', ['cc', 'gcc', 'clang']],
|
|
182
|
+
['a C++ compiler', ['c++', 'g++', 'clang++']],
|
|
183
|
+
['make', ['make']],
|
|
184
|
+
['python3', ['python3']],
|
|
185
|
+
].filter(([, names]) => !names.some(onPath)).map(([what]) => what);
|
|
186
|
+
const fix = process.platform === 'darwin'
|
|
187
|
+
? 'Install the Xcode command line tools (xcode-select --install), then reinstall TeleCoder.'
|
|
188
|
+
: 'Install a build toolchain (e.g. apt install build-essential python3), then reinstall TeleCoder.';
|
|
189
|
+
return [fail('node-pty failed to load (the terminal mode needs it)', redactSecrets(error instanceof Error ? error.message.split('\n')[0] : String(error)), ...(missing.length ? [`Missing: ${missing.join(', ')}.`, fix] : ['A build toolchain is present; try reinstalling TeleCoder.']))];
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async function checkLive(token) {
|
|
193
|
+
try {
|
|
194
|
+
const res = await fetch(`https://api.telegram.org/bot${token}/getMe`, { signal: AbortSignal.timeout(10_000) });
|
|
195
|
+
const body = await res.json();
|
|
196
|
+
if (body.ok && body.result?.username)
|
|
197
|
+
return ok(`Telegram knows the token: @${body.result.username}`);
|
|
198
|
+
return fail('Telegram rejected the token', redactSecrets(body.description ?? `HTTP ${res.status}`));
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
// The message of a failed fetch can carry the URL, and the URL the token.
|
|
202
|
+
return warn("Couldn't reach Telegram", redactSecrets(error instanceof Error ? error.message : String(error)).replaceAll(token, '<token>'));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// ── The command ────────────────────────────────────────────────
|
|
206
|
+
const ICON = { ok: '✓', warn: '!', fail: '✗' };
|
|
207
|
+
function print(io, result) {
|
|
208
|
+
io.out(`${ICON[result.status]} ${result.label}`);
|
|
209
|
+
for (const line of result.detail ?? [])
|
|
210
|
+
io.out(` ${line}`);
|
|
211
|
+
}
|
|
212
|
+
export async function runChecks(args) {
|
|
213
|
+
const results = [];
|
|
214
|
+
const live = args.includes('--live');
|
|
215
|
+
results.push(checkNodeVersion());
|
|
216
|
+
results.push(ok(`TeleCoder ${getInstalledVersion() ?? '?'} (${getInstallMode()} install at ${PACKAGE_ROOT})`));
|
|
217
|
+
const home = getConfigHomeInfo();
|
|
218
|
+
const why = { override: 'from TELECODER_HOME', 'package-root': 'next to package.json', home: 'default' }[home.source];
|
|
219
|
+
results.push(ok(`Config home: ${home.dir} (${why})`));
|
|
220
|
+
const envPath = legacyEnv('ENV_PATH') || configFile('.env');
|
|
221
|
+
const instancesPath = configFile('instances.json');
|
|
222
|
+
let fileEnv = {};
|
|
223
|
+
if (fs.existsSync(envPath)) {
|
|
224
|
+
try {
|
|
225
|
+
fileEnv = parseEnv(fs.readFileSync(envPath));
|
|
226
|
+
results.push(ok(`Config file: ${envPath}`));
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
results.push(fail(`Can't read ${envPath}`, error instanceof Error ? error.message : String(error)));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
else if (!fs.existsSync(instancesPath)) {
|
|
233
|
+
results.push(fail(`No config file at ${envPath}`, 'Run "telecoder init" to set one up.'));
|
|
234
|
+
}
|
|
235
|
+
// The environment wins over the file, as it does in the bot.
|
|
236
|
+
const value = (key) => process.env[key] ?? fileEnv[key];
|
|
237
|
+
const tokens = [];
|
|
238
|
+
if (fs.existsSync(instancesPath)) {
|
|
239
|
+
try {
|
|
240
|
+
const warnings = [];
|
|
241
|
+
const instances = resolveInstances(fs.readFileSync(instancesPath, 'utf-8'), (w) => warnings.push(w));
|
|
242
|
+
results.push(ok(`instances.json: ${instances.length} bot(s) — ${instances.map((i) => i.name).join(', ')}`));
|
|
243
|
+
for (const w of warnings)
|
|
244
|
+
results.push(warn(w));
|
|
245
|
+
for (const inst of instances) {
|
|
246
|
+
const r = checkToken(inst.token, instancesPath);
|
|
247
|
+
if (r.status !== 'ok')
|
|
248
|
+
results.push({ ...r, label: `${inst.name}: ${r.label}` });
|
|
249
|
+
else
|
|
250
|
+
tokens.push(inst.token);
|
|
251
|
+
}
|
|
252
|
+
const users = instances.map((i) => i.overrides?.ALLOWED_USER_IDS ?? value('ALLOWED_USER_IDS'));
|
|
253
|
+
for (const r of new Set(users))
|
|
254
|
+
results.push(checkAllowedUsers(r));
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
if (!(error instanceof InstancesConfigError))
|
|
258
|
+
throw error;
|
|
259
|
+
results.push(fail(`instances.json: ${error.message}`));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
const token = value('TELEGRAM_BOT_TOKEN');
|
|
264
|
+
const r = checkToken(token, envPath);
|
|
265
|
+
results.push(r);
|
|
266
|
+
if (r.status === 'ok' && token)
|
|
267
|
+
tokens.push(token);
|
|
268
|
+
results.push(checkAllowedUsers(value('ALLOWED_USER_IDS')));
|
|
269
|
+
}
|
|
270
|
+
const claudeBin = value('CLAUDE_EXECUTABLE_PATH') || 'claude';
|
|
271
|
+
const claude = await checkClaude(claudeBin, claudeAuthEnv(value));
|
|
272
|
+
results.push(...claude);
|
|
273
|
+
if (claude[1]?.status === 'ok') {
|
|
274
|
+
const loginWarning = checkLoginSurvivesService(await envOnlyLogin(claudeBin, claudeAuthEnv(value)), fileEnv, envPath);
|
|
275
|
+
if (loginWarning)
|
|
276
|
+
results.push(loginWarning);
|
|
277
|
+
}
|
|
278
|
+
else if (claude[1]?.status === 'fail' && process.env[SERVICE_MANAGER_ENV]) {
|
|
279
|
+
claude[1].detail = [...claude[1].detail ?? [], SERVICE_LOGIN_NOTE(envPath)];
|
|
280
|
+
}
|
|
281
|
+
results.push(...await checkNodePty());
|
|
282
|
+
if (live) {
|
|
283
|
+
for (const token of tokens)
|
|
284
|
+
results.push(await checkLive(token));
|
|
285
|
+
}
|
|
286
|
+
return results;
|
|
287
|
+
}
|
|
288
|
+
export async function run(args, io) {
|
|
289
|
+
const results = await runChecks(args);
|
|
290
|
+
for (const r of results)
|
|
291
|
+
print(io, r);
|
|
292
|
+
const failed = results.filter((r) => r.status === 'fail').length;
|
|
293
|
+
const warned = results.filter((r) => r.status === 'warn').length;
|
|
294
|
+
io.out('');
|
|
295
|
+
if (failed)
|
|
296
|
+
io.out(`${failed} problem(s) to fix before "telecoder start" will work.`);
|
|
297
|
+
else if (warned)
|
|
298
|
+
io.out(`Ready to start, with ${warned} warning(s).`);
|
|
299
|
+
else
|
|
300
|
+
io.out('All good. Run "telecoder start".');
|
|
301
|
+
if (!args.includes('--live') && !failed)
|
|
302
|
+
io.out('(Add --live to check the token with Telegram.)');
|
|
303
|
+
return failed ? 1 : 0;
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=doctor.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { COMMANDS } from '../dispatch.js';
|
|
2
|
+
export function helpText(only) {
|
|
3
|
+
const names = only && Object.hasOwn(COMMANDS, only) ? [only] : Object.keys(COMMANDS);
|
|
4
|
+
const rows = names.map((name) => {
|
|
5
|
+
const spec = COMMANDS[name];
|
|
6
|
+
return { left: [name, spec.usage].filter(Boolean).join(' '), right: spec.summary };
|
|
7
|
+
});
|
|
8
|
+
const width = Math.max(...rows.map((r) => r.left.length));
|
|
9
|
+
return [
|
|
10
|
+
'TeleCoder: Claude Code from Telegram',
|
|
11
|
+
'',
|
|
12
|
+
'Usage: telecoder <command> [options]',
|
|
13
|
+
'',
|
|
14
|
+
'Commands:',
|
|
15
|
+
...rows.map((r) => ` ${r.left.padEnd(width)} ${r.right}`),
|
|
16
|
+
'',
|
|
17
|
+
'Config is read from ~/.telecoder/.env (TELECODER_HOME moves it), or from',
|
|
18
|
+
'next to package.json in a source checkout. Docs: https://telecoder.dev',
|
|
19
|
+
].join('\n');
|
|
20
|
+
}
|
|
21
|
+
export async function run(args, io) {
|
|
22
|
+
io.out(helpText(args[0]));
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=help.js.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `telecoder init` — set up a bot interactively, or from flags in a script.
|
|
3
|
+
*
|
|
4
|
+
* The wizard itself is ../init/flow.ts; this module parses the flags and hands
|
|
5
|
+
* it the real terminal, the real Telegram and the real config location (the
|
|
6
|
+
* same .env `telecoder start` and the bot read: TELECODER_ENV_PATH if set,
|
|
7
|
+
* else <config home>/.env).
|
|
8
|
+
*/
|
|
9
|
+
import * as os from 'os';
|
|
10
|
+
import { getConfigHomeInfo, configFile } from '../../utils/config-home.js';
|
|
11
|
+
import { isCheckout, detectPackageRunner } from '../../utils/install-mode.js';
|
|
12
|
+
import { legacyEnv } from '../../utils/legacy-env.js';
|
|
13
|
+
import { checkClaude, checkNodePty, checkNodeVersion, envOnlyLogin } from './doctor.js';
|
|
14
|
+
import { runInit } from '../init/flow.js';
|
|
15
|
+
import { runServiceInstall } from './service.js';
|
|
16
|
+
import { createTerminalPrompter } from '../init/prompter.js';
|
|
17
|
+
import { createTelegramClient, DEFAULT_API_ROOT } from '../init/telegram.js';
|
|
18
|
+
const USAGE = [
|
|
19
|
+
'Usage: telecoder init [options]',
|
|
20
|
+
'',
|
|
21
|
+
'Asks for everything it needs when run in a terminal. For scripts:',
|
|
22
|
+
' --token-env VAR read the bot token from environment variable VAR',
|
|
23
|
+
' (never pass the token itself: arguments show up in ps)',
|
|
24
|
+
' --owner-id ID your numeric Telegram user id',
|
|
25
|
+
' --workspace DIR the folder your projects are in (default: ~/projects or ~)',
|
|
26
|
+
' --transport sdk|pty how Claude Code runs (default: sdk)',
|
|
27
|
+
' --groq-key-env VAR turn voice transcription on, with the Groq key in VAR',
|
|
28
|
+
' --telegraph publish long replies to Telegraph (public pages)',
|
|
29
|
+
' --no-test-message don\'t have the bot message you at the end',
|
|
30
|
+
' --yes ask nothing: take defaults, replace an existing .env',
|
|
31
|
+
' (backed up first), remove a webhook if one is set',
|
|
32
|
+
];
|
|
33
|
+
export function parseInitArgs(args) {
|
|
34
|
+
const opts = {};
|
|
35
|
+
const valued = {
|
|
36
|
+
'--token-env': (v) => { opts.tokenEnv = v; },
|
|
37
|
+
'--owner-id': (v) => { opts.ownerId = v; },
|
|
38
|
+
'--workspace': (v) => { opts.workspace = v; },
|
|
39
|
+
'--groq-key-env': (v) => { opts.groqKeyEnv = v; },
|
|
40
|
+
'--transport': (v) => {
|
|
41
|
+
if (v !== 'sdk' && v !== 'pty')
|
|
42
|
+
return '--transport takes sdk or pty.';
|
|
43
|
+
opts.transport = v;
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
for (let i = 0; i < args.length; i++) {
|
|
47
|
+
const [flag, inline] = args[i].includes('=') ? args[i].split(/=(.*)/s, 2) : [args[i], undefined];
|
|
48
|
+
if (flag === '--yes' || flag === '-y')
|
|
49
|
+
opts.yes = true;
|
|
50
|
+
else if (flag === '--telegraph')
|
|
51
|
+
opts.telegraph = true;
|
|
52
|
+
else if (flag === '--no-telegraph')
|
|
53
|
+
opts.telegraph = false;
|
|
54
|
+
else if (flag === '--no-test-message')
|
|
55
|
+
opts.noTestMessage = true;
|
|
56
|
+
else if (flag === '--token' || flag === '--groq-key') {
|
|
57
|
+
return { ok: false, error: `${flag} isn't accepted: arguments show up in ps. Put it in an environment variable and pass ${flag}-env VAR.` };
|
|
58
|
+
}
|
|
59
|
+
else if (Object.hasOwn(valued, flag)) {
|
|
60
|
+
const value = inline ?? args[++i];
|
|
61
|
+
if (value === undefined || value === '')
|
|
62
|
+
return { ok: false, error: `${flag} needs a value.` };
|
|
63
|
+
const problem = valued[flag](value);
|
|
64
|
+
if (problem)
|
|
65
|
+
return { ok: false, error: problem };
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return { ok: false, error: `Unknown option: ${args[i]}` };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { ok: true, opts };
|
|
72
|
+
}
|
|
73
|
+
export async function run(args, io) {
|
|
74
|
+
const parsed = parseInitArgs(args);
|
|
75
|
+
if (!parsed.ok) {
|
|
76
|
+
io.err(parsed.error);
|
|
77
|
+
for (const line of USAGE)
|
|
78
|
+
io.err(line);
|
|
79
|
+
return 2;
|
|
80
|
+
}
|
|
81
|
+
const claudeBin = process.env.CLAUDE_EXECUTABLE_PATH || 'claude';
|
|
82
|
+
const envPath = legacyEnv('ENV_PATH') || configFile('.env');
|
|
83
|
+
// Test-only: point the wizard at a fake Telegram. See init/telegram.ts.
|
|
84
|
+
const apiRoot = process.env.TELECODER_TELEGRAM_API_ROOT || DEFAULT_API_ROOT;
|
|
85
|
+
const prompter = createTerminalPrompter();
|
|
86
|
+
let serviceRequested = false;
|
|
87
|
+
let code;
|
|
88
|
+
try {
|
|
89
|
+
code = await runInit(parsed.opts, {
|
|
90
|
+
prompter,
|
|
91
|
+
makeClient: (token) => createTelegramClient(token, { apiRoot }),
|
|
92
|
+
preflight: async () => {
|
|
93
|
+
const claude = await checkClaude(claudeBin);
|
|
94
|
+
return {
|
|
95
|
+
node: checkNodeVersion(),
|
|
96
|
+
claude,
|
|
97
|
+
envLogin: claude[1]?.status === 'ok' ? await envOnlyLogin(claudeBin) : [],
|
|
98
|
+
nodePty: await checkNodePty(),
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
envPath,
|
|
102
|
+
// Tighten only ~/.telecoder itself: a checkout's root or a TELECODER_HOME
|
|
103
|
+
// may be a directory other things live in (a new one is made 0700 anyway).
|
|
104
|
+
ownDir: envPath === configFile('.env') && getConfigHomeInfo().source === 'home',
|
|
105
|
+
env: process.env,
|
|
106
|
+
homedir: os.homedir(),
|
|
107
|
+
claudeBin,
|
|
108
|
+
isCheckout: isCheckout(),
|
|
109
|
+
// Not from npx: its cache can be cleared under the unit, and the installer
|
|
110
|
+
// refuses it anyway.
|
|
111
|
+
requestService: detectPackageRunner() === 'npx' ? undefined : () => { serviceRequested = true; },
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
prompter.close();
|
|
116
|
+
}
|
|
117
|
+
if (code === 0 && serviceRequested) {
|
|
118
|
+
io.out('');
|
|
119
|
+
return runServiceInstall({ io });
|
|
120
|
+
}
|
|
121
|
+
return code;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=init.js.map
|