@capyclaw/caption-map 0.3.0 → 0.3.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 +27 -18
- package/client/client.js +18 -8
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +8 -1
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +5 -2
- package/node_modules/@capyclaw/foundation/abi/version.mjs +63 -5
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +11 -10
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +8 -1
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +29 -2
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +31 -3
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +12 -2
- package/node_modules/@capyclaw/foundation/package.json +1 -1
- package/node_modules/@capyclaw/plugin-kit/package.json +1 -1
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +3 -82
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,21 +93,28 @@ DOM 节点**——React 仍拥有这些节点;席位内未来新增注册项
|
|
|
93
93
|
它现在见到 `window.__CAPYCLAW_CHAT_DOCK_OWNER__` 就让位(`apply` 直接返回 null),
|
|
94
94
|
**已经不需要启用**;留着只是为了不让老配置报错。
|
|
95
95
|
|
|
96
|
-
##
|
|
96
|
+
## 「更多」/「其他」分组(两态)
|
|
97
97
|
|
|
98
98
|
侧栏顶部的面板列表(`SidebarRoot.tsx` 的 `nav.panelList`:`sidebar.panellist`
|
|
99
|
-
各注册项 + 有 entry action 时追加的「更多」)同样**不移动 DOM
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
-
|
|
109
|
-
|
|
110
|
-
|
|
99
|
+
各注册项 + 有 entry action 时追加的「更多」)同样**不移动 DOM**;入口形态按
|
|
100
|
+
侧栏状态分两态(编排器 `pass()` 的 `moreMode = !drawer() && !collapsed()`):
|
|
101
|
+
|
|
102
|
+
- **展开态 → 「更多」收拢浮窗**:插件在标题栏左侧注入「更多」按钮
|
|
103
|
+
(`#capyclaw-more-trigger`),点开在 `<html>` 置 `data-capyclaw-more-open`
|
|
104
|
+
显示浮窗(`data-capyclaw-more-panel`,背板尺寸贴合内容)。浮窗按序收拢:
|
|
105
|
+
① 新会话、② 折叠侧栏(两枚注入行)③ 应用/编辑菜单栏 host ④ 底部入口行
|
|
106
|
+
(Maple 账户 + 手机/电脑,横排、overflow 弹出菜单放行)⑤ 面板列表;
|
|
107
|
+
鲸鱼与侧栏开关本体在标题栏藏起,入口改由浮窗注入行提供。面板行标签用
|
|
108
|
+
`::after{content:attr(aria-label)}` 补、隐藏原生 `panelTitle`;点面板行 →
|
|
109
|
+
React 的 `selectPanel` 照常切换后收起,「更多」菜单锚点 / 账户 / 设备保持开;
|
|
110
|
+
点空白 / Esc 收起。此态 brand/seats/others 幂等让位。
|
|
111
|
+
- **折叠(rail)态 → 老「其他」下拉**:「其他」按钮(`#capyclaw-others-trigger`,
|
|
112
|
+
`position:fixed` 接在底部入口行右侧、标题栏垂直居中);整块 `nav` 被
|
|
113
|
+
`position:fixed` 到标题栏下方(宽 224px,菜单面 + 阴影),默认隐藏,点按钮时
|
|
114
|
+
在 `<html>` 置 `data-capyclaw-others-open` 显示;点行切换面板后收起,点「更多」
|
|
115
|
+
交给它自己的菜单。此态 more 让位、brand/seats 照旧映射。
|
|
116
|
+
- drawer 模式(`[data-sidebar-drawer]`)下整轮不搬,面板列表留在抽屉里;
|
|
117
|
+
两态互斥、切换与卸载都经各自 `yield()` 逐字还原。
|
|
111
118
|
|
|
112
119
|
## 预留栏位(「其他」后的占位场 + 挂载锚)
|
|
113
120
|
|
|
@@ -133,9 +140,11 @@ DOM 节点**——React 仍拥有这些节点;席位内未来新增注册项
|
|
|
133
140
|
共存于同一占位场(互不覆盖、单独释放不影响他人),这就是本栏位的可拓展点。让位(drawer/卸载/纯 web)
|
|
134
141
|
时所有 `getMount()` 转 `null`,消费者应 unmount 旧根;恢复后锚按租约重建新节点并广播,消费者重挂。
|
|
135
142
|
|
|
136
|
-
-
|
|
137
|
-
|
|
138
|
-
|
|
143
|
+
- 几何:编排器把排布后的 cursor 传给它(展开态 = `more.pass` 返回的「更多」右缘,
|
|
144
|
+
折叠态 = `others.pass` 返回的「其他」右缘)+ GAP;标题栏行垂直居中(28px 高,同触发按钮款);
|
|
145
|
+
占用后外盒靠 `left`(编排器钉)+ `right:150px`(预留区左缘)拉伸占满标题栏剩余宽度
|
|
146
|
+
(Edge 式标签条填满到末尾,不再内容自撑半截停住);mount `flex:1 1 0` 均分槽宽、
|
|
147
|
+
`overflow:hidden` 防溢出;未占用 `right:auto` 回虚线占位自撑(max 160px)。
|
|
139
148
|
- 护栏:右缘挤占原生 min/max/close 预留区(150px)时整枚隐藏;`-webkit-app-region:no-drag`;
|
|
140
149
|
- 门控与「其他」同生死:面板列表本轮不归我们管(drawer / 卸载 / 纯 web)时一起缺席;
|
|
141
150
|
停用插件即移除占位场并 unprovide 服务(纯自有节点,不钉宿主 DOM,无需样式账本)。
|
|
@@ -175,7 +184,7 @@ DOM**:每个工作区分组在标题栏**第二行**注入一枚文件夹按
|
|
|
175
184
|
- 点会话行 / 搜索结果行 → 照常打开会话并收起浮窗(收藏夹行为);组头折叠、
|
|
176
185
|
行内操作条、搜索、添加、overflow 菜单保持开;点浮窗外 / Esc 收起;搜索展开时
|
|
177
186
|
第一次 Esc 豁免,先交给原生逻辑收搜索;
|
|
178
|
-
-
|
|
187
|
+
- 文件夹下拉与「更多」/「其他」菜单**互斥**(开一个关另一个);
|
|
179
188
|
- 折叠态(rail)占用方会卸载列表内容、drawer 模式整块让位:不映射、收按钮与
|
|
180
189
|
过滤样式表、摘第二行占位、内联样式逐字还原;再展开重新映射。
|
|
181
190
|
|
|
@@ -282,7 +291,7 @@ renderSlot 统一带上,无需占用方配合。
|
|
|
282
291
|
(`require.async('./client.chat.js')`,卸载时先置 `dead` 再调子半的 disposer)。
|
|
283
292
|
标题栏映射 effect 内部 = 共享底座(门控 / 样式账本 / SRC_MARK 记账 /
|
|
284
293
|
容器隔离兜底 / 触发按钮工厂 / 开合互斥注册表)+ 六个特性模块
|
|
285
|
-
(brand / newSession / seats / others / extraSlot / workspaces,各持账本或自有节点、
|
|
294
|
+
(brand / newSession / seats / others / more / extraSlot / workspaces,各持账本或自有节点、
|
|
286
295
|
暴露 `pass` / `yield`)+ 薄编排器 + 浮窗外点击/Esc 策略分发(`dropdownFeatures`)。
|
|
287
296
|
加功能见「扩展」节。区域映射**不依赖 window-kit**(window-kit 被禁用时
|
|
288
297
|
它仍须工作),故用入口内自己的轻量账本;聊天窗半才走 `WINDOW_KIT.effect`。
|
package/client/client.js
CHANGED
|
@@ -224,15 +224,19 @@ window.__ModuleLoader__.load({
|
|
|
224
224
|
/* ── 预留栏位:「其他」后的占位场(内容待定,虚线盒示意) ─────── */
|
|
225
225
|
'[' + EXTRA_SLOT_MARK + ']{position:fixed!important;z-index:1080!important;box-sizing:border-box!important;',
|
|
226
226
|
'display:inline-flex!important;align-items:center!important;gap:4px!important;',
|
|
227
|
-
'height:28px!important;width:auto!important;max-width:160px!important;margin:0!important;padding:0 8px!important;',
|
|
227
|
+
'height:28px!important;width:auto!important;right:auto!important;max-width:160px!important;margin:0!important;padding:0 8px!important;',
|
|
228
228
|
'border:1px dashed var(--dsw-alias-border-l2,rgba(0,0,0,.25))!important;border-radius:var(--dsw-radius-sm,6px)!important;',
|
|
229
229
|
'background:transparent!important;color:var(--dsw-alias-label-secondary,inherit)!important;font:inherit!important;font-size:12px!important;line-height:1!important;',
|
|
230
|
-
'white-space:nowrap!important
|
|
230
|
+
'white-space:nowrap!important}',
|
|
231
231
|
'[' + EXTRA_SLOT_MARK + '] span{overflow:hidden!important;text-overflow:ellipsis!important;opacity:.75!important}',
|
|
232
|
-
/*
|
|
233
|
-
|
|
232
|
+
/* 被占用(挂载锚有消费者):去虚线/限宽;left 由编排器钉在「其他」右侧、right 钉在
|
|
233
|
+
窗口控件预留区左缘 ⇒ width:auto 的 fixed 盒拉伸占满标题栏剩余宽度(Edge 式标签
|
|
234
|
+
条填满到末尾,不再内容自撑半截停住);内层 mount 均分槽宽承载消费者 React 根。
|
|
235
|
+
未占用时 right:auto 回到虚线占位盒自撑。 */
|
|
236
|
+
'[' + EXTRA_SLOT_MARK + '][data-occupied]{border:none!important;max-width:calc(100vw - ' + CAPTION_RIGHT_RESERVE + 'px)!important;padding:0!important;gap:0!important;',
|
|
237
|
+
'right:' + CAPTION_RIGHT_RESERVE + 'px!important}',
|
|
234
238
|
'[' + EXTRA_SLOT_MOUNT_MARK + ']{display:flex!important;align-items:center!important;height:28px!important;',
|
|
235
|
-
'min-width:0!important;max-width:
|
|
239
|
+
'flex:1 1 0!important;min-width:0!important;max-width:100%!important;overflow:hidden!important}',
|
|
236
240
|
|
|
237
241
|
/* ── 「其他」分组:把 sidebar.panellist 收成下拉 ─────────────── */
|
|
238
242
|
'nav[' + MARK + ']{position:fixed!important;z-index:1090!important;box-sizing:border-box!important;',
|
|
@@ -429,10 +433,16 @@ window.__ModuleLoader__.load({
|
|
|
429
433
|
s.top = ((capH - 28) / 2) + 'px'
|
|
430
434
|
s.left = left + 'px'
|
|
431
435
|
s.zIndex = '1080'
|
|
432
|
-
s.webkitAppRegion = 'no-drag
|
|
433
|
-
/* 不挤占右侧原生 min/max/close
|
|
436
|
+
s.webkitAppRegion = '' /* 槽盒不挖拖拽区:空白尾继承宿主 drag;标签/按钮自带 no-drag 仍可点 */
|
|
437
|
+
/* 不挤占右侧原生 min/max/close 预留区:放不下整枚隐藏。
|
|
438
|
+
占用态靠 left+right 拉伸、宽恒等于剩余空间,只看 left 是否已越过预留区
|
|
439
|
+
左缘(若再累加 rect 宽,亚像素舍入会把拉伸盒误判成挤占而整枚隐藏);
|
|
440
|
+
未占用占位盒仍按内容宽判断。 */
|
|
434
441
|
var w = node.getBoundingClientRect().width
|
|
435
|
-
|
|
442
|
+
var over = leases.length
|
|
443
|
+
? left >= window.innerWidth - CAPTION_RIGHT_RESERVE
|
|
444
|
+
: left + w > window.innerWidth - CAPTION_RIGHT_RESERVE
|
|
445
|
+
s.display = over ? 'none' : ''
|
|
436
446
|
if (dirty) notify()
|
|
437
447
|
return left + w + GAP
|
|
438
448
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { ABI_MAJOR, getInterfaceKind } from './kinds.mjs'
|
|
3
3
|
import { validateInterface } from './validate.mjs'
|
|
4
4
|
import { AbiError, ERROR_CODES, toAbiError } from './errors.mjs'
|
|
5
|
-
import { satisfies } from './version.mjs'
|
|
5
|
+
import { satisfies, isValidRange } from './version.mjs'
|
|
6
6
|
|
|
7
7
|
const thenable = (value) => value && typeof value.then === 'function'
|
|
8
8
|
|
|
@@ -164,6 +164,13 @@ export function createLoader({ adapters = {}, capabilities = {}, log = null, abi
|
|
|
164
164
|
plugins.delete(spec.name)
|
|
165
165
|
void previous.handle?.dispose?.()
|
|
166
166
|
}
|
|
167
|
+
/* 非法范围单独报 E_SCHEMA:旧实现把「range 写错」和「能力真缺」都归成
|
|
168
|
+
* E_CAP_MISSING「能力不可用」,误导排障。先区分两者。 */
|
|
169
|
+
const badRanges = spec.requires.filter((need) => need.name.startsWith('os.') && !isValidRange(need.range))
|
|
170
|
+
if (badRanges.length) {
|
|
171
|
+
throw error(ERROR_CODES.E_SCHEMA, `插件 ${spec.name} 能力范围非法:${badRanges.map((r) => r.raw).join(', ')}`,
|
|
172
|
+
{ plugin: spec.name, invalid: badRanges })
|
|
173
|
+
}
|
|
167
174
|
const missing = spec.requires.filter((need) => need.name.startsWith('os.')
|
|
168
175
|
&& !satisfies(capabilityMap()[need.name] || '', need.range))
|
|
169
176
|
if (missing.length) {
|
|
@@ -191,9 +191,12 @@ export function definePlugin(options = {}) {
|
|
|
191
191
|
const requiresEntries = requires.map((entry) => parseCapability(entry, 'requires'))
|
|
192
192
|
const providesEntries = provides.map((entry) => parseCapability(entry, 'provides'))
|
|
193
193
|
for (const entry of providesEntries) {
|
|
194
|
-
|
|
194
|
+
/* 白名单而非黑名单:provides 必须是完整 x.y.z(可带 prerelease)。旧实现只拒
|
|
195
|
+
* ^~<>= 前缀,'1.x' / '1.*' / 裸 '1' 漏网被当成版本发布,消费方 parseVersion
|
|
196
|
+
* 解析不了 → satisfies 恒 false,能力永远「不可用」。 */
|
|
197
|
+
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(entry.range)) {
|
|
195
198
|
throw new AbiError(ERROR_CODES.E_PLUGIN_SHAPE,
|
|
196
|
-
`provides
|
|
199
|
+
`provides 必须写精确版本(x.y.z),不能写范围:${entry.raw}`, { entry: entry.raw })
|
|
197
200
|
}
|
|
198
201
|
}
|
|
199
202
|
|
|
@@ -2,25 +2,57 @@
|
|
|
2
2
|
* 版本与范围:能力声明用 `^1` / `^1.2.0` / `>=1.2` / `1.x` / 精确版本。
|
|
3
3
|
*
|
|
4
4
|
* 只实现这份 ABI 需要的语义,不引入 semver 依赖:
|
|
5
|
-
* - `^1.2.3` → >=1.2.3 且同主版本;`^0.2.3` → >=0.2.3
|
|
5
|
+
* - `^1.2.3` → >=1.2.3 且同主版本;`^0.2.3` → >=0.2.3 且同次版本;
|
|
6
|
+
* `^0.0.3` → >=0.0.3 且同补丁(0.0.x 约定,semver 标准)
|
|
6
7
|
* - `~1.2.3` → >=1.2.3 且同次版本
|
|
7
8
|
* - `1.x` / `1.*` → 同主版本
|
|
8
9
|
* - `>=` `>` `<=` `<` `=` 前缀
|
|
9
10
|
* - 裸版本 → 精确匹配(比较时忽略末位 0)
|
|
11
|
+
* - prerelease 保留并参与比较:1.0.0-beta < 1.0.0;带 prerelease 的版本只满足
|
|
12
|
+
* 同 [major,minor,patch] 且同样带 prerelease 的范围(semver 标准,避免预发布
|
|
13
|
+
* 版本被当成正式版本放行)。
|
|
10
14
|
*/
|
|
11
15
|
|
|
12
16
|
export function parseVersion(text) {
|
|
13
17
|
if (typeof text !== 'string') return null
|
|
14
|
-
const match = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-[0-9A-Za-z.-]+)?$/.exec(text.trim())
|
|
18
|
+
const match = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z.-]+))?$/.exec(text.trim())
|
|
15
19
|
if (!match) return null
|
|
16
|
-
|
|
20
|
+
const parts = [Number(match[1]), Number(match[2] || 0), Number(match[3] || 0)]
|
|
21
|
+
parts.prerelease = match[4] || null
|
|
22
|
+
return parts
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function comparePrerelease(a, b) {
|
|
26
|
+
/* 无 prerelease > 有 prerelease(1.0.0 > 1.0.0-beta)。 */
|
|
27
|
+
if (!a && !b) return 0
|
|
28
|
+
if (!a) return 1
|
|
29
|
+
if (!b) return -1
|
|
30
|
+
const left = a.split('.')
|
|
31
|
+
const right = b.split('.')
|
|
32
|
+
for (let i = 0; i < Math.max(left.length, right.length); i++) {
|
|
33
|
+
const x = left[i]
|
|
34
|
+
const y = right[i]
|
|
35
|
+
if (x === undefined) return -1
|
|
36
|
+
if (y === undefined) return 1
|
|
37
|
+
const xn = /^\d+$/.test(x)
|
|
38
|
+
const yn = /^\d+$/.test(y)
|
|
39
|
+
if (xn && yn) {
|
|
40
|
+
const d = Number(x) - Number(y)
|
|
41
|
+
if (d !== 0) return d < 0 ? -1 : 1
|
|
42
|
+
} else if (xn !== yn) {
|
|
43
|
+
return xn ? -1 : 1 // 数字标识符 < 字母数字标识符
|
|
44
|
+
} else if (x !== y) {
|
|
45
|
+
return x < y ? -1 : 1
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return 0
|
|
17
49
|
}
|
|
18
50
|
|
|
19
51
|
function compareParts(a, b) {
|
|
20
52
|
for (let i = 0; i < 3; i++) {
|
|
21
53
|
if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1
|
|
22
54
|
}
|
|
23
|
-
return
|
|
55
|
+
return comparePrerelease(a.prerelease || null, b.prerelease || null)
|
|
24
56
|
}
|
|
25
57
|
|
|
26
58
|
export function compareVersions(a, b) {
|
|
@@ -44,12 +76,23 @@ export function satisfies(version, range) {
|
|
|
44
76
|
if (raw.startsWith('^')) {
|
|
45
77
|
const base = parseVersion(raw.slice(1))
|
|
46
78
|
if (!base) return false
|
|
79
|
+
/* prerelease 只满足同 [major,minor,patch] 且带 prerelease 的范围(semver 标准),
|
|
80
|
+
* 避免 1.1.0-beta 被 ^1.0.0 当正式版本放行。 */
|
|
81
|
+
if (current.prerelease && (!base.prerelease
|
|
82
|
+
|| current[0] !== base[0] || current[1] !== base[1] || current[2] !== base[2])) return false
|
|
47
83
|
if (compareParts(current, base) < 0) return false
|
|
48
|
-
|
|
84
|
+
if (base[0] === 0) {
|
|
85
|
+
/* 0.0.x caret 收紧到补丁位:^0.0.3 只容 0.0.3,不容 0.0.9。 */
|
|
86
|
+
if (base[1] === 0) return current[0] === 0 && current[1] === 0 && current[2] === base[2]
|
|
87
|
+
return current[0] === 0 && current[1] === base[1]
|
|
88
|
+
}
|
|
89
|
+
return current[0] === base[0]
|
|
49
90
|
}
|
|
50
91
|
if (raw.startsWith('~')) {
|
|
51
92
|
const base = parseVersion(raw.slice(1))
|
|
52
93
|
if (!base) return false
|
|
94
|
+
if (current.prerelease && (!base.prerelease
|
|
95
|
+
|| current[0] !== base[0] || current[1] !== base[1] || current[2] !== base[2])) return false
|
|
53
96
|
return compareParts(current, base) >= 0 && current[0] === base[0] && current[1] === base[1]
|
|
54
97
|
}
|
|
55
98
|
if (raw.startsWith('>=')) {
|
|
@@ -80,3 +123,18 @@ export function satisfies(version, range) {
|
|
|
80
123
|
const exact = parseVersion(raw)
|
|
81
124
|
return Boolean(exact) && compareParts(current, exact) === 0
|
|
82
125
|
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 范围是否「语义合法」(区别于「合法但不满足」)。供加载器把非法范围单独报
|
|
129
|
+
* E_SCHEMA,而不是误归因成「能力不可用」误导排障。空范围视为「任意」,合法。
|
|
130
|
+
*/
|
|
131
|
+
export function isValidRange(range) {
|
|
132
|
+
const raw = String(range ?? '').trim()
|
|
133
|
+
if (!raw || raw === '*' || raw === 'x') return true
|
|
134
|
+
if (/^[\^~]/.test(raw)) return Boolean(parseVersion(raw.slice(1)))
|
|
135
|
+
if (/^(>=|<=)/.test(raw)) return Boolean(parseVersion(raw.slice(2)))
|
|
136
|
+
if (/^[><]/.test(raw)) return Boolean(parseVersion(raw.slice(1)))
|
|
137
|
+
if (raw.startsWith('=')) return isValidRange(raw.slice(1))
|
|
138
|
+
if (/^(\d+)(?:\.(\d+))?\.[x*]$/.test(raw)) return true
|
|
139
|
+
return Boolean(parseVersion(raw))
|
|
140
|
+
}
|
|
@@ -44,18 +44,19 @@ export function createRawAdapter({ log }) {
|
|
|
44
44
|
|
|
45
45
|
if (thenable(result)) {
|
|
46
46
|
let instance = {}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})
|
|
47
|
+
/* apply 结算只做归一化,绝不在此 eagerly 跑 instance.start()——旧实现
|
|
48
|
+
* 在 compile 返回的 promise resolve 时就启动,绕过 loader 的 start 阶段与
|
|
49
|
+
* stopRequested:loader 正在回滚/已请求卸载时 raw 仍会起进程/监听。
|
|
50
|
+
* start 交给 loader 在 start 阶段显式触发(此时才尊重 stopRequested)。 */
|
|
51
|
+
const ready = Promise.resolve(result).then((value) => { instance = normalize(value) })
|
|
53
52
|
return {
|
|
54
|
-
start: () =>
|
|
53
|
+
start: async ({ signal } = {}) => {
|
|
54
|
+
await ready
|
|
55
|
+
/* 转发 loader 的卸载 signal,让 raw 实例的 start 也能感知取消。 */
|
|
56
|
+
return instance.start ? instance.start({ signal }) : undefined
|
|
57
|
+
},
|
|
55
58
|
dispose: async () => {
|
|
56
|
-
|
|
57
|
-
try { await started } catch { /* start 失败由 loader 记录 */ }
|
|
58
|
-
}
|
|
59
|
+
try { await ready } catch { /* apply 失败由 loader 记录 */ }
|
|
59
60
|
if (typeof instance.dispose === 'function') return instance.dispose()
|
|
60
61
|
},
|
|
61
62
|
}
|
|
@@ -62,14 +62,21 @@ export function createRuntimeDriverAdapter({ host, config, log }) {
|
|
|
62
62
|
...(impl.args || []),
|
|
63
63
|
]
|
|
64
64
|
|
|
65
|
+
/* keepAlive 由声明推导:restart.max===0 表示「不要自动重启」,对应 keepAlive:false。
|
|
66
|
+
* 旧实现恒 true,应用声明 restart:{max:0} 仍被 broker 拉起,切换/回收行为与声明不符。 */
|
|
67
|
+
const keepAlive = !(impl.restart && impl.restart.max === 0)
|
|
65
68
|
const serviceSpec = {
|
|
66
69
|
id: impl.id,
|
|
67
70
|
cmd,
|
|
68
71
|
ports: { main: port },
|
|
69
72
|
url: 'http://127.0.0.1:${PORT}/',
|
|
70
|
-
keepAlive
|
|
73
|
+
keepAlive,
|
|
71
74
|
}
|
|
72
75
|
if (impl.health?.path) serviceSpec.healthPath = impl.health.path
|
|
76
|
+
/* 声明的健康期望/超时与重启策略必须透传给 broker,不能被静默丢弃。 */
|
|
77
|
+
if (impl.health?.expect && typeof impl.health.expect === 'object') serviceSpec.expect = impl.health.expect
|
|
78
|
+
if (impl.health?.timeoutMs) serviceSpec.waitMs = impl.health.timeoutMs
|
|
79
|
+
if (impl.restart) serviceSpec.restart = impl.restart
|
|
73
80
|
if (impl.dir) {
|
|
74
81
|
serviceSpec.cwd = fileURLToPath(new URL(impl.dir, mountContext.context.baseUrl))
|
|
75
82
|
}
|
|
@@ -11,6 +11,10 @@ import { BASE_CAPABILITIES } from './caps.mjs'
|
|
|
11
11
|
|
|
12
12
|
const NOOP_LOG = { debug() {}, info() {}, warn() {}, error() {} }
|
|
13
13
|
|
|
14
|
+
/* 内存宿主也要有界:app 不 dispose、asset 只 put 不 delete 的用法会让数组/Map
|
|
15
|
+
* 无限增长。app 提供 dispose() 摘除自己;assets 提供 delete() 与上限 LRU 淘汰。 */
|
|
16
|
+
const DEFAULT_MAX_ASSETS = 1024
|
|
17
|
+
|
|
14
18
|
export function createMemoryHost(options = {}) {
|
|
15
19
|
const state = {
|
|
16
20
|
providers: [],
|
|
@@ -24,6 +28,9 @@ export function createMemoryHost(options = {}) {
|
|
|
24
28
|
plugins: [],
|
|
25
29
|
}
|
|
26
30
|
const log = options.log ?? NOOP_LOG
|
|
31
|
+
const maxAssets = Number(options.maxAssets) > 0 ? Number(options.maxAssets) : DEFAULT_MAX_ASSETS
|
|
32
|
+
/* 单调序号:不能用 size+1 拼 id——淘汰后 size 回落,同毫秒内会撞掉已有资产。 */
|
|
33
|
+
let assetSeq = 0
|
|
27
34
|
|
|
28
35
|
function http() {
|
|
29
36
|
return {
|
|
@@ -41,6 +48,11 @@ export function createMemoryHost(options = {}) {
|
|
|
41
48
|
}
|
|
42
49
|
},
|
|
43
50
|
async dispatch() {},
|
|
51
|
+
dispose() {
|
|
52
|
+
const index = state.apps.indexOf(app)
|
|
53
|
+
if (index >= 0) state.apps.splice(index, 1)
|
|
54
|
+
routes.length = 0
|
|
55
|
+
},
|
|
44
56
|
}
|
|
45
57
|
state.apps.push(app)
|
|
46
58
|
return app
|
|
@@ -149,12 +161,27 @@ export function createMemoryHost(options = {}) {
|
|
|
149
161
|
}),
|
|
150
162
|
assets: () => ({
|
|
151
163
|
async put(value, contentType = 'application/octet-stream') {
|
|
152
|
-
const id = `asset-${state.assets.size + 1}`
|
|
153
164
|
const buffer = Buffer.isBuffer(value) ? value : Buffer.from(String(value))
|
|
165
|
+
/* Map 保持插入序:超限淘汰最旧(LRU 近似),get 命中会刷新到队尾。 */
|
|
166
|
+
while (state.assets.size >= maxAssets) {
|
|
167
|
+
const oldest = state.assets.keys().next().value
|
|
168
|
+
state.assets.delete(oldest)
|
|
169
|
+
}
|
|
170
|
+
const id = `asset-${++assetSeq}`
|
|
154
171
|
state.assets.set(id, { data: buffer, contentType })
|
|
155
172
|
return { id, url: `/assets/${id}`, size: buffer.length, contentType }
|
|
156
173
|
},
|
|
157
|
-
get(id) {
|
|
174
|
+
get(id) {
|
|
175
|
+
const entry = state.assets.get(id)
|
|
176
|
+
if (entry) { state.assets.delete(id); state.assets.set(id, entry) }
|
|
177
|
+
return entry
|
|
178
|
+
},
|
|
179
|
+
delete(id) { return state.assets.delete(id) },
|
|
180
|
+
gc() {
|
|
181
|
+
const removed = state.assets.size
|
|
182
|
+
state.assets.clear()
|
|
183
|
+
return { removed }
|
|
184
|
+
},
|
|
158
185
|
}),
|
|
159
186
|
}
|
|
160
187
|
}
|
|
@@ -13,12 +13,40 @@ const NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
|
13
13
|
const DEFAULT_RANK = 600
|
|
14
14
|
|
|
15
15
|
export function parseSkill(raw, path) {
|
|
16
|
+
/* BOM 会让 /^---/ 匹配不到 frontmatter,误报「缺少 YAML frontmatter」。先剥掉。 */
|
|
17
|
+
raw = raw.replace(/^\uFEFF/, '')
|
|
16
18
|
const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/u.exec(raw)
|
|
17
19
|
if (!frontmatter?.[1]) throw new Error(`skill ${path} 缺少 YAML frontmatter`)
|
|
18
20
|
const meta = {}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
const lines = frontmatter[1].split(/\r?\n/)
|
|
22
|
+
for (let i = 0; i < lines.length; i++) {
|
|
23
|
+
const match = /^([A-Za-z0-9_-]+):\s*(.*)$/.exec(lines[i])
|
|
24
|
+
if (!match) continue
|
|
25
|
+
const key = match[1]
|
|
26
|
+
let value = match[2].trim()
|
|
27
|
+
/* 块标量 description: | / > :旧实现把 '|' 本身当成描述直达 LLM,多行正文全丢。
|
|
28
|
+
* 这里聚合后续缩进行,| 保留换行、> 折叠为空格,按 chomping 处理尾部空白。 */
|
|
29
|
+
const block = /^([|>])([+-]?)$/.exec(value)
|
|
30
|
+
if (block) {
|
|
31
|
+
const body = []
|
|
32
|
+
let j = i + 1
|
|
33
|
+
for (; j < lines.length; j++) {
|
|
34
|
+
const ln = lines[j]
|
|
35
|
+
if (ln.trim() === '') { body.push(''); continue }
|
|
36
|
+
if (/^\s/.test(ln)) body.push(ln)
|
|
37
|
+
else break
|
|
38
|
+
}
|
|
39
|
+
i = j - 1
|
|
40
|
+
const nonEmpty = body.filter((l) => l.trim() !== '')
|
|
41
|
+
const minIndent = nonEmpty.length ? Math.min(...nonEmpty.map((l) => /^\s*/.exec(l)[0].length)) : 0
|
|
42
|
+
const stripped = body.map((l) => l.slice(minIndent))
|
|
43
|
+
let text = stripped.join(block[1] === '>' ? ' ' : '\n')
|
|
44
|
+
if (block[2] !== '+') text = text.replace(/\s+$/, '')
|
|
45
|
+
value = text
|
|
46
|
+
} else {
|
|
47
|
+
value = value.replace(/^['"]|['"]$/g, '').trim()
|
|
48
|
+
}
|
|
49
|
+
meta[key] = value
|
|
22
50
|
}
|
|
23
51
|
if (!meta.name || !meta.description) throw new Error(`skill ${path} 缺少 name/description`)
|
|
24
52
|
if (!NAME_RE.test(meta.name)) throw new Error(`skill ${path} name 必须是 kebab-case`)
|
|
@@ -91,7 +91,11 @@ export function createNet(host, config = {}) {
|
|
|
91
91
|
}
|
|
92
92
|
return
|
|
93
93
|
}
|
|
94
|
-
await new Promise((resolve) =>
|
|
94
|
+
await new Promise((resolve) => {
|
|
95
|
+
/* unref:迟到补挂的轮询定时器不得拖住进程退出(最长 60s 的尾延迟)。 */
|
|
96
|
+
const timer = setTimeout(resolve, WEB_LATE_POLL_MS)
|
|
97
|
+
timer.unref?.()
|
|
98
|
+
})
|
|
95
99
|
}
|
|
96
100
|
})().catch(() => {})
|
|
97
101
|
}
|
|
@@ -116,7 +120,10 @@ export function createNet(host, config = {}) {
|
|
|
116
120
|
if (!web && shouldWaitForWeb()) {
|
|
117
121
|
const deadline = Date.now() + WEB_WAIT_MS
|
|
118
122
|
while (!web && Date.now() < deadline && !closed) {
|
|
119
|
-
await new Promise((resolve) =>
|
|
123
|
+
await new Promise((resolve) => {
|
|
124
|
+
const timer = setTimeout(resolve, WEB_POLL_MS)
|
|
125
|
+
timer.unref?.()
|
|
126
|
+
})
|
|
120
127
|
web = webServer()
|
|
121
128
|
}
|
|
122
129
|
}
|
|
@@ -140,6 +147,9 @@ export function createNet(host, config = {}) {
|
|
|
140
147
|
disposal = (async () => {
|
|
141
148
|
if (!sharedHost) return
|
|
142
149
|
// listen 失败由 ready/start 报告;清理仍需执行,且 close 失败不能被吞掉。
|
|
150
|
+
// 注意:dispose 在 listen 失败时仍 RESOLVE(错误经 ready/start 上报)——这是
|
|
151
|
+
// 被 network-lifecycle 测试固化的契约,close 不再二次上抛 listen 错,避免
|
|
152
|
+
// 破坏「清理成功即 dispose 成功」的语义。
|
|
143
153
|
await listening.catch(() => {})
|
|
144
154
|
// 迟到补挂的路由要一起撤掉,否则共享宿主关了、宿主网页端口上还留着分发器。
|
|
145
155
|
try {
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { tuning } from '../tuning.mjs'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/* 与文档 owner 租约(document-workbench OWNER_TTL)对齐为 10s:
|
|
10
|
+
* 两条租约线共用「心跳 3s、TTL 10s」的并发协议,避免编辑器判活比文档慢半拍。 */
|
|
11
|
+
const DEFAULT_TTL = 10 // 秒
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* 创建编辑器租约仲裁器。
|
|
@@ -57,83 +58,3 @@ export function createEditorLease(opts = {}) {
|
|
|
57
58
|
},
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 编辑器端自动挂接循环。
|
|
63
|
-
* 首次 claim 强制抢占(后打开者赢),之后静默心跳。
|
|
64
|
-
* @param {{
|
|
65
|
-
* clientId: string,
|
|
66
|
-
* claim: (force: boolean) => Promise<boolean>,
|
|
67
|
-
* release?: () => void,
|
|
68
|
-
* onActive?: () => void,
|
|
69
|
-
* onStandby?: () => void,
|
|
70
|
-
* retryMs?: number,
|
|
71
|
-
* heartbeatMs?: number,
|
|
72
|
-
* setInterval?: (cb: () => void) => any,
|
|
73
|
-
* clearInterval?: (handle: any) => void
|
|
74
|
-
* }} o
|
|
75
|
-
*/
|
|
76
|
-
export function startAutoAttach(o) {
|
|
77
|
-
if (!o || !o.clientId) throw new Error('startAutoAttach: clientId 必填')
|
|
78
|
-
if (typeof o.claim !== 'function') throw new Error('startAutoAttach: claim 必须是函数')
|
|
79
|
-
|
|
80
|
-
const retryMs = o.retryMs || 1000
|
|
81
|
-
const heartbeatMs = o.heartbeatMs || DEFAULT_HEARTBEAT * 1000
|
|
82
|
-
const setI = o.setInterval || ((cb) => setInterval(cb, heartbeatMs))
|
|
83
|
-
const clearI = o.clearInterval || ((handle) => clearInterval(handle))
|
|
84
|
-
|
|
85
|
-
let active = false
|
|
86
|
-
let heartbeat = null
|
|
87
|
-
let disposed = false
|
|
88
|
-
|
|
89
|
-
async function tryClaim(force) {
|
|
90
|
-
try {
|
|
91
|
-
return await o.claim(force)
|
|
92
|
-
} catch {
|
|
93
|
-
return false
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function goActive() {
|
|
98
|
-
if (active) return
|
|
99
|
-
active = true
|
|
100
|
-
try { o.onActive && o.onActive() } catch { /* 用户回调失败不阻塞挂接 */ }
|
|
101
|
-
heartbeat = setI(async () => {
|
|
102
|
-
if (disposed) return
|
|
103
|
-
const ok = await tryClaim(false)
|
|
104
|
-
if (!ok) goStandby()
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function goStandby() {
|
|
109
|
-
if (!active) return
|
|
110
|
-
active = false
|
|
111
|
-
if (heartbeat != null) {
|
|
112
|
-
clearI(heartbeat)
|
|
113
|
-
heartbeat = null
|
|
114
|
-
}
|
|
115
|
-
try { o.onStandby && o.onStandby() } catch { /* 静默 */ }
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
;(async () => {
|
|
119
|
-
let first = true
|
|
120
|
-
while (!disposed) {
|
|
121
|
-
const ok = await tryClaim(first)
|
|
122
|
-
first = false
|
|
123
|
-
if (ok) {
|
|
124
|
-
goActive()
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
await new Promise((resolve) => setTimeout(resolve, retryMs))
|
|
128
|
-
}
|
|
129
|
-
})()
|
|
130
|
-
|
|
131
|
-
return {
|
|
132
|
-
get active() { return active },
|
|
133
|
-
dispose() {
|
|
134
|
-
disposed = true
|
|
135
|
-
goStandby()
|
|
136
|
-
try { o.release && o.release() } catch { /* 释放失败不阻塞退出 */ }
|
|
137
|
-
},
|
|
138
|
-
}
|
|
139
|
-
}
|
|
@@ -96,7 +96,7 @@ export function createMcpHandler({
|
|
|
96
96
|
if (method === 'initialize') {
|
|
97
97
|
const result = {
|
|
98
98
|
protocolVersion: String(params?.protocolVersion || DEFAULT_PROTOCOL),
|
|
99
|
-
capabilities: { tools: { listChanged:
|
|
99
|
+
capabilities: { tools: { listChanged: !!listChanged } },
|
|
100
100
|
serverInfo: serverInfo || { name: 'dsh-plugin', version: '0.0.0' },
|
|
101
101
|
}
|
|
102
102
|
if (typeof instructions === 'string' && instructions) result.instructions = instructions
|
|
@@ -108,13 +108,13 @@ export function createMcpHandler({
|
|
|
108
108
|
if (method === 'ping') return isNotification ? null : reply(id, {})
|
|
109
109
|
|
|
110
110
|
if (method === 'tools/list') {
|
|
111
|
-
return isNotification ? null : reply(id, { tools })
|
|
111
|
+
return isNotification ? null : reply(id, { tools: currentTools() })
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
if (method === 'tools/call') {
|
|
115
115
|
const name = params?.name
|
|
116
116
|
const args = params?.arguments && typeof params.arguments === 'object' ? params.arguments : {}
|
|
117
|
-
const tool =
|
|
117
|
+
const tool = toolMapNow().get(name)
|
|
118
118
|
if (!tool) {
|
|
119
119
|
if (isNotification) return null
|
|
120
120
|
return reply(id, {
|
package/package.json
CHANGED