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
//! Help content database
//!
//! Structured help content with topics, sections, and embedded documentation.

use std::collections::HashMap;

/// Help topic with title, content, and metadata
#[derive(Debug, Clone)]
pub struct HelpTopic {
    /// Unique topic identifier
    pub id: String,
    /// Topic title
    pub title: String,
    /// Topic content (markdown format)
    pub content: String,
    /// Related topics
    pub related: Vec<String>,
    /// Search keywords
    pub keywords: Vec<String>,
    /// Topic category
    pub category: HelpCategory,
}

/// Help section grouping related topics
#[derive(Debug, Clone)]
pub struct HelpSection {
    /// Section title
    pub title: String,
    /// Section topics
    pub topics: Vec<HelpTopic>,
}

/// Help category enumeration
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum HelpCategory {
    GettingStarted,
    WorkflowManagement,
    Editing,
    Execution,
    KeyboardShortcuts,
    Advanced,
    Troubleshooting,
}

impl HelpCategory {
    /// Get category display name
    pub fn name(&self) -> &'static str {
        match self {
            HelpCategory::GettingStarted => "Getting Started",
            HelpCategory::WorkflowManagement => "Workflow Management",
            HelpCategory::Editing => "Editing Workflows",
            HelpCategory::Execution => "Workflow Execution",
            HelpCategory::KeyboardShortcuts => "Keyboard Shortcuts",
            HelpCategory::Advanced => "Advanced Features",
            HelpCategory::Troubleshooting => "Troubleshooting",
        }
    }
}

/// Complete help content database
#[derive(Debug)]
pub struct HelpContent {
    /// All help topics indexed by ID
    topics: HashMap<String, HelpTopic>,
    /// Topics grouped by category
    categories: HashMap<HelpCategory, Vec<String>>,
}

impl HelpContent {
    /// Create new help content database
    pub fn new() -> Self {
        let mut content = Self {
            topics: HashMap::new(),
            categories: HashMap::new(),
        };
        content.initialize_content();
        content
    }

    /// Initialize all help content
    fn initialize_content(&mut self) {
        // Getting Started
        self.add_topic(HelpTopic {
            id: "overview".to_string(),
            title: "TUI Overview".to_string(),
            content: include_str!("../../../docs/tui/overview.md").to_string(),
            related: vec!["getting_started".to_string(), "navigation".to_string()],
            keywords: vec![
                "intro".to_string(),
                "introduction".to_string(),
                "overview".to_string(),
            ],
            category: HelpCategory::GettingStarted,
        });

        self.add_topic(HelpTopic {
            id: "getting_started".to_string(),
            title: "Getting Started".to_string(),
            content: r#"# Getting Started with DSL TUI

Welcome to the DSL Workflow TUI (Terminal User Interface)! This interactive tool helps you create, edit, and execute AI agent workflows.

## Quick Start

1. **Launch the TUI**: Run `dsl-executor tui` or `cargo run --bin dsl-executor -- tui`
2. **Navigate**: Use arrow keys or vim keys (hjkl) to move around
3. **Create a workflow**: Press `n` to create a new workflow
4. **Edit a workflow**: Select a workflow and press `Enter` or `e`
5. **Execute a workflow**: Press `x` to run the selected workflow
6. **Get help**: Press `?` or `F1` at any time

## Main Views

- **Workflow List**: Browse and manage your workflows
- **Viewer**: Read-only workflow visualization
- **Editor**: Edit workflow YAML with validation
- **Execution Monitor**: Watch workflows run in real-time
- **AI Generator**: Create workflows from natural language

## Navigation Basics

- `↑/↓` or `k/j`: Move up/down
- `Enter`: Select/Open
- `Esc`: Go back/Cancel
- `?` or `F1`: Context-sensitive help
- `q`: Quit (with confirmation)

## Next Steps

- Read about [Workflow Management](#navigating_workflows)
- Learn [Keyboard Shortcuts](#keyboard_shortcuts_global)
- Explore the [Editor](#editing_workflows)
"#.to_string(),
            related: vec!["overview".to_string(), "keyboard_shortcuts_global".to_string()],
            keywords: vec!["start".to_string(), "begin".to_string(), "intro".to_string(), "tutorial".to_string()],
            category: HelpCategory::GettingStarted,
        });

        // Workflow Management
        self.add_topic(HelpTopic {
            id: "navigating_workflows".to_string(),
            title: "Navigating Workflows".to_string(),
            content: r#"# Navigating Workflows

The Workflow List is your main hub for managing DSL workflows.

## Workflow List View

- **Up/Down**: Navigate through workflows using arrow keys or `k/j`
- **Search**: Press `/` to search workflows by name or description
- **Filter**: Type to filter the list in real-time
- **Clear search**: Press `Esc` to clear the search query

## Workflow Actions

| Key | Action |
|-----|--------|
| `Enter` or `o` | Open workflow in viewer |
| `e` | Edit workflow in editor |
| `x` | Execute workflow |
| `n` | Create new workflow |
| `d` | Delete selected workflow |
| `r` | Rename workflow |
| `c` | Copy workflow |

## Workflow Details

Each workflow entry shows:
- **Name**: Workflow identifier
- **Description**: Brief summary (if available)
- **Version**: Workflow version number
- **Modified**: Last modification time
- **Status**: Execution status indicator

## Tips

- Use search (`/`) to quickly find workflows in large lists
- Press `?` for context-specific help
- Workflows are auto-discovered from your workflows directory
"#
            .to_string(),
            related: vec![
                "creating_workflows".to_string(),
                "keyboard_shortcuts_list".to_string(),
            ],
            keywords: vec![
                "browse".to_string(),
                "list".to_string(),
                "manage".to_string(),
                "search".to_string(),
            ],
            category: HelpCategory::WorkflowManagement,
        });

        self.add_topic(HelpTopic {
            id: "creating_workflows".to_string(),
            title: "Creating Workflows".to_string(),
            content: r#"# Creating Workflows

There are multiple ways to create workflows in the TUI.

## Method 1: AI Generator (Recommended)

1. Press `g` from the workflow list
2. Describe your workflow in natural language
3. Review the generated YAML
4. Edit if needed and save

Example prompt:
> "Create a workflow that analyzes a codebase for security issues, generates a report, and sends it via email"

## Method 2: Manual Creation

1. Press `n` from the workflow list
2. Enter a workflow name
3. Choose to start from:
   - Empty template
   - Example workflow
   - Copy existing workflow

## Method 3: Import

1. Place YAML file in workflows directory
2. TUI auto-discovers it
3. Edit as needed

## Workflow Structure

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

agents:
  agent_id:
    description: "What this agent does"
    tools: [Read, Write, WebSearch]

tasks:
  task_id:
    description: "Task description"
    agent: "agent_id"
    depends_on: []
```

## Best Practices

- Use descriptive names for workflows, agents, and tasks
- Add descriptions to help others understand intent
- Test workflows with simple tasks first
- Use the validator before executing

See [Editing Workflows](#editing_workflows) for more details.
"#.to_string(),
            related: vec!["editing_workflows".to_string(), "generating_workflows".to_string()],
            keywords: vec!["new".to_string(), "create".to_string(), "generate".to_string(), "template".to_string()],
            category: HelpCategory::WorkflowManagement,
        });

        // Editing
        self.add_topic(HelpTopic {
            id: "editing_workflows".to_string(),
            title: "Editing Workflows".to_string(),
            content: r#"# Editing Workflows

The workflow editor provides real-time validation and syntax highlighting.

## Editor Modes

### Text Mode (Default)
- Direct YAML editing
- Syntax highlighting
- Real-time validation
- Auto-indentation

### Form Mode
- Structured forms for workflow components
- Field validation
- Auto-completion
- Toggle with `Tab`

## Editing Commands

| Key | Action |
|-----|--------|
| `Ctrl+S` | Save workflow |
| `Ctrl+V` | Validate YAML |
| `Ctrl+Z` | Undo |
| `Ctrl+Y` | Redo |
| `Tab` | Toggle text/form mode |
| `Esc` | Cancel (prompts if unsaved) |

## Navigation

- **Arrow keys**: Move cursor
- **Home/End**: Start/end of line
- **PageUp/PageDown**: Scroll page
- **Ctrl+Home/End**: Start/end of document

## Validation

The editor validates:
- ✓ YAML syntax
- ✓ Required fields
- ✓ Agent references
- ✓ Task dependencies
- ✓ Circular dependency detection
- ✓ Variable references

Validation errors appear inline with:
- Line number
- Error description
- Suggested fix (when available)

## Auto-completion

Press `Ctrl+Space` for context-aware suggestions:
- Workflow fields
- Agent properties
- Tool names
- Task attributes

## Tips

- Save frequently with `Ctrl+S`
- Use validation (`Ctrl+V`) before executing
- Form mode helps prevent syntax errors
- Undo history preserved across saves
"#
            .to_string(),
            related: vec![
                "yaml_syntax".to_string(),
                "validation".to_string(),
                "keyboard_shortcuts_editor".to_string(),
            ],
            keywords: vec![
                "edit".to_string(),
                "modify".to_string(),
                "change".to_string(),
                "yaml".to_string(),
            ],
            category: HelpCategory::Editing,
        });

        // Execution
        self.add_topic(HelpTopic {
            id: "monitoring_execution".to_string(),
            title: "Monitoring Execution".to_string(),
            content: r#"# Monitoring Workflow Execution

The execution monitor provides real-time visibility into running workflows.

## Execution View

The monitor displays:

1. **Task Graph**: Visual representation of task dependencies
2. **Current Status**: Which tasks are running, completed, or failed
3. **Logs**: Real-time output from agents and tasks
4. **Progress**: Overall completion percentage
5. **Timing**: Elapsed time and estimated completion

## Task States

- 🔵 **Pending**: Waiting to start
- 🟡 **Running**: Currently executing
- 🟢 **Completed**: Successfully finished
- 🔴 **Failed**: Error occurred
- ⚪ **Skipped**: Dependency failed

## Controls

| Key | Action |
|-----|--------|
| `Space` | Pause/Resume execution |
| `s` | Stop execution (with confirmation) |
| `l` | Toggle log view |
| `t` | Toggle task graph view |
| `f` | Follow mode (auto-scroll logs) |
| `↑/↓` | Scroll logs |

## Log Filtering

Press `/` to filter logs by:
- Task name
- Log level (info, warning, error)
- Agent name
- Keyword search

## Execution States

- **Running**: Workflow is executing
- **Paused**: Execution paused (can resume)
- **Completed**: All tasks finished successfully
- **Failed**: One or more tasks failed
- **Cancelled**: Stopped by user

## Tips

- Use follow mode (`f`) to auto-scroll logs
- Filter logs to focus on specific tasks
- Check task graph for dependency issues
- Review failed task logs for debugging
"#
            .to_string(),
            related: vec![
                "task_status".to_string(),
                "keyboard_shortcuts_monitor".to_string(),
            ],
            keywords: vec![
                "execute".to_string(),
                "run".to_string(),
                "monitor".to_string(),
                "logs".to_string(),
                "status".to_string(),
            ],
            category: HelpCategory::Execution,
        });

        // Keyboard Shortcuts
        self.add_topic(HelpTopic {
            id: "keyboard_shortcuts_global".to_string(),
            title: "Global Keyboard Shortcuts".to_string(),
            content: r#"# Global Keyboard Shortcuts

These shortcuts work in all views.

## Navigation

| Key | Action |
|-----|--------|
| `↑` or `k` | Move up |
| `↓` or `j` | Move down |
| `←` or `h` | Move left |
| `→` or `l` | Move right |
| `Home` or `g` | Go to top |
| `End` or `G` | Go to bottom |
| `PageUp` | Scroll page up |
| `PageDown` | Scroll page down |

## General

| Key | Action |
|-----|--------|
| `?` or `F1` | Help (context-aware) |
| `Esc` | Back/Cancel |
| `q` | Quit (with confirmation) |
| `/` | Search/Filter |
| `Ctrl+C` | Force quit |
| `Ctrl+L` | Refresh screen |

## View Switching

| Key | Action |
|-----|--------|
| `1` | Workflow list |
| `2` | Viewer |
| `3` | Editor |
| `4` | Execution monitor |
| `5` | AI generator |

See also:
- [Workflow List Shortcuts](#keyboard_shortcuts_list)
- [Editor Shortcuts](#keyboard_shortcuts_editor)
- [Monitor Shortcuts](#keyboard_shortcuts_monitor)
"#
            .to_string(),
            related: vec![
                "keyboard_shortcuts_list".to_string(),
                "keyboard_shortcuts_editor".to_string(),
            ],
            keywords: vec![
                "shortcuts".to_string(),
                "keys".to_string(),
                "hotkeys".to_string(),
                "bindings".to_string(),
            ],
            category: HelpCategory::KeyboardShortcuts,
        });

        self.add_topic(HelpTopic {
            id: "keyboard_shortcuts_list".to_string(),
            title: "Workflow List Shortcuts".to_string(),
            content: r#"# Workflow List Keyboard Shortcuts

Shortcuts specific to the workflow list view.

## Navigation

| Key | Action |
|-----|--------|
| `↑/↓` or `k/j` | Navigate workflows |
| `Enter` or `o` | Open in viewer |
| `/` | Search workflows |

## Actions

| Key | Action |
|-----|--------|
| `n` | New workflow |
| `e` | Edit workflow |
| `x` | Execute workflow |
| `d` | Delete workflow |
| `r` | Rename workflow |
| `c` | Copy workflow |
| `g` | Generate with AI |

## Sorting

| Key | Action |
|-----|--------|
| `s` | Sort menu |
| `sn` | Sort by name |
| `sm` | Sort by modified date |
| `sv` | Sort by version |

All global shortcuts also apply. Press `?` for context-specific help.
"#
            .to_string(),
            related: vec![
                "navigating_workflows".to_string(),
                "keyboard_shortcuts_global".to_string(),
            ],
            keywords: vec![
                "list".to_string(),
                "shortcuts".to_string(),
                "workflow list".to_string(),
            ],
            category: HelpCategory::KeyboardShortcuts,
        });

        self.add_topic(HelpTopic {
            id: "keyboard_shortcuts_editor".to_string(),
            title: "Editor Keyboard Shortcuts".to_string(),
            content: r#"# Editor Keyboard Shortcuts

Shortcuts for the workflow editor.

## File Operations

| Key | Action |
|-----|--------|
| `Ctrl+S` | Save |
| `Ctrl+Q` | Save and quit |
| `Esc` | Cancel (confirm if modified) |

## Editing

| Key | Action |
|-----|--------|
| `Ctrl+Z` | Undo |
| `Ctrl+Y` or `Ctrl+Shift+Z` | Redo |
| `Ctrl+X` | Cut line |
| `Ctrl+C` | Copy line |
| `Ctrl+V` | Paste (or Validate if no clipboard) |
| `Tab` | Indent / Toggle mode |
| `Shift+Tab` | Unindent |

## Navigation

| Key | Action |
|-----|--------|
| `Arrow keys` | Move cursor |
| `Home` | Start of line |
| `End` | End of line |
| `Ctrl+Home` | Start of document |
| `Ctrl+End` | End of document |
| `Ctrl+G` | Go to line |

## Features

| Key | Action |
|-----|--------|
| `Ctrl+Space` | Auto-complete |
| `Ctrl+V` | Validate YAML |
| `Ctrl+F` | Find |
| `Ctrl+H` | Find and replace |

All global shortcuts also apply.
"#
            .to_string(),
            related: vec![
                "editing_workflows".to_string(),
                "keyboard_shortcuts_global".to_string(),
            ],
            keywords: vec![
                "editor".to_string(),
                "shortcuts".to_string(),
                "edit".to_string(),
                "keys".to_string(),
            ],
            category: HelpCategory::KeyboardShortcuts,
        });

        // Advanced
        self.add_topic(HelpTopic {
            id: "yaml_syntax".to_string(),
            title: "YAML Syntax Reference".to_string(),
            content: r#"# DSL YAML Syntax Reference

Complete reference for DSL workflow YAML syntax.

## Top-Level Structure

```yaml
name: string              # Required: Workflow name
version: string           # Required: Semantic version
description: string       # Optional: Workflow description

inputs:                   # Optional: Workflow-level inputs
  input_name:
    type: string|number|boolean|array|object
    required: boolean
    default: any

agents:                   # Required: Agent definitions
  agent_id: AgentDef

tasks:                    # Required: Task definitions
  task_id: TaskDef

hooks:                    # Optional: Lifecycle hooks
  on_start: HookDef
  on_complete: HookDef
  on_error: HookDef
```

## Agent Definition

```yaml
agents:
  researcher:
    description: string   # Required: What this agent does
    model: string        # Optional: AI model (default: claude-sonnet-4-5)
    tools:               # Optional: Tool allowlist
      - Read
      - Write
      - WebSearch
    permissions:         # Optional: Permission settings
      mode: default|acceptEdits|plan|bypassPermissions
      max_turns: number
    inputs:              # Optional: Agent-specific inputs
      api_key:
        type: string
        required: true
```

## Task Definition

```yaml
tasks:
  analyze:
    description: string         # Required: Task description
    agent: string              # Required: Agent ID reference
    depends_on:                # Optional: Task dependencies
      - other_task_id
    subtasks:                  # Optional: Child tasks
      - child_task_id
    output: string             # Optional: Output file path
    inputs:                    # Optional: Task inputs
      config: value
    outputs:                   # Optional: Output variables
      result:
        source:
          type: file|state|result
          path: string
```

## Variable Interpolation

Use `${scope.variable}` or `${variable}` syntax:

```yaml
tasks:
  analyze:
    description: "Analyze ${workflow.project_name}"
    inputs:
      config: "${workflow.project_name}/config.yaml"
```

Scopes:
- `workflow.*`: Workflow-level variables
- `agent.*`: Agent-level variables
- `task.*`: Task-level variables

## Data Types

- **string**: Text values
- **number**: Numeric values
- **boolean**: true/false
- **array**: Lists of values
- **object**: Key-value maps

See official DSL documentation for complete specification.
"#
            .to_string(),
            related: vec!["editing_workflows".to_string(), "validation".to_string()],
            keywords: vec![
                "yaml".to_string(),
                "syntax".to_string(),
                "format".to_string(),
                "schema".to_string(),
            ],
            category: HelpCategory::Advanced,
        });

        // Initialize category index
        for topic in self.topics.values() {
            self.categories
                .entry(topic.category)
                .or_default()
                .push(topic.id.clone());
        }
    }

    /// Add a topic to the database
    fn add_topic(&mut self, topic: HelpTopic) {
        let id = topic.id.clone();
        self.topics.insert(id, topic);
    }

    /// Get a topic by ID
    pub fn get_topic(&self, id: &str) -> Option<&HelpTopic> {
        self.topics.get(id)
    }

    /// Get all topics in a category
    pub fn get_category_topics(&self, category: HelpCategory) -> Vec<&HelpTopic> {
        self.categories
            .get(&category)
            .map(|ids| ids.iter().filter_map(|id| self.topics.get(id)).collect())
            .unwrap_or_default()
    }

    /// Get all topics
    pub fn all_topics(&self) -> Vec<&HelpTopic> {
        self.topics.values().collect()
    }

    /// Get all categories with their topics
    pub fn all_categories(&self) -> Vec<(HelpCategory, Vec<&HelpTopic>)> {
        let mut categories: Vec<_> = self
            .categories
            .keys()
            .map(|&cat| (cat, self.get_category_topics(cat)))
            .collect();

        // Sort by category enum order
        categories.sort_by_key(|(cat, _)| *cat as u8);
        categories
    }
}

impl Default for HelpContent {
    fn default() -> Self {
        Self::new()
    }
}