bpmax-cli 0.1.7 → 0.1.9

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.
package/dist/bin.js CHANGED
@@ -81,6 +81,9 @@ function getConfigPath() {
81
81
  function getConfigDir() {
82
82
  return CONFIG_DIR;
83
83
  }
84
+ function getProfileDataDir(profileName) {
85
+ return path.join(CONFIG_DIR, "profiles", profileName);
86
+ }
84
87
  function maskApiKey(apiKey) {
85
88
  if (!apiKey) {
86
89
  return "(unset)";
@@ -138,14 +141,14 @@ async function upsertProfile(name, nextProfile) {
138
141
 
139
142
  // src/core/http.ts
140
143
  import axios, { AxiosHeaders } from "axios";
141
- var ensureApiPath = (path4) => {
142
- if (!path4.startsWith("/")) {
143
- path4 = `/${path4}`;
144
+ var ensureApiPath = (path5) => {
145
+ if (!path5.startsWith("/")) {
146
+ path5 = `/${path5}`;
144
147
  }
145
- if (path4.startsWith("/api/")) {
146
- return path4;
148
+ if (path5.startsWith("/api/")) {
149
+ return path5;
147
150
  }
148
- return `/api${path4}`;
151
+ return `/api${path5}`;
149
152
  };
150
153
  function createApiClient(profile) {
151
154
  const instance = axios.create({
@@ -167,10 +170,10 @@ function createApiClient(profile) {
167
170
  });
168
171
  return instance;
169
172
  }
170
- async function apiRequest(client, method, path4, options = {}) {
173
+ async function apiRequest(client, method, path5, options = {}) {
171
174
  const response = await client.request({
172
175
  method,
173
- url: ensureApiPath(path4),
176
+ url: ensureApiPath(path5),
174
177
  params: options.params,
175
178
  data: options.data
176
179
  });
@@ -253,10 +256,10 @@ function parseJson(input) {
253
256
  return JSON.parse(input);
254
257
  }
255
258
  function registerApiCommands(program2) {
256
- program2.command("api <method> <path>").description("Call an arbitrary BPMAX /api endpoint").option("--profile <profile>", "Profile name").option("--params <json>", "Query params JSON").option("--data <json>", "Request body JSON").option("--format <format>", "Output format", "json").action(async (method, path4, options) => {
259
+ program2.command("api <method> <path>").description("Call an arbitrary BPMAX /api endpoint").option("--profile <profile>", "Profile name").option("--params <json>", "Query params JSON").option("--data <json>", "Request body JSON").option("--format <format>", "Output format", "json").action(async (method, path5, options) => {
257
260
  const config = await loadConfig();
258
261
  const profile = resolveProfile(config, options.profile);
259
- const result = await apiRequest(createApiClient(profile), method, path4, {
262
+ const result = await apiRequest(createApiClient(profile), method, path5, {
260
263
  params: parseJson(options.params),
261
264
  data: parseJson(options.data)
262
265
  });
@@ -711,6 +714,100 @@ function validateFormAgainstFields(form, fields) {
711
714
  return { fields, errors };
712
715
  }
713
716
 
717
+ // src/core/urls.ts
718
+ function stripSlashes(value) {
719
+ return value.trim().replace(/^\/+|\/+$/g, "");
720
+ }
721
+ function isRecord3(value) {
722
+ return typeof value === "object" && value !== null && !Array.isArray(value);
723
+ }
724
+ function normalizeWorkspaceForUrl(workspace) {
725
+ const nextWorkspace = stripSlashes(workspace);
726
+ if (!nextWorkspace) {
727
+ throw new Error("Workspace is required to build a BPMAX URL.");
728
+ }
729
+ if (nextWorkspace === "default" || nextWorkspace.startsWith("w:")) {
730
+ return nextWorkspace;
731
+ }
732
+ return `w:${nextWorkspace}`;
733
+ }
734
+ function normalizeOrigin2(origin) {
735
+ const nextOrigin = origin.trim().replace(/\/+$/, "");
736
+ if (!nextOrigin) {
737
+ throw new Error("Origin is required to build a BPMAX URL.");
738
+ }
739
+ return nextOrigin;
740
+ }
741
+ function requireNumericId(value, name) {
742
+ const nextValue = String(value || "").trim();
743
+ if (!/^\d+$/.test(nextValue)) {
744
+ throw new Error(`${name} must be a non-empty numeric string.`);
745
+ }
746
+ return nextValue;
747
+ }
748
+ function withQuery(path5, query) {
749
+ const params = new URLSearchParams(query);
750
+ return `${path5}?${params.toString()}`;
751
+ }
752
+ function buildBpmaxUrl(profile, kind, params = {}) {
753
+ const origin = normalizeOrigin2(profile.config.origin);
754
+ const workspace = normalizeWorkspaceForUrl(params.workspace || profile.config.workspace);
755
+ const basePath = `/${workspace}`;
756
+ let path5 = basePath;
757
+ const result = {
758
+ kind,
759
+ profile: profile.name,
760
+ origin,
761
+ workspace
762
+ };
763
+ if (kind === "project-list") {
764
+ path5 = `${basePath}/project`;
765
+ } else if (kind === "project-detail") {
766
+ const projectId = requireNumericId(params.projectId, "projectId");
767
+ path5 = `${basePath}/project_detail/0/${projectId}`;
768
+ result.project_id = projectId;
769
+ } else if (kind === "project-step") {
770
+ const projectId = requireNumericId(params.projectId, "projectId");
771
+ const stepId = requireNumericId(params.stepId, "stepId");
772
+ path5 = withQuery(`${basePath}/projectContinue`, {
773
+ id: projectId,
774
+ step_id: stepId
775
+ });
776
+ result.project_id = projectId;
777
+ result.step_id = stepId;
778
+ }
779
+ return {
780
+ ...result,
781
+ path: path5,
782
+ url: `${origin}${path5}`
783
+ };
784
+ }
785
+ function extractProjectId(value) {
786
+ if (!isRecord3(value)) {
787
+ return void 0;
788
+ }
789
+ const candidates = [value.id, value.project_id, value.projectId];
790
+ const candidate = candidates.find((item) => item !== void 0 && item !== null);
791
+ if (candidate === void 0) {
792
+ return void 0;
793
+ }
794
+ const projectId = String(candidate).trim();
795
+ return /^\d+$/.test(projectId) ? projectId : void 0;
796
+ }
797
+ function attachProjectDetailUrl(profile, value) {
798
+ if (!isRecord3(value) || typeof value.url === "string") {
799
+ return value;
800
+ }
801
+ const projectId = extractProjectId(value);
802
+ if (!projectId) {
803
+ return value;
804
+ }
805
+ return {
806
+ ...value,
807
+ url: buildBpmaxUrl(profile, "project-detail", { projectId }).url
808
+ };
809
+ }
810
+
714
811
  // src/commands/project.ts
715
812
  function parseJson2(input) {
716
813
  if (!input) {
@@ -804,7 +901,7 @@ function registerProjectCommands(program2) {
804
901
  "GET",
805
902
  `/project/${id}`
806
903
  );
807
- printResult(options.format, result);
904
+ printResult(options.format, attachProjectDetailUrl(profile, result));
808
905
  });
809
906
  project.command("my-step").description("List my pending project steps").option("--profile <profile>", "Profile name").option("--finished <finished>", "Finished flag", "0").option("--page <page>", "Page number", "1").option("--page-size <pageSize>", "Page size", "20").option("--format <format>", "Output format", "table").action(async (options) => {
810
907
  const config = await loadConfig();
@@ -855,7 +952,366 @@ function registerProjectCommands(program2) {
855
952
  data: payload
856
953
  }
857
954
  );
858
- printResult(options.format, result);
955
+ printResult(options.format, attachProjectDetailUrl(profile, result));
956
+ });
957
+ }
958
+
959
+ // src/commands/recipe.ts
960
+ import { spawn } from "child_process";
961
+ import { fileURLToPath } from "url";
962
+
963
+ // src/core/recipes.ts
964
+ import { access, mkdir as mkdir2, readdir, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
965
+ import path2 from "path";
966
+ var RECIPE_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
967
+ var TEMPLATE_PATTERN = /{{\s*([a-zA-Z0-9_.-]+)\s*}}/g;
968
+ function assertSafeName(kind, value) {
969
+ if (!RECIPE_NAME_PATTERN.test(value) || value.includes("..") || value.includes("/") || value.includes("\\")) {
970
+ throw new Error(`${kind} must contain only letters, numbers, dots, underscores, and dashes.`);
971
+ }
972
+ }
973
+ function normalizeWorkspaceForPath(workspace) {
974
+ const normalized = (workspace || DEFAULT_WORKSPACE).trim() || DEFAULT_WORKSPACE;
975
+ const withoutPrefix = normalized.startsWith("w:") ? normalized.slice(2) : normalized;
976
+ assertSafeName("Workspace", withoutPrefix);
977
+ return withoutPrefix;
978
+ }
979
+ function resolveRecipeLocation(options) {
980
+ assertSafeName("Recipe name", options.recipeName);
981
+ const workspace = options.workspace || DEFAULT_WORKSPACE;
982
+ const workspaceDirName = normalizeWorkspaceForPath(workspace);
983
+ const profileDir = (options.getProfileDir || getProfileDataDir)(options.profileName);
984
+ return {
985
+ profileName: options.profileName,
986
+ workspace,
987
+ workspaceDirName,
988
+ recipeName: options.recipeName,
989
+ recipeDir: path2.join(profileDir, "recipes", workspaceDirName, options.recipeName)
990
+ };
991
+ }
992
+ function getRecipesDir(options) {
993
+ const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
994
+ return path2.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
995
+ }
996
+ function isRecord4(value) {
997
+ return typeof value === "object" && value !== null && !Array.isArray(value);
998
+ }
999
+ function asString(value, fieldName) {
1000
+ if (typeof value !== "string" || !value.trim()) {
1001
+ throw new Error(`${fieldName} must be a non-empty string.`);
1002
+ }
1003
+ return value;
1004
+ }
1005
+ function parseRecipeDefinition(input) {
1006
+ if (!isRecord4(input)) {
1007
+ throw new Error("recipe.json must be a JSON object.");
1008
+ }
1009
+ if (input.version !== 1) {
1010
+ throw new Error("recipe.json version must be 1.");
1011
+ }
1012
+ const name = asString(input.name, "recipe.name");
1013
+ assertSafeName("Recipe name", name);
1014
+ if (!isRecord4(input.command)) {
1015
+ throw new Error("recipe.command must be an object.");
1016
+ }
1017
+ const argv = input.command.argv;
1018
+ if (!Array.isArray(argv) || argv.some((item) => typeof item !== "string" || item.length === 0)) {
1019
+ throw new Error("recipe.command.argv must be a non-empty string array.");
1020
+ }
1021
+ const variables = Array.isArray(input.variables) ? input.variables.map((item, index) => {
1022
+ if (!isRecord4(item)) {
1023
+ throw new Error(`recipe.variables[${index}] must be an object.`);
1024
+ }
1025
+ const variableName = asString(item.name, `recipe.variables[${index}].name`);
1026
+ assertSafeName("Variable name", variableName);
1027
+ return {
1028
+ name: variableName,
1029
+ required: item.required === void 0 ? void 0 : Boolean(item.required)
1030
+ };
1031
+ }) : void 0;
1032
+ return {
1033
+ version: 1,
1034
+ name,
1035
+ ...typeof input.title === "string" ? { title: input.title } : {},
1036
+ ...typeof input.description === "string" ? { description: input.description } : {},
1037
+ ...typeof input.workspace === "string" ? { workspace: input.workspace } : {},
1038
+ ...variables ? { variables } : {},
1039
+ command: {
1040
+ argv,
1041
+ mutating: Boolean(input.command.mutating)
1042
+ }
1043
+ };
1044
+ }
1045
+ async function loadRecipe(recipeDir) {
1046
+ const raw = await readFile2(path2.join(recipeDir, "recipe.json"), "utf8");
1047
+ return parseRecipeDefinition(JSON.parse(raw));
1048
+ }
1049
+ async function listRecipes(recipesDir) {
1050
+ let entries;
1051
+ try {
1052
+ entries = await readdir(recipesDir);
1053
+ } catch (error) {
1054
+ if (error.code === "ENOENT") {
1055
+ return [];
1056
+ }
1057
+ throw error;
1058
+ }
1059
+ const summaries = [];
1060
+ for (const entry of entries.sort()) {
1061
+ if (!RECIPE_NAME_PATTERN.test(entry)) {
1062
+ continue;
1063
+ }
1064
+ const recipeDir = path2.join(recipesDir, entry);
1065
+ try {
1066
+ const recipe = await loadRecipe(recipeDir);
1067
+ summaries.push({
1068
+ name: recipe.name,
1069
+ title: recipe.title,
1070
+ description: recipe.description,
1071
+ workspace: recipe.workspace,
1072
+ path: recipeDir,
1073
+ mutating: Boolean(recipe.command.mutating)
1074
+ });
1075
+ } catch {
1076
+ }
1077
+ }
1078
+ return summaries;
1079
+ }
1080
+ function parseVarEntries(entries = []) {
1081
+ const variables = {};
1082
+ for (const entry of entries) {
1083
+ const index = entry.indexOf("=");
1084
+ if (index <= 0) {
1085
+ throw new Error(`Invalid --var value "${entry}". Expected key=value.`);
1086
+ }
1087
+ const key = entry.slice(0, index);
1088
+ assertSafeName("Variable name", key);
1089
+ variables[key] = entry.slice(index + 1);
1090
+ }
1091
+ return variables;
1092
+ }
1093
+ function parseVarsJson(input) {
1094
+ if (!input) {
1095
+ return {};
1096
+ }
1097
+ const parsed = JSON.parse(input);
1098
+ if (!isRecord4(parsed)) {
1099
+ throw new Error("--vars must be a JSON object.");
1100
+ }
1101
+ const variables = {};
1102
+ for (const [key, value] of Object.entries(parsed)) {
1103
+ assertSafeName("Variable name", key);
1104
+ variables[key] = String(value);
1105
+ }
1106
+ return variables;
1107
+ }
1108
+ function mergeVariables(varsJson, varEntries = []) {
1109
+ return {
1110
+ ...parseVarsJson(varsJson),
1111
+ ...parseVarEntries(varEntries)
1112
+ };
1113
+ }
1114
+ function validateRequiredVariables(recipe, variables) {
1115
+ const missing = (recipe.variables || []).filter((variable) => variable.required && !Object.prototype.hasOwnProperty.call(variables, variable.name)).map((variable) => variable.name);
1116
+ if (missing.length > 0) {
1117
+ throw new Error(`Missing required recipe variable(s): ${missing.join(", ")}.`);
1118
+ }
1119
+ }
1120
+ function renderTemplate(template, variables) {
1121
+ return template.replace(TEMPLATE_PATTERN, (match, variableName) => {
1122
+ if (!Object.prototype.hasOwnProperty.call(variables, variableName)) {
1123
+ throw new Error(`Missing recipe variable: ${variableName}.`);
1124
+ }
1125
+ return variables[variableName];
1126
+ });
1127
+ }
1128
+ function resolveRecipeFile(recipeDir, token) {
1129
+ const relative = token.slice(1);
1130
+ if (!relative || relative.includes("..") || path2.isAbsolute(relative)) {
1131
+ throw new Error(`Unsafe recipe file reference: ${token}`);
1132
+ }
1133
+ const resolved = path2.resolve(recipeDir, relative);
1134
+ const root = path2.resolve(recipeDir);
1135
+ if (resolved !== root && !resolved.startsWith(`${root}${path2.sep}`)) {
1136
+ throw new Error(`Recipe file reference escapes recipe directory: ${token}`);
1137
+ }
1138
+ return resolved;
1139
+ }
1140
+ async function renderArgv(options) {
1141
+ validateRequiredVariables(options.recipe, options.variables);
1142
+ const rendered = [];
1143
+ for (const token of options.recipe.command.argv) {
1144
+ if (token.startsWith("@")) {
1145
+ const raw = await readFile2(resolveRecipeFile(options.recipeDir, token), "utf8");
1146
+ rendered.push(renderTemplate(raw, options.variables));
1147
+ } else {
1148
+ rendered.push(renderTemplate(token, options.variables));
1149
+ }
1150
+ }
1151
+ if (!rendered.includes("--profile")) {
1152
+ rendered.push("--profile", options.profileName);
1153
+ }
1154
+ return rendered;
1155
+ }
1156
+ async function ensureEmptyOrForce(targetDir, force = false) {
1157
+ try {
1158
+ await access(targetDir);
1159
+ if (!force) {
1160
+ throw new Error(`Recipe already exists at ${targetDir}. Re-run with --force to overwrite scaffold files.`);
1161
+ }
1162
+ } catch (error) {
1163
+ if (error.code === "ENOENT") {
1164
+ return;
1165
+ }
1166
+ throw error;
1167
+ }
1168
+ }
1169
+ async function writeRecipeScaffold(options) {
1170
+ await ensureEmptyOrForce(options.location.recipeDir, options.force);
1171
+ await mkdir2(options.location.recipeDir, { recursive: true });
1172
+ const title = options.title || options.location.recipeName;
1173
+ const recipe = {
1174
+ version: 1,
1175
+ name: options.location.recipeName,
1176
+ title,
1177
+ description: "Describe what this BPMAX environment recipe does.",
1178
+ workspace: options.location.workspaceDirName,
1179
+ variables: [{ name: "name", required: true }],
1180
+ command: {
1181
+ argv: ["project", "create", "--body", "@payload.json", "--format", "json"],
1182
+ mutating: true
1183
+ }
1184
+ };
1185
+ await writeFile2(path2.join(options.location.recipeDir, "recipe.json"), `${JSON.stringify(recipe, null, 2)}
1186
+ `, "utf8");
1187
+ await writeFile2(
1188
+ path2.join(options.location.recipeDir, "payload.json"),
1189
+ `${JSON.stringify({ name: "{{name}}" }, null, 2)}
1190
+ `,
1191
+ "utf8"
1192
+ );
1193
+ await writeFile2(
1194
+ path2.join(options.location.recipeDir, "README.md"),
1195
+ [`# ${title}`, "", "Describe the BPMAX flow, field mapping, prerequisites, and verification steps for this recipe.", ""].join("\n"),
1196
+ "utf8"
1197
+ );
1198
+ }
1199
+
1200
+ // src/commands/recipe.ts
1201
+ function currentCliInvocation() {
1202
+ const entry = process.argv[1] || fileURLToPath(import.meta.url);
1203
+ return {
1204
+ command: process.execPath,
1205
+ argsPrefix: [entry]
1206
+ };
1207
+ }
1208
+ function defaultRunRecipe(argv) {
1209
+ const invocation = currentCliInvocation();
1210
+ return new Promise((resolve, reject) => {
1211
+ const child = spawn(invocation.command, [...invocation.argsPrefix, ...argv], {
1212
+ stdio: "inherit",
1213
+ shell: false
1214
+ });
1215
+ child.on("error", reject);
1216
+ child.on("close", (code) => resolve(code ?? 1));
1217
+ });
1218
+ }
1219
+ function resolveTargetProfile(configData, profileName) {
1220
+ const resolved = resolveProfile(configData, profileName);
1221
+ return {
1222
+ name: resolved.name,
1223
+ workspace: resolved.config.workspace || DEFAULT_WORKSPACE
1224
+ };
1225
+ }
1226
+ function collectVarEntries(value) {
1227
+ if (!value) {
1228
+ return [];
1229
+ }
1230
+ return Array.isArray(value) ? value : [value];
1231
+ }
1232
+ function registerRecipeCommands(program2, deps = {}) {
1233
+ const load = deps.loadConfig || loadConfig;
1234
+ const getProfileDir = deps.getProfileDataDir;
1235
+ const runRecipe = deps.runRecipe || defaultRunRecipe;
1236
+ const recipe = program2.command("recipe").description("Manage profile-scoped BPMAX recipes");
1237
+ recipe.command("init <name>").description("Create a scaffold for a profile/workspace recipe").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--title <title>", "Recipe title").option("--force", "Overwrite existing scaffold files").option("--format <format>", "Output format", "pretty").action(async (name, options) => {
1238
+ const configData = await load();
1239
+ const target = resolveTargetProfile(configData, options.profile);
1240
+ const location = resolveRecipeLocation({
1241
+ profileName: target.name,
1242
+ workspace: options.workspace || target.workspace,
1243
+ recipeName: name,
1244
+ getProfileDir
1245
+ });
1246
+ await writeRecipeScaffold({ location, title: options.title, force: options.force });
1247
+ printResult(options.format, {
1248
+ name,
1249
+ profile: target.name,
1250
+ workspace: location.workspaceDirName,
1251
+ path: location.recipeDir
1252
+ });
1253
+ });
1254
+ recipe.command("list").description("List recipes for a profile/workspace").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--format <format>", "Output format", "table").action(async (options) => {
1255
+ const configData = await load();
1256
+ const target = resolveTargetProfile(configData, options.profile);
1257
+ const workspace = options.workspace || target.workspace;
1258
+ const rows = await listRecipes(getRecipesDir({ profileName: target.name, workspace, getProfileDir }));
1259
+ printResult(options.format, rows);
1260
+ });
1261
+ recipe.command("show <name>").description("Show a recipe definition").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--format <format>", "Output format", "pretty").action(async (name, options) => {
1262
+ const configData = await load();
1263
+ const target = resolveTargetProfile(configData, options.profile);
1264
+ const location = resolveRecipeLocation({
1265
+ profileName: target.name,
1266
+ workspace: options.workspace || target.workspace,
1267
+ recipeName: name,
1268
+ getProfileDir
1269
+ });
1270
+ const definition = await loadRecipe(location.recipeDir);
1271
+ printResult(options.format, {
1272
+ ...definition,
1273
+ profile: target.name,
1274
+ path: location.recipeDir
1275
+ });
1276
+ });
1277
+ recipe.command("path <name>").description("Print a recipe directory path").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").action(async (name, options) => {
1278
+ const configData = await load();
1279
+ const target = resolveTargetProfile(configData, options.profile);
1280
+ const location = resolveRecipeLocation({
1281
+ profileName: target.name,
1282
+ workspace: options.workspace || target.workspace,
1283
+ recipeName: name,
1284
+ getProfileDir
1285
+ });
1286
+ console.log(location.recipeDir);
1287
+ });
1288
+ recipe.command("run <name>").description("Render and run a profile/workspace recipe through bpmax-cli").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--var <entry>", "Recipe variable as key=value", (value, previous = []) => [...previous, value], []).option("--vars <json>", "Recipe variables JSON object").option("--yes", "Confirm running a mutating recipe").option("--format <format>", "Output format", "pretty").action(async (name, options) => {
1289
+ const configData = await load();
1290
+ const target = resolveTargetProfile(configData, options.profile);
1291
+ const location = resolveRecipeLocation({
1292
+ profileName: target.name,
1293
+ workspace: options.workspace || target.workspace,
1294
+ recipeName: name,
1295
+ getProfileDir
1296
+ });
1297
+ const definition = await loadRecipe(location.recipeDir);
1298
+ if (definition.command.mutating && !options.yes) {
1299
+ throw new Error("Recipe is marked as mutating. Re-run with --yes to execute it.");
1300
+ }
1301
+ const variables = mergeVariables(options.vars, collectVarEntries(options.var));
1302
+ const argv = await renderArgv({
1303
+ recipe: definition,
1304
+ recipeDir: location.recipeDir,
1305
+ variables,
1306
+ profileName: target.name
1307
+ });
1308
+ const exitCode = await runRecipe(argv);
1309
+ if (exitCode !== 0) {
1310
+ throw new Error(`Recipe command failed with exit code ${exitCode}.`);
1311
+ }
1312
+ if (options.format === "json") {
1313
+ printResult("json", { name, profile: target.name, workspace: location.workspaceDirName, argv, exitCode });
1314
+ }
859
1315
  });
860
1316
  }
861
1317
 
@@ -1052,7 +1508,7 @@ function registerSetupCommand(program2, deps = {}) {
1052
1508
  // package.json
1053
1509
  var package_default = {
1054
1510
  name: "bpmax-cli",
1055
- version: "0.1.7",
1511
+ version: "0.1.9",
1056
1512
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
1057
1513
  type: "module",
1058
1514
  bin: {
@@ -1096,14 +1552,14 @@ var VERSION = package_default.version;
1096
1552
  var NPM_PACKAGE = "bpmax-cli";
1097
1553
 
1098
1554
  // src/core/skills.ts
1099
- import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
1100
- import path2 from "path";
1101
- import { fileURLToPath } from "url";
1555
+ import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
1556
+ import path3 from "path";
1557
+ import { fileURLToPath as fileURLToPath2 } from "url";
1102
1558
 
1103
1559
  // src/core/process.ts
1104
- import { spawn } from "child_process";
1560
+ import { spawn as spawn2 } from "child_process";
1105
1561
  var runCommand = (command, args, options = {}) => new Promise((resolve) => {
1106
- const child = spawn(command, args, {
1562
+ const child = spawn2(command, args, {
1107
1563
  cwd: options.cwd,
1108
1564
  env: options.env,
1109
1565
  stdio: ["ignore", "pipe", "pipe"]
@@ -1155,18 +1611,18 @@ var runCommand = (command, args, options = {}) => new Promise((resolve) => {
1155
1611
  var SKILLS_STAMP_FILE = "skills.stamp";
1156
1612
  var SKILLS_INSTALL_TIMEOUT_MS = 2 * 60 * 1e3;
1157
1613
  function stampPath(configDir = getConfigDir()) {
1158
- return path2.join(configDir, SKILLS_STAMP_FILE);
1614
+ return path3.join(configDir, SKILLS_STAMP_FILE);
1159
1615
  }
1160
1616
  async function readSkillsStamp(configDir = getConfigDir()) {
1161
1617
  try {
1162
- return (await readFile2(stampPath(configDir), "utf8")).trim();
1618
+ return (await readFile3(stampPath(configDir), "utf8")).trim();
1163
1619
  } catch {
1164
1620
  return "";
1165
1621
  }
1166
1622
  }
1167
1623
  async function writeSkillsStamp(version, configDir = getConfigDir()) {
1168
- await mkdir2(configDir, { recursive: true });
1169
- await writeFile2(stampPath(configDir), version, "utf8");
1624
+ await mkdir3(configDir, { recursive: true });
1625
+ await writeFile3(stampPath(configDir), version, "utf8");
1170
1626
  }
1171
1627
  async function checkSkillsSync(currentVersion, configDir = getConfigDir()) {
1172
1628
  if (process.env.BPMAX_CLI_NO_SKILLS_NOTIFIER) {
@@ -1176,11 +1632,11 @@ async function checkSkillsSync(currentVersion, configDir = getConfigDir()) {
1176
1632
  return { current, target: currentVersion, inSync: current === currentVersion };
1177
1633
  }
1178
1634
  function defaultPackageRoot() {
1179
- return path2.resolve(path2.dirname(fileURLToPath(import.meta.url)), "..", "..");
1635
+ return path3.resolve(path3.dirname(fileURLToPath2(import.meta.url)), "..", "..");
1180
1636
  }
1181
1637
  async function runSkillsInstall(options = {}) {
1182
1638
  const runner = options.runner || runCommand;
1183
- return runner(process.execPath, [path2.join(options.packageRoot || defaultPackageRoot(), "scripts", "install-skills.mjs")], {
1639
+ return runner(process.execPath, [path3.join(options.packageRoot || defaultPackageRoot(), "scripts", "install-skills.mjs")], {
1184
1640
  timeoutMs: SKILLS_INSTALL_TIMEOUT_MS
1185
1641
  });
1186
1642
  }
@@ -1200,8 +1656,8 @@ async function syncSkills(version, options = {}) {
1200
1656
  }
1201
1657
 
1202
1658
  // src/core/update.ts
1203
- import { access, mkdir as mkdir3, readFile as readFile3, realpath, writeFile as writeFile3 } from "fs/promises";
1204
- import path3 from "path";
1659
+ import { access as access2, mkdir as mkdir4, readFile as readFile4, realpath, writeFile as writeFile4 } from "fs/promises";
1660
+ import path4 from "path";
1205
1661
  var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/";
1206
1662
  var UPDATE_STATE_FILE = "update-state.json";
1207
1663
  var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
@@ -1313,11 +1769,11 @@ async function fetchLatestVersion(options = {}) {
1313
1769
  }
1314
1770
  }
1315
1771
  function updateStatePath(configDir = getConfigDir()) {
1316
- return path3.join(configDir, UPDATE_STATE_FILE);
1772
+ return path4.join(configDir, UPDATE_STATE_FILE);
1317
1773
  }
1318
1774
  async function readUpdateState(configDir) {
1319
1775
  try {
1320
- const raw = await readFile3(updateStatePath(configDir), "utf8");
1776
+ const raw = await readFile4(updateStatePath(configDir), "utf8");
1321
1777
  const parsed = JSON.parse(raw);
1322
1778
  if (typeof parsed.latest_version !== "string" || typeof parsed.checked_at !== "number") {
1323
1779
  return null;
@@ -1328,8 +1784,8 @@ async function readUpdateState(configDir) {
1328
1784
  }
1329
1785
  }
1330
1786
  async function writeUpdateState(state, configDir = getConfigDir()) {
1331
- await mkdir3(configDir, { recursive: true });
1332
- await writeFile3(updateStatePath(configDir), JSON.stringify(state), "utf8");
1787
+ await mkdir4(configDir, { recursive: true });
1788
+ await writeFile4(updateStatePath(configDir), JSON.stringify(state), "utf8");
1333
1789
  }
1334
1790
  async function checkCachedUpdate(currentVersion, configDir = getConfigDir()) {
1335
1791
  if (process.env.BPMAX_CLI_NO_UPDATE_NOTIFIER) {
@@ -1381,7 +1837,7 @@ async function findNpmPath() {
1381
1837
  }
1382
1838
  function detectInstallMethod(input) {
1383
1839
  const resolvedPath = input.executablePath || "";
1384
- const method = resolvedPath.includes(`node_modules${path3.sep}`) || resolvedPath.includes("node_modules/") ? "npm" : "manual";
1840
+ const method = resolvedPath.includes(`node_modules${path4.sep}`) || resolvedPath.includes("node_modules/") ? "npm" : "manual";
1385
1841
  return {
1386
1842
  method,
1387
1843
  resolvedPath,
@@ -1559,6 +2015,47 @@ ${detail}` : ""}`);
1559
2015
  });
1560
2016
  }
1561
2017
 
2018
+ // src/commands/url.ts
2019
+ function printUrl(format, result) {
2020
+ if (format === "pretty") {
2021
+ console.log(result.url);
2022
+ return;
2023
+ }
2024
+ printResult(format, result);
2025
+ }
2026
+ async function resolveUrl(load, kind, options) {
2027
+ const config = await load();
2028
+ const profile = resolveProfile(config, options.profile);
2029
+ printUrl(
2030
+ options.format,
2031
+ buildBpmaxUrl(profile, kind, {
2032
+ workspace: options.workspace,
2033
+ projectId: options.projectId,
2034
+ stepId: options.stepId
2035
+ })
2036
+ );
2037
+ }
2038
+ function registerUrlCommands(program2, deps = {}) {
2039
+ const load = deps.loadConfig || loadConfig;
2040
+ const url = program2.command("url").description("Generate BPMAX web URLs");
2041
+ url.command("workspace").description("Generate the current workspace URL").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--format <format>", "Output format", "pretty").action(async (options) => {
2042
+ await resolveUrl(load, "workspace", options);
2043
+ });
2044
+ url.command("project-list").description("Generate the project list URL").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--format <format>", "Output format", "pretty").action(async (options) => {
2045
+ await resolveUrl(load, "project-list", options);
2046
+ });
2047
+ url.command("project-detail <projectId>").description("Generate a project detail URL").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--format <format>", "Output format", "pretty").action(
2048
+ async (projectId, options) => {
2049
+ await resolveUrl(load, "project-detail", { ...options, projectId });
2050
+ }
2051
+ );
2052
+ url.command("project-step <projectId>").description("Generate a project step processing URL").requiredOption("--step-id <stepId>", "Step id").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--format <format>", "Output format", "pretty").action(
2053
+ async (projectId, options) => {
2054
+ await resolveUrl(load, "project-step", { ...options, projectId });
2055
+ }
2056
+ );
2057
+ }
2058
+
1562
2059
  // src/commands/user.ts
1563
2060
  function registerUserCommands(program2) {
1564
2061
  const user = program2.command("user").description("User commands");
@@ -1654,6 +2151,8 @@ registerSchemaCommands(program);
1654
2151
  registerUserCommands(program);
1655
2152
  registerFlowCommands(program);
1656
2153
  registerProjectCommands(program);
2154
+ registerRecipeCommands(program);
2155
+ registerUrlCommands(program);
1657
2156
  registerSetupCommand(program);
1658
2157
  registerUpdateCommands(program);
1659
2158
  var isCompletion = process.argv.includes("completion") || process.argv.includes("__complete");