@capyclaw/browser-suite 0.1.2 → 0.2.37

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 (217) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -5
  3. package/composition.lock.json +37 -25
  4. package/contract/browser-contract.json +484 -25
  5. package/cordis.patch.yml +3 -9
  6. package/dsh-suite.json +110 -82
  7. package/lib/index.mjs +1 -1
  8. package/node_modules/@capyclaw/asset-service/README.md +48 -0
  9. package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
  10. package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
  11. package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
  12. package/node_modules/@capyclaw/asset-service/package.json +59 -0
  13. package/node_modules/@capyclaw/asset-service/src/index.mjs +304 -0
  14. package/node_modules/@capyclaw/browser-skill-api/README.md +3 -0
  15. package/node_modules/@capyclaw/browser-skill-api/contract/browser-contract.json +1349 -0
  16. package/node_modules/@capyclaw/browser-skill-api/cordis.patch.yml +4 -0
  17. package/node_modules/@capyclaw/browser-skill-api/package.json +49 -0
  18. package/node_modules/@capyclaw/browser-skill-api/plugin.mjs +15 -0
  19. package/node_modules/@capyclaw/browser-skill-api/skills/browser-api/SKILL.md +85 -0
  20. package/node_modules/@capyclaw/browser-skill-api/skills/browser-api/references/tool-contract.md +692 -0
  21. package/node_modules/@capyclaw/browser-skill-browser/README.md +3 -0
  22. package/node_modules/@capyclaw/browser-skill-browser/contract/browser-contract.json +1349 -0
  23. package/node_modules/@capyclaw/browser-skill-browser/cordis.patch.yml +4 -0
  24. package/node_modules/@capyclaw/browser-skill-browser/package.json +49 -0
  25. package/node_modules/@capyclaw/browser-skill-browser/plugin.mjs +15 -0
  26. package/node_modules/@capyclaw/browser-skill-browser/skills/browser/SKILL.md +27 -0
  27. package/node_modules/@capyclaw/browser-skill-ops/README.md +3 -0
  28. package/node_modules/@capyclaw/browser-skill-ops/contract/browser-contract.json +1349 -0
  29. package/node_modules/@capyclaw/browser-skill-ops/cordis.patch.yml +4 -0
  30. package/node_modules/@capyclaw/browser-skill-ops/package.json +49 -0
  31. package/node_modules/@capyclaw/browser-skill-ops/plugin.mjs +15 -0
  32. package/node_modules/@capyclaw/browser-skill-ops/skills/browser-ops/SKILL.md +63 -0
  33. package/node_modules/@capyclaw/browser-workbench/README.md +89 -0
  34. package/node_modules/@capyclaw/browser-workbench/contract/browser-contract.json +1349 -0
  35. package/node_modules/@capyclaw/browser-workbench/demo/form.html +112 -0
  36. package/node_modules/@capyclaw/browser-workbench/lib/host.mjs +1 -0
  37. package/node_modules/@capyclaw/browser-workbench/package.json +71 -0
  38. package/node_modules/@capyclaw/browser-workbench/plugin.mjs +1 -0
  39. package/node_modules/@capyclaw/browser-workbench/server/constants.mjs +16 -0
  40. package/node_modules/@capyclaw/browser-workbench/server/contract-snapshots.mjs +81 -0
  41. package/node_modules/@capyclaw/browser-workbench/server/contract.mjs +24 -0
  42. package/node_modules/@capyclaw/browser-workbench/server/embedded-host.mjs +247 -0
  43. package/node_modules/@capyclaw/browser-workbench/server/engine.mjs +2466 -0
  44. package/node_modules/@capyclaw/browser-workbench/server/governor.mjs +189 -0
  45. package/node_modules/@capyclaw/browser-workbench/server/http-utils.mjs +2 -0
  46. package/node_modules/@capyclaw/browser-workbench/server/human.mjs +628 -0
  47. package/node_modules/@capyclaw/browser-workbench/server/infra/http.mjs +2 -0
  48. package/node_modules/@capyclaw/browser-workbench/server/infra/tuning.mjs +2 -0
  49. package/node_modules/@capyclaw/browser-workbench/server/input.mjs +154 -0
  50. package/node_modules/@capyclaw/browser-workbench/server/login-vault.mjs +109 -0
  51. package/node_modules/@capyclaw/browser-workbench/server/mcp/handler.mjs +2 -0
  52. package/node_modules/@capyclaw/browser-workbench/server/mcp/instructions.mjs +31 -0
  53. package/node_modules/@capyclaw/browser-workbench/server/orphans.mjs +163 -0
  54. package/node_modules/@capyclaw/browser-workbench/server/relay.mjs +198 -0
  55. package/node_modules/@capyclaw/browser-workbench/server/routes/api.mjs +233 -0
  56. package/node_modules/@capyclaw/browser-workbench/server/routes/assets.mjs +2 -0
  57. package/node_modules/@capyclaw/browser-workbench/server/routes/mcp.mjs +17 -0
  58. package/node_modules/@capyclaw/browser-workbench/server/routes/workbench.mjs +33 -0
  59. package/node_modules/@capyclaw/browser-workbench/server/session-engines.mjs +223 -0
  60. package/node_modules/@capyclaw/browser-workbench/server/shared/SHARED_MANIFEST.json +70 -0
  61. package/node_modules/@capyclaw/browser-workbench/server/shared/asset-service.mjs +2 -0
  62. package/node_modules/@capyclaw/browser-workbench/server/shared/editor-host.mjs +2 -0
  63. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/editor/lease.mjs +2 -0
  64. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/service/api.mjs +2 -0
  65. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/service/http.mjs +2 -0
  66. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/service/mcp-http.mjs +2 -0
  67. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/tools/validate.mjs +2 -0
  68. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/tuning.mjs +2 -0
  69. package/node_modules/@capyclaw/browser-workbench/server/shared/kit/util/fs-lock.mjs +2 -0
  70. package/node_modules/@capyclaw/browser-workbench/server/shared/service-host.mjs +2 -0
  71. package/node_modules/@capyclaw/browser-workbench/server/shared/tool-host.mjs +2 -0
  72. package/node_modules/@capyclaw/browser-workbench/server/shared/tuning.mjs +2 -0
  73. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/contract.mjs +55 -0
  74. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/evaluate.mjs +36 -0
  75. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/index.mjs +26 -0
  76. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/interaction.mjs +215 -0
  77. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/navigation.mjs +35 -0
  78. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/screenshot.mjs +50 -0
  79. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/session.mjs +81 -0
  80. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/snapshot.mjs +30 -0
  81. package/node_modules/@capyclaw/browser-workbench/server/tools/capabilities/tabs.mjs +35 -0
  82. package/node_modules/@capyclaw/browser-workbench/server/tools/index.mjs +12 -0
  83. package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/define.mjs +5 -0
  84. package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/output.mjs +30 -0
  85. package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/ports.mjs +59 -0
  86. package/node_modules/@capyclaw/browser-workbench/server/tools/kernel/registry.mjs +17 -0
  87. package/node_modules/@capyclaw/browser-workbench/server/tools.mjs +3 -0
  88. package/node_modules/@capyclaw/browser-workbench/server/workbench-framework.mjs +305 -0
  89. package/node_modules/@capyclaw/browser-workbench/ui/app.js +447 -0
  90. package/node_modules/@capyclaw/browser-workbench/ui/index.html +46 -0
  91. package/node_modules/@capyclaw/browser-workbench/ui/style.css +144 -0
  92. package/node_modules/@capyclaw/document-workbench/README.md +125 -0
  93. package/node_modules/@capyclaw/document-workbench/package.json +44 -0
  94. package/node_modules/@capyclaw/document-workbench/src/bridge/index.mjs +321 -0
  95. package/node_modules/@capyclaw/document-workbench/src/client/index.mjs +625 -0
  96. package/node_modules/@capyclaw/document-workbench/src/client/screenshot.mjs +98 -0
  97. package/node_modules/@capyclaw/document-workbench/src/index.mjs +9 -0
  98. package/node_modules/@capyclaw/document-workbench/src/model/audit.mjs +101 -0
  99. package/node_modules/@capyclaw/document-workbench/src/model/conformance.mjs +92 -0
  100. package/node_modules/@capyclaw/document-workbench/src/model/ids.mjs +56 -0
  101. package/node_modules/@capyclaw/document-workbench/src/model/index.mjs +18 -0
  102. package/node_modules/@capyclaw/document-workbench/src/model/locate.mjs +118 -0
  103. package/node_modules/@capyclaw/document-workbench/src/model/manifest.mjs +148 -0
  104. package/node_modules/@capyclaw/document-workbench/src/model/ops.mjs +160 -0
  105. package/node_modules/@capyclaw/document-workbench/src/model/validate.mjs +72 -0
  106. package/node_modules/@capyclaw/document-workbench/src/ops/index.mjs +93 -0
  107. package/node_modules/@capyclaw/document-workbench/src/session/context.mjs +103 -0
  108. package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +394 -0
  109. package/node_modules/@capyclaw/document-workbench/src/session/lease.mjs +105 -0
  110. package/node_modules/@capyclaw/document-workbench/src/session/mode.mjs +80 -0
  111. package/node_modules/@capyclaw/document-workbench/src/session/sanitize.mjs +107 -0
  112. package/node_modules/@capyclaw/document-workbench/src/session/state.mjs +159 -0
  113. package/node_modules/@capyclaw/document-workbench/src/session/watch.mjs +63 -0
  114. package/node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs +158 -0
  115. package/node_modules/@capyclaw/document-workbench/src/testing/index.mjs +75 -0
  116. package/node_modules/@capyclaw/foundation/README.md +51 -0
  117. package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
  118. package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
  119. package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
  120. package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
  121. package/node_modules/@capyclaw/foundation/abi/loader.mjs +345 -0
  122. package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
  123. package/node_modules/@capyclaw/foundation/abi/spec.mjs +255 -0
  124. package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
  125. package/node_modules/@capyclaw/foundation/abi/version.mjs +82 -0
  126. package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
  127. package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
  128. package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
  129. package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
  130. package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
  131. package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
  132. package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
  133. package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +69 -0
  134. package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +120 -0
  135. package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
  136. package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
  137. package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
  138. package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
  139. package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
  140. package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +34 -0
  141. package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
  142. package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
  143. package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +160 -0
  144. package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
  145. package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
  146. package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +115 -0
  147. package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
  148. package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
  149. package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +188 -0
  150. package/node_modules/@capyclaw/foundation/package.json +53 -0
  151. package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
  152. package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
  153. package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
  154. package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
  155. package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
  156. package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
  157. package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
  158. package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
  159. package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +139 -0
  160. package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
  161. package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
  162. package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
  163. package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
  164. package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
  165. package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
  166. package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
  167. package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
  168. package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
  169. package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
  170. package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
  171. package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
  172. package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
  173. package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
  174. package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
  175. package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
  176. package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
  177. package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
  178. package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
  179. package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
  180. package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
  181. package/node_modules/@capyclaw/portal/README.md +70 -0
  182. package/node_modules/@capyclaw/portal/lib/index.mjs +387 -0
  183. package/node_modules/@capyclaw/portal/lib/ledger.mjs +194 -0
  184. package/node_modules/@capyclaw/portal/lib/portal-agent.ps1 +811 -0
  185. package/node_modules/@capyclaw/portal/lib/portal-darwin.mjs +183 -0
  186. package/node_modules/@capyclaw/portal/package.json +40 -0
  187. package/node_modules/@capyclaw/service-broker/README.md +104 -0
  188. package/node_modules/@capyclaw/service-broker/cordis.patch.yml +8 -0
  189. package/node_modules/@capyclaw/service-broker/dsh-suite.json +21 -0
  190. package/node_modules/@capyclaw/service-broker/lib/control.mjs +193 -0
  191. package/node_modules/@capyclaw/service-broker/lib/discovery.mjs +109 -0
  192. package/node_modules/@capyclaw/service-broker/lib/engine.mjs +1236 -0
  193. package/node_modules/@capyclaw/service-broker/lib/host.mjs +182 -0
  194. package/node_modules/@capyclaw/service-broker/lib/manifest.mjs +249 -0
  195. package/node_modules/@capyclaw/service-broker/lib/recovery.mjs +325 -0
  196. package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +28 -0
  197. package/node_modules/@capyclaw/service-broker/lib/spec.mjs +78 -0
  198. package/node_modules/@capyclaw/service-broker/package.json +65 -0
  199. package/node_modules/@capyclaw/service-broker/server.mjs +81 -0
  200. package/node_modules/@capyclaw/service-broker/service.schema.json +62 -0
  201. package/node_modules/@capyclaw/service-broker/services.json +3 -0
  202. package/node_modules/@capyclaw/service-host/README.md +86 -0
  203. package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
  204. package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
  205. package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
  206. package/node_modules/@capyclaw/service-host/package.json +60 -0
  207. package/node_modules/@capyclaw/service-host/src/index.mjs +571 -0
  208. package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
  209. package/node_modules/@capyclaw/tool-host/README.md +56 -0
  210. package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
  211. package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
  212. package/node_modules/@capyclaw/tool-host/lib/host.mjs +16 -0
  213. package/node_modules/@capyclaw/tool-host/package.json +59 -0
  214. package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +166 -0
  215. package/node_modules/@capyclaw/tool-host/src/index.mjs +416 -0
  216. package/package.json +31 -14
  217. package/services.json +1 -21
@@ -0,0 +1,55 @@
1
+ /** 契约探测能力:版本、工具清单、能力清单与引擎状态。 */
2
+ import { defineCapability, defineTool } from '../kernel/define.mjs'
3
+ import { runTool } from '../kernel/output.mjs'
4
+
5
+ export const contractCapability = defineCapability({
6
+ id: 'contract',
7
+ title: '契约探测',
8
+ tags: ['meta'],
9
+ requires: ['engine', 'server'],
10
+ features: ['browser.contract'],
11
+ tools: [
12
+ defineTool({
13
+ name: 'browser_capabilities',
14
+ description: '返回工作台契约版本、工具清单、能力清单与引擎状态。skill 加载后先调用一次;工具缺失或 major 版本不一致时停止并提示升级。默认紧凑模式(只给名字/状态,省 token);需要能力描述与 tags 时传 detail="full"。',
15
+ inputSchema: {
16
+ type: 'object',
17
+ properties: { detail: { type: 'string', enum: ['compact', 'full'], description: '报告详细度,默认 compact' } },
18
+ additionalProperties: false,
19
+ },
20
+ kind: 'read',
21
+ since: '1.0.0',
22
+ handler: async (args, ctx) => runTool(async () => {
23
+ let runtime = { engineRunning: false, tabs: 0, headless: null, evaluateEnabled: false }
24
+ try {
25
+ const status = await ctx.engine.status()
26
+ runtime = {
27
+ engineRunning: !!status.running,
28
+ tabs: status.tabs.length,
29
+ headless: !!status.headless,
30
+ evaluateEnabled: !!status.evaluateEnabled,
31
+ }
32
+ } catch { /* 引擎未绑定时仍返回静态契约 */ }
33
+ let workbenchUrl = ''
34
+ try { workbenchUrl = ctx.server.url() } catch { /* 保持空 */ }
35
+ const report = ctx.contract.report(workbenchUrl, runtime)
36
+ if ((args && args.detail) === 'full') return JSON.stringify(report, null, 2)
37
+ /* 紧凑模式:保留契约/状态/工具名,去掉能力描述、tags、features 等模型路由用不到的胖字段。 */
38
+ const compact = {
39
+ contractVersion: report.contractVersion,
40
+ packageVersion: report.packageVersion,
41
+ editorUrl: report.editorUrl,
42
+ editorPath: report.editorPath,
43
+ engineRunning: report.engineRunning,
44
+ tabs: report.tabs,
45
+ headless: report.headless,
46
+ evaluateEnabled: report.evaluateEnabled,
47
+ toolCount: report.toolCount,
48
+ tools: (report.tools || []).map((t) => t.name),
49
+ capabilities: (report.capabilities || []).map((c) => ({ id: c.id, tools: c.tools })),
50
+ }
51
+ return JSON.stringify(compact, null, 2)
52
+ }),
53
+ }),
54
+ ],
55
+ })
@@ -0,0 +1,36 @@
1
+ /**
2
+ * 脚本执行能力:默认关闭(安全默认),如实返回 NOT_IMPLEMENTED。
3
+ *
4
+ * 与 scrapling 的诚实边界同一口径:不伪造结果、返回结构化错误与开启方法。
5
+ */
6
+ import { defineCapability, defineTool } from '../kernel/define.mjs'
7
+ import { runTool } from '../kernel/output.mjs'
8
+
9
+ export const evaluateCapability = defineCapability({
10
+ id: 'evaluate',
11
+ title: '页面脚本',
12
+ tags: ['advanced'],
13
+ requires: ['engine'],
14
+ features: ['browser.evaluate'],
15
+ tools: [
16
+ defineTool({
17
+ name: 'browser_evaluate',
18
+ description: '在页面里执行 JS 表达式并返回结果。默认关闭(安全默认);关闭时返回 NOT_IMPLEMENTED 与开启方法。优先用快照+ref 完成任务,本工具留给快照覆盖不了的场景。',
19
+ inputSchema: {
20
+ type: 'object',
21
+ properties: {
22
+ script: { type: 'string', maxLength: 20000, description: 'JS 表达式(如 document.title)' },
23
+ tab: { type: 'string', maxLength: 16, description: '目标标签页 id(缺省=当前活动标签页)' },
24
+ },
25
+ required: ['script'],
26
+ additionalProperties: false,
27
+ },
28
+ kind: 'write',
29
+ since: '1.0.0',
30
+ handler: async (args, ctx) => runTool(async () => {
31
+ const out = await ctx.engine.evaluate({ script: args.script, tab: args.tab })
32
+ return JSON.stringify({ tab: out.tab, result: out.result }, null, 2)
33
+ }),
34
+ }),
35
+ ],
36
+ })
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 能力清单:唯一扩展点。
3
+ *
4
+ * 新增能力:新建 capabilities/<id>.mjs,导出 defineCapability(...),
5
+ * 然后在这里加一行 import 和数组项即可。contract / instructions / 测试
6
+ * 全部由 registry 自动派生。
7
+ */
8
+ import { contractCapability } from './contract.mjs'
9
+ import { navigationCapability } from './navigation.mjs'
10
+ import { snapshotCapability } from './snapshot.mjs'
11
+ import { interactionCapability } from './interaction.mjs'
12
+ import { tabsCapability } from './tabs.mjs'
13
+ import { screenshotCapability } from './screenshot.mjs'
14
+ import { sessionCapability } from './session.mjs'
15
+ import { evaluateCapability } from './evaluate.mjs'
16
+
17
+ export const CAPABILITIES = [
18
+ contractCapability,
19
+ navigationCapability,
20
+ snapshotCapability,
21
+ interactionCapability,
22
+ tabsCapability,
23
+ screenshotCapability,
24
+ sessionCapability,
25
+ evaluateCapability,
26
+ ]
@@ -0,0 +1,215 @@
1
+ /** 交互能力:点击 / 填写 / 按键 / 下拉选择 / 滚动(动作后自动返回新快照)。 */
2
+ import { defineCapability, defineTool } from '../kernel/define.mjs'
3
+ import { runTool } from '../kernel/output.mjs'
4
+
5
+ const TAB_PROP = { type: 'string', maxLength: 16, description: '目标标签页 id(缺省=当前活动标签页)' }
6
+
7
+ export const interactionCapability = defineCapability({
8
+ id: 'interaction',
9
+ title: '页面交互',
10
+ tags: ['core'],
11
+ requires: ['engine'],
12
+ features: ['browser.interaction'],
13
+ tools: [
14
+ defineTool({
15
+ name: 'browser_click',
16
+ description: '点击元素。ref 来自最近一次快照(首选);快照里没有的元素(无 role 的 div 按钮等)用 selector 或 text 兜底。元素已变化时报 STALE_SNAPSHOT,重新快照后用新 ref。动作成功后返回新快照。',
17
+ inputSchema: {
18
+ type: 'object',
19
+ properties: {
20
+ ref: { type: 'string', maxLength: 16, description: '快照里的元素引用,如 e5(首选)' },
21
+ selector: { type: 'string', maxLength: 300, description: 'CSS 选择器兜底,如 .next-btn' },
22
+ text: { type: 'string', maxLength: 120, description: '可见文案兜底,如「下一步」' },
23
+ tab: TAB_PROP,
24
+ },
25
+ additionalProperties: false,
26
+ },
27
+ kind: 'write',
28
+ since: '1.0.0',
29
+ handler: async (args, ctx) => runTool(async () => {
30
+ const out = await ctx.engine.click({ ref: args.ref, selector: args.selector, text: args.text, tab: args.tab })
31
+ return `已点击 ${out.clicked}(标签页 ${out.tab})${out.snapshot.authWall ? `\n⚠ ${out.snapshot.authWall}` : ''}\n\n${out.snapshot.text}`
32
+ }),
33
+ }),
34
+ defineTool({
35
+ name: 'browser_drag',
36
+ description: '拖拽:滑块验证、拖放排序。起点可以给 ref / selector / text;终点给 toRef / toSelector / toText,或直接用 dx/dy 相对位移(滑块常用 dx)。内部按多步轨迹移动再松手,比一步到位更像人。成功后返回新快照。',
37
+ inputSchema: {
38
+ type: 'object',
39
+ properties: {
40
+ ref: { type: 'string', maxLength: 16, description: '起点 ref(首选)' },
41
+ selector: { type: 'string', maxLength: 300, description: '起点 CSS 选择器兜底' },
42
+ text: { type: 'string', maxLength: 120, description: '起点可见文案兜底' },
43
+ toRef: { type: 'string', maxLength: 16, description: '终点 ref' },
44
+ toSelector: { type: 'string', maxLength: 300, description: '终点 CSS 选择器' },
45
+ toText: { type: 'string', maxLength: 120, description: '终点可见文案' },
46
+ dx: { type: 'number', description: '相对起点的横向位移(滑块向右为正)' },
47
+ dy: { type: 'number', description: '相对起点的纵向位移' },
48
+ steps: { type: 'number', description: '轨迹分几步(默认 24,越大越平滑)' },
49
+ tab: TAB_PROP,
50
+ },
51
+ additionalProperties: false,
52
+ },
53
+ kind: 'write',
54
+ since: '1.2.0',
55
+ handler: async (args, ctx) => runTool(async () => {
56
+ const out = await ctx.engine.drag({
57
+ ref: args.ref, selector: args.selector, text: args.text,
58
+ toRef: args.toRef, toSelector: args.toSelector, toText: args.toText,
59
+ dx: args.dx, dy: args.dy, steps: args.steps, tab: args.tab,
60
+ })
61
+ return `已拖拽 ${out.moved.from} → (${out.moved.to}),位移 ${out.moved.distance}px(标签页 ${out.tab})${out.snapshot.authWall ? `\n⚠ ${out.snapshot.authWall}` : ''}\n\n${out.snapshot.text}`
62
+ }),
63
+ }),
64
+ defineTool({
65
+ name: 'browser_fill',
66
+ description: '在输入框/文本域填写文字(整体替换,兼容 React/Vue 受控输入)。submit=true 时填写后按回车提交。密码框会被快照掩码显示,但填写不受影响。',
67
+ inputSchema: {
68
+ type: 'object',
69
+ properties: {
70
+ ref: { type: 'string', maxLength: 16, description: '目标输入框的 ref' },
71
+ text: { type: 'string', maxLength: 10000, description: '要填入的文字(空字符串=清空)' },
72
+ submit: { type: 'boolean', description: '填写后按 Enter 提交(默认 false)' },
73
+ tab: TAB_PROP,
74
+ },
75
+ required: ['ref', 'text'],
76
+ additionalProperties: false,
77
+ },
78
+ kind: 'write',
79
+ since: '1.0.0',
80
+ handler: async (args, ctx) => runTool(async () => {
81
+ const out = await ctx.engine.fill({ ref: args.ref, text: args.text, submit: args.submit, tab: args.tab })
82
+ return `已填写 ${out.filled}${out.submit ? ' 并回车提交' : ''}(标签页 ${out.tab})${out.snapshot.authWall ? `\n⚠ ${out.snapshot.authWall}` : ''}\n\n${out.snapshot.text}`
83
+ }),
84
+ }),
85
+ defineTool({
86
+ name: 'browser_press',
87
+ description: '按键。给 ref 时在指定元素上按(如输入框内 Enter),不给 ref 时对当前页面按(如 Tab / Escape / Control+a)。',
88
+ inputSchema: {
89
+ type: 'object',
90
+ properties: {
91
+ key: { type: 'string', maxLength: 40, description: '键名:Enter / Tab / Escape / ArrowDown / Control+a 等(Playwright 键名)' },
92
+ ref: { type: 'string', maxLength: 16, description: '目标元素 ref(缺省=页面级按键)' },
93
+ tab: TAB_PROP,
94
+ },
95
+ required: ['key'],
96
+ additionalProperties: false,
97
+ },
98
+ kind: 'write',
99
+ since: '1.0.0',
100
+ handler: async (args, ctx) => runTool(async () => {
101
+ const out = await ctx.engine.press({ key: args.key, ref: args.ref, tab: args.tab })
102
+ return `已按键 ${out.key}(标签页 ${out.tab})${out.snapshot.authWall ? `\n⚠ ${out.snapshot.authWall}` : ''}\n\n${out.snapshot.text}`
103
+ }),
104
+ }),
105
+ defineTool({
106
+ name: 'browser_select',
107
+ description: '选择下拉框(select)的选项。value 先按 <option value> 匹配,失败自动按选项文本匹配。',
108
+ inputSchema: {
109
+ type: 'object',
110
+ properties: {
111
+ ref: { type: 'string', maxLength: 16, description: '目标下拉框的 ref' },
112
+ value: { type: 'string', maxLength: 300, description: '选项的 value 或可见文本' },
113
+ tab: TAB_PROP,
114
+ },
115
+ required: ['ref', 'value'],
116
+ additionalProperties: false,
117
+ },
118
+ kind: 'write',
119
+ since: '1.0.0',
120
+ handler: async (args, ctx) => runTool(async () => {
121
+ const out = await ctx.engine.select({ ref: args.ref, value: args.value, tab: args.tab })
122
+ return `已选择 ${out.selected}(标签页 ${out.tab})${out.snapshot.authWall ? `\n⚠ ${out.snapshot.authWall}` : ''}\n\n${out.snapshot.text}`
123
+ }),
124
+ }),
125
+ defineTool({
126
+ name: 'browser_upload',
127
+ description: '给文件上传控件(<input type="file">)设置本机文件。ref/selector 定位上传控件;files 是本机绝对路径数组(可多选),空数组=清空已选。闭环里 ppt 等套件产出的文件先物化成本机路径再传这里。成功后返回新快照。',
128
+ inputSchema: {
129
+ type: 'object',
130
+ properties: {
131
+ ref: { type: 'string', maxLength: 16, description: '上传控件的 ref(首选)' },
132
+ selector: { type: 'string', maxLength: 300, description: 'CSS 选择器兜底,如 input[type=file]' },
133
+ files: { type: 'array', items: { type: 'string', maxLength: 1000 }, maxItems: 20, description: '本机绝对路径数组;空数组=清空已选' },
134
+ tab: TAB_PROP,
135
+ },
136
+ required: ['files'],
137
+ additionalProperties: false,
138
+ },
139
+ kind: 'write',
140
+ since: '1.3.0',
141
+ handler: async (args, ctx) => runTool(async () => {
142
+ const out = await ctx.engine.upload({ ref: args.ref, selector: args.selector, files: args.files, tab: args.tab })
143
+ return `已上传 ${out.count} 个文件到 ${out.target}(标签页 ${out.tab}):${out.uploaded.join(', ') || '(清空)'}${out.snapshot.authWall ? `\n⚠ ${out.snapshot.authWall}` : ''}\n\n${out.snapshot.text}`
144
+ }),
145
+ }),
146
+ defineTool({
147
+ name: 'browser_scroll',
148
+ description: '滚动当前页面(默认向下 600px)。懒加载页面翻内容用它。',
149
+ inputSchema: {
150
+ type: 'object',
151
+ properties: {
152
+ direction: { type: 'string', enum: ['up', 'down'], description: '方向(默认 down)' },
153
+ amount: { type: 'number', description: '像素数(默认 600)' },
154
+ tab: TAB_PROP,
155
+ },
156
+ additionalProperties: false,
157
+ },
158
+ kind: 'write',
159
+ since: '1.0.0',
160
+ handler: async (args, ctx) => runTool(async () => {
161
+ const out = await ctx.engine.scroll({ direction: args.direction, amount: args.amount, tab: args.tab })
162
+ return `已滚动 ${out.scrolled}(标签页 ${out.tab})${out.snapshot.authWall ? `\n⚠ ${out.snapshot.authWall}` : ''}\n\n${out.snapshot.text}`
163
+ }),
164
+ }),
165
+ defineTool({
166
+ name: 'browser_act',
167
+ description: '把同一页面上多个不跳转的动作打包成一次调用(最多 10 步),只返回一份最终快照——替代「一步一次往返」,每条消息省下多次模型往返。典型:填账号 + 填密码 + 勾选协议 + 选城市 + 拖滑块。注意:会跳转或整页重排的动作(提交、下单、翻页)放最后一步或单独调用;中途不重拍快照,ref 沿用打包前的快照。失败会停在该步并给出原因,仍返回最新快照。',
168
+ inputSchema: {
169
+ type: 'object',
170
+ properties: {
171
+ steps: {
172
+ type: 'array',
173
+ maxItems: 10,
174
+ description: '按顺序执行的动作列表',
175
+ items: {
176
+ type: 'object',
177
+ properties: {
178
+ op: { type: 'string', enum: ['click', 'fill', 'press', 'select', 'drag', 'scroll', 'wait'], description: '动作类型' },
179
+ ref: { type: 'string', maxLength: 16, description: '目标 ref(click/fill/press/select/drag 的起点)' },
180
+ selector: { type: 'string', maxLength: 300, description: 'click/fill/press 的 CSS 兜底;wait 时是等待的选择器' },
181
+ text: { type: 'string', maxLength: 10000, description: 'fill 的文字;click 时是目标文案' },
182
+ submit: { type: 'boolean', description: 'fill 之后回车提交' },
183
+ key: { type: 'string', maxLength: 40, description: 'press 的键名,如 Enter / Tab' },
184
+ value: { type: 'string', maxLength: 300, description: 'select 的选项 value 或文本' },
185
+ toRef: { type: 'string', maxLength: 16, description: 'drag 的终点 ref' },
186
+ toSelector: { type: 'string', maxLength: 300, description: 'drag 的终点选择器' },
187
+ dx: { type: 'number', description: 'drag 的相对横向位移(滑块向右为正)' },
188
+ dy: { type: 'number', description: 'drag 的相对纵向位移' },
189
+ direction: { type: 'string', enum: ['up', 'down'], description: 'scroll 方向' },
190
+ amount: { type: 'number', description: 'scroll 像素数(默认 600)' },
191
+ ms: { type: 'number', description: 'wait 毫秒数' },
192
+ },
193
+ required: ['op'],
194
+ additionalProperties: false,
195
+ },
196
+ },
197
+ stopOnError: { type: 'boolean', description: '某步失败后是否停止(默认 true)' },
198
+ tab: TAB_PROP,
199
+ },
200
+ required: ['steps'],
201
+ additionalProperties: false,
202
+ },
203
+ kind: 'write',
204
+ since: '1.1.0',
205
+ handler: async (args, ctx) => runTool(async () => {
206
+ const out = await ctx.engine.act({ steps: args.steps, tab: args.tab, stopOnError: args.stopOnError !== false })
207
+ const lines = out.results.map((r) => `${r.index + 1}. ${r.op || '(空)'} ${r.ok ? '✓' : `✗ ${r.error}`}`)
208
+ const head = out.failed < 0
209
+ ? `已连做 ${out.results.length} 步(标签页 ${out.tab})`
210
+ : `第 ${out.failed + 1} 步失败,此前已完成 ${out.results.filter((r) => r.ok).length} 步(标签页 ${out.tab})`
211
+ return `${head}\n${lines.join('\n')}${out.snapshot.authWall ? `\n⚠ ${out.snapshot.authWall}` : ''}\n\n${out.snapshot.text}`
212
+ }),
213
+ }),
214
+ ],
215
+ })
@@ -0,0 +1,35 @@
1
+ /** 导航能力:打开网址并返回首屏快照。 */
2
+ import { defineCapability, defineTool } from '../kernel/define.mjs'
3
+ import { runTool } from '../kernel/output.mjs'
4
+
5
+ export const navigationCapability = defineCapability({
6
+ id: 'navigation',
7
+ title: '导航',
8
+ tags: ['core'],
9
+ requires: ['engine'],
10
+ features: ['browser.navigation'],
11
+ tools: [
12
+ defineTool({
13
+ name: 'browser_navigate',
14
+ description: '打开网址(仅 http/https;URL 内嵌用户名密码会被拒绝)。首次调用会自动拉起浏览器(默认有头可见,登录态持久化)。返回新页面的元素快照,后续动作直接引用其中的 ref。导航超时会返回当前已渲染的快照并标注 [NAV_TIMEOUT],不是空错误。',
15
+ inputSchema: {
16
+ type: 'object',
17
+ properties: {
18
+ url: { type: 'string', maxLength: 2048, description: '目标网址,如 https://example.com/' },
19
+ tab: { type: 'string', maxLength: 16, description: '在指定标签页打开(缺省=当前活动标签页;浏览器未启动时自动新建)' },
20
+ },
21
+ required: ['url'],
22
+ additionalProperties: false,
23
+ },
24
+ kind: 'write',
25
+ since: '1.0.0',
26
+ handler: async (args, ctx) => runTool(async () => {
27
+ const out = await ctx.engine.navigate({ url: args.url, tab: args.tab })
28
+ const head = out.timedOut
29
+ ? `[NAV_TIMEOUT] ${out.timeoutMs}ms 内没等到 domcontentloaded(站点慢或被拦)。下面是当前已渲染的内容,可先用 ref 继续操作,或 browser_screenshot 确认。\n已打开 ${out.url} — ${out.title || '(无标题)'}(标签页 ${out.tab})`
30
+ : `已打开 ${out.url} — ${out.title || '(无标题)'}(标签页 ${out.tab})`
31
+ return `${head}${out.note ? `\n⚠ ${out.note}` : ''}\n\n${out.snapshot.text}`
32
+ }),
33
+ }),
34
+ ],
35
+ })
@@ -0,0 +1,50 @@
1
+ /** 截图能力:PNG 直接回给模型(富内容块),同时落盘保留路径。 */
2
+ import { defineCapability, defineTool } from '../kernel/define.mjs'
3
+ import { fail, ok, okBlocks } from '../kernel/output.mjs'
4
+
5
+ /** 大图挡在 MCP 体量上限之外:超过就只回路径,避免整条结果被宿主拒绝。 */
6
+ const MAX_INLINE_IMAGE_BYTES = 4 * 1024 * 1024
7
+
8
+ const TAB_PROP = { type: 'string', maxLength: 16, description: '目标标签页 id(缺省=当前活动标签页)' }
9
+
10
+ export const screenshotCapability = defineCapability({
11
+ id: 'screenshot',
12
+ title: '页面截图',
13
+ tags: ['verify'],
14
+ requires: ['engine', 'server'],
15
+ features: ['browser.screenshot'],
16
+ tools: [
17
+ defineTool({
18
+ name: 'browser_screenshot',
19
+ description: '当前页面截图,图片直接返回给你看(PNG,同时落盘并给出路径);不要再调 read_image 去读它。默认视口截图;fullPage=true 截整页。工作台地址可实时观察页面。',
20
+ inputSchema: {
21
+ type: 'object',
22
+ properties: {
23
+ fullPage: { type: 'boolean', description: '是否截取整页(默认 false)' },
24
+ tab: TAB_PROP,
25
+ },
26
+ additionalProperties: false,
27
+ },
28
+ kind: 'read',
29
+ since: '1.0.0',
30
+ handler: async (args, ctx) => {
31
+ let out
32
+ try {
33
+ out = await ctx.engine.screenshot({ fullPage: args.fullPage, tab: args.tab })
34
+ } catch (error) {
35
+ return fail(error)
36
+ }
37
+ let workbench = ''
38
+ try { workbench = ctx.server.url() } catch { /* 未注入则省略 */ }
39
+ const note = `截图已保存: ${out.path}(${out.bytes} 字节)${workbench ? `\n工作台实时画面: ${workbench}` : ''}`
40
+ if (!out.data || out.bytes > MAX_INLINE_IMAGE_BYTES) {
41
+ return ok(`${note}\n(${out.bytes > MAX_INLINE_IMAGE_BYTES ? '图片过大' : '当前运行时未提供图像数据'},只回路径;需要查看再用 read_image 读该文件)`)
42
+ }
43
+ return okBlocks([
44
+ { type: 'image', data: out.data, mimeType: out.mimeType || 'image/png' },
45
+ { type: 'text', text: `${note}\n上图即当前页面,直接据此判断,无需再调用 read_image。` },
46
+ ])
47
+ },
48
+ }),
49
+ ],
50
+ })
@@ -0,0 +1,81 @@
1
+ /** 会话能力:状态 / 等待 / 历史 / 关闭浏览器。 */
2
+ import { defineCapability, defineTool } from '../kernel/define.mjs'
3
+ import { runTool } from '../kernel/output.mjs'
4
+
5
+ const TAB_PROP = { type: 'string', maxLength: 16, description: '目标标签页 id(缺省=当前活动标签页)' }
6
+
7
+ export const sessionCapability = defineCapability({
8
+ id: 'session',
9
+ title: '会话管理',
10
+ tags: ['core'],
11
+ requires: ['engine'],
12
+ features: ['browser.session'],
13
+ tools: [
14
+ defineTool({
15
+ name: 'browser_status',
16
+ description: '引擎状态:是否运行、有头/无头、标签页清单(id+地址)、累计动作数、最近动作日志。不确定浏览器是否还活着时先看它。',
17
+ inputSchema: { type: 'object', properties: {}, additionalProperties: false },
18
+ kind: 'read',
19
+ since: '1.0.0',
20
+ handler: async (_args, ctx) => runTool(async () => {
21
+ const status = await ctx.engine.status()
22
+ const log = await ctx.engine.actionLog()
23
+ return JSON.stringify({ ...status, recentActions: log.slice(0, 8) }, null, 2)
24
+ }),
25
+ }),
26
+ defineTool({
27
+ name: 'browser_wait',
28
+ description: '等待指定条件后返回**等待后的新快照**(不用再单独 browser_snapshot)。selector=等元素出现(首选,如 .result),ms=固定毫秒(上限 30000),都不给=等页面 load 完成。',
29
+ inputSchema: {
30
+ type: 'object',
31
+ properties: {
32
+ ms: { type: 'number', description: '等待毫秒数(上限 30000)' },
33
+ selector: { type: 'string', maxLength: 300, description: '等待出现的 CSS 选择器' },
34
+ tab: TAB_PROP,
35
+ },
36
+ additionalProperties: false,
37
+ },
38
+ kind: 'control',
39
+ since: '1.0.0',
40
+ handler: async (args, ctx) => runTool(async () => {
41
+ const out = await ctx.engine.wait({ ms: args.ms, selector: args.selector, tab: args.tab })
42
+ const head = args.selector
43
+ ? `已等到元素 ${args.selector}`
44
+ : args.ms
45
+ ? `已等待 ${args.ms}ms`
46
+ : '已等到页面 load'
47
+ return `${head}(标签页 ${out.tab})——下面是等待后的快照${out.snapshot.authWall ? `\n⚠ ${out.snapshot.authWall}` : ''}\n\n${out.snapshot.text}`
48
+ }),
49
+ }),
50
+ defineTool({
51
+ name: 'browser_history',
52
+ description: '浏览历史:back 后退 / forward 前进 / reload 重载。返回操作后的新快照。',
53
+ inputSchema: {
54
+ type: 'object',
55
+ properties: {
56
+ action: { type: 'string', enum: ['back', 'forward', 'reload'], description: '动作(默认 back)' },
57
+ tab: TAB_PROP,
58
+ },
59
+ additionalProperties: false,
60
+ },
61
+ kind: 'control',
62
+ since: '1.0.0',
63
+ handler: async (args, ctx) => runTool(async () => {
64
+ const out = await ctx.engine.history({ action: args.action, tab: args.tab })
65
+ const label = args.action === 'reload' ? '已重载' : args.action === 'forward' ? '已前进到' : '已后退到'
66
+ return `${label} ${out.url}(标签页 ${out.tab})${out.note ? `\n⚠ ${out.note}` : ''}\n\n${out.snapshot.text}`
67
+ }),
68
+ }),
69
+ defineTool({
70
+ name: 'browser_close',
71
+ description: '关闭浏览器(所有标签页)并清空标签页记录——这是一次显式重置:登录态保留在 profile,但下次 navigate 是干净浏览器(不恢复旧标签)。空闲回收/服务重启则会自动恢复上次标签页。任务结束或页面卡死时用它重置。',
72
+ inputSchema: { type: 'object', properties: {}, additionalProperties: false },
73
+ kind: 'control',
74
+ since: '1.0.0',
75
+ handler: async (_args, ctx) => runTool(async () => {
76
+ const out = await ctx.engine.close()
77
+ return out.closed ? '浏览器已关闭(登录态已持久化,下次 navigate 自动重启)' : '浏览器本就未在运行'
78
+ }),
79
+ }),
80
+ ],
81
+ })
@@ -0,0 +1,30 @@
1
+ /** 观察能力:无障碍风格的元素快照(ref 引用的唯一来源)。 */
2
+ import { defineCapability, defineTool } from '../kernel/define.mjs'
3
+ import { runTool } from '../kernel/output.mjs'
4
+
5
+ export const snapshotCapability = defineCapability({
6
+ id: 'snapshot',
7
+ title: '页面快照',
8
+ tags: ['core'],
9
+ requires: ['engine'],
10
+ features: ['browser.snapshot'],
11
+ tools: [
12
+ defineTool({
13
+ name: 'browser_snapshot',
14
+ description: '观察当前页面:返回可交互元素(链接/按钮/输入框/下拉…)与结构节点(标题/图片)的缩进文本树,每个元素带 ref=eN。click/fill/select 等动作只用 ref 定位;页面变化后 ref 会过期(报 STALE_SNAPSHOT),重新快照即可。',
15
+ inputSchema: {
16
+ type: 'object',
17
+ properties: {
18
+ tab: { type: 'string', maxLength: 16, description: '目标标签页 id(缺省=当前活动标签页)' },
19
+ },
20
+ additionalProperties: false,
21
+ },
22
+ kind: 'read',
23
+ since: '1.0.0',
24
+ handler: async (args, ctx) => runTool(async () => {
25
+ const out = await ctx.engine.snapshot({ tab: args.tab })
26
+ return `# ${out.title || '(无标题)'}\n${out.url}(标签页 ${out.tab},${out.elements} 个元素${out.truncated ? ',已截断' : ''})${out.note ? `\n⚠ ${out.note}` : ''}\n\n${out.text}`
27
+ }),
28
+ }),
29
+ ],
30
+ })
@@ -0,0 +1,35 @@
1
+ /** 标签页能力:列出 / 新建 / 切换 / 关闭(稳定 id:T1、T2…)。 */
2
+ import { defineCapability, defineTool } from '../kernel/define.mjs'
3
+ import { runTool } from '../kernel/output.mjs'
4
+
5
+ export const tabsCapability = defineCapability({
6
+ id: 'tabs',
7
+ title: '标签页管理',
8
+ tags: ['core'],
9
+ requires: ['engine'],
10
+ features: ['browser.tabs'],
11
+ tools: [
12
+ defineTool({
13
+ name: 'browser_tabs',
14
+ description: '标签页四合一:action=list 列出(含稳定 id 与当前地址);new 打开新标签页(可带 url);select 切换活动标签页;close 关闭。后续动作默认作用于活动标签页,也可用 tab 参数显式指定。',
15
+ inputSchema: {
16
+ type: 'object',
17
+ properties: {
18
+ action: { type: 'string', enum: ['list', 'new', 'select', 'close'], description: '动作(默认 list)' },
19
+ url: { type: 'string', maxLength: 2048, description: 'new 动作要打开的网址' },
20
+ tab: { type: 'string', maxLength: 16, description: 'select/close 的目标标签页 id' },
21
+ },
22
+ additionalProperties: false,
23
+ },
24
+ kind: 'control',
25
+ since: '1.0.0',
26
+ handler: async (args, ctx) => runTool(async () => {
27
+ const out = await ctx.engine.tabsAction({ action: args.action, url: args.url, tab: args.tab })
28
+ if (args.action === 'new') return `已打开新标签页 ${out.tab}(${out.url || 'about:blank'})${out.note ? `\n⚠ ${out.note}` : ''}\n\n${out.snapshot.text}`
29
+ if (args.action === 'select') return `已切换到标签页 ${out.tab}${out.note ? `\n⚠ ${out.note}` : ''}\n\n${out.snapshot.text}`
30
+ if (args.action === 'close') return `已关闭标签页 ${out.closed},剩余 ${out.tabs.length} 个`
31
+ return JSON.stringify(out, null, 2)
32
+ }),
33
+ }),
34
+ ],
35
+ })
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 工具组装:能力 → registry → TOOLS/TOOL_IMPL/契约。
3
+ * relay 与测试都从这里拿工具面。
4
+ */
5
+ import { createRegistry } from './kernel/registry.mjs'
6
+ import { CAPABILITIES } from './capabilities/index.mjs'
7
+
8
+ export { createRegistry } from './kernel/registry.mjs'
9
+ export { CAPABILITIES } from './capabilities/index.mjs'
10
+
11
+ export const registry = createRegistry(CAPABILITIES)
12
+ export const { TOOLS, TOOL_IMPL, TOOL_META, FEATURES } = registry
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 能力声明 DSL:统一来自 @capyclaw/tool-host 公共插件。
3
+ * 保留此文件作为稳定 import 路径,capabilities/* 不需要改。
4
+ */
5
+ export { defineTool, defineCapability } from '../../shared/tool-host.mjs'
@@ -0,0 +1,30 @@
1
+ /**
2
+ * 工具输出格式:引擎的结构化错误(code/hint)转成模型可读文本,
3
+ * 不让 MCP 协议壳把提示信息吞掉。
4
+ */
5
+ export function ok(text) {
6
+ return { content: [{ type: 'text', text }], isError: false }
7
+ }
8
+
9
+ /**
10
+ * 富内容成功结果(文本 + 图片等 MCP 内容块,按原顺序透传给宿主)。
11
+ * 图片必须是 canonical base64(无换行),mimeType 限 PNG/JPEG/WebP/GIF。
12
+ */
13
+ export function okBlocks(blocks) {
14
+ return { content: Array.isArray(blocks) ? blocks : [], isError: false }
15
+ }
16
+
17
+ export function fail(error) {
18
+ const code = error?.code ? `[${error.code}] ` : ''
19
+ const hint = error?.hint ? `\n提示:${error.hint}` : ''
20
+ return { content: [{ type: 'text', text: `${code}${error?.message || String(error)}${hint}` }], isError: true }
21
+ }
22
+
23
+ /** 包一层:handler 里只写业务,错误统一转 fail。 */
24
+ export async function runTool(fn) {
25
+ try {
26
+ return ok(await fn())
27
+ } catch (error) {
28
+ return fail(error)
29
+ }
30
+ }