@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,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
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@capyclaw/suite-kit",
3
+ "version": "0.2.3",
4
+ "description": "DSH suite/domain 标准件(双重身份:构建期库 + 运行时库,暂不拆包,见 README「双重身份」)。构建期:manifest 校验、compose、profile 生成、domain 解析、artifact 打包;运行时:统一能力描述符、编排闸/授权、嵌入握手与 surface 挂载。",
5
+ "type": "module",
6
+ "main": "./src/index.mjs",
7
+ "exports": {
8
+ ".": "./src/index.mjs",
9
+ "./domain": "./src/domain.mjs",
10
+ "./compose": "./src/compose.mjs",
11
+ "./manifest": "./src/manifest.mjs",
12
+ "./capability": "./src/capability.mjs",
13
+ "./orchestration": "./src/orchestration.mjs",
14
+ "./embed": "./src/embed.mjs",
15
+ "./surface": "./src/surface.mjs",
16
+ "./host": "./src/host.mjs",
17
+ "./client/embed.js": "./client/embed.js",
18
+ "./profile": "./src/profile.mjs",
19
+ "./artifacts": "./src/artifacts.mjs",
20
+ "./schema": "./suite.schema.json",
21
+ "./package.json": "./package.json",
22
+ "./domain-schema": "./domain.schema.json"
23
+ },
24
+ "bin": {
25
+ "dsh-suite": "./bin/dsh-suite.mjs",
26
+ "dsh-domain": "./bin/dsh-domain.mjs"
27
+ },
28
+ "scripts": {
29
+ "test": "node --test test/*.test.mjs"
30
+ },
31
+ "files": [
32
+ "README.md",
33
+ "bin/",
34
+ "client/",
35
+ "domain.schema.json",
36
+ "src/",
37
+ "suite.schema.json"
38
+ ],
39
+ "engines": {
40
+ "node": ">=18"
41
+ },
42
+ "dependencies": {
43
+ "@capyclaw/plugin-kit": "^0.2.9"
44
+ },
45
+ "license": "MIT",
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/Maple496/capyclaw.git",
52
+ "directory": "C/packages/capyclaw-suite-kit"
53
+ },
54
+ "bugs": {
55
+ "url": "https://github.com/Maple496/capyclaw/issues"
56
+ },
57
+ "homepage": "https://github.com/Maple496/capyclaw/tree/main/C/packages/capyclaw-suite-kit#readme"
58
+ }
@@ -0,0 +1,184 @@
1
+ /**
2
+ * 从 suite 组合结果编译 launch-engine 的 capability 注册表。
3
+ *
4
+ * 「实现一个功能要注册哪些组件」的唯一事实来源是 dsh-suite.json;
5
+ * 这里把它编译成运行期激活面(@capyclaw/launch-engine)直接消费的注册表,
6
+ * 不再手写第二种「要求 → 组件」映射。映射规则:
7
+ *
8
+ * - 每个包 = 一个激活 capability(name = 包名),条件是它有 row、拥有服务进程、
9
+ * 或是组合内其他包 required capability 的提供方(纯 support 依赖不单独成能力)
10
+ * entries = 该包的 rows(entryId = include:<rowId>)
11
+ * requires = 包 requires.capabilities 解析到的提供方包(组合内)
12
+ * services = 套件 services.json 里 cmd 指向该包 node_modules/<pkg>/ 的条目
13
+ * - 每个套件 = 一个聚合 capability(name = 套件名;bundle 级开关)
14
+ * bundles = [{ name: 套件名 }](installSuites 把套件名写进 dsh.profile.bundles)
15
+ * requires = 该套件下所有已注册的包 capability
16
+ * entries/services = 无法归属到具体包的行与服务
17
+ *
18
+ * services 编译时展开 ${PACKAGE_DIR}(注册表落在 profile 目录,不能依赖
19
+ * broker 清单装载期的展开基准),剥掉 portFrom/dirFrom(那是 runtime
20
+ * 物化期的分配提示,不是激活语义);${PORT} 原样留给 broker 仲裁。
21
+ */
22
+ import fs from 'node:fs'
23
+ import path from 'node:path'
24
+
25
+ export const ACTIVATION_REGISTRY_FILENAME = 'launch-engine.registry.json'
26
+ const ENTRY_PREFIX = 'include:'
27
+
28
+ function readSuiteServices(suiteDir) {
29
+ const file = path.join(suiteDir, 'services.json')
30
+ if (!fs.existsSync(file)) return []
31
+ try {
32
+ const raw = JSON.parse(fs.readFileSync(file, 'utf8'))
33
+ return Array.isArray(raw?.services) ? raw.services : []
34
+ } catch {
35
+ return []
36
+ }
37
+ }
38
+
39
+ function serviceOwnerPackage(service, packageNames) {
40
+ const cmd = Array.isArray(service?.cmd) ? service.cmd.join(' ') : ''
41
+ for (const name of packageNames) {
42
+ const needle = `node_modules/${name}/`
43
+ if (cmd.includes(needle)) return name
44
+ }
45
+ return null
46
+ }
47
+
48
+ /** 展开 services.json 的 ${PACKAGE_DIR}。两种规格:
49
+ * - 新代:cmd 形如 ${PACKAGE_DIR}/node_modules/<pkg>/…——${PACKAGE_DIR} 指
50
+ * 持有 node_modules 的套件根(services.json 所在目录),不是 owner 包自身目录;
51
+ * - 旧代:cmd 形如 ${PACKAGE_DIR}/server/relay.mjs——${PACKAGE_DIR} 指 owner 包目录。 */
52
+ function toActivationService(service, { packageDir, suiteDir }) {
53
+ const joined = (service.cmd || []).join(' ')
54
+ const base = joined.includes('node_modules/') ? suiteDir : packageDir
55
+ const cmd = (service.cmd || []).map((part) => String(part).replaceAll('${PACKAGE_DIR}', base))
56
+ const next = { ...service, cmd }
57
+ delete next.portFrom
58
+ delete next.dirFrom
59
+ return next
60
+ }
61
+
62
+ function packageDirOf(pkg) {
63
+ if (!pkg?.dir || !pkg?.entry?.path) return null
64
+ return path.resolve(pkg.dir, pkg.entry.path).replace(/\\/g, '/')
65
+ }
66
+
67
+ /**
68
+ * @param {{suites: {dir:string, manifest:object}[], composed: object, requiredCapabilities?: string[]}} input
69
+ * suites 已加载(components 已展开)的套件;composed = composeSuites 输出
70
+ * requiredCapabilities 额外的能力名(如 domain runtime.requires.capabilities),
71
+ * 其提供方也应进入注册表
72
+ * @returns {{registry: {version:1, capabilities:object}, warnings: string[]}}
73
+ */
74
+ export function buildActivationRegistry({ suites, composed, requiredCapabilities = [] }) {
75
+ const warnings = []
76
+ const capabilities = {}
77
+ const packages = composed?.packages || []
78
+ const packageNames = packages.map((pkg) => pkg.name)
79
+ const capProvider = new Map((composed?.capabilities || []).map((item) => [item.capability, item.package]))
80
+
81
+ /* 组合内被别人 required 的能力的提供方:即使没有 row(纯服务进程形态,
82
+ * 如 capyclaw-ppt-workbench)也必须成为 capability,否则依赖图断链。 */
83
+ const demandedProviders = new Set()
84
+ for (const pkg of packages) {
85
+ for (const capability of Object.keys(pkg.entry.requires?.capabilities || {})) {
86
+ const provider = capProvider.get(capability)
87
+ if (provider) demandedProviders.add(provider)
88
+ }
89
+ }
90
+ for (const capability of requiredCapabilities) {
91
+ const provider = capProvider.get(String(capability).split('@')[0])
92
+ if (provider) demandedProviders.add(provider)
93
+ }
94
+
95
+ const rowsByPackage = new Map()
96
+ const orphanRowsBySuite = new Map()
97
+ for (const row of composed?.rows || []) {
98
+ if (row.disabled) continue
99
+ if (packageNames.includes(row.name)) {
100
+ rowsByPackage.set(row.name, [...(rowsByPackage.get(row.name) || []), row])
101
+ } else {
102
+ const suite = row._suite || ''
103
+ orphanRowsBySuite.set(suite, [...(orphanRowsBySuite.get(suite) || []), row])
104
+ }
105
+ }
106
+
107
+ const packageServices = new Map()
108
+ for (const suite of suites || []) {
109
+ for (const service of readSuiteServices(suite.dir)) {
110
+ const owner = serviceOwnerPackage(service, packageNames)
111
+ if (owner) packageServices.set(owner, [...(packageServices.get(owner) || []), { service, suiteDir: (suite.dir || '').replace(/\\/g, '/') }])
112
+ }
113
+ }
114
+
115
+ for (const pkg of packages) {
116
+ const rows = rowsByPackage.get(pkg.name) || []
117
+ const services = packageServices.get(pkg.name) || []
118
+ if (!rows.length && !services.length && !demandedProviders.has(pkg.name)) continue
119
+ const requires = []
120
+ for (const capability of Object.keys(pkg.entry.requires?.capabilities || {})) {
121
+ const provider = capProvider.get(capability)
122
+ if (!provider || provider === pkg.name || requires.includes(provider)) continue
123
+ if (!packageNames.includes(provider)) continue
124
+ requires.push(provider)
125
+ }
126
+ capabilities[pkg.name] = {
127
+ name: pkg.name,
128
+ title: pkg.name,
129
+ requires,
130
+ bundles: [],
131
+ entries: rows.map((row) => ({ entryId: ENTRY_PREFIX + row.id, enabled: true })),
132
+ services: services.map(({ service, suiteDir }) => toActivationService(service, {
133
+ packageDir: packageDirOf(pkg) || suiteDir,
134
+ suiteDir,
135
+ })),
136
+ }
137
+ }
138
+
139
+ for (const suite of suites || []) {
140
+ const name = suite.manifest.name
141
+ const dir = (suite.dir || '').replace(/\\/g, '/')
142
+ if (capabilities[name]) {
143
+ warnings.push(`capability 名冲突: 套件 ${name} 与已有包能力重名,聚合能力改用 suite:<name>`)
144
+ }
145
+ const aggregateName = capabilities[name] ? `suite:${name}` : name
146
+ const unmatched = []
147
+
148
+ for (const service of readSuiteServices(suite.dir)) {
149
+ const owner = serviceOwnerPackage(service, packageNames)
150
+ /* 已在包能力里挂载的服务不重复;只有无主或主人未成能力的才归套件聚合。 */
151
+ if (owner && capabilities[owner]) continue
152
+ unmatched.push(toActivationService(service, { packageDir: dir, suiteDir: dir }))
153
+ }
154
+
155
+ const requires = []
156
+ for (const pkg of packages) {
157
+ if (pkg.suite !== name) continue
158
+ if (capabilities[pkg.name] && !requires.includes(pkg.name)) requires.push(pkg.name)
159
+ }
160
+ const orphanRows = orphanRowsBySuite.get(name) || []
161
+ if (orphanRows.length) {
162
+ warnings.push(`${name}: 行 [${orphanRows.map((row) => row.id).join(', ')}] 引用的包不在组合里(外部已安装),归入套件聚合能力`)
163
+ }
164
+
165
+ capabilities[aggregateName] = {
166
+ name: aggregateName,
167
+ title: suite.manifest.title || name,
168
+ requires,
169
+ bundles: [{ name, enabled: true }],
170
+ entries: orphanRows.map((row) => ({ entryId: ENTRY_PREFIX + row.id, enabled: true })),
171
+ services: unmatched,
172
+ }
173
+ }
174
+
175
+ return { registry: { version: 1, capabilities }, warnings }
176
+ }
177
+
178
+ /** 安装期落盘:<profile>/launch-engine.registry.json。 */
179
+ export function writeActivationRegistry(profileDir, { suites, composed }) {
180
+ const { registry, warnings } = buildActivationRegistry({ suites, composed })
181
+ const file = path.join(profileDir, ACTIVATION_REGISTRY_FILENAME)
182
+ fs.writeFileSync(file, JSON.stringify(registry, null, 2) + '\n')
183
+ return { file, registry, warnings, capabilities: Object.keys(registry.capabilities) }
184
+ }
@@ -0,0 +1,131 @@
1
+ /**
2
+ * 公共插件版本化 artifact store。
3
+ *
4
+ * 目录:
5
+ * <root>/index.json
6
+ * <root>/<safeName>/<version>/package/...
7
+ *
8
+ * 版本化安装:installSuites({ packageSpecs: ['@capyclaw/asset-service@0.1.3'] })
9
+ * 回滚:installSuites({ rollbackTo: '<profile>/dsh-composition.lock.json.bak-...' })
10
+ */
11
+ import crypto from 'node:crypto'
12
+ import fs from 'node:fs'
13
+ import os from 'node:os'
14
+ import path from 'node:path'
15
+
16
+ export function defaultArtifactRoot() {
17
+ return process.env.DSH_ARTIFACT_STORE || path.join(os.homedir(), '.dsh-store', 'artifacts')
18
+ }
19
+
20
+ function safeName(name) {
21
+ return String(name).replace(/[@/\\]/g, '__')
22
+ }
23
+
24
+ function readJsonSafe(file) {
25
+ try { return JSON.parse(fs.readFileSync(file, 'utf8')) } catch { return null }
26
+ }
27
+
28
+ function walk(dir, base = dir) {
29
+ const out = []
30
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
31
+ const full = path.join(dir, entry.name)
32
+ if (entry.isDirectory()) out.push(...walk(full, base))
33
+ else out.push(path.relative(base, full).split('\\').join('/'))
34
+ }
35
+ return out.sort()
36
+ }
37
+
38
+ function treeHash(dir) {
39
+ const hash = crypto.createHash('sha256')
40
+ for (const rel of walk(dir)) {
41
+ hash.update(rel)
42
+ hash.update(fs.readFileSync(path.join(dir, rel)))
43
+ }
44
+ return hash.digest('hex')
45
+ }
46
+
47
+ function copyPackageDir(src, dest) {
48
+ fs.mkdirSync(dest, { recursive: true })
49
+ for (const rel of walk(src)) {
50
+ if (rel === 'node_modules' || rel.startsWith('node_modules/')) continue
51
+ if (rel === '.git' || rel.startsWith('.git/')) continue
52
+ if (rel === 'test' || rel.startsWith('test/')) continue
53
+ if (rel === 'coverage' || rel.startsWith('coverage/')) continue
54
+ const to = path.join(dest, rel)
55
+ fs.mkdirSync(path.dirname(to), { recursive: true })
56
+ fs.copyFileSync(path.join(src, rel), to)
57
+ }
58
+ }
59
+
60
+ export function artifactIndexPath(root = defaultArtifactRoot()) {
61
+ return path.join(root, 'index.json')
62
+ }
63
+
64
+ export function readArtifactIndex(root = defaultArtifactRoot()) {
65
+ return readJsonSafe(artifactIndexPath(root)) || { version: 1, packages: {} }
66
+ }
67
+
68
+ function writeArtifactIndex(root, index) {
69
+ fs.mkdirSync(root, { recursive: true })
70
+ fs.writeFileSync(artifactIndexPath(root), JSON.stringify(index, null, 2) + '\n')
71
+ }
72
+
73
+ /**
74
+ * 打包一个包目录到 artifact store。
75
+ * @param {string} packageDir
76
+ * @param {{ root?: string, force?: boolean }} options
77
+ */
78
+ export function packPackage(packageDir, { root = defaultArtifactRoot(), force = false } = {}) {
79
+ const manifest = readJsonSafe(path.join(packageDir, 'package.json'))
80
+ if (!manifest?.name || !manifest?.version) throw new Error(`artifact pack: ${packageDir} 缺少 package.json name/version`)
81
+ const dest = path.join(root, safeName(manifest.name), manifest.version, 'package')
82
+ if (fs.existsSync(dest) && !force) throw new Error(`artifact 已存在: ${manifest.name}@${manifest.version}(加 --force 覆盖)`)
83
+ fs.rmSync(dest, { recursive: true, force: true })
84
+ copyPackageDir(packageDir, dest)
85
+ const meta = {
86
+ name: manifest.name,
87
+ version: manifest.version,
88
+ apiVersion: manifest.dsh?.apiVersion || null,
89
+ dependencies: manifest.dependencies || {},
90
+ dir: dest,
91
+ sha256: treeHash(dest),
92
+ packedAt: new Date().toISOString(),
93
+ }
94
+ const index = readArtifactIndex(root)
95
+ index.packages[manifest.name] ||= {}
96
+ index.packages[manifest.name][manifest.version] = meta
97
+ writeArtifactIndex(root, index)
98
+ return meta
99
+ }
100
+
101
+ /**
102
+ * @param {string} spec name 或 name@version
103
+ * @param {{ root?: string }} options
104
+ */
105
+ export function resolvePackageSpec(spec, { root = defaultArtifactRoot() } = {}) {
106
+ if (!spec || typeof spec !== 'string') throw new Error('artifact resolve: spec 必填')
107
+ const at = spec.lastIndexOf('@')
108
+ const name = at > 0 ? spec.slice(0, at) : spec
109
+ const version = at > 0 ? spec.slice(at + 1) : ''
110
+ const index = readArtifactIndex(root)
111
+ const versions = index.packages[name]
112
+ if (!versions) throw new Error(`artifact 不存在: ${name}(root=${root})`)
113
+ if (version) {
114
+ const hit = versions[version]
115
+ if (!hit) throw new Error(`artifact 版本不存在: ${spec};可用: ${Object.keys(versions).sort().join(', ')}`)
116
+ return hit
117
+ }
118
+ const latest = Object.keys(versions).sort((a, b) => a.localeCompare(b, undefined, { numeric: true })).at(-1)
119
+ return versions[latest]
120
+ }
121
+
122
+ export function listArtifacts({ root = defaultArtifactRoot() } = {}) {
123
+ const index = readArtifactIndex(root)
124
+ return Object.entries(index.packages).flatMap(([name, versions]) =>
125
+ Object.values(versions).map((meta) => ({ name, version: meta.version, apiVersion: meta.apiVersion, sha256: meta.sha256, dir: meta.dir })))
126
+ }
127
+
128
+ export function recordFromLock(lock, { root = defaultArtifactRoot() } = {}) {
129
+ if (!lock?.packages) throw new Error('artifact recordFromLock: lock 缺 packages')
130
+ return Object.entries(lock.packages).map(([name, meta]) => resolvePackageSpec(`${name}@${meta.version}`, { root }))
131
+ }