axiomsync 1.0.0

Core data-processing engine for AxiomSync local retrieval runtime.
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
use serde::{Deserialize, Serialize};

use super::{QueueDiagnostics, ReleaseSecurityAuditMode, ReplayReport};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseCheckDocument {
    pub version: u32,
    pub check_id: String,
    pub created_at: String,
    pub gate_profile: String,
    pub status: ReleaseGateStatus,
    pub passed: bool,
    pub reasons: Vec<String>,
    pub thresholds: ReleaseCheckThresholds,
    pub run_summary: ReleaseCheckRunSummary,
    pub embedding: ReleaseCheckEmbeddingMetadata,
    pub gate_record_uri: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseCheckThresholds {
    pub threshold_p95_ms: u128,
    pub min_top1_accuracy: f32,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub min_stress_top1_accuracy: Option<f32>,
    pub max_p95_regression_pct: Option<f32>,
    pub max_top1_regression_pct: Option<f32>,
    pub window_size: usize,
    pub required_passes: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseCheckRunSummary {
    pub evaluated_runs: usize,
    pub passing_runs: usize,
    pub latest_report_uri: Option<String>,
    pub previous_report_uri: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub latest_p95_latency_us: Option<u128>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub previous_p95_latency_us: Option<u128>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseCheckEmbeddingMetadata {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub embedding_provider: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub embedding_strict_error: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DependencyInventorySummary {
    pub lockfile_present: bool,
    pub package_count: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DependencyAuditSummary {
    pub tool: String,
    pub mode: ReleaseSecurityAuditMode,
    pub available: bool,
    pub executed: bool,
    pub status: DependencyAuditStatus,
    pub advisories_found: usize,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tool_version: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub output_excerpt: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityAuditCheck {
    pub name: String,
    pub passed: bool,
    pub details: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityAuditReport {
    pub report_id: String,
    pub created_at: String,
    pub workspace_dir: String,
    pub passed: bool,
    pub status: EvidenceStatus,
    pub inventory: DependencyInventorySummary,
    pub dependency_audit: DependencyAuditSummary,
    pub checks: Vec<SecurityAuditCheck>,
    pub report_uri: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OperabilityEvidenceCheck {
    pub name: String,
    pub passed: bool,
    pub details: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OperabilitySampleWindow {
    pub trace_limit: usize,
    pub request_limit: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OperabilityCoverage {
    pub traces_analyzed: usize,
    pub request_logs_scanned: usize,
    pub trace_metrics_snapshot_uri: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OperabilityEvidenceReport {
    pub report_id: String,
    pub created_at: String,
    pub passed: bool,
    pub status: EvidenceStatus,
    pub sample_window: OperabilitySampleWindow,
    pub coverage: OperabilityCoverage,
    pub queue: QueueDiagnostics,
    pub checks: Vec<OperabilityEvidenceCheck>,
    pub report_uri: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReliabilityEvidenceCheck {
    pub name: String,
    pub passed: bool,
    pub details: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReliabilityReplayPlan {
    pub replay_limit: usize,
    pub max_cycles: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReliabilityReplayProgress {
    pub replay_cycles: u32,
    pub replay_totals: ReplayReport,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReliabilityQueueDelta {
    pub baseline_dead_letter: u64,
    pub final_dead_letter: u64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub baseline_checkpoint: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub final_checkpoint: Option<i64>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReliabilitySearchProbe {
    pub queued_root_uri: String,
    pub query: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub replay_hit_uri: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub restart_hit_uri: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReliabilityEvidenceReport {
    pub report_id: String,
    pub created_at: String,
    pub passed: bool,
    pub status: EvidenceStatus,
    pub replay_plan: ReliabilityReplayPlan,
    pub replay_progress: ReliabilityReplayProgress,
    pub queue_delta: ReliabilityQueueDelta,
    pub search_probe: ReliabilitySearchProbe,
    pub queue: QueueDiagnostics,
    pub checks: Vec<ReliabilityEvidenceCheck>,
    pub report_uri: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommandProbeResult {
    pub test_name: String,
    pub command_ok: bool,
    pub matched: bool,
    pub output_excerpt: String,
    pub passed: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EpisodicSemverProbeResult {
    pub passed: bool,
    pub error: Option<String>,
    pub manifest_req: Option<String>,
    pub manifest_req_ok: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub manifest_path: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub manifest_path_ok: Option<bool>,
    pub manifest_uses_path: Option<bool>,
    pub manifest_uses_git: Option<bool>,
    pub manifest_source_ok: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub workspace_member_path: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub workspace_member_present: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub workspace_version: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub workspace_version_ok: Option<bool>,
    pub lock_version: Option<String>,
    pub lock_version_ok: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub lock_source: Option<String>,
    pub lock_source_ok: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EpisodicSemverPolicy {
    pub required_major: u64,
    pub required_minor: u64,
    pub required_manifest_path: String,
    pub required_workspace_member: String,
    pub allowed_manifest_operators: Vec<String>,
    pub required_lock_source: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OntologyContractPolicy {
    pub schema_uri: String,
    pub required_schema_version: u32,
    pub probe_test_name: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OntologySchemaVersionProbe {
    pub schema_uri: String,
    pub schema_version: Option<u32>,
    pub schema_version_ok: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OntologySchemaCardinality {
    pub object_type_count: usize,
    pub link_type_count: usize,
    pub action_type_count: usize,
    pub invariant_count: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OntologyInvariantCheckSummary {
    pub passed: usize,
    pub failed: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OntologyContractProbeResult {
    pub passed: bool,
    pub error: Option<String>,
    pub command_probe: CommandProbeResult,
    pub schema: OntologySchemaVersionProbe,
    pub cardinality: OntologySchemaCardinality,
    pub invariant_checks: OntologyInvariantCheckSummary,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContractIntegrityGateDetails {
    pub policy: EpisodicSemverPolicy,
    pub contract_probe: CommandProbeResult,
    pub episodic_api_probe: CommandProbeResult,
    pub episodic_semver_probe: EpisodicSemverProbeResult,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub ontology_policy: Option<OntologyContractPolicy>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub ontology_probe: Option<OntologyContractProbeResult>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReliabilityGateDetails {
    pub status: EvidenceStatus,
    pub replay_done: usize,
    pub dead_letter: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EvalQualityGateDetails {
    pub executed_cases: usize,
    pub top1_accuracy: f32,
    pub min_top1_accuracy: f32,
    pub failed: usize,
    pub filter_ignored: usize,
    pub relation_missing: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionMemoryGateDetails {
    pub base_details: String,
    pub memory_category_miss: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityAuditGateDetails {
    pub status: EvidenceStatus,
    pub mode: ReleaseSecurityAuditMode,
    pub strict_mode_required: bool,
    pub strict_mode: bool,
    pub audit_status: DependencyAuditStatus,
    pub advisories_found: usize,
    pub packages: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkGateDetails {
    pub passed: bool,
    pub evaluated_runs: usize,
    pub passing_runs: usize,
    pub reasons: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OperabilityGateDetails {
    pub status: EvidenceStatus,
    pub traces_analyzed: usize,
    pub request_logs_scanned: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlockerRollupGateDetails {
    pub unresolved_blockers: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BuildQualityGateDetails {
    pub cargo_check: bool,
    pub cargo_fmt: bool,
    pub cargo_clippy: bool,
    pub check_output: String,
    pub fmt_output: String,
    pub clippy_output: String,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ReleaseGateId {
    #[serde(rename = "G0")]
    ContractIntegrity,
    #[serde(rename = "G1")]
    BuildQuality,
    #[serde(rename = "G2")]
    ReliabilityEvidence,
    #[serde(rename = "G3")]
    EvalQuality,
    #[serde(rename = "G4")]
    SessionMemory,
    #[serde(rename = "G5")]
    SecurityAudit,
    #[serde(rename = "G6")]
    Benchmark,
    #[serde(rename = "G7")]
    OperabilityEvidence,
    #[serde(rename = "G8")]
    BlockerRollup,
}

impl ReleaseGateId {
    pub const ALL: [Self; 9] = [
        Self::ContractIntegrity,
        Self::BuildQuality,
        Self::ReliabilityEvidence,
        Self::EvalQuality,
        Self::SessionMemory,
        Self::SecurityAudit,
        Self::Benchmark,
        Self::OperabilityEvidence,
        Self::BlockerRollup,
    ];

    pub const fn code(self) -> &'static str {
        match self {
            Self::ContractIntegrity => "G0",
            Self::BuildQuality => "G1",
            Self::ReliabilityEvidence => "G2",
            Self::EvalQuality => "G3",
            Self::SessionMemory => "G4",
            Self::SecurityAudit => "G5",
            Self::Benchmark => "G6",
            Self::OperabilityEvidence => "G7",
            Self::BlockerRollup => "G8",
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ReleaseGateStatus {
    Pass,
    Fail,
}

impl ReleaseGateStatus {
    pub const fn from_passed(passed: bool) -> Self {
        if passed { Self::Pass } else { Self::Fail }
    }

    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Pass => "pass",
            Self::Fail => "fail",
        }
    }
}

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

pub type EvidenceStatus = ReleaseGateStatus;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DependencyAuditStatus {
    Passed,
    VulnerabilitiesFound,
    ToolMissing,
    Error,
    HostToolsDisabled,
}

impl std::fmt::Display for DependencyAuditStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let value = match self {
            Self::Passed => "passed",
            Self::VulnerabilitiesFound => "vulnerabilities_found",
            Self::ToolMissing => "tool_missing",
            Self::Error => "error",
            Self::HostToolsDisabled => "host_tools_disabled",
        };
        f.write_str(value)
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "kind", content = "data", rename_all = "snake_case")]
pub enum ReleaseGateDetails {
    ContractIntegrity(Box<ContractIntegrityGateDetails>),
    BuildQuality(BuildQualityGateDetails),
    ReliabilityEvidence(ReliabilityGateDetails),
    EvalQuality(EvalQualityGateDetails),
    SessionMemory(SessionMemoryGateDetails),
    SecurityAudit(SecurityAuditGateDetails),
    Benchmark(BenchmarkGateDetails),
    OperabilityEvidence(OperabilityGateDetails),
    BlockerRollup(BlockerRollupGateDetails),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseGateDecision {
    pub gate_id: ReleaseGateId,
    pub passed: bool,
    pub status: ReleaseGateStatus,
    pub details: ReleaseGateDetails,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub evidence_uri: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseGatePackReport {
    pub pack_id: String,
    pub created_at: String,
    pub workspace_dir: String,
    pub passed: bool,
    pub status: ReleaseGateStatus,
    pub unresolved_blockers: usize,
    pub decisions: Vec<ReleaseGateDecision>,
    pub report_uri: String,
}

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

    #[test]
    fn release_gate_status_serde_contract_is_stable() {
        let pass = serde_json::to_string(&ReleaseGateStatus::Pass).expect("serialize pass");
        let fail = serde_json::to_string(&ReleaseGateStatus::Fail).expect("serialize fail");
        assert_eq!(pass, "\"pass\"");
        assert_eq!(fail, "\"fail\"");

        let parsed_pass: ReleaseGateStatus =
            serde_json::from_str("\"pass\"").expect("deserialize pass");
        let parsed_fail: ReleaseGateStatus =
            serde_json::from_str("\"fail\"").expect("deserialize fail");
        assert_eq!(parsed_pass, ReleaseGateStatus::Pass);
        assert_eq!(parsed_fail, ReleaseGateStatus::Fail);
        assert!(serde_json::from_str::<ReleaseGateStatus>("\"PASS\"").is_err());
    }

    #[test]
    fn dependency_audit_status_serde_contract_is_exhaustive_and_stable() {
        let expected = [
            (DependencyAuditStatus::Passed, "passed"),
            (
                DependencyAuditStatus::VulnerabilitiesFound,
                "vulnerabilities_found",
            ),
            (DependencyAuditStatus::ToolMissing, "tool_missing"),
            (DependencyAuditStatus::Error, "error"),
            (
                DependencyAuditStatus::HostToolsDisabled,
                "host_tools_disabled",
            ),
        ];

        for (status, raw) in expected {
            let serialized = serde_json::to_string(&status).expect("serialize status");
            assert_eq!(serialized, format!("\"{raw}\""));
            let deserialized: DependencyAuditStatus =
                serde_json::from_str(&serialized).expect("deserialize status");
            assert_eq!(deserialized, status);
        }
    }
}