bpmax-cli 0.1.40 → 0.1.42

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
@@ -172,12 +172,12 @@ bpmax-cli project create --profile yuanrong --flow-id 123 --format json
172
172
  Use `--no-interactive` only for explicit direct-submit automation. If the target form template contains page-only behavior such as auto-init lambda scripts, serial number controls, complex selectors, uploads, rich text, or sub forms, the CLI still refuses direct submit and prints a web form handoff URL with `reason: "form_template_requires_page_handoff"`.
173
173
  Direct `project create --body` is blocked by default because it bypasses flow form-template checks and can create an empty project shell. Use `project create --json` with a flow id/type so the CLI can detect page-only controls such as serial numbers, complex selectors, uploads, rich text, and sub forms. Only local experts should use `--unsafe-direct-create --body` for intentional legacy raw creation.
174
174
 
175
- ## ES project queries
175
+ ## Project search queries
176
176
 
177
- Use ES project search for high-volume reads and reporting-style queries that can be expressed with the huanpingtong project-list request body. The CLI calls `POST /api/project/list`, so BPMAX still applies project list permissions, workspace filters, and dataset hooks:
177
+ Use typed project search for high-volume reads, candidate lookup, form-field lookup, and reporting-style queries that can be expressed with the huanpingtong project list ES-mode request body. The CLI calls `POST /api/project/list`, so huanpingtong keeps API Key authentication and forwards the authenticated user context to bpmax-server project list logic:
178
178
 
179
179
  ```bash
180
- bpmax-cli es project-search --profile yuanrong --body @project-list-query.json --page 1 --page-size 20 --format json
180
+ bpmax-cli project search --profile yuanrong --body @project-search-query.json --page 1 --page-size 20 --format json
181
181
  ```
182
182
 
183
183
  ```json
@@ -192,9 +192,11 @@ bpmax-cli es project-search --profile yuanrong --body @project-list-query.json -
192
192
  }
193
193
  ```
194
194
 
195
- Raw Elasticsearch DTOs are intentionally not supported through `bpmax-cli es project-search`. `huanpingtong-server` does not expose `/api/project/raw-es-search` as a public endpoint, and legacy `/api/project/<id>` routing can fall through to project creation. If the payload contains a top-level `body` field, the CLI fails before sending any request.
195
+ `bpmax-cli es project-search` remains as a compatibility alias, but new Agent/BBS scenarios should use `bpmax-cli project search`.
196
196
 
197
- Use a project-list body instead:
197
+ Raw Elasticsearch DTOs are intentionally not supported through `bpmax-cli project search` or `bpmax-cli es project-search`. `huanpingtong-server` does not expose `/api/project/raw-es-search` as a public endpoint, and legacy `/api/project/<id>` routing can fall through to project creation. If the payload contains a top-level `body` field, the CLI fails before sending any request.
198
+
199
+ Use a project search body instead:
198
200
 
199
201
  ```json
200
202
  {
@@ -208,6 +210,17 @@ Use a project-list body instead:
208
210
  }
209
211
  ```
210
212
 
213
+ ## Server capabilities
214
+
215
+ Authenticated CLI API commands are gated by the huanpingtong server capability whitelist. The CLI refreshes `GET /api/cli/capabilities` after device authorization and before API commands when the local cache is missing or expired. If the current user is not granted the required capability, the CLI stops before sending the business request.
216
+
217
+ ```bash
218
+ bpmax-cli capabilities status --profile yuanrong --format json
219
+ bpmax-cli capabilities refresh --profile yuanrong --format json
220
+ ```
221
+
222
+ Use typed commands instead of raw API calls so the capability gate can map the request to a stable capability such as `project.search`, `project.create`, `step.submit`, or `bbs.ensure`.
223
+
211
224
  ## Profile recipes
212
225
 
213
226
  Profile recipes are local, profile-scoped playbooks for environment-specific BPMAX operations. They live outside project repositories under the active config directory:
@@ -305,7 +318,7 @@ bpmax-cli --config-dir <config_dir> bbs ensure <skill-key> --agent <agent> --pro
305
318
 
306
319
  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`.
307
320
 
308
- For mutating raw API calls, `bpmax-cli api` requires `--confirm-mutating` and supports `--data @file.json`. Raw API calls to `POST /project` or `POST /project/<anything>` are blocked even with `--confirm-mutating`; the only project POST allowed in raw mode is the read-style `/project/list`. Create projects through `bpmax-cli project create --flow-id <id> --json <json>` so the CLI can run form-template checks and choose safe direct submit or handoff. Prefer typed commands such as `step submit` for workflow state changes.
321
+ For mutating raw API calls, `bpmax-cli api` requires `--confirm-mutating` and supports `--data @file.json`. Raw API calls to `POST /project` or `POST /project/<anything>` are blocked even with `--confirm-mutating`; the only project POST allowed in raw mode is the read-style `/project/list`. Search projects through `bpmax-cli project search`, and create projects through `bpmax-cli project create --flow-id <id> --json <json>` so the CLI can run form-template checks and choose safe direct submit or handoff. Prefer typed commands such as `step submit` for workflow state changes.
309
322
 
310
323
  If `aily-skillhub` is available in `PATH`, the installer also runs:
311
324
 
package/dist/bin.js CHANGED
@@ -145,7 +145,8 @@ function resolveProfile(config, profileName) {
145
145
  api_key: profile.api_key,
146
146
  workspace: profile.workspace || DEFAULT_WORKSPACE,
147
147
  language: profile.language || DEFAULT_LANGUAGE,
148
- user: profile.user
148
+ user: profile.user,
149
+ capabilities_cache: profile.capabilities_cache
149
150
  }
150
151
  };
151
152
  }
@@ -167,6 +168,106 @@ async function upsertProfile(name, nextProfile) {
167
168
 
168
169
  // src/core/http.ts
169
170
  import axios, { AxiosHeaders } from "axios";
171
+
172
+ // src/core/capabilities.ts
173
+ function capabilityForRequest(method, path6) {
174
+ const normalizedMethod = method.toUpperCase();
175
+ const normalizedPath = normalizePath(path6);
176
+ if (normalizedPath === "/cli/capabilities") {
177
+ return void 0;
178
+ }
179
+ if (normalizedMethod === "GET" && normalizedPath === "/user/current") return "user.current";
180
+ if (normalizedMethod === "GET" && normalizedPath === "/workspace/by_key") return "flow.list";
181
+ if (normalizedMethod === "GET" && normalizedPath === "/flow/flow_type") return "flow.list";
182
+ if (normalizedMethod === "GET" && normalizedPath === "/flow/options") return "flow.options";
183
+ if (normalizedMethod === "POST" && normalizedPath === "/flow/batch_get") return "flow.get";
184
+ if (normalizedMethod === "GET" && normalizedPath.startsWith("/form_template/")) return "project.create";
185
+ if (normalizedMethod === "POST" && normalizedPath === "/project_staging/prefill") return "project.create";
186
+ if (normalizedMethod === "POST" && normalizedPath === "/project/search") return "project.search";
187
+ if (normalizedMethod === "POST" && normalizedPath === "/project/list") return "project.list";
188
+ if (normalizedMethod === "POST" && normalizedPath === "/project") return "project.create";
189
+ if (normalizedMethod === "GET" && normalizedPath === "/project/my_step") return "project.my-step";
190
+ if (normalizedMethod === "GET" && /^\/project\/[^/]+$/.test(normalizedPath)) return "project.get";
191
+ if (normalizedMethod === "GET" && /^\/step\/[^/]+$/.test(normalizedPath)) return "step.get";
192
+ if (normalizedMethod === "PUT" && /^\/step\/[^/]+$/.test(normalizedPath)) return "step.submit";
193
+ if (normalizedMethod === "GET" && normalizedPath === "/business_skill") return "bbs.list";
194
+ if (normalizedMethod === "POST" && normalizedPath === "/business_skill") return "bbs.create";
195
+ if (normalizedMethod === "POST" && normalizedPath === "/business_skill/install_record") return "bbs.ensure";
196
+ if (normalizedMethod === "GET" && /^\/business_skill\/[^/]+$/.test(normalizedPath)) return "bbs.show";
197
+ if (normalizedMethod === "POST" && /^\/business_skill\/[^/]+\/versions$/.test(normalizedPath)) return "bbs.upgrade";
198
+ if (normalizedMethod === "GET" && /^\/business_skill\/[^/]+\/download$/.test(normalizedPath)) return "bbs.ensure";
199
+ return "api.raw";
200
+ }
201
+ async function refreshCapabilities(client, profile, now = /* @__PURE__ */ new Date()) {
202
+ const response = await client.request({
203
+ method: "GET",
204
+ url: "/api/cli/capabilities"
205
+ });
206
+ const body = response.data;
207
+ if (typeof body.code === "number" && body.code !== 0) {
208
+ throw new Error(body.msg || `Capabilities probe failed with code ${body.code}`);
209
+ }
210
+ const data = body.data ?? body;
211
+ const ttlSeconds = typeof data.ttl_seconds === "number" ? data.ttl_seconds : 300;
212
+ const cache = {
213
+ version: data.version ?? 1,
214
+ generated_at: data.generated_at,
215
+ ttl_seconds: ttlSeconds,
216
+ fetched_at: now.toISOString(),
217
+ expires_at: new Date(now.getTime() + ttlSeconds * 1e3).toISOString(),
218
+ capabilities: Array.isArray(data.capabilities) ? data.capabilities : []
219
+ };
220
+ await updateProfileCapabilities(profile.name, cache);
221
+ return cache;
222
+ }
223
+ async function ensureCapability(client, profile, capabilityName) {
224
+ if (!capabilityName) {
225
+ return;
226
+ }
227
+ let cache = profile.config.capabilities_cache;
228
+ if (!capabilityEnabled(cache, capabilityName)) {
229
+ cache = await refreshCapabilities(client, profile);
230
+ profile.config.capabilities_cache = cache;
231
+ }
232
+ if (!capabilityEnabled(cache, capabilityName)) {
233
+ throw new Error(`bpmax-cli capability "${capabilityName}" is not allowed for profile "${profile.name}". Refresh succeeded but the server did not grant this capability.`);
234
+ }
235
+ }
236
+ function capabilityEnabled(cache, capabilityName, now = /* @__PURE__ */ new Date()) {
237
+ if (!cache || Date.parse(cache.expires_at) <= now.getTime()) {
238
+ return false;
239
+ }
240
+ return cache.capabilities.some((item) => item.name === capabilityName && item.enabled === true);
241
+ }
242
+ async function updateProfileCapabilities(profileName, cache) {
243
+ const config = await loadConfig();
244
+ const profile = config.profiles[profileName];
245
+ if (!profile) {
246
+ return;
247
+ }
248
+ config.profiles[profileName] = {
249
+ ...profile,
250
+ capabilities_cache: cache
251
+ };
252
+ await saveConfig(config);
253
+ }
254
+ function normalizePath(path6) {
255
+ let normalized = path6.split("?")[0] || "/";
256
+ if (!normalized.startsWith("/")) {
257
+ normalized = `/${normalized}`;
258
+ }
259
+ normalized = normalized.replace(/\/+/g, "/");
260
+ if (normalized.startsWith("/api/")) {
261
+ normalized = normalized.slice(4);
262
+ }
263
+ if (normalized.length > 1) {
264
+ normalized = normalized.replace(/\/+$/g, "");
265
+ }
266
+ return normalized;
267
+ }
268
+
269
+ // src/core/http.ts
270
+ var clientProfiles = /* @__PURE__ */ new WeakMap();
170
271
  var ensureApiPath = (path6) => {
171
272
  if (!path6.startsWith("/")) {
172
273
  path6 = `/${path6}`;
@@ -176,15 +277,24 @@ var ensureApiPath = (path6) => {
176
277
  }
177
278
  return `/api${path6}`;
178
279
  };
280
+ function normalizeWorkspaceForApi(workspace) {
281
+ const normalized = workspace?.trim();
282
+ if (!normalized) {
283
+ return normalized;
284
+ }
285
+ return normalized.startsWith("w:") ? normalized.slice(2) : normalized;
286
+ }
179
287
  function createApiClient(profile) {
180
288
  const instance = axios.create({
181
289
  baseURL: profile.config.origin,
182
290
  withCredentials: false
183
291
  });
292
+ clientProfiles.set(instance, profile);
184
293
  instance.interceptors.request.use((config) => {
294
+ const workspaceParam = config.params?.$workspace ?? profile.config.workspace;
185
295
  config.params = {
186
296
  ...config.params || {},
187
- $workspace: config.params?.$workspace ?? profile.config.workspace,
297
+ $workspace: normalizeWorkspaceForApi(String(workspaceParam)),
188
298
  $language: config.params?.$language ?? profile.config.language
189
299
  };
190
300
  if (profile.config.api_key) {
@@ -197,6 +307,10 @@ function createApiClient(profile) {
197
307
  return instance;
198
308
  }
199
309
  async function apiRequest(client, method, path6, options = {}) {
310
+ const profile = clientProfiles.get(client);
311
+ if (profile) {
312
+ await ensureCapability(client, profile, options.capability ?? capabilityForRequest(method, path6));
313
+ }
200
314
  const response = await client.request({
201
315
  method,
202
316
  url: ensureApiPath(path6),
@@ -347,7 +461,7 @@ function assertRawApiPathAllowed(method, path6) {
347
461
  return;
348
462
  }
349
463
  throw new Error(
350
- `Raw API ${method} ${path6} is blocked because /api/project/<id> falls back to project creation in huanpingtong-server. Do not call /project/es-search or /project/raw-es-search; huanpingtong-server does not expose those as public ES APIs. Use bpmax-cli project create --flow-id <id> --json <json> for project creation, or bpmax-cli es project-search / project list for project reads.`
464
+ `Raw API ${method} ${path6} is blocked because /api/project/<id> falls back to project creation in huanpingtong-server. Do not call /project/es-search or /project/raw-es-search; huanpingtong-server does not expose those as public ES APIs. Use bpmax-cli project create --flow-id <id> --json <json> for project creation, or bpmax-cli project search / project list for project reads.`
351
465
  );
352
466
  }
353
467
  function registerApiCommands(program2) {
@@ -366,7 +480,9 @@ function registerApiCommands(program2) {
366
480
  }
367
481
  const config = await loadConfig();
368
482
  const profile = resolveProfile(config, options.profile);
369
- const result = await apiRequest(createApiClient(profile), normalizedMethod, path6, {
483
+ const client = createApiClient(profile);
484
+ await ensureCapability(client, profile, "api.raw");
485
+ const result = await apiRequest(client, normalizedMethod, path6, {
370
486
  params: options.params ? await parseJsonInput(options.params, "--params") : void 0,
371
487
  data: await parseJsonAny(options.data, "--data")
372
488
  });
@@ -399,9 +515,53 @@ function buildBridgeUrl(origin, workspace, params) {
399
515
  const query = new URLSearchParams(params);
400
516
  return `${origin}/${encodeURIComponent(workspace)}/cli-login?${query.toString()}`;
401
517
  }
518
+ function normalizeDeviceWorkspace(workspace) {
519
+ const nextWorkspace = workspace.trim().replace(/^\/+|\/+$/g, "");
520
+ if (!nextWorkspace) {
521
+ throw new Error("Workspace is required before starting device authorization.");
522
+ }
523
+ if (nextWorkspace === "default") {
524
+ return nextWorkspace;
525
+ }
526
+ if (nextWorkspace === "w" || nextWorkspace === "w:") {
527
+ throw new Error(`Invalid BPMAX workspace "${workspace}". Expected a concrete workspace like "w:ybs".`);
528
+ }
529
+ return nextWorkspace.startsWith("w:") ? nextWorkspace : `w:${nextWorkspace}`;
530
+ }
531
+ function normalizeOriginForLint(origin) {
532
+ const nextOrigin = origin.trim().replace(/\/+$/g, "");
533
+ if (!nextOrigin) {
534
+ throw new Error("Origin is required before starting device authorization.");
535
+ }
536
+ return nextOrigin;
537
+ }
538
+ function firstPathSegment(url) {
539
+ return url.pathname.split("/").filter(Boolean).map((segment) => decodeURIComponent(segment))[0];
540
+ }
541
+ function lintDeviceAuthorizationUrl(urlValue, expectedOrigin, expectedWorkspace, fieldName) {
542
+ let url;
543
+ try {
544
+ url = new URL(urlValue);
545
+ } catch {
546
+ throw new Error(`Device authorization ${fieldName} is not a valid URL: ${urlValue}`);
547
+ }
548
+ if (url.origin !== expectedOrigin) {
549
+ throw new Error(
550
+ `Device authorization URL origin mismatch for ${fieldName}: expected ${expectedOrigin}, got ${url.origin}.`
551
+ );
552
+ }
553
+ const actualWorkspace = firstPathSegment(url);
554
+ if (actualWorkspace !== expectedWorkspace) {
555
+ throw new Error(
556
+ `Device authorization URL workspace mismatch for ${fieldName}: expected ${expectedWorkspace}, got ${actualWorkspace || "(missing)"}. Refusing to print a potentially wrong authorization link.`
557
+ );
558
+ }
559
+ }
402
560
  async function runBrowserLogin(options) {
403
561
  const state = randomBytes(16).toString("hex");
404
562
  const timeoutMs = options.timeoutMs ?? 5 * 60 * 1e3;
563
+ const origin = normalizeOriginForLint(options.origin);
564
+ const workspace = normalizeDeviceWorkspace(options.workspace);
405
565
  return await new Promise((resolve, reject) => {
406
566
  const server = createServer(async (req, res) => {
407
567
  res.setHeader("Access-Control-Allow-Origin", "*");
@@ -458,7 +618,7 @@ async function runBrowserLogin(options) {
458
618
  return;
459
619
  }
460
620
  const callbackUrl = `http://127.0.0.1:${address.port}/callback`;
461
- const bridgeUrl = buildBridgeUrl(options.origin, options.workspace, {
621
+ const bridgeUrl = buildBridgeUrl(origin, workspace, {
462
622
  callback: callbackUrl,
463
623
  state,
464
624
  profile: options.profileName,
@@ -512,21 +672,28 @@ function numberField(value, name, fallback) {
512
672
  async function startDeviceLogin(options) {
513
673
  const agent = options.agent || "generic";
514
674
  const channel = options.channel || "json";
515
- const request = options.request || createDeviceRequest(options.origin);
675
+ const origin = normalizeOriginForLint(options.origin);
676
+ const workspace = normalizeDeviceWorkspace(options.workspace);
677
+ const request = options.request || createDeviceRequest(origin);
516
678
  const response = await request("POST", "/cli/device_authorizations", {
517
679
  data: {
518
- workspace: options.workspace,
680
+ workspace,
519
681
  profile: options.profileName,
520
682
  key_name: options.apiKeyName,
521
683
  agent,
522
684
  channel,
523
- origin: options.origin
685
+ origin
524
686
  }
525
687
  });
526
688
  const expiresIn = numberField(response.expires_in, "expires_in");
527
689
  const now = options.now?.() || /* @__PURE__ */ new Date();
528
690
  const verificationUri = stringField(response.verification_uri, "verification_uri");
691
+ lintDeviceAuthorizationUrl(verificationUri, origin, workspace, "verification_uri");
529
692
  const verificationUriComplete = typeof response.verification_uri_complete === "string" && response.verification_uri_complete.trim() ? response.verification_uri_complete : void 0;
693
+ if (verificationUriComplete) {
694
+ lintDeviceAuthorizationUrl(verificationUriComplete, origin, workspace, "verification_uri_complete");
695
+ }
696
+ const authorizationUrl = verificationUriComplete || verificationUri;
530
697
  return {
531
698
  profile: options.profileName,
532
699
  agent,
@@ -535,7 +702,7 @@ async function startDeviceLogin(options) {
535
702
  user_code: stringField(response.user_code, "user_code"),
536
703
  verification_uri: verificationUri,
537
704
  verification_uri_complete: verificationUriComplete,
538
- authorization_url: verificationUriComplete || verificationUri,
705
+ authorization_url: authorizationUrl,
539
706
  expires_in: expiresIn,
540
707
  interval: numberField(response.interval, "interval", 5),
541
708
  expires_at: new Date(now.getTime() + expiresIn * 1e3).toISOString()
@@ -631,6 +798,7 @@ function registerAuthCommands(program2, deps = {}) {
631
798
  const browserLogin = deps.browserLogin || runBrowserLogin;
632
799
  const startDevice = deps.startDeviceLogin || startDeviceLogin;
633
800
  const completeDevice = deps.completeDeviceLogin || completeDeviceLogin;
801
+ const shouldProbeCapabilities = !deps.loadConfig && !deps.saveConfig;
634
802
  const auth = program2.command("auth").description("Authenticate and manage API key state");
635
803
  auth.command("login").description("Authorize and persist the returned API key").option("--profile <profile>", "Profile name").option("--key-name <keyName>", "Target API key name", "bpmax-cli").option("--mode <mode>", "Login mode: browser | device", "browser").option("--agent <agent>", "Agent adapter for device mode", "generic").option("--channel <channel>", "Interaction channel for device mode", "terminal").option("--format <format>", "Output format", "pretty").action(async (options) => {
636
804
  const config = await load();
@@ -666,12 +834,23 @@ function registerAuthCommands(program2, deps = {}) {
666
834
  }
667
835
  config.profiles[profile.name] = updateProfileAuth(config.profiles[profile.name], result);
668
836
  await save(config);
837
+ let capabilitiesProbe;
838
+ if (shouldProbeCapabilities) {
839
+ try {
840
+ const authenticatedProfile = resolveProfile(await loadConfig(), profile.name);
841
+ const cache = await refreshCapabilities(createApiClient(authenticatedProfile), authenticatedProfile);
842
+ capabilitiesProbe = { status: "ok", count: cache.capabilities.filter((item) => item.enabled).length };
843
+ } catch (error) {
844
+ capabilitiesProbe = { status: "failed", error: error instanceof Error ? error.message : String(error) };
845
+ }
846
+ }
669
847
  if (options.format === "json") {
670
848
  printResult("json", {
671
849
  ok: true,
672
850
  profile: profile.name,
673
851
  login: "authenticated",
674
852
  user: result.user,
853
+ ...capabilitiesProbe ? { capabilities_probe: capabilitiesProbe } : {},
675
854
  ...authorization ? {
676
855
  authorization,
677
856
  message_card: buildAuthorizationMessageCard({
@@ -711,11 +890,22 @@ function registerAuthCommands(program2, deps = {}) {
711
890
  });
712
891
  config.profiles[profile.name] = updateProfileAuth(config.profiles[profile.name], result);
713
892
  await save(config);
893
+ let capabilitiesProbe;
894
+ if (shouldProbeCapabilities) {
895
+ try {
896
+ const authenticatedProfile = resolveProfile(await loadConfig(), profile.name);
897
+ const cache = await refreshCapabilities(createApiClient(authenticatedProfile), authenticatedProfile);
898
+ capabilitiesProbe = { status: "ok", count: cache.capabilities.filter((item) => item.enabled).length };
899
+ } catch (error) {
900
+ capabilitiesProbe = { status: "failed", error: error instanceof Error ? error.message : String(error) };
901
+ }
902
+ }
714
903
  printResult(options.format, {
715
904
  ok: true,
716
905
  profile: profile.name,
717
906
  login: "authenticated",
718
- user: result.user
907
+ user: result.user,
908
+ ...capabilitiesProbe ? { capabilities_probe: capabilitiesProbe } : {}
719
909
  });
720
910
  });
721
911
  auth.command("status").description("Show saved auth state and validate /api/user/current").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (options) => {
@@ -766,7 +956,7 @@ import { readFile as readFile5 } from "fs/promises";
766
956
  // package.json
767
957
  var package_default = {
768
958
  name: "bpmax-cli",
769
- version: "0.1.40",
959
+ version: "0.1.42",
770
960
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
771
961
  type: "module",
772
962
  bin: {
@@ -1000,15 +1190,16 @@ var knownBpmCommands = {
1000
1190
  api: null,
1001
1191
  auth: /* @__PURE__ */ new Set(["login", "status", "logout", "device"]),
1002
1192
  bbs: /* @__PURE__ */ new Set(["list", "show", "create", "upgrade", "sync", "ensure", "install", "update", "uninstall", "lint", "gate"]),
1193
+ capabilities: /* @__PURE__ */ new Set(["status", "refresh"]),
1003
1194
  config: null,
1004
1195
  es: /* @__PURE__ */ new Set(["project-search"]),
1005
1196
  flow: /* @__PURE__ */ new Set(["list", "options", "get"]),
1006
1197
  init: null,
1007
- project: /* @__PURE__ */ new Set(["list", "get", "my-step", "approval-context", "create"]),
1198
+ project: /* @__PURE__ */ new Set(["list", "search", "get", "my-step", "approval-context", "create"]),
1008
1199
  recipe: /* @__PURE__ */ new Set(["list", "show", "run", "scaffold"]),
1009
1200
  schema: /* @__PURE__ */ new Set(["list", "show"]),
1010
1201
  setup: null,
1011
- step: /* @__PURE__ */ new Set(["get"]),
1202
+ step: /* @__PURE__ */ new Set(["get", "context", "actions", "requirements", "submit"]),
1012
1203
  update: null,
1013
1204
  url: /* @__PURE__ */ new Set(["workspace", "project-create", "project-list", "project-detail", "project-step"]),
1014
1205
  user: /* @__PURE__ */ new Set(["current"])
@@ -1682,6 +1873,30 @@ function registerBbsCommands(program2) {
1682
1873
  });
1683
1874
  }
1684
1875
 
1876
+ // src/commands/capabilities.ts
1877
+ function registerCapabilitiesCommands(program2) {
1878
+ const capabilities = program2.command("capabilities").description("Inspect bpmax-cli server capability whitelist");
1879
+ capabilities.command("status").description("Show cached server capabilities for a profile").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
1880
+ const profile = resolveProfile(await loadConfig(), options.profile);
1881
+ printResult(options.format, {
1882
+ profile: profile.name,
1883
+ origin: profile.config.origin,
1884
+ workspace: profile.config.workspace,
1885
+ capabilities_cache: profile.config.capabilities_cache || null
1886
+ });
1887
+ });
1888
+ capabilities.command("refresh").description("Refresh server capabilities for a profile").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
1889
+ const profile = resolveProfile(await loadConfig(), options.profile);
1890
+ const cache = await refreshCapabilities(createApiClient(profile), profile);
1891
+ printResult(options.format, {
1892
+ profile: profile.name,
1893
+ origin: profile.config.origin,
1894
+ workspace: profile.config.workspace,
1895
+ capabilities_cache: cache
1896
+ });
1897
+ });
1898
+ }
1899
+
1685
1900
  // src/commands/config.ts
1686
1901
  import { text } from "@clack/prompts";
1687
1902
  async function ensureValue(current, label, placeholder) {
@@ -1764,22 +1979,27 @@ function registerConfigCommands(program2) {
1764
1979
  });
1765
1980
  }
1766
1981
 
1767
- // src/commands/es.ts
1982
+ // src/core/project-search.ts
1768
1983
  function isRecord3(value) {
1769
1984
  return typeof value === "object" && value !== null && !Array.isArray(value);
1770
1985
  }
1771
1986
  function hasRawProjectSearchBody(value) {
1772
1987
  return isRecord3(value) && Object.prototype.hasOwnProperty.call(value, "body");
1773
1988
  }
1989
+ function assertProjectSearchBody(value) {
1990
+ if (hasRawProjectSearchBody(value)) {
1991
+ throw new Error(
1992
+ "Raw ES DTO with top-level body is not supported through huanpingtong-server. Use bpmax-cli project search so the CLI calls /api/project/list ES mode. /api/project/raw-es-search is not exposed by huanpingtong-server and legacy /api/project/<id> routing can create projects."
1993
+ );
1994
+ }
1995
+ }
1996
+
1997
+ // src/commands/es.ts
1774
1998
  function registerEsCommands(program2) {
1775
1999
  const es = program2.command("es").description("Fast ES-backed data queries");
1776
- es.command("project-search").description("Search project ES data with the huanpingtong project-list API").option("--profile <profile>", "Profile name").option("--page <page>", "Page number for project-list payloads", "1").option("--page-size <pageSize>", "Page size for project-list payloads", "20").requiredOption("--body <json>", "Project list body JSON or @file").option("--format <format>", "Output format", "json").action(async (options) => {
2000
+ es.command("project-search").description("Compatibility alias for project search through huanpingtong /api/project/list ES mode").option("--profile <profile>", "Profile name").option("--page <page>", "Page number for project-list payloads", "1").option("--page-size <pageSize>", "Page size for project-list payloads", "20").requiredOption("--body <json>", "Project list body JSON or @file").option("--format <format>", "Output format", "json").action(async (options) => {
1777
2001
  const body = await parseJsonInput(options.body, "--body");
1778
- if (hasRawProjectSearchBody(body)) {
1779
- throw new Error(
1780
- "Raw ES DTO with top-level body is not supported through huanpingtong-server. Use a project-list body with bpmax-cli es project-search so the CLI calls /api/project/list. /api/project/raw-es-search is not exposed by huanpingtong-server and legacy /api/project/<id> routing can create projects."
1781
- );
1782
- }
2002
+ assertProjectSearchBody(body);
1783
2003
  const config = await loadConfig();
1784
2004
  const profile = resolveProfile(config, options.profile);
1785
2005
  const client = createApiClient(profile);
@@ -1793,7 +2013,8 @@ function registerEsCommands(program2) {
1793
2013
  page_size: Number(options.pageSize)
1794
2014
  },
1795
2015
  data: body,
1796
- preserveErrorBody: true
2016
+ preserveErrorBody: true,
2017
+ capability: "project.search"
1797
2018
  }
1798
2019
  );
1799
2020
  printResult(options.format, result);
@@ -2085,6 +2306,7 @@ function registerInitCommand(program2, deps = {}) {
2085
2306
  const saveConfig2 = deps.saveConfig || saveConfig;
2086
2307
  const syncSkills2 = deps.syncSkills || syncSkills;
2087
2308
  const startDeviceLogin2 = deps.startDeviceLogin || startDeviceLogin;
2309
+ const shouldProbeCapabilities = !deps.loadConfig && !deps.saveConfig;
2088
2310
  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) => {
2089
2311
  const parsed = parseBpmUrl(options.url);
2090
2312
  const baseProfileName = options.name || "default";
@@ -2119,6 +2341,16 @@ function registerInitCommand(program2, deps = {}) {
2119
2341
  language: options.language || DEFAULT_LANGUAGE
2120
2342
  });
2121
2343
  await saveConfig2(nextConfig);
2344
+ let capabilitiesProbe;
2345
+ if (shouldProbeCapabilities) {
2346
+ try {
2347
+ const profile = resolveProfile(nextConfig, profileName);
2348
+ const cache = await refreshCapabilities(createApiClient(profile), profile);
2349
+ capabilitiesProbe = { status: "ok", count: cache.capabilities.filter((item) => item.enabled).length };
2350
+ } catch (error) {
2351
+ capabilitiesProbe = { status: "failed", error: error instanceof Error ? error.message : String(error) };
2352
+ }
2353
+ }
2122
2354
  const skills = await syncSkills2(VERSION, {
2123
2355
  force: Boolean(options.forceSkills),
2124
2356
  agent: options.agent,
@@ -2153,6 +2385,7 @@ function registerInitCommand(program2, deps = {}) {
2153
2385
  detail: parseSkillsDetail(skills.result?.stdout),
2154
2386
  ...skills.action === "failed" ? { error: skills.result?.stderr || skills.result?.stdout } : {}
2155
2387
  },
2388
+ ...capabilitiesProbe ? { capabilities_probe: capabilitiesProbe } : {},
2156
2389
  authorization,
2157
2390
  message_card: buildAuthorizationMessageCard({
2158
2391
  ...authorization,
@@ -3165,6 +3398,27 @@ async function buildApprovalContext(client, projectId, options) {
3165
3398
  }
3166
3399
  function registerProjectCommands(program2) {
3167
3400
  const project = program2.command("project").description("Project commands");
3401
+ project.command("search").description("Search projects through huanpingtong /api/project/list ES mode").option("--profile <profile>", "Profile name").option("--page <page>", "Page number", "1").option("--page-size <pageSize>", "Page size", "20").requiredOption("--body <json>", "Project search body JSON or @file").option("--format <format>", "Output format", "json").action(async (options) => {
3402
+ const body = await parseJsonInput(options.body, "--body");
3403
+ assertProjectSearchBody(body);
3404
+ const config = await loadConfig();
3405
+ const profile = resolveProfile(config, options.profile);
3406
+ const result = await apiRequest(
3407
+ createApiClient(profile),
3408
+ "POST",
3409
+ "/project/list",
3410
+ {
3411
+ params: {
3412
+ page: Number(options.page),
3413
+ page_size: Number(options.pageSize)
3414
+ },
3415
+ data: body,
3416
+ preserveErrorBody: true,
3417
+ capability: "project.search"
3418
+ }
3419
+ );
3420
+ printResult(options.format, result);
3421
+ });
3168
3422
  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) => {
3169
3423
  const config = await loadConfig();
3170
3424
  const profile = resolveProfile(config, options.profile);
@@ -3726,14 +3980,19 @@ function registerRecipeCommands(program2, deps = {}) {
3726
3980
 
3727
3981
  // src/core/manifest.ts
3728
3982
  var schemaEntries = [
3729
- { name: "auth.login", description: "Open hpt-frontend bridge page and persist API key locally." },
3983
+ { name: "capabilities.status", description: "Show cached server capability whitelist.", bootstrap: true },
3984
+ { name: "capabilities.refresh", description: "Refresh server capability whitelist.", method: "GET", path: "/api/cli/capabilities", bootstrap: true },
3985
+ { name: "auth.login", description: "Open hpt-frontend bridge page and persist API key locally.", bootstrap: true },
3730
3986
  { name: "auth.status", description: "Show current profile status and validate /api/user/current." },
3731
- { name: "auth.logout", description: "Clear the saved API key for the selected profile." },
3987
+ { name: "auth.logout", description: "Clear the saved API key for the selected profile.", bootstrap: true },
3988
+ { name: "auth.device.start", description: "Start device authorization.", method: "POST", path: "/api/cli/device_authorizations", bootstrap: true },
3989
+ { name: "auth.device.complete", description: "Complete device authorization.", method: "POST", path: "/api/cli/device_token", bootstrap: true },
3732
3990
  { name: "user.current", description: "Get current user.", method: "GET", path: "/api/user/current" },
3733
3991
  { name: "flow.list", description: "List flows.", method: "GET", path: "/api/flow/flow_type" },
3734
3992
  { name: "flow.options", description: "List flow options.", method: "GET", path: "/api/flow/options" },
3735
3993
  { name: "flow.get", description: "Fetch flow details by id.", method: "POST", path: "/api/flow/batch_get" },
3736
- { name: "es.project-search", description: "Search project ES data through huanpingtong /api/project/list only.", method: "POST", path: "/api/project/list" },
3994
+ { name: "project.search", description: "Search projects through huanpingtong /api/project/list ES mode.", method: "POST", path: "/api/project/list" },
3995
+ { name: "es.project-search", description: "Compatibility alias for project.search; uses huanpingtong /api/project/list ES mode.", method: "POST", path: "/api/project/list" },
3737
3996
  { name: "project.list", description: "List projects.", method: "POST", path: "/api/project/list" },
3738
3997
  { name: "project.get", description: "Get project detail.", method: "GET", path: "/api/project/:id" },
3739
3998
  { name: "project.my-step", description: "List my pending steps.", method: "GET", path: "/api/project/my_step" },
@@ -3745,10 +4004,17 @@ var schemaEntries = [
3745
4004
  { name: "step.requirements", description: "List required step inputs before submitting.", method: "GET", path: "/api/project/:id + /api/step/:id" },
3746
4005
  { name: "step.submit", description: "Dry-run or submit a step action with safety checks.", method: "PUT", path: "/api/step/:id?action=:action" },
3747
4006
  { name: "bbs.list", description: "List BPMAX Business Skills.", method: "GET", path: "/api/business_skill" },
4007
+ { name: "bbs.show", description: "Show a BPMAX Business Skill.", method: "GET", path: "/api/business_skill/:id" },
3748
4008
  { name: "bbs.create", description: "Create a BPMAX Business Skill from a standard skill zip.", method: "POST", path: "/api/business_skill" },
3749
- { name: "bbs.lint", description: "Lint a BPMAX Business Skill package before publish." },
3750
- { name: "bbs.gate", description: "Run a BPMAX Business Skill business preflight or verify gate." },
3751
- { name: "bbs.ensure", description: "Install or update a BPMAX Business Skill lazily before use." }
4009
+ { name: "bbs.upgrade", description: "Publish a BPMAX Business Skill version.", method: "POST", path: "/api/business_skill/:id/versions" },
4010
+ { name: "bbs.sync", description: "Sync BPMAX Business Skill catalog.", method: "GET", path: "/api/business_skill" },
4011
+ { name: "bbs.ensure", description: "Install or update a BPMAX Business Skill lazily before use.", method: "GET", path: "/api/business_skill/:id/download + /api/business_skill/install_record" },
4012
+ { name: "bbs.install", description: "Install a BPMAX Business Skill.", method: "GET", path: "/api/business_skill/:id/download + /api/business_skill/install_record" },
4013
+ { name: "bbs.update", description: "Update a BPMAX Business Skill.", method: "GET", path: "/api/business_skill/:id/download + /api/business_skill/install_record" },
4014
+ { name: "bbs.uninstall", description: "Uninstall a BPMAX Business Skill.", method: "POST", path: "/api/business_skill/install_record" },
4015
+ { name: "bbs.lint", description: "Lint a BPMAX Business Skill package before publish.", bootstrap: true },
4016
+ { name: "bbs.gate", description: "Run a BPMAX Business Skill business preflight or verify gate.", bootstrap: true },
4017
+ { name: "api.raw", description: "Call raw BPMAX API paths allowed by server capability whitelist.", method: "*", path: "/api/*" }
3752
4018
  ];
3753
4019
 
3754
4020
  // src/commands/schema.ts
@@ -4168,8 +4434,8 @@ function checkCurrentUserCanProcess(step, currentUser) {
4168
4434
  }
4169
4435
  async function buildStepContext(profile, client, stepId, projectId) {
4170
4436
  const [project, step, currentUser] = await Promise.all([
4171
- apiRequest(client, "GET", `/project/${projectId}`),
4172
- apiRequest(client, "GET", `/step/${stepId}`),
4437
+ apiRequest(client, "GET", `/project/${projectId}`, { capability: "step.context" }),
4438
+ apiRequest(client, "GET", `/step/${stepId}`, { capability: "step.context" }),
4173
4439
  apiRequest(client, "GET", "/user/current").catch(() => null)
4174
4440
  ]);
4175
4441
  const actualProjectId = projectIdOfStep(step);
@@ -4882,6 +5148,7 @@ program.hook("preAction", (thisCommand) => {
4882
5148
  setConfigDir(options.configDir);
4883
5149
  });
4884
5150
  registerConfigCommands(program);
5151
+ registerCapabilitiesCommands(program);
4885
5152
  registerAuthCommands(program);
4886
5153
  registerBbsCommands(program);
4887
5154
  registerApiCommands(program);