Skip to content

feat(hospital): T2 (4/n) — dot-source 映射表 + 评分 port (#47) - #76

Merged
2233admin merged 3 commits into
mainfrom
claudeMaster/t2-parity-map
Jul 30, 2026
Merged

feat(hospital): T2 (4/n) — dot-source 映射表 + 评分 port (#47)#76
2233admin merged 3 commits into
mainfrom
claudeMaster/t2-parity-map

Conversation

@2233admin

Copy link
Copy Markdown
Owner

T2 步骤 4:dot-source 映射表 + hospital 评分 port

分类文档里我明确标为「不能当删除依据」的那条假设,验证完了 —— 它对约一半的面是错的

结论:分裂得很干净

dot-source 组 函数数 Rust 对应 判定
code-evidence 符号提取 9 native_code_evidence.rs 真重复,可退役
sentrux 门禁 metric delta 3 sentrux_gate.rs 真重复,可退役
hospital 状态机 / 诊断 ~5 hospital_diagnosis.rs 真重复,可退役
hospital 评分 / 测量 ~7 无 —— Rust 输出 null 缺口

重复的那部分证据native_code_evidence.rs 覆盖 PS1 那 6 种语言之外还多 7 种扩展名,是活的 evidence.native-code 节点(本仓自扫产出 2993 个符号),而且已经带一条针对旧生产者的 parity 测试。sentrux_gate.rs 每次 CI 都在跑 —— 这个战役里已经抓到我两次 god-file 回归,生产使用比单测更硬。

不重复的那部分,同仓同 commit 实测:

字段 PowerShell Rust
triage.overall_score 46 null
report_quality.overall_score 46 null
diagnostic_score 50 null
governance_score 33 null
dimensions 有内容 []

hospital_diagnosis.rs:410,425 是硬编码的 null,不是 TODO 也不是失败路径。PS1 那 16 个 hospital 用例里有 9 个专钉这套评分 —— 删掉不是去重,是删掉唯一一处该行为的覆盖。

所以先 port 评分

hospital_score.rs:step 分数、分档的 import resolution、source coverage、pollution 分类与分数、rules 分数、governance/diagnostic/overall 组合。

值得单独点名的 parity 陷阱:.NET 的 [math]::Round银行家舍入(半数取偶),launcher 用的是默认行为。Rust 的 f64::round 是半数远离零。五个中点用例里三个不一致,而中点是可达的 —— 这里全是整数的三项/四项平均。round_half_to_even 就是为此存在,有测试钉死。

不是拿我自己的理解验的 —— 把 PS1 原函数从 run-code-intel.ps1 里 dot-source 出来实际执行,逐值对拍:

import    100,100,75,75,50,50,30,30 | null=0
coverage  100,100,50,0,0
step      100,0,0,0 | null=0
rounding  2,4,-2,0,2
worked    governance=100 diagnostic=0 overall=70
ratio     33.3 / 66.7

全部吻合。

刻意不接线,allow(dead_code) 里写明原因

launcher 的评分输入约有一半在 Rust 侧没有生产者:DSM scope(pollution)、CodeNexus context(MRI)、runtime CI health(PET)—— 那些是 T5 的面。

拿流水线不产出的输入去喂这套算术,会发布自信地算错的分数,比它要替换的 null 更糟。这个体系里 0 的含义是「观察到且缺失」,不是「从未尝试」—— 和 d029b3f 为结构化证据划的是同一条界。

另一个用 ? 标记而非断言的疑似缺口

Rust 阶梯止于 post_op,没有测试提到 discharge_ready,所以 PS1 的「discharge requires affirmative resolved post-op target evidence」可能也没对应。需要单独查证,我没下结论。

验证

cargo test 45 套 0 失败、cargo fmt --check 干净、sentrux gate No degradation(耦合还降了 45.79 → 45.65)。

Refs #47

T2 step 4 (#47) — the evidence the classification document said had to exist
before any PowerShell deletion. It overturns the working assumption for about
half the surface.

Duplicated, safe to retire: the nine code-evidence symbol extractors
(native_code_evidence.rs handles every extension they do plus more, runs as
the live evidence.native-code node, and already carries an explicit
legacy-parity test), the three sentrux gate metric helpers (sentrux_gate.rs is
exercised on every CI run and caught two god-file regressions in this campaign
alone), and the hospital state-machine helpers.

Not duplicated: hospital scoring. The Rust hospital emits null for
triage.overall_score, report_quality.overall_score, diagnostic_score and
governance_score, and an empty dimensions array, where the PowerShell producer
computes 46 / 46 / 50 / 33 with a populated dimensions list on the same
repository at the same commit. hospital_diagnosis.rs:410,425 hardcodes those
nulls — not a TODO, not a failure path. Nine of the sixteen PowerShell hospital
test cases exist to pin that scoring behaviour, so deleting them would remove
the only coverage of logic that lives in exactly one place.

A second, smaller candidate gap is flagged with `?` rather than asserted: the
Rust ladder ends at post_op and no test names discharge_ready, so "discharge
requires affirmative resolved post-op target evidence" may also lack a
counterpart. It needs its own check.

Whether hospital scoring survives is a product decision the code cannot
answer, so it is recorded rather than guessed: porting it is real work, and
dropping it means the null fields are the intended contract and
docs/hospital-mode.md has to stop listing overall_score and dimensions as
reader surface.

Refs #47
T2 step 4 outcome (#47). The parity map found that hospital scoring was never
duplicated — the Rust hospital hardcodes `null` for every score while the
PowerShell launcher computes real values, so the logic lives in exactly one
place and that place is the file T2 is retiring. Porting it is a prerequisite
for deleting the launcher, not a nice-to-have.

`hospital_score.rs` carries the arithmetic: step scores, the banded import
resolution score, source coverage, pollution classification and score, rules
score, and the governance/diagnostic/overall composition.

The parity trap worth naming: `[math]::Round` in .NET is banker's rounding,
half to even, and the launcher relies on the default. Rust's `f64::round`
rounds half away from zero. Three of five midpoint cases disagree, and
midpoints are reachable — these are three- and four-term averages of integers.
`round_half_to_even` exists for that reason and is pinned by test.

Verified against the original rather than against my own reading of it: the
PowerShell functions were dot-sourced out of run-code-intel.ps1 and executed,
and every ported value matches.

  import    100,100,75,75,50,50,30,30 | null=0
  coverage  100,100,50,0,0
  step      100,0,0,0 | null=0
  rounding  2,4,-2,0,2
  worked    governance=100 diagnostic=0 overall=70
  ratio     33.3 / 66.7

Deliberately not wired yet, and `allow(dead_code)` says so with the reason.
Roughly half the launcher's score inputs — DSM scope for pollution, CodeNexus
context for MRI, runtime CI health for PET — have no Rust producer; they are
T5's surface. Feeding the arithmetic inputs the pipeline does not produce
would publish confidently wrong scores, which is worse than the nulls it
replaces. `0` in this scheme means observed-and-absent, not never-attempted —
the same distinction d029b3f drew for structural evidence.

cargo test 45 suites 0 failed; cargo fmt --check clean; sentrux gate no
degradation (coupling improved 45.79 -> 45.65).

Refs #47
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@2233admin, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 40 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ff3715bd-5574-4bd2-91f7-7769499ffb14

📥 Commits

Reviewing files that changed from the base of the PR and between b93981b and c473669.

📒 Files selected for processing (1)
  • docs/ps1-exit/t2-dot-source-parity-map.md
📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added hospital report scoring with resolution, coverage, pollution, rules, and step-based assessments.
    • Added composite governance, diagnostic, and overall scores with consistent rounding.
    • Added handling for unknown and unavailable measurement states.
  • Documentation

    • Documented parity between legacy and current hospital scoring behavior, including identified gaps and remaining validation cases.

Walkthrough

Adds a pure Rust hospital scoring module with banker’s rounding, component and composite scores, comprehensive tests, CLI module wiring, and documentation comparing the implementation with the PowerShell parity contract.

Changes

Hospital scoring

Layer / File(s) Summary
Scoring arithmetic and composites
crates/code-intel-cli/src/hospital_score.rs
Implements rounded component scores for steps, imports, coverage, pollution, and rules, plus governance, diagnostic, and overall composite scores.
Module wiring and validation
crates/code-intel-cli/src/main.rs, crates/code-intel-cli/src/hospital_score.rs
Registers the new module and tests score boundaries, unknown measurements, pollution states, rounding behavior, and composite results.
Parity map documentation
docs/ps1-exit/t2-dot-source-parity-map.md
Documents existing PowerShell/Rust parity, the hospital scoring gap, related test coverage, and the possible porting or removal outcomes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Poem

A bunny found scores in a neat little row,
With half-even hops where the decimals go.
Imports and rules now balance just right,
Composite hearts glow with arithmetic light.
“Parity!” thumps softly the rabbit tonight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly mentions the dot-source mapping and hospital scoring port, which matches the main change set.
Description check ✅ Passed The description accurately describes the hospital scoring port, parity mapping, rounding behavior, and validation, so it matches the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/code-intel-cli/src/hospital_score.rs (1)

137-150: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace the nine positional score arguments with a typed input struct.

All arguments are i64, so swapped score dimensions compile silently; Clippy also flags this signature. Use named fields (for example, ScoreInputs) to make composition call sites self-describing.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/code-intel-cli/src/hospital_score.rs` around lines 137 - 150, Replace
the positional parameters of compose with a typed input struct such as
ScoreInputs containing named i64 fields for all nine score dimensions. Update
compose to read those fields when calculating governance, diagnostic, and
overall scores, and update every call site to construct the struct with explicit
field names.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/ps1-exit/t2-dot-source-parity-map.md`:
- Around line 17-22: Update the parity map’s hospital scoring / measurements row
to reference the Rust hospital scoring module and mark the arithmetic as
implemented, with the remaining gap limited to launcher wiring and unavailable
input producers. Revise the test-coverage claims and open-product-question
section to reflect the Rust scoring and parity tests. Retain `null` only as the
current behavior when the launcher is unwired, not as evidence that Rust lacks
scoring.

---

Nitpick comments:
In `@crates/code-intel-cli/src/hospital_score.rs`:
- Around line 137-150: Replace the positional parameters of compose with a typed
input struct such as ScoreInputs containing named i64 fields for all nine score
dimensions. Update compose to read those fields when calculating governance,
diagnostic, and overall scores, and update every call site to construct the
struct with explicit field names.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 75e6a638-7143-4c04-9e12-fbe398988c00

📥 Commits

Reviewing files that changed from the base of the PR and between 5065482 and b93981b.

📒 Files selected for processing (3)
  • crates/code-intel-cli/src/hospital_score.rs
  • crates/code-intel-cli/src/main.rs
  • docs/ps1-exit/t2-dot-source-parity-map.md

Comment thread docs/ps1-exit/t2-dot-source-parity-map.md Outdated
…hips with

CodeRabbit review on #76. The document was written before hospital_score.rs
existed and then shipped alongside it, so within one PR the map claimed Rust
has "none" for hospital scoring while the branch added exactly that. Left
as-is it would drive a duplicate re-port or a wrong deletion decision later.

The map now separates translation from integration: the arithmetic is ported
and verified value-for-value against the dot-sourced PowerShell originals,
while the launcher is unwired and several inputs still have no Rust producer.
The pre-port null measurement is kept, relabelled as the evidence that made
this a finding rather than as current-state.

Adds §3.2, the input availability table behind the wiring block — governance,
graph, source coverage and import resolution have Rust producers; pollution
(DSM scope), MRI (CodeNexus context), PET (runtime CI) and memory (repowise)
do not, and DSM belongs to T5 (#50).

§4 stops posing the product question as open: it was escalated and settled —
scoring survives and ports, so the null fields are not the intended contract.
Records the consequence honestly: run-code-intel.ps1 cannot reach <=50 lines
until the wiring lands, while the twelve genuinely duplicated functions are
unblocked and can retire first.

Refs #47
@2233admin
2233admin merged commit 26ddbc1 into main Jul 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant