Inquiry API
Status: Generated from current Python docstrings and type hints.
Semantic-inquiry state machine, focus tracking, obligations, hypotheses,
rejections, review reports, and structured diagnostics for the
gaia inquiry CLI sub-app. Five of the 45 public symbols moved here
from gaia.cli.* in alpha 0 (KnowledgeBreakdown, HoleEntry,
analyze_knowledge_breakdown, find_possible_duplicate_claims,
load_or_generate_review_manifest).
gaia.engine.inquiry
gaia.engine.inquiry — spec §10 public surface.
Thin wrapper over Gaia. This module does not run its own compiler, validator, or inference engine; it composes the ones already in Gaia.
SourceAnchor
dataclass
SourceAnchor(file: str, line: int, column: int)
Source location for a DSL declaration inside a package.
to_dict
to_dict() -> dict[str, Any]
Return the JSON-compatible anchor payload.
Source code in gaia/engine/inquiry/anchor.py
65 66 67 | |
HoleEntry
dataclass
HoleEntry(cid: str, label: str, content: str, prior: float | None, prior_justification: str = '')
One independent claim, with or without a prior set.
is_hole
property
is_hole: bool
Return whether this independent claim is missing a prior.
KnowledgeBreakdown
dataclass
KnowledgeBreakdown(settings: list[str] = list(), questions: list[str] = list(), independent: list[HoleEntry] = list(), derived: list[str] = list(), structural: list[str] = list(), background_only: list[str] = list(), orphaned: list[str] = list(), classification: KnowledgeClassification = KnowledgeClassification())
Role-based breakdown of all knowledge nodes in an IR.
holes
property
holes: list[HoleEntry]
Return independent claims that still need priors.
covered
property
covered: list[HoleEntry]
Return independent claims that already have priors.
Diagnostic
dataclass
Diagnostic(severity: Severity, kind: DiagnosticKind, target: str, label: str, message: str, suggested_edit: str = '', data: dict[str, Any] = dict(), source_anchor: SourceAnchor | None = None)
Spec §15 Diagnostic record. Uniform across all detection sources.
to_dict
to_dict() -> dict[str, Any]
Return the diagnostic as a JSON-compatible dictionary.
Source code in gaia/engine/inquiry/diagnostics.py
67 68 69 70 71 72 73 74 | |
NextEdit
dataclass
NextEdit(text: str, kind: str, severity: Severity, target: str, label: str, source_anchor: SourceAnchor | None = None)
Spec §8.8 / Round A2 structured edit suggestion.
text 是渲染给人看的 imperative 一行; source_anchor 在可定位时指向
需要修改的源位置。其余字段复制自产生该 edit 的 Diagnostic。
to_dict
to_dict() -> dict[str, Any]
Return the structured edit as a JSON-compatible dictionary.
Source code in gaia/engine/inquiry/diagnostics.py
92 93 94 95 96 97 98 99 100 101 102 103 | |
ClaimDelta
dataclass
ClaimDelta(label: str, field: str, before: str, after: str)
Per-field change record for a knowledge / strategy / operator / prior.
to_dict
to_dict() -> dict[str, str]
Return the delta record as a JSON-compatible dictionary.
Source code in gaia/engine/inquiry/diff.py
36 37 38 39 40 41 42 43 | |
SemanticDiff
dataclass
SemanticDiff(baseline_review_id: str | None = None, added_claims: list[str] = list(), removed_claims: list[str] = list(), changed_claims: list[ClaimDelta] = list(), added_questions: list[str] = list(), removed_questions: list[str] = list(), added_settings: list[str] = list(), removed_settings: list[str] = list(), added_strategies: list[str] = list(), removed_strategies: list[str] = list(), changed_strategies: list[ClaimDelta] = list(), added_operators: list[str] = list(), removed_operators: list[str] = list(), changed_operators: list[ClaimDelta] = list(), changed_priors: list[ClaimDelta] = list(), changed_exports: list[ClaimDelta] = list())
Spec §9.1 semantic_diff object — covers all 16 §14.2 categories.
is_empty
property
is_empty: bool
Return whether the diff contains no semantic deltas.
to_dict
to_dict() -> dict[str, Any]
Return the full semantic diff as a JSON-compatible dictionary.
Source code in gaia/engine/inquiry/diff.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
FocusBinding
dataclass
FocusBinding(raw: str | None, resolved_id: str | None = None, resolved_label: str | None = None, kind: str = 'freeform')
Resolved inquiry focus target for review and rendering.
to_dict
to_dict() -> dict[str, str | None]
Return the focus binding as a JSON-compatible dictionary.
Source code in gaia/engine/inquiry/focus.py
18 19 20 21 22 23 24 25 | |
HypothesisView
dataclass
HypothesisView(qid: str, content: str, scope_qid: str | None, origin: str)
Display record for an IR or synthetic proof hypothesis.
ObligationView
dataclass
ObligationView(qid: str, target_qid: str | None, content: str, diagnostic_kind: str, origin: str, anchor: dict[str, Any] = dict())
Display record for an IR or synthetic proof obligation.
ProofContext
dataclass
ProofContext(obligations: list[ObligationView] = list(), hypotheses: list[HypothesisView] = list(), rejections: list[RejectionView] = list())
Merged proof-state view shown in inquiry review reports.
to_dict
to_dict() -> dict[str, Any]
Return the proof context as a JSON-compatible dictionary.
Source code in gaia/engine/inquiry/proof_state.py
52 53 54 55 56 57 58 | |
RejectionView
dataclass
RejectionView(qid: str, target_strategy: str, content: str)
Display record for a closed or rejected strategy branch.
ReviewReport
dataclass
ReviewReport(review_id: str, created_at: str, path: str, focus: FocusBinding, mode: str, compile_status: str, ir_hash: str | None, counts: dict[str, int], semantic_diff: SemanticDiff = empty_diff(), graph_health: dict[str, Any] = dict(), inquiry_tree: dict[str, Any] = dict(), prior_holes: list[dict[str, Any]] = list(), belief_report: dict[str, Any] = dict(), diagnostics: list[Diagnostic] = list(), next_edits: list[str] = list(), next_edits_structured: list[NextEdit] = list(), proof_context: ProofContext | None = None)
Passive container for the eight-section Gaia inquiry review report.
to_json_dict
to_json_dict() -> dict[str, Any]
Return the report in the shared JSON dictionary shape.
Source code in gaia/engine/inquiry/review.py
114 115 116 | |
InquiryState
dataclass
InquiryState(version: int = STATE_SCHEMA_VERSION, focus: str | None = None, focus_kind: str | None = None, focus_resolved_id: str | None = None, mode: str = 'auto', last_review_id: str | None = None, baseline_review_id: str | None = None, focus_stack: list[dict[str, Any]] = list(), synthetic_obligations: list[SyntheticObligation] = list(), synthetic_hypotheses: list[SyntheticHypothesis] = list(), synthetic_rejections: list[SyntheticRejection] = list())
Mutable Lean-style inquiry state stored under .gaia/inquiry.
to_dict
to_dict() -> dict[str, Any]
Return the persisted state payload as a JSON-compatible dictionary.
Source code in gaia/engine/inquiry/state.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
SyntheticHypothesis
dataclass
SyntheticHypothesis(qid: str, content: str, scope_qid: str | None = None, created_at: str | None = None)
Synthetic hypothesis tracked outside compiled IR.
SyntheticObligation
dataclass
SyntheticObligation(qid: str, target_qid: str, content: str, diagnostic_kind: str = 'other', anchor: dict[str, Any] = dict(), created_at: str | None = None)
Synthetic obligation tracked outside compiled IR.
SyntheticRejection
dataclass
SyntheticRejection(qid: str, target_strategy: str, content: str, created_at: str | None = None)
Synthetic record for a rejected strategy branch.
find_anchors
find_anchors(pkg_path: str | Path) -> dict[str, SourceAnchor]
Scan package Python files and return a label-to-anchor map.
重复 label 取首次出现; 排除 .gaia/ 与隐藏目录。
Source code in gaia/engine/inquiry/anchor.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
analyze_knowledge_breakdown
analyze_knowledge_breakdown(ir: dict[str, Any]) -> KnowledgeBreakdown
Walk the IR once and classify every knowledge node by structural role.
Source code in gaia/engine/inquiry/check_core.py
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 | |
find_possible_duplicate_claims
find_possible_duplicate_claims(ir: dict[str, Any]) -> list[tuple[str, str]]
Heuristic: pairs of claims with identical normalized content.
Conservative — only exact-match after whitespace collapse. Per spec §8
possible_duplicate_claims is a graph-health hint, not an error.
Source code in gaia/engine/inquiry/check_core.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
format_diagnostics_as_next_edits
format_diagnostics_as_next_edits(diags: list[Diagnostic]) -> list[str]
Format diagnostics as the spec §8 text Next edits list.
若 diagnostic 带 source_anchor, 追加 (file:line) 到末尾,
便于人眼直接定位源行。
Source code in gaia/engine/inquiry/diagnostics.py
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 | |
format_diagnostics_as_structured_edits
format_diagnostics_as_structured_edits(diags: list[Diagnostic]) -> list[NextEdit]
Format diagnostics as Round A2 structured NextEdit records.
Source code in gaia/engine/inquiry/diagnostics.py
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 | |
from_knowledge_breakdown
from_knowledge_breakdown(kb: KnowledgeBreakdown, ir: dict[str, Any], focus: FocusBinding | None, anchors: dict[str, SourceAnchor] | None = None) -> list[Diagnostic]
Emit diagnostics for prior holes, orphans, background-only, duplicates.
Source code in gaia/engine/inquiry/diagnostics.py
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 | |
from_validation
from_validation(warnings: list[str], errors: list[str]) -> list[Diagnostic]
Lift strings from ValidationResult into Diagnostic records.
Source code in gaia/engine/inquiry/diagnostics.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
empty_diff
empty_diff() -> SemanticDiff
Return an empty semantic diff for report defaults.
Source code in gaia/engine/inquiry/diff.py
130 131 132 | |
resolve_focus_target
resolve_focus_target(target: str | None, graph: Any) -> FocusBinding
Resolve a raw focus selector against graph IDs and labels.
Source code in gaia/engine/inquiry/focus.py
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 | |
build_proof_context
build_proof_context(graph: Any, state: InquiryState) -> ProofContext
Build the merged IR and synthetic proof context for a package.
Source code in gaia/engine/inquiry/proof_state.py
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 | |
render_json
render_json(report: ReviewReport) -> str
Render a review report as pretty JSON without ASCII escaping.
Source code in gaia/engine/inquiry/render.py
534 535 536 | |
render_markdown
render_markdown(report: ReviewReport) -> str
Spec §17.2 Markdown renderer.
Mirrors the eight-section text layout but uses Markdown headings, bullet lists, and fenced code blocks for IDs/source anchors. The section names match render_text exactly so agents can diff outputs.
Source code in gaia/engine/inquiry/render.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
to_json_dict
to_json_dict(report: ReviewReport) -> dict[str, Any]
Serialize a review report to the spec §9.1 JSON dictionary shape.
Source code in gaia/engine/inquiry/render.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
render_text
render_text(report: ReviewReport) -> str
Spec §8 eight-section text renderer.
Source code in gaia/engine/inquiry/review.py
138 139 140 | |
resolve_graph
resolve_graph(path: str | Path) -> Any
Compile a package and return its LocalCanonicalGraph (or None on failure).
Source code in gaia/engine/inquiry/review.py
124 125 126 127 128 129 130 131 132 133 134 135 | |
run_review
run_review(path: str | Path, *, focus_override: str | None = None, mode: str = 'auto', no_infer: bool = False, depth: int = 0, since: str | None = None, strict: bool = False) -> ReviewReport
Run the inquiry review pipeline and persist a review snapshot.
Source code in gaia/engine/inquiry/review.py
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 | |
load_or_generate_review_manifest
load_or_generate_review_manifest(pkg_path: str | Path, compiled: Any) -> ReviewManifest
Load .gaia/review_manifest.json if present, else generate one from the compiled IR.
Source code in gaia/engine/inquiry/review_manifest.py
90 91 92 93 94 95 96 97 98 99 100 101 102 | |
append_tactic_event
append_tactic_event(pkg_path: str | Path, event: str, payload: dict[str, Any] | None = None) -> None
Append one tactic event to the inquiry audit log.
Source code in gaia/engine/inquiry/state.py
186 187 188 189 190 191 192 193 194 195 196 197 | |
inquiry_dir
inquiry_dir(pkg_path: str | Path) -> Path
Return the package inquiry directory, creating it if needed.
Source code in gaia/engine/inquiry/state.py
132 133 134 135 136 | |
load_state
load_state(pkg_path: str | Path) -> InquiryState
Load the persisted inquiry state, or return the default empty state.
Source code in gaia/engine/inquiry/state.py
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 | |
mint_qid
mint_qid(prefix: str) -> str
Mint a short synthetic inquiry identifier with the given prefix.
Source code in gaia/engine/inquiry/state.py
42 43 44 | |
pop_focus_frame
pop_focus_frame(state: InquiryState) -> dict[str, Any] | None
Pop the top frame and restore it. Returns old current frame for logging.
Source code in gaia/engine/inquiry/state.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
push_focus_frame
push_focus_frame(state: InquiryState) -> None
Push current focus onto focus_stack. Caller sets the new focus after.
Source code in gaia/engine/inquiry/state.py
214 215 216 217 218 219 220 221 | |
read_tactic_log
read_tactic_log(pkg_path: str | Path) -> list[dict[str, Any]]
Read the inquiry tactic log as JSON records.
Source code in gaia/engine/inquiry/state.py
200 201 202 203 204 205 206 207 208 209 210 211 | |
save_state
save_state(pkg_path: str | Path, state: InquiryState) -> None
Persist inquiry state to .gaia/inquiry/state.json.
Source code in gaia/engine/inquiry/state.py
179 180 181 182 183 | |