@capyclaw/ppt-suite 2.5.70 → 2.5.72

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 (109) 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 +4 -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/ledger.mjs +151 -0
  33. package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
  34. package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +13 -5
  35. package/node_modules/@capyclaw/portal/package.json +1 -1
  36. package/node_modules/@capyclaw/ppt-editor/app.js +458 -10
  37. package/node_modules/@capyclaw/ppt-editor/contract/ppt-contract.json +1 -1
  38. package/node_modules/@capyclaw/ppt-editor/heartbeat-worker.js +5 -2
  39. package/node_modules/@capyclaw/ppt-editor/index.html +4 -0
  40. package/node_modules/@capyclaw/ppt-editor/package.json +2 -2
  41. package/node_modules/@capyclaw/ppt-skill-api/contract/ppt-contract.json +1 -1
  42. package/node_modules/@capyclaw/ppt-skill-api/package.json +1 -1
  43. package/node_modules/@capyclaw/ppt-skill-api/skills/pptist-api/references/tool-contract.md +1 -1
  44. package/node_modules/@capyclaw/ppt-skill-proposal/contract/ppt-contract.json +1 -1
  45. package/node_modules/@capyclaw/ppt-skill-proposal/package.json +1 -1
  46. package/node_modules/@capyclaw/ppt-workbench/contract/ppt-contract.json +1 -1
  47. package/node_modules/@capyclaw/ppt-workbench/core/deck-layout.js +3 -1
  48. package/node_modules/@capyclaw/ppt-workbench/core/ops/slide.js +9 -3
  49. package/node_modules/@capyclaw/ppt-workbench/core/text.js +14 -2
  50. package/node_modules/@capyclaw/ppt-workbench/package.json +10 -8
  51. package/node_modules/@capyclaw/ppt-workbench/plugin.mjs +13 -1
  52. package/node_modules/@capyclaw/ppt-workbench/server/contract.mjs +1 -1
  53. package/node_modules/@capyclaw/ppt-workbench/server/embedded-host.mjs +200 -29
  54. package/node_modules/@capyclaw/ppt-workbench/server/relay.mjs +10 -7
  55. package/node_modules/@capyclaw/ppt-workbench/server/shared/SHARED_MANIFEST.json +4 -4
  56. package/node_modules/@capyclaw/ppt-workbench/server/store/backends/file-backend.mjs +3 -0
  57. package/node_modules/@capyclaw/ppt-workbench/server/store/checkpoints.mjs +4 -1
  58. package/node_modules/@capyclaw/ppt-workbench/server/store/index.mjs +4 -0
  59. package/node_modules/@capyclaw/ppt-workbench/server/store/sessions.mjs +139 -4
  60. package/node_modules/@capyclaw/ppt-workbench/server/store/shape.mjs +37 -0
  61. package/node_modules/@capyclaw/service-broker/README.md +1 -1
  62. package/node_modules/@capyclaw/service-broker/lib/host.mjs +11 -6
  63. package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +13 -5
  64. package/node_modules/@capyclaw/service-broker/package.json +1 -1
  65. package/node_modules/@capyclaw/service-host/dsh-suite.json +1 -1
  66. package/node_modules/@capyclaw/service-host/package.json +2 -2
  67. package/node_modules/@capyclaw/service-host/src/index.mjs +45 -27
  68. package/node_modules/@capyclaw/skills-service/README.md +42 -10
  69. package/node_modules/@capyclaw/skills-service/package.json +6 -3
  70. package/node_modules/@capyclaw/skills-service/server.mjs +129 -51
  71. package/node_modules/@capyclaw/suite-kit/README.md +289 -0
  72. package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
  73. package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
  74. package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
  75. package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
  76. package/node_modules/@capyclaw/suite-kit/package.json +58 -0
  77. package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
  78. package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
  79. package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
  80. package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
  81. package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
  82. package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
  83. package/node_modules/@capyclaw/suite-kit/src/host.mjs +251 -0
  84. package/node_modules/@capyclaw/suite-kit/src/index.mjs +24 -0
  85. package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
  86. package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
  87. package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
  88. package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
  89. package/node_modules/@capyclaw/suite-kit/suite.schema.json +128 -0
  90. package/node_modules/@capyclaw/tool-host/dsh-suite.json +1 -1
  91. package/node_modules/@capyclaw/tool-host/lib/host.mjs +15 -4
  92. package/node_modules/@capyclaw/tool-host/package.json +1 -1
  93. package/node_modules/@capyclaw/tool-host/src/index.mjs +19 -5
  94. package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +71 -3
  95. package/node_modules/@capyclaw/work-store/README.md +83 -0
  96. package/node_modules/@capyclaw/work-store/STANDARD.md +263 -0
  97. package/node_modules/@capyclaw/work-store/cordis.patch.yml +3 -0
  98. package/node_modules/@capyclaw/work-store/dsh-suite.json +33 -0
  99. package/node_modules/@capyclaw/work-store/icon.svg +7 -0
  100. package/node_modules/@capyclaw/work-store/lib/host.mjs +21 -0
  101. package/node_modules/@capyclaw/work-store/package.json +68 -0
  102. package/node_modules/@capyclaw/work-store/src/backend.mjs +90 -0
  103. package/node_modules/@capyclaw/work-store/src/db.mjs +199 -0
  104. package/node_modules/@capyclaw/work-store/src/envelope.mjs +132 -0
  105. package/node_modules/@capyclaw/work-store/src/index.mjs +571 -0
  106. package/node_modules/@capyclaw/work-store/src/interop.mjs +70 -0
  107. package/node_modules/@capyclaw/work-store/src/refs.mjs +99 -0
  108. package/node_modules/@capyclaw/work-store/src/routes.mjs +135 -0
  109. package/package.json +16 -14
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 呈现面接线助手(标准 §A.5 / §C.7 双模态):给任意 service-host app 挂上
3
+ * GET /embed.js —— 嵌入握手客户端(suite-kit/client/embed.js 的唯一真源副本)
4
+ * GET /api/surface —— 呈现面自描述(standalone/embeddable/embedPath/协议版本)
5
+ * 套件只需 attachSurface(app, { suite, embedPath }),不必各自复制握手代码。
6
+ * 控制面不分模式:工具/HTTP 接口在两种模式下完全相同。
7
+ */
8
+ import fs from 'node:fs'
9
+ import path from 'node:path'
10
+ import { fileURLToPath } from 'node:url'
11
+ import { EMBED_PROTOCOL_VERSION } from './embed.mjs'
12
+
13
+ const CLIENT_PATH = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'client', 'embed.js')
14
+
15
+ export function attachSurface(app, { suite, embedPath, standalone = true } = {}) {
16
+ if (!app || typeof app.get !== 'function') throw new Error('attachSurface: 需要 service-host app(含 .get)')
17
+ if (typeof suite !== 'string' || !suite) throw new Error('attachSurface: suite 必填')
18
+ if (typeof embedPath !== 'string' || !embedPath.startsWith('/')) throw new Error('attachSurface: embedPath 必须以 / 开头(同源本地地址)')
19
+ app.get('/embed.js', (req, res) => {
20
+ res.writeHead(200, { 'content-type': 'application/javascript; charset=utf-8', 'cache-control': 'no-cache' })
21
+ res.end(fs.readFileSync(CLIENT_PATH, 'utf8'))
22
+ })
23
+ app.get('/api/surface', (req, res) => {
24
+ res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-cache' })
25
+ res.end(JSON.stringify({ ok: true, suite, standalone, embeddable: true, embedPath, protocolVersion: EMBED_PROTOCOL_VERSION }))
26
+ })
27
+ return { suite, embedPath, protocolVersion: EMBED_PROTOCOL_VERSION }
28
+ }
@@ -0,0 +1,128 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://dsh.local/schemas/suite.schema.json",
4
+ "title": "DSH Suite Manifest",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["name", "version", "packages", "rows"],
8
+ "properties": {
9
+ "$schema": { "type": "string" },
10
+ "name": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
11
+ "version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?$" },
12
+ "title": { "type": "string" },
13
+ "description": { "type": "string" },
14
+ "components": {
15
+ "type": "array",
16
+ "items": { "type": "string", "minLength": 1 },
17
+ "description": "引用其他 suite 目录(相对本 suite 目录);加载时展开其 packages/rows/checks。"
18
+ },
19
+ "packages": {
20
+ "type": "object",
21
+ "minProperties": 1,
22
+ "additionalProperties": {
23
+ "type": "object",
24
+ "additionalProperties": false,
25
+ "required": ["role", "version"],
26
+ "properties": {
27
+ "role": {
28
+ "type": "string",
29
+ "enum": ["runtime", "skills", "provider", "ui", "bridge", "support"]
30
+ },
31
+ "version": { "type": "string", "minLength": 1 },
32
+ "path": { "type": "string", "minLength": 1 },
33
+ "required": { "type": "boolean" },
34
+ "requires": {
35
+ "type": "object",
36
+ "properties": {
37
+ "capabilities": {
38
+ "type": "object",
39
+ "additionalProperties": { "type": "string", "minLength": 1 }
40
+ }
41
+ },
42
+ "additionalProperties": { "type": "string", "minLength": 1 }
43
+ },
44
+ "provides": {
45
+ "type": "object",
46
+ "additionalProperties": false,
47
+ "properties": {
48
+ "tools": { "type": "array", "items": { "type": "string" } },
49
+ "skills": { "type": "array", "items": { "type": "string" } },
50
+ "services": { "type": "array", "items": { "type": "string" } },
51
+ "ports": { "type": "array", "items": { "type": "integer", "minimum": 1, "maximum": 65535 } },
52
+ "capabilities": {
53
+ "type": "object",
54
+ "additionalProperties": { "type": "string", "minLength": 1 }
55
+ }
56
+ }
57
+ },
58
+ "surfaceLifecycle": {
59
+ "type": "object",
60
+ "additionalProperties": false,
61
+ "required": ["hooks", "headlessObservation"],
62
+ "description": "表面可见性生命周期标准声明(docs/SURFACE-LIFECYCLE-STANDARD.md §6):四个渲染面钩子齐全 + 无头观察兜底。协议真源 C/packages/capyclaw-foundation/abi/visibility.mjs。",
63
+ "properties": {
64
+ "hooks": {
65
+ "type": "array",
66
+ "items": { "enum": ["onVisibility", "suspendRender", "resumeRender", "rehydrate"] },
67
+ "minItems": 4,
68
+ "maxItems": 4,
69
+ "uniqueItems": true
70
+ },
71
+ "headlessObservation": { "const": true }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ },
77
+ "rows": {
78
+ "type": "array",
79
+ "minItems": 1,
80
+ "items": {
81
+ "type": "object",
82
+ "additionalProperties": false,
83
+ "required": ["id", "name"],
84
+ "properties": {
85
+ "id": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
86
+ "name": { "type": "string", "minLength": 1 },
87
+ "disabled": { "type": "boolean" },
88
+ "config": { "type": "object" }
89
+ }
90
+ }
91
+ },
92
+ "checks": {
93
+ "type": "array",
94
+ "items": {
95
+ "oneOf": [
96
+ {
97
+ "type": "object",
98
+ "additionalProperties": false,
99
+ "required": ["id", "type", "url"],
100
+ "properties": {
101
+ "id": { "type": "string" },
102
+ "type": { "const": "http" },
103
+ "url": { "type": "string", "format": "uri" },
104
+ "method": { "type": "string" },
105
+ "expectStatus": { "type": "integer" },
106
+ "expectBody": { "type": "object" },
107
+ "timeoutMs": { "type": "integer", "minimum": 100 }
108
+ }
109
+ },
110
+ {
111
+ "type": "object",
112
+ "additionalProperties": false,
113
+ "required": ["id", "type", "url", "tool", "major"],
114
+ "properties": {
115
+ "id": { "type": "string" },
116
+ "type": { "const": "contract" },
117
+ "url": { "type": "string", "format": "uri" },
118
+ "tool": { "type": "string" },
119
+ "major": { "type": "integer", "minimum": 0 },
120
+ "timeoutMs": { "type": "integer", "minimum": 100 }
121
+ }
122
+ }
123
+ ]
124
+ }
125
+ },
126
+ "tags": { "type": "array", "items": { "type": "string" } }
127
+ }
128
+ }
@@ -7,7 +7,7 @@
7
7
  "packages": {
8
8
  "@capyclaw/tool-host": {
9
9
  "role": "provider",
10
- "version": "^0.3.0",
10
+ "version": "^0.3.3",
11
11
  "path": ".",
12
12
  "provides": {
13
13
  "services": [
@@ -4,10 +4,12 @@
4
4
  * 同时落地“会话模式锁”这一基础设施能力:
5
5
  * · 把 work-store 惰性解析器注入 toolHost(模式锁的存储真源);
6
6
  * · 给 DSH tools 服务挂全局 guard(异领域调用硬拒兜底);
7
- * · 注册框架核心工具 mode_lock / mode_status(无领域,恒可见)——显式锁定入口。
7
+ * · 注册框架核心工具 mode_lock / mode_status(无领域,恒可见)——显式锁定入口;
8
+ * · 给 DSH systemPrompt 挂动态感知 section(锁定即告知模型主区工作台与交付路径)。
8
9
  * 核心工具与 guard 的注册统一走 modeGate.install(tools)(幂等):apply 时 best-effort 挂一次,
9
10
  * 若那一刻 tools 服务尚未就绪,首个套件注册(registerWithDsh / bridge host)会再调 install 补上,
10
- * 故不依赖加载顺序。所有经 toolHost.registerWithDsh / bridge host 注册的领域能力自动受锁约束,套件零接线。
11
+ * 故不依赖加载顺序。感知闸同理走 modeGate.installPrompt(systemPrompt)。
12
+ * 所有经 toolHost.registerWithDsh / bridge host 注册的领域能力自动受锁约束,套件零接线。
11
13
  */
12
14
  import { defineDriver } from '@capyclaw/foundation/abi'
13
15
  import { createToolHost } from '../src/index.mjs'
@@ -23,12 +25,21 @@ export const { name, inject, apply } = defineDriver({
23
25
  const service = createToolHost({ ...config, getWorkStore: () => safeGet(ctx, 'workStore') })
24
26
  const dispose = ctx.provide('toolHost', service)
25
27
 
26
- /* 模式锁兜底闸 + 核心锁定工具(幂等)。tools 缺席则降级:稍后套件注册时经 install 补挂。 */
28
+ /* 模式锁兜底闸 + 核心锁定工具(幂等)。tools 缺席则降级:稍后套件注册时经 install 补挂。
29
+ * install 返回引用计数 disposer,必须随 driver 卸载释放,否则核心工具/guard 永驻。 */
27
30
  const tools = safeGet(ctx, 'tools')
28
- if (tools && typeof tools.register === 'function') service.modeGate.install(tools)
31
+ const gateDispose = (tools && typeof tools.register === 'function') ? service.modeGate.install(tools) : null
32
+
33
+ /* 感知闸(幂等):锁定会话的系统提示里注入主区工作台感知。systemPrompt 缺席则降级,
34
+ * 稍后套件注册时经 installPrompt 补挂。disposer 同样必须随 driver 卸载释放。 */
35
+ const systemPrompt = safeGet(ctx, 'systemPrompt')
36
+ const promptDispose = (systemPrompt && typeof systemPrompt.section === 'function')
37
+ ? service.modeGate.installPrompt(systemPrompt) : null
29
38
 
30
39
  console.log('[tool-host] ready (mode-gate enabled)')
31
40
  return () => {
41
+ if (typeof promptDispose === 'function') promptDispose()
42
+ if (typeof gateDispose === 'function') gateDispose()
32
43
  if (typeof dispose === 'function') dispose()
33
44
  }
34
45
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capyclaw/tool-host",
3
- "version": "0.3.0",
3
+ "version": "0.3.3",
4
4
  "description": "DSH 公共工具面插件:能力 DSL、工具注册表、参数校验、契约报告、MCP 协议壳与 instructions 模板,向插件提供 ctx.toolHost。",
5
5
  "type": "module",
6
6
  "main": "./lib/host.mjs",
@@ -358,9 +358,21 @@ export function buildInstructions({
358
358
  */
359
359
  export function registerWithDsh(ctx, registry, { namespace = '', domain = '', modeGate = null } = {}) {
360
360
  if (!ctx?.tools?.register) throw new Error('registerWithDsh: 当前 DSH 没有 ctx.tools.register')
361
- /* 领域工具一旦注册即声明给模式锁,并挂全局 guard 兜底(幂等)。 */
362
- if (modeGate) modeGate.install(ctx.tools)
361
+ /* 领域工具一旦注册即声明给模式锁,并挂全局 guard 兜底(幂等)。
362
+ * install 的引用计数 disposer 必须随本次注册一起释放(旧写法丢弃⇒核心工具/guard 泄漏)。 */
363
+ const gateDispose = modeGate ? modeGate.install(ctx.tools) : null
363
364
  const disposers = []
365
+ if (typeof gateDispose === 'function') disposers.push(gateDispose)
366
+ /* 感知闸补挂(幂等):driver apply 那一刻 systemPrompt 可能尚未就绪,套件注册时再挂一次。
367
+ * 引用计数 disposer 随本次注册一起释放。cordis 服务缺席时访问可能抛错,try 包裹降级。 */
368
+ if (modeGate && typeof modeGate.installPrompt === 'function') {
369
+ let systemPrompt = null
370
+ try { systemPrompt = ctx.systemPrompt } catch { systemPrompt = null }
371
+ if (systemPrompt && typeof systemPrompt.section === 'function') {
372
+ const promptDispose = modeGate.installPrompt(systemPrompt)
373
+ if (typeof promptDispose === 'function') disposers.push(promptDispose)
374
+ }
375
+ }
364
376
  try {
365
377
  for (const tool of registry?.TOOLS || []) {
366
378
  const impl = registry.TOOL_IMPL?.[tool.name]
@@ -420,8 +432,10 @@ export function createToolHost(config = {}) {
420
432
  // (driver 注入 () => safeGet(ctx,'workStore'));底座缺席则降级为恒可见、不拒。
421
433
  const modeGate = createModeGate({ getWorkStore: config.getWorkStore })
422
434
  return {
423
- api: createServiceApi('toolHost', '1.2.0', ['dsl', 'registry', 'validate', 'contract', 'mcp', 'instructions', 'native-tools', 'descriptors', 'mode-gate']),
424
- version: '0.3.0',
435
+ // M12 对齐:自报以 package.json 为权威——dsh.apiVersion=1.1.0(对外契约,
436
+ // 消费者 assertServiceApi 只断言 major 1),version=0.3.1。旧自报 1.2.0/0.3.0 是漂移。
437
+ api: createServiceApi('toolHost', '1.1.0', ['dsl', 'registry', 'validate', 'contract', 'mcp', 'instructions', 'native-tools', 'descriptors', 'mode-gate']),
438
+ version: '0.3.1',
425
439
  defineTool,
426
440
  defineCapability,
427
441
  createRegistry: (capabilities, options = {}) => createRegistry(capabilities, { ...config, ...options }),
@@ -429,7 +443,7 @@ export function createToolHost(config = {}) {
429
443
  createToolDispatcher,
430
444
  createCapabilityReport,
431
445
  buildInstructions,
432
- // 服务级注册自动带会话模式锁(when 可见性 + guard 硬拒 + 调用者会话 ALS),套件零接线。
446
+ // 服务级注册自动带会话模式锁(when 可见性 + guard 硬拒 + 感知提示 + 调用者会话 ALS),套件零接线。
433
447
  registerWithDsh: (ctx, registry, options = {}) => registerWithDsh(ctx, registry, { modeGate, ...options }),
434
448
  validateToolArguments,
435
449
  modeGate,
@@ -5,11 +5,15 @@
5
5
  * 该领域的工具;其余已注册能力(browser_* 等)从工具声明里消失,且即便被强行
6
6
  * 调用也在分发层硬拒。所有经 tool-host 注册的能力自动受此约束。
7
7
  *
8
- * 三道原生闸里的两道在此落地:
8
+ * 三道原生闸在此全部落地:
9
9
  * · when(可见性):registerWithDsh / bridge host 给每个领域工具挂 whenFor(name),
10
10
  * DSH 每步 resolve() 求值,false 同时从声明与分发中排除该工具。
11
11
  * · guard(分发硬拒,兜底):install(tools) 挂一个全局 ToolGuard,异领域调用返回
12
12
  * denial。单调不可翻回,兜住任何绕过 when 的路径。
13
+ * · awareness(模型感知):installPrompt(systemPrompt) 注册一个动态提示 section,
14
+ * 每次组装按会话读锁状态,锁定即告知模型「主区工作台是唯一交付界面、用本领域
15
+ * 工具、勿用文件工具绕过」。缺了这道闸,when/guard 只挡得住领域工具,模型仍会
16
+ * 用无 domain 的内置文件工具(write/pwsh/office_*)绕过主区(2026-11-23 根因)。
13
17
  *
14
18
  * 领域来源:TOOL_META.domain(defineTool/defineCapability/createRegistry 声明)。
15
19
  * 存储真源:work-store.getSessionMode(sid)(终生固化,无 unlock)。
@@ -28,6 +32,10 @@ export function createModeGate({ getWorkStore } = {}) {
28
32
  const guardDisposers = []
29
33
  let coreToolsRegistered = false
30
34
  const coreDisposers = []
35
+ let installRefs = 0 // 安装方引用计数(见 install 注释)
36
+ let promptInstalled = false // 感知闸:动态提示 section 是否已注册
37
+ const promptDisposers = []
38
+ let promptRefs = 0 // 感知闸安装方引用计数(与 install 同语义)
31
39
 
32
40
  function store() {
33
41
  try { return typeof getWorkStore === 'function' ? getWorkStore() : null } catch { return null }
@@ -153,7 +161,10 @@ export function createModeGate({ getWorkStore } = {}) {
153
161
  }
154
162
 
155
163
  /** 把 guard + 核心锁定工具挂到 DSH tools 服务(幂等)。每个套件在 tools 就绪时都会调用,
156
- * 故核心工具注册不依赖 tool-host driver apply 那一刻 tools 是否已就绪(加载顺序鲁棒)。返回 disposer。 */
164
+ * 故核心工具注册不依赖 tool-host driver apply 那一刻 tools 是否已就绪(加载顺序鲁棒)。返回 disposer。
165
+ * 引用计数:多个安装方(driver apply / 各套件 registerWithDsh)共享同一份核心注册,
166
+ * 任一安装方卸载只减引用;最后一个释放才真正摘 guard + 核心工具,避免「丢 disposer」泄漏
167
+ * 与「先卸载者拆掉幸存者底座」两种事故。 */
157
168
  function install(tools) {
158
169
  if (!tools) return () => {}
159
170
  if (!guardInstalled && typeof tools.guard === 'function') {
@@ -174,7 +185,13 @@ export function createModeGate({ getWorkStore } = {}) {
174
185
  }
175
186
  coreToolsRegistered = true
176
187
  }
188
+ installRefs++
189
+ let released = false
177
190
  return () => {
191
+ if (released) return
192
+ released = true
193
+ installRefs--
194
+ if (installRefs > 0) return
178
195
  for (const dispose of guardDisposers.splice(0)) {
179
196
  try { dispose() } catch { /* 忽略重复释放 */ }
180
197
  }
@@ -186,6 +203,57 @@ export function createModeGate({ getWorkStore } = {}) {
186
203
  }
187
204
  }
188
205
 
206
+ /**
207
+ * 感知闸文本:锁定会话里注入系统提示,让模型知道主区工作台的存在与唯一交付地位。
208
+ * 只约束「工作台内容任务」的交付路径,不禁止为修插件/查资料等元任务读文件。
209
+ */
210
+ function awarenessText(kind) {
211
+ return `【会话工作模式锁】本会话已锁定为「${kind}」工作模式:GUI 主区界面就是「${kind}」工作台,它是本会话工作台内容任务的指定交付界面。\n`
212
+ + `- 用户要求创作/编辑文档、稿件等工作台内容时,必须用 ${kind}_* 专用工具直接读写主区工作台(先加载 ${kind} 相关 skill),让用户在主区实时看到结果。\n`
213
+ + `- 不得改用 write/pwsh/office_* 等通用文件工具生成独立文件来绕过主区交付;其他领域的工具与技能不适用于本会话。\n`
214
+ + `- 锁终生固化、不可解锁;确需其他领域,请提示用户新开会话。锁状态可用 mode_status 查询。`
215
+ }
216
+
217
+ /**
218
+ * 感知闸:把锁状态作为动态系统提示 section 挂到 DSH systemPrompt 服务(幂等)。
219
+ * text 回调每次 assemble 求值(DSH 每步组装提示时调用),按 context.agent.session.id
220
+ * 读锁:锁定 → 注入感知文本;未锁定/无会话 → 返回 ''(空 section 自动消失,零开销)。
221
+ * 锁可在会话中途被认领(墙上点选),回调动态读取故无需监听 agent 生命周期。
222
+ * 引用计数与 install(tools) 同语义:driver apply 与各套件 registerWithDsh 共享一份注册。
223
+ * 底座缺席(无 systemPrompt / 不支持 section)→ 降级为仅 when/guard 生效。
224
+ * @returns {() => void} 引用计数 disposer
225
+ */
226
+ function installPrompt(systemPrompt) {
227
+ if (!systemPrompt || typeof systemPrompt.section !== 'function') return () => {}
228
+ if (!promptInstalled) {
229
+ try {
230
+ const dispose = systemPrompt.section({
231
+ name: 'capyclaw:session-mode-lock',
232
+ order: 900,
233
+ interpolate: false,
234
+ text: (context) => {
235
+ const kind = modeOf(context?.agent?.session?.id)
236
+ return kind ? awarenessText(kind) : ''
237
+ },
238
+ })
239
+ if (typeof dispose === 'function') promptDisposers.push(dispose)
240
+ promptInstalled = true
241
+ } catch { /* 底座不支持 section 时降级:仅 when/guard 生效 */ }
242
+ }
243
+ promptRefs++
244
+ let released = false
245
+ return () => {
246
+ if (released) return
247
+ released = true
248
+ promptRefs--
249
+ if (promptRefs > 0) return
250
+ for (const dispose of promptDisposers.splice(0)) {
251
+ try { dispose() } catch { /* 忽略重复释放 */ }
252
+ }
253
+ promptInstalled = false
254
+ }
255
+ }
256
+
189
257
  /**
190
258
  * 能力发现面过滤:锁定会话里剔除异领域描述符(conductor_discover 自动受约束)。
191
259
  * 无 domain 的描述符(编排/核心基建)保留。未锁定 → 原样返回。
@@ -200,5 +268,5 @@ export function createModeGate({ getWorkStore } = {}) {
200
268
  })
201
269
  }
202
270
 
203
- return { declareTools, domainOf, modeOf, isVisible, whenFor, guard, install, filterEntries }
271
+ return { declareTools, domainOf, modeOf, isVisible, whenFor, guard, install, installPrompt, filterEntries }
204
272
  }
@@ -0,0 +1,83 @@
1
+ # @capyclaw/work-store
2
+
3
+ > DSH 通用**作品持久化底座**。把各套件(PPT、SVG、未来的任何生成物)的产出统一存进
4
+ > 一个 SQLite 作品库:结构清晰、分类清晰、版本不可变、字节只存引用。
5
+ > 向插件提供 `ctx.workStore`,并预留一组只读 HTTP 查询面,供后期的本地作品浏览界面(类 ddr0 前端)直接消费。
6
+
7
+ 这是 ddr0 平台生产架构(PostgreSQL 存结构化 + 内容寻址对象存储存字节)的**本地单机版**:
8
+ 零第三方依赖、零原生编译(DSH 自带 Node ≥ 22 内置 `node:sqlite`,WAL 自带崩溃安全)。
9
+
10
+ **完整标准见 [STANDARD.md](./STANDARD.md)(v2 已定稿)**:作品模型 / 存储分层 / 引用语法 / 服务 API(1.2.0)/
11
+ 后端契约 / 前端查询面 / 迁移 / **§9 强制条款 V2-1…V2-6(conformance 可验收)** / 附录 A 消费方分层规范。
12
+ 当前 schema 3(迁移执行器自动升级+冷备;v3 新增 artifacts 产物信封表,见 `docs/suite-interop-standard.md`);适配者:PPT(backendFor)与 offline-ddr0(WorkStoreRepository 第二适配者)。
13
+
14
+ ## 两条不可让步的原则
15
+
16
+ 1. **结构化进数据库,非结构化只存引用。** 正文(deck JSON / 稿件 / 配置)落 SQLite;
17
+ 图片/音视频字节**从不进库**,落内容寻址 blob 仓,正文只写 `@asset/<sha256>`。
18
+ 2. **单一真源、低耦合。** 一个作品只有一个权威存储;字节仓委托 `@capyclaw/asset-service`(`ctx.assets`),
19
+ work-store 不自己造 blob 仓。套件之间不互相 import,都只依赖底座。
20
+
21
+ ## 快速接入(套件侧)
22
+
23
+ 持久化后端做成与 `@capyclaw/document-workbench` 的 `FileStateBackend` **同接口**,
24
+ `DocumentSession` 全可选链访问 ⇒ **换后端上层零改**:
25
+
26
+ ```js
27
+ // 宿主:提供 ctx.workStore(defineDriver 自动 provide)
28
+ // 套件:把原来的文件后端换成底座后端,其余一行不改
29
+ const backend = ctx.workStore.backendFor({ suite: 'ppt', kind: 'deck', sessionId })
30
+ const session = new DocumentSession({ backend, documentKey: 'deck', initialDoc, summary })
31
+ ```
32
+
33
+ 文件专属旋钮(`fsyncEvery` / `journalMaxBytes` / tmp+rename)自然退役,由 SQLite WAL 接管崩溃安全。
34
+
35
+ 直接用服务 API 也行:
36
+
37
+ ```js
38
+ const work = ctx.workStore.ensureWork({ suite: 'svg', kind: 'drawing', sessionId, title: '图标' })
39
+ ctx.workStore.writeState(work.id, { seq: 1, svg: '<svg…>' })
40
+ ctx.workStore.saveVersion(work.id, payload, { note: '初版' })
41
+ ctx.workStore.rollback(work.id, 1) // 挪指针 + 恢复状态,历史不可变
42
+ ```
43
+
44
+ ## 前端查询面(预留)
45
+
46
+ `ctx.workStore.routes({ basePath: '/works' })` 暴露只读浏览接口:列表(按 suite/kind/tag/会话筛选、
47
+ 全文搜索、按 updated_at 看最近、分页)、分类统计、单作品、当前文档、版本历史、引用清单、回滚便利口。
48
+ 封面走 `cover_asset → /assets/<sha>`。后期本地作品浏览界面直接调这组接口,无需再动存储层。
49
+
50
+ ## 分类骨架(前端浏览的维度)
51
+
52
+ | 维度 | 字段 | 含义 |
53
+ |---|---|---|
54
+ | 套件 | `suite` | `ppt` / `svg` / …(谁产出的) |
55
+ | 类型 | `kind` | `deck` / `manuscript` / `drawing` / … |
56
+ | 会话 | `session_id` | DSH 会话 id(可空) |
57
+ | 标签 | `tags` | 首标签 = 频道(沿用 ddr0) |
58
+ | 状态 | `status` | 0 隐藏 / 1 正常 / 3 精选 |
59
+
60
+ 自然键 `id = <suite>:<kind>:<session_id|_>`,`ensureWork` 幂等映射同一作品。
61
+
62
+ ## 测试
63
+
64
+ ```bash
65
+ npm test # node --test --test-isolation=none test/*.test.mjs
66
+ ```
67
+
68
+ **34 项**:
69
+ - `work-store.test.mjs`(9):ensureWork 幂等 / writeState 往返 / 后端接口+journal+checkpoint /
70
+ 版本回滚 / listWorks 筛选分页 / updateWork 软删 / refs 三函数 / work_assets 索引 / HTTP 查询面。
71
+ - `document-session.test.mjs`(4,真 `DocumentSession` 集成):push/runBatch/state/checkpoint 全链路落库 /
72
+ 重开完整恢复(重启不丢)/ state 损坏从 checkpoint 恢复 / 版本回滚与状态协同。
73
+ 集成测试用 devDependency 引入 document-workbench,**运行时不耦合**(底座 src 不 import 它)。
74
+ - `storage-v2.test.mjs`(9):v2 增量能力——tx 单事务回滚/禁嵌套 / purgeWork 级联+tombstone /
75
+ work_meta KV / findJournal 字面台账 / 通用 checkpoint 清单 / schema 1→2 迁移+冷备 / 高版本拒开 / PRAGMA。
76
+ - `conformance.test.mjs`(11):**STANDARD v2 强制条款验收**(V2-1…V2-6)——消费方源码扫描禁私开句柄 /
77
+ 组合写中途抛错全回滚+重启指针一致 / v1→v2 自动升级+缺迁移步拒开且原文件不破坏 / close 后句柄释放 /
78
+ 任意 JSON checkpoint+purge 六表无残留+listWorks 截断 total / tx 内台账+findJournal 恰好一次。
79
+ 第二适配者 offline-ddr0 跑对应套件(`B/official/capyclaw-offline-ddr0/test/conformance.test.mjs`)。
80
+
81
+ ## 默认库位置
82
+
83
+ `$DSH_HOME/works/works.db`(缺省 `~/.dsh/works/works.db`);可经 `createWorkStore({ dir })` 或驱动配置覆盖。