bpmax-cli 0.1.39 → 0.1.41
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 +24 -13
- package/dist/bin.js +274 -33
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-cli/SKILL.md +2 -0
- package/skills/bpmax-project/SKILL.md +6 -4
- package/skills/bpmax-schema/SKILL.md +6 -2
package/README.md
CHANGED
|
@@ -172,13 +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
|
-
##
|
|
175
|
+
## Project search queries
|
|
176
176
|
|
|
177
|
-
Use
|
|
178
|
-
For normal project searches, pass a project-list style 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:
|
|
179
178
|
|
|
180
179
|
```bash
|
|
181
|
-
bpmax-cli
|
|
180
|
+
bpmax-cli project search --profile yuanrong --body @project-search-query.json --page 1 --page-size 20 --format json
|
|
182
181
|
```
|
|
183
182
|
|
|
184
183
|
```json
|
|
@@ -193,23 +192,35 @@ bpmax-cli es project-search --profile yuanrong --body @project-list-query.json -
|
|
|
193
192
|
}
|
|
194
193
|
```
|
|
195
194
|
|
|
196
|
-
|
|
195
|
+
`bpmax-cli es project-search` remains as a compatibility alias, but new Agent/BBS scenarios should use `bpmax-cli project search`.
|
|
196
|
+
|
|
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:
|
|
197
200
|
|
|
198
201
|
```json
|
|
199
202
|
{
|
|
200
203
|
"data_set_key": "budget_project",
|
|
201
204
|
"flow_type": "flow123",
|
|
202
205
|
"flow_key": "",
|
|
203
|
-
"
|
|
204
|
-
"
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
"by_status": { "terms": { "field": "status" } }
|
|
208
|
-
}
|
|
209
|
-
}
|
|
206
|
+
"query": {
|
|
207
|
+
"name": { "type": "match_phrase", "value": "董永喜" }
|
|
208
|
+
},
|
|
209
|
+
"is_select_all": false
|
|
210
210
|
}
|
|
211
211
|
```
|
|
212
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
|
+
|
|
213
224
|
## Profile recipes
|
|
214
225
|
|
|
215
226
|
Profile recipes are local, profile-scoped playbooks for environment-specific BPMAX operations. They live outside project repositories under the active config directory:
|
|
@@ -307,7 +318,7 @@ bpmax-cli --config-dir <config_dir> bbs ensure <skill-key> --agent <agent> --pro
|
|
|
307
318
|
|
|
308
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`.
|
|
309
320
|
|
|
310
|
-
For mutating raw API calls, `bpmax-cli api` requires `--confirm-mutating` and supports `--data @file.json`. 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.
|
|
311
322
|
|
|
312
323
|
If `aily-skillhub` is available in `PATH`, the installer also runs:
|
|
313
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:
|
|
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),
|
|
@@ -318,9 +432,42 @@ async function parseJsonAny(input, label = "JSON input") {
|
|
|
318
432
|
function isMutatingMethod(method) {
|
|
319
433
|
return ["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase());
|
|
320
434
|
}
|
|
435
|
+
function normalizeApiPath(path6) {
|
|
436
|
+
let normalized = path6.trim();
|
|
437
|
+
const queryIndex = normalized.indexOf("?");
|
|
438
|
+
if (queryIndex >= 0) {
|
|
439
|
+
normalized = normalized.slice(0, queryIndex);
|
|
440
|
+
}
|
|
441
|
+
if (!normalized.startsWith("/")) {
|
|
442
|
+
normalized = `/${normalized}`;
|
|
443
|
+
}
|
|
444
|
+
normalized = normalized.replace(/\/+/g, "/");
|
|
445
|
+
if (normalized.startsWith("/api/")) {
|
|
446
|
+
normalized = normalized.slice(4);
|
|
447
|
+
}
|
|
448
|
+
if (normalized.length > 1) {
|
|
449
|
+
normalized = normalized.replace(/\/+$/g, "");
|
|
450
|
+
}
|
|
451
|
+
return normalized;
|
|
452
|
+
}
|
|
453
|
+
function assertRawApiPathAllowed(method, path6) {
|
|
454
|
+
if (!isMutatingMethod(method)) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const normalizedPath = normalizeApiPath(path6);
|
|
458
|
+
const isProjectPath = normalizedPath === "/project" || normalizedPath.startsWith("/project/");
|
|
459
|
+
const isAllowedProjectReadPost = method === "POST" && normalizedPath === "/project/list";
|
|
460
|
+
if (!isProjectPath || isAllowedProjectReadPost) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
throw new Error(
|
|
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.`
|
|
465
|
+
);
|
|
466
|
+
}
|
|
321
467
|
function registerApiCommands(program2) {
|
|
322
468
|
program2.command("api <method> <path>").description("Call an arbitrary BPMAX /api endpoint").option("--profile <profile>", "Profile name").option("--params <json>", "Query params JSON or @file").option("--data <json>", "Request body JSON or @file").option("--confirm-mutating", "Allow mutating API calls").option("--format <format>", "Output format", "json").action(async (method, path6, options) => {
|
|
323
469
|
const normalizedMethod = method.toUpperCase();
|
|
470
|
+
assertRawApiPathAllowed(normalizedMethod, path6);
|
|
324
471
|
if (isMutatingMethod(normalizedMethod) && options.confirmMutating !== true) {
|
|
325
472
|
printResult(options.format, {
|
|
326
473
|
ok: false,
|
|
@@ -333,7 +480,9 @@ function registerApiCommands(program2) {
|
|
|
333
480
|
}
|
|
334
481
|
const config = await loadConfig();
|
|
335
482
|
const profile = resolveProfile(config, options.profile);
|
|
336
|
-
const
|
|
483
|
+
const client = createApiClient(profile);
|
|
484
|
+
await ensureCapability(client, profile, "api.raw");
|
|
485
|
+
const result = await apiRequest(client, normalizedMethod, path6, {
|
|
337
486
|
params: options.params ? await parseJsonInput(options.params, "--params") : void 0,
|
|
338
487
|
data: await parseJsonAny(options.data, "--data")
|
|
339
488
|
});
|
|
@@ -598,6 +747,7 @@ function registerAuthCommands(program2, deps = {}) {
|
|
|
598
747
|
const browserLogin = deps.browserLogin || runBrowserLogin;
|
|
599
748
|
const startDevice = deps.startDeviceLogin || startDeviceLogin;
|
|
600
749
|
const completeDevice = deps.completeDeviceLogin || completeDeviceLogin;
|
|
750
|
+
const shouldProbeCapabilities = !deps.loadConfig && !deps.saveConfig;
|
|
601
751
|
const auth = program2.command("auth").description("Authenticate and manage API key state");
|
|
602
752
|
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) => {
|
|
603
753
|
const config = await load();
|
|
@@ -633,12 +783,23 @@ function registerAuthCommands(program2, deps = {}) {
|
|
|
633
783
|
}
|
|
634
784
|
config.profiles[profile.name] = updateProfileAuth(config.profiles[profile.name], result);
|
|
635
785
|
await save(config);
|
|
786
|
+
let capabilitiesProbe;
|
|
787
|
+
if (shouldProbeCapabilities) {
|
|
788
|
+
try {
|
|
789
|
+
const authenticatedProfile = resolveProfile(await loadConfig(), profile.name);
|
|
790
|
+
const cache = await refreshCapabilities(createApiClient(authenticatedProfile), authenticatedProfile);
|
|
791
|
+
capabilitiesProbe = { status: "ok", count: cache.capabilities.filter((item) => item.enabled).length };
|
|
792
|
+
} catch (error) {
|
|
793
|
+
capabilitiesProbe = { status: "failed", error: error instanceof Error ? error.message : String(error) };
|
|
794
|
+
}
|
|
795
|
+
}
|
|
636
796
|
if (options.format === "json") {
|
|
637
797
|
printResult("json", {
|
|
638
798
|
ok: true,
|
|
639
799
|
profile: profile.name,
|
|
640
800
|
login: "authenticated",
|
|
641
801
|
user: result.user,
|
|
802
|
+
...capabilitiesProbe ? { capabilities_probe: capabilitiesProbe } : {},
|
|
642
803
|
...authorization ? {
|
|
643
804
|
authorization,
|
|
644
805
|
message_card: buildAuthorizationMessageCard({
|
|
@@ -678,11 +839,22 @@ function registerAuthCommands(program2, deps = {}) {
|
|
|
678
839
|
});
|
|
679
840
|
config.profiles[profile.name] = updateProfileAuth(config.profiles[profile.name], result);
|
|
680
841
|
await save(config);
|
|
842
|
+
let capabilitiesProbe;
|
|
843
|
+
if (shouldProbeCapabilities) {
|
|
844
|
+
try {
|
|
845
|
+
const authenticatedProfile = resolveProfile(await loadConfig(), profile.name);
|
|
846
|
+
const cache = await refreshCapabilities(createApiClient(authenticatedProfile), authenticatedProfile);
|
|
847
|
+
capabilitiesProbe = { status: "ok", count: cache.capabilities.filter((item) => item.enabled).length };
|
|
848
|
+
} catch (error) {
|
|
849
|
+
capabilitiesProbe = { status: "failed", error: error instanceof Error ? error.message : String(error) };
|
|
850
|
+
}
|
|
851
|
+
}
|
|
681
852
|
printResult(options.format, {
|
|
682
853
|
ok: true,
|
|
683
854
|
profile: profile.name,
|
|
684
855
|
login: "authenticated",
|
|
685
|
-
user: result.user
|
|
856
|
+
user: result.user,
|
|
857
|
+
...capabilitiesProbe ? { capabilities_probe: capabilitiesProbe } : {}
|
|
686
858
|
});
|
|
687
859
|
});
|
|
688
860
|
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) => {
|
|
@@ -733,7 +905,7 @@ import { readFile as readFile5 } from "fs/promises";
|
|
|
733
905
|
// package.json
|
|
734
906
|
var package_default = {
|
|
735
907
|
name: "bpmax-cli",
|
|
736
|
-
version: "0.1.
|
|
908
|
+
version: "0.1.41",
|
|
737
909
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
738
910
|
type: "module",
|
|
739
911
|
bin: {
|
|
@@ -967,15 +1139,16 @@ var knownBpmCommands = {
|
|
|
967
1139
|
api: null,
|
|
968
1140
|
auth: /* @__PURE__ */ new Set(["login", "status", "logout", "device"]),
|
|
969
1141
|
bbs: /* @__PURE__ */ new Set(["list", "show", "create", "upgrade", "sync", "ensure", "install", "update", "uninstall", "lint", "gate"]),
|
|
1142
|
+
capabilities: /* @__PURE__ */ new Set(["status", "refresh"]),
|
|
970
1143
|
config: null,
|
|
971
1144
|
es: /* @__PURE__ */ new Set(["project-search"]),
|
|
972
1145
|
flow: /* @__PURE__ */ new Set(["list", "options", "get"]),
|
|
973
1146
|
init: null,
|
|
974
|
-
project: /* @__PURE__ */ new Set(["list", "get", "my-step", "approval-context", "create"]),
|
|
1147
|
+
project: /* @__PURE__ */ new Set(["list", "search", "get", "my-step", "approval-context", "create"]),
|
|
975
1148
|
recipe: /* @__PURE__ */ new Set(["list", "show", "run", "scaffold"]),
|
|
976
1149
|
schema: /* @__PURE__ */ new Set(["list", "show"]),
|
|
977
1150
|
setup: null,
|
|
978
|
-
step: /* @__PURE__ */ new Set(["get"]),
|
|
1151
|
+
step: /* @__PURE__ */ new Set(["get", "context", "actions", "requirements", "submit"]),
|
|
979
1152
|
update: null,
|
|
980
1153
|
url: /* @__PURE__ */ new Set(["workspace", "project-create", "project-list", "project-detail", "project-step"]),
|
|
981
1154
|
user: /* @__PURE__ */ new Set(["current"])
|
|
@@ -1649,6 +1822,30 @@ function registerBbsCommands(program2) {
|
|
|
1649
1822
|
});
|
|
1650
1823
|
}
|
|
1651
1824
|
|
|
1825
|
+
// src/commands/capabilities.ts
|
|
1826
|
+
function registerCapabilitiesCommands(program2) {
|
|
1827
|
+
const capabilities = program2.command("capabilities").description("Inspect bpmax-cli server capability whitelist");
|
|
1828
|
+
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) => {
|
|
1829
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
1830
|
+
printResult(options.format, {
|
|
1831
|
+
profile: profile.name,
|
|
1832
|
+
origin: profile.config.origin,
|
|
1833
|
+
workspace: profile.config.workspace,
|
|
1834
|
+
capabilities_cache: profile.config.capabilities_cache || null
|
|
1835
|
+
});
|
|
1836
|
+
});
|
|
1837
|
+
capabilities.command("refresh").description("Refresh server capabilities for a profile").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
1838
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
1839
|
+
const cache = await refreshCapabilities(createApiClient(profile), profile);
|
|
1840
|
+
printResult(options.format, {
|
|
1841
|
+
profile: profile.name,
|
|
1842
|
+
origin: profile.config.origin,
|
|
1843
|
+
workspace: profile.config.workspace,
|
|
1844
|
+
capabilities_cache: cache
|
|
1845
|
+
});
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1652
1849
|
// src/commands/config.ts
|
|
1653
1850
|
import { text } from "@clack/prompts";
|
|
1654
1851
|
async function ensureValue(current, label, placeholder) {
|
|
@@ -1731,33 +1928,30 @@ function registerConfigCommands(program2) {
|
|
|
1731
1928
|
});
|
|
1732
1929
|
}
|
|
1733
1930
|
|
|
1734
|
-
// src/
|
|
1931
|
+
// src/core/project-search.ts
|
|
1735
1932
|
function isRecord3(value) {
|
|
1736
1933
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1737
1934
|
}
|
|
1738
|
-
function
|
|
1935
|
+
function hasRawProjectSearchBody(value) {
|
|
1739
1936
|
return isRecord3(value) && Object.prototype.hasOwnProperty.call(value, "body");
|
|
1740
1937
|
}
|
|
1938
|
+
function assertProjectSearchBody(value) {
|
|
1939
|
+
if (hasRawProjectSearchBody(value)) {
|
|
1940
|
+
throw new Error(
|
|
1941
|
+
"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."
|
|
1942
|
+
);
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
// src/commands/es.ts
|
|
1741
1947
|
function registerEsCommands(program2) {
|
|
1742
1948
|
const es = program2.command("es").description("Fast ES-backed data queries");
|
|
1743
|
-
es.command("project-search").description("
|
|
1949
|
+
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) => {
|
|
1950
|
+
const body = await parseJsonInput(options.body, "--body");
|
|
1951
|
+
assertProjectSearchBody(body);
|
|
1744
1952
|
const config = await loadConfig();
|
|
1745
1953
|
const profile = resolveProfile(config, options.profile);
|
|
1746
|
-
const body = await parseJsonInput(options.body, "--body");
|
|
1747
1954
|
const client = createApiClient(profile);
|
|
1748
|
-
if (isRawProjectSearchBody(body)) {
|
|
1749
|
-
const result2 = await apiRequest(
|
|
1750
|
-
client,
|
|
1751
|
-
"POST",
|
|
1752
|
-
"/project/raw-es-search",
|
|
1753
|
-
{
|
|
1754
|
-
data: body,
|
|
1755
|
-
preserveErrorBody: true
|
|
1756
|
-
}
|
|
1757
|
-
);
|
|
1758
|
-
printResult(options.format, result2);
|
|
1759
|
-
return;
|
|
1760
|
-
}
|
|
1761
1955
|
const result = await apiRequest(
|
|
1762
1956
|
client,
|
|
1763
1957
|
"POST",
|
|
@@ -1768,7 +1962,8 @@ function registerEsCommands(program2) {
|
|
|
1768
1962
|
page_size: Number(options.pageSize)
|
|
1769
1963
|
},
|
|
1770
1964
|
data: body,
|
|
1771
|
-
preserveErrorBody: true
|
|
1965
|
+
preserveErrorBody: true,
|
|
1966
|
+
capability: "project.search"
|
|
1772
1967
|
}
|
|
1773
1968
|
);
|
|
1774
1969
|
printResult(options.format, result);
|
|
@@ -2060,6 +2255,7 @@ function registerInitCommand(program2, deps = {}) {
|
|
|
2060
2255
|
const saveConfig2 = deps.saveConfig || saveConfig;
|
|
2061
2256
|
const syncSkills2 = deps.syncSkills || syncSkills;
|
|
2062
2257
|
const startDeviceLogin2 = deps.startDeviceLogin || startDeviceLogin;
|
|
2258
|
+
const shouldProbeCapabilities = !deps.loadConfig && !deps.saveConfig;
|
|
2063
2259
|
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) => {
|
|
2064
2260
|
const parsed = parseBpmUrl(options.url);
|
|
2065
2261
|
const baseProfileName = options.name || "default";
|
|
@@ -2094,6 +2290,16 @@ function registerInitCommand(program2, deps = {}) {
|
|
|
2094
2290
|
language: options.language || DEFAULT_LANGUAGE
|
|
2095
2291
|
});
|
|
2096
2292
|
await saveConfig2(nextConfig);
|
|
2293
|
+
let capabilitiesProbe;
|
|
2294
|
+
if (shouldProbeCapabilities) {
|
|
2295
|
+
try {
|
|
2296
|
+
const profile = resolveProfile(nextConfig, profileName);
|
|
2297
|
+
const cache = await refreshCapabilities(createApiClient(profile), profile);
|
|
2298
|
+
capabilitiesProbe = { status: "ok", count: cache.capabilities.filter((item) => item.enabled).length };
|
|
2299
|
+
} catch (error) {
|
|
2300
|
+
capabilitiesProbe = { status: "failed", error: error instanceof Error ? error.message : String(error) };
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2097
2303
|
const skills = await syncSkills2(VERSION, {
|
|
2098
2304
|
force: Boolean(options.forceSkills),
|
|
2099
2305
|
agent: options.agent,
|
|
@@ -2128,6 +2334,7 @@ function registerInitCommand(program2, deps = {}) {
|
|
|
2128
2334
|
detail: parseSkillsDetail(skills.result?.stdout),
|
|
2129
2335
|
...skills.action === "failed" ? { error: skills.result?.stderr || skills.result?.stdout } : {}
|
|
2130
2336
|
},
|
|
2337
|
+
...capabilitiesProbe ? { capabilities_probe: capabilitiesProbe } : {},
|
|
2131
2338
|
authorization,
|
|
2132
2339
|
message_card: buildAuthorizationMessageCard({
|
|
2133
2340
|
...authorization,
|
|
@@ -3140,6 +3347,27 @@ async function buildApprovalContext(client, projectId, options) {
|
|
|
3140
3347
|
}
|
|
3141
3348
|
function registerProjectCommands(program2) {
|
|
3142
3349
|
const project = program2.command("project").description("Project commands");
|
|
3350
|
+
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) => {
|
|
3351
|
+
const body = await parseJsonInput(options.body, "--body");
|
|
3352
|
+
assertProjectSearchBody(body);
|
|
3353
|
+
const config = await loadConfig();
|
|
3354
|
+
const profile = resolveProfile(config, options.profile);
|
|
3355
|
+
const result = await apiRequest(
|
|
3356
|
+
createApiClient(profile),
|
|
3357
|
+
"POST",
|
|
3358
|
+
"/project/list",
|
|
3359
|
+
{
|
|
3360
|
+
params: {
|
|
3361
|
+
page: Number(options.page),
|
|
3362
|
+
page_size: Number(options.pageSize)
|
|
3363
|
+
},
|
|
3364
|
+
data: body,
|
|
3365
|
+
preserveErrorBody: true,
|
|
3366
|
+
capability: "project.search"
|
|
3367
|
+
}
|
|
3368
|
+
);
|
|
3369
|
+
printResult(options.format, result);
|
|
3370
|
+
});
|
|
3143
3371
|
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) => {
|
|
3144
3372
|
const config = await loadConfig();
|
|
3145
3373
|
const profile = resolveProfile(config, options.profile);
|
|
@@ -3701,14 +3929,19 @@ function registerRecipeCommands(program2, deps = {}) {
|
|
|
3701
3929
|
|
|
3702
3930
|
// src/core/manifest.ts
|
|
3703
3931
|
var schemaEntries = [
|
|
3704
|
-
{ name: "
|
|
3932
|
+
{ name: "capabilities.status", description: "Show cached server capability whitelist.", bootstrap: true },
|
|
3933
|
+
{ name: "capabilities.refresh", description: "Refresh server capability whitelist.", method: "GET", path: "/api/cli/capabilities", bootstrap: true },
|
|
3934
|
+
{ name: "auth.login", description: "Open hpt-frontend bridge page and persist API key locally.", bootstrap: true },
|
|
3705
3935
|
{ name: "auth.status", description: "Show current profile status and validate /api/user/current." },
|
|
3706
|
-
{ name: "auth.logout", description: "Clear the saved API key for the selected profile." },
|
|
3936
|
+
{ name: "auth.logout", description: "Clear the saved API key for the selected profile.", bootstrap: true },
|
|
3937
|
+
{ name: "auth.device.start", description: "Start device authorization.", method: "POST", path: "/api/cli/device_authorizations", bootstrap: true },
|
|
3938
|
+
{ name: "auth.device.complete", description: "Complete device authorization.", method: "POST", path: "/api/cli/device_token", bootstrap: true },
|
|
3707
3939
|
{ name: "user.current", description: "Get current user.", method: "GET", path: "/api/user/current" },
|
|
3708
3940
|
{ name: "flow.list", description: "List flows.", method: "GET", path: "/api/flow/flow_type" },
|
|
3709
3941
|
{ name: "flow.options", description: "List flow options.", method: "GET", path: "/api/flow/options" },
|
|
3710
3942
|
{ name: "flow.get", description: "Fetch flow details by id.", method: "POST", path: "/api/flow/batch_get" },
|
|
3711
|
-
{ name: "
|
|
3943
|
+
{ name: "project.search", description: "Search projects through huanpingtong /api/project/list ES mode.", method: "POST", path: "/api/project/list" },
|
|
3944
|
+
{ name: "es.project-search", description: "Compatibility alias for project.search; uses huanpingtong /api/project/list ES mode.", method: "POST", path: "/api/project/list" },
|
|
3712
3945
|
{ name: "project.list", description: "List projects.", method: "POST", path: "/api/project/list" },
|
|
3713
3946
|
{ name: "project.get", description: "Get project detail.", method: "GET", path: "/api/project/:id" },
|
|
3714
3947
|
{ name: "project.my-step", description: "List my pending steps.", method: "GET", path: "/api/project/my_step" },
|
|
@@ -3720,10 +3953,17 @@ var schemaEntries = [
|
|
|
3720
3953
|
{ name: "step.requirements", description: "List required step inputs before submitting.", method: "GET", path: "/api/project/:id + /api/step/:id" },
|
|
3721
3954
|
{ name: "step.submit", description: "Dry-run or submit a step action with safety checks.", method: "PUT", path: "/api/step/:id?action=:action" },
|
|
3722
3955
|
{ name: "bbs.list", description: "List BPMAX Business Skills.", method: "GET", path: "/api/business_skill" },
|
|
3956
|
+
{ name: "bbs.show", description: "Show a BPMAX Business Skill.", method: "GET", path: "/api/business_skill/:id" },
|
|
3723
3957
|
{ name: "bbs.create", description: "Create a BPMAX Business Skill from a standard skill zip.", method: "POST", path: "/api/business_skill" },
|
|
3724
|
-
{ name: "bbs.
|
|
3725
|
-
{ name: "bbs.
|
|
3726
|
-
{ name: "bbs.ensure", description: "Install or update a BPMAX Business Skill lazily before use." }
|
|
3958
|
+
{ name: "bbs.upgrade", description: "Publish a BPMAX Business Skill version.", method: "POST", path: "/api/business_skill/:id/versions" },
|
|
3959
|
+
{ name: "bbs.sync", description: "Sync BPMAX Business Skill catalog.", method: "GET", path: "/api/business_skill" },
|
|
3960
|
+
{ 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" },
|
|
3961
|
+
{ name: "bbs.install", description: "Install a BPMAX Business Skill.", method: "GET", path: "/api/business_skill/:id/download + /api/business_skill/install_record" },
|
|
3962
|
+
{ name: "bbs.update", description: "Update a BPMAX Business Skill.", method: "GET", path: "/api/business_skill/:id/download + /api/business_skill/install_record" },
|
|
3963
|
+
{ name: "bbs.uninstall", description: "Uninstall a BPMAX Business Skill.", method: "POST", path: "/api/business_skill/install_record" },
|
|
3964
|
+
{ name: "bbs.lint", description: "Lint a BPMAX Business Skill package before publish.", bootstrap: true },
|
|
3965
|
+
{ name: "bbs.gate", description: "Run a BPMAX Business Skill business preflight or verify gate.", bootstrap: true },
|
|
3966
|
+
{ name: "api.raw", description: "Call raw BPMAX API paths allowed by server capability whitelist.", method: "*", path: "/api/*" }
|
|
3727
3967
|
];
|
|
3728
3968
|
|
|
3729
3969
|
// src/commands/schema.ts
|
|
@@ -4143,8 +4383,8 @@ function checkCurrentUserCanProcess(step, currentUser) {
|
|
|
4143
4383
|
}
|
|
4144
4384
|
async function buildStepContext(profile, client, stepId, projectId) {
|
|
4145
4385
|
const [project, step, currentUser] = await Promise.all([
|
|
4146
|
-
apiRequest(client, "GET", `/project/${projectId}
|
|
4147
|
-
apiRequest(client, "GET", `/step/${stepId}
|
|
4386
|
+
apiRequest(client, "GET", `/project/${projectId}`, { capability: "step.context" }),
|
|
4387
|
+
apiRequest(client, "GET", `/step/${stepId}`, { capability: "step.context" }),
|
|
4148
4388
|
apiRequest(client, "GET", "/user/current").catch(() => null)
|
|
4149
4389
|
]);
|
|
4150
4390
|
const actualProjectId = projectIdOfStep(step);
|
|
@@ -4857,6 +5097,7 @@ program.hook("preAction", (thisCommand) => {
|
|
|
4857
5097
|
setConfigDir(options.configDir);
|
|
4858
5098
|
});
|
|
4859
5099
|
registerConfigCommands(program);
|
|
5100
|
+
registerCapabilitiesCommands(program);
|
|
4860
5101
|
registerAuthCommands(program);
|
|
4861
5102
|
registerBbsCommands(program);
|
|
4862
5103
|
registerApiCommands(program);
|