@capyclaw/rsp-suite 0.0.0-stage → 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.
- package/README.md +84 -2
- package/cordis.patch.yml +8 -0
- package/dsh-suite.json +91 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +88 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +50 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +352 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +258 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +140 -0
- package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -0
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
- package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +72 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +120 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
- package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +38 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +88 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +54 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +187 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +195 -0
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +115 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +198 -0
- package/node_modules/@capyclaw/foundation/package.json +53 -0
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
- package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
- package/node_modules/@capyclaw/plugin-kit/package.json +72 -0
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +60 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/ledger.mjs +151 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +664 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/README.md +7 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/contract/rsp-contract.json +478 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/package.json +33 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/plugin.mjs +15 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/skills/remote-screen/SKILL.md +131 -0
- package/node_modules/@capyclaw/rsp-workbench/contract/capabilities.json +203 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/client.mjs +681 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/descriptors.mjs +28 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/host.mjs +51 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/manager.mjs +333 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/session-mode.mjs +68 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/tools.mjs +485 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/workbench.mjs +184 -0
- package/node_modules/@capyclaw/rsp-workbench/package.json +47 -0
- package/node_modules/@capyclaw/rsp-workbench/plugin.mjs +17 -0
- package/node_modules/@capyclaw/rsp-workbench/ui/index.html +578 -0
- package/node_modules/@capyclaw/service-host/README.md +86 -0
- package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
- package/node_modules/@capyclaw/service-host/package.json +60 -0
- package/node_modules/@capyclaw/service-host/src/index.mjs +597 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/suite-kit/README.md +289 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
- package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
- package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
- package/node_modules/@capyclaw/suite-kit/package.json +58 -0
- package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
- package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
- package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
- package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
- package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
- package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
- package/node_modules/@capyclaw/suite-kit/src/host.mjs +251 -0
- package/node_modules/@capyclaw/suite-kit/src/index.mjs +24 -0
- package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
- package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
- package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
- package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
- package/node_modules/@capyclaw/suite-kit/suite.schema.json +128 -0
- package/node_modules/@capyclaw/tool-host/README.md +56 -0
- package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +46 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/admit-images.mjs +80 -0
- package/node_modules/@capyclaw/tool-host/src/caller-session.mjs +25 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +166 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +461 -0
- package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +272 -0
- package/node_modules/ws/LICENSE +20 -0
- package/node_modules/ws/README.md +539 -0
- package/node_modules/ws/browser.js +8 -0
- package/node_modules/ws/index.js +22 -0
- package/node_modules/ws/lib/buffer-util.js +142 -0
- package/node_modules/ws/lib/constants.js +19 -0
- package/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/ws/lib/permessage-deflate.js +530 -0
- package/node_modules/ws/lib/receiver.js +751 -0
- package/node_modules/ws/lib/sender.js +610 -0
- package/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/ws/lib/websocket-server.js +562 -0
- package/node_modules/ws/lib/websocket.js +1440 -0
- package/node_modules/ws/package.json +74 -0
- package/node_modules/ws/wrapper.mjs +21 -0
- package/package.json +53 -4
package/README.md
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @capyclaw/rsp-suite — RSP/1 远程屏幕控制端套件
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
把 **RSP/1(Remote Screen Protocol)** 的控制端接进 DSH 套件基建:AI 通过 `rsp_*` 工具
|
|
4
|
+
连接被控端设备 → 观察实时屏幕帧 → 注入鼠标/键盘/文本 → 抓帧验证,完成对远程设备的 AI 操控。
|
|
5
|
+
与 ppt-suite / browser-suite 同一套基建(toolHost / serviceHost / suite-kit / 描述符面 / skill)。
|
|
6
|
+
|
|
7
|
+
## 组成
|
|
8
|
+
|
|
9
|
+
| 包 | 角色 | 说明 |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `@capyclaw/rsp-workbench` | runtime | 控制端核心 + 10 个 `rsp_*` 工具 + HTTP/MCP 能力面 + 查看器(挂 `/capyclaw/rsp`) |
|
|
12
|
+
| `@capyclaw/rsp-skill-remote-screen` | skills | `remote-screen` 技能:观察→操控→验证 工作流与硬规则 |
|
|
13
|
+
|
|
14
|
+
## 工具面(rsp_*)
|
|
15
|
+
|
|
16
|
+
- `rsp_capabilities` / `rsp_status` — 契约与连接状态(先调它们)
|
|
17
|
+
- `rsp_connect` / `rsp_disconnect` — 连接/断开被控端(url 或 host+port,token;目标持久化)
|
|
18
|
+
- `rsp_screen` — 抓当前屏幕帧:JPEG 内联回模型 + 落盘路径 + 帧/逻辑尺寸
|
|
19
|
+
- `rsp_mouse` — move/down/up/click/scroll(clicks=2 双击;dy>0 向上滚)
|
|
20
|
+
- `rsp_key` — 物理键 down/up(DOM `KeyboardEvent.code` + modifiers,成对发送)
|
|
21
|
+
- `rsp_text` — Unicode 文本注入(绕过布局/IME;>4096 码元自动分片)
|
|
22
|
+
- `rsp_drag` — down→插值 move→up 拖拽
|
|
23
|
+
- `rsp_batch` — 多事件一次提交顺序注入,可末尾抓帧验证(减少模型往返)
|
|
24
|
+
|
|
25
|
+
**坐标人体工学**:鼠标/拖拽默认接受「最近一帧截图的像素坐标」(`space:"frame"`),
|
|
26
|
+
控制端自动按 帧尺寸→hello 逻辑尺寸 换算成逻辑点上线(协议合规);`space:"logical"` 直传。
|
|
27
|
+
|
|
28
|
+
## 人机同看(GUI 主区实时画面)
|
|
29
|
+
|
|
30
|
+
查看器 `/capyclaw/rsp/` 是双层结构:底层 `api/frame` 快照(保证静止时也有图),
|
|
31
|
+
上层 `api/screen.mjpg` 实时流(有变化时覆盖)。左下角显示「更新于 N 秒前」——
|
|
32
|
+
被控端是**变化驱动**的,屏幕静止时本来就不推新帧,这是正常现象。
|
|
33
|
+
|
|
34
|
+
主区显示走 portal-hud 的会话模式(与 ppt/browser 同语义):
|
|
35
|
+
|
|
36
|
+
- `workbench/lib/session-mode.mjs`:非 read 工具执行前把**调用者会话**钉到 `rsp`
|
|
37
|
+
(`workStore.claimSessionMode(sid,'rsp','rsp-workbench')`;会话 id 取自
|
|
38
|
+
`exec.agent.session.id`,MCP/HTTP 形态没有 exec 就不认领,绝不误锁);
|
|
39
|
+
- 认领成功后 portal-hud 把 `slug=rsp` 的 surface 摆到主区,用户随时人工介入;
|
|
40
|
+
- 会话已钉给别的工作台 → 工具报 `SESSION_MODE_LOCKED`(带 `lockedTo`),提示新开会话。
|
|
41
|
+
|
|
42
|
+
## 协议符合性(RSP/1)
|
|
43
|
+
|
|
44
|
+
- `/info` 校验 `protocol=="rsp/1"`、`format=="jpeg"`;未知字段忽略。
|
|
45
|
+
- 画面:`/screen.ws` 常驻(TEXT hello + BINARY JPEG),断线退避 1s→5s 重连;4001→鉴权失败。
|
|
46
|
+
查看器走 `/api/screen.mjpg` 服务端代理(MJPEG),**令牌不下发页面**。
|
|
47
|
+
- 操控:`/control.ws` seq/ack 优先,失败降级 `POST /control`;move 限速 ≤60/s;
|
|
48
|
+
断开时主动补发按下态的 up(配合被控端 §5.5 防卡键)。
|
|
49
|
+
- 错误模型:401/403/400/413/503 与 WS 4001/4003/4004 全映射为工具错误码 + 提示。
|
|
50
|
+
|
|
51
|
+
## 安装(suite-kit)
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
node C/packages/capyclaw-suite-kit/bin/dsh-suite.mjs validate A/projects/rsp
|
|
55
|
+
# 连同已有本地 suite 一起安装(installSuites 会重写 dshSuiteKit.suites,必须全量传入)
|
|
56
|
+
node C/packages/capyclaw-suite-kit/bin/dsh-suite.mjs install \
|
|
57
|
+
B/suites/capyclaw-works-suite A/projects/capyclaw A/projects/conductor A/projects/rsp \
|
|
58
|
+
--profile desktop
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
安装后重启/重载 profile:`rsp_*` 工具进 DSH 工具面,查看器挂 `/capyclaw/rsp`,
|
|
62
|
+
`remote-screen` skill 进技能目录,10 个 `rsp.*` 描述符进公共发现面(conductor 可编排)。
|
|
63
|
+
|
|
64
|
+
## 测试
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
cd workbench && npm test # node --test:42 个用例
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`test/mock-server.mjs` 是严格按 RSP/1 实现的被控端 mock(hello/帧流/ack/鉴权/禁用/§5.5),
|
|
71
|
+
覆盖:协议握手、帧尺寸解析、坐标换算、bad_event 保持连接、401/4001、403、POST 降级、
|
|
72
|
+
断线补 up、退避重连、move 限速、MJPEG 代理、MCP 富内容、描述符校验、会话模式守卫
|
|
73
|
+
(认领/异种类硬拒/无 exec 不认领/幂等)、H.264 增量通道(503 回退/代理字节级一致/hello+head 缓存)。
|
|
74
|
+
|
|
75
|
+
实时画面(ToDesk 级低延迟)方案与开源核心提取见 [docs/realtime.md](docs/realtime.md):
|
|
76
|
+
瓶颈在被控端每帧临时抓屏+软件 JPEG(实测 1.4fps/623ms);改用持久采集+硬件 H.264
|
|
77
|
+
(FFmpeg LGPL 独立进程)实测 25.8fps/18ms。控制端已内置 `/screen.h264.ws` 客户端、
|
|
78
|
+
`/api/screen.h264` chunked 代理与 WebCodecs 硬解查看器,被控端增量升级后即插即用。
|
|
79
|
+
|
|
80
|
+
## 安全
|
|
81
|
+
|
|
82
|
+
- 令牌是 bearer 凭证(持有即完全控制被控端屏幕与输入):只存服务端 `hostDir/targets.json`,
|
|
83
|
+
工具回显一律掩码;公网部署必须前置 TLS。
|
|
84
|
+
- 屏幕内容是不可信数据;敏感操作先征得用户同意(见 skill 硬规则)。
|
|
85
|
+
- 被控端可整体关闭操控通道(只读共享);锁屏时注入无效。
|
package/cordis.patch.yml
ADDED
package/dsh-suite.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../../C/packages/capyclaw-suite-kit/suite.schema.json",
|
|
3
|
+
"name": "capyclaw-rsp-suite",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"title": "RSP 远程屏幕控制端套件",
|
|
6
|
+
"description": "RSP/1 控制端工作台(挂在 dsh 的 /capyclaw/rsp,路由与端口由基建决定)+ remote-screen skill。画面只读、操控只写;AI 经 rsp_* 工具连接被控端、观察屏幕帧、注入鼠标/键盘/文本并抓帧验证。公共基建(toolHost / serviceHost)由 @capyclaw/core 统一提供,需同一 profile 启用它。",
|
|
7
|
+
"packages": {
|
|
8
|
+
"@capyclaw/rsp-workbench": {
|
|
9
|
+
"role": "runtime",
|
|
10
|
+
"version": "0.1.0",
|
|
11
|
+
"path": "./node_modules/@capyclaw/rsp-workbench",
|
|
12
|
+
"requires": {
|
|
13
|
+
"capabilities": {
|
|
14
|
+
"host.http": "^1.0.0",
|
|
15
|
+
"tools.registry": "^1.0.0",
|
|
16
|
+
"tools.descriptors": "^1.1.0"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"provides": {
|
|
20
|
+
"tools": [
|
|
21
|
+
"rsp_*"
|
|
22
|
+
],
|
|
23
|
+
"capabilities": {
|
|
24
|
+
"rsp.remote": "0.1.0",
|
|
25
|
+
"rsp.surfaceLifecycle": "1.0.0"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"surfaceLifecycle": {
|
|
29
|
+
"hooks": [
|
|
30
|
+
"onVisibility",
|
|
31
|
+
"suspendRender",
|
|
32
|
+
"resumeRender",
|
|
33
|
+
"rehydrate"
|
|
34
|
+
],
|
|
35
|
+
"headlessObservation": true
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"@capyclaw/rsp-skill-remote-screen": {
|
|
39
|
+
"role": "skills",
|
|
40
|
+
"version": "0.1.0",
|
|
41
|
+
"path": "./node_modules/@capyclaw/rsp-skill-remote-screen",
|
|
42
|
+
"requires": {
|
|
43
|
+
"@capyclaw/rsp-workbench": "^0.1.0",
|
|
44
|
+
"capabilities": {
|
|
45
|
+
"rsp.remote": "^0.1.0"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"provides": {
|
|
49
|
+
"skills": [
|
|
50
|
+
"remote-screen"
|
|
51
|
+
],
|
|
52
|
+
"capabilities": {
|
|
53
|
+
"rsp.workflows": "0.1.0"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"@capyclaw/tool-host": {
|
|
58
|
+
"role": "provider",
|
|
59
|
+
"version": "^0.3.0",
|
|
60
|
+
"provides": {
|
|
61
|
+
"capabilities": {
|
|
62
|
+
"tools.registry": "1.1.0",
|
|
63
|
+
"tools.descriptors": "1.1.0"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"@capyclaw/service-host": {
|
|
68
|
+
"role": "provider",
|
|
69
|
+
"version": "^0.1.5",
|
|
70
|
+
"provides": {
|
|
71
|
+
"capabilities": {
|
|
72
|
+
"host.http": "1.0.0"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"rows": [
|
|
78
|
+
{
|
|
79
|
+
"id": "rsp-workbench",
|
|
80
|
+
"name": "@capyclaw/rsp-workbench",
|
|
81
|
+
"config": {
|
|
82
|
+
"mountPath": "/capyclaw/rsp"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"id": "rsp-skill-remote-screen",
|
|
87
|
+
"name": "@capyclaw/rsp-skill-remote-screen"
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
"checks": []
|
|
91
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @capyclaw/foundation
|
|
2
|
+
|
|
3
|
+
dsh 插件基石层:接口 ABI、插件加载器与内核服务 `ctx.os`。
|
|
4
|
+
|
|
5
|
+
应用插件不再写 `inject` / `apply` / provider 装配,只声明「我实现了哪个接口」:
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { createPlugin, skillProvider } from '@capyclaw/foundation/abi'
|
|
9
|
+
|
|
10
|
+
export const { name, inject, apply } = createPlugin({
|
|
11
|
+
name: 'canvas',
|
|
12
|
+
requires: ['canvas.runtime@^1'],
|
|
13
|
+
implements: [skillProvider({ skill: './skills/canvas' })],
|
|
14
|
+
}, import.meta.url)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 四个入口
|
|
18
|
+
|
|
19
|
+
| 入口 | 内容 | 谁用 |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `.` | Cordis 插件,产出 `ctx.os` | dsh profile |
|
|
22
|
+
| `./abi` | 描述符构建器、加载器、错误码、版本工具 | 应用插件 |
|
|
23
|
+
| `./kit` | plugin-kit 兼容导出,包含 Node/dsh 耦合,非纯函数库 | 兼容调用方 |
|
|
24
|
+
| `./runtime` | `createKernel` 等宿主 API | dsh 之外的宿主(独立技能服务、测试夹具) |
|
|
25
|
+
|
|
26
|
+
## 状态
|
|
27
|
+
|
|
28
|
+
- 包清单当前为 `0.1.6`;0.1.6 修的是「关掉插件再启用撞 E_DUP_PLUGIN」(disposer 未登记 + 失败
|
|
29
|
+
记录占名),详见下面的「生命周期」。
|
|
30
|
+
- 分层:应用插件 → ABI → 内核 → Host 适配器 → 本地 Node.js agent 运行时。
|
|
31
|
+
dsh 服务访问位于 Host 适配层;memory 只是参考实现,不证明第二个真实 agent 兼容。
|
|
32
|
+
HTTP/资源/进程仍有本地 Node 协议约束,详见 `docs/HOST-ADAPTER.md`。
|
|
33
|
+
- ABI v1,六个标准接口 + `host-event@1` + `client-panel@1` + `service-provider@1` +
|
|
34
|
+
`own-server@1` + 可执行 `raw@1`;基建插件使用 `defineDriver` 驱动入口。
|
|
35
|
+
- 能力表按 `ctx` 实际服务探测(见 `lib/kernel.mjs` 的 `detectCapabilities`),不做空头承诺。
|
|
36
|
+
- 当前仓库:27 个插件走标准接口,`raw@1` 当前为空,6 个基建插件走
|
|
37
|
+
`defineDriver` 驱动层;`meta/foundation.allowlist.json` 的模糊豁免为 0。
|
|
38
|
+
详见 `docs/POLICY.md` 与 `docs/spec/plugin-abi.md`。
|
|
39
|
+
|
|
40
|
+
设计规范见 `docs/spec/plugin-abi.md`,强制规则见 `docs/POLICY.md`。
|
|
41
|
+
|
|
42
|
+
## 生命周期(0.1.6 起)
|
|
43
|
+
|
|
44
|
+
`createPlugin().apply` 会把 `os.mount()` 的 disposer 通过 `ctx.effect(() => () => dispose())`
|
|
45
|
+
登记到本次激活的 ctx 上——**不能只靠 apply 的返回值**:Cordis 只认 `ctx.effect` 回调返回的
|
|
46
|
+
disposer,返回值不可靠。漏登记时,关掉插件后内核里的记录不会摘除,再次启用就会撞
|
|
47
|
+
`E_DUP_PLUGIN: 插件 xxx 已挂载`。
|
|
48
|
+
|
|
49
|
+
加载器侧另有两条兜底:`mount()` 遇到 `disposed` / `failed` 的旧记录会先摘掉并尽力回收;
|
|
50
|
+
`start` 失败清理完成后立即让出插件名。两者共同保证「关掉 → 再启用」可重复无数次。
|
|
51
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 资产引用契约的单一真源(公共 ABI 常量)。
|
|
3
|
+
*
|
|
4
|
+
* 互操作标准里资产有两副面孔,前缀在这里定义一次,内核门面与资产服务都引用它,
|
|
5
|
+
* 避免「路由实现」与「URL 门面」各写一份 '/assets/' 而漂移:
|
|
6
|
+
* - 字节仓 HTTP 路由前缀 ASSET_URL_PREFIX = '/assets/' (asset-service 挂 GET/HEAD)
|
|
7
|
+
* - 结构化正文里的引用前缀 ASSET_REF_PREFIX = '@asset/' (work-store 信封/正文只存引用)
|
|
8
|
+
*
|
|
9
|
+
* 这是契约常量,不是宿主服务名——放 ABI 层,应用与驱动都可 import。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** 资产字节仓的 HTTP 路由前缀(asset-service 实现,内核 os.assets.url 复用)。 */
|
|
13
|
+
export const ASSET_URL_PREFIX = '/assets/'
|
|
14
|
+
|
|
15
|
+
/** 结构化正文/产物信封里的内容寻址引用前缀(@asset/<sha256>)。 */
|
|
16
|
+
export const ASSET_REF_PREFIX = '@asset/'
|
|
17
|
+
|
|
18
|
+
/** 由资产 id 生成可加载 URL:/assets/<id>(id 做 URI 编码)。 */
|
|
19
|
+
export function assetUrl(id) {
|
|
20
|
+
return `${ASSET_URL_PREFIX}${encodeURIComponent(String(id))}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 由资产 id 生成规范引用:@asset/<id>。 */
|
|
24
|
+
export function assetRef(id) {
|
|
25
|
+
return `${ASSET_REF_PREFIX}${String(id)}`
|
|
26
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 桥(editor bridge)与文档模型的标准声明。
|
|
3
|
+
*
|
|
4
|
+
* 这一层只放「协议常量 + 声明校验」,不放运行时:
|
|
5
|
+
* - 常量:协议版本、模型版本、能力名(suite 清单与 healthz 都用它)
|
|
6
|
+
* - declareBridge():把工作台的声明冻结成标准形状
|
|
7
|
+
* - assertBridgeRuntime():启动/巡检时把「声明」与「运行时实际上报」对齐
|
|
8
|
+
*
|
|
9
|
+
* 运行时(relay / 队列 / 租约)仍在 @capyclaw/document-workbench + service-host,
|
|
10
|
+
* 不进 ABI 层:foundation 是所有插件的地基,不该背 HTTP/store 依赖。
|
|
11
|
+
*
|
|
12
|
+
* 能力名(与 suite 清单的 requires/provides.capabilities 对应):
|
|
13
|
+
* editor.bridge —— 插件提供一个编辑器权威桥(/healthz + /status + /watch + /ack)
|
|
14
|
+
* doc.model —— 插件提供文档模型(稳定 ID / 清单 / 定位 / 编辑计划 / 校验)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { AbiError, ERROR_CODES } from './errors.mjs'
|
|
18
|
+
|
|
19
|
+
/** 桥协议版本:端点集合与状态机语义的主版本。不兼容变更才升 major。 */
|
|
20
|
+
export const BRIDGE_PROTOCOL_VERSION = '1.0.0'
|
|
21
|
+
|
|
22
|
+
/** 文档模型版本:清单字段、定位器语义、编辑 op 的主版本。 */
|
|
23
|
+
export const DOC_MODEL_VERSION = '1.0.0'
|
|
24
|
+
|
|
25
|
+
export const BRIDGE_CAPABILITY = 'editor.bridge'
|
|
26
|
+
export const DOC_MODEL_CAPABILITY = 'doc.model'
|
|
27
|
+
|
|
28
|
+
/** healthz 里桥声明的字段名(避免与既有的 bridge: '<name>' 字符串冲突)。 */
|
|
29
|
+
export const BRIDGE_INFO_FIELD = 'bridgeInfo'
|
|
30
|
+
|
|
31
|
+
const ID_RE = /^[a-z0-9][a-z0-9-]*$/
|
|
32
|
+
const VERSION_RE = /^\d+\.\d+\.\d+$/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 校验并冻结一份桥声明。
|
|
36
|
+
* @param {{ id: string, protocol?: string, model?: string|null, editor?: 'required'|'optional' }} input
|
|
37
|
+
*/
|
|
38
|
+
export function declareBridge(input = {}) {
|
|
39
|
+
const { id, protocol = BRIDGE_PROTOCOL_VERSION, model = null, editor = 'required' } = input
|
|
40
|
+
const errors = []
|
|
41
|
+
if (typeof id !== 'string' || !ID_RE.test(id)) errors.push(`id 必须是 kebab-case:${id}`)
|
|
42
|
+
if (!VERSION_RE.test(protocol)) errors.push(`protocol 版本非法:${protocol}`)
|
|
43
|
+
if (model !== null && !VERSION_RE.test(model)) errors.push(`model 版本非法:${model}`)
|
|
44
|
+
if (editor !== 'required' && editor !== 'optional') errors.push(`editor 只能是 required/optional:${editor}`)
|
|
45
|
+
if (errors.length) throw new AbiError(ERROR_CODES.E_SCHEMA, `桥声明非法:${errors.join(';')}`, { errors })
|
|
46
|
+
return Object.freeze({ id, protocol, model, editor })
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 桥声明 → suite 清单里的 provides.capabilities。 */
|
|
50
|
+
export function bridgeCapabilities(declaration) {
|
|
51
|
+
const decl = declaration && declaration.protocol ? declaration : declareBridge(declaration)
|
|
52
|
+
return Object.freeze({
|
|
53
|
+
[BRIDGE_CAPABILITY]: decl.protocol,
|
|
54
|
+
...(decl.model ? { [DOC_MODEL_CAPABILITY]: decl.model } : {}),
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 桥声明 → suite 清单里工具面对运行时的 requires.capabilities(skill 包用)。 */
|
|
59
|
+
export function bridgeConsumerRequirements(ns, { needsModel = false } = {}) {
|
|
60
|
+
const out = { [`${ns}.runtime`]: `^${BRIDGE_PROTOCOL_VERSION}` }
|
|
61
|
+
if (needsModel) out[DOC_MODEL_CAPABILITY] = `^${DOC_MODEL_VERSION}`
|
|
62
|
+
return Object.freeze(out)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 声明与运行时对账:启动或巡检时调用。
|
|
67
|
+
*
|
|
68
|
+
* @param {object} declaration declareBridge 的结果(来自插件代码/清单)
|
|
69
|
+
* @param {object} runtime healthz 里的 bridgeInfo(实际运行值)
|
|
70
|
+
* @returns {{ ok: boolean, issues: string[] }}
|
|
71
|
+
*/
|
|
72
|
+
export function assertBridgeRuntime(declaration, runtime) {
|
|
73
|
+
const issues = []
|
|
74
|
+
const decl = declaration && declaration.id ? declaration : declareBridge(declaration || {})
|
|
75
|
+
if (!runtime || typeof runtime !== 'object') {
|
|
76
|
+
return { ok: false, issues: [`运行时没有上报 ${BRIDGE_INFO_FIELD}`] }
|
|
77
|
+
}
|
|
78
|
+
if (runtime.id !== decl.id) issues.push(`id 不一致:声明 ${decl.id} / 运行 ${runtime.id}`)
|
|
79
|
+
if (runtime.protocol !== decl.protocol) {
|
|
80
|
+
issues.push(`协议版本不一致:声明 ${decl.protocol} / 运行 ${runtime.protocol}`)
|
|
81
|
+
}
|
|
82
|
+
const declaredModel = decl.model || null
|
|
83
|
+
const runtimeModel = runtime.model || null
|
|
84
|
+
if (declaredModel !== runtimeModel) {
|
|
85
|
+
issues.push(`模型版本不一致:声明 ${declaredModel || '无'} / 运行 ${runtimeModel || '无'}`)
|
|
86
|
+
}
|
|
87
|
+
return { ok: issues.length === 0, issues }
|
|
88
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ABI 错误模型:稳定的错误码 + 结构化 detail。
|
|
3
|
+
*
|
|
4
|
+
* 约定:
|
|
5
|
+
* - 应用插件按 code 分支,不解析 message 文案;
|
|
6
|
+
* - message 面向人,detail 面向程序;
|
|
7
|
+
* - 所有加载期失败都必须是 AbiError,不允许裸 Error 穿透。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** 稳定错误码。新增只能追加,不得改语义。 */
|
|
11
|
+
export const ERROR_CODES = Object.freeze({
|
|
12
|
+
/** 插件入口形状不对:缺 name / 没有 implements / 导出了 apply 等。 */
|
|
13
|
+
E_PLUGIN_SHAPE: 'E_PLUGIN_SHAPE',
|
|
14
|
+
/** 插件声明的 ABI 主版本与内核不兼容。 */
|
|
15
|
+
E_ABI_MISMATCH: 'E_ABI_MISMATCH',
|
|
16
|
+
/** 描述符的 kind 不在内核认识的接口表里。 */
|
|
17
|
+
E_KIND_UNKNOWN: 'E_KIND_UNKNOWN',
|
|
18
|
+
/** 描述符字段不满足接口 schema。 */
|
|
19
|
+
E_SCHEMA: 'E_SCHEMA',
|
|
20
|
+
/** 内核没有提供该能力(通常是 os.* 子系统缺失)。 */
|
|
21
|
+
E_CAP_MISSING: 'E_CAP_MISSING',
|
|
22
|
+
/** 唯一性接口被第二个插件实现(例如同 id 的 runtime-driver)。 */
|
|
23
|
+
E_DUP_INTERFACE: 'E_DUP_INTERFACE',
|
|
24
|
+
/** 同名插件被重复挂载。 */
|
|
25
|
+
E_DUP_PLUGIN: 'E_DUP_PLUGIN',
|
|
26
|
+
/** 内核没有为这个 kind 注册适配器(接口定义存在但实现未就绪)。 */
|
|
27
|
+
E_KIND_UNAVAILABLE: 'E_KIND_UNAVAILABLE',
|
|
28
|
+
/** 适配器在编译期抛错。 */
|
|
29
|
+
E_ADAPTER_THREW: 'E_ADAPTER_THREW',
|
|
30
|
+
/** 插件入口没有拿到 baseUrl,相对路径无法解析。 */
|
|
31
|
+
E_BASE_URL_MISSING: 'E_BASE_URL_MISSING',
|
|
32
|
+
/** 运行时没有 ctx.os:foundation 未安装或未启用。 */
|
|
33
|
+
E_KERNEL_MISSING: 'E_KERNEL_MISSING',
|
|
34
|
+
E_KERNEL_CLOSED: 'E_KERNEL_CLOSED',
|
|
35
|
+
E_NOT_READY: 'E_NOT_READY',
|
|
36
|
+
E_CAP_RESERVED: 'E_CAP_RESERVED',
|
|
37
|
+
E_CAP_CONFLICT: 'E_CAP_CONFLICT',
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export class AbiError extends Error {
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} code ERROR_CODES 中的一项
|
|
43
|
+
* @param {string} message 面向人的说明
|
|
44
|
+
* @param {Record<string, unknown>} [detail] 面向程序的结构化信息
|
|
45
|
+
*/
|
|
46
|
+
constructor(code, message, detail = {}) {
|
|
47
|
+
super(`[${code}] ${message}`)
|
|
48
|
+
this.name = 'AbiError'
|
|
49
|
+
this.code = code
|
|
50
|
+
this.detail = detail
|
|
51
|
+
if (detail.cause instanceof Error) this.cause = detail.cause
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isAbiError(error) {
|
|
56
|
+
return error instanceof AbiError
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 把任意异常归一成 AbiError(已归一的原样返回)。 */
|
|
60
|
+
export function toAbiError(error, code = ERROR_CODES.E_ADAPTER_THREW, detail = {}) {
|
|
61
|
+
if (error instanceof AbiError) return error
|
|
62
|
+
return new AbiError(code, error?.message || String(error), { ...detail, cause: error })
|
|
63
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** 接口 ABI 的唯一入口:应用插件只需要 import 这个模块。 */
|
|
2
|
+
export { ABI_MAJOR, INTERFACE_KINDS, INTERFACE_KIND_NAMES, getInterfaceKind } from './kinds.mjs'
|
|
3
|
+
export {
|
|
4
|
+
defineInterface,
|
|
5
|
+
definePlugin,
|
|
6
|
+
createPlugin,
|
|
7
|
+
skillProvider,
|
|
8
|
+
toolProvider,
|
|
9
|
+
runtimeDriver,
|
|
10
|
+
httpRouter,
|
|
11
|
+
uiPanel,
|
|
12
|
+
lifecycleHook,
|
|
13
|
+
hostEvent,
|
|
14
|
+
clientPanel,
|
|
15
|
+
ownServer,
|
|
16
|
+
serviceProvider,
|
|
17
|
+
defineDriver,
|
|
18
|
+
rawPlugin,
|
|
19
|
+
} from './spec.mjs'
|
|
20
|
+
/* createLoader 是宿主/测试侧装配 API(内核 createKernel 与一致性测试用),虽从 abi 导出,
|
|
21
|
+
* 应用插件不应直接调用——应用只用 createPlugin + 接口 builders(见 plugin-abi.md §二)。 */
|
|
22
|
+
export { createLoader } from './loader.mjs'
|
|
23
|
+
export {
|
|
24
|
+
BRIDGE_CAPABILITY,
|
|
25
|
+
BRIDGE_INFO_FIELD,
|
|
26
|
+
BRIDGE_PROTOCOL_VERSION,
|
|
27
|
+
DOC_MODEL_CAPABILITY,
|
|
28
|
+
DOC_MODEL_VERSION,
|
|
29
|
+
assertBridgeRuntime,
|
|
30
|
+
bridgeCapabilities,
|
|
31
|
+
bridgeConsumerRequirements,
|
|
32
|
+
declareBridge,
|
|
33
|
+
} from './bridge.mjs'
|
|
34
|
+
export {
|
|
35
|
+
SURFACE_LIFECYCLE_VERSION,
|
|
36
|
+
SURFACE_LIFECYCLE_CAPABILITY_SUFFIX,
|
|
37
|
+
VISIBILITY_ACK_MESSAGE,
|
|
38
|
+
VISIBILITY_DEFAULTS,
|
|
39
|
+
VISIBILITY_MESSAGE,
|
|
40
|
+
VISIBILITY_STATES,
|
|
41
|
+
assertSurfaceLifecycle,
|
|
42
|
+
isVisibilityState,
|
|
43
|
+
normalizeVisibilityState,
|
|
44
|
+
surfaceLifecycleCapability,
|
|
45
|
+
} from './visibility.mjs'
|
|
46
|
+
export { ASSET_URL_PREFIX, ASSET_REF_PREFIX, assetUrl, assetRef } from './assets.mjs'
|
|
47
|
+
export { validateInterface } from './validate.mjs'
|
|
48
|
+
export { AbiError, ERROR_CODES, isAbiError, toAbiError } from './errors.mjs'
|
|
49
|
+
export { validateSchema } from './schema.mjs'
|
|
50
|
+
export { parseVersion, compareVersions, satisfies } from './version.mjs'
|