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,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
|