@capyclaw/rsp-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/README.md +84 -2
- package/cordis.patch.yml +8 -0
- package/dsh-suite.json +91 -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 +72 -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/ledger.mjs +151 -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/rsp-skill-remote-screen/README.md +7 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/contract/rsp-contract.json +478 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/package.json +33 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/plugin.mjs +15 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/skills/remote-screen/SKILL.md +131 -0
- package/node_modules/@capyclaw/rsp-workbench/contract/capabilities.json +203 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/client.mjs +681 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/descriptors.mjs +28 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/host.mjs +51 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/manager.mjs +333 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/session-mode.mjs +68 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/tools.mjs +485 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/workbench.mjs +184 -0
- package/node_modules/@capyclaw/rsp-workbench/package.json +47 -0
- package/node_modules/@capyclaw/rsp-workbench/plugin.mjs +17 -0
- package/node_modules/@capyclaw/rsp-workbench/ui/index.html +578 -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 +597 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/suite-kit/README.md +289 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
- package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
- package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
- package/node_modules/@capyclaw/suite-kit/package.json +58 -0
- package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
- package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
- package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
- package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
- package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
- package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
- package/node_modules/@capyclaw/suite-kit/src/host.mjs +251 -0
- package/node_modules/@capyclaw/suite-kit/src/index.mjs +24 -0
- package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
- package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
- package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
- package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
- package/node_modules/@capyclaw/suite-kit/suite.schema.json +128 -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/ws/LICENSE +20 -0
- package/node_modules/ws/README.md +539 -0
- package/node_modules/ws/browser.js +8 -0
- package/node_modules/ws/index.js +22 -0
- package/node_modules/ws/lib/buffer-util.js +142 -0
- package/node_modules/ws/lib/constants.js +19 -0
- package/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/ws/lib/permessage-deflate.js +530 -0
- package/node_modules/ws/lib/receiver.js +751 -0
- package/node_modules/ws/lib/sender.js +610 -0
- package/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/ws/lib/websocket-server.js +562 -0
- package/node_modules/ws/lib/websocket.js +1440 -0
- package/node_modules/ws/package.json +74 -0
- package/node_modules/ws/wrapper.mjs +21 -0
- package/package.json +53 -4
|
@@ -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,20 @@
|
|
|
1
|
+
Copyright (c) 2011 Einar Otto Stangvik <einaros@gmail.com>
|
|
2
|
+
Copyright (c) 2013 Arnout Kazemier and contributors
|
|
3
|
+
Copyright (c) 2016 Luigi Pinca and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|