@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.
- package/README.md +28 -2
- package/contract/capabilities.json +178 -0
- package/lib/descriptors.mjs +33 -0
- package/lib/host.mjs +102 -0
- package/lib/session-port.mjs +104 -0
- package/lib/tools.mjs +166 -0
- package/lib/workbench.mjs +133 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +345 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +255 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +82 -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 +55 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +68 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +113 -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 +34 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +160 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +87 -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 +188 -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 +69 -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 +129 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +139 -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/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 +143 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -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 +41 -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 +656 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -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 +571 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/suite-kit/README.md +238 -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 +54 -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/index.mjs +10 -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 +112 -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 +16 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +142 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +390 -0
- package/package.json +68 -4
- package/plugin.mjs +1 -0
- package/ui/app.js +114 -0
- package/ui/index.html +64 -0
- package/ui/style.css +54 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 多 suite 组合:合并 packages / rows / checks,检测冲突并生成 patch。
|
|
3
|
+
*/
|
|
4
|
+
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { join, resolve } from 'node:path'
|
|
6
|
+
import { isValidRange, majorOf, validateSuiteManifest, versionSatisfies } from './manifest.mjs'
|
|
7
|
+
|
|
8
|
+
function stable(value) {
|
|
9
|
+
if (Array.isArray(value)) return `[${value.map(stable).join(',')}]`
|
|
10
|
+
if (value && typeof value === 'object') {
|
|
11
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stable(value[key])}`).join(',')}}`
|
|
12
|
+
}
|
|
13
|
+
return JSON.stringify(value)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const deepEqual = (a, b) => stable(a) === stable(b)
|
|
17
|
+
|
|
18
|
+
function unique(list) {
|
|
19
|
+
return [...new Set(list)]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function mergeProvides(target, source) {
|
|
23
|
+
for (const key of ['tools', 'skills', 'services', 'ports']) {
|
|
24
|
+
if (!source?.[key]) continue
|
|
25
|
+
target[key] = unique([...(target[key] || []), ...source[key]])
|
|
26
|
+
}
|
|
27
|
+
if (source?.capabilities) {
|
|
28
|
+
target.capabilities = { ...(target.capabilities || {}), ...source.capabilities }
|
|
29
|
+
}
|
|
30
|
+
return target
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {{file:string,dir:string,manifest:object}[]} suites
|
|
35
|
+
* @param {{allowOverride?:boolean}} [options]
|
|
36
|
+
*/
|
|
37
|
+
export function composeSuites(suites, options = {}) {
|
|
38
|
+
const errors = []
|
|
39
|
+
const warnings = []
|
|
40
|
+
const packages = new Map()
|
|
41
|
+
const rows = new Map()
|
|
42
|
+
const checks = new Map()
|
|
43
|
+
const ports = new Map()
|
|
44
|
+
const tools = new Map()
|
|
45
|
+
const capabilities = new Map()
|
|
46
|
+
|
|
47
|
+
for (const suite of suites) {
|
|
48
|
+
const { manifest, dir, file } = suite
|
|
49
|
+
const validation = validateSuiteManifest(manifest)
|
|
50
|
+
warnings.push(...validation.warnings.map((w) => `${manifest.name}: ${w}`))
|
|
51
|
+
if (!validation.ok) {
|
|
52
|
+
errors.push(...validation.errors.map((e) => `${manifest.name}: ${e}`))
|
|
53
|
+
continue
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
for (const [name, entry] of Object.entries(manifest.packages)) {
|
|
57
|
+
const current = packages.get(name)
|
|
58
|
+
if (!current) {
|
|
59
|
+
packages.set(name, { name, entry: { ...entry }, suite: manifest.name, dir, file })
|
|
60
|
+
} else {
|
|
61
|
+
if (current.entry.version !== entry.version) {
|
|
62
|
+
errors.push(`包 ${name} 版本冲突: ${current.suite}=${current.entry.version} vs ${manifest.name}=${entry.version}`)
|
|
63
|
+
}
|
|
64
|
+
if (current.entry.role !== entry.role) {
|
|
65
|
+
errors.push(`包 ${name} role 冲突: ${current.suite}=${current.entry.role} vs ${manifest.name}=${entry.role}`)
|
|
66
|
+
}
|
|
67
|
+
if (current.entry.path && entry.path) {
|
|
68
|
+
const currentPath = resolve(current.dir, current.entry.path)
|
|
69
|
+
const nextPath = resolve(dir, entry.path)
|
|
70
|
+
if (currentPath !== nextPath) {
|
|
71
|
+
errors.push(`包 ${name} 路径冲突: ${current.suite}=${currentPath} vs ${manifest.name}=${nextPath}`)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const [dep, range] of Object.entries(entry.requires || {})) {
|
|
75
|
+
if (current.entry.requires?.[dep] && current.entry.requires[dep] !== range) {
|
|
76
|
+
errors.push(`包 ${name} 对 ${dep} 的 requires 冲突`)
|
|
77
|
+
}
|
|
78
|
+
current.entry.requires = { ...(current.entry.requires || {}), [dep]: range }
|
|
79
|
+
}
|
|
80
|
+
mergeProvides(current.entry.provides ||= {}, entry.provides)
|
|
81
|
+
}
|
|
82
|
+
for (const port of entry.provides?.ports || []) {
|
|
83
|
+
const owner = ports.get(port)
|
|
84
|
+
if (owner && owner !== name) errors.push(`端口 ${port} 冲突: ${owner} vs ${name}`)
|
|
85
|
+
else ports.set(port, name)
|
|
86
|
+
}
|
|
87
|
+
for (const tool of entry.provides?.tools || []) {
|
|
88
|
+
const owner = tools.get(tool)
|
|
89
|
+
if (owner && owner !== name) errors.push(`工具名 ${tool} 冲突: ${owner} vs ${name}`)
|
|
90
|
+
else tools.set(tool, name)
|
|
91
|
+
}
|
|
92
|
+
for (const [cap, version] of Object.entries(entry.provides?.capabilities || {})) {
|
|
93
|
+
const owner = capabilities.get(cap)
|
|
94
|
+
if (owner && !majorCompatible(owner.version, version)) {
|
|
95
|
+
errors.push(`能力 ${cap} 版本冲突: ${owner.package}=${owner.version} vs ${name}=${version}`)
|
|
96
|
+
} else if (!owner) {
|
|
97
|
+
capabilities.set(cap, { package: name, version })
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (const row of manifest.rows) {
|
|
103
|
+
const current = rows.get(row.id)
|
|
104
|
+
if (!current) {
|
|
105
|
+
rows.set(row.id, { row: { ...row }, suite: manifest.name })
|
|
106
|
+
continue
|
|
107
|
+
}
|
|
108
|
+
const same = current.row.name === row.name
|
|
109
|
+
&& current.row.disabled === row.disabled
|
|
110
|
+
&& deepEqual(current.row.config, row.config)
|
|
111
|
+
if (same) continue
|
|
112
|
+
if (options.allowOverride) {
|
|
113
|
+
warnings.push(`row ${row.id} 被 ${manifest.name} 覆盖(原 ${current.suite})`)
|
|
114
|
+
rows.set(row.id, { row: { ...row }, suite: manifest.name })
|
|
115
|
+
} else {
|
|
116
|
+
errors.push(`row ${row.id} 冲突: ${current.suite} 与 ${manifest.name} 定义了不同的 name/config`)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
for (const check of manifest.checks || []) {
|
|
121
|
+
const current = checks.get(check.id)
|
|
122
|
+
if (!current) checks.set(check.id, { check: { ...check }, suite: manifest.name })
|
|
123
|
+
else if (deepEqual(current.check, check)) continue
|
|
124
|
+
else errors.push(`check ${check.id} 冲突: ${current.suite} vs ${manifest.name}`)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/* requires 必须能在组合里解析,或由调用方声明 external。 */
|
|
129
|
+
for (const { name, entry, suite } of packages.values()) {
|
|
130
|
+
for (const dep of Object.keys(entry.requires || {})) {
|
|
131
|
+
if (dep === 'capabilities') {
|
|
132
|
+
for (const [cap, range] of Object.entries(entry.requires.capabilities)) {
|
|
133
|
+
const provider = capabilities.get(cap)
|
|
134
|
+
if (!provider) {
|
|
135
|
+
errors.push(`${suite}: 包 ${name} 需要能力 ${cap}@${range},但组合里没有提供者`)
|
|
136
|
+
} else if (!majorCompatible(provider.version, range)) {
|
|
137
|
+
errors.push(`${suite}: 包 ${name} 需要能力 ${cap}@${range},提供者 ${provider.package}@${provider.version} 不兼容`)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} else if (!packages.has(dep)) {
|
|
141
|
+
warnings.push(`${suite}: 包 ${name} 依赖 ${dep},但组合里没有声明该包(按外部已安装处理)`)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* 不同包的 wildcard 工具面重叠只告警,精确重名已经报错。 */
|
|
147
|
+
const wildcardOwners = [...packages.values()]
|
|
148
|
+
.filter(({ entry }) => (entry.provides?.tools || []).some((tool) => tool.includes('*')))
|
|
149
|
+
.map(({ name }) => name)
|
|
150
|
+
if (wildcardOwners.length > 1) {
|
|
151
|
+
warnings.push(`多个包声明通配工具面: ${wildcardOwners.join(', ')}(请确认 MCP serverName 不冲突)`)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
ok: errors.length === 0,
|
|
156
|
+
errors,
|
|
157
|
+
warnings,
|
|
158
|
+
packages: [...packages.values()].sort((a, b) => a.name.localeCompare(b.name)),
|
|
159
|
+
rows: [...rows.values()].map(({ row, suite }) => ({ ...row, _suite: suite })),
|
|
160
|
+
checks: [...checks.values()].map(({ check, suite }) => ({ ...check, _suite: suite })),
|
|
161
|
+
capabilities: [...capabilities.entries()].map(([capability, info]) => ({ capability, ...info })),
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** 生成 cordis.patch.yml(YAML;config 用 JSON 内联,避免 YAML 引号坑)。 */
|
|
166
|
+
export function renderCordisPatch(rows, { header = true } = {}) {
|
|
167
|
+
const lines = []
|
|
168
|
+
if (header) {
|
|
169
|
+
lines.push('# 由 @capyclaw/suite-kit 生成;改 dsh-suite.json 后重跑 compose。', '')
|
|
170
|
+
}
|
|
171
|
+
lines.push('- insert:')
|
|
172
|
+
for (const row of rows) {
|
|
173
|
+
lines.push(` - id: ${row.id}`)
|
|
174
|
+
lines.push(` name: ${JSON.stringify(row.name)}`)
|
|
175
|
+
if (row.disabled !== undefined) lines.push(` disabled: ${row.disabled ? 'true' : 'false'}`)
|
|
176
|
+
if (row.config !== undefined) lines.push(` config: ${JSON.stringify(row.config)}`)
|
|
177
|
+
}
|
|
178
|
+
return lines.join('\n') + '\n'
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function composeToDir(suites, outDir) {
|
|
182
|
+
const result = composeSuites(suites)
|
|
183
|
+
mkdirSync(outDir, { recursive: true })
|
|
184
|
+
if (result.ok) writeFileSync(join(outDir, 'cordis.patch.yml'), renderCordisPatch(result.rows))
|
|
185
|
+
writeFileSync(join(outDir, 'suite-compose.json'), JSON.stringify(result, null, 2) + '\n')
|
|
186
|
+
return result
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** 版本范围兼容:优先用精确版本对 range 求解,无法判断时退回 major 比较。 */
|
|
190
|
+
export function majorCompatible(left, right) {
|
|
191
|
+
const a = String(left || '').trim()
|
|
192
|
+
const b = String(right || '').trim()
|
|
193
|
+
if (a === '*' || b === '*' || a === 'latest' || b === 'latest') return true
|
|
194
|
+
if (!isValidRange(a) || !isValidRange(b)) return false
|
|
195
|
+
const exact = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/
|
|
196
|
+
if (exact.test(a) && !exact.test(b)) return versionSatisfies(b, a)
|
|
197
|
+
if (exact.test(b) && !exact.test(a)) return versionSatisfies(a, b)
|
|
198
|
+
const majorA = majorOf(a)
|
|
199
|
+
const majorB = majorOf(b)
|
|
200
|
+
return majorA != null && majorB != null && majorA === majorB
|
|
201
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain Pack:面向“某个工作领域”的组合入口。
|
|
3
|
+
*
|
|
4
|
+
* component = 一个可独立安装的 suite(内部可以再包含 plugin / skills / MCP)
|
|
5
|
+
* domain = 选择哪些 component 一起启动,以及 base profile / 端口 / 检查
|
|
6
|
+
*
|
|
7
|
+
* 启动时只为该 domain 生成 profile:base + web-app + 选中的 suite;
|
|
8
|
+
* 未选中的插件、skill、MCP 不会进入该 profile。
|
|
9
|
+
*/
|
|
10
|
+
import fs from 'node:fs'
|
|
11
|
+
import path from 'node:path'
|
|
12
|
+
import { composeSuites } from './compose.mjs'
|
|
13
|
+
import { loadSuiteManifest } from './manifest.mjs'
|
|
14
|
+
|
|
15
|
+
const NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
16
|
+
const VERSION_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/
|
|
17
|
+
export const DOMAIN_FILENAMES = ['dsh-domain.json', 'domain.json']
|
|
18
|
+
|
|
19
|
+
export function findDomainManifest(input) {
|
|
20
|
+
const abs = path.resolve(input)
|
|
21
|
+
if (!fs.existsSync(abs)) throw new Error(`domain 路径不存在: ${abs}`)
|
|
22
|
+
if (fs.statSync(abs).isFile()) return abs
|
|
23
|
+
for (const name of DOMAIN_FILENAMES) {
|
|
24
|
+
const file = path.join(abs, name)
|
|
25
|
+
if (fs.existsSync(file)) return file
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`目录里没有 ${DOMAIN_FILENAMES.join(' / ')}: ${abs}`)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function loadDomainManifest(input) {
|
|
31
|
+
const file = findDomainManifest(input)
|
|
32
|
+
return { file, dir: path.dirname(file), manifest: JSON.parse(fs.readFileSync(file, 'utf8')) }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function validateDomainManifest(manifest) {
|
|
36
|
+
const errors = []
|
|
37
|
+
const warnings = []
|
|
38
|
+
if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) {
|
|
39
|
+
return { ok: false, errors: ['domain manifest 必须是 object'], warnings }
|
|
40
|
+
}
|
|
41
|
+
if (!NAME_RE.test(manifest.name || '')) errors.push('name 必须是 kebab-case')
|
|
42
|
+
if (!VERSION_RE.test(manifest.version || '')) errors.push('version 必须是 semver')
|
|
43
|
+
if (!Array.isArray(manifest.components) || manifest.components.length === 0) {
|
|
44
|
+
errors.push('components 必须是非空数组')
|
|
45
|
+
} else for (const component of manifest.components) {
|
|
46
|
+
if (typeof component !== 'string' || !component) errors.push('components 必须是路径字符串数组')
|
|
47
|
+
}
|
|
48
|
+
if (manifest.baseBundles != null && (!Array.isArray(manifest.baseBundles) || manifest.baseBundles.some((v) => typeof v !== 'string'))) {
|
|
49
|
+
errors.push('baseBundles 必须是 string[]')
|
|
50
|
+
}
|
|
51
|
+
if (manifest.profile != null && (typeof manifest.profile !== 'object' || Array.isArray(manifest.profile))) {
|
|
52
|
+
errors.push('profile 必须是 object')
|
|
53
|
+
}
|
|
54
|
+
if (manifest.runtime != null) {
|
|
55
|
+
if (typeof manifest.runtime !== 'object' || Array.isArray(manifest.runtime)) {
|
|
56
|
+
errors.push('runtime 必须是 object')
|
|
57
|
+
} else {
|
|
58
|
+
if (manifest.runtime.driver != null && !['node', 'jobobject', 'docker', 'wsl'].includes(manifest.runtime.driver)) {
|
|
59
|
+
errors.push(`runtime.driver 非法: ${manifest.runtime.driver}`)
|
|
60
|
+
}
|
|
61
|
+
for (const key of ['requires', 'scope']) {
|
|
62
|
+
if (manifest.runtime[key] != null && (typeof manifest.runtime[key] !== 'object' || Array.isArray(manifest.runtime[key]))) {
|
|
63
|
+
errors.push(`runtime.${key} 必须是 object`)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (manifest.runtime.bindings != null) {
|
|
67
|
+
if (!Array.isArray(manifest.runtime.bindings)) errors.push('runtime.bindings 必须是数组')
|
|
68
|
+
else for (const [index, binding] of manifest.runtime.bindings.entries()) {
|
|
69
|
+
if (!binding || typeof binding !== 'object' || (!binding.row && !binding.package)) {
|
|
70
|
+
errors.push(`runtime.bindings[${index}] 必须包含 row 或 package`)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const key of ['tools', 'services', 'capabilities']) {
|
|
75
|
+
const list = manifest.runtime.requires?.[key]
|
|
76
|
+
if (list != null && (!Array.isArray(list) || list.some((item) => typeof item !== 'string'))) {
|
|
77
|
+
errors.push(`runtime.requires.${key} 必须是 string[]`)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const scope = manifest.runtime.scope
|
|
81
|
+
if (scope != null) {
|
|
82
|
+
if (scope.sessions != null && (typeof scope.sessions !== 'object' || Array.isArray(scope.sessions))) {
|
|
83
|
+
errors.push('runtime.scope.sessions 必须是 object')
|
|
84
|
+
}
|
|
85
|
+
if (scope.files != null) {
|
|
86
|
+
if (!Array.isArray(scope.files)) errors.push('runtime.scope.files 必须是数组')
|
|
87
|
+
else for (const [index, entry] of scope.files.entries()) {
|
|
88
|
+
if (!entry || typeof entry !== 'object' || typeof entry.path !== 'string' || !entry.path) {
|
|
89
|
+
errors.push(`runtime.scope.files[${index}].path 必须是非空字符串`)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const key of ['removeRows', 'removeDependencies']) {
|
|
97
|
+
if (manifest[key] != null && (!Array.isArray(manifest[key]) || manifest[key].some((v) => typeof v !== 'string'))) {
|
|
98
|
+
errors.push(`${key} 必须是 string[]`)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (manifest.rowOverrides != null) {
|
|
102
|
+
if (typeof manifest.rowOverrides !== 'object' || Array.isArray(manifest.rowOverrides)) {
|
|
103
|
+
errors.push('rowOverrides 必须是 object')
|
|
104
|
+
} else for (const [id, override] of Object.entries(manifest.rowOverrides)) {
|
|
105
|
+
if (!override || typeof override !== 'object' || Array.isArray(override)) {
|
|
106
|
+
errors.push(`rowOverrides.${id} 必须是 object`)
|
|
107
|
+
} else if (override.config != null && (typeof override.config !== 'object' || Array.isArray(override.config))) {
|
|
108
|
+
errors.push(`rowOverrides.${id}.config 必须是 object`)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { ok: errors.length === 0, errors, warnings }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 解析 domain → suites → 组合结果。 */
|
|
116
|
+
export function resolveDomain(input) {
|
|
117
|
+
const loaded = loadDomainManifest(input)
|
|
118
|
+
const validation = validateDomainManifest(loaded.manifest)
|
|
119
|
+
if (!validation.ok) throw new Error(`domain 校验失败:\n- ${validation.errors.join('\n- ')}`)
|
|
120
|
+
const suites = loaded.manifest.components.map((component) => {
|
|
121
|
+
const target = path.isAbsolute(component) ? component : path.resolve(loaded.dir, component)
|
|
122
|
+
return loadSuiteManifest(target)
|
|
123
|
+
})
|
|
124
|
+
const composed = composeSuites(suites)
|
|
125
|
+
if (!composed.ok) throw new Error(`domain 组合冲突:\n- ${composed.errors.join('\n- ')}`)
|
|
126
|
+
const overrides = loaded.manifest.rowOverrides || {}
|
|
127
|
+
const rows = composed.rows.map((row) => {
|
|
128
|
+
const override = overrides[row.id]
|
|
129
|
+
if (!override) return row
|
|
130
|
+
return {
|
|
131
|
+
...row,
|
|
132
|
+
...override,
|
|
133
|
+
config: override.config !== undefined ? override.config : row.config,
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
return { ...loaded, suites, composed: { ...composed, rows } }
|
|
137
|
+
}
|
|
138
|
+
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 嵌入握手协议(docs/suite-interop-standard.md §C.7 双模呈现)。
|
|
3
|
+
*
|
|
4
|
+
* 双模能力:套件既能独立运行(完整 app),也能作为浏览器壳内的子窗口被高层 AI 编排。
|
|
5
|
+
* 关键拆分:控制面不分模式——高层 AI 始终走同一套能力描述符/工具(ppt_export_pptx 同一接口);
|
|
6
|
+
* 模式只是呈现层状态。本模块只定义呈现层的握手与事件转发,不承载控制指令。
|
|
7
|
+
*
|
|
8
|
+
* 子窗口是同源本地地址(workbench 挂 /capyclaw/<ns>),iframe 自有套件不受 X-Frame-Options 限制
|
|
9
|
+
* (那只挡外站)。握手:父窗开子窗传 mode=embedded + sessionId/workId;子窗隐藏 standalone chrome、
|
|
10
|
+
* 报 ready、经 bridge 把产物/确认闸事件转发父窗。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const EMBED_PROTOCOL_VERSION = 1
|
|
14
|
+
export const EMBED_MESSAGE_TYPES = Object.freeze({
|
|
15
|
+
init: 'capyclaw:embed:init',
|
|
16
|
+
ready: 'capyclaw:embed:ready',
|
|
17
|
+
event: 'capyclaw:embed:event',
|
|
18
|
+
})
|
|
19
|
+
export const EMBED_EVENT_KINDS = Object.freeze(['progress', 'artifact', 'confirm', 'login', 'result', 'error'])
|
|
20
|
+
|
|
21
|
+
/** 只信本地同源(127.0.0.1 / localhost),拒绝任意外部 origin 注入握手。 */
|
|
22
|
+
export function isLocalOrigin(origin) {
|
|
23
|
+
return typeof origin === 'string' && /^http:\/\/(127\.0\.0\.1|localhost)(:\d+)?$/.test(origin)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 父 → 子:打开子窗口时下发嵌入上下文。 */
|
|
27
|
+
export function makeInitMessage({ sessionId, workId = null, parentOrigin, embedPath = null } = {}) {
|
|
28
|
+
if (typeof sessionId !== 'string' || !sessionId) throw new Error('makeInitMessage: sessionId 必填')
|
|
29
|
+
if (!isLocalOrigin(parentOrigin)) throw new Error('makeInitMessage: parentOrigin 必须是本地同源(127.0.0.1/localhost)')
|
|
30
|
+
return Object.freeze({
|
|
31
|
+
type: EMBED_MESSAGE_TYPES.init, protocolVersion: EMBED_PROTOCOL_VERSION,
|
|
32
|
+
mode: 'embedded', sessionId, workId, parentOrigin, embedPath,
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 子 → 父:子窗就绪(已隐藏 standalone chrome,可被编排)。 */
|
|
37
|
+
export function makeReadyMessage({ suite, embedPath, workId = null } = {}) {
|
|
38
|
+
if (typeof suite !== 'string' || !suite) throw new Error('makeReadyMessage: suite 必填')
|
|
39
|
+
if (typeof embedPath !== 'string' || !embedPath.startsWith('/')) throw new Error('makeReadyMessage: embedPath 必须以 / 开头')
|
|
40
|
+
return Object.freeze({
|
|
41
|
+
type: EMBED_MESSAGE_TYPES.ready, protocolVersion: EMBED_PROTOCOL_VERSION,
|
|
42
|
+
suite, embedPath, workId,
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 子 → 父:把统一事件(产物/确认闸/登录/进度)转发给父窗会话视图。 */
|
|
47
|
+
export function makeEventMessage({ event } = {}) {
|
|
48
|
+
if (!event || !EMBED_EVENT_KINDS.includes(event.kind)) {
|
|
49
|
+
throw new Error(`makeEventMessage: event.kind 必须是 ${EMBED_EVENT_KINDS.join('|')}`)
|
|
50
|
+
}
|
|
51
|
+
return Object.freeze({ type: EMBED_MESSAGE_TYPES.event, protocolVersion: EMBED_PROTOCOL_VERSION, event: Object.freeze({ ...event }) })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 校验一条握手消息。direction: 'to-child'(只收 init)| 'to-parent'(只收 ready/event)。
|
|
56
|
+
* 返回 {ok, errors};调用方还须自行核对 event.origin === 可信本地 origin(isLocalOrigin)。
|
|
57
|
+
*/
|
|
58
|
+
export function validateEmbedMessage(msg, { direction } = {}) {
|
|
59
|
+
const errors = []
|
|
60
|
+
if (!msg || typeof msg !== 'object') return { ok: false, errors: ['消息不是对象'] }
|
|
61
|
+
if (msg.protocolVersion !== EMBED_PROTOCOL_VERSION) errors.push(`protocolVersion 必须是 ${EMBED_PROTOCOL_VERSION}`)
|
|
62
|
+
const allowed = direction === 'to-child'
|
|
63
|
+
? [EMBED_MESSAGE_TYPES.init]
|
|
64
|
+
: direction === 'to-parent'
|
|
65
|
+
? [EMBED_MESSAGE_TYPES.ready, EMBED_MESSAGE_TYPES.event]
|
|
66
|
+
: null
|
|
67
|
+
if (!allowed) errors.push(`direction 必须是 to-child|to-parent,收到: ${direction}`)
|
|
68
|
+
else if (!allowed.includes(msg.type)) errors.push(`${direction} 方向不接受消息类型 ${msg.type}`)
|
|
69
|
+
if (msg.type === EMBED_MESSAGE_TYPES.init) {
|
|
70
|
+
if (!msg.sessionId) errors.push('init 缺 sessionId')
|
|
71
|
+
if (!isLocalOrigin(msg.parentOrigin)) errors.push('init.parentOrigin 非本地同源')
|
|
72
|
+
}
|
|
73
|
+
if (msg.type === EMBED_MESSAGE_TYPES.ready) {
|
|
74
|
+
if (!msg.suite) errors.push('ready 缺 suite')
|
|
75
|
+
if (typeof msg.embedPath !== 'string' || !msg.embedPath.startsWith('/')) errors.push('ready.embedPath 必须以 / 开头')
|
|
76
|
+
}
|
|
77
|
+
if (msg.type === EMBED_MESSAGE_TYPES.event) {
|
|
78
|
+
if (!msg.event || !EMBED_EVENT_KINDS.includes(msg.event.kind)) errors.push('event.kind 非法')
|
|
79
|
+
}
|
|
80
|
+
return { ok: errors.length === 0, errors }
|
|
81
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './manifest.mjs'
|
|
2
|
+
export * from './capability.mjs'
|
|
3
|
+
export * from './orchestration.mjs'
|
|
4
|
+
export * from './embed.mjs'
|
|
5
|
+
export * from './surface.mjs'
|
|
6
|
+
export * from './compose.mjs'
|
|
7
|
+
export * from './profile.mjs'
|
|
8
|
+
export * from './domain.mjs'
|
|
9
|
+
export * from './artifacts.mjs'
|
|
10
|
+
export * from './activation-registry.mjs'
|