@twinsearth/dsh-fang 3.3.2 → 3.7.6

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.
Files changed (57) hide show
  1. package/README.md +3 -3
  2. package/client.js +600 -60
  3. package/cordis.patch.yml +26 -20
  4. package/docs/APPROVAL-DRILL.md +42 -0
  5. package/docs/AUTO-WATCHDOG.md +46 -0
  6. package/docs/DECISION-LOSSLESS.md +36 -0
  7. package/docs/ESSENCE-AUTO-SYNC.md +32 -0
  8. package/docs/INBOX-SCROLL.md +33 -0
  9. package/docs/PACKAGE-RENAME-v3.3.3.md +40 -0
  10. package/docs/RESTART-CONFIRMATION.md +29 -0
  11. package/docs/TEST-STABILITY-v3.4.0.md +30 -0
  12. package/package.json +9 -5
  13. package/src/compose.mjs +4 -1
  14. package/src/contract/VENDOR.json +6 -5
  15. package/src/contract/constants.js +16 -1
  16. package/src/contract/relay.js +12 -6
  17. package/src/kernel/types.mjs +3 -1
  18. package/src/lib/accelerated-fork.mjs +813 -0
  19. package/src/lib/accelerated-install.mjs +295 -0
  20. package/src/lib/accelerated-web.mjs +103 -0
  21. package/src/lib/approval-drill.mjs +111 -0
  22. package/src/lib/boot-guard.mjs +6 -2
  23. package/src/lib/chat-import-delegation.mjs +47 -0
  24. package/src/lib/compat.mjs +5 -1
  25. package/src/lib/contract-delegation.mjs +161 -0
  26. package/src/lib/default-essence.mjs +7 -4
  27. package/src/lib/essence.mjs +113 -7
  28. package/src/lib/fork-config-lock.mjs +2 -2
  29. package/src/lib/fork-core-settings.mjs +95 -0
  30. package/src/lib/fork-export.mjs +85 -0
  31. package/src/lib/global-redline.mjs +164 -0
  32. package/src/lib/http-auth.mjs +36 -0
  33. package/src/lib/install-snapshot.mjs +77 -0
  34. package/src/lib/lsp-delegation.mjs +70 -0
  35. package/src/lib/lsp-provider.mjs +250 -0
  36. package/src/lib/main-gate.mjs +33 -28
  37. package/src/lib/mirror.mjs +115 -4
  38. package/src/lib/node-compat.mjs +24 -0
  39. package/src/lib/pro-delegation.mjs +185 -0
  40. package/src/lib/runtime-capture.mjs +11 -3
  41. package/src/lib/watch-guard.mjs +51 -0
  42. package/src/plugins/approver.mjs +5 -2
  43. package/src/plugins/auditor.mjs +125 -18
  44. package/src/plugins/decision-center.mjs +77 -34
  45. package/src/plugins/forker.mjs +258 -33
  46. package/src/plugins/orchestrator.mjs +1508 -65
  47. package/src/plugins/restart-guard.mjs +79 -2
  48. package/src/plugins/session-catalog.mjs +127 -40
  49. package/tools/approval-drill.mjs +21 -0
  50. package/tools/fangctl.mjs +21 -4
  51. package/tools/gate/main-city.mjs +1 -1
  52. package/tools/restart-supervisor.mjs +425 -0
  53. package/tools/restart-watchdog.mjs +568 -0
  54. package/vault/client.js +49 -0
  55. package/vault/cordis.patch.yml +3 -0
  56. package/vault/lib/vault.mjs +219 -0
  57. package/vault/package.json +29 -0
@@ -32,6 +32,7 @@
32
32
  import { spawn as spawnProcess, spawnSync } from 'node:child_process'
33
33
  import { randomBytes } from 'node:crypto'
34
34
  import fs from 'node:fs'
35
+ import { fileURLToPath } from 'node:url'
35
36
  import { createRequire } from 'node:module'
36
37
  import net from 'node:net'
37
38
  import path from 'node:path'
@@ -53,6 +54,7 @@ import {
53
54
  parseWebUrl,
54
55
  readJson,
55
56
  removeTree,
57
+ resolveFangHome,
56
58
  resolveFangLayout,
57
59
  roleGate,
58
60
  writeFileAtomic,
@@ -63,6 +65,18 @@ import { computeBackoff, planRestart, reconcileOrphans, writeForkMeta, probeHttp
63
65
  import { applyForkConfigLock, setProfileConfigReadonly } from '../lib/fork-config-lock.mjs'
64
66
  import { runMainGate, formatGateFailure } from '../lib/main-gate.mjs'
65
67
  import { DEFAULT_FORK_SEED, applyForkSeedToProfile } from '../lib/fork-seed.mjs'
68
+ import { loadAcceleratedKnownEventTypes, normalizeCoreMode, pruneAliasStubs, sanitizeAcceleratedForkSessions, writeAcceleratedForkProfile } from '../lib/accelerated-fork.mjs'
69
+ import { OFFICIAL_EXPERIMENTAL_BUNDLES, NODE_COMPAT_BUNDLE, parsePatchEntries } from '../lib/essence.mjs'
70
+ import { accelNodeModulesRoot, acceleratedCoreInfo, resolveAcceleratedCore } from '../lib/accelerated-install.mjs'
71
+
72
+ /** Repository root of this plugin (used as the @twinsearth/fang-dsh-plugin junction source). */
73
+ const FANG_ROOT = (() => {
74
+ try {
75
+ return path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..')
76
+ } catch {
77
+ return ''
78
+ }
79
+ })()
66
80
 
67
81
  export const name = 'fang-forker'
68
82
  export const inject = []
@@ -83,7 +97,7 @@ const PORT_HOST = '127.0.0.1'
83
97
  /** A bind probe that does not answer by then counts as "not usable" (fail-closed, try next). */
84
98
  const PORT_PROBE_TIMEOUT_MS = 5000
85
99
  /** Bundle list of the clean fork profile: base + web app + this bundle (Cordis patch). */
86
- const CLEAN_TEMPLATE_BUNDLES = ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app']
100
+ const CLEAN_TEMPLATE_BUNDLES = ['@twinsearth/dsh-fang-node-compat', '@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app']
87
101
 
88
102
  // v3.1.0: DSH's first-run preview notice persists ui-settings-general.welcomeNoticeVersion.
89
103
  // A clean profile that omits the row leaves the config form unavailable, so 「继续」 always
@@ -107,7 +121,7 @@ const DEFAULTS = {
107
121
  portPool: { ...DEFAULT_PORT_POOL },
108
122
  allocatePorts: true,
109
123
  cleanTemplate: true,
110
- bundleName: '@twinsearth/dsh-fang',
124
+ bundleName: '@twinsearth/fang-dsh-plugin',
111
125
  forkProfileTag: 'web-base',
112
126
  }
113
127
 
@@ -145,7 +159,9 @@ export const Config = z
145
159
  .boolean()
146
160
  .default(true)
147
161
  .description('true:用内置干净模板(不继承母体脏 profile);false:沿用 profileTemplate'),
148
- bundleName: z.string().default('@twinsearth/dsh-fang').description('干净模板 profile.bundles 的第三个 bundle'),
162
+ bundleName: z.string().default('@twinsearth/fang-dsh-plugin').description('干净模板 profile.bundles 的第三个 bundle'),
163
+ coreMode: z.union([z.const('stock'), z.const('accelerated')]).default('stock').description('new fork uses stock or accelerated DSH core'),
164
+ acceleratedCliPath: z.string().default('').description('accelerated DSH CLI path'),
149
165
  forkProfileTag: z.string().default('web-base').description('干净模板 profile 标签(模板目录/缺省 profile 名)'),
150
166
  // v3.1.12:新机器/新用户的干净分身默认不带第三方插件;这里按“安装不激活 /
151
167
  // 安装并激活”两组清单给每个新分身装默认插件(开关可关;失败不阻塞分身启动)。
@@ -543,16 +559,28 @@ export function apply(ctx, config) {
543
559
  let forksFile = ''
544
560
  let portsFile = ''
545
561
  let layout = null
546
- if (cfg.dataRoot) {
547
- try {
548
- layout = resolveFangLayout({ dataRoot: cfg.dataRoot })
562
+ // v3.5.3 修复:layout 必须始终解析。加速核安装位置由 FANG_HOME / fang-home.txt 决定,
563
+ // 与 forker 是否配置 dataRoot 无关;此前只在 cfg.dataRoot 时解析,导致生产环境
564
+ // acceleratedHome='' → /fang/api/fork-core 报“未安装”(按钮点击无效)、派生加速分身
565
+ // 直接 409 accelerated-cli-missing(无法启动)。
566
+ try {
567
+ layout = resolveFangLayout({ dataRoot: cfg.dataRoot })
568
+ // 持久化文件仍只在显式 dataRoot(独立/测试部署)下启用,避免测试污染真实数据根。
569
+ if (cfg.dataRoot) {
549
570
  forksFile = layout.forksFile
550
571
  portsFile = path.join(layout.dataDir, 'ports.json')
551
- } catch (e) {
552
- logWarn(`[fang-forker] layout resolve failed: ${msgOf(e)}`)
553
- forksFile = ''
554
- portsFile = ''
555
572
  }
573
+ } catch (e) {
574
+ logWarn(`[fang-forker] layout resolve failed: ${msgOf(e)}`)
575
+ layout = null
576
+ forksFile = ''
577
+ portsFile = ''
578
+ }
579
+ /** 加速核所在的 FANG_HOME:layout → env/fang-home.txt(与 forker dataRoot 无关)。 */
580
+ const acceleratedHomeDir = () => {
581
+ const fromLayout = String(layout?.fangHome ?? '').trim()
582
+ if (fromLayout) return fromLayout
583
+ try { return String(resolveFangHome(process.env) ?? '').trim() } catch { return '' }
556
584
  }
557
585
  let registryLoaded = false
558
586
  let portsLoaded = false
@@ -582,6 +610,7 @@ export function apply(ctx, config) {
582
610
  url: stripUrlToken(rec.url),
583
611
  homeDir: rec.homeDir ?? '',
584
612
  profile: rec.profile ?? '',
613
+ coreMode: rec.coreMode === 'accelerated' ? 'accelerated' : 'stock',
585
614
  profileDir: rec.profileDir ?? '',
586
615
  template: rec.template ?? '',
587
616
  bufferDir: rec.bufferDir ?? '',
@@ -856,17 +885,26 @@ export function apply(ctx, config) {
856
885
  ensureRegistry()
857
886
  const homeRaw = String(opts.homeDir ?? '').trim()
858
887
  if (!homeRaw) return { ok: false, error: 'no-home-dir' }
888
+ // Accelerated forks never clone the mother profile: its bundles are @deepseek-ai/*
889
+ // and its third-party plugins target the stock core. They get a minimal profile.
890
+ const coreMode = normalizeCoreMode(opts.coreMode ?? cfg.coreMode)
859
891
  const templateRaw = String(opts.profileTemplate ?? cfg.profileTemplate ?? '').trim()
860
- if (!templateRaw) return { ok: false, error: 'no-profile-template' }
861
- const sourceTemplateDir = path.resolve(templateRaw)
862
- if (!exists(sourceTemplateDir)) return { ok: false, error: 'profile-template-missing', profileTemplate: sourceTemplateDir }
892
+ let sourceTemplateDir = ''
893
+ if (coreMode !== 'accelerated') {
894
+ if (!templateRaw) return { ok: false, error: 'no-profile-template' }
895
+ sourceTemplateDir = path.resolve(templateRaw)
896
+ if (!exists(sourceTemplateDir)) return { ok: false, error: 'profile-template-missing', profileTemplate: sourceTemplateDir }
897
+ }
863
898
 
864
899
  const forkId = String(opts.forkId ?? '').trim() || newId('fork')
865
900
  const existing = records.get(forkId)
866
901
  if (existing && (existing.running || existing.starting)) return { ok: false, error: 'already-running', forkId }
867
902
 
868
903
  const homeDir = path.resolve(homeRaw)
869
- const profile = safeProfile(opts.profile ?? (cleanTemplate ? forkProfileTag : path.basename(sourceTemplateDir)))
904
+ const defaultProfileName = coreMode === 'accelerated'
905
+ ? `${forkProfileTag}-accel`
906
+ : (cleanTemplate ? forkProfileTag : path.basename(sourceTemplateDir))
907
+ const profile = safeProfile(opts.profile ?? defaultProfileName)
870
908
  const profileDir = path.join(homeDir, 'profiles', profile)
871
909
  // v3.3.0 主城门禁(新建 profile):分身/元主运行态首次落盘前必须过路径/磁盘/门禁。
872
910
  // 已存在的 profile 走 restart 路径,不重复新建检查。
@@ -890,10 +928,61 @@ export function apply(ctx, config) {
890
928
  // 显式 profileTemplate(例如原身 merged/profile)优先:此时不再用 clean template。
891
929
  const useCleanTemplate = typeof opts.cleanTemplate === 'boolean' ? opts.cleanTemplate : cleanTemplate
892
930
  const nodeModulesSource = String(opts.nodeModulesSource ?? '').trim() || path.join(sourceTemplateDir, 'node_modules')
893
- let template = sourceTemplateDir
931
+ let template = coreMode === 'accelerated' ? '' : sourceTemplateDir
894
932
  let cloned = []
895
-
896
- if (useCleanTemplate) {
933
+ let accelerated = null
934
+
935
+ if (coreMode === 'accelerated') {
936
+ // D2 hybrid: when a source profile is given (essence-derived fork), sync its
937
+ // plugin surface (third-party packages + @deepseek-ai/* alias stubs); otherwise
938
+ // fall back to the minimal accelerated profile.
939
+ const sourceProfileDir = String(opts.sourceProfileDir ?? '').trim()
940
+ // 与 spawn() 相同的加速核 home 解析;此前误用了 spawn 作用域的变量(ReferenceError 被
941
+ // try/catch 吞掉 → essence 派生的加速分身总是静默退回 minimal,插件面不生效)。
942
+ const accelHome = acceleratedHomeDir()
943
+ || (layout?.dataDir ? path.resolve(layout.dataDir, '..') : '')
944
+ let accelNodeModules = ''
945
+ try {
946
+ const resolvedAccel = resolveAcceleratedCore({ cliPath: cfg.acceleratedCliPath ?? '', env: process.env, fangHome: accelHome })
947
+ if (resolvedAccel.ok === true && resolvedAccel.cliPath) {
948
+ accelNodeModules = accelNodeModulesRoot(resolvedAccel.cliPath)
949
+ }
950
+ } catch { /* keep minimal profile */ }
951
+ // 原身派生的加速分身必须同步插件面;解析不到加速核模块树时显式失败,绝不静默退回 minimal
952
+ // (静默退回会让分身“能启动但插件全失效”,属于最难排查的假成功)。
953
+ if (sourceProfileDir && !accelNodeModules) {
954
+ return {
955
+ ok: false,
956
+ error: 'accelerated-sync-unavailable',
957
+ detail: 'source profile was given but the accelerated node_modules tree could not be resolved',
958
+ }
959
+ }
960
+ const written = writeAcceleratedForkProfile({
961
+ profileDir,
962
+ fangRoot: FANG_ROOT,
963
+ homeDir,
964
+ motherHome: String(process.env.DSH_HOME ?? '').trim(),
965
+ profileName: profile,
966
+ sourceProfileDir,
967
+ accelNodeModules,
968
+ })
969
+ if (written.ok !== true) {
970
+ return { ok: false, error: written.error ?? 'accelerated-profile-failed', detail: JSON.stringify(written) }
971
+ }
972
+ warnings.push(...(Array.isArray(written.warning) ? written.warning : []))
973
+ if (written.overlay?.ok !== true) warnings.push(`accelerated-model-overlay:${written.overlay?.error ?? 'unknown'}`)
974
+ // 2026-11-22: accelerated core 3.5.0 cannot read catalog v3 facts (and rejects
975
+ // stock-only event types). Sessions copied from a stock mother are made compatible here
976
+ // (frame-preserving, with a backup) so the fork's history opens.
977
+ try {
978
+ const sanitized = sanitizeAcceleratedForkSessions(homeDir)
979
+ if (sanitized.changedEvents > 0) warnings.push(`catalog-compat:${sanitized.changedEvents}`)
980
+ written.catalogSanitize = sanitized
981
+ } catch (error) {
982
+ warnings.push(`catalog-sanitize-failed:${msgOf(error)}`)
983
+ }
984
+ accelerated = { bundles: written.bundles, overlay: written.overlay, junctions: written.junctions, sync: written.sync ?? null, forkLsp: written.forkLsp ?? null }
985
+ } else if (useCleanTemplate) {
897
986
  // Forker-owned clean template: never written into the mother profile directory.
898
987
  const cleanDir = path.join(homeDir, 'templates', forkProfileTag)
899
988
  const ensured = ensureTemplate({
@@ -930,7 +1019,11 @@ export function apply(ctx, config) {
930
1019
  // (w2m's shim emits `required: false` in a property schema → the provider rejects
931
1020
  // every request: "Invalid schema for function 'w2m_report'", v3.1.7 report).
932
1021
  let nodeModules = null
933
- if (exists(nodeModulesSource)) {
1022
+ if (coreMode !== 'accelerated' && exists(nodeModulesSource)) {
1023
+ // Switching accelerated → stock: drop the accelerated alias stubs first, otherwise
1024
+ // the stock CLI keeps importing accelerated modules through them (startup abort).
1025
+ const pruned = pruneAliasStubs(profileDir)
1026
+ if (pruned.removed.length > 0) warnings.push(`alias-stubs-pruned:${pruned.removed.length}`)
934
1027
  try {
935
1028
  const mirrored = mirrorModuleTree(nodeModulesSource, path.join(profileDir, 'node_modules'))
936
1029
  if (mirrored.ok === true) nodeModules = nodeModulesSource
@@ -956,6 +1049,8 @@ export function apply(ctx, config) {
956
1049
  bufferDir,
957
1050
  template,
958
1051
  nodeModules,
1052
+ coreMode,
1053
+ accelerated,
959
1054
  pid: rec.pid ?? null,
960
1055
  port: rec.port ?? null,
961
1056
  url: rec.url ?? null,
@@ -968,8 +1063,8 @@ export function apply(ctx, config) {
968
1063
  })
969
1064
  records.set(forkId, rec)
970
1065
  persist()
971
- audit(AUDIT.FORK_CREATED, { forkId, homeDir, profile, taskTitle: rec.taskTitle, cloned, warnings, template })
972
- return { ok: true, forkId, homeDir, profileDir, bufferDir, profile, template, cloned, node_modules: nodeModules, warnings, configLock, profileReadonly }
1066
+ audit(AUDIT.FORK_CREATED, { forkId, homeDir, profile, taskTitle: rec.taskTitle, cloned, warnings, template, coreMode })
1067
+ return { ok: true, forkId, homeDir, profileDir, bufferDir, profile, template, cloned, node_modules: nodeModules, coreMode, accelerated, warnings, configLock, profileReadonly }
973
1068
  }
974
1069
 
975
1070
  // ───────────────────────────── spawn ─────────────────────────────
@@ -991,13 +1086,84 @@ export function apply(ctx, config) {
991
1086
  })
992
1087
  }
993
1088
 
1089
+ /** 2026-11-22:任何 stock 分身启动前都补齐官方 15 个实验性 bundle(不依赖 orchestrator 的
1090
+ * post-provision 步骤;修复 repair/restore 重新 provision 后实验性全关的回归)。 */
1091
+ function applyForkExperimentalSurface(profileDir) {
1092
+ try {
1093
+ const pkgFile = path.join(String(profileDir), 'package.json')
1094
+ const patchFile = path.join(String(profileDir), 'cordis.patch.yml')
1095
+ const pkg = readJson(pkgFile, null)
1096
+ if (!pkg) return { ok: false, error: 'profile-package-missing' }
1097
+ pkg.dsh = pkg.dsh && typeof pkg.dsh === 'object' ? pkg.dsh : {}
1098
+ pkg.dsh.profile = pkg.dsh.profile && typeof pkg.dsh.profile === 'object' ? pkg.dsh.profile : {}
1099
+ const bundles = Array.isArray(pkg.dsh.profile.bundles) ? [...pkg.dsh.profile.bundles] : []
1100
+ pkg.dependencies = pkg.dependencies && typeof pkg.dependencies === 'object' ? pkg.dependencies : {}
1101
+ pkg.dependencies[NODE_COMPAT_BUNDLE] = '^0.1.0'
1102
+ if (!bundles.includes(NODE_COMPAT_BUNDLE)) bundles.unshift(NODE_COMPAT_BUNDLE)
1103
+ for (const name of OFFICIAL_EXPERIMENTAL_BUNDLES) if (!bundles.includes(name)) bundles.push(name)
1104
+ pkg.dsh.profile.bundles = bundles
1105
+ writeJsonAtomic(pkgFile, pkg)
1106
+ // 把 node-compat 实际安装到 fork profile;否则 DSH 会跳过第一个 bundle。
1107
+ // 安装态:FANG_ROOT/../dsh-fang-node-compat;仓库态:FANG_ROOT/node_modules/... 或 node-compat/。
1108
+ const compatCandidates = [
1109
+ path.resolve(FANG_ROOT, '..', 'dsh-fang-node-compat'),
1110
+ path.join(FANG_ROOT, 'node_modules', '@twinsearth', 'dsh-fang-node-compat'),
1111
+ path.join(FANG_ROOT, 'node-compat'),
1112
+ ]
1113
+ const compatSource = compatCandidates.find((candidate) => exists(path.join(candidate, 'package.json')))
1114
+ const compatTarget = path.join(String(profileDir), 'node_modules', '@twinsearth', 'dsh-fang-node-compat')
1115
+ if (compatSource && process.env.DSH_FANG_NODE_COMPAT_COPY === '1' && !exists(path.join(compatTarget, 'package.json'))) {
1116
+ ensureDir(path.dirname(compatTarget))
1117
+ copyTree(compatSource, compatTarget)
1118
+ }
1119
+ const entries = parsePatchEntries(exists(patchFile) ? fs.readFileSync(patchFile, 'utf8') : '').entries
1120
+ const kept = entries.filter((entry) => !OFFICIAL_EXPERIMENTAL_BUNDLES.includes(String(entry?.name ?? '')))
1121
+ for (const name of OFFICIAL_EXPERIMENTAL_BUNDLES) kept.push({ id: `official-exp-${name.slice(-8)}`, name, disabled: false })
1122
+ fs.writeFileSync(patchFile, `${JSON.stringify(kept, null, 2)}\n`, 'utf8')
1123
+ return { ok: true, bundles: OFFICIAL_EXPERIMENTAL_BUNDLES.length }
1124
+ } catch (error) {
1125
+ return { ok: false, error: String(error?.message ?? error) }
1126
+ }
1127
+ }
994
1128
  const spawn = async (opts = {}) => {
995
1129
  ensureRegistry()
996
1130
  ensurePorts()
997
1131
  const forkId = String(opts.forkId ?? '').trim() || newId('fork')
998
1132
  const homeDir = String(opts.homeDir ?? '').trim()
999
1133
  const profile = safeProfile(opts.profile ?? 'default')
1000
- const cliPath = String(opts.cliPath ?? cfg.cliPath ?? '').trim()
1134
+ // Core selection is explicit: opts.coreMode (essence runtime passes 'stock') wins over the
1135
+ // plugin config. An accelerated fork NEVER falls back to the stock CLI — missing install is
1136
+ // a hard error so the fork cannot silently run unaccelerated.
1137
+ const coreMode = normalizeCoreMode(opts.coreMode ?? cfg.coreMode)
1138
+ let spawnCatalogCompat = null
1139
+ const acceleratedHome = acceleratedHomeDir()
1140
+ || (layout?.dataDir ? path.resolve(layout.dataDir, '..') : '')
1141
+ let cliPath = ''
1142
+ let acceleratedSource = null
1143
+ if (coreMode === 'accelerated') {
1144
+ const resolved = resolveAcceleratedCore({
1145
+ // opts.cliPath 是母体 stock CLI(orchestrator 传参),绝不能当加速核候选:
1146
+ // JS 入口的 stock CLI 会被误判为“加速核”从而静默跑官方 core(无效)。
1147
+ cliPath: String(opts.acceleratedCliPath ?? cfg.acceleratedCliPath ?? ''),
1148
+ env: process.env,
1149
+ fangHome: acceleratedHome,
1150
+ })
1151
+ if (resolved.ok !== true) {
1152
+ return { forkId, ok: false, error: 'accelerated-cli-missing', coreMode, searched: resolved.searched }
1153
+ }
1154
+ cliPath = resolved.cliPath
1155
+ acceleratedSource = resolved.source
1156
+ // 2026-11-22: the accelerated host refuses unknown event types (team/mode) and catalog
1157
+ // v3 facts from stock DSH. Make the fork's copied sessions compatible before it starts.
1158
+ try {
1159
+ const known = await loadAcceleratedKnownEventTypes(accelNodeModulesRoot(cliPath))
1160
+ spawnCatalogCompat = sanitizeAcceleratedForkSessions(homeDir, { knownEventTypes: known })
1161
+ } catch (error) {
1162
+ spawnCatalogCompat = { ok: false, error: msgOf(error) }
1163
+ }
1164
+ } else {
1165
+ cliPath = String(opts.cliPath ?? cfg.cliPath ?? '').trim()
1166
+ }
1001
1167
  const timeoutMs = Math.max(1, Math.floor(Number(opts.timeoutMs ?? cfg.startTimeoutMs) || DEFAULTS.startTimeoutMs))
1002
1168
  const maxLogLines = Math.max(1, Math.floor(Number(cfg.maxLogLines) || DEFAULTS.maxLogLines))
1003
1169
 
@@ -1030,6 +1196,8 @@ export function apply(ctx, config) {
1030
1196
  startedAt: nowMs(),
1031
1197
  ready: false,
1032
1198
  cliPath,
1199
+ coreMode,
1200
+ acceleratedSource,
1033
1201
  crashCount: rec.crashCount ?? 0,
1034
1202
  restartCount: rec.restartCount ?? 0,
1035
1203
  restartScheduledAt: null,
@@ -1040,6 +1208,7 @@ export function apply(ctx, config) {
1040
1208
  */
1041
1209
  adapterToken: randomBytes(24).toString('hex'),
1042
1210
  log: collector,
1211
+ catalogCompat: spawnCatalogCompat,
1043
1212
  })
1044
1213
  records.set(forkId, rec)
1045
1214
  // v3.0.9 生产盘:每次打开/重启都从来源模板重放配置(原身 merged 或 clean template),
@@ -1067,23 +1236,33 @@ export function apply(ctx, config) {
1067
1236
  // the per-entry mirror. This is what makes the fork host resolve the installation's
1068
1237
  // `@deepseek-ai/*` packages for profile plugins again; without it every agent request in
1069
1238
  // the fork is rejected by the provider (w2m offline shim → invalid tool schema).
1070
- try {
1071
- const repaired = ensureModuleMirror(path.join(rec.profileDir, 'node_modules'))
1072
- rec.nodeModulesMirror = {
1073
- changed: repaired.changed === true,
1074
- ok: repaired.ok !== false,
1075
- source: repaired.source ?? null,
1076
- links: Array.isArray(repaired.links) ? repaired.links.length : 0,
1077
- error: repaired.error ?? null,
1239
+ // Accelerated forks own a hand-built node_modules (fang + child junctions); the stock
1240
+ // mirror repair would point them back at the official installation, so skip it.
1241
+ if (rec.coreMode === 'accelerated') {
1242
+ rec.nodeModulesMirror = { ok: true, skipped: 'accelerated-core', changed: false, source: null, links: 0, error: null }
1243
+ } else {
1244
+ // A stock fork must never resolve the accelerated alias stubs. Repair stale stubs left
1245
+ // by an earlier accelerated run before the mirror repair, so restore/open works after a
1246
+ // core switch (2026-11-22: spawn-failed/exited on restore).
1247
+ try { rec.aliasPrune = pruneAliasStubs(rec.profileDir) } catch { rec.aliasPrune = { ok: false, removed: [] } }
1248
+ try {
1249
+ const repaired = ensureModuleMirror(path.join(rec.profileDir, 'node_modules'))
1250
+ rec.nodeModulesMirror = {
1251
+ changed: repaired.changed === true,
1252
+ ok: repaired.ok !== false,
1253
+ source: repaired.source ?? null,
1254
+ links: Array.isArray(repaired.links) ? repaired.links.length : 0,
1255
+ error: repaired.error ?? null,
1256
+ }
1257
+ } catch (e) {
1258
+ rec.nodeModulesMirror = { ok: false, changed: false, error: msgOf(e) }
1078
1259
  }
1079
- } catch (e) {
1080
- rec.nodeModulesMirror = { ok: false, changed: false, error: msgOf(e) }
1081
1260
  }
1082
1261
  // v3.1.12:默认第三方插件种子。install=只安装;activate=安装并激活(写入 bundles)。
1083
1262
  // 种子安装在独立 seed home(dsh 自带 pnpm),模块以 hardlink 合并进分身 node_modules;
1084
1263
  // 同一指纹只装一次。失败不阻塞分身启动,但结果保留在 rec.forkSeed 供 UI 诊断。
1085
1264
  rec.forkSeed = null
1086
- if (cfg.forkSeed?.enabled !== false && !String(profile).startsWith('essence-') && process.env.DSH_FANG_FORK_SEED !== '0') {
1265
+ if (cfg.forkSeed?.enabled !== false && rec.coreMode !== 'accelerated' && !String(profile).startsWith('essence-') && process.env.DSH_FANG_FORK_SEED !== '0') {
1087
1266
  const seedRoot = path.join(path.dirname(path.resolve(homeDir)), '.plugin-seed')
1088
1267
  try { setProfileConfigReadonly(rec.profileDir, false) } catch { /* ignore */ }
1089
1268
  try {
@@ -1103,6 +1282,12 @@ export function apply(ctx, config) {
1103
1282
  audit(AUDIT.FORK_CREATED, { forkId, forkSeedError: rec.forkSeed.error, forkSeedDetail: String(rec.forkSeed.detail ?? '').slice(0, 600) })
1104
1283
  }
1105
1284
  }
1285
+ // 2026-11-22:provision / repair / restore 可能把 profile 重置成干净模板;启动前
1286
+ // 无条件补齐官方 15 个实验性 bundle,避免实验性页面全关(不依赖 orchestrator 后置步骤)。
1287
+ if (rec.coreMode !== 'accelerated') {
1288
+ rec.experimentalSurface = applyForkExperimentalSurface(rec.profileDir)
1289
+ if (rec.experimentalSurface.ok !== true) audit(AUDIT.FORK_CREATED, { forkId, experimentalSurfaceError: rec.experimentalSurface.error })
1290
+ }
1106
1291
  writeForkMetaOf(rec)
1107
1292
  // 广播新 token:首次派生 = 生成,重启 = 刷新;订阅者拿到的是「当前 token」,
1108
1293
  // 不是「进程就绪」信号(进程就绪以 fang/fork-started 为准)。
@@ -1177,7 +1362,9 @@ export function apply(ctx, config) {
1177
1362
  // window for the native directory chooser; pin the browse interaction through a
1178
1363
  // launcher overlay so "select workspace" works inside every fork Web UI.
1179
1364
  const patchPaths = []
1180
- const headlessOverlay = writeHeadlessPickerOverlay(rec.profileDir, { cliPath })
1365
+ // The stock headless-picker overlay mounts @deepseek-ai/* rows; the accelerated
1366
+ // core has no such packages, so it is never applied there.
1367
+ const headlessOverlay = coreMode === 'accelerated' ? null : writeHeadlessPickerOverlay(rec.profileDir, { cliPath })
1181
1368
  if (headlessOverlay) patchPaths.push(headlessOverlay)
1182
1369
  const spec = buildLaunchSpec({ cliPath, profile, port: expectedPort, patchPaths })
1183
1370
  const env = buildForkChildEnv(process.env, {
@@ -1185,10 +1372,15 @@ export function apply(ctx, config) {
1185
1372
  // Fork identity is injected by the forker (a fork must never be able to call itself mother).
1186
1373
  DSH_FANG_ROLE: 'fork',
1187
1374
  DSH_FANG_TASK_ID: forkId,
1375
+ DSH_FANG_CORE: coreMode,
1188
1376
  ...(opts.env ?? {}),
1189
1377
  // v3:Adapter Bearer token(PROTOCOL-V3 §3)。放在 opts.env 之后,母体生成的 token 优先。
1190
1378
  DSH_ADAPTER_TOKEN: rec.adapterToken,
1191
1379
  })
1380
+ // JS 入口(加速核 lib/bin.js)用 process.execPath 启动。桌面宿主里 execPath 是 Electron 壳,
1381
+ // 子进程环境白名单会丢掉宿主的 ELECTRON_RUN_AS_NODE;不补回时壳把脚本当应用/URL,
1382
+ // 立即 exit 0 且无输出 —— 真机表现为“加速核心分身无法启动”。对真 node 无害(会忽略)。
1383
+ if (spec.nodeScript && env.ELECTRON_RUN_AS_NODE !== '1') env.ELECTRON_RUN_AS_NODE = '1'
1192
1384
  let child = null
1193
1385
  try {
1194
1386
  child = spawnProcess(spec.command, spec.args, {
@@ -1563,6 +1755,39 @@ export function apply(ctx, config) {
1563
1755
  try { audit(AUDIT.FORK_SUPERVISION, { enabled: runtimeSupervise }) } catch { /* audit optional */ }
1564
1756
  return { ok: true, enabled: runtimeSupervise }
1565
1757
  },
1758
+ /**
1759
+ * Read-only accelerated-core view for the mother panel route (P0).
1760
+ * It never starts anything: only reports the configured default, the install
1761
+ * state, and how many forks currently run on each core.
1762
+ */
1763
+ coreStatus() {
1764
+ const acceleratedHome = acceleratedHomeDir()
1765
+ || (layout?.dataDir ? path.resolve(layout.dataDir, '..') : '')
1766
+ const accelerated = acceleratedCoreInfo({ cliPath: cfg.acceleratedCliPath ?? '', fangHome: acceleratedHome })
1767
+ const counts = { stock: 0, accelerated: 0 }
1768
+ for (const rec of records.values()) {
1769
+ const mode = normalizeCoreMode(rec.coreMode)
1770
+ counts[mode] = (counts[mode] ?? 0) + 1
1771
+ }
1772
+ return {
1773
+ mode: normalizeCoreMode(cfg.coreMode),
1774
+ installable: true,
1775
+ accelerated: {
1776
+ installed: accelerated.installed,
1777
+ version: accelerated.version,
1778
+ cliPath: accelerated.cliPath,
1779
+ source: accelerated.source,
1780
+ error: accelerated.error,
1781
+ searched: accelerated.searched,
1782
+ installedAt: accelerated.installedAt,
1783
+ sizeBytes: accelerated.sizeBytes ?? 0,
1784
+ limitBytes: accelerated.limitBytes ?? null,
1785
+ requiresConfirmation: accelerated.requiresConfirmation === true,
1786
+ root: accelerated.layout?.root ?? null,
1787
+ },
1788
+ forks: counts,
1789
+ }
1790
+ },
1566
1791
  }
1567
1792
 
1568
1793
  ctx.effect(() => ctx.provide(SERVICE.forker, service))