periplon 0.2.0

Rust SDK for building multi-agent AI workflows and automation
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
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
# DSL Executor CLI Guide

## Overview

The `periplon-executor` is a command-line tool for executing multi-agent DSL workflows. It provides a simple interface for running, validating, and managing workflow executions with support for state persistence, progress tracking, and resume functionality.

## Installation

### Build from Source

```bash
# Clone the repository
git clone https://github.com/yourusername/periplon
cd periplon

# Build the CLI tool
cargo build --release --bin periplon-executor

# The binary will be at: target/release/periplon-executor
```

### Install Locally

```bash
cargo install --path . --bin periplon-executor
```

## Commands

### `run` - Execute a Workflow

Execute a workflow from a YAML file.

**Usage:**
```bash
periplon-executor run <WORKFLOW_FILE> [OPTIONS]
```

**Options:**
- `-s, --state-dir <DIR>` - Directory to store workflow state (default: `.workflow_states`)
- `-r, --resume` - Resume from saved state if available
- `-c, --clean` - Clean state before execution (delete existing state)
- `-v, --verbose` - Enable verbose output
- `--dry-run` - Validate workflow without executing

**Examples:**

```bash
# Run a workflow
periplon-executor run examples/dsl/simple_file_organizer.yaml

# Run with verbose output
periplon-executor run examples/dsl/research_pipeline.yaml --verbose

# Run with state persistence
periplon-executor run workflow.yaml --state-dir ./my-states

# Resume a previously interrupted workflow
periplon-executor run workflow.yaml --resume

# Clean and restart
periplon-executor run workflow.yaml --clean

# Validate without running
periplon-executor run workflow.yaml --dry-run
```

**Output:**
```
============================================================
DSL Workflow Executor
============================================================

Parsing workflow...  ✓
Validating workflow...  ✓

Initializing workflow...  ✓

Executing workflow...
------------------------------------------------------------

Executing task: organize_downloads - Sort files in Downloads folder
  Message: ...
Task completed: organize_downloads

------------------------------------------------------------
Shutting down...  ✓

✓ Workflow completed successfully!
  Duration: 2.45s
  Completed: 5/5
```

---

### `validate` - Validate a Workflow

Validate a workflow file without executing it.

**Usage:**
```bash
periplon-executor validate <WORKFLOW_FILE> [OPTIONS]
```

**Options:**
- `-v, --verbose` - Show detailed validation information

**Examples:**

```bash
# Validate a workflow
periplon-executor validate workflow.yaml

# Validate with details
periplon-executor validate workflow.yaml --verbose
```

**Output (verbose):**
```
Validating workflow...

  Parsing YAML...  ✓
    Workflow: File Organizer
    Version: 1.0.0
  Checking semantics...  ✓
    Agents: 1
    Tasks: 1

  Agents:
    • organizer - Organize files by type and date
      Tools: Read, Bash, Glob

  Tasks:
    • organize_downloads - Sort files in Downloads folder

✓ Workflow is valid
```

---

### `list` - List Saved Workflow States

List all saved workflow states in the state directory.

**Usage:**
```bash
periplon-executor list [OPTIONS]
```

**Options:**
- `-s, --state-dir <DIR>` - Directory containing workflow states (default: `.workflow_states`)

**Examples:**

```bash
# List all saved states
periplon-executor list

# List from custom directory
periplon-executor list --state-dir ./my-states
```

**Output:**
```
Saved Workflow States:
  Directory: .workflow_states

  • File Organizer
    Status: Completed
    Progress: 100.0%
    Tasks: 5/5
    Finished

  • Research Pipeline
    Status: Running
    Progress: 60.0%
    Tasks: 3/5
    In Progress

Total: 2 workflows
```

---

### `clean` - Clean Saved Workflow States

Delete saved workflow states.

**Usage:**
```bash
periplon-executor clean [WORKFLOW_NAME] [OPTIONS]
```

**Options:**
- `-s, --state-dir <DIR>` - Directory containing workflow states (default: `.workflow_states`)
- `-y, --yes` - Skip confirmation prompt

**Examples:**

```bash
# Clean a specific workflow (with confirmation)
periplon-executor clean "File Organizer"

# Clean all workflows (with confirmation)
periplon-executor clean

# Clean without confirmation
periplon-executor clean "Research Pipeline" --yes

# Clean all from custom directory
periplon-executor clean --state-dir ./my-states --yes
```

**Output:**
```
Delete state for workflow 'File Organizer'? [y/N] y
✓ Deleted state for 'File Organizer'
```

---

### `status` - Show Workflow Status

Display detailed status and progress information for a workflow.

**Usage:**
```bash
periplon-executor status <WORKFLOW_NAME> [OPTIONS]
```

**Options:**
- `-s, --state-dir <DIR>` - Directory containing workflow states (default: `.workflow_states`)

**Examples:**

```bash
# Show workflow status
periplon-executor status "Research Pipeline"

# From custom directory
periplon-executor status "My Workflow" --state-dir ./my-states
```

**Output:**
```
Workflow Status
============================================================

  Name: Research Pipeline
  Version: 1.0.0
  Status: Running

  Progress: 60.0%
  Total Tasks: 5
  Completed: 3
  Failed: 0

  Started: SystemTime { ... }
  Ended: In Progress
```

---

### `group` - Manage Task Groups

Manage task groups - collections of reusable predefined tasks that can be imported into workflows.

#### `group list` - List Available Task Groups

List all available task groups from configured search paths.

**Usage:**
```bash
periplon-executor group list [OPTIONS]
```

**Options:**
- `-v, --verbose` - Show detailed information about each group
- `-j, --json` - Output results in JSON format with syntax coloring
- `-p, --path <DIR>` - Search directory (default: standard search paths)

**Examples:**

```bash
# List all available task groups
periplon-executor group list

# List with detailed information
periplon-executor group list --verbose

# List from a specific directory
periplon-executor group list --path ~/.claude/task-groups

# JSON output for scripting
periplon-executor group list --json
```

**Output:**
```
Task Groups
============================================================

  Search Paths:
    • /Users/you/.claude/task-groups
    • ./.claude/task-groups

  Found Available Groups:

  • google-workspace@1.0.0
    3 tasks | /Users/you/.claude/task-groups/google-workspace.taskgroup.yaml

  • aws-tools@2.1.0
    5 tasks | /Users/you/.claude/task-groups/aws-tools.taskgroup.yaml

Total: 2 groups
```

---

#### `group install` - Install (Validate) a Task Group

Install and validate a task group by reference. This verifies that the group definition is valid and all required tasks are available.

**Usage:**
```bash
periplon-executor group install <GROUP_REF> [OPTIONS]
```

**Arguments:**
- `<GROUP_REF>` - Task group reference (format: `name@version`)

**Options:**
- `-v, --verbose` - Show detailed installation steps
- `-j, --json` - Output results in JSON format

**Examples:**

```bash
# Install a task group
periplon-executor group install google-workspace@1.0.0

# Install with verbose output
periplon-executor group install aws-tools@2.1.0 --verbose

# Install with JSON output
periplon-executor group install slack-integration@1.0.0 --json
```

**Output:**
```
Installing Task Group
============================================================

  Group: google-workspace
  Version: 1.0.0

  Resolving task group...  ✓
  Validating tasks...  ✓

✓ Task group installed successfully!
  Group: google-workspace
  Version: 1.0.0
  Tasks: 3
  Description: Google Workspace integration tasks

  Source: /Users/you/.claude/task-groups/google-workspace.taskgroup.yaml
```

---

#### `group update` - Update Task Group Cache

Update task group cache and refresh information. Use `--force` to clear the cache and reload all groups.

**Usage:**
```bash
periplon-executor group update [GROUP_REF] [OPTIONS]
```

**Arguments:**
- `[GROUP_REF]` - Specific group to update (optional, updates all if omitted)

**Options:**
- `-f, --force` - Force cache refresh
- `-v, --verbose` - Show detailed update information
- `-j, --json` - Output results in JSON format

**Examples:**

```bash
# Update all groups
periplon-executor group update

# Update specific group
periplon-executor group update google-workspace@1.0.0

# Force cache refresh for all groups
periplon-executor group update --force

# Update with verbose output
periplon-executor group update --verbose

# JSON output
periplon-executor group update --json
```

**Output:**
```
Updating Task Groups
============================================================

  ✓ Cache cleared
  Found 3 groups

  Updating: google-workspace@1.0.0
  Updating: aws-tools@2.1.0
  Updating: slack-integration@1.0.0

✓ Updated 3 groups
```

---

#### `group validate` - Validate a Task Group File

Validate a task group definition file to ensure it's correctly formatted and all referenced tasks exist.

**Usage:**
```bash
periplon-executor group validate <GROUP_FILE> [OPTIONS]
```

**Arguments:**
- `<GROUP_FILE>` - Path to the task group YAML file

**Options:**
- `-v, --verbose` - Show detailed validation information
- `-j, --json` - Output results in JSON format

**Examples:**

```bash
# Validate a task group file
periplon-executor group validate my-group.taskgroup.yaml

# Validate with verbose output
periplon-executor group validate my-group.taskgroup.yaml --verbose

# JSON output
periplon-executor group validate my-group.taskgroup.yaml --json
```

**Output (verbose):**
```
Validating Task Group
============================================================

  Loading group file...  ✓
    Name: my-custom-group
    Version: 1.0.0
    Tasks: 3

  Resolving tasks...  ✓
    ✓ task1 v1.0.0
    ✓ task2 v1.0.0
    ✓ task3 v2.0.0

✓ Task group is valid!
  Group: my-custom-group
  Version: 1.0.0
  Tasks: 3

  Tasks:
    • task1 v1.0.0 (required)
    • task2 v1.0.0
    • task3 v2.0.0 (required)
```

**Validation Errors:**
```
Validating Task Group
============================================================

✗ Task group validation failed!

  Errors:
    • Task 'missing-task' v1.0.0 not found
    • Task 'another-task' version mismatch: required 2.0.0, found 1.0.0
```

---

### Task Groups Overview

Task groups allow you to:

1. **Organize reusable tasks** into logical collections
2. **Share configuration** across multiple tasks (API keys, permissions, environment variables)
3. **Version and distribute** task collections
4. **Import into workflows** using namespace references

**Example Task Group File:**

```yaml
apiVersion: "taskgroup/v1"
kind: "TaskGroup"
metadata:
  name: "google-workspace"
  version: "1.0.0"
  description: "Google Workspace integration tasks"
  author: "Your Name"
  license: "MIT"
  tags:
    - "google"
    - "productivity"

spec:
  tasks:
    - name: "upload-to-drive"
      version: "1.0.0"
      required: true
      description: "Upload files to Google Drive"

    - name: "create-doc"
      version: "1.0.0"
      required: true
      description: "Create a Google Doc"

    - name: "send-gmail"
      version: "1.0.0"
      required: false
      description: "Send email via Gmail"

  shared_config:
    inputs:
      api_key:
        type: string
        required: true
        description: "Google API key"

    permissions:
      mode: "acceptEdits"
      allowed_directories:
        - "/tmp"

    environment:
      GOOGLE_API_URL: "https://www.googleapis.com"

    max_turns: 10
```

**Using in Workflows:**

```yaml
name: "My Workflow"
version: "1.0.0"

# Import task groups
imports:
  google: "google-workspace@1.0.0"
  aws: "aws-tools@2.1.0"

agents: {}

tasks:
  upload_files:
    description: "Upload processed files to Google Drive"
    uses_workflow: "google:upload-to-drive"
    inputs:
      files: "./output/*.pdf"
      folder_id: "abc123"
```

**Search Paths:**

Task groups are discovered from these locations (in priority order):

1. `./.claude/task-groups/` - Project-local groups (highest priority)
2. `~/.claude/task-groups/` - User-global groups

Place your `.taskgroup.yaml` files in these directories to make them available for import.

---

## Workflow State Persistence

### How It Works

When you run a workflow with state persistence enabled (using `--resume`, `--clean`, or `--state-dir`), the executor:

1. **Saves state automatically** after each task completion
2. **Tracks progress** including completed, failed, and pending tasks
3. **Records errors** for failed tasks with full error messages
4. **Timestamps execution** to track task duration
5. **Stores in JSON format** for easy debugging

### Resume Functionality

Use `--resume` to continue a workflow that was interrupted:

```bash
# Start a workflow
periplon-executor run long-workflow.yaml

# Interrupt with Ctrl+C

# Resume from where it left off
periplon-executor run long-workflow.yaml --resume
```

The executor will:
- ✓ Load the saved state
- ✓ Skip already-completed tasks
- ✓ Resume from the next pending task
- ✓ Show progress from the checkpoint

### State Files

State files are stored as JSON in the state directory:

```
.workflow_states/
├── File Organizer.state.json
├── Research Pipeline.state.json
└── Data Processing.state.json
```

**Example state file:**
```json
{
  "workflow_name": "Research Pipeline",
  "workflow_version": "1.0.0",
  "task_statuses": {
    "gather_data": "Completed",
    "process_data": "Running",
    "write_report": "Pending"
  },
  "task_start_times": {
    "gather_data": { "secs_since_epoch": 1698765432, "nanos_since_epoch": 0 }
  },
  "task_end_times": {
    "gather_data": { "secs_since_epoch": 1698765532, "nanos_since_epoch": 0 }
  },
  "task_attempts": {
    "gather_data": 1,
    "process_data": 2
  },
  "task_errors": {},
  "status": "Running",
  "started_at": { "secs_since_epoch": 1698765400, "nanos_since_epoch": 0 },
  "ended_at": null,
  "checkpoint_at": { "secs_since_epoch": 1698765550, "nanos_since_epoch": 0 },
  "metadata": {}
}
```

---

## Workflow Examples

### Simple File Organization

```yaml
name: "File Organizer"
version: "1.0.0"

agents:
  organizer:
    description: "Organize files by type and date"
    tools:
      - Read
      - Bash
      - Glob
    permissions:
      mode: "default"

tasks:
  organize_downloads:
    description: "Sort files in Downloads folder"
    agent: "organizer"
```

**Run it:**
```bash
periplon-executor run file-organizer.yaml --verbose
```

### Research Pipeline with State

```yaml
name: "Research Pipeline"
version: "1.0.0"

agents:
  researcher:
    description: "Research and gather information"
    tools: [Read, WebSearch]
    permissions:
      mode: "default"

  writer:
    description: "Write documentation"
    tools: [Read, Write, Edit]
    permissions:
      mode: "acceptEdits"

tasks:
  gather_data:
    description: "Research the topic"
    agent: "researcher"

  write_report:
    description: "Write research report"
    agent: "writer"
    depends_on: ["gather_data"]
    on_error:
      retry: 3
```

**Run with state:**
```bash
# Start the workflow
periplon-executor run research.yaml --state-dir ./states

# If interrupted, resume later
periplon-executor run research.yaml --state-dir ./states --resume

# Check status
periplon-executor status "Research Pipeline" --state-dir ./states
```

---

## Error Handling

### Retry on Failure

The executor supports automatic retry for failed tasks:

```yaml
tasks:
  fetch_data:
    agent: "fetcher"
    on_error:
      retry: 3  # Retry up to 3 times
```

### Fallback Agents

Specify a fallback agent if the primary fails:

```yaml
tasks:
  critical_task:
    agent: "primary_agent"
    on_error:
      retry: 2
      fallback_agent: "backup_agent"
```

### Error Messages

Failed tasks show detailed error information:

```bash
✗ Workflow failed!
  Error: Task 'fetch_data' failed after 3 attempts
  Progress: 40.0%
  Completed: 2/5
  Failed: fetch_data
```

---

## Tips and Best Practices

### 1. Use Validation First

Always validate your workflow before running:

```bash
periplon-executor validate workflow.yaml --verbose
```

### 2. Enable State for Long Workflows

For workflows that take a long time:

```bash
periplon-executor run long-workflow.yaml --state-dir ./states
```

### 3. Clean State When Needed

If a workflow changes significantly, clean the old state:

```bash
periplon-executor run workflow.yaml --clean
```

### 4. Check Status During Execution

In another terminal, check progress:

```bash
periplon-executor status "My Workflow"
```

### 5. Use Verbose Mode for Debugging

When things don't work as expected:

```bash
periplon-executor run workflow.yaml --verbose
```

### 6. List States Regularly

Keep track of your workflows:

```bash
periplon-executor list
```

---

## Troubleshooting

### Workflow Validation Fails

**Problem:** `Error: Agent 'unknown_agent' not found`

**Solution:** Check that all agents referenced in tasks are defined in the `agents` section.

### State Won't Resume

**Problem:** Resume flag doesn't seem to work

**Solution:**
1. Check that the workflow name matches exactly
2. Ensure the state directory is correct
3. Verify the state file exists: `periplon-executor list`

### Permission Errors

**Problem:** `Permission denied` when running workflow

**Solution:** Ensure the `permissions` mode in your workflow allows the required operations:
- `default`: Read-only
- `acceptEdits`: Allows file modifications

### State File Corruption

**Problem:** Unable to load state file

**Solution:**
1. Check the JSON file manually (`.workflow_states/<name>.state.json`)
2. If corrupted, clean the state: `periplon-executor clean "<workflow_name>" --yes`
3. Restart the workflow fresh

---

## Advanced Usage

### Custom State Directory

Organize states by project:

```bash
mkdir -p ./project-states
periplon-executor run workflow.yaml --state-dir ./project-states
```

### Scripting with periplon-executor

Use in shell scripts:

```bash
#!/bin/bash

# Run workflow and check exit code
if periplon-executor run workflow.yaml; then
    echo "Workflow succeeded"
    periplon-executor status "My Workflow"
else
    echo "Workflow failed"
    exit 1
fi
```

### CI/CD Integration

Use in continuous integration:

```bash
# .github/workflows/workflow.yml
- name: Run DSL Workflow
  run: |
    periplon-executor validate workflow.yaml
    periplon-executor run workflow.yaml --dry-run
```

---

## Exit Codes

The CLI uses standard exit codes:

- `0` - Success
- `1` - Failure (validation error, execution error, etc.)

Check exit codes in scripts:

```bash
periplon-executor run workflow.yaml
if [ $? -eq 0 ]; then
    echo "Success"
fi
```

---

## Environment Variables

Currently, the CLI does not use environment variables, but workflows can access environment variables through hooks.

---

## Colored Output

The CLI uses colored output for better readability:

- 🟢 **Green** - Success, completed tasks
- 🔴 **Red** - Errors, failed tasks
- 🟡 **Yellow** - Warnings, in-progress tasks
- 🔵 **Cyan** - Headers, separators
-**White** - Normal text
- **Bold** - Important information

To disable colors (for logging):

```bash
NO_COLOR=1 periplon-executor run workflow.yaml
```

---

## Version Information

Check the version:

```bash
periplon-executor --version
```

Get help:

```bash
periplon-executor --help
periplon-executor run --help
periplon-executor validate --help
```

---

## Support

For issues, feature requests, or questions:

- GitHub Issues: https://github.com/yourusername/periplon/issues
- Documentation: See `DSL_IMPLEMENTATION.md` for technical details
- Examples: Check `examples/dsl/` directory

---

**Last Updated:** 2025-10-18
**CLI Version:** 0.1.0