@sealant/mend 0.36.0-next.780 → 0.36.0-next.785

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 (92) hide show
  1. package/dist/main.js +395 -113
  2. package/man/mend-accounts.1 +1 -1
  3. package/man/mend-adopt.1 +1 -1
  4. package/man/mend-attach.1 +1 -1
  5. package/man/mend-codex.1 +1 -1
  6. package/man/mend-completions.1 +1 -1
  7. package/man/mend-connect-pi.1 +1 -1
  8. package/man/mend-connect.1 +1 -1
  9. package/man/mend-continue.1 +1 -1
  10. package/man/mend-doctor.1 +2 -2
  11. package/man/mend-dotfiles-repo.1 +1 -1
  12. package/man/mend-dotfiles-sync.1 +1 -1
  13. package/man/mend-dotfiles.1 +1 -1
  14. package/man/mend-env-cluster.1 +1 -1
  15. package/man/mend-env-load.1 +1 -1
  16. package/man/mend-env-show.1 +1 -1
  17. package/man/mend-folder-create.1 +1 -1
  18. package/man/mend-folder-list.1 +1 -1
  19. package/man/mend-folder-push.1 +1 -1
  20. package/man/mend-folder-rm.1 +1 -1
  21. package/man/mend-git-author.1 +1 -1
  22. package/man/mend-help.1 +1 -1
  23. package/man/mend-invite.1 +1 -1
  24. package/man/mend-keys-init.1 +1 -1
  25. package/man/mend-keys-mode.1 +1 -1
  26. package/man/mend-keys-share.1 +1 -1
  27. package/man/mend-keys-show.1 +1 -1
  28. package/man/mend-land.1 +1 -1
  29. package/man/mend-login.1 +1 -1
  30. package/man/mend-logout.1 +1 -1
  31. package/man/mend-logs.1 +1 -1
  32. package/man/mend-man.1 +1 -1
  33. package/man/mend-members.1 +1 -1
  34. package/man/mend-memory-import.1 +1 -1
  35. package/man/mend-memory-rm.1 +1 -1
  36. package/man/mend-memory-show.1 +1 -1
  37. package/man/mend-memory.1 +1 -1
  38. package/man/mend-models.1 +2 -2
  39. package/man/mend-operator-exposure.1 +1 -1
  40. package/man/mend-operator-gate.1 +1 -1
  41. package/man/mend-operator-grant-owner.1 +1 -1
  42. package/man/mend-operator-org-create.1 +1 -1
  43. package/man/mend-operator-org-invite-owner.1 +1 -1
  44. package/man/mend-operator-org-list.1 +1 -1
  45. package/man/mend-operator-org-rename.1 +1 -1
  46. package/man/mend-operator-reset-link.1 +1 -1
  47. package/man/mend-pair.1 +1 -1
  48. package/man/mend-projects.1 +1 -1
  49. package/man/mend-pull.1 +1 -1
  50. package/man/mend-refresh.1 +1 -1
  51. package/man/mend-rejoin.1 +1 -1
  52. package/man/mend-resume.1 +1 -1
  53. package/man/mend-run.1 +1 -1
  54. package/man/mend-secrets-add.1 +1 -1
  55. package/man/mend-secrets-rm.1 +1 -1
  56. package/man/mend-secrets.1 +1 -1
  57. package/man/mend-server-logs.1 +1 -1
  58. package/man/mend-server-restart.1 +1 -1
  59. package/man/mend-server-setup.1 +1 -1
  60. package/man/mend-server-start.1 +1 -1
  61. package/man/mend-server-status.1 +1 -1
  62. package/man/mend-server-stop.1 +1 -1
  63. package/man/mend-server-upgrade.1 +1 -1
  64. package/man/mend-server.1 +1 -1
  65. package/man/mend-service-add.1 +1 -1
  66. package/man/mend-service-connect.1 +1 -1
  67. package/man/mend-service-init.1 +1 -1
  68. package/man/mend-service-list.1 +1 -1
  69. package/man/mend-service-logs.1 +1 -1
  70. package/man/mend-service-restart.1 +1 -1
  71. package/man/mend-service-run.1 +1 -1
  72. package/man/mend-service-stop.1 +1 -1
  73. package/man/mend-session-share.1 +1 -1
  74. package/man/mend-sessions.1 +1 -1
  75. package/man/mend-shell.1 +1 -1
  76. package/man/mend-skills-push.1 +1 -1
  77. package/man/mend-skills.1 +1 -1
  78. package/man/mend-snake.1 +1 -1
  79. package/man/mend-ssh-keys-remove.1 +1 -1
  80. package/man/mend-ssh-keys.1 +1 -1
  81. package/man/mend-ssh-setup.1 +1 -1
  82. package/man/mend-ssh.1 +1 -1
  83. package/man/mend-stop.1 +1 -1
  84. package/man/mend-ui.1 +1 -1
  85. package/man/mend-uninstall.1 +1 -1
  86. package/man/mend-version.1 +1 -1
  87. package/man/mend-wait.1 +1 -1
  88. package/man/mend-workspace-replace.1 +1 -1
  89. package/man/mend-worktrees-rm.1 +1 -1
  90. package/man/mend-worktrees.1 +1 -1
  91. package/man/mend.1 +1 -1
  92. package/package.json +2 -2
package/dist/main.js CHANGED
@@ -2411,7 +2411,7 @@ var COMMANDS = [
2411
2411
  summary: "the models each harness offers, as the server lists them",
2412
2412
  synopsis: ["[--json]"],
2413
2413
  description: [
2414
- "One block per harness: each model's id, the one a launch runs when --model is not given, and the efforts a model takes where they are fewer than the harness's. The list is the server's; the phone, the web app, the desktop and VS Code offer the same one, and a session records which model it was started with.",
2414
+ "One block per harness: each model's id, the one a launch runs when --model is not given, and the efforts a model takes where they are fewer than the harness's. The list is the server's; the phone, the web app and VS Code offer the same one, and a session records which model it was started with.",
2415
2415
  "Pass an id to mend claude or mend codex with --model. An id the list does not know is passed through as given; the harness decides whether it exists."
2416
2416
  ],
2417
2417
  options: [{ flag: "--json", text: "the catalog as the server answers it" }],
@@ -2441,7 +2441,7 @@ var COMMANDS = [
2441
2441
  summary: "check this machine's setup, or bundle it for a bug report",
2442
2442
  synopsis: ["", "--bundle [--out <path>] [--tail <n>]"],
2443
2443
  description: [
2444
- "Read-only. One line per fact: the server, the sign-in, the platform connection, the provider accounts, the git key, and where docker is on PATH what a stop of its daemon waits for against what systemd allows docker.service. Each unfinished line ends with the command that fixes it.",
2444
+ "Read-only. One line per fact: the server, the sign-in, the platform connection, the provider accounts, the adopted projects, the claude, codex and gh CLIs on this machine, the exposure, the server's clock against this machine's, a Mac that sleeps on its own or when its lid closes, and where docker is on PATH what a stop of its daemon waits for against what systemd allows docker.service. Each unfinished line ends with the command that fixes it.",
2445
2445
  "--bundle collects what a maintainer asks for one output at a time into one tar.gz: this CLI and its environment, the doctor lines, the server's health, the local server's configuration (its compose file and the names of its .env keys, never their values), docker version, info, contexts, the Mend and workspace containers with their inspect facts, the local server's container logs, the running workspace containers' logs, every session with its processes, exit codes and argv, the recorded terminal output of each, the connected accounts, and the versions and paths of claude, codex, gh, git and docker on this machine.",
2446
2446
  "Each part is collected on its own: one that fails leaves a <name>.error.txt in the bundle instead of stopping it. One redactor runs over every file before it is written: bearer and header values, Slack, OpenAI, GitHub and AWS token shapes, JWTs, passwords in URLs, and any password, secret or token value. The archive is written with mode 0600. It still contains logs and configuration; read it before you share it."
2447
2447
  ],
@@ -7854,6 +7854,50 @@ var MEND_DOCKER_NAMESPACE_WITH_GARAGE = {
7854
7854
  };
7855
7855
  var secondaryVolumesOf = (namespace) => namespace.garage === void 0 ? [namespace.control] : [namespace.control, namespace.garage];
7856
7856
  var SERVER_VOLUME_OWNER_LABEL = "dev.sealant.mend.installation";
7857
+ var COMPOSE_PROJECT_LABEL = "com.docker.compose.project";
7858
+ var COMPOSE_WORKING_DIR_LABEL = "com.docker.compose.project.working_dir";
7859
+ var namedAs = (kind, names) => {
7860
+ const [only] = names;
7861
+ if (only === void 0) return [];
7862
+ return [
7863
+ names.length === 1 ? `${kind} ${only}` : `${names.length} ${kind}s (${names.join(", ")})`
7864
+ ];
7865
+ };
7866
+ var leftoverItems = (leftovers) => [
7867
+ ...namedAs("container", leftovers.containers),
7868
+ ...namedAs("network", leftovers.networks),
7869
+ ...namedAs("volume", leftovers.volumes)
7870
+ ];
7871
+ var leftoversRemoval = (dockerContext) => `DOCKER_CONTEXT=${dockerContext} mend uninstall --server`;
7872
+ var KEEP_THE_DATA = "To keep it, put that install's Mend config directory (identity.env and generations) back where it was and run mend server setup: setup takes up the volumes its identity owns.";
7873
+ var serverOldDataWords = (found) => {
7874
+ const elsewhere = "install in another Docker context: mend server setup --context <name>.";
7875
+ if (found._tag === "leftovers") {
7876
+ const { leftovers } = found;
7877
+ const count = leftovers.containers.length + leftovers.networks.length + leftovers.volumes.length;
7878
+ const them = count === 1 ? "it" : "them";
7879
+ const volumes = leftovers.volumes.length;
7880
+ return `Docker context ${leftovers.dockerContext} holds what an earlier Mend install left, and no installation owns ${them}: ${leftoverItems(leftovers).join(", ")}. ` + (volumes === 0 ? "" : `The ${volumes === 1 ? "volume" : "volumes"} may hold that install's data, and removing ${volumes === 1 ? "it" : "them"} deletes that data. ${KEEP_THE_DATA} `) + `Setup does not install beside ${them}. To remove ${them}: ${leftoversRemoval(leftovers.dockerContext)}, then run mend server setup again.`;
7881
+ }
7882
+ const [first, ...more] = found.inTheWay;
7883
+ const { dockerContext } = first;
7884
+ const beside = found.leftovers === null ? "" : ` Beside ${more.length === 0 ? "it" : "them"}, what an earlier Mend install left: ${leftoverItems(found.leftovers).join(", ")}, which ${leftoversRemoval(dockerContext)} removes.`;
7885
+ if (more.length === 0) {
7886
+ const { kind, name, mend, why } = first;
7887
+ const look = `To see what it is: docker --context ${dockerContext} ${kind} inspect ${name}.`;
7888
+ return mend ? `Docker context ${dockerContext} has ${kind} ${name} from an earlier Mend install, with no installation to own it, and ${why}. Setup leaves it alone. ${look} Stop what runs there, then remove what that install left with ${leftoversRemoval(dockerContext)}, or ${elsewhere}${beside}` : `Docker context ${dockerContext} has a ${kind} named ${name} that is not Mend's: it ${why}. Setup leaves it alone and cannot install beside it. ${look} Remove it yourself if nothing needs it, or ${elsewhere}${beside}`;
7889
+ }
7890
+ const items = found.inTheWay;
7891
+ const mends = items.some((item) => item.mend);
7892
+ const foreign = items.some((item) => !item.mend);
7893
+ const each = items.map(
7894
+ (item) => item.mend ? `${item.kind} ${item.name}, from an earlier Mend install with no installation to own it: ${item.why}` : `${item.kind} ${item.name}, not Mend's: it ${item.why}`
7895
+ );
7896
+ const looks = items.map(
7897
+ (item) => `docker --context ${dockerContext} ${item.kind} inspect ${item.name}`
7898
+ );
7899
+ return `Docker context ${dockerContext} has ${items.length} things setup cannot install beside: ${each.join("; ")}. Setup leaves them alone. To see what each is: ${looks.join(", ")}. ` + (mends ? `Stop what runs on Mend's, then remove what that install left with ${leftoversRemoval(dockerContext)}. ` : "") + (foreign ? `Remove what is not Mend's yourself if nothing needs it, or ${elsewhere}` : `Or ${elsewhere}`) + beside;
7900
+ };
7857
7901
  var ServerVolumeOwnershipError = class extends ServerRefusal {
7858
7902
  /** Stable error discriminator. */
7859
7903
  _tag = "ServerVolumeOwnershipError";
@@ -7861,17 +7905,16 @@ var ServerVolumeOwnershipError = class extends ServerRefusal {
7861
7905
  reason;
7862
7906
  /** Safe operation name, never credentials or raw Docker output. */
7863
7907
  operation;
7864
- /**
7865
- * Construct an actionable ownership failure without including identity bytes. `leftover`: the
7866
- * data in the way carries Mend's installation label but no anchor, so it is what an earlier
7867
- * install left behind (a partial `mend uninstall`), and `mend uninstall` is the way out.
7868
- */
7869
- constructor(reason, operation, leftover = false) {
7908
+ /** With `unowned-data`: what stands in the way. */
7909
+ found;
7910
+ /** Construct an actionable ownership failure without including identity bytes. */
7911
+ constructor(reason, operation, found) {
7870
7912
  super(
7871
- `Docker volume ownership check failed (${reason}, ${operation}). ` + (reason === "docker" || reason === "inspection" ? "Check Docker access and the selected context, then retry. No absence was assumed." : leftover ? "Docker still holds what an earlier Mend install left behind: volumes with Mend's installation label and no installation to own them. Run mend uninstall --server to remove them, then run setup again." : "Retain all Docker data. Restore the original Mend identity/configuration or choose a clean Docker daemon; do not delete or relabel existing data.")
7913
+ found !== void 0 ? serverOldDataWords(found) : `Docker volume ownership check failed (${reason}, ${operation}). ` + (reason === "docker" || reason === "inspection" ? "Check Docker access and the selected context, then retry. No absence was assumed." : "Retain all Docker data. Restore the original Mend identity/configuration or choose a clean Docker daemon; do not delete or relabel existing data.")
7872
7914
  );
7873
7915
  this.reason = reason;
7874
7916
  this.operation = operation;
7917
+ this.found = found;
7875
7918
  }
7876
7919
  };
7877
7920
  var fail5 = (reason, operation) => ({ _tag: "error", error: new ServerVolumeOwnershipError(reason, operation) });
@@ -7885,14 +7928,13 @@ var docker = async (runtime, context, args) => {
7885
7928
  return fail5("docker", args.slice(0, 2).join(" "));
7886
7929
  }
7887
7930
  };
7888
- var listNames = async (runtime, context, kind, project2, label) => {
7931
+ var listNames = async (runtime, context, kind, project2) => {
7889
7932
  const field2 = kind === "container" ? "Names" : "Name";
7890
7933
  const output = await docker(runtime, context, [
7891
7934
  kind,
7892
7935
  "ls",
7893
7936
  ...kind === "container" ? ["--all"] : [],
7894
- ...project2 === void 0 ? [] : ["--filter", `label=com.docker.compose.project=${project2}`],
7895
- ...label === void 0 ? [] : ["--filter", `label=${label}`],
7937
+ ...project2 === void 0 ? [] : ["--filter", `label=${COMPOSE_PROJECT_LABEL}=${project2}`],
7896
7938
  "--format",
7897
7939
  `{{json .${field2}}}`
7898
7940
  ]);
@@ -7958,80 +8000,200 @@ var reservedResourceName = (name, kind, namespace) => {
7958
8000
  })
7959
8001
  );
7960
8002
  };
7961
- var inspectForeignProject = async (runtime, context, kind, name, project2) => {
8003
+ var GENERATION_DIRECTORY = /\/generations\/gen-[0-9a-f-]{36}$/;
8004
+ var bundleComposeVolumes = (project2) => new Set(
8005
+ [
8006
+ "mend-config",
8007
+ "mend-ssh",
8008
+ "mend-postgres",
8009
+ "mend-edge-data",
8010
+ "mend-edge-config",
8011
+ "mend-npm-mirror",
8012
+ "mend-docker-mirror",
8013
+ T3_GATEWAY_VOLUME
8014
+ ].map((volume) => `${project2}_${volume}`)
8015
+ );
8016
+ var bundleNetworks = (project2) => new Set(["default", "edge"].map((network) => `${project2}_${network}`));
8017
+ var INSPECT_FORMAT = {
8018
+ volume: "{{json .}}",
8019
+ container: '{"Name":{{json .Name}},"Labels":{{json .Config.Labels}},"Running":{{json .State.Running}}}',
8020
+ network: '{"Name":{{json .Name}},"Labels":{{json .Labels}},"Containers":{{json .Containers}}}'
8021
+ };
8022
+ var inspectResource = async (runtime, context, kind, name) => {
7962
8023
  const output = await docker(runtime, context, [
7963
8024
  kind,
7964
8025
  "inspect",
7965
8026
  name,
7966
8027
  "--format",
7967
- `{"Name":{{json .Name}},"Labels":{{json .${kind === "container" ? "Config.Labels" : "Labels"}}}}`
8028
+ INSPECT_FORMAT[kind]
7968
8029
  ]);
7969
8030
  if (output._tag === "error") return output;
7970
8031
  try {
7971
8032
  const resource = JSON.parse(output.value);
7972
8033
  if (typeof resource !== "object" || resource === null || !("Name" in resource) || resource.Name !== (kind === "container" ? `/${name}` : name) || !("Labels" in resource))
7973
8034
  return fail5("inspection", `${kind} inspect`);
7974
- const labels = resource.Labels;
7975
- if (labels === null) return fail5("unowned-data", `existing ${kind} without anchor`);
7976
- if (typeof labels !== "object" || Array.isArray(labels) || !Object.values(labels).every((value) => typeof value === "string"))
7977
- return fail5("inspection", `${kind} labels`);
7978
- if (!("com.docker.compose.project" in labels))
7979
- return fail5("unowned-data", `existing ${kind} without anchor`);
7980
- const foreignProject = labels["com.docker.compose.project"];
7981
- if (typeof foreignProject !== "string" || !/^[a-z0-9][a-z0-9_-]*$/.test(foreignProject))
7982
- return fail5("inspection", `${kind} project label`);
7983
- if (foreignProject === project2 || !inProjectNamespace(name, foreignProject))
7984
- return fail5("unowned-data", `existing ${kind} without anchor`);
7985
- return { _tag: "ok", value: void 0 };
8035
+ const found = resource.Labels;
8036
+ let labels = null;
8037
+ if (found !== null) {
8038
+ if (typeof found !== "object" || Array.isArray(found))
8039
+ return fail5("inspection", `${kind} labels`);
8040
+ labels = {};
8041
+ for (const [key, value] of Object.entries(found)) {
8042
+ if (typeof value !== "string") return fail5("inspection", `${kind} labels`);
8043
+ labels[key] = value;
8044
+ }
8045
+ }
8046
+ let running = false;
8047
+ if (kind === "container") {
8048
+ if (!("Running" in resource) || typeof resource.Running !== "boolean")
8049
+ return fail5("inspection", "container state");
8050
+ running = resource.Running;
8051
+ }
8052
+ const attached = [];
8053
+ if (kind === "network") {
8054
+ const containers = "Containers" in resource ? resource.Containers : void 0;
8055
+ if (containers === void 0 || typeof containers !== "object" || Array.isArray(containers))
8056
+ return fail5("inspection", "network containers");
8057
+ for (const [id, endpoint] of Object.entries(containers ?? {})) {
8058
+ const endpointName = typeof endpoint === "object" && endpoint !== null && "Name" in endpoint ? endpoint.Name : void 0;
8059
+ attached.push(typeof endpointName === "string" ? endpointName : id.slice(0, 12));
8060
+ }
8061
+ }
8062
+ return { _tag: "ok", value: { labels, running, attached } };
7986
8063
  } catch {
7987
8064
  return fail5("inspection", `${kind} inspect`);
7988
8065
  }
7989
8066
  };
8067
+ var notMendsWhy = (labels, kind, project2) => {
8068
+ if (labels === null || Object.keys(labels).length === 0) return "carries no labels";
8069
+ const owner = labels[COMPOSE_PROJECT_LABEL];
8070
+ if (owner === void 0)
8071
+ return kind === "volume" ? "carries no Mend label" : "carries no Compose project label";
8072
+ if (owner !== project2) return `belongs to Compose project ${owner}`;
8073
+ return kind === "container" ? `carries Compose project label ${project2}, but no Mend install started it` : `carries Compose project label ${project2}, but no Mend install makes a ${kind} by that name`;
8074
+ };
8075
+ var findOldData = async (runtime, context, namespace, volumes) => {
8076
+ const project2 = namespace.project;
8077
+ const left = { container: [], network: [], volume: [] };
8078
+ const inTheWay = [];
8079
+ const refuse = (kind, name, mend, why) => {
8080
+ inTheWay.push({ dockerContext: context, kind, name, mend, why });
8081
+ };
8082
+ const projectVolumes = await listNames(runtime, context, "volume", project2);
8083
+ if (projectVolumes._tag === "error") return projectVolumes;
8084
+ const bundleVolumes = bundleComposeVolumes(project2);
8085
+ const candidates = /* @__PURE__ */ new Set([
8086
+ ...volumes.filter(
8087
+ (name) => secondaryVolumesOf(namespace).includes(name) || name.startsWith(`${project2}_`)
8088
+ ),
8089
+ ...projectVolumes.value
8090
+ ]);
8091
+ for (const name of candidates) {
8092
+ const inspected = await inspectResource(runtime, context, "volume", name);
8093
+ if (inspected._tag === "error") return inspected;
8094
+ const { labels } = inspected.value;
8095
+ if (labels?.[SERVER_VOLUME_OWNER_LABEL] !== void 0 || labels?.[COMPOSE_PROJECT_LABEL] === project2 && bundleVolumes.has(name))
8096
+ left.volume.push(name);
8097
+ else refuse("volume", name, false, notMendsWhy(labels, "volume", project2));
8098
+ }
8099
+ const networks = bundleNetworks(project2);
8100
+ for (const kind of ["container", "network"]) {
8101
+ const labelled = await listNames(runtime, context, kind, project2);
8102
+ if (labelled._tag === "error") return labelled;
8103
+ for (const name of labelled.value) {
8104
+ const inspected = await inspectResource(runtime, context, kind, name);
8105
+ if (inspected._tag === "error") return inspected;
8106
+ const { labels, running, attached } = inspected.value;
8107
+ if (kind === "container") {
8108
+ if (!GENERATION_DIRECTORY.test(labels?.[COMPOSE_WORKING_DIR_LABEL] ?? ""))
8109
+ refuse(kind, name, false, notMendsWhy(labels, kind, project2));
8110
+ else if (running) refuse(kind, name, true, "it is running");
8111
+ else left.container.push(name);
8112
+ } else if (!networks.has(name)) refuse(kind, name, false, notMendsWhy(labels, kind, project2));
8113
+ else if (attached.length > 0)
8114
+ refuse(
8115
+ kind,
8116
+ name,
8117
+ true,
8118
+ `${namedAs("container", attached).join("")} ${attached.length === 1 ? "is" : "are"} attached to it`
8119
+ );
8120
+ else left.network.push(name);
8121
+ }
8122
+ const named = await listNames(runtime, context, kind);
8123
+ if (named._tag === "error") return named;
8124
+ for (const name of named.value) {
8125
+ if (labelled.value.includes(name)) continue;
8126
+ const reserved = reservedResourceName(name, kind, namespace);
8127
+ if (!reserved && !name.startsWith(`${project2}_`) && !name.startsWith(`${project2}-`)) continue;
8128
+ const inspected = await inspectResource(runtime, context, kind, name);
8129
+ if (inspected._tag === "error") return inspected;
8130
+ const { labels } = inspected.value;
8131
+ const owner = labels?.[COMPOSE_PROJECT_LABEL];
8132
+ if (owner !== void 0 && !/^[a-z0-9][a-z0-9_-]*$/.test(owner))
8133
+ return fail5("inspection", `${kind} project label`);
8134
+ if (reserved || owner === void 0 || owner === project2 || !inProjectNamespace(name, owner))
8135
+ refuse(kind, name, false, notMendsWhy(labels, kind, project2));
8136
+ }
8137
+ }
8138
+ const leftovers = left.container.length + left.network.length + left.volume.length === 0 ? null : {
8139
+ dockerContext: context,
8140
+ containers: left.container,
8141
+ networks: left.network,
8142
+ volumes: left.volume
8143
+ };
8144
+ const [first, ...more] = inTheWay;
8145
+ if (first !== void 0)
8146
+ return { _tag: "ok", value: { _tag: "in-the-way", inTheWay: [first, ...more], leftovers } };
8147
+ return { _tag: "ok", value: leftovers === null ? null : { _tag: "leftovers", leftovers } };
8148
+ };
7990
8149
  var refuseOldData = async (runtime, context, namespace, volumes) => {
7991
- const refused = await findOldData(runtime, context, namespace, volumes);
7992
- if (refused._tag === "ok" || refused.error.reason !== "unowned-data") return refused;
7993
- const labelled = await listNames(
7994
- runtime,
7995
- context,
7996
- "volume",
7997
- void 0,
7998
- SERVER_VOLUME_OWNER_LABEL
7999
- );
8000
- if (labelled._tag === "error" || labelled.value.length === 0) return refused;
8150
+ const found = await findOldData(runtime, context, namespace, volumes);
8151
+ if (found._tag === "error") return found;
8152
+ if (found.value === null) return { _tag: "ok", value: void 0 };
8001
8153
  return {
8002
8154
  _tag: "error",
8003
- error: new ServerVolumeOwnershipError(refused.error.reason, refused.error.operation, true)
8155
+ error: new ServerVolumeOwnershipError(
8156
+ "unowned-data",
8157
+ found.value._tag === "leftovers" ? "leftovers without anchor" : `existing ${found.value.inTheWay[0].kind} without anchor`,
8158
+ found.value
8159
+ )
8004
8160
  };
8005
8161
  };
8006
- var findOldData = async (runtime, context, namespace, volumes) => {
8007
- if (volumes.some(
8008
- (name) => secondaryVolumesOf(namespace).includes(name) || name.startsWith(`${namespace.project}_`)
8009
- ))
8010
- return fail5("unowned-data", "existing volumes without anchor");
8011
- for (const kind of ["volume", "container", "network"]) {
8012
- const labelled = await listNames(runtime, context, kind, namespace.project);
8013
- if (labelled._tag === "error") return labelled;
8014
- if (labelled.value.length > 0) return fail5("unowned-data", `existing ${kind} without anchor`);
8015
- if (kind !== "volume") {
8016
- const named = await listNames(runtime, context, kind);
8017
- if (named._tag === "error") return named;
8018
- for (const name of named.value) {
8019
- if (reservedResourceName(name, kind, namespace))
8020
- return fail5("unowned-data", `existing ${kind} without anchor`);
8021
- if (name.startsWith(`${namespace.project}_`) || name.startsWith(`${namespace.project}-`)) {
8022
- const foreign = await inspectForeignProject(
8023
- runtime,
8024
- context,
8025
- kind,
8026
- name,
8027
- namespace.project
8162
+ var findServerOldData = async (runtime, dockerContext, namespace = MEND_DOCKER_NAMESPACE_WITH_GARAGE) => {
8163
+ const volumes = await listNames(runtime, dockerContext, "volume");
8164
+ if (volumes._tag === "error") return volumes;
8165
+ if (volumes.value.includes(namespace.store)) return { _tag: "ok", value: null };
8166
+ return findOldData(runtime, dockerContext, namespace, volumes.value);
8167
+ };
8168
+ var removeServerLeftovers = async (runtime, leftovers, write) => {
8169
+ const failures = [];
8170
+ const context = leftovers.dockerContext;
8171
+ const kinds = [
8172
+ ["container", leftovers.containers],
8173
+ ["network", leftovers.networks],
8174
+ ["volume", leftovers.volumes]
8175
+ ];
8176
+ for (const [kind, names] of kinds) {
8177
+ const removed = [];
8178
+ for (const name of names) {
8179
+ const args = kind === "container" ? ["container", "rm", "-v", name] : [kind, "rm", name];
8180
+ try {
8181
+ const output = await runtime.run("docker", ["--context", context, ...args]);
8182
+ if (output.status === 0 && output.error === void 0) removed.push(name);
8183
+ else
8184
+ failures.push(
8185
+ `could not remove ${kind} ${name}: ${(output.error ?? output.stderr.trim()) || "no output"}`
8028
8186
  );
8029
- if (foreign._tag === "error") return foreign;
8030
- }
8187
+ } catch (cause) {
8188
+ failures.push(
8189
+ `could not remove ${kind} ${name}: ${cause instanceof Error ? cause.message : String(cause)}`
8190
+ );
8031
8191
  }
8032
8192
  }
8193
+ if (removed.length > 0)
8194
+ write(`removed ${kind}${removed.length === 1 ? "" : "s"} ${removed.join(", ")}`);
8033
8195
  }
8034
- return { _tag: "ok", value: void 0 };
8196
+ return failures;
8035
8197
  };
8036
8198
  var serverVolumeOwner = (identityBytes) => createHash2("sha256").update(identityBytes).digest("hex");
8037
8199
  var parseOwnershipInput = (input) => {
@@ -8372,6 +8534,27 @@ var chooseDockerEngine = async (io, engines, preferred) => {
8372
8534
  throw cause;
8373
8535
  }
8374
8536
  };
8537
+ var offerLeftoverRemoval = async (io, leftovers) => {
8538
+ const count = leftovers.containers.length + leftovers.networks.length + leftovers.volumes.length;
8539
+ const them = count === 1 ? "it" : "them";
8540
+ io.write("");
8541
+ io.write(
8542
+ `Docker context ${leftovers.dockerContext} holds what an earlier Mend install left, and no installation owns ${them}:`
8543
+ );
8544
+ for (const item of leftoverItems(leftovers)) io.write(` ${item}`);
8545
+ const volumes = leftovers.volumes.length;
8546
+ if (volumes > 0)
8547
+ io.write(
8548
+ `The ${volumes === 1 ? "volume" : "volumes"} may hold that install's data (its database, repositories and captures). Removing ${volumes === 1 ? "it" : "them"} deletes that data for good. ${KEEP_THE_DATA}`
8549
+ );
8550
+ io.write(`Setup does not install beside ${them}.`);
8551
+ try {
8552
+ return await yesNo(io, `Remove ${them} now?`, false);
8553
+ } catch (cause) {
8554
+ if (cause instanceof GuideStopped) return null;
8555
+ throw cause;
8556
+ }
8557
+ };
8375
8558
  var reachModeOf = (settings) => settings.edgeHost !== void 0 ? "public" : isLoopbackAddress(settings.bind) ? "machine" : "network";
8376
8559
  var without = (declared, item) => declared.filter((entry) => entry !== item);
8377
8560
  var withItem = (declared, item) => declared.includes(item) ? declared : [...declared, item];
@@ -9819,7 +10002,7 @@ var envValue = (fields, key) => {
9819
10002
  }
9820
10003
  return value;
9821
10004
  };
9822
- var parseSecrets = (raw) => {
10005
+ var envFields = (raw) => {
9823
10006
  const fields = /* @__PURE__ */ new Map();
9824
10007
  for (const line of raw.split("\n")) {
9825
10008
  if (line === "") continue;
@@ -9831,6 +10014,10 @@ var parseSecrets = (raw) => {
9831
10014
  throw setupError(`Server secrets are corrupt: ${key} appears more than once.`);
9832
10015
  fields.set(key, line.slice(separator + 1));
9833
10016
  }
10017
+ return fields;
10018
+ };
10019
+ var parseSecrets = (raw) => {
10020
+ const fields = envFields(raw);
9834
10021
  const secrets = {
9835
10022
  postgresAdminPassword: envValue(fields, "MEND_POSTGRES_ADMIN_PASSWORD"),
9836
10023
  mendDatabasePassword: envValue(fields, "MEND_DB_PASSWORD"),
@@ -10298,16 +10485,15 @@ var edgeImageOf = (overlay) => {
10298
10485
  throw setupError("Server generation is corrupt: compose.edge.yaml pins no Caddy image.");
10299
10486
  return image;
10300
10487
  };
10301
- var validateOverlays = (config, files) => {
10302
- const posture = renderPostureOverlay(config);
10303
- if (posture === void 0 !== (files.posture === void 0)) {
10488
+ var validateOverlays = (config, files, envKeys) => {
10489
+ const posture = postureEnvironment(config).map(([key]) => key).filter((key) => envKeys.has(key));
10490
+ if (posture.length === 0 !== (files.posture === void 0)) {
10304
10491
  throw setupError(
10305
10492
  "Server generation is corrupt: compose.posture.yaml does not match the persisted server config."
10306
10493
  );
10307
10494
  }
10308
- for (const line of postureEnvLines(config)) {
10309
- const key = line.slice(0, line.indexOf("="));
10310
- if (key !== "MEND_EDGE_HOST" && !key.startsWith("MEND_T3_GATEWAY_") && !(files.posture ?? "").includes(` ${key}: \${${key}`)) {
10495
+ for (const key of posture) {
10496
+ if (!(files.posture ?? "").includes(` ${key}: \${${key}`)) {
10311
10497
  throw setupError(
10312
10498
  `Server generation is corrupt: compose.posture.yaml does not hand ${key} to Mend.`
10313
10499
  );
@@ -10384,20 +10570,56 @@ var validateMirrors = (config, secrets, files) => {
10384
10570
  );
10385
10571
  return mirrorImagesOf(files.mirrors);
10386
10572
  };
10573
+ var FOUNDING_ENV_KEYS = /* @__PURE__ */ new Set([
10574
+ "MEND_VERSION",
10575
+ "MEND_IMAGE_REPOSITORY",
10576
+ "APP_URL",
10577
+ "MEND_ALLOWED_ORIGINS",
10578
+ "MEND_BIND_HOST",
10579
+ "MEND_PORT",
10580
+ "MEND_SSH_PORT",
10581
+ "MEND_REGISTRY_PORT",
10582
+ "SEALANT_SSH_HOST",
10583
+ "MEND_STORE_VOLUME_NAME",
10584
+ "MEND_CONTROL_VOLUME_NAME",
10585
+ "DOCKER_SOCKET_PATH"
10586
+ ]);
10587
+ var secretEnvKey = (key) => key.startsWith("MEND_GARAGE_") || key.startsWith("MEND_DOCKER_HUB_");
10588
+ var validateServerEnv = (env, secrets, config) => {
10589
+ const rendered = envFields(renderSecrets(secrets, config));
10590
+ const written = envFields(env);
10591
+ for (const [key, value] of written) {
10592
+ const expected = rendered.get(key);
10593
+ if (expected === void 0)
10594
+ throw setupError(
10595
+ `Server secrets are corrupt: server.env has ${key}, which the persisted server config does not account for.`
10596
+ );
10597
+ if (value !== expected)
10598
+ throw setupError(
10599
+ `Server secrets are corrupt: ${key} in server.env does not match the persisted server config and identity.`
10600
+ );
10601
+ }
10602
+ for (const key of rendered.keys()) {
10603
+ if (!written.has(key) && (FOUNDING_ENV_KEYS.has(key) || secretEnvKey(key)))
10604
+ throw setupError(`Server secrets are corrupt: ${key} is missing from server.env.`);
10605
+ }
10606
+ return new Set(written.keys());
10607
+ };
10387
10608
  var readServerInstallation = (store) => {
10388
10609
  try {
10389
10610
  const generation = storeValue(store.readActive());
10390
10611
  if (generation === null) return { _tag: "ok", value: null };
10391
10612
  const config = parseServerConfig(generation.files.config);
10392
10613
  const secrets = parseSecrets(generation.files.env);
10393
- if (generation.files.env !== renderSecrets(secrets, config) || generation.files.identity !== renderIdentity(secrets)) {
10614
+ if (generation.files.identity !== renderIdentity(secrets)) {
10394
10615
  throw setupError(
10395
10616
  "Server secrets are corrupt: server.env does not match the persisted server config and identity."
10396
10617
  );
10397
10618
  }
10619
+ const envKeys = validateServerEnv(generation.files.env, secrets, config);
10398
10620
  validateComposeAsset(generation.files.compose);
10399
10621
  validatePostgresAsset(generation.files.postgresInit);
10400
- const edgeImage = validateOverlays(config, generation.files);
10622
+ const edgeImage = validateOverlays(config, generation.files, envKeys);
10401
10623
  const mirrorImages = validateMirrors(config, secrets, generation.files);
10402
10624
  return {
10403
10625
  _tag: "ok",
@@ -11167,6 +11389,27 @@ var settleDockerEngine = async (runtime, io) => {
11167
11389
  const picked = await chooseDockerEngine(io, observed.engines, preferred);
11168
11390
  return picked === null ? null : ["--context", picked];
11169
11391
  };
11392
+ var settleLeftovers = async (runtime, io, dockerContext) => {
11393
+ const found = await findServerOldData(runtime, dockerContext);
11394
+ if (found._tag === "error") return { _tag: "error", message: found.error.message };
11395
+ if (found.value === null) return null;
11396
+ if (found.value._tag === "in-the-way")
11397
+ return { _tag: "error", message: serverOldDataWords(found.value) };
11398
+ const leftovers = found.value.leftovers;
11399
+ const remove = await offerLeftoverRemoval(io, leftovers);
11400
+ if (remove !== true) {
11401
+ runtime.writeLine(
11402
+ remove === null ? "Nothing changed." : `Nothing changed. To remove them later: ${leftoversRemoval(dockerContext)}, then run mend server setup again.`
11403
+ );
11404
+ return { _tag: "ok" };
11405
+ }
11406
+ const failures = await removeServerLeftovers(runtime, leftovers, runtime.writeLine);
11407
+ if (failures.length === 0) return null;
11408
+ return {
11409
+ _tag: "error",
11410
+ message: `Setup stopped: ${failures.join("; ")}. Stop what uses ${failures.length === 1 ? "it" : "them"}, then run mend server setup again: it offers to remove what is left.`
11411
+ };
11412
+ };
11170
11413
  var guidedSetup = async (runtime, prompter, hostFlags2 = []) => {
11171
11414
  if (runtime.platform !== "linux" && runtime.platform !== "darwin") {
11172
11415
  throw setupError(`mend server setup supports Linux and macOS, not ${runtime.platform}.`);
@@ -11202,6 +11445,10 @@ var guidedSetup = async (runtime, prompter, hostFlags2 = []) => {
11202
11445
  io.write(
11203
11446
  `Docker: this install runs in context ${context.name} (socket ${socketOf(context.endpoint)}), where its data is, and stays there. Running Mend in another Docker engine is a new install: mend uninstall --server removes this one, its data included, then mend server setup there.`
11204
11447
  );
11448
+ if (existing === null) {
11449
+ const settled2 = await settleLeftovers(runtime, io, context.name);
11450
+ if (settled2 !== null) return settled2;
11451
+ }
11205
11452
  const reminder = await settleHostUserNamespaces(
11206
11453
  { ...runtime, prompter },
11207
11454
  hostOptions,
@@ -13810,22 +14057,8 @@ var DOCKER_SERVICE_IMAGE = "docker:27.5.1-dind-rootless";
13810
14057
  var WORKSPACE_IMAGE_REFERENCE = "sealant-workspace-*";
13811
14058
  var WORKSPACE_IMAGE_LABEL = "sh.sealant.plan-hash";
13812
14059
  var NETWORK_GUARD_IMAGE_LABEL2 = "dev.sealant.mend.network-guard-image";
13813
- var BUNDLE_COMPOSE_VOLUMES = new Set(
13814
- [
13815
- "mend-config",
13816
- "mend-ssh",
13817
- "mend-postgres",
13818
- "mend-edge-data",
13819
- "mend-edge-config",
13820
- "mend-npm-mirror",
13821
- "mend-docker-mirror",
13822
- T3_GATEWAY_VOLUME
13823
- ].map((volume) => `${MEND_DOCKER_NAMESPACE.project}_${volume}`)
13824
- );
13825
- var BUNDLE_NETWORKS = new Set(
13826
- ["default", "edge"].map((network) => `${MEND_DOCKER_NAMESPACE.project}_${network}`)
13827
- );
13828
- var GENERATION_DIRECTORY = /\/generations\/gen-[0-9a-f-]{36}$/;
14060
+ var BUNDLE_COMPOSE_VOLUMES = bundleComposeVolumes(MEND_DOCKER_NAMESPACE.project);
14061
+ var BUNDLE_NETWORKS = bundleNetworks(MEND_DOCKER_NAMESPACE.project);
13829
14062
  var HOST_HELPER_IMAGE2 = "postgres:17-alpine";
13830
14063
  var SYSCTL_DEFAULTS = {
13831
14064
  "kernel.apparmor_restrict_unprivileged_userns": "1",
@@ -14135,15 +14368,21 @@ var buildCacheSize = async (run2, context) => {
14135
14368
  }
14136
14369
  return null;
14137
14370
  };
14138
- var findLeftovers = async (run2) => {
14371
+ var findLeftovers = async (run2, owner) => {
14139
14372
  const shown = await run2("docker", ["context", "show"], { timeoutMs: DOCKER_DEADLINE_MS });
14140
14373
  const context = shown.status === 0 ? shown.stdout.trim() : "";
14141
14374
  if (!DOCKER_NAME.test(context)) return null;
14142
- const labelled = await listNamesIn(run2, context, "volume", [
14143
- `label=${SERVER_VOLUME_OWNER_LABEL}`
14144
- ]);
14145
- if ("problem" in labelled || labelled.length === 0) return null;
14146
- if (labelled.includes(MEND_DOCKER_NAMESPACE.store)) return null;
14375
+ const listed3 = await listNamesIn(run2, context, "volume", [`label=${SERVER_VOLUME_OWNER_LABEL}`]);
14376
+ if ("problem" in listed3) return null;
14377
+ const store = MEND_DOCKER_NAMESPACE.store;
14378
+ if (listed3.includes(store)) {
14379
+ const anchor = await volumeOwner(run2, context, store);
14380
+ if (owner === null || anchor.state !== "present" || anchor.owner !== owner) return null;
14381
+ }
14382
+ const labelled = [
14383
+ ...listed3.filter((name) => name !== store),
14384
+ ...listed3.filter((name) => name === store)
14385
+ ];
14147
14386
  const compose = `label=com.docker.compose.project=${MEND_DOCKER_NAMESPACE.project}`;
14148
14387
  const composeVolumes = await listNamesIn(run2, context, "volume", [compose]);
14149
14388
  const networks = await listNamesIn(run2, context, "network", [compose]);
@@ -14156,19 +14395,25 @@ var findLeftovers = async (run2) => {
14156
14395
  "--format",
14157
14396
  '{{.Names}} {{.Label "com.docker.compose.project.working_dir"}}'
14158
14397
  ]);
14159
- const holdings = labelled.includes(MEND_DOCKER_NAMESPACE.control) ? await findWorkspaces(run2, context, MEND_DOCKER_NAMESPACE.control) : NO_HOLDINGS;
14398
+ const found = labelled.includes(MEND_DOCKER_NAMESPACE.control) ? await findWorkspaces(run2, context, MEND_DOCKER_NAMESPACE.control) : NO_HOLDINGS;
14399
+ const holdings = "problem" in found ? NO_HOLDINGS : found;
14400
+ const volumes = [
14401
+ ..."problem" in composeVolumes ? [] : composeVolumes.filter((name) => BUNDLE_COMPOSE_VOLUMES.has(name)),
14402
+ ...labelled
14403
+ ];
14404
+ const bundleNetworksHere = "problem" in networks ? [] : networks.filter((name) => BUNDLE_NETWORKS.has(name));
14405
+ const containers = composed.status === 0 ? rows(composed.stdout).flatMap(
14406
+ ([name, directory]) => name !== void 0 && DOCKER_NAME.test(name) && GENERATION_DIRECTORY.test(directory ?? "") ? [name] : []
14407
+ ) : [];
14408
+ if (volumes.length === 0 && bundleNetworksHere.length === 0 && containers.length === 0 && holdings.workspaces.length === 0)
14409
+ return null;
14160
14410
  return {
14161
14411
  kind: "leftovers",
14162
14412
  dockerContext: context,
14163
- volumes: [
14164
- ...labelled,
14165
- ..."problem" in composeVolumes ? [] : composeVolumes.filter((name) => BUNDLE_COMPOSE_VOLUMES.has(name))
14166
- ],
14167
- networks: "problem" in networks ? [] : networks.filter((name) => BUNDLE_NETWORKS.has(name)),
14168
- containers: composed.status === 0 ? rows(composed.stdout).flatMap(
14169
- ([name, directory]) => name !== void 0 && DOCKER_NAME.test(name) && GENERATION_DIRECTORY.test(directory ?? "") ? [name] : []
14170
- ) : [],
14171
- holdings: "problem" in holdings ? NO_HOLDINGS : holdings
14413
+ volumes,
14414
+ networks: bundleNetworksHere,
14415
+ containers,
14416
+ holdings
14172
14417
  };
14173
14418
  };
14174
14419
  var parseUrl2 = (value) => {
@@ -14208,16 +14453,22 @@ var describeUninstall = async (runtime, scope) => {
14208
14453
  );
14209
14454
  if (read._tag === "error") {
14210
14455
  if (!read.error.message.startsWith("No Mend server is configured")) throw read.error;
14211
- server = await findLeftovers(run2) ?? "none";
14456
+ server = await findLeftovers(run2, null) ?? "none";
14212
14457
  } else if (read.value.installation === null) {
14458
+ const identity = read.value.identity;
14459
+ const leftovers = await findLeftovers(
14460
+ run2,
14461
+ identity === null ? null : serverVolumeOwner(Buffer.from(identity))
14462
+ );
14213
14463
  server = exists(path20.join(configDir, "identity.env")) ? {
14214
14464
  version: "(no active generation)",
14215
14465
  appUrl: "",
14216
14466
  dockerContext: "",
14217
14467
  edgeHost: null,
14218
14468
  generations: countEntries(path20.join(configDir, "generations")),
14219
- backups: countEntries(path20.join(configDir, "backups"))
14220
- } : await findLeftovers(run2) ?? "none";
14469
+ backups: countEntries(path20.join(configDir, "backups")),
14470
+ ...leftovers === null ? {} : { leftovers }
14471
+ } : leftovers ?? "none";
14221
14472
  } else {
14222
14473
  const { config, directory } = read.value.installation;
14223
14474
  const context = config.dockerContext;
@@ -14353,19 +14604,21 @@ var workspaceLines = (holdings, context) => {
14353
14604
  ` ${running.length === 0 ? "they are removed" : "uninstall stops them, then removes them"} with their Docker services, volumes and networks; unsaved work in them is lost`
14354
14605
  ];
14355
14606
  };
14607
+ var leftoverLines = (plan) => [
14608
+ ...plan.containers.length === 0 ? [] : [` containers ${plan.containers.join(", ")}`],
14609
+ ...plan.volumes.length === 0 ? [] : [` volumes ${plan.volumes.join(", ")}`],
14610
+ ...plan.networks.length === 0 ? [] : [` networks ${plan.networks.join(", ")}`],
14611
+ ...workspaceLines(plan.holdings, plan.dockerContext)
14612
+ ];
14356
14613
  var planLines = (plan, configDir) => {
14357
14614
  const lines = [];
14358
14615
  if (plan.server === "none") {
14359
14616
  lines.push(`server none installed under ${configDir}`);
14360
14617
  } else if (isLeftovers(plan.server)) {
14361
- const { dockerContext, volumes, networks, containers, holdings } = plan.server;
14362
14618
  lines.push(
14363
- `server none configured under ${configDir}, but docker context ${dockerContext} holds what an earlier Mend install left:`
14619
+ `server none configured under ${configDir}, but docker context ${plan.server.dockerContext} holds what an earlier Mend install left:`
14364
14620
  );
14365
- if (containers.length > 0) lines.push(` containers ${containers.join(", ")}`);
14366
- lines.push(` volumes ${volumes.join(", ")}`);
14367
- if (networks.length > 0) lines.push(` networks ${networks.join(", ")}`);
14368
- lines.push(...workspaceLines(holdings, dockerContext));
14621
+ lines.push(...leftoverLines(plan.server));
14369
14622
  } else if (plan.server !== null) {
14370
14623
  const { version, appUrl, dockerContext, edgeHost, generations, backups } = plan.server;
14371
14624
  lines.push(
@@ -14387,6 +14640,13 @@ var planLines = (plan, configDir) => {
14387
14640
  lines.push(
14388
14641
  ` ${configDir}: identity.env, active, ${plural(generations, "generation")}, ${plural(backups, "backup")}`
14389
14642
  );
14643
+ const leftovers = plan.server.leftovers;
14644
+ if (leftovers !== void 0) {
14645
+ lines.push(
14646
+ ` and on docker context ${leftovers.dockerContext}, what that setup or an earlier install left:`
14647
+ );
14648
+ lines.push(...leftoverLines(leftovers));
14649
+ }
14390
14650
  lines.push(...workspaceLines(plan.server.holdings ?? NO_HOLDINGS, dockerContext));
14391
14651
  const left = plan.server.leftByEarlier ?? [];
14392
14652
  if (left.length > 0)
@@ -14670,6 +14930,13 @@ var removeServer = async (runtime, plan, report) => {
14670
14930
  outcome = "partial";
14671
14931
  return;
14672
14932
  }
14933
+ } else if (plan.leftovers !== void 0) {
14934
+ const kept = await removeLeftovers(runtime, plan.leftovers, report);
14935
+ if (kept.length > 0) {
14936
+ report.remaining.push(configDir);
14937
+ outcome = "partial";
14938
+ return;
14939
+ }
14673
14940
  }
14674
14941
  for (const name of [...SERVER_FILES, LEFT_FILE]) {
14675
14942
  fs20.rmSync(path20.join(configDir, name), { recursive: true, force: true });
@@ -14708,8 +14975,23 @@ var removeLeftovers = async (runtime, plan, report) => {
14708
14975
  const volume = await volumeOwner(run2, context, name);
14709
14976
  if (volume.state === "present" && volume.owner !== null) volumes.push(name);
14710
14977
  }
14711
- left.push(...await removeEach(run2, context, "volume", volumes, report));
14978
+ const store = MEND_DOCKER_NAMESPACE.store;
14979
+ left.push(
14980
+ ...await removeEach(
14981
+ run2,
14982
+ context,
14983
+ "volume",
14984
+ volumes.filter((name) => name !== store),
14985
+ report
14986
+ )
14987
+ );
14988
+ if (volumes.includes(store)) {
14989
+ if (left.length === 0)
14990
+ left.push(...await removeEach(run2, context, "volume", [store], report));
14991
+ else left.push(store);
14992
+ }
14712
14993
  if (left.length > 0) report.remaining.push(...left);
14994
+ return left;
14713
14995
  };
14714
14996
  var removeHostExtras = async (runtime, context, extras, report) => {
14715
14997
  const run2 = runtime.server.run;