@aiwayds/dsh-opentui 0.26.0 → 0.26.2

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.
@@ -6,9 +6,11 @@
6
6
  // Invoked by the launcher on EVERY start (S6: bridge is the sole seam; the
7
7
  // former env escape hatch that skipped provisioning is removed with it).
8
8
  // The `opentui` profile path is otherwise untouched.
9
- // Seven local-FS steps (the first is the host-version gate), no pnpm/npm, no install scripts:
9
+ // Eight steps (the first is the host-version gate). Steps 1-3 and 5-8 are
10
+ // local-FS only; step 4 (companions) is the one unfrozen step that MAY run a
11
+ // package manager (user decision 2026-11-22 — "npm 安装好的时候,registry 和其他几个依赖插件,默认装好").
10
12
  //
11
- // [1/7] host — detect the running dsh version. OUTSIDE the supported
13
+ // [1/8] host — detect the running dsh version. OUTSIDE the supported
12
14
  // window (>=0.2.2-rc.3 <0.3.0) => fail-fast with the three
13
15
  // fail-fast elements: the host would otherwise skip the
14
16
  // bridge bundle silently (it only records the conflict in
@@ -17,32 +19,53 @@
17
19
  // exact-version exemption in compatibility.json. Never
18
20
  // grants outside the window: --accept-risk is not a way to
19
21
  // mask a genuine incompatibility.
20
- // [2/7] manifest — write $DSH_HOME/profiles/opentui-inproc/package.json with
22
+ // [2/8] manifest — write $DSH_HOME/profiles/opentui-inproc/package.json with
21
23
  // dsh.profile.bundles = [@deepseek-ai/dsh-base,
22
- // @aiwayds/dsh-opentui-bridge]. NO @deepseek-ai/* dependency
23
- // is ever written: the host's installation-first bundle
24
- // resolution supplies those bundles from the running dsh
25
- // closure (wild-package shadowing is the historical
24
+ // @aiwayds/dsh-opentui-bridge] PLUS any companion bundles
25
+ // already declared in dependencies. NO @deepseek-ai
26
+ // dependency is ever written: the host's installation-first
27
+ // bundle resolution supplies those bundles from the running
28
+ // dsh closure (wild-package shadowing is the historical
26
29
  // incident this guard prevents).
27
- // [3/7] copy — materialize node_modules/@aiwayds/dsh-opentui-bridge as a
30
+ // [3/8] copy — materialize node_modules/@aiwayds/dsh-opentui-bridge as a
31
+
28
32
  // REAL DIRECTORY COPY of THIS installation's dist/bridge.
29
33
  // S6 symlink-debt retirement: no absolute symlink (no path
30
34
  // binding, no multi-worktree last-writer-wins, no dangling
31
35
  // link when a worktree is removed). Converged every launch;
32
36
  // idempotent when the copy's index.js hash matches.
33
- // [4/7] verify — confirm the bridge is a real directory carrying the
34
- // shipped files; refuse any @deepseek-ai copy in the profile.
35
- // [5/7] identity — T5 guard: hash the materialized bridge's index.js and
37
+ // [4/8] companions — install the minimal companion set (default: the
38
+ // @aiwayds/dsh-subagent-registry bundle, which self-mounts
39
+ // the `use_agent` tool through its own cordis.patch.yml).
40
+ // Resolves `latest`, guards major/downgrade, skips when
41
+ // already at that version, and is disabled wholesale by
42
+ // DSH_OPENTUI_COMPANION_LATEST=off. A failed install OR a
43
+ // missing global `dsh` is a WARN (never a boot blocker):
44
+ // stale manifest declarations from a half-write are removed
45
+ // and hosts without dsh skip companions with a warning.
46
+ // Step 5 then verifies that whatever remains declared in
47
+ // the manifest is fully mounted.
48
+ // [5/8] verify — confirm the bridge is a real directory carrying the
49
+ // shipped files; refuse any @deepseek-ai copy in the profile;
50
+ // cross-check companion manifest deps <-> bundle entries <-
51
+ // -> installed node_modules (no half-provisioned state).
52
+ // Step 4 drops stale declarations an unsuccessful add left
53
+ // behind, so this guard never blocks a boot for something
54
+ // the provisioning pass itself could not install offline.
55
+ // [6/8] identity — T5 guard: hash the materialized bridge's index.js and
36
56
  // compare with the build-time fingerprint shipped in THIS
37
57
  // installation's dist/bridge/bundle-fingerprint.json, plus
38
58
  // name / version. No realpath-prefix hard binding.
39
- // [6/7] patch — generate $DSH_HOME/profiles/opentui-inproc/cordis.patch.yml
59
+ // [7/8] patch — generate $DSH_HOME/profiles/opentui-inproc/cordis.patch.yml
40
60
  // from the embedded inproc-only template (web-app
41
61
  // compensation rows removed, profileRevision stamped). The
42
62
  // template also registers the standalone sessionController
43
63
  // shim plus the real @deepseek-ai/dsh-api-session-controller
44
- // plugin — no dsh-web-app bundle is pulled in.
45
- // [7/7] shim — generate the local shim package under the profile's
64
+ // plugin — no dsh-web-app bundle is pulled in. Companion
65
+ // mounts ride their own bundle patches (activated by the
66
+ // manifest bundle entries), so no duplicate rows are added
67
+ // here.
68
+ // [8/8] shim — generate the local shim package under the profile's
46
69
  // node_modules (@aiwayds scope) that the patch row resolves.
47
70
  // Its
48
71
  // @deepseek-ai/cordis import is resolved by the host against
@@ -67,9 +90,11 @@
67
90
  // convergence, so a fingerprint mismatch still fails loud.
68
91
  //
69
92
  // Hard guard: this script only ever touches the ONE profile named
70
- // `opentui-inproc`. It never runs a package manager and never writes a
71
- // dependency into the manifest.
93
+ // `opentui-inproc`. The ONLY package-manager call is step [4/8], scoped to the
94
+ // explicit companion catalog; it never writes a @deepseek-ai dependency into
95
+ // the manifest (those bundles come from the running dsh closure).
72
96
 
97
+ import { spawnSync } from 'node:child_process'
73
98
  import { createHash } from 'node:crypto'
74
99
  import {
75
100
  closeSync,
@@ -108,6 +133,15 @@ import {
108
133
  ensureHostExemption,
109
134
  isHostVersionSupported,
110
135
  } from './lib/host-compat.mjs'
136
+ // Companion policy is a pure table; only the spawn and registry query live
137
+ // here (see step [4/8]). Mirrors dsh-tui-pi's companion-latest pattern.
138
+ import {
139
+ COMPANIONS,
140
+ COMPANION_LATEST_ENV,
141
+ decideCompanionInstall,
142
+ queryDistTagLatest,
143
+ selectCompanions,
144
+ } from './lib/inproc-companions.mjs'
111
145
 
112
146
  const PREFIX = 'dsh-opentui(inproc): '
113
147
  const PROFILE = 'opentui-inproc'
@@ -137,12 +171,13 @@ const lockPath = join(profileDir, LOCK_NAME)
137
171
  // S6: the patch/shim steps are unconditional (the env escape hatch that used
138
172
  // to skip them is removed with the legacy seam). The launcher runs this script
139
173
  // on every start; --repair-bridge and direct invocation converge identically.
140
- const TOTAL_STEPS = 7
174
+ const TOTAL_STEPS = 8
175
+ const COMPANION_INSTALL_TIMEOUT_MS = 10 * 60 * 1000
141
176
  const PATCH_NAME = 'cordis.patch.yml'
142
177
  const patchPath = join(profileDir, PATCH_NAME)
143
178
  const PATCH_REVISION_MARKER = '# profileRevision: '
144
179
  // Local shim package generated under the profile's node_modules. It lives in
145
- // the @aiwayds scope (never @deepseek-ai — see the guard in step [4/7]) so the
180
+ // the @aiwayds scope (never @deepseek-ai — see the guard in step [5/8]) so the
146
181
  // host resolves it from the profile scope; its own @deepseek-ai/cordis import
147
182
  // is routed by the host's runtime interception to the same dsh closure that
148
183
  // serves the bridge. The patch row uses this bare package name.
@@ -560,10 +595,19 @@ const PATCH_TEMPLATE = `# model route (managed by provision-opentui-profile.mjs
560
595
  config:
561
596
  maxActiveSubagents: 3
562
597
 
598
+ # Companion mounts (2026-11-22 unfreeze). The minimal set installed by
599
+ # provision-inproc-profile.mjs step [4/8] is @aiwayds/dsh-subagent-registry,
600
+ # which registers the use_agent / ask_agent tools globally and carries its OWN
601
+ # cordis.patch.yml mount row. That row is activated by the dsh.profile.bundles
602
+ # entry that dsh plugin add writes into package.json — no duplicate row is added
603
+ # here (a same-id insert from this profile layer would only shadow the bundle's
604
+ # own patch). DSH_OPENTUI_COMPANION_LATEST=off skips the install; the default
605
+ # roster stays the locally-defined agents under $DSH_HOME/agents.
606
+
563
607
  # Standalone sessionController support (no dsh-web-app bundle). The real
564
608
  # controller needs 13 injects; 11 come from dsh-base, and the two web-only ones
565
609
  # (fileUploads, workspaceRegistry) are satisfied by the local shim package
566
- # generated in step [7/7]. No connection shim: dsh-api-gateway's optional
610
+ # generated in step [8/8]. No connection shim: dsh-api-gateway's optional
567
611
  # ctx.inject(['connection']) calls connection.rpc.intercept(...), which a no-op
568
612
  # stub cannot honor; leaving connection absent only keeps the controller's
569
613
  # SessionMediaReferences sub-plugin pending, which does not block list().
@@ -582,7 +626,7 @@ const PATCH_CONTENT = `${PATCH_HEADER}${PATCH_TEMPLATE}`
582
626
  const KNOWN_PATCH_MD5 = new Set(['54b66bf37fbbb93a6f9dd204a24473f7'])
583
627
 
584
628
  // --- Standalone sessionController shim template -----------------------------
585
- // Generated into the profile's node_modules (step [7/7]) so its runtime imports
629
+ // Generated into the profile's node_modules (step [8/8]) so its runtime imports
586
630
  // are resolved from the profile scope by the host, exactly like the bridge.
587
631
  // The real controller imports fileUploads / workspaceRegistry as TYPES ONLY;
588
632
  // only the narrow methods below are ever called, so no dsh-web-app closure is
@@ -804,17 +848,230 @@ function readManifest() {
804
848
  return readJsonObject(manifestPath)
805
849
  }
806
850
 
851
+ /**
852
+ * Companion bundles already declared in the manifest must survive the step-2
853
+ * convergence: otherwise every launch would strip them and step 4 would
854
+ * reinstall. Only packages from OUR catalog that the manifest already declares
855
+ * are preserved, so a stray dependency can never smuggle a bundle in.
856
+ */
857
+ const managedBundles = (existing) => {
858
+ const declared = COMPANIONS
859
+ .filter((entry) => Object.prototype.hasOwnProperty.call(existing?.dependencies ?? {}, entry.name))
860
+ .map((entry) => entry.name)
861
+ return [...new Set([...BUNDLES, ...declared])]
862
+ }
863
+
807
864
  const desiredManifest = (existing) => ({
808
865
  ...existing,
809
866
  dsh: {
810
867
  ...(existing?.dsh ?? {}),
811
868
  profile: {
812
869
  ...(existing?.dsh?.profile ?? {}),
813
- bundles: [...BUNDLES],
870
+ bundles: managedBundles(existing),
814
871
  },
815
872
  },
816
873
  })
817
874
 
875
+ /** Version actually mounted in the profile node_modules, or undefined. */
876
+ function installedCompanionVersion(name) {
877
+ try {
878
+ return JSON.parse(readFileSync(join(profileDir, 'node_modules', ...name.split('/'), 'package.json'), 'utf8')).version
879
+ } catch {
880
+ return undefined
881
+ }
882
+ }
883
+
884
+ /**
885
+ * A failed `dsh plugin add` can leave a dependency + bundle row behind without
886
+ * ever installing node_modules. Left alone, step [5/8] would turn that
887
+ * half-write into a permanent boot blocker on later (offline) starts, with no
888
+ * self-heal path. Drop only the stale declarations — healthy companions and
889
+ * the user's own dependencies are untouched — so the failure stays a WARN and
890
+ * provisioning always yields a usable profile.
891
+ */
892
+ function dropUnmountedCompanions(reason, only = null) {
893
+ const manifest = readManifest()
894
+ if (!manifest?.dependencies || typeof manifest.dependencies !== 'object') return 0
895
+ const bundles = Array.isArray(manifest.dsh?.profile?.bundles) ? manifest.dsh.profile.bundles : null
896
+ const stale = COMPANIONS.filter((entry) =>
897
+ (!only || only.includes(entry.name)) &&
898
+ Object.prototype.hasOwnProperty.call(manifest.dependencies, entry.name) &&
899
+ installedCompanionVersion(entry.name) === undefined)
900
+ if (stale.length === 0) return 0
901
+ for (const entry of stale) {
902
+ delete manifest.dependencies[entry.name]
903
+ if (bundles) {
904
+ const at = bundles.indexOf(entry.name)
905
+ if (at !== -1) bundles.splice(at, 1)
906
+ }
907
+ warn(`companion ${entry.name}: ${reason}; dropping stale declaration (companions are optional)`)
908
+ }
909
+ const tmpPath = `${manifestPath}.tmp-${process.pid}-${Date.now()}`
910
+ writeFileSync(tmpPath, `${JSON.stringify(manifest, null, 2)}\n`)
911
+ renameSync(tmpPath, manifestPath)
912
+ say(4, 'companions', `dropped ${stale.length} stale companion declaration(s) — profile stays usable`)
913
+ return stale.length
914
+ }
915
+
916
+ /**
917
+ * Only the companion step needs a global dsh; a satisfied run stays offline.
918
+ * Absence is NOT an error: companions are optional, so the caller degrades to
919
+ * a WARN and leaves the profile fully bootable (e.g. hosted CI runners have no
920
+ * global dsh). `which` itself missing/failing is treated the same way.
921
+ */
922
+ function dshOnPath() {
923
+ try {
924
+ const which = spawnSync('which', ['dsh'], { encoding: 'utf8' })
925
+ return which.status === 0 && Boolean(which.stdout.trim())
926
+ } catch {
927
+ return false
928
+ }
929
+ }
930
+
931
+ /**
932
+ * Step [4/8] — install the minimal companion set.
933
+ *
934
+ * The install is done through `dsh plugin add`, which is the one supported way
935
+ * to put a @aiwayds package into a profile: it writes the dependency, appends
936
+ * the bundle entry (that entry is what activates the plugin's OWN
937
+ * cordis.patch.yml mount row), and installs node_modules — including the
938
+ * registry's `dsh-jev-core` dependency, which the client's spin-attention
939
+ * probe then finds in the profile. With `nodeLinker: hoisted` +
940
+ * `autoInstallPeers: false` in this profile, no @deepseek-ai peer is copied
941
+ * into the profile, so step [5/8]'s no-@deepseek-ai guard still holds.
942
+ *
943
+ * Companions are optional: an install failure is a WARN, never a boot blocker.
944
+ * A half-write (dependency declared, package missing) is cleaned up here —
945
+ * immediately after a failed add, and on later offline starts — so step [5/8]
946
+ * never hard-fails on a state this step itself could not resolve.
947
+ */
948
+ function provisionCompanions() {
949
+ const selected = selectCompanions(process.env)
950
+ if (selected.length === 0) {
951
+ const off = ['0', 'false', 'off'].includes(String(process.env[COMPANION_LATEST_ENV] ?? '').trim().toLowerCase())
952
+ say(4, 'companions', off ? `skipped (${COMPANION_LATEST_ENV}=off)` : 'none selected')
953
+ return
954
+ }
955
+
956
+ const manifest = readManifest() ?? {}
957
+ const specs = []
958
+ let unavailable = 0
959
+ for (const entry of selected) {
960
+ const currentPin = installedCompanionVersion(entry.name)
961
+ const resolved = queryDistTagLatest(entry.name, { cwd: profileDir, env: process.env })
962
+ if (resolved === null && currentPin === undefined &&
963
+ Object.prototype.hasOwnProperty.call(manifest.dependencies ?? {}, entry.name)) {
964
+ // A previous add left the dependency behind but never mounted the
965
+ // package. Offline there is no way to heal it: drop the stale declaration
966
+ // instead of handing step [5/8] an unrecoverable hard fail.
967
+ dropUnmountedCompanions('declared but not installed, and offline', [entry.name])
968
+ note(`companion ${entry.name}: skip (offline-stale)`)
969
+ unavailable++
970
+ continue
971
+ }
972
+ const decision = decideCompanionInstall({
973
+ packageName: entry.name,
974
+ declaredRange: entry.declaredRange,
975
+ resolved,
976
+ currentPin,
977
+ })
978
+ if (decision.action === 'skip') {
979
+ note(`companion ${entry.name}: skip (${decision.reason})`)
980
+ } else {
981
+ note(`companion ${entry.name}: ${currentPin ?? 'absent'} -> ${decision.spec} (${decision.reason})`)
982
+ specs.push(decision.spec)
983
+ }
984
+ }
985
+
986
+ if (specs.length === 0) {
987
+ say(4, 'companions', unavailable > 0
988
+ ? `skipped ${unavailable} of ${selected.length} (unavailable)`
989
+ : `already satisfied (${selected.length}/${selected.length})`)
990
+ return
991
+ }
992
+
993
+ if (!dshOnPath()) {
994
+ // Companions are optional: a missing host CLI is a WARN, never a boot
995
+ // blocker. Give an actionable next step and leave a usable profile.
996
+ warn(
997
+ `no global \`dsh\` on PATH; skipping optional companions. ` +
998
+ `Install dsh and re-run provisioning to auto-install them, or set ${COMPANION_LATEST_ENV}=off to skip them permanently.`,
999
+ )
1000
+ // A previous failed add may have left a half-written declaration. Drop it
1001
+ // so step [5/8] never blocks a boot over a package we cannot install here.
1002
+ dropUnmountedCompanions('no global dsh on PATH')
1003
+ say(4, 'companions', 'skipped (no global `dsh` on PATH; companions are optional)')
1004
+ return
1005
+ }
1006
+ const run = spawnSync('dsh', ['plugin', '--profile', PROFILE, 'add', ...specs], {
1007
+ stdio: 'inherit',
1008
+ env: { ...process.env, DSH_HOME: dshHome },
1009
+ cwd: profileDir,
1010
+ timeout: COMPANION_INSTALL_TIMEOUT_MS,
1011
+ })
1012
+ if (run.error) {
1013
+ warn(`companion install failed to start: ${run.error.message}`)
1014
+ dropUnmountedCompanions('install failed to start')
1015
+ say(4, 'companions', `installed 0 of ${specs.length} (failed to start)`)
1016
+ return
1017
+ }
1018
+ if (run.status !== 0) {
1019
+ warn(`dsh plugin add exited ${run.status}; companions are optional — the client still launches`)
1020
+ dropUnmountedCompanions(`dsh plugin add exited ${run.status}`)
1021
+ say(4, 'companions', `installed 0 of ${specs.length} (exit ${run.status})`)
1022
+ return
1023
+ }
1024
+
1025
+ // Readback: an exit 0 is not proof the requested versions landed.
1026
+ const landed = specs.filter((spec) => {
1027
+ const at = spec.lastIndexOf('@')
1028
+ const name = spec.slice(0, at)
1029
+ const pin = spec.slice(at + 1)
1030
+ const actual = installedCompanionVersion(name)
1031
+ return pin === 'latest' ? actual !== undefined : actual === pin
1032
+ })
1033
+ if (landed.length !== specs.length) {
1034
+ const missing = specs.filter((spec) => !landed.includes(spec))
1035
+ warn(`companion version readback mismatch: ${missing.join(', ')}`)
1036
+ dropUnmountedCompanions('version readback mismatch')
1037
+ }
1038
+ say(4, 'companions', `installed ${landed.length} of ${specs.length}`)
1039
+ }
1040
+
1041
+ /**
1042
+ * Step [5/8] cross-check: the companion state has three views — manifest
1043
+ * dependencies, manifest bundles and installed node_modules. A provisioning
1044
+ * pass that updated only one of them is a "two-state drift"; refuse to boot
1045
+ * rather than booting a profile that composes a bundle it cannot resolve.
1046
+ * Only catalog packages are considered, so a user's own dependencies are
1047
+ * never touched or judged here.
1048
+ */
1049
+ function verifyCompanionState() {
1050
+ const manifest = readManifest()
1051
+ if (!manifest) return 0
1052
+ const dependencies = manifest.dependencies ?? {}
1053
+ const bundles = manifest.dsh?.profile?.bundles ?? []
1054
+ const declared = COMPANIONS.filter((entry) =>
1055
+ Object.prototype.hasOwnProperty.call(dependencies, entry.name))
1056
+ for (const entry of declared) {
1057
+ if (!bundles.includes(entry.name)) {
1058
+ fail(
1059
+ `companion drift: ${entry.name} is a dependency but not a profile bundle`,
1060
+ `Re-run provisioning (dsh-opentui --repair-bridge) to restore the bundle entry. ` +
1061
+ `Set ${COMPANION_LATEST_ENV}=off only when you intend to manage companions yourself.`,
1062
+ )
1063
+ }
1064
+ if (installedCompanionVersion(entry.name) === undefined) {
1065
+ fail(
1066
+ `companion drift: ${entry.name} is declared but not installed in the profile`,
1067
+ `Re-run provisioning (dsh-opentui --repair-bridge), or remove the dependency from ${manifestPath} ` +
1068
+ `if the companion is no longer wanted.`,
1069
+ )
1070
+ }
1071
+ }
1072
+ return declared.length
1073
+ }
1074
+
818
1075
  function linkState(path) {
819
1076
  let lst
820
1077
  try {
@@ -923,7 +1180,7 @@ function verifyBridgeIdentity() {
923
1180
  )
924
1181
  }
925
1182
 
926
- say(5, 'identity', `name=${fp.name} version=${fp.version} sha256=${fp.sha256.slice(0, 12)}…`)
1183
+ say(6, 'identity', `name=${fp.name} version=${fp.version} sha256=${fp.sha256.slice(0, 12)}…`)
927
1184
  note(`bridge identity OK — ${resolved}`)
928
1185
  }
929
1186
 
@@ -1001,7 +1258,7 @@ function provisionPatch() {
1001
1258
 
1002
1259
  const localRevision = readPatchRevision(current)
1003
1260
  if (current === PATCH_CONTENT && localRevision === PATCH_REVISION) {
1004
- say(6, 'patch', 'already current, skipping')
1261
+ say(7, 'patch', 'already current, skipping')
1005
1262
  return
1006
1263
  }
1007
1264
 
@@ -1018,7 +1275,7 @@ function provisionPatch() {
1018
1275
  const tmpPath = `${patchPath}.tmp-${process.pid}-${Date.now()}`
1019
1276
  writeFileSync(tmpPath, PATCH_CONTENT)
1020
1277
  renameSync(tmpPath, patchPath)
1021
- say(6, 'patch', `wrote ${patchPath} (profileRevision ${PATCH_REVISION})`)
1278
+ say(7, 'patch', `wrote ${patchPath} (profileRevision ${PATCH_REVISION})`)
1022
1279
  }
1023
1280
 
1024
1281
  // --- Standalone sessionController shim ownership ---------------------------
@@ -1066,10 +1323,10 @@ function provisionShim() {
1066
1323
  const indexChanged = convergeShimFile(SHIM_INDEX_PATH, SHIM_INDEX_CONTENT, 'session controller shim index.mjs', SHIM_REVISION)
1067
1324
  const pkgChanged = convergeShimFile(SHIM_PKG_PATH, SHIM_PKG_CONTENT, 'session controller shim package.json', undefined)
1068
1325
  if (!indexChanged && !pkgChanged) {
1069
- say(7, 'shim', 'already current, skipping')
1326
+ say(8, 'shim', 'already current, skipping')
1070
1327
  return
1071
1328
  }
1072
- say(7, 'shim', `wrote ${SHIM_DIR} (shimRevision ${SHIM_REVISION})`)
1329
+ say(8, 'shim', `wrote ${SHIM_DIR} (shimRevision ${SHIM_REVISION})`)
1073
1330
  }
1074
1331
 
1075
1332
  // --- The provision pass itself (runs under the lock) ------------------------
@@ -1096,12 +1353,12 @@ function runProvision({ repair = false } = {}) {
1096
1353
  // or symlinked-in path that could drift with cwd or a moved install.
1097
1354
  const bridgeDir = realpathSync(bridgeDirRaw)
1098
1355
 
1099
- // [1/7] Host compatibility: fail loud when the running dsh is outside the
1356
+ // [1/8] Host compatibility: fail loud when the running dsh is outside the
1100
1357
  // supported window (the host would otherwise skip the bridge silently), and
1101
1358
  // grant the exact-version exemption when it is in-window but not exempted.
1102
1359
  verifyHostCompatibility(bridgeDir)
1103
1360
 
1104
- // [2/7] Manifest: write / converge the profile manifest. Only
1361
+ // [2/8] Manifest: write / converge the profile manifest. Only
1105
1362
  // dsh.profile.bundles is managed; every other field is preserved.
1106
1363
  {
1107
1364
  const existing = existsSync(manifestPath) ? readManifest() : undefined
@@ -1123,11 +1380,11 @@ function runProvision({ repair = false } = {}) {
1123
1380
  const tmpPath = `${manifestPath}.tmp-${process.pid}-${Date.now()}`
1124
1381
  writeFileSync(tmpPath, `${JSON.stringify(desired, null, 2)}\n`)
1125
1382
  renameSync(tmpPath, manifestPath)
1126
- say(2, 'manifest', `wrote bundles [${BUNDLES.join(', ')}]`)
1383
+ say(2, 'manifest', `wrote bundles [${managedBundles(existing ?? {}).join(', ')}]`)
1127
1384
  }
1128
1385
  }
1129
1386
 
1130
- // [3/7] Materialize the bridge as a REAL DIRECTORY COPY (S6 symlink-debt
1387
+ // [3/8] Materialize the bridge as a REAL DIRECTORY COPY (S6 symlink-debt
1131
1388
  // retirement). The old design wrote an ABSOLUTE symlink to THIS
1132
1389
  // installation's dist/bridge: that bound the profile to one install path and
1133
1390
  // let multiple worktrees sharing a DSH_HOME leave the link pointing at
@@ -1157,8 +1414,13 @@ function runProvision({ repair = false } = {}) {
1157
1414
  }
1158
1415
  }
1159
1416
 
1160
- // [4/7] Verify: linkPath is a REAL directory (never a symlink) carrying the
1417
+ // [4/8] Companion installation. Runs after the bridge copy and before the
1418
+ // verify step so a half-provisioned manifest is caught by step [5/8].
1419
+ provisionCompanions()
1420
+
1421
+ // [5/8] Verify: linkPath is a REAL directory (never a symlink) carrying the
1161
1422
  // shipped bridge files, and no @deepseek-ai package leaked into the profile.
1423
+ // Companion state is cross-checked too (deps <-> bundles <-> node_modules).
1162
1424
  {
1163
1425
  let st
1164
1426
  try { st = lstatSync(linkPath) } catch (error) { fail(`post-write verification failed for ${linkPath}: ${error?.message ?? error}`) }
@@ -1178,14 +1440,15 @@ function runProvision({ repair = false } = {}) {
1178
1440
  'The host closure supplies @deepseek-ai/* bundles; they must never be copied into a profile directory.',
1179
1441
  )
1180
1442
  }
1181
- say(4, 'verify', `bridge resolves to ${bridgeDir}; no @deepseek-ai copy in profile`)
1443
+ const companionCount = verifyCompanionState()
1444
+ say(5, 'verify', `bridge resolves to ${bridgeDir}; no @deepseek-ai copy in profile; ${companionCount} companion(s) consistent`)
1182
1445
  }
1183
1446
 
1184
- // [5/7] Identity guard always runs, including on the conflict path, so a
1447
+ // [6/8] Identity guard always runs, including on the conflict path, so a
1185
1448
  // repointed / replaced bridge cannot slip through as a mere WARN.
1186
1449
  verifyBridgeIdentity()
1187
1450
 
1188
- // [6/7] Inproc patch generation + [7/7] the local shim package the patch row
1451
+ // [7/8] Inproc patch generation + [8/8] the local shim package the patch row
1189
1452
  // resolves. S6: unconditional (no env escape hatch).
1190
1453
  provisionPatch()
1191
1454
  provisionShim()