@aiwayds/dsh-opentui 0.23.3 → 0.24.0

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": "@aiwayds/dsh-opentui",
3
- "version": "0.23.3",
3
+ "version": "0.24.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -4,7 +4,6 @@
4
4
 
5
5
  export declare const BRIDGE_REPAIR_COMMAND: string
6
6
  export declare const BRIDGE_APPEND_PRESET_NOTICE: string
7
- export declare const BRIDGE_LEGACY_REMOTE_HINT: string
8
7
  export declare const BRIDGE_REPAIR_HINT: string
9
8
 
10
9
  export declare function formatBridgeFailFastMessage(
@@ -34,15 +34,10 @@ export const BRIDGE_REPAIR_COMMAND = 'dsh-opentui --repair-bridge'
34
34
  export const BRIDGE_APPEND_PRESET_NOTICE =
35
35
  'inproc bridge mode injects append-system via the bridge section; presets are standard only.'
36
36
 
37
- /** The escape-hatch line carried by EVERY bridge failure: a launch-level opt
38
- * out of the default inproc bridge back to the legacy remote thin client. Kept
39
- * as its own constant so the host gate and the shared repair hint cannot drift. */
40
- export const BRIDGE_LEGACY_REMOTE_HINT =
41
- 'To keep the legacy remote thin client for this launch: DSH_OPENTUI_INPROC=0'
42
-
43
- /** The repair element with the link-vs-content caveat (provision-script wording). */
37
+ /** The repair element with the link-vs-content caveat (provision-script wording).
38
+ * S6: the legacy escape-hatch hint is gone with the seam it selected. */
44
39
  export const BRIDGE_REPAIR_HINT =
45
- `Run \`${BRIDGE_REPAIR_COMMAND}\` to rebuild the bridge symlink / manifest (it fixes links, not corrupted artifact contents).\n${BRIDGE_LEGACY_REMOTE_HINT}`
40
+ `Run \`${BRIDGE_REPAIR_COMMAND}\` to rebuild the bridge manifest (it fixes links, not corrupted artifact contents).`
46
41
 
47
42
  /**
48
43
  * Compose the three elements into one copy-pasteable, self-contained message.
@@ -3,9 +3,9 @@
3
3
  // `opentui-inproc` host profile (ADR-0009 decision 3; T3 of the in-process
4
4
  // bridge plan).
5
5
  //
6
- // Invoked by the launcher on EVERY start since 0.23.0 (bridge is the default);
7
- // only DSH_OPENTUI_INPROC=0 skips it (legacy `opentui` remote thin-client path).
8
- // The default `opentui` profile path is otherwise untouched.
6
+ // Invoked by the launcher on EVERY start (S6: bridge is the sole seam; the
7
+ // former env escape hatch that skipped provisioning is removed with it).
8
+ // The `opentui` profile path is otherwise untouched.
9
9
  // Seven local-FS steps (the first is the host-version gate), no pnpm/npm, no install scripts:
10
10
  //
11
11
  // [1/7] host — detect the running dsh version. OUTSIDE the supported
@@ -24,26 +24,27 @@
24
24
  // resolution supplies those bundles from the running dsh
25
25
  // closure (wild-package shadowing is the historical
26
26
  // incident this guard prevents).
27
- // [3/7] symlink — create node_modules/@aiwayds/dsh-opentui-bridge as an
28
- // ABSOLUTE symlink to THIS installation's dist/bridge
29
- // (realpath). No link:/file: protocol, no copying.
30
- // [4/7] verify — re-read the link and confirm it resolves to dist/bridge;
31
- // refuse any @deepseek-ai copy in the profile.
32
- // [5/7] identity — T5 guard: hash the RESOLVED bridge's index.js and compare
33
- // with the build-time fingerprint shipped in THIS
27
+ // [3/7] copy — materialize node_modules/@aiwayds/dsh-opentui-bridge as a
28
+ // REAL DIRECTORY COPY of THIS installation's dist/bridge.
29
+ // S6 symlink-debt retirement: no absolute symlink (no path
30
+ // binding, no multi-worktree last-writer-wins, no dangling
31
+ // link when a worktree is removed). Converged every launch;
32
+ // 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
36
+ // compare with the build-time fingerprint shipped in THIS
34
37
  // installation's dist/bridge/bundle-fingerprint.json, plus
35
38
  // name / version. No realpath-prefix hard binding.
36
- // [6/7] patch — skipped ONLY by the DSH_OPENTUI_INPROC=0 escape hatch:
37
- // generate $DSH_HOME/profiles/opentui-inproc/cordis.patch.yml
39
+ // [6/7] patch — generate $DSH_HOME/profiles/opentui-inproc/cordis.patch.yml
38
40
  // from the embedded inproc-only template (web-app
39
41
  // compensation rows removed, profileRevision stamped). The
40
42
  // template also registers the standalone sessionController
41
43
  // shim plus the real @deepseek-ai/dsh-api-session-controller
42
- // plugin — no dsh-web-app bundle is pulled in. The escape
43
- // hatch skips this step entirely.
44
- // [7/7] shim — skipped ONLY by DSH_OPENTUI_INPROC=0: generate the local
45
- // shim package under the profile's node_modules (@aiwayds
46
- // scope) that the patch row above resolves. Its
44
+ // plugin — no dsh-web-app bundle is pulled in.
45
+ // [7/7] shim — generate the local shim package under the profile's
46
+ // node_modules (@aiwayds scope) that the patch row resolves.
47
+ // Its
47
48
  // @deepseek-ai/cordis import is resolved by the host against
48
49
  // the profile scope, exactly like the bridge. revision +
49
50
  // backup converge it.
@@ -56,18 +57,14 @@
56
57
  // taken over. The lock is released in `finally`, including on failure.
57
58
  // Same-machine only: no cross-host / cross-user semantics.
58
59
  //
59
- // Idempotency: an existing symlink that resolves to the exact expected target
60
- // is left untouched. An existing entry that points somewhere else is NOT
61
- // overwritten: a conflict is reported (the identity guard below still runs
62
- // and decides whether the resolved artifact is acceptable).
60
+ // Idempotency: an existing bridge directory whose index.js hash matches THIS
61
+ // install's build-time fingerprint is left untouched; a stale directory, a
62
+ // leftover symlink, or a missing entry is replaced with a fresh copy.
63
63
  //
64
- // T7 — repair mode (`--repair`, invoked by `dsh-opentui --repair-bridge`):
65
- // In the normal path the conflict above is report-only. With --repair the
66
- // SAME lock and the SAME pass are used, but a wrong symlink target (or a
67
- // non-symlink entry) is replaced with the absolute link to this install's
68
- // dist/bridge; a missing / wrong manifest is still converged as usual. The
69
- // T5 identity guard runs afterwards either way — repair fixes the LINK,
70
- // never the artifact CONTENT, so a fingerprint mismatch still fails.
64
+ // `--repair` / `--repair-bridge`: still accepted for CLI/caller compatibility,
65
+ // but a no-op for the bridge materialization — the copy converges
66
+ // unconditionally on every provision. The T5 identity guard always runs after
67
+ // convergence, so a fingerprint mismatch still fails loud.
71
68
  //
72
69
  // Hard guard: this script only ever touches the ONE profile named
73
70
  // `opentui-inproc`. It never runs a package manager and never writes a
@@ -76,6 +73,7 @@
76
73
  import { createHash } from 'node:crypto'
77
74
  import {
78
75
  closeSync,
76
+ cpSync,
79
77
  existsSync,
80
78
  lstatSync,
81
79
  mkdirSync,
@@ -86,7 +84,6 @@ import {
86
84
  renameSync,
87
85
  rmSync,
88
86
  statSync,
89
- symlinkSync,
90
87
  unlinkSync,
91
88
  writeFileSync,
92
89
  writeSync,
@@ -99,7 +96,6 @@ import { fileURLToPath } from 'node:url'
99
96
  // BridgeBootstrapError (handshake) now carry the same three elements.
100
97
  import {
101
98
  BRIDGE_APPEND_PRESET_NOTICE,
102
- BRIDGE_LEGACY_REMOTE_HINT,
103
99
  BRIDGE_REPAIR_HINT,
104
100
  } from './lib/bridge-failfast-text.mjs'
105
101
  // Host-version gate. The host only records an incompatible profile bundle in
@@ -125,7 +121,10 @@ const LOCK_RETRY_MS = 25 // backoff between attempts while a peer holds the lock
125
121
  const LOCK_MAX_ATTEMPTS = 40 // <= ~1s of waiting before a peer is skipped
126
122
 
127
123
  const pkgRoot = dirname(dirname(fileURLToPath(import.meta.url)))
128
- const bridgeDirRaw = join(pkgRoot, 'dist', 'bridge')
124
+ // Testability seam: the fail-fast tests point this at a bogus bridge dir to
125
+ // drive the fingerprint-mismatch path without mutating the real build artifact.
126
+ // Unset in production (the shipped dist/bridge is authoritative).
127
+ const bridgeDirRaw = process.env.DSH_OPENTUI_TEST_BRIDGE_DIR || join(pkgRoot, 'dist', 'bridge')
129
128
  const fingerprintPath = join(bridgeDirRaw, 'bundle-fingerprint.json')
130
129
 
131
130
  const dshHome = process.env.DSH_HOME || join(homedir(), '.dsh')
@@ -134,13 +133,11 @@ const manifestPath = join(profileDir, 'package.json')
134
133
  const linkPath = join(profileDir, 'node_modules', ...BRIDGE_NAME.split('/'))
135
134
  const lockPath = join(profileDir, LOCK_NAME)
136
135
 
137
- // --- Inproc patch ownership (escape hatch: DSH_OPENTUI_INPROC=0) ------------
138
- // Bridge is the default since 0.23.0: the launcher runs this script on every
139
- // start, so the patch/shim steps are ON unless the explicit escape hatch
140
- // DSH_OPENTUI_INPROC=0 is set. "1" stays valid (idempotent); --repair-bridge
141
- // and direct invocation now converge on the same full-inproc output.
142
- const INPROC_MODE = process.env.DSH_OPENTUI_INPROC !== '0'
143
- const TOTAL_STEPS = INPROC_MODE ? 7 : 5
136
+ // --- Inproc patch ownership ------------------------------------------------
137
+ // S6: the patch/shim steps are unconditional (the env escape hatch that used
138
+ // to skip them is removed with the legacy seam). The launcher runs this script
139
+ // on every start; --repair-bridge and direct invocation converge identically.
140
+ const TOTAL_STEPS = 7
144
141
  const PATCH_NAME = 'cordis.patch.yml'
145
142
  const patchPath = join(profileDir, PATCH_NAME)
146
143
  const PATCH_REVISION_MARKER = '# profileRevision: '
@@ -840,8 +837,21 @@ function linkState(path) {
840
837
  return { kind: 'symlink', raw, abs, resolved }
841
838
  }
842
839
 
840
+ /** True when `dir` is an up-to-date copy of this install's bridge: its
841
+ * index.js sha256 matches the build-time fingerprint. Used to make the
842
+ * bridge-copy materialization idempotent across launches/worktrees. */
843
+ function stateIsCurrentCopy(dir, fingerprintFile) {
844
+ try {
845
+ const fp = readJsonObject(fingerprintFile)
846
+ if (!fp || typeof fp.sha256 !== 'string') return false
847
+ return sha256File(join(dir, 'index.js')) === fp.sha256
848
+ } catch {
849
+ return false
850
+ }
851
+ }
852
+
843
853
  /** Remove whatever occupies `path` (symlink, file or directory) so the correct
844
- * symlink can be created in its place. Repair mode only; ENOENT is a no-op. */
854
+ * copy can be created in its place. ENOENT is a no-op. */
845
855
  function removePath(path) {
846
856
  let st
847
857
  try {
@@ -929,7 +939,7 @@ function verifyHostCompatibility(bridgeDir) {
929
939
  } catch (error) {
930
940
  fail(
931
941
  'cannot verify the dsh host version before loading the bridge',
932
- `${error instanceof Error ? error.message : String(error)}\nDetected with \`dsh --version\` (override: ${HOST_VERSION_ENV}=<exact version>).\n${BRIDGE_LEGACY_REMOTE_HINT}`,
942
+ `${error instanceof Error ? error.message : String(error)}\nDetected with \`dsh --version\` (override: ${HOST_VERSION_ENV}=<exact version>).`,
933
943
  )
934
944
  }
935
945
 
@@ -938,8 +948,7 @@ function verifyHostCompatibility(bridgeDir) {
938
948
  `dsh host version is outside the bridge support window — expected ${HOST_PEER_RANGE}, actual ${hostVersion}`,
939
949
  `The host would skip ${BRIDGE_NAME} without a usable error and bridge.hello would time out (BRIDGE_TIMEOUT). `
940
950
  + `Install a dsh host in ${HOST_PEER_RANGE}, or upgrade dsh-opentui. `
941
- + `Detection override: ${HOST_VERSION_ENV}=${process.env[HOST_VERSION_ENV] ?? '(unset)'}.`
942
- + `\n${BRIDGE_LEGACY_REMOTE_HINT}`,
951
+ + `Detection override: ${HOST_VERSION_ENV}=${process.env[HOST_VERSION_ENV] ?? '(unset)'}.`,
943
952
  )
944
953
  }
945
954
 
@@ -1065,7 +1074,9 @@ function provisionShim() {
1065
1074
 
1066
1075
  // --- The provision pass itself (runs under the lock) ------------------------
1067
1076
  function runProvision({ repair = false } = {}) {
1068
- if (repair) note('repair mode — a wrong bridge symlink will be rebuilt (content is never repaired)')
1077
+ // S6: --repair is accepted for CLI compatibility but is a no-op — the bridge
1078
+ // copy converges unconditionally on every provision (no symlink to repair).
1079
+ if (repair) note('repair mode accepted (no-op — bridge copy converges every provision)')
1069
1080
  // Prerequisites (read-only) are checked before any mutation.
1070
1081
  if (!existsSync(bridgeDirRaw) || !statSync(bridgeDirRaw).isDirectory()) {
1071
1082
  fail(
@@ -1116,51 +1127,48 @@ function runProvision({ repair = false } = {}) {
1116
1127
  }
1117
1128
  }
1118
1129
 
1119
- // [3/7] Symlink: create the absolute link, skip when already correct, and
1120
- // ONLY in repair mode replace a wrong target / non-symlink entry. Normal
1121
- // startup stays report-only (a conflict is a WARN, never an overwrite).
1122
- let conflict = null
1130
+ // [3/7] Materialize the bridge as a REAL DIRECTORY COPY (S6 symlink-debt
1131
+ // retirement). The old design wrote an ABSOLUTE symlink to THIS
1132
+ // installation's dist/bridge: that bound the profile to one install path and
1133
+ // let multiple worktrees sharing a DSH_HOME leave the link pointing at
1134
+ // whichever install provisioned last (A's dsh loading B's bundle = cross-
1135
+ // contamination); deleting a worktree left a dangling link → BRIDGE_TIMEOUT.
1136
+ // A copy removes the path binding entirely: every provision converges the
1137
+ // profile copy to THIS install's bytes, and the fingerprint identity guard
1138
+ // below rejects any drift. No symlink, no --repair branch, no conflict
1139
+ // report-only path (the flag is accepted for CLI compatibility but is a
1140
+ // no-op — convergence is unconditional).
1123
1141
  {
1124
1142
  const state = linkState(linkPath)
1125
- if (state.kind === 'absent') {
1126
- mkdirSync(dirname(linkPath), { recursive: true })
1127
- try {
1128
- symlinkSync(bridgeDir, linkPath, 'dir')
1129
- } catch (error) {
1130
- fail(`could not create symlink ${linkPath}: ${error?.message ?? error}`)
1131
- }
1132
- say(3, 'symlink', `created ${linkPath} -> ${bridgeDir}`)
1133
- } else if (state.kind === 'symlink' && (state.resolved === bridgeDir || state.abs === bridgeDir)) {
1134
- say(3, 'symlink', 'already points at the bridge artifact, skipping')
1135
- } else if (repair) {
1136
- const desc = state.kind === 'not-symlink'
1137
- ? `${linkPath} is not a symlink`
1138
- : `${linkPath} -> ${state.raw}`
1139
- note(`repairing bridge link (${desc})`)
1143
+ const isReadyDir = state.kind === 'not-symlink' && stateIsCurrentCopy(linkPath, fingerprintPath)
1144
+ if (!isReadyDir) {
1145
+ const desc = state.kind === 'absent' ? 'absent' : state.kind === 'symlink' ? `symlink -> ${state.raw}` : 'stale directory'
1146
+ note(`materializing bridge copy (${desc})`)
1140
1147
  try {
1141
1148
  removePath(linkPath)
1142
1149
  mkdirSync(dirname(linkPath), { recursive: true })
1143
- symlinkSync(bridgeDir, linkPath, 'dir')
1150
+ cpSync(bridgeDir, linkPath, { recursive: true })
1144
1151
  } catch (error) {
1145
- fail(`could not repair symlink ${linkPath}: ${error?.message ?? error}`)
1152
+ fail(`could not materialize bridge copy at ${linkPath}: ${error?.message ?? error}`)
1146
1153
  }
1147
- say(3, 'symlink', `repaired ${linkPath} -> ${bridgeDir}`)
1148
- } else if (state.kind === 'not-symlink') {
1149
- conflict = `${linkPath} exists and is NOT a symlink`
1154
+ say(3, 'bridge-copy', `copied ${bridgeDir} -> ${linkPath}`)
1150
1155
  } else {
1151
- conflict = `${linkPath} -> ${state.raw} (expected ${bridgeDir})`
1156
+ say(3, 'bridge-copy', `${linkPath} already matches this install, skipping`)
1152
1157
  }
1153
1158
  }
1154
1159
 
1155
- // [4/7] Verify: report-only for a conflict; never overwrite.
1156
- if (conflict !== null) {
1157
- warn(`conflict, not overwriting: ${conflict}`)
1158
- warn('the profile link was left untouched; the identity guard below decides whether the resolved artifact is acceptable')
1159
- console.log(`${PREFIX}REPORT — conflict detected, no change made to the link`)
1160
- } else {
1161
- const finalState = linkState(linkPath)
1162
- if (finalState.kind !== 'symlink' || (finalState.resolved !== bridgeDir && finalState.abs !== bridgeDir)) {
1163
- fail(`post-write verification failed for ${linkPath}: link does not resolve to ${bridgeDir}`)
1160
+ // [4/7] Verify: linkPath is a REAL directory (never a symlink) carrying the
1161
+ // shipped bridge files, and no @deepseek-ai package leaked into the profile.
1162
+ {
1163
+ let st
1164
+ try { st = lstatSync(linkPath) } catch (error) { fail(`post-write verification failed for ${linkPath}: ${error?.message ?? error}`) }
1165
+ if (!st.isDirectory() || st.isSymbolicLink()) {
1166
+ fail(`post-write verification failed for ${linkPath}: bridge is not a real directory`)
1167
+ }
1168
+ for (const required of ['package.json', 'index.js', 'bundle-fingerprint.json']) {
1169
+ if (!existsSync(join(linkPath, required))) {
1170
+ fail(`post-write verification failed: ${linkPath} is missing ${required}`)
1171
+ }
1164
1172
  }
1165
1173
  // Explicit guard: no @deepseek-ai package may be present in the profile.
1166
1174
  const deepseekDir = join(profileDir, 'node_modules', '@deepseek-ai')
@@ -1177,13 +1185,10 @@ function runProvision({ repair = false } = {}) {
1177
1185
  // repointed / replaced bridge cannot slip through as a mere WARN.
1178
1186
  verifyBridgeIdentity()
1179
1187
 
1180
- // [6/7] Inproc-only patch generation. The gate is here (not just in the
1181
- // launcher) so --repair-bridge / direct runs without the env stay unchanged.
1182
- // [7/7] generates the local shim package that the patch row resolves.
1183
- if (INPROC_MODE) {
1184
- provisionPatch()
1185
- provisionShim()
1186
- }
1188
+ // [6/7] Inproc patch generation + [7/7] the local shim package the patch row
1189
+ // resolves. S6: unconditional (no env escape hatch).
1190
+ provisionPatch()
1191
+ provisionShim()
1187
1192
 
1188
1193
  console.log(`${PREFIX}PASS`)
1189
1194
  }