lifeloop-cli 0.3.0

Provider-neutral lifecycle abstraction and normalizer for AI harnesses
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
//! Adapter manifest types and built-in manifest registry.

use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

use crate::{
    AdapterRole, FailureClass, IntegrationMode, LifecycleEventKind, SCHEMA_VERSION, SupportState,
    ValidationError, require_non_empty,
};

/// Manifest placement classes — the trust-neutral, lifecycle-timing
/// vocabulary the adapter manifest uses to declare placement support.
///
/// **Distinct from [`crate::PlacementClass`]**, which is the routing
/// vocabulary the runtime uses on `acceptable_placements` for
/// concrete payload delivery. The manifest declares *capability*;
/// the payload envelope declares *routing intent*. A future
/// revision may unify them; the current contract keeps them
/// separate so manifest evolution does not churn payload routing.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ManifestPlacementClass {
    /// Before any frame opens; e.g. session-init context.
    PreSession,
    /// Leading edge of a frame, before user/task input arrives.
    PreFrameLeading,
    /// Trailing edge of a frame, after input but before model execution.
    PreFrameTrailing,
    /// Inside a tool-result envelope returned to the model.
    ToolResult,
    /// Through an operator or manual surface (skill, command, wrapper).
    ManualOperator,
}

impl ManifestPlacementClass {
    pub const ALL: &'static [Self] = &[
        Self::PreSession,
        Self::PreFrameLeading,
        Self::PreFrameTrailing,
        Self::ToolResult,
        Self::ManualOperator,
    ];
}

/// Per-event capability claim inside a manifest.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestLifecycleEventSupport {
    pub support: SupportState,
    /// Integration modes through which the adapter delivers this event.
    /// May be empty when `support` is `unavailable`.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub modes: Vec<IntegrationMode>,
}

/// Per-placement capability claim inside a manifest.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestPlacementSupport {
    pub support: SupportState,
    /// Placement size limit in bytes when the adapter declares one.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_bytes: Option<u64>,
}

/// Capability claim describing how the adapter surfaces
/// `context.pressure_observed` lifecycle evidence.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestContextPressure {
    pub support: SupportState,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub evidence: Option<String>,
}

/// Capability claim describing receipt emission and ledger support.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestReceipts {
    /// Adapter emits its own native receipts.
    pub native: bool,
    /// Lifeloop synthesizes receipts on the adapter's behalf.
    pub lifeloop_synthesized: bool,
    /// Durable cross-invocation receipt ledger.
    pub receipt_ledger: SupportState,
}

/// Per-id support claims for harness identity correlation. Optional
/// on the manifest because a telemetry-only adapter may not expose
/// any of these.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestSessionIdentity {
    pub harness_session_id: SupportState,
    pub harness_run_id: SupportState,
    pub harness_task_id: SupportState,
}

/// Capability claim for the adapter's session-rename surface.
/// Optional on the manifest; absent means "no rename concept."
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestSessionRename {
    pub support: SupportState,
}

/// Capability claim for reset/continuation renewal across a harness
/// boundary. Lifeloop reports whether the adapter can prove the
/// lifecycle path and delivery support; clients own renewal leases,
/// continuation-token policy, and thread/session binding.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestRenewal {
    pub reset: ManifestRenewalReset,
    pub continuation: ManifestRenewalContinuation,
    /// Host integration profile ids required for this renewal path
    /// when the claim is not available through every install shape.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub profiles: Vec<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub evidence: Option<String>,
}

/// Reset-side renewal capability. `native`, `wrapper_mediated`, and
/// `manual` are separate so a manifest can distinguish a real harness
/// reset surface, a launcher/wrapper path, an operator-only path, and
/// the all-`unavailable` "no safe reset path" case.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestRenewalReset {
    pub native: SupportState,
    pub wrapper_mediated: SupportState,
    pub manual: SupportState,
}

/// Continuation-side renewal capability. Observation means the
/// adapter can prove a continuation boundary happened; payload
/// delivery means it can carry client-provided continuation facts
/// across that boundary.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestRenewalContinuation {
    pub observation: SupportState,
    pub payload_delivery: SupportState,
}

/// Capability claim for operator approval/intervention surfaces.
/// Optional; absent means "no operator surface."
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestApprovalSurface {
    pub support: SupportState,
}

/// One telemetry source the adapter exposes for lifecycle evidence.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestTelemetrySource {
    pub source: String,
    pub support: SupportState,
}

/// One pre-declared capability degradation the adapter ships with.
/// Lets a manifest say "this build's `context_pressure` was native
/// upstream but is currently `unavailable` here" without firing a
/// runtime `capability.degraded` event.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestKnownDegradation {
    pub capability: String,
    pub previous_support: SupportState,
    pub current_support: SupportState,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub evidence: Option<String>,
}

/// Adapter manifest. Issue #6 lands the full shape; pre-issue-#6
/// drafts shipped a stub with only schema_version, adapter_id,
/// adapter_version, display_name, roles, integration_modes, and
/// lifecycle_events.
///
/// `contract_version` (this struct's first field) carries the
/// Lifeloop contract version label (e.g. `lifeloop.v0.2`),
/// independent of `adapter_version`. The two are separate so
/// adapters can iterate without bumping the contract.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AdapterManifest {
    pub contract_version: String,
    pub adapter_id: String,
    pub adapter_version: String,
    pub display_name: String,
    pub role: AdapterRole,
    pub integration_modes: Vec<IntegrationMode>,
    pub lifecycle_events: BTreeMap<LifecycleEventKind, ManifestLifecycleEventSupport>,
    pub placement: BTreeMap<ManifestPlacementClass, ManifestPlacementSupport>,
    pub context_pressure: ManifestContextPressure,
    pub receipts: ManifestReceipts,

    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub session_identity: Option<ManifestSessionIdentity>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub session_rename: Option<ManifestSessionRename>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub renewal: Option<ManifestRenewal>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approval_surface: Option<ManifestApprovalSurface>,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub failure_modes: Vec<FailureClass>,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub telemetry_sources: Vec<ManifestTelemetrySource>,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub known_degradations: Vec<ManifestKnownDegradation>,
}

impl AdapterManifest {
    pub fn validate(&self) -> Result<(), ValidationError> {
        if self.contract_version != SCHEMA_VERSION {
            return Err(ValidationError::SchemaVersionMismatch {
                expected: SCHEMA_VERSION.to_string(),
                found: self.contract_version.clone(),
            });
        }
        require_non_empty(&self.adapter_id, "manifest.adapter_id")?;
        require_non_empty(&self.adapter_version, "manifest.adapter_version")?;
        require_non_empty(&self.display_name, "manifest.display_name")?;
        if self.integration_modes.is_empty() {
            return Err(ValidationError::InvalidManifest(
                "manifest.integration_modes must declare at least one integration mode".into(),
            ));
        }
        for deg in &self.known_degradations {
            require_non_empty(&deg.capability, "manifest.known_degradations[].capability")?;
        }
        for src in &self.telemetry_sources {
            require_non_empty(&src.source, "manifest.telemetry_sources[].source")?;
        }
        if let Some(renewal) = &self.renewal
            && let Some(evidence) = &renewal.evidence
        {
            require_non_empty(evidence, "manifest.renewal.evidence")?;
        }
        if let Some(renewal) = &self.renewal {
            for profile in &renewal.profiles {
                require_non_empty(profile, "manifest.renewal.profiles[]")?;
            }
        }
        Ok(())
    }
}

// ----------------------------------------------------------------------------
// Manifest registry
// ----------------------------------------------------------------------------

/// Conformance posture of a registered adapter.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ConformanceLevel {
    /// v1-conformance adapter: every capability claim that depends on
    /// extracted code (asset rendering, telemetry, placement) is
    /// paired with a test that verifies the claim.
    V1Conformance,
    /// Initial manifest shipped without full claim verification. The
    /// claims describe expected behavior so clients can negotiate, but
    /// the registry does not yet run capability-claim tests for them.
    PreConformance,
}

/// Registry entry pairing an [`AdapterManifest`] with its
/// [`ConformanceLevel`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RegisteredAdapter {
    pub manifest: AdapterManifest,
    pub conformance: ConformanceLevel,
}

/// Built-in adapter manifest registry. Order is stable so callers
/// that render a `lifeloop adapters` listing get a predictable
/// output without sorting client-side.
pub fn manifest_registry() -> Vec<RegisteredAdapter> {
    vec![
        RegisteredAdapter {
            manifest: codex_manifest(),
            conformance: ConformanceLevel::V1Conformance,
        },
        RegisteredAdapter {
            manifest: claude_manifest(),
            conformance: ConformanceLevel::V1Conformance,
        },
        RegisteredAdapter {
            manifest: hermes_manifest(),
            conformance: ConformanceLevel::PreConformance,
        },
        RegisteredAdapter {
            manifest: openclaw_manifest(),
            conformance: ConformanceLevel::PreConformance,
        },
        RegisteredAdapter {
            manifest: gemini_manifest(),
            conformance: ConformanceLevel::PreConformance,
        },
        RegisteredAdapter {
            manifest: opencode_manifest(),
            conformance: ConformanceLevel::PreConformance,
        },
    ]
}

/// Resolve a registered adapter by `adapter_id`. Returns `None` for
/// unknown ids.
pub fn lookup_manifest(adapter_id: &str) -> Option<RegisteredAdapter> {
    manifest_registry()
        .into_iter()
        .find(|entry| entry.manifest.adapter_id == adapter_id)
}

fn synthesized() -> SupportState {
    SupportState::Synthesized
}

fn native() -> SupportState {
    SupportState::Native
}

fn unavailable() -> SupportState {
    SupportState::Unavailable
}

fn manual() -> SupportState {
    SupportState::Manual
}

/// Codex manifest. Native-hook integration covers Codex's stable hook
/// surface, including `PreCompact` in Codex CLI 0.129+. Capability
/// claims here are paired with verification tests in
/// `tests/manifest_claims.rs`.
pub fn codex_manifest() -> AdapterManifest {
    let lifecycle_events = BTreeMap::from([
        (
            LifecycleEventKind::SessionStarting,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::SessionStarted,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::FrameOpening,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::FrameOpened,
            ManifestLifecycleEventSupport {
                support: synthesized(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::ContextPressureObserved,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::ContextCompacted,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::FrameEnding,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::FrameEnded,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::SessionEnding,
            ManifestLifecycleEventSupport {
                support: unavailable(),
                modes: Vec::new(),
            },
        ),
        (
            LifecycleEventKind::SessionEnded,
            ManifestLifecycleEventSupport {
                support: unavailable(),
                modes: Vec::new(),
            },
        ),
        (
            LifecycleEventKind::SupervisorTick,
            ManifestLifecycleEventSupport {
                support: unavailable(),
                modes: Vec::new(),
            },
        ),
        (
            LifecycleEventKind::CapabilityDegraded,
            ManifestLifecycleEventSupport {
                support: synthesized(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::ReceiptEmitted,
            ManifestLifecycleEventSupport {
                support: synthesized(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::ReceiptGapDetected,
            ManifestLifecycleEventSupport {
                support: unavailable(),
                modes: Vec::new(),
            },
        ),
    ]);

    let placement = BTreeMap::from([
        (
            ManifestPlacementClass::PreSession,
            ManifestPlacementSupport {
                support: native(),
                max_bytes: Some(8192),
            },
        ),
        (
            ManifestPlacementClass::PreFrameLeading,
            ManifestPlacementSupport {
                support: native(),
                max_bytes: Some(8192),
            },
        ),
        (
            ManifestPlacementClass::PreFrameTrailing,
            ManifestPlacementSupport {
                support: unavailable(),
                max_bytes: None,
            },
        ),
        (
            ManifestPlacementClass::ToolResult,
            ManifestPlacementSupport {
                support: unavailable(),
                max_bytes: None,
            },
        ),
        (
            ManifestPlacementClass::ManualOperator,
            ManifestPlacementSupport {
                support: manual(),
                max_bytes: None,
            },
        ),
    ]);

    AdapterManifest {
        contract_version: SCHEMA_VERSION.to_string(),
        adapter_id: "codex".into(),
        adapter_version: "0.1.0".into(),
        display_name: "Codex".into(),
        role: AdapterRole::PrimaryWorker,
        integration_modes: vec![IntegrationMode::NativeHook, IntegrationMode::ManualSkill],
        lifecycle_events,
        placement,
        context_pressure: ManifestContextPressure {
            support: native(),
            evidence: Some(
                "Codex CLI 0.129 exposes PreCompact before context pressure handling and PostCompact after context compacts"
                    .into(),
            ),
        },
        receipts: ManifestReceipts {
            native: false,
            lifeloop_synthesized: true,
            receipt_ledger: unavailable(),
        },
        session_identity: Some(ManifestSessionIdentity {
            harness_session_id: native(),
            harness_run_id: synthesized(),
            harness_task_id: unavailable(),
        }),
        session_rename: None,
        renewal: Some(ManifestRenewal {
            reset: ManifestRenewalReset {
                native: unavailable(),
                wrapper_mediated: synthesized(),
                manual: manual(),
            },
            continuation: ManifestRenewalContinuation {
                observation: native(),
                payload_delivery: synthesized(),
            },
            profiles: vec![crate::host_assets::CCD_RENEWAL_PROFILE.id.into()],
            evidence: Some(
                "Codex Stop block-as-continuation evidence plus the opt-in renewal host-hook profile proves wrapper-mediated reset prepare and out-of-band continuation-token delivery"
                    .into(),
            ),
        }),
        approval_surface: None,
        failure_modes: vec![FailureClass::TransportError, FailureClass::PayloadTooLarge],
        telemetry_sources: Vec::new(),
        known_degradations: Vec::new(),
    }
}

/// Claude manifest. Native-hook integration via `.claude/settings.json`.
pub fn claude_manifest() -> AdapterManifest {
    let lifecycle_events = BTreeMap::from([
        (
            LifecycleEventKind::SessionStarting,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::SessionStarted,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::FrameOpening,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::FrameOpened,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::ContextPressureObserved,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::ContextCompacted,
            ManifestLifecycleEventSupport {
                support: unavailable(),
                modes: Vec::new(),
            },
        ),
        (
            LifecycleEventKind::FrameEnding,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::FrameEnded,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::SessionEnding,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::SessionEnded,
            ManifestLifecycleEventSupport {
                support: native(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::SupervisorTick,
            ManifestLifecycleEventSupport {
                support: unavailable(),
                modes: Vec::new(),
            },
        ),
        (
            LifecycleEventKind::CapabilityDegraded,
            ManifestLifecycleEventSupport {
                support: synthesized(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::ReceiptEmitted,
            ManifestLifecycleEventSupport {
                support: synthesized(),
                modes: vec![IntegrationMode::NativeHook],
            },
        ),
        (
            LifecycleEventKind::ReceiptGapDetected,
            ManifestLifecycleEventSupport {
                support: unavailable(),
                modes: Vec::new(),
            },
        ),
    ]);

    let placement = BTreeMap::from([
        (
            ManifestPlacementClass::PreSession,
            ManifestPlacementSupport {
                support: native(),
                max_bytes: Some(16_384),
            },
        ),
        (
            ManifestPlacementClass::PreFrameLeading,
            ManifestPlacementSupport {
                support: native(),
                max_bytes: Some(16_384),
            },
        ),
        (
            ManifestPlacementClass::PreFrameTrailing,
            ManifestPlacementSupport {
                support: unavailable(),
                max_bytes: None,
            },
        ),
        (
            ManifestPlacementClass::ToolResult,
            ManifestPlacementSupport {
                support: unavailable(),
                max_bytes: None,
            },
        ),
        (
            ManifestPlacementClass::ManualOperator,
            ManifestPlacementSupport {
                support: manual(),
                max_bytes: None,
            },
        ),
    ]);

    AdapterManifest {
        contract_version: SCHEMA_VERSION.to_string(),
        adapter_id: "claude".into(),
        adapter_version: "0.1.0".into(),
        display_name: "Claude".into(),
        role: AdapterRole::PrimaryWorker,
        integration_modes: vec![IntegrationMode::NativeHook],
        lifecycle_events,
        placement,
        context_pressure: ManifestContextPressure {
            support: native(),
            evidence: Some(
                "Claude emits PreCompact and SessionEnd events that map directly to context.pressure_observed"
                    .into(),
            ),
        },
        receipts: ManifestReceipts {
            native: false,
            lifeloop_synthesized: true,
            receipt_ledger: unavailable(),
        },
        session_identity: Some(ManifestSessionIdentity {
            harness_session_id: native(),
            harness_run_id: synthesized(),
            harness_task_id: unavailable(),
        }),
        session_rename: None,
        renewal: None,
        approval_surface: None,
        failure_modes: vec![FailureClass::TransportError, FailureClass::PayloadTooLarge],
        telemetry_sources: Vec::new(),
        known_degradations: Vec::new(),
    }
}

/// Hermes pre-conformance manifest. Reference-adapter integration
/// supplied as a JSON descriptor at the path declared in
/// [`crate::host_assets::HERMES_TARGET_ADAPTER`].
pub fn hermes_manifest() -> AdapterManifest {
    pre_conformance_reference_adapter_manifest("hermes", "Hermes")
}

/// OpenClaw pre-conformance manifest.
pub fn openclaw_manifest() -> AdapterManifest {
    pre_conformance_reference_adapter_manifest("openclaw", "OpenClaw")
}

/// Gemini pre-conformance manifest.
pub fn gemini_manifest() -> AdapterManifest {
    pre_conformance_telemetry_only_manifest("gemini", "Gemini")
}

/// OpenCode pre-conformance manifest.
pub fn opencode_manifest() -> AdapterManifest {
    pre_conformance_telemetry_only_manifest("opencode", "OpenCode")
}

fn pre_conformance_reference_adapter_manifest(
    adapter_id: &str,
    display_name: &str,
) -> AdapterManifest {
    let lifecycle_events = BTreeMap::from([
        (
            LifecycleEventKind::SessionStarting,
            ManifestLifecycleEventSupport {
                support: SupportState::Partial,
                modes: vec![IntegrationMode::ReferenceAdapter],
            },
        ),
        (
            LifecycleEventKind::SessionStarted,
            ManifestLifecycleEventSupport {
                support: SupportState::Partial,
                modes: vec![IntegrationMode::ReferenceAdapter],
            },
        ),
        (
            LifecycleEventKind::FrameOpening,
            ManifestLifecycleEventSupport {
                support: SupportState::Partial,
                modes: vec![IntegrationMode::ReferenceAdapter],
            },
        ),
        (
            LifecycleEventKind::FrameEnded,
            ManifestLifecycleEventSupport {
                support: SupportState::Partial,
                modes: vec![IntegrationMode::ReferenceAdapter],
            },
        ),
        (
            LifecycleEventKind::SessionEnded,
            ManifestLifecycleEventSupport {
                support: SupportState::Partial,
                modes: vec![IntegrationMode::ReferenceAdapter],
            },
        ),
    ]);

    let placement = BTreeMap::from([
        (
            ManifestPlacementClass::PreSession,
            ManifestPlacementSupport {
                support: SupportState::Partial,
                max_bytes: None,
            },
        ),
        (
            ManifestPlacementClass::PreFrameLeading,
            ManifestPlacementSupport {
                support: SupportState::Partial,
                max_bytes: None,
            },
        ),
        (
            ManifestPlacementClass::ManualOperator,
            ManifestPlacementSupport {
                support: SupportState::Manual,
                max_bytes: None,
            },
        ),
    ]);

    AdapterManifest {
        contract_version: SCHEMA_VERSION.to_string(),
        adapter_id: adapter_id.to_string(),
        adapter_version: "0.0.1-pre".into(),
        display_name: display_name.to_string(),
        role: AdapterRole::Worker,
        integration_modes: vec![IntegrationMode::ReferenceAdapter],
        lifecycle_events,
        placement,
        context_pressure: ManifestContextPressure {
            support: SupportState::Partial,
            evidence: None,
        },
        receipts: ManifestReceipts {
            native: false,
            lifeloop_synthesized: true,
            receipt_ledger: SupportState::Unavailable,
        },
        session_identity: None,
        session_rename: None,
        renewal: None,
        approval_surface: None,
        failure_modes: Vec::new(),
        telemetry_sources: Vec::new(),
        known_degradations: Vec::new(),
    }
}

fn pre_conformance_telemetry_only_manifest(
    adapter_id: &str,
    display_name: &str,
) -> AdapterManifest {
    let lifecycle_events = BTreeMap::from([
        (
            LifecycleEventKind::SessionStarting,
            ManifestLifecycleEventSupport {
                support: SupportState::Partial,
                modes: vec![IntegrationMode::TelemetryOnly],
            },
        ),
        (
            LifecycleEventKind::ContextPressureObserved,
            ManifestLifecycleEventSupport {
                support: SupportState::Partial,
                modes: vec![IntegrationMode::TelemetryOnly],
            },
        ),
        (
            LifecycleEventKind::SessionEnded,
            ManifestLifecycleEventSupport {
                support: SupportState::Partial,
                modes: vec![IntegrationMode::TelemetryOnly],
            },
        ),
    ]);

    let placement = BTreeMap::from([(
        ManifestPlacementClass::ManualOperator,
        ManifestPlacementSupport {
            support: SupportState::Manual,
            max_bytes: None,
        },
    )]);

    AdapterManifest {
        contract_version: SCHEMA_VERSION.to_string(),
        adapter_id: adapter_id.to_string(),
        adapter_version: "0.0.1-pre".into(),
        display_name: display_name.to_string(),
        role: AdapterRole::Observer,
        integration_modes: vec![IntegrationMode::TelemetryOnly],
        lifecycle_events,
        placement,
        context_pressure: ManifestContextPressure {
            support: SupportState::Partial,
            evidence: None,
        },
        receipts: ManifestReceipts {
            native: false,
            lifeloop_synthesized: true,
            receipt_ledger: SupportState::Unavailable,
        },
        session_identity: None,
        session_rename: None,
        renewal: None,
        approval_surface: None,
        failure_modes: Vec::new(),
        telemetry_sources: Vec::new(),
        known_degradations: Vec::new(),
    }
}