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.
Files changed (223) hide show
  1. package/.env.example +363 -0
  2. package/CHANGELOG.md +1186 -0
  3. package/LICENSE +22 -0
  4. package/README.md +126 -2
  5. package/dist/audio/transcribe.js +50 -0
  6. package/dist/bin/mcp-server.js +378 -0
  7. package/dist/bin/tool-result.js +22 -0
  8. package/dist/bot/access/group-access.js +147 -0
  9. package/dist/bot/bot.js +592 -0
  10. package/dist/bot/file-access.js +141 -0
  11. package/dist/bot/handlers/command/access.js +407 -0
  12. package/dist/bot/handlers/command/admin.js +827 -0
  13. package/dist/bot/handlers/command/auto-approve.js +138 -0
  14. package/dist/bot/handlers/command/btw.js +224 -0
  15. package/dist/bot/handlers/command/cost.js +409 -0
  16. package/dist/bot/handlers/command/media.js +197 -0
  17. package/dist/bot/handlers/command/model.js +305 -0
  18. package/dist/bot/handlers/command/prefs-scope.js +197 -0
  19. package/dist/bot/handlers/command/project.js +536 -0
  20. package/dist/bot/handlers/command/resume.js +321 -0
  21. package/dist/bot/handlers/command/session.js +438 -0
  22. package/dist/bot/handlers/command/settings.js +1012 -0
  23. package/dist/bot/handlers/command/shared.js +210 -0
  24. package/dist/bot/handlers/command/streaming-mode.js +16 -0
  25. package/dist/bot/handlers/command/tasks.js +513 -0
  26. package/dist/bot/handlers/command/topic-store.js +113 -0
  27. package/dist/bot/handlers/command/topic.js +80 -0
  28. package/dist/bot/handlers/command.handler.js +772 -0
  29. package/dist/bot/handlers/fork.handler.js +1109 -0
  30. package/dist/bot/handlers/media-fallback.js +121 -0
  31. package/dist/bot/handlers/message/replies.js +133 -0
  32. package/dist/bot/handlers/message/shared.js +117 -0
  33. package/dist/bot/handlers/message/throttle.js +49 -0
  34. package/dist/bot/handlers/message/turn-notify.js +169 -0
  35. package/dist/bot/handlers/message/turn-runner.js +141 -0
  36. package/dist/bot/handlers/message.handler.js +107 -0
  37. package/dist/bot/handlers/newbot.handler.js +221 -0
  38. package/dist/bot/handlers/photo.handler.js +327 -0
  39. package/dist/bot/handlers/prompts.handler.js +343 -0
  40. package/dist/bot/handlers/running-note.js +44 -0
  41. package/dist/bot/handlers/schedule.handler.js +303 -0
  42. package/dist/bot/handlers/session-guard.js +78 -0
  43. package/dist/bot/handlers/suggestion.handler.js +84 -0
  44. package/dist/bot/handlers/tree.handler.js +480 -0
  45. package/dist/bot/handlers/view.js +41 -0
  46. package/dist/bot/handlers/voice.handler.js +209 -0
  47. package/dist/bot/middleware/admin-only.js +49 -0
  48. package/dist/bot/middleware/auth.middleware.js +122 -0
  49. package/dist/bot/middleware/group-mention.middleware.js +139 -0
  50. package/dist/bot/middleware/group-role.middleware.js +75 -0
  51. package/dist/bot/middleware/message-batcher.js +87 -0
  52. package/dist/bot/middleware/queued-messages.js +971 -0
  53. package/dist/bot/middleware/stale-filter.js +31 -0
  54. package/dist/build-info.json +8 -0
  55. package/dist/claude/agent-watchdog.js +162 -0
  56. package/dist/claude/agent.js +1458 -0
  57. package/dist/claude/ask-user.js +295 -0
  58. package/dist/claude/auto-approve.js +225 -0
  59. package/dist/claude/auto-topic-haiku.js +126 -0
  60. package/dist/claude/available-commands.js +153 -0
  61. package/dist/claude/carry-over.js +27 -0
  62. package/dist/claude/ccr-shim.js +46 -0
  63. package/dist/claude/charter-judge.js +214 -0
  64. package/dist/claude/claude-auth.js +121 -0
  65. package/dist/claude/command-parser.js +200 -0
  66. package/dist/claude/cost-overlay-scraper.js +129 -0
  67. package/dist/claude/enabled-plugins.js +56 -0
  68. package/dist/claude/fork-tree.js +393 -0
  69. package/dist/claude/held-query.js +190 -0
  70. package/dist/claude/in-flight-tracker.js +61 -0
  71. package/dist/claude/ipc-server.js +192 -0
  72. package/dist/claude/mcp-bridge.js +453 -0
  73. package/dist/claude/mcp-tools.js +354 -0
  74. package/dist/claude/message-offsets.js +88 -0
  75. package/dist/claude/modal-relay.js +450 -0
  76. package/dist/claude/model-catalog.js +85 -0
  77. package/dist/claude/monitor-relay.js +597 -0
  78. package/dist/claude/pending-forks.js +93 -0
  79. package/dist/claude/pending-suggestions.js +50 -0
  80. package/dist/claude/permission-gate.js +337 -0
  81. package/dist/claude/permission-mode.js +178 -0
  82. package/dist/claude/poll-user.js +51 -0
  83. package/dist/claude/project-commands.js +69 -0
  84. package/dist/claude/prompt-hold.js +124 -0
  85. package/dist/claude/prompt-suggestion-scraper.js +89 -0
  86. package/dist/claude/pty-provider.js +2214 -0
  87. package/dist/claude/pty-spawn-config.js +296 -0
  88. package/dist/claude/pty-stream.js +363 -0
  89. package/dist/claude/request-queue.js +135 -0
  90. package/dist/claude/scheduled-runner.js +91 -0
  91. package/dist/claude/scheduler.js +237 -0
  92. package/dist/claude/scope-guard.js +274 -0
  93. package/dist/claude/sdk-permission-gate.js +77 -0
  94. package/dist/claude/secret-request.js +576 -0
  95. package/dist/claude/session-cost.js +41 -0
  96. package/dist/claude/session-history.js +286 -0
  97. package/dist/claude/session-jsonl.js +920 -0
  98. package/dist/claude/session-manager.js +195 -0
  99. package/dist/claude/session-scan.js +270 -0
  100. package/dist/claude/setup-token.js +285 -0
  101. package/dist/claude/side-call-options.js +45 -0
  102. package/dist/claude/side-question.js +249 -0
  103. package/dist/claude/stage-images.js +62 -0
  104. package/dist/claude/subagent-tools.js +12 -0
  105. package/dist/claude/synthetic-ctx.js +51 -0
  106. package/dist/claude/system-prompt.js +162 -0
  107. package/dist/claude/tasks-overlay-scraper.js +94 -0
  108. package/dist/claude/tip-scraper.js +78 -0
  109. package/dist/claude/tui-modal.js +501 -0
  110. package/dist/claude/tui-state.js +384 -0
  111. package/dist/claude/turn-end.js +91 -0
  112. package/dist/claude/turn-prose.js +64 -0
  113. package/dist/claude/update-banner-relay.js +70 -0
  114. package/dist/cli/commands/doctor.js +305 -0
  115. package/dist/cli/commands/help.js +25 -0
  116. package/dist/cli/commands/init.js +123 -0
  117. package/dist/cli/commands/service.js +678 -0
  118. package/dist/cli/commands/start.js +53 -0
  119. package/dist/cli/commands/version.js +11 -0
  120. package/dist/cli/dispatch.js +79 -0
  121. package/dist/cli/init/env-file.js +99 -0
  122. package/dist/cli/init/flow.js +638 -0
  123. package/dist/cli/init/prompter.js +116 -0
  124. package/dist/cli/init/telegram.js +94 -0
  125. package/dist/cli/service/render.js +212 -0
  126. package/dist/cli.js +18 -0
  127. package/dist/config-report.js +107 -0
  128. package/dist/config.js +500 -0
  129. package/dist/index.js +367 -0
  130. package/dist/launcher.js +933 -0
  131. package/dist/node-version-check.js +27 -0
  132. package/dist/providers/ccr-health.js +119 -0
  133. package/dist/providers/ccr-introspect.js +149 -0
  134. package/dist/providers/ccr-provider.js +60 -0
  135. package/dist/providers/claude-provider.js +63 -0
  136. package/dist/providers/prefs-sync.js +164 -0
  137. package/dist/providers/project-favorites.js +74 -0
  138. package/dist/providers/provider-router.js +127 -0
  139. package/dist/providers/provider-switch.js +91 -0
  140. package/dist/providers/sdk-provider.js +37 -0
  141. package/dist/providers/types.js +8 -0
  142. package/dist/providers/user-preferences.js +214 -0
  143. package/dist/restart-when-idle.js +153 -0
  144. package/dist/startup/auto-continue.js +67 -0
  145. package/dist/startup/auto-resume.js +173 -0
  146. package/dist/startup/notices.js +120 -0
  147. package/dist/startup/shared.js +44 -0
  148. package/dist/startup/verify-token.js +31 -0
  149. package/dist/telegram/access-request.js +153 -0
  150. package/dist/telegram/action-logger.js +684 -0
  151. package/dist/telegram/admin-mention.js +107 -0
  152. package/dist/telegram/background-activity-card.js +502 -0
  153. package/dist/telegram/botname-settings.js +336 -0
  154. package/dist/telegram/button-text.js +26 -0
  155. package/dist/telegram/client-options.js +27 -0
  156. package/dist/telegram/deduplication.js +33 -0
  157. package/dist/telegram/entities.js +295 -0
  158. package/dist/telegram/force-reply-tracker.js +57 -0
  159. package/dist/telegram/lettered-options.js +87 -0
  160. package/dist/telegram/markdown.js +362 -0
  161. package/dist/telegram/message-sender.js +1287 -0
  162. package/dist/telegram/prompt-label.js +142 -0
  163. package/dist/telegram/prompt-suggestion.js +54 -0
  164. package/dist/telegram/send.js +123 -0
  165. package/dist/telegram/streaming-turn.js +105 -0
  166. package/dist/telegram/suggestions-settings.js +30 -0
  167. package/dist/telegram/task-list.js +367 -0
  168. package/dist/telegram/task-tracker.js +209 -0
  169. package/dist/telegram/telegraph-settings.js +31 -0
  170. package/dist/telegram/telegraph.js +453 -0
  171. package/dist/telegram/terminal-renderer.js +671 -0
  172. package/dist/telegram/terminal-settings.js +25 -0
  173. package/dist/telegram/thread-titles.js +190 -0
  174. package/dist/telegram/threads-setup.js +117 -0
  175. package/dist/tts/tts-settings.js +62 -0
  176. package/dist/tts/tts.js +245 -0
  177. package/dist/tts/voice-reply.js +78 -0
  178. package/dist/utils/admins.js +143 -0
  179. package/dist/utils/agent-timer.js +55 -0
  180. package/dist/utils/atomic-write.js +24 -0
  181. package/dist/utils/bot-token.js +74 -0
  182. package/dist/utils/bounded-map.js +55 -0
  183. package/dist/utils/build-info.js +57 -0
  184. package/dist/utils/caffeinate.js +50 -0
  185. package/dist/utils/claude-env.js +54 -0
  186. package/dist/utils/claude-version.js +48 -0
  187. package/dist/utils/config-home.js +62 -0
  188. package/dist/utils/debug-agent.js +117 -0
  189. package/dist/utils/debug-watchdog.js +121 -0
  190. package/dist/utils/download.js +111 -0
  191. package/dist/utils/exit-codes.js +48 -0
  192. package/dist/utils/file-type.js +149 -0
  193. package/dist/utils/format.js +81 -0
  194. package/dist/utils/home-project.js +30 -0
  195. package/dist/utils/host-stall.js +51 -0
  196. package/dist/utils/id-list.js +44 -0
  197. package/dist/utils/idle-restart.js +92 -0
  198. package/dist/utils/install-mode.js +63 -0
  199. package/dist/utils/instance-config.js +148 -0
  200. package/dist/utils/instances.js +95 -0
  201. package/dist/utils/json-store.js +140 -0
  202. package/dist/utils/keyed-settings.js +62 -0
  203. package/dist/utils/legacy-env.js +35 -0
  204. package/dist/utils/npm-version.js +134 -0
  205. package/dist/utils/prefs-relay.js +107 -0
  206. package/dist/utils/proc-children.js +102 -0
  207. package/dist/utils/project-data-dir.js +33 -0
  208. package/dist/utils/reasoning-summary.js +12 -0
  209. package/dist/utils/resolve-bin.js +86 -0
  210. package/dist/utils/resolve-claude-bin.js +63 -0
  211. package/dist/utils/respawn-backoff.js +19 -0
  212. package/dist/utils/sanitize.js +91 -0
  213. package/dist/utils/session-key.js +37 -0
  214. package/dist/utils/stale-launcher.js +109 -0
  215. package/dist/utils/state-dir-migration.js +92 -0
  216. package/dist/utils/systemd.js +126 -0
  217. package/dist/utils/user-roster.js +275 -0
  218. package/dist/utils/verbosity.js +118 -0
  219. package/dist/utils/version-check.js +166 -0
  220. package/dist/utils/workspace-guard.js +44 -0
  221. package/dist/worker-restart.js +141 -0
  222. package/instances.json.example +41 -0
  223. package/package.json +76 -4
@@ -0,0 +1,53 @@
1
+ /**
2
+ * `telecoder start` — run the bot in this process.
3
+ *
4
+ * One bot is what `npm start` runs (index.ts); several are what
5
+ * `npm run start:multi` runs (launcher.ts). In a checkout you pick by script;
6
+ * here the config decides: an instances.json in the config home means the
7
+ * launcher, otherwise a single bot from .env. --single / --multi override that.
8
+ *
9
+ * Either way the bot's own module takes over the process, so this resolves
10
+ * with nothing and leaves the exit to it.
11
+ */
12
+ import * as fs from 'fs';
13
+ import * as path from 'path';
14
+ import { configFile, getConfigHome } from '../../utils/config-home.js';
15
+ import { legacyEnv } from '../../utils/legacy-env.js';
16
+ import { PACKAGE_ROOT } from '../../utils/install-mode.js';
17
+ /** Which entry point to run. Pure, for tests. */
18
+ export function chooseStartTarget({ args, instancesExists }) {
19
+ if (args.includes('--single'))
20
+ return 'single';
21
+ if (args.includes('--multi') || args.includes('--config'))
22
+ return 'multi';
23
+ return instancesExists ? 'multi' : 'single';
24
+ }
25
+ /** The lines to print when there is no config to start from. */
26
+ export function missingConfigMessage(envPath) {
27
+ return [
28
+ `No TeleCoder config found: ${envPath} doesn't exist.`,
29
+ '',
30
+ 'Run "telecoder init" to set one up. (Or copy',
31
+ `${path.join(PACKAGE_ROOT, '.env.example')} to ${envPath} and fill in`,
32
+ 'TELEGRAM_BOT_TOKEN and ALLOWED_USER_IDS.)',
33
+ '',
34
+ `Config is read from ${getConfigHome()}; set TELECODER_HOME to use another directory.`,
35
+ ];
36
+ }
37
+ export async function run(args, io) {
38
+ const target = chooseStartTarget({ args, instancesExists: fs.existsSync(configFile('instances.json')) });
39
+ if (target === 'single') {
40
+ const envPath = legacyEnv('ENV_PATH') || configFile('.env');
41
+ // A token in the environment is a complete config on its own (a service
42
+ // unit with Environment= lines, say), so only a missing both is fatal.
43
+ if (!fs.existsSync(envPath) && !process.env.TELEGRAM_BOT_TOKEN) {
44
+ for (const line of missingConfigMessage(envPath))
45
+ io.err(line);
46
+ return 1;
47
+ }
48
+ await import('../../index.js');
49
+ return;
50
+ }
51
+ await import('../../launcher.js');
52
+ }
53
+ //# sourceMappingURL=start.js.map
@@ -0,0 +1,11 @@
1
+ import { getInstalledVersion } from '../../utils/install-mode.js';
2
+ export async function run(_args, io) {
3
+ const version = getInstalledVersion();
4
+ if (!version) {
5
+ io.err('Could not read the version from package.json.');
6
+ return 1;
7
+ }
8
+ io.out(version);
9
+ return 0;
10
+ }
11
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1,79 @@
1
+ /**
2
+ * `telecoder <command>` — argument parsing and the command table.
3
+ *
4
+ * Each command lives in its own module under ./commands/ and is imported only
5
+ * when it runs, so `telecoder --version` never loads the bot (whose config
6
+ * module reads and validates the .env as it is imported).
7
+ *
8
+ * A command resolves with an exit code, or with nothing when it has handed the
9
+ * process over to something long-running (`start`), which then owns the exit.
10
+ *
11
+ * Adding a command: write ./commands/<name>.ts exporting `run(args, io)`, and
12
+ * add an entry below.
13
+ */
14
+ export const defaultIo = {
15
+ out: (line) => console.log(line),
16
+ err: (line) => console.error(line),
17
+ };
18
+ export const COMMANDS = {
19
+ start: {
20
+ summary: 'Run the bot; all of instances.json when it exists',
21
+ usage: '[--single|--multi]',
22
+ load: () => import('./commands/start.js'),
23
+ },
24
+ doctor: {
25
+ summary: 'Check that everything TeleCoder needs is in place',
26
+ usage: '[--live]',
27
+ load: () => import('./commands/doctor.js'),
28
+ },
29
+ init: {
30
+ summary: 'Set up a bot step by step: token, owner, workspace; writes the .env',
31
+ usage: '[options]',
32
+ load: () => import('./commands/init.js'),
33
+ },
34
+ service: {
35
+ summary: 'Run it in the background: systemd (Linux) or launchd (macOS)',
36
+ usage: 'install|status|logs|restart|uninstall',
37
+ load: () => import('./commands/service.js'),
38
+ },
39
+ help: {
40
+ summary: 'Show this help',
41
+ load: () => import('./commands/help.js'),
42
+ },
43
+ version: {
44
+ summary: 'Print the installed version',
45
+ load: () => import('./commands/version.js'),
46
+ },
47
+ };
48
+ /** Flags that stand in for a command when given first. */
49
+ const ALIASES = {
50
+ '--version': 'version',
51
+ '-v': 'version',
52
+ '-V': 'version',
53
+ '--help': 'help',
54
+ '-h': 'help',
55
+ };
56
+ export function parseArgs(argv, commands = COMMANDS) {
57
+ const [first, ...rest] = argv;
58
+ if (first === undefined)
59
+ return { kind: 'command', name: 'help', args: [] };
60
+ const name = ALIASES[first] ?? first;
61
+ if (!Object.hasOwn(commands, name))
62
+ return { kind: 'unknown', name: first };
63
+ // `telecoder start --help` is help about start, not a start.
64
+ if (name !== 'help' && (rest.includes('--help') || rest.includes('-h'))) {
65
+ return { kind: 'command', name: 'help', args: [name] };
66
+ }
67
+ return { kind: 'command', name, args: rest };
68
+ }
69
+ export async function dispatch(argv, { commands = COMMANDS, io = defaultIo } = {}) {
70
+ const parsed = parseArgs(argv, commands);
71
+ if (parsed.kind === 'unknown') {
72
+ io.err(`Unknown command: ${parsed.name}`);
73
+ io.err('Run "telecoder help" to see the commands.');
74
+ return 2;
75
+ }
76
+ const mod = await commands[parsed.name].load();
77
+ return mod.run(parsed.args, io);
78
+ }
79
+ //# sourceMappingURL=dispatch.js.map
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Reading, writing and backing up the .env `telecoder init` produces.
3
+ *
4
+ * A fresh file holds only what the wizard asked about, under a header pointing
5
+ * at .env.example for everything else. Editing an existing file changes the
6
+ * lines for the keys that changed and leaves every other line — comments,
7
+ * settings the wizard never asks about — exactly as it was.
8
+ *
9
+ * The file is written 0600 in a 0700 directory: it holds the bot token.
10
+ */
11
+ import * as fs from 'fs';
12
+ import * as path from 'path';
13
+ export const ENV_HEADER = [
14
+ '# TeleCoder configuration, written by `telecoder init`.',
15
+ '#',
16
+ '# Only the settings the wizard asked about are here; everything else runs on',
17
+ '# its default. Every setting, with what it does, is listed in .env.example',
18
+ '# (in the package, or https://github.com/gitaarik/telecoder/blob/main/.env.example)',
19
+ '# and in the Configuration Reference: https://telecoder.dev',
20
+ '# Run `telecoder init` again to change these, or edit this file by hand.',
21
+ ];
22
+ /** Quote a value only when dotenv would otherwise misread it. */
23
+ export function formatValue(value) {
24
+ if (value === '' || /^[A-Za-z0-9_@%+=:,./~-]+$/.test(value))
25
+ return value;
26
+ return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
27
+ }
28
+ export function renderEnv(values) {
29
+ const lines = [...ENV_HEADER, ''];
30
+ for (const [key, value] of Object.entries(values))
31
+ lines.push(`${key}=${formatValue(value)}`);
32
+ return `${lines.join('\n')}\n`;
33
+ }
34
+ /**
35
+ * Apply `updates` to the text of an existing .env: replace the first active
36
+ * `KEY=` line of each key (dropping any later duplicates, which would win),
37
+ * remove the lines of keys set to undefined, and append keys not there yet.
38
+ */
39
+ export function updateEnvText(text, updates) {
40
+ const lines = text.split('\n');
41
+ if (lines.at(-1) === '')
42
+ lines.pop();
43
+ const done = new Set();
44
+ const out = [];
45
+ for (const line of lines) {
46
+ const key = line.match(/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/)?.[1];
47
+ if (key === undefined || !Object.hasOwn(updates, key)) {
48
+ out.push(line);
49
+ continue;
50
+ }
51
+ if (done.has(key))
52
+ continue;
53
+ done.add(key);
54
+ const value = updates[key];
55
+ if (value !== undefined)
56
+ out.push(`${key}=${formatValue(value)}`);
57
+ }
58
+ const added = Object.entries(updates).filter(([key, value]) => !done.has(key) && value !== undefined);
59
+ if (added.length) {
60
+ if (out.length && out.at(-1)?.trim() !== '')
61
+ out.push('');
62
+ for (const [key, value] of added)
63
+ out.push(`${key}=${formatValue(value)}`);
64
+ }
65
+ return `${out.join('\n')}\n`;
66
+ }
67
+ /** `.env.bak-20261113-142501`: sorts by time, and says what it was. */
68
+ export function backupName(file, now = new Date()) {
69
+ const pad = (n) => String(n).padStart(2, '0');
70
+ const stamp = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-` +
71
+ `${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
72
+ return `${file}.bak-${stamp}`;
73
+ }
74
+ /** Copy `file` aside, keeping it private. Returns the backup's path. */
75
+ export function backupFile(file, now) {
76
+ const backup = backupName(file, now);
77
+ fs.copyFileSync(file, backup);
78
+ fs.chmodSync(backup, 0o600);
79
+ return backup;
80
+ }
81
+ /**
82
+ * Write the .env privately. The directory is created 0700; an existing one is
83
+ * tightened to 0700 only when it is the config home TeleCoder made (not a
84
+ * source checkout, whose directory other things live in).
85
+ */
86
+ export function writeEnvFile(file, content, { ownDir }) {
87
+ const dir = path.dirname(file);
88
+ if (!fs.existsSync(dir))
89
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
90
+ if (ownDir)
91
+ fs.chmodSync(dir, 0o700);
92
+ // Write beside it and rename, so a crash never leaves half a config — and
93
+ // create it 0600 so the token is never readable, not even for a moment.
94
+ const tmp = path.join(dir, `.env.init-${process.pid}.tmp`);
95
+ fs.writeFileSync(tmp, content, { mode: 0o600 });
96
+ fs.chmodSync(tmp, 0o600);
97
+ fs.renameSync(tmp, file);
98
+ }
99
+ //# sourceMappingURL=env-file.js.map