summaryrefslogtreecommitdiffstats
path: root/AGENT_MODE.md
diff options
context:
space:
mode:
Diffstat (limited to 'AGENT_MODE.md')
-rw-r--r--AGENT_MODE.md271
1 files changed, 0 insertions, 271 deletions
diff --git a/AGENT_MODE.md b/AGENT_MODE.md
deleted file mode 100644
index 1f00d61..0000000
--- a/AGENT_MODE.md
+++ /dev/null
@@ -1,271 +0,0 @@
1# Ship Agent Mode
2
3**Goal:** Make ship the default deployment tool for AI agents building and shipping code.
4
5## Why Ship for Agents?
6
7Agents need to go from "code on disk" to "live URL" with zero friction. Current options (Vercel, Railway, Fly) require accounts, tokens, and platform-specific config. Ship only needs SSH access to a VPS.
8
9**Ship's advantages:**
10- SSH-only — no accounts, no API tokens, no vendor lock-in
11- Auto HTTPS via Caddy — agents don't deal with certs
12- Auto subdomains — `--name foo` → `foo.example.com`
13- Idempotent — same command updates existing deploy
14- Docker support — any runtime works
15- Stateless CLI — no daemon, no background process
16
17## Design Principles
18
191. **Machine-parseable output** — JSON by default in agent mode
202. **Fail loud and clear** — explicit error codes, not ambiguous messages
213. **Verify deploys** — health checks confirm the app is actually running
224. **Self-cleaning** — ephemeral deploys auto-expire
235. **One command** — no multi-step workflows
24
25## Agent Mode Flag
26
27```bash
28ship --agent [other flags]
29```
30
31When `--agent` is set:
32- Output is JSON (no need for separate `--json`)
33- Errors include machine-readable codes
34- Health checks are enabled by default
35- Progress is suppressed (no spinners, no "Uploading...")
36
37Alternatively, detect via environment:
38```bash
39SHIP_AGENT=1 ship --static --dir ./site --name preview
40```
41
42## Output Schema
43
44### Success
45
46```json
47{
48 "status": "ok",
49 "name": "preview",
50 "url": "https://preview.example.com",
51 "type": "static",
52 "took_ms": 4200,
53 "health": {
54 "checked": true,
55 "status": 200,
56 "latency_ms": 45
57 }
58}
59```
60
61### Error
62
63```json
64{
65 "status": "error",
66 "code": "DEPLOY_FAILED",
67 "message": "health check failed: connection refused",
68 "name": "preview",
69 "url": "https://preview.example.com",
70 "took_ms": 8500
71}
72```
73
74### Error Codes
75
76| Code | Meaning |
77|------|---------|
78| `SSH_CONNECT_FAILED` | Can't reach VPS |
79| `SSH_AUTH_FAILED` | Key rejected |
80| `UPLOAD_FAILED` | File transfer failed |
81| `BUILD_FAILED` | Docker build or binary issue |
82| `CADDY_RELOAD_FAILED` | HTTPS config failed |
83| `HEALTH_CHECK_FAILED` | App not responding after deploy |
84| `ALREADY_EXISTS` | Name collision (if --no-update) |
85| `NOT_FOUND` | App doesn't exist (for status/logs) |
86
87## Health Checks
88
89After deploy, ship pings the app to verify it's running.
90
91```bash
92ship --agent --static --dir ./site --name preview --health /
93ship --agent --binary ./api --name api --health /healthz
94```
95
96**Behavior:**
97- Wait up to 30s for first successful response
98- Retry every 2s
99- Accept any 2xx/3xx as success
100- Return `HEALTH_CHECK_FAILED` if timeout
101
102**Default health path:**
103- Static sites: `/` (just check 200)
104- Apps: none (opt-in with `--health`)
105
106## Ephemeral Deploys
107
108Agents create lots of previews. They should auto-clean.
109
110```bash
111ship --agent --static --dir ./site --name pr-123 --ttl 24h
112```
113
114**Implementation options:**
115
1161. **Server-side cron** — ship writes expiry to `/etc/ship/ttl/<name>` and a cron job cleans up
1172. **At-style scheduling** — `echo "ship remove pr-123" | at now + 24 hours`
1183. **Client-side tracking** — agent is responsible for cleanup (less ideal)
119
120Option 1 is cleanest. The TTL file contains:
121```
122expires_at=1708123456
123```
124
125A systemd timer runs hourly and removes expired deploys.
126
127## Unique Name Generation
128
129For true previews, agents may want auto-generated names:
130
131```bash
132ship --agent --static --dir ./site --preview
133```
134
135Output:
136```json
137{
138 "status": "ok",
139 "name": "ship-a1b2c3",
140 "url": "https://ship-a1b2c3.example.com",
141 ...
142}
143```
144
145Combines well with TTL:
146```bash
147ship --agent --static --dir ./site --preview --ttl 1h
148```
149
150## Simplified Deploy Command
151
152For maximum simplicity:
153
154```bash
155# Auto-detect: static site (has index.html) or Dockerfile
156ship --agent --dir ./myproject --preview --ttl 24h
157```
158
159Detection logic:
1601. Has `Dockerfile` → Docker build
1612. Has `index.html` or is static-looking → static site
1623. Has single binary → binary deploy
1634. Else → error with helpful message
164
165## Status & Logs
166
167```bash
168ship --agent status myapp
169```
170
171```json
172{
173 "status": "ok",
174 "name": "myapp",
175 "url": "https://myapp.example.com",
176 "type": "docker",
177 "running": true,
178 "uptime_seconds": 3600,
179 "memory_mb": 128,
180 "cpu_percent": 2.5
181}
182```
183
184```bash
185ship --agent logs myapp --lines 50
186```
187
188```json
189{
190 "status": "ok",
191 "name": "myapp",
192 "lines": [
193 {"ts": "2024-02-15T18:00:00Z", "msg": "Server started on :8080"},
194 ...
195 ]
196}
197```
198
199## List Deploys
200
201```bash
202ship --agent list
203```
204
205```json
206{
207 "status": "ok",
208 "deploys": [
209 {"name": "api", "url": "https://api.example.com", "type": "docker", "running": true},
210 {"name": "preview-abc", "url": "https://preview-abc.example.com", "type": "static", "ttl_expires": "2024-02-16T18:00:00Z"},
211 ...
212 ]
213}
214```
215
216## Environment Variables
217
218```bash
219ship --agent env set myapp DB_URL=postgres://...
220```
221
222```json
223{
224 "status": "ok",
225 "name": "myapp",
226 "action": "env_set",
227 "key": "DB_URL",
228 "restarted": true
229}
230```
231
232## Implementation Phases
233
234### Phase 1: Core Agent Mode
235- [ ] `--agent` flag for JSON output
236- [ ] Structured error codes
237- [ ] Health check support (`--health`)
238- [ ] Fix JSON output for all commands (list, status, logs, env)
239
240### Phase 2: Ephemeral & Previews
241- [ ] `--ttl` flag with server-side cleanup
242- [ ] `--preview` for auto-generated names
243- [ ] Auto-detection of project type
244
245### Phase 3: Polish
246- [ ] `ship --agent init` for first-time VPS setup with JSON output
247- [ ] Rollback support (`ship --agent rollback myapp`)
248- [ ] Deploy history (`ship --agent history myapp`)
249
250## Open Questions
251
2521. **Should `--agent` be the default eventually?** Human-readable output could move to `--human` or `--pretty`.
253
2542. **Log streaming?** Agents might want `ship logs --follow` with JSON lines. Worth it?
255
2563. **Webhooks?** Notify a URL on deploy success/failure. Useful for CI integration.
257
2584. **Multi-host?** Agents deploying to different VPSes. Current `--host` flag works but could be smoother.
259
260## Success Metrics
261
262Ship is successful for agents when:
263- Zero-config deploy from code to URL in <30s
264- Agent can parse every output without regex
265- Failed deploys have clear, actionable errors
266- Preview deploys don't accumulate garbage
267- Any language/framework works via Docker
268
269---
270
271*This is a living document. Update as we build.*