clawless 0.1.2
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 +48 -0
- package/LICENSE +21 -0
- package/QUICKSTART-SCHEDULER.md +226 -0
- package/QUICKSTART.md +98 -0
- package/README.md +404 -0
- package/SCHEDULER.md +255 -0
- package/TESTING.md +239 -0
- package/acp/clientHelpers.ts +23 -0
- package/acp/tempAcpRunner.ts +320 -0
- package/agent-bridge.config.example.json +19 -0
- package/bin/cli.ts +255 -0
- package/dist/acp/clientHelpers.js +19 -0
- package/dist/acp/tempAcpRunner.js +263 -0
- package/dist/bin/cli.js +217 -0
- package/dist/index.js +1115 -0
- package/dist/messaging/telegramClient.js +109 -0
- package/dist/scheduler/cronScheduler.js +272 -0
- package/dist/scheduler/scheduledJobHandler.js +34 -0
- package/dist/utils/error.js +12 -0
- package/dist/utils/telegramMarkdown.js +128 -0
- package/ecosystem.config.json +23 -0
- package/index.ts +1272 -0
- package/messaging/telegramClient.ts +132 -0
- package/package.json +43 -0
- package/scheduler/cronScheduler.ts +355 -0
- package/scheduler/scheduledJobHandler.ts +55 -0
- package/scripts/callback-health.sh +6 -0
- package/scripts/callback-post-chat.sh +25 -0
- package/scripts/callback-post.sh +19 -0
- package/scripts/gemini-scheduler-examples.sh +162 -0
- package/scripts/test-scheduler.sh +78 -0
- package/tsconfig.json +23 -0
- package/utils/error.ts +12 -0
package/.env.example
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Telegram Token (required)
|
|
2
|
+
# Get this from @BotFather on Telegram
|
|
3
|
+
TELEGRAM_TOKEN=your_telegram_bot_token_here
|
|
4
|
+
|
|
5
|
+
# Typing indicator refresh interval in milliseconds (optional, default: 4000)
|
|
6
|
+
TYPING_INTERVAL_MS=4000
|
|
7
|
+
|
|
8
|
+
# Gemini command and mode options
|
|
9
|
+
GEMINI_COMMAND=gemini
|
|
10
|
+
# GEMINI_APPROVAL_MODE=yolo
|
|
11
|
+
# GEMINI_MODEL=
|
|
12
|
+
|
|
13
|
+
# How ACP permission options are auto-selected when requested by the agent.
|
|
14
|
+
# Supported: allow_once, reject_once, cancelled
|
|
15
|
+
ACP_PERMISSION_STRATEGY=allow_once
|
|
16
|
+
|
|
17
|
+
# Gemini overall timeout in milliseconds (optional, default: 900000)
|
|
18
|
+
GEMINI_TIMEOUT_MS=900000
|
|
19
|
+
|
|
20
|
+
# Gemini no-output timeout in milliseconds (optional, default: 60000)
|
|
21
|
+
# Set to 0 to disable idle-timeout behavior.
|
|
22
|
+
GEMINI_NO_OUTPUT_TIMEOUT_MS=60000
|
|
23
|
+
|
|
24
|
+
# Grace period before forcing SIGKILL after SIGTERM (optional, default: 5000)
|
|
25
|
+
GEMINI_KILL_GRACE_MS=5000
|
|
26
|
+
|
|
27
|
+
# Stream diagnostics
|
|
28
|
+
# ACP_STREAM_STDOUT=true writes raw ACP text chunks to stdout as they arrive
|
|
29
|
+
# ACP_DEBUG_STREAM=true writes structured chunk timing/count logs
|
|
30
|
+
ACP_STREAM_STDOUT=false
|
|
31
|
+
ACP_DEBUG_STREAM=false
|
|
32
|
+
|
|
33
|
+
# Maximum response length in characters (optional, default: 4000)
|
|
34
|
+
# Prevents memory issues with very long responses
|
|
35
|
+
# Telegram has a 4096 character limit per message anyway
|
|
36
|
+
MAX_RESPONSE_LENGTH=4000
|
|
37
|
+
|
|
38
|
+
# Local callback server: lets cron/jobs POST messages to Telegram directly
|
|
39
|
+
# Endpoint: POST http://localhost:8788/callback/telegram
|
|
40
|
+
CALLBACK_HOST=localhost
|
|
41
|
+
CALLBACK_PORT=8788
|
|
42
|
+
# Optional auth token, sent via x-callback-token or Authorization: Bearer <token>
|
|
43
|
+
CALLBACK_AUTH_TOKEN=
|
|
44
|
+
# Max accepted callback payload size in bytes
|
|
45
|
+
CALLBACK_MAX_BODY_BYTES=65536
|
|
46
|
+
|
|
47
|
+
# Persistent scheduler storage file (JSON)
|
|
48
|
+
SCHEDULES_FILE_PATH=~/.clawless/schedules.json
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hainan Zhao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# Quick Start Guide: Scheduler Feature
|
|
2
|
+
|
|
3
|
+
This guide will help you start using the scheduler feature in under 5 minutes.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
1. Clawless is installed and configured
|
|
8
|
+
2. You have sent at least one message to your bot (to establish chat binding)
|
|
9
|
+
3. The bridge is running (`npm run dev` or `npm start`)
|
|
10
|
+
|
|
11
|
+
## Basic Usage
|
|
12
|
+
|
|
13
|
+
### Talk to Gemini Naturally
|
|
14
|
+
|
|
15
|
+
The easiest way to use the scheduler is to just ask Gemini:
|
|
16
|
+
|
|
17
|
+
**Examples:**
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
You: "Remind me to take a break in 30 minutes"
|
|
21
|
+
|
|
22
|
+
You: "Check my calendar every morning at 9am and send me a summary"
|
|
23
|
+
|
|
24
|
+
You: "Every Friday at 5pm, remind me to review my weekly goals"
|
|
25
|
+
|
|
26
|
+
You: "What schedules do I have?"
|
|
27
|
+
|
|
28
|
+
You: "Cancel the daily calendar check"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Gemini will handle all the API calls automatically!
|
|
32
|
+
|
|
33
|
+
## Direct API Usage
|
|
34
|
+
|
|
35
|
+
### 1. Create a Recurring Schedule
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
curl -X POST http://127.0.0.1:8788/api/schedule \
|
|
39
|
+
-H "Content-Type: application/json" \
|
|
40
|
+
-d '{
|
|
41
|
+
"message": "What time is it?",
|
|
42
|
+
"description": "Time check",
|
|
43
|
+
"cronExpression": "0 9 * * *"
|
|
44
|
+
}'
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Response:**
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"ok": true,
|
|
51
|
+
"schedule": {
|
|
52
|
+
"id": "schedule_1707835800000_abc123",
|
|
53
|
+
"message": "What time is it?",
|
|
54
|
+
"description": "Time check",
|
|
55
|
+
"cronExpression": "0 9 * * *",
|
|
56
|
+
"oneTime": false,
|
|
57
|
+
"active": true,
|
|
58
|
+
"createdAt": "2026-02-13T10:00:00.000Z"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 2. Create a One-Time Schedule
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Schedule for 30 seconds from now
|
|
67
|
+
if ! RUN_AT=$(date -u -d "+30 seconds" +"%Y-%m-%dT%H:%M:%SZ" 2>/dev/null); then
|
|
68
|
+
# Fallback for macOS/BSD date
|
|
69
|
+
RUN_AT=$(date -u -v+30S +"%Y-%m-%dT%H:%M:%SZ")
|
|
70
|
+
fi
|
|
71
|
+
|
|
72
|
+
curl -X POST http://127.0.0.1:8788/api/schedule \
|
|
73
|
+
-H "Content-Type: application/json" \
|
|
74
|
+
-d "{
|
|
75
|
+
\"message\": \"Test reminder\",
|
|
76
|
+
\"oneTime\": true,
|
|
77
|
+
\"runAt\": \"${RUN_AT}\"
|
|
78
|
+
}"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 3. List All Schedules
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
curl http://127.0.0.1:8788/api/schedule | jq .
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 4. Delete a Schedule
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
curl -X DELETE http://127.0.0.1:8788/api/schedule/SCHEDULE_ID
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Common Cron Expressions
|
|
94
|
+
|
|
95
|
+
| Expression | Meaning |
|
|
96
|
+
|------------|---------|
|
|
97
|
+
| `0 9 * * *` | Every day at 9:00 AM |
|
|
98
|
+
| `0 */6 * * *` | Every 6 hours |
|
|
99
|
+
| `*/30 * * * *` | Every 30 minutes |
|
|
100
|
+
| `0 9 * * 1-5` | Weekdays at 9:00 AM |
|
|
101
|
+
| `0 17 * * 5` | Every Friday at 5:00 PM |
|
|
102
|
+
| `0 0 1 * *` | First day of month at midnight |
|
|
103
|
+
|
|
104
|
+
**Cron format:** `minute hour day month weekday`
|
|
105
|
+
|
|
106
|
+
## What Happens When a Job Runs?
|
|
107
|
+
|
|
108
|
+
1. **Scheduler triggers** at the scheduled time
|
|
109
|
+
2. **Message is sent** to a new Gemini CLI session
|
|
110
|
+
3. **Gemini processes** the message (can use tools, files, etc.)
|
|
111
|
+
4. **Response is sent** to your Telegram chat automatically
|
|
112
|
+
|
|
113
|
+
Example Telegram message you'll receive:
|
|
114
|
+
```
|
|
115
|
+
🔔 Scheduled task completed:
|
|
116
|
+
|
|
117
|
+
Daily calendar summary
|
|
118
|
+
|
|
119
|
+
Today's events:
|
|
120
|
+
- 9:00 AM: Team standup
|
|
121
|
+
- 2:00 PM: Project review
|
|
122
|
+
- 4:30 PM: 1-on-1 with manager
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Testing Your First Schedule
|
|
126
|
+
|
|
127
|
+
1. **Start the bridge:**
|
|
128
|
+
```bash
|
|
129
|
+
npm run dev
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
2. **Create a test schedule (runs in 30 seconds):**
|
|
133
|
+
```bash
|
|
134
|
+
if ! RUN_AT=$(date -u -d "+30 seconds" +"%Y-%m-%dT%H:%M:%SZ" 2>/dev/null); then
|
|
135
|
+
# Fallback for macOS/BSD date
|
|
136
|
+
RUN_AT=$(date -u -v+30S +"%Y-%m-%dT%H:%M:%SZ")
|
|
137
|
+
fi
|
|
138
|
+
|
|
139
|
+
curl -X POST http://127.0.0.1:8788/api/schedule \
|
|
140
|
+
-H "Content-Type: application/json" \
|
|
141
|
+
-d "{
|
|
142
|
+
\"message\": \"Hello! This is a test scheduled message.\",
|
|
143
|
+
\"description\": \"Test\",
|
|
144
|
+
\"oneTime\": true,
|
|
145
|
+
\"runAt\": \"${RUN_AT}\"
|
|
146
|
+
}"
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
3. **Wait 30 seconds** - You should receive a message in Telegram!
|
|
150
|
+
|
|
151
|
+
4. **Or ask Gemini directly:**
|
|
152
|
+
```
|
|
153
|
+
Send me a test message in 30 seconds
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## With Authentication
|
|
157
|
+
|
|
158
|
+
If you have `CALLBACK_AUTH_TOKEN` set in your config:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
curl -X POST http://127.0.0.1:8788/api/schedule \
|
|
162
|
+
-H "Content-Type: application/json" \
|
|
163
|
+
-H "x-callback-token: YOUR_TOKEN_HERE" \
|
|
164
|
+
-d '{
|
|
165
|
+
"message": "Test",
|
|
166
|
+
"cronExpression": "0 9 * * *"
|
|
167
|
+
}'
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Troubleshooting
|
|
171
|
+
|
|
172
|
+
### "No target chat available"
|
|
173
|
+
**Solution:** Send at least one message to your bot first.
|
|
174
|
+
|
|
175
|
+
### Schedule not executing
|
|
176
|
+
**Solution:**
|
|
177
|
+
- Check bridge logs for errors
|
|
178
|
+
- Verify cron expression is valid
|
|
179
|
+
- Ensure bridge is still running
|
|
180
|
+
|
|
181
|
+
### Can't reach API
|
|
182
|
+
**Solution:**
|
|
183
|
+
- Verify bridge is running: `curl http://127.0.0.1:8788/healthz`
|
|
184
|
+
- Check if port 8788 is available
|
|
185
|
+
- Look for errors in bridge logs
|
|
186
|
+
|
|
187
|
+
## Next Steps
|
|
188
|
+
|
|
189
|
+
- Read [SCHEDULER.md](SCHEDULER.md) for complete API documentation
|
|
190
|
+
- Read [TESTING.md](TESTING.md) for comprehensive testing guide
|
|
191
|
+
- Run `./scripts/test-scheduler.sh` for automated tests
|
|
192
|
+
- View `./scripts/gemini-scheduler-examples.sh` for more examples
|
|
193
|
+
|
|
194
|
+
## Pro Tips
|
|
195
|
+
|
|
196
|
+
1. **Descriptions matter**: Add clear descriptions to help you remember what each schedule does
|
|
197
|
+
2. **Test with one-time first**: Before setting up recurring jobs, test with a one-time schedule
|
|
198
|
+
3. **Use natural language**: Just ask Gemini - it's easier than curl commands!
|
|
199
|
+
4. **Check regularly**: Use "What schedules do I have?" to review active schedules
|
|
200
|
+
5. **Timezone aware**: Set `TZ` environment variable if needed (default is UTC)
|
|
201
|
+
|
|
202
|
+
## Example Workflows
|
|
203
|
+
|
|
204
|
+
### Daily Morning Routine
|
|
205
|
+
```
|
|
206
|
+
You: "Every morning at 7am, check my calendar and the weather, then send me a summary"
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Work Break Reminders
|
|
210
|
+
```
|
|
211
|
+
You: "Remind me to take a break every 2 hours during work days"
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Weekly Review
|
|
215
|
+
```
|
|
216
|
+
You: "Every Sunday at 6pm, remind me to plan my goals for next week"
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Custom Notifications
|
|
220
|
+
```
|
|
221
|
+
You: "Check if there are any urgent emails every 30 minutes and notify me if found"
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
That's it! You're ready to start scheduling with Clawless. 🎉
|
package/QUICKSTART.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Quick Start Guide
|
|
2
|
+
|
|
3
|
+
Get your Telegram-Gemini bridge running in 5 minutes!
|
|
4
|
+
|
|
5
|
+
## Prerequisites Checklist
|
|
6
|
+
|
|
7
|
+
- [ ] Node.js 18+ installed (`node --version`)
|
|
8
|
+
- [ ] Gemini CLI installed (`gemini --version`)
|
|
9
|
+
- [ ] Telegram bot token from [@BotFather](https://t.me/BotFather)
|
|
10
|
+
|
|
11
|
+
## Setup Steps
|
|
12
|
+
|
|
13
|
+
### 1. Install Dependencies
|
|
14
|
+
```bash
|
|
15
|
+
npm install
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### 2. Configure Environment
|
|
19
|
+
```bash
|
|
20
|
+
cp .env.example .env
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Edit `.env` and add your bot token:
|
|
24
|
+
```env
|
|
25
|
+
TELEGRAM_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 3. Test Gemini CLI
|
|
29
|
+
Verify Gemini CLI supports ACP:
|
|
30
|
+
```bash
|
|
31
|
+
gemini --protocol acp
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 4. Run the Bridge
|
|
35
|
+
|
|
36
|
+
**Quick test:**
|
|
37
|
+
```bash
|
|
38
|
+
npm start
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Development (auto-restart):**
|
|
42
|
+
```bash
|
|
43
|
+
npm run dev
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Production (with PM2):**
|
|
47
|
+
```bash
|
|
48
|
+
npm install -g pm2
|
|
49
|
+
pm2 start ecosystem.config.json
|
|
50
|
+
pm2 logs
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Verify It's Working
|
|
54
|
+
|
|
55
|
+
1. Open Telegram
|
|
56
|
+
2. Find your bot (search for the username you gave it)
|
|
57
|
+
3. Send a message: "Hello!"
|
|
58
|
+
4. You should see "🤔 Thinking..." followed by Gemini's response
|
|
59
|
+
|
|
60
|
+
## Common Issues
|
|
61
|
+
|
|
62
|
+
### "TELEGRAM_TOKEN is required"
|
|
63
|
+
- Check your `.env` file exists
|
|
64
|
+
- Verify the token is on the line `TELEGRAM_TOKEN=...`
|
|
65
|
+
- No quotes needed around the token
|
|
66
|
+
|
|
67
|
+
### "command not found: gemini"
|
|
68
|
+
- Install Gemini CLI first
|
|
69
|
+
- Verify with: `which gemini`
|
|
70
|
+
|
|
71
|
+
### Bot doesn't respond
|
|
72
|
+
- Check logs: `pm2 logs` (if using PM2)
|
|
73
|
+
- Or check console output
|
|
74
|
+
- Verify your bot token is correct
|
|
75
|
+
|
|
76
|
+
### Rate limit errors (429)
|
|
77
|
+
- Increase `UPDATE_INTERVAL_MS` in `.env` to 2000 or higher
|
|
78
|
+
- Restart the bot
|
|
79
|
+
|
|
80
|
+
## Next Steps
|
|
81
|
+
|
|
82
|
+
- Read the full [README.md](README.md) for detailed configuration
|
|
83
|
+
- Configure MCP servers for tool use
|
|
84
|
+
- Set up auto-start with PM2
|
|
85
|
+
|
|
86
|
+
## Getting Help
|
|
87
|
+
|
|
88
|
+
- Check [README.md](README.md) troubleshooting section
|
|
89
|
+
- Review Gemini CLI documentation
|
|
90
|
+
- Open an issue on GitHub
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
**Pro tip:** Keep the bridge running with PM2 and set it to auto-start on boot:
|
|
95
|
+
```bash
|
|
96
|
+
pm2 startup
|
|
97
|
+
pm2 save
|
|
98
|
+
```
|