@capyclaw/ppt-suite 2.5.70 → 2.5.71
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/composition.lock.json +27 -27
- package/contract/ppt-contract.json +1 -1
- package/dsh-suite.json +27 -17
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/asset-service/package.json +1 -1
- package/node_modules/@capyclaw/asset-service/src/index.mjs +4 -3
- package/node_modules/@capyclaw/document-workbench/package.json +6 -3
- package/node_modules/@capyclaw/document-workbench/src/client/index.mjs +56 -3
- package/node_modules/@capyclaw/document-workbench/src/client/visibility.mjs +112 -0
- package/node_modules/@capyclaw/document-workbench/src/model/manifest.mjs +6 -4
- package/node_modules/@capyclaw/document-workbench/src/model/ops.mjs +7 -2
- package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +8 -0
- package/node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs +17 -10
- package/node_modules/@capyclaw/document-workbench/src/store/projection.mjs +39 -0
- package/node_modules/@capyclaw/document-workbench/src/testing/index.mjs +14 -11
- package/node_modules/@capyclaw/editor-host/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/editor-host/package.json +1 -1
- package/node_modules/@capyclaw/editor-host/src/index.mjs +12 -21
- package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +3 -1
- package/node_modules/@capyclaw/foundation/abi/index.mjs +15 -0
- package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +21 -4
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +5 -1
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +5 -2
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +4 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +13 -3
- package/node_modules/@capyclaw/foundation/package.json +1 -1
- package/node_modules/@capyclaw/plugin-kit/package.json +3 -1
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +5 -2
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +13 -5
- package/node_modules/@capyclaw/portal/package.json +1 -1
- package/node_modules/@capyclaw/ppt-editor/app.js +458 -10
- package/node_modules/@capyclaw/ppt-editor/contract/ppt-contract.json +1 -1
- package/node_modules/@capyclaw/ppt-editor/heartbeat-worker.js +5 -2
- package/node_modules/@capyclaw/ppt-editor/index.html +4 -0
- package/node_modules/@capyclaw/ppt-editor/package.json +2 -2
- package/node_modules/@capyclaw/ppt-skill-api/contract/ppt-contract.json +1 -1
- package/node_modules/@capyclaw/ppt-skill-api/package.json +1 -1
- package/node_modules/@capyclaw/ppt-skill-api/skills/pptist-api/references/tool-contract.md +1 -1
- package/node_modules/@capyclaw/ppt-skill-proposal/contract/ppt-contract.json +1 -1
- package/node_modules/@capyclaw/ppt-skill-proposal/package.json +1 -1
- package/node_modules/@capyclaw/ppt-workbench/contract/ppt-contract.json +1 -1
- package/node_modules/@capyclaw/ppt-workbench/core/deck-layout.js +3 -1
- package/node_modules/@capyclaw/ppt-workbench/core/ops/slide.js +9 -3
- package/node_modules/@capyclaw/ppt-workbench/core/text.js +14 -2
- package/node_modules/@capyclaw/ppt-workbench/package.json +10 -8
- package/node_modules/@capyclaw/ppt-workbench/plugin.mjs +13 -1
- package/node_modules/@capyclaw/ppt-workbench/server/contract.mjs +1 -1
- package/node_modules/@capyclaw/ppt-workbench/server/embedded-host.mjs +200 -29
- package/node_modules/@capyclaw/ppt-workbench/server/relay.mjs +10 -7
- package/node_modules/@capyclaw/ppt-workbench/server/shared/SHARED_MANIFEST.json +4 -4
- package/node_modules/@capyclaw/ppt-workbench/server/store/backends/file-backend.mjs +3 -0
- package/node_modules/@capyclaw/ppt-workbench/server/store/checkpoints.mjs +4 -1
- package/node_modules/@capyclaw/ppt-workbench/server/store/index.mjs +4 -0
- package/node_modules/@capyclaw/ppt-workbench/server/store/sessions.mjs +139 -4
- package/node_modules/@capyclaw/ppt-workbench/server/store/shape.mjs +37 -0
- package/node_modules/@capyclaw/service-broker/README.md +1 -1
- package/node_modules/@capyclaw/service-broker/lib/host.mjs +11 -6
- package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +13 -5
- package/node_modules/@capyclaw/service-broker/package.json +1 -1
- package/node_modules/@capyclaw/service-host/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/service-host/package.json +1 -1
- package/node_modules/@capyclaw/service-host/src/index.mjs +13 -22
- package/node_modules/@capyclaw/skills-service/README.md +42 -10
- package/node_modules/@capyclaw/skills-service/package.json +6 -3
- package/node_modules/@capyclaw/skills-service/server.mjs +129 -51
- 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 +230 -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/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +15 -4
- package/node_modules/@capyclaw/tool-host/package.json +1 -1
- package/node_modules/@capyclaw/tool-host/src/index.mjs +19 -5
- package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +71 -3
- package/node_modules/@capyclaw/work-store/README.md +83 -0
- package/node_modules/@capyclaw/work-store/STANDARD.md +263 -0
- package/node_modules/@capyclaw/work-store/cordis.patch.yml +3 -0
- package/node_modules/@capyclaw/work-store/dsh-suite.json +33 -0
- package/node_modules/@capyclaw/work-store/icon.svg +7 -0
- package/node_modules/@capyclaw/work-store/lib/host.mjs +21 -0
- package/node_modules/@capyclaw/work-store/package.json +68 -0
- package/node_modules/@capyclaw/work-store/src/backend.mjs +90 -0
- package/node_modules/@capyclaw/work-store/src/db.mjs +199 -0
- package/node_modules/@capyclaw/work-store/src/envelope.mjs +132 -0
- package/node_modules/@capyclaw/work-store/src/index.mjs +571 -0
- package/node_modules/@capyclaw/work-store/src/interop.mjs +70 -0
- package/node_modules/@capyclaw/work-store/src/refs.mjs +99 -0
- package/node_modules/@capyclaw/work-store/src/routes.mjs +135 -0
- package/package.json +16 -14
|
@@ -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,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 套件宿主脚手架(P1-9「新套件宿主胶水抽共享」):capyclaw/conductor/rsp 三个
|
|
3
|
+
* 「新套件」宿主 lib/host.mjs 的公共胶水收敛到这里,未来新套件按同一 spec 接入。
|
|
4
|
+
*
|
|
5
|
+
* 封装的公共胶水(与三宿主原实现行为等价):
|
|
6
|
+
* 1. safeGet 服务懒解析(ctx.reflect.get 优先,回退 ctx[name],异常→null);
|
|
7
|
+
* 2. toolHost/serviceHost 缺席 bail+warn(降级不崩宿主)+ assertServiceApi major 断言;
|
|
8
|
+
* 3. 路由冲突先 probe 占位再 listen(2026-11-19 崩溃教训:前缀路由全局唯一,
|
|
9
|
+
* service-host app.listen 是 async,冲突变 rejected Promise 逃出 try/catch,
|
|
10
|
+
* 被 cordis 当 load failure 杀掉整个宿主);listen rejection 再 .catch 兜底;
|
|
11
|
+
* 4. 原生工具面 registerWithDsh(safeGet 解析 tools 服务后传平对象);
|
|
12
|
+
* 5. 能力描述符 publish/unpublish(validateCapabilityDescriptor 深度校验);
|
|
13
|
+
* 6. `${mountPath}/__host__` 自检端点(hostInfo 钩子补各套件差异字段);
|
|
14
|
+
* 7. portal.recordActivity(portal 可选);
|
|
15
|
+
* 8. disposers 逆序释放(每个 try/catch,重复释放安全);
|
|
16
|
+
* 9. DIAG 日志 env 门控(CAPYCLAW_WB_DIAG=1 才写 os.tmpdir()/<ns>-diag.log,默认不写盘)。
|
|
17
|
+
*
|
|
18
|
+
* 宿主差异经 spec 钩子注入(prepare/afterListen/afterTools/routes/hostInfo),
|
|
19
|
+
* 钩子拿到的 push() 把 disposer 压入公共栈,释放顺序与手写时代一致。
|
|
20
|
+
*
|
|
21
|
+
* 依赖方向:运行时模块。内部仅 import ./capability.mjs;外部仅
|
|
22
|
+
* @capyclaw/plugin-kit/service/api(纯契约断言,无副作用)。不 import 构建期模块。
|
|
23
|
+
*/
|
|
24
|
+
import fs from 'node:fs'
|
|
25
|
+
import os from 'node:os'
|
|
26
|
+
import path from 'node:path'
|
|
27
|
+
import { assertServiceApi } from '@capyclaw/plugin-kit/service/api'
|
|
28
|
+
import { validateCapabilityDescriptor } from './capability.mjs'
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 服务懒解析:cordis 未 inject 的服务直接访问 ctx[name] 可能抛错,
|
|
32
|
+
* 统一走 reflect.get(权威)→ ctx[name](兜底)→ null(缺席降级)。
|
|
33
|
+
* @param {object} ctx cordis 上下文
|
|
34
|
+
* @param {string} serviceName 服务名
|
|
35
|
+
* @returns {object|null}
|
|
36
|
+
*/
|
|
37
|
+
export function safeGet(ctx, serviceName) {
|
|
38
|
+
try { return ctx.reflect?.get?.(serviceName) ?? ctx[serviceName] } catch { return null }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* workStore 可选解析:优先 foundation 的 os.works 能力面(内核 getter 返回
|
|
43
|
+
* work-store 服务或 null),回退 safeGet(ctx,'workStore')。两者皆缺席返回 null,
|
|
44
|
+
* 消费者自行降级内存态(语义与旧 safeGet 裸摸一致)。
|
|
45
|
+
* @param {object} ctx cordis 上下文
|
|
46
|
+
* @returns {object|null}
|
|
47
|
+
*/
|
|
48
|
+
export function resolveWorkStore(ctx) {
|
|
49
|
+
try {
|
|
50
|
+
const osSvc = safeGet(ctx, 'os')
|
|
51
|
+
const works = osSvc ? osSvc.works : null
|
|
52
|
+
if (works) return works
|
|
53
|
+
} catch { /* os.works getter 异常 → 落回裸摸兜底 */ }
|
|
54
|
+
return safeGet(ctx, 'workStore') ?? null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @typedef {object} SuiteHostSpec
|
|
59
|
+
* @property {string} ns 宿主名(如 'conductor-workbench'):__host__.name / portal id /
|
|
60
|
+
* 日志与警告前缀 / diag 文件名 `<ns>-diag.log`。
|
|
61
|
+
* @property {string} suite 套件短名(如 'conductor'):缺服务 bail 警告里的 `<suite>-suite`。
|
|
62
|
+
* @property {string} mountPath 默认挂载前缀(config.mountPath 可覆盖)。
|
|
63
|
+
* @property {string} title portal.recordActivity 标题。
|
|
64
|
+
* @property {Array<{name:string}>} descriptors 本套件描述符清单(释放时逐个 unregister)。
|
|
65
|
+
* @property {(api:HostApi & {extra:object}) => object} createWorkbench 工厂:返回
|
|
66
|
+
* { app, registry, publishDescriptors(baseUrl,{validate}), ... }(各套件 workbench.mjs)。
|
|
67
|
+
* @property {(api:HostApi) => object|false} [prepare] 断言后、建 workbench 前的差异装配
|
|
68
|
+
* (capyclaw 的 sessionPort/session-watch、conductor 的 discoverCapabilities 闸 + workStore)。
|
|
69
|
+
* 返回 false(或 {bail:true})= 放弃挂载(钩子内已自行 warn/diag),返回对象 = extra。
|
|
70
|
+
* @property {(api:HostApi & {workbench:object, extra:object, webServer:object|null}) => void} [afterListen]
|
|
71
|
+
* listen 之后、工具注册之前的钩子(rsp:manager.close disposer + bindToolsToSessionMode)。
|
|
72
|
+
* @property {(api:HostApi & {workbench:object, extra:object, webServer:object|null}) => void} [afterTools]
|
|
73
|
+
* 工具注册之后、描述符发布之前的钩子(rsp:startPersistent)。
|
|
74
|
+
* @property {(args:{webServer:object, workbench:object, extra:object, push:(d:Function)=>void, log:object}) => void} [routes]
|
|
75
|
+
* __host__ 之后的额外固定端点(capyclaw 的 agent-pending/host-pending)。仅 webServer.register 可用时调用。
|
|
76
|
+
* @property {(workbench:object, extra:object) => object} [hostInfo] __host__ 响应附加字段
|
|
77
|
+
* (请求时求值;capyclaw: available、conductor: persisted、rsp: protocol/status)。
|
|
78
|
+
* @property {boolean} [descriptorsRequired] true = 无条件 publish(conductor 已在 prepare
|
|
79
|
+
* 里因缺 discoverCapabilities bail,描述符面必然在场);缺省 = 探测
|
|
80
|
+
* registerCapabilityDescriptor,缺席 warn 跳过(capyclaw/rsp 降级语义)。
|
|
81
|
+
* @property {string} [diagTag] diag 消息短标签(缺省 ns 去掉 '-workbench' 后缀)。
|
|
82
|
+
* @property {(toolHost:object|null) => string} [diagApplyExtra] apply diag 行附加段
|
|
83
|
+
* (conductor 的 ` discover=...`)。
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 钩子公共参数面。
|
|
88
|
+
* @typedef {object} HostApi
|
|
89
|
+
* @property {object} ctx cordis 上下文
|
|
90
|
+
* @property {object} config 插件配置(mountPath/port/version/...)
|
|
91
|
+
* @property {string} mountPath 生效挂载前缀(config.mountPath || spec.mountPath)
|
|
92
|
+
* @property {object} toolHost 已断言 major 1 的工具宿主服务
|
|
93
|
+
* @property {object} serviceHost 已断言 major 1 的服务宿主服务
|
|
94
|
+
* @property {(ctx:object, name:string) => object|null} safeGet 服务懒解析
|
|
95
|
+
* @property {{info:Function, warn:Function}} log ctx.logger 优先、console 兜底
|
|
96
|
+
* @property {(m:string) => void} diag env 门控诊断日志(默认不写盘)
|
|
97
|
+
* @property {(d:Function) => void} push 压入公共 disposer 栈(逆序释放)
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 挂载一个套件工作台:返回 disposer(与 cordis apply 契约一致)。
|
|
102
|
+
* 任何失败都降级为 warn + 安全 disposer,绝不把路由冲突/服务缺席升级成宿主崩溃。
|
|
103
|
+
* @param {object} ctx cordis 上下文
|
|
104
|
+
* @param {object} [config] 插件配置
|
|
105
|
+
* @param {SuiteHostSpec} spec 套件差异规格
|
|
106
|
+
* @returns {() => void} disposer(逆序释放全部已登记资源;重复调用安全)
|
|
107
|
+
*/
|
|
108
|
+
export function mountSuiteWorkbench(ctx, config = {}, spec) {
|
|
109
|
+
const { ns, suite, title, descriptors = [], createWorkbench } = spec
|
|
110
|
+
const tag = spec.diagTag || String(ns || '').replace(/-workbench$/, '')
|
|
111
|
+
/* 诊断日志默认关闭;设 CAPYCLAW_WB_DIAG=1 时写到系统临时目录(不硬编码任何本机路径)。 */
|
|
112
|
+
const DIAG_LOG = process.env.CAPYCLAW_WB_DIAG ? path.join(os.tmpdir(), `${ns}-diag.log`) : null
|
|
113
|
+
const diag = (m) => { if (!DIAG_LOG) return; try { fs.appendFileSync(DIAG_LOG, `[${new Date().toISOString()}] ${m}\n`) } catch { /* 忽略 */ } }
|
|
114
|
+
const log = {
|
|
115
|
+
info: (...a) => (ctx.logger?.info ? ctx.logger.info(...a) : console.log(`[${tag}]`, ...a)),
|
|
116
|
+
warn: (...a) => (ctx.logger?.warn ? ctx.logger.warn(...a) : console.warn(`[${tag}]`, ...a)),
|
|
117
|
+
}
|
|
118
|
+
const mountPath = config.mountPath || spec.mountPath
|
|
119
|
+
const disposers = []
|
|
120
|
+
const push = (d) => { if (typeof d === 'function') disposers.push(d) }
|
|
121
|
+
// splice(0) 清空栈再逆序:首次释放顺序与手写时代一致,重复释放是真 no-op
|
|
122
|
+
// (原 disposers.reverse() 原地反转,二次调用会重跑——与「忽略重复释放」注释意图相悖)。
|
|
123
|
+
const releaseAll = () => { for (const d of disposers.splice(0).reverse()) { try { d() } catch { /* 忽略重复释放 */ } } }
|
|
124
|
+
const noop = () => {}
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
if (!ns || !suite || !mountPath || !title || typeof createWorkbench !== 'function') {
|
|
128
|
+
throw new Error('mountSuiteWorkbench: spec 需要 ns/suite/mountPath/title/createWorkbench')
|
|
129
|
+
}
|
|
130
|
+
const toolHost = safeGet(ctx, 'toolHost')
|
|
131
|
+
const serviceHost = safeGet(ctx, 'serviceHost')
|
|
132
|
+
diag(`${tag} apply: toolHost=${!!toolHost} serviceHost=${!!serviceHost} webServer=${!!safeGet(ctx, 'webServer')} reflect=${!!ctx.reflect}${spec.diagApplyExtra ? spec.diagApplyExtra(toolHost) : ''}`)
|
|
133
|
+
if (!toolHost || !serviceHost) {
|
|
134
|
+
diag(`${tag} BAIL: missing toolHost/serviceHost`)
|
|
135
|
+
log.warn(`缺少 toolHost/serviceHost 公共服务,${suite}-suite 未激活(请安装对应基础套件)`)
|
|
136
|
+
return noop
|
|
137
|
+
}
|
|
138
|
+
assertServiceApi(toolHost, { name: 'toolHost', major: 1 })
|
|
139
|
+
assertServiceApi(serviceHost, { name: 'serviceHost', major: 1 })
|
|
140
|
+
|
|
141
|
+
/** @type {HostApi} */
|
|
142
|
+
const api = { ctx, config, mountPath, toolHost, serviceHost, safeGet, log, diag, push }
|
|
143
|
+
let extra = {}
|
|
144
|
+
if (spec.prepare) {
|
|
145
|
+
const prepared = spec.prepare(api)
|
|
146
|
+
if (prepared === false || (prepared && prepared.bail === true)) return noop
|
|
147
|
+
if (prepared && typeof prepared === 'object') extra = prepared
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const workbench = createWorkbench({ ...api, extra })
|
|
151
|
+
|
|
152
|
+
const webServer = safeGet(ctx, 'webServer')
|
|
153
|
+
|
|
154
|
+
// 前缀路由是全局唯一的(dsh-host-webserver 的 register 遇到同 (kind,path) 直接抛)。
|
|
155
|
+
// service-host 的 app.listen 是 async:冲突会变成 rejected Promise,而不是同步抛错。
|
|
156
|
+
// 不 await、也不 .catch 的话,冲突逃出外层 try/catch,被 cordis 当成 load failure
|
|
157
|
+
// 杀掉整个宿主(2026-11-19 两次:安全模式回滚把用户 patch 层清空)。
|
|
158
|
+
// 先探一次占位,冲突就只警告并退出本条目,绝不把路由冲突升级成宿主崩溃。
|
|
159
|
+
if (webServer && typeof webServer.register === 'function') {
|
|
160
|
+
let taken = false
|
|
161
|
+
try {
|
|
162
|
+
const probe = webServer.register({ kind: 'prefix', path: mountPath, handler: () => {} })
|
|
163
|
+
if (typeof probe === 'function') probe()
|
|
164
|
+
} catch {
|
|
165
|
+
taken = true
|
|
166
|
+
}
|
|
167
|
+
if (taken) {
|
|
168
|
+
diag(`${tag} BAIL: prefix ${mountPath} already registered`)
|
|
169
|
+
log.warn(`${ns}: 路由前缀 ${mountPath} 已被占用,本条目不挂载(不影响其它插件)`)
|
|
170
|
+
return noop
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const listenOpts = webServer ? { webServer, basePath: mountPath } : { port: config.port || 0 }
|
|
175
|
+
const listening = workbench.app.listen(listenOpts)
|
|
176
|
+
// 兜底:即使上面的探测有竞态,也把 rejection 收在这里,不让它变成未处理拒绝。
|
|
177
|
+
if (listening && typeof listening.catch === 'function') {
|
|
178
|
+
listening.catch((err) => {
|
|
179
|
+
diag(`${tag} listen rejected: ${err?.stack || err}`)
|
|
180
|
+
log.warn(`${ns}: 挂载 ${mountPath} 失败,本条目不生效:`, err?.message || err)
|
|
181
|
+
try { workbench.app.close() } catch { /* 忽略 */ }
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
push(() => workbench.app.close())
|
|
185
|
+
|
|
186
|
+
if (spec.afterListen) spec.afterListen({ ...api, workbench, extra, webServer })
|
|
187
|
+
|
|
188
|
+
// 原生工具面:safeGet 解析 tools 服务后传平对象,避免 cordis 未 inject 禁访问 ctx.tools。
|
|
189
|
+
const tools = safeGet(ctx, 'tools')
|
|
190
|
+
if (tools?.register) {
|
|
191
|
+
const { registerWithDsh } = toolHost
|
|
192
|
+
push(registerWithDsh({ tools }, workbench.registry))
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (spec.afterTools) spec.afterTools({ ...api, workbench, extra, webServer })
|
|
196
|
+
|
|
197
|
+
// 能力描述符 + 调用地址 → 公共注册表(供 conductor 发现)。
|
|
198
|
+
if (spec.descriptorsRequired || typeof toolHost.registerCapabilityDescriptor === 'function') {
|
|
199
|
+
workbench.publishDescriptors(workbench.app.url, { validate: validateCapabilityDescriptor })
|
|
200
|
+
push(() => { for (const d of descriptors) toolHost.unregisterCapabilityDescriptor?.(d.name) })
|
|
201
|
+
} else {
|
|
202
|
+
log.warn(`toolHost 无描述符面(需 >=0.2.0):跳过能力注册,conductor 将无法发现 ${suite}`)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 自检端点。
|
|
206
|
+
if (webServer?.register) {
|
|
207
|
+
const off = webServer.register({
|
|
208
|
+
kind: 'exact', path: `${mountPath}/__host__`,
|
|
209
|
+
handler: (req, res) => {
|
|
210
|
+
res.writeHead(200, { 'content-type': 'application/json' })
|
|
211
|
+
res.end(JSON.stringify({ ok: true, name: ns, mountPath, url: workbench.app.url, ...(spec.hostInfo ? spec.hostInfo(workbench, extra) : {}) }))
|
|
212
|
+
},
|
|
213
|
+
})
|
|
214
|
+
push(off)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (spec.routes && webServer?.register) spec.routes({ webServer, workbench, extra, push, log })
|
|
218
|
+
|
|
219
|
+
const portal = safeGet(ctx, 'portal')
|
|
220
|
+
portal?.recordActivity?.({ id: ns, url: workbench.app.url, title, kind: 'service' })
|
|
221
|
+
|
|
222
|
+
log.info(`${ns} 已挂载 ${mountPath} → ${workbench.app.url}`)
|
|
223
|
+
diag(`${tag} MOUNTED ${mountPath} → ${workbench.app.url}`)
|
|
224
|
+
return releaseAll
|
|
225
|
+
} catch (err) {
|
|
226
|
+
diag(`${tag} ERROR: ${err?.stack || err}`)
|
|
227
|
+
log.warn(`${ns} 激活失败:`, err?.stack || err)
|
|
228
|
+
return releaseAll
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @capyclaw/suite-kit 主入口(P2-12:双重身份显式文档化,暂不拆包)。
|
|
2
|
+
// 本包同时是:
|
|
3
|
+
// 构建期库 —— manifest/compose/profile/domain/artifacts/activation-registry
|
|
4
|
+
// (清单校验、组合、profile 安装、领域解析、artifact 打包);
|
|
5
|
+
// 运行时库 —— capability/orchestration/embed/surface/host(能力描述符、编排闸/Mandate/
|
|
6
|
+
// 事件、嵌入握手、surface 挂载、套件宿主脚手架),被 capyclaw/rsp/conductor 等
|
|
7
|
+
// 套件工作台在运行时 import。
|
|
8
|
+
// 依赖方向严格单向:运行时模块绝不 import 构建期模块(运行时内部 surface → embed、
|
|
9
|
+
// host → capability;host 另依赖 @capyclaw/plugin-kit/service/api 纯契约断言)。
|
|
10
|
+
// 根入口 export * 同时导出两类;运行时消费者应优先走子路径(./capability 等),
|
|
11
|
+
// 避免把构建期代码拉进运行时依赖图。
|
|
12
|
+
// 为什么不拆:拆包会破坏 9 个项目的 import 面,收益不抵成本;
|
|
13
|
+
// 决策记录与模块归属清单见 README「双重身份:构建期库 + 运行时库」。
|
|
14
|
+
export * from './manifest.mjs'
|
|
15
|
+
export * from './capability.mjs'
|
|
16
|
+
export * from './orchestration.mjs'
|
|
17
|
+
export * from './embed.mjs'
|
|
18
|
+
export * from './surface.mjs'
|
|
19
|
+
export * from './host.mjs'
|
|
20
|
+
export * from './compose.mjs'
|
|
21
|
+
export * from './profile.mjs'
|
|
22
|
+
export * from './domain.mjs'
|
|
23
|
+
export * from './artifacts.mjs'
|
|
24
|
+
export * from './activation-registry.mjs'
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Suite manifest:读取与静态校验。
|
|
3
|
+
*
|
|
4
|
+
* manifest 是组合的唯一真源;cordis.patch.yml 由 rows 生成,不手写。
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs'
|
|
7
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'node:path'
|
|
8
|
+
|
|
9
|
+
export const SUITE_FILENAMES = ['dsh-suite.json', 'suite.json']
|
|
10
|
+
export const ROLES = new Set(['runtime', 'skills', 'provider', 'ui', 'bridge', 'support'])
|
|
11
|
+
const NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
12
|
+
const VERSION_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/
|
|
13
|
+
const RANGE_RE = /^(?:\^|~|>=|<=|>|<|=)?\s*\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/
|
|
14
|
+
|
|
15
|
+
export function isValidRange(range) {
|
|
16
|
+
if (typeof range !== 'string') return false
|
|
17
|
+
const value = range.trim()
|
|
18
|
+
if (value === '*' || value === 'latest') return true
|
|
19
|
+
return RANGE_RE.test(value)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 判断 exact 版本是否满足简单 range(^ ~ >= <= > < = 或精确)。 */
|
|
23
|
+
export function versionSatisfies(range, version) {
|
|
24
|
+
if (!isValidRange(range) || !VERSION_RE.test(String(version || ''))) return false
|
|
25
|
+
const raw = String(range).trim()
|
|
26
|
+
if (raw === '*' || raw === 'latest') return true
|
|
27
|
+
const match = /^(\^|~|>=|<=|>|<|=)?\s*(\d+)\.(\d+)\.(\d+)/.exec(raw)
|
|
28
|
+
if (!match) return false
|
|
29
|
+
const [, op = '=', rawMajor, rawMinor, rawPatch] = match
|
|
30
|
+
const major = Number(rawMajor)
|
|
31
|
+
const minor = Number(rawMinor)
|
|
32
|
+
const patch = Number(rawPatch)
|
|
33
|
+
const [vm, vn, vp] = String(version).split('.').map(Number)
|
|
34
|
+
const cmp = (vm - major) || (vn - minor) || (vp - patch)
|
|
35
|
+
if (op === '^') return cmp >= 0 && vm === major
|
|
36
|
+
if (op === '~') return cmp >= 0 && vm === major && vn === minor
|
|
37
|
+
if (op === '>=') return cmp >= 0
|
|
38
|
+
if (op === '<=') return cmp <= 0
|
|
39
|
+
if (op === '>') return cmp > 0
|
|
40
|
+
if (op === '<') return cmp < 0
|
|
41
|
+
return cmp === 0
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function readJson(file) {
|
|
45
|
+
return JSON.parse(readFileSync(file, 'utf8'))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 从文件或目录定位 suite manifest。 */
|
|
49
|
+
export function findSuiteManifest(input) {
|
|
50
|
+
let abs = resolve(input)
|
|
51
|
+
/* junction/symlink 安装时 components 的相对路径必须以真实目录为基准,
|
|
52
|
+
* 否则 ../../../../packages/* 会解析到 profile 的 node_modules 外面。 */
|
|
53
|
+
try { abs = realpathSync(abs) } catch { /* 不存在时保留原路径,下面给出准确报错 */ }
|
|
54
|
+
if (!existsSync(abs)) throw new Error(`suite 路径不存在: ${abs}`)
|
|
55
|
+
if (statSync(abs).isFile()) return abs
|
|
56
|
+
for (const name of SUITE_FILENAMES) {
|
|
57
|
+
const file = join(abs, name)
|
|
58
|
+
if (existsSync(file)) return file
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`目录里没有 ${SUITE_FILENAMES.join(' / ')}: ${abs}`)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function loadSuiteManifest(input, options = {}) {
|
|
64
|
+
const file = findSuiteManifest(input)
|
|
65
|
+
const dir = dirname(file)
|
|
66
|
+
const raw = readJson(file)
|
|
67
|
+
const components = Array.isArray(raw.components) ? raw.components : []
|
|
68
|
+
if (options.expand === false || !components.length) {
|
|
69
|
+
return { file, dir, manifest: raw }
|
|
70
|
+
}
|
|
71
|
+
const seen = options.seen || new Set()
|
|
72
|
+
if (seen.has(file)) throw new Error(`suite components 循环引用: ${file}`)
|
|
73
|
+
seen.add(file)
|
|
74
|
+
const manifest = {
|
|
75
|
+
...raw,
|
|
76
|
+
packages: { ...(raw.packages || {}) },
|
|
77
|
+
rows: [],
|
|
78
|
+
checks: [...(raw.checks || [])],
|
|
79
|
+
}
|
|
80
|
+
const rawRows = [...(raw.rows || [])]
|
|
81
|
+
for (const component of components) {
|
|
82
|
+
if (typeof component !== 'string' || !component) throw new Error(`${file}: components 必须是字符串数组`)
|
|
83
|
+
const loaded = loadSuiteManifest(resolve(dir, component), { seen })
|
|
84
|
+
for (const [name, entry] of Object.entries(loaded.manifest.packages || {})) {
|
|
85
|
+
if (manifest.packages[name]) {
|
|
86
|
+
if (manifest.packages[name].version !== entry.version || manifest.packages[name].role !== entry.role) {
|
|
87
|
+
throw new Error(`suite components 包冲突: ${name}(${manifest.name})`)
|
|
88
|
+
}
|
|
89
|
+
continue
|
|
90
|
+
}
|
|
91
|
+
const path = entry.path ? relative(dir, resolve(loaded.dir, entry.path)) : entry.path
|
|
92
|
+
manifest.packages[name] = { ...entry, path }
|
|
93
|
+
}
|
|
94
|
+
manifest.rows.push(...(loaded.manifest.rows || []))
|
|
95
|
+
manifest.checks.push(...(loaded.manifest.checks || []))
|
|
96
|
+
}
|
|
97
|
+
/* 组件行必须先于本 suite 行:功能插件在 apply 时需要 ctx.* 已就绪。 */
|
|
98
|
+
manifest.rows.push(...rawRows)
|
|
99
|
+
delete manifest.components
|
|
100
|
+
return { file, dir, manifest }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** 取 semver range 的 major;无法判断时返回 null。 */
|
|
104
|
+
export function majorOf(range) {
|
|
105
|
+
if (typeof range !== 'string') return null
|
|
106
|
+
if (range.trim() === '*' || range.trim() === 'latest') return null
|
|
107
|
+
const match = /(?:^|[^\d])(\d+)(?:\.\d+)?/.exec(range)
|
|
108
|
+
return match ? Number(match[1]) : null
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function validateSuiteManifest(manifest, options = {}) {
|
|
112
|
+
const errors = []
|
|
113
|
+
const warnings = []
|
|
114
|
+
const add = (list, message) => list.push(message)
|
|
115
|
+
const baseDir = options.baseDir || null
|
|
116
|
+
|
|
117
|
+
if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) {
|
|
118
|
+
return { ok: false, errors: ['manifest 必须是 object'], warnings }
|
|
119
|
+
}
|
|
120
|
+
if (!NAME_RE.test(manifest.name || '')) add(errors, 'name 必须是 kebab-case')
|
|
121
|
+
if (!VERSION_RE.test(manifest.version || '')) add(errors, 'version 必须是 semver(如 2.0.0)')
|
|
122
|
+
if (manifest.title != null && typeof manifest.title !== 'string') add(errors, 'title 必须是字符串')
|
|
123
|
+
if (manifest.description != null && typeof manifest.description !== 'string') add(errors, 'description 必须是字符串')
|
|
124
|
+
if (manifest.components != null) {
|
|
125
|
+
if (!Array.isArray(manifest.components) || manifest.components.some((item) => typeof item !== 'string' || !item)) {
|
|
126
|
+
add(errors, 'components 必须是字符串数组')
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const packages = manifest.packages
|
|
131
|
+
if (!packages || typeof packages !== 'object' || Array.isArray(packages) || Object.keys(packages).length === 0) {
|
|
132
|
+
add(errors, 'packages 必须是非空 object')
|
|
133
|
+
} else {
|
|
134
|
+
for (const [name, pkg] of Object.entries(packages)) {
|
|
135
|
+
if (!name || typeof name !== 'string') add(errors, 'packages 的键必须是包名')
|
|
136
|
+
if (!pkg || typeof pkg !== 'object' || Array.isArray(pkg)) {
|
|
137
|
+
add(errors, `packages.${name} 必须是 object`)
|
|
138
|
+
continue
|
|
139
|
+
}
|
|
140
|
+
if (!ROLES.has(pkg.role)) add(errors, `packages.${name}.role 非法: ${pkg.role}`)
|
|
141
|
+
if (typeof pkg.version !== 'string' || !pkg.version) add(errors, `packages.${name}.version 必须是非空字符串`)
|
|
142
|
+
else if (!isValidRange(pkg.version)) add(errors, `packages.${name}.version 不是合法 semver range: ${pkg.version}`)
|
|
143
|
+
if (pkg.path != null && (typeof pkg.path !== 'string' || !pkg.path)) add(errors, `packages.${name}.path 必须是非空字符串`)
|
|
144
|
+
if (baseDir && typeof pkg.path === 'string' && pkg.path) {
|
|
145
|
+
const dir = resolve(baseDir, pkg.path)
|
|
146
|
+
if (!existsSync(join(dir, 'package.json'))) {
|
|
147
|
+
add(errors, `packages.${name}.path 指向的目录没有 package.json: ${dir}`)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (pkg.required != null && typeof pkg.required !== 'boolean') add(errors, `packages.${name}.required 必须是 boolean`)
|
|
151
|
+
if (pkg.requires != null) {
|
|
152
|
+
if (typeof pkg.requires !== 'object' || Array.isArray(pkg.requires)) add(errors, `packages.${name}.requires 必须是 object`)
|
|
153
|
+
else for (const [dep, range] of Object.entries(pkg.requires)) {
|
|
154
|
+
if (dep === 'capabilities') {
|
|
155
|
+
if (typeof range !== 'object' || Array.isArray(range)) {
|
|
156
|
+
add(errors, `packages.${name}.requires.capabilities 必须是 object`)
|
|
157
|
+
} else for (const [cap, capRange] of Object.entries(range)) {
|
|
158
|
+
if (typeof capRange !== 'string' || !capRange) add(errors, `packages.${name}.requires.capabilities.${cap} 必须是非空字符串`)
|
|
159
|
+
else if (!isValidRange(capRange)) add(errors, `packages.${name}.requires.capabilities.${cap} 不是合法 semver range: ${capRange}`)
|
|
160
|
+
}
|
|
161
|
+
} else if (typeof range !== 'string' || !range) {
|
|
162
|
+
add(errors, `packages.${name}.requires.${dep} 必须是非空字符串`)
|
|
163
|
+
} else if (!isValidRange(range)) {
|
|
164
|
+
add(errors, `packages.${name}.requires.${dep} 不是合法 semver range: ${range}`)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (pkg.provides != null) {
|
|
169
|
+
if (typeof pkg.provides !== 'object' || Array.isArray(pkg.provides)) {
|
|
170
|
+
add(errors, `packages.${name}.provides 必须是 object`)
|
|
171
|
+
} else {
|
|
172
|
+
for (const key of ['tools', 'skills', 'services']) {
|
|
173
|
+
if (pkg.provides[key] != null && (!Array.isArray(pkg.provides[key]) || pkg.provides[key].some((v) => typeof v !== 'string'))) {
|
|
174
|
+
add(errors, `packages.${name}.provides.${key} 必须是 string[]`)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (pkg.provides.capabilities != null) {
|
|
178
|
+
if (typeof pkg.provides.capabilities !== 'object' || Array.isArray(pkg.provides.capabilities)) {
|
|
179
|
+
add(errors, `packages.${name}.provides.capabilities 必须是 object`)
|
|
180
|
+
} else for (const [cap, version] of Object.entries(pkg.provides.capabilities)) {
|
|
181
|
+
if (typeof version !== 'string' || !version) add(errors, `packages.${name}.provides.capabilities.${cap} 必须是非空字符串`)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (pkg.provides.ports != null && (!Array.isArray(pkg.provides.ports) || pkg.provides.ports.some((v) => !Number.isInteger(v) || v < 1 || v > 65535))) {
|
|
185
|
+
add(errors, `packages.${name}.provides.ports 必须是 1..65535 的整数数组`)
|
|
186
|
+
} else if (Array.isArray(pkg.provides.ports)) {
|
|
187
|
+
const seenPorts = new Set()
|
|
188
|
+
for (const port of pkg.provides.ports) {
|
|
189
|
+
if (seenPorts.has(port)) add(errors, `packages.${name}.provides.ports 重复: ${port}`)
|
|
190
|
+
seenPorts.add(port)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const rows = manifest.rows
|
|
199
|
+
if (!Array.isArray(rows) || rows.length === 0) {
|
|
200
|
+
add(errors, 'rows 必须是非空数组')
|
|
201
|
+
} else {
|
|
202
|
+
const ids = new Set()
|
|
203
|
+
for (const row of rows) {
|
|
204
|
+
if (!row || typeof row !== 'object' || Array.isArray(row)) {
|
|
205
|
+
add(errors, 'rows 的每一项必须是 object')
|
|
206
|
+
continue
|
|
207
|
+
}
|
|
208
|
+
if (!NAME_RE.test(row.id || '')) add(errors, `row.id 非法: ${row.id}`)
|
|
209
|
+
if (ids.has(row.id)) add(errors, `row.id 重复: ${row.id}`)
|
|
210
|
+
ids.add(row.id)
|
|
211
|
+
if (typeof row.name !== 'string' || !row.name) add(errors, `row ${row.id} 缺少 name`)
|
|
212
|
+
if (row.disabled != null && typeof row.disabled !== 'boolean') add(errors, `row ${row.id}.disabled 必须是 boolean`)
|
|
213
|
+
if (row.config != null && (typeof row.config !== 'object' || Array.isArray(row.config))) add(errors, `row ${row.id}.config 必须是 object`)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (manifest.checks != null) {
|
|
218
|
+
if (!Array.isArray(manifest.checks)) add(errors, 'checks 必须是数组')
|
|
219
|
+
else {
|
|
220
|
+
const ids = new Set()
|
|
221
|
+
for (const check of manifest.checks) {
|
|
222
|
+
if (!check || typeof check !== 'object' || Array.isArray(check)) {
|
|
223
|
+
add(errors, 'checks 的每一项必须是 object')
|
|
224
|
+
continue
|
|
225
|
+
}
|
|
226
|
+
if (!check.id || ids.has(check.id)) add(errors, `check.id 缺失或重复: ${check.id}`)
|
|
227
|
+
ids.add(check.id)
|
|
228
|
+
if (check.type === 'http') {
|
|
229
|
+
if (typeof check.url !== 'string' || !check.url) add(errors, `check ${check.id} 缺少 url`)
|
|
230
|
+
} else if (check.type === 'contract') {
|
|
231
|
+
if (typeof check.url !== 'string' || !check.url) add(errors, `check ${check.id} 缺少 url`)
|
|
232
|
+
if (typeof check.tool !== 'string' || !check.tool) add(errors, `check ${check.id} 缺少 tool`)
|
|
233
|
+
if (!Number.isInteger(check.major) || check.major < 0) add(errors, `check ${check.id}.major 必须是非负整数`)
|
|
234
|
+
} else {
|
|
235
|
+
add(errors, `check ${check.id} 的 type 非法: ${check.type}`)
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/* 包内 rows 的 name 不一定在 packages 里(可以是官方 mcp-client),只给提示。 */
|
|
242
|
+
if (packages && rows) {
|
|
243
|
+
for (const row of rows) {
|
|
244
|
+
if (row && typeof row.name === 'string' && !packages[row.name]) {
|
|
245
|
+
warnings.push(`row ${row.id} 引用外部包 ${row.name}(不在 packages 里,按已安装处理)`)
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return { ok: errors.length === 0, errors, warnings }
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function assertValidSuiteManifest(manifest, label = 'suite') {
|
|
254
|
+
const result = validateSuiteManifest(manifest)
|
|
255
|
+
if (!result.ok) throw new Error(`${label} 校验失败:\n- ${result.errors.join('\n- ')}`)
|
|
256
|
+
return result
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** 解析 packages.<name>.path 为绝对目录。 */
|
|
260
|
+
export function packageDirOf(manifestDir, name, entry) {
|
|
261
|
+
if (!entry || typeof entry.path !== 'string') return null
|
|
262
|
+
return isAbsolute(entry.path) ? entry.path : resolve(manifestDir, entry.path)
|
|
263
|
+
}
|