foxclaw 0.1.0 → 0.1.2

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.
Files changed (495) hide show
  1. package/README.md +54 -29
  2. package/bin/foxclaw.cjs +51 -0
  3. package/index.js +11 -10
  4. package/package.json +46 -38
  5. package/python/.dockerignore +35 -0
  6. package/python/.env.example +165 -0
  7. package/python/.gitattributes +46 -0
  8. package/python/.github/workflows/ci.yml +122 -0
  9. package/python/.github/workflows/release.yml +183 -0
  10. package/python/Dockerfile +64 -0
  11. package/python/LICENSE +21 -0
  12. package/python/MANIFEST.in +14 -0
  13. package/python/README.md +192 -0
  14. package/python/README_CN.md +324 -0
  15. package/python/bench/bm25_audit.py +199 -0
  16. package/python/bench/bm25_regression.py +178 -0
  17. package/python/bench/bm25_stress.py +159 -0
  18. package/python/bench/cd_audit.py +238 -0
  19. package/python/bench/chaos.py +142 -0
  20. package/python/bench/concurrency.py +103 -0
  21. package/python/bench/e2e_real_models.py +95 -0
  22. package/python/bench/llm_retry_test.py +248 -0
  23. package/python/bench/load_test.py +196 -0
  24. package/python/bench/vector_ivf_upgrade.py +134 -0
  25. package/python/docs/CHANNELS.md +195 -0
  26. package/python/docs/GOVERNANCE.md +164 -0
  27. package/python/docs/RELEASE.md +109 -0
  28. package/python/docs/RUN.md +75 -0
  29. package/python/docs/RUN_CN.md +121 -0
  30. package/python/docs//351/205/215/347/275/256/346/214/207/345/215/227.md +152 -0
  31. package/python/evals/__init__.py +0 -0
  32. package/python/evals/governance/README.md +61 -0
  33. package/python/evals/governance/__init__.py +0 -0
  34. package/python/evals/governance/cases.py +152 -0
  35. package/python/evals/governance/compare_embeddings.py +94 -0
  36. package/python/evals/governance/convergence.svg +11 -0
  37. package/python/evals/governance/report.json +371 -0
  38. package/python/evals/governance/run_evals.py +400 -0
  39. package/python/examples/governance_middleware_demo.py +77 -0
  40. package/python/examples/langgraph_governance_demo.py +108 -0
  41. package/python/examples/sample_itinerary.csv +6 -0
  42. package/python/examples/sample_knowledge.csv +9 -0
  43. package/python/examples/sample_transactions.csv +14 -0
  44. package/python/foxclaw/__init__.py +526 -0
  45. package/python/foxclaw/agents/__init__.py +12 -0
  46. package/python/foxclaw/agents/agents.py +35 -0
  47. package/python/foxclaw/agents/base.py +865 -0
  48. package/python/foxclaw/agents/impl/__init__.py +1 -0
  49. package/python/foxclaw/agents/impl/_helpers.py +78 -0
  50. package/python/foxclaw/agents/impl/finance.py +248 -0
  51. package/python/foxclaw/agents/impl/office.py +367 -0
  52. package/python/foxclaw/agents/impl/supervisor.py +659 -0
  53. package/python/foxclaw/agents/mixins/_context.py +151 -0
  54. package/python/foxclaw/agents/mixins/augment.py +149 -0
  55. package/python/foxclaw/agents/mixins/llm.py +66 -0
  56. package/python/foxclaw/agents/mixins/memory.py +35 -0
  57. package/python/foxclaw/agents/mixins/preference.py +81 -0
  58. package/python/foxclaw/agents/mixins/prompt.py +77 -0
  59. package/python/foxclaw/agents/mixins/skillbox.py +58 -0
  60. package/python/foxclaw/agents/mixins/tool_exec.py +443 -0
  61. package/python/foxclaw/api/__init__.py +283 -0
  62. package/python/foxclaw/api/app.py +123 -0
  63. package/python/foxclaw/api/middleware.py +317 -0
  64. package/python/foxclaw/api/routes/ahs.py +417 -0
  65. package/python/foxclaw/api/routes/attachments.py +117 -0
  66. package/python/foxclaw/api/routes/browser.py +39 -0
  67. package/python/foxclaw/api/routes/domain.py +314 -0
  68. package/python/foxclaw/api/routes/knowledge.py +163 -0
  69. package/python/foxclaw/api/routes/llm_admin.py +461 -0
  70. package/python/foxclaw/api/routes/memory.py +89 -0
  71. package/python/foxclaw/api/routes/orchestration.py +41 -0
  72. package/python/foxclaw/api/routes/recovery.py +43 -0
  73. package/python/foxclaw/api/routes/review.py +275 -0
  74. package/python/foxclaw/api/routes/search.py +37 -0
  75. package/python/foxclaw/api/routes/system.py +327 -0
  76. package/python/foxclaw/api/routes/task.py +281 -0
  77. package/python/foxclaw/api/routes/ws.py +68 -0
  78. package/python/foxclaw/api/spine.py +55 -0
  79. package/python/foxclaw/browser/__init__.py +13 -0
  80. package/python/foxclaw/browser/action/__init__.py +1 -0
  81. package/python/foxclaw/browser/action/action_executor.py +54 -0
  82. package/python/foxclaw/browser/action/action_types.py +45 -0
  83. package/python/foxclaw/browser/action/action_verifier.py +68 -0
  84. package/python/foxclaw/browser/action/url_policy.py +147 -0
  85. package/python/foxclaw/browser/adapter/__init__.py +1 -0
  86. package/python/foxclaw/browser/adapter/base_adapter.py +23 -0
  87. package/python/foxclaw/browser/adapter/web_adapter.py +46 -0
  88. package/python/foxclaw/browser/driver/__init__.py +1 -0
  89. package/python/foxclaw/browser/driver/base_driver.py +61 -0
  90. package/python/foxclaw/browser/driver/playwright_driver.py +166 -0
  91. package/python/foxclaw/browser/perception/__init__.py +1 -0
  92. package/python/foxclaw/browser/perception/dom_extractor.py +43 -0
  93. package/python/foxclaw/browser/perception/element_indexer.py +57 -0
  94. package/python/foxclaw/browser/perception/semantic_reducer.py +33 -0
  95. package/python/foxclaw/browser/perception/snapshot.py +29 -0
  96. package/python/foxclaw/browser/service.py +148 -0
  97. package/python/foxclaw/browser/session/__init__.py +1 -0
  98. package/python/foxclaw/browser/session/session_manager.py +57 -0
  99. package/python/foxclaw/capability/__init__.py +12 -0
  100. package/python/foxclaw/capability/embedding_service.py +67 -0
  101. package/python/foxclaw/channels/__init__.py +140 -0
  102. package/python/foxclaw/channels/discord.py +184 -0
  103. package/python/foxclaw/channels/dispatcher.py +204 -0
  104. package/python/foxclaw/channels/feishu.py +225 -0
  105. package/python/foxclaw/channels/openclaw_bridge.py +156 -0
  106. package/python/foxclaw/channels/signing.py +187 -0
  107. package/python/foxclaw/channels/telegram.py +121 -0
  108. package/python/foxclaw/channels/weixin.py +225 -0
  109. package/python/foxclaw/cli.py +154 -0
  110. package/python/foxclaw/cognitive/__init__.py +4 -0
  111. package/python/foxclaw/cognitive/reasoner.py +82 -0
  112. package/python/foxclaw/cognitive/state.py +147 -0
  113. package/python/foxclaw/core/__init__.py +9 -0
  114. package/python/foxclaw/core/audit_chain.py +133 -0
  115. package/python/foxclaw/core/audit_sink.py +100 -0
  116. package/python/foxclaw/core/compaction.py +283 -0
  117. package/python/foxclaw/core/config.py +65 -0
  118. package/python/foxclaw/core/confirm_nonce.py +157 -0
  119. package/python/foxclaw/core/dispatch.py +27 -0
  120. package/python/foxclaw/core/envfile.py +48 -0
  121. package/python/foxclaw/core/failure_policy.py +151 -0
  122. package/python/foxclaw/core/gateway.py +85 -0
  123. package/python/foxclaw/core/governance_audit.py +175 -0
  124. package/python/foxclaw/core/idempotency.py +289 -0
  125. package/python/foxclaw/core/injection_guard.py +221 -0
  126. package/python/foxclaw/core/memory_adapter.py +516 -0
  127. package/python/foxclaw/core/metrics.py +89 -0
  128. package/python/foxclaw/core/model_router.py +1097 -0
  129. package/python/foxclaw/core/paths.py +103 -0
  130. package/python/foxclaw/core/recovery.py +362 -0
  131. package/python/foxclaw/core/scheduler.py +144 -0
  132. package/python/foxclaw/core/secrets.py +134 -0
  133. package/python/foxclaw/core/sessions.py +157 -0
  134. package/python/foxclaw/core/settings.py +430 -0
  135. package/python/foxclaw/core/shared_write.py +198 -0
  136. package/python/foxclaw/core/steering_queue.py +153 -0
  137. package/python/foxclaw/core/system_bus.py +84 -0
  138. package/python/foxclaw/core/thought_chain.py +318 -0
  139. package/python/foxclaw/core/token_meter.py +235 -0
  140. package/python/foxclaw/core/tools.py +172 -0
  141. package/python/foxclaw/core/tracing.py +390 -0
  142. package/python/foxclaw/core/truth_pipeline.py +114 -0
  143. package/python/foxclaw/core/vec_recall_adapter.py +503 -0
  144. package/python/foxclaw/core/verify.py +181 -0
  145. package/python/foxclaw/core/web_search.py +242 -0
  146. package/python/foxclaw/finance/__init__.py +15 -0
  147. package/python/foxclaw/finance/evidence.py +153 -0
  148. package/python/foxclaw/finance/fx.py +100 -0
  149. package/python/foxclaw/finance/graph.py +188 -0
  150. package/python/foxclaw/finance/models.py +150 -0
  151. package/python/foxclaw/finance/nlparse.py +575 -0
  152. package/python/foxclaw/finance/policy.py +329 -0
  153. package/python/foxclaw/finance/reasoner.py +129 -0
  154. package/python/foxclaw/finance/reasoning.py +340 -0
  155. package/python/foxclaw/finance/reconcile.py +180 -0
  156. package/python/foxclaw/finance/runtime.py +527 -0
  157. package/python/foxclaw/governance/__init__.py +24 -0
  158. package/python/foxclaw/governance/middleware.py +184 -0
  159. package/python/foxclaw/harness/__init__.py +17 -0
  160. package/python/foxclaw/harness/_base.py +72 -0
  161. package/python/foxclaw/harness/_policy.py +359 -0
  162. package/python/foxclaw/harness/drift.py +89 -0
  163. package/python/foxclaw/harness/event_bus.py +31 -0
  164. package/python/foxclaw/harness/harness.py +446 -0
  165. package/python/foxclaw/harness/loop_detection.py +152 -0
  166. package/python/foxclaw/itinerary/__init__.py +10 -0
  167. package/python/foxclaw/itinerary/amap_client.py +117 -0
  168. package/python/foxclaw/itinerary/models.py +80 -0
  169. package/python/foxclaw/itinerary/reasoner.py +101 -0
  170. package/python/foxclaw/itinerary/reasoning.py +174 -0
  171. package/python/foxclaw/itinerary/runtime.py +148 -0
  172. package/python/foxclaw/kernel/__init__.py +13 -0
  173. package/python/foxclaw/kernel/capabilities.py +73 -0
  174. package/python/foxclaw/kernel/policy_gate.py +114 -0
  175. package/python/foxclaw/kernel/process_manager.py +205 -0
  176. package/python/foxclaw/kernel/scheduler.py +131 -0
  177. package/python/foxclaw/kernel/sentinel.py +453 -0
  178. package/python/foxclaw/kernel/sentinel_client.py +246 -0
  179. package/python/foxclaw/kernel/spine.py +97 -0
  180. package/python/foxclaw/knowledge/__init__.py +376 -0
  181. package/python/foxclaw/knowledge/truth_crystallizer.py +92 -0
  182. package/python/foxclaw/learning/__init__.py +12 -0
  183. package/python/foxclaw/learning/knowledge_graph.py +149 -0
  184. package/python/foxclaw/learning/models.py +93 -0
  185. package/python/foxclaw/learning/reasoner.py +70 -0
  186. package/python/foxclaw/learning/runtime.py +363 -0
  187. package/python/foxclaw/learning/spaced_repetition.py +96 -0
  188. package/python/foxclaw/mcp_server.py +189 -0
  189. package/python/foxclaw/orchestration/__init__.py +184 -0
  190. package/python/foxclaw/pipeline/__init__.py +23 -0
  191. package/python/foxclaw/pipeline/cognitive_pipeline.py +481 -0
  192. package/python/foxclaw/pipeline/supervisor_stages.py +230 -0
  193. package/python/foxclaw/planning/__init__.py +17 -0
  194. package/python/foxclaw/planning/llm_planner.py +232 -0
  195. package/python/foxclaw/planning/planner.py +99 -0
  196. package/python/foxclaw/search/__init__.py +24 -0
  197. package/python/foxclaw/search/agent_port.py +194 -0
  198. package/python/foxclaw/search/evidence.py +113 -0
  199. package/python/foxclaw/search/external_search.py +50 -0
  200. package/python/foxclaw/search/hkc_read_port.py +60 -0
  201. package/python/foxclaw/search/internal_search.py +73 -0
  202. package/python/foxclaw/search/models.py +129 -0
  203. package/python/foxclaw/search/planner.py +44 -0
  204. package/python/foxclaw/search/retriever.py +39 -0
  205. package/python/foxclaw/search/runtime.py +134 -0
  206. package/python/foxclaw/search/strategy.py +44 -0
  207. package/python/foxclaw/skills/__init__.py +613 -0
  208. package/python/foxclaw/skills/hooks_spec.py +73 -0
  209. package/python/foxclaw/skills/lifecycle.py +278 -0
  210. package/python/foxclaw/skills/markdown_skill.py +174 -0
  211. package/python/foxclaw/skills/markdown_store.py +39 -0
  212. package/python/foxclaw/skills/mcp_client.py +190 -0
  213. package/python/foxclaw/skills/mcp_store.py +43 -0
  214. package/python/foxclaw/skills/permission.py +180 -0
  215. package/python/foxclaw/skills/pipeline.py +386 -0
  216. package/python/foxclaw/skills/policy.py +80 -0
  217. package/python/foxclaw/skills/review.py +72 -0
  218. package/python/foxclaw/skills/store.py +57 -0
  219. package/python/frontend/assets/core_bg.jpg +0 -0
  220. package/python/frontend/deck/auth.js +32 -0
  221. package/python/frontend/deck/chat_model_picker.js +537 -0
  222. package/python/frontend/deck/domain.js +296 -0
  223. package/python/frontend/deck/main.js +1950 -0
  224. package/python/frontend/deck/markdown.js +48 -0
  225. package/python/frontend/deck/settings.js +324 -0
  226. package/python/frontend/deck/state.js +6 -0
  227. package/python/frontend/deck/util.js +6 -0
  228. package/python/frontend/deck/visuals.js +212 -0
  229. package/python/frontend/deck.css +855 -0
  230. package/python/frontend/deck.html +686 -0
  231. package/python/frontend/deck_v2.html +341 -0
  232. package/python/frontend/planet/index.html +266 -0
  233. package/python/frontend/planet/planet.css +579 -0
  234. package/python/frontend/planet/planet.js +1637 -0
  235. package/python/frontend/planet/vendor/three.core.min.js +6 -0
  236. package/python/frontend/planet/vendor/three.module.min.js +6 -0
  237. package/python/frontend/v3/assets/index-BD7VPbMV.js +33 -0
  238. package/python/frontend/v3/assets/index-CAvnYWGH.css +1 -0
  239. package/python/frontend/v3/index.html +15 -0
  240. package/python/frontend/widget_runtime.js +295 -0
  241. package/python/frontend/widgets.js +696 -0
  242. package/python/frontend_src/index.html +14 -0
  243. package/python/frontend_src/package-lock.json +1376 -0
  244. package/python/frontend_src/package.json +19 -0
  245. package/python/frontend_src/src/App.vue +62 -0
  246. package/python/frontend_src/src/api.js +89 -0
  247. package/python/frontend_src/src/components/ChatDock.vue +377 -0
  248. package/python/frontend_src/src/components/ComposerMenu.vue +75 -0
  249. package/python/frontend_src/src/components/DocViewer.vue +171 -0
  250. package/python/frontend_src/src/components/Inspector.vue +241 -0
  251. package/python/frontend_src/src/components/LeftRail.vue +394 -0
  252. package/python/frontend_src/src/components/MenuPopover.vue +130 -0
  253. package/python/frontend_src/src/components/MessageStream.vue +401 -0
  254. package/python/frontend_src/src/components/ModelPicker.vue +355 -0
  255. package/python/frontend_src/src/components/QuickIngest.vue +118 -0
  256. package/python/frontend_src/src/components/Stage.vue +226 -0
  257. package/python/frontend_src/src/components/ToolMenu.vue +144 -0
  258. package/python/frontend_src/src/components/TopBar.vue +90 -0
  259. package/python/frontend_src/src/components/panels/ActivityPanel.vue +84 -0
  260. package/python/frontend_src/src/components/panels/AgentsPanel.vue +86 -0
  261. package/python/frontend_src/src/components/panels/KnowledgePanel.vue +441 -0
  262. package/python/frontend_src/src/components/panels/MemoryPanel.vue +118 -0
  263. package/python/frontend_src/src/components/panels/PanelBox.vue +51 -0
  264. package/python/frontend_src/src/components/panels/ReviewPanel.vue +308 -0
  265. package/python/frontend_src/src/components/panels/SettingsPanel.vue +254 -0
  266. package/python/frontend_src/src/components/panels/TasksPanel.vue +74 -0
  267. package/python/frontend_src/src/components/panels/ToolsPanel.vue +640 -0
  268. package/python/frontend_src/src/components/panels/UsagePanel.vue +105 -0
  269. package/python/frontend_src/src/lib/fmt.js +48 -0
  270. package/python/frontend_src/src/lib/md.js +204 -0
  271. package/python/frontend_src/src/main.js +7 -0
  272. package/python/frontend_src/src/stores/app.js +106 -0
  273. package/python/frontend_src/src/stores/chat.js +484 -0
  274. package/python/frontend_src/src/stores/model.js +104 -0
  275. package/python/frontend_src/src/stores/panels.js +330 -0
  276. package/python/frontend_src/src/styles/base.css +138 -0
  277. package/python/frontend_src/src/styles/panel.css +117 -0
  278. package/python/frontend_src/src/styles/tokens.css +78 -0
  279. package/python/frontend_src/vite.config.js +46 -0
  280. package/python/pyproject.toml +265 -0
  281. package/python/skills/README.md +123 -0
  282. package/python/skills/execution-contract/SKILL.md +30 -0
  283. package/python/skills/general-assistant/SKILL.md +34 -0
  284. package/python/skills/planner/SKILL.md +33 -0
  285. package/python/skills/schedule-itinerary/SKILL.md +35 -0
  286. package/python/skills/skill-composition/SKILL.md +31 -0
  287. package/python/skills/skill-guard/SKILL.md +67 -0
  288. package/python/skills/skill-memory/SKILL.md +50 -0
  289. package/python/skills/skill-router/SKILL.md +35 -0
  290. package/python/tests/conftest.py +76 -0
  291. package/python/tests/run_all.py +263 -0
  292. package/python/tests/test_agent_lifecycle.py +360 -0
  293. package/python/tests/test_ahs_p2.py +414 -0
  294. package/python/tests/test_anthropic_tools.py +206 -0
  295. package/python/tests/test_api.py +87 -0
  296. package/python/tests/test_api_auth.py +83 -0
  297. package/python/tests/test_api_host_guard.py +69 -0
  298. package/python/tests/test_attachments.py +167 -0
  299. package/python/tests/test_audit_chain.py +121 -0
  300. package/python/tests/test_audit_sink.py +136 -0
  301. package/python/tests/test_browser.py +153 -0
  302. package/python/tests/test_browser_request_guard.py +184 -0
  303. package/python/tests/test_capabilities.py +158 -0
  304. package/python/tests/test_channel_signing.py +192 -0
  305. package/python/tests/test_channel_trust.py +109 -0
  306. package/python/tests/test_channels.py +184 -0
  307. package/python/tests/test_cli.py +46 -0
  308. package/python/tests/test_compaction_toolpair.py +119 -0
  309. package/python/tests/test_config_layering.py +65 -0
  310. package/python/tests/test_confirm_nonce.py +197 -0
  311. package/python/tests/test_context_compaction_wiring.py +130 -0
  312. package/python/tests/test_dispatch.py +95 -0
  313. package/python/tests/test_domain_evals.py +403 -0
  314. package/python/tests/test_domain_import.py +78 -0
  315. package/python/tests/test_domain_reasoners.py +148 -0
  316. package/python/tests/test_e2e.py +178 -0
  317. package/python/tests/test_emb_cache.py +107 -0
  318. package/python/tests/test_embedding_singleton.py +89 -0
  319. package/python/tests/test_envfile.py +83 -0
  320. package/python/tests/test_evals_smoke.py +114 -0
  321. package/python/tests/test_event_spine.py +182 -0
  322. package/python/tests/test_evidence_semantic.py +101 -0
  323. package/python/tests/test_evidence_sse.py +97 -0
  324. package/python/tests/test_file_ingest.py +146 -0
  325. package/python/tests/test_finance.py +153 -0
  326. package/python/tests/test_finance_ledger.py +252 -0
  327. package/python/tests/test_finance_persist.py +178 -0
  328. package/python/tests/test_gateway.py +144 -0
  329. package/python/tests/test_governance.py +468 -0
  330. package/python/tests/test_governance_audit.py +359 -0
  331. package/python/tests/test_governance_middleware.py +143 -0
  332. package/python/tests/test_hkc.py +286 -0
  333. package/python/tests/test_hkc_index_build_manager.py +339 -0
  334. package/python/tests/test_hkc_manifest_reuse.py +317 -0
  335. package/python/tests/test_hkc_search_event_sync.py +533 -0
  336. package/python/tests/test_import_path_guard.py +161 -0
  337. package/python/tests/test_injection_guard.py +211 -0
  338. package/python/tests/test_integration.py +141 -0
  339. package/python/tests/test_itinerary.py +103 -0
  340. package/python/tests/test_kee_semantic.py +89 -0
  341. package/python/tests/test_kernel.py +222 -0
  342. package/python/tests/test_learning.py +110 -0
  343. package/python/tests/test_llm_admin.py +160 -0
  344. package/python/tests/test_llm_planner.py +366 -0
  345. package/python/tests/test_markdown_skills.py +73 -0
  346. package/python/tests/test_markdown_skills_openclaw.py +71 -0
  347. package/python/tests/test_mcp_connectors.py +109 -0
  348. package/python/tests/test_mcp_guardian_discovery.py +91 -0
  349. package/python/tests/test_mcp_no_memory.py +43 -0
  350. package/python/tests/test_mcp_policy_gate.py +77 -0
  351. package/python/tests/test_mcp_server.py +95 -0
  352. package/python/tests/test_memory_recall.py +95 -0
  353. package/python/tests/test_metrics.py +66 -0
  354. package/python/tests/test_multi_chain.py +102 -0
  355. package/python/tests/test_multimodal.py +135 -0
  356. package/python/tests/test_negotiation.py +146 -0
  357. package/python/tests/test_orchestration.py +119 -0
  358. package/python/tests/test_orchestration_decoupled.py +109 -0
  359. package/python/tests/test_p3_p5_hardening.py +338 -0
  360. package/python/tests/test_parallel_dispatch.py +215 -0
  361. package/python/tests/test_pipeline.py +533 -0
  362. package/python/tests/test_plan_visible.py +86 -0
  363. package/python/tests/test_planner.py +95 -0
  364. package/python/tests/test_policy_gate.py +109 -0
  365. package/python/tests/test_reasoner.py +185 -0
  366. package/python/tests/test_release_check.py +263 -0
  367. package/python/tests/test_resume_checkpoint.py +156 -0
  368. package/python/tests/test_routing.py +95 -0
  369. package/python/tests/test_scheduler.py +141 -0
  370. package/python/tests/test_search.py +204 -0
  371. package/python/tests/test_secrets.py +159 -0
  372. package/python/tests/test_semantic.py +78 -0
  373. package/python/tests/test_sessions.py +91 -0
  374. package/python/tests/test_settings.py +281 -0
  375. package/python/tests/test_shadow_learning.py +330 -0
  376. package/python/tests/test_shared_write.py +207 -0
  377. package/python/tests/test_skill_taint_gate.py +154 -0
  378. package/python/tests/test_skills.py +133 -0
  379. package/python/tests/test_stats_and_events.py +165 -0
  380. package/python/tests/test_streaming.py +60 -0
  381. package/python/tests/test_supervisor_pipeline.py +177 -0
  382. package/python/tests/test_supervisor_triage.py +108 -0
  383. package/python/tests/test_taint.py +117 -0
  384. package/python/tests/test_task_stream.py +85 -0
  385. package/python/tests/test_thinking_sse.py +67 -0
  386. package/python/tests/test_thinking_stream.py +76 -0
  387. package/python/tests/test_tool_center.py +129 -0
  388. package/python/tests/test_tool_parallel.py +113 -0
  389. package/python/tests/test_tool_params.py +103 -0
  390. package/python/tests/test_tool_use.py +242 -0
  391. package/python/tests/test_toplevel_concurrency.py +117 -0
  392. package/python/tests/test_tracing.py +290 -0
  393. package/python/tests/test_truth_crystallizer.py +127 -0
  394. package/python/tests/test_truth_flow.py +93 -0
  395. package/python/tests/test_url_policy.py +53 -0
  396. package/python/tests/test_verify_evidence.py +225 -0
  397. package/python/tests/test_version_sync.py +71 -0
  398. package/python/tests/test_web_trigger.py +99 -0
  399. package/python/tools/check_faiss_type.py +31 -0
  400. package/python/tools/check_log.ps1 +46 -0
  401. package/python/tools/ivf_status.py +72 -0
  402. package/python/tools/mypy_baseline.txt +5 -0
  403. package/python/tools/mypy_ratchet.py +97 -0
  404. package/python/tools/pack.py +178 -0
  405. package/python/tools/release_check.py +349 -0
  406. package/python/tools/restart_foxclaw.ps1 +74 -0
  407. package/python/tools/shared_write_audit.py +204 -0
  408. package/python/tools/size_baseline.txt +28 -0
  409. package/python/tools/size_check.py +102 -0
  410. package/python/tools/verify_env.bat +2 -0
  411. package/python/tools/verify_env.py +25 -0
  412. package/python/vendor/HMR_LICENSE +37 -0
  413. package/python/vendor/HMR_README.md +65 -0
  414. package/python/vendor/hkc/LICENSE +37 -0
  415. package/python/vendor/hkc/hkc_ace/__init__.py +0 -0
  416. package/python/vendor/hkc/hkc_ace/ace.py +457 -0
  417. package/python/vendor/hkc/hkc_ace/skill_taxonomy.json +465 -0
  418. package/python/vendor/hkc/hkc_api/__init__.py +0 -0
  419. package/python/vendor/hkc/hkc_api/container.py +416 -0
  420. package/python/vendor/hkc/hkc_api/ingest_jobs.py +103 -0
  421. package/python/vendor/hkc/hkc_api/main.py +157 -0
  422. package/python/vendor/hkc/hkc_api/routes/__init__.py +0 -0
  423. package/python/vendor/hkc/hkc_api/routes/ability.py +151 -0
  424. package/python/vendor/hkc/hkc_api/routes/config.py +51 -0
  425. package/python/vendor/hkc/hkc_api/routes/knowledge.py +630 -0
  426. package/python/vendor/hkc/hkc_api/routes/search.py +88 -0
  427. package/python/vendor/hkc/hkc_api/schemas.py +153 -0
  428. package/python/vendor/hkc/hkc_api/synthesis.py +179 -0
  429. package/python/vendor/hkc/hkc_core/__init__.py +0 -0
  430. package/python/vendor/hkc/hkc_core/graph/__init__.py +0 -0
  431. package/python/vendor/hkc/hkc_core/graph/base.py +188 -0
  432. package/python/vendor/hkc/hkc_core/graph/sqlite_store.py +789 -0
  433. package/python/vendor/hkc/hkc_core/models/__init__.py +0 -0
  434. package/python/vendor/hkc/hkc_core/models/enums.py +65 -0
  435. package/python/vendor/hkc/hkc_core/models/ku.py +307 -0
  436. package/python/vendor/hkc/hkc_core/utils/__init__.py +0 -0
  437. package/python/vendor/hkc/hkc_core/utils/id_gen.py +113 -0
  438. package/python/vendor/hkc/hkc_crystallizer/__init__.py +44 -0
  439. package/python/vendor/hkc/hkc_crystallizer/adapters.py +94 -0
  440. package/python/vendor/hkc/hkc_crystallizer/candidate.py +145 -0
  441. package/python/vendor/hkc/hkc_crystallizer/crystallizer.py +179 -0
  442. package/python/vendor/hkc/hkc_crystallizer/ingress.py +90 -0
  443. package/python/vendor/hkc/hkc_kde/__init__.py +0 -0
  444. package/python/vendor/hkc/hkc_kde/chunker.py +197 -0
  445. package/python/vendor/hkc/hkc_kde/extractor.py +623 -0
  446. package/python/vendor/hkc/hkc_kde/kde.py +298 -0
  447. package/python/vendor/hkc/hkc_kde/loaders/__init__.py +0 -0
  448. package/python/vendor/hkc/hkc_kde/loaders/ebook_loader.py +153 -0
  449. package/python/vendor/hkc/hkc_kde/loaders/office_loader.py +194 -0
  450. package/python/vendor/hkc/hkc_kde/loaders/pdf_loader.py +162 -0
  451. package/python/vendor/hkc/hkc_kde/loaders/text_loader.py +157 -0
  452. package/python/vendor/hkc/hkc_kde/loaders/web_loader.py +91 -0
  453. package/python/vendor/hkc/hkc_kde/models.py +74 -0
  454. package/python/vendor/hkc/hkc_kde/packager.py +329 -0
  455. package/python/vendor/hkc/hkc_kde/relation_disc.py +151 -0
  456. package/python/vendor/hkc/hkc_kee/__init__.py +0 -0
  457. package/python/vendor/hkc/hkc_kee/dedup.py +227 -0
  458. package/python/vendor/hkc/hkc_kee/fingerprint.py +106 -0
  459. package/python/vendor/hkc/hkc_kee/kee.py +541 -0
  460. package/python/vendor/hkc/hkc_kep/__init__.py +0 -0
  461. package/python/vendor/hkc/hkc_kep/event_bus.py +205 -0
  462. package/python/vendor/hkc/hkc_sdk/__init__.py +63 -0
  463. package/python/vendor/hkc/hkc_sdk/base.py +151 -0
  464. package/python/vendor/hkc/hkc_sdk/direct_client.py +153 -0
  465. package/python/vendor/hkc/hkc_sdk/exceptions.py +39 -0
  466. package/python/vendor/hkc/hkc_sdk/http_client.py +166 -0
  467. package/python/vendor/hkc/hkc_sdk/models.py +171 -0
  468. package/python/vendor/hkc/hkc_search/__init__.py +0 -0
  469. package/python/vendor/hkc/hkc_search/bm25.py +325 -0
  470. package/python/vendor/hkc/hkc_search/embedding_backends.py +374 -0
  471. package/python/vendor/hkc/hkc_search/graph_search.py +132 -0
  472. package/python/vendor/hkc/hkc_search/hybrid.py +331 -0
  473. package/python/vendor/hkc/hkc_search/index_build_manager.py +378 -0
  474. package/python/vendor/hkc/hkc_search/vector_search.py +484 -0
  475. package/python/vendor/hmr/__init__.py +0 -0
  476. package/python/vendor/hmr/core/__init__.py +0 -0
  477. package/python/vendor/hmr/core/hmr.py +684 -0
  478. package/python/vendor/hmr/core/models.py +310 -0
  479. package/python/vendor/hmr/engines/__init__.py +0 -0
  480. package/python/vendor/hmr/engines/evolution.py +710 -0
  481. package/python/vendor/hmr/engines/jit_compiler.py +472 -0
  482. package/python/vendor/hmr/engines/lifecycle.py +264 -0
  483. package/python/vendor/hmr/engines/policy.py +625 -0
  484. package/python/vendor/hmr/engines/recall.py +260 -0
  485. package/python/vendor/hmr/engines/runtime_state.py +158 -0
  486. package/python/vendor/hmr/engines/scheduler.py +323 -0
  487. package/python/vendor/hmr/engines/semantic.py +150 -0
  488. package/python/vendor/hmr/engines/temporal.py +261 -0
  489. package/python/vendor/hmr/engines/thought_chain.py +635 -0
  490. package/python/vendor/hmr/graph/__init__.py +0 -0
  491. package/python/vendor/hmr/graph/cwg.py +338 -0
  492. package/python/vendor/hmr/graph/memory_graph.py +530 -0
  493. package/python/vendor/hmr/storage/__init__.py +0 -0
  494. package/python/vendor/hmr/storage/memory_fs.py +300 -0
  495. package/python/vendor/hmr/storage/vector_store.py +520 -0
@@ -0,0 +1,696 @@
1
+ /* ════════════════════════════════════════════════════════════
2
+ FOXCLAW DECK — Widget Definitions
3
+ 每个 widget 是一个 registerWidget() 注册。
4
+ 新增模块只需在这里加一个 register block。
5
+ ════════════════════════════════════════════════════════════ */
6
+
7
+ /* 共享工具(由主文件注入到 ctx) */
8
+ function _esc(s){return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/\n/g,'<br>');}
9
+ function _statusColor(s){return{PASS:'#1dffa6',WARN:'#ffb347',BLOCK:'#ff4060',BASELINE:'#b066ff',PENDING:'#3a4d68'}[s]||'#1de9ff';}
10
+
11
+ /* ─────────────────────────────────────────────
12
+ WIDGET 1: AGENT 编队 (roster)
13
+ ───────────────────────────────────────────── */
14
+ WidgetRuntime.register({
15
+ id: 'roster',
16
+ title: 'AGENT 编队',
17
+ icon: '◈',
18
+ defaultColumn: 'left',
19
+ size: { flex: true },
20
+ render(el, ctx) {
21
+ el.innerHTML = `<div class="roster" data-role="roster-list"></div>`;
22
+ const list = el.querySelector('[data-role="roster-list"]');
23
+ list.innerHTML = ctx.AGENTS.map(a => `
24
+ <div class="agent-pod ${a.id===ctx.activeAgent?'active':''}" data-pod="${a.id}"
25
+ style="--apc:${a.color}">
26
+ <div class="pod-avatar"><div class="ring-pulse"></div>${a.emoji}</div>
27
+ <div class="pod-info">
28
+ <div class="pod-name">${a.name}</div>
29
+ <div class="pod-role">${a.code} · ${a.role}</div>
30
+ <div class="pod-state"><span class="s-dot"></span><span data-podstate="${a.id}">IDLE</span></div>
31
+ </div>
32
+ <div class="pod-metric">
33
+ <div class="pm-val" data-podtask="${a.id}" style="color:${a.color}">${a.tasks}</div>
34
+ <div class="pm-lbl">TASK</div>
35
+ </div>
36
+ </div>`).join('');
37
+ list.querySelectorAll('[data-pod]').forEach(pod => {
38
+ pod.onclick = () => ctx.setActiveCore(pod.dataset.pod);
39
+ });
40
+ },
41
+ onAgentChange(agentId, el) {
42
+ el.querySelectorAll('.agent-pod').forEach(p =>
43
+ p.classList.toggle('active', p.dataset.pod === agentId));
44
+ },
45
+ });
46
+
47
+ /* ─────────────────────────────────────────────
48
+ WIDGET 2: 任务流 (tasks)
49
+ ───────────────────────────────────────────── */
50
+ WidgetRuntime.register({
51
+ id: 'tasks',
52
+ title: '任务流',
53
+ icon: '▤',
54
+ defaultColumn: 'left',
55
+ size: { maxH: 200 },
56
+ render(el, ctx) {
57
+ el.innerHTML = `<div class="tc-stream" data-role="task-stream"><div class="empty">等待指令下达</div></div>`;
58
+ ctx._taskStreamEl = el.querySelector('[data-role="task-stream"]');
59
+ },
60
+ });
61
+
62
+ /* ─────────────────────────────────────────────
63
+ WIDGET 3: 中央核心 (core) — 激活 Agent
64
+ ───────────────────────────────────────────── */
65
+ WidgetRuntime.register({
66
+ id: 'core',
67
+ title: '中央核心 · 激活单元',
68
+ icon: '⊚',
69
+ defaultColumn: 'center',
70
+ size: { flex: true },
71
+ render(el, ctx) {
72
+ el.innerHTML = `
73
+ <div class="core-stage" data-role="core-stage">
74
+ <div class="core-hud-tl">SESSION <b data-hud="session">—</b><br>NODES <b data-hud="nodes">0</b></div>
75
+ <div class="core-hud-tr">CONF <b data-hud="conf">—</b><br>Δ DRIFT <b data-hud="drift">—</b></div>
76
+ <div class="core-hud-bl">POLICY <b data-hud="policy">v1</b><br>RULES <b data-hud="rules">0</b></div>
77
+ <div class="core-hud-br">MODE <b data-hud="mode">SHADOW</b><br>BLOCK <b data-hud="block">0.25</b></div>
78
+ <div class="core-orbit">
79
+ <div class="orbit-ring r1"></div><div class="orbit-ring r2"></div><div class="orbit-ring r3"></div>
80
+ <div class="orbit-tick" data-role="orbit-tick"></div>
81
+ <div class="radar-sweep"></div>
82
+ </div>
83
+ <div class="core-avatar" data-role="core-avatar">🏢</div>
84
+ <div class="core-name" data-role="core-name">主管</div>
85
+ <div class="core-role" data-role="core-role">SUPERVISOR · 全局协调</div>
86
+ <div class="core-statusline">
87
+ <span data-role="core-status-text">系统就绪 · 待命中</span>
88
+ <span class="cs-cursor"></span>
89
+ </div>
90
+ <div class="core-telemetry">
91
+ <div class="ct-stat"><div class="cts-val" data-core="tasks">0</div><div class="cts-lbl">任务</div></div>
92
+ <div class="ct-stat"><div class="cts-val" data-core="mem">0</div><div class="cts-lbl">记忆</div></div>
93
+ <div class="ct-stat"><div class="cts-val" data-core="nodes">0</div><div class="cts-lbl">推理</div></div>
94
+ </div>
95
+ <div class="chat-log" data-role="chat-log"></div>
96
+ </div>`;
97
+ // orbit ticks
98
+ const tick = el.querySelector('[data-role="orbit-tick"]');
99
+ let h=''; for(let i=0;i<24;i++)h+=`<span style="transform:translateX(-50%) rotate(${i*15}deg)"></span>`;
100
+ tick.innerHTML=h;
101
+ ctx._coreEl = el;
102
+ },
103
+ onAgentChange(agentId, el, ctx) {
104
+ const a = ctx.AG(agentId);
105
+ el.querySelector('[data-role="core-avatar"]').textContent = a.emoji;
106
+ el.querySelector('[data-role="core-avatar"]').style.setProperty('--cac', a.color);
107
+ el.querySelector('[data-role="core-name"]').textContent = a.name;
108
+ el.querySelector('[data-role="core-role"]').textContent = `${a.code} · ${a.role}`;
109
+ el.querySelector('[data-role="core-status-text"]').style.color = a.color;
110
+ el.querySelector('.cs-cursor').style.background = a.color;
111
+ },
112
+ });
113
+
114
+ /* ─────────────────────────────────────────────
115
+ WIDGET 4: HARNESS 遥测 (harness)
116
+ ───────────────────────────────────────────── */
117
+ WidgetRuntime.register({
118
+ id: 'harness',
119
+ title: 'HARNESS 遥测',
120
+ icon: '⛨',
121
+ defaultColumn: 'right',
122
+ size: {},
123
+ events: ['policy_updated', 'shadow_calibrated'],
124
+ render(el) {
125
+ el.innerHTML = `
126
+ <div class="harness-widget">
127
+ <svg class="h-ring-svg" width="72" height="72" viewBox="0 0 72 72">
128
+ <circle class="h-ring-bg" cx="36" cy="36" r="30"/>
129
+ <circle class="h-ring-fg" data-role="h-ring" cx="36" cy="36" r="30" stroke="#ffb347"
130
+ stroke-dasharray="188.5" stroke-dashoffset="188.5"/>
131
+ <text class="h-ring-label" x="36" y="32" fill="#cfe8ff" font-size="16" data-role="h-ring-val">0</text>
132
+ <text class="h-ring-label" x="36" y="46" fill="#3a4d68" font-size="8">/ 20</text>
133
+ </svg>
134
+ <div class="h-info">
135
+ <span class="h-mode shadow" data-role="h-mode">◔ SHADOW 校准</span>
136
+ <div class="h-detail">
137
+ BLOCK 阈值 <b data-role="h-block">0.250</b><br>
138
+ WARN 阈值 <b data-role="h-warn">0.150</b><br>
139
+ Δ 均值 <b data-role="h-avg">—</b>
140
+ </div>
141
+ </div>
142
+ </div>
143
+ <div class="weight-section">
144
+ <div class="wt-row"><span class="wt-lbl">语义距离</span><div class="wt-track"><div class="wt-fill" data-role="wt-sem" style="width:50%;background:#1de9ff;color:#1de9ff"></div></div><span class="wt-pct" data-role="wt-sem-pct">50%</span></div>
145
+ <div class="wt-row"><span class="wt-lbl">工具意图</span><div class="wt-track"><div class="wt-fill" data-role="wt-tool" style="width:30%;background:#b066ff;color:#b066ff"></div></div><span class="wt-pct" data-role="wt-tool-pct">30%</span></div>
146
+ <div class="wt-row"><span class="wt-lbl">范围蔓延</span><div class="wt-track"><div class="wt-fill" data-role="wt-scope" style="width:20%;background:#ffb347;color:#ffb347"></div></div><span class="wt-pct" data-role="wt-scope-pct">20%</span></div>
147
+ </div>`;
148
+ },
149
+ refresh(el, ctx, agentId) {
150
+ ctx.loadHarnessInto(el, agentId);
151
+ },
152
+ onEvent(evt, el, ctx) {
153
+ // policy 更新或校准完成时立即刷新
154
+ ctx.loadHarnessInto(el, ctx.activeAgent);
155
+ },
156
+ });
157
+
158
+ /* ─────────────────────────────────────────────
159
+ WIDGET 5: 推理链 STREAM (thoughtchain)
160
+ ───────────────────────────────────────────── */
161
+ WidgetRuntime.register({
162
+ id: 'thoughtchain',
163
+ title: '推理链 STREAM',
164
+ icon: '⌬',
165
+ defaultColumn: 'right',
166
+ size: { flex: true },
167
+ render(el) {
168
+ el.innerHTML = `<div class="tc-stream" data-role="tc-stream"><div class="empty">执行任务后显示推理轨迹</div></div>`;
169
+ },
170
+ refresh(el, ctx, agentId) {
171
+ ctx.loadChainInto(el, agentId);
172
+ },
173
+ onAgentChange(agentId, el, ctx) {
174
+ ctx.loadChainInto(el, agentId);
175
+ },
176
+ });
177
+
178
+ /* ─────────────────────────────────────────────
179
+ WIDGET 6: 事件流 LIVE (events)
180
+ ───────────────────────────────────────────── */
181
+ WidgetRuntime.register({
182
+ id: 'events',
183
+ title: '事件流 · LIVE',
184
+ icon: '⚡',
185
+ defaultColumn: 'right',
186
+ size: { maxH: 180 },
187
+ events: ['harness_block', 'harness_warn', 'policy_updated', 'shadow_calibrated'],
188
+ render(el) {
189
+ el.innerHTML = `<div class="evt-feed" data-role="evt-feed"><div class="empty">监听 Harness 事件...</div></div>`;
190
+ },
191
+ onEvent(evt, el) {
192
+ const feed = el.querySelector('[data-role="evt-feed"]');
193
+ feed.querySelector('.empty')?.remove();
194
+ const cmap={harness_block:'#ff4060',harness_warn:'#ffb347',policy_updated:'#b066ff',shadow_calibrated:'#1dffa6'};
195
+ const color = cmap[evt.type] || '#1de9ff';
196
+ const d = evt.data || {};
197
+ const reason = d.result?.reason || d.rule_id || d.reason || '';
198
+ const item = document.createElement('div');
199
+ item.className = 'evt'; item.style.setProperty('--ec', color);
200
+ item.innerHTML = `
201
+ <div class="evt-top"><span class="evt-type">${evt.type.replace('harness_','').replace('_',' ')}</span>
202
+ <span class="evt-time">${new Date().toLocaleTimeString('en-GB')}</span></div>
203
+ <div class="evt-body">${_esc((d.agent_id||'—')+' · '+reason).slice(0,70)}</div>`;
204
+ feed.insertBefore(item, feed.firstChild);
205
+ while (feed.children.length > 20) feed.lastChild?.remove();
206
+ },
207
+ });
208
+
209
+ /* ─────────────────────────────────────────────
210
+ WIDGET 7: 协同 DAG (dag) — 多 Agent 星舰控制流
211
+ 命令 → 主管分发 → 子 Agent → Harness 关卡 → 记忆汇聚
212
+ ───────────────────────────────────────────── */
213
+ WidgetRuntime.register({
214
+ id: 'dag',
215
+ title: '协同 DAG · 控制流',
216
+ icon: '⊶',
217
+ defaultColumn: 'center',
218
+ size: { maxH: 260 },
219
+ events: ['harness_block', 'harness_warn', 'policy_updated'],
220
+ render(el, ctx) {
221
+ el.innerHTML = `
222
+ <div class="dag-wrap">
223
+ <svg class="dag-svg" viewBox="0 0 640 230" preserveAspectRatio="xMidYMid meet">
224
+ <defs>
225
+ <marker id="dagArrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
226
+ <path d="M2 1L8 5L2 9" fill="none" stroke="#3a4d68" stroke-width="1.5" stroke-linecap="round"/>
227
+ </marker>
228
+ </defs>
229
+ <g data-role="dag-edges"></g>
230
+ <g data-role="dag-nodes"></g>
231
+ </svg>
232
+ </div>`;
233
+ ctx._dagEl = el;
234
+ _dagBuild(el, ctx);
235
+ },
236
+ onAgentChange(agentId, el, ctx) {
237
+ _dagSetActive(el, agentId);
238
+ },
239
+ onEvent(evt, el, ctx) {
240
+ if (evt.type === 'harness_block') _dagFlashGate(el, '#ff4060');
241
+ else if (evt.type === 'harness_warn') _dagFlashGate(el, '#ffb347');
242
+ else if (evt.type === 'policy_updated') _dagFlashGate(el, '#b066ff');
243
+ },
244
+ });
245
+
246
+ /* DAG 拓扑定义 */
247
+ const _DAG_NODES = {
248
+ command: { x: 60, y: 115, label: '指令', icon: '❯', kind: 'entry', color: '#1de9ff' },
249
+ supervisor: { x: 180, y: 115, label: '主管', icon: '🏢', kind: 'hub', color: '#1de9ff' },
250
+ assistant: { x: 320, y: 35, label: '助手', icon: '🤝', kind: 'agent', color: '#4d9fff' },
251
+ finance: { x: 320, y: 90, label: '财务', icon: '💰', kind: 'agent', color: '#ffb347' },
252
+ admin: { x: 320, y: 145, label: '行政', icon: '📅', kind: 'agent', color: '#ff5e9c' },
253
+ office: { x: 320, y: 200, label: '办公', icon: '📚', kind: 'agent', color: '#1dffa6' },
254
+ harness: { x: 460, y: 115, label: 'HARNESS', icon: '⛨', kind: 'gate', color: '#b066ff' },
255
+ memory: { x: 580, y: 115, label: 'HMR', icon: '🧠', kind: 'sink', color: '#1dffa6' },
256
+ };
257
+ const _DAG_EDGES = [
258
+ ['command','supervisor'],
259
+ ['supervisor','assistant'],['supervisor','finance'],['supervisor','admin'],['supervisor','office'],
260
+ ['assistant','harness'],['finance','harness'],['admin','harness'],['office','harness'],
261
+ ['harness','memory'],['memory','supervisor'],
262
+ ];
263
+
264
+ function _dagBuild(el, ctx) {
265
+ const edgesG = el.querySelector('[data-role="dag-edges"]');
266
+ const nodesG = el.querySelector('[data-role="dag-nodes"]');
267
+
268
+ // edges
269
+ edgesG.innerHTML = _DAG_EDGES.map(([from, to], i) => {
270
+ const a = _DAG_NODES[from], b = _DAG_NODES[to];
271
+ const curve = (from === 'memory' && to === 'supervisor')
272
+ ? `M${a.x},${a.y+18} C${a.x},${a.y+70} ${b.x},${b.y+70} ${b.x},${b.y+18}` // return loop below
273
+ : `M${a.x+16},${a.y} C${(a.x+b.x)/2},${a.y} ${(a.x+b.x)/2},${b.y} ${b.x-16},${b.y}`;
274
+ return `<path class="dag-edge" data-edge="${from}-${to}" d="${curve}"
275
+ fill="none" stroke="#1a2942" stroke-width="1.5" marker-end="url(#dagArrow)"/>`;
276
+ }).join('');
277
+
278
+ // nodes
279
+ nodesG.innerHTML = Object.entries(_DAG_NODES).map(([id, n]) => {
280
+ const r = n.kind === 'hub' ? 17 : n.kind === 'gate' ? 16 : 14;
281
+ const shape = n.kind === 'gate'
282
+ ? `<rect class="dag-node-shape" data-node="${id}" x="${n.x-r}" y="${n.y-r}" width="${r*2}" height="${r*2}" rx="3"
283
+ fill="rgba(10,20,40,0.9)" stroke="${n.color}" stroke-width="1.5"/>`
284
+ : `<circle class="dag-node-shape" data-node="${id}" cx="${n.x}" cy="${n.y}" r="${r}"
285
+ fill="rgba(10,20,40,0.9)" stroke="${n.color}" stroke-width="1.5"/>`;
286
+ const lbl = n.kind === 'gate'
287
+ ? `<text class="dag-label" x="${n.x}" y="${n.y+r+11}" fill="${n.color}" font-size="8" text-anchor="middle">${n.label}</text>`
288
+ : `<text class="dag-label" x="${n.x}" y="${n.y+r+11}" fill="#6b88aa" font-size="9" text-anchor="middle">${n.label}</text>`;
289
+ return `<g class="dag-node" data-node-g="${id}" style="--dnc:${n.color}">
290
+ ${shape}
291
+ <text class="dag-icon" x="${n.x}" y="${n.y+1}" font-size="13" text-anchor="middle" dominant-baseline="central">${n.icon}</text>
292
+ ${lbl}
293
+ </g>`;
294
+ }).join('');
295
+
296
+ _dagSetActive(el, ctx.activeAgent);
297
+ }
298
+
299
+ function _dagSetActive(el, agentId) {
300
+ if (!el) return;
301
+ el.querySelectorAll('.dag-node').forEach(g => {
302
+ g.classList.toggle('dag-dim', false);
303
+ });
304
+ // highlight active agent path: command→supervisor→agent→harness→memory
305
+ const path = ['command','supervisor', agentId, 'harness','memory'];
306
+ el.querySelectorAll('.dag-node').forEach(g => {
307
+ const id = g.dataset.nodeG;
308
+ g.classList.toggle('dag-active', path.includes(id));
309
+ });
310
+ }
311
+
312
+ let _dagAnimSeq = 0;
313
+ function _dagPulse(el, agentId) {
314
+ if (!el) return;
315
+ _dagAnimSeq++;
316
+ const seq = _dagAnimSeq;
317
+ const flow = [
318
+ ['command-supervisor', 'command', 'supervisor'],
319
+ [`supervisor-${agentId}`, agentId, null],
320
+ [`${agentId}-harness`, 'harness', null],
321
+ ['harness-memory', 'memory', null],
322
+ ['memory-supervisor', null, null],
323
+ ];
324
+ let i = 0;
325
+ const step = () => {
326
+ if (seq !== _dagAnimSeq) return; // 被新动画打断
327
+ if (i >= flow.length) { _dagClearFlow(el); return; }
328
+ const [edgeId, nodeId] = flow[i];
329
+ const edge = el.querySelector(`[data-edge="${edgeId}"]`);
330
+ if (edge) {
331
+ edge.classList.add('dag-edge-flow');
332
+ setTimeout(() => edge.classList.remove('dag-edge-flow'), 700);
333
+ }
334
+ if (nodeId) {
335
+ const node = el.querySelector(`[data-node-g="${nodeId}"]`);
336
+ if (node) {
337
+ node.classList.add('dag-pulse');
338
+ setTimeout(() => node.classList.remove('dag-pulse'), 700);
339
+ }
340
+ }
341
+ i++;
342
+ setTimeout(step, 280);
343
+ };
344
+ step();
345
+ }
346
+
347
+ function _dagClearFlow(el) {
348
+ el.querySelectorAll('.dag-edge-flow').forEach(e => e.classList.remove('dag-edge-flow'));
349
+ }
350
+
351
+ function _dagFlashGate(el, color) {
352
+ if (!el) return;
353
+ const gate = el.querySelector('[data-node="harness"]');
354
+ if (!gate) return;
355
+ const g = gate.closest('.dag-node') || gate;
356
+ // 注入一次性 keyframes(如未注入)
357
+ if (!document.getElementById('dag-flash-style')) {
358
+ const st = document.createElement('style');
359
+ st.id = 'dag-flash-style';
360
+ st.textContent = `@keyframes dagGateFlash{
361
+ 0%{stroke-width:1.5;filter:none}
362
+ 25%{stroke-width:4;filter:drop-shadow(0 0 14px var(--flash-c))}
363
+ 60%{stroke-width:3;filter:drop-shadow(0 0 10px var(--flash-c))}
364
+ 100%{stroke-width:1.5;filter:none}}
365
+ .dag-gate-flash{animation:dagGateFlash 1.2s ease-out;transform-box:fill-box;transform-origin:center}`;
366
+ document.head.appendChild(st);
367
+ }
368
+ const orig = gate.getAttribute('stroke');
369
+ gate.style.setProperty('--flash-c', color);
370
+ gate.setAttribute('stroke', color);
371
+ gate.classList.remove('dag-gate-flash');
372
+ void gate.offsetWidth; // 强制重排,允许动画重放
373
+ gate.classList.add('dag-gate-flash');
374
+ // 同时让 HARNESS 文字标签也闪一下
375
+ const label = el.querySelector('.dag-node[data-node-g="harness"] .dag-label');
376
+ if (label) { label.style.fill = color; label.style.fontWeight = '700'; }
377
+ setTimeout(() => {
378
+ gate.setAttribute('stroke', orig);
379
+ gate.classList.remove('dag-gate-flash');
380
+ if (label) { label.style.fill = ''; label.style.fontWeight = ''; }
381
+ }, 1200);
382
+ }
383
+
384
+ /* ─────────────────────────────────────────────
385
+ WIDGET 8: 执行终端 (terminal) — Shell 执行流
386
+ 命令回显 · 记忆检索 · 推理 · 工具调用 · Harness 校验
387
+ 带打字机流式效果,营造 "AI 正在工作" 的真实感
388
+ ───────────────────────────────────────────── */
389
+ WidgetRuntime.register({
390
+ id: 'terminal',
391
+ title: '执行终端 · SHELL',
392
+ icon: '▩',
393
+ defaultColumn: 'left',
394
+ size: { maxH: 240, flex: false },
395
+ render(el, ctx) {
396
+ el.innerHTML = `
397
+ <div class="term">
398
+ <div class="term-out" data-role="term-out"></div>
399
+ <div class="term-prompt-line">
400
+ <span class="term-ps">foxclaw@deck</span><span class="term-ps-sep">:</span><span class="term-ps-path" data-role="term-agent">~/supervisor</span><span class="term-ps-dollar">$</span>
401
+ <span class="term-caret"></span>
402
+ </div>
403
+ </div>`;
404
+ ctx._terminalEl = el;
405
+ ctx.termLog = (line, type) => _termWrite(el, line, type);
406
+ ctx.termClear = () => { el.querySelector('[data-role="term-out"]').innerHTML = ''; };
407
+ _termBoot(el);
408
+ },
409
+ onAgentChange(agentId, el, ctx) {
410
+ const a = ctx.AG(agentId);
411
+ const ps = el.querySelector('[data-role="term-agent"]');
412
+ if (ps) ps.textContent = `~/${agentId}`;
413
+ _termWrite(el, `切换激活单元 → ${a.name} [${a.code}]`, 'info');
414
+ },
415
+ });
416
+
417
+ function _termBoot(el) {
418
+ const lines = [
419
+ ['FOXCLAW DECK · 执行终端 v1.0', 'info'],
420
+ ['初始化 HMR 认知运行时...', 'out'],
421
+ ['挂载记忆层 [Vector · Graph · KV]', 'ok'],
422
+ ['Harness 线束在线 · Shadow 校准模式', 'ok'],
423
+ ['五单元编队就绪 · 等待指令', 'info'],
424
+ ];
425
+ let i = 0;
426
+ const tick = () => {
427
+ if (i >= lines.length) return;
428
+ _termWrite(el, lines[i][0], lines[i][1]);
429
+ i++; setTimeout(tick, 220);
430
+ };
431
+ tick();
432
+ }
433
+
434
+ function _termWrite(el, text, type = 'out', stream = false) {
435
+ const out = el.querySelector('[data-role="term-out"]');
436
+ if (!out) return;
437
+ const prefix = {
438
+ cmd: '❯ ',
439
+ info: '◇ ',
440
+ ok: '✓ ',
441
+ warn: '▲ ',
442
+ err: '✕ ',
443
+ tool: '⚙ ',
444
+ out: ' ',
445
+ }[type] || ' ';
446
+ const line = document.createElement('div');
447
+ line.className = `term-line tl-${type}`;
448
+ const ts = new Date().toLocaleTimeString('en-GB');
449
+ line.innerHTML = `<span class="tl-ts">${ts}</span><span class="tl-pfx">${prefix}</span><span class="tl-txt"></span>`;
450
+ out.appendChild(line);
451
+ const txtEl = line.querySelector('.tl-txt');
452
+
453
+ if (stream) {
454
+ let j = 0;
455
+ const speed = 14;
456
+ const type_ = () => {
457
+ txtEl.textContent = text.slice(0, j);
458
+ j++;
459
+ out.scrollTop = out.scrollHeight;
460
+ if (j <= text.length) setTimeout(type_, speed);
461
+ };
462
+ type_();
463
+ } else {
464
+ txtEl.textContent = text;
465
+ }
466
+ out.scrollTop = out.scrollHeight;
467
+ // 限制行数
468
+ while (out.children.length > 80) out.firstChild?.remove();
469
+ }
470
+
471
+ /* ─────────────────────────────────────────────
472
+ WIDGET 9: AI 浏览器 (browser) — 网页操作可视化
473
+ 模拟 Agent 浏览网页:地址栏 · 加载流 · 操作高亮(点击/输入/滚动)
474
+ ───────────────────────────────────────────── */
475
+ WidgetRuntime.register({
476
+ id: 'browser',
477
+ title: 'AI 浏览器 · BROWSE',
478
+ icon: '◍',
479
+ defaultColumn: 'center',
480
+ size: { maxH: 300, flex: false },
481
+ render(el, ctx) {
482
+ el.innerHTML = `
483
+ <div class="brz">
484
+ <div class="brz-bar">
485
+ <div class="brz-dots"><span></span><span></span><span></span></div>
486
+ <div class="brz-url" data-role="brz-url">about:standby</div>
487
+ <div class="brz-status" data-role="brz-status">IDLE</div>
488
+ </div>
489
+ <div class="brz-progress" data-role="brz-progress"></div>
490
+ <div class="brz-viewport" data-role="brz-viewport">
491
+ <div class="brz-empty">浏览器待命 · 等待 Agent 导航指令</div>
492
+ </div>
493
+ </div>`;
494
+ ctx._browserEl = el;
495
+ ctx.browseTo = (url, actions) => _brzNavigate(el, url, actions);
496
+ },
497
+ });
498
+
499
+ function _brzNavigate(el, url, actions) {
500
+ const urlEl = el.querySelector('[data-role="brz-url"]');
501
+ const statusEl = el.querySelector('[data-role="brz-status"]');
502
+ const progEl = el.querySelector('[data-role="brz-progress"]');
503
+ const vp = el.querySelector('[data-role="brz-viewport"]');
504
+ if (!vp) return;
505
+
506
+ urlEl.textContent = url;
507
+ statusEl.textContent = 'LOADING';
508
+ statusEl.className = 'brz-status loading';
509
+
510
+ // 进度条动画
511
+ progEl.style.width = '0%';
512
+ progEl.style.opacity = '1';
513
+ setTimeout(() => progEl.style.width = '70%', 80);
514
+ setTimeout(() => { progEl.style.width = '100%'; }, 700);
515
+ setTimeout(() => { progEl.style.opacity = '0'; statusEl.textContent = 'LOADED'; statusEl.className = 'brz-status loaded'; }, 950);
516
+
517
+ // 渲染一个抽象的"网页骨架" + 操作高亮
518
+ vp.innerHTML = `
519
+ <div class="brz-page">
520
+ <div class="brz-skel brz-skel-title"></div>
521
+ <div class="brz-skel brz-skel-nav">
522
+ <span></span><span></span><span></span><span></span>
523
+ </div>
524
+ <div class="brz-hero"></div>
525
+ <div class="brz-skel brz-skel-line w90"></div>
526
+ <div class="brz-skel brz-skel-line w75"></div>
527
+ <div class="brz-skel brz-skel-line w85"></div>
528
+ <div class="brz-cards">
529
+ <div class="brz-card"></div><div class="brz-card"></div><div class="brz-card"></div>
530
+ </div>
531
+ <div class="brz-cursor" data-role="brz-cursor">➤</div>
532
+ </div>`;
533
+
534
+ // AI 操作序列高亮
535
+ const acts = actions || [
536
+ { type: 'scan', label: '解析页面结构', x: 50, y: 20 },
537
+ { type: 'click', label: '点击主内容区', x: 30, y: 45 },
538
+ { type: 'read', label: '提取关键信息', x: 60, y: 65 },
539
+ { type: 'extract', label: '写入记忆库', x: 50, y: 80 },
540
+ ];
541
+ const cursor = vp.querySelector('[data-role="brz-cursor"]');
542
+ let i = 0;
543
+ const runAct = () => {
544
+ if (i >= acts.length || !cursor) { if (cursor) cursor.style.opacity = '0'; return; }
545
+ const a = acts[i];
546
+ cursor.style.opacity = '1';
547
+ cursor.style.left = a.x + '%';
548
+ cursor.style.top = a.y + '%';
549
+ cursor.setAttribute('data-label', a.label);
550
+ cursor.className = `brz-cursor act-${a.type}`;
551
+ // 涟漪
552
+ const ripple = document.createElement('div');
553
+ ripple.className = 'brz-ripple';
554
+ ripple.style.left = a.x + '%';
555
+ ripple.style.top = a.y + '%';
556
+ vp.querySelector('.brz-page')?.appendChild(ripple);
557
+ setTimeout(() => ripple.remove(), 600);
558
+ i++;
559
+ setTimeout(runAct, 750);
560
+ };
561
+ setTimeout(runAct, 1000);
562
+ }
563
+
564
+ /* ─────────────────────────────────────────────
565
+ WIDGET 10: 语音输入 (voice) — 麦克风波形 + 语音识别
566
+ Web Audio API 真实波形 + 浏览器原生 SpeechRecognition
567
+ 识别结果可直接作为指令传输给激活 Agent
568
+ ───────────────────────────────────────────── */
569
+ WidgetRuntime.register({
570
+ id: 'voice',
571
+ title: '语音输入 · VOICE',
572
+ icon: '◉',
573
+ defaultColumn: 'right',
574
+ size: { maxH: 200, flex: false },
575
+ render(el, ctx) {
576
+ el.innerHTML = `
577
+ <div class="voice">
578
+ <canvas class="voice-wave" data-role="voice-wave"></canvas>
579
+ <div class="voice-transcript" data-role="voice-transcript">点击麦克风开始语音指令</div>
580
+ <div class="voice-controls">
581
+ <button class="voice-mic" data-role="voice-mic" title="开始/停止录音">◉</button>
582
+ <div class="voice-meta">
583
+ <div class="voice-state" data-role="voice-state">待命</div>
584
+ <div class="voice-hint">支持中文 · 识别后可一键传输</div>
585
+ </div>
586
+ <button class="voice-send" data-role="voice-send" disabled title="传输识别结果">传输 ❯</button>
587
+ </div>
588
+ </div>`;
589
+ _voiceInit(el, ctx);
590
+ },
591
+ });
592
+
593
+ function _voiceInit(el, ctx) {
594
+ const canvas = el.querySelector('[data-role="voice-wave"]');
595
+ const transcriptEl = el.querySelector('[data-role="voice-transcript"]');
596
+ const micBtn = el.querySelector('[data-role="voice-mic"]');
597
+ const sendBtn = el.querySelector('[data-role="voice-send"]');
598
+ const stateEl = el.querySelector('[data-role="voice-state"]');
599
+
600
+ let audioCtx = null, analyser = null, dataArr = null, rafId = null, stream = null;
601
+ let recognition = null, recognizing = false, finalText = '';
602
+
603
+ // 语音识别(浏览器原生)
604
+ const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
605
+ if (SR) {
606
+ recognition = new SR();
607
+ recognition.lang = 'zh-CN';
608
+ recognition.continuous = true;
609
+ recognition.interimResults = true;
610
+ recognition.onresult = (e) => {
611
+ let interim = '', final = '';
612
+ for (let i = e.resultIndex; i < e.results.length; i++) {
613
+ const t = e.results[i][0].transcript;
614
+ if (e.results[i].isFinal) final += t; else interim += t;
615
+ }
616
+ if (final) finalText += final;
617
+ transcriptEl.textContent = (finalText + interim) || '聆听中...';
618
+ transcriptEl.classList.add('has-text');
619
+ sendBtn.disabled = !(finalText || interim).trim();
620
+ };
621
+ recognition.onerror = (e) => { stateEl.textContent = '识别错误: ' + e.error; };
622
+ } else {
623
+ transcriptEl.textContent = '此浏览器不支持语音识别(需 Chrome/Edge)';
624
+ }
625
+
626
+ function drawWave() {
627
+ if (!analyser) return;
628
+ rafId = requestAnimationFrame(drawWave);
629
+ analyser.getByteTimeDomainData(dataArr);
630
+ const w = canvas.width, h = canvas.height;
631
+ const cx = canvas.getContext('2d');
632
+ cx.clearRect(0, 0, w, h);
633
+ cx.lineWidth = 2;
634
+ cx.strokeStyle = '#1de9ff';
635
+ cx.shadowBlur = 8; cx.shadowColor = 'rgba(29,233,255,0.6)';
636
+ cx.beginPath();
637
+ const slice = w / dataArr.length;
638
+ let x = 0;
639
+ for (let i = 0; i < dataArr.length; i++) {
640
+ const v = dataArr[i] / 128.0;
641
+ const y = (v * h) / 2;
642
+ if (i === 0) cx.moveTo(x, y); else cx.lineTo(x, y);
643
+ x += slice;
644
+ }
645
+ cx.lineTo(w, h / 2);
646
+ cx.stroke();
647
+ }
648
+
649
+ async function startMic() {
650
+ try {
651
+ stream = await navigator.mediaDevices.getUserMedia({ audio: true });
652
+ audioCtx = new (window.AudioContext || window.webkitAudioContext)();
653
+ analyser = audioCtx.createAnalyser();
654
+ analyser.fftSize = 256;
655
+ dataArr = new Uint8Array(analyser.frequencyBinCount);
656
+ audioCtx.createMediaStreamSource(stream).connect(analyser);
657
+ canvas.width = canvas.offsetWidth; canvas.height = canvas.offsetHeight;
658
+ drawWave();
659
+ if (recognition) { finalText = ''; recognition.start(); }
660
+ recognizing = true;
661
+ micBtn.classList.add('recording');
662
+ stateEl.textContent = '● 录音中';
663
+ stateEl.style.color = '#ff4060';
664
+ } catch (err) {
665
+ stateEl.textContent = '麦克风权限被拒';
666
+ transcriptEl.textContent = '无法访问麦克风 · 请检查浏览器权限';
667
+ }
668
+ }
669
+
670
+ function stopMic() {
671
+ recognizing = false;
672
+ micBtn.classList.remove('recording');
673
+ stateEl.textContent = '待命';
674
+ stateEl.style.color = '';
675
+ if (rafId) cancelAnimationFrame(rafId);
676
+ if (recognition) try { recognition.stop(); } catch {}
677
+ if (stream) stream.getTracks().forEach(t => t.stop());
678
+ if (audioCtx) try { audioCtx.close(); } catch {}
679
+ const cx = canvas.getContext('2d');
680
+ if (cx) cx.clearRect(0, 0, canvas.width, canvas.height);
681
+ }
682
+
683
+ micBtn.onclick = () => recognizing ? stopMic() : startMic();
684
+ sendBtn.onclick = () => {
685
+ const text = transcriptEl.textContent.trim();
686
+ if (!text || text === '聆听中...') return;
687
+ stopMic();
688
+ // 把识别结果填入控制台并传输
689
+ const input = document.getElementById('consoleInput');
690
+ if (input) { input.value = text; }
691
+ if (typeof transmit === 'function') transmit();
692
+ transcriptEl.textContent = '已传输 → 控制台';
693
+ transcriptEl.classList.remove('has-text');
694
+ sendBtn.disabled = true;
695
+ };
696
+ }