telecoder 0.0.0-stage → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/.env.example +375 -0
  2. package/CHANGELOG.md +1867 -0
  3. package/LICENSE +22 -0
  4. package/README.md +130 -2
  5. package/dist/audio/transcribe.js +41 -0
  6. package/dist/bin/mcp-server.js +363 -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 +573 -0
  10. package/dist/bot/command-catalog.js +263 -0
  11. package/dist/bot/deleted-threads.js +103 -0
  12. package/dist/bot/file-access.js +150 -0
  13. package/dist/bot/handlers/album.handler.js +128 -0
  14. package/dist/bot/handlers/branch.handler.js +1096 -0
  15. package/dist/bot/handlers/command/access.js +407 -0
  16. package/dist/bot/handlers/command/admin.js +803 -0
  17. package/dist/bot/handlers/command/all-view.js +33 -0
  18. package/dist/bot/handlers/command/auto-approve.js +138 -0
  19. package/dist/bot/handlers/command/background.js +37 -0
  20. package/dist/bot/handlers/command/botname.js +76 -0
  21. package/dist/bot/handlers/command/btw.js +175 -0
  22. package/dist/bot/handlers/command/cleanup.js +329 -0
  23. package/dist/bot/handlers/command/model.js +226 -0
  24. package/dist/bot/handlers/command/prefs-scope.js +362 -0
  25. package/dist/bot/handlers/command/project.js +458 -0
  26. package/dist/bot/handlers/command/resume.js +325 -0
  27. package/dist/bot/handlers/command/session.js +299 -0
  28. package/dist/bot/handlers/command/settings.js +657 -0
  29. package/dist/bot/handlers/command/shared.js +207 -0
  30. package/dist/bot/handlers/command/tasks.js +681 -0
  31. package/dist/bot/handlers/command/thread.js +128 -0
  32. package/dist/bot/handlers/command/topic-store.js +74 -0
  33. package/dist/bot/handlers/command/topic.js +27 -0
  34. package/dist/bot/handlers/command/usage.js +382 -0
  35. package/dist/bot/handlers/command-fallback.js +179 -0
  36. package/dist/bot/handlers/command.handler.js +446 -0
  37. package/dist/bot/handlers/loop.handler.js +389 -0
  38. package/dist/bot/handlers/media-fallback.js +126 -0
  39. package/dist/bot/handlers/message/replies.js +56 -0
  40. package/dist/bot/handlers/message/shared.js +95 -0
  41. package/dist/bot/handlers/message/turn-notify.js +135 -0
  42. package/dist/bot/handlers/message/turn-runner.js +56 -0
  43. package/dist/bot/handlers/message.handler.js +114 -0
  44. package/dist/bot/handlers/newbot.handler.js +230 -0
  45. package/dist/bot/handlers/photo.handler.js +286 -0
  46. package/dist/bot/handlers/prompts.handler.js +343 -0
  47. package/dist/bot/handlers/running-note.js +44 -0
  48. package/dist/bot/handlers/session-guard.js +78 -0
  49. package/dist/bot/handlers/suggestion.handler.js +84 -0
  50. package/dist/bot/handlers/tree.handler.js +480 -0
  51. package/dist/bot/handlers/view.js +41 -0
  52. package/dist/bot/handlers/voice.handler.js +147 -0
  53. package/dist/bot/kept-threads.js +51 -0
  54. package/dist/bot/middleware/admin-only.js +49 -0
  55. package/dist/bot/middleware/album-collector.js +69 -0
  56. package/dist/bot/middleware/auth.middleware.js +122 -0
  57. package/dist/bot/middleware/group-mention.middleware.js +145 -0
  58. package/dist/bot/middleware/group-role.middleware.js +75 -0
  59. package/dist/bot/middleware/message-batcher.js +87 -0
  60. package/dist/bot/middleware/queued-messages.js +1082 -0
  61. package/dist/bot/middleware/stale-filter.js +9 -0
  62. package/dist/build-info.json +8 -0
  63. package/dist/claude/ask-user-form.js +517 -0
  64. package/dist/claude/ask-user.js +363 -0
  65. package/dist/claude/auto-approve.js +225 -0
  66. package/dist/claude/auto-topic-haiku.js +143 -0
  67. package/dist/claude/available-commands.js +156 -0
  68. package/dist/claude/background-hint.js +91 -0
  69. package/dist/claude/branch-tree.js +393 -0
  70. package/dist/claude/carry-over.js +25 -0
  71. package/dist/claude/ccr-shim.js +48 -0
  72. package/dist/claude/charter-judge.js +214 -0
  73. package/dist/claude/claude-auth.js +117 -0
  74. package/dist/claude/command-parser.js +206 -0
  75. package/dist/claude/cost-overlay-scraper.js +134 -0
  76. package/dist/claude/effort-level.js +5 -0
  77. package/dist/claude/enabled-plugins.js +52 -0
  78. package/dist/claude/in-flight-tracker.js +82 -0
  79. package/dist/claude/ipc-server.js +192 -0
  80. package/dist/claude/mcp-bridge.js +481 -0
  81. package/dist/claude/memory-guard.js +400 -0
  82. package/dist/claude/message-offsets.js +88 -0
  83. package/dist/claude/modal-relay.js +817 -0
  84. package/dist/claude/model-catalog.js +102 -0
  85. package/dist/claude/monitor-relay.js +712 -0
  86. package/dist/claude/native-commands.js +40 -0
  87. package/dist/claude/pending-branches.js +93 -0
  88. package/dist/claude/pending-suggestions.js +50 -0
  89. package/dist/claude/permission-gate.js +338 -0
  90. package/dist/claude/permission-mode.js +152 -0
  91. package/dist/claude/poll-user.js +51 -0
  92. package/dist/claude/prewarm.js +70 -0
  93. package/dist/claude/project-commands.js +69 -0
  94. package/dist/claude/prompt-hold.js +124 -0
  95. package/dist/claude/prompt-suggestion-scraper.js +89 -0
  96. package/dist/claude/pty-idle-reaper.js +96 -0
  97. package/dist/claude/pty-provider.js +2499 -0
  98. package/dist/claude/pty-spawn-config.js +343 -0
  99. package/dist/claude/pty-stream.js +363 -0
  100. package/dist/claude/pty-watch.js +201 -0
  101. package/dist/claude/request-queue.js +107 -0
  102. package/dist/claude/rewind.js +111 -0
  103. package/dist/claude/scheduled-runner.js +89 -0
  104. package/dist/claude/scheduler.js +241 -0
  105. package/dist/claude/scope-guard.js +279 -0
  106. package/dist/claude/screen-marks.js +83 -0
  107. package/dist/claude/screen-render.js +96 -0
  108. package/dist/claude/secret-request.js +576 -0
  109. package/dist/claude/session-history.js +288 -0
  110. package/dist/claude/session-jsonl.js +1067 -0
  111. package/dist/claude/session-manager.js +216 -0
  112. package/dist/claude/session-move.js +70 -0
  113. package/dist/claude/session-scan.js +270 -0
  114. package/dist/claude/setup-token.js +285 -0
  115. package/dist/claude/shell-mode-gate.js +60 -0
  116. package/dist/claude/side-call-options.js +45 -0
  117. package/dist/claude/side-question.js +252 -0
  118. package/dist/claude/stage-images.js +62 -0
  119. package/dist/claude/subagent-tools.js +12 -0
  120. package/dist/claude/synthetic-ctx.js +51 -0
  121. package/dist/claude/tasks-overlay-scraper.js +217 -0
  122. package/dist/claude/thread-judge-haiku.js +88 -0
  123. package/dist/claude/tip-scraper.js +77 -0
  124. package/dist/claude/tui-modal.js +746 -0
  125. package/dist/claude/tui-state.js +456 -0
  126. package/dist/claude/turn-end.js +105 -0
  127. package/dist/claude/turn-prose.js +64 -0
  128. package/dist/claude/typed-answer.js +104 -0
  129. package/dist/claude/update-banner-relay.js +70 -0
  130. package/dist/cli/commands/doctor.js +338 -0
  131. package/dist/cli/commands/help.js +34 -0
  132. package/dist/cli/commands/init.js +126 -0
  133. package/dist/cli/commands/service.js +710 -0
  134. package/dist/cli/commands/start.js +63 -0
  135. package/dist/cli/commands/version.js +11 -0
  136. package/dist/cli/commands/watch.js +322 -0
  137. package/dist/cli/dispatch.js +84 -0
  138. package/dist/cli/init/env-file.js +99 -0
  139. package/dist/cli/init/flow.js +705 -0
  140. package/dist/cli/init/prompter.js +124 -0
  141. package/dist/cli/init/telegram.js +120 -0
  142. package/dist/cli/service/render.js +212 -0
  143. package/dist/cli.js +18 -0
  144. package/dist/config-report.js +107 -0
  145. package/dist/config.js +525 -0
  146. package/dist/index.js +443 -0
  147. package/dist/launcher.js +960 -0
  148. package/dist/node-version-check.js +27 -0
  149. package/dist/providers/ccr-health.js +119 -0
  150. package/dist/providers/ccr-introspect.js +142 -0
  151. package/dist/providers/ccr-provider.js +59 -0
  152. package/dist/providers/claude-provider.js +10 -0
  153. package/dist/providers/prefs-sync.js +121 -0
  154. package/dist/providers/project-favorites.js +74 -0
  155. package/dist/providers/provider-router.js +128 -0
  156. package/dist/providers/provider-switch.js +91 -0
  157. package/dist/providers/spawn-settings.js +45 -0
  158. package/dist/providers/types.js +8 -0
  159. package/dist/providers/user-preferences.js +322 -0
  160. package/dist/restart-when-idle.js +173 -0
  161. package/dist/startup/auto-continue.js +67 -0
  162. package/dist/startup/auto-resume.js +161 -0
  163. package/dist/startup/notices.js +120 -0
  164. package/dist/startup/shared.js +44 -0
  165. package/dist/startup/verify-token.js +31 -0
  166. package/dist/telegram/access-request.js +153 -0
  167. package/dist/telegram/action-logger.js +522 -0
  168. package/dist/telegram/admin-mention.js +107 -0
  169. package/dist/telegram/background-activity-card.js +502 -0
  170. package/dist/telegram/botname-settings.js +282 -0
  171. package/dist/telegram/button-text.js +26 -0
  172. package/dist/telegram/client-options.js +26 -0
  173. package/dist/telegram/deduplication.js +33 -0
  174. package/dist/telegram/entities.js +295 -0
  175. package/dist/telegram/force-reply-tracker.js +96 -0
  176. package/dist/telegram/lettered-options.js +87 -0
  177. package/dist/telegram/markdown.js +362 -0
  178. package/dist/telegram/message-sender.js +1019 -0
  179. package/dist/telegram/prompt-label.js +148 -0
  180. package/dist/telegram/prompt-suggestion.js +54 -0
  181. package/dist/telegram/send.js +123 -0
  182. package/dist/telegram/streaming-turn.js +103 -0
  183. package/dist/telegram/suggestions-settings.js +30 -0
  184. package/dist/telegram/table-lists.js +56 -0
  185. package/dist/telegram/task-list.js +367 -0
  186. package/dist/telegram/task-tracker.js +128 -0
  187. package/dist/telegram/terminal-renderer.js +667 -0
  188. package/dist/telegram/thread-titles.js +262 -0
  189. package/dist/telegram/threads-setup.js +117 -0
  190. package/dist/utils/admins.js +143 -0
  191. package/dist/utils/agent-timer.js +55 -0
  192. package/dist/utils/atomic-write.js +24 -0
  193. package/dist/utils/bot-icon.js +248 -0
  194. package/dist/utils/bot-token.js +77 -0
  195. package/dist/utils/bounded-map.js +55 -0
  196. package/dist/utils/build-info.js +57 -0
  197. package/dist/utils/caffeinate.js +53 -0
  198. package/dist/utils/claude-env.js +53 -0
  199. package/dist/utils/claude-version.js +48 -0
  200. package/dist/utils/config-home.js +62 -0
  201. package/dist/utils/download.js +137 -0
  202. package/dist/utils/exit-codes.js +59 -0
  203. package/dist/utils/file-type.js +149 -0
  204. package/dist/utils/format.js +78 -0
  205. package/dist/utils/home-project.js +30 -0
  206. package/dist/utils/host-stall.js +51 -0
  207. package/dist/utils/id-list.js +44 -0
  208. package/dist/utils/idle-restart.js +92 -0
  209. package/dist/utils/install-mode.js +63 -0
  210. package/dist/utils/instance-config.js +148 -0
  211. package/dist/utils/instances.js +95 -0
  212. package/dist/utils/json-store.js +140 -0
  213. package/dist/utils/keyed-settings.js +62 -0
  214. package/dist/utils/legacy-env.js +35 -0
  215. package/dist/utils/memory-pressure.js +60 -0
  216. package/dist/utils/npm-version.js +134 -0
  217. package/dist/utils/prefs-relay.js +107 -0
  218. package/dist/utils/proc-children.js +102 -0
  219. package/dist/utils/resolve-bin.js +86 -0
  220. package/dist/utils/resolve-claude-bin.js +52 -0
  221. package/dist/utils/respawn-backoff.js +28 -0
  222. package/dist/utils/sanitize.js +91 -0
  223. package/dist/utils/session-key.js +37 -0
  224. package/dist/utils/stale-launcher.js +109 -0
  225. package/dist/utils/state-dir-migration.js +92 -0
  226. package/dist/utils/systemd.js +126 -0
  227. package/dist/utils/telegram-proxy.js +72 -0
  228. package/dist/utils/uploads-dir.js +27 -0
  229. package/dist/utils/user-roster.js +275 -0
  230. package/dist/utils/verbosity.js +118 -0
  231. package/dist/utils/version-check.js +166 -0
  232. package/dist/utils/workspace-guard.js +44 -0
  233. package/dist/worker-restart.js +141 -0
  234. package/instances.json.example +41 -0
  235. package/package.json +75 -4
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Who, inside an allow-listed group, may actually drive the agent.
3
+ *
4
+ * `ALLOWED_GROUP_IDS` answers a coarser question — may the bot be used in this
5
+ * chat at all — and answers it with Telegram membership. That is the right gate
6
+ * for a group of peers, and the wrong one for a group where some people are
7
+ * there to watch: a prompt to the agent is shell access on the host, while
8
+ * reading along is harmless. This store is the finer gate layered on top.
9
+ *
10
+ * Three roles:
11
+ * - admin — `isAdmin()`: a user id in ADMIN_USER_IDS, or every allowed
12
+ * user when that is unset. Full access, in DMs and in every
13
+ * group; the only role that can hand out the others.
14
+ * Config-level, so it can't be granted or revoked from chat.
15
+ * - contributor — may address the bot in one specific group. Anyone on the
16
+ * global roster is one everywhere by definition — they can
17
+ * already DM the bot, so denying them a group would be
18
+ * theatre.
19
+ * - spectator — present in the group, ignored by the bot. Talks to the
20
+ * humans; can't send the agent a prompt.
21
+ *
22
+ * `GROUP_MEMBERS_DEFAULT` decides which of the latter two an ungranted member
23
+ * falls into, so the store only ever holds the exceptions to it: `allow` is
24
+ * what matters under a `spectator` default, `deny` under a `contributor` one,
25
+ * and either default is safe to change afterwards without rewriting the file.
26
+ *
27
+ * Deliberately *not* here: a username→id cache. The global roster
28
+ * (`utils/user-roster.ts`) already learns a handle from every message the bot
29
+ * sees, including from spectators, and `resolveUser` reads it back. One cache
30
+ * for one question.
31
+ */
32
+ import * as path from 'path';
33
+ import { z } from 'zod';
34
+ import { BOT_ID, config } from '../../config.js';
35
+ import { isAdmin } from '../../utils/admins.js';
36
+ import { isAllowedUser } from '../../utils/user-roster.js';
37
+ import { ensureStateDir, getStateDir, readJsonFile, writeJsonFile } from '../../utils/json-store.js';
38
+ const LABEL = 'GroupAccess';
39
+ const entrySchema = z.object({
40
+ /** Handle as last seen, for display only — resolution always goes by id. */
41
+ username: z.string().optional(),
42
+ grantedBy: z.number().optional(),
43
+ grantedAt: z.string().optional(),
44
+ });
45
+ const groupSchema = z.object({
46
+ allow: z.record(z.string(), entrySchema).default({}),
47
+ deny: z.record(z.string(), entrySchema).default({}),
48
+ });
49
+ const fileSchema = z.object({
50
+ groups: z.record(z.string(), groupSchema).default({}),
51
+ });
52
+ function emptyStore() {
53
+ return { groups: {} };
54
+ }
55
+ let stateDir = getStateDir();
56
+ let cache;
57
+ function filePath() {
58
+ return path.join(stateDir, `group-access-${BOT_ID}.json`);
59
+ }
60
+ function store() {
61
+ if (!cache)
62
+ cache = readJsonFile(filePath(), fileSchema, LABEL) ?? emptyStore();
63
+ return cache;
64
+ }
65
+ function save() {
66
+ ensureStateDir(stateDir, LABEL);
67
+ writeJsonFile(filePath(), store(), LABEL, { rethrow: true });
68
+ }
69
+ /** Point the store at another directory and drop the cache. Test seam. */
70
+ export function configureGroupAccessStore(dir) {
71
+ stateDir = dir ?? getStateDir();
72
+ cache = undefined;
73
+ }
74
+ function groupEntry(chatId) {
75
+ const key = String(chatId);
76
+ const existing = store().groups[key];
77
+ if (existing)
78
+ return existing;
79
+ const created = { allow: {}, deny: {} };
80
+ store().groups[key] = created;
81
+ return created;
82
+ }
83
+ /**
84
+ * The role `userId` holds in `chatId`.
85
+ *
86
+ * An explicit deny outranks an explicit allow: `/deny` has to be able to take
87
+ * back a `/allow` under either default, and the losing entry is dropped by the
88
+ * writers below, so the two maps never actually disagree about a live user.
89
+ *
90
+ * The global roster is consulted before the default, which is what makes the
91
+ * two access layers compose: admitting someone with `/allow` in a DM makes
92
+ * them a contributor in every group without a per-group grant.
93
+ */
94
+ export function resolveRole(chatId, userId) {
95
+ if (isAdmin(userId))
96
+ return 'admin';
97
+ const group = store().groups[String(chatId)];
98
+ const id = String(userId);
99
+ if (group?.deny[id])
100
+ return 'spectator';
101
+ if (group?.allow[id])
102
+ return 'contributor';
103
+ if (isAllowedUser(userId))
104
+ return 'contributor';
105
+ return config.GROUP_MEMBERS_DEFAULT === 'contributor' ? 'contributor' : 'spectator';
106
+ }
107
+ /** Promote `userId` to contributor in `chatId`. Returns their role beforehand. */
108
+ export function grantAccess(chatId, userId, meta = {}) {
109
+ const previous = resolveRole(chatId, userId);
110
+ const group = groupEntry(chatId);
111
+ const id = String(userId);
112
+ delete group.deny[id];
113
+ group.allow[id] = {
114
+ ...(meta.username ? { username: meta.username } : {}),
115
+ ...(meta.grantedBy !== undefined ? { grantedBy: meta.grantedBy } : {}),
116
+ grantedAt: new Date().toISOString(),
117
+ };
118
+ save();
119
+ return previous;
120
+ }
121
+ /** Demote `userId` to spectator in `chatId`. Returns their role beforehand. */
122
+ export function revokeAccess(chatId, userId, meta = {}) {
123
+ const previous = resolveRole(chatId, userId);
124
+ const group = groupEntry(chatId);
125
+ const id = String(userId);
126
+ delete group.allow[id];
127
+ group.deny[id] = {
128
+ ...(meta.username ? { username: meta.username } : {}),
129
+ ...(meta.grantedBy !== undefined ? { grantedBy: meta.grantedBy } : {}),
130
+ grantedAt: new Date().toISOString(),
131
+ };
132
+ save();
133
+ return previous;
134
+ }
135
+ /** The explicit grants and denials recorded for `chatId`. */
136
+ export function listGroupAccess(chatId) {
137
+ const group = store().groups[String(chatId)];
138
+ const toList = (map) => Object.entries(map ?? {})
139
+ .map(([id, entry]) => ({ userId: Number(id), ...entry }))
140
+ .sort((a, b) => a.userId - b.userId);
141
+ return { allow: toList(group?.allow), deny: toList(group?.deny) };
142
+ }
143
+ /** Whether an ungranted member of an allow-listed group may prompt the agent. */
144
+ export function groupDefaultIsContributor() {
145
+ return config.GROUP_MEMBERS_DEFAULT === 'contributor';
146
+ }
147
+ //# sourceMappingURL=group-access.js.map