vcp-core 4.2.0

Value Context Protocol (VCP) core types and parsing
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
//! Situational context dimensions (VCP v3.2 Layer 2).
//!
//! Thirteen categorical dimensions describe the user's current situation
//! using emoji-keyed tag arrays in a compact wire format.
//!
//! **VCP v3.2 (incl. VEP-0004) dimension map**
//!
//! | #  | dim              | symbol     | notes                              |
//! |----|------------------|------------|------------------------------------|
//! |  1 | time             | ⏰          |                                    |
//! |  2 | space            | πŸ“          |                                    |
//! |  3 | company          | πŸ‘₯          |                                    |
//! |  4 | culture          | 🌍          | communication styles, NOT nations  |
//! |  5 | occasion         | 🎭          |                                    |
//! |  6 | environment      | 🌑️ (VS16)  |                                    |
//! |  7 | agency           | πŸ”·          |                                    |
//! |  8 | constraints      | πŸ”Ά          |                                    |
//! |  9 | `system_context` | πŸ“‘          | replaces deprecated STATE (v3.0)   |
//! | 10 | embodiment       | 🧍          | VEP-0004                           |
//! | 11 | proximity        | ↔️ (VS16)  | VEP-0004                           |
//! | 12 | relationship     | πŸͺ’          | VEP-0004, free-form `{tie}:{fn}`   |
//! | 13 | formality        | 🎩          | VEP-0004                           |
//!
//! Wire format example (core-only):
//! `β°πŸŒ…|πŸ“πŸ‘|πŸ‘₯πŸ‘Ά`
//!
//! Wire format example (full 13-dim + VEP-0004):
//! `β°πŸŒ…|πŸ“πŸ’|πŸ‘₯πŸ‘”|πŸŽ­πŸ’Ό|πŸ§βœ‹|β†”οΈπŸ€|πŸͺ’colleague:professional|πŸŽ©πŸ’Ό`

use std::fmt;

use serde::{Deserialize, Serialize};

use crate::error::{VcpError, VcpResult};

const MAX_SITUATIONAL_WIRE_CHARS: usize = 8_192;

/// The thirteen situational context dimensions (VCP v3.2, incl. VEP-0004).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SituationalDimension {
    Time,
    Space,
    Company,
    Culture,
    Occasion,
    Environment,
    Agency,
    Constraints,
    SystemContext,
    // VEP-0004 dimensions (positions 10-13)
    Embodiment,
    Proximity,
    Relationship,
    Formality,
}

impl SituationalDimension {
    /// Emoji symbol used as the wire-format prefix.
    pub fn symbol(self) -> &'static str {
        match self {
            Self::Time => "\u{23F0}",                 // ⏰ alarm clock
            Self::Space => "\u{1F4CD}",               // πŸ“ round pushpin
            Self::Company => "\u{1F465}",             // πŸ‘₯ busts in silhouette
            Self::Culture => "\u{1F30D}",             // 🌍 globe Europe-Africa
            Self::Occasion => "\u{1F3AD}",            // 🎭 performing arts
            Self::Environment => "\u{1F321}\u{FE0F}", // 🌑️ thermometer (+ VS16)
            Self::Agency => "\u{1F537}",              // πŸ”· large blue diamond
            Self::Constraints => "\u{1F536}",         // πŸ”Ά large orange diamond
            Self::SystemContext => "\u{1F4E1}",       // πŸ“‘ satellite antenna
            // VEP-0004
            Self::Embodiment => "\u{1F9CD}", // 🧍 standing person
            Self::Proximity => "\u{2194}\u{FE0F}", // ↔️ left-right arrow (+ VS16)
            Self::Relationship => "\u{1FAA2}", // πŸͺ’ knot
            Self::Formality => "\u{1F3A9}",  // 🎩 top hat
        }
    }

    /// Canonical position (1-13) of this dimension in the wire format.
    pub fn position(self) -> u8 {
        match self {
            Self::Time => 1,
            Self::Space => 2,
            Self::Company => 3,
            Self::Culture => 4,
            Self::Occasion => 5,
            Self::Environment => 6,
            Self::Agency => 7,
            Self::Constraints => 8,
            Self::SystemContext => 9,
            Self::Embodiment => 10,
            Self::Proximity => 11,
            Self::Relationship => 12,
            Self::Formality => 13,
        }
    }

    /// `true` if this dimension was introduced by VEP-0004 (positions 10-13).
    pub fn is_vep_0004(self) -> bool {
        matches!(
            self,
            Self::Embodiment | Self::Proximity | Self::Relationship | Self::Formality
        )
    }

    /// `true` if this dimension carries free-form string values
    /// rather than an emoji tag vocabulary.
    ///
    /// Currently only [`Self::Relationship`] is free-form: its value
    /// is a compound string of form `{tie}:{function}`
    /// (e.g. `colleague:professional`).
    pub fn is_free_form(self) -> bool {
        matches!(self, Self::Relationship)
    }

    /// Parse from the emoji symbol prefix.
    pub fn from_symbol(s: &str) -> Option<Self> {
        // Multi-codepoint symbols first.
        if s == "\u{1F321}\u{FE0F}" || s.starts_with("\u{1F321}\u{FE0F}") {
            return Some(Self::Environment);
        }
        if s == "\u{1F321}" || s.starts_with("\u{1F321}") {
            // bare thermometer without VS16
            return Some(Self::Environment);
        }
        if s == "\u{2194}\u{FE0F}" || s.starts_with("\u{2194}\u{FE0F}") {
            return Some(Self::Proximity);
        }
        if s == "\u{2194}" || s.starts_with("\u{2194}") {
            // bare arrow without VS16
            return Some(Self::Proximity);
        }
        match s {
            "\u{23F0}" => Some(Self::Time),
            "\u{1F4CD}" => Some(Self::Space),
            "\u{1F465}" => Some(Self::Company),
            "\u{1F30D}" => Some(Self::Culture),
            "\u{1F3AD}" => Some(Self::Occasion),
            "\u{1F537}" => Some(Self::Agency),
            "\u{1F536}" => Some(Self::Constraints),
            "\u{1F4E1}" => Some(Self::SystemContext),
            "\u{1F9CD}" => Some(Self::Embodiment),
            "\u{1FAA2}" => Some(Self::Relationship),
            "\u{1F3A9}" => Some(Self::Formality),
            _ => None,
        }
    }

    /// All thirteen dimensions in canonical position order (1..=13).
    pub fn all() -> &'static [SituationalDimension] {
        &[
            Self::Time,
            Self::Space,
            Self::Company,
            Self::Culture,
            Self::Occasion,
            Self::Environment,
            Self::Agency,
            Self::Constraints,
            Self::SystemContext,
            Self::Embodiment,
            Self::Proximity,
            Self::Relationship,
            Self::Formality,
        ]
    }
}

impl fmt::Display for SituationalDimension {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let label = match self {
            Self::Time => "time",
            Self::Space => "space",
            Self::Company => "company",
            Self::Culture => "culture",
            Self::Occasion => "occasion",
            Self::Environment => "environment",
            Self::Agency => "agency",
            Self::Constraints => "constraints",
            Self::SystemContext => "system_context",
            Self::Embodiment => "embodiment",
            Self::Proximity => "proximity",
            Self::Relationship => "relationship",
            Self::Formality => "formality",
        };
        f.write_str(label)
    }
}

/// The complete set of situational context tags (VCP v3.2, 13 dims).
///
/// Each dimension maps to an optional list of tag strings.
/// For the standard dimensions, tags are emoji values from the
/// dimension's vocabulary. For [`SituationalDimension::Relationship`],
/// tags are free-form compound strings of form `{tie}:{function}`.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct SituationalContext {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub time: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub space: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub company: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub culture: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub occasion: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub environment: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub agency: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub constraints: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub system_context: Option<Vec<String>>,
    // VEP-0004 dims
    #[serde(skip_serializing_if = "Option::is_none")]
    pub embodiment: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub proximity: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub relationship: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub formality: Option<Vec<String>>,
}

impl SituationalContext {
    /// Returns `true` if at least one dimension has tags.
    pub fn has_any(&self) -> bool {
        self.time.is_some()
            || self.space.is_some()
            || self.company.is_some()
            || self.culture.is_some()
            || self.occasion.is_some()
            || self.environment.is_some()
            || self.agency.is_some()
            || self.constraints.is_some()
            || self.system_context.is_some()
            || self.embodiment.is_some()
            || self.proximity.is_some()
            || self.relationship.is_some()
            || self.formality.is_some()
    }

    /// Returns `true` if any VEP-0004 dimension (positions 10-13) has tags.
    pub fn has_vep_0004(&self) -> bool {
        self.embodiment.is_some()
            || self.proximity.is_some()
            || self.relationship.is_some()
            || self.formality.is_some()
    }

    /// Encode to wire format.
    ///
    /// Each dimension is encoded as `<symbol><tag1><tag2>...` and
    /// dimensions are separated by `|`. Dimensions are emitted in
    /// canonical position order (1..=13).
    pub fn to_wire(&self) -> String {
        let mut parts = Vec::new();

        let dims: [(SituationalDimension, &Option<Vec<String>>); 13] = [
            (SituationalDimension::Time, &self.time),
            (SituationalDimension::Space, &self.space),
            (SituationalDimension::Company, &self.company),
            (SituationalDimension::Culture, &self.culture),
            (SituationalDimension::Occasion, &self.occasion),
            (SituationalDimension::Environment, &self.environment),
            (SituationalDimension::Agency, &self.agency),
            (SituationalDimension::Constraints, &self.constraints),
            (SituationalDimension::SystemContext, &self.system_context),
            (SituationalDimension::Embodiment, &self.embodiment),
            (SituationalDimension::Proximity, &self.proximity),
            (SituationalDimension::Relationship, &self.relationship),
            (SituationalDimension::Formality, &self.formality),
        ];

        for (dim, tags_opt) in &dims {
            if let Some(tags) = tags_opt {
                if !tags.is_empty() {
                    let mut s = String::from(dim.symbol());
                    for tag in tags {
                        s.push_str(tag);
                    }
                    parts.push(s);
                }
            }
        }

        parts.join("|")
    }

    /// Parse from wire format.
    ///
    /// The wire format is `<symbol><tags>|<symbol><tags>|...`.
    ///
    /// # Errors
    ///
    /// Returns [`VcpError::ParseError`] if a segment contains an
    /// unrecognised dimension symbol.
    pub fn from_wire(wire: &str) -> VcpResult<Self> {
        let mut ctx = SituationalContext::default();

        if wire.is_empty() {
            return Ok(ctx);
        }
        if wire.chars().count() > MAX_SITUATIONAL_WIRE_CHARS {
            return Err(VcpError::ParseError(format!(
                "situational context exceeds {MAX_SITUATIONAL_WIRE_CHARS} characters"
            )));
        }
        if wire
            .chars()
            .any(|character| character.is_whitespace() || character.is_control())
        {
            return Err(VcpError::ParseError(
                "situational context contains whitespace or control characters".to_string(),
            ));
        }

        for segment in wire.split('|') {
            if segment.is_empty() {
                return Err(VcpError::ParseError(
                    "situational context contains an empty dimension segment".to_string(),
                ));
            }

            let (dim, rest) = split_situational_symbol(segment)?;
            if rest.is_empty() {
                return Err(VcpError::ParseError(format!(
                    "situational dimension {dim} has no value"
                )));
            }
            // Relationship values are free-form `{tie}:{function}` strings
            // and remain intact. Other remainders are one opaque tag.
            let tags = vec![rest.to_string()];

            let slot = match dim {
                SituationalDimension::Time => &mut ctx.time,
                SituationalDimension::Space => &mut ctx.space,
                SituationalDimension::Company => &mut ctx.company,
                SituationalDimension::Culture => &mut ctx.culture,
                SituationalDimension::Occasion => &mut ctx.occasion,
                SituationalDimension::Environment => &mut ctx.environment,
                SituationalDimension::Agency => &mut ctx.agency,
                SituationalDimension::Constraints => &mut ctx.constraints,
                SituationalDimension::SystemContext => &mut ctx.system_context,
                SituationalDimension::Embodiment => &mut ctx.embodiment,
                SituationalDimension::Proximity => &mut ctx.proximity,
                SituationalDimension::Relationship => &mut ctx.relationship,
                SituationalDimension::Formality => &mut ctx.formality,
            };
            if slot.is_some() {
                return Err(VcpError::ParseError(format!(
                    "duplicate situational dimension: {dim}"
                )));
            }
            *slot = Some(tags);
        }

        Ok(ctx)
    }

    /// Get tags for a specific dimension.
    pub fn get(&self, dim: SituationalDimension) -> Option<&Vec<String>> {
        match dim {
            SituationalDimension::Time => self.time.as_ref(),
            SituationalDimension::Space => self.space.as_ref(),
            SituationalDimension::Company => self.company.as_ref(),
            SituationalDimension::Culture => self.culture.as_ref(),
            SituationalDimension::Occasion => self.occasion.as_ref(),
            SituationalDimension::Environment => self.environment.as_ref(),
            SituationalDimension::Agency => self.agency.as_ref(),
            SituationalDimension::Constraints => self.constraints.as_ref(),
            SituationalDimension::SystemContext => self.system_context.as_ref(),
            SituationalDimension::Embodiment => self.embodiment.as_ref(),
            SituationalDimension::Proximity => self.proximity.as_ref(),
            SituationalDimension::Relationship => self.relationship.as_ref(),
            SituationalDimension::Formality => self.formality.as_ref(),
        }
    }

    /// Set tags for a specific dimension.
    pub fn set(&mut self, dim: SituationalDimension, tags: Vec<String>) {
        match dim {
            SituationalDimension::Time => self.time = Some(tags),
            SituationalDimension::Space => self.space = Some(tags),
            SituationalDimension::Company => self.company = Some(tags),
            SituationalDimension::Culture => self.culture = Some(tags),
            SituationalDimension::Occasion => self.occasion = Some(tags),
            SituationalDimension::Environment => self.environment = Some(tags),
            SituationalDimension::Agency => self.agency = Some(tags),
            SituationalDimension::Constraints => self.constraints = Some(tags),
            SituationalDimension::SystemContext => self.system_context = Some(tags),
            SituationalDimension::Embodiment => self.embodiment = Some(tags),
            SituationalDimension::Proximity => self.proximity = Some(tags),
            SituationalDimension::Relationship => self.relationship = Some(tags),
            SituationalDimension::Formality => self.formality = Some(tags),
        }
    }
}

impl fmt::Display for SituationalContext {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(&self.to_wire())
    }
}

/// Split the leading dimension symbol from a wire-format segment.
///
/// Environment uses a two-codepoint emoji (`🌑️` = U+1F321 U+FE0F), and
/// Proximity uses a two-codepoint emoji (`↔️` = U+2194 U+FE0F), so
/// these must be checked before their single-codepoint base forms.
fn split_situational_symbol(s: &str) -> VcpResult<(SituationalDimension, &str)> {
    static SYMBOLS: &[(SituationalDimension, &str)] = &[
        (SituationalDimension::Space, "\u{1F4CD}"),
        (SituationalDimension::Company, "\u{1F465}"),
        (SituationalDimension::Culture, "\u{1F30D}"),
        (SituationalDimension::Occasion, "\u{1F3AD}"),
        (SituationalDimension::Agency, "\u{1F537}"),
        (SituationalDimension::Constraints, "\u{1F536}"),
        (SituationalDimension::SystemContext, "\u{1F4E1}"),
        (SituationalDimension::Embodiment, "\u{1F9CD}"),
        (SituationalDimension::Relationship, "\u{1FAA2}"),
        (SituationalDimension::Formality, "\u{1F3A9}"),
        (SituationalDimension::Time, "\u{23F0}"),
    ];

    // Two-codepoint (VS16) symbols β€” check first.
    let env_sym = "\u{1F321}\u{FE0F}";
    if let Some(rest) = s.strip_prefix(env_sym) {
        return Ok((SituationalDimension::Environment, rest));
    }
    let prox_sym = "\u{2194}\u{FE0F}";
    if let Some(rest) = s.strip_prefix(prox_sym) {
        return Ok((SituationalDimension::Proximity, rest));
    }
    // Also accept bare (no-VS16) variants.
    let env_bare = "\u{1F321}";
    if let Some(rest) = s.strip_prefix(env_bare) {
        return Ok((SituationalDimension::Environment, rest));
    }
    let prox_bare = "\u{2194}";
    if let Some(rest) = s.strip_prefix(prox_bare) {
        return Ok((SituationalDimension::Proximity, rest));
    }

    for (dim, sym) in SYMBOLS {
        if let Some(rest) = s.strip_prefix(sym) {
            return Ok((*dim, rest));
        }
    }

    Err(VcpError::ParseError(format!(
        "unrecognised situational dimension symbol in: {s}"
    )))
}

// ── Tests ───────────────────────────────────────────────────

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

    #[test]
    fn dimension_symbols_roundtrip() {
        for dim in SituationalDimension::all() {
            let sym = dim.symbol();
            assert_eq!(
                SituationalDimension::from_symbol(sym),
                Some(*dim),
                "symbol roundtrip failed for {dim}"
            );
        }
    }

    #[test]
    fn thirteen_dimensions_unique_positions() {
        let mut positions: Vec<u8> = SituationalDimension::all()
            .iter()
            .map(|d| d.position())
            .collect();
        positions.sort_unstable();
        assert_eq!(positions, (1u8..=13).collect::<Vec<_>>());
    }

    #[test]
    fn vep_0004_flags() {
        for dim in SituationalDimension::all() {
            let expected = matches!(
                dim,
                SituationalDimension::Embodiment
                    | SituationalDimension::Proximity
                    | SituationalDimension::Relationship
                    | SituationalDimension::Formality
            );
            assert_eq!(dim.is_vep_0004(), expected, "is_vep_0004 wrong for {dim}");
        }
    }

    #[test]
    fn relationship_is_free_form_others_are_not() {
        assert!(SituationalDimension::Relationship.is_free_form());
        for dim in SituationalDimension::all() {
            if *dim != SituationalDimension::Relationship {
                assert!(!dim.is_free_form(), "unexpected free-form for {dim}");
            }
        }
    }

    #[test]
    fn empty_context() {
        let ctx = SituationalContext::default();
        assert!(!ctx.has_any());
        assert!(!ctx.has_vep_0004());
        assert_eq!(ctx.to_wire(), "");
    }

    #[test]
    fn wire_roundtrip_single() {
        let ctx = SituationalContext {
            time: Some(vec!["\u{1F305}".to_string()]),  // sunrise
            space: Some(vec!["\u{1F3E1}".to_string()]), // house
            ..Default::default()
        };

        let wire = ctx.to_wire();
        assert!(wire.contains("\u{23F0}\u{1F305}"));
        assert!(wire.contains("\u{1F4CD}\u{1F3E1}"));
    }

    #[test]
    fn from_wire_basic() {
        let wire = "\u{23F0}\u{1F305}|\u{1F4CD}\u{1F3E1}";
        let ctx = SituationalContext::from_wire(wire).unwrap();

        assert!(ctx.time.is_some());
        assert!(ctx.space.is_some());
        assert!(ctx.company.is_none());
    }

    #[test]
    fn from_wire_empty() {
        let ctx = SituationalContext::from_wire("").unwrap();
        assert!(!ctx.has_any());
    }

    #[test]
    fn from_wire_rejects_ambiguous_or_noncanonical_segments() {
        for malformed in [
            "|",
            "\u{23F0}\u{1F305}|",
            "\u{23F0}",
            "\u{23F0}\u{1F305}|\u{23F0}\u{1F319}",
            "\u{23F0}\u{1F305} ",
        ] {
            assert!(
                SituationalContext::from_wire(malformed).is_err(),
                "accepted {malformed:?}"
            );
        }
        let oversized = format!("⏰{}", "a".repeat(MAX_SITUATIONAL_WIRE_CHARS));
        assert!(SituationalContext::from_wire(&oversized)
            .unwrap_err()
            .to_string()
            .contains("8192 characters"));
    }

    #[test]
    fn get_and_set() {
        let mut ctx = SituationalContext::default();
        assert!(ctx.get(SituationalDimension::Culture).is_none());

        ctx.set(
            SituationalDimension::Culture,
            vec!["\u{1F1EC}\u{1F1E7}".to_string()],
        );
        assert!(ctx.get(SituationalDimension::Culture).is_some());
    }

    #[test]
    fn serde_roundtrip() {
        let ctx = SituationalContext {
            time: Some(vec!["morning".to_string()]),
            company: Some(vec!["alone".to_string()]),
            ..Default::default()
        };

        let json = serde_json::to_string(&ctx).unwrap();
        let parsed: SituationalContext = serde_json::from_str(&json).unwrap();
        assert_eq!(ctx, parsed);
    }

    // ── VEP-0004 ────────────────────────────────────────────

    #[test]
    fn vep_0004_symbols_encode_and_parse() {
        let ctx = SituationalContext {
            embodiment: Some(vec!["\u{270B}".to_string()]), // βœ‹
            proximity: Some(vec!["\u{1F90F}".to_string()]), // 🀏
            relationship: Some(vec!["colleague:professional".to_string()]),
            formality: Some(vec!["\u{1F4BC}".to_string()]), // πŸ’Ό
            ..Default::default()
        };

        let wire = ctx.to_wire();
        assert!(wire.contains("\u{1F9CD}\u{270B}"));
        assert!(wire.contains("\u{2194}\u{FE0F}\u{1F90F}"));
        assert!(wire.contains("\u{1FAA2}colleague:professional"));
        assert!(wire.contains("\u{1F3A9}\u{1F4BC}"));

        let parsed = SituationalContext::from_wire(&wire).unwrap();
        assert_eq!(
            parsed.embodiment.as_deref(),
            Some(&["\u{270B}".to_string()][..])
        );
        assert_eq!(
            parsed.proximity.as_deref(),
            Some(&["\u{1F90F}".to_string()][..])
        );
        assert_eq!(
            parsed.relationship.as_deref(),
            Some(&["colleague:professional".to_string()][..])
        );
        assert_eq!(
            parsed.formality.as_deref(),
            Some(&["\u{1F4BC}".to_string()][..])
        );
    }

    #[test]
    fn has_vep_0004_is_true_when_vep_dim_set() {
        let mut ctx = SituationalContext {
            time: Some(vec!["\u{1F305}".to_string()]),
            ..Default::default()
        };
        assert!(!ctx.has_vep_0004());

        ctx.formality = Some(vec!["\u{1F4BC}".to_string()]);
        assert!(ctx.has_vep_0004());
    }

    #[test]
    fn canonical_thirteen_dim_example_encodes() {
        let ctx = SituationalContext {
            time: Some(vec!["\u{1F305}".to_string()]),      // πŸŒ…
            space: Some(vec!["\u{1F3E2}".to_string()]),     // 🏒
            company: Some(vec!["\u{1F454}".to_string()]),   // πŸ‘”
            occasion: Some(vec!["\u{1F4BC}".to_string()]),  // πŸ’Ό
            embodiment: Some(vec!["\u{270B}".to_string()]), // βœ‹
            proximity: Some(vec!["\u{1F90F}".to_string()]), // 🀏
            relationship: Some(vec!["colleague:professional".to_string()]),
            formality: Some(vec!["\u{1F4BC}".to_string()]), // πŸ’Ό
            ..Default::default()
        };

        let expected = "\u{23F0}\u{1F305}\
                        |\u{1F4CD}\u{1F3E2}\
                        |\u{1F465}\u{1F454}\
                        |\u{1F3AD}\u{1F4BC}\
                        |\u{1F9CD}\u{270B}\
                        |\u{2194}\u{FE0F}\u{1F90F}\
                        |\u{1FAA2}colleague:professional\
                        |\u{1F3A9}\u{1F4BC}";
        assert_eq!(ctx.to_wire(), expected);
    }
}