dsh-home-hosted 0.1.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/LICENSE +21 -0
- package/README.md +48 -0
- package/cordis.patch.yml +6 -0
- package/docs/DESIGN.md +114 -0
- package/lib/client.js +9 -0
- package/lib/index.js +3694 -0
- package/lib/index.js.map +7 -0
- package/lib/types/boot/common.d.ts +40 -0
- package/lib/types/boot/escape.d.ts +59 -0
- package/lib/types/boot/fallback.d.ts +10 -0
- package/lib/types/boot/index.d.ts +12 -0
- package/lib/types/boot/ladder.d.ts +4 -0
- package/lib/types/boot/launchd.d.ts +8 -0
- package/lib/types/boot/systemd.d.ts +10 -0
- package/lib/types/boot/types.d.ts +94 -0
- package/lib/types/boot/windows.d.ts +16 -0
- package/lib/types/boot/xdg.d.ts +3 -0
- package/lib/types/config.d.ts +15 -0
- package/lib/types/home-hosted/config-file.d.ts +23 -0
- package/lib/types/home-hosted/dsh-entry.d.ts +22 -0
- package/lib/types/home-hosted/entries.d.ts +20 -0
- package/lib/types/home-hosted/launch.d.ts +25 -0
- package/lib/types/home-hosted/launcher.d.ts +38 -0
- package/lib/types/home-hosted/panel-control.d.ts +34 -0
- package/lib/types/home-hosted/panel.d.ts +44 -0
- package/lib/types/home-hosted/resolve.d.ts +34 -0
- package/lib/types/home-hosted/runtime.d.ts +20 -0
- package/lib/types/home-hosted/token.d.ts +20 -0
- package/lib/types/index.d.ts +15 -0
- package/lib/types/rpc.d.ts +11 -0
- package/lib/types/service.d.ts +125 -0
- package/lib/types/settings.d.ts +13 -0
- package/lib/types/shared/contracts.d.ts +245 -0
- package/lib/types/tools.d.ts +14 -0
- package/lib/types/util/exec.d.ts +29 -0
- package/lib/types/util/fsx.d.ts +9 -0
- package/lib/types/util/paths.d.ts +12 -0
- package/package.json +108 -0
package/lib/index.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/config.ts", "../src/shared/contracts.ts", "../src/service.ts", "../src/boot/ladder.ts", "../src/util/exec.ts", "../src/boot/common.ts", "../src/util/fsx.ts", "../src/boot/systemd.ts", "../src/boot/escape.ts", "../src/boot/launchd.ts", "../src/boot/xdg.ts", "../src/boot/windows.ts", "../src/boot/fallback.ts", "../src/home-hosted/config-file.ts", "../src/util/paths.ts", "../src/home-hosted/dsh-entry.ts", "../src/home-hosted/launch.ts", "../src/home-hosted/entries.ts", "../src/home-hosted/resolve.ts", "../src/home-hosted/launcher.ts", "../src/home-hosted/panel-control.ts", "../src/home-hosted/panel.ts", "../src/home-hosted/runtime.ts", "../src/home-hosted/token.ts", "../src/rpc.ts", "../src/settings.ts", "../src/tools.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * `dsh-home-hosted` \u2014 boot autostart for the home-hosted panel, and home-hosted\n * server management, from inside DeepSeek Harness.\n *\n * The plugin supplies no server entries of its own: everything it manages is\n * declared by the person using the page, and nothing here knows a blessed id\n * beyond the one it is told to treat as the running harness.\n */\nimport type { Context } from '@deepseek-ai/cordis'\nimport path from 'node:path'\nimport { Config } from './config.js'\nimport type { Config as ConfigShape } from './config.js'\nimport { registerRpc } from './rpc.js'\nimport { HomeHostedService } from './service.js'\nimport { SettingsStore } from './settings.js'\nimport { registerAgentTools } from './tools.js'\nimport { ensureDir } from './util/fsx.js'\nimport { homeHostedHome, pluginStateDir } from './util/paths.js'\n\nexport const name = 'dsh-home-hosted'\n\nexport { Config }\n\nexport const inject: string[] = []\n\nexport function apply(ctx: Context, config?: ConfigShape): void {\n const resolved: ConfigShape = {\n stateDir: config?.stateDir,\n homeHostedCommand: config?.homeHostedCommand,\n defaultEntryId: config?.defaultEntryId ?? 'dsh',\n }\n\n const stateDir = pluginStateDir(resolved.stateDir)\n ensureDir(stateDir, 0o700)\n\n const settings = new SettingsStore(path.join(stateDir, 'settings.json'), resolved.defaultEntryId)\n const service = new HomeHostedService(ctx, {\n home: homeHostedHome(),\n stateDir,\n homeHostedCommand: resolved.homeHostedCommand,\n defaultEntryId: resolved.defaultEntryId,\n settings,\n })\n\n registerRpc(ctx, service)\n registerAgentTools(ctx, service, settings)\n\n // Re-assert an enabled boot entry shortly after startup: a node or CLI upgrade\n // moves the paths a unit was written with, and the fix is to rewrite it.\n ctx.effect(() => {\n const timer = setTimeout(() => {\n void service.reconcile().catch(() => {\n // the page reads the resulting status; a failed repair is not a startup failure\n })\n }, 5000)\n return () => clearTimeout(timer)\n }, 'dsh-home-hosted: startup reconcile')\n}\n", "/**\n * The Cordis row configuration: operator overrides only. Everything a person\n * changes in the plugin's own page lives in `settings.json` under the plugin\n * state directory, so the two never fight over the same field.\n */\nimport z from '@deepseek-ai/schemastery'\n\nexport interface Config {\n /** Override the plugin state directory (defaults to `$DSH_HOME/dsh-home-hosted`). */\n stateDir?: string\n /** Override the home-hosted executable used in generated boot entries. */\n homeHostedCommand?: string\n /** The entry this plugin manages for the running harness. */\n defaultEntryId: string\n}\n\nexport const Config: z<Config> = z.object({\n stateDir: z.string().description('Plugin state directory; defaults to $DSH_HOME/dsh-home-hosted'),\n homeHostedCommand: z.string().description('home-hosted executable to put in a generated autostart entry'),\n defaultEntryId: z.string().default('dsh').description('Server entry id used for the running harness'),\n})\n", "/**\n * The one wire contract shared by the host half and the browser half.\n *\n * Nothing here may import a Node builtin: the browser bundle includes this\n * module verbatim.\n */\n\n/** Exact Fetch route registered on DeepSeek Harness's authenticated `/api` channel. */\nexport const RPC_PATH = '/home-hosted'\n\n/** Bumped when a payload shape changes; a mismatch is reported, never guessed at. */\nexport const RPC_VERSION = 1\n\nexport interface RpcError {\n code: string\n message: string\n detail?: unknown\n}\n\nexport type Envelope<T> = { ok: true, value: T } | { ok: false, error: RpcError }\n\n/** Endpoints the browser and the agent tools both speak. */\nexport type RpcEndpoint =\n | 'status'\n | 'servers.list'\n | 'servers.get'\n | 'servers.create'\n | 'servers.update'\n | 'servers.delete'\n | 'servers.start'\n | 'servers.stop'\n | 'servers.restart'\n | 'servers.freePort'\n | 'entries.apply'\n | 'entries.restore'\n | 'boot.install'\n | 'boot.uninstall'\n | 'boot.verify'\n | 'panel.start'\n | 'panel.takeover'\n | 'cli.installGlobal'\n | 'settings.update'\n\n/** A settings write sends only the changed subtree; the host merges group by group. */\nexport interface SettingsPatch {\n autostart?: Partial<PluginSettings['autostart']>\n entries?: PluginSettings['entries']\n agentTools?: Partial<PluginSettings['agentTools']>\n cli?: Partial<PluginSettings['cli']>\n}\n\nexport interface EndpointPayloads {\n 'status': { refresh?: boolean }\n 'servers.list': Record<string, never>\n 'servers.get': { id: string }\n 'servers.create': { entry: ServerEntry }\n 'servers.update': { id: string, patch: ServerEntryPatch }\n 'servers.delete': { id: string }\n 'servers.start': { id: string }\n 'servers.stop': { id: string }\n 'servers.restart': { id: string }\n 'servers.freePort': { id: string }\n 'entries.apply': { intents: EntryIntent[] }\n 'entries.restore': { id: string }\n 'boot.install': { mechanism?: BootMechanism }\n 'boot.uninstall': { mechanism?: BootMechanism }\n 'boot.verify': Record<string, never>\n /** Start the preferred CLI as a detached panel; refused while one already answers. */\n 'panel.start': Record<string, never>\n /** Stop the answering panel and start the preferred copy instead. */\n 'panel.takeover': { force?: boolean }\n /** Install the pinned range as a global CLI, so the `global` preference can use it. */\n 'cli.installGlobal': Record<string, never>\n 'settings.update': { patch: SettingsPatch }\n}\n\nexport interface RpcRequest {\n v: number\n endpoint: RpcEndpoint\n payload?: unknown\n}\n\n// ---------------------------------------------------------------------------\n// Server entries\n// ---------------------------------------------------------------------------\n\nexport type OnPortConflict = 'block' | 'warn' | 'follow' | 'reclaim' | 'kill'\n\n/** Only the fields this plugin reads or writes are typed; the rest is preserved. */\nexport interface ServerEntry {\n id: string\n label?: string\n enabled?: boolean\n autostart?: boolean\n command?: string\n args?: string[]\n cwd?: string\n env?: Record<string, string>\n dataEnvs?: Record<string, string>\n port?: number | null\n bind?: string\n onPortConflict?: OnPortConflict\n stop?: { killPortHolders?: boolean, [key: string]: unknown }\n health?: Record<string, unknown>\n restart?: Record<string, unknown>\n [key: string]: unknown\n}\n\nexport type ServerEntryPatch = Partial<ServerEntry>\n\n/** What the plugin decides about one entry, and the keys it therefore owns. */\nexport interface EntryIntent {\n id: string\n autostart: boolean\n onPortConflict: OnPortConflict\n stopKillPortHolders: boolean\n}\n\n/** Keys an intent owns: a patch touches these and nothing else. */\nexport const OWNED_ENTRY_KEYS = ['autostart', 'onPortConflict', 'stop'] as const\n\nexport interface ServerEntryView {\n id: string\n status: string\n pid: number | null\n url: string | null\n config: ServerEntry\n}\n\nexport interface ManagedEntryStatus {\n intent: EntryIntent\n exists: boolean\n /** True once the plugin has adopted the entry and holds a snapshot of what it was. */\n managed: boolean\n /** Owned keys whose live value differs from the intent. */\n drift: string[]\n live: ServerEntryView | null\n snapshot: ServerEntry | null\n}\n\n// ---------------------------------------------------------------------------\n// Panel\n// ---------------------------------------------------------------------------\n\nexport type TokenState = 'enrolled' | 'present' | 'absent' | 'unknown'\n\nexport interface PanelStatus {\n /** `$HHOSTED_HOME` this plugin resolved, whether or not the panel answers. */\n home: string\n reachable: boolean\n url: string | null\n version: string | null\n pid: number | null\n /** How writes are authenticated right now. */\n writeVia: 'api' | 'file' | 'none'\n token: TokenState\n detail: string\n}\n\n/** Which home-hosted CLI the plugin drives, and where it came from. */\nexport type CliSource = 'config' | 'dependency' | 'path' | 'none'\n\n/** One place a CLI could come from, with the version found there. */\nexport interface CliCandidate {\n source: 'config' | 'dependency' | 'path'\n path: string | null\n version: string | null\n}\n\nexport interface PanelControlResult {\n ok: boolean\n detail: string\n url?: string | null\n version?: string | null\n}\n\nexport interface CliStatus {\n /** `config` (operator override), `dependency` (the pinned copy), `path`, or none. */\n source: CliSource\n path: string | null\n version: string | null\n /** The range the plugin ships in its own dependencies. */\n expectedRange: string\n /** False when the resolved CLI is older than the oldest release this plugin supports. */\n supported: boolean\n /** The stable launcher a boot entry runs instead of a moving node_modules path. */\n launcherPath?: string | null\n /** What the launcher answers right now, as the boot entry would invoke it. */\n launcherVersion?: string | null\n /** Which copy the plugin prefers. */\n prefer?: 'pinned' | 'global'\n /** The plugin's own copy, when it resolves. */\n dependency?: CliCandidate | null\n /** The global install on PATH, when there is one. */\n global?: CliCandidate | null\n detail: string\n}\n\n// ---------------------------------------------------------------------------\n// Boot autostart\n// ---------------------------------------------------------------------------\n\nexport type BootMechanism =\n | 'systemd-user'\n | 'systemd-system'\n | 'xdg-autostart'\n | 'launchd-agent'\n | 'launchd-daemon'\n | 'windows-run'\n | 'windows-task'\n | 'container'\n | 'unsupported'\n\nexport type BootState =\n | 'not-installed'\n | 'installed-disabled'\n | 'enabled-running'\n | 'enabled-failing'\n | 'unsupported'\n\nexport interface BootCandidate {\n mechanism: BootMechanism\n available: boolean\n /** Starts before an interactive login. */\n bootCapable: boolean\n /** This process can drive it without an elevation prompt. */\n privileged: boolean\n reason: string\n}\n\nexport interface BootStatus {\n platform: 'linux' | 'darwin' | 'win32' | 'other'\n mechanism: BootMechanism | null\n recommended: BootMechanism | null\n state: BootState\n bootCapable: boolean\n privileged: boolean\n unitPath: string | null\n /** Exact commands a person can run when this process cannot elevate. */\n commands: string[]\n detail: string\n candidates: BootCandidate[]\n}\n\n// ---------------------------------------------------------------------------\n// Plugin settings (UI-managed, persisted outside the Cordis config)\n// ---------------------------------------------------------------------------\n\nexport type AgentToolName =\n | 'status'\n | 'servers_list'\n | 'servers_start'\n | 'servers_stop'\n | 'servers_restart'\n | 'servers_create'\n | 'servers_update'\n | 'servers_delete'\n | 'autostart_install'\n | 'autostart_uninstall'\n\nexport const AGENT_TOOL_NAMES: readonly AgentToolName[] = [\n 'status',\n 'servers_list',\n 'servers_start',\n 'servers_stop',\n 'servers_restart',\n 'servers_create',\n 'servers_update',\n 'servers_delete',\n 'autostart_install',\n 'autostart_uninstall',\n]\n\n/** Tools that change something; every one of them asks for approval first. */\nexport const MUTATING_AGENT_TOOLS: readonly AgentToolName[] = [\n 'servers_start',\n 'servers_stop',\n 'servers_restart',\n 'servers_create',\n 'servers_update',\n 'servers_delete',\n 'autostart_install',\n 'autostart_uninstall',\n]\n\nexport interface PluginSettings {\n autostart: {\n enabled: boolean\n /** `auto` picks the best available mechanism; an explicit one is honoured only when available. */\n mechanism: 'auto' | BootMechanism\n }\n entries: EntryIntent[]\n agentTools: {\n enabled: boolean\n allow: AgentToolName[]\n }\n cli: {\n /** `pinned` runs the copy this plugin ships; `global` runs the one on PATH. */\n prefer: 'pinned' | 'global'\n }\n}\n\nexport const DEFAULT_SETTINGS: PluginSettings = {\n autostart: { enabled: false, mechanism: 'auto' },\n entries: [],\n agentTools: { enabled: false, allow: ['status', 'servers_list'] },\n cli: { prefer: 'pinned' },\n}\n\nexport interface HomeHostedStatus {\n panel: PanelStatus\n boot: BootStatus\n entries: ManagedEntryStatus[]\n servers: ServerEntryView[]\n settings: PluginSettings\n /** The CLI the plugin drives; absent only from a host older than this field. */\n cli?: CliStatus\n /** Set when the panel could not be reached, so the UI can show a degraded page. */\n lastError: string | null\n}\n", "/**\n * The one implementation behind both surfaces: the browser page and the agent\n * tools call the same endpoints, so they cannot drift apart.\n *\n * Writes prefer the panel API (the store ignores its own writes, so nothing is\n * restarted behind the user's back) and fall back to an atomic config-file write\n * only when the panel is not answering.\n */\nimport { Service, type Context } from '@deepseek-ai/cordis'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { fileURLToPath } from 'node:url'\nimport type { BootMechanism, BootStatus, EntryIntent, HomeHostedStatus, ManagedEntryStatus, PanelControlResult, PanelStatus, RpcEndpoint, ServerEntry, ServerEntryPatch, ServerEntryView } from './shared/contracts.js'\nimport type { BootSpec } from './boot/types.js'\nimport { createBootLadder } from './boot/index.js'\nimport { findEntry, patchEntry, readConfig, upsertEntry, writeConfig } from './home-hosted/config-file.js'\nimport { buildDshEntry, detectProfile, resolveDshLaunch } from './home-hosted/dsh-entry.js'\nimport { ownedDrift, ownedPatch, restorePatch, snapshotOwned } from './home-hosted/entries.js'\nimport { buildHomeHostedBootSpec, homeHostedEnv } from './home-hosted/launch.js'\nimport type { CliResolution } from './home-hosted/resolve.js'\nimport { compareVersions, EXPECTED_RANGE, MIN_KILL_VERSION, MIN_SUPPORTED_VERSION, resolveCli } from './home-hosted/resolve.js'\nimport { preflightLauncher, writeLauncher } from './home-hosted/launcher.js'\nimport type { PanelControlDeps } from './home-hosted/panel-control.js'\nimport { installGlobal, spawnTakeover, startPanel as startPanelProcess } from './home-hosted/panel-control.js'\nimport { PanelClient, verifyToken } from './home-hosted/panel.js'\nimport { readRuntime, probePanel, pidAlive } from './home-hosted/runtime.js'\nimport { apiTokenEnrolled, ensureToken, readStoredToken } from './home-hosted/token.js'\nimport type { SettingsStore } from './settings.js'\nimport { dshHome } from './util/paths.js'\nimport type { RunResult } from './util/exec.js'\nimport { run } from './util/exec.js'\nimport { readJson, writeJsonAtomic } from './util/fsx.js'\n\nconst ENTRY_ID_PATTERN = /^[a-z0-9][a-z0-9_-]*$/\n\n/** This plugin's own package root, used as a search hint for the pinned CLI. */\nfunction pluginRoot(): string | null {\n try {\n return path.dirname(path.dirname(fileURLToPath(import.meta.url)))\n }\n catch {\n return null\n }\n}\n\n/** What a boot install/uninstall answers with; mirrors the boot module's shape. */\nexport interface BootInstallResult {\n ok: boolean\n changed: boolean\n detail: string\n commands: string[]\n needsPrivilege: boolean\n /** Present on install; an uninstall names no mechanism. */\n mechanism?: BootMechanism | null\n status: BootStatus\n}\n\n/** The subset of the boot ladder this service uses. */\nexport interface BootLadderLike {\n status: (spec: BootSpec, mechanism?: BootMechanism) => Promise<BootStatus>\n install: (spec: BootSpec, mechanism?: BootMechanism) => Promise<BootInstallResult>\n uninstall: (spec: BootSpec, mechanism?: BootMechanism) => Promise<BootInstallResult>\n}\n\nexport class HomeHostedError extends Error {\n constructor(message: string, readonly code: string) {\n super(message)\n this.name = 'HomeHostedError'\n }\n}\n\nexport interface HomeHostedServiceOptions {\n home: string\n stateDir: string\n homeHostedCommand?: string\n defaultEntryId: string\n settings: SettingsStore\n /** Test seam: run the home-hosted CLI without spawning it. */\n execCli?: (args: string[], env: Record<string, string | undefined>) => Promise<RunResult>\n /** Test seam: supply the boot ladder instead of probing the real OS. */\n createLadder?: () => BootLadderLike\n}\n\ninterface CachedClient {\n client: PanelClient\n until: number\n}\n\ninterface LiveEntry {\n view: ServerEntryView\n config: ServerEntry\n}\n\nexport class HomeHostedService extends Service {\n private clientCache: CachedClient | null = null\n private tokenDetail = ''\n private readonly snapshotsFile: string\n\n constructor(ctx: Context, private readonly options: HomeHostedServiceOptions) {\n super(ctx, 'homeHosted')\n this.snapshotsFile = path.join(options.stateDir, 'snapshots.json')\n }\n\n // -------------------------------------------------------------------------\n // Facts\n // -------------------------------------------------------------------------\n\n private runtime() {\n return readRuntime(this.options.home)\n }\n\n /** The entry id this very process was started as, when the panel supervises us. */\n selfEntryId(): string | null {\n const id = process.env.HHOSTED_SERVER_ID\n return id !== undefined && id.length > 0 ? id : null\n }\n\n /** What the config's `meta.writtenBy` names: the panel release when we can read it. */\n private writtenBy(): string {\n return this.runtime()?.version ?? 'dsh-home-hosted'\n }\n\n private webServer(): { port: number | null, host: string } {\n const service = this.ctx.get('webServer') as { port?: unknown, host?: unknown } | undefined\n const port = typeof service?.port === 'number' ? service.port : null\n const host = typeof service?.host === 'string' ? service.host : '127.0.0.1'\n return { port, host }\n }\n\n private cliCache: { prefer: 'pinned' | 'global', resolution: CliResolution, launcher: string | null, launcherVersion: string | null, until: number } | null = null\n\n /**\n * Resolve the preferred CLI, refresh the stable launcher a boot entry runs, and\n * preflight that launcher the same way the entry will invoke it.\n */\n private async cli(): Promise<{ resolution: CliResolution, launcher: string | null, launcherVersion: string | null }> {\n const prefer = this.options.settings.get().cli.prefer\n if (this.cliCache !== null && this.cliCache.until > Date.now() && this.cliCache.prefer === prefer)\n return this.cliCache\n const resolution = await resolveCli({ override: this.options.homeHostedCommand, prefer })\n let launcher: string | null = null\n let launcherVersion: string | null = null\n if (resolution.launch !== null) {\n launcher = writeLauncher({\n stateDir: this.options.stateDir,\n dshHome: dshHome(),\n resolvedEntry: resolution.launch.cliEntry ?? resolution.launch.shimPath ?? null,\n resolvedVersion: resolution.status.version,\n pluginRoot: pluginRoot(),\n minVersion: MIN_SUPPORTED_VERSION,\n }).path\n launcherVersion = await preflightLauncher(this.options.stateDir)\n }\n this.cliCache = { prefer, resolution, launcher, launcherVersion, until: Date.now() + 60_000 }\n return this.cliCache\n }\n\n private async panelControlDeps(): Promise<PanelControlDeps> {\n const { resolution } = await this.cli()\n const launch = resolution.launch\n const projectDir = process.env.HHOSTED_PROJECT ?? this.runtime()?.projectDir ?? null\n return {\n launch,\n home: this.options.home,\n projectDir,\n stateDir: this.options.stateDir,\n env: launch === null ? {} : homeHostedEnv({ home: this.options.home, projectDir }, launch),\n }\n }\n\n private async cliExec(args: string[], env: Record<string, string | undefined>) {\n if (this.options.execCli !== undefined)\n return await this.options.execCli(args, env)\n const { resolution } = await this.cli()\n const launch = resolution.launch\n if (launch === null)\n throw new HomeHostedError(resolution.status.detail, 'CLI_NOT_FOUND')\n return await run(launch.program, [...launch.args, ...args], { env, timeoutMs: 30_000 })\n }\n\n // -------------------------------------------------------------------------\n // Panel\n // -------------------------------------------------------------------------\n\n async panelStatus(): Promise<PanelStatus> {\n const runtime = this.runtime()\n const stored = readStoredToken(this.options.stateDir)\n const enrolledOnDisk = apiTokenEnrolled(this.options.home)\n const reachable = runtime !== null && (pidAlive(runtime.pid) || await probePanel(runtime.url))\n const answered = runtime !== null && await probePanel(runtime.url)\n\n const token: PanelStatus['token'] = stored !== null ? 'enrolled' : (enrolledOnDisk ? 'present' : 'absent')\n const writeVia: PanelStatus['writeVia'] = answered && stored !== null ? 'api' : 'file'\n\n return {\n home: this.options.home,\n reachable: answered,\n url: runtime?.url ?? null,\n version: runtime?.version ?? null,\n pid: runtime?.pid ?? null,\n writeVia,\n token,\n detail: answered\n ? (stored !== null\n ? (this.tokenDetail || 'the panel is answering and this plugin holds a token')\n : (enrolledOnDisk\n ? 'the panel is answering, but home-hosted already holds an API token this plugin does not have'\n : 'the panel is answering; a token will be enrolled on the first write'))\n : (runtime === null\n ? 'no run.json: the panel is not running, so entries are written straight to servers.config.json'\n : reachable ? 'the panel process is alive but is not answering' : 'the panel is not running'),\n }\n }\n\n private async tryClient(): Promise<PanelClient | null> {\n if (this.clientCache !== null && this.clientCache.until > Date.now())\n return this.clientCache.client\n const runtime = this.runtime()\n if (runtime === null || !(await probePanel(runtime.url)))\n return null\n\n const ensured = await ensureToken({\n home: this.options.home,\n stateDir: this.options.stateDir,\n exec: (args, env) => this.cliExec(args, env),\n })\n this.tokenDetail = ensured.detail\n if (ensured.token === null)\n return null\n if (!(await verifyToken(runtime.url, ensured.token)))\n return null\n\n const client = new PanelClient({ baseUrl: runtime.url, token: ensured.token })\n this.clientCache = { client, until: Date.now() + 30_000 }\n return client\n }\n\n private async requireClient(): Promise<PanelClient> {\n const client = await this.tryClient()\n if (client === null) {\n const status = await this.panelStatus()\n throw new HomeHostedError(status.detail, 'PANEL_UNAVAILABLE')\n }\n return client\n }\n\n // -------------------------------------------------------------------------\n // Snapshot bookkeeping\n // -------------------------------------------------------------------------\n\n private snapshots(): Record<string, ServerEntry> {\n return readJson<Record<string, ServerEntry>>(this.snapshotsFile) ?? {}\n }\n\n private saveSnapshots(snapshots: Record<string, ServerEntry>): void {\n writeJsonAtomic(this.snapshotsFile, snapshots, 0o600)\n }\n\n // -------------------------------------------------------------------------\n // Entries\n // -------------------------------------------------------------------------\n\n private async liveEntries(): Promise<Map<string, LiveEntry>> {\n const map = new Map<string, LiveEntry>()\n const client = await this.tryClient()\n if (client !== null) {\n try {\n for (const view of await client.listServers())\n map.set(view.id, { view, config: view.config })\n return map\n }\n catch {\n // fall through to the file, which is still the best available truth\n }\n }\n const read = readConfig(this.options.home)\n for (const entry of read.raw?.servers ?? [])\n map.set(entry.id, { view: { id: entry.id, status: 'unknown', pid: null, url: null, config: entry }, config: entry })\n return map\n }\n\n private async createEntry(intent: EntryIntent, patch: ServerEntryPatch, live: ServerEntry | null): Promise<ServerEntry | null> {\n if (intent.id !== this.options.defaultEntryId)\n return null\n const dsh = await resolveDshLaunch()\n const { port, host } = this.webServer()\n const generated = buildDshEntry({\n id: intent.id,\n port,\n host,\n profile: detectProfile(process.argv, process.env),\n dshHome: process.env.DSH_HOME ?? dshHome(),\n launch: dsh,\n })\n return { ...(live ?? generated), ...generated, ...patch }\n }\n\n private async writeOwned(intent: EntryIntent): Promise<void> {\n const live = (await this.liveEntries()).get(intent.id) ?? null\n const snapshots = this.snapshots()\n if (snapshots[intent.id] === undefined) {\n snapshots[intent.id] = live === null ? { id: intent.id } : snapshotOwned(live.config)\n this.saveSnapshots(snapshots)\n }\n\n const patch = ownedPatch(intent, live?.config ?? null)\n const client = await this.tryClient()\n if (client !== null) {\n if (live !== null) {\n await client.updateServer(intent.id, patch)\n return\n }\n const entry = await this.createEntry(intent, patch, null)\n if (entry === null) {\n throw new HomeHostedError(\n `no server \"${intent.id}\" exists; create it first, then this plugin can adopt its autostart and conflict policy`,\n 'ENTRY_MISSING',\n )\n }\n await client.createServer(entry)\n return\n }\n\n const read = readConfig(this.options.home)\n if (read.error !== null)\n throw new HomeHostedError(read.error, 'CONFIG_UNREADABLE')\n let raw = read.raw ?? {}\n if (findEntry(raw, intent.id) !== null) {\n writeConfig(this.options.home, patchEntry(raw, intent.id, patch), this.writtenBy())\n return\n }\n\n const entry = await this.createEntry(intent, patch, null)\n if (entry === null)\n throw new HomeHostedError(`no server \"${intent.id}\" exists in ${this.options.home}/servers.config.json`, 'ENTRY_MISSING')\n\n // While a panel is running, an external write is a real change and a newly\n // added autostart entry would be started at once. Adding it disabled and\n // flipping autostart in a second write makes that a changed definition\n // instead, which only takes effect at that entry's next start.\n if (await this.panelRunning()) {\n writeConfig(this.options.home, upsertEntry(raw, { ...entry, autostart: false }), this.writtenBy())\n raw = readConfig(this.options.home).raw ?? raw\n writeConfig(this.options.home, patchEntry(raw, intent.id, { autostart: intent.autostart }), this.writtenBy())\n return\n }\n\n writeConfig(this.options.home, upsertEntry(raw, entry), this.writtenBy())\n }\n\n private async panelRunning(): Promise<boolean> {\n const runtime = this.runtime()\n return runtime !== null && (pidAlive(runtime.pid) || await probePanel(runtime.url))\n }\n\n /**\n * The version whose schema will parse what we write: the answering panel, or\n * the CLI that will parse it next. `kill` did not exist before 0.6.0, and an\n * older panel refuses to *boot* with it \u2014 so this is checked before any write.\n */\n private async configVersion(): Promise<string | null> {\n const runtime = this.runtime()\n if (runtime !== null && runtime.version !== null && (pidAlive(runtime.pid) || await probePanel(runtime.url)))\n return runtime.version\n const { resolution } = await this.cli()\n return resolution.status.version\n }\n\n private async assertPolicySupported(intent: EntryIntent): Promise<void> {\n if (intent.onPortConflict !== 'kill')\n return\n const version = await this.configVersion()\n if (version === null || compareVersions(version, MIN_KILL_VERSION) >= 0)\n return\n const { resolution } = await this.cli()\n throw new HomeHostedError(\n `the home-hosted that would parse this config is ${version}, which has no \"kill\" policy `\n + `(added in ${MIN_KILL_VERSION}); replace it with ${resolution.status.version ?? 'the pinned copy'} from this page, `\n + 'or set the entry\\'s on-port-conflict policy to block',\n 'KILL_UNSUPPORTED',\n )\n }\n\n private async applyIntents(intents: EntryIntent[]): Promise<ManagedEntryStatus[]> {\n for (const raw of intents) {\n if (!ENTRY_ID_PATTERN.test(raw.id))\n throw new HomeHostedError(`\"${raw.id}\" is not a valid server id`, 'INVALID_ID')\n const intent: EntryIntent = {\n id: raw.id,\n autostart: raw.autostart === true,\n onPortConflict: raw.onPortConflict ?? 'kill',\n stopKillPortHolders: raw.stopKillPortHolders !== false,\n }\n await this.assertPolicySupported(intent)\n await this.writeOwned(intent)\n const current = this.options.settings.get()\n const entries = current.entries.filter(entry => entry.id !== intent.id)\n entries.push(intent)\n this.options.settings.update({ entries })\n }\n return await this.entriesStatus()\n }\n\n private async restoreEntry(id: string): Promise<ManagedEntryStatus[]> {\n const live = (await this.liveEntries()).get(id) ?? null\n if (live === null)\n throw new HomeHostedError(`no server \"${id}\" exists`, 'ENTRY_MISSING')\n const snapshots = this.snapshots()\n // A restore without a snapshot would write schema defaults over the person's\n // own autostart and conflict policy, silently and irreversibly.\n if (snapshots[id] === undefined)\n throw new HomeHostedError(`\"${id}\" was never adopted by this plugin, so there is nothing to restore; adopt it first`, 'NOT_ADOPTED')\n const patch = restorePatch(live.config, snapshots[id] ?? null)\n const client = await this.tryClient()\n if (client !== null)\n await client.updateServer(id, patch)\n else {\n const read = readConfig(this.options.home)\n if (read.error !== null || read.raw === null)\n throw new HomeHostedError(read.error ?? 'the config file is unreadable', 'CONFIG_UNREADABLE')\n writeConfig(this.options.home, patchEntry(read.raw, id, patch), this.writtenBy())\n }\n delete snapshots[id]\n this.saveSnapshots(snapshots)\n const current = this.options.settings.get()\n this.options.settings.update({ entries: current.entries.filter(entry => entry.id !== id) })\n return await this.entriesStatus()\n }\n\n async entriesStatus(): Promise<ManagedEntryStatus[]> {\n const settings = this.options.settings.get()\n const live = await this.liveEntries()\n const snapshots = this.snapshots()\n const ids = new Set<string>([this.options.defaultEntryId, ...settings.entries.map(entry => entry.id)])\n return [...ids].map((id) => {\n const intent = this.options.settings.intentFor(id)\n const entry = live.get(id) ?? null\n return {\n intent,\n exists: entry !== null,\n managed: snapshots[id] !== undefined,\n drift: entry === null ? ['missing entry'] : ownedDrift(entry.config, intent),\n live: entry?.view ?? null,\n snapshot: snapshots[id] ?? null,\n }\n })\n }\n\n // -------------------------------------------------------------------------\n // Boot autostart\n // -------------------------------------------------------------------------\n\n private ladder(): BootLadderLike {\n if (this.options.createLadder !== undefined)\n return this.options.createLadder()\n return createBootLadder({ env: process.env })\n }\n\n private async bootSpec(): Promise<BootSpec | null> {\n const { resolution, launcher } = await this.cli()\n const launch = resolution.launch\n if (launch === null)\n return null\n const runtime = this.runtime()\n const spec = buildHomeHostedBootSpec(\n {\n home: this.options.home,\n projectDir: process.env.HHOSTED_PROJECT ?? runtime?.projectDir ?? null,\n version: runtime?.version ?? null,\n },\n launch,\n { stateDir: this.options.stateDir },\n )\n\n // The entry runs the stable launcher, not the pinned node_modules path: that\n // path carries a version and a peer hash, and moves on the next install.\n if (launcher !== null) {\n const cliArgs = spec.args.slice(launch.args.length)\n if (process.platform === 'win32') {\n spec.command = process.execPath\n spec.args = [launcher, ...cliArgs]\n }\n else {\n spec.command = launcher\n spec.args = cliArgs\n }\n }\n return spec\n }\n\n async bootStatus(mechanism?: BootMechanism): Promise<BootStatus> {\n const platform: BootStatus['platform'] = process.platform === 'linux'\n ? 'linux'\n : process.platform === 'darwin' ? 'darwin' : process.platform === 'win32' ? 'win32' : 'other'\n const spec = await this.bootSpec()\n if (spec === null) {\n return {\n platform,\n mechanism: null,\n recommended: null,\n state: 'unsupported',\n bootCapable: false,\n privileged: false,\n unitPath: null,\n commands: [],\n detail: 'no home-hosted CLI is available, so no boot entry can be generated; install the plugin with its dependencies',\n candidates: [],\n }\n }\n const settings = this.options.settings.get()\n const requested = mechanism ?? (settings.autostart.mechanism === 'auto' ? undefined : settings.autostart.mechanism)\n return await this.ladder().status(spec, requested)\n }\n\n async installBoot(mechanism?: BootMechanism): Promise<{ result: BootInstallResult, status: BootStatus }> {\n const spec = await this.bootSpec()\n if (spec === null)\n throw new HomeHostedError((await this.cli()).resolution.status.detail, 'CLI_NOT_FOUND')\n const result = await this.ladder().install(spec, mechanism)\n if (result.ok) {\n this.options.settings.update({\n autostart: {\n enabled: true,\n mechanism: mechanism ?? result.mechanism ?? this.options.settings.get().autostart.mechanism,\n },\n })\n }\n return { result, status: await this.bootStatus(mechanism) }\n }\n\n async uninstallBoot(mechanism?: BootMechanism): Promise<{ result: BootInstallResult, status: BootStatus }> {\n const spec = await this.bootSpec()\n if (spec === null)\n throw new HomeHostedError((await this.cli()).resolution.status.detail, 'CLI_NOT_FOUND')\n const result = await this.ladder().uninstall(spec, mechanism)\n if (result.ok)\n this.options.settings.update({ autostart: { ...this.options.settings.get().autostart, enabled: false } })\n return { result, status: await this.bootStatus(mechanism) }\n }\n\n // -------------------------------------------------------------------------\n // Panel lifecycle\n // -------------------------------------------------------------------------\n\n /** Out-of-the-box start: run the preferred CLI's `up`, which detaches itself. */\n async startPanelNow(): Promise<PanelControlResult> {\n const { resolution } = await this.cli()\n const deps = await this.panelControlDeps()\n if (deps.launch === null)\n throw new HomeHostedError(resolution.status.detail, 'CLI_NOT_FOUND')\n const runtime = this.runtime()\n if (runtime !== null && await probePanel(runtime.url)) {\n return { ok: true, detail: 'a panel is already answering', url: runtime.url, version: runtime.version }\n }\n const result = await startPanelProcess(deps)\n this.clientCache = null\n return result\n }\n\n /**\n * Replace an answering panel with the preferred copy.\n *\n * That stops the servers the old panel supervises \u2014 this process included \u2014 so\n * the work is handed to a detached helper and the guard demands that this\n * session is an adopted, autostarting entry the new panel will bring back.\n */\n async takeoverPanel(force = false): Promise<PanelControlResult> {\n const { resolution } = await this.cli()\n const deps = await this.panelControlDeps()\n if (deps.launch === null)\n throw new HomeHostedError(resolution.status.detail, 'CLI_NOT_FOUND')\n\n const runtime = this.runtime()\n if (runtime === null || !(await probePanel(runtime.url)))\n return await this.startPanelNow()\n\n if (runtime.version !== null && resolution.status.version !== null && runtime.version === resolution.status.version) {\n return { ok: true, detail: `the answering panel is already ${runtime.version}`, url: runtime.url, version: runtime.version }\n }\n\n if (!force) {\n const id = this.selfEntryId()\n const live = id === null ? null : (await this.liveEntries()).get(id) ?? null\n if (id === null || live === null || live.config.autostart !== true) {\n throw new HomeHostedError(\n 'replacing the panel stops every server it supervises, including this session, and nothing would start it again: '\n + 'adopt this entry with autostart first, or pass force',\n 'TAKEOVER_UNSAFE',\n )\n }\n }\n\n return spawnTakeover(deps, runtime.pid)\n }\n\n /** Install the pinned range globally, so the `global` preference has a copy to run. */\n async installGlobalCli(): Promise<PanelControlResult & { output?: string }> {\n const result = await installGlobal(EXPECTED_RANGE)\n this.cliCache = null\n return { ok: result.ok, detail: result.detail, output: result.output }\n }\n\n /** Re-assert an entry that is already installed: a node or CLI upgrade moves the\n * paths a unit was written with, and the fix is to rewrite it.\n *\n * Never installs one that is not there. Installing is a deliberate act \u2014 it can\n * need root and it makes this machine start something at boot \u2014 so it happens on\n * an explicit click or an approved tool call, not as a side effect of startup.\n */\n async reconcile(): Promise<void> {\n if (!this.options.settings.get().autostart.enabled)\n return\n const status = await this.bootStatus()\n if (status.state !== 'enabled-failing' && status.state !== 'installed-disabled')\n return\n // Belt on top of the probe: a file-backed entry is only repaired when the file\n // is actually there, so a reporting slip can never turn startup into an install.\n const fileBacked = status.mechanism === 'systemd-user'\n || status.mechanism === 'systemd-system'\n || status.mechanism === 'xdg-autostart'\n || status.mechanism === 'launchd-agent'\n || status.mechanism === 'launchd-daemon'\n if (fileBacked && (status.unitPath === null || !fs.existsSync(status.unitPath)))\n return\n try {\n await this.installBoot()\n }\n catch {\n // a failed repair is reported by the status the page reads\n }\n }\n\n // -------------------------------------------------------------------------\n // Status\n // -------------------------------------------------------------------------\n\n async status(): Promise<HomeHostedStatus> {\n // Resolve the client first: enrolling a token changes which write path is\n // available, and the page should see the state after that, not before.\n const client = await this.tryClient()\n const panel = await this.panelStatus()\n const { resolution, launcher, launcherVersion } = await this.cli()\n const cliDetail = resolution.status.detail\n const panelVersion = this.runtime()?.version ?? null\n const cli = {\n ...resolution.status,\n launcherPath: launcher,\n launcherVersion,\n // A panel left running from an older install is the usual reason to see\n // two versions on this page; say so instead of leaving it ambiguous.\n detail: panelVersion !== null && resolution.status.version !== null && panelVersion !== resolution.status.version\n ? `${cliDetail}; the running panel is ${panelVersion}`\n : cliDetail,\n }\n let servers: ServerEntryView[] = []\n let lastError: string | null = null\n if (client !== null) {\n try {\n servers = await client.listServers()\n }\n catch (error) {\n lastError = error instanceof Error ? error.message : String(error)\n }\n }\n else if (panel.reachable) {\n lastError = panel.detail\n }\n\n return {\n panel,\n boot: await this.bootStatus(),\n entries: await this.entriesStatus(),\n servers,\n settings: this.options.settings.get(),\n cli,\n lastError,\n }\n }\n\n // -------------------------------------------------------------------------\n // Endpoint dispatch\n // -------------------------------------------------------------------------\n\n async call(endpoint: RpcEndpoint, payload: unknown): Promise<unknown> {\n const input = (payload ?? {}) as Record<string, unknown>\n switch (endpoint) {\n case 'status':\n return await this.status()\n\n case 'settings.update': {\n const patch = (input.patch ?? {}) as Parameters<SettingsStore['update']>[0]\n this.options.settings.update(patch)\n return await this.status()\n }\n\n case 'servers.list':\n return await (await this.requireClient()).listServers()\n\n case 'servers.get':\n return await (await this.requireClient()).getServer(String(input.id))\n\n case 'servers.create': {\n const entry = input.entry as ServerEntry\n if (typeof entry?.id !== 'string' || !ENTRY_ID_PATTERN.test(entry.id))\n throw new HomeHostedError('a server entry needs an id matching ^[a-z0-9][a-z0-9_-]*$', 'INVALID_ID')\n return await (await this.requireClient()).createServer(entry)\n }\n\n case 'servers.update':\n return await (await this.requireClient()).updateServer(String(input.id), (input.patch ?? {}) as ServerEntryPatch)\n\n case 'servers.delete': {\n const id = String(input.id)\n if (id === this.selfEntryId()) {\n throw new HomeHostedError(\n `\"${id}\" is the entry this very process runs as, and deleting it stops this session; `\n + 'pause it (autostart off) or restore it instead',\n 'SELF_ENTRY',\n )\n }\n await (await this.requireClient()).deleteServer(id)\n return { id }\n }\n\n case 'servers.start':\n await (await this.requireClient()).startServer(String(input.id))\n return await this.entriesStatus()\n\n case 'servers.stop':\n await (await this.requireClient()).stopServer(String(input.id))\n return await this.entriesStatus()\n\n case 'servers.restart':\n await (await this.requireClient()).restartServer(String(input.id))\n return await this.entriesStatus()\n\n case 'servers.freePort':\n return await (await this.requireClient()).freePort(String(input.id))\n\n case 'entries.apply': {\n const intents = Array.isArray(input.intents) ? input.intents as EntryIntent[] : []\n return await this.applyIntents(intents)\n }\n\n case 'entries.restore':\n return await this.restoreEntry(String(input.id))\n\n case 'boot.install':\n return await this.installBoot(input.mechanism as BootMechanism | undefined)\n\n case 'boot.uninstall':\n return await this.uninstallBoot(input.mechanism as BootMechanism | undefined)\n\n case 'boot.verify':\n return await this.bootStatus()\n\n case 'panel.start':\n return await this.startPanelNow()\n\n case 'panel.takeover':\n return await this.takeoverPanel(input.force === true)\n\n case 'cli.installGlobal':\n return await this.installGlobalCli()\n\n default:\n throw new HomeHostedError(`unknown endpoint \"${String(endpoint)}\"`, 'UNKNOWN_ENDPOINT')\n }\n }\n}\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n homeHosted: HomeHostedService\n }\n}\n", "/**\n * The boot ladder: which mechanisms exist on this platform, which one is\n * installed, and which one this process should use. Everything platform\n * specific is inside a provider's `detect()`/`status()`/`install()` \u2014 this file\n * only orders them and never runs at import time.\n */\nimport os from 'node:os'\nimport process from 'node:process'\nimport type { BootCandidate, BootMechanism, BootStatus } from '../shared/contracts.js'\nimport { run as execRun, sudoAvailable } from '../util/exec.js'\nimport type {\n BootActionResult,\n BootLadder,\n BootLadderOptions,\n BootProvider,\n BootProviderContext,\n BootProviderStatus,\n BootSpec,\n} from './types.js'\nimport { errorMessage, failed, isInstalledState } from './common.js'\nimport { createSystemdSystemProvider, createSystemdUserProvider } from './systemd.js'\nimport { createLaunchdAgentProvider, createLaunchdDaemonProvider } from './launchd.js'\nimport { createXdgAutostartProvider } from './xdg.js'\nimport { createWindowsRunProvider, createWindowsTaskProvider } from './windows.js'\nimport { createContainerProvider, createUnsupportedProvider } from './fallback.js'\n\nfunction platformKind(platform: NodeJS.Platform): BootStatus['platform'] {\n if (platform === 'linux' || platform === 'darwin' || platform === 'win32')\n return platform\n return 'other'\n}\n\n/** Ordered by preference within a platform; the terminal providers come last. */\nexport function bootProviders(\n ctx: BootProviderContext,\n platform: NodeJS.Platform = ctx.platform,\n): BootProvider[] {\n const container = createContainerProvider(ctx)\n const unsupported = createUnsupportedProvider(platform)\n switch (platform) {\n case 'linux':\n return [createSystemdUserProvider(ctx), createSystemdSystemProvider(ctx), createXdgAutostartProvider(ctx), container, unsupported]\n case 'darwin':\n return [createLaunchdAgentProvider(ctx), createLaunchdDaemonProvider(ctx), unsupported]\n case 'win32':\n return [createWindowsRunProvider(ctx), createWindowsTaskProvider(ctx), unsupported]\n default:\n return [container, unsupported]\n }\n}\n\nexport function createBootLadder(options: BootLadderOptions = {}): BootLadder {\n const platform = options.platform ?? process.platform\n const isRoot = process.getuid?.() === 0\n const ctx: BootProviderContext = {\n platform,\n home: options.home ?? os.homedir(),\n env: options.env ?? process.env,\n run: options.run ?? execRun,\n sudo: options.sudo ?? (async () => (isRoot ? true : await sudoAvailable())),\n isRoot,\n exists: options.exists,\n }\n const providers = bootProviders(ctx, platform)\n const kind = platformKind(platform)\n\n async function detectAll(): Promise<{ platform: BootStatus['platform'], candidates: BootCandidate[] }> {\n const candidates = await Promise.all(providers.map(async (provider) => {\n try {\n return await provider.detect()\n }\n catch (error) {\n return {\n mechanism: provider.mechanism,\n available: false,\n bootCapable: false,\n privileged: false,\n reason: `detection failed: ${errorMessage(error)}`,\n } satisfies BootCandidate\n }\n }))\n return { platform: kind, candidates }\n }\n\n async function safeStatus(provider: BootProvider, spec: BootSpec): Promise<BootProviderStatus> {\n try {\n return await provider.status(spec)\n }\n catch (error) {\n return { state: 'not-installed', unitPath: null, detail: errorMessage(error), commands: [] }\n }\n }\n\n function recommend(candidates: BootCandidate[]): BootMechanism | null {\n const byMechanism = new Map(candidates.map(candidate => [candidate.mechanism, candidate]))\n const available = providers\n .map(provider => provider.mechanism)\n .filter(mechanism => byMechanism.get(mechanism)?.available === true)\n const bootCapable = available.find(mechanism => mechanism !== 'container' && byMechanism.get(mechanism)?.bootCapable === true)\n if (bootCapable)\n return bootCapable\n // Inside a container no OS entry starts anything, so the honest advice is the restart policy.\n if (available.includes('container'))\n return 'container'\n return available.find(mechanism => mechanism !== 'unsupported')\n ?? available[0]\n ?? null\n }\n\n async function buildStatus(spec: BootSpec, mechanism?: BootMechanism): Promise<BootStatus> {\n const { candidates } = await detectAll()\n const byMechanism = new Map(candidates.map(candidate => [candidate.mechanism, candidate]))\n const statuses = new Map<BootMechanism, BootProviderStatus>()\n for (const [provider, status] of await Promise.all(providers.map(async provider => [provider, await safeStatus(provider, spec)] as const)))\n statuses.set(provider.mechanism, status)\n\n const explicit = mechanism ? providers.find(provider => provider.mechanism === mechanism) : undefined\n const installedProvider = providers.find((provider) => {\n const status = statuses.get(provider.mechanism)\n return status !== undefined && isInstalledState(status.state)\n })\n const recommended = recommend(candidates)\n const target = explicit\n ?? installedProvider\n ?? (recommended ? providers.find(provider => provider.mechanism === recommended) : undefined)\n\n const explicitStatus = explicit ? statuses.get(explicit.mechanism) : undefined\n const installedMechanism = explicit && explicitStatus && isInstalledState(explicitStatus.state)\n ? explicit.mechanism\n : installedProvider?.mechanism ?? null\n\n const common = { platform: kind, mechanism: installedMechanism, recommended, candidates }\n if (!target) {\n return {\n ...common,\n state: 'unsupported',\n bootCapable: false,\n privileged: false,\n unitPath: null,\n commands: [],\n detail: `no boot mechanism is available on ${platform}`,\n }\n }\n\n const status = statuses.get(target.mechanism)\n const candidate = byMechanism.get(target.mechanism)\n const alsoInstalled = providers\n .filter(provider => provider.mechanism !== target.mechanism && isInstalledState(statuses.get(provider.mechanism)?.state ?? 'unsupported'))\n .map(provider => provider.mechanism)\n return {\n ...common,\n state: status?.state ?? 'unsupported',\n bootCapable: candidate?.bootCapable ?? false,\n privileged: candidate?.privileged ?? false,\n unitPath: status?.unitPath ?? null,\n commands: status?.commands ?? [],\n detail: `${status?.detail ?? 'no detail'}${alsoInstalled.length ? `; also installed: ${alsoInstalled.join(', ')}` : ''}`,\n }\n }\n\n async function safeInstall(provider: BootProvider, spec: BootSpec): Promise<BootActionResult> {\n try {\n return await provider.install(spec)\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n }\n\n async function safeUninstall(provider: BootProvider, spec: BootSpec): Promise<BootActionResult> {\n try {\n return await provider.uninstall(spec)\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n }\n\n return {\n providers,\n\n detect: detectAll,\n\n status: buildStatus,\n\n async install(spec: BootSpec, mechanism?: BootMechanism) {\n const before = await buildStatus(spec, mechanism)\n const chosen = mechanism ?? before.mechanism ?? before.recommended\n const target = chosen ? providers.find(provider => provider.mechanism === chosen) : undefined\n if (!target) {\n return {\n ...failed(`no boot mechanism is available on ${platform}`),\n mechanism: null,\n status: before,\n }\n }\n const result = await safeInstall(target, spec)\n const status = await buildStatus(spec, mechanism)\n return {\n ...result,\n mechanism: result.ok ? target.mechanism : status.mechanism,\n status,\n }\n },\n\n async uninstall(spec: BootSpec, mechanism?: BootMechanism) {\n const before = await buildStatus(spec, mechanism)\n const chosen = mechanism ?? before.mechanism\n const target = chosen ? providers.find(provider => provider.mechanism === chosen) : undefined\n if (!target) {\n return {\n ok: true,\n changed: false,\n detail: 'no OS boot entry is installed for this plugin, so there is nothing to uninstall',\n commands: [],\n needsPrivilege: false,\n status: before,\n }\n }\n const result = await safeUninstall(target, spec)\n const status = await buildStatus(spec, mechanism)\n return { ...result, status }\n },\n }\n}\n", "/**\n * The only place this plugin starts a process.\n *\n * Every call is an argv array with no shell, so a path or a value can never\n * become a command. Callers pass absolute programs; nothing here resolves\n * through a shell profile.\n */\nimport { spawn } from 'node:child_process'\n\nexport interface RunOptions {\n cwd?: string\n env?: Record<string, string | undefined>\n timeoutMs?: number\n /** Cap on each captured stream; a chatty command is truncated, not buffered forever. */\n maxBytes?: number\n}\n\nexport interface RunResult {\n command: string\n args: string[]\n code: number | null\n signal: NodeJS.Signals | null\n stdout: string\n stderr: string\n timedOut: boolean\n error: string | null\n}\n\n/** Run a program and always resolve; a non-zero code is data, not a throw. */\nexport async function run(command: string, args: string[] = [], options: RunOptions = {}): Promise<RunResult> {\n const maxBytes = options.maxBytes ?? 256 * 1024\n const timeoutMs = options.timeoutMs ?? 20_000\n\n return await new Promise<RunResult>((resolve) => {\n let settled = false\n let stdout = ''\n let stderr = ''\n let timedOut = false\n\n const finish = (result: Partial<RunResult>): void => {\n if (settled)\n return\n settled = true\n resolve({\n command,\n args,\n code: result.code ?? null,\n signal: result.signal ?? null,\n stdout: result.stdout ?? stdout,\n stderr: result.stderr ?? stderr,\n timedOut,\n error: result.error ?? null,\n })\n }\n\n let child\n try {\n child = spawn(command, args, {\n cwd: options.cwd,\n env: { ...process.env, ...options.env },\n shell: false,\n windowsHide: true,\n stdio: ['ignore', 'pipe', 'pipe'],\n })\n }\n catch (error) {\n finish({ error: error instanceof Error ? error.message : String(error) })\n return\n }\n\n const timer = setTimeout(() => {\n timedOut = true\n child.kill('SIGKILL')\n }, timeoutMs)\n\n child.stdout?.on('data', (chunk: Buffer) => {\n if (stdout.length < maxBytes)\n stdout += chunk.toString('utf8').slice(0, maxBytes - stdout.length)\n })\n child.stderr?.on('data', (chunk: Buffer) => {\n if (stderr.length < maxBytes)\n stderr += chunk.toString('utf8').slice(0, maxBytes - stderr.length)\n })\n\n child.on('error', (error) => {\n clearTimeout(timer)\n finish({ error: error.message })\n })\n child.on('close', (code, signal) => {\n clearTimeout(timer)\n finish({ code, signal })\n })\n })\n}\n\n/** Run a program and fail loudly on anything but success. */\nexport async function runOk(command: string, args: string[] = [], options: RunOptions = {}): Promise<RunResult> {\n const result = await run(command, args, options)\n if (result.error !== null)\n throw new Error(`${command} failed: ${result.error}`)\n if (result.code !== 0)\n throw new Error(`${command} exited ${String(result.code)}: ${result.stderr.trim() || result.stdout.trim()}`)\n return result\n}\n\n/** True when the program exists and answers to `--version` or similar. */\nexport async function hasCommand(command: string): Promise<boolean> {\n const probe = process.platform === 'win32' ? 'where.exe' : 'which'\n const result = await run(probe, [command], { timeoutMs: 5000 })\n return result.code === 0\n}\n\n/**\n * Whether this process can run one privileged command with no prompt.\n * `sudo -n` never asks for a password, so a failure is a definitive \"not\n * available\" rather than something to retry interactively.\n */\nexport async function sudoAvailable(): Promise<boolean> {\n if (process.getuid?.() === 0)\n return true\n const result = await run('sudo', ['-n', 'true'], { timeoutMs: 5000 })\n return result.code === 0\n}\n", "/**\n * Shared pieces of the boot ladder: where each mechanism's artifact lives, how\n * ownership of an existing artifact is proven before it is touched, and how a\n * probe's answers collapse into one `BootState`. No process is started here.\n */\nimport fs from 'node:fs'\nimport os from 'node:os'\nimport path from 'node:path'\nimport { readText, writeFileAtomic } from '../util/fsx.js'\nimport type { BootState } from '../shared/contracts.js'\nimport type { BootActionResult, BootProviderContext } from './types.js'\n\nexport function errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n\n/** Existence check through the injected seam, so a probe is testable without touching the host. */\nexport function existsOf(ctx: BootProviderContext, file: string): boolean {\n return ctx.exists ? ctx.exists(file) : fs.existsSync(file)\n}\n\nexport function posixJoin(...parts: string[]): string {\n return path.posix.join(...parts)\n}\n\n/** `$XDG_CONFIG_HOME`, else `~/.config`. */\nexport function configHome(ctx: BootProviderContext): string {\n const xdg = ctx.env.XDG_CONFIG_HOME?.trim()\n return xdg ? path.posix.resolve(xdg) : posixJoin(ctx.home, '.config')\n}\n\n/** `%LOCALAPPDATA%`, else `~\\AppData\\Local`. */\nexport function localAppData(ctx: BootProviderContext): string {\n const value = ctx.env.LOCALAPPDATA?.trim()\n return value ? value : path.join(ctx.home, 'AppData', 'Local')\n}\n\n/** A writable scratch directory, used to stage a unit before `sudo install`. */\nexport function tempDir(ctx: BootProviderContext): string {\n const value = ctx.env.TMPDIR?.trim() || ctx.env.TEMP?.trim() || ctx.env.TMP?.trim()\n return value || os.tmpdir()\n}\n\nexport function currentUser(ctx: BootProviderContext): string | null {\n const value = ctx.env.USER?.trim() || ctx.env.LOGNAME?.trim() || ctx.env.USERNAME?.trim()\n if (value)\n return value\n try {\n return os.userInfo().username\n }\n catch {\n return null\n }\n}\n\nexport function uidOf(ctx: BootProviderContext): string | null {\n const configured = ctx.env.UID?.trim()\n if (configured)\n return configured\n const uid = process.getuid?.()\n return uid === undefined ? null : String(uid)\n}\n\n// ---------------------------------------------------------------------------\n// Ownership\n// ---------------------------------------------------------------------------\n\nexport interface FileOwnership {\n exists: boolean\n owned: boolean\n text: string | null\n reason: string | null\n}\n\n/**\n * An artifact belongs to this plugin only when it carries the marker. A file\n * we cannot read is treated as foreign: we must never overwrite or delete a\n * unit somebody else wrote.\n */\nexport function inspectOwned(file: string, marker: string): FileOwnership {\n if (!fs.existsSync(file))\n return { exists: false, owned: false, text: null, reason: null }\n const text = readText(file)\n if (text === null)\n return { exists: true, owned: false, text: null, reason: `${file} exists but is unreadable, so it cannot be proven to be ours` }\n if (!text.includes(marker))\n return { exists: true, owned: false, text, reason: `${file} exists and does not carry this plugin's marker (${marker}); refusing to touch an artifact we did not write` }\n return { exists: true, owned: true, text, reason: null }\n}\n\n/** Write our artifact if the bytes differ; never overwrite a foreign one. */\nexport function writeOwned(file: string, marker: string, content: string, mode = 0o644): { changed: boolean, refusal: string | null } {\n const own = inspectOwned(file, marker)\n if (own.exists && !own.owned)\n return { changed: false, refusal: own.reason }\n if (own.exists && own.text === content)\n return { changed: false, refusal: null }\n writeFileAtomic(file, content, mode)\n return { changed: true, refusal: null }\n}\n\n/** Delete our artifact only; a missing file is already the desired state. */\nexport function removeOwned(file: string, marker: string): { removed: boolean, refusal: string | null } {\n const own = inspectOwned(file, marker)\n if (!own.exists)\n return { removed: false, refusal: null }\n if (!own.owned)\n return { removed: false, refusal: own.reason }\n try {\n fs.rmSync(file, { force: true })\n return { removed: true, refusal: null }\n }\n catch (error) {\n return { removed: false, refusal: `could not delete ${file}: ${errorMessage(error)}` }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Results\n// ---------------------------------------------------------------------------\n\nexport function failed(detail: string, extra: Partial<BootActionResult> = {}): BootActionResult {\n return { ok: false, changed: false, detail, commands: [], needsPrivilege: false, ...extra }\n}\n\n/** Installed + enabled + last run failed is `enabled-failing`; never a guessed success. */\nexport function bootState(installed: boolean, enabled: boolean, failing: boolean): BootState {\n if (!installed)\n return 'not-installed'\n if (!enabled)\n return 'installed-disabled'\n return failing ? 'enabled-failing' : 'enabled-running'\n}\n\nexport function isInstalledState(state: BootState): boolean {\n return state === 'installed-disabled' || state === 'enabled-running' || state === 'enabled-failing'\n}\n", "/**\n * Small filesystem helpers. Every write is atomic (temp file + rename) so a\n * reader never sees half a file, and secret-bearing files are created 0600.\n */\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\n\nexport function fileExists(file: string): boolean {\n try {\n return fs.statSync(file).isFile()\n }\n catch {\n return false\n }\n}\n\nexport function readText(file: string): string | null {\n try {\n return fs.readFileSync(file, 'utf8')\n }\n catch {\n return null\n }\n}\n\nexport function readJson<T>(file: string): T | null {\n const text = readText(file)\n if (text === null)\n return null\n try {\n return JSON.parse(text) as T\n }\n catch {\n return null\n }\n}\n\nexport function ensureDir(dir: string, mode = 0o700): void {\n fs.mkdirSync(dir, { recursive: true, mode })\n}\n\n/** Write a file through a sibling temp file, then rename it into place. */\nexport function writeFileAtomic(file: string, data: string, mode?: number): void {\n ensureDir(path.dirname(file))\n const temp = path.join(path.dirname(file), `.${path.basename(file)}.${process.pid}.${Date.now()}.tmp`)\n const fd = fs.openSync(temp, 'w', mode ?? 0o644)\n try {\n fs.writeFileSync(fd, data, 'utf8')\n fs.fsyncSync(fd)\n }\n finally {\n fs.closeSync(fd)\n }\n if (mode !== undefined)\n fs.chmodSync(temp, mode)\n fs.renameSync(temp, file)\n}\n\nexport function writeJsonAtomic(file: string, value: unknown, mode?: number): void {\n writeFileAtomic(file, `${JSON.stringify(value, null, 2)}\\n`, mode)\n}\n\n/** Best-effort removal; a missing file is not an error. */\nexport function removeFile(file: string): void {\n try {\n fs.rmSync(file, { force: true })\n }\n catch {\n // ignored: the caller only cares that it is gone, and reconciliation reports the rest\n }\n}\n", "/**\n * systemd: a user unit (`~/.config/systemd/user`) and a system unit\n * (`/etc/systemd/system`). The system one needs root, so every privileged call\n * goes through `sudo -n` \u2014 it never prompts \u2014 and the copy-pasteable `sudo \u2026`\n * form is reported when elevation is not available.\n */\nimport fs from 'node:fs'\nimport type { BootCandidate, BootState } from '../shared/contracts.js'\nimport type { BootActionResult, BootProvider, BootProviderContext, BootProviderStatus, BootSpec } from './types.js'\nimport {\n assertAbsolute,\n assertArg,\n assertEnvKey,\n assertLabel,\n assertMarker,\n assertUnitName,\n shellCommand,\n systemdEnvLine,\n systemdExecWord,\n systemdPath,\n systemdText,\n} from './escape.js'\nimport {\n bootState,\n configHome,\n currentUser,\n errorMessage,\n existsOf,\n failed,\n inspectOwned,\n posixJoin,\n removeOwned,\n tempDir,\n writeOwned,\n} from './common.js'\n\nconst ENABLED_UNIT_STATES = new Set(['enabled', 'enabled-runtime', 'alias', 'static', 'indirect', 'generated', 'transient'])\nconst FAILED_RESULTS = new Set(['failed', 'exit-code', 'signal', 'timeout', 'core-dump', 'watchdog', 'start-limit-hit', 'oom-kill'])\n\ntype Scope = 'user' | 'system'\n\nfunction validate(spec: BootSpec): void {\n assertUnitName(spec.unitName)\n assertMarker(spec.marker)\n assertLabel(spec.label)\n assertAbsolute(spec.command, 'spec.command')\n assertAbsolute(spec.cwd, 'spec.cwd')\n assertAbsolute(spec.logDir, 'spec.logDir')\n for (const arg of spec.args)\n assertArg(arg)\n for (const key of Object.keys(spec.env))\n assertEnvKey(key)\n}\n\nfunction envLines(spec: BootSpec): string[] {\n return Object.entries(spec.env).map(([key, value]) => `Environment=${systemdEnvLine(key, value)}`)\n}\n\nconst MANAGED = (spec: BootSpec): string => `# Managed by ${spec.marker}`\n\n/** `Type=exec` with an explicit environment; boot capability comes from linger, not from this file. */\nexport function systemdUserUnit(spec: BootSpec): string {\n validate(spec)\n return `${[\n MANAGED(spec),\n '[Unit]',\n `Description=${systemdText(spec.label)}`,\n 'After=network-online.target',\n '',\n '[Service]',\n 'Type=exec',\n `ExecStart=${[spec.command, ...spec.args].map(systemdExecWord).join(' ')}`,\n `WorkingDirectory=${systemdPath(spec.cwd, 'spec.cwd')}`,\n 'Restart=always',\n 'RestartSec=5',\n ...envLines(spec),\n '',\n '[Install]',\n 'WantedBy=default.target',\n '',\n ].join('\\n')}`\n}\n\n/**\n * The system unit. `StartLimit*` belongs in `[Unit]`, not `[Service]`; `User=`\n * is written only when we are root and know the target account.\n */\nexport function systemdSystemUnit(spec: BootSpec, user: string | null = null): string {\n validate(spec)\n return `${[\n MANAGED(spec),\n '[Unit]',\n `Description=${systemdText(spec.label)}`,\n 'After=network-online.target',\n 'StartLimitIntervalSec=60',\n 'StartLimitBurst=5',\n '',\n '[Service]',\n ...(user ? [`User=${user}`] : []),\n 'Type=exec',\n `ExecStart=${[spec.command, ...spec.args].map(systemdExecWord).join(' ')}`,\n `WorkingDirectory=${systemdPath(spec.cwd, 'spec.cwd')}`,\n 'Restart=always',\n 'RestartSec=5',\n ...envLines(spec),\n '',\n '[Install]',\n 'WantedBy=multi-user.target',\n '',\n ].join('\\n')}`\n}\n\nfunction codeOf(result: { code: number | null, error?: string | null }): number | null {\n return result.error ? null : result.code\n}\n\nfunction parseKeyValues(stdout: string): Record<string, string> {\n const out: Record<string, string> = {}\n for (const line of stdout.split('\\n')) {\n const eq = line.indexOf('=')\n if (eq > 0)\n out[line.slice(0, eq).trim()] = line.slice(eq + 1).trim()\n }\n return out\n}\n\ninterface UnitProbe {\n unitFileState: string\n activeState: string\n result: string\n nRestarts: string\n enabled: boolean\n installed: boolean\n reachable: boolean\n detail: string\n}\n\nasync function readUnit(ctx: BootProviderContext, unit: string, scope: Scope): Promise<UnitProbe> {\n const scopeArgs = scope === 'user' ? ['--user'] : []\n const show = await ctx.run('systemctl', [...scopeArgs, 'show', '-p', 'UnitFileState', '-p', 'ActiveState', '-p', 'Result', '-p', 'NRestarts', unit])\n const props = parseKeyValues(show.stdout)\n const isEnabled = await ctx.run('systemctl', [...scopeArgs, 'is-enabled', unit])\n const enabledCode = codeOf(isEnabled)\n const unitFileState = props.UnitFileState ?? ''\n /**\n * `is-enabled` exits 1 both for a disabled unit and for a unit it cannot even\n * look up, so only a known `UnitFileState` (or an explicit exit 0) proves the\n * unit exists. A user-bus failure must not read as `installed-disabled`.\n */\n const knownState = unitFileState !== '' && unitFileState !== 'not-found'\n const enabled = enabledCode === 0 || ENABLED_UNIT_STATES.has(unitFileState)\n const installed = enabled || knownState\n const result = props.Result ?? ''\n return {\n unitFileState,\n activeState: props.ActiveState ?? '',\n result,\n nRestarts: props.NRestarts ?? '',\n enabled,\n installed,\n reachable: show.error === undefined || show.error === null,\n detail: `UnitFileState=${unitFileState || '(none)'} ActiveState=${props.ActiveState || '(none)'} Result=${result || '(none)'} NRestarts=${props.NRestarts ?? '0'}`,\n }\n}\n\nasync function userScopeReachable(ctx: BootProviderContext): Promise<{ reachable: boolean, reason: string }> {\n const probe = await ctx.run('systemctl', ['--user', 'is-system-running'])\n if (probe.error)\n return { reachable: false, reason: `systemctl --user is not available here (${probe.error})` }\n if (`${probe.stdout}\\n${probe.stderr}`.includes('Failed to connect to user scope bus'))\n return { reachable: false, reason: 'systemctl --user cannot reach a user manager: Failed to connect to user scope bus' }\n return { reachable: true, reason: '' }\n}\n\nasync function lingerEnabled(ctx: BootProviderContext): Promise<boolean> {\n const user = currentUser(ctx)\n if (!user)\n return false\n const probe = await ctx.run('loginctl', ['show-user', user, '--property=Linger'])\n if (codeOf(probe) !== 0)\n return false\n return /(^|\\n)Linger=yes(\\n|$)/.test(probe.stdout)\n}\n\nfunction problem(run: { code: number | null, error?: string | null, stdout: string, stderr: string }, command: string): string | null {\n const code = codeOf(run)\n if (code === 0)\n return null\n if (code === null)\n return run.error ? `${command}: ${run.error}` : `${command}: no exit code`\n return `${command} exited ${code}: ${(run.stderr || run.stdout).trim() || '(no output)'}`\n}\n\nexport function createSystemdUserProvider(ctx: BootProviderContext): BootProvider {\n const mechanism = 'systemd-user' as const\n const unitOf = (spec: BootSpec): string => `${assertUnitName(spec.unitName)}.service`\n const pathOf = (spec: BootSpec): string => posixJoin(configHome(ctx), 'systemd', 'user', unitOf(spec))\n\n return {\n mechanism,\n\n async detect(): Promise<BootCandidate> {\n if (ctx.platform !== 'linux')\n return { mechanism, available: false, bootCapable: false, privileged: false, reason: 'systemd is Linux-only' }\n const bus = await userScopeReachable(ctx)\n if (!bus.reachable)\n return { mechanism, available: false, bootCapable: false, privileged: false, reason: bus.reason }\n const linger = await lingerEnabled(ctx)\n const privileged = linger || (await ctx.sudo())\n return {\n mechanism,\n available: true,\n bootCapable: linger,\n privileged,\n reason: linger\n ? 'a systemd user manager is reachable and linger is on, so the unit starts at boot'\n : 'a systemd user manager is reachable, but linger is off: the unit starts at login until `loginctl enable-linger` succeeds',\n }\n },\n\n async status(spec: BootSpec): Promise<BootProviderStatus> {\n try {\n const unit = unitOf(spec)\n const file = pathOf(spec)\n const own = inspectOwned(file, assertMarker(spec.marker))\n if (own.exists && !own.owned)\n return { state: 'not-installed', unitPath: file, detail: own.reason ?? 'foreign file', commands: [] }\n const probe = await readUnit(ctx, unit, 'user')\n const installed = own.owned || probe.installed\n const state: BootState = bootState(installed, probe.enabled, FAILED_RESULTS.has(probe.result))\n const user = currentUser(ctx)\n const linger = await lingerEnabled(ctx)\n const commands: string[] = []\n if (!linger && user)\n commands.push(shellCommand('sudo', ['loginctl', 'enable-linger', user]))\n const detail = `${probe.detail}; ${linger ? 'linger is on (boot-capable)' : 'linger is off (login-scoped)'}`\n return { state, unitPath: file, detail, commands }\n }\n catch (error) {\n return { state: 'not-installed', unitPath: null, detail: errorMessage(error), commands: [] }\n }\n },\n\n async install(spec: BootSpec): Promise<BootActionResult> {\n try {\n validate(spec)\n const unit = unitOf(spec)\n const file = pathOf(spec)\n const write = writeOwned(file, spec.marker, systemdUserUnit(spec), 0o644)\n if (write.refusal)\n return failed(write.refusal)\n\n const before = await readUnit(ctx, unit, 'user')\n let changed = write.changed\n if (write.changed || !before.enabled) {\n const reloadCommand = shellCommand('systemctl', ['--user', 'daemon-reload'])\n const reload = await ctx.run('systemctl', ['--user', 'daemon-reload'])\n const reloadProblem = problem(reload, reloadCommand)\n if (reloadProblem)\n return failed(reloadProblem, { changed, commands: [reloadCommand] })\n\n const enableCommand = shellCommand('systemctl', ['--user', 'enable', '--now', unit])\n const enable = await ctx.run('systemctl', ['--user', 'enable', '--now', unit])\n const enableProblem = problem(enable, enableCommand)\n if (enableProblem)\n return failed(enableProblem, { changed: true, commands: [enableCommand] })\n changed = true\n }\n\n const after = await readUnit(ctx, unit, 'user')\n if (!after.enabled)\n return failed(`unit ${unit} is not enabled after install (${after.detail})`, { changed })\n\n let linger = await lingerEnabled(ctx)\n const user = currentUser(ctx)\n const commands: string[] = []\n if (!linger && user) {\n const res = await ctx.run('loginctl', ['enable-linger', user])\n if (codeOf(res) === 0) {\n linger = true\n changed = true\n }\n else {\n commands.push(shellCommand('sudo', ['loginctl', 'enable-linger', user]))\n }\n }\n const detail = linger\n ? `${file} installed and enabled; linger is on, so ${unit} starts at boot`\n : `${file} installed and enabled, but linger is off: ${unit} starts at login only. ${commands.length ? `Run \\`${commands[0]}\\` to make it boot-capable.` : 'No target user could be determined to enable linger for.'}`\n return { ok: true, changed, detail, commands, needsPrivilege: !linger }\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n },\n\n async uninstall(spec: BootSpec): Promise<BootActionResult> {\n try {\n validate(spec)\n const unit = unitOf(spec)\n const file = pathOf(spec)\n const own = inspectOwned(file, spec.marker)\n if (own.exists && !own.owned)\n return failed(own.reason ?? 'foreign file')\n\n const before = await readUnit(ctx, unit, 'user')\n if (!before.reachable && !own.exists) {\n return { ok: true, changed: false, detail: `no unit file at ${file} and systemctl is unavailable; nothing to remove`, commands: [], needsPrivilege: false }\n }\n // A unit of the same name can come from anywhere on the search path; with\n // no file of ours, disabling by name would stop somebody else's unit.\n if (!own.owned && !own.exists && before.installed)\n return failed(`a unit named ${unit} exists but no unit file of ours is at ${file}; refusing to disable a unit this plugin did not install`)\n if (own.owned && before.reachable) {\n const disableCommand = shellCommand('systemctl', ['--user', 'disable', '--now', unit])\n const disable = await ctx.run('systemctl', ['--user', 'disable', '--now', unit])\n const disableCode = codeOf(disable)\n if (disableCode !== 0 && disableCode !== 1 && disableCode !== 4)\n return failed(problem(disable, disableCommand) ?? 'disable failed', { commands: [disableCommand] })\n }\n\n const remove = removeOwned(file, spec.marker)\n if (remove.refusal)\n return failed(remove.refusal)\n\n let changed = remove.removed\n if (before.installed || remove.removed) {\n await ctx.run('systemctl', ['--user', 'daemon-reload'])\n changed = true\n }\n\n const after = await readUnit(ctx, unit, 'user')\n if (after.installed)\n return failed(`unit ${unit} is still known to systemd after removal (${after.detail})`, { changed })\n\n return {\n ok: true,\n changed,\n detail: remove.removed ? `disabled and removed ${file}` : `${file} was already gone`,\n commands: [],\n needsPrivilege: false,\n }\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n },\n }\n}\n\nfunction systemUserName(ctx: BootProviderContext): string | null {\n const user = currentUser(ctx)\n return user && /^[A-Za-z_][A-Za-z0-9._-]*$/.test(user) ? user : null\n}\n\nfunction stageUnit(ctx: BootProviderContext, unit: string, content: string): string {\n const staged = posixJoin(tempDir(ctx), `home-hosted-${unit}`)\n fs.writeFileSync(staged, content, { mode: 0o644 })\n return staged\n}\n\nexport function createSystemdSystemProvider(ctx: BootProviderContext): BootProvider {\n const mechanism = 'systemd-system' as const\n const unitOf = (spec: BootSpec): string => `${assertUnitName(spec.unitName)}.service`\n const pathOf = (spec: BootSpec): string => posixJoin('/etc', 'systemd', 'system', unitOf(spec))\n const contentOf = (spec: BootSpec): string => systemdSystemUnit(spec, ctx.isRoot ? systemUserName(ctx) : null)\n\n const installCommands = (staged: string, file: string, unit: string): string[] => [\n shellCommand('sudo', ['install', '-m', '0644', staged, file]),\n shellCommand('sudo', ['systemctl', 'daemon-reload']),\n shellCommand('sudo', ['systemctl', 'enable', '--now', unit]),\n ]\n\n return {\n mechanism,\n\n async detect(): Promise<BootCandidate> {\n if (ctx.platform !== 'linux')\n return { mechanism, available: false, bootCapable: false, privileged: false, reason: 'systemd is Linux-only' }\n if (!existsOf(ctx, '/run/systemd/system'))\n return { mechanism, available: false, bootCapable: false, privileged: false, reason: 'systemd is not the init system here (no /run/systemd/system)' }\n const privileged = ctx.isRoot || (await ctx.sudo())\n return {\n mechanism,\n available: privileged,\n bootCapable: privileged,\n privileged,\n reason: privileged\n ? 'systemd is PID 1 and this process can use root, so a system unit starts at boot'\n : 'systemd is PID 1, but installing a system unit needs root or passwordless sudo',\n }\n },\n\n async status(spec: BootSpec): Promise<BootProviderStatus> {\n try {\n const unit = unitOf(spec)\n const file = pathOf(spec)\n const own = inspectOwned(file, assertMarker(spec.marker))\n if (own.exists && !own.owned)\n return { state: 'not-installed', unitPath: file, detail: own.reason ?? 'foreign file', commands: [] }\n const probe = await readUnit(ctx, unit, 'system')\n const installed = own.owned || probe.installed\n const state: BootState = bootState(installed, probe.enabled, FAILED_RESULTS.has(probe.result))\n const privileged = ctx.isRoot || (await ctx.sudo())\n const commands: string[] = []\n if (installed && !probe.enabled && !privileged)\n commands.push(shellCommand('sudo', ['systemctl', 'enable', '--now', unit]))\n return {\n state,\n unitPath: file,\n detail: `${probe.detail}${privileged ? '' : '; needs root to change'}`,\n commands,\n }\n }\n catch (error) {\n return { state: 'not-installed', unitPath: null, detail: errorMessage(error), commands: [] }\n }\n },\n\n async install(spec: BootSpec): Promise<BootActionResult> {\n try {\n validate(spec)\n const unit = unitOf(spec)\n const file = pathOf(spec)\n const content = contentOf(spec)\n const own = inspectOwned(file, spec.marker)\n if (own.exists && !own.owned)\n return failed(own.reason ?? 'foreign file')\n\n const before = await readUnit(ctx, unit, 'system')\n const changed = !own.exists || own.text !== content\n\n if (!ctx.isRoot && !(await ctx.sudo())) {\n const staged = stageUnit(ctx, unit, content)\n return failed(`installing a system unit needs root; the unit is staged at ${staged}`, {\n changed: false,\n needsPrivilege: true,\n commands: installCommands(staged, file, unit),\n })\n }\n\n if (ctx.isRoot) {\n const write = writeOwned(file, spec.marker, content, 0o644)\n if (write.refusal)\n return failed(write.refusal)\n }\n else {\n const staged = stageUnit(ctx, unit, content)\n const installCommand = shellCommand('sudo', ['install', '-m', '0644', staged, file])\n const install = await ctx.run('sudo', ['-n', 'install', '-m', '0644', staged, file])\n const installProblem = problem(install, installCommand)\n if (installProblem)\n return failed(installProblem, { needsPrivilege: true, commands: installCommands(staged, file, unit) })\n fs.rmSync(staged, { force: true })\n }\n\n if (changed || !before.enabled) {\n const sudoPrefix = ctx.isRoot ? [] : ['-n']\n const reloadCommand = shellCommand('sudo', ['systemctl', 'daemon-reload'])\n const reload = await ctx.run('sudo', [...sudoPrefix, 'systemctl', 'daemon-reload'])\n const reloadProblem = problem(reload, reloadCommand)\n if (reloadProblem)\n return failed(reloadProblem, { changed, needsPrivilege: !ctx.isRoot, commands: [reloadCommand] })\n\n const enableCommand = shellCommand('sudo', ['systemctl', 'enable', '--now', unit])\n const enable = await ctx.run('sudo', [...sudoPrefix, 'systemctl', 'enable', '--now', unit])\n const enableProblem = problem(enable, enableCommand)\n if (enableProblem)\n return failed(enableProblem, { changed: true, needsPrivilege: !ctx.isRoot, commands: [enableCommand] })\n }\n\n const after = await readUnit(ctx, unit, 'system')\n if (!after.enabled)\n return failed(`unit ${unit} is not enabled after install (${after.detail})`, { changed })\n\n return {\n ok: true,\n changed: changed || !before.enabled,\n detail: `${file} installed and enabled as a system unit (${after.detail})`,\n commands: [],\n needsPrivilege: !ctx.isRoot,\n }\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n },\n\n async uninstall(spec: BootSpec): Promise<BootActionResult> {\n try {\n const unit = unitOf(spec)\n const file = pathOf(spec)\n const own = inspectOwned(file, spec.marker)\n if (own.exists && !own.owned)\n return failed(own.reason ?? 'foreign file')\n\n const privileged = ctx.isRoot || (await ctx.sudo())\n if (!privileged) {\n if (!own.exists)\n return { ok: true, changed: false, detail: `no unit file at ${file} and no privilege to change systemd; nothing to remove`, commands: [], needsPrivilege: false }\n return failed('removing a system unit needs root', {\n needsPrivilege: true,\n commands: [\n shellCommand('sudo', ['systemctl', 'disable', '--now', unit]),\n shellCommand('sudo', ['rm', '-f', file]),\n shellCommand('sudo', ['systemctl', 'daemon-reload']),\n ],\n })\n }\n\n const prefix = ctx.isRoot ? [] : ['-n']\n // With no file of ours at the path we write, a same-named unit belongs to\n // somebody else (a vendor unit in /usr/lib/systemd/system): leave it alone.\n if (!own.exists && !own.owned)\n return failed(`no unit file of ours at ${file}; refusing to disable a unit this plugin did not install`)\n const disableCommand = shellCommand('sudo', ['systemctl', 'disable', '--now', unit])\n const disable = await ctx.run('sudo', [...prefix, 'systemctl', 'disable', '--now', unit])\n const disableCode = codeOf(disable)\n if (disableCode !== 0 && disableCode !== 1 && disableCode !== 4)\n return failed(problem(disable, disableCommand) ?? 'disable failed', { needsPrivilege: !ctx.isRoot, commands: [disableCommand] })\n\n if (own.exists) {\n if (ctx.isRoot) {\n const remove = removeOwned(file, spec.marker)\n if (remove.refusal)\n return failed(remove.refusal)\n }\n else {\n // The check above ran as the invoking user, which cannot read a\n // root-only file; re-prove ownership before the privileged delete.\n if (!own.owned)\n return failed(own.reason ?? 'foreign file')\n const rmCommand = shellCommand('sudo', ['rm', '-f', file])\n const rm = await ctx.run('sudo', ['-n', 'rm', '-f', file])\n const rmProblem = problem(rm, rmCommand)\n if (rmProblem)\n return failed(rmProblem, { needsPrivilege: true, commands: [rmCommand] })\n }\n }\n\n await ctx.run('sudo', [...prefix, 'systemctl', 'daemon-reload'])\n const after = await readUnit(ctx, unit, 'system')\n if (after.installed)\n return failed(`unit ${unit} is still known to systemd after removal (${after.detail})`, { changed: true, needsPrivilege: !ctx.isRoot })\n\n return {\n ok: true,\n changed: own.exists || disableCode === 0,\n detail: own.exists ? `disabled and removed ${file}` : `${file} was already gone`,\n commands: [],\n needsPrivilege: !ctx.isRoot,\n }\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n },\n }\n}\n", "/**\n * Escaping for every format this plugin writes.\n *\n * None of this builds a shell command: a unit file, a plist, a `.desktop`\n * entry, a task XML and a registry value each have their own parser, and each\n * value is quoted for exactly that parser. Values that carry control\n * characters (newlines included) are rejected outright, because a newline is\n * how a value escapes its field in every one of these formats.\n */\n\nconst CONTROL = /[\\u0000-\\u001F\\u007F]/\n\nexport function assertNoControl(value: string, what: string): string {\n if (CONTROL.test(value))\n throw new Error(`${what} must not contain control characters or newlines`)\n return value\n}\n\nexport function assertUnitName(name: string): string {\n if (!/^[A-Za-z0-9._@-]+$/.test(name))\n throw new Error(`unit name ${JSON.stringify(name)} must match ^[A-Za-z0-9._@-]+$`)\n if (name.startsWith('-') || name.startsWith('.') || name.includes('..'))\n throw new Error(`unit name ${JSON.stringify(name)} must not be option-like or traverse paths`)\n return name\n}\n\nexport function assertMarker(marker: string): string {\n if (marker.trim() === '')\n throw new Error('marker must not be empty')\n return assertNoControl(marker, 'marker')\n}\n\nexport function assertEnvKey(key: string): string {\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key))\n throw new Error(`environment key ${JSON.stringify(key)} is not a valid name`)\n return key\n}\n\n/** POSIX-absolute, Windows-drive-absolute or UNC; checked without consulting the host OS. */\nexport function isAbsolutePath(value: string): boolean {\n return value.startsWith('/') || /^[A-Za-z]:[\\\\/]/.test(value) || value.startsWith('\\\\\\\\')\n}\n\nexport function assertAbsolute(value: string, what: string): string {\n if (!isAbsolutePath(value))\n throw new Error(`${what} must be absolute, got ${JSON.stringify(value)}`)\n return assertNoControl(value, what)\n}\n\nexport function assertLabel(value: string): string {\n if (value.trim() === '')\n throw new Error('label must not be empty')\n return assertNoControl(value, 'label')\n}\n\nexport function assertArg(value: string, what = 'argument'): string {\n return assertNoControl(value, what)\n}\n\nfunction replaceAll(value: string, pairs: Array<[string, string]>): string {\n let out = value\n for (const [from, to] of pairs)\n out = out.split(from).join(to)\n return out\n}\n\n/** Single-quote a value the way a POSIX shell would, for `commands[]`. */\nexport function shellQuote(value: string): string {\n if (value !== '' && /^[A-Za-z0-9._/:=@%+,-]+$/.test(value))\n return value\n return `'${value.split('\\'').join('\\'\\\\\\'\\'')}'`\n}\n\n/** The exact line a person can paste into a shell. */\nexport function shellCommand(program: string, args: string[]): string {\n return [program, ...args].map(shellQuote).join(' ')\n}\n\n// ---------------------------------------------------------------------------\n// systemd\n// ---------------------------------------------------------------------------\n\n/**\n * A word in `ExecStart=`/`ExecStop=`. systemd expands `%` specifiers and `$`\n * variables there before it splits the line, so both are pinned, and `;` \u2014 the\n * multi-command separator \u2014 is quoted rather than left bare.\n */\nexport function systemdExecWord(value: string): string {\n assertNoControl(value, 'ExecStart word')\n const escaped = replaceAll(value, [['\\\\', '\\\\\\\\'], ['\"', '\\\\\"'], ['$', '$$'], ['%', '%%']])\n return escaped !== value || /[\\s\"';]/.test(value) ? `\"${escaped}\"` : value\n}\n\n/**\n * A single-line free-text setting such as `Description=` (specifiers only).\n */\nexport function systemdText(value: string): string {\n assertNoControl(value, 'unit setting')\n // A trailing backslash would continue the directive onto the next line.\n return replaceAll(value, [['\\\\', '\\\\\\\\'], ['%', '%%']])\n}\n\n/**\n * A path setting (`WorkingDirectory=`). systemd takes these verbatim \u2014 it does\n * not unquote, and does not unescape `\\%` or `\\$` \u2014 so the only correct\n * encoding is the raw value; anything that would break the line is refused.\n */\nexport function systemdPath(value: string, what = 'path'): string {\n assertAbsolute(value, what)\n if (value.includes('\"'))\n throw new Error(`${what} must not contain a double quote: ${JSON.stringify(value)}`)\n return value\n}\n\n/** `Environment=KEY=value`, quoted as one assignment when the value needs it. */\nexport function systemdEnvLine(key: string, value: string): string {\n assertEnvKey(key)\n assertNoControl(value, `environment value for ${key}`)\n const escaped = replaceAll(value, [['\\\\', '\\\\\\\\'], ['\"', '\\\\\"'], ['%', '%%']])\n return escaped !== value || /[\\s\"']/.test(value) ? `\"${key}=${escaped}\"` : `${key}=${value}`\n}\n\n// ---------------------------------------------------------------------------\n// XML (launchd plist, scheduled-task XML)\n// ---------------------------------------------------------------------------\n\nexport function xmlEscape(value: string): string {\n assertNoControl(value, 'xml value')\n return replaceAll(value, [['&', '&'], ['<', '<'], ['>', '>'], ['\"', '"'], ['\\'', ''']])\n}\n\nexport function xmlUnescape(value: string): string {\n return replaceAll(value, [['<', '<'], ['>', '>'], ['"', '\"'], [''', '\\''], ['&', '&']])\n}\n\n/** A marker inside an XML comment may not contain `--`. */\nexport function assertXmlCommentSafe(value: string): string {\n if (value.includes('--'))\n throw new Error('marker must not contain `--` when it is written inside an XML comment')\n return value\n}\n\n// ---------------------------------------------------------------------------\n// freedesktop .desktop\n// ---------------------------------------------------------------------------\n\nconst DESKTOP_RESERVED = /[\\s\"'\\\\><~|&;$*?#()`]/\n\nexport function desktopWord(value: string): string {\n assertNoControl(value, 'desktop Exec word')\n const escaped = replaceAll(value, [['\\\\', '\\\\\\\\'], ['\"', '\\\\\"'], ['`', '\\\\`'], ['$', '\\\\$'], ['%', '%%']])\n return DESKTOP_RESERVED.test(value) || escaped !== value ? `\"${escaped}\"` : value\n}\n\nexport function desktopExec(program: string, args: string[]): string {\n return [program, ...args].map(desktopWord).join(' ')\n}\n\n/** A `Key=value` line in a `.desktop` file; the marker is written verbatim. */\nexport function desktopValue(key: string, value: string): string {\n assertNoControl(value, `desktop ${key}`)\n if (key.includes('=') || key.includes('\\n'))\n throw new Error(`desktop key ${JSON.stringify(key)} is not valid`)\n return `${key}=${value}`\n}\n\n// ---------------------------------------------------------------------------\n// Windows\n// ---------------------------------------------------------------------------\n\n/** Quote one argv word the way `CreateProcess`/`cmd` parse a command line. */\nexport function windowsArg(value: string): string {\n assertNoControl(value, 'windows argument')\n if (value !== '' && !/[\\s\"]/.test(value))\n return value\n\n let out = '\"'\n let backslashes = 0\n for (const char of value) {\n if (char === '\\\\') {\n backslashes += 1\n continue\n }\n if (char === '\"') {\n out += `${'\\\\'.repeat(backslashes * 2 + 1)}\"`\n backslashes = 0\n continue\n }\n out += `${'\\\\'.repeat(backslashes)}${char}`\n backslashes = 0\n }\n out += `${'\\\\'.repeat(backslashes * 2)}\"`\n return out\n}\n\nexport function windowsCommandLine(program: string, args: string[]): string {\n return [program, ...args].map(windowsArg).join(' ')\n}\n\n/** A line for a `.cmd` wrapper: `%` is a batch metacharacter and is doubled. */\nexport function batchCommandLine(program: string, args: string[]): string {\n return batchEscape(windowsCommandLine(program, args))\n}\n\n/**\n * Make one already-quoted command line safe inside a batch file. `%` is doubled\n * last: the `^` inserted for a metacharacter must not itself gain a caret.\n */\nfunction batchEscape(line: string): string {\n assertNoControl(line, 'batch command line')\n return replaceAll(line, [\n ['^', '^^'],\n ['&', '^&'],\n ['|', '^|'],\n ['<', '^<'],\n ['>', '^>'],\n ['(', '^('],\n [')', '^)'],\n ['%', '%%'],\n ])\n}\n\n/** A single-quoted PowerShell literal. */\nexport function powershellLiteral(value: string): string {\n assertNoControl(value, 'powershell value')\n return `'${value.split('\\'').join('\\'\\'')}'`\n}\n\n/** Quote one word the way `cmd.exe` takes it, for a copy-pasteable `commands[]` entry. */\nexport function cmdQuote(value: string): string {\n if (value !== '' && !/[\\s\"&|<>^]/.test(value))\n return value\n return `\"${value.split('\"').join('\"\"')}\"`\n}\n\nexport function windowsDisplayCommand(program: string, args: string[]): string {\n return [program, ...args].map(cmdQuote).join(' ')\n}\n\n// ---------------------------------------------------------------------------\n// launchd / registry value names\n// ---------------------------------------------------------------------------\n\nexport function assertRegistryValueName(name: string): string {\n if (name.trim() === '')\n throw new Error('registry value name must not be empty')\n return assertNoControl(name, 'registry value name')\n}\n", "/**\n * launchd: a per-user agent (`~/Library/LaunchAgents`) and a system daemon\n * (`/Library/LaunchDaemons`). `launchctl print` is read for its exit code only\n * \u2014 its output is explicitly not API. Loading is `bootstrap`, unloading is\n * `bootout`, and exit 5 from bootstrap means the job is already loaded.\n */\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport type { BootCandidate, BootState } from '../shared/contracts.js'\nimport type { BootActionResult, BootProvider, BootProviderContext, BootProviderStatus, BootSpec } from './types.js'\nimport {\n assertAbsolute,\n assertArg,\n assertEnvKey,\n assertLabel,\n assertMarker,\n assertUnitName,\n assertXmlCommentSafe,\n shellCommand,\n xmlEscape,\n} from './escape.js'\nimport {\n bootState,\n errorMessage,\n failed,\n inspectOwned,\n posixJoin,\n removeOwned,\n tempDir,\n uidOf,\n writeOwned,\n} from './common.js'\n\n/** Both scopes label with the same reverse-DNS prefix. */\nexport const LAUNCHD_LABEL_PREFIX = 'dev.home-hosted.'\n/** bootstrap on an already-loaded job reports EIO. */\nconst LAUNCHCTL_ALREADY_LOADED = 5\n/** `launchctl print` for a label that is not loaded. */\nconst LAUNCHCTL_NOT_LOADED = 113\n/** `launchctl bootout` for a job that is not there. */\nconst LAUNCHCTL_NO_SUCH_PROCESS = 3\n\nfunction validate(spec: BootSpec): void {\n assertUnitName(spec.unitName)\n assertMarker(spec.marker)\n assertLabel(spec.label)\n assertAbsolute(spec.command, 'spec.command')\n assertAbsolute(spec.cwd, 'spec.cwd')\n assertAbsolute(spec.logDir, 'spec.logDir')\n for (const arg of spec.args)\n assertArg(arg)\n for (const key of Object.keys(spec.env))\n assertEnvKey(key)\n}\n\nexport function launchdLabel(spec: BootSpec): string {\n return `${LAUNCHD_LABEL_PREFIX}${assertUnitName(spec.unitName)}`\n}\n\n/** The full property list. The marker rides in an XML comment, which launchd ignores. */\nexport function launchdPlist(spec: BootSpec): string {\n validate(spec)\n const label = launchdLabel(spec)\n const out = path.posix.join(spec.logDir, `${label}.out.log`)\n const err = path.posix.join(spec.logDir, `${label}.err.log`)\n const envKeys = Object.keys(spec.env)\n const lines = [\n '<?xml version=\"1.0\" encoding=\"UTF-8\"?>',\n '<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">',\n '<plist version=\"1.0\">',\n '<dict>',\n '\\t<key>Label</key>',\n `\\t<string>${xmlEscape(label)}</string>`,\n '\\t<key>ProgramArguments</key>',\n '\\t<array>',\n ...[spec.command, ...spec.args].map(arg => `\\t\\t<string>${xmlEscape(arg)}</string>`),\n '\\t</array>',\n '\\t<key>RunAtLoad</key>',\n '\\t<true/>',\n '\\t<key>KeepAlive</key>',\n '\\t<dict>',\n '\\t\\t<key>SuccessfulExit</key>',\n '\\t\\t<false/>',\n '\\t</dict>',\n '\\t<key>ThrottleInterval</key>',\n '\\t<integer>10</integer>',\n '\\t<key>WorkingDirectory</key>',\n `\\t<string>${xmlEscape(spec.cwd)}</string>`,\n ...(envKeys.length\n ? [\n '\\t<key>EnvironmentVariables</key>',\n '\\t<dict>',\n ...envKeys.flatMap(key => [`\\t\\t<key>${xmlEscape(key)}</key>`, `\\t\\t<string>${xmlEscape(spec.env[key] ?? '')}</string>`]),\n '\\t</dict>',\n ]\n : []),\n '\\t<key>StandardOutPath</key>',\n `\\t<string>${xmlEscape(out)}</string>`,\n '\\t<key>StandardErrorPath</key>',\n `\\t<string>${xmlEscape(err)}</string>`,\n `\\t<!-- Managed by ${assertXmlCommentSafe(spec.marker)} -->`,\n '</dict>',\n '</plist>',\n '',\n ]\n return lines.join('\\n')\n}\n\nfunction codeOf(result: { code: number | null, error?: string | null }): number | null {\n return result.error ? null : result.code\n}\n\nfunction problem(run: { code: number | null, error?: string | null, stdout: string, stderr: string }, command: string): string | null {\n const code = codeOf(run)\n if (code === 0)\n return null\n if (code === null)\n return run.error ? `${command}: ${run.error}` : `${command}: no exit code`\n return `${command} exited ${code}: ${(run.stderr || run.stdout).trim() || '(no output)'}`\n}\n\ntype LaunchdMode = 'agent' | 'daemon'\n\n/** Best effort: `/Library/LaunchDaemons` exists on macOS, and only the privileged write can create it. */\nfunction ensureDirQuiet(dir: string): void {\n try {\n fs.mkdirSync(dir, { recursive: true })\n }\n catch {\n // the privileged install reports the real failure\n }\n}\n\nfunction createLaunchdProvider(ctx: BootProviderContext, mode: LaunchdMode): BootProvider {\n const mechanism = mode === 'agent' ? 'launchd-agent' as const : 'launchd-daemon' as const\n const pathOf = (spec: BootSpec): string => mode === 'agent'\n ? posixJoin(ctx.home, 'Library', 'LaunchAgents', `${launchdLabel(spec)}.plist`)\n : posixJoin('/Library', 'LaunchDaemons', `${launchdLabel(spec)}.plist`)\n\n /** `system` for the daemon; `gui/$UID`, else `user/$UID` for the agent. */\n const domainOf = async (): Promise<string | null> => {\n if (mode === 'daemon')\n return 'system'\n const uid = uidOf(ctx)\n if (!uid)\n return null\n const gui = `gui/${uid}`\n if (codeOf(await ctx.run('launchctl', ['print', gui])) === 0)\n return gui\n const user = `user/${uid}`\n if (codeOf(await ctx.run('launchctl', ['print', user])) === 0)\n return user\n return null\n }\n\n const privileged = async (): Promise<boolean> =>\n mode === 'agent' ? true : ctx.isRoot || (await ctx.sudo())\n\n /** Root runs launchctl directly; everything else goes through `sudo -n`. */\n const runPrivileged = async (program: string, args: string[]) =>\n mode === 'agent' || ctx.isRoot ? await ctx.run(program, args) : await ctx.run('sudo', ['-n', program, ...args])\n\n /** The sudo form of what is left to do when this process cannot write the file itself. */\n const commands = (file: string, label: string): string[] => mode === 'agent'\n ? []\n : [\n shellCommand('sudo', ['launchctl', 'bootstrap', 'system', file]),\n shellCommand('sudo', ['launchctl', 'enable', `system/${label}`]),\n ]\n\n return {\n mechanism,\n\n async detect(): Promise<BootCandidate> {\n if (ctx.platform !== 'darwin')\n return { mechanism, available: false, bootCapable: false, privileged: false, reason: 'launchd is macOS-only' }\n if (mode === 'agent') {\n const domain = await domainOf()\n return {\n mechanism,\n available: domain !== null,\n bootCapable: false,\n privileged: true,\n reason: domain === null\n ? `no launchd gui/$UID or user/$UID domain is reachable for uid ${uidOf(ctx) ?? '?'}`\n : `launchd ${domain} domain is reachable; a LaunchAgent loads at login, not at boot`,\n }\n }\n const canElevate = ctx.isRoot || (await ctx.sudo())\n return {\n mechanism,\n available: canElevate,\n bootCapable: canElevate,\n privileged: canElevate,\n reason: canElevate\n ? 'this process can write /Library/LaunchDaemons, so a LaunchDaemon starts at boot'\n : 'a LaunchDaemon needs root or passwordless sudo',\n }\n },\n\n async status(spec: BootSpec): Promise<BootProviderStatus> {\n try {\n const file = pathOf(spec)\n const label = launchdLabel(spec)\n const own = inspectOwned(file, assertMarker(spec.marker))\n if (own.exists && !own.owned)\n return { state: 'not-installed', unitPath: file, detail: own.reason ?? 'foreign file', commands: [] }\n const domain = await domainOf()\n if (!own.owned)\n return { state: 'not-installed', unitPath: file, detail: `no plist at ${file}`, commands: [] }\n if (domain === null)\n return { state: 'enabled-running', unitPath: file, detail: `${file} is present; launchd has no reachable domain for uid ${uidOf(ctx) ?? '?'}, so it loads at the next login`, commands: [] }\n const probe = await ctx.run('launchctl', ['print', `${domain}/${label}`])\n const loaded = codeOf(probe) === 0\n const state: BootState = bootState(true, true, false)\n return {\n state,\n unitPath: file,\n detail: `${file} is present; ${loaded ? `loaded in ${domain}` : `not loaded right now (RunAtLoad loads it at the next login)`}`,\n commands: [],\n }\n }\n catch (error) {\n return { state: 'not-installed', unitPath: null, detail: errorMessage(error), commands: [] }\n }\n },\n\n async install(spec: BootSpec): Promise<BootActionResult> {\n try {\n validate(spec)\n const file = pathOf(spec)\n const label = launchdLabel(spec)\n const content = launchdPlist(spec)\n const own = inspectOwned(file, spec.marker)\n if (own.exists && !own.owned)\n return failed(own.reason ?? 'foreign file')\n const staged = posixJoin(tempDir(ctx), `${label}.plist`)\n if (!(await privileged())) {\n // The command below installs this exact file, so it has to exist.\n ensureDirQuiet(path.posix.dirname(staged))\n fs.writeFileSync(staged, content, { mode: 0o644 })\n return failed('writing /Library/LaunchDaemons needs root; the plist is staged for you to install', {\n needsPrivilege: true,\n commands: [\n shellCommand('sudo', ['install', '-m', '0644', staged, file]),\n shellCommand('sudo', ['launchctl', 'bootstrap', 'system', file]),\n shellCommand('sudo', ['launchctl', 'enable', `system/${label}`]),\n ],\n })\n }\n\n const domain = await domainOf()\n if (domain === null)\n return failed(`launchd has no reachable domain for uid ${uidOf(ctx) ?? '?'}; refusing to write an agent that could never load`)\n\n ensureDirQuiet(path.posix.dirname(file))\n ensureDirQuiet(spec.logDir)\n\n const loaded = codeOf(await ctx.run('launchctl', ['print', `${domain}/${label}`])) === 0\n const before = { text: own.text, exists: own.exists }\n\n let changed = false\n if (mode === 'agent' || ctx.isRoot) {\n const write = writeOwned(file, spec.marker, content, 0o644)\n if (write.refusal)\n return failed(write.refusal)\n changed = write.changed\n }\n else {\n ensureDirQuiet(path.dirname(staged))\n fs.writeFileSync(staged, content, { mode: 0o644 })\n changed = !before.exists || before.text !== content\n if (!changed) {\n fs.rmSync(staged, { force: true })\n }\n else {\n const installCommand = shellCommand('sudo', ['install', '-m', '0644', staged, file])\n const install = await runPrivileged('install', ['-m', '0644', staged, file])\n if (codeOf(install) !== 0)\n return failed(problem(install, installCommand) ?? 'launchctl failed', { needsPrivilege: true, commands: [installCommand] })\n fs.rmSync(staged, { force: true })\n }\n }\n\n const lint = await runPrivileged('plutil', ['-lint', file])\n if (codeOf(lint) !== 0)\n return failed(`plutil -lint rejected the generated plist: ${(lint.stderr || lint.stdout).trim() || 'no output'}`, { changed, commands: commands(file, label) })\n\n if (loaded && changed) {\n const bootout = await runPrivileged('launchctl', ['bootout', `${domain}/${label}`])\n const bootoutCode = codeOf(bootout)\n if (bootoutCode !== 0 && bootoutCode !== LAUNCHCTL_NO_SUCH_PROCESS && bootoutCode !== LAUNCHCTL_NOT_LOADED)\n return failed(problem(bootout, shellCommand('launchctl', ['bootout', `${domain}/${label}`])) ?? 'launchctl failed', { changed, commands: commands(file, label) })\n }\n\n if (changed || !loaded) {\n const boot = await runPrivileged('launchctl', ['bootstrap', domain, file])\n const bootCode = codeOf(boot)\n if (bootCode !== 0 && bootCode !== LAUNCHCTL_ALREADY_LOADED)\n return failed(problem(boot, shellCommand('launchctl', ['bootstrap', domain, file])) ?? 'launchctl failed', { changed, commands: commands(file, label) })\n if (bootCode === 0)\n changed = true\n const enable = await runPrivileged('launchctl', ['enable', `${domain}/${label}`])\n if (codeOf(enable) !== 0)\n return failed(problem(enable, shellCommand('launchctl', ['enable', `${domain}/${label}`])) ?? 'launchctl failed', { changed, commands: commands(file, label) })\n }\n\n const verify = await runPrivileged('launchctl', ['print', `${domain}/${label}`])\n if (codeOf(verify) !== 0)\n return failed(`launchctl print ${domain}/${label} did not confirm the job (exit ${String(codeOf(verify))})`, { changed, commands: commands(file, label) })\n\n return {\n ok: true,\n changed,\n detail: `${file} installed and loaded in ${domain}`,\n commands: [],\n needsPrivilege: mode === 'daemon' && !ctx.isRoot,\n }\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n },\n\n async uninstall(spec: BootSpec): Promise<BootActionResult> {\n try {\n const file = pathOf(spec)\n const label = launchdLabel(spec)\n const own = inspectOwned(file, spec.marker)\n if (own.exists && !own.owned)\n return failed(own.reason ?? 'foreign file')\n if (mode === 'daemon' && !ctx.isRoot && !(await ctx.sudo())) {\n if (!own.exists)\n return { ok: true, changed: false, detail: `no plist at ${file} and no privilege to change launchd; nothing to remove`, commands: [], needsPrivilege: false }\n return failed('removing a LaunchDaemon needs root', {\n needsPrivilege: true,\n commands: [\n shellCommand('sudo', ['launchctl', 'bootout', `system/${label}`]),\n shellCommand('sudo', ['rm', '-f', file]),\n ],\n })\n }\n\n const domain = await domainOf()\n // A job under this label may belong to a plist we did not write; never\n // boot out a job whose own file is not ours.\n if (!own.exists && !own.owned)\n return failed(`no plist of ours at ${file}; refusing to unload a job this plugin did not install`)\n let changed = false\n if (domain !== null) {\n const bootout = await runPrivileged('launchctl', ['bootout', `${domain}/${label}`])\n const bootoutCode = codeOf(bootout)\n if (bootoutCode === 0)\n changed = true\n else if (bootoutCode !== LAUNCHCTL_NO_SUCH_PROCESS && bootoutCode !== LAUNCHCTL_NOT_LOADED)\n return failed(problem(bootout, shellCommand('launchctl', ['bootout', `${domain}/${label}`])) ?? 'launchctl failed', { commands: commands(file, label) })\n }\n\n if (own.exists) {\n if (mode === 'agent' || ctx.isRoot) {\n const remove = removeOwned(file, spec.marker)\n if (remove.refusal)\n return failed(remove.refusal)\n if (remove.removed)\n changed = true\n }\n else {\n // Re-prove ownership before the privileged delete: the check above\n // ran as the invoking user, which may not be able to read the file.\n if (!own.owned)\n return failed(own.reason ?? 'foreign file')\n const rmCommand = shellCommand('sudo', ['rm', '-f', file])\n const rm = await runPrivileged('rm', ['-f', file])\n if (codeOf(rm) !== 0)\n return failed(problem(rm, rmCommand) ?? 'launchctl failed', { needsPrivilege: true, commands: [rmCommand] })\n changed = true\n }\n }\n\n if (domain !== null) {\n const verify = await runPrivileged('launchctl', ['print', `${domain}/${label}`])\n if (codeOf(verify) === 0)\n return failed(`${label} is still loaded in ${domain} after bootout`, { changed })\n }\n\n return {\n ok: true,\n changed,\n detail: own.exists ? `unloaded and removed ${file}` : `no plist at ${file} (already gone)`,\n commands: [],\n needsPrivilege: mode === 'daemon' && !ctx.isRoot,\n }\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n },\n }\n}\n\nexport function createLaunchdAgentProvider(ctx: BootProviderContext): BootProvider {\n return createLaunchdProvider(ctx, 'agent')\n}\n\nexport function createLaunchdDaemonProvider(ctx: BootProviderContext): BootProvider {\n return createLaunchdProvider(ctx, 'daemon')\n}\n", "/**\n * freedesktop XDG autostart: `~/.config/autostart/<unitName>.desktop`.\n * This runs at login, never at boot, and needs no privilege. `Exec=` is not a\n * shell, so every word is quoted for the desktop entry parser and `$`/`%` are\n * escaped rather than expanded.\n */\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport type { BootCandidate, BootState } from '../shared/contracts.js'\nimport type { BootActionResult, BootProvider, BootProviderContext, BootProviderStatus, BootSpec } from './types.js'\nimport { assertAbsolute, assertArg, assertEnvKey, assertLabel, assertMarker, assertUnitName, desktopExec } from './escape.js'\nimport { bootState, configHome, errorMessage, failed, inspectOwned, posixJoin, removeOwned, writeOwned } from './common.js'\n\nfunction validate(spec: BootSpec): void {\n assertUnitName(spec.unitName)\n assertMarker(spec.marker)\n assertLabel(spec.label)\n assertAbsolute(spec.command, 'spec.command')\n assertAbsolute(spec.cwd, 'spec.cwd')\n for (const arg of spec.args)\n assertArg(arg)\n for (const key of Object.keys(spec.env))\n assertEnvKey(key)\n}\n\nexport function xdgDesktopEntry(spec: BootSpec): string {\n validate(spec)\n return `${[\n '[Desktop Entry]',\n 'Type=Application',\n `Name=${spec.label}`,\n `Comment=home-hosted daemon, managed by ${spec.marker}`,\n `Exec=${desktopExec(spec.command, spec.args)}`,\n `Path=${spec.cwd}`,\n 'Terminal=false',\n 'X-GNOME-Autostart-enabled=true',\n `X-HomeHosted-Marker=${spec.marker}`,\n '',\n ].join('\\n')}`\n}\n\nfunction desktopFlag(text: string, key: string): string | null {\n for (const line of text.split('\\n')) {\n const trimmed = line.trim()\n if (trimmed.startsWith(`${key}=`))\n return trimmed.slice(key.length + 1).trim()\n }\n return null\n}\n\nexport function createXdgAutostartProvider(ctx: BootProviderContext): BootProvider {\n const mechanism = 'xdg-autostart' as const\n const unitOf = (spec: BootSpec): string => `${assertUnitName(spec.unitName)}.desktop`\n const pathOf = (spec: BootSpec): string => posixJoin(configHome(ctx), 'autostart', unitOf(spec))\n\n return {\n mechanism,\n\n async detect(): Promise<BootCandidate> {\n if (ctx.platform !== 'linux')\n return { mechanism, available: false, bootCapable: false, privileged: false, reason: 'XDG autostart is Linux-only' }\n return {\n mechanism,\n available: true,\n bootCapable: false,\n privileged: true,\n reason: `a .desktop entry under ${posixJoin(configHome(ctx), 'autostart')} needs no privilege, but it starts at login rather than at boot`,\n }\n },\n\n async status(spec: BootSpec): Promise<BootProviderStatus> {\n try {\n const file = pathOf(spec)\n const own = inspectOwned(file, assertMarker(spec.marker))\n if (own.exists && !own.owned)\n return { state: 'not-installed', unitPath: file, detail: own.reason ?? 'foreign file', commands: [] }\n if (!own.owned || own.text === null)\n return { state: 'not-installed', unitPath: file, detail: `no autostart entry at ${file}`, commands: [] }\n const enabled = desktopFlag(own.text, 'X-GNOME-Autostart-enabled') !== 'false'\n && desktopFlag(own.text, 'Hidden') !== 'true'\n const state: BootState = bootState(true, enabled, false)\n return {\n state,\n unitPath: file,\n detail: `${file} is present; ${enabled ? 'it starts at login' : 'it is disabled'} (login scope, not boot)`,\n commands: [],\n }\n }\n catch (error) {\n return { state: 'not-installed', unitPath: null, detail: errorMessage(error), commands: [] }\n }\n },\n\n async install(spec: BootSpec): Promise<BootActionResult> {\n try {\n validate(spec)\n const file = pathOf(spec)\n fs.mkdirSync(path.dirname(file), { recursive: true })\n const write = writeOwned(file, spec.marker, xdgDesktopEntry(spec), 0o644)\n if (write.refusal)\n return failed(write.refusal)\n\n const text = inspectOwned(file, spec.marker).text\n const enabled = text !== null\n && desktopFlag(text, 'X-GNOME-Autostart-enabled') !== 'false'\n && desktopFlag(text, 'Hidden') !== 'true'\n if (!enabled)\n return failed(`${file} was written but does not read back as enabled`, { changed: write.changed })\n\n return {\n ok: true,\n changed: write.changed,\n detail: write.changed\n ? `${file} installed; it starts at login (not at boot)`\n : `${file} was already installed and enabled`,\n commands: [],\n needsPrivilege: false,\n }\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n },\n\n async uninstall(spec: BootSpec): Promise<BootActionResult> {\n try {\n const file = pathOf(spec)\n const own = inspectOwned(file, spec.marker)\n if (own.exists && !own.owned)\n return failed(own.reason ?? 'foreign file')\n const remove = removeOwned(file, spec.marker)\n if (remove.refusal)\n return failed(remove.refusal)\n return {\n ok: true,\n changed: remove.removed,\n detail: remove.removed ? `removed ${file}` : `${file} was already gone`,\n commands: [],\n needsPrivilege: false,\n }\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n },\n }\n}\n", "/**\n * Windows: the per-user `Run` key (login scope, no admin) and a scheduled task\n * (admin). `sc.exe` is never used \u2014 a plain Node process has no service\n * dispatcher and would fail with error 1053.\n *\n * The `Run` key starts *every* value it holds, so the ownership marker cannot\n * live beside the command there; it lives under this plugin's own key\n * (`HKCU\\Software\\home-hosted`), and a `Run` value is only touched when that\n * marker proves we wrote it.\n */\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport type { BootCandidate, BootState } from '../shared/contracts.js'\nimport type { BootActionResult, BootProvider, BootProviderContext, BootProviderStatus, BootSpec } from './types.js'\nimport {\n assertAbsolute,\n assertArg,\n assertEnvKey,\n assertLabel,\n assertMarker,\n assertRegistryValueName,\n assertUnitName,\n batchCommandLine,\n powershellLiteral,\n windowsArg,\n windowsCommandLine,\n windowsDisplayCommand,\n xmlEscape,\n xmlUnescape,\n} from './escape.js'\nimport { bootState, errorMessage, failed, inspectOwned, localAppData, removeOwned, tempDir, writeOwned } from './common.js'\n\nexport const RUN_KEY = 'HKCU\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Run'\nexport const MARKER_KEY = 'HKCU\\\\Software\\\\home-hosted'\nconst RUN_VALUE_LIMIT = 260\n\nfunction validate(spec: BootSpec): void {\n assertUnitName(spec.unitName)\n assertMarker(spec.marker)\n assertLabel(spec.label)\n assertAbsolute(spec.command, 'spec.command')\n assertAbsolute(spec.cwd, 'spec.cwd')\n for (const arg of spec.args)\n assertArg(arg)\n for (const key of Object.keys(spec.env))\n assertEnvKey(key)\n}\n\nfunction codeOf(result: { code: number | null, error?: string | null }): number | null {\n return result.error ? null : result.code\n}\n\nfunction problem(run: { code: number | null, error?: string | null, stdout: string, stderr: string }, command: string): string | null {\n const code = codeOf(run)\n if (code === 0)\n return null\n if (code === null)\n return run.error ? `${command}: ${run.error}` : `${command}: no exit code`\n return `${command} exited ${code}: ${(run.stderr || run.stdout).trim() || '(no output)'}`\n}\n\ninterface RegValue {\n exists: boolean\n data: string | null\n}\n\nasync function queryReg(ctx: BootProviderContext, key: string, name: string): Promise<RegValue> {\n const res = await ctx.run('reg.exe', ['query', key, '/v', name])\n if (res.error || res.code !== 0)\n return { exists: false, data: null }\n for (const line of res.stdout.split(/\\r?\\n/)) {\n const match = /^\\s{2,}(.+?)\\s{2,}(REG_[A-Z_]+)\\s{2,}(.*)$/.exec(line)\n if (match && match[1]?.trim() === name)\n return { exists: true, data: (match[3] ?? '').trim() }\n }\n return { exists: false, data: null }\n}\n\nexport interface WindowsRunPayload {\n /** The exact `Run` value data. */\n data: string\n /** Set when the command line exceeded the `Run` value limit and a `.cmd` wrapper is needed. */\n wrapperPath: string | null\n wrapperContent: string | null\n}\n\nexport function windowsRunPayload(ctx: BootProviderContext, spec: BootSpec): WindowsRunPayload {\n const direct = windowsCommandLine(spec.command, spec.args)\n if (direct.length <= RUN_VALUE_LIMIT)\n return { data: direct, wrapperPath: null, wrapperContent: null }\n const wrapperPath = path.join(localAppData(ctx), 'home-hosted', `${spec.unitName}.cmd`)\n return {\n data: `cmd.exe /c ${windowsArg(wrapperPath)}`,\n wrapperPath,\n wrapperContent: `@echo off\\r\\nrem ${spec.marker}\\r\\n${batchCommandLine(spec.command, spec.args)}\\r\\n`,\n }\n}\n\nfunction createWindowsRunProviderImpl(ctx: BootProviderContext): BootProvider {\n const mechanism = 'windows-run' as const\n const nameOf = (spec: BootSpec): string => assertRegistryValueName(assertUnitName(spec.unitName))\n\n const addValue = (key: string, name: string, data: string) =>\n ctx.run('reg.exe', ['add', key, '/v', name, '/t', 'REG_SZ', '/d', data, '/f'])\n\n return {\n mechanism,\n\n async detect(): Promise<BootCandidate> {\n if (ctx.platform !== 'win32')\n return { mechanism, available: false, bootCapable: false, privileged: false, reason: 'the Run key is Windows-only' }\n return {\n mechanism,\n available: true,\n bootCapable: false,\n privileged: true,\n reason: `HKCU\\\\\u2026\\\\Run needs no admin, but it starts at login rather than at boot`,\n }\n },\n\n async status(spec: BootSpec): Promise<BootProviderStatus> {\n try {\n const name = nameOf(spec)\n const marker = assertMarker(spec.marker)\n const value = await queryReg(ctx, RUN_KEY, name)\n if (!value.exists)\n return { state: 'not-installed', unitPath: RUN_KEY, detail: `no ${RUN_KEY}\\\\${name} value`, commands: [] }\n const markerValue = await queryReg(ctx, MARKER_KEY, name)\n const owned = markerValue.data?.includes(marker) === true\n if (!owned)\n return { state: 'not-installed', unitPath: RUN_KEY, detail: `${name} exists under ${RUN_KEY} but is not marked as ours; refusing to treat it as this plugin's entry`, commands: [] }\n const state: BootState = bootState(true, true, false)\n return { state, unitPath: RUN_KEY, detail: `${RUN_KEY}\\\\${name} starts at login (not at boot)`, commands: [] }\n }\n catch (error) {\n return { state: 'not-installed', unitPath: RUN_KEY, detail: errorMessage(error), commands: [] }\n }\n },\n\n async install(spec: BootSpec): Promise<BootActionResult> {\n try {\n validate(spec)\n const name = nameOf(spec)\n const marker = assertMarker(spec.marker)\n const payload = windowsRunPayload(ctx, spec)\n const wrapperExists = payload.wrapperPath !== null && fs.existsSync(payload.wrapperPath)\n const wrapperOwn = payload.wrapperPath ? inspectOwned(payload.wrapperPath, marker) : null\n if (wrapperOwn?.exists && !wrapperOwn.owned)\n return failed(wrapperOwn.reason ?? 'foreign wrapper')\n\n const markerValue = await queryReg(ctx, MARKER_KEY, name)\n const owned = markerValue.data?.includes(marker) === true\n const current = await queryReg(ctx, RUN_KEY, name)\n // A value the marker does not prove is ours is never touched and never\n // claimed, even when it already equals what we would write.\n if (current.exists && !owned)\n return failed(`${RUN_KEY}\\\\${name} already exists and was not written by this plugin; refusing to overwrite it`)\n\n const commands: string[] = [\n windowsDisplayCommand('reg.exe', ['add', RUN_KEY, '/v', name, '/t', 'REG_SZ', '/d', payload.data, '/f']),\n ]\n\n let changed = false\n if (payload.wrapperPath && payload.wrapperContent) {\n const write = writeOwned(payload.wrapperPath, marker, payload.wrapperContent, 0o644)\n if (write.refusal)\n return failed(write.refusal)\n changed = write.changed || changed\n }\n\n if (!current.exists || current.data !== payload.data) {\n const add = await addValue(RUN_KEY, name, payload.data)\n const addProblem = problem(add, commands[0] ?? 'reg.exe add')\n if (addProblem)\n return failed(addProblem, { changed, commands })\n changed = true\n }\n if (!owned) {\n const mark = await addValue(MARKER_KEY, name, marker)\n const markProblem = problem(mark, windowsDisplayCommand('reg.exe', ['add', MARKER_KEY, '/v', name, '/t', 'REG_SZ', '/d', marker, '/f']))\n if (markProblem)\n return failed(markProblem, { changed, commands })\n changed = true\n }\n\n const after = await queryReg(ctx, RUN_KEY, name)\n if (after.data !== payload.data)\n return failed(`${RUN_KEY}\\\\${name} does not read back as the value that was written`, { changed, commands })\n\n // A wrapper we no longer need is cleaned up so the Run value converges on the direct form.\n if (!payload.wrapperPath && wrapperExists && wrapperOwn?.owned) {\n removeOwned(path.join(localAppData(ctx), 'home-hosted', `${spec.unitName}.cmd`), marker)\n }\n\n return {\n ok: true,\n changed,\n detail: changed ? `${RUN_KEY}\\\\${name} installed; it starts at login (not at boot)` : `${RUN_KEY}\\\\${name} was already installed`,\n commands: [],\n needsPrivilege: false,\n }\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n },\n\n async uninstall(spec: BootSpec): Promise<BootActionResult> {\n try {\n const name = nameOf(spec)\n const marker = assertMarker(spec.marker)\n const current = await queryReg(ctx, RUN_KEY, name)\n const markerValue = await queryReg(ctx, MARKER_KEY, name)\n const owned = markerValue.data?.includes(marker) === true\n if (current.exists && !owned) {\n const payload = windowsRunPayload(ctx, spec)\n const wrapperOwned = payload.wrapperPath !== null ? inspectOwned(payload.wrapperPath, marker).owned : false\n if (current.data !== payload.data && !wrapperOwned)\n return failed(`${RUN_KEY}\\\\${name} is not marked as ours; refusing to delete a foreign Run value`)\n }\n\n let changed = false\n if (current.exists) {\n const del = await ctx.run('reg.exe', ['delete', RUN_KEY, '/v', name, '/f'])\n const delCode = codeOf(del)\n if (delCode !== 0 && delCode !== 1)\n return failed(problem(del, windowsDisplayCommand('reg.exe', ['delete', RUN_KEY, '/v', name, '/f'])) ?? 'reg.exe delete failed')\n changed = delCode === 0\n }\n if (owned) {\n await ctx.run('reg.exe', ['delete', MARKER_KEY, '/v', name, '/f'])\n changed = true\n }\n\n const payload = windowsRunPayload(ctx, spec)\n if (payload.wrapperPath) {\n const remove = removeOwned(payload.wrapperPath, marker)\n if (remove.refusal)\n return failed(remove.refusal)\n changed = remove.removed || changed\n }\n const stale = path.join(localAppData(ctx), 'home-hosted', `${spec.unitName}.cmd`)\n const staleRemove = removeOwned(stale, marker)\n if (staleRemove.refusal)\n return failed(staleRemove.refusal)\n changed = staleRemove.removed || changed\n\n const after = await queryReg(ctx, RUN_KEY, name)\n if (after.exists)\n return failed(`${RUN_KEY}\\\\${name} still exists after removal`, { changed })\n\n return {\n ok: true,\n changed,\n detail: changed ? `removed ${RUN_KEY}\\\\${name}` : `${RUN_KEY}\\\\${name} was already gone`,\n commands: [],\n needsPrivilege: false,\n }\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n },\n }\n}\n\n// ---------------------------------------------------------------------------\n// Scheduled task\n// ---------------------------------------------------------------------------\n\nexport function scheduledTaskXml(spec: BootSpec): string {\n validate(spec)\n const args = spec.args.map(windowsArg).join(' ')\n return `${[\n '<?xml version=\"1.0\" encoding=\"UTF-16\"?>',\n '<Task version=\"1.2\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">',\n '<RegistrationInfo>',\n `<Description>${xmlEscape(spec.marker)}</Description>`,\n '</RegistrationInfo>',\n '<Triggers>',\n '<LogonTrigger>',\n '<Enabled>true</Enabled>',\n '</LogonTrigger>',\n '</Triggers>',\n '<Principals>',\n '<Principal id=\"Author\">',\n '<LogonType>InteractiveToken</LogonType>',\n '<RunLevel>LeastPrivilege</RunLevel>',\n '</Principal>',\n '</Principals>',\n '<Settings>',\n '<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>',\n '<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>',\n '<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>',\n '<StartWhenAvailable>true</StartWhenAvailable>',\n '<RestartOnFailure>',\n '<Interval>PT1M</Interval>',\n '<Count>3</Count>',\n '</RestartOnFailure>',\n '<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>',\n '</Settings>',\n '<Actions Context=\"Author\">',\n '<Exec>',\n `<Command>${xmlEscape(spec.command)}</Command>`,\n `<Arguments>${xmlEscape(args)}</Arguments>`,\n `<WorkingDirectory>${xmlEscape(spec.cwd)}</WorkingDirectory>`,\n '</Exec>',\n '</Actions>',\n '</Task>',\n '',\n ].join('\\r\\n')}`\n}\n\nexport function registerTaskScript(spec: BootSpec): string {\n validate(spec)\n const args = spec.args.map(windowsArg).join(' ')\n return [\n `$action = New-ScheduledTaskAction -Execute ${powershellLiteral(spec.command)} -Argument ${powershellLiteral(args)} -WorkingDirectory ${powershellLiteral(spec.cwd)}`,\n '$trigger = New-ScheduledTaskTrigger -AtLogOn',\n '$settings = New-ScheduledTaskSettingsSet -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1) -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries',\n `Register-ScheduledTask -TaskName ${powershellLiteral(spec.unitName)} -Action $action -Trigger $trigger -Settings $settings -Description ${powershellLiteral(spec.marker)} -Force | Out-Null`,\n ].join('; ')\n}\n\nexport function unregisterTaskScript(name: string): string {\n return `Unregister-ScheduledTask -TaskName ${powershellLiteral(assertUnitName(name))} -Confirm:$false`\n}\n\nfunction xmlTag(xml: string, tag: string): string | null {\n const match = new RegExp(`<${tag}>([\\\\s\\\\S]*?)</${tag}>`).exec(xml)\n return match?.[1] === undefined ? null : xmlUnescape(match[1].trim())\n}\n\ninterface TaskInfo {\n exists: boolean\n xml: string | null\n marked: boolean\n matches: boolean\n}\n\nexport function createWindowsTaskProvider(ctx: BootProviderContext): BootProvider {\n const mechanism = 'windows-task' as const\n const nameOf = (spec: BootSpec): string => assertUnitName(spec.unitName)\n\n const query = async (name: string): Promise<{ exists: boolean, xml: string | null }> => {\n const res = await ctx.run('schtasks.exe', ['/Query', '/TN', name, '/XML'])\n if (res.error || res.code !== 0)\n return { exists: false, xml: null }\n return { exists: true, xml: res.stdout }\n }\n\n const inspect = async (spec: BootSpec): Promise<TaskInfo> => {\n const found = await query(nameOf(spec))\n if (!found.exists || found.xml === null)\n return { exists: false, xml: null, marked: false, matches: false }\n const marked = xmlUnescape(found.xml).includes(spec.marker)\n const args = spec.args.map(windowsArg).join(' ')\n const matches = marked\n && xmlTag(found.xml, 'Command') === spec.command\n && xmlTag(found.xml, 'Arguments') === args\n && (xmlTag(found.xml, 'WorkingDirectory') ?? spec.cwd) === spec.cwd\n return { exists: true, xml: found.xml, marked, matches }\n }\n\n const hasRegisterCmdlet = async (): Promise<boolean> => {\n const probe = await ctx.run('powershell.exe', ['-NoProfile', '-Command', 'Get-Command Register-ScheduledTask'])\n return probe.error === undefined || probe.error === null\n ? /Register-ScheduledTask/.test(probe.stdout)\n : false\n }\n\n const isElevated = async (): Promise<boolean> => {\n const script = '([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)'\n const probe = await ctx.run('powershell.exe', ['-NoProfile', '-Command', script])\n return probe.error === undefined || probe.error === null ? /^true$/im.test(probe.stdout.trim()) : false\n }\n\n return {\n mechanism,\n\n async detect(): Promise<BootCandidate> {\n if (ctx.platform !== 'win32')\n return { mechanism, available: false, bootCapable: false, privileged: false, reason: 'scheduled tasks are Windows-only' }\n const elevated = await isElevated()\n return {\n mechanism,\n available: elevated,\n bootCapable: false,\n privileged: elevated,\n reason: elevated\n ? 'administrator rights are available; the task is registered for logon (not for boot)'\n : 'registering a scheduled task needs an elevated process',\n }\n },\n\n async status(spec: BootSpec): Promise<BootProviderStatus> {\n try {\n const name = nameOf(spec)\n const info = await inspect(spec)\n if (!info.exists)\n return { state: 'not-installed', unitPath: null, detail: `no scheduled task named ${name}`, commands: [] }\n if (!info.marked)\n return { state: 'not-installed', unitPath: null, detail: `task ${name} exists but does not carry this plugin's marker; refusing to treat it as this plugin's entry`, commands: [] }\n const state: BootState = bootState(true, true, false)\n return { state, unitPath: null, detail: `scheduled task ${name} is registered (runs at logon, not at boot)`, commands: [] }\n }\n catch (error) {\n return { state: 'not-installed', unitPath: null, detail: errorMessage(error), commands: [] }\n }\n },\n\n async install(spec: BootSpec): Promise<BootActionResult> {\n try {\n validate(spec)\n const name = nameOf(spec)\n const info = await inspect(spec)\n if (info.exists && !info.marked)\n return failed(`scheduled task ${name} already exists and was not written by this plugin; refusing to overwrite it`)\n if (!(await isElevated()))\n return failed('registering a scheduled task needs an elevated process', { needsPrivilege: true })\n\n const elevatedCommands = [\n windowsDisplayCommand('powershell.exe', ['-NoProfile', '-Command', unregisterTaskScript(name)]),\n windowsDisplayCommand('schtasks.exe', ['/Query', '/TN', name, '/XML']),\n ]\n\n if (info.exists && info.matches) {\n const verify = await query(name)\n if (verify.exists)\n return { ok: true, changed: false, detail: `scheduled task ${name} is already registered`, commands: [], needsPrivilege: true }\n }\n\n const cmdlet = await hasRegisterCmdlet()\n if (cmdlet) {\n const script = registerTaskScript(spec)\n const res = await ctx.run('powershell.exe', ['-NoProfile', '-Command', script])\n if (codeOf(res) !== 0)\n return failed(problem(res, windowsDisplayCommand('powershell.exe', ['-NoProfile', '-Command', script])) ?? 'Register-ScheduledTask failed', { needsPrivilege: true, commands: elevatedCommands })\n }\n else {\n const xmlFile = path.join(tempDir(ctx), `${name}.xml`)\n fs.mkdirSync(path.dirname(xmlFile), { recursive: true })\n fs.writeFileSync(xmlFile, Buffer.from(`\\uFEFF${scheduledTaskXml(spec)}`, 'utf16le'))\n const createCommand = windowsDisplayCommand('schtasks.exe', ['/Create', '/TN', name, '/XML', xmlFile, '/F'])\n const create = await ctx.run('schtasks.exe', ['/Create', '/TN', name, '/XML', xmlFile, '/F'])\n if (codeOf(create) !== 0)\n return failed(problem(create, createCommand) ?? 'schtasks /Create failed', { needsPrivilege: true, commands: [createCommand] })\n fs.rmSync(xmlFile, { force: true })\n }\n\n const after = await query(name)\n if (!after.exists)\n return failed(`scheduled task ${name} was not found after registration`, { changed: true, needsPrivilege: true, commands: elevatedCommands })\n\n return {\n ok: true,\n changed: true,\n detail: `scheduled task ${name} registered (runs at logon, not at boot)`,\n commands: [],\n needsPrivilege: true,\n }\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n },\n\n async uninstall(spec: BootSpec): Promise<BootActionResult> {\n try {\n const name = nameOf(spec)\n const info = await inspect(spec)\n if (!info.exists)\n return { ok: true, changed: false, detail: `no scheduled task named ${name}; already gone`, commands: [], needsPrivilege: false }\n if (!info.marked)\n return failed(`scheduled task ${name} is not marked as ours; refusing to delete a foreign task`)\n if (!(await isElevated()))\n return failed('deleting a scheduled task needs an elevated process', { needsPrivilege: true })\n\n const cmdlet = await hasRegisterCmdlet()\n const res = cmdlet\n ? await ctx.run('powershell.exe', ['-NoProfile', '-Command', unregisterTaskScript(name)])\n : await ctx.run('schtasks.exe', ['/Delete', '/TN', name, '/F'])\n const code = codeOf(res)\n if (code !== 0 && code !== 1)\n return failed(problem(res, cmdlet ? 'powershell.exe Unregister-ScheduledTask' : windowsDisplayCommand('schtasks.exe', ['/Delete', '/TN', name, '/F'])) ?? 'unregistering the task failed', { needsPrivilege: true })\n\n const after = await query(name)\n if (after.exists)\n return failed(`scheduled task ${name} still exists after removal`, { changed: true, needsPrivilege: true })\n\n return {\n ok: true,\n changed: true,\n detail: `unregistered scheduled task ${name}`,\n commands: [],\n needsPrivilege: true,\n }\n }\n catch (error) {\n return failed(errorMessage(error))\n }\n },\n }\n}\n\nexport function createWindowsRunProvider(ctx: BootProviderContext): BootProvider {\n return createWindowsRunProviderImpl(ctx)\n}\n", "/**\n * The two terminals of the ladder: a container (an OS boot entry would land\n * outside it, so the right answer is the container's own restart policy) and a\n * platform this plugin has no mechanism for.\n */\n\nimport type { BootCandidate } from '../shared/contracts.js'\nimport type { BootActionResult, BootProvider, BootProviderContext, BootProviderStatus, BootSpec } from './types.js'\nimport { readText } from '../util/fsx.js'\nimport { failed, existsOf } from './common.js'\n\nconst RESTART_POLICY = 'use the container restart policy instead: `docker run --restart unless-stopped`, or `restart: unless-stopped` in a compose file'\n\n/** A human-readable description of the container we are inside, or null. */\nexport function detectContainer(ctx: BootProviderContext): string | null {\n if (existsOf(ctx, '/.dockerenv'))\n return 'Docker (/.dockerenv)'\n if (existsOf(ctx, '/run/.containerenv'))\n return 'Podman (/run/.containerenv)'\n if (ctx.env.container?.trim())\n return `container environment (container=${ctx.env.container.trim()})`\n const cgroup = existsOf(ctx, '/proc/1/cgroup') ? readText('/proc/1/cgroup') : null\n if (cgroup) {\n if (cgroup.includes('kubepods'))\n return 'Kubernetes (cgroup kubepods)'\n if (cgroup.includes('docker'))\n return 'Docker (cgroup docker)'\n if (cgroup.includes('lxc'))\n return 'LXC (cgroup lxc)'\n if (cgroup.includes('containerd'))\n return 'containerd (cgroup)'\n }\n return null\n}\n\nexport function createContainerProvider(ctx: BootProviderContext): BootProvider {\n const mechanism = 'container' as const\n return {\n mechanism,\n\n async detect(): Promise<BootCandidate> {\n const container = detectContainer(ctx)\n return {\n mechanism,\n available: container !== null,\n bootCapable: false,\n privileged: false,\n reason: container === null\n ? 'this process does not look like it is inside a container'\n : `this process runs inside ${container}; an OS boot entry would live on the host, not here`,\n }\n },\n\n async status(): Promise<BootProviderStatus> {\n const container = detectContainer(ctx)\n return {\n state: 'unsupported',\n unitPath: null,\n detail: container === null\n ? 'no container detected'\n : `running inside ${container}; ${RESTART_POLICY}`,\n commands: [],\n }\n },\n\n async install(): Promise<BootActionResult> {\n const container = detectContainer(ctx)\n return failed(\n container === null\n ? `no container detected; ${RESTART_POLICY}`\n : `this process runs inside ${container}; an OS boot entry would be installed outside the container \u2014 ${RESTART_POLICY}`,\n )\n },\n\n async uninstall(): Promise<BootActionResult> {\n return failed('nothing to uninstall: this plugin installed no OS boot entry for a container; the container restart policy is what starts it')\n },\n }\n}\n\nexport function createUnsupportedProvider(platform: NodeJS.Platform): BootProvider {\n const mechanism = 'unsupported' as const\n const reason = `no boot mechanism is known for ${platform}`\n return {\n mechanism,\n\n async detect(): Promise<BootCandidate> {\n return { mechanism, available: true, bootCapable: false, privileged: false, reason }\n },\n\n async status(_spec: BootSpec): Promise<BootProviderStatus> {\n return { state: 'unsupported', unitPath: null, detail: reason, commands: [] }\n },\n\n async install(_spec: BootSpec): Promise<BootActionResult> {\n return failed(`this plugin has no boot mechanism for ${platform}; start home-hosted from your platform's own service manager`)\n },\n\n async uninstall(_spec: BootSpec): Promise<BootActionResult> {\n return failed(`this plugin has no boot mechanism for ${platform}, so it installed nothing to remove`)\n },\n }\n}\n", "/**\n * Writing `servers.config.json` directly, for the case where the panel is not\n * running (no API to call, and nobody watching the file).\n *\n * When the panel *is* running this path is a fallback: its file watcher treats\n * an external edit as a real change, and a newly added `autostart` entry is\n * started at once. `addEntrySafely` therefore writes the entry disabled first\n * and only then flips `autostart`, which the watcher sees as a changed\n * definition \u2014 applied on that entry's next start, never started now.\n */\nimport fs from 'node:fs'\nimport type { ServerEntry, ServerEntryPatch } from '../shared/contracts.js'\nimport { readJson, writeFileAtomic } from '../util/fsx.js'\nimport { configFile } from '../util/paths.js'\n\nexport interface RawConfig {\n meta?: Record<string, unknown>\n servers?: ServerEntry[]\n [key: string]: unknown\n}\n\nexport interface ConfigReadResult {\n raw: RawConfig | null\n exists: boolean\n error: string | null\n}\n\nexport function readConfig(home: string): ConfigReadResult {\n const file = configFile(home)\n const raw = readJson<RawConfig>(file)\n if (raw === null) {\n // Distinguish \"no file yet\" from \"unreadable\", because only the first is safe to create.\n const exists = fs.existsSync(file)\n return { raw: null, exists, error: exists ? 'the config file could not be parsed' : null }\n }\n if (!Array.isArray(raw.servers) && raw.servers !== undefined)\n return { raw: null, exists: true, error: 'the config file has a servers field that is not an array' }\n return { raw, exists: true, error: null }\n}\n\n/**\n * Write the file back with home-hosted's own `meta` contract: a config records\n * the release that wrote it and the shape it wrote, so an unstamped file still\n * reads as the current schema.\n */\nexport function writeConfig(home: string, raw: RawConfig, writtenBy = 'dsh-home-hosted'): void {\n const meta = { schema: 1, ...(raw.meta ?? {}), writtenBy }\n const next: RawConfig = { ...raw, meta }\n writeFileAtomic(configFile(home), `${JSON.stringify(next, null, 2)}\\n`)\n}\n\nexport function findEntry(raw: RawConfig, id: string): ServerEntry | null {\n return (raw.servers ?? []).find(entry => entry.id === id) ?? null\n}\n\n/** Insert or replace one entry, preserving every other key in the file. */\nexport function upsertEntry(raw: RawConfig, entry: ServerEntry): RawConfig {\n const servers = [...(raw.servers ?? [])]\n const index = servers.findIndex(candidate => candidate.id === entry.id)\n if (index >= 0)\n servers[index] = entry\n else\n servers.push(entry)\n return { ...raw, servers }\n}\n\nexport function patchEntry(raw: RawConfig, id: string, patch: ServerEntryPatch): RawConfig {\n const servers = (raw.servers ?? []).map((entry) => {\n if (entry.id !== id)\n return entry\n const merged: ServerEntry = { ...entry, ...patch }\n if (patch.stop !== undefined && typeof entry.stop === 'object' && entry.stop !== null)\n merged.stop = { ...entry.stop, ...patch.stop }\n return merged\n })\n return { ...raw, servers }\n}\n\nexport function removeEntry(raw: RawConfig, id: string): RawConfig {\n return { ...raw, servers: (raw.servers ?? []).filter(entry => entry.id !== id) }\n}\n", "/**\n * Where things live. The harness home comes from `$DSH_HOME`; home-hosted's\n * state comes from `$HHOSTED_HOME`. Neither is ever hard-coded into a file this\n * plugin writes \u2014 the resolved value is written into generated units instead.\n */\nimport os from 'node:os'\nimport path from 'node:path'\n\nexport function expandHome(value: string): string {\n if (value === '~')\n return os.homedir()\n if (value.startsWith('~/') || value.startsWith('~\\\\'))\n return path.join(os.homedir(), value.slice(2))\n return value\n}\n\n/** DeepSeek Harness home: `$DSH_HOME`, else `~/.dsh`. */\nexport function dshHome(): string {\n const configured = process.env.DSH_HOME?.trim()\n return configured ? path.resolve(expandHome(configured)) : path.join(os.homedir(), '.dsh')\n}\n\n/** home-hosted state root: `$HHOSTED_HOME`, else `~/.home-hosted`. */\nexport function homeHostedHome(): string {\n const configured = process.env.HHOSTED_HOME?.trim()\n return configured ? path.resolve(expandHome(configured)) : path.join(os.homedir(), '.home-hosted')\n}\n\n/** Where this plugin keeps its own durable state (settings, snapshots, token). */\nexport function pluginStateDir(override?: string): string {\n const configured = override?.trim()\n if (configured)\n return path.resolve(expandHome(configured))\n return path.join(dshHome(), 'dsh-home-hosted')\n}\n\n/** home-hosted's own tokens file, written by the panel at startup. */\nexport function runtimeFile(home = homeHostedHome()): string {\n return path.join(home, 'run.json')\n}\n\n/** home-hosted's secrets file (0600): proves whether an API token is enrolled. */\nexport function secretsFile(home = homeHostedHome()): string {\n return path.join(home, '.control-secrets.json')\n}\n\nexport function configFile(home = homeHostedHome()): string {\n return path.join(home, 'servers.config.json')\n}\n", "/**\n * The server entry that represents the running harness.\n *\n * An existing entry is never rewritten: this plugin only owns `autostart`,\n * `onPortConflict` and `stop.killPortHolders`. A generated entry (only used when\n * there is none) mirrors how this process was actually launched where that is\n * knowable, and otherwise falls back to the `dsh web` app arguments.\n */\nimport path from 'node:path'\nimport process from 'node:process'\nimport type { ServerEntry } from '../shared/contracts.js'\nimport type { CliLaunch } from './launch.js'\nimport { resolveShimmedCli, which } from './launch.js'\n\n/**\n * Which profile this process is running.\n *\n * `DSH_PROFILE` alone is not trustworthy: it can be inherited from a parent\n * shell that ran a different profile (that is how an entry once ended up booting\n * `web` under another profile's home). The process's own argv is authoritative,\n * then the profile directory the launcher pointed at, then the env var.\n */\nexport function detectProfile(argv: readonly string[], env: Record<string, string | undefined> = {}): string {\n for (let index = 0; index < argv.length; index += 1) {\n const arg = argv[index]\n if (arg === '--profile' && typeof argv[index + 1] === 'string' && !argv[index + 1]!.startsWith('-'))\n return argv[index + 1]!\n if (arg?.startsWith('--profile='))\n return arg.slice('--profile='.length)\n }\n\n const dir = env.DSH_PROFILE_DIR\n if (typeof dir === 'string' && dir.length > 0) {\n const base = path.basename(dir)\n if (base.length > 0 && base !== '.' && base !== path.sep)\n return base\n }\n\n const app = argv.slice(2).find(candidate => candidate !== undefined && !candidate.startsWith('-'))\n if (app !== undefined && app.length > 0)\n return app\n\n const fromEnv = env.DSH_PROFILE\n return typeof fromEnv === 'string' && fromEnv.length > 0 ? fromEnv : 'web'\n}\n\nexport interface DshFacts {\n id: string\n port: number | null\n host: string\n profile: string | null\n dshHome: string\n launch: CliLaunch | null\n}\n\n/** Where the running harness's own CLI entry is, if we can tell. */\nexport async function resolveDshLaunch(): Promise<CliLaunch | null> {\n const fromArgv = process.argv[1]\n if (typeof fromArgv === 'string' && /\\.[cm]?js$/.test(fromArgv) && path.isAbsolute(fromArgv))\n return { program: process.execPath, args: [fromArgv], cliEntry: fromArgv, shimPath: null, source: 'entry' }\n const found = await which('dsh')\n return found === null ? null : resolveShimmedCli(found, process.execPath)\n}\n\nexport function buildDshEntry(facts: DshFacts): ServerEntry {\n const launch = facts.launch\n const entryArgs = launch?.args ?? []\n const profile = facts.profile === null || facts.profile === undefined ? 'web' : facts.profile\n\n const appArgs: string[] = []\n if (facts.port !== null) {\n appArgs.push(\n '--port', '{port}',\n '--host', '{host}',\n '--no-open',\n '--trusted-host', `localhost:{port}`,\n )\n if (facts.host === '0.0.0.0')\n appArgs.push('--trusted-host', '{lanIp}:{port}')\n }\n\n const launcherArgs = profile === 'web' ? ['web'] : ['--profile', profile]\n const args = [...entryArgs, ...launcherArgs, ...appArgs]\n\n return {\n id: facts.id,\n label: 'DSH web',\n enabled: true,\n autostart: true,\n command: launch?.program ?? 'dsh',\n args,\n bind: facts.host === '0.0.0.0' ? 'lan' : 'local',\n port: facts.port,\n cwd: process.cwd(),\n env: {},\n dataEnvs: { DSH_HOME: facts.dshHome },\n onPortConflict: 'kill',\n stop: { killPortHolders: true },\n health: {\n enabled: true,\n mode: 'http',\n http: { path: '/', method: 'GET', expectStatusBelow: 400, expectBody: '' },\n },\n }\n}\n", "/**\n * How the home-hosted daemon is launched, and what a boot entry for it contains.\n *\n * The executable is resolved to an absolute program plus argv: a generated boot\n * entry must not depend on a login shell's PATH. When the resolved command is a\n * package-manager shim, its `cmd-shim-target` comment names the real entry, and\n * node runs that directly \u2014 the same guarantee the shim itself gives.\n */\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport type { BootSpec } from '../boot/types.js'\nimport { run } from '../util/exec.js'\nimport { readText } from '../util/fsx.js'\n\nexport interface CliLaunch {\n program: string\n /** Args that must precede the command, e.g. the CLI entry path. */\n args: string[]\n cliEntry: string | null\n shimPath: string | null\n source: 'override' | 'entry' | 'shim-target' | 'shim'\n}\n\nexport async function which(command: string): Promise<string | null> {\n const probe = process.platform === 'win32' ? 'where.exe' : 'which'\n const result = await run(probe, [command], { timeoutMs: 5000 })\n if (result.code !== 0)\n return null\n const first = result.stdout.split(/\\r?\\n/).map(line => line.trim()).filter(Boolean)[0]\n return first ?? null\n}\n\n/** Turn a resolved CLI path into an absolute program + argv. */\nexport function resolveShimmedCli(absolute: string, nodePath = process.execPath): CliLaunch | null {\n if (!fs.existsSync(absolute))\n return null\n if (/\\.(?:mjs|cjs|js)$/.test(absolute))\n return { program: nodePath, args: [absolute], cliEntry: absolute, shimPath: null, source: 'entry' }\n\n const shimTarget = /^#\\s*cmd-shim-target=(.+)$/m.exec(readText(absolute) ?? '')?.[1]?.trim()\n if (shimTarget !== undefined && fs.existsSync(shimTarget))\n return { program: nodePath, args: [shimTarget], cliEntry: shimTarget, shimPath: absolute, source: 'shim-target' }\n\n // A shim with no readable target still works when node is on the entry's PATH.\n return { program: absolute, args: [], cliEntry: null, shimPath: absolute, source: 'shim' }\n}\n\nexport async function resolveHomeHostedLaunch(override?: string | null): Promise<CliLaunch | null> {\n const configured = override?.trim()\n const found = configured && configured.length > 0 ? configured : (await which('home-hosted')) ?? (await which('hh'))\n if (found === null || found === undefined)\n return null\n\n const launch = resolveShimmedCli(path.resolve(found))\n if (launch === null)\n return null\n return configured ? { ...launch, source: 'override' } : launch\n}\n\nexport interface HomeHostedFacts {\n home: string\n projectDir?: string | null\n version?: string | null\n}\n\n/** A deterministic environment for a boot-time entry, with absolute values. */\nexport function homeHostedEnv(facts: HomeHostedFacts, launch: CliLaunch, extra: Record<string, string> = {}): Record<string, string> {\n const dirs = [\n launch.shimPath === null ? null : path.dirname(launch.shimPath),\n path.dirname(process.execPath),\n ...(process.env.PATH ?? '').split(path.delimiter),\n '/usr/local/bin',\n '/usr/bin',\n '/bin',\n ].filter((dir): dir is string => typeof dir === 'string' && dir.length > 0)\n const seen = new Set<string>()\n const pathValue = dirs.filter((dir) => {\n if (seen.has(dir))\n return false\n seen.add(dir)\n return true\n }).join(path.delimiter)\n\n const env: Record<string, string> = {\n PATH: pathValue,\n HOME: process.env.HOME ?? process.env.USERPROFILE ?? '',\n HHOSTED_HOME: facts.home,\n ...extra,\n }\n if (facts.projectDir)\n env.HHOSTED_PROJECT = facts.projectDir\n return env\n}\n\nexport interface BootSpecOptions {\n stateDir: string\n marker?: string\n}\n\nexport function buildHomeHostedBootSpec(\n facts: HomeHostedFacts,\n launch: CliLaunch,\n options: BootSpecOptions,\n): BootSpec {\n const logDir = path.join(facts.home, '.logs')\n fs.mkdirSync(logDir, { recursive: true })\n const args = [...launch.args, 'up', '--foreground', '--home', facts.home]\n if (facts.projectDir)\n args.push('--project', facts.projectDir)\n\n return {\n command: launch.program,\n args,\n cwd: facts.projectDir ?? facts.home,\n env: homeHostedEnv(facts, launch),\n marker: options.marker ?? 'managed by dsh-home-hosted',\n unitName: 'home-hosted',\n label: 'home-hosted control panel',\n logDir,\n }\n}\n", "/**\n * What this plugin decides about a server entry, and how that intent maps onto\n * the entry: only the keys in `OWNED_ENTRY_KEYS` are ever written, so a person's\n * own command, args, env, health block and everything else survive untouched.\n */\nimport type { EntryIntent, OnPortConflict, ServerEntry, ServerEntryPatch } from '../shared/contracts.js'\n\nexport const DEFAULT_ON_PORT_CONFLICT: OnPortConflict = 'kill'\n\nexport function defaultIntent(id: string): EntryIntent {\n return {\n id,\n autostart: true,\n onPortConflict: DEFAULT_ON_PORT_CONFLICT,\n stopKillPortHolders: true,\n }\n}\n\n/** The owned keys as a patch, preserving any sibling keys inside `stop`. */\nexport function ownedPatch(intent: EntryIntent, live?: ServerEntry | null): ServerEntryPatch {\n const stop = (live?.stop ?? {}) as Record<string, unknown>\n return {\n autostart: intent.autostart,\n onPortConflict: intent.onPortConflict,\n stop: { ...stop, killPortHolders: intent.stopKillPortHolders },\n }\n}\n\n/** Owned keys whose live value differs from the intent. */\nexport function ownedDrift(live: ServerEntry | null, intent: EntryIntent): string[] {\n if (live === null)\n return ['missing entry']\n const drift: string[] = []\n if (live.autostart !== intent.autostart)\n drift.push('autostart')\n if (live.onPortConflict !== intent.onPortConflict)\n drift.push('onPortConflict')\n const killPortHolders = (live.stop as Record<string, unknown> | undefined)?.killPortHolders\n if (killPortHolders !== intent.stopKillPortHolders)\n drift.push('stop.killPortHolders')\n return drift\n}\n\n/** Only the owned keys, as they were before this plugin touched the entry. */\nexport function snapshotOwned(live: ServerEntry): ServerEntry {\n const snapshot: ServerEntry = { id: live.id }\n if (live.autostart !== undefined)\n snapshot.autostart = live.autostart\n if (live.onPortConflict !== undefined)\n snapshot.onPortConflict = live.onPortConflict\n if (typeof live.stop === 'object' && live.stop !== null) {\n const killPortHolders = (live.stop as Record<string, unknown>).killPortHolders\n if (typeof killPortHolders === 'boolean')\n snapshot.stop = { killPortHolders }\n }\n return snapshot\n}\n\n/**\n * Restore an entry to what it was before adoption. A key the snapshot does not\n * carry was inherited from the panel's defaults, and a PATCH cannot delete a\n * key, so it is restored to that schema default instead.\n */\nexport function restorePatch(live: ServerEntry, snapshot: ServerEntry | null): ServerEntryPatch {\n const stop = (live.stop ?? {}) as Record<string, unknown>\n const previous = (snapshot?.stop ?? {}) as Record<string, unknown>\n return {\n autostart: snapshot?.autostart ?? false,\n onPortConflict: snapshot?.onPortConflict ?? 'block',\n stop: {\n ...stop,\n killPortHolders: typeof previous.killPortHolders === 'boolean' ? previous.killPortHolders : false,\n },\n }\n}\n", "/**\n * Which home-hosted CLI this plugin drives.\n *\n * The plugin ships its own pinned copy as a dependency and prefers it, so the\n * version that runs the panel at boot is the version this plugin was built\n * against \u2014 not whatever `home-hosted` happens to be on PATH. Preferring a\n * global install is a supported setting, not an accident.\n *\n * Resolution order: the operator's `homeHostedCommand` override always wins,\n * then the preferred copy, then the other one as a fallback.\n */\nimport { createRequire } from 'node:module'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport type { CliCandidate, CliSource, CliStatus } from '../shared/contracts.js'\nimport { run } from '../util/exec.js'\nimport type { CliLaunch } from './launch.js'\nimport { resolveShimmedCli, which } from './launch.js'\n\n/** The range the plugin ships and is tested against. */\nexport const EXPECTED_RANGE = '^0.6.1'\n\n/** Oldest release whose API and config schema this plugin relies on. */\nexport const MIN_SUPPORTED_VERSION = '0.4.1'\n\n/** Oldest release whose config schema accepts `onPortConflict: kill`. */\nexport const MIN_KILL_VERSION = '0.6.0'\n\nexport type CliPreference = 'pinned' | 'global'\n\nexport interface CliResolution {\n launch: CliLaunch | null\n status: CliStatus\n}\n\nexport interface ResolveCliOptions {\n override?: string | null\n /** Which copy to run when both exist. */\n prefer?: CliPreference\n /** Test seam: the pinned package's manifest path, or null when it is not installed. */\n packageManifest?: () => string | null\n /** Test seam: ask a CLI for its own version. */\n readVersion?: (launch: CliLaunch) => Promise<string | null>\n /** Test seam: locate a command on PATH. */\n findOnPath?: (command: string) => Promise<string | null>\n timeoutMs?: number\n}\n\ninterface Candidate {\n candidate: CliCandidate\n launch: CliLaunch\n}\n\n/** Where the pinned `home-hosted` manifest is, resolved from this module. */\nexport function pinnedManifestPath(): string | null {\n try {\n return createRequire(import.meta.url).resolve('home-hosted/package.json')\n }\n catch {\n return null\n }\n}\n\n/** The `home-hosted` bin entry a package manifest declares. */\nexport function binEntryFromManifest(manifestPath: string): string | null {\n try {\n const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as { bin?: string | Record<string, string> }\n const declared = typeof manifest.bin === 'string'\n ? manifest.bin\n : manifest.bin?.['home-hosted'] ?? Object.values(manifest.bin ?? {})[0]\n return typeof declared === 'string' && declared.length > 0\n ? path.resolve(path.dirname(manifestPath), declared)\n : null\n }\n catch {\n return null\n }\n}\n\n/** The first `x.y.z[-pre]` in a CLI's output. */\nexport function parseVersion(output: string | null): string | null {\n const match = /(\\d+)\\.(\\d+)\\.(\\d+)(?:-([0-9A-Za-z.-]+))?/.exec(output ?? '')\n return match === null ? null : `${match[1]}.${match[2]}.${match[3]}${match[4] === undefined ? '' : `-${match[4]}`}`\n}\n\n/** Numeric comparison; a prerelease sorts below its own release. */\nexport function compareVersions(a: string, b: string): number {\n const split = (value: string): { parts: number[], pre: string | null } => {\n const [core, pre = null] = value.split('-', 2)\n return { parts: (core ?? '').split('.').map(part => Number.parseInt(part, 10) || 0), pre }\n }\n const left = split(a)\n const right = split(b)\n for (let index = 0; index < 3; index += 1) {\n const diff = (left.parts[index] ?? 0) - (right.parts[index] ?? 0)\n if (diff !== 0)\n return diff < 0 ? -1 : 1\n }\n if (left.pre === right.pre)\n return 0\n if (left.pre === null)\n return 1\n if (right.pre === null)\n return -1\n return left.pre < right.pre ? -1 : 1\n}\n\nfunction detailFor(source: CliSource, version: string | null, supported: boolean, prefer: CliPreference, unusableOverride: string | null = null): string {\n const shown = version ?? 'unknown version'\n switch (source) {\n case 'config':\n return unusableOverride === null\n ? `from the configured command (${shown})`\n : `the configured command could not be used: ${unusableOverride} does not exist (or is not a file this plugin can run); fix homeHostedCommand, or clear it to let the plugin choose`\n case 'dependency':\n return supported\n ? `the pinned dependency (${shown})`\n : `the pinned dependency is below the oldest supported release (${MIN_SUPPORTED_VERSION})`\n case 'path':\n if (!supported)\n return `the global install on PATH (${shown}) is below the oldest supported release (${MIN_SUPPORTED_VERSION})`\n return prefer === 'global'\n ? `the global install on PATH (${shown})`\n : `a global install on PATH (${shown}), not the pinned dependency ${EXPECTED_RANGE}`\n default:\n return 'no home-hosted CLI found: install the plugin with its dependencies, or put home-hosted on PATH'\n }\n}\n\nasync function defaultReadVersion(launch: CliLaunch, timeoutMs: number): Promise<string | null> {\n const result = await run(launch.program, [...launch.args, '--version'], { timeoutMs })\n return parseVersion(result.stdout) ?? parseVersion(result.stderr)\n}\n\nexport async function resolveCli(options: ResolveCliOptions = {}): Promise<CliResolution> {\n const timeoutMs = options.timeoutMs ?? 5000\n const prefer = options.prefer ?? 'pinned'\n const readVersion = options.readVersion ?? (launch => defaultReadVersion(launch, timeoutMs))\n const locate = options.findOnPath ?? which\n\n // 1. An explicit override is not a preference: it is an instruction. An\n // instruction that cannot be carried out is reported, never silently\n // replaced by a copy the operator did not ask for.\n const override = options.override?.trim()\n let unusableOverride: string | null = null\n if (override !== undefined && override.length > 0) {\n const launch = resolveShimmedCli(path.resolve(override))\n if (launch === null) {\n unusableOverride = override\n }\n else {\n const version = await readVersion(launch)\n const supported = version === null || compareVersions(version, MIN_SUPPORTED_VERSION) >= 0\n return {\n launch,\n status: {\n source: 'config',\n path: launch.cliEntry ?? launch.shimPath ?? launch.program,\n version,\n expectedRange: EXPECTED_RANGE,\n supported,\n prefer,\n dependency: null,\n global: null,\n detail: detailFor('config', version, supported, prefer),\n },\n }\n }\n }\n\n // 2. The two copies this plugin knows about.\n const manifest = (options.packageManifest ?? pinnedManifestPath)()\n const dependencyEntry = manifest === null ? null : binEntryFromManifest(manifest)\n let dependency: Candidate | null = null\n if (dependencyEntry !== null && fs.existsSync(dependencyEntry)) {\n let version: string | null = null\n try {\n version = (JSON.parse(fs.readFileSync(manifest as string, 'utf8')) as { version?: string }).version ?? null\n }\n catch {\n version = null\n }\n dependency = {\n candidate: { source: 'dependency', path: dependencyEntry, version },\n launch: { program: process.execPath, args: [dependencyEntry], cliEntry: dependencyEntry, shimPath: null, source: 'entry' },\n }\n }\n\n let global: Candidate | null = null\n const found = (await locate('home-hosted')) ?? (await locate('hh'))\n if (found !== null) {\n const launch = resolveShimmedCli(path.resolve(found))\n if (launch !== null) {\n global = {\n candidate: { source: 'path', path: launch.cliEntry ?? launch.shimPath ?? launch.program, version: await readVersion(launch) },\n launch,\n }\n }\n }\n\n const order = prefer === 'global' ? [global, dependency] : [dependency, global]\n const chosen = order.find(item => item !== null) ?? null\n const dependencySummary = dependency?.candidate ?? null\n const globalSummary = global?.candidate ?? null\n\n if (unusableOverride !== null) {\n return {\n launch: null,\n status: {\n source: 'config',\n path: unusableOverride,\n version: null,\n expectedRange: EXPECTED_RANGE,\n supported: false,\n prefer,\n dependency: dependencySummary,\n global: globalSummary,\n detail: detailFor('config', null, false, prefer, unusableOverride),\n },\n }\n }\n\n if (chosen === null) {\n return {\n launch: null,\n status: {\n source: 'none',\n path: null,\n version: null,\n expectedRange: EXPECTED_RANGE,\n supported: false,\n prefer,\n dependency: dependencySummary,\n global: globalSummary,\n detail: detailFor('none', null, false, prefer),\n },\n }\n }\n\n const version = chosen.candidate.version\n const supported = version === null || compareVersions(version, MIN_SUPPORTED_VERSION) >= 0\n return {\n launch: chosen.launch,\n status: {\n source: chosen.candidate.source,\n path: chosen.candidate.path,\n version,\n expectedRange: EXPECTED_RANGE,\n supported,\n prefer,\n dependency: dependencySummary,\n global: globalSummary,\n detail: detailFor(chosen.candidate.source, version, supported, prefer),\n },\n }\n}\n", "/**\n * A stable launcher for the pinned CLI.\n *\n * A dependency resolves to a pnpm path that carries the version and the peer\n * hash (`\u2026/.pnpm/home-hosted@0.6.1_zod@4.6.5/node_modules/home-hosted/\u2026`), which\n * moves on the next install and disappears when the profile is rebuilt. A boot\n * entry that baked that path in would fail at exactly the moment it exists for.\n *\n * So the plugin generates one small script in its own state directory and points\n * the boot entry at *that*. At boot the launcher finds the pinned copy again\n * (recorded path \u2192 profile node_modules, flat or pnpm) and falls back to PATH,\n * which is why the entry survives plugin upgrades and profile reinstalls.\n */\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { run } from '../util/exec.js'\nimport { readJson, writeFileAtomic, writeJsonAtomic } from '../util/fsx.js'\nimport { compareVersions, parseVersion } from './resolve.js'\n\nexport interface LauncherOptions {\n stateDir: string\n dshHome: string\n /** Where the pinned copy is right now; recorded as the fast path. */\n resolvedEntry: string | null\n /** The pinned copy's version, recorded for diagnostics. */\n resolvedVersion?: string | null\n /** The plugin's own package root, as a search hint. */\n pluginRoot?: string | null\n minVersion: string\n marker?: string\n}\n\nexport interface LauncherWrite {\n path: string\n changed: boolean\n}\n\ninterface LauncherRecord {\n entry: string | null\n version: string | null\n pluginRoot: string | null\n writtenAt: number\n}\n\nexport function launcherDir(stateDir: string): string {\n return path.join(stateDir, 'bin')\n}\n\nexport function launcherPath(stateDir: string): string {\n return path.join(launcherDir(stateDir), 'home-hosted.mjs')\n}\n\nexport function launcherRecordPath(stateDir: string): string {\n return path.join(launcherDir(stateDir), 'resolved.json')\n}\n\nexport function readLauncherRecord(stateDir: string): LauncherRecord | null {\n return readJson<LauncherRecord>(launcherRecordPath(stateDir))\n}\n\n/** The generated script's source; exported so a test can inspect it. */\nexport function buildLauncherSource(options: LauncherOptions): string {\n const marker = options.marker ?? 'managed by dsh-home-hosted'\n const record = launcherRecordPath(options.stateDir)\n return `#!/usr/bin/env node\n// ${marker} \u2014 rewritten on every plugin start; do not edit.\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { spawnSync } from 'node:child_process'\n\nconst DSH_HOME = ${JSON.stringify(options.dshHome)}\nconst RECORD = ${JSON.stringify(record)}\nconst MIN_VERSION = ${JSON.stringify(options.minVersion)}\nconst PLUGIN_ROOT = ${JSON.stringify(options.pluginRoot ?? null)}\n\nfunction readRecord() {\n try { return JSON.parse(fs.readFileSync(RECORD, 'utf8')) } catch { return null }\n}\n\nfunction versionOf(entry) {\n let dir = path.dirname(entry)\n for (let hop = 0; hop < 4; hop += 1) {\n try {\n const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'))\n if (typeof manifest.version === 'string') return manifest.version\n } catch {}\n dir = path.dirname(dir)\n }\n return null\n}\n\nfunction compare(a, b) {\n const split = value => {\n const [core, pre = null] = String(value).split('-', 2)\n return { parts: core.split('.').map(part => Number.parseInt(part, 10) || 0), pre }\n }\n const left = split(a); const right = split(b)\n for (let i = 0; i < 3; i += 1) {\n const diff = (left.parts[i] ?? 0) - (right.parts[i] ?? 0)\n if (diff !== 0) return diff < 0 ? -1 : 1\n }\n if (left.pre === right.pre) return 0\n if (left.pre === null) return 1\n if (right.pre === null) return -1\n return left.pre < right.pre ? -1 : 1\n}\n\nfunction collect(out, entry) {\n if (typeof entry === 'string' && entry.length > 0 && fs.existsSync(entry)) out.push(entry)\n}\n\nfunction collectRoot(root, out) {\n collect(out, path.join(root, 'node_modules', 'home-hosted', 'bin', 'home-hosted.mjs'))\n const store = path.join(root, 'node_modules', '.pnpm')\n let names = []\n try { names = fs.readdirSync(store) } catch { return }\n for (const name of names) {\n if (name.startsWith('home-hosted@') || name.startsWith('dsh-home-hosted@'))\n collect(out, path.join(store, name, 'node_modules', 'home-hosted', 'bin', 'home-hosted.mjs'))\n }\n}\n\nfunction candidates() {\n const out = []\n const record = readRecord()\n if (record && typeof record.entry === 'string') collect(out, record.entry)\n if (PLUGIN_ROOT !== null) collectRoot(PLUGIN_ROOT, out)\n try {\n for (const name of fs.readdirSync(path.join(DSH_HOME, 'profiles')))\n collectRoot(path.join(DSH_HOME, 'profiles', name), out)\n } catch {}\n collectRoot(path.join(DSH_HOME), out)\n // Last resort: a global install on the entry's own PATH.\n for (const dir of (process.env.PATH ?? '').split(path.delimiter)) {\n if (dir.length === 0) continue\n collect(out, path.join(dir, 'home-hosted'))\n collect(out, path.join(dir, 'home-hosted.cmd'))\n }\n return out\n}\n\nfunction choose() {\n const found = candidates().map(entry => ({ entry, version: versionOf(entry) }))\n const supported = found.filter(item => item.version !== null && compare(item.version, MIN_VERSION) >= 0)\n supported.sort((a, b) => compare(b.version, a.version))\n return (supported[0] ?? found[0] ?? null)?.entry ?? null\n}\n\nconst entry = choose()\nif (entry === null) {\n console.error('[dsh-home-hosted] no home-hosted CLI found (looked in ' + DSH_HOME + ' and PATH). Reinstall the plugin with its dependencies, or set homeHostedCommand in the plugin row.')\n process.exit(1)\n}\n\nconst args = process.argv.slice(2)\nconst isScript = /\\\\.(mjs|cjs|js)$/.test(entry)\nconst result = isScript\n ? spawnSync(process.execPath, [entry, ...args], { stdio: 'inherit' })\n : spawnSync(entry, args, { stdio: 'inherit', shell: process.platform === 'win32' && /\\\\.(cmd|bat)$/i.test(entry) })\nprocess.exit(typeof result.status === 'number' ? result.status : 1)\n`\n}\n\nexport function writeLauncher(options: LauncherOptions): LauncherWrite {\n const file = launcherPath(options.stateDir)\n const source = buildLauncherSource(options)\n const previous = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : null\n const changed = previous !== source\n if (changed) {\n writeFileAtomic(file, source, 0o755)\n fs.chmodSync(file, 0o755)\n }\n writeJsonAtomic(launcherRecordPath(options.stateDir), {\n entry: options.resolvedEntry,\n version: options.resolvedVersion ?? null,\n pluginRoot: options.pluginRoot ?? null,\n writtenAt: Date.now(),\n } satisfies LauncherRecord, 0o600)\n return { path: file, changed }\n}\n\n/** Run the launcher the way the boot entry will, and read the version it answers. */\nexport async function preflightLauncher(stateDir: string, timeoutMs = 10_000): Promise<string | null> {\n const file = launcherPath(stateDir)\n if (!fs.existsSync(file))\n return null\n const result = process.platform === 'win32'\n ? await run(process.execPath, [file, '--version'], { timeoutMs })\n : await run(file, ['--version'], { timeoutMs })\n return parseVersion(result.stdout) ?? parseVersion(result.stderr)\n}\n\n/** The version a CLI entry belongs to, read from the nearest package.json. */\nexport function versionOfEntry(entry: string): string | null {\n let dir = path.dirname(entry)\n for (let hop = 0; hop < 4; hop += 1) {\n const manifest = readJson<{ version?: string }>(path.join(dir, 'package.json'))\n if (typeof manifest?.version === 'string')\n return manifest.version\n dir = path.dirname(dir)\n }\n return null\n}\n\n/** Candidate entries under one root: a flat install, or a pnpm store. */\nexport function candidatesUnder(root: string): string[] {\n const out: string[] = []\n const direct = path.join(root, 'node_modules', 'home-hosted', 'bin', 'home-hosted.mjs')\n if (fs.existsSync(direct))\n out.push(direct)\n const store = path.join(root, 'node_modules', '.pnpm')\n if (fs.existsSync(store)) {\n for (const name of fs.readdirSync(store)) {\n if (!name.startsWith('home-hosted@') && !name.startsWith('dsh-home-hosted@'))\n continue\n const entry = path.join(store, name, 'node_modules', 'home-hosted', 'bin', 'home-hosted.mjs')\n if (fs.existsSync(entry))\n out.push(entry)\n }\n }\n return out\n}\n\n/** Highest satisfying candidate among explicit roots; exported for tests. */\nexport function findCandidate(roots: string[], minVersion: string): string | null {\n const found = roots.flatMap(root => candidatesUnder(root).map(entry => ({ entry, version: versionOfEntry(entry) })))\n const supported = found.filter(item => item.version !== null && compareVersions(item.version, minVersion) >= 0)\n supported.sort((a, b) => compareVersions(b.version ?? '0.0.0', a.version ?? '0.0.0'))\n return (supported[0] ?? found[0] ?? null)?.entry ?? null\n}\n", "/**\n * Starting, replacing and globally installing the panel.\n *\n * Starting it is the same thing a person does by hand: run the CLI's `up`, which\n * re-spawns itself detached, writes `run.json` and returns once the panel\n * answers. Replacing a panel *is* different \u2014 stopping the one that is answering\n * also stops the servers it supervises, including the dsh this plugin runs in \u2014\n * so the replacement is done by a detached helper that outlives this process.\n */\nimport { spawn } from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport type { PanelControlResult } from '../shared/contracts.js'\nimport { run } from '../util/exec.js'\nimport { writeFileAtomic } from '../util/fsx.js'\nimport type { CliLaunch } from './launch.js'\nimport { launcherDir } from './launcher.js'\n\nexport interface PanelControlDeps {\n /** The CLI to run, already resolved. */\n launch: CliLaunch | null\n home: string\n projectDir?: string | null\n stateDir: string\n /** Environment for the spawned CLI (absolute PATH, HOME, HHOSTED_HOME). */\n env: Record<string, string>\n timeoutMs?: number\n}\n\nfunction cliArgs(deps: PanelControlDeps, command: 'up' | 'down' | 'restart'): string[] {\n const args = [...(deps.launch?.args ?? []), command, '--home', deps.home]\n if (deps.projectDir)\n args.push('--project', deps.projectDir)\n return args\n}\n\nasync function runCli(deps: PanelControlDeps, command: 'up' | 'down' | 'restart'): Promise<{ code: number | null, stdout: string, stderr: string }> {\n const launch = deps.launch\n if (launch === null)\n return { code: null, stdout: '', stderr: 'no home-hosted CLI is available' }\n return await run(launch.program, cliArgs(deps, command), {\n env: deps.env,\n timeoutMs: deps.timeoutMs ?? 90_000,\n })\n}\n\n/** Start the preferred CLI as a detached panel; the CLI itself does the detaching. */\nexport async function startPanel(deps: PanelControlDeps): Promise<PanelControlResult> {\n const result = await runCli(deps, 'up')\n if (result.code !== 0) {\n const detail = result.stderr.trim() || result.stdout.trim() || `the CLI exited ${String(result.code)}`\n return { ok: false, detail }\n }\n const match = /https?:\\/\\/[^\\s]+/.exec(result.stdout)\n return { ok: true, detail: 'the panel is answering', url: match?.[0] ?? null }\n}\n\nexport function takeoverHelperPath(stateDir: string): string {\n return path.join(launcherDir(stateDir), 'panel-takeover.mjs')\n}\n\nexport function takeoverLogPath(stateDir: string): string {\n return path.join(launcherDir(stateDir), 'panel-takeover.log')\n}\n\n/** The generated helper's source; exported so a test can inspect it. */\nexport function buildTakeoverSource(deps: PanelControlDeps, oldPid: number | null, marker = 'managed by dsh-home-hosted'): string {\n const program = deps.launch?.program ?? process.execPath\n const args = deps.launch === null\n ? []\n : [...deps.launch.args, 'up', '--home', deps.home, ...(deps.projectDir ? ['--project', deps.projectDir] : [])]\n const downArgs = [...(deps.launch?.args ?? []), 'down', '--home', deps.home]\n return `#!/usr/bin/env node\n// ${marker} \u2014 replaces the panel; do not edit.\nimport fs from 'node:fs'\nimport { spawnSync } from 'node:child_process'\n\nconst OLD_PID = ${JSON.stringify(oldPid)}\nconst DOWN_ARGS = ${JSON.stringify(downArgs)}\nconst PROGRAM = ${JSON.stringify(program)}\nconst ARGS = ${JSON.stringify(args)}\nconst ENV = ${JSON.stringify(deps.env)}\nconst LOG = ${JSON.stringify(takeoverLogPath(deps.stateDir))}\n\nfunction log(line) {\n try { fs.appendFileSync(LOG, new Date().toISOString() + ' ' + line + '\\\\n') } catch {}\n}\n\nfunction alive(pid) {\n if (typeof pid !== 'number') return false\n try { process.kill(pid, 0); return true } catch { return false }\n}\n\nconst sleep = ms => new Promise(resolve => setTimeout(resolve, ms))\n\nlog('stopping the answering panel: ' + PROGRAM + ' ' + DOWN_ARGS.join(' '))\nconst down = spawnSync(PROGRAM, DOWN_ARGS, { env: { ...process.env, ...ENV }, stdio: 'ignore' })\nlog('down exited ' + String(down.status))\n\nfor (let i = 0; i < 40 && alive(OLD_PID); i += 1)\n await sleep(250)\n\nif (alive(OLD_PID)) {\n log('still alive; sending SIGTERM')\n try { process.kill(OLD_PID, 'SIGTERM') } catch {}\n for (let i = 0; i < 40 && alive(OLD_PID); i += 1)\n await sleep(250)\n}\n\nif (alive(OLD_PID)) {\n log('still alive; sending SIGKILL')\n try { process.kill(OLD_PID, 'SIGKILL') } catch {}\n for (let i = 0; i < 20 && alive(OLD_PID); i += 1)\n await sleep(250)\n}\n\nlog('starting ' + PROGRAM + ' ' + ARGS.join(' '))\nconst result = spawnSync(PROGRAM, ARGS, { env: { ...process.env, ...ENV }, stdio: 'ignore' })\nlog('started with exit ' + String(result.status))\n`\n}\n\nexport function writeTakeoverHelper(deps: PanelControlDeps, oldPid: number | null): string {\n const file = takeoverHelperPath(deps.stateDir)\n writeFileAtomic(file, buildTakeoverSource(deps, oldPid), 0o755)\n fs.chmodSync(file, 0o755)\n return file\n}\n\n/**\n * Spawn the helper detached and return immediately: the old panel's shutdown is\n * about to stop this very process, so waiting for the result would lose it.\n */\nexport function spawnTakeover(deps: PanelControlDeps, oldPid: number | null): PanelControlResult {\n const helper = writeTakeoverHelper(deps, oldPid)\n const child = spawn(process.execPath, [helper], { detached: true, stdio: 'ignore' })\n child.unref()\n return {\n ok: true,\n detail: 'replacing the panel now; this page will disconnect and come back under the preferred copy',\n }\n}\n\n/** Install the pinned range globally, so the `global` preference has something to use. */\nexport async function installGlobal(\n range: string,\n options: { pnpm?: boolean, run?: typeof run } = {},\n): Promise<{ ok: boolean, detail: string, output: string }> {\n const execute = options.run ?? run\n const usePnpm = options.pnpm ?? true\n const result = usePnpm\n ? await execute('pnpm', ['add', '-g', `home-hosted@${range}`], { timeoutMs: 300_000 })\n : await execute('npm', ['install', '-g', `home-hosted@${range}`], { timeoutMs: 300_000 })\n const output = `${result.stdout}\\n${result.stderr}`.trim()\n if (result.code !== 0)\n return { ok: false, detail: result.error ?? `the installer exited ${String(result.code)}`, output }\n return { ok: true, detail: `installed home-hosted@${range} globally`, output }\n}\n", "/**\n * The home-hosted HTTP API client.\n *\n * Every call carries the plugin's own API token; the panel verifies it from its\n * secrets file on each request. A write through this client is the safe path:\n * the config store records the bytes it wrote, so the panel's own file watcher\n * never treats the change as an external edit.\n */\nimport type { ServerEntry, ServerEntryPatch, ServerEntryView } from '../shared/contracts.js'\n\nexport class PanelError extends Error {\n constructor(\n message: string,\n readonly code: string,\n readonly status: number | null = null,\n /** The panel's own diagnostic, when it sent one. */\n readonly detail: unknown = undefined,\n ) {\n super(message)\n this.name = 'PanelError'\n }\n}\n\nexport interface PanelClientOptions {\n baseUrl: string\n token: string\n timeoutMs?: number\n}\n\nexport class PanelClient {\n private readonly baseUrl: string\n private readonly token: string\n private readonly timeoutMs: number\n\n constructor(options: PanelClientOptions) {\n this.baseUrl = options.baseUrl.replace(/\\/+$/, '')\n this.token = options.token\n this.timeoutMs = options.timeoutMs ?? 10_000\n }\n\n private async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n let response: Response\n try {\n response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: {\n authorization: `Bearer ${this.token}`,\n ...(body === undefined ? {} : { 'content-type': 'application/json' }),\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: AbortSignal.timeout(this.timeoutMs),\n })\n }\n catch (error) {\n throw new PanelError(\n error instanceof Error ? error.message : String(error),\n 'PANEL_UNREACHABLE',\n )\n }\n\n const text = await response.text()\n let parsed: unknown = null\n try {\n parsed = text.length > 0 ? JSON.parse(text) : null\n }\n catch {\n throw new PanelError(`the panel answered ${response.status} with a non-JSON body`, 'PANEL_BAD_RESPONSE', response.status)\n }\n\n if (!response.ok) {\n const record = parsed as { message?: unknown, code?: unknown, detail?: unknown } | null\n const message = typeof record?.message === 'string' ? record.message : `the panel answered ${response.status}`\n const code = typeof record?.code === 'string' ? record.code : 'PANEL_ERROR'\n throw new PanelError(message, code, response.status, record?.detail)\n }\n\n return parsed as T\n }\n\n async listServers(): Promise<ServerEntryView[]> {\n const answer = await this.request<{ servers: ServerEntryView[] }>('GET', '/api/servers')\n return answer.servers\n }\n\n async getServer(id: string): Promise<ServerEntryView> {\n const answer = await this.request<{ server: ServerEntryView }>('GET', `/api/servers/${encodeURIComponent(id)}`)\n return answer.server\n }\n\n async createServer(entry: ServerEntry): Promise<ServerEntryView> {\n const answer = await this.request<{ server: ServerEntryView }>('POST', '/api/servers', entry)\n return answer.server\n }\n\n async updateServer(id: string, patch: ServerEntryPatch): Promise<ServerEntryView> {\n const answer = await this.request<{ server: ServerEntryView }>('PATCH', `/api/servers/${encodeURIComponent(id)}`, patch)\n return answer.server\n }\n\n async deleteServer(id: string): Promise<void> {\n await this.request('DELETE', `/api/servers/${encodeURIComponent(id)}`)\n }\n\n async startServer(id: string): Promise<void> {\n await this.request('POST', `/api/servers/${encodeURIComponent(id)}/start`)\n }\n\n async stopServer(id: string): Promise<void> {\n await this.request('POST', `/api/servers/${encodeURIComponent(id)}/stop`)\n }\n\n async restartServer(id: string): Promise<void> {\n await this.request('POST', `/api/servers/${encodeURIComponent(id)}/restart`)\n }\n\n /** Re-list the port's listeners and stop what is not the panel's own tree. */\n async freePort(id: string): Promise<{ stopped?: number[] }> {\n return await this.request<{ stopped?: number[] }>('POST', `/api/servers/${encodeURIComponent(id)}/free-port`)\n }\n}\n\n/** Prove a token works, without needing any write permission. */\nexport async function verifyToken(baseUrl: string, token: string, timeoutMs = 5000): Promise<boolean> {\n try {\n await new PanelClient({ baseUrl, token, timeoutMs }).listServers()\n return true\n }\n catch {\n return false\n }\n}\n", "/**\n * Facts about the running home-hosted panel, read from the `run.json` it writes\n * at startup. Its token field is deliberately never read: the plugin\n * authenticates with its own enrolled API token instead.\n */\nimport http from 'node:http'\nimport https from 'node:https'\nimport process from 'node:process'\nimport { readJson } from '../util/fsx.js'\nimport { runtimeFile } from '../util/paths.js'\n\nexport interface PanelRuntime {\n version: string\n pid: number\n url: string\n probeUrl?: string\n protocol?: string\n port: number\n bindHost?: string\n projectDir?: string\n dataRoot?: string\n configPath?: string\n logFile?: string\n}\n\nexport function readRuntime(home: string): PanelRuntime | null {\n const raw = readJson<Record<string, unknown>>(runtimeFile(home))\n if (raw === null)\n return null\n const url = typeof raw.url === 'string' ? raw.url : null\n const pid = typeof raw.pid === 'number' ? raw.pid : null\n if (url === null || pid === null)\n return null\n return {\n version: typeof raw.version === 'string' ? raw.version : 'unknown',\n pid,\n url: url.replace(/\\/+$/, ''),\n probeUrl: typeof raw.probeUrl === 'string' ? raw.probeUrl : undefined,\n protocol: typeof raw.protocol === 'string' ? raw.protocol : undefined,\n port: typeof raw.port === 'number' ? raw.port : 0,\n bindHost: typeof raw.bindHost === 'string' ? raw.bindHost : undefined,\n projectDir: typeof raw.projectDir === 'string' ? raw.projectDir : undefined,\n dataRoot: typeof raw.dataRoot === 'string' ? raw.dataRoot : undefined,\n configPath: typeof raw.configPath === 'string' ? raw.configPath : undefined,\n logFile: typeof raw.logFile === 'string' ? raw.logFile : undefined,\n }\n}\n\nexport function pidAlive(pid: number): boolean {\n try {\n process.kill(pid, 0)\n return true\n }\n catch {\n return false\n }\n}\n\n/**\n * Ask the panel's public health route whether it is answering. Uses the raw\n * http/https modules so a self-signed TLS pair answers too.\n */\nexport async function probePanel(url: string, timeoutMs = 2000): Promise<boolean> {\n const target = `${url.replace(/\\/+$/, '')}/healthz`\n return await new Promise<boolean>((resolve) => {\n let settled = false\n const done = (value: boolean): void => {\n if (settled)\n return\n settled = true\n resolve(value)\n }\n\n let parsed: URL\n try {\n parsed = new URL(target)\n }\n catch {\n done(false)\n return\n }\n\n const transport = parsed.protocol === 'https:' ? https : http\n const request = transport.get(\n {\n hostname: parsed.hostname,\n port: parsed.port,\n path: `${parsed.pathname}${parsed.search}`,\n timeout: timeoutMs,\n rejectUnauthorized: false,\n },\n (response) => {\n response.resume()\n done(typeof response.statusCode === 'number')\n },\n )\n request.on('timeout', () => {\n request.destroy()\n done(false)\n })\n request.on('error', () => done(false))\n })\n}\n", "/**\n * The plugin's own credential for the home-hosted panel.\n *\n * home-hosted keeps only the token's hash, so a token this plugin did not\n * create can never be recovered from disk. When none is enrolled, the plugin\n * mints one and hands it to `home-hosted set-token` through `HHOSTED_TOKEN`,\n * which stores the hash and prints nothing. The plaintext lives 0600 under the\n * plugin state directory and is never logged, rendered, or sent to the browser.\n */\nimport { randomBytes } from 'node:crypto'\nimport path from 'node:path'\nimport type { RunResult } from '../util/exec.js'\nimport { readJson, readText, writeFileAtomic } from '../util/fsx.js'\nimport { secretsFile } from '../util/paths.js'\n\nexport type CliExecutor = (args: string[], env: Record<string, string | undefined>) => Promise<RunResult>\n\nexport interface EnsureTokenOptions {\n home: string\n stateDir: string\n exec: CliExecutor\n}\n\nexport interface EnsureTokenResult {\n token: string | null\n /** True when this call created the token. */\n enrolled: boolean\n detail: string\n}\n\nexport function storedTokenPath(stateDir: string): string {\n return path.join(stateDir, 'panel-token')\n}\n\nexport function readStoredToken(stateDir: string): string | null {\n const text = readText(storedTokenPath(stateDir))?.trim()\n return text !== undefined && text.length > 0 ? text : null\n}\n\nexport function storeToken(stateDir: string, token: string): void {\n writeFileAtomic(storedTokenPath(stateDir), `${token}\\n`, 0o600)\n}\n\nexport function generateToken(): string {\n return randomBytes(32).toString('base64url')\n}\n\n/** Whether home-hosted already holds an API token (only its hash is on disk). */\nexport function apiTokenEnrolled(home: string): boolean {\n const secrets = readJson<{ apiToken?: unknown }>(secretsFile(home))\n return secrets !== null && secrets.apiToken !== null && secrets.apiToken !== undefined\n}\n\nexport async function ensureToken(options: EnsureTokenOptions): Promise<EnsureTokenResult> {\n const stored = readStoredToken(options.stateDir)\n if (stored !== null)\n return { token: stored, enrolled: false, detail: 'using the stored panel token' }\n\n if (apiTokenEnrolled(options.home)) {\n return {\n token: null,\n enrolled: false,\n detail: 'home-hosted already has an API token, and this plugin does not have it; '\n + 'run `home-hosted set-token --generate` and store that token, or clear it and re-enable',\n }\n }\n\n const token = generateToken()\n const result = await options.exec(['--home', options.home, 'set-token'], { HHOSTED_TOKEN: token })\n if (result.code !== 0) {\n return {\n token: null,\n enrolled: false,\n detail: `could not enrol an API token: ${result.stderr.trim() || result.stdout.trim() || `exit ${String(result.code)}`}`,\n }\n }\n\n storeToken(options.stateDir, token)\n return { token, enrolled: true, detail: 'enrolled a new panel API token' }\n}\n", "/**\n * The browser half's one entry point.\n *\n * The route is registered on DeepSeek Harness's shared `/api` channel, so the\n * physical carrier has already applied the Host/Origin fence and browser\n * authentication before this handler runs: only the local operator reaches it.\n * Domain failures travel inside the envelope, protocol failures as HTTP status.\n */\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { RpcEndpoint, RpcRequest } from './shared/contracts.js'\nimport { RPC_PATH, RPC_VERSION } from './shared/contracts.js'\nimport type { HomeHostedService } from './service.js'\nimport { HomeHostedError } from './service.js'\n\ninterface FetchRoute {\n path: string\n methods: readonly string[]\n requestBody: 'buffered' | 'streaming'\n fetch: (request: Request) => Promise<Response>\n}\n\ninterface ConnectionLike {\n fetch: { register: (route: FetchRoute) => () => unknown }\n}\n\ninterface ConnectionHost {\n connection: ConnectionLike\n}\n\ninterface LoggerLike {\n warn?: (message: string) => void\n}\n\nfunction answer(endpoint: RpcEndpoint | string, result: unknown): Response {\n return Response.json({ v: RPC_VERSION, endpoint, result })\n}\n\nexport function registerRpc(ctx: Context, service: HomeHostedService): void {\n ctx.inject(['connection'], (scoped) => {\n const connection = (scoped as unknown as ConnectionHost).connection\n if (connection?.fetch?.register === undefined)\n return\n\n scoped.effect(() => {\n let dispose: () => unknown\n try {\n dispose = connection.fetch.register({\n // The exact-route registry is keyed by the full request path, so the\n // `/api` prefix belongs here; the page composes the same URL from\n // API_BASE + RPC_PATH.\n path: `/api${RPC_PATH}`,\n methods: ['POST'],\n requestBody: 'buffered',\n fetch: async (request: Request) => {\n let body: RpcRequest\n try {\n body = await request.json() as RpcRequest\n }\n catch {\n return Response.json({ error: 'the request body is not JSON' }, { status: 400 })\n }\n\n if (body === null || typeof body !== 'object' || body.v !== RPC_VERSION) {\n return Response.json(\n { error: `this page and the host disagree on the protocol version (expected ${String(RPC_VERSION)})` },\n { status: 409 },\n )\n }\n\n try {\n const value = await service.call(body.endpoint, body.payload)\n return answer(body.endpoint, { ok: true, value })\n }\n catch (error) {\n const code = error instanceof HomeHostedError ? error.code : 'INTERNAL'\n const message = error instanceof Error ? error.message : String(error)\n const detail = (error as { detail?: unknown } | null)?.detail\n return answer(body.endpoint, { ok: false, error: { code, message, ...(detail === undefined ? {} : { detail }) } })\n }\n },\n })\n }\n catch (error) {\n // A registration the carrier refuses would otherwise look like a page\n // that silently 404s; say so where an operator can see it.\n const logger = (scoped as unknown as { logger?: LoggerLike }).logger\n logger?.warn?.(`[dsh-home-hosted] could not register ${RPC_PATH}: ${error instanceof Error ? error.message : String(error)}`)\n return () => {}\n }\n\n return () => {\n void dispose()\n }\n }, 'dsh-home-hosted: rpc route')\n })\n}\n", "/**\n * The plugin's own settings, kept in a 0600 JSON file under its state directory.\n *\n * These are the things a person toggles; the Cordis row config stays for\n * operator overrides only, so neither surface can silently overwrite the other.\n */\nimport { AGENT_TOOL_NAMES, DEFAULT_SETTINGS } from './shared/contracts.js'\nimport type { AgentToolName, EntryIntent, PluginSettings, SettingsPatch } from './shared/contracts.js'\nimport { readJson, writeJsonAtomic } from './util/fsx.js'\nimport { defaultIntent } from './home-hosted/entries.js'\n\nfunction knownTool(value: unknown): value is AgentToolName {\n return typeof value === 'string' && (AGENT_TOOL_NAMES as readonly string[]).includes(value)\n}\n\nfunction normalizeIntent(value: Partial<EntryIntent> | null | undefined, fallbackId: string): EntryIntent {\n const base = defaultIntent(typeof value?.id === 'string' && value.id.length > 0 ? value.id : fallbackId)\n return {\n id: base.id,\n autostart: typeof value?.autostart === 'boolean' ? value.autostart : base.autostart,\n onPortConflict: value?.onPortConflict ?? base.onPortConflict,\n stopKillPortHolders: typeof value?.stopKillPortHolders === 'boolean' ? value.stopKillPortHolders : base.stopKillPortHolders,\n }\n}\n\nfunction normalize(raw: Partial<PluginSettings> | null, fallbackEntryId: string): PluginSettings {\n const entries = Array.isArray(raw?.entries)\n ? raw.entries.map(intent => normalizeIntent(intent, fallbackEntryId))\n : []\n const allow = Array.isArray(raw?.agentTools?.allow) ? raw.agentTools.allow.filter(knownTool) : DEFAULT_SETTINGS.agentTools.allow\n return {\n autostart: {\n enabled: raw?.autostart?.enabled === true,\n mechanism: raw?.autostart?.mechanism ?? 'auto',\n },\n entries,\n agentTools: {\n enabled: raw?.agentTools?.enabled === true,\n allow: allow.length > 0 ? allow : [...DEFAULT_SETTINGS.agentTools.allow],\n },\n cli: {\n prefer: raw?.cli?.prefer === 'global' ? 'global' : 'pinned',\n },\n }\n}\n\nexport class SettingsStore {\n private current: PluginSettings\n private readonly listeners = new Set<(settings: PluginSettings) => void>()\n\n constructor(\n readonly file: string,\n private readonly fallbackEntryId: string,\n ) {\n this.current = normalize(readJson<Partial<PluginSettings>>(file), fallbackEntryId)\n }\n\n get(): PluginSettings {\n return this.current\n }\n\n /** The intent for an entry, materialising the default when it has none yet. */\n intentFor(id: string): EntryIntent {\n return this.current.entries.find(entry => entry.id === id) ?? defaultIntent(id)\n }\n\n update(patch: SettingsPatch): PluginSettings {\n const next = normalize({\n autostart: { ...this.current.autostart, ...(patch.autostart ?? {}) },\n entries: patch.entries ?? this.current.entries,\n agentTools: { ...this.current.agentTools, ...(patch.agentTools ?? {}) },\n cli: { ...this.current.cli, ...(patch.cli ?? {}) },\n }, this.fallbackEntryId)\n this.current = next\n writeJsonAtomic(this.file, next, 0o600)\n for (const listener of this.listeners)\n listener(next)\n return next\n }\n\n onChange(listener: (settings: PluginSettings) => void): () => void {\n this.listeners.add(listener)\n return () => {\n this.listeners.delete(listener)\n }\n }\n}\n", "/**\n * Agent tools, off by default and allowlisted by name.\n *\n * The list is read at registration time and re-read whenever the settings file\n * changes, so toggling a tool takes effect without a restart. Every tool that\n * changes something asks the approval service first and fails closed when it is\n * absent or refuses.\n */\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { ParameterSchemaSpec } from '@deepseek-ai/dsh-tools'\nimport { defineTool } from '@deepseek-ai/dsh-tools'\nimport type { AgentToolName, RpcEndpoint } from './shared/contracts.js'\nimport { MUTATING_AGENT_TOOLS } from './shared/contracts.js'\nimport type { HomeHostedService } from './service.js'\nimport type { SettingsStore } from './settings.js'\n\ninterface ApprovalLike {\n request: (request: { agent: unknown, toolName: string, reason?: string }) => Promise<string>\n}\n\ninterface ToolSpec {\n endpoint: RpcEndpoint\n description: string\n parameters: ParameterSchemaSpec\n}\n\nconst TOOL_SPECS: Record<AgentToolName, ToolSpec> = {\n status: {\n endpoint: 'status',\n description: 'Report the home-hosted panel state, its boot-autostart entry, and the entries this plugin manages.',\n parameters: {},\n },\n servers_list: {\n endpoint: 'servers.list',\n description: 'List every server home-hosted supervises, with status, pid and url.',\n parameters: {},\n },\n servers_start: {\n endpoint: 'servers.start',\n description: 'Start a server supervised by home-hosted.',\n parameters: { id: { type: 'string', required: true, description: 'Server entry id' } },\n },\n servers_stop: {\n endpoint: 'servers.stop',\n description: 'Stop a server supervised by home-hosted.',\n parameters: { id: { type: 'string', required: true, description: 'Server entry id' } },\n },\n servers_restart: {\n endpoint: 'servers.restart',\n description: 'Restart a server supervised by home-hosted. Restarting the entry this session runs as will end the session.',\n parameters: { id: { type: 'string', required: true, description: 'Server entry id' } },\n },\n servers_create: {\n endpoint: 'servers.create',\n description: 'Add a server entry to home-hosted. The entry runs a command on this machine under the panel\\'s supervision.',\n parameters: { entry: { type: 'json', required: true, description: 'A full home-hosted server entry, including its id and command' } },\n },\n servers_update: {\n endpoint: 'servers.update',\n description: 'Change fields of an existing home-hosted server entry.',\n parameters: {\n id: { type: 'string', required: true, description: 'Server entry id' },\n patch: { type: 'json', required: true, description: 'Fields to change' },\n },\n },\n servers_delete: {\n endpoint: 'servers.delete',\n description: 'Stop and remove a home-hosted server entry. Refused for the entry this session runs as.',\n parameters: { id: { type: 'string', required: true, description: 'Server entry id' } },\n },\n autostart_install: {\n endpoint: 'boot.install',\n description: 'Install the OS entry that starts home-hosted at boot or login.',\n parameters: { mechanism: { type: 'string', description: 'Explicit mechanism, e.g. systemd-user; omit to pick the best available one' } },\n },\n autostart_uninstall: {\n endpoint: 'boot.uninstall',\n description: 'Remove the OS entry that starts home-hosted at boot or login.',\n parameters: { mechanism: { type: 'string', description: 'Explicit mechanism; omit to use the installed one' } },\n },\n}\n\nexport function toolNameFor(name: AgentToolName): string {\n return `home_hosted_${name}`\n}\n\nfunction registerOne(ctx: Context, service: HomeHostedService, name: AgentToolName): () => void {\n const spec = TOOL_SPECS[name]\n const toolName = toolNameFor(name)\n const mutating = MUTATING_AGENT_TOOLS.includes(name)\n\n return ctx.tools.register(defineTool({\n name: toolName,\n description: spec.description,\n parameters: spec.parameters,\n output: {\n schema: { type: 'string' },\n render: (_args, value) => [{ type: 'text', text: value }],\n },\n async execute(args, exec) {\n const input = (args ?? {}) as Record<string, unknown>\n\n if (mutating) {\n const approval = ctx.get('approval') as ApprovalLike | undefined\n if (approval?.request === undefined)\n return 'refused: this deployment has no approval service, so a mutating home-hosted tool cannot run.'\n const outcome = await approval.request({\n agent: (exec as { agent?: unknown } | undefined)?.agent,\n toolName,\n reason: `${spec.description} (${JSON.stringify(input)})`,\n })\n if (outcome !== 'allowed-once')\n return `refused: approval answered \"${outcome}\".`\n }\n\n try {\n const payload = name === 'servers_create'\n ? { entry: input.entry }\n : name === 'servers_update'\n ? { id: input.id, patch: input.patch }\n : name === 'status' || name === 'servers_list'\n ? {}\n : { id: input.id, mechanism: input.mechanism }\n const value = await service.call(spec.endpoint, payload)\n return JSON.stringify(value, null, 2)\n }\n catch (error) {\n return `failed: ${error instanceof Error ? error.message : String(error)}`\n }\n },\n }))\n}\n\nexport function registerAgentTools(ctx: Context, service: HomeHostedService, settings: SettingsStore): void {\n ctx.inject(['tools'], (scoped) => {\n const disposers: Array<() => void> = []\n\n const sync = (): void => {\n while (disposers.length > 0)\n disposers.pop()?.()\n const current = settings.get()\n if (!current.agentTools.enabled)\n return\n for (const name of current.agentTools.allow) {\n try {\n disposers.push(registerOne(scoped, service, name))\n }\n catch {\n // one unruly tool must not keep the rest of the allowlist off the model\n }\n }\n }\n\n scoped.effect(() => {\n sync()\n const off = settings.onChange(sync)\n return () => {\n off()\n while (disposers.length > 0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"process", "fs", "path", "fs", "name", "name", "run", "fs", "fs", "path", "validate", "path", "codeOf", "problem", "run", "fs", "fs", "path", "validate", "fs", "path", "fs", "path", "validate", "codeOf", "problem", "run", "name", "path", "fs", "payload", "process", "os", "candidate", "status", "provider", "fs", "os", "path", "fs", "path", "process", "fs", "path", "process", "process", "fs", "path", "process", "fs", "path", "process", "fs", "path", "process", "fs", "path", "version", "supported", "process", "fs", "path", "process", "path", "fs", "process", "spawn", "fs", "path", "process", "path", "process", "fs", "spawn", "path", "answer", "process", "process", "path", "path", "path", "process", "entry", "cliArgs", "fs", "name", "path"]
|
|
7
|
+
}
|