#!/usr/bin/env node import { readFile, rm, writeFile } from "node:fs/promises"; import path from "node:path"; import { pathToFileURL } from "node:url"; import { createOutput, createScaffold, redactValue } from "@clifn/core"; import { DevFnConfigError, discoverProject, loadTrustedDevFnConfig, renderDevFnConfig, resolveContainedPath, resolveDevFnManifestPath, trustProject, } from "@devfn/config"; import { DevFnError, DevFnOrchestrator, lifecycleOwnerMayRun, listRuntimeReceipts, oauthRelayStatus, selectRuntime, planPublicUrls, readRegisteredDomains, readTunnelBindings, recoverOrphanedProxyRoutes, recoverTunnel, registerDomain, registerTunnelBinding, ephemeralOriginDomain, resolveInstanceIdentity, resolveTunnelBinding, startOAuthRelay, stopOAuthRelay, tunnelStatus, unregisterDomain, unregisterTunnelBinding, type TunnelBindingInput, } from "@devfn/core"; import { FilePortRegistry, renderPortInventory } from "@devfn/ports"; import { defaultStateDir } from "@devfn/config"; interface ParsedArgs { command: string; positionals: string[]; json: boolean; yes: boolean; trust: boolean; configPath?: string; profile?: string; runtime?: string; stateDir?: string; output?: string; tail?: number; allowPublic: boolean; tls?: string; certificateFile?: string; keyFile?: string; host?: string; tunnel: Partial>; nonproduction: boolean; ephemeral: boolean; rerunTasks: string[]; } export interface CliOptions { cwd?: string; env?: NodeJS.ProcessEnv; stdout?: (text: string) => void; stderr?: (text: string) => void } const HELP = `DevFn — portable local development environments Usage: devfn [options] Commands: init Inspect a repository and preview or write devfn.config.ts up Reserve ports and start the selected profile down Stop only the selected runtime of this worktree restart Restart the selected runtime of this worktree status Show processes, services, ports, and health runtimes List the runtimes of this checkout that have receipts logs [name] Show process or Compose logs doctor Diagnose runtimes, Docker, ports, leases, and proxy ports [gc|report] Inspect, reconcile, collect (incl. orphaned routes), or report port state url [name] Print resolved local URLs domains [list|register|unregister] Manage machine-owned development domains oauth-relay [status|start |stop] Manage the machine's OAuth callback relay tunnel [list|register |unregister |urls|status |recover ] Manage machine public tunnel bindings and preview public URLs Options: --profile Select a named profile --runtime Select a named runtime of this checkout (up, down, restart, status, logs, doctor, url, tunnel urls); omitted selects the default runtime --config Use an explicit manifest --json Emit one machine-readable JSON value --trust Trust the current manifest digest before loading it --allow-public Confirm processes, ports or tunnel routes declared as public exposure --rerun-task Run a task on this start although its record would skip or block it (repeatable) --yes Confirm devfn init writes --state-dir Override machine state (primarily for testing) --output Write a ports report --tail Limit log lines --tls Domain TLS: internal or certificate --cert Certificate PEM for certificate TLS --key Private key PEM for certificate TLS --host