nika 0.35.4

Semantic YAML workflow engine for AI tasks - DAG execution, MCP integration, multi-provider LLM support
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
//! # Nika Init Templates
//!
//! This module contains all workflow templates generated by `nika init`.
//!
//! ## Organization
//!
//! Workflows are organized into 6 tiers of increasing complexity:
//!
//! - **Tier 1 (01-03)**: Zero dependencies - works immediately
//! - **Tier 2 (04-07)**: Requires LLM provider (`nika provider set anthropic`)
//! - **Tier 3 (08-09)**: Agent with file tools
//! - **Tier 4 (10)**: MCP integration (`nika mcp add novanet`)
//! - **Tier 5 (11-20)**: Developer use cases (complex DAGs)
//! - **Tier 6 (21-30)**: Everyday magic (non-tech use cases)
//!
//! ## Usage
//!
//! ```rust,ignore
//! use nika::init::{WORKFLOWS, CONTEXT_FILES, SCHEMAS, PARTIALS, README};
//! ```

mod context;
mod partials;
mod schemas;
mod tier1;
mod tier2;
mod tier3;
mod tier4;
mod tier5;
mod tier6;

pub use context::*;
pub use partials::*;
pub use schemas::*;
pub use tier1::*;
pub use tier2::*;
pub use tier3::*;
pub use tier4::*;
pub use tier5::*;
pub use tier6::*;

/// Workflow definition with metadata
pub struct WorkflowTemplate {
    /// Filename (e.g., "01-exec-basics.nika.yaml")
    pub filename: &'static str,
    /// Tier subdirectory (e.g., "tier-1-no-deps")
    pub tier_dir: &'static str,
    /// YAML content with ASCII art header
    pub content: &'static str,
}

/// Context file definition
pub struct ContextFile {
    pub filename: &'static str,
    /// Directory within workflows/ (e.g., "context", "schemas")
    pub dir: &'static str,
    pub content: &'static str,
}

/// All workflows organized by tier
pub fn get_all_workflows() -> Vec<WorkflowTemplate> {
    let mut workflows = Vec::with_capacity(30);

    // Tier 1: No dependencies
    workflows.extend(tier1::get_tier1_workflows());

    // Tier 2: LLM required
    workflows.extend(tier2::get_tier2_workflows());

    // Tier 3: Agent + file tools
    workflows.extend(tier3::get_tier3_workflows());

    // Tier 4: MCP integration
    workflows.extend(tier4::get_tier4_workflows());

    // Tier 5: Dev use cases
    workflows.extend(tier5::get_tier5_workflows());

    // Tier 6: Everyday magic
    workflows.extend(tier6::get_tier6_workflows());

    workflows
}

/// All context files
pub fn get_all_context_files() -> Vec<ContextFile> {
    context::get_context_files()
}

/// All JSON schemas
pub fn get_all_schemas() -> Vec<ContextFile> {
    schemas::get_schema_files()
}

/// All partial workflows
pub fn get_all_partials() -> Vec<ContextFile> {
    partials::get_partial_files()
}

/// README content for workflows directory
pub const WORKFLOWS_README: &str = r#"# Nika Example Workflows

> 30 progressive workflows from zero-dependency to full MCP integration.

## Quick Start

```bash
# Tier 1: Works immediately (no API keys needed)
nika run workflows/tier-1-no-deps/01-exec-basics.nika.yaml

# Tier 2: Setup LLM provider first
nika provider set anthropic       # or: openai, mistral, groq, deepseek, gemini
nika run workflows/tier-2-llm/04-infer-basics.nika.yaml

# Tier 3: Agent with file tools
nika run workflows/tier-3-agent/08-agent-basic.nika.yaml

# Tier 4: MCP integration (requires NovaNet)
nika mcp add novanet
nika run workflows/tier-4-mcp/10-mcp-novanet.nika.yaml

# Tier 5-6: Complex use cases
nika run workflows/tier-5-dev/11-code-review-pipeline.nika.yaml
nika run workflows/tier-6-magic/21-morning-briefing.nika.yaml
```

## Tiers Overview

| Tier | Folder | Workflows | Prerequisites | Features |
|------|--------|-----------|---------------|----------|
| 1 | `tier-1-no-deps/` | 01-03 | None | exec, fetch, builtins |
| 2 | `tier-2-llm/` | 04-07 | `nika provider set <name>` | infer, DAG, for_each, context |
| 3 | `tier-3-agent/` | 08-09 | LLM provider | agent, file tools, artifacts |
| 4 | `tier-4-mcp/` | 10 | `nika mcp add novanet` | MCP, NovaNet, invoke |
| 5 | `tier-5-dev/` | 11-20 | LLM + optional MCP | Complex DAGs, real dev workflows |
| 6 | `tier-6-magic/` | 21-30 | LLM | Everyday automation, marketing, fun |

## Provider Setup

```bash
# Check available providers
nika provider list

# Set your preferred provider (pick one)
nika provider set anthropic       # Claude (recommended)
nika provider set openai          # GPT-4
nika provider set mistral         # Mistral Large
nika provider set groq            # Groq (fast, free tier)
nika provider set deepseek        # DeepSeek
nika provider set gemini          # Google Gemini
```

## Local Models (Native Inference)

Run LLMs locally without API keys using Nika's native mistral.rs runtime:

```bash
# Download a GGUF model (e.g., from HuggingFace)
nika model pull llama3.2:1b           # Small, fast
nika model pull mistral:7b-instruct   # Good balance
nika model pull qwen2.5:7b            # Multilingual

# List installed models
nika model list
```

Use in workflows with `provider: native`:

```yaml
tasks:
  - id: local_infer
    infer:
      provider: native
      model: ~/.cache/huggingface/models/llama3.2-1b-q4.gguf
      prompt: "Explain quantum computing in simple terms"
      temperature: 0.7
```

**Benefits:**
- 🔒 Complete privacy (no data leaves your machine)
- 💰 No API costs
- 🔌 Works offline
- âš¡ Fast inference with Metal (macOS) or CUDA (Linux)

## MCP Setup (Tier 4+)

```bash
# Add NovaNet MCP server
nika mcp add novanet

# Verify MCP connection
nika mcp test novanet
```

## Workflow Index

### Tier 1: Zero Dependencies
- `01-exec-basics` - Shell commands, env vars, timeouts
- `02-fetch-http` - HTTP requests, headers, JSON parsing
- `03-builtins-core` - nika:log, nika:sleep, nika:emit, nika:assert

### Tier 2: LLM Required
- `04-infer-basics` - LLM prompts, temperature, system prompts
- `05-dag-patterns` - Diamond DAG, fan-out/fan-in
- `06-parallel-foreach` - for_each with concurrency
- `07-context-include` - File loading, DAG fusion, skills

### Tier 3: Agent + Tools
- `08-agent-basic` - Agent with file tools, stop conditions
- `09-structured-output` - JSON Schema validation, artifacts

### Tier 4: MCP Integration
- `10-mcp-novanet` - NovaNet queries, knowledge graph

### Tier 5: Developer Use Cases
- `11-code-review-pipeline` - Multi-file code analysis
- `12-content-localization` - Multi-locale content generation
- `13-seo-content-generator` - SEO-optimized articles
- `14-documentation-generator` - Auto-generate docs from code
- `15-data-etl-pipeline` - Extract, transform, load
- `16-research-assistant` - Nested agents, deep research
- `17-pr-review-bot` - Git diff analysis
- `18-meeting-processor` - Extract action items
- `19-api-health-checker` - Endpoint monitoring
- `20-knowledge-extractor` - Entity extraction to graph

### Tier 6: Everyday Magic
- `21-morning-briefing` - Daily summary (weather, news, calendar)
- `22-social-media-planner` - Week of posts in 2 minutes
- `23-competitor-spy` - Competitive intelligence
- `24-email-composer` - Perfect emails in any tone
- `25-recipe-meal-planner` - Weekly menu + grocery list
- `26-travel-planner` - Complete trip itinerary
- `27-birthday-party-planner` - Party planning kit
- `28-podcast-show-notes` - Transcript to content package
- `29-product-review-analyzer` - "Should I buy this?"
- `30-newsletter-curator` - Auto-curate newsletters

## Learn More

- [Nika Documentation](https://github.com/supernovae-studio/nika)
- [Nika CLI](https://github.com/supernovae-studio/nika)
- [NovaNet](https://github.com/supernovae-studio/novanet)
"#;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_all_workflows_exist() {
        let workflows = get_all_workflows();
        assert_eq!(workflows.len(), 30, "Should have exactly 30 workflows");
    }

    #[test]
    fn test_workflow_tiers() {
        let workflows = get_all_workflows();

        // Count workflows per tier
        let tier1 = workflows
            .iter()
            .filter(|w| w.tier_dir == "tier-1-no-deps")
            .count();
        let tier2 = workflows
            .iter()
            .filter(|w| w.tier_dir == "tier-2-llm")
            .count();
        let tier3 = workflows
            .iter()
            .filter(|w| w.tier_dir == "tier-3-agent")
            .count();
        let tier4 = workflows
            .iter()
            .filter(|w| w.tier_dir == "tier-4-mcp")
            .count();
        let tier5 = workflows
            .iter()
            .filter(|w| w.tier_dir == "tier-5-dev")
            .count();
        let tier6 = workflows
            .iter()
            .filter(|w| w.tier_dir == "tier-6-magic")
            .count();

        assert_eq!(tier1, 3, "Tier 1 should have 3 workflows");
        assert_eq!(tier2, 4, "Tier 2 should have 4 workflows");
        assert_eq!(tier3, 2, "Tier 3 should have 2 workflows");
        assert_eq!(tier4, 1, "Tier 4 should have 1 workflow");
        assert_eq!(tier5, 10, "Tier 5 should have 10 workflows");
        assert_eq!(tier6, 10, "Tier 6 should have 10 workflows");
    }

    #[test]
    fn test_workflow_filenames_unique() {
        let workflows = get_all_workflows();
        let mut filenames: Vec<&str> = workflows.iter().map(|w| w.filename).collect();
        let len_before = filenames.len();
        filenames.sort();
        filenames.dedup();
        assert_eq!(
            filenames.len(),
            len_before,
            "All workflow filenames should be unique"
        );
    }

    #[test]
    fn test_workflow_filenames_format() {
        let workflows = get_all_workflows();
        for w in &workflows {
            assert!(
                w.filename.ends_with(".nika.yaml"),
                "Workflow {} should end with .nika.yaml",
                w.filename
            );
            assert!(
                w.filename.starts_with(char::is_numeric),
                "Workflow {} should start with a number",
                w.filename
            );
        }
    }

    #[test]
    fn test_workflows_have_schema() {
        let workflows = get_all_workflows();
        for w in &workflows {
            assert!(
                w.content.contains("schema: \"nika/workflow@0.12\"")
                    || w.content.contains("schema: 'nika/workflow@0.12'")
                    || w.content.contains("schema: nika/workflow@0.12"),
                "Workflow {} should have schema declaration",
                w.filename
            );
        }
    }

    #[test]
    fn test_workflows_have_workflow_name() {
        let workflows = get_all_workflows();
        for w in &workflows {
            assert!(
                w.content.contains("workflow:"),
                "Workflow {} should have workflow: declaration",
                w.filename
            );
        }
    }

    #[test]
    fn test_workflows_have_tasks() {
        let workflows = get_all_workflows();
        for w in &workflows {
            assert!(
                w.content.contains("tasks:"),
                "Workflow {} should have tasks: section",
                w.filename
            );
        }
    }

    #[test]
    fn test_context_files_exist() {
        let files = get_all_context_files();
        assert!(files.len() >= 5, "Should have at least 5 context files");
    }

    #[test]
    fn test_schema_files_exist() {
        let files = get_all_schemas();
        assert!(files.len() >= 5, "Should have at least 5 schema files");
    }

    #[test]
    fn test_schema_files_valid_json() {
        let files = get_all_schemas();
        for f in &files {
            assert!(
                f.filename.ends_with(".schema.json"),
                "Schema {} should end with .schema.json",
                f.filename
            );
            // Parse as JSON to verify validity
            let parsed: Result<serde_json::Value, _> = serde_json::from_str(f.content);
            assert!(
                parsed.is_ok(),
                "Schema {} should be valid JSON: {:?}",
                f.filename,
                parsed.err()
            );
        }
    }

    #[test]
    fn test_partial_files_exist() {
        let files = get_all_partials();
        assert!(files.len() >= 5, "Should have at least 5 partial files");
    }

    #[test]
    fn test_readme_exists() {
        assert!(!WORKFLOWS_README.is_empty(), "README should not be empty");
        assert!(
            WORKFLOWS_README.contains("Nika Example Workflows"),
            "README should have title"
        );
        assert!(
            WORKFLOWS_README.contains("Quick Start"),
            "README should have Quick Start section"
        );
    }

    #[test]
    fn test_workflows_valid_yaml() {
        let workflows = get_all_workflows();
        for w in &workflows {
            // Parse as YAML to verify validity
            let parsed: Result<serde_json::Value, _> = crate::serde_yaml::from_str(w.content);
            assert!(
                parsed.is_ok(),
                "Workflow {} should be valid YAML: {:?}",
                w.filename,
                parsed.err()
            );
        }
    }

    #[test]
    fn test_partials_valid_yaml() {
        let partials = get_all_partials();
        for p in &partials {
            let parsed: Result<serde_json::Value, _> = crate::serde_yaml::from_str(p.content);
            assert!(
                parsed.is_ok(),
                "Partial {} should be valid YAML: {:?}",
                p.filename,
                parsed.err()
            );
        }
    }
}