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
//! Partial Workflows for DAG Fusion
//!
//! These are reusable workflow fragments that can be included
//! in other workflows via the `include:` directive.
//!
//! Usage:
//! ```yaml
//! include:
//!   - path: ./partials/logging-setup.nika.yaml
//!     prefix: log_
//! ```

use super::ContextFile;

/// Directory for partial workflows
pub const PARTIALS_DIR: &str = "partials";

/// Logging setup partial - adds logging tasks to any workflow
pub const PARTIAL_LOGGING: &str = r##"# ═══════════════════════════════════════════════════════════════════════════════
# PARTIAL: LOGGING SETUP
# ═══════════════════════════════════════════════════════════════════════════════
#
# Include this partial to add structured logging to your workflow.
# Use with prefix to namespace task IDs.
#
# Usage:
#   include:
#     - path: ./partials/logging-setup.nika.yaml
#       prefix: log_
#
# This adds tasks: log_start, log_end
# Connect your workflow tasks between them.
#
# ═══════════════════════════════════════════════════════════════════════════════

schema: "nika/workflow@0.12"
workflow: logging-setup-partial
description: "Reusable logging setup tasks"

tasks:
  - id: start
    description: "Log workflow start"
    invoke:
      tool: nika:log
      params:
        level: info
        message: "Workflow started"

  - id: end
    description: "Log workflow completion"
    invoke:
      tool: nika:log
      params:
        level: info
        message: "Workflow completed successfully"
"##;

/// Error handling partial - adds try/catch style error handling
pub const PARTIAL_ERROR_HANDLING: &str = r##"# ═══════════════════════════════════════════════════════════════════════════════
# PARTIAL: ERROR HANDLING
# ═══════════════════════════════════════════════════════════════════════════════
#
# Include this partial for standardized error handling.
# Provides error notification and logging tasks.
#
# Usage:
#   include:
#     - path: ./partials/error-handling.nika.yaml
#       prefix: err_
#
# ═══════════════════════════════════════════════════════════════════════════════

schema: "nika/workflow@0.12"
workflow: error-handling-partial
description: "Standardized error handling tasks"

inputs:
  previous_result: "No result provided"
  error_details: "Unknown error"

tasks:
  - id: check
    description: "Check for errors in previous task"
    infer:
      prompt: |
        Analyze the following result for errors:
        {{inputs.previous_result}}

        Return JSON:
        {
          "has_error": true/false,
          "error_type": "string or null",
          "error_message": "string or null",
          "recoverable": true/false
        }
      temperature: 0.1
      max_tokens: 200

  - id: notify
    description: "Send error notification"
    depends_on: [check]
    with:
      check_result: $check
    invoke:
      tool: nika:log
      params:
        level: error
        message: "Error check result: {{with.check_result}}"

  - id: recover
    description: "Attempt error recovery"
    depends_on: [check]
    with:
      check_result: $check
    infer:
      prompt: |
        An error check returned: {{with.check_result}}

        Suggest recovery steps:
        1. What can we try to recover?
        2. Should we retry?
        3. What should we report?

        Provide actionable recovery plan.
      temperature: 0.3
      max_tokens: 300
"##;

/// Validation partial - adds input/output validation
pub const PARTIAL_VALIDATION: &str = r##"# ═══════════════════════════════════════════════════════════════════════════════
# PARTIAL: VALIDATION
# ═══════════════════════════════════════════════════════════════════════════════
#
# Include this partial for input/output validation.
# Ensures data quality before and after processing.
#
# Usage:
#   include:
#     - path: ./partials/validation.nika.yaml
#       prefix: val_
#
# ═══════════════════════════════════════════════════════════════════════════════

schema: "nika/workflow@0.12"
workflow: validation-partial
description: "Input and output validation tasks"

inputs:
  data: "Sample input data for validation"

tasks:
  - id: validate_input
    description: "Validate workflow inputs"
    infer:
      prompt: |
        Validate the following inputs:
        {{inputs.data}}

        Check for:
        1. Required fields present
        2. Correct data types
        3. Value ranges/constraints
        4. Format compliance

        Return JSON:
        {
          "valid": true/false,
          "errors": ["list of validation errors"],
          "warnings": ["list of warnings"]
        }
      temperature: 0.1
      max_tokens: 400

  - id: validate_output
    description: "Validate workflow outputs"
    depends_on: [validate_input]
    with:
      validation: $validate_input
    infer:
      prompt: |
        Review the input validation result:
        {{with.validation}}

        Assess:
        1. Schema compliance
        2. Data completeness
        3. Quality metrics
        4. Consistency

        Return JSON:
        {
          "valid": true/false,
          "errors": [],
          "quality_score": 0-100,
          "recommendations": []
        }
      temperature: 0.1
      max_tokens: 400

  - id: sanitize
    description: "Sanitize data for safety"
    depends_on: [validate_input]
    with:
      validation: $validate_input
    infer:
      prompt: |
        Based on validation: {{with.validation}}

        Sanitize the original data:
        {{inputs.data}}

        Actions:
        1. Remove any PII
        2. Escape special characters
        3. Normalize formats
        4. Remove duplicates

        Return sanitized version.
      temperature: 0.1
      max_tokens: 500
"##;

/// Notification partial - adds notification capabilities
pub const PARTIAL_NOTIFICATION: &str = r##"# ═══════════════════════════════════════════════════════════════════════════════
# PARTIAL: NOTIFICATIONS
# ═══════════════════════════════════════════════════════════════════════════════
#
# Include this partial for notification capabilities.
# Supports multiple notification channels.
#
# Usage:
#   include:
#     - path: ./partials/notification.nika.yaml
#       prefix: notify_
#
# ═══════════════════════════════════════════════════════════════════════════════

schema: "nika/workflow@0.12"
workflow: notification-partial
description: "Multi-channel notification tasks"

inputs:
  event_type: "workflow_complete"
  details: "Workflow finished successfully"
  recipient: "team"
  channel: "slack"

tasks:
  - id: format_message
    description: "Format notification message"
    infer:
      prompt: |
        Create a notification message:

        Event type: {{inputs.event_type}}
        Details: {{inputs.details}}
        Recipient: {{inputs.recipient}}
        Channel: {{inputs.channel}}

        Format appropriately for the channel:
        - Slack: Use markdown, emojis
        - Email: HTML-safe, structured
        - SMS: Concise, <160 chars

        Return formatted message.
      temperature: 0.3
      max_tokens: 300

  - id: send_slack
    description: "Send Slack notification (placeholder)"
    depends_on: [format_message]
    with:
      formatted: $format_message
    invoke:
      tool: nika:log
      params:
        level: info
        message: "[SLACK] {{with.formatted}}"

  - id: send_email
    description: "Send email notification (placeholder)"
    depends_on: [format_message]
    with:
      formatted: $format_message
    invoke:
      tool: nika:log
      params:
        level: info
        message: "[EMAIL] {{with.formatted}}"

  - id: completion_summary
    description: "Create completion summary notification"
    depends_on: [send_slack, send_email]
    with:
      slack_result: $send_slack
      email_result: $send_email
    infer:
      prompt: |
        Create a completion summary:

        Slack notification sent: {{with.slack_result}}
        Email notification sent: {{with.email_result}}

        Original event: {{inputs.event_type}} - {{inputs.details}}

        Create a brief, informative summary suitable for logging.
        Include key metrics and any action items.
      temperature: 0.3
      max_tokens: 250
"##;

/// Quality check partial - adds quality assurance steps
pub const PARTIAL_QUALITY_CHECK: &str = r##"# ═══════════════════════════════════════════════════════════════════════════════
# PARTIAL: QUALITY CHECKS
# ═══════════════════════════════════════════════════════════════════════════════
#
# Include this partial for quality assurance checks.
# Useful for content generation workflows.
#
# Usage:
#   include:
#     - path: ./partials/quality-check.nika.yaml
#       prefix: qa_
#
# ═══════════════════════════════════════════════════════════════════════════════

schema: "nika/workflow@0.12"
workflow: quality-check-partial
description: "Quality assurance check tasks"

inputs:
  content: "Sample content for quality review"
  target_tone: "professional"

tasks:
  - id: check_grammar
    description: "Check grammar and spelling"
    infer:
      prompt: |
        Review this content for grammar and spelling:

        {{inputs.content}}

        Check for:
        1. Spelling errors
        2. Grammar issues
        3. Punctuation problems
        4. Awkward phrasing

        Return JSON:
        {
          "score": 0-100,
          "issues": [{"type": "...", "text": "...", "suggestion": "..."}],
          "corrected_content": "..."
        }
      temperature: 0.1
      max_tokens: 800

  - id: check_tone
    description: "Verify tone and style"
    infer:
      prompt: |
        Analyze the tone of this content:

        {{inputs.content}}

        Target tone: {{inputs.target_tone}}

        Evaluate:
        1. Does it match target tone?
        2. Is it consistent throughout?
        3. Is it appropriate for audience?

        Return JSON:
        {
          "matches_target": true/false,
          "detected_tone": "...",
          "consistency_score": 0-100,
          "suggestions": []
        }
      temperature: 0.2
      max_tokens: 400

  - id: check_factual
    description: "Flag potential factual claims for review"
    infer:
      prompt: |
        Identify factual claims in this content:

        {{inputs.content}}

        List any claims that should be fact-checked:
        1. Statistics and numbers
        2. Dates and events
        3. Quotes and attributions
        4. Technical specifications

        Return JSON:
        {
          "claims_to_verify": [
            {"claim": "...", "type": "...", "confidence": 0-100}
          ],
          "high_risk_count": 0
        }
      temperature: 0.2
      max_tokens: 500

  - id: final_score
    description: "Calculate final quality score"
    depends_on: [check_grammar, check_tone, check_factual]
    with:
      grammar: $check_grammar
      tone: $check_tone
      factual: $check_factual
    infer:
      prompt: |
        Calculate final quality score:

        Grammar check: {{with.grammar}}
        Tone check: {{with.tone}}
        Factual check: {{with.factual}}

        Weighted scores:
        - Grammar: 40%
        - Tone: 30%
        - Factual risk: 30%

        Return JSON:
        {
          "final_score": 0-100,
          "grade": "A/B/C/D/F",
          "ready_for_publish": true/false,
          "blocking_issues": [],
          "recommendations": []
        }
      temperature: 0.1
      max_tokens: 300
"##;

/// Returns all partial workflow files
pub fn get_partial_files() -> Vec<ContextFile> {
    vec![
        ContextFile {
            filename: "logging-setup.nika.yaml",
            dir: PARTIALS_DIR,
            content: PARTIAL_LOGGING,
        },
        ContextFile {
            filename: "error-handling.nika.yaml",
            dir: PARTIALS_DIR,
            content: PARTIAL_ERROR_HANDLING,
        },
        ContextFile {
            filename: "validation.nika.yaml",
            dir: PARTIALS_DIR,
            content: PARTIAL_VALIDATION,
        },
        ContextFile {
            filename: "notification.nika.yaml",
            dir: PARTIALS_DIR,
            content: PARTIAL_NOTIFICATION,
        },
        ContextFile {
            filename: "quality-check.nika.yaml",
            dir: PARTIALS_DIR,
            content: PARTIAL_QUALITY_CHECK,
        },
    ]
}