File size: 3,734 Bytes
8ffc9f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import path from "node:path";
import { promises as fs } from "node:fs";
import { REPO_ROOT } from "./config";

/**
 * Types + reader for the diagnostic catalog. The catalog is generated from
 * `qc/catalog/diagnostic_catalog.yaml` by `python -m qc.catalog render` into
 * `spec/diagnostics/catalog.json`; the studio only reads that JSON (never the YAML).
 */

export interface DiagRelationship {
  relationship: "direct" | "indirect" | "unlikely" | "context_dependent";
  note: string;
}
export interface DiagAlias {
  label: string;
  producer?: string;
  source_scope?: string;
  denominator?: string;
  note?: string;
}
export interface DiagMetric {
  metric_id: string;
  label: string;
  description: string;
  domain: string;
  unit: string;
  value_type: string;
  direction: string;
  scoreability: string;
  required_scopes: string[];
  platforms: string[];
  assays: string[];
  denominator?: string;
  canonical_calculation?: string;
  caveats?: string[];
  aliases?: DiagAlias[];
  references?: string[];
}
export interface DiagSignal {
  signal_id: string;
  label: string;
  description: string;
  metrics: string[];
  platforms?: string[];
  related_causes?: string[];
  is_root_cause?: boolean;
  references?: string[];
}
export interface DiagIssue {
  issue_id: string;
  title: string;
  summary: string;
  outcome_domains: string[];
  platforms: string[];
  workflow_stages: string[];
  supporting_signals: string[];
  contradicting_signals?: string[];
  candidate_root_causes: string[];
  impacts: string[];
  required_evidence: string[];
  missing_evidence?: string[];
  confirmatory_tests: string[];
  recovery_classes: string[];
  computational_actions?: string[];
  sequencing_actions?: string[];
  wetlab_actions?: string[];
  related_issues?: string[];
  simulation_modes?: string[];
  references?: string[];
  what_this_issue_cannot_explain: string;
}
export interface DiagCause {
  cause_id: string;
  title: string;
  mechanism: string;
  workflow_stage: string;
  produces_issues: string[];
  observable_signals: string[];
  evidence_against?: string[];
  required_inputs: string[];
  diagnostic_tests: string[];
  cell_recovery_relationship: DiagRelationship;
  sample_integrity_relationship: DiagRelationship;
  expression_fidelity_relationship: DiagRelationship;
  recoverability: string;
  recommended_actions?: string[];
  references?: string[];
  simulation_modes?: string[];
}
export interface DiagTest {
  test_id: string;
  title: string;
  purpose: string;
  required_inputs: string[];
  algorithm_summary: string;
  outputs: string;
  interpretation: string;
  limitations: string;
  supports_causes: string[];
  rejects_causes?: string[];
  status: "implemented" | "planned" | "external";
  implemented_by?: string;
  references?: string[];
}
export interface DiagRecoveryAction {
  recovery_class: string;
  label: string;
  description: string;
}
export interface DiagReference {
  reference_id: string;
  title: string;
  source: string;
  url?: string;
  assay_context?: string;
  note?: string;
  evidence_strength: string;
}
export interface DiagnosticCatalog {
  catalog_version: string;
  metrics: DiagMetric[];
  signals: DiagSignal[];
  issues: DiagIssue[];
  root_causes: DiagCause[];
  diagnostic_tests: DiagTest[];
  recovery_actions: DiagRecoveryAction[];
  references: DiagReference[];
}

export async function loadDiagnosticCatalog(): Promise<DiagnosticCatalog | null> {
  try {
    const raw = await fs.readFile(
      path.join(REPO_ROOT, "spec", "diagnostics", "catalog.json"),
      "utf8",
    );
    const parsed = JSON.parse(raw) as DiagnosticCatalog;
    if (!parsed || !Array.isArray(parsed.issues)) return null;
    return parsed;
  } catch {
    return null;
  }
}