@rockcarver/frodo-cli 5.0.0-21 → 5.0.0-22

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.
@@ -1,5 +1,5 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-C-fzZZTt.cjs");
2
- const require_Console = require("./Console-CoAlCJ12.cjs");
2
+ const require_Console = require("./Console-gqjYb6W3.cjs");
3
3
  let fs = require("fs");
4
4
  fs = require_rolldown_runtime.__toESM(fs, 1);
5
5
  // src/ops/RealmOps.ts
@@ -336,4 +336,4 @@ Object.defineProperty(exports, "listRealms", {
336
336
  }
337
337
  });
338
338
 
339
- //# sourceMappingURL=RealmOps-DL-uIcdz.cjs.map
339
+ //# sourceMappingURL=RealmOps-rM69C80W.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"RealmOps-DL-uIcdz.cjs","names":["frodo","createTable","c","createProgressIndicator","FrodoError","createKeyValueTable"],"sources":["../src/ops/RealmOps.ts"],"sourcesContent":["import fs from 'fs';\nimport {\n frodo,\n FrodoError,\n type RealmExportInterface,\n} from '@rockcarver/frodo-lib';\nimport c from '../utils/ColorTheme';\nimport {\n createKeyValueTable,\n createProgressIndicator,\n createTable,\n debugMessage,\n printError,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\n\nconst {\n readRealm,\n readRealms,\n readRealmByName,\n exportRealms,\n importRealms,\n updateRealm,\n} = frodo.realm;\n\nconst {\n getTypedFilename,\n saveToFile,\n saveJsonToFile,\n getFilePath,\n getWorkingDirectory,\n} = frodo.utils;\n\n/**\n * Per-invocation cache of the realm list. The realm picker reads\n * realms right after auth, and commands like `frodo realm list` read them\n * again moments later -- two HTTP calls to the same endpoint that would\n * (a) double the latency and (b) break Polly's order-matched replay in e2e\n * recordings, which have one entry for the endpoint. Sharing one memoized\n * read keeps both callers on a single fetch.\n */\nlet realmsCache: Awaited<ReturnType<typeof readRealms>> | undefined;\n\n/**\n * Reads all realms, memoized for the remainder of this invocation. Callers\n * that need fresh data (import/export mutations) call frodo.realm\n * .readRealms directly.\n */\nexport async function readRealmsCached() {\n if (!realmsCache) {\n realmsCache = await readRealms();\n }\n return realmsCache;\n}\n\n/**\n * Clears the memoized realm list (test hygiene between invocations).\n */\nexport function resetRealmsCacheForTests(): void {\n realmsCache = undefined;\n}\n\n/**\n * List realms\n * @param {boolean} long Long list format with details\n */\nexport async function listRealms(long = false) {\n try {\n const realms = await readRealmsCached();\n if (long) {\n const table = createTable([\n c.heading('Id'),\n c.heading('Name'),\n c.heading('Status'),\n c.heading('Custom Domains'),\n c.heading('Parent Path'),\n ]);\n realms.forEach((realmConfig) => {\n table.push([\n realmConfig._id,\n realmConfig.name,\n realmConfig.active ? c.positive('active') : c.negative('inactive'),\n realmConfig.aliases.join('\\n'),\n realmConfig.parentPath,\n ]);\n });\n printMessage(table.toString(), 'data');\n } else {\n realms.forEach((realmConfig) => {\n printMessage(\n (realmConfig.parentPath || '') +\n (realmConfig.parentPath && !realmConfig.parentPath.endsWith('/')\n ? '/'\n : '') +\n realmConfig.name,\n 'data'\n );\n });\n }\n } catch (error) {\n printMessage(error, 'error');\n printMessage(`Error listing realms: ${error.message}`, 'error');\n printMessage(error.response?.data, 'error');\n }\n}\n\n/**\n * Export realm to file by id\n * @param {string} realmId realm id\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportRealmById(\n realmId: string,\n file: string,\n includeMeta: boolean = true\n): Promise<boolean> {\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${realmId}...`\n );\n try {\n const realm = await readRealm(realmId);\n let fileName = getTypedFilename(realmId, `realm`);\n if (file) {\n fileName = file;\n }\n updateProgressIndicator(indicatorId, `Saving ${realmId} to ${fileName}...`);\n saveToFile(\n 'realm',\n [realm],\n '_id',\n getFilePath(fileName, true),\n includeMeta\n );\n stopProgressIndicator(\n indicatorId,\n `Exported realm ${realmId} to file`,\n 'success'\n );\n return true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error exporting realm ${realmId} to file`,\n 'fail'\n );\n printError(error);\n }\n return false;\n}\n\n/**\n * Export realm to file by name\n * @param {string} realmName realm name\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportRealmByName(\n realmName: string,\n file: string,\n includeMeta: boolean = true\n): Promise<boolean> {\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${realmName}...`\n );\n try {\n const realm = await readRealmByName(realmName);\n let fileName = getTypedFilename(\n !realmName || realmName === '/' ? 'root' : realmName,\n `realm`\n );\n if (file) {\n fileName = file;\n }\n updateProgressIndicator(\n indicatorId,\n `Saving ${realmName} to ${fileName}...`\n );\n saveToFile(\n 'realm',\n [realm],\n '_id',\n getFilePath(fileName, true),\n includeMeta\n );\n stopProgressIndicator(\n indicatorId,\n `Exported realm ${realmName} to file`,\n 'success'\n );\n return true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error exporting realm ${realmName} to file`,\n 'fail'\n );\n printError(error);\n }\n return false;\n}\n\n/**\n * Export all realms to file\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportRealmsToFile(\n file: string,\n includeMeta: boolean = true\n): Promise<boolean> {\n try {\n const exportData = await exportRealms();\n let fileName = getTypedFilename(`allRealms`, `realm`);\n if (file) {\n fileName = file;\n }\n saveJsonToFile(exportData, getFilePath(fileName, true), includeMeta);\n return true;\n } catch (error) {\n printError(error, `Error exporting realms to file`);\n }\n return false;\n}\n\n/**\n * Export all realms to separate files\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportRealmsToFiles(\n includeMeta: boolean = true\n): Promise<boolean> {\n try {\n const realms = await readRealms();\n for (const realm of realms) {\n const fileName = getTypedFilename(\n !realm.name || realm.name === '/' ? 'root' : realm.name,\n 'realm'\n );\n saveToFile(\n 'realm',\n realm,\n '_id',\n getFilePath(fileName, true),\n includeMeta\n );\n }\n return true;\n } catch (error) {\n printError(error, `Error exporting realms to files`);\n }\n return false;\n}\n\n/**\n * Import a realm from file. The first realm from the file will be imported if no id/name is provided.\n * @param {string} realmId realm id\n * @param {string} realmName realm name\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importRealmFromFile(\n realmId: string,\n realmName: string,\n file: string\n): Promise<boolean> {\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n 'Importing realm...'\n );\n try {\n const importData = JSON.parse(\n fs.readFileSync(getFilePath(file), 'utf8')\n ) as RealmExportInterface;\n if (!realmId && !realmName) {\n const firstRealm = Object.values(importData.realm)[0];\n if (!firstRealm) {\n stopProgressIndicator(indicatorId, `No realms found!`, 'fail');\n return false;\n }\n realmName = firstRealm.name;\n }\n updateProgressIndicator(\n indicatorId,\n `Importing realm ${realmName ? realmName : realmId}.`\n );\n await importRealms(importData, realmId, realmName);\n stopProgressIndicator(indicatorId, `Successfully imported realm.`);\n return true;\n } catch (error) {\n stopProgressIndicator(indicatorId, `Error importing realm`, 'fail');\n printError(error);\n }\n return false;\n}\n\n/**\n * Import all realms from file\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importRealmsFromFile(file: string): Promise<boolean> {\n try {\n debugMessage(`importRealmsFromFile: start`);\n const filePath = getFilePath(file);\n const data = fs.readFileSync(filePath, 'utf8');\n debugMessage(`importRealmsFromFile: importing ${filePath}`);\n const importData = JSON.parse(data);\n await importRealms(importData);\n debugMessage(`importRealmsFromFile: end`);\n return true;\n } catch (error) {\n printError(error, `Error importing realms from file`);\n }\n return false;\n}\n\n/**\n * Import all realms from separate files\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importRealmsFromFiles(): Promise<boolean> {\n const errors: Error[] = [];\n try {\n const names = fs.readdirSync(getWorkingDirectory());\n const realmFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.realm.json')\n );\n for (const file of realmFiles) {\n try {\n await importRealmsFromFile(file);\n } catch (error) {\n errors.push(\n new FrodoError(`Error importing realms from ${file}`, error)\n );\n }\n }\n if (errors.length > 0) {\n throw new FrodoError(`One or more errors importing realms`, errors);\n }\n return true;\n } catch (error) {\n if (errors.length > 0) {\n printError(error);\n } else {\n printError(error, `Error importing realms from files`);\n }\n }\n return false;\n}\n\n/**\n * Describe realm\n * @param {String} realm realm name\n */\nexport async function describeRealm(realm: string) {\n try {\n const realmConfig = await readRealmByName(realm);\n const table = createKeyValueTable();\n table.push([c.heading('Name'), realmConfig.name]);\n table.push([\n c.heading('Status'),\n realmConfig.active ? c.positive('active') : c.negative('inactive'),\n ]);\n table.push([c.heading('Custom Domains'), realmConfig.aliases.join('\\n')]);\n table.push([c.heading('Parent'), realmConfig.parentPath]);\n table.push([c.heading('Id'), realmConfig._id]);\n printMessage(table.toString(), 'data');\n } catch {\n printMessage(`Realm ${realm} not found!`, 'error');\n }\n}\n\n/**\n * Add custom DNS domain name (realm DNS alias)\n * @param {String} realm realm name\n * @param {String} domain domain name\n */\nexport async function addCustomDomain(realm: string, domain: string) {\n try {\n let realmConfig = await readRealmByName(realm);\n let exists = false;\n realmConfig.aliases.forEach((alias) => {\n if (domain.toLowerCase() === alias.toLowerCase()) {\n exists = true;\n }\n });\n if (!exists) {\n try {\n realmConfig.aliases.push(domain.toLowerCase());\n realmConfig = await updateRealm(realmConfig._id, realmConfig);\n const table = createKeyValueTable();\n table.push([c.heading('Name'), realmConfig.name]);\n table.push([\n c.heading('Status'),\n realmConfig.active ? c.positive('active') : c.negative('inactive'),\n ]);\n table.push([\n c.heading('Custom Domains'),\n realmConfig.aliases.join('\\n'),\n ]);\n table.push([c.heading('Parent'), realmConfig.parentPath]);\n table.push([c.heading('Id'), realmConfig._id]);\n printMessage(table.toString());\n } catch (error) {\n printMessage(`Error adding custom domain: ${error.message}`, 'error');\n }\n }\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n }\n}\n\n/**\n * Remove custom DNS domain name (realm DNS alias)\n * @param {String} realm realm name\n * @param {String} domain domain name\n */\nexport async function removeCustomDomain(realm: string, domain: string) {\n try {\n let realmConfig = await readRealmByName(realm);\n const aliases = realmConfig.aliases.filter(\n (alias) => domain.toLowerCase() !== alias.toLowerCase()\n );\n if (aliases.length < realmConfig.aliases.length) {\n try {\n realmConfig.aliases = aliases;\n realmConfig = await updateRealm(realmConfig._id, realmConfig);\n const table = createKeyValueTable();\n table.push([c.heading('Name'), realmConfig.name]);\n table.push([\n c.heading('Status'),\n realmConfig.active ? c.positive('active') : c.negative('inactive'),\n ]);\n table.push([\n c.heading('Custom Domains'),\n realmConfig.aliases.join('\\n'),\n ]);\n table.push([c.heading('Parent'), realmConfig.parentPath]);\n table.push([c.heading('Id'), realmConfig._id]);\n printMessage(table.toString());\n } catch (error) {\n printMessage(`Error removing custom domain: ${error.message}`, 'error');\n }\n }\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAM,EACJ,WACA,YACA,iBACA,cACA,cACA,gBACEA,gBAAAA,MAAM;AAEV,MAAM,EACJ,kBACA,YACA,gBACA,aACA,wBACEA,gBAAAA,MAAM;;;;;;;;;AAUV,IAAI;;;;;;AAOJ,eAAsB,mBAAmB;CACvC,IAAI,CAAC,aACH,cAAc,MAAM,WAAW;CAEjC,OAAO;AACT;;;;;AAaA,eAAsB,WAAW,OAAO,OAAO;CAC7C,IAAI;EACF,MAAM,SAAS,MAAM,iBAAiB;EACtC,IAAI,MAAM;GACR,MAAM,QAAQC,gBAAAA,YAAY;IACxBC,gBAAAA,MAAE,QAAQ,IAAI;IACdA,gBAAAA,MAAE,QAAQ,MAAM;IAChBA,gBAAAA,MAAE,QAAQ,QAAQ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,CAACH,gBAAAA,MAAE,QAAQ,MAAM,GAAG,YAAY,IAAI,CAAC;GAChD,MAAM,KAAK,CACTA,gBAAAA,MAAE,QAAQ,QAAQ,GAClB,YAAY,SAASA,gBAAAA,MAAE,SAAS,QAAQ,IAAIA,gBAAAA,MAAE,SAAS,UAAU,CACnE,CAAC;GACD,MAAM,KAAK,CACTA,gBAAAA,MAAE,QAAQ,gBAAgB,GAC1B,YAAY,QAAQ,KAAK,IAAI,CAC/B,CAAC;GACD,MAAM,KAAK,CAACA,gBAAAA,MAAE,QAAQ,QAAQ,GAAG,YAAY,UAAU,CAAC;GACxD,MAAM,KAAK,CAACA,gBAAAA,MAAE,QAAQ,IAAI,GAAG,YAAY,GAAG,CAAC;GAC7C,gBAAA,aAAa,MAAM,SAAS,CAAC;EAC/B,SAAS,OAAO;GACd,gBAAA,aAAa,+BAA+B,MAAM,WAAW,OAAO;EACtE;CAEJ,SAAS,OAAO;EACd,gBAAA,aAAa,GAAG,MAAM,WAAW,OAAO;CAC1C;AACF"}
1
+ {"version":3,"file":"RealmOps-rM69C80W.cjs","names":["frodo","createTable","c","createProgressIndicator","FrodoError","createKeyValueTable"],"sources":["../src/ops/RealmOps.ts"],"sourcesContent":["import fs from 'fs';\nimport {\n frodo,\n FrodoError,\n type RealmExportInterface,\n} from '@rockcarver/frodo-lib';\nimport c from '../utils/ColorTheme';\nimport {\n createKeyValueTable,\n createProgressIndicator,\n createTable,\n debugMessage,\n printError,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from '../utils/Console';\n\nconst {\n readRealm,\n readRealms,\n readRealmByName,\n exportRealms,\n importRealms,\n updateRealm,\n} = frodo.realm;\n\nconst {\n getTypedFilename,\n saveToFile,\n saveJsonToFile,\n getFilePath,\n getWorkingDirectory,\n} = frodo.utils;\n\n/**\n * Per-invocation cache of the realm list. The realm picker reads\n * realms right after auth, and commands like `frodo realm list` read them\n * again moments later -- two HTTP calls to the same endpoint that would\n * (a) double the latency and (b) break Polly's order-matched replay in e2e\n * recordings, which have one entry for the endpoint. Sharing one memoized\n * read keeps both callers on a single fetch.\n */\nlet realmsCache: Awaited<ReturnType<typeof readRealms>> | undefined;\n\n/**\n * Reads all realms, memoized for the remainder of this invocation. Callers\n * that need fresh data (import/export mutations) call frodo.realm\n * .readRealms directly.\n */\nexport async function readRealmsCached() {\n if (!realmsCache) {\n realmsCache = await readRealms();\n }\n return realmsCache;\n}\n\n/**\n * Clears the memoized realm list (test hygiene between invocations).\n */\nexport function resetRealmsCacheForTests(): void {\n realmsCache = undefined;\n}\n\n/**\n * List realms\n * @param {boolean} long Long list format with details\n */\nexport async function listRealms(long = false) {\n try {\n const realms = await readRealmsCached();\n if (long) {\n const table = createTable([\n c.heading('Id'),\n c.heading('Name'),\n c.heading('Status'),\n c.heading('Custom Domains'),\n c.heading('Parent Path'),\n ]);\n realms.forEach((realmConfig) => {\n table.push([\n realmConfig._id,\n realmConfig.name,\n realmConfig.active ? c.positive('active') : c.negative('inactive'),\n realmConfig.aliases.join('\\n'),\n realmConfig.parentPath,\n ]);\n });\n printMessage(table.toString(), 'data');\n } else {\n realms.forEach((realmConfig) => {\n printMessage(\n (realmConfig.parentPath || '') +\n (realmConfig.parentPath && !realmConfig.parentPath.endsWith('/')\n ? '/'\n : '') +\n realmConfig.name,\n 'data'\n );\n });\n }\n } catch (error) {\n printMessage(error, 'error');\n printMessage(`Error listing realms: ${error.message}`, 'error');\n printMessage(error.response?.data, 'error');\n }\n}\n\n/**\n * Export realm to file by id\n * @param {string} realmId realm id\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportRealmById(\n realmId: string,\n file: string,\n includeMeta: boolean = true\n): Promise<boolean> {\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${realmId}...`\n );\n try {\n const realm = await readRealm(realmId);\n let fileName = getTypedFilename(realmId, `realm`);\n if (file) {\n fileName = file;\n }\n updateProgressIndicator(indicatorId, `Saving ${realmId} to ${fileName}...`);\n saveToFile(\n 'realm',\n [realm],\n '_id',\n getFilePath(fileName, true),\n includeMeta\n );\n stopProgressIndicator(\n indicatorId,\n `Exported realm ${realmId} to file`,\n 'success'\n );\n return true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error exporting realm ${realmId} to file`,\n 'fail'\n );\n printError(error);\n }\n return false;\n}\n\n/**\n * Export realm to file by name\n * @param {string} realmName realm name\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportRealmByName(\n realmName: string,\n file: string,\n includeMeta: boolean = true\n): Promise<boolean> {\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n `Exporting ${realmName}...`\n );\n try {\n const realm = await readRealmByName(realmName);\n let fileName = getTypedFilename(\n !realmName || realmName === '/' ? 'root' : realmName,\n `realm`\n );\n if (file) {\n fileName = file;\n }\n updateProgressIndicator(\n indicatorId,\n `Saving ${realmName} to ${fileName}...`\n );\n saveToFile(\n 'realm',\n [realm],\n '_id',\n getFilePath(fileName, true),\n includeMeta\n );\n stopProgressIndicator(\n indicatorId,\n `Exported realm ${realmName} to file`,\n 'success'\n );\n return true;\n } catch (error) {\n stopProgressIndicator(\n indicatorId,\n `Error exporting realm ${realmName} to file`,\n 'fail'\n );\n printError(error);\n }\n return false;\n}\n\n/**\n * Export all realms to file\n * @param {string} file file name\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportRealmsToFile(\n file: string,\n includeMeta: boolean = true\n): Promise<boolean> {\n try {\n const exportData = await exportRealms();\n let fileName = getTypedFilename(`allRealms`, `realm`);\n if (file) {\n fileName = file;\n }\n saveJsonToFile(exportData, getFilePath(fileName, true), includeMeta);\n return true;\n } catch (error) {\n printError(error, `Error exporting realms to file`);\n }\n return false;\n}\n\n/**\n * Export all realms to separate files\n * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function exportRealmsToFiles(\n includeMeta: boolean = true\n): Promise<boolean> {\n try {\n const realms = await readRealms();\n for (const realm of realms) {\n const fileName = getTypedFilename(\n !realm.name || realm.name === '/' ? 'root' : realm.name,\n 'realm'\n );\n saveToFile(\n 'realm',\n realm,\n '_id',\n getFilePath(fileName, true),\n includeMeta\n );\n }\n return true;\n } catch (error) {\n printError(error, `Error exporting realms to files`);\n }\n return false;\n}\n\n/**\n * Import a realm from file. The first realm from the file will be imported if no id/name is provided.\n * @param {string} realmId realm id\n * @param {string} realmName realm name\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importRealmFromFile(\n realmId: string,\n realmName: string,\n file: string\n): Promise<boolean> {\n const indicatorId = createProgressIndicator(\n 'determinate',\n 1,\n 'Importing realm...'\n );\n try {\n const importData = JSON.parse(\n fs.readFileSync(getFilePath(file), 'utf8')\n ) as RealmExportInterface;\n if (!realmId && !realmName) {\n const firstRealm = Object.values(importData.realm)[0];\n if (!firstRealm) {\n stopProgressIndicator(indicatorId, `No realms found!`, 'fail');\n return false;\n }\n realmName = firstRealm.name;\n }\n updateProgressIndicator(\n indicatorId,\n `Importing realm ${realmName ? realmName : realmId}.`\n );\n await importRealms(importData, realmId, realmName);\n stopProgressIndicator(indicatorId, `Successfully imported realm.`);\n return true;\n } catch (error) {\n stopProgressIndicator(indicatorId, `Error importing realm`, 'fail');\n printError(error);\n }\n return false;\n}\n\n/**\n * Import all realms from file\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importRealmsFromFile(file: string): Promise<boolean> {\n try {\n debugMessage(`importRealmsFromFile: start`);\n const filePath = getFilePath(file);\n const data = fs.readFileSync(filePath, 'utf8');\n debugMessage(`importRealmsFromFile: importing ${filePath}`);\n const importData = JSON.parse(data);\n await importRealms(importData);\n debugMessage(`importRealmsFromFile: end`);\n return true;\n } catch (error) {\n printError(error, `Error importing realms from file`);\n }\n return false;\n}\n\n/**\n * Import all realms from separate files\n * @returns {Promise<boolean>} true if successful, false otherwise\n */\nexport async function importRealmsFromFiles(): Promise<boolean> {\n const errors: Error[] = [];\n try {\n const names = fs.readdirSync(getWorkingDirectory());\n const realmFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.realm.json')\n );\n for (const file of realmFiles) {\n try {\n await importRealmsFromFile(file);\n } catch (error) {\n errors.push(\n new FrodoError(`Error importing realms from ${file}`, error)\n );\n }\n }\n if (errors.length > 0) {\n throw new FrodoError(`One or more errors importing realms`, errors);\n }\n return true;\n } catch (error) {\n if (errors.length > 0) {\n printError(error);\n } else {\n printError(error, `Error importing realms from files`);\n }\n }\n return false;\n}\n\n/**\n * Describe realm\n * @param {String} realm realm name\n */\nexport async function describeRealm(realm: string) {\n try {\n const realmConfig = await readRealmByName(realm);\n const table = createKeyValueTable();\n table.push([c.heading('Name'), realmConfig.name]);\n table.push([\n c.heading('Status'),\n realmConfig.active ? c.positive('active') : c.negative('inactive'),\n ]);\n table.push([c.heading('Custom Domains'), realmConfig.aliases.join('\\n')]);\n table.push([c.heading('Parent'), realmConfig.parentPath]);\n table.push([c.heading('Id'), realmConfig._id]);\n printMessage(table.toString(), 'data');\n } catch {\n printMessage(`Realm ${realm} not found!`, 'error');\n }\n}\n\n/**\n * Add custom DNS domain name (realm DNS alias)\n * @param {String} realm realm name\n * @param {String} domain domain name\n */\nexport async function addCustomDomain(realm: string, domain: string) {\n try {\n let realmConfig = await readRealmByName(realm);\n let exists = false;\n realmConfig.aliases.forEach((alias) => {\n if (domain.toLowerCase() === alias.toLowerCase()) {\n exists = true;\n }\n });\n if (!exists) {\n try {\n realmConfig.aliases.push(domain.toLowerCase());\n realmConfig = await updateRealm(realmConfig._id, realmConfig);\n const table = createKeyValueTable();\n table.push([c.heading('Name'), realmConfig.name]);\n table.push([\n c.heading('Status'),\n realmConfig.active ? c.positive('active') : c.negative('inactive'),\n ]);\n table.push([\n c.heading('Custom Domains'),\n realmConfig.aliases.join('\\n'),\n ]);\n table.push([c.heading('Parent'), realmConfig.parentPath]);\n table.push([c.heading('Id'), realmConfig._id]);\n printMessage(table.toString());\n } catch (error) {\n printMessage(`Error adding custom domain: ${error.message}`, 'error');\n }\n }\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n }\n}\n\n/**\n * Remove custom DNS domain name (realm DNS alias)\n * @param {String} realm realm name\n * @param {String} domain domain name\n */\nexport async function removeCustomDomain(realm: string, domain: string) {\n try {\n let realmConfig = await readRealmByName(realm);\n const aliases = realmConfig.aliases.filter(\n (alias) => domain.toLowerCase() !== alias.toLowerCase()\n );\n if (aliases.length < realmConfig.aliases.length) {\n try {\n realmConfig.aliases = aliases;\n realmConfig = await updateRealm(realmConfig._id, realmConfig);\n const table = createKeyValueTable();\n table.push([c.heading('Name'), realmConfig.name]);\n table.push([\n c.heading('Status'),\n realmConfig.active ? c.positive('active') : c.negative('inactive'),\n ]);\n table.push([\n c.heading('Custom Domains'),\n realmConfig.aliases.join('\\n'),\n ]);\n table.push([c.heading('Parent'), realmConfig.parentPath]);\n table.push([c.heading('Id'), realmConfig._id]);\n printMessage(table.toString());\n } catch (error) {\n printMessage(`Error removing custom domain: ${error.message}`, 'error');\n }\n }\n } catch (error) {\n printMessage(`${error.message}`, 'error');\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAM,EACJ,WACA,YACA,iBACA,cACA,cACA,gBACEA,gBAAAA,MAAM;AAEV,MAAM,EACJ,kBACA,YACA,gBACA,aACA,wBACEA,gBAAAA,MAAM;;;;;;;;;AAUV,IAAI;;;;;;AAOJ,eAAsB,mBAAmB;CACvC,IAAI,CAAC,aACH,cAAc,MAAM,WAAW;CAEjC,OAAO;AACT;;;;;AAaA,eAAsB,WAAW,OAAO,OAAO;CAC7C,IAAI;EACF,MAAM,SAAS,MAAM,iBAAiB;EACtC,IAAI,MAAM;GACR,M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QAAQ,KAAK,OAAO,YAAY,CAAC;GAC7C,cAAc,MAAM,YAAY,YAAY,KAAK,WAAW;GAC5D,MAAM,QAAQG,gBAAAA,oBAAoB;GAClC,MAAM,KAAK,CAACH,gBAAAA,MAAE,QAAQ,MAAM,GAAG,YAAY,IAAI,CAAC;GAChD,MAAM,KAAK,CACTA,gBAAAA,MAAE,QAAQ,QAAQ,GAClB,YAAY,SAASA,gBAAAA,MAAE,SAAS,QAAQ,IAAIA,gBAAAA,MAAE,SAAS,UAAU,CACnE,CAAC;GACD,MAAM,KAAK,CACTA,gBAAAA,MAAE,QAAQ,gBAAgB,GAC1B,YAAY,QAAQ,KAAK,IAAI,CAC/B,CAAC;GACD,MAAM,KAAK,CAACA,gBAAAA,MAAE,QAAQ,QAAQ,GAAG,YAAY,UAAU,CAAC;GACxD,MAAM,KAAK,CAACA,gBAAAA,MAAE,QAAQ,IAAI,GAAG,YAAY,GAAG,CAAC;GAC7C,gBAAA,aAAa,MAAM,SAAS,CAAC;EAC/B,SAAS,OAAO;GACd,gBAAA,aAAa,+BAA+B,MAAM,WAAW,OAAO;EACtE;CAEJ,SAAS,OAAO;EACd,gBAAA,aAAa,GAAG,MAAM,WAAW,OAAO;CAC1C;AACF"}
@@ -1,6 +1,6 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-C-fzZZTt.cjs");
2
- const require_Console = require("./Console-CoAlCJ12.cjs");
3
- const require_EscapableSelectPrompt = require("./EscapableSelectPrompt-_LjMcD3D.cjs");
2
+ const require_Console = require("./Console-gqjYb6W3.cjs");
3
+ const require_EscapableSelectPrompt = require("./EscapableSelectPrompt-BQvkZbap.cjs");
4
4
  // src/utils/interactive/PositionalArgs.ts
5
5
  /**
6
6
  * Index of the default positional argument of that name on this command
@@ -135,7 +135,7 @@ async function resolveRealmPick(command) {
135
135
  let realms;
136
136
  try {
137
137
  if (!cachedRealms) {
138
- const { readRealmsCached } = await Promise.resolve().then(() => require("./RealmOps-DL-uIcdz.cjs")).then((n) => n.RealmOps_exports);
138
+ const { readRealmsCached } = await Promise.resolve().then(() => require("./RealmOps-rM69C80W.cjs")).then((n) => n.RealmOps_exports);
139
139
  cachedRealms = (await readRealmsCached()).map((realm) => ({
140
140
  name: realm.name ?? realm._id ?? "",
141
141
  active: realm.active ?? true
@@ -149,7 +149,7 @@ async function resolveRealmPick(command) {
149
149
  const current = require_Console.state.getRealm();
150
150
  let choice;
151
151
  for (;;) {
152
- const { livePositionalPreviewFor, runInvocationEditorForCommand } = await Promise.resolve().then(() => require("./ResolveInteractiveInputs-Guw_NOYz.cjs")).then((n) => n.ResolveInteractiveInputs_exports);
152
+ const { livePositionalPreviewFor, runInvocationEditorForCommand } = await Promise.resolve().then(() => require("./ResolveInteractiveInputs-yYRVsQmo.cjs")).then((n) => n.ResolveInteractiveInputs_exports);
153
153
  const answer = await require_EscapableSelectPrompt.escapableSelect({
154
154
  message: `Choose a realm (default: ${current}):`,
155
155
  default: current,
@@ -179,7 +179,7 @@ async function resolveRealmPick(command) {
179
179
  }
180
180
  require_Console.state.setRealm(choice);
181
181
  {
182
- const { setPositionalValueForCommand } = await Promise.resolve().then(() => require("./ResolveInteractiveInputs-Guw_NOYz.cjs")).then((n) => n.ResolveInteractiveInputs_exports);
182
+ const { setPositionalValueForCommand } = await Promise.resolve().then(() => require("./ResolveInteractiveInputs-yYRVsQmo.cjs")).then((n) => n.ResolveInteractiveInputs_exports);
183
183
  setPositionalValueForCommand(command, "realm", choice.replace(/^\//, ""));
184
184
  }
185
185
  require_Console.verboseMessage(`Using realm ${choice}.`);
@@ -221,4 +221,4 @@ Object.defineProperty(exports, "setPositionalValue", {
221
221
  }
222
222
  });
223
223
 
224
- //# sourceMappingURL=RealmPickers-Cu69kFhW.cjs.map
224
+ //# sourceMappingURL=RealmPickers-CqVo_oru.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"RealmPickers-Cu69kFhW.cjs","names":["state","canPrompt","escapableSelect","editableOptionsHint","EXIT_ALL","EXIT_ALL_SIGNAL","RIGHT","ESCAPE"],"sources":["../src/utils/interactive/PositionalArgs.ts","../src/utils/interactive/RealmPickers.ts"],"sourcesContent":["/**\n * Positional-argument read/write helpers, split from\n * ResolveInteractiveInputs.ts into a zero-import module (the\n * CommandPreview/ActiveActionCommandState pattern): pure commander, no\n * frodo-lib, so both the resolver and the unit tests (which cannot import\n * the resolver's frodo-lib-heavy graph under this Jest setup -- see\n * src/app.commandWiring.test.ts's header comment) and the post-auth realm\n * picker's write-back share one implementation.\n */\n\nimport type { Command } from 'commander';\n\n/**\n * Index of the default positional argument of that name on this command\n * (commands omit default args via the FrodoCommand omits list, so the\n * index differs per command), or -1 when the command doesn't declare it.\n */\nexport function positionalIndex(command: Command, name: string): number {\n return command.registeredArguments.findIndex(\n (argument) => argument.name() === name\n );\n}\n\nexport function positionalValue(\n command: Command,\n name: string\n): string | undefined {\n const index = positionalIndex(command, name);\n if (index === -1) return undefined;\n const value = command.processedArgs?.[index];\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\n/**\n * Writes `value` into BOTH surfaces the CLI reads for a positional:\n *\n * - `processedArgs` is what the action handler's positional parameters\n * are sliced from (commander's action() wrapper slices\n * this.processedArgs).\n * - `args` (raw, options-removed user args) is what\n * handleDefaultArgsAndOpts iterates to copy default arguments into\n * frodo-lib state INSIDE the action body -- it does NOT read\n * processedArgs, so a processedArgs-only injection would be\n * overwritten with `undefined` the moment the action starts.\n * Verified against commander's _processArguments (fills processedArgs\n * from args, never writes back) and this repo's\n * handleDefaultArgsAndOpts (iterates command.args).\n *\n * `args` holds only user-supplied positional values; a gap-fill by\n * definition fills a position the user left empty, so extending/padding\n * with the injected value is safe. Pad with nulls for any inner\n * positions the user skipped (rare: inner default args are optional),\n * since args is positional.\n */\nexport function setPositionalValue(\n command: Command,\n name: string,\n value: string\n): void {\n const index = positionalIndex(command, name);\n if (index === -1) return;\n if (command.processedArgs) {\n command.processedArgs[index] = value;\n }\n if (Array.isArray(command.args)) {\n while (command.args.length < index) {\n command.args.push(null);\n }\n if (index === command.args.length) {\n command.args.push(value);\n } else if (command.args[index] == null) {\n command.args[index] = value;\n }\n }\n}\n","/**\n * Realm picker (docs/INTERACTIVE-COMMANDS.md, post-auth pickers).\n *\n * After authentication succeeds, a command whose realm argument was left\n * at its default can offer a dropdown of the target system's realms --\n * but ONLY when the system actually has more than one (a single-realm\n * tenant has no choice to offer; the default is already correct). The\n * pick fires from the getTokens wrapper (AuthenticateOps) immediately\n * after auth succeeds, so every command gets it without per-command\n * wiring; a prompt only happens when\n *\n * - the gate allows prompting (canPrompt()),\n * - the command declares a realm positional argument,\n * - a required connection input or option prompted the user to complete the\n * command,\n * - the user did not name a realm explicitly (argument value or\n * FRODO_REALM -- recorded by `noteRealmProvenance` during the\n * resolution pass, BEFORE frodo-lib maps the sentinel default to the\n * deployment type's realm during auth), and\n * - the target system reports more than one realm.\n *\n * Every other path is a no-op. Escape declines the offer and keeps the\n * deployment-type default -- unlike the entity pickers there is no\n * \"wrong\" continuation to protect here (the default is a valid choice),\n * so backing out just means \"keep the default\".\n *\n * The loader failing (permission denied on realm listing, older servers,\n * classic deployments where the endpoint differs) is swallowed and the\n * default kept: the command is about to run against the default realm\n * exactly as it did before the interactive layer existed.\n */\n\nimport { state } from '@rockcarver/frodo-lib';\nimport { Command } from 'commander';\nimport { verboseMessage } from '../Console';\nimport { editableOptionsHint } from './EditableOptions';\nimport { escapableSelect, ESCAPE, RIGHT } from './EscapableSelectPrompt';\nimport { EXIT_ALL, EXIT_ALL_SIGNAL } from './ExitAll';\nimport { positionalValue } from './PositionalArgs';\nimport { canPrompt } from './PromptGateState';\n\n/** frodo-lib's sentinel default for \"no realm chosen yet\". */\nconst DEFAULT_REALM_KEY = '__default__realm__';\n\n/** Cache of the realms read during this invocation (one fetch per run). */\nlet cachedRealms: { name: string; active: boolean }[] | undefined;\n\n/**\n * Whether the current invocation's realm was user-specified. Captured by\n * `noteRealmProvenance` during the resolution pass -- it CANNOT be\n * re-derived after auth, because frodo-lib's determineDefaultRealm\n * replaces the sentinel default with the deployment type's realm (alpha\n * or /) during _getTokens, making a user choice and a mapped default\n * indistinguishable afterwards.\n */\nlet realmUserSpecified = false;\nlet requiredInputPrompted = false;\n\n/** Records whether required input prompted during resolution. */\nexport function noteRequiredInputPrompted(prompted: boolean): void {\n requiredInputPrompted = prompted;\n}\n\n/** Whether required connection input prompted in the current invocation. */\nexport function requiredInputPromptedForTests(): boolean {\n return requiredInputPrompted;\n}\n\n/**\n * Records whether this invocation's realm came from the user (positional\n * argument value or FRODO_REALM) as opposed to the sentinel default.\n * Called by the resolution pass BEFORE auth -- see the `realmUserSpecified`\n * doc for why the timing matters.\n *\n * The realm positional is read from the command's processed arguments: it\n * only reaches frodo-lib's state later, when the action body runs\n * `handleDefaultArgsAndOpts`, so `state.getRealm()` alone cannot see a realm\n * the user typed (the picker then opened for `frodo journey list <host>\n * /alpha`). FRODO_REALM is the positional's default, so it counts through the\n * same read.\n *\n * @param command the command being run; omit it to judge by the state alone\n */\nexport function noteRealmProvenance(command?: Command): void {\n const realm =\n (command ? positionalValue(command, 'realm') : undefined) ??\n state.getRealm();\n realmUserSpecified = !!realm && realm !== DEFAULT_REALM_KEY;\n}\n\n/** What `noteRealmProvenance` last recorded (for tests: the flag is module-private). */\nexport function realmUserSpecifiedForTests(): boolean {\n return realmUserSpecified;\n}\n\n/** Test hygiene: clears the per-invocation provenance + realm cache. */\nexport function resetRealmPickerStateForTests(): void {\n realmUserSpecified = false;\n requiredInputPrompted = false;\n cachedRealms = undefined;\n}\n\n/**\n * Offers the realm dropdown for `command`'s realm argument when the\n * conditions in the module doc hold. Called by the getTokens wrapper\n * after a successful login. Never throws; on any problem it simply keeps\n * the default.\n */\nexport async function resolveRealmPick(command: Command): Promise<void> {\n if (!canPrompt()) return;\n if (!command.registeredArguments.some((a) => a.name() === 'realm')) return;\n if (realmUserSpecified) return;\n if (!requiredInputPrompted) return;\n\n let realms: { name: string; active: boolean }[];\n try {\n if (!cachedRealms) {\n // Via the memoized ops helper: shares one fetch with commands that\n // read realms themselves (frodo realm list), keeping Polly's\n // order-matched replay intact (recordings have one entry for the\n // endpoint) and halving the latency when both run.\n const { readRealmsCached } = await import('../../ops/RealmOps');\n const skeletons = await readRealmsCached();\n cachedRealms = skeletons.map((realm) => ({\n name: realm.name ?? realm._id ?? '',\n active: realm.active ?? true,\n }));\n }\n realms = cachedRealms;\n } catch {\n return; // can't list realms: keep the default\n }\n if (realms.length <= 1) return;\n\n const current = state.getRealm();\n // The picker runs POST-AUTH, so `current` is already frodo-lib's mapped\n // deployment default (alpha on cloud, / on classic/forgeops) -- passing\n // it as the select's default pre-highlights the TRUE default instead of\n // the first row, so a bare <enter> means \"keep the deployment default\".\n // The default may legitimately be absent from the list (the realms\n // endpoint never returns the root realm, so on classic/forgeops \"/\" has\n // no row): escapableSelect falls back to the first row in that case.\n // → (armed by the hint) opens the invocation editor, then\n // re-prompts this picker; ESCAPE keeps the default as before; EXIT_ALL\n // THROWS the unwind signal (the session ends even though auth already\n // succeeded -- the gesture means \"leave everything\", from any depth,\n // per docs/INTERACTIVE-COMMANDS.md).\n // The loop's exit type is string | typeof ESCAPE (the RIGHT case loops;\n // EXIT_ALL never resolves out of the loop -- it throws).\n let choice: string | typeof ESCAPE;\n for (;;) {\n const { livePositionalPreviewFor, runInvocationEditorForCommand } =\n await import('../../cli/ResolveInteractiveInputs');\n const answer = await escapableSelect<string>({\n message: `Choose a realm (default: ${current}):`,\n default: current,\n hint: editableOptionsHint(command),\n // LIVE footer: the highlighted realm shadows the realm positional\n // per render, so the footer's realm token moves with the cursor\n // BEFORE <enter> commits (live preview).\n preview: livePositionalPreviewFor(command, 'realm'),\n choices: realms.map((realm) => ({\n value: realm.name,\n name: realm.name,\n description: realm.active ? undefined : 'inactive',\n })),\n });\n if (answer === EXIT_ALL) throw EXIT_ALL_SIGNAL;\n if (answer === RIGHT) {\n // The hint advertised the editor, so → must open it (this branch\n // used to just re-prompt, making the key look dead). The editor\n // throws EXIT_ALL_SIGNAL on a double-ESC; a plain return loops\n // back here and the user can still ESC the picker.\n await runInvocationEditorForCommand(command);\n continue;\n }\n choice = answer;\n break;\n }\n if (choice === ESCAPE) {\n // Backed out: keep the deployment default (the pre-interactive\n // behavior), AND say so -- a silent return after the frame erased\n // left the terminal idle with no explanation (user report\n // 2026-10-13: \"the picker wasn't active\" -- the prompt had actually\n // concluded; nothing showed why nothing then happened).\n verboseMessage(`Keeping the default realm ${current}.`);\n return;\n }\n if (!choice || choice === current) {\n // <enter> on the already-highlighted default: an explicit \"keep\n // it\". The pick is DONE -- do NOT loop back into another picker\n // instance (the old silent re-prompt read as a dead screen: the\n // prompt concluded and nothing re-appeared).\n verboseMessage(`Keeping the default realm ${current}.`);\n return;\n }\n state.setRealm(choice);\n // Write the picked realm back into the command's realm positional so the\n // deferred authoring print (flushed at the action's postAction hook, see\n // FrodoCommand/AuthoringPrintState) shows the command EXACTLY as it ran\n // -- the printed realm token matches state.getRealm() token for token.\n // Without this, a non-default pick would print the (sentinel-translated)\n // positional while the action actually runs in `choice`. The CLI\n // positional convention is the plain name (no leading slash) -- the\n // exact value the user would type -- and handleDefaultArgsAndOpts\n // re-feeds it into state.setRealm inside the action body, so the value\n // must be positional-shaped, not state-shaped.\n {\n const { setPositionalValueForCommand } =\n await import('../../cli/ResolveInteractiveInputs');\n setPositionalValueForCommand(command, 'realm', choice.replace(/^\\//, ''));\n }\n verboseMessage(`Using realm ${choice}.`);\n}\n"],"mappings":";;;;;;;;;AAiBA,SAAgB,gBAAgB,SAAkB,MAAsB;CACtE,OAAO,QAAQ,oBAAoB,WAChC,aAAa,SAAS,KAAK,MAAM,IACpC;AACF;AAEA,SAAgB,gBACd,SACA,MACoB;CACpB,MAAM,QAAQ,gBAAgB,SAAS,IAAI;CAC3C,IAAI,UAAU,IAAI,OAAO,KAAA;CACzB,MAAM,QAAQ,QAAQ,gBAAgB;CACtC,OAAO,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ,K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","EXIT_ALL","EXIT_ALL_SIGNAL","RIGHT","ESCAPE"],"sources":["../src/utils/interactive/PositionalArgs.ts","../src/utils/interactive/RealmPickers.ts"],"sourcesContent":["/**\n * Positional-argument read/write helpers, split from\n * ResolveInteractiveInputs.ts into a zero-import module (the\n * CommandPreview/ActiveActionCommandState pattern): pure commander, no\n * frodo-lib, so both the resolver and the unit tests (which cannot import\n * the resolver's frodo-lib-heavy graph under this Jest setup -- see\n * src/app.commandWiring.test.ts's header comment) and the post-auth realm\n * picker's write-back share one implementation.\n */\n\nimport type { Command } from 'commander';\n\n/**\n * Index of the default positional argument of that name on this command\n * (commands omit default args via the FrodoCommand omits list, so the\n * index differs per command), or -1 when the command doesn't declare it.\n */\nexport function positionalIndex(command: Command, name: string): number {\n return command.registeredArguments.findIndex(\n (argument) => argument.name() === name\n );\n}\n\nexport function positionalValue(\n command: Command,\n name: string\n): string | undefined {\n const index = positionalIndex(command, name);\n if (index === -1) return undefined;\n const value = command.processedArgs?.[index];\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\n/**\n * Writes `value` into BOTH surfaces the CLI reads for a positional:\n *\n * - `processedArgs` is what the action handler's positional parameters\n * are sliced from (commander's action() wrapper slices\n * this.processedArgs).\n * - `args` (raw, options-removed user args) is what\n * handleDefaultArgsAndOpts iterates to copy default arguments into\n * frodo-lib state INSIDE the action body -- it does NOT read\n * processedArgs, so a processedArgs-only injection would be\n * overwritten with `undefined` the moment the action starts.\n * Verified against commander's _processArguments (fills processedArgs\n * from args, never writes back) and this repo's\n * handleDefaultArgsAndOpts (iterates command.args).\n *\n * `args` holds only user-supplied positional values; a gap-fill by\n * definition fills a position the user left empty, so extending/padding\n * with the injected value is safe. Pad with nulls for any inner\n * positions the user skipped (rare: inner default args are optional),\n * since args is positional.\n */\nexport function setPositionalValue(\n command: Command,\n name: string,\n value: string\n): void {\n const index = positionalIndex(command, name);\n if (index === -1) return;\n if (command.processedArgs) {\n command.processedArgs[index] = value;\n }\n if (Array.isArray(command.args)) {\n while (command.args.length < index) {\n command.args.push(null);\n }\n if (index === command.args.length) {\n command.args.push(value);\n } else if (command.args[index] == null) {\n command.args[index] = value;\n }\n }\n}\n","/**\n * Realm picker (docs/INTERACTIVE-COMMANDS.md, post-auth pickers).\n *\n * After authentication succeeds, a command whose realm argument was left\n * at its default can offer a dropdown of the target system's realms --\n * but ONLY when the system actually has more than one (a single-realm\n * tenant has no choice to offer; the default is already correct). The\n * pick fires from the getTokens wrapper (AuthenticateOps) immediately\n * after auth succeeds, so every command gets it without per-command\n * wiring; a prompt only happens when\n *\n * - the gate allows prompting (canPrompt()),\n * - the command declares a realm positional argument,\n * - a required connection input or option prompted the user to complete the\n * command,\n * - the user did not name a realm explicitly (argument value or\n * FRODO_REALM -- recorded by `noteRealmProvenance` during the\n * resolution pass, BEFORE frodo-lib maps the sentinel default to the\n * deployment type's realm during auth), and\n * - the target system reports more than one realm.\n *\n * Every other path is a no-op. Escape declines the offer and keeps the\n * deployment-type default -- unlike the entity pickers there is no\n * \"wrong\" continuation to protect here (the default is a valid choice),\n * so backing out just means \"keep the default\".\n *\n * The loader failing (permission denied on realm listing, older servers,\n * classic deployments where the endpoint differs) is swallowed and the\n * default kept: the command is about to run against the default realm\n * exactly as it did before the interactive layer existed.\n */\n\nimport { state } from '@rockcarver/frodo-lib';\nimport { Command } from 'commander';\nimport { verboseMessage } from '../Console';\nimport { editableOptionsHint } from './EditableOptions';\nimport { escapableSelect, ESCAPE, RIGHT } from './EscapableSelectPrompt';\nimport { EXIT_ALL, EXIT_ALL_SIGNAL } from './ExitAll';\nimport { positionalValue } from './PositionalArgs';\nimport { canPrompt } from './PromptGateState';\n\n/** frodo-lib's sentinel default for \"no realm chosen yet\". */\nconst DEFAULT_REALM_KEY = '__default__realm__';\n\n/** Cache of the realms read during this invocation (one fetch per run). */\nlet cachedRealms: { name: string; active: boolean }[] | undefined;\n\n/**\n * Whether the current invocation's realm was user-specified. Captured by\n * `noteRealmProvenance` during the resolution pass -- it CANNOT be\n * re-derived after auth, because frodo-lib's determineDefaultRealm\n * replaces the sentinel default with the deployment type's realm (alpha\n * or /) during _getTokens, making a user choice and a mapped default\n * indistinguishable afterwards.\n */\nlet realmUserSpecified = false;\nlet requiredInputPrompted = false;\n\n/** Records whether required input prompted during resolution. */\nexport function noteRequiredInputPrompted(prompted: boolean): void {\n requiredInputPrompted = prompted;\n}\n\n/** Whether required connection input prompted in the current invocation. */\nexport function requiredInputPromptedForTests(): boolean {\n return requiredInputPrompted;\n}\n\n/**\n * Records whether this invocation's realm came from the user (positional\n * argument value or FRODO_REALM) as opposed to the sentinel default.\n * Called by the resolution pass BEFORE auth -- see the `realmUserSpecified`\n * doc for why the timing matters.\n *\n * The realm positional is read from the command's processed arguments: it\n * only reaches frodo-lib's state later, when the action body runs\n * `handleDefaultArgsAndOpts`, so `state.getRealm()` alone cannot see a realm\n * the user typed (the picker then opened for `frodo journey list <host>\n * /alpha`). FRODO_REALM is the positional's default, so it counts through the\n * same read.\n *\n * @param command the command being run; omit it to judge by the state alone\n */\nexport function noteRealmProvenance(command?: Command): void {\n const realm =\n (command ? positionalValue(command, 'realm') : undefined) ??\n state.getRealm();\n realmUserSpecified = !!realm && realm !== DEFAULT_REALM_KEY;\n}\n\n/** What `noteRealmProvenance` last recorded (for tests: the flag is module-private). */\nexport function realmUserSpecifiedForTests(): boolean {\n return realmUserSpecified;\n}\n\n/** Test hygiene: clears the per-invocation provenance + realm cache. */\nexport function resetRealmPickerStateForTests(): void {\n realmUserSpecified = false;\n requiredInputPrompted = false;\n cachedRealms = undefined;\n}\n\n/**\n * Offers the realm dropdown for `command`'s realm argument when the\n * conditions in the module doc hold. Called by the getTokens wrapper\n * after a successful login. Never throws; on any problem it simply keeps\n * the default.\n */\nexport async function resolveRealmPick(command: Command): Promise<void> {\n if (!canPrompt()) return;\n if (!command.registeredArguments.some((a) => a.name() === 'realm')) return;\n if (realmUserSpecified) return;\n if (!requiredInputPrompted) return;\n\n let realms: { name: string; active: boolean }[];\n try {\n if (!cachedRealms) {\n // Via the memoized ops helper: shares one fetch with commands that\n // read realms themselves (frodo realm list), keeping Polly's\n // order-matched replay intact (recordings have one entry for the\n // endpoint) and halving the latency when both run.\n const { readRealmsCached } = await import('../../ops/RealmOps');\n const skeletons = await readRealmsCached();\n cachedRealms = skeletons.map((realm) => ({\n name: realm.name ?? realm._id ?? '',\n active: realm.active ?? true,\n }));\n }\n realms = cachedRealms;\n } catch {\n return; // can't list realms: keep the default\n }\n if (realms.length <= 1) return;\n\n const current = state.getRealm();\n // The picker runs POST-AUTH, so `current` is already frodo-lib's mapped\n // deployment default (alpha on cloud, / on classic/forgeops) -- passing\n // it as the select's default pre-highlights the TRUE default instead of\n // the first row, so a bare <enter> means \"keep the deployment default\".\n // The default may legitimately be absent from the list (the realms\n // endpoint never returns the root realm, so on classic/forgeops \"/\" has\n // no row): escapableSelect falls back to the first row in that case.\n // → (armed by the hint) opens the invocation editor, then\n // re-prompts this picker; ESCAPE keeps the default as before; EXIT_ALL\n // THROWS the unwind signal (the session ends even though auth already\n // succeeded -- the gesture means \"leave everything\", from any depth,\n // per docs/INTERACTIVE-COMMANDS.md).\n // The loop's exit type is string | typeof ESCAPE (the RIGHT case loops;\n // EXIT_ALL never resolves out of the loop -- it throws).\n let choice: string | typeof ESCAPE;\n for (;;) {\n const { livePositionalPreviewFor, runInvocationEditorForCommand } =\n await import('../../cli/ResolveInteractiveInputs');\n const answer = await escapableSelect<string>({\n message: `Choose a realm (default: ${current}):`,\n default: current,\n hint: editableOptionsHint(command),\n // LIVE footer: the highlighted realm shadows the realm positional\n // per render, so the footer's realm token moves with the cursor\n // BEFORE <enter> commits (live preview).\n preview: livePositionalPreviewFor(command, 'realm'),\n choices: realms.map((realm) => ({\n value: realm.name,\n name: realm.name,\n description: realm.active ? undefined : 'inactive',\n })),\n });\n if (answer === EXIT_ALL) throw EXIT_ALL_SIGNAL;\n if (answer === RIGHT) {\n // The hint advertised the editor, so → must open it (this branch\n // used to just re-prompt, making the key look dead). The editor\n // throws EXIT_ALL_SIGNAL on a double-ESC; a plain return loops\n // back here and the user can still ESC the picker.\n await runInvocationEditorForCommand(command);\n continue;\n }\n choice = answer;\n break;\n }\n if (choice === ESCAPE) {\n // Backed out: keep the deployment default (the pre-interactive\n // behavior), AND say so -- a silent return after the frame erased\n // left the terminal idle with no explanation (user report\n // 2026-10-13: \"the picker wasn't active\" -- the prompt had actually\n // concluded; nothing showed why nothing then happened).\n verboseMessage(`Keeping the default realm ${current}.`);\n return;\n }\n if (!choice || choice === current) {\n // <enter> on the already-highlighted default: an explicit \"keep\n // it\". The pick is DONE -- do NOT loop back into another picker\n // instance (the old silent re-prompt read as a dead screen: the\n // prompt concluded and nothing re-appeared).\n verboseMessage(`Keeping the default realm ${current}.`);\n return;\n }\n state.setRealm(choice);\n // Write the picked realm back into the command's realm positional so the\n // deferred authoring print (flushed at the action's postAction hook, see\n // FrodoCommand/AuthoringPrintState) shows the command EXACTLY as it ran\n // -- the printed realm token matches state.getRealm() token for token.\n // Without this, a non-default pick would print the (sentinel-translated)\n // positional while the action actually runs in `choice`. The CLI\n // positional convention is the plain name (no leading slash) -- the\n // exact value the user would type -- and handleDefaultArgsAndOpts\n // re-feeds it into state.setRealm inside the action body, so the value\n // must be positional-shaped, not state-shaped.\n {\n const { setPositionalValueForCommand } =\n await import('../../cli/ResolveInteractiveInputs');\n setPositionalValueForCommand(command, 'realm', choice.replace(/^\\//, ''));\n }\n verboseMessage(`Using realm ${choice}.`);\n}\n"],"mappings":";;;;;;;;;AAiBA,SAAgB,gBAAgB,SAAkB,MAAsB;CACtE,OAAO,QAAQ,oBAAoB,WAChC,aAAa,SAAS,KAAK,MAAM,IACpC;AACF;AAEA,SAAgB,gBACd,SACA,MACoB;CACpB,MAAM,QAAQ,gBAAgB,SAAS,IAAI;CAC3C,IAAI,UAAU,IAAI,OAAO,KAAA;CACzB,MAAM,QAAQ,QAAQ,gBAAgB;CACtC,OAAO,OAAO,UAAU,YAAY,MAA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-runtime-C-fzZZTt.cjs");
2
- const require_Console = require("./Console-CoAlCJ12.cjs");
3
- const require_EscapableSelectPrompt = require("./EscapableSelectPrompt-_LjMcD3D.cjs");
2
+ const require_Console = require("./Console-gqjYb6W3.cjs");
3
+ const require_EscapableSelectPrompt = require("./EscapableSelectPrompt-BQvkZbap.cjs");
4
4
  const require_AuthoringPrintState = require("./AuthoringPrintState-DiVf7UYM.cjs");
5
- const require_EntityPickers = require("./EntityPickers-DwBJs2ob.cjs");
5
+ const require_EntityPickers = require("./EntityPickers-CW8YUPps.cjs");
6
6
  const require_DefaultsStore = require("./DefaultsStore-DQMSHsZo.cjs");
7
- const require_RealmPickers = require("./RealmPickers-Cu69kFhW.cjs");
7
+ const require_RealmPickers = require("./RealmPickers-CqVo_oru.cjs");
8
8
  let path = require("path");
9
9
  path = require_rolldown_runtime.__toESM(path, 1);
10
10
  let fs = require("fs");
@@ -1981,7 +1981,7 @@ async function runInvocationEditor(command) {
1981
1981
  require_Console.verboseMessage(`Using ${option.flags}.`);
1982
1982
  }
1983
1983
  if (picked.length > 0) {
1984
- const { replayEditorOptionStates } = await Promise.resolve().then(() => require("./FrodoCommand-CNGnTfsM.cjs")).then((n) => n.FrodoCommand_exports);
1984
+ const { replayEditorOptionStates } = await Promise.resolve().then(() => require("./FrodoCommand-C_WQ1qiY.cjs")).then((n) => n.FrodoCommand_exports);
1985
1985
  replayEditorOptionStates(command);
1986
1986
  }
1987
1987
  if (savingDefaults && Object.keys(committed).length > 0) {
@@ -2058,4 +2058,4 @@ Object.defineProperty(exports, "setGuidedMode", {
2058
2058
  }
2059
2059
  });
2060
2060
 
2061
- //# sourceMappingURL=ResolveInteractiveInputs-Guw_NOYz.cjs.map
2061
+ //# sourceMappingURL=ResolveInteractiveInputs-yYRVsQmo.cjs.map