@gracefultools/astrid-sdk 0.4.2 → 0.6.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/README.md CHANGED
@@ -5,30 +5,171 @@ AI agent SDK for automated coding tasks with Claude, OpenAI, and Gemini.
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @gracefultools/astrid-sdk
8
+ npm install -g @gracefultools/astrid-sdk
9
9
  ```
10
10
 
11
11
  ## Quick Start
12
12
 
13
- ### CLI Usage
13
+ ### Three Execution Modes
14
14
 
15
- Run the agent worker to poll for tasks:
15
+ | Mode | Command | Best For |
16
+ |------|---------|----------|
17
+ | **API** | `npx astrid-agent` | Cloud execution via Claude Agent SDK API |
18
+ | **Terminal** | `npx astrid-agent --terminal` | Local Claude Code CLI (remote control) |
19
+ | **Webhook** | `npx astrid-agent serve` | Always-on servers (fly.io, VPS, AWS) |
20
+
21
+ ### Terminal Mode (Remote Control Your Local Claude Code)
22
+
23
+ Uses your local Claude Code CLI to process tasks. Enables remote control of your local Claude Code from Astrid.
16
24
 
17
25
  ```bash
18
- # Set up environment variables
26
+ # Prerequisites: Install Claude Code CLI
27
+ npm install -g @anthropic-ai/claude-code
28
+
29
+ # Set up environment
30
+ export ANTHROPIC_API_KEY=sk-ant-...
19
31
  export ASTRID_OAUTH_CLIENT_ID=your_client_id
20
32
  export ASTRID_OAUTH_CLIENT_SECRET=your_client_secret
21
33
  export ASTRID_OAUTH_LIST_ID=your_list_id
22
- export ANTHROPIC_API_KEY=sk-ant-... # For Claude
23
34
 
24
- # Start the worker
35
+ # Start in terminal mode
36
+ cd /your/project
37
+ npx astrid-agent --terminal
38
+
39
+ # With options
40
+ npx astrid-agent --terminal --model=sonnet --cwd=/path/to/project --max-turns=100
41
+
42
+ # Or via environment variable
43
+ ASTRID_TERMINAL_MODE=true npx astrid-agent
44
+ ```
45
+
46
+ **How it works:**
47
+ 1. Agent polls Astrid for tasks assigned to AI agents
48
+ 2. When a task is found, it spawns the local Claude Code CLI with `--print`
49
+ 3. Claude Code executes in your project directory
50
+ 4. Results are posted back to Astrid as comments
51
+ 5. Session IDs are stored for resumption support
52
+
53
+ ### API Mode (Default)
54
+
55
+ Uses Claude Agent SDK API for cloud execution. Best for CI/CD and servers.
56
+
57
+ ```bash
58
+ # Set up environment
59
+ export ANTHROPIC_API_KEY=sk-ant-...
60
+ export ASTRID_OAUTH_CLIENT_ID=your_client_id
61
+ export ASTRID_OAUTH_CLIENT_SECRET=your_client_secret
62
+ export ASTRID_OAUTH_LIST_ID=your_list_id
63
+
64
+ # Start polling for tasks (API mode)
25
65
  npx astrid-agent
66
+ ```
26
67
 
27
- # Or process a specific task
28
- npx astrid-agent <taskId>
68
+ ### Webhook Mode (For Always-On Servers)
69
+
70
+ Receives instant task notifications via webhook. Requires a permanent IP or domain.
71
+
72
+ ```bash
73
+ # Set up environment
74
+ export ANTHROPIC_API_KEY=sk-ant-...
75
+ export ASTRID_WEBHOOK_SECRET=your_webhook_secret
76
+
77
+ # Start webhook server
78
+ npx astrid-agent serve --port=3001
79
+
80
+ # Optional: Install express for the server
81
+ npm install express
82
+ ```
83
+
84
+ Then configure your webhook URL in Astrid Settings.
85
+
86
+ ## Environment Variables
87
+
88
+ | Variable | Mode | Description |
89
+ |----------|------|-------------|
90
+ | **AI Providers** | All | |
91
+ | `ANTHROPIC_API_KEY` | All | Anthropic API key (for Claude) |
92
+ | `OPENAI_API_KEY` | All | OpenAI API key |
93
+ | `GEMINI_API_KEY` | All | Google Gemini API key |
94
+ | **Polling/Terminal Mode** | Polling, Terminal | |
95
+ | `ASTRID_OAUTH_CLIENT_ID` | Polling, Terminal | OAuth client ID from Astrid |
96
+ | `ASTRID_OAUTH_CLIENT_SECRET` | Polling, Terminal | OAuth client secret |
97
+ | `ASTRID_OAUTH_LIST_ID` | Polling, Terminal | List ID to monitor for tasks |
98
+ | **Terminal Mode** | Terminal | |
99
+ | `ASTRID_TERMINAL_MODE` | Terminal | Enable terminal mode (or use --terminal flag) |
100
+ | `CLAUDE_MODEL` | Terminal | Model to use (default: opus) |
101
+ | `CLAUDE_MAX_TURNS` | Terminal | Max turns per execution (default: 50) |
102
+ | `DEFAULT_PROJECT_PATH` | Terminal | Project directory (default: current dir) |
103
+ | **Webhook Mode** | Webhook | |
104
+ | `ASTRID_WEBHOOK_SECRET` | Webhook | Secret from Astrid webhook settings |
105
+ | `ASTRID_CALLBACK_URL` | Webhook | Optional callback URL |
106
+ | **Other** | All | |
107
+ | `GITHUB_TOKEN` | All | GitHub token for cloning private repos |
108
+ | `POLL_INTERVAL_MS` | Polling, Terminal | Poll interval (default: 30000) |
109
+ | `MAX_BUDGET_USD` | API | Max budget per task (default: 10.0) |
110
+
111
+ ## Supported AI Providers
112
+
113
+ The SDK automatically routes tasks to the correct provider based on the assignee email:
114
+
115
+ | Agent Email | Provider | Model |
116
+ |-------------|----------|-------|
117
+ | `claude@astrid.cc` | Claude | claude-sonnet-4 |
118
+ | `openai@astrid.cc` | OpenAI | gpt-4o |
119
+ | `gemini@astrid.cc` | Gemini | gemini-2.0-flash |
120
+
121
+ ## Deployment Examples
122
+
123
+ ### Fly.io (Webhook Mode)
124
+
125
+ ```toml
126
+ # fly.toml
127
+ app = "astrid-agent"
128
+ primary_region = "iad"
129
+
130
+ [http_service]
131
+ internal_port = 3001
132
+
133
+ [env]
134
+ PORT = "3001"
135
+ ```
136
+
137
+ ```bash
138
+ fly secrets set ANTHROPIC_API_KEY=sk-ant-...
139
+ fly secrets set ASTRID_WEBHOOK_SECRET=...
140
+ fly deploy
141
+ ```
142
+
143
+ ### Docker (Webhook Mode)
144
+
145
+ ```dockerfile
146
+ FROM node:20-slim
147
+ RUN npm install -g @gracefultools/astrid-sdk express
148
+ WORKDIR /app
149
+ EXPOSE 3001
150
+ CMD ["npx", "astrid-agent", "serve", "--port=3001"]
29
151
  ```
30
152
 
31
- ### Programmatic Usage
153
+ ### PM2 (Polling Mode)
154
+
155
+ ```bash
156
+ # ecosystem.config.js
157
+ module.exports = {
158
+ apps: [{
159
+ name: 'astrid-agent',
160
+ script: 'npx',
161
+ args: 'astrid-agent',
162
+ env: {
163
+ ANTHROPIC_API_KEY: 'sk-ant-...',
164
+ ASTRID_OAUTH_CLIENT_ID: '...',
165
+ ASTRID_OAUTH_CLIENT_SECRET: '...',
166
+ ASTRID_OAUTH_LIST_ID: '...'
167
+ }
168
+ }]
169
+ }
170
+ ```
171
+
172
+ ## Programmatic Usage
32
173
 
33
174
  ```typescript
34
175
  import {
@@ -72,81 +213,45 @@ if (planResult.success && planResult.plan) {
72
213
  }
73
214
  ```
74
215
 
75
- ## Environment Variables
76
-
77
- | Variable | Required | Description |
78
- |----------|----------|-------------|
79
- | `ASTRID_OAUTH_CLIENT_ID` | Yes | OAuth client ID from Astrid |
80
- | `ASTRID_OAUTH_CLIENT_SECRET` | Yes | OAuth client secret |
81
- | `ASTRID_OAUTH_LIST_ID` | Yes | List ID to monitor for tasks |
82
- | `ANTHROPIC_API_KEY` | For Claude | Anthropic API key |
83
- | `OPENAI_API_KEY` | For OpenAI | OpenAI API key |
84
- | `GEMINI_API_KEY` | For Gemini | Google Gemini API key |
85
- | `GITHUB_TOKEN` | For repos | GitHub token for cloning |
86
- | `POLL_INTERVAL_MS` | No | Poll interval (default: 30000) |
87
- | `MAX_BUDGET_USD` | No | Max budget per task (default: 10.0) |
88
-
89
- ## AI Providers
90
-
91
- The SDK supports three AI providers:
92
-
93
- ### Claude (Recommended)
94
-
95
- Uses the Claude Agent SDK for native tool use:
96
- - Best code quality
97
- - Native file editing
98
- - Real test execution
99
-
100
- ```typescript
101
- import { planWithClaude, executeWithClaude } from '@gracefultools/astrid-sdk'
102
- ```
103
-
104
- ### OpenAI
216
+ ## CLI Reference
105
217
 
106
- Uses GPT-4 with function calling:
218
+ ```bash
219
+ # Show help
220
+ npx astrid-agent --help
107
221
 
108
- ```typescript
109
- import { planWithOpenAI, executeWithOpenAI } from '@gracefultools/astrid-sdk'
110
- ```
222
+ # API mode (default - cloud execution)
223
+ npx astrid-agent
111
224
 
112
- ### Gemini
225
+ # Terminal mode (local Claude Code CLI)
226
+ npx astrid-agent --terminal
227
+ npx astrid-agent --terminal --model=sonnet --cwd=/path/to/project
113
228
 
114
- Uses Gemini with function calling:
229
+ # Process a specific task
230
+ npx astrid-agent <taskId>
231
+ npx astrid-agent --terminal <taskId>
115
232
 
116
- ```typescript
117
- import { planWithGemini, executeWithGemini } from '@gracefultools/astrid-sdk'
233
+ # Webhook mode
234
+ npx astrid-agent serve --port=3001
118
235
  ```
119
236
 
120
- ## Astrid OAuth Client
121
-
122
- The SDK includes a client for the Astrid OAuth API:
123
-
124
- ```typescript
125
- import { AstridOAuthClient } from '@gracefultools/astrid-sdk'
126
-
127
- const client = new AstridOAuthClient()
128
-
129
- // Get lists
130
- const lists = await client.getLists()
131
-
132
- // Get tasks
133
- const tasks = await client.getTasks(listId)
134
-
135
- // Get a specific task
136
- const task = await client.getTask(taskId)
237
+ ## Comparison: Terminal vs API vs Webhook
137
238
 
138
- // Add a comment
139
- await client.addComment(taskId, 'Work in progress...')
140
-
141
- // Complete a task
142
- await client.completeTask(taskId)
143
- ```
239
+ | Feature | Terminal | API | Webhook |
240
+ |---------|----------|-----|---------|
241
+ | Execution | Local CLI | Cloud API | Cloud API |
242
+ | Requires Claude Code CLI | Yes | No | No |
243
+ | Permanent IP needed | No | No | Yes |
244
+ | Works behind NAT | Yes | Yes | No |
245
+ | Session resume | Yes | No | No |
246
+ | Task notification | ~30s poll | ~30s poll | Instant |
247
+ | Best for | Local dev | CI/CD, servers | Always-on servers |
248
+ | Project access | Local files | Clones repo | Clones repo |
144
249
 
145
- ## Keeping Updated
250
+ ## Updating
146
251
 
147
252
  ```bash
148
253
  # Update to latest version
149
- npm update @gracefultools/astrid-sdk
254
+ npm update -g @gracefultools/astrid-sdk
150
255
  ```
151
256
 
152
257
  ## License
package/dist/bin/cli.d.ts CHANGED
@@ -5,7 +5,8 @@
5
5
  * Command-line interface for running the Astrid AI agent worker
6
6
  *
7
7
  * Usage:
8
- * npx astrid-agent # Start polling for tasks
8
+ * npx astrid-agent # Start polling for tasks (API mode)
9
+ * npx astrid-agent --terminal # Start polling using local Claude Code CLI
9
10
  * npx astrid-agent <taskId> # Process a specific task
10
11
  * npx astrid-agent --help # Show help
11
12
  */
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/bin/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;GASG"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/bin/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;GAUG"}