bpmax-cli 0.1.36 → 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 +412 -47
- 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/README.md
CHANGED
|
@@ -128,6 +128,28 @@ bpmax-cli project get 13097 --format json
|
|
|
128
128
|
bpmax-cli step get 15690 --format json
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
+
Before advancing or rejecting a step, inspect the safe context and available actions:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
bpmax-cli step context 15690 --project-id 13097 --format json
|
|
135
|
+
bpmax-cli step actions 15690 --project-id 13097 --format json
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`step context` reports the project/step URL, current user ownership, parsed actions, form evidence, and `identity_unverified`. If project and step form values are empty, do not advance from an ES keyword or attachment-text match alone.
|
|
139
|
+
|
|
140
|
+
Submit step actions through a dry-run first:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
bpmax-cli step submit 15690 \
|
|
144
|
+
--project-id 13097 \
|
|
145
|
+
--action approve \
|
|
146
|
+
--label "通过" \
|
|
147
|
+
--comments "确认推进" \
|
|
148
|
+
--format json
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
The command only calls `PUT /api/step/:id?action=<action>` when `--confirm <text>` is present and safety checks pass.
|
|
152
|
+
|
|
131
153
|
Filter pending steps at the API query level instead of pulling all pages locally:
|
|
132
154
|
|
|
133
155
|
```bash
|
|
@@ -267,6 +289,8 @@ bpmax-cli --config-dir <config_dir> bbs ensure <skill-key> --agent <agent> --pro
|
|
|
267
289
|
|
|
268
290
|
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`.
|
|
269
291
|
|
|
292
|
+
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.
|
|
293
|
+
|
|
270
294
|
If `aily-skillhub` is available in `PATH`, the installer also runs:
|
|
271
295
|
|
|
272
296
|
```bash
|
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)
|
|
@@ -1911,7 +1938,7 @@ function setupSummary(input) {
|
|
|
1911
1938
|
}
|
|
1912
1939
|
|
|
1913
1940
|
// src/core/skills.ts
|
|
1914
|
-
import { mkdir as mkdir3, readFile as
|
|
1941
|
+
import { mkdir as mkdir3, readFile as readFile6, writeFile as writeFile3 } from "fs/promises";
|
|
1915
1942
|
import path3 from "path";
|
|
1916
1943
|
import { fileURLToPath } from "url";
|
|
1917
1944
|
var SKILLS_STAMP_FILE = "skills.stamp";
|
|
@@ -1924,7 +1951,7 @@ function stampPath(configDir = getConfigDir()) {
|
|
|
1924
1951
|
}
|
|
1925
1952
|
async function readSkillsStamp(configDir = getConfigDir()) {
|
|
1926
1953
|
try {
|
|
1927
|
-
return (await
|
|
1954
|
+
return (await readFile6(stampPath(configDir), "utf8")).trim();
|
|
1928
1955
|
} catch {
|
|
1929
1956
|
return "";
|
|
1930
1957
|
}
|
|
@@ -2670,7 +2697,7 @@ async function buildProjectFormPayload(client, flowDetail, form, knownTemplate)
|
|
|
2670
2697
|
}
|
|
2671
2698
|
|
|
2672
2699
|
// src/commands/project.ts
|
|
2673
|
-
function
|
|
2700
|
+
function parseJson(input) {
|
|
2674
2701
|
if (!input) {
|
|
2675
2702
|
return {};
|
|
2676
2703
|
}
|
|
@@ -3063,7 +3090,7 @@ function registerProjectCommands(program2) {
|
|
|
3063
3090
|
page: Number(options.page),
|
|
3064
3091
|
page_size: Number(options.pageSize)
|
|
3065
3092
|
},
|
|
3066
|
-
data:
|
|
3093
|
+
data: parseJson(options.body)
|
|
3067
3094
|
}
|
|
3068
3095
|
);
|
|
3069
3096
|
printResult(options.format, result);
|
|
@@ -3128,11 +3155,11 @@ function registerProjectCommands(program2) {
|
|
|
3128
3155
|
const profile = resolveProfile(config, options.profile);
|
|
3129
3156
|
const client = createApiClient(profile);
|
|
3130
3157
|
const useInteractive = !options.body && options.interactive !== false;
|
|
3131
|
-
let payload =
|
|
3158
|
+
let payload = parseJson(options.body);
|
|
3132
3159
|
if (!options.body) {
|
|
3133
3160
|
const flow = await resolveFlowIdentifiers(client, options, { loadDetail: useInteractive });
|
|
3134
3161
|
const { flowDetail, ...flowIdentifiers } = flow;
|
|
3135
|
-
const extra =
|
|
3162
|
+
const extra = parseJson(options.json);
|
|
3136
3163
|
const form = typeof extra.form === "object" && extra.form !== null && !Array.isArray(extra.form) ? extra.form : {};
|
|
3137
3164
|
let name = options.name;
|
|
3138
3165
|
let projectFormTemplate;
|
|
@@ -3247,7 +3274,7 @@ import { spawn as spawn2 } from "child_process";
|
|
|
3247
3274
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3248
3275
|
|
|
3249
3276
|
// src/core/recipes.ts
|
|
3250
|
-
import { access, mkdir as mkdir4, readdir, readFile as
|
|
3277
|
+
import { access, mkdir as mkdir4, readdir, readFile as readFile7, writeFile as writeFile4 } from "fs/promises";
|
|
3251
3278
|
import path4 from "path";
|
|
3252
3279
|
var RECIPE_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
|
|
3253
3280
|
var TEMPLATE_PATTERN = /{{\s*([a-zA-Z0-9_.-]+)\s*}}/g;
|
|
@@ -3329,7 +3356,7 @@ function parseRecipeDefinition(input) {
|
|
|
3329
3356
|
};
|
|
3330
3357
|
}
|
|
3331
3358
|
async function loadRecipe(recipeDir) {
|
|
3332
|
-
const raw = await
|
|
3359
|
+
const raw = await readFile7(path4.join(recipeDir, "recipe.json"), "utf8");
|
|
3333
3360
|
return parseRecipeDefinition(JSON.parse(raw));
|
|
3334
3361
|
}
|
|
3335
3362
|
async function listRecipes(recipesDir) {
|
|
@@ -3428,7 +3455,7 @@ async function renderArgv(options) {
|
|
|
3428
3455
|
const rendered = [];
|
|
3429
3456
|
for (const token of options.recipe.command.argv) {
|
|
3430
3457
|
if (token.startsWith("@")) {
|
|
3431
|
-
const raw = await
|
|
3458
|
+
const raw = await readFile7(resolveRecipeFile(options.recipeDir, token), "utf8");
|
|
3432
3459
|
rendered.push(renderTemplate(raw, options.variables));
|
|
3433
3460
|
} else {
|
|
3434
3461
|
rendered.push(renderTemplate(token, options.variables));
|
|
@@ -3618,6 +3645,9 @@ var schemaEntries = [
|
|
|
3618
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" },
|
|
3619
3646
|
{ name: "project.create", description: "Create a project with local form schema validation when form payload is provided.", method: "POST", path: "/api/project" },
|
|
3620
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" },
|
|
3621
3651
|
{ name: "bbs.list", description: "List BPMAX Business Skills.", method: "GET", path: "/api/business_skill" },
|
|
3622
3652
|
{ name: "bbs.create", description: "Create a BPMAX Business Skill from a standard skill zip.", method: "POST", path: "/api/business_skill" },
|
|
3623
3653
|
{ name: "bbs.lint", description: "Lint a BPMAX Business Skill package before publish." },
|
|
@@ -3723,6 +3753,257 @@ function registerSetupCommand(program2, deps = {}) {
|
|
|
3723
3753
|
}
|
|
3724
3754
|
|
|
3725
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
|
+
}
|
|
3726
4007
|
function registerStepCommands(program2) {
|
|
3727
4008
|
const step = program2.command("step").description("Step commands");
|
|
3728
4009
|
step.command("get <id>").description("Get step detail").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (id, options) => {
|
|
@@ -3735,10 +4016,94 @@ function registerStepCommands(program2) {
|
|
|
3735
4016
|
);
|
|
3736
4017
|
printResult(options.format, result);
|
|
3737
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
|
+
});
|
|
3738
4103
|
}
|
|
3739
4104
|
|
|
3740
4105
|
// src/core/update.ts
|
|
3741
|
-
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";
|
|
3742
4107
|
import path5 from "path";
|
|
3743
4108
|
var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/";
|
|
3744
4109
|
var UPDATE_STATE_FILE = "update-state.json";
|
|
@@ -3855,7 +4220,7 @@ function updateStatePath(configDir = getConfigDir()) {
|
|
|
3855
4220
|
}
|
|
3856
4221
|
async function readUpdateState(configDir) {
|
|
3857
4222
|
try {
|
|
3858
|
-
const raw = await
|
|
4223
|
+
const raw = await readFile8(updateStatePath(configDir), "utf8");
|
|
3859
4224
|
const parsed = JSON.parse(raw);
|
|
3860
4225
|
if (typeof parsed.latest_version !== "string" || typeof parsed.checked_at !== "number") {
|
|
3861
4226
|
return null;
|