[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-112520":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":13,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":13,"stars7d":15,"stars30d":16,"stars90d":13,"forks30d":13,"starsTrendScore":15,"compositeScore":17,"rankGlobal":10,"rankLanguage":10,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":10,"pushedAt":38,"updatedAt":39,"readmeContent":40,"aiSummary":41,"trendingCount":13,"starSnapshotCount":13,"syncStatus":42,"lastSyncTime":43,"discoverSource":44},112520,"hygieia","chiang21fcb\u002Fhygieia","chiang21fcb","Inspect, evaluate, and stress-test an existing semantic layer. Runs fully offline.","",null,"Python",107,0,60,1,47,45.2,"MIT License",false,"main",true,[23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"agent-skills","cli","coding-agent","data-contracts","data-quality","dbt","evaluation","llm-agents","metrics","offline","proof-of-concept","python","semantic-layer","sqlglot","static-analysis","2026-11-08 10:46:29","2026-11-21 09:05:14","\u003Cdiv align=\"center\">\n\n**English** · [简体中文](docs\u002Freadme\u002FREADME_zh.md)\n\n# Hygieia\n\n### Inspect, evaluate, and stress-test an existing semantic layer. Runs fully offline.\n\n**On Apache Ossie's public TPC-DS model, three everyday words — `price`, `location`, `profit` — each point at two different definitions. Hygieia reports all three before a single query runs.**\n\n[Install & quick start](#install--quick-start) · [Public-layer evidence](#public-layer-evidence) · [Demo numbers](#demo-numbers-simulated) · [How it works](#how-it-works) · [Known limitations](#known-limitations) · [Documentation](#documentation) · [CI](docs\u002Fintegrate-ci.md) · [Agent](docs\u002Fintegrate-agent.md)\n\n\u003Ccode>pip install \"hygieia-sl @ git+https:\u002F\u002Fgithub.com\u002Fchiang21fcb\u002Fhygieia.git\" && hygieia audit fixtures\u002Fecom\u003C\u002Fcode>\n\n\u003C\u002Fdiv>\n\nHygieia is a Python command-line tool that runs locally and inspects an existing semantic layer: static diagnosis (`audit`), two-arm evaluation (`eval`), rot simulation (`rot`), and a Markdown health report (`report`). It does not build an ontology. It checks the one you already have and reports where the definitions no longer match the data.\n\n- Python 3.10+, runtime dependencies `pyyaml` + `sqlglot` (AST-level SQL parsing); no network, no accounts, no API keys\n- Ships as a coding-agent skill\n\n## Install & quick start\n\nInstall the distribution (the import package is `hygieia`; the console script is `hygieia`):\n\n```bash\npip install \"hygieia-sl @ git+https:\u002F\u002Fgithub.com\u002Fchiang21fcb\u002Fhygieia.git\"\n# or from a checkout:\npip install -e .\n\nhygieia audit  fixtures\u002Fecom   # static diagnosis\nhygieia eval   fixtures\u002Fecom   # two-arm evaluation\nhygieia rot    fixtures\u002Fecom   # rot simulation\nhygieia report fixtures\u002Fecom   # full health report\n```\n\nOne-shot run without installing (uv):\n\n```bash\nuvx --from git+https:\u002F\u002Fgithub.com\u002Fchiang21fcb\u002Fhygieia.git hygieia audit fixtures\u002Fecom\n```\n\n`python scripts\u002Fhygieia.py ...` still works as a thin compatibility wrapper around\nthe same package, but new docs use `hygieia`. After `report`, open\n`fixtures\u002Fecom\u002Freports\u002Fhealth-report.md` for the complete result. `eval` prints:\n\n```\n$ hygieia eval fixtures\u002Fecom\nArm                              Correct  Silent  Accuracy  Silent rate\ncontrol (no semantic layer)      13\u002F20    7\u002F20    65.0%     35.0%\ntreatment (with semantic layer)  20\u002F20    0\u002F20    100.0%    0.0%\n```\n\n(The CLI prints English by default. `--lang zh` switches to the Chinese variant, which is written separately, not translated. The fixture mirrors a Chinese data-warehouse scenario; the protocol is language-neutral.)\n\nThen run the self-tests to confirm the contract numbers still hold:\n\n```bash\npython -m unittest discover -s tests -v\n```\n\nUseful flags: `--results \u003Cjson-or-run-dir>` to evaluate a different answer file or a `runs\u002F\u003Cid>` directory (see [docs\u002Feval-live.md](docs\u002Feval-live.md)), `--json` for machine-readable output, `--fail-on high|medium|low|none` to gate CI on severity, `--sarif \u003Cpath|->` to emit SARIF 2.1.0 for code scanning, `--lang zh|en` for the output language (default `en`), `--write` to let `rot` persist the drifted semantic layer as `metrics.rot.yml`.\n\n## Public-layer evidence\n\nBefore claiming anything about a private warehouse, Hygieia is run on a public neutral\nlayer: [Apache Ossie](https:\u002F\u002Fgithub.com\u002Fapache\u002Fossie)'s TPC-DS semantic model. The\nfixture is a trimmed copy of `examples\u002Ftpcds_semantic_model.yaml` with the upstream\nApache-2.0 header kept; nothing in it is doctored, and no `schema.sql` is needed:\n\n```bash\nhygieia adapt ossie --in fixtures\u002Fossie_tpcds\u002Fossie_semantic_model.yaml --out .tmp\u002Fossie\nhygieia audit .tmp\u002Fossie\n# 🔴 High R1-synonym-conflict [location]: synonym \"location\" maps to multiple metrics\u002Ffields: ss_store_sk, s_city\n# 🔴 High R1-synonym-conflict [price]:    synonym \"price\" maps to multiple metrics\u002Ffields: ss_sales_price, i_current_price\n# 🔴 High R1-synonym-conflict [profit]:   synonym \"profit\" maps to multiple metrics\u002Ffields: total_profit, ss_net_profit\n```\n\nThree real vocabulary collisions in a reference model published by the standard's own\nauthors. `audit` also reports 4 × R5 (the model declares no evidence) and lists\n`R4-dangling-ref` plus the table\u002Fcolumn checks of R3 in `skipped_rules`, because the\nsample ships no DDL — reported, not hidden. Reproduction commands, dates, and limits:\n[docs\u002Fpublic-layers.md](docs\u002Fpublic-layers.md).\n\n## Demo numbers (simulated)\n\nThe numbers in this section are a **simulated demo**, not a live model run: the two\narms' answers are hand-written, and only the SQL scoring is executed for real. They\nshow the shape of the failure mode, not a benchmark of any particular model.\n\nA data agent gets its metrics, synonyms, joins, domains, and evidence from the semantic layer, so the definition lives in one place. When a definition drifts, the agent still returns a number that looks fine. The bundled `ecom` fixture reproduces this: 6 e-commerce tables, 20 Chinese questions, hand-written answers for both arms, and real SQL execution for scoring.\n\n| Metric | No semantic layer | With semantic layer |\n|---|---|---|\n| Accuracy | 13\u002F20 (65%) | 20\u002F20 (100%) |\n| **Silent-error rate** | **7\u002F20 (35%)** | **0\u002F20 (0%)** |\n\nA silent error is a wrong number with no error and no clarification, so the user cannot tell. This is the core metric of `eval`.\n\nEach answer is also scored on two dimensions: **entity** (tables \u002F join paths) and **relation** (metric caliber: aggregation + filters). On the demo, control scores entity 17\u002F20 and relation 13\u002F20, treatment 20\u002F20 on both: the failures are mostly caliber, not table-picking. `eval` writes a manifest (`reports\u002Fmanifest.json`) pinning model, prompt hash, question-set hash, corpus hash, semantic-layer hash, and tool version; `report` refuses to call two runs comparable when those differ, and flags a dimension that drops while the overall score rises:\n\n| Run lock | Value |\n|---|---|\n| prompt | `fixtures\u002Fecom\u002Fprompts\u002F{control,treatment}.md` sha256 |\n| questions \u002F corpus \u002F semantic layer | `questions.yaml`, `schema.sql`+`seed.sql`, `semantic\u002Fmetrics.yml` sha256 |\n| model | `simulated (hand-authored)` for the demo; `meta.json` model for live runs |\n\nRepresentative failures from the control arm:\n\n| # | Question | No semantic layer | Correct answer |\n|---|---|---|---|\n| q07 | Last month's net revenue | 1210 (canceled orders included) | 1110 |\n| q08 | Total revenue | 1860 (canceled orders included) | 1760 |\n| q09 | Active customers | 6 (counted the whole table) | 5 (ordered within 30 days) |\n| q10 | Revenue | 1860 (wrong caliber) | 1760 (net_revenue) |\n| q11 | Order conversion rate | Fabricated 0.25 | No visit data; should clarify |\n| q12 | Average order value | 155 (canceled orders included) | 176 |\n| q20 | Does net revenue include shipping? | Confident \"yes\" | Undefined; should clarify |\n\n`audit` finds 7 issues in the same semantic layer (3 high: R1 synonym conflict, R3 join ambiguity, R4 dangling reference; 4 medium: R5 missing evidence). `rot` injects five kinds of drift (column rename, definition tampering, new orphan metric, stale alias, conflicting source freshness) and re-runs audit: 6 new captures, split into structural 4 (two R4 from the column rename, plus R2 high and R5 medium from the new orphan metric) and semantic 2 (the stale alias, and the metric merging two sources with conflicting freshness). Definition tampering hits an R4 that already existed before the drift (`refund_total` referencing the missing `refunds` table), so by the set-difference rule it adds none.\n\nAbout this demo's data: the two arms' answers are hand-authored and marked `simulated: true` at the top of `demo_results.json`; they were not produced by a live model. The gold-standard SQL numbers come from real execution against the seed data in in-memory SQLite, and the scoring follows Section 13 of the contract. `net_revenue`'s expression `sum(orders.net_amount)` executes on the seed and matches the treatment answers. The R4 trap lives on a separate `refund_total` metric and is not on the evaluation's gold path.\n\n### Live run (2026-11-06)\n\nOne real two-arm run. The built-in coding agent (deepseek-v4-flash) answered as the model; scoring used the same `eval` protocol.\n\n| Arm | Correct | Silent | Accuracy | Silent rate |\n|---|---|---|---|---|\n| control (no semantic layer) | 16\u002F20 | 4\u002F20 | 80.0% | 20.0% |\n| treatment (with semantic layer) | 19\u002F20 | 1\u002F20 | 95.0% | 5.0% |\n\nThe semantic layer fixed three caliber errors on q08, q10, and q12: total revenue, revenue, and average order value now follow the non-cancelled scope. One shared error remained on q14, where both arms counted cancelled orders in per-customer spend; at run time the layer had no customer-dimension metric. A `customer_spend` metric (per customer, non-cancelled orders, `sum(orders.net_amount)`) was added afterwards and encodes the caliber q14 asks for, but the live answers above were **not re-run** under it (see the run's `notes.md`). Full methodology, meta, and per-question analysis: [fixtures\u002Fecom\u002Fruns\u002Flive-20261106-dsh](fixtures\u002Fecom\u002Fruns\u002Flive-20261106-dsh\u002F). The demo table above stays simulated; live runs follow [docs\u002Feval-live.md](docs\u002Feval-live.md).\n\n## How it works\n\n\u003Cpicture>\n  \u003Csource media=\"(prefers-color-scheme: dark)\" srcset=\"docs\u002Ffigures\u002Fpipeline-dark.svg\">\n  \u003Cimg src=\"docs\u002Ffigures\u002Fpipeline.svg\" width=\"880\" alt=\"Hygieia pipeline: inputs are the native semantic\u002Fmetrics.yml with optional schema.sql, plus the read-only adapt dbt and adapt ossie adapters that map external semantic models into metrics.yml; audit checks R1-R9, rot injects five drifts (3 structural + 2 semantic) and re-runs audit, eval scores two arms against executed gold SQL; report writes reports\u002Fhealth-report.md; two dashed consumption paths lead to a CI gate (audit --fail-on high + SARIF via a composite Action) and an agent gate that audits before answering.\">\n\u003C\u002Fpicture>\n\n### Commands\n\nFour main commands:\n\n| Command | What it does | Input | Output |\n|---|---|---|---|\n| `audit` | Static diagnosis across 9 rule classes (R1 synonym conflict \u002F R2 orphan metric \u002F R3 join ambiguity \u002F R4 dangling reference \u002F R5 missing evidence \u002F R6 missing description \u002F R7 redundancy \u002F R8 stale alias \u002F R9 source-freshness conflict) | `semantic\u002Fmetrics.yml` + `schema.sql` | Every finding with its rule, danger, and fix |\n| `eval` | Two-arm evaluation: the same questions answered with and without the semantic layer | `questions.yaml` + both arms' answers (default `demo_results.json`) | Accuracy and silent-error rate |\n| `rot` | Injects five kinds of drift (three structural, two semantic) into an in-memory copy and re-runs audit; reports new captures (never writes to disk by default) | Same as above | Before → after → new captures |\n| `report` | Full health report: high\u002Fmedium findings, rot simulation, evaluation | Same as above | `reports\u002Fhealth-report.md` |\n\nAdditional subcommands (v1 utilities):\n\n| Command | What it does | Docs |\n|---|---|---|\n| `adapt dbt` | Read-only adapter: maps dbt \u002F MetricFlow YAML (measure `expr`, metric\u002Fmeasure `filter`, newer agg-on-metric form) onto the `metrics.yml` contract | [docs\u002Fadapters.md](docs\u002Fadapters.md) |\n| `adapt ossie` | Read-only adapter for Apache Ossie\u002FOSI semantic models — the neutral first-class input; `schema.sql` is optional for the follow-up `audit` | [docs\u002Fadapters.md](docs\u002Fadapters.md) |\n| `impact` | Maps a git diff onto the affected metrics and suggests re-running `audit` | [docs\u002Fimpact.md](docs\u002Fimpact.md) |\n\n### Why this project exists\n\nMost existing tools answer how to build an ontology: bootstrapping one from metadata, docs, and guided forms, for example the ontology-skills bootstrap flow. Hygieia handles what comes after the build. A bootstrap output can be handed to it as a downstream quality gate, which answers two questions: is the ontology already broken, and would a data agent silently return wrong numbers on it? Diagnosis, evaluation, and rot detection are the whole scope, and the results are reproducible numbers.\n\n## Known limitations\n\n1. The two arms' demo answers are hand-authored (marked `simulated: true` in `demo_results.json`): the numbers come from real SQL execution, but the answers were not generated live by a model. For a real evaluation, run the protocol inside a coding agent and store artifacts under `fixtures\u002Fecom\u002Fruns\u002F\u003Ctimestamp>\u002F` (see [docs\u002Feval-live.md](docs\u002Feval-live.md));\n2. Reference extraction is AST-based (sqlglot, sqlite dialect) and covers column refs and join `on_expr`; multi-dialect parsing, dbt `ref()`\u002Fmacros, and CTE aliases are still not handled (an unparseable expression is surfaced as a high R4 finding, never silently ignored);\n3. 9 static rule classes are covered (R1–R9); deep caliber semantics, permissions, and action safety are out of scope;\n4. A single schema directory and a single dialect are supported (a SQLite-friendly subset is enough to run the fixture);\n5. No UI, no multi-tenancy, no action layer;\n6. v0's native layout is the `metrics.yml` contract. `adapt dbt` and `adapt ossie` are read-only downstream adapters (mapping: [docs\u002Fadapters.md](docs\u002Fadapters.md)); `schema.sql` is optional for `audit` (rules that need physical columns are listed in `skipped_rules`), while `eval`\u002F`rot` still need it. Write-back, bootstrap, `adapt cube`, OWL\u002FSHACL, and graph-database adapters are out of scope;\n7. The eval scoring keywords are coupled to the answer language: v0 ships a Chinese marker table and an English one (`unknown` \u002F `cannot compute` \u002F `insufficient data` \u002F `i don't know`, …), selected automatically by answer-language detection (any CJK character in the answers selects the Chinese table); the demo fixture itself stays Chinese (an English fixture is a v1+ item);\n8. `营收` is deliberately double-hung between `revenue` and `net_revenue`. The R1 red light in `audit` is the demo trap and stays on; removing the synonym would falsify the baseline. In the live run an agent still picked the right caliber from the preferred-caliber description, and `audit` still reports the conflict, which is the point of the check.\n\n### Known false positives and misses\n\n| Rule | Possible false positives | Known misses (v0) |\n|---|---|---|\n| R1 | Intentional alias layering (rare) | Cross-file synonyms, near-synonyms |\n| R3 | Legitimate alternative multi-paths | Implicit joins, sub-query paths |\n| R4 | Dialect functions mistaken for columns | CTE aliases, macros\u002Ftemplates |\n| R5 | Evidence stored outside the repo | Stale evidence still counts as present |\n| R6\u002FR7 | Short but precise descriptions | Long but empty boilerplate |\n| R8 | A migration alias (not reported when `replaced_by` points at the current metric) | An alias pointing at a metric deleted from the file |\n| R9 | Multi-source metrics that declare `authoritative: true` (not reported) | Freshness conflict that only exists in the data |\n\n## Roadmap\n\n```\nv0 (this demo)  diagnosis + evaluation + rot simulation                    ← prove the problem exists (current release)\nv1 (landed)     sqlglot AST refs + impact analysis + CI fail-on gate + adapt dbt  ← engineering assets\nv0.2 (landed)   Ossie first-class input, optional schema, SARIF + composite Action, integration docs ← hook it up in minutes\nv1+ (open)      multi-dialect parsing, dbt ref()\u002Fmacros, evolution loop     ← still to do\nv2              evolution loop: change → detect → suggest → approve → version  ← close the missing maintenance loop (2–3 months)\nv3              cross-platform semantic consistency + action-layer audit        ← the open slot (6–12 months)\n```\n\n- Landed (v1): AST-level reference extraction with sqlglot, which drives R4 and `impact`; `impact` maps a git diff to the affected metrics; the CI `--fail-on high` gate; the read-only `adapt dbt` adapter.\n- Landed (v0.2): Apache Ossie\u002FOSI as a first-class input (`adapt ossie`), `schema.sql` optional for `audit`, SARIF output and a composite GitHub Action, and consumer\u002Fagent integration examples.\n- Still v1+: multi-dialect parsing (sqlite today), dbt `ref()` and macro resolution, CTE aliases, and the change, detect, suggest, approve evolution loop.\n- v2: ontology versioning and evolution history; the change, detect, suggest, approve, merge loop; maintenance becomes CI events instead of a manual weekly report.\n\n## Documentation\n\n- [SKILL.md](SKILL.md): the skill's operating contract and trigger phrases\n- [docs\u002Fcontract.zh.md](docs\u002Fcontract.zh.md) and [docs\u002Fcontract.en.md](docs\u002Fcontract.en.md): the coding contract (Chinese authoritative, English mirror)\n- [docs\u002Feval-live.md](docs\u002Feval-live.md): the live two-arm evaluation protocol\n- [docs\u002Fadapters.md](docs\u002Fadapters.md): input assumptions and mapping for `adapt dbt` and `adapt ossie`\n- [docs\u002Fpublic-layers.md](docs\u002Fpublic-layers.md): public semantic layers Hygieia has been run on, with commands and findings\n- [docs\u002Fintegrate-ci.md](docs\u002Fintegrate-ci.md): CI integration (composite Action, SARIF, pre-commit)\n- [docs\u002Fintegrate-agent.md](docs\u002Fintegrate-agent.md): agent-pipeline integration (audit gate before answering)\n- [examples\u002Fconsumer-ci](examples\u002Fconsumer-ci\u002F): copy-paste CI workflow for a consumer repo\n- [examples\u002Fagent-pipeline](examples\u002Fagent-pipeline\u002F): audit-gated agent pipeline shell\n- [docs\u002Fimpact.md](docs\u002Fimpact.md): input and output for `impact`\n\n## Data statement\n\nThe `ecom` fixture is synthetic demo data with no external source.\n\n## License\n\nMIT License, see [LICENSE](LICENSE).\n\n","Hygieia 是一个离线运行的 Python 命令行工具，用于静态检查、评估和压力测试已有的语义层（如 dbt 模型、指标定义等）。它通过 SQLGlot 进行 AST 级 SQL 解析，支持语义一致性审计（audit）、双臂对照评估（eval）、数据退化模拟（rot）及生成 Markdown 健康报告（report），全程无需网络连接或外部服务。核心能力包括识别同名多义字段（如 price\u002Flocation\u002Fprofit 的歧义定义）、验证数据契约与实际数据的一致性，并输出可集成至 CI 的 SARIF 格式结果。适用于数据平台团队在部署前对语义层做质量门禁、合规审查或重构风险评估。",2,"2026-11-24 04:43:41","CREATED_QUERY"]