@twinsearth/dsh-fang 3.1.2 → 3.1.3

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.1.2",
3
+ "version": "3.1.3",
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.",
@@ -49,7 +49,7 @@
49
49
  "node": ">=22"
50
50
  },
51
51
  "optionalDependencies": {
52
- "@twinsearth/dsh-fang-queue-journal": "0.1.2",
52
+ "@twinsearth/dsh-fang-queue-journal": "0.1.3",
53
53
  "@twinsearth/dsh-fang-web-entry": "0.1.1"
54
54
  },
55
55
  "devDependencies": {
@@ -128,7 +128,7 @@ export const AUDIT = {
128
128
  RUNTIME_ERROR: 'runtime-error',
129
129
  }
130
130
 
131
- export const FANG_VERSION = '3.1.2'
131
+ export const FANG_VERSION = '3.1.3'
132
132
 
133
133
  /**
134
134
  * @typedef {object} ForkInfo
@@ -14,7 +14,7 @@ import path from 'node:path'
14
14
  import {
15
15
  z, roleGate, resolveFangLayout, resolveProfileDir, resolveSessionsLayout,
16
16
  SERVICE, AUDIT, TASK_STATUS, FORK_STATUS, FANG_VERSION, ADAPTER_OP,
17
- exists, ensureDir, readJson, writeJsonAtomic, writeFileAtomic, sha256, removeTree, copyTree, digestTree,
17
+ exists, ensureDir, readJson, writeJsonAtomic, writeFileAtomic, sha256, removeTree, copyTree, digestTree, makeJunction,
18
18
  newId, iso, nowMs, bus, sleep, parseWebUrl, probeWebUrl,
19
19
  invokeCommercial, commercialConfigSchemaDefaults,
20
20
  } from '../kernel/index.mjs'
@@ -82,6 +82,17 @@ export function atomicReplaceDir(sourceDir, targetDir) {
82
82
  }
83
83
 
84
84
 
85
+ const FORK_BUNDLE_NAMES = Object.freeze(['@twinsearth/dsh-fang', '@twinsearth/dsh-fang'])
86
+
87
+ /** 分身 profile 可解析的 fang bundle 路径(npm 安装名/开发 link 名都接受)。 */
88
+ function forkBundlePath(profileDir) {
89
+ for (const name of FORK_BUNDLE_NAMES) {
90
+ const candidate = path.join(String(profileDir ?? ''), 'node_modules', ...name.split('/'))
91
+ if (exists(candidate)) return candidate
92
+ }
93
+ return null
94
+ }
95
+
85
96
  export const name = 'fang-orchestrator'
86
97
  export const inject = []
87
98
 
@@ -754,9 +765,10 @@ export function apply(ctx, config) {
754
765
 
755
766
  // 防御:分身的 profile 必须能解析本 bundle;否则派生出来的是一个"没有 /fang 路由"的
756
767
  // 僵尸分身(adapter 握手会得到 http-404)。发现即回收并如实报错。
768
+ // npm 安装名是 @twinsearth/dsh-fang;开发 link 才是 @twinsearth/dsh-fang。两者都算可用。
757
769
  const forkProfileDir = path.join(homeDir, 'profiles', profile)
758
- const forkBundle = path.join(forkProfileDir, 'node_modules', '@local', 'dsh-fang')
759
- if (!exists(forkBundle)) {
770
+ const forkBundle = forkBundlePath(forkProfileDir)
771
+ if (!forkBundle) {
760
772
  task.status = TASK_STATUS.FAILED
761
773
  tasks.delete(taskId)
762
774
  persist()
@@ -1414,8 +1426,8 @@ export function apply(ctx, config) {
1414
1426
  return { ok: false, error: 'path-escape', taskId: id, detail: String(error?.message ?? error) }
1415
1427
  }
1416
1428
  const forkProfileDir = path.join(task.homeDir, 'profiles', task.profile)
1417
- const forkBundle = path.join(forkProfileDir, 'node_modules', '@local', 'dsh-fang')
1418
- if (!exists(forkBundle)) {
1429
+ const forkBundle = forkBundlePath(forkProfileDir)
1430
+ if (!forkBundle) {
1419
1431
  return { ok: false, error: 'fork-bundle-unavailable', taskId: id, detail: forkProfileDir }
1420
1432
  }
1421
1433
  const f = forker()
@@ -1494,8 +1506,8 @@ export function apply(ctx, config) {
1494
1506
  report.failed.push({ taskId: id, error: 'path-escape' })
1495
1507
  continue
1496
1508
  }
1497
- const forkBundle = path.join(task.homeDir, 'profiles', task.profile, 'node_modules', '@local', 'dsh-fang')
1498
- if (!exists(forkBundle)) {
1509
+ const forkBundle = forkBundlePath(path.join(task.homeDir, 'profiles', task.profile))
1510
+ if (!forkBundle) {
1499
1511
  report.failed.push({ taskId: id, error: 'fork-bundle-unavailable' })
1500
1512
  continue
1501
1513
  }
@@ -2158,9 +2170,12 @@ export function apply(ctx, config) {
2158
2170
  // makeJunction 对已存在的链接不会替换,所以先安全移除旧 junction(不进入目标)。
2159
2171
  const runtimeProfileDir = path.join(homeDir, 'profiles', 'essence-runtime')
2160
2172
  const runtimeModules = path.join(runtimeProfileDir, 'node_modules')
2161
- if (exists(runtimeModules)) {
2162
- try { if (fs.lstatSync(runtimeModules).isSymbolicLink()) removeTree(runtimeModules) } catch { /* ignore */ }
2163
- }
2173
+ // 迁移/旧版本可能留下“指向不存在 merged/profile/node_modules”的 junction;
2174
+ // fs.existsSync 对 broken junction 返回 false,必须用 lstat 才能发现并清掉。
2175
+ try {
2176
+ const stat = fs.lstatSync(runtimeModules)
2177
+ if (stat.isSymbolicLink() || !exists(runtimeModules)) removeTree(runtimeModules)
2178
+ } catch { /* 不存在 */ }
2164
2179
  const legacyHomes = [
2165
2180
  path.join(layout.dataDir, 'runtime', forkId, 'home'),
2166
2181
  path.join(essenceManager.essenceRoot(id), 'runtime', 'home'),
@@ -2180,6 +2195,17 @@ export function apply(ctx, config) {
2180
2195
  nodeModulesSource: essenceModules,
2181
2196
  })
2182
2197
  if (!provisioned.ok) throw new Error(String(provisioned.error ?? 'runtime-provision-failed'))
2198
+ // provision 若看到旧 junction 可能不替换;这里以 essenceModules 为准做最后自愈。
2199
+ if (!exists(runtimeModules)) {
2200
+ try {
2201
+ const stat = fs.lstatSync(runtimeModules)
2202
+ if (stat.isSymbolicLink()) removeTree(runtimeModules)
2203
+ } catch { /* ignore */ }
2204
+ if (!exists(essenceModules)) throw new Error('runtime-node-modules-source-missing')
2205
+ try { makeJunction(essenceModules, runtimeModules) } catch (error) {
2206
+ throw new Error(`runtime-node-modules-junction-failed: ${String(error?.message ?? error)}`)
2207
+ }
2208
+ }
2183
2209
  writeModuleStoreConfig(runtimeProfileDir)
2184
2210
  // 先导入选中的进行中会话,再拉起实例(实例启动时就能看到它们)。
2185
2211
  const importedSessions = importSessionsInto(homeDir, input?.sessionIds)