@twinsearth/dsh-fang 3.0.9 → 3.1.0

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 CHANGED
@@ -1,20 +1,26 @@
1
1
  [![CI](https://github.com/TwinsEarth/dsh-fang/actions/workflows/ci.yml/badge.svg)](https://github.com/TwinsEarth/dsh-fang/actions/workflows/ci.yml)
2
2
  [![License: AGPL-3.0](https://img.shields.io/badge/license-AGPL--3.0-blue.svg)](LICENSE-CORE)
3
3
  [![SDK: MIT](https://img.shields.io/badge/SDK-MIT-green.svg)](LICENSE-SDK)
4
- [![npm](https://img.shields.io/badge/npm-dsh--fang-red.svg)](https://www.npmjs.com/package/@twinsearth/dsh-fang)
4
+ [![npm latest](https://img.shields.io/npm/v/@twinsearth/dsh-fang.svg?label=npm&color=red)](https://www.npmjs.com/package/@twinsearth/dsh-fang)
5
5
 
6
6
  # 瓮城
7
7
 
8
8
  ## 让DSH不再需要反复重启客户端:
9
9
  加载、运行、更新、回滚、卸载、回收,全生命周期管理。
10
10
 
11
- ### 技术原理:DSH的第一台虚拟机!
11
+ ### 技术原理:DeepSeekHarness的第一台虚拟机!
12
12
 
13
13
  1.用dsh-Web,当瓮城完成风险阻隔&审批(Beta)
14
+
14
15
  2.DeepSeekHarness,当主城保存原样不变(稳定版)
15
16
 
16
- **母体大脑 + 分身器官 + 容器兜底**:一个只读母体,每个任务派生一个用完即弃的子 dsh-Web;
17
- 开发都在分身里,母体只在「提升」时被显式更新。崩溃不扩散、污染不残留、插件不串味。
17
+ **母体大脑 + 分身器官 + 容器兜底**:
18
+
19
+ 一个只读母体,每个任务派生一个用完即弃的子 dsh-Web;
20
+
21
+ 开发都在分身里,母体只在「提升」时被显式更新。
22
+
23
+ 崩溃不扩散、污染不残留、插件不串味。
18
24
 
19
25
  > v2.3.1 把「瓮城」做进 Web UI(左侧导航 + 3:7 分屏控制面板 + 双击派生 + 母体/分身会话继续开发);
20
26
  > v2.0.0 按三层拓扑重新部署,
package/client.js CHANGED
@@ -187,6 +187,20 @@ window.__ModuleLoader__.load({
187
187
  window.localStorage.setItem(key, value ? '1' : '0')
188
188
  } catch { /* 隐私模式:偏好只影响本次会话 */ }
189
189
  }
190
+ function readNumberPref(key, fallback) {
191
+ try {
192
+ if (typeof window === 'undefined' || !window.localStorage) return fallback
193
+ const raw = window.localStorage.getItem(key)
194
+ const n = Number(raw)
195
+ return raw !== null && Number.isFinite(n) ? n : fallback
196
+ } catch { return fallback }
197
+ }
198
+ function writeNumberPref(key, value) {
199
+ try {
200
+ if (typeof window === 'undefined' || !window.localStorage) return
201
+ window.localStorage.setItem(key, String(value))
202
+ } catch { /* 隐私模式 */ }
203
+ }
190
204
 
191
205
  // ── 标题降级:绝不把工作区名当会话标题 ────────────────────────────────
192
206
  function sessionTitleInfo(session) {
@@ -654,8 +668,14 @@ window.__ModuleLoader__.load({
654
668
  .chip--neutral{color:var(--f-text-3);background:var(--f-surface-2);border-color:var(--f-border)}
655
669
 
656
670
  /* layout */
657
- .fang-body{display:grid;grid-template-columns:minmax(320px,1fr) minmax(0,1fr);gap:16px;align-items:start;min-height:0;flex:1 1 auto}
658
- @media (max-width:1100px){.fang-body{grid-template-columns:1fr}}
671
+ .fang-body{position:relative;display:grid;grid-template-columns:minmax(320px,50fr) minmax(0,50fr);gap:16px;align-items:start;min-height:0;flex:1 1 auto}
672
+ .fang-body.is-resizing{cursor:col-resize;user-select:none}
673
+ .fang-body.is-resizing *{user-select:none}
674
+ .fang-split-handle{position:absolute;top:0;bottom:0;left:50%;width:10px;transform:translateX(-50%);cursor:col-resize;z-index:6;border-radius:6px;background:transparent;touch-action:none}
675
+ .fang-split-handle::after{content:"";position:absolute;top:50%;left:50%;width:3px;height:46px;transform:translate(-50%,-50%);border-radius:3px;background:var(--f-border-strong,var(--f-border));opacity:.55;transition:opacity .15s,background .15s}
676
+ .fang-split-handle:hover::after,.fang-split-handle:focus-visible::after,.fang-body.is-resizing .fang-split-handle::after{opacity:1;background:var(--f-blue,#3b82f6)}
677
+ .fang-split-handle:focus-visible{outline:2px solid var(--f-blue,#3b82f6);outline-offset:2px}
678
+ @media (max-width:1100px){.fang-body{grid-template-columns:1fr}.fang-split-handle{display:none}}
659
679
  .panel{background:var(--f-surface);border:1px solid var(--f-border);border-radius:var(--f-radius-panel);
660
680
  box-shadow:var(--f-shadow-card);display:flex;flex-direction:column;min-height:0;overflow:hidden;
661
681
  max-height:calc(100vh - 132px)}
@@ -923,8 +943,8 @@ window.__ModuleLoader__.load({
923
943
  .section-title{min-height:34px}
924
944
  }
925
945
  .btn--sm{min-height:34px}
926
- .expand-btn{width:34px;height:34px}
927
- .section-title{min-height:34px}
946
+ .expand-btn{width:34px;height:34px;min-width:34px}
947
+ .section-title{min-height:34px;min-width:34px}
928
948
  .fork-actions .btn,.fork-actions .text-action{min-height:34px}
929
949
  @media (prefers-reduced-motion:reduce){
930
950
  .fang-console *,.fang-console *::before,.fang-console *::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important}
@@ -1078,6 +1098,11 @@ window.__ModuleLoader__.load({
1078
1098
  expanded: new Set(),
1079
1099
  collapsed: new Set(['temporary']),
1080
1100
  collapsedTasks: new Set(),
1101
+ // 主工作区比例:元宝工作区 / 分身工作区,默认 50:50,可拖动中间手柄调整。
1102
+ splitRatio: (() => {
1103
+ const n = readNumberPref('fang.panel.split', 0.5)
1104
+ return Math.min(0.75, Math.max(0.25, Number.isFinite(n) ? n : 0.5))
1105
+ })(),
1081
1106
  showTemporary: readPref('fang.panel.showTemporary', true),
1082
1107
  // 母体会话只读投影:默认只看最近 20 条,可切 50 / 全部(偏好存本机)。
1083
1108
  sessionWindow: (() => {
@@ -3716,9 +3741,63 @@ window.__ModuleLoader__.load({
3716
3741
  for (const node of renderNotices(S, app)) frag.append(node)
3717
3742
 
3718
3743
  if (S.role.value === 'mother') {
3719
- frag.append(h('div', { class: 'fang-body', 'aria-busy': S.refreshing ? 'true' : undefined },
3720
- renderMotherPanel(S, app),
3721
- renderForkPanel(S, app)))
3744
+ const body = h('div', { class: 'fang-body', 'aria-busy': S.refreshing ? 'true' : undefined })
3745
+ body.append(renderMotherPanel(S, app), renderForkPanel(S, app))
3746
+ // 中间拖动手柄:默认 50:50,可拖动/键盘方向键调整,双击恢复 50:50(偏好存本机)。
3747
+ const handle = h('div', {
3748
+ class: 'fang-split-handle',
3749
+ role: 'separator',
3750
+ 'aria-orientation': 'vertical',
3751
+ 'aria-label': '调整元宝工作区与分身工作区比例',
3752
+ 'aria-valuemin': '25',
3753
+ 'aria-valuemax': '75',
3754
+ tabindex: '0',
3755
+ title: '拖动调整比例;双击恢复 50:50',
3756
+ })
3757
+ const applyRatio = (ratio, persist = false) => {
3758
+ const clamped = Math.min(0.75, Math.max(0.25, Number.isFinite(ratio) ? ratio : 0.5))
3759
+ S.splitRatio = clamped
3760
+ const left = (clamped * 100).toFixed(2)
3761
+ const right = ((1 - clamped) * 100).toFixed(2)
3762
+ // fr 会先扣除 gap 再按比例分配,避免 50% + gap 溢出。
3763
+ body.style.gridTemplateColumns = `minmax(320px, ${left}fr) minmax(0, ${right}fr)`
3764
+ handle.style.left = left + '%'
3765
+ handle.setAttribute('aria-valuenow', String(Math.round(clamped * 100)))
3766
+ if (persist) writeNumberPref('fang.panel.split', clamped)
3767
+ }
3768
+ applyRatio(S.splitRatio)
3769
+ const onMove = (event) => {
3770
+ const x = event.touches ? event.touches[0]?.clientX : event.clientX
3771
+ if (typeof x !== 'number') return
3772
+ const rect = body.getBoundingClientRect()
3773
+ if (rect.width > 0) applyRatio((x - rect.left) / rect.width)
3774
+ }
3775
+ const stop = () => {
3776
+ body.classList.remove('is-resizing')
3777
+ document.removeEventListener('mousemove', onMove)
3778
+ document.removeEventListener('touchmove', onMove)
3779
+ document.removeEventListener('mouseup', stop)
3780
+ document.removeEventListener('touchend', stop)
3781
+ writeNumberPref('fang.panel.split', S.splitRatio)
3782
+ }
3783
+ const start = (event) => {
3784
+ event.preventDefault()
3785
+ body.classList.add('is-resizing')
3786
+ document.addEventListener('mousemove', onMove)
3787
+ document.addEventListener('touchmove', onMove, { passive: false })
3788
+ document.addEventListener('mouseup', stop, { once: true })
3789
+ document.addEventListener('touchend', stop, { once: true })
3790
+ }
3791
+ handle.addEventListener('mousedown', start)
3792
+ handle.addEventListener('touchstart', start, { passive: false })
3793
+ handle.addEventListener('dblclick', () => applyRatio(0.5, true))
3794
+ handle.addEventListener('keydown', (event) => {
3795
+ if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return
3796
+ event.preventDefault()
3797
+ applyRatio(S.splitRatio + (event.key === 'ArrowLeft' ? -0.02 : 0.02), true)
3798
+ })
3799
+ body.append(handle)
3800
+ frag.append(body)
3722
3801
  frag.append(renderFooter(S, app))
3723
3802
  } else if (S.role.value === 'fork') {
3724
3803
  frag.append(renderHostNotice(S, app))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/dsh-fang",
3
- "version": "3.0.9",
3
+ "version": "3.1.0",
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.",
@@ -33,6 +33,11 @@
33
33
  "dsh": {
34
34
  "bundle": {
35
35
  "patch": "./cordis.patch.yml"
36
+ },
37
+ "client": {
38
+ "platform": "web",
39
+ "immediately": true,
40
+ "inject": []
36
41
  }
37
42
  },
38
43
  "scripts": {
@@ -125,7 +125,7 @@ export const AUDIT = {
125
125
  RUNTIME_ERROR: 'runtime-error',
126
126
  }
127
127
 
128
- export const FANG_VERSION = '3.0.9'
128
+ export const FANG_VERSION = '3.1.0'
129
129
 
130
130
  /**
131
131
  * @typedef {object} ForkInfo
@@ -11,12 +11,24 @@ export const FORK_LOCKED_ENTRY_IDS = Object.freeze([
11
11
  'tool-plugin-manager',
12
12
  ])
13
13
 
14
+ /** DSH first-run notice needs a durable ui-settings-general config form in every fork profile. */
15
+ const WELCOME_NOTICE_ENTRY = Object.freeze({
16
+ id: 'ui-settings-general',
17
+ name: '@deepseek-ai/dsh-client-ui-settings-general',
18
+ config: Object.freeze({ welcomeNoticeVersion: '2026-09-28.1' }),
19
+ })
20
+
14
21
  // cordis.yml 不加只读:DSH 启动时会打开它做规范化写入,只读会导致 EPERM 启动失败。
15
22
  export const PROFILE_CONFIG_FILES = Object.freeze(['package.json', 'cordis.patch.yml'])
16
23
 
17
24
  /** 把分身 profile 的配置文件设为只读(防止误写;不防有意绕过)。 */
18
25
  export function setProfileConfigReadonly(profileDir, readonly = true) {
19
26
  if (String(process.env.DSH_FANG_FORK_PROFILE_RO ?? '1') === '0') return { ok: true, skipped: true, changed: [] }
27
+ // essence-runtime 是元主的配置态实例:DSH 设置/内置插件开关需要原子写 package.json。
28
+ // 只对真正的分身(生产盘)保持只读;否则点「启用」会 EPERM rename package.json.tmp。
29
+ if (readonly && path.basename(String(profileDir)) === 'essence-runtime') {
30
+ return { ok: true, skipped: true, runtime: true, changed: [] }
31
+ }
20
32
  const changed = []
21
33
  for (const name of PROFILE_CONFIG_FILES) {
22
34
  const file = path.join(String(profileDir), name)
@@ -28,11 +40,54 @@ export function setProfileConfigReadonly(profileDir, readonly = true) {
28
40
  return { ok: true, changed }
29
41
  }
30
42
 
43
+ /**
44
+ * Essence-derived profiles serialize their patch as a JSON object `{ insert: [...] }`.
45
+ * Appending YAML lines after that object produces invalid YAML (the v3.0.10 spawn-failed
46
+ * bug). Return the semantic entry array when the file is JSON, so the lock can be merged
47
+ * structurally instead.
48
+ * @param {string} text
49
+ * @returns {Array<Record<string, unknown>> | null}
50
+ */
51
+ function jsonPatchEntries(text) {
52
+ const trimmed = String(text ?? '').trim()
53
+ if (!trimmed.startsWith('{') && !trimmed.startsWith('[')) return null
54
+ let value
55
+ try { value = JSON.parse(trimmed) } catch { return null }
56
+ if (Array.isArray(value)) return value.length === 0 ? null : value
57
+ if (value !== null && typeof value === 'object' && Array.isArray(value.insert)) return [value]
58
+ return null
59
+ }
60
+
61
+ /** Add the lock rows and the onboarding row without duplicating ids. */
62
+ function withLockRows(entries, ids) {
63
+ const out = entries.slice()
64
+ let added = 0
65
+ for (const id of ids) {
66
+ if (!out.some((entry) => entry !== null && typeof entry === 'object' && entry.id === id)) {
67
+ out.push({ id, disabled: true })
68
+ added += 1
69
+ }
70
+ }
71
+ if (!out.some((entry) => entry !== null && typeof entry === 'object' && entry.id === WELCOME_NOTICE_ENTRY.id)) {
72
+ out.push({ ...WELCOME_NOTICE_ENTRY, config: { ...WELCOME_NOTICE_ENTRY.config } })
73
+ }
74
+ return { entries: out, added }
75
+ }
76
+
31
77
  export function applyForkConfigLock(profileDir, options = {}) {
32
78
  if (String(process.env.DSH_FANG_FORK_CONFIG_LOCK ?? '1') === '0') return { ok: true, skipped: true }
33
79
  const file = path.join(String(profileDir), 'cordis.patch.yml')
34
80
  let text = ''
35
81
  try { text = fs.readFileSync(file, 'utf8') } catch { text = '' }
82
+ const ids = options.ids ?? FORK_LOCKED_ENTRY_IDS
83
+ // JSON object/array patches are semantic entry lists; merge them structurally. Appending
84
+ // YAML text after `{ insert: [...] }` would make the whole file unparsable.
85
+ const jsonEntries = jsonPatchEntries(text)
86
+ if (jsonEntries !== null) {
87
+ const merged = withLockRows(jsonEntries, ids)
88
+ fs.writeFileSync(file, `${JSON.stringify(merged.entries, null, 2)}\n`, 'utf8')
89
+ return { ok: true, entries: merged.added }
90
+ }
36
91
  // 模板里的 `[]`(空 YAML 数组)必须去掉,否则追加 `- id:` 会变成非法 YAML。
37
92
  const kept = text
38
93
  .replace(/^\uFEFF/, '')
@@ -40,15 +95,23 @@ export function applyForkConfigLock(profileDir, options = {}) {
40
95
  .filter((line) => !/^\s*\[\s*\]\s*(#.*)?$/.test(line))
41
96
  text = kept.join('\n')
42
97
  const lines = []
43
- for (const id of (options.ids ?? FORK_LOCKED_ENTRY_IDS)) {
98
+ for (const id of ids) {
44
99
  const present = new RegExp(`(^|\\n)\\s*-\\s*id:\\s*${id}\\s*$`, 'm').test(text)
45
100
  if (present) continue
46
101
  lines.push(`- id: ${id}`, ' disabled: true')
47
102
  }
103
+ if (!new RegExp(`(^|\\n)\\s*-\\s*id:\\s*${WELCOME_NOTICE_ENTRY.id}\\s*$`, 'm').test(text)) {
104
+ lines.push(
105
+ `- id: ${WELCOME_NOTICE_ENTRY.id}`,
106
+ ` name: "${WELCOME_NOTICE_ENTRY.name}"`,
107
+ ' config:',
108
+ ` welcomeNoticeVersion: ${WELCOME_NOTICE_ENTRY.config.welcomeNoticeVersion}`,
109
+ )
110
+ }
48
111
  if (lines.length === 0) return { ok: true, entries: 0 }
49
112
  const prefix = text.trim().length === 0 ? '' : (text.endsWith('\n') ? text : text + '\n')
50
113
  const comment = text.includes('# fang: fork is production-only')
51
114
  ? '' : '# fang: fork is production-only (plugin install / settings disabled)\n'
52
115
  fs.writeFileSync(file, `${prefix}${comment}${lines.join('\n')}\n`, 'utf8')
53
- return { ok: true, entries: lines.length / 2 }
116
+ return { ok: true, entries: ids.length }
54
117
  }
@@ -80,6 +80,18 @@ const PORT_PROBE_TIMEOUT_MS = 5000
80
80
  /** Bundle list of the clean fork profile: base + web app + this bundle (Cordis patch). */
81
81
  const CLEAN_TEMPLATE_BUNDLES = ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app']
82
82
 
83
+ // v3.1.0: DSH's first-run preview notice persists ui-settings-general.welcomeNoticeVersion.
84
+ // A clean profile that omits the row leaves the config form unavailable, so 「继续」 always
85
+ // reports "暂时无法保存确认状态". Seed the acknowledgement in every generated clean profile;
86
+ // the fork lock then appends its own disable rows.
87
+ const WELCOME_NOTICE_PATCH = [
88
+ '- id: ui-settings-general',
89
+ ' name: "@deepseek-ai/dsh-client-ui-settings-general"',
90
+ ' config:',
91
+ ' welcomeNoticeVersion: 2026-09-28.1',
92
+ '',
93
+ ].join('\n')
94
+
83
95
  const DEFAULTS = {
84
96
  cliPath: '',
85
97
  profileTemplate: '',
@@ -686,7 +698,7 @@ export function apply(ctx, config) {
686
698
  )
687
699
  files.push('package.json')
688
700
  for (const name of ['cordis.yml', 'cordis.patch.yml']) {
689
- writeFileAtomic(path.join(templateDir, name), '[]\n')
701
+ writeFileAtomic(path.join(templateDir, name), name === 'cordis.patch.yml' ? WELCOME_NOTICE_PATCH : '[]\n')
690
702
  files.push(name)
691
703
  }
692
704
  const srcRaw = String(opts.nodeModulesSource ?? '').trim()
@@ -1823,6 +1823,10 @@ export function apply(ctx, config) {
1823
1823
  const provisioned = await f.provision({
1824
1824
  forkId, taskTitle: `元主运行时 · ${String(meta.name ?? id)}`,
1825
1825
  homeDir, profile: 'essence-runtime', profileTemplate: merged,
1826
+ // 元主运行态必须继承元主的插件/设置;clean template 只用于空白分身,
1827
+ // 否则官方/用户元主打开后看不到本机插件列表(v3.0.10 实测)。
1828
+ cleanTemplate: false,
1829
+ nodeModulesSource: motherModules,
1826
1830
  })
1827
1831
  if (!provisioned.ok) throw new Error(String(provisioned.error ?? 'runtime-provision-failed'))
1828
1832
  // 先导入选中的进行中会话,再拉起实例(实例启动时就能看到它们)。
@@ -2243,7 +2247,7 @@ export function apply(ctx, config) {
2243
2247
  route('POST', `${prefix}/api/tasks/create`, async (req, res) => {
2244
2248
  const body = await readBody(req)
2245
2249
  try {
2246
- const out = await service.createTask({ title: body?.title, template: body?.template, collaborators: body?.collaborators, essenceId: body?.essenceId })
2250
+ const out = await service.createTask({ title: body?.title, template: body?.template, collaborators: body?.collaborators, essenceId: body?.essenceId, importSession: body?.importSession, seed: body?.seed })
2247
2251
  return json(res, out.ok ? 200 : 409, out)
2248
2252
  } catch (error) {
2249
2253
  return json(res, 500, { ok: false, error: String(error?.message ?? error) })