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
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
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
//! Workflow templates for `nika new`
//!
//! Contains embedded templates for common workflow patterns.
//! Each template is a function that generates YAML content.

use super::Template;

/// Generate template content based on template type and workflow name
pub fn generate_template(template: Template, workflow_name: &str) -> String {
    match template {
        Template::SimpleInfer => simple_infer(workflow_name),
        Template::SimpleExec => simple_exec(workflow_name),
        Template::SimpleFetch => simple_fetch(workflow_name),
        Template::ApiPipeline => api_pipeline(workflow_name),
        Template::BlogGenerator => blog_generator(workflow_name),
        Template::CodeReview => code_review(workflow_name),
        Template::AgentResearch => agent_research(workflow_name),
        Template::AgentBrowser => agent_browser(workflow_name),
        Template::McpIntegration => mcp_integration(workflow_name),
        Template::MultiProvider => multi_provider(workflow_name),
        Template::DataPipeline => data_pipeline(workflow_name),
        Template::MorningBriefing => morning_briefing(workflow_name),
        Template::GitChangelog => git_changelog(workflow_name),
        Template::ParallelTranslation => parallel_translation(workflow_name),
        Template::AgentQaTester => agent_qa_tester(workflow_name),
    }
}

/// Simple infer template - basic LLM text generation
fn simple_infer(name: &str) -> String {
    format!(
        r#"# {name}
#
# Simple LLM text generation example.
# Demonstrates the infer verb with basic configuration.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable

schema: "nika/workflow@0.12"
workflow: {name}
description: "Simple text generation with LLM"

provider: claude
model: claude-sonnet-4-6

tasks:
  - id: generate
    description: "Generate creative text"
    infer:
      prompt: |
        Write a short, creative paragraph about technology.
        Be engaging and informative.
    output:
      format: text

  - id: display
    description: "Display the result"
    with:
      content: $generate
    exec:
      command: |
        echo "Generated content:"
        echo "=================="
        echo "{{{{with.content}}}}"
      shell: true
    depends_on: [generate]
"#
    )
}

/// Simple shell template - shell command invocation
fn simple_exec(name: &str) -> String {
    format!(
        r#"# {name}
#
# Shell command invocation example.
# Demonstrates the exec verb with shell commands.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - None (no API keys needed)

schema: "nika/workflow@0.12"
workflow: {name}
description: "Shell command invocation workflow"

tasks:
  - id: system_info
    description: "Get system information"
    exec:
      command: |
        echo "=== System Information ==="
        echo "Date: $(date)"
        echo "User: $USER"
        echo "PWD: $PWD"
      shell: true
    output:
      format: text

  - id: list_files
    description: "List current directory"
    exec:
      command: "ls -la"
      shell: true
    output:
      format: text

  - id: summary
    description: "Create summary"
    with:
      info: $system_info
      files: $list_files
    exec:
      command: |
        echo "=== Workflow Complete ==="
        echo "System info collected"
        echo "Files listed"
      shell: true
    depends_on: [system_info, list_files]
"#
    )
}

/// Simple fetch template - HTTP requests
fn simple_fetch(name: &str) -> String {
    format!(
        r#"# {name}
#
# HTTP request example.
# Demonstrates the fetch verb with different methods.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - Internet connection

schema: "nika/workflow@0.12"
workflow: {name}
description: "HTTP request workflow"

tasks:
  - id: get_zen
    description: "Get GitHub zen quote"
    fetch:
      url: "https://api.github.com/zen"
      method: GET
      headers:
        Accept: text/plain
    output:
      format: text

  - id: get_user
    description: "Get GitHub user info"
    fetch:
      url: "https://api.github.com/users/octocat"
      method: GET
      headers:
        Accept: application/json
    output:
      format: json

  - id: display
    description: "Display results"
    with:
      zen: $get_zen
      user: $get_user
    exec:
      command: |
        echo "GitHub Zen: {{{{with.zen}}}}"
        echo ""
        echo "User: {{{{with.user.login}}}}"
        echo "Name: {{{{with.user.name}}}}"
      shell: true
    depends_on: [get_zen, get_user]
"#
    )
}

/// API pipeline template - multi-step data processing
fn api_pipeline(name: &str) -> String {
    format!(
        r#"# {name}
#
# Multi-step API data processing pipeline.
# Fetches data, transforms it with LLM, and saves results.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable
#   - Internet connection

schema: "nika/workflow@0.12"
workflow: {name}
description: "API data processing pipeline"

provider: claude
model: claude-sonnet-4-6

artifacts:
  dir: ./output/{{{{workflow_name}}}}
  format: json
  manifest: true

tasks:
  - id: fetch_data
    description: "Fetch data from API"
    fetch:
      url: "https://jsonplaceholder.typicode.com/posts?_limit=5"
      method: GET
      headers:
        Accept: application/json
    output:
      format: json

  - id: analyze
    description: "Analyze fetched data"
    with:
      posts: $fetch_data
    infer:
      prompt: |
        Analyze these blog posts and provide a summary:

        {{{{with.posts | to_yaml}}}}

        Return JSON with:
        - total_posts: number of posts
        - avg_title_length: average title length
        - topics: list of main topics covered
    output:
      format: json
      schema:
        type: object
        required: [total_posts, topics]
        properties:
          total_posts:
            type: integer
          avg_title_length:
            type: number
          topics:
            type: array
            items:
              type: string
    artifact:
      path: analysis.json
    depends_on: [fetch_data]

  - id: generate_report
    description: "Generate markdown report"
    with:
      analysis: $analyze
    infer:
      prompt: |
        Create a brief markdown report based on this analysis:

        {{{{with.analysis | to_yaml}}}}

        Include:
        - Summary statistics
        - Key topics identified
        - Recommendations
    output:
      format: text
    artifact:
      path: report.md
      format: text
    depends_on: [analyze]
"#
    )
}

/// Blog generator template - content generation pipeline
fn blog_generator(name: &str) -> String {
    format!(
        r#"# {name}
#
# Blog content generation pipeline.
# Researches topics, creates outline, writes article.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable

schema: "nika/workflow@0.12"
workflow: {name}
description: "Blog content generation pipeline"

provider: claude
model: claude-sonnet-4-6

inputs:
  topic:
    type: string
    description: "Blog topic to write about"
    default: "artificial intelligence in 2026"
  word_count:
    type: integer
    description: "Target word count"
    default: 1500

artifacts:
  dir: ./content/{{{{date}}}}/{{{{workflow_name}}}}
  format: json
  manifest: true

tasks:
  - id: research
    description: "Research the topic"
    infer:
      prompt: |
        Research the topic: "{{{{inputs.topic}}}}"

        Provide:
        1. Key points to cover
        2. Current trends
        3. Expert opinions
        4. Data and statistics

        Return as structured JSON.
    output:
      format: json
      schema:
        type: object
        required: [key_points, trends]
        properties:
          key_points:
            type: array
            items:
              type: string
          trends:
            type: array
            items:
              type: string
          statistics:
            type: array
            items:
              type: string
    artifact:
      path: research.json

  - id: outline
    description: "Create article outline"
    with:
      research: $research
    infer:
      prompt: |
        Based on this research, create a detailed blog post outline:

        {{{{with.research | to_yaml}}}}

        Create an outline with:
        - Compelling title
        - Introduction hook
        - 4-5 main sections with subsections
        - Conclusion with CTA

        Target word count: {{{{inputs.word_count}}}}
    output:
      format: text
    artifact:
      path: outline.md
      format: text
    depends_on: [research]

  - id: write
    description: "Write the article"
    with:
      research: $research
      outline: $outline
    infer:
      prompt: |
        Write a complete blog post following this outline:

        {{{{with.outline}}}}

        Research context:
        {{{{with.research | to_yaml}}}}

        Requirements:
        - Engaging, professional tone
        - Target: {{{{inputs.word_count}}}} words
        - Include practical examples
        - End with clear CTA

        Output as markdown.
    output:
      format: text
    artifact:
      path: article.md
      format: text
    depends_on: [outline]

  - id: metadata
    description: "Generate SEO metadata"
    with:
      article: $write
    infer:
      prompt: |
        Generate SEO metadata for this article:

        {{{{with.article | truncate: 500}}}}

        Return JSON with:
        - seo_title (55-60 chars)
        - meta_description (155-160 chars)
        - keywords (5-7 terms)
        - og_description
    output:
      format: json
      schema:
        type: object
        required: [seo_title, meta_description, keywords]
        properties:
          seo_title:
            type: string
          meta_description:
            type: string
          keywords:
            type: array
            items:
              type: string
          og_description:
            type: string
    artifact:
      path: metadata.json
    depends_on: [write]
"#
    )
}

/// Code review template - code analysis assistant
fn code_review(name: &str) -> String {
    format!(
        r#"# {name}
#
# Code review assistant workflow.
# Analyzes code for issues, suggests improvements.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable

schema: "nika/workflow@0.12"
workflow: {name}
description: "Code review assistant"

provider: claude
model: claude-sonnet-4-6

inputs:
  file_path:
    type: string
    description: "Path to file to review"
    default: "src/main.rs"

tasks:
  - id: read_code
    description: "Read the source file"
    exec:
      command: |
        if [ -f "{{{{inputs.file_path}}}}" ]; then
          cat "{{{{inputs.file_path}}}}"
        else
          echo "File not found: {{{{inputs.file_path}}}}"
          exit 1
        fi
      shell: true
    output:
      format: text

  - id: analyze
    description: "Analyze code quality"
    with:
      code: $read_code
    infer:
      prompt: |
        Perform a comprehensive code review on this code:

        ```
        {{{{with.code}}}}
        ```

        Analyze for:
        1. Code quality and best practices
        2. Potential bugs or issues
        3. Performance concerns
        4. Security vulnerabilities
        5. Readability and maintainability

        Return JSON with categorized findings.
    output:
      format: json
      schema:
        type: object
        required: [quality_score, issues, suggestions]
        properties:
          quality_score:
            type: integer
            minimum: 0
            maximum: 100
          issues:
            type: array
            items:
              type: object
              properties:
                severity:
                  type: string
                  enum: [critical, high, medium, low]
                line:
                  type: integer
                description:
                  type: string
          suggestions:
            type: array
            items:
              type: string
          security_concerns:
            type: array
            items:
              type: string
    depends_on: [read_code]

  - id: report
    description: "Generate review report"
    with:
      analysis: $analyze
      code: $read_code
    infer:
      prompt: |
        Create a markdown code review report based on:

        Analysis:
        {{{{with.analysis | to_yaml}}}}

        Include:
        - Overall summary
        - Quality score with explanation
        - Detailed findings by severity
        - Specific recommendations with code examples
        - Action items
    output:
      format: text
    depends_on: [analyze]
"#
    )
}

/// Agent research template - research agent with MCP
fn agent_research(name: &str) -> String {
    format!(
        r#"# {name}
#
# Research agent with web search capabilities.
# Uses MCP servers for real-time web research.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable
#   - PERPLEXITY_API_KEY environment variable

schema: "nika/workflow@0.12"
workflow: {name}
description: "Research agent with MCP web search"

provider: claude
model: claude-sonnet-4-6

mcp:
  perplexity:
    command: npx
    args: ["-y", "@perplexity-ai/mcp-server"]

inputs:
  research_topic:
    type: string
    description: "Topic to research"
    default: "latest developments in AI agents"

tasks:
  - id: research
    description: "Conduct web research"
    agent:
      prompt: |
        You are a thorough research agent.

        Research the topic: "{{{{inputs.research_topic}}}}"

        Use perplexity_search to:
        1. Find the latest news and developments
        2. Identify key players and companies
        3. Gather statistics and data
        4. Find expert opinions

        Compile a comprehensive research report.
        End with "RESEARCH_COMPLETE" when done.
      mcp: [perplexity]
      max_turns: 10
    output:
      format: json
      schema:
        type: object
        required: [topic, findings, sources]
        properties:
          topic:
            type: string
          findings:
            type: array
            items:
              type: object
              properties:
                category:
                  type: string
                content:
                  type: string
          key_players:
            type: array
            items:
              type: string
          statistics:
            type: array
            items:
              type: string
          sources:
            type: array
            items:
              type: string

  - id: synthesize
    description: "Synthesize findings into report"
    with:
      research: $research
    infer:
      prompt: |
        Create a summary from this research:

        {{{{with.research | to_yaml}}}}

        Format as a professional brief with:
        - Summary (3-5 sentences)
        - Key findings
        - Implications
        - Recommendations
    output:
      format: text
    depends_on: [research]
"#
    )
}

/// Agent browser template - browser automation
fn agent_browser(name: &str) -> String {
    format!(
        r#"# {name}
#
# Browser automation agent.
# Uses Playwright MCP for web automation.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable
#   - Playwright MCP server

schema: "nika/workflow@0.12"
workflow: {name}
description: "Browser automation agent"

provider: claude
model: claude-sonnet-4-6

mcp:
  playwright:
    command: npx
    args: ["-y", "@anthropic/mcp-server-playwright"]

inputs:
  target_url:
    type: string
    description: "URL to automate"
    default: "https://example.com"

tasks:
  - id: browse
    description: "Automate browser interaction"
    agent:
      prompt: |
        You are a browser automation agent.

        Navigate to: {{{{inputs.target_url}}}}

        Tasks:
        1. Open the page
        2. Wait for content to load
        3. Extract the main heading and key content
        4. Take a screenshot
        5. Report what you found

        Use the playwright tools to interact with the browser.
        End with "AUTOMATION_COMPLETE" when done.
      mcp: [playwright]
      max_turns: 15
    output:
      format: json
      schema:
        type: object
        required: [url, title, content_summary]
        properties:
          url:
            type: string
          title:
            type: string
          content_summary:
            type: string
          links_found:
            type: integer
          screenshot_path:
            type: string

  - id: report
    description: "Generate automation report"
    with:
      result: $browse
    exec:
      command: |
        echo "=== Browser Automation Report ==="
        echo "URL: {{{{with.result.url}}}}"
        echo "Title: {{{{with.result.title}}}}"
        echo ""
        echo "Summary:"
        echo "{{{{with.result.content_summary}}}}"
      shell: true
    depends_on: [browse]
"#
    )
}

/// MCP integration template - MCP server usage
fn mcp_integration(name: &str) -> String {
    format!(
        r#"# {name}
#
# MCP server integration example.
# Demonstrates using multiple MCP servers.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable
#   - FIRECRAWL_API_KEY environment variable

schema: "nika/workflow@0.12"
workflow: {name}
description: "MCP server integration example"

provider: claude
model: claude-sonnet-4-6

mcp:
  firecrawl:
    command: npx
    args: ["-y", "firecrawl-mcp"]

  filesystem:
    command: npx
    args: ["-y", "@anthropic/mcp-server-filesystem", "--root", "."]

tasks:
  - id: scrape_page
    description: "Scrape a webpage"
    invoke:
      server: firecrawl
      tool: firecrawl_scrape
      params:
        url: "https://news.ycombinator.com"
        formats: ["markdown"]
        onlyMainContent: true
    output:
      format: json

  - id: analyze_content
    description: "Analyze scraped content"
    with:
      page: $scrape_page
    infer:
      prompt: |
        Analyze this webpage content:

        {{{{with.page.markdown | truncate: 2000}}}}

        Extract:
        - Top 5 story headlines
        - Main topics covered
        - Content sentiment
    output:
      format: json
      schema:
        type: object
        required: [headlines, topics]
        properties:
          headlines:
            type: array
            items:
              type: string
            maxItems: 5
          topics:
            type: array
            items:
              type: string
          sentiment:
            type: string
            enum: [positive, neutral, negative]
    depends_on: [scrape_page]

  - id: save_analysis
    description: "Save analysis to file"
    with:
      analysis: $analyze_content
    invoke:
      server: filesystem
      tool: write_file
      params:
        path: "analysis-output.json"
        content: "{{{{with.analysis | to_json}}}}"
    depends_on: [analyze_content]
"#
    )
}

/// Multi-provider template - using multiple LLM providers
fn multi_provider(name: &str) -> String {
    format!(
        r#"# {name}
#
# Multi-provider workflow example.
# Uses different LLM providers for different tasks.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable
#   - OPENAI_API_KEY environment variable

schema: "nika/workflow@0.12"
workflow: {name}
description: "Multi-provider LLM workflow"

# Default provider (can be overridden per task)
provider: claude
model: claude-sonnet-4-6

inputs:
  question:
    type: string
    description: "Question to ask multiple providers"
    default: "What are the key trends in AI for 2026?"

tasks:
  - id: claude_response
    description: "Get response from Claude"
    provider: claude
    model: claude-sonnet-4-6
    infer:
      prompt: |
        Answer this question concisely:
        {{{{inputs.question}}}}
    output:
      format: text

  - id: openai_response
    description: "Get response from OpenAI"
    provider: openai
    model: gpt-4o
    infer:
      prompt: |
        Answer this question concisely:
        {{{{inputs.question}}}}
    output:
      format: text

  - id: compare
    description: "Compare responses"
    with:
      claude: $claude_response
      openai: $openai_response
    infer:
      prompt: |
        Compare these two AI responses:

        Claude's response:
        {{{{with.claude}}}}

        OpenAI's response:
        {{{{with.openai}}}}

        Analyze:
        1. Key similarities
        2. Key differences
        3. Which response is more comprehensive
        4. Synthesis of best points from both
    output:
      format: json
      schema:
        type: object
        required: [similarities, differences, recommendation]
        properties:
          similarities:
            type: array
            items:
              type: string
          differences:
            type: array
            items:
              type: string
          more_comprehensive:
            type: string
            enum: [claude, openai, both]
          recommendation:
            type: string
    depends_on: [claude_response, openai_response]

  - id: final_answer
    description: "Generate synthesized answer"
    with:
      comparison: $compare
      claude: $claude_response
      openai: $openai_response
    infer:
      prompt: |
        Create the best possible answer by synthesizing insights from both AI responses:

        Comparison analysis:
        {{{{with.comparison | to_yaml}}}}

        Original question: {{{{inputs.question}}}}

        Provide a comprehensive, well-structured answer.
    output:
      format: text
    depends_on: [compare]
"#
    )
}

/// Data pipeline template - ETL pattern
fn data_pipeline(name: &str) -> String {
    format!(
        r#"# {name}
#
# ETL data pipeline workflow.
# Extracts data from API, transforms with LLM, loads to output.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable
#   - Internet connection

schema: "nika/workflow@0.12"
workflow: {name}
description: "ETL data pipeline with fetch, transform, and load"

provider: claude
model: claude-sonnet-4-6

inputs:
  source_url:
    type: string
    description: "Data source URL"
    default: "https://jsonplaceholder.typicode.com/posts?_limit=10"
  output_format:
    type: string
    description: "Output format (json/csv)"
    default: "json"

artifacts:
  dir: ./data/{{{{date}}}}/{{{{workflow_name}}}}
  format: json
  manifest: true

tasks:
  # Extract: Fetch raw data
  - id: extract
    description: "Extract data from source"
    fetch:
      url: "{{{{inputs.source_url}}}}"
      method: GET
      headers:
        Accept: application/json
    output:
      format: json

  # Transform: Clean and enrich data
  - id: transform
    description: "Transform and enrich data"
    with:
      raw_data: $extract
    infer:
      prompt: |
        Transform this raw data into a clean, enriched format:

        Raw Data:
        {{{{with.raw_data | to_yaml}}}}

        Requirements:
        1. Clean any malformed entries
        2. Add a "processed_at" timestamp
        3. Calculate summary statistics
        4. Categorize items if applicable

        Return as JSON with:
        - records: cleaned data array
        - stats: summary statistics object
        - metadata: processing info
    output:
      format: json
      schema:
        type: object
        required: [records, stats]
        properties:
          records:
            type: array
          stats:
            type: object
            properties:
              total_records:
                type: integer
              categories:
                type: object
          metadata:
            type: object
    artifact:
      path: transformed.json
    depends_on: [extract]

  # Load: Save processed data
  - id: load
    description: "Load data to output"
    with:
      data: $transform
    exec:
      command: |
        echo "Data pipeline complete!"
        echo "Records processed: {{{{with.data.stats.total_records}}}}"
        echo "Output saved to artifacts directory"
      shell: true
    depends_on: [transform]
"#
    )
}

/// Morning briefing template - daily digest
fn morning_briefing(name: &str) -> String {
    format!(
        r#"# {name}
#
# Morning briefing workflow.
# Generates a daily digest with news, weather, and tasks.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable

schema: "nika/workflow@0.12"
workflow: {name}
description: "Daily digest with news, weather, and tasks"

provider: claude
model: claude-sonnet-4-6

inputs:
  location:
    type: string
    description: "Location for weather"
    default: "San Francisco, CA"
  interests:
    type: array
    description: "Topics of interest"
    default: ["technology", "AI", "startups"]

artifacts:
  dir: ./briefings/{{{{date}}}}
  format: json
  manifest: true

tasks:
  # Get current date/time
  - id: get_datetime
    description: "Get current date and time"
    exec:
      command: "date '+%A, %B %d, %Y at %H:%M'"
      shell: true
    output:
      format: text

  # Generate weather summary (mock - replace with real API)
  - id: weather
    description: "Generate weather summary"
    infer:
      prompt: |
        Generate a realistic weather forecast for {{{{inputs.location}}}} for today.

        Include:
        - Current temperature
        - High/low for the day
        - Conditions (sunny, cloudy, rain, etc.)
        - Recommendation (umbrella, sunscreen, etc.)

        Return as JSON.
    output:
      format: json
      schema:
        type: object
        required: [temperature, high, low, conditions]
        properties:
          temperature:
            type: string
          high:
            type: string
          low:
            type: string
          conditions:
            type: string
          recommendation:
            type: string

  # Generate news summary
  - id: news
    description: "Generate news highlights"
    infer:
      prompt: |
        Generate 5 plausible tech/AI news headlines for today.
        These should be realistic examples of current industry news.

        Topics of interest: {{{{inputs.interests | to_yaml}}}}

        Return as JSON array of objects with title and summary.
    output:
      format: json
      schema:
        type: object
        required: [headlines]
        properties:
          headlines:
            type: array
            items:
              type: object
              properties:
                title:
                  type: string
                summary:
                  type: string

  # Compile briefing
  - id: compile
    description: "Compile morning briefing"
    with:
      datetime: $get_datetime
      weather: $weather
      news: $news
    infer:
      prompt: |
        Create a friendly morning briefing email based on:

        Date: {{{{with.datetime}}}}

        Weather:
        {{{{with.weather | to_yaml}}}}

        News Headlines:
        {{{{with.news | to_yaml}}}}

        Format as a professional but warm morning email.
        Include:
        - Greeting with date
        - Weather summary
        - Top news highlights
        - Motivational closing
    output:
      format: text
    artifact:
      path: briefing.md
      format: text
    depends_on: [get_datetime, weather, news]
"#
    )
}

/// Git changelog template
fn git_changelog(name: &str) -> String {
    format!(
        r#"# {name}
#
# Git changelog generator workflow.
# Analyzes git commits and generates a changelog.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable
#   - Git repository

schema: "nika/workflow@0.12"
workflow: {name}
description: "Git commit analysis and changelog generation"

provider: claude
model: claude-sonnet-4-6

inputs:
  commit_range:
    type: string
    description: "Git commit range"
    default: "HEAD~10..HEAD"
  output_format:
    type: string
    description: "Output format"
    default: "markdown"

artifacts:
  dir: ./changelogs
  format: text
  manifest: true

tasks:
  # Get git log
  - id: git_log
    description: "Get git commit history"
    exec:
      command: |
        git log {{{{inputs.commit_range}}}} \
          --pretty=format:'%h|%s|%an|%ad' \
          --date=short 2>/dev/null || echo "No commits found"
      shell: true
    output:
      format: text

  # Get detailed diff stats
  - id: diff_stats
    description: "Get diff statistics"
    exec:
      command: |
        git diff --stat {{{{inputs.commit_range}}}} 2>/dev/null || echo "No changes"
      shell: true
    output:
      format: text

  # Analyze commits
  - id: analyze
    description: "Analyze commit patterns"
    with:
      log: $git_log
      stats: $diff_stats
    infer:
      prompt: |
        Analyze these git commits and categorize them:

        Commit Log (hash|subject|author|date):
        {{{{with.log}}}}

        Diff Statistics:
        {{{{with.stats}}}}

        Categorize each commit as:
        - feat: New features
        - fix: Bug fixes
        - docs: Documentation
        - refactor: Code refactoring
        - test: Testing
        - chore: Maintenance

        Return JSON with categorized commits.
    output:
      format: json
      schema:
        type: object
        required: [commits, summary]
        properties:
          commits:
            type: object
            properties:
              feat:
                type: array
              fix:
                type: array
              docs:
                type: array
              refactor:
                type: array
              test:
                type: array
              chore:
                type: array
          summary:
            type: object
            properties:
              total_commits:
                type: integer
              files_changed:
                type: integer
              contributors:
                type: array
    depends_on: [git_log, diff_stats]

  # Generate changelog
  - id: changelog
    description: "Generate formatted changelog"
    with:
      analysis: $analyze
    infer:
      prompt: |
        Generate a professional changelog from this analysis:

        {{{{with.analysis | to_yaml}}}}

        Format: {{{{inputs.output_format}}}}

        Include:
        - Version header (use date as version)
        - Sections for each category (Features, Bug Fixes, etc.)
        - Contributor acknowledgments
        - Keep it concise and scannable
    output:
      format: text
    artifact:
      path: CHANGELOG-{{{{date}}}}.md
      format: text
    depends_on: [analyze]
"#
    )
}

/// Parallel translation template
fn parallel_translation(name: &str) -> String {
    format!(
        r#"# {name}
#
# Parallel translation workflow.
# Translates content to multiple languages using for_each.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable

schema: "nika/workflow@0.12"
workflow: {name}
description: "Multi-language translation with for_each"

provider: claude
model: claude-sonnet-4-6

inputs:
  source_text:
    type: string
    description: "Text to translate"
    default: "Welcome to our platform! We help businesses scale with AI."
  source_lang:
    type: string
    description: "Source language"
    default: "English"

artifacts:
  dir: ./translations/{{{{date}}}}
  format: json
  manifest: true

tasks:
  # Define target languages
  - id: setup
    description: "Setup translation targets"
    exec:
      command: "echo 'Preparing translations...'"
      shell: true
    output:
      format: text

  # Parallel translation to all languages
  - id: translate
    description: "Translate to multiple languages"
    for_each: ["French", "Spanish", "German", "Japanese", "Chinese", "Portuguese"]
    as: target_lang
    concurrency: 6
    infer:
      prompt: |
        Translate the following text from {{{{inputs.source_lang}}}} to {{{{with.target_lang}}}}.

        Source text:
        "{{{{inputs.source_text}}}}"

        Requirements:
        - Maintain the tone and intent
        - Use natural, native-sounding language
        - Preserve any technical terms appropriately

        Return JSON with translation details.
    output:
      format: json
      schema:
        type: object
        required: [language, translation]
        properties:
          language:
            type: string
          translation:
            type: string
          notes:
            type: string
    artifact:
      path: "{{{{with.target_lang | lowercase}}}}.json"
    depends_on: [setup]

  # Compile all translations
  - id: compile
    description: "Compile translation summary"
    with:
      translations: $translate
    infer:
      prompt: |
        Create a translation summary report from:

        {{{{with.translations | to_yaml}}}}

        Include:
        - Source text and language
        - Table of all translations
        - Any notable localization challenges
        - Recommendations for each market
    output:
      format: text
    artifact:
      path: summary.md
      format: text
    depends_on: [translate]
"#
    )
}

/// QA testing agent template
fn agent_qa_tester(name: &str) -> String {
    format!(
        r#"# {name}
#
# QA testing agent workflow.
# Generates test cases and validates functionality.
#
# Usage:
#   nika {name}.nika.yaml
#
# Requirements:
#   - ANTHROPIC_API_KEY environment variable

schema: "nika/workflow@0.12"
workflow: {name}
description: "QA testing agent with test generation"

provider: claude
model: claude-sonnet-4-6

inputs:
  feature_description:
    type: string
    description: "Feature to test"
    default: "User login with email and password"
  test_types:
    type: array
    description: "Types of tests to generate"
    default: ["unit", "integration", "edge_cases"]

artifacts:
  dir: ./test-reports/{{{{date}}}}
  format: json
  manifest: true

tasks:
  # Analyze the feature
  - id: analyze_feature
    description: "Analyze feature requirements"
    infer:
      prompt: |
        Analyze this feature for testing:

        Feature: {{{{inputs.feature_description}}}}

        Identify:
        1. Core functionality to test
        2. Input parameters and types
        3. Expected outputs
        4. Error conditions
        5. Security considerations

        Return structured analysis as JSON.
    output:
      format: json
      schema:
        type: object
        required: [core_functionality, inputs, outputs]
        properties:
          core_functionality:
            type: array
            items:
              type: string
          inputs:
            type: array
            items:
              type: object
          outputs:
            type: array
          error_conditions:
            type: array
          security_considerations:
            type: array

  # Generate test cases using agent
  - id: generate_tests
    description: "Generate comprehensive test cases"
    with:
      analysis: $analyze_feature
    agent:
      prompt: |
        You are a QA Engineer. Generate test cases for this feature:

        Feature Analysis:
        {{{{with.analysis | to_yaml}}}}

        Test Types Required: {{{{inputs.test_types | to_yaml}}}}

        For each test type, generate:
        1. Test name and description
        2. Preconditions
        3. Test steps
        4. Expected results
        5. Priority (high/medium/low)

        Use the following tools:
        - nika:log to track your progress
        - nika:assert to validate test case format

        Generate at least 3 test cases per type.
        End with "TEST_GENERATION_COMPLETE" when done.
      max_turns: 8
      tools: [nika:log, nika:assert]
    output:
      format: json
      schema:
        type: object
        required: [test_cases]
        properties:
          test_cases:
            type: array
            items:
              type: object
              properties:
                id:
                  type: string
                name:
                  type: string
                type:
                  type: string
                priority:
                  type: string
                preconditions:
                  type: array
                steps:
                  type: array
                expected_results:
                  type: array
    artifact:
      path: test_cases.json
    depends_on: [analyze_feature]

  # Generate test report
  - id: report
    description: "Generate test report"
    with:
      analysis: $analyze_feature
      tests: $generate_tests
    infer:
      prompt: |
        Create a professional QA test plan document:

        Feature Analysis:
        {{{{with.analysis | to_yaml}}}}

        Generated Test Cases:
        {{{{with.tests | to_yaml}}}}

        Include:
        1. Executive Summary
        2. Test Scope
        3. Test Cases (organized by type)
        4. Risk Assessment
        5. Recommended Test Coverage
        6. Next Steps

        Format as markdown.
    output:
      format: text
    artifact:
      path: test_plan.md
      format: text
    depends_on: [generate_tests]
"#
    )
}

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

    #[test]
    fn test_simple_infer_template() {
        let content = simple_infer("test-workflow");
        assert!(content.contains("workflow: test-workflow"));
        assert!(content.contains("infer:"));
        assert!(content.contains("provider: claude"));
    }

    #[test]
    fn test_simple_exec_template() {
        let content = simple_exec("exec-test");
        assert!(content.contains("workflow: exec-test"));
        assert!(content.contains("exec:"));
        assert!(content.contains("shell: true"));
    }

    #[test]
    fn test_simple_fetch_template() {
        let content = simple_fetch("fetch-test");
        assert!(content.contains("workflow: fetch-test"));
        assert!(content.contains("fetch:"));
        assert!(content.contains("method: GET"));
    }

    #[test]
    fn test_api_pipeline_template() {
        let content = api_pipeline("pipeline-test");
        assert!(content.contains("workflow: pipeline-test"));
        assert!(content.contains("artifacts:"));
        assert!(content.contains("fetch:"));
        assert!(content.contains("infer:"));
    }

    #[test]
    fn test_blog_generator_template() {
        let content = blog_generator("blog-test");
        assert!(content.contains("workflow: blog-test"));
        assert!(content.contains("inputs:"));
        assert!(content.contains("research"));
        assert!(content.contains("outline"));
        assert!(content.contains("write"));
    }

    #[test]
    fn test_code_review_template() {
        let content = code_review("review-test");
        assert!(content.contains("workflow: review-test"));
        assert!(content.contains("quality_score"));
        assert!(content.contains("issues"));
    }

    #[test]
    fn test_agent_research_template() {
        let content = agent_research("research-test");
        assert!(content.contains("workflow: research-test"));
        assert!(content.contains("agent:"));
        assert!(content.contains("mcp:"));
        assert!(content.contains("perplexity"));
    }

    #[test]
    fn test_agent_browser_template() {
        let content = agent_browser("browser-test");
        assert!(content.contains("workflow: browser-test"));
        assert!(content.contains("playwright"));
        assert!(content.contains("agent:"));
    }

    #[test]
    fn test_mcp_integration_template() {
        let content = mcp_integration("mcp-test");
        assert!(content.contains("workflow: mcp-test"));
        assert!(content.contains("invoke:"));
        assert!(content.contains("firecrawl"));
        assert!(content.contains("filesystem"));
    }

    #[test]
    fn test_multi_provider_template() {
        let content = multi_provider("multi-test");
        assert!(content.contains("workflow: multi-test"));
        assert!(content.contains("provider: claude"));
        assert!(content.contains("provider: openai"));
        assert!(content.contains("compare"));
    }

    #[test]
    fn test_data_pipeline_template() {
        let content = data_pipeline("etl-test");
        assert!(content.contains("workflow: etl-test"));
        assert!(content.contains("artifacts:"));
        assert!(content.contains("extract"));
        assert!(content.contains("transform"));
        assert!(content.contains("load"));
    }

    #[test]
    fn test_morning_briefing_template() {
        let content = morning_briefing("briefing-test");
        assert!(content.contains("workflow: briefing-test"));
        assert!(content.contains("get_datetime"));
        assert!(content.contains("compile"));
        assert!(content.contains("briefings"));
    }

    #[test]
    fn test_git_changelog_template() {
        let content = git_changelog("changelog-test");
        assert!(content.contains("workflow: changelog-test"));
        assert!(content.contains("git_log"));
        assert!(content.contains("analyze"));
        assert!(content.contains("changelog"));
    }

    #[test]
    fn test_parallel_translation_template() {
        let content = parallel_translation("translate-test");
        assert!(content.contains("workflow: translate-test"));
        assert!(content.contains("for_each:"));
        assert!(content.contains("concurrency:"));
        assert!(content.contains("translations"));
    }

    #[test]
    fn test_agent_qa_tester_template() {
        let content = agent_qa_tester("qa-test");
        assert!(content.contains("workflow: qa-test"));
        assert!(content.contains("agent:"));
        assert!(content.contains("analyze_feature"));
        assert!(content.contains("generate_tests"));
    }

    #[test]
    fn test_all_templates_valid_yaml() {
        for template in Template::ALL {
            let content = generate_template(*template, "test");
            // Basic YAML validation - should contain schema
            assert!(
                content.contains("schema: \"nika/workflow@0.12\""),
                "Template {} missing schema",
                template.name()
            );
        }
    }
}