@capyclaw/rsp-suite 0.1.0 → 0.1.1

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 (159) hide show
  1. package/dsh-suite.json +13 -3
  2. package/node_modules/@capyclaw/foundation/README.md +51 -0
  3. package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
  4. package/node_modules/@capyclaw/foundation/abi/bridge.mjs +88 -0
  5. package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
  6. package/node_modules/@capyclaw/foundation/abi/index.mjs +50 -0
  7. package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
  8. package/node_modules/@capyclaw/foundation/abi/loader.mjs +352 -0
  9. package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
  10. package/node_modules/@capyclaw/foundation/abi/spec.mjs +258 -0
  11. package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
  12. package/node_modules/@capyclaw/foundation/abi/version.mjs +140 -0
  13. package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -0
  14. package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
  15. package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
  16. package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
  17. package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
  18. package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
  19. package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +72 -0
  20. package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
  21. package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +69 -0
  22. package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +120 -0
  23. package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
  24. package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
  25. package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
  26. package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
  27. package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
  28. package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +38 -0
  29. package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +88 -0
  30. package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +54 -0
  31. package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +187 -0
  32. package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
  33. package/node_modules/@capyclaw/foundation/lib/kernel.mjs +195 -0
  34. package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +115 -0
  35. package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
  36. package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
  37. package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +198 -0
  38. package/node_modules/@capyclaw/foundation/package.json +53 -0
  39. package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
  40. package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
  41. package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
  42. package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
  43. package/node_modules/@capyclaw/plugin-kit/package.json +72 -0
  44. package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
  45. package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
  46. package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +132 -0
  47. package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
  48. package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +60 -0
  49. package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
  50. package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
  51. package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
  52. package/node_modules/@capyclaw/plugin-kit/src/ledger.mjs +151 -0
  53. package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
  54. package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
  55. package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
  56. package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
  57. package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
  58. package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
  59. package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
  60. package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
  61. package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
  62. package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
  63. package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
  64. package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
  65. package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
  66. package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
  67. package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
  68. package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
  69. package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
  70. package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +664 -0
  71. package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
  72. package/{skill → node_modules/@capyclaw/rsp-skill-remote-screen}/contract/rsp-contract.json +102 -13
  73. package/{skill → node_modules/@capyclaw/rsp-skill-remote-screen}/skills/remote-screen/SKILL.md +13 -2
  74. package/{workbench → node_modules/@capyclaw/rsp-workbench}/contract/capabilities.json +32 -0
  75. package/{workbench → node_modules/@capyclaw/rsp-workbench}/lib/client.mjs +238 -11
  76. package/node_modules/@capyclaw/rsp-workbench/lib/host.mjs +51 -0
  77. package/{workbench → node_modules/@capyclaw/rsp-workbench}/lib/tools.mjs +116 -16
  78. package/{workbench → node_modules/@capyclaw/rsp-workbench}/lib/workbench.mjs +21 -2
  79. package/node_modules/@capyclaw/rsp-workbench/plugin.mjs +17 -0
  80. package/{workbench → node_modules/@capyclaw/rsp-workbench}/ui/index.html +113 -10
  81. package/node_modules/@capyclaw/service-host/README.md +86 -0
  82. package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
  83. package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
  84. package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
  85. package/node_modules/@capyclaw/service-host/package.json +60 -0
  86. package/node_modules/@capyclaw/service-host/src/index.mjs +597 -0
  87. package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
  88. package/node_modules/@capyclaw/suite-kit/README.md +289 -0
  89. package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
  90. package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
  91. package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
  92. package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
  93. package/node_modules/@capyclaw/suite-kit/package.json +58 -0
  94. package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
  95. package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
  96. package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
  97. package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
  98. package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
  99. package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
  100. package/node_modules/@capyclaw/suite-kit/src/host.mjs +251 -0
  101. package/node_modules/@capyclaw/suite-kit/src/index.mjs +24 -0
  102. package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
  103. package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
  104. package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
  105. package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
  106. package/node_modules/@capyclaw/suite-kit/suite.schema.json +128 -0
  107. package/node_modules/@capyclaw/tool-host/README.md +56 -0
  108. package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
  109. package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
  110. package/node_modules/@capyclaw/tool-host/lib/host.mjs +46 -0
  111. package/node_modules/@capyclaw/tool-host/package.json +59 -0
  112. package/node_modules/@capyclaw/tool-host/src/admit-images.mjs +80 -0
  113. package/node_modules/@capyclaw/tool-host/src/caller-session.mjs +25 -0
  114. package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +166 -0
  115. package/node_modules/@capyclaw/tool-host/src/index.mjs +461 -0
  116. package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +272 -0
  117. package/node_modules/ws/LICENSE +20 -0
  118. package/node_modules/ws/README.md +539 -0
  119. package/node_modules/ws/browser.js +8 -0
  120. package/node_modules/ws/index.js +22 -0
  121. package/node_modules/ws/lib/buffer-util.js +142 -0
  122. package/node_modules/ws/lib/constants.js +19 -0
  123. package/node_modules/ws/lib/event-target.js +292 -0
  124. package/node_modules/ws/lib/extension.js +203 -0
  125. package/node_modules/ws/lib/limiter.js +55 -0
  126. package/node_modules/ws/lib/permessage-deflate.js +530 -0
  127. package/node_modules/ws/lib/receiver.js +751 -0
  128. package/node_modules/ws/lib/sender.js +610 -0
  129. package/node_modules/ws/lib/stream.js +161 -0
  130. package/node_modules/ws/lib/subprotocol.js +62 -0
  131. package/node_modules/ws/lib/validation.js +152 -0
  132. package/node_modules/ws/lib/websocket-server.js +562 -0
  133. package/node_modules/ws/lib/websocket.js +1440 -0
  134. package/node_modules/ws/package.json +74 -0
  135. package/node_modules/ws/wrapper.mjs +21 -0
  136. package/package.json +22 -9
  137. package/workbench/lib/host.mjs +0 -111
  138. package/workbench/plugin.mjs +0 -2
  139. package/workbench/scripts/build-contract.mjs +0 -41
  140. package/workbench/scripts/drive.mjs +0 -66
  141. package/workbench/test/client.test.mjs +0 -218
  142. package/workbench/test/frames-prune.test.mjs +0 -49
  143. package/workbench/test/h264.test.mjs +0 -101
  144. package/workbench/test/live-persistent-smoke.mjs +0 -29
  145. package/workbench/test/live-smoke.mjs +0 -109
  146. package/workbench/test/mock-server.mjs +0 -194
  147. package/workbench/test/persistence.test.mjs +0 -177
  148. package/workbench/test/persistent.test.mjs +0 -160
  149. package/workbench/test/session-mode.test.mjs +0 -118
  150. package/workbench/test/workbench.test.mjs +0 -385
  151. package/workbench/verify-e2e.mjs +0 -44
  152. /package/{skill → node_modules/@capyclaw/rsp-skill-remote-screen}/README.md +0 -0
  153. /package/{skill → node_modules/@capyclaw/rsp-skill-remote-screen}/cordis.patch.yml +0 -0
  154. /package/{skill → node_modules/@capyclaw/rsp-skill-remote-screen}/package.json +0 -0
  155. /package/{skill → node_modules/@capyclaw/rsp-skill-remote-screen}/plugin.mjs +0 -0
  156. /package/{workbench → node_modules/@capyclaw/rsp-workbench}/lib/descriptors.mjs +0 -0
  157. /package/{workbench → node_modules/@capyclaw/rsp-workbench}/lib/manager.mjs +0 -0
  158. /package/{workbench → node_modules/@capyclaw/rsp-workbench}/lib/session-mode.mjs +0 -0
  159. /package/{workbench → node_modules/@capyclaw/rsp-workbench}/package.json +0 -0
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "ws",
3
+ "version": "8.22.2",
4
+ "description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js",
5
+ "keywords": [
6
+ "HyBi",
7
+ "Push",
8
+ "RFC-6455",
9
+ "WebSocket",
10
+ "WebSockets",
11
+ "real-time"
12
+ ],
13
+ "homepage": "https://github.com/websockets/ws",
14
+ "bugs": "https://github.com/websockets/ws/issues",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/websockets/ws.git"
18
+ },
19
+ "author": "Einar Otto Stangvik <einaros@gmail.com> (http://2x.io)",
20
+ "license": "MIT",
21
+ "main": "index.js",
22
+ "exports": {
23
+ ".": {
24
+ "browser": "./browser.js",
25
+ "import": "./wrapper.mjs",
26
+ "require": "./index.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "browser": "browser.js",
31
+ "engines": {
32
+ "node": ">=10.0.0"
33
+ },
34
+ "files": [
35
+ "browser.js",
36
+ "index.js",
37
+ "lib/*.js",
38
+ "wrapper.mjs"
39
+ ],
40
+ "scripts": {
41
+ "test": "nyc --reporter=lcov --reporter=text mocha --throw-deprecation test/*.test.js",
42
+ "integration": "mocha --throw-deprecation test/*.integration.js",
43
+ "lint": "eslint . && prettier --check --ignore-path .gitignore \"**/*.{json,md,yaml,yml}\""
44
+ },
45
+ "peerDependencies": {
46
+ "bufferutil": "^4.0.1",
47
+ "utf-8-validate": ">=5.0.2"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "bufferutil": {
51
+ "optional": true
52
+ },
53
+ "utf-8-validate": {
54
+ "optional": true
55
+ }
56
+ },
57
+ "devDependencies": {
58
+ "@eslint/js": "^10.0.1",
59
+ "benchmark": "^2.1.4",
60
+ "bufferutil": "^4.0.1",
61
+ "eslint": "^10.0.1",
62
+ "eslint-config-prettier": "^10.0.1",
63
+ "eslint-plugin-prettier": "^5.0.0",
64
+ "globals": "^17.0.0",
65
+ "mocha": "^8.4.0",
66
+ "nyc": "^15.0.0",
67
+ "prettier": "^3.0.0",
68
+ "utf-8-validate": "^6.0.0"
69
+ },
70
+ "allowScripts": {
71
+ "bufferutil": true,
72
+ "utf-8-validate": true
73
+ }
74
+ }
@@ -0,0 +1,21 @@
1
+ import createWebSocketStream from './lib/stream.js';
2
+ import extension from './lib/extension.js';
3
+ import PerMessageDeflate from './lib/permessage-deflate.js';
4
+ import Receiver from './lib/receiver.js';
5
+ import Sender from './lib/sender.js';
6
+ import subprotocol from './lib/subprotocol.js';
7
+ import WebSocket from './lib/websocket.js';
8
+ import WebSocketServer from './lib/websocket-server.js';
9
+
10
+ export {
11
+ createWebSocketStream,
12
+ extension,
13
+ PerMessageDeflate,
14
+ Receiver,
15
+ Sender,
16
+ subprotocol,
17
+ WebSocket,
18
+ WebSocketServer
19
+ };
20
+
21
+ export default WebSocket;
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "@capyclaw/rsp-suite",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "RSP/1 远程屏幕控制端套件:workbench(画面只读 + 操控只写,rsp_* 工具)+ remote-screen skill。接入 DSH 套件基建,AI 经接口操控被控端设备。",
5
5
  "type": "module",
6
- "engines": { "node": ">=20" },
6
+ "engines": {
7
+ "node": ">=20",
8
+ "dsh": "^0.2.0-rc.2"
9
+ },
7
10
  "dsh": {
8
- "bundle": { "patch": "./cordis.patch.yml" },
11
+ "bundle": {
12
+ "patch": "./cordis.patch.yml"
13
+ },
9
14
  "suite": "./dsh-suite.json",
10
15
  "category": "service",
11
16
  "platform": "both"
@@ -22,13 +27,11 @@
22
27
  "files": [
23
28
  "dsh-suite.json",
24
29
  "cordis.patch.yml",
25
- "workbench/",
26
- "skill/",
27
30
  "README.md"
28
31
  ],
29
32
  "dependencies": {
30
- "@capyclaw/rsp-workbench": "file:./workbench",
31
- "@capyclaw/rsp-skill-remote-screen": "file:./skill",
33
+ "@capyclaw/rsp-workbench": "^0.1.0",
34
+ "@capyclaw/rsp-skill-remote-screen": "^0.1.0",
32
35
  "@capyclaw/foundation": "^0.1.9",
33
36
  "@capyclaw/plugin-kit": "^0.2.6",
34
37
  "@capyclaw/service-host": "^0.1.5",
@@ -38,5 +41,15 @@
38
41
  "license": "MIT",
39
42
  "publishConfig": {
40
43
  "access": "public"
41
- }
42
- }
44
+ },
45
+ "bundledDependencies": [
46
+ "@capyclaw/foundation",
47
+ "@capyclaw/plugin-kit",
48
+ "@capyclaw/rsp-skill-remote-screen",
49
+ "@capyclaw/rsp-workbench",
50
+ "@capyclaw/service-host",
51
+ "@capyclaw/suite-kit",
52
+ "@capyclaw/tool-host",
53
+ "ws"
54
+ ]
55
+ }
@@ -1,111 +0,0 @@
1
- /**
2
- * rsp-workbench cordis 宿主入口:把可单测核心接进 DSH。
3
- * 模式沿用 conductor/browser embedded-host:inject=['webServer'],其余服务 safeGet 优雅降级。
4
- * 路由冲突只警告退出本条目,绝不升级为宿主崩溃;app.listen 的 rejection 必须 .catch 兜底。
5
- */
6
- import os from 'node:os'
7
- import path from 'node:path'
8
- import { assertServiceApi } from '@capyclaw/plugin-kit/service/api'
9
- import { validateCapabilityDescriptor } from '@capyclaw/suite-kit/capability'
10
- import { createRspWorkbench } from './workbench.mjs'
11
- import { RSP_DESCRIPTORS } from './descriptors.mjs'
12
- import { bindToolsToSessionMode } from './session-mode.mjs'
13
-
14
- export const name = 'rsp-workbench'
15
- export const inject = ['webServer']
16
-
17
- function safeGet(ctx, serviceName) {
18
- try { return ctx.reflect?.get?.(serviceName) ?? ctx[serviceName] } catch { return null }
19
- }
20
-
21
- export function apply(ctx, config = {}) {
22
- const log = {
23
- info: (...a) => (ctx.logger?.info ? ctx.logger.info(...a) : console.log('[rsp]', ...a)),
24
- warn: (...a) => (ctx.logger?.warn ? ctx.logger.warn(...a) : console.warn('[rsp]', ...a)),
25
- }
26
- const mountPath = config.mountPath || '/capyclaw/rsp'
27
- const hostDir = config.hostDir || path.join(os.homedir(), '.dsh-rsp')
28
- const disposers = []
29
-
30
- try {
31
- const toolHost = safeGet(ctx, 'toolHost')
32
- const serviceHost = safeGet(ctx, 'serviceHost')
33
- if (!toolHost || !serviceHost) {
34
- log.warn('缺少 toolHost/serviceHost 公共服务,rsp-suite 未激活(请安装对应基础套件)')
35
- return () => {}
36
- }
37
- assertServiceApi(toolHost, { name: 'toolHost', major: 1 })
38
- assertServiceApi(serviceHost, { name: 'serviceHost', major: 1 })
39
-
40
- const workbench = createRspWorkbench({
41
- toolHost, serviceHost,
42
- config: { mountPath, version: config.version || '0.1.0', hostDir },
43
- })
44
-
45
- const webServer = safeGet(ctx, 'webServer')
46
-
47
- // 前缀路由全局唯一:先探占位,冲突只警告退出本条目,绝不把路由冲突升级成宿主崩溃。
48
- if (webServer && typeof webServer.register === 'function') {
49
- let taken = false
50
- try {
51
- const probe = webServer.register({ kind: 'prefix', path: mountPath, handler: () => {} })
52
- if (typeof probe === 'function') probe()
53
- } catch { taken = true }
54
- if (taken) {
55
- log.warn(`rsp-workbench: 路由前缀 ${mountPath} 已被占用,本条目不挂载(不影响其它插件)`)
56
- return () => {}
57
- }
58
- }
59
-
60
- const listenOpts = webServer ? { webServer, basePath: mountPath } : { port: config.port || 0 }
61
- const listening = workbench.app.listen(listenOpts)
62
- if (listening && typeof listening.catch === 'function') {
63
- listening.catch((err) => {
64
- log.warn(`rsp-workbench: 挂载 ${mountPath} 失败,本条目不生效:`, err?.message || err)
65
- try { workbench.app.close() } catch { /* 忽略 */ }
66
- })
67
- }
68
- disposers.push(() => workbench.app.close())
69
- disposers.push(() => { workbench.manager.close().catch(() => {}) })
70
-
71
- // 会话模式守卫:非 read 工具执行前把「调用者会话」钉到 rsp 工作台
72
- // (与 ppt/browser/canvas 同语义)。认领成功后 portal-hud 会把查看器摆到主区,
73
- // 于是 AI 一动手,人在主区就能看到实时画面并随时介入。
74
- bindToolsToSessionMode(workbench.registry, { getWorkStore: () => safeGet(ctx, 'workStore') })
75
-
76
- // 原生工具面:safeGet 解析 tools 服务后传平对象,避免 cordis 未 inject 禁访问 ctx.tools。
77
- const tools = safeGet(ctx, 'tools')
78
- if (tools?.register) {
79
- const { registerWithDsh } = toolHost
80
- disposers.push(registerWithDsh({ tools }, workbench.registry))
81
- }
82
-
83
- // 持久化连接态:激活即连记住的 active 目标(进程级常驻、跨会话共享、掉线退避重试)。
84
- // 新会话/宿主重启后 rsp_status 与主区查看器缺省即「已连接」,无需每次 rsp_connect。
85
- try { workbench.manager.startPersistent() } catch (e) { log.warn('rsp-workbench: 常驻连接启动失败:', e?.message || e) }
86
-
87
- workbench.publishDescriptors(workbench.app.url, { validate: validateCapabilityDescriptor })
88
- disposers.push(() => { for (const d of RSP_DESCRIPTORS) toolHost.unregisterCapabilityDescriptor?.(d.name) })
89
-
90
- if (webServer?.register) {
91
- const p = `${mountPath}/__host__`
92
- const off = webServer.register({
93
- kind: 'exact', path: p,
94
- handler: (req, res) => {
95
- res.writeHead(200, { 'content-type': 'application/json' })
96
- res.end(JSON.stringify({ ok: true, name, mountPath, url: workbench.app.url, protocol: 'rsp/1', status: workbench.manager.status() }))
97
- },
98
- })
99
- if (typeof off === 'function') disposers.push(off)
100
- }
101
-
102
- const portal = safeGet(ctx, 'portal')
103
- portal?.recordActivity?.({ id: 'rsp-workbench', url: workbench.app.url, title: 'RSP 远程屏幕工作台', kind: 'service' })
104
-
105
- log.info(`rsp-workbench 已挂载 ${mountPath} → ${workbench.app.url}`)
106
- return () => { for (const d of disposers.reverse()) { try { d() } catch { /* 忽略重复释放 */ } } }
107
- } catch (err) {
108
- log.warn('rsp-workbench 激活失败:', err?.stack || err)
109
- return () => { for (const d of disposers.reverse()) { try { d() } catch { /* noop */ } } }
110
- }
111
- }
@@ -1,2 +0,0 @@
1
- /** @capyclaw/rsp-workbench 入口:cordis 宿主激活(见 lib/host.mjs)。 */
2
- export { name, inject, apply } from './lib/host.mjs'
@@ -1,41 +0,0 @@
1
- /**
2
- * 从 workbench 工具注册表生成 skill 契约快照(skill/contract/rsp-contract.json)。
3
- * 形状对齐 browser-contract.json:{contractVersion,packageVersion,toolCount,tools:[{name,kind,since,capability,description,inputSchema}],features,capabilities}。
4
- * 运行:node workbench/scripts/build-contract.mjs
5
- */
6
- import { writeFileSync, mkdirSync } from 'node:fs'
7
- import { fileURLToPath } from 'node:url'
8
- import path from 'node:path'
9
- import os from 'node:os'
10
- import { createToolHost } from '@capyclaw/tool-host/src'
11
- import { createRspCapabilities } from '../lib/tools.mjs'
12
- import { RspManager } from '../lib/manager.mjs'
13
-
14
- const here = path.dirname(fileURLToPath(import.meta.url))
15
- const toolHost = createToolHost({})
16
- const manager = new RspManager({ hostDir: path.join(os.tmpdir(), 'rsp-contract-build') })
17
- const capabilities = createRspCapabilities({ toolHost, manager, config: {} })
18
- const registry = toolHost.createRegistry(capabilities)
19
-
20
- const report = toolHost.createCapabilityReport({
21
- tools: registry.TOOLS,
22
- toolMeta: registry.TOOL_META,
23
- features: registry.FEATURES,
24
- capabilities: registry.CAPABILITIES,
25
- contractVersion: '0.1.0',
26
- packageVersion: '0.1.0',
27
- })
28
-
29
- // 契约快照带上 description + inputSchema(createCapabilityReport 默认只给 name/kind/since/capability)。
30
- const byName = new Map(registry.TOOLS.map((t) => [t.name, t]))
31
- report.tools = report.tools.map((t) => ({
32
- ...t,
33
- description: byName.get(t.name)?.description || '',
34
- inputSchema: byName.get(t.name)?.inputSchema || { type: 'object', properties: {} },
35
- }))
36
-
37
- const out = path.resolve(here, '../../skill/contract/rsp-contract.json')
38
- mkdirSync(path.dirname(out), { recursive: true })
39
- writeFileSync(out, JSON.stringify(report, null, 2) + '\n')
40
- console.log('wrote', out, '| toolCount', report.toolCount, '| tools:', report.tools.map((t) => t.name).join(', '))
41
- await manager.close()
@@ -1,66 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * 工作台 CLI 驱动(真实设备联调/演示用):经宿主 workbench 的 MCP 面调用 rsp_* 工具,
4
- * 与 AI 原生工具面同一条路径。令牌从环境变量 RSP_TOKEN 读取,不出现在命令行参数里。
5
- *
6
- * 用法:
7
- * RSP_TOKEN=xxx node scripts/drive.mjs connect http://host:8765
8
- * node scripts/drive.mjs tool rsp_screen '{"save":true}'
9
- * node scripts/drive.mjs tool rsp_mouse '{"action":"click","x":480,"y":270,"space":"frame"}'
10
- * node scripts/drive.mjs api status
11
- * 环境变量 RSP_WB 覆盖工作台基址(默认 http://127.0.0.1:8046/capyclaw/rsp)
12
- */
13
- import { mkdirSync, writeFileSync } from 'node:fs'
14
- import path from 'node:path'
15
-
16
- const WB = process.env.RSP_WB || 'http://127.0.0.1:8046/capyclaw/rsp'
17
- const TOKEN = process.env.RSP_TOKEN || ''
18
- const cmd = process.argv[2]
19
-
20
- async function api(pathname, body) {
21
- const opt = body === undefined ? {} : { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }
22
- const r = await fetch(WB + pathname, opt)
23
- const j = await r.json().catch(() => null)
24
- return { status: r.status, body: j }
25
- }
26
-
27
- let mcpId = 0
28
- async function tool(name, args) {
29
- const r = await fetch(WB + '/mcp', {
30
- method: 'POST', headers: { 'content-type': 'application/json' },
31
- body: JSON.stringify({ jsonrpc: '2.0', id: ++mcpId, method: 'tools/call', params: { name, arguments: args } }),
32
- })
33
- const j = await r.json().catch(() => null)
34
- const result = j?.result ?? j
35
- // 图片内容落盘,只回路径与文本,避免把 base64 喷到终端
36
- for (const c of result?.content || []) {
37
- if (c.type === 'image' && c.data) {
38
- const dir = path.join(process.cwd(), '.frames')
39
- mkdirSync(dir, { recursive: true })
40
- const f = path.join(dir, `frame-${Date.now()}.jpg`)
41
- writeFileSync(f, Buffer.from(c.data, 'base64'))
42
- c.file = f
43
- delete c.data
44
- }
45
- }
46
- return result
47
- }
48
-
49
- if (cmd === 'connect') {
50
- const url = process.argv[3]
51
- const { status, body } = await api('/api/connect', { url, token: TOKEN, name: process.argv[4] || 'real', persist: true })
52
- console.log(JSON.stringify({ status, info: body?.info, error: body?.error }))
53
- } else if (cmd === 'api') {
54
- const { status, body } = await api('/api/' + (process.argv[3] || 'status'))
55
- console.log(JSON.stringify({ status, body }))
56
- } else if (cmd === 'tool') {
57
- const name = process.argv[3]
58
- // 参数优先取 argv;PowerShell 会吞引号,故支持 RSP_ARGS 环境变量传 JSON
59
- const raw = process.argv[4] || process.env.RSP_ARGS || '{}'
60
- const args = JSON.parse(raw)
61
- const res = await tool(name, args)
62
- console.log(JSON.stringify(res))
63
- } else {
64
- console.log('usage: drive.mjs connect <url> | tool <name> <json> | api <endpoint>')
65
- process.exit(1)
66
- }
@@ -1,218 +0,0 @@
1
- /**
2
- * RSP/1 客户端测试:纯函数单元 + 对 mock 被控端的协议集成。
3
- * 覆盖:hello/帧、seq/ack、bad_event 保持连接、401/4001 鉴权、403 禁用、
4
- * POST 降级、§5.5 断线补 up、screen 退避重连、move 限速、releaseAll。
5
- */
6
- import { test } from 'node:test'
7
- import assert from 'node:assert/strict'
8
- import { RspClient, jpegSize, splitText, maskToken, normalizeBase, PROTOCOL } from '../lib/client.mjs'
9
- import { createMockRspServer, makeJpeg } from './mock-server.mjs'
10
-
11
- async function waitFor(fn, timeout = 4000, step = 20) {
12
- const end = Date.now() + timeout
13
- while (Date.now() < end) {
14
- const v = await fn()
15
- if (v) return v
16
- await new Promise((r) => setTimeout(r, step))
17
- }
18
- throw new Error('waitFor 超时')
19
- }
20
-
21
- // ---------- 纯函数 ----------
22
-
23
- test('jpegSize 解析 SOF0 尺寸', () => {
24
- assert.deepEqual(jpegSize(makeJpeg(960, 540)), { width: 960, height: 540 })
25
- assert.deepEqual(jpegSize(makeJpeg(1920, 1080)), { width: 1920, height: 1080 })
26
- assert.equal(jpegSize(null), null)
27
- assert.equal(jpegSize(Buffer.from([1, 2, 3])), null)
28
- assert.equal(jpegSize(Buffer.from([0xff, 0xd8, 0xff, 0xd9])), null) // 无 SOF
29
- })
30
-
31
- test('splitText 按 4096 UTF-16 码元分片且不切代理对', () => {
32
- assert.deepEqual(splitText('你好'), ['你好'])
33
- const long = 'a'.repeat(9000)
34
- const chunks = splitText(long)
35
- assert.deepEqual(chunks.map((c) => c.length), [4096, 4096, 808])
36
- assert.equal(chunks.join(''), long)
37
- // 高位代理恰好落在切口:回退一格,emoji 完整保留到下一片
38
- const s = 'a'.repeat(4095) + '😀' + 'b'.repeat(100)
39
- const cs = splitText(s)
40
- assert.equal(cs[0].length, 4095)
41
- assert.ok(cs[1].startsWith('😀'))
42
- assert.equal(cs.join(''), s)
43
- for (const c of cs) assert.ok(c.length <= 4096)
44
- })
45
-
46
- test('normalizeBase 归一化基址', () => {
47
- assert.equal(normalizeBase({ url: 'http://192.168.1.5:8765/' }), 'http://192.168.1.5:8765')
48
- assert.equal(normalizeBase({ url: 'https://example.com/rsp/' }), 'https://example.com/rsp')
49
- assert.equal(normalizeBase({ host: '10.0.0.2' }), 'http://10.0.0.2:8765')
50
- assert.equal(normalizeBase({ host: '10.0.0.2', port: 9000 }), 'http://10.0.0.2:9000')
51
- assert.equal(normalizeBase({ host: '::1' }), 'http://[::1]:8765')
52
- assert.throws(() => normalizeBase({ url: 'ftp://x' }), (e) => e.code === 'bad_event')
53
- assert.throws(() => normalizeBase({}), (e) => e.code === 'bad_event')
54
- })
55
-
56
- test('maskToken 掩码', () => {
57
- assert.equal(maskToken(''), null)
58
- assert.equal(maskToken('short'), '****')
59
- assert.equal(maskToken('abcdefghijklmnop'), 'abcd…mnop')
60
- })
61
-
62
- // ---------- 协议集成 ----------
63
-
64
- async function setup(t, opts = {}) {
65
- const mock = await createMockRspServer(opts)
66
- const client = new RspClient({ baseUrl: mock.url, token: mock.token })
67
- t.after(async () => { try { await client.disconnect() } catch { /* ignore */ } await mock.close() })
68
- return { mock, client }
69
- }
70
-
71
- test('connect:校验 rsp/1、收 hello 与 JPEG 帧、status 尺寸', async (t) => {
72
- const { mock, client } = await setup(t)
73
- const info = await client.connect()
74
- assert.equal(info.protocol, PROTOCOL)
75
- assert.equal(info.screen.format, 'jpeg')
76
- await waitFor(() => client.hello && client.lastFrame)
77
- const st = client.status()
78
- assert.equal(st.connected, true)
79
- assert.deepEqual(st.logical, { width: 1920, height: 1080 })
80
- assert.equal(st.lastFrame.width, 960)
81
- assert.equal(st.lastFrame.height, 540)
82
- assert.ok(st.frameCount > 0)
83
- assert.equal(st.token, maskToken(mock.token))
84
- assert.ok(client.lastFrame.bytes.length > 4)
85
- })
86
-
87
- test('sendEvent:mouse click 走 control.ws 并收 ack', async (t) => {
88
- const { mock, client } = await setup(t)
89
- await client.connect()
90
- const r = await client.sendEvent({ cmd: 'mouse', action: 'click', x: 960, y: 540, clicks: 2 })
91
- assert.equal(r.ok, true)
92
- assert.equal(r.via, 'ws')
93
- assert.equal(r.seq, 1)
94
- const ev = mock.events.find((e) => e.cmd === 'mouse')
95
- assert.equal(ev.action, 'click')
96
- assert.equal(ev.x, 960); assert.equal(ev.y, 540); assert.equal(ev.clicks, 2)
97
- assert.equal(ev.seq, 1)
98
- })
99
-
100
- test('bad_event:非法键位报错但连接保持', async (t) => {
101
- const { mock, client } = await setup(t)
102
- await client.connect()
103
- await assert.rejects(
104
- () => client.sendEvent({ cmd: 'key', action: 'down', code: 'Foo' }),
105
- (e) => e.code === 'bad_event' && /Foo/.test(e.message),
106
- )
107
- assert.equal(client.controlState, 'open')
108
- const r = await client.sendEvent({ cmd: 'key', action: 'down', code: 'KeyA' })
109
- assert.equal(r.ok, true)
110
- await client.sendEvent({ cmd: 'key', action: 'up', code: 'KeyA' })
111
- assert.deepEqual(client.status().pressedKeys, [])
112
- })
113
-
114
- test('错误令牌:/info 401 → unauthorized', async (t) => {
115
- const mock = await createMockRspServer()
116
- t.after(() => mock.close())
117
- const client = new RspClient({ baseUrl: mock.url, token: 'wrong-token' })
118
- await assert.rejects(() => client.connect(), (e) => e.code === 'unauthorized')
119
- })
120
-
121
- test('操控禁用:画面可连,注入 → forbidden', async (t) => {
122
- const { client } = await setup(t, { controlEnabled: false })
123
- const info = await client.connect()
124
- assert.equal(info.control.enabled, false)
125
- await waitFor(() => client.lastFrame)
126
- await assert.rejects(
127
- () => client.sendEvent({ cmd: 'mouse', action: 'click', x: 1, y: 1 }),
128
- (e) => e.code === 'forbidden',
129
- )
130
- })
131
-
132
- test('control.ws 不可用:降级 POST /control', async (t) => {
133
- const { mock, client } = await setup(t, { controlWs: false })
134
- await client.connect()
135
- assert.equal(client.controlMode, 'post')
136
- const r = await client.sendEvent({ cmd: 'mouse', action: 'click', x: 100, y: 200 })
137
- assert.equal(r.ok, true)
138
- assert.equal(r.via, 'post')
139
- const ev = mock.events.find((e) => e.cmd === 'mouse')
140
- assert.equal(ev.x, 100); assert.equal(ev.y, 200)
141
- assert.equal(ev.seq, undefined) // POST 不带 seq
142
- })
143
-
144
- test('§5.5 防卡键:control.ws 异常断开,被控端自动补 up', async (t) => {
145
- const { mock, client } = await setup(t)
146
- await client.connect()
147
- await client.sendEvent({ cmd: 'key', action: 'down', code: 'KeyA' })
148
- await client.sendEvent({ cmd: 'mouse', action: 'down', x: 10, y: 10, button: 'left' })
149
- assert.deepEqual(client.status().pressedKeys, ['KeyA'])
150
- assert.deepEqual(client.status().pressedButtons, ['left'])
151
- client.controlWs.terminate() // 模拟控制端掉线(不走 releaseAll)
152
- await waitFor(() => mock.releasedOnClose.length >= 2)
153
- const ups = mock.releasedOnClose
154
- assert.ok(ups.some((e) => e.cmd === 'key' && e.action === 'up' && e.code === 'KeyA'))
155
- assert.ok(ups.some((e) => e.cmd === 'mouse' && e.action === 'up' && e.button === 'left'))
156
- })
157
-
158
- test('disconnect 主动补发按下态的 up(releaseAll)', async (t) => {
159
- const { mock, client } = await setup(t)
160
- await client.connect()
161
- await client.sendEvent({ cmd: 'key', action: 'down', code: 'ShiftLeft' })
162
- await client.disconnect()
163
- await waitFor(() => mock.events.some((e) => e.cmd === 'key' && e.action === 'up' && e.code === 'ShiftLeft'))
164
- })
165
-
166
- test('screen.ws 断开后退避重连', async (t) => {
167
- const { client } = await setup(t)
168
- await client.connect()
169
- await waitFor(() => client.lastFrame)
170
- const before = client.frameCount
171
- client.screenWs.terminate()
172
- await waitFor(() => client.screenState === 'reconnecting' || client.screenState === 'connecting')
173
- await waitFor(() => client.screenState === 'open', 5000)
174
- await waitFor(() => client.frameCount > before, 3000)
175
- })
176
-
177
- test('WS 关闭码 4001 → auth-error,注入拒绝', async (t) => {
178
- const mock = await createMockRspServer()
179
- t.after(() => mock.close())
180
- const info = { protocol: 'rsp/1', screen: { width: 1920, height: 1080, format: 'jpeg' }, control: { enabled: true }, engine: { ready: true } }
181
- const client = new RspClient({
182
- baseUrl: mock.url, token: 'wrong-token',
183
- fetchImpl: async () => ({ ok: true, status: 200, json: async () => info }), // /info 假装通过,WS 真鉴权
184
- })
185
- t.after(async () => { try { await client.disconnect() } catch { /* ignore */ } })
186
- let authErr = null
187
- client.on('auth-error', (d) => { authErr = d })
188
- await client.connect()
189
- await waitFor(() => authErr)
190
- assert.equal(client.screenState, 'auth-error')
191
- await assert.rejects(() => client.sendEvent({ cmd: 'mouse', action: 'click', x: 1, y: 1 }), (e) => e.code === 'unauthorized')
192
- })
193
-
194
- test('move 限速 ≤60/s(间隔 ≥16ms)', async (t) => {
195
- const { client } = await setup(t)
196
- await client.connect()
197
- const t0 = Date.now()
198
- for (let i = 0; i < 3; i++) await client.sendEvent({ cmd: 'mouse', action: 'move', x: i, y: i })
199
- assert.ok(Date.now() - t0 >= 25, '3 次 move 应至少间隔 2×16ms')
200
- })
201
-
202
- test('waitFrame 等到新帧', async (t) => {
203
- const { client } = await setup(t)
204
- await client.connect()
205
- await waitFor(() => client.lastFrame)
206
- const since = Date.now()
207
- const f = await client.waitFrame(since, 2000)
208
- assert.ok(f.at >= since)
209
- })
210
-
211
- test('超大事件 → too_large(客户端侧拦截)', async (t) => {
212
- const { client } = await setup(t)
213
- await client.connect()
214
- await assert.rejects(
215
- () => client.sendEvent({ cmd: 'text', text: 'x'.repeat(70000) }),
216
- (e) => e.code === 'too_large',
217
- )
218
- })
@@ -1,49 +0,0 @@
1
- // 回归:rsp_screen 抓帧落盘必须有界(磁盘版 session-keeper 事故模式),
2
- // 且查看器 innerHTML 插值必须转义(目标名/基址来自调用者可控的 rsp_connect 参数)。
3
- import test from 'node:test'
4
- import assert from 'node:assert/strict'
5
- import { mkdtempSync, writeFileSync, readdirSync, readFileSync } from 'node:fs'
6
- import { tmpdir } from 'node:os'
7
- import path from 'node:path'
8
- import { fileURLToPath } from 'node:url'
9
- import { pruneFrames } from '../lib/tools.mjs'
10
-
11
- const here = path.dirname(fileURLToPath(import.meta.url))
12
-
13
- test('pruneFrames 只保留最近 40 张抓帧', () => {
14
- const dir = mkdtempSync(path.join(tmpdir(), 'rsp-frames-'))
15
- // 60 张帧:名字里的时间戳单调递增,sort() 即时间序
16
- for (let i = 0; i < 60; i++) writeFileSync(path.join(dir, `frame-${1700000000000 + i}.jpg`), 'x')
17
- // 混入非帧文件:不应被误删
18
- writeFileSync(path.join(dir, 'viewer-live.png'), 'keep')
19
- writeFileSync(path.join(dir, 'notes.txt'), 'keep')
20
- pruneFrames(dir)
21
- const left = readdirSync(dir).filter((n) => /^frame-\d+\.jpg$/.test(n)).sort()
22
- assert.equal(left.length, 40)
23
- assert.equal(left[0], 'frame-1700000000020.jpg') // 最旧 20 张被删
24
- assert.equal(left[39], 'frame-1700000000059.jpg')
25
- assert.ok(readdirSync(dir).includes('viewer-live.png'))
26
- assert.ok(readdirSync(dir).includes('notes.txt'))
27
- })
28
-
29
- test('pruneFrames 不足上限时一张不删', () => {
30
- const dir = mkdtempSync(path.join(tmpdir(), 'rsp-frames-'))
31
- for (let i = 0; i < 5; i++) writeFileSync(path.join(dir, `frame-${1700000000000 + i}.jpg`), 'x')
32
- pruneFrames(dir)
33
- assert.equal(readdirSync(dir).filter((n) => n.startsWith('frame-')).length, 5)
34
- })
35
-
36
- test('pruneFrames 目录不存在时静默返回', () => {
37
- assert.doesNotThrow(() => pruneFrames(path.join(tmpdir(), 'rsp-frames-definitely-missing-xyz')))
38
- })
39
-
40
- test('查看器 innerHTML 插值全部经 esc 转义', () => {
41
- const html = readFileSync(path.join(here, '..', 'ui', 'index.html'), 'utf8')
42
- assert.match(html, /function esc\(s\)/)
43
- // fillSelect 的 label 与 renderStatus 的 k/v 都必须包 esc(...)
44
- assert.match(html, /sel\.innerHTML = options\.map\(\(\[v, label\]\) => .*esc\(label\)/)
45
- assert.match(html, /\$\('status'\)\.innerHTML = rows\.map\(\(\[k, v\]\) => .*esc\(k\).*esc\(v\)/)
46
- // 不允许再出现未转义的裸 label / 裸 v 插值
47
- assert.ok(!/'>' \+ label \+ '<\/option>'/.test(html))
48
- assert.ok(!/'<span class="v">' \+ v \+ '<\/span>'/.test(html))
49
- })