| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /** Launcher-owned profile locations and composition inputs. */
- import { join } from 'node:path'
- import { composeEntries, loadProfileDirectory, PROFILE_PATCH_FILENAME, type Profile } from './profile.ts'
- import { loadOptionalPatches } from './index.ts'
- import type { PatchOptions } from '@deepseek-ai/cordis-plugin-include'
- /** Current profile facts; scheduling and mutation belong to their callers. */
- export interface ProfileContext {
- readonly name: string
- readonly dir: string
- readonly patchPath: string
- readonly installAnchor: string
- readonly cwd: string
- readonly home: string
- /** Bundle packages used to start this process, before any persisted edits. */
- readonly startedBundles: readonly string[]
- /** Parsed command-line overlays, applied above profile and home patches. */
- readonly overlays: readonly PatchOptions[]
- /** Launch-time DSH_TELEMETRY_DISABLED value; any non-empty value opts out. */
- readonly telemetryDisabledEnv: string | undefined
- }
- declare module '@deepseek-ai/cordis' {
- interface Context {
- /** Present only in a profile launched by dsh. */
- profileContext: ProfileContext
- }
- }
- const TELEMETRY_ROW_ID = 'session-telemetry-otel'
- /**
- * Resolve the telemetry opt-out switch into its boot patch. ANY non-empty
- * value (including `'0'`/`'false'`) disables: a privacy switch prefers
- * off-by-mistake over on-by-mistake. A composition without the telemetry row
- * exports nothing, so the switch is then trivially satisfied and no patch is
- * generated — custom profiles need not mount telemetry to run with the
- * switch set.
- * @param disabledEnv - the raw `DSH_TELEMETRY_DISABLED` value (`undefined` when unset).
- * @param hasRow - whether the composition carries the telemetry row.
- * @returns the disable patch, or `undefined` when no hard-disable patch is required.
- */
- export function resolveTelemetryPatch(disabledEnv: string | undefined, hasRow: boolean): PatchOptions | undefined {
- if ((disabledEnv ?? '') === '' || !hasRow) return undefined
- return { id: TELEMETRY_ROW_ID, disabled: true }
- }
- /** Read current bundle and user layers with the launch-time overlays.
- * @param binName Diagnostic prefix for malformed or missing configuration.
- * @param context Data supplied by the profile launcher.
- * @param initialProfile Already loaded startup profile; omitted reads the current files.
- * @returns Detached ordered patches; this function does not update the Loader.
- */
- export function readProfilePatches(binName: string, context: ProfileContext, initialProfile?: Profile): PatchOptions[] {
- const profile = initialProfile ?? loadProfileDirectory(binName, context.dir, context.installAnchor, { userLayer: false })
- const patches = structuredClone([
- ...profile.layers.flatMap(layer => layer.patches),
- ...(initialProfile?.patches ?? loadOptionalPatches(binName, context.patchPath) ?? []),
- ...(loadOptionalPatches(binName, join(context.home, PROFILE_PATCH_FILENAME)) ?? []),
- ...context.overlays,
- ])
- const telemetryPatch = resolveTelemetryPatch(context.telemetryDisabledEnv,
- composeEntries([patches]).some(row => row.id === TELEMETRY_ROW_ID))
- if (telemetryPatch !== undefined) patches.push(telemetryPatch)
- return patches
- }
|