systemprompt-cli 0.2.1

Unified CLI for systemprompt.io AI governance: agent orchestration, MCP governance, analytics, profiles, cloud deploy, and self-hosted operations.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
<div align="center">
  <a href="https://systemprompt.io">
    <img src="https://systemprompt.io/logo.svg" alt="systemprompt.io" width="150" />
  </a>
  <p><strong>Production infrastructure for AI agents</strong></p>
  <p><a href="https://systemprompt.io">systemprompt.io</a><a href="https://systemprompt.io/documentation">Documentation</a><a href="https://github.com/systempromptio/systemprompt-core">Core</a><a href="https://github.com/systempromptio/systemprompt-template">Template</a></p>
</div>

---


# Services CLI Commands

This document provides complete documentation for AI agents to use the services CLI commands. All commands support non-interactive mode for automation.

---

## Prerequisites

```bash
export SYSTEMPROMPT_PROFILE=/var/www/html/tyingshoelaces/.systemprompt/profiles/local/profile.yaml
cd /var/www/html/systemprompt-core
cargo build --package systemprompt-cli

alias sp="./target/debug/systemprompt --non-interactive"
```

---

## Command Reference

| Command | Description | Artifact Type | Requires Services |
|---------|-------------|---------------|-------------------|
| `infra services start` | Start API, agents, and MCP servers | `Text` | No |
| `infra services stop` | Stop running services gracefully | `Text` | No |
| `infra services restart` | Restart services | `Text` | Yes |
| `infra services status` | Show detailed service status | `Table` | No |
| `infra services cleanup` | Clean up orphaned processes | `Text` | No |
| `infra services serve` | Start API server (with agents/MCP) | `Text` | No |

---

## Core Commands

### services start

Start API server, agents, and MCP servers.

```bash
sp infra services start
sp infra services start --all
sp infra services start --api
sp infra services start --agents
sp infra services start --mcp
sp infra services start --skip-web
sp infra services start --skip-migrate
```

**Optional Flags:**
| Flag | Default | Description |
|------|---------|-------------|
| `--all` | `true` | Start all services |
| `--api` | `false` | Start API server only |
| `--agents` | `false` | Start agents only |
| `--mcp` | `false` | Start MCP servers only |
| `--foreground` | `true` | Run in foreground |
| `--skip-web` | `false` | Skip web asset build |
| `--skip-migrate` | `false` | Skip database migrations |

**Service Startup Order:**
1. Database migrations (unless skipped)
2. Web asset build (unless skipped)
3. MCP servers
4. Agent processes
5. API server

**Output Structure:**
```json
{
  "started": true,
  "services": {
    "api": {"status": "running", "port": 8080, "pid": 12345},
    "agents": [
      {"name": "primary", "status": "running", "port": 8001, "pid": 12346}
    ],
    "mcp": [
      {"name": "filesystem", "status": "running", "port": 9001, "pid": 12347}
    ]
  },
  "message": "All services started successfully"
}
```

**Artifact Type:** `Text`

---

### services stop

Stop running services gracefully.

```bash
sp infra services stop
sp infra services stop --all
sp infra services stop --api
sp infra services stop --agents
sp infra services stop --mcp
sp infra services stop --force
```

**Optional Flags:**
| Flag | Default | Description |
|------|---------|-------------|
| `--all` | `true` | Stop all services |
| `--api` | `false` | Stop API server only |
| `--agents` | `false` | Stop agents only |
| `--mcp` | `false` | Stop MCP servers only |
| `--force` | `false` | Force stop (SIGKILL) |

**Stop Order:**
1. API server
2. Agent processes
3. MCP servers

**Output Structure:**
```json
{
  "stopped": true,
  "services": {
    "api": {"status": "stopped"},
    "agents": [{"name": "primary", "status": "stopped"}],
    "mcp": [{"name": "filesystem", "status": "stopped"}]
  },
  "message": "All services stopped successfully"
}
```

**Artifact Type:** `Text`

---

### services restart

Restart services.

```bash
sp infra services restart api
sp infra services restart agent primary
sp infra services restart mcp filesystem
sp infra services restart --failed
```

**Subcommands:**
| Subcommand | Description |
|------------|-------------|
| `api` | Restart API server |
| `agent <name>` | Restart specific agent |
| `plugins mcp <name>` | Restart specific MCP server |

**Optional Flags:**
| Flag | Default | Description |
|------|---------|-------------|
| `--failed` | `false` | Restart only failed services |

**Output Structure:**
```json
{
  "restarted": ["primary"],
  "message": "Service 'primary' restarted successfully"
}
```

**Artifact Type:** `Text`

---

### services status

Show detailed service status.

```bash
sp infra services status
sp --json services status
sp infra services status --detailed
sp infra services status --health
```

**Optional Flags:**
| Flag | Default | Description |
|------|---------|-------------|
| `--detailed` | `false` | Show detailed information |
| `--json` | `false` | Output as JSON |
| `--health` | `false` | Include health check results |

**Output Structure:**
```json
{
  "api": {
    "status": "running",
    "port": 8080,
    "pid": 12345,
    "uptime_seconds": 3600,
    "health": "healthy"
  },
  "agents": [
    {
      "name": "primary",
      "status": "running",
      "port": 8001,
      "pid": 12346,
      "enabled": true,
      "health": "healthy"
    }
  ],
  "mcp_servers": [
    {
      "name": "filesystem",
      "status": "running",
      "port": 9001,
      "pid": 12347,
      "enabled": true,
      "health": "healthy"
    }
  ],
  "summary": {
    "total_services": 5,
    "running": 5,
    "stopped": 0,
    "failed": 0
  }
}
```

**Artifact Type:** `Table`
**Columns:** `name`, `type`, `status`, `port`, `pid`, `health`

---

### services cleanup

Clean up orphaned processes and stale entries.

```bash
sp infra services cleanup              # Interactive mode prompts for confirmation
sp infra services cleanup --yes        # Skip confirmation
sp infra services cleanup --dry-run    # Preview what would be cleaned
sp --json services cleanup --yes
```

**Optional Flags:**
| Flag | Default | Description |
|------|---------|-------------|
| `--yes` / `-y` | `false` | Skip confirmation prompt |
| `--dry-run` | `false` | Preview cleanup without executing |

**Cleanup Actions:**
- Terminate orphaned processes
- Remove stale PID files
- Clean up temporary files
- Reset service state

**Output Structure:**
```json
{
  "cleaned": true,
  "processes_killed": 2,
  "pid_files_removed": 3,
  "temp_files_removed": 5,
  "message": "Cleanup completed successfully"
}
```

**Artifact Type:** `Text`

---

### services serve

Start API server with automatic agent and MCP startup.

```bash
sp infra services serve
sp infra services serve --foreground
sp infra services serve --kill-port-process
```

**Optional Flags:**
| Flag | Default | Description |
|------|---------|-------------|
| `--foreground` | `false` | Run in foreground mode |
| `--kill-port-process` | `false` | Kill process using the port if occupied |

**Output Structure:**
```json
{
  "started": true,
  "api_port": 8080,
  "url": "http://localhost:8080",
  "message": "API server started at http://localhost:8080"
}
```

**Artifact Type:** `Text`

---

## Complete Services Workflow Example

This flow demonstrates managing services:

```bash
# Phase 1: Check current status
sp --json services status

# Phase 2: Start all services
sp infra services start

# Phase 3: Verify status
sp --json services status --health

# Phase 4: Check specific service
sp --json services status | jq '.agents[] | select(.name == "primary")'

# Phase 5: Restart failed services
sp infra services restart --failed

# Phase 6: Stop all services
sp infra services stop

# Phase 7: Cleanup
sp infra services cleanup
```

---

## Development Workflow

```bash
# Start with skip options for faster iteration
sp infra services start --skip-migrate

# Restart specific agent after code changes
sp infra services restart agent primary

# Force restart if hanging
sp infra services stop --force
sp infra services start
```

---

## Production Workflow

```bash
# Full startup with migrations and build
sp infra services start

# Health check
sp --json services status --health

# Graceful restart
sp infra services stop
sp infra services start

# Monitor status
watch -n 5 'sp --json services status | jq .summary'
```

---

## Service Configuration

Services are configured in `services.yaml`:

```yaml
api:
  port: 8080
  host: "0.0.0.0"

agents:
  primary:
    enabled: true
    port: 8001
    provider: anthropic
    model: claude-3-5-sonnet-20241022

mcp_servers:
  filesystem:
    enabled: true
    port: 9001
    command: "./target/debug/mcp-filesystem"
```

---

## Error Handling

### Port Already in Use

```bash
sp infra services start
# Error: Port 8080 is already in use. Use --kill-port-process to terminate existing process.

sp infra services serve --kill-port-process
# Killed process on port 8080, starting server...
```

### Service Already Running

```bash
sp infra services start --api
# Warning: API server is already running on port 8080

sp infra services status
# Shows current running services
```

### Database Connection Error

```bash
sp infra services start
# Error: Failed to connect to database. Check your profile configuration.
```

### Target Required

```bash
sp infra services restart
# Error: Must specify target (api, agent, mcp) or use --failed flag
```

---

## JSON Output

All commands support `--json` flag for structured output:

```bash
# Verify JSON is valid
sp --json services status | jq .

# Extract specific fields
sp --json services status | jq '.api.port'
sp --json services status | jq '.agents[].name'
sp --json services status | jq '.summary'

# Check running services
sp --json services status | jq '.agents[] | select(.status == "running")'

# Get health status
sp --json services status --health | jq '.agents[] | {name, health}'
```

---

## Compliance Checklist

- [x] All `execute` functions accept `config: &CliConfig`
- [x] All commands return `CommandResult<T>` with proper artifact type
- [x] All output types derive `Serialize`, `Deserialize`, `JsonSchema`
- [x] No `println!` / `eprintln!` - uses `CliService`
- [x] No `unwrap()` / `expect()` - uses `?` with `.context()`
- [x] JSON output supported via `--json` flag
- [x] Graceful shutdown handling


---

## License

Business Source License 1.1 - See [LICENSE](https://github.com/systempromptio/systemprompt-core/blob/main/LICENSE) for details.