windows-shell.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * The Windows shell platform layer: on win32 hosts the shipped profile
  3. * compositions swap the POSIX-only bash stack for the sandbox-confined
  4. * PowerShell stack (`@deepseek-ai/dsh-pwsh-sandbox` +
  5. * `@deepseek-ai/dsh-tool-pwsh`). The layer is the base bundle's
  6. * `windows.cordis.patch.yml`, injected by the launcher between the bundle
  7. * layers and the user layers so a user patch can still override it — the
  8. * only override channel is composition config, like every other roster
  9. * decision. POSIX hosts never receive the layer.
  10. * @module @deepseek-ai/dsh/windows-shell
  11. */
  12. import { join } from 'node:path'
  13. import type { PatchOptions } from '@deepseek-ai/cordis-plugin-include'
  14. import { loadOverlayPatches, type ProfileLayer } from '@deepseek-ai/dsh-app-boot'
  15. /** The base bundle whose package carries the Windows shell patch. */
  16. export const BASE_BUNDLE = '@deepseek-ai/dsh-base'
  17. /** The Windows shell patch filename inside the base bundle package. */
  18. export const WINDOWS_SHELL_PATCH_FILENAME = 'windows.cordis.patch.yml'
  19. /** One Windows shell platform layer: its patch file and parsed patches. */
  20. export interface WindowsShellLayer {
  21. /** The patch file path, used as the config-dump provenance label. */
  22. label: string
  23. /** The parsed patch entries, applied after the bundle layers. */
  24. patches: PatchOptions[]
  25. }
  26. /**
  27. * Resolve the Windows shell platform layer for a profile composition.
  28. * @param platform - the host platform (`process.platform` at call sites).
  29. * @param layers - the profile's bundle layers, in application order.
  30. * @param binName - the diagnostic prefix on thrown errors (`dsh`).
  31. * @returns the pwsh layer on win32, else `undefined`. A custom profile that
  32. * mounts no base bundle is skipped (it owns its shell stack); a base
  33. * bundle whose Windows shell patch is missing fails loud in
  34. * {@link loadOverlayPatches} — the shipped package always carries it, so
  35. * a miss is a broken installation.
  36. */
  37. export function resolveWindowsShellLayer(
  38. platform: NodeJS.Platform,
  39. layers: readonly ProfileLayer[],
  40. binName: string,
  41. ): WindowsShellLayer | undefined {
  42. if (platform !== 'win32') return undefined
  43. const base = layers.find(layer => layer.packageName === BASE_BUNDLE)
  44. if (base === undefined) return undefined
  45. const label = join(base.packageDir, WINDOWS_SHELL_PATCH_FILENAME)
  46. return { label, patches: loadOverlayPatches(binName, label) }
  47. }