@capyclaw/wall-suite 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +20 -2
- package/composition.lock.json +48 -0
- package/contract/wall-contract.json +8 -0
- package/cordis.patch.yml +6 -0
- package/dsh-suite.json +128 -0
- package/lib/index.mjs +6 -0
- package/node_modules/@capyclaw/asset-service/README.md +48 -0
- package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
- package/node_modules/@capyclaw/asset-service/package.json +59 -0
- package/node_modules/@capyclaw/asset-service/src/index.mjs +310 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +88 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +50 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +352 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +258 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +140 -0
- package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -0
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
- package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +72 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +120 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
- package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +38 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +88 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +54 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +187 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +195 -0
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +115 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +198 -0
- package/node_modules/@capyclaw/foundation/package.json +53 -0
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
- package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
- package/node_modules/@capyclaw/plugin-kit/package.json +71 -0
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +60 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +664 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/portal/README.md +70 -0
- package/node_modules/@capyclaw/portal/lib/index.mjs +387 -0
- package/node_modules/@capyclaw/portal/lib/ledger.mjs +194 -0
- package/node_modules/@capyclaw/portal/lib/portal-agent.ps1 +811 -0
- package/node_modules/@capyclaw/portal/lib/portal-darwin.mjs +183 -0
- package/node_modules/@capyclaw/portal/package.json +40 -0
- package/node_modules/@capyclaw/service-broker/README.md +104 -0
- package/node_modules/@capyclaw/service-broker/cordis.patch.yml +8 -0
- package/node_modules/@capyclaw/service-broker/dsh-suite.json +21 -0
- package/node_modules/@capyclaw/service-broker/lib/control.mjs +209 -0
- package/node_modules/@capyclaw/service-broker/lib/discovery.mjs +109 -0
- package/node_modules/@capyclaw/service-broker/lib/engine.mjs +1290 -0
- package/node_modules/@capyclaw/service-broker/lib/host.mjs +187 -0
- package/node_modules/@capyclaw/service-broker/lib/manifest.mjs +262 -0
- package/node_modules/@capyclaw/service-broker/lib/recovery.mjs +275 -0
- package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +48 -0
- package/node_modules/@capyclaw/service-broker/lib/spec.mjs +78 -0
- package/node_modules/@capyclaw/service-broker/package.json +65 -0
- package/node_modules/@capyclaw/service-broker/server.mjs +81 -0
- package/node_modules/@capyclaw/service-broker/service.schema.json +62 -0
- package/node_modules/@capyclaw/service-broker/services.json +3 -0
- package/node_modules/@capyclaw/service-host/README.md +86 -0
- package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
- package/node_modules/@capyclaw/service-host/package.json +60 -0
- package/node_modules/@capyclaw/service-host/src/index.mjs +570 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/tool-host/README.md +56 -0
- package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +46 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/admit-images.mjs +80 -0
- package/node_modules/@capyclaw/tool-host/src/caller-session.mjs +25 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +166 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +461 -0
- package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +272 -0
- package/node_modules/@capyclaw/wall-workbench/README.md +58 -0
- package/node_modules/@capyclaw/wall-workbench/contract/wall-contract.json +8 -0
- package/node_modules/@capyclaw/wall-workbench/lib/host.mjs +1 -0
- package/node_modules/@capyclaw/wall-workbench/package.json +63 -0
- package/node_modules/@capyclaw/wall-workbench/plugin.mjs +13 -0
- package/node_modules/@capyclaw/wall-workbench/server/activate-log.mjs +66 -0
- package/node_modules/@capyclaw/wall-workbench/server/constants.mjs +12 -0
- package/node_modules/@capyclaw/wall-workbench/server/contract.mjs +12 -0
- package/node_modules/@capyclaw/wall-workbench/server/embedded-host.mjs +162 -0
- package/node_modules/@capyclaw/wall-workbench/server/infra/http.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/infra/tuning.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/relay.mjs +68 -0
- package/node_modules/@capyclaw/wall-workbench/server/routes/claim.mjs +46 -0
- package/node_modules/@capyclaw/wall-workbench/server/routes/workbench.mjs +29 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/SHARED_MANIFEST.json +70 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/asset-service.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/editor-host.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/editor/lease.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/service/api.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/service/http.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/service/mcp-http.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/tools/validate.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/tuning.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/util/fs-lock.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/service-host.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/tool-host.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/tuning.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/tools/capabilities/index.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/tools/index.mjs +12 -0
- package/node_modules/@capyclaw/wall-workbench/server/tools.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/workbench-framework.mjs +339 -0
- package/node_modules/@capyclaw/wall-workbench/ui/app.js +225 -0
- package/node_modules/@capyclaw/wall-workbench/ui/index.html +20 -0
- package/node_modules/@capyclaw/wall-workbench/ui/style.css +77 -0
- package/package.json +72 -4
- package/services.json +3 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* B 段提供的运行时框架:工作台 relay 的骨架。
|
|
3
|
+
*
|
|
4
|
+
* 这个文件由 build/bridge-build.mjs 从本目录拷进每个包的 server/workbench-framework.mjs。
|
|
5
|
+
* A 段(projects/<id>/src)只写业务钩子,不再自己拼 HTTP/MCP/锁/发现/独立入口。
|
|
6
|
+
*
|
|
7
|
+
* 框架职责(A 不再考虑):
|
|
8
|
+
* - serviceHost / 内置 createServiceApp 的选择与降级
|
|
9
|
+
* - 端口复用、单实例锁、优雅关闭、请求超时
|
|
10
|
+
* - MCP Streamable HTTP handler 装配与契约拒绝
|
|
11
|
+
* - 对象仓库(/assets)兜底
|
|
12
|
+
* - bridge.json 发现文件写入与清理
|
|
13
|
+
* - 独立运行入口(node server/relay.mjs --port --dir)
|
|
14
|
+
*
|
|
15
|
+
* A 段职责(全部是业务决策):
|
|
16
|
+
* prepare / createStore / routes / health / metrics / tools / instructions / getTuning
|
|
17
|
+
*
|
|
18
|
+
* 两种承载形态,都由框架决定,A 段不选端口:
|
|
19
|
+
* embedded(默认,DSH 宿主进程内)—— 传 `webServer`,应用挂到宿主 HTTP 路由的
|
|
20
|
+
* 前缀下(默认 `/capyclaw/<id>`),**不监听任何端口**,生命周期随 DSH。
|
|
21
|
+
* standalone(仅开发/测试)—— 没传 `webServer` 时按 `port` 自己监听 loopback。
|
|
22
|
+
*
|
|
23
|
+
* 窗口不在这里:桌面窗口是基建能力(@capyclaw/portal-hud 主区舞台)。workbench
|
|
24
|
+
* 只提供页面,就绪时把编辑地址记进活动台账;开不开窗由舞台的内容闸与链接拦截决定。
|
|
25
|
+
*/
|
|
26
|
+
import fs from 'node:fs'
|
|
27
|
+
import os from 'node:os'
|
|
28
|
+
import path from 'node:path'
|
|
29
|
+
import { fileURLToPath } from 'node:url'
|
|
30
|
+
|
|
31
|
+
const PKG_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 返回与历史签名兼容的 startRelay。
|
|
35
|
+
*
|
|
36
|
+
* spec:
|
|
37
|
+
* id / title / packageVersion / contractVersion
|
|
38
|
+
* port / basePath / homeEnv / defaultHome
|
|
39
|
+
* getTuning() 调优参数(A 的业务模块;缺省用框架默认值)
|
|
40
|
+
* contract { version, inspect(dir, version), describe(state) }
|
|
41
|
+
* createStore({ hostDir, backend, packageDir }) => store
|
|
42
|
+
* createAssetStore({ hostDir }) => assetStore | null
|
|
43
|
+
* prepare(ctx) => 额外业务资源(例如浏览器引擎),合并进 ctx
|
|
44
|
+
* routes(ctx) => route[](业务路由,按声明顺序挂载)
|
|
45
|
+
* health(ctx) / metrics(ctx) 业务健康与指标
|
|
46
|
+
* tools(ctx) => { TOOLS, TOOL_IMPL, CAPABILITIES, exemptTool? }
|
|
47
|
+
* instructions(ctx) => string
|
|
48
|
+
* onListening(ctx, info, url) 监听后、装载工具前(设 URL 环境变量、崩溃恢复)
|
|
49
|
+
* resultExtras(ctx) 追加进返回对象的字段(历史形状兼容)
|
|
50
|
+
* beforeStop(ctx) 停服前的业务清理(例如关浏览器)
|
|
51
|
+
*/
|
|
52
|
+
export function createWorkbench(spec) {
|
|
53
|
+
return async function startRelay(options = {}) {
|
|
54
|
+
const {
|
|
55
|
+
port = spec.port,
|
|
56
|
+
/* embedded 形态:宿主(DSH)把 HTTP 路由借给我们,不监听端口。 */
|
|
57
|
+
webServer = null,
|
|
58
|
+
mountPrefix = spec.mountPrefix || `/capyclaw/${spec.id}`,
|
|
59
|
+
hostDir: hostDirOption = null,
|
|
60
|
+
packageDir = spec.packageDir || PKG_ROOT,
|
|
61
|
+
scanLimit = 50,
|
|
62
|
+
lockFile,
|
|
63
|
+
strictPort = false,
|
|
64
|
+
allowReuse = true,
|
|
65
|
+
backend = null,
|
|
66
|
+
assetStore: givenAssetStore = null,
|
|
67
|
+
assetService = null,
|
|
68
|
+
capabilities = null,
|
|
69
|
+
serviceHost = null,
|
|
70
|
+
toolHost = null,
|
|
71
|
+
editorHost = null,
|
|
72
|
+
...extra
|
|
73
|
+
} = options
|
|
74
|
+
|
|
75
|
+
/* 承载形态决定状态目录:embedded 归 DSH 的 `~/.dsh/workbenches/<id>`,
|
|
76
|
+
* standalone(开发/测试)沿用历史 `~/.dsh-<id>-bridge` 之类的位置。 */
|
|
77
|
+
const hostDir = hostDirOption
|
|
78
|
+
|| (spec.homeEnv && process.env[spec.homeEnv])
|
|
79
|
+
|| (webServer
|
|
80
|
+
? path.join(os.homedir(), '.dsh', 'workbenches', spec.id)
|
|
81
|
+
: path.join(os.homedir(), spec.defaultHome || `.dsh-${spec.id}`))
|
|
82
|
+
|
|
83
|
+
const { createServiceApp } = await import('./shared/service-host.mjs')
|
|
84
|
+
const { createMcpHandler } = await import('./shared/kit/service/mcp-http.mjs')
|
|
85
|
+
|
|
86
|
+
const contractState = spec.contract
|
|
87
|
+
? spec.contract.inspect(packageDir, spec.contract.version)
|
|
88
|
+
: { ok: true, checked: 0 }
|
|
89
|
+
if (!contractState.ok) {
|
|
90
|
+
console.error(`[${spec.id}] 契约快照不一致,工具调用将被拒绝:`, spec.contract.describe?.(contractState) || '')
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const store = await spec.createStore({ hostDir, backend, packageDir })
|
|
94
|
+
let assetStore = givenAssetStore
|
|
95
|
+
if (!assetStore && !assetService && spec.createAssetStore) {
|
|
96
|
+
try {
|
|
97
|
+
assetStore = spec.createAssetStore({ hostDir })
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error(`[${spec.id}] 对象仓库不可用(/assets 将返回 503):`, error.message)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const ctx = {
|
|
104
|
+
id: spec.id, hostDir, store, capabilities, contractState, packageDir,
|
|
105
|
+
serviceHost, toolHost, editorHost, assetService, ...extra,
|
|
106
|
+
}
|
|
107
|
+
Object.defineProperty(ctx, 'assetStore', { get: () => assetStore, enumerable: true })
|
|
108
|
+
|
|
109
|
+
/* 资源闭合:createStore/createAssetStore/prepare 都发生在 listen 之前。任何
|
|
110
|
+
* 「没进入正常服务」的路径(prepare 失败、listen 抛错、复用命中)都必须回收
|
|
111
|
+
* 已创建的资源——否则引擎/仓库泄漏在仍存活的进程里(reused 分支的 stop 是
|
|
112
|
+
* no-op,不会有人替它清理)。外部传入的 assetStore 不归本框架关。 */
|
|
113
|
+
let app
|
|
114
|
+
/* 资产仓库周期 GC:默认只清孤儿临时文件(安全——内容寻址资产被稿件引用,
|
|
115
|
+
* 按龄/LRU 淘汰会毁掉旧稿渲染,必须经 tuning 显式 opt-in)。定时器 unref,
|
|
116
|
+
* 不拖住进程退出;所有关闭路径都要清掉它。 */
|
|
117
|
+
let assetGcTimer = null
|
|
118
|
+
const stopAssetGc = () => { if (assetGcTimer) { clearInterval(assetGcTimer); assetGcTimer = null } }
|
|
119
|
+
const closeCreatedResources = async (why) => {
|
|
120
|
+
stopAssetGc()
|
|
121
|
+
try { if (spec.beforeStop) await spec.beforeStop(ctx) } catch (error) { console.error(`[${spec.id}] ${why}:beforeStop 失败`, error?.message || error) }
|
|
122
|
+
try { if (!givenAssetStore) await assetStore?.close?.() } catch (error) { console.error(`[${spec.id}] ${why}:assetStore 关闭失败`, error?.message || error) }
|
|
123
|
+
try { await store?.close?.() } catch (error) { console.error(`[${spec.id}] ${why}:store 关闭失败`, error?.message || error) }
|
|
124
|
+
try { await app?.close?.() } catch (error) { console.error(`[${spec.id}] ${why}:app 关闭失败`, error?.message || error) }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* 业务资源准备(例如浏览器引擎、进程内 session 注入):失败即启动失败。 */
|
|
128
|
+
if (spec.prepare) {
|
|
129
|
+
try {
|
|
130
|
+
Object.assign(ctx, (await spec.prepare(ctx)) || {})
|
|
131
|
+
} catch (error) {
|
|
132
|
+
await closeCreatedResources('prepare 失败')
|
|
133
|
+
throw error
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const createApp = serviceHost?.createApp ? (opts) => serviceHost.createApp(opts) : createServiceApp
|
|
138
|
+
/* 桥声明(来自 foundation declareBridge):对外暴露成 bridgeInfo,
|
|
139
|
+
* 供 suite 清单校验与巡检对齐「声明 vs 运行时」。 */
|
|
140
|
+
const bridgeInfo = spec.bridge
|
|
141
|
+
? { id: spec.bridge.id, protocol: spec.bridge.protocol, model: spec.bridge.model || null, editor: spec.bridge.editor || 'required' }
|
|
142
|
+
: null
|
|
143
|
+
app = createApp({
|
|
144
|
+
id: spec.id,
|
|
145
|
+
title: spec.title,
|
|
146
|
+
version: spec.packageVersion,
|
|
147
|
+
contractVersion: spec.contractVersion,
|
|
148
|
+
health: () => ({
|
|
149
|
+
...(bridgeInfo ? { bridgeInfo } : {}),
|
|
150
|
+
...(spec.health ? spec.health(ctx) : {}),
|
|
151
|
+
contractsOk: contractState.ok,
|
|
152
|
+
contractsChecked: contractState.checked,
|
|
153
|
+
}),
|
|
154
|
+
metrics: () => (spec.metrics ? spec.metrics(ctx) : []),
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
/* routes 里可能要用 app 本身(例如公共 asset-service 的 mount)。 */
|
|
158
|
+
ctx.app = app
|
|
159
|
+
/* 挂载前缀必须在 route 工厂**之前**可见:稿件/图片路由会把给浏览器的媒体地址
|
|
160
|
+
* 拼成 `<mountPath><basePath>/media/<sha>`;embedded 下晚一步设,就会漏掉
|
|
161
|
+
* `/capyclaw/<ns>`,编辑器和导出取图全部 404(2026-11-10 实测)。 */
|
|
162
|
+
const embeddable = !!(webServer && typeof webServer.register === 'function')
|
|
163
|
+
ctx.mountPath = embeddable ? mountPrefix : ''
|
|
164
|
+
for (const route of spec.routes(ctx) || []) app.use(route)
|
|
165
|
+
|
|
166
|
+
const tuning = spec.getTuning ? spec.getTuning() : {}
|
|
167
|
+
let info
|
|
168
|
+
try {
|
|
169
|
+
info = embeddable
|
|
170
|
+
? await app.listen({
|
|
171
|
+
webServer,
|
|
172
|
+
basePath: mountPrefix,
|
|
173
|
+
requestTimeoutMs: Number(tuning.httpRequestTimeoutMs) || 30000,
|
|
174
|
+
headersTimeoutMs: Number(tuning.httpHeadersTimeoutMs) || 10000,
|
|
175
|
+
keepAliveTimeoutMs: Number(tuning.httpKeepAliveTimeoutMs) || 5000,
|
|
176
|
+
})
|
|
177
|
+
: await app.listen({
|
|
178
|
+
port,
|
|
179
|
+
hostDir,
|
|
180
|
+
scanLimit,
|
|
181
|
+
lockFile: lockFile || path.join(hostDir, '.relay-instance.lock'),
|
|
182
|
+
strictPort,
|
|
183
|
+
allowReuse,
|
|
184
|
+
discoveryFile: '',
|
|
185
|
+
requestTimeoutMs: Number(tuning.httpRequestTimeoutMs) || 30000,
|
|
186
|
+
headersTimeoutMs: Number(tuning.httpHeadersTimeoutMs) || 10000,
|
|
187
|
+
keepAliveTimeoutMs: Number(tuning.httpKeepAliveTimeoutMs) || 5000,
|
|
188
|
+
})
|
|
189
|
+
} catch (error) {
|
|
190
|
+
/* listen 抛错(端口冲突/锁失败等)同样要回收已建的 store/引擎,
|
|
191
|
+
* 这里在下方 try 之外,旧代码会让它们永久泄漏。 */
|
|
192
|
+
await closeCreatedResources('listen 失败')
|
|
193
|
+
throw error
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/* info.url 在 embedded 下已经是「origin + 挂载前缀」,standalone 下是 origin。
|
|
197
|
+
* 业务只认 ctx.editorUrl / ctx.url(接口基址),不需要知道端口或前缀。 */
|
|
198
|
+
const base = info.url
|
|
199
|
+
const url = `${base}${spec.basePath || ''}`
|
|
200
|
+
ctx.port = info.port
|
|
201
|
+
ctx.embedded = info.mode === 'embedded'
|
|
202
|
+
ctx.origin = info.mode === 'embedded' ? `http://127.0.0.1:${info.port}` : info.url
|
|
203
|
+
ctx.mountPath = info.mode === 'embedded' ? new URL(base).pathname.replace(/\/$/, '') : ''
|
|
204
|
+
ctx.editorUrl = `${base}/`
|
|
205
|
+
ctx.url = url
|
|
206
|
+
|
|
207
|
+
if (info.reused) {
|
|
208
|
+
/* 复用命中:本进程不提供服务,必须回收已创建的 store/引擎等资源,
|
|
209
|
+
* 否则它们泄漏在仍存活的进程里(下面的 stop 是 no-op,无人清理)。 */
|
|
210
|
+
await closeCreatedResources('复用既有实例')
|
|
211
|
+
return {
|
|
212
|
+
url,
|
|
213
|
+
editorUrl: ctx.editorUrl,
|
|
214
|
+
port: info.port,
|
|
215
|
+
mode: info.mode || 'standalone',
|
|
216
|
+
reused: true,
|
|
217
|
+
...(spec.resultExtras ? spec.resultExtras(ctx) : {}),
|
|
218
|
+
stop: async () => {},
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/* 只有真正提供服务的形态才起周期 GC(reused 形态已回收资源,不起定时器)。
|
|
223
|
+
* tuning.assetGcIntervalMs<=0 可整体关闭;maxAgeMs/maxBytes 缺省 0=不按龄/量淘汰。 */
|
|
224
|
+
if (assetStore && typeof assetStore.gc === 'function') {
|
|
225
|
+
const gcIntervalMs = Number(tuning.assetGcIntervalMs ?? 3600000)
|
|
226
|
+
if (gcIntervalMs > 0) {
|
|
227
|
+
const gcOptions = {
|
|
228
|
+
maxAgeMs: Number(tuning.assetGcMaxAgeMs) || 0,
|
|
229
|
+
maxBytes: Number(tuning.assetGcMaxBytes) || 0,
|
|
230
|
+
}
|
|
231
|
+
const runGc = async () => {
|
|
232
|
+
try {
|
|
233
|
+
const result = await assetStore.gc(gcOptions)
|
|
234
|
+
if (result?.removed || result?.orphanTmpRemoved) {
|
|
235
|
+
console.log(`[${spec.id}] 资产 GC:清理 ${result.removed || 0} 项、孤儿临时文件 ${result.orphanTmpRemoved || 0} 个,释放 ${result.freedBytes || 0} 字节`)
|
|
236
|
+
}
|
|
237
|
+
} catch (error) {
|
|
238
|
+
console.error(`[${spec.id}] 资产 GC 失败(下轮再试):`, error?.message || error)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
assetGcTimer = setInterval(runGc, gcIntervalMs)
|
|
242
|
+
assetGcTimer.unref?.()
|
|
243
|
+
/* 启动即跑一轮:清掉上次进程崩溃留下的孤儿 tmp,不必等第一个周期。 */
|
|
244
|
+
runGc()
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
/* 业务钩子:设置 URL 环境变量、崩溃恢复等(必须在工具装载之前)。 */
|
|
250
|
+
if (spec.onListening) await spec.onListening(ctx, info, url)
|
|
251
|
+
|
|
252
|
+
if (spec.tools) {
|
|
253
|
+
const registry = (await spec.tools(ctx)) || {}
|
|
254
|
+
const TOOLS = registry.TOOLS || []
|
|
255
|
+
ctx.tools = TOOLS
|
|
256
|
+
ctx.toolsRegistry = registry
|
|
257
|
+
const mcpHandler = createMcpHandler({
|
|
258
|
+
tools: TOOLS,
|
|
259
|
+
callTool: (name, args) => {
|
|
260
|
+
if (!contractState.ok && !registry.exemptTool?.(name)) {
|
|
261
|
+
throw new Error(
|
|
262
|
+
`契约快照与运行时 major 不一致,已拒绝 ${name}:` +
|
|
263
|
+
`${spec.contract.describe?.(contractState) || ''}。请重装/升级对应 suite 后重试。`,
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
const impl = registry.TOOL_IMPL[name]
|
|
267
|
+
if (!impl) throw new Error('未知工具: ' + name)
|
|
268
|
+
return impl(args)
|
|
269
|
+
},
|
|
270
|
+
serverInfo: { name: spec.id, version: spec.packageVersion },
|
|
271
|
+
instructions: spec.instructions ? spec.instructions(ctx) : undefined,
|
|
272
|
+
maxBodyBytes: Number(tuning.bodyLimitBytes) || 12 * 1024 * 1024,
|
|
273
|
+
maxBatch: Number(tuning.mcpBatchLimit) || 100,
|
|
274
|
+
})
|
|
275
|
+
ctx.getMcpHandler = () => mcpHandler
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
spec.onStarted?.({ url, port: info.port, hostDir, store, ctx })
|
|
279
|
+
/* 独立端口形态才写发现文件;embedded 的生命周期由宿主 ctx.effect 管。 */
|
|
280
|
+
if (!ctx.embedded) writeDiscovery(hostDir, spec.id, url, info.port)
|
|
281
|
+
return {
|
|
282
|
+
url,
|
|
283
|
+
editorUrl: ctx.editorUrl,
|
|
284
|
+
port: info.port,
|
|
285
|
+
mode: info.mode || 'standalone',
|
|
286
|
+
reused: false,
|
|
287
|
+
tools: ctx.toolsRegistry || null,
|
|
288
|
+
...(spec.resultExtras ? spec.resultExtras(ctx) : {}),
|
|
289
|
+
stop: async () => {
|
|
290
|
+
stopAssetGc()
|
|
291
|
+
if (!ctx.embedded) removeDiscovery(hostDir)
|
|
292
|
+
if (spec.beforeStop) await spec.beforeStop(ctx)
|
|
293
|
+
await info.stop()
|
|
294
|
+
},
|
|
295
|
+
}
|
|
296
|
+
} catch (error) {
|
|
297
|
+
stopAssetGc()
|
|
298
|
+
try { if (!ctx.embedded) removeDiscovery(hostDir) } catch { /* 忽略 */ }
|
|
299
|
+
try { if (spec.beforeStop) await spec.beforeStop(ctx) } catch { /* 忽略 */ }
|
|
300
|
+
try { await info.stop() } catch { /* 忽略 */ }
|
|
301
|
+
throw error
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** 独立运行入口:node server/relay.mjs --port <n> --dir <hostDir>(符号链接安装下也判得准)。 */
|
|
307
|
+
export function runIfMain(moduleUrl, main) {
|
|
308
|
+
if (!process.argv[1]) return false
|
|
309
|
+
let isMain = false
|
|
310
|
+
try {
|
|
311
|
+
isMain = fs.realpathSync(path.resolve(process.argv[1])) === fileURLToPath(moduleUrl)
|
|
312
|
+
} catch {
|
|
313
|
+
isMain = path.resolve(process.argv[1]) === fileURLToPath(moduleUrl)
|
|
314
|
+
}
|
|
315
|
+
if (!isMain) return false
|
|
316
|
+
const arg = (flag, fallback) => {
|
|
317
|
+
const i = process.argv.indexOf(flag)
|
|
318
|
+
return i >= 0 && process.argv[i + 1] ? process.argv[i + 1] : fallback
|
|
319
|
+
}
|
|
320
|
+
main({ port: Number(arg('--port', undefined)) || undefined, dir: arg('--dir', undefined) })
|
|
321
|
+
return true
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function writeDiscovery(hostDir, id, url, port) {
|
|
325
|
+
try {
|
|
326
|
+
fs.mkdirSync(hostDir, { recursive: true })
|
|
327
|
+
fs.writeFileSync(path.join(hostDir, 'bridge.json'), JSON.stringify({
|
|
328
|
+
bridge: id, url, port, pid: process.pid, updated: new Date().toISOString(),
|
|
329
|
+
}, null, 2))
|
|
330
|
+
} catch { /* 发现文件写失败不影响服务 */ }
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function removeDiscovery(hostDir) {
|
|
334
|
+
const file = path.join(hostDir, 'bridge.json')
|
|
335
|
+
try {
|
|
336
|
+
const data = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
337
|
+
if (data.pid === process.pid) fs.rmSync(file, { force: true })
|
|
338
|
+
} catch { /* 不存在或不是本进程写的 */ }
|
|
339
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 展示墙选择器页:
|
|
3
|
+
* - 从主区舞台 /__portal_hud__/state 读已注册的工作台类型(类型无关,不硬编码清单);
|
|
4
|
+
* - 点选 → POST claim 显式认领会话模式(explicit),舞台随后收掉墙、摆出真实工作台;
|
|
5
|
+
* - 舞台换会话时 postMessage 通知本页(retarget):立即回 ack,再按新会话重取清单。
|
|
6
|
+
* - 表面可见性生命周期(标准 §4):收宿主 visibility 信号,存状态并恒回 ack
|
|
7
|
+
* (静态选择页无渲染循环可挂起,宿主靠 ack 判半挂起)。
|
|
8
|
+
*
|
|
9
|
+
* standalone(无 portal-hud)时 state 取不到 → 降级为提示,不报错。
|
|
10
|
+
*/
|
|
11
|
+
(function () {
|
|
12
|
+
'use strict'
|
|
13
|
+
|
|
14
|
+
/* iframe 不继承宿主 CSS 变量:把宿主当前主题的 --dsw-alias-* 计算值镜像到本页 :root,
|
|
15
|
+
使选择墙与 DSH 自带主题同一套肤色(暗色随暗色)。独立打开时保留 CSS 回退色。 */
|
|
16
|
+
var THEME_MAP = [
|
|
17
|
+
['--paper', '--dsw-alias-bg-base'],
|
|
18
|
+
['--card', '--dsw-alias-bg-layer-1'],
|
|
19
|
+
['--ink', '--dsw-alias-label-primary'],
|
|
20
|
+
['--muted', '--dsw-alias-label-secondary'],
|
|
21
|
+
['--line', '--dsw-alias-border-l2'],
|
|
22
|
+
['--accent', '--dsw-alias-brand-primary'],
|
|
23
|
+
['--warn', '--dsw-alias-state-warn-label'],
|
|
24
|
+
['--ok', '--dsw-alias-state-success-primary'],
|
|
25
|
+
]
|
|
26
|
+
var themeObserver = null
|
|
27
|
+
|
|
28
|
+
function syncTheme() {
|
|
29
|
+
try {
|
|
30
|
+
if (!window.parent || window.parent === window) return
|
|
31
|
+
var doc = window.parent.document
|
|
32
|
+
if (!doc || !doc.body) return
|
|
33
|
+
var bodyStyle = window.parent.getComputedStyle(doc.body)
|
|
34
|
+
var htmlStyle = window.parent.getComputedStyle(doc.documentElement)
|
|
35
|
+
var root = document.documentElement
|
|
36
|
+
var found = false
|
|
37
|
+
for (var i = 0; i < THEME_MAP.length; i++) {
|
|
38
|
+
var value = bodyStyle.getPropertyValue(THEME_MAP[i][1]).trim()
|
|
39
|
+
|| htmlStyle.getPropertyValue(THEME_MAP[i][1]).trim()
|
|
40
|
+
if (value) { root.style.setProperty(THEME_MAP[i][0], value); found = true }
|
|
41
|
+
}
|
|
42
|
+
if (found) {
|
|
43
|
+
var dark = doc.body.hasAttribute('data-ds-dark-theme') || doc.documentElement.hasAttribute('data-ds-dark-theme')
|
|
44
|
+
root.style.colorScheme = dark ? 'dark' : 'light'
|
|
45
|
+
}
|
|
46
|
+
} catch (err) { /* 独立或隔离预览保留 CSS 回退色。 */ }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function watchTheme() {
|
|
50
|
+
try {
|
|
51
|
+
if (!window.parent || window.parent === window || typeof MutationObserver === 'undefined') return
|
|
52
|
+
var doc = window.parent.document
|
|
53
|
+
if (!doc || !doc.body) return
|
|
54
|
+
if (themeObserver) themeObserver.disconnect()
|
|
55
|
+
themeObserver = new MutationObserver(syncTheme)
|
|
56
|
+
themeObserver.observe(doc.body, { attributes: true, attributeFilter: ['style', 'data-ds-dark-theme', 'class'] })
|
|
57
|
+
themeObserver.observe(doc.documentElement, { attributes: true, attributeFilter: ['style', 'data-ds-dark-theme', 'class'] })
|
|
58
|
+
} catch (err) { /* 独立或隔离预览保留 CSS 回退色。 */ }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
syncTheme()
|
|
62
|
+
watchTheme()
|
|
63
|
+
window.addEventListener('load', function () { syncTheme(); watchTheme() })
|
|
64
|
+
window.addEventListener('pagehide', function () {
|
|
65
|
+
if (themeObserver) { themeObserver.disconnect(); themeObserver = null }
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
/* 与 service-host 的会话段规则一致:/s/<sid>(sid 字母数字开头,可含 . _ ~ -)。 */
|
|
69
|
+
var SESSION_RE = /\/s\/([A-Za-z0-9][A-Za-z0-9._~-]{0,127})(?=\/|$)/
|
|
70
|
+
|
|
71
|
+
var cardsEl = document.getElementById('cards')
|
|
72
|
+
var statusEl = document.getElementById('status')
|
|
73
|
+
var sid = currentSid()
|
|
74
|
+
var busy = false
|
|
75
|
+
var locked = false
|
|
76
|
+
|
|
77
|
+
function currentSid() {
|
|
78
|
+
var m = SESSION_RE.exec(location.pathname)
|
|
79
|
+
return m ? m[1] : ''
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* 挂载前缀 = 去掉会话段的路径(embedded: /capyclaw/wall;standalone: '')。 */
|
|
83
|
+
function mountBase() {
|
|
84
|
+
return location.pathname.replace(SESSION_RE, '').replace(/\/$/, '')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function setStatus(text, tone) {
|
|
88
|
+
statusEl.textContent = text || ''
|
|
89
|
+
statusEl.className = 'status' + (tone ? ' status-' + tone : '')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function claimUrl() {
|
|
93
|
+
return mountBase() + (sid ? '/s/' + encodeURIComponent(sid) : '') + '/claim'
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function render(surfaces) {
|
|
97
|
+
cardsEl.textContent = ''
|
|
98
|
+
var others = surfaces.filter(function (row) {
|
|
99
|
+
return row && row.slug !== 'wall' && row.id !== 'wall-workbench'
|
|
100
|
+
})
|
|
101
|
+
if (!others.length) {
|
|
102
|
+
setStatus('当前 profile 没有注册其他工作台。安装相应套件(如 ppt-suite / browser-suite)后刷新。', 'warn')
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
others.forEach(function (row) {
|
|
106
|
+
var card = document.createElement('button')
|
|
107
|
+
card.type = 'button'
|
|
108
|
+
card.className = 'card'
|
|
109
|
+
card.dataset.kind = row.slug
|
|
110
|
+
var title = document.createElement('span')
|
|
111
|
+
title.className = 'card-title'
|
|
112
|
+
title.textContent = row.title || row.slug
|
|
113
|
+
var slug = document.createElement('span')
|
|
114
|
+
slug.className = 'card-slug'
|
|
115
|
+
slug.textContent = row.slug
|
|
116
|
+
card.appendChild(title)
|
|
117
|
+
card.appendChild(slug)
|
|
118
|
+
card.addEventListener('click', function () { choose(row.slug, card) })
|
|
119
|
+
cardsEl.appendChild(card)
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function lockCards() {
|
|
124
|
+
locked = true
|
|
125
|
+
var cards = cardsEl.querySelectorAll('.card')
|
|
126
|
+
for (var i = 0; i < cards.length; i++) cards[i].disabled = true
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function unlockCards() {
|
|
130
|
+
locked = false
|
|
131
|
+
var cards = cardsEl.querySelectorAll('.card')
|
|
132
|
+
for (var i = 0; i < cards.length; i++) cards[i].disabled = false
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function choose(kind, card) {
|
|
136
|
+
if (busy || locked) return
|
|
137
|
+
busy = true
|
|
138
|
+
card.classList.add('card-busy')
|
|
139
|
+
setStatus('正在锁定「' + kind + '」…')
|
|
140
|
+
fetch(claimUrl(), {
|
|
141
|
+
method: 'POST',
|
|
142
|
+
headers: { 'content-type': 'application/json' },
|
|
143
|
+
body: JSON.stringify({ sid: sid, kind: kind }),
|
|
144
|
+
}).then(function (res) {
|
|
145
|
+
return res.json().catch(function () { return { ok: false, error: '响应不是 JSON' } })
|
|
146
|
+
}).then(function (result) {
|
|
147
|
+
busy = false
|
|
148
|
+
card.classList.remove('card-busy')
|
|
149
|
+
if (result && result.ok) {
|
|
150
|
+
lockCards()
|
|
151
|
+
if (result.skipped) {
|
|
152
|
+
setStatus('已选择「' + kind + '」(standalone 形态没有会话模式底座,未启用锁定)。', 'warn')
|
|
153
|
+
} else {
|
|
154
|
+
setStatus('已锁定「' + kind + '」。主区将切换到对应工作台。', 'ok')
|
|
155
|
+
}
|
|
156
|
+
} else if (result && result.lockedTo) {
|
|
157
|
+
setStatus('本会话已固化为「' + result.lockedTo + '」,不能再选「' + kind + '」。请新开一个会话。', 'warn')
|
|
158
|
+
} else {
|
|
159
|
+
setStatus('认领失败:' + ((result && result.error) || '未知错误'), 'warn')
|
|
160
|
+
}
|
|
161
|
+
}).catch(function (err) {
|
|
162
|
+
busy = false
|
|
163
|
+
card.classList.remove('card-busy')
|
|
164
|
+
setStatus('认领请求失败:' + (err && err.message ? err.message : err), 'warn')
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function loadState() {
|
|
169
|
+
var url = '/__portal_hud__/state' + (sid ? '?sid=' + encodeURIComponent(sid) : '')
|
|
170
|
+
return fetch(url).then(function (res) {
|
|
171
|
+
if (!res.ok) throw new Error('HTTP ' + res.status)
|
|
172
|
+
return res.json()
|
|
173
|
+
}).then(function (data) {
|
|
174
|
+
render((data && data.surfaces) || [])
|
|
175
|
+
if (!locked) setStatus('')
|
|
176
|
+
}).catch(function () {
|
|
177
|
+
cardsEl.textContent = ''
|
|
178
|
+
setStatus('读不到已注册的工作台(standalone 形态没有主区舞台注册信息)。请在 DSH 宿主内打开本页。', 'warn')
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* ---- 表面可见性生命周期(标准 §4 信号通道,阶段3) ----
|
|
183
|
+
* 本 UI 无构建、原样拷贝部署(build-plugin.mjs copyDirs),不能 import 共享包,
|
|
184
|
+
* 故内联一个最小 visibility 订阅器(照 browser src/ui/app.js 先例)。展示墙是
|
|
185
|
+
* 静态选择页:没有渲染循环可挂起/恢复,只把表面状态存下来(平凡实现);但必须
|
|
186
|
+
* 恒回 ack——宿主靠 ack 判半挂起(标准 §4 兜底)。协议常量真源:
|
|
187
|
+
* C/packages/capyclaw-foundation/abi/visibility.mjs —— 改那边必须同步这里。 */
|
|
188
|
+
var VISIBILITY_MESSAGE = 'capyclaw:workbench:visibility'
|
|
189
|
+
var VISIBILITY_ACK_MESSAGE = 'capyclaw:workbench:visibility-ack'
|
|
190
|
+
var VISIBILITY_STATES = ['foreground', 'background', 'hidden', 'detached']
|
|
191
|
+
var visibilityState = 'foreground'
|
|
192
|
+
|
|
193
|
+
function onVisibilityMessage(event) {
|
|
194
|
+
if (event.origin !== location.origin) return
|
|
195
|
+
var data = event.data
|
|
196
|
+
if (!data || data.type !== VISIBILITY_MESSAGE) return
|
|
197
|
+
if (VISIBILITY_STATES.indexOf(data.state) === -1) return
|
|
198
|
+
/* 静态页无渲染面可挂起/恢复:状态存下来即可(suspendRender/resumeRender 平凡)。 */
|
|
199
|
+
visibilityState = data.state
|
|
200
|
+
/* 无条件回 ack(即使状态未变,宿主可重发):ack 形状与 abi 一致。 */
|
|
201
|
+
try {
|
|
202
|
+
if (event.source) {
|
|
203
|
+
event.source.postMessage({ type: VISIBILITY_ACK_MESSAGE, state: data.state, sid: data.sid }, event.origin)
|
|
204
|
+
}
|
|
205
|
+
} catch (err) { /* 回执失败不致命 */ }
|
|
206
|
+
}
|
|
207
|
+
window.addEventListener('message', onVisibilityMessage)
|
|
208
|
+
|
|
209
|
+
/* 舞台 retarget:同工作台换会话不重载 iframe,只 postMessage。
|
|
210
|
+
* 必须立刻回 ack(父侧 600ms 无 ack 会硬重载),再按新会话重取清单。 */
|
|
211
|
+
window.addEventListener('message', function (e) {
|
|
212
|
+
if (e.origin !== location.origin) return
|
|
213
|
+
var d = e.data
|
|
214
|
+
if (!d || d.type !== 'capyclaw:workbench:session') return
|
|
215
|
+
sid = String(d.sid || '')
|
|
216
|
+
if (e.source && typeof e.source.postMessage === 'function') {
|
|
217
|
+
e.source.postMessage({ type: 'capyclaw:workbench:session-ack', sid: sid }, location.origin)
|
|
218
|
+
}
|
|
219
|
+
unlockCards()
|
|
220
|
+
setStatus('')
|
|
221
|
+
loadState()
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
loadState()
|
|
225
|
+
})()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>展示墙 · 选择要做什么</title>
|
|
7
|
+
<link rel="stylesheet" href="style.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<main class="wall">
|
|
11
|
+
<header class="wall-head">
|
|
12
|
+
<h1>选择要做什么</h1>
|
|
13
|
+
<p class="wall-sub">这个会话还没有绑定工作台。选一个类型,本会话将固定使用它。</p>
|
|
14
|
+
</header>
|
|
15
|
+
<div id="cards" class="cards" aria-live="polite"></div>
|
|
16
|
+
<p id="status" class="status" role="status"></p>
|
|
17
|
+
</main>
|
|
18
|
+
<script src="app.js"></script>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* 展示墙选择器:直接复用宿主 DSH 主题肤色(--dsw-alias-*),铺满主区容器(无窗壳)。
|
|
2
|
+
iframe 不继承父页 CSS 变量:app.js 会把宿主计算值镜像到本页 :root;
|
|
3
|
+
这里的 var() 回退色仅在独立打开(无宿主)时生效。 */
|
|
4
|
+
:root {
|
|
5
|
+
--paper: var(--dsw-alias-bg-base, #f7f7f5);
|
|
6
|
+
--card: var(--dsw-alias-bg-layer-1, #fff);
|
|
7
|
+
--ink: var(--dsw-alias-label-primary, #1c1e21);
|
|
8
|
+
--muted: var(--dsw-alias-label-secondary, #6b7075);
|
|
9
|
+
--line: var(--dsw-alias-border-l2, #e3e4e0);
|
|
10
|
+
--accent: var(--dsw-alias-brand-primary, #2f6f4f);
|
|
11
|
+
--accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
|
|
12
|
+
--warn: var(--dsw-alias-state-warn-label, #8a5a00);
|
|
13
|
+
--ok: var(--dsw-alias-state-success-primary, #2f6f4f);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
* { box-sizing: border-box; }
|
|
17
|
+
|
|
18
|
+
html, body {
|
|
19
|
+
margin: 0;
|
|
20
|
+
height: 100%;
|
|
21
|
+
background: var(--paper);
|
|
22
|
+
color: var(--ink);
|
|
23
|
+
font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.wall {
|
|
27
|
+
min-height: 100%;
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
align-items: center;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
padding: 48px 24px 96px; /* 底部留白避开抬高的输入框底座 */
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.wall-head { text-align: center; margin-bottom: 32px; }
|
|
36
|
+
.wall-head h1 { font-size: 28px; font-weight: 600; margin: 0 0 8px; letter-spacing: .02em; }
|
|
37
|
+
.wall-sub { margin: 0; color: var(--muted); font-size: 14px; }
|
|
38
|
+
|
|
39
|
+
.cards {
|
|
40
|
+
display: grid;
|
|
41
|
+
grid-template-columns: repeat(auto-fit, minmax(200px, 260px));
|
|
42
|
+
gap: 16px;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
width: 100%;
|
|
45
|
+
max-width: 900px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.card {
|
|
49
|
+
display: flex;
|
|
50
|
+
flex-direction: column;
|
|
51
|
+
gap: 6px;
|
|
52
|
+
align-items: flex-start;
|
|
53
|
+
padding: 20px 22px;
|
|
54
|
+
background: var(--card);
|
|
55
|
+
border: 1px solid var(--line);
|
|
56
|
+
border-radius: 12px;
|
|
57
|
+
cursor: pointer;
|
|
58
|
+
text-align: left;
|
|
59
|
+
font: inherit;
|
|
60
|
+
color: inherit;
|
|
61
|
+
transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
|
|
62
|
+
}
|
|
63
|
+
.card:hover:not(:disabled) {
|
|
64
|
+
border-color: var(--accent);
|
|
65
|
+
box-shadow: 0 4px 16px color-mix(in srgb, var(--ink) 8%, transparent);
|
|
66
|
+
transform: translateY(-2px);
|
|
67
|
+
}
|
|
68
|
+
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
69
|
+
.card:disabled { opacity: .55; cursor: default; }
|
|
70
|
+
.card-busy { border-color: var(--accent); background: var(--accent-soft); }
|
|
71
|
+
|
|
72
|
+
.card-title { font-size: 17px; font-weight: 600; }
|
|
73
|
+
.card-slug { font-size: 12px; color: var(--muted); font-family: Consolas, monospace; }
|
|
74
|
+
|
|
75
|
+
.status { margin-top: 28px; min-height: 20px; font-size: 14px; color: var(--muted); text-align: center; }
|
|
76
|
+
.status-ok { color: var(--ok); }
|
|
77
|
+
.status-warn { color: var(--warn); }
|