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,842 @@
|
|
|
1
|
+
"""Deterministic repair routing for blocked or failed workspaces.
|
|
2
|
+
|
|
3
|
+
The router is intentionally read-only. It does not create repair plans, mutate
|
|
4
|
+
artifacts, call agents, or execute repair. It only maps known finding shapes to
|
|
5
|
+
the stage/artifact owner that may repair them.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from multi_agent_brief.audit.proposal_boundary import is_advisory_semantic_support_proposal
|
|
15
|
+
from multi_agent_brief.orchestrator.runtime_state import (
|
|
16
|
+
load_artifact_contracts,
|
|
17
|
+
load_stage_specs,
|
|
18
|
+
runtime_state_paths,
|
|
19
|
+
utc_now,
|
|
20
|
+
)
|
|
21
|
+
from multi_agent_brief.orchestrator.runtime_state.artifact_registry import _build_artifact_registry
|
|
22
|
+
from multi_agent_brief.orchestrator_contract import resolve_repo_workdir
|
|
23
|
+
from multi_agent_brief.quality_gates.contract import quality_gate_paths
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
INTERMEDIATE_DIR = Path("output/intermediate")
|
|
27
|
+
STAGE_REPAIR_ARTIFACTS = {
|
|
28
|
+
"source-discovery": ["input/sources/*"],
|
|
29
|
+
"input-governance": ["input/*"],
|
|
30
|
+
"scout": ["output/intermediate/candidate_claims.json"],
|
|
31
|
+
"screener": ["output/intermediate/screened_candidates.json"],
|
|
32
|
+
"claim-ledger": ["output/intermediate/claim_ledger.json"],
|
|
33
|
+
"analyst": ["output/intermediate/audited_brief.md"],
|
|
34
|
+
"editor": ["output/intermediate/audited_brief.md"],
|
|
35
|
+
"auditor": ["output/intermediate/audit_report.json"],
|
|
36
|
+
"finalize": ["output/delivery/brief.md"],
|
|
37
|
+
}
|
|
38
|
+
ARTIFACT_PATHS = {
|
|
39
|
+
"candidate_claims": "output/intermediate/candidate_claims.json",
|
|
40
|
+
"screened_candidates": "output/intermediate/screened_candidates.json",
|
|
41
|
+
"claim_ledger": "output/intermediate/claim_ledger.json",
|
|
42
|
+
"audited_brief": "output/intermediate/audited_brief.md",
|
|
43
|
+
"audit_report": "output/intermediate/audit_report.json",
|
|
44
|
+
"auditor_quality_gate_report": "output/intermediate/gates/auditor_quality_gate_report.json",
|
|
45
|
+
"finalize_quality_gate_report": "output/intermediate/gates/finalize_quality_gate_report.json",
|
|
46
|
+
}
|
|
47
|
+
OWNER_ALIASES = {
|
|
48
|
+
"source": "source-discovery",
|
|
49
|
+
"source_discovery": "source-discovery",
|
|
50
|
+
"source-discovery": "source-discovery",
|
|
51
|
+
"claim_ledger": "claim-ledger",
|
|
52
|
+
"claim-ledger": "claim-ledger",
|
|
53
|
+
"analyst": "analyst",
|
|
54
|
+
"editor": "editor",
|
|
55
|
+
"auditor": "auditor",
|
|
56
|
+
"human": "human",
|
|
57
|
+
"orchestrator": "orchestrator",
|
|
58
|
+
}
|
|
59
|
+
RERUN_FROM_BY_OWNER = {
|
|
60
|
+
"source-discovery": "input-governance",
|
|
61
|
+
"input-governance": "scout",
|
|
62
|
+
"scout": "screener",
|
|
63
|
+
"screener": "claim-ledger",
|
|
64
|
+
"claim-ledger": "analyst",
|
|
65
|
+
"analyst": "editor",
|
|
66
|
+
"editor": "auditor",
|
|
67
|
+
"auditor": "gates",
|
|
68
|
+
"finalize": "finalize",
|
|
69
|
+
}
|
|
70
|
+
DOWNSTREAM_BLOCKED_EDITS = {
|
|
71
|
+
"source-discovery": [
|
|
72
|
+
"output/intermediate/candidate_claims.json",
|
|
73
|
+
"output/intermediate/screened_candidates.json",
|
|
74
|
+
"output/intermediate/claim_ledger.json",
|
|
75
|
+
"output/intermediate/audited_brief.md",
|
|
76
|
+
"output/intermediate/audit_report.json",
|
|
77
|
+
],
|
|
78
|
+
"claim-ledger": [
|
|
79
|
+
"output/intermediate/audited_brief.md",
|
|
80
|
+
"output/intermediate/audit_report.json",
|
|
81
|
+
],
|
|
82
|
+
"analyst": [
|
|
83
|
+
"output/intermediate/analyst_draft_snapshot.md",
|
|
84
|
+
"output/intermediate/claim_ledger.json",
|
|
85
|
+
"output/intermediate/audit_report.json",
|
|
86
|
+
],
|
|
87
|
+
"editor": [
|
|
88
|
+
"output/intermediate/analyst_draft_snapshot.md",
|
|
89
|
+
"output/intermediate/claim_ledger.json",
|
|
90
|
+
"output/intermediate/audit_report.json",
|
|
91
|
+
],
|
|
92
|
+
}
|
|
93
|
+
IMPORTED_FACT_LAYER_FORBIDDEN_ARTIFACTS = {
|
|
94
|
+
"output/input_classification.json",
|
|
95
|
+
"output/intermediate/candidate_claims.json",
|
|
96
|
+
"output/intermediate/screened_candidates.json",
|
|
97
|
+
"output/intermediate/claim_ledger.json",
|
|
98
|
+
}
|
|
99
|
+
IMPORTED_FACT_LAYER_FORBIDDEN_PREFIXES = (
|
|
100
|
+
"input/sources/",
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def route_repair(
|
|
105
|
+
*,
|
|
106
|
+
workspace: str | Path,
|
|
107
|
+
route_index: int | None = None,
|
|
108
|
+
finding_id: str | None = None,
|
|
109
|
+
) -> dict[str, Any]:
|
|
110
|
+
ws = Path(workspace).expanduser().resolve()
|
|
111
|
+
if route_index is not None and finding_id is not None:
|
|
112
|
+
return {
|
|
113
|
+
"ok": False,
|
|
114
|
+
"error_code": "E_REPAIR_ROUTE_SELECTION_INVALID",
|
|
115
|
+
"message": "Use either --route-index or --finding-id, not both.",
|
|
116
|
+
"workspace": str(ws),
|
|
117
|
+
}
|
|
118
|
+
if not (ws / "config.yaml").exists():
|
|
119
|
+
return {
|
|
120
|
+
"ok": False,
|
|
121
|
+
"error_code": "E_REPAIR_WORKSPACE_MISSING",
|
|
122
|
+
"message": f"Workspace config.yaml not found: {ws / 'config.yaml'}",
|
|
123
|
+
"workspace": str(ws),
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
findings, input_errors, payloads = _collect_findings(ws)
|
|
127
|
+
if input_errors:
|
|
128
|
+
return {
|
|
129
|
+
"ok": False,
|
|
130
|
+
"error_code": "E_REPAIR_INPUT_INVALID",
|
|
131
|
+
"message": "Repair route inputs are invalid or unreadable.",
|
|
132
|
+
"workspace": str(ws),
|
|
133
|
+
"input_errors": input_errors,
|
|
134
|
+
}
|
|
135
|
+
routes = [_route_for_finding(finding) for finding in findings]
|
|
136
|
+
routes = [route for route in routes if route is not None]
|
|
137
|
+
routes = sorted(routes, key=_route_priority)
|
|
138
|
+
routes = _annotated_routes(routes, imported_fact_layer=_workspace_has_fact_layer_import(payloads))
|
|
139
|
+
selected = _select_route(routes, route_index=route_index, finding_id=finding_id)
|
|
140
|
+
if not selected.get("ok", True):
|
|
141
|
+
return {
|
|
142
|
+
"ok": False,
|
|
143
|
+
"workspace": str(ws),
|
|
144
|
+
"routes": routes,
|
|
145
|
+
"finding_count": len(findings),
|
|
146
|
+
**selected,
|
|
147
|
+
}
|
|
148
|
+
selected = _with_run_integrity_context(selected, payloads.get("workflow_state"))
|
|
149
|
+
return {
|
|
150
|
+
"ok": True,
|
|
151
|
+
"workspace": str(ws),
|
|
152
|
+
**selected,
|
|
153
|
+
"routes": routes,
|
|
154
|
+
"finding_count": len(findings),
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _collect_findings(workspace: Path) -> tuple[list[dict[str, Any]], list[dict[str, str]], dict[str, dict[str, Any]]]:
|
|
159
|
+
findings: list[dict[str, Any]] = []
|
|
160
|
+
input_errors: list[dict[str, str]] = []
|
|
161
|
+
payloads: dict[str, dict[str, Any]] = {}
|
|
162
|
+
input_paths = _input_paths(workspace)
|
|
163
|
+
for label, path in input_paths.items():
|
|
164
|
+
payload, error = _read_json_object(path)
|
|
165
|
+
if error:
|
|
166
|
+
input_errors.append({"source": label, "path": _workspace_relative(workspace, path), "error": error})
|
|
167
|
+
continue
|
|
168
|
+
if payload is None:
|
|
169
|
+
continue
|
|
170
|
+
payloads[label] = payload
|
|
171
|
+
current_stage = _current_workflow_stage(payloads.get("workflow_state"))
|
|
172
|
+
for label, payload in payloads.items():
|
|
173
|
+
path = input_paths[label]
|
|
174
|
+
rel_path = _workspace_relative(workspace, path)
|
|
175
|
+
findings.extend(_findings_from_payload(payload, source=label, path=rel_path))
|
|
176
|
+
if label == "finalize_report" and current_stage == "finalize":
|
|
177
|
+
findings.extend(_findings_from_finalize_report(payload, path=rel_path))
|
|
178
|
+
registry = payloads.get("artifact_registry")
|
|
179
|
+
findings.extend(_findings_from_artifact_registry(registry))
|
|
180
|
+
findings.extend(_findings_from_frozen_artifact_integrity(workspace, payloads))
|
|
181
|
+
return _dedupe_findings(findings), input_errors, payloads
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _current_workflow_stage(workflow_state: dict[str, Any] | None) -> str:
|
|
185
|
+
stage = workflow_state.get("current_stage") if isinstance(workflow_state, dict) else None
|
|
186
|
+
return stage if isinstance(stage, str) else ""
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _input_paths(workspace: Path) -> dict[str, Path]:
|
|
190
|
+
gate_paths = quality_gate_paths(workspace)
|
|
191
|
+
runtime_paths = runtime_state_paths(workspace)
|
|
192
|
+
paths = {
|
|
193
|
+
"auditor_quality_gate_report": gate_paths["auditor_quality_gate_report"],
|
|
194
|
+
"finalize_quality_gate_report": gate_paths["finalize_quality_gate_report"],
|
|
195
|
+
"audit_report": workspace / INTERMEDIATE_DIR / "audit_report.json",
|
|
196
|
+
"finalize_report": workspace / INTERMEDIATE_DIR / "finalize_report.json",
|
|
197
|
+
"runtime_manifest": runtime_paths["runtime_manifest"],
|
|
198
|
+
"workflow_state": runtime_paths["workflow_state"],
|
|
199
|
+
"artifact_registry": runtime_paths["artifact_registry"],
|
|
200
|
+
}
|
|
201
|
+
if not gate_paths["auditor_quality_gate_report"].exists() and not gate_paths["finalize_quality_gate_report"].exists():
|
|
202
|
+
paths["quality_gate_report"] = gate_paths["quality_gate_report"]
|
|
203
|
+
return paths
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _read_json_object(path: Path) -> tuple[dict[str, Any] | None, str | None]:
|
|
207
|
+
if not path.exists():
|
|
208
|
+
return None, None
|
|
209
|
+
try:
|
|
210
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
211
|
+
except OSError as exc:
|
|
212
|
+
return None, str(exc)
|
|
213
|
+
except json.JSONDecodeError as exc:
|
|
214
|
+
return None, f"invalid JSON: {exc}"
|
|
215
|
+
if not isinstance(payload, dict):
|
|
216
|
+
return None, "JSON payload must be an object"
|
|
217
|
+
return payload, None
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _findings_from_payload(payload: dict[str, Any], *, source: str, path: str) -> list[dict[str, Any]]:
|
|
221
|
+
findings = payload.get("findings")
|
|
222
|
+
if not isinstance(findings, list):
|
|
223
|
+
return []
|
|
224
|
+
metadata = payload.get("metadata") if isinstance(payload.get("metadata"), dict) else {}
|
|
225
|
+
source_stage_id = metadata.get("gate_stage_id") or metadata.get("stage_id")
|
|
226
|
+
report_status = payload.get("status") or payload.get("audit_status")
|
|
227
|
+
normalized: list[dict[str, Any]] = []
|
|
228
|
+
for idx, finding in enumerate(findings):
|
|
229
|
+
if not isinstance(finding, dict):
|
|
230
|
+
continue
|
|
231
|
+
item = dict(finding)
|
|
232
|
+
item.setdefault("_source", source)
|
|
233
|
+
item.setdefault("_source_path", path)
|
|
234
|
+
item.setdefault("_source_index", idx)
|
|
235
|
+
if report_status:
|
|
236
|
+
item.setdefault("_report_status", report_status)
|
|
237
|
+
if source_stage_id:
|
|
238
|
+
item.setdefault("_source_stage_id", source_stage_id)
|
|
239
|
+
normalized.append(item)
|
|
240
|
+
return normalized
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _findings_from_finalize_report(payload: dict[str, Any], *, path: str) -> list[dict[str, Any]]:
|
|
244
|
+
reader_clean = payload.get("reader_clean")
|
|
245
|
+
if not isinstance(reader_clean, dict) or reader_clean.get("status") == "pass":
|
|
246
|
+
return []
|
|
247
|
+
sample_findings = reader_clean.get("sample_findings")
|
|
248
|
+
if not isinstance(sample_findings, list):
|
|
249
|
+
return []
|
|
250
|
+
normalized: list[dict[str, Any]] = []
|
|
251
|
+
for idx, finding in enumerate(sample_findings):
|
|
252
|
+
if not isinstance(finding, dict):
|
|
253
|
+
continue
|
|
254
|
+
kind = str(finding.get("kind") or "reader_clean_residue")
|
|
255
|
+
message = str(finding.get("message") or f"Reader-clean failure: {kind}.")
|
|
256
|
+
residue = str(finding.get("text") or "")
|
|
257
|
+
if residue:
|
|
258
|
+
message = f"{message} Residue: {residue!r}."
|
|
259
|
+
normalized.append({
|
|
260
|
+
"_source": "finalize_report",
|
|
261
|
+
"_source_path": path,
|
|
262
|
+
"_source_index": idx,
|
|
263
|
+
"_source_stage_id": "finalize",
|
|
264
|
+
"finding_id": f"READER_CLEAN_{idx + 1:03d}",
|
|
265
|
+
"finding_type": f"reader_clean_{kind}",
|
|
266
|
+
"category": "reader_clean",
|
|
267
|
+
"severity": "medium",
|
|
268
|
+
"artifact_id": "audited_brief",
|
|
269
|
+
"repair_owner": "editor",
|
|
270
|
+
"repair_stage_id": "editor",
|
|
271
|
+
"repair_artifact_id": "audited_brief",
|
|
272
|
+
"message": message,
|
|
273
|
+
"recommended_action": "repair_editor_audited_brief_and_rerun_auditor_finalize",
|
|
274
|
+
})
|
|
275
|
+
return normalized
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _findings_from_artifact_registry(registry: dict[str, Any] | None) -> list[dict[str, Any]]:
|
|
279
|
+
artifacts = registry.get("artifacts") if isinstance(registry, dict) else None
|
|
280
|
+
if not isinstance(artifacts, dict):
|
|
281
|
+
return []
|
|
282
|
+
findings: list[dict[str, Any]] = []
|
|
283
|
+
for artifact_id, record in artifacts.items():
|
|
284
|
+
if not isinstance(record, dict):
|
|
285
|
+
continue
|
|
286
|
+
status = str(record.get("status") or "")
|
|
287
|
+
validation_result = str(record.get("validation_result") or "")
|
|
288
|
+
blocking_reason = str(record.get("blocking_reason") or "")
|
|
289
|
+
if status == "missing" and not blocking_reason and validation_result in {"", "not_checked"}:
|
|
290
|
+
continue
|
|
291
|
+
if status not in {"invalid", "missing"}:
|
|
292
|
+
continue
|
|
293
|
+
findings.append({
|
|
294
|
+
"_source": "artifact_registry",
|
|
295
|
+
"_source_path": "output/intermediate/artifact_registry.json",
|
|
296
|
+
"finding_type": validation_result or "artifact_invalid",
|
|
297
|
+
"artifact_id": artifact_id,
|
|
298
|
+
"message": blocking_reason or f"Artifact {artifact_id} is {status}.",
|
|
299
|
+
})
|
|
300
|
+
return findings
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def _findings_from_frozen_artifact_integrity(
|
|
304
|
+
workspace: Path,
|
|
305
|
+
payloads: dict[str, dict[str, Any]],
|
|
306
|
+
) -> list[dict[str, Any]]:
|
|
307
|
+
manifest = payloads.get("runtime_manifest")
|
|
308
|
+
workflow = payloads.get("workflow_state")
|
|
309
|
+
old_registry = payloads.get("artifact_registry")
|
|
310
|
+
if not isinstance(manifest, dict) or not isinstance(workflow, dict) or not isinstance(old_registry, dict):
|
|
311
|
+
return []
|
|
312
|
+
run_id = str(manifest.get("run_id") or "")
|
|
313
|
+
if not run_id:
|
|
314
|
+
return []
|
|
315
|
+
try:
|
|
316
|
+
repo = resolve_repo_workdir(None, workspace=workspace)
|
|
317
|
+
stages = load_stage_specs(repo)
|
|
318
|
+
artifacts = load_artifact_contracts(repo)
|
|
319
|
+
current_registry = _build_artifact_registry(
|
|
320
|
+
workspace=workspace,
|
|
321
|
+
run_id=run_id,
|
|
322
|
+
artifacts=artifacts,
|
|
323
|
+
workflow=workflow,
|
|
324
|
+
updated_at=utc_now(),
|
|
325
|
+
)
|
|
326
|
+
except Exception:
|
|
327
|
+
return []
|
|
328
|
+
|
|
329
|
+
old_records = old_registry.get("artifacts")
|
|
330
|
+
current_records = current_registry.get("artifacts")
|
|
331
|
+
if not isinstance(old_records, dict) or not isinstance(current_records, dict):
|
|
332
|
+
return []
|
|
333
|
+
|
|
334
|
+
findings: list[dict[str, Any]] = []
|
|
335
|
+
for artifact in artifacts:
|
|
336
|
+
artifact_id = str(artifact.get("artifact_id") or "")
|
|
337
|
+
owner = str(artifact.get("producer_stage") or "")
|
|
338
|
+
if not artifact_id or not owner or not _stage_is_complete(workflow, owner):
|
|
339
|
+
continue
|
|
340
|
+
old_record = old_records.get(artifact_id)
|
|
341
|
+
current_record = current_records.get(artifact_id)
|
|
342
|
+
if not isinstance(old_record, dict) or not isinstance(current_record, dict):
|
|
343
|
+
continue
|
|
344
|
+
old_sha = str(old_record.get("sha256") or "")
|
|
345
|
+
current_sha = str(current_record.get("sha256") or "")
|
|
346
|
+
if not old_sha or (current_sha and current_sha == old_sha):
|
|
347
|
+
continue
|
|
348
|
+
path = str(current_record.get("path") or old_record.get("path") or artifact.get("path") or artifact_id)
|
|
349
|
+
if not current_sha or current_record.get("status") == "missing":
|
|
350
|
+
message = (
|
|
351
|
+
f"Frozen artifact '{path}' from owner stage '{owner}' is missing after stage-complete; "
|
|
352
|
+
"route repair back to the owner stage."
|
|
353
|
+
)
|
|
354
|
+
else:
|
|
355
|
+
message = (
|
|
356
|
+
f"Frozen artifact '{path}' from owner stage '{owner}' changed after stage-complete; "
|
|
357
|
+
"route repair back to the owner stage instead of downstream in-place conversion."
|
|
358
|
+
)
|
|
359
|
+
findings.append(
|
|
360
|
+
{
|
|
361
|
+
"_source": "transaction_integrity",
|
|
362
|
+
"_source_path": "output/intermediate/artifact_registry.json",
|
|
363
|
+
"finding_id": f"TX_FROZEN_{artifact_id}",
|
|
364
|
+
"finding_type": "frozen_artifact_changed",
|
|
365
|
+
"category": "transaction_integrity",
|
|
366
|
+
"severity": "high",
|
|
367
|
+
"artifact_id": artifact_id,
|
|
368
|
+
"repair_owner": owner,
|
|
369
|
+
"repair_stage_id": owner,
|
|
370
|
+
"repair_artifact_id": artifact_id,
|
|
371
|
+
"message": message,
|
|
372
|
+
"recommended_action": (
|
|
373
|
+
"Use repair start/complete for local inspection, or start a fresh workspace for "
|
|
374
|
+
"reference-grade evidence."
|
|
375
|
+
),
|
|
376
|
+
"run_integrity_effect": {
|
|
377
|
+
"reference_eligible": False,
|
|
378
|
+
"reason": "Frozen artifact changed after stage completion.",
|
|
379
|
+
},
|
|
380
|
+
}
|
|
381
|
+
)
|
|
382
|
+
return findings
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def _stage_is_complete(workflow: dict[str, Any], stage_id: str) -> bool:
|
|
386
|
+
statuses = workflow.get("stage_statuses")
|
|
387
|
+
if not isinstance(statuses, dict):
|
|
388
|
+
return False
|
|
389
|
+
stage = statuses.get(stage_id)
|
|
390
|
+
return isinstance(stage, dict) and stage.get("status") == "complete"
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def _route_for_finding(finding: dict[str, Any]) -> dict[str, Any] | None:
|
|
394
|
+
# Advisory semantic support proposals must never become a repair route, even
|
|
395
|
+
# if they carry a repair_owner: they are model proposals, not authoritative
|
|
396
|
+
# audit findings, and only a human-acceptance transaction can turn one into a
|
|
397
|
+
# workflow signal. A non-low "proposal" is malformed/spoofed and fails closed.
|
|
398
|
+
if is_advisory_semantic_support_proposal(
|
|
399
|
+
finding.get("finding_type") or finding.get("category"),
|
|
400
|
+
finding.get("severity"),
|
|
401
|
+
):
|
|
402
|
+
return None
|
|
403
|
+
|
|
404
|
+
if _is_input_limitation_finding(finding):
|
|
405
|
+
return _input_limitation_route(finding)
|
|
406
|
+
|
|
407
|
+
explicit = _explicit_repair_route(finding)
|
|
408
|
+
if explicit is not None:
|
|
409
|
+
return explicit
|
|
410
|
+
|
|
411
|
+
text = _finding_text(finding)
|
|
412
|
+
artifact_id = str(finding.get("artifact_id") or finding.get("repair_artifact_id") or "")
|
|
413
|
+
finding_type = str(finding.get("finding_type") or finding.get("category") or "").lower()
|
|
414
|
+
|
|
415
|
+
if _is_source_pack_missing_excerpt(text, finding_type):
|
|
416
|
+
return _route(
|
|
417
|
+
repair_owner="source-discovery",
|
|
418
|
+
allowed_artifacts=["input/sources/*"],
|
|
419
|
+
must_rerun_from="input-governance",
|
|
420
|
+
blocked_direct_edits=[
|
|
421
|
+
"output/intermediate/candidate_claims.json",
|
|
422
|
+
"output/intermediate/screened_candidates.json",
|
|
423
|
+
"output/intermediate/claim_ledger.json",
|
|
424
|
+
"output/intermediate/audited_brief.md",
|
|
425
|
+
"output/intermediate/audit_report.json",
|
|
426
|
+
],
|
|
427
|
+
reason=_reason(finding, "source pack missing raw excerpt/snippet"),
|
|
428
|
+
source=finding,
|
|
429
|
+
)
|
|
430
|
+
|
|
431
|
+
if _is_claim_ledger_issue(text, finding_type, artifact_id):
|
|
432
|
+
return _route(
|
|
433
|
+
repair_owner="claim-ledger",
|
|
434
|
+
allowed_artifacts=["output/intermediate/claim_ledger.json"],
|
|
435
|
+
must_rerun_from="analyst",
|
|
436
|
+
blocked_direct_edits=[
|
|
437
|
+
"output/intermediate/audited_brief.md",
|
|
438
|
+
"output/intermediate/audit_report.json",
|
|
439
|
+
],
|
|
440
|
+
reason=_reason(finding, "claim ledger schema/support issue"),
|
|
441
|
+
source=finding,
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
if _is_audited_brief_binding_issue(finding_type, artifact_id):
|
|
445
|
+
return _route(
|
|
446
|
+
repair_owner="editor",
|
|
447
|
+
allowed_artifacts=["output/intermediate/audited_brief.md"],
|
|
448
|
+
must_rerun_from="auditor",
|
|
449
|
+
blocked_direct_edits=[
|
|
450
|
+
"output/intermediate/claim_ledger.json",
|
|
451
|
+
"output/intermediate/audit_report.json",
|
|
452
|
+
],
|
|
453
|
+
reason=_reason(finding, "audited brief claim binding issue"),
|
|
454
|
+
source=finding,
|
|
455
|
+
)
|
|
456
|
+
return None
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def _explicit_repair_route(finding: dict[str, Any]) -> dict[str, Any] | None:
|
|
460
|
+
owner = _normalize_owner(finding.get("repair_stage_id") or finding.get("repair_owner"))
|
|
461
|
+
if owner is None:
|
|
462
|
+
return None
|
|
463
|
+
repair_artifact = _repair_artifact_path(finding.get("repair_artifact_id"))
|
|
464
|
+
if owner == "analyst" and repair_artifact == "output/intermediate/audited_brief.md":
|
|
465
|
+
owner = "editor"
|
|
466
|
+
if owner == "source-discovery":
|
|
467
|
+
allowed_artifacts = STAGE_REPAIR_ARTIFACTS[owner]
|
|
468
|
+
else:
|
|
469
|
+
allowed_artifacts = [repair_artifact] if repair_artifact else STAGE_REPAIR_ARTIFACTS.get(owner, [])
|
|
470
|
+
if not allowed_artifacts:
|
|
471
|
+
return None
|
|
472
|
+
return _route(
|
|
473
|
+
repair_owner=owner,
|
|
474
|
+
allowed_artifacts=allowed_artifacts,
|
|
475
|
+
must_rerun_from=RERUN_FROM_BY_OWNER.get(owner, ""),
|
|
476
|
+
blocked_direct_edits=DOWNSTREAM_BLOCKED_EDITS.get(owner, []),
|
|
477
|
+
reason=_reason(finding, f"{owner} repair required"),
|
|
478
|
+
source=finding,
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
def _normalize_owner(value: Any) -> str | None:
|
|
483
|
+
if not isinstance(value, str):
|
|
484
|
+
return None
|
|
485
|
+
key = value.strip().lower().replace(" ", "-")
|
|
486
|
+
if not key:
|
|
487
|
+
return None
|
|
488
|
+
return OWNER_ALIASES.get(key)
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
def _repair_artifact_path(value: Any) -> str | None:
|
|
492
|
+
if not isinstance(value, str):
|
|
493
|
+
return None
|
|
494
|
+
artifact_id = value.strip()
|
|
495
|
+
if not artifact_id:
|
|
496
|
+
return None
|
|
497
|
+
if "/" in artifact_id or artifact_id.startswith("input/"):
|
|
498
|
+
return artifact_id
|
|
499
|
+
return ARTIFACT_PATHS.get(artifact_id)
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def _is_source_pack_missing_excerpt(text: str, finding_type: str) -> bool:
|
|
503
|
+
if "source" not in text and "raw_excerpt" not in text and "snippet" not in text:
|
|
504
|
+
return False
|
|
505
|
+
return (
|
|
506
|
+
"raw_excerpt" in text
|
|
507
|
+
or "raw excerpt" in text
|
|
508
|
+
or "snippet" in text
|
|
509
|
+
or "missing_raw_excerpt" in finding_type
|
|
510
|
+
or "missing_snippet" in finding_type
|
|
511
|
+
)
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
def _is_claim_ledger_issue(text: str, finding_type: str, artifact_id: str) -> bool:
|
|
515
|
+
if artifact_id == "claim_ledger":
|
|
516
|
+
return True
|
|
517
|
+
if "claim_ledger" not in text and "claim ledger" not in text:
|
|
518
|
+
return False
|
|
519
|
+
return any(token in text or token in finding_type for token in ("schema", "support", "invalid", "missing support"))
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
def _is_input_limitation_finding(finding: dict[str, Any]) -> bool:
|
|
523
|
+
finding_type = str(finding.get("finding_type") or finding.get("category") or "").lower()
|
|
524
|
+
return finding_type in {"insufficient_claims", "no_reportable_claims"}
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
def _input_limitation_route(finding: dict[str, Any]) -> dict[str, Any]:
|
|
528
|
+
return {
|
|
529
|
+
"repair_owner": "none",
|
|
530
|
+
"allowed_artifacts": [],
|
|
531
|
+
"must_rerun_from": "",
|
|
532
|
+
"blocked_direct_edits": [
|
|
533
|
+
"output/intermediate/claim_ledger.json",
|
|
534
|
+
"output/intermediate/audited_brief.md",
|
|
535
|
+
"output/intermediate/audit_report.json",
|
|
536
|
+
],
|
|
537
|
+
"reason": _reason(finding, "Input limitation requires human review or a fresh evidence setup."),
|
|
538
|
+
"recommended_action": "request_human_review_or_start_fresh_workspace",
|
|
539
|
+
"run_integrity_effect": None,
|
|
540
|
+
"source": {
|
|
541
|
+
"file": finding.get("_source_path"),
|
|
542
|
+
"kind": finding.get("_source"),
|
|
543
|
+
"stage_id": finding.get("_source_stage_id") or finding.get("gate_stage_id") or finding.get("stage_id"),
|
|
544
|
+
"finding_id": finding.get("finding_id") or finding.get("id"),
|
|
545
|
+
"finding_type": finding.get("finding_type") or finding.get("category"),
|
|
546
|
+
"artifact_id": finding.get("artifact_id"),
|
|
547
|
+
"route_classification": "input_limitation",
|
|
548
|
+
},
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
def _is_audited_brief_binding_issue(finding_type: str, artifact_id: str) -> bool:
|
|
553
|
+
return (
|
|
554
|
+
finding_type in {"unsupported_claim", "claim_binding_imprecise"}
|
|
555
|
+
and artifact_id in {"", "audited_brief"}
|
|
556
|
+
)
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
def _route(
|
|
560
|
+
*,
|
|
561
|
+
repair_owner: str,
|
|
562
|
+
allowed_artifacts: list[str],
|
|
563
|
+
must_rerun_from: str,
|
|
564
|
+
blocked_direct_edits: list[str],
|
|
565
|
+
reason: str,
|
|
566
|
+
source: dict[str, Any],
|
|
567
|
+
) -> dict[str, Any]:
|
|
568
|
+
return {
|
|
569
|
+
"repair_owner": repair_owner,
|
|
570
|
+
"allowed_artifacts": allowed_artifacts,
|
|
571
|
+
"must_rerun_from": must_rerun_from,
|
|
572
|
+
"blocked_direct_edits": blocked_direct_edits,
|
|
573
|
+
"reason": reason,
|
|
574
|
+
"recommended_action": source.get("recommended_action"),
|
|
575
|
+
"run_integrity_effect": source.get("run_integrity_effect"),
|
|
576
|
+
"source": {
|
|
577
|
+
"file": source.get("_source_path"),
|
|
578
|
+
"kind": source.get("_source"),
|
|
579
|
+
"stage_id": source.get("_source_stage_id") or source.get("gate_stage_id") or source.get("stage_id"),
|
|
580
|
+
"finding_id": source.get("finding_id") or source.get("id"),
|
|
581
|
+
"finding_type": source.get("finding_type") or source.get("category"),
|
|
582
|
+
"artifact_id": source.get("artifact_id"),
|
|
583
|
+
"severity": source.get("severity"),
|
|
584
|
+
"status": source.get("_report_status") or source.get("status") or source.get("audit_status"),
|
|
585
|
+
"blocking": source.get("blocking"),
|
|
586
|
+
},
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
def _no_route() -> dict[str, Any]:
|
|
591
|
+
return {
|
|
592
|
+
"repair_owner": "none",
|
|
593
|
+
"allowed_artifacts": [],
|
|
594
|
+
"must_rerun_from": "",
|
|
595
|
+
"blocked_direct_edits": [],
|
|
596
|
+
"reason": "No deterministic repair route found.",
|
|
597
|
+
"recommended_action": "start_fresh_workspace_or_request_human_review",
|
|
598
|
+
"run_integrity_effect": None,
|
|
599
|
+
"source": {},
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
def _no_legal_route() -> dict[str, Any]:
|
|
604
|
+
route = _no_route()
|
|
605
|
+
route["ok"] = False
|
|
606
|
+
route["error_code"] = "E_REPAIR_NO_LEGAL_ROUTE"
|
|
607
|
+
route["message"] = (
|
|
608
|
+
"No legal deterministic repair route found. Available routes target imported frozen fact-layer "
|
|
609
|
+
"artifacts or require human review."
|
|
610
|
+
)
|
|
611
|
+
route["reason"] = (
|
|
612
|
+
"No legal deterministic repair route found. Available routes target imported frozen fact-layer "
|
|
613
|
+
"artifacts or require human review."
|
|
614
|
+
)
|
|
615
|
+
route["recommended_action"] = "start_fresh_workspace_or_request_human_review"
|
|
616
|
+
route["no_legal_route"] = True
|
|
617
|
+
return route
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
def _workspace_has_fact_layer_import(payloads: dict[str, dict[str, Any]]) -> bool:
|
|
621
|
+
manifest = payloads.get("runtime_manifest")
|
|
622
|
+
return isinstance(manifest, dict) and isinstance(manifest.get("fact_layer_import"), dict)
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
def _annotated_routes(routes: list[dict[str, Any]], *, imported_fact_layer: bool) -> list[dict[str, Any]]:
|
|
626
|
+
annotated: list[dict[str, Any]] = []
|
|
627
|
+
for rank, route in enumerate(routes):
|
|
628
|
+
item = dict(route)
|
|
629
|
+
forbidden = imported_fact_layer and _route_targets_imported_fact_layer(item)
|
|
630
|
+
item["route_rank"] = rank
|
|
631
|
+
item["is_blocking"] = _route_is_blocking(item)
|
|
632
|
+
item["is_imported_fact_layer_forbidden"] = forbidden
|
|
633
|
+
item["default_selected"] = False
|
|
634
|
+
annotated.append(item)
|
|
635
|
+
default = _default_selected_route(annotated)
|
|
636
|
+
if default is not None:
|
|
637
|
+
default["default_selected"] = True
|
|
638
|
+
return annotated
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
def _select_route(
|
|
642
|
+
routes: list[dict[str, Any]],
|
|
643
|
+
*,
|
|
644
|
+
route_index: int | None,
|
|
645
|
+
finding_id: str | None,
|
|
646
|
+
) -> dict[str, Any]:
|
|
647
|
+
if finding_id is not None:
|
|
648
|
+
for route in routes:
|
|
649
|
+
source = route.get("source") if isinstance(route.get("source"), dict) else {}
|
|
650
|
+
if source.get("finding_id") == finding_id:
|
|
651
|
+
return _selected_route_or_forbidden_error(route)
|
|
652
|
+
return {
|
|
653
|
+
"ok": False,
|
|
654
|
+
"error_code": "E_REPAIR_ROUTE_NOT_FOUND",
|
|
655
|
+
"message": f"No deterministic repair route found for finding_id '{finding_id}'.",
|
|
656
|
+
}
|
|
657
|
+
if route_index is not None:
|
|
658
|
+
if route_index < 0 or route_index >= len(routes):
|
|
659
|
+
return {
|
|
660
|
+
"ok": False,
|
|
661
|
+
"error_code": "E_REPAIR_ROUTE_NOT_FOUND",
|
|
662
|
+
"message": f"No deterministic repair route found for route_index {route_index}.",
|
|
663
|
+
}
|
|
664
|
+
return _selected_route_or_forbidden_error(routes[route_index])
|
|
665
|
+
if not routes:
|
|
666
|
+
return _no_route()
|
|
667
|
+
selected = _default_selected_route(routes)
|
|
668
|
+
return selected if selected is not None else _no_legal_route()
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
def _selected_route_or_forbidden_error(route: dict[str, Any]) -> dict[str, Any]:
|
|
672
|
+
if route.get("is_imported_fact_layer_forbidden") is not True:
|
|
673
|
+
return route
|
|
674
|
+
source = route.get("source") if isinstance(route.get("source"), dict) else {}
|
|
675
|
+
finding_id = source.get("finding_id") or source.get("finding_type") or "<unknown>"
|
|
676
|
+
return {
|
|
677
|
+
"ok": False,
|
|
678
|
+
"error_code": "E_REPAIR_IMPORTED_FACT_LAYER_FORBIDDEN",
|
|
679
|
+
"message": (
|
|
680
|
+
f"Repair route '{finding_id}' targets imported frozen fact-layer artifacts. "
|
|
681
|
+
"Start a fresh condition workspace or use human review; do not repair imported fact layer artifacts in place."
|
|
682
|
+
),
|
|
683
|
+
"selected_route": route,
|
|
684
|
+
"allowed_artifacts": list(route.get("allowed_artifacts") or []),
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
def _default_selected_route(routes: list[dict[str, Any]]) -> dict[str, Any] | None:
|
|
689
|
+
if not routes:
|
|
690
|
+
return None
|
|
691
|
+
first = routes[0]
|
|
692
|
+
source = first.get("source") if isinstance(first.get("source"), dict) else {}
|
|
693
|
+
if source.get("route_classification") == "input_limitation":
|
|
694
|
+
return first
|
|
695
|
+
for route in routes:
|
|
696
|
+
if route.get("repair_owner") in {None, "", "none"}:
|
|
697
|
+
continue
|
|
698
|
+
if route.get("is_imported_fact_layer_forbidden") is True:
|
|
699
|
+
continue
|
|
700
|
+
return route
|
|
701
|
+
return None
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
def _route_priority(route: dict[str, Any]) -> tuple[int, int, int, str, str]:
|
|
705
|
+
source = route.get("source") if isinstance(route.get("source"), dict) else {}
|
|
706
|
+
kind = str(source.get("kind") or "")
|
|
707
|
+
finding_type = str(source.get("finding_type") or "")
|
|
708
|
+
repair_owner = str(route.get("repair_owner") or "")
|
|
709
|
+
if source.get("route_classification") == "input_limitation":
|
|
710
|
+
return (0, 0, 0, kind, finding_type)
|
|
711
|
+
blocking_priority = 0 if _route_is_blocking(route) else 1
|
|
712
|
+
kind_priority = {
|
|
713
|
+
"transaction_integrity": 0,
|
|
714
|
+
"auditor_quality_gate_report": 1,
|
|
715
|
+
"quality_gate_report": 1,
|
|
716
|
+
"finalize_quality_gate_report": 2,
|
|
717
|
+
"audit_report": 3,
|
|
718
|
+
"finalize_report": 4,
|
|
719
|
+
"artifact_registry": 5,
|
|
720
|
+
}.get(kind, 20)
|
|
721
|
+
if finding_type == "frozen_artifact_changed":
|
|
722
|
+
kind_priority = 0
|
|
723
|
+
if repair_owner == "none":
|
|
724
|
+
kind_priority = 90
|
|
725
|
+
finding_id = str(source.get("finding_id") or "")
|
|
726
|
+
return (1, blocking_priority, kind_priority, finding_id, finding_type)
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
def _route_is_blocking(route: dict[str, Any]) -> bool:
|
|
730
|
+
source = route.get("source") if isinstance(route.get("source"), dict) else {}
|
|
731
|
+
kind = str(source.get("kind") or "")
|
|
732
|
+
finding_type = str(source.get("finding_type") or "")
|
|
733
|
+
status = str(source.get("status") or "").lower()
|
|
734
|
+
severity = str(source.get("severity") or "").lower()
|
|
735
|
+
blocking = source.get("blocking")
|
|
736
|
+
if source.get("route_classification") == "input_limitation":
|
|
737
|
+
return True
|
|
738
|
+
if kind == "transaction_integrity" or finding_type == "frozen_artifact_changed":
|
|
739
|
+
return True
|
|
740
|
+
if isinstance(blocking, bool):
|
|
741
|
+
return blocking
|
|
742
|
+
if status in {"fail", "failed", "block", "blocked", "blocking"}:
|
|
743
|
+
return True
|
|
744
|
+
if kind in {"auditor_quality_gate_report", "finalize_quality_gate_report", "quality_gate_report"}:
|
|
745
|
+
return severity in {"high", "critical", "blocker", "blocking"}
|
|
746
|
+
if kind == "audit_report":
|
|
747
|
+
return severity in {"high", "critical", "blocker", "blocking"} or status in {"fail", "block", "blocking"}
|
|
748
|
+
return False
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
def _route_targets_imported_fact_layer(route: dict[str, Any]) -> bool:
|
|
752
|
+
for artifact in route.get("allowed_artifacts") or []:
|
|
753
|
+
if _path_targets_imported_fact_layer(str(artifact)):
|
|
754
|
+
return True
|
|
755
|
+
return False
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
def _path_targets_imported_fact_layer(path_or_pattern: str) -> bool:
|
|
759
|
+
normalized = path_or_pattern.strip().replace("\\", "/")
|
|
760
|
+
if not normalized:
|
|
761
|
+
return False
|
|
762
|
+
if normalized in {"input/sources", "input/sources/*"}:
|
|
763
|
+
return True
|
|
764
|
+
if normalized in IMPORTED_FACT_LAYER_FORBIDDEN_ARTIFACTS:
|
|
765
|
+
return True
|
|
766
|
+
stripped = normalized.rstrip("*")
|
|
767
|
+
return any(stripped.startswith(prefix) for prefix in IMPORTED_FACT_LAYER_FORBIDDEN_PREFIXES)
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
def _with_run_integrity_context(route: dict[str, Any], workflow: dict[str, Any] | None) -> dict[str, Any]:
|
|
771
|
+
if not isinstance(workflow, dict):
|
|
772
|
+
return route
|
|
773
|
+
integrity = workflow.get("run_integrity")
|
|
774
|
+
if not isinstance(integrity, dict):
|
|
775
|
+
return route
|
|
776
|
+
status = str(integrity.get("status") or "")
|
|
777
|
+
if status in {"", "clean"} and integrity.get("reference_eligible", True) is True:
|
|
778
|
+
return route
|
|
779
|
+
updated = dict(route)
|
|
780
|
+
existing_effect = updated.get("run_integrity_effect")
|
|
781
|
+
if not isinstance(existing_effect, dict):
|
|
782
|
+
existing_effect = {}
|
|
783
|
+
updated["run_integrity_effect"] = {
|
|
784
|
+
**existing_effect,
|
|
785
|
+
"status": status or "unknown",
|
|
786
|
+
"reference_eligible": False,
|
|
787
|
+
"reason": (
|
|
788
|
+
"This run is already non-reference-eligible. Repair can support local inspection "
|
|
789
|
+
"but cannot restore clean reference eligibility."
|
|
790
|
+
),
|
|
791
|
+
}
|
|
792
|
+
recommended = updated.get("recommended_action")
|
|
793
|
+
if not isinstance(recommended, str) or not recommended.strip():
|
|
794
|
+
recommended = "repair_for_local_inspection_or_start_fresh_workspace"
|
|
795
|
+
elif "local inspection" not in recommended:
|
|
796
|
+
recommended = f"{recommended}; repair is local inspection only for this non-reference run"
|
|
797
|
+
updated["recommended_action"] = recommended
|
|
798
|
+
return updated
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
def _dedupe_findings(findings: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
802
|
+
seen: set[tuple[str, str, str]] = set()
|
|
803
|
+
deduped: list[dict[str, Any]] = []
|
|
804
|
+
for finding in findings:
|
|
805
|
+
key = (
|
|
806
|
+
str(finding.get("finding_id") or finding.get("id") or ""),
|
|
807
|
+
str(finding.get("finding_type") or finding.get("category") or ""),
|
|
808
|
+
str(finding.get("artifact_id") or finding.get("repair_artifact_id") or ""),
|
|
809
|
+
)
|
|
810
|
+
if key in seen:
|
|
811
|
+
continue
|
|
812
|
+
seen.add(key)
|
|
813
|
+
deduped.append(finding)
|
|
814
|
+
return deduped
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
def _finding_text(finding: dict[str, Any]) -> str:
|
|
818
|
+
fields = [
|
|
819
|
+
finding.get("finding_type"),
|
|
820
|
+
finding.get("category"),
|
|
821
|
+
finding.get("message"),
|
|
822
|
+
finding.get("summary"),
|
|
823
|
+
finding.get("description"),
|
|
824
|
+
finding.get("artifact_id"),
|
|
825
|
+
finding.get("repair_artifact_id"),
|
|
826
|
+
]
|
|
827
|
+
return " ".join(str(item).lower() for item in fields if item)
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
def _reason(finding: dict[str, Any], fallback: str) -> str:
|
|
831
|
+
for key in ("message", "summary", "description", "reason"):
|
|
832
|
+
value = finding.get(key)
|
|
833
|
+
if isinstance(value, str) and value.strip():
|
|
834
|
+
return " ".join(value.split())[:400]
|
|
835
|
+
return fallback
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
def _workspace_relative(workspace: Path, path: Path) -> str:
|
|
839
|
+
try:
|
|
840
|
+
return path.resolve().relative_to(workspace.resolve()).as_posix()
|
|
841
|
+
except ValueError:
|
|
842
|
+
return path.as_posix()
|