briefloop 0.11.12__py3-none-any.whl
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.
- briefloop-0.11.12.dist-info/METADATA +473 -0
- briefloop-0.11.12.dist-info/RECORD +424 -0
- briefloop-0.11.12.dist-info/WHEEL +5 -0
- briefloop-0.11.12.dist-info/entry_points.txt +3 -0
- briefloop-0.11.12.dist-info/licenses/LICENSE +22 -0
- briefloop-0.11.12.dist-info/top_level.txt +1 -0
- multi_agent_brief/__init__.py +36 -0
- multi_agent_brief/analysis_blocks/__init__.py +11 -0
- multi_agent_brief/analysis_blocks/builder.py +206 -0
- multi_agent_brief/analysis_blocks/renderer.py +237 -0
- multi_agent_brief/analysis_blocks/schemas.py +52 -0
- multi_agent_brief/analysis_modules/__init__.py +8 -0
- multi_agent_brief/analysis_modules/base.py +87 -0
- multi_agent_brief/analysis_modules/market_competitor/__init__.py +68 -0
- multi_agent_brief/analysis_modules/market_competitor/auditor.py +290 -0
- multi_agent_brief/analysis_modules/market_competitor/config.py +187 -0
- multi_agent_brief/analysis_modules/market_competitor/event_builder.py +226 -0
- multi_agent_brief/analysis_modules/market_competitor/renderer.py +199 -0
- multi_agent_brief/analysis_modules/market_competitor/schemas.py +518 -0
- multi_agent_brief/analysis_modules/policy_regulatory/__init__.py +7 -0
- multi_agent_brief/analysis_modules/policy_regulatory/audit.py +195 -0
- multi_agent_brief/analysis_modules/policy_regulatory/module.py +387 -0
- multi_agent_brief/analysis_modules/policy_regulatory/schemas.py +129 -0
- multi_agent_brief/analysis_modules/registry.py +73 -0
- multi_agent_brief/audience/__init__.py +19 -0
- multi_agent_brief/audience/profiles.py +246 -0
- multi_agent_brief/audience_memory/__init__.py +23 -0
- multi_agent_brief/audience_memory/profile.py +358 -0
- multi_agent_brief/audit/__init__.py +36 -0
- multi_agent_brief/audit/case_applicability.py +181 -0
- multi_agent_brief/audit/deterministic.py +471 -0
- multi_agent_brief/audit/editorial_governance.py +404 -0
- multi_agent_brief/audit/final_quality.py +764 -0
- multi_agent_brief/audit/harness.py +242 -0
- multi_agent_brief/audit/interfaces.py +96 -0
- multi_agent_brief/audit/limitation_hygiene.py +238 -0
- multi_agent_brief/audit/proposal_boundary.py +34 -0
- multi_agent_brief/audit/redaction.py +27 -0
- multi_agent_brief/audit/rule_packs.py +96 -0
- multi_agent_brief/audit/semantic.py +435 -0
- multi_agent_brief/capabilities/__init__.py +22 -0
- multi_agent_brief/capabilities/catalog.py +215 -0
- multi_agent_brief/capabilities/detect.py +199 -0
- multi_agent_brief/capabilities/models.py +60 -0
- multi_agent_brief/capabilities/recommend.py +206 -0
- multi_agent_brief/cli/__init__.py +2 -0
- multi_agent_brief/cli/analysis_commands.py +140 -0
- multi_agent_brief/cli/approval_commands.py +107 -0
- multi_agent_brief/cli/audit_commands.py +59 -0
- multi_agent_brief/cli/capability_commands.py +548 -0
- multi_agent_brief/cli/claude_commands.py +159 -0
- multi_agent_brief/cli/competitors_commands.py +182 -0
- multi_agent_brief/cli/controls_commands.py +137 -0
- multi_agent_brief/cli/deliver_commands.py +942 -0
- multi_agent_brief/cli/eval_cases_commands.py +99 -0
- multi_agent_brief/cli/experiments_commands.py +395 -0
- multi_agent_brief/cli/feedback_commands.py +192 -0
- multi_agent_brief/cli/finalize_commands.py +153 -0
- multi_agent_brief/cli/gates_commands.py +174 -0
- multi_agent_brief/cli/hermes_commands.py +356 -0
- multi_agent_brief/cli/improve_commands.py +224 -0
- multi_agent_brief/cli/init_commands.py +564 -0
- multi_agent_brief/cli/init_wizard.py +1473 -0
- multi_agent_brief/cli/input_commands.py +237 -0
- multi_agent_brief/cli/main.py +288 -0
- multi_agent_brief/cli/onboard_commands.py +193 -0
- multi_agent_brief/cli/product_commands.py +1449 -0
- multi_agent_brief/cli/provenance_commands.py +100 -0
- multi_agent_brief/cli/release_commands.py +68 -0
- multi_agent_brief/cli/repair_commands.py +169 -0
- multi_agent_brief/cli/run_commands.py +292 -0
- multi_agent_brief/cli/runtime_commands.py +81 -0
- multi_agent_brief/cli/secrets_commands.py +232 -0
- multi_agent_brief/cli/semantic_support_commands.py +80 -0
- multi_agent_brief/cli/sources_commands.py +647 -0
- multi_agent_brief/cli/start_commands.py +8 -0
- multi_agent_brief/cli/state_commands.py +446 -0
- multi_agent_brief/cli/status_commands.py +26 -0
- multi_agent_brief/cli/workbuddy_commands.py +103 -0
- multi_agent_brief/configs/artifact_contracts.yaml +514 -0
- multi_agent_brief/configs/orchestrator_contract.yaml +181 -0
- multi_agent_brief/configs/policy_packs/default.yaml +65 -0
- multi_agent_brief/configs/policy_profiles/evidence_extract_default.yaml +58 -0
- multi_agent_brief/configs/policy_profiles/finance_default.yaml +44 -0
- multi_agent_brief/configs/policy_profiles/internet_default.yaml +44 -0
- multi_agent_brief/configs/policy_profiles/manufacturing_default.yaml +33 -0
- multi_agent_brief/configs/policy_profiles/solar_manufacturing_default.yaml +64 -0
- multi_agent_brief/configs/report_packs/evidence_extract.yaml +48 -0
- multi_agent_brief/configs/report_packs/management_monthly.yaml +36 -0
- multi_agent_brief/configs/report_packs/market_weekly.yaml +36 -0
- multi_agent_brief/configs/report_packs/solar_industry_periodic.yaml +50 -0
- multi_agent_brief/configs/report_templates/evidence_extract.yaml +55 -0
- multi_agent_brief/configs/report_templates/management_monthly.yaml +48 -0
- multi_agent_brief/configs/report_templates/market_weekly.yaml +49 -0
- multi_agent_brief/configs/report_templates/solar_industry_periodic.yaml +75 -0
- multi_agent_brief/configs/stage_specs.yaml +180 -0
- multi_agent_brief/contracts/__init__.py +41 -0
- multi_agent_brief/contracts/base.py +99 -0
- multi_agent_brief/contracts/errors.py +41 -0
- multi_agent_brief/contracts/migrations/__init__.py +5 -0
- multi_agent_brief/contracts/migrations/claim_v1_to_v2.py +33 -0
- multi_agent_brief/contracts/registry.py +159 -0
- multi_agent_brief/contracts/role_topology.py +25 -0
- multi_agent_brief/contracts/schemas/__init__.py +35 -0
- multi_agent_brief/contracts/schemas/analysis_pack.py +135 -0
- multi_agent_brief/contracts/schemas/atomic_claim_graph.py +304 -0
- multi_agent_brief/contracts/schemas/audit_report.py +80 -0
- multi_agent_brief/contracts/schemas/candidate_item.py +51 -0
- multi_agent_brief/contracts/schemas/claim.py +197 -0
- multi_agent_brief/contracts/schemas/claim_draft.py +386 -0
- multi_agent_brief/contracts/schemas/claim_support_matrix.py +334 -0
- multi_agent_brief/contracts/schemas/evidence_span_registry.py +270 -0
- multi_agent_brief/contracts/schemas/policy_profile.py +247 -0
- multi_agent_brief/contracts/schemas/report_spec.py +257 -0
- multi_agent_brief/contracts/schemas/semantic_assessment_report.py +480 -0
- multi_agent_brief/contracts/schemas/source_evidence_pack_manifest.py +233 -0
- multi_agent_brief/contracts/schemas/source_item.py +96 -0
- multi_agent_brief/contracts/semantic_assessment_status.py +12 -0
- multi_agent_brief/contracts/source_metadata.py +252 -0
- multi_agent_brief/contracts/target_contract.py +460 -0
- multi_agent_brief/contracts/validator.py +225 -0
- multi_agent_brief/controls/__init__.py +23 -0
- multi_agent_brief/controls/contract.py +106 -0
- multi_agent_brief/controls/switchboard.py +1076 -0
- multi_agent_brief/core/__init__.py +2 -0
- multi_agent_brief/core/citations.py +14 -0
- multi_agent_brief/core/claim_ledger.py +94 -0
- multi_agent_brief/core/config.py +191 -0
- multi_agent_brief/core/env.py +69 -0
- multi_agent_brief/core/previous.py +83 -0
- multi_agent_brief/core/schemas.py +181 -0
- multi_agent_brief/core/selection.py +189 -0
- multi_agent_brief/delivery/__init__.py +6 -0
- multi_agent_brief/delivery/base.py +36 -0
- multi_agent_brief/delivery/feishu.py +204 -0
- multi_agent_brief/delivery/gws.py +237 -0
- multi_agent_brief/evaluation_cases/__init__.py +15 -0
- multi_agent_brief/evaluation_cases/contract.py +429 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/approved_guidance_materialized/workspace/config.yaml +18 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/approved_guidance_materialized/workspace/improvement/ledger.jsonl +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/approved_guidance_materialized/workspace/sources.yaml +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/approved_guidance_materialized/workspace/user.md +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/company_event_missing_latest_official_check/workspace/config.yaml +13 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/company_event_missing_latest_official_check/workspace/sources.yaml +9 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/company_event_missing_latest_official_check/workspace/user.md +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/control_switchboard_selection_is_not_execution/workspace/config.yaml +12 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/control_switchboard_selection_is_not_execution/workspace/sources.yaml +6 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/control_switchboard_selection_is_not_execution/workspace/user.md +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/feedback_triage_required/workspace/config.yaml +6 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/feedback_triage_required/workspace/input/human_feedback.md +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/feedback_triage_required/workspace/sources.yaml +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/feedback_triage_required/workspace/user.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/final_abstract_quality_warning_surface/workspace/config.yaml +8 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/final_abstract_quality_warning_surface/workspace/output/brief.md +14 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/final_abstract_quality_warning_surface/workspace/output/intermediate/audit_report.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/final_abstract_quality_warning_surface/workspace/output/intermediate/audited_brief.md +5 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/final_abstract_quality_warning_surface/workspace/output/intermediate/candidate_claims.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/final_abstract_quality_warning_surface/workspace/output/intermediate/claim_ledger.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/final_abstract_quality_warning_surface/workspace/output/intermediate/screened_candidates.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/final_abstract_quality_warning_surface/workspace/sources.yaml +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/final_abstract_quality_warning_surface/workspace/user.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/formal_release_missing_human_approval/workspace/config.yaml +13 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/formal_release_missing_human_approval/workspace/sources.yaml +9 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/formal_release_missing_human_approval/workspace/user.md +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/guidance_manifestation_not_observable/workspace/config.yaml +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/guidance_manifestation_not_observable/workspace/sources.yaml +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/guidance_manifestation_not_observable/workspace/user.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/media_only_legal_policy_blocks_research_review/workspace/config.yaml +13 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/media_only_legal_policy_blocks_research_review/workspace/sources.yaml +9 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/media_only_legal_policy_blocks_research_review/workspace/user.md +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/mixed_metric_scope_support_blocker/workspace/config.yaml +13 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/mixed_metric_scope_support_blocker/workspace/sources.yaml +9 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/mixed_metric_scope_support_blocker/workspace/user.md +5 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/planned_blocking_issue_cannot_continue/workspace/config.yaml +6 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/planned_blocking_issue_cannot_continue/workspace/output/intermediate/audited_brief.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/planned_blocking_issue_cannot_continue/workspace/output/intermediate/candidate_claims.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/planned_blocking_issue_cannot_continue/workspace/output/intermediate/claim_ledger.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/planned_blocking_issue_cannot_continue/workspace/output/intermediate/feedback_issues.json +25 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/planned_blocking_issue_cannot_continue/workspace/output/intermediate/repair_plan.json +27 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/planned_blocking_issue_cannot_continue/workspace/output/intermediate/screened_candidates.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/planned_blocking_issue_cannot_continue/workspace/sources.yaml +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/planned_blocking_issue_cannot_continue/workspace/user.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/provenance_projection_minimal/workspace/config.yaml +8 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/provenance_projection_minimal/workspace/output/intermediate/audit_report.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/provenance_projection_minimal/workspace/output/intermediate/audited_brief.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/provenance_projection_minimal/workspace/output/intermediate/candidate_claims.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/provenance_projection_minimal/workspace/output/intermediate/claim_ledger.json +11 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/provenance_projection_minimal/workspace/output/intermediate/quality_gate_report.json +22 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/provenance_projection_minimal/workspace/output/intermediate/screened_candidates.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/provenance_projection_minimal/workspace/sources.yaml +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/provenance_projection_minimal/workspace/user.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_source_appendix/workspace/config.yaml +13 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_source_appendix/workspace/output/intermediate/audit_report.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_source_appendix/workspace/output/intermediate/audited_brief.md +5 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_source_appendix/workspace/output/intermediate/candidate_claims.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_source_appendix/workspace/output/intermediate/claim_ledger.json +40 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_source_appendix/workspace/output/intermediate/screened_candidates.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_source_appendix/workspace/sources.yaml +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_source_appendix/workspace/user.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_target_relevance/workspace/config.yaml +8 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_target_relevance/workspace/output/brief.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_target_relevance/workspace/output/intermediate/audit_report.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_target_relevance/workspace/output/intermediate/audited_brief.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_target_relevance/workspace/output/intermediate/candidate_claims.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_target_relevance/workspace/output/intermediate/claim_ledger.json +13 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_target_relevance/workspace/output/intermediate/screened_candidates.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_target_relevance/workspace/sources.yaml +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reader_facing_target_relevance/workspace/user.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/release_readiness_forged_event_blocker/workspace/config.yaml +13 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/release_readiness_forged_event_blocker/workspace/output/intermediate/release_readiness_report.json +31 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/release_readiness_forged_event_blocker/workspace/sources.yaml +9 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/release_readiness_forged_event_blocker/workspace/user.md +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reverted_entry_removed_from_next_snapshot/workspace/config.yaml +18 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reverted_entry_removed_from_next_snapshot/workspace/improvement/ledger.jsonl +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reverted_entry_removed_from_next_snapshot/workspace/improvement/memory.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reverted_entry_removed_from_next_snapshot/workspace/output/intermediate/improvement_memory_snapshot.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reverted_entry_removed_from_next_snapshot/workspace/sources.yaml +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/reverted_entry_removed_from_next_snapshot/workspace/user.md +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/config.yaml +12 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/input/sources/source-001.txt +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/brief.md +37 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/delivery/brief.md +37 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/intermediate/atomic_claim_graph.json +17 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/intermediate/audit_report.json +5 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/intermediate/audited_brief.md +37 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/intermediate/claim_ledger.json +20 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/intermediate/evidence_span_registry.json +20 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/intermediate/finalize_report.json +40 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/intermediate/gates/auditor_quality_gate_report.json +42 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/intermediate/gates/finalize_quality_gate_report.json +42 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/intermediate/screened_candidates.json +33 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/source_appendix.md +12 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/output/source_appendix_trace.md +10 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/report_spec.yaml +24 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/sources.yaml +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/same_evidence_reader_quality_regression/workspace/user.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/source_evidence_pack_blocks_non_evidence_file/workspace/config.yaml +13 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/source_evidence_pack_blocks_non_evidence_file/workspace/input/sources/README.md +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/source_evidence_pack_blocks_non_evidence_file/workspace/output/intermediate/source_evidence_pack_manifest.json +26 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/source_evidence_pack_blocks_non_evidence_file/workspace/sources.yaml +9 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/source_evidence_pack_blocks_non_evidence_file/workspace/user.md +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/stale_current_claim/workspace/config.yaml +9 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/stale_current_claim/workspace/output/intermediate/audit_report.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/stale_current_claim/workspace/output/intermediate/audited_brief.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/stale_current_claim/workspace/output/intermediate/candidate_claims.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/stale_current_claim/workspace/output/intermediate/claim_ledger.json +13 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/stale_current_claim/workspace/output/intermediate/screened_candidates.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/stale_current_claim/workspace/sources.yaml +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/stale_current_claim/workspace/user.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/third_party_price_snapshot_formal_block/workspace/config.yaml +13 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/third_party_price_snapshot_formal_block/workspace/sources.yaml +9 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/third_party_price_snapshot_formal_block/workspace/user.md +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/trajectory_retry_budget_exhausted/workspace/config.yaml +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/trajectory_retry_budget_exhausted/workspace/sources.yaml +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/trajectory_retry_budget_exhausted/workspace/user.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unapproved_entry_not_materialized/workspace/config.yaml +18 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unapproved_entry_not_materialized/workspace/improvement/ledger.jsonl +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unapproved_entry_not_materialized/workspace/sources.yaml +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unapproved_entry_not_materialized/workspace/user.md +4 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unauthorized_institution_branding_blocks_release/workspace/config.yaml +18 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unauthorized_institution_branding_blocks_release/workspace/sources.yaml +9 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unauthorized_institution_branding_blocks_release/workspace/user.md +5 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unsupported_material_fact/workspace/config.yaml +8 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unsupported_material_fact/workspace/output/intermediate/audit_report.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unsupported_material_fact/workspace/output/intermediate/audited_brief.md +8 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unsupported_material_fact/workspace/output/intermediate/candidate_claims.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unsupported_material_fact/workspace/output/intermediate/claim_ledger.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unsupported_material_fact/workspace/output/intermediate/screened_candidates.json +1 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unsupported_material_fact/workspace/sources.yaml +2 -0
- multi_agent_brief/evaluation_cases/fixtures/cases/unsupported_material_fact/workspace/user.md +3 -0
- multi_agent_brief/evaluation_cases/fixtures/manifest.yaml +861 -0
- multi_agent_brief/evaluation_cases/fixtures.py +20 -0
- multi_agent_brief/evaluation_cases/runner.py +1603 -0
- multi_agent_brief/experiments/__init__.py +45 -0
- multi_agent_brief/experiments/experiment_080.py +5835 -0
- multi_agent_brief/experiments/schemas.py +63 -0
- multi_agent_brief/experiments/target_contract.py +10 -0
- multi_agent_brief/feedback/__init__.py +17 -0
- multi_agent_brief/feedback/feedback_contract.py +482 -0
- multi_agent_brief/feedback/feedback_state.py +898 -0
- multi_agent_brief/hermes/__init__.py +25 -0
- multi_agent_brief/hermes/adapter.py +832 -0
- multi_agent_brief/improvement/__init__.py +83 -0
- multi_agent_brief/improvement/contract.py +1114 -0
- multi_agent_brief/improvement/memory.py +451 -0
- multi_agent_brief/improvement/product_definition.py +228 -0
- multi_agent_brief/improvement/state.py +961 -0
- multi_agent_brief/inputs/__init__.py +2 -0
- multi_agent_brief/inputs/classifier.py +322 -0
- multi_agent_brief/inputs/contracts.py +59 -0
- multi_agent_brief/inputs/extractor.py +310 -0
- multi_agent_brief/install/__init__.py +2 -0
- multi_agent_brief/install/writer.py +97 -0
- multi_agent_brief/onboarding/__init__.py +11 -0
- multi_agent_brief/onboarding/io.py +103 -0
- multi_agent_brief/onboarding/mapper.py +484 -0
- multi_agent_brief/onboarding/schema.py +46 -0
- multi_agent_brief/orchestrator/__init__.py +2 -0
- multi_agent_brief/orchestrator/fact_layer_import.py +352 -0
- multi_agent_brief/orchestrator/handoff.py +2209 -0
- multi_agent_brief/orchestrator/role_topology.py +42 -0
- multi_agent_brief/orchestrator/run_archive.py +888 -0
- multi_agent_brief/orchestrator/run_integrity.py +346 -0
- multi_agent_brief/orchestrator/runtime_state/__init__.py +70 -0
- multi_agent_brief/orchestrator/runtime_state/_io.py +167 -0
- multi_agent_brief/orchestrator/runtime_state/_transactions.py +298 -0
- multi_agent_brief/orchestrator/runtime_state/artifact_registry.py +1825 -0
- multi_agent_brief/orchestrator/runtime_state/atomic_claim_graph.py +96 -0
- multi_agent_brief/orchestrator/runtime_state/claim_ledger_freeze.py +510 -0
- multi_agent_brief/orchestrator/runtime_state/claim_metadata_enrichment.py +836 -0
- multi_agent_brief/orchestrator/runtime_state/claim_support_matrix.py +582 -0
- multi_agent_brief/orchestrator/runtime_state/completion_gates.py +672 -0
- multi_agent_brief/orchestrator/runtime_state/contracts_loader.py +66 -0
- multi_agent_brief/orchestrator/runtime_state/decisions.py +239 -0
- multi_agent_brief/orchestrator/runtime_state/errors.py +61 -0
- multi_agent_brief/orchestrator/runtime_state/event_log.py +256 -0
- multi_agent_brief/orchestrator/runtime_state/evidence_span_registry.py +233 -0
- multi_agent_brief/orchestrator/runtime_state/fact_layer.py +755 -0
- multi_agent_brief/orchestrator/runtime_state/identity.py +90 -0
- multi_agent_brief/orchestrator/runtime_state/lifecycle.py +675 -0
- multi_agent_brief/orchestrator/runtime_state/manifest.py +82 -0
- multi_agent_brief/orchestrator/runtime_state/operations.py +224 -0
- multi_agent_brief/orchestrator/runtime_state/paths.py +38 -0
- multi_agent_brief/orchestrator/runtime_state/repair.py +984 -0
- multi_agent_brief/orchestrator/runtime_state/safety_surfaces.py +147 -0
- multi_agent_brief/orchestrator/runtime_state/semantic_assessment_report.py +692 -0
- multi_agent_brief/orchestrator/runtime_state/semantic_support_acceptance.py +683 -0
- multi_agent_brief/orchestrator/runtime_state/source_evidence_pack.py +131 -0
- multi_agent_brief/orchestrator/runtime_state/stage_completion.py +1320 -0
- multi_agent_brief/orchestrator/runtime_state/trajectory.py +200 -0
- multi_agent_brief/orchestrator/runtime_state/workflow.py +350 -0
- multi_agent_brief/orchestrator/source_evidence.py +43 -0
- multi_agent_brief/orchestrator/timing.py +410 -0
- multi_agent_brief/orchestrator_contract.py +96 -0
- multi_agent_brief/outputs/__init__.py +2 -0
- multi_agent_brief/outputs/atomic_reader_projection.py +288 -0
- multi_agent_brief/outputs/docx.py +32 -0
- multi_agent_brief/outputs/finalize.py +1036 -0
- multi_agent_brief/outputs/ib_docx.py +983 -0
- multi_agent_brief/outputs/naming.py +38 -0
- multi_agent_brief/outputs/pdf.py +20 -0
- multi_agent_brief/outputs/reader_final_gate.py +509 -0
- multi_agent_brief/outputs/reader_projection.py +397 -0
- multi_agent_brief/outputs/source_appendix.py +753 -0
- multi_agent_brief/outputs/templates/__init__.py +112 -0
- multi_agent_brief/product/__init__.py +49 -0
- multi_agent_brief/product/bundle_projection.py +686 -0
- multi_agent_brief/product/citation_profile.py +145 -0
- multi_agent_brief/product/guidance_manifestation.py +421 -0
- multi_agent_brief/product/materiality_selection.py +472 -0
- multi_agent_brief/product/policy_gate_adapter.py +116 -0
- multi_agent_brief/product/policy_profile.py +39 -0
- multi_agent_brief/product/policy_projection.py +161 -0
- multi_agent_brief/product/policy_registry.py +83 -0
- multi_agent_brief/product/policy_resolver.py +225 -0
- multi_agent_brief/product/quality_closeout.py +188 -0
- multi_agent_brief/product/quality_panel.py +2217 -0
- multi_agent_brief/product/release_approval.py +1034 -0
- multi_agent_brief/product/report_pack.py +130 -0
- multi_agent_brief/product/report_pack_aliases.py +68 -0
- multi_agent_brief/product/report_registry.py +101 -0
- multi_agent_brief/product/report_spec.py +181 -0
- multi_agent_brief/product/support_wording.py +525 -0
- multi_agent_brief/product/template_conformance.py +516 -0
- multi_agent_brief/product/template_projection.py +123 -0
- multi_agent_brief/product/template_registry.py +244 -0
- multi_agent_brief/product/template_render_plan.py +315 -0
- multi_agent_brief/product/template_renderer.py +224 -0
- multi_agent_brief/product/trajectory_regulation.py +441 -0
- multi_agent_brief/provenance/__init__.py +5 -0
- multi_agent_brief/provenance/builder.py +841 -0
- multi_agent_brief/provenance/contract.py +21 -0
- multi_agent_brief/provenance/io.py +144 -0
- multi_agent_brief/provenance/model.py +110 -0
- multi_agent_brief/provenance/references.py +43 -0
- multi_agent_brief/provenance/validator.py +135 -0
- multi_agent_brief/quality_gates/__init__.py +19 -0
- multi_agent_brief/quality_gates/contract.py +581 -0
- multi_agent_brief/quality_gates/state.py +2498 -0
- multi_agent_brief/repair/__init__.py +5 -0
- multi_agent_brief/repair/router.py +842 -0
- multi_agent_brief/runtime_assets.py +431 -0
- multi_agent_brief/sources/__init__.py +16 -0
- multi_agent_brief/sources/api_filings.py +236 -0
- multi_agent_brief/sources/api_news.py +174 -0
- multi_agent_brief/sources/base.py +142 -0
- multi_agent_brief/sources/cached_package.py +119 -0
- multi_agent_brief/sources/cli_provider.py +263 -0
- multi_agent_brief/sources/coverage.py +336 -0
- multi_agent_brief/sources/decider.py +756 -0
- multi_agent_brief/sources/doctor.py +373 -0
- multi_agent_brief/sources/evidence_pack.py +364 -0
- multi_agent_brief/sources/feishu_provider.py +326 -0
- multi_agent_brief/sources/filing_resolver.py +400 -0
- multi_agent_brief/sources/industry_packs.py +130 -0
- multi_agent_brief/sources/join.py +206 -0
- multi_agent_brief/sources/local_signal.py +81 -0
- multi_agent_brief/sources/local_signal_planner.py +636 -0
- multi_agent_brief/sources/manual.py +259 -0
- multi_agent_brief/sources/mcp_provider.py +309 -0
- multi_agent_brief/sources/mineru_provider.py +601 -0
- multi_agent_brief/sources/normalizer.py +95 -0
- multi_agent_brief/sources/opencli_provider.py +282 -0
- multi_agent_brief/sources/planner.py +178 -0
- multi_agent_brief/sources/registry.py +367 -0
- multi_agent_brief/sources/rss.py +190 -0
- multi_agent_brief/sources/search_backends/__init__.py +31 -0
- multi_agent_brief/sources/search_backends/base.py +51 -0
- multi_agent_brief/sources/search_backends/brave.py +192 -0
- multi_agent_brief/sources/search_backends/capabilities.py +94 -0
- multi_agent_brief/sources/search_backends/exa.py +180 -0
- multi_agent_brief/sources/search_backends/firecrawl.py +164 -0
- multi_agent_brief/sources/search_backends/serper.py +241 -0
- multi_agent_brief/sources/search_backends/tavily.py +124 -0
- multi_agent_brief/sources/sourcehub.py +505 -0
- multi_agent_brief/sources/web_search.py +267 -0
- multi_agent_brief/status.py +966 -0
- multi_agent_brief/tools/__init__.py +3 -0
- multi_agent_brief/tools/draft_cleanup.py +198 -0
- multi_agent_brief/workbuddy/__init__.py +1 -0
- multi_agent_brief/workbuddy/diagnose.py +569 -0
- multi_agent_brief/workbuddy/skill_pack.py +309 -0
- multi_agent_brief/workspace/__init__.py +1 -0
- multi_agent_brief/workspace/init_profile.py +45 -0
|
@@ -0,0 +1,2217 @@
|
|
|
1
|
+
"""Product-layer quality panel projection.
|
|
2
|
+
|
|
3
|
+
The Quality Panel summarizes existing control-plane artifacts for operator
|
|
4
|
+
review. It does not run gates, call LLMs, mutate workflow state, approve
|
|
5
|
+
delivery, or decide release eligibility.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
import uuid
|
|
13
|
+
from collections import Counter
|
|
14
|
+
from datetime import datetime, timezone
|
|
15
|
+
from html import escape as _html_escape
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any, Mapping
|
|
18
|
+
|
|
19
|
+
from multi_agent_brief.core.claim_ledger import ClaimLedger
|
|
20
|
+
from multi_agent_brief.product.guidance_manifestation import (
|
|
21
|
+
validate_guidance_manifestation_projection_payload,
|
|
22
|
+
)
|
|
23
|
+
from multi_agent_brief.product.materiality_selection import validate_materiality_selection_payload
|
|
24
|
+
from multi_agent_brief.product.quality_closeout import (
|
|
25
|
+
quality_panel_closeout_projection,
|
|
26
|
+
validate_quality_panel_closeout_payload,
|
|
27
|
+
)
|
|
28
|
+
from multi_agent_brief.product.support_wording import validate_support_wording_payload
|
|
29
|
+
from multi_agent_brief.product.template_conformance import validate_report_template_conformance_payload
|
|
30
|
+
from multi_agent_brief.product.trajectory_regulation import validate_trajectory_regulation_payload
|
|
31
|
+
from multi_agent_brief.contracts.semantic_assessment_status import SEMANTIC_ASSESSMENT_REPORT_STATUSES
|
|
32
|
+
|
|
33
|
+
QUALITY_PANEL_SCHEMA_VERSION = "briefloop.quality_panel.v1"
|
|
34
|
+
QUALITY_PANEL_BOUNDARY = "product_quality_panel_projection_only_not_gate_or_release_authority"
|
|
35
|
+
QUALITY_PANEL_RUNTIME_EFFECT = "projection_only"
|
|
36
|
+
QUALITY_SUMMARY_BOUNDARY = (
|
|
37
|
+
"deterministic projection of quality_panel.json only; not a quality score, "
|
|
38
|
+
"not a truth proof, not a gate report replacement, and not a release authorization"
|
|
39
|
+
)
|
|
40
|
+
QUALITY_PANEL_HTML_BOUNDARY = (
|
|
41
|
+
"static deterministic projection of quality_panel.json only; not a quality score, "
|
|
42
|
+
"not a truth proof, not a gate report replacement, not a release authorization, "
|
|
43
|
+
"and not an interactive frontend"
|
|
44
|
+
)
|
|
45
|
+
QUALITY_PANEL_HTML_BOUNDARY_ZH = (
|
|
46
|
+
"仅为 quality_panel.json 的静态确定性投影;不是质量评分,不是真实性证明,"
|
|
47
|
+
"不能替代门禁报告,不构成发布授权,也不是交互式前端"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
_INTERMEDIATE = Path("output") / "intermediate"
|
|
51
|
+
_BLOCKING_SUPPORT_LABELS = {"unsupported", "contradicted", "insufficient_evidence"}
|
|
52
|
+
_QUALITY_SUMMARY_FORBIDDEN_PHRASES = (
|
|
53
|
+
"ready to publish",
|
|
54
|
+
"truth proven",
|
|
55
|
+
"approved for publication",
|
|
56
|
+
"approved for release",
|
|
57
|
+
"release authorized",
|
|
58
|
+
)
|
|
59
|
+
_QUALITY_PANEL_SHA_PREFIX = "Quality-Panel-SHA256: sha256:"
|
|
60
|
+
_QUALITY_PANEL_HTML_FORBIDDEN_MARKERS = (
|
|
61
|
+
"<script",
|
|
62
|
+
"<link",
|
|
63
|
+
"<iframe",
|
|
64
|
+
" src=",
|
|
65
|
+
"src=",
|
|
66
|
+
"javascript:",
|
|
67
|
+
" onload=",
|
|
68
|
+
" onclick=",
|
|
69
|
+
)
|
|
70
|
+
_QUALITY_PANEL_RECOMMENDED_ACTIONS = {
|
|
71
|
+
"inspect_workflow_blocker",
|
|
72
|
+
"materialize_durable_source_evidence",
|
|
73
|
+
"repair_source_evidence_pack_manifest",
|
|
74
|
+
"resolve_quality_gate_blockers",
|
|
75
|
+
"regenerate_scoped_gate_reports",
|
|
76
|
+
"complete_finalize_delivery_hygiene",
|
|
77
|
+
"review_claim_support_records",
|
|
78
|
+
"repair_reader_final_residue",
|
|
79
|
+
"inspect_run_integrity",
|
|
80
|
+
"request_human_review",
|
|
81
|
+
"block_run",
|
|
82
|
+
"review_materiality_exclusions",
|
|
83
|
+
"review_reader_template_conformance",
|
|
84
|
+
"review_support_wording_warnings",
|
|
85
|
+
}
|
|
86
|
+
_QUALITY_PANEL_HTML_LABELS = {
|
|
87
|
+
"audit_attachment": ("BriefLoop audit attachment", "BriefLoop 审计附件"),
|
|
88
|
+
"quality_panel": ("Quality Panel", "质量面板"),
|
|
89
|
+
"overall_status": ("Overall status", "总体状态"),
|
|
90
|
+
"run_id": ("Run ID", "运行 ID"),
|
|
91
|
+
"generated": ("Generated", "生成时间"),
|
|
92
|
+
"gate_blockers": ("Gate blockers", "门禁阻断项"),
|
|
93
|
+
"gate_warnings": ("Gate warnings", "门禁警告"),
|
|
94
|
+
"missing_incomplete": ("Missing/incomplete", "缺失/未完成"),
|
|
95
|
+
"materiality_findings": ("Materiality findings", "重要性发现"),
|
|
96
|
+
"template_warnings": ("Template warnings", "模板警告"),
|
|
97
|
+
"support_wording": ("Support wording", "支持措辞"),
|
|
98
|
+
"semantic_support": ("Semantic support proposals", "语义支持提案"),
|
|
99
|
+
"semantic_support_proposals": ("Semantic support proposals", "语义支持提案"),
|
|
100
|
+
"recommended_actions": ("Recommended actions", "建议动作"),
|
|
101
|
+
"recommended_next_actions": ("Recommended Next Actions", "建议下一步"),
|
|
102
|
+
"control_integrity": ("Control Integrity", "控制完整性"),
|
|
103
|
+
"run_integrity": ("Run integrity", "运行完整性"),
|
|
104
|
+
"reference_eligible": ("Reference eligible", "可作为参考"),
|
|
105
|
+
"fact_layer": ("Fact layer", "事实层"),
|
|
106
|
+
"runtime_effect": ("Runtime effect", "运行影响"),
|
|
107
|
+
"source_evidence": ("Source Evidence", "来源证据"),
|
|
108
|
+
"source_pack": ("Source pack", "来源包"),
|
|
109
|
+
"durable_sources": ("Durable sources", "持久来源"),
|
|
110
|
+
"missing_titles": ("Missing titles", "缺失标题"),
|
|
111
|
+
"missing_publishers": ("Missing publishers/institutions", "缺失发布方/机构"),
|
|
112
|
+
"retrieval_source_mix": ("Retrieval source mix", "检索来源构成"),
|
|
113
|
+
"underlying_evidence_mix": ("Underlying evidence mix", "底层证据构成"),
|
|
114
|
+
"gate_findings": ("Gate Findings", "门禁发现"),
|
|
115
|
+
"auditor_gate": ("Auditor gate", "审计门禁"),
|
|
116
|
+
"finalize_gate": ("Finalize gate", "定稿门禁"),
|
|
117
|
+
"legacy_latest_gate": ("Legacy/latest gate", "旧版/最新门禁"),
|
|
118
|
+
"blocking_findings": ("Blocking findings", "阻断发现"),
|
|
119
|
+
"warning_findings": ("Warning findings", "警告发现"),
|
|
120
|
+
"claim_support_risk": ("Claim And Support Risk", "声明与支持风险"),
|
|
121
|
+
"claim_count": ("Claim count", "声明数量"),
|
|
122
|
+
"claim_support_matrix": ("Claim-Support Matrix", "声明支持矩阵"),
|
|
123
|
+
"unsupported_rows": (
|
|
124
|
+
"Unsupported / contradicted / insufficient rows",
|
|
125
|
+
"不支持 / 矛盾 / 证据不足行",
|
|
126
|
+
),
|
|
127
|
+
"weak_support_atoms": ("Weak-support atoms", "弱支持原子"),
|
|
128
|
+
"materiality_selection": ("Materiality selection", "重要性筛选"),
|
|
129
|
+
"materiality_exclusions": ("Materiality/focus exclusions", "重要性/焦点排除"),
|
|
130
|
+
"reader_template_conformance": ("Reader template conformance", "读者模板一致性"),
|
|
131
|
+
"reader_template_warnings": ("Reader template warnings", "读者模板警告"),
|
|
132
|
+
"support_wording_warnings": ("Support wording warnings", "支持措辞警告"),
|
|
133
|
+
"semantic_support_status": ("Semantic support status", "语义支持状态"),
|
|
134
|
+
"semantic_support_boundary": ("Semantic support boundary", "语义支持边界"),
|
|
135
|
+
"calibration_labels": ("Calibration labels", "校准标签"),
|
|
136
|
+
"llm_only_proposals": ("LLM-only proposals", "仅 LLM 提案"),
|
|
137
|
+
"high_uncertainty": ("High uncertainty", "高不确定性"),
|
|
138
|
+
"high_disagreement": ("High disagreement", "高分歧"),
|
|
139
|
+
"human_adjudication_required": ("Human adjudication required", "需要人工裁决"),
|
|
140
|
+
"reader_clean_citation": ("Reader Clean And Citation Hygiene", "读者清洁与引用卫生"),
|
|
141
|
+
"reader_clean_status": ("Reader-clean status", "读者清洁状态"),
|
|
142
|
+
"duplicate_citation_count": ("Duplicate citation count", "重复引用数量"),
|
|
143
|
+
"source_appendix_warnings": ("Source appendix warnings", "来源附录警告"),
|
|
144
|
+
"quality_closeout_bundle": ("Quality Closeout And Bundle Separation", "质量收口与包分离"),
|
|
145
|
+
"closeout_status": ("Closeout status", "收口状态"),
|
|
146
|
+
"closeout_command": ("Closeout command", "收口命令"),
|
|
147
|
+
"audit_bundle": ("Audit bundle", "审计包"),
|
|
148
|
+
"delivery_bundle": ("Delivery bundle", "交付包"),
|
|
149
|
+
"none": ("none", "无"),
|
|
150
|
+
"no_recommended_action": (
|
|
151
|
+
"No recommended action reported by quality_panel.json.",
|
|
152
|
+
"quality_panel.json 未报告建议动作。",
|
|
153
|
+
),
|
|
154
|
+
"color_legend": ("Color legend", "颜色图例"),
|
|
155
|
+
"legend_pass": ("pass / clean", "通过 / 正常"),
|
|
156
|
+
"legend_warning": ("warning", "警告"),
|
|
157
|
+
"legend_block": ("blocking", "阻断"),
|
|
158
|
+
"legend_missing": ("missing / incomplete", "缺失 / 未完成"),
|
|
159
|
+
"legend_info": ("neutral / informational", "中性 / 信息"),
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
# Status-value semantics: machine value -> color level. Values not listed
|
|
163
|
+
# render as level "missing" when falsy-ish and "info" otherwise via
|
|
164
|
+
# _status_level. Levels: pass, warning, block, missing, info.
|
|
165
|
+
_QUALITY_PANEL_STATUS_LEVELS = {
|
|
166
|
+
"pass": "pass",
|
|
167
|
+
"clean": "pass",
|
|
168
|
+
"checked": "pass",
|
|
169
|
+
"generated": "pass",
|
|
170
|
+
"complete": "pass",
|
|
171
|
+
"ok": "pass",
|
|
172
|
+
"true": "pass",
|
|
173
|
+
"warning": "warning",
|
|
174
|
+
"degraded": "warning",
|
|
175
|
+
"stale": "warning",
|
|
176
|
+
"false": "warning",
|
|
177
|
+
"expected": "warning",
|
|
178
|
+
"block": "block",
|
|
179
|
+
"blocked": "block",
|
|
180
|
+
"fail": "block",
|
|
181
|
+
"failed": "block",
|
|
182
|
+
"error": "block",
|
|
183
|
+
"invalid": "block",
|
|
184
|
+
"contaminated": "block",
|
|
185
|
+
"missing": "missing",
|
|
186
|
+
"incomplete": "missing",
|
|
187
|
+
"not_available": "missing",
|
|
188
|
+
"missing_input": "missing",
|
|
189
|
+
"not_ready": "missing",
|
|
190
|
+
"unavailable": "missing",
|
|
191
|
+
"unknown": "missing",
|
|
192
|
+
"none": "missing",
|
|
193
|
+
"projection_only": "info",
|
|
194
|
+
"excluded": "info",
|
|
195
|
+
"included_when_present_and_valid": "info",
|
|
196
|
+
"not_applicable": "info",
|
|
197
|
+
"skipped": "info",
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
# Machine status value -> zh display text. The en side always shows the raw
|
|
201
|
+
# machine value so the audit attachment stays greppable against control files.
|
|
202
|
+
_QUALITY_PANEL_HTML_VALUES_ZH = {
|
|
203
|
+
"pass": "通过",
|
|
204
|
+
"clean": "无污染",
|
|
205
|
+
"checked": "已检查",
|
|
206
|
+
"generated": "已生成",
|
|
207
|
+
"complete": "已完成",
|
|
208
|
+
"ok": "正常",
|
|
209
|
+
"true": "是",
|
|
210
|
+
"warning": "警告",
|
|
211
|
+
"degraded": "已降级",
|
|
212
|
+
"stale": "已过期",
|
|
213
|
+
"false": "否",
|
|
214
|
+
"expected": "待生成",
|
|
215
|
+
"block": "阻断",
|
|
216
|
+
"blocked": "已阻断",
|
|
217
|
+
"fail": "失败",
|
|
218
|
+
"failed": "失败",
|
|
219
|
+
"error": "错误",
|
|
220
|
+
"invalid": "无效",
|
|
221
|
+
"contaminated": "已污染",
|
|
222
|
+
"missing": "缺失",
|
|
223
|
+
"incomplete": "未完成",
|
|
224
|
+
"not_available": "不可用",
|
|
225
|
+
"missing_input": "缺少输入",
|
|
226
|
+
"not_ready": "未就绪",
|
|
227
|
+
"unavailable": "不可用",
|
|
228
|
+
"unknown": "未知",
|
|
229
|
+
"none": "无",
|
|
230
|
+
"projection_only": "仅投影,不改运行状态",
|
|
231
|
+
"excluded": "已排除",
|
|
232
|
+
"included_when_present_and_valid": "存在且有效时包含",
|
|
233
|
+
"not_applicable": "不适用",
|
|
234
|
+
"skipped": "已跳过",
|
|
235
|
+
"invalid_report": "报告无效",
|
|
236
|
+
"proposal_only_not_a_gate_not_release_authority": "仅提案,不是门禁或发布授权",
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
# Recommended-action machine names -> zh display text (en shows the raw name).
|
|
240
|
+
_QUALITY_PANEL_HTML_ACTIONS_ZH = {
|
|
241
|
+
"inspect_workflow_blocker": "检查工作流阻断项",
|
|
242
|
+
"materialize_durable_source_evidence": "落地持久来源证据",
|
|
243
|
+
"repair_source_evidence_pack_manifest": "修复来源证据包清单",
|
|
244
|
+
"resolve_quality_gate_blockers": "解决质量门禁阻断项",
|
|
245
|
+
"regenerate_scoped_gate_reports": "重新生成阶段门禁报告",
|
|
246
|
+
"complete_finalize_delivery_hygiene": "完成定稿交付卫生检查",
|
|
247
|
+
"review_claim_support_records": "复核声明支持记录",
|
|
248
|
+
"repair_reader_final_residue": "修复读者终稿残留",
|
|
249
|
+
"inspect_run_integrity": "检查运行完整性",
|
|
250
|
+
"request_human_review": "请求人工审阅",
|
|
251
|
+
"block_run": "阻断本次运行",
|
|
252
|
+
"review_materiality_exclusions": "复核重要性排除项",
|
|
253
|
+
"review_reader_template_conformance": "复核读者模板一致性",
|
|
254
|
+
"review_support_wording_warnings": "复核支持措辞警告",
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
# Recommended-action reason codes -> zh display text (en shows the raw code).
|
|
258
|
+
_QUALITY_PANEL_HTML_REASONS_ZH = {
|
|
259
|
+
"blocking_gate_findings": "存在门禁阻断发现",
|
|
260
|
+
"finalize_or_reader_clean_missing": "定稿或读者清洁检查缺失",
|
|
261
|
+
"materiality_or_focus_candidate_deprioritized": "重要性/焦点候选被降级",
|
|
262
|
+
"materiality_or_focus_candidate_excluded_by_capacity_or_scope": "重要性/焦点候选因容量或范围被排除",
|
|
263
|
+
"quality_gate_status_failed": "质量门禁状态为失败",
|
|
264
|
+
"reader_clean_failed": "读者清洁检查失败",
|
|
265
|
+
"reader_template_conformance_warning_only": "读者模板一致性仅为警告",
|
|
266
|
+
"run_integrity_not_clean": "运行完整性不干净",
|
|
267
|
+
"scoped_quality_gate_reports_missing": "阶段门禁报告缺失",
|
|
268
|
+
"source_evidence_pack_invalid": "来源证据包无效",
|
|
269
|
+
"source_evidence_pack_missing": "来源证据包缺失",
|
|
270
|
+
"semantic_support_human_adjudication_required": "语义支持提案需要人工裁决",
|
|
271
|
+
"support_calibrated_wording_warning_only": "支持措辞校准仅为警告",
|
|
272
|
+
"unsupported_claim_present_in_reader_text": "读者文本存在未支持声明",
|
|
273
|
+
"unsupported_claim_support_rows": "存在未支持的声明支持行",
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
class QualityPanelError(ValueError):
|
|
278
|
+
"""Raised when a Quality Panel projection cannot be built or rendered."""
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def quality_panel_path(workspace: str | Path) -> Path:
|
|
282
|
+
return Path(workspace).expanduser().resolve() / _INTERMEDIATE / "quality_panel.json"
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def quality_summary_path(workspace: str | Path) -> Path:
|
|
286
|
+
return Path(workspace).expanduser().resolve() / _INTERMEDIATE / "quality_summary.md"
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def quality_panel_html_path(workspace: str | Path) -> Path:
|
|
290
|
+
return Path(workspace).expanduser().resolve() / _INTERMEDIATE / "quality_panel.html"
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def build_quality_panel(
|
|
294
|
+
workspace: str | Path,
|
|
295
|
+
*,
|
|
296
|
+
generated_at: str | None = None,
|
|
297
|
+
) -> dict[str, Any]:
|
|
298
|
+
"""Build a read-only machine-readable quality projection."""
|
|
299
|
+
|
|
300
|
+
from multi_agent_brief.status import build_workspace_status
|
|
301
|
+
|
|
302
|
+
ws = Path(workspace).expanduser().resolve()
|
|
303
|
+
workspace_status = build_workspace_status(ws)
|
|
304
|
+
registry_payload = _read_json_mapping(ws / _INTERMEDIATE / "artifact_registry.json") or {}
|
|
305
|
+
artifacts = registry_payload.get("artifacts") if isinstance(registry_payload, dict) else {}
|
|
306
|
+
artifacts = artifacts if isinstance(artifacts, dict) else {}
|
|
307
|
+
|
|
308
|
+
runtime = workspace_status.get("runtime") if isinstance(workspace_status.get("runtime"), dict) else {}
|
|
309
|
+
workflow = workspace_status.get("workflow") if isinstance(workspace_status.get("workflow"), dict) else {}
|
|
310
|
+
run_integrity = workflow.get("run_integrity") if isinstance(workflow.get("run_integrity"), dict) else {}
|
|
311
|
+
source_evidence = _source_evidence_summary(ws, artifacts)
|
|
312
|
+
gates = _gate_summary(ws)
|
|
313
|
+
claims = _claim_summary(ws, workspace_status, artifacts)
|
|
314
|
+
delivery = _delivery_summary(ws, workspace_status)
|
|
315
|
+
trajectory = (
|
|
316
|
+
workspace_status.get("trajectory_regulation")
|
|
317
|
+
if isinstance(workspace_status.get("trajectory_regulation"), dict)
|
|
318
|
+
else {}
|
|
319
|
+
)
|
|
320
|
+
guidance_manifestation = (
|
|
321
|
+
workspace_status.get("guidance_manifestation")
|
|
322
|
+
if isinstance(workspace_status.get("guidance_manifestation"), dict)
|
|
323
|
+
else {}
|
|
324
|
+
)
|
|
325
|
+
materiality_selection = (
|
|
326
|
+
workspace_status.get("materiality_selection")
|
|
327
|
+
if isinstance(workspace_status.get("materiality_selection"), dict)
|
|
328
|
+
else {}
|
|
329
|
+
)
|
|
330
|
+
report_template_conformance = (
|
|
331
|
+
workspace_status.get("report_template_conformance")
|
|
332
|
+
if isinstance(workspace_status.get("report_template_conformance"), dict)
|
|
333
|
+
else {}
|
|
334
|
+
)
|
|
335
|
+
support_wording = (
|
|
336
|
+
workspace_status.get("support_wording")
|
|
337
|
+
if isinstance(workspace_status.get("support_wording"), dict)
|
|
338
|
+
else {}
|
|
339
|
+
)
|
|
340
|
+
semantic_support = _semantic_support_summary(workspace_status)
|
|
341
|
+
finalize_report = _read_json_mapping(ws / _INTERMEDIATE / "finalize_report.json") or {}
|
|
342
|
+
closeout = quality_panel_closeout_projection(
|
|
343
|
+
workspace=ws,
|
|
344
|
+
finalize_report=finalize_report,
|
|
345
|
+
generated_by_quality_summarize=True,
|
|
346
|
+
artifact_registry=registry_payload,
|
|
347
|
+
)
|
|
348
|
+
control_integrity = {
|
|
349
|
+
"run_integrity": run_integrity.get("status") or "unknown",
|
|
350
|
+
"reference_eligible": bool(run_integrity.get("reference_eligible")),
|
|
351
|
+
"fact_layer_status": _fact_layer_status(artifacts, source_evidence),
|
|
352
|
+
}
|
|
353
|
+
recommended_actions = _recommended_actions(
|
|
354
|
+
workflow=workflow,
|
|
355
|
+
control_integrity=control_integrity,
|
|
356
|
+
source_evidence=source_evidence,
|
|
357
|
+
gates=gates,
|
|
358
|
+
claims=claims,
|
|
359
|
+
delivery=delivery,
|
|
360
|
+
trajectory=trajectory,
|
|
361
|
+
materiality_selection=materiality_selection,
|
|
362
|
+
report_template_conformance=report_template_conformance,
|
|
363
|
+
support_wording=support_wording,
|
|
364
|
+
semantic_support=semantic_support,
|
|
365
|
+
)
|
|
366
|
+
overall_status = _overall_status(
|
|
367
|
+
workspace_status=workspace_status,
|
|
368
|
+
workflow=workflow,
|
|
369
|
+
control_integrity=control_integrity,
|
|
370
|
+
source_evidence=source_evidence,
|
|
371
|
+
gates=gates,
|
|
372
|
+
claims=claims,
|
|
373
|
+
delivery=delivery,
|
|
374
|
+
materiality_selection=materiality_selection,
|
|
375
|
+
report_template_conformance=report_template_conformance,
|
|
376
|
+
support_wording=support_wording,
|
|
377
|
+
semantic_support=semantic_support,
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
return {
|
|
381
|
+
"schema_version": QUALITY_PANEL_SCHEMA_VERSION,
|
|
382
|
+
"workspace": ".",
|
|
383
|
+
"run_id": _text(runtime.get("run_id")) or "unknown",
|
|
384
|
+
"generated_at": _text(generated_at) or _utc_now(),
|
|
385
|
+
"read_only": True,
|
|
386
|
+
"runtime_effect": QUALITY_PANEL_RUNTIME_EFFECT,
|
|
387
|
+
"boundary": QUALITY_PANEL_BOUNDARY,
|
|
388
|
+
"overall_status": overall_status,
|
|
389
|
+
"control_integrity": control_integrity,
|
|
390
|
+
"source_evidence": source_evidence,
|
|
391
|
+
"gates": gates,
|
|
392
|
+
"claims": claims,
|
|
393
|
+
"delivery": delivery,
|
|
394
|
+
"trajectory_regulation": trajectory,
|
|
395
|
+
"guidance_manifestation": guidance_manifestation,
|
|
396
|
+
"materiality_selection": materiality_selection,
|
|
397
|
+
"report_template_conformance": report_template_conformance,
|
|
398
|
+
"support_wording": support_wording,
|
|
399
|
+
"semantic_support": semantic_support,
|
|
400
|
+
"quality_panel_closeout": closeout,
|
|
401
|
+
"recommended_actions": recommended_actions,
|
|
402
|
+
"non_goals": [
|
|
403
|
+
"quality_score",
|
|
404
|
+
"semantic_truth_proof",
|
|
405
|
+
"release_eligibility_decision",
|
|
406
|
+
"delivery_approval",
|
|
407
|
+
"gate_reimplementation",
|
|
408
|
+
"automatic_repair",
|
|
409
|
+
],
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
def write_quality_panel(
|
|
414
|
+
*,
|
|
415
|
+
workspace: str | Path,
|
|
416
|
+
output_path: str | Path | None = None,
|
|
417
|
+
generated_at: str | None = None,
|
|
418
|
+
) -> dict[str, Any]:
|
|
419
|
+
ws = Path(workspace).expanduser().resolve()
|
|
420
|
+
target = Path(output_path).expanduser() if output_path else quality_panel_path(ws)
|
|
421
|
+
if not target.is_absolute():
|
|
422
|
+
target = ws / target
|
|
423
|
+
target = target.resolve()
|
|
424
|
+
try:
|
|
425
|
+
target.relative_to(ws)
|
|
426
|
+
except ValueError as exc:
|
|
427
|
+
raise ValueError("quality_panel output must stay inside the workspace.") from exc
|
|
428
|
+
payload = build_quality_panel(ws, generated_at=generated_at)
|
|
429
|
+
_write_json_atomic(target, payload)
|
|
430
|
+
return payload
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
def render_quality_summary(
|
|
434
|
+
panel_payload: Mapping[str, Any],
|
|
435
|
+
*,
|
|
436
|
+
quality_panel_sha256: str,
|
|
437
|
+
) -> str:
|
|
438
|
+
"""Render a compact human-readable summary from a valid Quality Panel payload."""
|
|
439
|
+
|
|
440
|
+
reason = validate_quality_panel_payload(panel_payload)
|
|
441
|
+
if reason:
|
|
442
|
+
raise QualityPanelError(f"quality_panel invalid: {reason}")
|
|
443
|
+
panel_sha256 = _normalize_sha256(quality_panel_sha256)
|
|
444
|
+
if not panel_sha256:
|
|
445
|
+
raise QualityPanelError("quality_panel_sha256 must be a SHA-256 hex digest.")
|
|
446
|
+
|
|
447
|
+
source = panel_payload.get("source_evidence")
|
|
448
|
+
source = source if isinstance(source, Mapping) else {}
|
|
449
|
+
gates = panel_payload.get("gates")
|
|
450
|
+
gates = gates if isinstance(gates, Mapping) else {}
|
|
451
|
+
claims = panel_payload.get("claims")
|
|
452
|
+
claims = claims if isinstance(claims, Mapping) else {}
|
|
453
|
+
delivery = panel_payload.get("delivery")
|
|
454
|
+
delivery = delivery if isinstance(delivery, Mapping) else {}
|
|
455
|
+
control = panel_payload.get("control_integrity")
|
|
456
|
+
control = control if isinstance(control, Mapping) else {}
|
|
457
|
+
materiality = panel_payload.get("materiality_selection")
|
|
458
|
+
materiality = materiality if isinstance(materiality, Mapping) else {}
|
|
459
|
+
template_conformance = panel_payload.get("report_template_conformance")
|
|
460
|
+
template_conformance = template_conformance if isinstance(template_conformance, Mapping) else {}
|
|
461
|
+
support_wording = panel_payload.get("support_wording")
|
|
462
|
+
support_wording = support_wording if isinstance(support_wording, Mapping) else {}
|
|
463
|
+
semantic_support = panel_payload.get("semantic_support")
|
|
464
|
+
semantic_support = semantic_support if isinstance(semantic_support, Mapping) else {}
|
|
465
|
+
closeout = panel_payload.get("quality_panel_closeout")
|
|
466
|
+
closeout = closeout if isinstance(closeout, Mapping) else {}
|
|
467
|
+
actions = panel_payload.get("recommended_actions")
|
|
468
|
+
actions = actions if isinstance(actions, list) else []
|
|
469
|
+
|
|
470
|
+
lines = [
|
|
471
|
+
"# Quality Summary",
|
|
472
|
+
"",
|
|
473
|
+
f"Boundary: {QUALITY_SUMMARY_BOUNDARY}.",
|
|
474
|
+
f"{_QUALITY_PANEL_SHA_PREFIX}{panel_sha256}",
|
|
475
|
+
"",
|
|
476
|
+
"This summary is a read-only operator view of existing BriefLoop control artifacts.",
|
|
477
|
+
"Use the source gate reports, artifact registry, event log, and human review records as authority.",
|
|
478
|
+
"",
|
|
479
|
+
"## Overall",
|
|
480
|
+
"",
|
|
481
|
+
f"- Overall status: `{_text(panel_payload.get('overall_status')) or 'unknown'}`",
|
|
482
|
+
f"- Run ID: `{_text(panel_payload.get('run_id')) or 'unknown'}`",
|
|
483
|
+
f"- Runtime effect: `{_text(panel_payload.get('runtime_effect')) or 'unknown'}`",
|
|
484
|
+
f"- Quality Panel boundary: `{_text(panel_payload.get('boundary')) or 'unknown'}`",
|
|
485
|
+
"",
|
|
486
|
+
"## Blocking Issues",
|
|
487
|
+
"",
|
|
488
|
+
]
|
|
489
|
+
_extend_bullets(lines, _quality_summary_blocking_items(control, gates, claims, delivery))
|
|
490
|
+
lines.extend(["", "## Warnings", ""])
|
|
491
|
+
_extend_bullets(
|
|
492
|
+
lines,
|
|
493
|
+
_quality_summary_warning_items(
|
|
494
|
+
source,
|
|
495
|
+
gates,
|
|
496
|
+
claims,
|
|
497
|
+
delivery,
|
|
498
|
+
materiality,
|
|
499
|
+
template_conformance,
|
|
500
|
+
support_wording,
|
|
501
|
+
semantic_support,
|
|
502
|
+
),
|
|
503
|
+
)
|
|
504
|
+
lines.extend(["", "## Missing Or Incomplete Surfaces", ""])
|
|
505
|
+
_extend_bullets(lines, _quality_summary_missing_items(control, source, gates, delivery))
|
|
506
|
+
lines.extend(["", "## Source Evidence", ""])
|
|
507
|
+
lines.extend([
|
|
508
|
+
f"- Source pack status: `{_text(source.get('source_pack_status')) or 'unknown'}`",
|
|
509
|
+
f"- Durable source records: `{_intish(source.get('source_count'))}`",
|
|
510
|
+
f"- Missing source titles: `{_intish(source.get('missing_title_count'))}`",
|
|
511
|
+
f"- Missing publishers/institutions: `{_intish(source.get('missing_publisher_count'))}`",
|
|
512
|
+
f"- Retrieval source mix: {_inline_mapping(source.get('retrieval_source_mix'))}",
|
|
513
|
+
f"- Underlying evidence mix: {_inline_mapping(source.get('underlying_evidence_mix'))}",
|
|
514
|
+
"",
|
|
515
|
+
"## Gates And Reader Clean",
|
|
516
|
+
"",
|
|
517
|
+
f"- Auditor gate: `{_text(gates.get('auditor_status')) or 'unknown'}`",
|
|
518
|
+
f"- Finalize gate: `{_text(gates.get('finalize_status')) or 'unknown'}`",
|
|
519
|
+
f"- Legacy/latest gate report: `{_text(gates.get('legacy_quality_gate_status')) or 'missing'}`",
|
|
520
|
+
f"- Gate blocking findings: `{_intish(gates.get('blocking_count'))}`",
|
|
521
|
+
f"- Gate warnings: `{_intish(gates.get('warning_count'))}`",
|
|
522
|
+
f"- Reader-clean status: `{_text(delivery.get('reader_clean_status')) or 'unknown'}`",
|
|
523
|
+
f"- Duplicate citation count: `{_intish(delivery.get('duplicate_citation_count'))}`",
|
|
524
|
+
f"- Source appendix warnings: `{_intish(delivery.get('source_appendix_warning_count'))}`",
|
|
525
|
+
"",
|
|
526
|
+
"## Claims And Support Records",
|
|
527
|
+
"",
|
|
528
|
+
f"- Claim count: `{_intish(claims.get('claim_count'))}`",
|
|
529
|
+
f"- Claim-Support Matrix status: `{_text(claims.get('claim_support_matrix_status')) or 'unknown'}`",
|
|
530
|
+
f"- Unsupported/contradicted/insufficient support rows: `{_intish(claims.get('unsupported_count'))}`",
|
|
531
|
+
f"- Weak-support atoms: `{_intish(claims.get('weak_support_count'))}`",
|
|
532
|
+
f"- Materiality selection status: `{_text(materiality.get('status')) or 'unknown'}`",
|
|
533
|
+
"- Materiality/focus exclusions: "
|
|
534
|
+
f"`{_materiality_selection_warning_count(materiality)}`",
|
|
535
|
+
"- Reader template conformance: "
|
|
536
|
+
f"`{_text(template_conformance.get('status')) or 'unknown'}`",
|
|
537
|
+
"- Reader template warnings: "
|
|
538
|
+
f"`{_template_conformance_warning_count(template_conformance)}`",
|
|
539
|
+
f"- Support wording status: `{_text(support_wording.get('status')) or 'unknown'}`",
|
|
540
|
+
f"- Support wording warnings: `{_support_wording_warning_count(support_wording)}`",
|
|
541
|
+
"- Semantic support status: "
|
|
542
|
+
f"`{_text(semantic_support.get('status')) or 'unknown'}` "
|
|
543
|
+
"(`proposal-only`, not a gate, not release authority)",
|
|
544
|
+
"- Semantic support proposals: "
|
|
545
|
+
f"`{_intish(semantic_support.get('proposal_count'))}`",
|
|
546
|
+
"- Semantic support calibration labels: "
|
|
547
|
+
f"{_inline_mapping(semantic_support.get('calibration_label_counts'))}",
|
|
548
|
+
"- Semantic support human adjudication required: "
|
|
549
|
+
f"`{_intish(semantic_support.get('requires_human_adjudication_count'))}`",
|
|
550
|
+
"",
|
|
551
|
+
"## Quality Closeout And Bundle Separation",
|
|
552
|
+
"",
|
|
553
|
+
f"- Quality closeout status: `{_text(closeout.get('status')) or 'unknown'}`",
|
|
554
|
+
f"- Closeout command: `{_text(closeout.get('command')) or 'unknown'}`",
|
|
555
|
+
f"- Audit bundle: `{_text(closeout.get('audit_bundle')) or 'unknown'}`",
|
|
556
|
+
f"- Delivery bundle: `{_text(closeout.get('delivery_bundle')) or 'unknown'}`",
|
|
557
|
+
"",
|
|
558
|
+
"## Recommended Next Actions",
|
|
559
|
+
"",
|
|
560
|
+
])
|
|
561
|
+
_extend_bullets(lines, _quality_summary_action_items(actions))
|
|
562
|
+
text = "\n".join(lines).rstrip() + "\n"
|
|
563
|
+
reason = validate_quality_summary_markdown(text)
|
|
564
|
+
if reason:
|
|
565
|
+
raise QualityPanelError(f"quality_summary invalid: {reason}")
|
|
566
|
+
return text
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
def write_quality_summary(
|
|
570
|
+
*,
|
|
571
|
+
workspace: str | Path,
|
|
572
|
+
output_path: str | Path | None = None,
|
|
573
|
+
panel_payload: Mapping[str, Any] | None = None,
|
|
574
|
+
) -> dict[str, Any]:
|
|
575
|
+
ws = Path(workspace).expanduser().resolve()
|
|
576
|
+
panel_path = quality_panel_path(ws)
|
|
577
|
+
source_panel_payload = _read_json_mapping(panel_path)
|
|
578
|
+
if source_panel_payload is None:
|
|
579
|
+
raise QualityPanelError("quality_panel.json is required before writing quality_summary.md.")
|
|
580
|
+
if panel_payload is None:
|
|
581
|
+
panel_payload = source_panel_payload
|
|
582
|
+
elif dict(panel_payload) != source_panel_payload:
|
|
583
|
+
raise QualityPanelError("panel_payload must match quality_panel.json before writing quality_summary.md.")
|
|
584
|
+
text = render_quality_summary(panel_payload, quality_panel_sha256=_sha256_file(panel_path))
|
|
585
|
+
target = Path(output_path).expanduser() if output_path else quality_summary_path(ws)
|
|
586
|
+
if not target.is_absolute():
|
|
587
|
+
target = ws / target
|
|
588
|
+
target = target.resolve()
|
|
589
|
+
try:
|
|
590
|
+
target.relative_to(ws)
|
|
591
|
+
except ValueError as exc:
|
|
592
|
+
raise ValueError("quality_summary output must stay inside the workspace.") from exc
|
|
593
|
+
_write_text_atomic(target, text)
|
|
594
|
+
return {
|
|
595
|
+
"path": _workspace_relative(ws, target),
|
|
596
|
+
"sha256": _sha256_text(text),
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
def render_quality_panel_html(
|
|
601
|
+
panel_payload: Mapping[str, Any],
|
|
602
|
+
*,
|
|
603
|
+
quality_panel_sha256: str,
|
|
604
|
+
) -> str:
|
|
605
|
+
"""Render a static, dependency-free Quality Panel HTML audit attachment."""
|
|
606
|
+
|
|
607
|
+
reason = validate_quality_panel_payload(panel_payload)
|
|
608
|
+
if reason:
|
|
609
|
+
raise QualityPanelError(f"quality_panel invalid: {reason}")
|
|
610
|
+
panel_sha256 = _normalize_sha256(quality_panel_sha256)
|
|
611
|
+
if not panel_sha256:
|
|
612
|
+
raise QualityPanelError("quality_panel_sha256 must be a SHA-256 hex digest.")
|
|
613
|
+
|
|
614
|
+
source = panel_payload.get("source_evidence")
|
|
615
|
+
source = source if isinstance(source, Mapping) else {}
|
|
616
|
+
gates = panel_payload.get("gates")
|
|
617
|
+
gates = gates if isinstance(gates, Mapping) else {}
|
|
618
|
+
claims = panel_payload.get("claims")
|
|
619
|
+
claims = claims if isinstance(claims, Mapping) else {}
|
|
620
|
+
delivery = panel_payload.get("delivery")
|
|
621
|
+
delivery = delivery if isinstance(delivery, Mapping) else {}
|
|
622
|
+
control = panel_payload.get("control_integrity")
|
|
623
|
+
control = control if isinstance(control, Mapping) else {}
|
|
624
|
+
materiality = panel_payload.get("materiality_selection")
|
|
625
|
+
materiality = materiality if isinstance(materiality, Mapping) else {}
|
|
626
|
+
template_conformance = panel_payload.get("report_template_conformance")
|
|
627
|
+
template_conformance = template_conformance if isinstance(template_conformance, Mapping) else {}
|
|
628
|
+
support_wording = panel_payload.get("support_wording")
|
|
629
|
+
support_wording = support_wording if isinstance(support_wording, Mapping) else {}
|
|
630
|
+
semantic_support = panel_payload.get("semantic_support")
|
|
631
|
+
semantic_support = semantic_support if isinstance(semantic_support, Mapping) else {}
|
|
632
|
+
closeout = panel_payload.get("quality_panel_closeout")
|
|
633
|
+
closeout = closeout if isinstance(closeout, Mapping) else {}
|
|
634
|
+
actions = panel_payload.get("recommended_actions")
|
|
635
|
+
actions = actions if isinstance(actions, list) else []
|
|
636
|
+
overall_status = _text(panel_payload.get("overall_status")) or "unknown"
|
|
637
|
+
|
|
638
|
+
body = "\n".join(
|
|
639
|
+
[
|
|
640
|
+
_html_header_card(panel_payload, overall_status=overall_status),
|
|
641
|
+
_html_metrics_grid(
|
|
642
|
+
[
|
|
643
|
+
("gate_blockers", _intish(gates.get("blocking_count")), "block"),
|
|
644
|
+
("gate_warnings", _intish(gates.get("warning_count")), "warning"),
|
|
645
|
+
(
|
|
646
|
+
"missing_incomplete",
|
|
647
|
+
_quality_panel_incomplete_count(control, source, gates, delivery),
|
|
648
|
+
"incomplete",
|
|
649
|
+
),
|
|
650
|
+
(
|
|
651
|
+
"materiality_findings",
|
|
652
|
+
_materiality_selection_warning_count(materiality),
|
|
653
|
+
"warning",
|
|
654
|
+
),
|
|
655
|
+
(
|
|
656
|
+
"template_warnings",
|
|
657
|
+
_template_conformance_warning_count(template_conformance),
|
|
658
|
+
"warning",
|
|
659
|
+
),
|
|
660
|
+
(
|
|
661
|
+
"support_wording",
|
|
662
|
+
_support_wording_warning_count(support_wording),
|
|
663
|
+
"warning",
|
|
664
|
+
),
|
|
665
|
+
(
|
|
666
|
+
"semantic_support_proposals",
|
|
667
|
+
_intish(semantic_support.get("proposal_count")),
|
|
668
|
+
"warning",
|
|
669
|
+
),
|
|
670
|
+
("recommended_actions", len(actions), "action"),
|
|
671
|
+
]
|
|
672
|
+
),
|
|
673
|
+
_html_section(
|
|
674
|
+
"control-integrity",
|
|
675
|
+
"control_integrity",
|
|
676
|
+
[
|
|
677
|
+
("run_integrity", _text(control.get("run_integrity")) or "unknown", "status"),
|
|
678
|
+
(
|
|
679
|
+
"reference_eligible",
|
|
680
|
+
str(bool(control.get("reference_eligible"))).lower(),
|
|
681
|
+
"status",
|
|
682
|
+
),
|
|
683
|
+
("fact_layer", _text(control.get("fact_layer_status")) or "unknown", "status"),
|
|
684
|
+
(
|
|
685
|
+
"runtime_effect",
|
|
686
|
+
_text(panel_payload.get("runtime_effect")) or "unknown",
|
|
687
|
+
"status",
|
|
688
|
+
),
|
|
689
|
+
],
|
|
690
|
+
),
|
|
691
|
+
_html_section(
|
|
692
|
+
"source-evidence",
|
|
693
|
+
"source_evidence",
|
|
694
|
+
[
|
|
695
|
+
("source_pack", _text(source.get("source_pack_status")) or "unknown", "status"),
|
|
696
|
+
("durable_sources", _intish(source.get("source_count")), "count_neutral"),
|
|
697
|
+
("missing_titles", _intish(source.get("missing_title_count")), "count_warning"),
|
|
698
|
+
(
|
|
699
|
+
"missing_publishers",
|
|
700
|
+
_intish(source.get("missing_publisher_count")),
|
|
701
|
+
"count_warning",
|
|
702
|
+
),
|
|
703
|
+
(
|
|
704
|
+
"retrieval_source_mix",
|
|
705
|
+
_inline_mapping(source.get("retrieval_source_mix")),
|
|
706
|
+
"text",
|
|
707
|
+
),
|
|
708
|
+
(
|
|
709
|
+
"underlying_evidence_mix",
|
|
710
|
+
_inline_mapping(source.get("underlying_evidence_mix")),
|
|
711
|
+
"text",
|
|
712
|
+
),
|
|
713
|
+
],
|
|
714
|
+
),
|
|
715
|
+
_html_section(
|
|
716
|
+
"gate-findings",
|
|
717
|
+
"gate_findings",
|
|
718
|
+
[
|
|
719
|
+
("auditor_gate", _text(gates.get("auditor_status")) or "unknown", "status"),
|
|
720
|
+
("finalize_gate", _text(gates.get("finalize_status")) or "unknown", "status"),
|
|
721
|
+
(
|
|
722
|
+
"legacy_latest_gate",
|
|
723
|
+
_text(gates.get("legacy_quality_gate_status")) or "missing",
|
|
724
|
+
"status",
|
|
725
|
+
),
|
|
726
|
+
("blocking_findings", _intish(gates.get("blocking_count")), "count_block"),
|
|
727
|
+
("warning_findings", _intish(gates.get("warning_count")), "count_warning"),
|
|
728
|
+
],
|
|
729
|
+
),
|
|
730
|
+
_html_section(
|
|
731
|
+
"claim-support-risk",
|
|
732
|
+
"claim_support_risk",
|
|
733
|
+
[
|
|
734
|
+
("claim_count", _intish(claims.get("claim_count")), "count_neutral"),
|
|
735
|
+
(
|
|
736
|
+
"claim_support_matrix",
|
|
737
|
+
_text(claims.get("claim_support_matrix_status")) or "unknown",
|
|
738
|
+
"status",
|
|
739
|
+
),
|
|
740
|
+
(
|
|
741
|
+
"unsupported_rows",
|
|
742
|
+
_intish(claims.get("unsupported_count")),
|
|
743
|
+
"count_block",
|
|
744
|
+
),
|
|
745
|
+
(
|
|
746
|
+
"weak_support_atoms",
|
|
747
|
+
_intish(claims.get("weak_support_count")),
|
|
748
|
+
"count_warning",
|
|
749
|
+
),
|
|
750
|
+
(
|
|
751
|
+
"materiality_selection",
|
|
752
|
+
_text(materiality.get("status")) or "unknown",
|
|
753
|
+
"status",
|
|
754
|
+
),
|
|
755
|
+
(
|
|
756
|
+
"materiality_exclusions",
|
|
757
|
+
_materiality_selection_warning_count(materiality),
|
|
758
|
+
"count_warning",
|
|
759
|
+
),
|
|
760
|
+
(
|
|
761
|
+
"reader_template_conformance",
|
|
762
|
+
_text(template_conformance.get("status")) or "unknown",
|
|
763
|
+
"status",
|
|
764
|
+
),
|
|
765
|
+
(
|
|
766
|
+
"reader_template_warnings",
|
|
767
|
+
_template_conformance_warning_count(template_conformance),
|
|
768
|
+
"count_warning",
|
|
769
|
+
),
|
|
770
|
+
(
|
|
771
|
+
"support_wording",
|
|
772
|
+
_text(support_wording.get("status")) or "unknown",
|
|
773
|
+
"status",
|
|
774
|
+
),
|
|
775
|
+
(
|
|
776
|
+
"support_wording_warnings",
|
|
777
|
+
_support_wording_warning_count(support_wording),
|
|
778
|
+
"count_warning",
|
|
779
|
+
),
|
|
780
|
+
(
|
|
781
|
+
"semantic_support_status",
|
|
782
|
+
_text(semantic_support.get("status")) or "not_available",
|
|
783
|
+
"status",
|
|
784
|
+
),
|
|
785
|
+
(
|
|
786
|
+
"semantic_support_boundary",
|
|
787
|
+
_text(semantic_support.get("boundary")) or "unknown",
|
|
788
|
+
"status",
|
|
789
|
+
),
|
|
790
|
+
(
|
|
791
|
+
"semantic_support_proposals",
|
|
792
|
+
_intish(semantic_support.get("proposal_count")),
|
|
793
|
+
"count_warning",
|
|
794
|
+
),
|
|
795
|
+
(
|
|
796
|
+
"calibration_labels",
|
|
797
|
+
_inline_mapping(semantic_support.get("calibration_label_counts")),
|
|
798
|
+
"text",
|
|
799
|
+
),
|
|
800
|
+
(
|
|
801
|
+
"llm_only_proposals",
|
|
802
|
+
_intish(semantic_support.get("llm_only_count")),
|
|
803
|
+
"count_warning",
|
|
804
|
+
),
|
|
805
|
+
(
|
|
806
|
+
"high_uncertainty",
|
|
807
|
+
_intish(semantic_support.get("high_uncertainty_count")),
|
|
808
|
+
"count_warning",
|
|
809
|
+
),
|
|
810
|
+
(
|
|
811
|
+
"high_disagreement",
|
|
812
|
+
_intish(semantic_support.get("high_disagreement_count")),
|
|
813
|
+
"count_warning",
|
|
814
|
+
),
|
|
815
|
+
(
|
|
816
|
+
"human_adjudication_required",
|
|
817
|
+
_intish(semantic_support.get("requires_human_adjudication_count")),
|
|
818
|
+
"count_warning",
|
|
819
|
+
),
|
|
820
|
+
],
|
|
821
|
+
),
|
|
822
|
+
_html_section(
|
|
823
|
+
"reader-clean-citation-hygiene",
|
|
824
|
+
"reader_clean_citation",
|
|
825
|
+
[
|
|
826
|
+
(
|
|
827
|
+
"reader_clean_status",
|
|
828
|
+
_text(delivery.get("reader_clean_status")) or "unknown",
|
|
829
|
+
"status",
|
|
830
|
+
),
|
|
831
|
+
(
|
|
832
|
+
"duplicate_citation_count",
|
|
833
|
+
_intish(delivery.get("duplicate_citation_count")),
|
|
834
|
+
"count_warning",
|
|
835
|
+
),
|
|
836
|
+
(
|
|
837
|
+
"source_appendix_warnings",
|
|
838
|
+
_intish(delivery.get("source_appendix_warning_count")),
|
|
839
|
+
"count_warning",
|
|
840
|
+
),
|
|
841
|
+
],
|
|
842
|
+
),
|
|
843
|
+
_html_section(
|
|
844
|
+
"quality-closeout-bundle-separation",
|
|
845
|
+
"quality_closeout_bundle",
|
|
846
|
+
[
|
|
847
|
+
("closeout_status", _text(closeout.get("status")) or "unknown", "status"),
|
|
848
|
+
("closeout_command", _text(closeout.get("command")) or "unknown", "code"),
|
|
849
|
+
("audit_bundle", _text(closeout.get("audit_bundle")) or "unknown", "status"),
|
|
850
|
+
("delivery_bundle", _text(closeout.get("delivery_bundle")) or "unknown", "status"),
|
|
851
|
+
],
|
|
852
|
+
),
|
|
853
|
+
_html_actions(actions),
|
|
854
|
+
]
|
|
855
|
+
)
|
|
856
|
+
|
|
857
|
+
html = (
|
|
858
|
+
"<!doctype html>\n"
|
|
859
|
+
"<html lang=\"en\">\n"
|
|
860
|
+
"<head>\n"
|
|
861
|
+
" <meta charset=\"utf-8\">\n"
|
|
862
|
+
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
|
|
863
|
+
f" <meta name=\"briefloop-boundary\" content=\"{_html(QUALITY_PANEL_HTML_BOUNDARY)}\">\n"
|
|
864
|
+
" <title>BriefLoop Quality Panel</title>\n"
|
|
865
|
+
" <style>\n"
|
|
866
|
+
f"{_quality_panel_css()}\n"
|
|
867
|
+
" </style>\n"
|
|
868
|
+
"</head>\n"
|
|
869
|
+
"<body>\n"
|
|
870
|
+
f"<!-- {_QUALITY_PANEL_SHA_PREFIX}{panel_sha256} -->\n"
|
|
871
|
+
f"<!-- Boundary: {_html(QUALITY_PANEL_HTML_BOUNDARY)} -->\n"
|
|
872
|
+
"<input class=\"language-radio\" id=\"lang-en\" name=\"qp-lang\" type=\"radio\" checked>\n"
|
|
873
|
+
"<input class=\"language-radio\" id=\"lang-zh\" name=\"qp-lang\" type=\"radio\">\n"
|
|
874
|
+
"<div class=\"language-toggle\" aria-label=\"Language\">\n"
|
|
875
|
+
" <label for=\"lang-en\">English</label>\n"
|
|
876
|
+
" <label for=\"lang-zh\">中文</label>\n"
|
|
877
|
+
"</div>\n"
|
|
878
|
+
"<main class=\"quality-panel\">\n"
|
|
879
|
+
f"{body}\n"
|
|
880
|
+
"</main>\n"
|
|
881
|
+
"</body>\n"
|
|
882
|
+
"</html>\n"
|
|
883
|
+
)
|
|
884
|
+
reason = validate_quality_panel_html(html)
|
|
885
|
+
if reason:
|
|
886
|
+
raise QualityPanelError(f"quality_panel_html invalid: {reason}")
|
|
887
|
+
return html
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
def write_quality_panel_html(
|
|
891
|
+
*,
|
|
892
|
+
workspace: str | Path,
|
|
893
|
+
output_path: str | Path | None = None,
|
|
894
|
+
panel_payload: Mapping[str, Any] | None = None,
|
|
895
|
+
) -> dict[str, Any]:
|
|
896
|
+
ws = Path(workspace).expanduser().resolve()
|
|
897
|
+
panel_path = quality_panel_path(ws)
|
|
898
|
+
source_panel_payload = _read_json_mapping(panel_path)
|
|
899
|
+
if source_panel_payload is None:
|
|
900
|
+
raise QualityPanelError("quality_panel.json is required before writing quality_panel.html.")
|
|
901
|
+
if panel_payload is None:
|
|
902
|
+
panel_payload = source_panel_payload
|
|
903
|
+
elif dict(panel_payload) != source_panel_payload:
|
|
904
|
+
raise QualityPanelError("panel_payload must match quality_panel.json before writing quality_panel.html.")
|
|
905
|
+
text = render_quality_panel_html(panel_payload, quality_panel_sha256=_sha256_file(panel_path))
|
|
906
|
+
target = Path(output_path).expanduser() if output_path else quality_panel_html_path(ws)
|
|
907
|
+
if not target.is_absolute():
|
|
908
|
+
target = ws / target
|
|
909
|
+
target = target.resolve()
|
|
910
|
+
try:
|
|
911
|
+
target.relative_to(ws)
|
|
912
|
+
except ValueError as exc:
|
|
913
|
+
raise ValueError("quality_panel_html output must stay inside the workspace.") from exc
|
|
914
|
+
_write_text_atomic(target, text)
|
|
915
|
+
return {
|
|
916
|
+
"path": _workspace_relative(ws, target),
|
|
917
|
+
"sha256": _sha256_text(text),
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
def validate_quality_panel_payload(payload: Any) -> str | None:
|
|
922
|
+
if not isinstance(payload, dict):
|
|
923
|
+
return "quality_panel_schema_error:not_object"
|
|
924
|
+
if payload.get("schema_version") != QUALITY_PANEL_SCHEMA_VERSION:
|
|
925
|
+
return "quality_panel_schema_error:schema_version"
|
|
926
|
+
if payload.get("boundary") != QUALITY_PANEL_BOUNDARY:
|
|
927
|
+
return "quality_panel_schema_error:boundary"
|
|
928
|
+
if payload.get("runtime_effect") != QUALITY_PANEL_RUNTIME_EFFECT:
|
|
929
|
+
return "quality_panel_schema_error:runtime_effect"
|
|
930
|
+
if payload.get("workspace") != ".":
|
|
931
|
+
return "quality_panel_schema_error:workspace"
|
|
932
|
+
if not _text(payload.get("run_id")):
|
|
933
|
+
return "quality_panel_schema_error:run_id"
|
|
934
|
+
if payload.get("overall_status") not in {"pass", "warning", "block", "incomplete"}:
|
|
935
|
+
return "quality_panel_schema_error:overall_status"
|
|
936
|
+
for field in ("control_integrity", "source_evidence", "gates", "claims", "delivery"):
|
|
937
|
+
if not isinstance(payload.get(field), dict):
|
|
938
|
+
return f"quality_panel_schema_error:{field}"
|
|
939
|
+
trajectory = payload.get("trajectory_regulation")
|
|
940
|
+
if trajectory is not None:
|
|
941
|
+
if not isinstance(trajectory, dict):
|
|
942
|
+
return "quality_panel_schema_error:trajectory_regulation"
|
|
943
|
+
trajectory_error = validate_trajectory_regulation_payload(trajectory)
|
|
944
|
+
if trajectory_error:
|
|
945
|
+
return f"quality_panel_schema_error:trajectory_regulation:{trajectory_error}"
|
|
946
|
+
guidance = payload.get("guidance_manifestation")
|
|
947
|
+
if guidance is not None:
|
|
948
|
+
if not isinstance(guidance, dict):
|
|
949
|
+
return "quality_panel_schema_error:guidance_manifestation"
|
|
950
|
+
guidance_error = validate_guidance_manifestation_projection_payload(guidance)
|
|
951
|
+
if guidance_error:
|
|
952
|
+
return f"quality_panel_schema_error:guidance_manifestation:{guidance_error}"
|
|
953
|
+
materiality = payload.get("materiality_selection")
|
|
954
|
+
if materiality is not None:
|
|
955
|
+
if not isinstance(materiality, dict):
|
|
956
|
+
return "quality_panel_schema_error:materiality_selection"
|
|
957
|
+
materiality_error = validate_materiality_selection_payload(materiality)
|
|
958
|
+
if materiality_error:
|
|
959
|
+
return f"quality_panel_schema_error:materiality_selection:{materiality_error}"
|
|
960
|
+
template_conformance = payload.get("report_template_conformance")
|
|
961
|
+
if template_conformance is not None:
|
|
962
|
+
if not isinstance(template_conformance, dict):
|
|
963
|
+
return "quality_panel_schema_error:report_template_conformance"
|
|
964
|
+
template_error = validate_report_template_conformance_payload(template_conformance)
|
|
965
|
+
if template_error:
|
|
966
|
+
return f"quality_panel_schema_error:report_template_conformance:{template_error}"
|
|
967
|
+
support_wording = payload.get("support_wording")
|
|
968
|
+
if support_wording is not None:
|
|
969
|
+
if not isinstance(support_wording, dict):
|
|
970
|
+
return "quality_panel_schema_error:support_wording"
|
|
971
|
+
support_wording_error = validate_support_wording_payload(support_wording)
|
|
972
|
+
if support_wording_error:
|
|
973
|
+
return f"quality_panel_schema_error:support_wording:{support_wording_error}"
|
|
974
|
+
semantic_support = payload.get("semantic_support")
|
|
975
|
+
if semantic_support is not None:
|
|
976
|
+
if not isinstance(semantic_support, dict):
|
|
977
|
+
return "quality_panel_schema_error:semantic_support"
|
|
978
|
+
semantic_support_error = _validate_semantic_support_payload(semantic_support)
|
|
979
|
+
if semantic_support_error:
|
|
980
|
+
return f"quality_panel_schema_error:semantic_support:{semantic_support_error}"
|
|
981
|
+
closeout = payload.get("quality_panel_closeout")
|
|
982
|
+
if closeout is not None:
|
|
983
|
+
if not isinstance(closeout, dict):
|
|
984
|
+
return "quality_panel_schema_error:quality_panel_closeout"
|
|
985
|
+
closeout_error = validate_quality_panel_closeout_payload(closeout)
|
|
986
|
+
if closeout_error:
|
|
987
|
+
return f"quality_panel_schema_error:quality_panel_closeout:{closeout_error}"
|
|
988
|
+
recommended_actions = payload.get("recommended_actions")
|
|
989
|
+
if not isinstance(recommended_actions, list):
|
|
990
|
+
return "quality_panel_schema_error:recommended_actions"
|
|
991
|
+
for item in recommended_actions:
|
|
992
|
+
if not isinstance(item, dict):
|
|
993
|
+
return "quality_panel_schema_error:recommended_actions"
|
|
994
|
+
if _text(item.get("action")) not in _QUALITY_PANEL_RECOMMENDED_ACTIONS:
|
|
995
|
+
return "quality_panel_schema_error:recommended_actions.action"
|
|
996
|
+
if not isinstance(payload.get("non_goals"), list):
|
|
997
|
+
return "quality_panel_schema_error:non_goals"
|
|
998
|
+
forbidden = {"semantic_truth_proof", "release_eligibility_decision", "delivery_approval"}
|
|
999
|
+
if not forbidden.issubset(set(str(item) for item in payload.get("non_goals", []))):
|
|
1000
|
+
return "quality_panel_schema_error:non_goals"
|
|
1001
|
+
return None
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
def validate_quality_summary_markdown(text: Any) -> str | None:
|
|
1005
|
+
if not isinstance(text, str):
|
|
1006
|
+
return "quality_summary_schema_error:not_text"
|
|
1007
|
+
if not text.strip():
|
|
1008
|
+
return "quality_summary_schema_error:empty"
|
|
1009
|
+
if not text.startswith("# Quality Summary\n"):
|
|
1010
|
+
return "quality_summary_schema_error:title"
|
|
1011
|
+
if f"Boundary: {QUALITY_SUMMARY_BOUNDARY}." not in text:
|
|
1012
|
+
return "quality_summary_schema_error:boundary"
|
|
1013
|
+
panel_sha = quality_summary_panel_sha256(text)
|
|
1014
|
+
if not panel_sha:
|
|
1015
|
+
return "quality_summary_schema_error:quality_panel_sha256"
|
|
1016
|
+
lower = text.lower()
|
|
1017
|
+
for phrase in _QUALITY_SUMMARY_FORBIDDEN_PHRASES:
|
|
1018
|
+
if phrase in lower:
|
|
1019
|
+
return f"quality_summary_schema_error:forbidden_phrase:{phrase.replace(' ', '_')}"
|
|
1020
|
+
required_sections = (
|
|
1021
|
+
"## Overall",
|
|
1022
|
+
"## Blocking Issues",
|
|
1023
|
+
"## Warnings",
|
|
1024
|
+
"## Missing Or Incomplete Surfaces",
|
|
1025
|
+
"## Source Evidence",
|
|
1026
|
+
"## Gates And Reader Clean",
|
|
1027
|
+
"## Claims And Support Records",
|
|
1028
|
+
"## Recommended Next Actions",
|
|
1029
|
+
)
|
|
1030
|
+
for section in required_sections:
|
|
1031
|
+
if section not in text:
|
|
1032
|
+
return f"quality_summary_schema_error:missing_section:{section[3:].lower().replace(' ', '_')}"
|
|
1033
|
+
return None
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
def validate_quality_panel_html(text: Any) -> str | None:
|
|
1037
|
+
if not isinstance(text, str):
|
|
1038
|
+
return "quality_panel_html_schema_error:not_text"
|
|
1039
|
+
if not text.strip():
|
|
1040
|
+
return "quality_panel_html_schema_error:empty"
|
|
1041
|
+
if not text.startswith("<!doctype html>\n"):
|
|
1042
|
+
return "quality_panel_html_schema_error:doctype"
|
|
1043
|
+
if QUALITY_PANEL_HTML_BOUNDARY not in text:
|
|
1044
|
+
return "quality_panel_html_schema_error:boundary"
|
|
1045
|
+
panel_sha = quality_panel_html_panel_sha256(text)
|
|
1046
|
+
if not panel_sha:
|
|
1047
|
+
return "quality_panel_html_schema_error:quality_panel_sha256"
|
|
1048
|
+
lower = text.lower()
|
|
1049
|
+
for marker in _QUALITY_PANEL_HTML_FORBIDDEN_MARKERS:
|
|
1050
|
+
if marker in lower:
|
|
1051
|
+
return f"quality_panel_html_schema_error:external_or_active_content:{marker.strip('<>= ')}"
|
|
1052
|
+
required_language_toggle = (
|
|
1053
|
+
'id="lang-en"',
|
|
1054
|
+
'id="lang-zh"',
|
|
1055
|
+
'for="lang-en">English</label>',
|
|
1056
|
+
'for="lang-zh">中文</label>',
|
|
1057
|
+
'class="lang-en"',
|
|
1058
|
+
'class="lang-zh"',
|
|
1059
|
+
)
|
|
1060
|
+
for fragment in required_language_toggle:
|
|
1061
|
+
if fragment not in text:
|
|
1062
|
+
return f"quality_panel_html_schema_error:missing_language_toggle:{fragment}"
|
|
1063
|
+
required_sections = (
|
|
1064
|
+
'data-section="control-integrity"',
|
|
1065
|
+
'data-section="source-evidence"',
|
|
1066
|
+
'data-section="gate-findings"',
|
|
1067
|
+
'data-section="claim-support-risk"',
|
|
1068
|
+
'data-section="reader-clean-citation-hygiene"',
|
|
1069
|
+
'data-section="quality-closeout-bundle-separation"',
|
|
1070
|
+
'data-section="recommended-next-actions"',
|
|
1071
|
+
)
|
|
1072
|
+
for section in required_sections:
|
|
1073
|
+
if section not in text:
|
|
1074
|
+
return f"quality_panel_html_schema_error:missing_section:{section}"
|
|
1075
|
+
return None
|
|
1076
|
+
|
|
1077
|
+
|
|
1078
|
+
def quality_summary_panel_sha256(text: str) -> str | None:
|
|
1079
|
+
for line in text.splitlines():
|
|
1080
|
+
if line.startswith(_QUALITY_PANEL_SHA_PREFIX):
|
|
1081
|
+
return _normalize_sha256(line.removeprefix(_QUALITY_PANEL_SHA_PREFIX).strip())
|
|
1082
|
+
return None
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
def quality_panel_html_panel_sha256(text: str) -> str | None:
|
|
1086
|
+
for line in text.splitlines():
|
|
1087
|
+
if _QUALITY_PANEL_SHA_PREFIX not in line:
|
|
1088
|
+
continue
|
|
1089
|
+
value = line.split(_QUALITY_PANEL_SHA_PREFIX, 1)[1]
|
|
1090
|
+
value = value.split("-->", 1)[0].strip()
|
|
1091
|
+
return _normalize_sha256(value)
|
|
1092
|
+
return None
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
def _source_evidence_summary(workspace: Path, artifacts: Mapping[str, Any]) -> dict[str, Any]:
|
|
1096
|
+
record = _artifact_record(artifacts, "source_evidence_pack_manifest")
|
|
1097
|
+
source_pack_status = _source_pack_status(record)
|
|
1098
|
+
if source_pack_status == "present":
|
|
1099
|
+
manifest = _read_json_mapping(workspace / _INTERMEDIATE / "source_evidence_pack_manifest.json") or {}
|
|
1100
|
+
else:
|
|
1101
|
+
manifest = {}
|
|
1102
|
+
records = manifest.get("records") if isinstance(manifest, dict) else []
|
|
1103
|
+
records = records if isinstance(records, list) else []
|
|
1104
|
+
retrieval_mix: Counter[str] = Counter()
|
|
1105
|
+
underlying_mix: Counter[str] = Counter()
|
|
1106
|
+
missing_title_count = 0
|
|
1107
|
+
missing_publisher_count = 0
|
|
1108
|
+
usable_records = 0
|
|
1109
|
+
for item in records:
|
|
1110
|
+
if not isinstance(item, dict):
|
|
1111
|
+
continue
|
|
1112
|
+
usable_records += 1
|
|
1113
|
+
title = _first_text(item, "source_title", "title", "source_name")
|
|
1114
|
+
publisher = _first_text(item, "publisher", "publisher_or_institution", "source_name")
|
|
1115
|
+
if not title:
|
|
1116
|
+
missing_title_count += 1
|
|
1117
|
+
if not publisher:
|
|
1118
|
+
missing_publisher_count += 1
|
|
1119
|
+
retrieval_mix[_first_text(item, "retrieval_source_type") or "unknown"] += 1
|
|
1120
|
+
underlying_mix[_first_text(item, "underlying_evidence_type", "source_category") or "unknown"] += 1
|
|
1121
|
+
return {
|
|
1122
|
+
"source_pack_status": source_pack_status,
|
|
1123
|
+
"source_count": int(manifest.get("record_count") or usable_records or 0)
|
|
1124
|
+
if isinstance(manifest, dict)
|
|
1125
|
+
else 0,
|
|
1126
|
+
"missing_title_count": missing_title_count,
|
|
1127
|
+
"missing_publisher_count": missing_publisher_count,
|
|
1128
|
+
"retrieval_source_mix": dict(sorted(retrieval_mix.items())),
|
|
1129
|
+
"underlying_evidence_mix": dict(sorted(underlying_mix.items())),
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
def _gate_summary(workspace: Path) -> dict[str, Any]:
|
|
1134
|
+
auditor = _gate_file_summary(workspace / _INTERMEDIATE / "gates" / "auditor_quality_gate_report.json")
|
|
1135
|
+
finalize = _gate_file_summary(workspace / _INTERMEDIATE / "gates" / "finalize_quality_gate_report.json")
|
|
1136
|
+
legacy = _gate_file_summary(workspace / _INTERMEDIATE / "quality_gate_report.json")
|
|
1137
|
+
return {
|
|
1138
|
+
"auditor_status": auditor["status"],
|
|
1139
|
+
"finalize_status": finalize["status"],
|
|
1140
|
+
"auditor_report_status": _scoped_gate_report_status(auditor),
|
|
1141
|
+
"finalize_report_status": _scoped_gate_report_status(finalize),
|
|
1142
|
+
"legacy_quality_gate_present": legacy["present"],
|
|
1143
|
+
"legacy_quality_gate_status": legacy["status"],
|
|
1144
|
+
"legacy_quality_gate_stage": legacy["stage"],
|
|
1145
|
+
"blocking_count": auditor["blocking_count"] + finalize["blocking_count"],
|
|
1146
|
+
"warning_count": auditor["warning_count"] + finalize["warning_count"],
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
|
|
1150
|
+
def _gate_file_summary(path: Path) -> dict[str, bool | int | str]:
|
|
1151
|
+
payload = _read_json_mapping(path)
|
|
1152
|
+
if payload is None:
|
|
1153
|
+
return {
|
|
1154
|
+
"present": False,
|
|
1155
|
+
"status": "missing",
|
|
1156
|
+
"stage": "",
|
|
1157
|
+
"blocking_count": 0,
|
|
1158
|
+
"warning_count": 0,
|
|
1159
|
+
}
|
|
1160
|
+
findings = payload.get("findings") if isinstance(payload.get("findings"), list) else []
|
|
1161
|
+
blocking = 0
|
|
1162
|
+
warning = 0
|
|
1163
|
+
for finding in findings:
|
|
1164
|
+
if not isinstance(finding, dict):
|
|
1165
|
+
continue
|
|
1166
|
+
if finding.get("blocking") is True or finding.get("blocking_level") == "blocking":
|
|
1167
|
+
blocking += 1
|
|
1168
|
+
else:
|
|
1169
|
+
warning += 1
|
|
1170
|
+
metadata = payload.get("metadata") if isinstance(payload.get("metadata"), Mapping) else {}
|
|
1171
|
+
status = _text(payload.get("status")) or "unknown"
|
|
1172
|
+
stage = _text(metadata.get("gate_stage_id")) or _text(payload.get("stage")) or _text(payload.get("gate_stage"))
|
|
1173
|
+
return {
|
|
1174
|
+
"present": True,
|
|
1175
|
+
"status": status,
|
|
1176
|
+
"stage": stage,
|
|
1177
|
+
"blocking_count": blocking,
|
|
1178
|
+
"warning_count": warning,
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
def _scoped_gate_report_status(summary: Mapping[str, Any]) -> str:
|
|
1183
|
+
return "present" if summary.get("present") is True else "missing_scoped_report"
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
def _claim_summary(
|
|
1187
|
+
workspace: Path,
|
|
1188
|
+
workspace_status: Mapping[str, Any],
|
|
1189
|
+
artifacts: Mapping[str, Any],
|
|
1190
|
+
) -> dict[str, Any]:
|
|
1191
|
+
matrix = workspace_status.get("claim_support_matrix")
|
|
1192
|
+
matrix = matrix if isinstance(matrix, dict) else {}
|
|
1193
|
+
matrix_status = _optional_artifact_status(
|
|
1194
|
+
_artifact_record(artifacts, "claim_support_matrix"),
|
|
1195
|
+
not_available="not_available",
|
|
1196
|
+
)
|
|
1197
|
+
counts = (
|
|
1198
|
+
matrix.get("summary_counts")
|
|
1199
|
+
if matrix_status == "valid" and isinstance(matrix.get("summary_counts"), dict)
|
|
1200
|
+
else {}
|
|
1201
|
+
)
|
|
1202
|
+
rows = _matrix_rows(workspace) if matrix_status == "valid" else []
|
|
1203
|
+
return {
|
|
1204
|
+
"claim_count": _claim_count(workspace / _INTERMEDIATE / "claim_ledger.json"),
|
|
1205
|
+
"claim_support_matrix_status": matrix_status,
|
|
1206
|
+
"weak_support_count": int(counts.get("weak_atom_count") or 0),
|
|
1207
|
+
"unsupported_count": sum(
|
|
1208
|
+
1
|
|
1209
|
+
for row in rows
|
|
1210
|
+
if isinstance(row, dict) and _text(row.get("support_label")) in _BLOCKING_SUPPORT_LABELS
|
|
1211
|
+
),
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
def _semantic_support_summary(workspace_status: Mapping[str, Any]) -> dict[str, Any]:
|
|
1216
|
+
"""Project the optional Semantic Support Auditor proposals for the panel.
|
|
1217
|
+
|
|
1218
|
+
Read-only and proposal-only: this surfaces counts and a human-review hint,
|
|
1219
|
+
but it is not a gate, not a repair route, and not a release authority.
|
|
1220
|
+
"""
|
|
1221
|
+
|
|
1222
|
+
semantic = workspace_status.get("semantic_assessment_report")
|
|
1223
|
+
semantic = semantic if isinstance(semantic, Mapping) else {}
|
|
1224
|
+
counts = semantic.get("summary_counts")
|
|
1225
|
+
counts = counts if isinstance(counts, Mapping) else {}
|
|
1226
|
+
label_counts = counts.get("calibration_label_counts")
|
|
1227
|
+
label_counts = label_counts if isinstance(label_counts, Mapping) else {}
|
|
1228
|
+
adjudication = int(counts.get("requires_human_adjudication_count") or 0)
|
|
1229
|
+
return {
|
|
1230
|
+
"status": _text(semantic.get("status")) or "not_available",
|
|
1231
|
+
"boundary": "proposal_only_not_a_gate_not_release_authority",
|
|
1232
|
+
"proposal_count": int(counts.get("proposal_row_count") or 0),
|
|
1233
|
+
"calibration_label_counts": dict(label_counts),
|
|
1234
|
+
"llm_only_count": int(counts.get("llm_only_count") or 0),
|
|
1235
|
+
"high_uncertainty_count": int(counts.get("high_uncertainty_count") or 0),
|
|
1236
|
+
"high_disagreement_count": int(counts.get("high_disagreement_count") or 0),
|
|
1237
|
+
"requires_human_adjudication_count": adjudication,
|
|
1238
|
+
"recommended_human_review": adjudication > 0,
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
def _delivery_summary(workspace: Path, workspace_status: Mapping[str, Any]) -> dict[str, Any]:
|
|
1243
|
+
reader = workspace_status.get("reader_clean")
|
|
1244
|
+
reader = reader if isinstance(reader, dict) else {}
|
|
1245
|
+
finalize_report = _read_json_mapping(workspace / _INTERMEDIATE / "finalize_report.json") or {}
|
|
1246
|
+
source_warnings = finalize_report.get("source_appendix_warnings")
|
|
1247
|
+
trace_warnings = finalize_report.get("source_appendix_trace_warnings")
|
|
1248
|
+
source_warning_count = len(source_warnings) if isinstance(source_warnings, list) else 0
|
|
1249
|
+
trace_warning_count = len(trace_warnings) if isinstance(trace_warnings, list) else 0
|
|
1250
|
+
return {
|
|
1251
|
+
"reader_clean_status": reader.get("status") or "missing",
|
|
1252
|
+
"duplicate_citation_count": int(finalize_report.get("duplicate_citation_count") or 0)
|
|
1253
|
+
if isinstance(finalize_report, dict)
|
|
1254
|
+
else 0,
|
|
1255
|
+
"source_appendix_warning_count": source_warning_count + trace_warning_count,
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
def _overall_status(
|
|
1260
|
+
*,
|
|
1261
|
+
workspace_status: Mapping[str, Any],
|
|
1262
|
+
workflow: Mapping[str, Any],
|
|
1263
|
+
control_integrity: Mapping[str, Any],
|
|
1264
|
+
source_evidence: Mapping[str, Any],
|
|
1265
|
+
gates: Mapping[str, Any],
|
|
1266
|
+
claims: Mapping[str, Any],
|
|
1267
|
+
delivery: Mapping[str, Any],
|
|
1268
|
+
materiality_selection: Mapping[str, Any],
|
|
1269
|
+
report_template_conformance: Mapping[str, Any],
|
|
1270
|
+
support_wording: Mapping[str, Any],
|
|
1271
|
+
semantic_support: Mapping[str, Any],
|
|
1272
|
+
) -> str:
|
|
1273
|
+
if not workspace_status.get("ok"):
|
|
1274
|
+
return "incomplete"
|
|
1275
|
+
auditor_gate_level = _gate_status_level(gates.get("auditor_status"))
|
|
1276
|
+
finalize_gate_level = _gate_status_level(gates.get("finalize_status"))
|
|
1277
|
+
reader_clean_status = _text(delivery.get("reader_clean_status"))
|
|
1278
|
+
if (
|
|
1279
|
+
workflow.get("blocked") or
|
|
1280
|
+
control_integrity.get("run_integrity") not in {"clean", "unknown"}
|
|
1281
|
+
or gates.get("blocking_count", 0) > 0
|
|
1282
|
+
or auditor_gate_level == "block"
|
|
1283
|
+
or finalize_gate_level == "block"
|
|
1284
|
+
or reader_clean_status == "fail"
|
|
1285
|
+
or claims.get("unsupported_count", 0) > 0
|
|
1286
|
+
):
|
|
1287
|
+
return "block"
|
|
1288
|
+
if (
|
|
1289
|
+
control_integrity.get("fact_layer_status") in {"missing", "incomplete"}
|
|
1290
|
+
or source_evidence.get("source_pack_status") in {"missing", "not_available"}
|
|
1291
|
+
or auditor_gate_level in {"missing", "incomplete"}
|
|
1292
|
+
or finalize_gate_level in {"missing", "incomplete"}
|
|
1293
|
+
or reader_clean_status != "pass"
|
|
1294
|
+
):
|
|
1295
|
+
return "incomplete"
|
|
1296
|
+
if (
|
|
1297
|
+
source_evidence.get("source_pack_status") == "invalid"
|
|
1298
|
+
or claims.get("claim_support_matrix_status") == "invalid"
|
|
1299
|
+
or auditor_gate_level == "warning"
|
|
1300
|
+
or finalize_gate_level == "warning"
|
|
1301
|
+
or gates.get("warning_count", 0) > 0
|
|
1302
|
+
or delivery.get("source_appendix_warning_count", 0) > 0
|
|
1303
|
+
or claims.get("weak_support_count", 0) > 0
|
|
1304
|
+
or _materiality_selection_warning_count(materiality_selection) > 0
|
|
1305
|
+
or _template_conformance_warning_count(report_template_conformance) > 0
|
|
1306
|
+
or _support_wording_warning_count(support_wording) > 0
|
|
1307
|
+
or _semantic_support_warning_count(semantic_support) > 0
|
|
1308
|
+
):
|
|
1309
|
+
return "warning"
|
|
1310
|
+
return "pass"
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
def _recommended_actions(
|
|
1314
|
+
*,
|
|
1315
|
+
workflow: Mapping[str, Any],
|
|
1316
|
+
control_integrity: Mapping[str, Any],
|
|
1317
|
+
source_evidence: Mapping[str, Any],
|
|
1318
|
+
gates: Mapping[str, Any],
|
|
1319
|
+
claims: Mapping[str, Any],
|
|
1320
|
+
delivery: Mapping[str, Any],
|
|
1321
|
+
trajectory: Mapping[str, Any],
|
|
1322
|
+
materiality_selection: Mapping[str, Any],
|
|
1323
|
+
report_template_conformance: Mapping[str, Any],
|
|
1324
|
+
support_wording: Mapping[str, Any],
|
|
1325
|
+
semantic_support: Mapping[str, Any],
|
|
1326
|
+
) -> list[dict[str, str]]:
|
|
1327
|
+
actions: list[dict[str, str]] = []
|
|
1328
|
+
if workflow.get("blocked"):
|
|
1329
|
+
actions.append({
|
|
1330
|
+
"action": "inspect_workflow_blocker",
|
|
1331
|
+
"reason": _text(workflow.get("blocking_reason")) or "workflow_blocked",
|
|
1332
|
+
})
|
|
1333
|
+
if source_evidence.get("source_pack_status") in {"missing", "not_available"}:
|
|
1334
|
+
actions.append({
|
|
1335
|
+
"action": "materialize_durable_source_evidence",
|
|
1336
|
+
"reason": "source_evidence_pack_missing",
|
|
1337
|
+
})
|
|
1338
|
+
elif source_evidence.get("source_pack_status") == "invalid":
|
|
1339
|
+
actions.append({
|
|
1340
|
+
"action": "repair_source_evidence_pack_manifest",
|
|
1341
|
+
"reason": "source_evidence_pack_invalid",
|
|
1342
|
+
})
|
|
1343
|
+
if gates.get("blocking_count", 0) > 0:
|
|
1344
|
+
actions.append({"action": "resolve_quality_gate_blockers", "reason": "blocking_gate_findings"})
|
|
1345
|
+
gate_levels = {
|
|
1346
|
+
"auditor": _gate_status_level(gates.get("auditor_status")),
|
|
1347
|
+
"finalize": _gate_status_level(gates.get("finalize_status")),
|
|
1348
|
+
}
|
|
1349
|
+
failed_gate_stages = [stage for stage, level in gate_levels.items() if level == "block"]
|
|
1350
|
+
if failed_gate_stages and gates.get("blocking_count", 0) == 0:
|
|
1351
|
+
actions.append({
|
|
1352
|
+
"action": "resolve_quality_gate_blockers",
|
|
1353
|
+
"reason": "quality_gate_status_failed",
|
|
1354
|
+
})
|
|
1355
|
+
scoped_reports_missing = any(level in {"missing", "incomplete"} for level in gate_levels.values())
|
|
1356
|
+
reader_clean_missing = _text(delivery.get("reader_clean_status")) in {"", "missing", "unknown", "invalid"}
|
|
1357
|
+
if scoped_reports_missing and not reader_clean_missing:
|
|
1358
|
+
actions.append({
|
|
1359
|
+
"action": "regenerate_scoped_gate_reports",
|
|
1360
|
+
"reason": "scoped_quality_gate_reports_missing",
|
|
1361
|
+
})
|
|
1362
|
+
elif scoped_reports_missing or reader_clean_missing:
|
|
1363
|
+
actions.append({
|
|
1364
|
+
"action": "complete_finalize_delivery_hygiene",
|
|
1365
|
+
"reason": "finalize_or_reader_clean_missing",
|
|
1366
|
+
})
|
|
1367
|
+
if claims.get("unsupported_count", 0) > 0:
|
|
1368
|
+
actions.append({"action": "review_claim_support_records", "reason": "unsupported_claim_support_rows"})
|
|
1369
|
+
if delivery.get("reader_clean_status") == "fail":
|
|
1370
|
+
actions.append({"action": "repair_reader_final_residue", "reason": "reader_clean_failed"})
|
|
1371
|
+
if control_integrity.get("run_integrity") not in {"clean", "unknown"}:
|
|
1372
|
+
actions.append({"action": "inspect_run_integrity", "reason": "run_integrity_not_clean"})
|
|
1373
|
+
materiality_counts = (
|
|
1374
|
+
materiality_selection.get("summary_counts")
|
|
1375
|
+
if isinstance(materiality_selection.get("summary_counts"), Mapping)
|
|
1376
|
+
else {}
|
|
1377
|
+
)
|
|
1378
|
+
if int(materiality_counts.get("human_review_recommended_count") or 0) > 0:
|
|
1379
|
+
actions.append({
|
|
1380
|
+
"action": "request_human_review",
|
|
1381
|
+
"reason": "materiality_or_focus_candidate_excluded_by_capacity_or_scope",
|
|
1382
|
+
})
|
|
1383
|
+
elif int(materiality_counts.get("finding_count") or 0) > 0:
|
|
1384
|
+
actions.append({
|
|
1385
|
+
"action": "review_materiality_exclusions",
|
|
1386
|
+
"reason": "materiality_or_focus_candidate_deprioritized",
|
|
1387
|
+
})
|
|
1388
|
+
if _template_conformance_warning_count(report_template_conformance) > 0:
|
|
1389
|
+
actions.append({
|
|
1390
|
+
"action": "review_reader_template_conformance",
|
|
1391
|
+
"reason": "reader_template_conformance_warning_only",
|
|
1392
|
+
})
|
|
1393
|
+
support_counts = (
|
|
1394
|
+
support_wording.get("summary_counts")
|
|
1395
|
+
if isinstance(support_wording.get("summary_counts"), Mapping)
|
|
1396
|
+
else {}
|
|
1397
|
+
)
|
|
1398
|
+
if int(support_counts.get("unsupported_reader_claim_count") or 0) > 0:
|
|
1399
|
+
actions.append({
|
|
1400
|
+
"action": "request_human_review",
|
|
1401
|
+
"reason": "unsupported_claim_present_in_reader_text",
|
|
1402
|
+
})
|
|
1403
|
+
elif _support_wording_warning_count(support_wording) > 0:
|
|
1404
|
+
actions.append({
|
|
1405
|
+
"action": "review_support_wording_warnings",
|
|
1406
|
+
"reason": "support_calibrated_wording_warning_only",
|
|
1407
|
+
})
|
|
1408
|
+
if int(semantic_support.get("requires_human_adjudication_count") or 0) > 0:
|
|
1409
|
+
actions.append({
|
|
1410
|
+
"action": "request_human_review",
|
|
1411
|
+
"reason": "semantic_support_human_adjudication_required",
|
|
1412
|
+
})
|
|
1413
|
+
for item in trajectory.get("recommended_actions") or []:
|
|
1414
|
+
if not isinstance(item, Mapping):
|
|
1415
|
+
continue
|
|
1416
|
+
action = _text(item.get("action"))
|
|
1417
|
+
if action not in {"request_human_review", "block_run"}:
|
|
1418
|
+
continue
|
|
1419
|
+
actions.append({
|
|
1420
|
+
"action": action,
|
|
1421
|
+
"reason": _text(item.get("reason")) or "trajectory_regulation",
|
|
1422
|
+
"stage_id": _text(item.get("stage_id")) or "unknown",
|
|
1423
|
+
})
|
|
1424
|
+
return actions[:20]
|
|
1425
|
+
|
|
1426
|
+
|
|
1427
|
+
def _materiality_selection_warning_count(materiality_selection: Mapping[str, Any]) -> int:
|
|
1428
|
+
counts = (
|
|
1429
|
+
materiality_selection.get("summary_counts")
|
|
1430
|
+
if isinstance(materiality_selection.get("summary_counts"), Mapping)
|
|
1431
|
+
else {}
|
|
1432
|
+
)
|
|
1433
|
+
return int(counts.get("finding_count") or 0)
|
|
1434
|
+
|
|
1435
|
+
|
|
1436
|
+
def _template_conformance_warning_count(report_template_conformance: Mapping[str, Any]) -> int:
|
|
1437
|
+
counts = (
|
|
1438
|
+
report_template_conformance.get("summary_counts")
|
|
1439
|
+
if isinstance(report_template_conformance.get("summary_counts"), Mapping)
|
|
1440
|
+
else {}
|
|
1441
|
+
)
|
|
1442
|
+
return (
|
|
1443
|
+
int(counts.get("reader_block_warning_count") or 0)
|
|
1444
|
+
+ int(counts.get("missing_section_count") or 0)
|
|
1445
|
+
+ int(counts.get("out_of_order_section_count") or 0)
|
|
1446
|
+
+ int(counts.get("extra_heading_count") or 0)
|
|
1447
|
+
)
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
def _support_wording_warning_count(support_wording: Mapping[str, Any]) -> int:
|
|
1451
|
+
counts = (
|
|
1452
|
+
support_wording.get("summary_counts")
|
|
1453
|
+
if isinstance(support_wording.get("summary_counts"), Mapping)
|
|
1454
|
+
else {}
|
|
1455
|
+
)
|
|
1456
|
+
return int(counts.get("finding_count") or 0)
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
def _semantic_support_warning_count(semantic_support: Mapping[str, Any]) -> int:
|
|
1460
|
+
if _text(semantic_support.get("status")) in {"invalid_report", "missing_input", "stale"}:
|
|
1461
|
+
return 1
|
|
1462
|
+
return int(semantic_support.get("proposal_count") or 0)
|
|
1463
|
+
|
|
1464
|
+
|
|
1465
|
+
def _validate_semantic_support_payload(payload: Mapping[str, Any]) -> str | None:
|
|
1466
|
+
if payload.get("boundary") != "proposal_only_not_a_gate_not_release_authority":
|
|
1467
|
+
return "semantic_support_schema_error:boundary"
|
|
1468
|
+
forbidden_authority_keys = {
|
|
1469
|
+
"accepted_support_truth",
|
|
1470
|
+
"auto_repair",
|
|
1471
|
+
"delivery_approval",
|
|
1472
|
+
"delivery_authority",
|
|
1473
|
+
"gate_authority",
|
|
1474
|
+
"gate_decision",
|
|
1475
|
+
"release_authority",
|
|
1476
|
+
"repair_execution",
|
|
1477
|
+
"runtime_effect",
|
|
1478
|
+
"state_transition",
|
|
1479
|
+
"writes_claim_support_matrix",
|
|
1480
|
+
}
|
|
1481
|
+
for key in sorted(forbidden_authority_keys):
|
|
1482
|
+
if key in payload:
|
|
1483
|
+
return f"semantic_support_schema_error:{key}"
|
|
1484
|
+
status = _text(payload.get("status"))
|
|
1485
|
+
if status not in SEMANTIC_ASSESSMENT_REPORT_STATUSES:
|
|
1486
|
+
return "semantic_support_schema_error:status"
|
|
1487
|
+
for field in (
|
|
1488
|
+
"proposal_count",
|
|
1489
|
+
"llm_only_count",
|
|
1490
|
+
"high_uncertainty_count",
|
|
1491
|
+
"high_disagreement_count",
|
|
1492
|
+
"requires_human_adjudication_count",
|
|
1493
|
+
):
|
|
1494
|
+
value = payload.get(field)
|
|
1495
|
+
if not isinstance(value, int) or value < 0:
|
|
1496
|
+
return f"semantic_support_schema_error:{field}"
|
|
1497
|
+
labels = payload.get("calibration_label_counts")
|
|
1498
|
+
if not isinstance(labels, dict):
|
|
1499
|
+
return "semantic_support_schema_error:calibration_label_counts"
|
|
1500
|
+
for label, count in labels.items():
|
|
1501
|
+
if not isinstance(label, str) or not isinstance(count, int) or count < 0:
|
|
1502
|
+
return "semantic_support_schema_error:calibration_label_counts"
|
|
1503
|
+
if not isinstance(payload.get("recommended_human_review"), bool):
|
|
1504
|
+
return "semantic_support_schema_error:recommended_human_review"
|
|
1505
|
+
return None
|
|
1506
|
+
|
|
1507
|
+
|
|
1508
|
+
def _fact_layer_status(artifacts: Mapping[str, Any], source_evidence: Mapping[str, Any]) -> str:
|
|
1509
|
+
claim_ledger_status = _optional_artifact_status(_artifact_record(artifacts, "claim_ledger"))
|
|
1510
|
+
source_pack_status = str(source_evidence.get("source_pack_status") or "")
|
|
1511
|
+
if claim_ledger_status == "valid" and source_pack_status == "present":
|
|
1512
|
+
return "complete"
|
|
1513
|
+
if claim_ledger_status in {"missing", "not_available"}:
|
|
1514
|
+
return "missing"
|
|
1515
|
+
return "incomplete"
|
|
1516
|
+
|
|
1517
|
+
|
|
1518
|
+
def _source_pack_status(record: Mapping[str, Any] | None) -> str:
|
|
1519
|
+
status = _optional_artifact_status(record, not_available="not_available")
|
|
1520
|
+
if status == "valid":
|
|
1521
|
+
return "present"
|
|
1522
|
+
if status in {"expected", "missing", "not_available"}:
|
|
1523
|
+
return "missing"
|
|
1524
|
+
if status in {"invalid", "stale"}:
|
|
1525
|
+
return "invalid"
|
|
1526
|
+
return status
|
|
1527
|
+
|
|
1528
|
+
|
|
1529
|
+
def _gate_status_level(value: Any) -> str:
|
|
1530
|
+
status = _text(value)
|
|
1531
|
+
if status == "pass":
|
|
1532
|
+
return "pass"
|
|
1533
|
+
if status in {"fail", "failed", "block", "blocked", "blocking"}:
|
|
1534
|
+
return "block"
|
|
1535
|
+
if status == "warning":
|
|
1536
|
+
return "warning"
|
|
1537
|
+
if status == "missing":
|
|
1538
|
+
return "missing"
|
|
1539
|
+
return "incomplete"
|
|
1540
|
+
|
|
1541
|
+
|
|
1542
|
+
def _optional_artifact_status(
|
|
1543
|
+
record: Mapping[str, Any] | None,
|
|
1544
|
+
*,
|
|
1545
|
+
not_available: str = "not_available",
|
|
1546
|
+
) -> str:
|
|
1547
|
+
if not isinstance(record, Mapping):
|
|
1548
|
+
return not_available
|
|
1549
|
+
status = _text(record.get("status"))
|
|
1550
|
+
return status or not_available
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
def _artifact_record(artifacts: Mapping[str, Any], artifact_id: str) -> Mapping[str, Any] | None:
|
|
1554
|
+
record = artifacts.get(artifact_id)
|
|
1555
|
+
return record if isinstance(record, Mapping) else None
|
|
1556
|
+
|
|
1557
|
+
|
|
1558
|
+
def _claim_count(path: Path) -> int:
|
|
1559
|
+
if not path.exists():
|
|
1560
|
+
return 0
|
|
1561
|
+
try:
|
|
1562
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
1563
|
+
return len(ClaimLedger._claim_items_from_json(payload))
|
|
1564
|
+
except (OSError, json.JSONDecodeError, ValueError):
|
|
1565
|
+
return 0
|
|
1566
|
+
|
|
1567
|
+
|
|
1568
|
+
def _matrix_rows(workspace: Path) -> list[dict[str, Any]]:
|
|
1569
|
+
payload = _read_json_mapping(workspace / _INTERMEDIATE / "claim_support_matrix.json")
|
|
1570
|
+
rows = payload.get("rows") if isinstance(payload, dict) else None
|
|
1571
|
+
return [row for row in rows if isinstance(row, dict)] if isinstance(rows, list) else []
|
|
1572
|
+
|
|
1573
|
+
|
|
1574
|
+
def _quality_summary_blocking_items(
|
|
1575
|
+
control: Mapping[str, Any],
|
|
1576
|
+
gates: Mapping[str, Any],
|
|
1577
|
+
claims: Mapping[str, Any],
|
|
1578
|
+
delivery: Mapping[str, Any],
|
|
1579
|
+
) -> list[str]:
|
|
1580
|
+
items: list[str] = []
|
|
1581
|
+
if _text(control.get("run_integrity")) not in {"", "clean", "unknown"}:
|
|
1582
|
+
items.append(f"Run integrity is `{_text(control.get('run_integrity'))}`.")
|
|
1583
|
+
if _intish(gates.get("blocking_count")) > 0:
|
|
1584
|
+
items.append(f"Quality gates report `{_intish(gates.get('blocking_count'))}` blocking finding(s).")
|
|
1585
|
+
if _gate_status_level(gates.get("auditor_status")) == "block":
|
|
1586
|
+
items.append(f"Auditor gate status is `{_text(gates.get('auditor_status'))}`.")
|
|
1587
|
+
if _gate_status_level(gates.get("finalize_status")) == "block":
|
|
1588
|
+
items.append(f"Finalize gate status is `{_text(gates.get('finalize_status'))}`.")
|
|
1589
|
+
if _text(delivery.get("reader_clean_status")) == "fail":
|
|
1590
|
+
items.append("Reader-clean status is `fail`.")
|
|
1591
|
+
if _intish(claims.get("unsupported_count")) > 0:
|
|
1592
|
+
items.append(
|
|
1593
|
+
"Claim-Support Matrix projection includes "
|
|
1594
|
+
f"`{_intish(claims.get('unsupported_count'))}` unsupported/contradicted/insufficient row(s)."
|
|
1595
|
+
)
|
|
1596
|
+
return items
|
|
1597
|
+
|
|
1598
|
+
|
|
1599
|
+
def _quality_summary_warning_items(
|
|
1600
|
+
source: Mapping[str, Any],
|
|
1601
|
+
gates: Mapping[str, Any],
|
|
1602
|
+
claims: Mapping[str, Any],
|
|
1603
|
+
delivery: Mapping[str, Any],
|
|
1604
|
+
materiality_selection: Mapping[str, Any],
|
|
1605
|
+
report_template_conformance: Mapping[str, Any],
|
|
1606
|
+
support_wording: Mapping[str, Any],
|
|
1607
|
+
semantic_support: Mapping[str, Any],
|
|
1608
|
+
) -> list[str]:
|
|
1609
|
+
items: list[str] = []
|
|
1610
|
+
if _text(source.get("source_pack_status")) == "invalid":
|
|
1611
|
+
items.append("Durable source evidence pack manifest is invalid.")
|
|
1612
|
+
if _intish(gates.get("warning_count")) > 0:
|
|
1613
|
+
items.append(f"Quality gates report `{_intish(gates.get('warning_count'))}` warning finding(s).")
|
|
1614
|
+
if _gate_status_level(gates.get("auditor_status")) == "warning":
|
|
1615
|
+
items.append("Auditor gate status is `warning`.")
|
|
1616
|
+
if _gate_status_level(gates.get("finalize_status")) == "warning":
|
|
1617
|
+
items.append("Finalize gate status is `warning`.")
|
|
1618
|
+
if _text(claims.get("claim_support_matrix_status")) == "invalid":
|
|
1619
|
+
items.append("Claim-Support Matrix is invalid and is not interpreted as support authority.")
|
|
1620
|
+
if _intish(claims.get("weak_support_count")) > 0:
|
|
1621
|
+
items.append(f"`{_intish(claims.get('weak_support_count'))}` atom(s) have weak-support projection.")
|
|
1622
|
+
if _intish(delivery.get("source_appendix_warning_count")) > 0:
|
|
1623
|
+
items.append(
|
|
1624
|
+
f"Source appendix surfaces `{_intish(delivery.get('source_appendix_warning_count'))}` warning(s)."
|
|
1625
|
+
)
|
|
1626
|
+
if _materiality_selection_warning_count(materiality_selection) > 0:
|
|
1627
|
+
items.append(
|
|
1628
|
+
"Materiality selection projection found "
|
|
1629
|
+
f"`{_materiality_selection_warning_count(materiality_selection)}` "
|
|
1630
|
+
"excluded/deprioritized candidate(s) matching explicit materiality or focus terms."
|
|
1631
|
+
)
|
|
1632
|
+
if _template_conformance_warning_count(report_template_conformance) > 0:
|
|
1633
|
+
items.append(
|
|
1634
|
+
"Reader template conformance projection found "
|
|
1635
|
+
f"`{_template_conformance_warning_count(report_template_conformance)}` warning(s)."
|
|
1636
|
+
)
|
|
1637
|
+
if _support_wording_warning_count(support_wording) > 0:
|
|
1638
|
+
items.append(
|
|
1639
|
+
"Support-calibrated wording projection found "
|
|
1640
|
+
f"`{_support_wording_warning_count(support_wording)}` reader wording warning(s)."
|
|
1641
|
+
)
|
|
1642
|
+
if _text(semantic_support.get("status")) == "invalid_report":
|
|
1643
|
+
items.append("Semantic support proposal report is invalid and is not interpreted as authority.")
|
|
1644
|
+
elif _semantic_support_warning_count(semantic_support) > 0:
|
|
1645
|
+
items.append(
|
|
1646
|
+
"Semantic support auditor surfaced "
|
|
1647
|
+
f"`{_semantic_support_warning_count(semantic_support)}` proposal(s) "
|
|
1648
|
+
"(`proposal-only`, not a gate, not release authority)."
|
|
1649
|
+
)
|
|
1650
|
+
return items
|
|
1651
|
+
|
|
1652
|
+
|
|
1653
|
+
def _quality_summary_missing_items(
|
|
1654
|
+
control: Mapping[str, Any],
|
|
1655
|
+
source: Mapping[str, Any],
|
|
1656
|
+
gates: Mapping[str, Any],
|
|
1657
|
+
delivery: Mapping[str, Any],
|
|
1658
|
+
) -> list[str]:
|
|
1659
|
+
items: list[str] = []
|
|
1660
|
+
if _text(control.get("fact_layer_status")) in {"", "missing", "incomplete"}:
|
|
1661
|
+
items.append(f"Fact layer status is `{_text(control.get('fact_layer_status')) or 'unknown'}`.")
|
|
1662
|
+
if _text(source.get("source_pack_status")) in {"", "missing", "not_available"}:
|
|
1663
|
+
items.append("Durable source evidence pack is missing or not available.")
|
|
1664
|
+
if _gate_status_level(gates.get("auditor_status")) in {"missing", "incomplete"}:
|
|
1665
|
+
items.append(f"Auditor gate status is `{_text(gates.get('auditor_status')) or 'unknown'}`.")
|
|
1666
|
+
if _gate_status_level(gates.get("finalize_status")) in {"missing", "incomplete"}:
|
|
1667
|
+
items.append(f"Finalize gate status is `{_text(gates.get('finalize_status')) or 'unknown'}`.")
|
|
1668
|
+
if gates.get("legacy_quality_gate_present") is True:
|
|
1669
|
+
legacy_status = _text(gates.get("legacy_quality_gate_status")) or "unknown"
|
|
1670
|
+
legacy_stage = _text(gates.get("legacy_quality_gate_stage")) or "unknown"
|
|
1671
|
+
items.append(
|
|
1672
|
+
"Legacy/latest quality gate report is present "
|
|
1673
|
+
f"with status `{legacy_status}` and stage `{legacy_stage}`; "
|
|
1674
|
+
"scoped gate reports are still tracked separately."
|
|
1675
|
+
)
|
|
1676
|
+
if _text(delivery.get("reader_clean_status")) != "pass":
|
|
1677
|
+
items.append(f"Reader-clean status is `{_text(delivery.get('reader_clean_status')) or 'unknown'}`.")
|
|
1678
|
+
return items
|
|
1679
|
+
|
|
1680
|
+
|
|
1681
|
+
def _quality_summary_action_items(actions: list[Any]) -> list[str]:
|
|
1682
|
+
items: list[str] = []
|
|
1683
|
+
for action in actions:
|
|
1684
|
+
if not isinstance(action, Mapping):
|
|
1685
|
+
continue
|
|
1686
|
+
action_name = _text(action.get("action")) or "unknown_action"
|
|
1687
|
+
reason = _text(action.get("reason")) or "unspecified"
|
|
1688
|
+
items.append(f"`{action_name}` - {reason}.")
|
|
1689
|
+
return items
|
|
1690
|
+
|
|
1691
|
+
|
|
1692
|
+
def _quality_panel_incomplete_count(
|
|
1693
|
+
control: Mapping[str, Any],
|
|
1694
|
+
source: Mapping[str, Any],
|
|
1695
|
+
gates: Mapping[str, Any],
|
|
1696
|
+
delivery: Mapping[str, Any],
|
|
1697
|
+
) -> int:
|
|
1698
|
+
count = 0
|
|
1699
|
+
if _text(control.get("fact_layer_status")) in {"", "missing", "incomplete"}:
|
|
1700
|
+
count += 1
|
|
1701
|
+
if _text(source.get("source_pack_status")) in {"", "missing", "not_available"}:
|
|
1702
|
+
count += 1
|
|
1703
|
+
if _gate_status_level(gates.get("auditor_status")) in {"missing", "incomplete"}:
|
|
1704
|
+
count += 1
|
|
1705
|
+
if _gate_status_level(gates.get("finalize_status")) in {"missing", "incomplete"}:
|
|
1706
|
+
count += 1
|
|
1707
|
+
if _text(delivery.get("reader_clean_status")) != "pass":
|
|
1708
|
+
count += 1
|
|
1709
|
+
return count
|
|
1710
|
+
|
|
1711
|
+
|
|
1712
|
+
def _html_header_card(panel_payload: Mapping[str, Any], *, overall_status: str) -> str:
|
|
1713
|
+
level = _status_level(overall_status)
|
|
1714
|
+
run_id = _text(panel_payload.get("run_id")) or "unknown"
|
|
1715
|
+
generated_at = _text(panel_payload.get("generated_at")) or "unknown"
|
|
1716
|
+
return (
|
|
1717
|
+
"<header class=\"panel-hero\" data-section=\"panel-header\">\n"
|
|
1718
|
+
" <div>\n"
|
|
1719
|
+
f" <p class=\"eyebrow\">{_html_label('audit_attachment')}</p>\n"
|
|
1720
|
+
f" <h1>{_html_label('quality_panel')}</h1>\n"
|
|
1721
|
+
" <p class=\"boundary\">"
|
|
1722
|
+
f"<span class=\"lang-en\" lang=\"en\">{_html(QUALITY_PANEL_HTML_BOUNDARY)}</span>"
|
|
1723
|
+
f"<span class=\"lang-zh\" lang=\"zh-CN\">{_html(QUALITY_PANEL_HTML_BOUNDARY_ZH)}</span>"
|
|
1724
|
+
"</p>\n"
|
|
1725
|
+
" </div>\n"
|
|
1726
|
+
f" <div class=\"status-pill level-{level}\"><span>{_html_label('overall_status')}</span>"
|
|
1727
|
+
f"<strong>{_html_bilingual_value(overall_status)}</strong></div>\n"
|
|
1728
|
+
f" <dl class=\"hero-meta\"><dt>{_html_label('run_id')}</dt><dd>{_html(run_id)}</dd>"
|
|
1729
|
+
f"<dt>{_html_label('generated')}</dt><dd>{_html(generated_at)}</dd></dl>\n"
|
|
1730
|
+
"</header>"
|
|
1731
|
+
)
|
|
1732
|
+
|
|
1733
|
+
|
|
1734
|
+
_METRIC_KIND_LEVELS = {
|
|
1735
|
+
"block": "block",
|
|
1736
|
+
"warning": "warning",
|
|
1737
|
+
"incomplete": "missing",
|
|
1738
|
+
"action": "info",
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
|
|
1742
|
+
def _html_metrics_grid(metrics: list[tuple[str, int, str]]) -> str:
|
|
1743
|
+
cards = []
|
|
1744
|
+
for label_key, value, kind in metrics:
|
|
1745
|
+
level = _METRIC_KIND_LEVELS.get(kind, "info") if value > 0 else "zero"
|
|
1746
|
+
cards.append(
|
|
1747
|
+
" <div class=\"metric-card\">"
|
|
1748
|
+
f"<span>{_html_label(label_key)}</span>"
|
|
1749
|
+
f"<strong class=\"metric level-{level}\">{value}</strong>"
|
|
1750
|
+
"</div>"
|
|
1751
|
+
)
|
|
1752
|
+
legend = "".join(
|
|
1753
|
+
f"<span class=\"badge badge-{level}\">{_html_label(f'legend_{level}')}</span>"
|
|
1754
|
+
for level in ("pass", "warning", "block", "missing", "info")
|
|
1755
|
+
)
|
|
1756
|
+
return (
|
|
1757
|
+
"<section class=\"metric-grid\" data-section=\"metrics\" aria-label=\"Quality metrics\">\n"
|
|
1758
|
+
+ "\n".join(cards)
|
|
1759
|
+
+ "\n</section>\n"
|
|
1760
|
+
"<p class=\"color-legend\" data-section=\"color-legend\">"
|
|
1761
|
+
f"<span class=\"legend-title\">{_html_label('color_legend')}</span>{legend}</p>"
|
|
1762
|
+
)
|
|
1763
|
+
|
|
1764
|
+
|
|
1765
|
+
def _html_section(section_id: str, title_key: str, rows: list[tuple[str, Any, str]]) -> str:
|
|
1766
|
+
items = []
|
|
1767
|
+
for label_key, value, kind in rows:
|
|
1768
|
+
items.append(
|
|
1769
|
+
" <tr>"
|
|
1770
|
+
f"<th scope=\"row\">{_html_label(label_key)}</th>"
|
|
1771
|
+
f"<td>{_html_typed_value(value, kind)}</td>"
|
|
1772
|
+
"</tr>"
|
|
1773
|
+
)
|
|
1774
|
+
return (
|
|
1775
|
+
f"<section class=\"panel-section\" data-section=\"{_html(section_id)}\">\n"
|
|
1776
|
+
f" <h2>{_html_label(title_key)}</h2>\n"
|
|
1777
|
+
" <table>\n"
|
|
1778
|
+
" <tbody>\n"
|
|
1779
|
+
+ "\n".join(items)
|
|
1780
|
+
+ "\n"
|
|
1781
|
+
" </tbody>\n"
|
|
1782
|
+
" </table>\n"
|
|
1783
|
+
"</section>"
|
|
1784
|
+
)
|
|
1785
|
+
|
|
1786
|
+
|
|
1787
|
+
def _html_actions(actions: list[Any]) -> str:
|
|
1788
|
+
items = []
|
|
1789
|
+
for action in actions:
|
|
1790
|
+
if not isinstance(action, Mapping):
|
|
1791
|
+
continue
|
|
1792
|
+
action_name = _text(action.get("action")) or "unknown_action"
|
|
1793
|
+
reason = _text(action.get("reason")) or "unspecified"
|
|
1794
|
+
action_zh = _QUALITY_PANEL_HTML_ACTIONS_ZH.get(action_name, action_name)
|
|
1795
|
+
reason_zh = _QUALITY_PANEL_HTML_REASONS_ZH.get(reason, reason)
|
|
1796
|
+
items.append(
|
|
1797
|
+
"<li>"
|
|
1798
|
+
"<strong>"
|
|
1799
|
+
f"<span class=\"lang-en\" lang=\"en\">{_html(action_name)}</span>"
|
|
1800
|
+
f"<span class=\"lang-zh\" lang=\"zh-CN\">{_html(action_zh)}</span>"
|
|
1801
|
+
"</strong>"
|
|
1802
|
+
"<span>"
|
|
1803
|
+
f"<span class=\"lang-en\" lang=\"en\">{_html(reason)}</span>"
|
|
1804
|
+
f"<span class=\"lang-zh\" lang=\"zh-CN\">{_html(reason_zh)}</span>"
|
|
1805
|
+
"</span>"
|
|
1806
|
+
"</li>"
|
|
1807
|
+
)
|
|
1808
|
+
if not items:
|
|
1809
|
+
items.append(f"<li><strong>{_html_label('none')}</strong><span>{_html_label('no_recommended_action')}</span></li>")
|
|
1810
|
+
return (
|
|
1811
|
+
"<section class=\"panel-section actions\" data-section=\"recommended-next-actions\">\n"
|
|
1812
|
+
f" <h2>{_html_label('recommended_next_actions')}</h2>\n"
|
|
1813
|
+
" <ul>\n"
|
|
1814
|
+
+ "\n".join(f" {item}" for item in items)
|
|
1815
|
+
+ "\n"
|
|
1816
|
+
" </ul>\n"
|
|
1817
|
+
"</section>"
|
|
1818
|
+
)
|
|
1819
|
+
|
|
1820
|
+
|
|
1821
|
+
_COUNT_KIND_LEVELS = {
|
|
1822
|
+
"count_block": "block",
|
|
1823
|
+
"count_warning": "warning",
|
|
1824
|
+
"count_neutral": None,
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
|
|
1828
|
+
def _html_typed_value(value: Any, kind: str) -> str:
|
|
1829
|
+
if kind == "status":
|
|
1830
|
+
return _html_status_badge(value)
|
|
1831
|
+
if kind in _COUNT_KIND_LEVELS:
|
|
1832
|
+
count = _intish(value)
|
|
1833
|
+
level = _COUNT_KIND_LEVELS[kind]
|
|
1834
|
+
if level is None or count == 0:
|
|
1835
|
+
return f"<span class=\"count-zero\">{count}</span>" if count == 0 else str(count)
|
|
1836
|
+
return f"<span class=\"badge badge-{level}\">{count}</span>"
|
|
1837
|
+
if kind == "code":
|
|
1838
|
+
return f"<code>{_html(_text(value))}</code>"
|
|
1839
|
+
return _html_inline_value(_text(value))
|
|
1840
|
+
|
|
1841
|
+
|
|
1842
|
+
def _html_status_badge(value: Any) -> str:
|
|
1843
|
+
raw = _text(value) or "unknown"
|
|
1844
|
+
level = _status_level(raw)
|
|
1845
|
+
return (
|
|
1846
|
+
f"<span class=\"badge badge-{level}\" title=\"{_html(raw)}\">"
|
|
1847
|
+
f"{_html_bilingual_value(raw)}"
|
|
1848
|
+
"</span>"
|
|
1849
|
+
)
|
|
1850
|
+
|
|
1851
|
+
|
|
1852
|
+
def _html_bilingual_value(value: Any) -> str:
|
|
1853
|
+
raw = _text(value) or "unknown"
|
|
1854
|
+
zh = _QUALITY_PANEL_HTML_VALUES_ZH.get(raw, raw)
|
|
1855
|
+
return (
|
|
1856
|
+
f"<span class=\"lang-en\" lang=\"en\">{_html(raw)}</span>"
|
|
1857
|
+
f"<span class=\"lang-zh\" lang=\"zh-CN\">{_html(zh)}</span>"
|
|
1858
|
+
)
|
|
1859
|
+
|
|
1860
|
+
|
|
1861
|
+
def _status_level(value: Any) -> str:
|
|
1862
|
+
raw = _text(value).lower()
|
|
1863
|
+
return _QUALITY_PANEL_STATUS_LEVELS.get(raw, "info")
|
|
1864
|
+
|
|
1865
|
+
|
|
1866
|
+
def _html_inline_value(value: str) -> str:
|
|
1867
|
+
stripped = value.strip()
|
|
1868
|
+
if stripped.startswith("`") and stripped.endswith("`"):
|
|
1869
|
+
return f"<code>{_html(stripped.strip('`'))}</code>"
|
|
1870
|
+
return _html(stripped)
|
|
1871
|
+
|
|
1872
|
+
|
|
1873
|
+
def _html(value: Any) -> str:
|
|
1874
|
+
return _html_escape(str(value), quote=True)
|
|
1875
|
+
|
|
1876
|
+
|
|
1877
|
+
def _html_label(key: str) -> str:
|
|
1878
|
+
en, zh = _QUALITY_PANEL_HTML_LABELS.get(key, (key, key))
|
|
1879
|
+
return (
|
|
1880
|
+
f"<span class=\"lang-en\" lang=\"en\">{_html(en)}</span>"
|
|
1881
|
+
f"<span class=\"lang-zh\" lang=\"zh-CN\">{_html(zh)}</span>"
|
|
1882
|
+
)
|
|
1883
|
+
|
|
1884
|
+
|
|
1885
|
+
def _quality_panel_css() -> str:
|
|
1886
|
+
return """ :root {
|
|
1887
|
+
color-scheme: light;
|
|
1888
|
+
--ink: #1f2937;
|
|
1889
|
+
--muted: #667085;
|
|
1890
|
+
--line: #d0d5dd;
|
|
1891
|
+
--panel: #ffffff;
|
|
1892
|
+
--bg: #f6f7f9;
|
|
1893
|
+
--pass-fg: #067647;
|
|
1894
|
+
--pass-bg: #ecfdf3;
|
|
1895
|
+
--pass-line: #abefc6;
|
|
1896
|
+
--warning-fg: #b54708;
|
|
1897
|
+
--warning-bg: #fffaeb;
|
|
1898
|
+
--warning-line: #fedf89;
|
|
1899
|
+
--block-fg: #b42318;
|
|
1900
|
+
--block-bg: #fef3f2;
|
|
1901
|
+
--block-line: #fecdca;
|
|
1902
|
+
--missing-fg: #475467;
|
|
1903
|
+
--missing-bg: #f2f4f7;
|
|
1904
|
+
--missing-line: #d0d5dd;
|
|
1905
|
+
--info-fg: #175cd3;
|
|
1906
|
+
--info-bg: #eff8ff;
|
|
1907
|
+
--info-line: #b2ddff;
|
|
1908
|
+
}
|
|
1909
|
+
* { box-sizing: border-box; }
|
|
1910
|
+
body {
|
|
1911
|
+
margin: 0;
|
|
1912
|
+
padding: 32px;
|
|
1913
|
+
background: var(--bg);
|
|
1914
|
+
color: var(--ink);
|
|
1915
|
+
font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI",
|
|
1916
|
+
"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
|
|
1917
|
+
}
|
|
1918
|
+
.language-radio {
|
|
1919
|
+
position: fixed;
|
|
1920
|
+
opacity: 0;
|
|
1921
|
+
pointer-events: none;
|
|
1922
|
+
}
|
|
1923
|
+
.language-toggle {
|
|
1924
|
+
position: fixed;
|
|
1925
|
+
top: 16px;
|
|
1926
|
+
right: 16px;
|
|
1927
|
+
z-index: 2;
|
|
1928
|
+
display: inline-flex;
|
|
1929
|
+
overflow: hidden;
|
|
1930
|
+
border: 1px solid var(--line);
|
|
1931
|
+
border-radius: 8px;
|
|
1932
|
+
background: var(--panel);
|
|
1933
|
+
box-shadow: 0 2px 8px rgba(16, 24, 40, .08);
|
|
1934
|
+
}
|
|
1935
|
+
.language-toggle label {
|
|
1936
|
+
cursor: pointer;
|
|
1937
|
+
padding: 7px 10px;
|
|
1938
|
+
color: var(--muted);
|
|
1939
|
+
font-weight: 700;
|
|
1940
|
+
line-height: 1;
|
|
1941
|
+
border-left: 1px solid var(--line);
|
|
1942
|
+
user-select: none;
|
|
1943
|
+
}
|
|
1944
|
+
.language-toggle label:first-child { border-left: 0; }
|
|
1945
|
+
#lang-en:checked ~ .language-toggle label[for="lang-en"],
|
|
1946
|
+
#lang-zh:checked ~ .language-toggle label[for="lang-zh"] {
|
|
1947
|
+
background: var(--ink);
|
|
1948
|
+
color: #fff;
|
|
1949
|
+
}
|
|
1950
|
+
.lang-zh { display: none; }
|
|
1951
|
+
#lang-zh:checked ~ main .lang-en { display: none; }
|
|
1952
|
+
#lang-zh:checked ~ main .lang-zh { display: inline; }
|
|
1953
|
+
#lang-en:checked ~ main .lang-en { display: inline; }
|
|
1954
|
+
#lang-en:checked ~ main .lang-zh { display: none; }
|
|
1955
|
+
.panel-hero, .panel-section, .metric-card {
|
|
1956
|
+
background: var(--panel);
|
|
1957
|
+
border: 1px solid var(--line);
|
|
1958
|
+
border-radius: 8px;
|
|
1959
|
+
}
|
|
1960
|
+
.panel-hero {
|
|
1961
|
+
display: grid;
|
|
1962
|
+
grid-template-columns: 1fr auto;
|
|
1963
|
+
gap: 20px;
|
|
1964
|
+
padding: 24px;
|
|
1965
|
+
margin: 0 0 16px;
|
|
1966
|
+
}
|
|
1967
|
+
.eyebrow {
|
|
1968
|
+
margin: 0 0 6px;
|
|
1969
|
+
color: var(--muted);
|
|
1970
|
+
font-size: 12px;
|
|
1971
|
+
font-weight: 700;
|
|
1972
|
+
letter-spacing: .04em;
|
|
1973
|
+
text-transform: uppercase;
|
|
1974
|
+
}
|
|
1975
|
+
h1, h2 { margin: 0; line-height: 1.2; }
|
|
1976
|
+
h1 { font-size: 28px; }
|
|
1977
|
+
h2 { font-size: 18px; margin-bottom: 14px; }
|
|
1978
|
+
.boundary { max-width: 760px; color: var(--muted); margin: 10px 0 0; }
|
|
1979
|
+
.status-pill {
|
|
1980
|
+
align-self: start;
|
|
1981
|
+
min-width: 112px;
|
|
1982
|
+
padding: 8px 14px;
|
|
1983
|
+
border-radius: 999px;
|
|
1984
|
+
text-align: center;
|
|
1985
|
+
font-weight: 700;
|
|
1986
|
+
color: #fff;
|
|
1987
|
+
background: var(--missing-fg);
|
|
1988
|
+
}
|
|
1989
|
+
.status-pill span { display: block; font-size: 11px; opacity: .85; }
|
|
1990
|
+
.status-pill strong { display: block; margin-top: 2px; }
|
|
1991
|
+
.status-pill.level-pass { background: var(--pass-fg); }
|
|
1992
|
+
.status-pill.level-warning { background: var(--warning-fg); }
|
|
1993
|
+
.status-pill.level-block { background: var(--block-fg); }
|
|
1994
|
+
.status-pill.level-missing { background: var(--missing-fg); }
|
|
1995
|
+
.status-pill.level-info { background: var(--info-fg); }
|
|
1996
|
+
.badge {
|
|
1997
|
+
display: inline-flex;
|
|
1998
|
+
align-items: center;
|
|
1999
|
+
gap: 6px;
|
|
2000
|
+
padding: 2px 10px;
|
|
2001
|
+
border-radius: 999px;
|
|
2002
|
+
border: 1px solid var(--missing-line);
|
|
2003
|
+
background: var(--missing-bg);
|
|
2004
|
+
color: var(--missing-fg);
|
|
2005
|
+
font-weight: 600;
|
|
2006
|
+
font-size: 13px;
|
|
2007
|
+
line-height: 1.6;
|
|
2008
|
+
}
|
|
2009
|
+
.badge::before {
|
|
2010
|
+
content: "";
|
|
2011
|
+
flex: none;
|
|
2012
|
+
width: 8px;
|
|
2013
|
+
height: 8px;
|
|
2014
|
+
border-radius: 50%;
|
|
2015
|
+
background: currentColor;
|
|
2016
|
+
}
|
|
2017
|
+
.badge-pass { background: var(--pass-bg); color: var(--pass-fg); border-color: var(--pass-line); }
|
|
2018
|
+
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-line); }
|
|
2019
|
+
.badge-block { background: var(--block-bg); color: var(--block-fg); border-color: var(--block-line); }
|
|
2020
|
+
.badge-missing { background: var(--missing-bg); color: var(--missing-fg); border-color: var(--missing-line); }
|
|
2021
|
+
.badge-info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-line); }
|
|
2022
|
+
.count-zero { color: var(--muted); }
|
|
2023
|
+
.color-legend {
|
|
2024
|
+
display: flex;
|
|
2025
|
+
flex-wrap: wrap;
|
|
2026
|
+
align-items: center;
|
|
2027
|
+
gap: 8px;
|
|
2028
|
+
margin: 0 0 16px;
|
|
2029
|
+
color: var(--muted);
|
|
2030
|
+
font-size: 12px;
|
|
2031
|
+
}
|
|
2032
|
+
.color-legend .legend-title { font-weight: 700; margin-right: 4px; }
|
|
2033
|
+
.color-legend .badge { font-size: 12px; }
|
|
2034
|
+
.hero-meta {
|
|
2035
|
+
grid-column: 1 / -1;
|
|
2036
|
+
display: grid;
|
|
2037
|
+
grid-template-columns: max-content 1fr;
|
|
2038
|
+
column-gap: 10px;
|
|
2039
|
+
row-gap: 2px;
|
|
2040
|
+
margin: 0;
|
|
2041
|
+
color: var(--muted);
|
|
2042
|
+
}
|
|
2043
|
+
.hero-meta dt { font-weight: 700; }
|
|
2044
|
+
.hero-meta dd { margin: 0; overflow-wrap: anywhere; }
|
|
2045
|
+
.metric-grid {
|
|
2046
|
+
display: grid;
|
|
2047
|
+
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
|
2048
|
+
gap: 12px;
|
|
2049
|
+
margin-bottom: 16px;
|
|
2050
|
+
}
|
|
2051
|
+
.metric-card { padding: 16px; }
|
|
2052
|
+
.metric-card span { display: block; color: var(--muted); margin-bottom: 8px; }
|
|
2053
|
+
.metric-card strong {
|
|
2054
|
+
display: inline-flex;
|
|
2055
|
+
min-width: 44px;
|
|
2056
|
+
min-height: 36px;
|
|
2057
|
+
padding: 4px 10px;
|
|
2058
|
+
border-radius: 6px;
|
|
2059
|
+
align-items: center;
|
|
2060
|
+
justify-content: center;
|
|
2061
|
+
font-size: 22px;
|
|
2062
|
+
color: var(--ink);
|
|
2063
|
+
background: #eef2f6;
|
|
2064
|
+
border: 1px solid transparent;
|
|
2065
|
+
}
|
|
2066
|
+
.metric.level-pass { background: var(--pass-bg); color: var(--pass-fg); border-color: var(--pass-line); }
|
|
2067
|
+
.metric.level-warning { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-line); }
|
|
2068
|
+
.metric.level-block { background: var(--block-bg); color: var(--block-fg); border-color: var(--block-line); }
|
|
2069
|
+
.metric.level-missing { background: var(--missing-bg); color: var(--missing-fg); border-color: var(--missing-line); }
|
|
2070
|
+
.metric.level-info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-line); }
|
|
2071
|
+
.metric.level-zero { background: #eef2f6; color: var(--muted); }
|
|
2072
|
+
.panel-section { padding: 20px; margin-bottom: 16px; }
|
|
2073
|
+
table { width: 100%; border-collapse: collapse; }
|
|
2074
|
+
th, td { padding: 10px 0; border-top: 1px solid #eaecf0; text-align: left; vertical-align: top; }
|
|
2075
|
+
th { width: 36%; color: var(--muted); font-weight: 650; padding-right: 16px; }
|
|
2076
|
+
code {
|
|
2077
|
+
padding: 2px 5px;
|
|
2078
|
+
border-radius: 4px;
|
|
2079
|
+
background: #eef2f6;
|
|
2080
|
+
color: #344054;
|
|
2081
|
+
}
|
|
2082
|
+
.actions ul { list-style: none; padding: 0; margin: 0; }
|
|
2083
|
+
.actions li {
|
|
2084
|
+
display: grid;
|
|
2085
|
+
grid-template-columns: minmax(160px, 260px) 1fr;
|
|
2086
|
+
gap: 12px;
|
|
2087
|
+
padding: 10px 0;
|
|
2088
|
+
border-top: 1px solid #eaecf0;
|
|
2089
|
+
}
|
|
2090
|
+
.actions span { color: var(--muted); }
|
|
2091
|
+
@media (max-width: 720px) {
|
|
2092
|
+
body { padding: 16px; }
|
|
2093
|
+
.language-toggle { position: static; margin-bottom: 12px; }
|
|
2094
|
+
.panel-hero { grid-template-columns: 1fr; }
|
|
2095
|
+
.actions li { grid-template-columns: 1fr; }
|
|
2096
|
+
th, td { display: block; width: 100%; }
|
|
2097
|
+
th { padding-bottom: 2px; }
|
|
2098
|
+
td { padding-top: 0; }
|
|
2099
|
+
}"""
|
|
2100
|
+
|
|
2101
|
+
|
|
2102
|
+
def _extend_bullets(lines: list[str], items: list[str]) -> None:
|
|
2103
|
+
if not items:
|
|
2104
|
+
lines.append("- None reported by `quality_panel.json`.")
|
|
2105
|
+
return
|
|
2106
|
+
for item in items:
|
|
2107
|
+
lines.append(f"- {item}")
|
|
2108
|
+
|
|
2109
|
+
|
|
2110
|
+
def _inline_mapping(value: Any) -> str:
|
|
2111
|
+
if not isinstance(value, Mapping) or not value:
|
|
2112
|
+
return "`none`"
|
|
2113
|
+
parts = [
|
|
2114
|
+
f"{_text(key) or str(key)}={_intish(count)}"
|
|
2115
|
+
for key, count in sorted(value.items(), key=lambda item: str(item[0]))
|
|
2116
|
+
]
|
|
2117
|
+
return "`" + ", ".join(parts) + "`"
|
|
2118
|
+
|
|
2119
|
+
|
|
2120
|
+
def _intish(value: Any) -> int:
|
|
2121
|
+
if isinstance(value, bool):
|
|
2122
|
+
return int(value)
|
|
2123
|
+
if isinstance(value, int):
|
|
2124
|
+
return value
|
|
2125
|
+
try:
|
|
2126
|
+
return int(value)
|
|
2127
|
+
except (TypeError, ValueError):
|
|
2128
|
+
return 0
|
|
2129
|
+
|
|
2130
|
+
|
|
2131
|
+
def _write_json_atomic(path: Path, payload: dict[str, Any]) -> None:
|
|
2132
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
2133
|
+
text = json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True) + "\n"
|
|
2134
|
+
tmp = path.with_name(f".{path.name}.{uuid.uuid4().hex}.tmp")
|
|
2135
|
+
try:
|
|
2136
|
+
tmp.write_text(text, encoding="utf-8")
|
|
2137
|
+
os.replace(tmp, path)
|
|
2138
|
+
except OSError:
|
|
2139
|
+
try:
|
|
2140
|
+
tmp.unlink(missing_ok=True)
|
|
2141
|
+
except OSError:
|
|
2142
|
+
pass
|
|
2143
|
+
raise
|
|
2144
|
+
|
|
2145
|
+
|
|
2146
|
+
def _write_text_atomic(path: Path, text: str) -> None:
|
|
2147
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
2148
|
+
tmp = path.with_name(f".{path.name}.{uuid.uuid4().hex}.tmp")
|
|
2149
|
+
try:
|
|
2150
|
+
tmp.write_text(text, encoding="utf-8")
|
|
2151
|
+
os.replace(tmp, path)
|
|
2152
|
+
except OSError:
|
|
2153
|
+
try:
|
|
2154
|
+
tmp.unlink(missing_ok=True)
|
|
2155
|
+
except OSError:
|
|
2156
|
+
pass
|
|
2157
|
+
raise
|
|
2158
|
+
|
|
2159
|
+
|
|
2160
|
+
def _sha256_text(text: str) -> str:
|
|
2161
|
+
import hashlib
|
|
2162
|
+
|
|
2163
|
+
return hashlib.sha256(text.encode("utf-8")).hexdigest()
|
|
2164
|
+
|
|
2165
|
+
|
|
2166
|
+
def _sha256_file(path: Path) -> str:
|
|
2167
|
+
import hashlib
|
|
2168
|
+
|
|
2169
|
+
h = hashlib.sha256()
|
|
2170
|
+
with path.open("rb") as f:
|
|
2171
|
+
for chunk in iter(lambda: f.read(1024 * 1024), b""):
|
|
2172
|
+
h.update(chunk)
|
|
2173
|
+
return h.hexdigest()
|
|
2174
|
+
|
|
2175
|
+
|
|
2176
|
+
def _normalize_sha256(value: Any) -> str | None:
|
|
2177
|
+
if not isinstance(value, str):
|
|
2178
|
+
return None
|
|
2179
|
+
stripped = value.strip()
|
|
2180
|
+
if stripped.startswith("sha256:"):
|
|
2181
|
+
stripped = stripped.removeprefix("sha256:")
|
|
2182
|
+
if len(stripped) != 64:
|
|
2183
|
+
return None
|
|
2184
|
+
lowered = stripped.lower()
|
|
2185
|
+
if any(ch not in "0123456789abcdef" for ch in lowered):
|
|
2186
|
+
return None
|
|
2187
|
+
return lowered
|
|
2188
|
+
|
|
2189
|
+
|
|
2190
|
+
def _workspace_relative(workspace: Path, path: Path) -> str:
|
|
2191
|
+
return path.resolve().relative_to(workspace.resolve()).as_posix()
|
|
2192
|
+
|
|
2193
|
+
|
|
2194
|
+
def _utc_now() -> str:
|
|
2195
|
+
return datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
|
2196
|
+
|
|
2197
|
+
|
|
2198
|
+
def _read_json_mapping(path: Path) -> dict[str, Any] | None:
|
|
2199
|
+
if not path.exists():
|
|
2200
|
+
return None
|
|
2201
|
+
try:
|
|
2202
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
2203
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError):
|
|
2204
|
+
return None
|
|
2205
|
+
return payload if isinstance(payload, dict) else None
|
|
2206
|
+
|
|
2207
|
+
|
|
2208
|
+
def _first_text(mapping: Mapping[str, Any], *keys: str) -> str:
|
|
2209
|
+
for key in keys:
|
|
2210
|
+
value = _text(mapping.get(key))
|
|
2211
|
+
if value:
|
|
2212
|
+
return value
|
|
2213
|
+
return ""
|
|
2214
|
+
|
|
2215
|
+
|
|
2216
|
+
def _text(value: Any) -> str:
|
|
2217
|
+
return value.strip() if isinstance(value, str) else ""
|