foxclaw 0.1.0 → 0.1.3
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.
- package/README.md +54 -29
- package/bin/foxclaw.cjs +51 -0
- package/index.js +4 -10
- package/package.json +46 -38
- package/python/.dockerignore +35 -0
- package/python/.env.example +173 -0
- package/python/.gitattributes +46 -0
- package/python/.github/workflows/ci.yml +167 -0
- package/python/.github/workflows/release.yml +183 -0
- package/python/CHANGELOG.md +57 -0
- package/python/CHANGELOG_CN.md +57 -0
- package/python/Dockerfile +64 -0
- package/python/LICENSE +21 -0
- package/python/MANIFEST.in +14 -0
- package/python/README.md +201 -0
- package/python/README_CN.md +336 -0
- package/python/bench/bm25_audit.py +186 -0
- package/python/bench/bm25_regression.py +177 -0
- package/python/bench/bm25_stress.py +155 -0
- package/python/bench/cd_audit.py +215 -0
- package/python/bench/chaos.py +140 -0
- package/python/bench/concurrency.py +103 -0
- package/python/bench/e2e_real_models.py +94 -0
- package/python/bench/llm_retry_test.py +241 -0
- package/python/bench/load_test.py +193 -0
- package/python/bench/vector_ivf_upgrade.py +128 -0
- package/python/docs/CHANNELS.md +195 -0
- package/python/docs/GOVERNANCE.md +164 -0
- package/python/docs/RELEASE.md +110 -0
- package/python/docs/RUN.md +75 -0
- package/python/docs/RUN_CN.md +121 -0
- package/python/docs//351/205/215/347/275/256/346/214/207/345/215/227.md +152 -0
- package/python/evals/__init__.py +0 -0
- package/python/evals/governance/README.md +61 -0
- package/python/evals/governance/__init__.py +0 -0
- package/python/evals/governance/cases.py +115 -0
- package/python/evals/governance/compare_embeddings.py +94 -0
- package/python/evals/governance/convergence.svg +11 -0
- package/python/evals/governance/report.json +371 -0
- package/python/evals/governance/run_evals.py +368 -0
- package/python/examples/governance_middleware_demo.py +72 -0
- package/python/examples/langgraph_governance_demo.py +104 -0
- package/python/examples/sample_itinerary.csv +6 -0
- package/python/examples/sample_knowledge.csv +9 -0
- package/python/examples/sample_transactions.csv +14 -0
- package/python/foxclaw/__init__.py +408 -0
- package/python/foxclaw/agents/__init__.py +12 -0
- package/python/foxclaw/agents/agents.py +35 -0
- package/python/foxclaw/agents/base.py +794 -0
- package/python/foxclaw/agents/impl/__init__.py +1 -0
- package/python/foxclaw/agents/impl/_helpers.py +70 -0
- package/python/foxclaw/agents/impl/finance.py +231 -0
- package/python/foxclaw/agents/impl/office.py +350 -0
- package/python/foxclaw/agents/impl/supervisor.py +592 -0
- package/python/foxclaw/agents/mixins/_context.py +128 -0
- package/python/foxclaw/agents/mixins/augment.py +143 -0
- package/python/foxclaw/agents/mixins/llm.py +67 -0
- package/python/foxclaw/agents/mixins/memory.py +41 -0
- package/python/foxclaw/agents/mixins/preference.py +131 -0
- package/python/foxclaw/agents/mixins/prompt.py +71 -0
- package/python/foxclaw/agents/mixins/skillbox.py +58 -0
- package/python/foxclaw/agents/mixins/tool_exec.py +417 -0
- package/python/foxclaw/api/__init__.py +224 -0
- package/python/foxclaw/api/_state.py +43 -0
- package/python/foxclaw/api/bootstrap.py +96 -0
- package/python/foxclaw/api/middleware.py +294 -0
- package/python/foxclaw/api/routes/ahs.py +404 -0
- package/python/foxclaw/api/routes/attachments.py +116 -0
- package/python/foxclaw/api/routes/browser.py +35 -0
- package/python/foxclaw/api/routes/domain.py +306 -0
- package/python/foxclaw/api/routes/knowledge.py +145 -0
- package/python/foxclaw/api/routes/llm_admin.py +449 -0
- package/python/foxclaw/api/routes/memory.py +105 -0
- package/python/foxclaw/api/routes/orchestration.py +39 -0
- package/python/foxclaw/api/routes/recovery.py +44 -0
- package/python/foxclaw/api/routes/review.py +266 -0
- package/python/foxclaw/api/routes/search.py +33 -0
- package/python/foxclaw/api/routes/system.py +311 -0
- package/python/foxclaw/api/routes/task.py +263 -0
- package/python/foxclaw/api/routes/ws.py +64 -0
- package/python/foxclaw/api/spine.py +52 -0
- package/python/foxclaw/browser/__init__.py +13 -0
- package/python/foxclaw/browser/action/__init__.py +1 -0
- package/python/foxclaw/browser/action/action_executor.py +50 -0
- package/python/foxclaw/browser/action/action_types.py +44 -0
- package/python/foxclaw/browser/action/action_verifier.py +68 -0
- package/python/foxclaw/browser/action/url_policy.py +143 -0
- package/python/foxclaw/browser/adapter/__init__.py +1 -0
- package/python/foxclaw/browser/adapter/base_adapter.py +23 -0
- package/python/foxclaw/browser/adapter/web_adapter.py +46 -0
- package/python/foxclaw/browser/driver/__init__.py +1 -0
- package/python/foxclaw/browser/driver/base_driver.py +61 -0
- package/python/foxclaw/browser/driver/playwright_driver.py +170 -0
- package/python/foxclaw/browser/perception/__init__.py +1 -0
- package/python/foxclaw/browser/perception/dom_extractor.py +42 -0
- package/python/foxclaw/browser/perception/element_indexer.py +56 -0
- package/python/foxclaw/browser/perception/semantic_reducer.py +33 -0
- package/python/foxclaw/browser/perception/snapshot.py +29 -0
- package/python/foxclaw/browser/service.py +144 -0
- package/python/foxclaw/browser/session/__init__.py +1 -0
- package/python/foxclaw/browser/session/session_manager.py +57 -0
- package/python/foxclaw/capability/__init__.py +12 -0
- package/python/foxclaw/capability/embedding_service.py +65 -0
- package/python/foxclaw/channels/__init__.py +138 -0
- package/python/foxclaw/channels/discord.py +175 -0
- package/python/foxclaw/channels/dispatcher.py +179 -0
- package/python/foxclaw/channels/feishu.py +215 -0
- package/python/foxclaw/channels/openclaw_bridge.py +151 -0
- package/python/foxclaw/channels/signing.py +187 -0
- package/python/foxclaw/channels/telegram.py +120 -0
- package/python/foxclaw/channels/weixin.py +215 -0
- package/python/foxclaw/cli.py +183 -0
- package/python/foxclaw/cognitive/__init__.py +4 -0
- package/python/foxclaw/cognitive/reasoner.py +81 -0
- package/python/foxclaw/cognitive/state.py +141 -0
- package/python/foxclaw/core/__init__.py +9 -0
- package/python/foxclaw/core/audit_chain.py +131 -0
- package/python/foxclaw/core/audit_sink.py +100 -0
- package/python/foxclaw/core/compaction.py +265 -0
- package/python/foxclaw/core/config.py +65 -0
- package/python/foxclaw/core/confirm_nonce.py +151 -0
- package/python/foxclaw/core/dispatch.py +27 -0
- package/python/foxclaw/core/envfile.py +48 -0
- package/python/foxclaw/core/failure_policy.py +142 -0
- package/python/foxclaw/core/gateway.py +81 -0
- package/python/foxclaw/core/governance_audit.py +171 -0
- package/python/foxclaw/core/idempotency.py +282 -0
- package/python/foxclaw/core/injection_guard.py +202 -0
- package/python/foxclaw/core/memory_adapter.py +489 -0
- package/python/foxclaw/core/metrics.py +88 -0
- package/python/foxclaw/core/model_router.py +985 -0
- package/python/foxclaw/core/paths.py +103 -0
- package/python/foxclaw/core/recovery.py +349 -0
- package/python/foxclaw/core/scheduler.py +141 -0
- package/python/foxclaw/core/secrets.py +131 -0
- package/python/foxclaw/core/sessions.py +155 -0
- package/python/foxclaw/core/settings.py +414 -0
- package/python/foxclaw/core/shared_write.py +186 -0
- package/python/foxclaw/core/steering_queue.py +154 -0
- package/python/foxclaw/core/system_bus.py +84 -0
- package/python/foxclaw/core/thought_chain.py +316 -0
- package/python/foxclaw/core/token_meter.py +231 -0
- package/python/foxclaw/core/tools.py +164 -0
- package/python/foxclaw/core/tracing.py +375 -0
- package/python/foxclaw/core/truth_pipeline.py +110 -0
- package/python/foxclaw/core/update_check.py +149 -0
- package/python/foxclaw/core/vec_recall_adapter.py +477 -0
- package/python/foxclaw/core/verify.py +173 -0
- package/python/foxclaw/core/web_search.py +218 -0
- package/python/foxclaw/finance/__init__.py +15 -0
- package/python/foxclaw/finance/evidence.py +149 -0
- package/python/foxclaw/finance/fx.py +98 -0
- package/python/foxclaw/finance/graph.py +179 -0
- package/python/foxclaw/finance/models.py +146 -0
- package/python/foxclaw/finance/nlparse.py +515 -0
- package/python/foxclaw/finance/policy.py +301 -0
- package/python/foxclaw/finance/reasoner.py +121 -0
- package/python/foxclaw/finance/reasoning.py +319 -0
- package/python/foxclaw/finance/reconcile.py +175 -0
- package/python/foxclaw/finance/runtime.py +500 -0
- package/python/foxclaw/governance/__init__.py +24 -0
- package/python/foxclaw/governance/middleware.py +176 -0
- package/python/foxclaw/harness/__init__.py +17 -0
- package/python/foxclaw/harness/_base.py +66 -0
- package/python/foxclaw/harness/_policy.py +340 -0
- package/python/foxclaw/harness/drift.py +77 -0
- package/python/foxclaw/harness/event_bus.py +28 -0
- package/python/foxclaw/harness/harness.py +358 -0
- package/python/foxclaw/harness/loop_detection.py +145 -0
- package/python/foxclaw/itinerary/__init__.py +10 -0
- package/python/foxclaw/itinerary/amap_client.py +114 -0
- package/python/foxclaw/itinerary/models.py +80 -0
- package/python/foxclaw/itinerary/reasoner.py +96 -0
- package/python/foxclaw/itinerary/reasoning.py +168 -0
- package/python/foxclaw/itinerary/runtime.py +144 -0
- package/python/foxclaw/kernel/__init__.py +13 -0
- package/python/foxclaw/kernel/capabilities.py +72 -0
- package/python/foxclaw/kernel/policy_gate.py +108 -0
- package/python/foxclaw/kernel/process_manager.py +186 -0
- package/python/foxclaw/kernel/scheduler.py +125 -0
- package/python/foxclaw/kernel/sentinel.py +443 -0
- package/python/foxclaw/kernel/sentinel_client.py +243 -0
- package/python/foxclaw/kernel/spine.py +97 -0
- package/python/foxclaw/knowledge/__init__.py +360 -0
- package/python/foxclaw/knowledge/truth_crystallizer.py +89 -0
- package/python/foxclaw/learning/__init__.py +12 -0
- package/python/foxclaw/learning/knowledge_graph.py +144 -0
- package/python/foxclaw/learning/models.py +93 -0
- package/python/foxclaw/learning/reasoner.py +67 -0
- package/python/foxclaw/learning/runtime.py +351 -0
- package/python/foxclaw/learning/spaced_repetition.py +91 -0
- package/python/foxclaw/mcp_server.py +188 -0
- package/python/foxclaw/orchestration/__init__.py +167 -0
- package/python/foxclaw/pipeline/__init__.py +23 -0
- package/python/foxclaw/pipeline/cognitive_pipeline.py +429 -0
- package/python/foxclaw/pipeline/stage_meta.py +21 -0
- package/python/foxclaw/pipeline/supervisor_stages.py +201 -0
- package/python/foxclaw/planning/__init__.py +17 -0
- package/python/foxclaw/planning/llm_planner.py +232 -0
- package/python/foxclaw/planning/planner.py +94 -0
- package/python/foxclaw/search/__init__.py +24 -0
- package/python/foxclaw/search/agent_port.py +190 -0
- package/python/foxclaw/search/evidence.py +109 -0
- package/python/foxclaw/search/external_search.py +50 -0
- package/python/foxclaw/search/hkc_read_port.py +60 -0
- package/python/foxclaw/search/internal_search.py +71 -0
- package/python/foxclaw/search/models.py +127 -0
- package/python/foxclaw/search/planner.py +44 -0
- package/python/foxclaw/search/retriever.py +39 -0
- package/python/foxclaw/search/runtime.py +127 -0
- package/python/foxclaw/search/strategy.py +44 -0
- package/python/foxclaw/skills/__init__.py +559 -0
- package/python/foxclaw/skills/archive.py +111 -0
- package/python/foxclaw/skills/fetch.py +226 -0
- package/python/foxclaw/skills/hooks_spec.py +69 -0
- package/python/foxclaw/skills/install_cmd.py +216 -0
- package/python/foxclaw/skills/lifecycle.py +252 -0
- package/python/foxclaw/skills/markdown_skill.py +175 -0
- package/python/foxclaw/skills/markdown_store.py +39 -0
- package/python/foxclaw/skills/mcp_client.py +184 -0
- package/python/foxclaw/skills/mcp_store.py +40 -0
- package/python/foxclaw/skills/permission.py +145 -0
- package/python/foxclaw/skills/pipeline.py +354 -0
- package/python/foxclaw/skills/policy.py +74 -0
- package/python/foxclaw/skills/review.py +72 -0
- package/python/foxclaw/skills/store.py +57 -0
- package/python/frontend/assets/core_bg.jpg +0 -0
- package/python/frontend/deck/auth.js +25 -0
- package/python/frontend/deck/chat_model_picker.js +483 -0
- package/python/frontend/deck/domain.js +276 -0
- package/python/frontend/deck/main.js +1806 -0
- package/python/frontend/deck/markdown.js +44 -0
- package/python/frontend/deck/settings.js +307 -0
- package/python/frontend/deck/state.js +5 -0
- package/python/frontend/deck/util.js +4 -0
- package/python/frontend/deck/visuals.js +190 -0
- package/python/frontend/deck.css +855 -0
- package/python/frontend/deck.html +686 -0
- package/python/frontend/deck_v2.html +341 -0
- package/python/frontend/planet/index.html +266 -0
- package/python/frontend/planet/planet.css +579 -0
- package/python/frontend/planet/planet.js +1436 -0
- package/python/frontend/planet/vendor/three.core.min.js +6 -0
- package/python/frontend/planet/vendor/three.module.min.js +6 -0
- package/python/frontend/v3/assets/index-CQSBdxk4.js +34 -0
- package/python/frontend/v3/assets/index-D5nIsjms.css +1 -0
- package/python/frontend/v3/index.html +15 -0
- package/python/frontend/widget_runtime.js +252 -0
- package/python/frontend/widgets.js +639 -0
- package/python/frontend_src/index.html +14 -0
- package/python/frontend_src/package-lock.json +1376 -0
- package/python/frontend_src/package.json +19 -0
- package/python/frontend_src/src/App.vue +58 -0
- package/python/frontend_src/src/api.js +82 -0
- package/python/frontend_src/src/components/ChatDock.vue +365 -0
- package/python/frontend_src/src/components/ComposerMenu.vue +75 -0
- package/python/frontend_src/src/components/DocViewer.vue +162 -0
- package/python/frontend_src/src/components/Inspector.vue +235 -0
- package/python/frontend_src/src/components/LeftRail.vue +415 -0
- package/python/frontend_src/src/components/MenuPopover.vue +128 -0
- package/python/frontend_src/src/components/MessageStream.vue +389 -0
- package/python/frontend_src/src/components/ModelPicker.vue +350 -0
- package/python/frontend_src/src/components/QuickIngest.vue +112 -0
- package/python/frontend_src/src/components/Stage.vue +272 -0
- package/python/frontend_src/src/components/ToolMenu.vue +141 -0
- package/python/frontend_src/src/components/TopBar.vue +118 -0
- package/python/frontend_src/src/components/panels/ActivityPanel.vue +82 -0
- package/python/frontend_src/src/components/panels/AgentsPanel.vue +83 -0
- package/python/frontend_src/src/components/panels/KnowledgePanel.vue +425 -0
- package/python/frontend_src/src/components/panels/MemoryPanel.vue +117 -0
- package/python/frontend_src/src/components/panels/PanelBox.vue +50 -0
- package/python/frontend_src/src/components/panels/ReviewPanel.vue +292 -0
- package/python/frontend_src/src/components/panels/SettingsPanel.vue +358 -0
- package/python/frontend_src/src/components/panels/TasksPanel.vue +73 -0
- package/python/frontend_src/src/components/panels/ToolsPanel.vue +746 -0
- package/python/frontend_src/src/components/panels/UsagePanel.vue +105 -0
- package/python/frontend_src/src/lib/fmt.js +44 -0
- package/python/frontend_src/src/lib/i18n.js +53 -0
- package/python/frontend_src/src/lib/locales/en.js +173 -0
- package/python/frontend_src/src/lib/locales/zh.js +174 -0
- package/python/frontend_src/src/lib/md.js +190 -0
- package/python/frontend_src/src/main.js +9 -0
- package/python/frontend_src/src/stores/app.js +91 -0
- package/python/frontend_src/src/stores/chat.js +450 -0
- package/python/frontend_src/src/stores/model.js +96 -0
- package/python/frontend_src/src/stores/panels.js +289 -0
- package/python/frontend_src/src/stores/profile.js +31 -0
- package/python/frontend_src/src/stores/system.js +25 -0
- package/python/frontend_src/src/styles/base.css +138 -0
- package/python/frontend_src/src/styles/panel.css +117 -0
- package/python/frontend_src/src/styles/tokens.css +78 -0
- package/python/frontend_src/vite.config.js +39 -0
- package/python/pyproject.toml +268 -0
- package/python/requirements.txt +311 -0
- package/python/skills/README.md +123 -0
- package/python/skills/execution-contract/SKILL.md +30 -0
- package/python/skills/general-assistant/SKILL.md +34 -0
- package/python/skills/planner/SKILL.md +33 -0
- package/python/skills/schedule-itinerary/SKILL.md +35 -0
- package/python/skills/skill-composition/SKILL.md +31 -0
- package/python/skills/skill-guard/SKILL.md +67 -0
- package/python/skills/skill-memory/SKILL.md +50 -0
- package/python/skills/skill-router/SKILL.md +35 -0
- package/python/tests/conftest.py +54 -0
- package/python/tests/run_all.py +200 -0
- package/python/tests/test_agent_lifecycle.py +326 -0
- package/python/tests/test_ahs_p2.py +393 -0
- package/python/tests/test_anthropic_tools.py +192 -0
- package/python/tests/test_api.py +97 -0
- package/python/tests/test_api_auth.py +79 -0
- package/python/tests/test_api_host_guard.py +69 -0
- package/python/tests/test_attachments.py +151 -0
- package/python/tests/test_audit_chain.py +116 -0
- package/python/tests/test_audit_sink.py +130 -0
- package/python/tests/test_browser.py +149 -0
- package/python/tests/test_browser_request_guard.py +180 -0
- package/python/tests/test_capabilities.py +152 -0
- package/python/tests/test_channel_signing.py +185 -0
- package/python/tests/test_channel_trust.py +109 -0
- package/python/tests/test_channels.py +174 -0
- package/python/tests/test_cli.py +46 -0
- package/python/tests/test_compaction_toolpair.py +119 -0
- package/python/tests/test_config_layering.py +61 -0
- package/python/tests/test_confirm_nonce.py +186 -0
- package/python/tests/test_context_compaction_wiring.py +124 -0
- package/python/tests/test_dispatch.py +89 -0
- package/python/tests/test_domain_evals.py +334 -0
- package/python/tests/test_domain_import.py +72 -0
- package/python/tests/test_domain_reasoners.py +134 -0
- package/python/tests/test_e2e.py +161 -0
- package/python/tests/test_emb_cache.py +97 -0
- package/python/tests/test_embedding_singleton.py +87 -0
- package/python/tests/test_envfile.py +83 -0
- package/python/tests/test_evals_smoke.py +90 -0
- package/python/tests/test_event_spine.py +174 -0
- package/python/tests/test_evidence_semantic.py +88 -0
- package/python/tests/test_evidence_sse.py +94 -0
- package/python/tests/test_file_ingest.py +135 -0
- package/python/tests/test_finance.py +144 -0
- package/python/tests/test_finance_ledger.py +245 -0
- package/python/tests/test_finance_persist.py +174 -0
- package/python/tests/test_gateway.py +125 -0
- package/python/tests/test_governance.py +421 -0
- package/python/tests/test_governance_audit.py +324 -0
- package/python/tests/test_governance_middleware.py +137 -0
- package/python/tests/test_hkc.py +268 -0
- package/python/tests/test_hkc_index_build_manager.py +306 -0
- package/python/tests/test_hkc_manifest_reuse.py +294 -0
- package/python/tests/test_hkc_search_event_sync.py +482 -0
- package/python/tests/test_import_path_guard.py +155 -0
- package/python/tests/test_injection_guard.py +193 -0
- package/python/tests/test_integration.py +117 -0
- package/python/tests/test_itinerary.py +100 -0
- package/python/tests/test_kee_semantic.py +84 -0
- package/python/tests/test_kernel.py +212 -0
- package/python/tests/test_learning.py +101 -0
- package/python/tests/test_llm_admin.py +145 -0
- package/python/tests/test_llm_planner.py +344 -0
- package/python/tests/test_markdown_skills.py +62 -0
- package/python/tests/test_markdown_skills_openclaw.py +66 -0
- package/python/tests/test_mcp_connectors.py +97 -0
- package/python/tests/test_mcp_guardian_discovery.py +87 -0
- package/python/tests/test_mcp_no_memory.py +43 -0
- package/python/tests/test_mcp_policy_gate.py +76 -0
- package/python/tests/test_mcp_server.py +92 -0
- package/python/tests/test_memory_recall.py +92 -0
- package/python/tests/test_metrics.py +58 -0
- package/python/tests/test_multi_chain.py +90 -0
- package/python/tests/test_multimodal.py +122 -0
- package/python/tests/test_negotiation.py +136 -0
- package/python/tests/test_orchestration.py +109 -0
- package/python/tests/test_orchestration_decoupled.py +103 -0
- package/python/tests/test_p3_p5_hardening.py +324 -0
- package/python/tests/test_parallel_dispatch.py +207 -0
- package/python/tests/test_pipeline.py +492 -0
- package/python/tests/test_plan_visible.py +86 -0
- package/python/tests/test_planner.py +88 -0
- package/python/tests/test_policy_gate.py +108 -0
- package/python/tests/test_profile.py +67 -0
- package/python/tests/test_readme_claims.py +163 -0
- package/python/tests/test_reasoner.py +170 -0
- package/python/tests/test_release_check.py +252 -0
- package/python/tests/test_resume_checkpoint.py +148 -0
- package/python/tests/test_routing.py +85 -0
- package/python/tests/test_scheduler.py +138 -0
- package/python/tests/test_search.py +194 -0
- package/python/tests/test_secrets.py +153 -0
- package/python/tests/test_semantic.py +69 -0
- package/python/tests/test_sessions.py +90 -0
- package/python/tests/test_settings.py +265 -0
- package/python/tests/test_shadow_learning.py +290 -0
- package/python/tests/test_shared_write.py +200 -0
- package/python/tests/test_skill_taint_gate.py +145 -0
- package/python/tests/test_skills.py +117 -0
- package/python/tests/test_skills_fetch.py +282 -0
- package/python/tests/test_stats_and_events.py +162 -0
- package/python/tests/test_streaming.py +55 -0
- package/python/tests/test_supervisor_pipeline.py +176 -0
- package/python/tests/test_supervisor_triage.py +102 -0
- package/python/tests/test_taint.py +112 -0
- package/python/tests/test_task_stream.py +74 -0
- package/python/tests/test_thinking_sse.py +66 -0
- package/python/tests/test_thinking_stream.py +76 -0
- package/python/tests/test_tool_center.py +113 -0
- package/python/tests/test_tool_parallel.py +113 -0
- package/python/tests/test_tool_params.py +99 -0
- package/python/tests/test_tool_use.py +229 -0
- package/python/tests/test_toplevel_concurrency.py +116 -0
- package/python/tests/test_tracing.py +256 -0
- package/python/tests/test_truth_crystallizer.py +125 -0
- package/python/tests/test_truth_flow.py +88 -0
- package/python/tests/test_update_check.py +95 -0
- package/python/tests/test_url_policy.py +53 -0
- package/python/tests/test_verify_evidence.py +212 -0
- package/python/tests/test_version_sync.py +100 -0
- package/python/tests/test_web_trigger.py +82 -0
- package/python/tools/check_faiss_type.py +30 -0
- package/python/tools/check_log.ps1 +38 -0
- package/python/tools/ivf_status.py +72 -0
- package/python/tools/mypy_baseline.txt +13 -0
- package/python/tools/mypy_ratchet.py +143 -0
- package/python/tools/pack.py +173 -0
- package/python/tools/release_check.py +349 -0
- package/python/tools/restart_foxclaw.ps1 +71 -0
- package/python/tools/shared_write_audit.py +190 -0
- package/python/tools/size_baseline.txt +28 -0
- package/python/tools/size_check.py +102 -0
- package/python/tools/strip_comments.py +228 -0
- package/python/tools/verify_env.bat +2 -0
- package/python/tools/verify_env.py +25 -0
- package/python/vendor/HMR_LICENSE +37 -0
- package/python/vendor/HMR_README.md +65 -0
- package/python/vendor/hkc/LICENSE +37 -0
- package/python/vendor/hkc/hkc_ace/__init__.py +0 -0
- package/python/vendor/hkc/hkc_ace/ace.py +457 -0
- package/python/vendor/hkc/hkc_ace/skill_taxonomy.json +465 -0
- package/python/vendor/hkc/hkc_api/__init__.py +0 -0
- package/python/vendor/hkc/hkc_api/container.py +416 -0
- package/python/vendor/hkc/hkc_api/ingest_jobs.py +103 -0
- package/python/vendor/hkc/hkc_api/main.py +157 -0
- package/python/vendor/hkc/hkc_api/routes/__init__.py +0 -0
- package/python/vendor/hkc/hkc_api/routes/ability.py +151 -0
- package/python/vendor/hkc/hkc_api/routes/config.py +51 -0
- package/python/vendor/hkc/hkc_api/routes/knowledge.py +630 -0
- package/python/vendor/hkc/hkc_api/routes/search.py +88 -0
- package/python/vendor/hkc/hkc_api/schemas.py +153 -0
- package/python/vendor/hkc/hkc_api/synthesis.py +179 -0
- package/python/vendor/hkc/hkc_core/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/graph/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/graph/base.py +188 -0
- package/python/vendor/hkc/hkc_core/graph/sqlite_store.py +789 -0
- package/python/vendor/hkc/hkc_core/models/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/models/enums.py +65 -0
- package/python/vendor/hkc/hkc_core/models/ku.py +307 -0
- package/python/vendor/hkc/hkc_core/utils/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/utils/id_gen.py +113 -0
- package/python/vendor/hkc/hkc_crystallizer/__init__.py +44 -0
- package/python/vendor/hkc/hkc_crystallizer/adapters.py +94 -0
- package/python/vendor/hkc/hkc_crystallizer/candidate.py +145 -0
- package/python/vendor/hkc/hkc_crystallizer/crystallizer.py +179 -0
- package/python/vendor/hkc/hkc_crystallizer/ingress.py +90 -0
- package/python/vendor/hkc/hkc_kde/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kde/chunker.py +197 -0
- package/python/vendor/hkc/hkc_kde/extractor.py +623 -0
- package/python/vendor/hkc/hkc_kde/kde.py +298 -0
- package/python/vendor/hkc/hkc_kde/loaders/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kde/loaders/ebook_loader.py +153 -0
- package/python/vendor/hkc/hkc_kde/loaders/office_loader.py +194 -0
- package/python/vendor/hkc/hkc_kde/loaders/pdf_loader.py +162 -0
- package/python/vendor/hkc/hkc_kde/loaders/text_loader.py +157 -0
- package/python/vendor/hkc/hkc_kde/loaders/web_loader.py +91 -0
- package/python/vendor/hkc/hkc_kde/models.py +74 -0
- package/python/vendor/hkc/hkc_kde/packager.py +329 -0
- package/python/vendor/hkc/hkc_kde/relation_disc.py +151 -0
- package/python/vendor/hkc/hkc_kee/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kee/dedup.py +227 -0
- package/python/vendor/hkc/hkc_kee/fingerprint.py +106 -0
- package/python/vendor/hkc/hkc_kee/kee.py +541 -0
- package/python/vendor/hkc/hkc_kep/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kep/event_bus.py +205 -0
- package/python/vendor/hkc/hkc_sdk/__init__.py +63 -0
- package/python/vendor/hkc/hkc_sdk/base.py +151 -0
- package/python/vendor/hkc/hkc_sdk/direct_client.py +153 -0
- package/python/vendor/hkc/hkc_sdk/exceptions.py +39 -0
- package/python/vendor/hkc/hkc_sdk/http_client.py +166 -0
- package/python/vendor/hkc/hkc_sdk/models.py +171 -0
- package/python/vendor/hkc/hkc_search/__init__.py +0 -0
- package/python/vendor/hkc/hkc_search/bm25.py +325 -0
- package/python/vendor/hkc/hkc_search/embedding_backends.py +374 -0
- package/python/vendor/hkc/hkc_search/graph_search.py +132 -0
- package/python/vendor/hkc/hkc_search/hybrid.py +331 -0
- package/python/vendor/hkc/hkc_search/index_build_manager.py +378 -0
- package/python/vendor/hkc/hkc_search/vector_search.py +484 -0
- package/python/vendor/hmr/__init__.py +0 -0
- package/python/vendor/hmr/core/__init__.py +0 -0
- package/python/vendor/hmr/core/hmr.py +684 -0
- package/python/vendor/hmr/core/models.py +310 -0
- package/python/vendor/hmr/engines/__init__.py +0 -0
- package/python/vendor/hmr/engines/evolution.py +710 -0
- package/python/vendor/hmr/engines/jit_compiler.py +472 -0
- package/python/vendor/hmr/engines/lifecycle.py +264 -0
- package/python/vendor/hmr/engines/policy.py +625 -0
- package/python/vendor/hmr/engines/recall.py +260 -0
- package/python/vendor/hmr/engines/runtime_state.py +158 -0
- package/python/vendor/hmr/engines/scheduler.py +323 -0
- package/python/vendor/hmr/engines/semantic.py +150 -0
- package/python/vendor/hmr/engines/temporal.py +261 -0
- package/python/vendor/hmr/engines/thought_chain.py +635 -0
- package/python/vendor/hmr/graph/__init__.py +0 -0
- package/python/vendor/hmr/graph/cwg.py +338 -0
- package/python/vendor/hmr/graph/memory_graph.py +530 -0
- package/python/vendor/hmr/storage/__init__.py +0 -0
- package/python/vendor/hmr/storage/memory_fs.py +300 -0
- package/python/vendor/hmr/storage/vector_store.py +520 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
"""AHS 执行链:技能安装/管理、MCP 接入、Markdown 指令技能、策略封杀、运行、断路器、钩子审计。
|
|
2
|
+
|
|
3
|
+
从 foxclaw/api.py 原样搬移(纯搬移,零行为变更)。共享 OS 实例经 `_api.current_os()`
|
|
4
|
+
晚绑定读取;路由用 `@app` 装饰器在 import 时注册。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import asyncio
|
|
8
|
+
import uuid
|
|
9
|
+
from typing import Optional, cast
|
|
10
|
+
|
|
11
|
+
from fastapi import HTTPException
|
|
12
|
+
from pydantic import BaseModel
|
|
13
|
+
|
|
14
|
+
import foxclaw.api as _api
|
|
15
|
+
from .. import app
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AHSRunPayload(BaseModel):
|
|
19
|
+
task: str
|
|
20
|
+
confirmed: bool = False
|
|
21
|
+
resume_state: Optional[dict] = None
|
|
22
|
+
confirm_nonce: str = ""
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@app.get("/api/ahs/skills")
|
|
26
|
+
async def ahs_list_skills():
|
|
27
|
+
"""列出注册的 skill(含信任分级 trust + 封杀标记 blocked)。"""
|
|
28
|
+
pol = _api.os_instance().skill_policy
|
|
29
|
+
out = _api.os_instance().skill_registry.catalog()
|
|
30
|
+
for s in out:
|
|
31
|
+
s["blocked"] = pol.is_blocked(s.get("id", ""))
|
|
32
|
+
return {"skills": out}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class PolicyDenyPayload(BaseModel):
|
|
36
|
+
id: str
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@app.get("/api/ahs/policy")
|
|
40
|
+
async def ahs_policy_get():
|
|
41
|
+
"""全局封杀策略快照(deny/allow)。"""
|
|
42
|
+
return _api.os_instance().skill_policy.snapshot()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@app.post("/api/ahs/policy/deny")
|
|
46
|
+
async def ahs_policy_deny(p: PolicyDenyPayload):
|
|
47
|
+
"""封杀一个技能 id(deny 压倒 enable,立即对所有执行/注入生效)。"""
|
|
48
|
+
_api.os_instance().skill_policy.deny(p.id)
|
|
49
|
+
return {"ok": True, "policy": _api.os_instance().skill_policy.snapshot()}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@app.delete("/api/ahs/policy/deny/{skill_id}")
|
|
53
|
+
async def ahs_policy_undeny(skill_id: str):
|
|
54
|
+
"""解封。E1:被 policy 层(管理员 FOXCLAW_POLICY_DENY / policy.json)锁定的技能运行时无法解封,
|
|
55
|
+
诚实返回 ok=False + 原因(不再假报成功);其余情况与改前一致(ok=True)。"""
|
|
56
|
+
_api.os_instance().skill_policy.undeny(skill_id)
|
|
57
|
+
snap = _api.os_instance().skill_policy.snapshot()
|
|
58
|
+
if skill_id in snap.get("policy_deny", []):
|
|
59
|
+
return {"ok": False,
|
|
60
|
+
"reason": f"「{skill_id}」被管理员策略(policy 层)锁定,运行时无法解封", "policy": snap}
|
|
61
|
+
return {"ok": True, "policy": snap}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class SkillInstallPayload(BaseModel):
|
|
65
|
+
id: str
|
|
66
|
+
name: str
|
|
67
|
+
description: str = ""
|
|
68
|
+
kind: str
|
|
69
|
+
triggers: list = []
|
|
70
|
+
side_effect: str = "write"
|
|
71
|
+
destructive: bool = False
|
|
72
|
+
external: bool = True
|
|
73
|
+
params: dict = {}
|
|
74
|
+
endpoint: str = ""
|
|
75
|
+
http_method: str = "GET"
|
|
76
|
+
http_headers: dict = {}
|
|
77
|
+
param_location: str = "auto"
|
|
78
|
+
allow_local: bool = False
|
|
79
|
+
timeout: float = 10.0
|
|
80
|
+
mcp_server: str = ""
|
|
81
|
+
mcp_tool: str = ""
|
|
82
|
+
acknowledged: bool = False
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class SkillPatchPayload(BaseModel):
|
|
86
|
+
enabled: bool
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class SkillTestPayload(BaseModel):
|
|
90
|
+
args: dict = {}
|
|
91
|
+
confirmed: bool = False
|
|
92
|
+
mode: str = "strict"
|
|
93
|
+
confirm_nonce: str = ""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
_SKILL_KINDS = {"web_api", "mcp"}
|
|
97
|
+
_SIDE_EFFECTS = {"read", "write", "send", "pay"}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _validate_install(p: "SkillInstallPayload"):
|
|
101
|
+
if p.kind not in _SKILL_KINDS:
|
|
102
|
+
raise HTTPException(400, "kind 只能是 web_api 或 mcp(不支持从界面安装本地代码技能)")
|
|
103
|
+
if p.side_effect not in _SIDE_EFFECTS:
|
|
104
|
+
raise HTTPException(400, "side_effect 非法")
|
|
105
|
+
if p.kind == "web_api":
|
|
106
|
+
if not (p.endpoint.startswith("http://") or p.endpoint.startswith("https://")):
|
|
107
|
+
raise HTTPException(400, "web_api 需合法 http(s) endpoint")
|
|
108
|
+
if p.kind == "mcp" and not (p.mcp_server and p.mcp_tool):
|
|
109
|
+
raise HTTPException(400, "mcp 需同时提供 mcp_server 与 mcp_tool")
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@app.post("/api/ahs/skills")
|
|
113
|
+
async def ahs_install_skill(p: SkillInstallPayload):
|
|
114
|
+
"""安装/注册一个 web_api|mcp 技能(过安装审核门 + 持久化)。同 id 覆盖更新。"""
|
|
115
|
+
_validate_install(p)
|
|
116
|
+
from foxclaw.skills import SideEffect, SkillKind, SkillSpec
|
|
117
|
+
from foxclaw.skills.review import review_install
|
|
118
|
+
reg = _api.os_instance().skill_registry
|
|
119
|
+
_existing = reg.get(p.id)
|
|
120
|
+
if _existing is not None and _existing.source == "builtin":
|
|
121
|
+
raise HTTPException(409, "该 id 属于内置技能,不能覆盖")
|
|
122
|
+
existed = _existing is not None
|
|
123
|
+
spec = SkillSpec(
|
|
124
|
+
id=p.id, name=p.name, description=p.description,
|
|
125
|
+
kind=cast(SkillKind, p.kind), triggers=list(p.triggers),
|
|
126
|
+
side_effect=cast(SideEffect, p.side_effect),
|
|
127
|
+
destructive=p.destructive, external=p.external, params=dict(p.params),
|
|
128
|
+
endpoint=p.endpoint, http_method=p.http_method, http_headers=dict(p.http_headers),
|
|
129
|
+
param_location=p.param_location, allow_local=p.allow_local, timeout=p.timeout,
|
|
130
|
+
mcp_server=p.mcp_server, mcp_tool=p.mcp_tool, source="user",
|
|
131
|
+
)
|
|
132
|
+
verdict = review_install(spec)
|
|
133
|
+
if verdict["verdict"] == "deny":
|
|
134
|
+
raise HTTPException(403, detail={"error": "install_denied", "reasons": verdict["reasons"]})
|
|
135
|
+
if verdict["verdict"] == "warn" and not p.acknowledged:
|
|
136
|
+
raise HTTPException(409, detail={"needs_ack": True, "warnings": verdict["warnings"]})
|
|
137
|
+
reg.register(spec)
|
|
138
|
+
_api.os_instance().skill_store.save(reg)
|
|
139
|
+
return {"ok": True, "skill": spec.to_dict(), "created": not existed, "warnings": verdict["warnings"]}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@app.patch("/api/ahs/skills/{skill_id}")
|
|
143
|
+
async def ahs_patch_skill(skill_id: str, p: SkillPatchPayload):
|
|
144
|
+
"""启停一个技能(内置/用户均可,持久化)。"""
|
|
145
|
+
reg = _api.os_instance().skill_registry
|
|
146
|
+
sp = reg.get(skill_id)
|
|
147
|
+
if sp is None:
|
|
148
|
+
raise HTTPException(404, "技能不存在")
|
|
149
|
+
sp.enabled = bool(p.enabled)
|
|
150
|
+
_api.os_instance().skill_store.save(reg)
|
|
151
|
+
return {"ok": True, "skill": sp.to_dict()}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@app.delete("/api/ahs/skills/{skill_id}")
|
|
155
|
+
async def ahs_delete_skill(skill_id: str):
|
|
156
|
+
"""删除用户安装的技能;内置技能不可删(只能停用)。"""
|
|
157
|
+
reg = _api.os_instance().skill_registry
|
|
158
|
+
sp = reg.get(skill_id)
|
|
159
|
+
if sp is None:
|
|
160
|
+
raise HTTPException(404, "技能不存在")
|
|
161
|
+
if sp.source == "builtin":
|
|
162
|
+
raise HTTPException(409, "内置技能不可删除,只能停用")
|
|
163
|
+
reg.unregister(skill_id)
|
|
164
|
+
_api.os_instance().skill_store.save(reg)
|
|
165
|
+
return {"ok": True}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
@app.post("/api/ahs/skills/{skill_id}/test")
|
|
169
|
+
async def ahs_test_skill(skill_id: str, p: SkillTestPayload):
|
|
170
|
+
"""单技能测试调用:走真实权限管线/断路器/SSRF。副作用未确认 → needs_confirmation。"""
|
|
171
|
+
reg = _api.os_instance().skill_registry
|
|
172
|
+
sp = reg.get(skill_id)
|
|
173
|
+
if sp is None:
|
|
174
|
+
raise HTTPException(404, "技能不存在")
|
|
175
|
+
res = await asyncio.to_thread(_api.os_instance().skill_adapter.invoke,
|
|
176
|
+
sp, p.args, p.confirmed, p.mode,
|
|
177
|
+
confirm_nonce=p.confirm_nonce)
|
|
178
|
+
return res.to_dict()
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class McpServerPayload(BaseModel):
|
|
182
|
+
id: str
|
|
183
|
+
name: str = ""
|
|
184
|
+
url: str
|
|
185
|
+
headers: dict = {}
|
|
186
|
+
transport: str = "streamable_http"
|
|
187
|
+
acknowledged: bool = False
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@app.post("/api/ahs/mcp/servers")
|
|
191
|
+
async def mcp_add_server(p: McpServerPayload):
|
|
192
|
+
"""接入一个远程 MCP server:审核→连接拉工具→批量注册 mcp 技能→持久化。"""
|
|
193
|
+
from foxclaw.skills.review import review_mcp_server
|
|
194
|
+
from foxclaw.skills.mcp_client import tool_to_spec
|
|
195
|
+
if p.transport not in ("streamable_http", "sse"):
|
|
196
|
+
raise HTTPException(400, "transport 只能是 streamable_http 或 sse")
|
|
197
|
+
if not (p.url.startswith("http://") or p.url.startswith("https://")):
|
|
198
|
+
raise HTTPException(400, "url 需为 http(s)")
|
|
199
|
+
verdict = review_mcp_server(p.url)
|
|
200
|
+
if verdict["verdict"] == "deny":
|
|
201
|
+
raise HTTPException(403, detail={"error": "install_denied", "reasons": verdict["reasons"]})
|
|
202
|
+
if verdict["verdict"] == "warn" and not p.acknowledged:
|
|
203
|
+
raise HTTPException(409, detail={"needs_ack": True, "warnings": verdict["warnings"]})
|
|
204
|
+
cfg = {"id": p.id, "name": p.name or p.id, "url": p.url,
|
|
205
|
+
"headers": dict(p.headers), "transport": p.transport}
|
|
206
|
+
sentinel = getattr(_api.current_os(), "sentinel", None)
|
|
207
|
+
try:
|
|
208
|
+
if sentinel is not None:
|
|
209
|
+
tools = await asyncio.to_thread(_api.os_instance().mcp_add_server_guardian, cfg)
|
|
210
|
+
else:
|
|
211
|
+
tools = await asyncio.to_thread(_api.os_instance().mcp_manager.add_server, cfg)
|
|
212
|
+
_api.os_instance().mcp_store.save(_api.os_instance().mcp_manager.servers())
|
|
213
|
+
except Exception as e:
|
|
214
|
+
raise HTTPException(502, f"连接 MCP server 失败: {e}")
|
|
215
|
+
reg = _api.os_instance().skill_registry
|
|
216
|
+
n = 0
|
|
217
|
+
for tool in tools:
|
|
218
|
+
reg.register(tool_to_spec(p.id, tool)); n += 1
|
|
219
|
+
_api.os_instance().skill_store.save(reg)
|
|
220
|
+
_api.os_instance().sync_mcp_servers_to_sentinel()
|
|
221
|
+
return {"ok": True, "server": {k: cfg[k] for k in ("id", "name", "url", "transport")},
|
|
222
|
+
"tools_registered": n, "warnings": verdict["warnings"]}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
@app.get("/api/ahs/mcp/servers")
|
|
226
|
+
async def mcp_list_servers():
|
|
227
|
+
"""列出已接入 MCP server(工具数由注册表派生,无需连接)。"""
|
|
228
|
+
reg = _api.os_instance().skill_registry
|
|
229
|
+
all_sk = reg.all_including_disabled()
|
|
230
|
+
out = []
|
|
231
|
+
for c in _api.os_instance().mcp_manager.servers():
|
|
232
|
+
tc = sum(1 for s in all_sk if s.kind == "mcp" and s.mcp_server == c["id"])
|
|
233
|
+
out.append({"id": c["id"], "name": c["name"], "url": c["url"],
|
|
234
|
+
"transport": c["transport"], "tool_count": tc})
|
|
235
|
+
return {"servers": out}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@app.delete("/api/ahs/mcp/servers/{server_id}")
|
|
239
|
+
async def mcp_remove_server(server_id: str):
|
|
240
|
+
"""移除 server + 其注册的所有 mcp 技能。"""
|
|
241
|
+
mgr = _api.os_instance().mcp_manager
|
|
242
|
+
if not mgr.remove_server(server_id):
|
|
243
|
+
raise HTTPException(404, "server 不存在")
|
|
244
|
+
reg = _api.os_instance().skill_registry
|
|
245
|
+
removed = [s.id for s in reg.all_including_disabled()
|
|
246
|
+
if s.kind == "mcp" and s.mcp_server == server_id]
|
|
247
|
+
for sid in removed:
|
|
248
|
+
reg.unregister(sid)
|
|
249
|
+
_api.os_instance().skill_store.save(reg)
|
|
250
|
+
_api.os_instance().mcp_store.save(mgr.servers())
|
|
251
|
+
_api.os_instance().sync_mcp_servers_to_sentinel()
|
|
252
|
+
return {"ok": True, "removed_skills": len(removed)}
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
@app.post("/api/ahs/mcp/servers/{server_id}/refresh")
|
|
256
|
+
async def mcp_refresh_server(server_id: str):
|
|
257
|
+
"""重连拉工具:新增/更新技能,删除已消失的工具技能。"""
|
|
258
|
+
from foxclaw.skills.mcp_client import tool_to_spec
|
|
259
|
+
mgr = _api.os_instance().mcp_manager
|
|
260
|
+
if not any(s["id"] == server_id for s in mgr.servers()):
|
|
261
|
+
raise HTTPException(404, "server 不存在")
|
|
262
|
+
sentinel = getattr(_api.current_os(), "sentinel", None)
|
|
263
|
+
try:
|
|
264
|
+
if sentinel is not None:
|
|
265
|
+
tools = await asyncio.to_thread(sentinel.mcp_list_tools, server_id)
|
|
266
|
+
else:
|
|
267
|
+
tools = await asyncio.to_thread(mgr.list_tools, server_id)
|
|
268
|
+
except Exception as e:
|
|
269
|
+
raise HTTPException(502, f"刷新失败: {e}")
|
|
270
|
+
reg = _api.os_instance().skill_registry
|
|
271
|
+
fresh = set()
|
|
272
|
+
for tool in tools:
|
|
273
|
+
spec = tool_to_spec(server_id, tool); reg.register(spec); fresh.add(spec.id)
|
|
274
|
+
for s in [s for s in reg.all_including_disabled()
|
|
275
|
+
if s.kind == "mcp" and s.mcp_server == server_id and s.id not in fresh]:
|
|
276
|
+
reg.unregister(s.id)
|
|
277
|
+
_api.os_instance().skill_store.save(reg)
|
|
278
|
+
return {"ok": True, "tools": len(fresh)}
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
class MdSkillPayload(BaseModel):
|
|
282
|
+
content: str = ""
|
|
283
|
+
package_b64: str = ""
|
|
284
|
+
id: str = ""
|
|
285
|
+
acknowledged: bool = False
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
class MdSkillPatchPayload(BaseModel):
|
|
289
|
+
enabled: bool | None = None
|
|
290
|
+
triggers: list | None = None
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
@app.post("/api/ahs/md-skills")
|
|
294
|
+
async def md_install(p: MdSkillPayload):
|
|
295
|
+
"""上传/注册一个 SKILL.md 指令技能(单 .md 文本 或 OpenClaw zip 包)。解析→审核→持久化。"""
|
|
296
|
+
from foxclaw.skills.markdown_skill import parse_skill_md, extract_skill_package
|
|
297
|
+
content, want_id, want_version = p.content, (p.id or None), ""
|
|
298
|
+
if p.package_b64:
|
|
299
|
+
import base64 as _b64
|
|
300
|
+
try:
|
|
301
|
+
content, meta = extract_skill_package(_b64.b64decode(p.package_b64))
|
|
302
|
+
except ValueError as e:
|
|
303
|
+
raise HTTPException(400, f"OpenClaw 包解析失败: {e}")
|
|
304
|
+
except Exception as e:
|
|
305
|
+
raise HTTPException(400, f"包解码失败: {e}")
|
|
306
|
+
want_id = want_id or (meta.get("slug") or None)
|
|
307
|
+
want_version = str(meta.get("version") or "")
|
|
308
|
+
try:
|
|
309
|
+
skill = parse_skill_md(content, id=want_id)
|
|
310
|
+
except ValueError as e:
|
|
311
|
+
raise HTTPException(400, f"SKILL.md 解析失败: {e}")
|
|
312
|
+
if want_version and not skill.version:
|
|
313
|
+
skill.version = want_version
|
|
314
|
+
if not p.acknowledged:
|
|
315
|
+
raise HTTPException(409, detail={"needs_ack": True, "warnings": [
|
|
316
|
+
"此技能会把内容注入你 AI 的提示词、影响其行为,仅从可信来源安装"]})
|
|
317
|
+
reg = _api.os_instance().md_skills
|
|
318
|
+
existed = reg.get(skill.id) is not None
|
|
319
|
+
reg.register(skill)
|
|
320
|
+
_api.os_instance().md_store.save(reg)
|
|
321
|
+
return {"ok": True, "skill": skill.to_meta(), "created": not existed}
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
@app.get("/api/ahs/md-skills")
|
|
325
|
+
async def md_list():
|
|
326
|
+
pol = _api.os_instance().skill_policy
|
|
327
|
+
out = _api.os_instance().md_skills.catalog()
|
|
328
|
+
for s in out:
|
|
329
|
+
s["blocked"] = pol.is_blocked(s.get("id", ""))
|
|
330
|
+
return {"skills": out}
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
@app.get("/api/ahs/md-skills/{skill_id}")
|
|
334
|
+
async def md_get(skill_id: str):
|
|
335
|
+
s = _api.os_instance().md_skills.get(skill_id)
|
|
336
|
+
if s is None:
|
|
337
|
+
raise HTTPException(404, "指令技能不存在")
|
|
338
|
+
return s.to_dict()
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
@app.patch("/api/ahs/md-skills/{skill_id}")
|
|
342
|
+
async def md_patch(skill_id: str, p: MdSkillPatchPayload):
|
|
343
|
+
reg = _api.os_instance().md_skills
|
|
344
|
+
s = reg.get(skill_id)
|
|
345
|
+
if s is None:
|
|
346
|
+
raise HTTPException(404, "指令技能不存在")
|
|
347
|
+
if p.enabled is not None:
|
|
348
|
+
s.enabled = bool(p.enabled)
|
|
349
|
+
if p.triggers is not None:
|
|
350
|
+
s.triggers = [str(t).strip() for t in p.triggers if str(t).strip()]
|
|
351
|
+
_api.os_instance().md_store.save(reg)
|
|
352
|
+
return {"ok": True, "skill": s.to_meta()}
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
@app.delete("/api/ahs/md-skills/{skill_id}")
|
|
356
|
+
async def md_delete(skill_id: str):
|
|
357
|
+
reg = _api.os_instance().md_skills
|
|
358
|
+
if reg.get(skill_id) is None:
|
|
359
|
+
raise HTTPException(404, "指令技能不存在")
|
|
360
|
+
reg.unregister(skill_id)
|
|
361
|
+
_api.os_instance().md_store.save(reg)
|
|
362
|
+
return {"ok": True}
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
@app.post("/api/ahs/run")
|
|
366
|
+
async def ahs_run(payload: AHSRunPayload):
|
|
367
|
+
"""跑一遍 AHS 执行链:router→planner→composition,全程过 guard+breaker+hooks。
|
|
368
|
+
【P3-2】用 run_async 把同步 compose 放到线程池,避免阻塞事件循环。
|
|
369
|
+
【P2-2】暴露 pending_confirmation/is_pending,供前端识别"待确认"并断点续跑
|
|
370
|
+
(确认后带 confirmed=True + resume_state 重发本接口)。
|
|
371
|
+
【P1】关键操作还需带 confirm_nonce(响应里的 pending_confirmation.confirm_nonce);
|
|
372
|
+
缺/错/过期 → 仍返回 pending_confirmation 并换发新码,不会执行。"""
|
|
373
|
+
from foxclaw.skills import set_loop_session, reset_loop_session
|
|
374
|
+
sid = (payload.resume_state or {}).get("task_id") or f"ahs_{uuid.uuid4().hex[:8]}"
|
|
375
|
+
token = set_loop_session(sid)
|
|
376
|
+
try:
|
|
377
|
+
res = await _api.os_instance().ahs_pipeline.run_async(
|
|
378
|
+
payload.task, confirmed=payload.confirmed,
|
|
379
|
+
resume_state=payload.resume_state,
|
|
380
|
+
confirm_nonce=payload.confirm_nonce)
|
|
381
|
+
return {
|
|
382
|
+
"task": res.task, "route": res.route, "plan": res.plan,
|
|
383
|
+
"composition": res.composition, "success": res.success,
|
|
384
|
+
"summary": res.summary,
|
|
385
|
+
"pending_confirmation": res.pending_confirmation,
|
|
386
|
+
"is_pending": res.is_pending,
|
|
387
|
+
}
|
|
388
|
+
except Exception as e:
|
|
389
|
+
return {"success": False, "summary": f"执行链异常: {e}"}
|
|
390
|
+
finally:
|
|
391
|
+
reset_loop_session(token)
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
@app.get("/api/ahs/breaker")
|
|
395
|
+
async def ahs_breaker_status():
|
|
396
|
+
"""断路器状态:各 skill 的失败计数与开闸情况。"""
|
|
397
|
+
br = _api.os_instance().skill_adapter.breaker
|
|
398
|
+
return {"breakers": {sid: br.status(sid) for sid in br._entries}}
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
@app.get("/api/ahs/hooks/audit")
|
|
402
|
+
async def ahs_hooks_audit():
|
|
403
|
+
"""钩子审计日志(最近 20 条)。"""
|
|
404
|
+
return {"audit": _api.os_instance().skill_adapter.hooks.recent_audit(20)}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""聊天附件:通用文件上传/下载(多模态渲染·步骤7)。
|
|
2
|
+
|
|
3
|
+
与「文件摄入知识库」(domain.py 的 import + HKC ingest)不同:这里是**聊天附件**——文件随问题
|
|
4
|
+
发给 LLM(文本类提取正文、其它降级为元数据提示),并在对话里以卡片渲染。图片多模态(images
|
|
5
|
+
base64)走既有 /chat/stream 的 images 通道,不经过这里。
|
|
6
|
+
|
|
7
|
+
安全铁律:
|
|
8
|
+
· 文件名只留 basename + 清洗非法字符,杜绝路径穿越;
|
|
9
|
+
· id 只认我们生成的 [A-Za-z0-9_-] 形态;
|
|
10
|
+
· 大小 / 文本提取长度均设上限(防超大 payload / 超长上下文);
|
|
11
|
+
· 附件落 `<data_dir>/attachments/`,下载按 id 定位,不信任客户端传路径。
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import re
|
|
16
|
+
import uuid
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
from fastapi import File, HTTPException, UploadFile
|
|
20
|
+
from fastapi.responses import FileResponse
|
|
21
|
+
|
|
22
|
+
import foxclaw.api as _api
|
|
23
|
+
from .. import app
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
_MAX_ATTACH_BYTES = 20 * 1024 * 1024
|
|
27
|
+
_MAX_TEXT_CHARS = 20000
|
|
28
|
+
_ID_RE = re.compile(r"^[A-Za-z0-9_-]{1,64}$")
|
|
29
|
+
|
|
30
|
+
_TEXT_EXTS = {
|
|
31
|
+
".txt", ".md", ".markdown", ".csv", ".json", ".yaml", ".yml", ".log",
|
|
32
|
+
".py", ".js", ".ts", ".html", ".css", ".xml", ".toml", ".ini", ".sh",
|
|
33
|
+
".go", ".rs", ".java", ".c", ".cpp", ".h", ".sql", ".rb", ".php",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _att_dir() -> Path:
|
|
38
|
+
d = Path(_api.os_instance().data_dir) / "attachments"
|
|
39
|
+
d.mkdir(parents=True, exist_ok=True)
|
|
40
|
+
return d
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _decode_text(data: bytes) -> str:
|
|
44
|
+
"""按常见编码尝试解码,失败返回空(降级)。"""
|
|
45
|
+
for enc in ("utf-8", "gbk", "utf-16"):
|
|
46
|
+
try:
|
|
47
|
+
return data.decode(enc)
|
|
48
|
+
except (UnicodeDecodeError, LookupError):
|
|
49
|
+
continue
|
|
50
|
+
return ""
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _extract_text(path: Path, name: str) -> str:
|
|
54
|
+
"""从上传的附件提取正文:文本类直接读、PDF 用 fitz、其它返回空(前端/LLM 降级为元数据提示)。"""
|
|
55
|
+
ext = Path(name).suffix.lower()
|
|
56
|
+
if ext in _TEXT_EXTS:
|
|
57
|
+
try:
|
|
58
|
+
return _decode_text(path.read_bytes())[:_MAX_TEXT_CHARS]
|
|
59
|
+
except Exception:
|
|
60
|
+
return ""
|
|
61
|
+
if ext == ".pdf":
|
|
62
|
+
try:
|
|
63
|
+
import fitz
|
|
64
|
+
except ImportError:
|
|
65
|
+
return ""
|
|
66
|
+
try:
|
|
67
|
+
doc = fitz.open(str(path))
|
|
68
|
+
try:
|
|
69
|
+
text = ""
|
|
70
|
+
for page in doc:
|
|
71
|
+
text += page.get_text()
|
|
72
|
+
if len(text) >= _MAX_TEXT_CHARS:
|
|
73
|
+
break
|
|
74
|
+
return text[:_MAX_TEXT_CHARS]
|
|
75
|
+
finally:
|
|
76
|
+
doc.close()
|
|
77
|
+
except Exception:
|
|
78
|
+
return ""
|
|
79
|
+
return ""
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@app.post("/api/upload")
|
|
83
|
+
async def upload_attachment(file: UploadFile = File(...)):
|
|
84
|
+
"""通用聊天附件上传:落盘 + 尽力提取正文,返回 {id,name,size,mime,url,text}。
|
|
85
|
+
text 为空表示不可提取(二进制/图片等),前端/LLM 降级为「文件名 + 元数据」提示。"""
|
|
86
|
+
raw_name = (file.filename or "attachment").strip()
|
|
87
|
+
name = Path(raw_name).name or "attachment"
|
|
88
|
+
data = await file.read()
|
|
89
|
+
if not data:
|
|
90
|
+
raise HTTPException(400, "空文件")
|
|
91
|
+
if len(data) > _MAX_ATTACH_BYTES:
|
|
92
|
+
raise HTTPException(413, f"文件过大({len(data) / 1048576:.1f}MB>{_MAX_ATTACH_BYTES // 1048576}MB)")
|
|
93
|
+
aid = uuid.uuid4().hex[:12]
|
|
94
|
+
safe_name = re.sub(r"[^A-Za-z0-9._\-]", "_", name)[:120] or "attachment"
|
|
95
|
+
dest = _att_dir() / f"{aid}_{safe_name}"
|
|
96
|
+
dest.write_bytes(data)
|
|
97
|
+
text = _extract_text(dest, name)
|
|
98
|
+
return {
|
|
99
|
+
"id": aid,
|
|
100
|
+
"name": name,
|
|
101
|
+
"size": len(data),
|
|
102
|
+
"mime": (file.content_type or "application/octet-stream").lower(),
|
|
103
|
+
"url": f"/api/attachments/{aid}",
|
|
104
|
+
"text": text,
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@app.get("/api/attachments/{aid}")
|
|
109
|
+
async def get_attachment(aid: str):
|
|
110
|
+
"""下载附件。id 只认自生成形态,路径穿越到此为止。"""
|
|
111
|
+
if not _ID_RE.fullmatch(aid or ""):
|
|
112
|
+
raise HTTPException(400, "非法附件 id")
|
|
113
|
+
d = _att_dir()
|
|
114
|
+
for p in d.glob(f"{aid}_*"):
|
|
115
|
+
return FileResponse(str(p), filename=p.name.split("_", 1)[1])
|
|
116
|
+
raise HTTPException(404, "附件不存在")
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""浏览器子系统(HIR-Browser)端点。
|
|
2
|
+
|
|
3
|
+
从 foxclaw/api.py 原样搬移(纯搬移,零行为变更)。共享 OS 实例经 `_api.current_os()`
|
|
4
|
+
晚绑定读取;路由用 `@app` 装饰器在 import 时注册。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel
|
|
8
|
+
|
|
9
|
+
import foxclaw.api as _api
|
|
10
|
+
from .. import app
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BrowserActPayload(BaseModel):
|
|
14
|
+
type: str
|
|
15
|
+
target: str | None = None
|
|
16
|
+
value: object | None = None
|
|
17
|
+
meta: dict = {}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@app.get("/api/browser/status")
|
|
21
|
+
async def browser_status():
|
|
22
|
+
"""浏览器子系统能力/会话状态(available/session_active/launch_error)。"""
|
|
23
|
+
return _api.os_instance().browser_service.status()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@app.get("/api/browser/perceive")
|
|
27
|
+
async def browser_perceive():
|
|
28
|
+
"""只感知当前页面语义结构(带编号的可交互元素 + 摘要),不改变页面。"""
|
|
29
|
+
return await _api.os_instance().browser_service.perceive()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@app.post("/api/browser/act")
|
|
33
|
+
async def browser_act(p: BrowserActPayload):
|
|
34
|
+
"""执行一个 Web 动作,返回校验后最新语义结构。"""
|
|
35
|
+
return await _api.os_instance().browser_service.act(p.model_dump())
|