@twinsearth/dsh-fang 3.1.29 → 3.1.30

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/client.js CHANGED
@@ -2034,6 +2034,8 @@ window.__ModuleLoader__.load({
2034
2034
  await refresh()
2035
2035
  }
2036
2036
 
2037
+ // v3.1.30:DEPRECATED —— 打开元主已改为无对话直接启动(见 openEssence)。
2038
+ // 保留此函数只为兼容未来可能的多会话入口;元主与派生都不再调用它。
2037
2039
  // 打开前选会话:多选 1–5 个进行中会话(归档会话不出现)。
2038
2040
  function showSessionPicker(sessions, onPick) {
2039
2041
  const doc = document
@@ -2174,7 +2176,9 @@ window.__ModuleLoader__.load({
2174
2176
  await refresh()
2175
2177
  }
2176
2178
 
2177
- // 打开&设置:已在跑 → 直接开带 token 的 URL;没跑 → 选会话后启动再打开。
2179
+ // 打开&设置:已在跑 → 直接开带 token 的 URL;没跑 → **无对话直接启动**再打开。
2180
+ // v3.1.30:元主 Web 本身不允许会话(会话按钮与工作区已隐藏),
2181
+ // 因此打开元主时不再要求/提示导入进行中会话——「导入一个会话」只属于派生分身。
2178
2182
  async function openEssence(essenceId) {
2179
2183
  if (isBusy()) return
2180
2184
  S.busy = 'essence:open:' + essenceId
@@ -2188,9 +2192,8 @@ window.__ModuleLoader__.load({
2188
2192
  else setNotice({ tone: 'bad', title: '无法打开元主 Web', message: '实例在跑但拿不到带 token 的地址' })
2189
2193
  return
2190
2194
  }
2191
- const candidates = await api('/fang/api/essence/open/candidates')
2192
- const sessions = Array.isArray(candidates.body?.sessions) ? candidates.body.sessions : []
2193
- showSessionPicker(sessions, (sessionIds) => void startEssenceRuntime(essenceId, sessionIds))
2195
+ // 直接启动:不导入任何会话(元主是「插件控制台」,不是对话工作区)。
2196
+ void startEssenceRuntime(essenceId, [])
2194
2197
  }
2195
2198
 
2196
2199
  async function copyEssence(essence) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/dsh-fang",
3
- "version": "3.1.29",
3
+ "version": "3.1.30",
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.",
@@ -129,7 +129,7 @@ export const AUDIT = {
129
129
  RUNTIME_ERROR: 'runtime-error',
130
130
  }
131
131
 
132
- export const FANG_VERSION = '3.1.29'
132
+ export const FANG_VERSION = '3.1.30'
133
133
 
134
134
  /**
135
135
  * @typedef {object} ForkInfo
@@ -21,9 +21,19 @@ const WELCOME_NOTICE_ENTRY = Object.freeze({
21
21
  config: Object.freeze({ welcomeNoticeVersion: '2026-09-28.1' }),
22
22
  })
23
23
 
24
- // cordis.yml 不加只读:DSH 启动时会打开它做规范化写入,只读会导致 EPERM 启动失败。
24
+ // v3.1.30:DSH 0.2.2 每次启动都会重写 profile 的 package.json
25
+ // (dsh-app-boot dropRetiredBundles → writeProfileManifest),cordis.patch.yml 也会被
26
+ // 规范化写回。把这两个文件设成只读会让子进程在引导阶段直接
27
+ // EPERM: operation not permitted, open '...\profiles\<profile>\package.json'
28
+ // 然后立即退出——上层看到的就是 spawn-failed(派生与还原都失败,v3.1.28 实测)。
29
+ //
30
+ // 因此 readonly=true 不再 chmod 任何 DSH 启动必须写的文件;readonly=false 仍会 chmod 0644,
31
+ // 用于自动修复历史上被设成只读的分身 profile。行为锁由 applyForkConfigLock 承担。
25
32
  export const PROFILE_CONFIG_FILES = Object.freeze(['package.json', 'cordis.patch.yml'])
26
33
 
34
+ /** 真正会被 chmod 成只读的文件:v3.1.30 起为空(见上面的根因说明)。 */
35
+ export const READONLY_LOCKED_FILES = Object.freeze([])
36
+
27
37
  /** v3.1.5 曾错误禁用 ui-plugin-manager(它提供 pluginNavigation);升级时自动移除该历史锁。 */
28
38
  export const LEGACY_LOCKED_ENTRY_IDS = Object.freeze(['ui-plugin-manager'])
29
39
 
@@ -31,20 +41,23 @@ export const LEGACY_LOCKED_ENTRY_IDS = Object.freeze(['ui-plugin-manager'])
31
41
  * 把分身 profile 的配置文件设为只读(防止误写;不防有意绕过)。 */
32
42
  export function setProfileConfigReadonly(profileDir, readonly = true) {
33
43
  if (String(process.env.DSH_FANG_FORK_PROFILE_RO ?? '1') === '0') return { ok: true, skipped: true, changed: [] }
34
- // essence-runtime 是元主的配置态实例:DSH 设置/内置插件开关需要原子写 package.json。
35
- // 只对真正的分身(生产盘)保持只读;否则点「启用」会 EPERM rename package.json.tmp。
36
- if (readonly && path.basename(String(profileDir)) === 'essence-runtime') {
37
- return { ok: true, skipped: true, runtime: true, changed: [] }
38
- }
39
44
  const changed = []
45
+ const repaired = []
40
46
  for (const name of PROFILE_CONFIG_FILES) {
41
47
  const file = path.join(String(profileDir), name)
48
+ // readonly=true:只记录、不 chmod(DSH 启动必须能写这两个文件,v3.1.30 根因修复)。
49
+ // readonly=false:解锁——顺带修掉历史版本留下的 0444,让旧分身恢复可用。
50
+ if (readonly) continue
42
51
  try {
43
- fs.chmodSync(file, readonly ? 0o444 : 0o644)
52
+ if (!fs.existsSync(file)) continue
53
+ const stat = fs.statSync(file)
54
+ const wasReadonly = (stat.mode & 0o222) === 0
55
+ fs.chmodSync(file, 0o644)
44
56
  changed.push(name)
45
- } catch { /* 文件不存在/平台不支持则跳过 */ }
57
+ if (wasReadonly) repaired.push(name)
58
+ } catch { /* 平台不支持/文件被占用则跳过 */ }
46
59
  }
47
- return { ok: true, changed }
60
+ return { ok: true, changed, repaired, enforced: false, files: PROFILE_CONFIG_FILES }
48
61
  }
49
62
 
50
63
  /**
@@ -1221,10 +1221,23 @@ export function apply(ctx, config) {
1221
1221
  * 只读会话目录(session catalog)缺失时退化为 lineage-only,不阻塞派生。
1222
1222
  */
1223
1223
  async derive(input = {}) {
1224
- const sessionId = String(input.sessionId ?? '').trim()
1224
+ // v3.1.30:派生分身必须导入「一个」进行中会话。
1225
+ // · 不传 sessionId → 明确拒绝(不再静默退化成空白分身)
1226
+ // · 传了多个 sessionIds → 拒绝(一次只能导入一个,避免来源混淆)
1227
+ // 元主 Web 自身启动不经过这里,因此「元主无对话启动」不受影响。
1228
+ const rawMulti = Array.isArray(input.sessionIds)
1229
+ ? input.sessionIds.map((id) => String(id ?? '').trim()).filter(Boolean)
1230
+ : []
1231
+ if (rawMulti.length > 1) {
1232
+ return { ok: false, error: 'session-multi-not-allowed', detail: '一次只能导入一个会话(收到 ' + rawMulti.length + ' 个)' }
1233
+ }
1234
+ const sessionId = (rawMulti[0] ?? String(input.sessionId ?? '')).trim()
1235
+ if (!sessionId) {
1236
+ return { ok: false, error: 'session-required', detail: '派生分身需要先选择一个进行中的会话(一次只能导入一个)' }
1237
+ }
1225
1238
  let seed = null
1226
1239
  let importSession = null
1227
- if (sessionId) {
1240
+ {
1228
1241
  const catalog = safeGet(SERVICE.sessionCatalog)
1229
1242
  if (!catalog || typeof catalog.seed !== 'function') {
1230
1243
  return { ok: false, error: 'session-catalog-unavailable' }
@@ -3204,7 +3217,13 @@ export function apply(ctx, config) {
3204
3217
 
3205
3218
  route('POST', `${prefix}/api/derive`, async (req, res) => {
3206
3219
  const body = await readBody(req)
3207
- const out = await service.derive({ title: body?.title, sessionId: body?.sessionId, collaborators: body?.collaborators })
3220
+ // v3.1.30:透传 sessionIds,让「一次只能导入一个会话」的校验在 API 层生效。
3221
+ const out = await service.derive({
3222
+ title: body?.title,
3223
+ sessionId: body?.sessionId,
3224
+ sessionIds: body?.sessionIds,
3225
+ collaborators: body?.collaborators,
3226
+ })
3208
3227
  return json(res, out.ok ? 200 : 409, out)
3209
3228
  })
3210
3229
  route('GET', `${prefix}/api/tasks/sessions`, async (req, res) => {