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,888 @@
|
|
|
1
|
+
"""Immutable finalized run archive support."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import shutil
|
|
9
|
+
import uuid
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from multi_agent_brief.orchestrator.run_integrity import interpret_run_integrity, project_for_read
|
|
14
|
+
from multi_agent_brief.orchestrator.runtime_state.evidence_span_registry import (
|
|
15
|
+
EVIDENCE_SPAN_REGISTRY_VALIDATION_PREFIX,
|
|
16
|
+
validate_evidence_span_registry_against_source_pack,
|
|
17
|
+
)
|
|
18
|
+
from multi_agent_brief.orchestrator.source_evidence import is_evidence_input_path
|
|
19
|
+
from multi_agent_brief.orchestrator.timing import derive_control_timing_from_path
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
RUN_ARCHIVE_SCHEMA = "mabw.run_archive.v1"
|
|
23
|
+
RUN_ARCHIVE_FACT_LAYER_SCHEMA = "mabw.run_archive.fact_layer.v1"
|
|
24
|
+
RUN_ARCHIVE_EVIDENCE_SPAN_REGISTRY_SCHEMA = "mabw.run_archive.evidence_span_registry.v1"
|
|
25
|
+
E_RUN_ARCHIVE_CONFLICT = "E_RUN_ARCHIVE_CONFLICT"
|
|
26
|
+
E_RUN_ARCHIVE_FAILED = "E_RUN_ARCHIVE_FAILED"
|
|
27
|
+
|
|
28
|
+
_KNOWN_INTERMEDIATE_FILES = (
|
|
29
|
+
"candidate_claims.json",
|
|
30
|
+
"screened_candidates.json",
|
|
31
|
+
"claim_ledger.json",
|
|
32
|
+
"analyst_draft_snapshot.md",
|
|
33
|
+
"audited_brief.md",
|
|
34
|
+
"audit_report.json",
|
|
35
|
+
"gates/auditor_quality_gate_report.json",
|
|
36
|
+
"gates/finalize_quality_gate_report.json",
|
|
37
|
+
"quality_gate_report.json",
|
|
38
|
+
"finalize_report.json",
|
|
39
|
+
)
|
|
40
|
+
_CONTROL_FILES = (
|
|
41
|
+
"runtime_manifest.json",
|
|
42
|
+
"workflow_state.json",
|
|
43
|
+
"artifact_registry.json",
|
|
44
|
+
"event_log.jsonl",
|
|
45
|
+
)
|
|
46
|
+
_FACT_LAYER_REQUIRED_ARTIFACTS: dict[str, str] = {
|
|
47
|
+
"input_classification": "output/input_classification.json",
|
|
48
|
+
"candidate_claims": "output/intermediate/candidate_claims.json",
|
|
49
|
+
"screened_candidates": "output/intermediate/screened_candidates.json",
|
|
50
|
+
"claim_ledger": "output/intermediate/claim_ledger.json",
|
|
51
|
+
}
|
|
52
|
+
_FACT_LAYER_SOURCE_ARTIFACT_ID = "durable_source_evidence_or_source_pack"
|
|
53
|
+
_SOURCE_PLAN_EXCLUDED_ARTIFACT_ID = "source_candidates"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class RunArchiveError(Exception):
|
|
57
|
+
"""Raised when a finalized run cannot be archived safely."""
|
|
58
|
+
|
|
59
|
+
def __init__(self, message: str, *, details: dict[str, Any] | None = None, error_code: str = E_RUN_ARCHIVE_FAILED) -> None:
|
|
60
|
+
super().__init__(message)
|
|
61
|
+
self.details = details or {}
|
|
62
|
+
self.error_code = error_code
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def archive_finalized_run(
|
|
66
|
+
*,
|
|
67
|
+
workspace: Path,
|
|
68
|
+
run_id: str,
|
|
69
|
+
manifest: dict[str, Any],
|
|
70
|
+
workflow: dict[str, Any],
|
|
71
|
+
artifact_registry: dict[str, Any],
|
|
72
|
+
finalize_report: dict[str, Any],
|
|
73
|
+
fast_rerun_freshness_at_finalize: dict[str, Any] | None = None,
|
|
74
|
+
) -> dict[str, Any]:
|
|
75
|
+
"""Create or verify the immutable archive for a finalized run."""
|
|
76
|
+
ws = workspace.expanduser().resolve()
|
|
77
|
+
archive_root = ws / "output" / "runs" / run_id
|
|
78
|
+
archive_plan = _archive_plan(
|
|
79
|
+
workspace=ws,
|
|
80
|
+
finalize_report=finalize_report,
|
|
81
|
+
artifact_registry=artifact_registry,
|
|
82
|
+
)
|
|
83
|
+
files = archive_plan["files"]
|
|
84
|
+
fast_rerun = _fast_rerun_for_manifest(
|
|
85
|
+
manifest,
|
|
86
|
+
freshness_at_finalize=fast_rerun_freshness_at_finalize,
|
|
87
|
+
)
|
|
88
|
+
evidence_span_registry = archive_plan["evidence_span_registry"]
|
|
89
|
+
archive_manifest = {
|
|
90
|
+
"schema_version": RUN_ARCHIVE_SCHEMA,
|
|
91
|
+
"run_id": run_id,
|
|
92
|
+
"archived_at": _utc_now(),
|
|
93
|
+
"source": "finalize-complete",
|
|
94
|
+
"runtime_manifest_run_id": manifest.get("run_id"),
|
|
95
|
+
"workflow_current_stage": workflow.get("current_stage"),
|
|
96
|
+
"run_integrity": _run_integrity_for_manifest(workflow),
|
|
97
|
+
"timing": _timing_for_manifest(ws, workflow),
|
|
98
|
+
"fast_rerun": fast_rerun,
|
|
99
|
+
"fact_layer": archive_plan["fact_layer"],
|
|
100
|
+
"event_log_semantics": "copied_before_current_archive_event",
|
|
101
|
+
"files": files,
|
|
102
|
+
}
|
|
103
|
+
if evidence_span_registry is not None:
|
|
104
|
+
archive_manifest["evidence_span_registry"] = evidence_span_registry
|
|
105
|
+
if archive_root.exists():
|
|
106
|
+
_verify_existing_archive_matches_plan(
|
|
107
|
+
archive_root=archive_root,
|
|
108
|
+
planned_files=files,
|
|
109
|
+
planned_fact_layer=archive_plan["fact_layer"],
|
|
110
|
+
planned_fast_rerun=fast_rerun,
|
|
111
|
+
planned_evidence_span_registry=evidence_span_registry,
|
|
112
|
+
)
|
|
113
|
+
return _archive_result(archive_root)
|
|
114
|
+
|
|
115
|
+
tmp_root = ws / "output" / "runs" / f".tmp-{run_id}-{uuid.uuid4().hex}"
|
|
116
|
+
try:
|
|
117
|
+
tmp_root.mkdir(parents=True, exist_ok=False)
|
|
118
|
+
for record in files:
|
|
119
|
+
src = ws / str(record["original_path"])
|
|
120
|
+
dst = tmp_root / str(record["archive_path"])
|
|
121
|
+
dst.parent.mkdir(parents=True, exist_ok=True)
|
|
122
|
+
shutil.copy2(src, dst)
|
|
123
|
+
copied_sha = _sha256_file(dst)
|
|
124
|
+
if copied_sha != record["sha256"]:
|
|
125
|
+
raise RunArchiveError(
|
|
126
|
+
"Copied archive file hash does not match source hash.",
|
|
127
|
+
details={
|
|
128
|
+
"archive_path": record["archive_path"],
|
|
129
|
+
"expected_sha256": record["sha256"],
|
|
130
|
+
"actual_sha256": copied_sha,
|
|
131
|
+
},
|
|
132
|
+
)
|
|
133
|
+
_write_manifest(tmp_root / "manifest.json", archive_manifest)
|
|
134
|
+
os.replace(tmp_root, archive_root)
|
|
135
|
+
except Exception:
|
|
136
|
+
if tmp_root.exists():
|
|
137
|
+
shutil.rmtree(tmp_root, ignore_errors=True)
|
|
138
|
+
raise
|
|
139
|
+
return _archive_result(archive_root)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def preflight_finalized_run_archive(
|
|
143
|
+
*,
|
|
144
|
+
workspace: Path,
|
|
145
|
+
run_id: str,
|
|
146
|
+
manifest: dict[str, Any],
|
|
147
|
+
workflow: dict[str, Any],
|
|
148
|
+
artifact_registry: dict[str, Any],
|
|
149
|
+
finalize_report: dict[str, Any],
|
|
150
|
+
fast_rerun_freshness_at_finalize: dict[str, Any] | None = None,
|
|
151
|
+
) -> dict[str, Any]:
|
|
152
|
+
"""Validate whether the finalized run archive can be created without mutating state."""
|
|
153
|
+
ws = workspace.expanduser().resolve()
|
|
154
|
+
archive_root = ws / "output" / "runs" / run_id
|
|
155
|
+
archive_plan = _archive_plan(
|
|
156
|
+
workspace=ws,
|
|
157
|
+
finalize_report=finalize_report,
|
|
158
|
+
artifact_registry=artifact_registry,
|
|
159
|
+
)
|
|
160
|
+
files = archive_plan["files"]
|
|
161
|
+
fast_rerun = _fast_rerun_for_manifest(
|
|
162
|
+
manifest,
|
|
163
|
+
freshness_at_finalize=fast_rerun_freshness_at_finalize,
|
|
164
|
+
)
|
|
165
|
+
evidence_span_registry = archive_plan["evidence_span_registry"]
|
|
166
|
+
if archive_root.exists():
|
|
167
|
+
return _verify_existing_archive_matches_plan(
|
|
168
|
+
archive_root=archive_root,
|
|
169
|
+
planned_files=files,
|
|
170
|
+
planned_fact_layer=archive_plan["fact_layer"],
|
|
171
|
+
planned_fast_rerun=fast_rerun,
|
|
172
|
+
planned_evidence_span_registry=evidence_span_registry,
|
|
173
|
+
)
|
|
174
|
+
result: dict[str, Any] = {
|
|
175
|
+
"archive_path": str(archive_root),
|
|
176
|
+
"file_count": len(files),
|
|
177
|
+
"would_create": True,
|
|
178
|
+
"run_id": run_id,
|
|
179
|
+
"runtime_manifest_run_id": manifest.get("run_id"),
|
|
180
|
+
"workflow_current_stage": workflow.get("current_stage"),
|
|
181
|
+
"run_integrity": _run_integrity_for_manifest(workflow),
|
|
182
|
+
"timing": _timing_for_manifest(ws, workflow),
|
|
183
|
+
"fast_rerun": fast_rerun,
|
|
184
|
+
"fact_layer": archive_plan["fact_layer"],
|
|
185
|
+
}
|
|
186
|
+
if evidence_span_registry is not None:
|
|
187
|
+
result["evidence_span_registry"] = evidence_span_registry
|
|
188
|
+
return result
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _archive_plan(
|
|
192
|
+
*,
|
|
193
|
+
workspace: Path,
|
|
194
|
+
finalize_report: dict[str, Any],
|
|
195
|
+
artifact_registry: dict[str, Any],
|
|
196
|
+
) -> dict[str, Any]:
|
|
197
|
+
records: list[dict[str, Any]] = []
|
|
198
|
+
seen_archive_paths: set[str] = set()
|
|
199
|
+
delivery_count = 0
|
|
200
|
+
for raw_path in finalize_report.get("delivery_artifacts") or []:
|
|
201
|
+
source = _resolve_workspace_file(workspace, raw_path)
|
|
202
|
+
try:
|
|
203
|
+
rel_from_delivery = source.relative_to(workspace / "output" / "delivery")
|
|
204
|
+
except ValueError as exc:
|
|
205
|
+
raise RunArchiveError(
|
|
206
|
+
"Finalize report contains a delivery artifact outside output/delivery.",
|
|
207
|
+
details={"artifact": str(raw_path)},
|
|
208
|
+
) from exc
|
|
209
|
+
_add_file_record(
|
|
210
|
+
records,
|
|
211
|
+
seen_archive_paths,
|
|
212
|
+
role="delivery",
|
|
213
|
+
source=source,
|
|
214
|
+
original_path=_workspace_relative(workspace, source),
|
|
215
|
+
archive_path=Path("delivery") / rel_from_delivery,
|
|
216
|
+
)
|
|
217
|
+
delivery_count += 1
|
|
218
|
+
if delivery_count == 0:
|
|
219
|
+
raise RunArchiveError(
|
|
220
|
+
"finalize_report.json must list at least one delivery artifact for run archive.",
|
|
221
|
+
details={"field": "delivery_artifacts"},
|
|
222
|
+
)
|
|
223
|
+
_add_finalize_auxiliary_records(
|
|
224
|
+
records=records,
|
|
225
|
+
seen_archive_paths=seen_archive_paths,
|
|
226
|
+
workspace=workspace,
|
|
227
|
+
finalize_report=finalize_report,
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
intermediate_dir = workspace / "output" / "intermediate"
|
|
231
|
+
for name in _KNOWN_INTERMEDIATE_FILES:
|
|
232
|
+
rel_from_intermediate = Path(name)
|
|
233
|
+
source = intermediate_dir / rel_from_intermediate
|
|
234
|
+
if source.exists() and source.is_file():
|
|
235
|
+
_add_file_record(
|
|
236
|
+
records,
|
|
237
|
+
seen_archive_paths,
|
|
238
|
+
role="intermediate",
|
|
239
|
+
source=source,
|
|
240
|
+
original_path=_workspace_relative(workspace, source),
|
|
241
|
+
archive_path=Path("intermediate") / rel_from_intermediate,
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
artifacts = artifact_registry.get("artifacts") if isinstance(artifact_registry.get("artifacts"), dict) else {}
|
|
245
|
+
for artifact_id, artifact in sorted(artifacts.items()):
|
|
246
|
+
if not isinstance(artifact, dict):
|
|
247
|
+
continue
|
|
248
|
+
rel_path = str(artifact.get("path") or "")
|
|
249
|
+
if not rel_path.startswith("output/intermediate/"):
|
|
250
|
+
continue
|
|
251
|
+
source = workspace / rel_path
|
|
252
|
+
if not source.exists() or not source.is_file():
|
|
253
|
+
continue
|
|
254
|
+
try:
|
|
255
|
+
rel_from_intermediate = source.relative_to(intermediate_dir)
|
|
256
|
+
except ValueError:
|
|
257
|
+
rel_from_intermediate = Path(source.name)
|
|
258
|
+
archive_path = Path("intermediate") / rel_from_intermediate
|
|
259
|
+
_add_file_record(
|
|
260
|
+
records,
|
|
261
|
+
seen_archive_paths,
|
|
262
|
+
role="intermediate",
|
|
263
|
+
source=source,
|
|
264
|
+
original_path=rel_path,
|
|
265
|
+
archive_path=archive_path,
|
|
266
|
+
artifact_id=str(artifact_id),
|
|
267
|
+
)
|
|
268
|
+
evidence_span_registry = intermediate_dir / "evidence_span_registry.json"
|
|
269
|
+
if evidence_span_registry.exists() and evidence_span_registry.is_file():
|
|
270
|
+
_add_file_record(
|
|
271
|
+
records,
|
|
272
|
+
seen_archive_paths,
|
|
273
|
+
role="intermediate",
|
|
274
|
+
source=evidence_span_registry,
|
|
275
|
+
original_path=_workspace_relative(workspace, evidence_span_registry),
|
|
276
|
+
archive_path=Path("intermediate") / "evidence_span_registry.json",
|
|
277
|
+
artifact_id="evidence_span_registry",
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
fact_layer = _add_fact_layer_records(
|
|
281
|
+
records=records,
|
|
282
|
+
seen_archive_paths=seen_archive_paths,
|
|
283
|
+
workspace=workspace,
|
|
284
|
+
)
|
|
285
|
+
evidence_span_registry = _evidence_span_registry_projection(
|
|
286
|
+
workspace=workspace,
|
|
287
|
+
artifact_registry=artifact_registry,
|
|
288
|
+
records=records,
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
for name in _CONTROL_FILES:
|
|
292
|
+
source = intermediate_dir / name
|
|
293
|
+
if source.exists() and source.is_file():
|
|
294
|
+
_add_file_record(
|
|
295
|
+
records,
|
|
296
|
+
seen_archive_paths,
|
|
297
|
+
role="control",
|
|
298
|
+
source=source,
|
|
299
|
+
original_path=_workspace_relative(workspace, source),
|
|
300
|
+
archive_path=Path("control") / name,
|
|
301
|
+
)
|
|
302
|
+
return {
|
|
303
|
+
"files": records,
|
|
304
|
+
"fact_layer": fact_layer,
|
|
305
|
+
"evidence_span_registry": evidence_span_registry,
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def _add_fact_layer_records(
|
|
310
|
+
*,
|
|
311
|
+
records: list[dict[str, Any]],
|
|
312
|
+
seen_archive_paths: set[str],
|
|
313
|
+
workspace: Path,
|
|
314
|
+
) -> dict[str, Any]:
|
|
315
|
+
artifacts: list[dict[str, Any]] = []
|
|
316
|
+
excluded: list[dict[str, Any]] = []
|
|
317
|
+
missing: list[str] = []
|
|
318
|
+
|
|
319
|
+
source_files = _iter_durable_source_files(workspace)
|
|
320
|
+
if not source_files:
|
|
321
|
+
missing.append(_FACT_LAYER_SOURCE_ARTIFACT_ID)
|
|
322
|
+
source_pack_files: list[dict[str, Any]] = []
|
|
323
|
+
for source in source_files:
|
|
324
|
+
original_path = _workspace_relative(workspace, source)
|
|
325
|
+
record = _add_file_record(
|
|
326
|
+
records,
|
|
327
|
+
seen_archive_paths,
|
|
328
|
+
role="fact_layer",
|
|
329
|
+
source=source,
|
|
330
|
+
original_path=original_path,
|
|
331
|
+
archive_path=Path("fact_layer") / original_path,
|
|
332
|
+
artifact_id=_FACT_LAYER_SOURCE_ARTIFACT_ID,
|
|
333
|
+
)
|
|
334
|
+
if record is not None:
|
|
335
|
+
source_pack_files.append(_fact_layer_file_record(record))
|
|
336
|
+
if source_pack_files:
|
|
337
|
+
artifacts.append({
|
|
338
|
+
"artifact_id": _FACT_LAYER_SOURCE_ARTIFACT_ID,
|
|
339
|
+
"fact_role": "durable_source_evidence_pack",
|
|
340
|
+
"file_count": len(source_pack_files),
|
|
341
|
+
"files": source_pack_files,
|
|
342
|
+
"pack_sha256": _sha256_json(source_pack_files),
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
for artifact_id, rel_path in _FACT_LAYER_REQUIRED_ARTIFACTS.items():
|
|
346
|
+
source = workspace / rel_path
|
|
347
|
+
if not source.exists() or not source.is_file():
|
|
348
|
+
missing.append(artifact_id)
|
|
349
|
+
continue
|
|
350
|
+
record = _add_file_record(
|
|
351
|
+
records,
|
|
352
|
+
seen_archive_paths,
|
|
353
|
+
role="fact_layer",
|
|
354
|
+
source=source,
|
|
355
|
+
original_path=rel_path,
|
|
356
|
+
archive_path=Path("fact_layer") / rel_path,
|
|
357
|
+
artifact_id=artifact_id,
|
|
358
|
+
)
|
|
359
|
+
if record is not None:
|
|
360
|
+
artifacts.append(_fact_layer_artifact_record(
|
|
361
|
+
record,
|
|
362
|
+
artifact_id=artifact_id,
|
|
363
|
+
fact_role="fact_layer_artifact",
|
|
364
|
+
))
|
|
365
|
+
|
|
366
|
+
source_candidates = workspace / "source_candidates.yaml"
|
|
367
|
+
if source_candidates.exists() and source_candidates.is_file():
|
|
368
|
+
excluded.append({
|
|
369
|
+
"artifact_id": _SOURCE_PLAN_EXCLUDED_ARTIFACT_ID,
|
|
370
|
+
"original_path": "source_candidates.yaml",
|
|
371
|
+
"reason": "source_plan_not_evidence",
|
|
372
|
+
"sha256": _sha256_file(source_candidates),
|
|
373
|
+
"size_bytes": source_candidates.stat().st_size,
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
return {
|
|
377
|
+
"schema_version": RUN_ARCHIVE_FACT_LAYER_SCHEMA,
|
|
378
|
+
"status": "complete" if not missing else "incomplete",
|
|
379
|
+
"completion_semantics": "required_fact_files_present_and_source_paths_pass_evidence_filter",
|
|
380
|
+
"required_artifact_ids": [
|
|
381
|
+
_FACT_LAYER_SOURCE_ARTIFACT_ID,
|
|
382
|
+
*_FACT_LAYER_REQUIRED_ARTIFACTS.keys(),
|
|
383
|
+
],
|
|
384
|
+
"missing_artifact_ids": missing,
|
|
385
|
+
"artifact_count": len(artifacts),
|
|
386
|
+
"source_evidence_count": len(source_files),
|
|
387
|
+
"artifacts": artifacts,
|
|
388
|
+
"excluded": excluded,
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def _add_finalize_auxiliary_records(
|
|
393
|
+
*,
|
|
394
|
+
records: list[dict[str, Any]],
|
|
395
|
+
seen_archive_paths: set[str],
|
|
396
|
+
workspace: Path,
|
|
397
|
+
finalize_report: dict[str, Any],
|
|
398
|
+
) -> None:
|
|
399
|
+
for field_name in ("source_appendix_trace",):
|
|
400
|
+
raw_path = finalize_report.get(field_name)
|
|
401
|
+
if not isinstance(raw_path, str) or not raw_path.strip():
|
|
402
|
+
continue
|
|
403
|
+
source = _resolve_workspace_file(workspace, raw_path)
|
|
404
|
+
try:
|
|
405
|
+
rel_from_output = source.relative_to(workspace / "output")
|
|
406
|
+
except ValueError as exc:
|
|
407
|
+
raise RunArchiveError(
|
|
408
|
+
"Finalize report auxiliary artifact must be under output/.",
|
|
409
|
+
details={"field": field_name, "artifact": raw_path},
|
|
410
|
+
) from exc
|
|
411
|
+
if rel_from_output.parts[:1] == ("delivery",):
|
|
412
|
+
raise RunArchiveError(
|
|
413
|
+
"Finalize report auxiliary artifact must not be part of the reader delivery bundle.",
|
|
414
|
+
details={"field": field_name, "artifact": raw_path},
|
|
415
|
+
)
|
|
416
|
+
_add_file_record(
|
|
417
|
+
records,
|
|
418
|
+
seen_archive_paths,
|
|
419
|
+
role="auxiliary",
|
|
420
|
+
source=source,
|
|
421
|
+
original_path=_workspace_relative(workspace, source),
|
|
422
|
+
archive_path=Path("auxiliary") / rel_from_output,
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def _iter_durable_source_files(workspace: Path) -> list[Path]:
|
|
427
|
+
source_dir = workspace / "input" / "sources"
|
|
428
|
+
if not source_dir.exists() or not source_dir.is_dir():
|
|
429
|
+
return []
|
|
430
|
+
return [
|
|
431
|
+
path
|
|
432
|
+
for path in sorted(source_dir.rglob("*"))
|
|
433
|
+
if path.is_file() and is_evidence_input_path(path, workspace)
|
|
434
|
+
]
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def _evidence_span_registry_projection(
|
|
438
|
+
*,
|
|
439
|
+
workspace: Path,
|
|
440
|
+
artifact_registry: dict[str, Any],
|
|
441
|
+
records: list[dict[str, Any]],
|
|
442
|
+
) -> dict[str, Any] | None:
|
|
443
|
+
artifacts = artifact_registry.get("artifacts") if isinstance(artifact_registry.get("artifacts"), dict) else {}
|
|
444
|
+
registry_record = artifacts.get("evidence_span_registry") if isinstance(artifacts, dict) else None
|
|
445
|
+
registry_path = workspace / "output" / "intermediate" / "evidence_span_registry.json"
|
|
446
|
+
if not registry_path.exists() or not registry_path.is_file():
|
|
447
|
+
return None
|
|
448
|
+
|
|
449
|
+
registry_sha = _sha256_file(registry_path)
|
|
450
|
+
projection_base: dict[str, Any] = {
|
|
451
|
+
"schema_version": RUN_ARCHIVE_EVIDENCE_SPAN_REGISTRY_SCHEMA,
|
|
452
|
+
"registry_path": "output/intermediate/evidence_span_registry.json",
|
|
453
|
+
"registry_archive_path": "intermediate/evidence_span_registry.json",
|
|
454
|
+
"registry_sha256": registry_sha,
|
|
455
|
+
"registry_size_bytes": registry_path.stat().st_size,
|
|
456
|
+
}
|
|
457
|
+
if not isinstance(registry_record, dict) or registry_record.get("status") != "valid":
|
|
458
|
+
projection_base.update({
|
|
459
|
+
"status": "invalid",
|
|
460
|
+
"validation_result": (
|
|
461
|
+
registry_record.get("validation_result")
|
|
462
|
+
if isinstance(registry_record, dict) and isinstance(registry_record.get("validation_result"), str)
|
|
463
|
+
else "not_checked"
|
|
464
|
+
),
|
|
465
|
+
})
|
|
466
|
+
return projection_base
|
|
467
|
+
|
|
468
|
+
if registry_record.get("sha256") and registry_record.get("sha256") != registry_sha:
|
|
469
|
+
raise RunArchiveError(
|
|
470
|
+
"Evidence Span Registry artifact registry hash does not match current file bytes.",
|
|
471
|
+
details={
|
|
472
|
+
"artifact_id": "evidence_span_registry",
|
|
473
|
+
"registry_path": "output/intermediate/evidence_span_registry.json",
|
|
474
|
+
"registry_sha256": registry_sha,
|
|
475
|
+
"artifact_registry_sha256": registry_record.get("sha256"),
|
|
476
|
+
},
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
try:
|
|
480
|
+
payload = json.loads(registry_path.read_text(encoding="utf-8"))
|
|
481
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
482
|
+
raise RunArchiveError(
|
|
483
|
+
"Evidence Span Registry is marked valid but cannot be read for archive projection.",
|
|
484
|
+
details={"registry_path": "output/intermediate/evidence_span_registry.json", "reason": str(exc)},
|
|
485
|
+
) from exc
|
|
486
|
+
if not isinstance(payload, dict):
|
|
487
|
+
raise RunArchiveError(
|
|
488
|
+
"Evidence Span Registry is marked valid but does not contain an object.",
|
|
489
|
+
details={"registry_path": "output/intermediate/evidence_span_registry.json"},
|
|
490
|
+
)
|
|
491
|
+
validation_reason = validate_evidence_span_registry_against_source_pack(
|
|
492
|
+
registry_payload=payload,
|
|
493
|
+
workspace=workspace,
|
|
494
|
+
)
|
|
495
|
+
if validation_reason:
|
|
496
|
+
raise RunArchiveError(
|
|
497
|
+
"Evidence Span Registry is marked valid but no longer matches current source-pack bytes.",
|
|
498
|
+
details={
|
|
499
|
+
"registry_path": "output/intermediate/evidence_span_registry.json",
|
|
500
|
+
"validation_result": f"{EVIDENCE_SPAN_REGISTRY_VALIDATION_PREFIX}:{validation_reason}",
|
|
501
|
+
},
|
|
502
|
+
)
|
|
503
|
+
|
|
504
|
+
records_by_original_path = {
|
|
505
|
+
str(record.get("original_path")): record
|
|
506
|
+
for record in records
|
|
507
|
+
if isinstance(record, dict) and isinstance(record.get("original_path"), str)
|
|
508
|
+
}
|
|
509
|
+
projected_sources: list[dict[str, Any]] = []
|
|
510
|
+
span_count = 0
|
|
511
|
+
for source in sorted(
|
|
512
|
+
(item for item in payload.get("sources", []) if isinstance(item, dict)),
|
|
513
|
+
key=lambda item: (str(item.get("source_id") or ""), str(item.get("source_path") or "")),
|
|
514
|
+
):
|
|
515
|
+
source_id = _stripped_string(source.get("source_id")) or "<unknown_source>"
|
|
516
|
+
source_path = _stripped_string(source.get("source_path"))
|
|
517
|
+
if source_path is None:
|
|
518
|
+
raise RunArchiveError(
|
|
519
|
+
"Evidence Span Registry is marked valid but a source is missing source_path.",
|
|
520
|
+
details={"source_id": source_id},
|
|
521
|
+
)
|
|
522
|
+
source_record = records_by_original_path.get(source_path)
|
|
523
|
+
if not isinstance(source_record, dict) or not str(source_record.get("archive_path") or "").startswith(
|
|
524
|
+
"fact_layer/input/sources/"
|
|
525
|
+
):
|
|
526
|
+
raise RunArchiveError(
|
|
527
|
+
"Evidence Span Registry source is not present in archived fact-layer source pack.",
|
|
528
|
+
details={"source_id": source_id, "source_path": source_path},
|
|
529
|
+
)
|
|
530
|
+
spans: list[dict[str, Any]] = []
|
|
531
|
+
for span in sorted(
|
|
532
|
+
(item for item in source.get("spans", []) if isinstance(item, dict)),
|
|
533
|
+
key=lambda item: str(item.get("span_id") or ""),
|
|
534
|
+
):
|
|
535
|
+
span_id = _stripped_string(span.get("span_id")) or "<unknown_span>"
|
|
536
|
+
projected_span: dict[str, Any] = {
|
|
537
|
+
"span_id": span_id,
|
|
538
|
+
"raw_excerpt_hash": _stripped_string(span.get("hash")) or "",
|
|
539
|
+
"span_role": _stripped_string(span.get("span_role")) or "",
|
|
540
|
+
}
|
|
541
|
+
if isinstance(span.get("char_start"), int):
|
|
542
|
+
projected_span["char_start"] = span["char_start"]
|
|
543
|
+
if isinstance(span.get("char_end"), int):
|
|
544
|
+
projected_span["char_end"] = span["char_end"]
|
|
545
|
+
spans.append(projected_span)
|
|
546
|
+
span_count += 1
|
|
547
|
+
projected_sources.append({
|
|
548
|
+
"source_id": source_id,
|
|
549
|
+
"source_path": source_path,
|
|
550
|
+
"archive_path": source_record["archive_path"],
|
|
551
|
+
"source_sha256": source_record["sha256"],
|
|
552
|
+
"source_size_bytes": source_record["size_bytes"],
|
|
553
|
+
"span_count": len(spans),
|
|
554
|
+
"spans": spans,
|
|
555
|
+
})
|
|
556
|
+
|
|
557
|
+
projection_base.update({
|
|
558
|
+
"status": "valid",
|
|
559
|
+
"validation_result": "experimental_evidence_span_registry_schema",
|
|
560
|
+
"source_count": len(projected_sources),
|
|
561
|
+
"span_count": span_count,
|
|
562
|
+
"sources": projected_sources,
|
|
563
|
+
})
|
|
564
|
+
return projection_base
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def _stripped_string(value: Any) -> str | None:
|
|
568
|
+
if isinstance(value, str) and value.strip():
|
|
569
|
+
return value.strip()
|
|
570
|
+
return None
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def _fact_layer_artifact_record(
|
|
574
|
+
record: dict[str, Any],
|
|
575
|
+
*,
|
|
576
|
+
artifact_id: str,
|
|
577
|
+
fact_role: str,
|
|
578
|
+
) -> dict[str, Any]:
|
|
579
|
+
return {
|
|
580
|
+
"artifact_id": artifact_id,
|
|
581
|
+
"fact_role": fact_role,
|
|
582
|
+
"archive_path": record["archive_path"],
|
|
583
|
+
"original_path": record["original_path"],
|
|
584
|
+
"sha256": record["sha256"],
|
|
585
|
+
"size_bytes": record["size_bytes"],
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
def _fact_layer_file_record(record: dict[str, Any]) -> dict[str, Any]:
|
|
590
|
+
return {
|
|
591
|
+
"archive_path": record["archive_path"],
|
|
592
|
+
"original_path": record["original_path"],
|
|
593
|
+
"sha256": record["sha256"],
|
|
594
|
+
"size_bytes": record["size_bytes"],
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
def _add_file_record(
|
|
599
|
+
records: list[dict[str, Any]],
|
|
600
|
+
seen_archive_paths: set[str],
|
|
601
|
+
*,
|
|
602
|
+
role: str,
|
|
603
|
+
source: Path,
|
|
604
|
+
original_path: str,
|
|
605
|
+
archive_path: Path,
|
|
606
|
+
artifact_id: str | None = None,
|
|
607
|
+
) -> dict[str, Any] | None:
|
|
608
|
+
archive_rel = archive_path.as_posix()
|
|
609
|
+
if archive_rel in seen_archive_paths:
|
|
610
|
+
return None
|
|
611
|
+
seen_archive_paths.add(archive_rel)
|
|
612
|
+
record: dict[str, Any] = {
|
|
613
|
+
"role": role,
|
|
614
|
+
"archive_path": archive_rel,
|
|
615
|
+
"original_path": original_path,
|
|
616
|
+
"sha256": _sha256_file(source),
|
|
617
|
+
"size_bytes": source.stat().st_size,
|
|
618
|
+
}
|
|
619
|
+
if artifact_id:
|
|
620
|
+
record["artifact_id"] = artifact_id
|
|
621
|
+
records.append(record)
|
|
622
|
+
return record
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
def _resolve_workspace_file(workspace: Path, raw_path: Any) -> Path:
|
|
626
|
+
if not isinstance(raw_path, str) or not raw_path.strip():
|
|
627
|
+
raise RunArchiveError(
|
|
628
|
+
"Finalize report contains an invalid artifact path.",
|
|
629
|
+
details={"artifact": raw_path},
|
|
630
|
+
)
|
|
631
|
+
path = Path(raw_path)
|
|
632
|
+
if not path.is_absolute():
|
|
633
|
+
path = workspace / path
|
|
634
|
+
resolved = path.expanduser().resolve()
|
|
635
|
+
try:
|
|
636
|
+
resolved.relative_to(workspace)
|
|
637
|
+
except ValueError as exc:
|
|
638
|
+
raise RunArchiveError(
|
|
639
|
+
"Finalize report artifact is outside the workspace.",
|
|
640
|
+
details={"artifact": raw_path},
|
|
641
|
+
) from exc
|
|
642
|
+
if not resolved.exists() or not resolved.is_file():
|
|
643
|
+
raise RunArchiveError(
|
|
644
|
+
"Finalize report artifact does not exist.",
|
|
645
|
+
details={"artifact": raw_path},
|
|
646
|
+
)
|
|
647
|
+
return resolved
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
def _verify_existing_archive(
|
|
651
|
+
*,
|
|
652
|
+
archive_root: Path,
|
|
653
|
+
) -> dict[str, Any]:
|
|
654
|
+
manifest_path = archive_root / "manifest.json"
|
|
655
|
+
try:
|
|
656
|
+
existing = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
657
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
658
|
+
raise RunArchiveError(
|
|
659
|
+
"Existing run archive manifest is unreadable.",
|
|
660
|
+
details={"archive_path": str(archive_root), "reason": str(exc)},
|
|
661
|
+
error_code=E_RUN_ARCHIVE_CONFLICT,
|
|
662
|
+
) from exc
|
|
663
|
+
if not isinstance(existing, dict):
|
|
664
|
+
raise RunArchiveError(
|
|
665
|
+
"Existing run archive manifest must be an object.",
|
|
666
|
+
details={"archive_path": str(archive_root)},
|
|
667
|
+
error_code=E_RUN_ARCHIVE_CONFLICT,
|
|
668
|
+
)
|
|
669
|
+
existing_files = existing.get("files")
|
|
670
|
+
if existing.get("schema_version") != RUN_ARCHIVE_SCHEMA or not isinstance(existing_files, list):
|
|
671
|
+
raise RunArchiveError(
|
|
672
|
+
"Existing run archive manifest is invalid.",
|
|
673
|
+
details={"archive_path": _workspaceish(archive_root)},
|
|
674
|
+
error_code=E_RUN_ARCHIVE_CONFLICT,
|
|
675
|
+
)
|
|
676
|
+
for record in existing_files:
|
|
677
|
+
if not isinstance(record, dict):
|
|
678
|
+
raise RunArchiveError(
|
|
679
|
+
"Existing run archive manifest contains an invalid file record.",
|
|
680
|
+
details={"archive_path": _workspaceish(archive_root)},
|
|
681
|
+
error_code=E_RUN_ARCHIVE_CONFLICT,
|
|
682
|
+
)
|
|
683
|
+
path = archive_root / str(record["archive_path"])
|
|
684
|
+
if not path.exists() or _sha256_file(path) != record["sha256"]:
|
|
685
|
+
raise RunArchiveError(
|
|
686
|
+
"Existing run archive file differs from manifest.",
|
|
687
|
+
details={"archive_path": str(record["archive_path"])},
|
|
688
|
+
error_code=E_RUN_ARCHIVE_CONFLICT,
|
|
689
|
+
)
|
|
690
|
+
return _archive_result(archive_root)
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
def _verify_existing_archive_matches_plan(
|
|
694
|
+
*,
|
|
695
|
+
archive_root: Path,
|
|
696
|
+
planned_files: list[dict[str, Any]],
|
|
697
|
+
planned_fact_layer: dict[str, Any],
|
|
698
|
+
planned_fast_rerun: dict[str, Any],
|
|
699
|
+
planned_evidence_span_registry: dict[str, Any] | None,
|
|
700
|
+
) -> dict[str, Any]:
|
|
701
|
+
result = _verify_existing_archive(archive_root=archive_root)
|
|
702
|
+
existing_files = result["manifest"].get("files")
|
|
703
|
+
if not isinstance(existing_files, list):
|
|
704
|
+
raise RunArchiveError(
|
|
705
|
+
"Existing run archive manifest is invalid.",
|
|
706
|
+
details={"archive_path": _workspaceish(archive_root)},
|
|
707
|
+
error_code=E_RUN_ARCHIVE_CONFLICT,
|
|
708
|
+
)
|
|
709
|
+
planned_by_archive_path = {
|
|
710
|
+
str(record.get("archive_path")): record
|
|
711
|
+
for record in planned_files
|
|
712
|
+
if isinstance(record, dict) and record.get("archive_path")
|
|
713
|
+
}
|
|
714
|
+
existing_by_archive_path = {
|
|
715
|
+
str(record.get("archive_path")): record
|
|
716
|
+
for record in existing_files
|
|
717
|
+
if isinstance(record, dict) and record.get("archive_path")
|
|
718
|
+
}
|
|
719
|
+
if set(planned_by_archive_path) != set(existing_by_archive_path):
|
|
720
|
+
raise RunArchiveError(
|
|
721
|
+
"Existing run archive file set differs from the current finalized run.",
|
|
722
|
+
details={
|
|
723
|
+
"archive_path": _workspaceish(archive_root),
|
|
724
|
+
"missing_from_existing": sorted(
|
|
725
|
+
set(planned_by_archive_path) - set(existing_by_archive_path)
|
|
726
|
+
),
|
|
727
|
+
"extra_in_existing": sorted(
|
|
728
|
+
set(existing_by_archive_path) - set(planned_by_archive_path)
|
|
729
|
+
),
|
|
730
|
+
},
|
|
731
|
+
error_code=E_RUN_ARCHIVE_CONFLICT,
|
|
732
|
+
)
|
|
733
|
+
for archive_path, planned in planned_by_archive_path.items():
|
|
734
|
+
existing = existing_by_archive_path[archive_path]
|
|
735
|
+
for field in ("original_path", "sha256", "size_bytes"):
|
|
736
|
+
if (
|
|
737
|
+
archive_path == "control/event_log.jsonl"
|
|
738
|
+
and field in {"sha256", "size_bytes"}
|
|
739
|
+
and result["manifest"].get("event_log_semantics")
|
|
740
|
+
== "copied_before_current_archive_event"
|
|
741
|
+
):
|
|
742
|
+
continue
|
|
743
|
+
if existing.get(field) != planned.get(field):
|
|
744
|
+
raise RunArchiveError(
|
|
745
|
+
"Existing run archive differs from the current finalized run.",
|
|
746
|
+
details={
|
|
747
|
+
"archive_path": archive_path,
|
|
748
|
+
"field": field,
|
|
749
|
+
"existing": existing.get(field),
|
|
750
|
+
"planned": planned.get(field),
|
|
751
|
+
},
|
|
752
|
+
error_code=E_RUN_ARCHIVE_CONFLICT,
|
|
753
|
+
)
|
|
754
|
+
existing_fact_layer = result["manifest"].get("fact_layer")
|
|
755
|
+
if existing_fact_layer != planned_fact_layer:
|
|
756
|
+
raise RunArchiveError(
|
|
757
|
+
"Existing run archive fact_layer projection differs from the current finalized run.",
|
|
758
|
+
details={
|
|
759
|
+
"archive_path": _workspaceish(archive_root),
|
|
760
|
+
"field": "fact_layer",
|
|
761
|
+
},
|
|
762
|
+
error_code=E_RUN_ARCHIVE_CONFLICT,
|
|
763
|
+
)
|
|
764
|
+
existing_fast_rerun = result["manifest"].get("fast_rerun")
|
|
765
|
+
if existing_fast_rerun != planned_fast_rerun:
|
|
766
|
+
raise RunArchiveError(
|
|
767
|
+
"Existing run archive fast_rerun projection differs from the current finalized run.",
|
|
768
|
+
details={
|
|
769
|
+
"archive_path": _workspaceish(archive_root),
|
|
770
|
+
"field": "fast_rerun",
|
|
771
|
+
},
|
|
772
|
+
error_code=E_RUN_ARCHIVE_CONFLICT,
|
|
773
|
+
)
|
|
774
|
+
existing_evidence_span_registry = result["manifest"].get("evidence_span_registry")
|
|
775
|
+
if existing_evidence_span_registry != planned_evidence_span_registry:
|
|
776
|
+
raise RunArchiveError(
|
|
777
|
+
"Existing run archive evidence_span_registry projection differs from the current finalized run.",
|
|
778
|
+
details={
|
|
779
|
+
"archive_path": _workspaceish(archive_root),
|
|
780
|
+
"field": "evidence_span_registry",
|
|
781
|
+
},
|
|
782
|
+
error_code=E_RUN_ARCHIVE_CONFLICT,
|
|
783
|
+
)
|
|
784
|
+
return result
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
def _archive_result(archive_root: Path) -> dict[str, Any]:
|
|
788
|
+
manifest = json.loads((archive_root / "manifest.json").read_text(encoding="utf-8"))
|
|
789
|
+
return {
|
|
790
|
+
"archive_path": str(archive_root),
|
|
791
|
+
"archive_manifest": str(archive_root / "manifest.json"),
|
|
792
|
+
"archive_manifest_sha256": _sha256_file(archive_root / "manifest.json"),
|
|
793
|
+
"file_count": len(manifest.get("files") or []),
|
|
794
|
+
"manifest": manifest,
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
def _write_manifest(path: Path, manifest: dict[str, Any]) -> None:
|
|
799
|
+
text = json.dumps(manifest, ensure_ascii=False, indent=2, sort_keys=True) + "\n"
|
|
800
|
+
path.write_text(text, encoding="utf-8")
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
def _sha256_json(payload: Any) -> str:
|
|
804
|
+
return hashlib.sha256(
|
|
805
|
+
json.dumps(payload, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode("utf-8")
|
|
806
|
+
).hexdigest()
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
def _run_integrity_for_manifest(workflow: dict[str, Any]) -> dict[str, Any]:
|
|
810
|
+
return project_for_read(
|
|
811
|
+
interpret_run_integrity(
|
|
812
|
+
workflow.get("run_integrity"),
|
|
813
|
+
field_present="run_integrity" in workflow,
|
|
814
|
+
)
|
|
815
|
+
)
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
def _timing_for_manifest(workspace: Path, workflow: dict[str, Any]) -> dict[str, Any]:
|
|
819
|
+
timing = derive_control_timing_from_path(
|
|
820
|
+
workspace / "output" / "intermediate" / "event_log.jsonl",
|
|
821
|
+
workflow_state=workflow,
|
|
822
|
+
expected_run_id=workflow.get("run_id") if isinstance(workflow.get("run_id"), str) else None,
|
|
823
|
+
)
|
|
824
|
+
projected = {
|
|
825
|
+
"schema_version": timing.get("schema_version"),
|
|
826
|
+
"kind": timing.get("kind"),
|
|
827
|
+
"source": timing.get("source"),
|
|
828
|
+
"precision": timing.get("precision"),
|
|
829
|
+
"status": timing.get("status"),
|
|
830
|
+
"total_elapsed_seconds": timing.get("total_elapsed_seconds"),
|
|
831
|
+
"warnings": timing.get("warnings") or [],
|
|
832
|
+
}
|
|
833
|
+
if isinstance(timing.get("stages"), list):
|
|
834
|
+
projected["stages"] = timing["stages"]
|
|
835
|
+
if isinstance(timing.get("finalize"), dict):
|
|
836
|
+
projected["finalize"] = timing["finalize"]
|
|
837
|
+
return projected
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
def _fast_rerun_for_manifest(
|
|
841
|
+
manifest: dict[str, Any],
|
|
842
|
+
*,
|
|
843
|
+
freshness_at_finalize: dict[str, Any] | None = None,
|
|
844
|
+
) -> dict[str, Any]:
|
|
845
|
+
record = manifest.get("fact_layer_import")
|
|
846
|
+
if not isinstance(record, dict):
|
|
847
|
+
return {}
|
|
848
|
+
projected = {
|
|
849
|
+
"schema_version": "mabw.run_archive.fast_rerun.v1",
|
|
850
|
+
"source_run_id": record.get("source_run_id", ""),
|
|
851
|
+
"source_archive_manifest": record.get("source_archive_manifest", ""),
|
|
852
|
+
"source_archive_manifest_sha256": record.get("source_archive_manifest_sha256", ""),
|
|
853
|
+
"fact_layer_sha256": record.get("fact_layer_sha256", ""),
|
|
854
|
+
"freshness_at_import": (
|
|
855
|
+
record.get("freshness_at_import") if isinstance(record.get("freshness_at_import"), dict) else {}
|
|
856
|
+
),
|
|
857
|
+
"satisfied_stage_ids": (
|
|
858
|
+
record.get("satisfied_stage_ids") if isinstance(record.get("satisfied_stage_ids"), list) else []
|
|
859
|
+
),
|
|
860
|
+
"timing_comparability": record.get("timing_comparability") or "downstream_only",
|
|
861
|
+
}
|
|
862
|
+
if isinstance(freshness_at_finalize, dict):
|
|
863
|
+
projected["freshness_at_finalize"] = freshness_at_finalize
|
|
864
|
+
elif isinstance(record.get("freshness_at_finalize"), dict):
|
|
865
|
+
projected["freshness_at_finalize"] = record["freshness_at_finalize"]
|
|
866
|
+
return projected
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
def _sha256_file(path: Path) -> str:
|
|
870
|
+
digest = hashlib.sha256()
|
|
871
|
+
with path.open("rb") as fh:
|
|
872
|
+
for chunk in iter(lambda: fh.read(1024 * 1024), b""):
|
|
873
|
+
digest.update(chunk)
|
|
874
|
+
return digest.hexdigest()
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
def _workspace_relative(workspace: Path, path: Path) -> str:
|
|
878
|
+
return path.resolve().relative_to(workspace).as_posix()
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
def _workspaceish(path: Path) -> str:
|
|
882
|
+
return path.as_posix()
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
def _utc_now() -> str:
|
|
886
|
+
from datetime import datetime, timezone
|
|
887
|
+
|
|
888
|
+
return datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
|