tg-code-bot 0.1.0__tar.gz
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.
- tg_code_bot-0.1.0/.claude/settings.local.json +14 -0
- tg_code_bot-0.1.0/.gitignore +3 -0
- tg_code_bot-0.1.0/Dockerfile +30 -0
- tg_code_bot-0.1.0/PKG-INFO +9 -0
- tg_code_bot-0.1.0/README.md +113 -0
- tg_code_bot-0.1.0/plan.md +760 -0
- tg_code_bot-0.1.0/pyproject.toml +22 -0
- tg_code_bot-0.1.0/src/tg_code_bot/Dockerfile +30 -0
- tg_code_bot-0.1.0/src/tg_code_bot/__init__.py +0 -0
- tg_code_bot-0.1.0/src/tg_code_bot/bot.py +539 -0
- tg_code_bot-0.1.0/src/tg_code_bot/cli.py +159 -0
- tg_code_bot-0.1.0/src/tg_code_bot/config.py +126 -0
- tg_code_bot-0.1.0/src/tg_code_bot/db.py +144 -0
- tg_code_bot-0.1.0/src/tg_code_bot/engines/__init__.py +0 -0
- tg_code_bot-0.1.0/src/tg_code_bot/engines/base.py +15 -0
- tg_code_bot-0.1.0/src/tg_code_bot/engines/claude.py +41 -0
- tg_code_bot-0.1.0/src/tg_code_bot/engines/codex.py +55 -0
- tg_code_bot-0.1.0/src/tg_code_bot/github.py +109 -0
- tg_code_bot-0.1.0/src/tg_code_bot/sandbox.py +246 -0
- tg_code_bot-0.1.0/src/tg_code_bot/session.py +156 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"WebSearch",
|
|
5
|
+
"WebFetch(domain:developers.openai.com)",
|
|
6
|
+
"Bash(claude -p \"say hello\" --output-format json 2>&1)",
|
|
7
|
+
"WebFetch(domain:github.com)",
|
|
8
|
+
"Bash(docker build -t tg-code-sandbox -f /home/andrew/Documents/projects/chat-with-codebase/Dockerfile /home/andrew/Documents/projects/chat-with-codebase/ 2>&1)",
|
|
9
|
+
"Bash(.venv/bin/tg-code config remove-repo test-repo 2>&1 && .venv/bin/tg-code config list-repos 2>&1)",
|
|
10
|
+
"Bash(.venv/bin/tg-code config allowed-users remove 12345 2>&1)",
|
|
11
|
+
"Bash(docker rm -f tg-code-wt-test 2>&1)"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
FROM node:22-bookworm-slim
|
|
2
|
+
|
|
3
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
4
|
+
git \
|
|
5
|
+
python3 \
|
|
6
|
+
python3-pip \
|
|
7
|
+
curl \
|
|
8
|
+
jq \
|
|
9
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
10
|
+
|
|
11
|
+
# Install Claude Code CLI
|
|
12
|
+
RUN npm install -g @anthropic-ai/claude-code
|
|
13
|
+
|
|
14
|
+
# Install Codex CLI
|
|
15
|
+
RUN npm install -g @openai/codex
|
|
16
|
+
|
|
17
|
+
# Install GitHub CLI
|
|
18
|
+
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
|
|
19
|
+
| dd of=/usr/share/keyrings/gh.gpg && \
|
|
20
|
+
echo "deb [signed-by=/usr/share/keyrings/gh.gpg] https://cli.github.com/packages stable main" \
|
|
21
|
+
> /etc/apt/sources.list.d/github-cli.list && \
|
|
22
|
+
apt-get update && apt-get install -y gh && \
|
|
23
|
+
rm -rf /var/lib/apt/lists/*
|
|
24
|
+
|
|
25
|
+
RUN mkdir -p /workspace/repo /workspace/sessions
|
|
26
|
+
|
|
27
|
+
WORKDIR /workspace/repo
|
|
28
|
+
|
|
29
|
+
# Keep container alive
|
|
30
|
+
CMD ["sleep", "infinity"]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tg-code-bot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Telegram bot bridging 1-on-1 messages to Claude Code CLI or OpenAI Codex CLI in isolated Docker containers
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Requires-Dist: aiogram>=3.25
|
|
7
|
+
Requires-Dist: aiosqlite
|
|
8
|
+
Requires-Dist: click
|
|
9
|
+
Requires-Dist: tomli-w
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# tg-code
|
|
2
|
+
|
|
3
|
+
Telegram bot that bridges 1-on-1 DMs to [Claude Code CLI](https://docs.anthropic.com/en/docs/claude-code) or [OpenAI Codex CLI](https://github.com/openai/codex), with each repo running in an isolated Docker container sandbox.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
Telegram DM (you <-> bot)
|
|
7
|
+
|
|
|
8
|
+
tg-code bot (Python/aiogram on host)
|
|
9
|
+
|
|
|
10
|
+
+-- Session #1 --> docker exec container-myapp claude -p "..." --resume sid1
|
|
11
|
+
+-- Session #2 --> docker exec container-myapp codex exec resume tid2 "..."
|
|
12
|
+
+-- /pr ----------> docker exec container-myapp gh pr create ...
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- Python >= 3.11
|
|
18
|
+
- Docker
|
|
19
|
+
- A Telegram bot token (from [@BotFather](https://t.me/BotFather))
|
|
20
|
+
- An Anthropic API key and/or OpenAI API key
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# With uv (recommended)
|
|
26
|
+
uv tool install tg-code-bot
|
|
27
|
+
|
|
28
|
+
# Or ephemeral
|
|
29
|
+
uvx tg-code-bot --help
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Setup
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# 1. Set your bot token
|
|
36
|
+
tg-code config bot-token YOUR_BOT_TOKEN
|
|
37
|
+
|
|
38
|
+
# 2. Whitelist your Telegram user ID
|
|
39
|
+
tg-code config allowed-users add YOUR_TELEGRAM_USER_ID
|
|
40
|
+
|
|
41
|
+
# 3. Register a repo
|
|
42
|
+
tg-code config add-repo --path /path/to/your/repo --name my-app
|
|
43
|
+
|
|
44
|
+
# 4. Set API keys (or export ANTHROPIC_API_KEY / CODEX_API_KEY env vars)
|
|
45
|
+
tg-code config set-keys
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Run
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
tg-code run
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
On first run, tg-code builds the `tg-code-sandbox` Docker image (node 22 + claude-code + codex + gh CLI). This takes a few minutes.
|
|
55
|
+
|
|
56
|
+
## Telegram Commands
|
|
57
|
+
|
|
58
|
+
| Command | Description |
|
|
59
|
+
|---------|-------------|
|
|
60
|
+
| `/start` | Connect this chat to a repo |
|
|
61
|
+
| `/new` | Start a new sandboxed session (git worktree) |
|
|
62
|
+
| `/pr` | Create a PR from the current session |
|
|
63
|
+
| `/pr 123` | Check out PR #123 into a new session |
|
|
64
|
+
| `/pr search text` | Search PRs and pick one to check out |
|
|
65
|
+
| `/claude` | Switch engine to Claude Code |
|
|
66
|
+
| `/codex` | Switch engine to Codex CLI |
|
|
67
|
+
| `/status` | Show current session info |
|
|
68
|
+
| `/destroy` | Remove container and all sessions |
|
|
69
|
+
|
|
70
|
+
Regular messages are forwarded to the active AI session. Reply to a bot message to route to that specific session.
|
|
71
|
+
|
|
72
|
+
## CLI Commands
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
tg-code config bot-token <token> # Set Telegram bot token
|
|
76
|
+
tg-code config add-repo [--path] [--name] # Register a repo
|
|
77
|
+
tg-code config remove-repo <name> # Unregister a repo
|
|
78
|
+
tg-code config list-repos # List all repos
|
|
79
|
+
tg-code config allowed-users add <id> # Allow a Telegram user
|
|
80
|
+
tg-code config allowed-users remove <id> # Remove a Telegram user
|
|
81
|
+
tg-code config set-keys # Set API keys interactively
|
|
82
|
+
tg-code run # Start the bot
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## How It Works
|
|
86
|
+
|
|
87
|
+
- Each registered repo gets its own Docker container with claude-code, codex, and gh pre-installed
|
|
88
|
+
- Sessions run in git worktrees for branch isolation, so you can have multiple parallel tasks per repo
|
|
89
|
+
- Your `~/.gitconfig` and `~/.git-credentials` are copied into containers so git/gh operations work
|
|
90
|
+
- Session state is persisted to SQLite (`~/.config/tg-code/state.db`) and survives bot restarts
|
|
91
|
+
- CLIs are auto-updated nightly at 3 AM EST
|
|
92
|
+
|
|
93
|
+
## Config
|
|
94
|
+
|
|
95
|
+
Stored at `~/.config/tg-code/config.toml`:
|
|
96
|
+
|
|
97
|
+
```toml
|
|
98
|
+
[bot]
|
|
99
|
+
token = "123456:ABC..."
|
|
100
|
+
allowed_users = [987654321]
|
|
101
|
+
|
|
102
|
+
[keys]
|
|
103
|
+
anthropic_api_key = ""
|
|
104
|
+
codex_api_key = ""
|
|
105
|
+
|
|
106
|
+
[[repos]]
|
|
107
|
+
name = "my-app"
|
|
108
|
+
path = "/home/user/projects/my-app"
|
|
109
|
+
default_engine = "claude"
|
|
110
|
+
copy_untracked = [".env"]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
API keys can also be set via `ANTHROPIC_API_KEY` and `CODEX_API_KEY` environment variables.
|