Skip to content

refactor(semantics): modularize inventory with zero-Any typed reports - #9469

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/slim-semantics-inventory-zero-any-20261126
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/slim-semantics-inventory-zero-any-20261126

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

Modularizes loopx/semantics/inventory.py (618 -> 500 LOC, 49 -> 0 AST Any) into strict Zero-Any typed semantic inventory and reporting modules while preserving all exports, identity contracts, isolated development-probe packaging, and zero caller mypy regressions:

  • loopx/semantics/inventory_reports.py (398 LOC, 0 AST Any, 0 # type: ignore, 0 # noqa, max 33 statements / 17 decision points):
    • Defines typed carrier and report TypedDicts (FactEntry, CarrierEntry, CarrierDefinition, MultiValueDuplicateEntry, StringConstantEntry, StringDefinition, StringDuplicateEntry, MergeCandidateGroup, DivergentValueSetEntry, ConsumerRankingEntry) alongside SourceFile.
    • Extracts render_inventory, registered_owner_symbol_sets, merge_candidate_groups, divergent_value_sets, _word_token_mentions, and consumer_ranking cleanly with top-level json import and safe container checks.
  • loopx/semantics/inventory.py (500 LOC <= 600, 0 AST Any, 0 # type: ignore, 0 # noqa, max 40 statements / 24 decision points):
    • Retains load_sources, parse_python, python_facts, typescript_facts, multi_value_carriers, multi_value_name_collisions, build_inventory, string_constant_definitions, collect_string_constants, and all inventory regexes/constants in place without creating extra semantic carriers.
    • Preserves exact object-identity re-exports for SourceFile, render_inventory, registered_owner_symbol_sets, merge_candidate_groups, divergent_value_sets, _word_token_mentions, and consumer_ranking.
  • Caller alignment & isolated probe packaging (0 new Any, +0 caller mypy errors):
    • loopx/semantics/development_probe.py (+4/-1 lines): narrows inventory.get(section) list check in _carriers (0 errors under mypy --strict).
    • scripts/generate_semantic_inventory.py (+2/-2 lines): uses distinct entry loop variable in divergent_value_sets loop so ConsumerRankingEntry and DivergentValueSetEntry do not collide statically.
    • tests/architecture/test_semantic_development_probe.py: appends loopx/semantics/inventory_reports.py to PROBE_CLI_FILES so isolated probe copies remain self-contained.
  • tests/architecture/test_semantic_inventory_contract.py (196 LOC, 0 AST Any, 0 # type: ignore, 0 # noqa):
    • Verifies LOC budgets, 0 AST Any / # type: ignore / # noqa, AST statement/decision bounds, re-export identity parity, tracked symlink rejection, boundary Python/TS AST extractions, invalid syntax errors, malformed registry/container handling, non-word token regex ranking fallback, and render_inventory round-tripping.

Verification

  • Static & boundary checks (af38c5b37c):
    • ruff check (6/6 changed/added files): passed
    • mypy --strict --no-incremental --follow-imports=silent (inventory.py, inventory_reports.py, development_probe.py, test_semantic_inventory_contract.py): 0 errors
    • mypy --no-incremental ([tool.mypy], 17 files): 0 errors
    • 6-file caller mypy --no-incremental --follow-imports=silent: 15 == 15 baseline (+0 regressions)
    • npm run typecheck:control-plane: passed
    • scripts/check_rfc_bilingual.py --base origin/main --head HEAD & git merge-tree --write-tree origin/main HEAD: clean
  • Parity, smokes & test runs (af38c5b37c):
    • Paired 57c4c43b52 vs af38c5b37c repository-wide JSON parity (render_inventory(build_inventory(...)), merge_candidate_groups raw/registry, divergent_value_sets, consumer_ranking, collect_string_constants, string_constant_definitions): byte-identical (1,237,581 bytes)
    • examples/semantic-vocabulary-drift-smoke.py, scripts/semantic_incident_retrodiction.py (12/15 caught, 0/5 false positives), examples/control_plane/control-plane-maintainability-ratchet-smoke.py (unreviewed=0, magnitude_regressions=0), scripts/generate_semantic_inventory.py --report, scripts/generate_semantic_bindings.py --check: passed
    • node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/content_digest_single_owner.test.ts: 17/17 passed
    • pytest -n 6 -rs (tests/architecture/, tests/canary/, tests/test_cli_entrypoint.py): 2,369 passed, 6 skipped (6 APFS filename skips in tests/canary/test_git_path_display.py, 0 failed)
    • loopx canary premerge --from-git-diff --git-diff-base origin/main (standard): ok=true, merge_gate_passed=true, direct_checks=4/4, python_compile=1/1, catalog_run=2/2, manual_hold_count=0

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

[P3] 报告应标明 registry owner 过滤不可用。隔离 CLI 中,vocabularies 为字符串时,基线 --report 退出 1。此处使新版本退出 0 并显示 “0 explained”,与合法空 registry 相同。差异限于 advisory report。同一输入的 --changed-from 在两版仍拒绝。 让 --report 共用现有 registry 校验入口,或在 owner 过滤不可用时输出明确诊断。 源码

动机 / Motivation

抽出语义清单报告和记录类型,保留 tracked source 扫描、碰撞分类及开发者 CLI。 原 inventory.py 同时负责 source 读取、carrier、报告排序和渲染。开发期 probe 与全树报告共用同一事实。 用 semantic inventory 查找 Python 和 TypeScript vocabulary 定义、fork 与未登记候选的开发者和 drift 检查。

把相同值集合当作同一 domain 或错认已登记 owner,会在后续评审掩盖独立定义和范围。 正常全树 CLI advisory report 逐字节相同。JSON 清单唯一变化是 source_files 从 1,942 到 1,943。独立三文件 Git 夹具中,两版均区分反序 list 与 set membership、过滤已登记跨运行时 owner、保留其他未登记组合。 基线 87、Head 91 项定向测试通过,包含隔离的 development-probe CLI。另核对全树 CLI、三文件 Git 夹具和隔离错误输入。两版 drift smoke 均通过,覆盖 34 个 vocabulary 与 62 个 owner。git diff --check 通过。 范围为 scanner 已支持的词法与结构。未核验当前安装和远程 CI。 基线契约

改动思路 / Approach

该改动沿用 scripts/generate_semantic_inventory.py → tracked SourceFile → inventory and advisory reports / development probe。扫描和 carrier 提取留在原模块,报告使用同一记录及 registry。通过重导出保留调用入口,报告继续是只读。 候选来源绑定 Git 路径。仍按 list 顺序与 set membership 区分冲突。报告复用原名称、值及已登记 owner。 沿现有 tracked load_sources 和 AST/TS 扫描分开渲染端。共用 registry owner 集合处理候选,无需新格式或配置。

具体改动 / Changes

精确提交 af38c5b,分叉基线 57c4c43。6 个文件,新增 757 行、删除 277 行。报告模块 398 行,新增 196 行契约测试,开发 probe 的隔离环境补齐依赖。

关键代码讲解

  • load_sources。从 Git index 读 tracked 路径,保留 symlink 拒绝。 源码

  • build_inventory。沿用 carrier 分类和排序,保持有序及无序碰撞规则。 源码

  • merge_candidate_groups。生成值相等的 advisory groups,用原已登记 owner 过滤。 源码

  • _carriers。隔离 diff CLI 继续复用 scanner。 源码

  • preserve-tracked-scan-and-advisory-collision-semantics(implemented)。全树 inventory 使用 Git 跟踪来源,维持碰撞判断,报告保持只读辅助。

对主干的风险 / Risks

两版均拒绝 tracked 符号链接、tracked 语法错误,并默认忽略未跟踪文件。changed-from 继续拒绝无效 registry 和缺失基线。普通 advisory report 对异常容器的变化见 P3。 坏容器可生成看似正常的 advisory,真正的 diff guard 仍拒绝同一输入。 延续严格源校验,在无法过滤 registry owner 时明确诊断。

我的整体评价 / Verdict

APPROVE。 有效输入的 CLI 与固定 Git 夹具一致。已记录异常时的 advisory fallback,严格 changed-from 保持拒绝。 真实来源与原 registry 对照让审阅者区分登记声明和仅同值的待审组合。

English verdict: APPROVE at af38c5b. Exact-base/head tracked inventory and valid reports preserve scanner semantics. The malformed-registry report fallback is nonblocking and changed-from still rejects it.

sets: set[frozenset[str]] = set()
vocabularies = registry["vocabularies"]
if not isinstance(vocabularies, Mapping):
return sets

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[P3] 报告应标明 registry owner 过滤不可用

隔离 CLI 中,vocabularies 为字符串时,基线 --report 退出 1。此处使新版本退出 0 并显示 “0 explained”,与合法空 registry 相同。差异限于 advisory report。同一输入的 --changed-from 在两版仍拒绝。 让 --report 共用现有 registry 校验入口,或在 owner 过滤不可用时输出明确诊断。

This branch has not been deployed

No deployments
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