bpmax-cli 0.1.35 → 0.1.37
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 -0
- package/dist/bin.js +462 -60
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-cli/SKILL.md +1 -0
- package/skills/bpmax-project/SKILL.md +27 -0
package/dist/bin.js
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
// src/bin.ts
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
|
|
6
|
+
// src/commands/api.ts
|
|
7
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
8
|
+
|
|
6
9
|
// src/core/config.ts
|
|
7
10
|
import { homedir } from "os";
|
|
8
11
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
@@ -210,6 +213,27 @@ async function apiRequest(client, method, path6, options = {}) {
|
|
|
210
213
|
return body.data ?? body;
|
|
211
214
|
}
|
|
212
215
|
|
|
216
|
+
// src/core/json-input.ts
|
|
217
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
218
|
+
async function parseJsonInput(input, label = "JSON input") {
|
|
219
|
+
const source = input.startsWith("@") ? input.slice(1) : void 0;
|
|
220
|
+
if (source === "") {
|
|
221
|
+
throw new Error(`${label} file path is empty.`);
|
|
222
|
+
}
|
|
223
|
+
const raw = source ? await readFile2(source, "utf8") : input;
|
|
224
|
+
let parsed;
|
|
225
|
+
try {
|
|
226
|
+
parsed = JSON.parse(raw);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
229
|
+
throw new Error(`${label} is not valid JSON: ${detail}`);
|
|
230
|
+
}
|
|
231
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
232
|
+
throw new Error(`${label} must be a JSON object.`);
|
|
233
|
+
}
|
|
234
|
+
return parsed;
|
|
235
|
+
}
|
|
236
|
+
|
|
213
237
|
// src/core/output.ts
|
|
214
238
|
var noticeProvider = null;
|
|
215
239
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -275,19 +299,43 @@ function printResult(format, value) {
|
|
|
275
299
|
}
|
|
276
300
|
|
|
277
301
|
// src/commands/api.ts
|
|
278
|
-
function
|
|
302
|
+
async function parseJsonAny(input, label = "JSON input") {
|
|
279
303
|
if (!input) {
|
|
280
304
|
return void 0;
|
|
281
305
|
}
|
|
282
|
-
|
|
306
|
+
const source = input.startsWith("@") ? input.slice(1) : void 0;
|
|
307
|
+
if (source === "") {
|
|
308
|
+
throw new Error(`${label} file path is empty.`);
|
|
309
|
+
}
|
|
310
|
+
const raw = source ? await readFile3(source, "utf8") : input;
|
|
311
|
+
try {
|
|
312
|
+
return JSON.parse(raw);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
315
|
+
throw new Error(`${label} is not valid JSON: ${detail}`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function isMutatingMethod(method) {
|
|
319
|
+
return ["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase());
|
|
283
320
|
}
|
|
284
321
|
function registerApiCommands(program2) {
|
|
285
|
-
program2.command("api <method> <path>").description("Call an arbitrary BPMAX /api endpoint").option("--profile <profile>", "Profile name").option("--params <json>", "Query params JSON").option("--data <json>", "Request body JSON").option("--format <format>", "Output format", "json").action(async (method, path6, options) => {
|
|
322
|
+
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
|
+
const normalizedMethod = method.toUpperCase();
|
|
324
|
+
if (isMutatingMethod(normalizedMethod) && options.confirmMutating !== true) {
|
|
325
|
+
printResult(options.format, {
|
|
326
|
+
ok: false,
|
|
327
|
+
dry_run: true,
|
|
328
|
+
method: normalizedMethod,
|
|
329
|
+
path: path6,
|
|
330
|
+
warning: "Mutating raw API calls require --confirm-mutating. Prefer typed bpmax-cli commands such as step submit."
|
|
331
|
+
});
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
286
334
|
const config = await loadConfig();
|
|
287
335
|
const profile = resolveProfile(config, options.profile);
|
|
288
|
-
const result = await apiRequest(createApiClient(profile),
|
|
289
|
-
params:
|
|
290
|
-
data:
|
|
336
|
+
const result = await apiRequest(createApiClient(profile), normalizedMethod, path6, {
|
|
337
|
+
params: options.params ? await parseJsonInput(options.params, "--params") : void 0,
|
|
338
|
+
data: await parseJsonAny(options.data, "--data")
|
|
291
339
|
});
|
|
292
340
|
printResult(options.format, result);
|
|
293
341
|
});
|
|
@@ -680,33 +728,12 @@ function registerAuthCommands(program2, deps = {}) {
|
|
|
680
728
|
|
|
681
729
|
// src/commands/bbs.ts
|
|
682
730
|
import { basename } from "path";
|
|
683
|
-
import { readFile as
|
|
684
|
-
|
|
685
|
-
// src/core/json-input.ts
|
|
686
|
-
import { readFile as readFile2 } from "fs/promises";
|
|
687
|
-
async function parseJsonInput(input, label = "JSON input") {
|
|
688
|
-
const source = input.startsWith("@") ? input.slice(1) : void 0;
|
|
689
|
-
if (source === "") {
|
|
690
|
-
throw new Error(`${label} file path is empty.`);
|
|
691
|
-
}
|
|
692
|
-
const raw = source ? await readFile2(source, "utf8") : input;
|
|
693
|
-
let parsed;
|
|
694
|
-
try {
|
|
695
|
-
parsed = JSON.parse(raw);
|
|
696
|
-
} catch (error) {
|
|
697
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
698
|
-
throw new Error(`${label} is not valid JSON: ${detail}`);
|
|
699
|
-
}
|
|
700
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
701
|
-
throw new Error(`${label} must be a JSON object.`);
|
|
702
|
-
}
|
|
703
|
-
return parsed;
|
|
704
|
-
}
|
|
731
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
705
732
|
|
|
706
733
|
// package.json
|
|
707
734
|
var package_default = {
|
|
708
735
|
name: "bpmax-cli",
|
|
709
|
-
version: "0.1.
|
|
736
|
+
version: "0.1.37",
|
|
710
737
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
711
738
|
type: "module",
|
|
712
739
|
bin: {
|
|
@@ -867,7 +894,7 @@ function attachProjectDetailUrl(profile, value) {
|
|
|
867
894
|
}
|
|
868
895
|
|
|
869
896
|
// src/core/business-skills.ts
|
|
870
|
-
import { cp, mkdir as mkdir2, readFile as
|
|
897
|
+
import { cp, mkdir as mkdir2, readFile as readFile4, rm, stat, writeFile as writeFile2 } from "fs/promises";
|
|
871
898
|
import { createHash as createHash2 } from "crypto";
|
|
872
899
|
import { homedir as homedir2, tmpdir } from "os";
|
|
873
900
|
import path2 from "path";
|
|
@@ -983,7 +1010,7 @@ function parseBbsJson(raw) {
|
|
|
983
1010
|
}
|
|
984
1011
|
async function readBbsJson(skillDir) {
|
|
985
1012
|
try {
|
|
986
|
-
return parseBbsJson(await
|
|
1013
|
+
return parseBbsJson(await readFile4(path2.join(skillDir, "bbs.json"), "utf8"));
|
|
987
1014
|
} catch (error) {
|
|
988
1015
|
if (error.code === "ENOENT") {
|
|
989
1016
|
return void 0;
|
|
@@ -1068,7 +1095,7 @@ function businessSkillStatePath(profileName, agent) {
|
|
|
1068
1095
|
}
|
|
1069
1096
|
async function readBusinessSkillState(profileName, agent) {
|
|
1070
1097
|
try {
|
|
1071
|
-
return JSON.parse(await
|
|
1098
|
+
return JSON.parse(await readFile4(businessSkillStatePath(profileName, agent), "utf8"));
|
|
1072
1099
|
} catch {
|
|
1073
1100
|
return { skills: {} };
|
|
1074
1101
|
}
|
|
@@ -1139,7 +1166,7 @@ async function lintBusinessSkillDirectory(skillDir, options = {}) {
|
|
|
1139
1166
|
let manifest = {};
|
|
1140
1167
|
let config;
|
|
1141
1168
|
try {
|
|
1142
|
-
skillMarkdown = await
|
|
1169
|
+
skillMarkdown = await readFile4(path2.join(skillDir, "SKILL.md"), "utf8");
|
|
1143
1170
|
manifest = parseFrontmatter(skillMarkdown);
|
|
1144
1171
|
} catch {
|
|
1145
1172
|
issues.push(issue("error", "missing_skill_md", "BBS package must contain top-level SKILL.md."));
|
|
@@ -1226,7 +1253,7 @@ async function lintBusinessSkillDirectory(skillDir, options = {}) {
|
|
|
1226
1253
|
}
|
|
1227
1254
|
async function lintBusinessSkillZip(zipPath, options = {}) {
|
|
1228
1255
|
try {
|
|
1229
|
-
const buffer = await
|
|
1256
|
+
const buffer = await readFile4(zipPath);
|
|
1230
1257
|
const dir = await zipDirectoryToTemp(buffer, "bbs-lint");
|
|
1231
1258
|
return lintBusinessSkillDirectory(dir, options);
|
|
1232
1259
|
} catch (error) {
|
|
@@ -1247,7 +1274,7 @@ async function runBusinessSkillGate(options) {
|
|
|
1247
1274
|
let skillMarkdown = "";
|
|
1248
1275
|
let config;
|
|
1249
1276
|
try {
|
|
1250
|
-
skillMarkdown = await
|
|
1277
|
+
skillMarkdown = await readFile4(path2.join(options.skillDir, "SKILL.md"), "utf8");
|
|
1251
1278
|
} catch {
|
|
1252
1279
|
errors.push(issue("error", "missing_skill_md", "Installed BBS is missing SKILL.md."));
|
|
1253
1280
|
}
|
|
@@ -1410,7 +1437,7 @@ async function buildCatalogSkill(skills) {
|
|
|
1410
1437
|
|
|
1411
1438
|
// src/commands/bbs.ts
|
|
1412
1439
|
async function zipPayload(zipPath) {
|
|
1413
|
-
const buffer = await
|
|
1440
|
+
const buffer = await readFile5(zipPath);
|
|
1414
1441
|
return {
|
|
1415
1442
|
zip_base64: buffer.toString("base64"),
|
|
1416
1443
|
file_name: basename(zipPath)
|
|
@@ -1723,13 +1750,42 @@ function registerEsCommands(program2) {
|
|
|
1723
1750
|
}
|
|
1724
1751
|
|
|
1725
1752
|
// src/commands/flow.ts
|
|
1753
|
+
function normalizeWorkspaceKey(workspace) {
|
|
1754
|
+
const nextWorkspace = workspace.trim().replace(/^\/+|\/+$/g, "");
|
|
1755
|
+
return nextWorkspace.startsWith("w:") ? nextWorkspace.slice(2) : nextWorkspace;
|
|
1756
|
+
}
|
|
1757
|
+
function flowBindingKey(flowType, flowKey) {
|
|
1758
|
+
return `${String(flowType || "default")}:${String(flowKey || "")}`;
|
|
1759
|
+
}
|
|
1760
|
+
async function getWorkspaceFlowBindings(client, profile, options) {
|
|
1761
|
+
if (options.all) {
|
|
1762
|
+
return void 0;
|
|
1763
|
+
}
|
|
1764
|
+
const workspace = normalizeWorkspaceKey(options.workspace || profile.config.workspace);
|
|
1765
|
+
const workspaceInfo = await apiRequest(client, "GET", "/workspace/by_key", {
|
|
1766
|
+
params: {
|
|
1767
|
+
key: workspace
|
|
1768
|
+
}
|
|
1769
|
+
});
|
|
1770
|
+
return new Set(
|
|
1771
|
+
(workspaceInfo.workspace_flow || []).map((item) => flowBindingKey(item.flow_type, item.flow_key))
|
|
1772
|
+
);
|
|
1773
|
+
}
|
|
1774
|
+
function filterFlowsByBindings(flows, bindings) {
|
|
1775
|
+
if (!bindings) {
|
|
1776
|
+
return flows;
|
|
1777
|
+
}
|
|
1778
|
+
return flows.filter((flow) => bindings.has(flowBindingKey(flow.flow_type, flow.key)));
|
|
1779
|
+
}
|
|
1726
1780
|
function registerFlowCommands(program2) {
|
|
1727
1781
|
const flow = program2.command("flow").description("Flow commands");
|
|
1728
|
-
flow.command("list").description("List flows").option("--profile <profile>", "Profile name").option("--draft <draft>", "Draft flag", "1").option("--format <format>", "Output format", "table").action(async (options) => {
|
|
1782
|
+
flow.command("list").description("List flows").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--all", "List all flows without workspace binding filtering").option("--draft <draft>", "Draft flag", "1").option("--format <format>", "Output format", "table").action(async (options) => {
|
|
1729
1783
|
const config = await loadConfig();
|
|
1730
1784
|
const profile = resolveProfile(config, options.profile);
|
|
1785
|
+
const client = createApiClient(profile);
|
|
1786
|
+
const bindings = await getWorkspaceFlowBindings(client, profile, options);
|
|
1731
1787
|
const result = await apiRequest(
|
|
1732
|
-
|
|
1788
|
+
client,
|
|
1733
1789
|
"GET",
|
|
1734
1790
|
"/flow/flow_type",
|
|
1735
1791
|
{
|
|
@@ -1739,40 +1795,48 @@ function registerFlowCommands(program2) {
|
|
|
1739
1795
|
}
|
|
1740
1796
|
}
|
|
1741
1797
|
);
|
|
1742
|
-
printResult(options.format, result);
|
|
1798
|
+
printResult(options.format, filterFlowsByBindings(result, bindings));
|
|
1743
1799
|
});
|
|
1744
|
-
flow.command("options").description("List flow options").option("--profile <profile>", "Profile name").option("--name <name>", "Flow name filter").option("--format <format>", "Output format", "table").action(async (options) => {
|
|
1800
|
+
flow.command("options").description("List flow options").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--all", "List all flow options without workspace binding filtering").option("--name <name>", "Flow name filter").option("--format <format>", "Output format", "table").action(async (options) => {
|
|
1745
1801
|
const config = await loadConfig();
|
|
1746
1802
|
const profile = resolveProfile(config, options.profile);
|
|
1803
|
+
const client = createApiClient(profile);
|
|
1804
|
+
const bindings = await getWorkspaceFlowBindings(client, profile, options);
|
|
1747
1805
|
const result = await apiRequest(
|
|
1748
|
-
|
|
1806
|
+
client,
|
|
1749
1807
|
"GET",
|
|
1750
1808
|
"/flow/options",
|
|
1751
1809
|
{
|
|
1752
1810
|
params: options.name ? { name: options.name } : void 0
|
|
1753
1811
|
}
|
|
1754
1812
|
);
|
|
1755
|
-
printResult(options.format, result);
|
|
1813
|
+
printResult(options.format, filterFlowsByBindings(result, bindings));
|
|
1756
1814
|
});
|
|
1757
|
-
flow.command("get").description("Get flow detail by id or flow_type/flow_key").option("--id <id>", "Flow id").option("--flow-type <flowType>", "Flow type").option("--flow-key <flowKey>", "Flow key", "").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
1815
|
+
flow.command("get").description("Get flow detail by id or flow_type/flow_key").option("--id <id>", "Flow id").option("--flow-type <flowType>", "Flow type").option("--flow-key <flowKey>", "Flow key", "").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--all", "Get flow by flow_type without workspace binding filtering").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
1758
1816
|
const config = await loadConfig();
|
|
1759
1817
|
const profile = resolveProfile(config, options.profile);
|
|
1760
1818
|
const client = createApiClient(profile);
|
|
1761
1819
|
if (options.flowType) {
|
|
1820
|
+
const bindings = await getWorkspaceFlowBindings(client, profile, options);
|
|
1821
|
+
const path6 = options.flowKey ? "/flow/options" : "/flow/flow_type";
|
|
1822
|
+
const params = options.flowKey ? {
|
|
1823
|
+
detail: "1"
|
|
1824
|
+
} : {
|
|
1825
|
+
draft: "1",
|
|
1826
|
+
skip_i18n: "true"
|
|
1827
|
+
};
|
|
1762
1828
|
const result2 = await apiRequest(
|
|
1763
1829
|
client,
|
|
1764
1830
|
"GET",
|
|
1765
|
-
|
|
1831
|
+
path6,
|
|
1766
1832
|
{
|
|
1767
|
-
params
|
|
1768
|
-
draft: "1",
|
|
1769
|
-
skip_i18n: "true"
|
|
1770
|
-
}
|
|
1833
|
+
params
|
|
1771
1834
|
}
|
|
1772
1835
|
);
|
|
1836
|
+
const filteredResult = filterFlowsByBindings(result2, bindings);
|
|
1773
1837
|
printResult(
|
|
1774
1838
|
options.format,
|
|
1775
|
-
|
|
1839
|
+
filteredResult.find((item) => item.flow_type === options.flowType && String(item.key || "") === options.flowKey) ?? null
|
|
1776
1840
|
);
|
|
1777
1841
|
return;
|
|
1778
1842
|
}
|
|
@@ -1874,7 +1938,7 @@ function setupSummary(input) {
|
|
|
1874
1938
|
}
|
|
1875
1939
|
|
|
1876
1940
|
// src/core/skills.ts
|
|
1877
|
-
import { mkdir as mkdir3, readFile as
|
|
1941
|
+
import { mkdir as mkdir3, readFile as readFile6, writeFile as writeFile3 } from "fs/promises";
|
|
1878
1942
|
import path3 from "path";
|
|
1879
1943
|
import { fileURLToPath } from "url";
|
|
1880
1944
|
var SKILLS_STAMP_FILE = "skills.stamp";
|
|
@@ -1887,7 +1951,7 @@ function stampPath(configDir = getConfigDir()) {
|
|
|
1887
1951
|
}
|
|
1888
1952
|
async function readSkillsStamp(configDir = getConfigDir()) {
|
|
1889
1953
|
try {
|
|
1890
|
-
return (await
|
|
1954
|
+
return (await readFile6(stampPath(configDir), "utf8")).trim();
|
|
1891
1955
|
} catch {
|
|
1892
1956
|
return "";
|
|
1893
1957
|
}
|
|
@@ -2633,7 +2697,7 @@ async function buildProjectFormPayload(client, flowDetail, form, knownTemplate)
|
|
|
2633
2697
|
}
|
|
2634
2698
|
|
|
2635
2699
|
// src/commands/project.ts
|
|
2636
|
-
function
|
|
2700
|
+
function parseJson(input) {
|
|
2637
2701
|
if (!input) {
|
|
2638
2702
|
return {};
|
|
2639
2703
|
}
|
|
@@ -3026,7 +3090,7 @@ function registerProjectCommands(program2) {
|
|
|
3026
3090
|
page: Number(options.page),
|
|
3027
3091
|
page_size: Number(options.pageSize)
|
|
3028
3092
|
},
|
|
3029
|
-
data:
|
|
3093
|
+
data: parseJson(options.body)
|
|
3030
3094
|
}
|
|
3031
3095
|
);
|
|
3032
3096
|
printResult(options.format, result);
|
|
@@ -3091,11 +3155,11 @@ function registerProjectCommands(program2) {
|
|
|
3091
3155
|
const profile = resolveProfile(config, options.profile);
|
|
3092
3156
|
const client = createApiClient(profile);
|
|
3093
3157
|
const useInteractive = !options.body && options.interactive !== false;
|
|
3094
|
-
let payload =
|
|
3158
|
+
let payload = parseJson(options.body);
|
|
3095
3159
|
if (!options.body) {
|
|
3096
3160
|
const flow = await resolveFlowIdentifiers(client, options, { loadDetail: useInteractive });
|
|
3097
3161
|
const { flowDetail, ...flowIdentifiers } = flow;
|
|
3098
|
-
const extra =
|
|
3162
|
+
const extra = parseJson(options.json);
|
|
3099
3163
|
const form = typeof extra.form === "object" && extra.form !== null && !Array.isArray(extra.form) ? extra.form : {};
|
|
3100
3164
|
let name = options.name;
|
|
3101
3165
|
let projectFormTemplate;
|
|
@@ -3210,7 +3274,7 @@ import { spawn as spawn2 } from "child_process";
|
|
|
3210
3274
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3211
3275
|
|
|
3212
3276
|
// src/core/recipes.ts
|
|
3213
|
-
import { access, mkdir as mkdir4, readdir, readFile as
|
|
3277
|
+
import { access, mkdir as mkdir4, readdir, readFile as readFile7, writeFile as writeFile4 } from "fs/promises";
|
|
3214
3278
|
import path4 from "path";
|
|
3215
3279
|
var RECIPE_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
|
|
3216
3280
|
var TEMPLATE_PATTERN = /{{\s*([a-zA-Z0-9_.-]+)\s*}}/g;
|
|
@@ -3292,7 +3356,7 @@ function parseRecipeDefinition(input) {
|
|
|
3292
3356
|
};
|
|
3293
3357
|
}
|
|
3294
3358
|
async function loadRecipe(recipeDir) {
|
|
3295
|
-
const raw = await
|
|
3359
|
+
const raw = await readFile7(path4.join(recipeDir, "recipe.json"), "utf8");
|
|
3296
3360
|
return parseRecipeDefinition(JSON.parse(raw));
|
|
3297
3361
|
}
|
|
3298
3362
|
async function listRecipes(recipesDir) {
|
|
@@ -3391,7 +3455,7 @@ async function renderArgv(options) {
|
|
|
3391
3455
|
const rendered = [];
|
|
3392
3456
|
for (const token of options.recipe.command.argv) {
|
|
3393
3457
|
if (token.startsWith("@")) {
|
|
3394
|
-
const raw = await
|
|
3458
|
+
const raw = await readFile7(resolveRecipeFile(options.recipeDir, token), "utf8");
|
|
3395
3459
|
rendered.push(renderTemplate(raw, options.variables));
|
|
3396
3460
|
} else {
|
|
3397
3461
|
rendered.push(renderTemplate(token, options.variables));
|
|
@@ -3581,6 +3645,9 @@ var schemaEntries = [
|
|
|
3581
3645
|
{ name: "project.approval-context", description: "Get project form values and ended approval step form values.", method: "GET", path: "/api/project/:id + /api/step/:id" },
|
|
3582
3646
|
{ name: "project.create", description: "Create a project with local form schema validation when form payload is provided.", method: "POST", path: "/api/project" },
|
|
3583
3647
|
{ name: "step.get", description: "Get step detail.", method: "GET", path: "/api/step/:id" },
|
|
3648
|
+
{ name: "step.context", description: "Get safe step processing context before mutation.", method: "GET", path: "/api/project/:id + /api/step/:id + /api/user/current" },
|
|
3649
|
+
{ name: "step.actions", description: "List safe step actions parsed from the flow node.", method: "GET", path: "/api/project/:id + /api/step/:id" },
|
|
3650
|
+
{ name: "step.submit", description: "Dry-run or submit a step action with safety checks.", method: "PUT", path: "/api/step/:id?action=:action" },
|
|
3584
3651
|
{ name: "bbs.list", description: "List BPMAX Business Skills.", method: "GET", path: "/api/business_skill" },
|
|
3585
3652
|
{ name: "bbs.create", description: "Create a BPMAX Business Skill from a standard skill zip.", method: "POST", path: "/api/business_skill" },
|
|
3586
3653
|
{ name: "bbs.lint", description: "Lint a BPMAX Business Skill package before publish." },
|
|
@@ -3686,6 +3753,257 @@ function registerSetupCommand(program2, deps = {}) {
|
|
|
3686
3753
|
}
|
|
3687
3754
|
|
|
3688
3755
|
// src/commands/step.ts
|
|
3756
|
+
function isRecord7(value) {
|
|
3757
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3758
|
+
}
|
|
3759
|
+
function stringValue(value) {
|
|
3760
|
+
if (value === void 0 || value === null) {
|
|
3761
|
+
return void 0;
|
|
3762
|
+
}
|
|
3763
|
+
const next = String(value).trim();
|
|
3764
|
+
return next ? next : void 0;
|
|
3765
|
+
}
|
|
3766
|
+
function idValue(value) {
|
|
3767
|
+
const next = stringValue(value);
|
|
3768
|
+
return next && /^\d+$/.test(next) ? next : void 0;
|
|
3769
|
+
}
|
|
3770
|
+
function hasMeaningfulValue(value) {
|
|
3771
|
+
if (value === void 0 || value === null) {
|
|
3772
|
+
return false;
|
|
3773
|
+
}
|
|
3774
|
+
if (typeof value === "string") {
|
|
3775
|
+
return value.trim().length > 0;
|
|
3776
|
+
}
|
|
3777
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
3778
|
+
return true;
|
|
3779
|
+
}
|
|
3780
|
+
if (Array.isArray(value)) {
|
|
3781
|
+
return value.some(hasMeaningfulValue);
|
|
3782
|
+
}
|
|
3783
|
+
if (isRecord7(value)) {
|
|
3784
|
+
return Object.values(value).some(hasMeaningfulValue);
|
|
3785
|
+
}
|
|
3786
|
+
return false;
|
|
3787
|
+
}
|
|
3788
|
+
function projectIdOfStep(step) {
|
|
3789
|
+
const nestedProjectId = isRecord7(step.project) ? step.project.id : void 0;
|
|
3790
|
+
return idValue(step.project_id ?? step.projectId ?? nestedProjectId);
|
|
3791
|
+
}
|
|
3792
|
+
function stepFlowNodeId(step) {
|
|
3793
|
+
return stringValue(step.flow_step_id ?? step.flowStepId ?? step.flow_node_id ?? step.flowNodeId);
|
|
3794
|
+
}
|
|
3795
|
+
function isStepFinished(step) {
|
|
3796
|
+
if (step.real_end_time || step.end_time) {
|
|
3797
|
+
return true;
|
|
3798
|
+
}
|
|
3799
|
+
const status = step.status;
|
|
3800
|
+
if (typeof status === "string") {
|
|
3801
|
+
return ["finished", "done", "completed", "end", "ended"].includes(status.toLowerCase());
|
|
3802
|
+
}
|
|
3803
|
+
if (typeof status === "number") {
|
|
3804
|
+
return [3, 4, 5].includes(status);
|
|
3805
|
+
}
|
|
3806
|
+
return false;
|
|
3807
|
+
}
|
|
3808
|
+
function collectRecords(value, output = [], seen = /* @__PURE__ */ new Set()) {
|
|
3809
|
+
if (!value || seen.has(value)) {
|
|
3810
|
+
return output;
|
|
3811
|
+
}
|
|
3812
|
+
seen.add(value);
|
|
3813
|
+
if (Array.isArray(value)) {
|
|
3814
|
+
value.forEach((item) => collectRecords(item, output, seen));
|
|
3815
|
+
return output;
|
|
3816
|
+
}
|
|
3817
|
+
if (!isRecord7(value)) {
|
|
3818
|
+
return output;
|
|
3819
|
+
}
|
|
3820
|
+
output.push(value);
|
|
3821
|
+
for (const child of Object.values(value)) {
|
|
3822
|
+
if (Array.isArray(child) || isRecord7(child)) {
|
|
3823
|
+
collectRecords(child, output, seen);
|
|
3824
|
+
}
|
|
3825
|
+
}
|
|
3826
|
+
return output;
|
|
3827
|
+
}
|
|
3828
|
+
function findFlowNode(project, step) {
|
|
3829
|
+
const flowStepId = stepFlowNodeId(step);
|
|
3830
|
+
if (!flowStepId) {
|
|
3831
|
+
return null;
|
|
3832
|
+
}
|
|
3833
|
+
const candidates = [
|
|
3834
|
+
project.flow,
|
|
3835
|
+
project.flow_data,
|
|
3836
|
+
project.flowData,
|
|
3837
|
+
project.flow_detail,
|
|
3838
|
+
project.flowDetail,
|
|
3839
|
+
project.current_flow,
|
|
3840
|
+
project.currentFlow,
|
|
3841
|
+
project.config
|
|
3842
|
+
];
|
|
3843
|
+
for (const candidate of candidates) {
|
|
3844
|
+
const match = collectRecords(candidate).find((item) => stringValue(item.id) === flowStepId);
|
|
3845
|
+
if (match) {
|
|
3846
|
+
return match;
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
return null;
|
|
3850
|
+
}
|
|
3851
|
+
function parseConfiguredActions(value, action, type) {
|
|
3852
|
+
if (!Array.isArray(value)) {
|
|
3853
|
+
return [];
|
|
3854
|
+
}
|
|
3855
|
+
return value.map((item) => {
|
|
3856
|
+
const raw = String(item ?? "");
|
|
3857
|
+
const [label, targetStep] = raw.split("|");
|
|
3858
|
+
return {
|
|
3859
|
+
action,
|
|
3860
|
+
type,
|
|
3861
|
+
label: label?.trim() || (action === "approve" ? "\u901A\u8FC7" : "\u62D2\u7EDD"),
|
|
3862
|
+
...targetStep?.trim() ? { target_step: targetStep.trim() } : {},
|
|
3863
|
+
requires_comment: action === "refuse",
|
|
3864
|
+
requires_attachment: false,
|
|
3865
|
+
requires_next_owner: false
|
|
3866
|
+
};
|
|
3867
|
+
});
|
|
3868
|
+
}
|
|
3869
|
+
function buildStepActions(flowNode) {
|
|
3870
|
+
const approveActions = parseConfiguredActions(flowNode?.approve_actions, "approve", "pass");
|
|
3871
|
+
const refuseActions = parseConfiguredActions(flowNode?.approve_fail_actions, "refuse", "refuse");
|
|
3872
|
+
const actions = [...approveActions, ...refuseActions];
|
|
3873
|
+
const hasApprove = actions.some((item) => item.action === "approve");
|
|
3874
|
+
const hasRefuse = actions.some((item) => item.action === "refuse");
|
|
3875
|
+
if (!hasApprove) {
|
|
3876
|
+
actions.unshift({
|
|
3877
|
+
action: "approve",
|
|
3878
|
+
type: "pass",
|
|
3879
|
+
label: "\u901A\u8FC7",
|
|
3880
|
+
requires_comment: false,
|
|
3881
|
+
requires_attachment: false,
|
|
3882
|
+
requires_next_owner: false
|
|
3883
|
+
});
|
|
3884
|
+
}
|
|
3885
|
+
if (!hasRefuse) {
|
|
3886
|
+
actions.push({
|
|
3887
|
+
action: "refuse",
|
|
3888
|
+
type: "refuse",
|
|
3889
|
+
label: "\u62D2\u7EDD",
|
|
3890
|
+
requires_comment: true,
|
|
3891
|
+
requires_attachment: false,
|
|
3892
|
+
requires_next_owner: false
|
|
3893
|
+
});
|
|
3894
|
+
}
|
|
3895
|
+
return actions.map((item) => ({
|
|
3896
|
+
...item,
|
|
3897
|
+
requires_attachment: Array.isArray(flowNode?.attachment_required) && flowNode.attachment_required.length > 0,
|
|
3898
|
+
requires_next_owner: Array.isArray(flowNode?.arrange_owner_steps) && flowNode.arrange_owner_steps.length > 0
|
|
3899
|
+
}));
|
|
3900
|
+
}
|
|
3901
|
+
function formListOfStep(step) {
|
|
3902
|
+
const values = [step.formList, step.forms, step.metaForm];
|
|
3903
|
+
return values.filter(hasMeaningfulValue);
|
|
3904
|
+
}
|
|
3905
|
+
function buildFormSummary(project, step) {
|
|
3906
|
+
const projectFormEmpty = !hasMeaningfulValue(project.metaForm ?? project.project_form ?? project.projectForm);
|
|
3907
|
+
const stepFormsEmpty = formListOfStep(step).length === 0;
|
|
3908
|
+
return {
|
|
3909
|
+
project_form_empty: projectFormEmpty,
|
|
3910
|
+
step_forms_empty: stepFormsEmpty,
|
|
3911
|
+
has_identity_evidence: !projectFormEmpty || !stepFormsEmpty
|
|
3912
|
+
};
|
|
3913
|
+
}
|
|
3914
|
+
function ownerIdsFromStep(step) {
|
|
3915
|
+
const owners = [
|
|
3916
|
+
step.owner_id,
|
|
3917
|
+
step.ownerId,
|
|
3918
|
+
step.user_id,
|
|
3919
|
+
step.userId,
|
|
3920
|
+
...Array.isArray(step.owners) ? step.owners : [],
|
|
3921
|
+
...Array.isArray(step.owner_list) ? step.owner_list : [],
|
|
3922
|
+
...Array.isArray(step.step_owners) ? step.step_owners : []
|
|
3923
|
+
];
|
|
3924
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3925
|
+
for (const owner of owners) {
|
|
3926
|
+
if (isRecord7(owner)) {
|
|
3927
|
+
const id = idValue(owner.owner_id ?? owner.user_id ?? owner.id);
|
|
3928
|
+
if (id) {
|
|
3929
|
+
ids.add(id);
|
|
3930
|
+
}
|
|
3931
|
+
} else {
|
|
3932
|
+
const id = idValue(owner);
|
|
3933
|
+
if (id) {
|
|
3934
|
+
ids.add(id);
|
|
3935
|
+
}
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
return [...ids];
|
|
3939
|
+
}
|
|
3940
|
+
function checkCurrentUserCanProcess(step, currentUser) {
|
|
3941
|
+
const ownerIds = ownerIdsFromStep(step);
|
|
3942
|
+
if (ownerIds.length === 0) {
|
|
3943
|
+
return {
|
|
3944
|
+
current_user_can_process: null,
|
|
3945
|
+
current_user_reason: "Step owner data is unavailable in step detail; verify my-step before mutating."
|
|
3946
|
+
};
|
|
3947
|
+
}
|
|
3948
|
+
const currentUserId = currentUser ? idValue(currentUser.id ?? currentUser.user_id ?? currentUser.owner_id) : void 0;
|
|
3949
|
+
if (!currentUserId) {
|
|
3950
|
+
return {
|
|
3951
|
+
current_user_can_process: false,
|
|
3952
|
+
current_user_reason: "Current user id is unavailable."
|
|
3953
|
+
};
|
|
3954
|
+
}
|
|
3955
|
+
return {
|
|
3956
|
+
current_user_can_process: ownerIds.includes(currentUserId),
|
|
3957
|
+
current_user_reason: ownerIds.includes(currentUserId) ? "Current user is listed as a step owner." : "Current user is not listed as a step owner."
|
|
3958
|
+
};
|
|
3959
|
+
}
|
|
3960
|
+
async function buildStepContext(profile, client, stepId, projectId) {
|
|
3961
|
+
const [project, step, currentUser] = await Promise.all([
|
|
3962
|
+
apiRequest(client, "GET", `/project/${projectId}`),
|
|
3963
|
+
apiRequest(client, "GET", `/step/${stepId}`),
|
|
3964
|
+
apiRequest(client, "GET", "/user/current").catch(() => null)
|
|
3965
|
+
]);
|
|
3966
|
+
const actualProjectId = projectIdOfStep(step);
|
|
3967
|
+
if (actualProjectId && actualProjectId !== projectId) {
|
|
3968
|
+
throw new Error(`Step ${stepId} belongs to project ${actualProjectId}, not project ${projectId}.`);
|
|
3969
|
+
}
|
|
3970
|
+
const flowNode = findFlowNode(project, step);
|
|
3971
|
+
const formSummary = buildFormSummary(project, step);
|
|
3972
|
+
const identityUnverified = !formSummary.has_identity_evidence;
|
|
3973
|
+
const userCheck = checkCurrentUserCanProcess(step, currentUser);
|
|
3974
|
+
const stepFinished = isStepFinished(step);
|
|
3975
|
+
const riskWarnings = [];
|
|
3976
|
+
if (identityUnverified) {
|
|
3977
|
+
riskWarnings.push("No project or step form evidence was returned; do not advance solely from ES or attachment text matches.");
|
|
3978
|
+
}
|
|
3979
|
+
if (stepFinished) {
|
|
3980
|
+
riskWarnings.push("Step appears to be finished.");
|
|
3981
|
+
}
|
|
3982
|
+
if (userCheck.current_user_can_process === false) {
|
|
3983
|
+
riskWarnings.push(userCheck.current_user_reason);
|
|
3984
|
+
}
|
|
3985
|
+
return {
|
|
3986
|
+
project_id: projectId,
|
|
3987
|
+
step_id: stepId,
|
|
3988
|
+
project,
|
|
3989
|
+
step,
|
|
3990
|
+
current_flow_node: flowNode,
|
|
3991
|
+
actions: buildStepActions(flowNode),
|
|
3992
|
+
url: buildBpmaxUrl(profile, "project-step", { projectId, stepId }).url,
|
|
3993
|
+
current_user: currentUser,
|
|
3994
|
+
...userCheck,
|
|
3995
|
+
step_finished: stepFinished,
|
|
3996
|
+
form_summary: formSummary,
|
|
3997
|
+
identity_unverified: identityUnverified,
|
|
3998
|
+
risk_warnings: riskWarnings
|
|
3999
|
+
};
|
|
4000
|
+
}
|
|
4001
|
+
async function loadSubmitData(data) {
|
|
4002
|
+
if (!data) {
|
|
4003
|
+
return {};
|
|
4004
|
+
}
|
|
4005
|
+
return parseJsonInput(data, "--data");
|
|
4006
|
+
}
|
|
3689
4007
|
function registerStepCommands(program2) {
|
|
3690
4008
|
const step = program2.command("step").description("Step commands");
|
|
3691
4009
|
step.command("get <id>").description("Get step detail").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (id, options) => {
|
|
@@ -3698,10 +4016,94 @@ function registerStepCommands(program2) {
|
|
|
3698
4016
|
);
|
|
3699
4017
|
printResult(options.format, result);
|
|
3700
4018
|
});
|
|
4019
|
+
step.command("context <id>").description("Get safe step processing context").requiredOption("--project-id <projectId>", "Project id").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (id, options) => {
|
|
4020
|
+
const config = await loadConfig();
|
|
4021
|
+
const profile = resolveProfile(config, options.profile);
|
|
4022
|
+
const client = createApiClient(profile);
|
|
4023
|
+
const result = await buildStepContext(profile, client, id, options.projectId);
|
|
4024
|
+
printResult(options.format, result);
|
|
4025
|
+
});
|
|
4026
|
+
step.command("actions <id>").description("List safe step actions").requiredOption("--project-id <projectId>", "Project id").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (id, options) => {
|
|
4027
|
+
const config = await loadConfig();
|
|
4028
|
+
const profile = resolveProfile(config, options.profile);
|
|
4029
|
+
const client = createApiClient(profile);
|
|
4030
|
+
const context = await buildStepContext(profile, client, id, options.projectId);
|
|
4031
|
+
printResult(options.format, {
|
|
4032
|
+
project_id: context.project_id,
|
|
4033
|
+
step_id: context.step_id,
|
|
4034
|
+
current_flow_node: context.current_flow_node,
|
|
4035
|
+
actions: context.actions,
|
|
4036
|
+
identity_unverified: context.identity_unverified,
|
|
4037
|
+
risk_warnings: context.risk_warnings
|
|
4038
|
+
});
|
|
4039
|
+
});
|
|
4040
|
+
step.command("submit <id>").description("Safely submit a step action").requiredOption("--project-id <projectId>", "Project id").requiredOption("--action <action>", "Step action, e.g. approve/refuse").option("--label <label>", "Action label").option("--target-step <targetStep>", "Target flow step id").option("--data <json>", "Additional submit payload JSON or @file").option("--comments <comments>", "Step comments").option("--urgency <urgency>", "Urgency value", "1").option("--confirm <confirmation>", "Actually submit the step action").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (id, options) => {
|
|
4041
|
+
const config = await loadConfig();
|
|
4042
|
+
const profile = resolveProfile(config, options.profile);
|
|
4043
|
+
const client = createApiClient(profile);
|
|
4044
|
+
const context = await buildStepContext(profile, client, id, options.projectId);
|
|
4045
|
+
const data = await loadSubmitData(options.data);
|
|
4046
|
+
const payload = {
|
|
4047
|
+
...data,
|
|
4048
|
+
project_id: Number(options.projectId),
|
|
4049
|
+
...options.targetStep ? { target_step: options.targetStep } : {},
|
|
4050
|
+
action: options.action,
|
|
4051
|
+
...options.label ? { action_label: options.label } : {},
|
|
4052
|
+
...options.comments ? { step_comments: options.comments } : {},
|
|
4053
|
+
urgency: Number(options.urgency)
|
|
4054
|
+
};
|
|
4055
|
+
const dryRun = !options.confirm;
|
|
4056
|
+
const request = {
|
|
4057
|
+
method: "PUT",
|
|
4058
|
+
path: `/step/${id}`,
|
|
4059
|
+
params: { action: options.action },
|
|
4060
|
+
data: payload
|
|
4061
|
+
};
|
|
4062
|
+
if (dryRun) {
|
|
4063
|
+
printResult(options.format, {
|
|
4064
|
+
ok: true,
|
|
4065
|
+
dry_run: true,
|
|
4066
|
+
request,
|
|
4067
|
+
context: {
|
|
4068
|
+
project_id: context.project_id,
|
|
4069
|
+
step_id: context.step_id,
|
|
4070
|
+
url: context.url,
|
|
4071
|
+
identity_unverified: context.identity_unverified,
|
|
4072
|
+
current_user_can_process: context.current_user_can_process,
|
|
4073
|
+
step_finished: context.step_finished,
|
|
4074
|
+
risk_warnings: context.risk_warnings
|
|
4075
|
+
},
|
|
4076
|
+
next_command_hint: "Re-run with --confirm after verifying project identity, target action, and payload."
|
|
4077
|
+
});
|
|
4078
|
+
return;
|
|
4079
|
+
}
|
|
4080
|
+
if (context.identity_unverified) {
|
|
4081
|
+
throw new Error("Refusing to submit: project identity is unverified because project and step form evidence is empty.");
|
|
4082
|
+
}
|
|
4083
|
+
if (context.step_finished) {
|
|
4084
|
+
throw new Error("Refusing to submit: step appears to be finished.");
|
|
4085
|
+
}
|
|
4086
|
+
if (context.current_user_can_process === false) {
|
|
4087
|
+
throw new Error(`Refusing to submit: ${context.current_user_reason}`);
|
|
4088
|
+
}
|
|
4089
|
+
const result = await apiRequest(client, "PUT", `/step/${id}`, {
|
|
4090
|
+
params: { action: options.action },
|
|
4091
|
+
data: payload
|
|
4092
|
+
});
|
|
4093
|
+
printResult(options.format, {
|
|
4094
|
+
ok: true,
|
|
4095
|
+
submitted: true,
|
|
4096
|
+
request,
|
|
4097
|
+
result,
|
|
4098
|
+
project_id: options.projectId,
|
|
4099
|
+
step_id: id,
|
|
4100
|
+
url: context.url
|
|
4101
|
+
});
|
|
4102
|
+
});
|
|
3701
4103
|
}
|
|
3702
4104
|
|
|
3703
4105
|
// src/core/update.ts
|
|
3704
|
-
import { access as access2, mkdir as mkdir5, readFile as
|
|
4106
|
+
import { access as access2, mkdir as mkdir5, readFile as readFile8, realpath, writeFile as writeFile5 } from "fs/promises";
|
|
3705
4107
|
import path5 from "path";
|
|
3706
4108
|
var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/";
|
|
3707
4109
|
var UPDATE_STATE_FILE = "update-state.json";
|
|
@@ -3818,7 +4220,7 @@ function updateStatePath(configDir = getConfigDir()) {
|
|
|
3818
4220
|
}
|
|
3819
4221
|
async function readUpdateState(configDir) {
|
|
3820
4222
|
try {
|
|
3821
|
-
const raw = await
|
|
4223
|
+
const raw = await readFile8(updateStatePath(configDir), "utf8");
|
|
3822
4224
|
const parsed = JSON.parse(raw);
|
|
3823
4225
|
if (typeof parsed.latest_version !== "string" || typeof parsed.checked_at !== "number") {
|
|
3824
4226
|
return null;
|