@twinsearth/dsh-fang 3.1.17 → 3.1.20
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 +22 -9
- package/client.js +190 -1
- package/locale/en.json +2 -2
- package/locale/zh.json +2 -2
- package/package.json +1 -1
- package/src/kernel/types.mjs +1 -1
package/README.md
CHANGED
|
@@ -3,24 +3,37 @@
|
|
|
3
3
|
[](LICENSE-SDK)
|
|
4
4
|
[](https://www.npmjs.com/package/@twinsearth/dsh-fang)
|
|
5
5
|
|
|
6
|
-
# 瓮城
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
加载、运行、更新、回滚、卸载、回收,全生命周期管理。
|
|
7
|
+
# 瓮城:DSH 的第一台虚拟机!
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
> Dsh-瓮城,诞生于一群热爱折腾、也被折腾过无数次的极客之手。
|
|
10
|
+
> 我们深知在「自进化 AI」时代,**「如何安全地尝试新事物」比「新事物本身」更重要**。
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
## 如果你是以下三类人,瓮城就是为你量身定制的
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
### 1. 插件开发狂魔
|
|
15
|
+
每天要写 N 个新插件、改几百次代码。以前改一次重启一次 DSH;现在在瓮城里随便热更新,坏了直接秒回滚。
|
|
16
|
+
|
|
17
|
+
### 2. 多任务并发狂
|
|
18
|
+
一个窗口跑数据分析,一个窗口写爬虫,一个窗口做长周期测试。瓮城让你像开浏览器一样「多开不崩」,并且各跑各的绝对隔离。
|
|
19
|
+
|
|
20
|
+
### 3. 安全焦虑症患者
|
|
21
|
+
不敢把客户端交给第三方插件,怕乱删文件、怕被盗取 API Key。瓮城的审核系统和独立沙箱,把危险代码安排得明明白白。
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 它怎么做到
|
|
16
26
|
|
|
17
27
|
**母体大脑 + 分身器官 + 容器兜底**:
|
|
18
28
|
|
|
19
|
-
一个只读母体,每个任务派生一个用完即弃的子 dsh-Web;
|
|
29
|
+
- 一个只读母体,每个任务派生一个用完即弃的子 dsh-Web;
|
|
30
|
+
- 开发都在分身里,母体只在「提升」时被显式更新;
|
|
31
|
+
- 崩溃不扩散、污染不残留、插件不串味。
|
|
20
32
|
|
|
21
|
-
|
|
33
|
+
> 技术定位:**DeepSeek Harness 的第一台虚拟机**。
|
|
34
|
+
> 用 dsh-Web 当瓮城完成风险阻隔与审批(Beta),把 DeepSeek Harness 当主城保存原样不变(稳定版)。
|
|
22
35
|
|
|
23
|
-
|
|
36
|
+
---
|
|
24
37
|
|
|
25
38
|
> v2.3.1 把「瓮城」做进 Web UI(左侧导航 + 3:7 分屏控制面板 + 双击派生 + 母体/分身会话继续开发);
|
|
26
39
|
> v2.0.0 按三层拓扑重新部署,
|
package/client.js
CHANGED
|
@@ -6399,15 +6399,204 @@ window.__ModuleLoader__.load({
|
|
|
6399
6399
|
})
|
|
6400
6400
|
}
|
|
6401
6401
|
|
|
6402
|
+
|
|
6403
|
+
/**
|
|
6404
|
+
* v3.1.19:分身 Web 的界面收敛。
|
|
6405
|
+
*
|
|
6406
|
+
* 1) 隐藏左侧栏「插件」入口 —— 分身里不允许进入插件设置页(避免用户在一次性沙箱里
|
|
6407
|
+
* 改动宿主插件配置,导致下一次派生继承脏配置)。
|
|
6408
|
+
* 2) 「启动」类按钮在分身里变成真正无操作:capture 阶段拦下点击,
|
|
6409
|
+
* 宿主处理器不执行 → 不切换面板、不弹提醒、不打印错误。
|
|
6410
|
+
* (此前用户点「启动」会收到一条无法处理的报错,属噪音。)
|
|
6411
|
+
*
|
|
6412
|
+
* 只在 role === 'fork' 时生效;母体/元主不受影响。
|
|
6413
|
+
*/
|
|
6414
|
+
function mountForkUiLocks() {
|
|
6415
|
+
if (typeof document === 'undefined' || !document.body) return () => {}
|
|
6416
|
+
const doc = document
|
|
6417
|
+
let disposed = false
|
|
6418
|
+
let active = false
|
|
6419
|
+
let timer = 0
|
|
6420
|
+
let observer = null
|
|
6421
|
+
const NAV_TEXTS = ['插件']
|
|
6422
|
+
const ACTION_TEXTS = ['启动', '启动插件', '开始使用', '启用']
|
|
6423
|
+
|
|
6424
|
+
/** v3.1.20:宿主侧栏行类名会随版本变化,不再只认 panelRow。 */
|
|
6425
|
+
const isPanelRow = (node) => {
|
|
6426
|
+
try {
|
|
6427
|
+
if (!node || node.tagName !== 'BUTTON') return false
|
|
6428
|
+
const cls = String(node.className || '')
|
|
6429
|
+
if (/panelRow/i.test(cls)) return true
|
|
6430
|
+
// 兜底:侧栏/导航容器内的按钮
|
|
6431
|
+
return Boolean(node.closest('nav, aside, [class*="sidebar"], [class*="sideBar"], [class*="sider"]'))
|
|
6432
|
+
} catch { return false }
|
|
6433
|
+
}
|
|
6434
|
+
|
|
6435
|
+
/** 插件入口的文本判定(中英 + 少量变体),容忍零宽字符与多余空白。 */
|
|
6436
|
+
const isPluginNavText = (text) => {
|
|
6437
|
+
const clean = String(text || '').replace(/[\u200b-\u200d\ufeff]/g, '').replace(/\s+/g, ' ').trim()
|
|
6438
|
+
if (!clean) return false
|
|
6439
|
+
if (clean === '插件' || clean === 'Plugins' || clean === 'Plugin') return true
|
|
6440
|
+
// 「插件」后面可能跟计数徽标,例如「插件 3」
|
|
6441
|
+
return /^插件(\s|$)/.test(clean) || /^Plugins?(\s|$)/.test(clean)
|
|
6442
|
+
}
|
|
6443
|
+
|
|
6444
|
+
const hidePluginNav = () => {
|
|
6445
|
+
if (disposed || !active) return
|
|
6446
|
+
for (const node of doc.querySelectorAll('button')) {
|
|
6447
|
+
if (!isPanelRow(node)) continue
|
|
6448
|
+
if (!isPluginNavText(node.textContent)) continue
|
|
6449
|
+
if (node.dataset.fangForkHidden === '1' && node.hidden) continue
|
|
6450
|
+
node.dataset.fangForkHidden = '1'
|
|
6451
|
+
node.hidden = true
|
|
6452
|
+
node.setAttribute('aria-hidden', 'true')
|
|
6453
|
+
node.style.setProperty('display', 'none', 'important')
|
|
6454
|
+
}
|
|
6455
|
+
}
|
|
6456
|
+
|
|
6457
|
+
const onClickCapture = (event) => {
|
|
6458
|
+
if (!active || disposed) return
|
|
6459
|
+
const target = event.target
|
|
6460
|
+
const button = target && typeof target.closest === 'function' ? target.closest('button') : null
|
|
6461
|
+
if (!button) return
|
|
6462
|
+
const text = String(button.textContent || '').trim()
|
|
6463
|
+
// ① 侧栏「插件」入口:双重保险(DOM 已隐藏,这里再拦一次点击/键盘激活)
|
|
6464
|
+
if (isPanelRow(button) && isPluginNavText(text)) {
|
|
6465
|
+
event.preventDefault()
|
|
6466
|
+
event.stopPropagation()
|
|
6467
|
+
event.stopImmediatePropagation()
|
|
6468
|
+
return
|
|
6469
|
+
}
|
|
6470
|
+
// ② 插件页「启动」:无操作(不切换、不提醒、不报错)
|
|
6471
|
+
const isAction = ACTION_TEXTS.some((label) => text === label || text.startsWith(label))
|
|
6472
|
+
if (!isAction) return
|
|
6473
|
+
event.preventDefault()
|
|
6474
|
+
event.stopPropagation()
|
|
6475
|
+
event.stopImmediatePropagation()
|
|
6476
|
+
// ③ 万一宿主已被别处触发过提示,把残留的错误气泡收掉(仅限含错误语义的气泡)
|
|
6477
|
+
setTimeout(() => {
|
|
6478
|
+
if (disposed) return
|
|
6479
|
+
for (const node of doc.querySelectorAll('[role="alert"],[class*="toast"],[class*="Toast"]')) {
|
|
6480
|
+
const body = String(node.textContent || '')
|
|
6481
|
+
if (!/失败|错误|异常|无法|不能|不可|不允许|拒绝|failed|error/i.test(body)) continue
|
|
6482
|
+
if (node.dataset.fangForkAlertHidden === '1') continue
|
|
6483
|
+
node.dataset.fangForkAlertPrevDisplay = node.style.display || ''
|
|
6484
|
+
node.dataset.fangForkAlertHidden = '1'
|
|
6485
|
+
node.style.setProperty('display', 'none', 'important')
|
|
6486
|
+
}
|
|
6487
|
+
}, 60)
|
|
6488
|
+
}
|
|
6489
|
+
|
|
6490
|
+
const activate = () => {
|
|
6491
|
+
if (active || disposed) return
|
|
6492
|
+
active = true
|
|
6493
|
+
hidePluginNav()
|
|
6494
|
+
try {
|
|
6495
|
+
doc.documentElement?.setAttribute('data-fang-fork-locks', 'applied')
|
|
6496
|
+
window.__fangForkLocks = { applied: true, at: Date.now() }
|
|
6497
|
+
} catch { /* ignore */ }
|
|
6498
|
+
doc.addEventListener('click', onClickCapture, true)
|
|
6499
|
+
try {
|
|
6500
|
+
observer = new MutationObserver(() => { hidePluginNav() })
|
|
6501
|
+
observer.observe(doc.body, { childList: true, subtree: true })
|
|
6502
|
+
} catch { observer = null }
|
|
6503
|
+
timer = setInterval(hidePluginNav, 1500)
|
|
6504
|
+
try { timer && timer.unref && timer.unref() } catch { /* ignore */ }
|
|
6505
|
+
hidePluginNav()
|
|
6506
|
+
}
|
|
6507
|
+
|
|
6508
|
+
void (async () => {
|
|
6509
|
+
try {
|
|
6510
|
+
const role = await detectWebRole()
|
|
6511
|
+
if (disposed || role !== 'fork') return
|
|
6512
|
+
activate()
|
|
6513
|
+
} catch { /* 识别失败:保持原样,不误伤母体 */ }
|
|
6514
|
+
})()
|
|
6515
|
+
|
|
6516
|
+
return () => {
|
|
6517
|
+
disposed = true
|
|
6518
|
+
active = false
|
|
6519
|
+
if (timer) { clearInterval(timer); timer = 0 }
|
|
6520
|
+
try { observer?.disconnect() } catch { /* ignore */ }
|
|
6521
|
+
observer = null
|
|
6522
|
+
try { doc.removeEventListener('click', onClickCapture, true) } catch { /* ignore */ }
|
|
6523
|
+
// 恢复被隐藏的入口与提示,避免热卸载后宿主界面残缺
|
|
6524
|
+
for (const node of doc.querySelectorAll('button[data-fang-fork-hidden="1"]')) {
|
|
6525
|
+
try {
|
|
6526
|
+
node.hidden = false
|
|
6527
|
+
node.removeAttribute('aria-hidden')
|
|
6528
|
+
node.style.removeProperty('display')
|
|
6529
|
+
delete node.dataset.fangForkHidden
|
|
6530
|
+
} catch { /* ignore */ }
|
|
6531
|
+
}
|
|
6532
|
+
for (const node of doc.querySelectorAll('[data-fang-fork-alert-hidden="1"]')) {
|
|
6533
|
+
try {
|
|
6534
|
+
const prev = node.dataset.fangForkAlertPrevDisplay || ''
|
|
6535
|
+
if (prev) node.style.display = prev
|
|
6536
|
+
else node.style.removeProperty('display')
|
|
6537
|
+
delete node.dataset.fangForkAlertPrevDisplay
|
|
6538
|
+
delete node.dataset.fangForkAlertHidden
|
|
6539
|
+
} catch { /* ignore */ }
|
|
6540
|
+
}
|
|
6541
|
+
}
|
|
6542
|
+
}
|
|
6543
|
+
|
|
6544
|
+
|
|
6545
|
+
/**
|
|
6546
|
+
* v3.1.19:元主 / 分身 Web 的「关闭二次确认」。
|
|
6547
|
+
*
|
|
6548
|
+
* 右上角直接关闭很容易误触(尤其是把分身窗口当临时浏览器用时)。
|
|
6549
|
+
* 这里注册 beforeunload:浏览器会弹出原生「离开此网站?」确认框,
|
|
6550
|
+
* 用户确认后才真正关闭;母体(主会话)不注册,避免打断正常主机操作。
|
|
6551
|
+
*/
|
|
6552
|
+
function mountCloseConfirm() {
|
|
6553
|
+
if (typeof window === 'undefined') return () => {}
|
|
6554
|
+
let installed = false
|
|
6555
|
+
let disposed = false
|
|
6556
|
+
const onBeforeUnload = (event) => {
|
|
6557
|
+
try {
|
|
6558
|
+
event.preventDefault()
|
|
6559
|
+
// 现代浏览器忽略自定义文案,但仍要求设置 returnValue 才会弹确认框
|
|
6560
|
+
event.returnValue = '确认关闭瓮城窗口?未保存的分身状态会丢失。'
|
|
6561
|
+
} catch { /* ignore */ }
|
|
6562
|
+
return event.returnValue
|
|
6563
|
+
}
|
|
6564
|
+
const activate = () => {
|
|
6565
|
+
if (installed || disposed) return
|
|
6566
|
+
installed = true
|
|
6567
|
+
window.addEventListener('beforeunload', onBeforeUnload)
|
|
6568
|
+
// 兜底:宿主若用 history/路由隐藏关闭入口,键盘快捷键也走同一确认
|
|
6569
|
+
window.addEventListener('unload', () => {}, { once: true })
|
|
6570
|
+
}
|
|
6571
|
+
void (async () => {
|
|
6572
|
+
try {
|
|
6573
|
+
const role = await detectWebRole()
|
|
6574
|
+
if (disposed) return
|
|
6575
|
+
// 母体是主机式长驻窗口,不打断;元主/分身需要确认
|
|
6576
|
+
if (role === 'essence' || role === 'fork') activate()
|
|
6577
|
+
} catch { /* ignore */ }
|
|
6578
|
+
})()
|
|
6579
|
+
return () => {
|
|
6580
|
+
disposed = true
|
|
6581
|
+
if (!installed) return
|
|
6582
|
+
installed = false
|
|
6583
|
+
try { window.removeEventListener('beforeunload', onBeforeUnload) } catch { /* ignore */ }
|
|
6584
|
+
}
|
|
6585
|
+
}
|
|
6586
|
+
|
|
6402
6587
|
// ── 插件入口 ──────────────────────────────────────────────────────────
|
|
6403
6588
|
return {
|
|
6404
6589
|
mountPanel,
|
|
6405
|
-
...(typeof window !== 'undefined' && window.__FANG_TEST_HOOK__ ? { __renderDecisionMini: renderDecisionMini, __mountWebRoleBadge: mountWebRoleBadge, __detectWebRole: detectWebRole, __mountDecisionRelay: mountDecisionRelay } : {}),
|
|
6590
|
+
...(typeof window !== 'undefined' && window.__FANG_TEST_HOOK__ ? { __renderDecisionMini: renderDecisionMini, __mountWebRoleBadge: mountWebRoleBadge, __detectWebRole: detectWebRole, __mountForkUiLocks: mountForkUiLocks, __mountCloseConfirm: mountCloseConfirm, __mountDecisionRelay: mountDecisionRelay } : {}),
|
|
6406
6591
|
inject: ['slots'],
|
|
6407
6592
|
apply(ctx) {
|
|
6408
6593
|
const disposers = []
|
|
6409
6594
|
// v3.1.12:侧栏 HARNESS 右侧的 Web 端身份徽标(母体 / 元主 / 分身)。
|
|
6410
6595
|
disposers.push(mountWebRoleBadge())
|
|
6596
|
+
// v3.1.19:分身 Web 界面收敛(隐藏「插件」入口 + 「启动」无操作)。
|
|
6597
|
+
disposers.push(mountForkUiLocks())
|
|
6598
|
+
// v3.1.19:元主 / 分身 Web 关闭前二次确认(防误触)。
|
|
6599
|
+
disposers.push(mountCloseConfirm())
|
|
6411
6600
|
// 母体 Web = DSH 主会话视图;Web 端直接切回 conversation 面板。
|
|
6412
6601
|
const goMother = () => {
|
|
6413
6602
|
try {
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
|
-
"title": "
|
|
4
|
-
"description": "
|
|
3
|
+
"title": "Fangcheng: DSH's First Virtual Machine!",
|
|
4
|
+
"description": "Dsh-Fangcheng was born from a group of geeks who love tinkering — and have been burned by it more times than we can count. In the era of self-evolving AI, we believe that \"how to safely try something new\" matters more than \"the new thing itself\".\n\nIf you are one of these three, Fangcheng was built for you:\n1. The plugin-building maniac: writing N new plugins a day and changing code hundreds of times. You used to restart DSH after every edit; now you hot-reload inside Fangcheng, and a broken build rolls back instantly.\n2. The multi-tasker: one window for data analysis, one for a crawler, one for long-running tests. Fangcheng lets you open as many as you like without crashing — each in its own absolute isolation.\n3. The security worrier: unwilling to hand your client to third-party plugins, afraid of deleted files or stolen API keys. Fangcheng's review gates and independent sandboxes keep risky code boxed in."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
|
-
"title": "
|
|
4
|
-
"description": "
|
|
3
|
+
"title": "瓮城:DSH的第一台虚拟机!",
|
|
4
|
+
"description": "Dsh-瓮城,诞生于一群热爱折腾、也被折腾过无数次的极客之手。我们深知在“自进化 AI”时代,“如何安全地尝试新事物”比“新事物本身”更重要!\n\n如果你是以下三类人,瓮城就是为你量身定制的:\n1. 插件开发狂魔:每天要写 N 个新插件、改几百次代码。以前改一次重启一次 DSH;现在在瓮城里随便热更新,坏了直接秒回滚。\n2. 多任务并发狂:一个窗口跑数据分析,一个窗口写爬虫,一个窗口做长周期测试。瓮城让你像开浏览器一样“多开不崩”,并各跑各的绝对隔离。\n3. 安全焦虑症患者:不敢把客户端交给第三方插件,怕乱删文件、怕被盗取 API Key。瓮城的审核系统和独立沙箱,把危险代码安排得明明白白。"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twinsearth/dsh-fang",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.20",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "dsh-Fang (瓮城) — mother/fork plugin development environment for DeepSeek Harness: one readonly mother, a disposable child dsh-Web per task.",
|