qwen-sci 0.2.2__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.
- qwen_sci-0.2.2.dist-info/METADATA +492 -0
- qwen_sci-0.2.2.dist-info/RECORD +549 -0
- qwen_sci-0.2.2.dist-info/WHEEL +4 -0
- qwen_sci-0.2.2.dist-info/entry_points.txt +6 -0
- qwen_sci-0.2.2.dist-info/licenses/LICENSE +21 -0
- src/1.txt +1 -0
- src/__init__.py +1 -0
- src/__main__.py +5 -0
- src/agents/__init__.py +1 -0
- src/agents/experiment_design_agent/__init__.py +268 -0
- src/agents/experiment_design_agent/artifacts.py +747 -0
- src/agents/experiment_design_agent/cache.py +319 -0
- src/agents/experiment_design_agent/completeness.py +130 -0
- src/agents/experiment_design_agent/contracts.py +771 -0
- src/agents/experiment_design_agent/counterexample_analyzer.py +187 -0
- src/agents/experiment_design_agent/design_evidence_paper_screener.py +470 -0
- src/agents/experiment_design_agent/discipline_catalog.py +178 -0
- src/agents/experiment_design_agent/evidence_cards.py +338 -0
- src/agents/experiment_design_agent/evidence_planner.py +452 -0
- src/agents/experiment_design_agent/formal_reasoning_planner.py +884 -0
- src/agents/experiment_design_agent/fulltext_acquisition.py +863 -0
- src/agents/experiment_design_agent/idea_adapter.py +100 -0
- src/agents/experiment_design_agent/idea_intake.py +87 -0
- src/agents/experiment_design_agent/llm_json.py +328 -0
- src/agents/experiment_design_agent/orchestrator.py +1220 -0
- src/agents/experiment_design_agent/reasoning_context.py +183 -0
- src/agents/experiment_design_agent/reasoning_validation.py +546 -0
- src/agents/experiment_design_agent/run.py +481 -0
- src/agents/experiment_design_agent/run_logging.py +292 -0
- src/agents/experiment_design_agent/scope_gate.py +198 -0
- src/agents/experiment_design_agent/study_type_composer.py +1360 -0
- src/agents/experiment_design_agent/survey_evidence.py +1381 -0
- src/agents/experiment_design_agent/template_router.py +195 -0
- src/agents/experiment_design_agent/variable_claim_extractor.py +93 -0
- src/agents/idea_agent/__init__.py +1 -0
- src/agents/idea_agent/agent/__init__.py +6 -0
- src/agents/idea_agent/agent/artifacts.py +308 -0
- src/agents/idea_agent/agent/base.py +122 -0
- src/agents/idea_agent/agent/ligagent.py +488 -0
- src/agents/idea_agent/agent/mcts.py +2060 -0
- src/agents/idea_agent/agent/prompts/__init__.py +48 -0
- src/agents/idea_agent/agent/prompts/advanced_analysis.py +235 -0
- src/agents/idea_agent/agent/prompts/algorithm_alignment.py +55 -0
- src/agents/idea_agent/agent/prompts/algorithm_structuring.py +48 -0
- src/agents/idea_agent/agent/prompts/component_extraction.py +62 -0
- src/agents/idea_agent/agent/prompts/component_novelty_evaluation.py +54 -0
- src/agents/idea_agent/agent/prompts/experiment_findings_extraction.py +39 -0
- src/agents/idea_agent/agent/prompts/idea_fusion.py +295 -0
- src/agents/idea_agent/agent/prompts/idea_introduction.py +30 -0
- src/agents/idea_agent/agent/prompts/idea_result_alignment.py +39 -0
- src/agents/idea_agent/agent/prompts/input_interpreter.py +52 -0
- src/agents/idea_agent/agent/prompts/keynote_ops.py +78 -0
- src/agents/idea_agent/agent/prompts/mcts_evaluation.py +235 -0
- src/agents/idea_agent/agent/prompts/mcts_generation.py +140 -0
- src/agents/idea_agent/agent/prompts/mechanism_commit_query.py +99 -0
- src/agents/idea_agent/agent/prompts/memory_selection.py +0 -0
- src/agents/idea_agent/agent/prompts/prompt_modes.py +16 -0
- src/agents/idea_agent/agent/prompts/rag_query.py +34 -0
- src/agents/idea_agent/agent/prompts/re_analysis_replan.py +48 -0
- src/agents/idea_agent/agent/prompts/reference_grounding.py +34 -0
- src/agents/idea_agent/agent/prompts/root_domain_classification.py +32 -0
- src/agents/idea_agent/agent/prompts/scientific_debate.py +88 -0
- src/agents/idea_agent/agent/prompts/scientific_materialization.py +45 -0
- src/agents/idea_agent/agent/prompts/skill_instantiation.py +193 -0
- src/agents/idea_agent/agent/prompts/theory_transfer_query.py +93 -0
- src/agents/idea_agent/agent/prompts/topic_background.py +15 -0
- src/agents/idea_agent/agent/skills/DEFAULT_SKILL_TEMPLATES.json +263 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/alternative-path-contrast/SKILL.md +40 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/alternative-path-contrast/references/contrast_patterns.md +22 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/feedback-closed-loop/SKILL.md +40 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/feedback-closed-loop/references/mechanism_cards.md +24 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/hierarchical-decomposition/SKILL.md +39 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/hierarchical-decomposition/references/hierarchy_patterns.md +22 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/mechanism-commit-innovation/SKILL.md +39 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/mechanism-commit-innovation/references/mechanism_commit_patterns.md +24 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/multi-scale-coordinator/SKILL.md +39 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/multi-scale-coordinator/references/coordination_patterns.md +22 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/speculative-execution-with-repair/SKILL.md +41 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/speculative-execution-with-repair/references/speculation_patterns.md +22 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/surgical-modularity/SKILL.md +39 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/surgical-modularity/references/modularity_patterns.md +22 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/theory-transfer-injection/SKILL.md +40 -0
- src/agents/idea_agent/agent/skills/edit_operator_skills/theory-transfer-injection/references/transfer_patterns.md +24 -0
- src/agents/idea_agent/example/idea_result.json +900 -0
- src/agents/idea_agent/run.py +276 -0
- src/agents/idea_agent/tests/test_advanced_analysis_contract.py +90 -0
- src/agents/idea_agent/tests/test_gap_hypothesis_bridge.py +166 -0
- src/agents/idea_agent/tests/test_idea_debate.py +480 -0
- src/agents/idea_agent/tests/test_idea_result_v5.py +99 -0
- src/agents/idea_agent/tests/test_idea_synthesis.py +92 -0
- src/agents/idea_agent/tests/test_mature_idea_sources.py +27 -0
- src/agents/idea_agent/tests/test_multimodal_idea_integration.py +386 -0
- src/agents/idea_agent/tests/test_profile_materialization_and_scoring.py +219 -0
- src/agents/idea_agent/tests/test_profile_native_skill_rendering.py +122 -0
- src/agents/idea_agent/tests/test_result_persistence.py +183 -0
- src/agents/idea_agent/tests/test_scientific_intervention_profiles.py +241 -0
- src/agents/idea_agent/tests/test_scientific_rubric_and_prompts.py +559 -0
- src/agents/idea_agent/tests/test_strict_json_object_responses.py +48 -0
- src/agents/idea_agent/utils/core/__init__.py +1 -0
- src/agents/idea_agent/utils/core/ablation_inputs.py +60 -0
- src/agents/idea_agent/utils/core/chat_errors.py +95 -0
- src/agents/idea_agent/utils/core/chat_router.py +130 -0
- src/agents/idea_agent/utils/core/chat_transport.py +188 -0
- src/agents/idea_agent/utils/core/config_loader.py +166 -0
- src/agents/idea_agent/utils/core/json_utils.py +28 -0
- src/agents/idea_agent/utils/core/logger.py +287 -0
- src/agents/idea_agent/utils/core/progress.py +58 -0
- src/agents/idea_agent/utils/core/response_parsing.py +57 -0
- src/agents/idea_agent/utils/core/run_inputs.py +198 -0
- src/agents/idea_agent/utils/mcts/__init__.py +1 -0
- src/agents/idea_agent/utils/mcts/component_novelty.py +342 -0
- src/agents/idea_agent/utils/mcts/defect_registry.py +302 -0
- src/agents/idea_agent/utils/mcts/idea_routes.py +61 -0
- src/agents/idea_agent/utils/mcts/idea_taste_presets.py +312 -0
- src/agents/idea_agent/utils/mcts/mcts_helpers.py +738 -0
- src/agents/idea_agent/utils/mcts/mcts_runtime.py +3000 -0
- src/agents/idea_agent/utils/mcts/scientific_intervention_ontology.py +1561 -0
- src/agents/idea_agent/utils/mcts/scientific_rubric.py +211 -0
- src/agents/idea_agent/utils/mcts/skill_parsing.py +92 -0
- src/agents/idea_agent/utils/papers/__init__.py +1 -0
- src/agents/idea_agent/utils/papers/paper_graph_vector_store.py +499 -0
- src/agents/idea_agent/utils/papers/paper_repository.py +372 -0
- src/agents/idea_agent/utils/prompting/__init__.py +1 -0
- src/agents/idea_agent/utils/prompting/prompt_views.py +637 -0
- src/agents/idea_agent/utils/workflow/__init__.py +1 -0
- src/agents/idea_agent/utils/workflow/advanced_analysis_contract.py +244 -0
- src/agents/idea_agent/utils/workflow/gap_hypothesis_bridge.py +461 -0
- src/agents/idea_agent/utils/workflow/idea_contract.py +426 -0
- src/agents/idea_agent/utils/workflow/idea_debate.py +1238 -0
- src/agents/idea_agent/utils/workflow/idea_diversity.py +163 -0
- src/agents/idea_agent/utils/workflow/idea_fusion.py +889 -0
- src/agents/idea_agent/utils/workflow/idea_helpers.py +478 -0
- src/agents/idea_agent/utils/workflow/idea_portfolio.py +422 -0
- src/agents/idea_agent/utils/workflow/idea_synthesis.py +482 -0
- src/agents/idea_agent/utils/workflow/ligagent_flow.py +581 -0
- src/agents/idea_agent/utils/workflow/ligagent_handlers.py +1836 -0
- src/agents/idea_agent/utils/workflow/ligagent_helpers.py +1331 -0
- src/agents/idea_agent/utils/workflow/ligagent_utils.py +322 -0
- src/agents/idea_agent/utils/workflow/mature_idea_sources.py +648 -0
- src/agents/idea_agent/utils/workflow/multimodal_data_anchoring.py +578 -0
- src/agents/idea_agent/utils/workflow/result_persistence.py +774 -0
- src/agents/idea_agent/utils/workflow/stage_contract.py +76 -0
- src/agents/idea_agent/utils/workflow/workflow_runtime.py +288 -0
- src/agents/research_plan_author/__init__.py +50 -0
- src/agents/research_plan_author/artifacts.py +270 -0
- src/agents/research_plan_author/authoring_blueprint.py +1246 -0
- src/agents/research_plan_author/bibtex_renderer.py +252 -0
- src/agents/research_plan_author/contract_repair.py +131 -0
- src/agents/research_plan_author/contracts.py +745 -0
- src/agents/research_plan_author/cross_section_editor.py +232 -0
- src/agents/research_plan_author/document_quality.py +987 -0
- src/agents/research_plan_author/idea_evolution.py +223 -0
- src/agents/research_plan_author/input_loader.py +76 -0
- src/agents/research_plan_author/latex_compiler.py +260 -0
- src/agents/research_plan_author/latex_safety.py +159 -0
- src/agents/research_plan_author/llm_json.py +74 -0
- src/agents/research_plan_author/markdown_renderer.py +275 -0
- src/agents/research_plan_author/pdf_validator.py +149 -0
- src/agents/research_plan_author/render.py +166 -0
- src/agents/research_plan_author/render_artifacts.py +187 -0
- src/agents/research_plan_author/run.py +765 -0
- src/agents/research_plan_author/run_logging.py +209 -0
- src/agents/research_plan_author/section_cache.py +184 -0
- src/agents/research_plan_author/section_composer.py +1764 -0
- src/agents/research_plan_author/section_router.py +209 -0
- src/agents/research_plan_author/semantic_validator.py +254 -0
- src/agents/research_plan_author/source_bundle.py +46 -0
- src/agents/research_plan_author/source_registry.py +208 -0
- src/agents/research_plan_author/survey_source_loader.py +137 -0
- src/agents/research_plan_author/template_adapter.py +173 -0
- src/agents/research_plan_author/template_profile.py +204 -0
- src/agents/research_plan_author/tex_renderer.py +496 -0
- src/agents/research_plan_author/theory_presentation.py +134 -0
- src/agents/research_plan_author/theory_spine.py +703 -0
- src/agents/survey_agent/Dockerfile +54 -0
- src/agents/survey_agent/README.md +350 -0
- src/agents/survey_agent/config/deep_survey.yaml +217 -0
- src/agents/survey_agent/config/deep_survey_batch.yaml +176 -0
- src/agents/survey_agent/config/deep_survey_fast.yaml +183 -0
- src/agents/survey_agent/config/evaluate_baseline.yaml +197 -0
- src/agents/survey_agent/config/outcomeRAG.yaml +159 -0
- src/agents/survey_agent/env_report.md +348 -0
- src/agents/survey_agent/modules/__init__.py +0 -0
- src/agents/survey_agent/modules/code_collector.py +2194 -0
- src/agents/survey_agent/modules/code_report_generator.py +1282 -0
- src/agents/survey_agent/modules/data_manager.py +1713 -0
- src/agents/survey_agent/modules/database.py +167 -0
- src/agents/survey_agent/modules/fulltext_download_cache.py +462 -0
- src/agents/survey_agent/modules/fulltext_http.py +134 -0
- src/agents/survey_agent/modules/fulltext_resolution.py +749 -0
- src/agents/survey_agent/modules/judge.py +434 -0
- src/agents/survey_agent/modules/outcome_RAG.py +236 -0
- src/agents/survey_agent/modules/paper_graph_retriever.py +1075 -0
- src/agents/survey_agent/modules/pe.py +1729 -0
- src/agents/survey_agent/modules/pseudo_creator.py +782 -0
- src/agents/survey_agent/modules/pseudo_reviser.py +537 -0
- src/agents/survey_agent/modules/refine_agent.py +1952 -0
- src/agents/survey_agent/modules/survey_generator.py +5691 -0
- src/agents/survey_agent/modules/survey_visualizer.py +1817 -0
- src/agents/survey_agent/modules/visual_prompts.py +327 -0
- src/agents/survey_agent/modules/work_analyzer.py +2750 -0
- src/agents/survey_agent/modules/work_collector.py +5649 -0
- src/agents/survey_agent/scripts/baseline_evaluation.py +411 -0
- src/agents/survey_agent/scripts/run_deep_survey.py +224 -0
- src/agents/survey_agent/scripts/run_deep_survey_adapter.py +407 -0
- src/agents/survey_agent/scripts/run_deep_survey_adapter_with_input.py +409 -0
- src/agents/survey_agent/scripts/run_deep_survey_batch.py +228 -0
- src/agents/survey_agent/scripts/run_deep_survey_batch_arg.py +243 -0
- src/agents/survey_agent/scripts/run_deep_survey_batch_settings.py +218 -0
- src/agents/survey_agent/scripts/run_keynotes_gen.py +128 -0
- src/agents/survey_agent/scripts/run_work_clusters.py +140 -0
- src/agents/survey_agent/utils/__init__.py +0 -0
- src/agents/survey_agent/utils/ablation_utils.py +317 -0
- src/agents/survey_agent/utils/api_call.py +2518 -0
- src/agents/survey_agent/utils/chat_utils.py +82 -0
- src/agents/survey_agent/utils/config_utils.py +70 -0
- src/agents/survey_agent/utils/convert_to_md.py +29 -0
- src/agents/survey_agent/utils/err_info.py +24 -0
- src/agents/survey_agent/utils/file_utils.py +176 -0
- src/agents/survey_agent/utils/gpu_utils.py +145 -0
- src/agents/survey_agent/utils/graph_visualizer.py +279 -0
- src/agents/survey_agent/utils/html_utils.py +181 -0
- src/agents/survey_agent/utils/latex_generator_intra_cluster.py +529 -0
- src/agents/survey_agent/utils/latex_generator_relation_table.py +193 -0
- src/agents/survey_agent/utils/mineru_section_packer.py +334 -0
- src/agents/survey_agent/utils/mineru_utils.py +396 -0
- src/agents/survey_agent/utils/paper.py +144 -0
- src/agents/survey_agent/utils/read_yaml.py +15 -0
- src/agents/survey_agent/utils/repo_utils.py +167 -0
- src/agents/survey_agent/utils/rich_logger.py +77 -0
- src/agents/survey_agent/utils/step2v2.py +874 -0
- src/agents/survey_agent/utils/step2v2_extractor.py +856 -0
- src/agents/survey_agent/utils/topic_survey_storage.py +309 -0
- src/agents/survey_agent/utils/utils.py +118 -0
- src/agents/survey_agent/utils/work.py +2 -0
- src/cli.py +1611 -0
- src/config/__init__.py +213 -0
- src/config/default.yaml +1122 -0
- src/harness/LICENSE +21 -0
- src/harness/VENDORED.md +14 -0
- src/harness/src/__init__.py +0 -0
- src/harness/src/openharness/__init__.py +0 -0
- src/harness/src/openharness/__main__.py +6 -0
- src/harness/src/openharness/api/__init__.py +21 -0
- src/harness/src/openharness/api/client.py +281 -0
- src/harness/src/openharness/api/codex_client.py +407 -0
- src/harness/src/openharness/api/copilot_auth.py +240 -0
- src/harness/src/openharness/api/copilot_client.py +134 -0
- src/harness/src/openharness/api/errors.py +19 -0
- src/harness/src/openharness/api/openai_client.py +577 -0
- src/harness/src/openharness/api/provider.py +186 -0
- src/harness/src/openharness/api/registry.py +437 -0
- src/harness/src/openharness/api/usage.py +17 -0
- src/harness/src/openharness/auth/__init__.py +29 -0
- src/harness/src/openharness/auth/external.py +610 -0
- src/harness/src/openharness/auth/flows.py +189 -0
- src/harness/src/openharness/auth/manager.py +482 -0
- src/harness/src/openharness/auth/storage.py +269 -0
- src/harness/src/openharness/autopilot/__init__.py +23 -0
- src/harness/src/openharness/autopilot/service.py +2239 -0
- src/harness/src/openharness/autopilot/types.py +91 -0
- src/harness/src/openharness/bridge/__init__.py +20 -0
- src/harness/src/openharness/bridge/manager.py +106 -0
- src/harness/src/openharness/bridge/session_runner.py +46 -0
- src/harness/src/openharness/bridge/types.py +37 -0
- src/harness/src/openharness/bridge/work_secret.py +41 -0
- src/harness/src/openharness/channels/UPSTREAM +6 -0
- src/harness/src/openharness/channels/__init__.py +22 -0
- src/harness/src/openharness/channels/adapter.py +131 -0
- src/harness/src/openharness/channels/bus/__init__.py +6 -0
- src/harness/src/openharness/channels/bus/events.py +38 -0
- src/harness/src/openharness/channels/bus/queue.py +44 -0
- src/harness/src/openharness/channels/impl/__init__.py +6 -0
- src/harness/src/openharness/channels/impl/base.py +141 -0
- src/harness/src/openharness/channels/impl/dingtalk.py +445 -0
- src/harness/src/openharness/channels/impl/discord.py +311 -0
- src/harness/src/openharness/channels/impl/email.py +410 -0
- src/harness/src/openharness/channels/impl/feishu.py +1342 -0
- src/harness/src/openharness/channels/impl/manager.py +257 -0
- src/harness/src/openharness/channels/impl/matrix.py +700 -0
- src/harness/src/openharness/channels/impl/mochat.py +897 -0
- src/harness/src/openharness/channels/impl/qq.py +141 -0
- src/harness/src/openharness/channels/impl/slack.py +284 -0
- src/harness/src/openharness/channels/impl/telegram.py +525 -0
- src/harness/src/openharness/channels/impl/whatsapp.py +159 -0
- src/harness/src/openharness/cli.py +2551 -0
- src/harness/src/openharness/commands/__init__.py +21 -0
- src/harness/src/openharness/commands/registry.py +2783 -0
- src/harness/src/openharness/config/__init__.py +34 -0
- src/harness/src/openharness/config/paths.py +160 -0
- src/harness/src/openharness/config/schema.py +119 -0
- src/harness/src/openharness/config/settings.py +1104 -0
- src/harness/src/openharness/coordinator/__init__.py +12 -0
- src/harness/src/openharness/coordinator/agent_definitions.py +975 -0
- src/harness/src/openharness/coordinator/coordinator_mode.py +520 -0
- src/harness/src/openharness/engine/__init__.py +80 -0
- src/harness/src/openharness/engine/cost_tracker.py +24 -0
- src/harness/src/openharness/engine/messages.py +222 -0
- src/harness/src/openharness/engine/query.py +1188 -0
- src/harness/src/openharness/engine/query_engine.py +313 -0
- src/harness/src/openharness/engine/stream_events.py +90 -0
- src/harness/src/openharness/hooks/__init__.py +50 -0
- src/harness/src/openharness/hooks/events.py +20 -0
- src/harness/src/openharness/hooks/executor.py +242 -0
- src/harness/src/openharness/hooks/hot_reload.py +31 -0
- src/harness/src/openharness/hooks/loader.py +68 -0
- src/harness/src/openharness/hooks/schemas.py +66 -0
- src/harness/src/openharness/hooks/types.py +38 -0
- src/harness/src/openharness/keybindings/__init__.py +14 -0
- src/harness/src/openharness/keybindings/default_bindings.py +11 -0
- src/harness/src/openharness/keybindings/loader.py +22 -0
- src/harness/src/openharness/keybindings/parser.py +18 -0
- src/harness/src/openharness/keybindings/resolver.py +13 -0
- src/harness/src/openharness/mcp/__init__.py +79 -0
- src/harness/src/openharness/mcp/client.py +298 -0
- src/harness/src/openharness/mcp/config.py +16 -0
- src/harness/src/openharness/mcp/types.py +76 -0
- src/harness/src/openharness/memory/__init__.py +25 -0
- src/harness/src/openharness/memory/agent.py +91 -0
- src/harness/src/openharness/memory/manager.py +183 -0
- src/harness/src/openharness/memory/memdir.py +52 -0
- src/harness/src/openharness/memory/migrate.py +137 -0
- src/harness/src/openharness/memory/paths.py +22 -0
- src/harness/src/openharness/memory/relevance.py +145 -0
- src/harness/src/openharness/memory/scan.py +116 -0
- src/harness/src/openharness/memory/schema.py +443 -0
- src/harness/src/openharness/memory/search.py +71 -0
- src/harness/src/openharness/memory/team.py +90 -0
- src/harness/src/openharness/memory/types.py +33 -0
- src/harness/src/openharness/memory/usage.py +153 -0
- src/harness/src/openharness/output_styles/__init__.py +5 -0
- src/harness/src/openharness/output_styles/loader.py +42 -0
- src/harness/src/openharness/permissions/__init__.py +26 -0
- src/harness/src/openharness/permissions/checker.py +200 -0
- src/harness/src/openharness/permissions/modes.py +13 -0
- src/harness/src/openharness/personalization/__init__.py +6 -0
- src/harness/src/openharness/personalization/extractor.py +138 -0
- src/harness/src/openharness/personalization/rules.py +64 -0
- src/harness/src/openharness/personalization/session_hook.py +65 -0
- src/harness/src/openharness/platforms.py +86 -0
- src/harness/src/openharness/plugins/__init__.py +53 -0
- src/harness/src/openharness/plugins/bundled/__init__.py +0 -0
- src/harness/src/openharness/plugins/installer.py +39 -0
- src/harness/src/openharness/plugins/loader.py +730 -0
- src/harness/src/openharness/plugins/schemas.py +24 -0
- src/harness/src/openharness/plugins/types.py +59 -0
- src/harness/src/openharness/prompts/__init__.py +14 -0
- src/harness/src/openharness/prompts/claudemd.py +48 -0
- src/harness/src/openharness/prompts/context.py +187 -0
- src/harness/src/openharness/prompts/environment.py +135 -0
- src/harness/src/openharness/prompts/system_prompt.py +109 -0
- src/harness/src/openharness/sandbox/Dockerfile +6 -0
- src/harness/src/openharness/sandbox/__init__.py +33 -0
- src/harness/src/openharness/sandbox/adapter.py +148 -0
- src/harness/src/openharness/sandbox/docker_backend.py +232 -0
- src/harness/src/openharness/sandbox/docker_image.py +103 -0
- src/harness/src/openharness/sandbox/path_validator.py +37 -0
- src/harness/src/openharness/sandbox/session.py +63 -0
- src/harness/src/openharness/services/__init__.py +30 -0
- src/harness/src/openharness/services/autodream/__init__.py +34 -0
- src/harness/src/openharness/services/autodream/backup.py +104 -0
- src/harness/src/openharness/services/autodream/lock.py +138 -0
- src/harness/src/openharness/services/autodream/prompt.py +128 -0
- src/harness/src/openharness/services/autodream/service.py +313 -0
- src/harness/src/openharness/services/compact/__init__.py +1725 -0
- src/harness/src/openharness/services/cron.py +137 -0
- src/harness/src/openharness/services/cron_scheduler.py +595 -0
- src/harness/src/openharness/services/lsp/__init__.py +216 -0
- src/harness/src/openharness/services/memory_extract/__init__.py +261 -0
- src/harness/src/openharness/services/oauth/__init__.py +0 -0
- src/harness/src/openharness/services/session_backend.py +97 -0
- src/harness/src/openharness/services/session_memory/__init__.py +139 -0
- src/harness/src/openharness/services/session_storage.py +230 -0
- src/harness/src/openharness/services/token_estimation.py +15 -0
- src/harness/src/openharness/services/tool_outputs.py +55 -0
- src/harness/src/openharness/skills/__init__.py +44 -0
- src/harness/src/openharness/skills/_frontmatter.py +97 -0
- src/harness/src/openharness/skills/bundled/__init__.py +75 -0
- src/harness/src/openharness/skills/bundled/content/commit.md +25 -0
- src/harness/src/openharness/skills/bundled/content/debug.md +25 -0
- src/harness/src/openharness/skills/bundled/content/diagnose.md +35 -0
- src/harness/src/openharness/skills/bundled/content/plan.md +39 -0
- src/harness/src/openharness/skills/bundled/content/review.md +33 -0
- src/harness/src/openharness/skills/bundled/content/simplify.md +26 -0
- src/harness/src/openharness/skills/bundled/content/skill-creator.md +175 -0
- src/harness/src/openharness/skills/bundled/content/test.md +38 -0
- src/harness/src/openharness/skills/loader.py +229 -0
- src/harness/src/openharness/skills/registry.py +29 -0
- src/harness/src/openharness/skills/types.py +24 -0
- src/harness/src/openharness/state/__init__.py +6 -0
- src/harness/src/openharness/state/app_state.py +30 -0
- src/harness/src/openharness/state/store.py +40 -0
- src/harness/src/openharness/swarm/__init__.py +70 -0
- src/harness/src/openharness/swarm/in_process.py +693 -0
- src/harness/src/openharness/swarm/lockfile.py +24 -0
- src/harness/src/openharness/swarm/mailbox.py +522 -0
- src/harness/src/openharness/swarm/permission_sync.py +1168 -0
- src/harness/src/openharness/swarm/registry.py +410 -0
- src/harness/src/openharness/swarm/spawn_utils.py +229 -0
- src/harness/src/openharness/swarm/subprocess_backend.py +171 -0
- src/harness/src/openharness/swarm/team_lifecycle.py +910 -0
- src/harness/src/openharness/swarm/types.py +398 -0
- src/harness/src/openharness/swarm/worktree.py +315 -0
- src/harness/src/openharness/tasks/__init__.py +18 -0
- src/harness/src/openharness/tasks/local_agent_task.py +28 -0
- src/harness/src/openharness/tasks/local_shell_task.py +17 -0
- src/harness/src/openharness/tasks/manager.py +475 -0
- src/harness/src/openharness/tasks/stop_task.py +11 -0
- src/harness/src/openharness/tasks/types.py +32 -0
- src/harness/src/openharness/themes/__init__.py +21 -0
- src/harness/src/openharness/themes/builtin.py +89 -0
- src/harness/src/openharness/themes/loader.py +55 -0
- src/harness/src/openharness/themes/schema.py +54 -0
- src/harness/src/openharness/tools/__init__.py +107 -0
- src/harness/src/openharness/tools/agent_tool.py +141 -0
- src/harness/src/openharness/tools/ask_user_question_tool.py +46 -0
- src/harness/src/openharness/tools/base.py +80 -0
- src/harness/src/openharness/tools/bash_tool.py +259 -0
- src/harness/src/openharness/tools/brief_tool.py +33 -0
- src/harness/src/openharness/tools/config_tool.py +54 -0
- src/harness/src/openharness/tools/cron_create_tool.py +105 -0
- src/harness/src/openharness/tools/cron_delete_tool.py +32 -0
- src/harness/src/openharness/tools/cron_list_tool.py +69 -0
- src/harness/src/openharness/tools/cron_toggle_tool.py +37 -0
- src/harness/src/openharness/tools/enter_plan_mode_tool.py +28 -0
- src/harness/src/openharness/tools/enter_worktree_tool.py +80 -0
- src/harness/src/openharness/tools/exit_plan_mode_tool.py +28 -0
- src/harness/src/openharness/tools/exit_worktree_tool.py +42 -0
- src/harness/src/openharness/tools/file_edit_tool.py +95 -0
- src/harness/src/openharness/tools/file_read_tool.py +72 -0
- src/harness/src/openharness/tools/file_write_tool.py +87 -0
- src/harness/src/openharness/tools/glob_tool.py +175 -0
- src/harness/src/openharness/tools/grep_tool.py +374 -0
- src/harness/src/openharness/tools/image_generation_tool.py +447 -0
- src/harness/src/openharness/tools/image_to_text_tool.py +237 -0
- src/harness/src/openharness/tools/list_mcp_resources_tool.py +36 -0
- src/harness/src/openharness/tools/lsp_tool.py +154 -0
- src/harness/src/openharness/tools/mcp_auth_tool.py +71 -0
- src/harness/src/openharness/tools/mcp_tool.py +72 -0
- src/harness/src/openharness/tools/notebook_edit_tool.py +97 -0
- src/harness/src/openharness/tools/read_mcp_resource_tool.py +38 -0
- src/harness/src/openharness/tools/remote_trigger_tool.py +74 -0
- src/harness/src/openharness/tools/send_message_tool.py +58 -0
- src/harness/src/openharness/tools/skill_tool.py +43 -0
- src/harness/src/openharness/tools/sleep_tool.py +32 -0
- src/harness/src/openharness/tools/task_create_tool.py +56 -0
- src/harness/src/openharness/tools/task_get_tool.py +33 -0
- src/harness/src/openharness/tools/task_list_tool.py +35 -0
- src/harness/src/openharness/tools/task_output_tool.py +35 -0
- src/harness/src/openharness/tools/task_stop_tool.py +30 -0
- src/harness/src/openharness/tools/task_update_tool.py +50 -0
- src/harness/src/openharness/tools/team_create_tool.py +31 -0
- src/harness/src/openharness/tools/team_delete_tool.py +30 -0
- src/harness/src/openharness/tools/todo_write_tool.py +46 -0
- src/harness/src/openharness/tools/tool_search_tool.py +38 -0
- src/harness/src/openharness/tools/web_fetch_tool.py +117 -0
- src/harness/src/openharness/tools/web_search_tool.py +119 -0
- src/harness/src/openharness/ui/__init__.py +5 -0
- src/harness/src/openharness/ui/app.py +320 -0
- src/harness/src/openharness/ui/backend_host.py +941 -0
- src/harness/src/openharness/ui/coordinator_drain.py +198 -0
- src/harness/src/openharness/ui/input.py +32 -0
- src/harness/src/openharness/ui/output.py +265 -0
- src/harness/src/openharness/ui/permission_dialog.py +14 -0
- src/harness/src/openharness/ui/protocol.py +247 -0
- src/harness/src/openharness/ui/react_launcher.py +179 -0
- src/harness/src/openharness/ui/runtime.py +799 -0
- src/harness/src/openharness/ui/textual_app.py +495 -0
- src/harness/src/openharness/utils/__init__.py +0 -0
- src/harness/src/openharness/utils/file_lock.py +86 -0
- src/harness/src/openharness/utils/fs.py +98 -0
- src/harness/src/openharness/utils/helpers.py +77 -0
- src/harness/src/openharness/utils/network_guard.py +340 -0
- src/harness/src/openharness/utils/shell.py +147 -0
- src/harness/src/openharness/vim/__init__.py +5 -0
- src/harness/src/openharness/vim/transitions.py +8 -0
- src/harness/src/openharness/voice/__init__.py +7 -0
- src/harness/src/openharness/voice/keyterms.py +10 -0
- src/harness/src/openharness/voice/stream_stt.py +8 -0
- src/harness/src/openharness/voice/voice_mode.py +44 -0
- src/llm/__init__.py +29 -0
- src/llm/image_generation.py +402 -0
- src/llm/provider_registry.py +419 -0
- src/llm/runtime_env.py +64 -0
- src/llm/structured_output.py +131 -0
- src/llm/vision.py +198 -0
- src/memory/__init__.py +2 -0
- src/memory/api/__init__.py +1 -0
- src/memory/api/base_memory_system_api.py +98 -0
- src/memory/api/base_symbolic_memory_system_api.py +190 -0
- src/memory/api/base_vector_memory_system_api.py +116 -0
- src/memory/api/faiss_memory_system_api.py +228 -0
- src/memory/api/slot_process_api.py +827 -0
- src/memory/api/symbolic_memory_system_api.py +572 -0
- src/memory/memory_system/__init__.py +48 -0
- src/memory/memory_system/component_taxonomy.py +430 -0
- src/memory/memory_system/llm.py +437 -0
- src/memory/memory_system/models.py +168 -0
- src/memory/memory_system/user_prompt.py +418 -0
- src/memory/memory_system/utils.py +282 -0
- src/memory/memory_system/vectorstore.py +311 -0
- src/memory/memory_system/working_slot.py +99 -0
- src/pipeline/__init__.py +129 -0
- src/pipeline/contracts.py +531 -0
- src/pipeline/discipline_taxonomy.py +916 -0
- src/pipeline/evidence_coverage_ledger.py +1150 -0
- src/pipeline/evidence_refinement.py +620 -0
- src/pipeline/experiment_to_symbolic.py +137 -0
- src/pipeline/multimodal_evidence/__init__.py +28 -0
- src/pipeline/multimodal_evidence/capabilities.py +107 -0
- src/pipeline/multimodal_evidence/claims.py +135 -0
- src/pipeline/multimodal_evidence/contract.py +291 -0
- src/pipeline/multimodal_evidence/data_sh_compiler.py +505 -0
- src/pipeline/multimodal_evidence/handoff_binding.py +135 -0
- src/pipeline/multimodal_evidence/manifest.py +254 -0
- src/pipeline/multimodal_evidence/native_analysis.py +479 -0
- src/pipeline/multimodal_evidence/perception.py +277 -0
- src/pipeline/multimodal_evidence/query_binding.py +65 -0
- src/pipeline/multimodal_evidence/rendering.py +120 -0
- src/pipeline/multimodal_evidence/safety.py +42 -0
- src/pipeline/multimodal_evidence/sampling.py +69 -0
- src/pipeline/multimodal_evidence/service.py +148 -0
- src/pipeline/multimodal_evidence/survey_integration.py +460 -0
- src/pipeline/paper_identity.py +52 -0
- src/pipeline/research_design_inventory.py +338 -0
- src/pipeline/research_domain_resolution.py +669 -0
- src/pipeline/research_identity.py +548 -0
- src/pipeline/research_question_contract.py +646 -0
- src/pipeline/retrieval_lanes.py +889 -0
- src/pipeline/run_loop.py +862 -0
- src/pipeline/science_events.py +30 -0
- src/pipeline/science_manifests.py +602 -0
- src/pipeline/science_run.py +918 -0
- src/pipeline/science_stages.py +709 -0
- src/pipeline/science_workflow.py +807 -0
- src/pipeline/sh_cluster_projection.py +306 -0
- src/pipeline/sh_graph_provenance.py +648 -0
- src/pipeline/subhypothesis_decomposition.py +392 -0
- src/pipeline/subhypothesis_evidence.py +856 -0
- src/pipeline/survey_evidence_plan.py +858 -0
- src/pipeline/survey_gap_adjudication.py +647 -0
- src/pipeline/survey_gap_candidates.py +840 -0
- src/pipeline/survey_gap_ledger.py +683 -0
- src/pipeline/survey_gap_triage.py +401 -0
- src/pipeline/survey_handoff_persistence.py +481 -0
- src/pipeline/survey_handoff_projection.py +457 -0
- src/pipeline/survey_idea_handoff.py +1112 -0
- src/pipeline/survey_idea_loader.py +289 -0
- src/research_run_ids.py +11 -0
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
"""Versioned JSON contracts for ExperimentDesign Agent's design-only phase."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from copy import deepcopy
|
|
6
|
+
from typing import Any, Mapping
|
|
7
|
+
|
|
8
|
+
from jsonschema import Draft202012Validator
|
|
9
|
+
|
|
10
|
+
from .reasoning_context import (
|
|
11
|
+
REASONING_CONTEXT_SCHEMA,
|
|
12
|
+
REASONING_CONTEXT_SCHEMA_VERSION,
|
|
13
|
+
build_reasoning_context_from_idea_result,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
from .discipline_catalog import (
|
|
17
|
+
DESIGN_ONLY,
|
|
18
|
+
DIGITAL_EXECUTION_ELIGIBLE,
|
|
19
|
+
normalize_discipline_ids,
|
|
20
|
+
resolve_design_scope,
|
|
21
|
+
resolve_execution_policy,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
RESEARCH_BRIEF_SCHEMA_VERSION = "research_brief_v1"
|
|
26
|
+
EVIDENCE_BUNDLE_SCHEMA_VERSION = "evidence_bundle_v1"
|
|
27
|
+
OUTCOME_BRANCH_SCHEMA_VERSION = "outcome_branch_v1"
|
|
28
|
+
EXPERIMENT_DESIGN_SCHEMA_VERSION = "experiment_design_v1"
|
|
29
|
+
|
|
30
|
+
_NONEMPTY_STRING = {"type": "string", "minLength": 1}
|
|
31
|
+
_STRING_LIST = {"type": "array", "items": _NONEMPTY_STRING}
|
|
32
|
+
_STATUS_VALUE = {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"enum": [
|
|
35
|
+
"evidence_backed",
|
|
36
|
+
"user_declared",
|
|
37
|
+
"design_assumption",
|
|
38
|
+
"needs_human_input",
|
|
39
|
+
"not_applicable",
|
|
40
|
+
],
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
RESEARCH_BRIEF_SCHEMA: dict[str, Any] = {
|
|
44
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
45
|
+
"title": "ResearchBrief v1",
|
|
46
|
+
"type": "object",
|
|
47
|
+
"additionalProperties": False,
|
|
48
|
+
"required": [
|
|
49
|
+
"schema_version",
|
|
50
|
+
"brief_id",
|
|
51
|
+
"topic",
|
|
52
|
+
"discipline_ids",
|
|
53
|
+
"selected_direction",
|
|
54
|
+
"research_object",
|
|
55
|
+
"evidence_status",
|
|
56
|
+
"known_unknowns",
|
|
57
|
+
"source",
|
|
58
|
+
"reasoning_context",
|
|
59
|
+
],
|
|
60
|
+
"properties": {
|
|
61
|
+
"schema_version": {"const": RESEARCH_BRIEF_SCHEMA_VERSION},
|
|
62
|
+
"brief_id": _NONEMPTY_STRING,
|
|
63
|
+
"topic": _NONEMPTY_STRING,
|
|
64
|
+
"discipline_ids": {"type": "array", "minItems": 1, "uniqueItems": True, "items": _NONEMPTY_STRING},
|
|
65
|
+
"selected_direction": {
|
|
66
|
+
"type": "object",
|
|
67
|
+
"additionalProperties": False,
|
|
68
|
+
"required": ["id", "title", "central_hypothesis", "mechanism_or_relation"],
|
|
69
|
+
"properties": {
|
|
70
|
+
"id": _NONEMPTY_STRING,
|
|
71
|
+
"title": _NONEMPTY_STRING,
|
|
72
|
+
"central_hypothesis": _NONEMPTY_STRING,
|
|
73
|
+
"mechanism_or_relation": {"type": "string"},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
"research_object": {"type": "object", "minProperties": 1},
|
|
77
|
+
"intervention_or_transformation": {"type": "string"},
|
|
78
|
+
"discriminating_observations": _STRING_LIST,
|
|
79
|
+
"boundary_conditions": _STRING_LIST,
|
|
80
|
+
"alternative_explanations": _STRING_LIST,
|
|
81
|
+
"known_unknowns": _STRING_LIST,
|
|
82
|
+
"evidence_status": {"const": "PROPOSED"},
|
|
83
|
+
"source": {
|
|
84
|
+
"type": "object",
|
|
85
|
+
"additionalProperties": False,
|
|
86
|
+
"required": ["idea_result_schema", "direction_id"],
|
|
87
|
+
"properties": {
|
|
88
|
+
"idea_result_schema": {"const": "idea_result_v5"},
|
|
89
|
+
"direction_id": _NONEMPTY_STRING,
|
|
90
|
+
"survey_binding": {"type": "object"},
|
|
91
|
+
"upstream_source_paths": {"type": "object"},
|
|
92
|
+
"missing_audit_sources": _STRING_LIST,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
"reasoning_context": deepcopy(REASONING_CONTEXT_SCHEMA),
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
EVIDENCE_BUNDLE_SCHEMA: dict[str, Any] = {
|
|
100
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
101
|
+
"title": "EvidenceBundle v1",
|
|
102
|
+
"type": "object",
|
|
103
|
+
"additionalProperties": False,
|
|
104
|
+
"required": ["schema_version", "brief_id", "evidence_cards", "coverage"],
|
|
105
|
+
"properties": {
|
|
106
|
+
"schema_version": {"const": EVIDENCE_BUNDLE_SCHEMA_VERSION},
|
|
107
|
+
"brief_id": _NONEMPTY_STRING,
|
|
108
|
+
"evidence_cards": {
|
|
109
|
+
"type": "array",
|
|
110
|
+
"items": {
|
|
111
|
+
"type": "object",
|
|
112
|
+
"additionalProperties": False,
|
|
113
|
+
"required": [
|
|
114
|
+
"card_id",
|
|
115
|
+
"claim_slot",
|
|
116
|
+
"statement",
|
|
117
|
+
"design_implication",
|
|
118
|
+
"source_id",
|
|
119
|
+
"source_location",
|
|
120
|
+
"evidence_level",
|
|
121
|
+
"evidence_excerpt",
|
|
122
|
+
"limitations",
|
|
123
|
+
"does_not_establish",
|
|
124
|
+
],
|
|
125
|
+
"properties": {
|
|
126
|
+
"card_id": _NONEMPTY_STRING,
|
|
127
|
+
"claim_slot": _NONEMPTY_STRING,
|
|
128
|
+
"statement": _NONEMPTY_STRING,
|
|
129
|
+
"design_implication": _NONEMPTY_STRING,
|
|
130
|
+
"source_id": _NONEMPTY_STRING,
|
|
131
|
+
"source_location": _NONEMPTY_STRING,
|
|
132
|
+
"evidence_level": {"enum": ["fulltext", "abstract", "metadata", "user_supplied"]},
|
|
133
|
+
"evidence_excerpt": _NONEMPTY_STRING,
|
|
134
|
+
"limitations": _STRING_LIST,
|
|
135
|
+
"does_not_establish": _STRING_LIST,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
"paper_registry": {
|
|
140
|
+
"type": "array",
|
|
141
|
+
"items": {
|
|
142
|
+
"type": "object",
|
|
143
|
+
"additionalProperties": False,
|
|
144
|
+
"required": [
|
|
145
|
+
"canonical_paper_id",
|
|
146
|
+
"title",
|
|
147
|
+
"provider_ids",
|
|
148
|
+
"providers",
|
|
149
|
+
"query_task_ids",
|
|
150
|
+
"content_availability",
|
|
151
|
+
"fulltext_source_location",
|
|
152
|
+
],
|
|
153
|
+
"properties": {
|
|
154
|
+
"canonical_paper_id": _NONEMPTY_STRING,
|
|
155
|
+
"title": _NONEMPTY_STRING,
|
|
156
|
+
"doi": {"type": "string"},
|
|
157
|
+
"authors": _STRING_LIST,
|
|
158
|
+
"year": {"type": "string"},
|
|
159
|
+
"venue": {"type": "string"},
|
|
160
|
+
"url": {"type": "string"},
|
|
161
|
+
"citation_rendering_status": {
|
|
162
|
+
"enum": ["RENDERABLE", "NOT_RENDERABLE_NEEDS_HUMAN_METADATA"]
|
|
163
|
+
},
|
|
164
|
+
"citation_missing_fields": _STRING_LIST,
|
|
165
|
+
"provider_ids": {"type": "object", "minProperties": 1},
|
|
166
|
+
"providers": _STRING_LIST,
|
|
167
|
+
"query_task_ids": _STRING_LIST,
|
|
168
|
+
"content_availability": {"enum": ["fulltext", "abstract", "metadata", "user_supplied", "unavailable"]},
|
|
169
|
+
"fulltext_source_location": {"type": "string"},
|
|
170
|
+
"keynote_status": {"enum": ["TRACEABLE_CARDS_AVAILABLE", "NO_CARDS_EXTRACTED", "NO_ELIGIBLE_TEXT"]},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
"keynotes": {
|
|
175
|
+
"type": "array",
|
|
176
|
+
"items": {
|
|
177
|
+
"type": "object",
|
|
178
|
+
"additionalProperties": False,
|
|
179
|
+
"required": ["canonical_paper_id", "status", "evidence_card_ids", "covered_slots", "source_locations"],
|
|
180
|
+
"properties": {
|
|
181
|
+
"canonical_paper_id": _NONEMPTY_STRING,
|
|
182
|
+
"status": {"enum": ["TRACEABLE_CARDS_AVAILABLE", "NO_CARDS_EXTRACTED", "NO_ELIGIBLE_TEXT"]},
|
|
183
|
+
"evidence_card_ids": _STRING_LIST,
|
|
184
|
+
"covered_slots": _STRING_LIST,
|
|
185
|
+
"source_locations": _STRING_LIST,
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
"field_evidence_ledger": {
|
|
190
|
+
"type": "array",
|
|
191
|
+
"items": {
|
|
192
|
+
"type": "object",
|
|
193
|
+
"additionalProperties": False,
|
|
194
|
+
"required": ["field_path", "status", "card_ids", "source_ids", "required_evidence_levels", "reason"],
|
|
195
|
+
"properties": {
|
|
196
|
+
"field_path": _NONEMPTY_STRING,
|
|
197
|
+
"status": _STATUS_VALUE,
|
|
198
|
+
"card_ids": _STRING_LIST,
|
|
199
|
+
"source_ids": _STRING_LIST,
|
|
200
|
+
"required_evidence_levels": _STRING_LIST,
|
|
201
|
+
"reason": _NONEMPTY_STRING,
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
"retrieval_audit": {"type": "object"},
|
|
206
|
+
"coverage": {
|
|
207
|
+
"type": "object",
|
|
208
|
+
"additionalProperties": False,
|
|
209
|
+
"required": ["required_slots", "covered_slots", "uncovered_slots"],
|
|
210
|
+
"properties": {
|
|
211
|
+
"required_slots": _STRING_LIST,
|
|
212
|
+
"covered_slots": _STRING_LIST,
|
|
213
|
+
"uncovered_slots": _STRING_LIST,
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
OUTCOME_BRANCH_SCHEMA: dict[str, Any] = {
|
|
220
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
221
|
+
"title": "OutcomeBranch v1",
|
|
222
|
+
"type": "object",
|
|
223
|
+
"additionalProperties": False,
|
|
224
|
+
"required": [
|
|
225
|
+
"schema_version",
|
|
226
|
+
"branch_id",
|
|
227
|
+
"trigger",
|
|
228
|
+
"interpretation",
|
|
229
|
+
"conclusion_scope",
|
|
230
|
+
"improvement_actions",
|
|
231
|
+
"evidence_status",
|
|
232
|
+
],
|
|
233
|
+
"properties": {
|
|
234
|
+
"schema_version": {"const": OUTCOME_BRANCH_SCHEMA_VERSION},
|
|
235
|
+
"branch_id": {"enum": ["supports_mechanism", "partial_or_heterogeneous", "null_or_contradictory", "uninformative_or_invalid"]},
|
|
236
|
+
"trigger": _NONEMPTY_STRING,
|
|
237
|
+
"interpretation": _NONEMPTY_STRING,
|
|
238
|
+
"conclusion_scope": _NONEMPTY_STRING,
|
|
239
|
+
"improvement_actions": {"type": "array", "minItems": 1, "items": _NONEMPTY_STRING},
|
|
240
|
+
"evidence_status": {"const": "EXPECTED_NOT_OBSERVED"},
|
|
241
|
+
},
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
EXPERIMENT_DESIGN_SCHEMA: dict[str, Any] = {
|
|
245
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
246
|
+
"title": "ExperimentDesign v1",
|
|
247
|
+
"type": "object",
|
|
248
|
+
"additionalProperties": False,
|
|
249
|
+
"required": [
|
|
250
|
+
"schema_version",
|
|
251
|
+
"design_id",
|
|
252
|
+
"evidence_status",
|
|
253
|
+
"execution_policy",
|
|
254
|
+
"research_brief",
|
|
255
|
+
"evidence_bundle",
|
|
256
|
+
"research_design",
|
|
257
|
+
"hypothesis_mapping",
|
|
258
|
+
"variables_and_operationalization",
|
|
259
|
+
"sampling_and_eligibility",
|
|
260
|
+
"measurement_and_calibration",
|
|
261
|
+
"comparison_and_robustness",
|
|
262
|
+
"analysis_plan",
|
|
263
|
+
"data_governance_and_reproducibility",
|
|
264
|
+
"field_statuses",
|
|
265
|
+
"outcome_branches",
|
|
266
|
+
"risk_and_human_review",
|
|
267
|
+
"open_design_questions",
|
|
268
|
+
"observed_results",
|
|
269
|
+
"validation_report",
|
|
270
|
+
],
|
|
271
|
+
"properties": {
|
|
272
|
+
"schema_version": {"const": EXPERIMENT_DESIGN_SCHEMA_VERSION},
|
|
273
|
+
"design_id": _NONEMPTY_STRING,
|
|
274
|
+
"evidence_status": {"const": "DESIGNED_NOT_EXECUTED"},
|
|
275
|
+
"execution_policy": {
|
|
276
|
+
"type": "object",
|
|
277
|
+
"additionalProperties": False,
|
|
278
|
+
"required": ["mode", "allow_digital_execution", "reason"],
|
|
279
|
+
"properties": {
|
|
280
|
+
"mode": {"enum": [DESIGN_ONLY, DIGITAL_EXECUTION_ELIGIBLE]},
|
|
281
|
+
"allow_digital_execution": {"type": "boolean"},
|
|
282
|
+
"reason": _NONEMPTY_STRING,
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
"research_brief": deepcopy(RESEARCH_BRIEF_SCHEMA),
|
|
286
|
+
"evidence_bundle": deepcopy(EVIDENCE_BUNDLE_SCHEMA),
|
|
287
|
+
"variable_claim_model": {"type": "object"},
|
|
288
|
+
"formal_reasoning_plan": {"type": "object"},
|
|
289
|
+
"counterexample_analysis": {"type": "object"},
|
|
290
|
+
"reasoning_validation_report": {"type": "object"},
|
|
291
|
+
"research_design": {
|
|
292
|
+
"type": "object",
|
|
293
|
+
"additionalProperties": False,
|
|
294
|
+
"required": ["design_type", "experimental_unit", "time_structure"],
|
|
295
|
+
"properties": {
|
|
296
|
+
"design_type": _NONEMPTY_STRING,
|
|
297
|
+
"experimental_unit": _NONEMPTY_STRING,
|
|
298
|
+
"time_structure": _NONEMPTY_STRING,
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
"hypothesis_mapping": {
|
|
302
|
+
"type": "array",
|
|
303
|
+
"minItems": 1,
|
|
304
|
+
"items": {
|
|
305
|
+
"type": "object",
|
|
306
|
+
"additionalProperties": False,
|
|
307
|
+
"required": ["hypothesis_id", "claim", "observables", "decision_rule"],
|
|
308
|
+
"properties": {
|
|
309
|
+
"hypothesis_id": _NONEMPTY_STRING,
|
|
310
|
+
"claim": _NONEMPTY_STRING,
|
|
311
|
+
"observables": _STRING_LIST,
|
|
312
|
+
"decision_rule": _NONEMPTY_STRING,
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
"variables_and_operationalization": {
|
|
317
|
+
"type": "object",
|
|
318
|
+
"additionalProperties": False,
|
|
319
|
+
"required": ["independent_variables", "dependent_variables", "control_variables", "confounders", "operational_definitions"],
|
|
320
|
+
"properties": {
|
|
321
|
+
"independent_variables": {"type": "array"},
|
|
322
|
+
"dependent_variables": {"type": "array"},
|
|
323
|
+
"control_variables": {"type": "array"},
|
|
324
|
+
"confounders": {"type": "array"},
|
|
325
|
+
"operational_definitions": {"type": "array"},
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
"sampling_and_eligibility": {
|
|
329
|
+
"type": "object",
|
|
330
|
+
"additionalProperties": False,
|
|
331
|
+
"required": ["source", "eligibility_criteria", "sample_size_or_power_basis"],
|
|
332
|
+
"properties": {
|
|
333
|
+
"source": {"type": "object"},
|
|
334
|
+
"eligibility_criteria": {"type": "object"},
|
|
335
|
+
"sample_size_or_power_basis": {"type": "object"},
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
"measurement_and_calibration": {
|
|
339
|
+
"type": "object",
|
|
340
|
+
"additionalProperties": False,
|
|
341
|
+
"required": ["instruments", "measurement_plan", "calibration", "quality_control"],
|
|
342
|
+
"properties": {
|
|
343
|
+
"instruments": {"type": "array"},
|
|
344
|
+
"measurement_plan": {"type": "object"},
|
|
345
|
+
"calibration": {"type": "object"},
|
|
346
|
+
"quality_control": {"type": "object"},
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
"comparison_and_robustness": {
|
|
350
|
+
"type": "object",
|
|
351
|
+
"additionalProperties": False,
|
|
352
|
+
"required": ["groups", "controls", "baselines", "comparisons", "ablation_sensitivity_robustness"],
|
|
353
|
+
"properties": {
|
|
354
|
+
"groups": {"type": "array"},
|
|
355
|
+
"controls": {"type": "array"},
|
|
356
|
+
"baselines": {"type": "array"},
|
|
357
|
+
"comparisons": {"type": "array"},
|
|
358
|
+
"ablation_sensitivity_robustness": {"type": "array"},
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
"analysis_plan": {
|
|
362
|
+
"type": "object",
|
|
363
|
+
"additionalProperties": False,
|
|
364
|
+
"required": ["randomization", "blinding", "repetitions", "batch_effects", "missing_data", "statistical_analysis"],
|
|
365
|
+
"properties": {
|
|
366
|
+
"randomization": {"type": "object"},
|
|
367
|
+
"blinding": {"type": "object"},
|
|
368
|
+
"repetitions": {"type": "object"},
|
|
369
|
+
"batch_effects": {"type": "object"},
|
|
370
|
+
"missing_data": {"type": "object"},
|
|
371
|
+
"statistical_analysis": {"type": "object"},
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
"data_governance_and_reproducibility": {
|
|
375
|
+
"type": "object",
|
|
376
|
+
"additionalProperties": False,
|
|
377
|
+
"required": ["data_management", "reproducibility"],
|
|
378
|
+
"properties": {
|
|
379
|
+
"data_management": {"type": "object"},
|
|
380
|
+
"reproducibility": {"type": "object"},
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
"outcome_branches": {"type": "array", "minItems": 4, "items": deepcopy(OUTCOME_BRANCH_SCHEMA)},
|
|
384
|
+
"risk_and_human_review": {
|
|
385
|
+
"type": "object",
|
|
386
|
+
"additionalProperties": False,
|
|
387
|
+
"required": ["risk_level", "human_review_required", "review_triggers", "execution_prohibited"],
|
|
388
|
+
"properties": {
|
|
389
|
+
"risk_level": {"enum": ["low", "medium", "high", "critical"]},
|
|
390
|
+
"human_review_required": {"type": "boolean"},
|
|
391
|
+
"review_triggers": _STRING_LIST,
|
|
392
|
+
"approval_dependencies": _STRING_LIST,
|
|
393
|
+
"restricted_content": _STRING_LIST,
|
|
394
|
+
"execution_prohibited": {"type": "boolean"},
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
"template_composition": {
|
|
398
|
+
"type": "object",
|
|
399
|
+
"additionalProperties": False,
|
|
400
|
+
"required": ["template_id", "secondary_template", "submode", "prompt_variant", "llm_used"],
|
|
401
|
+
"properties": {
|
|
402
|
+
"template_id": _NONEMPTY_STRING,
|
|
403
|
+
"secondary_template": {"type": "string"},
|
|
404
|
+
"submode": {"type": "string"},
|
|
405
|
+
"prompt_variant": _NONEMPTY_STRING,
|
|
406
|
+
"llm_used": {"type": "boolean"},
|
|
407
|
+
},
|
|
408
|
+
},
|
|
409
|
+
"template_details": {"type": "object"},
|
|
410
|
+
"field_statuses": {
|
|
411
|
+
"type": "object",
|
|
412
|
+
"additionalProperties": _NONEMPTY_STRING,
|
|
413
|
+
},
|
|
414
|
+
"open_design_questions": {"type": "array"},
|
|
415
|
+
"observed_results": {"type": "array", "maxItems": 0},
|
|
416
|
+
"validation_report": {
|
|
417
|
+
"type": "object",
|
|
418
|
+
"additionalProperties": False,
|
|
419
|
+
"required": ["status", "errors", "warnings"],
|
|
420
|
+
"properties": {
|
|
421
|
+
"status": {"enum": ["READY_FOR_HUMAN_REVIEW", "DRAFT_REQUIRES_INPUT", "BLOCKED_BY_SCOPE", "BLOCKED_BY_RISK_REVIEW"]},
|
|
422
|
+
"errors": _STRING_LIST,
|
|
423
|
+
"warnings": _STRING_LIST,
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
def _schema_errors(payload: Any, schema: Mapping[str, Any], *, prefix: str = "$") -> list[str]:
|
|
431
|
+
errors: list[str] = []
|
|
432
|
+
for error in sorted(Draft202012Validator(schema).iter_errors(payload), key=lambda item: list(item.absolute_path)):
|
|
433
|
+
path = "/".join(str(part) for part in error.absolute_path)
|
|
434
|
+
errors.append(f"{prefix}/{path}: {error.message}" if path else f"{prefix}: {error.message}")
|
|
435
|
+
return errors
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
def _scope_errors(discipline_ids: object) -> list[str]:
|
|
439
|
+
scope = resolve_design_scope(discipline_ids)
|
|
440
|
+
if scope["status"] == "IN_SCOPE":
|
|
441
|
+
return []
|
|
442
|
+
errors: list[str] = []
|
|
443
|
+
errors.extend(f"excluded_discipline:{identifier}" for identifier in scope["excluded_discipline_ids"])
|
|
444
|
+
errors.extend(f"unresolved_discipline:{identifier}" for identifier in scope["unresolved_disciplines"])
|
|
445
|
+
if not errors:
|
|
446
|
+
errors.append("discipline_scope_requires_clarification")
|
|
447
|
+
return errors
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def validate_research_brief(payload: Any) -> list[str]:
|
|
451
|
+
errors = _schema_errors(payload, RESEARCH_BRIEF_SCHEMA)
|
|
452
|
+
if isinstance(payload, Mapping):
|
|
453
|
+
errors.extend(_scope_errors(payload.get("discipline_ids")))
|
|
454
|
+
return errors
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def validate_evidence_bundle(payload: Any) -> list[str]:
|
|
458
|
+
errors = _schema_errors(payload, EVIDENCE_BUNDLE_SCHEMA)
|
|
459
|
+
if not isinstance(payload, Mapping):
|
|
460
|
+
return errors
|
|
461
|
+
registry = payload.get("paper_registry")
|
|
462
|
+
paper_ids = {
|
|
463
|
+
str(record.get("canonical_paper_id") or "").strip()
|
|
464
|
+
for record in registry
|
|
465
|
+
if isinstance(record, Mapping)
|
|
466
|
+
} if isinstance(registry, list) else set()
|
|
467
|
+
if isinstance(registry, list) and len(paper_ids) != len(registry):
|
|
468
|
+
errors.append("paper_registry_contains_missing_or_duplicate_canonical_paper_id")
|
|
469
|
+
if isinstance(registry, list):
|
|
470
|
+
for record in registry:
|
|
471
|
+
if not isinstance(record, Mapping):
|
|
472
|
+
continue
|
|
473
|
+
rendering_status = str(record.get("citation_rendering_status") or "").strip()
|
|
474
|
+
if not rendering_status:
|
|
475
|
+
continue
|
|
476
|
+
missing_fields = {
|
|
477
|
+
str(field).strip()
|
|
478
|
+
for field in record.get("citation_missing_fields") or []
|
|
479
|
+
if str(field).strip()
|
|
480
|
+
}
|
|
481
|
+
expected_missing_fields = {
|
|
482
|
+
field
|
|
483
|
+
for field, value in (
|
|
484
|
+
("authors", record.get("authors")),
|
|
485
|
+
("year", record.get("year")),
|
|
486
|
+
("venue", record.get("venue")),
|
|
487
|
+
)
|
|
488
|
+
if not value
|
|
489
|
+
}
|
|
490
|
+
if rendering_status == "RENDERABLE" and missing_fields:
|
|
491
|
+
errors.append("renderable_citation_lists_missing_metadata")
|
|
492
|
+
elif rendering_status == "RENDERABLE" and expected_missing_fields:
|
|
493
|
+
errors.append("renderable_citation_is_missing_required_metadata")
|
|
494
|
+
elif rendering_status == "NOT_RENDERABLE_NEEDS_HUMAN_METADATA":
|
|
495
|
+
if not missing_fields:
|
|
496
|
+
errors.append("non_renderable_citation_omits_missing_metadata")
|
|
497
|
+
elif missing_fields != expected_missing_fields:
|
|
498
|
+
errors.append("non_renderable_citation_missing_metadata_mismatch")
|
|
499
|
+
cards = payload.get("evidence_cards")
|
|
500
|
+
card_ids: set[str] = set()
|
|
501
|
+
card_by_id: dict[str, Mapping[str, Any]] = {}
|
|
502
|
+
if isinstance(cards, list):
|
|
503
|
+
if cards and not isinstance(registry, list):
|
|
504
|
+
errors.append("evidence_cards_require_paper_registry")
|
|
505
|
+
for card in cards:
|
|
506
|
+
if not isinstance(card, Mapping):
|
|
507
|
+
continue
|
|
508
|
+
card_id = str(card.get("card_id") or "").strip()
|
|
509
|
+
source_id = str(card.get("source_id") or "").strip()
|
|
510
|
+
if card_id in card_ids:
|
|
511
|
+
errors.append(f"duplicate_evidence_card_id:{card_id}")
|
|
512
|
+
if card_id:
|
|
513
|
+
card_ids.add(card_id)
|
|
514
|
+
card_by_id[card_id] = card
|
|
515
|
+
if isinstance(registry, list) and source_id not in paper_ids:
|
|
516
|
+
errors.append(f"evidence_card_unknown_source_id:{source_id}")
|
|
517
|
+
ledger = payload.get("field_evidence_ledger")
|
|
518
|
+
if isinstance(ledger, list):
|
|
519
|
+
seen_fields: set[str] = set()
|
|
520
|
+
for record in ledger:
|
|
521
|
+
if not isinstance(record, Mapping):
|
|
522
|
+
continue
|
|
523
|
+
field_path = str(record.get("field_path") or "").strip()
|
|
524
|
+
if field_path in seen_fields:
|
|
525
|
+
errors.append(f"duplicate_field_evidence_ledger_path:{field_path}")
|
|
526
|
+
if field_path:
|
|
527
|
+
seen_fields.add(field_path)
|
|
528
|
+
referenced_cards = [
|
|
529
|
+
str(card_id).strip()
|
|
530
|
+
for card_id in record.get("card_ids") or []
|
|
531
|
+
if str(card_id).strip()
|
|
532
|
+
]
|
|
533
|
+
for card_id in referenced_cards:
|
|
534
|
+
if card_id not in card_ids:
|
|
535
|
+
errors.append(f"field_evidence_ledger_unknown_card_id:{field_path}:{card_id}")
|
|
536
|
+
if record.get("status") == "evidence_backed":
|
|
537
|
+
required_levels = set(record.get("required_evidence_levels") or [])
|
|
538
|
+
qualifying = [
|
|
539
|
+
card_by_id[card_id]
|
|
540
|
+
for card_id in referenced_cards
|
|
541
|
+
if card_id in card_by_id
|
|
542
|
+
and card_by_id[card_id].get("evidence_level") in required_levels
|
|
543
|
+
]
|
|
544
|
+
if not qualifying:
|
|
545
|
+
errors.append(f"evidence_backed_field_without_qualifying_card:{field_path}")
|
|
546
|
+
return errors
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def validate_outcome_branch(payload: Any) -> list[str]:
|
|
550
|
+
return _schema_errors(payload, OUTCOME_BRANCH_SCHEMA)
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
def validate_experiment_design(payload: Any) -> list[str]:
|
|
554
|
+
errors = _schema_errors(payload, EXPERIMENT_DESIGN_SCHEMA)
|
|
555
|
+
if not isinstance(payload, Mapping):
|
|
556
|
+
return errors
|
|
557
|
+
research_brief = payload.get("research_brief")
|
|
558
|
+
evidence_bundle = payload.get("evidence_bundle")
|
|
559
|
+
if isinstance(research_brief, Mapping):
|
|
560
|
+
errors.extend(f"research_brief:{error}" for error in validate_research_brief(research_brief))
|
|
561
|
+
if isinstance(evidence_bundle, Mapping):
|
|
562
|
+
errors.extend(f"evidence_bundle:{error}" for error in validate_evidence_bundle(evidence_bundle))
|
|
563
|
+
if isinstance(research_brief, Mapping) and isinstance(evidence_bundle, Mapping):
|
|
564
|
+
if evidence_bundle.get("brief_id") != research_brief.get("brief_id"):
|
|
565
|
+
errors.append("evidence_bundle_brief_id_mismatch")
|
|
566
|
+
reasoning_context = _mapping(research_brief.get("reasoning_context")) if isinstance(research_brief, Mapping) else {}
|
|
567
|
+
if reasoning_context:
|
|
568
|
+
errors.extend(
|
|
569
|
+
f"research_brief.reasoning_context:{error}"
|
|
570
|
+
for error in _schema_errors(reasoning_context, REASONING_CONTEXT_SCHEMA)
|
|
571
|
+
)
|
|
572
|
+
from .reasoning_validation import validate_reasoning_artifacts
|
|
573
|
+
|
|
574
|
+
errors.extend(
|
|
575
|
+
validate_reasoning_artifacts(
|
|
576
|
+
variable_claim_model=payload.get("variable_claim_model") if isinstance(payload.get("variable_claim_model"), Mapping) else None,
|
|
577
|
+
formal_reasoning_plan=payload.get("formal_reasoning_plan") if isinstance(payload.get("formal_reasoning_plan"), Mapping) else None,
|
|
578
|
+
counterexample_analysis=payload.get("counterexample_analysis") if isinstance(payload.get("counterexample_analysis"), Mapping) else None,
|
|
579
|
+
design=payload,
|
|
580
|
+
template_composition=payload.get("template_composition") if isinstance(payload.get("template_composition"), Mapping) else None,
|
|
581
|
+
)
|
|
582
|
+
)
|
|
583
|
+
field_statuses = payload.get("field_statuses")
|
|
584
|
+
status_sections = {
|
|
585
|
+
"research_design",
|
|
586
|
+
"hypothesis_mapping",
|
|
587
|
+
"variables_and_operationalization",
|
|
588
|
+
"sampling_and_eligibility",
|
|
589
|
+
"measurement_and_calibration",
|
|
590
|
+
"comparison_and_robustness",
|
|
591
|
+
"analysis_plan",
|
|
592
|
+
"data_governance_and_reproducibility",
|
|
593
|
+
"template_details",
|
|
594
|
+
}
|
|
595
|
+
def nested_status_paths(value: object, path: str) -> list[str]:
|
|
596
|
+
found: list[str] = []
|
|
597
|
+
if isinstance(value, Mapping):
|
|
598
|
+
for key, child in value.items():
|
|
599
|
+
child_path = f"{path}.{key}" if path else str(key)
|
|
600
|
+
if key == "status":
|
|
601
|
+
found.append(child_path)
|
|
602
|
+
else:
|
|
603
|
+
found.extend(nested_status_paths(child, child_path))
|
|
604
|
+
elif isinstance(value, list):
|
|
605
|
+
for index, child in enumerate(value):
|
|
606
|
+
found.extend(nested_status_paths(child, f"{path}[{index}]"))
|
|
607
|
+
return found
|
|
608
|
+
for section in status_sections:
|
|
609
|
+
for path in nested_status_paths(payload.get(section), section):
|
|
610
|
+
errors.append(f"{path}:status_must_use_top_level_field_statuses")
|
|
611
|
+
if isinstance(field_statuses, Mapping) and isinstance(evidence_bundle, Mapping):
|
|
612
|
+
qualifying_fields = {
|
|
613
|
+
str(record.get("field_path") or "").strip()
|
|
614
|
+
for record in evidence_bundle.get("field_evidence_ledger") or []
|
|
615
|
+
if isinstance(record, Mapping) and record.get("status") == "evidence_backed"
|
|
616
|
+
}
|
|
617
|
+
for field_path, status in field_statuses.items():
|
|
618
|
+
if status == "evidence_backed" and str(field_path) not in qualifying_fields:
|
|
619
|
+
errors.append(f"field_status_evidence_not_qualified:{field_path}")
|
|
620
|
+
branches = payload.get("outcome_branches")
|
|
621
|
+
if isinstance(branches, list):
|
|
622
|
+
errors.extend(
|
|
623
|
+
f"outcome_branches[{index}]:{error}"
|
|
624
|
+
for index, branch in enumerate(branches)
|
|
625
|
+
for error in validate_outcome_branch(branch)
|
|
626
|
+
)
|
|
627
|
+
expected_ids = {
|
|
628
|
+
"supports_mechanism",
|
|
629
|
+
"partial_or_heterogeneous",
|
|
630
|
+
"null_or_contradictory",
|
|
631
|
+
"uninformative_or_invalid",
|
|
632
|
+
}
|
|
633
|
+
actual_ids = [branch.get("branch_id") for branch in branches if isinstance(branch, Mapping)]
|
|
634
|
+
if set(actual_ids) != expected_ids or len(actual_ids) != len(expected_ids):
|
|
635
|
+
errors.append("outcome_branches_must_cover_each_required_branch_once")
|
|
636
|
+
policy = payload.get("execution_policy")
|
|
637
|
+
if isinstance(research_brief, Mapping) and isinstance(policy, Mapping):
|
|
638
|
+
expected = resolve_execution_policy(
|
|
639
|
+
research_brief.get("discipline_ids"),
|
|
640
|
+
allow_digital_execution=bool(policy.get("allow_digital_execution")),
|
|
641
|
+
)
|
|
642
|
+
if policy.get("mode") != expected["mode"]:
|
|
643
|
+
errors.append("execution_policy_mode_does_not_match_discipline_scope")
|
|
644
|
+
return errors
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
def assert_valid(payload: Any, validator) -> dict[str, Any]:
|
|
648
|
+
errors = validator(payload)
|
|
649
|
+
if errors:
|
|
650
|
+
raise ValueError("; ".join(errors))
|
|
651
|
+
return dict(payload)
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
def _text(value: Any) -> str:
|
|
655
|
+
return str(value or "").strip()
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
def _mapping(value: object) -> dict[str, Any]:
|
|
659
|
+
return dict(value) if isinstance(value, Mapping) else {}
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
def _texts(value: Any) -> list[str]:
|
|
663
|
+
values = value if isinstance(value, (list, tuple, set)) else [value]
|
|
664
|
+
result: list[str] = []
|
|
665
|
+
for item in values:
|
|
666
|
+
text = _text(item)
|
|
667
|
+
if text and text not in result:
|
|
668
|
+
result.append(text)
|
|
669
|
+
return result
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
def _idea_source_layers(
|
|
673
|
+
direction: Mapping[str, Any],
|
|
674
|
+
idea_result: Mapping[str, Any],
|
|
675
|
+
audit_sources: Mapping[str, Any] | None,
|
|
676
|
+
) -> list[tuple[str, Mapping[str, Any]]]:
|
|
677
|
+
"""Expose source precedence without ever combining multiple directions."""
|
|
678
|
+
|
|
679
|
+
layers: list[tuple[str, Mapping[str, Any]]] = []
|
|
680
|
+
|
|
681
|
+
def add_nested(prefix: str, value: object) -> None:
|
|
682
|
+
record = value if isinstance(value, Mapping) else {}
|
|
683
|
+
for nested_key in ("hypothesis", "experiment_handoff"):
|
|
684
|
+
nested = record.get(nested_key)
|
|
685
|
+
if isinstance(nested, Mapping):
|
|
686
|
+
layers.append((f"{prefix}.{nested_key}", nested))
|
|
687
|
+
layers.append((prefix, record))
|
|
688
|
+
|
|
689
|
+
add_nested("selected_direction", direction)
|
|
690
|
+
add_nested("legacy_best_entry", idea_result.get("legacy_best_entry"))
|
|
691
|
+
audit = audit_sources if isinstance(audit_sources, Mapping) else {}
|
|
692
|
+
add_nested("selected_primary_idea", audit.get("selected_primary_idea"))
|
|
693
|
+
add_nested("idea_candidate", audit.get("idea_candidate"))
|
|
694
|
+
return layers
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
def _first_idea_value(
|
|
698
|
+
layers: list[tuple[str, Mapping[str, Any]]],
|
|
699
|
+
keys: tuple[str, ...],
|
|
700
|
+
) -> Any:
|
|
701
|
+
for _, layer in layers:
|
|
702
|
+
for key in keys:
|
|
703
|
+
value = layer.get(key)
|
|
704
|
+
if value not in (None, "", [], {}):
|
|
705
|
+
return deepcopy(value)
|
|
706
|
+
return ""
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
def build_research_brief_from_idea_result(
|
|
710
|
+
idea_result: Mapping[str, Any],
|
|
711
|
+
*,
|
|
712
|
+
discipline_ids: object,
|
|
713
|
+
brief_id: str,
|
|
714
|
+
selected_direction: str = "",
|
|
715
|
+
audit_sources: Mapping[str, Any] | None = None,
|
|
716
|
+
) -> dict[str, Any]:
|
|
717
|
+
"""Create a v1 ResearchBrief from one explicitly selected Idea Agent direction."""
|
|
718
|
+
|
|
719
|
+
if idea_result.get("schema_version") != "idea_result_v5":
|
|
720
|
+
raise ValueError("ResearchBrief v1 requires an idea_result_v5 input.")
|
|
721
|
+
directions = [item for item in idea_result.get("directions") or [] if isinstance(item, Mapping)]
|
|
722
|
+
requested = _text(selected_direction) or _text(idea_result.get("primary_direction"))
|
|
723
|
+
matching = [
|
|
724
|
+
direction
|
|
725
|
+
for direction in directions
|
|
726
|
+
if _text(direction.get("direction_mode")) == requested
|
|
727
|
+
or _text(direction.get("id")) == requested
|
|
728
|
+
or _text(direction.get("title")) == requested
|
|
729
|
+
]
|
|
730
|
+
if len(matching) != 1:
|
|
731
|
+
raise ValueError("ResearchBrief v1 requires one unambiguous selected Idea Agent direction.")
|
|
732
|
+
direction = matching[0]
|
|
733
|
+
hypothesis = direction.get("hypothesis") if isinstance(direction.get("hypothesis"), Mapping) else {}
|
|
734
|
+
handoff = direction.get("experiment_handoff") if isinstance(direction.get("experiment_handoff"), Mapping) else {}
|
|
735
|
+
direction_id = _text(direction.get("direction_mode")) or _text(direction.get("id")) or _text(direction.get("title"))
|
|
736
|
+
idea_layers = _idea_source_layers(direction, idea_result, audit_sources)
|
|
737
|
+
research_object = _first_idea_value(idea_layers, ("scientific_object", "research_object")) or {}
|
|
738
|
+
if not isinstance(research_object, Mapping):
|
|
739
|
+
research_object = {"description": _text(research_object)} if _text(research_object) else {}
|
|
740
|
+
title = _text(direction.get("title")) or _text(_first_idea_value(idea_layers, ("title",))) or _text(idea_result.get("title"))
|
|
741
|
+
payload = {
|
|
742
|
+
"schema_version": RESEARCH_BRIEF_SCHEMA_VERSION,
|
|
743
|
+
"brief_id": _text(brief_id),
|
|
744
|
+
"topic": _text(idea_result.get("topic")) or _text(idea_result.get("title")) or title,
|
|
745
|
+
"discipline_ids": list(normalize_discipline_ids(discipline_ids)),
|
|
746
|
+
"selected_direction": {
|
|
747
|
+
"id": direction_id,
|
|
748
|
+
"title": title,
|
|
749
|
+
"central_hypothesis": _text(_first_idea_value(idea_layers, ("central_hypothesis", "claim_to_test"))),
|
|
750
|
+
"mechanism_or_relation": _text(_first_idea_value(idea_layers, ("mechanism_or_relation", "mechanism_to_discriminate"))),
|
|
751
|
+
},
|
|
752
|
+
"research_object": dict(research_object),
|
|
753
|
+
"intervention_or_transformation": _text(_first_idea_value(idea_layers, ("intervention_or_transformation",))),
|
|
754
|
+
"discriminating_observations": _texts(_first_idea_value(idea_layers, ("required_observations", "discriminating_observations", "discriminating_observation"))),
|
|
755
|
+
"boundary_conditions": _texts(_first_idea_value(idea_layers, ("boundary_conditions", "boundary_or_failure_condition"))),
|
|
756
|
+
"alternative_explanations": _texts(_first_idea_value(idea_layers, ("alternative_explanations",))),
|
|
757
|
+
"known_unknowns": _texts(_first_idea_value(idea_layers, ("known_unknowns",))),
|
|
758
|
+
"evidence_status": "PROPOSED",
|
|
759
|
+
"source": {
|
|
760
|
+
"idea_result_schema": "idea_result_v5",
|
|
761
|
+
"direction_id": direction_id,
|
|
762
|
+
"survey_binding": dict(idea_result.get("survey_binding") or {}),
|
|
763
|
+
},
|
|
764
|
+
"reasoning_context": build_reasoning_context_from_idea_result(
|
|
765
|
+
idea_result,
|
|
766
|
+
selected_direction=selected_direction,
|
|
767
|
+
audit_sources=audit_sources,
|
|
768
|
+
),
|
|
769
|
+
}
|
|
770
|
+
assert_valid(payload, validate_research_brief)
|
|
771
|
+
return payload
|