@twinsearth/dsh-fang 3.0.10 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/dsh-fang",
3
- "version": "3.0.10",
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.",
@@ -125,7 +125,7 @@ export const AUDIT = {
125
125
  RUNTIME_ERROR: 'runtime-error',
126
126
  }
127
127
 
128
- export const FANG_VERSION = '3.0.10'
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) })