@capyclaw/capyclaw-workbench 0.0.0-stage → 0.1.0

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 (109) hide show
  1. package/README.md +28 -2
  2. package/contract/capabilities.json +178 -0
  3. package/lib/descriptors.mjs +33 -0
  4. package/lib/host.mjs +102 -0
  5. package/lib/session-port.mjs +104 -0
  6. package/lib/tools.mjs +166 -0
  7. package/lib/workbench.mjs +133 -0
  8. package/node_modules/@capyclaw/foundation/README.md +51 -0
  9. package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
  10. package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
  11. package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
  12. package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
  13. package/node_modules/@capyclaw/foundation/abi/loader.mjs +345 -0
  14. package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
  15. package/node_modules/@capyclaw/foundation/abi/spec.mjs +255 -0
  16. package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
  17. package/node_modules/@capyclaw/foundation/abi/version.mjs +82 -0
  18. package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
  19. package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
  20. package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
  21. package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
  22. package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
  23. package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
  24. package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
  25. package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +68 -0
  26. package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +113 -0
  27. package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
  28. package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
  29. package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
  30. package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
  31. package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
  32. package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +34 -0
  33. package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
  34. package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
  35. package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +160 -0
  36. package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
  37. package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
  38. package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +87 -0
  39. package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
  40. package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
  41. package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +188 -0
  42. package/node_modules/@capyclaw/foundation/package.json +53 -0
  43. package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
  44. package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
  45. package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
  46. package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
  47. package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
  48. package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
  49. package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
  50. package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
  51. package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +139 -0
  52. package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
  53. package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
  54. package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
  55. package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
  56. package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
  57. package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
  58. package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
  59. package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
  60. package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +143 -0
  61. package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
  62. package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
  63. package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
  64. package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
  65. package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
  66. package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +41 -0
  67. package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
  68. package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
  69. package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
  70. package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
  71. package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
  72. package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
  73. package/node_modules/@capyclaw/service-host/README.md +86 -0
  74. package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
  75. package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
  76. package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
  77. package/node_modules/@capyclaw/service-host/package.json +60 -0
  78. package/node_modules/@capyclaw/service-host/src/index.mjs +571 -0
  79. package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
  80. package/node_modules/@capyclaw/suite-kit/README.md +238 -0
  81. package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
  82. package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
  83. package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
  84. package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
  85. package/node_modules/@capyclaw/suite-kit/package.json +54 -0
  86. package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
  87. package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
  88. package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
  89. package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
  90. package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
  91. package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
  92. package/node_modules/@capyclaw/suite-kit/src/index.mjs +10 -0
  93. package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
  94. package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
  95. package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
  96. package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
  97. package/node_modules/@capyclaw/suite-kit/suite.schema.json +112 -0
  98. package/node_modules/@capyclaw/tool-host/README.md +56 -0
  99. package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
  100. package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
  101. package/node_modules/@capyclaw/tool-host/lib/host.mjs +16 -0
  102. package/node_modules/@capyclaw/tool-host/package.json +59 -0
  103. package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +142 -0
  104. package/node_modules/@capyclaw/tool-host/src/index.mjs +390 -0
  105. package/package.json +68 -4
  106. package/plugin.mjs +1 -0
  107. package/ui/app.js +114 -0
  108. package/ui/index.html +64 -0
  109. package/ui/style.css +54 -0
@@ -0,0 +1,238 @@
1
+ # @capyclaw/suite-kit(DSH 组合标准件)
2
+
3
+ 把“多个插件 + 一组 patch 行 + 健康检查 + 安装脚本”收成一个可校验、可组合、可诊断的标准件。
4
+
5
+ ## 一个 suite 的最小结构
6
+
7
+ ```text
8
+ my-suite/
9
+ ├─ package.json # dsh.bundle.patch -> cordis.patch.yml, dsh.suite -> dsh-suite.json
10
+ ├─ dsh-suite.json # 唯一真源:packages / rows / checks
11
+ ├─ cordis.patch.yml # 由 rows 生成,不手写
12
+ └─ lib/index.mjs # 可选:组合包自身的空实现
13
+ ```
14
+
15
+ `dsh-suite.json`:
16
+
17
+ ```json
18
+ {
19
+ "name": "my-suite",
20
+ "version": "1.0.0",
21
+ "title": "我的组合",
22
+ "packages": {
23
+ "my-plugin": {
24
+ "role": "runtime",
25
+ "version": "^1.0.0",
26
+ "path": "./plugins/my-plugin",
27
+ "provides": { "tools": ["my_*"], "ports": ["<port>"] }
28
+ }
29
+ },
30
+ "rows": [
31
+ { "id": "my-host", "name": "my-plugin" }
32
+ ],
33
+ "checks": [
34
+ { "id": "health", "type": "http", "url": "http://127.0.0.1:<port>/healthz", "expectStatus": 200 }
35
+ ]
36
+ }
37
+ ```
38
+
39
+ ## 两种组合粒度
40
+
41
+ ### Suite(组件集合)
42
+
43
+ 一个 suite 描述一组插件包和 patch 行。适合“一个产品/一个套件”。
44
+
45
+ suite 可以用 `components` 引用其他 suite,而不是复制它们的 C/packages/rows:
46
+
47
+ ```json
48
+ {
49
+ "name": "my-suite",
50
+ "components": ["../../packages/capyclaw-service-host", "../../packages/capyclaw-tool-host"],
51
+ "packages": { "my-plugin": { "role": "runtime", "version": "^1.0.0", "path": "../my-plugin" } },
52
+ "rows": [{ "id": "my-host", "name": "my-plugin" }]
53
+ }
54
+ ```
55
+
56
+ `loadSuiteManifest()` 会展开组件,并把组件行排在功能插件行之前,保证 `ctx.*`
57
+ 在功能插件 `apply()` 时已经就绪。`stageDomain` 会把展开后的 manifest 写入 staged
58
+ 组件,目录统一为 `components/<packageName>`。
59
+
60
+ ### Domain(领域包 / 启动单位)
61
+
62
+ 一个 domain 只选择某个工作领域需要的 suite,并生成独立 profile:
63
+
64
+ ```text
65
+ domain.json
66
+ components: [../ppt-suite, ../canvas-suite]
67
+ baseBundles: [dsh-base, dsh-web-app]
68
+ profile: { name: domain-ppt, port: 3080 }
69
+ ```
70
+
71
+ 启动时只加载 base + web-app + 选中的 suite;未选中的插件、skill、MCP 不注册。`stage` 只复制选中组件,形成一个可带走的领域包。
72
+
73
+ ## CLI
74
+
75
+ ```bash
76
+ dsh-suite validate ./my-suite
77
+ dsh-suite compose ./ppt-suite ./canvas-suite --out ./composed
78
+ dsh-suite install ./ppt-suite ./canvas-suite --profile web
79
+ dsh-suite doctor --profile web --dsh-bin /path/to/dsh
80
+ dsh-suite init ./new-suite --name my-suite --title "我的组合"
81
+
82
+ dsh-domain validate ./my-domain
83
+ dsh-domain resolve ./my-domain
84
+ dsh-domain install ./my-domain --profile domain-my --dsh-home ~/.dsh
85
+ dsh-domain stage ./my-domain --out ./dist/my-domain
86
+
87
+ # 直接启动需要处理 dsh 的登录 token;桌面/本地推荐走 auth-proxy 零登录
88
+ dsh-domain launch ./my-domain --auth-proxy /path/to/auth-proxy.mjs --port 3090 --proxy-port 3091
89
+
90
+ # 推荐:每个 DSH 进程一个 runtime(独立端口/目录/namespace)
91
+ dsh-runtime create --name my-runtime --domain ./my-domain
92
+ dsh-runtime start <runtimeId>
93
+ dsh-runtime list
94
+ dsh-runtime works <runtimeId>
95
+ dsh-runtime declare <runtimeId> main --files "state.json,journal.jsonl,checkpoints/**" --no-new
96
+ dsh-runtime stop <runtimeId>
97
+ ```
98
+
99
+ ## Runtime(统一中间层的启动单位)
100
+
101
+ `@capyclaw/suite-kit` 是统一中间层:它同时负责“打包哪些插件、分配哪些端口、
102
+ 创建哪个 runtime、这个 runtime 声明需要哪些工具/能力、工作范围多大、
103
+ 文件归属和生命周期”。
104
+
105
+ 每个 runtime 获得:
106
+
107
+ - `harness` 端口:浏览器访问 DSH 的入口;
108
+ - `dsh` 端口:auth-proxy 后面的 DSH 上游端口;
109
+ - `content` 端口:作品/编辑器的显示端口;
110
+ - 独立 `DSH_HOME`、profile、workspace、日志、临时目录、auth-proxy 锁;
111
+ - 独立 Content Store namespace token。
112
+
113
+ 启动声明写在 `dsh-domain.json` 的 `runtime` 段:
114
+
115
+ ```json
116
+ {
117
+ "runtime": {
118
+ "driver": "node",
119
+ "workId": "main",
120
+ "bindings": [
121
+ {
122
+ "row": "ppt-workbench-host",
123
+ "config": {
124
+ "port": "${ports.content}",
125
+ "hostDir": "${paths.contentState}",
126
+ "strictPort": true,
127
+ "workId": "${workId}"
128
+ }
129
+ }
130
+ ],
131
+ "env": {
132
+ "PPT_BRIDGE_HOME": "${paths.contentState}"
133
+ },
134
+ "model": {
135
+ "id": "llm-deepseek",
136
+ "plugin": "@deepseek-ai/dsh-llm-deepseek-api-key",
137
+ "apiKeyEnv": "DEEPSEEK_API_KEY",
138
+ "baseURL": "https://api.deepseek.com/anthropic"
139
+ },
140
+ "requires": {
141
+ "tools": ["ppt_*"],
142
+ "capabilities": ["ppt.runtime@^2.2.0"],
143
+ "services": ["ppt-workbench"]
144
+ },
145
+ "scope": {
146
+ "sessions": { "path": ".dsh/sessions", "isolated": true },
147
+ "files": [
148
+ { "id": "workspace", "kind": "workspace", "path": "workspace", "patterns": ["**"] },
149
+ { "id": "ppt", "kind": "content", "path": "content/ppt", "patterns": ["state.json", "journal.jsonl", "checkpoints/**"] }
150
+ ],
151
+ "workspace": {
152
+ "workId": "main",
153
+ "files": ["state.json", "journal.jsonl", "checkpoints/**"],
154
+ "allowNew": false
155
+ },
156
+ "network": { "bind": ["127.0.0.1"], "outbound": "none" }
157
+ },
158
+ "ports": {
159
+ "harness": { "preferred": 3080, "range": 100 },
160
+ "content": { "preferred": "<port>", "range": 100 }
161
+ }
162
+ }
163
+ }
164
+ ```
165
+
166
+ `dsh-runtime create` 在分配端口之前先校验 `requires`;`scope.workspace`
167
+ 会变成该 work 的 `manifest.json.declaration`,后续写入由中间层校验。
168
+ `scope.sessions` 和 `scope.files` 会解析成 `runtime.json.paths` /
169
+ `runtime.json.storage` 里的绝对路径:会话记录落在该 runtime 的
170
+ `DSH_HOME/sessions`,修改文件落在声明的 files 根目录内。
171
+ `bindings` 按 row/package 注入端口、目录、workId 等模板值,通用层不认具体插件名。
172
+ `env` 可按 runtime 注入插件兼容环境变量。`model` 会生成 runtime 自己的 `DSH_HOME/cordis.patch.yml` 模型通道,
173
+ 避免把用户的全局模型配置带进 runtime;`workspaceController` 会把
174
+ DSH 默认 workspace 固定到该 runtime 的 workspace 根目录下。
175
+ `declare` 命令可以在运行时调整声明:
176
+
177
+ ```bash
178
+ dsh-runtime works <runtimeId>
179
+ dsh-runtime declare <runtimeId> main --files "state.json,journal.jsonl,checkpoints/**" --no-new
180
+ ```
181
+
182
+ 同一个 runtime 内的多个会话共享同一个 work(例如 `main`);不同 runtime 即使
183
+ 使用相同 `workId` 也互相隔离。
184
+
185
+ 所有落盘文件都在同一个 `DSH_STORE_ROOT`(默认 `~/.dsh-store`):
186
+
187
+ ```text
188
+ <storeRoot>/
189
+ ├─ objects/<aa>/<sha256> # 纯对象仓库(不关心文件关系)
190
+ ├─ workspaces/<runtimeId>/<workId>/manifest.json # 中间层:文件关系/版本/归属
191
+ ├─ catalog/works.json # 供 UI / 生命周期管理读取的作品目录
192
+ ├─ namespaces/<runtimeId>.json # token 哈希 / TTL
193
+ ├─ runtimes/<runtimeId>/ # DSH_HOME、workspace、日志、锁、runtime.json
194
+ └─ registry.json # 端口租约
195
+ ```
196
+
197
+ `objects/` 只负责存字节;`workspaces/` 和 `catalog/` 是中间层,负责“哪些文件属于同一个作品、谁能修改、版本和生命周期”。`catalog/works.json` 是展示索引,采用最终一致性刷新,不作为热路径事务日志。
198
+
199
+ `runtime.driver` 预留 `node`(L1 逻辑隔离)、`jobobject`、`docker`、`wsl`;
200
+ 需要真正的文件/网络强隔离时接 L2/L3 driver。
201
+
202
+ ## 组合规则
203
+
204
+ - `components`:先展开组件 suite 的 C/packages/rows/checks,再合并本 suite;组件行优先。
205
+ - `packages`:同名包版本/role 必须一致;`provides` 合并去重。
206
+ - 能力(capability):`provides.capabilities` 声明“我提供什么”,`requires.capabilities` 声明“我需要什么”;组合时解析 provider,缺失或不兼容会报错。
207
+ - 例如 `dsh-ppt-skills` 只依赖 `ppt.runtime@^2`,不依赖某个具体 workbench 包,因此可以替换实现。
208
+ - `rows`:同 id 同 name/config 自动去重;不同则报冲突(除非 `allowOverride`)。
209
+ - 端口:同一个端口被不同包声明 → 冲突。
210
+ - 工具名:精确重名 → 冲突;多个通配工具面 → 告警。
211
+ - `checks`:同 id 去重;不同则冲突。
212
+
213
+ ## 安装规则
214
+
215
+ - profile 里只把 suite 包作为 `link:` 依赖;子包通过 junction 放进 `node_modules`,不进入 profile 的 `dependencies`。
216
+ - `dsh.profile.bundles` 只列 suite 名;suite patch 负责插入子包的行。
217
+ - 重复安装时按 `dshSuiteKit.managedPackages` 清理旧链接,避免残留。
218
+ - `doctor` 会检查:suite manifest、子包存在性、HTTP 健康、MCP contract major、组合后 row id 重复。
219
+
220
+ ## 从 domain 构建 bundle
221
+
222
+ `scripts/build-bundle.mjs` 直接使用本包的 `resolveDomain` / `stageDomain`:
223
+
224
+ ```bash
225
+ node scripts/build-bundle.mjs \
226
+ --domain A/projects/canvas/domains/canvas \
227
+ --out builds/ppt --target portable
228
+ ```
229
+
230
+ 生成的 bundle 内含 `domain/`(组件 + kit + domain.json)、`setup.mjs` 和启动脚本。
231
+ `setup.mjs` 调用 `installDomain({ runPnpm: false })`,在 bundle 自带的
232
+ `DSH_HOME` 下建立 profile 和组件链接,不依赖 pnpm,也不写用户主目录。
233
+
234
+ ## 设计边界
235
+
236
+ - 这个包是**开发/安装工具**,不是 DSH 运行时插件;不会出现在 agent 工具面里。
237
+ - 组合层不替子包做业务;它只负责“谁和谁一起跑、怎么验证、冲突在哪”。
238
+ - 运行时通信用 Cordis service / MCP / HTTP;suite-kit 不创建跨进程总线。
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * dsh-domain CLI:
4
+ * dsh-domain validate <domain>
5
+ * dsh-domain resolve <domain>
6
+ * dsh-domain registry <domain>
7
+ * dsh-domain doctor --profile name [--dsh-bin path]
8
+ */
9
+ import {
10
+ buildActivationRegistry, doctor, formatReport, loadDomainManifest,
11
+ resolveDomain, validateDomainManifest,
12
+ } from '../src/index.mjs'
13
+
14
+ function parse(argv) {
15
+ const args = []
16
+ const flags = {}
17
+ for (let i = 0; i < argv.length; i++) {
18
+ const item = argv[i]
19
+ if (!item.startsWith('--')) { args.push(item); continue }
20
+ const key = item.slice(2)
21
+ const next = argv[i + 1]
22
+ if (next && !next.startsWith('--')) { flags[key] = next; i++ }
23
+ else flags[key] = true
24
+ }
25
+ return { args, flags }
26
+ }
27
+
28
+ function fail(message) {
29
+ console.error(`✗ ${message}`)
30
+ process.exit(1)
31
+ }
32
+
33
+ function cmdValidate(input) {
34
+ if (!input) fail('用法: dsh-domain validate <domain>')
35
+ const loaded = loadDomainManifest(input)
36
+ const result = validateDomainManifest(loaded.manifest)
37
+ for (const warning of result.warnings) console.log(`! ${warning}`)
38
+ for (const error of result.errors) console.log(`✗ ${error}`)
39
+ console.log(result.ok ? `✓ ${loaded.manifest.name}` : '✗ domain 校验失败')
40
+ process.exit(result.ok ? 0 : 1)
41
+ }
42
+
43
+ function cmdResolve(input) {
44
+ if (!input) fail('用法: dsh-domain resolve <domain>')
45
+ const resolved = resolveDomain(input)
46
+ console.log(JSON.stringify({
47
+ domain: resolved.manifest.name,
48
+ components: resolved.suites.map((suite) => suite.manifest.name),
49
+ capabilities: resolved.composed.capabilities,
50
+ rows: resolved.composed.rows,
51
+ checks: resolved.composed.checks,
52
+ warnings: resolved.composed.warnings,
53
+ }, null, 2))
54
+ }
55
+
56
+ function cmdRegistry(input) {
57
+ if (!input) fail('用法: dsh-domain registry <domain>')
58
+ try {
59
+ const resolved = resolveDomain(input)
60
+ const { registry, warnings } = buildActivationRegistry({
61
+ suites: resolved.suites,
62
+ composed: resolved.composed,
63
+ requiredCapabilities: resolved.manifest.runtime?.requires?.capabilities || [],
64
+ })
65
+ for (const warning of warnings) console.error(`! ${warning}`)
66
+ console.log(JSON.stringify(registry, null, 2))
67
+ } catch (error) {
68
+ fail(error.message)
69
+ }
70
+ }
71
+
72
+ async function cmdDoctor(flags) {
73
+ const report = await doctor({
74
+ profile: flags.profile,
75
+ dshHome: flags['dsh-home'],
76
+ dshBin: flags['dsh-bin'],
77
+ })
78
+ console.log(formatReport(report))
79
+ process.exitCode = report.ok ? 0 : 1
80
+ }
81
+
82
+ const { args, flags } = parse(process.argv.slice(2))
83
+ const [command] = args
84
+ if (!command || command === 'help' || command === '--help') {
85
+ console.log(`dsh-domain — 领域包校验器
86
+
87
+ validate <domain> 校验 domain manifest
88
+ resolve <domain> 解析组件/能力/row
89
+ registry <domain> 生成 launch-engine 激活注册表(预览)
90
+ doctor --profile name 运行健康检查
91
+ `)
92
+ process.exit(0)
93
+ }
94
+ if (command === 'validate') cmdValidate(args[1])
95
+ else if (command === 'resolve') cmdResolve(args[1])
96
+ else if (command === 'registry') cmdRegistry(args[1])
97
+ else if (command === 'doctor') await cmdDoctor(flags)
98
+ else fail(`未知命令: ${command}`)
@@ -0,0 +1,174 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * dsh-suite CLI:
4
+ * dsh-suite validate <suite...>
5
+ * dsh-suite compose <suite...> --out <dir>
6
+ * dsh-suite install <suite...> --profile web [--dsh-home <dir>] [--dry-run] [--no-pnpm]
7
+ * dsh-suite doctor --profile web [--dsh-home <dir>] [--dsh-bin <path>]
8
+ * dsh-suite init <dir> --name <name> [--title <title>]
9
+ */
10
+ import fs from 'node:fs'
11
+ import path from 'node:path'
12
+ import {
13
+ buildActivationRegistry, composeSuites, composeToDir, doctor, formatReport, installSuites,
14
+ loadSuiteManifest, renderCordisPatch, validateSuiteManifest,
15
+ } from '../src/index.mjs'
16
+
17
+ function parse(argv) {
18
+ const args = []
19
+ const flags = {}
20
+ for (let i = 0; i < argv.length; i++) {
21
+ const item = argv[i]
22
+ if (!item.startsWith('--')) { args.push(item); continue }
23
+ const key = item.slice(2)
24
+ const next = argv[i + 1]
25
+ if (next && !next.startsWith('--')) { flags[key] = next; i++ }
26
+ else flags[key] = true
27
+ }
28
+ return { args, flags }
29
+ }
30
+
31
+ function fail(message) {
32
+ console.error(`✗ ${message}`)
33
+ process.exit(1)
34
+ }
35
+
36
+ function printValidation(loaded) {
37
+ const result = validateSuiteManifest(loaded.manifest, { baseDir: loaded.dir })
38
+ console.log(`${result.ok ? '✓' : '✗'} ${loaded.manifest.name || loaded.file}`)
39
+ for (const warning of result.warnings) console.log(` ! ${warning}`)
40
+ for (const error of result.errors) console.log(` ✗ ${error}`)
41
+ return result.ok
42
+ }
43
+
44
+ function cmdValidate(suitePaths) {
45
+ if (!suitePaths.length) fail('用法: dsh-suite validate <suite...>')
46
+ let ok = true
47
+ for (const input of suitePaths) {
48
+ try {
49
+ ok = printValidation(loadSuiteManifest(input)) && ok
50
+ } catch (error) {
51
+ console.log(`✗ ${input}: ${error.message}`)
52
+ ok = false
53
+ }
54
+ }
55
+ process.exit(ok ? 0 : 1)
56
+ }
57
+
58
+ function cmdCompose(suitePaths, flags) {
59
+ if (!suitePaths.length || !flags.out) fail('用法: dsh-suite compose <suite...> --out <dir>')
60
+ const suites = suitePaths.map((input) => loadSuiteManifest(input))
61
+ const result = composeToDir(suites, path.resolve(flags.out))
62
+ for (const warning of result.warnings) console.log(`! ${warning}`)
63
+ for (const error of result.errors) console.log(`✗ ${error}`)
64
+ console.log(result.ok
65
+ ? `✓ 组合 ${suites.length} 个 suite,${result.rows.length} 行 → ${path.resolve(flags.out)}`
66
+ : '✗ 组合存在冲突')
67
+ process.exit(result.ok ? 0 : 1)
68
+ }
69
+
70
+ function cmdInstall(suitePaths, flags) {
71
+ if (!suitePaths.length) fail('用法: dsh-suite install <suite...> --profile <name>')
72
+ try {
73
+ const plan = installSuites({
74
+ suiteInputs: suitePaths,
75
+ profile: flags.profile,
76
+ dshHome: flags['dsh-home'],
77
+ dryRun: !!flags['dry-run'],
78
+ runPnpm: !flags['no-pnpm'],
79
+ packageSpecs: flags.package ? String(flags.package).split(',') : [],
80
+ rollbackTo: flags['rollback-to'],
81
+ artifactRoot: flags['artifact-root'],
82
+ })
83
+ for (const warning of plan.warnings || []) console.log(`! ${warning}`)
84
+ console.log(`✓ ${plan.dryRun ? 'dry-run ' : ''}suite 安装完成`)
85
+ console.log(JSON.stringify(plan, null, 2))
86
+ } catch (error) {
87
+ fail(error.message)
88
+ }
89
+ }
90
+
91
+ function cmdRegistry(suitePaths) {
92
+ if (!suitePaths.length) fail('用法: dsh-suite registry <suite...>')
93
+ const suites = suitePaths.map((input) => loadSuiteManifest(input))
94
+ const composed = composeSuites(suites)
95
+ if (!composed.ok) fail('suite 组合冲突:\n- ' + composed.errors.join('\n- '))
96
+ const { registry, warnings } = buildActivationRegistry({ suites, composed })
97
+ for (const warning of warnings) console.error(`! ${warning}`)
98
+ console.log(JSON.stringify(registry, null, 2))
99
+ }
100
+
101
+ async function cmdDoctor(flags) {
102
+ const report = await doctor({
103
+ profile: flags.profile,
104
+ dshHome: flags['dsh-home'],
105
+ dshBin: flags['dsh-bin'],
106
+ })
107
+ console.log(formatReport(report))
108
+ process.exitCode = report.ok ? 0 : 1
109
+ }
110
+
111
+ function cmdInit(dir, flags) {
112
+ if (!dir || !flags.name) fail('用法: dsh-suite init <dir> --name <name> [--title <title>]')
113
+ const target = path.resolve(dir)
114
+ if (fs.existsSync(target) && fs.readdirSync(target).length) fail(`目录非空: ${target}`)
115
+ fs.mkdirSync(target, { recursive: true })
116
+ const name = flags.name
117
+ const title = flags.title || name
118
+ const manifest = {
119
+ name,
120
+ version: '0.1.0',
121
+ title,
122
+ description: `${title}(DSH 组合套件)`,
123
+ packages: {
124
+ [name]: { role: 'runtime', version: '^0.1.0', path: '.' },
125
+ },
126
+ rows: [{ id: `${name}-host`, name }],
127
+ checks: [],
128
+ }
129
+ const pkg = {
130
+ name,
131
+ version: '0.1.0',
132
+ description: manifest.description,
133
+ type: 'module',
134
+ main: './lib/index.mjs',
135
+ exports: { '.': './lib/index.mjs', './package.json': './package.json' },
136
+ dsh: { bundle: { patch: './cordis.patch.yml' }, suite: './dsh-suite.json' },
137
+ files: ['lib/', 'dsh-suite.json', 'cordis.patch.yml', 'README.md'],
138
+ license: 'MIT',
139
+ private: true,
140
+ }
141
+ fs.writeFileSync(path.join(target, 'dsh-suite.json'), JSON.stringify(manifest, null, 2) + '\n')
142
+ fs.writeFileSync(path.join(target, 'package.json'), JSON.stringify(pkg, null, 2) + '\n')
143
+ fs.writeFileSync(path.join(target, 'cordis.patch.yml'), renderCordisPatch(manifest.rows))
144
+ fs.mkdirSync(path.join(target, 'lib'))
145
+ fs.writeFileSync(path.join(target, 'lib', 'index.mjs'),
146
+ `export const name = ${JSON.stringify(name)}\nexport function apply() {}\n`)
147
+ fs.writeFileSync(path.join(target, 'README.md'),
148
+ `# ${title}\n\n由 @capyclaw/suite-kit 生成的 DSH 组合套件。\n\n` +
149
+ '```bash\ndsh-suite validate .\ndsh-suite install . --profile web\n```\n')
150
+ console.log(`✓ 已生成 ${target}`)
151
+ }
152
+
153
+ const { args, flags } = parse(process.argv.slice(2))
154
+ const [command] = args
155
+ if (!command || command === '--help' || command === 'help') {
156
+ console.log(`dsh-suite — DSH 组合标准件
157
+
158
+ validate <suite...> 校验 manifest
159
+ compose <suite...> --out <dir> 组合并生成 cordis.patch.yml
160
+ registry <suite...> 生成 launch-engine 激活注册表(预览)
161
+ install <suite...> --profile web 安装到 profile
162
+ doctor --profile web 运行健康检查
163
+ init <dir> --name <name> 生成新 suite 模板
164
+ `)
165
+ process.exit(0)
166
+ }
167
+
168
+ if (command === 'validate') cmdValidate(args.slice(1))
169
+ else if (command === 'compose') cmdCompose(args.slice(1), flags)
170
+ else if (command === 'registry') cmdRegistry(args.slice(1))
171
+ else if (command === 'install') cmdInstall(args.slice(1), flags)
172
+ else if (command === 'doctor') await cmdDoctor(flags)
173
+ else if (command === 'init') cmdInit(args[1], flags)
174
+ else fail(`未知命令: ${command}`)
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 嵌入握手客户端(浏览器侧,无构建、无依赖)。镜像 src/embed.mjs 的协议常量。
3
+ * 套件 UI 以 <script src="./embed.js"> 引入;被父窗以 mode=embedded 打开时隐藏 standalone chrome、
4
+ * 报 ready,并经 CapyclawEmbed.sendEvent 把统一事件转发父窗。控制面不分模式(标准 §C.7)。
5
+ */
6
+ (function () {
7
+ var VERSION = 1
8
+ var TYPES = { init: 'capyclaw:embed:init', ready: 'capyclaw:embed:ready', event: 'capyclaw:embed:event' }
9
+ var KINDS = ['progress', 'artifact', 'confirm', 'login', 'result', 'error']
10
+ function isLocalOrigin(o) { return typeof o === 'string' && /^http:\/\/(127\.0\.0\.1|localhost)(:\d+)?$/.test(o) }
11
+ var state = { mode: 'standalone', suite: '', sessionId: null, workId: null, parentOrigin: null, embedPath: location.pathname }
12
+ function post(msg) { if (state.parentOrigin && window.parent !== window) window.parent.postMessage(msg, state.parentOrigin) }
13
+ function sendEvent(event) {
14
+ if (!event || KINDS.indexOf(event.kind) === -1) return false
15
+ post({ type: TYPES.event, protocolVersion: VERSION, event: event })
16
+ return true
17
+ }
18
+ function ready() { post({ type: TYPES.ready, protocolVersion: VERSION, suite: state.suite, embedPath: state.embedPath, workId: state.workId }) }
19
+ window.addEventListener('message', function (ev) {
20
+ var msg = ev.data
21
+ if (!msg || msg.type !== TYPES.init || msg.protocolVersion !== VERSION) return
22
+ if (!isLocalOrigin(ev.origin)) return // 只信本地同源,拒外部注入
23
+ if (!msg.sessionId) return
24
+ state.mode = 'embedded'; state.sessionId = msg.sessionId; state.workId = msg.workId || null; state.parentOrigin = ev.origin
25
+ document.body.classList.add('capyclaw-embedded')
26
+ document.dispatchEvent(new CustomEvent('capyclaw:embed:mode', { detail: Object.assign({}, state) }))
27
+ ready()
28
+ })
29
+ window.CapyclawEmbed = {
30
+ get state() { return Object.assign({}, state) },
31
+ setSuite: function (s) { state.suite = s },
32
+ sendEvent: sendEvent,
33
+ isEmbedded: function () { return state.mode === 'embedded' },
34
+ }
35
+ })()
@@ -0,0 +1,129 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://dsh.local/schemas/domain.schema.json",
4
+ "title": "DSH Domain Pack Manifest",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["name", "version", "components"],
8
+ "properties": {
9
+ "$schema": { "type": "string" },
10
+ "name": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
11
+ "version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?$" },
12
+ "title": { "type": "string" },
13
+ "description": { "type": "string" },
14
+ "baseBundles": { "type": "array", "items": { "type": "string" } },
15
+ "components": { "type": "array", "minItems": 1, "items": { "type": "string" } },
16
+ "profile": {
17
+ "type": "object",
18
+ "additionalProperties": true,
19
+ "properties": {
20
+ "name": { "type": "string" },
21
+ "port": { "type": "integer" }
22
+ }
23
+ },
24
+ "runtime": {
25
+ "type": "object",
26
+ "additionalProperties": true,
27
+ "properties": {
28
+ "driver": { "type": "string", "enum": ["node", "jobobject", "docker", "wsl"] },
29
+ "workId": { "type": "string" },
30
+ "ttlSec": { "type": "integer", "minimum": 0 },
31
+ "env": { "type": "object", "additionalProperties": true },
32
+ "bindings": {
33
+ "type": "array",
34
+ "items": {
35
+ "type": "object",
36
+ "additionalProperties": false,
37
+ "properties": {
38
+ "row": { "type": "string" },
39
+ "package": { "type": "string" },
40
+ "port": { "type": "string" },
41
+ "config": { "type": "object" }
42
+ }
43
+ }
44
+ },
45
+ "urlPort": { "type": "string" },
46
+ "model": {
47
+ "oneOf": [
48
+ { "type": "boolean" },
49
+ {
50
+ "type": "object",
51
+ "additionalProperties": true,
52
+ "properties": {
53
+ "id": { "type": "string" },
54
+ "plugin": { "type": "string" },
55
+ "apiKeyEnv": { "type": "string" },
56
+ "baseUrlEnv": { "type": "string" },
57
+ "baseURL": { "type": "string" }
58
+ }
59
+ }
60
+ ]
61
+ },
62
+ "workspaceController": {
63
+ "oneOf": [
64
+ { "type": "boolean" },
65
+ { "type": "object", "additionalProperties": true }
66
+ ]
67
+ },
68
+ "requires": {
69
+ "type": "object",
70
+ "additionalProperties": true,
71
+ "properties": {
72
+ "tools": { "type": "array", "items": { "type": "string" } },
73
+ "services": { "type": "array", "items": { "type": "string" } },
74
+ "capabilities": { "type": "array", "items": { "type": "string" } }
75
+ }
76
+ },
77
+ "scope": {
78
+ "type": "object",
79
+ "additionalProperties": true,
80
+ "properties": {
81
+ "sessions": { "type": "object" },
82
+ "files": {
83
+ "type": "array",
84
+ "items": {
85
+ "type": "object",
86
+ "required": ["path"],
87
+ "properties": {
88
+ "id": { "type": "string" },
89
+ "kind": { "type": "string" },
90
+ "path": { "type": "string" },
91
+ "patterns": { "type": "array", "items": { "type": "string" } }
92
+ }
93
+ }
94
+ },
95
+ "workspace": { "type": "object" },
96
+ "network": { "type": "object" },
97
+ "processes": { "type": "object" }
98
+ }
99
+ },
100
+ "ports": {
101
+ "type": "object",
102
+ "additionalProperties": true,
103
+ "properties": {
104
+ "harness": { "oneOf": [{ "type": "integer" }, { "type": "object" }] },
105
+ "dsh": { "oneOf": [{ "type": "integer" }, { "type": "object" }] },
106
+ "content": { "oneOf": [{ "type": "integer" }, { "type": "object" }] },
107
+ "services": {
108
+ "type": "object",
109
+ "additionalProperties": { "oneOf": [{ "type": "integer" }, { "type": "object" }] }
110
+ }
111
+ }
112
+ }
113
+ }
114
+ },
115
+ "removeRows": { "type": "array", "items": { "type": "string" } },
116
+ "removeDependencies": { "type": "array", "items": { "type": "string" } },
117
+ "rowOverrides": {
118
+ "type": "object",
119
+ "additionalProperties": {
120
+ "type": "object",
121
+ "additionalProperties": false,
122
+ "properties": {
123
+ "config": { "type": "object" },
124
+ "disabled": { "type": "boolean" }
125
+ }
126
+ }
127
+ }
128
+ }
129
+ }