@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,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话模式锁 —— 工具面标准框架的强制闸(基础设施能力,非各套件自接)。
|
|
3
|
+
*
|
|
4
|
+
* 设计目标(用户诉求):锁定一种工作模式(如 rsp)后,本会话只看得见、调得动
|
|
5
|
+
* 该领域的工具;其余已注册能力(browser_* 等)从工具声明里消失,且即便被强行
|
|
6
|
+
* 调用也在分发层硬拒。所有经 tool-host 注册的能力自动受此约束。
|
|
7
|
+
*
|
|
8
|
+
* 三道原生闸在此全部落地:
|
|
9
|
+
* · when(可见性):registerWithDsh / bridge host 给每个领域工具挂 whenFor(name),
|
|
10
|
+
* DSH 每步 resolve() 求值,false 同时从声明与分发中排除该工具。
|
|
11
|
+
* · guard(分发硬拒,兜底):install(tools) 挂一个全局 ToolGuard,异领域调用返回
|
|
12
|
+
* denial。单调不可翻回,兜住任何绕过 when 的路径。
|
|
13
|
+
* · awareness(模型感知):installPrompt(systemPrompt) 注册一个动态提示 section,
|
|
14
|
+
* 每次组装按会话读锁状态,锁定即告知模型「主区工作台是唯一交付界面、用本领域
|
|
15
|
+
* 工具、勿用文件工具绕过」。缺了这道闸,when/guard 只挡得住领域工具,模型仍会
|
|
16
|
+
* 用无 domain 的内置文件工具(write/pwsh/office_*)绕过主区(2026-11-23 根因)。
|
|
17
|
+
*
|
|
18
|
+
* 领域来源:TOOL_META.domain(defineTool/defineCapability/createRegistry 声明)。
|
|
19
|
+
* 存储真源:work-store.getSessionMode(sid)(终生固化,无 unlock)。
|
|
20
|
+
* 降级:无 workStore / 无 sid / 未锁定 → 恒可见、不拒(与既有“底座缺席不启用”一致)。
|
|
21
|
+
* 无 domain 的工具(conductor/capyclaw/框架核心 mode_*)恒可见,不受锁限制。
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {{ getWorkStore?: () => object|null }} deps
|
|
26
|
+
*/
|
|
27
|
+
export function createModeGate({ getWorkStore } = {}) {
|
|
28
|
+
const domainByTool = new Map() // 原生工具名 → domain
|
|
29
|
+
const domainBySuite = new Map() // 套件名 → domain(描述符发现面按 suite 兜底)
|
|
30
|
+
const lockCache = new Map() // sid → kind(锁终生固化,一旦落定永不变更,可缓存)
|
|
31
|
+
let guardInstalled = false
|
|
32
|
+
const guardDisposers = []
|
|
33
|
+
let coreToolsRegistered = false
|
|
34
|
+
const coreDisposers = []
|
|
35
|
+
let installRefs = 0 // 安装方引用计数(见 install 注释)
|
|
36
|
+
let promptInstalled = false // 感知闸:动态提示 section 是否已注册
|
|
37
|
+
const promptDisposers = []
|
|
38
|
+
let promptRefs = 0 // 感知闸安装方引用计数(与 install 同语义)
|
|
39
|
+
|
|
40
|
+
function store() {
|
|
41
|
+
try { return typeof getWorkStore === 'function' ? getWorkStore() : null } catch { return null }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 当前会话锁定的工作模式 kind;未锁定/底座缺席/无 sid → null。 */
|
|
45
|
+
function modeOf(sessionId) {
|
|
46
|
+
const sid = String(sessionId || '').trim()
|
|
47
|
+
if (!sid) return null
|
|
48
|
+
if (lockCache.has(sid)) return lockCache.get(sid)
|
|
49
|
+
const ws = store()
|
|
50
|
+
if (!ws || typeof ws.getSessionMode !== 'function') return null
|
|
51
|
+
let rec = null
|
|
52
|
+
try { rec = ws.getSessionMode(sid) } catch { return null }
|
|
53
|
+
const kind = rec && rec.kind ? String(rec.kind) : null
|
|
54
|
+
if (kind) lockCache.set(sid, kind) // 只缓存已落定的锁;null 不缓存(可能稍后被认领)
|
|
55
|
+
return kind
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 领域工具在指定会话里是否可见。无 domain / 未锁定 / 同领域 → 可见。 */
|
|
59
|
+
function isVisible(domain, sessionId) {
|
|
60
|
+
if (!domain) return true
|
|
61
|
+
const lock = modeOf(sessionId)
|
|
62
|
+
return !lock || domain === lock
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 声明一组工具属于某领域(registerWithDsh / bridge host 注册时调用)。 */
|
|
66
|
+
function declareTools(domain, names = [], suite = domain) {
|
|
67
|
+
const d = String(domain || '').trim()
|
|
68
|
+
if (!d) return
|
|
69
|
+
for (const name of names || []) {
|
|
70
|
+
if (name) domainByTool.set(String(name), d)
|
|
71
|
+
}
|
|
72
|
+
if (suite) domainBySuite.set(String(suite), d)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** 某工具的领域;未声明 → ''(恒可见)。 */
|
|
76
|
+
function domainOf(name) {
|
|
77
|
+
return domainByTool.get(String(name)) || ''
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* DSH register 的 when 条件。未声明领域的工具返回 undefined(不挂 when,恒可见,
|
|
82
|
+
* 也避免给内置/核心工具增加每步求值开销)。
|
|
83
|
+
* @returns {((context: object) => boolean)|undefined}
|
|
84
|
+
*/
|
|
85
|
+
function whenFor(name) {
|
|
86
|
+
const domain = domainOf(name)
|
|
87
|
+
if (!domain) return undefined
|
|
88
|
+
return (context) => isVisible(domain, context?.agent?.session?.id)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 全局 ToolGuard(分发硬拒兜底)。非领域工具立即放行(不读 store,内置工具零开销);
|
|
93
|
+
* 领域工具在异领域锁定的会话里返回 denial。
|
|
94
|
+
* @returns {{reason: string, info: object}|undefined}
|
|
95
|
+
*/
|
|
96
|
+
function guard(execution) {
|
|
97
|
+
const name = execution?.name
|
|
98
|
+
const domain = domainByTool.get(String(name))
|
|
99
|
+
if (!domain) return undefined
|
|
100
|
+
const lock = modeOf(execution?.agent?.session?.id)
|
|
101
|
+
if (!lock || domain === lock) return undefined
|
|
102
|
+
return {
|
|
103
|
+
reason: `本会话已锁定为「${lock}」工作模式,「${name}」属于「${domain}」领域,已被框架屏蔽。`
|
|
104
|
+
+ `请只用「${lock}」领域的工具完成任务;确需其他领域,请新开一个会话。`,
|
|
105
|
+
info: { name: 'SessionModeLocked', code: 'SESSION_MODE_LOCKED', reason: `locked to ${lock}, tool domain ${domain}` },
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 框架核心工具 mode_lock / mode_status(无领域,恒可见)——显式锁定入口与状态查询。
|
|
110
|
+
* 存储经 modeGate 的 getWorkStore 解析(不依赖插件 ctx),故可在任何 tools 就绪时机注册。 */
|
|
111
|
+
function coreTools() {
|
|
112
|
+
const textRender = (_args, value) => [{ type: 'text', text: typeof value === 'string' ? value : JSON.stringify(value, null, 2) }]
|
|
113
|
+
const OUTPUT_SCHEMA = { type: 'object', additionalProperties: true }
|
|
114
|
+
const modeLock = {
|
|
115
|
+
name: 'mode_lock',
|
|
116
|
+
description: '把当前会话锁定到一种工作模式(领域),如 rsp/browser/ppt/canvas。锁定后本会话只看得见、调得动该领域的工具,'
|
|
117
|
+
+ '其余领域能力被框架从工具面屏蔽并在分发层硬拒。锁终生固化、不可解锁;确需其他领域请新开一个会话。',
|
|
118
|
+
parameters: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
properties: { kind: { type: 'string', description: '要锁定的工作模式/领域,如 rsp、browser、ppt、canvas' } },
|
|
121
|
+
required: ['kind'],
|
|
122
|
+
additionalProperties: false,
|
|
123
|
+
},
|
|
124
|
+
output: { schema: OUTPUT_SCHEMA, render: textRender },
|
|
125
|
+
execute: async (args, exec) => {
|
|
126
|
+
const kind = String(args?.kind || '').trim()
|
|
127
|
+
if (!kind) return { ok: false, error: '需要 kind(要锁定的工作模式/领域)' }
|
|
128
|
+
const sid = exec?.agent?.session?.id
|
|
129
|
+
if (!sid) return { ok: false, error: '无法识别当前会话,不能锁定' }
|
|
130
|
+
const ws = store()
|
|
131
|
+
if (!ws || typeof ws.claimSessionMode !== 'function') return { ok: false, error: 'work-store 底座缺席,无法锁定' }
|
|
132
|
+
const res = ws.claimSessionMode(sid, kind, 'mode-lock', { explicit: true })
|
|
133
|
+
if (res && res.ok === false) {
|
|
134
|
+
return { ok: false, lockedTo: res.lockedTo, error: `本会话已固化为「${res.lockedTo}」模式,不能改为「${kind}」。确需其他领域请新开一个会话。` }
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
ok: true, kind: res.kind, fresh: !!res.fresh, explicit: true,
|
|
138
|
+
message: res.fresh ? `已锁定为「${res.kind}」工作模式,本会话此后只用该领域工具。` : `本会话已处于「${res.kind}」工作模式。`,
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
const modeStatus = {
|
|
143
|
+
name: 'mode_status',
|
|
144
|
+
description: '查询当前会话的工作模式锁状态:是否锁定、锁定到哪个领域、由谁何时认领。未锁定时所有领域工具可见。',
|
|
145
|
+
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
146
|
+
output: { schema: OUTPUT_SCHEMA, render: textRender },
|
|
147
|
+
execute: async (_args, exec) => {
|
|
148
|
+
const sid = exec?.agent?.session?.id
|
|
149
|
+
const ws = store()
|
|
150
|
+
if (!ws || typeof ws.getSessionMode !== 'function') return { locked: false, reason: 'work-store 底座缺席' }
|
|
151
|
+
if (!sid) return { locked: false, reason: '无法识别当前会话' }
|
|
152
|
+
const rec = ws.getSessionMode(sid)
|
|
153
|
+
if (!rec) return { locked: false, kind: null, message: '本会话未锁定工作模式,所有领域工具可见。' }
|
|
154
|
+
return {
|
|
155
|
+
locked: true, kind: rec.kind, claimedBy: rec.claimedBy || '', claimedAt: rec.claimedAt || '', explicit: !!rec.explicit,
|
|
156
|
+
message: `本会话已锁定为「${rec.kind}」工作模式,其余领域工具已被屏蔽。`,
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
return [modeLock, modeStatus]
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** 把 guard + 核心锁定工具挂到 DSH tools 服务(幂等)。每个套件在 tools 就绪时都会调用,
|
|
164
|
+
* 故核心工具注册不依赖 tool-host driver apply 那一刻 tools 是否已就绪(加载顺序鲁棒)。返回 disposer。
|
|
165
|
+
* 引用计数:多个安装方(driver apply / 各套件 registerWithDsh)共享同一份核心注册,
|
|
166
|
+
* 任一安装方卸载只减引用;最后一个释放才真正摘 guard + 核心工具,避免「丢 disposer」泄漏
|
|
167
|
+
* 与「先卸载者拆掉幸存者底座」两种事故。 */
|
|
168
|
+
function install(tools) {
|
|
169
|
+
if (!tools) return () => {}
|
|
170
|
+
if (!guardInstalled && typeof tools.guard === 'function') {
|
|
171
|
+
try {
|
|
172
|
+
const dispose = tools.guard(guard)
|
|
173
|
+
if (typeof dispose === 'function') guardDisposers.push(dispose)
|
|
174
|
+
guardInstalled = true
|
|
175
|
+
} catch { /* 底座不支持 guard 时降级:仅 when 生效 */ }
|
|
176
|
+
}
|
|
177
|
+
if (!coreToolsRegistered && typeof tools.register === 'function') {
|
|
178
|
+
for (const tool of coreTools()) {
|
|
179
|
+
try {
|
|
180
|
+
const d = tools.register(tool)
|
|
181
|
+
if (typeof d === 'function') coreDisposers.push(d)
|
|
182
|
+
} catch (err) {
|
|
183
|
+
console.warn(`[tool-host] 注册核心工具 ${tool.name} 失败:`, err?.message || err)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
coreToolsRegistered = true
|
|
187
|
+
}
|
|
188
|
+
installRefs++
|
|
189
|
+
let released = false
|
|
190
|
+
return () => {
|
|
191
|
+
if (released) return
|
|
192
|
+
released = true
|
|
193
|
+
installRefs--
|
|
194
|
+
if (installRefs > 0) return
|
|
195
|
+
for (const dispose of guardDisposers.splice(0)) {
|
|
196
|
+
try { dispose() } catch { /* 忽略重复释放 */ }
|
|
197
|
+
}
|
|
198
|
+
for (const dispose of coreDisposers.splice(0)) {
|
|
199
|
+
try { dispose() } catch { /* 忽略重复释放 */ }
|
|
200
|
+
}
|
|
201
|
+
guardInstalled = false
|
|
202
|
+
coreToolsRegistered = false
|
|
203
|
+
}
|
|
204
|
+
}
|
|
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
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 能力发现面过滤:锁定会话里剔除异领域描述符(conductor_discover 自动受约束)。
|
|
259
|
+
* 无 domain 的描述符(编排/核心基建)保留。未锁定 → 原样返回。
|
|
260
|
+
*/
|
|
261
|
+
function filterEntries(entries, sessionId) {
|
|
262
|
+
const lock = modeOf(sessionId)
|
|
263
|
+
if (!lock) return entries
|
|
264
|
+
return (entries || []).filter((entry) => {
|
|
265
|
+
const d = entry?.descriptor || {}
|
|
266
|
+
const domain = domainByTool.get(String(d.tool || d.name)) || domainBySuite.get(String(entry?.suite)) || ''
|
|
267
|
+
return !domain || domain === lock
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return { declareTools, domainOf, modeOf, isVisible, whenFor, guard, install, installPrompt, filterEntries }
|
|
272
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @capyclaw/wall-workbench
|
|
2
|
+
|
|
3
|
+
展示墙工作台运行时:主区的**空态选择器**。会话还没有绑定工作台模式时,主区舞台摆出这扇墙,列出当前 profile 已注册的工作台类型(ppt / canvas / browser …,类型无关、动态读取);用户点选即**显式认领**会话模式,舞台随后收掉墙、摆出真实工作台。
|
|
4
|
+
|
|
5
|
+
最精简的工作台实例:**零 MCP 工具、零引擎、零文档模型**(`declareBridge({ model: null })`),与 browser 同构但没有 Playwright 面。
|
|
6
|
+
|
|
7
|
+
## 组成
|
|
8
|
+
|
|
9
|
+
- `server/relay.mjs` — `createWorkbench` 业务装配(静态选择器页 + `/claim` 认领端点)。
|
|
10
|
+
- `server/embedded-host.mjs` — cordis 宿主入口(手写精简版):挂宿主路由、`__host__` 自检、活动台账。
|
|
11
|
+
- `server/routes/claim.mjs` — `POST /claim {sid?, kind}`:经 work-store `claimSessionMode(..., { explicit: true })` 认领;底座缺席降级 `skipped`。
|
|
12
|
+
- `ui/` — 选择器页(读 `/__portal_hud__/state` 渲染卡片;支持舞台 retarget 换会话)。
|
|
13
|
+
- `server/workbench-framework.mjs` — 构建期从 `A/build/framework/` 拷入的公共骨架(HTTP/锁/发现/独立入口)。
|
|
14
|
+
|
|
15
|
+
## 快速开始
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# 构建产物(本仓库)
|
|
19
|
+
node build/build-plugin.mjs
|
|
20
|
+
|
|
21
|
+
# standalone(仅开发/调试;无 portal-hud 注册信息,页面降级为提示)
|
|
22
|
+
node artifacts/plugin/capyclaw-wall-workbench/server/relay.mjs --port 39319
|
|
23
|
+
|
|
24
|
+
# 生产:作为 DSH 插件挂进 profile(embedded,不监听端口)
|
|
25
|
+
dsh plugin --profile web add @capyclaw/wall-suite
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 端点
|
|
29
|
+
|
|
30
|
+
| 方法 | 路径 | 说明 |
|
|
31
|
+
| --- | --- | --- |
|
|
32
|
+
| GET | `/`(及 `/index.html` `/app.js` `/style.css`) | 选择器页(白名单静态) |
|
|
33
|
+
| POST | `/claim` | 显式认领会话模式,body `{sid?, kind}`;回 `{ok, kind, fresh?, explicit?, skipped?, lockedTo?}` |
|
|
34
|
+
| GET | `/healthz` `/metrics` | 框架内置健康/指标 |
|
|
35
|
+
| GET | `<mount>/__host__` | 宿主自检(embedded) |
|
|
36
|
+
|
|
37
|
+
`/s/<sid>` 会话段由 service-host 剥层:页面从 `location.pathname` 读 sid,认领时放进 body(retarget 后 URL 可能仍是旧会话)。
|
|
38
|
+
|
|
39
|
+
## 配置
|
|
40
|
+
|
|
41
|
+
| 来源 | 说明 |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `config.mountPath` | 挂载前缀,默认 `/capyclaw/wall` |
|
|
44
|
+
| `config.hostDir` / `WALL_BRIDGE_HOME` | 状态目录(embedded 缺省 `~/.dsh/workbenches/wall-workbench`) |
|
|
45
|
+
| `config.strictPort` / `config.allowReuse` | standalone 端口策略 |
|
|
46
|
+
|
|
47
|
+
## 架构
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
plugin.mjs → server/embedded-host.mjs(cordis 入口,inject: webServer)
|
|
51
|
+
→ server/relay.mjs(createWorkbench 业务钩子)
|
|
52
|
+
→ server/workbench-framework.mjs(公共骨架:HTTP/锁/MCP 装配/独立入口)
|
|
53
|
+
→ server/routes/{workbench,claim}.mjs + ui/(选择器页)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## 许可证
|
|
57
|
+
|
|
58
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { name, apply } from '../server/embedded-host.mjs'
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capyclaw/wall-workbench",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "展示墙工作台运行时:主区空态选择器(列出已注册工作台类型,点选显式认领会话模式)。零工具、零引擎、零文档模型。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./plugin.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./plugin.mjs",
|
|
9
|
+
"./package.json": "./package.json"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=18",
|
|
13
|
+
"dsh": "^0.2.0-rc.2"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"dsh": {
|
|
19
|
+
"member": true,
|
|
20
|
+
"category": "service",
|
|
21
|
+
"platform": "both",
|
|
22
|
+
"capabilities": {
|
|
23
|
+
"source": "server/tools/capabilities",
|
|
24
|
+
"manifest": "capabilities.json"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"meta": {
|
|
28
|
+
"title": "展示墙工作台运行时",
|
|
29
|
+
"description": "主区空态选择器:会话未绑定模式时列出已注册的工作台类型,点选即显式认领会话模式(挂在 dsh 的 /capyclaw/wall,路由与端口由基建决定)"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"plugin.mjs",
|
|
33
|
+
"lib/",
|
|
34
|
+
"server/",
|
|
35
|
+
"ui/",
|
|
36
|
+
"!server/.relay-instance.lock",
|
|
37
|
+
"contract/",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"scripts": {},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@capyclaw/asset-service": "^0.1.6",
|
|
44
|
+
"@capyclaw/foundation": "^0.1.11",
|
|
45
|
+
"@capyclaw/plugin-kit": "^0.2.8",
|
|
46
|
+
"@capyclaw/service-host": "^0.1.7",
|
|
47
|
+
"@capyclaw/tool-host": "^0.3.2"
|
|
48
|
+
},
|
|
49
|
+
"author": {
|
|
50
|
+
"name": "CapyClaw",
|
|
51
|
+
"url": "https://github.com/capyclaw",
|
|
52
|
+
"email": "support@capyclaw.dev"
|
|
53
|
+
},
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "git+https://github.com/Maple496/capyclaw.git",
|
|
57
|
+
"directory": "A/projects/wall/artifacts/plugin/capyclaw-wall-workbench"
|
|
58
|
+
},
|
|
59
|
+
"bugs": {
|
|
60
|
+
"url": "https://github.com/Maple496/capyclaw/issues"
|
|
61
|
+
},
|
|
62
|
+
"homepage": "https://github.com/Maple496/capyclaw/tree/main/A/projects/wall/artifacts/plugin/capyclaw-wall-workbench#readme"
|
|
63
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* foundation ABI raw@1 wrapper:准入闸扩面后宿主必须走 ABI(见 bridge-build 注释)。
|
|
3
|
+
* raw@1 逃生舱承载多面共生命周期(webServer 路由 + toolHost 工具 + 描述符/表面/portal,
|
|
4
|
+
* 共享 workId/relay);额外 inject 仅 raw@1 可声明。core/os.skills 是套件运行时前提。
|
|
5
|
+
*/
|
|
6
|
+
import { createPlugin, rawPlugin } from '@capyclaw/foundation/abi'
|
|
7
|
+
import { name as hostName, apply as applyHost } from './server/embedded-host.mjs'
|
|
8
|
+
|
|
9
|
+
export const { name, inject, apply } = createPlugin({
|
|
10
|
+
name: hostName,
|
|
11
|
+
inject: ['webServer'],
|
|
12
|
+
implements: [rawPlugin(({ ctx, config }) => applyHost(ctx, config))],
|
|
13
|
+
}, import.meta.url)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 激活失败诊断日志的有界写入(防 activate-error.log 无界增长)。
|
|
3
|
+
*
|
|
4
|
+
* 旧实现直接 fs.appendFileSync 追加完整栈,长期反复激活失败会让日志无限膨胀。
|
|
5
|
+
* 这里改为「读尾部 + 追加 + 超限裁剪 + 整体重写」:
|
|
6
|
+
* - 行数硬上限 ACTIVATE_LOG_MAX_LINES(200):每次追加只保留最近 200 行;
|
|
7
|
+
* - 字节硬上限 ACTIVATE_LOG_MAX_BYTES(256KB):仍超则按字节取尾部并丢掉
|
|
8
|
+
* 首条不完整行,保证不截断出半行乱码。
|
|
9
|
+
* 只读取文件尾部 maxBytes 字节,内存占用有界;失败信息(最近若干条栈)始终可诊断。
|
|
10
|
+
*
|
|
11
|
+
* 本模块不依赖构建期才生成的 ./shared/*,可被 src 直接 import 做回归测试。
|
|
12
|
+
*/
|
|
13
|
+
import fs from 'node:fs'
|
|
14
|
+
|
|
15
|
+
export const ACTIVATE_LOG_MAX_BYTES = 256 * 1024
|
|
16
|
+
export const ACTIVATE_LOG_MAX_LINES = 200
|
|
17
|
+
|
|
18
|
+
/** 只读文件尾部 maxBytes 字节;若从中间读起则丢掉首条不完整行。读失败返回空串。 */
|
|
19
|
+
function readTail(filePath, maxBytes) {
|
|
20
|
+
let fd
|
|
21
|
+
try {
|
|
22
|
+
fd = fs.openSync(filePath, 'r')
|
|
23
|
+
const size = fs.fstatSync(fd).size
|
|
24
|
+
const start = Math.max(0, size - maxBytes)
|
|
25
|
+
const len = size - start
|
|
26
|
+
const buf = Buffer.alloc(len)
|
|
27
|
+
fs.readSync(fd, buf, 0, len, start)
|
|
28
|
+
let text = buf.toString('utf8')
|
|
29
|
+
if (start > 0) {
|
|
30
|
+
const i = text.indexOf('\n')
|
|
31
|
+
text = i >= 0 ? text.slice(i + 1) : ''
|
|
32
|
+
}
|
|
33
|
+
return text
|
|
34
|
+
} catch {
|
|
35
|
+
return ''
|
|
36
|
+
} finally {
|
|
37
|
+
if (fd !== undefined) { try { fs.closeSync(fd) } catch { /* 忽略 */ } }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 向 filePath 有界追加一条 entry(自动补尾换行)。超限按行/按字节裁剪后整体重写。
|
|
43
|
+
* @param {string} filePath 目标日志文件绝对路径
|
|
44
|
+
* @param {string} entry 要追加的一条诊断文本(通常含时间戳与错误栈)
|
|
45
|
+
* @param {{maxBytes?:number, maxLines?:number}} [opts] 覆盖默认上限
|
|
46
|
+
*/
|
|
47
|
+
export function appendBoundedLog(filePath, entry, opts = {}) {
|
|
48
|
+
const maxBytes = opts.maxBytes ?? ACTIVATE_LOG_MAX_BYTES
|
|
49
|
+
const maxLines = opts.maxLines ?? ACTIVATE_LOG_MAX_LINES
|
|
50
|
+
const line = String(entry)
|
|
51
|
+
const text = line.endsWith('\n') ? line : `${line}\n`
|
|
52
|
+
let combined = readTail(filePath, maxBytes) + text
|
|
53
|
+
/* 行数硬上限:每次追加都只保留最近 maxLines 行(最新一条必在末尾)。 */
|
|
54
|
+
const lines = combined.split('\n').filter((l) => l.length > 0)
|
|
55
|
+
if (lines.length > maxLines) combined = `${lines.slice(-maxLines).join('\n')}\n`
|
|
56
|
+
/* 字节硬上限:仍超则按字节取尾部并丢首条不完整行,避免截出半行乱码。 */
|
|
57
|
+
if (Buffer.byteLength(combined, 'utf8') > maxBytes) {
|
|
58
|
+
let tail = Buffer.from(combined, 'utf8').subarray(-maxBytes).toString('utf8')
|
|
59
|
+
const i = tail.indexOf('\n')
|
|
60
|
+
tail = i >= 0 ? tail.slice(i + 1) : tail
|
|
61
|
+
/* 极端:单条 entry 本身就超过 maxBytes,按字节裁剪可能整条丢空——
|
|
62
|
+
兜底保留 entry 尾部,确保最新失败信息不丢。 */
|
|
63
|
+
combined = tail.length > 0 ? tail : text.slice(-maxBytes)
|
|
64
|
+
}
|
|
65
|
+
fs.writeFileSync(filePath, combined)
|
|
66
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** 墙的稳定常量(relay/routes/tests 共用,避免循环 import)。 */
|
|
2
|
+
|
|
3
|
+
/* standalone(仅开发/调试)默认端口;embedded 形态挂宿主路由,不监听端口。 */
|
|
4
|
+
export const DEFAULT_PORT = 39319
|
|
5
|
+
|
|
6
|
+
/** 工作台静态页(白名单,杜绝路径穿越;相对 ui/)。 */
|
|
7
|
+
export const WALL_FILES = {
|
|
8
|
+
'/': ['index.html', 'text/html; charset=utf-8'],
|
|
9
|
+
'/index.html': ['index.html', 'text/html; charset=utf-8'],
|
|
10
|
+
'/app.js': ['app.js', 'text/javascript; charset=utf-8'],
|
|
11
|
+
'/style.css': ['style.css', 'text/css; charset=utf-8'],
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP 工具契约的唯一真源(版本号)。
|
|
3
|
+
*
|
|
4
|
+
* 展示墙零工具:契约面是空数组(tools.mjs),版本号供 suite 清单与巡检对账。
|
|
5
|
+
* 新增能力只改 tools/capabilities/index.mjs(当前为空)。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** 工具契约版本:工具名、参数、返回结构发生不兼容变化时升 major。 */
|
|
9
|
+
export const CONTRACT_VERSION = '1.0.0'
|
|
10
|
+
|
|
11
|
+
/** 工作台包版本。 */
|
|
12
|
+
export const PACKAGE_VERSION = '0.1.2'
|