@capyclaw/offline-ddr0 1.9.0 → 1.9.2
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 +4 -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/ledger.mjs +151 -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/service-host/dsh-suite.json +1 -1
- package/node_modules/@capyclaw/service-host/package.json +2 -2
- package/node_modules/@capyclaw/service-host/src/index.mjs +50 -24
- 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 +251 -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
|
@@ -0,0 +1,251 @@
|
|
|
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(纯契约断言)与 /ledger(统一台账,best-effort)。
|
|
23
|
+
* 不 import 构建期模块。
|
|
24
|
+
*/
|
|
25
|
+
import fs from 'node:fs'
|
|
26
|
+
import os from 'node:os'
|
|
27
|
+
import path from 'node:path'
|
|
28
|
+
import { assertServiceApi } from '@capyclaw/plugin-kit/service/api'
|
|
29
|
+
import { validateCapabilityDescriptor } from './capability.mjs'
|
|
30
|
+
import { appendLedger, ledgerFileFor } from '@capyclaw/plugin-kit/ledger'
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 服务懒解析:cordis 未 inject 的服务直接访问 ctx[name] 可能抛错,
|
|
34
|
+
* 统一走 reflect.get(权威)→ ctx[name](兜底)→ null(缺席降级)。
|
|
35
|
+
* @param {object} ctx cordis 上下文
|
|
36
|
+
* @param {string} serviceName 服务名
|
|
37
|
+
* @returns {object|null}
|
|
38
|
+
*/
|
|
39
|
+
export function safeGet(ctx, serviceName) {
|
|
40
|
+
try { return ctx.reflect?.get?.(serviceName) ?? ctx[serviceName] } catch { return null }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* workStore 可选解析:优先 foundation 的 os.works 能力面(内核 getter 返回
|
|
45
|
+
* work-store 服务或 null),回退 safeGet(ctx,'workStore')。两者皆缺席返回 null,
|
|
46
|
+
* 消费者自行降级内存态(语义与旧 safeGet 裸摸一致)。
|
|
47
|
+
* @param {object} ctx cordis 上下文
|
|
48
|
+
* @returns {object|null}
|
|
49
|
+
*/
|
|
50
|
+
export function resolveWorkStore(ctx) {
|
|
51
|
+
try {
|
|
52
|
+
const osSvc = safeGet(ctx, 'os')
|
|
53
|
+
const works = osSvc ? osSvc.works : null
|
|
54
|
+
if (works) return works
|
|
55
|
+
} catch { /* os.works getter 异常 → 落回裸摸兜底 */ }
|
|
56
|
+
return safeGet(ctx, 'workStore') ?? null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @typedef {object} SuiteHostSpec
|
|
61
|
+
* @property {string} ns 宿主名(如 'conductor-workbench'):__host__.name / portal id /
|
|
62
|
+
* 日志与警告前缀 / diag 文件名 `<ns>-diag.log`。
|
|
63
|
+
* @property {string} suite 套件短名(如 'conductor'):缺服务 bail 警告里的 `<suite>-suite`。
|
|
64
|
+
* @property {string} mountPath 默认挂载前缀(config.mountPath 可覆盖)。
|
|
65
|
+
* @property {string} title portal.recordActivity 标题。
|
|
66
|
+
* @property {Array<{name:string}>} descriptors 本套件描述符清单(释放时逐个 unregister)。
|
|
67
|
+
* @property {(api:HostApi & {extra:object}) => object} createWorkbench 工厂:返回
|
|
68
|
+
* { app, registry, publishDescriptors(baseUrl,{validate}), ... }(各套件 workbench.mjs)。
|
|
69
|
+
* @property {(api:HostApi) => object|false} [prepare] 断言后、建 workbench 前的差异装配
|
|
70
|
+
* (capyclaw 的 sessionPort/session-watch、conductor 的 discoverCapabilities 闸 + workStore)。
|
|
71
|
+
* 返回 false(或 {bail:true})= 放弃挂载(钩子内已自行 warn/diag),返回对象 = extra。
|
|
72
|
+
* @property {(api:HostApi & {workbench:object, extra:object, webServer:object|null}) => void} [afterListen]
|
|
73
|
+
* listen 之后、工具注册之前的钩子(rsp:manager.close disposer + bindToolsToSessionMode)。
|
|
74
|
+
* @property {(api:HostApi & {workbench:object, extra:object, webServer:object|null}) => void} [afterTools]
|
|
75
|
+
* 工具注册之后、描述符发布之前的钩子(rsp:startPersistent)。
|
|
76
|
+
* @property {(args:{webServer:object, workbench:object, extra:object, push:(d:Function)=>void, log:object}) => void} [routes]
|
|
77
|
+
* __host__ 之后的额外固定端点(capyclaw 的 agent-pending/host-pending)。仅 webServer.register 可用时调用。
|
|
78
|
+
* @property {(workbench:object, extra:object) => object} [hostInfo] __host__ 响应附加字段
|
|
79
|
+
* (请求时求值;capyclaw: available、conductor: persisted、rsp: protocol/status)。
|
|
80
|
+
* @property {boolean} [descriptorsRequired] true = 无条件 publish(conductor 已在 prepare
|
|
81
|
+
* 里因缺 discoverCapabilities bail,描述符面必然在场);缺省 = 探测
|
|
82
|
+
* registerCapabilityDescriptor,缺席 warn 跳过(capyclaw/rsp 降级语义)。
|
|
83
|
+
* @property {string} [diagTag] diag 消息短标签(缺省 ns 去掉 '-workbench' 后缀)。
|
|
84
|
+
* @property {(toolHost:object|null) => string} [diagApplyExtra] apply diag 行附加段
|
|
85
|
+
* (conductor 的 ` discover=...`)。
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 钩子公共参数面。
|
|
90
|
+
* @typedef {object} HostApi
|
|
91
|
+
* @property {object} ctx cordis 上下文
|
|
92
|
+
* @property {object} config 插件配置(mountPath/port/version/...)
|
|
93
|
+
* @property {string} mountPath 生效挂载前缀(config.mountPath || spec.mountPath)
|
|
94
|
+
* @property {object} toolHost 已断言 major 1 的工具宿主服务
|
|
95
|
+
* @property {object} serviceHost 已断言 major 1 的服务宿主服务
|
|
96
|
+
* @property {(ctx:object, name:string) => object|null} safeGet 服务懒解析
|
|
97
|
+
* @property {{info:Function, warn:Function}} log ctx.logger 优先、console 兜底
|
|
98
|
+
* @property {(m:string) => void} diag env 门控诊断日志(默认不写盘)
|
|
99
|
+
* @property {(d:Function) => void} push 压入公共 disposer 栈(逆序释放)
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 挂载一个套件工作台:返回 disposer(与 cordis apply 契约一致)。
|
|
104
|
+
* 任何失败都降级为 warn + 安全 disposer,绝不把路由冲突/服务缺席升级成宿主崩溃。
|
|
105
|
+
* @param {object} ctx cordis 上下文
|
|
106
|
+
* @param {object} [config] 插件配置
|
|
107
|
+
* @param {SuiteHostSpec} spec 套件差异规格
|
|
108
|
+
* @returns {() => void} disposer(逆序释放全部已登记资源;重复调用安全)
|
|
109
|
+
*/
|
|
110
|
+
export function mountSuiteWorkbench(ctx, config = {}, spec) {
|
|
111
|
+
const { ns, suite, title, descriptors = [], createWorkbench } = spec
|
|
112
|
+
const tag = spec.diagTag || String(ns || '').replace(/-workbench$/, '')
|
|
113
|
+
/* 诊断日志默认关闭;设 CAPYCLAW_WB_DIAG=1 时写到系统临时目录(不硬编码任何本机路径)。 */
|
|
114
|
+
const DIAG_LOG = process.env.CAPYCLAW_WB_DIAG ? path.join(os.tmpdir(), `${ns}-diag.log`) : null
|
|
115
|
+
const diag = (m) => { if (!DIAG_LOG) return; try { fs.appendFileSync(DIAG_LOG, `[${new Date().toISOString()}] ${m}\n`) } catch { /* 忽略 */ } }
|
|
116
|
+
const log = {
|
|
117
|
+
info: (...a) => (ctx.logger?.info ? ctx.logger.info(...a) : console.log(`[${tag}]`, ...a)),
|
|
118
|
+
warn: (...a) => (ctx.logger?.warn ? ctx.logger.warn(...a) : console.warn(`[${tag}]`, ...a)),
|
|
119
|
+
}
|
|
120
|
+
const mountPath = config.mountPath || spec.mountPath
|
|
121
|
+
const disposers = []
|
|
122
|
+
const push = (d) => { if (typeof d === 'function') disposers.push(d) }
|
|
123
|
+
/* 统一台账(2026-11-25):挂载/退让/降级/失败/释放状态追加到 profile 台账,
|
|
124
|
+
* best-effort 绝不反噬挂载;凡走 mountSuiteWorkbench 的套件统一覆盖。 */
|
|
125
|
+
const ledgerFile = ledgerFileFor(safeGet(ctx, 'profileContext')?.dir || process.env.DSH_PROFILE_DIR || null)
|
|
126
|
+
const record = (action, ok, extra = {}) => appendLedger({ source: 'suite-kit', name: ns, suite, version: config.version || null, phase: 'activate', action, ok, mountPath, ...extra }, { file: ledgerFile })
|
|
127
|
+
// splice(0) 清空栈再逆序:首次释放顺序与手写时代一致,重复释放是真 no-op
|
|
128
|
+
// (原 disposers.reverse() 原地反转,二次调用会重跑——与「忽略重复释放」注释意图相悖)。
|
|
129
|
+
let released = false
|
|
130
|
+
const releaseAll = () => {
|
|
131
|
+
if (released) return
|
|
132
|
+
released = true
|
|
133
|
+
record('disposed', true, { phase: 'dispose' })
|
|
134
|
+
for (const d of disposers.splice(0).reverse()) { try { d() } catch { /* 忽略重复释放 */ } }
|
|
135
|
+
}
|
|
136
|
+
const noop = () => {}
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
if (!ns || !suite || !mountPath || !title || typeof createWorkbench !== 'function') {
|
|
140
|
+
throw new Error('mountSuiteWorkbench: spec 需要 ns/suite/mountPath/title/createWorkbench')
|
|
141
|
+
}
|
|
142
|
+
const toolHost = safeGet(ctx, 'toolHost')
|
|
143
|
+
const serviceHost = safeGet(ctx, 'serviceHost')
|
|
144
|
+
diag(`${tag} apply: toolHost=${!!toolHost} serviceHost=${!!serviceHost} webServer=${!!safeGet(ctx, 'webServer')} reflect=${!!ctx.reflect}${spec.diagApplyExtra ? spec.diagApplyExtra(toolHost) : ''}`)
|
|
145
|
+
if (!toolHost || !serviceHost) {
|
|
146
|
+
diag(`${tag} BAIL: missing toolHost/serviceHost`)
|
|
147
|
+
log.warn(`缺少 toolHost/serviceHost 公共服务,${suite}-suite 未激活(请安装对应基础套件)`)
|
|
148
|
+
record('bail-missing-services', false, { code: 'missing-services', message: '缺少 toolHost/serviceHost 公共服务' })
|
|
149
|
+
return noop
|
|
150
|
+
}
|
|
151
|
+
assertServiceApi(toolHost, { name: 'toolHost', major: 1 })
|
|
152
|
+
assertServiceApi(serviceHost, { name: 'serviceHost', major: 1 })
|
|
153
|
+
|
|
154
|
+
/** @type {HostApi} */
|
|
155
|
+
const api = { ctx, config, mountPath, toolHost, serviceHost, safeGet, log, diag, push }
|
|
156
|
+
let extra = {}
|
|
157
|
+
if (spec.prepare) {
|
|
158
|
+
const prepared = spec.prepare(api)
|
|
159
|
+
if (prepared === false || (prepared && prepared.bail === true)) {
|
|
160
|
+
record('bail-prepare', false, { code: 'prepare-bail' })
|
|
161
|
+
return noop
|
|
162
|
+
}
|
|
163
|
+
if (prepared && typeof prepared === 'object') extra = prepared
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const workbench = createWorkbench({ ...api, extra })
|
|
167
|
+
|
|
168
|
+
const webServer = safeGet(ctx, 'webServer')
|
|
169
|
+
|
|
170
|
+
// 前缀路由是全局唯一的(dsh-host-webserver 的 register 遇到同 (kind,path) 直接抛)。
|
|
171
|
+
// service-host 的 app.listen 是 async:冲突会变成 rejected Promise,而不是同步抛错。
|
|
172
|
+
// 不 await、也不 .catch 的话,冲突逃出外层 try/catch,被 cordis 当成 load failure
|
|
173
|
+
// 杀掉整个宿主(2026-11-19 两次:安全模式回滚把用户 patch 层清空)。
|
|
174
|
+
// 先探一次占位,冲突就只警告并退出本条目,绝不把路由冲突升级成宿主崩溃。
|
|
175
|
+
if (webServer && typeof webServer.register === 'function') {
|
|
176
|
+
let taken = false
|
|
177
|
+
try {
|
|
178
|
+
const probe = webServer.register({ kind: 'prefix', path: mountPath, handler: () => {} })
|
|
179
|
+
if (typeof probe === 'function') probe()
|
|
180
|
+
} catch {
|
|
181
|
+
taken = true
|
|
182
|
+
}
|
|
183
|
+
if (taken) {
|
|
184
|
+
diag(`${tag} BAIL: prefix ${mountPath} already registered`)
|
|
185
|
+
log.warn(`${ns}: 路由前缀 ${mountPath} 已被占用,本条目不挂载(不影响其它插件)`)
|
|
186
|
+
record('bail-prefix-taken', false, { code: 'prefix-taken', message: `路由前缀 ${mountPath} 已被占用` })
|
|
187
|
+
return noop
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const listenOpts = webServer ? { webServer, basePath: mountPath } : { port: config.port || 0 }
|
|
192
|
+
const listening = workbench.app.listen(listenOpts)
|
|
193
|
+
// 兜底:即使上面的探测有竞态,也把 rejection 收在这里,不让它变成未处理拒绝。
|
|
194
|
+
if (listening && typeof listening.catch === 'function') {
|
|
195
|
+
listening.catch((err) => {
|
|
196
|
+
diag(`${tag} listen rejected: ${err?.stack || err}`)
|
|
197
|
+
log.warn(`${ns}: 挂载 ${mountPath} 失败,本条目不生效:`, err?.message || err)
|
|
198
|
+
record('listen-rejected', false, { code: 'listen-rejected', message: String(err?.message || err), stackTop: err?.stack || null })
|
|
199
|
+
try { workbench.app.close() } catch { /* 忽略 */ }
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
push(() => workbench.app.close())
|
|
203
|
+
|
|
204
|
+
if (spec.afterListen) spec.afterListen({ ...api, workbench, extra, webServer })
|
|
205
|
+
|
|
206
|
+
// 原生工具面:safeGet 解析 tools 服务后传平对象,避免 cordis 未 inject 禁访问 ctx.tools。
|
|
207
|
+
const tools = safeGet(ctx, 'tools')
|
|
208
|
+
if (tools?.register) {
|
|
209
|
+
const { registerWithDsh } = toolHost
|
|
210
|
+
push(registerWithDsh({ tools }, workbench.registry))
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (spec.afterTools) spec.afterTools({ ...api, workbench, extra, webServer })
|
|
214
|
+
|
|
215
|
+
// 能力描述符 + 调用地址 → 公共注册表(供 conductor 发现)。
|
|
216
|
+
if (spec.descriptorsRequired || typeof toolHost.registerCapabilityDescriptor === 'function') {
|
|
217
|
+
workbench.publishDescriptors(workbench.app.url, { validate: validateCapabilityDescriptor })
|
|
218
|
+
push(() => { for (const d of descriptors) toolHost.unregisterCapabilityDescriptor?.(d.name) })
|
|
219
|
+
} else {
|
|
220
|
+
log.warn(`toolHost 无描述符面(需 >=0.2.0):跳过能力注册,conductor 将无法发现 ${suite}`)
|
|
221
|
+
record('degraded-no-descriptors', true, { degraded: true, code: 'no-descriptor-face', message: 'toolHost 无描述符面,跳过能力注册' })
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// 自检端点。
|
|
225
|
+
if (webServer?.register) {
|
|
226
|
+
const off = webServer.register({
|
|
227
|
+
kind: 'exact', path: `${mountPath}/__host__`,
|
|
228
|
+
handler: (req, res) => {
|
|
229
|
+
res.writeHead(200, { 'content-type': 'application/json' })
|
|
230
|
+
res.end(JSON.stringify({ ok: true, name: ns, mountPath, url: workbench.app.url, ...(spec.hostInfo ? spec.hostInfo(workbench, extra) : {}) }))
|
|
231
|
+
},
|
|
232
|
+
})
|
|
233
|
+
push(off)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (spec.routes && webServer?.register) spec.routes({ webServer, workbench, extra, push, log })
|
|
237
|
+
|
|
238
|
+
const portal = safeGet(ctx, 'portal')
|
|
239
|
+
portal?.recordActivity?.({ id: ns, url: workbench.app.url, title, kind: 'service' })
|
|
240
|
+
|
|
241
|
+
log.info(`${ns} 已挂载 ${mountPath} → ${workbench.app.url}`)
|
|
242
|
+
diag(`${tag} MOUNTED ${mountPath} → ${workbench.app.url}`)
|
|
243
|
+
record('mounted', true, { url: workbench.app.url })
|
|
244
|
+
return releaseAll
|
|
245
|
+
} catch (err) {
|
|
246
|
+
diag(`${tag} ERROR: ${err?.stack || err}`)
|
|
247
|
+
log.warn(`${ns} 激活失败:`, err?.stack || err)
|
|
248
|
+
record('activate-error', false, { code: 'activate-error', message: String(err?.message || err), stackTop: err?.stack || null })
|
|
249
|
+
return releaseAll
|
|
250
|
+
}
|
|
251
|
+
}
|
|
@@ -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.3",
|
|
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.3",
|
|
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.2",
|
|
4
4
|
"description": "真离线版 ddr0 + 作品/会话统一持久化地基:接口快照与作品代码打包在插件内,断网也能打开;本地库稳定存储作品与会话,可管理/查看/继续对话;本地 work-store(SQLite)生成物按 ddr0 作品契约进画廊,PPT 用 PPTist 装饰器只读放映;ETag/304 协商缓存+列表瘦身提速 by CapyClaw",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./plugin.mjs",
|
package/plugin.mjs
CHANGED
|
@@ -50,6 +50,11 @@ function resolveConfig(config = {}) {
|
|
|
50
50
|
// env DSH_OFFLINE_DDR0_STORAGE 可覆盖;非法值回落 workstore 并告警在装配处。
|
|
51
51
|
const raw = String(config.storage || process.env.DSH_OFFLINE_DDR0_STORAGE || 'workstore').toLowerCase()
|
|
52
52
|
const storage = raw === 'json' ? 'json' : 'workstore'
|
|
53
|
+
// standalone:显式声明离线单装(无宿主 workStore 服务)才允许画廊桥自开单实例(V2-1)。
|
|
54
|
+
// 缺省 false=宿主内,一律消费注入的共享服务;服务缺席时降级为空,不私开第二实例。
|
|
55
|
+
// env DSH_OFFLINE_DDR0_STANDALONE=1/true/yes 可覆盖。
|
|
56
|
+
const standalone = config.standalone === true
|
|
57
|
+
|| /^(1|true|yes)$/i.test(String(process.env.DSH_OFFLINE_DDR0_STANDALONE || ''))
|
|
53
58
|
// 主站同步(手动触发,离线优先):源站直连参数 + 可选会话令牌。
|
|
54
59
|
const syncCfg = (config && typeof config.sync === 'object' && config.sync) || {}
|
|
55
60
|
const sync = {
|
|
@@ -64,6 +69,7 @@ function resolveConfig(config = {}) {
|
|
|
64
69
|
).replace(/\/+$/, ''),
|
|
65
70
|
sitePath: String(config.sitePath || DEFAULT_SITE_PATH).replace(/\/+$/, ''),
|
|
66
71
|
storage,
|
|
72
|
+
standalone,
|
|
67
73
|
sync,
|
|
68
74
|
}
|
|
69
75
|
}
|
|
@@ -139,12 +145,12 @@ export const { name, inject, apply } = createPlugin({
|
|
|
139
145
|
const mirrorIndex = createMirrorIndex(mirrorDir, { log })
|
|
140
146
|
// 本地作品库(其它会话投递的内容)持久化在 profile plugin-data。
|
|
141
147
|
// 装配层只面向 LocalWorkRepository 契约(lib/repository.mjs),JSON↔work-store 切换零改路由。
|
|
142
|
-
const { storage } = resolveConfig(config)
|
|
148
|
+
const { storage, standalone } = resolveConfig(config)
|
|
143
149
|
const storeDir = resolveStoreDir()
|
|
144
|
-
// work-store 公共服务(
|
|
150
|
+
// work-store 公共服务(workStore):跨隔离安全探测;不在场给 null。
|
|
145
151
|
let workStoreService = null
|
|
146
152
|
try { workStoreService = (typeof service === 'function' && service('workStore')) || null } catch { /* 服务不在场 */ }
|
|
147
|
-
// asset-service 公共服务(
|
|
153
|
+
// asset-service 公共服务(assets):媒体仓优先接共享池/共享工厂;不在场给 null(私有仓兜底)。
|
|
148
154
|
let assetsService = null
|
|
149
155
|
try { assetsService = (typeof service === 'function' && service('assets')) || null } catch { /* 服务不在场 */ }
|
|
150
156
|
|
|
@@ -159,13 +165,15 @@ export const { name, inject, apply } = createPlugin({
|
|
|
159
165
|
// 装配决策(迁移/降级/回滚)在 lib/repository.mjs,可独立单测。
|
|
160
166
|
const { repo } = resolveLocalRepository({ storage, workStoreService, dir: storeDir, log })
|
|
161
167
|
// 本地 work-store(SQLite)作品源:只读、免登录,把 PPT 等本地生成物按 ddr0
|
|
162
|
-
//
|
|
168
|
+
// 作品契约并进画廊。宿主内注入共享服务(不自开句柄、不负责 close,V2-1);
|
|
169
|
+
// 服务缺席时降级为空,仅显式 standalone(离线单装)才自开只读单实例。
|
|
163
170
|
const wsSource = createWorkStoreSource({
|
|
164
171
|
dir: repo.dir,
|
|
165
172
|
mirrorDir,
|
|
166
173
|
log,
|
|
167
174
|
index: mirrorIndex,
|
|
168
175
|
store: workStoreService || undefined,
|
|
176
|
+
standalone,
|
|
169
177
|
})
|
|
170
178
|
const mirror = createMirror(mirrorDir, {
|
|
171
179
|
log,
|
|
@@ -179,7 +187,7 @@ export const { name, inject, apply } = createPlugin({
|
|
|
179
187
|
|
|
180
188
|
// 本地媒体资产仓(内容寻址,sha256 去重):同步时把外部/源站媒体物化进来,
|
|
181
189
|
// 本地直出路由先于 mirror——外部源失效不影响离线放映。两种存储模式都可用。
|
|
182
|
-
// 套件化复用公共基建:优先共享
|
|
190
|
+
// 套件化复用公共基建:优先共享 assets 服务(store/工厂),无服务时私有仓兜底(离线优先)。
|
|
183
191
|
const mediaStore = resolveMediaStore({ assets: assetsService, dir: path.join(storeDir, 'media-assets'), log })
|
|
184
192
|
const mediaHandler = createMediaHandler({ store: mediaStore, log })
|
|
185
193
|
|