@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.
Files changed (108) hide show
  1. package/composition.lock.json +27 -27
  2. package/contract/ppt-contract.json +1 -1
  3. package/dsh-suite.json +27 -17
  4. package/node_modules/@capyclaw/asset-service/dsh-suite.json +1 -1
  5. package/node_modules/@capyclaw/asset-service/package.json +1 -1
  6. package/node_modules/@capyclaw/asset-service/src/index.mjs +4 -3
  7. package/node_modules/@capyclaw/document-workbench/package.json +6 -3
  8. package/node_modules/@capyclaw/document-workbench/src/client/index.mjs +56 -3
  9. package/node_modules/@capyclaw/document-workbench/src/client/visibility.mjs +112 -0
  10. package/node_modules/@capyclaw/document-workbench/src/model/manifest.mjs +6 -4
  11. package/node_modules/@capyclaw/document-workbench/src/model/ops.mjs +7 -2
  12. package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +8 -0
  13. package/node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs +17 -10
  14. package/node_modules/@capyclaw/document-workbench/src/store/projection.mjs +39 -0
  15. package/node_modules/@capyclaw/document-workbench/src/testing/index.mjs +14 -11
  16. package/node_modules/@capyclaw/editor-host/dsh-suite.json +1 -1
  17. package/node_modules/@capyclaw/editor-host/package.json +1 -1
  18. package/node_modules/@capyclaw/editor-host/src/index.mjs +12 -21
  19. package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
  20. package/node_modules/@capyclaw/foundation/abi/bridge.mjs +3 -1
  21. package/node_modules/@capyclaw/foundation/abi/index.mjs +15 -0
  22. package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -0
  23. package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +21 -4
  24. package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +5 -1
  25. package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +5 -2
  26. package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +4 -0
  27. package/node_modules/@capyclaw/foundation/lib/kernel.mjs +13 -3
  28. package/node_modules/@capyclaw/foundation/package.json +1 -1
  29. package/node_modules/@capyclaw/plugin-kit/package.json +3 -1
  30. package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +5 -2
  31. package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
  32. package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
  33. package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +13 -5
  34. package/node_modules/@capyclaw/portal/package.json +1 -1
  35. package/node_modules/@capyclaw/ppt-editor/app.js +458 -10
  36. package/node_modules/@capyclaw/ppt-editor/contract/ppt-contract.json +1 -1
  37. package/node_modules/@capyclaw/ppt-editor/heartbeat-worker.js +5 -2
  38. package/node_modules/@capyclaw/ppt-editor/index.html +4 -0
  39. package/node_modules/@capyclaw/ppt-editor/package.json +2 -2
  40. package/node_modules/@capyclaw/ppt-skill-api/contract/ppt-contract.json +1 -1
  41. package/node_modules/@capyclaw/ppt-skill-api/package.json +1 -1
  42. package/node_modules/@capyclaw/ppt-skill-api/skills/pptist-api/references/tool-contract.md +1 -1
  43. package/node_modules/@capyclaw/ppt-skill-proposal/contract/ppt-contract.json +1 -1
  44. package/node_modules/@capyclaw/ppt-skill-proposal/package.json +1 -1
  45. package/node_modules/@capyclaw/ppt-workbench/contract/ppt-contract.json +1 -1
  46. package/node_modules/@capyclaw/ppt-workbench/core/deck-layout.js +3 -1
  47. package/node_modules/@capyclaw/ppt-workbench/core/ops/slide.js +9 -3
  48. package/node_modules/@capyclaw/ppt-workbench/core/text.js +14 -2
  49. package/node_modules/@capyclaw/ppt-workbench/package.json +10 -8
  50. package/node_modules/@capyclaw/ppt-workbench/plugin.mjs +13 -1
  51. package/node_modules/@capyclaw/ppt-workbench/server/contract.mjs +1 -1
  52. package/node_modules/@capyclaw/ppt-workbench/server/embedded-host.mjs +200 -29
  53. package/node_modules/@capyclaw/ppt-workbench/server/relay.mjs +10 -7
  54. package/node_modules/@capyclaw/ppt-workbench/server/shared/SHARED_MANIFEST.json +4 -4
  55. package/node_modules/@capyclaw/ppt-workbench/server/store/backends/file-backend.mjs +3 -0
  56. package/node_modules/@capyclaw/ppt-workbench/server/store/checkpoints.mjs +4 -1
  57. package/node_modules/@capyclaw/ppt-workbench/server/store/index.mjs +4 -0
  58. package/node_modules/@capyclaw/ppt-workbench/server/store/sessions.mjs +139 -4
  59. package/node_modules/@capyclaw/ppt-workbench/server/store/shape.mjs +37 -0
  60. package/node_modules/@capyclaw/service-broker/README.md +1 -1
  61. package/node_modules/@capyclaw/service-broker/lib/host.mjs +11 -6
  62. package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +13 -5
  63. package/node_modules/@capyclaw/service-broker/package.json +1 -1
  64. package/node_modules/@capyclaw/service-host/dsh-suite.json +1 -1
  65. package/node_modules/@capyclaw/service-host/package.json +1 -1
  66. package/node_modules/@capyclaw/service-host/src/index.mjs +13 -22
  67. package/node_modules/@capyclaw/skills-service/README.md +42 -10
  68. package/node_modules/@capyclaw/skills-service/package.json +6 -3
  69. package/node_modules/@capyclaw/skills-service/server.mjs +129 -51
  70. package/node_modules/@capyclaw/suite-kit/README.md +289 -0
  71. package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
  72. package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
  73. package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
  74. package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
  75. package/node_modules/@capyclaw/suite-kit/package.json +58 -0
  76. package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
  77. package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
  78. package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
  79. package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
  80. package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
  81. package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
  82. package/node_modules/@capyclaw/suite-kit/src/host.mjs +230 -0
  83. package/node_modules/@capyclaw/suite-kit/src/index.mjs +24 -0
  84. package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
  85. package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
  86. package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
  87. package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
  88. package/node_modules/@capyclaw/suite-kit/suite.schema.json +128 -0
  89. package/node_modules/@capyclaw/tool-host/dsh-suite.json +1 -1
  90. package/node_modules/@capyclaw/tool-host/lib/host.mjs +15 -4
  91. package/node_modules/@capyclaw/tool-host/package.json +1 -1
  92. package/node_modules/@capyclaw/tool-host/src/index.mjs +19 -5
  93. package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +71 -3
  94. package/node_modules/@capyclaw/work-store/README.md +83 -0
  95. package/node_modules/@capyclaw/work-store/STANDARD.md +263 -0
  96. package/node_modules/@capyclaw/work-store/cordis.patch.yml +3 -0
  97. package/node_modules/@capyclaw/work-store/dsh-suite.json +33 -0
  98. package/node_modules/@capyclaw/work-store/icon.svg +7 -0
  99. package/node_modules/@capyclaw/work-store/lib/host.mjs +21 -0
  100. package/node_modules/@capyclaw/work-store/package.json +68 -0
  101. package/node_modules/@capyclaw/work-store/src/backend.mjs +90 -0
  102. package/node_modules/@capyclaw/work-store/src/db.mjs +199 -0
  103. package/node_modules/@capyclaw/work-store/src/envelope.mjs +132 -0
  104. package/node_modules/@capyclaw/work-store/src/index.mjs +571 -0
  105. package/node_modules/@capyclaw/work-store/src/interop.mjs +70 -0
  106. package/node_modules/@capyclaw/work-store/src/refs.mjs +99 -0
  107. package/node_modules/@capyclaw/work-store/src/routes.mjs +135 -0
  108. package/package.json +16 -14
@@ -3,6 +3,8 @@
3
3
  * owner 租约组合成稳定的 DocumentSession API。
4
4
  *
5
5
  * 领域文档放在 documentKey 下;summary/onApplied 由调用方提供。
6
+ * shape(可选形状标签,如 'ppt.deck')随 checkpoint 写入,供套件投影识别;
7
+ * checkpoint 列表的业务字段由 backend 的 project 声明叠加,内核只回通用信封。
6
8
  */
7
9
  import {
8
10
  applyAck, applyPush, applyServer, applyShotRequest, applyShotResult,
@@ -41,6 +43,7 @@ export class DocumentSession {
41
43
  checkpointDocument = null,
42
44
  stateCompact = true,
43
45
  pendingTtl = PENDING_TTL,
46
+ shape = null,
44
47
  } = {}) {
45
48
  if (!backend) throw new Error('DocumentSession 需要 backend')
46
49
  this.backend = backend
@@ -51,6 +54,9 @@ export class DocumentSession {
51
54
  this.checkpointDocument = checkpointDocument
52
55
  this.stateCompact = stateCompact !== false
53
56
  this.pendingTtl = Number(pendingTtl) || PENDING_TTL
57
+ /* 形状标签(如 'ppt.deck'):写进 checkpoint payload 供套件投影识别新格式;
58
+ * 缺省不写(旧格式不变),旧 payload 无标签时套件 projector 按键名兜底。 */
59
+ this.shape = typeof shape === 'string' && shape ? shape : null
54
60
  this.dir = backend.dir || ''
55
61
  this.file = backend.file || ''
56
62
  this.journalFile = backend.journalFile || ''
@@ -251,6 +257,8 @@ export class DocumentSession {
251
257
  seq: this.doc.seq | 0,
252
258
  appliedSeq: this.doc.applied_seq | 0,
253
259
  pending,
260
+ /* 通用信封 + 形状标签:业务形状的解释归套件投影,内核只记录标签。 */
261
+ ...(this.shape ? { shape: this.shape } : {}),
254
262
  ...summary,
255
263
  title: this.doc.title || summary.title || '',
256
264
  [this.documentKey]: this.doc[this.documentKey]
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import fs from 'node:fs'
9
9
  import path from 'node:path'
10
+ import { projectCheckpoint } from './projection.mjs'
10
11
 
11
12
  export class FileStateBackend {
12
13
  /* journalMaxBytes 默认 512KB 由 NSGA-II 进化搜索固化(evolution/,2026-11-01):
@@ -18,7 +19,7 @@ export class FileStateBackend {
18
19
  * document-workbench 每个编辑批次会写 2 次状态——节流到每 16 次写一次 fsync,
19
20
  * 把该链路成本从 ~3.6ms/批降到 ~1.5ms/批;checkpoint 仍强制 fsync(里程碑语义)。
20
21
  * 设为 1 恢复「每次写都 fsync」的旧行为;设为 0 则完全不做 fsync。 */
21
- constructor(file, { initialDoc = {}, journalMaxBytes = 512 * 1024, fsyncEvery = 16 } = {}) {
22
+ constructor(file, { initialDoc = {}, journalMaxBytes = 512 * 1024, fsyncEvery = 16, project = null } = {}) {
22
23
  if (!file) throw new Error('FileStateBackend 需要 file')
23
24
  this.file = file
24
25
  this.dir = path.dirname(file)
@@ -27,6 +28,9 @@ export class FileStateBackend {
27
28
  this.initialDoc = initialDoc
28
29
  this.journalMaxBytes = Math.max(64 * 1024, Number(journalMaxBytes) || 512 * 1024)
29
30
  this.fsyncEvery = Math.max(0, Number(fsyncEvery) || 0)
31
+ /* checkpoint 列表的套件投影(形状声明):内核默认只回通用信封,
32
+ * PPT 的 slides/title 等业务字段由套件适配层显式传入(见 projection.mjs)。 */
33
+ this.project = typeof project === 'function' ? project : null
30
34
  this._writeCount = 0
31
35
  /** 最近一次读状态失败的原因;ENOENT 不算错误。 */
32
36
  this.lastStateError = null
@@ -128,17 +132,20 @@ export class FileStateBackend {
128
132
  .filter((name) => name.endsWith('.json'))
129
133
  .map((name) => {
130
134
  try {
131
- const payload = JSON.parse(fs.readFileSync(path.join(this.checkpointDir, name), 'utf8'))
132
- return {
133
- name: payload.name,
134
- seq: payload.seq,
135
- appliedSeq: payload.appliedSeq,
136
- pending: !!payload.pending,
137
- title: payload.title,
138
- slides: payload.slides,
135
+ const file = path.join(this.checkpointDir, name)
136
+ const raw = fs.readFileSync(file, 'utf8')
137
+ const parsed = JSON.parse(raw)
138
+ const payload = parsed && typeof parsed === 'object' ? parsed : {}
139
+ /* 通用信封(V2-5):不解析 payload 内部业务形状;
140
+ * seq/slides 等扩展字段由 this.project(套件声明)叠加。 */
141
+ const base = {
142
+ name: payload.name ?? name.slice(0, -5),
143
+ ts: fs.statSync(file).mtimeMs,
139
144
  createdAt: payload.createdAt,
140
- meta: payload.meta || {},
145
+ size: Buffer.byteLength(raw, 'utf8'),
146
+ meta: payload.meta && typeof payload.meta === 'object' ? payload.meta : {},
141
147
  }
148
+ return projectCheckpoint(payload, base, this.project)
142
149
  } catch { return null }
143
150
  })
144
151
  .filter(Boolean)
@@ -0,0 +1,39 @@
1
+ /**
2
+ * checkpoint 列表投影:通用信封 + 套件声明(M5 / checkpoint 投影通用化)。
3
+ *
4
+ * 内核只产出形状无关的通用信封 {name, ts, createdAt, size, meta}
5
+ * (work-store STANDARD V2-5:不解析 payload 内部业务形状);
6
+ * 会话协议字段(seq/appliedSeq/pending/title)在这里作为可选组合助手提供,
7
+ * 业务形状(如 PPT 的 slides)由套件适配层显式声明 project(payload, base)
8
+ * 并传给 backend——内核不硬编码任何套件名词。
9
+ *
10
+ * 旧 checkpoint 的 payload 原样保留(readCheckpoint 仍返回全量),
11
+ * 套件 projector 负责兼容读取历史形状,无需迁移数据。
12
+ */
13
+
14
+ /**
15
+ * 会话协议字段(形状无关):payload 里实际存在才附带,不造零值。
16
+ * 兼容旧 payload 的 applied_seq 蛇形命名;pending 兼容布尔与数组(取条数)。
17
+ */
18
+ export function sessionCheckpointFields(payload) {
19
+ const out = {}
20
+ if (!payload || typeof payload !== 'object') return out
21
+ if ('seq' in payload) out.seq = payload.seq | 0
22
+ const applied = payload.appliedSeq ?? payload.applied_seq
23
+ if (applied != null) out.appliedSeq = applied | 0
24
+ if ('pending' in payload) {
25
+ out.pending = Array.isArray(payload.pending) ? payload.pending.length : !!payload.pending
26
+ }
27
+ if (typeof payload.title === 'string' && payload.title) out.title = payload.title
28
+ return out
29
+ }
30
+
31
+ /**
32
+ * 合并套件投影:project(payload, base) 返回扩展字段,叠加到通用信封上。
33
+ * project 缺省或返回非对象时原样返回 base(内核默认 = 纯通用信封)。
34
+ */
35
+ export function projectCheckpoint(payload, base, project) {
36
+ if (typeof project !== 'function') return base
37
+ const extra = project(payload, base)
38
+ return extra && typeof extra === 'object' ? { ...base, ...extra } : base
39
+ }
@@ -1,6 +1,7 @@
1
1
  /** 测试工具:内存 backend 与 fake editor adapter,供框架自身和消费者做一致性测试。 */
2
+ import { projectCheckpoint } from '../store/projection.mjs'
2
3
 
3
- export function createMemoryBackend({ initialDoc = {} } = {}) {
4
+ export function createMemoryBackend({ initialDoc = {}, project = null } = {}) {
4
5
  let state = null
5
6
  const journal = []
6
7
  const checkpoints = new Map()
@@ -27,16 +28,18 @@ export function createMemoryBackend({ initialDoc = {} } = {}) {
27
28
  },
28
29
  listCheckpoints() {
29
30
  return [...checkpoints.values()]
30
- .map((payload) => ({
31
- name: payload.name,
32
- seq: payload.seq,
33
- appliedSeq: payload.appliedSeq,
34
- pending: !!payload.pending,
35
- title: payload.title,
36
- slides: payload.slides,
37
- createdAt: payload.createdAt,
38
- meta: payload.meta || {},
39
- }))
31
+ .map((raw) => {
32
+ const payload = raw && typeof raw === 'object' ? raw : {}
33
+ /* 通用信封(V2-5):业务字段由 project(套件声明)叠加,与 FileStateBackend 同契约。 */
34
+ const base = {
35
+ name: payload.name,
36
+ ts: Date.parse(payload.createdAt) || 0,
37
+ createdAt: payload.createdAt,
38
+ size: Buffer.byteLength(JSON.stringify(raw ?? null), 'utf8'),
39
+ meta: payload.meta && typeof payload.meta === 'object' ? payload.meta : {},
40
+ }
41
+ return projectCheckpoint(payload, base, project)
42
+ })
40
43
  .sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)))
41
44
  },
42
45
  readCheckpoint(name) {
@@ -7,7 +7,7 @@
7
7
  "packages": {
8
8
  "@capyclaw/editor-host": {
9
9
  "role": "provider",
10
- "version": "^0.1.5",
10
+ "version": "^0.1.7",
11
11
  "path": ".",
12
12
  "provides": {
13
13
  "services": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capyclaw/editor-host",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "DSH 公共编辑器宿主插件:静态托管、租约仲裁、心跳与连接状态,向插件提供 ctx.editorHost。",
5
5
  "type": "module",
6
6
  "main": "./lib/host.mjs",
@@ -16,13 +16,9 @@ import { createEditorLease } from '@capyclaw/plugin-kit/editor/lease'
16
16
  import { send, readBody } from '@capyclaw/plugin-kit/service/http'
17
17
  import { createServiceApi } from '@capyclaw/plugin-kit/service/api'
18
18
  import { mimeFor } from '@capyclaw/plugin-kit/util/http'
19
+ import { safeJoin, cleanStaticPrefix, staticPrefixHit, staticRelRaw, decodeStaticRel, staticFileHit, staticHitNameType, staticBaseHeaders } from '@capyclaw/plugin-kit/service/static'
19
20
 
20
- function safeJoin(root, rel) {
21
- const target = path.resolve(root, `.${path.sep}${rel}`)
22
- const base = path.resolve(root)
23
- return target === base || target.startsWith(base + path.sep) ? target : null
24
- }
25
-
21
+ /* safeJoin 已收敛到 @capyclaw/plugin-kit/service/static(P2-13a 静态公共核心)。 */
26
22
  const contentType = mimeFor
27
23
 
28
24
  /**
@@ -30,7 +26,7 @@ const contentType = mimeFor
30
26
  */
31
27
  export function createEditorHost({ id, dir, basePath = '', index = 'index.html', files = null } = {}) {
32
28
  if (!id) throw new Error('createEditorHost: id 必填')
33
- const prefix = basePath === '/' ? '' : String(basePath || '').replace(/\/+$/, '')
29
+ const prefix = cleanStaticPrefix(basePath)
34
30
  const lease = createEditorLease()
35
31
 
36
32
  /* 编辑器主包 4.6MB,且每次打开窗口都会重新下载。按 (size, mtime) 做 ETag +
@@ -55,7 +51,7 @@ export function createEditorHost({ id, dir, basePath = '', index = 'index.html',
55
51
 
56
52
  const staticRoutes = async function editorStatic(req, res, u) {
57
53
  if (req.method !== 'GET' && req.method !== 'HEAD') return false
58
- if (prefix && u.pathname !== prefix && !u.pathname.startsWith(prefix + '/')) return false
54
+ if (!staticPrefixHit(u.pathname, prefix)) return false
59
55
  /* 目录式入口必须带尾斜杠,否则整页白:页面里的 `./app-v*.js` 按 document.baseURI
60
56
  * 解析,`/capyclaw/ppt` 的 baseURI 是 `/capyclaw/`,脚本会去要
61
57
  * `/capyclaw/app-v*.js` → 404,只剩顶栏 + 「正在装载编辑器…」。
@@ -65,19 +61,17 @@ export function createEditorHost({ id, dir, basePath = '', index = 'index.html',
65
61
  res.end()
66
62
  return true
67
63
  }
68
- const relRaw = prefix ? u.pathname.slice(prefix.length) : u.pathname
69
- let rel
70
- try {
71
- rel = relRaw === '' || relRaw === '/' ? index : decodeURIComponent(relRaw.replace(/^\/+/, ''))
72
- } catch {
64
+ const relRaw = staticRelRaw(u.pathname, prefix)
65
+ const rel = decodeStaticRel(relRaw, index)
66
+ if (rel === null) {
73
67
  /* 百分号编码坏了只该是 400 级别的路径问题,不该让整个静态面抛异常。 */
74
68
  return false
75
69
  }
76
70
  let file = null
77
71
  if (files) {
78
- const hit = files[relRaw === '' ? '/' : relRaw] || files[relRaw]
72
+ const hit = staticFileHit(files, relRaw)
79
73
  if (!hit) return false
80
- const name = Array.isArray(hit) ? hit[0] : hit
74
+ const [name] = staticHitNameType(hit)
81
75
  file = safeJoin(dir, name)
82
76
  } else {
83
77
  file = safeJoin(dir, rel)
@@ -93,14 +87,11 @@ export function createEditorHost({ id, dir, basePath = '', index = 'index.html',
93
87
  }
94
88
  const wantsGzip = Boolean(asset.gzip) && /\bgzip\b/.test(String(req.headers['accept-encoding'] || ''))
95
89
  const body = wantsGzip ? asset.gzip : asset.data
90
+ /* 基础五项头走公共核心;本宿主在其上追加 etag/vary。
91
+ * no-cache = 允许缓存但每次都带 ETag 回来校验;304 时不重下 4.6MB。 */
96
92
  const headers = {
97
- 'content-type': asset.type,
98
- 'content-length': body.length,
93
+ ...staticBaseHeaders(asset.type, body.length),
99
94
  etag: asset.etag,
100
- 'x-content-type-options': 'nosniff',
101
- 'referrer-policy': 'no-referrer',
102
- /* no-cache = 允许缓存但每次都带 ETag 回来校验;304 时不重下 4.6MB。 */
103
- 'cache-control': 'no-cache',
104
95
  vary: 'accept-encoding',
105
96
  }
106
97
  if (wantsGzip) headers['content-encoding'] = 'gzip'
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 资产引用契约的单一真源(公共 ABI 常量)。
3
+ *
4
+ * 互操作标准里资产有两副面孔,前缀在这里定义一次,内核门面与资产服务都引用它,
5
+ * 避免「路由实现」与「URL 门面」各写一份 '/assets/' 而漂移:
6
+ * - 字节仓 HTTP 路由前缀 ASSET_URL_PREFIX = '/assets/' (asset-service 挂 GET/HEAD)
7
+ * - 结构化正文里的引用前缀 ASSET_REF_PREFIX = '@asset/' (work-store 信封/正文只存引用)
8
+ *
9
+ * 这是契约常量,不是宿主服务名——放 ABI 层,应用与驱动都可 import。
10
+ */
11
+
12
+ /** 资产字节仓的 HTTP 路由前缀(asset-service 实现,内核 os.assets.url 复用)。 */
13
+ export const ASSET_URL_PREFIX = '/assets/'
14
+
15
+ /** 结构化正文/产物信封里的内容寻址引用前缀(@asset/<sha256>)。 */
16
+ export const ASSET_REF_PREFIX = '@asset/'
17
+
18
+ /** 由资产 id 生成可加载 URL:/assets/<id>(id 做 URI 编码)。 */
19
+ export function assetUrl(id) {
20
+ return `${ASSET_URL_PREFIX}${encodeURIComponent(String(id))}`
21
+ }
22
+
23
+ /** 由资产 id 生成规范引用:@asset/<id>。 */
24
+ export function assetRef(id) {
25
+ return `${ASSET_REF_PREFIX}${String(id)}`
26
+ }
@@ -14,6 +14,8 @@
14
14
  * doc.model —— 插件提供文档模型(稳定 ID / 清单 / 定位 / 编辑计划 / 校验)
15
15
  */
16
16
 
17
+ import { AbiError, ERROR_CODES } from './errors.mjs'
18
+
17
19
  /** 桥协议版本:端点集合与状态机语义的主版本。不兼容变更才升 major。 */
18
20
  export const BRIDGE_PROTOCOL_VERSION = '1.0.0'
19
21
 
@@ -40,7 +42,7 @@ export function declareBridge(input = {}) {
40
42
  if (!VERSION_RE.test(protocol)) errors.push(`protocol 版本非法:${protocol}`)
41
43
  if (model !== null && !VERSION_RE.test(model)) errors.push(`model 版本非法:${model}`)
42
44
  if (editor !== 'required' && editor !== 'optional') errors.push(`editor 只能是 required/optional:${editor}`)
43
- if (errors.length) throw new Error(`桥声明非法:${errors.join(';')}`)
45
+ if (errors.length) throw new AbiError(ERROR_CODES.E_SCHEMA, `桥声明非法:${errors.join(';')}`, { errors })
44
46
  return Object.freeze({ id, protocol, model, editor })
45
47
  }
46
48
 
@@ -17,6 +17,8 @@ export {
17
17
  defineDriver,
18
18
  rawPlugin,
19
19
  } from './spec.mjs'
20
+ /* createLoader 是宿主/测试侧装配 API(内核 createKernel 与一致性测试用),虽从 abi 导出,
21
+ * 应用插件不应直接调用——应用只用 createPlugin + 接口 builders(见 plugin-abi.md §二)。 */
20
22
  export { createLoader } from './loader.mjs'
21
23
  export {
22
24
  BRIDGE_CAPABILITY,
@@ -29,6 +31,19 @@ export {
29
31
  bridgeConsumerRequirements,
30
32
  declareBridge,
31
33
  } from './bridge.mjs'
34
+ export {
35
+ SURFACE_LIFECYCLE_VERSION,
36
+ SURFACE_LIFECYCLE_CAPABILITY_SUFFIX,
37
+ VISIBILITY_ACK_MESSAGE,
38
+ VISIBILITY_DEFAULTS,
39
+ VISIBILITY_MESSAGE,
40
+ VISIBILITY_STATES,
41
+ assertSurfaceLifecycle,
42
+ isVisibilityState,
43
+ normalizeVisibilityState,
44
+ surfaceLifecycleCapability,
45
+ } from './visibility.mjs'
46
+ export { ASSET_URL_PREFIX, ASSET_REF_PREFIX, assetUrl, assetRef } from './assets.mjs'
32
47
  export { validateInterface } from './validate.mjs'
33
48
  export { AbiError, ERROR_CODES, isAbiError, toAbiError } from './errors.mjs'
34
49
  export { validateSchema } from './schema.mjs'
@@ -0,0 +1,90 @@
1
+ /**
2
+ * 表面生命周期(surface lifecycle)的标准声明。
3
+ *
4
+ * 与 bridge.mjs 同层:只放「协议常量 + 声明校验」,不放运行时。
5
+ * 依据 docs/SURFACE-LIFECYCLE-STANDARD.md:
6
+ * - 宿主(portal-hud + window-kit)是表面可见性的唯一真源,经统一 postMessage
7
+ * 信号通道下发给 iframe;iframe 内 document.hidden 只反映顶层 tab,不能用来
8
+ * 推断「被宿主藏起来」,所以表面可见性必须宿主显式告知。
9
+ * - 只有渲染面响应可见性;权威/数据面与桥接/仲裁面(租约心跳、apply/ack)
10
+ * 永远在线,与可见性无关。
11
+ *
12
+ * 消费方:
13
+ * - 宿主侧:@capyclaw/window-kit 的 visibility 驱动器(CJS 自包含叶子,无法
14
+ * import 本 ESM 模块,内联同名常量,由 parity 测试钉死一致)。
15
+ * - iframe 侧:@capyclaw/document-workbench/client 的 visibility 订阅器,
16
+ * 以及各编辑器前端(ppt/canvas/browser)。
17
+ * - 注册面:suite 清单 provides.capabilities 的 <ns>.surfaceLifecycle。
18
+ */
19
+
20
+ import { AbiError, ERROR_CODES } from './errors.mjs'
21
+
22
+ /** 表面生命周期契约版本:状态机语义与信号形状的主版本。不兼容变更才升 major。 */
23
+ export const SURFACE_LIFECYCLE_VERSION = '1.0.0'
24
+
25
+ /** 宿主 → iframe 的可见性信号:{ type, state, sid },targetOrigin 同源。 */
26
+ export const VISIBILITY_MESSAGE = 'capyclaw:workbench:visibility'
27
+
28
+ /** iframe → 宿主 的回执:{ type, state, sid }。detached 由宿主直接卸载,无需回执。 */
29
+ export const VISIBILITY_ACK_MESSAGE = 'capyclaw:workbench:visibility-ack'
30
+
31
+ /**
32
+ * 可见性状态(标准 §3):
33
+ * foreground 前台可见全速;background 可见非焦点(降速,SHOULD 档);
34
+ * hidden 不再绘制(渲染面必须挂起);detached 久藏卸载(影子编辑器接管)。
35
+ */
36
+ export const VISIBILITY_STATES = Object.freeze(['foreground', 'background', 'hidden', 'detached'])
37
+
38
+ /**
39
+ * 节奏/预算默认值(标准 §3/§4/§5)。运行时经 tuning 单一真源可调;
40
+ * 这里是协议默认,不是各插件私设的第二份。
41
+ * detachAfterMs hidden 持续多久才卸载 iframe(编辑器权威型可更长)
42
+ * visibilityAckTimeoutMs 信号发出后多久没回执算半挂起(宿主可强制重载)
43
+ * hiddenGraceMs shown→hidden 的去抖宽限,避免快速切换抖动
44
+ */
45
+ export const VISIBILITY_DEFAULTS = Object.freeze({
46
+ detachAfterMs: 120000,
47
+ visibilityAckTimeoutMs: 1500,
48
+ hiddenGraceMs: 250,
49
+ })
50
+
51
+ /** 能力名后缀:与 suite 清单 provides.capabilities 的 <ns>.surfaceLifecycle 对应。 */
52
+ export const SURFACE_LIFECYCLE_CAPABILITY_SUFFIX = 'surfaceLifecycle'
53
+
54
+ const STATE_SET = new Set(VISIBILITY_STATES)
55
+
56
+ /** 是否合法状态。 */
57
+ export function isVisibilityState(value) {
58
+ return typeof value === 'string' && STATE_SET.has(value)
59
+ }
60
+
61
+ /** 归一化:非法/缺省一律退回 foreground(宁可多渲染,不可假挂起)。 */
62
+ export function normalizeVisibilityState(value) {
63
+ return isVisibilityState(value) ? value : 'foreground'
64
+ }
65
+
66
+ /** 注册声明 → suite 清单 provides.capabilities(标准 §6)。 */
67
+ export function surfaceLifecycleCapability(ns, version = SURFACE_LIFECYCLE_VERSION) {
68
+ if (typeof ns !== 'string' || !/^[a-z0-9][a-z0-9-]*$/.test(ns)) {
69
+ throw new AbiError(ERROR_CODES.E_SCHEMA, `surfaceLifecycle 命名空间必须是 kebab-case:${ns}`)
70
+ }
71
+ return Object.freeze({ [`${ns}.${SURFACE_LIFECYCLE_CAPABILITY_SUFFIX}`]: version })
72
+ }
73
+
74
+ /**
75
+ * 校验一份表面生命周期声明(注册契约,标准 §6)。
76
+ * 渲染面四钩子必须齐;editor-gated 观察必须声明无头兜底。
77
+ * @param {{ hooks?: string[], headlessObservation?: boolean }} input
78
+ */
79
+ export function assertSurfaceLifecycle(input = {}) {
80
+ const required = ['onVisibility', 'suspendRender', 'resumeRender', 'rehydrate']
81
+ const hooks = Array.isArray(input.hooks) ? input.hooks : []
82
+ const issues = []
83
+ for (const hook of required) {
84
+ if (!hooks.includes(hook)) issues.push(`缺少渲染面钩子 ${hook}`)
85
+ }
86
+ if (input.headlessObservation !== true) {
87
+ issues.push('editor-gated 观察必须声明无头兜底(headlessObservation:true)')
88
+ }
89
+ return { ok: issues.length === 0, issues }
90
+ }
@@ -1,10 +1,14 @@
1
1
  /**
2
2
  * lifecycle-hook@1 的适配器。
3
3
  *
4
- * 运行时只执行 onStart / onStop;onInstall / onUpgrade 属于安装与升级流程,
5
- * 由安装器(publisher / dsh profile 安装)在对应时点读取描述符后调用。
6
- * 这里把它们登记进 hook 注册表,保证「声明了就找得到」。
4
+ * 运行时只执行 onStart / onStop。onInstall / onUpgrade 属于安装与升级流程:
5
+ * 这里把它们登记进 hook 注册表(os.hooks),保证「声明了就找得到」。
6
+ * 截至本版本仓内尚无自动 fire 它们的安装/升级消费者(见 plugin-abi.md §4.6)——
7
+ * 这是已声明的集成点,不是已落地的自动钩子。安装器可经 os.hooks.run('install'|'upgrade', args)
8
+ * 主动触发;run() 只提供调用 API,是否/何时调用由安装器决定。
7
9
  */
10
+ import { AbiError, ERROR_CODES } from '../../abi/errors.mjs'
11
+
8
12
  export const kind = 'lifecycle-hook@1'
9
13
 
10
14
  export function createHookRegistry() {
@@ -12,7 +16,7 @@ export function createHookRegistry() {
12
16
  install: [],
13
17
  upgrade: [],
14
18
  register(phase, entry) {
15
- if (!this[phase]) throw new Error(`未知生命周期阶段 ${phase}`)
19
+ if (!this[phase]) throw new AbiError(ERROR_CODES.E_SCHEMA, `未知生命周期阶段 ${phase}`)
16
20
  this[phase].push(entry)
17
21
  return () => {
18
22
  const index = this[phase].indexOf(entry)
@@ -25,6 +29,19 @@ export function createHookRegistry() {
25
29
  upgrade: this.upgrade.map((entry) => entry.plugin),
26
30
  }
27
31
  },
32
+ /**
33
+ * 安装/升级集成点:按登记顺序触发某阶段全部钩子,逐个 await。
34
+ * 仓内暂无自动调用方(见头注);这是给安装器(plugin-sync / plugin-drop / publisher)
35
+ * 预留的调用 API。未知阶段抛稳定错误码 E_SCHEMA。
36
+ */
37
+ async run(phase, args = {}) {
38
+ if (!this[phase]) throw new AbiError(ERROR_CODES.E_SCHEMA, `未知生命周期阶段 ${phase}`)
39
+ const results = []
40
+ for (const entry of [...this[phase]]) {
41
+ results.push({ plugin: entry.plugin, result: await entry.run(args) })
42
+ }
43
+ return results
44
+ },
28
45
  }
29
46
  }
30
47
 
@@ -6,6 +6,7 @@
6
6
  * editorHost)的地方——它们属于 dsh 适配层,不属于 ABI。
7
7
  */
8
8
  import { getService } from '../ctx-service.mjs'
9
+ import { HOST_SERVICE_CONTRACT } from './contract.mjs'
9
10
 
10
11
  export const BASE_CAPABILITIES = Object.freeze({
11
12
  'os.events': '1.0.0',
@@ -26,9 +27,12 @@ export function detectDshCapabilities(ctx) {
26
27
  && hasMethods(getService(ctx, 'tools'), 'register')) capabilities['os.tools'] = '1.0.0'
27
28
  if (hasMethods(getService(ctx, 'serviceBroker'), 'start', 'stop')) capabilities['os.proc'] = '1.0.0'
28
29
  if (capabilities['os.net'] && hasMethods(getService(ctx, 'editorHost'), 'createEditorHost')) capabilities['os.ui'] = '1.0.0'
29
- if (hasMethods(getService(ctx, 'pluginManager'), 'listBundles', 'listPlugins', 'setBundleEnabled', 'setPluginEnabled')) {
30
+ if (hasMethods(getService(ctx, 'pluginManager'), ...HOST_SERVICE_CONTRACT['os.plugins'][1])) {
30
31
  capabilities['os.plugins'] = '1.0.0'
31
32
  }
32
33
  if (hasMethods(getService(ctx, 'assets'), 'put', 'get')) capabilities['os.assets'] = '1.0.0'
34
+ // work-store 是可选持久化层(不在 core 六件内):探测到才 advertise os.works,
35
+ // 应用用 os.caps.has('os.works') 判断降级,不再 safeGet(ctx, 'workStore') 裸摸。
36
+ if (hasMethods(getService(ctx, 'workStore'), 'backendFor')) capabilities['os.works'] = '1.0.0'
33
37
  return capabilities
34
38
  }
@@ -3,7 +3,9 @@ import { parseVersion } from '../../abi/version.mjs'
3
3
  import { AbiError, ERROR_CODES } from '../../abi/errors.mjs'
4
4
 
5
5
  const ACCESSORS = ['capabilities', 'log', 'skills', 'tools', 'http', 'proc', 'ui']
6
- const SERVICES = {
6
+ /** Host v1 能力→[访问器, 必需方法] 契约。导出为单一真源:内核门面与能力探测都引用它,
7
+ * 不再各自硬编码 os.plugins 的 dsh 方法名(listBundles/setPluginEnabled…)。 */
8
+ export const HOST_SERVICE_CONTRACT = {
7
9
  'os.skills': ['skills', ['registerProvider']],
8
10
  'os.tools': ['tools', ['register']],
9
11
  'os.net': ['http', ['createApp', 'createSharedHost']],
@@ -12,6 +14,7 @@ const SERVICES = {
12
14
  'os.ui': ['ui', ['createEditorHost']],
13
15
  'os.plugins': ['plugins', ['listBundles', 'listPlugins', 'setBundleEnabled', 'setPluginEnabled']],
14
16
  'os.assets': ['assets', ['put', 'get']],
17
+ 'os.works': ['works', ['backendFor']],
15
18
  }
16
19
 
17
20
  function invalid(path, expectation) {
@@ -68,7 +71,7 @@ export function assertHostContract(host) {
68
71
  if (typeof logger[method] !== 'function') invalid(`host.log().${method}`, 'must be a function')
69
72
  }
70
73
  }
71
- for (const [capability, [accessor, methods]] of Object.entries(SERVICES)) {
74
+ for (const [capability, [accessor, methods]] of Object.entries(HOST_SERVICE_CONTRACT)) {
72
75
  if (!Object.hasOwn(capabilities, capability)) continue
73
76
  if (typeof host[accessor] !== 'function') {
74
77
  invalid(`host.${accessor}`, `must be a function when advertising ${capability}`)
@@ -15,6 +15,9 @@
15
15
  * web() { register({kind, path, handler}) => dispose, port } | undefined
16
16
  * proc() { start(serviceSpec) => Promise<{errors?}>, stop(id) }
17
17
  * ui() { createEditorHost({ id, dir, basePath, index }) }
18
+ * assets() { put, get, ... } | undefined —— 资产字节仓(asset-service)
19
+ * works() { backendFor, claimSessionMode, ... } | undefined —— 作品目录(work-store,
20
+ * 可选持久化层:缺席时内核 os.works 返回 null,应用自行降级内存态)
18
21
  *
19
22
  * `web()` 是宿主网页端口本身(dsh 即 ctx.webServer)。拿到它时,内核一律把 HTTP
20
23
  * 挂到该端口的路径前缀下,不再另起端口;拿不到才退回 os.net 的独立监听。
@@ -46,5 +49,6 @@ export function createDshHost(ctx) {
46
49
  ui: () => getService(ctx, 'editorHost'),
47
50
  plugins: () => getService(ctx, 'pluginManager'),
48
51
  assets: () => getService(ctx, 'assets'),
52
+ works: () => getService(ctx, 'workStore'),
49
53
  }
50
54
  }
@@ -13,7 +13,8 @@ import { AbiError, ERROR_CODES, toAbiError } from '../abi/errors.mjs'
13
13
  import { createLoader } from '../abi/loader.mjs'
14
14
  import { BASE_CAPABILITIES, detectDshCapabilities } from './host/caps.mjs'
15
15
  import { createDshHost } from './host/dsh.mjs'
16
- import { assertHostContract } from './host/contract.mjs'
16
+ import { assertHostContract, HOST_SERVICE_CONTRACT } from './host/contract.mjs'
17
+ import { assetUrl } from '../abi/assets.mjs'
17
18
  import { createSkillAdapter } from './adapters/skill-provider.mjs'
18
19
  import { createToolProviderAdapter } from './adapters/tool-provider.mjs'
19
20
  import { createRuntimeDriverAdapter } from './adapters/runtime-driver.mjs'
@@ -88,7 +89,8 @@ export function createKernel(ctx, config = {}, options = {}) {
88
89
 
89
90
  function pluginManager() {
90
91
  const service = hostService('plugins', 'os.plugins')
91
- for (const method of ['listBundles', 'listPlugins', 'setBundleEnabled', 'setPluginEnabled']) {
92
+ // 方法名单一真源 = Host 契约(contract.mjs),内核不再硬编码 dsh 方法名。
93
+ for (const method of HOST_SERVICE_CONTRACT['os.plugins'][1]) {
92
94
  if (typeof service[method] !== 'function') {
93
95
  throw new AbiError(ERROR_CODES.E_CAP_MISSING,
94
96
  `os.plugins 不可用:pluginManager 缺少 ${method}`, { capability: 'os.plugins', method })
@@ -143,7 +145,15 @@ export function createKernel(ctx, config = {}, options = {}) {
143
145
  assets: {
144
146
  put: (value, contentType) => hostService('assets', 'os.assets').put(value, contentType),
145
147
  get: (id) => hostService('assets', 'os.assets').get(id),
146
- url: (id) => `/assets/${encodeURIComponent(String(id))}`,
148
+ url: (id) => assetUrl(id),
149
+ },
150
+
151
+ /** 作品目录门面(可选持久化层):work-store 缺席时返回 null,应用自行降级内存态。
152
+ * 与 os.assets(必需字节仓,缺席抛 E_CAP_MISSING)不同——works 是可选增强,
153
+ * 不在 core 六件内。用 os.caps.has('os.works') 探测可用性,不再 safeGet(ctx,'workStore') 裸摸。 */
154
+ get works() {
155
+ const service = typeof host.works === 'function' ? host.works() : null
156
+ return service && typeof service.then !== 'function' ? service : null
147
157
  },
148
158
 
149
159
  /** 能力检查与自报。 */
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capyclaw/foundation",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "dsh 插件基石层:接口 ABI、插件加载器与内核服务 ctx.os。应用插件只声明接口,不写装配代码。",
5
5
  "type": "module",
6
6
  "main": "./lib/host.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capyclaw/plugin-kit",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "DSH 插件基础设施标准件:HTTP/MCP、单实例锁、参数校验、技能 provider、journal 存储、编辑器传输与租约。",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -10,11 +10,13 @@
10
10
  "./service/mcp-http": "./src/service/mcp-http.mjs",
11
11
  "./service/server": "./src/service/server.mjs",
12
12
  "./service/api": "./src/service/api.mjs",
13
+ "./service/static": "./src/service/static.mjs",
13
14
  "./tools/validate": "./src/tools/validate.mjs",
14
15
  "./tools/result": "./src/tools/result.mjs",
15
16
  "./skills/provider": "./src/skills/provider.mjs",
16
17
  "./editor/transport": "./src/editor/transport.js",
17
18
  "./editor/lease": "./src/editor/lease.mjs",
19
+ "./editor/heartbeat": "./src/editor/heartbeat.mjs",
18
20
  "./editor/shadow": "./src/editor/shadow.mjs",
19
21
  "./store/journal-store": "./src/store/journal-store.mjs",
20
22
  "./store/blob-store": "./src/store/blob-store.mjs",
@@ -45,7 +45,10 @@ self.onmessage = function(e) {
45
45
  function startHeartbeat() {
46
46
  if (intervalHandle) clearInterval(intervalHandle);
47
47
 
48
- // 每 4 秒发送心跳(留 1 秒缓冲,避免刚好 5 秒时被判过期)
48
+ // 心跳节奏统一为 3s:单一真源是 editor/heartbeat.mjs 的 HEARTBEAT_INTERVAL_MS。
49
+ // 本文件是原样拷贝的经典 Worker,运行时不能 import npm 模块,故以字面量承载节奏,
50
+ // 由 test/heartbeat-constants.test.mjs 钉死与常量一致,防止再次漂移。
51
+ // 心跳对象是编辑器「在场租约」(editor-host /claim);两层租约语义见 heartbeat.mjs 头注。
49
52
  intervalHandle = setInterval(() => {
50
53
  if (!active) return;
51
54
 
@@ -66,7 +69,7 @@ function startHeartbeat() {
66
69
  });
67
70
  }
68
71
  });
69
- }, 4000);
72
+ }, 3000);
70
73
 
71
74
  // 立即发送第一次
72
75
  sendClaim().catch(() => {});