@capyclaw/offline-ddr0 1.9.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/media.mjs +3 -3
- package/lib/sync.mjs +1 -1
- package/lib/workstore-repository.mjs +1 -1
- package/lib/workstore.mjs +17 -7
- 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 +96 -9
- 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/loader.mjs +8 -1
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +5 -2
- package/node_modules/@capyclaw/foundation/abi/version.mjs +63 -5
- 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/adapters/raw.mjs +11 -10
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +8 -1
- 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/host/memory.mjs +29 -2
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +13 -3
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +31 -3
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +12 -2
- 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/editor/lease.mjs +3 -82
- 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/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 +18 -19
- package/node_modules/@capyclaw/suite-kit/README.md +52 -1
- package/node_modules/@capyclaw/suite-kit/package.json +6 -2
- package/node_modules/@capyclaw/suite-kit/src/host.mjs +230 -0
- package/node_modules/@capyclaw/suite-kit/src/index.mjs +14 -0
- package/node_modules/@capyclaw/suite-kit/suite.schema.json +16 -0
- package/node_modules/@capyclaw/work-store/STANDARD.md +9 -3
- package/node_modules/@capyclaw/work-store/dsh-suite.json +10 -3
- package/node_modules/@capyclaw/work-store/package.json +1 -1
- package/node_modules/@capyclaw/work-store/src/backend.mjs +3 -2
- package/node_modules/@capyclaw/work-store/src/index.mjs +16 -15
- package/package.json +1 -1
- package/plugin.mjs +13 -5
|
@@ -19,6 +19,7 @@ import crypto from 'node:crypto'
|
|
|
19
19
|
import { listen, send, sendText, readBody } from '@capyclaw/plugin-kit/service/http'
|
|
20
20
|
import { createServiceApi } from '@capyclaw/plugin-kit/service/api'
|
|
21
21
|
import { isLoopbackOrigin as sharedIsLoopbackOrigin, mimeFor } from '@capyclaw/plugin-kit/util/http'
|
|
22
|
+
import { safeJoin, cleanStaticPrefix, staticPrefixHit, staticRelRaw, decodeStaticRel, staticFileHit, staticHitNameType, staticBaseHeaders } from '@capyclaw/plugin-kit/service/static'
|
|
22
23
|
import { tuning } from './tuning.mjs'
|
|
23
24
|
|
|
24
25
|
function slugOf(id) {
|
|
@@ -133,11 +134,7 @@ async function probeExisting(origin, healthPath, id) {
|
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
|
|
137
|
-
const target = path.resolve(root, `.${path.sep}${rel}`)
|
|
138
|
-
const base = path.resolve(root)
|
|
139
|
-
return target === base || target.startsWith(base + path.sep) ? target : null
|
|
140
|
-
}
|
|
137
|
+
/* safeJoin 已收敛到 @capyclaw/plugin-kit/service/static(P2-13a 静态公共核心)。 */
|
|
141
138
|
|
|
142
139
|
/**
|
|
143
140
|
* @param {{
|
|
@@ -204,20 +201,28 @@ export function createServiceApp(options = {}) {
|
|
|
204
201
|
})
|
|
205
202
|
},
|
|
206
203
|
|
|
207
|
-
/** 静态目录挂载。files 可给显式映射:{ '/': ['index.html','text/html'] }。
|
|
204
|
+
/** 静态目录挂载。files 可给显式映射:{ '/': ['index.html','text/html'] }。
|
|
205
|
+
* 路径/头部计算走 @capyclaw/plugin-kit/service/static 公共核心(P2-13a);
|
|
206
|
+
* 本宿主保留自己的响应政策:畸形编码回 400、content-type 取 mimeFor(请求 rel)、每次读盘。 */
|
|
208
207
|
static(prefix, dir, { files = null, index = 'index.html' } = {}) {
|
|
209
|
-
const cleanPrefix = prefix
|
|
208
|
+
const cleanPrefix = cleanStaticPrefix(prefix)
|
|
210
209
|
return app.use((req, res, u) => {
|
|
211
210
|
if (req.method !== 'GET' && req.method !== 'HEAD') return false
|
|
212
|
-
if (
|
|
213
|
-
const relRaw =
|
|
214
|
-
const rel = relRaw
|
|
211
|
+
if (!staticPrefixHit(u.pathname, cleanPrefix)) return false
|
|
212
|
+
const relRaw = staticRelRaw(u.pathname, cleanPrefix)
|
|
213
|
+
const rel = decodeStaticRel(relRaw, index)
|
|
214
|
+
if (rel === null) {
|
|
215
|
+
/* 畸形百分号编码 → URIError,不包会冒成 500;客户端错误回 400。 */
|
|
216
|
+
res.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' })
|
|
217
|
+
res.end(req.method === 'HEAD' ? undefined : 'malformed path encoding')
|
|
218
|
+
return true
|
|
219
|
+
}
|
|
215
220
|
let file = null
|
|
216
221
|
let type = mimeFor(rel)
|
|
217
222
|
if (files) {
|
|
218
|
-
const hit = files
|
|
223
|
+
const hit = staticFileHit(files, relRaw)
|
|
219
224
|
if (!hit) return false
|
|
220
|
-
const [name, explicitType] =
|
|
225
|
+
const [name, explicitType] = staticHitNameType(hit)
|
|
221
226
|
file = safeJoin(dir, name)
|
|
222
227
|
type = explicitType || type
|
|
223
228
|
} else {
|
|
@@ -226,13 +231,7 @@ export function createServiceApp(options = {}) {
|
|
|
226
231
|
if (!file) return false
|
|
227
232
|
try {
|
|
228
233
|
const data = fs.readFileSync(file)
|
|
229
|
-
res.writeHead(200,
|
|
230
|
-
'content-type': type,
|
|
231
|
-
'content-length': data.length,
|
|
232
|
-
'x-content-type-options': 'nosniff',
|
|
233
|
-
'referrer-policy': 'no-referrer',
|
|
234
|
-
'cache-control': 'no-cache',
|
|
235
|
-
})
|
|
234
|
+
res.writeHead(200, staticBaseHeaders(type, data.length))
|
|
236
235
|
res.end(req.method === 'HEAD' ? undefined : data)
|
|
237
236
|
return true
|
|
238
237
|
} catch {
|
|
@@ -231,8 +231,59 @@ node scripts/build-bundle.mjs \
|
|
|
231
231
|
`setup.mjs` 调用 `installDomain({ runPnpm: false })`,在 bundle 自带的
|
|
232
232
|
`DSH_HOME` 下建立 profile 和组件链接,不依赖 pnpm,也不写用户主目录。
|
|
233
233
|
|
|
234
|
+
## 双重身份:构建期库 + 运行时库(P2-12 决策记录)
|
|
235
|
+
|
|
236
|
+
这个包同时是**构建期库**(suite/domain 清单 validate/compose/profile)与**运行时库**
|
|
237
|
+
(orchestration 闸/Mandate/事件/步骤、embed 握手、surface 挂载)。两类模块同包共存,
|
|
238
|
+
但依赖方向严格单向:**运行时模块绝不 import 构建期模块**。
|
|
239
|
+
|
|
240
|
+
### 构建期模块(清单校验 / 组合 / 安装,构建与安装期执行)
|
|
241
|
+
|
|
242
|
+
| 子路径 | 模块 | 职责 |
|
|
243
|
+
| --- | --- | --- |
|
|
244
|
+
| `@capyclaw/suite-kit/manifest` | `src/manifest.mjs` | suite/domain 清单读取与静态校验(`loadSuiteManifest`) |
|
|
245
|
+
| `@capyclaw/suite-kit/compose` | `src/compose.mjs` | 套件组合、冲突检测、`renderCordisPatch`、`composeToDir` |
|
|
246
|
+
| `@capyclaw/suite-kit/profile` | `src/profile.mjs` | profile 生成/安装(`installSuites`)、`doctor` 诊断 |
|
|
247
|
+
| `@capyclaw/suite-kit/domain` | `src/domain.mjs` | 领域解析(`resolveDomain`)与 staging(`stageDomain`) |
|
|
248
|
+
| `@capyclaw/suite-kit/artifacts` | `src/artifacts.mjs` | 版本化 artifact store:打包/回滚 |
|
|
249
|
+
| 仅根入口导出 | `src/activation-registry.mjs` | 安装期编译 launch-engine 激活注册表(无独立子路径) |
|
|
250
|
+
| `dsh-suite` / `dsh-domain` | `bin/` | CLI 入口 |
|
|
251
|
+
| `@capyclaw/suite-kit/schema` / `./domain-schema` | 两个 JSON Schema | 清单 schema |
|
|
252
|
+
|
|
253
|
+
构建期内部依赖:`profile → compose / manifest / artifacts / activation-registry`,
|
|
254
|
+
`compose → manifest`,`domain → compose / manifest`。
|
|
255
|
+
|
|
256
|
+
### 运行时模块(宿主无关的协议原语,被套件工作台在运行时 import)
|
|
257
|
+
|
|
258
|
+
| 子路径 | 模块 | 职责 | 现有消费者(grep 实证) |
|
|
259
|
+
| --- | --- | --- | --- |
|
|
260
|
+
| `@capyclaw/suite-kit/capability` | `src/capability.mjs` | 能力描述符词表/校验/匹配/发现(纯函数,无内部依赖) | capyclaw/rsp/conductor 工作台 `lib/host.mjs` |
|
|
261
|
+
| `@capyclaw/suite-kit/orchestration` | `src/orchestration.mjs` | 确认闸 `evaluateGate`、Mandate、事件、步骤原语(仅依赖 `node:crypto`) | conductor 工作台 `lib/engine.mjs`、`lib/plan-store.mjs` |
|
|
262
|
+
| `@capyclaw/suite-kit/embed` | `src/embed.mjs` | 嵌入握手协议原语(无内部依赖) | `surface.mjs` 与浏览器侧客户端 |
|
|
263
|
+
| `@capyclaw/suite-kit/surface` | `src/surface.mjs` | `attachSurface`:挂 `GET /embed.js` 与 `/api/surface`(import `./embed.mjs`) | capyclaw/rsp/conductor 工作台 `lib/workbench.mjs`、B/official/capyclaw-offline-ddr0 |
|
|
264
|
+
| `@capyclaw/suite-kit/client/embed.js` | `client/embed.js` | 浏览器侧握手客户端(经 surface 分发) | 嵌入页面 |
|
|
265
|
+
|
|
266
|
+
### 依赖方向与使用约定
|
|
267
|
+
|
|
268
|
+
- 运行时模块(capability/orchestration/embed/surface/client)绝不 import 构建期模块;
|
|
269
|
+
运行时内部唯一依赖是 `surface → embed`。
|
|
270
|
+
- 根入口 `export *` 同时导出两类模块:构建脚本 import 根入口会连带拉入运行时件
|
|
271
|
+
(均为纯函数、无副作用,不会触发安装逻辑);**运行时消费者应优先走子路径**,
|
|
272
|
+
避免把构建期代码拉进运行时依赖图。
|
|
273
|
+
|
|
274
|
+
### 为什么暂不拆包(决策记录)
|
|
275
|
+
|
|
276
|
+
拆成 `suite-kit-build` / `suite-kit-runtime` 两个包会破坏既有项目的 import 面
|
|
277
|
+
(架构审查 M7/P2-12 统计涉及 9 个项目;本轮 grep 实证至少包括 A/projects 的
|
|
278
|
+
capyclaw/rsp/conductor 工作台、A/build 构建脚本、B/official/capyclaw-offline-ddr0、
|
|
279
|
+
C/tools/capyclaw-plugin-generator),所有消费者都要同步改 import 与依赖声明。
|
|
280
|
+
而两类模块已按子路径隔离、依赖方向单向,实际耦合成本低。**收益不抵成本,暂不拆包**,
|
|
281
|
+
改为以本节 + package.json description + 主入口头注释显式文档化双重身份。
|
|
282
|
+
将来若确需拆包,应先把所有消费者迁到子路径 import,再做物理拆分。
|
|
283
|
+
|
|
234
284
|
## 设计边界
|
|
235
285
|
|
|
236
|
-
-
|
|
286
|
+
- 这个包不是 DSH 运行时插件,不会出现在 agent 工具面里;但它有**双重身份**——
|
|
287
|
+
构建期库 + 运行时库(运行时协议原语被套件工作台 import),见上节「双重身份」。
|
|
237
288
|
- 组合层不替子包做业务;它只负责“谁和谁一起跑、怎么验证、冲突在哪”。
|
|
238
289
|
- 运行时通信用 Cordis service / MCP / HTTP;suite-kit 不创建跨进程总线。
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capyclaw/suite-kit",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "DSH suite/domain
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "DSH suite/domain 标准件(双重身份:构建期库 + 运行时库,暂不拆包,见 README「双重身份」)。构建期:manifest 校验、compose、profile 生成、domain 解析、artifact 打包;运行时:统一能力描述符、编排闸/授权、嵌入握手与 surface 挂载。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
|
7
7
|
"exports": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"./orchestration": "./src/orchestration.mjs",
|
|
14
14
|
"./embed": "./src/embed.mjs",
|
|
15
15
|
"./surface": "./src/surface.mjs",
|
|
16
|
+
"./host": "./src/host.mjs",
|
|
16
17
|
"./client/embed.js": "./client/embed.js",
|
|
17
18
|
"./profile": "./src/profile.mjs",
|
|
18
19
|
"./artifacts": "./src/artifacts.mjs",
|
|
@@ -38,6 +39,9 @@
|
|
|
38
39
|
"engines": {
|
|
39
40
|
"node": ">=18"
|
|
40
41
|
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@capyclaw/plugin-kit": "^0.2.6"
|
|
44
|
+
},
|
|
41
45
|
"license": "MIT",
|
|
42
46
|
"publishConfig": {
|
|
43
47
|
"access": "public"
|
|
@@ -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
|
+
}
|
|
@@ -1,8 +1,22 @@
|
|
|
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「双重身份:构建期库 + 运行时库」。
|
|
1
14
|
export * from './manifest.mjs'
|
|
2
15
|
export * from './capability.mjs'
|
|
3
16
|
export * from './orchestration.mjs'
|
|
4
17
|
export * from './embed.mjs'
|
|
5
18
|
export * from './surface.mjs'
|
|
19
|
+
export * from './host.mjs'
|
|
6
20
|
export * from './compose.mjs'
|
|
7
21
|
export * from './profile.mjs'
|
|
8
22
|
export * from './domain.mjs'
|
|
@@ -54,6 +54,22 @@
|
|
|
54
54
|
"additionalProperties": { "type": "string", "minLength": 1 }
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
+
},
|
|
58
|
+
"surfaceLifecycle": {
|
|
59
|
+
"type": "object",
|
|
60
|
+
"additionalProperties": false,
|
|
61
|
+
"required": ["hooks", "headlessObservation"],
|
|
62
|
+
"description": "表面可见性生命周期标准声明(docs/SURFACE-LIFECYCLE-STANDARD.md §6):四个渲染面钩子齐全 + 无头观察兜底。协议真源 C/packages/capyclaw-foundation/abi/visibility.mjs。",
|
|
63
|
+
"properties": {
|
|
64
|
+
"hooks": {
|
|
65
|
+
"type": "array",
|
|
66
|
+
"items": { "enum": ["onVisibility", "suspendRender", "resumeRender", "rehydrate"] },
|
|
67
|
+
"minItems": 4,
|
|
68
|
+
"maxItems": 4,
|
|
69
|
+
"uniqueItems": true
|
|
70
|
+
},
|
|
71
|
+
"headlessObservation": { "const": true }
|
|
72
|
+
}
|
|
57
73
|
}
|
|
58
74
|
}
|
|
59
75
|
}
|
|
@@ -98,11 +98,13 @@ stats() → {total,bySuite,byKind} # 仪表盘
|
|
|
98
98
|
appendJournal(id,event) / journalTail(id,limit)
|
|
99
99
|
findJournal(type, needle, limit?) → [{workId,...data,ts}] # instr 字面匹配(摄入台账去重,V2-6)
|
|
100
100
|
writeCheckpoint(id,name,payload) / readCheckpoint(id,name)
|
|
101
|
-
listCheckpoints(id) → [{name,ts,createdAt,size,meta}]
|
|
101
|
+
listCheckpoints(id,{project?}) → [{name,ts,createdAt,size,meta,...}] # 通用形状,不解析 payload(V2-5);
|
|
102
|
+
# project(payload,base)→扩展字段,由套件适配层显式声明(如 PPT slides)
|
|
102
103
|
getMeta(key, fallback?) / setMeta(key, value) # work_meta KV(V2-3 配套)
|
|
103
104
|
listAssets(id) → [{assetId,role}]
|
|
104
105
|
tx(fn) → fn(api) # 单事务组合写(BEGIN IMMEDIATE,异常 ROLLBACK,禁嵌套,V2-2)
|
|
105
|
-
backendFor({suite,kind,sessionId,initialDoc?,documentKey?}) → FileStateBackend 同接口
|
|
106
|
+
backendFor({suite,kind,sessionId,initialDoc?,documentKey?,transform?,project?}) → FileStateBackend 同接口
|
|
107
|
+
# project:checkpoint 列表的套件投影(形状声明),透传 listCheckpoints
|
|
106
108
|
routes({basePath?}) → HTTP handler # 前端浏览接口
|
|
107
109
|
flush() / close()
|
|
108
110
|
```
|
|
@@ -213,7 +215,11 @@ POST /works/works/<id>/rollback {version}
|
|
|
213
215
|
- **验收**:「close() 后句柄释放(再操作抛错)」「mount → dispose → 无残留 interval/句柄」。
|
|
214
216
|
|
|
215
217
|
### V2-5 通用化修订(去套件专属假设)
|
|
216
|
-
- `listCheckpoints` 返回通用形状 `{name,ts,createdAt,size,meta}`,**不解析 payload
|
|
218
|
+
- `listCheckpoints` 返回通用形状 `{name,ts,createdAt,size,meta}`,**不解析 payload 内部结构**
|
|
219
|
+
(含 seq/applied_seq 等会话字段也不默认解析)。业务/协议扩展字段由套件适配层经
|
|
220
|
+
`{project}` 显式声明叠加(`project(payload,base)→扩展字段`,合并约定同
|
|
221
|
+
document-workbench `store/projection` 的 `projectCheckpoint`);旧 payload 原样保留,
|
|
222
|
+
`readCheckpoint` 返回全量,套件投影兼容读旧形状,无需迁移数据。
|
|
217
223
|
- 删除分层:`deleteWork` 软删;`purgeWork` 硬删(FK 级联清 state/versions/checkpoints/assets)+ journal
|
|
218
224
|
tombstone `{type:'purge',id,ts}`。画廊「删除」映射 purgeWork(磁盘回收),回收站映射 deleteWork。
|
|
219
225
|
- 查询截断显式:`listWorks` limit 钳 1–500,`total` 为全量计数;消费方不得把「取满 500」当全量(须分页)。
|
|
@@ -7,10 +7,12 @@
|
|
|
7
7
|
"packages": {
|
|
8
8
|
"@capyclaw/work-store": {
|
|
9
9
|
"role": "provider",
|
|
10
|
-
"version": "0.3.
|
|
10
|
+
"version": "^0.3.2",
|
|
11
11
|
"path": ".",
|
|
12
12
|
"provides": {
|
|
13
|
-
"services": [
|
|
13
|
+
"services": [
|
|
14
|
+
"workStore"
|
|
15
|
+
],
|
|
14
16
|
"capabilities": {
|
|
15
17
|
"workStore.store": "1.2.0",
|
|
16
18
|
"workStore.catalog": "1.2.0",
|
|
@@ -21,6 +23,11 @@
|
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
},
|
|
24
|
-
"rows": [
|
|
26
|
+
"rows": [
|
|
27
|
+
{
|
|
28
|
+
"id": "work-store",
|
|
29
|
+
"name": "@capyclaw/work-store"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
25
32
|
"checks": []
|
|
26
33
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capyclaw/work-store",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "DSH 通用作品持久化底座:SQLite(node:sqlite) 作品目录 + 不可变版本 + journal + checkpoint + 前端查询面,向插件提供 ctx.workStore;非结构化字节委托内容寻址 blob 仓(ctx.assets),正文只存引用。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/host.mjs",
|
|
@@ -19,7 +19,7 @@ function checkpointName(name) {
|
|
|
19
19
|
return safe
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export function createSqliteBackend({ store, workId, initialDoc = {}, transform = null }) {
|
|
22
|
+
export function createSqliteBackend({ store, workId, initialDoc = {}, transform = null, project = null }) {
|
|
23
23
|
if (!store) throw new Error('createSqliteBackend 需要 store')
|
|
24
24
|
if (!workId) throw new Error('createSqliteBackend 需要 workId')
|
|
25
25
|
const id = String(workId)
|
|
@@ -83,7 +83,8 @@ export function createSqliteBackend({ store, workId, initialDoc = {}, transform
|
|
|
83
83
|
},
|
|
84
84
|
|
|
85
85
|
listCheckpoints() {
|
|
86
|
-
|
|
86
|
+
/* 套件投影(形状声明)透传给 store:内核默认只回通用信封(V2-5)。 */
|
|
87
|
+
return store.listCheckpoints(id, typeof project === 'function' ? { project } : {})
|
|
87
88
|
},
|
|
88
89
|
}
|
|
89
90
|
}
|
|
@@ -470,29 +470,28 @@ export function createWorkStore(config = {}) {
|
|
|
470
470
|
}
|
|
471
471
|
|
|
472
472
|
/**
|
|
473
|
-
* 通用 checkpoint 清单(V2-5):{name, ts, size, meta}
|
|
474
|
-
* payload
|
|
473
|
+
* 通用 checkpoint 清单(V2-5):{name, ts, createdAt, size, meta}——
|
|
474
|
+
* 内核不解析 payload 内部任何业务形状(PPT 的 slides/title、会话的 seq 等)。
|
|
475
|
+
* 扩展字段由套件适配层经 options.project(payload, base) 显式声明并叠加;
|
|
476
|
+
* 旧 checkpoint 的 payload 原样保留(readCheckpoint 返回全量),套件投影兼容读旧形状。
|
|
477
|
+
* 合并约定与 document-workbench/store/projection 的 projectCheckpoint 一致
|
|
478
|
+
* (底座刻意不 import document-workbench,故内联同约定)。
|
|
475
479
|
*/
|
|
476
|
-
function listCheckpoints(id) {
|
|
480
|
+
function listCheckpoints(id, options = {}) {
|
|
481
|
+
const project = typeof options.project === 'function' ? options.project : null
|
|
477
482
|
return stmt.listCheckpoints.all(String(id)).map((r) => {
|
|
478
|
-
const
|
|
479
|
-
const
|
|
483
|
+
const parsed = parseJson(r.payload, {})
|
|
484
|
+
const p = parsed && typeof parsed === 'object' ? parsed : {}
|
|
485
|
+
const base = {
|
|
480
486
|
name: r.name,
|
|
481
487
|
ts: r.created_at,
|
|
482
488
|
createdAt: r.created_at,
|
|
483
489
|
size: Buffer.byteLength(r.payload, 'utf8'),
|
|
484
490
|
meta: p.meta && typeof p.meta === 'object' ? p.meta : {},
|
|
485
491
|
}
|
|
486
|
-
if (
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
if (Array.isArray(p.pending)) out.pending = p.pending.length
|
|
490
|
-
const deck = p.deck && typeof p.deck === 'object' ? p.deck : null
|
|
491
|
-
const title = p.title || (deck && deck.title) || ''
|
|
492
|
-
if (title) out.title = title
|
|
493
|
-
if (deck && Array.isArray(deck.slides)) out.slides = deck.slides.length
|
|
494
|
-
}
|
|
495
|
-
return out
|
|
492
|
+
if (!project) return base
|
|
493
|
+
const extra = project(p, base)
|
|
494
|
+
return extra && typeof extra === 'object' ? { ...base, ...extra } : base
|
|
496
495
|
})
|
|
497
496
|
}
|
|
498
497
|
|
|
@@ -503,6 +502,7 @@ export function createWorkStore(config = {}) {
|
|
|
503
502
|
/**
|
|
504
503
|
* 给 DocumentSession 用的后端:实现 FileStateBackend 同接口,上层零改。
|
|
505
504
|
* 先 ensureWork(幂等),再返回绑定该作品的 SqliteStateBackend。
|
|
505
|
+
* input.project:checkpoint 列表的套件投影(形状声明),透传给 backend。
|
|
506
506
|
*/
|
|
507
507
|
function backendFor(input = {}) {
|
|
508
508
|
const work = ensureWork(input)
|
|
@@ -511,6 +511,7 @@ export function createWorkStore(config = {}) {
|
|
|
511
511
|
workId: work.id,
|
|
512
512
|
initialDoc: input.initialDoc || {},
|
|
513
513
|
transform: typeof input.transform === 'function' ? input.transform : null,
|
|
514
|
+
project: typeof input.project === 'function' ? input.project : null,
|
|
514
515
|
})
|
|
515
516
|
}
|
|
516
517
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capyclaw/offline-ddr0",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"description": "真离线版 ddr0 + 作品/会话统一持久化地基:接口快照与作品代码打包在插件内,断网也能打开;本地库稳定存储作品与会话,可管理/查看/继续对话;本地 work-store(SQLite)生成物按 ddr0 作品契约进画廊,PPT 用 PPTist 装饰器只读放映;ETag/304 协商缓存+列表瘦身提速 by CapyClaw",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./plugin.mjs",
|