bpmax-cli 0.1.27 → 0.1.29
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 +1233 -346
- 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 +2 -0
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.29",
|
|
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");
|
|
@@ -790,70 +1710,50 @@ function registerFlowCommands(program2) {
|
|
|
790
1710
|
params: options.name ? { name: options.name } : void 0
|
|
791
1711
|
}
|
|
792
1712
|
);
|
|
793
|
-
printResult(options.format, result);
|
|
794
|
-
});
|
|
795
|
-
flow.command("get").description("Get flow detail by id").
|
|
796
|
-
const config = await loadConfig();
|
|
797
|
-
const profile = resolveProfile(config, options.profile);
|
|
798
|
-
const
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
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";
|
|
1713
|
+
printResult(options.format, result);
|
|
1714
|
+
});
|
|
1715
|
+
flow.command("get").description("Get flow detail by id or flow_type/flow_key").option("--id <id>", "Flow id").option("--flow-type <flowType>", "Flow type").option("--flow-key <flowKey>", "Flow key", "").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
1716
|
+
const config = await loadConfig();
|
|
1717
|
+
const profile = resolveProfile(config, options.profile);
|
|
1718
|
+
const client = createApiClient(profile);
|
|
1719
|
+
if (options.flowType) {
|
|
1720
|
+
const result2 = await apiRequest(
|
|
1721
|
+
client,
|
|
1722
|
+
"GET",
|
|
1723
|
+
"/flow/flow_type",
|
|
1724
|
+
{
|
|
1725
|
+
params: {
|
|
1726
|
+
draft: "1",
|
|
1727
|
+
skip_i18n: "true"
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
);
|
|
1731
|
+
printResult(
|
|
1732
|
+
options.format,
|
|
1733
|
+
result2.find((item) => item.flow_type === options.flowType && String(item.key || "") === options.flowKey) ?? null
|
|
1734
|
+
);
|
|
1735
|
+
return;
|
|
1736
|
+
}
|
|
1737
|
+
if (!options.id) {
|
|
1738
|
+
throw new Error("Either --id or --flow-type is required.");
|
|
1739
|
+
}
|
|
1740
|
+
const id = Number(options.id);
|
|
1741
|
+
if (!Number.isInteger(id)) {
|
|
1742
|
+
throw new Error("--id must be a numeric flow id. Use --flow-type for values like flow322497069.");
|
|
1743
|
+
}
|
|
1744
|
+
const result = await apiRequest(
|
|
1745
|
+
client,
|
|
1746
|
+
"POST",
|
|
1747
|
+
"/flow/batch_get",
|
|
1748
|
+
{
|
|
1749
|
+
data: {
|
|
1750
|
+
ids: [id]
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
);
|
|
1754
|
+
printResult(options.format, result[0] ?? null);
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
857
1757
|
|
|
858
1758
|
// src/core/setup.ts
|
|
859
1759
|
function parseBpmUrl(input) {
|
|
@@ -932,80 +1832,27 @@ function setupSummary(input) {
|
|
|
932
1832
|
}
|
|
933
1833
|
|
|
934
1834
|
// src/core/skills.ts
|
|
935
|
-
import { mkdir as
|
|
936
|
-
import
|
|
1835
|
+
import { mkdir as mkdir3, readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
|
|
1836
|
+
import path3 from "path";
|
|
937
1837
|
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
1838
|
var SKILLS_STAMP_FILE = "skills.stamp";
|
|
992
1839
|
var SKILLS_INSTALL_TIMEOUT_MS = 2 * 60 * 1e3;
|
|
993
1840
|
function skillsStampValue(version, agent) {
|
|
994
1841
|
return agent ? `${version}:${agent}` : version;
|
|
995
1842
|
}
|
|
996
1843
|
function stampPath(configDir = getConfigDir()) {
|
|
997
|
-
return
|
|
1844
|
+
return path3.join(configDir, SKILLS_STAMP_FILE);
|
|
998
1845
|
}
|
|
999
1846
|
async function readSkillsStamp(configDir = getConfigDir()) {
|
|
1000
1847
|
try {
|
|
1001
|
-
return (await
|
|
1848
|
+
return (await readFile5(stampPath(configDir), "utf8")).trim();
|
|
1002
1849
|
} catch {
|
|
1003
1850
|
return "";
|
|
1004
1851
|
}
|
|
1005
1852
|
}
|
|
1006
1853
|
async function writeSkillsStamp(version, configDir = getConfigDir(), agent) {
|
|
1007
|
-
await
|
|
1008
|
-
await
|
|
1854
|
+
await mkdir3(configDir, { recursive: true });
|
|
1855
|
+
await writeFile3(stampPath(configDir), skillsStampValue(version, agent), "utf8");
|
|
1009
1856
|
}
|
|
1010
1857
|
async function checkSkillsSync(currentVersion, configDir = getConfigDir(), agent) {
|
|
1011
1858
|
const target = skillsStampValue(currentVersion, agent);
|
|
@@ -1015,12 +1862,23 @@ async function checkSkillsSync(currentVersion, configDir = getConfigDir(), agent
|
|
|
1015
1862
|
const current = await readSkillsStamp(configDir);
|
|
1016
1863
|
return { current, target, inSync: current === target };
|
|
1017
1864
|
}
|
|
1018
|
-
function
|
|
1019
|
-
|
|
1865
|
+
async function resolvePackageRootFrom(entrypointPath) {
|
|
1866
|
+
const entryDir = path3.dirname(entrypointPath);
|
|
1867
|
+
if (path3.basename(entryDir) === "dist") {
|
|
1868
|
+
return path3.dirname(entryDir);
|
|
1869
|
+
}
|
|
1870
|
+
if (path3.basename(entryDir) === "core" && path3.basename(path3.dirname(entryDir)) === "src") {
|
|
1871
|
+
return path3.dirname(path3.dirname(entryDir));
|
|
1872
|
+
}
|
|
1873
|
+
return path3.resolve(entryDir, "..", "..");
|
|
1874
|
+
}
|
|
1875
|
+
async function defaultPackageRoot() {
|
|
1876
|
+
return resolvePackageRootFrom(fileURLToPath(import.meta.url));
|
|
1020
1877
|
}
|
|
1021
1878
|
async function runSkillsInstall(options = {}) {
|
|
1022
1879
|
const runner = options.runner || runCommand;
|
|
1023
|
-
const
|
|
1880
|
+
const packageRoot = options.packageRoot || await defaultPackageRoot();
|
|
1881
|
+
const args = [path3.join(packageRoot, "scripts", "install-skills.mjs")];
|
|
1024
1882
|
if (options.agent) {
|
|
1025
1883
|
args.push("--json", "--agent", options.agent);
|
|
1026
1884
|
}
|
|
@@ -1115,8 +1973,8 @@ var FIELD_KEY_NAMES = [
|
|
|
1115
1973
|
var FIELD_LABEL_NAMES = ["label", "title", "display_name", "displayName", "text"];
|
|
1116
1974
|
var FIELD_TYPE_NAMES = ["type", "field_type", "fieldType", "value_type", "valueType", "control", "component", "widget"];
|
|
1117
1975
|
var OPTION_NAMES = ["options", "items", "choices", "values"];
|
|
1118
|
-
var REQUIRED_NAMES = ["required", "is_required", "isRequired", "require", "must"];
|
|
1119
|
-
function
|
|
1976
|
+
var REQUIRED_NAMES = ["required", "is_required", "isRequired", "require", "must", "validateRequired"];
|
|
1977
|
+
function isRecord3(value) {
|
|
1120
1978
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1121
1979
|
}
|
|
1122
1980
|
function pickString(source, keys) {
|
|
@@ -1143,7 +2001,7 @@ function pickBoolean(source, keys) {
|
|
|
1143
2001
|
}
|
|
1144
2002
|
const rules = source.rules;
|
|
1145
2003
|
if (Array.isArray(rules)) {
|
|
1146
|
-
return rules.some((rule) =>
|
|
2004
|
+
return rules.some((rule) => isRecord3(rule) && pickBoolean(rule, REQUIRED_NAMES));
|
|
1147
2005
|
}
|
|
1148
2006
|
return false;
|
|
1149
2007
|
}
|
|
@@ -1151,7 +2009,7 @@ function optionValue(option) {
|
|
|
1151
2009
|
if (typeof option === "string" || typeof option === "number") {
|
|
1152
2010
|
return String(option);
|
|
1153
2011
|
}
|
|
1154
|
-
if (!
|
|
2012
|
+
if (!isRecord3(option)) {
|
|
1155
2013
|
return null;
|
|
1156
2014
|
}
|
|
1157
2015
|
return pickString(option, ["value", "key", "id", "name", "label", "title"]) ?? null;
|
|
@@ -1198,6 +2056,7 @@ function mergeField(existing, incoming) {
|
|
|
1198
2056
|
return {
|
|
1199
2057
|
...existing,
|
|
1200
2058
|
...incoming,
|
|
2059
|
+
required: Boolean(existing?.required || incoming.required),
|
|
1201
2060
|
...children?.length ? { children } : {}
|
|
1202
2061
|
};
|
|
1203
2062
|
}
|
|
@@ -1211,7 +2070,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
1211
2070
|
}
|
|
1212
2071
|
return;
|
|
1213
2072
|
}
|
|
1214
|
-
if (!
|
|
2073
|
+
if (!isRecord3(value)) {
|
|
1215
2074
|
return;
|
|
1216
2075
|
}
|
|
1217
2076
|
const field = fieldFromRecord(value);
|
|
@@ -1219,7 +2078,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
1219
2078
|
if (isSubFormField(field)) {
|
|
1220
2079
|
const childFields = /* @__PURE__ */ new Map();
|
|
1221
2080
|
for (const child of Object.values(value)) {
|
|
1222
|
-
if (
|
|
2081
|
+
if (isRecord3(child) || Array.isArray(child)) {
|
|
1223
2082
|
collectFieldCandidates(child, childFields, depth + 1);
|
|
1224
2083
|
}
|
|
1225
2084
|
}
|
|
@@ -1233,7 +2092,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
1233
2092
|
fields.set(field.key, mergeField(fields.get(field.key), field));
|
|
1234
2093
|
}
|
|
1235
2094
|
for (const child of Object.values(value)) {
|
|
1236
|
-
if (
|
|
2095
|
+
if (isRecord3(child) || Array.isArray(child)) {
|
|
1237
2096
|
collectFieldCandidates(child, fields, depth + 1);
|
|
1238
2097
|
}
|
|
1239
2098
|
}
|
|
@@ -1248,10 +2107,10 @@ function isEmpty(value) {
|
|
|
1248
2107
|
}
|
|
1249
2108
|
function validateComplexSelector(field, value) {
|
|
1250
2109
|
const type = field.type?.toLowerCase() ?? "";
|
|
1251
|
-
if (
|
|
2110
|
+
if (!isComplexSelectorType(type)) {
|
|
1252
2111
|
return null;
|
|
1253
2112
|
}
|
|
1254
|
-
const validObject = (item) =>
|
|
2113
|
+
const validObject = (item) => isRecord3(item);
|
|
1255
2114
|
if (Array.isArray(value)) {
|
|
1256
2115
|
return value.every(validObject) ? null : `${field.key} must contain selector option object(s), not scalar values`;
|
|
1257
2116
|
}
|
|
@@ -1260,6 +2119,9 @@ function validateComplexSelector(field, value) {
|
|
|
1260
2119
|
}
|
|
1261
2120
|
return `${field.key} must be a selector option object or array of option objects, not a scalar value`;
|
|
1262
2121
|
}
|
|
2122
|
+
function isComplexSelectorType(type) {
|
|
2123
|
+
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);
|
|
2124
|
+
}
|
|
1263
2125
|
function validateType(field, value) {
|
|
1264
2126
|
const type = field.type?.toLowerCase() ?? "";
|
|
1265
2127
|
if (!type || isEmpty(value)) {
|
|
@@ -1269,13 +2131,16 @@ function validateType(field, value) {
|
|
|
1269
2131
|
if (!Array.isArray(value)) {
|
|
1270
2132
|
return `${field.key} must be a JSON array of row objects`;
|
|
1271
2133
|
}
|
|
1272
|
-
const invalidRowIndex = value.findIndex((row) => !
|
|
2134
|
+
const invalidRowIndex = value.findIndex((row) => !isRecord3(row));
|
|
1273
2135
|
return invalidRowIndex >= 0 ? `${field.key}[${invalidRowIndex}] must be a row object` : null;
|
|
1274
2136
|
}
|
|
1275
2137
|
const selectorError = validateComplexSelector(field, value);
|
|
1276
2138
|
if (selectorError) {
|
|
1277
2139
|
return selectorError;
|
|
1278
2140
|
}
|
|
2141
|
+
if (isComplexSelectorType(type)) {
|
|
2142
|
+
return null;
|
|
2143
|
+
}
|
|
1279
2144
|
if (field.options) {
|
|
1280
2145
|
const values = Array.isArray(value) ? value.map(String) : [String(value)];
|
|
1281
2146
|
const invalid = values.filter((item) => !field.options?.includes(item));
|
|
@@ -1318,7 +2183,7 @@ function validateFormEntries(form, fields, prefix = "") {
|
|
|
1318
2183
|
}
|
|
1319
2184
|
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
1320
2185
|
for (const [index, row] of value.entries()) {
|
|
1321
|
-
if (
|
|
2186
|
+
if (isRecord3(row)) {
|
|
1322
2187
|
errors.push(...validateFormEntries(row, field.children, `${prefix}${field.key}[${index}].`));
|
|
1323
2188
|
}
|
|
1324
2189
|
}
|
|
@@ -1488,8 +2353,9 @@ async function promptAction(message, allowFormHandoff) {
|
|
|
1488
2353
|
}
|
|
1489
2354
|
async function promptProjectCreateForm(input) {
|
|
1490
2355
|
const allowFormHandoff = input.allowFormHandoff === true;
|
|
2356
|
+
const requireName = input.requireName !== false;
|
|
1491
2357
|
let name = input.name;
|
|
1492
|
-
if (!name?.trim()) {
|
|
2358
|
+
if (requireName && !name?.trim()) {
|
|
1493
2359
|
const value = await text2({
|
|
1494
2360
|
message: "\u6D41\u7A0B\u5355\u6807\u9898 *",
|
|
1495
2361
|
validate(candidate) {
|
|
@@ -1501,6 +2367,7 @@ async function promptProjectCreateForm(input) {
|
|
|
1501
2367
|
cancelIfNeeded(value);
|
|
1502
2368
|
name = String(value).trim();
|
|
1503
2369
|
}
|
|
2370
|
+
name = name ?? "";
|
|
1504
2371
|
const form = { ...input.form };
|
|
1505
2372
|
const requiredFields = input.fields.filter((field) => field.required);
|
|
1506
2373
|
const optionalFields = input.fields.filter((field) => !field.required);
|
|
@@ -1539,15 +2406,15 @@ async function promptProjectCreateForm(input) {
|
|
|
1539
2406
|
}
|
|
1540
2407
|
|
|
1541
2408
|
// src/core/project-form.ts
|
|
1542
|
-
function
|
|
2409
|
+
function isRecord4(value) {
|
|
1543
2410
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1544
2411
|
}
|
|
1545
2412
|
function clone(value) {
|
|
1546
2413
|
return JSON.parse(JSON.stringify(value));
|
|
1547
2414
|
}
|
|
1548
2415
|
function getFlowFormTemplateId(flowDetail) {
|
|
1549
|
-
const data =
|
|
1550
|
-
const meta =
|
|
2416
|
+
const data = isRecord4(flowDetail?.data) ? flowDetail.data : void 0;
|
|
2417
|
+
const meta = isRecord4(data?.meta) ? data.meta : void 0;
|
|
1551
2418
|
const templateId = meta?.form_template;
|
|
1552
2419
|
if (typeof templateId === "number" && Number.isFinite(templateId)) {
|
|
1553
2420
|
return templateId;
|
|
@@ -1570,7 +2437,7 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
1570
2437
|
if (Array.isArray(value)) {
|
|
1571
2438
|
return value.some((item) => hasAutoInitLambda(item, seen));
|
|
1572
2439
|
}
|
|
1573
|
-
if (!
|
|
2440
|
+
if (!isRecord4(value)) {
|
|
1574
2441
|
return false;
|
|
1575
2442
|
}
|
|
1576
2443
|
if (seen.has(value)) {
|
|
@@ -1585,14 +2452,14 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
1585
2452
|
function setControlValue(control, value) {
|
|
1586
2453
|
const next = clone(control);
|
|
1587
2454
|
next.value = {
|
|
1588
|
-
...
|
|
2455
|
+
...isRecord4(next.value) ? next.value : {},
|
|
1589
2456
|
type: next.value?.type ?? next.field_type,
|
|
1590
2457
|
value
|
|
1591
2458
|
};
|
|
1592
2459
|
return next;
|
|
1593
2460
|
}
|
|
1594
2461
|
function applyRowValues(rowTemplate, rowValue) {
|
|
1595
|
-
const source =
|
|
2462
|
+
const source = isRecord4(rowValue) ? rowValue : {};
|
|
1596
2463
|
return rowTemplate.map((control) => {
|
|
1597
2464
|
if (control.key && Object.prototype.hasOwnProperty.call(source, control.key)) {
|
|
1598
2465
|
return setControlValue(control, source[control.key]);
|
|
@@ -1630,121 +2497,6 @@ async function buildProjectFormPayload(client, flowDetail, form, knownTemplate)
|
|
|
1630
2497
|
};
|
|
1631
2498
|
}
|
|
1632
2499
|
|
|
1633
|
-
// src/core/urls.ts
|
|
1634
|
-
function stripSlashes(value) {
|
|
1635
|
-
return value.trim().replace(/^\/+|\/+$/g, "");
|
|
1636
|
-
}
|
|
1637
|
-
function isRecord4(value) {
|
|
1638
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1639
|
-
}
|
|
1640
|
-
function normalizeWorkspaceForUrl(workspace) {
|
|
1641
|
-
const nextWorkspace = stripSlashes(workspace);
|
|
1642
|
-
if (!nextWorkspace) {
|
|
1643
|
-
throw new Error("Workspace is required to build a BPMAX URL.");
|
|
1644
|
-
}
|
|
1645
|
-
if (nextWorkspace === "default" || nextWorkspace.startsWith("w:")) {
|
|
1646
|
-
return nextWorkspace;
|
|
1647
|
-
}
|
|
1648
|
-
return `w:${nextWorkspace}`;
|
|
1649
|
-
}
|
|
1650
|
-
function normalizeOrigin2(origin) {
|
|
1651
|
-
const nextOrigin = origin.trim().replace(/\/+$/, "");
|
|
1652
|
-
if (!nextOrigin) {
|
|
1653
|
-
throw new Error("Origin is required to build a BPMAX URL.");
|
|
1654
|
-
}
|
|
1655
|
-
return nextOrigin;
|
|
1656
|
-
}
|
|
1657
|
-
function requireNumericId(value, name) {
|
|
1658
|
-
const nextValue = String(value || "").trim();
|
|
1659
|
-
if (!/^\d+$/.test(nextValue)) {
|
|
1660
|
-
throw new Error(`${name} must be a non-empty numeric string.`);
|
|
1661
|
-
}
|
|
1662
|
-
return nextValue;
|
|
1663
|
-
}
|
|
1664
|
-
function withQuery(path5, query) {
|
|
1665
|
-
const params = new URLSearchParams();
|
|
1666
|
-
for (const [key, value] of Object.entries(query)) {
|
|
1667
|
-
if (value !== void 0) {
|
|
1668
|
-
params.set(key, value);
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
return `${path5}?${params.toString()}`;
|
|
1672
|
-
}
|
|
1673
|
-
function buildBpmaxUrl(profile, kind, params = {}) {
|
|
1674
|
-
const origin = normalizeOrigin2(profile.config.origin);
|
|
1675
|
-
const workspace = normalizeWorkspaceForUrl(params.workspace || profile.config.workspace);
|
|
1676
|
-
const basePath = `/${workspace}`;
|
|
1677
|
-
let path5 = basePath;
|
|
1678
|
-
const result = {
|
|
1679
|
-
kind,
|
|
1680
|
-
profile: profile.name,
|
|
1681
|
-
origin,
|
|
1682
|
-
workspace
|
|
1683
|
-
};
|
|
1684
|
-
if (kind === "project-list") {
|
|
1685
|
-
path5 = `${basePath}/project`;
|
|
1686
|
-
} else if (kind === "project-detail") {
|
|
1687
|
-
const projectId = requireNumericId(params.projectId, "projectId");
|
|
1688
|
-
path5 = `${basePath}/project_detail/0/${projectId}`;
|
|
1689
|
-
result.project_id = projectId;
|
|
1690
|
-
} else if (kind === "project-step") {
|
|
1691
|
-
const projectId = requireNumericId(params.projectId, "projectId");
|
|
1692
|
-
const stepId = requireNumericId(params.stepId, "stepId");
|
|
1693
|
-
path5 = withQuery(`${basePath}/projectContinue`, {
|
|
1694
|
-
id: projectId,
|
|
1695
|
-
step_id: stepId
|
|
1696
|
-
});
|
|
1697
|
-
result.project_id = projectId;
|
|
1698
|
-
result.step_id = stepId;
|
|
1699
|
-
} else if (kind === "project-create") {
|
|
1700
|
-
const flowType = params.flowType || "default";
|
|
1701
|
-
const flowKey = params.flowKey || "";
|
|
1702
|
-
const initValue = params.initValue ? JSON.stringify(params.initValue) : void 0;
|
|
1703
|
-
const query = {
|
|
1704
|
-
flow_type: flowType,
|
|
1705
|
-
flow_key: flowKey,
|
|
1706
|
-
...flowKey ? { key: flowKey } : {},
|
|
1707
|
-
init_value: initValue
|
|
1708
|
-
};
|
|
1709
|
-
path5 = withQuery(`${basePath}/project/create`, query);
|
|
1710
|
-
result.flow_type = flowType;
|
|
1711
|
-
result.flow_key = flowKey;
|
|
1712
|
-
result.mobile_path = withQuery("/pages/projectCreate/projectCreate", query);
|
|
1713
|
-
}
|
|
1714
|
-
const url = `${origin}${path5}`;
|
|
1715
|
-
return {
|
|
1716
|
-
...result,
|
|
1717
|
-
path: path5,
|
|
1718
|
-
url,
|
|
1719
|
-
...kind === "project-create" ? { pc_url: url } : {}
|
|
1720
|
-
};
|
|
1721
|
-
}
|
|
1722
|
-
function extractProjectId(value) {
|
|
1723
|
-
if (!isRecord4(value)) {
|
|
1724
|
-
return void 0;
|
|
1725
|
-
}
|
|
1726
|
-
const candidates = [value.id, value.project_id, value.projectId];
|
|
1727
|
-
const candidate = candidates.find((item) => item !== void 0 && item !== null);
|
|
1728
|
-
if (candidate === void 0) {
|
|
1729
|
-
return void 0;
|
|
1730
|
-
}
|
|
1731
|
-
const projectId = String(candidate).trim();
|
|
1732
|
-
return /^\d+$/.test(projectId) ? projectId : void 0;
|
|
1733
|
-
}
|
|
1734
|
-
function attachProjectDetailUrl(profile, value) {
|
|
1735
|
-
if (!isRecord4(value) || typeof value.url === "string") {
|
|
1736
|
-
return value;
|
|
1737
|
-
}
|
|
1738
|
-
const projectId = extractProjectId(value);
|
|
1739
|
-
if (!projectId) {
|
|
1740
|
-
return value;
|
|
1741
|
-
}
|
|
1742
|
-
return {
|
|
1743
|
-
...value,
|
|
1744
|
-
url: buildBpmaxUrl(profile, "project-detail", { projectId }).url
|
|
1745
|
-
};
|
|
1746
|
-
}
|
|
1747
|
-
|
|
1748
2500
|
// src/commands/project.ts
|
|
1749
2501
|
function parseJson2(input) {
|
|
1750
2502
|
if (!input) {
|
|
@@ -1752,11 +2504,34 @@ function parseJson2(input) {
|
|
|
1752
2504
|
}
|
|
1753
2505
|
return JSON.parse(input);
|
|
1754
2506
|
}
|
|
1755
|
-
async function resolveFlowIdentifiers(client, options) {
|
|
1756
|
-
if (options.flowType
|
|
2507
|
+
async function resolveFlowIdentifiers(client, options, resolveOptions = {}) {
|
|
2508
|
+
if (options.flowType) {
|
|
2509
|
+
const flowKey = options.flowKey ?? "";
|
|
2510
|
+
if (resolveOptions.loadDetail) {
|
|
2511
|
+
const flows2 = await apiRequest(
|
|
2512
|
+
client,
|
|
2513
|
+
"GET",
|
|
2514
|
+
"/flow/flow_type",
|
|
2515
|
+
{
|
|
2516
|
+
params: {
|
|
2517
|
+
draft: "1",
|
|
2518
|
+
skip_i18n: "true"
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
);
|
|
2522
|
+
const flow2 = flows2.find((item) => item.flow_type === options.flowType && String(item.key || "") === flowKey);
|
|
2523
|
+
if (!flow2) {
|
|
2524
|
+
throw new Error(`Flow ${options.flowType}:${flowKey} not found.`);
|
|
2525
|
+
}
|
|
2526
|
+
return {
|
|
2527
|
+
flow_type: options.flowType,
|
|
2528
|
+
flow_key: flowKey,
|
|
2529
|
+
flowDetail: flow2
|
|
2530
|
+
};
|
|
2531
|
+
}
|
|
1757
2532
|
return {
|
|
1758
2533
|
flow_type: options.flowType,
|
|
1759
|
-
flow_key:
|
|
2534
|
+
flow_key: flowKey
|
|
1760
2535
|
};
|
|
1761
2536
|
}
|
|
1762
2537
|
if (!options.flowId) {
|
|
@@ -1796,12 +2571,11 @@ async function validateCreateForm(client, options) {
|
|
|
1796
2571
|
);
|
|
1797
2572
|
flowDetail = flows[0];
|
|
1798
2573
|
}
|
|
1799
|
-
const
|
|
1800
|
-
if (
|
|
1801
|
-
const
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
const templateFields = extractFormFields(template);
|
|
2574
|
+
const templateId = getFlowFormTemplateId(flowDetail);
|
|
2575
|
+
if (options.projectFormTemplate || templateId) {
|
|
2576
|
+
const template = options.projectFormTemplate?.template ?? (templateId ? await apiRequest(client, "GET", `/form_template/${templateId}`) : void 0);
|
|
2577
|
+
const templateFields = extractFormFields(template);
|
|
2578
|
+
if (templateFields.length > 0) {
|
|
1805
2579
|
const result2 = validateFormAgainstFields(options.form, templateFields);
|
|
1806
2580
|
if (result2.errors.length > 0) {
|
|
1807
2581
|
throw new Error(`Form validation failed:
|
|
@@ -1810,6 +2584,15 @@ async function validateCreateForm(client, options) {
|
|
|
1810
2584
|
return;
|
|
1811
2585
|
}
|
|
1812
2586
|
}
|
|
2587
|
+
const fields = extractFormFields(flowDetail);
|
|
2588
|
+
if (fields.length > 0) {
|
|
2589
|
+
const result2 = validateFormAgainstFields(options.form, fields);
|
|
2590
|
+
if (result2.errors.length > 0) {
|
|
2591
|
+
throw new Error(`Form validation failed:
|
|
2592
|
+
- ${result2.errors.join("\n- ")}`);
|
|
2593
|
+
}
|
|
2594
|
+
return;
|
|
2595
|
+
}
|
|
1813
2596
|
if (fields.length === 0) {
|
|
1814
2597
|
throw new Error(
|
|
1815
2598
|
[
|
|
@@ -1882,7 +2665,20 @@ function assertCreateFormHandoffUrl(url, expectedInitValue, expectedFormKeys) {
|
|
|
1882
2665
|
}
|
|
1883
2666
|
function fieldsForValidation(flowDetail, projectFormTemplate) {
|
|
1884
2667
|
const templateFields = projectFormTemplate ? extractFormFields(projectFormTemplate.template) : [];
|
|
1885
|
-
|
|
2668
|
+
if (templateFields.length === 0) {
|
|
2669
|
+
return extractFormFields(flowDetail);
|
|
2670
|
+
}
|
|
2671
|
+
const flowFieldsByKey = new Map(extractFormFields(flowDetail).map((field) => [field.key, field]));
|
|
2672
|
+
return templateFields.map((field) => ({
|
|
2673
|
+
...field,
|
|
2674
|
+
required: field.required || flowFieldsByKey.get(field.key)?.required === true
|
|
2675
|
+
}));
|
|
2676
|
+
}
|
|
2677
|
+
function metaUsesTemplateProjectName(flowDetail) {
|
|
2678
|
+
const data = isRecord5(flowDetail?.data) ? flowDetail.data : void 0;
|
|
2679
|
+
const meta = isRecord5(data?.meta) ? data.meta : void 0;
|
|
2680
|
+
const hideFields = Array.isArray(meta?.hide_fields) ? meta.hide_fields.map(String) : [];
|
|
2681
|
+
return meta?.use_template_project_name === true || hideFields.includes("project.name");
|
|
1886
2682
|
}
|
|
1887
2683
|
function formValidationErrors(fields, form) {
|
|
1888
2684
|
return validateFormAgainstFields(form, fields).errors;
|
|
@@ -1899,6 +2695,78 @@ function assertHandoffFormReady(fields, form) {
|
|
|
1899
2695
|
);
|
|
1900
2696
|
}
|
|
1901
2697
|
}
|
|
2698
|
+
function isRecord5(value) {
|
|
2699
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2700
|
+
}
|
|
2701
|
+
function isEndedStep(step) {
|
|
2702
|
+
if (step.real_end_time) {
|
|
2703
|
+
return true;
|
|
2704
|
+
}
|
|
2705
|
+
if (step.status === "finished" || step.status === "done" || step.status === "completed") {
|
|
2706
|
+
return true;
|
|
2707
|
+
}
|
|
2708
|
+
return typeof step.status === "number" && [3, 4, 5].includes(step.status);
|
|
2709
|
+
}
|
|
2710
|
+
function stepIdOf(step) {
|
|
2711
|
+
const id = step.id;
|
|
2712
|
+
if (typeof id === "number" || typeof id === "string") {
|
|
2713
|
+
const value = String(id);
|
|
2714
|
+
return value ? value : void 0;
|
|
2715
|
+
}
|
|
2716
|
+
return void 0;
|
|
2717
|
+
}
|
|
2718
|
+
function pickStepFormPayload(step) {
|
|
2719
|
+
const formList = Array.isArray(step.formList) ? step.formList : [];
|
|
2720
|
+
const forms = Array.isArray(step.forms) ? step.forms : [];
|
|
2721
|
+
const metaForm = isRecord5(step.metaForm) ? step.metaForm : void 0;
|
|
2722
|
+
return {
|
|
2723
|
+
step_id: step.id,
|
|
2724
|
+
flow_step_id: step.flow_step_id,
|
|
2725
|
+
name: step.name,
|
|
2726
|
+
status: step.status,
|
|
2727
|
+
real_start_time: step.real_start_time,
|
|
2728
|
+
real_end_time: step.real_end_time,
|
|
2729
|
+
form_template_id: step.form_template_id,
|
|
2730
|
+
formList,
|
|
2731
|
+
forms,
|
|
2732
|
+
...metaForm ? { metaForm } : {},
|
|
2733
|
+
has_form_values: formList.length > 0 || forms.length > 0 || Boolean(metaForm)
|
|
2734
|
+
};
|
|
2735
|
+
}
|
|
2736
|
+
async function buildApprovalContext(client, projectId, options) {
|
|
2737
|
+
const projectDetail = await apiRequest(client, "GET", `/project/${projectId}`);
|
|
2738
|
+
const steps = Array.isArray(projectDetail.steps) ? projectDetail.steps.filter(isRecord5) : [];
|
|
2739
|
+
const targetStepIds = /* @__PURE__ */ new Set();
|
|
2740
|
+
for (const step of steps) {
|
|
2741
|
+
const id = stepIdOf(step);
|
|
2742
|
+
if (id && isEndedStep(step)) {
|
|
2743
|
+
targetStepIds.add(id);
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
if (options.stepId) {
|
|
2747
|
+
targetStepIds.add(options.stepId);
|
|
2748
|
+
}
|
|
2749
|
+
const stepForms = [];
|
|
2750
|
+
const failedSteps = [];
|
|
2751
|
+
for (const stepId of targetStepIds) {
|
|
2752
|
+
try {
|
|
2753
|
+
const stepDetail = await apiRequest(client, "GET", `/step/${stepId}`);
|
|
2754
|
+
stepForms.push(pickStepFormPayload(stepDetail));
|
|
2755
|
+
} catch (error) {
|
|
2756
|
+
failedSteps.push({
|
|
2757
|
+
step_id: stepId,
|
|
2758
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2759
|
+
});
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
return {
|
|
2763
|
+
project: projectDetail,
|
|
2764
|
+
project_form: isRecord5(projectDetail.metaForm) ? projectDetail.metaForm : null,
|
|
2765
|
+
inspected_step_count: stepForms.length,
|
|
2766
|
+
step_forms: stepForms,
|
|
2767
|
+
failed_steps: failedSteps
|
|
2768
|
+
};
|
|
2769
|
+
}
|
|
1902
2770
|
function registerProjectCommands(program2) {
|
|
1903
2771
|
const project = program2.command("project").description("Project commands");
|
|
1904
2772
|
project.command("list").description("List projects").option("--profile <profile>", "Profile name").option("--page <page>", "Page number", "1").option("--page-size <pageSize>", "Page size", "20").option("--body <json>", "Project list body JSON", "{}").option("--format <format>", "Output format", "table").action(async (options) => {
|
|
@@ -1959,7 +2827,17 @@ function registerProjectCommands(program2) {
|
|
|
1959
2827
|
);
|
|
1960
2828
|
printResult(options.format, result);
|
|
1961
2829
|
});
|
|
1962
|
-
project.command("
|
|
2830
|
+
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) => {
|
|
2831
|
+
const config = await loadConfig();
|
|
2832
|
+
const profile = resolveProfile(config, options.profile);
|
|
2833
|
+
const client = createApiClient(profile);
|
|
2834
|
+
const context = await buildApprovalContext(client, projectId, { stepId: options.stepId });
|
|
2835
|
+
printResult(options.format, {
|
|
2836
|
+
...context,
|
|
2837
|
+
project: attachProjectDetailUrl(profile, context.project)
|
|
2838
|
+
});
|
|
2839
|
+
});
|
|
2840
|
+
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) => {
|
|
1963
2841
|
const interactiveSource = command.getOptionValueSource("interactive");
|
|
1964
2842
|
if (options.body && options.interactive === true && interactiveSource === "cli") {
|
|
1965
2843
|
throw new Error("--body and --interactive cannot be used together.");
|
|
@@ -1970,7 +2848,7 @@ function registerProjectCommands(program2) {
|
|
|
1970
2848
|
const useInteractive = !options.body && options.interactive !== false;
|
|
1971
2849
|
let payload = parseJson2(options.body);
|
|
1972
2850
|
if (!options.body) {
|
|
1973
|
-
const flow = await resolveFlowIdentifiers(client, options);
|
|
2851
|
+
const flow = await resolveFlowIdentifiers(client, options, { loadDetail: useInteractive });
|
|
1974
2852
|
const { flowDetail, ...flowIdentifiers } = flow;
|
|
1975
2853
|
const extra = parseJson2(options.json);
|
|
1976
2854
|
const form = typeof extra.form === "object" && extra.form !== null && !Array.isArray(extra.form) ? extra.form : {};
|
|
@@ -1982,16 +2860,19 @@ function registerProjectCommands(program2) {
|
|
|
1982
2860
|
}
|
|
1983
2861
|
return projectFormTemplate;
|
|
1984
2862
|
};
|
|
2863
|
+
const usesTemplateProjectName = metaUsesTemplateProjectName(flowDetail);
|
|
1985
2864
|
if (useInteractive) {
|
|
1986
2865
|
if (!flowDetail) {
|
|
1987
2866
|
throw new Error("Interactive project creation requires --flow-id so the form schema can be discovered.");
|
|
1988
2867
|
}
|
|
1989
|
-
|
|
2868
|
+
projectFormTemplate = await loadProjectFormTemplate();
|
|
2869
|
+
const fields = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
1990
2870
|
const promptResult = await promptProjectCreateForm({
|
|
1991
|
-
name,
|
|
2871
|
+
name: usesTemplateProjectName ? name ?? "" : name,
|
|
1992
2872
|
form: { ...form },
|
|
1993
2873
|
fields,
|
|
1994
|
-
allowFormHandoff: options.allowFormHandoff === true
|
|
2874
|
+
allowFormHandoff: options.allowFormHandoff === true,
|
|
2875
|
+
...usesTemplateProjectName ? { requireName: false } : {}
|
|
1995
2876
|
});
|
|
1996
2877
|
name = promptResult.name;
|
|
1997
2878
|
Object.keys(form).forEach((key) => {
|
|
@@ -2002,7 +2883,6 @@ function registerProjectCommands(program2) {
|
|
|
2002
2883
|
printResult(options.format, { cancelled: true });
|
|
2003
2884
|
return;
|
|
2004
2885
|
}
|
|
2005
|
-
projectFormTemplate = await loadProjectFormTemplate();
|
|
2006
2886
|
if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
|
|
2007
2887
|
assertHandoffFormReady(fieldsForValidation(flowDetail, projectFormTemplate), form);
|
|
2008
2888
|
printCreateFormHandoff(options.format, profile, flowIdentifiers, {
|
|
@@ -2026,7 +2906,7 @@ function registerProjectCommands(program2) {
|
|
|
2026
2906
|
return;
|
|
2027
2907
|
}
|
|
2028
2908
|
}
|
|
2029
|
-
if (!name) {
|
|
2909
|
+
if (!name && !usesTemplateProjectName) {
|
|
2030
2910
|
throw new Error("--name is required unless --body is provided.");
|
|
2031
2911
|
}
|
|
2032
2912
|
projectFormTemplate = await loadProjectFormTemplate();
|
|
@@ -2044,7 +2924,7 @@ function registerProjectCommands(program2) {
|
|
|
2044
2924
|
}
|
|
2045
2925
|
assertHandoffFormReady(handoffFields, form);
|
|
2046
2926
|
printCreateFormHandoff(options.format, profile, flowIdentifiers, {
|
|
2047
|
-
name,
|
|
2927
|
+
name: name ?? "",
|
|
2048
2928
|
form,
|
|
2049
2929
|
reason: "form_template_auto_init_lambda",
|
|
2050
2930
|
message: "\u68C0\u6D4B\u5230\u8868\u5355\u6A21\u677F\u5305\u542B\u81EA\u52A8\u521D\u59CB\u5316\u811A\u672C\uFF0C\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002"
|
|
@@ -2057,12 +2937,12 @@ function registerProjectCommands(program2) {
|
|
|
2057
2937
|
...projectExtra,
|
|
2058
2938
|
...projectFlowIdentifiers,
|
|
2059
2939
|
key: flowKey,
|
|
2060
|
-
name,
|
|
2940
|
+
...name ? { name } : {},
|
|
2061
2941
|
workspace: profile.config.workspace,
|
|
2062
2942
|
...projectExtra.projectForm ? {} : await buildProjectFormPayload(client, flowDetail, form, projectFormTemplate)
|
|
2063
2943
|
};
|
|
2064
2944
|
if (!options.skipFormValidation) {
|
|
2065
|
-
await validateCreateForm(client, { flowId: options.flowId, flowDetail, form });
|
|
2945
|
+
await validateCreateForm(client, { flowId: options.flowId, flowDetail, form, projectFormTemplate });
|
|
2066
2946
|
}
|
|
2067
2947
|
}
|
|
2068
2948
|
const result = await apiRequest(
|
|
@@ -2082,8 +2962,8 @@ import { spawn as spawn2 } from "child_process";
|
|
|
2082
2962
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
2083
2963
|
|
|
2084
2964
|
// src/core/recipes.ts
|
|
2085
|
-
import { access, mkdir as
|
|
2086
|
-
import
|
|
2965
|
+
import { access, mkdir as mkdir4, readdir, readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
|
|
2966
|
+
import path4 from "path";
|
|
2087
2967
|
var RECIPE_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
|
|
2088
2968
|
var TEMPLATE_PATTERN = /{{\s*([a-zA-Z0-9_.-]+)\s*}}/g;
|
|
2089
2969
|
function assertSafeName(kind, value) {
|
|
@@ -2107,14 +2987,14 @@ function resolveRecipeLocation(options) {
|
|
|
2107
2987
|
workspace,
|
|
2108
2988
|
workspaceDirName,
|
|
2109
2989
|
recipeName: options.recipeName,
|
|
2110
|
-
recipeDir:
|
|
2990
|
+
recipeDir: path4.join(profileDir, "recipes", workspaceDirName, options.recipeName)
|
|
2111
2991
|
};
|
|
2112
2992
|
}
|
|
2113
2993
|
function getRecipesDir(options) {
|
|
2114
2994
|
const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
|
|
2115
|
-
return
|
|
2995
|
+
return path4.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
|
|
2116
2996
|
}
|
|
2117
|
-
function
|
|
2997
|
+
function isRecord6(value) {
|
|
2118
2998
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2119
2999
|
}
|
|
2120
3000
|
function asString(value, fieldName) {
|
|
@@ -2124,7 +3004,7 @@ function asString(value, fieldName) {
|
|
|
2124
3004
|
return value;
|
|
2125
3005
|
}
|
|
2126
3006
|
function parseRecipeDefinition(input) {
|
|
2127
|
-
if (!
|
|
3007
|
+
if (!isRecord6(input)) {
|
|
2128
3008
|
throw new Error("recipe.json must be a JSON object.");
|
|
2129
3009
|
}
|
|
2130
3010
|
if (input.version !== 1) {
|
|
@@ -2132,7 +3012,7 @@ function parseRecipeDefinition(input) {
|
|
|
2132
3012
|
}
|
|
2133
3013
|
const name = asString(input.name, "recipe.name");
|
|
2134
3014
|
assertSafeName("Recipe name", name);
|
|
2135
|
-
if (!
|
|
3015
|
+
if (!isRecord6(input.command)) {
|
|
2136
3016
|
throw new Error("recipe.command must be an object.");
|
|
2137
3017
|
}
|
|
2138
3018
|
const argv = input.command.argv;
|
|
@@ -2140,7 +3020,7 @@ function parseRecipeDefinition(input) {
|
|
|
2140
3020
|
throw new Error("recipe.command.argv must be a non-empty string array.");
|
|
2141
3021
|
}
|
|
2142
3022
|
const variables = Array.isArray(input.variables) ? input.variables.map((item, index) => {
|
|
2143
|
-
if (!
|
|
3023
|
+
if (!isRecord6(item)) {
|
|
2144
3024
|
throw new Error(`recipe.variables[${index}] must be an object.`);
|
|
2145
3025
|
}
|
|
2146
3026
|
const variableName = asString(item.name, `recipe.variables[${index}].name`);
|
|
@@ -2164,7 +3044,7 @@ function parseRecipeDefinition(input) {
|
|
|
2164
3044
|
};
|
|
2165
3045
|
}
|
|
2166
3046
|
async function loadRecipe(recipeDir) {
|
|
2167
|
-
const raw = await
|
|
3047
|
+
const raw = await readFile6(path4.join(recipeDir, "recipe.json"), "utf8");
|
|
2168
3048
|
return parseRecipeDefinition(JSON.parse(raw));
|
|
2169
3049
|
}
|
|
2170
3050
|
async function listRecipes(recipesDir) {
|
|
@@ -2182,7 +3062,7 @@ async function listRecipes(recipesDir) {
|
|
|
2182
3062
|
if (!RECIPE_NAME_PATTERN.test(entry)) {
|
|
2183
3063
|
continue;
|
|
2184
3064
|
}
|
|
2185
|
-
const recipeDir =
|
|
3065
|
+
const recipeDir = path4.join(recipesDir, entry);
|
|
2186
3066
|
try {
|
|
2187
3067
|
const recipe = await loadRecipe(recipeDir);
|
|
2188
3068
|
summaries.push({
|
|
@@ -2216,7 +3096,7 @@ function parseVarsJson(input) {
|
|
|
2216
3096
|
return {};
|
|
2217
3097
|
}
|
|
2218
3098
|
const parsed = JSON.parse(input);
|
|
2219
|
-
if (!
|
|
3099
|
+
if (!isRecord6(parsed)) {
|
|
2220
3100
|
throw new Error("--vars must be a JSON object.");
|
|
2221
3101
|
}
|
|
2222
3102
|
const variables = {};
|
|
@@ -2248,12 +3128,12 @@ function renderTemplate(template, variables) {
|
|
|
2248
3128
|
}
|
|
2249
3129
|
function resolveRecipeFile(recipeDir, token) {
|
|
2250
3130
|
const relative = token.slice(1);
|
|
2251
|
-
if (!relative || relative.includes("..") ||
|
|
3131
|
+
if (!relative || relative.includes("..") || path4.isAbsolute(relative)) {
|
|
2252
3132
|
throw new Error(`Unsafe recipe file reference: ${token}`);
|
|
2253
3133
|
}
|
|
2254
|
-
const resolved =
|
|
2255
|
-
const root =
|
|
2256
|
-
if (resolved !== root && !resolved.startsWith(`${root}${
|
|
3134
|
+
const resolved = path4.resolve(recipeDir, relative);
|
|
3135
|
+
const root = path4.resolve(recipeDir);
|
|
3136
|
+
if (resolved !== root && !resolved.startsWith(`${root}${path4.sep}`)) {
|
|
2257
3137
|
throw new Error(`Recipe file reference escapes recipe directory: ${token}`);
|
|
2258
3138
|
}
|
|
2259
3139
|
return resolved;
|
|
@@ -2263,7 +3143,7 @@ async function renderArgv(options) {
|
|
|
2263
3143
|
const rendered = [];
|
|
2264
3144
|
for (const token of options.recipe.command.argv) {
|
|
2265
3145
|
if (token.startsWith("@")) {
|
|
2266
|
-
const raw = await
|
|
3146
|
+
const raw = await readFile6(resolveRecipeFile(options.recipeDir, token), "utf8");
|
|
2267
3147
|
rendered.push(renderTemplate(raw, options.variables));
|
|
2268
3148
|
} else {
|
|
2269
3149
|
rendered.push(renderTemplate(token, options.variables));
|
|
@@ -2289,7 +3169,7 @@ async function ensureEmptyOrForce(targetDir, force = false) {
|
|
|
2289
3169
|
}
|
|
2290
3170
|
async function writeRecipeScaffold(options) {
|
|
2291
3171
|
await ensureEmptyOrForce(options.location.recipeDir, options.force);
|
|
2292
|
-
await
|
|
3172
|
+
await mkdir4(options.location.recipeDir, { recursive: true });
|
|
2293
3173
|
const title = options.title || options.location.recipeName;
|
|
2294
3174
|
const recipe = {
|
|
2295
3175
|
version: 1,
|
|
@@ -2303,16 +3183,16 @@ async function writeRecipeScaffold(options) {
|
|
|
2303
3183
|
mutating: true
|
|
2304
3184
|
}
|
|
2305
3185
|
};
|
|
2306
|
-
await
|
|
3186
|
+
await writeFile4(path4.join(options.location.recipeDir, "recipe.json"), `${JSON.stringify(recipe, null, 2)}
|
|
2307
3187
|
`, "utf8");
|
|
2308
|
-
await
|
|
2309
|
-
|
|
3188
|
+
await writeFile4(
|
|
3189
|
+
path4.join(options.location.recipeDir, "payload.json"),
|
|
2310
3190
|
`${JSON.stringify({ name: "{{name}}" }, null, 2)}
|
|
2311
3191
|
`,
|
|
2312
3192
|
"utf8"
|
|
2313
3193
|
);
|
|
2314
|
-
await
|
|
2315
|
-
|
|
3194
|
+
await writeFile4(
|
|
3195
|
+
path4.join(options.location.recipeDir, "README.md"),
|
|
2316
3196
|
[`# ${title}`, "", "Describe the BPMAX flow, field mapping, prerequisites, and verification steps for this recipe.", ""].join("\n"),
|
|
2317
3197
|
"utf8"
|
|
2318
3198
|
);
|
|
@@ -2449,8 +3329,14 @@ var schemaEntries = [
|
|
|
2449
3329
|
{ name: "project.list", description: "List projects.", method: "POST", path: "/api/project/list" },
|
|
2450
3330
|
{ name: "project.get", description: "Get project detail.", method: "GET", path: "/api/project/:id" },
|
|
2451
3331
|
{ name: "project.my-step", description: "List my pending steps.", method: "GET", path: "/api/project/my_step" },
|
|
3332
|
+
{ name: "project.approval-context", description: "Get project form values and ended approval step form values.", method: "GET", path: "/api/project/:id + /api/step/:id" },
|
|
2452
3333
|
{ name: "project.create", description: "Create a project with local form schema validation when form payload is provided.", method: "POST", path: "/api/project" },
|
|
2453
|
-
{ name: "step.get", description: "Get step detail.", method: "GET", path: "/api/step/:id" }
|
|
3334
|
+
{ name: "step.get", description: "Get step detail.", method: "GET", path: "/api/step/:id" },
|
|
3335
|
+
{ name: "bbs.list", description: "List BPMAX Business Skills.", method: "GET", path: "/api/business_skill" },
|
|
3336
|
+
{ name: "bbs.create", description: "Create a BPMAX Business Skill from a standard skill zip.", method: "POST", path: "/api/business_skill" },
|
|
3337
|
+
{ name: "bbs.lint", description: "Lint a BPMAX Business Skill package before publish." },
|
|
3338
|
+
{ name: "bbs.gate", description: "Run a BPMAX Business Skill business preflight or verify gate." },
|
|
3339
|
+
{ name: "bbs.ensure", description: "Install or update a BPMAX Business Skill lazily before use." }
|
|
2454
3340
|
];
|
|
2455
3341
|
|
|
2456
3342
|
// src/commands/schema.ts
|
|
@@ -2566,8 +3452,8 @@ function registerStepCommands(program2) {
|
|
|
2566
3452
|
}
|
|
2567
3453
|
|
|
2568
3454
|
// src/core/update.ts
|
|
2569
|
-
import { access as access2, mkdir as
|
|
2570
|
-
import
|
|
3455
|
+
import { access as access2, mkdir as mkdir5, readFile as readFile7, realpath, writeFile as writeFile5 } from "fs/promises";
|
|
3456
|
+
import path5 from "path";
|
|
2571
3457
|
var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/";
|
|
2572
3458
|
var UPDATE_STATE_FILE = "update-state.json";
|
|
2573
3459
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -2679,11 +3565,11 @@ async function fetchLatestVersion(options = {}) {
|
|
|
2679
3565
|
}
|
|
2680
3566
|
}
|
|
2681
3567
|
function updateStatePath(configDir = getConfigDir()) {
|
|
2682
|
-
return
|
|
3568
|
+
return path5.join(configDir, UPDATE_STATE_FILE);
|
|
2683
3569
|
}
|
|
2684
3570
|
async function readUpdateState(configDir) {
|
|
2685
3571
|
try {
|
|
2686
|
-
const raw = await
|
|
3572
|
+
const raw = await readFile7(updateStatePath(configDir), "utf8");
|
|
2687
3573
|
const parsed = JSON.parse(raw);
|
|
2688
3574
|
if (typeof parsed.latest_version !== "string" || typeof parsed.checked_at !== "number") {
|
|
2689
3575
|
return null;
|
|
@@ -2694,8 +3580,8 @@ async function readUpdateState(configDir) {
|
|
|
2694
3580
|
}
|
|
2695
3581
|
}
|
|
2696
3582
|
async function writeUpdateState(state, configDir = getConfigDir()) {
|
|
2697
|
-
await
|
|
2698
|
-
await
|
|
3583
|
+
await mkdir5(configDir, { recursive: true });
|
|
3584
|
+
await writeFile5(updateStatePath(configDir), JSON.stringify(state), "utf8");
|
|
2699
3585
|
}
|
|
2700
3586
|
async function checkCachedUpdate(currentVersion, configDir = getConfigDir()) {
|
|
2701
3587
|
if (process.env.BPMAX_CLI_NO_UPDATE_NOTIFIER) {
|
|
@@ -2747,7 +3633,7 @@ async function findNpmPath() {
|
|
|
2747
3633
|
}
|
|
2748
3634
|
function detectInstallMethod(input) {
|
|
2749
3635
|
const resolvedPath = input.executablePath || "";
|
|
2750
|
-
const method = resolvedPath.includes(`node_modules${
|
|
3636
|
+
const method = resolvedPath.includes(`node_modules${path5.sep}`) || resolvedPath.includes("node_modules/") ? "npm" : "manual";
|
|
2751
3637
|
return {
|
|
2752
3638
|
method,
|
|
2753
3639
|
resolvedPath,
|
|
@@ -3068,6 +3954,7 @@ var program = new Command();
|
|
|
3068
3954
|
program.name(CLI_NAME).description("BPMAX multi-environment CLI").version(VERSION);
|
|
3069
3955
|
registerConfigCommands(program);
|
|
3070
3956
|
registerAuthCommands(program);
|
|
3957
|
+
registerBbsCommands(program);
|
|
3071
3958
|
registerApiCommands(program);
|
|
3072
3959
|
registerSchemaCommands(program);
|
|
3073
3960
|
registerUserCommands(program);
|