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,730 @@
|
|
|
1
|
+
"""Plugin discovery and loading."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import importlib
|
|
6
|
+
import importlib.util
|
|
7
|
+
import json
|
|
8
|
+
import logging
|
|
9
|
+
import os
|
|
10
|
+
import sys
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any, Iterable
|
|
13
|
+
|
|
14
|
+
import yaml
|
|
15
|
+
|
|
16
|
+
from openharness.config.paths import get_config_dir
|
|
17
|
+
from openharness.coordinator.agent_definitions import (
|
|
18
|
+
AGENT_COLORS,
|
|
19
|
+
EFFORT_LEVELS,
|
|
20
|
+
ISOLATION_MODES,
|
|
21
|
+
MEMORY_SCOPES,
|
|
22
|
+
PERMISSION_MODES,
|
|
23
|
+
AgentDefinition,
|
|
24
|
+
_parse_agent_frontmatter,
|
|
25
|
+
_parse_positive_int,
|
|
26
|
+
_parse_str_list,
|
|
27
|
+
)
|
|
28
|
+
from openharness.plugins.schemas import PluginManifest
|
|
29
|
+
from openharness.plugins.types import LoadedPlugin, PluginCommandDefinition
|
|
30
|
+
from openharness.skills.loader import _parse_skill_metadata
|
|
31
|
+
from openharness.skills.types import SkillDefinition
|
|
32
|
+
|
|
33
|
+
logger = logging.getLogger(__name__)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_user_plugins_dir() -> Path:
|
|
37
|
+
"""Return the user plugin directory."""
|
|
38
|
+
path = get_config_dir() / "plugins"
|
|
39
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
40
|
+
return path
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def get_project_plugins_dir(cwd: str | Path) -> Path:
|
|
44
|
+
"""Return the project plugin directory."""
|
|
45
|
+
path = Path(cwd).resolve() / ".openharness" / "plugins"
|
|
46
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
47
|
+
return path
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _find_manifest(plugin_dir: Path) -> Path | None:
|
|
51
|
+
"""Find plugin.json in standard or .claude-plugin/ locations."""
|
|
52
|
+
for candidate in [
|
|
53
|
+
plugin_dir / "plugin.json",
|
|
54
|
+
plugin_dir / ".claude-plugin" / "plugin.json",
|
|
55
|
+
]:
|
|
56
|
+
if candidate.exists():
|
|
57
|
+
return candidate
|
|
58
|
+
return None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def discover_plugin_paths(cwd: str | Path, extra_roots: Iterable[str | Path] | None = None) -> list[Path]:
|
|
62
|
+
"""Find plugin directories from user and project locations."""
|
|
63
|
+
roots = [get_user_plugins_dir(), get_project_plugins_dir(cwd)]
|
|
64
|
+
if extra_roots:
|
|
65
|
+
for root in extra_roots:
|
|
66
|
+
path = Path(root).expanduser().resolve()
|
|
67
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
68
|
+
roots.append(path)
|
|
69
|
+
paths: list[Path] = []
|
|
70
|
+
seen: set[Path] = set()
|
|
71
|
+
for root in roots:
|
|
72
|
+
if not root.exists():
|
|
73
|
+
continue
|
|
74
|
+
for path in sorted(root.iterdir()):
|
|
75
|
+
if path.is_dir() and _find_manifest(path) is not None and path not in seen:
|
|
76
|
+
seen.add(path)
|
|
77
|
+
paths.append(path)
|
|
78
|
+
return paths
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def discover_plugin_paths_for_settings(
|
|
82
|
+
settings,
|
|
83
|
+
cwd: str | Path,
|
|
84
|
+
extra_roots: Iterable[str | Path] | None = None,
|
|
85
|
+
) -> list[Path]:
|
|
86
|
+
"""Find plugin directories that are permitted by the active settings."""
|
|
87
|
+
roots = [get_user_plugins_dir()]
|
|
88
|
+
if getattr(settings, "allow_project_plugins", False):
|
|
89
|
+
roots.append(get_project_plugins_dir(cwd))
|
|
90
|
+
if extra_roots:
|
|
91
|
+
for root in extra_roots:
|
|
92
|
+
path = Path(root).expanduser().resolve()
|
|
93
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
94
|
+
roots.append(path)
|
|
95
|
+
paths: list[Path] = []
|
|
96
|
+
seen: set[Path] = set()
|
|
97
|
+
for root in roots:
|
|
98
|
+
if not root.exists():
|
|
99
|
+
continue
|
|
100
|
+
for path in sorted(root.iterdir()):
|
|
101
|
+
if path.is_dir() and _find_manifest(path) is not None and path not in seen:
|
|
102
|
+
seen.add(path)
|
|
103
|
+
paths.append(path)
|
|
104
|
+
return paths
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def load_plugins(settings, cwd: str | Path, extra_roots: Iterable[str | Path] | None = None) -> list[LoadedPlugin]:
|
|
108
|
+
"""Load plugins from disk."""
|
|
109
|
+
project_plugins_dir = get_project_plugins_dir(cwd)
|
|
110
|
+
if not getattr(settings, "allow_project_plugins", False) and any(
|
|
111
|
+
path.is_dir() and _find_manifest(path) is not None for path in sorted(project_plugins_dir.iterdir())
|
|
112
|
+
):
|
|
113
|
+
logger.warning(
|
|
114
|
+
"Found project-local plugins in %s, but they are disabled by default. "
|
|
115
|
+
"Set allow_project_plugins=true if you trust this workspace.",
|
|
116
|
+
project_plugins_dir,
|
|
117
|
+
)
|
|
118
|
+
plugins: list[LoadedPlugin] = []
|
|
119
|
+
for path in discover_plugin_paths_for_settings(settings, cwd, extra_roots=extra_roots):
|
|
120
|
+
plugin = load_plugin(path, settings.enabled_plugins)
|
|
121
|
+
if plugin is not None:
|
|
122
|
+
plugins.append(plugin)
|
|
123
|
+
return plugins
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def load_plugin(path: Path, enabled_plugins: dict[str, bool]) -> LoadedPlugin | None:
|
|
127
|
+
"""Load one plugin directory."""
|
|
128
|
+
manifest_path = _find_manifest(path)
|
|
129
|
+
if manifest_path is None:
|
|
130
|
+
return None
|
|
131
|
+
try:
|
|
132
|
+
manifest = PluginManifest.model_validate_json(manifest_path.read_text(encoding="utf-8"))
|
|
133
|
+
except Exception as exc:
|
|
134
|
+
logger.debug("Failed to load plugin manifest from %s: %s", manifest_path, exc)
|
|
135
|
+
return None
|
|
136
|
+
enabled = enabled_plugins.get(manifest.name, manifest.enabled_by_default)
|
|
137
|
+
|
|
138
|
+
skills = _load_plugin_skills(path / manifest.skills_dir)
|
|
139
|
+
commands = _load_plugin_commands(path, manifest)
|
|
140
|
+
agents = _load_plugin_agents(path, manifest)
|
|
141
|
+
tools = _load_plugin_tools(path, manifest) if enabled else []
|
|
142
|
+
hooks = _load_plugin_hooks(path / manifest.hooks_file)
|
|
143
|
+
hooks_dir_file = path / "hooks" / "hooks.json"
|
|
144
|
+
if not hooks and hooks_dir_file.exists():
|
|
145
|
+
hooks = _load_plugin_hooks_structured(hooks_dir_file, path)
|
|
146
|
+
|
|
147
|
+
mcp = _load_plugin_mcp(path / manifest.mcp_file)
|
|
148
|
+
mcp_json = path / ".mcp.json"
|
|
149
|
+
if not mcp and mcp_json.exists():
|
|
150
|
+
mcp = _load_plugin_mcp(mcp_json)
|
|
151
|
+
|
|
152
|
+
return LoadedPlugin(
|
|
153
|
+
manifest=manifest,
|
|
154
|
+
path=path,
|
|
155
|
+
enabled=enabled,
|
|
156
|
+
skills=skills,
|
|
157
|
+
commands=commands,
|
|
158
|
+
agents=agents,
|
|
159
|
+
hooks=hooks,
|
|
160
|
+
mcp_servers=mcp,
|
|
161
|
+
tools=tools,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _parse_frontmatter(content: str, path: Path) -> tuple[dict[str, Any], str]:
|
|
166
|
+
if not content.startswith("---\n"):
|
|
167
|
+
return {}, content
|
|
168
|
+
marker = "\n---\n"
|
|
169
|
+
end_index = content.find(marker, 4)
|
|
170
|
+
if end_index == -1:
|
|
171
|
+
return {}, content
|
|
172
|
+
raw_frontmatter = content[4:end_index]
|
|
173
|
+
body = content[end_index + len(marker):]
|
|
174
|
+
try:
|
|
175
|
+
parsed = yaml.safe_load(raw_frontmatter) or {}
|
|
176
|
+
except yaml.YAMLError:
|
|
177
|
+
logger.debug("Failed to parse frontmatter from %s", path, exc_info=True)
|
|
178
|
+
parsed = {}
|
|
179
|
+
if not isinstance(parsed, dict):
|
|
180
|
+
parsed = {}
|
|
181
|
+
return parsed, body.strip()
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _extract_description(frontmatter: dict[str, Any], body: str, *, fallback: str) -> str:
|
|
185
|
+
description = frontmatter.get("description")
|
|
186
|
+
if isinstance(description, str) and description.strip():
|
|
187
|
+
return description.strip()
|
|
188
|
+
for line in body.splitlines():
|
|
189
|
+
stripped = line.strip()
|
|
190
|
+
if not stripped:
|
|
191
|
+
continue
|
|
192
|
+
if stripped.startswith("#"):
|
|
193
|
+
stripped = stripped.lstrip("#").strip()
|
|
194
|
+
if stripped:
|
|
195
|
+
return stripped
|
|
196
|
+
return fallback
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _walk_plugin_markdown(
|
|
200
|
+
root: Path,
|
|
201
|
+
*,
|
|
202
|
+
stop_at_skill_dir: bool,
|
|
203
|
+
) -> list[Path]:
|
|
204
|
+
if not root.exists():
|
|
205
|
+
return []
|
|
206
|
+
files: list[Path] = []
|
|
207
|
+
for current_root, dirnames, filenames in os.walk(root, followlinks=True):
|
|
208
|
+
current = Path(current_root)
|
|
209
|
+
skill_file = current / "SKILL.md"
|
|
210
|
+
if stop_at_skill_dir and skill_file.exists():
|
|
211
|
+
files.append(skill_file)
|
|
212
|
+
dirnames[:] = []
|
|
213
|
+
continue
|
|
214
|
+
for filename in sorted(filenames):
|
|
215
|
+
if filename.lower().endswith(".md"):
|
|
216
|
+
files.append(current / filename)
|
|
217
|
+
return sorted(files)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _transform_command_files(files: list[Path]) -> list[Path]:
|
|
221
|
+
files_by_dir: dict[Path, list[Path]] = {}
|
|
222
|
+
for file_path in files:
|
|
223
|
+
files_by_dir.setdefault(file_path.parent, []).append(file_path)
|
|
224
|
+
result: list[Path] = []
|
|
225
|
+
for dir_path, dir_files in files_by_dir.items():
|
|
226
|
+
skill_files = [path for path in dir_files if path.name.lower() == "skill.md"]
|
|
227
|
+
if skill_files:
|
|
228
|
+
result.append(skill_files[0])
|
|
229
|
+
else:
|
|
230
|
+
result.extend(sorted(dir_files))
|
|
231
|
+
return sorted(result)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _command_name_from_file(file_path: Path, base_dir: Path, plugin_name: str) -> str:
|
|
235
|
+
if file_path.name.lower() == "skill.md":
|
|
236
|
+
skill_dir = file_path.parent
|
|
237
|
+
parent_of_skill_dir = skill_dir.parent
|
|
238
|
+
command_base_name = skill_dir.name
|
|
239
|
+
relative_path = parent_of_skill_dir.relative_to(base_dir)
|
|
240
|
+
else:
|
|
241
|
+
command_base_name = file_path.stem
|
|
242
|
+
relative_path = file_path.parent.relative_to(base_dir)
|
|
243
|
+
namespace = ":".join(part for part in relative_path.parts if part and part != ".")
|
|
244
|
+
return (
|
|
245
|
+
f"{plugin_name}:{namespace}:{command_base_name}"
|
|
246
|
+
if namespace
|
|
247
|
+
else f"{plugin_name}:{command_base_name}"
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def _load_plugin_skills(path: Path) -> list[SkillDefinition]:
|
|
252
|
+
"""Load plugin skills using Claude Code's directory SKILL.md layout."""
|
|
253
|
+
if not path.exists():
|
|
254
|
+
return []
|
|
255
|
+
skills: list[SkillDefinition] = []
|
|
256
|
+
direct_skill = path / "SKILL.md"
|
|
257
|
+
if direct_skill.exists():
|
|
258
|
+
content = direct_skill.read_text(encoding="utf-8")
|
|
259
|
+
metadata = _parse_skill_metadata(path.name, content)
|
|
260
|
+
name = metadata["name"]
|
|
261
|
+
description = metadata["description"]
|
|
262
|
+
display_name = name if name != path.name else None
|
|
263
|
+
skills.append(
|
|
264
|
+
SkillDefinition(
|
|
265
|
+
name=name,
|
|
266
|
+
description=description,
|
|
267
|
+
content=content,
|
|
268
|
+
source="plugin",
|
|
269
|
+
path=str(direct_skill),
|
|
270
|
+
base_dir=str(path),
|
|
271
|
+
command_name=path.name,
|
|
272
|
+
display_name=display_name,
|
|
273
|
+
user_invocable=metadata["user_invocable"],
|
|
274
|
+
disable_model_invocation=metadata["disable_model_invocation"],
|
|
275
|
+
model=metadata["model"],
|
|
276
|
+
argument_hint=metadata["argument_hint"],
|
|
277
|
+
)
|
|
278
|
+
)
|
|
279
|
+
return skills
|
|
280
|
+
for child in sorted(path.iterdir()):
|
|
281
|
+
if not child.is_dir():
|
|
282
|
+
continue
|
|
283
|
+
skill_path = child / "SKILL.md"
|
|
284
|
+
if not skill_path.exists():
|
|
285
|
+
continue
|
|
286
|
+
content = skill_path.read_text(encoding="utf-8")
|
|
287
|
+
metadata = _parse_skill_metadata(child.name, content)
|
|
288
|
+
name = metadata["name"]
|
|
289
|
+
description = metadata["description"]
|
|
290
|
+
display_name = name if name != child.name else None
|
|
291
|
+
skills.append(
|
|
292
|
+
SkillDefinition(
|
|
293
|
+
name=name,
|
|
294
|
+
description=description,
|
|
295
|
+
content=content,
|
|
296
|
+
source="plugin",
|
|
297
|
+
path=str(skill_path),
|
|
298
|
+
base_dir=str(child),
|
|
299
|
+
command_name=child.name,
|
|
300
|
+
display_name=display_name,
|
|
301
|
+
user_invocable=metadata["user_invocable"],
|
|
302
|
+
disable_model_invocation=metadata["disable_model_invocation"],
|
|
303
|
+
model=metadata["model"],
|
|
304
|
+
argument_hint=metadata["argument_hint"],
|
|
305
|
+
)
|
|
306
|
+
)
|
|
307
|
+
return skills
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def _coerce_path_list(raw: Any) -> list[str]:
|
|
311
|
+
if raw is None:
|
|
312
|
+
return []
|
|
313
|
+
if isinstance(raw, str):
|
|
314
|
+
return [raw]
|
|
315
|
+
if isinstance(raw, list):
|
|
316
|
+
return [str(item) for item in raw]
|
|
317
|
+
return []
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _load_plugin_commands(path: Path, manifest: PluginManifest) -> list[PluginCommandDefinition]:
|
|
321
|
+
commands: list[PluginCommandDefinition] = []
|
|
322
|
+
seen: set[Path] = set()
|
|
323
|
+
default_commands_dir = path / "commands"
|
|
324
|
+
commands.extend(
|
|
325
|
+
_load_commands_from_directory(
|
|
326
|
+
default_commands_dir,
|
|
327
|
+
plugin_name=manifest.name,
|
|
328
|
+
seen=seen,
|
|
329
|
+
)
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
manifest_commands = manifest.commands
|
|
333
|
+
if isinstance(manifest_commands, dict):
|
|
334
|
+
for command_name, metadata in manifest_commands.items():
|
|
335
|
+
if not isinstance(metadata, dict):
|
|
336
|
+
continue
|
|
337
|
+
source = metadata.get("source")
|
|
338
|
+
content = metadata.get("content")
|
|
339
|
+
if isinstance(source, str):
|
|
340
|
+
command_path = (path / source).resolve()
|
|
341
|
+
if command_path.is_dir():
|
|
342
|
+
commands.extend(
|
|
343
|
+
_load_commands_from_directory(
|
|
344
|
+
command_path,
|
|
345
|
+
plugin_name=manifest.name,
|
|
346
|
+
seen=seen,
|
|
347
|
+
)
|
|
348
|
+
)
|
|
349
|
+
continue
|
|
350
|
+
command = _load_single_command_file(
|
|
351
|
+
command_path,
|
|
352
|
+
command_name=f"{manifest.name}:{command_name}",
|
|
353
|
+
metadata_override=metadata,
|
|
354
|
+
seen=seen,
|
|
355
|
+
)
|
|
356
|
+
if command is not None:
|
|
357
|
+
commands.append(command)
|
|
358
|
+
elif isinstance(content, str):
|
|
359
|
+
description = str(metadata.get("description") or f"Plugin command from {manifest.name}").strip()
|
|
360
|
+
commands.append(
|
|
361
|
+
PluginCommandDefinition(
|
|
362
|
+
name=f"{manifest.name}:{command_name}",
|
|
363
|
+
description=description,
|
|
364
|
+
content=content.strip(),
|
|
365
|
+
source="plugin",
|
|
366
|
+
argument_hint=metadata.get("argumentHint"),
|
|
367
|
+
model=metadata.get("model"),
|
|
368
|
+
)
|
|
369
|
+
)
|
|
370
|
+
else:
|
|
371
|
+
for raw_path in _coerce_path_list(manifest_commands):
|
|
372
|
+
command_path = (path / raw_path).resolve()
|
|
373
|
+
if command_path.is_dir():
|
|
374
|
+
commands.extend(
|
|
375
|
+
_load_commands_from_directory(
|
|
376
|
+
command_path,
|
|
377
|
+
plugin_name=manifest.name,
|
|
378
|
+
seen=seen,
|
|
379
|
+
)
|
|
380
|
+
)
|
|
381
|
+
elif command_path.is_file() and command_path.suffix.lower() == ".md":
|
|
382
|
+
command = _load_single_command_file(
|
|
383
|
+
command_path,
|
|
384
|
+
command_name=f"{manifest.name}:{command_path.stem}",
|
|
385
|
+
metadata_override=None,
|
|
386
|
+
seen=seen,
|
|
387
|
+
)
|
|
388
|
+
if command is not None:
|
|
389
|
+
commands.append(command)
|
|
390
|
+
return commands
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def _load_commands_from_directory(
|
|
394
|
+
directory: Path,
|
|
395
|
+
*,
|
|
396
|
+
plugin_name: str,
|
|
397
|
+
seen: set[Path],
|
|
398
|
+
) -> list[PluginCommandDefinition]:
|
|
399
|
+
if not directory.exists():
|
|
400
|
+
return []
|
|
401
|
+
raw_files = _walk_plugin_markdown(directory, stop_at_skill_dir=True)
|
|
402
|
+
files = _transform_command_files(raw_files)
|
|
403
|
+
commands: list[PluginCommandDefinition] = []
|
|
404
|
+
for file_path in files:
|
|
405
|
+
command_name = _command_name_from_file(file_path, directory, plugin_name)
|
|
406
|
+
command = _load_single_command_file(
|
|
407
|
+
file_path,
|
|
408
|
+
command_name=command_name,
|
|
409
|
+
metadata_override=None,
|
|
410
|
+
seen=seen,
|
|
411
|
+
)
|
|
412
|
+
if command is not None:
|
|
413
|
+
if file_path.name.lower() == "skill.md":
|
|
414
|
+
command = PluginCommandDefinition(
|
|
415
|
+
**{
|
|
416
|
+
**command.__dict__,
|
|
417
|
+
"is_skill": True,
|
|
418
|
+
"base_dir": str(file_path.parent),
|
|
419
|
+
}
|
|
420
|
+
)
|
|
421
|
+
commands.append(command)
|
|
422
|
+
return commands
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
def _load_single_command_file(
|
|
426
|
+
file_path: Path,
|
|
427
|
+
*,
|
|
428
|
+
command_name: str,
|
|
429
|
+
metadata_override: dict[str, Any] | None,
|
|
430
|
+
seen: set[Path],
|
|
431
|
+
) -> PluginCommandDefinition | None:
|
|
432
|
+
if not file_path.exists():
|
|
433
|
+
return None
|
|
434
|
+
resolved = file_path.resolve()
|
|
435
|
+
if resolved in seen:
|
|
436
|
+
return None
|
|
437
|
+
seen.add(resolved)
|
|
438
|
+
content = file_path.read_text(encoding="utf-8")
|
|
439
|
+
frontmatter, body = _parse_frontmatter(content, file_path)
|
|
440
|
+
if metadata_override:
|
|
441
|
+
frontmatter = {
|
|
442
|
+
**frontmatter,
|
|
443
|
+
**{
|
|
444
|
+
"description": metadata_override.get("description", frontmatter.get("description")),
|
|
445
|
+
"argument-hint": metadata_override.get("argumentHint", frontmatter.get("argument-hint")),
|
|
446
|
+
"model": metadata_override.get("model", frontmatter.get("model")),
|
|
447
|
+
"allowed-tools": metadata_override.get("allowedTools", frontmatter.get("allowed-tools")),
|
|
448
|
+
},
|
|
449
|
+
}
|
|
450
|
+
description = _extract_description(frontmatter, body, fallback=f"Plugin command from {command_name}")
|
|
451
|
+
display_name = frontmatter.get("name")
|
|
452
|
+
argument_hint = frontmatter.get("argument-hint")
|
|
453
|
+
when_to_use = frontmatter.get("when_to_use")
|
|
454
|
+
version = frontmatter.get("version")
|
|
455
|
+
model = frontmatter.get("model")
|
|
456
|
+
effort = frontmatter.get("effort")
|
|
457
|
+
disable_model_invocation = bool(frontmatter.get("disable-model-invocation", False))
|
|
458
|
+
user_invocable_raw = frontmatter.get("user-invocable")
|
|
459
|
+
user_invocable = True if user_invocable_raw is None else bool(user_invocable_raw)
|
|
460
|
+
return PluginCommandDefinition(
|
|
461
|
+
name=command_name,
|
|
462
|
+
description=description,
|
|
463
|
+
content=body,
|
|
464
|
+
path=str(file_path),
|
|
465
|
+
source="plugin",
|
|
466
|
+
base_dir=str(file_path.parent),
|
|
467
|
+
argument_hint=str(argument_hint) if isinstance(argument_hint, str) else None,
|
|
468
|
+
when_to_use=str(when_to_use) if isinstance(when_to_use, str) else None,
|
|
469
|
+
version=str(version) if isinstance(version, str) else None,
|
|
470
|
+
model=str(model) if isinstance(model, str) else None,
|
|
471
|
+
effort=effort if isinstance(effort, (str, int)) else None,
|
|
472
|
+
disable_model_invocation=disable_model_invocation,
|
|
473
|
+
user_invocable=user_invocable,
|
|
474
|
+
is_skill=file_path.name.lower() == "skill.md",
|
|
475
|
+
display_name=str(display_name) if isinstance(display_name, str) else None,
|
|
476
|
+
)
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def _load_plugin_agents(path: Path, manifest: PluginManifest) -> list[AgentDefinition]:
|
|
480
|
+
agents: list[AgentDefinition] = []
|
|
481
|
+
seen: set[Path] = set()
|
|
482
|
+
default_agents_dir = path / "agents"
|
|
483
|
+
agents.extend(_load_agents_from_directory(default_agents_dir, plugin_name=manifest.name, seen=seen))
|
|
484
|
+
for raw_path in _coerce_path_list(manifest.agents):
|
|
485
|
+
agent_path = (path / raw_path).resolve()
|
|
486
|
+
if agent_path.is_dir():
|
|
487
|
+
agents.extend(_load_agents_from_directory(agent_path, plugin_name=manifest.name, seen=seen))
|
|
488
|
+
elif agent_path.is_file() and agent_path.suffix.lower() == ".md":
|
|
489
|
+
agent = _load_single_agent_file(agent_path, plugin_name=manifest.name, namespace=(), seen=seen)
|
|
490
|
+
if agent is not None:
|
|
491
|
+
agents.append(agent)
|
|
492
|
+
return agents
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
def _load_agents_from_directory(
|
|
496
|
+
directory: Path,
|
|
497
|
+
*,
|
|
498
|
+
plugin_name: str,
|
|
499
|
+
seen: set[Path],
|
|
500
|
+
) -> list[AgentDefinition]:
|
|
501
|
+
if not directory.exists():
|
|
502
|
+
return []
|
|
503
|
+
agents: list[AgentDefinition] = []
|
|
504
|
+
for file_path in _walk_plugin_markdown(directory, stop_at_skill_dir=False):
|
|
505
|
+
namespace = file_path.relative_to(directory).parts[:-1]
|
|
506
|
+
agent = _load_single_agent_file(
|
|
507
|
+
file_path,
|
|
508
|
+
plugin_name=plugin_name,
|
|
509
|
+
namespace=namespace,
|
|
510
|
+
seen=seen,
|
|
511
|
+
)
|
|
512
|
+
if agent is not None:
|
|
513
|
+
agents.append(agent)
|
|
514
|
+
return agents
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
def _load_single_agent_file(
|
|
518
|
+
file_path: Path,
|
|
519
|
+
*,
|
|
520
|
+
plugin_name: str,
|
|
521
|
+
namespace: tuple[str, ...],
|
|
522
|
+
seen: set[Path],
|
|
523
|
+
) -> AgentDefinition | None:
|
|
524
|
+
if not file_path.exists():
|
|
525
|
+
return None
|
|
526
|
+
resolved = file_path.resolve()
|
|
527
|
+
if resolved in seen:
|
|
528
|
+
return None
|
|
529
|
+
seen.add(resolved)
|
|
530
|
+
content = file_path.read_text(encoding="utf-8")
|
|
531
|
+
frontmatter, body = _parse_agent_frontmatter(content)
|
|
532
|
+
|
|
533
|
+
base_agent_name = str(frontmatter.get("name", "")).strip() or file_path.stem
|
|
534
|
+
agent_name = ":".join([plugin_name, *namespace, base_agent_name])
|
|
535
|
+
description = str(frontmatter.get("description", "")).strip() or f"Agent from {plugin_name} plugin"
|
|
536
|
+
description = description.replace("\\n", "\n")
|
|
537
|
+
|
|
538
|
+
tools = _parse_str_list(frontmatter.get("tools"))
|
|
539
|
+
disallowed_raw = frontmatter.get("disallowedTools", frontmatter.get("disallowed_tools"))
|
|
540
|
+
disallowed_tools = _parse_str_list(disallowed_raw)
|
|
541
|
+
|
|
542
|
+
model_raw = frontmatter.get("model")
|
|
543
|
+
model: str | None = None
|
|
544
|
+
if isinstance(model_raw, str) and model_raw.strip():
|
|
545
|
+
trimmed = model_raw.strip()
|
|
546
|
+
model = "inherit" if trimmed.lower() == "inherit" else trimmed
|
|
547
|
+
|
|
548
|
+
effort_raw = frontmatter.get("effort")
|
|
549
|
+
effort: str | int | None = None
|
|
550
|
+
if effort_raw is not None:
|
|
551
|
+
if isinstance(effort_raw, int):
|
|
552
|
+
effort = effort_raw if effort_raw > 0 else None
|
|
553
|
+
elif isinstance(effort_raw, str) and effort_raw in EFFORT_LEVELS:
|
|
554
|
+
effort = effort_raw
|
|
555
|
+
|
|
556
|
+
background_raw = frontmatter.get("background")
|
|
557
|
+
background = background_raw is True or background_raw == "true"
|
|
558
|
+
skills = _parse_str_list(frontmatter.get("skills")) or []
|
|
559
|
+
|
|
560
|
+
color_raw = frontmatter.get("color")
|
|
561
|
+
color = color_raw if isinstance(color_raw, str) and color_raw in AGENT_COLORS else None
|
|
562
|
+
|
|
563
|
+
memory_raw = frontmatter.get("memory")
|
|
564
|
+
memory = memory_raw if isinstance(memory_raw, str) and memory_raw in MEMORY_SCOPES else None
|
|
565
|
+
|
|
566
|
+
isolation_raw = frontmatter.get("isolation")
|
|
567
|
+
isolation = isolation_raw if isinstance(isolation_raw, str) and isolation_raw in ISOLATION_MODES else None
|
|
568
|
+
|
|
569
|
+
max_turns_raw = frontmatter.get("maxTurns", frontmatter.get("max_turns"))
|
|
570
|
+
max_turns = _parse_positive_int(max_turns_raw)
|
|
571
|
+
|
|
572
|
+
permission_raw = frontmatter.get("permissionMode", frontmatter.get("permission_mode"))
|
|
573
|
+
permission_mode = (
|
|
574
|
+
permission_raw if isinstance(permission_raw, str) and permission_raw in PERMISSION_MODES else None
|
|
575
|
+
)
|
|
576
|
+
|
|
577
|
+
initial_prompt_raw = frontmatter.get("initialPrompt", frontmatter.get("initial_prompt"))
|
|
578
|
+
initial_prompt = initial_prompt_raw.strip() if isinstance(initial_prompt_raw, str) and initial_prompt_raw.strip() else None
|
|
579
|
+
|
|
580
|
+
critical_raw = frontmatter.get("criticalSystemReminder", frontmatter.get("critical_system_reminder"))
|
|
581
|
+
critical_system_reminder = critical_raw.strip() if isinstance(critical_raw, str) and critical_raw.strip() else None
|
|
582
|
+
|
|
583
|
+
required_mcp_servers = _parse_str_list(
|
|
584
|
+
frontmatter.get("requiredMcpServers", frontmatter.get("required_mcp_servers"))
|
|
585
|
+
)
|
|
586
|
+
|
|
587
|
+
permissions: list[str] = []
|
|
588
|
+
raw_permissions = frontmatter.get("permissions", "")
|
|
589
|
+
if raw_permissions:
|
|
590
|
+
permissions = [p.strip() for p in str(raw_permissions).split(",") if p.strip()]
|
|
591
|
+
|
|
592
|
+
return AgentDefinition(
|
|
593
|
+
name=agent_name,
|
|
594
|
+
description=description,
|
|
595
|
+
system_prompt=body or None,
|
|
596
|
+
tools=tools,
|
|
597
|
+
disallowed_tools=disallowed_tools,
|
|
598
|
+
model=model,
|
|
599
|
+
effort=effort,
|
|
600
|
+
permission_mode=permission_mode,
|
|
601
|
+
max_turns=max_turns,
|
|
602
|
+
skills=skills,
|
|
603
|
+
mcp_servers=None,
|
|
604
|
+
hooks=None,
|
|
605
|
+
color=color,
|
|
606
|
+
background=background,
|
|
607
|
+
initial_prompt=initial_prompt,
|
|
608
|
+
memory=memory,
|
|
609
|
+
isolation=isolation,
|
|
610
|
+
omit_claude_md=False,
|
|
611
|
+
critical_system_reminder=critical_system_reminder,
|
|
612
|
+
required_mcp_servers=required_mcp_servers,
|
|
613
|
+
permissions=permissions,
|
|
614
|
+
filename=base_agent_name,
|
|
615
|
+
base_dir=str(file_path.parent),
|
|
616
|
+
subagent_type=str(frontmatter.get("subagent_type", agent_name)),
|
|
617
|
+
source="plugin",
|
|
618
|
+
)
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
def _load_plugin_hooks(path: Path) -> dict[str, list]:
|
|
622
|
+
"""Load hooks from a flat hooks.json file."""
|
|
623
|
+
if not path.exists():
|
|
624
|
+
return {}
|
|
625
|
+
from openharness.hooks.schemas import (
|
|
626
|
+
AgentHookDefinition,
|
|
627
|
+
CommandHookDefinition,
|
|
628
|
+
HttpHookDefinition,
|
|
629
|
+
PromptHookDefinition,
|
|
630
|
+
)
|
|
631
|
+
|
|
632
|
+
raw = json.loads(path.read_text(encoding="utf-8"))
|
|
633
|
+
parsed: dict[str, list] = {}
|
|
634
|
+
for event, hooks in raw.items():
|
|
635
|
+
parsed[event] = []
|
|
636
|
+
for hook in hooks:
|
|
637
|
+
hook_type = hook.get("type")
|
|
638
|
+
if hook_type == "command":
|
|
639
|
+
parsed[event].append(CommandHookDefinition.model_validate(hook))
|
|
640
|
+
elif hook_type == "prompt":
|
|
641
|
+
parsed[event].append(PromptHookDefinition.model_validate(hook))
|
|
642
|
+
elif hook_type == "http":
|
|
643
|
+
parsed[event].append(HttpHookDefinition.model_validate(hook))
|
|
644
|
+
elif hook_type == "agent":
|
|
645
|
+
parsed[event].append(AgentHookDefinition.model_validate(hook))
|
|
646
|
+
return parsed
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
def _load_plugin_hooks_structured(path: Path, plugin_root: Path) -> dict[str, list]:
|
|
650
|
+
"""Load hooks from structured hooks.json format."""
|
|
651
|
+
if not path.exists():
|
|
652
|
+
return {}
|
|
653
|
+
try:
|
|
654
|
+
raw = json.loads(path.read_text(encoding="utf-8"))
|
|
655
|
+
except (json.JSONDecodeError, OSError):
|
|
656
|
+
return {}
|
|
657
|
+
hooks_data = raw.get("hooks", raw)
|
|
658
|
+
if not isinstance(hooks_data, dict):
|
|
659
|
+
return {}
|
|
660
|
+
parsed: dict[str, list] = {}
|
|
661
|
+
for event, entries in hooks_data.items():
|
|
662
|
+
if not isinstance(entries, list):
|
|
663
|
+
continue
|
|
664
|
+
parsed[event] = []
|
|
665
|
+
for entry in entries:
|
|
666
|
+
hook_list = entry.get("hooks", [])
|
|
667
|
+
matcher = entry.get("matcher", "")
|
|
668
|
+
for hook in hook_list:
|
|
669
|
+
cmd = hook.get("command", "")
|
|
670
|
+
cmd = cmd.replace("${CLAUDE_PLUGIN_ROOT}", str(plugin_root))
|
|
671
|
+
parsed[event].append({
|
|
672
|
+
"type": hook.get("type", "command"),
|
|
673
|
+
"command": cmd,
|
|
674
|
+
"matcher": matcher,
|
|
675
|
+
"timeout": hook.get("timeout"),
|
|
676
|
+
})
|
|
677
|
+
return parsed
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
def _load_plugin_mcp(path: Path) -> dict[str, object]:
|
|
681
|
+
"""Load MCP server configuration from a JSON file."""
|
|
682
|
+
if not path.exists():
|
|
683
|
+
return {}
|
|
684
|
+
from openharness.mcp.types import McpJsonConfig
|
|
685
|
+
|
|
686
|
+
raw = json.loads(path.read_text(encoding="utf-8"))
|
|
687
|
+
parsed = McpJsonConfig.model_validate(raw)
|
|
688
|
+
return parsed.mcpServers
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
def _load_plugin_tools(path: Path, manifest: PluginManifest) -> list:
|
|
692
|
+
"""Discover and instantiate BaseTool subclasses from a plugin's tools/ directory."""
|
|
693
|
+
from openharness.tools.base import BaseTool
|
|
694
|
+
|
|
695
|
+
tools_dir = path / manifest.tools_dir
|
|
696
|
+
if not tools_dir.is_dir():
|
|
697
|
+
return []
|
|
698
|
+
|
|
699
|
+
tools: list[BaseTool] = []
|
|
700
|
+
for py_file in sorted(tools_dir.glob("*.py")):
|
|
701
|
+
if py_file.name.startswith("_"):
|
|
702
|
+
continue
|
|
703
|
+
module_name = f"_plugin_tools_{manifest.name}_{py_file.stem}"
|
|
704
|
+
try:
|
|
705
|
+
spec = importlib.util.spec_from_file_location(module_name, py_file)
|
|
706
|
+
if spec is None or spec.loader is None:
|
|
707
|
+
continue
|
|
708
|
+
module = importlib.util.module_from_spec(spec)
|
|
709
|
+
sys.modules[module_name] = module
|
|
710
|
+
spec.loader.exec_module(module)
|
|
711
|
+
except Exception:
|
|
712
|
+
logger.debug("Failed to load plugin tool module %s", py_file, exc_info=True)
|
|
713
|
+
continue
|
|
714
|
+
|
|
715
|
+
for attr_name in dir(module):
|
|
716
|
+
attr = getattr(module, attr_name, None)
|
|
717
|
+
if (
|
|
718
|
+
isinstance(attr, type)
|
|
719
|
+
and issubclass(attr, BaseTool)
|
|
720
|
+
and attr is not BaseTool
|
|
721
|
+
and hasattr(attr, "name")
|
|
722
|
+
and hasattr(attr, "description")
|
|
723
|
+
):
|
|
724
|
+
try:
|
|
725
|
+
instance = attr()
|
|
726
|
+
tools.append(instance)
|
|
727
|
+
logger.debug("Loaded plugin tool: %s from %s", instance.name, py_file)
|
|
728
|
+
except Exception:
|
|
729
|
+
logger.debug("Failed to instantiate tool %s from %s", attr_name, py_file, exc_info=True)
|
|
730
|
+
return tools
|