@fonz/tgcc 0.6.15 → 0.6.18
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 +74 -50
- package/dist/bridge.d.ts +19 -7
- package/dist/bridge.js +898 -629
- package/dist/bridge.js.map +1 -1
- package/dist/cc-process.js +11 -0
- package/dist/cc-process.js.map +1 -1
- package/dist/cc-protocol.d.ts +11 -1
- package/dist/cc-protocol.js.map +1 -1
- package/dist/cli.js +0 -0
- package/dist/ctl-server.d.ts +4 -0
- package/dist/ctl-server.js +30 -4
- package/dist/ctl-server.js.map +1 -1
- package/dist/event-buffer.d.ts +27 -0
- package/dist/event-buffer.js +50 -0
- package/dist/event-buffer.js.map +1 -0
- package/dist/high-signal.d.ts +53 -0
- package/dist/high-signal.js +391 -0
- package/dist/high-signal.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp-bridge.d.ts +3 -5
- package/dist/mcp-server.js +80 -0
- package/dist/mcp-server.js.map +1 -1
- package/dist/session.d.ts +13 -8
- package/dist/session.js +63 -39
- package/dist/session.js.map +1 -1
- package/dist/streaming.d.ts +30 -8
- package/dist/streaming.js +270 -118
- package/dist/streaming.js.map +1 -1
- package/dist/telegram.d.ts +3 -1
- package/dist/telegram.js +19 -1
- package/dist/telegram.js.map +1 -1
- package/package.json +1 -1
- package/dist/telegram-html.d.ts +0 -5
- package/dist/telegram-html.js +0 -126
- package/dist/telegram-html.js.map +0 -1
package/README.md
CHANGED
|
@@ -20,11 +20,81 @@ TGCC bridges the [Claude Code CLI](https://docs.anthropic.com/en/docs/claude-cod
|
|
|
20
20
|
|
|
21
21
|
- **Streaming** — responses stream into a single message that updates in place
|
|
22
22
|
- **Sessions** — resume, switch, and list sessions. Roam between Telegram and the CC CLI on the same session
|
|
23
|
-
- **Multi-
|
|
23
|
+
- **Multi-agent** — run dedicated bots per project, each with its own repo and model
|
|
24
24
|
- **Permission relay** — CC permission prompts appear as inline buttons
|
|
25
25
|
- **MCP tools** — CC can send files, images, and voice back via built-in MCP server
|
|
26
26
|
- **Markdown → Telegram HTML** — code blocks, bold, italic, links, tables, all rendered properly
|
|
27
27
|
- **Usage stats** — per-turn token counts and cost
|
|
28
|
+
- **Supervisor protocol** — external orchestrators (e.g. OpenClaw) can send messages, subscribe to events, and share the same CC process via Unix socket
|
|
29
|
+
|
|
30
|
+
## Architecture
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
Telegram ──► TGCC Bridge ──► Claude Code CLI (stream-json)
|
|
34
|
+
│
|
|
35
|
+
CLI (ctl) ───────┤
|
|
36
|
+
│
|
|
37
|
+
Supervisor ──────┘ (Unix socket, NDJSON)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Agent Model
|
|
41
|
+
|
|
42
|
+
Each agent has:
|
|
43
|
+
- **One repo** — the project directory CC runs in
|
|
44
|
+
- **One CC process** (at most) — shared by all message sources (Telegram, supervisor, CLI)
|
|
45
|
+
- **One model** — the Claude model to use
|
|
46
|
+
|
|
47
|
+
Agents don't know about users. `allowedUsers` is a system-level ACL that gates which Telegram users can interact with the bot. All allowed users share the same agent state.
|
|
48
|
+
|
|
49
|
+
`sessionId` lives on the CC process, not the agent. When a process spawns, it either continues the last session (`--continue`) or resumes a specific one (`--resume <id>`).
|
|
50
|
+
|
|
51
|
+
### Supervisor Protocol
|
|
52
|
+
|
|
53
|
+
External systems connect to TGCC's control socket (`/tmp/tgcc/ctl/tgcc.sock`) and register as a supervisor. They can then:
|
|
54
|
+
|
|
55
|
+
- **`send_message`** — send a message to any agent's CC process (spawns if needed)
|
|
56
|
+
- **`send_to_cc`** — write directly to an active CC process's stdin
|
|
57
|
+
- **`subscribe`** / **`unsubscribe`** — observe an agent's events
|
|
58
|
+
- **`status`** — list all agents, their state, and active processes
|
|
59
|
+
- **`kill_cc`** — terminate an agent's CC process
|
|
60
|
+
|
|
61
|
+
Events forwarded to subscribers: `result`, `session_takeover`, `process_exit`, `cc_spawned`, `state_changed`, `bridge_started`, plus all observability events.
|
|
62
|
+
|
|
63
|
+
When a supervisor sends a message to a persistent agent, a system notification (`🦞 OpenClaw: ...`) appears in the Telegram chat.
|
|
64
|
+
|
|
65
|
+
### Ephemeral Agents
|
|
66
|
+
|
|
67
|
+
Supervisors can create temporary agents for one-off tasks — no Telegram bot needed:
|
|
68
|
+
|
|
69
|
+
- **`create_agent`** — create an in-memory agent with a repo and model
|
|
70
|
+
- **`destroy_agent`** — tear down when the task is done
|
|
71
|
+
|
|
72
|
+
Ephemeral agents auto-destroy on timeout. Only the supervisor can interact with them.
|
|
73
|
+
|
|
74
|
+
### Observability
|
|
75
|
+
|
|
76
|
+
TGCC detects high-signal events from CC processes and forwards them to subscribers:
|
|
77
|
+
|
|
78
|
+
- **Build/test results** — pass/fail with error counts
|
|
79
|
+
- **Git commits** — commit messages as natural progress summaries
|
|
80
|
+
- **Context pressure** — alerts at 50%, 75%, 90% of context window
|
|
81
|
+
- **Failure loops** — 3+ consecutive tool failures
|
|
82
|
+
- **Stuck detection** — no CC output for 5+ minutes
|
|
83
|
+
- **Task milestones** — TodoWrite progress tracking
|
|
84
|
+
- **Sub-agent spawns** — CC using Task tool for parallel work
|
|
85
|
+
|
|
86
|
+
Each agent's events are stored in a ring buffer, queryable via `get_log` with offset/limit/grep/since/type filters.
|
|
87
|
+
|
|
88
|
+
### MCP Tools for CC → Supervisor
|
|
89
|
+
|
|
90
|
+
CC processes can communicate back to the orchestrator via built-in MCP tools:
|
|
91
|
+
|
|
92
|
+
- **`notify_parent`** — send a message to the parent (questions, blockers, progress)
|
|
93
|
+
- **`supervisor_exec`** — request command execution on the host
|
|
94
|
+
- **`supervisor_notify`** — send a notification to any agent
|
|
95
|
+
|
|
96
|
+
See [`docs/SPEC-SUPERVISOR-PROTOCOL.md`](docs/SPEC-SUPERVISOR-PROTOCOL.md) for the full protocol spec.
|
|
97
|
+
See [`docs/SPEC-SUBAGENT-OBSERVABILITY.md`](docs/SPEC-SUBAGENT-OBSERVABILITY.md) for the observability spec.
|
|
28
98
|
|
|
29
99
|
## Service Management
|
|
30
100
|
|
|
@@ -61,7 +131,7 @@ tgcc repo list
|
|
|
61
131
|
|
|
62
132
|
# Messaging (while service is running)
|
|
63
133
|
tgcc message "fix the login bug"
|
|
64
|
-
tgcc message "deploy" --agent=mybot
|
|
134
|
+
tgcc message "deploy" --agent=mybot
|
|
65
135
|
tgcc status
|
|
66
136
|
tgcc status --agent=mybot
|
|
67
137
|
|
|
@@ -82,40 +152,6 @@ tgcc permissions set mybot dangerously-skip
|
|
|
82
152
|
| `/permissions` | Set permission mode |
|
|
83
153
|
| `/status` | Process state, model, repo, cost |
|
|
84
154
|
| `/cancel` | Abort current CC turn |
|
|
85
|
-
| `/catchup` | Summarize external CC activity |
|
|
86
|
-
|
|
87
|
-
## Project Setup
|
|
88
|
-
|
|
89
|
-
TGCC supports two approaches — use one or both:
|
|
90
|
-
|
|
91
|
-
### Single bot, multiple repos (recommended)
|
|
92
|
-
|
|
93
|
-
One bot switches between projects on the fly:
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
tgcc repo add ~/code/frontend --name=frontend
|
|
97
|
-
tgcc repo add ~/code/backend --name=backend
|
|
98
|
-
tgcc repo assign --agent=mybot --name=frontend # set default
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
In Telegram, use `/repo` to switch. If no repo is selected, TGCC warns that CC will run in `~`.
|
|
102
|
-
|
|
103
|
-
### Dedicated bot per project
|
|
104
|
-
|
|
105
|
-
Create a separate Telegram bot (via [@BotFather](https://t.me/BotFather)) for each project:
|
|
106
|
-
|
|
107
|
-
```bash
|
|
108
|
-
tgcc agent add frontend-bot --bot-token <token1>
|
|
109
|
-
tgcc agent add backend-bot --bot-token <token2>
|
|
110
|
-
|
|
111
|
-
tgcc repo add ~/code/frontend --name=frontend
|
|
112
|
-
tgcc repo add ~/code/backend --name=backend
|
|
113
|
-
|
|
114
|
-
tgcc repo assign --agent=frontend-bot --name=frontend
|
|
115
|
-
tgcc repo assign --agent=backend-bot --name=backend
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
Each bot starts CC in its assigned repo by default. Users can still `/repo` switch if needed.
|
|
119
155
|
|
|
120
156
|
## Configuration
|
|
121
157
|
|
|
@@ -133,9 +169,10 @@ Config lives at `~/.tgcc/config.json` (created by `tgcc init`).
|
|
|
133
169
|
"agents": {
|
|
134
170
|
"mybot": {
|
|
135
171
|
"botToken": "123456:ABC-DEF...",
|
|
136
|
-
"allowedUsers": [],
|
|
172
|
+
"allowedUsers": ["your-telegram-id"],
|
|
137
173
|
"defaults": {
|
|
138
174
|
"repo": "myproject",
|
|
175
|
+
"model": "claude-sonnet-4-20250514",
|
|
139
176
|
"permissionMode": "bypassPermissions"
|
|
140
177
|
}
|
|
141
178
|
}
|
|
@@ -152,19 +189,6 @@ Config lives at `~/.tgcc/config.json` (created by `tgcc init`).
|
|
|
152
189
|
| `default` | Full permission flow via inline buttons |
|
|
153
190
|
| `plan` | Plan-only, no tool execution |
|
|
154
191
|
|
|
155
|
-
## Architecture
|
|
156
|
-
|
|
157
|
-
```
|
|
158
|
-
User ──► Telegram ──► TGCC ──► Claude Code CLI (stream-json)
|
|
159
|
-
│
|
|
160
|
-
config.json ─── agents, repos, permissions
|
|
161
|
-
state.json ─── sessions, per-user overrides
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
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.
|
|
165
|
-
|
|
166
|
-
Sessions are fully interoperable with the VS Code Claude Code extension — same `~/.claude/projects/` JSONL files.
|
|
167
|
-
|
|
168
192
|
## License
|
|
169
193
|
|
|
170
194
|
MIT
|
package/dist/bridge.d.ts
CHANGED
|
@@ -6,11 +6,16 @@ export declare class Bridge extends EventEmitter implements CtlHandler {
|
|
|
6
6
|
private config;
|
|
7
7
|
private agents;
|
|
8
8
|
private processRegistry;
|
|
9
|
-
private sessionModelOverrides;
|
|
10
9
|
private mcpServer;
|
|
11
10
|
private ctlServer;
|
|
12
11
|
private sessionStore;
|
|
13
12
|
private logger;
|
|
13
|
+
private highSignalDetector;
|
|
14
|
+
private supervisorWrite;
|
|
15
|
+
private supervisorAgentId;
|
|
16
|
+
private supervisorSubscriptions;
|
|
17
|
+
private suppressExitForProcess;
|
|
18
|
+
private supervisorPendingRequests;
|
|
14
19
|
constructor(config: TgccConfig, logger?: pino.Logger);
|
|
15
20
|
start(): Promise<void>;
|
|
16
21
|
private startAgent;
|
|
@@ -18,14 +23,12 @@ export declare class Bridge extends EventEmitter implements CtlHandler {
|
|
|
18
23
|
private stopAgent;
|
|
19
24
|
private handleTelegramMessage;
|
|
20
25
|
private sendToCC;
|
|
21
|
-
/** Check if the session JSONL was modified externally since we last tracked it. */
|
|
22
|
-
private checkSessionStaleness;
|
|
23
26
|
/**
|
|
24
|
-
*
|
|
25
|
-
* If other subscribers remain, the process stays alive.
|
|
26
|
-
* If this was the last subscriber, the process is destroyed.
|
|
27
|
+
* Kill the agent's CC process and clean up.
|
|
27
28
|
*/
|
|
28
|
-
private
|
|
29
|
+
private killAgentProcess;
|
|
30
|
+
/** Get the primary TG chat ID for an agent (first allowed user). */
|
|
31
|
+
private getAgentChatId;
|
|
29
32
|
private startTypingIndicator;
|
|
30
33
|
private stopTypingIndicator;
|
|
31
34
|
private spawnCCProcess;
|
|
@@ -36,5 +39,14 @@ export declare class Bridge extends EventEmitter implements CtlHandler {
|
|
|
36
39
|
handleCtlMessage(agentId: string, text: string, sessionId?: string): CtlAckResponse;
|
|
37
40
|
handleCtlStatus(agentId?: string): CtlStatusResponse;
|
|
38
41
|
private handleMcpToolRequest;
|
|
42
|
+
private isSupervisorSubscribed;
|
|
43
|
+
registerSupervisor(agentId: string, capabilities: string[], writeFn: (line: string) => void): void;
|
|
44
|
+
handleSupervisorDetach(): void;
|
|
45
|
+
handleSupervisorLine(line: string): void;
|
|
46
|
+
private handleSupervisorCommand;
|
|
47
|
+
private emitStateChanged;
|
|
48
|
+
private sendToSupervisor;
|
|
49
|
+
private sendSupervisorRequest;
|
|
50
|
+
private destroyEphemeralAgent;
|
|
39
51
|
stop(): Promise<void>;
|
|
40
52
|
}
|