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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
<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>

---


# Jobs CLI Commands

This document provides complete documentation for AI agents to use the jobs 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 |
|---------|-------------|---------------|
| `infra jobs list` | List available scheduled jobs | `Table` |
| `infra jobs show <name>` | Show detailed job information | `PresentationCard` |
| `infra jobs run <name...>` | Run job(s) manually | `Table` |
| `infra jobs run --all` | Run all enabled jobs | `Table` |
| `infra jobs history` | View job execution history | `Table` |
| `infra jobs enable <name>` | Enable a job | `Text` |
| `infra jobs disable <name>` | Disable a job | `Text` |
| `infra jobs cleanup-sessions` | Clean up inactive sessions | `Text` |
| `infra jobs log-cleanup` | Clean up old log entries | `Text` |

---

## Core Commands

### jobs list

List all available scheduled jobs from the registry.

```bash
sp infra jobs list
sp --json jobs list
```

**Output Structure:**
```json
{
  "data": {
    "jobs": [
      {
        "name": "content_ingestion",
        "description": "Ingests markdown content from configured directories",
        "schedule": "0 0 * * * *",
        "enabled": true
      }
    ],
    "total": 10
  },
  "artifact_type": "table",
  "title": "Available Jobs"
}
```

---

### jobs show

Show detailed information about a specific job.

```bash
sp infra jobs show content_ingestion
sp --json jobs show database_cleanup
```

**Output Structure:**
```json
{
  "data": {
    "name": "content_ingestion",
    "description": "Ingests markdown content from configured directories",
    "schedule": "0 0 * * * *",
    "schedule_human": "Every hour",
    "enabled": true,
    "last_run": "2026-01-14T10:00:00Z",
    "next_run": "2026-01-14T11:00:00Z",
    "last_status": "success",
    "last_error": null,
    "run_count": 42
  },
  "artifact_type": "presentation_card",
  "title": "Job: content_ingestion"
}
```

---

### jobs run

Run one or more scheduled jobs manually.

```bash
# Run a single job
sp infra jobs run content_ingestion

# Run multiple jobs
sp infra jobs run content_ingestion publish_content database_cleanup

# Run all enabled jobs
sp infra jobs run --all
```

**Arguments & Flags:**
| Argument/Flag | Description |
|---------------|-------------|
| `<name...>` | Job name(s) to run |
| `--all` | Run all enabled jobs |
| `--sequential` | Run jobs one at a time (default: parallel) |

**Output Structure:**
```json
{
  "data": {
    "jobs_run": [
      {
        "job_name": "content_ingestion",
        "status": "success",
        "duration_ms": 64,
        "result": {
          "success": true,
          "message": "Ingested 31 files",
          "items_processed": 31,
          "items_failed": 0
        }
      }
    ],
    "total": 1,
    "succeeded": 1,
    "failed": 0
  },
  "artifact_type": "table",
  "title": "Job Execution Results"
}
```

---

### jobs history

View job execution history.

```bash
sp infra jobs history
sp infra jobs history --job content_ingestion
sp infra jobs history --status failed
sp infra jobs history -n 50
```

**Flags:**
| Flag | Default | Description |
|------|---------|-------------|
| `--job` | | Filter by job name |
| `--status` | | Filter by status (success, failed, running) |
| `-n, --limit` | `20` | Number of entries to show |

**Output Structure:**
```json
{
  "data": {
    "entries": [
      {
        "job_name": "publish_content",
        "status": "success",
        "run_at": "2026-01-14T10:30:02Z",
        "error": null
      }
    ],
    "total": 5
  },
  "artifact_type": "table",
  "title": "Job Execution History"
}
```

---

### jobs enable / disable

Enable or disable a job.

```bash
sp infra jobs enable behavioral_analysis
sp infra jobs disable behavioral_analysis
```

**Output Structure:**
```json
{
  "data": {
    "job_name": "behavioral_analysis",
    "enabled": true,
    "message": "Job 'behavioral_analysis' has been enabled"
  },
  "artifact_type": "text",
  "title": "Job Enabled"
}
```

---

### jobs cleanup-sessions

Clean up inactive user sessions.

```bash
sp infra jobs cleanup-sessions
sp infra jobs cleanup-sessions --hours 2
sp infra jobs cleanup-sessions --dry-run
```

**Flags:**
| Flag | Default | Description |
|------|---------|-------------|
| `--hours` | `1` | Sessions inactive for more than N hours |
| `--dry-run` | | Preview without executing |

**Output Structure:**
```json
{
  "data": {
    "job_name": "session_cleanup",
    "sessions_cleaned": 15,
    "hours_threshold": 1,
    "message": "Cleaned up 15 inactive session(s)"
  },
  "artifact_type": "text",
  "title": "Session Cleanup"
}
```

---

### jobs log-cleanup

Clean up old log entries.

```bash
sp infra jobs log-cleanup
sp infra jobs log-cleanup --days 7
sp infra jobs log-cleanup --days 7 --dry-run
```

**Flags:**
| Flag | Default | Description |
|------|---------|-------------|
| `--days` | `30` | Delete logs older than N days |
| `--dry-run` | | Preview without executing |

**Output Structure:**
```json
{
  "data": {
    "job_name": "log_cleanup",
    "entries_deleted": 5000,
    "days_threshold": 30,
    "message": "Deleted 5000 log entries older than 30 days"
  },
  "artifact_type": "text",
  "title": "Log Cleanup"
}
```

---

## Creating a New Job

Jobs are registered at compile-time using the `inventory` crate. To create a new job:

### Step 1: Create the Job File

Create a new file in your extension or domain crate:

```
/var/www/html/tyingshoelaces/extensions/blog/src/jobs/my_job.rs
```

### Step 2: Implement the Job Trait

```rust
use anyhow::Result;
use async_trait::async_trait;
use std::sync::Arc;
use systemprompt_core_database::DbPool;
use systemprompt_traits::{Job, JobContext, JobResult};
use tracing::info;

/// My custom job that does something useful
#[derive(Debug, Clone, Copy)]
pub struct MyCustomJob;

#[async_trait]
impl Job for MyCustomJob {
    /// Unique job identifier (used in CLI commands)
    fn name(&self) -> &'static str {
        "my_custom_job"
    }

    /// Human-readable description
    fn description(&self) -> &'static str {
        "Does something useful on a schedule"
    }

    /// Cron schedule (6 fields: sec min hour day month weekday)
    fn schedule(&self) -> &'static str {
        "0 */15 * * * *"  // Every 15 minutes
    }

    /// Whether this job is enabled by default
    fn enabled(&self) -> bool {
        true
    }

    /// The actual job logic
    async fn execute(&self, ctx: &JobContext) -> Result<JobResult> {
        let start = std::time::Instant::now();

        // Extract database pool from context
        let db_pool = Arc::clone(
            ctx.db_pool::<DbPool>()
                .ok_or_else(|| anyhow::anyhow!("DbPool not available"))?
        );

        info!("my_custom_job started");

        // Do your work here
        let processed = do_the_work(&db_pool).await?;

        let duration_ms = start.elapsed().as_millis() as u64;

        info!(
            processed = processed,
            duration_ms = duration_ms,
            "my_custom_job completed"
        );

        // Return result with stats
        Ok(JobResult::success()
            .with_message(format!("Processed {} items", processed))
            .with_stats(processed, 0)
            .with_duration(duration_ms))
    }
}

async fn do_the_work(pool: &DbPool) -> Result<u64> {
    // Your implementation here
    Ok(42)
}

// CRITICAL: Register the job with inventory
systemprompt_traits::submit_job!(&MyCustomJob);
```

### Step 3: Export from Module

In your `jobs/mod.rs`:

```rust
mod my_job;

pub use my_job::MyCustomJob;
```

### Step 4: Include in Crate

Ensure the jobs module is included in your crate's `lib.rs`:

```rust
pub mod jobs;
```

### Step 5: Link to CLI

The job will automatically appear in `infra jobs list` after rebuilding, as long as the crate is linked to the CLI binary. For extensions, this happens through the generator crate dependency.

---

## Job Trait Reference

```rust
#[async_trait]
pub trait Job: Send + Sync + 'static {
    /// Unique identifier for the job
    fn name(&self) -> &'static str;

    /// Human-readable description (optional, defaults to "")
    fn description(&self) -> &'static str { "" }

    /// Cron schedule expression (6 fields)
    fn schedule(&self) -> &'static str;

    /// Execute the job
    async fn execute(&self, ctx: &JobContext) -> Result<JobResult>;

    /// Whether the job is enabled (optional, defaults to true)
    fn enabled(&self) -> bool { true }
}
```

---

## JobResult Builder

```rust
// Success with message
JobResult::success()
    .with_message("Completed successfully")

// Success with stats
JobResult::success()
    .with_stats(100, 5)  // processed, failed
    .with_duration(1500) // milliseconds

// Failure
JobResult::failure("Database connection failed")
```

---

## Cron Schedule Format

The schedule uses 6-field cron syntax:

```
┌──────────── second (0-59)
│ ┌────────── minute (0-59)
│ │ ┌──────── hour (0-23)
│ │ │ ┌────── day of month (1-31)
│ │ │ │ ┌──── month (1-12)
│ │ │ │ │ ┌── day of week (0-6, Sun=0)
│ │ │ │ │ │
* * * * * *
```

**Common Schedules:**
| Schedule | Description |
|----------|-------------|
| `0 0 * * * *` | Every hour |
| `0 */15 * * * *` | Every 15 minutes |
| `0 */30 * * * *` | Every 30 minutes |
| `0 0 */2 * * *` | Every 2 hours |
| `0 0 3 * * *` | Daily at 3:00 AM |
| `0 30 2 * * *` | Daily at 2:30 AM |
| `0 0 0 * * 0` | Weekly on Sunday at midnight |
| `0 0 0 1 * *` | Monthly on the 1st at midnight |

---

## Example: Blog Extension Job

Location: `/var/www/html/tyingshoelaces/extensions/blog/src/jobs/`

```rust
// blog_content_ingestion.rs
use anyhow::Result;
use async_trait::async_trait;
use std::sync::Arc;
use systemprompt_core_database::DbPool;
use systemprompt_traits::{Job, JobContext, JobResult};

#[derive(Debug, Clone, Copy)]
pub struct BlogContentIngestionJob;

#[async_trait]
impl Job for BlogContentIngestionJob {
    fn name(&self) -> &'static str {
        "blog_content_ingestion"
    }

    fn description(&self) -> &'static str {
        "Ingests blog posts from markdown files"
    }

    fn schedule(&self) -> &'static str {
        "0 0 * * * *"  // Every hour
    }

    async fn execute(&self, ctx: &JobContext) -> Result<JobResult> {
        let start = std::time::Instant::now();
        let db_pool = Arc::clone(
            ctx.db_pool::<DbPool>()
                .ok_or_else(|| anyhow::anyhow!("DbPool not available"))?
        );

        // Ingest blog content...
        let posts_ingested = ingest_blog_posts(&db_pool).await?;

        Ok(JobResult::success()
            .with_stats(posts_ingested, 0)
            .with_duration(start.elapsed().as_millis() as u64))
    }
}

systemprompt_traits::submit_job!(&BlogContentIngestionJob);
```

---

## Workflow Examples

### Development Workflow

```bash
# List all jobs
sp --json jobs list | jq '.data.jobs[].name'

# Check job details before running
sp infra jobs show content_ingestion

# Preview cleanup without executing
sp infra jobs cleanup-sessions --dry-run
sp infra jobs log-cleanup --days 7 --dry-run

# Run the job
sp infra jobs run content_ingestion

# Check execution history
sp --json jobs history --job content_ingestion
```

### Maintenance Workflow

```bash
# Run all maintenance jobs
sp infra jobs run cleanup_inactive_sessions cleanup_empty_contexts database_cleanup

# Or run everything
sp infra jobs run --all

# Check results
sp --json jobs history -n 10
```

### Disable/Enable Workflow

```bash
# Temporarily disable a job
sp infra jobs disable behavioral_analysis

# Re-enable when ready
sp infra jobs enable behavioral_analysis

# Verify status
sp infra jobs show behavioral_analysis
```

---

## Database Schema

Jobs are tracked in the `scheduled_jobs` table:

```sql
CREATE TABLE scheduled_jobs (
    id TEXT PRIMARY KEY,
    job_name TEXT NOT NULL UNIQUE,
    schedule TEXT NOT NULL,
    enabled BOOLEAN NOT NULL DEFAULT true,
    last_run TIMESTAMPTZ,
    next_run TIMESTAMPTZ,
    last_status TEXT,          -- 'success', 'failed', 'running'
    last_error TEXT,
    run_count INTEGER NOT NULL DEFAULT 0,
    created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
```

---

## 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 `render_result()`
- [x] No `unwrap()` / `expect()` - uses `?` with `.context()`
- [x] JSON output supported via `--json` flag
- [x] Cleanup commands support `--dry-run`


---

## License

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