home-hosted 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +95 -49
  2. package/dist/chunks/{archive-DpCwA8Nf.js → archive-DP-XQR8X.js} +15 -2
  3. package/dist/chunks/archive-DP-XQR8X.js.map +1 -0
  4. package/dist/chunks/{atomic-CEfCUfkQ.js → atomic-C1PfJpE7.js} +3 -2
  5. package/dist/chunks/atomic-C1PfJpE7.js.map +1 -0
  6. package/dist/chunks/{backup-CPrJVPJI.js → backup-CZcVca2a.js} +101 -76
  7. package/dist/chunks/backup-CZcVca2a.js.map +1 -0
  8. package/dist/chunks/{backups-Bd2SF2qd.js → backups-CFRaWe_m.js} +881 -536
  9. package/dist/chunks/backups-CFRaWe_m.js.map +1 -0
  10. package/dist/chunks/{contracts-ku5ypHXJ.js → contracts-CMBD1TF9.js} +381 -407
  11. package/dist/chunks/contracts-CMBD1TF9.js.map +1 -0
  12. package/dist/chunks/{daemon-TwXk5vb8.js → daemon-qKVECISl.js} +52 -20
  13. package/dist/chunks/daemon-qKVECISl.js.map +1 -0
  14. package/dist/chunks/{docker-CGv4Uv7w.js → docker-Cy9Lyvda.js} +4 -3
  15. package/dist/chunks/docker-Cy9Lyvda.js.map +1 -0
  16. package/dist/chunks/{down-BlX5X3bm.js → down-pKbGCW9d.js} +22 -17
  17. package/dist/chunks/down-pKbGCW9d.js.map +1 -0
  18. package/dist/chunks/{init-DdmqHVra.js → init-BZ7hK9Vf.js} +19 -6
  19. package/dist/chunks/init-BZ7hK9Vf.js.map +1 -0
  20. package/dist/chunks/{last-stop-BZ08Z89-.js → last-stop-C-BXz_XI.js} +6 -5
  21. package/dist/chunks/last-stop-C-BXz_XI.js.map +1 -0
  22. package/dist/chunks/{layout-D74TGUnr.js → layout-DwTtmund.js} +2 -2
  23. package/dist/chunks/{layout-D74TGUnr.js.map → layout-DwTtmund.js.map} +1 -1
  24. package/dist/chunks/lazy-Ce5zEAq1.js +66 -0
  25. package/dist/chunks/lazy-Ce5zEAq1.js.map +1 -0
  26. package/dist/chunks/{log-buffer-HnP0jKhZ.js → log-buffer-Dy9HHDMD.js} +114 -50
  27. package/dist/chunks/log-buffer-Dy9HHDMD.js.map +1 -0
  28. package/dist/chunks/{logs-gI_69Q1P.js → logs---TI_bxM.js} +23 -21
  29. package/dist/chunks/logs---TI_bxM.js.map +1 -0
  30. package/dist/chunks/{migrate-BTlsibvF.js → migrate-Cfoq-Vgh.js} +5 -5
  31. package/dist/chunks/{migrate-BTlsibvF.js.map → migrate-Cfoq-Vgh.js.map} +1 -1
  32. package/dist/chunks/{nanny-CjnnrIpm.js → nanny-B-Eu0sFW.js} +3 -3
  33. package/dist/chunks/{nanny-CjnnrIpm.js.map → nanny-B-Eu0sFW.js.map} +1 -1
  34. package/dist/chunks/{nanny-20aBXL1o.js → nanny-BtWfy0QH.js} +121 -23
  35. package/dist/chunks/nanny-BtWfy0QH.js.map +1 -0
  36. package/dist/chunks/{nanny-DUaAfCV-.js → nanny-ChMtq1Zl.js} +3 -3
  37. package/dist/chunks/{nanny-DUaAfCV-.js.map → nanny-ChMtq1Zl.js.map} +1 -1
  38. package/dist/chunks/{nanny-sweep-Ca9kPAVi.js → nanny-sweep-DErnlPY1.js} +5 -4
  39. package/dist/chunks/nanny-sweep-DErnlPY1.js.map +1 -0
  40. package/dist/chunks/{parse-B9owE47G.js → parse-DhmG26fI.js} +4 -4
  41. package/dist/chunks/{parse-B9owE47G.js.map → parse-DhmG26fI.js.map} +1 -1
  42. package/dist/chunks/{paths-BT94q6-w.js → paths-CGlGDrOU.js} +36 -2
  43. package/dist/chunks/paths-CGlGDrOU.js.map +1 -0
  44. package/dist/chunks/{restart-UZgeDukG.js → restart-Des4DrAN.js} +25 -59
  45. package/dist/chunks/restart-Des4DrAN.js.map +1 -0
  46. package/dist/chunks/{schema-o7Lgk0V1.js → schema-B240VXcV.js} +11 -10
  47. package/dist/chunks/schema-B240VXcV.js.map +1 -0
  48. package/dist/chunks/{secrets-D7PdYh71.js → secrets-BieELnZh.js} +22 -4
  49. package/dist/chunks/secrets-BieELnZh.js.map +1 -0
  50. package/dist/chunks/{server-BuIeSsRu.js → server-Bge2r2qQ.js} +3 -3
  51. package/dist/chunks/{server-BuIeSsRu.js.map → server-Bge2r2qQ.js.map} +1 -1
  52. package/dist/chunks/{set-password-DegMumPh.js → set-password-D5vZqqSX.js} +7 -7
  53. package/dist/chunks/set-password-D5vZqqSX.js.map +1 -0
  54. package/dist/chunks/{set-token-21d1FTDC.js → set-token-obPiEJYk.js} +7 -7
  55. package/dist/chunks/set-token-obPiEJYk.js.map +1 -0
  56. package/dist/chunks/{settings-BVSBnIwJ.js → settings-xu-XTfWg.js} +126 -35
  57. package/dist/chunks/settings-xu-XTfWg.js.map +1 -0
  58. package/dist/chunks/{setup-temp-XiuAtiW2.js → setup-temp-CAN4_bA-.js} +6 -6
  59. package/dist/chunks/setup-temp-CAN4_bA-.js.map +1 -0
  60. package/dist/chunks/{src-BL97vLVb.js → src-BtWMFmzZ.js} +2246 -1061
  61. package/dist/chunks/src-BtWMFmzZ.js.map +1 -0
  62. package/dist/chunks/{status-EuWdRq8Q.js → status-DT1EsA-B.js} +12 -8
  63. package/dist/chunks/status-DT1EsA-B.js.map +1 -0
  64. package/dist/chunks/{ui-DbPuwddJ.js → ui-D562aqw5.js} +9 -7
  65. package/dist/chunks/ui-D562aqw5.js.map +1 -0
  66. package/dist/chunks/{ui-revert-BhqOAhmM.js → ui-revert-EkBBwRTt.js} +3 -3
  67. package/dist/chunks/{ui-revert-BhqOAhmM.js.map → ui-revert-EkBBwRTt.js.map} +1 -1
  68. package/dist/chunks/{ui-switch-CMoslPO2.js → ui-switch-BnZTdMDd.js} +3 -3
  69. package/dist/chunks/{ui-switch-CMoslPO2.js.map → ui-switch-BnZTdMDd.js.map} +1 -1
  70. package/dist/chunks/{ui-update-TTBBoDik.js → ui-update-_xryLYxw.js} +5 -5
  71. package/dist/chunks/{ui-update-TTBBoDik.js.map → ui-update-_xryLYxw.js.map} +1 -1
  72. package/dist/chunks/{up-C4H13hBw.js → up-Pdz-l6IH.js} +25 -11
  73. package/dist/chunks/up-Pdz-l6IH.js.map +1 -0
  74. package/dist/chunks/{usage-CSBgLRN5.js → usage-DFrCVXpT.js} +29 -3
  75. package/dist/chunks/usage-DFrCVXpT.js.map +1 -0
  76. package/dist/chunks/{workspaces-CAln2sQ7.js → workspaces-DYcfvKV_.js} +16 -8
  77. package/dist/chunks/workspaces-DYcfvKV_.js.map +1 -0
  78. package/dist/chunks/wsl-temperature-BiCI4iK6.js.map +1 -1
  79. package/dist/cli.js +80 -70
  80. package/dist/cli.js.map +1 -1
  81. package/dist/client.js +25 -1
  82. package/dist/client.js.map +1 -1
  83. package/dist/types/api/backups.d.ts +8 -3
  84. package/dist/types/api/control.d.ts +4 -3
  85. package/dist/types/api/events.d.ts +2 -1
  86. package/dist/types/api/health.d.ts +1 -0
  87. package/dist/types/api/metrics.d.ts +3 -1
  88. package/dist/types/api/settings.d.ts +2 -2
  89. package/dist/types/api/state.d.ts +8 -2
  90. package/dist/types/app.d.ts +26 -11
  91. package/dist/types/cli/backup.d.ts +7 -0
  92. package/dist/types/cli/down.d.ts +5 -0
  93. package/dist/types/cli/logs.d.ts +14 -2
  94. package/dist/types/cli/restart.d.ts +0 -1
  95. package/dist/types/cli/set-password.d.ts +2 -2
  96. package/dist/types/cli/up.d.ts +8 -2
  97. package/dist/types/client.d.ts +5618 -11
  98. package/dist/types/config/secrets.d.ts +2 -0
  99. package/dist/types/config/settings.d.ts +54 -8
  100. package/dist/types/config/store.d.ts +16 -3
  101. package/dist/types/config/workspaces.d.ts +4 -1
  102. package/dist/types/helpers/copy-tree.d.ts +5 -0
  103. package/dist/types/helpers/daemon.d.ts +20 -7
  104. package/dist/types/helpers/error.d.ts +8 -0
  105. package/dist/types/helpers/event-stream.d.ts +21 -0
  106. package/dist/types/helpers/openapi.d.ts +12 -24
  107. package/dist/types/helpers/paths.d.ts +18 -0
  108. package/dist/types/helpers/utf8-chunks.d.ts +15 -0
  109. package/dist/types/middleware/auth.d.ts +19 -3
  110. package/dist/types/providers/host.d.ts +1 -1
  111. package/dist/types/providers/log-tail.d.ts +27 -0
  112. package/dist/types/providers/nanny-sweep.d.ts +3 -0
  113. package/dist/types/providers/nanny.d.ts +10 -0
  114. package/dist/types/providers/proc.d.ts +9 -0
  115. package/dist/types/providers/process.d.ts +17 -0
  116. package/dist/types/providers/telegram.d.ts +45 -3
  117. package/dist/types/providers/wsl-temperature.d.ts +0 -4
  118. package/dist/types/services/auth.d.ts +36 -4
  119. package/dist/types/services/backups.d.ts +125 -1
  120. package/dist/types/services/ddns.d.ts +5 -0
  121. package/dist/types/services/exposure.d.ts +54 -1
  122. package/dist/types/services/history.d.ts +1 -0
  123. package/dist/types/services/host-monitor.d.ts +1 -0
  124. package/dist/types/services/log-buffer.d.ts +11 -0
  125. package/dist/types/services/log-files.d.ts +1 -11
  126. package/dist/types/services/log-relay.d.ts +0 -1
  127. package/dist/types/services/panel.d.ts +19 -0
  128. package/dist/types/services/proxy-certificates/certificates.d.ts +116 -0
  129. package/dist/types/services/proxy.d.ts +46 -69
  130. package/dist/types/services/state.d.ts +0 -3
  131. package/dist/types/services/supervisor/entry.d.ts +10 -0
  132. package/dist/types/services/supervisor/health.d.ts +3 -2
  133. package/dist/types/services/supervisor/output.d.ts +126 -0
  134. package/dist/types/services/supervisor/persistent.d.ts +4 -1
  135. package/dist/types/services/supervisor/records.d.ts +81 -1
  136. package/dist/types/services/supervisor.d.ts +32 -0
  137. package/dist/types/shared/action-outcome.d.ts +25 -0
  138. package/dist/types/shared/api-client.d.ts +218 -4
  139. package/dist/types/shared/backup-scope.d.ts +58 -0
  140. package/dist/types/shared/contracts.d.ts +142 -200
  141. package/dist/types/shared/ddns-form.d.ts +13 -0
  142. package/dist/types/shared/form-repair.d.ts +6 -0
  143. package/dist/types/shared/lazy.d.ts +4 -0
  144. package/dist/types/shared/live-frames.d.ts +22 -0
  145. package/dist/types/shared/live-series.d.ts +21 -0
  146. package/dist/types/shared/live-store.d.ts +72 -0
  147. package/dist/types/shared/patch-diff.d.ts +13 -2
  148. package/dist/types/shared/proxy-form.d.ts +2 -0
  149. package/dist/types/shared/server-form.d.ts +121 -0
  150. package/dist/types/shared/stream-access.d.ts +20 -0
  151. package/docs/API.md +45 -16
  152. package/docs/BACKUPS.md +31 -11
  153. package/docs/CLI.md +34 -61
  154. package/docs/DDNS.md +3 -1
  155. package/docs/NOTIFICATIONS.md +7 -1
  156. package/docs/REVERSE_PROXY.md +7 -1
  157. package/docs/SECURITY.md +21 -10
  158. package/docs/SERVERS.md +102 -23
  159. package/docs/UI_CREATION.md +10 -1
  160. package/docs/demo/blank-host-restore.sh +4 -3
  161. package/package.json +5 -7
  162. package/uis/stock/dist/assets/CopyButton-BUBKRJyY.js +1 -0
  163. package/uis/stock/dist/assets/GlobalSettingsView-yYMcRWvt.js +1 -0
  164. package/uis/stock/dist/assets/LogViewer-DIliXy62.js +1 -0
  165. package/uis/stock/dist/assets/LogsView-B7Z-7RNg.js +1 -0
  166. package/uis/stock/dist/assets/Modal-DmKa5Qpp.js +39 -0
  167. package/uis/stock/dist/assets/ProxyView-DvZiNkwb.js +1 -0
  168. package/uis/stock/dist/assets/ServerDetailView-6idGT_EX.js +2 -0
  169. package/uis/stock/dist/assets/SettingsShell-CeGtleYI.js +1 -0
  170. package/uis/stock/dist/assets/SettingsView-BrhJIrmk.js +2 -0
  171. package/uis/stock/dist/assets/de-BRITeb0H.js +1 -0
  172. package/uis/stock/dist/assets/es-B2zIEssV.js +1 -0
  173. package/uis/stock/dist/assets/fr-s0ZOBEqh.js +1 -0
  174. package/uis/stock/dist/assets/index-C1MehbKy.css +2 -0
  175. package/uis/stock/dist/assets/index-CnBN54wF.js +15 -0
  176. package/uis/stock/dist/assets/ja-CU7MR85V.js +1 -0
  177. package/uis/stock/dist/assets/ko-tL5Me6d-.js +1 -0
  178. package/uis/stock/dist/assets/ru-92yrvkNJ.js +1 -0
  179. package/uis/stock/dist/assets/vi-CzvY16k2.js +1 -0
  180. package/uis/stock/dist/assets/zh-CN-DDwFW_uW.js +1 -0
  181. package/uis/stock/dist/index.html +3 -2
  182. package/uis/stock/dist/ui.json +3 -3
  183. package/dist/chunks/archive-DpCwA8Nf.js.map +0 -1
  184. package/dist/chunks/atomic-CEfCUfkQ.js.map +0 -1
  185. package/dist/chunks/backup-CPrJVPJI.js.map +0 -1
  186. package/dist/chunks/backups-Bd2SF2qd.js.map +0 -1
  187. package/dist/chunks/contracts-ku5ypHXJ.js.map +0 -1
  188. package/dist/chunks/daemon-TwXk5vb8.js.map +0 -1
  189. package/dist/chunks/docker-CGv4Uv7w.js.map +0 -1
  190. package/dist/chunks/down-BlX5X3bm.js.map +0 -1
  191. package/dist/chunks/init-DdmqHVra.js.map +0 -1
  192. package/dist/chunks/last-stop-BZ08Z89-.js.map +0 -1
  193. package/dist/chunks/log-buffer-HnP0jKhZ.js.map +0 -1
  194. package/dist/chunks/logs-gI_69Q1P.js.map +0 -1
  195. package/dist/chunks/nanny-20aBXL1o.js.map +0 -1
  196. package/dist/chunks/nanny-sweep-Ca9kPAVi.js.map +0 -1
  197. package/dist/chunks/paths-BT94q6-w.js.map +0 -1
  198. package/dist/chunks/restart-UZgeDukG.js.map +0 -1
  199. package/dist/chunks/schema-o7Lgk0V1.js.map +0 -1
  200. package/dist/chunks/secrets-D7PdYh71.js.map +0 -1
  201. package/dist/chunks/set-password-DegMumPh.js.map +0 -1
  202. package/dist/chunks/set-token-21d1FTDC.js.map +0 -1
  203. package/dist/chunks/settings-BVSBnIwJ.js.map +0 -1
  204. package/dist/chunks/setup-temp-XiuAtiW2.js.map +0 -1
  205. package/dist/chunks/src-BL97vLVb.js.map +0 -1
  206. package/dist/chunks/status-EuWdRq8Q.js.map +0 -1
  207. package/dist/chunks/ui-DbPuwddJ.js.map +0 -1
  208. package/dist/chunks/up-C4H13hBw.js.map +0 -1
  209. package/dist/chunks/usage-CSBgLRN5.js.map +0 -1
  210. package/dist/chunks/workspaces-CAln2sQ7.js.map +0 -1
  211. package/docs/RESTORE_DEMO.md +0 -306
  212. package/uis/stock/dist/assets/de-DyGrM1KK.js +0 -1
  213. package/uis/stock/dist/assets/es-BebHdc0E.js +0 -1
  214. package/uis/stock/dist/assets/fr-DsDTrxhI.js +0 -1
  215. package/uis/stock/dist/assets/index-6LANO2Ua.css +0 -2
  216. package/uis/stock/dist/assets/index-D06cUZbM.js +0 -56
  217. package/uis/stock/dist/assets/ja-D3RARJjW.js +0 -1
  218. package/uis/stock/dist/assets/ko-CKI3dFoD.js +0 -1
  219. package/uis/stock/dist/assets/ru-DEU5ujXt.js +0 -1
  220. package/uis/stock/dist/assets/vi-ULKPnasj.js +0 -1
  221. package/uis/stock/dist/assets/zh-CN-tCvnOxWy.js +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
- import { n as GlobalSettingsStore } from "./settings-BVSBnIwJ.js";
3
- import { a as globalSettingsPath, i as globalSecretsPath, j as workspacesPath, s as hhDir, x as tlsDir, y as resolveUserPath } from "./paths-BT94q6-w.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-Bd2SF2qd.js";
5
- import { n as WorkspaceRegistry } from "./workspaces-CAln2sQ7.js";
6
- import { g as readNannyState } from "./nanny-20aBXL1o.js";
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
+ 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";
5
+ import { n as WorkspaceRegistry } from "./workspaces-DYcfvKV_.js";
6
+ import { _ as readNannyState } from "./nanny-BtWfy0QH.js";
7
7
  import process from "node:process";
8
8
  import { defineCommand } from "citty";
9
9
  import path from "node:path";
@@ -73,9 +73,9 @@ function createOfflineBackup(options = {}) {
73
73
  const settingsPath = options.settingsPath ?? globalSettingsPath;
74
74
  const registryPath = path.join(hhDir$1, path.basename(workspacesPath));
75
75
  const settings = new GlobalSettingsStore(settingsPath);
76
- settings.load();
76
+ settings.load({ write: false });
77
77
  const registry = new WorkspaceRegistry(registryPath);
78
- registry.load();
78
+ registry.load({ write: false });
79
79
  const workspaces = workspaceIds(registry);
80
80
  const ids = workspaces.map((workspace) => workspace.id);
81
81
  const loaded = workspaces.map((workspace) => {
@@ -84,7 +84,7 @@ function createOfflineBackup(options = {}) {
84
84
  const serversPath = path.join(dir, "servers.config.json");
85
85
  const secretsPath = path.join(dir, ".secrets.json");
86
86
  const store = new WorkspaceStore(workspace.id, settingsPath, serversPath);
87
- store.load();
87
+ store.load({ write: false });
88
88
  return {
89
89
  id: workspace.id,
90
90
  label: workspace.label,
@@ -113,7 +113,7 @@ function createOfflineBackup(options = {}) {
113
113
  */
114
114
  onLoadPending: (workspaceId, serverId, dumpDir) => {
115
115
  const dir = path.join(hhDir$1, workspaceId, ".state");
116
- fs.mkdirSync(dir, { recursive: true });
116
+ ensureStateDir(dir);
117
117
  const statePath = entryStatePath(dir, serverId);
118
118
  const persisted = readEntryState(statePath);
119
119
  writeEntryState(statePath, {
@@ -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-TwXk5vb8.js");
196
+ const daemon = await import("./daemon-qKVECISl.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,23 +208,13 @@ 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-TwXk5vb8.js");
211
+ const daemon = await import("./daemon-qKVECISl.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;
215
215
  }
216
- /**
217
- * The offline service.
218
- *
219
- * It reads the same files the panel does — every workspace's `settings.json` and
220
- * `servers.config.json` under the state root — so an archive taken with the panel down holds what a
221
- * running one would have captured.
222
- */
223
- async function offlineBackup() {
224
- return createOfflineBackup();
225
- }
226
- /** Turn a non-200 control answer into the panel's own message, or the status. */
227
- function refusal(answer) {
216
+ /** Exit on a non-200 control answer with the panel's own message, or the status. */
217
+ function failWithAnswer(answer) {
228
218
  const body = answer.body;
229
219
  if (body?.message !== void 0) fail(body.message);
230
220
  fail(`the panel answered ${answer.status}`);
@@ -321,7 +311,7 @@ async function refuseWithoutScope(action, suffix) {
321
311
  */
322
312
  async function availableRowsFromDisk(action, suffix) {
323
313
  try {
324
- const { service } = await offlineBackup();
314
+ const { service } = createOfflineBackup();
325
315
  await service.warm();
326
316
  if (action === "create") return service.selection().entries;
327
317
  const query = new URLSearchParams(suffix.startsWith("?") ? suffix.slice(1) : suffix);
@@ -342,7 +332,7 @@ async function availableRowsFromDisk(action, suffix) {
342
332
  * be reached yields no ids — the refusal still fires, it just cannot enumerate.
343
333
  */
344
334
  async function availableRows(action, suffix) {
345
- const daemon = await import("./daemon-TwXk5vb8.js");
335
+ const daemon = await import("./daemon-qKVECISl.js");
346
336
  const runtime = daemon.readRuntime();
347
337
  if (runtime === null || !await daemon.runtimeIsAlive(runtime)) return await availableRowsFromDisk(action, suffix);
348
338
  const path = action === "create" ? "/_hh/backups" : "/_hh/backups/restore";
@@ -362,14 +352,13 @@ function withParam(suffix, key, value) {
362
352
  /**
363
353
  * Ask before writing.
364
354
  *
365
- * A session that cannot be asked gets the plan and a one-line instruction — not a silent write, and
366
- * not a silent no-op that looks like one.
355
+ * A session that cannot be asked is refused, exit 1, after the plan: not a silent write, and not a
356
+ * success. Exiting 0 here meant a cron job's `backup create --all` printed a plan every night and
357
+ * never took a backup, with nothing in its exit status to say so. (`--json` without `--confirm` is
358
+ * the explicit "show me the plan" request and still exits 0; it never reaches this.)
367
359
  */
368
360
  async function consent(question) {
369
- if (process.stdin.isTTY !== true) {
370
- process.stdout.write("\nnot applied — this session cannot ask. Re-run with `--confirm` to apply.\n");
371
- return false;
372
- }
361
+ if (process.stdin.isTTY !== true) fail("not applied — this session cannot ask for consent; re-run with --confirm to apply (or --json to only read the plan)");
373
362
  const answer = await prompt(`${question} [y/N] `);
374
363
  if (/^yes$|^y$/i.test(answer.trim())) {
375
364
  process.stdout.write("\n");
@@ -391,12 +380,12 @@ async function runBackupList(json) {
391
380
  if (runtime !== null) {
392
381
  const answer = await runtime.request(runtime, "/_hh/backups", 3e4, "GET");
393
382
  if (answer === null) fail(`the control panel is not answering on ${runtime.probeUrl}`);
394
- if (answer.status !== 200) refusal(answer);
383
+ if (answer.status !== 200) failWithAnswer(answer);
395
384
  printList(answer.body, json);
396
385
  return;
397
386
  }
398
387
  }
399
- const { service } = await offlineBackup();
388
+ const { service } = createOfflineBackup();
400
389
  await service.warm();
401
390
  printList(service.selection(), json);
402
391
  }
@@ -439,11 +428,11 @@ async function runBackupCreate(options) {
439
428
  if (runtime !== null) {
440
429
  const answer = await runtime.request(runtime, "/_hh/backups", 12e4);
441
430
  if (answer === null) fail(`the control panel is not answering on ${runtime.probeUrl}`);
442
- if (answer.status !== 200) refusal(answer);
431
+ if (answer.status !== 200) failWithAnswer(answer);
443
432
  return answer.body?.entries ?? [];
444
433
  }
445
434
  }
446
- const { service } = await offlineBackup();
435
+ const { service } = createOfflineBackup();
447
436
  await service.warm();
448
437
  return service.selection().entries;
449
438
  })();
@@ -465,12 +454,12 @@ async function runBackupCreate(options) {
465
454
  process.stdout.write(" (nothing matched — check --include, or what the entries declare)\n");
466
455
  return;
467
456
  }
468
- warnRunning(await runningEntries());
457
+ warnRunning(createOfflineBackup().runningNow());
469
458
  if (!await consent("Take this backup?")) return;
470
459
  }
471
460
  const include = scope.kind === "include" ? scope.ids : void 0;
472
461
  const exclude = options.exclude;
473
- const file = (await (async () => {
462
+ const created = await (async () => {
474
463
  if (online) {
475
464
  const runtime = await livePanel();
476
465
  if (runtime !== null) {
@@ -480,11 +469,11 @@ async function runBackupCreate(options) {
480
469
  if (exclude !== void 0) query.set("exclude", exclude.join(","));
481
470
  const answer = await runtime.request(runtime, `/_hh/backups${withParam(suffixOf(query), "confirm", "true")}`, 6e5);
482
471
  if (answer === null) fail(`the control panel is not answering on ${runtime.probeUrl}`);
483
- if (answer.status !== 200) refusal(answer);
472
+ if (answer.status !== 200) failWithAnswer(answer);
484
473
  return answer.body;
485
474
  }
486
475
  }
487
- const { service } = await offlineBackup();
476
+ const { service } = createOfflineBackup();
488
477
  await service.warm();
489
478
  const result = await service.create({
490
479
  password: options.password,
@@ -492,28 +481,25 @@ async function runBackupCreate(options) {
492
481
  exclude
493
482
  });
494
483
  if (!result.ok) fail(result.error ?? "the backup failed");
495
- return { file: result.file };
496
- })())?.file;
484
+ return {
485
+ file: result.file,
486
+ ...result.warnings === void 0 ? {} : { warnings: result.warnings }
487
+ };
488
+ })();
489
+ const file = created?.file;
497
490
  if (file === void 0) fail("the backup reported success but named no archive");
491
+ const warnings = created?.warnings ?? [];
498
492
  if (options.json) {
499
493
  process.stdout.write(`${JSON.stringify({
500
494
  action: "create",
501
495
  apply: true,
502
- file
496
+ file,
497
+ ...warnings.length === 0 ? {} : { warnings }
503
498
  }, null, 2)}\n`);
504
499
  return;
505
500
  }
506
501
  process.stdout.write(`${green("backup created")} ${file.name} ${dim(`(${human(file.sizeBytes)})`)}\n`);
507
- }
508
- /**
509
- * The entries running right now.
510
- *
511
- * Read from the state files in **both** cases: the panel's own backup view has no per-entry running
512
- * flag to read, and the state files are the same witness the panel's supervisor would give — a
513
- * persistent entry keeps its nanny alive and rewrites that file whether or not the panel is up.
514
- */
515
- async function runningEntries() {
516
- return (await offlineBackup()).runningNow();
502
+ for (const warning of warnings) process.stderr.write(`warning: ${warning}\n`);
517
503
  }
518
504
  /**
519
505
  * Why a restore plan is not something to apply, or `null`.
@@ -531,20 +517,6 @@ function planRefusal(plan) {
531
517
  if (plan.error !== void 0 && plan.error.length > 0) return plan.error;
532
518
  return null;
533
519
  }
534
- /**
535
- * A restore's per-item skips, as lines a person can act on.
536
- *
537
- * `skipped` is the same list the UI draws, and it is the only thing that says a piece of an
538
- * otherwise successful restore was left behind — an unreadable `servers.config.json`, a data path
539
- * whose declaration changed, a dump staged for an entry with no `load` hook. Printing only the
540
- * applied count reported such a restore as complete.
541
- *
542
- * Read from the outcome of the run that is being reported: the plan and the apply answer different
543
- * lists, because a skip such as a missing load hook is only known once the files have landed.
544
- */
545
- function restoreNotes(outcome) {
546
- return outcome?.skipped ?? [];
547
- }
548
520
  async function runBackupRestore(options) {
549
521
  const scope = options.scope;
550
522
  const online = await usesPanel();
@@ -569,7 +541,7 @@ async function runBackupRestore(options) {
569
541
  /** What to call it in the plan and the result: the file it read, name or path. */
570
542
  const label = source.kind === "from" ? path.basename(source.path) : source.name;
571
543
  if (source.kind === "from" && (!fs.existsSync(source.path) || !fs.statSync(source.path).isFile())) fail(`no file at ${source.path} — \`--from\` takes the path to an archive on this machine`);
572
- const service = online ? null : (await offlineBackup()).service;
544
+ const service = online ? null : createOfflineBackup().service;
573
545
  if (service !== null) await service.warm();
574
546
  const plan = await (async () => {
575
547
  if (service !== null) {
@@ -593,7 +565,7 @@ async function runBackupRestore(options) {
593
565
  const base = restoreQuery(source, options, scope);
594
566
  const answer = await runtime.request(runtime, `/_hh/backups/restore${suffixOf(base)}`, 12e4);
595
567
  if (answer === null) fail(`the control panel is not answering at ${runtime.probeUrl}`);
596
- if (answer.status !== 200) refusal(answer);
568
+ if (answer.status !== 200) failWithAnswer(answer);
597
569
  return answer.body;
598
570
  })();
599
571
  const refused = planRefusal(plan);
@@ -616,7 +588,7 @@ async function runBackupRestore(options) {
616
588
  apply: false,
617
589
  name: label,
618
590
  items,
619
- skipped: restoreNotes(plan)
591
+ skipped: plan?.skipped ?? []
620
592
  }, null, 2)}\n`);
621
593
  return;
622
594
  }
@@ -626,7 +598,7 @@ async function runBackupRestore(options) {
626
598
  id: item.id,
627
599
  note: item.note ?? null
628
600
  })));
629
- if (!options.confirm) for (const note of restoreNotes(plan)) process.stdout.write(` ${dim("!")} ${note}\n`);
601
+ if (!options.confirm) for (const note of plan?.skipped ?? []) process.stdout.write(` ${dim("!")} ${note}\n`);
630
602
  if (items.length === 0) {
631
603
  process.stdout.write(" (nothing to restore — check --include, or what this host declares)\n");
632
604
  return;
@@ -653,7 +625,7 @@ async function runBackupRestore(options) {
653
625
  const base = restoreQuery(source, options, scope);
654
626
  const answer = await runtime.request(runtime, `/_hh/backups/restore${withParam(suffixOf(base), "confirm", "true")}`, 6e5);
655
627
  if (answer === null) fail(`the control panel is not answering at ${runtime.probeUrl}`);
656
- if (answer.status !== 200) refusal(answer);
628
+ if (answer.status !== 200) failWithAnswer(answer);
657
629
  const result = answer.body;
658
630
  return {
659
631
  ...result,
@@ -673,7 +645,7 @@ async function runBackupRestore(options) {
673
645
  }
674
646
  const applied = (outcome.items ?? []).filter((item) => item.selected !== false);
675
647
  const hooks = (outcome.hooks ?? []).filter((hook) => hook.action === "load");
676
- const notes = restoreNotes(outcome);
648
+ const notes = outcome.skipped ?? [];
677
649
  if (options.json) {
678
650
  process.stdout.write(`${JSON.stringify({
679
651
  action: "restore",
@@ -710,6 +682,58 @@ function restoreQuery(source, options, scope) {
710
682
  if (options.exclude !== void 0) base.set("exclude", options.exclude.join(","));
711
683
  return base;
712
684
  }
685
+ /** What each action reads. Anything else given is refused, never parsed and dropped. */
686
+ var HONOURED = {
687
+ list: /* @__PURE__ */ new Set(["json"]),
688
+ create: /* @__PURE__ */ new Set([
689
+ "password",
690
+ "include",
691
+ "exclude",
692
+ "all",
693
+ "confirm",
694
+ "json"
695
+ ]),
696
+ restore: /* @__PURE__ */ new Set([
697
+ "target",
698
+ "from",
699
+ "password",
700
+ "include",
701
+ "exclude",
702
+ "all",
703
+ "confirm",
704
+ "json"
705
+ ])
706
+ };
707
+ /**
708
+ * A flag the action cannot honour is refused, not ignored: `backup list --all --include x` listed
709
+ * every archive, and `backup create foo --all` dropped `foo` without a word.
710
+ */
711
+ function unhonouredBackupFlag(action, given) {
712
+ for (const flag of Object.keys(given)) {
713
+ if (given[flag] === void 0 || HONOURED[action].has(flag)) continue;
714
+ if (flag === "target") return `\`backup ${action}\` takes no archive name ("${String(given.target)}") — only restore reads one`;
715
+ return `--${flag} does nothing for \`backup ${action}\` — drop it`;
716
+ }
717
+ return null;
718
+ }
719
+ function refuseUnhonouredFlags(action, args) {
720
+ const given = {};
721
+ for (const flag of [
722
+ "target",
723
+ "from",
724
+ "password",
725
+ "include",
726
+ "exclude",
727
+ "all",
728
+ "confirm",
729
+ "json"
730
+ ]) {
731
+ const value = args[flag];
732
+ if (value !== void 0 && value !== "") given[flag] = value;
733
+ }
734
+ const problem = unhonouredBackupFlag(action, given);
735
+ if (problem !== null) fail(problem);
736
+ }
713
737
  var backupCommand = defineCommand({
714
738
  meta: { name: "backup" },
715
739
  args: {
@@ -755,9 +779,10 @@ var backupCommand = defineCommand({
755
779
  async run({ args }) {
756
780
  try {
757
781
  const action = args.action === void 0 || args.action.length === 0 ? "list" : args.action;
782
+ if (action !== "list" && action !== "create" && action !== "restore") fail(`unknown action "${action}" — use list, create or restore`);
783
+ refuseUnhonouredFlags(action, args);
758
784
  const parsed = action === "create" || action === "restore" ? parseScope(args.all === true, args.include) : null;
759
785
  const exclude = action === "create" || action === "restore" ? parseExclude(args.exclude) : void 0;
760
- if (action !== "restore" && args.from !== void 0 && args.from.length > 0) fail(`--from is for restore — \`${invocation()} backup ${action}\` takes none`);
761
786
  if (action === "list") await runBackupList(args.json === true);
762
787
  else if (action === "create") {
763
788
  const scope = parsed ?? await refuseWithoutScope("create", "");
@@ -768,7 +793,7 @@ var backupCommand = defineCommand({
768
793
  confirm: args.confirm === true,
769
794
  json: args.json === true
770
795
  });
771
- } else if (action === "restore") {
796
+ } else {
772
797
  const from = args.from !== void 0 && args.from.length > 0 ? args.from : void 0;
773
798
  const name = args.target !== void 0 && args.target.length > 0 ? args.target : void 0;
774
799
  if (from !== void 0 && name !== void 0) fail("pass an archive name or --from <path>, not both — they name two different archives");
@@ -785,7 +810,7 @@ var backupCommand = defineCommand({
785
810
  confirm: args.confirm === true,
786
811
  json: args.json === true
787
812
  });
788
- } else fail(`unknown action "${action}" — use list, create or restore`);
813
+ }
789
814
  } catch (error) {
790
815
  fail(errorMessage(error));
791
816
  }
@@ -794,4 +819,4 @@ var backupCommand = defineCommand({
794
819
  //#endregion
795
820
  export { backupCommand };
796
821
 
797
- //# sourceMappingURL=backup-CPrJVPJI.js.map
822
+ //# sourceMappingURL=backup-CZcVca2a.js.map
@@ -0,0 +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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