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,898 @@
|
|
|
1
|
+
"""Workspace feedback issue ingestion and deterministic repair planning."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import uuid
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from multi_agent_brief.audit.proposal_boundary import is_advisory_semantic_support_proposal
|
|
13
|
+
from multi_agent_brief.feedback.feedback_contract import (
|
|
14
|
+
FEEDBACK_STATE_FILES,
|
|
15
|
+
FEEDBACK_ISSUES_SCHEMA,
|
|
16
|
+
ISSUE_CATEGORIES,
|
|
17
|
+
ISSUE_SEVERITIES,
|
|
18
|
+
REPAIR_PLAN_SCHEMA,
|
|
19
|
+
artifact_ids,
|
|
20
|
+
empty_feedback_issues,
|
|
21
|
+
empty_repair_plan,
|
|
22
|
+
feedback_state_paths,
|
|
23
|
+
load_feedback_issues,
|
|
24
|
+
load_repair_plan,
|
|
25
|
+
stage_allowed_decisions,
|
|
26
|
+
stage_ids,
|
|
27
|
+
validate_feedback_issues_payload,
|
|
28
|
+
validate_feedback_state,
|
|
29
|
+
validate_repair_plan_payload,
|
|
30
|
+
)
|
|
31
|
+
from multi_agent_brief.orchestrator.runtime_state import (
|
|
32
|
+
RuntimeStateError,
|
|
33
|
+
append_event,
|
|
34
|
+
initialize_runtime_state,
|
|
35
|
+
load_artifact_contracts,
|
|
36
|
+
load_stage_specs,
|
|
37
|
+
show_runtime_state,
|
|
38
|
+
utc_now,
|
|
39
|
+
)
|
|
40
|
+
from multi_agent_brief.orchestrator_contract import resolve_repo_workdir
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
FEEDBACK_EVENT_ACTOR = "cli"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _require_workspace(workspace: str | Path) -> Path:
|
|
47
|
+
ws = Path(workspace).expanduser().resolve()
|
|
48
|
+
if not (ws / "config.yaml").exists():
|
|
49
|
+
raise RuntimeStateError(
|
|
50
|
+
f"Workspace config.yaml not found: {ws / 'config.yaml'}",
|
|
51
|
+
details={"workspace": str(ws)},
|
|
52
|
+
)
|
|
53
|
+
return ws
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _write_json_atomic(path: Path, payload: dict[str, Any]) -> None:
|
|
57
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
58
|
+
text = json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True) + "\n"
|
|
59
|
+
tmp = path.with_name(f".{path.name}.{uuid.uuid4().hex}.tmp")
|
|
60
|
+
try:
|
|
61
|
+
tmp.write_text(text, encoding="utf-8")
|
|
62
|
+
os.replace(tmp, path)
|
|
63
|
+
except OSError as exc:
|
|
64
|
+
try:
|
|
65
|
+
tmp.unlink(missing_ok=True)
|
|
66
|
+
except OSError:
|
|
67
|
+
pass
|
|
68
|
+
raise RuntimeStateError(
|
|
69
|
+
f"Failed to write feedback state file: {path}",
|
|
70
|
+
details={"path": str(path), "reason": str(exc)},
|
|
71
|
+
) from exc
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _read_json_or_text(path: Path) -> Any:
|
|
75
|
+
try:
|
|
76
|
+
text = path.read_text(encoding="utf-8")
|
|
77
|
+
except OSError as exc:
|
|
78
|
+
raise RuntimeStateError(
|
|
79
|
+
f"Failed to read feedback input: {path}",
|
|
80
|
+
details={"path": str(path), "reason": str(exc)},
|
|
81
|
+
) from exc
|
|
82
|
+
if not text.strip():
|
|
83
|
+
raise RuntimeStateError(
|
|
84
|
+
f"Feedback input is empty: {path}",
|
|
85
|
+
details={"path": str(path)},
|
|
86
|
+
)
|
|
87
|
+
try:
|
|
88
|
+
return json.loads(text)
|
|
89
|
+
except json.JSONDecodeError:
|
|
90
|
+
return text
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _workspace_relative(workspace: Path, path: Path) -> str:
|
|
94
|
+
resolved = path.expanduser().resolve()
|
|
95
|
+
try:
|
|
96
|
+
return resolved.relative_to(workspace).as_posix()
|
|
97
|
+
except ValueError:
|
|
98
|
+
return path.as_posix()
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _contracts(
|
|
102
|
+
*,
|
|
103
|
+
workspace: Path,
|
|
104
|
+
repo_workdir: str | Path | None,
|
|
105
|
+
) -> tuple[Path, list[dict[str, Any]], list[dict[str, Any]]]:
|
|
106
|
+
repo = resolve_repo_workdir(repo_workdir, workspace=workspace)
|
|
107
|
+
return repo, load_stage_specs(repo), load_artifact_contracts(repo)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _runtime_run_id(
|
|
111
|
+
*,
|
|
112
|
+
workspace: Path,
|
|
113
|
+
repo_workdir: str | Path | None,
|
|
114
|
+
runtime: str = "hermes",
|
|
115
|
+
) -> str:
|
|
116
|
+
try:
|
|
117
|
+
state = show_runtime_state(workspace=workspace)
|
|
118
|
+
except RuntimeStateError:
|
|
119
|
+
state = initialize_runtime_state(
|
|
120
|
+
workspace=workspace,
|
|
121
|
+
runtime=runtime,
|
|
122
|
+
repo_workdir=repo_workdir,
|
|
123
|
+
actor=FEEDBACK_EVENT_ACTOR,
|
|
124
|
+
)
|
|
125
|
+
return str((state.get("manifest") or {}).get("run_id") or "")
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _validate_explicit_refs(
|
|
129
|
+
*,
|
|
130
|
+
stage_id: str | None,
|
|
131
|
+
artifact_id: str | None,
|
|
132
|
+
category: str | None,
|
|
133
|
+
severity: str | None,
|
|
134
|
+
stages: list[dict[str, Any]],
|
|
135
|
+
artifacts: list[dict[str, Any]],
|
|
136
|
+
) -> None:
|
|
137
|
+
known_stages = stage_ids(stages)
|
|
138
|
+
known_artifacts = artifact_ids(artifacts)
|
|
139
|
+
if stage_id is not None and stage_id not in known_stages:
|
|
140
|
+
raise RuntimeStateError(
|
|
141
|
+
f"Unknown feedback stage: {stage_id}",
|
|
142
|
+
details={"stage_id": stage_id, "known_stages": sorted(known_stages)},
|
|
143
|
+
)
|
|
144
|
+
if artifact_id is not None and artifact_id not in known_artifacts:
|
|
145
|
+
raise RuntimeStateError(
|
|
146
|
+
f"Unknown feedback artifact: {artifact_id}",
|
|
147
|
+
details={"artifact_id": artifact_id, "known_artifacts": sorted(known_artifacts)},
|
|
148
|
+
)
|
|
149
|
+
if category is not None and category not in ISSUE_CATEGORIES:
|
|
150
|
+
raise RuntimeStateError(
|
|
151
|
+
f"Unknown feedback category: {category}",
|
|
152
|
+
details={"category": category, "known_categories": sorted(ISSUE_CATEGORIES)},
|
|
153
|
+
)
|
|
154
|
+
if severity is not None and severity not in ISSUE_SEVERITIES:
|
|
155
|
+
raise RuntimeStateError(
|
|
156
|
+
f"Unknown feedback severity: {severity}",
|
|
157
|
+
details={"severity": severity, "known_severities": sorted(ISSUE_SEVERITIES)},
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _summary_from_text(text: str) -> str:
|
|
162
|
+
for line in text.splitlines():
|
|
163
|
+
clean = " ".join(line.strip().split())
|
|
164
|
+
if clean:
|
|
165
|
+
return clean[:240]
|
|
166
|
+
return "Feedback issue"
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _excerpt(value: Any) -> str:
|
|
170
|
+
if isinstance(value, str):
|
|
171
|
+
text = value
|
|
172
|
+
else:
|
|
173
|
+
text = json.dumps(value, ensure_ascii=False, sort_keys=True)
|
|
174
|
+
return " ".join(text.strip().split())[:1000]
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _normalize_severity(value: Any) -> str | None:
|
|
178
|
+
if value is None:
|
|
179
|
+
return None
|
|
180
|
+
text = str(value).strip().lower().replace("-", "_")
|
|
181
|
+
mapping = {
|
|
182
|
+
"block": "blocking",
|
|
183
|
+
"blocked": "blocking",
|
|
184
|
+
"critical": "blocking",
|
|
185
|
+
"p0": "blocking",
|
|
186
|
+
"p1": "high",
|
|
187
|
+
"warning": "medium",
|
|
188
|
+
"warn": "medium",
|
|
189
|
+
"info": "low",
|
|
190
|
+
}
|
|
191
|
+
text = mapping.get(text, text)
|
|
192
|
+
return text if text in ISSUE_SEVERITIES else None
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _stable_hash(parts: list[str]) -> str:
|
|
196
|
+
digest = hashlib.sha256("\n".join(parts).encode("utf-8")).hexdigest()
|
|
197
|
+
return digest[:16]
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _issue_fingerprint(issue: dict[str, Any]) -> str:
|
|
201
|
+
return _stable_hash([
|
|
202
|
+
str(issue.get("source") or ""),
|
|
203
|
+
str((issue.get("metadata") or {}).get("source_finding_id") or ""),
|
|
204
|
+
str(issue.get("raw_feedback_ref") or ""),
|
|
205
|
+
str(issue.get("stage_id") or ""),
|
|
206
|
+
str(issue.get("artifact_id") or ""),
|
|
207
|
+
" ".join(str(issue.get("summary") or "").lower().split()),
|
|
208
|
+
])
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _new_issue_id(fingerprint: str) -> str:
|
|
212
|
+
return f"fb_{fingerprint}"
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _issue_status(
|
|
216
|
+
*,
|
|
217
|
+
stage_id: str | None,
|
|
218
|
+
artifact_id: str | None,
|
|
219
|
+
category: str | None,
|
|
220
|
+
) -> str:
|
|
221
|
+
if stage_id and artifact_id and category:
|
|
222
|
+
return "open"
|
|
223
|
+
return "triage"
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _human_issue(
|
|
227
|
+
*,
|
|
228
|
+
workspace: Path,
|
|
229
|
+
feedback_path: Path,
|
|
230
|
+
text: str,
|
|
231
|
+
stage_id: str | None,
|
|
232
|
+
artifact_id: str | None,
|
|
233
|
+
category: str | None,
|
|
234
|
+
severity: str | None,
|
|
235
|
+
now: str,
|
|
236
|
+
) -> dict[str, Any]:
|
|
237
|
+
issue = {
|
|
238
|
+
"issue_id": "",
|
|
239
|
+
"source": "human",
|
|
240
|
+
"severity": severity or "medium",
|
|
241
|
+
"stage_id": stage_id,
|
|
242
|
+
"artifact_id": artifact_id,
|
|
243
|
+
"category": category,
|
|
244
|
+
"summary": _summary_from_text(text),
|
|
245
|
+
"feedback_excerpt": _excerpt(text),
|
|
246
|
+
"raw_feedback_ref": _workspace_relative(workspace, feedback_path),
|
|
247
|
+
"source_artifact": _workspace_relative(workspace, feedback_path),
|
|
248
|
+
"supporting_context": [],
|
|
249
|
+
"metadata": {},
|
|
250
|
+
"status": _issue_status(stage_id=stage_id, artifact_id=artifact_id, category=category),
|
|
251
|
+
"created_at": now,
|
|
252
|
+
"updated_at": now,
|
|
253
|
+
"fingerprint": "",
|
|
254
|
+
}
|
|
255
|
+
issue["fingerprint"] = _issue_fingerprint(issue)
|
|
256
|
+
issue["issue_id"] = _new_issue_id(str(issue["fingerprint"]))
|
|
257
|
+
return issue
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def _extract_audit_findings(data: Any) -> list[dict[str, Any]]:
|
|
261
|
+
if isinstance(data, list):
|
|
262
|
+
return [item for item in data if isinstance(item, dict)]
|
|
263
|
+
if not isinstance(data, dict):
|
|
264
|
+
return []
|
|
265
|
+
for key in (
|
|
266
|
+
"findings",
|
|
267
|
+
"issues",
|
|
268
|
+
"audit_findings",
|
|
269
|
+
"blocking_findings",
|
|
270
|
+
"violations",
|
|
271
|
+
"results",
|
|
272
|
+
):
|
|
273
|
+
value = data.get(key)
|
|
274
|
+
if isinstance(value, list):
|
|
275
|
+
return [item for item in value if isinstance(item, dict)]
|
|
276
|
+
return []
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _first_text(finding: dict[str, Any], keys: tuple[str, ...]) -> str | None:
|
|
280
|
+
for key in keys:
|
|
281
|
+
value = finding.get(key)
|
|
282
|
+
if isinstance(value, str) and value.strip():
|
|
283
|
+
return value.strip()
|
|
284
|
+
return None
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _valid_or_none(value: Any, allowed: set[str]) -> str | None:
|
|
288
|
+
if value is None:
|
|
289
|
+
return None
|
|
290
|
+
text = str(value)
|
|
291
|
+
return text if text in allowed else None
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def _audit_issue(
|
|
295
|
+
*,
|
|
296
|
+
workspace: Path,
|
|
297
|
+
feedback_path: Path,
|
|
298
|
+
finding: dict[str, Any],
|
|
299
|
+
index: int,
|
|
300
|
+
explicit_stage_id: str | None,
|
|
301
|
+
explicit_artifact_id: str | None,
|
|
302
|
+
explicit_category: str | None,
|
|
303
|
+
explicit_severity: str | None,
|
|
304
|
+
stages: list[dict[str, Any]],
|
|
305
|
+
artifacts: list[dict[str, Any]],
|
|
306
|
+
now: str,
|
|
307
|
+
) -> dict[str, Any]:
|
|
308
|
+
known_stages = stage_ids(stages)
|
|
309
|
+
known_artifacts = artifact_ids(artifacts)
|
|
310
|
+
source_finding_id = (
|
|
311
|
+
finding.get("finding_id")
|
|
312
|
+
or finding.get("id")
|
|
313
|
+
or finding.get("rule_id")
|
|
314
|
+
or finding.get("claim_id")
|
|
315
|
+
or f"finding_{index}"
|
|
316
|
+
)
|
|
317
|
+
blocking_level = finding.get("blocking_level") or finding.get("severity") or finding.get("level")
|
|
318
|
+
repair_owner = finding.get("repair_owner") or finding.get("owner")
|
|
319
|
+
finding_type = finding.get("finding_type") or finding.get("category") or finding.get("type") or finding.get("rule_id")
|
|
320
|
+
|
|
321
|
+
stage_id = explicit_stage_id
|
|
322
|
+
if stage_id is None:
|
|
323
|
+
stage_id = _valid_or_none(finding.get("repair_stage_id"), known_stages)
|
|
324
|
+
if stage_id is None:
|
|
325
|
+
stage_id = _valid_or_none(finding.get("stage_id"), known_stages)
|
|
326
|
+
if stage_id is None:
|
|
327
|
+
stage_id = _valid_or_none(repair_owner, known_stages)
|
|
328
|
+
|
|
329
|
+
artifact_id = explicit_artifact_id
|
|
330
|
+
if artifact_id is None:
|
|
331
|
+
artifact_id = _valid_or_none(finding.get("repair_artifact_id"), known_artifacts)
|
|
332
|
+
if artifact_id is None:
|
|
333
|
+
artifact_id = _valid_or_none(finding.get("artifact_id"), known_artifacts)
|
|
334
|
+
|
|
335
|
+
category = explicit_category
|
|
336
|
+
if category is None:
|
|
337
|
+
category = _valid_or_none(finding.get("category"), ISSUE_CATEGORIES)
|
|
338
|
+
if category is None:
|
|
339
|
+
category = _valid_or_none(finding_type, ISSUE_CATEGORIES)
|
|
340
|
+
|
|
341
|
+
severity = explicit_severity or _normalize_severity(blocking_level) or _normalize_severity(finding.get("severity")) or "medium"
|
|
342
|
+
summary = _first_text(finding, ("summary", "message", "description", "finding", "title")) or _excerpt(finding)
|
|
343
|
+
raw_ref = f"{_workspace_relative(workspace, feedback_path)}#finding:{source_finding_id}"
|
|
344
|
+
|
|
345
|
+
issue = {
|
|
346
|
+
"issue_id": "",
|
|
347
|
+
"source": "audit",
|
|
348
|
+
"severity": severity,
|
|
349
|
+
"stage_id": stage_id,
|
|
350
|
+
"artifact_id": artifact_id,
|
|
351
|
+
"category": category,
|
|
352
|
+
"summary": summary[:240],
|
|
353
|
+
"feedback_excerpt": _excerpt(summary),
|
|
354
|
+
"raw_feedback_ref": raw_ref,
|
|
355
|
+
"source_artifact": _workspace_relative(workspace, feedback_path),
|
|
356
|
+
"supporting_context": [],
|
|
357
|
+
"metadata": {
|
|
358
|
+
"source_finding_id": source_finding_id,
|
|
359
|
+
"blocking_level": blocking_level,
|
|
360
|
+
"repair_owner": repair_owner,
|
|
361
|
+
"finding_type": finding_type,
|
|
362
|
+
"raw_finding": finding,
|
|
363
|
+
},
|
|
364
|
+
"status": _issue_status(stage_id=stage_id, artifact_id=artifact_id, category=category),
|
|
365
|
+
"created_at": now,
|
|
366
|
+
"updated_at": now,
|
|
367
|
+
"fingerprint": "",
|
|
368
|
+
}
|
|
369
|
+
issue["fingerprint"] = _issue_fingerprint(issue)
|
|
370
|
+
issue["issue_id"] = _new_issue_id(str(issue["fingerprint"]))
|
|
371
|
+
return issue
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def _load_existing_issues(workspace: Path, now: str) -> dict[str, Any]:
|
|
375
|
+
existing = load_feedback_issues(workspace)
|
|
376
|
+
if existing is None:
|
|
377
|
+
return empty_feedback_issues(updated_at=now)
|
|
378
|
+
return existing
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def ingest_feedback(
|
|
382
|
+
*,
|
|
383
|
+
workspace: str | Path,
|
|
384
|
+
feedback_path: str | Path,
|
|
385
|
+
source: str,
|
|
386
|
+
stage_id: str | None = None,
|
|
387
|
+
artifact_id: str | None = None,
|
|
388
|
+
category: str | None = None,
|
|
389
|
+
severity: str | None = None,
|
|
390
|
+
repo_workdir: str | Path | None = None,
|
|
391
|
+
actor: str = FEEDBACK_EVENT_ACTOR,
|
|
392
|
+
) -> dict[str, Any]:
|
|
393
|
+
ws = _require_workspace(workspace)
|
|
394
|
+
path = Path(feedback_path).expanduser().resolve()
|
|
395
|
+
if source not in {"human", "audit"}:
|
|
396
|
+
raise RuntimeStateError(
|
|
397
|
+
f"Unknown feedback source: {source}",
|
|
398
|
+
details={"source": source, "known_sources": ["audit", "human"]},
|
|
399
|
+
)
|
|
400
|
+
if not path.exists():
|
|
401
|
+
raise RuntimeStateError(
|
|
402
|
+
f"Feedback input not found: {path}",
|
|
403
|
+
details={"path": str(path)},
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
_repo, stages, artifacts = _contracts(workspace=ws, repo_workdir=repo_workdir)
|
|
407
|
+
_validate_explicit_refs(
|
|
408
|
+
stage_id=stage_id,
|
|
409
|
+
artifact_id=artifact_id,
|
|
410
|
+
category=category,
|
|
411
|
+
severity=severity,
|
|
412
|
+
stages=stages,
|
|
413
|
+
artifacts=artifacts,
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
raw = _read_json_or_text(path)
|
|
417
|
+
now = utc_now()
|
|
418
|
+
if source == "human":
|
|
419
|
+
text = raw if isinstance(raw, str) else json.dumps(raw, ensure_ascii=False, sort_keys=True)
|
|
420
|
+
candidate_issues = [
|
|
421
|
+
_human_issue(
|
|
422
|
+
workspace=ws,
|
|
423
|
+
feedback_path=path,
|
|
424
|
+
text=text,
|
|
425
|
+
stage_id=stage_id,
|
|
426
|
+
artifact_id=artifact_id,
|
|
427
|
+
category=category,
|
|
428
|
+
severity=severity,
|
|
429
|
+
now=now,
|
|
430
|
+
)
|
|
431
|
+
]
|
|
432
|
+
else:
|
|
433
|
+
findings = [
|
|
434
|
+
finding
|
|
435
|
+
for finding in _extract_audit_findings(raw)
|
|
436
|
+
# Advisory semantic-support proposals are not authoritative audit
|
|
437
|
+
# findings and must not become editor-owned feedback issues.
|
|
438
|
+
if not is_advisory_semantic_support_proposal(
|
|
439
|
+
finding.get("finding_type") or finding.get("category") or finding.get("type"),
|
|
440
|
+
finding.get("severity"),
|
|
441
|
+
)
|
|
442
|
+
]
|
|
443
|
+
candidate_issues = [
|
|
444
|
+
_audit_issue(
|
|
445
|
+
workspace=ws,
|
|
446
|
+
feedback_path=path,
|
|
447
|
+
finding=finding,
|
|
448
|
+
index=idx,
|
|
449
|
+
explicit_stage_id=stage_id,
|
|
450
|
+
explicit_artifact_id=artifact_id,
|
|
451
|
+
explicit_category=category,
|
|
452
|
+
explicit_severity=severity,
|
|
453
|
+
stages=stages,
|
|
454
|
+
artifacts=artifacts,
|
|
455
|
+
now=now,
|
|
456
|
+
)
|
|
457
|
+
for idx, finding in enumerate(findings)
|
|
458
|
+
]
|
|
459
|
+
|
|
460
|
+
existing = _load_existing_issues(ws, now)
|
|
461
|
+
if feedback_state_paths(ws)["feedback_issues"].exists():
|
|
462
|
+
existing_errors = validate_feedback_issues_payload(existing, stages=stages, artifacts=artifacts)
|
|
463
|
+
if existing_errors:
|
|
464
|
+
raise RuntimeStateError(
|
|
465
|
+
"Existing feedback issues failed contract validation.",
|
|
466
|
+
details={"errors": existing_errors},
|
|
467
|
+
)
|
|
468
|
+
existing_issues = [issue for issue in existing.get("issues") or [] if isinstance(issue, dict)]
|
|
469
|
+
fingerprints = {str(issue.get("fingerprint")) for issue in existing_issues if issue.get("fingerprint")}
|
|
470
|
+
new_issues = [
|
|
471
|
+
issue for issue in candidate_issues if str(issue.get("fingerprint")) not in fingerprints
|
|
472
|
+
]
|
|
473
|
+
|
|
474
|
+
payload = dict(existing)
|
|
475
|
+
payload["schema_version"] = FEEDBACK_ISSUES_SCHEMA
|
|
476
|
+
payload.setdefault("created_at", now)
|
|
477
|
+
payload["updated_at"] = now
|
|
478
|
+
payload["issues"] = [*existing_issues, *new_issues]
|
|
479
|
+
|
|
480
|
+
# Validate before touching runtime state. A malformed feedback file should
|
|
481
|
+
# not create runtime_manifest.json/event_log.jsonl as a side effect.
|
|
482
|
+
errors = validate_feedback_issues_payload(payload, stages=stages, artifacts=artifacts)
|
|
483
|
+
if errors:
|
|
484
|
+
raise RuntimeStateError(
|
|
485
|
+
"Feedback issues failed contract validation.",
|
|
486
|
+
details={"errors": errors},
|
|
487
|
+
)
|
|
488
|
+
|
|
489
|
+
run_id: str | None = None
|
|
490
|
+
if new_issues:
|
|
491
|
+
run_id = _runtime_run_id(workspace=ws, repo_workdir=repo_workdir)
|
|
492
|
+
for issue in new_issues:
|
|
493
|
+
metadata = dict(issue.get("metadata") or {})
|
|
494
|
+
metadata.setdefault("run_id", run_id)
|
|
495
|
+
issue["metadata"] = metadata
|
|
496
|
+
|
|
497
|
+
payload["issues"] = [*existing_issues, *new_issues]
|
|
498
|
+
errors = validate_feedback_issues_payload(payload, stages=stages, artifacts=artifacts)
|
|
499
|
+
if errors:
|
|
500
|
+
raise RuntimeStateError(
|
|
501
|
+
"Feedback issues failed contract validation.",
|
|
502
|
+
details={"errors": errors},
|
|
503
|
+
)
|
|
504
|
+
|
|
505
|
+
for issue in new_issues:
|
|
506
|
+
append_event(
|
|
507
|
+
workspace=ws,
|
|
508
|
+
run_id=str(run_id),
|
|
509
|
+
event_type="feedback_issue_created",
|
|
510
|
+
actor=actor,
|
|
511
|
+
stage_id=issue.get("stage_id"),
|
|
512
|
+
artifact_id=issue.get("artifact_id"),
|
|
513
|
+
reason=str(issue.get("summary") or ""),
|
|
514
|
+
metadata={
|
|
515
|
+
"issue_id": issue.get("issue_id"),
|
|
516
|
+
"source": issue.get("source"),
|
|
517
|
+
"severity": issue.get("severity"),
|
|
518
|
+
"status": issue.get("status"),
|
|
519
|
+
},
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
_write_json_atomic(feedback_state_paths(ws)["feedback_issues"], payload)
|
|
523
|
+
return show_feedback_state(workspace=ws, repo_workdir=repo_workdir)
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
def _plan_fingerprint(stage_id: str, issue_ids: list[str], artifacts: list[str]) -> str:
|
|
527
|
+
return _stable_hash([stage_id, *sorted(issue_ids), *sorted(artifacts)])
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
def _new_plan_id(fingerprint: str) -> str:
|
|
531
|
+
return f"rp_{fingerprint}"
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
def _candidate_decision(stage_id: str, stages: list[dict[str, Any]]) -> tuple[str | None, bool]:
|
|
535
|
+
allowed = stage_allowed_decisions(stages).get(stage_id, set())
|
|
536
|
+
if "delegate_repair" in allowed:
|
|
537
|
+
return "delegate_repair", False
|
|
538
|
+
if "request_human_review" in allowed:
|
|
539
|
+
return "request_human_review", True
|
|
540
|
+
if "block_run" in allowed:
|
|
541
|
+
return "block_run", True
|
|
542
|
+
return None, True
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
def plan_feedback(
|
|
546
|
+
*,
|
|
547
|
+
workspace: str | Path,
|
|
548
|
+
repo_workdir: str | Path | None = None,
|
|
549
|
+
actor: str = FEEDBACK_EVENT_ACTOR,
|
|
550
|
+
) -> dict[str, Any]:
|
|
551
|
+
ws = _require_workspace(workspace)
|
|
552
|
+
_repo, stages, artifacts = _contracts(workspace=ws, repo_workdir=repo_workdir)
|
|
553
|
+
now = utc_now()
|
|
554
|
+
issues_payload = _load_existing_issues(ws, now)
|
|
555
|
+
errors = validate_feedback_issues_payload(issues_payload, stages=stages, artifacts=artifacts)
|
|
556
|
+
if errors:
|
|
557
|
+
raise RuntimeStateError(
|
|
558
|
+
"Feedback issues failed contract validation.",
|
|
559
|
+
details={"errors": errors},
|
|
560
|
+
)
|
|
561
|
+
|
|
562
|
+
open_issues = [
|
|
563
|
+
issue
|
|
564
|
+
for issue in issues_payload.get("issues") or []
|
|
565
|
+
if isinstance(issue, dict) and issue.get("status") == "open"
|
|
566
|
+
]
|
|
567
|
+
existing_plan_raw = load_repair_plan(ws)
|
|
568
|
+
existing_plan = existing_plan_raw or empty_repair_plan(updated_at=now)
|
|
569
|
+
existing_errors = (
|
|
570
|
+
validate_repair_plan_payload(
|
|
571
|
+
existing_plan,
|
|
572
|
+
issues_payload=issues_payload,
|
|
573
|
+
stages=stages,
|
|
574
|
+
artifacts=artifacts,
|
|
575
|
+
)
|
|
576
|
+
if existing_plan_raw is not None
|
|
577
|
+
else []
|
|
578
|
+
)
|
|
579
|
+
if existing_errors:
|
|
580
|
+
raise RuntimeStateError(
|
|
581
|
+
"Existing repair plan failed contract validation.",
|
|
582
|
+
details={"errors": existing_errors},
|
|
583
|
+
)
|
|
584
|
+
|
|
585
|
+
plans = [plan for plan in existing_plan.get("repair_plans") or [] if isinstance(plan, dict)]
|
|
586
|
+
existing_fingerprints = {str(plan.get("fingerprint")) for plan in plans if plan.get("fingerprint")}
|
|
587
|
+
|
|
588
|
+
grouped: dict[str, list[dict[str, Any]]] = {}
|
|
589
|
+
for issue in open_issues:
|
|
590
|
+
stage_id = str(issue.get("stage_id") or "")
|
|
591
|
+
if not stage_id:
|
|
592
|
+
continue
|
|
593
|
+
grouped.setdefault(stage_id, []).append(issue)
|
|
594
|
+
|
|
595
|
+
created_plans: list[dict[str, Any]] = []
|
|
596
|
+
planned_issue_ids: set[str] = set()
|
|
597
|
+
for stage_id in sorted(grouped):
|
|
598
|
+
stage_issues = grouped[stage_id]
|
|
599
|
+
issue_ids = [str(issue.get("issue_id")) for issue in stage_issues]
|
|
600
|
+
target_artifacts = sorted({
|
|
601
|
+
str(issue.get("artifact_id"))
|
|
602
|
+
for issue in stage_issues
|
|
603
|
+
if issue.get("artifact_id")
|
|
604
|
+
})
|
|
605
|
+
fingerprint = _plan_fingerprint(stage_id, issue_ids, target_artifacts)
|
|
606
|
+
if fingerprint in existing_fingerprints:
|
|
607
|
+
planned_issue_ids.update(issue_ids)
|
|
608
|
+
continue
|
|
609
|
+
decision, requires_human_review = _candidate_decision(stage_id, stages)
|
|
610
|
+
plan = {
|
|
611
|
+
"repair_plan_id": _new_plan_id(fingerprint),
|
|
612
|
+
"created_at": now,
|
|
613
|
+
"updated_at": now,
|
|
614
|
+
"target_stage": stage_id,
|
|
615
|
+
"target_artifacts": target_artifacts,
|
|
616
|
+
"issue_ids": issue_ids,
|
|
617
|
+
"allowed_decision": decision,
|
|
618
|
+
"repair_scope": "minimal",
|
|
619
|
+
"instructions": [
|
|
620
|
+
f"Review {issue.get('artifact_id')}: {issue.get('summary')}"
|
|
621
|
+
for issue in stage_issues
|
|
622
|
+
],
|
|
623
|
+
"requires_human_review": requires_human_review,
|
|
624
|
+
"status": "planned",
|
|
625
|
+
"fingerprint": fingerprint,
|
|
626
|
+
}
|
|
627
|
+
plans.append(plan)
|
|
628
|
+
created_plans.append(plan)
|
|
629
|
+
planned_issue_ids.update(issue_ids)
|
|
630
|
+
|
|
631
|
+
updated_issues: list[dict[str, Any]] = []
|
|
632
|
+
status_changed: list[dict[str, Any]] = []
|
|
633
|
+
for issue in issues_payload.get("issues") or []:
|
|
634
|
+
if isinstance(issue, dict) and str(issue.get("issue_id")) in planned_issue_ids and issue.get("status") == "open":
|
|
635
|
+
updated = dict(issue)
|
|
636
|
+
updated["status"] = "planned"
|
|
637
|
+
updated["updated_at"] = now
|
|
638
|
+
updated_issues.append(updated)
|
|
639
|
+
status_changed.append(updated)
|
|
640
|
+
else:
|
|
641
|
+
updated_issues.append(issue)
|
|
642
|
+
|
|
643
|
+
issues_payload = dict(issues_payload)
|
|
644
|
+
issues_payload["updated_at"] = now
|
|
645
|
+
issues_payload["issues"] = updated_issues
|
|
646
|
+
plan_payload = dict(existing_plan)
|
|
647
|
+
plan_payload["schema_version"] = REPAIR_PLAN_SCHEMA
|
|
648
|
+
plan_payload.setdefault("created_at", now)
|
|
649
|
+
plan_payload["updated_at"] = now
|
|
650
|
+
plan_payload["repair_plans"] = plans
|
|
651
|
+
|
|
652
|
+
issue_errors = validate_feedback_issues_payload(issues_payload, stages=stages, artifacts=artifacts)
|
|
653
|
+
plan_errors = validate_repair_plan_payload(
|
|
654
|
+
plan_payload,
|
|
655
|
+
issues_payload=issues_payload,
|
|
656
|
+
stages=stages,
|
|
657
|
+
artifacts=artifacts,
|
|
658
|
+
)
|
|
659
|
+
if issue_errors or plan_errors:
|
|
660
|
+
raise RuntimeStateError(
|
|
661
|
+
"Repair planning failed contract validation.",
|
|
662
|
+
details={"feedback_errors": issue_errors, "repair_plan_errors": plan_errors},
|
|
663
|
+
)
|
|
664
|
+
|
|
665
|
+
run_id = _runtime_run_id(workspace=ws, repo_workdir=repo_workdir)
|
|
666
|
+
for issue in status_changed:
|
|
667
|
+
append_event(
|
|
668
|
+
workspace=ws,
|
|
669
|
+
run_id=run_id,
|
|
670
|
+
event_type="feedback_issue_planned",
|
|
671
|
+
actor=actor,
|
|
672
|
+
stage_id=issue.get("stage_id"),
|
|
673
|
+
artifact_id=issue.get("artifact_id"),
|
|
674
|
+
reason=str(issue.get("summary") or ""),
|
|
675
|
+
metadata={"issue_id": issue.get("issue_id")},
|
|
676
|
+
)
|
|
677
|
+
for plan in created_plans:
|
|
678
|
+
append_event(
|
|
679
|
+
workspace=ws,
|
|
680
|
+
run_id=run_id,
|
|
681
|
+
event_type="repair_plan_created",
|
|
682
|
+
actor=actor,
|
|
683
|
+
stage_id=plan.get("target_stage"),
|
|
684
|
+
reason=f"Repair plan created for {len(plan.get('issue_ids') or [])} issue(s).",
|
|
685
|
+
metadata={
|
|
686
|
+
"repair_plan_id": plan.get("repair_plan_id"),
|
|
687
|
+
"issue_ids": plan.get("issue_ids"),
|
|
688
|
+
"allowed_decision": plan.get("allowed_decision"),
|
|
689
|
+
},
|
|
690
|
+
)
|
|
691
|
+
|
|
692
|
+
_write_json_atomic(feedback_state_paths(ws)["feedback_issues"], issues_payload)
|
|
693
|
+
if created_plans or plans:
|
|
694
|
+
_write_json_atomic(feedback_state_paths(ws)["repair_plan"], plan_payload)
|
|
695
|
+
return show_feedback_state(workspace=ws, repo_workdir=repo_workdir)
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
def resolve_feedback(
|
|
699
|
+
*,
|
|
700
|
+
workspace: str | Path,
|
|
701
|
+
issue_id: str,
|
|
702
|
+
repair_plan_id: str,
|
|
703
|
+
reason: str,
|
|
704
|
+
delta_audit: str | Path | None = None,
|
|
705
|
+
repo_workdir: str | Path | None = None,
|
|
706
|
+
actor: str = FEEDBACK_EVENT_ACTOR,
|
|
707
|
+
) -> dict[str, Any]:
|
|
708
|
+
ws = _require_workspace(workspace)
|
|
709
|
+
_repo, stages, artifacts = _contracts(workspace=ws, repo_workdir=repo_workdir)
|
|
710
|
+
now = utc_now()
|
|
711
|
+
issues_payload = load_feedback_issues(ws)
|
|
712
|
+
if issues_payload is None:
|
|
713
|
+
raise RuntimeStateError(
|
|
714
|
+
"feedback_issues.json is not initialized.",
|
|
715
|
+
details={"workspace": str(ws)},
|
|
716
|
+
)
|
|
717
|
+
plan_payload = load_repair_plan(ws)
|
|
718
|
+
if plan_payload is None:
|
|
719
|
+
raise RuntimeStateError(
|
|
720
|
+
"repair_plan.json is not initialized.",
|
|
721
|
+
details={"workspace": str(ws)},
|
|
722
|
+
)
|
|
723
|
+
|
|
724
|
+
errors = validate_feedback_issues_payload(issues_payload, stages=stages, artifacts=artifacts)
|
|
725
|
+
errors.extend(
|
|
726
|
+
validate_repair_plan_payload(
|
|
727
|
+
plan_payload,
|
|
728
|
+
issues_payload=issues_payload,
|
|
729
|
+
stages=stages,
|
|
730
|
+
artifacts=artifacts,
|
|
731
|
+
)
|
|
732
|
+
)
|
|
733
|
+
if errors:
|
|
734
|
+
raise RuntimeStateError(
|
|
735
|
+
"Feedback state failed contract validation.",
|
|
736
|
+
details={"errors": errors},
|
|
737
|
+
)
|
|
738
|
+
|
|
739
|
+
delta_ref: str | None = None
|
|
740
|
+
if delta_audit is not None:
|
|
741
|
+
delta_path = Path(delta_audit).expanduser().resolve()
|
|
742
|
+
if not delta_path.exists():
|
|
743
|
+
raise RuntimeStateError(
|
|
744
|
+
f"Delta audit report not found: {delta_path}",
|
|
745
|
+
details={"path": str(delta_path)},
|
|
746
|
+
)
|
|
747
|
+
_read_json_or_text(delta_path)
|
|
748
|
+
delta_ref = _workspace_relative(ws, delta_path)
|
|
749
|
+
|
|
750
|
+
issues = [issue for issue in issues_payload.get("issues") or [] if isinstance(issue, dict)]
|
|
751
|
+
plans = [plan for plan in plan_payload.get("repair_plans") or [] if isinstance(plan, dict)]
|
|
752
|
+
target_issue = next((issue for issue in issues if issue.get("issue_id") == issue_id), None)
|
|
753
|
+
target_plan = next((plan for plan in plans if plan.get("repair_plan_id") == repair_plan_id), None)
|
|
754
|
+
if target_issue is None:
|
|
755
|
+
raise RuntimeStateError(
|
|
756
|
+
f"Unknown feedback issue: {issue_id}",
|
|
757
|
+
details={"issue_id": issue_id},
|
|
758
|
+
)
|
|
759
|
+
if target_plan is None:
|
|
760
|
+
raise RuntimeStateError(
|
|
761
|
+
f"Unknown repair plan: {repair_plan_id}",
|
|
762
|
+
details={"repair_plan_id": repair_plan_id},
|
|
763
|
+
)
|
|
764
|
+
if issue_id not in [str(item) for item in (target_plan.get("issue_ids") or [])]:
|
|
765
|
+
raise RuntimeStateError(
|
|
766
|
+
f"Repair plan '{repair_plan_id}' does not reference issue '{issue_id}'.",
|
|
767
|
+
details={"issue_id": issue_id, "repair_plan_id": repair_plan_id},
|
|
768
|
+
)
|
|
769
|
+
|
|
770
|
+
updated_issues: list[dict[str, Any]] = []
|
|
771
|
+
for issue in issues:
|
|
772
|
+
if issue.get("issue_id") == issue_id:
|
|
773
|
+
updated = dict(issue)
|
|
774
|
+
updated["status"] = "resolved"
|
|
775
|
+
updated["updated_at"] = now
|
|
776
|
+
updated["resolution"] = {
|
|
777
|
+
"reason": reason,
|
|
778
|
+
"repair_plan_id": repair_plan_id,
|
|
779
|
+
"delta_audit_report": delta_ref,
|
|
780
|
+
"resolved_at": now,
|
|
781
|
+
}
|
|
782
|
+
updated_issues.append(updated)
|
|
783
|
+
else:
|
|
784
|
+
updated_issues.append(issue)
|
|
785
|
+
|
|
786
|
+
updated_issue_status_by_id = {
|
|
787
|
+
str(issue.get("issue_id")): str(issue.get("status") or "")
|
|
788
|
+
for issue in updated_issues
|
|
789
|
+
if isinstance(issue, dict) and issue.get("issue_id")
|
|
790
|
+
}
|
|
791
|
+
target_plan_issue_ids = [str(item) for item in (target_plan.get("issue_ids") or [])]
|
|
792
|
+
unresolved_plan_issue_ids = [
|
|
793
|
+
plan_issue_id
|
|
794
|
+
for plan_issue_id in target_plan_issue_ids
|
|
795
|
+
if updated_issue_status_by_id.get(plan_issue_id) != "resolved"
|
|
796
|
+
]
|
|
797
|
+
plan_completed = not unresolved_plan_issue_ids
|
|
798
|
+
|
|
799
|
+
updated_plans: list[dict[str, Any]] = []
|
|
800
|
+
for plan in plans:
|
|
801
|
+
if plan.get("repair_plan_id") == repair_plan_id:
|
|
802
|
+
updated = dict(plan)
|
|
803
|
+
updated["updated_at"] = now
|
|
804
|
+
if plan_completed:
|
|
805
|
+
updated["status"] = "completed"
|
|
806
|
+
updated["completed_at"] = now
|
|
807
|
+
updated["completion_reason"] = reason
|
|
808
|
+
if delta_ref is not None:
|
|
809
|
+
updated["delta_audit_report"] = delta_ref
|
|
810
|
+
updated_plans.append(updated)
|
|
811
|
+
else:
|
|
812
|
+
updated_plans.append(plan)
|
|
813
|
+
|
|
814
|
+
issues_payload = dict(issues_payload)
|
|
815
|
+
issues_payload["updated_at"] = now
|
|
816
|
+
issues_payload["issues"] = updated_issues
|
|
817
|
+
plan_payload = dict(plan_payload)
|
|
818
|
+
plan_payload["updated_at"] = now
|
|
819
|
+
plan_payload["repair_plans"] = updated_plans
|
|
820
|
+
|
|
821
|
+
issue_errors = validate_feedback_issues_payload(issues_payload, stages=stages, artifacts=artifacts)
|
|
822
|
+
plan_errors = validate_repair_plan_payload(
|
|
823
|
+
plan_payload,
|
|
824
|
+
issues_payload=issues_payload,
|
|
825
|
+
stages=stages,
|
|
826
|
+
artifacts=artifacts,
|
|
827
|
+
)
|
|
828
|
+
if issue_errors or plan_errors:
|
|
829
|
+
raise RuntimeStateError(
|
|
830
|
+
"Resolved feedback state failed contract validation.",
|
|
831
|
+
details={"feedback_errors": issue_errors, "repair_plan_errors": plan_errors},
|
|
832
|
+
)
|
|
833
|
+
|
|
834
|
+
run_id = _runtime_run_id(workspace=ws, repo_workdir=repo_workdir)
|
|
835
|
+
target_stage = target_plan.get("target_stage") or target_issue.get("stage_id")
|
|
836
|
+
append_event(
|
|
837
|
+
workspace=ws,
|
|
838
|
+
run_id=run_id,
|
|
839
|
+
event_type="feedback_issue_resolved",
|
|
840
|
+
actor=actor,
|
|
841
|
+
stage_id=target_issue.get("stage_id"),
|
|
842
|
+
artifact_id=target_issue.get("artifact_id"),
|
|
843
|
+
reason=reason,
|
|
844
|
+
metadata={
|
|
845
|
+
"issue_id": issue_id,
|
|
846
|
+
"repair_plan_id": repair_plan_id,
|
|
847
|
+
"delta_audit_report": delta_ref,
|
|
848
|
+
"remaining_issue_ids": unresolved_plan_issue_ids,
|
|
849
|
+
},
|
|
850
|
+
)
|
|
851
|
+
if plan_completed:
|
|
852
|
+
append_event(
|
|
853
|
+
workspace=ws,
|
|
854
|
+
run_id=run_id,
|
|
855
|
+
event_type="repair_plan_completed",
|
|
856
|
+
actor=actor,
|
|
857
|
+
stage_id=str(target_stage) if target_stage else None,
|
|
858
|
+
reason=reason,
|
|
859
|
+
metadata={
|
|
860
|
+
"repair_plan_id": repair_plan_id,
|
|
861
|
+
"issue_id": issue_id,
|
|
862
|
+
"delta_audit_report": delta_ref,
|
|
863
|
+
},
|
|
864
|
+
)
|
|
865
|
+
|
|
866
|
+
_write_json_atomic(feedback_state_paths(ws)["feedback_issues"], issues_payload)
|
|
867
|
+
_write_json_atomic(feedback_state_paths(ws)["repair_plan"], plan_payload)
|
|
868
|
+
return show_feedback_state(workspace=ws, repo_workdir=repo_workdir)
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
def show_feedback_state(
|
|
872
|
+
*,
|
|
873
|
+
workspace: str | Path,
|
|
874
|
+
repo_workdir: str | Path | None = None,
|
|
875
|
+
) -> dict[str, Any]:
|
|
876
|
+
ws = _require_workspace(workspace)
|
|
877
|
+
_repo, stages, artifacts = _contracts(workspace=ws, repo_workdir=repo_workdir)
|
|
878
|
+
issues_payload = load_feedback_issues(ws)
|
|
879
|
+
plan_payload = load_repair_plan(ws)
|
|
880
|
+
validation = validate_feedback_state(workspace=ws, stages=stages, artifacts=artifacts)
|
|
881
|
+
return {
|
|
882
|
+
"ok": bool(validation.get("ok")),
|
|
883
|
+
"workspace": str(ws),
|
|
884
|
+
"feedback_state_files": dict(FEEDBACK_STATE_FILES),
|
|
885
|
+
"feedback_issues": issues_payload or empty_feedback_issues(updated_at=""),
|
|
886
|
+
"repair_plan": plan_payload,
|
|
887
|
+
"validation": validation,
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
def validate_feedback_workspace(
|
|
892
|
+
*,
|
|
893
|
+
workspace: str | Path,
|
|
894
|
+
repo_workdir: str | Path | None = None,
|
|
895
|
+
) -> dict[str, Any]:
|
|
896
|
+
ws = _require_workspace(workspace)
|
|
897
|
+
_repo, stages, artifacts = _contracts(workspace=ws, repo_workdir=repo_workdir)
|
|
898
|
+
return validate_feedback_state(workspace=ws, stages=stages, artifacts=artifacts)
|