@twinsearth/dsh-fang 3.1.5 → 3.1.7
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 +1 -1
- package/src/kernel/fsx.mjs +72 -0
- package/src/kernel/types.mjs +1 -1
- package/src/lib/fork-config-lock.mjs +11 -5
- package/src/plugins/forker.mjs +145 -24
- package/src/plugins/orchestrator.mjs +9 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twinsearth/dsh-fang",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.7",
|
|
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.",
|
package/src/kernel/fsx.mjs
CHANGED
|
@@ -184,6 +184,78 @@ export function makeJunction(target, linkPath) {
|
|
|
184
184
|
return linkPath
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Replace `dest` with a real directory that mirrors `source`'s top-level entries:
|
|
189
|
+
* directories become junctions to their real targets, plain root files are copied.
|
|
190
|
+
* Package contents are never copied, so the module tree stays shared — but every
|
|
191
|
+
* entry is its own link. That is what DSH's profile-scope resolver needs: an
|
|
192
|
+
* importer below a linked root gets the installation's `@deepseek-ai/*` packages
|
|
193
|
+
* supplied (subject to the peer declaration), while a single whole-node_modules
|
|
194
|
+
* junction leaves the importer outside every known scope. Measured consequence of
|
|
195
|
+
* the whole-tree link: plugins that lazily `import('@deepseek-ai/dsh-tools')` in a
|
|
196
|
+
* fork fall back to their offline shim — w2m's shim stamps `required: false` into a
|
|
197
|
+
* property schema, and the provider rejects every request with
|
|
198
|
+
* `Invalid schema for function 'w2m_report'` (v3.1.7 report).
|
|
199
|
+
* Junction-safe: a reparse point in `dest` is unlinked, never entered; link targets
|
|
200
|
+
* are resolved with realpath first so a link-to-link (pnpm) also lands on a dir.
|
|
201
|
+
* @param {string} source Directory whose entries are mirrored (the module tree).
|
|
202
|
+
* @param {string} dest Directory to replace with the mirror.
|
|
203
|
+
* @returns {{ok:boolean, links:string[], files:string[], error?:string}}
|
|
204
|
+
*/
|
|
205
|
+
export function mirrorModuleTree(source, dest) {
|
|
206
|
+
const src = path.resolve(String(source ?? ''))
|
|
207
|
+
if (!exists(src)) return { ok: false, links: [], files: [], error: 'source-missing' }
|
|
208
|
+
let srcStat
|
|
209
|
+
try { srcStat = fs.lstatSync(src) } catch { return { ok: false, links: [], files: [], error: 'source-unreadable' } }
|
|
210
|
+
if (!srcStat.isDirectory() && !srcStat.isSymbolicLink()) return { ok: false, links: [], files: [], error: 'source-not-directory' }
|
|
211
|
+
removeTree(dest)
|
|
212
|
+
ensureDir(dest)
|
|
213
|
+
const links = []
|
|
214
|
+
const files = []
|
|
215
|
+
let names = []
|
|
216
|
+
try { names = fs.readdirSync(src) } catch { names = [] }
|
|
217
|
+
for (const name of names) {
|
|
218
|
+
const from = path.join(src, name)
|
|
219
|
+
const to = path.join(dest, name)
|
|
220
|
+
let real = from
|
|
221
|
+
try {
|
|
222
|
+
if (fs.lstatSync(from).isSymbolicLink()) real = fs.realpathSync(from)
|
|
223
|
+
} catch { continue }
|
|
224
|
+
let targetStat
|
|
225
|
+
try { targetStat = fs.statSync(real) } catch { continue }
|
|
226
|
+
if (targetStat.isDirectory()) {
|
|
227
|
+
try {
|
|
228
|
+
fs.symlinkSync(path.resolve(real), to, 'junction')
|
|
229
|
+
links.push(name)
|
|
230
|
+
} catch { /* an unmirrorable entry is skipped; the remaining tree still boots */ }
|
|
231
|
+
continue
|
|
232
|
+
}
|
|
233
|
+
try {
|
|
234
|
+
fs.copyFileSync(from, to)
|
|
235
|
+
files.push(name)
|
|
236
|
+
} catch { /* ignore */ }
|
|
237
|
+
}
|
|
238
|
+
return { ok: true, links, files }
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Repair a profile `node_modules` that is still a whole-tree junction (v3.1.6 and
|
|
243
|
+
* older) into the per-entry mirror form. A real directory is left untouched.
|
|
244
|
+
* @param {string} modulesPath The profile's node_modules path.
|
|
245
|
+
* @returns {{ok:boolean, changed:boolean, links?:string[], files?:string[], source?:string, error?:string}}
|
|
246
|
+
*/
|
|
247
|
+
export function ensureModuleMirror(modulesPath) {
|
|
248
|
+
const p = String(modulesPath ?? '')
|
|
249
|
+
if (!p || !exists(p)) return { ok: false, changed: false, error: 'node-modules-missing' }
|
|
250
|
+
let st
|
|
251
|
+
try { st = fs.lstatSync(p) } catch { return { ok: false, changed: false, error: 'node-modules-unreadable' } }
|
|
252
|
+
if (!st.isSymbolicLink()) return { ok: true, changed: false, links: [], files: [] }
|
|
253
|
+
let source
|
|
254
|
+
try { source = fs.realpathSync(p) } catch { return { ok: false, changed: false, error: 'node-modules-target-missing' } }
|
|
255
|
+
const mirrored = mirrorModuleTree(source, p)
|
|
256
|
+
return { ...mirrored, changed: true, source }
|
|
257
|
+
}
|
|
258
|
+
|
|
187
259
|
/**
|
|
188
260
|
* Remove a file or directory tree. Junction-safe: a reparse point is unlinked,
|
|
189
261
|
* its target is never entered. This is the ONLY removal path plugins may use on
|
package/src/kernel/types.mjs
CHANGED
|
@@ -9,9 +9,8 @@ export const FORK_LOCKED_ENTRY_IDS = Object.freeze([
|
|
|
9
9
|
// 禁用 config-editor / ui-settings 会移除 configForms 服务,导致 locale 及之后
|
|
10
10
|
// 50 个客户端插件永久 pending(实测:web boot 50 entries did not activate)。
|
|
11
11
|
'tool-plugin-manager',
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
'ui-plugin-manager',
|
|
12
|
+
// 只隐藏设置页的插件清单;不能禁用 ui-plugin-manager:它提供 pluginNavigation,
|
|
13
|
+
// 禁掉会让 dsh-client-ui-plugin-recommendations 永久 pending(v3.1.5 实测)。
|
|
15
14
|
'ui-settings-plugin-inventory',
|
|
16
15
|
])
|
|
17
16
|
|
|
@@ -25,7 +24,11 @@ const WELCOME_NOTICE_ENTRY = Object.freeze({
|
|
|
25
24
|
// cordis.yml 不加只读:DSH 启动时会打开它做规范化写入,只读会导致 EPERM 启动失败。
|
|
26
25
|
export const PROFILE_CONFIG_FILES = Object.freeze(['package.json', 'cordis.patch.yml'])
|
|
27
26
|
|
|
28
|
-
/**
|
|
27
|
+
/** v3.1.5 曾错误禁用 ui-plugin-manager(它提供 pluginNavigation);升级时自动移除该历史锁。 */
|
|
28
|
+
export const LEGACY_LOCKED_ENTRY_IDS = Object.freeze(['ui-plugin-manager'])
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 把分身 profile 的配置文件设为只读(防止误写;不防有意绕过)。 */
|
|
29
32
|
export function setProfileConfigReadonly(profileDir, readonly = true) {
|
|
30
33
|
if (String(process.env.DSH_FANG_FORK_PROFILE_RO ?? '1') === '0') return { ok: true, skipped: true, changed: [] }
|
|
31
34
|
// essence-runtime 是元主的配置态实例:DSH 设置/内置插件开关需要原子写 package.json。
|
|
@@ -78,7 +81,10 @@ function withLockRows(entries, ids) {
|
|
|
78
81
|
return { entries: out, added }
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
export function applyForkConfigLock(profileDir, options = {}) {
|
|
84
|
+
export function applyForkConfigLock(profileDir, options = {}) {
|
|
85
|
+
if (String(process.env.DSH_FANG_FORK_CONFIG_LOCK ?? '1') === '0') return { ok: true, skipped: true }
|
|
86
|
+
// 自动修复 v3.1.5 遗留的 ui-plugin-manager disabled:true(会断 pluginNavigation)。
|
|
87
|
+
try { clearForkConfigLock(profileDir, { ids: LEGACY_LOCKED_ENTRY_IDS }) } catch { /* best effort */ }
|
|
82
88
|
const file = path.join(String(profileDir), 'cordis.patch.yml')
|
|
83
89
|
let text = ''
|
|
84
90
|
try { text = fs.readFileSync(file, 'utf8') } catch { text = '' }
|
package/src/plugins/forker.mjs
CHANGED
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
// `shell: true`; `.mjs`/`.js` entries are launched through node; `.exe` directly.
|
|
32
32
|
import { spawn as spawnProcess, spawnSync } from 'node:child_process'
|
|
33
33
|
import { randomBytes } from 'node:crypto'
|
|
34
|
+
import fs from 'node:fs'
|
|
35
|
+
import { createRequire } from 'node:module'
|
|
34
36
|
import net from 'node:net'
|
|
35
37
|
import path from 'node:path'
|
|
36
38
|
import {
|
|
@@ -41,10 +43,11 @@ import {
|
|
|
41
43
|
bus,
|
|
42
44
|
copyTree,
|
|
43
45
|
ensureDir,
|
|
46
|
+
ensureModuleMirror,
|
|
44
47
|
exists,
|
|
45
48
|
iso,
|
|
46
49
|
listFiles,
|
|
47
|
-
|
|
50
|
+
mirrorModuleTree,
|
|
48
51
|
newId,
|
|
49
52
|
nowMs,
|
|
50
53
|
parseWebUrl,
|
|
@@ -57,7 +60,7 @@ import {
|
|
|
57
60
|
z,
|
|
58
61
|
} from '../kernel/index.mjs'
|
|
59
62
|
import { computeBackoff, planRestart, reconcileOrphans, writeForkMeta, probeHttpAlive, SUPERVISION_DEFAULTS } from '../lib/fork-supervisor.mjs'
|
|
60
|
-
import { applyForkConfigLock,
|
|
63
|
+
import { applyForkConfigLock, setProfileConfigReadonly } from '../lib/fork-config-lock.mjs'
|
|
61
64
|
|
|
62
65
|
export const name = 'fang-forker'
|
|
63
66
|
export const inject = []
|
|
@@ -176,12 +179,19 @@ export function isShellLauncher(cliPath) {
|
|
|
176
179
|
* Pure: argv appended to the CLI (CONTRACTS.md §5.1).
|
|
177
180
|
* v2: with allocatePorts the forker passes the pre-allocated `--port <n>`; the v1 fallback
|
|
178
181
|
* is still `--port 0` (OS picks a free port).
|
|
182
|
+
* v3.1.7: `patchPaths` are launcher layers (`--patch <path>`) handed to the child before
|
|
183
|
+
* its app args; the headless directory-picker overlay travels this way.
|
|
179
184
|
* @returns {string[]}
|
|
180
185
|
*/
|
|
181
|
-
export function buildSpawnArgs({ profile = 'default', port = 0, noOpen = true } = {}) {
|
|
186
|
+
export function buildSpawnArgs({ profile = 'default', port = 0, noOpen = true, patchPaths = [] } = {}) {
|
|
182
187
|
const n = Math.floor(Number(port))
|
|
183
188
|
const p = Number.isInteger(n) && n >= 0 && n <= 65535 ? n : 0
|
|
184
|
-
const args = ['--profile', safeProfile(profile)
|
|
189
|
+
const args = ['--profile', safeProfile(profile)]
|
|
190
|
+
for (const entry of Array.isArray(patchPaths) ? patchPaths : []) {
|
|
191
|
+
const patchPath = String(entry ?? '').trim()
|
|
192
|
+
if (patchPath) args.push('--patch', patchPath)
|
|
193
|
+
}
|
|
194
|
+
args.push('--port', String(p))
|
|
185
195
|
if (noOpen) args.push('--no-open')
|
|
186
196
|
return args
|
|
187
197
|
}
|
|
@@ -194,11 +204,14 @@ export function buildSpawnArgs({ profile = 'default', port = 0, noOpen = true }
|
|
|
194
204
|
* Never touches the filesystem, so it is safe to unit-test without launching anything.
|
|
195
205
|
* @returns {{command:string, args:string[], shell:boolean, windowsHide:boolean, nodeScript:boolean}}
|
|
196
206
|
*/
|
|
197
|
-
export function buildLaunchSpec({ cliPath = '', profile = 'default', port = 0 } = {}) {
|
|
207
|
+
export function buildLaunchSpec({ cliPath = '', profile = 'default', port = 0, patchPaths = [] } = {}) {
|
|
198
208
|
const entry = String(cliPath ?? '').trim()
|
|
199
|
-
const args = buildSpawnArgs({ profile, port })
|
|
209
|
+
const args = buildSpawnArgs({ profile, port, patchPaths })
|
|
200
210
|
if (isShellLauncher(entry)) {
|
|
201
|
-
|
|
211
|
+
// `shell: true` concatenates argv without escaping (DEP0190); a profile home or overlay
|
|
212
|
+
// path containing whitespace would otherwise split into two child arguments.
|
|
213
|
+
const quoted = args.map((arg) => (/[\s"]/u.test(arg) ? `"${String(arg).replace(/"/g, '\\"')}"` : arg))
|
|
214
|
+
return { command: entry, args: quoted, shell: true, windowsHide: true, nodeScript: false }
|
|
202
215
|
}
|
|
203
216
|
if (/\.(mjs|cjs|js)$/i.test(entry)) {
|
|
204
217
|
return { command: process.execPath, args: [entry, ...args], shell: false, windowsHide: true, nodeScript: true }
|
|
@@ -233,6 +246,91 @@ export function buildForkChildEnv(base = process.env, overrides = {}) {
|
|
|
233
246
|
return env
|
|
234
247
|
}
|
|
235
248
|
|
|
249
|
+
/**
|
|
250
|
+
* The launch overlay that pins the directory picker to the browser dialog in every
|
|
251
|
+
* fork/ESSENCE-RUNTIME web host.
|
|
252
|
+
*
|
|
253
|
+
* `dsh-host-directory-picker-auto` resolves `native` on win32/darwin whenever the
|
|
254
|
+
* bind is loopback and the launch is not SSH — it has no way to know the host was
|
|
255
|
+
* started headless through `dsh.cmd` (ELECTRON_RUN_AS_NODE, no Electron shell), so
|
|
256
|
+
* the native chooser has no window to open and "选择工作区" fails in the fork Web UI
|
|
257
|
+
* (v3.1.7 report). The documented composition switch is an overlay that disables
|
|
258
|
+
* the auto row and mounts the browse backend + its client surface directly; both
|
|
259
|
+
* package names exist as installation dependencies of the same DSH release.
|
|
260
|
+
*/
|
|
261
|
+
export const HEADLESS_PICKER_OVERLAY = [
|
|
262
|
+
'# dsh-Fang v3.1.7: headless web host (dsh.cmd --no-open) has no native chooser window.',
|
|
263
|
+
'# Pin the directory-picker interaction to the browser dialog.',
|
|
264
|
+
'- id: directory-picker',
|
|
265
|
+
' disabled: true',
|
|
266
|
+
'- insert:',
|
|
267
|
+
' - id: directory-picker-browse',
|
|
268
|
+
" name: '@deepseek-ai/dsh-host-directory-picker-browse'",
|
|
269
|
+
' - id: ui-directory-picker-browse',
|
|
270
|
+
" name: '@deepseek-ai/dsh-client-ui-directory-picker-browse'",
|
|
271
|
+
'',
|
|
272
|
+
].join('\n')
|
|
273
|
+
|
|
274
|
+
/** File name of the headless launch overlay inside the fork/essence-runtime profile. */
|
|
275
|
+
export const HEADLESS_PICKER_OVERLAY_FILE = 'fang-headless.patch.yml'
|
|
276
|
+
|
|
277
|
+
/** Whether this DSH installation carries the browse-picker pair the overlay mounts. */
|
|
278
|
+
export function headlessPickerSupported({ cliPath = '' } = {}) {
|
|
279
|
+
const names = [
|
|
280
|
+
'@deepseek-ai/dsh-host-directory-picker-browse',
|
|
281
|
+
'@deepseek-ai/dsh-client-ui-directory-picker-browse',
|
|
282
|
+
]
|
|
283
|
+
let require = null
|
|
284
|
+
try { require = createRequire(import.meta.url) } catch { require = null }
|
|
285
|
+
const anchors = []
|
|
286
|
+
// Desktop install: <root>/resources/app.asar/dsh/node_modules (asar-aware fs in the host).
|
|
287
|
+
try { anchors.push(path.join(path.dirname(process.execPath), 'resources', 'app.asar', 'dsh', 'node_modules')) } catch { /* ignore */ }
|
|
288
|
+
// Launcher-derived install root: .../resources/runtime/cli/bin/dsh.cmd → .../resources/app.asar/dsh/node_modules
|
|
289
|
+
const cli = String(cliPath ?? '').trim()
|
|
290
|
+
if (cli) {
|
|
291
|
+
const resources = path.resolve(path.dirname(cli), '..', '..', '..', '..', 'resources')
|
|
292
|
+
anchors.push(path.join(resources, 'app.asar', 'dsh', 'node_modules'))
|
|
293
|
+
}
|
|
294
|
+
for (const name of names) {
|
|
295
|
+
let found = false
|
|
296
|
+
if (require) {
|
|
297
|
+
try { require.resolve(name); found = true } catch { /* not resolvable here */ }
|
|
298
|
+
}
|
|
299
|
+
if (!found) {
|
|
300
|
+
for (const anchor of anchors) {
|
|
301
|
+
try {
|
|
302
|
+
if (fs.existsSync(path.join(anchor, ...name.split('/'), 'package.json'))) { found = true; break }
|
|
303
|
+
} catch { /* ignore */ }
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (!found) return false
|
|
307
|
+
}
|
|
308
|
+
return true
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Write (or refresh) the headless-picker launch overlay in `profileDir`.
|
|
313
|
+
* `DSH_FANG_HEADLESS_PICKER_PATCH=0` opts out; an installation without the browse
|
|
314
|
+
* pair keeps the DSH default (native) so an unknown-version host is not patched blind.
|
|
315
|
+
* @param {string} profileDir The fork/essence-runtime profile directory.
|
|
316
|
+
* @param {{cliPath?: string, supported?: boolean}} [options] The launcher the fork will
|
|
317
|
+
* be started with; `supported` overrides the installation probe (tests).
|
|
318
|
+
* @returns {string|null} The overlay path to pass as `--patch`, or null.
|
|
319
|
+
*/
|
|
320
|
+
export function writeHeadlessPickerOverlay(profileDir, { cliPath = '', supported } = {}) {
|
|
321
|
+
if (String(process.env.DSH_FANG_HEADLESS_PICKER_PATCH ?? '1') === '0') return null
|
|
322
|
+
if (!profileDir || !exists(profileDir)) return null
|
|
323
|
+
const available = typeof supported === 'boolean' ? supported : headlessPickerSupported({ cliPath })
|
|
324
|
+
if (!available) return null
|
|
325
|
+
const file = path.join(profileDir, HEADLESS_PICKER_OVERLAY_FILE)
|
|
326
|
+
try {
|
|
327
|
+
writeFileAtomic(file, HEADLESS_PICKER_OVERLAY)
|
|
328
|
+
return file
|
|
329
|
+
} catch {
|
|
330
|
+
return null
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
236
334
|
/**
|
|
237
335
|
* Pure: why did a fork exit? (CONTRACTS.md §5.1)
|
|
238
336
|
* 0 = normal, 75 = the guard allowed a restart (supervisor contract), else crash.
|
|
@@ -708,10 +806,12 @@ export function apply(ctx, config) {
|
|
|
708
806
|
const link = path.join(templateDir, 'node_modules')
|
|
709
807
|
if (source && exists(source)) {
|
|
710
808
|
try {
|
|
711
|
-
|
|
712
|
-
|
|
809
|
+
// v3.1.7: per-entry mirror instead of one whole-tree junction — see fsx.mirrorModuleTree.
|
|
810
|
+
const mirrored = mirrorModuleTree(source, link)
|
|
811
|
+
if (mirrored.ok !== true) warnings.push(`node-modules-mirror-failed: ${mirrored.error ?? 'unknown'}`)
|
|
812
|
+
else files.push('node_modules')
|
|
713
813
|
} catch (e) {
|
|
714
|
-
warnings.push(`node-modules-
|
|
814
|
+
warnings.push(`node-modules-mirror-failed: ${msgOf(e)}`)
|
|
715
815
|
}
|
|
716
816
|
} else {
|
|
717
817
|
warnings.push('node-modules-source-missing')
|
|
@@ -795,13 +895,21 @@ export function apply(ctx, config) {
|
|
|
795
895
|
// 配置文件只读:防误写(DSH_FANG_FORK_PROFILE_RO=0 可关)。
|
|
796
896
|
const profileReadonly = setProfileConfigReadonly(profileDir, true)
|
|
797
897
|
|
|
798
|
-
// node_modules
|
|
898
|
+
// node_modules mirror in the fork profile (always to the mother's module tree).
|
|
899
|
+
// v3.1.7: one junction per top-level entry instead of a whole-tree junction. DSH's
|
|
900
|
+
// profile-scope resolver only supplies installation packages (`@deepseek-ai/*`) to an
|
|
901
|
+
// importer inside the profile tree or below a linked root; a whole-tree junction keeps
|
|
902
|
+
// the importer outside every scope, so lazy host imports fall back to plugin shims
|
|
903
|
+
// (w2m's shim emits `required: false` in a property schema → the provider rejects
|
|
904
|
+
// every request: "Invalid schema for function 'w2m_report'", v3.1.7 report).
|
|
799
905
|
let nodeModules = null
|
|
800
906
|
if (exists(nodeModulesSource)) {
|
|
801
907
|
try {
|
|
802
|
-
|
|
908
|
+
const mirrored = mirrorModuleTree(nodeModulesSource, path.join(profileDir, 'node_modules'))
|
|
909
|
+
if (mirrored.ok === true) nodeModules = nodeModulesSource
|
|
910
|
+
else warnings.push(`node-modules-mirror-failed: ${mirrored.error ?? 'unknown'}`)
|
|
803
911
|
} catch (e) {
|
|
804
|
-
warnings.push(`node-modules-
|
|
912
|
+
warnings.push(`node-modules-mirror-failed: ${msgOf(e)}`)
|
|
805
913
|
}
|
|
806
914
|
} else if (!cleanTemplate) {
|
|
807
915
|
// Degraded but still usable: the fork simply has no node_modules link to the mother.
|
|
@@ -926,16 +1034,23 @@ export function apply(ctx, config) {
|
|
|
926
1034
|
rec.configSync = { at: nowMs(), ok: false, error: msgOf(e) }
|
|
927
1035
|
}
|
|
928
1036
|
}
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
1037
|
+
try { rec.configLock = applyForkConfigLock(rec.profileDir) } catch { rec.configLock = { ok: false } }
|
|
1038
|
+
try { rec.profileReadonly = setProfileConfigReadonly(rec.profileDir, true) } catch { rec.profileReadonly = { ok: false } }
|
|
1039
|
+
// v3.1.7: repair a whole-tree `node_modules` junction left by any previous release into
|
|
1040
|
+
// the per-entry mirror. This is what makes the fork host resolve the installation's
|
|
1041
|
+
// `@deepseek-ai/*` packages for profile plugins again; without it every agent request in
|
|
1042
|
+
// the fork is rejected by the provider (w2m offline shim → invalid tool schema).
|
|
1043
|
+
try {
|
|
1044
|
+
const repaired = ensureModuleMirror(path.join(rec.profileDir, 'node_modules'))
|
|
1045
|
+
rec.nodeModulesMirror = {
|
|
1046
|
+
changed: repaired.changed === true,
|
|
1047
|
+
ok: repaired.ok !== false,
|
|
1048
|
+
source: repaired.source ?? null,
|
|
1049
|
+
links: Array.isArray(repaired.links) ? repaired.links.length : 0,
|
|
1050
|
+
error: repaired.error ?? null,
|
|
1051
|
+
}
|
|
1052
|
+
} catch (e) {
|
|
1053
|
+
rec.nodeModulesMirror = { ok: false, changed: false, error: msgOf(e) }
|
|
939
1054
|
}
|
|
940
1055
|
writeForkMetaOf(rec)
|
|
941
1056
|
// 广播新 token:首次派生 = 生成,重启 = 刷新;订阅者拿到的是「当前 token」,
|
|
@@ -1007,7 +1122,13 @@ export function apply(ctx, config) {
|
|
|
1007
1122
|
}
|
|
1008
1123
|
pendingSpawns.add(cleanup)
|
|
1009
1124
|
|
|
1010
|
-
|
|
1125
|
+
// v3.1.7: the headless web host (`dsh.cmd --no-open`, ELECTRON_RUN_AS_NODE) has no
|
|
1126
|
+
// window for the native directory chooser; pin the browse interaction through a
|
|
1127
|
+
// launcher overlay so "select workspace" works inside every fork Web UI.
|
|
1128
|
+
const patchPaths = []
|
|
1129
|
+
const headlessOverlay = writeHeadlessPickerOverlay(rec.profileDir, { cliPath })
|
|
1130
|
+
if (headlessOverlay) patchPaths.push(headlessOverlay)
|
|
1131
|
+
const spec = buildLaunchSpec({ cliPath, profile, port: expectedPort, patchPaths })
|
|
1011
1132
|
const env = buildForkChildEnv(process.env, {
|
|
1012
1133
|
DSH_HOME: homeDir,
|
|
1013
1134
|
// Fork identity is injected by the forker (a fork must never be able to call itself mother).
|
|
@@ -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, ensureModuleMirror, readJson, writeJsonAtomic, writeFileAtomic, sha256, removeTree, copyTree, digestTree,
|
|
18
18
|
newId, iso, nowMs, bus, sleep, parseWebUrl, probeWebUrl,
|
|
19
19
|
invokeCommercial, commercialConfigSchemaDefaults,
|
|
20
20
|
} from '../kernel/index.mjs'
|
|
@@ -2209,16 +2209,14 @@ export function apply(ctx, config) {
|
|
|
2209
2209
|
if (!provisioned.ok) throw new Error(String(provisioned.error ?? 'runtime-provision-failed'))
|
|
2210
2210
|
// 历史版本把生产盘锁写进了 essence-runtime;配置实例必须能管理插件,升级后清掉。
|
|
2211
2211
|
try { clearForkConfigLock(runtimeProfileDir) } catch { /* best effort */ }
|
|
2212
|
-
//
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
throw new Error(`runtime-node-modules-junction-failed: ${String(error?.message ?? error)}`)
|
|
2221
|
-
}
|
|
2212
|
+
// v3.1.7:运行态 profile 的 node_modules 必须是 per-entry mirror(不是整树 junction)。
|
|
2213
|
+
// 整树 junction 会让插件 importer 落在 DSH profile 作用域之外,运行态内 w2m 等插件
|
|
2214
|
+
// 无法解析 @deepseek-ai/*,退回离线 shim,工具 schema 非法 → 模型请求被供应商拒绝。
|
|
2215
|
+
try {
|
|
2216
|
+
const repaired = ensureModuleMirror(runtimeModules)
|
|
2217
|
+
if (repaired.ok === false) throw new Error(repaired.error ?? 'unknown')
|
|
2218
|
+
} catch (error) {
|
|
2219
|
+
throw new Error(`runtime-node-modules-mirror-failed: ${String(error?.message ?? error)}`)
|
|
2222
2220
|
}
|
|
2223
2221
|
writeModuleStoreConfig(runtimeProfileDir)
|
|
2224
2222
|
// 先导入选中的进行中会话,再拉起实例(实例启动时就能看到它们)。
|