bpmax-cli 0.1.28 → 0.1.30

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/README.md CHANGED
@@ -236,6 +236,29 @@ Running `npm install` or `npm run install:skills` copies project skills into det
236
236
 
237
237
  Only directories that already exist, or whose parent agent home exists, are targeted.
238
238
 
239
+ After installation, the script prints an agent-oriented guide. The recommended agent flow is:
240
+
241
+ 1. Ask the user to directly input any BPMAX workspace page URL in the target workspace.
242
+ 2. Initialize bpmax-cli for the current agent:
243
+
244
+ ```bash
245
+ bpmax-cli init --agent <agent> --channel feishu --url "<USER_URL>" --name local --format json
246
+ ```
247
+
248
+ 3. Show `message_card.authorization_url` and `message_card.user_code` to the user, then run `message_card.next_command` exactly after the user confirms the code.
249
+
250
+ For local terminal/browser setup, `bpmax-cli setup "<USER_URL>" --name local` remains available.
251
+
252
+ For business requests, first look for BPMAX Business Skills (BBS):
253
+
254
+ ```bash
255
+ bpmax-cli bbs list --profile <profile> --format json
256
+ bpmax-cli bbs sync --agent <agent> --profile <profile> --format json
257
+ bpmax-cli bbs ensure <skill-key> --agent <agent> --profile <profile> --format json
258
+ ```
259
+
260
+ Use `bbs sync` when there is no local/catalog match, then check again before falling back to generic flow/project/API commands. `bbs sync` installs only the catalog skill; individual business skills are installed lazily with `bbs ensure`.
261
+
239
262
  If `aily-skillhub` is available in `PATH`, the installer also runs:
240
263
 
241
264
  ```bash
package/dist/bin.js CHANGED
@@ -665,7 +665,7 @@ async function parseJsonInput(input, label = "JSON input") {
665
665
  // package.json
666
666
  var package_default = {
667
667
  name: "bpmax-cli",
668
- version: "0.1.28",
668
+ version: "0.1.30",
669
669
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
670
670
  type: "module",
671
671
  bin: {
@@ -1712,16 +1712,42 @@ function registerFlowCommands(program2) {
1712
1712
  );
1713
1713
  printResult(options.format, result);
1714
1714
  });
1715
- flow.command("get").description("Get flow detail by id").requiredOption("--id <id>", "Flow id").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (options) => {
1715
+ flow.command("get").description("Get flow detail by id or flow_type/flow_key").option("--id <id>", "Flow id").option("--flow-type <flowType>", "Flow type").option("--flow-key <flowKey>", "Flow key", "").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (options) => {
1716
1716
  const config = await loadConfig();
1717
1717
  const profile = resolveProfile(config, options.profile);
1718
+ const client = createApiClient(profile);
1719
+ if (options.flowType) {
1720
+ const result2 = await apiRequest(
1721
+ client,
1722
+ "GET",
1723
+ "/flow/flow_type",
1724
+ {
1725
+ params: {
1726
+ draft: "1",
1727
+ skip_i18n: "true"
1728
+ }
1729
+ }
1730
+ );
1731
+ printResult(
1732
+ options.format,
1733
+ result2.find((item) => item.flow_type === options.flowType && String(item.key || "") === options.flowKey) ?? null
1734
+ );
1735
+ return;
1736
+ }
1737
+ if (!options.id) {
1738
+ throw new Error("Either --id or --flow-type is required.");
1739
+ }
1740
+ const id = Number(options.id);
1741
+ if (!Number.isInteger(id)) {
1742
+ throw new Error("--id must be a numeric flow id. Use --flow-type for values like flow322497069.");
1743
+ }
1718
1744
  const result = await apiRequest(
1719
- createApiClient(profile),
1745
+ client,
1720
1746
  "POST",
1721
1747
  "/flow/batch_get",
1722
1748
  {
1723
1749
  data: {
1724
- ids: [Number(options.id)]
1750
+ ids: [id]
1725
1751
  }
1726
1752
  }
1727
1753
  );
@@ -1836,12 +1862,23 @@ async function checkSkillsSync(currentVersion, configDir = getConfigDir(), agent
1836
1862
  const current = await readSkillsStamp(configDir);
1837
1863
  return { current, target, inSync: current === target };
1838
1864
  }
1839
- function defaultPackageRoot() {
1840
- return path3.resolve(path3.dirname(fileURLToPath(import.meta.url)), "..", "..");
1865
+ async function resolvePackageRootFrom(entrypointPath) {
1866
+ const entryDir = path3.dirname(entrypointPath);
1867
+ if (path3.basename(entryDir) === "dist") {
1868
+ return path3.dirname(entryDir);
1869
+ }
1870
+ if (path3.basename(entryDir) === "core" && path3.basename(path3.dirname(entryDir)) === "src") {
1871
+ return path3.dirname(path3.dirname(entryDir));
1872
+ }
1873
+ return path3.resolve(entryDir, "..", "..");
1874
+ }
1875
+ async function defaultPackageRoot() {
1876
+ return resolvePackageRootFrom(fileURLToPath(import.meta.url));
1841
1877
  }
1842
1878
  async function runSkillsInstall(options = {}) {
1843
1879
  const runner = options.runner || runCommand;
1844
- const args = [path3.join(options.packageRoot || defaultPackageRoot(), "scripts", "install-skills.mjs")];
1880
+ const packageRoot = options.packageRoot || await defaultPackageRoot();
1881
+ const args = [path3.join(packageRoot, "scripts", "install-skills.mjs")];
1845
1882
  if (options.agent) {
1846
1883
  args.push("--json", "--agent", options.agent);
1847
1884
  }
@@ -2316,8 +2353,9 @@ async function promptAction(message, allowFormHandoff) {
2316
2353
  }
2317
2354
  async function promptProjectCreateForm(input) {
2318
2355
  const allowFormHandoff = input.allowFormHandoff === true;
2356
+ const requireName = input.requireName !== false;
2319
2357
  let name = input.name;
2320
- if (!name?.trim()) {
2358
+ if (requireName && !name?.trim()) {
2321
2359
  const value = await text2({
2322
2360
  message: "\u6D41\u7A0B\u5355\u6807\u9898 *",
2323
2361
  validate(candidate) {
@@ -2329,6 +2367,7 @@ async function promptProjectCreateForm(input) {
2329
2367
  cancelIfNeeded(value);
2330
2368
  name = String(value).trim();
2331
2369
  }
2370
+ name = name ?? "";
2332
2371
  const form = { ...input.form };
2333
2372
  const requiredFields = input.fields.filter((field) => field.required);
2334
2373
  const optionalFields = input.fields.filter((field) => !field.required);
@@ -2465,11 +2504,34 @@ function parseJson2(input) {
2465
2504
  }
2466
2505
  return JSON.parse(input);
2467
2506
  }
2468
- async function resolveFlowIdentifiers(client, options) {
2469
- if (options.flowType && options.flowKey !== void 0) {
2507
+ async function resolveFlowIdentifiers(client, options, resolveOptions = {}) {
2508
+ if (options.flowType) {
2509
+ const flowKey = options.flowKey ?? "";
2510
+ if (resolveOptions.loadDetail) {
2511
+ const flows2 = await apiRequest(
2512
+ client,
2513
+ "GET",
2514
+ "/flow/flow_type",
2515
+ {
2516
+ params: {
2517
+ draft: "1",
2518
+ skip_i18n: "true"
2519
+ }
2520
+ }
2521
+ );
2522
+ const flow2 = flows2.find((item) => item.flow_type === options.flowType && String(item.key || "") === flowKey);
2523
+ if (!flow2) {
2524
+ throw new Error(`Flow ${options.flowType}:${flowKey} not found.`);
2525
+ }
2526
+ return {
2527
+ flow_type: options.flowType,
2528
+ flow_key: flowKey,
2529
+ flowDetail: flow2
2530
+ };
2531
+ }
2470
2532
  return {
2471
2533
  flow_type: options.flowType,
2472
- flow_key: options.flowKey
2534
+ flow_key: flowKey
2473
2535
  };
2474
2536
  }
2475
2537
  if (!options.flowId) {
@@ -2603,7 +2665,20 @@ function assertCreateFormHandoffUrl(url, expectedInitValue, expectedFormKeys) {
2603
2665
  }
2604
2666
  function fieldsForValidation(flowDetail, projectFormTemplate) {
2605
2667
  const templateFields = projectFormTemplate ? extractFormFields(projectFormTemplate.template) : [];
2606
- return templateFields.length > 0 ? templateFields : extractFormFields(flowDetail);
2668
+ if (templateFields.length === 0) {
2669
+ return extractFormFields(flowDetail);
2670
+ }
2671
+ const flowFieldsByKey = new Map(extractFormFields(flowDetail).map((field) => [field.key, field]));
2672
+ return templateFields.map((field) => ({
2673
+ ...field,
2674
+ required: field.required || flowFieldsByKey.get(field.key)?.required === true
2675
+ }));
2676
+ }
2677
+ function metaUsesTemplateProjectName(flowDetail) {
2678
+ const data = isRecord5(flowDetail?.data) ? flowDetail.data : void 0;
2679
+ const meta = isRecord5(data?.meta) ? data.meta : void 0;
2680
+ const hideFields = Array.isArray(meta?.hide_fields) ? meta.hide_fields.map(String) : [];
2681
+ return meta?.use_template_project_name === true || hideFields.includes("project.name");
2607
2682
  }
2608
2683
  function formValidationErrors(fields, form) {
2609
2684
  return validateFormAgainstFields(form, fields).errors;
@@ -2762,7 +2837,7 @@ function registerProjectCommands(program2) {
2762
2837
  project: attachProjectDetailUrl(profile, context.project)
2763
2838
  });
2764
2839
  });
2765
- 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("--interactive", "Guide the user through filling project form fields").option("--no-interactive", "Disable the project create guide and submit directly when safe").option("--allow-form-handoff", "Allow interactive mode to hand off to the BPMAX web create form").option("--skip-form-validation", "Skip local form schema validation before submit").option("--format <format>", "Output format", "pretty").action(async (options, command) => {
2840
+ 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("--interactive", "Guide the user through filling project form fields").option("--no-interactive", "Disable the project create guide and submit directly when safe").option("--allow-form-handoff", "Allow interactive mode to hand off to the BPMAX web create form").option("--skip-form-validation", "Skip local form schema validation before submit").option("--format <format>", "Output format", "pretty").action(async (options, command) => {
2766
2841
  const interactiveSource = command.getOptionValueSource("interactive");
2767
2842
  if (options.body && options.interactive === true && interactiveSource === "cli") {
2768
2843
  throw new Error("--body and --interactive cannot be used together.");
@@ -2773,7 +2848,7 @@ function registerProjectCommands(program2) {
2773
2848
  const useInteractive = !options.body && options.interactive !== false;
2774
2849
  let payload = parseJson2(options.body);
2775
2850
  if (!options.body) {
2776
- const flow = await resolveFlowIdentifiers(client, options);
2851
+ const flow = await resolveFlowIdentifiers(client, options, { loadDetail: useInteractive });
2777
2852
  const { flowDetail, ...flowIdentifiers } = flow;
2778
2853
  const extra = parseJson2(options.json);
2779
2854
  const form = typeof extra.form === "object" && extra.form !== null && !Array.isArray(extra.form) ? extra.form : {};
@@ -2785,16 +2860,19 @@ function registerProjectCommands(program2) {
2785
2860
  }
2786
2861
  return projectFormTemplate;
2787
2862
  };
2863
+ const usesTemplateProjectName = metaUsesTemplateProjectName(flowDetail);
2788
2864
  if (useInteractive) {
2789
2865
  if (!flowDetail) {
2790
2866
  throw new Error("Interactive project creation requires --flow-id so the form schema can be discovered.");
2791
2867
  }
2792
- const fields = extractFormFields(flowDetail);
2868
+ projectFormTemplate = await loadProjectFormTemplate();
2869
+ const fields = fieldsForValidation(flowDetail, projectFormTemplate);
2793
2870
  const promptResult = await promptProjectCreateForm({
2794
- name,
2871
+ name: usesTemplateProjectName ? name ?? "" : name,
2795
2872
  form: { ...form },
2796
2873
  fields,
2797
- allowFormHandoff: options.allowFormHandoff === true
2874
+ allowFormHandoff: options.allowFormHandoff === true,
2875
+ ...usesTemplateProjectName ? { requireName: false } : {}
2798
2876
  });
2799
2877
  name = promptResult.name;
2800
2878
  Object.keys(form).forEach((key) => {
@@ -2805,7 +2883,6 @@ function registerProjectCommands(program2) {
2805
2883
  printResult(options.format, { cancelled: true });
2806
2884
  return;
2807
2885
  }
2808
- projectFormTemplate = await loadProjectFormTemplate();
2809
2886
  if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
2810
2887
  assertHandoffFormReady(fieldsForValidation(flowDetail, projectFormTemplate), form);
2811
2888
  printCreateFormHandoff(options.format, profile, flowIdentifiers, {
@@ -2829,7 +2906,7 @@ function registerProjectCommands(program2) {
2829
2906
  return;
2830
2907
  }
2831
2908
  }
2832
- if (!name) {
2909
+ if (!name && !usesTemplateProjectName) {
2833
2910
  throw new Error("--name is required unless --body is provided.");
2834
2911
  }
2835
2912
  projectFormTemplate = await loadProjectFormTemplate();
@@ -2847,7 +2924,7 @@ function registerProjectCommands(program2) {
2847
2924
  }
2848
2925
  assertHandoffFormReady(handoffFields, form);
2849
2926
  printCreateFormHandoff(options.format, profile, flowIdentifiers, {
2850
- name,
2927
+ name: name ?? "",
2851
2928
  form,
2852
2929
  reason: "form_template_auto_init_lambda",
2853
2930
  message: "\u68C0\u6D4B\u5230\u8868\u5355\u6A21\u677F\u5305\u542B\u81EA\u52A8\u521D\u59CB\u5316\u811A\u672C\uFF0C\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002"
@@ -2860,7 +2937,7 @@ function registerProjectCommands(program2) {
2860
2937
  ...projectExtra,
2861
2938
  ...projectFlowIdentifiers,
2862
2939
  key: flowKey,
2863
- name,
2940
+ ...name ? { name } : {},
2864
2941
  workspace: profile.config.workspace,
2865
2942
  ...projectExtra.projectForm ? {} : await buildProjectFormPayload(client, flowDetail, form, projectFormTemplate)
2866
2943
  };