Trace API
Status: Generated from current Python docstrings and type hints.
ARM Trace schema, manifests, hash chain primitives, and review report
helpers used by the independent gaia trace CLI sub-app
(verify / review / show).
gaia.engine.trace
ARM Trace — 7th modality of ARM v1 (4/27).
提供: - Trace / TraceEvent / TraceManifest / ClaimRef pydantic schema - canonical-json + sha256 hash chain(事件级抗作弊) - 11 个确定性 detector(无 LLM 参与) - TraceReviewReport 八段 review(与 gaia.inquiry 设计同质) - run_trace_review(path, *, mode="trace") 端到端入口
目标:审计/debug/学习一段 ARM 执行轨迹时,给出可解释、可重算、不易作弊的报告。
TraceReviewReport
dataclass
TraceReviewReport(trace_review_id: str, created_at: str, path: str, mode: str, manifest_status: str, manifest_hash: str | None, counts: dict[str, int] = dict(), hash_chain: dict[str, Any] = dict(), causal_health: dict[str, Any] = dict(), reference_validity: list[dict[str, Any]] = list(), tampering: list[dict[str, Any]] = list(), execution_stats: dict[str, Any] = dict(), diagnostics: list[Diagnostic] = list(), next_edits: list[str] = list(), next_edits_structured: list[NextEdit] = list())
Represent the eight-section ARM trace review report.
section mapping(参 PLAN 与 gaia.inquiry.ReviewReport): §1 Header — trace_review_id / created_at / path / mode §2 Manifest — manifest_status / manifest_hash / counts §3 Hash Chain — hash_chain (ok / broken_at_seq / recomputed_root) §4 Causal Health — causal_health (tool_pairing / decision_grounds / parent_links / actor_continuity) §5 Reference Validity — reference_validity (claim_ref 解析摘要) §6 Tampering Signals — tampering (篡改信号集中视图) §7 Execution Stats — execution_stats (actors / kind 分布 / retry / time_span) §8 Diagnostics + NextEdits — diagnostics / next_edits / next_edits_structured
to_json_dict
to_json_dict() -> dict[str, Any]
Return the JSON-compatible report payload.
Source code in gaia/engine/trace/review.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
ClaimRef
Bases: BaseModel
Reference one Gaia knowledge claim from a trace event.
Trace
Bases: BaseModel
Represent a complete trace as a manifest plus ordered events.
TraceEvent
Bases: BaseModel
Represent the smallest accounting unit in an ARM trace.
- prev_hash:前一事件的 canonical-json sha256(首事件
"") - seq:单调递增整数,从 0 起,reviewer 校验连续
- ts:utc datetime;reviewer 校验单调非降
- parent_event_id:retry / sub-call 父子关系(None ⇒ root 事件)
TraceManifest
Bases: BaseModel
Describe trace metadata and hash anchors.
events_root / manifest_hash 在写入端计算后冻结,
reviewer 端独立重算比对——任何字段被改 ⇒ 哈希不一致。
signature 字段是 v2 hook,v1 不验签也不强求填。
run_trace_review
run_trace_review(path: str | Path, *, mode: str = 'trace', resolver: ReviewIdResolver | None = None, package_path: str | Path | None = None, retry_chain_limit: int = RETRY_CHAIN_LIMIT_DEFAULT, snapshot_dir: str | Path | None = None) -> TraceReviewReport
Load a trace, run detectors, build sections, and save a snapshot.
mode 与 ranking 的 mode 表对齐;默认 "trace"。
mode == "publish" 时 ranking 套 publish 表,warning 也会被前置。
snapshot_dir=None 走默认 <cwd>/.gaia/trace/reviews/。
Source code in gaia/engine/trace/review.py
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 | |