bpmax-cli 0.1.26 → 0.1.28
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 +23 -0
- package/dist/bin.js +1189 -340
- package/dist/bin.js.map +1 -1
- package/package.json +2 -1
- package/skills/bpmax-business-skill/SKILL.md +64 -0
- package/skills/bpmax-project/SKILL.md +4 -1
package/dist/bin.js
CHANGED
|
@@ -141,14 +141,14 @@ async function upsertProfile(name, nextProfile) {
|
|
|
141
141
|
|
|
142
142
|
// src/core/http.ts
|
|
143
143
|
import axios, { AxiosHeaders } from "axios";
|
|
144
|
-
var ensureApiPath = (
|
|
145
|
-
if (!
|
|
146
|
-
|
|
144
|
+
var ensureApiPath = (path6) => {
|
|
145
|
+
if (!path6.startsWith("/")) {
|
|
146
|
+
path6 = `/${path6}`;
|
|
147
147
|
}
|
|
148
|
-
if (
|
|
149
|
-
return
|
|
148
|
+
if (path6.startsWith("/api/")) {
|
|
149
|
+
return path6;
|
|
150
150
|
}
|
|
151
|
-
return `/api${
|
|
151
|
+
return `/api${path6}`;
|
|
152
152
|
};
|
|
153
153
|
function createApiClient(profile) {
|
|
154
154
|
const instance = axios.create({
|
|
@@ -170,10 +170,10 @@ function createApiClient(profile) {
|
|
|
170
170
|
});
|
|
171
171
|
return instance;
|
|
172
172
|
}
|
|
173
|
-
async function apiRequest(client, method,
|
|
173
|
+
async function apiRequest(client, method, path6, options = {}) {
|
|
174
174
|
const response = await client.request({
|
|
175
175
|
method,
|
|
176
|
-
url: ensureApiPath(
|
|
176
|
+
url: ensureApiPath(path6),
|
|
177
177
|
params: options.params,
|
|
178
178
|
data: options.data
|
|
179
179
|
});
|
|
@@ -259,10 +259,10 @@ function parseJson(input) {
|
|
|
259
259
|
return JSON.parse(input);
|
|
260
260
|
}
|
|
261
261
|
function registerApiCommands(program2) {
|
|
262
|
-
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,
|
|
262
|
+
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) => {
|
|
263
263
|
const config = await loadConfig();
|
|
264
264
|
const profile = resolveProfile(config, options.profile);
|
|
265
|
-
const result = await apiRequest(createApiClient(profile), method,
|
|
265
|
+
const result = await apiRequest(createApiClient(profile), method, path6, {
|
|
266
266
|
params: parseJson(options.params),
|
|
267
267
|
data: parseJson(options.data)
|
|
268
268
|
});
|
|
@@ -363,18 +363,18 @@ async function runBrowserLogin(options) {
|
|
|
363
363
|
}, timeoutMs);
|
|
364
364
|
});
|
|
365
365
|
}
|
|
366
|
-
function apiPath(
|
|
367
|
-
if (
|
|
368
|
-
return
|
|
366
|
+
function apiPath(path6) {
|
|
367
|
+
if (path6.startsWith("/api/")) {
|
|
368
|
+
return path6;
|
|
369
369
|
}
|
|
370
|
-
return `/api${
|
|
370
|
+
return `/api${path6.startsWith("/") ? path6 : `/${path6}`}`;
|
|
371
371
|
}
|
|
372
372
|
function createDeviceRequest(origin) {
|
|
373
373
|
const client = axios2.create({ baseURL: origin, withCredentials: false });
|
|
374
|
-
return async (method,
|
|
374
|
+
return async (method, path6, options) => {
|
|
375
375
|
const response = await client.request({
|
|
376
376
|
method,
|
|
377
|
-
url: apiPath(
|
|
377
|
+
url: apiPath(path6),
|
|
378
378
|
data: options.data
|
|
379
379
|
});
|
|
380
380
|
const body = response.data;
|
|
@@ -637,6 +637,947 @@ function registerAuthCommands(program2, deps = {}) {
|
|
|
637
637
|
});
|
|
638
638
|
}
|
|
639
639
|
|
|
640
|
+
// src/commands/bbs.ts
|
|
641
|
+
import { basename } from "path";
|
|
642
|
+
import { readFile as readFile4 } from "fs/promises";
|
|
643
|
+
|
|
644
|
+
// src/core/json-input.ts
|
|
645
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
646
|
+
async function parseJsonInput(input, label = "JSON input") {
|
|
647
|
+
const source = input.startsWith("@") ? input.slice(1) : void 0;
|
|
648
|
+
if (source === "") {
|
|
649
|
+
throw new Error(`${label} file path is empty.`);
|
|
650
|
+
}
|
|
651
|
+
const raw = source ? await readFile2(source, "utf8") : input;
|
|
652
|
+
let parsed;
|
|
653
|
+
try {
|
|
654
|
+
parsed = JSON.parse(raw);
|
|
655
|
+
} catch (error) {
|
|
656
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
657
|
+
throw new Error(`${label} is not valid JSON: ${detail}`);
|
|
658
|
+
}
|
|
659
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
660
|
+
throw new Error(`${label} must be a JSON object.`);
|
|
661
|
+
}
|
|
662
|
+
return parsed;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// package.json
|
|
666
|
+
var package_default = {
|
|
667
|
+
name: "bpmax-cli",
|
|
668
|
+
version: "0.1.28",
|
|
669
|
+
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
670
|
+
type: "module",
|
|
671
|
+
bin: {
|
|
672
|
+
"bpmax-cli": "dist/bin.js"
|
|
673
|
+
},
|
|
674
|
+
files: [
|
|
675
|
+
"dist",
|
|
676
|
+
"scripts/install-skills.mjs",
|
|
677
|
+
"skills",
|
|
678
|
+
"README.md"
|
|
679
|
+
],
|
|
680
|
+
scripts: {
|
|
681
|
+
postinstall: "node scripts/install-skills.mjs",
|
|
682
|
+
build: "tsup",
|
|
683
|
+
dev: "tsx src/bin.ts",
|
|
684
|
+
"install:skills": "node scripts/install-skills.mjs",
|
|
685
|
+
test: "vitest run",
|
|
686
|
+
typecheck: "tsc --noEmit"
|
|
687
|
+
},
|
|
688
|
+
engines: {
|
|
689
|
+
node: ">=18"
|
|
690
|
+
},
|
|
691
|
+
dependencies: {
|
|
692
|
+
"@clack/prompts": "^1.2.0",
|
|
693
|
+
axios: "^1.9.0",
|
|
694
|
+
commander: "^14.0.0",
|
|
695
|
+
jszip: "^3.10.1",
|
|
696
|
+
open: "^10.1.2"
|
|
697
|
+
},
|
|
698
|
+
devDependencies: {
|
|
699
|
+
"@types/node": "^22.15.17",
|
|
700
|
+
tsup: "^8.5.0",
|
|
701
|
+
tsx: "^4.19.4",
|
|
702
|
+
typescript: "^5.8.3",
|
|
703
|
+
vitest: "^3.1.3"
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
// src/core/build.ts
|
|
708
|
+
var CLI_NAME = "bpmax-cli";
|
|
709
|
+
var VERSION = package_default.version;
|
|
710
|
+
var NPM_PACKAGE = "bpmax-cli";
|
|
711
|
+
|
|
712
|
+
// src/core/urls.ts
|
|
713
|
+
function stripSlashes(value) {
|
|
714
|
+
return value.trim().replace(/^\/+|\/+$/g, "");
|
|
715
|
+
}
|
|
716
|
+
function isRecord2(value) {
|
|
717
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
718
|
+
}
|
|
719
|
+
function normalizeWorkspaceForUrl(workspace) {
|
|
720
|
+
const nextWorkspace = stripSlashes(workspace);
|
|
721
|
+
if (!nextWorkspace) {
|
|
722
|
+
throw new Error("Workspace is required to build a BPMAX URL.");
|
|
723
|
+
}
|
|
724
|
+
if (nextWorkspace === "default" || nextWorkspace.startsWith("w:")) {
|
|
725
|
+
return nextWorkspace;
|
|
726
|
+
}
|
|
727
|
+
return `w:${nextWorkspace}`;
|
|
728
|
+
}
|
|
729
|
+
function normalizeOrigin2(origin) {
|
|
730
|
+
const nextOrigin = origin.trim().replace(/\/+$/, "");
|
|
731
|
+
if (!nextOrigin) {
|
|
732
|
+
throw new Error("Origin is required to build a BPMAX URL.");
|
|
733
|
+
}
|
|
734
|
+
return nextOrigin;
|
|
735
|
+
}
|
|
736
|
+
function requireNumericId(value, name) {
|
|
737
|
+
const nextValue = String(value || "").trim();
|
|
738
|
+
if (!/^\d+$/.test(nextValue)) {
|
|
739
|
+
throw new Error(`${name} must be a non-empty numeric string.`);
|
|
740
|
+
}
|
|
741
|
+
return nextValue;
|
|
742
|
+
}
|
|
743
|
+
function withQuery(path6, query) {
|
|
744
|
+
const params = new URLSearchParams();
|
|
745
|
+
for (const [key, value] of Object.entries(query)) {
|
|
746
|
+
if (value !== void 0) {
|
|
747
|
+
params.set(key, value);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
return `${path6}?${params.toString()}`;
|
|
751
|
+
}
|
|
752
|
+
function buildBpmaxUrl(profile, kind, params = {}) {
|
|
753
|
+
const origin = normalizeOrigin2(profile.config.origin);
|
|
754
|
+
const workspace = normalizeWorkspaceForUrl(params.workspace || profile.config.workspace);
|
|
755
|
+
const basePath = `/${workspace}`;
|
|
756
|
+
let path6 = basePath;
|
|
757
|
+
const result = {
|
|
758
|
+
kind,
|
|
759
|
+
profile: profile.name,
|
|
760
|
+
origin,
|
|
761
|
+
workspace
|
|
762
|
+
};
|
|
763
|
+
if (kind === "project-list") {
|
|
764
|
+
path6 = `${basePath}/project`;
|
|
765
|
+
} else if (kind === "project-detail") {
|
|
766
|
+
const projectId = requireNumericId(params.projectId, "projectId");
|
|
767
|
+
path6 = `${basePath}/project_detail/0/${projectId}`;
|
|
768
|
+
result.project_id = projectId;
|
|
769
|
+
} else if (kind === "project-step") {
|
|
770
|
+
const projectId = requireNumericId(params.projectId, "projectId");
|
|
771
|
+
const stepId = requireNumericId(params.stepId, "stepId");
|
|
772
|
+
path6 = withQuery(`${basePath}/projectContinue`, {
|
|
773
|
+
id: projectId,
|
|
774
|
+
step_id: stepId
|
|
775
|
+
});
|
|
776
|
+
result.project_id = projectId;
|
|
777
|
+
result.step_id = stepId;
|
|
778
|
+
} else if (kind === "project-create") {
|
|
779
|
+
const flowType = params.flowType || "default";
|
|
780
|
+
const flowKey = params.flowKey || "";
|
|
781
|
+
const initValue = params.initValue ? JSON.stringify(params.initValue) : void 0;
|
|
782
|
+
const query = {
|
|
783
|
+
flow_type: flowType,
|
|
784
|
+
flow_key: flowKey,
|
|
785
|
+
...flowKey ? { key: flowKey } : {},
|
|
786
|
+
init_value: initValue
|
|
787
|
+
};
|
|
788
|
+
path6 = withQuery(`${basePath}/project/create`, query);
|
|
789
|
+
result.flow_type = flowType;
|
|
790
|
+
result.flow_key = flowKey;
|
|
791
|
+
result.mobile_path = withQuery("/pages/projectCreate/projectCreate", query);
|
|
792
|
+
}
|
|
793
|
+
const url = `${origin}${path6}`;
|
|
794
|
+
return {
|
|
795
|
+
...result,
|
|
796
|
+
path: path6,
|
|
797
|
+
url,
|
|
798
|
+
...kind === "project-create" ? { pc_url: url } : {}
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
function extractProjectId(value) {
|
|
802
|
+
if (!isRecord2(value)) {
|
|
803
|
+
return void 0;
|
|
804
|
+
}
|
|
805
|
+
const candidates = [value.id, value.project_id, value.projectId];
|
|
806
|
+
const candidate = candidates.find((item) => item !== void 0 && item !== null);
|
|
807
|
+
if (candidate === void 0) {
|
|
808
|
+
return void 0;
|
|
809
|
+
}
|
|
810
|
+
const projectId = String(candidate).trim();
|
|
811
|
+
return /^\d+$/.test(projectId) ? projectId : void 0;
|
|
812
|
+
}
|
|
813
|
+
function attachProjectDetailUrl(profile, value) {
|
|
814
|
+
if (!isRecord2(value) || typeof value.url === "string") {
|
|
815
|
+
return value;
|
|
816
|
+
}
|
|
817
|
+
const projectId = extractProjectId(value);
|
|
818
|
+
if (!projectId) {
|
|
819
|
+
return value;
|
|
820
|
+
}
|
|
821
|
+
return {
|
|
822
|
+
...value,
|
|
823
|
+
url: buildBpmaxUrl(profile, "project-detail", { projectId }).url
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// src/core/business-skills.ts
|
|
828
|
+
import { cp, mkdir as mkdir2, readFile as readFile3, rm, stat, writeFile as writeFile2 } from "fs/promises";
|
|
829
|
+
import { createHash } from "crypto";
|
|
830
|
+
import { homedir as homedir2, tmpdir } from "os";
|
|
831
|
+
import path2 from "path";
|
|
832
|
+
import { setTimeout as delay } from "timers/promises";
|
|
833
|
+
import axios3 from "axios";
|
|
834
|
+
import JSZip from "jszip";
|
|
835
|
+
|
|
836
|
+
// src/core/process.ts
|
|
837
|
+
import { spawn } from "child_process";
|
|
838
|
+
var runCommand = (command, args, options = {}) => new Promise((resolve) => {
|
|
839
|
+
const child = spawn(command, args, {
|
|
840
|
+
cwd: options.cwd,
|
|
841
|
+
env: options.env,
|
|
842
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
843
|
+
});
|
|
844
|
+
let stdout = "";
|
|
845
|
+
let stderr = "";
|
|
846
|
+
let settled = false;
|
|
847
|
+
const timer = options.timeoutMs && options.timeoutMs > 0 ? setTimeout(() => {
|
|
848
|
+
if (settled) {
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
settled = true;
|
|
852
|
+
child.kill("SIGTERM");
|
|
853
|
+
resolve({
|
|
854
|
+
stdout,
|
|
855
|
+
stderr: `${stderr}${stderr ? "\n" : ""}Timed out after ${options.timeoutMs}ms`,
|
|
856
|
+
exitCode: 124
|
|
857
|
+
});
|
|
858
|
+
}, options.timeoutMs) : void 0;
|
|
859
|
+
child.stdout?.on("data", (chunk) => {
|
|
860
|
+
stdout += String(chunk);
|
|
861
|
+
});
|
|
862
|
+
child.stderr?.on("data", (chunk) => {
|
|
863
|
+
stderr += String(chunk);
|
|
864
|
+
});
|
|
865
|
+
child.on("error", (error) => {
|
|
866
|
+
if (settled) {
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
settled = true;
|
|
870
|
+
if (timer) {
|
|
871
|
+
clearTimeout(timer);
|
|
872
|
+
}
|
|
873
|
+
resolve({ stdout, stderr: `${stderr}${stderr ? "\n" : ""}${error.message}`, exitCode: 1 });
|
|
874
|
+
});
|
|
875
|
+
child.on("close", (code) => {
|
|
876
|
+
if (settled) {
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
settled = true;
|
|
880
|
+
if (timer) {
|
|
881
|
+
clearTimeout(timer);
|
|
882
|
+
}
|
|
883
|
+
resolve({ stdout, stderr, exitCode: code ?? 1 });
|
|
884
|
+
});
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
// src/core/business-skills.ts
|
|
888
|
+
var directoryTargets = {
|
|
889
|
+
codex: path2.join(homedir2(), ".codex", "skills"),
|
|
890
|
+
claude: path2.join(homedir2(), ".claude", "skills"),
|
|
891
|
+
"cc-switch": path2.join(homedir2(), ".cc-switch", "skills"),
|
|
892
|
+
agents: path2.join(homedir2(), ".agents", "skills"),
|
|
893
|
+
gemini: path2.join(homedir2(), ".gemini", "skills"),
|
|
894
|
+
generic: path2.join(homedir2(), ".agents", "skills")
|
|
895
|
+
};
|
|
896
|
+
var semverPattern = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
|
|
897
|
+
var knownBpmCommands = {
|
|
898
|
+
api: null,
|
|
899
|
+
auth: /* @__PURE__ */ new Set(["login", "status", "logout", "device"]),
|
|
900
|
+
bbs: /* @__PURE__ */ new Set(["list", "show", "create", "upgrade", "sync", "ensure", "install", "update", "uninstall", "lint", "gate"]),
|
|
901
|
+
config: null,
|
|
902
|
+
es: /* @__PURE__ */ new Set(["project-search"]),
|
|
903
|
+
flow: /* @__PURE__ */ new Set(["list", "options", "get"]),
|
|
904
|
+
init: null,
|
|
905
|
+
project: /* @__PURE__ */ new Set(["list", "get", "my-step", "approval-context", "create"]),
|
|
906
|
+
recipe: /* @__PURE__ */ new Set(["list", "show", "run", "scaffold"]),
|
|
907
|
+
schema: /* @__PURE__ */ new Set(["list", "show"]),
|
|
908
|
+
setup: null,
|
|
909
|
+
step: /* @__PURE__ */ new Set(["get"]),
|
|
910
|
+
update: null,
|
|
911
|
+
url: /* @__PURE__ */ new Set(["workspace", "project-create", "project-list", "project-detail", "project-step"]),
|
|
912
|
+
user: /* @__PURE__ */ new Set(["current"])
|
|
913
|
+
};
|
|
914
|
+
function issue(severity, code, message) {
|
|
915
|
+
return { severity, code, message };
|
|
916
|
+
}
|
|
917
|
+
function parseFrontmatter(markdown) {
|
|
918
|
+
const match = markdown.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
919
|
+
if (!match) {
|
|
920
|
+
return {};
|
|
921
|
+
}
|
|
922
|
+
const result = {};
|
|
923
|
+
match[1].split(/\r?\n/).forEach((line) => {
|
|
924
|
+
const item = line.match(/^([A-Za-z0-9_.-]+):\s*(.*)$/);
|
|
925
|
+
if (!item) {
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
result[item[1]] = item[2].trim().replace(/^['"]|['"]$/g, "");
|
|
929
|
+
});
|
|
930
|
+
return result;
|
|
931
|
+
}
|
|
932
|
+
function normalizeBusinessSkillKey(input) {
|
|
933
|
+
return input.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
934
|
+
}
|
|
935
|
+
function parseBbsJson(raw) {
|
|
936
|
+
const parsed = JSON.parse(raw);
|
|
937
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
938
|
+
throw new Error("bbs.json must be a JSON object.");
|
|
939
|
+
}
|
|
940
|
+
return parsed;
|
|
941
|
+
}
|
|
942
|
+
async function readBbsJson(skillDir) {
|
|
943
|
+
try {
|
|
944
|
+
return parseBbsJson(await readFile3(path2.join(skillDir, "bbs.json"), "utf8"));
|
|
945
|
+
} catch (error) {
|
|
946
|
+
if (error.code === "ENOENT") {
|
|
947
|
+
return void 0;
|
|
948
|
+
}
|
|
949
|
+
throw error;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
function compareSemver(a, b) {
|
|
953
|
+
const left = a.split(/[+-]/)[0].split(".").map((part) => Number(part));
|
|
954
|
+
const right = b.split(/[+-]/)[0].split(".").map((part) => Number(part));
|
|
955
|
+
for (let index = 0; index < 3; index += 1) {
|
|
956
|
+
const diff = (left[index] || 0) - (right[index] || 0);
|
|
957
|
+
if (diff !== 0) {
|
|
958
|
+
return diff;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
return a.localeCompare(b);
|
|
962
|
+
}
|
|
963
|
+
function extractBpmaxCommands(markdown) {
|
|
964
|
+
const commands = [];
|
|
965
|
+
const regex = /bpmax-cli\s+([^\n`]+)/g;
|
|
966
|
+
let match;
|
|
967
|
+
while (match = regex.exec(markdown)) {
|
|
968
|
+
commands.push(`bpmax-cli ${match[1].trim()}`);
|
|
969
|
+
}
|
|
970
|
+
return commands;
|
|
971
|
+
}
|
|
972
|
+
function commandPrefix(command) {
|
|
973
|
+
return command.replace(/^bpmax-cli\s+/, "").split(/\s+/).filter(Boolean).slice(0, 2).join(" ");
|
|
974
|
+
}
|
|
975
|
+
function commandExists(command) {
|
|
976
|
+
const parts = command.replace(/^bpmax-cli\s+/, "").split(/\s+/).filter(Boolean);
|
|
977
|
+
const group = parts[0];
|
|
978
|
+
if (!group || !Object.prototype.hasOwnProperty.call(knownBpmCommands, group)) {
|
|
979
|
+
return false;
|
|
980
|
+
}
|
|
981
|
+
const subcommands = knownBpmCommands[group];
|
|
982
|
+
if (!subcommands) {
|
|
983
|
+
return true;
|
|
984
|
+
}
|
|
985
|
+
return Boolean(parts[1] && subcommands.has(parts[1]));
|
|
986
|
+
}
|
|
987
|
+
function isApprovalSkill(markdown, manifest) {
|
|
988
|
+
const text4 = `${manifest.name || ""}
|
|
989
|
+
${manifest.description || ""}
|
|
990
|
+
${markdown}`.toLowerCase();
|
|
991
|
+
return /审批|同意|拒绝|approve|reject|approval/.test(text4);
|
|
992
|
+
}
|
|
993
|
+
function hasAny(text4, patterns) {
|
|
994
|
+
return patterns.some((pattern) => pattern.test(text4));
|
|
995
|
+
}
|
|
996
|
+
function truncateOutput(value) {
|
|
997
|
+
return value.length > 4e3 ? `${value.slice(0, 4e3)}...<truncated>` : value;
|
|
998
|
+
}
|
|
999
|
+
async function runShellCommand(command, cwd) {
|
|
1000
|
+
const shell = process.platform === "win32" ? "cmd" : "sh";
|
|
1001
|
+
const args = process.platform === "win32" ? ["/c", command] : ["-c", command];
|
|
1002
|
+
return runCommand(shell, args, { cwd, timeoutMs: 6e4 });
|
|
1003
|
+
}
|
|
1004
|
+
function completeReport(report) {
|
|
1005
|
+
const errors = report.issues.filter((item) => item.severity === "error");
|
|
1006
|
+
const warnings = report.issues.filter((item) => item.severity === "warning");
|
|
1007
|
+
return {
|
|
1008
|
+
ok: errors.length === 0,
|
|
1009
|
+
errors,
|
|
1010
|
+
warnings,
|
|
1011
|
+
manifest: report.manifest,
|
|
1012
|
+
checks: report.checks,
|
|
1013
|
+
skill_dir: report.skill_dir
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
async function exists(targetPath) {
|
|
1017
|
+
try {
|
|
1018
|
+
await stat(targetPath);
|
|
1019
|
+
return true;
|
|
1020
|
+
} catch {
|
|
1021
|
+
return false;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
function businessSkillStatePath(profileName, agent) {
|
|
1025
|
+
return path2.join(homedir2(), ".bpmax", "business-skills", profileName, agent, "state.json");
|
|
1026
|
+
}
|
|
1027
|
+
async function readBusinessSkillState(profileName, agent) {
|
|
1028
|
+
try {
|
|
1029
|
+
return JSON.parse(await readFile3(businessSkillStatePath(profileName, agent), "utf8"));
|
|
1030
|
+
} catch {
|
|
1031
|
+
return { skills: {} };
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
async function writeBusinessSkillState(profileName, agent, state) {
|
|
1035
|
+
const target = businessSkillStatePath(profileName, agent);
|
|
1036
|
+
await mkdir2(path2.dirname(target), { recursive: true });
|
|
1037
|
+
await writeFile2(target, JSON.stringify(state, null, 2), "utf8");
|
|
1038
|
+
}
|
|
1039
|
+
async function acquireStateLock(profileName, agent) {
|
|
1040
|
+
const target = businessSkillStatePath(profileName, agent);
|
|
1041
|
+
const lockPath = `${target}.lock`;
|
|
1042
|
+
await mkdir2(path2.dirname(target), { recursive: true });
|
|
1043
|
+
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
1044
|
+
try {
|
|
1045
|
+
await mkdir2(lockPath);
|
|
1046
|
+
return lockPath;
|
|
1047
|
+
} catch (error) {
|
|
1048
|
+
const code = error.code;
|
|
1049
|
+
if (code !== "EEXIST") {
|
|
1050
|
+
throw error;
|
|
1051
|
+
}
|
|
1052
|
+
await delay(50);
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
throw new Error(`Timed out waiting for BBS state lock: ${lockPath}`);
|
|
1056
|
+
}
|
|
1057
|
+
async function updateBusinessSkillState(profileName, agent, updater) {
|
|
1058
|
+
const lockPath = await acquireStateLock(profileName, agent);
|
|
1059
|
+
try {
|
|
1060
|
+
const state = await readBusinessSkillState(profileName, agent);
|
|
1061
|
+
const next = await updater(state) ?? state;
|
|
1062
|
+
await writeBusinessSkillState(profileName, agent, next);
|
|
1063
|
+
return next;
|
|
1064
|
+
} finally {
|
|
1065
|
+
await rm(lockPath, { recursive: true, force: true });
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
async function zipDirectoryToTemp(zipBuffer, prefix) {
|
|
1069
|
+
const zip = await JSZip.loadAsync(zipBuffer);
|
|
1070
|
+
const root = path2.join(tmpdir(), `${prefix}-${Date.now()}-${Math.random().toString(16).slice(2)}`);
|
|
1071
|
+
await mkdir2(root, { recursive: true });
|
|
1072
|
+
await Promise.all(
|
|
1073
|
+
Object.keys(zip.files).map(async (filename) => {
|
|
1074
|
+
const normalized = filename.replace(/\\/g, "/");
|
|
1075
|
+
if (normalized.startsWith("/") || normalized.includes("../") || normalized === "..") {
|
|
1076
|
+
throw new Error(`Unsafe path in BBS zip: ${filename}`);
|
|
1077
|
+
}
|
|
1078
|
+
const file = zip.files[filename];
|
|
1079
|
+
const target = path2.join(root, normalized);
|
|
1080
|
+
if (file.dir) {
|
|
1081
|
+
await mkdir2(target, { recursive: true });
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
await mkdir2(path2.dirname(target), { recursive: true });
|
|
1085
|
+
await writeFile2(target, await file.async("nodebuffer"));
|
|
1086
|
+
})
|
|
1087
|
+
);
|
|
1088
|
+
if (!await exists(path2.join(root, "SKILL.md"))) {
|
|
1089
|
+
throw new Error("BBS zip must contain top-level SKILL.md.");
|
|
1090
|
+
}
|
|
1091
|
+
return root;
|
|
1092
|
+
}
|
|
1093
|
+
async function lintBusinessSkillDirectory(skillDir, options = {}) {
|
|
1094
|
+
const issues = [];
|
|
1095
|
+
const checks = [];
|
|
1096
|
+
let skillMarkdown = "";
|
|
1097
|
+
let manifest = {};
|
|
1098
|
+
let config;
|
|
1099
|
+
try {
|
|
1100
|
+
skillMarkdown = await readFile3(path2.join(skillDir, "SKILL.md"), "utf8");
|
|
1101
|
+
manifest = parseFrontmatter(skillMarkdown);
|
|
1102
|
+
} catch {
|
|
1103
|
+
issues.push(issue("error", "missing_skill_md", "BBS package must contain top-level SKILL.md."));
|
|
1104
|
+
}
|
|
1105
|
+
try {
|
|
1106
|
+
config = await readBbsJson(skillDir);
|
|
1107
|
+
} catch (error) {
|
|
1108
|
+
issues.push(issue("error", "invalid_bbs_json", error instanceof Error ? error.message : String(error)));
|
|
1109
|
+
}
|
|
1110
|
+
const name = manifest.name;
|
|
1111
|
+
const version = manifest.version;
|
|
1112
|
+
const description = manifest.description;
|
|
1113
|
+
if (!name || typeof name !== "string") {
|
|
1114
|
+
issues.push(issue("error", "missing_name", "SKILL.md frontmatter must contain name."));
|
|
1115
|
+
} else if (!normalizeBusinessSkillKey(name)) {
|
|
1116
|
+
issues.push(issue("error", "invalid_name", "SKILL.md frontmatter name must produce a valid BBS key."));
|
|
1117
|
+
}
|
|
1118
|
+
if (!version || typeof version !== "string") {
|
|
1119
|
+
issues.push(issue("error", "missing_version", "SKILL.md frontmatter must contain version."));
|
|
1120
|
+
} else if (!semverPattern.test(version)) {
|
|
1121
|
+
issues.push(issue("error", "invalid_version", "SKILL.md frontmatter version must be semver, for example 1.0.0."));
|
|
1122
|
+
} else if (options.latestVersion && compareSemver(version, options.latestVersion) <= 0) {
|
|
1123
|
+
issues.push(
|
|
1124
|
+
issue(
|
|
1125
|
+
"error",
|
|
1126
|
+
"version_not_incremented",
|
|
1127
|
+
`BBS package version ${version} must be greater than latest version ${options.latestVersion}.`
|
|
1128
|
+
)
|
|
1129
|
+
);
|
|
1130
|
+
}
|
|
1131
|
+
if (!description || typeof description !== "string") {
|
|
1132
|
+
issues.push(issue("error", "missing_description", "SKILL.md frontmatter must contain description."));
|
|
1133
|
+
}
|
|
1134
|
+
const commands = extractBpmaxCommands(skillMarkdown);
|
|
1135
|
+
const unknownCommands = commands.filter((command) => !commandExists(command));
|
|
1136
|
+
unknownCommands.forEach((command) => {
|
|
1137
|
+
issues.push(issue("error", "unknown_bpmax_command", `Unknown bpmax-cli command in SKILL.md: ${commandPrefix(command)}`));
|
|
1138
|
+
});
|
|
1139
|
+
checks.push({ name: "bpmax_commands", commands, unknown: unknownCommands });
|
|
1140
|
+
[
|
|
1141
|
+
{ pattern: /\brm\s+-rf\b/, code: "dangerous_rm_rf", message: "Dangerous rm -rf command found." },
|
|
1142
|
+
{ pattern: /\bgit\s+reset\s+--hard\b/, code: "dangerous_git_reset", message: "Dangerous git reset --hard command found." },
|
|
1143
|
+
{ pattern: /\bgit\s+checkout\s+--\b/, code: "dangerous_git_checkout", message: "Dangerous git checkout -- command found." },
|
|
1144
|
+
{ pattern: /authorization\s*:\s*bearer|api[_-]?key\s*[:=]\s*['"][^'"]+/i, code: "secret_literal", message: "Possible literal credential found." },
|
|
1145
|
+
{ pattern: /\bcurl\b[\s\S]{0,160}\b-X\s*(POST|PUT|PATCH|DELETE)\b/i, code: "raw_mutating_curl", message: "Raw mutating curl command found; use bpmax-cli wrappers." }
|
|
1146
|
+
].forEach((rule) => {
|
|
1147
|
+
if (rule.pattern.test(skillMarkdown)) {
|
|
1148
|
+
issues.push(issue("error", rule.code, rule.message));
|
|
1149
|
+
}
|
|
1150
|
+
});
|
|
1151
|
+
if (/\bcurl\b/i.test(skillMarkdown)) {
|
|
1152
|
+
issues.push(issue("warning", "curl_usage", "curl usage found; prefer bpmax-cli commands for BPMAX APIs."));
|
|
1153
|
+
}
|
|
1154
|
+
if (isApprovalSkill(skillMarkdown, manifest)) {
|
|
1155
|
+
const lower = skillMarkdown.toLowerCase();
|
|
1156
|
+
if (!hasAny(lower, [/confirm|confirmation|explicit|明确|确认/])) {
|
|
1157
|
+
issues.push(issue("error", "approval_missing_confirmation", "Approval BBS must require explicit user confirmation."));
|
|
1158
|
+
}
|
|
1159
|
+
if (!hasAny(lower, [/batch|multiple|批量|多个|exact task list/])) {
|
|
1160
|
+
issues.push(issue("error", "approval_missing_batch_guardrail", "Approval BBS must define batch approval guardrails."));
|
|
1161
|
+
}
|
|
1162
|
+
if (!/bpmax-cli\s+project\s+approval-context/.test(skillMarkdown)) {
|
|
1163
|
+
issues.push(issue("error", "approval_missing_context", "Approval BBS must use bpmax-cli project approval-context before approving."));
|
|
1164
|
+
}
|
|
1165
|
+
if (!hasAny(lower, [/stop|failed|failure|error|失败|不要|不得|do not/])) {
|
|
1166
|
+
issues.push(issue("error", "approval_missing_failure_stop", "Approval BBS must stop on failed context or API errors."));
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
const lintCommands = config?.lint?.commands || [];
|
|
1170
|
+
for (const command of lintCommands) {
|
|
1171
|
+
const result = await runShellCommand(command, skillDir);
|
|
1172
|
+
checks.push({
|
|
1173
|
+
name: "custom_lint_command",
|
|
1174
|
+
command,
|
|
1175
|
+
exit_code: result.exitCode,
|
|
1176
|
+
stdout: truncateOutput(result.stdout),
|
|
1177
|
+
stderr: truncateOutput(result.stderr)
|
|
1178
|
+
});
|
|
1179
|
+
if (result.exitCode !== 0) {
|
|
1180
|
+
issues.push(issue("error", "custom_lint_failed", `Custom lint command failed: ${command}`));
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
return completeReport({ manifest, checks, issues, skill_dir: skillDir });
|
|
1184
|
+
}
|
|
1185
|
+
async function lintBusinessSkillZip(zipPath, options = {}) {
|
|
1186
|
+
try {
|
|
1187
|
+
const buffer = await readFile3(zipPath);
|
|
1188
|
+
const dir = await zipDirectoryToTemp(buffer, "bbs-lint");
|
|
1189
|
+
return lintBusinessSkillDirectory(dir, options);
|
|
1190
|
+
} catch (error) {
|
|
1191
|
+
return completeReport({
|
|
1192
|
+
manifest: {},
|
|
1193
|
+
checks: [],
|
|
1194
|
+
issues: [issue("error", "invalid_package", error instanceof Error ? error.message : String(error))]
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
function hasOwn(value, key) {
|
|
1199
|
+
return Object.prototype.hasOwnProperty.call(value, key) && value[key] !== void 0 && value[key] !== null && value[key] !== "";
|
|
1200
|
+
}
|
|
1201
|
+
async function runBusinessSkillGate(options) {
|
|
1202
|
+
const errors = [];
|
|
1203
|
+
const warnings = [];
|
|
1204
|
+
const checks = [];
|
|
1205
|
+
let skillMarkdown = "";
|
|
1206
|
+
let config;
|
|
1207
|
+
try {
|
|
1208
|
+
skillMarkdown = await readFile3(path2.join(options.skillDir, "SKILL.md"), "utf8");
|
|
1209
|
+
} catch {
|
|
1210
|
+
errors.push(issue("error", "missing_skill_md", "Installed BBS is missing SKILL.md."));
|
|
1211
|
+
}
|
|
1212
|
+
try {
|
|
1213
|
+
config = await readBbsJson(options.skillDir);
|
|
1214
|
+
} catch (error) {
|
|
1215
|
+
errors.push(issue("error", "invalid_bbs_json", error instanceof Error ? error.message : String(error)));
|
|
1216
|
+
}
|
|
1217
|
+
const gate = config?.gates?.[options.stage];
|
|
1218
|
+
if (!gate) {
|
|
1219
|
+
errors.push(issue("error", "missing_gate_stage", `bbs.json does not define gates.${options.stage}.`));
|
|
1220
|
+
}
|
|
1221
|
+
const requiredValues = options.stage === "verify" ? gate?.requiredOutputs || [] : gate?.requiredInputs || [];
|
|
1222
|
+
const missingValues = requiredValues.filter((key) => !hasOwn(options.input, key));
|
|
1223
|
+
missingValues.forEach((key) => {
|
|
1224
|
+
errors.push(issue("error", "missing_gate_value", `BBS gate ${options.stage} input is missing required value: ${key}`));
|
|
1225
|
+
});
|
|
1226
|
+
checks.push({ name: "required_values", required: requiredValues, missing: missingValues });
|
|
1227
|
+
const requiredCommands = gate?.requiredCommands || [];
|
|
1228
|
+
const missingCommands = requiredCommands.filter((command) => !skillMarkdown.includes(command));
|
|
1229
|
+
missingCommands.forEach((command) => {
|
|
1230
|
+
errors.push(issue("error", "missing_required_command", `SKILL.md does not include required gate command: ${command}`));
|
|
1231
|
+
});
|
|
1232
|
+
checks.push({ name: "required_commands", required: requiredCommands, missing: missingCommands });
|
|
1233
|
+
if (options.stage === "preflight" && isApprovalSkill(skillMarkdown, parseFrontmatter(skillMarkdown))) {
|
|
1234
|
+
if (!hasOwn(options.input, "approval_context")) {
|
|
1235
|
+
errors.push(issue("error", "missing_approval_context", "Approval BBS preflight requires approval_context from project approval-context."));
|
|
1236
|
+
}
|
|
1237
|
+
const batchSize = options.input.batch_size;
|
|
1238
|
+
if (typeof batchSize === "number" && batchSize > 1 && !options.input.user_confirmed_batch) {
|
|
1239
|
+
errors.push(issue("error", "missing_batch_confirmation", "Batch approval requires explicit user_confirmed_batch=true."));
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
if (options.stage === "verify" && hasOwn(options.input, "action_result")) {
|
|
1243
|
+
const actionResult = options.input.action_result;
|
|
1244
|
+
if (typeof actionResult === "object" && actionResult !== null) {
|
|
1245
|
+
const result = actionResult;
|
|
1246
|
+
if (result.ok === false || result.code === -1 || result.status === "failed" || result.status === "error") {
|
|
1247
|
+
errors.push(issue("error", "action_result_failed", "BBS verify action_result indicates failure."));
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
return {
|
|
1252
|
+
ok: errors.length === 0,
|
|
1253
|
+
skill: options.skill,
|
|
1254
|
+
stage: options.stage,
|
|
1255
|
+
errors,
|
|
1256
|
+
warnings,
|
|
1257
|
+
checks,
|
|
1258
|
+
...options.projectUrl ? { project_url: options.projectUrl } : {}
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
async function findOpenClawCli() {
|
|
1262
|
+
const command = process.platform === "win32" ? "where" : "which";
|
|
1263
|
+
const result = await runCommand(command, ["openclaw"]);
|
|
1264
|
+
if (result.exitCode !== 0) {
|
|
1265
|
+
return null;
|
|
1266
|
+
}
|
|
1267
|
+
return result.stdout.split(/\r?\n/).find((line) => line.trim())?.trim() || "openclaw";
|
|
1268
|
+
}
|
|
1269
|
+
async function installSkillDirectory(skillDir, skillName, agent) {
|
|
1270
|
+
if (agent === "openclaw") {
|
|
1271
|
+
const executable = await findOpenClawCli();
|
|
1272
|
+
if (executable) {
|
|
1273
|
+
const result = await runCommand(executable, ["skills", "install", "--file-path", skillDir], {
|
|
1274
|
+
timeoutMs: 2 * 60 * 1e3
|
|
1275
|
+
});
|
|
1276
|
+
if (result.exitCode === 0) {
|
|
1277
|
+
return skillDir;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
const fallbackRoot = path2.join(homedir2(), ".openclaw", "skills");
|
|
1281
|
+
const destination2 = path2.join(fallbackRoot, skillName);
|
|
1282
|
+
await mkdir2(fallbackRoot, { recursive: true });
|
|
1283
|
+
await rm(destination2, { recursive: true, force: true });
|
|
1284
|
+
await cp(skillDir, destination2, { recursive: true });
|
|
1285
|
+
return destination2;
|
|
1286
|
+
}
|
|
1287
|
+
const root = directoryTargets[agent] || directoryTargets.generic;
|
|
1288
|
+
const destination = path2.join(root, skillName);
|
|
1289
|
+
await mkdir2(root, { recursive: true });
|
|
1290
|
+
await rm(destination, { recursive: true, force: true });
|
|
1291
|
+
await cp(skillDir, destination, { recursive: true });
|
|
1292
|
+
return destination;
|
|
1293
|
+
}
|
|
1294
|
+
function resolveDownloadUrl(profile, url) {
|
|
1295
|
+
if (/^https?:\/\//i.test(url)) {
|
|
1296
|
+
return url;
|
|
1297
|
+
}
|
|
1298
|
+
return `${profile.config.origin.replace(/\/$/, "")}${url.startsWith("/") ? url : `/${url}`}`;
|
|
1299
|
+
}
|
|
1300
|
+
async function downloadBusinessSkillPackage(profile, download) {
|
|
1301
|
+
const buffer = download.content_base64 ? Buffer.from(download.content_base64, "base64") : Buffer.from(
|
|
1302
|
+
(await axios3.get(resolveDownloadUrl(profile, download.url), {
|
|
1303
|
+
responseType: "arraybuffer"
|
|
1304
|
+
})).data
|
|
1305
|
+
);
|
|
1306
|
+
const checksum = createHash("sha256").update(buffer).digest("hex");
|
|
1307
|
+
if (download.checksum && checksum !== download.checksum) {
|
|
1308
|
+
throw new Error(`BBS checksum mismatch. expected ${download.checksum}, got ${checksum}`);
|
|
1309
|
+
}
|
|
1310
|
+
return buffer;
|
|
1311
|
+
}
|
|
1312
|
+
async function fetchBusinessSkillByKeyOrId(client, keyOrId) {
|
|
1313
|
+
if (/^\d+$/.test(keyOrId)) {
|
|
1314
|
+
return apiRequest(client, "GET", `/business_skill/${keyOrId}`);
|
|
1315
|
+
}
|
|
1316
|
+
const result = await apiRequest(
|
|
1317
|
+
client,
|
|
1318
|
+
"GET",
|
|
1319
|
+
"/business_skill",
|
|
1320
|
+
{ params: { q_key: keyOrId, page_size: 1 } }
|
|
1321
|
+
);
|
|
1322
|
+
const list = Array.isArray(result) ? result : result.data || [];
|
|
1323
|
+
const skill = list.find((item) => item.key === keyOrId) || list[0];
|
|
1324
|
+
if (!skill) {
|
|
1325
|
+
throw new Error(`BBS not found: ${keyOrId}`);
|
|
1326
|
+
}
|
|
1327
|
+
return skill;
|
|
1328
|
+
}
|
|
1329
|
+
async function buildCatalogSkill(skills) {
|
|
1330
|
+
const dir = path2.join(tmpdir(), `bpmax-business-skill-catalog-${Date.now()}-${Math.random().toString(16).slice(2)}`);
|
|
1331
|
+
await mkdir2(dir, { recursive: true });
|
|
1332
|
+
const body = [
|
|
1333
|
+
"---",
|
|
1334
|
+
"name: bpmax-business-skill-catalog",
|
|
1335
|
+
"version: 1.0.0",
|
|
1336
|
+
"description: Discover remote BPMAX Business Skills and install them lazily with bpmax-cli bbs ensure.",
|
|
1337
|
+
"---",
|
|
1338
|
+
"",
|
|
1339
|
+
"# BPMAX Business Skill Catalog",
|
|
1340
|
+
"",
|
|
1341
|
+
"Use this catalog when a user request matches one of the remote BPMAX Business Skills below.",
|
|
1342
|
+
"Before using a business skill, run:",
|
|
1343
|
+
"",
|
|
1344
|
+
"```bash",
|
|
1345
|
+
"bpmax-cli bbs ensure <skill-key> --agent <agent> --format json",
|
|
1346
|
+
"```",
|
|
1347
|
+
"",
|
|
1348
|
+
"## Available Skills",
|
|
1349
|
+
"",
|
|
1350
|
+
...skills.map(
|
|
1351
|
+
(skill) => [
|
|
1352
|
+
`### ${skill.name}`,
|
|
1353
|
+
"",
|
|
1354
|
+
`- key: \`${skill.key}\``,
|
|
1355
|
+
`- version: \`${skill.latest_version || ""}\``,
|
|
1356
|
+
`- scene: ${skill.scene || ""}`,
|
|
1357
|
+
`- description: ${skill.description || ""}`,
|
|
1358
|
+
""
|
|
1359
|
+
].join("\n")
|
|
1360
|
+
)
|
|
1361
|
+
].join("\n");
|
|
1362
|
+
await writeFile2(path2.join(dir, "SKILL.md"), body, "utf8");
|
|
1363
|
+
return {
|
|
1364
|
+
dir,
|
|
1365
|
+
checksum: createHash("sha256").update(body).digest("hex")
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
// src/commands/bbs.ts
|
|
1370
|
+
async function zipPayload(zipPath) {
|
|
1371
|
+
const buffer = await readFile4(zipPath);
|
|
1372
|
+
return {
|
|
1373
|
+
zip_base64: buffer.toString("base64"),
|
|
1374
|
+
file_name: basename(zipPath)
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
function defaultAgent(options) {
|
|
1378
|
+
return options.agent || process.env.BPMAX_CLI_AGENT || "openclaw";
|
|
1379
|
+
}
|
|
1380
|
+
function assertLintPassed(report, allowLintErrors) {
|
|
1381
|
+
if (!report.ok && !allowLintErrors) {
|
|
1382
|
+
throw new Error(`BBS lint failed:
|
|
1383
|
+
- ${report.errors.map((item) => item.message).join("\n- ")}`);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
function registerBbsCommands(program2) {
|
|
1387
|
+
const bbs = program2.command("bbs").description("Manage BPMAX Business Skills");
|
|
1388
|
+
bbs.command("list").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
1389
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
1390
|
+
const result = await apiRequest(createApiClient(profile), "GET", "/business_skill");
|
|
1391
|
+
printResult(options.format, result);
|
|
1392
|
+
});
|
|
1393
|
+
bbs.command("show <keyOrId>").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (keyOrId, options) => {
|
|
1394
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
1395
|
+
const result = await fetchBusinessSkillByKeyOrId(createApiClient(profile), keyOrId);
|
|
1396
|
+
printResult(options.format, result);
|
|
1397
|
+
});
|
|
1398
|
+
bbs.command("lint").requiredOption("--zip <path>", "Skill zip path").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
1399
|
+
const report = await lintBusinessSkillZip(options.zip);
|
|
1400
|
+
printResult(options.format, report);
|
|
1401
|
+
});
|
|
1402
|
+
bbs.command("create").requiredOption("--zip <path>", "Skill zip path").option("--name <name>", "BBS display name").option("--key <key>", "BBS key").option("--scene <scene>", "BBS scene").option("--description <description>", "BBS description").option("--allow-lint-errors", "Allow upload even when local BBS lint reports errors").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
1403
|
+
const lintReport = await lintBusinessSkillZip(options.zip);
|
|
1404
|
+
assertLintPassed(lintReport, options.allowLintErrors);
|
|
1405
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
1406
|
+
const data = {
|
|
1407
|
+
...await zipPayload(options.zip),
|
|
1408
|
+
name: options.name,
|
|
1409
|
+
key: options.key,
|
|
1410
|
+
scene: options.scene,
|
|
1411
|
+
description: options.description
|
|
1412
|
+
};
|
|
1413
|
+
const result = await apiRequest(createApiClient(profile), "POST", "/business_skill", { data });
|
|
1414
|
+
printResult(options.format, {
|
|
1415
|
+
...typeof result === "object" && result !== null ? result : { result },
|
|
1416
|
+
lint_report: lintReport,
|
|
1417
|
+
...options.allowLintErrors && !lintReport.ok ? { lint_bypassed: true } : {}
|
|
1418
|
+
});
|
|
1419
|
+
});
|
|
1420
|
+
bbs.command("upgrade <keyOrId>").requiredOption("--zip <path>", "Skill zip path").option("--release-note <text>", "Release note").option("--allow-lint-errors", "Allow upload even when local BBS lint reports errors").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (keyOrId, options) => {
|
|
1421
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
1422
|
+
const client = createApiClient(profile);
|
|
1423
|
+
const skill = await fetchBusinessSkillByKeyOrId(client, keyOrId);
|
|
1424
|
+
const lintReport = await lintBusinessSkillZip(options.zip, { latestVersion: skill.latest_version });
|
|
1425
|
+
assertLintPassed(lintReport, options.allowLintErrors);
|
|
1426
|
+
const data = {
|
|
1427
|
+
...await zipPayload(options.zip),
|
|
1428
|
+
release_note: options.releaseNote
|
|
1429
|
+
};
|
|
1430
|
+
const result = await apiRequest(client, "POST", `/business_skill/${skill.id}/versions`, { data });
|
|
1431
|
+
printResult(options.format, {
|
|
1432
|
+
...typeof result === "object" && result !== null ? result : { result },
|
|
1433
|
+
lint_report: lintReport,
|
|
1434
|
+
...options.allowLintErrors && !lintReport.ok ? { lint_bypassed: true } : {}
|
|
1435
|
+
});
|
|
1436
|
+
});
|
|
1437
|
+
bbs.command("gate <keyOrId>").requiredOption("--stage <stage>", "Gate stage, for example preflight or verify").requiredOption("--input <json>", "Gate input JSON or @file").option("--skill-dir <path>", "Installed skill directory override").option("--agent <agent>", "Agent adapter", "openclaw").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (keyOrId, options) => {
|
|
1438
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
1439
|
+
const agent = defaultAgent(options);
|
|
1440
|
+
const input = await parseJsonInput(options.input, "Gate input");
|
|
1441
|
+
let skillDir = options.skillDir;
|
|
1442
|
+
if (!skillDir) {
|
|
1443
|
+
const state = await readBusinessSkillState(profile.name, agent);
|
|
1444
|
+
const installed = state.skills[keyOrId];
|
|
1445
|
+
if (!installed) {
|
|
1446
|
+
throw new Error(`BBS ${keyOrId} is not installed for agent ${agent}. Run: bpmax-cli bbs ensure ${keyOrId} --agent ${agent}`);
|
|
1447
|
+
}
|
|
1448
|
+
skillDir = installed.install_path;
|
|
1449
|
+
}
|
|
1450
|
+
const projectId = input.project_id;
|
|
1451
|
+
const projectUrl = typeof projectId === "number" || typeof projectId === "string" ? buildBpmaxUrl(profile, "project-detail", { projectId: String(projectId) }).url : void 0;
|
|
1452
|
+
const report = await runBusinessSkillGate({
|
|
1453
|
+
skill: keyOrId,
|
|
1454
|
+
stage: options.stage,
|
|
1455
|
+
skillDir,
|
|
1456
|
+
input,
|
|
1457
|
+
projectUrl
|
|
1458
|
+
});
|
|
1459
|
+
if (!report.ok) {
|
|
1460
|
+
throw new Error(`BBS gate failed:
|
|
1461
|
+
- ${report.errors.map((item) => item.message).join("\n- ")}`);
|
|
1462
|
+
}
|
|
1463
|
+
printResult(options.format, report);
|
|
1464
|
+
});
|
|
1465
|
+
bbs.command("sync").option("--agent <agent>", "Agent adapter", "openclaw").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
1466
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
1467
|
+
const agent = defaultAgent(options);
|
|
1468
|
+
const result = await apiRequest(
|
|
1469
|
+
createApiClient(profile),
|
|
1470
|
+
"GET",
|
|
1471
|
+
"/business_skill",
|
|
1472
|
+
{ params: { page_size: 1e3 } }
|
|
1473
|
+
);
|
|
1474
|
+
const skills = Array.isArray(result) ? result : result.data || [];
|
|
1475
|
+
const catalog = await buildCatalogSkill(skills);
|
|
1476
|
+
const installPath = await installSkillDirectory(catalog.dir, "bpmax-business-skill-catalog", agent);
|
|
1477
|
+
await updateBusinessSkillState(profile.name, agent, (state) => {
|
|
1478
|
+
state.catalog = {
|
|
1479
|
+
checksum: catalog.checksum,
|
|
1480
|
+
install_path: installPath,
|
|
1481
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1482
|
+
};
|
|
1483
|
+
});
|
|
1484
|
+
printResult(options.format, {
|
|
1485
|
+
action: "synced",
|
|
1486
|
+
agent,
|
|
1487
|
+
installed: "bpmax-business-skill-catalog",
|
|
1488
|
+
install_path: installPath,
|
|
1489
|
+
skills_count: skills.length
|
|
1490
|
+
});
|
|
1491
|
+
});
|
|
1492
|
+
async function ensureSkill(keyOrId, options) {
|
|
1493
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
1494
|
+
const agent = defaultAgent(options);
|
|
1495
|
+
const client = createApiClient(profile);
|
|
1496
|
+
const skill = await fetchBusinessSkillByKeyOrId(client, keyOrId);
|
|
1497
|
+
const state = await readBusinessSkillState(profile.name, agent);
|
|
1498
|
+
const installed = state.skills[skill.key];
|
|
1499
|
+
if (!options.force && installed?.version === skill.latest_version) {
|
|
1500
|
+
printResult(options.format, { action: "in_sync", agent, skill: skill.key, version: installed.version });
|
|
1501
|
+
return;
|
|
1502
|
+
}
|
|
1503
|
+
const download = await apiRequest(
|
|
1504
|
+
client,
|
|
1505
|
+
"GET",
|
|
1506
|
+
`/business_skill/${skill.id}/download`,
|
|
1507
|
+
{ params: skill.latest_version ? { version: skill.latest_version } : void 0 }
|
|
1508
|
+
);
|
|
1509
|
+
const buffer = await downloadBusinessSkillPackage(profile, download);
|
|
1510
|
+
const skillDir = await zipDirectoryToTemp(buffer, `bbs-${skill.key}`);
|
|
1511
|
+
const installPath = await installSkillDirectory(skillDir, skill.key, agent);
|
|
1512
|
+
await updateBusinessSkillState(profile.name, agent, (current) => {
|
|
1513
|
+
current.skills[skill.key] = {
|
|
1514
|
+
id: skill.id,
|
|
1515
|
+
key: skill.key,
|
|
1516
|
+
name: skill.name,
|
|
1517
|
+
version: download.version,
|
|
1518
|
+
checksum: download.checksum,
|
|
1519
|
+
install_path: installPath,
|
|
1520
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1521
|
+
};
|
|
1522
|
+
});
|
|
1523
|
+
await apiRequest(client, "POST", "/business_skill/install_record", {
|
|
1524
|
+
data: {
|
|
1525
|
+
skill_id: skill.id,
|
|
1526
|
+
version_id: download.version_id,
|
|
1527
|
+
version: download.version,
|
|
1528
|
+
agent,
|
|
1529
|
+
action: installed ? "update" : options.action || "install",
|
|
1530
|
+
status: "success",
|
|
1531
|
+
cli_version: VERSION,
|
|
1532
|
+
install_path: installPath
|
|
1533
|
+
}
|
|
1534
|
+
});
|
|
1535
|
+
printResult(options.format, {
|
|
1536
|
+
action: installed ? "updated" : "installed",
|
|
1537
|
+
agent,
|
|
1538
|
+
skill: skill.key,
|
|
1539
|
+
version: download.version,
|
|
1540
|
+
install_path: installPath
|
|
1541
|
+
});
|
|
1542
|
+
}
|
|
1543
|
+
bbs.command("ensure <keyOrId>").option("--agent <agent>", "Agent adapter", "openclaw").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(
|
|
1544
|
+
(keyOrId, options) => ensureSkill(keyOrId, options)
|
|
1545
|
+
);
|
|
1546
|
+
bbs.command("install <keyOrId>").option("--agent <agent>", "Agent adapter", "openclaw").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(
|
|
1547
|
+
(keyOrId, options) => ensureSkill(keyOrId, { ...options, force: true, action: "install" })
|
|
1548
|
+
);
|
|
1549
|
+
bbs.command("update <keyOrId>").option("--agent <agent>", "Agent adapter", "openclaw").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(
|
|
1550
|
+
(keyOrId, options) => ensureSkill(keyOrId, { ...options, force: true, action: "update" })
|
|
1551
|
+
);
|
|
1552
|
+
bbs.command("uninstall <keyOrId>").option("--agent <agent>", "Agent adapter", "openclaw").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (keyOrId, options) => {
|
|
1553
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
1554
|
+
const agent = defaultAgent(options);
|
|
1555
|
+
const client = createApiClient(profile);
|
|
1556
|
+
const skill = await fetchBusinessSkillByKeyOrId(client, keyOrId);
|
|
1557
|
+
const state = await readBusinessSkillState(profile.name, agent);
|
|
1558
|
+
const installed = state.skills[skill.key];
|
|
1559
|
+
if (installed) {
|
|
1560
|
+
const { rm: rm2 } = await import("fs/promises");
|
|
1561
|
+
await rm2(installed.install_path, { recursive: true, force: true });
|
|
1562
|
+
await updateBusinessSkillState(profile.name, agent, (current) => {
|
|
1563
|
+
delete current.skills[skill.key];
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
await apiRequest(client, "POST", "/business_skill/install_record", {
|
|
1567
|
+
data: {
|
|
1568
|
+
skill_id: skill.id,
|
|
1569
|
+
version: installed?.version || "",
|
|
1570
|
+
agent,
|
|
1571
|
+
action: "uninstall",
|
|
1572
|
+
status: "success",
|
|
1573
|
+
cli_version: VERSION,
|
|
1574
|
+
install_path: installed?.install_path || ""
|
|
1575
|
+
}
|
|
1576
|
+
});
|
|
1577
|
+
printResult(options.format, { action: "uninstalled", agent, skill: skill.key });
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
|
|
640
1581
|
// src/commands/config.ts
|
|
641
1582
|
import { text } from "@clack/prompts";
|
|
642
1583
|
async function ensureValue(current, label, placeholder) {
|
|
@@ -719,27 +1660,6 @@ function registerConfigCommands(program2) {
|
|
|
719
1660
|
});
|
|
720
1661
|
}
|
|
721
1662
|
|
|
722
|
-
// src/core/json-input.ts
|
|
723
|
-
import { readFile as readFile2 } from "fs/promises";
|
|
724
|
-
async function parseJsonInput(input, label = "JSON input") {
|
|
725
|
-
const source = input.startsWith("@") ? input.slice(1) : void 0;
|
|
726
|
-
if (source === "") {
|
|
727
|
-
throw new Error(`${label} file path is empty.`);
|
|
728
|
-
}
|
|
729
|
-
const raw = source ? await readFile2(source, "utf8") : input;
|
|
730
|
-
let parsed;
|
|
731
|
-
try {
|
|
732
|
-
parsed = JSON.parse(raw);
|
|
733
|
-
} catch (error) {
|
|
734
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
735
|
-
throw new Error(`${label} is not valid JSON: ${detail}`);
|
|
736
|
-
}
|
|
737
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
738
|
-
throw new Error(`${label} must be a JSON object.`);
|
|
739
|
-
}
|
|
740
|
-
return parsed;
|
|
741
|
-
}
|
|
742
|
-
|
|
743
1663
|
// src/commands/es.ts
|
|
744
1664
|
function registerEsCommands(program2) {
|
|
745
1665
|
const es = program2.command("es").description("Fast ES-backed data queries");
|
|
@@ -784,76 +1704,30 @@ function registerFlowCommands(program2) {
|
|
|
784
1704
|
const profile = resolveProfile(config, options.profile);
|
|
785
1705
|
const result = await apiRequest(
|
|
786
1706
|
createApiClient(profile),
|
|
787
|
-
"GET",
|
|
788
|
-
"/flow/options",
|
|
789
|
-
{
|
|
790
|
-
params: options.name ? { name: options.name } : void 0
|
|
791
|
-
}
|
|
792
|
-
);
|
|
793
|
-
printResult(options.format, result);
|
|
794
|
-
});
|
|
795
|
-
flow.command("get").description("Get flow detail by id").requiredOption("--id <id>", "Flow id").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
796
|
-
const config = await loadConfig();
|
|
797
|
-
const profile = resolveProfile(config, options.profile);
|
|
798
|
-
const result = await apiRequest(
|
|
799
|
-
createApiClient(profile),
|
|
800
|
-
"POST",
|
|
801
|
-
"/flow/batch_get",
|
|
802
|
-
{
|
|
803
|
-
data: {
|
|
804
|
-
ids: [Number(options.id)]
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
);
|
|
808
|
-
printResult(options.format, result[0] ?? null);
|
|
809
|
-
});
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
// package.json
|
|
813
|
-
var package_default = {
|
|
814
|
-
name: "bpmax-cli",
|
|
815
|
-
version: "0.1.26",
|
|
816
|
-
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
817
|
-
type: "module",
|
|
818
|
-
bin: {
|
|
819
|
-
"bpmax-cli": "dist/bin.js"
|
|
820
|
-
},
|
|
821
|
-
files: [
|
|
822
|
-
"dist",
|
|
823
|
-
"scripts/install-skills.mjs",
|
|
824
|
-
"skills",
|
|
825
|
-
"README.md"
|
|
826
|
-
],
|
|
827
|
-
scripts: {
|
|
828
|
-
postinstall: "node scripts/install-skills.mjs",
|
|
829
|
-
build: "tsup",
|
|
830
|
-
dev: "tsx src/bin.ts",
|
|
831
|
-
"install:skills": "node scripts/install-skills.mjs",
|
|
832
|
-
test: "vitest run",
|
|
833
|
-
typecheck: "tsc --noEmit"
|
|
834
|
-
},
|
|
835
|
-
engines: {
|
|
836
|
-
node: ">=18"
|
|
837
|
-
},
|
|
838
|
-
dependencies: {
|
|
839
|
-
"@clack/prompts": "^1.2.0",
|
|
840
|
-
axios: "^1.9.0",
|
|
841
|
-
commander: "^14.0.0",
|
|
842
|
-
open: "^10.1.2"
|
|
843
|
-
},
|
|
844
|
-
devDependencies: {
|
|
845
|
-
"@types/node": "^22.15.17",
|
|
846
|
-
tsup: "^8.5.0",
|
|
847
|
-
tsx: "^4.19.4",
|
|
848
|
-
typescript: "^5.8.3",
|
|
849
|
-
vitest: "^3.1.3"
|
|
850
|
-
}
|
|
851
|
-
};
|
|
852
|
-
|
|
853
|
-
// src/core/build.ts
|
|
854
|
-
var CLI_NAME = "bpmax-cli";
|
|
855
|
-
var VERSION = package_default.version;
|
|
856
|
-
var NPM_PACKAGE = "bpmax-cli";
|
|
1707
|
+
"GET",
|
|
1708
|
+
"/flow/options",
|
|
1709
|
+
{
|
|
1710
|
+
params: options.name ? { name: options.name } : void 0
|
|
1711
|
+
}
|
|
1712
|
+
);
|
|
1713
|
+
printResult(options.format, result);
|
|
1714
|
+
});
|
|
1715
|
+
flow.command("get").description("Get flow detail by id").requiredOption("--id <id>", "Flow id").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
1716
|
+
const config = await loadConfig();
|
|
1717
|
+
const profile = resolveProfile(config, options.profile);
|
|
1718
|
+
const result = await apiRequest(
|
|
1719
|
+
createApiClient(profile),
|
|
1720
|
+
"POST",
|
|
1721
|
+
"/flow/batch_get",
|
|
1722
|
+
{
|
|
1723
|
+
data: {
|
|
1724
|
+
ids: [Number(options.id)]
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
);
|
|
1728
|
+
printResult(options.format, result[0] ?? null);
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
857
1731
|
|
|
858
1732
|
// src/core/setup.ts
|
|
859
1733
|
function parseBpmUrl(input) {
|
|
@@ -932,80 +1806,27 @@ function setupSummary(input) {
|
|
|
932
1806
|
}
|
|
933
1807
|
|
|
934
1808
|
// src/core/skills.ts
|
|
935
|
-
import { mkdir as
|
|
936
|
-
import
|
|
1809
|
+
import { mkdir as mkdir3, readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
|
|
1810
|
+
import path3 from "path";
|
|
937
1811
|
import { fileURLToPath } from "url";
|
|
938
|
-
|
|
939
|
-
// src/core/process.ts
|
|
940
|
-
import { spawn } from "child_process";
|
|
941
|
-
var runCommand = (command, args, options = {}) => new Promise((resolve) => {
|
|
942
|
-
const child = spawn(command, args, {
|
|
943
|
-
cwd: options.cwd,
|
|
944
|
-
env: options.env,
|
|
945
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
946
|
-
});
|
|
947
|
-
let stdout = "";
|
|
948
|
-
let stderr = "";
|
|
949
|
-
let settled = false;
|
|
950
|
-
const timer = options.timeoutMs && options.timeoutMs > 0 ? setTimeout(() => {
|
|
951
|
-
if (settled) {
|
|
952
|
-
return;
|
|
953
|
-
}
|
|
954
|
-
settled = true;
|
|
955
|
-
child.kill("SIGTERM");
|
|
956
|
-
resolve({
|
|
957
|
-
stdout,
|
|
958
|
-
stderr: `${stderr}${stderr ? "\n" : ""}Timed out after ${options.timeoutMs}ms`,
|
|
959
|
-
exitCode: 124
|
|
960
|
-
});
|
|
961
|
-
}, options.timeoutMs) : void 0;
|
|
962
|
-
child.stdout?.on("data", (chunk) => {
|
|
963
|
-
stdout += String(chunk);
|
|
964
|
-
});
|
|
965
|
-
child.stderr?.on("data", (chunk) => {
|
|
966
|
-
stderr += String(chunk);
|
|
967
|
-
});
|
|
968
|
-
child.on("error", (error) => {
|
|
969
|
-
if (settled) {
|
|
970
|
-
return;
|
|
971
|
-
}
|
|
972
|
-
settled = true;
|
|
973
|
-
if (timer) {
|
|
974
|
-
clearTimeout(timer);
|
|
975
|
-
}
|
|
976
|
-
resolve({ stdout, stderr: `${stderr}${stderr ? "\n" : ""}${error.message}`, exitCode: 1 });
|
|
977
|
-
});
|
|
978
|
-
child.on("close", (code) => {
|
|
979
|
-
if (settled) {
|
|
980
|
-
return;
|
|
981
|
-
}
|
|
982
|
-
settled = true;
|
|
983
|
-
if (timer) {
|
|
984
|
-
clearTimeout(timer);
|
|
985
|
-
}
|
|
986
|
-
resolve({ stdout, stderr, exitCode: code ?? 1 });
|
|
987
|
-
});
|
|
988
|
-
});
|
|
989
|
-
|
|
990
|
-
// src/core/skills.ts
|
|
991
1812
|
var SKILLS_STAMP_FILE = "skills.stamp";
|
|
992
1813
|
var SKILLS_INSTALL_TIMEOUT_MS = 2 * 60 * 1e3;
|
|
993
1814
|
function skillsStampValue(version, agent) {
|
|
994
1815
|
return agent ? `${version}:${agent}` : version;
|
|
995
1816
|
}
|
|
996
1817
|
function stampPath(configDir = getConfigDir()) {
|
|
997
|
-
return
|
|
1818
|
+
return path3.join(configDir, SKILLS_STAMP_FILE);
|
|
998
1819
|
}
|
|
999
1820
|
async function readSkillsStamp(configDir = getConfigDir()) {
|
|
1000
1821
|
try {
|
|
1001
|
-
return (await
|
|
1822
|
+
return (await readFile5(stampPath(configDir), "utf8")).trim();
|
|
1002
1823
|
} catch {
|
|
1003
1824
|
return "";
|
|
1004
1825
|
}
|
|
1005
1826
|
}
|
|
1006
1827
|
async function writeSkillsStamp(version, configDir = getConfigDir(), agent) {
|
|
1007
|
-
await
|
|
1008
|
-
await
|
|
1828
|
+
await mkdir3(configDir, { recursive: true });
|
|
1829
|
+
await writeFile3(stampPath(configDir), skillsStampValue(version, agent), "utf8");
|
|
1009
1830
|
}
|
|
1010
1831
|
async function checkSkillsSync(currentVersion, configDir = getConfigDir(), agent) {
|
|
1011
1832
|
const target = skillsStampValue(currentVersion, agent);
|
|
@@ -1016,11 +1837,11 @@ async function checkSkillsSync(currentVersion, configDir = getConfigDir(), agent
|
|
|
1016
1837
|
return { current, target, inSync: current === target };
|
|
1017
1838
|
}
|
|
1018
1839
|
function defaultPackageRoot() {
|
|
1019
|
-
return
|
|
1840
|
+
return path3.resolve(path3.dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
1020
1841
|
}
|
|
1021
1842
|
async function runSkillsInstall(options = {}) {
|
|
1022
1843
|
const runner = options.runner || runCommand;
|
|
1023
|
-
const args = [
|
|
1844
|
+
const args = [path3.join(options.packageRoot || defaultPackageRoot(), "scripts", "install-skills.mjs")];
|
|
1024
1845
|
if (options.agent) {
|
|
1025
1846
|
args.push("--json", "--agent", options.agent);
|
|
1026
1847
|
}
|
|
@@ -1115,8 +1936,8 @@ var FIELD_KEY_NAMES = [
|
|
|
1115
1936
|
var FIELD_LABEL_NAMES = ["label", "title", "display_name", "displayName", "text"];
|
|
1116
1937
|
var FIELD_TYPE_NAMES = ["type", "field_type", "fieldType", "value_type", "valueType", "control", "component", "widget"];
|
|
1117
1938
|
var OPTION_NAMES = ["options", "items", "choices", "values"];
|
|
1118
|
-
var REQUIRED_NAMES = ["required", "is_required", "isRequired", "require", "must"];
|
|
1119
|
-
function
|
|
1939
|
+
var REQUIRED_NAMES = ["required", "is_required", "isRequired", "require", "must", "validateRequired"];
|
|
1940
|
+
function isRecord3(value) {
|
|
1120
1941
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1121
1942
|
}
|
|
1122
1943
|
function pickString(source, keys) {
|
|
@@ -1143,7 +1964,7 @@ function pickBoolean(source, keys) {
|
|
|
1143
1964
|
}
|
|
1144
1965
|
const rules = source.rules;
|
|
1145
1966
|
if (Array.isArray(rules)) {
|
|
1146
|
-
return rules.some((rule) =>
|
|
1967
|
+
return rules.some((rule) => isRecord3(rule) && pickBoolean(rule, REQUIRED_NAMES));
|
|
1147
1968
|
}
|
|
1148
1969
|
return false;
|
|
1149
1970
|
}
|
|
@@ -1151,7 +1972,7 @@ function optionValue(option) {
|
|
|
1151
1972
|
if (typeof option === "string" || typeof option === "number") {
|
|
1152
1973
|
return String(option);
|
|
1153
1974
|
}
|
|
1154
|
-
if (!
|
|
1975
|
+
if (!isRecord3(option)) {
|
|
1155
1976
|
return null;
|
|
1156
1977
|
}
|
|
1157
1978
|
return pickString(option, ["value", "key", "id", "name", "label", "title"]) ?? null;
|
|
@@ -1198,6 +2019,7 @@ function mergeField(existing, incoming) {
|
|
|
1198
2019
|
return {
|
|
1199
2020
|
...existing,
|
|
1200
2021
|
...incoming,
|
|
2022
|
+
required: Boolean(existing?.required || incoming.required),
|
|
1201
2023
|
...children?.length ? { children } : {}
|
|
1202
2024
|
};
|
|
1203
2025
|
}
|
|
@@ -1211,7 +2033,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
1211
2033
|
}
|
|
1212
2034
|
return;
|
|
1213
2035
|
}
|
|
1214
|
-
if (!
|
|
2036
|
+
if (!isRecord3(value)) {
|
|
1215
2037
|
return;
|
|
1216
2038
|
}
|
|
1217
2039
|
const field = fieldFromRecord(value);
|
|
@@ -1219,7 +2041,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
1219
2041
|
if (isSubFormField(field)) {
|
|
1220
2042
|
const childFields = /* @__PURE__ */ new Map();
|
|
1221
2043
|
for (const child of Object.values(value)) {
|
|
1222
|
-
if (
|
|
2044
|
+
if (isRecord3(child) || Array.isArray(child)) {
|
|
1223
2045
|
collectFieldCandidates(child, childFields, depth + 1);
|
|
1224
2046
|
}
|
|
1225
2047
|
}
|
|
@@ -1233,7 +2055,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
1233
2055
|
fields.set(field.key, mergeField(fields.get(field.key), field));
|
|
1234
2056
|
}
|
|
1235
2057
|
for (const child of Object.values(value)) {
|
|
1236
|
-
if (
|
|
2058
|
+
if (isRecord3(child) || Array.isArray(child)) {
|
|
1237
2059
|
collectFieldCandidates(child, fields, depth + 1);
|
|
1238
2060
|
}
|
|
1239
2061
|
}
|
|
@@ -1246,13 +2068,41 @@ function extractFormFields(flowDetail) {
|
|
|
1246
2068
|
function isEmpty(value) {
|
|
1247
2069
|
return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
1248
2070
|
}
|
|
2071
|
+
function validateComplexSelector(field, value) {
|
|
2072
|
+
const type = field.type?.toLowerCase() ?? "";
|
|
2073
|
+
if (!isComplexSelectorType(type)) {
|
|
2074
|
+
return null;
|
|
2075
|
+
}
|
|
2076
|
+
const validObject = (item) => isRecord3(item);
|
|
2077
|
+
if (Array.isArray(value)) {
|
|
2078
|
+
return value.every(validObject) ? null : `${field.key} must contain selector option object(s), not scalar values`;
|
|
2079
|
+
}
|
|
2080
|
+
if (validObject(value)) {
|
|
2081
|
+
return null;
|
|
2082
|
+
}
|
|
2083
|
+
return `${field.key} must be a selector option object or array of option objects, not a scalar value`;
|
|
2084
|
+
}
|
|
2085
|
+
function isComplexSelectorType(type) {
|
|
2086
|
+
return /(plugin_city_selector|plugin_project_selector|plugin_user_selector|plugin_department_selector|relation_project|relation_form|user_selector|department_selector|group_select|project_selector_new)/.test(type);
|
|
2087
|
+
}
|
|
1249
2088
|
function validateType(field, value) {
|
|
1250
2089
|
const type = field.type?.toLowerCase() ?? "";
|
|
1251
2090
|
if (!type || isEmpty(value)) {
|
|
1252
2091
|
return null;
|
|
1253
2092
|
}
|
|
1254
2093
|
if (isSubFormField(field)) {
|
|
1255
|
-
|
|
2094
|
+
if (!Array.isArray(value)) {
|
|
2095
|
+
return `${field.key} must be a JSON array of row objects`;
|
|
2096
|
+
}
|
|
2097
|
+
const invalidRowIndex = value.findIndex((row) => !isRecord3(row));
|
|
2098
|
+
return invalidRowIndex >= 0 ? `${field.key}[${invalidRowIndex}] must be a row object` : null;
|
|
2099
|
+
}
|
|
2100
|
+
const selectorError = validateComplexSelector(field, value);
|
|
2101
|
+
if (selectorError) {
|
|
2102
|
+
return selectorError;
|
|
2103
|
+
}
|
|
2104
|
+
if (isComplexSelectorType(type)) {
|
|
2105
|
+
return null;
|
|
1256
2106
|
}
|
|
1257
2107
|
if (field.options) {
|
|
1258
2108
|
const values = Array.isArray(value) ? value.map(String) : [String(value)];
|
|
@@ -1296,7 +2146,7 @@ function validateFormEntries(form, fields, prefix = "") {
|
|
|
1296
2146
|
}
|
|
1297
2147
|
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
1298
2148
|
for (const [index, row] of value.entries()) {
|
|
1299
|
-
if (
|
|
2149
|
+
if (isRecord3(row)) {
|
|
1300
2150
|
errors.push(...validateFormEntries(row, field.children, `${prefix}${field.key}[${index}].`));
|
|
1301
2151
|
}
|
|
1302
2152
|
}
|
|
@@ -1517,15 +2367,15 @@ async function promptProjectCreateForm(input) {
|
|
|
1517
2367
|
}
|
|
1518
2368
|
|
|
1519
2369
|
// src/core/project-form.ts
|
|
1520
|
-
function
|
|
2370
|
+
function isRecord4(value) {
|
|
1521
2371
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1522
2372
|
}
|
|
1523
2373
|
function clone(value) {
|
|
1524
2374
|
return JSON.parse(JSON.stringify(value));
|
|
1525
2375
|
}
|
|
1526
2376
|
function getFlowFormTemplateId(flowDetail) {
|
|
1527
|
-
const data =
|
|
1528
|
-
const meta =
|
|
2377
|
+
const data = isRecord4(flowDetail?.data) ? flowDetail.data : void 0;
|
|
2378
|
+
const meta = isRecord4(data?.meta) ? data.meta : void 0;
|
|
1529
2379
|
const templateId = meta?.form_template;
|
|
1530
2380
|
if (typeof templateId === "number" && Number.isFinite(templateId)) {
|
|
1531
2381
|
return templateId;
|
|
@@ -1548,7 +2398,7 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
1548
2398
|
if (Array.isArray(value)) {
|
|
1549
2399
|
return value.some((item) => hasAutoInitLambda(item, seen));
|
|
1550
2400
|
}
|
|
1551
|
-
if (!
|
|
2401
|
+
if (!isRecord4(value)) {
|
|
1552
2402
|
return false;
|
|
1553
2403
|
}
|
|
1554
2404
|
if (seen.has(value)) {
|
|
@@ -1563,14 +2413,14 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
1563
2413
|
function setControlValue(control, value) {
|
|
1564
2414
|
const next = clone(control);
|
|
1565
2415
|
next.value = {
|
|
1566
|
-
...
|
|
2416
|
+
...isRecord4(next.value) ? next.value : {},
|
|
1567
2417
|
type: next.value?.type ?? next.field_type,
|
|
1568
2418
|
value
|
|
1569
2419
|
};
|
|
1570
2420
|
return next;
|
|
1571
2421
|
}
|
|
1572
2422
|
function applyRowValues(rowTemplate, rowValue) {
|
|
1573
|
-
const source =
|
|
2423
|
+
const source = isRecord4(rowValue) ? rowValue : {};
|
|
1574
2424
|
return rowTemplate.map((control) => {
|
|
1575
2425
|
if (control.key && Object.prototype.hasOwnProperty.call(source, control.key)) {
|
|
1576
2426
|
return setControlValue(control, source[control.key]);
|
|
@@ -1608,121 +2458,6 @@ async function buildProjectFormPayload(client, flowDetail, form, knownTemplate)
|
|
|
1608
2458
|
};
|
|
1609
2459
|
}
|
|
1610
2460
|
|
|
1611
|
-
// src/core/urls.ts
|
|
1612
|
-
function stripSlashes(value) {
|
|
1613
|
-
return value.trim().replace(/^\/+|\/+$/g, "");
|
|
1614
|
-
}
|
|
1615
|
-
function isRecord4(value) {
|
|
1616
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1617
|
-
}
|
|
1618
|
-
function normalizeWorkspaceForUrl(workspace) {
|
|
1619
|
-
const nextWorkspace = stripSlashes(workspace);
|
|
1620
|
-
if (!nextWorkspace) {
|
|
1621
|
-
throw new Error("Workspace is required to build a BPMAX URL.");
|
|
1622
|
-
}
|
|
1623
|
-
if (nextWorkspace === "default" || nextWorkspace.startsWith("w:")) {
|
|
1624
|
-
return nextWorkspace;
|
|
1625
|
-
}
|
|
1626
|
-
return `w:${nextWorkspace}`;
|
|
1627
|
-
}
|
|
1628
|
-
function normalizeOrigin2(origin) {
|
|
1629
|
-
const nextOrigin = origin.trim().replace(/\/+$/, "");
|
|
1630
|
-
if (!nextOrigin) {
|
|
1631
|
-
throw new Error("Origin is required to build a BPMAX URL.");
|
|
1632
|
-
}
|
|
1633
|
-
return nextOrigin;
|
|
1634
|
-
}
|
|
1635
|
-
function requireNumericId(value, name) {
|
|
1636
|
-
const nextValue = String(value || "").trim();
|
|
1637
|
-
if (!/^\d+$/.test(nextValue)) {
|
|
1638
|
-
throw new Error(`${name} must be a non-empty numeric string.`);
|
|
1639
|
-
}
|
|
1640
|
-
return nextValue;
|
|
1641
|
-
}
|
|
1642
|
-
function withQuery(path5, query) {
|
|
1643
|
-
const params = new URLSearchParams();
|
|
1644
|
-
for (const [key, value] of Object.entries(query)) {
|
|
1645
|
-
if (value !== void 0) {
|
|
1646
|
-
params.set(key, value);
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
return `${path5}?${params.toString()}`;
|
|
1650
|
-
}
|
|
1651
|
-
function buildBpmaxUrl(profile, kind, params = {}) {
|
|
1652
|
-
const origin = normalizeOrigin2(profile.config.origin);
|
|
1653
|
-
const workspace = normalizeWorkspaceForUrl(params.workspace || profile.config.workspace);
|
|
1654
|
-
const basePath = `/${workspace}`;
|
|
1655
|
-
let path5 = basePath;
|
|
1656
|
-
const result = {
|
|
1657
|
-
kind,
|
|
1658
|
-
profile: profile.name,
|
|
1659
|
-
origin,
|
|
1660
|
-
workspace
|
|
1661
|
-
};
|
|
1662
|
-
if (kind === "project-list") {
|
|
1663
|
-
path5 = `${basePath}/project`;
|
|
1664
|
-
} else if (kind === "project-detail") {
|
|
1665
|
-
const projectId = requireNumericId(params.projectId, "projectId");
|
|
1666
|
-
path5 = `${basePath}/project_detail/0/${projectId}`;
|
|
1667
|
-
result.project_id = projectId;
|
|
1668
|
-
} else if (kind === "project-step") {
|
|
1669
|
-
const projectId = requireNumericId(params.projectId, "projectId");
|
|
1670
|
-
const stepId = requireNumericId(params.stepId, "stepId");
|
|
1671
|
-
path5 = withQuery(`${basePath}/projectContinue`, {
|
|
1672
|
-
id: projectId,
|
|
1673
|
-
step_id: stepId
|
|
1674
|
-
});
|
|
1675
|
-
result.project_id = projectId;
|
|
1676
|
-
result.step_id = stepId;
|
|
1677
|
-
} else if (kind === "project-create") {
|
|
1678
|
-
const flowType = params.flowType || "default";
|
|
1679
|
-
const flowKey = params.flowKey || "";
|
|
1680
|
-
const initValue = params.initValue ? JSON.stringify(params.initValue) : void 0;
|
|
1681
|
-
const query = {
|
|
1682
|
-
flow_type: flowType,
|
|
1683
|
-
flow_key: flowKey,
|
|
1684
|
-
...flowKey ? { key: flowKey } : {},
|
|
1685
|
-
init_value: initValue
|
|
1686
|
-
};
|
|
1687
|
-
path5 = withQuery(`${basePath}/project/create`, query);
|
|
1688
|
-
result.flow_type = flowType;
|
|
1689
|
-
result.flow_key = flowKey;
|
|
1690
|
-
result.mobile_path = withQuery("/pages/projectCreate/projectCreate", query);
|
|
1691
|
-
}
|
|
1692
|
-
const url = `${origin}${path5}`;
|
|
1693
|
-
return {
|
|
1694
|
-
...result,
|
|
1695
|
-
path: path5,
|
|
1696
|
-
url,
|
|
1697
|
-
...kind === "project-create" ? { pc_url: url } : {}
|
|
1698
|
-
};
|
|
1699
|
-
}
|
|
1700
|
-
function extractProjectId(value) {
|
|
1701
|
-
if (!isRecord4(value)) {
|
|
1702
|
-
return void 0;
|
|
1703
|
-
}
|
|
1704
|
-
const candidates = [value.id, value.project_id, value.projectId];
|
|
1705
|
-
const candidate = candidates.find((item) => item !== void 0 && item !== null);
|
|
1706
|
-
if (candidate === void 0) {
|
|
1707
|
-
return void 0;
|
|
1708
|
-
}
|
|
1709
|
-
const projectId = String(candidate).trim();
|
|
1710
|
-
return /^\d+$/.test(projectId) ? projectId : void 0;
|
|
1711
|
-
}
|
|
1712
|
-
function attachProjectDetailUrl(profile, value) {
|
|
1713
|
-
if (!isRecord4(value) || typeof value.url === "string") {
|
|
1714
|
-
return value;
|
|
1715
|
-
}
|
|
1716
|
-
const projectId = extractProjectId(value);
|
|
1717
|
-
if (!projectId) {
|
|
1718
|
-
return value;
|
|
1719
|
-
}
|
|
1720
|
-
return {
|
|
1721
|
-
...value,
|
|
1722
|
-
url: buildBpmaxUrl(profile, "project-detail", { projectId }).url
|
|
1723
|
-
};
|
|
1724
|
-
}
|
|
1725
|
-
|
|
1726
2461
|
// src/commands/project.ts
|
|
1727
2462
|
function parseJson2(input) {
|
|
1728
2463
|
if (!input) {
|
|
@@ -1774,12 +2509,11 @@ async function validateCreateForm(client, options) {
|
|
|
1774
2509
|
);
|
|
1775
2510
|
flowDetail = flows[0];
|
|
1776
2511
|
}
|
|
1777
|
-
const
|
|
1778
|
-
if (
|
|
1779
|
-
const
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
const templateFields = extractFormFields(template);
|
|
2512
|
+
const templateId = getFlowFormTemplateId(flowDetail);
|
|
2513
|
+
if (options.projectFormTemplate || templateId) {
|
|
2514
|
+
const template = options.projectFormTemplate?.template ?? (templateId ? await apiRequest(client, "GET", `/form_template/${templateId}`) : void 0);
|
|
2515
|
+
const templateFields = extractFormFields(template);
|
|
2516
|
+
if (templateFields.length > 0) {
|
|
1783
2517
|
const result2 = validateFormAgainstFields(options.form, templateFields);
|
|
1784
2518
|
if (result2.errors.length > 0) {
|
|
1785
2519
|
throw new Error(`Form validation failed:
|
|
@@ -1788,6 +2522,15 @@ async function validateCreateForm(client, options) {
|
|
|
1788
2522
|
return;
|
|
1789
2523
|
}
|
|
1790
2524
|
}
|
|
2525
|
+
const fields = extractFormFields(flowDetail);
|
|
2526
|
+
if (fields.length > 0) {
|
|
2527
|
+
const result2 = validateFormAgainstFields(options.form, fields);
|
|
2528
|
+
if (result2.errors.length > 0) {
|
|
2529
|
+
throw new Error(`Form validation failed:
|
|
2530
|
+
- ${result2.errors.join("\n- ")}`);
|
|
2531
|
+
}
|
|
2532
|
+
return;
|
|
2533
|
+
}
|
|
1791
2534
|
if (fields.length === 0) {
|
|
1792
2535
|
throw new Error(
|
|
1793
2536
|
[
|
|
@@ -1858,11 +2601,96 @@ function assertCreateFormHandoffUrl(url, expectedInitValue, expectedFormKeys) {
|
|
|
1858
2601
|
throw new Error(`Generated project create handoff URL did not include init_value (${encoded.length} bytes).`);
|
|
1859
2602
|
}
|
|
1860
2603
|
}
|
|
1861
|
-
function
|
|
1862
|
-
|
|
2604
|
+
function fieldsForValidation(flowDetail, projectFormTemplate) {
|
|
2605
|
+
const templateFields = projectFormTemplate ? extractFormFields(projectFormTemplate.template) : [];
|
|
2606
|
+
return templateFields.length > 0 ? templateFields : extractFormFields(flowDetail);
|
|
2607
|
+
}
|
|
2608
|
+
function formValidationErrors(fields, form) {
|
|
2609
|
+
return validateFormAgainstFields(form, fields).errors;
|
|
2610
|
+
}
|
|
2611
|
+
function assertHandoffFormReady(fields, form) {
|
|
2612
|
+
const errors = formValidationErrors(fields, form);
|
|
2613
|
+
if (errors.length > 0) {
|
|
2614
|
+
throw new Error(
|
|
2615
|
+
[
|
|
2616
|
+
"Form handoff cannot be generated because collected values are incomplete or not page-compatible.",
|
|
2617
|
+
"Continue guiding the user to fill missing fields, or ask them to choose complex selector fields in the BPMAX page.",
|
|
2618
|
+
`Validation errors: ${errors.join("; ")}`
|
|
2619
|
+
].join("\n")
|
|
2620
|
+
);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
function isRecord5(value) {
|
|
2624
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2625
|
+
}
|
|
2626
|
+
function isEndedStep(step) {
|
|
2627
|
+
if (step.real_end_time) {
|
|
2628
|
+
return true;
|
|
2629
|
+
}
|
|
2630
|
+
if (step.status === "finished" || step.status === "done" || step.status === "completed") {
|
|
2631
|
+
return true;
|
|
2632
|
+
}
|
|
2633
|
+
return typeof step.status === "number" && [3, 4, 5].includes(step.status);
|
|
2634
|
+
}
|
|
2635
|
+
function stepIdOf(step) {
|
|
2636
|
+
const id = step.id;
|
|
2637
|
+
if (typeof id === "number" || typeof id === "string") {
|
|
2638
|
+
const value = String(id);
|
|
2639
|
+
return value ? value : void 0;
|
|
2640
|
+
}
|
|
2641
|
+
return void 0;
|
|
2642
|
+
}
|
|
2643
|
+
function pickStepFormPayload(step) {
|
|
2644
|
+
const formList = Array.isArray(step.formList) ? step.formList : [];
|
|
2645
|
+
const forms = Array.isArray(step.forms) ? step.forms : [];
|
|
2646
|
+
const metaForm = isRecord5(step.metaForm) ? step.metaForm : void 0;
|
|
2647
|
+
return {
|
|
2648
|
+
step_id: step.id,
|
|
2649
|
+
flow_step_id: step.flow_step_id,
|
|
2650
|
+
name: step.name,
|
|
2651
|
+
status: step.status,
|
|
2652
|
+
real_start_time: step.real_start_time,
|
|
2653
|
+
real_end_time: step.real_end_time,
|
|
2654
|
+
form_template_id: step.form_template_id,
|
|
2655
|
+
formList,
|
|
2656
|
+
forms,
|
|
2657
|
+
...metaForm ? { metaForm } : {},
|
|
2658
|
+
has_form_values: formList.length > 0 || forms.length > 0 || Boolean(metaForm)
|
|
2659
|
+
};
|
|
1863
2660
|
}
|
|
1864
|
-
function
|
|
1865
|
-
|
|
2661
|
+
async function buildApprovalContext(client, projectId, options) {
|
|
2662
|
+
const projectDetail = await apiRequest(client, "GET", `/project/${projectId}`);
|
|
2663
|
+
const steps = Array.isArray(projectDetail.steps) ? projectDetail.steps.filter(isRecord5) : [];
|
|
2664
|
+
const targetStepIds = /* @__PURE__ */ new Set();
|
|
2665
|
+
for (const step of steps) {
|
|
2666
|
+
const id = stepIdOf(step);
|
|
2667
|
+
if (id && isEndedStep(step)) {
|
|
2668
|
+
targetStepIds.add(id);
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
if (options.stepId) {
|
|
2672
|
+
targetStepIds.add(options.stepId);
|
|
2673
|
+
}
|
|
2674
|
+
const stepForms = [];
|
|
2675
|
+
const failedSteps = [];
|
|
2676
|
+
for (const stepId of targetStepIds) {
|
|
2677
|
+
try {
|
|
2678
|
+
const stepDetail = await apiRequest(client, "GET", `/step/${stepId}`);
|
|
2679
|
+
stepForms.push(pickStepFormPayload(stepDetail));
|
|
2680
|
+
} catch (error) {
|
|
2681
|
+
failedSteps.push({
|
|
2682
|
+
step_id: stepId,
|
|
2683
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2684
|
+
});
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
return {
|
|
2688
|
+
project: projectDetail,
|
|
2689
|
+
project_form: isRecord5(projectDetail.metaForm) ? projectDetail.metaForm : null,
|
|
2690
|
+
inspected_step_count: stepForms.length,
|
|
2691
|
+
step_forms: stepForms,
|
|
2692
|
+
failed_steps: failedSteps
|
|
2693
|
+
};
|
|
1866
2694
|
}
|
|
1867
2695
|
function registerProjectCommands(program2) {
|
|
1868
2696
|
const project = program2.command("project").description("Project commands");
|
|
@@ -1924,6 +2752,16 @@ function registerProjectCommands(program2) {
|
|
|
1924
2752
|
);
|
|
1925
2753
|
printResult(options.format, result);
|
|
1926
2754
|
});
|
|
2755
|
+
project.command("approval-context <projectId>").description("Get project form values plus ended approval step form values").option("--profile <profile>", "Profile name").option("--step-id <stepId>", "Also include a current approval step id").option("--format <format>", "Output format", "json").action(async (projectId, options) => {
|
|
2756
|
+
const config = await loadConfig();
|
|
2757
|
+
const profile = resolveProfile(config, options.profile);
|
|
2758
|
+
const client = createApiClient(profile);
|
|
2759
|
+
const context = await buildApprovalContext(client, projectId, { stepId: options.stepId });
|
|
2760
|
+
printResult(options.format, {
|
|
2761
|
+
...context,
|
|
2762
|
+
project: attachProjectDetailUrl(profile, context.project)
|
|
2763
|
+
});
|
|
2764
|
+
});
|
|
1927
2765
|
project.command("create").description("Minimal project create shortcut").option("--profile <profile>", "Profile name").option("--flow-id <flowId>", "Flow id").option("--flow-type <flowType>", "Flow type").option("--flow-key <flowKey>", "Flow key").option("--name <name>", "Project name").option("--json <json>", "Additional request JSON").option("--body <body>", "Full request body JSON override").option("--interactive", "Guide the user through filling project form fields").option("--no-interactive", "Disable the project create guide and submit directly when safe").option("--allow-form-handoff", "Allow interactive mode to hand off to the BPMAX web create form").option("--skip-form-validation", "Skip local form schema validation before submit").option("--format <format>", "Output format", "pretty").action(async (options, command) => {
|
|
1928
2766
|
const interactiveSource = command.getOptionValueSource("interactive");
|
|
1929
2767
|
if (options.body && options.interactive === true && interactiveSource === "cli") {
|
|
@@ -1969,6 +2807,7 @@ function registerProjectCommands(program2) {
|
|
|
1969
2807
|
}
|
|
1970
2808
|
projectFormTemplate = await loadProjectFormTemplate();
|
|
1971
2809
|
if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
|
|
2810
|
+
assertHandoffFormReady(fieldsForValidation(flowDetail, projectFormTemplate), form);
|
|
1972
2811
|
printCreateFormHandoff(options.format, profile, flowIdentifiers, {
|
|
1973
2812
|
name,
|
|
1974
2813
|
form,
|
|
@@ -1981,6 +2820,7 @@ function registerProjectCommands(program2) {
|
|
|
1981
2820
|
if (!options.allowFormHandoff) {
|
|
1982
2821
|
throw new Error("Form handoff requires --allow-form-handoff. Continue interactive filling by default.");
|
|
1983
2822
|
}
|
|
2823
|
+
assertHandoffFormReady(fieldsForValidation(flowDetail, projectFormTemplate), form);
|
|
1984
2824
|
printCreateFormHandoff(options.format, profile, flowIdentifiers, {
|
|
1985
2825
|
name,
|
|
1986
2826
|
form,
|
|
@@ -1994,7 +2834,8 @@ function registerProjectCommands(program2) {
|
|
|
1994
2834
|
}
|
|
1995
2835
|
projectFormTemplate = await loadProjectFormTemplate();
|
|
1996
2836
|
if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
|
|
1997
|
-
const
|
|
2837
|
+
const handoffFields = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
2838
|
+
const missingFields = formValidationErrors(handoffFields, form);
|
|
1998
2839
|
if (!useInteractive && missingFields.length > 0) {
|
|
1999
2840
|
throw new Error(
|
|
2000
2841
|
[
|
|
@@ -2004,6 +2845,7 @@ function registerProjectCommands(program2) {
|
|
|
2004
2845
|
].join("\n")
|
|
2005
2846
|
);
|
|
2006
2847
|
}
|
|
2848
|
+
assertHandoffFormReady(handoffFields, form);
|
|
2007
2849
|
printCreateFormHandoff(options.format, profile, flowIdentifiers, {
|
|
2008
2850
|
name,
|
|
2009
2851
|
form,
|
|
@@ -2023,7 +2865,7 @@ function registerProjectCommands(program2) {
|
|
|
2023
2865
|
...projectExtra.projectForm ? {} : await buildProjectFormPayload(client, flowDetail, form, projectFormTemplate)
|
|
2024
2866
|
};
|
|
2025
2867
|
if (!options.skipFormValidation) {
|
|
2026
|
-
await validateCreateForm(client, { flowId: options.flowId, flowDetail, form });
|
|
2868
|
+
await validateCreateForm(client, { flowId: options.flowId, flowDetail, form, projectFormTemplate });
|
|
2027
2869
|
}
|
|
2028
2870
|
}
|
|
2029
2871
|
const result = await apiRequest(
|
|
@@ -2043,8 +2885,8 @@ import { spawn as spawn2 } from "child_process";
|
|
|
2043
2885
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
2044
2886
|
|
|
2045
2887
|
// src/core/recipes.ts
|
|
2046
|
-
import { access, mkdir as
|
|
2047
|
-
import
|
|
2888
|
+
import { access, mkdir as mkdir4, readdir, readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
|
|
2889
|
+
import path4 from "path";
|
|
2048
2890
|
var RECIPE_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
|
|
2049
2891
|
var TEMPLATE_PATTERN = /{{\s*([a-zA-Z0-9_.-]+)\s*}}/g;
|
|
2050
2892
|
function assertSafeName(kind, value) {
|
|
@@ -2068,14 +2910,14 @@ function resolveRecipeLocation(options) {
|
|
|
2068
2910
|
workspace,
|
|
2069
2911
|
workspaceDirName,
|
|
2070
2912
|
recipeName: options.recipeName,
|
|
2071
|
-
recipeDir:
|
|
2913
|
+
recipeDir: path4.join(profileDir, "recipes", workspaceDirName, options.recipeName)
|
|
2072
2914
|
};
|
|
2073
2915
|
}
|
|
2074
2916
|
function getRecipesDir(options) {
|
|
2075
2917
|
const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
|
|
2076
|
-
return
|
|
2918
|
+
return path4.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
|
|
2077
2919
|
}
|
|
2078
|
-
function
|
|
2920
|
+
function isRecord6(value) {
|
|
2079
2921
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2080
2922
|
}
|
|
2081
2923
|
function asString(value, fieldName) {
|
|
@@ -2085,7 +2927,7 @@ function asString(value, fieldName) {
|
|
|
2085
2927
|
return value;
|
|
2086
2928
|
}
|
|
2087
2929
|
function parseRecipeDefinition(input) {
|
|
2088
|
-
if (!
|
|
2930
|
+
if (!isRecord6(input)) {
|
|
2089
2931
|
throw new Error("recipe.json must be a JSON object.");
|
|
2090
2932
|
}
|
|
2091
2933
|
if (input.version !== 1) {
|
|
@@ -2093,7 +2935,7 @@ function parseRecipeDefinition(input) {
|
|
|
2093
2935
|
}
|
|
2094
2936
|
const name = asString(input.name, "recipe.name");
|
|
2095
2937
|
assertSafeName("Recipe name", name);
|
|
2096
|
-
if (!
|
|
2938
|
+
if (!isRecord6(input.command)) {
|
|
2097
2939
|
throw new Error("recipe.command must be an object.");
|
|
2098
2940
|
}
|
|
2099
2941
|
const argv = input.command.argv;
|
|
@@ -2101,7 +2943,7 @@ function parseRecipeDefinition(input) {
|
|
|
2101
2943
|
throw new Error("recipe.command.argv must be a non-empty string array.");
|
|
2102
2944
|
}
|
|
2103
2945
|
const variables = Array.isArray(input.variables) ? input.variables.map((item, index) => {
|
|
2104
|
-
if (!
|
|
2946
|
+
if (!isRecord6(item)) {
|
|
2105
2947
|
throw new Error(`recipe.variables[${index}] must be an object.`);
|
|
2106
2948
|
}
|
|
2107
2949
|
const variableName = asString(item.name, `recipe.variables[${index}].name`);
|
|
@@ -2125,7 +2967,7 @@ function parseRecipeDefinition(input) {
|
|
|
2125
2967
|
};
|
|
2126
2968
|
}
|
|
2127
2969
|
async function loadRecipe(recipeDir) {
|
|
2128
|
-
const raw = await
|
|
2970
|
+
const raw = await readFile6(path4.join(recipeDir, "recipe.json"), "utf8");
|
|
2129
2971
|
return parseRecipeDefinition(JSON.parse(raw));
|
|
2130
2972
|
}
|
|
2131
2973
|
async function listRecipes(recipesDir) {
|
|
@@ -2143,7 +2985,7 @@ async function listRecipes(recipesDir) {
|
|
|
2143
2985
|
if (!RECIPE_NAME_PATTERN.test(entry)) {
|
|
2144
2986
|
continue;
|
|
2145
2987
|
}
|
|
2146
|
-
const recipeDir =
|
|
2988
|
+
const recipeDir = path4.join(recipesDir, entry);
|
|
2147
2989
|
try {
|
|
2148
2990
|
const recipe = await loadRecipe(recipeDir);
|
|
2149
2991
|
summaries.push({
|
|
@@ -2177,7 +3019,7 @@ function parseVarsJson(input) {
|
|
|
2177
3019
|
return {};
|
|
2178
3020
|
}
|
|
2179
3021
|
const parsed = JSON.parse(input);
|
|
2180
|
-
if (!
|
|
3022
|
+
if (!isRecord6(parsed)) {
|
|
2181
3023
|
throw new Error("--vars must be a JSON object.");
|
|
2182
3024
|
}
|
|
2183
3025
|
const variables = {};
|
|
@@ -2209,12 +3051,12 @@ function renderTemplate(template, variables) {
|
|
|
2209
3051
|
}
|
|
2210
3052
|
function resolveRecipeFile(recipeDir, token) {
|
|
2211
3053
|
const relative = token.slice(1);
|
|
2212
|
-
if (!relative || relative.includes("..") ||
|
|
3054
|
+
if (!relative || relative.includes("..") || path4.isAbsolute(relative)) {
|
|
2213
3055
|
throw new Error(`Unsafe recipe file reference: ${token}`);
|
|
2214
3056
|
}
|
|
2215
|
-
const resolved =
|
|
2216
|
-
const root =
|
|
2217
|
-
if (resolved !== root && !resolved.startsWith(`${root}${
|
|
3057
|
+
const resolved = path4.resolve(recipeDir, relative);
|
|
3058
|
+
const root = path4.resolve(recipeDir);
|
|
3059
|
+
if (resolved !== root && !resolved.startsWith(`${root}${path4.sep}`)) {
|
|
2218
3060
|
throw new Error(`Recipe file reference escapes recipe directory: ${token}`);
|
|
2219
3061
|
}
|
|
2220
3062
|
return resolved;
|
|
@@ -2224,7 +3066,7 @@ async function renderArgv(options) {
|
|
|
2224
3066
|
const rendered = [];
|
|
2225
3067
|
for (const token of options.recipe.command.argv) {
|
|
2226
3068
|
if (token.startsWith("@")) {
|
|
2227
|
-
const raw = await
|
|
3069
|
+
const raw = await readFile6(resolveRecipeFile(options.recipeDir, token), "utf8");
|
|
2228
3070
|
rendered.push(renderTemplate(raw, options.variables));
|
|
2229
3071
|
} else {
|
|
2230
3072
|
rendered.push(renderTemplate(token, options.variables));
|
|
@@ -2250,7 +3092,7 @@ async function ensureEmptyOrForce(targetDir, force = false) {
|
|
|
2250
3092
|
}
|
|
2251
3093
|
async function writeRecipeScaffold(options) {
|
|
2252
3094
|
await ensureEmptyOrForce(options.location.recipeDir, options.force);
|
|
2253
|
-
await
|
|
3095
|
+
await mkdir4(options.location.recipeDir, { recursive: true });
|
|
2254
3096
|
const title = options.title || options.location.recipeName;
|
|
2255
3097
|
const recipe = {
|
|
2256
3098
|
version: 1,
|
|
@@ -2264,16 +3106,16 @@ async function writeRecipeScaffold(options) {
|
|
|
2264
3106
|
mutating: true
|
|
2265
3107
|
}
|
|
2266
3108
|
};
|
|
2267
|
-
await
|
|
3109
|
+
await writeFile4(path4.join(options.location.recipeDir, "recipe.json"), `${JSON.stringify(recipe, null, 2)}
|
|
2268
3110
|
`, "utf8");
|
|
2269
|
-
await
|
|
2270
|
-
|
|
3111
|
+
await writeFile4(
|
|
3112
|
+
path4.join(options.location.recipeDir, "payload.json"),
|
|
2271
3113
|
`${JSON.stringify({ name: "{{name}}" }, null, 2)}
|
|
2272
3114
|
`,
|
|
2273
3115
|
"utf8"
|
|
2274
3116
|
);
|
|
2275
|
-
await
|
|
2276
|
-
|
|
3117
|
+
await writeFile4(
|
|
3118
|
+
path4.join(options.location.recipeDir, "README.md"),
|
|
2277
3119
|
[`# ${title}`, "", "Describe the BPMAX flow, field mapping, prerequisites, and verification steps for this recipe.", ""].join("\n"),
|
|
2278
3120
|
"utf8"
|
|
2279
3121
|
);
|
|
@@ -2410,8 +3252,14 @@ var schemaEntries = [
|
|
|
2410
3252
|
{ name: "project.list", description: "List projects.", method: "POST", path: "/api/project/list" },
|
|
2411
3253
|
{ name: "project.get", description: "Get project detail.", method: "GET", path: "/api/project/:id" },
|
|
2412
3254
|
{ name: "project.my-step", description: "List my pending steps.", method: "GET", path: "/api/project/my_step" },
|
|
3255
|
+
{ name: "project.approval-context", description: "Get project form values and ended approval step form values.", method: "GET", path: "/api/project/:id + /api/step/:id" },
|
|
2413
3256
|
{ name: "project.create", description: "Create a project with local form schema validation when form payload is provided.", method: "POST", path: "/api/project" },
|
|
2414
|
-
{ name: "step.get", description: "Get step detail.", method: "GET", path: "/api/step/:id" }
|
|
3257
|
+
{ name: "step.get", description: "Get step detail.", method: "GET", path: "/api/step/:id" },
|
|
3258
|
+
{ name: "bbs.list", description: "List BPMAX Business Skills.", method: "GET", path: "/api/business_skill" },
|
|
3259
|
+
{ name: "bbs.create", description: "Create a BPMAX Business Skill from a standard skill zip.", method: "POST", path: "/api/business_skill" },
|
|
3260
|
+
{ name: "bbs.lint", description: "Lint a BPMAX Business Skill package before publish." },
|
|
3261
|
+
{ name: "bbs.gate", description: "Run a BPMAX Business Skill business preflight or verify gate." },
|
|
3262
|
+
{ name: "bbs.ensure", description: "Install or update a BPMAX Business Skill lazily before use." }
|
|
2415
3263
|
];
|
|
2416
3264
|
|
|
2417
3265
|
// src/commands/schema.ts
|
|
@@ -2527,8 +3375,8 @@ function registerStepCommands(program2) {
|
|
|
2527
3375
|
}
|
|
2528
3376
|
|
|
2529
3377
|
// src/core/update.ts
|
|
2530
|
-
import { access as access2, mkdir as
|
|
2531
|
-
import
|
|
3378
|
+
import { access as access2, mkdir as mkdir5, readFile as readFile7, realpath, writeFile as writeFile5 } from "fs/promises";
|
|
3379
|
+
import path5 from "path";
|
|
2532
3380
|
var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/";
|
|
2533
3381
|
var UPDATE_STATE_FILE = "update-state.json";
|
|
2534
3382
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -2640,11 +3488,11 @@ async function fetchLatestVersion(options = {}) {
|
|
|
2640
3488
|
}
|
|
2641
3489
|
}
|
|
2642
3490
|
function updateStatePath(configDir = getConfigDir()) {
|
|
2643
|
-
return
|
|
3491
|
+
return path5.join(configDir, UPDATE_STATE_FILE);
|
|
2644
3492
|
}
|
|
2645
3493
|
async function readUpdateState(configDir) {
|
|
2646
3494
|
try {
|
|
2647
|
-
const raw = await
|
|
3495
|
+
const raw = await readFile7(updateStatePath(configDir), "utf8");
|
|
2648
3496
|
const parsed = JSON.parse(raw);
|
|
2649
3497
|
if (typeof parsed.latest_version !== "string" || typeof parsed.checked_at !== "number") {
|
|
2650
3498
|
return null;
|
|
@@ -2655,8 +3503,8 @@ async function readUpdateState(configDir) {
|
|
|
2655
3503
|
}
|
|
2656
3504
|
}
|
|
2657
3505
|
async function writeUpdateState(state, configDir = getConfigDir()) {
|
|
2658
|
-
await
|
|
2659
|
-
await
|
|
3506
|
+
await mkdir5(configDir, { recursive: true });
|
|
3507
|
+
await writeFile5(updateStatePath(configDir), JSON.stringify(state), "utf8");
|
|
2660
3508
|
}
|
|
2661
3509
|
async function checkCachedUpdate(currentVersion, configDir = getConfigDir()) {
|
|
2662
3510
|
if (process.env.BPMAX_CLI_NO_UPDATE_NOTIFIER) {
|
|
@@ -2708,7 +3556,7 @@ async function findNpmPath() {
|
|
|
2708
3556
|
}
|
|
2709
3557
|
function detectInstallMethod(input) {
|
|
2710
3558
|
const resolvedPath = input.executablePath || "";
|
|
2711
|
-
const method = resolvedPath.includes(`node_modules${
|
|
3559
|
+
const method = resolvedPath.includes(`node_modules${path5.sep}`) || resolvedPath.includes("node_modules/") ? "npm" : "manual";
|
|
2712
3560
|
return {
|
|
2713
3561
|
method,
|
|
2714
3562
|
resolvedPath,
|
|
@@ -3029,6 +3877,7 @@ var program = new Command();
|
|
|
3029
3877
|
program.name(CLI_NAME).description("BPMAX multi-environment CLI").version(VERSION);
|
|
3030
3878
|
registerConfigCommands(program);
|
|
3031
3879
|
registerAuthCommands(program);
|
|
3880
|
+
registerBbsCommands(program);
|
|
3032
3881
|
registerApiCommands(program);
|
|
3033
3882
|
registerSchemaCommands(program);
|
|
3034
3883
|
registerUserCommands(program);
|