@fonz/tgcc 0.5.5 → 0.5.6
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/README.md +85 -214
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,84 +1,109 @@
|
|
|
1
1
|
# @fonz/tgcc
|
|
2
2
|
|
|
3
|
-
**Telegram ↔ Claude Code bridge** — run Claude Code sessions from Telegram with full streaming,
|
|
3
|
+
**Telegram ↔ Claude Code bridge** — run Claude Code sessions from Telegram with full streaming, session management, and multi-agent support.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quick Start
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @anthropic-ai/claude-code
|
|
9
|
+
claude login
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- **Sub-agent threading** — sub-agent tool calls appear as threaded replies to the main message
|
|
15
|
-
- **Staleness detection** — detects when a session was modified externally (e.g. from VS Code) and reconnects
|
|
16
|
-
- **Usage stats** — per-turn token counts and cost shown as a subtle footer
|
|
17
|
-
- **CLI tool** — send messages from your terminal, manage agents and repos
|
|
18
|
-
- **HTML formatting** — code blocks with syntax highlighting, bold, italic, links
|
|
11
|
+
npm install -g @fonz/tgcc
|
|
12
|
+
tgcc init # walks you through setup
|
|
13
|
+
tgcc run # test in foreground
|
|
14
|
+
tgcc install # install as a user service
|
|
15
|
+
```
|
|
19
16
|
|
|
20
|
-
##
|
|
17
|
+
## What it does
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
User ──► Telegram ──► TGCC ──► Claude Code CLI (stream-json)
|
|
24
|
-
│
|
|
25
|
-
config.json (agents, repos, permissions)
|
|
26
|
-
state.json (sessions, models, per-user overrides)
|
|
27
|
-
```
|
|
19
|
+
TGCC bridges the [Claude Code CLI](https://docs.anthropic.com/en/docs/claude-code) to Telegram. Each Telegram bot becomes a full Claude Code client.
|
|
28
20
|
|
|
29
|
-
|
|
21
|
+
- **Streaming** — responses stream into a single message that updates in place
|
|
22
|
+
- **Sessions** — resume, switch, and list sessions. Roam between Telegram and the CC CLI on the same session
|
|
23
|
+
- **Multi-agent** — one bot per project, each with its own config and permissions
|
|
24
|
+
- **Permission relay** — CC permission prompts appear as inline buttons
|
|
25
|
+
- **MCP tools** — CC can send files, images, and voice back via built-in MCP server
|
|
26
|
+
- **Markdown → Telegram HTML** — code blocks, bold, italic, links, tables, all rendered properly
|
|
27
|
+
- **Usage stats** — per-turn token counts and cost
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
- **Config-driven** — everything in `~/.tgcc/config.json`, hot-reloaded on changes
|
|
33
|
-
- **Unix sockets** — CLI communicates with the running service via per-agent sockets in `/tmp/tgcc/ctl/`
|
|
34
|
-
- **MCP bridge** — CC can send files, images, and voice back to the user via a built-in MCP server
|
|
35
|
-
- **State-aware hang detection** — distinguishes between API waits, tool execution (checks child processes), and real hangs
|
|
29
|
+
## Service Management
|
|
36
30
|
|
|
37
|
-
|
|
31
|
+
```bash
|
|
32
|
+
tgcc install # Install & start as a user service (systemd/launchd)
|
|
33
|
+
tgcc start # Start the service
|
|
34
|
+
tgcc stop # Stop the service
|
|
35
|
+
tgcc restart # Restart the service
|
|
36
|
+
tgcc uninstall # Remove the service
|
|
37
|
+
tgcc logs # Tail service logs
|
|
38
|
+
tgcc run # Run in the foreground (no service)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## CLI Commands
|
|
38
42
|
|
|
39
43
|
```bash
|
|
40
|
-
#
|
|
41
|
-
|
|
44
|
+
# Setup
|
|
45
|
+
tgcc init # Interactive setup
|
|
42
46
|
|
|
43
|
-
#
|
|
47
|
+
# Agents
|
|
48
|
+
tgcc agent add mybot --bot-token <token>
|
|
49
|
+
tgcc agent remove mybot
|
|
50
|
+
tgcc agent rename mybot newname
|
|
51
|
+
tgcc agent list
|
|
44
52
|
|
|
45
|
-
#
|
|
46
|
-
tgcc
|
|
53
|
+
# Repos
|
|
54
|
+
tgcc repo add . # Add current directory
|
|
55
|
+
tgcc repo add . --name=myrepo # Add with explicit name
|
|
56
|
+
tgcc repo add ~/code/backend # Add a path
|
|
57
|
+
tgcc repo remove --name=myrepo
|
|
58
|
+
tgcc repo assign --agent=mybot --name=myrepo
|
|
59
|
+
tgcc repo clear --agent=mybot
|
|
60
|
+
tgcc repo list
|
|
47
61
|
|
|
48
|
-
#
|
|
49
|
-
tgcc
|
|
62
|
+
# Messaging (while service is running)
|
|
63
|
+
tgcc message "fix the login bug"
|
|
64
|
+
tgcc message "deploy" --agent=mybot --session=abc123
|
|
65
|
+
tgcc status
|
|
66
|
+
tgcc status --agent=mybot
|
|
50
67
|
|
|
51
|
-
#
|
|
68
|
+
# Permissions
|
|
69
|
+
tgcc permissions set mybot dangerously-skip
|
|
52
70
|
```
|
|
53
71
|
|
|
72
|
+
## Telegram Commands
|
|
73
|
+
|
|
74
|
+
| Command | Description |
|
|
75
|
+
|---------|-------------|
|
|
76
|
+
| `/start` | Welcome message |
|
|
77
|
+
| `/new` | Start a fresh session |
|
|
78
|
+
| `/sessions` | List recent sessions with resume buttons |
|
|
79
|
+
| `/resume <id>` | Resume a session by ID |
|
|
80
|
+
| `/repo` | Switch repo with inline buttons |
|
|
81
|
+
| `/model <name>` | Switch model |
|
|
82
|
+
| `/permissions` | Set permission mode |
|
|
83
|
+
| `/status` | Process state, model, repo, cost |
|
|
84
|
+
| `/cancel` | Abort current CC turn |
|
|
85
|
+
| `/catchup` | Summarize external CC activity |
|
|
86
|
+
|
|
54
87
|
## Configuration
|
|
55
88
|
|
|
56
|
-
Config lives at `~/.tgcc/config.json
|
|
89
|
+
Config lives at `~/.tgcc/config.json` (created by `tgcc init`).
|
|
57
90
|
|
|
58
91
|
```jsonc
|
|
59
92
|
{
|
|
60
93
|
"global": {
|
|
61
|
-
"ccBinaryPath": "claude",
|
|
62
|
-
"logLevel": "info"
|
|
63
|
-
"mediaDir": "~/.tgcc/media",
|
|
64
|
-
"socketDir": "/tmp/tgcc",
|
|
65
|
-
"stateFile": "~/.tgcc/state.json"
|
|
94
|
+
"ccBinaryPath": "claude",
|
|
95
|
+
"logLevel": "info"
|
|
66
96
|
},
|
|
67
97
|
"repos": {
|
|
68
|
-
"myproject": "/home/user/myproject"
|
|
69
|
-
"backend": "/home/user/backend"
|
|
98
|
+
"myproject": "/home/user/myproject"
|
|
70
99
|
},
|
|
71
100
|
"agents": {
|
|
72
101
|
"mybot": {
|
|
73
102
|
"botToken": "123456:ABC-DEF...",
|
|
74
|
-
"allowedUsers": [
|
|
103
|
+
"allowedUsers": [],
|
|
75
104
|
"defaults": {
|
|
76
|
-
"model": "claude-sonnet-4-20250514",
|
|
77
105
|
"repo": "myproject",
|
|
78
|
-
"permissionMode": "
|
|
79
|
-
"maxTurns": 30,
|
|
80
|
-
"idleTimeoutMs": 600000,
|
|
81
|
-
"hangTimeoutMs": 300000
|
|
106
|
+
"permissionMode": "bypassPermissions"
|
|
82
107
|
}
|
|
83
108
|
}
|
|
84
109
|
}
|
|
@@ -89,177 +114,23 @@ Config lives at `~/.tgcc/config.json`. TGCC creates it automatically when you ru
|
|
|
89
114
|
|
|
90
115
|
| Mode | Description |
|
|
91
116
|
|------|-------------|
|
|
92
|
-
| `
|
|
93
|
-
| `acceptEdits` | Auto-accept
|
|
94
|
-
| `default` |
|
|
95
|
-
| `plan` | Plan-only
|
|
96
|
-
|
|
97
|
-
### Repo Registry
|
|
98
|
-
|
|
99
|
-
Repos are named shortcuts for project paths. Register them once, use everywhere:
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
tgcc repo add myproject ~/code/myproject
|
|
103
|
-
tgcc repo add backend ~/code/backend
|
|
104
|
-
tgcc repo assign mybot myproject # Set as agent's default
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
In Telegram, `/repo` shows an inline keyboard to switch repos on the fly.
|
|
108
|
-
|
|
109
|
-
## Telegram Commands
|
|
110
|
-
|
|
111
|
-
| Command | Description |
|
|
112
|
-
|---------|-------------|
|
|
113
|
-
| `/start` | Welcome message, register bot commands |
|
|
114
|
-
| `/help` | List all commands |
|
|
115
|
-
| `/new` | Start a fresh session |
|
|
116
|
-
| `/sessions` | List recent sessions with Resume/Delete buttons |
|
|
117
|
-
| `/resume <id>` | Resume a session by ID |
|
|
118
|
-
| `/session` | Current session info |
|
|
119
|
-
| `/status` | Process state, model, repo, uptime, cost |
|
|
120
|
-
| `/cost` | Show session cost |
|
|
121
|
-
| `/model <name>` | Switch model (takes effect on next spawn) |
|
|
122
|
-
| `/permissions` | Set permission mode with inline buttons |
|
|
123
|
-
| `/repo` | Switch repo with inline buttons |
|
|
124
|
-
| `/cancel` | Abort current CC turn (sends SIGINT) |
|
|
125
|
-
| `/catchup` | Summarize external CC activity on the same repo |
|
|
126
|
-
| `/ping` | Liveness check |
|
|
127
|
-
|
|
128
|
-
### Examples
|
|
117
|
+
| `dangerouslySkipPermissions` | Skip all prompts |
|
|
118
|
+
| `acceptEdits` | Auto-accept edits, prompt for commands |
|
|
119
|
+
| `default` | Full permission flow via inline buttons |
|
|
120
|
+
| `plan` | Plan-only, no tool execution |
|
|
129
121
|
|
|
130
|
-
|
|
131
|
-
> You: Fix the auth middleware to handle expired tokens
|
|
132
|
-
|
|
133
|
-
> Bot:
|
|
134
|
-
> <blockquote expandable>💭 Thinking<br>Looking at the auth middleware...</blockquote>
|
|
135
|
-
>
|
|
136
|
-
> I've updated `src/middleware/auth.ts` to handle expired tokens gracefully...
|
|
137
|
-
>
|
|
138
|
-
> *↩️ 1.2k in · 450 out · $0.0034*
|
|
139
|
-
|
|
140
|
-
**Permission prompt (when not using bypass mode):**
|
|
141
|
-
> 🔐 CC wants to use `Write`
|
|
142
|
-
> ```{"file_path": "src/auth.ts", ...}```
|
|
143
|
-
>
|
|
144
|
-
> `[✅ Allow]` `[❌ Deny]` `[✅ Allow All]`
|
|
145
|
-
|
|
146
|
-
**Switch repos:**
|
|
147
|
-
> `/repo`
|
|
148
|
-
>
|
|
149
|
-
> Current repo: `~/myproject`
|
|
150
|
-
>
|
|
151
|
-
> `[myproject]`
|
|
152
|
-
> `[backend]`
|
|
153
|
-
> `[➕ Add]` `[❓ Help]`
|
|
154
|
-
|
|
155
|
-
## CLI Commands
|
|
156
|
-
|
|
157
|
-
The `tgcc` CLI communicates with the running service via Unix sockets.
|
|
158
|
-
|
|
159
|
-
```bash
|
|
160
|
-
# Start the service (foreground)
|
|
161
|
-
tgcc
|
|
162
|
-
|
|
163
|
-
# Send a message to a running agent
|
|
164
|
-
tgcc message "fix the login bug" --agent mybot
|
|
165
|
-
tgcc msg "deploy to staging" --agent mybot --session abc123
|
|
166
|
-
|
|
167
|
-
# Check status
|
|
168
|
-
tgcc status
|
|
169
|
-
tgcc status --agent mybot
|
|
170
|
-
|
|
171
|
-
# Agent management
|
|
172
|
-
tgcc agent add mybot --bot-token <token> --repo ~/project
|
|
173
|
-
tgcc agent remove mybot
|
|
174
|
-
tgcc agent rename mybot newname
|
|
175
|
-
tgcc agent list
|
|
176
|
-
tgcc agent repo mybot backend # Set default repo
|
|
177
|
-
|
|
178
|
-
# Repo management
|
|
179
|
-
tgcc repo add myproject ~/code/myproject
|
|
180
|
-
tgcc repo remove myproject
|
|
181
|
-
tgcc repo assign mybot myproject
|
|
182
|
-
tgcc repo clear mybot
|
|
183
|
-
tgcc repo list
|
|
122
|
+
## Architecture
|
|
184
123
|
|
|
185
|
-
# Permissions
|
|
186
|
-
tgcc permissions set mybot dangerously-skip
|
|
187
124
|
```
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
CC output streams into a single Telegram message. As CC produces text, TGCC edits the same message with the accumulated content (throttled to ~1 edit/second to respect Telegram rate limits). When the message gets too long (~4000 chars), it splits into a new message.
|
|
194
|
-
|
|
195
|
-
### HTML Formatting
|
|
196
|
-
|
|
197
|
-
All output uses Telegram's HTML parse mode:
|
|
198
|
-
- Code blocks → `<pre><code class="language-python">...</code></pre>`
|
|
199
|
-
- Inline code → `<code>...</code>`
|
|
200
|
-
- Bold, italic, strikethrough, links — all converted from CC's markdown
|
|
201
|
-
|
|
202
|
-
### Thinking in Expandable Blockquotes
|
|
203
|
-
|
|
204
|
-
When CC thinks, the thinking content is captured and displayed as a collapsible blockquote:
|
|
205
|
-
|
|
206
|
-
```html
|
|
207
|
-
<blockquote expandable>💭 Thinking
|
|
208
|
-
Analyzing the auth middleware pattern...
|
|
209
|
-
</blockquote>
|
|
125
|
+
User ──► Telegram ──► TGCC ──► Claude Code CLI (stream-json)
|
|
126
|
+
│
|
|
127
|
+
config.json ─── agents, repos, permissions
|
|
128
|
+
state.json ─── sessions, per-user overrides
|
|
210
129
|
```
|
|
211
130
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
### Sub-Agent Activity
|
|
215
|
-
|
|
216
|
-
When CC spawns sub-agents (via `dispatch_agent`, `Task`, etc.), TGCC sends a threaded reply:
|
|
217
|
-
|
|
218
|
-
> 🔄 Sub-agent spawned: `dispatch_agent`
|
|
219
|
-
> *(updates with input preview, then ✅ on completion)*
|
|
220
|
-
|
|
221
|
-
### Smart Hang Detection
|
|
131
|
+
TGCC runs as a persistent service. When a user sends a message, it spawns (or resumes) a Claude Code process using the `stream-json` protocol, streams the response back with edit-in-place updates.
|
|
222
132
|
|
|
223
|
-
|
|
224
|
-
- **Tool executing** with active children → extend timer
|
|
225
|
-
- **Waiting for API** → extend timer (API can be slow)
|
|
226
|
-
- **No activity** for hangTimeoutMs → truly hung, kill and notify
|
|
227
|
-
|
|
228
|
-
### Session Staleness Detection
|
|
229
|
-
|
|
230
|
-
If you use the same CC session from both Telegram and VS Code, TGCC detects the modification when you next message from Telegram. It shows a summary of what happened externally and reconnects cleanly.
|
|
231
|
-
|
|
232
|
-
## How It Works with Claude Code
|
|
233
|
-
|
|
234
|
-
TGCC uses CC's `stream-json` protocol:
|
|
235
|
-
|
|
236
|
-
1. **Spawn** — `claude -p --input-format stream-json --output-format stream-json --verbose --include-partial-messages`
|
|
237
|
-
2. **Initialize** — Send `control_request` with `subtype: "initialize"` (SDK handshake)
|
|
238
|
-
3. **Messages** — Write JSON user messages to stdin, parse NDJSON events from stdout
|
|
239
|
-
4. **Streaming** — `stream_event` wraps inner events: `message_start`, `content_block_start`, `content_block_delta` (text, thinking, image), `content_block_stop`, `message_stop`
|
|
240
|
-
5. **Permissions** — CC sends `control_request` with `subtype: "can_use_tool"`, TGCC relays to Telegram and sends `control_response` back
|
|
241
|
-
6. **Sessions** — `--resume <id>` reconnects to an existing session, same JSONL files as the VS Code extension
|
|
242
|
-
7. **Results** — `result` event with cost, token usage, success/error status
|
|
243
|
-
|
|
244
|
-
Sessions are fully interoperable with the VS Code Claude Code extension — the same `~/.claude/projects/` JSONL files are used by both.
|
|
245
|
-
|
|
246
|
-
## Project Structure
|
|
247
|
-
|
|
248
|
-
```
|
|
249
|
-
src/
|
|
250
|
-
├── cli.ts # CLI tool (tgcc command)
|
|
251
|
-
├── bridge.ts # Core orchestrator (TG ↔ CC)
|
|
252
|
-
├── cc-process.ts # CC process lifecycle management
|
|
253
|
-
├── cc-protocol.ts # CC stream-json protocol types & parser
|
|
254
|
-
├── streaming.ts # Stream accumulator (edit-in-place, splitting)
|
|
255
|
-
├── telegram.ts # Telegram bot (grammY)
|
|
256
|
-
├── config.ts # Config loading, validation, hot-reload
|
|
257
|
-
├── session.ts # Session store, staleness, catchup
|
|
258
|
-
├── ctl-server.ts # Unix socket server for CLI communication
|
|
259
|
-
├── mcp-bridge.ts # MCP server for CC → TG file/image/voice
|
|
260
|
-
├── mcp-server.ts # MCP tool definitions
|
|
261
|
-
└── index.ts # Entry point
|
|
262
|
-
```
|
|
133
|
+
Sessions are fully interoperable with the VS Code Claude Code extension — same `~/.claude/projects/` JSONL files.
|
|
263
134
|
|
|
264
135
|
## License
|
|
265
136
|
|