@mx-space/cli 0.1.0 → 0.2.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 (159) hide show
  1. package/README.md +106 -29
  2. package/ROADMAP.md +4 -3
  3. package/dist/{auth-DIFZzoMm.mjs → auth-Duj8jJn9.mjs} +3 -3
  4. package/dist/{auth-DIFZzoMm.mjs.map → auth-Duj8jJn9.mjs.map} +1 -1
  5. package/dist/bin/mxs.d.mts +3 -1
  6. package/dist/bin/mxs.mjs +250 -48
  7. package/dist/bin/mxs.mjs.map +1 -1
  8. package/dist/config-store-DmwX2iZU.mjs +165 -0
  9. package/dist/config-store-DmwX2iZU.mjs.map +1 -0
  10. package/dist/{create-DjlRHPXy.mjs → create-Cqt1rrSZ.mjs} +5 -5
  11. package/dist/{create-DjlRHPXy.mjs.map → create-Cqt1rrSZ.mjs.map} +1 -1
  12. package/dist/{create-DT1l2hue.mjs → create-D7cR9xcN.mjs} +3 -3
  13. package/dist/{create-DT1l2hue.mjs.map → create-D7cR9xcN.mjs.map} +1 -1
  14. package/dist/{create-B2AOQL1e.mjs → create-DAt3FXLf.mjs} +5 -5
  15. package/dist/{create-B2AOQL1e.mjs.map → create-DAt3FXLf.mjs.map} +1 -1
  16. package/dist/{create-CwjGcv2n.mjs → create-_H8YO7ze.mjs} +3 -3
  17. package/dist/{create-CwjGcv2n.mjs.map → create-_H8YO7ze.mjs.map} +1 -1
  18. package/dist/{create-Dz6rJJSS.mjs → create-kYlrs4d6.mjs} +4 -4
  19. package/dist/{create-Dz6rJJSS.mjs.map → create-kYlrs4d6.mjs.map} +1 -1
  20. package/dist/{delete-BrY5zJ6S.mjs → delete-DVNebWqO.mjs} +4 -4
  21. package/dist/{delete-BrY5zJ6S.mjs.map → delete-DVNebWqO.mjs.map} +1 -1
  22. package/dist/{delete-B4dGrrus.mjs → delete-D_NRteuq.mjs} +4 -4
  23. package/dist/{delete-B4dGrrus.mjs.map → delete-D_NRteuq.mjs.map} +1 -1
  24. package/dist/{delete-BH6ZngTz.mjs → delete-DmKPzzsQ.mjs} +4 -4
  25. package/dist/{delete-BH6ZngTz.mjs.map → delete-DmKPzzsQ.mjs.map} +1 -1
  26. package/dist/{delete-CaG2d_xt.mjs → delete-ZIjkquZj.mjs} +4 -4
  27. package/dist/{delete-CaG2d_xt.mjs.map → delete-ZIjkquZj.mjs.map} +1 -1
  28. package/dist/{delete-YzRliRn8.mjs → delete-aCVSWuKi.mjs} +4 -4
  29. package/dist/{delete-YzRliRn8.mjs.map → delete-aCVSWuKi.mjs.map} +1 -1
  30. package/dist/{onboarding-640IldLz.mjs → dist-DJF1Ntdn.mjs} +95 -173
  31. package/dist/dist-DJF1Ntdn.mjs.map +1 -0
  32. package/dist/{document-output-BVB8emLt.mjs → document-output-BtY8T7eY.mjs} +59 -4
  33. package/dist/document-output-BtY8T7eY.mjs.map +1 -0
  34. package/dist/{edit-DLDw_ZWX.mjs → edit-BWX7X4sy.mjs} +8 -8
  35. package/dist/{edit-DLDw_ZWX.mjs.map → edit-BWX7X4sy.mjs.map} +1 -1
  36. package/dist/{edit-Bb0Ze4w6.mjs → edit-CHCuoiWT.mjs} +9 -9
  37. package/dist/{edit-Bb0Ze4w6.mjs.map → edit-CHCuoiWT.mjs.map} +1 -1
  38. package/dist/{edit-z55ofr1S.mjs → edit-DjRE8Gk-.mjs} +4 -4
  39. package/dist/{edit-z55ofr1S.mjs.map → edit-DjRE8Gk-.mjs.map} +1 -1
  40. package/dist/{edit-BeFmC3XD.mjs → edit-R6H5RtWd.mjs} +8 -8
  41. package/dist/{edit-BeFmC3XD.mjs.map → edit-R6H5RtWd.mjs.map} +1 -1
  42. package/dist/{editor-xrF-j3UE.mjs → editor-Dywlo4-8.mjs} +2 -2
  43. package/dist/{editor-xrF-j3UE.mjs.map → editor-Dywlo4-8.mjs.map} +1 -1
  44. package/dist/{envelope-overlays-DPAlMNW1.mjs → envelope-overlays-D1gmGVe5.mjs} +2 -2
  45. package/dist/{envelope-overlays-DPAlMNW1.mjs.map → envelope-overlays-D1gmGVe5.mjs.map} +1 -1
  46. package/dist/get-CiLnUGHw.mjs +14 -0
  47. package/dist/get-CiLnUGHw.mjs.map +1 -0
  48. package/dist/{get-2qjq0wgG.mjs → get-CkBqVyGi.mjs} +8 -8
  49. package/dist/get-CkBqVyGi.mjs.map +1 -0
  50. package/dist/{get-CRR13lgj.mjs → get-DNdde54z.mjs} +3 -3
  51. package/dist/{get-CRR13lgj.mjs.map → get-DNdde54z.mjs.map} +1 -1
  52. package/dist/get-DbH58EkF.mjs +14 -0
  53. package/dist/get-DbH58EkF.mjs.map +1 -0
  54. package/dist/get-IQQv4_rP.mjs +10 -0
  55. package/dist/get-IQQv4_rP.mjs.map +1 -0
  56. package/dist/get-xtByxURm.mjs +13 -0
  57. package/dist/get-xtByxURm.mjs.map +1 -0
  58. package/dist/index.d.mts +33 -4
  59. package/dist/index.mjs +10 -10
  60. package/dist/list-Bnlg9SfR.mjs +10 -0
  61. package/dist/list-Bnlg9SfR.mjs.map +1 -0
  62. package/dist/{list-DY-tPNG-.mjs → list-C6z1iw4a.mjs} +3 -3
  63. package/dist/{list-DY-tPNG-.mjs.map → list-C6z1iw4a.mjs.map} +1 -1
  64. package/dist/list-CD9j9did.mjs +10 -0
  65. package/dist/list-CD9j9did.mjs.map +1 -0
  66. package/dist/list-DVMtBAHG.mjs +15 -0
  67. package/dist/list-DVMtBAHG.mjs.map +1 -0
  68. package/dist/list-DW5TcGxS.mjs +10 -0
  69. package/dist/list-DW5TcGxS.mjs.map +1 -0
  70. package/dist/list-lmpHwOQx.mjs +14 -0
  71. package/dist/list-lmpHwOQx.mjs.map +1 -0
  72. package/dist/{litexml-codec-CDoRloiR.mjs → litexml-codec-D-1oggXL.mjs} +3 -3
  73. package/dist/{litexml-codec-CDoRloiR.mjs.map → litexml-codec-D-1oggXL.mjs.map} +1 -1
  74. package/dist/{login-CLOJ-fTJ.mjs → login-D-SoeV01.mjs} +20 -9
  75. package/dist/{login-CLOJ-fTJ.mjs.map → login-D-SoeV01.mjs.map} +1 -1
  76. package/dist/logout-D63ZU-1Q.mjs +17 -0
  77. package/dist/logout-D63ZU-1Q.mjs.map +1 -0
  78. package/dist/ls-Bz3BCcwU.mjs +32 -0
  79. package/dist/ls-Bz3BCcwU.mjs.map +1 -0
  80. package/dist/mark-N-IpKK17.mjs +28 -0
  81. package/dist/mark-N-IpKK17.mjs.map +1 -0
  82. package/dist/onboarding-FPMcuqn8.mjs +212 -0
  83. package/dist/onboarding-FPMcuqn8.mjs.map +1 -0
  84. package/dist/{output-CTnO1lYt.d.mts → output-DQMhacTo.d.mts} +1 -1
  85. package/dist/output-Dg8PISJM.mjs +299 -0
  86. package/dist/output-Dg8PISJM.mjs.map +1 -0
  87. package/dist/{payload-CN11pUto.mjs → payload-CjlZ9CeZ.mjs} +3 -3
  88. package/dist/{payload-CN11pUto.mjs.map → payload-CjlZ9CeZ.mjs.map} +1 -1
  89. package/dist/{publish-pRBfTJfe.mjs → publish-C9O5obZ6.mjs} +4 -4
  90. package/dist/{publish-pRBfTJfe.mjs.map → publish-C9O5obZ6.mjs.map} +1 -1
  91. package/dist/{publish-DkTYB-eK.mjs → publish-yuM6YGSb.mjs} +4 -4
  92. package/dist/{publish-DkTYB-eK.mjs.map → publish-yuM6YGSb.mjs.map} +1 -1
  93. package/dist/{resolve-Bp1AfBmM.mjs → resolve-B4-fMQ6I.mjs} +3 -3
  94. package/dist/{resolve-Bp1AfBmM.mjs.map → resolve-B4-fMQ6I.mjs.map} +1 -1
  95. package/dist/{resolve-BogJOR7R.mjs → resolve-DIu9N2sD.mjs} +2 -2
  96. package/dist/{resolve-BogJOR7R.mjs.map → resolve-DIu9N2sD.mjs.map} +1 -1
  97. package/dist/{resolve-CyjMlaoJ.mjs → resolve-TBYXBS4i.mjs} +3 -3
  98. package/dist/{resolve-CyjMlaoJ.mjs.map → resolve-TBYXBS4i.mjs.map} +1 -1
  99. package/dist/{resolve-Bw5Po9yK.mjs → resolve-U6RJ3AnQ.mjs} +3 -3
  100. package/dist/{resolve-Bw5Po9yK.mjs.map → resolve-U6RJ3AnQ.mjs.map} +1 -1
  101. package/dist/{resolve-helpers-CahPoJ0Y.mjs → resolve-helpers-C7PIVziv.mjs} +2 -2
  102. package/dist/{resolve-helpers-CahPoJ0Y.mjs.map → resolve-helpers-C7PIVziv.mjs.map} +1 -1
  103. package/dist/rm-D9GvLhhF.mjs +32 -0
  104. package/dist/rm-D9GvLhhF.mjs.map +1 -0
  105. package/dist/{set-BEGQz2si.mjs → set-jD79hpuF.mjs} +3 -3
  106. package/dist/{set-BEGQz2si.mjs.map → set-jD79hpuF.mjs.map} +1 -1
  107. package/dist/{shared-D0HVBDHI.mjs → shared-SryY2QPY.mjs} +20 -9
  108. package/dist/shared-SryY2QPY.mjs.map +1 -0
  109. package/dist/show-C5Zk0tcK.mjs +38 -0
  110. package/dist/show-C5Zk0tcK.mjs.map +1 -0
  111. package/dist/status-evZpPR3N.mjs +22 -0
  112. package/dist/status-evZpPR3N.mjs.map +1 -0
  113. package/dist/{update-BMZQPOvR.mjs → update--7NPzL_w.mjs} +4 -4
  114. package/dist/{update-BMZQPOvR.mjs.map → update--7NPzL_w.mjs.map} +1 -1
  115. package/dist/{update-BXz0l7Lz.mjs → update-0q5hxJFh.mjs} +5 -5
  116. package/dist/{update-BXz0l7Lz.mjs.map → update-0q5hxJFh.mjs.map} +1 -1
  117. package/dist/{update-Dx6AF8tf.mjs → update-CPJXcOg_.mjs} +6 -6
  118. package/dist/{update-Dx6AF8tf.mjs.map → update-CPJXcOg_.mjs.map} +1 -1
  119. package/dist/{update-q66TLS38.mjs → update-DN78pXGZ.mjs} +4 -4
  120. package/dist/{update-q66TLS38.mjs.map → update-DN78pXGZ.mjs.map} +1 -1
  121. package/dist/{update-B9ynFCdZ.mjs → update-hhAcAz_M.mjs} +6 -6
  122. package/dist/{update-B9ynFCdZ.mjs.map → update-hhAcAz_M.mjs.map} +1 -1
  123. package/dist/use-CHDCEe38.mjs +28 -0
  124. package/dist/use-CHDCEe38.mjs.map +1 -0
  125. package/dist/{whoami-CTkctOEd.mjs → whoami-BHDYyY5D.mjs} +4 -5
  126. package/dist/whoami-BHDYyY5D.mjs.map +1 -0
  127. package/package.json +1 -1
  128. package/dist/chunk-hT5z_Zn9.mjs +0 -35
  129. package/dist/config-store-DIu7x0ao.mjs +0 -121
  130. package/dist/config-store-DIu7x0ao.mjs.map +0 -1
  131. package/dist/document-output-BVB8emLt.mjs.map +0 -1
  132. package/dist/get-2qjq0wgG.mjs.map +0 -1
  133. package/dist/get-BGAk1Zmv.mjs +0 -14
  134. package/dist/get-BGAk1Zmv.mjs.map +0 -1
  135. package/dist/get-ClkpDBTL.mjs +0 -13
  136. package/dist/get-ClkpDBTL.mjs.map +0 -1
  137. package/dist/get-DJfUJ3sP.mjs +0 -10
  138. package/dist/get-DJfUJ3sP.mjs.map +0 -1
  139. package/dist/get-DiqaQvoS.mjs +0 -14
  140. package/dist/get-DiqaQvoS.mjs.map +0 -1
  141. package/dist/list-BYzhflDg.mjs +0 -14
  142. package/dist/list-BYzhflDg.mjs.map +0 -1
  143. package/dist/list-DlQSkbqx.mjs +0 -10
  144. package/dist/list-DlQSkbqx.mjs.map +0 -1
  145. package/dist/list-DsrA5wIz.mjs +0 -15
  146. package/dist/list-DsrA5wIz.mjs.map +0 -1
  147. package/dist/list-Fp4nKfQb.mjs +0 -10
  148. package/dist/list-Fp4nKfQb.mjs.map +0 -1
  149. package/dist/list-s_tloiEX.mjs +0 -10
  150. package/dist/list-s_tloiEX.mjs.map +0 -1
  151. package/dist/logout-v8ihxsim.mjs +0 -11
  152. package/dist/logout-v8ihxsim.mjs.map +0 -1
  153. package/dist/onboarding-640IldLz.mjs.map +0 -1
  154. package/dist/output-BM7aBFwt.mjs +0 -120
  155. package/dist/output-BM7aBFwt.mjs.map +0 -1
  156. package/dist/shared-D0HVBDHI.mjs.map +0 -1
  157. package/dist/status-LXrN9fI-.mjs +0 -22
  158. package/dist/status-LXrN9fI-.mjs.map +0 -1
  159. package/dist/whoami-CTkctOEd.mjs.map +0 -1
package/dist/bin/mxs.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { i as __toESM, r as __require, t as __commonJSMin } from "../chunk-hT5z_Zn9.mjs";
3
- import { c as exitCodeForError, n as emitError } from "../output-BM7aBFwt.mjs";
2
+ import { i as __commonJSMin, n as ue, o as __require, r as q, s as __toESM } from "../dist-DJF1Ntdn.mjs";
3
+ import { C as MxsError, b as writeProfileConfig, l as getCurrentProfile, n as emitError, p as getProfilesDir, v as setCurrentProfile, w as exitCodeForError, x as writeProfileCredentials, y as validateProfileName } from "../output-Dg8PISJM.mjs";
4
+ import { a as getLegacyConfigPath, o as getLegacyCredentialsPath } from "../config-store-DmwX2iZU.mjs";
5
+ import { promises } from "node:fs";
4
6
  //#region ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/lib/error.js
5
7
  var require_error = /* @__PURE__ */ __commonJSMin(((exports) => {
6
8
  /**
@@ -1018,7 +1020,7 @@ var require_command = /* @__PURE__ */ __commonJSMin(((exports) => {
1018
1020
  const EventEmitter = __require("node:events").EventEmitter;
1019
1021
  const childProcess = __require("node:child_process");
1020
1022
  const path = __require("node:path");
1021
- const fs = __require("node:fs");
1023
+ const fs$1 = __require("node:fs");
1022
1024
  const process$1 = __require("node:process");
1023
1025
  const { Argument, humanReadableArgName } = require_argument();
1024
1026
  const { CommanderError } = require_error();
@@ -1914,7 +1916,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1914
1916
  * @param {string} subcommandName
1915
1917
  */
1916
1918
  _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
1917
- if (fs.existsSync(executableFile)) return;
1919
+ if (fs$1.existsSync(executableFile)) return;
1918
1920
  const executableMissing = `'${executableFile}' does not exist
1919
1921
  - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
1920
1922
  - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
@@ -1938,9 +1940,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
1938
1940
  ];
1939
1941
  function findFile(baseDir, baseName) {
1940
1942
  const localBin = path.resolve(baseDir, baseName);
1941
- if (fs.existsSync(localBin)) return localBin;
1943
+ if (fs$1.existsSync(localBin)) return localBin;
1942
1944
  if (sourceExt.includes(path.extname(baseName))) return void 0;
1943
- const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
1945
+ const foundExt = sourceExt.find((ext) => fs$1.existsSync(`${localBin}${ext}`));
1944
1946
  if (foundExt) return `${localBin}${foundExt}`;
1945
1947
  }
1946
1948
  this._checkForMissingMandatoryOptions();
@@ -1950,7 +1952,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1950
1952
  if (this._scriptPath) {
1951
1953
  let resolvedScriptPath;
1952
1954
  try {
1953
- resolvedScriptPath = fs.realpathSync(this._scriptPath);
1955
+ resolvedScriptPath = fs$1.realpathSync(this._scriptPath);
1954
1956
  } catch {
1955
1957
  resolvedScriptPath = this._scriptPath;
1956
1958
  }
@@ -3012,10 +3014,187 @@ const { program: program$1, createCommand, createArgument, createOption, Command
3012
3014
  exports.InvalidOptionArgumentError = InvalidArgumentError;
3013
3015
  })))(), 1)).default;
3014
3016
  //#endregion
3017
+ //#region src/core/migration.ts
3018
+ async function fileExists(p) {
3019
+ try {
3020
+ await promises.stat(p);
3021
+ return true;
3022
+ } catch (err) {
3023
+ if (err?.code === "ENOENT") return false;
3024
+ throw err;
3025
+ }
3026
+ }
3027
+ async function dirExists(p) {
3028
+ try {
3029
+ return (await promises.stat(p)).isDirectory();
3030
+ } catch (err) {
3031
+ if (err?.code === "ENOENT") return false;
3032
+ throw err;
3033
+ }
3034
+ }
3035
+ function emit(report, line) {
3036
+ if (report === null) return;
3037
+ if (report !== void 0) {
3038
+ report(line);
3039
+ return;
3040
+ }
3041
+ process.stderr.write(`${line}\n`);
3042
+ }
3043
+ async function tryUnlink(p, report) {
3044
+ try {
3045
+ await promises.unlink(p);
3046
+ } catch (err) {
3047
+ if (err?.code !== "ENOENT") emit(report, `mxs: warning: could not remove stale legacy file ${p}: ${err.message}`);
3048
+ }
3049
+ }
3050
+ async function runLegacyMigrationIfNeeded(opts) {
3051
+ const report = opts?.report;
3052
+ const legacyConfigPath = getLegacyConfigPath();
3053
+ const legacyCredentialsPath = getLegacyCredentialsPath();
3054
+ const [hasConfig, hasCreds] = await Promise.all([fileExists(legacyConfigPath), fileExists(legacyCredentialsPath)]);
3055
+ if (!hasConfig && !hasCreds) return null;
3056
+ if (await dirExists(getProfilesDir())) {
3057
+ const toRemove = [];
3058
+ if (hasConfig) toRemove.push(legacyConfigPath);
3059
+ if (hasCreds) toRemove.push(legacyCredentialsPath);
3060
+ for (const p of toRemove) await tryUnlink(p, report);
3061
+ emit(report, `mxs: removed stale legacy config files at ${toRemove.join(", ")}`);
3062
+ return {
3063
+ profile: null,
3064
+ production: false,
3065
+ cleanedStaleLegacy: true
3066
+ };
3067
+ }
3068
+ let legacyConfig = {};
3069
+ if (hasConfig) try {
3070
+ const raw = await promises.readFile(legacyConfigPath, "utf8");
3071
+ legacyConfig = JSON.parse(raw);
3072
+ } catch (err) {
3073
+ if (err?.code !== "ENOENT") throw new MxsError({
3074
+ code: "config.migration.failed",
3075
+ message: `failed to read legacy config at ${legacyConfigPath}: ${err.message}`,
3076
+ cause: err
3077
+ });
3078
+ }
3079
+ let legacyCredentials = null;
3080
+ if (hasCreds) try {
3081
+ const raw = await promises.readFile(legacyCredentialsPath, "utf8");
3082
+ legacyCredentials = JSON.parse(raw);
3083
+ } catch (err) {
3084
+ if (err?.code !== "ENOENT") throw new MxsError({
3085
+ code: "config.migration.failed",
3086
+ message: `failed to read legacy credentials at ${legacyCredentialsPath}: ${err.message}`,
3087
+ cause: err
3088
+ });
3089
+ }
3090
+ let production = false;
3091
+ const tty = opts?.isTTY ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
3092
+ const apiUrl = typeof legacyConfig.api_url === "string" ? legacyConfig.api_url : void 0;
3093
+ if (tty && apiUrl) {
3094
+ const answer = opts?.promptIsProduction ? await opts.promptIsProduction(apiUrl) : await ue({
3095
+ message: `Is "${apiUrl}" a production environment?`,
3096
+ initialValue: false
3097
+ });
3098
+ production = q(answer) ? false : Boolean(answer);
3099
+ }
3100
+ const migratedConfig = { ...legacyConfig };
3101
+ if (production) migratedConfig.production = true;
3102
+ else delete migratedConfig.production;
3103
+ try {
3104
+ await writeProfileConfig("default", migratedConfig);
3105
+ } catch (err) {
3106
+ throw new MxsError({
3107
+ code: "config.migration.failed",
3108
+ message: `failed to write profile config during migration: ${err.message}`,
3109
+ cause: err
3110
+ });
3111
+ }
3112
+ if (legacyCredentials !== null) try {
3113
+ await writeProfileCredentials("default", legacyCredentials);
3114
+ } catch (err) {
3115
+ throw new MxsError({
3116
+ code: "config.migration.failed",
3117
+ message: `failed to write profile credentials during migration: ${err.message}`,
3118
+ cause: err
3119
+ });
3120
+ }
3121
+ await setCurrentProfile("default");
3122
+ if (hasConfig) await tryUnlink(legacyConfigPath, report);
3123
+ if (hasCreds) await tryUnlink(legacyCredentialsPath, report);
3124
+ emit(report, `mxs: migrated single-profile config to profile 'default'.`);
3125
+ return {
3126
+ profile: "default",
3127
+ production,
3128
+ cleanedStaleLegacy: false
3129
+ };
3130
+ }
3131
+ //#endregion
3132
+ //#region src/core/preaction-guards.ts
3133
+ /**
3134
+ * Single source of truth for preAction exemptions.
3135
+ *
3136
+ * Any command registration in bin/mxs.ts (or future Task 4 profile commands)
3137
+ * MUST match the names declared here exactly — this is the contract.
3138
+ */
3139
+ /** Parent command names whose entire subtree is exempt from the none_active guard. */
3140
+ const PREACTION_EXEMPT_PARENTS = new Set(["profile"]);
3141
+ /**
3142
+ * Individual (parent, name) pairs that are exempt regardless of profile state.
3143
+ * `auth login` is included unconditionally so a fresh install can bootstrap.
3144
+ */
3145
+ const PREACTION_EXEMPT_COMMANDS = [{
3146
+ parent: "auth",
3147
+ name: "login"
3148
+ }];
3149
+ /** Returns true if the command is exempt from the profile.none_active guard. */
3150
+ function isPreActionExempt(input) {
3151
+ return PREACTION_EXEMPT_PARENTS.has(input.parentName) || input.commandName === "profile" || PREACTION_EXEMPT_COMMANDS.some((c) => c.parent === input.parentName && c.name === input.commandName);
3152
+ }
3153
+ /**
3154
+ * Returns true if the guard should throw profile.none_active.
3155
+ * A resolved profile, any URL override, or an exempt command all suppress it.
3156
+ */
3157
+ function requiresActiveProfile(input) {
3158
+ if (input.profileFlag || input.envProfile) return false;
3159
+ if (input.apiUrlFlag || input.envApiUrl) return false;
3160
+ if (input.currentProfile) return false;
3161
+ if (isPreActionExempt(input)) return false;
3162
+ return true;
3163
+ }
3164
+ //#endregion
3015
3165
  //#region src/bin/mxs.ts
3016
3166
  const program = new Command();
3017
- program.name("mxs").description("mx-space CLI — manage your mx-core blog from the command line").version("0.1.0").option("--json", "emit JSON output").option("--output <mode>", "pretty-json | json | readable | llm | envelope").option("--api-url <url>", "override the configured API URL").option("--token <t>", "override the stored access token").option("--api-key <key>", "authenticate with an x-api-key API key").option("-q, --quiet", "suppress non-error stderr").option("--verbose", "log HTTP method/url/status/duration").option("--dry-run", "show resolved payload without calling the server");
3167
+ program.name("mxs").description("mx-space CLI — manage your mx-core blog from the command line").version("0.2.0").option("--json", "emit JSON output").option("--output <mode>", "pretty-json | json | readable | llm | envelope").option("--api-url <url>", "override the configured API URL").option("--token <t>", "override the stored access token").option("--api-key <key>", "authenticate with an x-api-key API key").option("--lang <code>", "request translated read data for a locale").option("-q, --quiet", "suppress non-error stderr").option("--verbose", "log HTTP method/url/status/duration").option("--dry-run", "show resolved payload without calling the server").option("--profile <name>", "profile to use (overrides MXS_PROFILE and the active profile pointer)");
3168
+ program.hook("preAction", async (thisCommand, actionCommand) => {
3169
+ const opts = thisCommand.optsWithGlobals();
3170
+ if (opts.profile) try {
3171
+ validateProfileName(opts.profile);
3172
+ } catch (err) {
3173
+ if (err instanceof MxsError) throw new MxsError({
3174
+ code: "profile.invalid_name",
3175
+ message: err.message,
3176
+ hint: "profile name must match ^[a-z0-9_-]{1,32}$ and must not be \"current\""
3177
+ });
3178
+ throw err;
3179
+ }
3180
+ await runLegacyMigrationIfNeeded({ report: opts.quiet ? null : void 0 });
3181
+ const currentProfile = await getCurrentProfile();
3182
+ if (requiresActiveProfile({
3183
+ profileFlag: opts.profile,
3184
+ apiUrlFlag: opts.apiUrl,
3185
+ envProfile: process.env.MXS_PROFILE?.trim(),
3186
+ envApiUrl: process.env.MXS_API_URL?.trim(),
3187
+ currentProfile,
3188
+ parentName: actionCommand.parent?.name() ?? "",
3189
+ commandName: actionCommand.name()
3190
+ })) throw new MxsError({
3191
+ code: "profile.none_active",
3192
+ message: "no active mxs profile",
3193
+ hint: "run `mxs profile use <name>` to switch, or `mxs auth login --profile <name>` to create one"
3194
+ });
3195
+ });
3018
3196
  addAuthCommands(program);
3197
+ addProfileCommands(program);
3019
3198
  addPostCommands(program);
3020
3199
  addNoteCommands(program);
3021
3200
  addPageCommands(program);
@@ -3040,46 +3219,46 @@ function readGlobalFlags(cmd) {
3040
3219
  }
3041
3220
  function addAuthCommands(parent) {
3042
3221
  const auth = parent.command("auth").description("authentication");
3043
- auth.command("login").description("start device authorization flow").action(async (_opts, command) => {
3044
- const { run } = await import("../login-CLOJ-fTJ.mjs");
3045
- await run(readGlobalFlags(command), readGlobalOptions(command));
3222
+ auth.command("login").description("start device authorization flow").option("--production", "mark the target profile as production after login").action(async (opts, command) => {
3223
+ const { run } = await import("../login-D-SoeV01.mjs");
3224
+ await run(readGlobalFlags(command), readGlobalOptions(command), { production: opts.production });
3046
3225
  });
3047
3226
  auth.command("logout").description("delete stored credentials").action(async (_opts, command) => {
3048
- const { run } = await import("../logout-v8ihxsim.mjs");
3227
+ const { run } = await import("../logout-D63ZU-1Q.mjs");
3049
3228
  await run(readGlobalFlags(command), readGlobalOptions(command));
3050
3229
  });
3051
3230
  auth.command("whoami").description("show the authenticated user").action(async (_opts, command) => {
3052
- const { run } = await import("../whoami-CTkctOEd.mjs");
3231
+ const { run } = await import("../whoami-BHDYyY5D.mjs");
3053
3232
  await run(readGlobalFlags(command), readGlobalOptions(command));
3054
3233
  });
3055
3234
  auth.command("status").description("show token validity and expiry").action(async (_opts, command) => {
3056
- const { run } = await import("../status-LXrN9fI-.mjs");
3235
+ const { run } = await import("../status-evZpPR3N.mjs");
3057
3236
  await run(readGlobalFlags(command), readGlobalOptions(command));
3058
3237
  });
3059
3238
  }
3060
3239
  function addPostCommands(parent) {
3061
3240
  const post = parent.command("post").description("manage posts");
3062
3241
  post.command("list").option("--page <n>", "page number", (v) => Number(v)).option("--size <n>", "page size", (v) => Number(v)).option("--state <s>", "draft | publish").option("--sort <s>", "created | modified").action(async (opts, command) => {
3063
- const { run } = await import("../list-DsrA5wIz.mjs");
3242
+ const { run } = await import("../list-DVMtBAHG.mjs");
3064
3243
  await run(opts, readGlobalFlags(command), readGlobalOptions(command));
3065
3244
  });
3066
3245
  post.command("get <slugOrId>").action(async (id, _opts, command) => {
3067
- const { run } = await import("../get-DiqaQvoS.mjs");
3246
+ const { run } = await import("../get-DbH58EkF.mjs");
3068
3247
  await run(id, readGlobalFlags(command), readGlobalOptions(command));
3069
3248
  });
3070
3249
  addPostWriteCommand(post, "create");
3071
3250
  addPostWriteCommand(post, "edit", true);
3072
3251
  addPostWriteCommand(post, "update", true);
3073
3252
  post.command("delete <slugOrId>").option("--force", "skip confirmation").action(async (id, opts, command) => {
3074
- const { run } = await import("../delete-B4dGrrus.mjs");
3253
+ const { run } = await import("../delete-D_NRteuq.mjs");
3075
3254
  await run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3076
3255
  });
3077
3256
  post.command("publish <slugOrId>").action(async (id, _opts, command) => {
3078
- const { run } = await import("../publish-DkTYB-eK.mjs");
3257
+ const { run } = await import("../publish-yuM6YGSb.mjs");
3079
3258
  await run(id, true, readGlobalFlags(command), readGlobalOptions(command));
3080
3259
  });
3081
3260
  post.command("unpublish <slugOrId>").action(async (id, _opts, command) => {
3082
- const { run } = await import("../publish-DkTYB-eK.mjs");
3261
+ const { run } = await import("../publish-yuM6YGSb.mjs");
3083
3262
  await run(id, false, readGlobalFlags(command), readGlobalOptions(command));
3084
3263
  });
3085
3264
  }
@@ -3091,13 +3270,13 @@ function addPostWriteCommand(parent, name, requiresId = false) {
3091
3270
  const opts = args.at(-2);
3092
3271
  const id = requiresId ? args[0] : void 0;
3093
3272
  if (name === "create") {
3094
- const { run } = await import("../create-B2AOQL1e.mjs");
3273
+ const { run } = await import("../create-DAt3FXLf.mjs");
3095
3274
  await run(opts, readGlobalFlags(command), readGlobalOptions(command));
3096
3275
  } else if (name === "edit") {
3097
- const { run } = await import("../edit-DLDw_ZWX.mjs");
3276
+ const { run } = await import("../edit-BWX7X4sy.mjs");
3098
3277
  await run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3099
3278
  } else {
3100
- const { run } = await import("../update-B9ynFCdZ.mjs");
3279
+ const { run } = await import("../update-hhAcAz_M.mjs");
3101
3280
  await run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3102
3281
  }
3103
3282
  });
@@ -3108,26 +3287,26 @@ function attachPostWriteFlags(cmd) {
3108
3287
  function addNoteCommands(parent) {
3109
3288
  const note = parent.command("note").description("manage notes");
3110
3289
  note.command("list").option("--page <n>", "", (v) => Number(v)).option("--size <n>", "", (v) => Number(v)).option("--state <s>").option("--sort <s>").action(async (opts, command) => {
3111
- const { run } = await import("../list-BYzhflDg.mjs");
3290
+ const { run } = await import("../list-lmpHwOQx.mjs");
3112
3291
  await run(opts, readGlobalFlags(command), readGlobalOptions(command));
3113
3292
  });
3114
3293
  note.command("get <slugOrId>").action(async (id, _opts, command) => {
3115
- const { run } = await import("../get-2qjq0wgG.mjs");
3294
+ const { run } = await import("../get-CkBqVyGi.mjs");
3116
3295
  await run(id, readGlobalFlags(command), readGlobalOptions(command));
3117
3296
  });
3118
3297
  addNoteWriteCommand(note, "create");
3119
3298
  addNoteWriteCommand(note, "edit", true);
3120
3299
  addNoteWriteCommand(note, "update", true);
3121
3300
  note.command("delete <slugOrId>").option("--force").action(async (id, opts, command) => {
3122
- const { run } = await import("../delete-BH6ZngTz.mjs");
3301
+ const { run } = await import("../delete-DmKPzzsQ.mjs");
3123
3302
  await run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3124
3303
  });
3125
3304
  note.command("publish <slugOrId>").action(async (id, _opts, command) => {
3126
- const { run } = await import("../publish-pRBfTJfe.mjs");
3305
+ const { run } = await import("../publish-C9O5obZ6.mjs");
3127
3306
  await run(id, true, readGlobalFlags(command), readGlobalOptions(command));
3128
3307
  });
3129
3308
  note.command("unpublish <slugOrId>").action(async (id, _opts, command) => {
3130
- const { run } = await import("../publish-pRBfTJfe.mjs");
3309
+ const { run } = await import("../publish-C9O5obZ6.mjs");
3131
3310
  await run(id, false, readGlobalFlags(command), readGlobalOptions(command));
3132
3311
  });
3133
3312
  }
@@ -3139,13 +3318,13 @@ function addNoteWriteCommand(parent, name, requiresId = false) {
3139
3318
  const opts = args.at(-2);
3140
3319
  const id = requiresId ? args[0] : void 0;
3141
3320
  if (name === "create") {
3142
- const { run } = await import("../create-DjlRHPXy.mjs");
3321
+ const { run } = await import("../create-Cqt1rrSZ.mjs");
3143
3322
  await run(opts, readGlobalFlags(command), readGlobalOptions(command));
3144
3323
  } else if (name === "edit") {
3145
- const { run } = await import("../edit-Bb0Ze4w6.mjs");
3324
+ const { run } = await import("../edit-CHCuoiWT.mjs");
3146
3325
  await run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3147
3326
  } else {
3148
- const { run } = await import("../update-Dx6AF8tf.mjs");
3327
+ const { run } = await import("../update-CPJXcOg_.mjs");
3149
3328
  await run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3150
3329
  }
3151
3330
  });
@@ -3153,11 +3332,11 @@ function addNoteWriteCommand(parent, name, requiresId = false) {
3153
3332
  function addPageCommands(parent) {
3154
3333
  const page = parent.command("page").description("manage pages");
3155
3334
  page.command("list").action(async (_opts, command) => {
3156
- const { run } = await import("../list-DlQSkbqx.mjs");
3335
+ const { run } = await import("../list-DW5TcGxS.mjs");
3157
3336
  await run({}, readGlobalFlags(command), readGlobalOptions(command));
3158
3337
  });
3159
3338
  page.command("get <slugOrId>").action(async (id, _opts, command) => {
3160
- const { run } = await import("../get-BGAk1Zmv.mjs");
3339
+ const { run } = await import("../get-CiLnUGHw.mjs");
3161
3340
  await run(id, readGlobalFlags(command), readGlobalOptions(command));
3162
3341
  });
3163
3342
  const writeCmd = (name, requiresId) => {
@@ -3167,81 +3346,104 @@ function addPageCommands(parent) {
3167
3346
  const command = args.at(-1);
3168
3347
  const opts = args.at(-2);
3169
3348
  const id = requiresId ? args[0] : void 0;
3170
- await (name === "create" ? await import("../create-Dz6rJJSS.mjs") : name === "edit" ? await import("../edit-BeFmC3XD.mjs") : await import("../update-BXz0l7Lz.mjs")).run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3349
+ await (name === "create" ? await import("../create-kYlrs4d6.mjs") : name === "edit" ? await import("../edit-R6H5RtWd.mjs") : await import("../update-0q5hxJFh.mjs")).run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3171
3350
  });
3172
3351
  };
3173
3352
  writeCmd("create", false);
3174
3353
  writeCmd("edit", true);
3175
3354
  writeCmd("update", true);
3176
3355
  page.command("delete <slugOrId>").option("--force").action(async (id, opts, command) => {
3177
- const { run } = await import("../delete-CaG2d_xt.mjs");
3356
+ const { run } = await import("../delete-ZIjkquZj.mjs");
3178
3357
  await run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3179
3358
  });
3180
3359
  }
3181
3360
  function addCategoryCommands(parent) {
3182
3361
  const cat = parent.command("category").description("manage categories / tags");
3183
3362
  cat.command("list").action(async (_o, command) => {
3184
- const { run } = await import("../list-Fp4nKfQb.mjs");
3363
+ const { run } = await import("../list-CD9j9did.mjs");
3185
3364
  await run(readGlobalFlags(command), readGlobalOptions(command));
3186
3365
  });
3187
3366
  cat.command("get <slugOrId>").action(async (id, _o, command) => {
3188
- const { run } = await import("../get-DJfUJ3sP.mjs");
3367
+ const { run } = await import("../get-IQQv4_rP.mjs");
3189
3368
  await run(id, readGlobalFlags(command), readGlobalOptions(command));
3190
3369
  });
3191
3370
  cat.command("create").requiredOption("--name <s>").requiredOption("--slug <s>").option("--type <s>", "category | tag").option("--icon <s>").action(async (opts, command) => {
3192
- const { run } = await import("../create-CwjGcv2n.mjs");
3371
+ const { run } = await import("../create-_H8YO7ze.mjs");
3193
3372
  await run(opts, readGlobalFlags(command), readGlobalOptions(command));
3194
3373
  });
3195
3374
  cat.command("update <slugOrId>").option("--name <s>").option("--slug <s>").option("--type <s>").option("--icon <s>").action(async (id, opts, command) => {
3196
- const { run } = await import("../update-BMZQPOvR.mjs");
3375
+ const { run } = await import("../update--7NPzL_w.mjs");
3197
3376
  await run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3198
3377
  });
3199
3378
  cat.command("delete <slugOrId>").option("--force").action(async (id, opts, command) => {
3200
- const { run } = await import("../delete-BrY5zJ6S.mjs");
3379
+ const { run } = await import("../delete-DVNebWqO.mjs");
3201
3380
  await run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3202
3381
  });
3203
3382
  }
3204
3383
  function addTopicCommands(parent) {
3205
3384
  const topic = parent.command("topic").description("manage topics");
3206
3385
  topic.command("list").action(async (_o, command) => {
3207
- const { run } = await import("../list-s_tloiEX.mjs");
3386
+ const { run } = await import("../list-Bnlg9SfR.mjs");
3208
3387
  await run(readGlobalFlags(command), readGlobalOptions(command));
3209
3388
  });
3210
3389
  topic.command("get <slugOrId>").action(async (id, _o, command) => {
3211
- const { run } = await import("../get-ClkpDBTL.mjs");
3390
+ const { run } = await import("../get-xtByxURm.mjs");
3212
3391
  await run(id, readGlobalFlags(command), readGlobalOptions(command));
3213
3392
  });
3214
3393
  topic.command("create").requiredOption("--name <s>").requiredOption("--slug <s>").option("--description <s>").option("--icon <s>").action(async (opts, command) => {
3215
- const { run } = await import("../create-DT1l2hue.mjs");
3394
+ const { run } = await import("../create-D7cR9xcN.mjs");
3216
3395
  await run(opts, readGlobalFlags(command), readGlobalOptions(command));
3217
3396
  });
3218
3397
  topic.command("update <slugOrId>").option("--name <s>").option("--slug <s>").option("--description <s>").option("--icon <s>").action(async (id, opts, command) => {
3219
- const { run } = await import("../update-q66TLS38.mjs");
3398
+ const { run } = await import("../update-DN78pXGZ.mjs");
3220
3399
  await run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3221
3400
  });
3222
3401
  topic.command("delete <slugOrId>").option("--force").action(async (id, opts, command) => {
3223
- const { run } = await import("../delete-YzRliRn8.mjs");
3402
+ const { run } = await import("../delete-aCVSWuKi.mjs");
3224
3403
  await run(id, opts, readGlobalFlags(command), readGlobalOptions(command));
3225
3404
  });
3226
3405
  }
3227
3406
  function addConfigCommands(parent) {
3228
3407
  const cfg = parent.command("config").description("manage server options");
3229
3408
  cfg.command("list").action(async (_o, command) => {
3230
- const { run } = await import("../list-DY-tPNG-.mjs");
3409
+ const { run } = await import("../list-C6z1iw4a.mjs");
3231
3410
  await run(readGlobalFlags(command), readGlobalOptions(command));
3232
3411
  });
3233
3412
  cfg.command("get <key>").action(async (key, _o, command) => {
3234
- const { run } = await import("../get-CRR13lgj.mjs");
3413
+ const { run } = await import("../get-DNdde54z.mjs");
3235
3414
  await run(key, readGlobalFlags(command), readGlobalOptions(command));
3236
3415
  });
3237
3416
  cfg.command("set <key> <value>").option("--type <t>", "json | string | number | bool").action(async (key, value, opts, command) => {
3238
- const { run } = await import("../set-BEGQz2si.mjs");
3417
+ const { run } = await import("../set-jD79hpuF.mjs");
3239
3418
  await run(key, value, opts, readGlobalFlags(command), readGlobalOptions(command));
3240
3419
  });
3241
3420
  cfg.command("edit").action(async (_o, command) => {
3242
- const { run } = await import("../edit-z55ofr1S.mjs");
3421
+ const { run } = await import("../edit-DjRE8Gk-.mjs");
3422
+ await run(readGlobalFlags(command), readGlobalOptions(command));
3423
+ });
3424
+ }
3425
+ function addProfileCommands(parent) {
3426
+ const profile = parent.command("profile").description("manage mxs profiles");
3427
+ profile.command("ls").description("list profiles").action(async (_opts, command) => {
3428
+ const { run } = await import("../ls-Bz3BCcwU.mjs");
3243
3429
  await run(readGlobalFlags(command), readGlobalOptions(command));
3244
3430
  });
3431
+ profile.command("show [name]").description("show resolved info for a profile").action(async (name, _opts, command) => {
3432
+ const { run } = await import("../show-C5Zk0tcK.mjs");
3433
+ await run(name, readGlobalFlags(command), readGlobalOptions(command));
3434
+ });
3435
+ profile.command("use <name>").description("set the active profile").action(async (name, _opts, command) => {
3436
+ const { run } = await import("../use-CHDCEe38.mjs");
3437
+ await run(name, readGlobalFlags(command), readGlobalOptions(command));
3438
+ });
3439
+ profile.command("mark <name>").description("toggle production flag on a profile").option("--production", "mark profile as production").option("--no-production", "mark profile as non-production").action(async (name, opts, command) => {
3440
+ const { run } = await import("../mark-N-IpKK17.mjs");
3441
+ await run(name, { production: opts.production }, readGlobalFlags(command), readGlobalOptions(command));
3442
+ });
3443
+ profile.command("rm <name>").description("remove a profile").option("--force", "skip confirmation and allow removing current profile").action(async (name, opts, command) => {
3444
+ const { run } = await import("../rm-D9GvLhhF.mjs");
3445
+ await run(name, opts, readGlobalFlags(command), readGlobalOptions(command));
3446
+ });
3245
3447
  }
3246
3448
  //#endregion
3247
3449
  export { readGlobalFlags, readGlobalOptions };