bpmax-cli 0.1.6 → 0.1.8

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
  });
@@ -542,6 +545,175 @@ function registerFlowCommands(program2) {
542
545
  });
543
546
  }
544
547
 
548
+ // src/core/form-schema.ts
549
+ var FIELD_KEY_NAMES = [
550
+ "key",
551
+ "field_key",
552
+ "fieldKey",
553
+ "field",
554
+ "code",
555
+ "prop",
556
+ "name",
557
+ "data_index",
558
+ "dataIndex",
559
+ "id"
560
+ ];
561
+ var FIELD_LABEL_NAMES = ["label", "title", "display_name", "displayName", "text"];
562
+ var FIELD_TYPE_NAMES = ["type", "field_type", "fieldType", "value_type", "valueType", "control", "component", "widget"];
563
+ var OPTION_NAMES = ["options", "items", "choices", "values"];
564
+ var REQUIRED_NAMES = ["required", "is_required", "isRequired", "require", "must"];
565
+ function isRecord2(value) {
566
+ return typeof value === "object" && value !== null && !Array.isArray(value);
567
+ }
568
+ function pickString(source, keys) {
569
+ for (const key of keys) {
570
+ const value = source[key];
571
+ if (typeof value === "string" && value.trim()) {
572
+ return value.trim();
573
+ }
574
+ if (typeof value === "number" && Number.isFinite(value)) {
575
+ return String(value);
576
+ }
577
+ }
578
+ return void 0;
579
+ }
580
+ function pickBoolean(source, keys) {
581
+ for (const key of keys) {
582
+ const value = source[key];
583
+ if (typeof value === "boolean") {
584
+ return value;
585
+ }
586
+ if (value === 1 || value === "1" || value === "true") {
587
+ return true;
588
+ }
589
+ }
590
+ const rules = source.rules;
591
+ if (Array.isArray(rules)) {
592
+ return rules.some((rule) => isRecord2(rule) && pickBoolean(rule, REQUIRED_NAMES));
593
+ }
594
+ return false;
595
+ }
596
+ function optionValue(option) {
597
+ if (typeof option === "string" || typeof option === "number") {
598
+ return String(option);
599
+ }
600
+ if (!isRecord2(option)) {
601
+ return null;
602
+ }
603
+ return pickString(option, ["value", "key", "id", "name", "label", "title"]) ?? null;
604
+ }
605
+ function pickOptions(source) {
606
+ for (const key of OPTION_NAMES) {
607
+ const value = source[key];
608
+ if (!Array.isArray(value)) {
609
+ continue;
610
+ }
611
+ const options = value.map(optionValue).filter((item) => Boolean(item));
612
+ if (options.length > 0) {
613
+ return options;
614
+ }
615
+ }
616
+ return void 0;
617
+ }
618
+ function fieldFromRecord(source) {
619
+ const key = pickString(source, FIELD_KEY_NAMES);
620
+ if (!key) {
621
+ return null;
622
+ }
623
+ const type = pickString(source, FIELD_TYPE_NAMES);
624
+ const label = pickString(source, FIELD_LABEL_NAMES);
625
+ const options = pickOptions(source);
626
+ const required = pickBoolean(source, REQUIRED_NAMES);
627
+ if (!type && !label && !options && !required) {
628
+ return null;
629
+ }
630
+ return {
631
+ key,
632
+ ...label ? { label } : {},
633
+ ...type ? { type } : {},
634
+ required,
635
+ ...options ? { options } : {}
636
+ };
637
+ }
638
+ function collectFieldCandidates(value, fields, depth = 0) {
639
+ if (depth > 8) {
640
+ return;
641
+ }
642
+ if (Array.isArray(value)) {
643
+ for (const item of value) {
644
+ collectFieldCandidates(item, fields, depth + 1);
645
+ }
646
+ return;
647
+ }
648
+ if (!isRecord2(value)) {
649
+ return;
650
+ }
651
+ const field = fieldFromRecord(value);
652
+ if (field) {
653
+ fields.set(field.key, { ...fields.get(field.key), ...field });
654
+ }
655
+ for (const child of Object.values(value)) {
656
+ if (isRecord2(child) || Array.isArray(child)) {
657
+ collectFieldCandidates(child, fields, depth + 1);
658
+ }
659
+ }
660
+ }
661
+ function extractFormFields(flowDetail) {
662
+ const fields = /* @__PURE__ */ new Map();
663
+ collectFieldCandidates(flowDetail, fields);
664
+ return [...fields.values()].sort((left, right) => left.key.localeCompare(right.key));
665
+ }
666
+ function isEmpty(value) {
667
+ return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
668
+ }
669
+ function validateType(field, value) {
670
+ const type = field.type?.toLowerCase() ?? "";
671
+ if (!type || isEmpty(value)) {
672
+ return null;
673
+ }
674
+ if (field.options) {
675
+ const values = Array.isArray(value) ? value.map(String) : [String(value)];
676
+ const invalid = values.filter((item) => !field.options?.includes(item));
677
+ if (invalid.length > 0) {
678
+ return `${field.key} has invalid option value(s): ${invalid.join(", ")}`;
679
+ }
680
+ }
681
+ if (/(number|int|decimal|float|double|amount)/.test(type) && typeof value !== "number") {
682
+ return `${field.key} must be a number`;
683
+ }
684
+ if (/(boolean|bool|switch|checkbox)/.test(type) && typeof value !== "boolean") {
685
+ return `${field.key} must be a boolean`;
686
+ }
687
+ if (/(array|multi|multiple)/.test(type) && !Array.isArray(value)) {
688
+ return `${field.key} must be an array`;
689
+ }
690
+ if (/(string|text|textarea|input|date|time|select|user|department)/.test(type) && typeof value === "object" && value !== null && !Array.isArray(value)) {
691
+ return `${field.key} must be a scalar value`;
692
+ }
693
+ return null;
694
+ }
695
+ function validateFormAgainstFields(form, fields) {
696
+ const byKey = new Map(fields.map((field) => [field.key, field]));
697
+ const errors = [];
698
+ for (const field of fields) {
699
+ if (field.required && isEmpty(form[field.key])) {
700
+ errors.push(`${field.key} is required`);
701
+ }
702
+ }
703
+ for (const [key, value] of Object.entries(form)) {
704
+ const field = byKey.get(key);
705
+ if (!field) {
706
+ errors.push(`${key} is not defined in the flow create form`);
707
+ continue;
708
+ }
709
+ const typeError = validateType(field, value);
710
+ if (typeError) {
711
+ errors.push(typeError);
712
+ }
713
+ }
714
+ return { fields, errors };
715
+ }
716
+
545
717
  // src/commands/project.ts
546
718
  function parseJson2(input) {
547
719
  if (!input) {
@@ -573,9 +745,41 @@ async function resolveFlowIdentifiers(client, options) {
573
745
  }
574
746
  return {
575
747
  flow_type: String(flow.flow_type || "default"),
576
- flow_key: String(flow.key || "")
748
+ flow_key: String(flow.key || ""),
749
+ flowDetail: flow
577
750
  };
578
751
  }
752
+ async function validateCreateForm(client, options) {
753
+ if (Object.keys(options.form).length === 0) {
754
+ return;
755
+ }
756
+ let flowDetail = options.flowDetail;
757
+ if (!flowDetail && options.flowId) {
758
+ const flows = await apiRequest(
759
+ client,
760
+ "POST",
761
+ "/flow/batch_get",
762
+ {
763
+ data: { ids: [Number(options.flowId)] }
764
+ }
765
+ );
766
+ flowDetail = flows[0];
767
+ }
768
+ const fields = extractFormFields(flowDetail);
769
+ if (fields.length === 0) {
770
+ throw new Error(
771
+ [
772
+ "Could not discover the flow create form schema for local validation.",
773
+ "Re-run with --skip-form-validation only if you intentionally want the server to validate the raw payload."
774
+ ].join("\n")
775
+ );
776
+ }
777
+ const result = validateFormAgainstFields(options.form, fields);
778
+ if (result.errors.length > 0) {
779
+ throw new Error(`Form validation failed:
780
+ - ${result.errors.join("\n- ")}`);
781
+ }
782
+ }
579
783
  function registerProjectCommands(program2) {
580
784
  const project = program2.command("project").description("Project commands");
581
785
  project.command("list").description("List projects").option("--profile <profile>", "Profile name").option("--page <page>", "Page number", "1").option("--page-size <pageSize>", "Page size", "20").option("--body <json>", "Project list body JSON", "{}").option("--format <format>", "Output format", "table").action(async (options) => {
@@ -622,7 +826,7 @@ function registerProjectCommands(program2) {
622
826
  );
623
827
  printResult(options.format, result);
624
828
  });
625
- project.command("create").description("Minimal project create shortcut").option("--profile <profile>", "Profile name").option("--flow-id <flowId>", "Flow id").option("--flow-type <flowType>", "Flow type").option("--flow-key <flowKey>", "Flow key").option("--name <name>", "Project name").option("--json <json>", "Additional request JSON").option("--body <body>", "Full request body JSON override").option("--format <format>", "Output format", "pretty").action(async (options) => {
829
+ project.command("create").description("Minimal project create shortcut").option("--profile <profile>", "Profile name").option("--flow-id <flowId>", "Flow id").option("--flow-type <flowType>", "Flow type").option("--flow-key <flowKey>", "Flow key").option("--name <name>", "Project name").option("--json <json>", "Additional request JSON").option("--body <body>", "Full request body JSON override").option("--skip-form-validation", "Skip local form schema validation before submit").option("--format <format>", "Output format", "pretty").action(async (options) => {
626
830
  const config = await loadConfig();
627
831
  const profile = resolveProfile(config, options.profile);
628
832
  const client = createApiClient(profile);
@@ -632,15 +836,19 @@ function registerProjectCommands(program2) {
632
836
  throw new Error("--name is required unless --body is provided.");
633
837
  }
634
838
  const flow = await resolveFlowIdentifiers(client, options);
839
+ const { flowDetail, ...flowIdentifiers } = flow;
635
840
  const extra = parseJson2(options.json);
636
841
  const form = typeof extra.form === "object" && extra.form !== null && !Array.isArray(extra.form) ? extra.form : {};
637
842
  payload = {
638
843
  ...extra,
639
- ...flow,
844
+ ...flowIdentifiers,
640
845
  name: options.name,
641
846
  workspace: profile.config.workspace,
642
847
  form
643
848
  };
849
+ if (!options.skipFormValidation) {
850
+ await validateCreateForm(client, { flowId: options.flowId, flowDetail, form });
851
+ }
644
852
  }
645
853
  const result = await apiRequest(
646
854
  client,
@@ -654,6 +862,365 @@ function registerProjectCommands(program2) {
654
862
  });
655
863
  }
656
864
 
865
+ // src/commands/recipe.ts
866
+ import { spawn } from "child_process";
867
+ import { fileURLToPath } from "url";
868
+
869
+ // src/core/recipes.ts
870
+ import { access, mkdir as mkdir2, readdir, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
871
+ import path2 from "path";
872
+ var RECIPE_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
873
+ var TEMPLATE_PATTERN = /{{\s*([a-zA-Z0-9_.-]+)\s*}}/g;
874
+ function assertSafeName(kind, value) {
875
+ if (!RECIPE_NAME_PATTERN.test(value) || value.includes("..") || value.includes("/") || value.includes("\\")) {
876
+ throw new Error(`${kind} must contain only letters, numbers, dots, underscores, and dashes.`);
877
+ }
878
+ }
879
+ function normalizeWorkspaceForPath(workspace) {
880
+ const normalized = (workspace || DEFAULT_WORKSPACE).trim() || DEFAULT_WORKSPACE;
881
+ const withoutPrefix = normalized.startsWith("w:") ? normalized.slice(2) : normalized;
882
+ assertSafeName("Workspace", withoutPrefix);
883
+ return withoutPrefix;
884
+ }
885
+ function resolveRecipeLocation(options) {
886
+ assertSafeName("Recipe name", options.recipeName);
887
+ const workspace = options.workspace || DEFAULT_WORKSPACE;
888
+ const workspaceDirName = normalizeWorkspaceForPath(workspace);
889
+ const profileDir = (options.getProfileDir || getProfileDataDir)(options.profileName);
890
+ return {
891
+ profileName: options.profileName,
892
+ workspace,
893
+ workspaceDirName,
894
+ recipeName: options.recipeName,
895
+ recipeDir: path2.join(profileDir, "recipes", workspaceDirName, options.recipeName)
896
+ };
897
+ }
898
+ function getRecipesDir(options) {
899
+ const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
900
+ return path2.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
901
+ }
902
+ function isRecord3(value) {
903
+ return typeof value === "object" && value !== null && !Array.isArray(value);
904
+ }
905
+ function asString(value, fieldName) {
906
+ if (typeof value !== "string" || !value.trim()) {
907
+ throw new Error(`${fieldName} must be a non-empty string.`);
908
+ }
909
+ return value;
910
+ }
911
+ function parseRecipeDefinition(input) {
912
+ if (!isRecord3(input)) {
913
+ throw new Error("recipe.json must be a JSON object.");
914
+ }
915
+ if (input.version !== 1) {
916
+ throw new Error("recipe.json version must be 1.");
917
+ }
918
+ const name = asString(input.name, "recipe.name");
919
+ assertSafeName("Recipe name", name);
920
+ if (!isRecord3(input.command)) {
921
+ throw new Error("recipe.command must be an object.");
922
+ }
923
+ const argv = input.command.argv;
924
+ if (!Array.isArray(argv) || argv.some((item) => typeof item !== "string" || item.length === 0)) {
925
+ throw new Error("recipe.command.argv must be a non-empty string array.");
926
+ }
927
+ const variables = Array.isArray(input.variables) ? input.variables.map((item, index) => {
928
+ if (!isRecord3(item)) {
929
+ throw new Error(`recipe.variables[${index}] must be an object.`);
930
+ }
931
+ const variableName = asString(item.name, `recipe.variables[${index}].name`);
932
+ assertSafeName("Variable name", variableName);
933
+ return {
934
+ name: variableName,
935
+ required: item.required === void 0 ? void 0 : Boolean(item.required)
936
+ };
937
+ }) : void 0;
938
+ return {
939
+ version: 1,
940
+ name,
941
+ ...typeof input.title === "string" ? { title: input.title } : {},
942
+ ...typeof input.description === "string" ? { description: input.description } : {},
943
+ ...typeof input.workspace === "string" ? { workspace: input.workspace } : {},
944
+ ...variables ? { variables } : {},
945
+ command: {
946
+ argv,
947
+ mutating: Boolean(input.command.mutating)
948
+ }
949
+ };
950
+ }
951
+ async function loadRecipe(recipeDir) {
952
+ const raw = await readFile2(path2.join(recipeDir, "recipe.json"), "utf8");
953
+ return parseRecipeDefinition(JSON.parse(raw));
954
+ }
955
+ async function listRecipes(recipesDir) {
956
+ let entries;
957
+ try {
958
+ entries = await readdir(recipesDir);
959
+ } catch (error) {
960
+ if (error.code === "ENOENT") {
961
+ return [];
962
+ }
963
+ throw error;
964
+ }
965
+ const summaries = [];
966
+ for (const entry of entries.sort()) {
967
+ if (!RECIPE_NAME_PATTERN.test(entry)) {
968
+ continue;
969
+ }
970
+ const recipeDir = path2.join(recipesDir, entry);
971
+ try {
972
+ const recipe = await loadRecipe(recipeDir);
973
+ summaries.push({
974
+ name: recipe.name,
975
+ title: recipe.title,
976
+ description: recipe.description,
977
+ workspace: recipe.workspace,
978
+ path: recipeDir,
979
+ mutating: Boolean(recipe.command.mutating)
980
+ });
981
+ } catch {
982
+ }
983
+ }
984
+ return summaries;
985
+ }
986
+ function parseVarEntries(entries = []) {
987
+ const variables = {};
988
+ for (const entry of entries) {
989
+ const index = entry.indexOf("=");
990
+ if (index <= 0) {
991
+ throw new Error(`Invalid --var value "${entry}". Expected key=value.`);
992
+ }
993
+ const key = entry.slice(0, index);
994
+ assertSafeName("Variable name", key);
995
+ variables[key] = entry.slice(index + 1);
996
+ }
997
+ return variables;
998
+ }
999
+ function parseVarsJson(input) {
1000
+ if (!input) {
1001
+ return {};
1002
+ }
1003
+ const parsed = JSON.parse(input);
1004
+ if (!isRecord3(parsed)) {
1005
+ throw new Error("--vars must be a JSON object.");
1006
+ }
1007
+ const variables = {};
1008
+ for (const [key, value] of Object.entries(parsed)) {
1009
+ assertSafeName("Variable name", key);
1010
+ variables[key] = String(value);
1011
+ }
1012
+ return variables;
1013
+ }
1014
+ function mergeVariables(varsJson, varEntries = []) {
1015
+ return {
1016
+ ...parseVarsJson(varsJson),
1017
+ ...parseVarEntries(varEntries)
1018
+ };
1019
+ }
1020
+ function validateRequiredVariables(recipe, variables) {
1021
+ const missing = (recipe.variables || []).filter((variable) => variable.required && !Object.prototype.hasOwnProperty.call(variables, variable.name)).map((variable) => variable.name);
1022
+ if (missing.length > 0) {
1023
+ throw new Error(`Missing required recipe variable(s): ${missing.join(", ")}.`);
1024
+ }
1025
+ }
1026
+ function renderTemplate(template, variables) {
1027
+ return template.replace(TEMPLATE_PATTERN, (match, variableName) => {
1028
+ if (!Object.prototype.hasOwnProperty.call(variables, variableName)) {
1029
+ throw new Error(`Missing recipe variable: ${variableName}.`);
1030
+ }
1031
+ return variables[variableName];
1032
+ });
1033
+ }
1034
+ function resolveRecipeFile(recipeDir, token) {
1035
+ const relative = token.slice(1);
1036
+ if (!relative || relative.includes("..") || path2.isAbsolute(relative)) {
1037
+ throw new Error(`Unsafe recipe file reference: ${token}`);
1038
+ }
1039
+ const resolved = path2.resolve(recipeDir, relative);
1040
+ const root = path2.resolve(recipeDir);
1041
+ if (resolved !== root && !resolved.startsWith(`${root}${path2.sep}`)) {
1042
+ throw new Error(`Recipe file reference escapes recipe directory: ${token}`);
1043
+ }
1044
+ return resolved;
1045
+ }
1046
+ async function renderArgv(options) {
1047
+ validateRequiredVariables(options.recipe, options.variables);
1048
+ const rendered = [];
1049
+ for (const token of options.recipe.command.argv) {
1050
+ if (token.startsWith("@")) {
1051
+ const raw = await readFile2(resolveRecipeFile(options.recipeDir, token), "utf8");
1052
+ rendered.push(renderTemplate(raw, options.variables));
1053
+ } else {
1054
+ rendered.push(renderTemplate(token, options.variables));
1055
+ }
1056
+ }
1057
+ if (!rendered.includes("--profile")) {
1058
+ rendered.push("--profile", options.profileName);
1059
+ }
1060
+ return rendered;
1061
+ }
1062
+ async function ensureEmptyOrForce(targetDir, force = false) {
1063
+ try {
1064
+ await access(targetDir);
1065
+ if (!force) {
1066
+ throw new Error(`Recipe already exists at ${targetDir}. Re-run with --force to overwrite scaffold files.`);
1067
+ }
1068
+ } catch (error) {
1069
+ if (error.code === "ENOENT") {
1070
+ return;
1071
+ }
1072
+ throw error;
1073
+ }
1074
+ }
1075
+ async function writeRecipeScaffold(options) {
1076
+ await ensureEmptyOrForce(options.location.recipeDir, options.force);
1077
+ await mkdir2(options.location.recipeDir, { recursive: true });
1078
+ const title = options.title || options.location.recipeName;
1079
+ const recipe = {
1080
+ version: 1,
1081
+ name: options.location.recipeName,
1082
+ title,
1083
+ description: "Describe what this BPMAX environment recipe does.",
1084
+ workspace: options.location.workspaceDirName,
1085
+ variables: [{ name: "name", required: true }],
1086
+ command: {
1087
+ argv: ["project", "create", "--body", "@payload.json", "--format", "json"],
1088
+ mutating: true
1089
+ }
1090
+ };
1091
+ await writeFile2(path2.join(options.location.recipeDir, "recipe.json"), `${JSON.stringify(recipe, null, 2)}
1092
+ `, "utf8");
1093
+ await writeFile2(
1094
+ path2.join(options.location.recipeDir, "payload.json"),
1095
+ `${JSON.stringify({ name: "{{name}}" }, null, 2)}
1096
+ `,
1097
+ "utf8"
1098
+ );
1099
+ await writeFile2(
1100
+ path2.join(options.location.recipeDir, "README.md"),
1101
+ [`# ${title}`, "", "Describe the BPMAX flow, field mapping, prerequisites, and verification steps for this recipe.", ""].join("\n"),
1102
+ "utf8"
1103
+ );
1104
+ }
1105
+
1106
+ // src/commands/recipe.ts
1107
+ function currentCliInvocation() {
1108
+ const entry = process.argv[1] || fileURLToPath(import.meta.url);
1109
+ return {
1110
+ command: process.execPath,
1111
+ argsPrefix: [entry]
1112
+ };
1113
+ }
1114
+ function defaultRunRecipe(argv) {
1115
+ const invocation = currentCliInvocation();
1116
+ return new Promise((resolve, reject) => {
1117
+ const child = spawn(invocation.command, [...invocation.argsPrefix, ...argv], {
1118
+ stdio: "inherit",
1119
+ shell: false
1120
+ });
1121
+ child.on("error", reject);
1122
+ child.on("close", (code) => resolve(code ?? 1));
1123
+ });
1124
+ }
1125
+ function resolveTargetProfile(configData, profileName) {
1126
+ const resolved = resolveProfile(configData, profileName);
1127
+ return {
1128
+ name: resolved.name,
1129
+ workspace: resolved.config.workspace || DEFAULT_WORKSPACE
1130
+ };
1131
+ }
1132
+ function collectVarEntries(value) {
1133
+ if (!value) {
1134
+ return [];
1135
+ }
1136
+ return Array.isArray(value) ? value : [value];
1137
+ }
1138
+ function registerRecipeCommands(program2, deps = {}) {
1139
+ const load = deps.loadConfig || loadConfig;
1140
+ const getProfileDir = deps.getProfileDataDir;
1141
+ const runRecipe = deps.runRecipe || defaultRunRecipe;
1142
+ const recipe = program2.command("recipe").description("Manage profile-scoped BPMAX recipes");
1143
+ 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) => {
1144
+ const configData = await load();
1145
+ const target = resolveTargetProfile(configData, options.profile);
1146
+ const location = resolveRecipeLocation({
1147
+ profileName: target.name,
1148
+ workspace: options.workspace || target.workspace,
1149
+ recipeName: name,
1150
+ getProfileDir
1151
+ });
1152
+ await writeRecipeScaffold({ location, title: options.title, force: options.force });
1153
+ printResult(options.format, {
1154
+ name,
1155
+ profile: target.name,
1156
+ workspace: location.workspaceDirName,
1157
+ path: location.recipeDir
1158
+ });
1159
+ });
1160
+ 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) => {
1161
+ const configData = await load();
1162
+ const target = resolveTargetProfile(configData, options.profile);
1163
+ const workspace = options.workspace || target.workspace;
1164
+ const rows = await listRecipes(getRecipesDir({ profileName: target.name, workspace, getProfileDir }));
1165
+ printResult(options.format, rows);
1166
+ });
1167
+ 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) => {
1168
+ const configData = await load();
1169
+ const target = resolveTargetProfile(configData, options.profile);
1170
+ const location = resolveRecipeLocation({
1171
+ profileName: target.name,
1172
+ workspace: options.workspace || target.workspace,
1173
+ recipeName: name,
1174
+ getProfileDir
1175
+ });
1176
+ const definition = await loadRecipe(location.recipeDir);
1177
+ printResult(options.format, {
1178
+ ...definition,
1179
+ profile: target.name,
1180
+ path: location.recipeDir
1181
+ });
1182
+ });
1183
+ recipe.command("path <name>").description("Print a recipe directory path").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").action(async (name, options) => {
1184
+ const configData = await load();
1185
+ const target = resolveTargetProfile(configData, options.profile);
1186
+ const location = resolveRecipeLocation({
1187
+ profileName: target.name,
1188
+ workspace: options.workspace || target.workspace,
1189
+ recipeName: name,
1190
+ getProfileDir
1191
+ });
1192
+ console.log(location.recipeDir);
1193
+ });
1194
+ 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) => {
1195
+ const configData = await load();
1196
+ const target = resolveTargetProfile(configData, options.profile);
1197
+ const location = resolveRecipeLocation({
1198
+ profileName: target.name,
1199
+ workspace: options.workspace || target.workspace,
1200
+ recipeName: name,
1201
+ getProfileDir
1202
+ });
1203
+ const definition = await loadRecipe(location.recipeDir);
1204
+ if (definition.command.mutating && !options.yes) {
1205
+ throw new Error("Recipe is marked as mutating. Re-run with --yes to execute it.");
1206
+ }
1207
+ const variables = mergeVariables(options.vars, collectVarEntries(options.var));
1208
+ const argv = await renderArgv({
1209
+ recipe: definition,
1210
+ recipeDir: location.recipeDir,
1211
+ variables,
1212
+ profileName: target.name
1213
+ });
1214
+ const exitCode = await runRecipe(argv);
1215
+ if (exitCode !== 0) {
1216
+ throw new Error(`Recipe command failed with exit code ${exitCode}.`);
1217
+ }
1218
+ if (options.format === "json") {
1219
+ printResult("json", { name, profile: target.name, workspace: location.workspaceDirName, argv, exitCode });
1220
+ }
1221
+ });
1222
+ }
1223
+
657
1224
  // src/core/manifest.ts
658
1225
  var schemaEntries = [
659
1226
  { name: "auth.login", description: "Open hpt-frontend bridge page and persist API key locally." },
@@ -666,7 +1233,7 @@ var schemaEntries = [
666
1233
  { name: "project.list", description: "List projects.", method: "POST", path: "/api/project/list" },
667
1234
  { name: "project.get", description: "Get project detail.", method: "GET", path: "/api/project/:id" },
668
1235
  { name: "project.my-step", description: "List my pending steps.", method: "GET", path: "/api/project/my_step" },
669
- { name: "project.create", description: "Minimal project create shortcut.", method: "POST", path: "/api/project/open-api/create" }
1236
+ { name: "project.create", description: "Create a project with local form schema validation when form payload is provided.", method: "POST", path: "/api/project/open-api/create" }
670
1237
  ];
671
1238
 
672
1239
  // src/commands/schema.ts
@@ -847,7 +1414,7 @@ function registerSetupCommand(program2, deps = {}) {
847
1414
  // package.json
848
1415
  var package_default = {
849
1416
  name: "bpmax-cli",
850
- version: "0.1.6",
1417
+ version: "0.1.8",
851
1418
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
852
1419
  type: "module",
853
1420
  bin: {
@@ -891,14 +1458,14 @@ var VERSION = package_default.version;
891
1458
  var NPM_PACKAGE = "bpmax-cli";
892
1459
 
893
1460
  // src/core/skills.ts
894
- import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
895
- import path2 from "path";
896
- import { fileURLToPath } from "url";
1461
+ import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
1462
+ import path3 from "path";
1463
+ import { fileURLToPath as fileURLToPath2 } from "url";
897
1464
 
898
1465
  // src/core/process.ts
899
- import { spawn } from "child_process";
1466
+ import { spawn as spawn2 } from "child_process";
900
1467
  var runCommand = (command, args, options = {}) => new Promise((resolve) => {
901
- const child = spawn(command, args, {
1468
+ const child = spawn2(command, args, {
902
1469
  cwd: options.cwd,
903
1470
  env: options.env,
904
1471
  stdio: ["ignore", "pipe", "pipe"]
@@ -950,18 +1517,18 @@ var runCommand = (command, args, options = {}) => new Promise((resolve) => {
950
1517
  var SKILLS_STAMP_FILE = "skills.stamp";
951
1518
  var SKILLS_INSTALL_TIMEOUT_MS = 2 * 60 * 1e3;
952
1519
  function stampPath(configDir = getConfigDir()) {
953
- return path2.join(configDir, SKILLS_STAMP_FILE);
1520
+ return path3.join(configDir, SKILLS_STAMP_FILE);
954
1521
  }
955
1522
  async function readSkillsStamp(configDir = getConfigDir()) {
956
1523
  try {
957
- return (await readFile2(stampPath(configDir), "utf8")).trim();
1524
+ return (await readFile3(stampPath(configDir), "utf8")).trim();
958
1525
  } catch {
959
1526
  return "";
960
1527
  }
961
1528
  }
962
1529
  async function writeSkillsStamp(version, configDir = getConfigDir()) {
963
- await mkdir2(configDir, { recursive: true });
964
- await writeFile2(stampPath(configDir), version, "utf8");
1530
+ await mkdir3(configDir, { recursive: true });
1531
+ await writeFile3(stampPath(configDir), version, "utf8");
965
1532
  }
966
1533
  async function checkSkillsSync(currentVersion, configDir = getConfigDir()) {
967
1534
  if (process.env.BPMAX_CLI_NO_SKILLS_NOTIFIER) {
@@ -971,11 +1538,11 @@ async function checkSkillsSync(currentVersion, configDir = getConfigDir()) {
971
1538
  return { current, target: currentVersion, inSync: current === currentVersion };
972
1539
  }
973
1540
  function defaultPackageRoot() {
974
- return path2.resolve(path2.dirname(fileURLToPath(import.meta.url)), "..", "..");
1541
+ return path3.resolve(path3.dirname(fileURLToPath2(import.meta.url)), "..", "..");
975
1542
  }
976
1543
  async function runSkillsInstall(options = {}) {
977
1544
  const runner = options.runner || runCommand;
978
- return runner(process.execPath, [path2.join(options.packageRoot || defaultPackageRoot(), "scripts", "install-skills.mjs")], {
1545
+ return runner(process.execPath, [path3.join(options.packageRoot || defaultPackageRoot(), "scripts", "install-skills.mjs")], {
979
1546
  timeoutMs: SKILLS_INSTALL_TIMEOUT_MS
980
1547
  });
981
1548
  }
@@ -995,8 +1562,8 @@ async function syncSkills(version, options = {}) {
995
1562
  }
996
1563
 
997
1564
  // src/core/update.ts
998
- import { access, mkdir as mkdir3, readFile as readFile3, realpath, writeFile as writeFile3 } from "fs/promises";
999
- import path3 from "path";
1565
+ import { access as access2, mkdir as mkdir4, readFile as readFile4, realpath, writeFile as writeFile4 } from "fs/promises";
1566
+ import path4 from "path";
1000
1567
  var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/";
1001
1568
  var UPDATE_STATE_FILE = "update-state.json";
1002
1569
  var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
@@ -1108,11 +1675,11 @@ async function fetchLatestVersion(options = {}) {
1108
1675
  }
1109
1676
  }
1110
1677
  function updateStatePath(configDir = getConfigDir()) {
1111
- return path3.join(configDir, UPDATE_STATE_FILE);
1678
+ return path4.join(configDir, UPDATE_STATE_FILE);
1112
1679
  }
1113
1680
  async function readUpdateState(configDir) {
1114
1681
  try {
1115
- const raw = await readFile3(updateStatePath(configDir), "utf8");
1682
+ const raw = await readFile4(updateStatePath(configDir), "utf8");
1116
1683
  const parsed = JSON.parse(raw);
1117
1684
  if (typeof parsed.latest_version !== "string" || typeof parsed.checked_at !== "number") {
1118
1685
  return null;
@@ -1123,8 +1690,8 @@ async function readUpdateState(configDir) {
1123
1690
  }
1124
1691
  }
1125
1692
  async function writeUpdateState(state, configDir = getConfigDir()) {
1126
- await mkdir3(configDir, { recursive: true });
1127
- await writeFile3(updateStatePath(configDir), JSON.stringify(state), "utf8");
1693
+ await mkdir4(configDir, { recursive: true });
1694
+ await writeFile4(updateStatePath(configDir), JSON.stringify(state), "utf8");
1128
1695
  }
1129
1696
  async function checkCachedUpdate(currentVersion, configDir = getConfigDir()) {
1130
1697
  if (process.env.BPMAX_CLI_NO_UPDATE_NOTIFIER) {
@@ -1176,7 +1743,7 @@ async function findNpmPath() {
1176
1743
  }
1177
1744
  function detectInstallMethod(input) {
1178
1745
  const resolvedPath = input.executablePath || "";
1179
- const method = resolvedPath.includes(`node_modules${path3.sep}`) || resolvedPath.includes("node_modules/") ? "npm" : "manual";
1746
+ const method = resolvedPath.includes(`node_modules${path4.sep}`) || resolvedPath.includes("node_modules/") ? "npm" : "manual";
1180
1747
  return {
1181
1748
  method,
1182
1749
  resolvedPath,
@@ -1449,6 +2016,7 @@ registerSchemaCommands(program);
1449
2016
  registerUserCommands(program);
1450
2017
  registerFlowCommands(program);
1451
2018
  registerProjectCommands(program);
2019
+ registerRecipeCommands(program);
1452
2020
  registerSetupCommand(program);
1453
2021
  registerUpdateCommands(program);
1454
2022
  var isCompletion = process.argv.includes("completion") || process.argv.includes("__complete");