@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,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 静态文件服务公共核心(P2-13a)。
|
|
3
|
+
*
|
|
4
|
+
* service-host 与 editor-host 各有一套静态文件服务,其中「路径穿越防护 / 挂载前缀
|
|
5
|
+
* 归一与命中 / 相对路径解码 / files 显式映射 / 基础响应头」这几段逻辑逐字重复。
|
|
6
|
+
* 这里把它们收敛成一组纯函数作为单一真源,两个宿主都 import 本文件,不再各写一份。
|
|
7
|
+
*
|
|
8
|
+
* 边界(刻意不收敛的部分):本文件只做「无 IO 的路径/头部计算」,不碰响应政策。
|
|
9
|
+
* 两宿主的行为差异必须各自保留——
|
|
10
|
+
* - 畸形百分号编码:service-host 回 400,editor-host 交还路由链(return false);
|
|
11
|
+
* - 目录入口补尾斜杠 301、ETag/gzip/304/vary:仅 editor-host;
|
|
12
|
+
* - content-type 取值:service-host 用 mimeFor(请求 rel) + explicitType,
|
|
13
|
+
* editor-host 用 mimeFor(落盘文件路径);
|
|
14
|
+
* - 读盘策略:service-host 每次 readFileSync,editor-host 走 (size,mtime) 缓存。
|
|
15
|
+
* 因此 decodeStaticRel 畸形时返回 null(而非抛错/替宿主回响应),由调用方决定 400 还是放行。
|
|
16
|
+
*
|
|
17
|
+
* 只依赖 node 内置(node:path),不 import 本包其它文件,不成环(与 util/http.mjs 同风格)。
|
|
18
|
+
*/
|
|
19
|
+
import path from 'node:path'
|
|
20
|
+
|
|
21
|
+
/** 路径穿越防护:只允许落在 root 内(含 root 自身),越界返回 null。两宿主共用。 */
|
|
22
|
+
export function safeJoin(root, rel) {
|
|
23
|
+
const target = path.resolve(root, `.${path.sep}${rel}`)
|
|
24
|
+
const base = path.resolve(root)
|
|
25
|
+
return target === base || target.startsWith(base + path.sep) ? target : null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** 挂载前缀归一:'/' → ''(挂全部);其余去掉尾斜杠。空/缺省按 '' 处理。 */
|
|
29
|
+
export function cleanStaticPrefix(prefix) {
|
|
30
|
+
return prefix === '/' ? '' : String(prefix || '').replace(/\/+$/, '')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 前缀命中:空前缀命中一切;非空须精确等于前缀或其子路径。 */
|
|
34
|
+
export function staticPrefixHit(pathname, prefix) {
|
|
35
|
+
return !prefix || pathname === prefix || pathname.startsWith(prefix + '/')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 去掉挂载前缀后的原始相对路径(未解码)。 */
|
|
39
|
+
export function staticRelRaw(pathname, prefix) {
|
|
40
|
+
return prefix ? pathname.slice(prefix.length) : pathname
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 解码相对路径:空/'/' 落到 index;其余去掉 leading 斜杠后 decodeURIComponent。
|
|
45
|
+
* 畸形百分号编码(URIError)返回 null——由宿主决定回 400(service-host)还是
|
|
46
|
+
* 交还路由链(editor-host),本核心不替宿主做响应政策。
|
|
47
|
+
*/
|
|
48
|
+
export function decodeStaticRel(relRaw, index = 'index.html') {
|
|
49
|
+
try {
|
|
50
|
+
return relRaw === '' || relRaw === '/' ? index : decodeURIComponent(relRaw.replace(/^\/+/, ''))
|
|
51
|
+
} catch {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** files 显式映射查表:relRaw 为空时用 '/' 键;未命中返回 null(宿主交还路由链)。 */
|
|
57
|
+
export function staticFileHit(files, relRaw) {
|
|
58
|
+
if (!files) return null
|
|
59
|
+
return files[relRaw === '' ? '/' : relRaw] || files[relRaw] || null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 映射条目 → [文件名, 显式 content-type(可空)]。字符串条目无显式 type。 */
|
|
63
|
+
export function staticHitNameType(hit) {
|
|
64
|
+
return Array.isArray(hit) ? [hit[0], hit[1]] : [hit, undefined]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 静态 200 基础响应头:content-type/length + 安全与缓存政策(两宿主一致的五项)。
|
|
69
|
+
* no-cache = 允许缓存但每次回源校验;editor-host 会在此之上追加 etag/vary。
|
|
70
|
+
*/
|
|
71
|
+
export function staticBaseHeaders(type, length) {
|
|
72
|
+
return {
|
|
73
|
+
'content-type': type,
|
|
74
|
+
'content-length': length,
|
|
75
|
+
'x-content-type-options': 'nosniff',
|
|
76
|
+
'referrer-policy': 'no-referrer',
|
|
77
|
+
'cache-control': 'no-cache',
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -575,7 +575,7 @@ export class WorkspaceClient {
|
|
|
575
575
|
|
|
576
576
|
/** 插件的 JournalStore 持久化接口 → 中间层 workspace。 */
|
|
577
577
|
export class WorkspaceBackend {
|
|
578
|
-
constructor({ client, workId = 'main', journalPath = null }) {
|
|
578
|
+
constructor({ client, workId = 'main', journalPath = null, project = null }) {
|
|
579
579
|
/* 结构化契约:workspace-service 可能来自另一份 kit 快照。 */
|
|
580
580
|
if (!client || typeof client.put !== 'function' || typeof client.getJson !== 'function') {
|
|
581
581
|
throw new Error('WorkspaceBackend 需要 WorkspaceClient 兼容实现')
|
|
@@ -583,6 +583,9 @@ export class WorkspaceBackend {
|
|
|
583
583
|
this.client = client
|
|
584
584
|
this.workId = workId
|
|
585
585
|
this.journalPath = journalPath || null
|
|
586
|
+
/* checkpoint 列表投影(形状声明):内核只产出通用信封,业务字段(如 PPT 的 slides)
|
|
587
|
+
* 由套件适配层传入 project(payload, base) 叠加。缺省纯信封,不硬编码任何业务名词。 */
|
|
588
|
+
this.project = typeof project === 'function' ? project : null
|
|
586
589
|
this.stateKey = 'state.json'
|
|
587
590
|
this.journalKey = 'journal.jsonl'
|
|
588
591
|
this.checkpointPrefix = 'checkpoints/'
|
|
@@ -624,23 +627,27 @@ export class WorkspaceBackend {
|
|
|
624
627
|
return { name, createdAt: payload.createdAt, meta: payload.meta || {} }
|
|
625
628
|
}
|
|
626
629
|
|
|
627
|
-
listCheckpoints() {
|
|
630
|
+
listCheckpoints(opts = {}) {
|
|
631
|
+
const project = typeof opts.project === 'function' ? opts.project : this.project
|
|
628
632
|
return this.client.list(this.workId)
|
|
629
633
|
.filter((item) => item.key.startsWith(this.checkpointPrefix) && item.key.endsWith('.json'))
|
|
630
634
|
.map((item) => {
|
|
631
635
|
try {
|
|
632
636
|
const payload = this.client.getJson(this.workId, item.key)
|
|
633
637
|
if (!payload) return null
|
|
634
|
-
|
|
638
|
+
/* 通用会话信封:不含任何业务名词(slides/deck 等)。业务字段经 project 叠加。
|
|
639
|
+
* 约定与 document-workbench projectCheckpoint 一致:project(payload, base) 只返回
|
|
640
|
+
* 「扩展字段」,由 backend 合并 base({...base, ...extra}),保证 name/createdAt/meta 不丢。 */
|
|
641
|
+
const base = {
|
|
635
642
|
name: payload.name,
|
|
636
643
|
seq: payload.seq,
|
|
637
644
|
appliedSeq: payload.appliedSeq,
|
|
638
645
|
pending: !!payload.pending,
|
|
639
646
|
title: payload.title,
|
|
640
|
-
slides: payload.slides,
|
|
641
647
|
createdAt: payload.createdAt,
|
|
642
648
|
meta: payload.meta || {},
|
|
643
649
|
}
|
|
650
|
+
return project ? { ...base, ...project(payload, base) } : base
|
|
644
651
|
} catch { return null }
|
|
645
652
|
})
|
|
646
653
|
.filter(Boolean)
|
|
@@ -650,7 +657,8 @@ export class WorkspaceBackend {
|
|
|
650
657
|
readCheckpoint(name) {
|
|
651
658
|
const key = `${this.checkpointPrefix}${name}.json`
|
|
652
659
|
const payload = this.client.getJson(this.workId, key, null)
|
|
653
|
-
|
|
660
|
+
/* 只校验载荷存在;业务形状(如 PPT 的 deck)由套件适配层 / DocumentSession 的 documentKey 校验。 */
|
|
661
|
+
if (!payload) throw new Error('checkpoint 内容损坏: ' + name)
|
|
654
662
|
return payload
|
|
655
663
|
}
|
|
656
664
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capyclaw/service-host",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "DSH 公共服务宿主插件:统一 HTTP 路由、健康检查、指标、单实例锁、端口复用与静态资源,向插件提供 ctx.serviceHost。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/host.mjs",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"test": "node --test test/*.test.mjs"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@capyclaw/plugin-kit": "^0.2.
|
|
48
|
+
"@capyclaw/plugin-kit": "^0.2.9",
|
|
49
49
|
"@capyclaw/foundation": "^0.1.1"
|
|
50
50
|
},
|
|
51
51
|
"repository": {
|
|
@@ -19,6 +19,8 @@ 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'
|
|
23
|
+
import { appendLedger, ledgerFileFor } from '@capyclaw/plugin-kit/ledger'
|
|
22
24
|
import { tuning } from './tuning.mjs'
|
|
23
25
|
|
|
24
26
|
function slugOf(id) {
|
|
@@ -133,11 +135,7 @@ async function probeExisting(origin, healthPath, id) {
|
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
137
|
|
|
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
|
-
}
|
|
138
|
+
/* safeJoin 已收敛到 @capyclaw/plugin-kit/service/static(P2-13a 静态公共核心)。 */
|
|
141
139
|
|
|
142
140
|
/**
|
|
143
141
|
* @param {{
|
|
@@ -169,6 +167,11 @@ export function createServiceApp(options = {}) {
|
|
|
169
167
|
let closed = false
|
|
170
168
|
let workdir = ''
|
|
171
169
|
|
|
170
|
+
/* 统一台账(2026-11-25):服务生命周期/运行时错误追加到 profile 台账,best-effort
|
|
171
|
+
* 绝不反噬服务;listenOptions.ledgerFile 可覆盖(suite-kit 传自己解析的路径)。 */
|
|
172
|
+
const defaultLedgerFile = ledgerFileFor(process.env.DSH_PROFILE_DIR || null)
|
|
173
|
+
const record = (action, ok, extra = {}, file = defaultLedgerFile) => appendLedger({ source: 'service-host', name: id, version, phase: 'runtime', action, ok, ...extra }, { file })
|
|
174
|
+
|
|
172
175
|
const app = {
|
|
173
176
|
id,
|
|
174
177
|
title,
|
|
@@ -204,20 +207,28 @@ export function createServiceApp(options = {}) {
|
|
|
204
207
|
})
|
|
205
208
|
},
|
|
206
209
|
|
|
207
|
-
/** 静态目录挂载。files 可给显式映射:{ '/': ['index.html','text/html'] }。
|
|
210
|
+
/** 静态目录挂载。files 可给显式映射:{ '/': ['index.html','text/html'] }。
|
|
211
|
+
* 路径/头部计算走 @capyclaw/plugin-kit/service/static 公共核心(P2-13a);
|
|
212
|
+
* 本宿主保留自己的响应政策:畸形编码回 400、content-type 取 mimeFor(请求 rel)、每次读盘。 */
|
|
208
213
|
static(prefix, dir, { files = null, index = 'index.html' } = {}) {
|
|
209
|
-
const cleanPrefix = prefix
|
|
214
|
+
const cleanPrefix = cleanStaticPrefix(prefix)
|
|
210
215
|
return app.use((req, res, u) => {
|
|
211
216
|
if (req.method !== 'GET' && req.method !== 'HEAD') return false
|
|
212
|
-
if (
|
|
213
|
-
const relRaw =
|
|
214
|
-
const rel = relRaw
|
|
217
|
+
if (!staticPrefixHit(u.pathname, cleanPrefix)) return false
|
|
218
|
+
const relRaw = staticRelRaw(u.pathname, cleanPrefix)
|
|
219
|
+
const rel = decodeStaticRel(relRaw, index)
|
|
220
|
+
if (rel === null) {
|
|
221
|
+
/* 畸形百分号编码 → URIError,不包会冒成 500;客户端错误回 400。 */
|
|
222
|
+
res.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' })
|
|
223
|
+
res.end(req.method === 'HEAD' ? undefined : 'malformed path encoding')
|
|
224
|
+
return true
|
|
225
|
+
}
|
|
215
226
|
let file = null
|
|
216
227
|
let type = mimeFor(rel)
|
|
217
228
|
if (files) {
|
|
218
|
-
const hit = files
|
|
229
|
+
const hit = staticFileHit(files, relRaw)
|
|
219
230
|
if (!hit) return false
|
|
220
|
-
const [name, explicitType] =
|
|
231
|
+
const [name, explicitType] = staticHitNameType(hit)
|
|
221
232
|
file = safeJoin(dir, name)
|
|
222
233
|
type = explicitType || type
|
|
223
234
|
} else {
|
|
@@ -226,13 +237,7 @@ export function createServiceApp(options = {}) {
|
|
|
226
237
|
if (!file) return false
|
|
227
238
|
try {
|
|
228
239
|
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
|
-
})
|
|
240
|
+
res.writeHead(200, staticBaseHeaders(type, data.length))
|
|
236
241
|
res.end(req.method === 'HEAD' ? undefined : data)
|
|
237
242
|
return true
|
|
238
243
|
} catch {
|
|
@@ -362,13 +367,25 @@ export function createServiceApp(options = {}) {
|
|
|
362
367
|
const webServer = listenOptions.webServer
|
|
363
368
|
if (webServer && typeof webServer.register === 'function') {
|
|
364
369
|
const prefix = basePath || `/plugins/${id}`
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
+
try {
|
|
371
|
+
embeddedDispose = webServer.register({
|
|
372
|
+
kind: 'prefix',
|
|
373
|
+
path: prefix,
|
|
374
|
+
handler: (req, res) => Promise.resolve(app.dispatch(req, res, prefix)).catch((error) => {
|
|
375
|
+
record('dispatch-error', false, { code: 'dispatch-error', message: String((error && error.message) || error), stackTop: (error && error.stack) || null, url: req.url }, listenOptions.ledgerFile)
|
|
376
|
+
try {
|
|
377
|
+
if (!res.headersSent) send(req, res, 500, { ok: false, error: String((error && error.message) || error) })
|
|
378
|
+
else res.destroy()
|
|
379
|
+
} catch { /* 连接已断开 */ }
|
|
380
|
+
}),
|
|
381
|
+
})
|
|
382
|
+
} catch (error) {
|
|
383
|
+
record('listen-error', false, { code: 'register-conflict', message: String((error && error.message) || error), stackTop: (error && error.stack) || null, mountPath: prefix }, listenOptions.ledgerFile)
|
|
384
|
+
throw error
|
|
385
|
+
}
|
|
370
386
|
listeningPort = Number(webServer.port) || 0
|
|
371
387
|
url = `http://127.0.0.1:${listeningPort}${prefix}`
|
|
388
|
+
record('listen', true, { mode: 'embedded', url, mountPath: prefix }, listenOptions.ledgerFile)
|
|
372
389
|
return { url, port: listeningPort, reused: false, mode: 'embedded', stop: app.close }
|
|
373
390
|
}
|
|
374
391
|
|
|
@@ -391,10 +408,12 @@ export function createServiceApp(options = {}) {
|
|
|
391
408
|
if (existing && sameContract && sameVersion && sameWorkdir) {
|
|
392
409
|
listeningPort = port
|
|
393
410
|
url = `http://127.0.0.1:${port}${publicBasePath}`
|
|
411
|
+
record('listen', true, { mode: 'standalone', reused: true, url, port }, listenOptions.ledgerFile)
|
|
394
412
|
return { url, port, reused: true, mode: 'standalone', stop: async () => {} }
|
|
395
413
|
}
|
|
396
414
|
if (existing && !(sameContract && sameVersion && sameWorkdir)) {
|
|
397
415
|
const old = `pid ${existing.pid || '?'},version ${existing.version || '?'},contract ${existing.contractVersion || '?'},workdir ${existing.workdir || '?'}`
|
|
416
|
+
record('listen-error', false, { code: 'identity-conflict', message: `端口 ${port} 被不同身份实例占用(${old})`, mountPath: publicBasePath }, listenOptions.ledgerFile)
|
|
398
417
|
throw new Error(
|
|
399
418
|
`${id} 端口 ${port} 被不同身份的实例占用(${old};当前 ${version} / ${contractVersion} / ${workdir})。` +
|
|
400
419
|
`为避免“新套件 + 旧进程”或“同版本 + 错数据目录”的假启动,已拒绝复用:请结束 ${existing.pid || '该'} 进程或重启 DSH 后再启动。`,
|
|
@@ -404,6 +423,7 @@ export function createServiceApp(options = {}) {
|
|
|
404
423
|
|
|
405
424
|
const lock = await acquireLock(lockFile, { healthPath, id })
|
|
406
425
|
if (!lock) {
|
|
426
|
+
record('listen-error', false, { code: 'lock-held', message: `已有另一个实例在运行: ${lockFile}` }, listenOptions.ledgerFile)
|
|
407
427
|
throw new Error(`${id} 已有另一个实例在运行;如确认没有,请删除锁文件: ${lockFile}`)
|
|
408
428
|
}
|
|
409
429
|
|
|
@@ -422,12 +442,14 @@ export function createServiceApp(options = {}) {
|
|
|
422
442
|
lastError = error
|
|
423
443
|
if (port === 0 || strictPort || attempt === scanLimit) {
|
|
424
444
|
releaseLock(lock)
|
|
445
|
+
record('listen-error', false, { code: 'port-unavailable', message: `端口 ${tryPort} 不可用: ${(error && error.message) || error}` }, listenOptions.ledgerFile)
|
|
425
446
|
throw new Error(`端口 ${tryPort} 不可用${strictPort ? '(strictPort)' : ''}: ${(error && error.message) || error}`)
|
|
426
447
|
}
|
|
427
448
|
}
|
|
428
449
|
}
|
|
429
450
|
if (!server) {
|
|
430
451
|
releaseLock(lock)
|
|
452
|
+
record('listen-error', false, { code: 'port-unavailable', message: String((lastError && lastError.message) || lastError || '无法监听端口') }, listenOptions.ledgerFile)
|
|
431
453
|
throw lastError || new Error('无法监听端口')
|
|
432
454
|
}
|
|
433
455
|
|
|
@@ -437,6 +459,7 @@ export function createServiceApp(options = {}) {
|
|
|
437
459
|
try { server.close() } catch { /* 忽略 */ }
|
|
438
460
|
server = null
|
|
439
461
|
releaseLock(lock)
|
|
462
|
+
record('listen-error', false, { code: 'write-lock-failed', message: String((error && error.message) || error), stackTop: (error && error.stack) || null }, listenOptions.ledgerFile)
|
|
440
463
|
throw error
|
|
441
464
|
}
|
|
442
465
|
listeningPort = actualPort
|
|
@@ -444,6 +467,7 @@ export function createServiceApp(options = {}) {
|
|
|
444
467
|
|
|
445
468
|
server.on('request', (req, res) => {
|
|
446
469
|
Promise.resolve(app.dispatch(req, res, publicBasePath)).catch((error) => {
|
|
470
|
+
record('dispatch-error', false, { code: 'dispatch-error', message: String((error && error.message) || error), stackTop: (error && error.stack) || null, url: req.url })
|
|
447
471
|
try {
|
|
448
472
|
if (!res.headersSent) send(req, res, 500, { ok: false, error: String((error && error.message) || error) })
|
|
449
473
|
else res.destroy()
|
|
@@ -465,12 +489,14 @@ export function createServiceApp(options = {}) {
|
|
|
465
489
|
|
|
466
490
|
app._lock = lock
|
|
467
491
|
app._discoveryFile = discoveryFile
|
|
492
|
+
record('listen', true, { mode: 'standalone', url, port: actualPort }, listenOptions.ledgerFile)
|
|
468
493
|
return { url, port: actualPort, reused: false, mode: 'standalone', stop: app.close }
|
|
469
494
|
},
|
|
470
495
|
|
|
471
496
|
async close() {
|
|
472
497
|
if (closed) return
|
|
473
498
|
closed = true
|
|
499
|
+
record('closed', true, { phase: 'dispose', mode: embeddedDispose ? 'embedded' : 'standalone' })
|
|
474
500
|
if (embeddedDispose) {
|
|
475
501
|
try { embeddedDispose() } catch { /* 忽略 */ }
|
|
476
502
|
embeddedDispose = null
|
|
@@ -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.3",
|
|
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.9"
|
|
44
|
+
},
|
|
41
45
|
"license": "MIT",
|
|
42
46
|
"publishConfig": {
|
|
43
47
|
"access": "public"
|