cliclaw 1.0.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 ADDED
@@ -0,0 +1,16 @@
1
+ # Token do bot (obter no @BotFather)
2
+ TELEGRAM_BOT_TOKEN=
3
+
4
+ # ID do grupo com Forum/Topics ativado (usar /id no grupo)
5
+ FORUM_GROUP_ID=
6
+
7
+ # Anthropic API Key (opcional — o bot usa OAuth do Claude Code CLI)
8
+ # Deixar em branco se fizer login via: claude (abre link OAuth)
9
+ ANTHROPIC_API_KEY=
10
+
11
+ # OpenAI API Key (opcional — o bot usa o Codex CLI logado)
12
+ # Deixar em branco se já logado via: codex login
13
+ OPENAI_API_KEY=
14
+
15
+ # Pasta de dados (padrão: ~/openclaw/data)
16
+ DATA_DIR=
package/README.md ADDED
@@ -0,0 +1,241 @@
1
+ # 🦀 Cli-Claw
2
+
3
+ > **Cli-Claw** is a Telegram bot that acts as a **direct bridge between AI CLI tools and your phone**. Each conversation lives in a dedicated Forum Topic thread — you type from anywhere, the CLI runs on your server, the answer comes back. No API keys, no per-token billing, just your own subscription plan.
4
+
5
+ ```
6
+ /new → opens a forum topic → 🟣 Claude or 🟢 Codex
7
+ └ each topic = one CLI session with full conversation memory
8
+ ```
9
+
10
+ 📖 **[Leia em Português →](README.pt.md)**
11
+
12
+ ---
13
+
14
+ ## Why a CLI bridge?
15
+
16
+ Most Telegram AI bots call HTTP APIs. Cli-Claw is different — it drives the actual CLI binaries installed on your server:
17
+
18
+ | | Cli-Claw | API-based bots |
19
+ |---|---|---|
20
+ | **Auth** | OAuth / ChatGPT login | API keys (paid per token) |
21
+ | **Cost** | Your subscription plan | Metered billing |
22
+ | **Agentic tasks** | ✅ Full tool access | ❌ Limited |
23
+ | **Permission control** | ✅ Per session / on demand | N/A |
24
+ | **Adds a new CLI** | Just install & restart | N/A |
25
+
26
+ Because it drives real CLI processes, Cli-Claw can do anything you can do in a terminal — install software, execute code, browse files, run long agentic workflows.
27
+
28
+ ---
29
+
30
+ ## Supported agents
31
+
32
+ | Agent | Status | Notes |
33
+ |---|---|---|
34
+ | 🟣 **Claude Code** | ✅ Available | Requires claude.ai subscription |
35
+ | 🟢 **Codex** | ✅ Available | Requires OpenAI/ChatGPT account |
36
+ | 🔜 **OpenCode** | Coming soon | Open-source CLI, no subscription needed |
37
+
38
+ Each agent you install becomes immediately available. The bot detects which CLIs are in `PATH` on startup and shows a setup guide for anything not yet configured.
39
+
40
+ ---
41
+
42
+ ## Bot commands
43
+
44
+ | English | Portuguese | Description |
45
+ |---|---|---|
46
+ | `/new` | `/nova` | New Claude session (creates a forum topic) |
47
+ | `/new codex` | `/nova codex` | New Codex session |
48
+ | `/sessions` | `/sessoes` | List all sessions |
49
+ | `/clear` | `/limpar` | Reset current session / topic |
50
+ | `/status` | `/status` | Active session info |
51
+ | `/id` | `/id` | Show this chat ID |
52
+ | `/help` | `/ajuda` | Show help message |
53
+
54
+ ---
55
+
56
+ ## Requirements
57
+
58
+ - **Ubuntu 22+** (tested on Oracle Cloud ARM64)
59
+ - **Node.js 22+**
60
+ - **Claude Code CLI** authenticated via OAuth (`claude`) — *optional, add to unlock 🟣*
61
+ - **Codex CLI** authenticated via ChatGPT (`codex login`) — *optional, add to unlock 🟢*
62
+ - A Telegram **group** with **Topics enabled**, bot added as **admin**
63
+
64
+ ---
65
+
66
+ ## Installation
67
+
68
+ ### 1. Clone and install
69
+
70
+ ```bash
71
+ git clone https://github.com/luizfeer/cliclaw.git
72
+ cd cliclaw
73
+ npm install
74
+ ```
75
+
76
+ ### 2. Install Node.js 22 (if needed)
77
+
78
+ ```bash
79
+ curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
80
+ sudo apt-get install -y nodejs
81
+ npm install -g tsx pm2
82
+ ```
83
+
84
+ ### 3. Install AI CLIs
85
+
86
+ Install at least one. You can add more later — just restart the bot.
87
+
88
+ ```bash
89
+ # Set up npm global prefix (no sudo)
90
+ mkdir -p ~/.npm-global
91
+ npm config set prefix ~/.npm-global
92
+ echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc
93
+
94
+ # 🟣 Claude Code (requires claude.ai subscription)
95
+ npm install -g @anthropic-ai/claude-code
96
+ claude # opens OAuth link in your browser
97
+
98
+ # 🟢 Codex (requires OpenAI/ChatGPT account)
99
+ npm install -g @openai/codex
100
+ codex login
101
+ ```
102
+
103
+ > **Don't have either yet?** That's fine — install the bot first, then send `/start` in Telegram. The bot will show exactly what to run.
104
+
105
+ ### 4. Configure
106
+
107
+ ```bash
108
+ cp .env.example .env
109
+ nano .env
110
+ ```
111
+
112
+ ```env
113
+ TELEGRAM_BOT_TOKEN= # from @BotFather → /newbot
114
+ FORUM_GROUP_ID= # run /id inside your group to get it
115
+ ```
116
+
117
+ ### 5. Choose a permission mode
118
+
119
+ Add `PERMISSION_MODE` to your `.env`:
120
+
121
+ | Mode | Value | Behavior |
122
+ |---|---|---|
123
+ | **Full auto** *(recommended)* | `auto` | Always skips all permission prompts — models run freely |
124
+ | **Per session** | `session` | Bot asks when you run `/new`: *"Allow full auto for this session?"* |
125
+ | **On demand** | `ask` | Restricted by default; prefix any message with `!` to grant full auto for that message only |
126
+
127
+ ```env
128
+ PERMISSION_MODE=auto
129
+ ```
130
+
131
+ ### 6. Set up Telegram group
132
+
133
+ 1. Create a Telegram group
134
+ 2. **Edit group → Topics → Enable**
135
+ 3. Add your bot as **Admin** with *Manage Topics* permission
136
+ 4. Send `/id` in the group and copy the Chat ID
137
+ 5. Paste it as `FORUM_GROUP_ID` in `.env`
138
+
139
+ ### 7. Start
140
+
141
+ ```bash
142
+ # Test run
143
+ npx tsx index.ts
144
+
145
+ # Production — auto-restarts on crash and reboot
146
+ pm2 start ecosystem.config.js
147
+ pm2 save && pm2 startup
148
+ ```
149
+
150
+ ---
151
+
152
+ ## How it works
153
+
154
+ ```
155
+ Message in forum topic
156
+
157
+ Resolve session by thread_id
158
+
159
+ Lock session (prevent concurrent processes)
160
+
161
+ Send "⚙️ Processing..." + typing loop every 4s
162
+
163
+ Spawn CLI based on PERMISSION_MODE:
164
+ claude --resume <id> -p "msg" --output-format text
165
+ codex exec resume <thread> --json "msg"
166
+
167
+ Process runs to completion (no kill timeout)
168
+
169
+ Delete "Processing..." → send formatted HTML response
170
+ ```
171
+
172
+ Session IDs are saved to `data/chat_<id>.json` — context survives bot restarts.
173
+
174
+ ---
175
+
176
+ ## Publishing to npm *(planned)*
177
+
178
+ The goal is to make installation a single command:
179
+
180
+ ```bash
181
+ npm install -g cliclaw
182
+ cliclaw setup # interactive wizard: bot token, group ID, permission mode
183
+ cliclaw start
184
+ ```
185
+
186
+ This requires a `cli.js` setup wizard and a compiled entry point. The CLIs (`claude`, `codex`) will still need to be authenticated manually — npm can bundle the bot code but not OAuth sessions. The wizard would guide through that step.
187
+
188
+ Contributions welcome: **[github.com/luizfeer/cliclaw](https://github.com/luizfeer/cliclaw)**
189
+
190
+ ---
191
+
192
+ ## Project structure
193
+
194
+ ```
195
+ cliclaw/
196
+ ├── index.ts # Entry point
197
+ ├── ecosystem.config.js # PM2 config (uses tsx)
198
+ ├── src/
199
+ │ ├── config.ts # Loads .env + detects available CLIs
200
+ │ ├── storage.ts # JSON session persistence
201
+ │ ├── agents/
202
+ │ │ ├── claude.ts # Claude Code CLI wrapper
203
+ │ │ └── codex.ts # Codex CLI wrapper
204
+ │ ├── handlers/
205
+ │ │ ├── commands.ts # /new /sessions /clear etc.
206
+ │ │ └── messages.ts # Routes by thread_id, typing loop, lock
207
+ │ └── utils/
208
+ │ └── markdown.ts # Markdown → Telegram HTML
209
+ ├── data/ # Session JSON files (git-ignored)
210
+ ├── .env # Secrets (git-ignored)
211
+ └── .env.example # Template
212
+ ```
213
+
214
+ ---
215
+
216
+ ## Deploy to another VPS
217
+
218
+ ```bash
219
+ git clone https://github.com/luizfeer/cliclaw.git
220
+ cd cliclaw && npm install
221
+ npm install -g tsx pm2 @anthropic-ai/claude-code @openai/codex
222
+ claude && codex login
223
+ cp .env.example .env && nano .env
224
+ pm2 start ecosystem.config.js && pm2 save
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Contributing
230
+
231
+ Cli-Claw is an open community project. PRs welcome — especially:
232
+ - New CLI agent adapters (OpenCode, Gemini CLI, etc.)
233
+ - `cliclaw setup` wizard for npm distribution
234
+ - i18n improvements
235
+ - Better permission UX
236
+
237
+ ---
238
+
239
+ ## License
240
+
241
+ MIT
package/README.pt.md ADDED
@@ -0,0 +1,241 @@
1
+ # 🦀 Cli-Claw
2
+
3
+ > **Cli-Claw** é um bot Telegram que funciona como **ponte direta entre ferramentas CLI de IA e o seu celular**. Cada conversa vive em um tópico dedicado de Fórum — você digita de qualquer lugar, o CLI roda no servidor, a resposta volta. Sem API keys, sem cobrança por token, só o seu plano de assinatura.
4
+
5
+ ```
6
+ /nova → abre um tópico no fórum → 🟣 Claude ou 🟢 Codex
7
+ └ cada tópico = uma sessão CLI com memória completa de conversa
8
+ ```
9
+
10
+ 📖 **[Read in English →](README.md)**
11
+
12
+ ---
13
+
14
+ ## Por que uma ponte de CLI?
15
+
16
+ A maioria dos bots Telegram de IA chama APIs HTTP. O Cli-Claw é diferente — ele aciona os binários CLI instalados no seu servidor:
17
+
18
+ | | Cli-Claw | Bots baseados em API |
19
+ |---|---|---|
20
+ | **Autenticação** | OAuth / login ChatGPT | API keys (pago por token) |
21
+ | **Custo** | Seu plano de assinatura | Cobrança por uso |
22
+ | **Tarefas agênticas** | ✅ Acesso completo às ferramentas | ❌ Limitado |
23
+ | **Controle de permissões** | ✅ Por sessão / sob demanda | N/A |
24
+ | **Adicionar novo CLI** | Instale e reinicie | N/A |
25
+
26
+ Por acionar processos CLI reais, o Cli-Claw pode fazer tudo o que você faria no terminal — instalar software, executar código, navegar em arquivos, rodar workflows agênticos longos.
27
+
28
+ ---
29
+
30
+ ## Agentes disponíveis
31
+
32
+ | Agente | Status | Requisito |
33
+ |---|---|---|
34
+ | 🟣 **Claude Code** | ✅ Disponível | Assinatura claude.ai |
35
+ | 🟢 **Codex** | ✅ Disponível | Conta OpenAI/ChatGPT |
36
+ | 🔜 **OpenCode** | Em breve | CLI open-source, sem assinatura |
37
+
38
+ Cada agente que você instala fica disponível imediatamente. O bot detecta quais CLIs estão no `PATH` ao iniciar e exibe um guia de configuração para o que ainda não está instalado.
39
+
40
+ ---
41
+
42
+ ## Comandos do bot
43
+
44
+ | Português | Inglês | Descrição |
45
+ |---|---|---|
46
+ | `/nova` | `/new` | Nova sessão Claude (cria tópico no fórum) |
47
+ | `/nova codex` | `/new codex` | Nova sessão Codex |
48
+ | `/sessoes` | `/sessions` | Listar todas as sessões |
49
+ | `/limpar` | `/clear` | Reiniciar sessão / tópico atual |
50
+ | `/status` | `/status` | Info da sessão ativa |
51
+ | `/id` | `/id` | Ver ID deste chat |
52
+ | `/ajuda` | `/help` | Exibir ajuda |
53
+
54
+ ---
55
+
56
+ ## Requisitos
57
+
58
+ - **Ubuntu 22+** (testado em Oracle Cloud ARM64)
59
+ - **Node.js 22+**
60
+ - **Claude Code CLI** autenticado via OAuth (`claude`) — *opcional, instale para ativar 🟣*
61
+ - **Codex CLI** autenticado via ChatGPT (`codex login`) — *opcional, instale para ativar 🟢*
62
+ - Um **grupo** Telegram com **Tópicos ativados**, bot adicionado como **admin**
63
+
64
+ ---
65
+
66
+ ## Instalação
67
+
68
+ ### 1. Clonar e instalar
69
+
70
+ ```bash
71
+ git clone https://github.com/luizfeer/cliclaw.git
72
+ cd cliclaw
73
+ npm install
74
+ ```
75
+
76
+ ### 2. Instalar Node.js 22 (se necessário)
77
+
78
+ ```bash
79
+ curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
80
+ sudo apt-get install -y nodejs
81
+ npm install -g tsx pm2
82
+ ```
83
+
84
+ ### 3. Instalar os CLIs de IA
85
+
86
+ Instale pelo menos um. Pode adicionar mais depois — basta reiniciar o bot.
87
+
88
+ ```bash
89
+ # Configurar npm global sem sudo
90
+ mkdir -p ~/.npm-global
91
+ npm config set prefix ~/.npm-global
92
+ echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc
93
+
94
+ # 🟣 Claude Code (requer assinatura claude.ai)
95
+ npm install -g @anthropic-ai/claude-code
96
+ claude # abre link OAuth no navegador
97
+
98
+ # 🟢 Codex (requer conta OpenAI/ChatGPT)
99
+ npm install -g @openai/codex
100
+ codex login
101
+ ```
102
+
103
+ > **Ainda não tem nenhum?** Tudo bem — instale o bot primeiro, depois envie `/start` no Telegram. O bot mostrará exatamente o que executar.
104
+
105
+ ### 4. Configurar
106
+
107
+ ```bash
108
+ cp .env.example .env
109
+ nano .env
110
+ ```
111
+
112
+ ```env
113
+ TELEGRAM_BOT_TOKEN= # obtido no @BotFather → /newbot
114
+ FORUM_GROUP_ID= # use /id dentro do grupo para obter
115
+ ```
116
+
117
+ ### 5. Escolher o modo de permissões
118
+
119
+ Adicione `PERMISSION_MODE` ao seu `.env`:
120
+
121
+ | Modo | Valor | Comportamento |
122
+ |---|---|---|
123
+ | **Full auto** *(recomendado)* | `auto` | Sempre pula prompts de permissão — modelos rodam livremente |
124
+ | **Por sessão** | `session` | Bot pergunta ao criar `/nova`: *"Permitir full auto nesta sessão?"* |
125
+ | **Sob demanda** | `ask` | Restrito por padrão; prefixe mensagens com `!` para liberar só aquele envio |
126
+
127
+ ```env
128
+ PERMISSION_MODE=auto
129
+ ```
130
+
131
+ ### 6. Configurar o grupo Telegram
132
+
133
+ 1. Crie um grupo no Telegram
134
+ 2. **Editar grupo → Tópicos → Ativar**
135
+ 3. Adicione o bot como **Admin** com permissão de *Gerenciar Tópicos*
136
+ 4. Envie `/id` no grupo e copie o Chat ID
137
+ 5. Cole como `FORUM_GROUP_ID` no `.env`
138
+
139
+ ### 7. Iniciar
140
+
141
+ ```bash
142
+ # Teste rápido
143
+ npx tsx index.ts
144
+
145
+ # Produção — reinicia automaticamente em crash e reboot
146
+ pm2 start ecosystem.config.js
147
+ pm2 save && pm2 startup
148
+ ```
149
+
150
+ ---
151
+
152
+ ## Como funciona
153
+
154
+ ```
155
+ Mensagem no tópico do fórum
156
+
157
+ Identifica sessão pelo thread_id
158
+
159
+ Lock da sessão (impede processos concorrentes)
160
+
161
+ Envia "⚙️ Processando..." + typing loop a cada 4s
162
+
163
+ Spawn do CLI com base no PERMISSION_MODE:
164
+ claude --resume <id> -p "msg" --output-format text
165
+ codex exec resume <thread> --json "msg"
166
+
167
+ Processo roda até terminar (sem timeout que mata o processo)
168
+
169
+ Deleta "Processando..." → envia resposta formatada em HTML
170
+ ```
171
+
172
+ Os IDs de sessão são salvos em `data/chat_<id>.json` — o contexto sobrevive a reinicializações.
173
+
174
+ ---
175
+
176
+ ## Publicar no npm *(planejado)*
177
+
178
+ O objetivo é tornar a instalação um único comando:
179
+
180
+ ```bash
181
+ npm install -g cliclaw
182
+ cliclaw setup # wizard interativo: token do bot, ID do grupo, modo de permissão
183
+ cliclaw start
184
+ ```
185
+
186
+ Isso requer um wizard `cli.js` e um entry point compilado. Os CLIs (`claude`, `codex`) ainda precisariam ser autenticados manualmente — o npm pode empacotar o código do bot mas não sessões OAuth. O wizard guiaria por esse passo.
187
+
188
+ Contribuições são bem-vindas: **[github.com/luizfeer/cliclaw](https://github.com/luizfeer/cliclaw)**
189
+
190
+ ---
191
+
192
+ ## Estrutura do projeto
193
+
194
+ ```
195
+ cliclaw/
196
+ ├── index.ts # Ponto de entrada
197
+ ├── ecosystem.config.js # Configuração PM2 (usa tsx)
198
+ ├── src/
199
+ │ ├── config.ts # Carrega .env + detecta CLIs disponíveis
200
+ │ ├── storage.ts # Persistência de sessões em JSON
201
+ │ ├── agents/
202
+ │ │ ├── claude.ts # Wrapper do CLI Claude Code
203
+ │ │ └── codex.ts # Wrapper do CLI Codex
204
+ │ ├── handlers/
205
+ │ │ ├── commands.ts # /nova /sessoes /limpar etc.
206
+ │ │ └── messages.ts # Roteamento por thread_id, typing loop, lock
207
+ │ └── utils/
208
+ │ └── markdown.ts # Conversor Markdown → HTML do Telegram
209
+ ├── data/ # Arquivos JSON de sessão (ignorado pelo git)
210
+ ├── .env # Segredos (ignorado pelo git)
211
+ └── .env.example # Template de configuração
212
+ ```
213
+
214
+ ---
215
+
216
+ ## Deploy em outra VPS
217
+
218
+ ```bash
219
+ git clone https://github.com/luizfeer/cliclaw.git
220
+ cd cliclaw && npm install
221
+ npm install -g tsx pm2 @anthropic-ai/claude-code @openai/codex
222
+ claude && codex login
223
+ cp .env.example .env && nano .env
224
+ pm2 start ecosystem.config.js && pm2 save
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Contribuindo
230
+
231
+ Cli-Claw é um projeto aberto para a comunidade. PRs são bem-vindos — especialmente:
232
+ - Novos adaptadores de agentes CLI (OpenCode, Gemini CLI, etc.)
233
+ - Wizard `cliclaw setup` para distribuição via npm
234
+ - Melhorias de i18n
235
+ - UX de permissões mais refinada
236
+
237
+ ---
238
+
239
+ ## Licença
240
+
241
+ MIT