home-hosted 0.13.0 → 0.13.1

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.
Files changed (37) hide show
  1. package/dist/chunks/{backup-CZcVca2a.js → backup-DeAJ3pbO.js} +6 -6
  2. package/dist/chunks/{backup-CZcVca2a.js.map → backup-DeAJ3pbO.js.map} +1 -1
  3. package/dist/chunks/{backups-CFRaWe_m.js → backups-twva7x2n.js} +3 -3
  4. package/dist/chunks/{backups-CFRaWe_m.js.map → backups-twva7x2n.js.map} +1 -1
  5. package/dist/chunks/{daemon-qKVECISl.js → daemon-CofN9k6Q.js} +3 -3
  6. package/dist/chunks/{daemon-qKVECISl.js.map → daemon-CofN9k6Q.js.map} +1 -1
  7. package/dist/chunks/{down-pKbGCW9d.js → down-C59ne5aM.js} +5 -5
  8. package/dist/chunks/{down-pKbGCW9d.js.map → down-C59ne5aM.js.map} +1 -1
  9. package/dist/chunks/{nanny-BtWfy0QH.js → nanny-COyCJXj9.js} +10 -5
  10. package/dist/chunks/nanny-COyCJXj9.js.map +1 -0
  11. package/dist/chunks/{nanny-ChMtq1Zl.js → nanny-Dnun3hVB.js} +3 -3
  12. package/dist/chunks/{nanny-ChMtq1Zl.js.map → nanny-Dnun3hVB.js.map} +1 -1
  13. package/dist/chunks/{nanny-B-Eu0sFW.js → nanny-rewguyXg.js} +2 -2
  14. package/dist/chunks/{nanny-B-Eu0sFW.js.map → nanny-rewguyXg.js.map} +1 -1
  15. package/dist/chunks/{nanny-sweep-DErnlPY1.js → nanny-sweep-ClVuNJRo.js} +3 -3
  16. package/dist/chunks/{nanny-sweep-DErnlPY1.js.map → nanny-sweep-ClVuNJRo.js.map} +1 -1
  17. package/dist/chunks/{port-B8WBTRMk.js → port-k5VBw8t9.js} +5 -2
  18. package/dist/chunks/{port-B8WBTRMk.js.map → port-k5VBw8t9.js.map} +1 -1
  19. package/dist/chunks/{restart-Des4DrAN.js → restart-BYu_E7x5.js} +5 -5
  20. package/dist/chunks/{restart-Des4DrAN.js.map → restart-BYu_E7x5.js.map} +1 -1
  21. package/dist/chunks/{server-Bge2r2qQ.js → server-By-zktjx.js} +3 -3
  22. package/dist/chunks/{server-Bge2r2qQ.js.map → server-By-zktjx.js.map} +1 -1
  23. package/dist/chunks/{set-token-obPiEJYk.js → set-token-xJkA1IZp.js} +2 -2
  24. package/dist/chunks/{set-token-obPiEJYk.js.map → set-token-xJkA1IZp.js.map} +1 -1
  25. package/dist/chunks/{src-BtWMFmzZ.js → src-BOBh9MBf.js} +9 -6
  26. package/dist/chunks/src-BOBh9MBf.js.map +1 -0
  27. package/dist/chunks/{status-DT1EsA-B.js → status-B6f2-qhs.js} +2 -2
  28. package/dist/chunks/{status-DT1EsA-B.js.map → status-B6f2-qhs.js.map} +1 -1
  29. package/dist/chunks/{up-Pdz-l6IH.js → up-DNZuTi2q.js} +4 -4
  30. package/dist/chunks/{up-Pdz-l6IH.js.map → up-DNZuTi2q.js.map} +1 -1
  31. package/dist/chunks/{usage-DFrCVXpT.js → usage-BrnDARNM.js} +2 -2
  32. package/dist/chunks/{usage-DFrCVXpT.js.map → usage-BrnDARNM.js.map} +1 -1
  33. package/dist/cli.js +11 -11
  34. package/package.json +1 -1
  35. package/uis/stock/dist/ui.json +2 -2
  36. package/dist/chunks/nanny-BtWfy0QH.js.map +0 -1
  37. package/dist/chunks/src-BtWMFmzZ.js.map +0 -1
@@ -1,9 +1,9 @@
1
1
  import { C as errorMessage, _ as prompt, c as bold, d as dim, f as fail, g as paint, h as invocation, m as green } from "../cli.js";
2
2
  import { C as tlsDir, N as workspacesPath, a as globalSecretsPath, c as hhDir, i as ensureStateDir, o as globalSettingsPath, x as resolveUserPath } from "./paths-CGlGDrOU.js";
3
3
  import { n as GlobalSettingsStore } from "./settings-xu-XTfWg.js";
4
- import { _ as entryStatePath, a as unknownBackupIds, b as WorkspaceStore, n as buildBackupSources, t as BackupService, v as readEntryState, y as writeEntryState } from "./backups-CFRaWe_m.js";
4
+ import { _ as entryStatePath, a as unknownBackupIds, b as WorkspaceStore, n as buildBackupSources, t as BackupService, v as readEntryState, y as writeEntryState } from "./backups-twva7x2n.js";
5
5
  import { n as WorkspaceRegistry } from "./workspaces-DYcfvKV_.js";
6
- import { _ as readNannyState } from "./nanny-BtWfy0QH.js";
6
+ import { _ as readNannyState } from "./nanny-COyCJXj9.js";
7
7
  import process from "node:process";
8
8
  import { defineCommand } from "citty";
9
9
  import path from "node:path";
@@ -193,7 +193,7 @@ function human(bytes) {
193
193
  }
194
194
  /** The running panel's record, or a message saying what to do instead. */
195
195
  async function livePanel() {
196
- const daemon = await import("./daemon-qKVECISl.js");
196
+ const daemon = await import("./daemon-CofN9k6Q.js");
197
197
  const runtime = daemon.readRuntime();
198
198
  if (runtime === null || !await daemon.runtimeIsAlive(runtime)) {
199
199
  if (runtime !== null && await daemon.runtimeIsGone(runtime)) daemon.clearRuntime();
@@ -208,7 +208,7 @@ async function livePanel() {
208
208
  * authority on what is running, and a stopped one has no opinion to disagree with.
209
209
  */
210
210
  async function usesPanel() {
211
- const daemon = await import("./daemon-qKVECISl.js");
211
+ const daemon = await import("./daemon-CofN9k6Q.js");
212
212
  const runtime = daemon.readRuntime();
213
213
  if (runtime === null || !await daemon.runtimeIsAlive(runtime)) return false;
214
214
  return (await daemon.probeRuntime(runtime)).reachable;
@@ -332,7 +332,7 @@ async function availableRowsFromDisk(action, suffix) {
332
332
  * be reached yields no ids — the refusal still fires, it just cannot enumerate.
333
333
  */
334
334
  async function availableRows(action, suffix) {
335
- const daemon = await import("./daemon-qKVECISl.js");
335
+ const daemon = await import("./daemon-CofN9k6Q.js");
336
336
  const runtime = daemon.readRuntime();
337
337
  if (runtime === null || !await daemon.runtimeIsAlive(runtime)) return await availableRowsFromDisk(action, suffix);
338
338
  const path = action === "create" ? "/_hh/backups" : "/_hh/backups/restore";
@@ -819,4 +819,4 @@ var backupCommand = defineCommand({
819
819
  //#endregion
820
820
  export { backupCommand };
821
821
 
822
- //# sourceMappingURL=backup-CZcVca2a.js.map
822
+ //# sourceMappingURL=backup-DeAJ3pbO.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"backup-CZcVca2a.js","names":["hhDir","defaultHhDir","defaultGlobalSettingsPath","defaultWorkspacesPath","Service","defaultGlobalSecretsPath","defaultTlsDir"],"sources":["../../src/cli/backup-offline.ts","../../src/cli/backup.ts"],"sourcesContent":["import type { BackupService } from '#src/services/backups'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { GlobalSettingsStore } from '#src/config/settings'\nimport { WorkspaceStore } from '#src/config/store'\nimport { WorkspaceRegistry } from '#src/config/workspaces'\nimport {\n globalSecretsPath as defaultGlobalSecretsPath,\n globalSettingsPath as defaultGlobalSettingsPath,\n hhDir as defaultHhDir,\n tlsDir as defaultTlsDir,\n workspacesPath as defaultWorkspacesPath,\n ensureStateDir,\n} from '#src/helpers/paths'\nimport { entryStatePath, readEntryState, writeEntryState } from '#src/providers/entry-state'\nimport { readNannyState } from '#src/providers/nanny'\nimport { buildBackupSources, BackupService as Service } from '#src/services/backups'\n\n/**\n * A backup service for a host whose panel is **not running**.\n *\n * `backup` used to need the daemon because the service is built inside it, so backing up or\n * restoring meant leaving the panel up — the opposite of what someone migrating a machine wants.\n * Nothing in the service needs the daemon: every source is a file, and the one live fact it wants\n * (which entries are running) is on disk as the nanny state each entry writes.\n *\n * This builds the same sources the panel does, through the same `buildBackupSources`, so an offline\n * archive cannot differ from an online one. `runningServers` is answered from `.state/*.json` rather\n * than from supervisor views: a *persistent* entry keeps running when the panel stops, so \"no panel\"\n * does not mean \"nothing is running\", and the restore warning has to keep telling the truth.\n */\n\n/** The workspace ids this host knows, from the registry on disk. */\nfunction workspaceIds(registry: WorkspaceRegistry): Array<{ id: string, label: string }> {\n return registry.all().map(workspace => ({ id: workspace.id, label: workspace.label }))\n}\n\n/**\n * Entries whose nanny is alive right now, read from the state files they rewrite.\n *\n * Every path comes from `hhDir`, never from the module-level helpers: those resolve from this\n * process's own `HHOSTED_HOME`, so a caller passing `--home` elsewhere would read a different host's\n * state — which is exactly how a test came to depend on the developer's real `~/.home-hosted`.\n */\nfunction runningFromDisk(hhDir: string, ids: string[]): Array<{ workspaceId: string, serverId: string }> {\n const running: Array<{ workspaceId: string, serverId: string }> = []\n for (const workspaceId of ids) {\n const stateDir = path.join(hhDir, workspaceId, '.state')\n let names: string[]\n try {\n names = fs.readdirSync(stateDir)\n }\n catch {\n continue\n }\n for (const name of names) {\n // `<id>.json` is a persistent entry's nanny state; `<id>.run.json` is a detached child.\n if (!name.endsWith('.json') || name.endsWith('.spec.json') || name.endsWith('.tmp'))\n continue\n const serverId = name.replace(/\\.run\\.json$|\\.json$/, '')\n if (serverId.length === 0)\n continue\n const state = readNannyState(path.join(stateDir, name))\n if (state === null)\n continue\n // The heartbeat is the panel's own liveness rule, so this agrees with what the UI would say.\n if (Date.now() - state.heartbeatAt <= 30_000)\n running.push({ workspaceId, serverId })\n }\n }\n return running\n}\n\nexport interface OfflineBackup {\n service: BackupService\n /** The workspaces this host declares, for a refusal that lists real ids. */\n workspaceIds: string[]\n /** Entries whose process is alive right now, read from the state files they rewrite. */\n runningNow: () => Array<{ workspaceId: string, serverId: string }>\n}\n\n/**\n * Build the service against this host's files.\n *\n * `ensureWorkspace` and `onRestored` are the two panel hooks, and both are deliberately absent: with\n * no daemon there is nothing to reload, and a restore that brings a workspace this host lacks leaves\n * it on disk for the next `up` to pick up. The registry is written by the service itself, which is\n * what makes that work.\n */\nexport function createOfflineBackup(options: { hhDir?: string, settingsPath?: string } = {}): OfflineBackup {\n const hhDir = options.hhDir ?? defaultHhDir\n const settingsPath = options.settingsPath ?? defaultGlobalSettingsPath\n const registryPath = path.join(hhDir, path.basename(defaultWorkspacesPath))\n\n // Read-only: looking at a fresh home (`backup list`, a plan) must not seed its config files. The\n // writes a restore makes go through the service, and the registry writes itself on `create`.\n const settings = new GlobalSettingsStore(settingsPath)\n settings.load({ write: false })\n const registry = new WorkspaceRegistry(registryPath)\n registry.load({ write: false })\n\n const workspaces = workspaceIds(registry)\n const ids = workspaces.map(workspace => workspace.id)\n\n // Each workspace's servers are read from its config, which is the only thing the source builder\n // needs beyond the id — no supervisor, no runtime. The paths are the ones the panel's own stores\n // read, so a stopped panel cannot archive a different file than a running one.\n const loaded = workspaces.map((workspace) => {\n const dir = path.join(hhDir, workspace.id)\n const settingsPath = path.join(dir, 'settings.json')\n const serversPath = path.join(dir, 'servers.config.json')\n const secretsPath = path.join(dir, '.secrets.json')\n const store = new WorkspaceStore(workspace.id, settingsPath, serversPath)\n store.load({ write: false })\n return { id: workspace.id, label: workspace.label, settingsPath, serversPath, secretsPath, servers: store.servers }\n })\n\n const service = new Service({\n dataRoot: hhDir,\n getConfig: () => settings.backups,\n /**\n * Register a workspace the archive brought.\n *\n * A panel-only hook in the running case, because the panel creates the runtime itself. With no\n * panel there is nobody to do it, so the registry is written here — otherwise a restored\n * workspace's files land on disk unreachable, and the next `up` never looks at them.\n */\n /**\n * Record the staged dump so the entry's next `up` loads it.\n *\n * Nothing is running to hold it in memory, so this is the only path that matters offline: the\n * panel is started afterwards, reads the entry state, and runs the hook.\n */\n onLoadPending: (workspaceId, serverId, dumpDir) => {\n // `entryStatePath` is the one spelling of this file. Hand-building `<id>.json` wrote a\n // different name than the supervisor reads (`<id>.run.json`), so the staged load was silently\n // invisible — the same class of bug as the schema rejection just above.\n const dir = path.join(hhDir, workspaceId, '.state')\n ensureStateDir(dir)\n const statePath = entryStatePath(dir, serverId)\n // Through `readEntryState`/`writeEntryState`, not hand-rolled JSON: the schema requires\n // `restarts` and `bootstrapDone`, and a file missing them is silently rejected on read — which\n // is how the staged load became invisible to the panel that was supposed to run it.\n const persisted = readEntryState(statePath)\n writeEntryState(statePath, {\n // No `bootstrapDone` default of `true`: that told the entry its `runOnce` bootstrap had\n // already run, so a restored blank host skipped its install/migrate step entirely.\n ...(persisted ?? { restarts: 0, bootstrapDone: false }),\n pendingLoad: dumpDir,\n })\n },\n ensureWorkspace: (input) => {\n if (registry.has(input.id))\n return\n // `create` writes the registry file itself; there is no separate save.\n registry.create(input)\n },\n getSources: () => buildBackupSources({\n globalSettingsPath: settings.path,\n globalSecretsPath: path.join(hhDir, path.basename(defaultGlobalSecretsPath)),\n tlsDir: path.join(hhDir, path.basename(defaultTlsDir)),\n registryPath,\n includePaths: settings.backups.includePaths,\n runningServers: () => runningFromDisk(hhDir, ids),\n workspaces: loaded,\n }),\n })\n\n return { service, workspaceIds: ids, runningNow: () => runningFromDisk(hhDir, ids) }\n}\n","import type { requestControl, Runtime } from '#src/helpers/daemon'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { defineCommand } from 'citty'\nimport { createOfflineBackup } from '#src/cli/backup-offline'\nimport { bold, dim, fail, green, invocation, paint, prompt } from '#src/cli/io'\nimport { resolveUserPath } from '#src/helpers/paths'\nimport { unknownBackupIds } from '#src/shared/backup-scope'\nimport { errorMessage } from '#src/shared/error-message'\n\n/**\n * `backup` — take an archive, list them, or restore one, without a browser.\n *\n * The archive is written by the panel, never by this command: it drives the running panel over the\n * same local token `down` and `start` use, so the allowlist, the manifest shape and the retention\n * rules stay in one implementation.\n *\n * `create` and `restore` both **plan first**. Nothing is written unless `--confirm` is given or the\n * person answers yes at a prompt — and a session that cannot be asked is not treated as consent, so\n * it prints the plan and says how to apply it. `--json` prints the same plan as JSON, for a script\n * or an agent that wants to read it rather than apply it.\n */\n\ninterface BackupFileView {\n name: string\n sizeBytes: number\n createdAt: number | null\n /** Only the panel's view carries it; the service's own list does not. */\n automatic?: boolean\n}\n\ninterface CreatedBody {\n file?: { name: string, sizeBytes: number }\n warnings?: string[]\n}\n\n/** One thing a backup would capture, or a restore would write. */\ninterface PlanHook {\n serverId: string\n workspaceId: string\n action: 'dump' | 'load'\n ok: boolean\n output?: string\n}\n\ninterface PlanItem {\n id: string\n kind?: string\n label?: string\n note?: string | null\n /** The plan lists everything; this says whether the request selected it. */\n selected?: boolean\n items?: Array<{ id: string, label?: string, note?: string | null }>\n}\n\n/** One row of a plan: an id, and what the panel says about it. */\ninterface PlanRow {\n id: string\n note?: string | null\n}\n\n/**\n * What a restore plan says beyond its items.\n *\n * `error` is not a warning: the service fills it when it refused to write *anything* — a file that\n * is not a zip, an archive from a newer config schema, a password that is missing or wrong — and the\n * plan is then empty. Filtering that plan to `items` and printing \"restored 0 items\" made every one\n * of those read as a tidy no-op, on the one command a person runs on a blank host with no other way\n * to check. `skipped` is the same list the UI draws, so a restore that dropped a piece says which.\n */\ninterface RestoreOutcome {\n items?: PlanItem[]\n skipped?: string[]\n /** Set by the service when nothing was applied. */\n error?: string\n /** Set instead of `error` when the archive needs a password that was absent or wrong. */\n needsPassword?: boolean\n hooks?: PlanHook[]\n restartRequired?: boolean\n createdWorkspaces?: string[]\n replacedUnderRunning?: Array<{ workspaceId: string, serverId: string, path: string }>\n}\n\n/**\n * Render plan ids as the tree they already are.\n *\n * Every id is a colon-separated path, so the hierarchy is in the data and the renderer's only job is\n * to show it: one row per prefix, each one level deeper than its parent. Depth is whatever the id\n * says, not a fixed number of columns — `workspace:default:secrets:telegram` sits three deep, and a\n * renderer that assumed two printed it beside its own parent.\n *\n * Both directions print through this, and so does the \"what could I act on\" list, so the three read\n * alike. A row's note is the panel's own wording, passed through untouched.\n */\nfunction printPlanTree(rows: PlanRow[], out: (text: string) => void = text => process.stdout.write(text)): void {\n const known = new Set(rows.map(row => row.id))\n // Every prefix of every id, so a parent that is not itself a row still gets a line to hang under.\n const nodes = new Map<string, { note: string | null, children: Set<string> }>()\n const ensure = (id: string): { note: string | null, children: Set<string> } => {\n const existing = nodes.get(id)\n if (existing !== undefined)\n return existing\n const created = { note: null, children: new Set<string>() }\n nodes.set(id, created)\n return created\n }\n for (const row of rows) {\n const segments = row.id.split(':')\n // `workspace:<id>:data:/a/b` carries a path in its last segment; it is a leaf, not a branch.\n for (let depth = 1; depth <= segments.length; depth++) {\n const id = segments.slice(0, depth).join(':')\n const node = ensure(id)\n if (depth > 1)\n ensure(segments.slice(0, depth - 1).join(':')).children.add(id)\n if (depth === segments.length && known.has(row.id))\n node.note = row.note ?? null\n }\n }\n\n const roots = [...nodes.keys()].filter(id => !id.includes(':'))\n const write = (id: string, depth: number): void => {\n const node = nodes.get(id)\n if (node === undefined)\n return\n const padding = ' '.repeat(depth)\n out(`${padding}${depth === 1 ? '' : '- '}${id}${node.note === null ? '' : ` ${dim(`(${node.note})`)}`}\\n`)\n for (const child of node.children)\n write(child, depth + 1)\n }\n for (const root of roots)\n write(root, 1)\n}\n\nfunction human(bytes: number): string {\n if (bytes < 1024)\n return `${bytes} B`\n if (bytes < 1024 * 1024)\n return `${Math.round(bytes / 1024)} KB`\n return `${(bytes / 1024 / 1024).toFixed(1)} MB`\n}\n\n/** The running panel's record, or a message saying what to do instead. */\nasync function livePanel(): Promise<(Runtime & { request: typeof requestControl }) | null> {\n const daemon = await import('#src/helpers/daemon')\n const runtime = daemon.readRuntime()\n if (runtime === null || !await daemon.runtimeIsAlive(runtime)) {\n if (runtime !== null && await daemon.runtimeIsGone(runtime))\n daemon.clearRuntime()\n return null\n }\n return Object.assign(runtime, { request: daemon.requestControl })\n}\n\n/**\n * Whether to talk to a panel or work on the files directly.\n *\n * Both paths run the same service, so the only question is who owns the state: a live panel is the\n * authority on what is running, and a stopped one has no opinion to disagree with.\n */\nasync function usesPanel(): Promise<boolean> {\n const daemon = await import('#src/helpers/daemon')\n const runtime = daemon.readRuntime()\n if (runtime === null || !await daemon.runtimeIsAlive(runtime))\n return false\n return (await daemon.probeRuntime(runtime)).reachable\n}\n\n/** Exit on a non-200 control answer with the panel's own message, or the status. */\nfunction failWithAnswer(answer: { status: number, body: unknown }): never {\n const body = answer.body as { message?: string } | null\n if (body?.message !== undefined)\n fail(body.message)\n fail(`the panel answered ${answer.status}`)\n}\n\n/**\n * What a `create`/`restore` should act on: `'all'`, or an explicit list of ids.\n *\n * There is no \"neither flag\" case. Reading it as \"everything\" made the destructive path the default —\n * `backup create --confirm` would archive the whole machine, and a restore would write the whole\n * archive, without anyone naming what they meant. A scope is now required, so silence is refused\n * rather than guessed.\n */\ntype Scope = { kind: 'all' } | { kind: 'include', ids: string[] }\n\n/** Where a restore reads its archive from: a name in the backups directory, or a path. */\ntype RestoreSource = { kind: 'name', name: string } | { kind: 'from', path: string }\n\n/**\n * The flag combination, as far as it can be judged without asking the panel.\n *\n * `null` means \"neither flag\", which only the caller can resolve — it lists the available ids, and\n * that needs a panel. Every other case is decided here, before any lookup, so a typo is refused\n * whether or not anything is running.\n */\nfunction parseScope(all: boolean, raw: string | undefined): Scope | null {\n if (all && raw !== undefined)\n fail('--include and --all are exclusive — pass one or the other')\n if (all)\n return { kind: 'all' }\n if (raw === undefined)\n return null\n const ids = raw.split(',').map(part => part.trim()).filter(part => part.length > 0)\n if (ids.length === 0)\n fail('--include is empty — name the ids to act on, or pass --all for everything')\n return { kind: 'include', ids }\n}\n\n/**\n * The plan rows a scope selects, and an exclusion drops.\n *\n * `kind` is deliberately not part of this: it is the panel's label for a row, not an id, and every id\n * the plan prints is already prefixed with it (`global:settings`, `workspace:default:servers`).\n */\n/** Flatten a nested plan into the rows the tree renders. */\nfunction flattenRows(rows: PlanItem[]): PlanRow[] {\n return rows.flatMap(row => [\n { id: row.id, note: row.note ?? null },\n ...(row.items ?? []).map(leaf => ({ id: leaf.id, note: leaf.note ?? null })),\n ])\n}\n\nfunction filterEntries<T extends { id: string, items?: Array<{ id: string }> }>(entries: T[], scope: Scope, exclude: string[] | undefined): T[] {\n const unwanted = exclude ?? []\n const excluded = (id: string): boolean => unwanted.some(entry => id === entry || id.startsWith(`${entry}:`))\n // Upwards too: naming a leaf (`workspace:default:servers`) has to keep its parent entry in the\n // plan, or the leaf's own file is captured and the plan says \"nothing matched\".\n const named = (id: string): boolean => scope.kind === 'all'\n || scope.ids.some(entry => id === entry || id.startsWith(`${entry}:`) || entry.startsWith(`${id}:`))\n // The leaves are filtered too: a plan that lists `workspace:default:servers` while the archive\n // leaves it out is a plan that describes a different backup from the one it is planning.\n return entries\n .filter(entry => named(entry.id) && !excluded(entry.id))\n .map(entry => (entry.items === undefined\n ? entry\n : { ...entry, items: entry.items.filter(leaf => named(leaf.id) && !excluded(leaf.id)) }))\n}\n\n/**\n * Refuse an id the plan does not have.\n *\n * An id that matches nothing is silently ignored by the service, which is right for an archive that\n * simply does not carry something — and wrong for a typo: `--exclude global:secret` excludes nothing\n * and says nothing, so the archive carries the credentials the person believed they had dropped.\n *\n * `action` decides the hint, because the two directions list their ids from different places: a\n * create plan lists what this host declares, a restore plan lists what the archive holds — and the\n * command that prints that one is a restore, not a create.\n */\nfunction assertKnown(ids: string[] | undefined, entries: PlanItem[], flag: string, action: 'create' | 'restore'): void {\n if (ids === undefined)\n return\n // The same rule the settings page applies to a schedule scope, so a typo is refused wherever it\n // is typed rather than only in the dialog.\n const unknown = unknownBackupIds(ids, entries)\n if (unknown.length > 0) {\n const hint = action === 'create'\n ? `\\`backup create\\` with no flags lists the ids`\n : `\\`backup restore <name>\\` with no --include/--exclude lists the ids the archive holds`\n fail(`${flag} names ${unknown.map(id => `\"${id}\"`).join(', ')}, which ${unknown.length === 1 ? 'is' : 'are'} not in this plan — ${hint}`)\n }\n}\n\n/** `--exclude` parsed. An empty value is a mistake, not \"exclude nothing\". */\nfunction parseExclude(raw: string | undefined): string[] | undefined {\n if (raw === undefined)\n return undefined\n const ids = raw.split(',').map(part => part.trim()).filter(part => part.length > 0)\n if (ids.length === 0)\n fail('--exclude is empty — name the ids to leave out, or drop the flag')\n return ids\n}\n\n/**\n * Neither flag given. Refused outright — the ids are a *bonus*, not the reason.\n *\n * The refusal must not depend on a panel being up: a mistyped command deserves the flag error, not\n * \"home-hosted is not running\". So the list is best-effort, and a failure to produce it is silent.\n */\nasync function refuseWithoutScope(action: 'create' | 'restore', suffix: string): Promise<never> {\n const rows = await availableRows(action, suffix).catch(() => [] as PlanItem[])\n if (rows.length === 0)\n fail('name what to act on — pass --include <ids> or --all')\n // The same tree the plan uses, so all three outputs read alike: a flat list here was the one place\n // the scopes and the nesting disappeared.\n //\n // All of it on stderr, tree included. A `--json` caller reads stdout, and the tree landed there\n // while the sentence explaining it did not: measured `backup create --json` writing ` global` /\n // ` - global:settings` to stdout and `error name what to act on` to stderr, so a script got\n // neither a document nor a reason, and a terminal with stderr filtered got ids with no sentence.\n process.stderr.write(`${paint('31', 'error')} name what to act on — pass --include <ids> or --all\\n\\n`)\n process.stderr.write('available (or narrow it):\\n')\n printPlanTree(flattenRows(rows), text => process.stderr.write(text))\n process.stderr.write('\\n--exclude <ids> leaves those out: --all --exclude global:secrets\\n')\n process.exit(1)\n}\n\n/**\n * The ids an offline run could act on, read from the state files.\n *\n * The refusal has to name real ids whether or not a panel is up — an empty list is the one answer\n * worse than no list, because it reads as \"there is nothing to back up\".\n */\nasync function availableRowsFromDisk(action: 'create' | 'restore', suffix: string): Promise<PlanItem[]> {\n try {\n const { service } = createOfflineBackup()\n await service.warm()\n if (action === 'create')\n return service.selection().entries as unknown as PlanItem[]\n // A restore lists what the **archive** holds, not what this host declares. Reading the create\n // view here named every slot on the machine — including ones the archive never carried — and\n // marked them \"(not set)\", which is not a thing a restore can be missing.\n // The same either/or the restore itself takes: a name resolved against the backups directory,\n // or a path read where it is.\n const query = new URLSearchParams(suffix.startsWith('?') ? suffix.slice(1) : suffix)\n const from = query.get('from')\n const name = query.get('name')\n const archive = from !== null && from.length > 0\n ? (fs.existsSync(from) && fs.statSync(from).isFile() ? from : null)\n : (name === null || name.length === 0 ? null : service.resolve(name))\n if (archive === null)\n return []\n const plan = await service.restore(archive, { confirm: false })\n return (plan.items ?? []).filter(item => item.selected !== false)\n }\n catch {\n return []\n }\n}\n\n/**\n * The ids this action could be scoped to.\n *\n * `create` asks what the entries declare; `restore` asks what the archive holds. Both come from the\n * panel, so the list in a refusal is the real one rather than a hardcoded guess. A panel that cannot\n * be reached yields no ids — the refusal still fires, it just cannot enumerate.\n */\nasync function availableRows(action: 'create' | 'restore', suffix: string): Promise<PlanItem[]> {\n // Read the record directly rather than through `livePanel()`: a hint must not `fail()` the process\n // when the panel is down, and the caller turns an empty list into \"nothing to list\".\n const daemon = await import('#src/helpers/daemon')\n const runtime = daemon.readRuntime()\n if (runtime === null || !await daemon.runtimeIsAlive(runtime))\n return await availableRowsFromDisk(action, suffix)\n const path = action === 'create' ? '/_hh/backups' : '/_hh/backups/restore'\n const answer = await daemon.requestControl(runtime, `${path}${suffix}`, 120000)\n if (answer === null || answer.status !== 200)\n return []\n const body = answer.body as { entries?: PlanItem[], items?: PlanItem[] } | null\n // The rows themselves, not just their ids: a refusal that lists what could be acted on should say\n // the same things the plan does, `(not set)` included.\n return action === 'create' ? (body?.entries ?? []) : (body?.items ?? [])\n}\n\n/** `?a=b`, or `''`. */\nfunction suffixOf(query: URLSearchParams): string {\n return query.size === 0 ? '' : `?${query.toString()}`\n}\n\n/** Appends one query parameter, keeping the `?`/`&` right. */\nfunction withParam(suffix: string, key: string, value: string): string {\n return `${suffix}${suffix === '' ? '?' : '&'}${key}=${encodeURIComponent(value)}`\n}\n\n/**\n * Ask before writing.\n *\n * A session that cannot be asked is refused, exit 1, after the plan: not a silent write, and not a\n * success. Exiting 0 here meant a cron job's `backup create --all` printed a plan every night and\n * never took a backup, with nothing in its exit status to say so. (`--json` without `--confirm` is\n * the explicit \"show me the plan\" request and still exits 0; it never reaches this.)\n */\nasync function consent(question: string): Promise<boolean> {\n if (process.stdin.isTTY !== true)\n fail('not applied — this session cannot ask for consent; re-run with --confirm to apply (or --json to only read the plan)')\n const answer = await prompt(`${question} [y/N] `)\n if (/^yes$|^y$/i.test(answer.trim())) {\n process.stdout.write('\\n')\n return true\n }\n process.stdout.write('cancelled — nothing was written\\n')\n return false\n}\n\n/**\n * Run against the panel when one is up, and against the files when it is not.\n *\n * Both run the same `BackupService`, so the archive cannot differ; only the authority on what is\n * running changes. A stopped panel is exactly when someone wants to back up or restore — the services\n * are down because they stopped them on purpose.\n */\nexport async function runBackupList(json: boolean): Promise<void> {\n if (await usesPanel()) {\n const runtime = await livePanel()\n if (runtime !== null) {\n const answer = await runtime.request(runtime, '/_hh/backups', 30000, 'GET')\n if (answer === null)\n fail(`the control panel is not answering on ${runtime.probeUrl}`)\n if (answer.status !== 200)\n failWithAnswer(answer)\n printList(answer.body as { files?: BackupFileView[], dir?: string } | null, json)\n return\n }\n }\n const { service } = createOfflineBackup()\n await service.warm()\n printList(service.selection(), json)\n}\n\nfunction printList(view: { files?: BackupFileView[], dir?: string } | null, json: boolean): void {\n const files = view?.files ?? []\n if (json) {\n process.stdout.write(`${JSON.stringify(view, null, 2)}\\n`)\n return\n }\n if (files.length === 0) {\n process.stdout.write(`no backups yet — \\`${invocation()} backup create --all\\` takes one\\n`)\n return\n }\n const noun = files.length === 1 ? 'archive' : 'archives'\n process.stdout.write(`${bold(String(files.length))} ${noun}${view?.dir === undefined ? '' : ` in ${dim(view.dir)}`}\\n`)\n for (const file of files) {\n const when = file.createdAt == null ? '' : new Date(file.createdAt).toISOString().replace('T', ' ').slice(0, 16)\n process.stdout.write(` ${file.name.padEnd(36)} ${human(file.sizeBytes).padStart(8)} ${dim(when)}${file.automatic ? dim(' auto') : ''}\\n`)\n }\n}\n\n/**\n * Name the entries still running, without blocking.\n *\n * A **persistent** entry keeps running while the panel is stopped, so \"panel off\" is not \"services\n * off\" — and its data being captured mid-write is worth knowing before it is relied on. Warned rather\n * than refused: the user may know, and the panel's own backup has always proceeded here.\n */\nfunction warnRunning(entries: Array<{ workspaceId?: string, serverId?: string, id?: string }>): void {\n if (entries.length === 0)\n return\n const named = entries.map(entry => entry.serverId ?? entry.id ?? '').filter(name => name.length > 0)\n const isOne = named.length === 1\n process.stdout.write(`${dim(`! ${named.length} entr${isOne ? 'y is' : 'ies are'} still running (${named.join(', ')}) — its data may be captured mid-write`)}\\n`)\n}\n\nexport async function runBackupCreate(options: { password?: string, scope: Scope, exclude?: string[], confirm: boolean, json: boolean }): Promise<void> {\n const scope = options.scope\n const online = await usesPanel()\n\n // The plan: what this archive would capture, from the same source either way.\n const entries = await (async (): Promise<PlanItem[]> => {\n if (online) {\n const runtime = await livePanel()\n if (runtime !== null) {\n const answer = await runtime.request(runtime, '/_hh/backups', 120000)\n if (answer === null)\n fail(`the control panel is not answering on ${runtime.probeUrl}`)\n if (answer.status !== 200)\n failWithAnswer(answer)\n return (answer.body as { entries?: PlanItem[] } | null)?.entries ?? []\n }\n }\n const { service } = createOfflineBackup()\n await service.warm()\n return service.selection().entries as unknown as PlanItem[]\n })()\n\n // Checked against the plan the user is looking at, so a typo is refused instead of quietly\n // excluding nothing.\n assertKnown(options.exclude, entries, '--exclude', 'create')\n assertKnown(scope.kind === 'include' ? scope.ids : undefined, entries, '--include', 'create')\n const wanted = filterEntries(entries, scope, options.exclude)\n\n if (!options.confirm) {\n if (options.json) {\n process.stdout.write(`${JSON.stringify({ action: 'create', apply: false, entries: wanted }, null, 2)}\\n`)\n return\n }\n process.stdout.write(`${bold('Plan')} — what a backup would capture; nothing has been written yet\\n`)\n printPlanTree(flattenRows(wanted))\n if (wanted.length === 0) {\n process.stdout.write(' (nothing matched — check --include, or what the entries declare)\\n')\n return\n }\n // From the state files either way: the panel's backup view has no per-entry running flag, and a\n // persistent entry's nanny rewrites its file whether or not the panel is up.\n warnRunning(createOfflineBackup().runningNow())\n if (!await consent('Take this backup?'))\n return\n }\n\n const include = scope.kind === 'include' ? scope.ids : undefined\n const exclude = options.exclude\n const created = await (async (): Promise<CreatedBody | null> => {\n if (online) {\n const runtime = await livePanel()\n if (runtime !== null) {\n const query = new URLSearchParams()\n if (options.password !== undefined && options.password.length > 0)\n query.set('password', options.password)\n if (include !== undefined)\n query.set('include', include.join(','))\n if (exclude !== undefined)\n query.set('exclude', exclude.join(','))\n const answer = await runtime.request(runtime, `/_hh/backups${withParam(suffixOf(query), 'confirm', 'true')}`, 600000)\n if (answer === null)\n fail(`the control panel is not answering on ${runtime.probeUrl}`)\n if (answer.status !== 200)\n failWithAnswer(answer)\n return answer.body as CreatedBody | null\n }\n }\n const { service } = createOfflineBackup()\n await service.warm()\n const result = await service.create({ password: options.password, include, exclude })\n if (!result.ok)\n fail(result.error ?? 'the backup failed')\n return { file: result.file, ...(result.warnings === undefined ? {} : { warnings: result.warnings }) }\n })()\n\n const file = created?.file\n if (file === undefined)\n fail('the backup reported success but named no archive')\n const warnings = created?.warnings ?? []\n if (options.json) {\n process.stdout.write(`${JSON.stringify({ action: 'create', apply: true, file, ...(warnings.length === 0 ? {} : { warnings }) }, null, 2)}\\n`)\n return\n }\n process.stdout.write(`${green('backup created')} ${file.name} ${dim(`(${human(file.sizeBytes)})`)}\\n`)\n for (const warning of warnings)\n process.stderr.write(`warning: ${warning}\\n`)\n}\n\n/**\n * Why a restore plan is not something to apply, or `null`.\n *\n * The service answers a plan for every archive, including ones it refuses to read: `error` carries\n * the refusal and `items` is empty. A caller that reads only `items` sees a tidy empty restore — and\n * on a blank host, `restored 0 items` printed with exit 0 is the worst possible answer, because\n * nothing distinguishes \"this archive was empty\" from \"this archive could not be opened\".\n *\n * `needsPassword` is its own case: it is the one refusal the person can fix from the same command.\n */\nfunction planRefusal(plan: RestoreOutcome | null): string | null {\n if (plan === null)\n return null\n if (plan.needsPassword === true) {\n const reason = plan.error ?? 'this backup is password-protected'\n return `${reason} — add \\`--password <text>\\` to unlock it`\n }\n if (plan.error !== undefined && plan.error.length > 0)\n return plan.error\n return null\n}\n\nexport async function runBackupRestore(options: { name?: string, from?: string, password?: string, scope: Scope, exclude?: string[], confirm: boolean, json: boolean }): Promise<void> {\n const scope = options.scope\n const online = await usesPanel()\n\n /**\n * What this restore reads from: an archive **name** in the backups directory, or a **path**.\n *\n * A name is an allowlist entry, which is why it is the default. `--from` is for the blank host\n * where the archive is on a USB stick: it names the file to read, not a directory to write in.\n * The two are refused together rather than one quietly winning — on the one command that\n * overwrites live data, a guess about which archive was meant is the wrong default.\n *\n * The path is resolved against *this* process's directory; the panel would resolve a relative\n * one against its own cwd, which is a different directory and so a different file.\n */\n const source: RestoreSource = options.from !== undefined\n ? { kind: 'from', path: resolveUserPath(options.from) }\n : { kind: 'name', name: options.name ?? '' }\n /** What to call it in the plan and the result: the file it read, name or path. */\n const label = source.kind === 'from' ? path.basename(source.path) : source.name\n\n // Checked here for both paths: when the panel is up *it* reads the file, so letting it answer\n // \"not a home-hosted backup\" for a path that simply is not there sends the person to inspect an\n // archive's contents instead of their typo.\n if (source.kind === 'from' && (!fs.existsSync(source.path) || !fs.statSync(source.path).isFile()))\n fail(`no file at ${source.path} — \\`--from\\` takes the path to an archive on this machine`)\n\n const service = online ? null : createOfflineBackup().service\n if (service !== null)\n await service.warm()\n\n // The plan is free and always shown: it is the only way to see what a restore would overwrite.\n const plan = await (async (): Promise<RestoreOutcome | null> => {\n if (service !== null) {\n // `--from` names a file, so there is no allowlist entry to resolve: the path is read, and\n // everything that decides *where* it may write still comes from the live config.\n if (source.kind === 'from')\n return await service.restore(source.path, { confirm: false, password: options.password, include: scope.kind === 'include' ? scope.ids : undefined, exclude: options.exclude })\n const archive = service.resolve(source.name)\n // The name is an *allowlist entry*, not a path: `resolve` refuses anything that is not a plain\n // archive name, so `backup restore /tmp/from-s3.zip` cannot be reached by naming the file.\n // Say both halves — which directory the name must be in, and that a path is not a name — and\n // point at `--from`, or the person on a blank host, holding the one archive, is told to run a\n // command that lists nothing and to try a name they have never seen.\n if (archive === null)\n fail(`no backup named \"${source.name}\" in ${service.directory} — a restore takes the archive's file name, not a path; pass --from <path> to read the file where it is, or copy it into that directory (\\`${invocation()} backup list\\` shows what is there)`)\n return await service.restore(archive, { confirm: false, password: options.password, include: scope.kind === 'include' ? scope.ids : undefined, exclude: options.exclude })\n }\n const runtime = await livePanel()\n if (runtime === null)\n fail(`the control panel is not answering — try again once it is up`)\n const base = restoreQuery(source, options, scope)\n const answer = await runtime.request(runtime, `/_hh/backups/restore${suffixOf(base)}`, 120000)\n if (answer === null)\n fail(`the control panel is not answering at ${runtime.probeUrl}`)\n if (answer.status !== 200)\n failWithAnswer(answer)\n return answer.body as RestoreOutcome | null\n })()\n\n // Refused before anything is printed as if it could be applied. A `--json` caller gets the plan\n // (with the reason in it) *and* a non-zero exit, so a script can branch on either.\n const refused = planRefusal(plan)\n if (refused !== null) {\n if (options.json)\n process.stdout.write(`${JSON.stringify({ action: 'restore', apply: false, name: label, error: refused }, null, 2)}\\n`)\n fail(refused)\n }\n\n // Every item the archive knows, with `selected` on each — `--include` narrows the selection, not\n // the list. Reading the list as the selection reported the whole archive either way.\n const items = (plan?.items ?? []).filter(item => item.selected !== false)\n // The same typo rule `create` applies, on this direction too: an id the archive does not carry is\n // a mistake, and `--exclude globalsecrets` excludes nothing while the archive still holds exactly\n // the credentials the person believed they had dropped.\n const archiveItems = plan?.items ?? []\n if (options.exclude !== undefined)\n assertKnown(options.exclude, archiveItems, '--exclude', 'restore')\n if (scope.kind === 'include')\n assertKnown(scope.ids, archiveItems, '--include', 'restore')\n\n if (options.json && !options.confirm) {\n process.stdout.write(`${JSON.stringify({ action: 'restore', apply: false, name: label, items, skipped: (plan?.skipped ?? []) }, null, 2)}\\n`)\n return\n }\n\n if (!options.json) {\n // With `--confirm` the same run goes on to apply, so the header must not claim nothing was\n // written — and the plan's skips are not reprinted below, where the applied result says them\n // again with the same words.\n process.stdout.write(options.confirm\n ? `${bold('Plan')} for ${label} — applying it now\\n`\n : `${bold('Plan')} for ${label} — nothing has been written yet\\n`)\n printPlanTree(items.map(item => ({ id: item.id, note: item.note ?? null })))\n if (!options.confirm) {\n for (const note of (plan?.skipped ?? []))\n process.stdout.write(` ${dim('!')} ${note}\\n`)\n }\n if (items.length === 0) {\n process.stdout.write(' (nothing to restore — check --include, or what this host declares)\\n')\n return\n }\n }\n\n if (!options.confirm && !await consent(`Restore these ${items.length} item(s) over this host?`))\n return\n\n // No lock here: `BackupService.restore` takes it on apply, so this path and the panel's both get\n // it from one place. A second guard here would be the third implementation of the same rule.\n {\n const outcome = await (async (): Promise<RestoreOutcome> => {\n if (service !== null) {\n // The plan above already proved this path (or name) reads, so it is reused rather than\n // resolved twice — and a file that vanished between the two is the service's refusal to\n // report, not a crash.\n const archive = source.kind === 'from' ? source.path : service.resolve(source.name)!\n const result = await service.restore(archive, { confirm: true, password: options.password, include: scope.kind === 'include' ? scope.ids : undefined, exclude: options.exclude })\n return { ...result, items: (result.items ?? []).filter(item => item.selected !== false) }\n }\n const runtime = await livePanel()\n if (runtime === null)\n fail('the control panel stopped answering — nothing further was written')\n const base = restoreQuery(source, options, scope)\n const answer = await runtime.request(runtime, `/_hh/backups/restore${withParam(suffixOf(base), 'confirm', 'true')}`, 600000)\n if (answer === null)\n fail(`the control panel is not answering at ${runtime.probeUrl}`)\n if (answer.status !== 200)\n failWithAnswer(answer)\n const result = answer.body as RestoreOutcome | null\n return {\n ...result,\n items: (result?.items ?? plan?.items ?? []).filter(item => item.selected !== false),\n ...(result?.hooks === undefined && plan?.hooks !== undefined ? { hooks: plan.hooks } : {}),\n }\n })()\n\n // The apply can refuse too, and it is the run that actually matters: a wrong password against an\n // encrypted archive reaches here, and a failure part-way names what already landed.\n const applyRefused = planRefusal(outcome)\n if (applyRefused !== null) {\n if (options.json)\n process.stdout.write(`${JSON.stringify({ action: 'restore', apply: true, name: label, error: applyRefused }, null, 2)}\\n`)\n fail(applyRefused)\n }\n\n const applied = (outcome.items ?? []).filter(item => item.selected !== false)\n const hooks = (outcome.hooks ?? []).filter(hook => hook.action === 'load')\n // The **apply's** skips, not the plan's: a dump staged for an entry with no `load` hook is only\n // discovered here, and reporting the plan's list dropped that sentence from both outputs. They are\n // the only thing that says a piece of an otherwise successful restore was left behind.\n const notes = outcome.skipped ?? []\n\n if (options.json) {\n process.stdout.write(`${JSON.stringify({\n action: 'restore',\n apply: true,\n name: label,\n items: applied,\n hooks,\n skipped: notes,\n ...(outcome.restartRequired === true ? { restartRequired: true } : {}),\n ...((outcome.createdWorkspaces ?? []).length === 0 ? {} : { createdWorkspaces: outcome.createdWorkspaces }),\n ...((outcome.replacedUnderRunning ?? []).length === 0 ? {} : { replacedUnderRunning: outcome.replacedUnderRunning }),\n }, null, 2)}\\n`)\n return\n }\n if (applied.length === 0)\n process.stdout.write(`${green('restored')} nothing — the archive carried no item this host can take\\n`)\n else\n process.stdout.write(`${green('restored')} ${applied.length} ${applied.length === 1 ? 'item' : 'items'} from ${label}\\n`)\n for (const hook of hooks)\n // \"staged\", not \"ran\": the hook runs on the entry's next start, and saying it already ran\n // would leave a person waiting for data that has not been loaded yet.\n process.stdout.write(` ${dim(`load ${hook.serverId}: ${hook.output ?? 'staged'}`)}\\n`)\n for (const note of notes)\n process.stdout.write(` ${dim('!')} ${note}\\n`)\n // The listener moved, so the panel that is up is not the one the archive described. Said here\n // because the CLI is where a restore from another host is run, and nothing else mentions it.\n if (outcome.restartRequired === true)\n process.stdout.write(` ${dim(`! the panel's listener changed — restart it so it binds where the archive says (\\`${invocation()} restart\\`)`)}\\n`)\n if ((outcome.createdWorkspaces ?? []).length > 0)\n process.stdout.write(` ${dim(`! created ${outcome.createdWorkspaces!.join(', ')}, which this host did not have`)}\\n`)\n if (service !== null)\n process.stdout.write(dim(`the panel is not running, so nothing was reloaded — the next \\`${invocation()} up\\` reads what was restored\\n`))\n }\n}\n\n/**\n * The restore query both the plan and the apply send.\n *\n * One builder, because the two requests must agree: a password or a selection on the plan and not on\n * the apply made the apply answer about different items than the person approved.\n */\nfunction restoreQuery(source: RestoreSource, options: { password?: string, exclude?: string[] }, scope: Scope): URLSearchParams {\n // `from` is read by the panel, so it travels in place of `name`, never as well — the same\n // either/or the CLI itself enforces on the flags.\n const base = source.kind === 'from'\n ? new URLSearchParams({ from: source.path })\n : new URLSearchParams({ name: source.name })\n if (options.password !== undefined && options.password.length > 0)\n base.set('password', options.password)\n if (scope.kind === 'include')\n base.set('include', scope.ids.join(','))\n if (options.exclude !== undefined)\n base.set('exclude', options.exclude.join(','))\n return base\n}\n\ntype BackupAction = 'list' | 'create' | 'restore'\ntype BackupFlag = 'target' | 'from' | 'password' | 'include' | 'exclude' | 'all' | 'confirm' | 'json'\n\n/** What each action reads. Anything else given is refused, never parsed and dropped. */\nconst HONOURED: Record<BackupAction, ReadonlySet<BackupFlag>> = {\n list: new Set(['json']),\n create: new Set(['password', 'include', 'exclude', 'all', 'confirm', 'json']),\n restore: new Set(['target', 'from', 'password', 'include', 'exclude', 'all', 'confirm', 'json']),\n}\n\n/**\n * A flag the action cannot honour is refused, not ignored: `backup list --all --include x` listed\n * every archive, and `backup create foo --all` dropped `foo` without a word.\n */\nexport function unhonouredBackupFlag(action: BackupAction, given: Partial<Record<BackupFlag, unknown>>): string | null {\n for (const flag of Object.keys(given) as BackupFlag[]) {\n if (given[flag] === undefined || HONOURED[action].has(flag))\n continue\n if (flag === 'target')\n return `\\`backup ${action}\\` takes no archive name (\"${String(given.target)}\") — only restore reads one`\n return `--${flag} does nothing for \\`backup ${action}\\` — drop it`\n }\n return null\n}\n\nfunction refuseUnhonouredFlags(action: BackupAction, args: Partial<Record<BackupFlag, unknown>>): void {\n const given: Partial<Record<BackupFlag, unknown>> = {}\n for (const flag of ['target', 'from', 'password', 'include', 'exclude', 'all', 'confirm', 'json'] as const) {\n const value = args[flag]\n if (value !== undefined && value !== '')\n given[flag] = value\n }\n const problem = unhonouredBackupFlag(action, given)\n if (problem !== null)\n fail(problem)\n}\n\nexport const backupCommand = defineCommand({\n meta: { name: 'backup' },\n args: {\n // Two positionals: `backup restore <name>`. citty reads them by name, so the first is the\n // action and the second the archive — the order on the command line is the order here.\n action: { type: 'positional', description: 'list (default) | create | restore', required: false },\n target: { type: 'positional', description: 'the archive name, for restore', required: false },\n from: { type: 'string', description: 'restore from this archive file anywhere on the machine, instead of a name in the backups directory' },\n password: { type: 'string', description: 'encrypt the archive, or unlock it on restore' },\n include: { type: 'string', description: 'comma-separated item ids to act on' },\n exclude: { type: 'string', description: 'comma-separated item ids to leave out, applied after --include' },\n all: { type: 'boolean', description: 'act on everything, rather than naming ids' },\n confirm: { type: 'boolean', description: 'apply without asking (a restore writes over live data)' },\n json: { type: 'boolean', description: 'print the plan or the result as JSON' },\n },\n async run({ args }) {\n try {\n const action = args.action === undefined || args.action.length === 0 ? 'list' : args.action\n if (action !== 'list' && action !== 'create' && action !== 'restore')\n fail(`unknown action \"${action}\" — use list, create or restore`)\n refuseUnhonouredFlags(action, args)\n // Validated up front, before any panel lookup: a bad flag combination is refused whether or\n // not anything is running, which is also what makes it testable without a panel.\n const parsed = action === 'create' || action === 'restore' ? parseScope(args.all === true, args.include) : null\n const exclude = action === 'create' || action === 'restore' ? parseExclude(args.exclude) : undefined\n if (action === 'list') {\n await runBackupList(args.json === true)\n }\n else if (action === 'create') {\n const scope = parsed ?? await refuseWithoutScope('create', '')\n await runBackupCreate({\n password: args.password,\n scope,\n exclude,\n confirm: args.confirm === true,\n json: args.json === true,\n })\n }\n else {\n const from = args.from !== undefined && args.from.length > 0 ? args.from : undefined\n const name = args.target !== undefined && args.target.length > 0 ? args.target : undefined\n // Refused before anything is looked up, like every other flag combination here: on the one\n // command that overwrites live data, choosing one of two named archives is a guess.\n if (from !== undefined && name !== undefined)\n fail('pass an archive name or --from <path>, not both — they name two different archives')\n if (from === undefined && name === undefined)\n fail('restore needs an archive — a name (`backup list` shows them), or --from <path> for a file anywhere on this machine')\n // The refusal that lists the ids an archive holds needs the archive, so it is named the way\n // this run names it: a path is read, a name is resolved against the backups directory.\n const suffix = from !== undefined\n ? `?from=${encodeURIComponent(resolveUserPath(from))}`\n : `?name=${encodeURIComponent(name!)}`\n // A path is a *file* question before it is a scope question: with no `--all`/`--include`,\n // `restore --from /media/usb` used to answer \"name what to act on\" to someone who had\n // already named their archive, hiding the real problem (a directory, a typo). Check the\n // path first, so the sentence names the thing that is actually wrong.\n // A *file*, not merely something that exists: a directory is the case this is for, and\n // `existsSync` alone says yes to it.\n if (from !== undefined && parsed === null && !(fs.existsSync(resolveUserPath(from)) && fs.statSync(resolveUserPath(from)).isFile()))\n fail(`no file at ${resolveUserPath(from)} — \\`--from\\` takes the path to an archive on this machine`)\n const scope = parsed ?? await refuseWithoutScope('restore', suffix)\n await runBackupRestore({\n ...(name === undefined ? {} : { name }),\n ...(from === undefined ? {} : { from }),\n password: args.password,\n scope,\n exclude,\n confirm: args.confirm === true,\n json: args.json === true,\n })\n }\n }\n catch (error) {\n fail(errorMessage(error))\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAS,aAAa,UAAmE;CACvF,OAAO,SAAS,IAAI,CAAC,CAAC,KAAI,eAAc;EAAE,IAAI,UAAU;EAAI,OAAO,UAAU;CAAM,EAAE;AACvF;;;;;;;;AASA,SAAS,gBAAgB,OAAe,KAAiE;CACvG,MAAM,UAA4D,CAAC;CACnE,KAAK,MAAM,eAAe,KAAK;EAC7B,MAAM,WAAW,KAAK,KAAK,OAAO,aAAa,QAAQ;EACvD,IAAI;EACJ,IAAI;GACF,QAAQ,GAAG,YAAY,QAAQ;EACjC,QACM;GACJ;EACF;EACA,KAAK,MAAM,QAAQ,OAAO;GAExB,IAAI,CAAC,KAAK,SAAS,OAAO,KAAK,KAAK,SAAS,YAAY,KAAK,KAAK,SAAS,MAAM,GAChF;GACF,MAAM,WAAW,KAAK,QAAQ,wBAAwB,EAAE;GACxD,IAAI,SAAS,WAAW,GACtB;GACF,MAAM,QAAQ,eAAe,KAAK,KAAK,UAAU,IAAI,CAAC;GACtD,IAAI,UAAU,MACZ;GAEF,IAAI,KAAK,IAAI,IAAI,MAAM,eAAe,KACpC,QAAQ,KAAK;IAAE;IAAa;GAAS,CAAC;EAC1C;CACF;CACA,OAAO;AACT;;;;;;;;;AAkBA,SAAgB,oBAAoB,UAAqD,CAAC,GAAkB;CAC1G,MAAMA,UAAQ,QAAQ,SAASC;CAC/B,MAAM,eAAe,QAAQ,gBAAgBC;CAC7C,MAAM,eAAe,KAAK,KAAKF,SAAO,KAAK,SAASG,cAAqB,CAAC;CAI1E,MAAM,WAAW,IAAI,oBAAoB,YAAY;CACrD,SAAS,KAAK,EAAE,OAAO,MAAM,CAAC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KAAK,OAAO,SAAS,IAAI,KAAK,SAAS,KAAA;IAGjF,IAAI,SAAS,KAAA,KAAa,SAAS,KAAA,GACjC,KAAK,oFAAoF;IAC3F,IAAI,SAAS,KAAA,KAAa,SAAS,KAAA,GACjC,KAAK,oHAAoH;IAG3H,MAAM,SAAS,SAAS,KAAA,IACpB,SAAS,mBAAmB,gBAAgB,IAAI,CAAC,MACjD,SAAS,mBAAmB,IAAK;IAOrC,IAAI,SAAS,KAAA,KAAa,WAAW,QAAQ,EAAE,GAAG,WAAW,gBAAgB,IAAI,CAAC,KAAK,GAAG,SAAS,gBAAgB,IAAI,CAAC,CAAC,CAAC,OAAO,IAC/H,KAAK,cAAc,gBAAgB,IAAI,EAAE,2DAA2D;IACtG,MAAM,QAAQ,UAAU,MAAM,mBAAmB,WAAW,MAAM;IAClE,MAAM,iBAAiB;KACrB,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK;KACrC,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK;KACrC,UAAU,KAAK;KACf;KACA;KACA,SAAS,KAAK,YAAY;KAC1B,MAAM,KAAK,SAAS;IACtB,CAAC;GACH;EACF,SACO,OAAO;GACZ,KAAK,aAAa,KAAK,CAAC;EAC1B;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"backup-DeAJ3pbO.js","names":["hhDir","defaultHhDir","defaultGlobalSettingsPath","defaultWorkspacesPath","Service","defaultGlobalSecretsPath","defaultTlsDir"],"sources":["../../src/cli/backup-offline.ts","../../src/cli/backup.ts"],"sourcesContent":["import type { BackupService } from '#src/services/backups'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { GlobalSettingsStore } from '#src/config/settings'\nimport { WorkspaceStore } from '#src/config/store'\nimport { WorkspaceRegistry } from '#src/config/workspaces'\nimport {\n globalSecretsPath as defaultGlobalSecretsPath,\n globalSettingsPath as defaultGlobalSettingsPath,\n hhDir as defaultHhDir,\n tlsDir as defaultTlsDir,\n workspacesPath as defaultWorkspacesPath,\n ensureStateDir,\n} from '#src/helpers/paths'\nimport { entryStatePath, readEntryState, writeEntryState } from '#src/providers/entry-state'\nimport { readNannyState } from '#src/providers/nanny'\nimport { buildBackupSources, BackupService as Service } from '#src/services/backups'\n\n/**\n * A backup service for a host whose panel is **not running**.\n *\n * `backup` used to need the daemon because the service is built inside it, so backing up or\n * restoring meant leaving the panel up — the opposite of what someone migrating a machine wants.\n * Nothing in the service needs the daemon: every source is a file, and the one live fact it wants\n * (which entries are running) is on disk as the nanny state each entry writes.\n *\n * This builds the same sources the panel does, through the same `buildBackupSources`, so an offline\n * archive cannot differ from an online one. `runningServers` is answered from `.state/*.json` rather\n * than from supervisor views: a *persistent* entry keeps running when the panel stops, so \"no panel\"\n * does not mean \"nothing is running\", and the restore warning has to keep telling the truth.\n */\n\n/** The workspace ids this host knows, from the registry on disk. */\nfunction workspaceIds(registry: WorkspaceRegistry): Array<{ id: string, label: string }> {\n return registry.all().map(workspace => ({ id: workspace.id, label: workspace.label }))\n}\n\n/**\n * Entries whose nanny is alive right now, read from the state files they rewrite.\n *\n * Every path comes from `hhDir`, never from the module-level helpers: those resolve from this\n * process's own `HHOSTED_HOME`, so a caller passing `--home` elsewhere would read a different host's\n * state — which is exactly how a test came to depend on the developer's real `~/.home-hosted`.\n */\nfunction runningFromDisk(hhDir: string, ids: string[]): Array<{ workspaceId: string, serverId: string }> {\n const running: Array<{ workspaceId: string, serverId: string }> = []\n for (const workspaceId of ids) {\n const stateDir = path.join(hhDir, workspaceId, '.state')\n let names: string[]\n try {\n names = fs.readdirSync(stateDir)\n }\n catch {\n continue\n }\n for (const name of names) {\n // `<id>.json` is a persistent entry's nanny state; `<id>.run.json` is a detached child.\n if (!name.endsWith('.json') || name.endsWith('.spec.json') || name.endsWith('.tmp'))\n continue\n const serverId = name.replace(/\\.run\\.json$|\\.json$/, '')\n if (serverId.length === 0)\n continue\n const state = readNannyState(path.join(stateDir, name))\n if (state === null)\n continue\n // The heartbeat is the panel's own liveness rule, so this agrees with what the UI would say.\n if (Date.now() - state.heartbeatAt <= 30_000)\n running.push({ workspaceId, serverId })\n }\n }\n return running\n}\n\nexport interface OfflineBackup {\n service: BackupService\n /** The workspaces this host declares, for a refusal that lists real ids. */\n workspaceIds: string[]\n /** Entries whose process is alive right now, read from the state files they rewrite. */\n runningNow: () => Array<{ workspaceId: string, serverId: string }>\n}\n\n/**\n * Build the service against this host's files.\n *\n * `ensureWorkspace` and `onRestored` are the two panel hooks, and both are deliberately absent: with\n * no daemon there is nothing to reload, and a restore that brings a workspace this host lacks leaves\n * it on disk for the next `up` to pick up. The registry is written by the service itself, which is\n * what makes that work.\n */\nexport function createOfflineBackup(options: { hhDir?: string, settingsPath?: string } = {}): OfflineBackup {\n const hhDir = options.hhDir ?? defaultHhDir\n const settingsPath = options.settingsPath ?? defaultGlobalSettingsPath\n const registryPath = path.join(hhDir, path.basename(defaultWorkspacesPath))\n\n // Read-only: looking at a fresh home (`backup list`, a plan) must not seed its config files. The\n // writes a restore makes go through the service, and the registry writes itself on `create`.\n const settings = new GlobalSettingsStore(settingsPath)\n settings.load({ write: false })\n const registry = new WorkspaceRegistry(registryPath)\n registry.load({ write: false })\n\n const workspaces = workspaceIds(registry)\n const ids = workspaces.map(workspace => workspace.id)\n\n // Each workspace's servers are read from its config, which is the only thing the source builder\n // needs beyond the id — no supervisor, no runtime. The paths are the ones the panel's own stores\n // read, so a stopped panel cannot archive a different file than a running one.\n const loaded = workspaces.map((workspace) => {\n const dir = path.join(hhDir, workspace.id)\n const settingsPath = path.join(dir, 'settings.json')\n const serversPath = path.join(dir, 'servers.config.json')\n const secretsPath = path.join(dir, '.secrets.json')\n const store = new WorkspaceStore(workspace.id, settingsPath, serversPath)\n store.load({ write: false })\n return { id: workspace.id, label: workspace.label, settingsPath, serversPath, secretsPath, servers: store.servers }\n })\n\n const service = new Service({\n dataRoot: hhDir,\n getConfig: () => settings.backups,\n /**\n * Register a workspace the archive brought.\n *\n * A panel-only hook in the running case, because the panel creates the runtime itself. With no\n * panel there is nobody to do it, so the registry is written here — otherwise a restored\n * workspace's files land on disk unreachable, and the next `up` never looks at them.\n */\n /**\n * Record the staged dump so the entry's next `up` loads it.\n *\n * Nothing is running to hold it in memory, so this is the only path that matters offline: the\n * panel is started afterwards, reads the entry state, and runs the hook.\n */\n onLoadPending: (workspaceId, serverId, dumpDir) => {\n // `entryStatePath` is the one spelling of this file. Hand-building `<id>.json` wrote a\n // different name than the supervisor reads (`<id>.run.json`), so the staged load was silently\n // invisible — the same class of bug as the schema rejection just above.\n const dir = path.join(hhDir, workspaceId, '.state')\n ensureStateDir(dir)\n const statePath = entryStatePath(dir, serverId)\n // Through `readEntryState`/`writeEntryState`, not hand-rolled JSON: the schema requires\n // `restarts` and `bootstrapDone`, and a file missing them is silently rejected on read — which\n // is how the staged load became invisible to the panel that was supposed to run it.\n const persisted = readEntryState(statePath)\n writeEntryState(statePath, {\n // No `bootstrapDone` default of `true`: that told the entry its `runOnce` bootstrap had\n // already run, so a restored blank host skipped its install/migrate step entirely.\n ...(persisted ?? { restarts: 0, bootstrapDone: false }),\n pendingLoad: dumpDir,\n })\n },\n ensureWorkspace: (input) => {\n if (registry.has(input.id))\n return\n // `create` writes the registry file itself; there is no separate save.\n registry.create(input)\n },\n getSources: () => buildBackupSources({\n globalSettingsPath: settings.path,\n globalSecretsPath: path.join(hhDir, path.basename(defaultGlobalSecretsPath)),\n tlsDir: path.join(hhDir, path.basename(defaultTlsDir)),\n registryPath,\n includePaths: settings.backups.includePaths,\n runningServers: () => runningFromDisk(hhDir, ids),\n workspaces: loaded,\n }),\n })\n\n return { service, workspaceIds: ids, runningNow: () => runningFromDisk(hhDir, ids) }\n}\n","import type { requestControl, Runtime } from '#src/helpers/daemon'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { defineCommand } from 'citty'\nimport { createOfflineBackup } from '#src/cli/backup-offline'\nimport { bold, dim, fail, green, invocation, paint, prompt } from '#src/cli/io'\nimport { resolveUserPath } from '#src/helpers/paths'\nimport { unknownBackupIds } from '#src/shared/backup-scope'\nimport { errorMessage } from '#src/shared/error-message'\n\n/**\n * `backup` — take an archive, list them, or restore one, without a browser.\n *\n * The archive is written by the panel, never by this command: it drives the running panel over the\n * same local token `down` and `start` use, so the allowlist, the manifest shape and the retention\n * rules stay in one implementation.\n *\n * `create` and `restore` both **plan first**. Nothing is written unless `--confirm` is given or the\n * person answers yes at a prompt — and a session that cannot be asked is not treated as consent, so\n * it prints the plan and says how to apply it. `--json` prints the same plan as JSON, for a script\n * or an agent that wants to read it rather than apply it.\n */\n\ninterface BackupFileView {\n name: string\n sizeBytes: number\n createdAt: number | null\n /** Only the panel's view carries it; the service's own list does not. */\n automatic?: boolean\n}\n\ninterface CreatedBody {\n file?: { name: string, sizeBytes: number }\n warnings?: string[]\n}\n\n/** One thing a backup would capture, or a restore would write. */\ninterface PlanHook {\n serverId: string\n workspaceId: string\n action: 'dump' | 'load'\n ok: boolean\n output?: string\n}\n\ninterface PlanItem {\n id: string\n kind?: string\n label?: string\n note?: string | null\n /** The plan lists everything; this says whether the request selected it. */\n selected?: boolean\n items?: Array<{ id: string, label?: string, note?: string | null }>\n}\n\n/** One row of a plan: an id, and what the panel says about it. */\ninterface PlanRow {\n id: string\n note?: string | null\n}\n\n/**\n * What a restore plan says beyond its items.\n *\n * `error` is not a warning: the service fills it when it refused to write *anything* — a file that\n * is not a zip, an archive from a newer config schema, a password that is missing or wrong — and the\n * plan is then empty. Filtering that plan to `items` and printing \"restored 0 items\" made every one\n * of those read as a tidy no-op, on the one command a person runs on a blank host with no other way\n * to check. `skipped` is the same list the UI draws, so a restore that dropped a piece says which.\n */\ninterface RestoreOutcome {\n items?: PlanItem[]\n skipped?: string[]\n /** Set by the service when nothing was applied. */\n error?: string\n /** Set instead of `error` when the archive needs a password that was absent or wrong. */\n needsPassword?: boolean\n hooks?: PlanHook[]\n restartRequired?: boolean\n createdWorkspaces?: string[]\n replacedUnderRunning?: Array<{ workspaceId: string, serverId: string, path: string }>\n}\n\n/**\n * Render plan ids as the tree they already are.\n *\n * Every id is a colon-separated path, so the hierarchy is in the data and the renderer's only job is\n * to show it: one row per prefix, each one level deeper than its parent. Depth is whatever the id\n * says, not a fixed number of columns — `workspace:default:secrets:telegram` sits three deep, and a\n * renderer that assumed two printed it beside its own parent.\n *\n * Both directions print through this, and so does the \"what could I act on\" list, so the three read\n * alike. A row's note is the panel's own wording, passed through untouched.\n */\nfunction printPlanTree(rows: PlanRow[], out: (text: string) => void = text => process.stdout.write(text)): void {\n const known = new Set(rows.map(row => row.id))\n // Every prefix of every id, so a parent that is not itself a row still gets a line to hang under.\n const nodes = new Map<string, { note: string | null, children: Set<string> }>()\n const ensure = (id: string): { note: string | null, children: Set<string> } => {\n const existing = nodes.get(id)\n if (existing !== undefined)\n return existing\n const created = { note: null, children: new Set<string>() }\n nodes.set(id, created)\n return created\n }\n for (const row of rows) {\n const segments = row.id.split(':')\n // `workspace:<id>:data:/a/b` carries a path in its last segment; it is a leaf, not a branch.\n for (let depth = 1; depth <= segments.length; depth++) {\n const id = segments.slice(0, depth).join(':')\n const node = ensure(id)\n if (depth > 1)\n ensure(segments.slice(0, depth - 1).join(':')).children.add(id)\n if (depth === segments.length && known.has(row.id))\n node.note = row.note ?? null\n }\n }\n\n const roots = [...nodes.keys()].filter(id => !id.includes(':'))\n const write = (id: string, depth: number): void => {\n const node = nodes.get(id)\n if (node === undefined)\n return\n const padding = ' '.repeat(depth)\n out(`${padding}${depth === 1 ? '' : '- '}${id}${node.note === null ? '' : ` ${dim(`(${node.note})`)}`}\\n`)\n for (const child of node.children)\n write(child, depth + 1)\n }\n for (const root of roots)\n write(root, 1)\n}\n\nfunction human(bytes: number): string {\n if (bytes < 1024)\n return `${bytes} B`\n if (bytes < 1024 * 1024)\n return `${Math.round(bytes / 1024)} KB`\n return `${(bytes / 1024 / 1024).toFixed(1)} MB`\n}\n\n/** The running panel's record, or a message saying what to do instead. */\nasync function livePanel(): Promise<(Runtime & { request: typeof requestControl }) | null> {\n const daemon = await import('#src/helpers/daemon')\n const runtime = daemon.readRuntime()\n if (runtime === null || !await daemon.runtimeIsAlive(runtime)) {\n if (runtime !== null && await daemon.runtimeIsGone(runtime))\n daemon.clearRuntime()\n return null\n }\n return Object.assign(runtime, { request: daemon.requestControl })\n}\n\n/**\n * Whether to talk to a panel or work on the files directly.\n *\n * Both paths run the same service, so the only question is who owns the state: a live panel is the\n * authority on what is running, and a stopped one has no opinion to disagree with.\n */\nasync function usesPanel(): Promise<boolean> {\n const daemon = await import('#src/helpers/daemon')\n const runtime = daemon.readRuntime()\n if (runtime === null || !await daemon.runtimeIsAlive(runtime))\n return false\n return (await daemon.probeRuntime(runtime)).reachable\n}\n\n/** Exit on a non-200 control answer with the panel's own message, or the status. */\nfunction failWithAnswer(answer: { status: number, body: unknown }): never {\n const body = answer.body as { message?: string } | null\n if (body?.message !== undefined)\n fail(body.message)\n fail(`the panel answered ${answer.status}`)\n}\n\n/**\n * What a `create`/`restore` should act on: `'all'`, or an explicit list of ids.\n *\n * There is no \"neither flag\" case. Reading it as \"everything\" made the destructive path the default —\n * `backup create --confirm` would archive the whole machine, and a restore would write the whole\n * archive, without anyone naming what they meant. A scope is now required, so silence is refused\n * rather than guessed.\n */\ntype Scope = { kind: 'all' } | { kind: 'include', ids: string[] }\n\n/** Where a restore reads its archive from: a name in the backups directory, or a path. */\ntype RestoreSource = { kind: 'name', name: string } | { kind: 'from', path: string }\n\n/**\n * The flag combination, as far as it can be judged without asking the panel.\n *\n * `null` means \"neither flag\", which only the caller can resolve — it lists the available ids, and\n * that needs a panel. Every other case is decided here, before any lookup, so a typo is refused\n * whether or not anything is running.\n */\nfunction parseScope(all: boolean, raw: string | undefined): Scope | null {\n if (all && raw !== undefined)\n fail('--include and --all are exclusive — pass one or the other')\n if (all)\n return { kind: 'all' }\n if (raw === undefined)\n return null\n const ids = raw.split(',').map(part => part.trim()).filter(part => part.length > 0)\n if (ids.length === 0)\n fail('--include is empty — name the ids to act on, or pass --all for everything')\n return { kind: 'include', ids }\n}\n\n/**\n * The plan rows a scope selects, and an exclusion drops.\n *\n * `kind` is deliberately not part of this: it is the panel's label for a row, not an id, and every id\n * the plan prints is already prefixed with it (`global:settings`, `workspace:default:servers`).\n */\n/** Flatten a nested plan into the rows the tree renders. */\nfunction flattenRows(rows: PlanItem[]): PlanRow[] {\n return rows.flatMap(row => [\n { id: row.id, note: row.note ?? null },\n ...(row.items ?? []).map(leaf => ({ id: leaf.id, note: leaf.note ?? null })),\n ])\n}\n\nfunction filterEntries<T extends { id: string, items?: Array<{ id: string }> }>(entries: T[], scope: Scope, exclude: string[] | undefined): T[] {\n const unwanted = exclude ?? []\n const excluded = (id: string): boolean => unwanted.some(entry => id === entry || id.startsWith(`${entry}:`))\n // Upwards too: naming a leaf (`workspace:default:servers`) has to keep its parent entry in the\n // plan, or the leaf's own file is captured and the plan says \"nothing matched\".\n const named = (id: string): boolean => scope.kind === 'all'\n || scope.ids.some(entry => id === entry || id.startsWith(`${entry}:`) || entry.startsWith(`${id}:`))\n // The leaves are filtered too: a plan that lists `workspace:default:servers` while the archive\n // leaves it out is a plan that describes a different backup from the one it is planning.\n return entries\n .filter(entry => named(entry.id) && !excluded(entry.id))\n .map(entry => (entry.items === undefined\n ? entry\n : { ...entry, items: entry.items.filter(leaf => named(leaf.id) && !excluded(leaf.id)) }))\n}\n\n/**\n * Refuse an id the plan does not have.\n *\n * An id that matches nothing is silently ignored by the service, which is right for an archive that\n * simply does not carry something — and wrong for a typo: `--exclude global:secret` excludes nothing\n * and says nothing, so the archive carries the credentials the person believed they had dropped.\n *\n * `action` decides the hint, because the two directions list their ids from different places: a\n * create plan lists what this host declares, a restore plan lists what the archive holds — and the\n * command that prints that one is a restore, not a create.\n */\nfunction assertKnown(ids: string[] | undefined, entries: PlanItem[], flag: string, action: 'create' | 'restore'): void {\n if (ids === undefined)\n return\n // The same rule the settings page applies to a schedule scope, so a typo is refused wherever it\n // is typed rather than only in the dialog.\n const unknown = unknownBackupIds(ids, entries)\n if (unknown.length > 0) {\n const hint = action === 'create'\n ? `\\`backup create\\` with no flags lists the ids`\n : `\\`backup restore <name>\\` with no --include/--exclude lists the ids the archive holds`\n fail(`${flag} names ${unknown.map(id => `\"${id}\"`).join(', ')}, which ${unknown.length === 1 ? 'is' : 'are'} not in this plan — ${hint}`)\n }\n}\n\n/** `--exclude` parsed. An empty value is a mistake, not \"exclude nothing\". */\nfunction parseExclude(raw: string | undefined): string[] | undefined {\n if (raw === undefined)\n return undefined\n const ids = raw.split(',').map(part => part.trim()).filter(part => part.length > 0)\n if (ids.length === 0)\n fail('--exclude is empty — name the ids to leave out, or drop the flag')\n return ids\n}\n\n/**\n * Neither flag given. Refused outright — the ids are a *bonus*, not the reason.\n *\n * The refusal must not depend on a panel being up: a mistyped command deserves the flag error, not\n * \"home-hosted is not running\". So the list is best-effort, and a failure to produce it is silent.\n */\nasync function refuseWithoutScope(action: 'create' | 'restore', suffix: string): Promise<never> {\n const rows = await availableRows(action, suffix).catch(() => [] as PlanItem[])\n if (rows.length === 0)\n fail('name what to act on — pass --include <ids> or --all')\n // The same tree the plan uses, so all three outputs read alike: a flat list here was the one place\n // the scopes and the nesting disappeared.\n //\n // All of it on stderr, tree included. A `--json` caller reads stdout, and the tree landed there\n // while the sentence explaining it did not: measured `backup create --json` writing ` global` /\n // ` - global:settings` to stdout and `error name what to act on` to stderr, so a script got\n // neither a document nor a reason, and a terminal with stderr filtered got ids with no sentence.\n process.stderr.write(`${paint('31', 'error')} name what to act on — pass --include <ids> or --all\\n\\n`)\n process.stderr.write('available (or narrow it):\\n')\n printPlanTree(flattenRows(rows), text => process.stderr.write(text))\n process.stderr.write('\\n--exclude <ids> leaves those out: --all --exclude global:secrets\\n')\n process.exit(1)\n}\n\n/**\n * The ids an offline run could act on, read from the state files.\n *\n * The refusal has to name real ids whether or not a panel is up — an empty list is the one answer\n * worse than no list, because it reads as \"there is nothing to back up\".\n */\nasync function availableRowsFromDisk(action: 'create' | 'restore', suffix: string): Promise<PlanItem[]> {\n try {\n const { service } = createOfflineBackup()\n await service.warm()\n if (action === 'create')\n return service.selection().entries as unknown as PlanItem[]\n // A restore lists what the **archive** holds, not what this host declares. Reading the create\n // view here named every slot on the machine — including ones the archive never carried — and\n // marked them \"(not set)\", which is not a thing a restore can be missing.\n // The same either/or the restore itself takes: a name resolved against the backups directory,\n // or a path read where it is.\n const query = new URLSearchParams(suffix.startsWith('?') ? suffix.slice(1) : suffix)\n const from = query.get('from')\n const name = query.get('name')\n const archive = from !== null && from.length > 0\n ? (fs.existsSync(from) && fs.statSync(from).isFile() ? from : null)\n : (name === null || name.length === 0 ? null : service.resolve(name))\n if (archive === null)\n return []\n const plan = await service.restore(archive, { confirm: false })\n return (plan.items ?? []).filter(item => item.selected !== false)\n }\n catch {\n return []\n }\n}\n\n/**\n * The ids this action could be scoped to.\n *\n * `create` asks what the entries declare; `restore` asks what the archive holds. Both come from the\n * panel, so the list in a refusal is the real one rather than a hardcoded guess. A panel that cannot\n * be reached yields no ids — the refusal still fires, it just cannot enumerate.\n */\nasync function availableRows(action: 'create' | 'restore', suffix: string): Promise<PlanItem[]> {\n // Read the record directly rather than through `livePanel()`: a hint must not `fail()` the process\n // when the panel is down, and the caller turns an empty list into \"nothing to list\".\n const daemon = await import('#src/helpers/daemon')\n const runtime = daemon.readRuntime()\n if (runtime === null || !await daemon.runtimeIsAlive(runtime))\n return await availableRowsFromDisk(action, suffix)\n const path = action === 'create' ? '/_hh/backups' : '/_hh/backups/restore'\n const answer = await daemon.requestControl(runtime, `${path}${suffix}`, 120000)\n if (answer === null || answer.status !== 200)\n return []\n const body = answer.body as { entries?: PlanItem[], items?: PlanItem[] } | null\n // The rows themselves, not just their ids: a refusal that lists what could be acted on should say\n // the same things the plan does, `(not set)` included.\n return action === 'create' ? (body?.entries ?? []) : (body?.items ?? [])\n}\n\n/** `?a=b`, or `''`. */\nfunction suffixOf(query: URLSearchParams): string {\n return query.size === 0 ? '' : `?${query.toString()}`\n}\n\n/** Appends one query parameter, keeping the `?`/`&` right. */\nfunction withParam(suffix: string, key: string, value: string): string {\n return `${suffix}${suffix === '' ? '?' : '&'}${key}=${encodeURIComponent(value)}`\n}\n\n/**\n * Ask before writing.\n *\n * A session that cannot be asked is refused, exit 1, after the plan: not a silent write, and not a\n * success. Exiting 0 here meant a cron job's `backup create --all` printed a plan every night and\n * never took a backup, with nothing in its exit status to say so. (`--json` without `--confirm` is\n * the explicit \"show me the plan\" request and still exits 0; it never reaches this.)\n */\nasync function consent(question: string): Promise<boolean> {\n if (process.stdin.isTTY !== true)\n fail('not applied — this session cannot ask for consent; re-run with --confirm to apply (or --json to only read the plan)')\n const answer = await prompt(`${question} [y/N] `)\n if (/^yes$|^y$/i.test(answer.trim())) {\n process.stdout.write('\\n')\n return true\n }\n process.stdout.write('cancelled — nothing was written\\n')\n return false\n}\n\n/**\n * Run against the panel when one is up, and against the files when it is not.\n *\n * Both run the same `BackupService`, so the archive cannot differ; only the authority on what is\n * running changes. A stopped panel is exactly when someone wants to back up or restore — the services\n * are down because they stopped them on purpose.\n */\nexport async function runBackupList(json: boolean): Promise<void> {\n if (await usesPanel()) {\n const runtime = await livePanel()\n if (runtime !== null) {\n const answer = await runtime.request(runtime, '/_hh/backups', 30000, 'GET')\n if (answer === null)\n fail(`the control panel is not answering on ${runtime.probeUrl}`)\n if (answer.status !== 200)\n failWithAnswer(answer)\n printList(answer.body as { files?: BackupFileView[], dir?: string } | null, json)\n return\n }\n }\n const { service } = createOfflineBackup()\n await service.warm()\n printList(service.selection(), json)\n}\n\nfunction printList(view: { files?: BackupFileView[], dir?: string } | null, json: boolean): void {\n const files = view?.files ?? []\n if (json) {\n process.stdout.write(`${JSON.stringify(view, null, 2)}\\n`)\n return\n }\n if (files.length === 0) {\n process.stdout.write(`no backups yet — \\`${invocation()} backup create --all\\` takes one\\n`)\n return\n }\n const noun = files.length === 1 ? 'archive' : 'archives'\n process.stdout.write(`${bold(String(files.length))} ${noun}${view?.dir === undefined ? '' : ` in ${dim(view.dir)}`}\\n`)\n for (const file of files) {\n const when = file.createdAt == null ? '' : new Date(file.createdAt).toISOString().replace('T', ' ').slice(0, 16)\n process.stdout.write(` ${file.name.padEnd(36)} ${human(file.sizeBytes).padStart(8)} ${dim(when)}${file.automatic ? dim(' auto') : ''}\\n`)\n }\n}\n\n/**\n * Name the entries still running, without blocking.\n *\n * A **persistent** entry keeps running while the panel is stopped, so \"panel off\" is not \"services\n * off\" — and its data being captured mid-write is worth knowing before it is relied on. Warned rather\n * than refused: the user may know, and the panel's own backup has always proceeded here.\n */\nfunction warnRunning(entries: Array<{ workspaceId?: string, serverId?: string, id?: string }>): void {\n if (entries.length === 0)\n return\n const named = entries.map(entry => entry.serverId ?? entry.id ?? '').filter(name => name.length > 0)\n const isOne = named.length === 1\n process.stdout.write(`${dim(`! ${named.length} entr${isOne ? 'y is' : 'ies are'} still running (${named.join(', ')}) — its data may be captured mid-write`)}\\n`)\n}\n\nexport async function runBackupCreate(options: { password?: string, scope: Scope, exclude?: string[], confirm: boolean, json: boolean }): Promise<void> {\n const scope = options.scope\n const online = await usesPanel()\n\n // The plan: what this archive would capture, from the same source either way.\n const entries = await (async (): Promise<PlanItem[]> => {\n if (online) {\n const runtime = await livePanel()\n if (runtime !== null) {\n const answer = await runtime.request(runtime, '/_hh/backups', 120000)\n if (answer === null)\n fail(`the control panel is not answering on ${runtime.probeUrl}`)\n if (answer.status !== 200)\n failWithAnswer(answer)\n return (answer.body as { entries?: PlanItem[] } | null)?.entries ?? []\n }\n }\n const { service } = createOfflineBackup()\n await service.warm()\n return service.selection().entries as unknown as PlanItem[]\n })()\n\n // Checked against the plan the user is looking at, so a typo is refused instead of quietly\n // excluding nothing.\n assertKnown(options.exclude, entries, '--exclude', 'create')\n assertKnown(scope.kind === 'include' ? scope.ids : undefined, entries, '--include', 'create')\n const wanted = filterEntries(entries, scope, options.exclude)\n\n if (!options.confirm) {\n if (options.json) {\n process.stdout.write(`${JSON.stringify({ action: 'create', apply: false, entries: wanted }, null, 2)}\\n`)\n return\n }\n process.stdout.write(`${bold('Plan')} — what a backup would capture; nothing has been written yet\\n`)\n printPlanTree(flattenRows(wanted))\n if (wanted.length === 0) {\n process.stdout.write(' (nothing matched — check --include, or what the entries declare)\\n')\n return\n }\n // From the state files either way: the panel's backup view has no per-entry running flag, and a\n // persistent entry's nanny rewrites its file whether or not the panel is up.\n warnRunning(createOfflineBackup().runningNow())\n if (!await consent('Take this backup?'))\n return\n }\n\n const include = scope.kind === 'include' ? scope.ids : undefined\n const exclude = options.exclude\n const created = await (async (): Promise<CreatedBody | null> => {\n if (online) {\n const runtime = await livePanel()\n if (runtime !== null) {\n const query = new URLSearchParams()\n if (options.password !== undefined && options.password.length > 0)\n query.set('password', options.password)\n if (include !== undefined)\n query.set('include', include.join(','))\n if (exclude !== undefined)\n query.set('exclude', exclude.join(','))\n const answer = await runtime.request(runtime, `/_hh/backups${withParam(suffixOf(query), 'confirm', 'true')}`, 600000)\n if (answer === null)\n fail(`the control panel is not answering on ${runtime.probeUrl}`)\n if (answer.status !== 200)\n failWithAnswer(answer)\n return answer.body as CreatedBody | null\n }\n }\n const { service } = createOfflineBackup()\n await service.warm()\n const result = await service.create({ password: options.password, include, exclude })\n if (!result.ok)\n fail(result.error ?? 'the backup failed')\n return { file: result.file, ...(result.warnings === undefined ? {} : { warnings: result.warnings }) }\n })()\n\n const file = created?.file\n if (file === undefined)\n fail('the backup reported success but named no archive')\n const warnings = created?.warnings ?? []\n if (options.json) {\n process.stdout.write(`${JSON.stringify({ action: 'create', apply: true, file, ...(warnings.length === 0 ? {} : { warnings }) }, null, 2)}\\n`)\n return\n }\n process.stdout.write(`${green('backup created')} ${file.name} ${dim(`(${human(file.sizeBytes)})`)}\\n`)\n for (const warning of warnings)\n process.stderr.write(`warning: ${warning}\\n`)\n}\n\n/**\n * Why a restore plan is not something to apply, or `null`.\n *\n * The service answers a plan for every archive, including ones it refuses to read: `error` carries\n * the refusal and `items` is empty. A caller that reads only `items` sees a tidy empty restore — and\n * on a blank host, `restored 0 items` printed with exit 0 is the worst possible answer, because\n * nothing distinguishes \"this archive was empty\" from \"this archive could not be opened\".\n *\n * `needsPassword` is its own case: it is the one refusal the person can fix from the same command.\n */\nfunction planRefusal(plan: RestoreOutcome | null): string | null {\n if (plan === null)\n return null\n if (plan.needsPassword === true) {\n const reason = plan.error ?? 'this backup is password-protected'\n return `${reason} — add \\`--password <text>\\` to unlock it`\n }\n if (plan.error !== undefined && plan.error.length > 0)\n return plan.error\n return null\n}\n\nexport async function runBackupRestore(options: { name?: string, from?: string, password?: string, scope: Scope, exclude?: string[], confirm: boolean, json: boolean }): Promise<void> {\n const scope = options.scope\n const online = await usesPanel()\n\n /**\n * What this restore reads from: an archive **name** in the backups directory, or a **path**.\n *\n * A name is an allowlist entry, which is why it is the default. `--from` is for the blank host\n * where the archive is on a USB stick: it names the file to read, not a directory to write in.\n * The two are refused together rather than one quietly winning — on the one command that\n * overwrites live data, a guess about which archive was meant is the wrong default.\n *\n * The path is resolved against *this* process's directory; the panel would resolve a relative\n * one against its own cwd, which is a different directory and so a different file.\n */\n const source: RestoreSource = options.from !== undefined\n ? { kind: 'from', path: resolveUserPath(options.from) }\n : { kind: 'name', name: options.name ?? '' }\n /** What to call it in the plan and the result: the file it read, name or path. */\n const label = source.kind === 'from' ? path.basename(source.path) : source.name\n\n // Checked here for both paths: when the panel is up *it* reads the file, so letting it answer\n // \"not a home-hosted backup\" for a path that simply is not there sends the person to inspect an\n // archive's contents instead of their typo.\n if (source.kind === 'from' && (!fs.existsSync(source.path) || !fs.statSync(source.path).isFile()))\n fail(`no file at ${source.path} — \\`--from\\` takes the path to an archive on this machine`)\n\n const service = online ? null : createOfflineBackup().service\n if (service !== null)\n await service.warm()\n\n // The plan is free and always shown: it is the only way to see what a restore would overwrite.\n const plan = await (async (): Promise<RestoreOutcome | null> => {\n if (service !== null) {\n // `--from` names a file, so there is no allowlist entry to resolve: the path is read, and\n // everything that decides *where* it may write still comes from the live config.\n if (source.kind === 'from')\n return await service.restore(source.path, { confirm: false, password: options.password, include: scope.kind === 'include' ? scope.ids : undefined, exclude: options.exclude })\n const archive = service.resolve(source.name)\n // The name is an *allowlist entry*, not a path: `resolve` refuses anything that is not a plain\n // archive name, so `backup restore /tmp/from-s3.zip` cannot be reached by naming the file.\n // Say both halves — which directory the name must be in, and that a path is not a name — and\n // point at `--from`, or the person on a blank host, holding the one archive, is told to run a\n // command that lists nothing and to try a name they have never seen.\n if (archive === null)\n fail(`no backup named \"${source.name}\" in ${service.directory} — a restore takes the archive's file name, not a path; pass --from <path> to read the file where it is, or copy it into that directory (\\`${invocation()} backup list\\` shows what is there)`)\n return await service.restore(archive, { confirm: false, password: options.password, include: scope.kind === 'include' ? scope.ids : undefined, exclude: options.exclude })\n }\n const runtime = await livePanel()\n if (runtime === null)\n fail(`the control panel is not answering — try again once it is up`)\n const base = restoreQuery(source, options, scope)\n const answer = await runtime.request(runtime, `/_hh/backups/restore${suffixOf(base)}`, 120000)\n if (answer === null)\n fail(`the control panel is not answering at ${runtime.probeUrl}`)\n if (answer.status !== 200)\n failWithAnswer(answer)\n return answer.body as RestoreOutcome | null\n })()\n\n // Refused before anything is printed as if it could be applied. A `--json` caller gets the plan\n // (with the reason in it) *and* a non-zero exit, so a script can branch on either.\n const refused = planRefusal(plan)\n if (refused !== null) {\n if (options.json)\n process.stdout.write(`${JSON.stringify({ action: 'restore', apply: false, name: label, error: refused }, null, 2)}\\n`)\n fail(refused)\n }\n\n // Every item the archive knows, with `selected` on each — `--include` narrows the selection, not\n // the list. Reading the list as the selection reported the whole archive either way.\n const items = (plan?.items ?? []).filter(item => item.selected !== false)\n // The same typo rule `create` applies, on this direction too: an id the archive does not carry is\n // a mistake, and `--exclude globalsecrets` excludes nothing while the archive still holds exactly\n // the credentials the person believed they had dropped.\n const archiveItems = plan?.items ?? []\n if (options.exclude !== undefined)\n assertKnown(options.exclude, archiveItems, '--exclude', 'restore')\n if (scope.kind === 'include')\n assertKnown(scope.ids, archiveItems, '--include', 'restore')\n\n if (options.json && !options.confirm) {\n process.stdout.write(`${JSON.stringify({ action: 'restore', apply: false, name: label, items, skipped: (plan?.skipped ?? []) }, null, 2)}\\n`)\n return\n }\n\n if (!options.json) {\n // With `--confirm` the same run goes on to apply, so the header must not claim nothing was\n // written — and the plan's skips are not reprinted below, where the applied result says them\n // again with the same words.\n process.stdout.write(options.confirm\n ? `${bold('Plan')} for ${label} — applying it now\\n`\n : `${bold('Plan')} for ${label} — nothing has been written yet\\n`)\n printPlanTree(items.map(item => ({ id: item.id, note: item.note ?? null })))\n if (!options.confirm) {\n for (const note of (plan?.skipped ?? []))\n process.stdout.write(` ${dim('!')} ${note}\\n`)\n }\n if (items.length === 0) {\n process.stdout.write(' (nothing to restore — check --include, or what this host declares)\\n')\n return\n }\n }\n\n if (!options.confirm && !await consent(`Restore these ${items.length} item(s) over this host?`))\n return\n\n // No lock here: `BackupService.restore` takes it on apply, so this path and the panel's both get\n // it from one place. A second guard here would be the third implementation of the same rule.\n {\n const outcome = await (async (): Promise<RestoreOutcome> => {\n if (service !== null) {\n // The plan above already proved this path (or name) reads, so it is reused rather than\n // resolved twice — and a file that vanished between the two is the service's refusal to\n // report, not a crash.\n const archive = source.kind === 'from' ? source.path : service.resolve(source.name)!\n const result = await service.restore(archive, { confirm: true, password: options.password, include: scope.kind === 'include' ? scope.ids : undefined, exclude: options.exclude })\n return { ...result, items: (result.items ?? []).filter(item => item.selected !== false) }\n }\n const runtime = await livePanel()\n if (runtime === null)\n fail('the control panel stopped answering — nothing further was written')\n const base = restoreQuery(source, options, scope)\n const answer = await runtime.request(runtime, `/_hh/backups/restore${withParam(suffixOf(base), 'confirm', 'true')}`, 600000)\n if (answer === null)\n fail(`the control panel is not answering at ${runtime.probeUrl}`)\n if (answer.status !== 200)\n failWithAnswer(answer)\n const result = answer.body as RestoreOutcome | null\n return {\n ...result,\n items: (result?.items ?? plan?.items ?? []).filter(item => item.selected !== false),\n ...(result?.hooks === undefined && plan?.hooks !== undefined ? { hooks: plan.hooks } : {}),\n }\n })()\n\n // The apply can refuse too, and it is the run that actually matters: a wrong password against an\n // encrypted archive reaches here, and a failure part-way names what already landed.\n const applyRefused = planRefusal(outcome)\n if (applyRefused !== null) {\n if (options.json)\n process.stdout.write(`${JSON.stringify({ action: 'restore', apply: true, name: label, error: applyRefused }, null, 2)}\\n`)\n fail(applyRefused)\n }\n\n const applied = (outcome.items ?? []).filter(item => item.selected !== false)\n const hooks = (outcome.hooks ?? []).filter(hook => hook.action === 'load')\n // The **apply's** skips, not the plan's: a dump staged for an entry with no `load` hook is only\n // discovered here, and reporting the plan's list dropped that sentence from both outputs. They are\n // the only thing that says a piece of an otherwise successful restore was left behind.\n const notes = outcome.skipped ?? []\n\n if (options.json) {\n process.stdout.write(`${JSON.stringify({\n action: 'restore',\n apply: true,\n name: label,\n items: applied,\n hooks,\n skipped: notes,\n ...(outcome.restartRequired === true ? { restartRequired: true } : {}),\n ...((outcome.createdWorkspaces ?? []).length === 0 ? {} : { createdWorkspaces: outcome.createdWorkspaces }),\n ...((outcome.replacedUnderRunning ?? []).length === 0 ? {} : { replacedUnderRunning: outcome.replacedUnderRunning }),\n }, null, 2)}\\n`)\n return\n }\n if (applied.length === 0)\n process.stdout.write(`${green('restored')} nothing — the archive carried no item this host can take\\n`)\n else\n process.stdout.write(`${green('restored')} ${applied.length} ${applied.length === 1 ? 'item' : 'items'} from ${label}\\n`)\n for (const hook of hooks)\n // \"staged\", not \"ran\": the hook runs on the entry's next start, and saying it already ran\n // would leave a person waiting for data that has not been loaded yet.\n process.stdout.write(` ${dim(`load ${hook.serverId}: ${hook.output ?? 'staged'}`)}\\n`)\n for (const note of notes)\n process.stdout.write(` ${dim('!')} ${note}\\n`)\n // The listener moved, so the panel that is up is not the one the archive described. Said here\n // because the CLI is where a restore from another host is run, and nothing else mentions it.\n if (outcome.restartRequired === true)\n process.stdout.write(` ${dim(`! the panel's listener changed — restart it so it binds where the archive says (\\`${invocation()} restart\\`)`)}\\n`)\n if ((outcome.createdWorkspaces ?? []).length > 0)\n process.stdout.write(` ${dim(`! created ${outcome.createdWorkspaces!.join(', ')}, which this host did not have`)}\\n`)\n if (service !== null)\n process.stdout.write(dim(`the panel is not running, so nothing was reloaded — the next \\`${invocation()} up\\` reads what was restored\\n`))\n }\n}\n\n/**\n * The restore query both the plan and the apply send.\n *\n * One builder, because the two requests must agree: a password or a selection on the plan and not on\n * the apply made the apply answer about different items than the person approved.\n */\nfunction restoreQuery(source: RestoreSource, options: { password?: string, exclude?: string[] }, scope: Scope): URLSearchParams {\n // `from` is read by the panel, so it travels in place of `name`, never as well — the same\n // either/or the CLI itself enforces on the flags.\n const base = source.kind === 'from'\n ? new URLSearchParams({ from: source.path })\n : new URLSearchParams({ name: source.name })\n if (options.password !== undefined && options.password.length > 0)\n base.set('password', options.password)\n if (scope.kind === 'include')\n base.set('include', scope.ids.join(','))\n if (options.exclude !== undefined)\n base.set('exclude', options.exclude.join(','))\n return base\n}\n\ntype BackupAction = 'list' | 'create' | 'restore'\ntype BackupFlag = 'target' | 'from' | 'password' | 'include' | 'exclude' | 'all' | 'confirm' | 'json'\n\n/** What each action reads. Anything else given is refused, never parsed and dropped. */\nconst HONOURED: Record<BackupAction, ReadonlySet<BackupFlag>> = {\n list: new Set(['json']),\n create: new Set(['password', 'include', 'exclude', 'all', 'confirm', 'json']),\n restore: new Set(['target', 'from', 'password', 'include', 'exclude', 'all', 'confirm', 'json']),\n}\n\n/**\n * A flag the action cannot honour is refused, not ignored: `backup list --all --include x` listed\n * every archive, and `backup create foo --all` dropped `foo` without a word.\n */\nexport function unhonouredBackupFlag(action: BackupAction, given: Partial<Record<BackupFlag, unknown>>): string | null {\n for (const flag of Object.keys(given) as BackupFlag[]) {\n if (given[flag] === undefined || HONOURED[action].has(flag))\n continue\n if (flag === 'target')\n return `\\`backup ${action}\\` takes no archive name (\"${String(given.target)}\") — only restore reads one`\n return `--${flag} does nothing for \\`backup ${action}\\` — drop it`\n }\n return null\n}\n\nfunction refuseUnhonouredFlags(action: BackupAction, args: Partial<Record<BackupFlag, unknown>>): void {\n const given: Partial<Record<BackupFlag, unknown>> = {}\n for (const flag of ['target', 'from', 'password', 'include', 'exclude', 'all', 'confirm', 'json'] as const) {\n const value = args[flag]\n if (value !== undefined && value !== '')\n given[flag] = value\n }\n const problem = unhonouredBackupFlag(action, given)\n if (problem !== null)\n fail(problem)\n}\n\nexport const backupCommand = defineCommand({\n meta: { name: 'backup' },\n args: {\n // Two positionals: `backup restore <name>`. citty reads them by name, so the first is the\n // action and the second the archive — the order on the command line is the order here.\n action: { type: 'positional', description: 'list (default) | create | restore', required: false },\n target: { type: 'positional', description: 'the archive name, for restore', required: false },\n from: { type: 'string', description: 'restore from this archive file anywhere on the machine, instead of a name in the backups directory' },\n password: { type: 'string', description: 'encrypt the archive, or unlock it on restore' },\n include: { type: 'string', description: 'comma-separated item ids to act on' },\n exclude: { type: 'string', description: 'comma-separated item ids to leave out, applied after --include' },\n all: { type: 'boolean', description: 'act on everything, rather than naming ids' },\n confirm: { type: 'boolean', description: 'apply without asking (a restore writes over live data)' },\n json: { type: 'boolean', description: 'print the plan or the result as JSON' },\n },\n async run({ args }) {\n try {\n const action = args.action === undefined || args.action.length === 0 ? 'list' : args.action\n if (action !== 'list' && action !== 'create' && action !== 'restore')\n fail(`unknown action \"${action}\" — use list, create or restore`)\n refuseUnhonouredFlags(action, args)\n // Validated up front, before any panel lookup: a bad flag combination is refused whether or\n // not anything is running, which is also what makes it testable without a panel.\n const parsed = action === 'create' || action === 'restore' ? parseScope(args.all === true, args.include) : null\n const exclude = action === 'create' || action === 'restore' ? parseExclude(args.exclude) : undefined\n if (action === 'list') {\n await runBackupList(args.json === true)\n }\n else if (action === 'create') {\n const scope = parsed ?? await refuseWithoutScope('create', '')\n await runBackupCreate({\n password: args.password,\n scope,\n exclude,\n confirm: args.confirm === true,\n json: args.json === true,\n })\n }\n else {\n const from = args.from !== undefined && args.from.length > 0 ? args.from : undefined\n const name = args.target !== undefined && args.target.length > 0 ? args.target : undefined\n // Refused before anything is looked up, like every other flag combination here: on the one\n // command that overwrites live data, choosing one of two named archives is a guess.\n if (from !== undefined && name !== undefined)\n fail('pass an archive name or --from <path>, not both — they name two different archives')\n if (from === undefined && name === undefined)\n fail('restore needs an archive — a name (`backup list` shows them), or --from <path> for a file anywhere on this machine')\n // The refusal that lists the ids an archive holds needs the archive, so it is named the way\n // this run names it: a path is read, a name is resolved against the backups directory.\n const suffix = from !== undefined\n ? `?from=${encodeURIComponent(resolveUserPath(from))}`\n : `?name=${encodeURIComponent(name!)}`\n // A path is a *file* question before it is a scope question: with no `--all`/`--include`,\n // `restore --from /media/usb` used to answer \"name what to act on\" to someone who had\n // already named their archive, hiding the real problem (a directory, a typo). Check the\n // path first, so the sentence names the thing that is actually wrong.\n // A *file*, not merely something that exists: a directory is the case this is for, and\n // `existsSync` alone says yes to it.\n if (from !== undefined && parsed === null && !(fs.existsSync(resolveUserPath(from)) && fs.statSync(resolveUserPath(from)).isFile()))\n fail(`no file at ${resolveUserPath(from)} — \\`--from\\` takes the path to an archive on this machine`)\n const scope = parsed ?? await refuseWithoutScope('restore', suffix)\n await runBackupRestore({\n ...(name === undefined ? {} : { name }),\n ...(from === undefined ? {} : { from }),\n password: args.password,\n scope,\n exclude,\n confirm: args.confirm === true,\n json: args.json === true,\n })\n }\n }\n catch (error) {\n fail(errorMessage(error))\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAS,aAAa,UAAmE;CACvF,OAAO,SAAS,IAAI,CAAC,CAAC,KAAI,eAAc;EAAE,IAAI,UAAU;EAAI,OAAO,UAAU;CAAM,EAAE;AACvF;;;;;;;;AASA,SAAS,gBAAgB,OAAe,KAAiE;CACvG,MAAM,UAA4D,CAAC;CACnE,KAAK,MAAM,eAAe,KAAK;EAC7B,MAAM,WAAW,KAAK,KAAK,OAAO,aAAa,QAAQ;EACvD,IA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AClE,MAAM,iBAAiB;KACrB,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK;KACrC,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK;KACrC,UAAU,KAAK;KACf;KACA;KACA,SAAS,KAAK,YAAY;KAC1B,MAAM,KAAK,SAAS;IACtB,CAAC;GACH;EACF,SACO,OAAO;GACZ,KAAK,aAAa,KAAK,CAAC;EAC1B;CACF;AACF,CAAC"}
@@ -9,8 +9,8 @@ import { F as notificationsSchema, S as entryStateSchema, Y as serverSchema, _ a
9
9
  import { a as mergeDefaults, c as serversFileSchema, l as workspaceSettingsSchema } from "./schema-B240VXcV.js";
10
10
  import { a as SEED_SERVERS_FILE, c as EMPTY_MERGE_KEYS, d as SERVER_MERGE_KEYS, f as applyPatch, l as NOTIFICATION_MERGE_KEYS, o as SEED_WORKSPACE_SETTINGS, r as assertSaveable, s as DDNS_MERGE_KEYS, t as ConfigError } from "./settings-xu-XTfWg.js";
11
11
  import { r as workspacesFileSchema } from "./workspaces-DYcfvKV_.js";
12
- import { C as resolveCwd } from "./nanny-BtWfy0QH.js";
13
- import { r as isProcessAlive } from "./port-B8WBTRMk.js";
12
+ import { C as resolveCwd } from "./nanny-COyCJXj9.js";
13
+ import { r as isProcessAlive } from "./port-k5VBw8t9.js";
14
14
  import { a as listZip, i as isZipArchive, n as extractZip, o as copyTree, r as isInvalidPassword, t as createZip } from "./archive-DP-XQR8X.js";
15
15
  import process from "node:process";
16
16
  import path from "node:path";
@@ -4688,4 +4688,4 @@ function readableWorkspaceSettings(text) {
4688
4688
  //#endregion
4689
4689
  export { normalizeHost as A, expandEnvList as C, ddnsProvider as D, resolveEnvFilePath as E, ddnsProviderInfos as O, targetProblem as S, loadEnvFile as T, entryStatePath as _, unknownBackupIds as a, WorkspaceStore as b, serverTemplateVars as c, isExposed as d, lanAddress as f, clearEntryState as g, resolveTemplates as h, selectionWritesCredentials as i, validateDdnsConfig as k, bindHost as l, resolveTemplate as m, buildBackupSources as n, hookFailure as o, resolveRecord as p, selectionOf as r, runBackupHook as s, BackupService as t, displayHost as u, readEntryState as v, expandEnvRecord as w, sendWebhook as x, writeEntryState as y };
4690
4690
 
4691
- //# sourceMappingURL=backups-CFRaWe_m.js.map
4691
+ //# sourceMappingURL=backups-twva7x2n.js.map