harn-cli 0.10.132

CLI for the Harn programming language — run, test, REPL, format, and lint
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
//! Generated projections of the Harn-owned deterministic session recap.
//!
//! The runtime DTOs and JSON schema in `harn_vm::session_recap` own meaning.
//! This module keeps every host-language projection and the non-vacuous wire
//! fixture together so adding a field cannot hide in one language emitter.

use serde_json::{json, Value};

pub(super) fn session_recap_round_trip_fixture() -> Result<Value, String> {
    let source_events = (1..=9)
        .map(|event_id| {
            json!({
                "eventId": event_id,
                "recordHash": format!("sha256:fixture-{event_id}"),
            })
        })
        .collect::<Vec<_>>();
    let wire = json!({
        "state": "available",
        "snapshot": {
            "schemaVersion": harn_vm::session_recap::SESSION_RECAP_SCHEMA_VERSION,
            "sessionId": "session-recap-fixture",
            "query": {
                "sessionId": "session-recap-fixture",
                "runId": "run-recap-fixture",
                "turnId": "turn-recap-fixture",
                "fromEventId": 1,
                "limit": 32
            },
            "cursor": {"lastEventId": 9, "nextEventId": 10},
            "coverage": {
                "scanned": 9,
                "matched": 9,
                "pending": 1,
                "unassigned": 0,
                "truncated": true
            },
            "source": {"firstEventId": 1, "lastEventId": 9, "events": source_events},
            "contentHash": "sha256:fixture-content",
            "projectionHash": "sha256:fixture-projection",
            "turns": [{
                "turnId": "turn-recap-fixture",
                "runId": "run-recap-fixture",
                "state": "complete",
                "prompts": [{"text": "Investigate the incident", "sourceEventId": 1}],
                "iterations": [{
                    "iteration": 0,
                    "state": "complete",
                    "assistantText": [{"text": "I found and fixed the cause.", "sourceEventId": 3}],
                    "tools": [{
                        "toolCallId": "tool-recap-fixture",
                        "toolName": "write_file",
                        "state": "completed",
                        "callObserved": true,
                        "resultObserved": true,
                        "input": {"path": "src/lib.rs"},
                        "output": {"changed": true},
                        "verification": {
                            "schema": "harn.agent_tool_postcondition.v1",
                            "status": "passed",
                            "verifiedPaths": ["src/lib.rs"],
                            "sourceEventId": 5
                        },
                        "sourceEventIds": [4, 5]
                    }],
                    "plans": [{
                        "documentId": "plan-recap-fixture",
                        "revisionId": "revision-recap-fixture",
                        "title": "Repair the incident",
                        "summary": "Fix and verify the owning seam",
                        "steps": [{
                            "id": "step-recap-fixture",
                            "content": "Run the regression",
                            "status": "completed"
                        }],
                        "event": {
                            "kind": "updated",
                            "eventId": "plan-event-recap-fixture",
                            "inputRevisionId": "revision-before-recap-fixture"
                        },
                        "sourceEventId": 6
                    }],
                    "progress": [{
                        "message": "Regression is green",
                        "entries": [{
                            "content": "Verify the canonical path",
                            "status": "completed",
                            "priority": "high"
                        }],
                        "replace": true,
                        "sourceEventId": 7
                    }],
                    "sourceEventIds": [2, 3, 4, 5, 6, 7, 8]
                }],
                "terminal": {
                    "state": "complete",
                    "finalStatus": "done",
                    "stopReason": "completed",
                    "kind": "natural",
                    "owner": "agent",
                    "reason": "verified",
                    "sourceEventId": 9
                },
                "sourceEventIds": [1, 2, 3, 4, 5, 6, 7, 8, 9]
            }],
            "extensions": {
                "example.harn.dev/recap": {"label": "fixture"}
            }
        }
    });
    let typed: harn_vm::session_recap::SessionRecapAvailability = serde_json::from_value(wire)
        .map_err(|error| format!("session recap fixture does not match runtime types: {error}"))?;
    serde_json::to_value(typed)
        .map_err(|error| format!("failed to encode typed session recap fixture: {error}"))
}

pub(super) fn append_typescript_session_recap_types(out: &mut String) {
    out.push_str(
        r#"
export const HARN_SESSION_RECAP_QUERY_METHOD = "harn.session_recap.query" as const
export const HARN_SESSION_RECAP_SCHEMA_VERSION = 1 as const

"#,
    );
    super::recap_records::append_enums(out, super::records::Target::Typescript);
    super::recap_records::append(out, super::records::Target::Typescript);
    out.push_str(r#"
export type HarnSessionRecapAvailability =
  | { state: "available"; snapshot: HarnSessionRecapSnapshot }
  | { state: "unavailable"; reason: HarnSessionRecapUnavailableReason }

function harnSessionRecapObject(value: unknown, label: string, keys: readonly string[]): Record<string, unknown> {
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
    throw new TypeError(`${label} must be an object`)
  }
  const object = value as Record<string, unknown>
  const known = new Set(keys)
  for (const key of Object.keys(object)) {
    if (!known.has(key)) throw new TypeError(`${label} contains unknown field ${key}`)
  }
  return object
}

function harnSessionRecapArray(value: unknown, label: string): unknown[] {
  if (!Array.isArray(value)) throw new TypeError(`${label} must be an array`)
  return value
}

"#,
    );
    super::recap_records::append_validators(out, super::records::Target::Typescript);
    out.push_str(r#"

/** Decode the closed recap envelope without silently dropping future fields. */
export function decodeHarnSessionRecapAvailability(value: unknown): HarnSessionRecapAvailability {
  const base = harnSessionRecapObject(value, "Harn session recap availability", ["state", "snapshot", "reason"])
  const availability = base as Record<string, unknown>
  if (availability.state === "unavailable") {
    harnSessionRecapObject(value, "Harn session recap availability", ["state", "reason"])
    return value as HarnSessionRecapAvailability
  }
  if (availability.state !== "available") {
    throw new TypeError("Harn session recap availability has an unknown state")
  }
  harnSessionRecapObject(value, "Harn session recap availability", ["state", "snapshot"])
  validateHarnSessionRecapSnapshot(availability.snapshot)
  return value as HarnSessionRecapAvailability
}
"#,
    );
}

pub(super) fn append_rust_session_recap_types(out: &mut String) {
    out.push_str(
        r#"
pub const HARN_SESSION_RECAP_QUERY_METHOD: &str = "harn.session_recap.query";
pub const HARN_SESSION_RECAP_SCHEMA_VERSION: u32 = 1;

"#,
    );
    super::recap_records::append_enums(out, super::records::Target::Rust);
    super::recap_records::append(out, super::records::Target::Rust);
    out.push_str(
        r#"
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "state", rename_all = "snake_case", deny_unknown_fields)]
pub enum HarnSessionRecapAvailability {
    Available { snapshot: Box<HarnSessionRecapSnapshot> },
    Unavailable { reason: HarnSessionRecapUnavailableReason },
}
"#,
    );
}

pub(super) fn append_swift_session_recap_types(out: &mut String) {
    out.push_str(
        r#"
public enum HarnSessionRecapProtocol {
    public static let queryMethod = "harn.session_recap.query"
    public static let schemaVersion = 1
}
"#,
    );
    super::recap_records::append_enums(out, super::records::Target::Swift);
    super::recap_records::append(out, super::records::Target::Swift);
    out.push_str(
        r#"
public struct HarnSessionRecapAvailability: Codable, Sendable, Equatable {
    public var state: HarnSessionRecapAvailabilityState
    public var snapshot: HarnSessionRecapSnapshot?
    public var reason: HarnSessionRecapUnavailableReason?
}

private struct HarnSessionRecapAnyCodingKey: CodingKey {
    var stringValue: String
    var intValue: Int?
    init?(stringValue: String) { self.stringValue = stringValue; self.intValue = nil }
    init?(intValue: Int) { self.stringValue = String(intValue); self.intValue = intValue }
}

private func harnSessionRecapObject(
    _ value: HarnACPValue?,
    label: String,
    keys: Set<String>
) throws -> [String: HarnACPValue] {
    guard case .object(let object) = value else {
        throw DecodingError.dataCorrupted(
            .init(codingPath: [], debugDescription: "\(label) must be an object")
        )
    }
    if let unknown = object.keys.first(where: { !keys.contains($0) }) {
        throw DecodingError.dataCorrupted(
            .init(codingPath: [], debugDescription: "\(label) contains unknown field \(unknown)")
        )
    }
    return object
}

private func harnSessionRecapArray(_ value: HarnACPValue?, label: String) throws -> [HarnACPValue] {
    guard case .array(let array) = value else {
        throw DecodingError.dataCorrupted(
            .init(codingPath: [], debugDescription: "\(label) must be an array")
        )
    }
    return array
}

"#,
    );
    super::recap_records::append_validators(out, super::records::Target::Swift);
    out.push_str(r#"

extension HarnSessionRecapAvailability {
    private enum CodingKeys: String, CodingKey { case state, snapshot, reason }

    public init(from decoder: Decoder) throws {
        let raw = try HarnACPValue(from: decoder)
        let object = try harnSessionRecapObject(raw, label: "Harn session recap availability", keys: ["state", "snapshot", "reason"])
        let values = try decoder.container(keyedBy: CodingKeys.self)
        state = try values.decode(HarnSessionRecapAvailabilityState.self, forKey: .state)
        switch state {
        case .available:
            if Set(object.keys) != Set(["state", "snapshot"]) {
                throw DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "available Harn session recap requires only snapshot"))
            }
            try validateHarnSessionRecapSnapshot(object["snapshot"])
            snapshot = try values.decode(HarnSessionRecapSnapshot.self, forKey: .snapshot)
            reason = nil
        case .unavailable:
            if Set(object.keys) != Set(["state", "reason"]) {
                throw DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "unavailable Harn session recap requires only reason"))
            }
            snapshot = nil
            reason = try values.decode(HarnSessionRecapUnavailableReason.self, forKey: .reason)
        }
    }

    public func encode(to encoder: Encoder) throws {
        var values = encoder.container(keyedBy: CodingKeys.self)
        try values.encode(state, forKey: .state)
        switch state {
        case .available: try values.encode(snapshot, forKey: .snapshot)
        case .unavailable: try values.encode(reason, forKey: .reason)
        }
    }
}

extension HarnSessionRecapSnapshot {
    private enum CodingKeys: String, CodingKey, CaseIterable {
        case schemaVersion, sessionId, query, cursor, coverage, source
        case contentHash, projectionHash, turns, extensions
    }

    public init(from decoder: Decoder) throws {
        let raw = try decoder.container(keyedBy: HarnSessionRecapAnyCodingKey.self)
        let known = Set(CodingKeys.allCases.map(\.rawValue))
        if let unknown = raw.allKeys.first(where: { !known.contains($0.stringValue) }) {
            throw DecodingError.dataCorruptedError(
                forKey: unknown,
                in: raw,
                debugDescription: "Harn session recap snapshot contains unknown field \(unknown.stringValue)"
            )
        }
        let values = try decoder.container(keyedBy: CodingKeys.self)
        schemaVersion = try values.decode(Int.self, forKey: .schemaVersion)
        sessionId = try values.decode(String.self, forKey: .sessionId)
        query = try values.decode(HarnSessionRecapQuery.self, forKey: .query)
        cursor = try values.decode(HarnSessionRecapCursor.self, forKey: .cursor)
        coverage = try values.decode(HarnSessionRecapCoverage.self, forKey: .coverage)
        source = try values.decode(HarnSessionRecapSource.self, forKey: .source)
        contentHash = try values.decode(String.self, forKey: .contentHash)
        projectionHash = try values.decode(String.self, forKey: .projectionHash)
        turns = try values.decode([HarnSessionPromptTurnRecap].self, forKey: .turns)
        extensions = try values.decode([String: HarnACPValue].self, forKey: .extensions)
    }

    public func encode(to encoder: Encoder) throws {
        var values = encoder.container(keyedBy: CodingKeys.self)
        try values.encode(schemaVersion, forKey: .schemaVersion)
        try values.encode(sessionId, forKey: .sessionId)
        try values.encode(query, forKey: .query)
        try values.encode(cursor, forKey: .cursor)
        try values.encode(coverage, forKey: .coverage)
        try values.encode(source, forKey: .source)
        try values.encode(contentHash, forKey: .contentHash)
        try values.encode(projectionHash, forKey: .projectionHash)
        try values.encode(turns, forKey: .turns)
        try values.encode(extensions, forKey: .extensions)
    }
}
"#,
    );
}

pub(super) fn append_python_session_recap_types(out: &mut String) {
    out.push_str(
        r#"

HARN_SESSION_RECAP_QUERY_METHOD: str = "harn.session_recap.query"
HARN_SESSION_RECAP_SCHEMA_VERSION: int = 1

"#,
    );
    super::recap_records::append_enums(out, super::records::Target::Python);
    out.push_str(r#"

class _HarnStrictRecapDataclass(_HarnDataclass):
    @classmethod
    def _strict_values(cls, data: Mapping[str, Any]) -> Dict[str, Any]:
        if not isinstance(data, Mapping):
            raise TypeError(f"{cls.__name__}.from_wire expected a mapping, got {type(data).__name__}")
        expected = {item.name for item in fields(cls)}  # type: ignore[arg-type]
        unknown = set(data) - expected
        missing = expected - set(data)
        if unknown:
            raise ValueError(f"{cls.__name__} contains unknown fields: {', '.join(sorted(unknown))}")
        if missing:
            raise ValueError(f"{cls.__name__} is missing fields: {', '.join(sorted(missing))}")
        return dict(data)

    @classmethod
    def from_wire(cls: Type[_T], data: Mapping[str, Any]) -> _T:
        return cls(**cls._strict_values(data))

    def to_wire(self) -> JsonObject:
        return _harn_recap_wire(self)

def _harn_recap_wire(value: Any) -> Any:
    if is_dataclass(value):
        return _harn_recap_wire(asdict(value))
    if isinstance(value, dict):
        return {key: _harn_recap_wire(item) for key, item in value.items()}
    if isinstance(value, list):
        return [_harn_recap_wire(item) for item in value]
    if isinstance(value, Enum):
        return value.value
    return value

"#,
    );
    super::recap_records::append(out, super::records::Target::Python);
    out.push_str(r#"
@dataclass
class HarnSessionRecapAvailability(_HarnDataclass):
    state: HarnSessionRecapAvailabilityState
    snapshot: Optional[HarnSessionRecapSnapshot] = None
    reason: Optional[HarnSessionRecapUnavailableReason] = None

    @classmethod
    def from_wire(cls, data: Mapping[str, Any]) -> "HarnSessionRecapAvailability":
        if not isinstance(data, Mapping):
            raise TypeError(f"HarnSessionRecapAvailability.from_wire expected a mapping, got {type(data).__name__}")
        state = HarnSessionRecapAvailabilityState(data.get("state"))
        expected = {"state", "snapshot"} if state is HarnSessionRecapAvailabilityState.AVAILABLE else {"state", "reason"}
        unknown = set(data) - expected
        missing = expected - set(data)
        if unknown:
            raise ValueError(f"HarnSessionRecapAvailability contains unknown fields: {', '.join(sorted(unknown))}")
        if missing:
            raise ValueError(f"HarnSessionRecapAvailability is missing fields: {', '.join(sorted(missing))}")
        if state is HarnSessionRecapAvailabilityState.AVAILABLE:
            return cls(state=state, snapshot=HarnSessionRecapSnapshot.from_wire(data["snapshot"]))
        return cls(state=state, reason=HarnSessionRecapUnavailableReason(data["reason"]))

    def to_wire(self) -> JsonObject:
        if self.state is HarnSessionRecapAvailabilityState.AVAILABLE:
            if self.snapshot is None or self.reason is not None:
                raise ValueError("available Harn session recap requires only snapshot")
            return {"state": self.state.value, "snapshot": _harn_recap_wire(self.snapshot)}
        if self.reason is None or self.snapshot is not None:
            raise ValueError("unavailable Harn session recap requires only reason")
        return {"state": self.state.value, "reason": self.reason.value}
"#,
    );
}

pub(super) fn append_go_session_recap_types(out: &mut String) {
    out.push_str(
        r#"

const HarnSessionRecapQueryMethod = "harn.session_recap.query"
const HarnSessionRecapSchemaVersion uint32 = 1

"#,
    );
    super::recap_records::append_enums(out, super::records::Target::Go);
    out.push_str(
        r#"

const HarnSessionRecapVerificationPassed HarnSessionRecapVerificationStatus = "passed"

func (status *HarnSessionRecapVerificationStatus) UnmarshalJSON(data []byte) error {
	var decoded string
	if err := json.Unmarshal(data, &decoded); err != nil { return err }
	if decoded != string(HarnSessionRecapVerificationPassed) {
		return fmt.Errorf("unknown Harn session recap verification status %q", decoded)
	}
	*status = HarnSessionRecapVerificationPassed
	return nil
}

"#,
    );
    super::recap_records::append(out, super::records::Target::Go);
    out.push_str(r#"

func harnSessionRecapDecodeStrict[T any](data []byte, target *T) error {
	decoder := json.NewDecoder(bytes.NewReader(data))
	decoder.DisallowUnknownFields()
	return decoder.Decode(target)
}

func (value *HarnSessionRecapQuery) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapQuery; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapQuery(decoded); return nil }
func (value *HarnSessionRecapCursor) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapCursor; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapCursor(decoded); return nil }
func (value *HarnSessionRecapCoverage) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapCoverage; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapCoverage(decoded); return nil }
func (value *HarnSessionRecapSourceEvent) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapSourceEvent; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapSourceEvent(decoded); return nil }
func (value *HarnSessionRecapSource) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapSource; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapSource(decoded); return nil }
func (value *HarnSessionRecapTextFact) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapTextFact; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapTextFact(decoded); return nil }
func (value *HarnSessionRecapVerificationFact) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapVerificationFact; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapVerificationFact(decoded); return nil }
func (value *HarnSessionRecapToolExchange) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapToolExchange; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapToolExchange(decoded); return nil }
func (value *HarnSessionRecapPlanStep) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapPlanStep; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapPlanStep(decoded); return nil }
func (value *HarnSessionRecapPlanEventFact) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapPlanEventFact; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapPlanEventFact(decoded); return nil }
func (value *HarnSessionRecapPlanFact) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapPlanFact; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapPlanFact(decoded); return nil }
func (value *HarnSessionRecapProgressEntry) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapProgressEntry; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapProgressEntry(decoded); return nil }
func (value *HarnSessionRecapProgressFact) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapProgressFact; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapProgressFact(decoded); return nil }
func (value *HarnSessionRecapTerminalFact) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapTerminalFact; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapTerminalFact(decoded); return nil }
func (value *HarnSessionRecapIteration) UnmarshalJSON(data []byte) error { type wire HarnSessionRecapIteration; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionRecapIteration(decoded); return nil }
func (value *HarnSessionPromptTurnRecap) UnmarshalJSON(data []byte) error { type wire HarnSessionPromptTurnRecap; var decoded wire; if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }; *value = HarnSessionPromptTurnRecap(decoded); return nil }

func (snapshot *HarnSessionRecapSnapshot) UnmarshalJSON(data []byte) error {
	type wire HarnSessionRecapSnapshot
	var decoded wire
	if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }
	*snapshot = HarnSessionRecapSnapshot(decoded)
	return nil
}

type HarnSessionRecapAvailability struct { State string `json:"state"`; Snapshot *HarnSessionRecapSnapshot `json:"snapshot,omitempty"`; Reason *HarnSessionRecapUnavailableReason `json:"reason,omitempty"` }

func (value *HarnSessionRecapAvailability) UnmarshalJSON(data []byte) error {
	type wire HarnSessionRecapAvailability
	var decoded wire
	if err := harnSessionRecapDecodeStrict(data, &decoded); err != nil { return err }
	switch decoded.State {
	case "available":
		if decoded.Snapshot == nil || decoded.Reason != nil {
			return fmt.Errorf("available Harn session recap requires only snapshot")
		}
	case "unavailable":
		if decoded.Snapshot != nil || decoded.Reason == nil {
			return fmt.Errorf("unavailable Harn session recap requires only reason")
		}
	default:
		return fmt.Errorf("unknown Harn session recap availability state %q", decoded.State)
	}
	*value = HarnSessionRecapAvailability(decoded)
	return nil
}
"#,
    );
}