@sealant/mend 0.36.0-next.783 → 0.36.0-next.786

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 (94) hide show
  1. package/dist/{chunk-NSHXPJLT.js → chunk-SR67W2OC.js} +3 -2
  2. package/dist/{dashboard-KZHIOJEX.js → dashboard-IHWNKW2E.js} +1 -1
  3. package/dist/main.js +347 -104
  4. package/man/mend-accounts.1 +1 -1
  5. package/man/mend-adopt.1 +1 -1
  6. package/man/mend-attach.1 +1 -1
  7. package/man/mend-codex.1 +1 -1
  8. package/man/mend-completions.1 +1 -1
  9. package/man/mend-connect-pi.1 +1 -1
  10. package/man/mend-connect.1 +1 -1
  11. package/man/mend-continue.1 +1 -1
  12. package/man/mend-doctor.1 +1 -1
  13. package/man/mend-dotfiles-repo.1 +1 -1
  14. package/man/mend-dotfiles-sync.1 +1 -1
  15. package/man/mend-dotfiles.1 +1 -1
  16. package/man/mend-env-cluster.1 +1 -1
  17. package/man/mend-env-load.1 +1 -1
  18. package/man/mend-env-show.1 +1 -1
  19. package/man/mend-folder-create.1 +1 -1
  20. package/man/mend-folder-list.1 +1 -1
  21. package/man/mend-folder-push.1 +1 -1
  22. package/man/mend-folder-rm.1 +1 -1
  23. package/man/mend-git-author.1 +1 -1
  24. package/man/mend-help.1 +1 -1
  25. package/man/mend-invite.1 +1 -1
  26. package/man/mend-keys-init.1 +1 -1
  27. package/man/mend-keys-mode.1 +1 -1
  28. package/man/mend-keys-share.1 +1 -1
  29. package/man/mend-keys-show.1 +1 -1
  30. package/man/mend-land.1 +1 -1
  31. package/man/mend-login.1 +1 -1
  32. package/man/mend-logout.1 +1 -1
  33. package/man/mend-logs.1 +1 -1
  34. package/man/mend-man.1 +1 -1
  35. package/man/mend-members.1 +1 -1
  36. package/man/mend-memory-import.1 +1 -1
  37. package/man/mend-memory-rm.1 +1 -1
  38. package/man/mend-memory-show.1 +1 -1
  39. package/man/mend-memory.1 +1 -1
  40. package/man/mend-models.1 +1 -1
  41. package/man/mend-operator-exposure.1 +1 -1
  42. package/man/mend-operator-gate.1 +1 -1
  43. package/man/mend-operator-grant-owner.1 +1 -1
  44. package/man/mend-operator-org-create.1 +1 -1
  45. package/man/mend-operator-org-invite-owner.1 +1 -1
  46. package/man/mend-operator-org-list.1 +1 -1
  47. package/man/mend-operator-org-rename.1 +1 -1
  48. package/man/mend-operator-reset-link.1 +1 -1
  49. package/man/mend-pair.1 +1 -1
  50. package/man/mend-projects.1 +1 -1
  51. package/man/mend-pull.1 +1 -1
  52. package/man/mend-refresh.1 +1 -1
  53. package/man/mend-rejoin.1 +1 -1
  54. package/man/mend-resume.1 +1 -1
  55. package/man/mend-run.1 +1 -1
  56. package/man/mend-secrets-add.1 +1 -1
  57. package/man/mend-secrets-rm.1 +1 -1
  58. package/man/mend-secrets.1 +1 -1
  59. package/man/mend-server-logs.1 +1 -1
  60. package/man/mend-server-restart.1 +1 -1
  61. package/man/mend-server-setup.1 +1 -1
  62. package/man/mend-server-start.1 +1 -1
  63. package/man/mend-server-status.1 +1 -1
  64. package/man/mend-server-stop.1 +1 -1
  65. package/man/mend-server-upgrade.1 +1 -1
  66. package/man/mend-server.1 +1 -1
  67. package/man/mend-service-add.1 +1 -1
  68. package/man/mend-service-connect.1 +1 -1
  69. package/man/mend-service-init.1 +1 -1
  70. package/man/mend-service-list.1 +1 -1
  71. package/man/mend-service-logs.1 +1 -1
  72. package/man/mend-service-restart.1 +1 -1
  73. package/man/mend-service-run.1 +1 -1
  74. package/man/mend-service-stop.1 +1 -1
  75. package/man/mend-session-share.1 +1 -1
  76. package/man/mend-sessions.1 +1 -1
  77. package/man/mend-shell.1 +1 -1
  78. package/man/mend-skills-push.1 +1 -1
  79. package/man/mend-skills.1 +1 -1
  80. package/man/mend-snake.1 +1 -1
  81. package/man/mend-ssh-keys-remove.1 +1 -1
  82. package/man/mend-ssh-keys.1 +1 -1
  83. package/man/mend-ssh-setup.1 +1 -1
  84. package/man/mend-ssh.1 +1 -1
  85. package/man/mend-stop.1 +1 -1
  86. package/man/mend-ui.1 +1 -1
  87. package/man/mend-uninstall.1 +1 -1
  88. package/man/mend-version.1 +1 -1
  89. package/man/mend-wait.1 +1 -1
  90. package/man/mend-workspace-replace.1 +1 -1
  91. package/man/mend-worktrees-rm.1 +1 -1
  92. package/man/mend-worktrees.1 +1 -1
  93. package/man/mend.1 +1 -1
  94. package/package.json +2 -2
@@ -28884,8 +28884,9 @@ var SessionProcess = class extends Schema_exports.Class("SessionProcess")({
28884
28884
  /**
28885
28885
  * The Mend account whose Linux user the process runs as in a person-layout executor
28886
28886
  * (docs/adr/0016, decision 1: "the person a process runs as is recorded on the process when it
28887
- * starts"). Null for a process that runs as root (a `shared` executor), on rows from before it
28888
- * was recorded, and where older servers omit it.
28887
+ * starts"). An observed agent (`agent-external`): the person whose saved directory its
28888
+ * transcript is in. Null for a process that runs as root (a `shared` executor), on rows from
28889
+ * before it was recorded, and where older servers omit it.
28889
28890
  */
28890
28891
  runsAs: Schema_exports.NullOr(Schema_exports.String).pipe(
28891
28892
  Schema_exports.withDecodingDefaultKey(Effect_exports.succeed(null)),
@@ -29,7 +29,7 @@ import {
29
29
  workspaceReadsOf,
30
30
  worktreeJoinLine,
31
31
  wrapWords
32
- } from "./chunk-NSHXPJLT.js";
32
+ } from "./chunk-SR67W2OC.js";
33
33
 
34
34
  // src/dashboard.tsx
35
35
  import { CliRenderEvents, createCliRenderer } from "@opentui/core";
package/dist/main.js CHANGED
@@ -80,7 +80,7 @@ import {
80
80
  workspaceRetirementLine,
81
81
  worktreeJoinLine,
82
82
  worktreeListsPeople
83
- } from "./chunk-NSHXPJLT.js";
83
+ } from "./chunk-SR67W2OC.js";
84
84
 
85
85
  // src/main.ts
86
86
  import { spawn as spawn3, spawnSync as spawnSync7 } from "node:child_process";
@@ -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];
@@ -11206,6 +11389,27 @@ var settleDockerEngine = async (runtime, io) => {
11206
11389
  const picked = await chooseDockerEngine(io, observed.engines, preferred);
11207
11390
  return picked === null ? null : ["--context", picked];
11208
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
+ };
11209
11413
  var guidedSetup = async (runtime, prompter, hostFlags2 = []) => {
11210
11414
  if (runtime.platform !== "linux" && runtime.platform !== "darwin") {
11211
11415
  throw setupError(`mend server setup supports Linux and macOS, not ${runtime.platform}.`);
@@ -11241,6 +11445,10 @@ var guidedSetup = async (runtime, prompter, hostFlags2 = []) => {
11241
11445
  io.write(
11242
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.`
11243
11447
  );
11448
+ if (existing === null) {
11449
+ const settled2 = await settleLeftovers(runtime, io, context.name);
11450
+ if (settled2 !== null) return settled2;
11451
+ }
11244
11452
  const reminder = await settleHostUserNamespaces(
11245
11453
  { ...runtime, prompter },
11246
11454
  hostOptions,
@@ -13849,22 +14057,8 @@ var DOCKER_SERVICE_IMAGE = "docker:27.5.1-dind-rootless";
13849
14057
  var WORKSPACE_IMAGE_REFERENCE = "sealant-workspace-*";
13850
14058
  var WORKSPACE_IMAGE_LABEL = "sh.sealant.plan-hash";
13851
14059
  var NETWORK_GUARD_IMAGE_LABEL2 = "dev.sealant.mend.network-guard-image";
13852
- var BUNDLE_COMPOSE_VOLUMES = new Set(
13853
- [
13854
- "mend-config",
13855
- "mend-ssh",
13856
- "mend-postgres",
13857
- "mend-edge-data",
13858
- "mend-edge-config",
13859
- "mend-npm-mirror",
13860
- "mend-docker-mirror",
13861
- T3_GATEWAY_VOLUME
13862
- ].map((volume) => `${MEND_DOCKER_NAMESPACE.project}_${volume}`)
13863
- );
13864
- var BUNDLE_NETWORKS = new Set(
13865
- ["default", "edge"].map((network) => `${MEND_DOCKER_NAMESPACE.project}_${network}`)
13866
- );
13867
- 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);
13868
14062
  var HOST_HELPER_IMAGE2 = "postgres:17-alpine";
13869
14063
  var SYSCTL_DEFAULTS = {
13870
14064
  "kernel.apparmor_restrict_unprivileged_userns": "1",
@@ -14174,15 +14368,21 @@ var buildCacheSize = async (run2, context) => {
14174
14368
  }
14175
14369
  return null;
14176
14370
  };
14177
- var findLeftovers = async (run2) => {
14371
+ var findLeftovers = async (run2, owner) => {
14178
14372
  const shown = await run2("docker", ["context", "show"], { timeoutMs: DOCKER_DEADLINE_MS });
14179
14373
  const context = shown.status === 0 ? shown.stdout.trim() : "";
14180
14374
  if (!DOCKER_NAME.test(context)) return null;
14181
- const labelled = await listNamesIn(run2, context, "volume", [
14182
- `label=${SERVER_VOLUME_OWNER_LABEL}`
14183
- ]);
14184
- if ("problem" in labelled || labelled.length === 0) return null;
14185
- 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
+ ];
14186
14386
  const compose = `label=com.docker.compose.project=${MEND_DOCKER_NAMESPACE.project}`;
14187
14387
  const composeVolumes = await listNamesIn(run2, context, "volume", [compose]);
14188
14388
  const networks = await listNamesIn(run2, context, "network", [compose]);
@@ -14195,19 +14395,25 @@ var findLeftovers = async (run2) => {
14195
14395
  "--format",
14196
14396
  '{{.Names}} {{.Label "com.docker.compose.project.working_dir"}}'
14197
14397
  ]);
14198
- 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;
14199
14410
  return {
14200
14411
  kind: "leftovers",
14201
14412
  dockerContext: context,
14202
- volumes: [
14203
- ...labelled,
14204
- ..."problem" in composeVolumes ? [] : composeVolumes.filter((name) => BUNDLE_COMPOSE_VOLUMES.has(name))
14205
- ],
14206
- networks: "problem" in networks ? [] : networks.filter((name) => BUNDLE_NETWORKS.has(name)),
14207
- containers: composed.status === 0 ? rows(composed.stdout).flatMap(
14208
- ([name, directory]) => name !== void 0 && DOCKER_NAME.test(name) && GENERATION_DIRECTORY.test(directory ?? "") ? [name] : []
14209
- ) : [],
14210
- holdings: "problem" in holdings ? NO_HOLDINGS : holdings
14413
+ volumes,
14414
+ networks: bundleNetworksHere,
14415
+ containers,
14416
+ holdings
14211
14417
  };
14212
14418
  };
14213
14419
  var parseUrl2 = (value) => {
@@ -14247,16 +14453,22 @@ var describeUninstall = async (runtime, scope) => {
14247
14453
  );
14248
14454
  if (read._tag === "error") {
14249
14455
  if (!read.error.message.startsWith("No Mend server is configured")) throw read.error;
14250
- server = await findLeftovers(run2) ?? "none";
14456
+ server = await findLeftovers(run2, null) ?? "none";
14251
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
+ );
14252
14463
  server = exists(path20.join(configDir, "identity.env")) ? {
14253
14464
  version: "(no active generation)",
14254
14465
  appUrl: "",
14255
14466
  dockerContext: "",
14256
14467
  edgeHost: null,
14257
14468
  generations: countEntries(path20.join(configDir, "generations")),
14258
- backups: countEntries(path20.join(configDir, "backups"))
14259
- } : await findLeftovers(run2) ?? "none";
14469
+ backups: countEntries(path20.join(configDir, "backups")),
14470
+ ...leftovers === null ? {} : { leftovers }
14471
+ } : leftovers ?? "none";
14260
14472
  } else {
14261
14473
  const { config, directory } = read.value.installation;
14262
14474
  const context = config.dockerContext;
@@ -14392,19 +14604,21 @@ var workspaceLines = (holdings, context) => {
14392
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`
14393
14605
  ];
14394
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
+ ];
14395
14613
  var planLines = (plan, configDir) => {
14396
14614
  const lines = [];
14397
14615
  if (plan.server === "none") {
14398
14616
  lines.push(`server none installed under ${configDir}`);
14399
14617
  } else if (isLeftovers(plan.server)) {
14400
- const { dockerContext, volumes, networks, containers, holdings } = plan.server;
14401
14618
  lines.push(
14402
- `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:`
14403
14620
  );
14404
- if (containers.length > 0) lines.push(` containers ${containers.join(", ")}`);
14405
- lines.push(` volumes ${volumes.join(", ")}`);
14406
- if (networks.length > 0) lines.push(` networks ${networks.join(", ")}`);
14407
- lines.push(...workspaceLines(holdings, dockerContext));
14621
+ lines.push(...leftoverLines(plan.server));
14408
14622
  } else if (plan.server !== null) {
14409
14623
  const { version, appUrl, dockerContext, edgeHost, generations, backups } = plan.server;
14410
14624
  lines.push(
@@ -14426,6 +14640,13 @@ var planLines = (plan, configDir) => {
14426
14640
  lines.push(
14427
14641
  ` ${configDir}: identity.env, active, ${plural(generations, "generation")}, ${plural(backups, "backup")}`
14428
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
+ }
14429
14650
  lines.push(...workspaceLines(plan.server.holdings ?? NO_HOLDINGS, dockerContext));
14430
14651
  const left = plan.server.leftByEarlier ?? [];
14431
14652
  if (left.length > 0)
@@ -14709,6 +14930,13 @@ var removeServer = async (runtime, plan, report) => {
14709
14930
  outcome = "partial";
14710
14931
  return;
14711
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
+ }
14712
14940
  }
14713
14941
  for (const name of [...SERVER_FILES, LEFT_FILE]) {
14714
14942
  fs20.rmSync(path20.join(configDir, name), { recursive: true, force: true });
@@ -14747,8 +14975,23 @@ var removeLeftovers = async (runtime, plan, report) => {
14747
14975
  const volume = await volumeOwner(run2, context, name);
14748
14976
  if (volume.state === "present" && volume.owner !== null) volumes.push(name);
14749
14977
  }
14750
- 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
+ }
14751
14993
  if (left.length > 0) report.remaining.push(...left);
14994
+ return left;
14752
14995
  };
14753
14996
  var removeHostExtras = async (runtime, context, extras, report) => {
14754
14997
  const run2 = runtime.server.run;
@@ -18935,7 +19178,7 @@ var dashboard = async (config, options = {}) => {
18935
19178
  );
18936
19179
  process.exit(rerun.status ?? 0);
18937
19180
  }
18938
- const { runDashboard } = await import("./dashboard-KZHIOJEX.js");
19181
+ const { runDashboard } = await import("./dashboard-IHWNKW2E.js");
18939
19182
  const agentShare = await startShareIfBridge(config);
18940
19183
  const tunnels = options.noTunnel === true || serverIsLocal(config) ? null : createServiceTunnels({
18941
19184
  listServices: () => fetchServices(config),
@@ -1,4 +1,4 @@
1
- .TH MEND-ACCOUNTS 1 "" "mend 0.36.0\-next.783" "mend manual"
1
+ .TH MEND-ACCOUNTS 1 "" "mend 0.36.0\-next.786" "mend manual"
2
2
  .SH NAME
3
3
  mend\-accounts \- your connected accounts on the platform
4
4
  .SH SYNOPSIS