@twinsearth/dsh-fang 3.1.20 → 3.1.22

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.
Files changed (115) hide show
  1. package/LICENSES/LICENSES/cordis-MIT.txt +39 -0
  2. package/client.js +197 -3
  3. package/defaults/defaults/umbrella-rules.yaml +113 -0
  4. package/package.json +2 -2
  5. package/sdk/sdk/README.md +65 -0
  6. package/sdk/sdk/examples/status-badge/README.md +16 -0
  7. package/sdk/sdk/examples/status-badge/client.js +60 -0
  8. package/sdk/sdk/examples/status-badge/cordis.patch.yml +7 -0
  9. package/sdk/sdk/examples/status-badge/index.js +12 -0
  10. package/sdk/sdk/examples/status-badge/package.json +24 -0
  11. package/sdk/sdk/templates/plugin/README.md +36 -0
  12. package/sdk/sdk/templates/plugin/client.js +35 -0
  13. package/sdk/sdk/templates/plugin/cordis.patch.yml +8 -0
  14. package/sdk/sdk/templates/plugin/icon.svg +5 -0
  15. package/sdk/sdk/templates/plugin/index.js +23 -0
  16. package/sdk/sdk/templates/plugin/locale/en.json +6 -0
  17. package/sdk/sdk/templates/plugin/package.json +36 -0
  18. package/src/kernel/types.mjs +1 -1
  19. package/src/lib/composer-journal.mjs +45 -0
  20. package/src/plugins/orchestrator.mjs +11 -1
  21. package/src/src/compose.mjs +67 -0
  22. package/src/src/contract/client.js +86 -0
  23. package/src/src/contract/constants.js +79 -0
  24. package/src/src/contract/envelope.js +83 -0
  25. package/src/src/contract/index.js +19 -0
  26. package/src/src/contract/negotiate.js +106 -0
  27. package/src/src/contract/server.js +77 -0
  28. package/src/src/contract/transports.js +301 -0
  29. package/src/src/index.mjs +11 -0
  30. package/src/src/kernel/core.mjs +100 -0
  31. package/src/src/kernel/extensions.mjs +61 -0
  32. package/src/src/kernel/fsx.mjs +349 -0
  33. package/src/src/kernel/index.mjs +21 -0
  34. package/src/src/kernel/ledger.mjs +94 -0
  35. package/src/src/kernel/paths.mjs +182 -0
  36. package/src/src/kernel/role.mjs +68 -0
  37. package/src/src/kernel/rounds.mjs +172 -0
  38. package/src/src/kernel/schema.mjs +5 -0
  39. package/src/src/kernel/types.mjs +264 -0
  40. package/src/src/kernel/vendor/cosmokit.mjs +421 -0
  41. package/src/src/kernel/vendor/schemastery.mjs +638 -0
  42. package/src/src/lib/adapter-client.mjs +383 -0
  43. package/src/src/lib/adapter-protocol.mjs +243 -0
  44. package/src/src/lib/ai-secret-store.mjs +202 -0
  45. package/src/src/lib/boot-guard.mjs +182 -0
  46. package/src/src/lib/branch-store.mjs +84 -0
  47. package/src/src/lib/branch.mjs +74 -0
  48. package/src/src/lib/bridge-client.mjs +133 -0
  49. package/src/src/lib/broker-adapter.mjs +67 -0
  50. package/src/src/lib/broker.mjs +45 -0
  51. package/src/src/lib/business-producers.mjs +109 -0
  52. package/src/src/lib/command-cache.mjs +209 -0
  53. package/src/src/lib/compat.mjs +170 -0
  54. package/src/src/lib/composer-journal.mjs +128 -0
  55. package/src/src/lib/container/index.mjs +806 -0
  56. package/src/src/lib/decision-events.mjs +129 -0
  57. package/src/src/lib/decision-ingest-client.mjs +41 -0
  58. package/src/src/lib/decision-outbox.mjs +129 -0
  59. package/src/src/lib/default-essence.mjs +61 -0
  60. package/src/src/lib/desktop-launch.mjs +138 -0
  61. package/src/src/lib/essence.mjs +1211 -0
  62. package/src/src/lib/fork-client.mjs +410 -0
  63. package/src/src/lib/fork-config-lock.mjs +153 -0
  64. package/src/src/lib/fork-seed.mjs +304 -0
  65. package/src/src/lib/fork-supervision-settings.mjs +58 -0
  66. package/src/src/lib/fork-supervisor.mjs +122 -0
  67. package/src/src/lib/fs-guard.mjs +28 -0
  68. package/src/src/lib/http-auth.mjs +162 -0
  69. package/src/src/lib/idle-audit.mjs +178 -0
  70. package/src/src/lib/interaction-poke.mjs +61 -0
  71. package/src/src/lib/mirror-etag.mjs +92 -0
  72. package/src/src/lib/mirror-official-source.mjs +93 -0
  73. package/src/src/lib/mirror.mjs +478 -0
  74. package/src/src/lib/mother-link.mjs +156 -0
  75. package/src/src/lib/mutex.mjs +31 -0
  76. package/src/src/lib/permissions.mjs +115 -0
  77. package/src/src/lib/pnpm-store.mjs +189 -0
  78. package/src/src/lib/preferences.mjs +212 -0
  79. package/src/src/lib/producer-contract.mjs +162 -0
  80. package/src/src/lib/reflow.mjs +41 -0
  81. package/src/src/lib/remote.mjs +408 -0
  82. package/src/src/lib/restart-contract.mjs +650 -0
  83. package/src/src/lib/roots.mjs +30 -0
  84. package/src/src/lib/rule-registry.mjs +1101 -0
  85. package/src/src/lib/runtime-capture.mjs +307 -0
  86. package/src/src/lib/semaphore.mjs +34 -0
  87. package/src/src/lib/session-bundle.mjs +138 -0
  88. package/src/src/lib/session-format.mjs +658 -0
  89. package/src/src/lib/sse-parser.mjs +102 -0
  90. package/src/src/lib/ssrf-guard.mjs +170 -0
  91. package/src/src/lib/status-store.mjs +257 -0
  92. package/src/src/lib/task-handle.mjs +622 -0
  93. package/src/src/lib/ui-actions.mjs +55 -0
  94. package/src/src/lib/umbrella.mjs +1661 -0
  95. package/src/src/lib/upgrade-coordinator.mjs +107 -0
  96. package/src/src/lib/upgrade-status.mjs +43 -0
  97. package/src/src/plugins/adapter.mjs +1468 -0
  98. package/src/src/plugins/approver.mjs +1210 -0
  99. package/src/src/plugins/auditor.mjs +330 -0
  100. package/src/src/plugins/buffer-keeper.mjs +522 -0
  101. package/src/src/plugins/decision-center.mjs +2265 -0
  102. package/src/src/plugins/forker.mjs +1594 -0
  103. package/src/src/plugins/healer.mjs +664 -0
  104. package/src/src/plugins/hot-reloader.mjs +274 -0
  105. package/src/src/plugins/imports.mjs +247 -0
  106. package/src/src/plugins/orchestrator.mjs +3806 -0
  107. package/src/src/plugins/restart-guard.mjs +948 -0
  108. package/src/src/plugins/router.mjs +714 -0
  109. package/src/src/plugins/scorer.mjs +624 -0
  110. package/src/src/plugins/session-bridge.mjs +166 -0
  111. package/src/src/plugins/session-catalog.mjs +771 -0
  112. package/src/src/plugins/session-router.mjs +125 -0
  113. package/src/src/plugins/session-sync.mjs +171 -0
  114. package/src/src/plugins/umbrella.mjs +419 -0
  115. package/tools/recover-queue.mjs +133 -0
@@ -0,0 +1,39 @@
1
+ # Third-party licenses
2
+
3
+ This directory contains license texts for third-party components included in this repository.
4
+
5
+ ## cordis (schemastery, cosmokit) — MIT
6
+
7
+ Upstream project: https://github.com/shigma/cordis
8
+ Copyright (c) 2022-present Shigma and cordis contributors.
9
+
10
+ Files vendored into `src/kernel/vendor/`:
11
+
12
+ - `schemastery.mjs` — runtime config schema library (import paths rewritten to a sibling file)
13
+ - `cosmokit.mjs` — utility library used by schemastery
14
+
15
+ ```
16
+ MIT License
17
+
18
+ Copyright (c) 2022-present Shigma and cordis contributors
19
+
20
+ Permission is hereby granted, free of charge, to any person obtaining a copy
21
+ of this software and associated documentation files (the "Software"), to deal
22
+ in the Software without restriction, including without limitation the rights
23
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24
+ copies of the Software, and to permit persons to whom the Software is
25
+ furnished to do so, subject to the following conditions:
26
+
27
+ The above copyright notice and this permission notice shall be included in all
28
+ copies or substantial portions of the Software.
29
+
30
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
+ SOFTWARE.
37
+ ```
38
+
39
+ > If the upstream license changes, the upstream `LICENSE` at the URL above governs.
package/client.js CHANGED
@@ -1756,6 +1756,15 @@ window.__ModuleLoader__.load({
1756
1756
  }
1757
1757
 
1758
1758
  async function deriveTask(payload) {
1759
+ // v3.1.23:元主派生必须绑定一个会话(不允许空白快速派生出来源不明的一次性分身)。
1760
+ if (!String(payload?.sessionId ?? '').trim()) {
1761
+ try {
1762
+ if ((await detectWebRole()) === 'essence') {
1763
+ setNotice({ tone: 'warn', title: '元主派生需要先选择一个会话', message: '请在左侧会话列表中选中一个进行中的会话,再点「从此会话派生」。' })
1764
+ return
1765
+ }
1766
+ } catch { /* 识别失败则按原行为 */ }
1767
+ }
1759
1768
  if (deriveStore.inflight) return
1760
1769
  deriveStore.lastGesture = Date.now()
1761
1770
  S.notice = null
@@ -6411,6 +6420,177 @@ window.__ModuleLoader__.load({
6411
6420
  *
6412
6421
  * 只在 role === 'fork' 时生效;母体/元主不受影响。
6413
6422
  */
6423
+
6424
+ /**
6425
+ * v3.1.23:元主(essence)Web 的界面收敛。
6426
+ *
6427
+ * 用户要求:
6428
+ * 1) 元主端不允许执行会话 / 任务 / 指令(派生与调度由房主 Router 负责);
6429
+ * 2) 元主派生新分身必须选一个会话,分身内不允许新建会话(只能分叉会话);
6430
+ * 3) 元主 Web 隐藏「工作区」「新会话」,只保留 插件安装/设置 与 系统设置,
6431
+ * 默认进入即打开插件设置页。
6432
+ *
6433
+ * 实现方式:DOM 收敛 + 事件拦截 + 一次性落地页跳转;不依赖宿主内部 API。
6434
+ */
6435
+ function mountEssenceUiLocks() {
6436
+ if (typeof document === 'undefined' || !document.body) return () => {}
6437
+ const doc = document
6438
+ let disposed = false
6439
+ let active = false
6440
+ let observer = null
6441
+ const NAV_HIDDEN = ['工作区', '新会话', '新建会话', 'Workspace', 'New session', 'New Session']
6442
+ const NOTICE_ID = 'fang-essence-notice'
6443
+
6444
+ const clean = (text) => String(text || '').replace(/[\u200b-\u200d\ufeff]/g, '').replace(/\s+/g, ' ').trim()
6445
+ const isPanelRow = (node) => {
6446
+ try {
6447
+ if (!node || node.tagName !== 'BUTTON') return false
6448
+ if (/panelRow/i.test(String(node.className || ''))) return true
6449
+ return Boolean(node.closest('nav, aside, [class*="sidebar"], [class*="sideBar"], [class*="sider"]'))
6450
+ } catch { return false }
6451
+ }
6452
+ const matchNav = (text) => {
6453
+ const value = clean(text)
6454
+ if (!value) return false
6455
+ return NAV_HIDDEN.some((label) => value === label || value.startsWith(label + ' '))
6456
+ }
6457
+ const isPluginNav = (text) => {
6458
+ const value = clean(text)
6459
+ return value === '插件' || value === 'Plugins' || /^插件(\s|$)/.test(value) || /^Plugins?(\s|$)/.test(value)
6460
+ }
6461
+
6462
+ const hideNavRows = () => {
6463
+ if (disposed || !active) return
6464
+ for (const node of doc.querySelectorAll('button')) {
6465
+ if (!isPanelRow(node)) continue
6466
+ const text = clean(node.textContent)
6467
+ if (!matchNav(text)) continue
6468
+ if (node.dataset.fangEssenceHidden === '1' && node.hidden) continue
6469
+ node.dataset.fangEssenceHidden = '1'
6470
+ node.hidden = true
6471
+ node.setAttribute('aria-hidden', 'true')
6472
+ node.style.setProperty('display', 'none', 'important')
6473
+ // 有些宿主用父级容器承载整行(工作区整块),一并收掉
6474
+ const row = node.closest('[class*="panelRow"],[class*="workspaceRow"],[data-workspace-row]')
6475
+ if (row && row !== node) {
6476
+ row.hidden = true
6477
+ row.dataset.fangEssenceHidden = '1'
6478
+ row.style.setProperty('display', 'none', 'important')
6479
+ }
6480
+ }
6481
+ }
6482
+
6483
+ /** 隐藏输入区:元主不执行会话/指令(避免误以为能在这里跑任务)。 */
6484
+ const hideComposer = () => {
6485
+ if (disposed || !active) return
6486
+ for (const textarea of doc.querySelectorAll('textarea')) {
6487
+ const box = textarea.closest('[class*="composer"],[class*="Composer"]') || textarea.parentElement?.parentElement
6488
+ if (!box) continue
6489
+ if (box.dataset.fangEssenceHidden === '1') continue
6490
+ box.dataset.fangEssenceHidden = '1'
6491
+ box.hidden = true
6492
+ box.setAttribute('aria-hidden', 'true')
6493
+ box.style.setProperty('display', 'none', 'important')
6494
+ }
6495
+ for (const node of doc.querySelectorAll('button')) {
6496
+ const label = clean(node.getAttribute?.('aria-label') || node.textContent)
6497
+ if (!/^(发送|Send|发送消息)$/.test(label)) continue
6498
+ if (node.dataset.fangEssenceHidden === '1') continue
6499
+ node.dataset.fangEssenceHidden = '1'
6500
+ node.hidden = true
6501
+ node.style.setProperty('display', 'none', 'important')
6502
+ }
6503
+ }
6504
+
6505
+ const insertNotice = () => {
6506
+ if (disposed || !active) return
6507
+ if (doc.getElementById(NOTICE_ID)) return
6508
+ const notice = doc.createElement('div')
6509
+ notice.id = NOTICE_ID
6510
+ notice.setAttribute('data-fang-essence-notice', '1')
6511
+ notice.setAttribute('role', 'status')
6512
+ notice.textContent = '元主 Web:仅插件安装/设置与系统设置可用;会话、任务与指令请在母体或分身中执行。'
6513
+ notice.style.cssText = 'position:fixed;left:16px;bottom:16px;z-index:2147483000;max-width:min(520px,60vw);' +
6514
+ 'padding:8px 12px;border-radius:10px;border:1px solid rgba(10,107,224,.25);background:rgba(232,241,253,.96);' +
6515
+ 'color:#0B3E8E;font:12px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif;box-shadow:0 2px 8px rgba(16,17,20,.08)'
6516
+ doc.body.appendChild(notice)
6517
+ }
6518
+
6519
+ /** 默认落地页 = 插件设置页(点一次侧栏「插件」,只做一次)。 */
6520
+ let landed = false
6521
+ const landOnPlugins = () => {
6522
+ if (disposed || !active || landed) return
6523
+ const button = [...doc.querySelectorAll('button')].find((node) => isPanelRow(node) && isPluginNav(clean(node.textContent)))
6524
+ if (!button) return
6525
+ landed = true
6526
+ try { button.click() } catch { /* ignore */ }
6527
+ doc.documentElement?.setAttribute?.('data-fang-essence-landing', 'plugins')
6528
+ }
6529
+
6530
+ const onClickCapture = (event) => {
6531
+ if (!active || disposed) return
6532
+ const button = event.target && typeof event.target.closest === 'function' ? event.target.closest('button') : null
6533
+ if (!button) return
6534
+ const text = clean(button.textContent)
6535
+ if (isPanelRow(button) && matchNav(text)) {
6536
+ event.preventDefault(); event.stopPropagation(); event.stopImmediatePropagation(); return
6537
+ }
6538
+ const label = clean(button.getAttribute?.('aria-label') || '')
6539
+ if (/^(发送|Send)$/.test(label) || /^(发送|Send)$/.test(text)) {
6540
+ event.preventDefault(); event.stopPropagation(); event.stopImmediatePropagation()
6541
+ }
6542
+ }
6543
+
6544
+ const onKeyDown = (event) => {
6545
+ if (!active || disposed) return
6546
+ if (event.key !== 'Enter' || event.shiftKey) return
6547
+ const target = event.target
6548
+ const inComposer = Boolean(target && typeof target.closest === 'function' && target.closest('[class*="composer"],[class*="Composer"],textarea'))
6549
+ if (!inComposer) return
6550
+ event.preventDefault(); event.stopPropagation(); event.stopImmediatePropagation()
6551
+ }
6552
+
6553
+ const apply = () => {
6554
+ if (disposed) return
6555
+ hideNavRows()
6556
+ hideComposer()
6557
+ insertNotice()
6558
+ landOnPlugins()
6559
+ }
6560
+ const start = () => {
6561
+ if (disposed || active) return
6562
+ active = true
6563
+ apply()
6564
+ try {
6565
+ observer = new MutationObserver(() => apply())
6566
+ observer.observe(doc.body, { childList: true, subtree: true })
6567
+ } catch { /* ignore */ }
6568
+ doc.addEventListener('click', onClickCapture, true)
6569
+ doc.addEventListener('keydown', onKeyDown, true)
6570
+ // 宿主首屏渲染有先后:分几次重试落地页与隐藏
6571
+ for (const delay of [300, 800, 1500, 3000]) setTimeout(apply, delay)
6572
+ doc.documentElement?.setAttribute?.('data-fang-essence-locks', 'applied')
6573
+ }
6574
+
6575
+ void detectWebRole().then((role) => {
6576
+ if (disposed) return
6577
+ if (role === 'essence') start()
6578
+ }).catch(() => { /* 识别失败则不启用 */ })
6579
+
6580
+ return () => {
6581
+ disposed = true
6582
+ active = false
6583
+ try { observer?.disconnect() } catch { /* ignore */ }
6584
+ try { doc.removeEventListener('click', onClickCapture, true) } catch { /* ignore */ }
6585
+ try { doc.removeEventListener('keydown', onKeyDown, true) } catch { /* ignore */ }
6586
+ try { doc.getElementById(NOTICE_ID)?.remove() } catch { /* ignore */ }
6587
+ for (const node of doc.querySelectorAll('[data-fang-essence-hidden="1"]')) {
6588
+ try { node.hidden = false; node.style.removeProperty('display'); node.removeAttribute('aria-hidden'); delete node.dataset.fangEssenceHidden } catch { /* ignore */ }
6589
+ }
6590
+ doc.documentElement?.removeAttribute?.('data-fang-essence-locks')
6591
+ }
6592
+ }
6593
+
6414
6594
  function mountForkUiLocks() {
6415
6595
  if (typeof document === 'undefined' || !document.body) return () => {}
6416
6596
  const doc = document
@@ -6418,7 +6598,7 @@ window.__ModuleLoader__.load({
6418
6598
  let active = false
6419
6599
  let timer = 0
6420
6600
  let observer = null
6421
- const NAV_TEXTS = ['插件']
6601
+ const NAV_TEXTS = ['插件', '新会话', '新建会话']
6422
6602
  const ACTION_TEXTS = ['启动', '启动插件', '开始使用', '启用']
6423
6603
 
6424
6604
  /** v3.1.20:宿主侧栏行类名会随版本变化,不再只认 panelRow。 */
@@ -6445,7 +6625,8 @@ window.__ModuleLoader__.load({
6445
6625
  if (disposed || !active) return
6446
6626
  for (const node of doc.querySelectorAll('button')) {
6447
6627
  if (!isPanelRow(node)) continue
6448
- if (!isPluginNavText(node.textContent)) continue
6628
+ const navText = String(node.textContent || '').trim()
6629
+ if (!isPluginNavText(navText) && !/^新会话$|^新建会话$/.test(navText)) continue
6449
6630
  if (node.dataset.fangForkHidden === '1' && node.hidden) continue
6450
6631
  node.dataset.fangForkHidden = '1'
6451
6632
  node.hidden = true
@@ -6585,9 +6766,20 @@ window.__ModuleLoader__.load({
6585
6766
  }
6586
6767
 
6587
6768
  // ── 插件入口 ──────────────────────────────────────────────────────────
6769
+ // v3.1.23:jsdom 回归用钩子桥(只在测试模式挂到 window,正常运行时不存在)
6770
+ if (typeof window !== 'undefined' && window.__FANG_TEST_HOOK__) {
6771
+ window.__fangTestHooks = window.__fangTestHooks || {}
6772
+ Object.assign(window.__fangTestHooks, {
6773
+ __mountEssenceUiLocks: mountEssenceUiLocks,
6774
+ __mountForkUiLocks: mountForkUiLocks,
6775
+ __mountCloseConfirm: mountCloseConfirm,
6776
+ __detectWebRole: detectWebRole,
6777
+ })
6778
+ }
6779
+
6588
6780
  return {
6589
6781
  mountPanel,
6590
- ...(typeof window !== 'undefined' && window.__FANG_TEST_HOOK__ ? { __renderDecisionMini: renderDecisionMini, __mountWebRoleBadge: mountWebRoleBadge, __detectWebRole: detectWebRole, __mountForkUiLocks: mountForkUiLocks, __mountCloseConfirm: mountCloseConfirm, __mountDecisionRelay: mountDecisionRelay } : {}),
6782
+ ...(typeof window !== 'undefined' && window.__FANG_TEST_HOOK__ ? { __renderDecisionMini: renderDecisionMini, __mountWebRoleBadge: mountWebRoleBadge, __detectWebRole: detectWebRole, __mountForkUiLocks: mountForkUiLocks, __mountEssenceUiLocks: mountEssenceUiLocks, __mountCloseConfirm: mountCloseConfirm, __mountDecisionRelay: mountDecisionRelay } : {}),
6591
6783
  inject: ['slots'],
6592
6784
  apply(ctx) {
6593
6785
  const disposers = []
@@ -6595,6 +6787,8 @@ window.__ModuleLoader__.load({
6595
6787
  disposers.push(mountWebRoleBadge())
6596
6788
  // v3.1.19:分身 Web 界面收敛(隐藏「插件」入口 + 「启动」无操作)。
6597
6789
  disposers.push(mountForkUiLocks())
6790
+ // v3.1.23:元主 Web 界面收敛(隐藏工作区/新会话、只留插件与系统设置、默认落地插件页)。
6791
+ disposers.push(mountEssenceUiLocks())
6598
6792
  // v3.1.19:元主 / 分身 Web 关闭前二次确认(防误触)。
6599
6793
  disposers.push(mountCloseConfirm())
6600
6794
  // 母体 Web = DSH 主会话视图;Web 端直接切回 conversation 面板。
@@ -0,0 +1,113 @@
1
+ # dsh-Fang v2.8.1 — Umbrella 推荐基线配置(随包分发,项目不可替换,只能叠加)
2
+ #
3
+ # 加载顺序(后加载的层按 id 覆盖先加载的层;未列出的规则保持内置默认):
4
+ # 1) 本文件(包内基线) ← defaults/umbrella-rules.yaml
5
+ # 2) 项目级 <project>/.dsh/umbrella-rules.yaml(插件配置 rulesFile)
6
+ # 3) 环境级 $UMBRELLA_RULES_PATH(CI/部署注入,可选)
7
+ #
8
+ # 锁定语义:带 non-negotiable / hard-deny 标签的规则不可被**关闭**、不可被**降低灯色**;
9
+ # 允许项目追加 pattern(扩大覆盖面)或提升灯色(更严格)。
10
+ # 项目尝试关闭硬规则 → 该层错误;若该层 failOnInvalidPattern: true → 整层拒绝,回退到基线。
11
+ #
12
+ # 说明:本文件刻意**只显式写硬规则与兜底**。可调规则留空 = 使用内置默认值,
13
+ # 项目按需在自己的叠加层里覆盖(示例见文件末尾注释与 docs/RULES-BASELINE.md)。
14
+
15
+ version: 1
16
+
17
+ settings:
18
+ failOnUnknownRule: false # 未知 id 只警告,不阻断(基线可能领先于代码)
19
+ failOnInvalidPattern: true # 正则/声明式规则编译失败视为配置错误,整层拒绝(宁可不启动)
20
+ rejectUnsafeRegex: true # 拒绝明显灾难回溯的正则形状
21
+
22
+ rules:
23
+ # ── 硬规则:显式锁定(不可关闭、不可降级)──────────────────────────────
24
+ - id: dsh-lifecycle
25
+ enabled: true
26
+ light: red
27
+ priority: 10
28
+ reason: "DSH 宿主的生命周期动作(重启/终止/进程级),必须转交 restart-guard 审批"
29
+ tags: [hard-deny, non-negotiable, delegate-to-restart-guard]
30
+
31
+ - id: destructive-command
32
+ enabled: true
33
+ light: red
34
+ priority: 20
35
+ reason: "破坏性 shell 命令(rm -rf / format / shutdown / 强制推送等),一律红色"
36
+ tags: [hard-deny, non-negotiable]
37
+
38
+ - id: credential-access
39
+ enabled: true
40
+ light: red
41
+ priority: 30
42
+ reason: "读取凭据路径(.ssh/.aws/.gnupg/.git-credentials 等),唯一硬拒绝出口"
43
+ tags: [hard-deny, non-negotiable]
44
+
45
+ # ── 兜底:安全网(不可关闭)──────────────────────────────────────────────
46
+ # 未登记的工具/没有可识别目标时落到这里;优先级 9999 保证它永远最后。
47
+ - id: unknown-tool
48
+ enabled: true
49
+ light: yellow
50
+ priority: 9999
51
+ reason: "未知工具或目标:行为不可预测,保守判黄(需审批)"
52
+ tags: [conservative, non-negotiable]
53
+
54
+ # ── 可调规则:留空 = 使用内置默认。下面是**推荐值**(注释形式),项目按需覆盖 ──
55
+ #
56
+ # 用于参考的默认(与 DEFAULT_RULE_PRIORITIES 一致):
57
+ # network-allowlisted blue 40 外连命中允许列表 → 放行 + 标记
58
+ # network-egress yellow 50 外连未在允许列表 → 拆审批
59
+ # dynamic-import yellow 60 动态加载未评分模块 → 先扫描
60
+ # write-in-buffer blue 70 写沙箱缓冲区 → 放行 + 标记
61
+ # write-in-allowlist blue 80 写允许列表路径 → 放行 + 标记
62
+ # write-production yellow 90 写生产区 → 需审批
63
+ # write-outside-buffer yellow 100 写越界 → 需审批
64
+ # exec-read-only blue 110 只读 shell(无重定向)→ 放行 + 标记
65
+ # exec-side-effect yellow 120 shell 有副作用 → 需审批
66
+ # read-in-buffer green 130 读沙箱缓冲区 → 自动放行
67
+ # read-outside-buffer blue 140 读缓冲区外 → 放行 + 标记
68
+ #
69
+ # 项目级覆盖示例(写在 <project>/.dsh/umbrella-rules.yaml):
70
+ #
71
+ # version: 1
72
+ # settings:
73
+ # failOnInvalidPattern: true
74
+ # rules:
75
+ # # 更严格:越界写从黄升红
76
+ # - id: write-outside-buffer
77
+ # light: red
78
+ # reason: "本项目:任何越界写都直接拒绝"
79
+ #
80
+ # # 更严格:生产区写也需要人工审批(升红)
81
+ # - id: write-production
82
+ # light: red
83
+ #
84
+ # # 追加凭据 pattern(硬规则允许"扩大覆盖面",不允许关闭)
85
+ # - id: credential-access
86
+ # pathPatterns:
87
+ # - re: "\\.npmrc$"
88
+ # label: "npm registry token"
89
+ # - re: "secrets[\\\\/]"
90
+ # label: "project secrets directory"
91
+ #
92
+ # # 项目专属声明式规则
93
+ # - id: project-build-guard
94
+ # category: destructive
95
+ # light: red
96
+ # reason: "禁止删除构建目录"
97
+ # priority: 25
98
+ # match:
99
+ # kind: command-pattern
100
+ # patterns:
101
+ # - re: "\\brm\\s+-rf\\s+(?:dist|build|out)\\b"
102
+ # label: "delete build directory"
103
+ # evidence:
104
+ # kind: pattern-match
105
+ #
106
+ # # 以下写法会被拒绝(硬规则锁定):
107
+ # # - id: destructive-command
108
+ # # enabled: false # → "cannot be disabled"
109
+ # # - id: credential-access
110
+ # # light: yellow # → "light cannot be lowered from red to yellow"
111
+ #
112
+ # 注意:`light: blue` 不能把 network-egress 变成"内网放行"——它的谓词看 allowHosts;
113
+ # 要放行内网域请把它们加入 policy.networkAllowlist,而不是只改灯色。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/dsh-fang",
3
- "version": "3.1.20",
3
+ "version": "3.1.22",
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.",
@@ -50,7 +50,7 @@
50
50
  "node": ">=22"
51
51
  },
52
52
  "optionalDependencies": {
53
- "@twinsearth/dsh-fang-queue-journal": "0.1.4",
53
+ "@twinsearth/dsh-fang-queue-journal": "^0.1.6",
54
54
  "@twinsearth/dsh-fang-web-entry": "0.1.1"
55
55
  },
56
56
  "devDependencies": {
@@ -0,0 +1,65 @@
1
+ # dsh-Fang 生态层(MIT)
2
+
3
+ 这个目录是 dsh-Fang 的**生态层**,使用 [MIT 许可](../LICENSE-SDK):
4
+ 插件 SDK、模板、示例都可以零摩擦复制、修改、二次分发,甚至闭源集成进你的产品。
5
+
6
+ > 核心层(编排器/派生器/红线守卫/Adapter/容器执行器等)在 `src/` 下,使用 **AGPL-3.0**(见
7
+ > `../LICENSE-CORE`);商业层(Relay/企业功能)在 `../relay-server`、`../enterprise`,闭源。
8
+ > 逐目录许可地图见 [`../NOTICE`](../NOTICE)。
9
+
10
+ ---
11
+
12
+ ## 1. 一个 dsh-Fang 插件长什么样
13
+
14
+ Fang 插件就是一个 DSH bundle:一个 npm 包目录,带
15
+
16
+ ```
17
+ my-plugin/
18
+ ├── package.json # name + dsh.bundle.patch(+ 可选 dsh.client 声明浏览器半)
19
+ ├── cordis.patch.yml # 安装时把本插件的 loader 行 insert 进 profile
20
+ ├── index.js # Host 半:export const name/inject/Config/apply
21
+ └── client.js # 可选 Client 半:window.__ModuleLoader__.load({...})
22
+ ```
23
+
24
+ 安装(不需要发布到 npm):
25
+
26
+ ```powershell
27
+ # 在 DSH 会话里对 Agent 说:
28
+ # plugin_manager install_bundle(target="E:\path\to\my-plugin")
29
+ # 或者由你的发布脚本调用 DSH 的 plugin_manager
30
+ ```
31
+
32
+ ## 2. 模板
33
+
34
+ - [`templates/plugin/`](templates/plugin/) — 最小可安装插件(Host + 可选 Client + 图标 + locale)
35
+ - [`examples/status-badge/`](examples/status-badge/) — 读取瓮城 `/fang/api/status` 并在输入框下方显示徽标
36
+ (演示"第三方插件如何安全调用 Fang 的公开 HTTP 面")
37
+
38
+ 复制模板:
39
+
40
+ ```powershell
41
+ Copy-Item -Recurse sdk\templates\plugin my-plugin
42
+ # 改 package.json 里的 name / 行 id / patch 里的 id
43
+ ```
44
+
45
+ ## 3. 与瓮城核心交互的三种合法方式
46
+
47
+ | 方式 | 适用 | 协议边界 |
48
+ |---|---|---|
49
+ | 读 `/fang/api/status`、`/fang/api/tasks`、`/fang/api/sessions` | 面板/徽标/旁路观察 | 只读 HTTP,最安全 |
50
+ | `POST /fang/api/derive`、`/tasks/*`、`/promote` | 自动化工作流 | 写入前请遵守核心的配额与审批语义 |
51
+ | Adapter 协议(仅分身内,`/fang/adapter/*`) | 分身内插件 | 需要分身 token;不要在母体调用 |
52
+
53
+ > 插件与核心之间通过**公开 HTTP API** 交互时,你的插件是独立作品,可以自选许可证
54
+ > (MIT/Apache/闭源均可)——这正是生态层 MIT 的意义。
55
+
56
+ ## 4. 需要遵守的少量规则
57
+
58
+ - 不要从其他插件的 DOM / 样式表里"猜"布局;用 slots 与主题 token(`--dsw-alias-*`)。
59
+ - Client 半不要 `require` 其他 DSH Client 包;React 来自浏览器模块表。
60
+ - 定时器/监听器用 `ctx.effect` 注册清理。
61
+ - 不要写 `$DSH_HOME/profiles/**`;通过 bundle/plugin_manager 安装。
62
+
63
+ ## 5. 贡献
64
+
65
+ 生态层(`sdk/`、`tools/fangctl.mjs`)的贡献同样需要签署 [CLA](../CLA.md)(为了让项目能双许可)。
@@ -0,0 +1,16 @@
1
+ # status-badge(MIT 示例插件)
2
+
3
+ 演示第三方插件如何**只通过公开 HTTP 面**与瓮城交互:
4
+
5
+ - `index.js`:Host 半,提供一个只读服务(证明插件已加载);
6
+ - `client.js`:Client 半,每 10s 拉一次 `GET /fang/api/status`,在输入框下方显示「瓮城 N/M」。
7
+ - 不 import 任何瓮城内部模块 → 它是独立作品,可自由选许可证(本示例为 MIT)。
8
+
9
+ 安装:
10
+
11
+ ```powershell
12
+ # DSH 会话里:
13
+ # plugin_manager install_bundle(target="<repo>\\sdk\\examples\\status-badge")
14
+ ```
15
+
16
+ 失败态:拉不到 `/fang/api/status` 时显示「瓮城离线」,不假装有数据。
@@ -0,0 +1,60 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Example client half: read dsh-Fang's public read-only HTTP surface and show it in the dock.
3
+ // This demonstrates the recommended third-party integration: HTTP only, no host internals.
4
+ window.__ModuleLoader__.load({
5
+ id: '@fang-example/status-badge',
6
+ factory(require) {
7
+ const React = require('react')
8
+ const h = React.createElement
9
+
10
+ function StatusBadge() {
11
+ const [view, setView] = React.useState({ state: 'loading', text: '瓮城 …' })
12
+ React.useEffect(() => {
13
+ let alive = true
14
+ const poll = async () => {
15
+ try {
16
+ const res = await fetch('/fang/api/status', { headers: { accept: 'application/json' } })
17
+ if (!res.ok) throw new Error('status ' + res.status)
18
+ const body = await res.json()
19
+ if (!alive) return
20
+ const ready = body?.tasks?.ready ?? 0
21
+ const max = body?.tasks?.max ?? '?'
22
+ setView({ state: 'ok', text: `瓮城 ${ready}/${max}`, version: body?.version })
23
+ } catch {
24
+ if (alive) setView({ state: 'off', text: '瓮城离线' })
25
+ }
26
+ }
27
+ poll()
28
+ const timer = setInterval(poll, 10000)
29
+ return () => { alive = false; clearInterval(timer) }
30
+ }, [])
31
+
32
+ const color = view.state === 'ok'
33
+ ? 'var(--dsw-alias-state-success, #22c55e)'
34
+ : view.state === 'off'
35
+ ? 'var(--dsw-alias-state-warning, #9ca3af)'
36
+ : 'var(--dsw-alias-state-business-primary, #2563eb)'
37
+ return h('div', {
38
+ title: view.version ? `dsh-Fang ${view.version}` : 'dsh-Fang 状态(第三方插件示例)',
39
+ style: {
40
+ display: 'inline-flex', alignItems: 'center', gap: 6, padding: '2px 8px', borderRadius: 999,
41
+ fontSize: 11, color: 'var(--dsw-alias-label-secondary, #888)',
42
+ border: '1px solid var(--dsw-alias-border, rgba(127,127,127,.3))',
43
+ },
44
+ },
45
+ h('span', { 'aria-hidden': true, style: { width: 6, height: 6, borderRadius: '50%', background: color } }),
46
+ h('span', null, view.text))
47
+ }
48
+
49
+ return {
50
+ inject: ['slots'],
51
+ apply(ctx) {
52
+ return ctx.slots.inject('conversation.composer.dock', () => ctx.slots.register({
53
+ name: 'conversation.composer.dock',
54
+ id: 'fang-example-status-badge',
55
+ order: 70,
56
+ }, (props) => h(StatusBadge, { ...props, ctx })))
57
+ },
58
+ }
59
+ },
60
+ })
@@ -0,0 +1,7 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Example plugin row: host half marks the plugin present; the client half talks to /fang/api/status.
3
+ - insert:
4
+ - id: fang-example-status-badge
5
+ name: '@fang-example/status-badge'
6
+ config:
7
+ intervalMs: 10000
@@ -0,0 +1,12 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Example host half: exposes a tiny service so the plugin is observable, and nothing else.
3
+ export const name = 'fang-example-status-badge'
4
+ export const inject = []
5
+
6
+ export function apply(ctx, config) {
7
+ const cfg = { intervalMs: 10000, ...(config ?? {}) }
8
+ ctx.effect(() => ctx.provide('fangExampleStatusBadge', {
9
+ intervalMs: () => cfg.intervalMs,
10
+ at: new Date().toISOString(),
11
+ }))
12
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@fang-example/status-badge",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "description": "Example MIT plugin: shows dsh-Fang status next to the composer (third-party plugin calling Fang's public HTTP surface).",
7
+ "exports": {
8
+ ".": "./index.js",
9
+ "./client": {
10
+ "browser": "./client.js",
11
+ "default": "./client.js"
12
+ }
13
+ },
14
+ "files": ["index.js", "client.js", "cordis.patch.yml"],
15
+ "license": "MIT",
16
+ "dsh": {
17
+ "bundle": { "patch": "./cordis.patch.yml" },
18
+ "client": {
19
+ "platform": "web",
20
+ "immediately": true,
21
+ "inject": ["@deepseek-ai/dsh-client-connection"]
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,36 @@
1
+ # 插件模板(MIT)
2
+
3
+ 最小可安装的 DSH / dsh-Fang 插件,包含 Host 半(`index.js`)与可选的 Client 半(`client.js`)。
4
+
5
+ ## 用法
6
+
7
+ ```powershell
8
+ Copy-Item -Recurse sdk\templates\plugin E:\my\my-plugin
9
+ cd E:\my\my-plugin
10
+ # 1) 改 package.json:name、dsh.client(不需要 UI 就删掉 dsh.client 与 client.js)
11
+ # 2) 改 cordis.patch.yml:id 与 name 保持一致
12
+ # 3) 在 DSH 会话里安装:
13
+ # plugin_manager install_bundle(target="E:\\my\\my-plugin")
14
+ ```
15
+
16
+ ## 结构
17
+
18
+ | 文件 | 作用 |
19
+ |---|---|
20
+ | `package.json` | `dsh.bundle.patch` 让它成为可安装 bundle;`dsh.client` 声明浏览器半 |
21
+ | `cordis.patch.yml` | 安装时把 `my-plugin` 这一行 insert 进 profile 的 loader 树 |
22
+ | `index.js` | Host 半:`export const name / inject / apply`;用 `ctx.effect(ctx.provide(...))` 提供能力 |
23
+ | `client.js` | Client 半:向 `conversation.composer.dock` 注册一个徽标(可删) |
24
+ | `locale/en.json` | 界面上显示给用户的标题与描述(国际化) |
25
+ | `icon.svg` | 插件图标;不要用上游/他人的图标 |
26
+
27
+ ## 可配置
28
+
29
+ 模板刻意**不带** `Config`,避免模板依赖 schema 库。需要配置时,把 schemastery(MIT)复制到
30
+ `vendor/` 再 `export const Config = z.object({...})`——核心层的做法可直接参考。
31
+
32
+ ## 与瓮城交互
33
+
34
+ 第三方插件调用瓮城只看公开 HTTP 面:`/fang/api/status`、`/fang/api/tasks`、`/fang/api/sessions`、
35
+ `POST /fang/api/derive` 等(见 [`../../README.md`](../../README.md))。用 HTTP 交互时你的插件是独立作品,
36
+ 可以选择自己的许可证。