bugx-cli 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +190 -186
- package/core/README.md +2 -2
- package/core/agent/README.md +2 -1
- package/core/agent/agent_artifacts.py +8 -6
- package/core/agent/agent_eval.py +136 -54
- package/core/agent/agent_execution.py +218 -52
- package/core/agent/agent_orchestrator.py +14 -8
- package/core/agent/agent_targets.py +8 -2
- package/core/agent/feature_baseline.py +150 -0
- package/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
- package/core/assets/axe-core/LICENSE.txt +362 -0
- package/core/assets/axe-core/UPSTREAM.md +10 -0
- package/core/assets/axe-core/axe.min.js +12 -0
- package/core/assets/bugx-hero-en.svg +74 -0
- package/core/assets/bugx-hero-zh.svg +74 -0
- package/core/assets/codex.png +0 -0
- package/core/assets/dsh.png +0 -0
- package/core/assets/webui-chatgpt.jpg +0 -0
- package/core/assets/webui-session.jpg +0 -0
- package/core/assets/webui-skills.jpg +0 -0
- package/core/assets/webui-studio.jpg +0 -0
- package/core/assets/webui-zcode.jpg +0 -0
- package/core/assets/zcode.png +0 -0
- package/core/autonomous_cve/SPEC.md +1 -1
- package/core/autonomous_cve/attack_graph_store.py +152 -106
- package/core/autonomous_cve/behavior_graph.py +8 -2
- package/core/autonomous_cve/verifier.py +4 -1
- package/core/bugx.md +1 -1
- package/core/bugx_paths.py +43 -8
- package/core/cli-help.txt +66 -0
- package/core/cloud_sync/SPEC.md +1 -1
- package/core/cloud_sync/cloud_client.py +25 -6
- package/core/cloud_sync/cloud_onboard.py +42 -1
- package/core/cloud_sync/flywheel_client.py +16 -7
- package/core/cloud_sync/network_transport.py +24 -3
- package/core/cloud_sync/sensitive_filter.py +2 -2
- package/core/cloud_sync/sync_push.py +12 -10
- package/core/contracts/AGENT_GUIDE.md +6 -9
- package/core/contracts/README.md +2 -2
- package/core/contracts/bugx-runtime-contract.md +1 -1
- package/core/contracts/bugx-worker.md +1 -1
- package/core/contracts/engine_gap_contracts.py +86 -3
- package/core/coverage/coverage_discovery.py +599 -29
- package/core/coverage/coverage_evidence.py +47 -0
- package/core/coverage/coverage_forensics.py +9 -0
- package/core/coverage/coverage_validate.py +6 -1
- package/core/dev_harness/SPEC.md +1 -1
- package/core/engine-integrity.json +591 -419
- package/core/fuzzing/concurrency_fuzzer.py +53 -0
- package/core/fuzzing/differential_oracle.py +562 -27
- package/core/fuzzing/fuzz_input.py +109 -6
- package/core/fuzzing/stateful_fuzzer.py +72 -0
- package/core/governance/secret_redactor.py +22 -10
- package/core/host_acp/SPEC.md +1 -1
- package/core/host_acp/__init__.py +4 -4
- package/core/host_acp/claude.py +59 -1
- package/core/host_acp/cline.py +64 -1
- package/core/host_acp/codex.py +56 -1
- package/core/host_acp/dsh.py +59 -1
- package/core/host_acp/opencode.py +56 -1
- package/core/host_acp/pi.py +59 -1
- package/core/host_acp/zcode.py +59 -1
- package/core/host_runtime/SPEC.md +1 -1
- package/core/host_runtime/adapters.py +1 -1
- package/core/host_runtime/cline.py +13 -0
- package/core/host_runtime/host_evaluators.py +44 -4
- package/core/host_runtime/host_probe.py +1 -1
- package/core/host_runtime/host_provider_arbitrator.py +116 -62
- package/core/host_runtime/host_registry.py +15 -8
- package/core/host_runtime/mcp_registry_gate.py +12 -1
- package/core/host_runtime/pi.py +102 -0
- package/core/host_runtime/provider_facts.py +66 -0
- package/core/hosts/SPEC.md +1 -1
- package/core/hosts/__init__.py +6 -2
- package/core/hosts/_dsh_usage.py +1 -1
- package/core/hosts/base.py +32 -4
- package/core/hosts/claude.py +55 -0
- package/core/hosts/cline.py +6 -2
- package/core/hosts/codex.py +58 -0
- package/core/hosts/dsh.py +9 -1
- package/core/hosts/opencode.py +6 -6
- package/core/hosts/pi.py +159 -2
- package/core/infra/README.md +4 -2
- package/core/infra/__init__.py +2 -0
- package/core/infra/build_info.py +22 -3
- package/core/infra/client_metadata.py +1 -1
- package/core/infra/json_utils.py +22 -0
- package/core/launch_phases/README.md +2 -2
- package/core/launch_phases/SPEC.md +1 -1
- package/core/launch_phases/common.py +21 -2
- package/core/launch_phases/finding_confirm_phase.py +5 -1
- package/core/launch_phases/finding_settlement.py +188 -1
- package/core/launch_phases/judge_phase.py +69 -12
- package/core/launch_phases/orchestrator_controls.py +11 -7
- package/core/launch_phases/post_coverage_sync.py +9 -2
- package/core/launch_phases/post_phase.py +139 -3
- package/core/launch_phases/post_receipt.py +12 -1
- package/core/launch_phases/pre_phase.py +3 -3
- package/core/launch_phases/pre_recon_scout.py +53 -36
- package/core/launch_phases/pre_state_builder.py +23 -176
- package/core/launch_phases/round_orchestrator.py +15 -32
- package/core/launch_phases/session_runtime.py +56 -9
- package/core/launch_phases/startup_gates.py +36 -8
- package/core/launch_phases/startup_interaction.py +68 -12
- package/core/launch_phases/startup_version_gate.py +9 -3
- package/core/launch_phases/supervisor_bridge.py +46 -17
- package/core/launch_phases/supervisor_coverage.py +8 -2
- package/core/launch_phases/supervisor_degraded.py +1 -9
- package/core/launch_phases/worker_barriers.py +15 -5
- package/core/launch_phases/worker_orchestrator.py +105 -25
- package/core/ledger/README.md +1 -1
- package/core/ledger/SPEC.md +1 -1
- package/core/ledger/_facade.py +2 -1
- package/core/ledger/archive_ops.py +60 -2
- package/core/ledger/cli.py +6 -1
- package/core/ledger/export_ops.py +6 -1
- package/core/ledger/finding_confirmation.py +48 -6
- package/core/ledger/finding_lifecycle.py +428 -5
- package/core/ledger/finding_verification.py +44 -8
- package/core/ledger/incidents.py +10 -4
- package/core/ledger/patterns.py +10 -7
- package/core/ledger/receipt_contract.py +17 -1
- package/core/ledger/sync_ops.py +21 -16
- package/core/ledger/tool_experience.py +2 -1
- package/core/ledger/verify_life.py +88 -17
- package/core/locales/en-US.json +2 -2
- package/core/locales/zh-CN.json +2 -2
- package/core/mcp_handlers/SPEC.md +1 -1
- package/core/mcp_handlers/base.py +23 -3
- package/core/mcp_handlers/channel_lifecycle.py +85 -30
- package/core/mcp_handlers/retrieval_handlers.py +11 -1
- package/core/mcp_handlers/rpc_server.py +6 -1
- package/core/mcp_handlers/supervisor_handlers.py +32 -6
- package/core/mcp_handlers/tool_table.py +15 -0
- package/core/mcp_runtime_support/environment.py +0 -38
- package/core/mcp_runtime_support/verifier.py +0 -52
- package/core/metadata.txt +2 -3
- package/core/planning/README.md +1 -1
- package/core/planning/domain_router.py +4 -2
- package/core/planning/dynamic_flow_analyzer.py +219 -14
- package/core/planning/judge_pipeline.py +87 -4
- package/core/planning/prompt_harness.py +7 -5
- package/core/planning/spec_harvester.py +4 -4
- package/core/probes/INTERFACE.md +11 -1
- package/core/probes/SPEC.md +11 -1
- package/core/probes/__init__.py +46 -40
- package/core/probes/android_probe.py +177 -9
- package/core/probes/codebase_memory_probe.py +57 -0
- package/core/probes/desktop_probe.py +104 -0
- package/core/probes/differential_probe.py +99 -21
- package/core/probes/efficiency_probe.py +64 -0
- package/core/probes/ios_binary_probe.py +105 -1
- package/core/probes/memory_probe.py +66 -0
- package/core/probes/miniprogram_probe.py +75 -13
- package/core/probes/mobile_probe.py +215 -30
- package/core/probes/native_probe.py +88 -0
- package/core/probes/openwiki_probe.py +70 -0
- package/core/probes/pattern_probe.py +106 -0
- package/core/probes/platform_probe.py +81 -0
- package/core/probes/probe_registry.py +108 -7
- package/core/probes/sast_fixture_corpus.py +340 -0
- package/core/probes/sast_probe.py +553 -52
- package/core/probes/sast_rules.py +668 -28
- package/core/probes/sca_scanner.py +48 -0
- package/core/probes/ui_accessibility.py +149 -0
- package/core/probes/ui_audit.py +513 -0
- package/core/probes/ui_contract.py +273 -0
- package/core/probes/ui_evidence.py +212 -0
- package/core/probes/ui_measurements.py +314 -0
- package/core/probes/ui_repair.py +250 -0
- package/core/probes/ui_review.py +133 -0
- package/core/probes/ui_storybook.py +107 -0
- package/core/probes/ui_tokens.py +185 -0
- package/core/probes/ui_visual_diff.py +131 -0
- package/core/probes/web_probe.py +373 -18
- package/core/project_profiler/SPEC.md +1 -1
- package/core/project_profiler/arbitrator.py +6 -1
- package/core/project_profiler/detector.py +8 -1
- package/core/project_profiler/strategy.py +51 -15
- package/core/prompts/command_routing_en.md +2 -2
- package/core/prompts/command_routing_zh.md +2 -2
- package/core/prompts/stages/stage_repair.md +1 -1
- package/core/repair/README.md +1 -1
- package/core/repair/l7_repair_loop.py +1 -4
- package/core/repair/rsi_fixer.py +4 -4
- package/core/repair/rsi_loop.py +1 -3
- package/core/repair/rsi_repair.py +7 -7
- package/core/repair/rsi_scope.py +27 -8
- package/core/report_engine/SPEC.md +1 -1
- package/core/report_engine/attestation.py +8 -4
- package/core/report_engine/finding_report.py +2 -1
- package/core/report_engine/models.py +7 -9
- package/core/report_engine/sast_bridge.py +2 -2
- package/core/report_engine/server.py +18 -8
- package/core/report_engine/web-conformance.md +123 -18
- package/core/report_engine/web_conformance.py +21 -52
- package/core/retrieval/README.md +1 -1
- package/core/retrieval/SPEC.md +1 -1
- package/core/retrieval/code_analyzer.py +50 -14
- package/core/retrieval/context_assembler.py +7 -1
- package/core/retrieval/knowledge_sync.py +108 -14
- package/core/retrieval/symbol_index.py +25 -6
- package/core/retrieval/universal_code_matcher.py +234 -49
- package/core/runtime/README.md +1 -1
- package/core/runtime/bugx_logging.py +78 -7
- package/core/runtime/fixture_solidify.py +5 -10
- package/core/runtime/incident_eval.py +1 -1
- package/core/runtime/model_runner.py +4 -41
- package/core/runtime/platform_adapter.py +2 -2
- package/core/runtime/prep_validate.py +4 -2
- package/core/runtime/project_settings.py +2 -1
- package/core/runtime/scenario_eval.py +50 -8
- package/core/skills/bugx_docs_mcp_server.py +3 -1
- package/core/skills/bugx_mcp_server.py +29 -2
- package/core/skills/tools_kb.py +1 -1
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/SPEC.md +1 -1
- package/core/supervisor/budget_governor.py +503 -9
- package/core/supervisor/checkpoint_pipeline.py +248 -6
- package/core/supervisor/checkpoint_sync.py +13 -0
- package/core/supervisor/claim_events.py +1 -1
- package/core/supervisor/finding_workflow.py +22 -5
- package/core/supervisor/lease_manager.py +1 -1
- package/core/supervisor/lifecycle_blocks.py +6 -1
- package/core/supervisor/rejection_remedies.py +52 -5
- package/core/supervisor/serial_authorization.py +48 -4
- package/core/supervisor/task_scheduler.py +2 -2
- package/core/supervisor/worker_checkpoint.py +8 -1
- package/core/supervisor/worker_runtime.py +8 -2
- package/core/supervisor_types/worker_claim.py +9 -0
- package/core/webui/README.md +1 -1
- package/core/webui/SPEC.md +2 -1
- package/core/webui/adapters/claude.py +5 -1
- package/core/webui/adapters/cline.py +10 -2
- package/core/webui/adapters/codex.py +5 -1
- package/core/webui/adapters/dsh.py +5 -1
- package/core/webui/docs_session_service.py +2 -2
- package/core/webui/mcp_inspector.py +11 -7
- package/core/webui/static/00-base.css +1060 -0
- package/core/webui/static/01-monitoring.css +802 -0
- package/core/webui/static/02-header-actions.css +321 -0
- package/core/webui/static/03-trigger-popover.css +697 -0
- package/core/webui/static/04-composer.css +628 -0
- package/core/webui/static/05-skills-center.css +878 -0
- package/core/webui/static/06-mcp-center.css +623 -0
- package/core/webui/static/07-skill-detail.css +265 -0
- package/core/webui/static/08-files-management.css +167 -0
- package/core/webui/static/09-files-center.css +386 -0
- package/core/webui/static/10-icons.css +105 -0
- package/core/webui/static/11-project-options.css +185 -0
- package/core/webui/static/12-profile-tab.css +383 -0
- package/core/webui/static/design-tokens.css +113 -0
- package/core/webui/static/index.html +14 -1
- package/core/webui/workspace_service.py +1 -1
- package/docs/07_distribution/01_README_NPM.md +190 -186
- package/ecosystem/integrations/README.md +1 -1
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
- package/ecosystem/integrations/opencode/mcp-lock.json +14 -6
- package/ecosystem/integrations/opencode/opencode.json +23 -12
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/qoder/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
- package/interfaces/bin/bugx.js +37 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -2
- package/interfaces/cli/bugx_cli/cli.py +11 -4
- package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
- package/interfaces/cli/bugx_cli/commands/agent.py +339 -73
- package/interfaces/cli/bugx_cli/commands/audit.py +2 -2
- package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
- package/interfaces/cli/bugx_cli/commands/cloud.py +4 -3
- package/interfaces/cli/bugx_cli/commands/doctor.py +449 -204
- package/interfaces/cli/bugx_cli/commands/interaction.py +5 -1
- package/interfaces/cli/bugx_cli/commands/knowledge.py +2 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
- package/interfaces/cli/bugx_cli/commands/plugin.py +55 -20
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +7 -7
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +2 -1
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +1 -1
- package/interfaces/cli/bugx_cli/commands/report.py +2 -6
- package/interfaces/cli/bugx_cli/commands/system.py +11 -11
- package/interfaces/cli/bugx_cli/common.py +15 -7
- package/interfaces/cli/bugx_cli/host_adapters.py +29 -54
- package/interfaces/cli/bugx_cli/hosts/registry.py +8 -6
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +157 -27
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +18 -10
- package/interfaces/cli/bugx_cli/infra/host_sync.py +11 -8
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +76 -5
- package/interfaces/cli/bugx_cli/infra/security.py +13 -6
- package/package.json +2 -1
- package/pyproject.toml +20 -8
- package/scripts/ensure-python.mjs +7 -7
- package/scripts/sync-version.mjs +10 -21
- package/scripts/test-npm-wrapper.mjs +1 -1
- package/core/webui/static/project-settings.css +0 -6458
- package/docs/07_distribution/README.md +0 -16
- package/docs/README.md +0 -121
- package/interfaces/README.md +0 -143
- package/interfaces/bin/README.md +0 -35
- package/interfaces/cli/README.md +0 -90
- package/scripts/README.md +0 -118
|
@@ -248,9 +248,13 @@ def _analyze_python_ast(raw_bytes: bytes | str, sloc: int = 1) -> dict[str, Any]
|
|
|
248
248
|
try:
|
|
249
249
|
tree = ast.parse(raw_bytes)
|
|
250
250
|
except Exception:
|
|
251
|
+
# 解析失败必须可区分(F-RSI-20261115-276):解析器失效/新语法等场景下
|
|
252
|
+
# 返回满分 mi=100.0 会把系统性解析失败伪装成最优健康度。mi 不可信时
|
|
253
|
+
# 返回 None 并携带 parse_status="failed",由调用方与聚合层显式处理。
|
|
251
254
|
return {
|
|
252
255
|
"cc": 1, "cognitive": 0, "max_depth": 1, "functions": 0, "classes": 0,
|
|
253
|
-
"god_functions": 0, "taint_flows": [], "imports": [],
|
|
256
|
+
"god_functions": 0, "taint_flows": [], "imports": [],
|
|
257
|
+
"maintainability_index": None, "parse_status": "failed",
|
|
254
258
|
}
|
|
255
259
|
|
|
256
260
|
class Visitor(ast.NodeVisitor):
|
|
@@ -646,6 +650,7 @@ def _analyze_python_ast(raw_bytes: bytes | str, sloc: int = 1) -> dict[str, Any]
|
|
|
646
650
|
"imports": visitor.imports,
|
|
647
651
|
"halstead_volume": round(halstead_v, 2),
|
|
648
652
|
"maintainability_index": norm_mi,
|
|
653
|
+
"parse_status": "ok",
|
|
649
654
|
}
|
|
650
655
|
|
|
651
656
|
|
|
@@ -895,8 +900,9 @@ def analyze_file_risk(
|
|
|
895
900
|
return {
|
|
896
901
|
"cc": 1, "cognitive": 0, "max_depth": 1, "functions": 0, "classes": 0,
|
|
897
902
|
"god_functions": 0, "god_module": False, "sinks": 0,
|
|
898
|
-
"taint_flows": [], "critical_sinks": [], "mitigations": [], "secrets": [], "imports": [],
|
|
899
|
-
"
|
|
903
|
+
"taint_flows": [], "critical_sinks": [], "mitigations": [], "secrets": [], "imports": [],
|
|
904
|
+
"maintainability_index": None, "parse_status": "unreadable",
|
|
905
|
+
"risk_score": 0.0, "tags": ["unreadable"],
|
|
900
906
|
}
|
|
901
907
|
text = raw_bytes.decode("utf-8", errors="ignore")
|
|
902
908
|
|
|
@@ -913,7 +919,8 @@ def analyze_file_risk(
|
|
|
913
919
|
else:
|
|
914
920
|
struct = {
|
|
915
921
|
"cc": 1, "cognitive": 0, "max_depth": 1, "functions": 0, "classes": 0,
|
|
916
|
-
"god_functions": 0, "taint_flows": [], "critical_sinks": [], "mitigations": [], "imports": [],
|
|
922
|
+
"god_functions": 0, "taint_flows": [], "critical_sinks": [], "mitigations": [], "imports": [],
|
|
923
|
+
"maintainability_index": None, "parse_status": "not_applicable",
|
|
917
924
|
}
|
|
918
925
|
non_code_mask = set()
|
|
919
926
|
|
|
@@ -925,7 +932,8 @@ def analyze_file_risk(
|
|
|
925
932
|
cc = struct.get("cc", 1)
|
|
926
933
|
cognitive = struct.get("cognitive", 0)
|
|
927
934
|
max_depth = struct.get("max_depth", 1)
|
|
928
|
-
mi = struct.get("maintainability_index"
|
|
935
|
+
mi = struct.get("maintainability_index")
|
|
936
|
+
parse_status = struct.get("parse_status", "ok")
|
|
929
937
|
|
|
930
938
|
# God Module: only for production code
|
|
931
939
|
is_god_module = False
|
|
@@ -953,8 +961,12 @@ def analyze_file_risk(
|
|
|
953
961
|
tags.append("mitigated-control")
|
|
954
962
|
if len(secrets) > 0:
|
|
955
963
|
tags.append("hardcoded-secret")
|
|
956
|
-
if mi < 40.0:
|
|
964
|
+
if mi is not None and mi < 40.0:
|
|
957
965
|
tags.append("low-maintainability")
|
|
966
|
+
if parse_status == "failed":
|
|
967
|
+
# 解析失败必须出现在标签面(F-RSI-20261115-276):无结构的"满分"伪装
|
|
968
|
+
# 被移除后,文件级降级信号在 hotspots/tags 通道保持可见。
|
|
969
|
+
tags.append("parse-failed")
|
|
958
970
|
|
|
959
971
|
# Composite Risk score calculation (0 ~ 100) - 彻底废除复杂度即风险,确立高危一票置顶
|
|
960
972
|
if len(critical_sinks) > 0 or len(taints) > 0:
|
|
@@ -972,7 +984,7 @@ def analyze_file_risk(
|
|
|
972
984
|
+ (sinks * 3.0)
|
|
973
985
|
+ (len(secrets) * 6.0)
|
|
974
986
|
+ (max_depth * 1.5)
|
|
975
|
-
+ (10.0 if mi < 40.0 else 0.0),
|
|
987
|
+
+ (10.0 if (mi is not None and mi < 40.0) else 0.0),
|
|
976
988
|
)
|
|
977
989
|
|
|
978
990
|
risk_score = round(min(100.0, max(10.0, base_score)), 1)
|
|
@@ -992,6 +1004,7 @@ def analyze_file_risk(
|
|
|
992
1004
|
"secrets": secrets,
|
|
993
1005
|
"imports": struct.get("imports", []),
|
|
994
1006
|
"maintainability_index": mi,
|
|
1007
|
+
"parse_status": parse_status,
|
|
995
1008
|
"risk_score": risk_score,
|
|
996
1009
|
"tags": tags,
|
|
997
1010
|
}
|
|
@@ -1397,6 +1410,7 @@ def analyze_codebase(
|
|
|
1397
1410
|
all_critical_sinks: list[dict[str, Any]] = []
|
|
1398
1411
|
all_secrets: list[dict[str, Any]] = []
|
|
1399
1412
|
maintainability_scores: list[float] = []
|
|
1413
|
+
maintainability_parse_failed_files = 0
|
|
1400
1414
|
file_import_map: dict[str, list[str]] = {}
|
|
1401
1415
|
prod_files_list: list[tuple[str, Path, int, str]] = []
|
|
1402
1416
|
# Per-pass cache of decoded production source text. ``count_file_lines``,
|
|
@@ -1457,7 +1471,14 @@ def analyze_codebase(
|
|
|
1457
1471
|
if cog > max_cognitive:
|
|
1458
1472
|
max_cognitive = cog
|
|
1459
1473
|
|
|
1460
|
-
|
|
1474
|
+
file_mi = risk_info.get("maintainability_index")
|
|
1475
|
+
if file_mi is None:
|
|
1476
|
+
# 解析/读取失败的文件不进入均值(F-RSI-20261115-276):假满分
|
|
1477
|
+
# 会污染聚合,降级文件计数显式暴露给度量看板。
|
|
1478
|
+
if risk_info.get("parse_status", "ok") in {"failed", "unreadable"}:
|
|
1479
|
+
maintainability_parse_failed_files += 1
|
|
1480
|
+
else:
|
|
1481
|
+
maintainability_scores.append(file_mi)
|
|
1461
1482
|
if risk_info.get("critical_sinks"):
|
|
1462
1483
|
for cs in risk_info["critical_sinks"]:
|
|
1463
1484
|
all_critical_sinks.append({
|
|
@@ -1500,7 +1521,7 @@ def analyze_codebase(
|
|
|
1500
1521
|
"risk_score": risk_info["risk_score"],
|
|
1501
1522
|
"cyclomatic_complexity": cc,
|
|
1502
1523
|
"cognitive_complexity": cog,
|
|
1503
|
-
"maintainability_index": risk_info.get("maintainability_index"
|
|
1524
|
+
"maintainability_index": risk_info.get("maintainability_index"),
|
|
1504
1525
|
"sensitive_sinks": risk_info["sinks"],
|
|
1505
1526
|
"max_depth": risk_info["max_depth"],
|
|
1506
1527
|
"sloc": sloc,
|
|
@@ -1601,8 +1622,20 @@ def analyze_codebase(
|
|
|
1601
1622
|
|
|
1602
1623
|
avg_cc = round(total_cc / max(1, code_files), 1) if code_files > 0 else 1.0
|
|
1603
1624
|
avg_cog = round(total_cognitive / max(1, code_files), 1) if code_files > 0 else 0.0
|
|
1604
|
-
|
|
1605
|
-
|
|
1625
|
+
# 聚合均值只取可解析文件(F-RSI-20261115-276):无可解析文件时不得伪装
|
|
1626
|
+
# 满分 100.0,以 None 表示"未测得",输出层降级为 0.0 并携带降级计数。
|
|
1627
|
+
avg_mi = (
|
|
1628
|
+
round(sum(maintainability_scores) / len(maintainability_scores), 1)
|
|
1629
|
+
if maintainability_scores else None
|
|
1630
|
+
)
|
|
1631
|
+
if avg_mi is None:
|
|
1632
|
+
mi_grade = "⚪ 未测得(无可解析代码文件)"
|
|
1633
|
+
elif avg_mi >= 65:
|
|
1634
|
+
mi_grade = "🟢 良好"
|
|
1635
|
+
elif avg_mi >= 40:
|
|
1636
|
+
mi_grade = "🟡 关注"
|
|
1637
|
+
else:
|
|
1638
|
+
mi_grade = "🔴 恶化"
|
|
1606
1639
|
|
|
1607
1640
|
health_grade = compute_health_grade(avg_cc, total_god_modules, test_to_code_ratio)
|
|
1608
1641
|
|
|
@@ -1650,9 +1683,11 @@ def analyze_codebase(
|
|
|
1650
1683
|
"modules": modules_breakdown,
|
|
1651
1684
|
"scale_estimation": scale,
|
|
1652
1685
|
"maintainability": {
|
|
1653
|
-
"maintainability_index": avg_mi,
|
|
1654
|
-
"avg_maintainability_index": avg_mi,
|
|
1686
|
+
"maintainability_index": avg_mi if avg_mi is not None else 0.0,
|
|
1687
|
+
"avg_maintainability_index": avg_mi if avg_mi is not None else 0.0,
|
|
1655
1688
|
"maintainability_grade": mi_grade,
|
|
1689
|
+
"parse_failed_files": maintainability_parse_failed_files,
|
|
1690
|
+
"measured_files": len(maintainability_scores),
|
|
1656
1691
|
"avg_cognitive_complexity": avg_cog,
|
|
1657
1692
|
"max_cognitive_complexity": max_cognitive,
|
|
1658
1693
|
},
|
|
@@ -1674,7 +1709,8 @@ def analyze_codebase(
|
|
|
1674
1709
|
"secrets": all_secrets,
|
|
1675
1710
|
"critical_sinks": all_critical_sinks,
|
|
1676
1711
|
"taint_flows": all_taints,
|
|
1677
|
-
"maintainability_index": avg_mi,
|
|
1712
|
+
"maintainability_index": avg_mi if avg_mi is not None else 0.0,
|
|
1713
|
+
"maintainability_parse_failed_files": maintainability_parse_failed_files,
|
|
1678
1714
|
"avg_cognitive_complexity": avg_cog,
|
|
1679
1715
|
"duplication_percentage": duplication_info.get("duplication_percentage", 0.0),
|
|
1680
1716
|
"circular_dependencies_count": architecture_info.get("total_cycles", 0),
|
|
@@ -50,6 +50,12 @@ TIER_SYMBOL_BUDGET = {"deep": 14, "standard": 8, "triage": 5}
|
|
|
50
50
|
RULE_CORPUS_RELATIVE = "prompts/rules"
|
|
51
51
|
|
|
52
52
|
|
|
53
|
+
def _strip_dot_prefix(path: str) -> str:
|
|
54
|
+
"""剥 "./" 前缀(F-029):str.lstrip("./") 是字符集剥离,会吃掉
|
|
55
|
+
点前缀文件名(.bugx/.tests/.github)的开头点——symbol_index.py:198
|
|
56
|
+
已记载该坑,本仓其余站点此番统一对齐。"""
|
|
57
|
+
return path[2:] if path.startswith("./") else path
|
|
58
|
+
|
|
53
59
|
def _core_root(root: Path | None) -> Path:
|
|
54
60
|
if root is not None:
|
|
55
61
|
return Path(root).resolve()
|
|
@@ -63,7 +69,7 @@ def _core_root(root: Path | None) -> Path:
|
|
|
63
69
|
|
|
64
70
|
def _unit_path(unit: str, root: Path) -> Path | None:
|
|
65
71
|
"""把 unit id(可能带 ::symbol 后缀)解析到真实文件。"""
|
|
66
|
-
rel = str(unit).split("::", 1)[0].replace("\\", "/")
|
|
72
|
+
rel = _strip_dot_prefix(str(unit).split("::", 1)[0].replace("\\", "/"))
|
|
67
73
|
if not rel:
|
|
68
74
|
return None
|
|
69
75
|
candidate = root / rel
|
|
@@ -49,6 +49,9 @@ _MACHINE_PREFIX_RE = re.compile(r"/(?:Users|home)/[^/\s\"'`,;)\]]+")
|
|
|
49
49
|
|
|
50
50
|
# 摘要模式的声明字段(TO-008-013):只保留摘要、分类、指纹、计数与必要状态;
|
|
51
51
|
# 结构化错误上下文、before/after、决策链、探针等详情一律不随摘要出网。
|
|
52
|
+
# F-249:full 模式同样默认不带 before/after 源码片段——「不携带源码片段」不再是
|
|
53
|
+
# summary 模式的专属约束,而是两种模式的共同默认;full 与 summary 的差别只在
|
|
54
|
+
# 方法论字段的保留粒度。需要片段的调用方必须显式 ``include_source_snippets=True``。
|
|
52
55
|
SUMMARY_PATTERN_FIELDS = (
|
|
53
56
|
"pattern_id", "category", "title", "root_cause", "status",
|
|
54
57
|
"use_count", "hit_count", "miss_count",
|
|
@@ -112,6 +115,67 @@ def _safe_text(value: Any, field: str) -> str:
|
|
|
112
115
|
return text
|
|
113
116
|
|
|
114
117
|
|
|
118
|
+
#: 片段级审查的敏感标识(F-249):源码片段出网前,值位置一律替换为占位符,
|
|
119
|
+
#: 保留标识名/结构用于复现。凭据形态与绝对路径的硬闸仍是 ``_safe_text``。
|
|
120
|
+
_SNIPPET_ASSIGNMENT_RE = re.compile(
|
|
121
|
+
r"(?i)\b(api[_-]?key|access[_-]?key|secret|password|passwd|private[_-]?key|"
|
|
122
|
+
r"access[_-]?token|auth[_-]?token|token)\b"
|
|
123
|
+
r"(\s*(?::\s*[^=:]+?)?\s*=\s*)(.*)$"
|
|
124
|
+
)
|
|
125
|
+
_SNIPPET_AUTH_HEADER_RE = re.compile(
|
|
126
|
+
r"(?i)\b(bearer|basic)\s+(?=[A-Za-z0-9._~+/=-]*\d)[A-Za-z0-9._~+/=-]{8,}"
|
|
127
|
+
)
|
|
128
|
+
_SNIPPET_EMAIL_RE = re.compile(r"(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b")
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _mask_sensitive_assignment(match: re.Match[str]) -> str:
|
|
132
|
+
"""把敏感标识赋值的**整个右侧**替换为占位符,只保留标识名与赋值结构。
|
|
133
|
+
|
|
134
|
+
``token = get_token()`` / ``api_key = os.environ["KEY"]`` 的右侧虽非硬编码
|
|
135
|
+
字面量,但仍会命中 ``_safe_text`` 的「未脱敏凭据」硬闸而拒绝整包;片段是
|
|
136
|
+
显式要求才出网的证据,宁可抹掉表达式也不能让审查与硬闸互相矛盾。保留
|
|
137
|
+
标识名足以表达「这里用了什么」,具体取值由本地源码负责复现。
|
|
138
|
+
"""
|
|
139
|
+
name, sep, _rest = match.groups()
|
|
140
|
+
return f"{name}{sep}{{{{REDACTED_SECRET}}}}"
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _review_source_snippet(value: Any, field: str) -> str:
|
|
144
|
+
"""片段级审查:语法归一化 + 敏感标识剔除,之后仍过 ``_safe_text`` 硬闸。
|
|
145
|
+
|
|
146
|
+
仅在显式 ``include_source_snippets=True`` 时调用。归一化让片段与本地源码
|
|
147
|
+
形态一致(统一行尾、tab 展开、逐行去尾空白、压缩连续空行、去首尾空行);
|
|
148
|
+
剔除把赋值/认证头/邮箱里的敏感值换成占位符。**不做凭据豁免**:审查漏掉的
|
|
149
|
+
凭据形态仍由 ``_safe_text`` 阻断,绝对路径仍按 ``_safe_text`` 既有判定处理
|
|
150
|
+
(该判定只认行首/空白前的绝对路径,引号内路径不在其覆盖范围——这是修复前
|
|
151
|
+
就存在的边界,本次不放宽也不扩大)。
|
|
152
|
+
"""
|
|
153
|
+
if not isinstance(value, str) or not value.strip():
|
|
154
|
+
raise KnowledgeSyncError(f"{field}必须是非空字符串")
|
|
155
|
+
lines = [
|
|
156
|
+
line.replace("\t", " ").rstrip()
|
|
157
|
+
for line in value.replace("\r\n", "\n").replace("\r", "\n").split("\n")
|
|
158
|
+
]
|
|
159
|
+
normalized: list[str] = []
|
|
160
|
+
for line in lines:
|
|
161
|
+
if not line.strip():
|
|
162
|
+
# 首部空行丢弃、连续空行压成一行、尾部空行在收尾时统一去掉。
|
|
163
|
+
if not normalized or normalized[-1] == "":
|
|
164
|
+
continue
|
|
165
|
+
normalized.append("")
|
|
166
|
+
continue
|
|
167
|
+
normalized.append(line)
|
|
168
|
+
while normalized and normalized[-1] == "":
|
|
169
|
+
normalized.pop()
|
|
170
|
+
reviewed = []
|
|
171
|
+
for line in normalized:
|
|
172
|
+
line = _SNIPPET_ASSIGNMENT_RE.sub(_mask_sensitive_assignment, line)
|
|
173
|
+
line = _SNIPPET_AUTH_HEADER_RE.sub(lambda m: f"{m.group(1)} {{{{REDACTED_TOKEN}}}}", line)
|
|
174
|
+
line = _SNIPPET_EMAIL_RE.sub("{{REDACTED_EMAIL}}", line)
|
|
175
|
+
reviewed.append(line)
|
|
176
|
+
return _safe_text("\n".join(reviewed), field)
|
|
177
|
+
|
|
178
|
+
|
|
115
179
|
def _bundle_content(bundle: dict[str, Any]) -> dict[str, Any]:
|
|
116
180
|
return {
|
|
117
181
|
"schema_version": bundle.get("schema_version"),
|
|
@@ -158,7 +222,16 @@ def _validate_bundle(bundle: dict[str, Any], *, require_approved: bool = False)
|
|
|
158
222
|
return {"bundle_id": bundle_id, "patterns": normalized, "approval": approval}
|
|
159
223
|
|
|
160
224
|
|
|
161
|
-
def _portable_pattern(
|
|
225
|
+
def _portable_pattern(
|
|
226
|
+
pattern: dict[str, Any], *, include_source_snippets: bool = False,
|
|
227
|
+
) -> dict[str, Any]:
|
|
228
|
+
"""把本地 pattern 投影为可出网的便携记录(数据最小化边界)。
|
|
229
|
+
|
|
230
|
+
F-249:默认**不携带** ``before_code``/``after_code`` 源码片段——出网面只保留
|
|
231
|
+
``fix_summary``/``pattern_id``/指纹与 ``source_refs`` 定位引用。源码片段只有在
|
|
232
|
+
调用方显式 ``include_source_snippets=True`` 时才写入,且必须先经
|
|
233
|
+
``_review_source_snippet``(语法归一化 + 敏感标识剔除)再落盘。
|
|
234
|
+
"""
|
|
162
235
|
source_refs = []
|
|
163
236
|
for value in pattern.get("source_refs", []):
|
|
164
237
|
text = _safe_text(value, "source_refs")
|
|
@@ -191,16 +264,9 @@ def _portable_pattern(pattern: dict[str, Any]) -> dict[str, Any]:
|
|
|
191
264
|
_safe_text(x, "successful_solution")
|
|
192
265
|
for x in pattern.get("successful_solution", [])
|
|
193
266
|
],
|
|
194
|
-
#
|
|
195
|
-
#
|
|
196
|
-
|
|
197
|
-
_safe_text(pattern["before_code"], "before_code")
|
|
198
|
-
if pattern.get("before_code") else ""
|
|
199
|
-
),
|
|
200
|
-
"after_code": (
|
|
201
|
-
_safe_text(pattern["after_code"], "after_code")
|
|
202
|
-
if pattern.get("after_code") else ""
|
|
203
|
-
),
|
|
267
|
+
# 源码证据默认不出网(F-249):便携包只带「怎么修」的结论(fix_summary)
|
|
268
|
+
# 与定位引用(source_refs)。before/after 片段是调用方显式要求时才追加,
|
|
269
|
+
# 见本函数末尾的 include_source_snippets 分支——不再由模式名隐式决定。
|
|
204
270
|
"fix_summary": (
|
|
205
271
|
_safe_text(pattern["fix_summary"], "fix_summary")
|
|
206
272
|
if pattern.get("fix_summary") else ""
|
|
@@ -218,17 +284,37 @@ def _portable_pattern(pattern: dict[str, Any]) -> dict[str, Any]:
|
|
|
218
284
|
"source_refs": source_refs,
|
|
219
285
|
"status": "candidate",
|
|
220
286
|
}
|
|
287
|
+
if include_source_snippets:
|
|
288
|
+
# 显式开关 + 片段级审查:先归一化/剔除敏感标识,再由 _safe_text 兜住
|
|
289
|
+
# 凭据与绝对路径。空片段保持空串,不因开关打开就凭空生成内容。
|
|
290
|
+
result["before_code"] = (
|
|
291
|
+
_review_source_snippet(pattern["before_code"], "before_code")
|
|
292
|
+
if pattern.get("before_code") else ""
|
|
293
|
+
)
|
|
294
|
+
result["after_code"] = (
|
|
295
|
+
_review_source_snippet(pattern["after_code"], "after_code")
|
|
296
|
+
if pattern.get("after_code") else ""
|
|
297
|
+
)
|
|
221
298
|
# Validate after stripping local counters, timestamps and finding fingerprints.
|
|
222
299
|
ledger._pattern(result) # noqa: SLF001
|
|
223
300
|
return result
|
|
224
301
|
|
|
225
302
|
|
|
226
|
-
def export_candidates(
|
|
303
|
+
def export_candidates(
|
|
304
|
+
project_ledger: Path, output: Path, contributor: str,
|
|
305
|
+
*, include_source_snippets: bool = False,
|
|
306
|
+
) -> dict[str, Any]:
|
|
307
|
+
"""导出 candidate 便携包。
|
|
308
|
+
|
|
309
|
+
``include_source_snippets`` 默认 False:出网包只带修复结论与定位引用,
|
|
310
|
+
before/after 源码片段需调用方显式开启(并接受片段级审查)。该默认对
|
|
311
|
+
export/approve/import 全链路一致,不按 detail_mode 隐式区分(F-249)。
|
|
312
|
+
"""
|
|
227
313
|
_regular(project_ledger.with_suffix(".sqlite3"), "项目 SQLite 账本")
|
|
228
314
|
contributor = _safe_text(contributor, "contributor")
|
|
229
315
|
state = ledger.read(project_ledger)
|
|
230
316
|
patterns = [
|
|
231
|
-
_portable_pattern(value)
|
|
317
|
+
_portable_pattern(value, include_source_snippets=include_source_snippets)
|
|
232
318
|
for value in state["lessons"].values()
|
|
233
319
|
if value.get("status") == "candidate"
|
|
234
320
|
]
|
|
@@ -252,6 +338,7 @@ def export_candidates(project_ledger: Path, output: Path, contributor: str) -> d
|
|
|
252
338
|
_atomic_json(output, bundle)
|
|
253
339
|
return {"status": "exported", "bundle_id": bundle["bundle_id"],
|
|
254
340
|
"patterns": len(patterns), "content_hash": bundle["content_hash"],
|
|
341
|
+
"source_snippets": bool(include_source_snippets),
|
|
255
342
|
"output": str(output)}
|
|
256
343
|
|
|
257
344
|
|
|
@@ -874,6 +961,10 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
874
961
|
parser.add_argument("--output", type=Path)
|
|
875
962
|
parser.add_argument("--bundle-id")
|
|
876
963
|
parser.add_argument("--contributor", default="local-supervisor")
|
|
964
|
+
parser.add_argument(
|
|
965
|
+
"--include-source-snippets", action="store_true",
|
|
966
|
+
help="在便携包中携带 before/after 源码片段(默认不带;开启后经片段级审查)",
|
|
967
|
+
)
|
|
877
968
|
parser.add_argument("--reviewer")
|
|
878
969
|
parser.add_argument("--reason")
|
|
879
970
|
args = parser.parse_args(argv)
|
|
@@ -881,7 +972,10 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
881
972
|
if args.command == "export":
|
|
882
973
|
if not all((args.project_ledger, args.output)):
|
|
883
974
|
raise KnowledgeSyncError("export 需要 --project-ledger 和 --output")
|
|
884
|
-
result = export_candidates(
|
|
975
|
+
result = export_candidates(
|
|
976
|
+
args.project_ledger, args.output, args.contributor,
|
|
977
|
+
include_source_snippets=args.include_source_snippets,
|
|
978
|
+
)
|
|
885
979
|
elif args.command == "approve":
|
|
886
980
|
if not all((args.bundle, args.output, args.reviewer, args.reason)):
|
|
887
981
|
raise KnowledgeSyncError("approve 需要 --bundle --output --reviewer --reason")
|
|
@@ -44,7 +44,7 @@ _LEGACY_HOST_RUNTIME_DIRS = {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
def
|
|
47
|
+
def is_engine_namespace_segment(part: str) -> bool:
|
|
48
48
|
"""任一目录分量是否属于 BugX 引擎自己的运行态命名空间。
|
|
49
49
|
|
|
50
50
|
``_LEGACY_HOST_RUNTIME_DIRS`` 只登记了确切的 ``.bugx``,而引擎与宿主 AI
|
|
@@ -94,7 +94,8 @@ DEPENDENCY_OR_GENERATED_DIRS = {
|
|
|
94
94
|
".gradle", "vendor", "third_party", ".pytest_cache", ".ruff_cache",
|
|
95
95
|
}
|
|
96
96
|
# Keep the old public name for callers that used it, but do not use it as a
|
|
97
|
-
# blunt ``any path segment`` filter:
|
|
97
|
+
# blunt ``any path segment`` filter: product code may legitimately contain a
|
|
98
|
+
# directory named ``build``.
|
|
98
99
|
EXCLUDED_DIRS = HOST_RUNTIME_DIRS | DEPENDENCY_OR_GENERATED_DIRS | {
|
|
99
100
|
"build", "tests", "test", "__tests__", "docs", "examples", "evals",
|
|
100
101
|
}
|
|
@@ -105,10 +106,10 @@ TOP_LEVEL_SOURCE_EXCLUDED_DIRS = {
|
|
|
105
106
|
".bugx-patches",
|
|
106
107
|
}
|
|
107
108
|
# 资产发现(include_test_assets=True)额外排除的顶层目录:BugX 双轨报告/
|
|
108
|
-
# 收据默认输出到 ``evals/oss``(HTML/JSON 均在资产扩展名清单内)——审计
|
|
109
|
+
# 收据默认输出到 ``verification/evals/oss``(HTML/JSON 均在资产扩展名清单内)——审计
|
|
109
110
|
# 产物喂回覆盖清单是自增强污染(实测 evals 报告被列为审计单元)。
|
|
110
111
|
TOP_LEVEL_ASSET_EXCLUDED_DIRS = {
|
|
111
|
-
"
|
|
112
|
+
"verification",
|
|
112
113
|
".bugx-patches",
|
|
113
114
|
}
|
|
114
115
|
SOURCE_EXTS = {
|
|
@@ -281,7 +282,7 @@ def _directory_is_excluded(
|
|
|
281
282
|
) -> bool:
|
|
282
283
|
parts = set(relative.parts)
|
|
283
284
|
if parts & (HOST_RUNTIME_DIRS | DEPENDENCY_OR_GENERATED_DIRS) \
|
|
284
|
-
or any(
|
|
285
|
+
or any(is_engine_namespace_segment(part) for part in parts) \
|
|
285
286
|
or _generated_directory(relative):
|
|
286
287
|
return True
|
|
287
288
|
if include_test_assets and relative.parts and relative.parts[0] in TOP_LEVEL_ASSET_EXCLUDED_DIRS:
|
|
@@ -686,7 +687,7 @@ def _tree_sitter_symbols(source: str, language: str) -> tuple[list[Symbol], str
|
|
|
686
687
|
try:
|
|
687
688
|
from tree_sitter_language_pack import get_parser
|
|
688
689
|
except ImportError:
|
|
689
|
-
return [], "Tree-sitter 后端未安装;安装 bugx-
|
|
690
|
+
return [], "Tree-sitter 后端未安装;安装 bugx-cli[graph]"
|
|
690
691
|
try:
|
|
691
692
|
tree = get_parser(language).parse(source.encode("utf-8"))
|
|
692
693
|
except Exception as exc: # language-pack 对不支持语法抛出多种运行时异常
|
|
@@ -939,8 +940,15 @@ def index_repository(
|
|
|
939
940
|
except OSError as exc:
|
|
940
941
|
if strict:
|
|
941
942
|
raise SourceDiscoveryError(f"源码读取失败 {path}: {exc}") from exc
|
|
943
|
+
# 宽松模式必须让读失败在索引输出层可区分(F-RSI-20261115-284):
|
|
944
|
+
# digest_status 与 parse 的 error 字段正交,二者可在同一文件共存,
|
|
945
|
+
# 避免"空 digest 文件"静默从索引消失、下游产生盲区。模式对齐
|
|
946
|
+
# code_analyzer._analyze_python_ast 的 parse_status(F-RSI-20261115-276)。
|
|
942
947
|
digest = ""
|
|
943
948
|
size = 0
|
|
949
|
+
digest_status = "error"
|
|
950
|
+
else:
|
|
951
|
+
digest_status = "ok"
|
|
944
952
|
file_id = f"file:{relative}"
|
|
945
953
|
nodes.append({"id": file_id, "type": "file", "path": relative})
|
|
946
954
|
symbol_payload = []
|
|
@@ -966,6 +974,7 @@ def index_repository(
|
|
|
966
974
|
"error": error,
|
|
967
975
|
"content_hash": digest,
|
|
968
976
|
"size": size,
|
|
977
|
+
"digest_status": digest_status,
|
|
969
978
|
"symbols": symbol_payload,
|
|
970
979
|
})
|
|
971
980
|
return {
|
|
@@ -978,6 +987,9 @@ def index_repository(
|
|
|
978
987
|
"files": len(files),
|
|
979
988
|
"symbols": sum(len(item["symbols"]) for item in files),
|
|
980
989
|
"parse_errors": sum(bool(item["error"]) for item in files),
|
|
990
|
+
"digest_errors": sum(
|
|
991
|
+
1 for item in files if item["digest_status"] == "error"
|
|
992
|
+
),
|
|
981
993
|
},
|
|
982
994
|
}
|
|
983
995
|
|
|
@@ -999,6 +1011,11 @@ def audit_units(
|
|
|
999
1011
|
if strict:
|
|
1000
1012
|
raise SourceDiscoveryError(f"源码读取失败 {path}: {exc}") from exc
|
|
1001
1013
|
digest = ""
|
|
1014
|
+
# F-RSI-20261115-284 同型输出面:与 index_repository 的 digest_status
|
|
1015
|
+
# 对齐,避免读失败单元以空 content_hash 静默进入下游审计/覆盖清单。
|
|
1016
|
+
digest_status = "error"
|
|
1017
|
+
else:
|
|
1018
|
+
digest_status = "ok"
|
|
1002
1019
|
leaves = _leaf_symbols(symbols)
|
|
1003
1020
|
if leaves and all(symbol.kind == "module" for symbol in leaves):
|
|
1004
1021
|
# A file containing only constants/configuration remains a useful
|
|
@@ -1015,6 +1032,7 @@ def audit_units(
|
|
|
1015
1032
|
"error": error,
|
|
1016
1033
|
"end_line": symbol.end_line,
|
|
1017
1034
|
"content_hash": digest,
|
|
1035
|
+
"digest_status": digest_status,
|
|
1018
1036
|
"language": language,
|
|
1019
1037
|
} for symbol in leaves)
|
|
1020
1038
|
else:
|
|
@@ -1028,6 +1046,7 @@ def audit_units(
|
|
|
1028
1046
|
"error": error,
|
|
1029
1047
|
"language": language,
|
|
1030
1048
|
"content_hash": digest,
|
|
1049
|
+
"digest_status": digest_status,
|
|
1031
1050
|
})
|
|
1032
1051
|
return result
|
|
1033
1052
|
|