bpmax-cli 0.1.32 → 0.1.34

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
@@ -29,10 +29,13 @@ bpmax-cli init \
29
29
  --agent openclaw \
30
30
  --channel feishu \
31
31
  --url https://example.com/w:store_mgr \
32
- --name retail \
32
+ --name local \
33
+ --profile-scope "<TRUSTED_RUNTIME_SCOPE>" \
33
34
  --format json
34
35
  ```
35
36
 
37
+ For OpenClaw multi-user deployments, `TRUSTED_RUNTIME_SCOPE` must come from trusted runtime metadata such as channel + peer/user, or at least a stable user id. The LLM should not invent it, and follow-up commands must use the returned `profile`.
38
+
36
39
  The command saves the profile, syncs bundled skills for the selected agent adapter, and returns a `message_card` with:
37
40
 
38
41
  - `authorization_url`
@@ -242,9 +245,11 @@ After installation, the script prints an agent-oriented guide. The recommended a
242
245
  2. Initialize bpmax-cli for the current agent:
243
246
 
244
247
  ```bash
245
- bpmax-cli init --agent <agent> --channel feishu --url "<USER_URL>" --name local --format json
248
+ bpmax-cli init --agent <agent> --channel feishu --url "<USER_URL>" --name local --profile-scope "<TRUSTED_RUNTIME_SCOPE>" --format json
246
249
  ```
247
250
 
251
+ For OpenClaw multi-user deployments, `TRUSTED_RUNTIME_SCOPE` must come from trusted runtime metadata such as channel + peer/user, or at least a stable user id. Do not ask the LLM to invent this value. The final profile name is the `profile` returned by `init`; do not reuse `local` for follow-up commands.
252
+
248
253
  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
254
 
250
255
  For local terminal/browser setup, `bpmax-cli setup "<USER_URL>" --name local` remains available.
package/dist/bin.js CHANGED
@@ -6,6 +6,7 @@ import { Command } from "commander";
6
6
  // src/core/config.ts
7
7
  import { homedir } from "os";
8
8
  import { mkdir, readFile, writeFile } from "fs/promises";
9
+ import { createHash } from "crypto";
9
10
  import path from "path";
10
11
 
11
12
  // src/core/setup-guide.ts
@@ -84,6 +85,14 @@ function getConfigDir() {
84
85
  function getProfileDataDir(profileName) {
85
86
  return path.join(CONFIG_DIR, "profiles", profileName);
86
87
  }
88
+ function hashProfileScope(scope) {
89
+ return createHash("sha256").update(scope.trim()).digest("hex").slice(0, 12);
90
+ }
91
+ function scopedProfileName(baseProfile, agent, scope) {
92
+ const safeBase = baseProfile.trim().replace(/[^a-zA-Z0-9._-]+/g, "_") || "default";
93
+ const safeAgent = agent.trim().replace(/[^a-zA-Z0-9._-]+/g, "_") || "generic";
94
+ return `${safeBase}__${safeAgent}__${hashProfileScope(scope)}`;
95
+ }
87
96
  function maskApiKey(apiKey) {
88
97
  if (!apiKey) {
89
98
  return "(unset)";
@@ -665,7 +674,7 @@ async function parseJsonInput(input, label = "JSON input") {
665
674
  // package.json
666
675
  var package_default = {
667
676
  name: "bpmax-cli",
668
- version: "0.1.32",
677
+ version: "0.1.34",
669
678
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
670
679
  type: "module",
671
680
  bin: {
@@ -827,7 +836,7 @@ function attachProjectDetailUrl(profile, value) {
827
836
 
828
837
  // src/core/business-skills.ts
829
838
  import { cp, mkdir as mkdir2, readFile as readFile3, rm, stat, writeFile as writeFile2 } from "fs/promises";
830
- import { createHash } from "crypto";
839
+ import { createHash as createHash2 } from "crypto";
831
840
  import { homedir as homedir2, tmpdir } from "os";
832
841
  import path2 from "path";
833
842
  import { setTimeout as delay } from "timers/promises";
@@ -1304,7 +1313,7 @@ async function downloadBusinessSkillPackage(profile, download) {
1304
1313
  responseType: "arraybuffer"
1305
1314
  })).data
1306
1315
  );
1307
- const checksum = createHash("sha256").update(buffer).digest("hex");
1316
+ const checksum = createHash2("sha256").update(buffer).digest("hex");
1308
1317
  if (download.checksum && checksum !== download.checksum) {
1309
1318
  throw new Error(`BBS checksum mismatch. expected ${download.checksum}, got ${checksum}`);
1310
1319
  }
@@ -1363,7 +1372,7 @@ async function buildCatalogSkill(skills) {
1363
1372
  await writeFile2(path2.join(dir, "SKILL.md"), body, "utf8");
1364
1373
  return {
1365
1374
  dir,
1366
- checksum: createHash("sha256").update(body).digest("hex")
1375
+ checksum: createHash2("sha256").update(body).digest("hex")
1367
1376
  };
1368
1377
  }
1369
1378
 
@@ -1913,14 +1922,39 @@ function parseSkillsDetail(stdout) {
1913
1922
  return void 0;
1914
1923
  }
1915
1924
  }
1925
+ var SHARED_OPENCLAW_PROFILES = /* @__PURE__ */ new Set(["default", "local"]);
1926
+ var OPENCLAW_SCOPE_REQUIRED_MESSAGE = 'OpenClaw multi-user initialization with shared profile names "local" or "default" requires --profile-scope from trusted runtime metadata.';
1927
+ function isSharedOpenClawProfile(agent, profileName) {
1928
+ return agent === "openclaw" && SHARED_OPENCLAW_PROFILES.has(profileName);
1929
+ }
1916
1930
  function registerInitCommand(program2, deps = {}) {
1917
1931
  const loadConfig2 = deps.loadConfig || loadConfig;
1918
1932
  const saveConfig2 = deps.saveConfig || saveConfig;
1919
1933
  const syncSkills2 = deps.syncSkills || syncSkills;
1920
1934
  const startDeviceLogin2 = deps.startDeviceLogin || startDeviceLogin;
1921
- program2.command("init").description("Initialize bpmax-cli for browserless agent environments").requiredOption("--url <url>", "Full BPMAX workspace URL, for example https://example.com/w:store_mgr").option("--name <name>", "Profile name", "default").option("--agent <agent>", "Agent adapter: openclaw | aily | codex | claude | gemini | generic", "generic").option("--channel <channel>", "Interaction channel: feishu | terminal | json", "json").option("--key-name <keyName>", "Target API key name", "bpmax-cli").option("--language <language>", "Default language", DEFAULT_LANGUAGE).option("--force-skills", "Force skills reinstall").option("--format <format>", "Output format", "pretty").action(async (options) => {
1935
+ program2.command("init").description("Initialize bpmax-cli for browserless agent environments").requiredOption("--url <url>", "Full BPMAX workspace URL, for example https://example.com/w:store_mgr").option("--name <name>", "Profile name", "default").option("--profile-scope <scope>", "Trusted runtime scope for agent-user profile isolation").option("--agent <agent>", "Agent adapter: openclaw | aily | codex | claude | gemini | generic", "generic").option("--channel <channel>", "Interaction channel: feishu | terminal | json", "json").option("--key-name <keyName>", "Target API key name", "bpmax-cli").option("--language <language>", "Default language", DEFAULT_LANGUAGE).option("--force-skills", "Force skills reinstall").option("--format <format>", "Output format", "pretty").action(async (options) => {
1922
1936
  const parsed = parseBpmUrl(options.url);
1923
- const profileName = options.name || "default";
1937
+ const baseProfileName = options.name || "default";
1938
+ if (isSharedOpenClawProfile(options.agent, baseProfileName) && !options.profileScope?.trim()) {
1939
+ if (options.format === "json") {
1940
+ printResult("json", {
1941
+ ok: false,
1942
+ error: {
1943
+ code: "profile_scope_required",
1944
+ message: OPENCLAW_SCOPE_REQUIRED_MESSAGE,
1945
+ agent: options.agent,
1946
+ base_profile: baseProfileName,
1947
+ requires: "--profile-scope"
1948
+ }
1949
+ });
1950
+ process.exitCode = 1;
1951
+ return;
1952
+ }
1953
+ throw new Error(OPENCLAW_SCOPE_REQUIRED_MESSAGE);
1954
+ }
1955
+ const profileScope = options.profileScope?.trim();
1956
+ const profileName = profileScope ? scopedProfileName(baseProfileName, options.agent, profileScope) : baseProfileName;
1957
+ const profileScopeHash = profileScope ? hashProfileScope(profileScope) : void 0;
1924
1958
  const config = await loadConfig2();
1925
1959
  const nextConfig = applySetupProfile(config, profileName, {
1926
1960
  origin: parsed.origin,
@@ -1943,6 +1977,11 @@ function registerInitCommand(program2, deps = {}) {
1943
1977
  printResult(options.format, {
1944
1978
  ok: true,
1945
1979
  profile: profileName,
1980
+ ...profileScope ? {
1981
+ base_profile: baseProfileName,
1982
+ profile_isolated: true,
1983
+ profile_scope_hash: profileScopeHash
1984
+ } : {},
1946
1985
  origin: parsed.origin,
1947
1986
  workspace: parsed.workspace,
1948
1987
  agent: options.agent,
@@ -1975,6 +2014,8 @@ var FIELD_LABEL_NAMES = ["label", "title", "display_name", "displayName", "text"
1975
2014
  var FIELD_TYPE_NAMES = ["type", "field_type", "fieldType", "value_type", "valueType", "control", "component", "widget"];
1976
2015
  var OPTION_NAMES = ["options", "items", "choices", "values"];
1977
2016
  var REQUIRED_NAMES = ["required", "is_required", "isRequired", "require", "must", "validateRequired"];
2017
+ var HIDDEN_NAMES = ["hidden", "is_hidden", "isHidden", "hide", "hideInForm"];
2018
+ var VISIBLE_NAMES = ["visible", "display", "show"];
1978
2019
  function isRecord3(value) {
1979
2020
  return typeof value === "object" && value !== null && !Array.isArray(value);
1980
2021
  }
@@ -2004,6 +2045,25 @@ function pickBoolean(source, keys) {
2004
2045
  if (Array.isArray(rules)) {
2005
2046
  return rules.some((rule) => isRecord3(rule) && pickBoolean(rule, REQUIRED_NAMES));
2006
2047
  }
2048
+ const validateMap = source.validateMap;
2049
+ if (isRecord3(validateMap) && pickBoolean(validateMap, REQUIRED_NAMES)) {
2050
+ return true;
2051
+ }
2052
+ return false;
2053
+ }
2054
+ function pickHidden(source) {
2055
+ for (const key of HIDDEN_NAMES) {
2056
+ const value = source[key];
2057
+ if (value === true || value === 1 || value === "1" || value === "true") {
2058
+ return true;
2059
+ }
2060
+ }
2061
+ for (const key of VISIBLE_NAMES) {
2062
+ const value = source[key];
2063
+ if (value === false || value === 0 || value === "0" || value === "false") {
2064
+ return true;
2065
+ }
2066
+ }
2007
2067
  return false;
2008
2068
  }
2009
2069
  function optionValue(option) {
@@ -2037,6 +2097,7 @@ function fieldFromRecord(source) {
2037
2097
  const label = pickString(source, FIELD_LABEL_NAMES);
2038
2098
  const options = pickOptions(source);
2039
2099
  const required = pickBoolean(source, REQUIRED_NAMES);
2100
+ const hidden = pickHidden(source);
2040
2101
  if (!type && !label && !options && !required) {
2041
2102
  return null;
2042
2103
  }
@@ -2045,6 +2106,7 @@ function fieldFromRecord(source) {
2045
2106
  ...label ? { label } : {},
2046
2107
  ...type ? { type } : {},
2047
2108
  required,
2109
+ ...hidden ? { hidden } : {},
2048
2110
  ...options ? { options } : {}
2049
2111
  };
2050
2112
  }
@@ -2054,10 +2116,12 @@ function isSubFormField(field) {
2054
2116
  }
2055
2117
  function mergeField(existing, incoming) {
2056
2118
  const children = incoming.children ?? existing?.children;
2119
+ const hidden = incoming.hidden === true || existing?.hidden === true && incoming.hidden !== false;
2057
2120
  return {
2058
2121
  ...existing,
2059
2122
  ...incoming,
2060
2123
  required: Boolean(existing?.required || incoming.required),
2124
+ ...hidden ? { hidden } : {},
2061
2125
  ...children?.length ? { children } : {}
2062
2126
  };
2063
2127
  }
@@ -2123,6 +2187,15 @@ function validateComplexSelector(field, value) {
2123
2187
  function isComplexSelectorType(type) {
2124
2188
  return /(plugin_city_selector|plugin_project_selector|plugin_user_selector|plugin_department_selector|relation_project|relation_form|user_selector|department_selector|group_select|project_selector_new)/.test(type);
2125
2189
  }
2190
+ function isEnumSelectType(type) {
2191
+ return /enum_select/.test(type);
2192
+ }
2193
+ function optionComparableValue(value) {
2194
+ if (isRecord3(value) && ("value" in value || "label" in value)) {
2195
+ return value.value ?? value.label;
2196
+ }
2197
+ return value;
2198
+ }
2126
2199
  function validateType(field, value) {
2127
2200
  const type = field.type?.toLowerCase() ?? "";
2128
2201
  if (!type || isEmpty(value)) {
@@ -2143,7 +2216,7 @@ function validateType(field, value) {
2143
2216
  return null;
2144
2217
  }
2145
2218
  if (field.options) {
2146
- const values = Array.isArray(value) ? value.map(String) : [String(value)];
2219
+ const values = Array.isArray(value) ? value.map((item) => String(optionComparableValue(item))) : [String(optionComparableValue(value))];
2147
2220
  const invalid = values.filter((item) => !field.options?.includes(item));
2148
2221
  if (invalid.length > 0) {
2149
2222
  return `${field.key} has invalid option value(s): ${invalid.join(", ")}`;
@@ -2158,6 +2231,10 @@ function validateType(field, value) {
2158
2231
  if (/(array|multi|multiple)/.test(type) && !Array.isArray(value)) {
2159
2232
  return `${field.key} must be an array`;
2160
2233
  }
2234
+ if (isEnumSelectType(type) && isRecord3(value)) {
2235
+ const optionValue2 = value.value ?? value.label;
2236
+ return typeof optionValue2 === "string" || typeof optionValue2 === "number" ? null : `${field.key} must be an enum option object with a scalar value`;
2237
+ }
2161
2238
  if (/(string|text|textarea|input|date|time|select|user|department)/.test(type) && typeof value === "object" && value !== null && !Array.isArray(value)) {
2162
2239
  return `${field.key} must be a scalar value`;
2163
2240
  }
@@ -2749,10 +2826,6 @@ function assertHandoffFormCompatible(fields, form) {
2749
2826
  function isEmptyValue(value) {
2750
2827
  return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
2751
2828
  }
2752
- function isSuggestedManualField(field) {
2753
- const type = field.type?.toLowerCase() ?? "";
2754
- return /(plugin_|selector|relation_|sub[_-]?form|associated[_-]?form|table|upload|image|file|attachment)/.test(type);
2755
- }
2756
2829
  function contextField(field, reason, options = {}) {
2757
2830
  return {
2758
2831
  key: options.path ?? field.key,
@@ -2775,10 +2848,8 @@ function collectPrefillContextForFields(fields, form, result, options = {}) {
2775
2848
  parentKey: options.parentKey
2776
2849
  };
2777
2850
  if (isEmptyValue(value)) {
2778
- if (field.required) {
2851
+ if (field.required && !field.hidden) {
2779
2852
  result.missing_fields.push(contextField(field, "required_empty", fieldOptions));
2780
- } else if (isSuggestedManualField(field)) {
2781
- result.suggested_fields.push(contextField(field, "manual_confirm_recommended", fieldOptions));
2782
2853
  }
2783
2854
  continue;
2784
2855
  }