@capyclaw/browser-suite 0.2.37 → 0.2.39

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 (240) hide show
  1. package/composition.lock.json +23 -23
  2. package/contract/browser-contract.json +45 -19
  3. package/dsh-suite.json +26 -16
  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 +10 -4
  7. package/node_modules/@capyclaw/browser-skill-api/contract/browser-contract.json +45 -19
  8. package/node_modules/@capyclaw/browser-skill-api/package.json +1 -1
  9. package/node_modules/@capyclaw/browser-skill-api/skills/browser-api/references/tool-contract.md +1 -1
  10. package/node_modules/@capyclaw/browser-skill-browser/contract/browser-contract.json +45 -19
  11. package/node_modules/@capyclaw/browser-skill-browser/package.json +1 -1
  12. package/node_modules/@capyclaw/browser-skill-ops/contract/browser-contract.json +45 -19
  13. package/node_modules/@capyclaw/browser-skill-ops/package.json +1 -1
  14. package/node_modules/@capyclaw/browser-workbench/contract/browser-contract.json +45 -19
  15. package/node_modules/@capyclaw/browser-workbench/package.json +7 -7
  16. package/node_modules/@capyclaw/browser-workbench/plugin.mjs +13 -1
  17. package/node_modules/@capyclaw/browser-workbench/server/activate-log.mjs +66 -0
  18. package/node_modules/@capyclaw/browser-workbench/server/contract.mjs +1 -1
  19. package/node_modules/@capyclaw/browser-workbench/server/embedded-host.mjs +23 -2
  20. package/node_modules/@capyclaw/browser-workbench/server/engine.mjs +11 -4
  21. package/node_modules/@capyclaw/browser-workbench/server/routes/api.mjs +2 -2
  22. package/node_modules/@capyclaw/browser-workbench/server/shared/SHARED_MANIFEST.json +4 -4
  23. package/node_modules/@capyclaw/browser-workbench/server/workbench-framework.mjs +34 -0
  24. package/node_modules/@capyclaw/browser-workbench/ui/app.js +87 -10
  25. package/node_modules/@capyclaw/document-workbench/package.json +6 -3
  26. package/node_modules/@capyclaw/document-workbench/src/client/index.mjs +56 -3
  27. package/node_modules/@capyclaw/document-workbench/src/client/visibility.mjs +112 -0
  28. package/node_modules/@capyclaw/document-workbench/src/model/manifest.mjs +6 -4
  29. package/node_modules/@capyclaw/document-workbench/src/model/ops.mjs +7 -2
  30. package/node_modules/@capyclaw/document-workbench/src/session/index.mjs +8 -0
  31. package/node_modules/@capyclaw/document-workbench/src/store/file-backend.mjs +17 -10
  32. package/node_modules/@capyclaw/document-workbench/src/store/projection.mjs +39 -0
  33. package/node_modules/@capyclaw/document-workbench/src/testing/index.mjs +14 -11
  34. package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
  35. package/node_modules/@capyclaw/foundation/abi/bridge.mjs +3 -1
  36. package/node_modules/@capyclaw/foundation/abi/index.mjs +15 -0
  37. package/node_modules/@capyclaw/foundation/abi/loader.mjs +8 -1
  38. package/node_modules/@capyclaw/foundation/abi/spec.mjs +5 -2
  39. package/node_modules/@capyclaw/foundation/abi/version.mjs +63 -5
  40. package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -0
  41. package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +21 -4
  42. package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +5 -1
  43. package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +5 -2
  44. package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +4 -0
  45. package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +29 -2
  46. package/node_modules/@capyclaw/foundation/lib/kernel.mjs +13 -3
  47. package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +12 -2
  48. package/node_modules/@capyclaw/foundation/package.json +1 -1
  49. package/node_modules/@capyclaw/plugin-kit/package.json +3 -1
  50. package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +5 -2
  51. package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
  52. package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +3 -82
  53. package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
  54. package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +13 -5
  55. package/node_modules/@capyclaw/portal/package.json +1 -1
  56. package/node_modules/@capyclaw/service-broker/README.md +1 -1
  57. package/node_modules/@capyclaw/service-broker/lib/control.mjs +23 -7
  58. package/node_modules/@capyclaw/service-broker/lib/engine.mjs +60 -6
  59. package/node_modules/@capyclaw/service-broker/lib/host.mjs +11 -6
  60. package/node_modules/@capyclaw/service-broker/lib/manifest.mjs +15 -2
  61. package/node_modules/@capyclaw/service-broker/lib/recovery.mjs +0 -50
  62. package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +30 -10
  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 +18 -19
  67. package/node_modules/@capyclaw/tool-host/dsh-suite.json +2 -2
  68. package/node_modules/@capyclaw/tool-host/lib/host.mjs +34 -4
  69. package/node_modules/@capyclaw/tool-host/package.json +1 -1
  70. package/node_modules/@capyclaw/tool-host/src/admit-images.mjs +80 -0
  71. package/node_modules/@capyclaw/tool-host/src/caller-session.mjs +25 -0
  72. package/node_modules/@capyclaw/tool-host/src/index.mjs +59 -14
  73. package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +272 -0
  74. package/node_modules/playwright/LICENSE +202 -0
  75. package/node_modules/playwright/NOTICE +5 -0
  76. package/node_modules/playwright/README.md +318 -0
  77. package/node_modules/playwright/ThirdPartyNotices.txt +14 -0
  78. package/node_modules/playwright/cli.js +19 -0
  79. package/node_modules/playwright/index.d.ts +17 -0
  80. package/node_modules/playwright/index.js +17 -0
  81. package/node_modules/playwright/index.mjs +18 -0
  82. package/node_modules/playwright/lib/agents/agentParser.js +89 -0
  83. package/node_modules/playwright/lib/agents/copilot-setup-steps.yml +34 -0
  84. package/node_modules/playwright/lib/agents/generateAgents.js +395 -0
  85. package/node_modules/playwright/lib/agents/playwright-test-coverage.prompt.md +31 -0
  86. package/node_modules/playwright/lib/agents/playwright-test-generate.prompt.md +8 -0
  87. package/node_modules/playwright/lib/agents/playwright-test-generator.agent.md +88 -0
  88. package/node_modules/playwright/lib/agents/playwright-test-heal.prompt.md +6 -0
  89. package/node_modules/playwright/lib/agents/playwright-test-healer.agent.md +56 -0
  90. package/node_modules/playwright/lib/agents/playwright-test-plan.prompt.md +9 -0
  91. package/node_modules/playwright/lib/agents/playwright-test-planner.agent.md +74 -0
  92. package/node_modules/playwright/lib/cli/reportActions.js +78 -0
  93. package/node_modules/playwright/lib/cli/testActions.js +217 -0
  94. package/node_modules/playwright/lib/common/index.js +2937 -0
  95. package/node_modules/playwright/lib/common/index.js.txt +33 -0
  96. package/node_modules/playwright/lib/errorContext.js +129 -0
  97. package/node_modules/playwright/lib/globals.js +58 -0
  98. package/node_modules/playwright/lib/index.js +827 -0
  99. package/node_modules/playwright/lib/isomorphic.js +260 -0
  100. package/node_modules/playwright/lib/isomorphic.js.txt +9 -0
  101. package/node_modules/playwright/lib/loader/loaderProcessEntry.js +34 -0
  102. package/node_modules/playwright/lib/loader/loaderProcessEntry.js.txt +9 -0
  103. package/node_modules/playwright/lib/matchers/expect.js +13496 -0
  104. package/node_modules/playwright/lib/matchers/expect.js.LICENSE +640 -0
  105. package/node_modules/playwright/lib/matchers/expect.js.txt +67 -0
  106. package/node_modules/playwright/lib/package.js +47 -0
  107. package/node_modules/playwright/lib/program.js +242 -0
  108. package/node_modules/playwright/lib/runner/index.js +8721 -0
  109. package/node_modules/playwright/lib/runner/index.js.txt +62 -0
  110. package/node_modules/playwright/lib/transform/babelBundle.js +72490 -0
  111. package/node_modules/playwright/lib/transform/babelBundle.js.LICENSE +2384 -0
  112. package/node_modules/playwright/lib/transform/babelBundle.js.txt +328 -0
  113. package/node_modules/playwright/lib/transform/esmLoader.js +8066 -0
  114. package/node_modules/playwright/lib/transform/esmLoader.js.LICENSE +355 -0
  115. package/node_modules/playwright/lib/transform/esmLoader.js.txt +60 -0
  116. package/node_modules/playwright/lib/util.js +373 -0
  117. package/node_modules/playwright/lib/worker/workerProcessEntry.js +1860 -0
  118. package/node_modules/playwright/lib/worker/workerProcessEntry.js.txt +19 -0
  119. package/node_modules/playwright/package.json +50 -0
  120. package/node_modules/playwright/test.d.ts +18 -0
  121. package/node_modules/playwright/test.js +24 -0
  122. package/node_modules/playwright/test.mjs +35 -0
  123. package/node_modules/playwright/types/test.d.ts +11191 -0
  124. package/node_modules/playwright/types/testReporter.d.ts +950 -0
  125. package/node_modules/playwright-core/LICENSE +202 -0
  126. package/node_modules/playwright-core/NOTICE +5 -0
  127. package/node_modules/playwright-core/README.md +3 -0
  128. package/node_modules/playwright-core/ThirdPartyNotices.txt +13 -0
  129. package/node_modules/playwright-core/bin/install_media_pack.ps1 +5 -0
  130. package/node_modules/playwright-core/bin/install_webkit_wsl.ps1 +33 -0
  131. package/node_modules/playwright-core/bin/reinstall_chrome_beta_linux.sh +42 -0
  132. package/node_modules/playwright-core/bin/reinstall_chrome_beta_mac.sh +13 -0
  133. package/node_modules/playwright-core/bin/reinstall_chrome_beta_win.ps1 +24 -0
  134. package/node_modules/playwright-core/bin/reinstall_chrome_stable_linux.sh +42 -0
  135. package/node_modules/playwright-core/bin/reinstall_chrome_stable_mac.sh +12 -0
  136. package/node_modules/playwright-core/bin/reinstall_chrome_stable_win.ps1 +24 -0
  137. package/node_modules/playwright-core/bin/reinstall_msedge_beta_linux.sh +48 -0
  138. package/node_modules/playwright-core/bin/reinstall_msedge_beta_mac.sh +11 -0
  139. package/node_modules/playwright-core/bin/reinstall_msedge_beta_win.ps1 +23 -0
  140. package/node_modules/playwright-core/bin/reinstall_msedge_dev_linux.sh +48 -0
  141. package/node_modules/playwright-core/bin/reinstall_msedge_dev_mac.sh +11 -0
  142. package/node_modules/playwright-core/bin/reinstall_msedge_dev_win.ps1 +23 -0
  143. package/node_modules/playwright-core/bin/reinstall_msedge_stable_linux.sh +48 -0
  144. package/node_modules/playwright-core/bin/reinstall_msedge_stable_mac.sh +11 -0
  145. package/node_modules/playwright-core/bin/reinstall_msedge_stable_win.ps1 +24 -0
  146. package/node_modules/playwright-core/browsers.json +52 -0
  147. package/node_modules/playwright-core/cli.js +22 -0
  148. package/node_modules/playwright-core/index.d.ts +17 -0
  149. package/node_modules/playwright-core/index.js +17 -0
  150. package/node_modules/playwright-core/index.mjs +28 -0
  151. package/node_modules/playwright-core/lib/bootstrap.js +149 -0
  152. package/node_modules/playwright-core/lib/coreBundle.js +78041 -0
  153. package/node_modules/playwright-core/lib/entry/cliDaemon.js +5 -0
  154. package/node_modules/playwright-core/lib/entry/dashboardApp.js +3 -0
  155. package/node_modules/playwright-core/lib/entry/mcp.js +10 -0
  156. package/node_modules/playwright-core/lib/entry/oopBrowserDownload.js +3 -0
  157. package/node_modules/playwright-core/lib/package.js +50 -0
  158. package/node_modules/playwright-core/lib/server/chromium/appIcon.png +0 -0
  159. package/node_modules/playwright-core/lib/server/electron/loader.js +123 -0
  160. package/node_modules/playwright-core/lib/serverRegistry.js +1939 -0
  161. package/node_modules/playwright-core/lib/serverRegistry.js.LICENSE +65 -0
  162. package/node_modules/playwright-core/lib/tools/cli-client/channelSessions.js +141 -0
  163. package/node_modules/playwright-core/lib/tools/cli-client/cli.js +7 -0
  164. package/node_modules/playwright-core/lib/tools/cli-client/help.json +808 -0
  165. package/node_modules/playwright-core/lib/tools/cli-client/minimist.js +128 -0
  166. package/node_modules/playwright-core/lib/tools/cli-client/output.js +352 -0
  167. package/node_modules/playwright-core/lib/tools/cli-client/program.js +422 -0
  168. package/node_modules/playwright-core/lib/tools/cli-client/registry.js +180 -0
  169. package/node_modules/playwright-core/lib/tools/cli-client/session.js +261 -0
  170. package/node_modules/playwright-core/lib/tools/dashboard/appIcon.png +0 -0
  171. package/node_modules/playwright-core/lib/tools/skills/playwright-cli/SKILL.md +493 -0
  172. package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/element-attributes.md +23 -0
  173. package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/playwright-tests.md +39 -0
  174. package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/pr-attachments.md +60 -0
  175. package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/request-mocking.md +87 -0
  176. package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/running-code.md +245 -0
  177. package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/session-management.md +227 -0
  178. package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/storage-state.md +275 -0
  179. package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/test-generation.md +433 -0
  180. package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/tracing.md +139 -0
  181. package/node_modules/playwright-core/lib/tools/skills/playwright-cli/references/video-recording.md +216 -0
  182. package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/SKILL.md +136 -0
  183. package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/gallery-spec.md +144 -0
  184. package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/migration.md +89 -0
  185. package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/react.md +69 -0
  186. package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/typing.md +173 -0
  187. package/node_modules/playwright-core/lib/tools/skills/playwright-component-testing/references/vue.md +77 -0
  188. package/node_modules/playwright-core/lib/tools/skills/playwright-trace/SKILL.md +174 -0
  189. package/node_modules/playwright-core/lib/tools/utils/extension.js +112 -0
  190. package/node_modules/playwright-core/lib/tools/utils/socketConnection.js +108 -0
  191. package/node_modules/playwright-core/lib/utilsBundle.js +86078 -0
  192. package/node_modules/playwright-core/lib/utilsBundle.js.LICENSE +1890 -0
  193. package/node_modules/playwright-core/lib/vite/dashboard/assets/codeMirrorModule--QdMvsKi.css +1 -0
  194. package/node_modules/playwright-core/lib/vite/dashboard/assets/codeMirrorModule-CQ8RZGBm.js +32 -0
  195. package/node_modules/playwright-core/lib/vite/dashboard/assets/codicon-DCmgc-ay.ttf +0 -0
  196. package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-1bWoP6pv.svg +1 -0
  197. package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-beta-k3eOH_eK.svg +1 -0
  198. package/node_modules/playwright-core/lib/vite/dashboard/assets/firefox-nightly-Cp5nfeDT.svg +1 -0
  199. package/node_modules/playwright-core/lib/vite/dashboard/assets/index-AwgwcYie.css +1 -0
  200. package/node_modules/playwright-core/lib/vite/dashboard/assets/index-hRvO4yU2.js +12 -0
  201. package/node_modules/playwright-core/lib/vite/dashboard/assets/safari-na3_-uQk.svg +1 -0
  202. package/node_modules/playwright-core/lib/vite/dashboard/index.html +29 -0
  203. package/node_modules/playwright-core/lib/vite/dashboard/playwright-logo.svg +24 -0
  204. package/node_modules/playwright-core/lib/vite/htmlReport/index.html +16 -0
  205. package/node_modules/playwright-core/lib/vite/htmlReport/report.css +2 -0
  206. package/node_modules/playwright-core/lib/vite/htmlReport/report.js +32 -0
  207. package/node_modules/playwright-core/lib/vite/recorder/assets/codeMirrorModule--QdMvsKi.css +1 -0
  208. package/node_modules/playwright-core/lib/vite/recorder/assets/codeMirrorModule-DK72OMRi.js +32 -0
  209. package/node_modules/playwright-core/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
  210. package/node_modules/playwright-core/lib/vite/recorder/assets/index-BZpYJZ-P.css +1 -0
  211. package/node_modules/playwright-core/lib/vite/recorder/assets/index-Cn0mmDuv.js +129 -0
  212. package/node_modules/playwright-core/lib/vite/recorder/index.html +29 -0
  213. package/node_modules/playwright-core/lib/vite/recorder/playwright-logo.svg +9 -0
  214. package/node_modules/playwright-core/lib/vite/traceViewer/assets/codeMirrorModule-BEB2e8M3.js +32 -0
  215. package/node_modules/playwright-core/lib/vite/traceViewer/assets/defaultSettingsView-D-g2vrvf.js +184 -0
  216. package/node_modules/playwright-core/lib/vite/traceViewer/assets/urlMatch-L3liM589.js +1 -0
  217. package/node_modules/playwright-core/lib/vite/traceViewer/assets/xtermModule-B794rD2Z.js +7 -0
  218. package/node_modules/playwright-core/lib/vite/traceViewer/codeMirrorModule.-QdMvsKi.css +1 -0
  219. package/node_modules/playwright-core/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
  220. package/node_modules/playwright-core/lib/vite/traceViewer/defaultSettingsView.C8BeHuxd.css +1 -0
  221. package/node_modules/playwright-core/lib/vite/traceViewer/index.B_TqY17P.css +1 -0
  222. package/node_modules/playwright-core/lib/vite/traceViewer/index.html +44 -0
  223. package/node_modules/playwright-core/lib/vite/traceViewer/index.oNry3Hjv.js +1 -0
  224. package/node_modules/playwright-core/lib/vite/traceViewer/manifest.webmanifest +16 -0
  225. package/node_modules/playwright-core/lib/vite/traceViewer/playwright-logo.svg +9 -0
  226. package/node_modules/playwright-core/lib/vite/traceViewer/snapshot.B_Jk1wbt.js +1 -0
  227. package/node_modules/playwright-core/lib/vite/traceViewer/snapshot.html +10 -0
  228. package/node_modules/playwright-core/lib/vite/traceViewer/sw.bundle.js +4 -0
  229. package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CYwC_gH1.js +5 -0
  230. package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.CyMfwkXJ.css +1 -0
  231. package/node_modules/playwright-core/lib/vite/traceViewer/uiMode.html +18 -0
  232. package/node_modules/playwright-core/lib/vite/traceViewer/xtermModule.kHJ-D0s7.css +1 -0
  233. package/node_modules/playwright-core/lib/webp_codec.LICENSE +173 -0
  234. package/node_modules/playwright-core/lib/webp_codec.wasm +0 -0
  235. package/node_modules/playwright-core/lib/xdg-open +1267 -0
  236. package/node_modules/playwright-core/package.json +34 -0
  237. package/node_modules/playwright-core/types/protocol.d.ts +24776 -0
  238. package/node_modules/playwright-core/types/structs.d.ts +52 -0
  239. package/node_modules/playwright-core/types/types.d.ts +27167 -0
  240. package/package.json +15 -14
@@ -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) {
@@ -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'
@@ -2,7 +2,7 @@
2
2
  import { ABI_MAJOR, getInterfaceKind } from './kinds.mjs'
3
3
  import { validateInterface } from './validate.mjs'
4
4
  import { AbiError, ERROR_CODES, toAbiError } from './errors.mjs'
5
- import { satisfies } from './version.mjs'
5
+ import { satisfies, isValidRange } from './version.mjs'
6
6
 
7
7
  const thenable = (value) => value && typeof value.then === 'function'
8
8
 
@@ -164,6 +164,13 @@ export function createLoader({ adapters = {}, capabilities = {}, log = null, abi
164
164
  plugins.delete(spec.name)
165
165
  void previous.handle?.dispose?.()
166
166
  }
167
+ /* 非法范围单独报 E_SCHEMA:旧实现把「range 写错」和「能力真缺」都归成
168
+ * E_CAP_MISSING「能力不可用」,误导排障。先区分两者。 */
169
+ const badRanges = spec.requires.filter((need) => need.name.startsWith('os.') && !isValidRange(need.range))
170
+ if (badRanges.length) {
171
+ throw error(ERROR_CODES.E_SCHEMA, `插件 ${spec.name} 能力范围非法:${badRanges.map((r) => r.raw).join(', ')}`,
172
+ { plugin: spec.name, invalid: badRanges })
173
+ }
167
174
  const missing = spec.requires.filter((need) => need.name.startsWith('os.')
168
175
  && !satisfies(capabilityMap()[need.name] || '', need.range))
169
176
  if (missing.length) {
@@ -191,9 +191,12 @@ export function definePlugin(options = {}) {
191
191
  const requiresEntries = requires.map((entry) => parseCapability(entry, 'requires'))
192
192
  const providesEntries = provides.map((entry) => parseCapability(entry, 'provides'))
193
193
  for (const entry of providesEntries) {
194
- if (/^[\^~<>=]/.test(entry.range)) {
194
+ /* 白名单而非黑名单:provides 必须是完整 x.y.z(可带 prerelease)。旧实现只拒
195
+ * ^~<>= 前缀,'1.x' / '1.*' / 裸 '1' 漏网被当成版本发布,消费方 parseVersion
196
+ * 解析不了 → satisfies 恒 false,能力永远「不可用」。 */
197
+ if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(entry.range)) {
195
198
  throw new AbiError(ERROR_CODES.E_PLUGIN_SHAPE,
196
- `provides 必须写精确版本,不能写范围:${entry.raw}`, { entry: entry.raw })
199
+ `provides 必须写精确版本(x.y.z),不能写范围:${entry.raw}`, { entry: entry.raw })
197
200
  }
198
201
  }
199
202
 
@@ -2,25 +2,57 @@
2
2
  * 版本与范围:能力声明用 `^1` / `^1.2.0` / `>=1.2` / `1.x` / 精确版本。
3
3
  *
4
4
  * 只实现这份 ABI 需要的语义,不引入 semver 依赖:
5
- * - `^1.2.3` → >=1.2.3 且同主版本;`^0.2.3` → >=0.2.3 且同次版本(0.x 约定)
5
+ * - `^1.2.3` → >=1.2.3 且同主版本;`^0.2.3` → >=0.2.3 且同次版本;
6
+ * `^0.0.3` → >=0.0.3 且同补丁(0.0.x 约定,semver 标准)
6
7
  * - `~1.2.3` → >=1.2.3 且同次版本
7
8
  * - `1.x` / `1.*` → 同主版本
8
9
  * - `>=` `>` `<=` `<` `=` 前缀
9
10
  * - 裸版本 → 精确匹配(比较时忽略末位 0)
11
+ * - prerelease 保留并参与比较:1.0.0-beta < 1.0.0;带 prerelease 的版本只满足
12
+ * 同 [major,minor,patch] 且同样带 prerelease 的范围(semver 标准,避免预发布
13
+ * 版本被当成正式版本放行)。
10
14
  */
11
15
 
12
16
  export function parseVersion(text) {
13
17
  if (typeof text !== 'string') return null
14
- const match = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-[0-9A-Za-z.-]+)?$/.exec(text.trim())
18
+ const match = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z.-]+))?$/.exec(text.trim())
15
19
  if (!match) return null
16
- return [Number(match[1]), Number(match[2] || 0), Number(match[3] || 0)]
20
+ const parts = [Number(match[1]), Number(match[2] || 0), Number(match[3] || 0)]
21
+ parts.prerelease = match[4] || null
22
+ return parts
23
+ }
24
+
25
+ function comparePrerelease(a, b) {
26
+ /* 无 prerelease > 有 prerelease(1.0.0 > 1.0.0-beta)。 */
27
+ if (!a && !b) return 0
28
+ if (!a) return 1
29
+ if (!b) return -1
30
+ const left = a.split('.')
31
+ const right = b.split('.')
32
+ for (let i = 0; i < Math.max(left.length, right.length); i++) {
33
+ const x = left[i]
34
+ const y = right[i]
35
+ if (x === undefined) return -1
36
+ if (y === undefined) return 1
37
+ const xn = /^\d+$/.test(x)
38
+ const yn = /^\d+$/.test(y)
39
+ if (xn && yn) {
40
+ const d = Number(x) - Number(y)
41
+ if (d !== 0) return d < 0 ? -1 : 1
42
+ } else if (xn !== yn) {
43
+ return xn ? -1 : 1 // 数字标识符 < 字母数字标识符
44
+ } else if (x !== y) {
45
+ return x < y ? -1 : 1
46
+ }
47
+ }
48
+ return 0
17
49
  }
18
50
 
19
51
  function compareParts(a, b) {
20
52
  for (let i = 0; i < 3; i++) {
21
53
  if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1
22
54
  }
23
- return 0
55
+ return comparePrerelease(a.prerelease || null, b.prerelease || null)
24
56
  }
25
57
 
26
58
  export function compareVersions(a, b) {
@@ -44,12 +76,23 @@ export function satisfies(version, range) {
44
76
  if (raw.startsWith('^')) {
45
77
  const base = parseVersion(raw.slice(1))
46
78
  if (!base) return false
79
+ /* prerelease 只满足同 [major,minor,patch] 且带 prerelease 的范围(semver 标准),
80
+ * 避免 1.1.0-beta 被 ^1.0.0 当正式版本放行。 */
81
+ if (current.prerelease && (!base.prerelease
82
+ || current[0] !== base[0] || current[1] !== base[1] || current[2] !== base[2])) return false
47
83
  if (compareParts(current, base) < 0) return false
48
- return base[0] === 0 ? current[0] === 0 && current[1] === base[1] : current[0] === base[0]
84
+ if (base[0] === 0) {
85
+ /* 0.0.x caret 收紧到补丁位:^0.0.3 只容 0.0.3,不容 0.0.9。 */
86
+ if (base[1] === 0) return current[0] === 0 && current[1] === 0 && current[2] === base[2]
87
+ return current[0] === 0 && current[1] === base[1]
88
+ }
89
+ return current[0] === base[0]
49
90
  }
50
91
  if (raw.startsWith('~')) {
51
92
  const base = parseVersion(raw.slice(1))
52
93
  if (!base) return false
94
+ if (current.prerelease && (!base.prerelease
95
+ || current[0] !== base[0] || current[1] !== base[1] || current[2] !== base[2])) return false
53
96
  return compareParts(current, base) >= 0 && current[0] === base[0] && current[1] === base[1]
54
97
  }
55
98
  if (raw.startsWith('>=')) {
@@ -80,3 +123,18 @@ export function satisfies(version, range) {
80
123
  const exact = parseVersion(raw)
81
124
  return Boolean(exact) && compareParts(current, exact) === 0
82
125
  }
126
+
127
+ /**
128
+ * 范围是否「语义合法」(区别于「合法但不满足」)。供加载器把非法范围单独报
129
+ * E_SCHEMA,而不是误归因成「能力不可用」误导排障。空范围视为「任意」,合法。
130
+ */
131
+ export function isValidRange(range) {
132
+ const raw = String(range ?? '').trim()
133
+ if (!raw || raw === '*' || raw === 'x') return true
134
+ if (/^[\^~]/.test(raw)) return Boolean(parseVersion(raw.slice(1)))
135
+ if (/^(>=|<=)/.test(raw)) return Boolean(parseVersion(raw.slice(2)))
136
+ if (/^[><]/.test(raw)) return Boolean(parseVersion(raw.slice(1)))
137
+ if (raw.startsWith('=')) return isValidRange(raw.slice(1))
138
+ if (/^(\d+)(?:\.(\d+))?\.[x*]$/.test(raw)) return true
139
+ return Boolean(parseVersion(raw))
140
+ }
@@ -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
  }
@@ -11,6 +11,10 @@ import { BASE_CAPABILITIES } from './caps.mjs'
11
11
 
12
12
  const NOOP_LOG = { debug() {}, info() {}, warn() {}, error() {} }
13
13
 
14
+ /* 内存宿主也要有界:app 不 dispose、asset 只 put 不 delete 的用法会让数组/Map
15
+ * 无限增长。app 提供 dispose() 摘除自己;assets 提供 delete() 与上限 LRU 淘汰。 */
16
+ const DEFAULT_MAX_ASSETS = 1024
17
+
14
18
  export function createMemoryHost(options = {}) {
15
19
  const state = {
16
20
  providers: [],
@@ -24,6 +28,9 @@ export function createMemoryHost(options = {}) {
24
28
  plugins: [],
25
29
  }
26
30
  const log = options.log ?? NOOP_LOG
31
+ const maxAssets = Number(options.maxAssets) > 0 ? Number(options.maxAssets) : DEFAULT_MAX_ASSETS
32
+ /* 单调序号:不能用 size+1 拼 id——淘汰后 size 回落,同毫秒内会撞掉已有资产。 */
33
+ let assetSeq = 0
27
34
 
28
35
  function http() {
29
36
  return {
@@ -41,6 +48,11 @@ export function createMemoryHost(options = {}) {
41
48
  }
42
49
  },
43
50
  async dispatch() {},
51
+ dispose() {
52
+ const index = state.apps.indexOf(app)
53
+ if (index >= 0) state.apps.splice(index, 1)
54
+ routes.length = 0
55
+ },
44
56
  }
45
57
  state.apps.push(app)
46
58
  return app
@@ -149,12 +161,27 @@ export function createMemoryHost(options = {}) {
149
161
  }),
150
162
  assets: () => ({
151
163
  async put(value, contentType = 'application/octet-stream') {
152
- const id = `asset-${state.assets.size + 1}`
153
164
  const buffer = Buffer.isBuffer(value) ? value : Buffer.from(String(value))
165
+ /* Map 保持插入序:超限淘汰最旧(LRU 近似),get 命中会刷新到队尾。 */
166
+ while (state.assets.size >= maxAssets) {
167
+ const oldest = state.assets.keys().next().value
168
+ state.assets.delete(oldest)
169
+ }
170
+ const id = `asset-${++assetSeq}`
154
171
  state.assets.set(id, { data: buffer, contentType })
155
172
  return { id, url: `/assets/${id}`, size: buffer.length, contentType }
156
173
  },
157
- get(id) { return state.assets.get(id) },
174
+ get(id) {
175
+ const entry = state.assets.get(id)
176
+ if (entry) { state.assets.delete(id); state.assets.set(id, entry) }
177
+ return entry
178
+ },
179
+ delete(id) { return state.assets.delete(id) },
180
+ gc() {
181
+ const removed = state.assets.size
182
+ state.assets.clear()
183
+ return { removed }
184
+ },
158
185
  }),
159
186
  }
160
187
  }