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,200 @@
|
|
|
1
|
+
import { config } from '../config.js';
|
|
2
|
+
import { hasGuestUsers } from '../utils/admins.js';
|
|
3
|
+
import { isCheckout } from '../utils/install-mode.js';
|
|
4
|
+
import { EntityText } from '../telegram/entities.js';
|
|
5
|
+
const CLAUDE_COMMANDS = ['plan', 'explore', 'model', 'commands', 'loop', 'resume', 'continue', 'sessions', 'provider'];
|
|
6
|
+
export function parseClaudeCommand(message) {
|
|
7
|
+
const trimmed = message.trim();
|
|
8
|
+
// Check if message starts with a slash command
|
|
9
|
+
if (!trimmed.startsWith('/')) {
|
|
10
|
+
return { command: null, args: trimmed, model: null };
|
|
11
|
+
}
|
|
12
|
+
const firstSpace = trimmed.indexOf(' ');
|
|
13
|
+
const commandPart = firstSpace === -1 ? trimmed.slice(1) : trimmed.slice(1, firstSpace);
|
|
14
|
+
const args = firstSpace === -1 ? '' : trimmed.slice(firstSpace + 1).trim();
|
|
15
|
+
// Check if it's a Claude command
|
|
16
|
+
if (CLAUDE_COMMANDS.includes(commandPart)) {
|
|
17
|
+
return { command: commandPart, args, model: null };
|
|
18
|
+
}
|
|
19
|
+
// Not a recognized Claude command - return as regular message
|
|
20
|
+
return { command: null, args: trimmed, model: null };
|
|
21
|
+
}
|
|
22
|
+
export function isClaudeCommand(message) {
|
|
23
|
+
const trimmed = message.trim();
|
|
24
|
+
if (!trimmed.startsWith('/'))
|
|
25
|
+
return false;
|
|
26
|
+
const firstSpace = trimmed.indexOf(' ');
|
|
27
|
+
const commandPart = firstSpace === -1 ? trimmed.slice(1) : trimmed.slice(1, firstSpace);
|
|
28
|
+
return CLAUDE_COMMANDS.includes(commandPart);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Telegram appends `@BotName` to slash commands sent in group chats
|
|
32
|
+
* (`/compact@MyBot`, `/compact@MyBot keep the plan`). Strip the mention off the
|
|
33
|
+
* leading command token so downstream command detection — and the PTY TUI,
|
|
34
|
+
* which would otherwise type `/compact@MyBot` verbatim — see a clean `/compact`.
|
|
35
|
+
* Only touches a genuine `/word@word` command token; leaves ordinary messages
|
|
36
|
+
* (and slash-prefixed paths like `/some/path@host`) untouched.
|
|
37
|
+
*/
|
|
38
|
+
export function stripCommandBotMention(text) {
|
|
39
|
+
const m = text.match(/^\/(\w+)@\w+(\s[\s\S]*)?$/);
|
|
40
|
+
return m ? '/' + m[1] + (m[2] ?? '') : text;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* True if `text` is the native Claude Code `/compact` slash command (optionally
|
|
44
|
+
* with a `@BotName` mention or trailing custom-instructions argument). Single
|
|
45
|
+
* source of truth shared by the SDK interceptor (agent.ts) and the PTY provider
|
|
46
|
+
* so both agree on what counts as a manual compaction request.
|
|
47
|
+
*/
|
|
48
|
+
export function isNativeCompactCommand(text) {
|
|
49
|
+
return /^\/compact(?:@\w+)?(?:\s|$)/.test(text.trim());
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The /commands list. Each line is written with `backticks` around what shows
|
|
53
|
+
* as code; section titles go out bold.
|
|
54
|
+
*/
|
|
55
|
+
export function getAvailableCommands() {
|
|
56
|
+
// Only worth saying on a bot that actually has guests — on a solo bot every
|
|
57
|
+
// user is an admin, so the tag would mark every line without narrowing
|
|
58
|
+
// anything.
|
|
59
|
+
const adminTag = hasGuestUsers() ? ' (admin)' : '';
|
|
60
|
+
// Opening an auto-approve window sits with the people who answer prompts,
|
|
61
|
+
// which is a wider set than the people who own the bot.
|
|
62
|
+
const approverTag = hasGuestUsers() ? ' (admin / approver)' : '';
|
|
63
|
+
const sections = [
|
|
64
|
+
{
|
|
65
|
+
title: 'Claude Commands',
|
|
66
|
+
commands: [
|
|
67
|
+
'• `/plan <task>` - Enter plan mode for complex tasks',
|
|
68
|
+
'• `/explore <question>` - Use explore agent for codebase questions',
|
|
69
|
+
'• `/loop <task>` - Run iteratively until task complete',
|
|
70
|
+
'• `/model [name]` - Show or set AI model',
|
|
71
|
+
"• `/later [text]` - Set an idea aside, and be asked about it after Claude's turn",
|
|
72
|
+
'• `/steer <text>` - Stop the running turn and send this in its place',
|
|
73
|
+
...(config.CCR_ENABLED ? [`• \`/provider\` - Switch AI provider (Claude / CCR)${adminTag}`] : []),
|
|
74
|
+
'• `/commands` - Show this list',
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
title: 'Session Commands',
|
|
79
|
+
commands: [
|
|
80
|
+
'• `/project <path>` - Set working directory',
|
|
81
|
+
'• `/newproject <name>` - Create a new project',
|
|
82
|
+
'• `/newbot [project]` - Create a bot for a project, named after it and starting in it',
|
|
83
|
+
'• `/resume` - Pick from recent sessions to resume',
|
|
84
|
+
'• `/continue` - Resume most recent session',
|
|
85
|
+
'• `/sessions` - List all sessions',
|
|
86
|
+
'• `/teleport` - Move session to terminal (forked)',
|
|
87
|
+
'• `/clear` - Clear session and start fresh',
|
|
88
|
+
'• `/status` - Show current session info',
|
|
89
|
+
'• `/fork` - Fork current conversation to another bot',
|
|
90
|
+
'• `/spinoff <task>` - Split a task off into a new thread, compacted around it (as a reply: from that message)',
|
|
91
|
+
'• `/tree` - Show where this conversation branched, and jump between branches',
|
|
92
|
+
'• `/accept` - Accept a pending fork from another bot',
|
|
93
|
+
'• `/decline` - Discard a pending fork',
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
title: 'File Commands',
|
|
98
|
+
commands: [
|
|
99
|
+
'• `/file <path>` - Download a file from project',
|
|
100
|
+
'• `/telegraph <path>` - View markdown with Instant View',
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
const mediaCommands = [];
|
|
105
|
+
if (config.TRANSCRIBE_ENABLED) {
|
|
106
|
+
mediaCommands.push('• `/transcribe` - Transcribe audio to text (reply to voice/audio, or ForceReply)');
|
|
107
|
+
}
|
|
108
|
+
if (mediaCommands.length > 0) {
|
|
109
|
+
sections.push({ title: 'Media Commands', commands: mediaCommands });
|
|
110
|
+
}
|
|
111
|
+
sections.push({
|
|
112
|
+
title: 'Bot Commands',
|
|
113
|
+
commands: [
|
|
114
|
+
'• `/tts` - Toggle voice replies',
|
|
115
|
+
'• `/context` - Show Claude context usage',
|
|
116
|
+
'• `/cost` - Show usage limits and cost from Claude Code',
|
|
117
|
+
'• `/compact` - Compact the context window (reports the token reduction)',
|
|
118
|
+
'• `/botstatus` - Show bot process status',
|
|
119
|
+
'• `/version` - Show the running version and whether it\'s the latest',
|
|
120
|
+
`• \`/restartbot\` - Restart the bot process${adminTag}`,
|
|
121
|
+
...(isCheckout()
|
|
122
|
+
? [`• \`/rebuildbot\` - Rebuild and restart with auto-resume; \`/rebuildbot idle\` waits for each bot to finish first${adminTag}`]
|
|
123
|
+
: []),
|
|
124
|
+
'• `/ping` - Check if bot is responsive',
|
|
125
|
+
'• `/cancel` - Stop the current request and drop anything queued',
|
|
126
|
+
'• `/mode` - How much Claude asks before acting',
|
|
127
|
+
`• \`/autoapprove [30m|off|status]\` - Let the gate approve instead of asking, for a while${approverTag}`,
|
|
128
|
+
'• `/streaming` - Toggle streaming / wait replies',
|
|
129
|
+
'• `/verbosity` - Pick verbosity tier (quiet / normal / verbose / debug)',
|
|
130
|
+
'• `/terminalui` - Toggle terminal-style display',
|
|
131
|
+
'• `/botname` - Toggle dynamic bot name',
|
|
132
|
+
'• `/topic <text>` - Set current work topic in bot name',
|
|
133
|
+
],
|
|
134
|
+
});
|
|
135
|
+
sections.push({
|
|
136
|
+
title: 'Claude Code Commands',
|
|
137
|
+
commands: [
|
|
138
|
+
'Claude Code\'s own slash commands pass straight through — `/code-review`,',
|
|
139
|
+
'`/security-review`, `/simplify`, `/init`, `/run` and any `.claude/commands/`',
|
|
140
|
+
'command all work by typing them here.',
|
|
141
|
+
'',
|
|
142
|
+
'⚠️ Where a bot command shares the name, the bot wins — `/loop` and',
|
|
143
|
+
'`/schedule` are TeleCoder\'s, not Claude Code\'s. The overlap shifts with',
|
|
144
|
+
'each Claude Code release, so `/projectcommands` reports the current one.',
|
|
145
|
+
'',
|
|
146
|
+
'• `/projectcommands` - List everything this project offers, shadowing included',
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
sections.push({
|
|
150
|
+
title: 'Group Access',
|
|
151
|
+
commands: [
|
|
152
|
+
'• `/members` - Show who may prompt the agent in this group',
|
|
153
|
+
'• `/allow` - Let someone prompt the agent here (reply to them, or pass @handle / id)',
|
|
154
|
+
'• `/deny` - Make someone a spectator here (admin only)',
|
|
155
|
+
],
|
|
156
|
+
});
|
|
157
|
+
const b = new EntityText();
|
|
158
|
+
sections.forEach((section, i) => {
|
|
159
|
+
if (i > 0)
|
|
160
|
+
b.newline(2);
|
|
161
|
+
b.bold(`${section.title}:`).newline(2);
|
|
162
|
+
section.commands.forEach((line, j) => {
|
|
163
|
+
if (j > 0)
|
|
164
|
+
b.newline();
|
|
165
|
+
// Odd segments between backticks are code.
|
|
166
|
+
line.split('`').forEach((segment, k) => (k % 2 === 1 ? b.code(segment) : b.add(segment)));
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
return b.build();
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Command names TeleCoder registers with grammY that do NOT reach Claude Code,
|
|
173
|
+
* recorded as they register (see the `cmd()` wrapper in `bot.ts`).
|
|
174
|
+
*
|
|
175
|
+
* A bot command wins over the native Claude Code command of the same name:
|
|
176
|
+
* grammY matches it first and the text never reaches the agent. `/loop` and
|
|
177
|
+
* `/schedule` are TeleCoder's own features rather than Claude Code's skills of
|
|
178
|
+
* those names, and `/model` answers about the bot's state rather than the
|
|
179
|
+
* CLI's. Keeping the list live rather than hand-maintained means
|
|
180
|
+
* `/projectcommands` names the shadowed commands accurately — the overlap
|
|
181
|
+
* shifts with every Claude Code release.
|
|
182
|
+
*
|
|
183
|
+
* `forwardsToAgent` marks the exception: a name registered only so grammY
|
|
184
|
+
* routes it (and its group-chat `@BotName` form) into the normal message
|
|
185
|
+
* pipeline, which hands it to Claude Code unchanged. `/compact` is one. Those
|
|
186
|
+
* are not shadowed and must not be reported as such.
|
|
187
|
+
*/
|
|
188
|
+
const registeredBotCommands = new Set();
|
|
189
|
+
export function registerBotCommandName(name, forwardsToAgent = false) {
|
|
190
|
+
if (forwardsToAgent) {
|
|
191
|
+
registeredBotCommands.delete(name);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
registeredBotCommands.add(name);
|
|
195
|
+
}
|
|
196
|
+
/** Names that shadow a same-named Claude Code command. */
|
|
197
|
+
export function getBotCommandNames() {
|
|
198
|
+
return registeredBotCommands;
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=command-parser.js.map
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scrape the Session totals out of Claude Code's `/cost` overlay.
|
|
3
|
+
*
|
|
4
|
+
* `/cost` in the TUI is not a transcript message — it opens the settings panel
|
|
5
|
+
* on its Usage tab, behind the same full-width `▔` rule the `/tasks` overlay
|
|
6
|
+
* uses:
|
|
7
|
+
*
|
|
8
|
+
* ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
|
|
9
|
+
* Settings Status Config Usage Stats
|
|
10
|
+
*
|
|
11
|
+
* Session
|
|
12
|
+
*
|
|
13
|
+
* Total cost: $0.0246
|
|
14
|
+
* Total duration (API): 3s
|
|
15
|
+
* Total duration (wall): 8s
|
|
16
|
+
* Total code changes: 0 lines added, 0 lines removed
|
|
17
|
+
* Usage by model:
|
|
18
|
+
* claude-haiku-4-5: 1.8k input, 63 output, 26.3k cache read …
|
|
19
|
+
* Prompt cache (main): 1 request · 73% of input tokens from cache …
|
|
20
|
+
*
|
|
21
|
+
* Current session
|
|
22
|
+
* █████████ 18% used
|
|
23
|
+
* …
|
|
24
|
+
*
|
|
25
|
+
* Only the Session block is taken. Everything below it is the account-wide
|
|
26
|
+
* limits view, which `claude -p /cost` prints too — more compactly, and from
|
|
27
|
+
* any mode — so /cost reads that from the probe and comes here only for the
|
|
28
|
+
* part a probe can never have: the totals belong to the process that spent
|
|
29
|
+
* them, and a freshly spawned one has spent nothing.
|
|
30
|
+
*
|
|
31
|
+
* The panel scrolls, so only its first screenful is rendered. That is where
|
|
32
|
+
* the Session block lives, which is why this scrapes it and leaves the rest.
|
|
33
|
+
*/
|
|
34
|
+
/** The overlay's top rule. Full-width in practice; 10 is a safe floor. */
|
|
35
|
+
const OVERLAY_RULE_RE = /^▔{10,}$/;
|
|
36
|
+
/** The block's heading, on its own line. */
|
|
37
|
+
const SESSION_HEADING_RE = /^Session$/;
|
|
38
|
+
/**
|
|
39
|
+
* `Total cost: $0.0246`, and the per-model rows, which have the same shape.
|
|
40
|
+
* The label is deliberately narrow — letters, digits and the few punctuation
|
|
41
|
+
* marks real labels use — so that a wrapped continuation line ("35m, next turn
|
|
42
|
+
* re-caches ~426.3k tokens") can't be mistaken for the start of a new field.
|
|
43
|
+
*/
|
|
44
|
+
const FIELD_RE = /^([A-Za-z][\w .()/-]*?):\s*(.*)$/;
|
|
45
|
+
/**
|
|
46
|
+
* Where the Session block ends and the account-wide limits view begins. The
|
|
47
|
+
* panel always renders one of these next, so this doubles as the block's
|
|
48
|
+
* terminator when the screen is tall enough to show more.
|
|
49
|
+
*/
|
|
50
|
+
const BLOCK_END_RE = /^(?:Current session|Current week|What's contributing)/i;
|
|
51
|
+
/**
|
|
52
|
+
* How far below the rule the `Session` heading may sit. The real layout puts
|
|
53
|
+
* it on the fourth line (rule, tab bar, blank, heading); the allowance is for
|
|
54
|
+
* a release that adds a line, not for finding the word somewhere in
|
|
55
|
+
* scrollback. Without a ceiling, a stale overlay left in the buffer could pass
|
|
56
|
+
* off last hour's numbers as this moment's.
|
|
57
|
+
*/
|
|
58
|
+
const HEADING_SEARCH_LINES = 8;
|
|
59
|
+
/** Leading spaces on a line; 0 for a blank one. */
|
|
60
|
+
function indentOf(line) {
|
|
61
|
+
return line.trim() === '' ? 0 : line.length - line.trimStart().length;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The Session block of the `/cost` overlay, or null when the screen doesn't
|
|
65
|
+
* hold one — no overlay, a different tab, or a layout we no longer recognise.
|
|
66
|
+
* Callers show the limits view alone rather than guessing at the numbers.
|
|
67
|
+
*/
|
|
68
|
+
export function scrapeCostSession(screenText) {
|
|
69
|
+
const lines = screenText.split('\n');
|
|
70
|
+
// Bottom-up: the panel is pinned to the bottom of the screen, and an earlier
|
|
71
|
+
// rule can survive in scrollback from a previous overlay.
|
|
72
|
+
let ruleIndex = -1;
|
|
73
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
74
|
+
if (OVERLAY_RULE_RE.test(lines[i].trim())) {
|
|
75
|
+
ruleIndex = i;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (ruleIndex === -1)
|
|
80
|
+
return null;
|
|
81
|
+
const limit = Math.min(lines.length, ruleIndex + 1 + HEADING_SEARCH_LINES);
|
|
82
|
+
let headingIndex = -1;
|
|
83
|
+
for (let i = ruleIndex + 1; i < limit; i++) {
|
|
84
|
+
if (SESSION_HEADING_RE.test(lines[i].trim())) {
|
|
85
|
+
headingIndex = i;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (headingIndex === -1)
|
|
90
|
+
return null;
|
|
91
|
+
const body = [];
|
|
92
|
+
for (let i = headingIndex + 1; i < lines.length; i++) {
|
|
93
|
+
if (BLOCK_END_RE.test(lines[i].trim()))
|
|
94
|
+
break;
|
|
95
|
+
body.push(lines[i]);
|
|
96
|
+
}
|
|
97
|
+
// The heading sets the block's baseline indent; the per-model rows sit four
|
|
98
|
+
// columns further in. Two is the smallest gap that can't be indent jitter.
|
|
99
|
+
const baseline = indentOf(lines[headingIndex]);
|
|
100
|
+
const nestedFrom = baseline + 2;
|
|
101
|
+
const rows = [];
|
|
102
|
+
for (const line of body) {
|
|
103
|
+
const text = line.trim();
|
|
104
|
+
if (!text)
|
|
105
|
+
continue;
|
|
106
|
+
const field = text.match(FIELD_RE);
|
|
107
|
+
if (field) {
|
|
108
|
+
rows.push({
|
|
109
|
+
label: field[1],
|
|
110
|
+
value: field[2].trim(),
|
|
111
|
+
nested: indentOf(line) >= nestedFrom,
|
|
112
|
+
});
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
// No label, so this is the tail of a value the panel wrapped. Rejoin it —
|
|
116
|
+
// the prompt-cache line is long enough to wrap on most terminals, and
|
|
117
|
+
// dropping the remainder would truncate it mid-sentence.
|
|
118
|
+
const previous = rows[rows.length - 1];
|
|
119
|
+
if (previous)
|
|
120
|
+
previous.value = `${previous.value} ${text}`.trim();
|
|
121
|
+
}
|
|
122
|
+
// A panel showing no dollar or duration total isn't the Usage tab, whatever
|
|
123
|
+
// else matched. Better to fall back to the limits view than to relay rows
|
|
124
|
+
// scraped out of something else.
|
|
125
|
+
if (!rows.some((row) => /^Total /.test(row.label)))
|
|
126
|
+
return null;
|
|
127
|
+
return { rows };
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=cost-overlay-scraper.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which marketplace plugins the agent loads.
|
|
3
|
+
*
|
|
4
|
+
* Claude Code keeps plugin enablement in settings.json under `enabledPlugins`,
|
|
5
|
+
* and both transports deliberately decline to read the user's copy of that
|
|
6
|
+
* file. The pty spawns with `--setting-sources project,local` so that
|
|
7
|
+
* `editorMode: "vim"` cannot turn Enter into a newline and swallow every prompt
|
|
8
|
+
* (see pty-provider.ts); the SDK defaults to `settingSources: ['project']` so
|
|
9
|
+
* that a machine's worth of MCP servers cannot inflate the tool count into
|
|
10
|
+
* deferral. Both are worth keeping — but `enabledPlugins` lives in the file
|
|
11
|
+
* they skip, so a plugin enabled in the terminal is simply absent in Telegram,
|
|
12
|
+
* and absent silently: a missing skill looks like a model that ignored it.
|
|
13
|
+
*
|
|
14
|
+
* CLAUDE_PLUGINS names the few worth bringing across. It goes in at the *flag*
|
|
15
|
+
* tier — `--settings` for the pty, `settings:` for the SDK — which sits above
|
|
16
|
+
* project and local in Claude Code's precedence order and merges with them
|
|
17
|
+
* key-by-key, so a project that enables its own plugins keeps them and picks
|
|
18
|
+
* these up as well. Nothing else from ~/.claude/settings.json comes with it,
|
|
19
|
+
* except the answer to the bypass warning, which the pty carries for itself (see
|
|
20
|
+
* buildSettingsJson).
|
|
21
|
+
*/
|
|
22
|
+
import { config } from '../config.js';
|
|
23
|
+
/**
|
|
24
|
+
* `plugin@marketplace`, the id `claude plugin list` prints. The bare plugin
|
|
25
|
+
* name is the natural guess and never matches anything — Claude Code looks the
|
|
26
|
+
* entry up by the full id and finds nothing, which is indistinguishable from
|
|
27
|
+
* the plugin not being installed. Rejecting it here at least says so.
|
|
28
|
+
*/
|
|
29
|
+
const PLUGIN_ID = /^[^@\s]+@[^@\s]+$/;
|
|
30
|
+
/** Bad ids already reported, so a respawn loop doesn't repeat itself. */
|
|
31
|
+
const warned = new Set();
|
|
32
|
+
/**
|
|
33
|
+
* The `enabledPlugins` settings fragment for this install, or undefined when
|
|
34
|
+
* nothing is configured — callers spread it conditionally so the key stays out
|
|
35
|
+
* of the settings payload entirely rather than appearing as `{}`.
|
|
36
|
+
*/
|
|
37
|
+
export function enabledPluginsSetting() {
|
|
38
|
+
const enabled = {};
|
|
39
|
+
for (const id of config.CLAUDE_PLUGINS) {
|
|
40
|
+
if (!PLUGIN_ID.test(id)) {
|
|
41
|
+
if (!warned.has(id)) {
|
|
42
|
+
warned.add(id);
|
|
43
|
+
console.warn(`[plugins] ignoring CLAUDE_PLUGINS entry "${id}": expected plugin@marketplace, ` +
|
|
44
|
+
'e.g. frontend-design@claude-plugins-official. Run `claude plugin list` for the ids.');
|
|
45
|
+
}
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
enabled[id] = true;
|
|
49
|
+
}
|
|
50
|
+
return Object.keys(enabled).length > 0 ? enabled : undefined;
|
|
51
|
+
}
|
|
52
|
+
/** Reset the warn-once state. Test seam — production never needs this. */
|
|
53
|
+
export function resetPluginWarnings() {
|
|
54
|
+
warned.clear();
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=enabled-plugins.js.map
|