matrixcode-core 0.4.40

MatrixCode Agent Core - Pure logic, no UI
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
//! Conversation pattern types for pattern-based memory system.
//!
//! This module defines the core data structures for conversation patterns,
//! which capture reusable reference and code patterns from conversations.

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

// ============================================================================
// Pattern Types
// ============================================================================

/// Types of conversation patterns.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PatternType {
    /// Reference pattern - how to refer to things (e.g., "PR", "issue", "commit")
    Reference,
    /// Code pattern - code style and structure patterns
    Code,
}

impl PatternType {
    /// Get display name for the pattern type.
    pub fn display_name(&self) -> &'static str {
        match self {
            PatternType::Reference => "引用模式",
            PatternType::Code => "代码模式",
        }
    }

    /// Get icon for the pattern type.
    pub fn icon(&self) -> &'static str {
        match self {
            PatternType::Reference => "🔗",
            PatternType::Code => "💻",
        }
    }
}

// ============================================================================
// Pattern Sources
// ============================================================================

/// Source of a conversation pattern.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum PatternSource {
    /// Learned from user conversation.
    UserConversation {
        /// Example context where this pattern was observed.
        example: String,
    },
    /// Derived from project code style.
    ProjectCodeStyle {
        /// Programming language for this style.
        language: String,
    },
    /// System preset pattern (built-in defaults).
    SystemPreset,
    /// Manually added by user.
    Manual,
}

impl PatternSource {
    /// Create a user conversation source.
    pub fn user_conversation(example: impl Into<String>) -> Self {
        PatternSource::UserConversation {
            example: example.into(),
        }
    }

    /// Create a project code style source.
    pub fn project_code_style(language: impl Into<String>) -> Self {
        PatternSource::ProjectCodeStyle {
            language: language.into(),
        }
    }

    /// Check if this is a system preset.
    pub fn is_preset(&self) -> bool {
        matches!(self, PatternSource::SystemPreset)
    }

    /// Check if this is manually added.
    pub fn is_manual(&self) -> bool {
        matches!(self, PatternSource::Manual)
    }

    /// Get display name for the source.
    pub fn display_name(&self) -> &'static str {
        match self {
            PatternSource::UserConversation { .. } => "用户对话",
            PatternSource::ProjectCodeStyle { .. } => "项目风格",
            PatternSource::SystemPreset => "系统预设",
            PatternSource::Manual => "手动添加",
        }
    }
}

// ============================================================================
// Conversation Pattern
// ============================================================================

/// A conversation pattern captured from user interactions.
///
/// Patterns represent reusable conventions like:
/// - How to refer to pull requests ("PR #123" vs "pull request #123")
/// - Code style preferences (naming conventions, formatting)
/// - Common phrases and their variations
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConversationPattern {
    /// Unique identifier.
    pub id: String,
    /// Type of pattern.
    pub pattern_type: PatternType,
    /// The pattern string (regex or literal).
    pub pattern: String,
    /// Source where this pattern was learned from.
    pub source: PatternSource,
    /// Number of times this pattern has been used/matched.
    pub frequency: u32,
    /// When this pattern was last used.
    pub last_used: DateTime<Utc>,
    /// Confidence score (0.0-1.0), higher means more certain.
    pub confidence: f32,
    /// Whether this pattern is currently active.
    pub is_active: bool,
    /// Optional description of what this pattern represents.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// Tags for categorization and search.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub tags: Vec<String>,
}

impl ConversationPattern {
    /// Create a new conversation pattern.
    pub fn new(
        pattern_type: PatternType,
        pattern: impl Into<String>,
        source: PatternSource,
    ) -> Self {
        let id = uuid::Uuid::new_v4().to_string();
        Self {
            id,
            pattern_type,
            pattern: pattern.into(),
            source,
            frequency: 1,
            last_used: Utc::now(),
            confidence: 0.5,
            is_active: true,
            description: None,
            tags: Vec::new(),
        }
    }

    /// Create a system preset pattern.
    pub fn preset(pattern_type: PatternType, pattern: impl Into<String>) -> Self {
        let mut p = Self::new(pattern_type, pattern, PatternSource::SystemPreset);
        p.confidence = 1.0;
        p.frequency = 100; // Start with high frequency for presets
        p
    }

    /// Create a manually added pattern.
    pub fn manual(pattern_type: PatternType, pattern: impl Into<String>) -> Self {
        let mut p = Self::new(pattern_type, pattern, PatternSource::Manual);
        p.confidence = 0.9;
        p.is_active = true;
        p
    }

    /// Set the description.
    pub fn with_description(mut self, desc: impl Into<String>) -> Self {
        self.description = Some(desc.into());
        self
    }

    /// Add a tag.
    pub fn with_tag(mut self, tag: impl Into<String>) -> Self {
        self.tags.push(tag.into());
        self
    }

    /// Mark this pattern as used (increment frequency, update timestamp).
    pub fn mark_used(&mut self) {
        self.frequency = self.frequency.saturating_add(1);
        self.last_used = Utc::now();
        // Boost confidence slightly with usage
        self.confidence = (self.confidence + 0.01).min(1.0);
    }

    /// Deactivate this pattern.
    pub fn deactivate(&mut self) {
        self.is_active = false;
    }

    /// Activate this pattern.
    pub fn activate(&mut self) {
        self.is_active = true;
    }

    /// Format for display.
    pub fn format_line(&self) -> String {
        let active_marker = if self.is_active { "" } else { "[inactive] " };
        let freq_marker = if self.frequency > 10 { "" } else { "" };
        format!(
            "{}{} {} {} (freq: {}, conf: {:.2}) {}",
            active_marker,
            self.pattern_type.icon(),
            self.pattern_type.display_name(),
            &self.pattern,
            self.frequency,
            self.confidence,
            freq_marker
        )
    }

    /// Format for inclusion in system prompt.
    pub fn format_for_prompt(&self) -> String {
        match &self.description {
            Some(desc) => format!("{}: {}", &self.pattern, desc),
            None => self.pattern.clone(),
        }
    }
}

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

    // =========================================================================
    // PatternType Tests
    // =========================================================================

    #[test]
    fn test_pattern_type_display_name() {
        assert_eq!(PatternType::Reference.display_name(), "引用模式");
        assert_eq!(PatternType::Code.display_name(), "代码模式");
    }

    #[test]
    fn test_pattern_type_icon() {
        assert_eq!(PatternType::Reference.icon(), "🔗");
        assert_eq!(PatternType::Code.icon(), "💻");
    }

    #[test]
    fn test_pattern_type_equality() {
        assert_eq!(PatternType::Reference, PatternType::Reference);
        assert_eq!(PatternType::Code, PatternType::Code);
        assert_ne!(PatternType::Reference, PatternType::Code);
    }

    #[test]
    fn test_pattern_type_hash() {
        use std::collections::HashSet;
        let mut set = HashSet::new();
        set.insert(PatternType::Reference);
        set.insert(PatternType::Code);
        set.insert(PatternType::Reference); // Duplicate

        assert_eq!(set.len(), 2);
    }

    #[test]
    fn test_pattern_type_serialization() {
        let pt = PatternType::Reference;
        let json = serde_json::to_string(&pt).unwrap();
        assert_eq!(json, "\"reference\"");

        let decoded: PatternType = serde_json::from_str(&json).unwrap();
        assert_eq!(decoded, PatternType::Reference);

        let pt2 = PatternType::Code;
        let json2 = serde_json::to_string(&pt2).unwrap();
        assert_eq!(json2, "\"code\"");
    }

    // =========================================================================
    // PatternSource Tests
    // =========================================================================

    #[test]
    fn test_pattern_source_user_conversation() {
        let source = PatternSource::user_conversation("User mentioned PR #123");
        match source {
            PatternSource::UserConversation { example } => {
                assert_eq!(example, "User mentioned PR #123");
            }
            _ => panic!("Expected UserConversation variant"),
        }
    }

    #[test]
    fn test_pattern_source_project_code_style() {
        let source = PatternSource::project_code_style("rust");
        match source {
            PatternSource::ProjectCodeStyle { language } => {
                assert_eq!(language, "rust");
            }
            _ => panic!("Expected ProjectCodeStyle variant"),
        }
    }

    #[test]
    fn test_pattern_source_is_preset() {
        assert!(PatternSource::SystemPreset.is_preset());
        assert!(!PatternSource::user_conversation("test").is_preset());
        assert!(!PatternSource::project_code_style("rust").is_preset());
        assert!(!PatternSource::Manual.is_preset());
    }

    #[test]
    fn test_pattern_source_is_manual() {
        assert!(PatternSource::Manual.is_manual());
        assert!(!PatternSource::SystemPreset.is_manual());
        assert!(!PatternSource::user_conversation("test").is_manual());
        assert!(!PatternSource::project_code_style("rust").is_manual());
    }

    #[test]
    fn test_pattern_source_display_name() {
        assert_eq!(PatternSource::user_conversation("test").display_name(), "用户对话");
        assert_eq!(PatternSource::project_code_style("rust").display_name(), "项目风格");
        assert_eq!(PatternSource::SystemPreset.display_name(), "系统预设");
        assert_eq!(PatternSource::Manual.display_name(), "手动添加");
    }

    #[test]
    fn test_pattern_source_serialization() {
        // UserConversation
        let source = PatternSource::user_conversation("example context");
        let json = serde_json::to_string(&source).unwrap();
        let decoded: PatternSource = serde_json::from_str(&json).unwrap();
        assert_eq!(decoded, source);

        // ProjectCodeStyle
        let source2 = PatternSource::project_code_style("typescript");
        let json2 = serde_json::to_string(&source2).unwrap();
        let decoded2: PatternSource = serde_json::from_str(&json2).unwrap();
        assert_eq!(decoded2, source2);

        // SystemPreset
        let source3 = PatternSource::SystemPreset;
        let json3 = serde_json::to_string(&source3).unwrap();
        assert!(json3.contains("system_preset"));

        // Manual
        let source4 = PatternSource::Manual;
        let json4 = serde_json::to_string(&source4).unwrap();
        assert!(json4.contains("manual"));
    }

    // =========================================================================
    // ConversationPattern Creation Tests
    // =========================================================================

    #[test]
    fn test_pattern_creation() {
        let pattern = ConversationPattern::new(
            PatternType::Reference,
            r"PR #\d+",
            PatternSource::user_conversation("User mentioned PR #123"),
        );
        assert!(pattern.is_active);
        assert_eq!(pattern.frequency, 1);
        assert_eq!(pattern.confidence, 0.5);
        assert!(pattern.description.is_none());
        assert!(pattern.tags.is_empty());
        assert!(!pattern.id.is_empty()); // UUID should be generated
    }

    #[test]
    fn test_pattern_creation_with_all_types() {
        // Reference type
        let ref_pattern = ConversationPattern::new(
            PatternType::Reference,
            r"issue #\d+",
            PatternSource::Manual,
        );
        assert_eq!(ref_pattern.pattern_type, PatternType::Reference);

        // Code type
        let code_pattern = ConversationPattern::new(
            PatternType::Code,
            r"fn \w+\(",
            PatternSource::SystemPreset,
        );
        assert_eq!(code_pattern.pattern_type, PatternType::Code);
    }

    #[test]
    fn test_pattern_preset() {
        let pattern = ConversationPattern::preset(PatternType::Reference, r"PR #\d+");

        assert!(pattern.source.is_preset());
        assert!(pattern.is_active);
        assert_eq!(pattern.confidence, 1.0);
        assert_eq!(pattern.frequency, 100); // Presets start with high frequency
    }

    #[test]
    fn test_pattern_manual() {
        let pattern = ConversationPattern::manual(PatternType::Code, "custom-pattern");

        assert!(pattern.source.is_manual());
        assert!(pattern.is_active);
        assert_eq!(pattern.confidence, 0.9);
    }

    #[test]
    fn test_pattern_with_description() {
        let pattern = ConversationPattern::new(
            PatternType::Reference,
            "test-pattern",
            PatternSource::Manual,
        )
        .with_description("This is a test pattern");

        assert_eq!(pattern.description, Some("This is a test pattern".to_string()));
    }

    #[test]
    fn test_pattern_with_tag() {
        let pattern = ConversationPattern::new(
            PatternType::Code,
            "test-pattern",
            PatternSource::Manual,
        )
        .with_tag("rust")
        .with_tag("async");

        assert_eq!(pattern.tags, vec!["rust", "async"]);
    }

    #[test]
    fn test_pattern_builder_chain() {
        let pattern = ConversationPattern::preset(PatternType::Reference, r"\bPR\s*#\d+\b")
            .with_description("Pull Request reference")
            .with_tag("git")
            .with_tag("github");

        assert_eq!(pattern.pattern, r"\bPR\s*#\d+\b");
        assert_eq!(pattern.description, Some("Pull Request reference".to_string()));
        assert_eq!(pattern.tags, vec!["git", "github"]);
        assert!(pattern.source.is_preset());
    }

    // =========================================================================
    // ConversationPattern State Change Tests
    // =========================================================================

    #[test]
    fn test_pattern_mark_used() {
        let mut pattern = ConversationPattern::new(
            PatternType::Code,
            "fn test()",
            PatternSource::Manual,
        );
        let initial_confidence = pattern.confidence;
        let initial_last_used = pattern.last_used;

        pattern.mark_used();

        assert_eq!(pattern.frequency, 2);
        assert!(pattern.confidence > initial_confidence);
        assert!(pattern.last_used >= initial_last_used);
    }

    #[test]
    fn test_pattern_mark_used_confidence_cap() {
        let mut pattern = ConversationPattern::new(
            PatternType::Code,
            "test",
            PatternSource::Manual,
        );

        // Set confidence near the cap
        pattern.confidence = 0.999;

        pattern.mark_used();

        // Confidence should not exceed 1.0
        assert!(pattern.confidence <= 1.0);
    }

    #[test]
    fn test_pattern_mark_used_frequency_overflow() {
        let mut pattern = ConversationPattern::new(
            PatternType::Code,
            "test",
            PatternSource::Manual,
        );

        // Set frequency near max
        pattern.frequency = u32::MAX - 1;

        pattern.mark_used();

        // Should saturate at max instead of overflowing
        assert_eq!(pattern.frequency, u32::MAX);
    }

    #[test]
    fn test_pattern_deactivate() {
        let mut pattern = ConversationPattern::new(
            PatternType::Reference,
            "test",
            PatternSource::Manual,
        );

        assert!(pattern.is_active);
        pattern.deactivate();
        assert!(!pattern.is_active);
    }

    #[test]
    fn test_pattern_activate() {
        let mut pattern = ConversationPattern::new(
            PatternType::Reference,
            "test",
            PatternSource::Manual,
        );

        pattern.deactivate();
        assert!(!pattern.is_active);

        pattern.activate();
        assert!(pattern.is_active);
    }

    #[test]
    fn test_pattern_activate_deactivate_cycle() {
        let mut pattern = ConversationPattern::preset(PatternType::Code, "test");

        // Multiple cycles
        for _ in 0..3 {
            pattern.deactivate();
            assert!(!pattern.is_active);
            pattern.activate();
            assert!(pattern.is_active);
        }
    }

    // =========================================================================
    // ConversationPattern Formatting Tests
    // =========================================================================

    #[test]
    fn test_format_line_active_high_frequency() {
        let mut pattern = ConversationPattern::preset(PatternType::Reference, "test-pattern");
        pattern.frequency = 15; // Above the 10 threshold for star marker

        let line = pattern.format_line();

        assert!(line.contains("🔗"));
        assert!(line.contains("引用模式"));
        assert!(line.contains("test-pattern"));
        assert!(line.contains("freq: 15"));
        assert!(line.contains("")); // High frequency marker
        assert!(!line.contains("[inactive]"));
    }

    #[test]
    fn test_format_line_active_low_frequency() {
        let pattern = ConversationPattern::new(
            PatternType::Code,
            "test-pattern",
            PatternSource::Manual,
        );

        let line = pattern.format_line();

        assert!(line.contains("💻"));
        assert!(line.contains("代码模式"));
        assert!(!line.contains("")); // Low frequency, no star
        assert!(!line.contains("[inactive]"));
    }

    #[test]
    fn test_format_line_inactive() {
        let mut pattern = ConversationPattern::preset(PatternType::Reference, "test-pattern");
        pattern.deactivate();

        let line = pattern.format_line();

        assert!(line.contains("[inactive]"));
    }

    #[test]
    fn test_format_for_prompt_with_description() {
        let pattern = ConversationPattern::preset(PatternType::Reference, r"\bPR\s*#\d+\b")
            .with_description("Pull Request reference format");

        let prompt = pattern.format_for_prompt();

        assert_eq!(prompt, r"\bPR\s*#\d+\b: Pull Request reference format");
    }

    #[test]
    fn test_format_for_prompt_without_description() {
        let pattern = ConversationPattern::preset(PatternType::Reference, "simple-pattern");

        let prompt = pattern.format_for_prompt();

        assert_eq!(prompt, "simple-pattern");
    }

    // =========================================================================
    // Serialization Tests
    // =========================================================================

    #[test]
    fn test_serialization() {
        let pattern = ConversationPattern::preset(PatternType::Reference, r"PR #\d+")
            .with_description("Test pattern");

        let json = serde_json::to_string(&pattern).unwrap();
        let decoded: ConversationPattern = serde_json::from_str(&json).unwrap();

        assert_eq!(decoded.pattern, pattern.pattern);
        assert_eq!(decoded.pattern_type, PatternType::Reference);
        assert_eq!(decoded.description, Some("Test pattern".to_string()));
    }

    #[test]
    fn test_serialization_with_tags() {
        let pattern = ConversationPattern::preset(PatternType::Code, r"fn \w+")
            .with_tag("rust")
            .with_tag("function");

        let json = serde_json::to_string(&pattern).unwrap();
        let decoded: ConversationPattern = serde_json::from_str(&json).unwrap();

        assert_eq!(decoded.tags, vec!["rust", "function"]);
    }

    #[test]
    fn test_serialization_roundtrip() {
        let original = ConversationPattern::new(
            PatternType::Reference,
            r"issue #\d+",
            PatternSource::user_conversation("User said issue #42"),
        )
        .with_description("Issue reference")
        .with_tag("git");

        let json = serde_json::to_string(&original).unwrap();
        let decoded: ConversationPattern = serde_json::from_str(&json).unwrap();

        assert_eq!(decoded.id, original.id);
        assert_eq!(decoded.pattern_type, original.pattern_type);
        assert_eq!(decoded.pattern, original.pattern);
        assert_eq!(decoded.source, original.source);
        assert_eq!(decoded.frequency, original.frequency);
        assert_eq!(decoded.confidence, original.confidence);
        assert_eq!(decoded.is_active, original.is_active);
        assert_eq!(decoded.description, original.description);
        assert_eq!(decoded.tags, original.tags);
    }

    // =========================================================================
    // Edge Cases and Boundary Tests
    // =========================================================================

    #[test]
    fn test_empty_pattern_string() {
        let pattern = ConversationPattern::new(
            PatternType::Reference,
            "",
            PatternSource::Manual,
        );

        assert_eq!(pattern.pattern, "");
    }

    #[test]
    fn test_special_regex_chars_in_pattern() {
        let pattern = ConversationPattern::new(
            PatternType::Code,
            r"fn\s+\w+\s*\([^)]*\)\s*\{",
            PatternSource::Manual,
        );

        assert_eq!(pattern.pattern, r"fn\s+\w+\s*\([^)]*\)\s*\{");
    }

    #[test]
    fn test_unicode_pattern() {
        let pattern = ConversationPattern::new(
            PatternType::Reference,
            "中文模式",
            PatternSource::user_conversation("测试"),
        );

        assert_eq!(pattern.pattern, "中文模式");
    }

    #[test]
    fn test_very_long_pattern() {
        let long_pattern = "x".repeat(10000);
        let pattern = ConversationPattern::new(
            PatternType::Code,
            long_pattern.clone(),
            PatternSource::Manual,
        );

        assert_eq!(pattern.pattern.len(), 10000);
    }

    #[test]
    fn test_confidence_boundary() {
        let mut pattern = ConversationPattern::new(
            PatternType::Code,
            "test",
            PatternSource::Manual,
        );

        // Test minimum confidence
        pattern.confidence = 0.0;
        assert_eq!(pattern.confidence, 0.0);

        // Test maximum confidence
        pattern.confidence = 1.0;
        assert_eq!(pattern.confidence, 1.0);
    }

    #[test]
    fn test_unique_ids() {
        let p1 = ConversationPattern::new(PatternType::Code, "test", PatternSource::Manual);
        let p2 = ConversationPattern::new(PatternType::Code, "test", PatternSource::Manual);

        // Each pattern should have a unique ID
        assert_ne!(p1.id, p2.id);
    }
}