reasonkit-core 0.1.8

The Reasoning Engine — Auditable Reasoning for Production AI | Rust-Native | Turn Prompts into Protocols
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
//! Protocol Registry
//!
//! Manages loading, storing, and retrieving ThinkTool protocols.

use std::collections::HashMap;
use std::path::{Path, PathBuf};

use super::protocol::Protocol;
use super::toml_loader;
use super::yaml_loader;
use crate::error::{Error, Result};

/// Registry of available ThinkTool protocols
#[derive(Debug, Default)]
pub struct ProtocolRegistry {
    /// Loaded protocols by ID
    protocols: HashMap<String, Protocol>,

    /// Protocol search paths
    search_paths: Vec<PathBuf>,
}

impl ProtocolRegistry {
    /// Create a new empty registry
    pub fn new() -> Self {
        Self::default()
    }

    /// Create registry with default search paths
    pub fn with_defaults() -> Self {
        let mut registry = Self::new();

        // Add default search paths
        if let Ok(cwd) = std::env::current_dir() {
            registry.add_search_path(cwd.join("protocols"));
        }

        // User config directory
        if let Some(config_dir) = dirs_config_path() {
            registry.add_search_path(config_dir.join("reasonkit").join("protocols"));
        }

        registry
    }

    /// Add a search path for protocol files
    pub fn add_search_path(&mut self, path: impl Into<PathBuf>) {
        let path = path.into();
        if !self.search_paths.contains(&path) {
            self.search_paths.push(path);
        }
    }

    /// Load all protocols from search paths
    pub fn load_all(&mut self) -> Result<usize> {
        let mut count = 0;

        for path in &self.search_paths.clone() {
            if path.exists() && path.is_dir() {
                count += self.load_from_directory(path)?;
            }
        }

        Ok(count)
    }

    /// Load protocols from a specific directory
    pub fn load_from_directory(&mut self, dir: &Path) -> Result<usize> {
        let mut count = 0;

        let entries = std::fs::read_dir(dir).map_err(|e| Error::IoMessage {
            message: format!("Failed to read directory {}: {}", dir.display(), e),
        })?;

        for entry in entries.flatten() {
            let path = entry.path();

            if path.is_file() {
                let ext = path.extension().and_then(|e| e.to_str());

                match ext {
                    Some("json") => {
                        if let Ok(protocol) = self.load_json_file(&path) {
                            self.register(protocol)?;
                            count += 1;
                        }
                    }
                    Some("yaml") | Some("yml") => {
                        // Load YAML protocols using yaml_loader
                        match yaml_loader::load_from_yaml_file(&path) {
                            Ok(protocols) => {
                                for protocol in protocols {
                                    self.register(protocol)?;
                                    count += 1;
                                }
                                tracing::info!(
                                    "Loaded {} protocols from YAML: {}",
                                    count,
                                    path.display()
                                );
                            }
                            Err(e) => {
                                tracing::warn!(
                                    "Failed to load YAML protocol {}: {}",
                                    path.display(),
                                    e
                                );
                            }
                        }
                    }
                    Some("toml") => {
                        // Load TOML protocols using toml_loader
                        match toml_loader::load_from_toml_file(&path) {
                            Ok(protocols) => {
                                for protocol in protocols {
                                    self.register(protocol)?;
                                    count += 1;
                                }
                                tracing::info!(
                                    "Loaded {} protocols from TOML: {}",
                                    count,
                                    path.display()
                                );
                            }
                            Err(e) => {
                                tracing::warn!(
                                    "Failed to load TOML protocol {}: {}",
                                    path.display(),
                                    e
                                );
                            }
                        }
                    }
                    _ => {}
                }
            }
        }

        Ok(count)
    }

    /// Load a protocol from a JSON file
    fn load_json_file(&self, path: &Path) -> Result<Protocol> {
        let content = std::fs::read_to_string(path).map_err(|e| Error::IoMessage {
            message: format!("Failed to read {}: {}", path.display(), e),
        })?;

        let protocol: Protocol = serde_json::from_str(&content).map_err(|e| Error::Parse {
            message: format!("Failed to parse protocol {}: {}", path.display(), e),
        })?;

        // Validate the protocol
        protocol.validate().map_err(|errors| {
            Error::Validation(format!(
                "Invalid protocol {}: {}",
                protocol.id,
                errors.join(", ")
            ))
        })?;

        Ok(protocol)
    }

    /// Load protocols from the standard thinktools.yaml file
    pub fn load_from_yaml(&mut self, path: &Path) -> Result<usize> {
        let protocols = yaml_loader::load_from_yaml_file(path)?;
        let count = protocols.len();

        for protocol in protocols {
            self.register(protocol)?;
        }

        Ok(count)
    }

    /// Register a protocol (by value)
    pub fn register(&mut self, protocol: Protocol) -> Result<()> {
        // Validate before registering
        protocol.validate().map_err(|errors| {
            Error::Validation(format!(
                "Invalid protocol {}: {}",
                protocol.id,
                errors.join(", ")
            ))
        })?;

        let id = protocol.id.clone();
        self.protocols.insert(id, protocol);
        Ok(())
    }

    /// Get a protocol by ID
    pub fn get(&self, id: &str) -> Option<&Protocol> {
        self.protocols.get(id)
    }

    /// Check if a protocol exists
    pub fn contains(&self, id: &str) -> bool {
        self.protocols.contains_key(id)
    }

    /// List all protocol IDs
    pub fn list_ids(&self) -> Vec<&str> {
        self.protocols.keys().map(|s| s.as_str()).collect()
    }

    /// List all protocols
    pub fn list(&self) -> Vec<&Protocol> {
        self.protocols.values().collect()
    }

    /// Get protocol count
    pub fn len(&self) -> usize {
        self.protocols.len()
    }

    /// Check if registry is empty
    pub fn is_empty(&self) -> bool {
        self.protocols.is_empty()
    }

    /// Remove a protocol by ID
    pub fn remove(&mut self, id: &str) -> Option<Protocol> {
        self.protocols.remove(id)
    }

    /// Clear all protocols
    pub fn clear(&mut self) {
        self.protocols.clear();
    }

    /// Register built-in protocols (hardcoded fallback)
    pub fn register_builtins(&mut self) -> Result<()> {
        // Try to load from YAML first
        let mut loaded_from_yaml = false;
        if let Ok(cwd) = std::env::current_dir() {
            // Check protocols/thinktools.yaml
            let yaml_path = cwd.join("protocols").join("thinktools.yaml");

            if yaml_path.exists() {
                match self.load_from_yaml(&yaml_path) {
                    Ok(count) => {
                        tracing::info!("Loaded {} protocols from thinktools.yaml", count);
                        loaded_from_yaml = true;
                    }
                    Err(e) => {
                        tracing::warn!(
                            "Failed to load thinktools.yaml: {}, falling back to hardcoded protocols",
                            e
                        );
                    }
                }
            }
        }

        // Only use hardcoded fallbacks if we failed to load from YAML
        if !loaded_from_yaml {
            tracing::info!("Using hardcoded fallback protocols");
            self.register(builtin_gigathink())?;
            self.register(builtin_laserlogic())?;
            self.register(builtin_bedrock())?;
            self.register(builtin_proofguard())?;
            self.register(builtin_brutalhonesty())?;
        }

        Ok(())
    }
}

/// Get config directory path
fn dirs_config_path() -> Option<PathBuf> {
    dirs::config_dir()
}

// ═══════════════════════════════════════════════════════════════════════════
// BUILT-IN PROTOCOLS (FALLBACK)
// ═══════════════════════════════════════════════════════════════════════════

use super::protocol::{
    AggregationType, CritiqueSeverity, InputSpec, OutputSpec, ProtocolMetadata, ProtocolStep,
    ReasoningStrategy, StepAction, StepOutputFormat,
};

fn builtin_gigathink() -> Protocol {
    Protocol {
        id: "gigathink".to_string(),
        name: "GigaThink".to_string(),
        version: "1.0.0".to_string(),
        description: "Expansive creative thinking - generate 10+ diverse perspectives".to_string(),
        strategy: ReasoningStrategy::Expansive,
        input: InputSpec {
            required: vec!["query".to_string()],
            optional: vec!["context".to_string(), "constraints".to_string()],
        },
        steps: vec![
            ProtocolStep {
                id: "identify_dimensions".to_string(),
                action: StepAction::Generate {
                    min_count: 5,
                    max_count: 10,
                },
                prompt_template:
                    r#"Identify 5-10 distinct dimensions or angles to analyze this question:

Question: {{query}}
{{#if context}}Context: {{context}}{{/if}}
{{#if constraints}}Constraints: {{constraints}}{{/if}}

For each dimension, provide a brief label. Format as a numbered list."#
                        .to_string(),
                output_format: StepOutputFormat::List,
                min_confidence: 0.7,
                depends_on: vec![],
                branch: None,
            },
            ProtocolStep {
                id: "explore_perspectives".to_string(),
                action: StepAction::Analyze {
                    criteria: vec![
                        "novelty".to_string(),
                        "relevance".to_string(),
                        "depth".to_string(),
                    ],
                },
                prompt_template: r#"For each dimension identified, provide:
1. Key insight from this perspective
2. Supporting evidence or example
3. Implications or consequences
4. Confidence score (0.0-1.0)

Dimensions to explore:
{{identify_dimensions}}

Question: {{query}}"#
                    .to_string(),
                output_format: StepOutputFormat::Structured,
                min_confidence: 0.6,
                depends_on: vec!["identify_dimensions".to_string()],
                branch: None,
            },
            ProtocolStep {
                id: "synthesize".to_string(),
                action: StepAction::Synthesize {
                    aggregation: AggregationType::ThematicClustering,
                },
                prompt_template:
                    r#"Synthesize the perspectives into key themes and actionable insights:

Perspectives:
{{explore_perspectives}}

Provide:
1. Major themes (2-4)
2. Key insights (3-5)
3. Recommended actions (if applicable)
4. Areas of uncertainty"#
                        .to_string(),
                output_format: StepOutputFormat::Structured,
                min_confidence: 0.8,
                depends_on: vec!["explore_perspectives".to_string()],
                branch: None,
            },
        ],
        output: OutputSpec {
            format: "GigaThinkResult".to_string(),
            fields: vec![
                "dimensions".to_string(),
                "perspectives".to_string(),
                "themes".to_string(),
                "insights".to_string(),
                "confidence".to_string(),
            ],
        },
        validation: vec![],
        metadata: ProtocolMetadata {
            category: "creative".to_string(),
            composable_with: vec!["laserlogic".to_string(), "brutalhonesty".to_string()],
            typical_tokens: 2500,
            estimated_latency_ms: 5000,
            ..Default::default()
        },
    }
}

fn builtin_laserlogic() -> Protocol {
    Protocol {
        id: "laserlogic".to_string(),
        name: "LaserLogic".to_string(),
        version: "1.0.0".to_string(),
        description: "Precision deductive reasoning with fallacy detection".to_string(),
        strategy: ReasoningStrategy::Deductive,
        input: InputSpec {
            required: vec!["argument".to_string()],
            optional: vec!["context".to_string()],
        },
        steps: vec![
            ProtocolStep {
                id: "extract_claims".to_string(),
                action: StepAction::Analyze {
                    criteria: vec!["clarity".to_string(), "completeness".to_string()],
                },
                prompt_template: r#"Extract the logical structure from this argument:

Argument: {{argument}}

Identify:
1. Main conclusion
2. Supporting premises
3. Implicit assumptions
4. Causal claims (if any)

Format each as a clear statement."#
                    .to_string(),
                output_format: StepOutputFormat::Structured,
                min_confidence: 0.7,
                depends_on: vec![],
                branch: None,
            },
            ProtocolStep {
                id: "check_validity".to_string(),
                action: StepAction::Validate {
                    rules: vec![
                        "logical_consistency".to_string(),
                        "premise_support".to_string(),
                    ],
                },
                prompt_template: r#"Evaluate the logical validity of this argument analysis:

{{extract_claims}}

Based on the claims identified above, check:
1. Do the premises logically lead to the conclusion?
2. Are there gaps in reasoning?
3. Is the argument valid (structure) vs sound (true premises)?
4. Rate logical strength (0.0-1.0)"#
                    .to_string(),
                output_format: StepOutputFormat::Structured,
                min_confidence: 0.8,
                depends_on: vec!["extract_claims".to_string()],
                branch: None,
            },
            ProtocolStep {
                id: "detect_fallacies".to_string(),
                action: StepAction::Critique {
                    severity: CritiqueSeverity::Standard,
                },
                prompt_template: r#"Check for logical fallacies in the argument:

Argument structure:
{{extract_claims}}

Common fallacies to check:
- Ad hominem, Straw man, False dichotomy
- Appeal to authority, Circular reasoning
- Hasty generalization, Post hoc
- Slippery slope, Red herring

For each fallacy found, explain where and why."#
                    .to_string(),
                output_format: StepOutputFormat::List,
                min_confidence: 0.7,
                depends_on: vec!["extract_claims".to_string()],
                branch: None,
            },
        ],
        output: OutputSpec {
            format: "LaserLogicResult".to_string(),
            fields: vec![
                "conclusion".to_string(),
                "premises".to_string(),
                "validity".to_string(),
                "fallacies".to_string(),
                "confidence".to_string(),
            ],
        },
        validation: vec![],
        metadata: ProtocolMetadata {
            category: "analytical".to_string(),
            composable_with: vec!["gigathink".to_string(), "bedrock".to_string()],
            typical_tokens: 1800,
            estimated_latency_ms: 4000,
            ..Default::default()
        },
    }
}

fn builtin_bedrock() -> Protocol {
    Protocol {
        id: "bedrock".to_string(),
        name: "BedRock".to_string(),
        version: "1.0.0".to_string(),
        description: "First principles decomposition - reduce to fundamental axioms".to_string(),
        strategy: ReasoningStrategy::Analytical,
        input: InputSpec {
            required: vec!["statement".to_string()],
            optional: vec!["domain".to_string()],
        },
        steps: vec![
            ProtocolStep {
                id: "decompose".to_string(),
                action: StepAction::Analyze {
                    criteria: vec!["fundamentality".to_string(), "independence".to_string()],
                },
                prompt_template: r#"Decompose this statement to first principles:

Statement: {{statement}}
{{#if domain}}Domain: {{domain}}{{/if}}

Ask repeatedly: "What is this based on? Why is this true?"
Continue until reaching fundamental axioms or assumptions.

Format as a tree structure showing dependencies."#
                    .to_string(),
                output_format: StepOutputFormat::Structured,
                min_confidence: 0.7,
                depends_on: vec![],
                branch: None,
            },
            ProtocolStep {
                id: "identify_axioms".to_string(),
                action: StepAction::Generate {
                    min_count: 3,
                    max_count: 7,
                },
                prompt_template: r#"From the decomposition, identify the foundational axioms:

Decomposition:
{{decompose}}

For each axiom:
1. State clearly
2. Explain why it's fundamental (cannot be further reduced)
3. Note if it's empirical, logical, or definitional
4. Rate certainty (0.0-1.0)"#
                    .to_string(),
                output_format: StepOutputFormat::List,
                min_confidence: 0.8,
                depends_on: vec!["decompose".to_string()],
                branch: None,
            },
            ProtocolStep {
                id: "reconstruct".to_string(),
                action: StepAction::Synthesize {
                    aggregation: AggregationType::WeightedMerge,
                },
                prompt_template: r#"Reconstruct the original statement from axioms:

Axioms:
{{identify_axioms}}

Original statement: {{statement}}

Show the logical path from axioms to statement.
Identify any gaps or leaps in reasoning.
Calculate overall confidence based on axiom certainties."#
                    .to_string(),
                output_format: StepOutputFormat::Structured,
                min_confidence: 0.75,
                depends_on: vec!["identify_axioms".to_string()],
                branch: None,
            },
        ],
        output: OutputSpec {
            format: "BedRockResult".to_string(),
            fields: vec![
                "axioms".to_string(),
                "decomposition".to_string(),
                "reconstruction".to_string(),
                "gaps".to_string(),
                "confidence".to_string(),
            ],
        },
        validation: vec![],
        metadata: ProtocolMetadata {
            category: "analytical".to_string(),
            composable_with: vec!["laserlogic".to_string(), "proofguard".to_string()],
            typical_tokens: 2000,
            estimated_latency_ms: 4500,
            ..Default::default()
        },
    }
}

fn builtin_proofguard() -> Protocol {
    Protocol {
        id: "proofguard".to_string(),
        name: "ProofGuard".to_string(),
        version: "1.0.0".to_string(),
        description: "Multi-source verification using triangulation protocol".to_string(),
        strategy: ReasoningStrategy::Verification,
        input: InputSpec {
            required: vec!["claim".to_string()],
            optional: vec!["sources".to_string()],
        },
        steps: vec![
            ProtocolStep {
                id: "identify_sources".to_string(),
                action: StepAction::CrossReference { min_sources: 3 },
                prompt_template: r#"Identify potential sources to verify this claim:

Claim: {{claim}}
{{#if sources}}Known sources: {{sources}}{{/if}}

List 3+ independent sources that could verify or refute this claim.
Prioritize: official docs, peer-reviewed, primary sources."#
                    .to_string(),
                output_format: StepOutputFormat::List,
                min_confidence: 0.6,
                depends_on: vec![],
                branch: None,
            },
            ProtocolStep {
                id: "verify_each".to_string(),
                action: StepAction::Validate {
                    rules: vec![
                        "source_reliability".to_string(),
                        "claim_support".to_string(),
                    ],
                },
                prompt_template: r#"For each source, evaluate support for the claim:

Claim: {{claim}}
Sources to check:
{{identify_sources}}

For each source:
1. What does it say about the claim?
2. Support level: Confirms / Partially confirms / Neutral / Contradicts
3. Source reliability (0.0-1.0)
4. Key quote or evidence"#
                    .to_string(),
                output_format: StepOutputFormat::Structured,
                min_confidence: 0.7,
                depends_on: vec!["identify_sources".to_string()],
                branch: None,
            },
            ProtocolStep {
                id: "triangulate".to_string(),
                action: StepAction::Synthesize {
                    aggregation: AggregationType::Consensus,
                },
                prompt_template: r#"Apply triangulation to determine claim validity:

Claim: {{claim}}
Source evaluations:
{{verify_each}}

Triangulation rules:
- 3+ independent confirming sources = HIGH confidence
- 2 confirming, 1 neutral = MEDIUM confidence
- Mixed results = LOW confidence, note discrepancies
- Any contradiction = FLAG for review

Provide final verdict and confidence score."#
                    .to_string(),
                output_format: StepOutputFormat::Structured,
                min_confidence: 0.8,
                depends_on: vec!["verify_each".to_string()],
                branch: None,
            },
        ],
        output: OutputSpec {
            format: "ProofGuardResult".to_string(),
            fields: vec![
                "verdict".to_string(),
                "sources".to_string(),
                "evidence".to_string(),
                "discrepancies".to_string(),
                "confidence".to_string(),
            ],
        },
        validation: vec![],
        metadata: ProtocolMetadata {
            category: "verification".to_string(),
            composable_with: vec!["bedrock".to_string(), "brutalhonesty".to_string()],
            typical_tokens: 2200,
            estimated_latency_ms: 5000,
            ..Default::default()
        },
    }
}

fn builtin_brutalhonesty() -> Protocol {
    Protocol {
        id: "brutalhonesty".to_string(),
        name: "BrutalHonesty".to_string(),
        version: "1.0.0".to_string(),
        description: "Adversarial self-critique - find every flaw".to_string(),
        strategy: ReasoningStrategy::Adversarial,
        input: InputSpec {
            required: vec!["work".to_string()],
            optional: vec!["criteria".to_string()],
        },
        steps: vec![
            ProtocolStep {
                id: "steelman".to_string(),
                action: StepAction::Analyze {
                    criteria: vec!["strengths".to_string()],
                },
                prompt_template: r#"First, steelman the work - what are its genuine strengths?

Work to critique:
{{work}}

Identify:
1. What does this do well?
2. What problems does it solve?
3. What is genuinely valuable here?

Be generous but honest."#
                    .to_string(),
                output_format: StepOutputFormat::List,
                min_confidence: 0.7,
                depends_on: vec![],
                branch: None,
            },
            ProtocolStep {
                id: "attack".to_string(),
                action: StepAction::Critique {
                    severity: CritiqueSeverity::Brutal,
                },
                prompt_template: r#"Now be brutally honest - what's wrong with this?

Work:
{{work}}

Strengths identified:
{{steelman}}

Attack from all angles:
1. Logical flaws
2. Missing considerations
3. Weak assumptions
4. Implementation problems
5. Unintended consequences
6. What would a harsh critic say?

Don't hold back. Be specific."#
                    .to_string(),
                output_format: StepOutputFormat::List,
                min_confidence: 0.6,
                depends_on: vec!["steelman".to_string()],
                branch: None,
            },
            ProtocolStep {
                id: "verdict".to_string(),
                action: StepAction::Decide {
                    method: super::protocol::DecisionMethod::ProsCons,
                },
                prompt_template: r#"Final verdict - is this work acceptable?

Strengths:
{{steelman}}

Flaws:
{{attack}}

Provide:
1. Overall assessment (Pass / Conditional Pass / Fail)
2. Most critical issue to fix
3. Confidence in verdict (0.0-1.0)
4. What would make this excellent?"#
                    .to_string(),
                output_format: StepOutputFormat::Structured,
                min_confidence: 0.75,
                depends_on: vec!["steelman".to_string(), "attack".to_string()],
                branch: None,
            },
        ],
        output: OutputSpec {
            format: "BrutalHonestyResult".to_string(),
            fields: vec![
                "strengths".to_string(),
                "flaws".to_string(),
                "verdict".to_string(),
                "critical_fix".to_string(),
                "confidence".to_string(),
            ],
        },
        validation: vec![],
        metadata: ProtocolMetadata {
            category: "critique".to_string(),
            composable_with: vec!["gigathink".to_string(), "proofguard".to_string()],
            typical_tokens: 2000,
            estimated_latency_ms: 4500,
            ..Default::default()
        },
    }
}

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

    #[test]
    fn test_registry_creation() {
        let registry = ProtocolRegistry::new();
        assert!(registry.is_empty());
    }

    #[test]
    fn test_register_builtins() {
        let mut registry = ProtocolRegistry::new();
        registry.register_builtins().unwrap();

        assert_eq!(registry.len(), 6);
        assert!(registry.contains("gigathink"));
        assert!(registry.contains("laserlogic"));
        assert!(registry.contains("bedrock"));
        assert!(registry.contains("proofguard"));
        assert!(registry.contains("brutalhonesty"));
        assert!(registry.contains("powercombo"));
    }

    #[test]
    fn test_get_protocol() {
        let mut registry = ProtocolRegistry::new();
        registry.register_builtins().unwrap();

        let gt = registry.get("gigathink").unwrap();
        assert_eq!(gt.name, "GigaThink");
        assert_eq!(gt.strategy, ReasoningStrategy::Expansive);
    }

    #[test]
    fn test_list_ids() {
        let mut registry = ProtocolRegistry::new();
        registry.register_builtins().unwrap();

        let ids = registry.list_ids();
        assert_eq!(ids.len(), 6);
        assert!(ids.contains(&"gigathink"));
        assert!(ids.contains(&"powercombo"));
    }
}