bpmax-cli 0.1.34 → 0.1.35
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 +16 -13
- package/dist/bin.js +95 -19
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/scripts/install-skills.mjs +7 -5
- package/skills/bpmax-auth/SKILL.md +5 -5
- package/skills/bpmax-business-skill/SKILL.md +8 -7
- package/skills/bpmax-cli/SKILL.md +3 -3
- package/skills/bpmax-shared/SKILL.md +9 -5
package/README.md
CHANGED
|
@@ -34,7 +34,9 @@ bpmax-cli init \
|
|
|
34
34
|
--format json
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
For
|
|
37
|
+
For Agent 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. When `--profile-scope` is present, `init` creates an isolated context under `~/.bpmax/agent-contexts/<agent>/<scope_hash>/` and returns `config_dir`, `profile`, `message_card.next_command`, and `next_commands`.
|
|
38
|
+
|
|
39
|
+
Agent follow-up commands must copy the returned commands exactly, including `--config-dir`. Do not run bare `bpmax-cli config profile list`, `bpmax-cli auth status`, or `bpmax-cli bbs ...` from a shared Agent environment.
|
|
38
40
|
|
|
39
41
|
The command saves the profile, syncs bundled skills for the selected agent adapter, and returns a `message_card` with:
|
|
40
42
|
|
|
@@ -44,10 +46,10 @@ The command saves the profile, syncs bundled skills for the selected agent adapt
|
|
|
44
46
|
- `next_action`
|
|
45
47
|
- `next_command`
|
|
46
48
|
|
|
47
|
-
After the user confirms the code in BPMAX, complete authorization
|
|
49
|
+
After the user confirms the code in BPMAX, complete authorization by running `message_card.next_command` exactly. In an isolated Agent context it looks like:
|
|
48
50
|
|
|
49
51
|
```bash
|
|
50
|
-
bpmax-cli auth device complete --profile
|
|
52
|
+
bpmax-cli --config-dir ~/.bpmax/agent-contexts/openclaw/<scope_hash> auth device complete --profile local__openclaw__<scope_hash> --session <device_code> --format json
|
|
51
53
|
```
|
|
52
54
|
|
|
53
55
|
For agent-driven use, ask the user for any BPMAX page URL in the target workspace, then run setup with that URL. The CLI extracts the environment origin and workspace from the URL and opens browser authorization without terminal prompts:
|
|
@@ -81,8 +83,8 @@ bpmax-cli auth device start \
|
|
|
81
83
|
--format json
|
|
82
84
|
```
|
|
83
85
|
|
|
84
|
-
The result includes a short `user_code`, `authorization_url`, `session` (same as `device_code`), and a channel-neutral `message_card`. This is the recommended path for
|
|
85
|
-
Agents should execute `message_card.next_command` after the user confirms the code.
|
|
86
|
+
The result includes a short `user_code`, `authorization_url`, `session` (same as `device_code`), and a channel-neutral `message_card`. This is the recommended path for Agents embedded in Feishu or other chat surfaces.
|
|
87
|
+
Agents should execute `message_card.next_command` after the user confirms the code. If the command includes `--config-dir`, keep it unchanged.
|
|
86
88
|
|
|
87
89
|
Complete after the user confirms the code:
|
|
88
90
|
|
|
@@ -172,10 +174,10 @@ The body is passed to `POST /api/project/raw-es-search` unchanged:
|
|
|
172
174
|
|
|
173
175
|
## Profile recipes
|
|
174
176
|
|
|
175
|
-
Profile recipes are local, profile-scoped playbooks for environment-specific BPMAX operations. They live outside project repositories under:
|
|
177
|
+
Profile recipes are local, profile-scoped playbooks for environment-specific BPMAX operations. They live outside project repositories under the active config directory:
|
|
176
178
|
|
|
177
179
|
```text
|
|
178
|
-
|
|
180
|
+
<config-dir>/profiles/<profile>/recipes/<workspace>/<recipe-name>/
|
|
179
181
|
```
|
|
180
182
|
|
|
181
183
|
Create a scaffold for the active profile and workspace:
|
|
@@ -248,18 +250,19 @@ After installation, the script prints an agent-oriented guide. The recommended a
|
|
|
248
250
|
bpmax-cli init --agent <agent> --channel feishu --url "<USER_URL>" --name local --profile-scope "<TRUSTED_RUNTIME_SCOPE>" --format json
|
|
249
251
|
```
|
|
250
252
|
|
|
251
|
-
For
|
|
253
|
+
For Agent 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 and config root are the `profile` and `config_dir` returned by `init`; do not reuse `local` or a shared `~/.bpmax/config.json` for follow-up commands.
|
|
252
254
|
|
|
253
255
|
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.
|
|
256
|
+
4. For later checks, copy `next_commands.profile_list`, `next_commands.auth_status`, and `next_commands.bbs_list` exactly. Do not reconstruct these commands from natural language.
|
|
254
257
|
|
|
255
258
|
For local terminal/browser setup, `bpmax-cli setup "<USER_URL>" --name local` remains available.
|
|
256
259
|
|
|
257
260
|
For business requests, first look for BPMAX Business Skills (BBS):
|
|
258
261
|
|
|
259
262
|
```bash
|
|
260
|
-
bpmax-cli bbs list --profile <profile> --format json
|
|
261
|
-
bpmax-cli bbs sync --agent <agent> --profile <profile> --format json
|
|
262
|
-
bpmax-cli bbs ensure <skill-key> --agent <agent> --profile <profile> --format json
|
|
263
|
+
bpmax-cli --config-dir <config_dir> bbs list --profile <profile> --format json
|
|
264
|
+
bpmax-cli --config-dir <config_dir> bbs sync --agent <agent> --profile <profile> --format json
|
|
265
|
+
bpmax-cli --config-dir <config_dir> bbs ensure <skill-key> --agent <agent> --profile <profile> --format json
|
|
263
266
|
```
|
|
264
267
|
|
|
265
268
|
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`.
|
|
@@ -294,13 +297,13 @@ BPMAX Business Skills (BBS) are standard skill zip packages hosted by a BPMAX en
|
|
|
294
297
|
Sync only the lightweight catalog into an agent:
|
|
295
298
|
|
|
296
299
|
```bash
|
|
297
|
-
bpmax-cli bbs sync --agent openclaw --profile yuanrong --format json
|
|
300
|
+
bpmax-cli --config-dir <config_dir> bbs sync --agent openclaw --profile yuanrong --format json
|
|
298
301
|
```
|
|
299
302
|
|
|
300
303
|
Install or update a business skill only when it is needed:
|
|
301
304
|
|
|
302
305
|
```bash
|
|
303
|
-
bpmax-cli bbs ensure <skill-key> --agent openclaw --profile yuanrong --format json
|
|
306
|
+
bpmax-cli --config-dir <config_dir> bbs ensure <skill-key> --agent openclaw --profile yuanrong --format json
|
|
304
307
|
```
|
|
305
308
|
|
|
306
309
|
Publish a BBS:
|
package/dist/bin.js
CHANGED
|
@@ -16,8 +16,8 @@ var SETUP_COMMAND_HINT = 'Do not show a command template yet. After the user rep
|
|
|
16
16
|
// src/core/config.ts
|
|
17
17
|
var DEFAULT_WORKSPACE = "default";
|
|
18
18
|
var DEFAULT_LANGUAGE = "zhCN";
|
|
19
|
-
var
|
|
20
|
-
var
|
|
19
|
+
var DEFAULT_CONFIG_DIR = path.join(homedir(), ".bpmax");
|
|
20
|
+
var configDirOverride;
|
|
21
21
|
var defaultConfig = () => ({
|
|
22
22
|
version: 2,
|
|
23
23
|
current_profile: "default",
|
|
@@ -61,7 +61,7 @@ var toV2Config = (input) => {
|
|
|
61
61
|
};
|
|
62
62
|
async function loadConfig() {
|
|
63
63
|
try {
|
|
64
|
-
const raw = await readFile(
|
|
64
|
+
const raw = await readFile(getConfigPath(), "utf8");
|
|
65
65
|
const parsed = JSON.parse(raw);
|
|
66
66
|
return toV2Config(parsed);
|
|
67
67
|
} catch (error) {
|
|
@@ -72,18 +72,28 @@ async function loadConfig() {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
async function saveConfig(config) {
|
|
75
|
-
|
|
76
|
-
await
|
|
75
|
+
const configDir = getConfigDir();
|
|
76
|
+
await mkdir(configDir, { recursive: true });
|
|
77
|
+
await writeFile(getConfigPath(), `${JSON.stringify(config, null, 2)}
|
|
77
78
|
`, "utf8");
|
|
78
79
|
}
|
|
79
80
|
function getConfigPath() {
|
|
80
|
-
return
|
|
81
|
+
return path.join(getConfigDir(), "config.json");
|
|
81
82
|
}
|
|
82
83
|
function getConfigDir() {
|
|
83
|
-
return
|
|
84
|
+
return configDirOverride || DEFAULT_CONFIG_DIR;
|
|
85
|
+
}
|
|
86
|
+
function getDefaultConfigDir() {
|
|
87
|
+
return DEFAULT_CONFIG_DIR;
|
|
88
|
+
}
|
|
89
|
+
function setConfigDir(configDir) {
|
|
90
|
+
configDirOverride = configDir?.trim() ? path.resolve(configDir.trim()) : void 0;
|
|
91
|
+
}
|
|
92
|
+
function isConfigDirOverridden() {
|
|
93
|
+
return Boolean(configDirOverride);
|
|
84
94
|
}
|
|
85
95
|
function getProfileDataDir(profileName) {
|
|
86
|
-
return path.join(
|
|
96
|
+
return path.join(getConfigDir(), "profiles", profileName);
|
|
87
97
|
}
|
|
88
98
|
function hashProfileScope(scope) {
|
|
89
99
|
return createHash("sha256").update(scope.trim()).digest("hex").slice(0, 12);
|
|
@@ -93,6 +103,10 @@ function scopedProfileName(baseProfile, agent, scope) {
|
|
|
93
103
|
const safeAgent = agent.trim().replace(/[^a-zA-Z0-9._-]+/g, "_") || "generic";
|
|
94
104
|
return `${safeBase}__${safeAgent}__${hashProfileScope(scope)}`;
|
|
95
105
|
}
|
|
106
|
+
function agentContextConfigDir(agent, scope, rootDir = getDefaultConfigDir()) {
|
|
107
|
+
const safeAgent = agent.trim().replace(/[^a-zA-Z0-9._-]+/g, "_") || "generic";
|
|
108
|
+
return path.join(rootDir, "agent-contexts", safeAgent, hashProfileScope(scope));
|
|
109
|
+
}
|
|
96
110
|
function maskApiKey(apiKey) {
|
|
97
111
|
if (!apiKey) {
|
|
98
112
|
return "(unset)";
|
|
@@ -284,6 +298,12 @@ import { createServer } from "http";
|
|
|
284
298
|
import { randomBytes } from "crypto";
|
|
285
299
|
import axios2 from "axios";
|
|
286
300
|
import open from "open";
|
|
301
|
+
function shellQuote(value) {
|
|
302
|
+
if (/^[A-Za-z0-9_./:@=-]+$/.test(value)) {
|
|
303
|
+
return value;
|
|
304
|
+
}
|
|
305
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
306
|
+
}
|
|
287
307
|
var DeviceAuthorizationError = class extends Error {
|
|
288
308
|
code;
|
|
289
309
|
interval;
|
|
@@ -491,6 +511,7 @@ async function pollDeviceLogin(options) {
|
|
|
491
511
|
throw new DeviceAuthorizationError("expired_token", "Device authorization expired.");
|
|
492
512
|
}
|
|
493
513
|
function buildAuthorizationMessageCard(input) {
|
|
514
|
+
const configDirPrefix = input.config_dir ? ` --config-dir ${shellQuote(input.config_dir)}` : "";
|
|
494
515
|
return {
|
|
495
516
|
title: "Authorize BPMAX CLI",
|
|
496
517
|
summary: `Open the authorization link and confirm code ${input.user_code} for profile "${input.profile}".`,
|
|
@@ -498,7 +519,7 @@ function buildAuthorizationMessageCard(input) {
|
|
|
498
519
|
user_code: input.user_code,
|
|
499
520
|
expires_at: input.expires_at,
|
|
500
521
|
next_action: "Open the authorization URL, confirm the code, then run next_command.",
|
|
501
|
-
next_command: `bpmax-cli auth device complete --profile ${input.profile} --session ${input.device_code} --format json`
|
|
522
|
+
next_command: `bpmax-cli${configDirPrefix} auth device complete --profile ${input.profile} --session ${input.device_code} --format json`
|
|
502
523
|
};
|
|
503
524
|
}
|
|
504
525
|
function updateProfileAuth(profile, result) {
|
|
@@ -511,11 +532,16 @@ function updateProfileAuth(profile, result) {
|
|
|
511
532
|
|
|
512
533
|
// src/commands/auth.ts
|
|
513
534
|
function deviceStartBody(result) {
|
|
535
|
+
const configDir = isConfigDirOverridden() ? getConfigDir() : void 0;
|
|
514
536
|
return {
|
|
515
537
|
ok: true,
|
|
516
538
|
...result,
|
|
517
539
|
session: result.device_code,
|
|
518
|
-
|
|
540
|
+
...configDir ? { config_dir: configDir } : {},
|
|
541
|
+
message_card: buildAuthorizationMessageCard({
|
|
542
|
+
...result,
|
|
543
|
+
...configDir ? { config_dir: configDir } : {}
|
|
544
|
+
})
|
|
519
545
|
};
|
|
520
546
|
}
|
|
521
547
|
function registerAuthCommands(program2, deps = {}) {
|
|
@@ -565,7 +591,13 @@ function registerAuthCommands(program2, deps = {}) {
|
|
|
565
591
|
profile: profile.name,
|
|
566
592
|
login: "authenticated",
|
|
567
593
|
user: result.user,
|
|
568
|
-
...authorization ? {
|
|
594
|
+
...authorization ? {
|
|
595
|
+
authorization,
|
|
596
|
+
message_card: buildAuthorizationMessageCard({
|
|
597
|
+
...authorization,
|
|
598
|
+
...isConfigDirOverridden() ? { config_dir: getConfigDir() } : {}
|
|
599
|
+
})
|
|
600
|
+
} : {}
|
|
569
601
|
});
|
|
570
602
|
} else {
|
|
571
603
|
console.log(`Saved API key for profile "${profile.name}".`);
|
|
@@ -674,7 +706,7 @@ async function parseJsonInput(input, label = "JSON input") {
|
|
|
674
706
|
// package.json
|
|
675
707
|
var package_default = {
|
|
676
708
|
name: "bpmax-cli",
|
|
677
|
-
version: "0.1.
|
|
709
|
+
version: "0.1.35",
|
|
678
710
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
679
711
|
type: "module",
|
|
680
712
|
bin: {
|
|
@@ -1032,7 +1064,7 @@ async function exists(targetPath) {
|
|
|
1032
1064
|
}
|
|
1033
1065
|
}
|
|
1034
1066
|
function businessSkillStatePath(profileName, agent) {
|
|
1035
|
-
return path2.join(
|
|
1067
|
+
return path2.join(getConfigDir(), "business-skills", profileName, agent, "state.json");
|
|
1036
1068
|
}
|
|
1037
1069
|
async function readBusinessSkillState(profileName, agent) {
|
|
1038
1070
|
try {
|
|
@@ -1912,6 +1944,12 @@ async function syncSkills(version, options = {}) {
|
|
|
1912
1944
|
}
|
|
1913
1945
|
|
|
1914
1946
|
// src/commands/init.ts
|
|
1947
|
+
function shellQuote2(value) {
|
|
1948
|
+
if (/^[A-Za-z0-9_./:@=-]+$/.test(value)) {
|
|
1949
|
+
return value;
|
|
1950
|
+
}
|
|
1951
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
1952
|
+
}
|
|
1915
1953
|
function parseSkillsDetail(stdout) {
|
|
1916
1954
|
if (!stdout?.trim()) {
|
|
1917
1955
|
return void 0;
|
|
@@ -1955,6 +1993,10 @@ function registerInitCommand(program2, deps = {}) {
|
|
|
1955
1993
|
const profileScope = options.profileScope?.trim();
|
|
1956
1994
|
const profileName = profileScope ? scopedProfileName(baseProfileName, options.agent, profileScope) : baseProfileName;
|
|
1957
1995
|
const profileScopeHash = profileScope ? hashProfileScope(profileScope) : void 0;
|
|
1996
|
+
if (profileScope) {
|
|
1997
|
+
setConfigDir(agentContextConfigDir(options.agent, profileScope));
|
|
1998
|
+
}
|
|
1999
|
+
const configDir = getConfigDir();
|
|
1958
2000
|
const config = await loadConfig2();
|
|
1959
2001
|
const nextConfig = applySetupProfile(config, profileName, {
|
|
1960
2002
|
origin: parsed.origin,
|
|
@@ -1964,7 +2006,8 @@ function registerInitCommand(program2, deps = {}) {
|
|
|
1964
2006
|
await saveConfig2(nextConfig);
|
|
1965
2007
|
const skills = await syncSkills2(VERSION, {
|
|
1966
2008
|
force: Boolean(options.forceSkills),
|
|
1967
|
-
agent: options.agent
|
|
2009
|
+
agent: options.agent,
|
|
2010
|
+
configDir
|
|
1968
2011
|
});
|
|
1969
2012
|
const authorization = await startDeviceLogin2({
|
|
1970
2013
|
origin: parsed.origin,
|
|
@@ -1974,13 +2017,17 @@ function registerInitCommand(program2, deps = {}) {
|
|
|
1974
2017
|
agent: options.agent,
|
|
1975
2018
|
channel: options.channel
|
|
1976
2019
|
});
|
|
2020
|
+
const commandPrefix2 = `bpmax-cli --config-dir ${shellQuote2(configDir)}`;
|
|
1977
2021
|
printResult(options.format, {
|
|
1978
2022
|
ok: true,
|
|
1979
2023
|
profile: profileName,
|
|
1980
2024
|
...profileScope ? {
|
|
1981
2025
|
base_profile: baseProfileName,
|
|
1982
2026
|
profile_isolated: true,
|
|
1983
|
-
profile_scope_hash: profileScopeHash
|
|
2027
|
+
profile_scope_hash: profileScopeHash,
|
|
2028
|
+
config_dir: configDir,
|
|
2029
|
+
context_isolated: true,
|
|
2030
|
+
context_scope_hash: profileScopeHash
|
|
1984
2031
|
} : {},
|
|
1985
2032
|
origin: parsed.origin,
|
|
1986
2033
|
workspace: parsed.workspace,
|
|
@@ -1992,7 +2039,17 @@ function registerInitCommand(program2, deps = {}) {
|
|
|
1992
2039
|
...skills.action === "failed" ? { error: skills.result?.stderr || skills.result?.stdout } : {}
|
|
1993
2040
|
},
|
|
1994
2041
|
authorization,
|
|
1995
|
-
message_card: buildAuthorizationMessageCard(
|
|
2042
|
+
message_card: buildAuthorizationMessageCard({
|
|
2043
|
+
...authorization,
|
|
2044
|
+
...profileScope ? { config_dir: configDir } : {}
|
|
2045
|
+
}),
|
|
2046
|
+
...profileScope ? {
|
|
2047
|
+
next_commands: {
|
|
2048
|
+
profile_list: `${commandPrefix2} config profile list --format json`,
|
|
2049
|
+
auth_status: `${commandPrefix2} auth status --profile ${profileName} --format json`,
|
|
2050
|
+
bbs_list: `${commandPrefix2} bbs list --profile ${profileName} --format json`
|
|
2051
|
+
}
|
|
2052
|
+
} : {}
|
|
1996
2053
|
});
|
|
1997
2054
|
});
|
|
1998
2055
|
}
|
|
@@ -3497,12 +3554,13 @@ function registerRecipeCommands(program2, deps = {}) {
|
|
|
3497
3554
|
variables,
|
|
3498
3555
|
profileName: target.name
|
|
3499
3556
|
});
|
|
3500
|
-
const
|
|
3557
|
+
const runnableArgv = isConfigDirOverridden() ? ["--config-dir", getConfigDir(), ...argv] : argv;
|
|
3558
|
+
const exitCode = await runRecipe(runnableArgv);
|
|
3501
3559
|
if (exitCode !== 0) {
|
|
3502
3560
|
throw new Error(`Recipe command failed with exit code ${exitCode}.`);
|
|
3503
3561
|
}
|
|
3504
3562
|
if (options.format === "json") {
|
|
3505
|
-
printResult("json", { name, profile: target.name, workspace: location.workspaceDirName, argv, exitCode });
|
|
3563
|
+
printResult("json", { name, profile: target.name, workspace: location.workspaceDirName, argv: runnableArgv, exitCode });
|
|
3506
3564
|
}
|
|
3507
3565
|
});
|
|
3508
3566
|
}
|
|
@@ -4142,7 +4200,24 @@ async function setupNotices(argv = process.argv) {
|
|
|
4142
4200
|
|
|
4143
4201
|
// src/bin.ts
|
|
4144
4202
|
var program = new Command();
|
|
4145
|
-
|
|
4203
|
+
function configDirFromArgv(argv) {
|
|
4204
|
+
const option = "--config-dir";
|
|
4205
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
4206
|
+
const arg = argv[index];
|
|
4207
|
+
if (arg === option) {
|
|
4208
|
+
return argv[index + 1];
|
|
4209
|
+
}
|
|
4210
|
+
if (arg.startsWith(`${option}=`)) {
|
|
4211
|
+
return arg.slice(option.length + 1);
|
|
4212
|
+
}
|
|
4213
|
+
}
|
|
4214
|
+
return void 0;
|
|
4215
|
+
}
|
|
4216
|
+
program.name(CLI_NAME).description("BPMAX multi-environment CLI").version(VERSION).option("--config-dir <dir>", "Root directory for bpmax-cli local state");
|
|
4217
|
+
program.hook("preAction", (thisCommand) => {
|
|
4218
|
+
const options = thisCommand.optsWithGlobals();
|
|
4219
|
+
setConfigDir(options.configDir);
|
|
4220
|
+
});
|
|
4146
4221
|
registerConfigCommands(program);
|
|
4147
4222
|
registerAuthCommands(program);
|
|
4148
4223
|
registerBbsCommands(program);
|
|
@@ -4159,6 +4234,7 @@ registerSetupCommand(program);
|
|
|
4159
4234
|
registerInitCommand(program);
|
|
4160
4235
|
registerUpdateCommands(program);
|
|
4161
4236
|
var isCompletion = process.argv.includes("completion") || process.argv.includes("__complete");
|
|
4237
|
+
setConfigDir(configDirFromArgv(process.argv));
|
|
4162
4238
|
(isCompletion ? Promise.resolve() : setupNotices()).then(() => program.parseAsync(process.argv)).catch((error) => {
|
|
4163
4239
|
console.error(error instanceof Error ? error.message : String(error));
|
|
4164
4240
|
process.exitCode = 1;
|