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,703 @@
|
|
|
1
|
+
"""Compile frozen theory artifacts into a deterministic audit registry.
|
|
2
|
+
|
|
3
|
+
The compiler deliberately creates only document-local labels. It never adds
|
|
4
|
+
scientific content, bibliography records, or upstream identifiers; every
|
|
5
|
+
compiled unit retains reverse references to the frozen Author handoff.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Mapping, Sequence
|
|
11
|
+
from copy import deepcopy
|
|
12
|
+
import json
|
|
13
|
+
import re
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from jsonschema import Draft202012Validator
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
THEORY_SPINE_SCHEMA_VERSION = "research_plan_theory_spine_v1"
|
|
20
|
+
|
|
21
|
+
_NONEMPTY = {"type": "string", "minLength": 1}
|
|
22
|
+
_STRING_LIST = {"type": "array", "items": _NONEMPTY, "uniqueItems": True}
|
|
23
|
+
_LOCAL_LEMMA_ID = re.compile(r"^TS-L-[1-9][0-9]*$")
|
|
24
|
+
_LOCAL_PROOF_OBLIGATION_ID = re.compile(r"^TS-PO-[1-9][0-9]*$")
|
|
25
|
+
_LOCAL_FALSIFIER_ID = re.compile(r"^TS-F-[1-9][0-9]*$")
|
|
26
|
+
_LOCAL_BRANCH_ID = re.compile(r"^TS-BR-[A-Z0-9][A-Z0-9_-]*$")
|
|
27
|
+
_VISIBLE_LOCAL_ID = re.compile(r"(?<![A-Za-z0-9_-])TS-(?:L|PO|F|BR)-[A-Za-z0-9_-]+(?![A-Za-z0-9_-])")
|
|
28
|
+
_UNRESOLVED_STATUSES = {
|
|
29
|
+
"missing",
|
|
30
|
+
"needs_human_input",
|
|
31
|
+
"requires_human_review",
|
|
32
|
+
"review_required",
|
|
33
|
+
"unresolved",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
THEORY_SPINE_SCHEMA: dict[str, Any] = {
|
|
38
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
39
|
+
"title": "Research Plan Theory Spine v1",
|
|
40
|
+
"type": "object",
|
|
41
|
+
"additionalProperties": False,
|
|
42
|
+
"required": [
|
|
43
|
+
"schema_version",
|
|
44
|
+
"template_family",
|
|
45
|
+
"enabled",
|
|
46
|
+
"compiler_status",
|
|
47
|
+
"lemma_units",
|
|
48
|
+
"proof_obligations",
|
|
49
|
+
"falsifiers",
|
|
50
|
+
"decision_branches",
|
|
51
|
+
],
|
|
52
|
+
"properties": {
|
|
53
|
+
"schema_version": {"const": THEORY_SPINE_SCHEMA_VERSION},
|
|
54
|
+
"template_family": _NONEMPTY,
|
|
55
|
+
"enabled": {"type": "boolean"},
|
|
56
|
+
"compiler_status": {"enum": ["ready", "no_auditable_lemma_input", "not_applicable"]},
|
|
57
|
+
"lemma_units": {"type": "array", "items": {"type": "object"}},
|
|
58
|
+
"proof_obligations": {"type": "array", "items": {"type": "object"}},
|
|
59
|
+
"falsifiers": {"type": "array", "items": {"type": "object"}},
|
|
60
|
+
"decision_branches": {"type": "array", "items": {"type": "object"}},
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class TheorySpineError(ValueError):
|
|
66
|
+
"""Raised when a deterministic theory registry cannot be source-bounded."""
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _mapping(value: object) -> dict[str, Any]:
|
|
70
|
+
return dict(value) if isinstance(value, Mapping) else {}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _text(value: object) -> str:
|
|
74
|
+
return str(value or "").strip()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _canonical_json(value: object) -> str:
|
|
78
|
+
return json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"), allow_nan=False)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _text_list(value: object) -> list[str]:
|
|
82
|
+
if isinstance(value, str):
|
|
83
|
+
return [_text(value)] if _text(value) else []
|
|
84
|
+
if not isinstance(value, Sequence) or isinstance(value, (bytes, bytearray)):
|
|
85
|
+
return []
|
|
86
|
+
return sorted({_text(item) for item in value if _text(item)})
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _record_references(record: Mapping[str, Any], *field_names: str) -> set[str]:
|
|
90
|
+
references: set[str] = set()
|
|
91
|
+
for field_name in field_names:
|
|
92
|
+
references.update(_text_list(record.get(field_name)))
|
|
93
|
+
return references
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _reference_tokens(record: Mapping[str, Any]) -> set[str]:
|
|
97
|
+
return {
|
|
98
|
+
*(_record_references(record, "symbol_references", "symbols")),
|
|
99
|
+
*(_record_references(record, "variable_references", "variables")),
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _stable_records(records: object, *, identifier_field: str) -> list[dict[str, Any]]:
|
|
104
|
+
if not isinstance(records, list):
|
|
105
|
+
return []
|
|
106
|
+
values = [dict(record) for record in records if isinstance(record, Mapping) and _text(record.get(identifier_field))]
|
|
107
|
+
return sorted(values, key=lambda record: (_text(record.get(identifier_field)), _canonical_json(record)))
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _formal_records(author_context: Mapping[str, Any]) -> tuple[dict[str, dict[str, Any]], dict[str, str]]:
|
|
111
|
+
formal_reasoning = _mapping(author_context.get("formal_reasoning"))
|
|
112
|
+
records: dict[str, dict[str, Any]] = {}
|
|
113
|
+
kinds: dict[str, str] = {}
|
|
114
|
+
collections = (
|
|
115
|
+
("definitions", "definition_id", "definition"),
|
|
116
|
+
("assumptions", "assumption_id", "assumption"),
|
|
117
|
+
("propositions", "proposition_id", "proposition"),
|
|
118
|
+
("proof_obligations", "obligation_id", "proof_obligation"),
|
|
119
|
+
)
|
|
120
|
+
for collection, identifier_field, kind in collections:
|
|
121
|
+
for record in _stable_records(formal_reasoning.get(collection), identifier_field=identifier_field):
|
|
122
|
+
identifier = _text(record.get(identifier_field))
|
|
123
|
+
records.setdefault(identifier, record)
|
|
124
|
+
kinds.setdefault(identifier, kind)
|
|
125
|
+
derivation = _mapping(formal_reasoning.get("forward_derivation"))
|
|
126
|
+
for record in _stable_records(derivation.get("steps"), identifier_field="step_id"):
|
|
127
|
+
identifier = _text(record.get("step_id"))
|
|
128
|
+
records.setdefault(identifier, record)
|
|
129
|
+
kinds.setdefault(identifier, "forward_derivation_step")
|
|
130
|
+
return records, kinds
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _unknown_records(
|
|
134
|
+
preparation: Mapping[str, Any],
|
|
135
|
+
source_registry: Mapping[str, Any] | None,
|
|
136
|
+
) -> list[dict[str, Any]]:
|
|
137
|
+
"""Return source-registry unknown IDs plus their frozen records.
|
|
138
|
+
|
|
139
|
+
``source_registry`` is available in Author preparation. Direct library
|
|
140
|
+
callers receive the same canonical ``unknown-N`` IDs by constructing the
|
|
141
|
+
frozen registry from the supplied preparation rather than minting a local
|
|
142
|
+
unknown-item identifier.
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
resolved_registry = source_registry
|
|
146
|
+
if not isinstance(resolved_registry, Mapping):
|
|
147
|
+
from .source_registry import build_frozen_source_registry
|
|
148
|
+
|
|
149
|
+
resolved_registry = build_frozen_source_registry(preparation)
|
|
150
|
+
records = [
|
|
151
|
+
{
|
|
152
|
+
"source_item_id": _text(record.get("source_item_id")),
|
|
153
|
+
"original_item": deepcopy(_mapping(record.get("original_item"))),
|
|
154
|
+
}
|
|
155
|
+
for record in resolved_registry.get("unknown_items") or []
|
|
156
|
+
if isinstance(record, Mapping) and _text(record.get("source_item_id"))
|
|
157
|
+
]
|
|
158
|
+
return sorted(records, key=lambda record: (_text(_mapping(record["original_item"]).get("field_path")), record["source_item_id"]))
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _formal_reference_for_unknown(record: Mapping[str, Any], formal_ids: set[str]) -> str:
|
|
162
|
+
field_path = _text(record.get("field_path"))
|
|
163
|
+
match = re.search(r"(?:definitions|assumptions|propositions|proof_obligations|forward_derivation(?:\.steps)?)\.([A-Za-z][A-Za-z0-9_-]*)", field_path)
|
|
164
|
+
if match and match.group(1) in formal_ids:
|
|
165
|
+
return match.group(1)
|
|
166
|
+
return ""
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _status(value: object) -> str:
|
|
170
|
+
raw = _text(value).casefold()
|
|
171
|
+
if raw in {"candidate_formalization", "proposed", "user_declared"}:
|
|
172
|
+
return "candidate"
|
|
173
|
+
return "unverified"
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _local_branch_token(identifier: str) -> str:
|
|
177
|
+
token = re.sub(r"[^A-Z0-9]+", "-", identifier.upper()).strip("-")
|
|
178
|
+
return token or "UPSTREAM"
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _outcome_branch_id(outcome_ids: set[str], *candidates: str) -> list[str]:
|
|
182
|
+
return [candidate for candidate in candidates if candidate in outcome_ids][:1]
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _explicit_formal_references(record: Mapping[str, Any], formal_ids: set[str]) -> set[str]:
|
|
186
|
+
references = _record_references(
|
|
187
|
+
record,
|
|
188
|
+
"premises",
|
|
189
|
+
"depends_on",
|
|
190
|
+
"assumption_ids",
|
|
191
|
+
"formal_reference_ids",
|
|
192
|
+
"required_formal_reference_ids",
|
|
193
|
+
)
|
|
194
|
+
return references & formal_ids
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _matching_formal_ids(
|
|
198
|
+
record: Mapping[str, Any],
|
|
199
|
+
*,
|
|
200
|
+
candidates: Mapping[str, Mapping[str, Any]],
|
|
201
|
+
) -> set[str]:
|
|
202
|
+
tokens = _reference_tokens(record)
|
|
203
|
+
if not tokens:
|
|
204
|
+
return set()
|
|
205
|
+
return {
|
|
206
|
+
identifier
|
|
207
|
+
for identifier, candidate in candidates.items()
|
|
208
|
+
if tokens & _reference_tokens(candidate)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def _counterexample_classification(record: Mapping[str, Any]) -> str:
|
|
213
|
+
validity = _text(record.get("validity")).casefold()
|
|
214
|
+
conclusion = _mapping(record.get("conclusion_check"))
|
|
215
|
+
conclusion_result = _text(conclusion.get("result")).casefold()
|
|
216
|
+
if validity in {"valid_counterexample", "valid", "all_assumptions_satisfied"} and conclusion_result in {
|
|
217
|
+
"counterexample",
|
|
218
|
+
"contradicted",
|
|
219
|
+
"refuted",
|
|
220
|
+
"violated",
|
|
221
|
+
}:
|
|
222
|
+
return "would_falsify"
|
|
223
|
+
if validity == "boundary_case":
|
|
224
|
+
return "scope_delimiter"
|
|
225
|
+
if validity == "assumptions_not_satisfied":
|
|
226
|
+
return "assumptions_not_satisfied"
|
|
227
|
+
return "no_information"
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def build_theory_spine(
|
|
231
|
+
preparation: Mapping[str, Any],
|
|
232
|
+
*,
|
|
233
|
+
routing: Mapping[str, Any],
|
|
234
|
+
source_registry: Mapping[str, Any] | None = None,
|
|
235
|
+
) -> dict[str, Any]:
|
|
236
|
+
"""Compile frozen mathematical-theory records into local audit units.
|
|
237
|
+
|
|
238
|
+
Internal IDs such as ``TS-L-1`` and ``TS-BR-PO1-NO_INFORMATION`` are
|
|
239
|
+
document-local. Their reader-facing ``display_label`` values retain the
|
|
240
|
+
conventional ``L1``/``PO1``/``F1`` notation, while source-reference fields
|
|
241
|
+
contain exclusively IDs supplied by the frozen handoff records.
|
|
242
|
+
"""
|
|
243
|
+
|
|
244
|
+
template_family = _text(routing.get("template_family"))
|
|
245
|
+
empty_spine = {
|
|
246
|
+
"schema_version": THEORY_SPINE_SCHEMA_VERSION,
|
|
247
|
+
"template_family": template_family,
|
|
248
|
+
"enabled": False,
|
|
249
|
+
"compiler_status": "not_applicable",
|
|
250
|
+
"lemma_units": [],
|
|
251
|
+
"proof_obligations": [],
|
|
252
|
+
"falsifiers": [],
|
|
253
|
+
"decision_branches": [],
|
|
254
|
+
}
|
|
255
|
+
if template_family != "mathematics_theory":
|
|
256
|
+
return empty_spine
|
|
257
|
+
|
|
258
|
+
author_context = _mapping(_mapping(preparation.get("source_bundle")).get("author_context"))
|
|
259
|
+
formal_reasoning = _mapping(author_context.get("formal_reasoning"))
|
|
260
|
+
formal_by_id, formal_kinds = _formal_records(author_context)
|
|
261
|
+
formal_ids = set(formal_by_id)
|
|
262
|
+
assumption_records = {
|
|
263
|
+
identifier: record
|
|
264
|
+
for identifier, record in formal_by_id.items()
|
|
265
|
+
if formal_kinds.get(identifier) == "assumption"
|
|
266
|
+
}
|
|
267
|
+
proof_records = {
|
|
268
|
+
identifier: record
|
|
269
|
+
for identifier, record in formal_by_id.items()
|
|
270
|
+
if formal_kinds.get(identifier) == "proof_obligation"
|
|
271
|
+
}
|
|
272
|
+
unknown_records = _unknown_records(preparation, source_registry)
|
|
273
|
+
unknown_ids_by_formal_id: dict[str, list[str]] = {}
|
|
274
|
+
for unknown in unknown_records:
|
|
275
|
+
original_item = _mapping(unknown.get("original_item"))
|
|
276
|
+
formal_reference_id = _formal_reference_for_unknown(original_item, formal_ids)
|
|
277
|
+
if formal_reference_id:
|
|
278
|
+
unknown_ids_by_formal_id.setdefault(formal_reference_id, []).append(_text(unknown.get("source_item_id")))
|
|
279
|
+
for unknown_ids in unknown_ids_by_formal_id.values():
|
|
280
|
+
unknown_ids.sort()
|
|
281
|
+
|
|
282
|
+
outcomes = _stable_records(author_context.get("outcome_branches"), identifier_field="branch_id")
|
|
283
|
+
outcome_ids = {_text(record.get("branch_id")) for record in outcomes}
|
|
284
|
+
|
|
285
|
+
lemma_sources = [
|
|
286
|
+
(identifier, record)
|
|
287
|
+
for identifier, record in formal_by_id.items()
|
|
288
|
+
if formal_kinds.get(identifier) in {"proposition", "forward_derivation_step"}
|
|
289
|
+
]
|
|
290
|
+
lemma_sources.sort(key=lambda item: (0 if formal_kinds[item[0]] == "proposition" else 1, item[0], _canonical_json(item[1])))
|
|
291
|
+
lemma_units: list[dict[str, Any]] = []
|
|
292
|
+
lemma_id_by_source_id: dict[str, str] = {}
|
|
293
|
+
for index, (source_id, record) in enumerate(lemma_sources, start=1):
|
|
294
|
+
lemma_id = f"TS-L-{index}"
|
|
295
|
+
lemma_id_by_source_id[source_id] = lemma_id
|
|
296
|
+
premise_ids = _explicit_formal_references(record, formal_ids)
|
|
297
|
+
premise_ids.update(_matching_formal_ids(record, candidates=assumption_records))
|
|
298
|
+
related_proof_ids = _matching_formal_ids(record, candidates=proof_records)
|
|
299
|
+
lemma_units.append(
|
|
300
|
+
{
|
|
301
|
+
"lemma_id": lemma_id,
|
|
302
|
+
"display_label": f"L{index}",
|
|
303
|
+
"source_kind": formal_kinds[source_id],
|
|
304
|
+
"source_formal_reference_ids": [source_id],
|
|
305
|
+
"premise_ids": sorted(premise_ids),
|
|
306
|
+
"status": _status(record.get("status")),
|
|
307
|
+
"source_status": _text(record.get("status")),
|
|
308
|
+
"proof_obligation_ids": sorted(related_proof_ids),
|
|
309
|
+
"falsifier_ids": [],
|
|
310
|
+
"decision_branch_ids": [],
|
|
311
|
+
}
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
no_information_reference_ids = {
|
|
315
|
+
identifier
|
|
316
|
+
for identifier, record in formal_by_id.items()
|
|
317
|
+
if _text(record.get("status")).casefold() in _UNRESOLVED_STATUSES
|
|
318
|
+
}
|
|
319
|
+
no_information_reference_ids.update(unknown_ids_by_formal_id)
|
|
320
|
+
decision_branches: list[dict[str, Any]] = []
|
|
321
|
+
for outcome in outcomes:
|
|
322
|
+
outcome_id = _text(outcome.get("branch_id"))
|
|
323
|
+
decision_branches.append(
|
|
324
|
+
{
|
|
325
|
+
"branch_id": f"TS-BR-OUTCOME-{_local_branch_token(outcome_id)}",
|
|
326
|
+
"display_label": f"Branch {outcome_id}",
|
|
327
|
+
"branch_kind": "upstream_outcome_branch",
|
|
328
|
+
"source_formal_reference_ids": [],
|
|
329
|
+
"source_counterexample_ids": [],
|
|
330
|
+
"source_outcome_branch_ids": [outcome_id],
|
|
331
|
+
"source_unknown_item_ids": [],
|
|
332
|
+
"status": "expected_not_observed",
|
|
333
|
+
"conclusion_policy": "defer_to_upstream_outcome_branch",
|
|
334
|
+
}
|
|
335
|
+
)
|
|
336
|
+
no_information_branch_by_formal_id: dict[str, str] = {}
|
|
337
|
+
for source_id in sorted(no_information_reference_ids):
|
|
338
|
+
branch_id = f"TS-BR-{_local_branch_token(source_id)}-NO_INFORMATION"
|
|
339
|
+
no_information_branch_by_formal_id[source_id] = branch_id
|
|
340
|
+
decision_branches.append(
|
|
341
|
+
{
|
|
342
|
+
"branch_id": branch_id,
|
|
343
|
+
"display_label": f"No-information: {source_id}",
|
|
344
|
+
"branch_kind": "no_information",
|
|
345
|
+
"source_formal_reference_ids": [source_id] if source_id in formal_ids else [],
|
|
346
|
+
"source_counterexample_ids": [],
|
|
347
|
+
"source_outcome_branch_ids": _outcome_branch_id(outcome_ids, "uninformative_or_invalid"),
|
|
348
|
+
"source_unknown_item_ids": sorted(unknown_ids_by_formal_id.get(source_id) or []),
|
|
349
|
+
"status": "no_information",
|
|
350
|
+
"conclusion_policy": "withhold_theorem_status_update",
|
|
351
|
+
"next_action": "resolve_or_review_upstream_input",
|
|
352
|
+
}
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
proof_obligations: list[dict[str, Any]] = []
|
|
356
|
+
for index, (source_id, record) in enumerate(sorted(proof_records.items()), start=1):
|
|
357
|
+
local_id = f"TS-PO-{index}"
|
|
358
|
+
matching_dependencies = _matching_formal_ids(record, candidates={
|
|
359
|
+
identifier: candidate
|
|
360
|
+
for identifier, candidate in formal_by_id.items()
|
|
361
|
+
if formal_kinds.get(identifier) in {"definition", "assumption", "proposition", "forward_derivation_step"}
|
|
362
|
+
})
|
|
363
|
+
matching_dependencies.update(_explicit_formal_references(record, formal_ids))
|
|
364
|
+
related_lemma_ids = sorted(
|
|
365
|
+
lemma_id
|
|
366
|
+
for lemma_source_id, lemma_id in lemma_id_by_source_id.items()
|
|
367
|
+
if lemma_source_id in matching_dependencies
|
|
368
|
+
or source_id in set(next(
|
|
369
|
+
unit["proof_obligation_ids"]
|
|
370
|
+
for unit in lemma_units
|
|
371
|
+
if unit["lemma_id"] == lemma_id
|
|
372
|
+
))
|
|
373
|
+
)
|
|
374
|
+
proof_obligations.append(
|
|
375
|
+
{
|
|
376
|
+
"proof_obligation_id": local_id,
|
|
377
|
+
"display_label": f"PO{index}",
|
|
378
|
+
"source_formal_reference_ids": [source_id],
|
|
379
|
+
"required_formal_reference_ids": sorted(matching_dependencies),
|
|
380
|
+
"related_lemma_ids": related_lemma_ids,
|
|
381
|
+
"source_unknown_item_ids": sorted(unknown_ids_by_formal_id.get(source_id) or []),
|
|
382
|
+
"status": _status(record.get("status")),
|
|
383
|
+
"source_status": _text(record.get("status")),
|
|
384
|
+
"if_unavailable_branch_id": no_information_branch_by_formal_id.get(source_id, ""),
|
|
385
|
+
}
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
local_proof_id_by_source_id = {
|
|
389
|
+
source_id: proof_obligation["proof_obligation_id"]
|
|
390
|
+
for source_id, proof_obligation in zip(sorted(proof_records), proof_obligations, strict=True)
|
|
391
|
+
}
|
|
392
|
+
for unit in lemma_units:
|
|
393
|
+
unit["proof_obligation_ids"] = [
|
|
394
|
+
local_proof_id_by_source_id[source_id]
|
|
395
|
+
for source_id in unit["proof_obligation_ids"]
|
|
396
|
+
if source_id in local_proof_id_by_source_id
|
|
397
|
+
]
|
|
398
|
+
related_source_ids = set(unit["source_formal_reference_ids"]) | set(unit["premise_ids"])
|
|
399
|
+
unit["decision_branch_ids"] = sorted(
|
|
400
|
+
branch_id
|
|
401
|
+
for source_id, branch_id in no_information_branch_by_formal_id.items()
|
|
402
|
+
if source_id in related_source_ids
|
|
403
|
+
or source_id in {
|
|
404
|
+
proof_obligation["source_formal_reference_ids"][0]
|
|
405
|
+
for proof_obligation in proof_obligations
|
|
406
|
+
if set(proof_obligation["related_lemma_ids"]) & {unit["lemma_id"]}
|
|
407
|
+
}
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
counterexample_analysis = _mapping(author_context.get("counterexample_analysis"))
|
|
411
|
+
counterexamples = _stable_records(counterexample_analysis.get("candidate_counterexamples"), identifier_field="counterexample_id")
|
|
412
|
+
counterexample_target_id = _text(counterexample_analysis.get("target_claim_id"))
|
|
413
|
+
target_lemma_ids = [lemma_id_by_source_id[counterexample_target_id]] if counterexample_target_id in lemma_id_by_source_id else []
|
|
414
|
+
falsifiers: list[dict[str, Any]] = []
|
|
415
|
+
outcome_candidates_by_classification = {
|
|
416
|
+
"would_falsify": ("null_or_contradictory",),
|
|
417
|
+
"scope_delimiter": ("partial_or_heterogeneous",),
|
|
418
|
+
"assumptions_not_satisfied": ("uninformative_or_invalid",),
|
|
419
|
+
"no_information": ("uninformative_or_invalid",),
|
|
420
|
+
}
|
|
421
|
+
for index, record in enumerate(counterexamples, start=1):
|
|
422
|
+
counterexample_id = _text(record.get("counterexample_id"))
|
|
423
|
+
classification = _counterexample_classification(record)
|
|
424
|
+
falsifier_id = f"TS-F-{index}"
|
|
425
|
+
falsifiers.append(
|
|
426
|
+
{
|
|
427
|
+
"falsifier_id": falsifier_id,
|
|
428
|
+
"display_label": f"F{index}",
|
|
429
|
+
"source_counterexample_ids": [counterexample_id],
|
|
430
|
+
"target_formal_reference_ids": [counterexample_target_id] if counterexample_target_id in formal_ids else [],
|
|
431
|
+
"target_lemma_ids": target_lemma_ids,
|
|
432
|
+
"classification": classification,
|
|
433
|
+
"source_outcome_branch_ids": _outcome_branch_id(
|
|
434
|
+
outcome_ids,
|
|
435
|
+
*outcome_candidates_by_classification[classification],
|
|
436
|
+
),
|
|
437
|
+
}
|
|
438
|
+
)
|
|
439
|
+
for falsifier in falsifiers:
|
|
440
|
+
for lemma_id in falsifier["target_lemma_ids"]:
|
|
441
|
+
for unit in lemma_units:
|
|
442
|
+
if unit["lemma_id"] == lemma_id:
|
|
443
|
+
unit["falsifier_ids"].append(falsifier["falsifier_id"])
|
|
444
|
+
|
|
445
|
+
if not lemma_units:
|
|
446
|
+
decision_branches.append(
|
|
447
|
+
{
|
|
448
|
+
"branch_id": "TS-BR-MISSING-DERIVATION-INPUT-NO_INFORMATION",
|
|
449
|
+
"display_label": "No-information: derivation input",
|
|
450
|
+
"branch_kind": "compiler_no_information",
|
|
451
|
+
"source_formal_reference_ids": [],
|
|
452
|
+
"source_counterexample_ids": [],
|
|
453
|
+
"source_outcome_branch_ids": _outcome_branch_id(outcome_ids, "uninformative_or_invalid"),
|
|
454
|
+
"source_unknown_item_ids": [],
|
|
455
|
+
"status": "no_information",
|
|
456
|
+
"conclusion_policy": "withhold_theorem_status_update",
|
|
457
|
+
"next_action": "supply_upstream_proposition_or_derivation_input",
|
|
458
|
+
"reason_code": "missing_upstream_derivation_input",
|
|
459
|
+
}
|
|
460
|
+
)
|
|
461
|
+
spine = {
|
|
462
|
+
"schema_version": THEORY_SPINE_SCHEMA_VERSION,
|
|
463
|
+
"template_family": template_family,
|
|
464
|
+
"enabled": True,
|
|
465
|
+
"compiler_status": "ready" if lemma_units else "no_auditable_lemma_input",
|
|
466
|
+
"lemma_units": lemma_units,
|
|
467
|
+
"proof_obligations": proof_obligations,
|
|
468
|
+
"falsifiers": falsifiers,
|
|
469
|
+
"decision_branches": decision_branches,
|
|
470
|
+
}
|
|
471
|
+
errors = validate_theory_spine(spine, preparation=preparation, source_registry=source_registry)
|
|
472
|
+
if errors:
|
|
473
|
+
raise TheorySpineError("theory spine compilation failed: " + "; ".join(errors))
|
|
474
|
+
return spine
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
def validate_theory_spine(
|
|
478
|
+
payload: object,
|
|
479
|
+
*,
|
|
480
|
+
preparation: Mapping[str, Any],
|
|
481
|
+
source_registry: Mapping[str, Any] | None = None,
|
|
482
|
+
) -> list[str]:
|
|
483
|
+
"""Validate local labels and their reverse references to frozen records."""
|
|
484
|
+
|
|
485
|
+
errors: list[str] = []
|
|
486
|
+
for error in Draft202012Validator(THEORY_SPINE_SCHEMA).iter_errors(payload):
|
|
487
|
+
path = "/".join(str(part) for part in error.absolute_path) or "$"
|
|
488
|
+
errors.append(f"{path}: {error.message}")
|
|
489
|
+
if not isinstance(payload, Mapping):
|
|
490
|
+
return sorted(set(errors))
|
|
491
|
+
spine = dict(payload)
|
|
492
|
+
author_context = _mapping(_mapping(preparation.get("source_bundle")).get("author_context"))
|
|
493
|
+
resolved_source_registry = source_registry
|
|
494
|
+
if not isinstance(resolved_source_registry, Mapping):
|
|
495
|
+
from .source_registry import build_frozen_source_registry
|
|
496
|
+
|
|
497
|
+
resolved_source_registry = build_frozen_source_registry(preparation)
|
|
498
|
+
formal_by_id, _formal_kinds = _formal_records(author_context)
|
|
499
|
+
formal_ids = set(formal_by_id)
|
|
500
|
+
counterexample_ids = {
|
|
501
|
+
_text(record.get("counterexample_id"))
|
|
502
|
+
for record in _mapping(author_context.get("counterexample_analysis")).get("candidate_counterexamples") or []
|
|
503
|
+
if isinstance(record, Mapping) and _text(record.get("counterexample_id"))
|
|
504
|
+
}
|
|
505
|
+
outcome_ids = {
|
|
506
|
+
_text(record.get("branch_id"))
|
|
507
|
+
for record in author_context.get("outcome_branches") or []
|
|
508
|
+
if isinstance(record, Mapping) and _text(record.get("branch_id"))
|
|
509
|
+
}
|
|
510
|
+
unknown_ids = {
|
|
511
|
+
_text(record.get("source_item_id"))
|
|
512
|
+
for record in _mapping(resolved_source_registry).get("unknown_items") or []
|
|
513
|
+
if isinstance(record, Mapping) and _text(record.get("source_item_id"))
|
|
514
|
+
}
|
|
515
|
+
collection_specs = (
|
|
516
|
+
("lemma_units", "lemma_id", _LOCAL_LEMMA_ID),
|
|
517
|
+
("proof_obligations", "proof_obligation_id", _LOCAL_PROOF_OBLIGATION_ID),
|
|
518
|
+
("falsifiers", "falsifier_id", _LOCAL_FALSIFIER_ID),
|
|
519
|
+
("decision_branches", "branch_id", _LOCAL_BRANCH_ID),
|
|
520
|
+
)
|
|
521
|
+
records_by_collection = {
|
|
522
|
+
collection: [record for record in spine.get(collection) or [] if isinstance(record, Mapping)]
|
|
523
|
+
for collection, _identifier_field, _pattern in collection_specs
|
|
524
|
+
}
|
|
525
|
+
local_ids: set[str] = set()
|
|
526
|
+
for collection, identifier_field, pattern in collection_specs:
|
|
527
|
+
seen_ids: set[str] = set()
|
|
528
|
+
for index, record in enumerate(spine.get(collection) or []):
|
|
529
|
+
if not isinstance(record, Mapping):
|
|
530
|
+
errors.append(f"{collection}/{index} must be an object")
|
|
531
|
+
continue
|
|
532
|
+
identifier = _text(record.get(identifier_field))
|
|
533
|
+
if not pattern.fullmatch(identifier):
|
|
534
|
+
errors.append(f"{collection}/{index}/{identifier_field} is not a valid local audit label")
|
|
535
|
+
if identifier in seen_ids or identifier in local_ids:
|
|
536
|
+
errors.append(f"{collection}/{index}/{identifier_field} duplicates a local audit label")
|
|
537
|
+
seen_ids.add(identifier)
|
|
538
|
+
local_ids.add(identifier)
|
|
539
|
+
upstream_ids = {
|
|
540
|
+
*formal_ids,
|
|
541
|
+
*counterexample_ids,
|
|
542
|
+
*outcome_ids,
|
|
543
|
+
*unknown_ids,
|
|
544
|
+
*{
|
|
545
|
+
_text(value)
|
|
546
|
+
for value in _mapping(resolved_source_registry).get("allowed_source_ids") or []
|
|
547
|
+
if _text(value)
|
|
548
|
+
},
|
|
549
|
+
*{
|
|
550
|
+
_text(_mapping(record).get("citation_key"))
|
|
551
|
+
for record in _mapping(resolved_source_registry).get("citation_registry") or []
|
|
552
|
+
if _text(_mapping(record).get("citation_key"))
|
|
553
|
+
},
|
|
554
|
+
}
|
|
555
|
+
if local_ids & upstream_ids:
|
|
556
|
+
errors.append("local theory audit labels collide with frozen upstream identifiers")
|
|
557
|
+
|
|
558
|
+
lemma_ids = {
|
|
559
|
+
_text(record.get("lemma_id")) for record in records_by_collection["lemma_units"] if _text(record.get("lemma_id"))
|
|
560
|
+
}
|
|
561
|
+
proof_obligation_ids = {
|
|
562
|
+
_text(record.get("proof_obligation_id"))
|
|
563
|
+
for record in records_by_collection["proof_obligations"]
|
|
564
|
+
if _text(record.get("proof_obligation_id"))
|
|
565
|
+
}
|
|
566
|
+
falsifier_ids = {
|
|
567
|
+
_text(record.get("falsifier_id")) for record in records_by_collection["falsifiers"] if _text(record.get("falsifier_id"))
|
|
568
|
+
}
|
|
569
|
+
decision_branch_ids = {
|
|
570
|
+
_text(record.get("branch_id"))
|
|
571
|
+
for record in records_by_collection["decision_branches"]
|
|
572
|
+
if _text(record.get("branch_id"))
|
|
573
|
+
}
|
|
574
|
+
for collection, records in records_by_collection.items():
|
|
575
|
+
for index, record in enumerate(records):
|
|
576
|
+
for field, allowed in (
|
|
577
|
+
("source_formal_reference_ids", formal_ids),
|
|
578
|
+
("required_formal_reference_ids", formal_ids),
|
|
579
|
+
("target_formal_reference_ids", formal_ids),
|
|
580
|
+
("source_counterexample_ids", counterexample_ids),
|
|
581
|
+
("source_outcome_branch_ids", outcome_ids),
|
|
582
|
+
):
|
|
583
|
+
values = _text_list(record.get(field))
|
|
584
|
+
if set(values) - allowed:
|
|
585
|
+
errors.append(f"{collection}/{index}/{field} contains an unknown upstream ID")
|
|
586
|
+
unknown_references = _text_list(record.get("source_unknown_item_ids"))
|
|
587
|
+
if set(unknown_references) - unknown_ids:
|
|
588
|
+
errors.append(f"{collection}/{index}/source_unknown_item_ids contains an unknown source item")
|
|
589
|
+
if collection == "lemma_units":
|
|
590
|
+
if set(_text_list(record.get("premise_ids"))) - formal_ids:
|
|
591
|
+
errors.append(f"lemma_units/{index}/premise_ids contains an unknown formal reference")
|
|
592
|
+
if set(_text_list(record.get("proof_obligation_ids"))) - proof_obligation_ids:
|
|
593
|
+
errors.append(f"lemma_units/{index}/proof_obligation_ids contains an unknown local proof obligation")
|
|
594
|
+
if set(_text_list(record.get("falsifier_ids"))) - falsifier_ids:
|
|
595
|
+
errors.append(f"lemma_units/{index}/falsifier_ids contains an unknown local falsifier")
|
|
596
|
+
if set(_text_list(record.get("decision_branch_ids"))) - decision_branch_ids:
|
|
597
|
+
errors.append(f"lemma_units/{index}/decision_branch_ids contains an unknown local decision branch")
|
|
598
|
+
elif collection == "proof_obligations":
|
|
599
|
+
if set(_text_list(record.get("related_lemma_ids"))) - lemma_ids:
|
|
600
|
+
errors.append(f"proof_obligations/{index}/related_lemma_ids contains an unknown local lemma")
|
|
601
|
+
branch_id = _text(record.get("if_unavailable_branch_id"))
|
|
602
|
+
if branch_id and branch_id not in decision_branch_ids:
|
|
603
|
+
errors.append(f"proof_obligations/{index}/if_unavailable_branch_id contains an unknown local decision branch")
|
|
604
|
+
elif collection == "falsifiers" and set(_text_list(record.get("target_lemma_ids"))) - lemma_ids:
|
|
605
|
+
errors.append(f"falsifiers/{index}/target_lemma_ids contains an unknown local lemma")
|
|
606
|
+
return sorted(set(errors))
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
def theory_spine_context_for_section(
|
|
610
|
+
theory_spine: Mapping[str, Any],
|
|
611
|
+
*,
|
|
612
|
+
section_id: str,
|
|
613
|
+
unit_references: Mapping[str, Any] | None = None,
|
|
614
|
+
) -> dict[str, Any]:
|
|
615
|
+
"""Return the compact, route-owned slice of a theory spine registry."""
|
|
616
|
+
|
|
617
|
+
spine = _mapping(theory_spine)
|
|
618
|
+
if not spine.get("enabled"):
|
|
619
|
+
return {
|
|
620
|
+
"schema_version": _text(spine.get("schema_version")) or THEORY_SPINE_SCHEMA_VERSION,
|
|
621
|
+
"enabled": False,
|
|
622
|
+
"section_id": section_id,
|
|
623
|
+
"mode": "not_applicable",
|
|
624
|
+
"lemma_units": [],
|
|
625
|
+
"proof_obligations": [],
|
|
626
|
+
"falsifiers": [],
|
|
627
|
+
"decision_branches": [],
|
|
628
|
+
}
|
|
629
|
+
references = _mapping(unit_references)
|
|
630
|
+
|
|
631
|
+
def selected(collection: str, identifier_field: str, reference_field: str) -> list[dict[str, Any]]:
|
|
632
|
+
selected_ids = set(_text_list(references.get(reference_field)))
|
|
633
|
+
return [
|
|
634
|
+
deepcopy(dict(record))
|
|
635
|
+
for record in spine.get(collection) or []
|
|
636
|
+
if isinstance(record, Mapping) and _text(record.get(identifier_field)) in selected_ids
|
|
637
|
+
]
|
|
638
|
+
|
|
639
|
+
return {
|
|
640
|
+
"schema_version": _text(spine.get("schema_version")) or THEORY_SPINE_SCHEMA_VERSION,
|
|
641
|
+
"enabled": True,
|
|
642
|
+
"section_id": section_id,
|
|
643
|
+
"mode": _text(references.get("mode")) or "reference_only",
|
|
644
|
+
"lemma_units": selected("lemma_units", "lemma_id", "lemma_ids"),
|
|
645
|
+
"proof_obligations": selected("proof_obligations", "proof_obligation_id", "proof_obligation_ids"),
|
|
646
|
+
"falsifiers": selected("falsifiers", "falsifier_id", "falsifier_ids"),
|
|
647
|
+
"decision_branches": selected("decision_branches", "branch_id", "decision_branch_ids"),
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
def theory_spine_display_labels(theory_spine: Mapping[str, Any]) -> dict[str, str]:
|
|
652
|
+
"""Return the reader-facing labels for private local theory identifiers."""
|
|
653
|
+
|
|
654
|
+
spine = _mapping(theory_spine)
|
|
655
|
+
labels: dict[str, str] = {}
|
|
656
|
+
for collection, identifier_field in (
|
|
657
|
+
("lemma_units", "lemma_id"),
|
|
658
|
+
("proof_obligations", "proof_obligation_id"),
|
|
659
|
+
("falsifiers", "falsifier_id"),
|
|
660
|
+
("decision_branches", "branch_id"),
|
|
661
|
+
):
|
|
662
|
+
for record in spine.get(collection) or []:
|
|
663
|
+
if not isinstance(record, Mapping):
|
|
664
|
+
continue
|
|
665
|
+
identifier = _text(record.get(identifier_field))
|
|
666
|
+
display_label = _text(record.get("display_label"))
|
|
667
|
+
if identifier and display_label:
|
|
668
|
+
labels[identifier] = display_label
|
|
669
|
+
return labels
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
def replace_theory_spine_internal_ids(text: object, theory_spine: Mapping[str, Any]) -> str:
|
|
673
|
+
"""Replace known private audit identifiers with their public labels."""
|
|
674
|
+
|
|
675
|
+
value = str(text or "")
|
|
676
|
+
labels = theory_spine_display_labels(theory_spine)
|
|
677
|
+
if not labels:
|
|
678
|
+
return value
|
|
679
|
+
pattern = re.compile(
|
|
680
|
+
r"(?<![A-Za-z0-9_-])(?:"
|
|
681
|
+
+ "|".join(re.escape(identifier) for identifier in sorted(labels, key=len, reverse=True))
|
|
682
|
+
+ r")(?![A-Za-z0-9_-])"
|
|
683
|
+
)
|
|
684
|
+
return pattern.sub(lambda match: labels[match.group(0)], value)
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
def theory_spine_internal_ids_in_text(text: object) -> list[str]:
|
|
688
|
+
"""Return local audit identifiers that must never appear in public prose."""
|
|
689
|
+
|
|
690
|
+
return sorted(set(_VISIBLE_LOCAL_ID.findall(str(text or ""))))
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
__all__ = [
|
|
694
|
+
"THEORY_SPINE_SCHEMA",
|
|
695
|
+
"THEORY_SPINE_SCHEMA_VERSION",
|
|
696
|
+
"TheorySpineError",
|
|
697
|
+
"build_theory_spine",
|
|
698
|
+
"replace_theory_spine_internal_ids",
|
|
699
|
+
"theory_spine_display_labels",
|
|
700
|
+
"theory_spine_context_for_section",
|
|
701
|
+
"theory_spine_internal_ids_in_text",
|
|
702
|
+
"validate_theory_spine",
|
|
703
|
+
]
|